Changeset 2485 for code/branches/presentation/src/orxonox/gamestates
- Timestamp:
- Dec 16, 2008, 6:01:13 PM (16 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
-
code/branches/presentation/src/orxonox/gamestates/GSGraphics.cc
r2171 r2485 31 31 32 32 #include <fstream> 33 #include <OgreCompositorManager.h> 33 34 #include <OgreConfigFile.h> 34 35 #include <OgreFrameListener.h> … … 164 165 FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen); 165 166 functor1->setObject(this); 166 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "printScreen")); 167 ccPrintScreen_ = createConsoleCommand(functor1, "printScreen"); 168 CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_); 167 169 } 168 170 … … 170 172 { 171 173 using namespace Ogre; 174 175 delete this->ccPrintScreen_; 172 176 173 177 // remove our WindowEventListener first to avoid bad calls after the window has been destroyed … … 184 188 Loader::unload(this->debugOverlay_); 185 189 delete this->debugOverlay_; 190 191 // unload all compositors 192 Ogre::CompositorManager::getSingleton().removeAll(); 186 193 187 194 // destroy render window … … 430 437 // create a full screen default viewport 431 438 this->viewport_ = this->renderWindow_->addViewport(0, 0); 439 440 if (this->graphicsEngine_) 441 this->graphicsEngine_->setViewport(this->viewport_); 432 442 } 433 443 -
code/branches/presentation/src/orxonox/gamestates/GSGraphics.h
r2103 r2485 112 112 unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high) 113 113 std::string defaultMasterKeybindings_; //!< Filename of default master keybindings. 114 115 // console commands 116 ConsoleCommand* ccPrintScreen_; 114 117 }; 115 118 } -
code/branches/presentation/src/orxonox/gamestates/GSLevel.cc
r2460 r2485 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" 47 #include "PlayerManager.h" 49 48 #include "Settings.h" 50 49 … … 55 54 GSLevel::GSLevel() 56 55 // : GameState<GSGraphics>(name) 57 : timeFactor_(1.0f) 58 , keyBinder_(0) 56 : keyBinder_(0) 59 57 , inputState_(0) 60 58 , radar_(0) … … 64 62 { 65 63 RegisterObject(GSLevel); 64 65 this->ccKeybind_ = 0; 66 this->ccTkeybind_ = 0; 67 66 68 setConfigValues(); 67 69 } … … 95 97 } 96 98 99 this->playerManager_ = new PlayerManager(); 100 97 101 if (Core::isMaster()) 98 102 { 99 103 // create the global LevelManager 100 104 this->levelManager_ = new LevelManager(); 101 102 // reset game speed to normal103 timeFactor_ = 1.0f;104 105 105 106 this->loadLevel(); … … 114 115 FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind); 115 116 functor1->setObject(this); 116 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind")); 117 ccKeybind_ = createConsoleCommand(functor1, "keybind"); 118 CommandExecutor::addConsoleCommandShortcut(ccKeybind_); 117 119 FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind); 118 120 functor2->setObject(this); 119 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind")); 121 ccTkeybind_ = createConsoleCommand(functor2, "tkeybind"); 122 CommandExecutor::addConsoleCommandShortcut(ccTkeybind_); 120 123 // set our console command as callback for the key detector 121 124 InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_); … … 124 127 InputManager::getInstance().requestEnterState("game"); 125 128 } 126 127 if (Core::isMaster())128 {129 // time factor console command130 FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);131 functor->setObject(this);132 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;133 }134 129 } 135 130 136 131 void GSLevel::leave() 137 132 { 133 // destroy console commands 134 if (this->ccKeybind_) 135 { 136 delete this->ccKeybind_; 137 this->ccKeybind_ = 0; 138 } 139 if (this->ccTkeybind_) 140 { 141 delete this->ccTkeybind_; 142 this->ccTkeybind_ = 0; 143 } 144 138 145 // this call will delete every BaseObject! 139 146 // But currently this will call methods of objects that exist no more … … 149 156 150 157 if (this->radar_) 158 { 151 159 delete this->radar_; 160 this->radar_ = 0; 161 } 152 162 153 163 if (this->cameraManager_) 164 { 154 165 delete this->cameraManager_; 166 this->cameraManager_ = 0; 167 } 155 168 156 169 if (this->levelManager_) 170 { 157 171 delete this->levelManager_; 172 this->levelManager_ = 0; 173 } 174 175 if (this->playerManager_) 176 { 177 delete this->playerManager_; 178 this->playerManager_ = 0; 179 } 158 180 159 181 if (Core::showsGraphics()) … … 162 184 InputManager::getInstance().requestDestroyState("game"); 163 185 if (this->keyBinder_) 186 { 164 187 delete this->keyBinder_; 188 this->keyBinder_ = 0; 189 } 165 190 } 166 191 } … … 172 197 //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) 173 198 // it->tick(time.getDeltaTime() * this->timeFactor_); 174 }175 176 /**177 @brief178 Changes the speed of Orxonox179 */180 void GSLevel::setTimeFactor(float factor)181 {182 /*183 float change = factor / this->timeFactor_;184 */185 this->timeFactor_ = factor;186 /*187 for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)188 it->setSpeedFactor(it->getSpeedFactor() * change);189 190 for (ObjectList<Backlight>::iterator it = ObjectList<Backlight>::begin(); it; ++it)191 it->setTimeFactor(timeFactor_);192 */193 199 } 194 200 -
code/branches/presentation/src/orxonox/gamestates/GSLevel.h
r2103 r2485 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 … … 70 63 CameraManager* cameraManager_; 71 64 LevelManager* levelManager_; 65 PlayerManager* playerManager_; 72 66 73 67 //##### ConfigValues ##### … … 75 69 //! Filename of default keybindings. 76 70 std::string defaultKeybindings_; 71 72 // console commands 73 ConsoleCommand* ccKeybind_; 74 ConsoleCommand* ccTkeybind_; 77 75 78 76 private: -
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 } -
code/branches/presentation/src/orxonox/gamestates/GSRoot.h
r1891 r2485 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 void pause(); 53 float getTimeFactor() { return this->timeFactor_; } 54 49 55 private: 50 56 void enter(); … … 55 61 void setThreadAffinity(unsigned int limitToCPU); 56 62 63 float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal. 64 bool bPaused_; 65 float timeFactorPauseBackup_; 57 66 Settings* settings_; 58 67 TclBind* tclBind_; 59 68 TclThreadManager* tclThreadManager_; 60 69 Shell* shell_; 70 LuaBind* luaBind_; 71 72 // console commands 73 ConsoleCommand* ccExit_; 74 ConsoleCommand* ccSelectGameState_; 75 ConsoleCommand* ccSetTimeFactor_; 76 ConsoleCommand* ccPause_; 77 }; 78 79 class _OrxonoxExport TimeFactorListener : virtual public OrxonoxClass 80 { 81 friend class GSRoot; 82 83 public: 84 TimeFactorListener(); 85 virtual ~TimeFactorListener() {} 86 87 protected: 88 virtual void changedTimeFactor(float factor_new, float factor_old) {} 89 inline float getTimeFactor() const 90 { return TimeFactorListener::timefactor_s; } 91 92 private: 93 static float timefactor_s; 61 94 }; 62 95 }
Note: See TracChangeset
for help on using the changeset viewer.