/** * 在模型销毁的时候, * 需判断组件是否由自身创建. * 检查m_SelfOwn, * 若为true, * 则需要同时销毁所有组件. */ Model::~Model() { for (UINT32 i = 0; i < m_ComponentList.size(); ++i) { IComponent *component = m_ComponentList[i]; component->Destroy(); } }
bool Controller::changeScene(const char* buf, uint32 size) { EngineModules::world()->clear(); XMLDoc doc; doc.parseBuffer( buf, size ); if( doc.hasError() ) { EngineModules::engineLogger()->writeError("Controller::changeScene(): scene parsing failed, %d@%s", __LINE__, __FILE__); return false; } sig_start_new_scn_.Emit(); XMLNode rootNode = doc.getRootNode(); if ( !rootNode.isEmpty() && (strcmp(rootNode.getName(), "Setup") == 0) ) { // load settings from setup file XMLNode xmlNode1 = rootNode.getFirstChild("Settings"); if (!xmlNode1.isEmpty()) { string set_xml = ""; rapidxml::print( back_inserter( set_xml ), *xmlNode1.getRapidXMLNode(), 0 ); EngineModules::engineLogger()->writeDebugInfo("Controller::changeScene(): " "loading scene specified settings"); EngineModules::engineConfig()->setExtraConfig(set_xml.c_str(), set_xml.length()); } // Parse children, and create the known component // add the created components to the root entity in the world IEntity *root_ent = EngineModules::world()->getEntity(0u); xmlNode1 = rootNode.getFirstChild(); while( !xmlNode1.isEmpty() ) { // skip node if (xmlNode1.getName() == 0x0 || _stricmp(xmlNode1.getName(), "Settings") == 0 || //_stricmp(xmlNode1.getName(), "EnginePath") == 0 || _stricmp(xmlNode1.getName(), "Editor") == 0 ) { xmlNode1 = xmlNode1.getNextSibling(); continue; } IComponent *com = manager_->createComponent(xmlNode1.getName()); if (com && root_ent->addComponent(com)) { string com_xml = ""; rapidxml::print( back_inserter( com_xml ), *xmlNode1.getRapidXMLNode(), 0 ); // set serialized data char *txt = new char[com_xml.length()]; memcpy(txt, com_xml.c_str(), com_xml.length()); com->loadFromXml(txt, com_xml.length()); delete []txt; } else { EngineModules::engineLogger()->writeWarning("Controller::changeScene():" " can not handle the node of '%s'", xmlNode1.getName()); if(com) com->Destroy(); } xmlNode1 = xmlNode1.getNextSibling(); } // Emit load scene signal for those unhandled or who need to know the gloabl information sig_load_scene_.Emit(buf, size); } else { EngineModules::engineLogger()->writeError("Controller::changeScene(): " "it's not a valid scene setup data, %d@%s", __LINE__, __FILE__); return false; } return true; }