Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 20, 2008, 6:49:24 PM (16 years ago)
Author:
rgrieder
Message:

Finally! The InputManager is now working like I imagined it to. And it's even easier to use it as well.
A little explanation: Every time you change something about the input distribution, it is a change of 'state' represented by the class 'InputState'.
That can be for instance: "console", "game", "gui", etc. Every state has a name and a priority which describes who comes first. Now if one state doesn't handle mouse input or instance, then the one with the next lower priority gets it. To prevent that, you can add the 'EmptyHandler' to the state with setMouseHandler.
InputState is just an abstract base class. There are two classes implementing it: SimpleInputState and ExtendedInputState. The latter allows for multiple input handlers for one single device.

Basically, what you need to know is what you see in Orxonox.cc, InGameConsole.cc and Shell.cc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/input/src/core/input/Button.cc

    r1630 r1637  
    8888                    '\\', false, '"', false, '(', ')', false, '\0');
    8989
    90                 unsigned int iToken = 0;
    91 
    92                 // for real axes, we can feed a ButtonThreshold argument as entire command
    93                 if (getLowercase(tokens[0]) == "buttonthreshold")
    94                 {
    95                     if (tokens.size() == 1)
    96                         continue;
    97                     // may fail, but doesn't matter
    98                     convertValue(&buttonThreshold_, tokens[1]);
    99                     continue;
    100                 }
    101 
    102                 // first argument can be OnPress, OnHold OnRelease or nothing
    10390                KeybindMode::Enum mode = KeybindMode::None;
    104                 if (getLowercase(tokens[iToken]) == "onpress")
    105                     mode = KeybindMode::OnPress,   iToken++;
    106                 if (getLowercase(tokens[iToken]) == "onrelease")
    107                     mode = KeybindMode::OnRelease, iToken++;
    108                 if (getLowercase(tokens[iToken]) == "onhold")
    109                     mode = KeybindMode::OnHold,    iToken++;
    110 
    111                 if (iToken == tokens.size())
    112                     continue;
    113 
    114                 // second argument can be the amplitude for the case it as an axis command
    115                 // default amplitude is 1.0f
    11691                float paramModifier = 1.0f;
    117                 if (getLowercase(tokens[iToken]) == "scale")
    118                 {
    119                     iToken++;
    120                     if (iToken == tokens.size() || !convertValue(&paramModifier, tokens[iToken]))
    121                     {
    122                         COUT(2) << "Error while parsing key binding " << name_
    123                                 << ". Numeric expression expected afer 'AxisAmp', switching to default value"
    124                                 << std::endl;
     92                std::string commandStr = "";
     93
     94                for (unsigned int iToken = 0; iToken < tokens.size(); ++iToken)
     95                {
     96                    std::string token = getLowercase(tokens[iToken]);
     97
     98                    if (token == "onpress")
     99                        mode = KeybindMode::OnPress;
     100                    else if (token == "onrelease")
     101                        mode = KeybindMode::OnRelease;
     102                    else if (token == "onhold")
     103                        mode = KeybindMode::OnHold;
     104                    else if (token == "buttonthreshold")
     105                    {
     106                        // for real axes, we can feed a ButtonThreshold argument
     107                        ++iToken;
    125108                        if (iToken == tokens.size())
    126109                            continue;
    127                     }
    128                     iToken++;
    129                 }
    130 
    131                 // no more arguments expected except for the actual command
    132                 if (iToken == tokens.size())
     110                        // may fail, but doesn't matter (default value already set)
     111                        if (!convertValue(&buttonThreshold_, tokens[iToken + 1]))
     112                            parseError("Could not parse 'ButtonThreshold' argument. \
     113                                Switching to default value.", true);
     114                    }
     115                    else if (token == "scale")
     116                    {
     117                        ++iToken;
     118                        if (iToken == tokens.size() || !convertValue(&paramModifier, tokens[iToken]))
     119                            parseError("Could not parse 'scale' argument. Switching to default value.", true);
     120                    }
     121                    else
     122                    {
     123                        // no input related argument
     124                        // we interpret everything from here as a command string
     125                        while (iToken != tokens.size())
     126                            commandStr += tokens[iToken++] + " ";
     127                    }
     128                }
     129
     130                if (commandStr == "")
     131                {
     132                    parseError("No command string given.", false);
    133133                    continue;
    134 
    135                 std::string commandStr;
    136                 while (iToken != tokens.size())
    137                     commandStr += tokens[iToken++] + " ";
     134                }
    138135
    139136                // evaluate the command
    140137                CommandEvaluation eval = CommandExecutor::evaluate(commandStr);
    141138                if (!eval.isValid())
     139                {
     140                    parseError("Command evaluation failed.", true);
    142141                    continue;
     142                }
    143143
    144144                // check for param command
     
    215215        return true;
    216216    }
     217
     218    inline void Button::parseError(std::string message, bool serious)
     219    {
     220        if (serious)
     221        {
     222            COUT(2) << "Error while parsing binding for button/axis" << this->name_ << ". "
     223                << message << std::endl;
     224        }
     225        else
     226        {
     227            COUT(3) << "Warning while parsing binding for button/axis" << this->name_ << ". "
     228                << message << std::endl;
     229        }
     230    }
    217231}
Note: See TracChangeset for help on using the changeset viewer.