- Timestamp:
- Dec 16, 2008, 6:01:13 PM (17 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
-
code/branches/presentation/src/orxonox/gamestates/GSRoot.cc
r2459 r2485 32 32 #include "util/Exception.h" 33 33 #include "util/Debug.h" 34 #include "core/Core.h" 34 35 #include "core/Factory.h" 35 36 #include "core/ConfigValueIncludes.h" … … 40 41 #include "core/TclBind.h" 41 42 #include "core/TclThreadManager.h" 43 #include "core/LuaBind.h" 42 44 #include "tools/Timer.h" 43 45 #include "objects/Tickable.h" 44 46 #include "Settings.h" 45 47 46 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 48 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 47 49 # ifndef WIN32_LEAN_AND_MEAN 48 50 # define WIN32_LEAN_AND_MEAN … … 66 68 GSRoot::GSRoot() 67 69 : RootGameState("root") 70 , timeFactor_(1.0f) 71 , bPaused_(false) 72 , timeFactorPauseBackup_(1.0f) 68 73 , settings_(0) 69 74 , tclBind_(0) … … 73 78 RegisterRootObject(GSRoot); 74 79 setConfigValues(); 80 81 this->ccSetTimeFactor_ = 0; 82 this->ccPause_ = 0; 75 83 } 76 84 … … 87 95 // creates the class hierarchy for all classes with factories 88 96 Factory::createClassHierarchy(); 97 98 // reset game speed to normal 99 timeFactor_ = 1.0f; 100 101 // Create the lua interface 102 this->luaBind_ = new LuaBind(); 89 103 90 104 // instantiate Settings class … … 114 128 setThreadAffinity((unsigned int)(limitToCPU - 1)); 115 129 116 // add console commands 117 FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame); 118 functor1->setObject(this); 119 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "exit")); 120 121 // add console commands 122 FunctorMember01<GameStateBase, const std::string&>* functor2 = createFunctor(&GameStateBase::requestState); 123 functor2->setObject(this); 124 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "selectGameState")); 130 { 131 // add console commands 132 FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::exitGame); 133 functor->setObject(this); 134 this->ccExit_ = createConsoleCommand(functor, "exit"); 135 CommandExecutor::addConsoleCommandShortcut(this->ccExit_); 136 } 137 138 { 139 // add console commands 140 FunctorMember01<GameStateBase, const std::string&>* functor = createFunctor(&GameStateBase::requestState); 141 functor->setObject(this); 142 this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState"); 143 CommandExecutor::addConsoleCommandShortcut(this->ccSelectGameState_); 144 } 145 146 { 147 // time factor console command 148 FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::setTimeFactor); 149 functor->setObject(this); 150 this->ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor"); 151 CommandExecutor::addConsoleCommandShortcut(this->ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0); 152 } 153 154 { 155 // time factor console command 156 FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::pause); 157 functor->setObject(this); 158 this->ccPause_ = createConsoleCommand(functor, "pause"); 159 CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline); 160 } 125 161 } 126 162 127 163 void GSRoot::leave() 128 164 { 129 // TODO: remove and destroy console commands 165 // destroy console commands 166 delete this->ccExit_; 167 delete this->ccSelectGameState_; 130 168 131 169 delete this->shell_; … … 133 171 delete this->tclBind_; 134 172 135 delete settings_; 136 173 delete this->settings_; 174 delete this->luaBind_; 175 176 if (this->ccSetTimeFactor_) 177 { 178 delete this->ccSetTimeFactor_; 179 this->ccSetTimeFactor_ = 0; 180 } 181 182 if (this->ccPause_) 183 { 184 delete this->ccPause_; 185 this->ccPause_ = 0; 186 } 137 187 } 138 188 … … 153 203 } 154 204 for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) 155 it->tick(leveldt );205 it->tick(leveldt * this->timeFactor_); 156 206 /*** HACK *** HACK ***/ 157 207 … … 166 216 167 217 Copyright (c) 2000-2008 Torus Knot Software Ltd 168 218 169 219 OGRE is licensed under the LGPL. For more info, see OGRE license. 170 220 */ … … 173 223 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 174 224 // Get the current process core mask 175 176 225 DWORD procMask; 226 DWORD sysMask; 177 227 # if _MSC_VER >= 1400 && defined (_M_X64) 178 228 GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask); 179 229 # else 180 230 GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask); 181 231 # endif 182 232 183 184 185 186 233 // If procMask is 0, consider there is only one core available 234 // (using 0 as procMask will cause an infinite loop below) 235 if (procMask == 0) 236 procMask = 1; 187 237 188 238 // if the core specified with limitToCPU is not available, take the lowest one … … 190 240 limitToCPU = 0; 191 241 192 242 // Find the lowest core that this process uses and limitToCPU suggests 193 243 DWORD threadMask = 1; 194 195 196 197 198 244 while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU))) 245 threadMask <<= 1; 246 247 // Set affinity to the first core 248 SetThreadAffinityMask(GetCurrentThread(), threadMask); 199 249 #endif 200 250 } 251 252 /** 253 @brief 254 Changes the speed of Orxonox 255 */ 256 void GSRoot::setTimeFactor(float factor) 257 { 258 if (Core::isMaster()) 259 { 260 if (!this->bPaused_) 261 { 262 TimeFactorListener::timefactor_s = factor; 263 264 for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it) 265 it->changedTimeFactor(factor, this->timeFactor_); 266 267 this->timeFactor_ = factor; 268 } 269 else 270 this->timeFactorPauseBackup_ = factor; 271 } 272 } 273 274 void GSRoot::pause() 275 { 276 if (Core::isMaster()) 277 { 278 if (!this->bPaused_) 279 { 280 this->timeFactorPauseBackup_ = this->timeFactor_; 281 this->setTimeFactor(0.0f); 282 this->bPaused_ = true; 283 } 284 else 285 { 286 this->bPaused_ = false; 287 this->setTimeFactor(this->timeFactorPauseBackup_); 288 } 289 } 290 } 291 292 //////////////////////// 293 // TimeFactorListener // 294 //////////////////////// 295 float TimeFactorListener::timefactor_s = 1.0f; 296 297 TimeFactorListener::TimeFactorListener() 298 { 299 RegisterRootObject(TimeFactorListener); 300 } 201 301 }
Note: See TracChangeset
for help on using the changeset viewer.