Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1219 for code/trunk


Ignore:
Timestamp:
May 2, 2008, 10:44:57 PM (17 years ago)
Author:
rgrieder
Message:

merged input branch back to trunk. Not yet tested on tardis

Location:
code/trunk
Files:
8 deleted
24 edited
70 copied

Legend:

Unmodified
Added
Removed
  • code/trunk/CMakeLists.txt

    r1214 r1219  
    5959#Performs the search and sets the variables
    6060FIND_PACKAGE(OGRE)
    61 FIND_PACKAGE(OIS)
     61#FIND_PACKAGE(OIS)
    6262# FIND_PACKAGE(CEGUI)
    6363# FIND_PACKAGE(CEGUI_OGRE)
     
    7474LINK_DIRECTORIES(
    7575  ${OGRE_LIB_DIR}
    76   ${OIS_LIB_DIR}
     76#  ${OIS_LIB_DIR}
    7777#  ${CEGUI_LIB_DIR} ${CEGUI_OGRE_LIB_DIR}
    7878  ${ENet_LIBRARY}
     
    8585INCLUDE_DIRECTORIES(
    8686  ${OGRE_INCLUDE_DIR}
    87   ${OIS_INCLUDE_DIR}
     87#  ${OIS_INCLUDE_DIR}
    8888#  ${CEGUI_INCLUDE_DIR} ${CEGUI_OGRE_INCLUDE_DIR}
    8989  ${ENet_INCLUDE_DIR}
  • code/trunk/bin/keybindings.ini

    r1215 r1219  
    11[KeyBinder]
    2 P_UNASSIGNED=
     2P_UNASSIGNED=activateConsole
    33R_UNASSIGNED=
    44H_UNASSIGNED=
  • code/trunk/src/CMakeLists.txt

    r1214 r1219  
    22INCLUDE_DIRECTORIES(orxonox)
    33INCLUDE_DIRECTORIES(tolua)
     4INCLUDE_DIRECTORIES(ois)
    45
     6ADD_SUBDIRECTORY(cpptcl)
     7ADD_SUBDIRECTORY(ois)
    58ADD_SUBDIRECTORY(tinyxml)
    69ADD_SUBDIRECTORY(tolua)
    7 ADD_SUBDIRECTORY(cpptcl)
     10
    811ADD_SUBDIRECTORY(util)
    912ADD_SUBDIRECTORY(core)
  • code/trunk/src/core/CMakeLists.txt

    r1214 r1219  
    77  InputHandler.cc
    88  InputManager.cc
    9   InputEventListener.cc
    109  MetaObjectList.cc
    1110  ConfigFileManager.cc
     
    5251  cpptcl
    5352  ${Lua_LIBRARIES}
    54   ${OIS_LIBRARIES}
    5553  ${OGRE_LIBRARIES}
    5654  tinyxml
    5755  tolualib
     56  ois
    5857  util
    5958)
  • code/trunk/src/core/CorePrereqs.h

    r1214 r1219  
    114114  class Identifier;
    115115  class IdentifierDistributor;
    116   class InputBuffer;
    117   class InputBufferListener;
    118   class InputHandlerGame;
    119   class InputHandlerGUI;
    120   class InputManager;
    121116  template <class T>
    122117  class Iterator;
     
    147142  class XMLPortObjectContainer;
    148143  class XMLPortParamContainer;
     144
     145  // input
     146  class InputBuffer;
     147  class InputBufferListener;
     148  class InputManager;
     149  class KeyBinder;
     150  class GUIInputHandler;
     151  class KeyHandler;
     152  class MouseHandler;
     153  class JoyStickHandler;
     154
    149155}
    150156
  • code/trunk/src/core/Debug.h

    r1089 r1219  
    264264///  CCOUT: Prints output with std::cout and adds the classname   ///
    265265/////////////////////////////////////////////////////////////////////
     266#define CCOUTORX_NONE    CCOUT0
     267#define CCOUTORX_ERROR   CCOUT1
     268#define CCOUTORX_WARNING CCOUT2
     269#define CCOUTORX_INFO    CCOUT3
     270#define CCOUTORX_DEBUG   CCOUT4
     271#define CCOUTORX_vDEBUG  CCOUT5
    266272
    267273#define CCOUT_EXEC(x) \
  • code/trunk/src/core/InputBuffer.cc

    r1214 r1219  
    4040        //this->bActivated_ = false;
    4141        this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"(){}[]<>.:,;_-+*/=!?|$&%^";
    42         this->keyboard_ = InputManager::getSingleton().getKeyboard();
     42        this->keyboard_ = InputManager::getKeyboard();
    4343        this->buffer_ = "";
    4444
  • code/trunk/src/core/InputBuffer.h

    r1214 r1219  
    3535#include <list>
    3636
    37 #ifdef WIN32
    38 #include <OIS/OISKeyboard.h>
    39 #else
    40 #include <OISKeyboard.h>
    41 #endif
     37#include "ois/OISKeyboard.h"
     38#include "InputHandler.h"
    4239
    4340namespace orxonox
     
    4643    {};
    4744
    48     class _CoreExport InputBuffer : public OIS::KeyListener
     45    class _CoreExport InputBuffer : public KeyHandler
    4946    {
    5047        struct InputBufferListenerTuple
     
    115112            bool keyPressed(const OIS::KeyEvent &e);
    116113            bool keyReleased(const OIS::KeyEvent &e);
     114            bool keyHeld(const OIS::KeyEvent &e) { return true; }
    117115
    118116            OIS::Keyboard* keyboard_;
  • code/trunk/src/core/InputHandler.cc

    r1214 r1219  
    3434#include "InputHandler.h"
    3535#include "Debug.h"
     36#include "ConfigValueIncludes.h"
     37#include "CoreIncludes.h"
    3638#include "util/Convert.h"
    37 #include "InputEventListener.h"
    38 #include "InputEvent.h"
    39 #include "InputManager.h"
     39#include "core/CommandExecutor.h"
    4040
    4141namespace orxonox
    4242{
    4343  // ###############################
    44   // ###    InputHandlerGame     ###
     44  // ######     KeyBinder     ######
    4545  // ###############################
    4646
    4747  /**
    48     @brief standard constructor
    49   */
    50   InputHandlerGame::InputHandlerGame()
    51   {
     48    @brief Constructor that does as little as necessary.
     49  */
     50  KeyBinder::KeyBinder()
     51  {
     52    RegisterObject(KeyBinder);
     53    clearBindings();
     54
     55    std::string keyNames[] = {
     56    "UNASSIGNED",
     57                "ESCAPE",
     58                "1",
     59                "2",
     60                "3",
     61                "4",
     62                "5",
     63                "6",
     64                "7",
     65                "8",
     66                "9",
     67                "0",
     68                "MINUS",
     69                "EQUALS",
     70                "BACK",
     71                "TAB",
     72                "Q",
     73                "W",
     74                "E",
     75                "R",
     76                "T",
     77                "Y",
     78                "U",
     79                "I",
     80                "O",
     81                "P",
     82                "LBRACKET",
     83                "RBRACKET",
     84                "RETURN",
     85                "LCONTROL",
     86                "A",
     87                "S",
     88                "D",
     89                "F",
     90                "G",
     91                "H",
     92                "J",
     93                "K",
     94                "L",
     95                "SEMICOLON",
     96                "APOSTROPHE",
     97                "GRAVE",
     98                "LSHIFT",
     99                "BACKSLASH",
     100                "Z",
     101                "X",
     102                "C",
     103                "V",
     104                "B",
     105                "N",
     106                "M",
     107                "COMMA",
     108                "PERIOD",
     109                "SLASH",
     110                "RSHIFT",
     111                "MULTIPLY",
     112                "LMENU",
     113                "SPACE",
     114                "CAPITAL",
     115                "F1",
     116                "F2",
     117                "F3",
     118                "F4",
     119                "F5",
     120                "F6",
     121                "F7",
     122                "F8",
     123                "F9",
     124                "F10",
     125                "NUMLOCK",
     126                "SCROLL",
     127                "NUMPAD7",
     128                "NUMPAD8",
     129                "NUMPAD9",
     130                "SUBTRACT",
     131                "NUMPAD4",
     132                "NUMPAD5",
     133                "NUMPAD6",
     134                "ADD",
     135                "NUMPAD1",
     136                "NUMPAD2",
     137                "NUMPAD3",
     138                "NUMPAD0",
     139                "DECIMAL",
     140    "","",
     141                "OEM_102",
     142                "F11",
     143                "F12",
     144    "","","","","","","","","","","",
     145                "F13",
     146                "F14",
     147                "F15",
     148    "","","","","","","","","","",
     149                "KANA",
     150    "","",
     151                "ABNT_C1",
     152    "","","","","",
     153                "CONVERT",
     154    "",
     155                "NOCONVERT",
     156    "",
     157                "YEN",
     158                "ABNT_C2",
     159    "","","","","","","","","","","","","","",
     160                "NUMPADEQUALS",
     161    "","",
     162                "PREVTRACK",
     163                "AT",
     164                "COLON",
     165                "UNDERLINE",
     166                "KANJI",
     167                "STOP",
     168                "AX",
     169                "UNLABELED",
     170                "NEXTTRACK",
     171    "","",
     172                "NUMPADENTER",
     173                "RCONTROL",
     174    "","",
     175                "MUTE",
     176                "CALCULATOR",
     177                "PLAYPAUSE",
     178    "",
     179                "MEDIASTOP",
     180    "","","","","","","","","",
     181                "VOLUMEDOWN",
     182    "",
     183                "VOLUMEUP",
     184    "",
     185                "WEBHOME",
     186                "NUMPADCOMMA",
     187    "",
     188                "DIVIDE",
     189    "",
     190                "SYSRQ",
     191                "RMENU",
     192    "","","","","","","","","","","","",
     193                "PAUSE",
     194    "",
     195                "HOME",
     196                "UP",
     197                "PGUP",
     198    "",
     199                "LEFT",
     200    "",
     201                "RIGHT",
     202    "",
     203                "END",
     204                "DOWN",
     205                "PGDOWN",
     206                "INSERT",
     207                "DELETE",
     208    "","","","","","","",
     209                "LWIN",
     210                "RWIN",
     211                "APPS",
     212                "POWER",
     213                "SLEEP",
     214    "","","",
     215                "WAKE",
     216    "",
     217                "WEBSEARCH",
     218                "WEBFAVORITES",
     219                "WEBREFRESH",
     220                "WEBSTOP",
     221                "WEBFORWARD",
     222                "WEBBACK",
     223                "MYCOMPUTER",
     224                "MAIL",
     225                "MEDIASELECT"
     226    };
     227    for (int i = 0; i < numberOfKeys_s; i++)
     228      keyNames_[i] = keyNames[i];
     229
     230    std::string mouseButtonNames[] = {
     231    "MouseLeft", "MouseRight", "MouseMiddle",
     232    "MouseButton3", "MouseButton4", "MouseButton5",
     233    "MouseButton6", "MouseButton7" };
     234    for (int i = 0; i < numberOfMouseButtons_s; i++)
     235      mouseButtonNames_[i] = mouseButtonNames[i];
     236
     237    for (int i = 0; i < numberOfJoyStickButtons_s; i++)
     238      joyStickButtonNames_[i] = "JoyStick" + getConvertedValue<int, std::string>(i);
    52239  }
    53240
     
    55242    @brief Destructor
    56243  */
    57   InputHandlerGame::~InputHandlerGame()
    58   {
    59   }
    60 
    61   /**
    62     @brief Loads the key bindings from the ini file.
    63     Currently, this is just a simple test routine that fills the list with numbers.
    64   */
    65   bool InputHandlerGame::loadBindings()
    66   {
     244  KeyBinder::~KeyBinder()
     245  {
     246  }
     247
     248  /**
     249    @brief Loader for the key bindings, managed by config values.
     250  */
     251  void KeyBinder::setConfigValues()
     252  {
     253    ConfigValueContainer* cont;
     254    std::string modes[] = {"P_", "R_", "H_"};
     255
     256    // keys
    67257    for (int i = 0; i < numberOfKeys_s; i++)
    68258    {
    69       // simply write the key number (i) in the string
    70       this->bindingsKeyPressed_[i] = getConvertedValue<int, std::string>(i);
    71       this->bindingsKeyReleased_[i] = getConvertedValue<int, std::string>(i);
    72     }
    73     return true;
    74   }
     259      for (int j = 0; j < 3; j++)
     260      {
     261        cont = getIdentifier()->getConfigValueContainer(modes[j] + keyNames_[i]);
     262        if (!cont)
     263        {
     264          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), modes[j] + keyNames_[i], "");
     265          getIdentifier()->addConfigValueContainer(modes[j] + keyNames_[i], cont);
     266        }
     267        switch (j)
     268        {
     269          // note: the first element in the struct is the string, so the following pointer
     270          //       arithmetic works.
     271          case 0:
     272            cont->getValue(&bindingsKeyPress_[i].commandStr);
     273            break;
     274          case 1:
     275            cont->getValue(bindingsKeyRelease_ + i);
     276            break;
     277          case 2:
     278            cont->getValue(bindingsKeyHold_ + i);
     279        }
     280      }
     281    }
     282
     283    // mouse buttons
     284    for (int i = 0; i < numberOfMouseButtons_s; i++)
     285    {
     286      for (int j = 0; j < 3; j++)
     287      {
     288        cont = getIdentifier()->getConfigValueContainer(modes[j] + mouseButtonNames_[i]);
     289        if (!cont)
     290        {
     291          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), modes[j] + mouseButtonNames_[i], "");
     292          getIdentifier()->addConfigValueContainer(modes[j] + mouseButtonNames_[i], cont);
     293        }
     294        switch (j)
     295        {
     296          case 0:
     297            cont->getValue(bindingsMouseButtonPress_ + i);
     298            break;
     299          case 1:
     300            cont->getValue(bindingsMouseButtonRelease_ + i);
     301            break;
     302          case 2:
     303            cont->getValue(bindingsMouseButtonHold_ + i);
     304        }
     305      }
     306    }
     307
     308    // joy stick buttons
     309    for (int i = 0; i < numberOfJoyStickButtons_s; i++)
     310    {
     311      for (int j = 0; j < 3; j++)
     312      {
     313        cont = getIdentifier()->getConfigValueContainer(modes[j] + joyStickButtonNames_[i]);
     314        if (!cont)
     315        {
     316          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), modes[j] + joyStickButtonNames_[i], "");
     317          getIdentifier()->addConfigValueContainer(modes[j] + joyStickButtonNames_[i], cont);
     318        }
     319        switch (j)
     320        {
     321          case 0:
     322            cont->getValue(bindingsJoyStickButtonPress_ + i);
     323            break;
     324          case 1:
     325            cont->getValue(bindingsJoyStickButtonRelease_ + i);
     326            break;
     327          case 2:
     328            cont->getValue(bindingsJoyStickButtonHold_ + i);
     329        }
     330      }
     331    }
     332  }
     333
     334  /**
     335    @brief Overwrites all bindings with ""
     336  */
     337  void KeyBinder::clearBindings()
     338  {
     339    for (int i = 0; i < numberOfKeys_s; i++)
     340    {
     341      bindingsKeyPress_  [i].commandStr = "";
     342      bindingsKeyRelease_[i].commandStr = "";
     343      bindingsKeyHold_   [i].commandStr = "";
     344    }
     345    for (int i = 0; i < numberOfMouseButtons_s; i++)
     346    {
     347      bindingsMouseButtonPress_  [i] = "";
     348      bindingsMouseButtonRelease_[i] = "";
     349      bindingsMouseButtonHold_   [i] = "";
     350    }
     351    for (int i = 0; i < numberOfJoyStickButtons_s; i++)
     352    {
     353      bindingsJoyStickButtonPress_  [i] = "";
     354      bindingsJoyStickButtonRelease_[i] = "";
     355      bindingsJoyStickButtonHold_   [i] = "";
     356    }
     357  }
     358
     359  /**
     360    @brief Loads the key and button bindings.
     361    @return True if loading succeeded.
     362  */
     363  bool KeyBinder::loadBindings()
     364  {
     365    COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings..." << std::endl;
     366
     367    ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, "keybindings.ini");
     368    setConfigValues();
     369
     370    // evaluate the key bindings
     371    // TODO: what if binding is invalid?
     372    //for (int i = 0; i < numberOfKeys_s; i++)
     373    //{
     374    //  if (bindingsKeyPress_[i].commandStr != "")
     375    //  {
     376    //    bindingsKeyPress_[i].evaluation = CommandExecutor::evaluate(bindingsKeyPress_[i].commandStr);
     377    //    bindingsKeyPress_[i].commandStr = bindingsKeyPress_[i].evaluation.getCommandString();
     378    //  }
     379    //}
     380
     381    COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings done." << std::endl;
     382    return true;
     383  }
     384
     385  bool KeyBinder::executeBinding(KeyBinding& binding)
     386  {
     387    if (binding.commandStr != "")
     388    {
     389      //if (binding.commandStr != binding.evaluation.getCommandString())
     390      //{
     391      //  // key binding has changed, reevaluate the command string.
     392      //  binding.evaluation = CommandExecutor::evaluate(binding.commandStr);
     393      //  binding.commandStr = binding.evaluation.getCommandString();
     394      //}
     395      COUT(3) << "Executing command: " << binding.commandStr << std::endl;
     396      CommandExecutor::execute(binding.commandStr);
     397    }
     398
     399    return true;
     400  }
     401
    75402
    76403  /**
     
    78405    @param e Event information
    79406  */
    80   bool InputHandlerGame::keyPressed(const OIS::KeyEvent &e)
    81   {
    82     if (e.key == OIS::KC_ESCAPE)
    83     {
    84       InputEvent e = {1, true, 0, 0, 0};
    85       InputHandlerGame::callListeners(e);
    86     }
    87     else if (e.key == OIS::KC_UNASSIGNED || e.key == OIS::KC_NUMPADENTER)
    88     {
    89       InputManager::getSingleton().setInputMode(IM_KEYBOARD);
    90     }
    91     else
    92     {
    93       // find the appropriate key binding
    94       std::string cmdStr = bindingsKeyPressed_[int(e.key)];
    95       //COUT(3) << cmdStr << " pressed" << std::endl;
    96     }
     407  bool KeyBinder::keyPressed(const OIS::KeyEvent &e)
     408  {
     409    COUT(3) << "Key: " << e.key << std::endl;
     410    // find the appropriate key binding
     411    executeBinding(bindingsKeyPress_[int(e.key)]);
     412     
    97413    return true;
    98414  }
     
    102418    @param e Event information
    103419  */
    104   bool InputHandlerGame::keyReleased(const OIS::KeyEvent &e)
    105   {
    106     // find the appropriate key binding
    107     std::string cmdStr = bindingsKeyReleased_[int(e.key)];
    108     //COUT(3) << cmdStr << " released" << std::endl;
     420  bool KeyBinder::keyReleased(const OIS::KeyEvent &e)
     421  {
     422    // find the appropriate key binding
     423    executeBinding(bindingsKeyRelease_[int(e.key)]);
     424
     425    return true;
     426  }
     427
     428  /**
     429    @brief Event handler for the keyHeld Event.
     430    @param e Event information
     431  */
     432  bool KeyBinder::keyHeld(const OIS::KeyEvent &e)
     433  {
     434    // find the appropriate key binding
     435    executeBinding(bindingsKeyHold_[int(e.key)]);
     436
    109437    return true;
    110438  }
     
    114442    @param e Event information
    115443  */
    116   bool InputHandlerGame::mouseMoved(const OIS::MouseEvent &e)
     444  bool KeyBinder::mouseMoved(const OIS::MouseEvent &e)
    117445  {
    118446    return true;
     
    124452    @param id The ID of the mouse button
    125453  */
    126   bool InputHandlerGame::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    127   {
     454  bool KeyBinder::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     455  {
     456    // find the appropriate key binding
     457    std::string cmdStr = bindingsMouseButtonPress_[int(id)];
     458    if (cmdStr != "")
     459    {
     460      CommandExecutor::execute(cmdStr);
     461      COUT(3) << "Executing command: " << cmdStr << std::endl;
     462    }
     463
    128464    return true;
    129465  }
     
    134470    @param id The ID of the mouse button
    135471  */
    136   bool InputHandlerGame::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    137   {
    138     return true;
    139   }
    140 
    141   /**
    142     @brief Calls all the objects from classes that derive from InputEventListener.
    143     @param evt The input event that occured.
    144   */
    145   inline void InputHandlerGame::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 
    157   // ###############################
    158   // ###     InputHandlerGUI     ###
    159   // ###############################
    160 
    161   /**
    162     @brief standard constructor
    163   */
    164   InputHandlerGUI::InputHandlerGUI()
    165   {
    166   }
    167 
    168   /**
    169     @brief Destructor
    170   */
    171   InputHandlerGUI::~InputHandlerGUI()
    172   {
    173   }
    174 
    175   /**
    176     @brief Event handler for the keyPressed Event.
    177     @param e Event information
    178   */
    179   bool InputHandlerGUI::keyPressed(const OIS::KeyEvent &e)
    180   {
    181                 //CEGUI::System::getSingleton().injectKeyDown( arg.key );
    182                 //CEGUI::System::getSingleton().injectChar( arg.text );
    183     return true;
    184   }
    185 
    186   /**
    187     @brief Event handler for the keyReleased Event.
    188     @param e Event information
    189   */
    190   bool InputHandlerGUI::keyReleased(const OIS::KeyEvent &e)
    191   {
    192                 //CEGUI::System::getSingleton().injectKeyUp( arg.key );
    193     return true;
    194   }
    195 
    196   /**
    197     @brief Event handler for the mouseMoved Event.
    198     @param e Event information
    199   */
    200   bool InputHandlerGUI::mouseMoved(const OIS::MouseEvent &e)
    201   {
    202                 //CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel );
    203     return true;
    204   }
    205 
    206   /**
    207     @brief Event handler for the mousePressed Event.
     472  bool KeyBinder::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     473  {
     474    // find the appropriate key binding
     475    std::string cmdStr = bindingsMouseButtonRelease_[int(id)];
     476    if (cmdStr != "")
     477    {
     478      CommandExecutor::execute(cmdStr);
     479      COUT(3) << "Executing command: " << cmdStr << std::endl;
     480    }
     481
     482    return true;
     483  }
     484
     485  /**
     486    @brief Event handler for the mouseHeld Event.
    208487    @param e Event information
    209488    @param id The ID of the mouse button
    210489  */
    211   bool InputHandlerGUI::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    212   {
    213                 //CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id));
    214     return true;
    215   }
    216 
    217   /**
    218     @brief Event handler for the mouseReleased Event.
    219     @param e Event information
    220     @param id The ID of the mouse button
    221   */
    222   bool InputHandlerGUI::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    223   {
    224                 //CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id));
    225     return true;
    226   }
     490  bool KeyBinder::mouseHeld(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     491  {
     492    // find the appropriate key binding
     493    std::string cmdStr = bindingsMouseButtonHold_[int(id)];
     494    if (cmdStr != "")
     495    {
     496      CommandExecutor::execute(cmdStr);
     497      COUT(3) << "Executing command: " << cmdStr << std::endl;
     498    }
     499
     500    return true;
     501  }
     502
     503  bool KeyBinder::buttonPressed(int joyStickID, const OIS::JoyStickEvent &arg, int button)
     504  {
     505    // find the appropriate key binding
     506    std::string cmdStr = bindingsJoyStickButtonPress_[button];
     507    if (cmdStr != "")
     508    {
     509      CommandExecutor::execute(cmdStr);
     510      COUT(3) << "Executing command: " << cmdStr << std::endl;
     511    }
     512
     513    return true;
     514  }
     515
     516  bool KeyBinder::buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button)
     517  {
     518    // find the appropriate key binding
     519    std::string cmdStr = bindingsJoyStickButtonRelease_[button];
     520    if (cmdStr != "")
     521    {
     522      CommandExecutor::execute(cmdStr);
     523      COUT(3) << "Executing command: " << cmdStr << std::endl;
     524    }
     525
     526    return true;
     527  }
     528
     529  bool KeyBinder::buttonHeld(int joyStickID, const OIS::JoyStickEvent &arg, int button)
     530  {
     531    // find the appropriate key binding
     532    std::string cmdStr = bindingsJoyStickButtonHold_[button];
     533    if (cmdStr != "")
     534    {
     535      CommandExecutor::execute(cmdStr);
     536      COUT(3) << "Executing command: " << cmdStr << std::endl;
     537    }
     538
     539    return true;
     540  }
     541
     542  bool KeyBinder::axisMoved(int joyStickID, const OIS::JoyStickEvent &arg, int axis)
     543  {
     544    return true;
     545  }
     546
     547  bool KeyBinder::sliderMoved(int joyStickID, const OIS::JoyStickEvent &arg, int id)
     548  {
     549    return true;
     550  }
     551
     552  bool KeyBinder::povMoved(int joyStickID, const OIS::JoyStickEvent &arg, int id)
     553  {
     554    return true;
     555  }
     556
     557  bool KeyBinder::vector3Moved(int joyStickID, const OIS::JoyStickEvent &arg, int id)
     558  {
     559    return true;
     560  }
     561
     562
     563
     564  // ###############################
     565  // ###     GUIInputHandler     ###
     566  // ###############################
     567
     568  ///**
     569  //  @brief standard constructor
     570  //*/
     571  //GUIInputHandler::GUIInputHandler()
     572  //{
     573  //}
     574
     575  ///**
     576  //  @brief Destructor
     577  //*/
     578  //GUIInputHandler::~GUIInputHandler()
     579  //{
     580  //}
     581
     582  ///**
     583  //  @brief Event handler for the keyPressed Event.
     584  //  @param e Event information
     585  //*/
     586  //bool GUIInputHandler::keyPressed(const OIS::KeyEvent &e)
     587  //{
     588                ////CEGUI::System::getSingleton().injectKeyDown( arg.key );
     589                ////CEGUI::System::getSingleton().injectChar( arg.text );
     590  //  return true;
     591  //}
     592
     593  ///**
     594  //  @brief Event handler for the keyReleased Event.
     595  //  @param e Event information
     596  //*/
     597  //bool GUIInputHandler::keyReleased(const OIS::KeyEvent &e)
     598  //{
     599                ////CEGUI::System::getSingleton().injectKeyUp( arg.key );
     600  //  return true;
     601  //}
     602
     603  ///**
     604  //  @brief Event handler for the mouseMoved Event.
     605  //  @param e Event information
     606  //*/
     607  //bool GUIInputHandler::mouseMoved(const OIS::MouseEvent &e)
     608  //{
     609                ////CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel );
     610  //  return true;
     611  //}
     612
     613  ///**
     614  //  @brief Event handler for the mousePressed Event.
     615  //  @param e Event information
     616  //  @param id The ID of the mouse button
     617  //*/
     618  //bool GUIInputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     619  //{
     620                ////CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id));
     621  //  return true;
     622  //}
     623
     624  ///**
     625  //  @brief Event handler for the mouseReleased Event.
     626  //  @param e Event information
     627  //  @param id The ID of the mouse button
     628  //*/
     629  //bool GUIInputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     630  //{
     631                ////CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id));
     632  //  return true;
     633  //}
    227634
    228635}
  • code/trunk/src/core/InputHandler.h

    r1062 r1219  
    3838
    3939#include <string>
    40 #include <OIS/OIS.h>
    41 
    42 #include "InputEvent.h"
     40#include "ois/OIS.h"
     41#include "OrxonoxClass.h"
     42#include "CommandExecutor.h"
    4343
    4444namespace orxonox
    4545{
    46   /**
    47     @brief Captures mouse and keyboard input while in the actual game mode.
    48     Manages the key bindings.
    49   */
    50   class _CoreExport InputHandlerGame
    51         : public OIS::KeyListener, public OIS::MouseListener
    52   {
    53   public:
    54     InputHandlerGame ();
    55     ~InputHandlerGame();
     46  namespace KeybindSetting
     47  {
     48    enum KeybindSetting
     49    {
     50      None,
     51      OnPress,
     52      OnRelease,
     53      Continuous,
     54    };
     55  }
     56
     57  /**
     58    @brief Interface class used for key input listeners.
     59  */
     60  class _CoreExport KeyHandler : public OIS::KeyListener
     61  {
     62  public:
     63    virtual ~KeyHandler() { }
     64    virtual bool keyHeld(const OIS::KeyEvent &arg) = 0;
     65  };
     66
     67  /**
     68    @brief Interface class used for mouse input listeners.
     69  */
     70  class _CoreExport MouseHandler : public OIS::MouseListener
     71  {
     72  public:
     73    virtual ~MouseHandler() { }
     74    virtual bool mouseHeld(const OIS::MouseEvent &arg, OIS::MouseButtonID id) = 0;
     75  };
     76
     77  /**
     78    @brief Interface class used for joy stick input listeners.
     79  */
     80  class _CoreExport JoyStickHandler
     81  {
     82  public:
     83    virtual ~JoyStickHandler() { }
     84                virtual bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;
     85                virtual bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;
     86    virtual bool buttonHeld    (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;
     87                virtual bool axisMoved     (int joyStickID, const OIS::JoyStickEvent &arg, int axis)   = 0;
     88                virtual bool sliderMoved   (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}
     89                virtual bool povMoved      (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}
     90                virtual bool vector3Moved  (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}
     91  };
     92
     93  struct _CoreExport KeyBinding
     94  {
     95    std::string commandStr;
     96    CommandEvaluation evaluation;
     97  };
     98 
     99
     100  /**
     101    @brief Captures mouse, keyboard and joy stick input while in the actual game mode.
     102           Manages the key bindings.
     103  */
     104  class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass
     105  {
     106  public:
     107    KeyBinder ();
     108    ~KeyBinder();
    56109
    57110    bool loadBindings();
    58 
    59   private:
    60     // input events
    61                 bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
    62                 bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
    63     bool mouseMoved   (const OIS::MouseEvent &arg);
     111    void clearBindings();
     112
     113    void setConfigValues();
     114
     115    std::string testtest;
     116
     117  private: // functions
     118
     119    bool executeBinding(KeyBinding &binding);
     120
    64121                bool keyPressed   (const OIS::KeyEvent   &arg);
    65122                bool keyReleased  (const OIS::KeyEvent   &arg);
    66 
    67     // temporary hack
    68     void callListeners(InputEvent &evt);
    69 
    70     /** denotes the maximum number of different keys there are in OIS.
    71         256 should be ok since the highest number in the enum is 237. */
    72     static const int numberOfKeys_s = 256;
     123                bool keyHeld      (const OIS::KeyEvent   &arg);
     124
     125    bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     126                bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     127                bool mouseHeld    (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     128    bool mouseMoved   (const OIS::MouseEvent &arg);
     129
     130                bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button);
     131                bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button);
     132                bool buttonHeld    (int joyStickID, const OIS::JoyStickEvent &arg, int button);
     133                bool axisMoved     (int joyStickID, const OIS::JoyStickEvent &arg, int axis);
     134                bool sliderMoved   (int joyStickID, const OIS::JoyStickEvent &arg, int id);
     135                bool povMoved      (int joyStickID, const OIS::JoyStickEvent &arg, int id);
     136                bool vector3Moved  (int joyStickID, const OIS::JoyStickEvent &arg, int id);
     137
     138  private: // variables
     139
     140    //! denotes the number of different keys there are in OIS.
     141    static const int numberOfKeys_s = 0xEE;
    73142    //! Array of input events for every pressed key
    74     std::string bindingsKeyPressed_[numberOfKeys_s];
     143    KeyBinding bindingsKeyPress_  [numberOfKeys_s];
    75144    //! Array of input events for every released key
    76     std::string bindingsKeyReleased_[numberOfKeys_s];
    77 
    78     /** denotes the maximum number of different buttons there are in OIS.
    79         16 should be ok since the highest number in the enum is 7. */
    80     static const int numberOfButtons_s = 16;
    81     //! Array of input events for every pressed key
    82     std::string bindingsButtonPressed_[numberOfButtons_s];
    83     //! Array of input events for every released key
    84     std::string bindingsButtonReleased_[numberOfButtons_s];
     145    KeyBinding bindingsKeyRelease_[numberOfKeys_s];
     146    //! Array of input events for every held key
     147    KeyBinding bindingsKeyHold_   [numberOfKeys_s];
     148    //! Names of the keys as strings
     149    std::string keyNames_[numberOfKeys_s];
     150
     151    //! denotes the number of different mouse buttons there are in OIS.
     152    static const int numberOfMouseButtons_s = 8;
     153    //! Array of input events for every pressed mouse button
     154    std::string bindingsMouseButtonPress_  [numberOfMouseButtons_s];
     155    //! Array of input events for every released mouse button
     156    std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s];
     157    //! Array of input events for every held mouse button
     158    std::string bindingsMouseButtonHold_   [numberOfMouseButtons_s];
     159    //! Names of the mouse buttons as strings
     160    std::string mouseButtonNames_[numberOfMouseButtons_s];
     161
     162    //! denotes the number of different joy stick buttons there are in OIS.
     163    static const int numberOfJoyStickButtons_s = 32;
     164    //! Array of input events for every pressed joy stick button
     165    std::string bindingsJoyStickButtonPress_  [numberOfJoyStickButtons_s];
     166    //! Array of input events for every released joy stick button
     167    std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s];
     168    //! Array of input events for every held joy stick button
     169    std::string bindingsJoyStickButtonHold_   [numberOfJoyStickButtons_s];
     170    //! Names of the joy stick buttons as strings
     171    std::string joyStickButtonNames_[numberOfJoyStickButtons_s];
    85172
    86173  };
     
    91178    GUI.
    92179  */
    93   class _CoreExport InputHandlerGUI
    94         : public OIS::KeyListener, public OIS::MouseListener
    95   {
    96   public:
    97     InputHandlerGUI ();
    98     ~InputHandlerGUI();
    99 
    100   private:
    101     // input events
    102                 bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
    103                 bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
    104     bool mouseMoved   (const OIS::MouseEvent &arg);
    105                 bool keyPressed   (const OIS::KeyEvent   &arg);
    106                 bool keyReleased  (const OIS::KeyEvent   &arg);
    107   };
     180  //class _CoreExport GUIInputHandler : public KeyHandler, public MouseHandler, public JoyStickHandler
     181  //{
     182  //public:
     183  //  GUIInputHandler ();
     184  //  ~GUIInputHandler();
     185
     186  //private:
     187  //  // input events
     188                //bool keyPressed   (const OIS::KeyEvent   &arg);
     189                //bool keyReleased  (const OIS::KeyEvent   &arg);
     190                //bool keyHeld      (const OIS::KeyEvent   &arg);
     191
     192  //  bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     193                //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     194                //bool mouseHeld    (const OIS::MouseEvent &arg, OIS::MouseButtonID id);
     195  //  bool mouseMoved   (const OIS::MouseEvent &arg);
     196
     197                //bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
     198                //bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
     199                //bool buttonHeld    (const OIS::JoyStickEvent &arg, int button);
     200                //bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
     201                //bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
     202                //bool povMoved      (const OIS::JoyStickEvent &arg, int id);
     203  //};
    108204
    109205}
  • code/trunk/src/core/InputManager.cc

    r1089 r1219  
    2828
    2929/**
    30  @file
    31  @brief Implementation of a little Input handler that distributes everything
    32         coming from OIS.
     30  @file
     31  @brief Implementation of the InputManager that captures all the input from OIS
     32         and redirects it to handlers if necessary.
    3333 */
    3434
     
    3636#include "CoreIncludes.h"
    3737#include "Debug.h"
    38 #include "InputEventListener.h"
     38#include "InputBuffer.h"
    3939#include "InputHandler.h"
    40 #include "InputBuffer.h"
    41 #include "ConsoleCommand.h"
    4240
    4341namespace orxonox
    4442{
    45   ConsoleCommand(InputManager, setInputMode, AccessLevel::Admin, true).setDefaultValue(0, IM_INGAME);
    46 
    47   /**
    48     @brief Constructor only resets the pointer values to 0.
     43  // ###############################
     44  // ###    Internal Methods     ###
     45  // ###############################
     46  // ###############################
     47
     48  /**
     49    @brief Constructor only sets member fields to initial zero values
     50           and registers the class in the class hierarchy.
    4951  */
    5052  InputManager::InputManager() :
    5153      inputSystem_(0), keyboard_(0), mouse_(0),
    52       currentMode_(IM_UNINIT), setMode_(IM_UNINIT),
    53       handlerGUI_(0), handlerBuffer_(0), handlerGame_(0)
     54      state_(IS_UNINIT), stateRequest_(IS_UNINIT)
    5455  {
    5556    RegisterObject(InputManager);
    56   }
    57 
    58   /**
    59     @brief Destructor only called at the end of the program
    60   */
    61   InputManager::~InputManager()
    62   {
    63     this->destroy();
     57
     58    this->joySticks_.reserve(5);
     59    //this->activeJoyStickHandlers_.reserve(10);
     60    this->activeKeyHandlers_.reserve(10);
     61    this->activeMouseHandlers_.reserve(10);
    6462  }
    6563
     
    6866    @return A reference to the only instance of the InputManager
    6967  */
    70   InputManager& InputManager::getSingleton()
     68  InputManager& InputManager::_getSingleton()
    7169  {
    7270    static InputManager theOnlyInstance;
     
    7573
    7674  /**
    77     @brief Creates the OIS::InputMananger, the keyboard and the mouse and
    78            assigns the key bindings.
     75    @brief Destructor only called at the end of the program, after main.
     76  */
     77  InputManager::~InputManager()
     78  {
     79    _destroy();
     80  }
     81
     82  /**
     83    @brief Creates the OIS::InputMananger, the keyboard, the mouse and
     84           the joysticks and assigns the key bindings.
    7985    @param windowHnd The window handle of the render window
    8086    @param windowWidth The width of the render window
    8187    @param windowHeight The height of the render window
    8288  */
    83   bool InputManager::initialise(size_t windowHnd, int windowWidth, int windowHeight)
    84   {
    85     if (!this->inputSystem_)
    86     {
    87       // Setup basic variables
     89  bool InputManager::_initialise(const size_t windowHnd, const int windowWidth, const int windowHeight,
     90        const bool createKeyboard, const bool createMouse, const bool createJoySticks)
     91  {
     92    if (state_ == IS_UNINIT)
     93    {
     94      CCOUT(ORX_DEBUG) << "Initialising OIS components..." << std::endl;
     95
    8896      OIS::ParamList paramList;
    8997      std::ostringstream windowHndStr;
     
    93101      paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
    94102
    95 #if defined OIS_LINUX_PLATFORM
    96       paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
    97 #endif
     103//#if defined OIS_LINUX_PLATFORM
     104//      paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
     105//#endif
    98106
    99107      try
    100108      {
    101         // Create inputsystem
    102109        inputSystem_ = OIS::InputManager::createInputSystem(paramList);
    103         COUT(ORX_DEBUG) << "*** InputManager: Created OIS input system" << std::endl;
    104 
    105         // create a keyboard. If none are available the exception is caught.
    106         keyboard_ = static_cast<OIS::Keyboard*>(inputSystem_->createInputObject(OIS::OISKeyboard, true));
    107         COUT(ORX_DEBUG) << "*** InputManager: Created OIS mouse" << std::endl;
    108 
    109         // create a mouse. If none are available the exception is caught.
     110        CCOUT(ORX_DEBUG) << "Created OIS input system" << std::endl;
     111      }
     112      catch (OIS::Exception ex)
     113      {
     114        CCOUT(ORX_ERROR) << "Error: Failed creating an OIS input system."
     115            << "OIS message: \"" << ex.eText << "\"" << std::endl;
     116        inputSystem_ = 0;
     117        return false;
     118      }
     119
     120      if (createKeyboard)
     121        _initialiseKeyboard();
     122
     123      if (createMouse)
     124        _initialiseMouse();
     125
     126      if (createJoySticks)
     127        _initialiseJoySticks();
     128
     129      // Set mouse/joystick region
     130      setWindowExtents(windowWidth, windowHeight);
     131
     132      state_ = IS_NONE;
     133      CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl;
     134    }
     135    else
     136    {
     137      CCOUT(ORX_WARNING) << "Warning: OIS compoments already initialised, skipping" << std::endl;
     138    }
     139
     140    // InputManager holds the input buffer --> create one and add it.
     141    addKeyHandler(new InputBuffer(), "buffer");
     142
     143    KeyBinder* binder = new KeyBinder();
     144    binder->loadBindings();
     145    addKeyHandler(binder, "keybinder");
     146    addMouseHandler(binder, "keybinder");
     147
     148    // Read all the key bindings and assign them
     149    //if (!_loadBindings())
     150    //  return false;
     151
     152    CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl;
     153    return true;
     154  }
     155
     156  /**
     157    @brief Creates a keyboard and sets the event handler.
     158    @return False if keyboard stays uninitialised, true otherwise.
     159  */
     160  bool InputManager::_initialiseKeyboard()
     161  {
     162    if (keyboard_ != 0)
     163    {
     164      CCOUT(2) << "Warning: Keyboard already initialised, skipping." << std::endl;
     165      return true;
     166    }
     167    try
     168    {
     169      if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0)
     170      {
     171        keyboard_ = (OIS::Keyboard*)inputSystem_->createInputObject(OIS::OISKeyboard, true);
     172        // register our listener in OIS.
     173        keyboard_->setEventCallback(this);
     174        // note: OIS will not detect keys that have already been down when the keyboard was created.
     175        CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;
     176        return true;
     177      }
     178      else
     179      {
     180        CCOUT(ORX_WARNING) << "Warning: No keyboard found!" << std::endl;
     181        return false;
     182      }
     183    }
     184    catch (OIS::Exception ex)
     185    {
     186      // TODO: Test this output regarding formatting
     187      CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS keyboard\n"
     188          << "OIS error message: \"" << ex.eText << "\"" << std::endl;
     189      keyboard_ = 0;
     190      return false;
     191    }
     192  }
     193
     194  /**
     195    @brief Creates a mouse and sets the event handler.
     196    @return False if mouse stays uninitialised, true otherwise.
     197  */
     198  bool InputManager::_initialiseMouse()
     199  {
     200    if (mouse_ != 0)
     201    {
     202      CCOUT(2) << "Warning: Mouse already initialised, skipping." << std::endl;
     203      return true;
     204    }
     205    try
     206    {
     207      if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0)
     208      {
    110209        mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
    111         COUT(ORX_DEBUG) << "*** InputManager: Created OIS keyboard" << std::endl;
    112 
    113         // Set mouse region
    114         this->setWindowExtents(windowWidth, windowHeight);
    115       }
    116       catch (OIS::Exception ex)
    117       {
    118         // something went wrong with the initialisation
    119         COUT(ORX_ERROR) << "Error: Failed creating an input system/keyboard/mouse. Message: \"" << ex.eText << "\"" << std::endl;
    120         this->inputSystem_ = 0;
     210        // register our listener in OIS.
     211        mouse_->setEventCallback(this);
     212        CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;
     213        return true;
     214      }
     215      else
     216      {
     217        CCOUT(ORX_WARNING) << "Warning: No mouse found!" << std::endl;
    121218        return false;
    122219      }
    123220    }
    124 
    125     // create the handlers
    126     this->handlerGUI_ = new InputHandlerGUI();
    127     this->handlerGame_ = new InputHandlerGame();
    128     //this->handlerBuffer_ = new InputBuffer();
    129     this->handlerGame_->loadBindings();
    130 
    131     /*COUT(ORX_DEBUG) << "*** InputManager: Loading key bindings..." << std::endl;
    132     // load the key bindings
    133     InputEvent empty = {0, false, 0, 0, 0};
    134     for (int i = 0; i < this->numberOfKeys_; i++)
    135       this->bindingsKeyPressed_[i] = empty;
    136 
    137     //assign 'abort' to the escape key
    138     this->bindingsKeyPressed_[(int)OIS::KC_ESCAPE].id = 1;
    139     COUT(ORX_DEBUG) << "*** InputManager: Loading done." << std::endl;*/
    140 
    141     return true;
    142   }
    143 
    144   /**
    145     @brief Destroys all the created input devices and handlers.
    146   */
    147   void InputManager::destroy()
    148   {
    149     COUT(ORX_DEBUG) << "*** InputManager: Destroying ..." << std::endl;
    150     if (this->mouse_)
    151       this->inputSystem_->destroyInputObject(mouse_);
    152     if (this->keyboard_)
    153       this->inputSystem_->destroyInputObject(keyboard_);
    154     if (this->inputSystem_)
    155       OIS::InputManager::destroyInputSystem(this->inputSystem_);
    156 
    157     this->mouse_         = 0;
    158     this->keyboard_      = 0;
    159     this->inputSystem_   = 0;
    160 
    161     if (this->handlerBuffer_)
    162       delete this->handlerBuffer_;
    163     if (this->handlerGame_)
    164       delete this->handlerGame_;
    165     if (this->handlerGUI_)
    166       delete this->handlerGUI_;
    167 
    168     this->handlerBuffer_ = 0;
    169     this->handlerGame_   = 0;
    170     this->handlerGUI_    = 0;
    171 
    172     COUT(ORX_DEBUG) << "*** InputManager: Destroying done." << std::endl;
    173   }
    174 
    175   /**
    176     @brief Updates the InputManager
     221    catch (OIS::Exception ex)
     222    {
     223      CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS mouse\n"
     224          << "OIS error message: \"" << ex.eText << "\"" << std::endl;
     225      mouse_ = 0;
     226      return false;
     227    }
     228  }
     229
     230  /**
     231    @brief Creates all joy sticks and sets the event handler.
     232    @return False joy stick stay uninitialised, true otherwise.
     233  */
     234  bool InputManager::_initialiseJoySticks()
     235  {
     236    if (joySticks_.size() > 0)
     237    {
     238      CCOUT(2) << "Warning: Joy sticks already initialised, skipping." << std::endl;
     239      return true;
     240    }
     241    bool success = false;
     242    if (inputSystem_->getNumberOfDevices(OIS::OISJoyStick) > 0)
     243    {
     244      for (int i = 0; i < inputSystem_->getNumberOfDevices(OIS::OISJoyStick); i++)
     245      {
     246        try
     247        {
     248          OIS::JoyStick* stig = static_cast<OIS::JoyStick*>(inputSystem_->createInputObject(OIS::OISJoyStick, true));
     249          joySticks_.push_back(stig);
     250          // register our listener in OIS.
     251          stig->setEventCallback(this);
     252          CCOUT(ORX_DEBUG) << "Created OIS joy stick with ID " << stig->getID() << std::endl;
     253          success = true;
     254        }
     255        catch (OIS::Exception ex)
     256        {
     257          CCOUT(ORX_WARNING) << "Warning: Failed to create OIS joy number" << i << "\n"
     258              << "OIS error message: \"" << ex.eText << "\"" << std::endl;
     259        }
     260      }
     261    }
     262    else
     263    {
     264      CCOUT(ORX_WARNING) << "Warning: Joy stick support requested, but no joy stick was found" << std::endl;
     265      return false;
     266    }
     267    return success;
     268  }
     269
     270  /**
     271    @brief Destroys all the created input devices and sets the InputManager to construction state.
     272  */
     273  void InputManager::_destroy()
     274  {
     275    CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl;
     276
     277    if (state_ != IS_UNINIT)
     278    {
     279      if (keyHandlers_.find("buffer") != keyHandlers_.end())
     280        delete keyHandlers_["buffer"];
     281
     282      if (keyHandlers_.find("keybinder") != keyHandlers_.end())
     283        delete keyHandlers_["keybinder"];
     284
     285      keyHandlers_.clear();
     286      mouseHandlers_.clear();
     287      joyStickHandlers_.clear();
     288
     289      _destroyKeyboard();
     290      _destroyMouse();
     291      _destroyJoySticks();
     292
     293      // inputSystem_ can never be 0, or else the code is mistaken
     294      OIS::InputManager::destroyInputSystem(inputSystem_);
     295      inputSystem_ = 0;
     296
     297      state_ = IS_UNINIT;
     298    }
     299    else
     300      CCOUT(ORX_WARNING) << "Warning: Cannot be destroyed, since not initialised." << std::endl;
     301
     302    CCOUT(ORX_DEBUG) << "Destroying done." << std::endl;
     303  }
     304
     305  /**
     306    @brief Destroys the keyboard and sets it to 0.
     307  */
     308  void InputManager::_destroyKeyboard()
     309  {
     310    if (keyboard_)
     311      // inputSystem_ can never be 0, or else the code is mistaken
     312      inputSystem_->destroyInputObject(keyboard_);
     313    keyboard_ = 0;
     314    activeKeyHandlers_.clear();
     315    keysDown_.clear();
     316    CCOUT(ORX_DEBUG) << "Keyboard destroyed." << std::endl;
     317  }
     318
     319  /**
     320    @brief Destroys the mouse and sets it to 0.
     321  */
     322  void InputManager::_destroyMouse()
     323  {
     324    if (mouse_)
     325      // inputSystem_ can never be 0, or else the code is mistaken
     326      inputSystem_->destroyInputObject(mouse_);
     327    mouse_ = 0;
     328    activeMouseHandlers_.clear();
     329    mouseButtonsDown_.clear();
     330    CCOUT(ORX_DEBUG) << "Mouse destroyed." << std::endl;
     331  }
     332
     333  /**
     334    @brief Destroys all the joy sticks and resizes the lists to 0.
     335  */
     336  void InputManager::_destroyJoySticks()
     337  {
     338    if (joySticks_.size() > 0)
     339    {
     340      // note: inputSystem_ can never be 0, or else the code is mistaken
     341      for (unsigned int i = 0; i < joySticks_.size(); i++)
     342        if (joySticks_[i] != 0)
     343          inputSystem_->destroyInputObject(joySticks_[i]);
     344
     345      joySticks_.clear();
     346      activeJoyStickHandlers_.clear();
     347      joyStickButtonsDown_.clear();
     348    }
     349    CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl;
     350  }
     351
     352
     353  // #################################
     354  // ### Private Interface Methods ###
     355  // #################################
     356  // #################################
     357
     358  /**
     359    @brief Updates the InputManager. Tick is called by Orxonox.
    177360    @param dt Delta time
    178361  */
    179362  void InputManager::tick(float dt)
    180363  {
     364    if (state_ == IS_UNINIT)
     365      return;
     366
    181367    // reset the game if it has changed
    182     if (this->currentMode_ != this->setMode_)
    183     {
    184       switch (this->setMode_)
    185       {
    186       case IM_GUI:
    187         this->mouse_->setEventCallback(this->handlerGUI_);
    188         this->keyboard_->setEventCallback(this->handlerGUI_);
    189         break;
    190       case IM_INGAME:
    191         this->mouse_->setEventCallback(this->handlerGame_);
    192         this->keyboard_->setEventCallback(this->handlerGame_);
    193         break;
    194       case IM_KEYBOARD:
    195         this->mouse_->setEventCallback(this->handlerGame_);
    196         this->keyboard_->setEventCallback(this->handlerBuffer_);
    197         break;
    198       case IM_UNINIT:
    199         this->mouse_->setEventCallback(0);
    200         this->keyboard_->setEventCallback(0);
    201         break;
    202       }
    203       this->currentMode_ = this->setMode_;
    204     }
    205 
    206     // capture all the input. That calls the event handlers.
     368    if (state_ != stateRequest_)
     369    {
     370      if (stateRequest_ != IS_CUSTOM)
     371      {
     372        activeKeyHandlers_.clear();
     373        activeMouseHandlers_.clear();
     374        activeJoyStickHandlers_.clear();
     375
     376        switch (stateRequest_)
     377        {
     378        case IS_NORMAL:
     379          // normal play mode
     380          // note: we assume that the handlers exist since otherwise, something's wrong anyway.
     381          activeKeyHandlers_.push_back(keyHandlers_["keybinder"]);
     382          activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]);
     383          activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]);
     384          for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin();
     385                it != joySticks_.end(); it++)
     386            activeJoyStickHandlers_[*it].push_back(joyStickHandlers_["keybinder"]);
     387          break;
     388
     389        case IS_GUI:
     390          // FIXME: do stuff
     391          break;
     392
     393        case IS_CONSOLE:
     394          activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]);
     395          for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin();
     396                it != joySticks_.end(); it++)
     397            activeJoyStickHandlers_[*it].push_back(joyStickHandlers_["keybinder"]);
     398
     399          activeKeyHandlers_.push_back(keyHandlers_["buffer"]);
     400          break;
     401
     402        default:
     403          break;
     404        }
     405        state_ = stateRequest_;
     406      }
     407    }
     408
     409    // Capture all the input. This calls the event handlers in InputManager.
    207410    if (mouse_)
    208411      mouse_->capture();
    209 
    210412    if (keyboard_)
    211413      keyboard_->capture();
    212   }
     414
     415
     416    // call all the handlers for the held key events
     417    for (std::list<OIS::KeyCode>::const_iterator itKey = keysDown_.begin();
     418          itKey != keysDown_.end(); itKey++)
     419    {
     420      OIS::KeyEvent keyArg(keyboard_, *itKey, 0);
     421      for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
     422        activeKeyHandlers_[i]->keyHeld(keyArg);
     423    }
     424
     425    // call all the handlers for the held mouse button events
     426    for (std::list<OIS::MouseButtonID>::const_iterator itMouseButton = mouseButtonsDown_.begin();
     427          itMouseButton != mouseButtonsDown_.end(); itMouseButton++)
     428    {
     429      OIS::MouseEvent mouseButtonArg(mouse_, mouse_->getMouseState());
     430      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
     431        activeMouseHandlers_[i]->mouseHeld(mouseButtonArg, *itMouseButton);
     432    }
     433
     434    // call all the handlers for the held joy stick button events
     435    for (std::map< OIS::JoyStick*, std::list <int> >::const_iterator itJoyStick = joyStickButtonsDown_.begin();
     436          itJoyStick != joyStickButtonsDown_.end(); itJoyStick++)
     437    {
     438      OIS::JoyStick* joyStick = (*itJoyStick).first;
     439      for (std::list<int>::const_iterator itJoyStickButton = (*itJoyStick).second.begin();
     440            itJoyStickButton != (*itJoyStick).second.end(); itJoyStickButton++)
     441      {
     442        OIS::JoyStickEvent joyStickButtonArg(joyStick, joyStick->getJoyStickState());
     443        for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
     444          activeJoyStickHandlers_[joyStick][i]->buttonHeld(i, joyStickButtonArg, *itJoyStickButton);
     445      }
     446    }
     447  }
     448
     449
     450  // ###### Key Events ######
     451
     452  /**
     453    @brief Event handler for the keyPressed Event.
     454    @param e Event information
     455  */
     456  bool InputManager::keyPressed(const OIS::KeyEvent &e)
     457  {
     458    // check whether the key already is in the list (can happen when focus was lost)
     459    for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
     460    {
     461      if (*it == e.key)
     462      {
     463        keysDown_.erase(it);
     464        break;
     465      }
     466    }
     467    keysDown_.push_back(e.key);
     468
     469    for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
     470      activeKeyHandlers_[i]->keyPressed(e);
     471
     472    return true;
     473  }
     474
     475  /**
     476    @brief Event handler for the keyReleased Event.
     477    @param e Event information
     478  */
     479  bool InputManager::keyReleased(const OIS::KeyEvent &e)
     480  {
     481    // remove the key from the keysDown_ list
     482    for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
     483    {
     484      if (*it == e.key)
     485      {
     486        keysDown_.erase(it);
     487        break;
     488      }
     489    }
     490
     491    for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++)
     492      activeKeyHandlers_[i]->keyReleased(e);
     493
     494    return true;
     495  }
     496
     497
     498  // ###### Mouse Events ######
     499
     500  /**
     501    @brief Event handler for the mouseMoved Event.
     502    @param e Event information
     503  */
     504  bool InputManager::mouseMoved(const OIS::MouseEvent &e)
     505  {
     506    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
     507      activeMouseHandlers_[i]->mouseMoved(e);
     508
     509    return true;
     510  }
     511
     512  /**
     513    @brief Event handler for the mousePressed Event.
     514    @param e Event information
     515    @param id The ID of the mouse button
     516  */
     517  bool InputManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     518  {
     519    // check whether the button already is in the list (can happen when focus was lost)
     520    for (std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++)
     521    {
     522      if (*it == id)
     523      {
     524        mouseButtonsDown_.erase(it);
     525        break;
     526      }
     527    }
     528    mouseButtonsDown_.push_back(id);
     529
     530    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
     531      activeMouseHandlers_[i]->mousePressed(e, id);
     532
     533    return true;
     534  }
     535
     536  /**
     537    @brief Event handler for the mouseReleased Event.
     538    @param e Event information
     539    @param id The ID of the mouse button
     540  */
     541  bool InputManager::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     542  {
     543    // remove the button from the keysDown_ list
     544    for (std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++)
     545    {
     546      if (*it == id)
     547      {
     548        mouseButtonsDown_.erase(it);
     549        break;
     550      }
     551    }
     552
     553    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
     554      activeMouseHandlers_[i]->mouseReleased(e, id);
     555
     556    return true;
     557  }
     558
     559
     560  // ###### Joy Stick Events ######
     561
     562  bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button)
     563  {
     564    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     565
     566    // check whether the button already is in the list (can happen when focus was lost)
     567    std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick];
     568    for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++)
     569    {
     570      if (*it == button)
     571      {
     572        buttonsDownList.erase(it);
     573        break;
     574      }
     575    }
     576    joyStickButtonsDown_[joyStick].push_back(button);
     577
     578    for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
     579      activeJoyStickHandlers_[joyStick][i]->buttonPressed(i, arg, button);
     580
     581    return true;
     582  }
     583
     584  bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)
     585  {
     586    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     587
     588    // remove the button from the joyStickButtonsDown_ list
     589    std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick];
     590    for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++)
     591    {
     592      if (*it == button)
     593      {
     594        buttonsDownList.erase(it);
     595        break;
     596      }
     597    }
     598
     599    for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
     600      activeJoyStickHandlers_[joyStick][i]->buttonReleased(i, arg, button);
     601
     602    return true;
     603  }
     604
     605  bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
     606  {
     607    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     608    for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
     609      activeJoyStickHandlers_[joyStick][i]->axisMoved(i, arg, axis);
     610
     611    return true;
     612  }
     613
     614  bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id)
     615  {
     616    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     617    for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
     618      activeJoyStickHandlers_[joyStick][i]->sliderMoved(i, arg, id);
     619
     620    return true;
     621  }
     622
     623  bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id)
     624  {
     625    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     626    for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
     627      activeJoyStickHandlers_[joyStick][i]->povMoved(i, arg, id);
     628
     629    return true;
     630  }
     631
     632  bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
     633  {
     634    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     635    for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)
     636      activeJoyStickHandlers_[joyStick][i]->vector3Moved(i, arg, id);
     637
     638    return true;
     639  }
     640
     641
     642  // ################################
     643  // ### Static Interface Methods ###
     644  // ################################
     645  // ################################
     646
     647  bool InputManager::initialise(const size_t windowHnd, const int windowWidth, const int windowHeight,
     648    const bool createKeyboard, const bool createMouse, const bool createJoySticks)
     649  {
     650    return _getSingleton()._initialise(windowHnd, windowWidth, windowHeight,
     651          createKeyboard, createMouse, createJoySticks);
     652  }
     653
     654  bool InputManager::initialiseKeyboard()
     655  {
     656    return _getSingleton()._initialiseKeyboard();
     657  }
     658
     659  bool InputManager::initialiseMouse()
     660  {
     661    return _getSingleton()._initialiseMouse();
     662  }
     663
     664  bool InputManager::initialiseJoySticks()
     665  {
     666    return _getSingleton()._initialiseJoySticks();
     667  }
     668
     669  int InputManager::numberOfKeyboards()
     670  {
     671    if (_getSingleton().keyboard_ != 0)
     672      return 1;
     673    else
     674      return 0;
     675  }
     676
     677  int InputManager::numberOfMice()
     678  {
     679    if (_getSingleton().mouse_ != 0)
     680      return 1;
     681    else
     682      return 0;
     683  }
     684
     685  int InputManager::numberOfJoySticks()
     686  {
     687    return _getSingleton().joySticks_.size();
     688  }
     689
     690
     691  void InputManager::destroy()
     692  {
     693    _getSingleton()._destroy();
     694  }
     695
     696  void InputManager::destroyKeyboard()
     697  {
     698    return _getSingleton()._destroyKeyboard();
     699  }
     700
     701  void InputManager::destroyMouse()
     702  {
     703    return _getSingleton()._destroyMouse();
     704  }
     705
     706  void InputManager::destroyJoySticks()
     707  {
     708    return _getSingleton()._destroyJoySticks();
     709  }
     710
    213711
    214712  /**
     
    218716    @param height the new height of the render window
    219717  */
    220   void InputManager::setWindowExtents(int width, int height)
    221   {
    222     // Set mouse region (if window resizes, we should alter this to reflect as well)
    223     const OIS::MouseState &mouseState = mouse_->getMouseState();
    224     mouseState.width  = width;
    225     mouseState.height = height;
     718  void InputManager::setWindowExtents(const int width, const int height)
     719  {
     720    if (_getSingleton().mouse_)
     721    {
     722      // Set mouse region (if window resizes, we should alter this to reflect as well)
     723      const OIS::MouseState &mouseState = _getSingleton().mouse_->getMouseState();
     724      mouseState.width  = width;
     725      mouseState.height = height;
     726    }
    226727  }
    227728
     
    231732    @remark Only has an affect if the mode actually changes
    232733  */
    233   void InputManager::setInputMode(int mode)
    234   {
    235     if (mode > 0 && mode < 4)
    236       getSingleton().setMode_ = (InputMode)mode;
     734  void InputManager::setInputState(const InputState state)
     735  {
     736    _getSingleton().stateRequest_ = state;
    237737  }
    238738
     
    241741    @return The current input mode.
    242742  */
    243   InputMode InputManager::getInputMode()
    244   {
    245     return this->currentMode_;
    246   }
    247 
    248   void InputManager::feedInputBuffer(InputBuffer* buffer)
    249   {
    250     this->handlerBuffer_ = buffer;
    251   }
    252 
     743  InputManager::InputState InputManager::getInputState()
     744  {
     745    return _getSingleton().state_;
     746  }
     747
     748
     749  // ###### KeyHandler ######
     750
     751  /**
     752    @brief Adds a new key handler.
     753    @param handler Pointer to the handler object.
     754    @param name Unique name of the handler.
     755    @return True if added, false if name already existed.
     756  */
     757  bool InputManager::addKeyHandler(KeyHandler* handler, const std::string& name)
     758  {
     759    if (_getSingleton().keyHandlers_.find(name) == _getSingleton().keyHandlers_.end())
     760    {
     761      _getSingleton().keyHandlers_[name] = handler;
     762      return true;
     763    }
     764    else
     765      return false;
     766  }
     767
     768  /**
     769    @brief Removes a Key handler from the list.
     770    @param name Unique name of the handler.
     771    @return True if removal was successful, false if name was not found.
     772  */
     773  bool InputManager::removeKeyHandler(const std::string &name)
     774  {
     775    disableKeyHandler(name);
     776    std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name);
     777    if (it != _getSingleton().keyHandlers_.end())
     778    {
     779      _getSingleton().keyHandlers_.erase(it);
     780      return true;
     781    }
     782    else
     783      return false;
     784  }
     785
     786  /**
     787    @brief Returns the pointer to a handler.
     788    @param name Unique name of the handler.
     789    @return Pointer to the instance, 0 if name was not found.
     790  */
     791  KeyHandler* InputManager::getKeyHandler(const std::string& name)
     792  {
     793    std::map<std::string, KeyHandler*>::iterator it = _getSingleton().keyHandlers_.find(name);
     794    if (it != _getSingleton().keyHandlers_.end())
     795    {
     796      return (*it).second;
     797    }
     798    else
     799      return 0;
     800  }
     801
     802  /**
     803    @brief Enables a specific key handler that has already been added.
     804    @param name Unique name of the handler.
     805    @return False if name was not found, true otherwise.
     806  */
     807  bool InputManager::enableKeyHandler(const std::string& name)
     808  {
     809    // get pointer from the map with all stored handlers
     810    std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name);
     811    if (mapIt == _getSingleton().keyHandlers_.end())
     812      return false;
     813    // see whether the handler already is in the list
     814    for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
     815          it != _getSingleton().activeKeyHandlers_.end(); it++)
     816    {
     817      if ((*it) == (*mapIt).second)
     818      {
     819        _getSingleton().stateRequest_ = IS_CUSTOM;
     820        return true;
     821      }
     822    }
     823    _getSingleton().activeKeyHandlers_.push_back((*mapIt).second);
     824    _getSingleton().stateRequest_ = IS_CUSTOM;
     825    return true;
     826  }
     827
     828  /**
     829    @brief Disables a specific key handler.
     830    @param name Unique name of the handler.
     831    @return False if name was not found, true otherwise.
     832  */
     833  bool InputManager::disableKeyHandler(const std::string &name)
     834  {
     835    // get pointer from the map with all stored handlers
     836    std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name);
     837    if (mapIt == _getSingleton().keyHandlers_.end())
     838      return false;
     839    // look for the handler in the list
     840    for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
     841          it != _getSingleton().activeKeyHandlers_.end(); it++)
     842    {
     843      if ((*it) == (*mapIt).second)
     844      {
     845        _getSingleton().activeKeyHandlers_.erase(it);
     846        _getSingleton().stateRequest_ = IS_CUSTOM;
     847        return true;
     848      }
     849    }
     850    _getSingleton().stateRequest_ = IS_CUSTOM;
     851    return true;
     852  }
     853
     854  /**
     855    @brief Checks whether a key handler is active
     856    @param name Unique name of the handler.
     857    @return False if key handler is not active or doesn't exist, true otherwise.
     858  */
     859  bool InputManager::isKeyHandlerActive(const std::string& name)
     860  {
     861    // get pointer from the map with all stored handlers
     862    std::map<std::string, KeyHandler*>::const_iterator mapIt = _getSingleton().keyHandlers_.find(name);
     863    if (mapIt == _getSingleton().keyHandlers_.end())
     864      return false;
     865    // see whether the handler already is in the list
     866    for (std::vector<KeyHandler*>::iterator it = _getSingleton().activeKeyHandlers_.begin();
     867          it != _getSingleton().activeKeyHandlers_.end(); it++)
     868    {
     869      if ((*it) == (*mapIt).second)
     870        return true;
     871    }
     872    return false;
     873  }
     874
     875
     876  // ###### MouseHandler ######
     877  /**
     878    @brief Adds a new mouse handler.
     879    @param handler Pointer to the handler object.
     880    @param name Unique name of the handler.
     881    @return True if added, false if name already existed.
     882  */
     883  bool InputManager::addMouseHandler(MouseHandler* handler, const std::string& name)
     884  {
     885    if (_getSingleton().mouseHandlers_.find(name) == _getSingleton().mouseHandlers_.end())
     886    {
     887      _getSingleton().mouseHandlers_[name] = handler;
     888      return true;
     889    }
     890    else
     891      return false;
     892  }
     893
     894  /**
     895    @brief Removes a Mouse handler from the list.
     896    @param name Unique name of the handler.
     897    @return True if removal was successful, false if name was not found.
     898  */
     899  bool InputManager::removeMouseHandler(const std::string &name)
     900  {
     901    disableMouseHandler(name);
     902    std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name);
     903    if (it != _getSingleton().mouseHandlers_.end())
     904    {
     905      _getSingleton().mouseHandlers_.erase(it);
     906      return true;
     907    }
     908    else
     909      return false;
     910  }
     911
     912  /**
     913    @brief Returns the pointer to a handler.
     914    @param name Unique name of the handler.
     915    @return Pointer to the instance, 0 if name was not found.
     916  */
     917  MouseHandler* InputManager::getMouseHandler(const std::string& name)
     918  {
     919    std::map<std::string, MouseHandler*>::iterator it = _getSingleton().mouseHandlers_.find(name);
     920    if (it != _getSingleton().mouseHandlers_.end())
     921    {
     922      return (*it).second;
     923    }
     924    else
     925      return 0;
     926  }
     927
     928  /**
     929    @brief Enables a specific mouse handler that has already been added.
     930    @param name Unique name of the handler.
     931    @return False if name was not found, true otherwise.
     932  */
     933  bool InputManager::enableMouseHandler(const std::string& name)
     934  {
     935    // get pointer from the map with all stored handlers
     936    std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);
     937    if (mapIt == _getSingleton().mouseHandlers_.end())
     938      return false;
     939    // see whether the handler already is in the list
     940    for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
     941          it != _getSingleton().activeMouseHandlers_.end(); it++)
     942    {
     943      if ((*it) == (*mapIt).second)
     944      {
     945        _getSingleton().stateRequest_ = IS_CUSTOM;
     946        return true;
     947      }
     948    }
     949    _getSingleton().activeMouseHandlers_.push_back((*mapIt).second);
     950    _getSingleton().stateRequest_ = IS_CUSTOM;
     951    return true;
     952  }
     953
     954  /**
     955    @brief Disables a specific mouse handler.
     956    @param name Unique name of the handler.
     957    @return False if name was not found, true otherwise.
     958  */
     959  bool InputManager::disableMouseHandler(const std::string &name)
     960  {
     961    // get pointer from the map with all stored handlers
     962    std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);
     963    if (mapIt == _getSingleton().mouseHandlers_.end())
     964      return false;
     965    // look for the handler in the list
     966    for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
     967          it != _getSingleton().activeMouseHandlers_.end(); it++)
     968    {
     969      if ((*it) == (*mapIt).second)
     970      {
     971        _getSingleton().activeMouseHandlers_.erase(it);
     972        _getSingleton().stateRequest_ = IS_CUSTOM;
     973        return true;
     974      }
     975    }
     976    _getSingleton().stateRequest_ = IS_CUSTOM;
     977    return true;
     978  }
     979
     980  /**
     981    @brief Checks whether a mouse handler is active
     982    @param name Unique name of the handler.
     983    @return False if key handler is not active or doesn't exist, true otherwise.
     984  */
     985  bool InputManager::isMouseHandlerActive(const std::string& name)
     986  {
     987    // get pointer from the map with all stored handlers
     988    std::map<std::string, MouseHandler*>::const_iterator mapIt = _getSingleton().mouseHandlers_.find(name);
     989    if (mapIt == _getSingleton().mouseHandlers_.end())
     990      return false;
     991    // see whether the handler already is in the list
     992    for (std::vector<MouseHandler*>::iterator it = _getSingleton().activeMouseHandlers_.begin();
     993          it != _getSingleton().activeMouseHandlers_.end(); it++)
     994    {
     995      if ((*it) == (*mapIt).second)
     996        return true;
     997    }
     998    return false;
     999  }
     1000
     1001
     1002  // ###### JoyStickHandler ######
     1003
     1004  /**
     1005    @brief Adds a new joy stick handler.
     1006    @param handler Pointer to the handler object.
     1007    @param name Unique name of the handler.
     1008    @return True if added, false if name already existed.
     1009  */
     1010  bool InputManager::addJoyStickHandler(JoyStickHandler* handler, const std::string& name)
     1011  {
     1012    if (_getSingleton().joyStickHandlers_.find(name) == _getSingleton().joyStickHandlers_.end())
     1013    {
     1014      _getSingleton().joyStickHandlers_[name] = handler;
     1015      return true;
     1016    }
     1017    else
     1018      return false;
     1019  }
     1020
     1021  /**
     1022    @brief Removes a JoyStick handler from the list.
     1023    @param name Unique name of the handler.
     1024    @return True if removal was successful, false if name was not found.
     1025  */
     1026  bool InputManager::removeJoyStickHandler(const std::string &name)
     1027  {
     1028    for (std::vector<OIS::JoyStick*>::iterator itstick = _getSingleton().joySticks_.begin();
     1029          itstick != _getSingleton().joySticks_.end(); itstick++)
     1030      disableJoyStickHandler(name, itstick - _getSingleton().joySticks_.begin());
     1031
     1032    std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name);
     1033    if (it != _getSingleton().joyStickHandlers_.end())
     1034    {
     1035      _getSingleton().joyStickHandlers_.erase(it);
     1036      return true;
     1037    }
     1038    else
     1039      return false;
     1040  }
     1041
     1042  /**
     1043    @brief Returns the pointer to a handler.
     1044    @param name Unique name of the handler.
     1045    @return Pointer to the instance, 0 if name was not found.
     1046  */
     1047  JoyStickHandler* InputManager::getJoyStickHandler(const std::string& name)
     1048  {
     1049    std::map<std::string, JoyStickHandler*>::iterator it = _getSingleton().joyStickHandlers_.find(name);
     1050    if (it != _getSingleton().joyStickHandlers_.end())
     1051    {
     1052      return (*it).second;
     1053    }
     1054    else
     1055      return 0;
     1056  }
     1057
     1058  /**
     1059    @brief Enables a specific joy stick handler that has already been added.
     1060    @param name Unique name of the handler.
     1061    @return False if name or id was not found, true otherwise.
     1062  */
     1063  bool InputManager::enableJoyStickHandler(const std::string& name, const int ID)
     1064  {
     1065    // get handler pointer from the map with all stored handlers
     1066    std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);
     1067    if (handlerIt == _getSingleton().joyStickHandlers_.end())
     1068      return false;
     1069
     1070    // check for existence of the ID
     1071    if ((unsigned int)ID >= _getSingleton().joySticks_.size())
     1072      return false;
     1073    OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID];
     1074
     1075    // see whether the handler already is in the list
     1076    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[joyStick].begin();
     1077          it != _getSingleton().activeJoyStickHandlers_[joyStick].end(); it++)
     1078    {
     1079      if ((*it) == (*handlerIt).second)
     1080      {
     1081        _getSingleton().stateRequest_ = IS_CUSTOM;
     1082        return true;
     1083      }
     1084    }
     1085    _getSingleton().activeJoyStickHandlers_[joyStick].push_back((*handlerIt).second);
     1086    _getSingleton().stateRequest_ = IS_CUSTOM;
     1087    return true;
     1088  }
     1089
     1090  /**
     1091    @brief Disables a specific joy stick handler.
     1092    @param name Unique name of the handler.
     1093    @return False if name or id was not found, true otherwise.
     1094  */
     1095  bool InputManager::disableJoyStickHandler(const std::string &name, int ID)
     1096  {
     1097    // get handler pointer from the map with all stored handlers
     1098    std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);
     1099    if (handlerIt == _getSingleton().joyStickHandlers_.end())
     1100      return false;
     1101
     1102    // check for existence of the ID
     1103    if ((unsigned int)ID >= _getSingleton().joySticks_.size())
     1104      return false;
     1105    OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID];
     1106
     1107    // look for the handler in the list
     1108    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[joyStick].begin();
     1109          it != _getSingleton().activeJoyStickHandlers_[joyStick].end(); it++)
     1110    {
     1111      if ((*it) == (*handlerIt).second)
     1112      {
     1113        _getSingleton().activeJoyStickHandlers_[joyStick].erase(it);
     1114        _getSingleton().stateRequest_ = IS_CUSTOM;
     1115        return true;
     1116      }
     1117    }
     1118    return true;
     1119  }
     1120
     1121  /**
     1122    @brief Checks whether a joy stick handler is active
     1123    @param name Unique name of the handler.
     1124    @return False if key handler is not active or doesn't exist, true otherwise.
     1125  */
     1126  bool InputManager::isJoyStickHandlerActive(const std::string& name, const int ID)
     1127  {
     1128    // get handler pointer from the map with all stored handlers
     1129    std::map<std::string, JoyStickHandler*>::const_iterator handlerIt = _getSingleton().joyStickHandlers_.find(name);
     1130    if (handlerIt == _getSingleton().joyStickHandlers_.end())
     1131      return false;
     1132
     1133    // check for existence of the ID
     1134    if ((unsigned int)ID >= _getSingleton().joySticks_.size())
     1135      return false;
     1136    OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID];
     1137
     1138    // see whether the handler already is in the list
     1139    for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[joyStick].begin();
     1140          it != _getSingleton().activeJoyStickHandlers_[joyStick].end(); it++)
     1141    {
     1142      if ((*it) == (*handlerIt).second)
     1143        return true;
     1144    }
     1145    return false;
     1146  }
    2531147
    2541148}
  • code/trunk/src/core/InputManager.h

    r1084 r1219  
    3838#include "CorePrereqs.h"
    3939
    40 #include <OIS/OIS.h>
     40#include <map>
     41#include <list>
    4142
     43#include "ois/OIS.h"
    4244#include "Tickable.h"
    43 #include "InputEvent.h"
    4445
    4546namespace orxonox
    4647{
    47   /**
    48     @brief Designates the way input is handled currently.
    49     IM_GUI:      All the OIS input events are passed to CEGUI
    50     IM_KEYBOARD: Only keyboard input is captured and passed to the InputBuffer
    51     IM_INGAME:   Normal game mode. Key bindings and mouse are active.
    52   */
    53   enum InputMode
     48  class Mouse : public OIS::Mouse
    5449  {
    55     IM_GUI      = 0,
    56     IM_KEYBOARD = 1,
    57     IM_INGAME   = 2,
    58     IM_UNINIT   = 3,
    5950  };
    6051
    6152  /**
    6253    @brief Captures and distributes mouse and keyboard input.
    63     It resolves the key bindings to InputEvents which can be heard by
    64     implementing the InputEventListener interface.
    6554  */
    6655  class _CoreExport InputManager
    67         : public Tickable
     56        : public Tickable,
     57          public OIS::KeyListener, public OIS::MouseListener, public OIS::JoyStickListener
    6858  {
    69   public:
    70     bool initialise(size_t windowHnd, int windowWidth, int windowHeight);
    71     void destroy();
    72     void tick(float dt);
    73     void setWindowExtents(int width, int height);
    74     InputMode getInputMode();
     59  public: // enumerations
     60    /**
     61      @brief Designates the way input is handled and redirected.
     62    */
     63    enum InputState
     64    {
     65      IS_UNINIT,  //!< InputManager has not yet been initialised.
     66      IS_NONE,    //!< Input is discarded.
     67      IS_NORMAL,  //!< Normal play state. Key and button bindings are active.
     68      IS_GUI,     //!< All OIS input events are passed to CEGUI.
     69      IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer.
     70      IS_CUSTOM   //!< Any possible configuration.
     71    };
    7572
    76     // temporary hack
    77     void feedInputBuffer(InputBuffer* buffer);
     73  public: // static functions
     74    static bool initialise(const size_t windowHnd, const int windowWidth, const int windowHeight,
     75          const bool createKeyboard = true, const bool createMouse = true, const bool createJoySticks = false);
     76    static bool initialiseKeyboard();
     77    static bool initialiseMouse();
     78    static bool initialiseJoySticks();
     79    static int  numberOfKeyboards();
     80    static int  numberOfMice();
     81    static int  numberOfJoySticks();
     82
     83    static void destroy();
     84    static void destroyKeyboard();
     85    static void destroyMouse();
     86    static void destroyJoySticks();
     87
     88    static void setWindowExtents(const int width, const int height);
     89
     90    static void setInputState(const InputState state);
     91    static InputState getInputState();
     92
     93    static bool addKeyHandler                 (KeyHandler* handler, const std::string& name);
     94    static bool removeKeyHandler              (const std::string& name);
     95    static KeyHandler* getKeyHandler          (const std::string& name);
     96    static bool enableKeyHandler              (const std::string& name);
     97    static bool disableKeyHandler             (const std::string& name);
     98    static bool isKeyHandlerActive            (const std::string& name);
     99
     100    static bool addMouseHandler               (MouseHandler* handler, const std::string& name);
     101    static bool removeMouseHandler            (const std::string& name);
     102    static MouseHandler* getMouseHandler      (const std::string& name);
     103    static bool enableMouseHandler            (const std::string& name);
     104    static bool disableMouseHandler           (const std::string& name);
     105    static bool isMouseHandlerActive          (const std::string& name);
     106
     107    static bool addJoyStickHandler            (JoyStickHandler* handler, const std::string& name);
     108    static bool removeJoyStickHandler         (const std::string& name);
     109    static JoyStickHandler* getJoyStickHandler(const std::string& name);
     110    static bool enableJoyStickHandler         (const std::string& name, const int id);
     111    static bool disableJoyStickHandler        (const std::string& name, const int id);
     112    static bool isJoyStickHandlerActive       (const std::string& name, const int id);
    78113
    79114    // Temporary solutions. Will be removed soon!
    80     OIS::Mouse    *getMouse()    { return this->mouse_   ; }
    81     OIS::Keyboard *getKeyboard() { return this->keyboard_; }
     115    static OIS::Mouse*    getMouse()    { return _getSingleton().mouse_   ; }
     116    static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; }
    82117
    83     static InputManager& getSingleton();
    84     static InputManager* getSingletonPtr() { return &getSingleton(); }
    85     static void setInputMode(int mode);
    86 
    87   private:
     118  private: // functions
    88119    // don't mess with a Singleton
    89120    InputManager ();
     
    91122    ~InputManager();
    92123
    93     OIS::InputManager *inputSystem_;    //!< OIS input manager
    94     OIS::Keyboard     *keyboard_;       //!< OIS mouse
    95     OIS::Mouse        *mouse_;          //!< OIS keyboard
     124    // Intenal methods
     125    bool _initialise(const size_t, const int, const int, const bool, const bool, const bool);
     126    bool _initialiseKeyboard();
     127    bool _initialiseMouse();
     128    bool _initialiseJoySticks();
    96129
    97     InputMode          currentMode_;    //!< Input mode currently used
    98     InputMode          setMode_;        //!< Input mode that has been set lately
    99     InputHandlerGUI   *handlerGUI_;     //!< Handles the input if in GUI mode
    100     // FIXME: insert the InputBuffer once merged with core2
    101     InputBuffer       *handlerBuffer_;  //!< Handles the input if in Buffer mode
    102     InputHandlerGame  *handlerGame_;    //!< Handles the input if in Game mode
     130    void _destroy();
     131    void _destroyKeyboard();
     132    void _destroyMouse();
     133    void _destroyJoySticks();
    103134
    104     //! Pointer to the instance of the singleton
    105     //static InputManager *singletonRef_s;
     135    //void _setNumberOfJoysticks(int size);
     136
     137    void tick(float dt);
     138
     139    // input events
     140                bool mousePressed  (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
     141                bool mouseReleased (const OIS::MouseEvent    &arg, OIS::MouseButtonID id);
     142    bool mouseMoved    (const OIS::MouseEvent    &arg);
     143                bool keyPressed    (const OIS::KeyEvent      &arg);
     144                bool keyReleased   (const OIS::KeyEvent      &arg);
     145                bool buttonPressed (const OIS::JoyStickEvent &arg, int button);
     146                bool buttonReleased(const OIS::JoyStickEvent &arg, int button);
     147                bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
     148                bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
     149                bool povMoved      (const OIS::JoyStickEvent &arg, int id);
     150                bool vector3Moved  (const OIS::JoyStickEvent &arg, int id);
     151
     152    static InputManager& _getSingleton();
     153    static InputManager* _getSingletonPtr() { return &_getSingleton(); }
     154
     155  private: // variables
     156    OIS::InputManager*                          inputSystem_; //!< OIS input manager
     157    OIS::Keyboard*                              keyboard_;    //!< OIS mouse
     158    OIS::Mouse*                                 mouse_;       //!< OIS keyboard
     159    std::vector<OIS::JoyStick*>                 joySticks_;   //!< OIS joy sticks
     160
     161    InputState state_;
     162    InputState stateRequest_;
     163
     164    std::map<std::string, KeyHandler*>          keyHandlers_;
     165    std::map<std::string, MouseHandler*>        mouseHandlers_;
     166    std::map<std::string, JoyStickHandler*>     joyStickHandlers_;
     167
     168    std::vector<KeyHandler*>                    activeKeyHandlers_;
     169    std::vector<MouseHandler*>                  activeMouseHandlers_;
     170    std::map< OIS::JoyStick*, std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
     171
     172    std::list<OIS::KeyCode>                     keysDown_;
     173    std::list<OIS::MouseButtonID>               mouseButtonsDown_;
     174    std::map< OIS::JoyStick*, std::list<int> >  joyStickButtonsDown_;
     175
    106176  };
    107177}
  • code/trunk/src/orxonox/CMakeLists.txt

    r1214 r1219  
    5858  tinyxml
    5959  tolualib
     60  ois
    6061  util
    6162  core
  • code/trunk/src/orxonox/Orxonox.cc

    r1214 r1219  
    8585namespace orxonox
    8686{
    87   ConsoleCommand(Orxonox, exit, AccessLevel::None, true);
    88   ConsoleCommand(Orxonox, slomo, AccessLevel::Offline, true).setDefaultValue(0, 1.0);
    89   ConsoleCommand(Orxonox, setTimeFactor, AccessLevel::Offline, false).setDefaultValue(0, 1.0);
    90 
     87  ConsoleCommandShortcut(Orxonox, exit, AccessLevel::None);
     88  ConsoleCommandShortcut(Orxonox, slomo, AccessLevel::Offline).setDefaultValue(0, 1.0);
     89  ConsoleCommandShortcut(Orxonox, setTimeFactor, AccessLevel::Offline).setDefaultValue(0, 1.0);
     90  ConsoleCommandShortcut(Orxonox, activateConsole, AccessLevel::None);
    9191  class Testconsole : public InputBufferListener
    9292  {
     
    119119      void exit() const
    120120      {
    121         CommandExecutor::execute("setInputMode 2");
     121        InputManager::setInputState(InputManager::IS_NORMAL);
    122122      }
    123123
     
    185185      delete this->orxonoxHUD_;
    186186    Loader::close();
    187     InputManager::getSingleton().destroy();
     187    InputManager::destroy();
    188188    if (this->auMan_)
    189189      delete this->auMan_;
     
    400400  void Orxonox::setupInputSystem()
    401401  {
    402     inputHandler_ = &InputManager::getSingleton();
    403     if (!inputHandler_->initialise(ogre_->getWindowHandle(),
     402    if (!InputManager::initialise(ogre_->getWindowHandle(),
    404403          ogre_->getWindowWidth(), ogre_->getWindowHeight()))
    405404      abortImmediateForce();
    406     inputHandler_->setInputMode(IM_INGAME);
     405    InputManager::setInputState(InputManager::IS_NORMAL);
    407406  }
    408407
     
    423422  void Orxonox::startRenderLoop()
    424423  {
    425     InputBuffer* ib = new InputBuffer();
    426     InputManager::getSingleton().feedInputBuffer(ib);
     424    InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer"));
    427425    /*
    428426    Testconsole* console = new Testconsole(ib);
     
    459457      eventTimes[i].clear();
    460458    // fill the fps time list with zeros
    461     for (int i = 0; i < 20; i++)
     459    for (int i = 0; i < 50; i++)
    462460      eventTimes[3].push_back(0);
    463461
     
    485483      // show the current time in the HUD
    486484      orxonoxHUD_->setTime((int)now, 0);
     485      orxonoxHUD_->setRocket2(ogreRoot.getCurrentFrameNumber());
    487486      if (eventTimes[3].back() - eventTimes[3].front() != 0)
    488         orxonoxHUD_->setRocket1((int)(20000.0f/(eventTimes[3].back() - eventTimes[3].front())));
     487        orxonoxHUD_->setRocket1((int)(50000.0f/(eventTimes[3].back() - eventTimes[3].front())));
    489488
    490489      // Iterate through all Tickables and call their tick(dt) function
     
    551550  }
    552551
    553   /**
    554     @brief Test method for the InputHandler.
    555     But: Is actually responsible for catching an exit event..
    556   */
    557   void Orxonox::eventOccured(InputEvent &evt)
    558   {
    559     if (evt.id == 1)
    560       this->abortRequest();
     552  void Orxonox::activateConsole()
     553  {
     554    InputManager::setInputState(InputManager::IS_CONSOLE);
    561555  }
    562556}
  • code/trunk/src/orxonox/Orxonox.h

    r1214 r1219  
    4444
    4545#include "GraphicsEngine.h"
    46 #include "core/InputEventListener.h"
    47 
    4846
    4947namespace orxonox {
     
    5654
    5755  //! Orxonox singleton class
    58   class _OrxonoxExport Orxonox : public InputEventListener
     56  class _OrxonoxExport Orxonox
    5957  {
    6058    public:
     
    7270      static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; }
    7371      static inline void exit() { Orxonox::getSingleton()->abortRequest(); }
     72      static inline void activateConsole();
    7473
    7574   private:
     
    9594      float calculateEventTime(unsigned long, std::deque<unsigned long>&);
    9695
    97       void eventOccured(InputEvent &evt);
    98 
    9996    private:
    10097      GraphicsEngine*       ogre_;          //!< our dearest graphics engine <3
  • code/trunk/src/orxonox/OrxonoxStableHeaders.h

    r1209 r1219  
    7979#include <OgreWindowEventUtilities.h>
    8080
    81 #include <OIS/OIS.h>
    82 
    8381//-----------------------------------------------------------------------
    8482// ORXONOX HEADERS
    8583//-----------------------------------------------------------------------
     84
     85#include "ois/OIS.h"
    8686
    8787//#include "util/Convert.h"
  • code/trunk/src/orxonox/objects/SpaceShip.cc

    r1209 r1219  
    3232#include <string>
    3333
    34 #include <OIS/OIS.h>
    3534#include <OgreCamera.h>
    3635#include <OgreRenderWindow.h>
     
    3938
    4039#include "tinyxml/tinyxml.h"
     40#include "ois/OIS.h"
    4141#include "util/Convert.h"
    4242#include "util/Math.h"
     
    428428    void SpaceShip::tick(float dt)
    429429    {
    430       if (InputManager::getSingleton().getMouse()->getEventCallback() != this)
    431         {
    432             if (InputManager::getSingleton().getMouse())
    433             {
    434                 InputManager::getSingleton().getMouse()->setEventCallback(this);
    435                 this->setMouseEventCallback_ = true;
    436             }
     430        if (!setMouseEventCallback_)
     431        {
     432          InputManager::addMouseHandler(this, "SpaceShip");
     433          setMouseEventCallback_ = true;
    437434        }
    438435
     
    457454        }
    458455
    459         OIS::Keyboard* mKeyboard = InputManager::getSingleton().getKeyboard();
    460         //FIXME: variable never used
    461         //OIS::Mouse* mMouse = InputManager::getSingleton().getMouse();
     456        OIS::Keyboard* mKeyboard = InputManager::getKeyboard();
    462457
    463458
  • code/trunk/src/orxonox/objects/SpaceShip.h

    r1056 r1219  
    3333
    3434#include <OgrePrerequisites.h>
    35 #include <OIS/OISMouse.h>
    3635
     36#include "core/InputHandler.h"
    3737#include "Model.h"
    3838#include "../tools/BillboardSet.h"
     
    4040namespace orxonox
    4141{
    42     class _OrxonoxExport SpaceShip : public Model, public OIS::MouseListener
     42    class _OrxonoxExport SpaceShip : public Model, public MouseHandler
    4343    {
    4444        public:
     
    6868            bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id);
    6969            bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id);
     70            bool mouseHeld(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; }
    7071
    7172
  • code/trunk/src/util/String.cc

    r1214 r1219  
    6565{
    6666    unsigned int pos1 = 0;
    67     unsigned int pos2 = str.size() - 1;
     67    int pos2 = str.size() - 1;
    6868    for (; pos1 < str.size() && (str[pos1] == ' ' || str[pos1] == '\t' || str[pos1] == '\n'); pos1++);
    69     for (; pos2 >= 0         && (str[pos2] == ' ' || str[pos2] == '\t' || str[pos2] == '\n'); pos2--);
     69    for (; pos2 > 0          && (str[pos2] == ' ' || str[pos2] == '\t' || str[pos2] == '\n'); pos2--);
    7070    return str.substr(pos1, pos2 - pos1 + 1);
    7171}
  • code/trunk/visual_studio/base_properties.vsprops

    r1084 r1219  
    88        <Tool
    99                Name="VCCLCompilerTool"
    10                 AdditionalIncludeDirectories="&quot;$(RootDir)src&quot;;&quot;$(RootDir)src\orxonox&quot;;&quot;$(RootDir)src\util\tolua&quot;;&quot;$(DependencyDir)include&quot;"
     10                AdditionalIncludeDirectories="&quot;$(RootDir)src&quot;;&quot;$(RootDir)src\orxonox&quot;;&quot;$(RootDir)src\util\tolua&quot;;&quot;$(RootDir)src\ois\include&quot;;&quot;$(DependencyDir)include&quot;"
    1111                PreprocessorDefinitions="WIN32;__WIN32__;_WIN32;BOOST_ALL_DYN_LINK;OIS_DYNAMIC_LIB; ZLIB_WINAPI"
    1212                WarningLevel="3"
  • code/trunk/visual_studio/core_properties.vsprops

    r1206 r1219  
    1212        <Tool
    1313                Name="VCLinkerTool"
    14                 AdditionalDependencies="OgreMain$(CSS).lib ois-1.2.0$(CS).lib lua-5.1$(CS).lib"
     14                AdditionalDependencies="OgreMain$(CSS).lib lua-5.1$(CS).lib"
    1515        />
    1616</VisualStudioPropertySheet>
  • code/trunk/visual_studio/orxonox_properties.vsprops

    r1206 r1219  
    1414        <Tool
    1515                Name="VCLinkerTool"
    16                 AdditionalDependencies="OgreMain$(CSS).lib ois-1.2.0$(CS).lib"
     16                AdditionalDependencies="OgreMain$(CSS).lib"
    1717                OutputFile="$(OutDir)$(ProjectName)$(CS).exe"
    1818                IgnoreDefaultLibraryNames=""
  • code/trunk/visual_studio/orxonox_vc8.sln

    r1209 r1219  
    77        EndProjectSection
    88        ProjectSection(ProjectDependencies) = postProject
     9                {271715F3-5B90-4110-A552-70C788084A86} = {271715F3-5B90-4110-A552-70C788084A86}
    910                {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC}
    10                 {271715F3-5B90-4110-A552-70C788084A86} = {271715F3-5B90-4110-A552-70C788084A86}
    1111        EndProjectSection
    1212EndProject
     
    1818        ProjectSection(ProjectDependencies) = postProject
    1919                {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626} = {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}
     20                {9CC704CB-4956-4479-BDEC-57CBC03F700E} = {9CC704CB-4956-4479-BDEC-57CBC03F700E}
     21                {F101C2F0-1CB9-4A57-827B-6C399A99B28F} = {F101C2F0-1CB9-4A57-827B-6C399A99B28F}
    2022                {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC}
    21                 {F101C2F0-1CB9-4A57-827B-6C399A99B28F} = {F101C2F0-1CB9-4A57-827B-6C399A99B28F}
    2223        EndProjectSection
    2324EndProject
     
    2829        EndProjectSection
    2930        ProjectSection(ProjectDependencies) = postProject
     31                {271715F3-5B90-4110-A552-70C788084A86} = {271715F3-5B90-4110-A552-70C788084A86}
    3032                {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC}
    31                 {271715F3-5B90-4110-A552-70C788084A86} = {271715F3-5B90-4110-A552-70C788084A86}
    3233        EndProjectSection
    3334EndProject
     
    3839        EndProjectSection
    3940        ProjectSection(ProjectDependencies) = postProject
     41                {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626} = {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}
    4042                {35575B59-E1AE-40E8-89C4-2862B5B09B68} = {35575B59-E1AE-40E8-89C4-2862B5B09B68}
     43                {9CC704CB-4956-4479-BDEC-57CBC03F700E} = {9CC704CB-4956-4479-BDEC-57CBC03F700E}
     44                {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC}
    4145                {F101C2F0-1CB9-4A57-827B-6C399A99B28F} = {F101C2F0-1CB9-4A57-827B-6C399A99B28F}
     46                {271715F3-5B90-4110-A552-70C788084A86} = {271715F3-5B90-4110-A552-70C788084A86}
    4247                {4733BD1A-E04C-458D-8BFB-5010250EA497} = {4733BD1A-E04C-458D-8BFB-5010250EA497}
    43                 {271715F3-5B90-4110-A552-70C788084A86} = {271715F3-5B90-4110-A552-70C788084A86}
    44                 {2240ECD7-2F48-4431-8E1B-25466A384CCC} = {2240ECD7-2F48-4431-8E1B-25466A384CCC}
    4548        EndProjectSection
    4649EndProject
     
    5760        EndProjectSection
    5861EndProject
    59 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tolua++", "vc8\tolua++.vcproj", "{35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}"
     62Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tolua", "vc8\tolua.vcproj", "{35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}"
     63        ProjectSection(WebsiteProperties) = preProject
     64                Debug.AspNetCompiler.Debug = "True"
     65                Release.AspNetCompiler.Debug = "False"
     66        EndProjectSection
     67EndProject
     68Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ois", "vc8\ois.vcproj", "{9CC704CB-4956-4479-BDEC-57CBC03F700E}"
    6069        ProjectSection(WebsiteProperties) = preProject
    6170                Debug.AspNetCompiler.Debug = "True"
     
    117126                {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}.static_libs_release|Win32.ActiveCfg = Release|Win32
    118127                {35E36A06-0A5C-4A0D-9AB6-5A05EAA87626}.static_libs_release|Win32.Build.0 = Release|Win32
     128                {9CC704CB-4956-4479-BDEC-57CBC03F700E}.Debug|Win32.ActiveCfg = Debug|Win32
     129                {9CC704CB-4956-4479-BDEC-57CBC03F700E}.Debug|Win32.Build.0 = Debug|Win32
     130                {9CC704CB-4956-4479-BDEC-57CBC03F700E}.Release|Win32.ActiveCfg = Release|Win32
     131                {9CC704CB-4956-4479-BDEC-57CBC03F700E}.Release|Win32.Build.0 = Release|Win32
     132                {9CC704CB-4956-4479-BDEC-57CBC03F700E}.static_libs_debug|Win32.ActiveCfg = Release|Win32
     133                {9CC704CB-4956-4479-BDEC-57CBC03F700E}.static_libs_debug|Win32.Build.0 = Release|Win32
     134                {9CC704CB-4956-4479-BDEC-57CBC03F700E}.static_libs_release|Win32.ActiveCfg = Release|Win32
     135                {9CC704CB-4956-4479-BDEC-57CBC03F700E}.static_libs_release|Win32.Build.0 = Release|Win32
    119136        EndGlobalSection
    120137        GlobalSection(SolutionProperties) = preSolution
  • code/trunk/visual_studio/vc8/core.vcproj

    r1153 r1219  
    197197                        </File>
    198198                        <File
    199                                 RelativePath="..\..\src\core\InputEventListener.cc"
    200                                 >
    201                         </File>
    202                         <File
    203199                                RelativePath="..\..\src\core\InputHandler.cc"
    204200                                >
     
    347343                        </File>
    348344                        <File
    349                                 RelativePath="..\..\src\core\InputEvent.h"
    350                                 >
    351                         </File>
    352                         <File
    353                                 RelativePath="..\..\src\core\InputEventListener.h"
    354                                 >
    355                         </File>
    356                         <File
    357345                                RelativePath="..\..\src\core\InputHandler.h"
    358346                                >
  • code/trunk/visual_studio/vc8/orxonox.vcproj

    r1214 r1219  
    406406                                                />
    407407                                        </FileConfiguration>
     408                                        <FileConfiguration
     409                                                Name="Release|Win32"
     410                                                >
     411                                                <Tool
     412                                                        Name="VCCLCompilerTool"
     413                                                        UsePrecompiledHeader="0"
     414                                                />
     415                                        </FileConfiguration>
    408416                                </File>
    409417                        </Filter>
Note: See TracChangeset for help on using the changeset viewer.