Changeset 10518
- Timestamp:
- May 31, 2015, 10:56:32 AM (9 years ago)
- Location:
- code/branches/core7/src/libraries/core
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/Core.cc
r10509 r10518 111 111 , graphicsScope_(NULL) 112 112 , bGraphicsLoaded_(false) 113 , rootModule_(NULL) 113 114 , config_(NULL) 114 115 , destructionHelper_(this) … … 121 122 // Create a new dynamic library manager 122 123 this->dynLibManager_ = new DynLibManager(); 123 124 // Load modules125 orxout(internal_info) << "Loading modules:" << endl;126 const std::vector<std::string>& modulePaths = ApplicationPaths::getInstance().getModulePaths();127 for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it)128 {129 try130 {131 this->dynLibManager_->load(*it);132 }133 catch (...)134 {135 orxout(user_error) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << endl;136 }137 }138 124 139 125 // TODO: initialize Root-Context … … 142 128 // TODO: initialize CommandLineParser here 143 129 // TODO: initialize ConsoleCommandManager here 144 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(); 130 this->rootModule_ = ModuleInstance::getCurrentModuleInstance(); 131 this->rootModule_->loadAllStaticallyInitializedInstances(); 145 132 146 133 // Parse command line arguments AFTER the modules have been loaded (static code!) … … 258 245 IdentifierManager::getInstance().destroyAllIdentifiers(); 259 246 safeObjectDelete(&signalHandler_); 247 // if (this->rootModule_) 248 // this->rootModule_->unloadAllStaticallyInitializedInstances(); 249 // safeObjectDelete(&rootModule_); 260 250 safeObjectDelete(&dynLibManager_); 261 251 safeObjectDelete(&configurablePaths_); … … 263 253 264 254 orxout(internal_status) << "finished destroying Core object" << endl; 255 } 256 257 void Core::loadModules() 258 { 259 orxout(internal_info) << "Loading modules:" << endl; 260 261 const std::vector<std::string>& modulePaths = ApplicationPaths::getInstance().getModulePaths(); 262 for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it) 263 { 264 try 265 { 266 ModuleInstance* module = new ModuleInstance(*it); 267 this->loadModule(module); 268 this->modules_.push_back(module); 269 } 270 catch (...) 271 { 272 orxout(user_error) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << endl; 273 } 274 } 275 276 orxout(internal_info) << "finished loading modules" << endl; 277 } 278 279 void Core::loadModule(ModuleInstance* module) 280 { 281 ModuleInstance::setCurrentModuleInstance(module); 282 DynLib* dynLib = this->dynLibManager_->load(module->getName()); 283 module->setDynLib(dynLib); 284 module->loadAllStaticallyInitializedInstances(); 285 IdentifierManager::getInstance().createClassHierarchy(); 286 ScopeManager::getInstance().updateListeners(); 287 } 288 289 void Core::unloadModules() 290 { 291 for (std::list<ModuleInstance*>::iterator it = this->modules_.begin(); it != this->modules_.end(); ++it) 292 { 293 ModuleInstance* module = (*it); 294 this->unloadModule(module); 295 delete module; 296 } 297 this->modules_.clear(); 298 } 299 300 void Core::unloadModule(ModuleInstance* module) 301 { 302 module->unloadAllStaticallyInitializedInstances(); 303 module->deleteAllStaticallyInitializedInstances(); 304 this->dynLibManager_->unload(module->getDynLib()); 305 module->setDynLib(NULL); 265 306 } 266 307 -
code/branches/core7/src/libraries/core/Core.h
r10509 r10518 60 60 { 61 61 friend class Singleton<Core>; 62 friend class Game;63 62 64 63 public: … … 77 76 void destroy(); 78 77 78 void preUpdate(const Clock& time); 79 void postUpdate(const Clock& time); 80 81 void loadGraphics(); 82 void unloadGraphics(); 83 84 void loadModules(); 85 void unloadModules(); 86 void loadModule(ModuleInstance* module); 87 void unloadModule(ModuleInstance* module); 88 79 89 inline CoreConfig* getConfig() const 80 90 { return this->config_; } … … 82 92 private: 83 93 Core(const Core&); //!< Don't use (undefined symbol) 84 85 void preUpdate(const Clock& time);86 void postUpdate(const Clock& time);87 88 void loadGraphics();89 void unloadGraphics();90 94 91 95 void setThreadAffinity(int limitToCPU); … … 108 112 Scope<ScopeID::GRAPHICS>* graphicsScope_; 109 113 bool bGraphicsLoaded_; 114 ModuleInstance* rootModule_; 115 std::list<ModuleInstance*>modules_; 110 116 111 117 /// Helper object that stores the config values -
code/branches/core7/src/libraries/core/Game.cc
r10479 r10518 110 110 orxout(internal_info) << "creating Core object:" << endl; 111 111 this->core_ = new Core(cmdLine); 112 this->core_->loadModules(); 112 113 113 114 // Do this after the Core creation! … … 141 142 GameStateFactory::getFactories().clear(); 142 143 safeObjectDelete(&config_); 144 // if (this->core_) 145 // this->core_->unloadModules(); 143 146 safeObjectDelete(&core_); 144 147 safeObjectDelete(&gameClock_); -
code/branches/core7/src/libraries/core/class/IdentifierManager.cc
r10483 r10518 100 100 { 101 101 Identifier* identifier = (*it); 102 if (identifier->isInitialized()) 103 continue; 102 104 103 105 orxout(verbose, context::identifier) << "Initialize ClassIdentifier<" << identifier->getName() << ">-Singleton." << endl; … … 135 137 if (initializedIdentifiers.find(identifier) != initializedIdentifiers.end()) 136 138 identifier->finishInitialization(); 137 else 139 else if (!identifier->isInitialized()) 138 140 orxout(internal_error) << "Identifier was registered late and is not initialized: " << identifier->getName() << " / " << identifier->getTypeInfo().name() << endl; 139 141 } -
code/branches/core7/src/libraries/core/module/ModuleInstance.cc
r10404 r10518 35 35 ModuleInstance* ModuleInstance::currentModuleInstance_s = NULL; 36 36 37 ModuleInstance::ModuleInstance(const std::string& name) 38 : name_(name) 39 , dynLib_(NULL) 40 { 41 } 42 37 43 ModuleInstance::~ModuleInstance() 38 44 { 39 std::list<StaticallyInitializedInstance*> copy(this->staticallyInitializedInstances_); 40 for (std::list<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it) 41 delete (*it); 45 this->deleteAllStaticallyInitializedInstances(); 42 46 } 43 47 44 48 void ModuleInstance::addStaticallyInitializedInstance(StaticallyInitializedInstance* instance) 45 49 { 46 this->staticallyInitializedInstances_. push_back(instance);50 this->staticallyInitializedInstances_.insert(instance); 47 51 } 48 52 49 53 void ModuleInstance::loadAllStaticallyInitializedInstances() 50 54 { 51 for (std:: list<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)55 for (std::set<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it) 52 56 (*it)->load(); 53 57 } … … 55 59 void ModuleInstance::unloadAllStaticallyInitializedInstances() 56 60 { 57 for (std:: list<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it)61 for (std::set<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it) 58 62 (*it)->unload(); 59 63 } … … 61 65 void ModuleInstance::removeStaticallyInitializedInstance(StaticallyInitializedInstance* instance) 62 66 { 63 this->staticallyInitializedInstances_. remove(instance);67 this->staticallyInitializedInstances_.erase(instance); 64 68 } 69 70 void ModuleInstance::deleteAllStaticallyInitializedInstances() 71 { 72 std::set<StaticallyInitializedInstance*> copy(this->staticallyInitializedInstances_); 73 this->staticallyInitializedInstances_.clear(); 74 for (std::set<StaticallyInitializedInstance*>::iterator it = this->staticallyInitializedInstances_.begin(); it != this->staticallyInitializedInstances_.end(); ++it) 75 delete (*it); 76 } 77 65 78 66 79 /*static*/ void ModuleInstance::setCurrentModuleInstance(ModuleInstance* instance) … … 72 85 { 73 86 if (!ModuleInstance::currentModuleInstance_s) 74 ModuleInstance::currentModuleInstance_s = new ModuleInstance( );87 ModuleInstance::currentModuleInstance_s = new ModuleInstance(""); 75 88 return ModuleInstance::currentModuleInstance_s; 76 89 } -
code/branches/core7/src/libraries/core/module/ModuleInstance.h
r10404 r10518 32 32 #include "core/CorePrereqs.h" 33 33 34 #include <list> 34 #include <set> 35 #include <string> 35 36 36 37 namespace orxonox … … 39 40 { 40 41 public: 42 ModuleInstance(const std::string& name); 41 43 ~ModuleInstance(); 42 44 … … 45 47 void unloadAllStaticallyInitializedInstances(); 46 48 void removeStaticallyInitializedInstance(StaticallyInitializedInstance* instance); 49 void deleteAllStaticallyInitializedInstances(); 50 51 inline const std::string& getName() const 52 { return this->name_; } 53 54 inline void setDynLib(DynLib* dynLib) 55 { this->dynLib_ = dynLib; } 56 inline DynLib* getDynLib() const 57 { return this->dynLib_; } 47 58 48 59 static void setCurrentModuleInstance(ModuleInstance* instance); … … 50 61 51 62 private: 52 std::list<StaticallyInitializedInstance*> staticallyInitializedInstances_; 63 std::set<StaticallyInitializedInstance*> staticallyInitializedInstances_; 64 std::string name_; 65 DynLib* dynLib_; 53 66 54 67 static ModuleInstance* currentModuleInstance_s;
Note: See TracChangeset
for help on using the changeset viewer.