bool EngineBase::deserialize(TinyXML::TiXmlElement &n) { /* * Engine deserialization should ideally * take place BEFORE it has been started. */ TinyXML::TiXmlElement *l_element; l_element = n.FirstChildElement("scenes"); n.QueryFloatAttribute("fps", &m_fps); n.QueryFloatAttribute("ups", &m_ups); const char *l_suspendable = n.Attribute("suspendable"); m_suspendable = (l_suspendable && (l_suspendable[0] == 't' || l_suspendable[0] == 'T')); if (l_element && m_scene_manager) m_scene_manager->deserialize(*l_element); else if (l_element && !m_scene_manager) return(false); return(true); }
bool ComponentBase::serialize(TinyXML::TiXmlElement &n) const { n.SetAttribute("id", id().str().c_str()); n.SetAttribute("type", type().str().c_str()); return(true); }
void GameElements::ConfigurationLoader::parseWeapons( TinyXML::TiXmlElement * root ) { ::std::cout<<"-- Loading weapons"<<::std::endl ; TinyXML::TiXmlElement * rootWeapons = root->FirstChildElement("weapons") ; for(TinyXML::TiXmlElement * element = rootWeapons->FirstChildElement("weapon") ; element!=NULL ; element = element->NextSiblingElement("weapon") ) { ::std::cout<<element->Attribute("name")<<::std::endl ; m_weaponsArchetypes.addArchetype(element) ; } }
void GameElements::ConfigurationLoader::parseMaps( TinyXML::TiXmlElement * root, Ogre::SceneManager * sceneManager ) { ::std::cout<<"-- Loading maps"<<::std::endl; TinyXML::TiXmlElement * rootUnits = root->FirstChildElement("maps") ; for(TinyXML::TiXmlElement * element = rootUnits->FirstChildElement("map") ; element!=NULL ; element = element->NextSiblingElement("map") ) { ::std::cout<<element->Attribute("name")<<::std::endl ; Map * map = new Map(sceneManager, element) ; m_maps.insert(::std::make_pair(map->getName(), map)) ; } }
bool MeshBase::deserialize(TinyXML::TiXmlElement &n) { TinyXML::TiXmlElement *l_child; int l_i; n.QueryFloatAttribute("rotation", &m_rotation); /* color */ l_child = n.FirstChildElement("color"); if (l_child) { l_child->QueryFloatAttribute("r", &m_color[0]); l_child->QueryFloatAttribute("g", &m_color[1]); l_child->QueryFloatAttribute("b", &m_color[2]); l_child->QueryFloatAttribute("a", &m_color[3]); } /* texture */ l_child = n.FirstChildElement("texture"); if (l_child) { const char *l_file = l_child->Attribute("id"); if (l_file) m_tdata->load(l_file); } /* texture coordinates */ for (l_child = n.FirstChildElement("tcoord"), l_i = 0; l_child; l_child = l_child->NextSiblingElement("tcoord")) { float l_u, l_v; l_child->QueryFloatAttribute("u", &l_u); l_child->QueryFloatAttribute("v", &l_v); if (!m_tcdata->set(l_i++, l_u, l_v)) { MMWARNING1("Failed to assign texture coordinate data."); break; } } /* vertexes */ for (l_child = n.FirstChildElement("vector"), l_i = 0; l_child; l_child = l_child->NextSiblingElement("vector")) { float l_x, l_y; l_child->QueryFloatAttribute("x", &l_x); l_child->QueryFloatAttribute("y", &l_y); if (!m_vdata->set(l_i++, l_x, l_y)) { MMWARNING1("Failed to assign vertex data."); break; } } return(true); }
bool SceneBase::deserialize(TinyXML::TiXmlElement &n) { TinyXML::TiXmlElement *l_child; for (l_child = n.FirstChildElement("layer") ; l_child; l_child = l_child->NextSiblingElement("layer")) { const char *l_id = l_child->Attribute("id"); const char *l_type = l_child->Attribute("type"); SharedSceneLayer l_layer = FactoryBase::Instance()->createSceneLayer(l_type, l_id, *this); if (!l_layer) { MMWARNING("SceneLayer '%s' of type '%s' creation failed", l_id, l_type); continue; } if (!l_layer->deserialize(*l_child)) { MMWARNING("SceneLayer '%s' of type '%s' failed deserialization", l_id, l_type); continue; } pushLayer(l_layer); } return(true); }
bool SceneBase::serialize(TinyXML::TiXmlElement &n) const { n.SetAttribute("id", id().str().c_str()); n.SetAttribute("type", type().str().c_str()); SceneLayerList::const_reverse_iterator l_i; SceneLayerList::const_reverse_iterator l_c = m_layers.rend(); for (l_i = m_layers.rbegin(); l_i != l_c; ++l_i) { TinyXML::TiXmlElement l_element("layer"); if ((*l_i)->serialize(l_element)) n.InsertEndChild(l_element); } return(true); }
bool EntityBase::deserialize(TinyXML::TiXmlElement &n) { TinyXML::TiXmlElement *l_child; for (l_child = n.FirstChildElement("component") ; l_child; l_child = l_child->NextSiblingElement("component")) { const char *l_id = l_child->Attribute("id"); const char *l_type = l_child->Attribute("type"); SharedComponent l_component = FactoryBase::Instance()->createComponent(l_type, l_id, *this); if (!l_component) { MMWARNING("Component '%s' of type '%s' creation failed", l_id, l_type); continue; } if (!l_component->deserialize(*l_child)) { MMWARNING("Component '%s' of type '%s' failed deserialization", l_id, l_type); continue; } pushComponent(l_component); } return(true); }
bool EntityBase::serialize(TinyXML::TiXmlElement &n) const { n.SetAttribute("id", id().str().c_str()); n.SetAttribute("type", type().str().c_str()); ComponentList::const_reverse_iterator l_i; ComponentList::const_reverse_iterator l_c = m_components.rend(); for (l_i = m_components.rbegin(); l_i != l_c; l_i++) { TinyXML::TiXmlElement l_element("component"); if ((*l_i)->serialize(l_element)) n.InsertEndChild(l_element); } return(true); }
bool Box2DComponent::serialize(TinyXML::TiXmlElement &n) const { if (!ComponentBase::serialize(n)) return(false); switch (m_body_type) { case b2_staticBody: n.SetAttribute("body", "static"); break; case b2_kinematicBody: n.SetAttribute("body", "kinematic"); break; case b2_dynamicBody: n.SetAttribute("body", "dynamic"); break; } n.SetDoubleAttribute("width", m_size.width()); n.SetDoubleAttribute("height", m_size.height()); n.SetDoubleAttribute("density", m_density); n.SetDoubleAttribute("friction", m_friction); return(true); }
bool PositionComponent::deserialize(TinyXML::TiXmlElement &n) { if (!ComponentBase::deserialize(n)) return(false); n.QueryFloatAttribute("x", &m_position[0]); n.QueryFloatAttribute("y", &m_position[1]); return(true); }
bool PositionComponent::serialize(TinyXML::TiXmlElement &n) const { if (!ComponentBase::serialize(n)) return(false); n.SetDoubleAttribute("x", m_position.x()); n.SetDoubleAttribute("y", m_position.y()); return(true); }
bool EngineBase::serialize(TinyXML::TiXmlElement &n) const { n.SetDoubleAttribute("fps", m_fps); n.SetDoubleAttribute("ups", m_ups); n.SetAttribute("suspendable", m_suspendable ? "t" : "f"); if (m_scene_manager) { TinyXML::TiXmlElement l_element("scenes"); if (!m_scene_manager->serialize(l_element)) { MMWARNING1("Scene Manager serialization failed"); return(false); } n.InsertEndChild(l_element); } return(true); }
bool Box2DComponent::deserialize(TinyXML::TiXmlElement &n) { if (!ComponentBase::deserialize(n)) return(false); const char *l_body = n.Attribute("body"); m_body_type = b2_staticBody; if (l_body && l_body[0] == 'k') m_body_type = b2_kinematicBody; if (l_body && l_body[0] == 'd') m_body_type = b2_dynamicBody; n.QueryFloatAttribute("width", &m_size[0]); n.QueryFloatAttribute("height", &m_size[1]); n.QueryFloatAttribute("density", &m_density); n.QueryFloatAttribute("friction", &m_friction); return(true); }
bool VehicleRenderable::loadSceneNodes(TinyXml::TiXmlElement* ele) { TinyXml::TiXmlElement* nodeEle = ele->FirstChildElement("node"); while (nodeEle) { Ogre::String name = getAttrib(nodeEle, "name"); Ogre::SceneNode* node = NULL; if (name.empty()) node = mAttachNode->createChildSceneNode(); else node = mAttachNode->createChildSceneNode(name); mSceneNodes.push_back(node); Ogre::LogManager::getSingleton(). logMessage("VehicleRenderable : parsing <" + name + "> node..."); //process position TinyXml::TiXmlElement* pos = nodeEle->FirstChildElement("position"); node->setPosition(parseVector3(pos)); node->setInitialState(); //process scale TinyXml::TiXmlElement* scale = nodeEle->FirstChildElement("scale"); node->setScale(parseVector3(scale)); node->setInitialState(); //process rotate TinyXml::TiXmlElement* rotate = nodeEle->FirstChildElement("rotation"); node->setOrientation(parseQuaternion(rotate)); node->setInitialState(); //process entities TinyXml::TiXmlElement* entity = nodeEle->FirstChildElement("entity"); while (entity) { if (!loadEntity(entity, node)) return false; entity = entity->NextSiblingElement("entity"); } nodeEle = nodeEle->NextSiblingElement("node"); } return true; }
bool MeshBase::serialize(TinyXML::TiXmlElement &n) const { n.SetAttribute("type", type().str().c_str()); n.SetDoubleAttribute("rotation", m_rotation); /* color */ TinyXML::TiXmlElement l_color("color"); l_color.SetDoubleAttribute("r", m_color[0]); l_color.SetDoubleAttribute("g", m_color[1]); l_color.SetDoubleAttribute("b", m_color[2]); l_color.SetDoubleAttribute("a", m_color[3]); n.InsertEndChild(l_color); /* texture */ if (m_tdata->isLoaded()) { TinyXML::TiXmlElement l_texture("texture"); l_texture.SetAttribute("id", m_tdata->id().str().c_str()); n.InsertEndChild(l_texture); } /* texture coordinates */ for (int i = 0; i < m_tcdata->count(); ++i) { float l_u, l_v; if (m_tcdata->get(i, l_u, l_v)) { TinyXML::TiXmlElement l_vector("tcoord"); l_vector.SetDoubleAttribute("u", l_u); l_vector.SetDoubleAttribute("v", l_v); n.InsertEndChild(l_vector); } else MMWARNING("Failed to serialize text coord %d", i); } /* vertexes */ for (int i = 0; i < m_vdata->count(); ++i) { float l_x, l_y; if (m_vdata->get(i, l_x, l_y)) { TinyXML::TiXmlElement l_vector("vector"); l_vector.SetDoubleAttribute("x", l_x); l_vector.SetDoubleAttribute("y", l_y); n.InsertEndChild(l_vector); } else MMWARNING("Failed to serialize vertex %d", i); } return(true); }