|
From: <sik...@us...> - 2006-05-22 08:22:33
|
Revision: 58 Author: sik0fewl Date: 2006-05-22 01:22:17 -0700 (Mon, 22 May 2006) ViewCVS: http://svn.sourceforge.net/perceptioncrash/?rev=58&view=rev Log Message: ----------- New input system - Mouse motion events still don't work - buttons still need to be mapped. We'll need to discuss this a bit, I think Modified Paths: -------------- trunk/perceptioncrash/src/GameManager.cpp trunk/perceptioncrash/src/GameManager.hpp trunk/perceptioncrash/src/GameState.hpp trunk/perceptioncrash/src/InputController.hpp trunk/perceptioncrash/src/InputManager.cpp trunk/perceptioncrash/src/IntroState.cpp trunk/perceptioncrash/src/IntroState.hpp trunk/perceptioncrash/src/PauseState.cpp trunk/perceptioncrash/src/PauseState.hpp trunk/perceptioncrash/src/PlayState.cpp trunk/perceptioncrash/src/PlayState.hpp Added Paths: ----------- trunk/perceptioncrash/src/KeyboardMouseInputController.cpp trunk/perceptioncrash/src/KeyboardMouseInputController.hpp Removed Paths: ------------- trunk/perceptioncrash/src/InputController.cpp Modified: trunk/perceptioncrash/src/GameManager.cpp =================================================================== --- trunk/perceptioncrash/src/GameManager.cpp 2006-05-21 19:22:25 UTC (rev 57) +++ trunk/perceptioncrash/src/GameManager.cpp 2006-05-22 08:22:17 UTC (rev 58) @@ -42,8 +42,10 @@ mRoot->addFrameListener(this); mInputManager = new InputManager(mRoot->getAutoCreatedWindow()); - mInputManager->getEventProcessor()->addKeyListener(this); - mInputManager->getEventProcessor()->addMouseMotionListener(this); + mInputController = mInputManager->createController("default"); + mInputController->addEventListener(this); + //mInputManager->getEventProcessor()->addKeyListener(this); + //mInputManager->getEventProcessor()->addMouseMotionListener(this); mDebugPanelOverlay = Ogre::OverlayManager::getSingleton().getByName("Core/DebugOverlay"); @@ -163,30 +165,23 @@ } void -GameManager::keyClicked(Ogre::KeyEvent* e) +GameManager::buttonPressed(InputControllerEvent* e) { - // call keyClicked of current state - mStates.back()->keyClicked(e); -} - -void -GameManager::keyPressed(Ogre::KeyEvent* e) -{ // Stateless code: - if (e->getKey() == Ogre::KC_F12) + if (e->getButton() == "toggle_fps") { toggleDebugPanelOverlay(); } - // call keyPressed of current state - mStates.back()->keyPressed(e); + // call buttonPressed of current state + mStates.back()->buttonPressed(e); } void -GameManager::keyReleased(Ogre::KeyEvent* e) +GameManager::buttonReleased(InputControllerEvent* e) { - // call keyReleased of current state - mStates.back()->keyReleased(e); + // call buttonReleased of current state + mStates.back()->buttonReleased(e); } void @@ -213,6 +208,9 @@ bool GameManager::frameStarted(const Ogre::FrameEvent& evt) { + // update controllers + mInputManager->updateAllControllers(); + // call frameStarted of current state return mStates.back()->frameStarted(evt); } Modified: trunk/perceptioncrash/src/GameManager.hpp =================================================================== --- trunk/perceptioncrash/src/GameManager.hpp 2006-05-21 19:22:25 UTC (rev 57) +++ trunk/perceptioncrash/src/GameManager.hpp 2006-05-22 08:22:17 UTC (rev 58) @@ -7,14 +7,14 @@ #include <OgreSingleton.h> #include "InputManager.hpp" +#include "InputController.hpp" class GameState; /** Main game class. */ class GameManager : public Ogre::FrameListener, - public Ogre::KeyListener, - public Ogre::MouseMotionListener, + public InputControllerListener, public Ogre::Singleton<GameManager> { public: @@ -93,24 +93,24 @@ static GameManager* getSingletonPtr(void); protected: - /** OGRE Root */ + /** Ogre Root */ Ogre::Root* mRoot; /** Render window */ Ogre::RenderWindow* mRenderWindow; /** Input manager */ InputManager* mInputManager; + /** Controller */ + InputController* mInputController; /** Setup resource locations */ void setupResources(void); /** Configure OGRE */ bool configure(void); - /** Ogre::KeyListener keyClicked event */ - void keyClicked(Ogre::KeyEvent* e); /** Ogre::KeyListener keyPressed event */ - void keyPressed(Ogre::KeyEvent* e); + void buttonPressed(InputControllerEvent* e); /** Ogre::KeyListener keyReleased event */ - void keyReleased(Ogre::KeyEvent* e); + void buttonReleased(InputControllerEvent* e); /** Ogre::MouseMotionListener mouseMoved event */ void mouseMoved(Ogre::MouseEvent* e); Modified: trunk/perceptioncrash/src/GameState.hpp =================================================================== --- trunk/perceptioncrash/src/GameState.hpp 2006-05-21 19:22:25 UTC (rev 57) +++ trunk/perceptioncrash/src/GameState.hpp 2006-05-22 08:22:17 UTC (rev 58) @@ -16,9 +16,8 @@ virtual void pause() = 0; virtual void resume() = 0; - virtual void keyClicked(Ogre::KeyEvent* e) { } - virtual void keyPressed(Ogre::KeyEvent* e) { } - virtual void keyReleased(Ogre::KeyEvent* e) { } + virtual void buttonPressed(InputControllerEvent* e) { } + virtual void buttonReleased(InputControllerEvent* e) { } virtual void mouseMoved(Ogre::MouseEvent* e) { } virtual void mouseDragged(Ogre::MouseEvent* e) { } Deleted: trunk/perceptioncrash/src/InputController.cpp =================================================================== --- trunk/perceptioncrash/src/InputController.cpp 2006-05-21 19:22:25 UTC (rev 57) +++ trunk/perceptioncrash/src/InputController.cpp 2006-05-22 08:22:17 UTC (rev 58) @@ -1,79 +0,0 @@ -#include "InputController.hpp" -#include "InputManager.hpp" - -InputController::~InputController() -{ - std::map<std::string, InputControllerButton*>::iterator i; - for (i = mButtons.begin(); i != mButtons.end(); ++i) - { - delete i->second; - } -} - -void -InputController::update() -{ - Ogre::InputReader* inpReader = InputManager::getSingleton().getInputDevice(); - inpReader->capture(); - - std::map<std::string, InputControllerButton*>::iterator i; - for (i = mButtons.begin(); i != mButtons.end(); ++i) - { - if ( i->second->getButtonType() == BT_KEYBOARD ) - { - i->second->setDown( inpReader->isKeyDown(static_cast<Ogre::KeyCode>(i->second->getButton())) ); - } - else if ( i->second->getButtonType() == BT_MOUSE ) - { - i->second->setDown( inpReader->getMouseButton(i->second->getButton()) ); - } - } -} -InputControllerButton* -InputController::registerButton(std::string name, int button, int type) -{ - if ( mButtons.find(name) == mButtons.end() ) - { - return mButtons[name] = new InputControllerButton(button, type); - } - - return 0; -} - -void -InputController::unregisterButton(std::string name) -{ - std::map<std::string, InputControllerButton*>::iterator i = mButtons.find(name); - if ( i != mButtons.end() ) - { - delete i->second; - mButtons.erase(i); - } -} - -InputControllerButton* -InputController::getButton(std::string name) -{ - std::map<std::string, InputControllerButton*>::iterator i = mButtons.find(name); - if ( i != mButtons.end() ) - { - return i->second; - } - - return 0; -} - -InputControllerButton* -InputController::getButton(int button) -{ - std::map<std::string, InputControllerButton*>::iterator i; - for (i = mButtons.begin(); i != mButtons.end(); ++i) - { - if ( i->second->getButton() == button ) - { - return i->second; - } - } - - return 0; -} Modified: trunk/perceptioncrash/src/InputController.hpp =================================================================== --- trunk/perceptioncrash/src/InputController.hpp 2006-05-21 19:22:25 UTC (rev 57) +++ trunk/perceptioncrash/src/InputController.hpp 2006-05-22 08:22:17 UTC (rev 58) @@ -4,51 +4,59 @@ #include <map> #include <string> -enum BUTTON_TYPE -{ - BT_KEYBOARD = 0, - BT_MOUSE -}; +class InputControllerListener; +class InputControllerEvent; -class InputControllerButton +class InputController { public: - InputControllerButton(int button, int type) - : mDown(false), mButton(button), mButtonType(type) { } + virtual ~InputController() { } + + typedef std::string Button; + + virtual bool isButtonDown(Button button) = 0; - bool isDown() const - { return mDown; } - void setDown(bool value) - { mDown = value; } + virtual void addEventListener(InputControllerListener* l) + { + /// @todo Check to make sure 'l' isn't already registered + mInputControllerListeners.push_back(l); + } - int getButton() const - { return mButton; } - int getButtonType() const - { return mButtonType; } + virtual void removeEventListener(InputControllerListener* l) + { + /// @todo throw exception if listener isn't in list + std::vector<InputControllerListener*>* icl = &mInputControllerListeners; + icl->erase(std::remove(icl->begin(), icl->end(), l)); + } - private: - bool mDown; + // For controllers that need to update there state every frame + virtual void update() { } - int mButton; - int mButtonType; + protected: + std::map<Button, bool> mButtonStates; + std::vector<InputControllerListener*> mInputControllerListeners; }; -class InputController +class InputControllerListener { public: - InputController() { } - ~InputController(); + virtual ~InputControllerListener() { } + virtual void buttonPressed(InputControllerEvent* e) = 0; + virtual void buttonReleased(InputControllerEvent* e) = 0; +}; - void update(); +class InputControllerEvent +{ + public: + InputControllerEvent(InputController::Button& button) + { mButton = button; } - InputControllerButton* registerButton(std::string name, int button, int type = 0); - void unregisterButton(std::string name); + InputController::Button getButton() + { return mButton; } - InputControllerButton* getButton(std::string name); - InputControllerButton* getButton(int button); - private: - std::map<std::string, InputControllerButton*> mButtons; + InputController::Button mButton; }; + #endif /* PC_INPUT_CONTROLLER_HPP */ Modified: trunk/perceptioncrash/src/InputManager.cpp =================================================================== --- trunk/perceptioncrash/src/InputManager.cpp 2006-05-21 19:22:25 UTC (rev 57) +++ trunk/perceptioncrash/src/InputManager.cpp 2006-05-22 08:22:17 UTC (rev 58) @@ -1,3 +1,5 @@ +#include <stdexcept> + #include <OgreEventProcessor.h> #include <OgrePlatformManager.h> @@ -2,2 +4,3 @@ #include "InputManager.hpp" +#include "KeyboardMouseInputController.hpp" @@ -39,11 +42,10 @@ { if ( mControllers.find(name) == mControllers.end() ) { - return mControllers[name] = new InputController(); + return mControllers[name] = new KeyboardMouseInputController(); } - // Name collision, return - return 0; + throw std::runtime_error("Controller '" + name + "' already exists"); } void @@ -65,7 +67,7 @@ return mControllers[name]; } - return 0; + throw std::runtime_error("Controller '" + name + "' does not exist"); } void Modified: trunk/perceptioncrash/src/IntroState.cpp =================================================================== --- trunk/perceptioncrash/src/IntroState.cpp 2006-05-21 19:22:25 UTC (rev 57) +++ trunk/perceptioncrash/src/IntroState.cpp 2006-05-22 08:22:17 UTC (rev 58) @@ -1,5 +1,4 @@ #include <Ogre.h> -#include <OgreKeyEvent.h> #include "IntroState.hpp" #include "PlayState.hpp" @@ -9,7 +8,6 @@ void IntroState::enter() { - mInputDevice = InputManager::getSingletonPtr()->getInputDevice(); mRoot = Ogre::Root::getSingletonPtr(); mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC); @@ -22,14 +20,6 @@ mLogoOverlay->show(); 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 @@ -55,38 +45,27 @@ } void -IntroState::keyClicked(Ogre::KeyEvent* e) +IntroState::buttonPressed(InputControllerEvent* e) { -} - -void -IntroState::keyPressed(Ogre::KeyEvent* e) -{ - if (e->getKey() == Ogre::KC_SPACE) + if (e->getButton() == "select") { changeState(PlayState::getInstance()); } - if (e->getKey() == Ogre::KC_ESCAPE) + if (e->getButton() == "back") { mExitGame = true; } } void -IntroState::keyReleased(Ogre::KeyEvent* e) +IntroState::buttonReleased(InputControllerEvent* e) { } bool IntroState::frameStarted(const Ogre::FrameEvent& evt) { - InputManager::getSingletonPtr()->updateAllControllers(); - if ( mButton_StartGame->isDown() ) - { - Ogre::LogManager::getSingleton().logMessage("start_game is down"); - } - return true; } Modified: trunk/perceptioncrash/src/IntroState.hpp =================================================================== --- trunk/perceptioncrash/src/IntroState.hpp 2006-05-21 19:22:25 UTC (rev 57) +++ trunk/perceptioncrash/src/IntroState.hpp 2006-05-22 08:22:17 UTC (rev 58) @@ -4,6 +4,7 @@ #include <Ogre.h> #include "GameState.hpp" +#include "InputController.hpp" class IntroState : public GameState { @@ -14,9 +15,8 @@ void pause(); void resume(); - void keyClicked(Ogre::KeyEvent* e); - void keyPressed(Ogre::KeyEvent* e); - void keyReleased(Ogre::KeyEvent* e); + void buttonPressed(InputControllerEvent* e); + void buttonReleased(InputControllerEvent* e); bool frameStarted(const Ogre::FrameEvent& evt); bool frameEnded(const Ogre::FrameEvent& evt); @@ -29,14 +29,10 @@ Ogre::Root *mRoot; Ogre::SceneManager* mSceneMgr; Ogre::Viewport* mViewport; - 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; Added: trunk/perceptioncrash/src/KeyboardMouseInputController.cpp =================================================================== --- trunk/perceptioncrash/src/KeyboardMouseInputController.cpp (rev 0) +++ trunk/perceptioncrash/src/KeyboardMouseInputController.cpp 2006-05-22 08:22:17 UTC (rev 58) @@ -0,0 +1,177 @@ +#include <Ogre.h> + +#include "KeyboardMouseInputController.hpp" + +KeyboardMouseInputController::KeyboardMouseInputController() +{ + /// @todo this can be implemented with events(current) or unbuffered input. + /// which is better? + InputManager* inputManager = InputManager::getSingletonPtr(); + inputManager->getEventProcessor()->addKeyListener(this); + inputManager->getEventProcessor()->addMouseMotionListener(this); + + /// @todo Remove this. This is just for testing. + mKeyboardMap.insert(std::pair<int, Button>(Ogre::KC_SPACE, "select")); +} + +KeyboardMouseInputController::~KeyboardMouseInputController() +{ + InputManager* inputManager = InputManager::getSingletonPtr(); + inputManager->getEventProcessor()->removeKeyListener(this); + inputManager->getEventProcessor()->removeMouseMotionListener(this); +} + +bool +KeyboardMouseInputController::isButtonDown(Button button) +{ + return mButtonStates[button]; +} + +void +KeyboardMouseInputController::keyClicked(Ogre::KeyEvent* e) +{ +} + +void +KeyboardMouseInputController::keyPressed(Ogre::KeyEvent* e) +{ + /// @todo less code repetition in these event functions + + std::vector<Button> pressed; + + // Build a list of pushed buttons (single keys can map to more than one + // button) and update button states + for (std::multimap<int, Button>::iterator i = mKeyboardMap.begin(); + i != mKeyboardMap.end(); + i++) + { + mButtonStates[i->second] = true; + pressed.push_back(i->second); + } + + // Fire events + for (std::vector<Button>::iterator i = pressed.begin(); i != pressed.end(); i++) + { + InputControllerEvent event(*i); + for (std::vector<InputControllerListener*>::iterator j = mInputControllerListeners.begin(); + j != mInputControllerListeners.end(); + j++) + { + (*j)->buttonPressed(&event); + } + } +} + +void +KeyboardMouseInputController::keyReleased(Ogre::KeyEvent* e) +{ + std::vector<Button> released; + + // Build a list of pushed buttons (single keys can map to more than one + // button) and update button states + for (std::multimap<int, Button>::iterator i = mKeyboardMap.begin(); + i != mKeyboardMap.end(); + i++) + { + mButtonStates[i->second] = false; + released.push_back(i->second); + } + + // Fire events + for (std::vector<Button>::iterator i = released.begin(); i != released.end(); i++) + { + InputControllerEvent event(*i); + for (std::vector<InputControllerListener*>::iterator j = mInputControllerListeners.begin(); + j != mInputControllerListeners.end(); + j++) + { + (*j)->buttonReleased(&event); + } + } +} + +void +KeyboardMouseInputController::mouseClicked(Ogre::MouseEvent* e) +{ +} + +void +KeyboardMouseInputController::mouseEntered(Ogre::MouseEvent* e) +{ +} + +void +KeyboardMouseInputController::mouseExited(Ogre::MouseEvent* e) +{ +} + +void +KeyboardMouseInputController::mousePressed(Ogre::MouseEvent* e) +{ + std::vector<Button> pressed; + + // Build a list of pushed buttons (a single mouse button can map to more + // than one button) and update button states + for (std::multimap<int, Button>::iterator i = mMouseMap.begin(); + i != mMouseMap.end(); + i++) + { + mButtonStates[i->second] = true; + pressed.push_back(i->second); + } + + // Fire events + for (std::vector<Button>::iterator i = pressed.begin(); i != pressed.end(); i++) + { + InputControllerEvent event(*i); + for (std::vector<InputControllerListener*>::iterator j = mInputControllerListeners.begin(); + j != mInputControllerListeners.end(); + j++) + { + (*j)->buttonPressed(&event); + } + } +} + +void +KeyboardMouseInputController::mouseReleased(Ogre::MouseEvent* e) +{ + std::vector<Button> released; + + // Build a list of pushed buttons (a single mouse button can map to more + // than one button) and update button states + for (std::multimap<int, Button>::iterator i = mMouseMap.begin(); + i != mMouseMap.end(); + i++) + { + mButtonStates[i->second] = false; + released.push_back(i->second); + } + + // Fire events + for (std::vector<Button>::iterator i = released.begin(); i != released.end(); i++) + { + InputControllerEvent event(*i); + for (std::vector<InputControllerListener*>::iterator j = mInputControllerListeners.begin(); + j != mInputControllerListeners.end(); + j++) + { + (*j)->buttonReleased(&event); + } + } +} + +void +KeyboardMouseInputController::mouseMoved(Ogre::MouseEvent* e) +{ +} + +void +KeyboardMouseInputController::mouseDragged(Ogre::MouseEvent* e) +{ +} + +void +KeyboardMouseInputController::mouseDragMoved(Ogre::MouseEvent* e) +{ +} Property changes on: trunk/perceptioncrash/src/KeyboardMouseInputController.cpp ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native Added: trunk/perceptioncrash/src/KeyboardMouseInputController.hpp =================================================================== --- trunk/perceptioncrash/src/KeyboardMouseInputController.hpp (rev 0) +++ trunk/perceptioncrash/src/KeyboardMouseInputController.hpp 2006-05-22 08:22:17 UTC (rev 58) @@ -0,0 +1,52 @@ +#ifndef PC_KEYBOARD_MOUSE_INPUT_CONTROLLER_HPP +#define PC_KEYBOARD_MOUSE_INPUT_CONTROLLER_HPP + +#include <OgreEventListeners.h> +#include <OgreKeyEvent.h> + +#include "InputManager.hpp" +#include "InputController.hpp" + +class KeyboardMouseInputController : public InputController, + public Ogre::KeyListener, + public Ogre::MouseListener, + public Ogre::MouseMotionListener +{ + public: + KeyboardMouseInputController(); + ~KeyboardMouseInputController(); + + bool isButtonDown(Button button); + + protected: + /** Ogre::KeyListener keyClicked event */ + void keyClicked(Ogre::KeyEvent* e); + /** Ogre::KeyListener keyPressed event */ + void keyPressed(Ogre::KeyEvent* e); + /** Ogre::KeyListener keyReleased event */ + void keyReleased(Ogre::KeyEvent* e); + + /** Ogre::MouseListener mouseClicked event */ + void mouseClicked(Ogre::MouseEvent* e); + /** Ogre::MouseListener mouseEntered event */ + void mouseEntered(Ogre::MouseEvent* e); + /** Ogre::MouseListener mouseExited event */ + void mouseExited(Ogre::MouseEvent* e); + /** Ogre::MouseListener mousePressed event */ + void mousePressed(Ogre::MouseEvent* e); + /** Ogre::MouseListener mouseReleased event */ + void mouseReleased(Ogre::MouseEvent* e); + + /** Ogre::MouseMotionListener mouseMoved event */ + void mouseMoved(Ogre::MouseEvent* e); + /** Ogre::MouseMotionListener mouseDragged event */ + void mouseDragged(Ogre::MouseEvent* e); + /** Ogre::MouseMotionListener mouseDragMoved event */ + void mouseDragMoved(Ogre::MouseEvent* e); + + private: + std::multimap<int, Button> mKeyboardMap; + std::multimap<int, Button> mMouseMap; +}; + +#endif /* PC_KEYBOARD_MOUSE_INPUT_CONTROLLER_HPP */ Property changes on: trunk/perceptioncrash/src/KeyboardMouseInputController.hpp ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native Modified: trunk/perceptioncrash/src/PauseState.cpp =================================================================== --- trunk/perceptioncrash/src/PauseState.cpp 2006-05-21 19:22:25 UTC (rev 57) +++ trunk/perceptioncrash/src/PauseState.cpp 2006-05-22 08:22:17 UTC (rev 58) @@ -8,7 +8,6 @@ void PauseState::enter() { - mInputDevice = InputManager::getSingletonPtr()->getInputDevice(); mRoot = Ogre::Root::getSingletonPtr(); mViewport = mRoot->getAutoCreatedWindow()->getViewport(0); @@ -31,21 +30,16 @@ } void -PauseState::keyClicked(Ogre::KeyEvent* e) +PauseState::buttonPressed(InputControllerEvent* e) { -} - -void -PauseState::keyPressed(Ogre::KeyEvent* e) -{ - if (e->getKey() == Ogre::KC_P) + if (e->getButton() == "pause") { popState(); } } void -PauseState::keyReleased(Ogre::KeyEvent* e) +PauseState::buttonReleased(InputControllerEvent* e) { } Modified: trunk/perceptioncrash/src/PauseState.hpp =================================================================== --- trunk/perceptioncrash/src/PauseState.hpp 2006-05-21 19:22:25 UTC (rev 57) +++ trunk/perceptioncrash/src/PauseState.hpp 2006-05-22 08:22:17 UTC (rev 58) @@ -14,9 +14,8 @@ void pause(); void resume(); - void keyClicked(Ogre::KeyEvent* e); - void keyPressed(Ogre::KeyEvent* e); - void keyReleased(Ogre::KeyEvent* e); + void buttonPressed(InputControllerEvent* e); + void buttonReleased(InputControllerEvent* e); bool frameStarted(const Ogre::FrameEvent& evt); bool frameEnded(const Ogre::FrameEvent& evt); @@ -28,7 +27,7 @@ Ogre::Root *mRoot; Ogre::SceneManager* mSceneMgr; Ogre::Viewport* mViewport; - Ogre::InputReader* mInputDevice; + InputController* mInputController; Ogre::Camera* mCamera; private: Modified: trunk/perceptioncrash/src/PlayState.cpp =================================================================== --- trunk/perceptioncrash/src/PlayState.cpp 2006-05-21 19:22:25 UTC (rev 57) +++ trunk/perceptioncrash/src/PlayState.cpp 2006-05-22 08:22:17 UTC (rev 58) @@ -25,6 +25,8 @@ mCamera->setAspectRatio(Ogre::Real(mViewport->getActualWidth()) / Ogre::Real(mViewport->getActualHeight())); + mInputController = InputManager::getSingleton().getController("default"); + Ogre::ResourceGroupManager* rgm = Ogre::ResourceGroupManager::getSingletonPtr(); rgm->setWorldResourceGroupName("PlayStateResources"); rgm->linkWorldGeometryToResourceGroup(rgm->getWorldResourceGroupName(), @@ -74,29 +76,24 @@ } void -PlayState::keyClicked(Ogre::KeyEvent* e) +PlayState::buttonPressed(InputControllerEvent* e) { - if (e->getKey() == Ogre::KC_DOWN) + if (e->getButton() == "pause") { - mCamera->setPosition(mCamera->getPosition() - Ogre::Vector3(0, 1, 0)); - } -} - -void -PlayState::keyPressed(Ogre::KeyEvent* e) -{ - if (e->getKey() == Ogre::KC_P) - { pushState(PauseState::getInstance()); } - else if (e->getKey() == Ogre::KC_ESCAPE) + else if (e->getButton() == "back") { changeState(IntroState::getInstance()); } + else if (e->getButton() == "move_down") + { + mCamera->setPosition(mCamera->getPosition() - Ogre::Vector3(0, 1, 0)); + } } void -PlayState::keyReleased(Ogre::KeyEvent* e) +PlayState::buttonReleased(InputControllerEvent* e) { } Modified: trunk/perceptioncrash/src/PlayState.hpp =================================================================== --- trunk/perceptioncrash/src/PlayState.hpp 2006-05-21 19:22:25 UTC (rev 57) +++ trunk/perceptioncrash/src/PlayState.hpp 2006-05-22 08:22:17 UTC (rev 58) @@ -14,9 +14,8 @@ void pause(); void resume(); - void keyClicked(Ogre::KeyEvent* e); - void keyPressed(Ogre::KeyEvent* e); - void keyReleased(Ogre::KeyEvent* e); + void buttonPressed(InputControllerEvent* e); + void buttonReleased(InputControllerEvent* e); void mouseMoved(Ogre::MouseEvent* e); void mouseDragged(Ogre::MouseEvent* e); @@ -36,6 +35,7 @@ Ogre::Viewport* mViewport; Ogre::Camera* mCamera; Ogre::Overlay* mLogoOverlay; + InputController* mInputController; private: static PlayState mPlayState; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |