Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1349 for code/trunk/src/core


Ignore:
Timestamp:
May 21, 2008, 9:07:08 PM (16 years ago)
Author:
rgrieder
Message:
  • merged input branch back to trunk
Location:
code/trunk/src/core
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/CommandExecutor.cc

    r1214 r1349  
    3131#include "util/String.h"
    3232#include "util/Convert.h"
     33#include "util/SubString.h"
    3334#include "Identifier.h"
    3435#include "Language.h"
     
    173174    }
    174175
    175     KeybindMode CommandEvaluation::getKeybindMode()
     176    KeybindMode::Enum CommandEvaluation::getKeybindMode()
    176177    {
    177178        if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
     
    198199        }
    199200        // FIXME: Had to insert a return statement
    200         return (KeybindMode)0;
     201        return (KeybindMode::Enum)0;
    201202    }
    202203
  • code/trunk/src/core/CommandExecutor.h

    r1293 r1349  
    7070    std::string read(const std::string& filename);
    7171
    72     enum KeybindMode {}; // temporary
    73 
    7472    ///////////////////////
    7573    // CommandEvaluation //
     
    8280            CommandEvaluation();
    8381
    84             KeybindMode getKeybindMode();
     82            KeybindMode::Enum getKeybindMode();
    8583            bool isValid() const;
    8684
     
    8987            inline std::string getAdditionalParameter() const
    9088                { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; }
    91             inline std::string getCommandString() const { return this->processedCommand_; }
     89            inline ExecutorStatic* getEvaluatedExecutor() { return evaluatedExecutor_; }
     90            inline std::string getCommandString() { return this->processedCommand_; }
    9291
    9392            void setEvaluatedParameter(unsigned int index, MultiTypeMath param);
  • code/trunk/src/core/CorePrereqs.h

    r1293 r1349  
    7878#endif
    7979
     80  namespace KeybindMode
     81  {
     82    enum Enum
     83    {
     84      OnPress,
     85      OnHold,
     86      OnRelease,
     87      None
     88    };
     89  };
     90
    8091  typedef std::string LanguageEntryLabel;
    8192
  • code/trunk/src/core/Executor.cc

    r1062 r1349  
    3939        this->name_ = name;
    4040        this->accessLevel_ = level;
     41        this->keybindMode_ = KeybindMode::OnPress;
     42        this->axisParamIndex_ = -1;
     43        this->bAxisRelative_ = false;
    4144
    4245        this->bAddedDescription_ = false;
  • code/trunk/src/core/Executor.h

    r1062 r1349  
    204204                { return this->accessLevel_; }
    205205
     206            inline Executor& setKeybindMode(KeybindMode::Enum mode)
     207                { this->keybindMode_ = mode; return *this; }
     208            inline KeybindMode::Enum getKeybindMode() const
     209                { return this->keybindMode_; }
     210
     211            inline Executor& setAxisParamIndex(int index)
     212                { this->axisParamIndex_ = index; return *this; }
     213            inline int getAxisParamIndex() const
     214                { return this->axisParamIndex_; }
     215
     216            inline Executor& setIsAxisRelative(bool val)
     217                { this->bAxisRelative_ = val; return *this; }
     218            inline int getIsAxisRelative() const
     219                { return this->bAxisRelative_; }
     220
    206221            Executor& setDefaultValues(const MultiTypeMath& param1);
    207222            Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2);
     
    233248            MultiTypeMath defaultValue_[MAX_FUNCTOR_ARGUMENTS];
    234249            bool bAddedDefaultValue_[MAX_FUNCTOR_ARGUMENTS];
     250
     251            KeybindMode::Enum keybindMode_;
     252            int axisParamIndex_;
     253            bool bAxisRelative_;
    235254
    236255        private:
  • code/trunk/src/core/InputBuffer.cc

    r1293 r1349  
    173173  }
    174174
     175  /**
     176  * This tick() function is called by the InputManager if the InputBuffer is active.
     177  * @param dt Delta time
     178  */
    175179  void InputBuffer::tick(float dt)
    176180  {
     
    187191  }
    188192
    189   bool InputBuffer::keyPressed(const KeyEvent &evt)
     193  void InputBuffer::keyPressed(const KeyEvent &evt)
    190194  {
    191195    lastKey_ = evt.key;
     
    195199
    196200    processKey(evt);
    197     return true;
    198   }
    199 
    200   bool InputBuffer::keyHeld(const KeyEvent& evt)
     201  }
     202
     203  void InputBuffer::keyHeld(const KeyEvent& evt)
    201204  {
    202205    if (evt.key == lastKey_)
     
    208211      }
    209212    }
    210     return true;
    211213  }
    212214
  • code/trunk/src/core/InputBuffer.h

    r1293 r1349  
    4343  {};
    4444
    45   class _CoreExport InputBuffer : public KeyHandler, public TickableReal
     45  class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass
    4646  {
    4747    struct InputBufferListenerTuple
     
    101101    bool charIsAllowed(const char& input);
    102102
    103     bool keyPressed (const KeyEvent& evt);
    104     bool keyReleased(const KeyEvent& evt) { return true; }
    105     bool keyHeld    (const KeyEvent& evt);
     103    void keyPressed (const KeyEvent& evt);
     104    void keyReleased(const KeyEvent& evt) { }
     105    void keyHeld    (const KeyEvent& evt);
    106106    void processKey (const KeyEvent &e);
    107107
  • code/trunk/src/core/InputHandler.cc

    r1293 r1349  
    3434#include "InputHandler.h"
    3535#include "util/Convert.h"
     36#include "util/SubString.h"
     37#include "util/String.h"
    3638#include "Debug.h"
    3739#include "ConfigValueIncludes.h"
    3840#include "CoreIncludes.h"
    3941#include "CommandExecutor.h"
     42#include "Executor.h"
    4043
    4144namespace orxonox
    4245{
    4346  // ###############################
     47  // ######      Button       ######
     48  // ###############################
     49
     50  bool BufferedParamCommand::execute()
     51  {
     52    if (nValuesAdded_)
     53    {
     54      BufferedParamCommand& cmd = *this;
     55      cmd.evaluation_.setEvaluatedParameter(cmd.paramIndex_, cmd.value_);
     56      // reset
     57      cmd.nValuesAdded_ = 0;
     58      cmd.value_ = 0;
     59      return CommandExecutor::execute(cmd.evaluation_);
     60    }
     61    else
     62      return true;
     63  }
     64
     65  bool SimpleCommand::execute(float abs, float rel)
     66  {
     67    return CommandExecutor::execute(evaluation_);
     68  }
     69
     70  bool ParamCommand::execute(float abs, float rel)
     71  {
     72    BufferedParamCommand& paramCommand = *paramCommand_;
     73    // command has an additional parameter
     74    if (bRelative_ && (rel > 0 || rel < 0))
     75    {
     76      // we have to calculate a relative movement.
     77      // paramModifier_ says how much one keystroke is
     78      paramCommand.value_ += paramModifier_ * rel;
     79    }
     80    else if (abs > 0 || abs < 0)
     81    {
     82      // we have to calculate absolute position of the axis.
     83      // Since there might be another axis that is affected, we have to wait and
     84      // store the result in a temporary place
     85      paramCommand.value_ = (paramCommand.value_ * paramCommand.nValuesAdded_ + paramModifier_ * abs)
     86                            /++paramCommand.nValuesAdded_;
     87    }
     88    return true;
     89  }
     90
     91  void Button::clear()
     92  {
     93    for (unsigned int j = 0; j < 3; j++)
     94    {
     95      if (nCommands_[j])
     96      {
     97        // delete all commands and the command pointer array
     98        for (unsigned int i = 0; i < nCommands_[j]; i++)
     99          delete commands_[j][i];
     100        delete[] commands_[j];
     101        commands_[j] = 0;
     102        nCommands_[j] = 0;
     103      }
     104      else
     105      {
     106        commands_[j] = 0;
     107      }
     108    }
     109  }
     110
     111  void Button::parse(std::vector<BufferedParamCommand*>& paramCommandBuffer)
     112  {
     113    if (isEmpty(bindingString_))
     114    {
     115      clear();
     116      return;
     117    }
     118
     119    // use std::vector for a temporary dynamic array
     120    std::vector<BaseCommand*> commands[3];
     121
     122
     123    // separate the commands
     124    SubString commandStrings(bindingString_, "|", SubString::WhiteSpaces, false,
     125        '\\', false, '"', false, '(', ')', false, '\0');
     126
     127    for (unsigned int iCommand = 0; iCommand < commandStrings.size(); iCommand++)
     128    {
     129      if (commandStrings[iCommand] != "")
     130      {
     131        SubString tokens(commandStrings[iCommand], " ", SubString::WhiteSpaces, false,
     132            '\\', false, '"', false, '(', ')', false, '\0');
     133       
     134        unsigned int iToken = 0;
     135
     136        // for real axes, we can feed a ButtonThreshold argument as entire command
     137        if (getLowercase(tokens[0]) == "buttonthreshold")
     138        {
     139          if (tokens.size() == 1)
     140            continue;
     141          // may fail, but doesn't matter
     142          convertValue(&buttonThreshold_, tokens[1]);
     143          continue;
     144        }
     145
     146        // first argument can be OnPress, OnHold OnRelease or nothing
     147        KeybindMode::Enum mode = KeybindMode::None;
     148        if (getLowercase(tokens[iToken]) == "onpress")
     149          mode = KeybindMode::OnPress,   iToken++;
     150        if (getLowercase(tokens[iToken]) == "onrelease")
     151          mode = KeybindMode::OnRelease, iToken++;
     152        if (getLowercase(tokens[iToken]) == "onhold")
     153          mode = KeybindMode::OnHold,    iToken++;
     154
     155        if (iToken == tokens.size())
     156          continue;
     157
     158        // second argument can be the amplitude for the case it as an axis command
     159        // default amplitude is 1.0f
     160        float paramModifier = 1.0f;
     161        if (getLowercase(tokens[iToken]) == "axisamp")
     162        {
     163          iToken++;
     164          if (iToken == tokens.size() || !convertValue(&paramModifier, tokens[iToken]))
     165          {
     166            COUT(2) << "Error while parsing key binding " << name_
     167                << ". Numeric expression expected afer 'AxisAmp', switching to default value" << std::endl;
     168            if (iToken == tokens.size())
     169              continue;
     170          }
     171          iToken++;
     172        }
     173
     174        // no more arguments expected except for the actual command
     175        if (iToken == tokens.size())
     176          continue;
     177
     178        std::string commandStr;
     179        while (iToken != tokens.size())
     180          commandStr += tokens[iToken++] + " ";
     181
     182        // evaluate the command
     183        CommandEvaluation eval = CommandExecutor::evaluate(commandStr);
     184        if (!eval.isValid())
     185          continue;
     186
     187        // check for param command
     188        int paramIndex = eval.getEvaluatedExecutor()->getAxisParamIndex();
     189        // TODO: check in Executor for correct paramIndex
     190        if (paramIndex >= 0)
     191        {
     192          // parameter supported command
     193          ParamCommand* cmd = new ParamCommand();
     194          cmd->paramModifier_ = paramModifier;
     195          cmd->bRelative_ = eval.getEvaluatedExecutor()->getIsAxisRelative();
     196
     197          // add command to the buffer if not yet existing
     198          for (unsigned int iParamCmd = 0; iParamCmd < paramCommandBuffer.size(); iParamCmd++)
     199          {
     200            if (getLowercase(paramCommandBuffer[iParamCmd]->evaluation_.getCommandString())
     201                == getLowercase(commandStr))
     202            {
     203              // already in list
     204              cmd->paramCommand_ = paramCommandBuffer[iParamCmd];
     205              break;
     206            }
     207          }
     208          if (cmd->paramCommand_ == 0)
     209          {
     210            cmd->paramCommand_ = new BufferedParamCommand();
     211            paramCommandBuffer.push_back(cmd->paramCommand_);
     212            cmd->paramCommand_->evaluation_ = eval;
     213            cmd->paramCommand_->paramIndex_ = paramIndex;
     214          }
     215
     216
     217          // we don't know whether this is an actual axis or just a button
     218          if (mode == KeybindMode::None)
     219          {
     220            if (!addParamCommand(cmd))
     221            {
     222              mode = eval.getEvaluatedExecutor()->getKeybindMode();
     223              commands[mode].push_back(cmd);
     224            }
     225          }
     226        }
     227        else
     228        {
     229          SimpleCommand* cmd = new SimpleCommand();
     230          cmd->evaluation_ = eval;
     231
     232          //TODO: check CommandEvaluation for correct KeybindMode
     233          if (mode == KeybindMode::None)
     234            mode = eval.getEvaluatedExecutor()->getKeybindMode();
     235
     236          commands[mode].push_back(cmd);
     237        }
     238      }
     239    }
     240
     241    for (unsigned int j = 0; j < 3; j++)
     242    {
     243      nCommands_[j] = commands[j].size();
     244      if (nCommands_[j])
     245      {
     246        commands_[j] = new BaseCommand*[nCommands_[j]];
     247        for (unsigned int i = 0; i < commands[j].size(); i++)
     248          commands_[j][i] = commands[j][i];
     249      }
     250      else
     251        commands_[j] = 0;
     252    }
     253  }
     254
     255  bool Button::execute(KeybindMode::Enum mode, float abs, float rel)
     256  {
     257    // execute all the parsed commands in the string
     258    for (unsigned int iCommand = 0; iCommand < nCommands_[mode]; iCommand++)
     259      commands_[mode][iCommand]->execute(abs, rel);
     260    return true;
     261  }
     262
     263  void HalfAxis::clear()
     264  {
     265    Button::clear();
     266    if (nParamCommands_)
     267    {
     268      // delete all commands and the command pointer array
     269      for (unsigned int i = 0; i < nParamCommands_; i++)
     270        delete paramCommands_[i];
     271      delete[] paramCommands_;
     272    }
     273    else
     274    {
     275      nParamCommands_ = 0; nParamCommands_ = 0;
     276    }
     277  }
     278 
     279  bool HalfAxis::addParamCommand(ParamCommand* command)
     280  {
     281    ParamCommand** cmds = paramCommands_;
     282    paramCommands_ = new ParamCommand*[++nParamCommands_];
     283    unsigned int i;
     284    for (i = 0; i < nParamCommands_ - 1; i++)
     285      paramCommands_[i] = cmds[i];
     286    paramCommands_[i] = command;
     287    delete[] cmds;
     288    return true;
     289  }
     290
     291  bool HalfAxis::execute()
     292  {
     293    bool success = true;
     294    for (unsigned int i = 0; i < nParamCommands_; i++)
     295      success = success && paramCommands_[i]->execute(absVal_, relVal_);
     296    return success;
     297  }
     298
     299
     300  // ###############################
    44301  // ######     KeyBinder     ######
    45302  // ###############################
     
    48305    @brief Constructor that does as little as necessary.
    49306  */
    50   KeyBinder::KeyBinder()
     307  KeyBinder::KeyBinder() : deriveTime_(0.0f)
    51308  {
    52309    RegisterObject(KeyBinder);
    53     clearBindings();
    54 
     310
     311    // keys
    55312    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"
     313      "UNASSIGNED",
     314      "ESCAPE",
     315      "1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
     316      "MINUS", "EQUALS", "BACK", "TAB",
     317      "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P",
     318      "LBRACKET", "RBRACKET",
     319      "RETURN", "LCONTROL",
     320      "A", "S", "D", "F", "G", "H", "J", "K", "L",
     321      "SEMICOLON", "APOSTROPHE", "GRAVE",
     322      "LSHIFT", "BACKSLASH",
     323      "Z", "X", "C", "V", "B", "N", "M",
     324      "COMMA", "PERIOD", "SLASH",
     325      "RSHIFT",
     326      "MULTIPLY",
     327      "LMENU",
     328      "SPACE",
     329      "CAPITAL",
     330      "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10",
     331      "NUMLOCK", "SCROLL",
     332      "NUMPAD7", "NUMPAD8", "NUMPAD9",
     333      "SUBTRACT",
     334      "NUMPAD4", "NUMPAD5", "NUMPAD6",
     335      "ADD",
     336      "NUMPAD1", "NUMPAD2", "NUMPAD3", "NUMPAD0",
     337      "DECIMAL",
     338      "","",
     339      "OEM_102",
     340      "F11", "F12",
     341      "","","","","","","","","","","",
     342      "F13", "F14", "F15",
     343      "","","","","","","","","","",
     344      "KANA",
     345      "","",
     346      "ABNT_C1",
     347      "","","","","",
     348      "CONVERT",
     349      "",
     350      "NOCONVERT",
     351      "",
     352      "YEN",
     353      "ABNT_C2",
     354      "","","","","","","","","","","","","","",
     355      "NUMPADEQUALS",
     356      "","",
     357      "PREVTRACK",
     358      "AT",
     359      "COLON", "UNDERLINE",
     360      "KANJI",
     361      "STOP",
     362      "AX",
     363      "UNLABELED",
     364      "NEXTTRACK",
     365      "","",
     366      "NUMPADENTER",
     367      "RCONTROL",
     368      "","",
     369      "MUTE",
     370      "CALCULATOR",
     371      "PLAYPAUSE",
     372      "",
     373      "MEDIASTOP",
     374      "","","","","","","","","",
     375      "VOLUMEDOWN",
     376      "",
     377      "VOLUMEUP",
     378      "",
     379      "WEBHOME",
     380      "NUMPADCOMMA",
     381      "",
     382      "DIVIDE",
     383      "",
     384      "SYSRQ",
     385      "RMENU",
     386      "","","","","","","","","","","","",
     387      "PAUSE",
     388      "",
     389      "HOME",
     390      "UP",
     391      "PGUP",
     392      "",
     393      "LEFT",
     394      "",
     395      "RIGHT",
     396      "",
     397      "END", "DOWN", "PGDOWN", "INSERT", "DELETE",
     398      "","","","","","","",
     399      "LWIN", "RWIN", "APPS",
     400      "POWER", "SLEEP",
     401      "","","",
     402      "WAKE",
     403      "",
     404      "WEBSEARCH", "WEBFAVORITES", "WEBREFRESH", "WEBSTOP", "WEBFORWARD", "WEBBACK",
     405      "MYCOMPUTER", "MAIL", "MEDIASELECT"
    226406    };
    227     for (int i = 0; i < numberOfKeys_s; i++)
    228       keyNames_[i] = keyNames[i];
    229 
     407    for (unsigned int i = 0; i < nKeys_s; i++)
     408      keys_[i].name_ = "Key" + keyNames[i];
     409
     410    // mouse buttons
    230411    std::string mouseButtonNames[] = {
    231412      "MouseLeft", "MouseRight", "MouseMiddle",
    232413      "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);
     414      "MouseButton6", "MouseButton7",
     415      "MouseWheel1Up", "MouseWheel1Down",
     416      "MouseWheel2Up", "MouseWheel2Down" };
     417    for (unsigned int i = 0; i < nMouseButtons_s; i++)
     418      mouseButtons_[i].name_ = mouseButtonNames[i];
     419
     420    // joy stick buttons
     421    for (unsigned int i = 0; i < 32; i++)
     422      joyStickButtons_[i].name_ = "JoyButton" + getConvertedValue<int, std::string>(i);
     423    for (unsigned int i = 32; i < nJoyStickButtons_s; i += 4)
     424    {
     425                  joyStickButtons_[i + 0].name_ = "JoyPOV" + getConvertedValue<int, std::string>((i - 32)/4 + 1) + "North";
     426                  joyStickButtons_[i + 1].name_ = "JoyPOV" + getConvertedValue<int, std::string>((i - 32)/4 + 1) + "South";
     427                  joyStickButtons_[i + 2].name_ = "JoyPOV" + getConvertedValue<int, std::string>((i - 32)/4 + 1) + "East";
     428                  joyStickButtons_[i + 3].name_ = "JoyPOV" + getConvertedValue<int, std::string>((i - 32)/4 + 1) + "West";
     429    }
     430
     431    // half axes
     432    std::string rawNames[nHalfAxes_s/2];
     433    rawNames[0] = "MouseX";
     434    rawNames[1] = "MouseY";
     435    rawNames[2] = "Empty1";
     436    rawNames[3] = "Empty2";
     437    for (unsigned int i = 4; i < nHalfAxes_s/2; i++)
     438      rawNames[i] = "JoyAxis" + getConvertedValue<int, std::string>(i - 3);
     439    for (unsigned int i = 0; i < nHalfAxes_s/2; i++)
     440    {
     441      halfAxes_[i * 2 + 0].name_ = rawNames[i] + "Pos";
     442      halfAxes_[i * 2 + 1].name_ = rawNames[i] + "Neg";
     443    }
     444
     445    for (unsigned int i = 0; i < this->nHalfAxes_s; i++)
     446      halfAxes_[i].buttonThreshold_ = buttonThreshold_;
    239447  }
    240448
     
    244452  KeyBinder::~KeyBinder()
    245453  {
     454    // almost no destructors required because most of the arrays are static.
     455    clearBindings(); // does some destruction work
     456  }
     457
     458  /**
     459    @brief Loads the key and button bindings.
     460    @return True if loading succeeded.
     461  */
     462  void KeyBinder::loadBindings()
     463  {
     464    COUT(3) << "KeyBinder: Loading key bindings..." << std::endl;
     465
     466    ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, "keybindings.ini");
     467    clearBindings();
     468    setConfigValues();
     469
     470    COUT(3) << "KeyBinder: Loading key bindings done." << std::endl;
    246471  }
    247472
     
    251476  void KeyBinder::setConfigValues()
    252477  {
    253     ConfigValueContainer* cont;
    254     std::string modes[] = {"P_", "R_", "H_"};
     478    SetConfigValue(analogThreshold_, 0.01f)  .description("Threshold for analog axes until which the state is 0.");
     479    SetConfigValue(bDeriveMouseInput_, false).description("Whether or not to derive moues movement for the absolute value.");
     480    SetConfigValue(derivePeriod_, 0.1f)      .description("Accuracy of the mouse input deriver. The higher the more precise, but laggier.");
     481    SetConfigValue(mouseSensitivity_, 1.0f)  .description("Mouse sensitivity.");
     482
     483    float oldThresh = buttonThreshold_;
     484    SetConfigValue(buttonThreshold_, 0.80f).description("Threshold for analog axes until which the button is not pressed.");
     485    if (oldThresh != buttonThreshold_)
     486      for (unsigned int i = 0; i < nHalfAxes_s; i++)
     487        if (halfAxes_[i].buttonThreshold_ == oldThresh)
     488          halfAxes_[i].buttonThreshold_ = buttonThreshold_;
    255489
    256490    // keys
    257     for (int i = 0; i < numberOfKeys_s; i++)
    258     {
    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           case 0:
    270             cont->getValue(&bindingsKeyPress_[i].commandStr);
    271             break;
    272           case 1:
    273             cont->getValue(&bindingsKeyRelease_[i].commandStr);
    274             break;
    275           case 2:
    276             cont->getValue(&bindingsKeyHold_[i].commandStr);
    277         }
    278       }
    279     }
    280 
     491    for (unsigned int i = 0; i < nKeys_s; i++)
     492      readTrigger(keys_[i]);
    281493    // mouse buttons
    282     for (int i = 0; i < numberOfMouseButtons_s; i++)
    283     {
    284       for (int j = 0; j < 3; j++)
    285       {
    286         cont = getIdentifier()->getConfigValueContainer(modes[j] + mouseButtonNames_[i]);
    287         if (!cont)
    288         {
    289           cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), modes[j] + mouseButtonNames_[i], "");
    290           getIdentifier()->addConfigValueContainer(modes[j] + mouseButtonNames_[i], cont);
    291         }
    292         switch (j)
    293         {
    294           case 0:
    295             cont->getValue(&bindingsMouseButtonPress_[i].commandStr);
    296             break;
    297           case 1:
    298             cont->getValue(&bindingsMouseButtonRelease_[i].commandStr);
    299             break;
    300           case 2:
    301             cont->getValue(&bindingsMouseButtonHold_[i].commandStr);
    302         }
    303       }
    304     }
    305 
     494    for (unsigned int i = 0; i < nMouseButtons_s; i++)
     495      readTrigger(mouseButtons_[i]);
    306496    // joy stick buttons
    307     for (int i = 0; i < numberOfJoyStickButtons_s; i++)
    308     {
    309       for (int j = 0; j < 3; j++)
    310       {
    311         cont = getIdentifier()->getConfigValueContainer(modes[j] + joyStickButtonNames_[i]);
    312         if (!cont)
    313         {
    314           cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), modes[j] + joyStickButtonNames_[i], "");
    315           getIdentifier()->addConfigValueContainer(modes[j] + joyStickButtonNames_[i], cont);
    316         }
    317         switch (j)
    318         {
    319           case 0:
    320             cont->getValue(&bindingsJoyStickButtonPress_[i].commandStr);
    321             break;
    322           case 1:
    323             cont->getValue(&bindingsJoyStickButtonRelease_[i].commandStr);
    324             break;
    325           case 2:
    326             cont->getValue(&bindingsJoyStickButtonHold_[i].commandStr);
    327         }
    328       }
     497    for (unsigned int i = 0; i < nJoyStickButtons_s; i++)
     498      readTrigger(joyStickButtons_[i]);
     499    // half axes
     500    for (unsigned int i = 0; i < nHalfAxes_s; i++)
     501      readTrigger(halfAxes_[i]);
     502  }
     503
     504  void KeyBinder::readTrigger(Button& button)
     505  {
     506    // config value stuff
     507    ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer(button.name_);
     508    if (!cont)
     509    {
     510      cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), button.name_, "");
     511      getIdentifier()->addConfigValueContainer(button.name_, cont);
     512    }
     513    std::string old = button.bindingString_;
     514    cont->getValue(&button.bindingString_);
     515
     516    // keybinder stuff
     517    if (old != button.bindingString_)
     518    {
     519      // binding has changed
     520      button.parse(paramCommandBuffer_);
    329521    }
    330522  }
     
    333525    @brief Overwrites all bindings with ""
    334526  */
    335   void KeyBinder::clearBindings()
    336   {
    337     for (int i = 0; i < numberOfKeys_s; i++)
    338     {
    339       bindingsKeyPress_  [i].commandStr = "";
    340       bindingsKeyRelease_[i].commandStr = "";
    341       bindingsKeyHold_   [i].commandStr = "";
    342     }
    343     for (int i = 0; i < numberOfMouseButtons_s; i++)
    344     {
    345       bindingsMouseButtonPress_  [i].commandStr = "";
    346       bindingsMouseButtonRelease_[i].commandStr = "";
    347       bindingsMouseButtonHold_   [i].commandStr = "";
    348     }
    349     for (int i = 0; i < numberOfJoyStickButtons_s; i++)
    350     {
    351       bindingsJoyStickButtonPress_  [i].commandStr = "";
    352       bindingsJoyStickButtonRelease_[i].commandStr = "";
    353       bindingsJoyStickButtonHold_   [i].commandStr = "";
    354     }
    355   }
    356 
    357   /**
    358     @brief Loads the key and button bindings.
    359     @return True if loading succeeded.
    360   */
    361   bool KeyBinder::loadBindings()
    362   {
    363     COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings..." << std::endl;
    364 
    365     ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, "keybindings.ini");
    366     setConfigValues();
    367 
    368     // evaluate the key bindings
    369     // TODO: what if binding is invalid?
    370     for (int i = 0; i < numberOfKeys_s; i++)
    371     {
    372       if (bindingsKeyPress_[i].commandStr != "")
     527  void KeyBinder::clearBindings(bool bInit)
     528  {
     529    for (unsigned int i = 0; i < nKeys_s; i++)
     530      keys_[i].clear();
     531
     532    for (unsigned int i = 0; i < nMouseButtons_s; i++)
     533      mouseButtons_[i].clear();
     534
     535    for (unsigned int i = 0; i < nJoyStickButtons_s; i++)
     536      joyStickButtons_[i].clear();
     537
     538    for (unsigned int i = 0; i < nHalfAxes_s; i++)
     539      halfAxes_[i].clear();
     540
     541    for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++)
     542      delete paramCommandBuffer_[i];
     543    paramCommandBuffer_.clear();
     544  }
     545
     546  void KeyBinder::tick(float dt)
     547  {
     548    // we have to process all the analog input since there is e.g. no 'mouseDoesntMove' event.
     549    for (unsigned int i = 0; i < nHalfAxes_s; i++)
     550    {
     551      if (halfAxes_[i].hasChanged_)
    373552      {
    374         bindingsKeyPress_[i].evaluation = CommandExecutor::evaluate(bindingsKeyPress_[i].commandStr);
    375         bindingsKeyPress_[i].commandStr = bindingsKeyPress_[i].evaluation.getCommandString();
     553        if (!halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ > halfAxes_[i].buttonThreshold_)
     554        {
     555          halfAxes_[i].wasDown_ = true;
     556          if (halfAxes_[i].nCommands_[KeybindMode::OnPress])
     557            halfAxes_[i].execute(KeybindMode::OnPress);
     558        }
     559        else if (halfAxes_[i].wasDown_ && halfAxes_[i].absVal_ < halfAxes_[i].buttonThreshold_)
     560        {
     561          halfAxes_[i].wasDown_ = false;
     562          if (halfAxes_[i].nCommands_[KeybindMode::OnRelease])
     563            halfAxes_[i].execute(KeybindMode::OnRelease);
     564        }
     565        if (halfAxes_[i].wasDown_)
     566        {
     567          if (halfAxes_[i].nCommands_[KeybindMode::OnHold])
     568            halfAxes_[i].execute(KeybindMode::OnHold);
     569        }
     570        halfAxes_[i].hasChanged_ = false;
    376571      }
    377     }
    378 
    379     COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings done." << std::endl;
    380     return true;
    381   }
    382 
    383   bool KeyBinder::executeSimpleBinding(KeyBinding& binding)
    384   {
    385     if (binding.commandStr != "")
    386     {
    387       if (binding.commandStr != binding.evaluation.getCommandString())
     572
     573      // these are the actually useful axis bindings for analog input AND output
     574      if (halfAxes_[i].relVal_ > analogThreshold_ || halfAxes_[i].absVal_ > analogThreshold_)
    388575      {
    389         // key binding has changed, reevaluate the command string.
    390         binding.evaluation = CommandExecutor::evaluate(binding.commandStr);
    391         binding.commandStr = binding.evaluation.getCommandString();
     576        halfAxes_[i].execute();
    392577      }
    393       COUT(ORX_DEBUG) << "Keybinding: Executing command: " << binding.commandStr << std::endl;
    394       CommandExecutor::execute(binding.commandStr);
    395     }
    396 
    397     return true;
    398   }
    399 
    400 
    401   /**
    402     @brief Event handler for the keyPressed Event.
    403     @param e Event information
    404   */
    405   bool KeyBinder::keyPressed(const KeyEvent& evt)
    406   {
    407     // find the appropriate key binding
    408     executeSimpleBinding(bindingsKeyPress_[int(evt.key)]);
    409 
    410     return true;
    411   }
    412 
    413   /**
    414     @brief Event handler for the keyReleased Event.
    415     @param e Event information
    416   */
    417   bool KeyBinder::keyReleased(const KeyEvent& evt)
    418   {
    419     // find the appropriate key binding
    420     executeSimpleBinding(bindingsKeyRelease_[int(evt.key)]);
    421 
    422     return true;
    423   }
    424 
    425   /**
    426     @brief Event handler for the keyHeld Event.
    427     @param e Mouse state information
    428   */
    429   bool KeyBinder::keyHeld(const KeyEvent& evt)
    430   {
    431     // find the appropriate key binding
    432     executeSimpleBinding(bindingsKeyHold_[int(evt.key)]);
    433 
    434     return true;
    435   }
     578    }
     579
     580    if (bDeriveMouseInput_)
     581    {
     582      if (deriveTime_ > derivePeriod_)
     583      {
     584        deriveTime_ = 0.0f;
     585        //CCOUT(3) << "mouse abs: ";
     586        for (int i = 0; i < 2; i++)
     587        {
     588          if (mouseRelative_[i] > 0)
     589          {
     590            halfAxes_[2*i + 0].absVal_ = mouseRelative_[i] * derivePeriod_ / 500 * mouseSensitivity_;
     591            halfAxes_[2*i + 1].absVal_ = 0.0f;
     592          }
     593          else if (mouseRelative_[0] < 0)
     594          {
     595            halfAxes_[2*i + 0].absVal_ = 0.0f;
     596            halfAxes_[2*i + 1].absVal_ = -mouseRelative_[i] * derivePeriod_ / 500 * mouseSensitivity_;
     597          }
     598          //COUT(3) << mouseRelative_[i] << " | ";
     599          mouseRelative_[i] = 0;
     600        }
     601        //COUT(3) << std::endl;
     602      }
     603      else
     604        deriveTime_ += dt;
     605    }
     606
     607    // execute all buffered bindings (addional parameter)
     608    for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++)
     609      paramCommandBuffer_[i]->execute();
     610
     611    // always reset the relative movement of the mouse
     612    for (unsigned int i = 0; i < 8; i++)
     613      halfAxes_[i].relVal_ = 0.0f;
     614  }
     615
     616  void KeyBinder::keyPressed (const KeyEvent& evt)
     617  { keys_[evt.key].execute(KeybindMode::OnPress); }
     618
     619  void KeyBinder::keyReleased(const KeyEvent& evt)
     620  { keys_[evt.key].execute(KeybindMode::OnRelease); }
     621
     622  void KeyBinder::keyHeld    (const KeyEvent& evt)
     623  { keys_[evt.key].execute(KeybindMode::OnHold); }
     624
     625
     626  void KeyBinder::mouseButtonPressed (MouseButton::Enum id)
     627  { mouseButtons_[id].execute(KeybindMode::OnPress); }
     628
     629  void KeyBinder::mouseButtonReleased(MouseButton::Enum id)
     630  { mouseButtons_[id].execute(KeybindMode::OnRelease); }
     631
     632  void KeyBinder::mouseButtonHeld    (MouseButton::Enum id)
     633  { mouseButtons_[id].execute(KeybindMode::OnHold); }
     634
     635
     636  void KeyBinder::joyStickButtonPressed (int joyStickID, int button)
     637  { joyStickButtons_[button].execute(KeybindMode::OnPress); }
     638
     639  void KeyBinder::joyStickButtonReleased(int joyStickID, int button)
     640  { joyStickButtons_[button].execute(KeybindMode::OnRelease); }
     641
     642  void KeyBinder::joyStickButtonHeld    (int joyStickID, int button)
     643  { joyStickButtons_[button].execute(KeybindMode::OnHold); }
    436644
    437645  /**
     
    439647    @param e Mouse state information
    440648  */
    441   bool KeyBinder::mouseMoved(const MouseState &evt)
    442   {
    443     /*if (bindingMouseMoved_.commandStr != "")
    444     {
    445       if (bindingMouseMoved_.commandStr != bindingMouseMoved_.evaluation.getCommandString())
     649  void KeyBinder::mouseMoved(IntVector2 abs_, IntVector2 rel_, IntVector2 clippingSize)
     650  {
     651    if (!bDeriveMouseInput_)
     652    {
     653      // y axis of mouse input is inverted
     654      int rel[] = { rel_.x, -rel_.y };
     655
     656      //COUT(3) << rel[0] << " | " << rel[1] << std::endl;
     657
     658      for (int i = 0; i < 2; i++)
    446659      {
    447         // key binding has changed, reevaluate the command string.
    448         bindingMouseMoved_.evaluation = CommandExecutor::evaluate(bindingMouseMoved_.commandStr);
    449         bindingMouseMoved_.commandStr = bindingMouseMoved_.evaluation.getCommandString();
     660        if (rel[i])
     661        {
     662          // absolute
     663          if (mousePosition_[i] >= 0)
     664          {
     665            mousePosition_[i] += rel[i];
     666            halfAxes_[0 + 2*i].hasChanged_ = true;
     667            if (mousePosition_[i] < 0)
     668            {
     669              halfAxes_[1 + 2*i].hasChanged_ = true;
     670              halfAxes_[1 + 2*i].absVal_ = -((float)mousePosition_[i])/1024 * mouseSensitivity_;
     671              halfAxes_[0 + 2*i].absVal_ =  0.0f;
     672            }
     673            else
     674              halfAxes_[1 + 2*i].absVal_ =  ((float)mousePosition_[i])/1024 * mouseSensitivity_;
     675          }
     676          else
     677          {
     678            mousePosition_[i] += rel[i];
     679            halfAxes_[1 + 2*i].hasChanged_ = true;
     680            if (mousePosition_[i] > 0)
     681            {
     682              halfAxes_[0 + 2*i].hasChanged_ = true;
     683              halfAxes_[0 + 2*i].absVal_ =  ((float)mousePosition_[i])/1024 * mouseSensitivity_;
     684              halfAxes_[1 + 2*i].absVal_ =  0.0f;
     685            }
     686            else
     687              halfAxes_[1 + 2*i].absVal_ = -((float)mousePosition_[i])/1024 * mouseSensitivity_;
     688          }
     689
     690          // relative
     691          if (rel[i] > 0)
     692            halfAxes_[0 + 2*i].relVal_ =  ((float)rel[i])/1024 * mouseSensitivity_;
     693          else
     694            halfAxes_[1 + 2*i].relVal_ = -((float)rel[i])/1024 * mouseSensitivity_;
     695        }
    450696      }
    451       COUT(3) << "Executing command: " << bindingMouseMoved_.commandStr << std::endl;
    452 
    453       bindingMouseMoved_.evaluation.setEvaluatedParameter(
    454       CommandExecutor::execute(bindingMouseMoved_.commandStr);
    455     }*/
    456 
    457     return true;
     697    }
     698    else
     699    {
     700      mouseRelative_[0] += rel_.x;
     701      mouseRelative_[1] -= rel_.y;
     702    }
    458703  }
    459704
     
    462707    @param e Mouse state information
    463708  */
    464   bool KeyBinder::mouseScrolled(const MouseState &evt)
    465   {
    466     return true;
    467   }
    468 
    469   /**
    470     @brief Event handler for the mousePressed Event.
    471     @param e Event information
    472     @param id The ID of the mouse button
    473   */
    474   bool KeyBinder::mouseButtonPressed(const MouseState& state, MouseButton::Enum id)
    475   {
    476     // find the appropriate key binding
    477     executeSimpleBinding(bindingsMouseButtonPress_[int(id)]);
    478 
    479     return true;
    480   }
    481 
    482   /**
    483     @brief Event handler for the mouseReleased Event.
    484     @param e Event information
    485     @param id The ID of the mouse button
    486   */
    487   bool KeyBinder::mouseButtonReleased(const MouseState& state, MouseButton::Enum id)
    488   {
    489     // find the appropriate key binding
    490     executeSimpleBinding(bindingsMouseButtonRelease_[int(id)]);
    491 
    492     return true;
    493   }
    494 
    495   /**
    496     @brief Event handler for the mouseHeld Event.
    497     @param e Event information
    498     @param id The ID of the mouse button
    499   */
    500   bool KeyBinder::mouseButtonHeld(const MouseState& state, MouseButton::Enum id)
    501   {
    502     // find the appropriate key binding
    503     executeSimpleBinding(bindingsMouseButtonHold_[int(id)]);
    504 
    505     return true;
    506   }
    507 
    508   bool KeyBinder::joyStickButtonPressed(const JoyStickState& state, int button)
    509   {
    510     // find the appropriate key binding
    511     executeSimpleBinding(bindingsJoyStickButtonPress_[button]);
    512 
    513     return true;
    514   }
    515 
    516   bool KeyBinder::joyStickButtonReleased(const JoyStickState& state, int button)
    517   {
    518     // find the appropriate key binding
    519     executeSimpleBinding(bindingsJoyStickButtonRelease_[button]);
    520 
    521     return true;
    522   }
    523 
    524   bool KeyBinder::joyStickButtonHeld(const JoyStickState& state, int button)
    525   {
    526     // find the appropriate key binding
    527     executeSimpleBinding(bindingsJoyStickButtonHold_[button]);
    528 
    529     return true;
    530   }
    531 
    532   bool KeyBinder::joyStickAxisMoved(const JoyStickState& state, int axis)
    533   {
    534     return true;
    535   }
    536 
    537   bool KeyBinder::joyStickSliderMoved(const JoyStickState& state, int index)
    538   {
    539     return true;
    540   }
    541 
    542   bool KeyBinder::joyStickPovMoved(const JoyStickState& state, int index)
    543   {
    544     return true;
    545   }
    546 
    547   bool KeyBinder::joyStickVector3Moved(const JoyStickState& state, int index)
    548   {
    549     return true;
    550   }
    551 
     709  void KeyBinder::mouseScrolled(int abs, int rel)
     710  {
     711    //COUT(3) << mouseButtons_[8].name_ << "   " << abs << " | " << rel << std::endl;
     712
     713    if (rel > 0)
     714      for (int i = 0; i < rel/120; i++)
     715        mouseButtons_[8].execute(KeybindMode::OnPress, ((float)abs)/120.0f);
     716    else
     717      for (int i = 0; i < -rel/120; i++)
     718        mouseButtons_[9].execute(KeybindMode::OnPress, ((float)abs)/120.0f);
     719  }
     720
     721  void KeyBinder::joyStickAxisMoved(int joyStickID, int axis, int value)
     722  {
     723    // TODO: check whether 16 bit integer as general axis value is a good idea (works under windows)
     724    CCOUT(3) << halfAxes_[8 + axis].name_ << std::endl;
     725    if (value >= 0)
     726    {
     727      halfAxes_[8 + axis].absVal_ = ((float)value)/0x8000;
     728      halfAxes_[8 + axis].relVal_ = ((float)value)/0x8000;
     729      halfAxes_[8 + axis].hasChanged_ = true;
     730    }
     731    else
     732    {
     733      halfAxes_[8 + axis + 1].absVal_ = -((float)value)/0x8000;
     734      halfAxes_[8 + axis + 1].relVal_ = -((float)value)/0x8000;
     735      halfAxes_[8 + axis + 1].hasChanged_ = true;
     736    }
     737  }
    552738
    553739
  • code/trunk/src/core/InputHandler.h

    r1293 r1349  
    3838
    3939#include <string>
     40#include <vector>
    4041
    4142#include "ois/OIS.h"
     43#include "util/Math.h"
    4244#include "OrxonoxClass.h"
    4345#include "CommandExecutor.h"
     
    4648namespace orxonox
    4749{
    48   namespace KeybindSetting
    49   {
    50     enum KeybindSetting
    51     {
    52       None,
    53       OnPress,
    54       OnRelease,
    55       Continuous,
    56     };
    57   }
    58 
    59   struct _CoreExport KeyBinding
    60   {
    61     std::string commandStr;
    62     CommandEvaluation evaluation;
    63   };
    64  
     50  class _CoreExport BaseCommand
     51  {
     52  public:
     53    virtual ~BaseCommand() { }
     54    virtual bool execute(float abs = 1.0f, float rel = 1.0f) = 0;
     55  };
     56
     57  class _CoreExport BufferedParamCommand
     58  {
     59  public:
     60    BufferedParamCommand() : value_(0.0f), nValuesAdded_(0), paramIndex_(-1) { }
     61    bool execute();
     62
     63    float value_;
     64    unsigned int nValuesAdded_;
     65    int paramIndex_;
     66    CommandEvaluation evaluation_;
     67  };
     68
     69  class _CoreExport SimpleCommand : public BaseCommand
     70  {
     71  public:
     72    bool execute(float abs = 1.0f, float rel = 1.0f);
     73
     74    CommandEvaluation evaluation_;
     75  };
     76
     77  class _CoreExport ParamCommand : public BaseCommand
     78  {
     79  public:
     80    ParamCommand() : bRelative_(false), paramModifier_(1.0f), paramCommand_(0) { }
     81    bool execute(float abs = 1.0f, float rel = 1.0f);
     82
     83    bool bRelative_;
     84    float paramModifier_;
     85    BufferedParamCommand* paramCommand_;
     86  };
     87
     88  class _CoreExport Button
     89  {
     90  public:
     91    Button() { nCommands_[0]=0; nCommands_[1]=0; nCommands_[2]=0; clear(); }
     92    virtual ~Button() { clear(); }
     93    virtual void clear();
     94    virtual bool addParamCommand(ParamCommand* command) { return false; }
     95    void parse(std::vector<BufferedParamCommand*>& paramCommandBuffer);
     96    bool execute(KeybindMode::Enum mode, float abs = 1.0f, float rel = 1.0f);
     97
     98    //! The configured string value
     99    std::string bindingString_;
     100    //! Name of the trigger as strings
     101    std::string name_;
     102    //! Basic commands for OnPress, OnHold and OnRelease
     103    BaseCommand** commands_[3];
     104    //! Number of basic commands
     105    unsigned int nCommands_[3];
     106    //! Says how much it takes for an analog axis to trigger a button
     107    //! Note: This variable is here to have only one parse() function.
     108    float buttonThreshold_;
     109  };
     110
     111
     112  class _CoreExport HalfAxis : public Button
     113  {
     114  public:
     115    HalfAxis() : relVal_(0.0f), absVal_(0.0f), paramCommands_(0), nParamCommands_(0),
     116                 wasDown_(false), hasChanged_(false) { }
     117    using Button::execute;
     118    bool execute();
     119    //bool execute(KeybindMode::Enum mode) { return Button::execute(mode); }
     120    bool addParamCommand(ParamCommand* command);
     121    void clear();
     122
     123    // axis related
     124    float relVal_;
     125    float absVal_;
     126    ParamCommand** paramCommands_;
     127    unsigned int nParamCommands_;
     128
     129    // button related
     130    bool wasDown_;
     131    bool hasChanged_;
     132  };
     133
    65134
    66135  /**
    67     @brief Captures mouse, keyboard and joy stick input while in the actual game mode.
     136    @brief Handles mouse, keyboard and joy stick input while in the actual game mode.
    68137           Manages the key bindings.
    69138  */
     
    74143    ~KeyBinder();
    75144
    76     bool loadBindings();
    77     void clearBindings();
     145    void loadBindings();
     146    void clearBindings(bool bInit = false);
    78147
    79148    void setConfigValues();
    80149
    81150  private: // functions
    82 
    83     bool executeSimpleBinding(KeyBinding &binding);
    84 
    85     bool keyPressed (const KeyEvent& evt);
    86     bool keyReleased(const KeyEvent& evt);
    87     bool keyHeld    (const KeyEvent& evt);
    88 
    89     bool mouseButtonPressed (const MouseState& state, MouseButton::Enum id);
    90     bool mouseButtonReleased(const MouseState& state, MouseButton::Enum id);
    91     bool mouseButtonHeld    (const MouseState& state, MouseButton::Enum id);
    92     bool mouseMoved         (const MouseState& state);
    93     bool mouseScrolled      (const MouseState& state);
    94 
    95     bool joyStickButtonPressed (const JoyStickState& state, int button);
    96     bool joyStickButtonReleased(const JoyStickState& state, int button);
    97     bool joyStickButtonHeld    (const JoyStickState& state, int button);
    98     bool joyStickAxisMoved     (const JoyStickState& state, int axis)  ;
    99     bool joyStickSliderMoved   (const JoyStickState& state, int index) ;
    100     bool joyStickPovMoved      (const JoyStickState& state, int index) ;
    101     bool joyStickVector3Moved  (const JoyStickState& state, int index) ;
     151    void readTrigger(Button& button);
     152
     153    //static void clearBundle(KeyBindingBundle& bundle, bool bInit);
     154    //static void redimensionBinding(KeyBinding& binding);
     155
     156    void tick(float dt);
     157
     158    void keyPressed (const KeyEvent& evt);
     159    void keyReleased(const KeyEvent& evt);
     160    void keyHeld    (const KeyEvent& evt);
     161
     162    void mouseButtonPressed (MouseButton::Enum id);
     163    void mouseButtonReleased(MouseButton::Enum id);
     164    void mouseButtonHeld    (MouseButton::Enum id);
     165    void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
     166    void mouseScrolled      (int abs, int rel);
     167
     168    void joyStickButtonPressed (int joyStickID, int button);
     169    void joyStickButtonReleased(int joyStickID, int button);
     170    void joyStickButtonHeld    (int joyStickID, int button);
     171    void joyStickAxisMoved     (int joyStickID, int axis, int value);
    102172
    103173  private: // variables
    104 
    105174    //! denotes the number of different keys there are in OIS.
    106     static const int numberOfKeys_s = 0xEE;
    107     //! Array of input events for every pressed key
    108     KeyBinding bindingsKeyPress_  [numberOfKeys_s];
    109     //! Array of input events for every released key
    110     KeyBinding bindingsKeyRelease_[numberOfKeys_s];
    111     //! Array of input events for every held key
    112     KeyBinding bindingsKeyHold_   [numberOfKeys_s];
    113     //! Names of the keys as strings
    114     std::string keyNames_[numberOfKeys_s];
     175    static const unsigned int nKeys_s = 0xEE;
     176    //! Actual key bindings as bundle for Press, Hold and Release
     177    Button keys_ [nKeys_s];
    115178
    116179    //! denotes the number of different mouse buttons there are in OIS.
    117     static const int numberOfMouseButtons_s = 8;
    118     //! Array of input events for every pressed mouse button
    119     KeyBinding bindingsMouseButtonPress_  [numberOfMouseButtons_s];
    120     //! Array of input events for every released mouse button
    121     KeyBinding bindingsMouseButtonRelease_[numberOfMouseButtons_s];
    122     //! Array of input events for every held mouse button
    123     KeyBinding bindingsMouseButtonHold_   [numberOfMouseButtons_s];
    124     //! Key binding for mouse moved event
    125     KeyBinding bindingMouseMoved_;
    126     //! Key binding for mouse scrolled event
    127     KeyBinding bindingMouseScrolled_;
    128     //! Names of the mouse buttons as strings
    129     std::string mouseButtonNames_[numberOfMouseButtons_s];
     180    static const unsigned int nMouseButtons_s = 8 + 2*2; // 8 buttons and 2 scroll wheels
     181    //! Actual key bindings as bundle for Press, Hold and Release
     182    Button mouseButtons_ [nMouseButtons_s];
    130183
    131184    //! denotes the number of different joy stick buttons there are in OIS.
    132     static const int numberOfJoyStickButtons_s = 32;
    133     //! Array of input events for every pressed joy stick button
    134     KeyBinding bindingsJoyStickButtonPress_  [numberOfJoyStickButtons_s];
    135     //! Array of input events for every released joy stick button
    136     KeyBinding bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s];
    137     //! Array of input events for every held joy stick button
    138     KeyBinding bindingsJoyStickButtonHold_   [numberOfJoyStickButtons_s];
    139     //! Names of the joy stick buttons as strings
    140     std::string joyStickButtonNames_[numberOfJoyStickButtons_s];
    141 
     185    static const unsigned int nJoyStickButtons_s = 32 + 4 * 4; // 32 buttons and 4 POVs with 4 buttons
     186    //! Actual key bindings as bundle for Press, Hold and Release
     187    Button joyStickButtons_ [nJoyStickButtons_s];
     188
     189    //! denotes the number of half axes (every axis twice) there can be.
     190    static const unsigned int nHalfAxes_s = 56;
     191    /**
     192    * Array with all the half axes for mouse and joy sticks.
     193    * Keep in mind that the positions are fixed and that the first entry is the
     194    * positive one and the second is negative.
     195    * Sequence is as follows:
     196    *  0 -  3: Mouse x and y
     197    *  4 -  7: empty
     198    *  8 - 23: joy stick (slider) axes 1 to 8
     199    * 24 - 55: joy stick axes 1 - 16
     200    */
     201    HalfAxis halfAxes_[nHalfAxes_s];
     202
     203    /**
     204    * Commands that have additional parameters (axes) are executed at the end of
     205    * the tick() so that all values can be buffered for single execution.
     206    */
     207    std::vector<BufferedParamCommand*> paramCommandBuffer_;
     208
     209    //! Keeps track of the absolute mouse value (incl. scroll wheel)
     210    int mousePosition_[3];
     211    //! Used to derive mouse input if requested
     212    int mouseRelative_[2];
     213    float deriveTime_;
     214
     215    //##### ConfigValues #####
     216    //! Threshold for analog triggers until which the state is 0.
     217    float analogThreshold_;
     218    //! Threshold for analog triggers until which the button is not pressed.
     219    float buttonThreshold_;
     220    //! Derive mouse input for absolute values?
     221    bool bDeriveMouseInput_;
     222    //! Accuracy of the mouse input deriver. The higher the more precise, but laggier.
     223    float derivePeriod_;
     224    //! mouse sensitivity
     225    float mouseSensitivity_;
    142226  };
    143227
  • code/trunk/src/core/InputInterfaces.h

    r1293 r1349  
    3838
    3939#include "ois/OIS.h"
     40#include "util/Math.h"
    4041
    4142namespace orxonox
     
    239240  };
    240241
    241   typedef OIS::MouseState MouseState;
    242 
    243   class _CoreExport JoyStickState : OIS::JoyStickState
     242  //typedef OIS::MouseState MouseState;
     243
     244  /*class _CoreExport JoyStickState
    244245  {
    245246  public:
     
    247248    JoyStickState() { clear(); }
    248249    int mJoyStickID;
     250                JoyStickState() { clear(); }
     251
     252                std::vector<bool> mButtons;
     253                int axes[16];
     254                std::vector<Vector3> mVectors;
     255  };*/
     256
     257  class _CoreExport InputTickable
     258  {
     259  public:
     260    virtual ~InputTickable() { }
     261    virtual void tick(float dt) = 0;
    249262  };
    250263
     
    252265    @brief Interface class used for key input listeners.
    253266  */
    254   class _CoreExport KeyHandler
     267  class _CoreExport KeyHandler : virtual public InputTickable
    255268  {
    256269  public:
    257270    virtual ~KeyHandler() { }
    258     virtual bool keyPressed (const KeyEvent& evt) = 0;
    259     virtual bool keyReleased(const KeyEvent& evt) = 0;
    260     virtual bool keyHeld    (const KeyEvent& evt) = 0;
     271    virtual void keyPressed (const KeyEvent& evt) = 0;
     272    virtual void keyReleased(const KeyEvent& evt) = 0;
     273    virtual void keyHeld    (const KeyEvent& evt) = 0;
    261274  };
    262275
     
    264277    @brief Interface class used for mouse input listeners.
    265278  */
    266   class _CoreExport MouseHandler
     279  class _CoreExport MouseHandler : virtual public InputTickable
    267280  {
    268281  public:
    269282    virtual ~MouseHandler() { }
    270     virtual bool mouseButtonPressed (const MouseState& state, MouseButton::Enum id) = 0;
    271     virtual bool mouseButtonReleased(const MouseState& state, MouseButton::Enum id) = 0;
    272     virtual bool mouseButtonHeld    (const MouseState& state, MouseButton::Enum id) = 0;
    273     virtual bool mouseMoved         (const MouseState& state) = 0;
    274     virtual bool mouseScrolled      (const MouseState& state) = 0;
     283    virtual void mouseButtonPressed (MouseButton::Enum id) = 0;
     284    virtual void mouseButtonReleased(MouseButton::Enum id) = 0;
     285    virtual void mouseButtonHeld    (MouseButton::Enum id) = 0;
     286    virtual void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;
     287    virtual void mouseScrolled      (int abs, int rel)    = 0;
    275288  };
    276289
     
    279292    @brief Interface class used for joy stick input listeners.
    280293  */
    281   class _CoreExport JoyStickHandler
     294  class _CoreExport JoyStickHandler : virtual public InputTickable
    282295  {
    283296  public:
    284297    virtual ~JoyStickHandler() { }
    285     virtual bool joyStickButtonPressed (const JoyStickState& state, int button) = 0;
    286     virtual bool joyStickButtonReleased(const JoyStickState& state, int button) = 0;
    287     virtual bool joyStickButtonHeld    (const JoyStickState& state, int button) = 0;
    288     virtual bool joyStickAxisMoved     (const JoyStickState& state, int axis)   = 0;
    289     virtual bool joyStickSliderMoved   (const JoyStickState& state, int index) {return true;}
    290     virtual bool joyStickPovMoved      (const JoyStickState& state, int index) {return true;}
    291     virtual bool joyStickVector3Moved  (const JoyStickState& state, int index) {return true;}
     298    virtual void joyStickButtonPressed (int joyStickID, int button) = 0;
     299    virtual void joyStickButtonReleased(int joyStickID, int button) = 0;
     300    virtual void joyStickButtonHeld    (int joyStickID, int button) = 0;
     301    virtual void joyStickAxisMoved     (int joyStickID, int axis, int value) = 0;
     302    //virtual bool joyStickVector3Moved  (int joyStickID, int index /*, fill list*/) {return true;}
    292303  };
    293304
  • code/trunk/src/core/InputManager.cc

    r1293 r1349  
    9898      windowHndStr << (unsigned int)windowHnd;
    9999      paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
    100 
     100      //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
     101      //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
    101102//#if defined OIS_LINUX_PLATFORM
    102103//      paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
     
    126127
    127128      // Set mouse/joystick region
    128       setWindowExtents(windowWidth, windowHeight);
     129      if (mouse_)
     130      {
     131        //// hack the mouse position
     132        //((OIS::MouseState&)mouse_->getMouseState()).X.abs = windowWidth/2;
     133        //((OIS::MouseState&)mouse_->getMouseState()).Y.abs = windowHeight/2;
     134        setWindowExtents(windowWidth, windowHeight);
     135      }
    129136
    130137      state_ = IS_NONE;
     
    267274    activeJoyStickHandlers_.resize(joySticksSize_);
    268275    joyStickButtonsDown_.resize(joySticksSize_);
     276    povStates_.resize(joySticksSize_);
     277    sliderStates_.resize(joySticksSize_);
    269278    return success;
    270279  }
     
    350359  }
    351360
     361  void InputManager::_updateTickables()
     362  {
     363    // we can use a set to have a list of unique pointers (an object can implement all 3 handlers)
     364    std::set<InputTickable*> tempSet;
     365    for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++)
     366      tempSet.insert(activeKeyHandlers_[iHandler]);
     367    for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
     368      tempSet.insert(activeMouseHandlers_[iHandler]);
     369    for (unsigned int iJoyStick  = 0; iJoyStick < joySticksSize_; iJoyStick++)
     370      for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     371        tempSet.insert(activeJoyStickHandlers_[iJoyStick][iHandler]);
     372
     373    // copy the content of the set back to the actual vector
     374    activeHandlers_.clear();
     375    for (std::set<InputTickable*>::const_iterator itHandler = tempSet.begin(); itHandler != tempSet.end(); itHandler++)
     376      activeHandlers_.push_back(*itHandler);
     377  }
     378
    352379
    353380  // #################################
     
    380407          // normal play mode
    381408          // note: we assume that the handlers exist since otherwise, something's wrong anyway.
    382           activeKeyHandlers_.push_back(keyHandlers_["keybinder"]);
    383           activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]);
    384           if (getMouseHandler("SpaceShip"))
    385             activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]);
    386           for (unsigned int i = 0; i < joySticksSize_; i++)
    387             activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]);
     409          enableKeyHandler("keybinder");
     410          enableMouseHandler("keybinder");
     411          enableMouseHandler("SpaceShip");
     412          enableJoyStickHandler("keybinder", 0);
    388413          break;
    389414
    390415        case IS_GUI:
    391           // FIXME: do stuff
     416          // TODO: do stuff
    392417          break;
    393418
    394419        case IS_CONSOLE:
    395           activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]);
    396           if (getMouseHandler("SpaceShip"))
    397             activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]);
    398           for (unsigned int i = 0; i < joySticksSize_; i++)
    399             activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]);
    400 
    401           activeKeyHandlers_.push_back(keyHandlers_["buffer"]);
     420          enableMouseHandler("keybinder");
     421          enableMouseHandler("SpaceShip");
     422          enableJoyStickHandler("keybinder", 0);
     423          enableKeyHandler("buffer");
    402424          break;
    403425
     
    426448    for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++)
    427449      for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++)
    428         activeMouseHandlers_[iHandler]->mouseButtonHeld(mouse_->getMouseState(), mouseButtonsDown_[iButton]);
     450        activeMouseHandlers_[iHandler]->mouseButtonHeld(mouseButtonsDown_[iButton]);
    429451
    430452    // call all the handlers for the held joy stick button events
     
    432454      for (unsigned int iButton   = 0; iButton   < joyStickButtonsDown_[iJoyStick].size(); iButton++)
    433455        for (unsigned int iHandler = 0; iHandler  < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    434           activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(
    435               JoyStickState(joySticks_[iJoyStick]->getJoyStickState(), iJoyStick), joyStickButtonsDown_[iJoyStick][iButton]);
     456          activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld(iJoyStick, joyStickButtonsDown_[iJoyStick][iButton]);
     457
     458
     459    // call the ticks
     460    for (unsigned int iHandler = 0; iHandler < activeHandlers_.size(); iHandler++)
     461      activeHandlers_[iHandler]->tick(dt);
    436462  }
    437463
     
    508534    {
    509535      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    510         activeMouseHandlers_[i]->mouseMoved(e.state);
     536        activeMouseHandlers_[i]->mouseMoved(IntVector2(e.state.X.abs, e.state.Y.abs),
     537            IntVector2(e.state.X.rel, e.state.Y.rel), IntVector2(e.state.width, e.state.height));
    511538    }
    512539
     
    515542    {
    516543      for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    517         activeMouseHandlers_[i]->mouseScrolled(e.state);
     544        activeMouseHandlers_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
    518545    }
    519546
     
    536563
    537564    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    538       activeMouseHandlers_[i]->mouseButtonPressed(e.state, (MouseButton::Enum)id);
     565      activeMouseHandlers_[i]->mouseButtonPressed((MouseButton::Enum)id);
    539566
    540567    return true;
     
    559586
    560587    for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++)
    561       activeMouseHandlers_[i]->mouseButtonReleased(e.state, (MouseButton::Enum)id);
     588      activeMouseHandlers_[i]->mouseButtonReleased((MouseButton::Enum)id);
    562589
    563590    return true;
     
    584611
    585612    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    586       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(JoyStickState(arg.state, iJoyStick), button);
     613      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(iJoyStick, button);
    587614
    588615    return true;
     
    609636
    610637    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    611       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(JoyStickState(arg.state, iJoyStick), button);
     638      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(iJoyStick, button);
    612639
    613640    return true;
     
    616643  bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis)
    617644  {
     645    //CCOUT(3) << arg.state.mAxes[axis].abs << std::endl;
    618646    // use the device to identify which one called the method
    619647    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     
    622650      iJoyStick++;
    623651
     652    // keep in mind that the first 8 axes are reserved for the sliders
    624653    for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    625       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(JoyStickState(arg.state, iJoyStick), axis);
     654      activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, axis + 8, arg.state.mAxes[axis].abs);
    626655
    627656    return true;
     
    630659  bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id)
    631660  {
     661    //CCOUT(3) << arg.state.mSliders[id].abX << "\t |" << arg.state.mSliders[id].abY << std::endl;
    632662    // use the device to identify which one called the method
    633663    OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device;
     
    636666      iJoyStick++;
    637667
    638     for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    639       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickSliderMoved(JoyStickState(arg.state, iJoyStick), id);
     668    if (sliderStates_[iJoyStick].sliderStates[id].x != arg.state.mSliders[id].abX)
     669    {
     670      // slider X axis changed
     671      sliderStates_[iJoyStick].sliderStates[id].x = arg.state.mSliders[id].abX;
     672      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     673        activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2, arg.state.mSliders[id].abX);
     674    }
     675    else if (sliderStates_[iJoyStick].sliderStates[id].y != arg.state.mSliders[id].abY)
     676    {
     677      // slider Y axis changed
     678      sliderStates_[iJoyStick].sliderStates[id].y = arg.state.mSliders[id].abY;
     679      for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
     680        activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(iJoyStick, id * 2 + 1, arg.state.mSliders[id].abY);
     681    }
    640682
    641683    return true;
     
    650692      iJoyStick++;
    651693
    652     for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++)
    653       activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickPovMoved(JoyStickState(arg.state, iJoyStick), id);
    654 
    655     return true;
    656   }
    657 
    658   bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
     694    // translate the POV into 8 simple buttons
     695    int lastState = povStates_[iJoyStick][id];
     696    if (lastState & OIS::Pov::North)
     697      buttonReleased(arg, 32 + id * 4 + 0);
     698    if (lastState & OIS::Pov::South)
     699      buttonReleased(arg, 32 + id * 4 + 1);
     700    if (lastState & OIS::Pov::East)
     701      buttonReleased(arg, 32 + id * 4 + 2);
     702    if (lastState & OIS::Pov::West)
     703      buttonReleased(arg, 32 + id * 4 + 3);
     704   
     705    povStates_[iJoyStick].povStates[id] = arg.state.mPOV[id].direction;
     706    int currentState = povStates_[iJoyStick][id];
     707    if (currentState & OIS::Pov::North)
     708      buttonPressed(arg, 32 + id * 4 + 0);
     709    if (currentState & OIS::Pov::South)
     710      buttonPressed(arg, 32 + id * 4 + 1);
     711    if (currentState & OIS::Pov::East)
     712      buttonPressed(arg, 32 + id * 4 + 2);
     713    if (currentState & OIS::Pov::West)
     714      buttonPressed(arg, 32 + id * 4 + 3);
     715
     716    return true;
     717  }
     718
     719  /*bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id)
    659720  {
    660721    // use the device to identify which one called the method
     
    668729
    669730    return true;
    670   }
     731  }*/
    671732
    672733
     
    735796  }
    736797
    737   const MouseState InputManager::getMouseState()
     798  /*const MouseState InputManager::getMouseState()
    738799  {
    739800    if (_getSingleton().mouse_)
     
    741802    else
    742803      return MouseState();
    743   }
    744 
    745   const JoyStickState InputManager::getJoyStickState(unsigned int ID)
     804  }*/
     805
     806  /*const JoyStickState InputManager::getJoyStickState(unsigned int ID)
    746807  {
    747808    if (ID < _getSingleton().joySticksSize_)
     
    749810    else
    750811      return JoyStickState();
    751   }
     812  }*/
    752813
    753814
     
    882943      if ((*it) == (*mapIt).second)
    883944      {
    884         _getSingleton().stateRequest_ = IS_CUSTOM;
    885945        return true;
    886946      }
     
    888948    _getSingleton().activeKeyHandlers_.push_back((*mapIt).second);
    889949    _getSingleton().stateRequest_ = IS_CUSTOM;
     950    _getSingleton()._updateTickables();
    890951    return true;
    891952  }
     
    910971        _getSingleton().activeKeyHandlers_.erase(it);
    911972        _getSingleton().stateRequest_ = IS_CUSTOM;
     973        _getSingleton()._updateTickables();
    912974        return true;
    913975      }
    914976    }
    915     _getSingleton().stateRequest_ = IS_CUSTOM;
    916977    return true;
    917978  }
     
    10101071      if ((*it) == (*mapIt).second)
    10111072      {
    1012         _getSingleton().stateRequest_ = IS_CUSTOM;
    10131073        return true;
    10141074      }
     
    10161076    _getSingleton().activeMouseHandlers_.push_back((*mapIt).second);
    10171077    _getSingleton().stateRequest_ = IS_CUSTOM;
     1078    _getSingleton()._updateTickables();
    10181079    return true;
    10191080  }
     
    10381099        _getSingleton().activeMouseHandlers_.erase(it);
    10391100        _getSingleton().stateRequest_ = IS_CUSTOM;
     1101        _getSingleton()._updateTickables();
    10401102        return true;
    10411103      }
    10421104    }
    1043     _getSingleton().stateRequest_ = IS_CUSTOM;
    10441105    return true;
    10451106  }
     
    11471208      if ((*it) == (*handlerIt).second)
    11481209      {
    1149         _getSingleton().stateRequest_ = IS_CUSTOM;
    11501210        return true;
    11511211      }
     
    11531213    _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second);
    11541214    _getSingleton().stateRequest_ = IS_CUSTOM;
     1215    _getSingleton()._updateTickables();
    11551216    return true;
    11561217  }
     
    11801241        _getSingleton().activeJoyStickHandlers_[ID].erase(it);
    11811242        _getSingleton().stateRequest_ = IS_CUSTOM;
     1243        _getSingleton()._updateTickables();
    11821244        return true;
    11831245      }
  • code/trunk/src/core/InputManager.h

    r1293 r1349  
    4242
    4343#include "ois/OIS.h"
     44#include "util/Math.h"
    4445#include "Tickable.h"
    4546#include "InputInterfaces.h"
     
    4748namespace orxonox
    4849{
     50  /**
     51  * Helper class to realise a vector<int[4]>
     52  */
     53  class POVStates
     54  {
     55  public:
     56    int operator[](unsigned int index) { return povStates[index]; }
     57    int povStates[4];
     58  };
     59
     60  /**
     61  * Helper class to realise a vector< {int[4], int[4]} >
     62  */
     63  class SliderStates
     64  {
     65  public:
     66    IntVector2 sliderStates[4];
     67  };
     68
    4969  /**
    5070    @brief Captures and distributes mouse and keyboard input.
     
    85105    static bool isModifierDown(KeyboardModifier::Enum modifier);
    86106    static bool isKeyDown(KeyCode::Enum key);
    87     static const MouseState getMouseState();
    88     static const JoyStickState getJoyStickState(unsigned int ID);
     107    //static const MouseState getMouseState();
     108    //static const JoyStickState getJoyStickState(unsigned int ID);
    89109
    90110    static void setWindowExtents(const int width, const int height);
     
    130150    void _destroyMouse();
    131151    void _destroyJoySticks();
     152
     153    void _updateTickables();
    132154
    133155    void tick(float dt);
     
    144166    bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
    145167    bool povMoved      (const OIS::JoyStickEvent &arg, int id);
    146     bool vector3Moved  (const OIS::JoyStickEvent &arg, int id);
     168    //bool vector3Moved  (const OIS::JoyStickEvent &arg, int id);
    147169
    148170    static InputManager& _getSingleton();
     
    160182    unsigned int keyboardModifiers_;
    161183
     184    //! Keeps track of the joy stick POV states
     185    std::vector<POVStates>                      povStates_;
     186    //! Keeps track of the possibly two slider axes
     187    std::vector<SliderStates>                   sliderStates_;
     188
    162189    std::map<std::string, KeyHandler*>          keyHandlers_;
    163190    std::map<std::string, MouseHandler*>        mouseHandlers_;
     
    167194    std::vector<MouseHandler*>                  activeMouseHandlers_;
    168195    std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
     196    std::vector<InputTickable*>                 activeHandlers_;
    169197
    170198    std::vector<Key>                            keysDown_;
  • code/trunk/src/core/SignalHandler.cc

    r1293 r1349  
    150150  {
    151151    std::cout << "Trying to restore XAutoKeyRepeat" << std::endl;
    152         Display* display;
    153           if ((display = XOpenDisplay(0)))
    154     {
    155                         XAutoRepeatOn(display);
    156                   XCloseDisplay(display);
     152    Display* display;
     153    if ((display = XOpenDisplay(0)))
     154    {
     155      XAutoRepeatOn(display);
     156      XCloseDisplay(display);
    157157    }
    158158  }
     
    320320
    321321  std::string timeString = "\n\n\n\n"
    322                            "=======================================================\n"
    323                            "= time: " + std::string(ctime(&now)) +
    324                            "=======================================================\n";
     322                     "=======================================================\n"
     323                     "= time: " + std::string(ctime(&now)) +
     324         "=======================================================\n";
    325325  bt.insert(0, timeString);
    326326
Note: See TracChangeset for help on using the changeset viewer.