Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 922


Ignore:
Timestamp:
Mar 25, 2008, 5:04:26 PM (17 years ago)
Author:
rgrieder
Message:
  • created InputEventListener and InputEvent
  • escape key now works through the InputHandler
  • the concept will soon be replaced by a new one this is more of a 'svn save' ;)
Location:
code/branches/network
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/orxonox/CMakeLists.txt

    r919 r922  
    22  GraphicsEngine.cc
    33  InputHandler.cc
     4  InputEventListener.cc
    45  Main.cc
    56  Orxonox.cc
  • code/branches/network/src/orxonox/InputHandler.cc

    r921 r922  
    3636#include "core/CoreIncludes.h"
    3737#include "Orxonox.h"
     38#include "InputEventListener.h"
    3839#include "InputHandler.h"
    3940
    4041namespace orxonox
    4142{
    42   //using namespace OIS;
    43 
    4443  /**
    4544    @brief Constructor only resets the pointer values to 0.
     
    4746  InputHandler::InputHandler()
    4847  {
    49     /*if (orxonox::Identifier::isCreatingHierarchy() && !this->getParents())
    50         this->createParents();
    51     this->setIdentifier(orxonox::ClassManager<InputHandler>::getIdentifier()->registerClass(this->getParents(), "InputHandler", true));
    52     if (orxonox::Identifier::isCreatingHierarchy() && this->getParents())
    53         this->getParents()->insert(this->getParents()->end(), this->getIdentifier());
    54     orxonox::ClassManager<InputHandler>::getIdentifier()->addObject(this);*/
    55 
    5648    //RegisterObject(InputHandler);
    57 
    5849    this->mouse_       = 0;
    5950    this->keyboard_    = 0;
    6051    this->inputSystem_ = 0;
    61 
    62     //this->setConfigValues();
    63   }
    64 
    65   void InputHandler::setConfigValues()
    66   {
    67     //SetConfigValue(codeFire_, 4).description("test value");
    68 
    69     ConfigValueContainer *containercodeFire_ = new ConfigValueContainer("asdfblah", "codeFire_", 4);
    70     containercodeFire_->getValue(&codeFire_).description("test");
    71     //containercodeFire_->
    7252  }
    7353
     
    7656    @return The pointer to the only instance of the InputHandler
    7757  */
    78   InputHandler* InputHandler::getSingleton()
     58  InputHandler *InputHandler::getSingleton()
    7959  {
    8060    static InputHandler theOnlyInstance;
     
    8363
    8464  /**
    85     @brief Creates the OIS::InputMananger, the keyboard and the mouse
     65    @brief Creates the OIS::InputMananger, the keyboard and the mouse and
     66           assigns the key bindings.
    8667    @param windowHnd The window handle of the render window
    8768    @param windowWidth The width of the render window
     
    120101      }
    121102    }
     103
     104    // load the key bindings
     105    InputEvent empty = {0, false, 0, 0, 0};
     106    for (int i = 0; i < this->numberOfKeys_; i++)
     107      this->bindingsKeyPressed_[i] = empty;
     108
     109    //assign 'abort' to the escape key
     110    this->bindingsKeyPressed_[(int)OIS::KC_ESCAPE].id = 1;
    122111  }
    123112
     
    130119    // capture all the input. That calls the event handlers.
    131120    if (mouse_)
    132     {
    133121      mouse_->capture();
    134     }
    135122
    136123    if (keyboard_)
    137     {
    138124      keyboard_->capture();
    139     }
    140125  }
    141126
     
    155140
    156141  /**
     142    @brief Calls all the objects from classes that derive from InputEventListener.
     143    @param evt The input event that occured.
     144  */
     145  inline void InputHandler::callListeners(orxonox::InputEvent &evt)
     146  {
     147    for (Iterator<InputEventListener> it = ObjectList<InputEventListener>::start(); it; )
     148    {
     149      if (it->bActive_)
     150        (it++)->eventOccured(evt);
     151      else
     152        it++;
     153    }
     154  }
     155
     156  /**
    157157    @brief Event handler for the keyPressed Event.
    158158    @param e Event information
     
    160160  bool InputHandler::keyPressed(const OIS::KeyEvent &e)
    161161  {
    162     if (e.key == OIS::KC_ESCAPE)
    163       Orxonox::getSingleton()->abortRequest();
     162    callListeners(this->bindingsKeyPressed_[(int)e.key]);
    164163    return true;
    165164  }
  • code/branches/network/src/orxonox/InputHandler.h

    r921 r922  
    3838
    3939#include "OrxonoxPrereqs.h"
    40 //#include "core/OrxonoxClass.h"
    4140#include "core/Tickable.h"
     41#include "InputEvent.h"
    4242
    4343namespace orxonox
    4444{
    4545  class _OrxonoxExport InputHandler
    46         : public Tickable,
    47           public OIS::KeyListener, public OIS::MouseListener
     46        : public Tickable, public OIS::KeyListener, public OIS::MouseListener
    4847  {
     48    //friend ClassIdentifier<InputHandler>;
    4949  public:
    50 
    5150    void initialise(size_t windowHnd, int windowWidth, int windowHeight);
    5251    void tick(float dt);
     
    5554    OIS::Mouse    *getMouse()    { return this->mouse_   ; }
    5655    OIS::Keyboard *getKeyboard() { return this->keyboard_; }
     56
     57    static InputHandler* getSingleton();
     58
     59  private:
     60    // don't mess with a Singleton
     61    InputHandler ();
     62    InputHandler (const InputHandler&) { }
     63    ~InputHandler() { }
     64
     65    void callListeners(InputEvent &evt);
    5766
    5867    // input events
     
    6372                bool keyReleased  (const OIS::KeyEvent   &arg);
    6473
    65     static InputHandler* getSingleton();
     74    OIS::InputManager *inputSystem_;    //!< OIS input manager
     75    OIS::Keyboard     *keyboard_;       //!< OIS mouse
     76    OIS::Mouse        *mouse_;          //!< OIS keyboard
    6677
    67     void setConfigValues();
     78    //! denotes the maximum number of different keys there are in OIS.
     79    //! 256 should be ok since the highest number in the enum is 237.
     80    static const int numberOfKeys_ = 256;
     81    //! Array of input events for every pressed key
     82    InputEvent bindingsKeyPressed_[numberOfKeys_];
     83    //! Array of input events for every released key
     84    InputEvent bindingsKeyReleased_[numberOfKeys_];
    6885
    69   private:
    70     // don't mess with a Singleton
    71     InputHandler ();
    72     InputHandler (const InputHandler&) { }
    73     ~InputHandler() { }
    74 
    75     OIS::InputManager *inputSystem_;
    76     OIS::Keyboard     *keyboard_;
    77     OIS::Mouse        *mouse_;
    78 
    79     // Key bindings
    80     int codeFire_;
    81     OIS::KeyCode codeMoveForward_;
     86    //! denotes the maximum number of different buttons there are in OIS.
     87    //! 16 should be ok since the highest number in the enum is 7.
     88    static const int numberOfButtons_ = 16;
     89    //! Array of input events for every pressed key
     90    InputEvent bindingsButtonPressed_[numberOfButtons_];
     91    //! Array of input events for every released key
     92    InputEvent bindingsButtonReleased_[numberOfButtons_];
    8293
    8394  };
  • code/branches/network/src/orxonox/Orxonox.cc

    r919 r922  
    3737#include <OgreException.h>
    3838#include <OgreRoot.h>
    39 #include <OgreFrameListener.h>
    4039#include <OgreRenderWindow.h>
    4140#include <OgreTextureManager.h>
     
    373372  }
    374373
    375 
     374  /**
     375    @brief Calls the InputHandler which sets up the input devices.
     376    The render window width and height are used to set up the mouse movement.
     377  */
    376378  void Orxonox::setupInputSystem()
    377379  {
     
    379381    inputHandler_->initialise(ogre_->getWindowHandle(),
    380382          ogre_->getWindowWidth(), ogre_->getWindowHeight());
    381 
    382     /*size_t windowHnd = 0;
    383     std::ostringstream windowHndStr;
    384     OIS::ParamList pl;
    385 
    386     // fixes auto repeat problem
    387     #if defined OIS_LINUX_PLATFORM
    388       pl.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
    389     #endif
    390 
    391       Ogre::RenderWindow *win = ogre_->getRoot()->getAutoCreatedWindow();
    392     win->getCustomAttribute("WINDOW", &windowHnd);
    393     windowHndStr << windowHnd;
    394     pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
    395     inputManager_ = OIS::InputManager::createInputSystem(pl);
    396 
    397     try
    398     {
    399       keyboard_ = static_cast<OIS::Keyboard*>(inputManager_->createInputObject(OIS::OISKeyboard, false));
    400       mouse_ = static_cast<OIS::Mouse*>(inputManager_->createInputObject(OIS::OISMouse, true));
    401     }
    402     catch (const OIS::Exception &e)
    403     {
    404       throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem");
    405     }*/
    406383  }
    407384
     
    512489    return (float)(times.back() - times.front()) / ((times.size()-1) * 1000);
    513490  }
     491
     492  void Orxonox::eventOccured(InputEvent &evt)
     493  {
     494    if (evt.id == 1)
     495      this->abortRequest();
     496  }
    514497}
  • code/branches/network/src/orxonox/Orxonox.h

    r919 r922  
    1818
    1919#include "GraphicsEngine.h"
     20#include "InputEventListener.h"
    2021
    2122
     
    3031  };
    3132
    32   class _OrxonoxExport Orxonox
     33  class _OrxonoxExport Orxonox : public InputEventListener
    3334  {
    3435    public:
     
    6869      float calculateEventTime(unsigned long, std::deque<unsigned long>&);
    6970
     71      void eventOccured(InputEvent &evt);
     72
    7073    private:
    7174      GraphicsEngine*       ogre_;          //!< our dearest graphics engine <3
  • code/branches/network/src/orxonox/OrxonoxPrereqs.h

    r919 r922  
    6868  class Camera;
    6969  class GraphicsEngine;
     70  struct InputEvent;
     71  class InputEventListener;
    7072  class InputHandler;
    7173  class Mesh;
  • code/branches/network/src/orxonox/OrxonoxStableHeaders.h

    r918 r922  
    4646#endif
    4747//#include <Ogre.h>
    48 //#include <OgreBillboardSet.h>
    49 //#include <OgreCamera.h>
    50 //#include <OgreConfigFile.h>
     48#include <OgreBillboardSet.h>
     49#include <OgreCamera.h>
     50#include <OgreColourValue.h>
     51#include <OgreConfigFile.h>
    5152#include <OgreEntity.h>
    5253#include <OgreException.h>
    53 //#include <OgreFrameListener.h>
     54#include <OgreFrameListener.h>
    5455#include <OgreLight.h>
    55 //#include <OgreOverlay.h>
    56 //#include <OgreOverlayElement.h>
    57 //#include <OgreOverlayManager.h>
     56#include <OgreMath.h>
     57#include <OgreMatrix3.h>
     58#include <OgreOverlay.h>
     59#include <OgreOverlayElement.h>
     60#include <OgreOverlayManager.h>
    5861#include <OgreParticleEmitter.h>
    5962#include <OgreParticleSystem.h>
    6063#include <OgrePlatform.h>
    6164#include <OgrePrerequisites.h>
    62 //#include <OgreRenderWindow.h>
    63 //#include <OgreRoot.h>
     65#include <OgreQuaternion.h>
     66#include <OgreResourceGroupManager.h>
     67#include <OgreRenderWindow.h>
     68#include <OgreRoot.h>
    6469#include <OgreSceneManager.h>
    6570#include <OgreSceneNode.h>
    6671#include <OgreStringConverter.h>
    67 //#include <OgreTextureManager.h>
    68 //#include <OgreViewport.h>
     72#include <OgreTextureManager.h>
     73#include <OgreTimer.h>
     74#include <OgreVector2.h>
     75#include <OgreVector3.h>
     76#include <OgreVector3.h>
     77#include <OgreViewport.h>
     78#include <OgreWindowEventUtilities.h>
    6979
    7080#include <OIS/OIS.h>
  • code/branches/network/visual_studio/vc8/orxonox.vcproj

    r919 r922  
    285285                        </File>
    286286                        <File
     287                                RelativePath="..\..\src\orxonox\InputEventListener.cc"
     288                                >
     289                        </File>
     290                        <File
    287291                                RelativePath="..\..\src\orxonox\InputHandler.cc"
    288292                                >
     
    655659                        </File>
    656660                        <File
     661                                RelativePath="..\..\src\orxonox\InputEvent.h"
     662                                >
     663                        </File>
     664                        <File
     665                                RelativePath="..\..\src\orxonox\InputEventListener.h"
     666                                >
     667                        </File>
     668                        <File
    657669                                RelativePath="..\..\src\orxonox\InputHandler.h"
    658670                                >
Note: See TracChangeset for help on using the changeset viewer.