Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

merged input branch into gui test branch (was about time)
svn save (it's still a mess and CMLs haven't been updated)
I'll have to create a special project to create the tolua_bind files for tolua itself anyway..

Location:
code/branches/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui

  • code/branches/gui/src/core/input/InputCommands.cc

    r1535 r1638  
    2828
    2929/**
    30  @file
    31  @brief Implementation of the different input handlers.
    32  */
     30@file
     31@brief
     32    Implementation of the different input handlers.
     33*/
    3334
    3435#include "InputCommands.h"
     
    3738namespace orxonox
    3839{
    39   // ###############################
    40   // ###  BufferedParamCommand   ###
    41   // ###############################
     40    // ###############################
     41    // ###  BufferedParamCommand   ###
     42    // ###############################
    4243
    43   /**
    44   * Executes a buffered command. This is used for commands with additional
    45   * parameters.
    46   * @return True if command execution was successful or value was zero.
    47   */
    48   bool BufferedParamCommand::execute()
    49   {
    50     if (nValuesAdded_)
     44    /**
     45    @brief
     46        Executes a buffered command. This is used for commands with additional
     47        parameters.
     48    @return
     49        True if command execution was successful or value was zero.
     50    */
     51    bool BufferedParamCommand::execute()
    5152    {
    52       BufferedParamCommand& cmd = *this;
    53       cmd.evaluation_.setEvaluatedParameter(cmd.paramIndex_, cmd.value_);
    54       // reset
    55       cmd.nValuesAdded_ = 0;
    56       cmd.value_ = 0;
    57       return cmd.evaluation_.execute();
     53        if (nValuesAdded_)
     54        {
     55            BufferedParamCommand& cmd = *this;
     56            cmd.evaluation_.setEvaluatedParameter(cmd.paramIndex_, cmd.value_);
     57            // reset
     58            cmd.nValuesAdded_ = 0;
     59            cmd.value_ = 0;
     60            return cmd.evaluation_.execute();
     61        }
     62        else
     63            return true;
    5864    }
    59     else
    60       return true;
    61   }
    6265
    63   // ###############################
    64   // #####    SimpleCommand    #####
    65   // ###############################
     66    // ###############################
     67    // #####    SimpleCommand    #####
     68    // ###############################
    6669
    67   /**
    68   * Executes a simple command with no additional paramters.
    69   * @return True if command execution was successful, false otherwise.
    70   */
    71   bool SimpleCommand::execute(float abs, float rel)
    72   {
    73     return evaluation_.execute();
    74   }
     70    /**
     71    @brief
     72        Executes a simple command with no additional paramters.
     73    @return
     74        True if command execution was successful, false otherwise.
     75    */
     76    bool SimpleCommand::execute(float abs, float rel)
     77    {
     78        return evaluation_.execute();
     79    }
    7580
    76   // ###############################
    77   // #####    ParamCommand     #####
    78   // ###############################
     81    // ###############################
     82    // #####    ParamCommand     #####
     83    // ###############################
    7984
    80   /**
    81   * Executes a parameter command. The commmand string is not directly executed,
    82   * but instead stored in a buffer list so that values can be combined.
    83   * @return Always true.
    84   */
    85   bool ParamCommand::execute(float abs, float rel)
    86   {
    87     BufferedParamCommand& cmd = *paramCommand_;
    88     // command has an additional parameter
    89     if (bRelative_)
     85    /**
     86    @brief
     87        Executes a parameter command. The commmand string is not directly executed,
     88        but instead stored in a buffer list so that values can be combined.
     89    @return
     90        Always true.
     91    */
     92    bool ParamCommand::execute(float abs, float rel)
    9093    {
    91       if (rel != 0.0f)
    92       {
    93         // we have to calculate a relative movement.
    94         // paramModifier_ says how much one keystroke is
    95         cmd.value_ += paramModifier_ * rel;
    96       }
     94        BufferedParamCommand& cmd = *paramCommand_;
     95        // command has an additional parameter
     96        if (bRelative_)
     97        {
     98            if (rel != 0.0f)
     99            {
     100                // we have to calculate a relative movement.
     101                // paramModifier_ says how much one keystroke is
     102                cmd.value_ += paramModifier_ * rel;
     103            }
     104        }
     105        else if (abs != 0.0f)
     106        {
     107            // Usually, joy sticks create 'noise' (they return values if they're in 0 position)
     108            // and normally this is caught in tickInput(), but that threshold cannot be to high
     109            // in order to preserve accuracy. Instead, we have to catch the problem here. An example:
     110            // Someone only uses buttons with an active joystick. The joy stick value could then
     111            // be 0.05 for instance and the the key value 1. Without handling the problem, the final
     112            // value would be computed to (1+0.05)/2=0.5025 which is not what the user expects.
     113            float absQ = abs * abs;
     114            float valueQ = cmd.value_ * cmd.value_;
     115            if (absQ > 50.0f * valueQ) // ease up comparison by using quadratics
     116            {
     117                cmd.value_ = abs * paramModifier_;
     118                cmd.nValuesAdded_ = 1;
     119            }
     120            else if (absQ * 50.0f < valueQ)
     121            {
     122                // abs is too small, we just don't do anything
     123            }
     124            else
     125            {
     126                // we have to calculate the absolute position of the axis.
     127                // Since there might be another axis that is affected, we have to wait and
     128                // store the result in a temporary place
     129                cmd.value_ = (cmd.value_ * cmd.nValuesAdded_ + paramModifier_ * abs) / ++cmd.nValuesAdded_;
     130            }
     131        }
     132        return true;
    97133    }
    98     else if (abs != 0.0f)
    99     {
    100       // Usually, joy sticks create 'noise' (they return values if they're in 0 position)
    101       // and normally this is caught in tickInput(), but that threshold cannot be to high
    102       // in order to preserve accuracy. Instead, we have to catch the problem here. An example:
    103       // Someone only uses buttons with an active joystick. The joy stick value could then
    104       // be 0.05 for instance and the the key value 1. Without handling the problem, the final
    105       // value would be computed to (1+0.05)/2=0.5025 which is not what the user expects.
    106       float absQ = abs * abs;
    107       float valueQ = cmd.value_ * cmd.value_;
    108       if (absQ > 50.0f * valueQ) // ease up comparison by using quadratics
    109       {
    110         cmd.value_ = abs * paramModifier_;
    111         cmd.nValuesAdded_ = 1;
    112       }
    113       else if (absQ * 50.0f < valueQ)
    114       {
    115         // abs is too small, we just don't do anything
    116       }
    117       else
    118       {
    119         // we have to calculate the absolute position of the axis.
    120         // Since there might be another axis that is affected, we have to wait and
    121         // store the result in a temporary place
    122         cmd.value_ = (cmd.value_ * cmd.nValuesAdded_ + paramModifier_ * abs) / ++cmd.nValuesAdded_;
    123       }
    124     }
    125     return true;
    126   }
    127134}
Note: See TracChangeset for help on using the changeset viewer.