Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 25, 2008, 5:04:26 PM (16 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' ;)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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  }
Note: See TracChangeset for help on using the changeset viewer.