Changeset 2400 for code/branches/objecthierarchy2/src/orxonox/gamestates
- Timestamp:
- Dec 10, 2008, 10:08:37 PM (16 years ago)
- Location:
- code/branches/objecthierarchy2/src/orxonox/gamestates
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.cc
r2396 r2400 41 41 #include "core/CoreIncludes.h" 42 42 #include "core/Core.h" 43 //#include "objects/Backlight.h"44 43 #include "objects/Tickable.h" 45 44 #include "objects/Radar.h" 46 //#include "tools/ParticleInterface.h"47 45 #include "CameraManager.h" 48 46 #include "LevelManager.h" … … 56 54 GSLevel::GSLevel() 57 55 // : GameState<GSGraphics>(name) 58 : timeFactor_(1.0f) 59 , keyBinder_(0) 56 : keyBinder_(0) 60 57 , inputState_(0) 61 58 , radar_(0) … … 68 65 this->ccKeybind_ = 0; 69 66 this->ccTkeybind_ = 0; 70 this->ccSetTimeFactor_ = 0;71 67 72 68 setConfigValues(); … … 107 103 // create the global LevelManager 108 104 this->levelManager_ = new LevelManager(); 109 110 // reset game speed to normal111 timeFactor_ = 1.0f;112 105 113 106 this->loadLevel(); … … 134 127 InputManager::getInstance().requestEnterState("game"); 135 128 } 136 137 if (Core::isMaster())138 {139 // time factor console command140 FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);141 functor->setObject(this);142 ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor");143 CommandExecutor::addConsoleCommandShortcut(ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;144 }145 129 } 146 130 … … 152 136 delete this->ccKeybind_; 153 137 this->ccKeybind_ = 0; 154 }155 if (this->ccSetTimeFactor_)156 {157 delete this->ccSetTimeFactor_;158 this->ccSetTimeFactor_ = 0;159 138 } 160 139 if (this->ccTkeybind_) … … 218 197 //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) 219 198 // it->tick(time.getDeltaTime() * this->timeFactor_); 220 }221 222 /**223 @brief224 Changes the speed of Orxonox225 */226 void GSLevel::setTimeFactor(float factor)227 {228 /*229 float change = factor / this->timeFactor_;230 */231 this->timeFactor_ = factor;232 /*233 for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)234 it->setSpeedFactor(it->getSpeedFactor() * change);235 236 for (ObjectList<Backlight>::iterator it = ObjectList<Backlight>::begin(); it; ++it)237 it->setTimeFactor(timeFactor_);238 */239 199 } 240 200 -
code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.h
r2344 r2400 44 44 ~GSLevel(); 45 45 46 // this has to be public because proteced triggers a bug in msvc47 // when taking the function address.48 void setTimeFactor(float factor);49 float getTimeFactor() { return this->timeFactor_; }50 51 46 protected: 52 47 void enter(Ogre::Viewport* viewport); … … 56 51 void loadLevel(); 57 52 void unloadLevel(); 58 59 float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal.60 53 61 54 // console commands … … 80 73 ConsoleCommand* ccKeybind_; 81 74 ConsoleCommand* ccTkeybind_; 82 ConsoleCommand* ccSetTimeFactor_;83 75 84 76 private: -
code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.cc
r2344 r2400 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" … … 43 44 #include "tools/Timer.h" 44 45 #include "objects/Tickable.h" 46 #include "objects/worldentities/Backlight.h" 47 #include "tools/ParticleInterface.h" 45 48 #include "Settings.h" 46 49 … … 67 70 GSRoot::GSRoot() 68 71 : RootGameState("root") 72 , timeFactor_(1.0f) 69 73 , settings_(0) 70 74 , tclBind_(0) … … 74 78 RegisterRootObject(GSRoot); 75 79 setConfigValues(); 80 81 this->ccSetTimeFactor_ = 0; 76 82 } 77 83 … … 88 94 // creates the class hierarchy for all classes with factories 89 95 Factory::createClassHierarchy(); 96 97 // reset game speed to normal 98 timeFactor_ = 1.0f; 90 99 91 100 // Create the lua interface … … 129 138 ccSelectGameState_ = createConsoleCommand(functor2, "selectGameState"); 130 139 CommandExecutor::addConsoleCommandShortcut(ccSelectGameState_); 140 141 // time factor console command 142 FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::setTimeFactor); 143 functor->setObject(this); 144 ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor"); 145 CommandExecutor::addConsoleCommandShortcut(ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);; 131 146 } 132 147 … … 143 158 delete this->settings_; 144 159 delete this->luaBind_; 160 161 if (this->ccSetTimeFactor_) 162 { 163 delete this->ccSetTimeFactor_; 164 this->ccSetTimeFactor_ = 0; 165 } 145 166 } 146 167 … … 155 176 // Call the Tickable objects 156 177 for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) 157 it->tick(time.getDeltaTime() );178 it->tick(time.getDeltaTime() * this->timeFactor_); 158 179 /*** HACK *** HACK ***/ 159 180 … … 168 189 169 190 Copyright (c) 2000-2008 Torus Knot Software Ltd 170 191 171 192 OGRE is licensed under the LGPL. For more info, see OGRE license. 172 193 */ … … 175 196 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 176 197 // Get the current process core mask 177 178 198 DWORD procMask; 199 DWORD sysMask; 179 200 # if _MSC_VER >= 1400 && defined (_M_X64) 180 201 GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask); 181 202 # else 182 183 # endif 184 185 186 187 188 203 GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask); 204 # endif 205 206 // If procMask is 0, consider there is only one core available 207 // (using 0 as procMask will cause an infinite loop below) 208 if (procMask == 0) 209 procMask = 1; 189 210 190 211 // if the core specified with limitToCPU is not available, take the lowest one … … 192 213 limitToCPU = 0; 193 214 194 215 // Find the lowest core that this process uses and limitToCPU suggests 195 216 DWORD threadMask = 1; 196 197 198 199 200 217 while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU))) 218 threadMask <<= 1; 219 220 // Set affinity to the first core 221 SetThreadAffinityMask(GetCurrentThread(), threadMask); 201 222 #endif 202 223 } 224 225 /** 226 @brief 227 Changes the speed of Orxonox 228 */ 229 void GSRoot::setTimeFactor(float factor) 230 { 231 if (Core::isMaster()) 232 { 233 float change = factor / this->timeFactor_; 234 235 this->timeFactor_ = factor; 236 /* 237 for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it != ObjectList<ParticleInterface>::end(); ++it) 238 it->setSpeedFactor(it->getSpeedFactor() * change); 239 240 for (ObjectList<Backlight>::iterator it = ObjectList<Backlight>::begin(); it != ObjectList<Backlight>::end(); ++it) 241 it->setTimeFactor(timeFactor_); 242 */ 243 } 244 } 203 245 } -
code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.h
r2344 r2400 47 47 { requestState("root"); } 48 48 49 // this has to be public because proteced triggers a bug in msvc 50 // when taking the function address. 51 void setTimeFactor(float factor); 52 float getTimeFactor() { return this->timeFactor_; } 53 49 54 private: 50 55 void enter(); … … 55 60 void setThreadAffinity(unsigned int limitToCPU); 56 61 62 float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal. 57 63 Settings* settings_; 58 64 TclBind* tclBind_; … … 64 70 ConsoleCommand* ccExit_; 65 71 ConsoleCommand* ccSelectGameState_; 72 ConsoleCommand* ccSetTimeFactor_; 66 73 }; 67 74 }
Note: See TracChangeset
for help on using the changeset viewer.