Changeset 5877 for code/branches/core5/src/libraries/core
- Timestamp:
- Oct 5, 2009, 1:34:10 AM (15 years ago)
- Location:
- code/branches/core5/src/libraries/core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/libraries/core/Core.cc
r5876 r5877 434 434 { 435 435 // singletons from other libraries 436 ScopedSingletonManager::update (time, ScopeID::Root);436 ScopedSingletonManager::update<ScopeID::Root>(time); 437 437 if (this->bGraphicsLoaded_) 438 438 { … … 442 442 this->guiManager_->update(time); 443 443 // graphics singletons from other libraries 444 ScopedSingletonManager::update (time, ScopeID::Graphics);444 ScopedSingletonManager::update<ScopeID::Graphics>(time); 445 445 } 446 446 // process thread commands -
code/branches/core5/src/libraries/core/ScopedSingletonManager.h
r5867 r5877 34 34 #include <cassert> 35 35 #include <map> 36 #include "util/Exception.h" 36 37 #include "util/Scope.h" 37 38 #include "util/Singleton.h" 38 39 39 #define ManageScopedSingleton(className, scope ) \40 static ClassScopedSingletonManager<className, scope > className##ScopedSingletonManager(#className)40 #define ManageScopedSingleton(className, scope, allowedToFail) \ 41 static ClassScopedSingletonManager<className, scope, allowedToFail> className##ScopedSingletonManager(#className) 41 42 42 43 namespace orxonox … … 53 54 static void removeManager(ScopedSingletonManager* manager); 54 55 55 static void update(const Clock& time, ScopeID::Value scope) 56 template<ScopeID::Value scope> 57 static void update(const Clock& time) 56 58 { 59 assert(Scope<scope>::isActive()); 57 60 for (ManagerMultiMap::iterator it = getManagersByScope().lower_bound(scope); it != getManagersByScope().upper_bound(scope); ++it) 58 61 it->second->update(time); … … 69 72 }; 70 73 71 template <class T, ScopeID::Value scope >74 template <class T, ScopeID::Value scope, bool allowedToFail> 72 75 class ClassScopedSingletonManager : public ScopedSingletonManager, public ScopeListener 73 76 { … … 83 86 ~ClassScopedSingletonManager() 84 87 { 88 assert(singletonPtr_ == NULL); 85 89 ScopedSingletonManager::removeManager(this); 86 90 } … … 101 105 } 102 106 107 void destroy(OrxonoxClass*) 108 { 109 singletonPtr_->destroy(); 110 } 111 void destroy(void*) 112 { 113 delete singletonPtr_; 114 } 115 116 //! Called every frame by the ScopedSingletonManager 117 void update(const Clock& time) 118 { 119 assert(Scope<scope>::isActive()); 120 // assuming T inherits Singleton<T> 121 singletonPtr_->updateSingleton(time); 122 } 123 124 private: 125 T* singletonPtr_; 126 }; 127 128 template <class T, ScopeID::Value scope> 129 class ClassScopedSingletonManager<T, scope, true> : public ScopedSingletonManager, public ScopeListener 130 { 131 public: 132 ClassScopedSingletonManager(const std::string& className) 133 : ScopedSingletonManager(className, scope) 134 , ScopeListener(scope) 135 , singletonPtr_(NULL) 136 { 137 ScopedSingletonManager::addManager(this); 138 } 139 140 ~ClassScopedSingletonManager() 141 { 142 assert(singletonPtr_ == NULL); 143 ScopedSingletonManager::removeManager(this); 144 } 145 146 //! Called if the Scope of the Singleton gets active (creates the instance) 147 void activated() 148 { 149 assert(singletonPtr_ == NULL); 150 try 151 { singletonPtr_ = new T(); } 152 catch (...) 153 { COUT(1) << "Singleton creation failed: " << Exception::handleMessage() << std::endl; } 154 } 155 156 //! Called if the Scope of this Singleton gets deactivated (destroys the instance) 157 void deactivated() 158 { 159 if (singletonPtr_ != NULL) 160 { 161 this->destroy(singletonPtr_); 162 singletonPtr_ = NULL; 163 } 164 } 165 103 166 void destroy(OrxonoxClass* ptr) 104 167 { … … 113 176 void update(const Clock& time) 114 177 { 178 assert(Scope<scope>::isActive()); 115 179 // assuming T inherits Singleton<T> 116 singletonPtr_->updateSingleton(time); 180 if (singletonPtr_ != NULL) 181 singletonPtr_->updateSingleton(time); 117 182 } 118 183 -
code/branches/core5/src/libraries/core/input/KeyBinderManager.cc
r5869 r5877 41 41 { 42 42 KeyBinderManager* KeyBinderManager::singletonPtr_s = 0; 43 ManageScopedSingleton(KeyBinderManager, ScopeID::Graphics );43 ManageScopedSingleton(KeyBinderManager, ScopeID::Graphics, false); 44 44 45 45 KeyBinderManager::KeyBinderManager() -
code/branches/core5/src/libraries/core/input/KeyDetector.cc
r5869 r5877 40 40 std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed"; 41 41 KeyDetector* KeyDetector::singletonPtr_s = 0; 42 ManageScopedSingleton(KeyDetector, ScopeID::Graphics );42 ManageScopedSingleton(KeyDetector, ScopeID::Graphics, false); 43 43 44 44 KeyDetector::KeyDetector()
Note: See TracChangeset
for help on using the changeset viewer.