|
From: <xs...@us...> - 2006-05-21 19:02:08
|
Revision: 56 Author: xsdwx Date: 2006-05-21 12:01:41 -0700 (Sun, 21 May 2006) ViewCVS: http://svn.sourceforge.net/perceptioncrash/?rev=56&view=rev Log Message: ----------- -Game manager now logs correctly-Did some house cleaning-Started InputController class-Added some test code for InputControllerThe InputController seems buggy Modified Paths: -------------- trunk/perceptioncrash/src/GameManager.cpp trunk/perceptioncrash/src/GameManager.hpp trunk/perceptioncrash/src/InputManager.cpp trunk/perceptioncrash/src/InputManager.hpp trunk/perceptioncrash/src/IntroState.cpp trunk/perceptioncrash/src/IntroState.hpp trunk/perceptioncrash/src/PauseState.hpp trunk/perceptioncrash/src/PlayState.cpp trunk/perceptioncrash/src/PlayState.hpp Modified: trunk/perceptioncrash/src/GameManager.cpp =================================================================== --- trunk/perceptioncrash/src/GameManager.cpp 2006-05-21 18:45:39 UTC (rev 55) +++ trunk/perceptioncrash/src/GameManager.cpp 2006-05-21 19:01:41 UTC (rev 56) @@ -32,7 +32,7 @@ void GameManager::start(GameState* state) { - mRoot = new Ogre::Root(); + mRoot = new Ogre::Root("plugins.cfg", "ogre.cfg", "ogre.log"); setupResources(); @@ -174,9 +174,9 @@ { // Stateless code: if (e->getKey() == Ogre::KC_F12) - { - toggleDebugPanelOverlay(); - } + { + toggleDebugPanelOverlay(); + } // call keyPressed of current state mStates.back()->keyPressed(e); Modified: trunk/perceptioncrash/src/GameManager.hpp =================================================================== --- trunk/perceptioncrash/src/GameManager.hpp 2006-05-21 18:45:39 UTC (rev 55) +++ trunk/perceptioncrash/src/GameManager.hpp 2006-05-21 19:01:41 UTC (rev 56) @@ -33,7 +33,7 @@ void start(GameState* state); /** Change state to the specified state. - * + * * This exits the current state, pops it, pushes the new state and enters * it * @@ -42,7 +42,7 @@ void changeState(GameState* state); /** Push new state onto state stack - * + * * This pauses the current state, pushes the new state onto the game state * stack and enters it * @@ -51,7 +51,7 @@ void pushState(GameState* state); /** Pop current state off of state stack - * + * * This exits the current state, pops it off the state stack and resumes * the previous state (if any) */ @@ -59,7 +59,7 @@ /** Override standard Ogre::Singleton retrieval. - * + * * @remarks * * Why do we do this? Well, it's because the Singleton implementation is in @@ -67,16 +67,16 @@ * This is needed for the Singleton template to work, but we actually only * want it compiled into the implementation of the class based on the * Singleton, not all of them. If we don't change this, we get link errors - * when trying to use the Singleton-based class from an outside dll. + * when trying to use the Singleton-based class from an outside dll. * * This method just delegates to the template version anyway, but the * implementation stays in this single compilation unit, preventing link - * errors. + * errors. */ static GameManager& getSingleton(void); /** Override standard Ogre::Singleton retrieval. - * + * * @remarks * * Why do we do this? Well, it's because the Singleton implementation is in @@ -84,11 +84,11 @@ * This is needed for the Singleton template to work, but we actually only * want it compiled into the implementation of the class based on the * Singleton, not all of them. If we don't change this, we get link errors - * when trying to use the Singleton-based class from an outside dll. + * when trying to use the Singleton-based class from an outside dll. * * This method just delegates to the template version anyway, but the * implementation stays in this single compilation unit, preventing link - * errors. + * errors. */ static GameManager* getSingletonPtr(void); Modified: trunk/perceptioncrash/src/InputManager.cpp =================================================================== --- trunk/perceptioncrash/src/InputManager.cpp 2006-05-21 18:45:39 UTC (rev 55) +++ trunk/perceptioncrash/src/InputManager.cpp 2006-05-21 19:01:41 UTC (rev 56) @@ -33,3 +33,47 @@ assert(ms_Singleton); return *ms_Singleton; } + +InputController* +InputManager::createController(std::string name) +{ + if ( mControllers.find(name) == mControllers.end() ) + { + return mControllers[name] = new InputController(); + } + + // Name collision, return + return 0; +} + +void +InputManager::removeController(std::string name) +{ + std::map<std::string, InputController*>::iterator iter = mControllers.find(name); + if ( iter != mControllers.end() ) + { + delete iter->second; + mControllers.erase(iter); + } +} + +InputController* +InputManager::getController(std::string name) +{ + if ( mControllers.find(name) != mControllers.end() ) + { + return mControllers[name]; + } + + return 0; +} + +void +InputManager::updateAllControllers() +{ + std::map<std::string, InputController*>::iterator i; + for (i = mControllers.begin(); i != mControllers.end(); ++i) + { + i->second->update(); + } +} Modified: trunk/perceptioncrash/src/InputManager.hpp =================================================================== --- trunk/perceptioncrash/src/InputManager.hpp 2006-05-21 18:45:39 UTC (rev 55) +++ trunk/perceptioncrash/src/InputManager.hpp 2006-05-21 19:01:41 UTC (rev 56) @@ -4,23 +4,32 @@ #include <OgreSingleton.h> #include <OgreInput.h> +#include "InputController.hpp" + class InputManager : public Ogre::Singleton<InputManager> { public: InputManager(Ogre::RenderWindow* rwindow); virtual ~InputManager(); + static InputManager& getSingleton(void); + static InputManager* getSingletonPtr(void); + Ogre::InputReader* getInputDevice() const { return mInputDevice; } Ogre::EventProcessor* getEventProcessor() const { return mEventProcessor; } - static InputManager& getSingleton(void); - static InputManager* getSingletonPtr(void); + InputController* createController(std::string name); + void removeController(std::string name); + InputController* getController(std::string name); + void updateAllControllers(); private: Ogre::EventProcessor* mEventProcessor; Ogre::InputReader* mInputDevice; + + std::map<std::string, InputController*> mControllers; }; #endif /* PC_INPUT_MANAGER_HPP */ Modified: trunk/perceptioncrash/src/IntroState.cpp =================================================================== --- trunk/perceptioncrash/src/IntroState.cpp 2006-05-21 18:45:39 UTC (rev 55) +++ trunk/perceptioncrash/src/IntroState.cpp 2006-05-21 19:01:41 UTC (rev 56) @@ -13,15 +13,23 @@ mRoot = Ogre::Root::getSingletonPtr(); mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC); - mCamera = mSceneMgr->createCamera("IntroCamera"); - mViewport = mRoot->getAutoCreatedWindow()->addViewport(mCamera); + mCamera = mSceneMgr->createCamera("IntroCamera"); + mViewport = mRoot->getAutoCreatedWindow()->addViewport(mCamera); mViewport->setBackgroundColour( Ogre::ColourValue(0.0, 0.0, 0.0) ); mLogoOverlay = Ogre::OverlayManager::getSingleton().getByName("Overlays/Logo/LogoLargeGreenGlow"); - if (mLogoOverlay) + if (mLogoOverlay) mLogoOverlay->show(); - mExitGame = false; + mExitGame = false; + + mInputController = InputManager::getSingletonPtr()->createController("default"); + if ( !mInputController ) + mInputController = InputManager::getSingletonPtr()->getController("default"); + + mButton_StartGame = mInputController->registerButton("start_game", Ogre::KC_A); + if ( !mButton_StartGame ) + mButton_StartGame = mInputController->getButton("start_game"); } void @@ -30,9 +38,10 @@ if (mLogoOverlay) mLogoOverlay->hide(); - mSceneMgr->clearScene(); - mSceneMgr->destroyAllCameras(); + mSceneMgr->clearScene(); + mSceneMgr->destroyAllCameras(); mRoot->getAutoCreatedWindow()->removeAllViewports(); + mRoot->destroySceneManager(mSceneMgr); } void @@ -54,14 +63,14 @@ IntroState::keyPressed(Ogre::KeyEvent* e) { if (e->getKey() == Ogre::KC_SPACE) - { - changeState(PlayState::getInstance()); - } + { + changeState(PlayState::getInstance()); + } if (e->getKey() == Ogre::KC_ESCAPE) - { - mExitGame = true; - } + { + mExitGame = true; + } } void @@ -72,14 +81,20 @@ bool IntroState::frameStarted(const Ogre::FrameEvent& evt) { - return true; + InputManager::getSingletonPtr()->updateAllControllers(); + if ( mButton_StartGame->isDown() ) + { + Ogre::LogManager::getSingleton().logMessage("start_game is down"); + } + + return true; } bool IntroState::frameEnded(const Ogre::FrameEvent& evt) { - if (mExitGame) - return false; + if (mExitGame) + return false; - return true; + return true; } Modified: trunk/perceptioncrash/src/IntroState.hpp =================================================================== --- trunk/perceptioncrash/src/IntroState.hpp 2006-05-21 18:45:39 UTC (rev 55) +++ trunk/perceptioncrash/src/IntroState.hpp 2006-05-21 19:01:41 UTC (rev 56) @@ -7,7 +7,7 @@ class IntroState : public GameState { -public: + public: void enter(); void exit(); @@ -23,7 +23,7 @@ static IntroState* getInstance() { return &mIntroState; } -protected: + protected: IntroState() { } Ogre::Root *mRoot; @@ -32,13 +32,16 @@ Ogre::InputReader* mInputDevice; Ogre::Camera* mCamera; + InputController* mInputController; + InputControllerButton* mButton_StartGame; + // This is temporary and should probably be replaced with some CEGUI stuff // It currently just shows the Core/DebugOverlay overlay Ogre::Overlay* mLogoOverlay; bool mExitGame; -private: + private: static IntroState mIntroState; }; Modified: trunk/perceptioncrash/src/PauseState.hpp =================================================================== --- trunk/perceptioncrash/src/PauseState.hpp 2006-05-21 18:45:39 UTC (rev 55) +++ trunk/perceptioncrash/src/PauseState.hpp 2006-05-21 19:01:41 UTC (rev 56) @@ -7,7 +7,7 @@ class PauseState : public GameState { -public: + public: void enter(); void exit(); @@ -21,8 +21,8 @@ bool frameEnded(const Ogre::FrameEvent& evt); static PauseState* getInstance() { return &mPauseState; } - -protected: + + protected: PauseState() { } Ogre::Root *mRoot; @@ -30,8 +30,8 @@ Ogre::Viewport* mViewport; Ogre::InputReader* mInputDevice; Ogre::Camera* mCamera; - -private: + + private: static PauseState mPauseState; }; Modified: trunk/perceptioncrash/src/PlayState.cpp =================================================================== --- trunk/perceptioncrash/src/PlayState.cpp 2006-05-21 18:45:39 UTC (rev 55) +++ trunk/perceptioncrash/src/PlayState.cpp 2006-05-21 19:01:41 UTC (rev 56) @@ -33,7 +33,7 @@ // sdw: This line causes me to crash, i don't know why. It works fine in another // project, and used to in this one, until something must have changed. - rgm->loadResourceGroup(rgm->getWorldResourceGroupName(), false, true); + //rgm->loadResourceGroup(rgm->getWorldResourceGroupName(), false, true); mSceneMgr->setAmbientLight(Ogre::ColourValue(1, 1, 1)); @@ -44,7 +44,7 @@ mCamera->setFixedYawAxis(true, Ogre::Vector3::UNIT_Z); mLogoOverlay = Ogre::OverlayManager::getSingleton().getByName("Overlays/Logo/LogoCornerGreenGlow"); - if (mLogoOverlay) + if (mLogoOverlay) mLogoOverlay->show(); } @@ -59,6 +59,7 @@ mSceneMgr->clearScene(); mSceneMgr->destroyAllCameras(); mRoot->getAutoCreatedWindow()->removeAllViewports(); + mRoot->destroySceneManager(mSceneMgr); } void Modified: trunk/perceptioncrash/src/PlayState.hpp =================================================================== --- trunk/perceptioncrash/src/PlayState.hpp 2006-05-21 18:45:39 UTC (rev 55) +++ trunk/perceptioncrash/src/PlayState.hpp 2006-05-21 19:01:41 UTC (rev 56) @@ -7,7 +7,7 @@ class PlayState : public GameState { -public: + public: void enter(); void exit(); @@ -28,7 +28,7 @@ static PlayState* getInstance() { return &mPlayState; } -protected: + protected: PlayState() { } Ogre::Root *mRoot; @@ -37,7 +37,7 @@ Ogre::Camera* mCamera; Ogre::Overlay* mLogoOverlay; -private: + private: static PlayState mPlayState; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |