Changeset 1672 for code/branches/gui/src/orxonox/gamestates
- Timestamp:
- Aug 27, 2008, 10:21:39 PM (16 years ago)
- Location:
- code/branches/gui/src/orxonox/gamestates
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/orxonox/gamestates/GSClient.cc
r1670 r1672 78 78 } 79 79 80 void GSClient::ticked(float dt )80 void GSClient::ticked(float dt, uint64_t time) 81 81 { 82 GSLevel::ticked(dt );82 GSLevel::ticked(dt, time); 83 83 client_->tick(dt); 84 84 85 this->tickChild(dt );85 this->tickChild(dt, time); 86 86 } 87 87 } -
code/branches/gui/src/orxonox/gamestates/GSClient.h
r1670 r1672 46 46 void enter(); 47 47 void leave(); 48 void ticked(float dt );48 void ticked(float dt, uint64_t time); 49 49 50 50 network::Client* client_; -
code/branches/gui/src/orxonox/gamestates/GSGUI.cc
r1670 r1672 58 58 } 59 59 60 void GSGUI::ticked(float dt )60 void GSGUI::ticked(float dt, uint64_t time) 61 61 { 62 62 // tick CEGUI 63 63 GUIManager::getInstance().tick(dt); 64 64 65 this->tickChild(dt );65 this->tickChild(dt, time); 66 66 } 67 67 } -
code/branches/gui/src/orxonox/gamestates/GSGUI.h
r1670 r1672 44 44 void enter(); 45 45 void leave(); 46 void ticked(float dt );46 void ticked(float dt, uint64_t time); 47 47 48 48 }; -
code/branches/gui/src/orxonox/gamestates/GSGraphics.cc
r1670 r1672 34 34 #include <OgreTimer.h> 35 35 #include <OgreWindowEventUtilities.h> 36 #include <OgreRenderWindow.h> 36 37 37 38 #include "core/ConsoleCommand.h" 38 39 #include "core/ConfigValueIncludes.h" 39 40 #include "core/input/InputManager.h" 40 #include "core/TclThreadManager.h"41 41 //#include "core/Core.h" 42 42 #include "overlays/console/InGameConsole.h" … … 48 48 GSGraphics::GSGraphics() 49 49 : GameState("graphics") 50 , timer_(0)51 50 , debugRefreshTime_(0.0f) 52 51 , inputManager_(0) 53 52 , console_(0) 54 53 , guiManager_(0) 54 , frameCount_(0) 55 55 { 56 56 } … … 67 67 void GSGraphics::enter() 68 68 { 69 this->ogreRoot_ = Ogre::Root::getSingletonPtr(); 69 70 this->graphicsEngine_ = GraphicsEngine::getInstancePtr(); 70 71 … … 87 88 guiManager_ = new GUIManager(); 88 89 guiManager_->initialise(); 89 90 // use the ogre timer class to measure time.91 timer_ = new Ogre::Timer();92 90 } 93 91 94 92 void GSGraphics::leave() 95 93 { 96 delete this->timer_;97 98 94 delete this->guiManager_; 99 95 … … 102 98 delete this->inputManager_; 103 99 100 this->ogreRoot_->detachRenderTarget(GraphicsEngine::getInstance().getRenderWindow()); 101 delete GraphicsEngine::getInstance().getRenderWindow(); 102 this->ogreRoot_->shutdown 104 103 // TODO: destroy render window 105 104 } … … 118 117 need the time. So we shouldn't run into problems. 119 118 */ 120 void GSGraphics::ticked(float dt )119 void GSGraphics::ticked(float dt, uint64_t time) 121 120 { 122 // note: paramter 'dt' is of no meaning121 this->inputManager_->tick(dt); 123 122 124 Ogre::Root& ogreRoot = Ogre::Root::getSingleton();123 this->tickChild(dt, time); 125 124 126 unsigned long frameCount = 0; 125 // tick console 126 this->console_->tick(dt); 127 127 128 const unsigned long refreshTime = (unsigned long)(debugRefreshTime_ * 1000000.0f); 129 unsigned long refreshStartTime = 0; 130 unsigned long tickTime = 0; 131 unsigned long oldFrameCount = 0; 128 //// get current time once again 129 //timeAfterTick = timer_->getMicroseconds(); 132 130 133 unsigned long timeBeforeTick = 0; 134 unsigned long timeBeforeTickOld = 0; 135 unsigned long timeAfterTick = 0; 131 //tickTime += timeAfterTick - timeBeforeTick; 132 //if (timeAfterTick > refreshStartTime + refreshTime) 133 //{ 134 // GraphicsEngine::getInstance().setAverageTickTime( 135 // (float)tickTime * 0.001 / (frameCount - oldFrameCount)); 136 // float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0; 137 // GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS); 136 138 137 // TODO: Update time in seconds every 7 seconds to avoid any overflow (7 secs is very tight) 139 // oldFrameCount = frameCount; 140 // tickTime = 0; 141 // refreshStartTime = timeAfterTick; 142 //} 138 143 139 COUT(3) << "Orxonox: Starting the main loop." << std::endl; 144 // don't forget to call _fireFrameStarted in ogre to make sure 145 // everything goes smoothly 146 Ogre::FrameEvent evt; 147 evt.timeSinceLastFrame = dt; 148 evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway 149 ogreRoot_->_fireFrameStarted(evt); 140 150 141 try 142 { 143 timer_->reset(); 144 while (!this->hasScheduledTransition()) 145 { 146 // get current time 147 timeBeforeTickOld = timeBeforeTick; 148 timeBeforeTick = timer_->getMicroseconds(); 149 float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0; 151 // Pump messages in all registered RenderWindows 152 // This calls the WindowEventListener objects. 153 Ogre::WindowEventUtilities::messagePump(); 154 // make sure the window stays active even when not focused 155 // (probably only necessary on windows) 156 GraphicsEngine::getInstance().setWindowActivity(true); 150 157 151 this->inputManager_->tick(dt);152 TclThreadManager::getInstance().tick(dt);158 // render 159 ogreRoot_->_updateAllRenderTargets(); 153 160 154 this->tickChild(dt); 161 // again, just to be sure ogre works fine 162 ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 155 163 156 // tick console 157 this->console_->tick(dt); 164 ++frameCount_; 158 165 159 // get current time once again 160 timeAfterTick = timer_->getMicroseconds(); 161 162 tickTime += timeAfterTick - timeBeforeTick; 163 if (timeAfterTick > refreshStartTime + refreshTime) 164 { 165 GraphicsEngine::getInstance().setAverageTickTime( 166 (float)tickTime * 0.001 / (frameCount - oldFrameCount)); 167 float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0; 168 GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS); 169 170 oldFrameCount = frameCount; 171 tickTime = 0; 172 refreshStartTime = timeAfterTick; 173 } 174 175 // don't forget to call _fireFrameStarted in ogre to make sure 176 // everything goes smoothly 177 Ogre::FrameEvent evt; 178 evt.timeSinceLastFrame = dt; 179 evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway 180 ogreRoot._fireFrameStarted(evt); 181 182 // Pump messages in all registered RenderWindows 183 // This calls the WindowEventListener objects. 184 Ogre::WindowEventUtilities::messagePump(); 185 // make sure the window stays active even when not focused 186 // (probably only necessary on windows) 187 GraphicsEngine::getInstance().setWindowActivity(true); 188 189 // render 190 ogreRoot._updateAllRenderTargets(); 191 192 // again, just to be sure ogre works fine 193 ogreRoot._fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 194 195 ++frameCount; 196 } 197 } 198 catch (std::exception& ex) 199 { 200 // something went wrong. 201 COUT(1) << ex.what() << std::endl; 202 COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl; 203 } 166 //} 167 //catch (std::exception& ex) 168 //{ 169 // // something went wrong. 170 // COUT(1) << ex.what() << std::endl; 171 // COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl; 172 //} 204 173 } 205 174 } -
code/branches/gui/src/orxonox/gamestates/GSGraphics.h
r1670 r1672 48 48 void enter(); 49 49 void leave(); 50 void ticked(float dt); 51 52 Ogre::Timer* timer_; //!< Main loop timer 50 void ticked(float dt, uint64_t time); 53 51 54 52 // config values 55 53 float debugRefreshTime_; 56 54 55 Ogre::Root* ogreRoot_; 57 56 GraphicsEngine* graphicsEngine_; //!< our dearest graphics engine <3 58 57 InputManager* inputManager_; 59 58 InGameConsole* console_; 60 59 GUIManager* guiManager_; 60 61 62 // variables for time statistics 63 unsigned long frameCount_; 64 65 //const unsigned long refreshTime = (unsigned long)(debugRefreshTime_ * 1000000.0f); 66 //unsigned long refreshStartTime; 67 //unsigned long tickTime; 68 //unsigned long oldFrameCount; 69 70 //unsigned long timeBeforeTick; 71 //unsigned long timeBeforeTickOld; 72 //unsigned long timeAfterTick; 61 73 }; 62 74 } -
code/branches/gui/src/orxonox/gamestates/GSIO.cc
r1670 r1672 58 58 } 59 59 60 void GSIO::ticked(float dt )60 void GSIO::ticked(float dt, uint64_t time) 61 61 { 62 this->tickChild(dt );62 this->tickChild(dt, time); 63 63 //Ogre::Root& ogreRoot = Ogre::Root::getSingleton(); 64 64 -
code/branches/gui/src/orxonox/gamestates/GSIO.h
r1670 r1672 45 45 void enter(); 46 46 void leave(); 47 void ticked(float dt );47 void ticked(float dt, uint64_t time); 48 48 49 49 //Ogre::Timer* timer_; //!< Main loop timer -
code/branches/gui/src/orxonox/gamestates/GSIOConsole.cc
r1670 r1672 58 58 } 59 59 60 void GSIOConsole::ticked(float dt )60 void GSIOConsole::ticked(float dt, uint64_t time) 61 61 { 62 while (!this->hasScheduledTransition()) 63 { 64 std::string command; 65 std::cin >> command; 66 CommandExecutor::execute(command, true); 67 } 62 std::string command; 63 std::getline(std::cin, command); 64 CommandExecutor::execute(command, true); 65 66 tickChild(dt, time); 68 67 } 69 68 } -
code/branches/gui/src/orxonox/gamestates/GSIOConsole.h
r1670 r1672 45 45 void enter(); 46 46 void leave(); 47 void ticked(float dt );47 void ticked(float dt, uint64_t time); 48 48 }; 49 49 } -
code/branches/gui/src/orxonox/gamestates/GSLevel.cc
r1670 r1672 96 96 } 97 97 98 void GSLevel::ticked(float dt )98 void GSLevel::ticked(float dt, uint64_t time) 99 99 { 100 100 // Call those objects that need the real time -
code/branches/gui/src/orxonox/gamestates/GSLevel.h
r1670 r1672 49 49 virtual void enter(); 50 50 virtual void leave(); 51 virtual void ticked(float dt );51 virtual void ticked(float dt, uint64_t time); 52 52 53 53 void loadLevel(); -
code/branches/gui/src/orxonox/gamestates/GSRoot.cc
r1670 r1672 41 41 #include "core/Core.h" 42 42 #include "core/CommandLine.h" 43 #include "core/TclThreadManager.h" 43 44 #include "GraphicsEngine.h" 44 45 #include "Settings.h" … … 49 50 50 51 GSRoot::GSRoot() 51 : GameState("root")52 : RootGameState("root") 52 53 , settings_(0) 53 54 , graphicsEngine_(0) 54 , bExit_(false)55 55 { 56 56 } … … 113 113 // initialise TCL 114 114 TclBind::getInstance().setDataPath(Settings::getDataPath()); 115 TclThreadManager::getInstance(); 115 116 116 117 // initialise graphics engine. Doesn't load the render window yet! … … 118 119 graphicsEngine_->setup(); // creates ogre root and other essentials 119 120 120 // console commands121 FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::loadGame);122 functor ->setObject(this);123 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor , "loadGame"));121 // add console commands 122 FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame); 123 functor1->setObject(this); 124 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "exit")); 124 125 125 126 // add console commands 126 functor = createFunctor(&GSRoot::exitGame);127 functor ->setObject(this);128 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor , "exit"));127 FunctorMember01<GameState, const std::string&>* functor2 = createFunctor(&GameState::requestState); 128 functor2->setObject(this); 129 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "selectGameState")); 129 130 } 130 131 … … 137 138 } 138 139 139 void GSRoot::ticked(float dt )140 void GSRoot::ticked(float dt, uint64_t time) 140 141 { 141 this->tickChild(dt); 142 } 142 TclThreadManager::getInstance().tick(dt); 143 143 144 /** 145 @brief 146 Requests a state. 147 */ 148 void GSRoot::loadGame(const std::string& name) 149 { 150 this->requestState(name); 144 this->tickChild(dt, time); 151 145 } 152 146 } -
code/branches/gui/src/orxonox/gamestates/GSRoot.h
r1670 r1672 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include "core/ GameState.h"33 #include "core/RootGameState.h" 34 34 35 35 namespace orxonox 36 36 { 37 class _OrxonoxExport GSRoot : public GameState37 class _OrxonoxExport GSRoot : public RootGameState 38 38 { 39 39 public: … … 42 42 43 43 void feedCommandLine(int argc, char** argv); 44 void loadGame(const std::string& name);45 44 46 45 void exitGame() 47 46 { requestState("root"); } 48 bool isGameFinished() { return (this->getActiveChild() == 0); }49 47 50 48 private: 51 49 void enter(); 52 50 void leave(); 53 void ticked(float dt );51 void ticked(float dt, uint64_t time); 54 52 55 53 Settings* settings_; 56 GraphicsEngine* graphicsEngine_; //!< our dearest graphics engine <3 57 bool bExit_; 54 GraphicsEngine* graphicsEngine_; //!< Interface to Ogre 58 55 }; 59 56 } 60 57 61 #endif /* _GS Graphics_H__ */58 #endif /* _GSRoot_H__ */ -
code/branches/gui/src/orxonox/gamestates/GSServer.cc
r1670 r1672 83 83 } 84 84 85 void GSServer::ticked(float dt )85 void GSServer::ticked(float dt, uint64_t time) 86 86 { 87 GSLevel::ticked(dt );87 GSLevel::ticked(dt, time); 88 88 server_->tick(dt); 89 this->tickChild(dt );89 this->tickChild(dt, time); 90 90 } 91 91 } -
code/branches/gui/src/orxonox/gamestates/GSServer.h
r1670 r1672 46 46 void enter(); 47 47 void leave(); 48 void ticked(float dt );48 void ticked(float dt, uint64_t time); 49 49 50 50 network::Server* server_; -
code/branches/gui/src/orxonox/gamestates/GSStandalone.cc
r1670 r1672 70 70 } 71 71 72 void GSStandalone::ticked(float dt )72 void GSStandalone::ticked(float dt, uint64_t time) 73 73 { 74 GSLevel::ticked(dt );74 GSLevel::ticked(dt, time); 75 75 76 this->tickChild(dt );76 this->tickChild(dt, time); 77 77 } 78 78 } -
code/branches/gui/src/orxonox/gamestates/GSStandalone.h
r1670 r1672 45 45 void enter(); 46 46 void leave(); 47 void ticked(float dt );47 void ticked(float dt, uint64_t time); 48 48 }; 49 49 }
Note: See TracChangeset
for help on using the changeset viewer.