Changeset 2844 for code/branches/gui/src/orxonox/gamestates
- Timestamp:
- Mar 25, 2009, 5:23:00 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
r2817 r2844 35 35 #include "core/Core.h" 36 36 #include "network/Client.h" 37 #include "core/Game.h" 37 38 38 39 namespace orxonox 39 40 { 41 AddGameState(GSClient, "client"); 42 40 43 SetCommandLineArgument(ip, "127.0.0.1").information("#.#.#.#"); 41 44 42 GSClient::GSClient( )43 : GameState( "client")45 GSClient::GSClient(const std::string& name) 46 : GameState(name) 44 47 , client_(0) 45 48 { … … 50 53 } 51 54 52 void GSClient:: enter()55 void GSClient::activate() 53 56 { 54 57 Core::setIsClient(true); … … 59 62 ThrowException(InitialisationFailed, "Could not establish connection with server."); 60 63 61 GSLevel::enter();62 63 64 client_->update(Core::getGameClock()); 64 65 } 65 66 66 void GSClient:: leave()67 void GSClient::deactivate() 67 68 { 68 GSLevel::leave();69 70 69 client_->closeConnection(); 71 70 … … 76 75 } 77 76 78 void GSClient:: ticked(const Clock& time)77 void GSClient::update(const Clock& time) 79 78 { 80 GSLevel::ticked(time);81 79 client_->update(time); 82 83 this->tickChild(time);84 80 } 85 81 } -
code/branches/gui/src/orxonox/gamestates/GSClient.h
r2817 r2844 33 33 #include "core/GameState.h" 34 34 #include "network/NetworkPrereqs.h" 35 #include "GSLevel.h"36 35 37 36 namespace orxonox 38 37 { 39 class _OrxonoxExport GSClient : public GameState , public GSLevel38 class _OrxonoxExport GSClient : public GameState 40 39 { 41 40 public: 42 GSClient( );41 GSClient(const std::string& name); 43 42 ~GSClient(); 44 43 44 void activate(); 45 void deactivate(); 46 void update(const Clock& time); 45 47 46 48 private: 47 void enter();48 void leave();49 void ticked(const Clock& time);50 51 49 Client* client_; 52 50 }; -
code/branches/gui/src/orxonox/gamestates/GSDedicated.cc
r2817 r2844 37 37 #include "objects/Tickable.h" 38 38 #include "util/Sleep.h" 39 #include "core/Game.h" 39 40 40 41 namespace orxonox 41 42 { 42 GSDedicated::GSDedicated() 43 : GameState("dedicated") 43 AddGameState(GSDedicated, "dedicated"); 44 45 GSDedicated::GSDedicated(const std::string& name) 46 : GameState(name) 44 47 , server_(0) 45 48 , timeSinceLastUpdate_(0) … … 51 54 } 52 55 53 void GSDedicated:: enter()56 void GSDedicated::activate() 54 57 { 55 58 Core::setHasServer(true); … … 58 61 COUT(0) << "Loading scene in server mode" << std::endl; 59 62 60 GSLevel::enter();61 62 63 server_->open(); 63 64 } 64 65 65 void GSDedicated:: leave()66 void GSDedicated::deactivate() 66 67 { 67 GSLevel::leave();68 69 68 this->server_->close(); 70 69 delete this->server_; … … 73 72 } 74 73 75 void GSDedicated:: ticked(const Clock& time)74 void GSDedicated::update(const Clock& time) 76 75 { 77 76 // static float startTime = time.getSecondsPrecise(); … … 83 82 // COUT(0) << "estimated ticks/sec: " << nrOfTicks/(time.getSecondsPrecise()-startTime) << endl; 84 83 timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD; 85 GSLevel::ticked(time);86 84 server_->update(time); 87 this->tickChild(time);88 85 } 89 86 else -
code/branches/gui/src/orxonox/gamestates/GSDedicated.h
r2817 r2844 33 33 #include "core/GameState.h" 34 34 #include "network/NetworkPrereqs.h" 35 #include "GSLevel.h"36 35 37 36 namespace orxonox 38 37 { 39 class _OrxonoxExport GSDedicated : public GameState , public GSLevel38 class _OrxonoxExport GSDedicated : public GameState 40 39 { 41 40 public: 42 GSDedicated( );41 GSDedicated(const std::string& name); 43 42 ~GSDedicated(); 44 43 44 void activate(); 45 void deactivate(); 46 void update(const Clock& time); 47 45 48 private: 46 void enter(); 47 void leave(); 48 void ticked(const Clock& time); 49 50 Server* server_; 51 float timeSinceLastUpdate_; 49 Server* server_; 50 float timeSinceLastUpdate_; 52 51 }; 53 52 } -
code/branches/gui/src/orxonox/gamestates/GSGUI.cc
r2817 r2844 32 32 #include <OgreViewport.h> 33 33 #include "core/Clock.h" 34 #include "core/ConsoleCommand.h" 34 35 #include "core/input/InputManager.h" 35 36 #include "core/input/SimpleInputState.h" 36 37 #include "gui/GUIManager.h" 37 38 #include "GraphicsManager.h" 39 #include "core/Game.h" 38 40 39 41 namespace orxonox 40 42 { 41 GSGUI::GSGUI() 42 : GameState("gui") 43 AddGameState(GSGUI, "gui"); 44 45 GSGUI::GSGUI(const std::string& name) 46 : GameState(name) 43 47 { 44 48 } … … 48 52 } 49 53 50 void GSGUI:: enter()54 void GSGUI::activate() 51 55 { 52 56 guiManager_ = GUIManager::getInstancePtr(); … … 56 60 guiManager_->showGUI("MainMenu", 0); 57 61 GraphicsManager::getInstance().getViewport()->setCamera(guiManager_->getCamera()); 62 63 { 64 // time factor console command 65 FunctorMember<GSGUI>* functor = createFunctor(&GSGUI::startGame); 66 functor->setObject(this); 67 this->ccStartGame_ = createConsoleCommand(functor, "startGame"); 68 CommandExecutor::addConsoleCommandShortcut(this->ccStartGame_); 69 } 58 70 } 59 71 60 void GSGUI:: leave()72 void GSGUI::deactivate() 61 73 { 74 if (this->ccStartGame_) 75 { 76 delete this->ccStartGame_; 77 this->ccStartGame_ = 0; 78 } 79 62 80 guiManager_->hideGUI(); 63 81 } 64 82 65 void GSGUI:: ticked(const Clock& time)83 void GSGUI::update(const Clock& time) 66 84 { 67 85 // tick CEGUI 68 86 guiManager_->update(time); 87 } 69 88 70 this->tickChild(time); 89 void GSGUI::startGame() 90 { 91 // HACK - HACK 92 Game::getInstance().popState(); 93 Game::getInstance().requestState("standalone"); 94 Game::getInstance().requestState("level"); 71 95 } 72 96 } -
code/branches/gui/src/orxonox/gamestates/GSGUI.h
r2817 r2844 38 38 { 39 39 public: 40 GSGUI( );40 GSGUI(const std::string& name); 41 41 ~GSGUI(); 42 42 43 void activate(); 44 void deactivate(); 45 void update(const Clock& time); 46 47 void startGame(); 48 43 49 private: 44 void enter(); 45 void leave(); 46 void ticked(const Clock& time); 50 GUIManager* guiManager_; 47 51 48 GUIManager* guiManager_; 52 // console commands 53 ConsoleCommand* ccStartGame_; 49 54 }; 50 55 } -
code/branches/gui/src/orxonox/gamestates/GSGraphics.cc
r2817 r2844 45 45 #include "gui/GUIManager.h" 46 46 #include "GraphicsManager.h" 47 #include " Game.h"47 #include "core/Game.h" 48 48 49 49 namespace orxonox 50 50 { 51 GSGraphics::GSGraphics() 52 : GameState("graphics") 51 AddGameState(GSGraphics, "graphics"); 52 53 GSGraphics::GSGraphics(const std::string& name) 54 : GameState(name) 53 55 , inputManager_(0) 54 56 , console_(0) … … 60 62 { 61 63 RegisterRootObject(GSGraphics); 62 setConfigValues();63 64 } 64 65 … … 71 72 } 72 73 73 void GSGraphics:: enter()74 void GSGraphics::activate() 74 75 { 76 setConfigValues(); 77 75 78 Core::setShowsGraphics(true); 76 79 … … 108 111 } 109 112 110 void GSGraphics:: leave()113 void GSGraphics::deactivate() 111 114 { 112 115 if (Core::showsGraphics()) … … 146 149 need the time. So we shouldn't run into problems. 147 150 */ 148 void GSGraphics:: ticked(const Clock& time)151 void GSGraphics::update(const Clock& time) 149 152 { 150 153 uint64_t timeBeforeTick = time.getRealMicroseconds(); … … 152 155 this->inputManager_->update(time); // tick console 153 156 this->console_->update(time); 154 this->tickChild(time);155 157 156 158 uint64_t timeAfterTick = time.getRealMicroseconds(); -
code/branches/gui/src/orxonox/gamestates/GSGraphics.h
r2817 r2844 32 32 #include "OrxonoxPrereqs.h" 33 33 #include "core/GameState.h" 34 #include "core/OrxonoxClass.h"35 34 #include "tools/WindowEventListener.h" 36 35 … … 39 38 class _OrxonoxExport GSGraphics : public GameState, public WindowEventListener 40 39 { 41 friend class ClassIdentifier<GSGraphics>;42 43 40 public: 44 GSGraphics( );41 GSGraphics(const std::string& name); 45 42 ~GSGraphics(); 46 47 private: // functions48 void enter();49 void leave();50 void ticked(const Clock& time);51 52 43 void setConfigValues(); 53 44 45 void activate(); 46 void deactivate(); 47 void update(const Clock& time); 48 49 private: 54 50 // Window events from WindowEventListener 55 51 void windowResized(unsigned int newWidth, unsigned int newHeight); 56 52 void windowFocusChanged(); 57 53 58 private:59 54 // managed singletons 60 55 InputManager* inputManager_; -
code/branches/gui/src/orxonox/gamestates/GSIOConsole.cc
r2817 r2844 36 36 37 37 #include "core/ConsoleCommand.h" 38 #include "core/Game.h" 38 39 39 40 namespace orxonox 40 41 { 41 GSIOConsole::GSIOConsole() 42 : GameState("ioConsole") 42 AddGameState(GSIOConsole, "ioConsole"); 43 44 GSIOConsole::GSIOConsole(const std::string& name) 45 : GameState(name) 43 46 { 44 47 } … … 48 51 } 49 52 50 void GSIOConsole:: enter()53 void GSIOConsole::activate() 51 54 { 52 55 } 53 56 54 void GSIOConsole:: leave()57 void GSIOConsole::deactivate() 55 58 { 56 59 } 57 60 58 void GSIOConsole:: ticked(const Clock& time)61 void GSIOConsole::update(const Clock& time) 59 62 { 60 63 std::string command; 61 64 std::getline(std::cin, command); 62 65 CommandExecutor::execute(command, true); 63 64 tickChild(time);65 66 } 66 67 } -
code/branches/gui/src/orxonox/gamestates/GSIOConsole.h
r2817 r2844 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include <OgrePrerequisites.h>34 33 #include "core/GameState.h" 35 34 … … 39 38 { 40 39 public: 41 GSIOConsole( );40 GSIOConsole(const std::string& name); 42 41 ~GSIOConsole(); 43 42 43 void activate(); 44 void deactivate(); 45 void update(const Clock& time); 46 44 47 private: 45 void enter(); 46 void leave(); 47 void ticked(const Clock& time); 48 48 49 }; 49 50 } -
code/branches/gui/src/orxonox/gamestates/GSLevel.cc
r2817 r2844 47 47 #include "LevelManager.h" 48 48 #include "PlayerManager.h" 49 #include "core/Game.h" 49 50 50 51 namespace orxonox 51 52 { 53 AddGameState(GSLevel, "level"); 54 52 55 SetCommandLineArgument(level, "presentation.oxw").shortcut("l"); 53 56 54 GSLevel::GSLevel( )55 //: GameState(name)56 :keyBinder_(0)57 GSLevel::GSLevel(const std::string& name) 58 : GameState(name) 59 , keyBinder_(0) 57 60 , inputState_(0) 58 61 , radar_(0) … … 65 68 this->ccKeybind_ = 0; 66 69 this->ccTkeybind_ = 0; 67 70 } 71 72 GSLevel::~GSLevel() 73 { 74 } 75 76 void GSLevel::setConfigValues() 77 { 78 SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName="); 79 } 80 81 void GSLevel::activate() 82 { 68 83 setConfigValues(); 69 } 70 71 GSLevel::~GSLevel() 72 { 73 } 74 75 void GSLevel::setConfigValues() 76 { 77 SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName="); 78 } 79 80 void GSLevel::enter() 81 { 84 82 85 if (Core::showsGraphics()) 83 86 { … … 126 129 } 127 130 128 void GSLevel:: leave()131 void GSLevel::deactivate() 129 132 { 130 133 // destroy console commands … … 188 191 } 189 192 190 void GSLevel:: ticked(const Clock& time)191 { 192 // Commented by 1337: Temporarily moved to GSGraphics.193 void GSLevel::update(const Clock& time) 194 { 195 // Note: Temporarily moved to GSGraphics. 193 196 //// Call the scene objects 194 197 //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) … … 233 236 Command string that can be executed by the CommandExecutor 234 237 OR: Internal string "KeybindBindingStringKeyName=" used for the second call to identify 235 the key/button/axis that has been activated. This is configured above in enter().238 the key/button/axis that has been activated. This is configured above in activate(). 236 239 */ 237 240 void GSLevel::keybindInternal(const std::string& command, bool bTemporary) -
code/branches/gui/src/orxonox/gamestates/GSLevel.h
r2817 r2844 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include "core/OrxonoxClass.h" 33 34 #include "core/GameState.h" 34 #include "core/OrxonoxClass.h"35 35 36 36 namespace orxonox 37 37 { 38 class _OrxonoxExport GSLevel : public OrxonoxClass38 class _OrxonoxExport GSLevel : public GameState, public OrxonoxClass 39 39 { 40 friend class ClassIdentifier<GSLevel>;41 40 public: 42 GSLevel( );41 GSLevel(const std::string& name); 43 42 ~GSLevel(); 44 45 // was private before (is public now because of console command in GSStandalone)46 43 void setConfigValues(); 47 44 45 void activate(); 46 void deactivate(); 47 void update(const Clock& time); 48 48 49 protected: 49 void enter();50 void leave();51 void ticked(const Clock& time);52 53 50 void loadLevel(); 54 51 void unloadLevel(); -
code/branches/gui/src/orxonox/gamestates/GSRoot.cc
r2843 r2844 32 32 #include "util/Exception.h" 33 33 #include "util/Debug.h" 34 #include "core/Clock.h" 34 35 #include "core/Core.h" 35 #include "core/CoreIncludes.h"36 36 #include "core/ConsoleCommand.h" 37 37 #include "tools/TimeFactorListener.h" 38 38 #include "tools/Timer.h" 39 39 #include "objects/Tickable.h" 40 #include " Game.h"40 #include "core/Game.h" 41 41 42 42 namespace orxonox 43 43 { 44 GSRoot::GSRoot() 45 : RootGameState("root") 44 AddGameState(GSRoot, "root"); 45 46 GSRoot::GSRoot(const std::string& name) 47 : GameState(name) 46 48 , timeFactor_(1.0f) 47 49 , bPaused_(false) … … 56 58 } 57 59 58 void GSRoot:: enter()60 void GSRoot::activate() 59 61 { 60 62 // reset game speed to normal 61 63 timeFactor_ = 1.0f; 62 63 {64 // add console commands65 FunctorMember01<GameState, const std::string&>* functor = createFunctor(&GameState::requestState);66 functor->setObject(this);67 this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState");68 CommandExecutor::addConsoleCommandShortcut(this->ccSelectGameState_);69 }70 64 71 65 { … … 86 80 } 87 81 88 void GSRoot:: leave()82 void GSRoot::deactivate() 89 83 { 90 // destroy console commands91 delete this->ccSelectGameState_;92 93 84 if (this->ccSetTimeFactor_) 94 85 { … … 104 95 } 105 96 106 void GSRoot:: ticked(const Clock& time)97 void GSRoot::update(const Clock& time) 107 98 { 108 99 uint64_t timeBeforeTick = time.getRealMicroseconds(); … … 129 120 // Also add our tick time to the list in GSRoot 130 121 Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick); 131 132 this->tickChild(time);133 122 } 134 123 -
code/branches/gui/src/orxonox/gamestates/GSRoot.h
r2843 r2844 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include <list> 35 #include "core/RootGameState.h" 33 #include "core/GameState.h" 36 34 #include "core/OrxonoxClass.h" 37 35 38 36 namespace orxonox 39 37 { 40 class _OrxonoxExport GSRoot : public RootGameState38 class _OrxonoxExport GSRoot : public GameState 41 39 { 42 friend class ClassIdentifier<GSRoot>; 40 public: 41 GSRoot(const std::string& name); 42 ~GSRoot(); 43 43 44 public: 45 46 public: 47 GSRoot(); 48 ~GSRoot(); 44 void activate(); 45 void deactivate(); 46 void update(const Clock& time); 49 47 50 48 // this has to be public because proteced triggers a bug in msvc … … 55 53 56 54 private: 57 void enter();58 void leave();59 void ticked(const Clock& time);60 61 55 float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal. 62 56 bool bPaused_; … … 64 58 65 59 // console commands 66 ConsoleCommand* ccSelectGameState_;67 60 ConsoleCommand* ccSetTimeFactor_; 68 61 ConsoleCommand* ccPause_; -
code/branches/gui/src/orxonox/gamestates/GSServer.cc
r2817 r2844 33 33 #include "core/Core.h" 34 34 #include "network/Server.h" 35 #include "core/Game.h" 35 36 36 37 namespace orxonox 37 38 { 39 AddGameState(GSServer, "server"); 40 38 41 SetCommandLineArgument(port, 55556).shortcut("p").information("0-65535"); 39 42 40 GSServer::GSServer( )41 : GameState( "server")43 GSServer::GSServer(const std::string& name) 44 : GameState(name) 42 45 , server_(0) 43 46 { … … 48 51 } 49 52 50 void GSServer:: enter()53 void GSServer::activate() 51 54 { 52 55 Core::setHasServer(true); … … 55 58 COUT(0) << "Loading scene in server mode" << std::endl; 56 59 57 GSLevel::enter();58 59 60 server_->open(); 60 61 } 61 62 62 void GSServer:: leave()63 void GSServer::deactivate() 63 64 { 64 GSLevel::leave();65 66 65 this->server_->close(); 67 66 delete this->server_; … … 70 69 } 71 70 72 void GSServer:: ticked(const Clock& time)71 void GSServer::update(const Clock& time) 73 72 { 74 GSLevel::ticked(time);75 73 server_->update(time); 76 this->tickChild(time);77 74 } 78 75 } -
code/branches/gui/src/orxonox/gamestates/GSServer.h
r2817 r2844 33 33 #include "core/GameState.h" 34 34 #include "network/NetworkPrereqs.h" 35 #include "GSLevel.h"36 35 37 36 namespace orxonox 38 37 { 39 class _OrxonoxExport GSServer : public GameState , public GSLevel38 class _OrxonoxExport GSServer : public GameState 40 39 { 41 40 public: 42 GSServer( );41 GSServer(const std::string& name); 43 42 ~GSServer(); 44 43 44 void activate(); 45 void deactivate(); 46 void update(const Clock& time); 47 45 48 private: 46 void enter(); 47 void leave(); 48 void ticked(const Clock& time); 49 50 Server* server_; 49 Server* server_; 51 50 }; 52 51 } -
code/branches/gui/src/orxonox/gamestates/GSStandalone.cc
r2834 r2844 36 36 #include "gui/GUIManager.h" 37 37 #include "GraphicsManager.h" 38 #include "core/Game.h" 38 39 39 40 namespace orxonox 40 41 { 41 GSStandalone::GSStandalone() 42 : GameState("standalone") 42 AddGameState(GSStandalone, "standalone"); 43 44 GSStandalone::GSStandalone(const std::string& name) 45 : GameState(name) 43 46 { 44 47 } … … 49 52 50 53 51 void GSStandalone:: enter()54 void GSStandalone::activate() 52 55 { 53 56 Core::setIsStandalone(true); 54 55 GSLevel::enter();56 57 57 58 guiManager_ = GUIManager::getInstancePtr(); … … 60 61 } 61 62 62 void GSStandalone:: leave()63 void GSStandalone::deactivate() 63 64 { 64 GSLevel::leave();65 66 65 Core::setIsStandalone(false); 67 66 } 68 67 69 void GSStandalone:: ticked(const Clock& time)68 void GSStandalone::update(const Clock& time) 70 69 { 71 70 //Ogre::Viewport* viewport = GraphicsManager::getInstance().getViewport(); … … 77 76 // tick CEGUI 78 77 guiManager_->update(time); 79 80 GSLevel::ticked(time);81 this->tickChild(time);82 78 } 83 79 } -
code/branches/gui/src/orxonox/gamestates/GSStandalone.h
r2817 r2844 32 32 #include "OrxonoxPrereqs.h" 33 33 #include "core/GameState.h" 34 #include "GSLevel.h"35 34 36 35 namespace orxonox 37 36 { 38 class _OrxonoxExport GSStandalone : public GameState , public GSLevel37 class _OrxonoxExport GSStandalone : public GameState 39 38 { 40 39 public: 41 GSStandalone( );40 GSStandalone(const std::string& name); 42 41 ~GSStandalone(); 43 42 43 void activate(); 44 void deactivate(); 45 void update(const Clock& time); 46 44 47 private: 45 void enter(); 46 void leave(); 47 void ticked(const Clock& time); 48 49 GUIManager* guiManager_; 48 GUIManager* guiManager_; 50 49 }; 51 50 }
Note: See TracChangeset
for help on using the changeset viewer.