Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1428 for code


Ignore:
Timestamp:
May 26, 2008, 11:36:50 AM (17 years ago)
Author:
rgrieder
Message:
  • added SetConfigValueGeneric to set the config value of the actual class when using hierarchies
  • fixed a bug when handling derived mouse input
  • refined 'keybind' command so that input goes to KeyDetector only
Location:
code/branches/network/src/core
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/core/ConfigValueIncludes.h

    r1062 r1428  
    5353        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, varname = defvalue); \
    5454        this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \
     55    } \
     56    container##varname->getValue(&varname)
     57
     58/**
     59    @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
     60    @param classname name in which the config value should be stored
     61    @param varname The name of the variable
     62    @param defvalue The default-value of the variable
     63*/
     64#define SetConfigValueGeneric(classname, varname, defvalue) \
     65    orxonox::ConfigValueContainer* container##varname = ClassManager<classname>::getIdentifier()->getConfigValueContainer(#varname); \
     66    if (!container##varname) \
     67    { \
     68        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, ClassManager<classname>::getIdentifier(), #varname, varname = defvalue); \
     69        ClassManager<classname>::getIdentifier()->addConfigValueContainer(#varname, container##varname); \
    5570    } \
    5671    container##varname->getValue(&varname)
  • code/branches/network/src/core/InputManager.cc

    r1426 r1428  
    371371  }
    372372
     373  void InputManager::_saveState()
     374  {
     375    savedHandlers_.activeHandlers_ = activeHandlers_;
     376    savedHandlers_.activeJoyStickHandlers_ = activeJoyStickHandlers_;
     377    savedHandlers_.activeKeyHandlers_ = activeKeyHandlers_;
     378    savedHandlers_.activeMouseHandlers_ = activeMouseHandlers_;
     379  }
     380
     381  void InputManager::_restoreState()
     382  {
     383    activeHandlers_ = savedHandlers_.activeHandlers_;
     384    activeJoyStickHandlers_ = savedHandlers_.activeJoyStickHandlers_;
     385    activeKeyHandlers_ = savedHandlers_.activeKeyHandlers_;
     386    activeMouseHandlers_ = savedHandlers_.activeMouseHandlers_;
     387  }
     388
    373389  void InputManager::_updateTickables()
    374390  {
     
    405421      return;
    406422
    407     // reset the game if it has changed
    408423    if (state_ != stateRequest_)
    409424    {
    410425      if (stateRequest_ != IS_CUSTOM)
    411426      {
    412         if (stateRequest_ != IS_NODETECT && stateRequest_ != IS_DETECT)
     427        if (stateRequest_ != IS_DETECT)
    413428        {
    414429          activeKeyHandlers_.clear();
     
    439454        case IS_DETECT:
    440455          savedState_ = state_;
     456          _saveState();
     457
     458          activeKeyHandlers_.clear();
     459          activeMouseHandlers_.clear();
     460          for (unsigned int i = 0; i < joySticksSize_; i++)
     461            activeJoyStickHandlers_[i].clear();
     462
    441463          enableKeyHandler("keydetector");
    442464          enableMouseHandler("keydetector");
     
    445467
    446468        case IS_NODETECT:
    447           disableKeyHandler("keydetector");
    448           disableMouseHandler("keydetector");
    449           disableJoyStickHandler("keydetector", 0);
     469          _restoreState();
    450470          break;
    451471
  • code/branches/network/src/core/InputManager.h

    r1426 r1428  
    6565  public:
    6666    IntVector2 sliderStates[4];
     67  };
     68
     69  /**
     70  * Struct for storing a custom input state
     71  */
     72  struct StoredState
     73  {
     74    std::vector<KeyHandler*>                    activeKeyHandlers_;
     75    std::vector<MouseHandler*>                  activeMouseHandlers_;
     76    std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_;
     77    std::vector<std::pair<InputTickable*, HandlerState> > activeHandlers_;
    6778  };
    6879
     
    158169    void _updateTickables();
    159170
     171    void _saveState();
     172    void _restoreState();
     173
    160174    void tick(float dt);
    161175
     
    191205    unsigned int keyboardModifiers_;
    192206    InputState savedState_;
     207    StoredState savedHandlers_;
    193208
    194209    //! Keeps track of the joy stick POV states
  • code/branches/network/src/core/KeyBinder.cc

    r1426 r1428  
    321321        delete paramCommands_[i];
    322322      delete[] paramCommands_;
     323      nParamCommands_ = 0;
    323324    }
    324325    else
     
    543544  void KeyBinder::setConfigValues()
    544545  {
    545     SetConfigValue(analogThreshold_, 0.01f)  .description("Threshold for analog axes until which the state is 0.");
    546     SetConfigValue(mouseSensitivity_, 1.0f)  .description("Mouse sensitivity.");
    547     SetConfigValue(bDeriveMouseInput_, false).description("Whether or not to derive moues movement for the absolute value.");
    548     SetConfigValue(derivePeriod_, 0.5f).description("Accuracy of the mouse input deriver. The higher the more precise, but laggier.");
    549     SetConfigValue(mouseSensitivityDerived_, 1.0f).description("Mouse sensitivity if mouse input is derived.");
     546    SetConfigValueGeneric(KeyBinder, analogThreshold_, 0.01f)  .description("Threshold for analog axes until which the state is 0.");
     547    SetConfigValueGeneric(KeyBinder, mouseSensitivity_, 1.0f)  .description("Mouse sensitivity.");
     548    SetConfigValueGeneric(KeyBinder, bDeriveMouseInput_, false).description("Whether or not to derive moues movement for the absolute value.");
     549    SetConfigValueGeneric(KeyBinder, derivePeriod_, 0.5f).description("Accuracy of the mouse input deriver. The higher the more precise, but laggier.");
     550    SetConfigValueGeneric(KeyBinder, mouseSensitivityDerived_, 1.0f).description("Mouse sensitivity if mouse input is derived.");
     551    SetConfigValueGeneric(KeyBinder, bClipMouse_, true).description("Whether or not to clip absolute value of mouse in non derive mode.");
    550552
    551553    float oldThresh = buttonThreshold_;
    552     SetConfigValue(buttonThreshold_, 0.80f).description("Threshold for analog axes until which the button is not pressed.");
     554    SetConfigValueGeneric(KeyBinder, buttonThreshold_, 0.80f).description("Threshold for analog axes until which the button is not pressed.");
    553555    if (oldThresh != buttonThreshold_)
    554556      for (unsigned int i = 0; i < nHalfAxes_s; i++)
     
    573575  {
    574576    // config value stuff
    575     ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer(button.name_);
     577    ConfigValueContainer* cont = ClassManager<KeyBinder>::getIdentifier()->getConfigValueContainer(button.name_);
    576578    if (!cont)
    577579    {
    578       cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), button.name_, "");
    579       getIdentifier()->addConfigValueContainer(button.name_, cont);
     580      cont = new ConfigValueContainer(CFT_Keybindings, ClassManager<KeyBinder>::getIdentifier(), button.name_, "");
     581      ClassManager<KeyBinder>::getIdentifier()->addConfigValueContainer(button.name_, cont);
    580582    }
    581583    std::string old = button.bindingString_;
     
    585587    if (old != button.bindingString_)
    586588    {
     589      // clear everything so we don't get old axis ParamCommands mixed up
     590      button.clear();
     591
    587592      // binding has changed
    588593      button.parse(paramCommandBuffer_);
     
    678683          //COUT(3) << mouseRelative_[i] << " | ";
    679684          mouseRelative_[i] = 0;
     685          halfAxes_[2*i + 0].hasChanged_ = true;
     686          halfAxes_[2*i + 1].hasChanged_ = true;
    680687        }
    681688        deriveTime_ = 0.0f;
     
    731738  void KeyBinder::mouseMoved(IntVector2 abs_, IntVector2 rel_, IntVector2 clippingSize)
    732739  {
     740    // y axis of mouse input is inverted
     741    int rel[] = { rel_.x, -rel_.y };
     742
    733743    if (!bDeriveMouseInput_)
    734744    {
    735       // y axis of mouse input is inverted
    736       int rel[] = { rel_.x, -rel_.y };
    737 
    738       //COUT(3) << rel[0] << " | " << rel[1] << std::endl;
    739 
    740745      for (int i = 0; i < 2; i++)
    741746      {
     
    743748        {
    744749          // absolute
     750          halfAxes_[2*i + 0].hasChanged_ = true;
     751          halfAxes_[2*i + 1].hasChanged_ = true;
     752          mousePosition_[i] += rel[i];
     753
     754          if (bClipMouse_)
     755          {
     756            if (mousePosition_[i] > 1024)
     757              mousePosition_[i] =  1024;
     758            if (mousePosition_[i] < -1024)
     759              mousePosition_[i] = -1024;
     760          }
     761
    745762          if (mousePosition_[i] >= 0)
    746763          {
    747             mousePosition_[i] += rel[i];
    748             halfAxes_[0 + 2*i].hasChanged_ = true;
    749             if (mousePosition_[i] < 0)
    750             {
    751               halfAxes_[1 + 2*i].hasChanged_ = true;
    752               halfAxes_[1 + 2*i].absVal_ = -((float)mousePosition_[i])/1024 * mouseSensitivity_;
    753               halfAxes_[0 + 2*i].absVal_ =  0.0f;
    754             }
    755             else
    756               halfAxes_[0 + 2*i].absVal_ =  ((float)mousePosition_[i])/1024 * mouseSensitivity_;
     764            halfAxes_[2*i + 0].absVal_ =   mousePosition_[i]/1024.0f * mouseSensitivity_;
     765            halfAxes_[2*i + 1].absVal_ =  0.0f;
    757766          }
    758767          else
    759768          {
    760             mousePosition_[i] += rel[i];
    761             halfAxes_[1 + 2*i].hasChanged_ = true;
    762             if (mousePosition_[i] > 0)
    763             {
    764               halfAxes_[0 + 2*i].hasChanged_ = true;
    765               halfAxes_[0 + 2*i].absVal_ =  ((float)mousePosition_[i])/1024 * mouseSensitivity_;
    766               halfAxes_[1 + 2*i].absVal_ =  0.0f;
    767             }
    768             else
    769               halfAxes_[1 + 2*i].absVal_ = -((float)mousePosition_[i])/1024 * mouseSensitivity_;
    770           }
    771           //COUT(3) << "half axis 0: " << halfAxes_[0].absVal_ << std::endl;
    772           //COUT(3) << "half axis 1: " << halfAxes_[1].absVal_ << std::endl;
    773           //COUT(3) << "half axis 2: " << halfAxes_[2].absVal_ << std::endl;
    774           //COUT(3) << "half axis 3: " << halfAxes_[3].absVal_ << std::endl;
    775 
    776           // relative
    777           if (rel[i] > 0)
    778             halfAxes_[0 + 2*i].relVal_ =  ((float)rel[i])/1024 * mouseSensitivity_;
    779           else
    780             halfAxes_[1 + 2*i].relVal_ = -((float)rel[i])/1024 * mouseSensitivity_;
     769            halfAxes_[2*i + 0].absVal_ =  0.0f;
     770            halfAxes_[2*i + 1].absVal_ =  -mousePosition_[i]/1024.0f * mouseSensitivity_;
     771          }
    781772        }
    782773      }
     
    784775    else
    785776    {
    786       mouseRelative_[0] += rel_.x;
    787       mouseRelative_[1] -= rel_.y;
     777      mouseRelative_[0] += rel[0];
     778      mouseRelative_[1] += rel[1];
     779    }
     780
     781    // relative
     782    for (int i = 0; i < 2; i++)
     783    {
     784      if (rel[i] > 0)
     785        halfAxes_[0 + 2*i].relVal_ =  ((float)rel[i])/1024 * mouseSensitivity_;
     786      else
     787        halfAxes_[1 + 2*i].relVal_ = -((float)rel[i])/1024 * mouseSensitivity_;
    788788    }
    789789  }
     
    871871  }
    872872
    873   /**
    874     @brief Loader for the key bindings, managed by config values.
    875   */
    876   void KeyDetector::setConfigValues()
    877   {
    878     // keys
    879     for (unsigned int i = 0; i < nKeys_s; i++)
    880       readTrigger(keys_[i]);
    881     // mouse buttons
    882     for (unsigned int i = 0; i < nMouseButtons_s; i++)
    883       readTrigger(mouseButtons_[i]);
    884     // joy stick buttons
    885     for (unsigned int i = 0; i < nJoyStickButtons_s; i++)
    886       readTrigger(joyStickButtons_[i]);
    887     // half axes
    888     for (unsigned int i = 0; i < nHalfAxes_s; i++)
    889       readTrigger(halfAxes_[i]);
    890   }
    891 
    892873  void KeyDetector::readTrigger(Button& button)
    893874  {
    894     // binding has changed
    895     button.parse(paramCommandBuffer_);
    896875    SimpleCommand* cmd = new SimpleCommand();
    897876    cmd->evaluation_ = CommandExecutor::evaluate("storeKeyStroke " + button.name_);
  • code/branches/network/src/core/KeyBinder.h

    r1426 r1428  
    150150    void tickInput(float dt, const HandlerState& state);
    151151
    152     void readTrigger(Button& button);
     152    virtual void readTrigger(Button& button);
    153153
    154154    void keyPressed (const KeyEvent& evt);
     
    222222    //! mouse sensitivity if mouse input is derived
    223223    float mouseSensitivityDerived_;
     224    //! Whether or not to clip abslute mouse values to 1024
     225    bool bClipMouse_;
    224226  };
    225227
     
    231233    ~KeyDetector();
    232234    void loadBindings();
    233     void setConfigValues();
    234235
    235236  protected:
Note: See TracChangeset for help on using the changeset viewer.