Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 28, 2008, 11:56:31 PM (16 years ago)
Author:
rgrieder
Message:
  • Fixed a bug in ConfigFileManager::getVectorSize(). If there were no entries, 1 was returned instead of 0.
  • Added getSctionName to the ConfigValueContainer
  • Bugfix in Button::clear()
  • Renamed some joy stick buttons and axes to have them sorted corrected in the config file
  • Removed annoying and useless "Key_084=" from keybindings.ini file (there were about a hundred of them)
  • Bugfix in KeyBinder: All the axes were inverted (which was then corrected in the ini file)
  • Also inverted rotateYaw in SpaceShip and Spectator because that actually corrected the bug from above ;)
  • Some small performance optimisation in InputManager
Location:
code/branches/presentation/src/core
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/core/ConfigFileManager.cc

    r2103 r2543  
    160160                if ((*it)->getIndex() > size)
    161161                    size = (*it)->getIndex();
    162         return (size + 1);
     162        if (size == 0)
     163            return 0;
     164        else
     165            return (size + 1);
    163166    }
    164167
  • code/branches/presentation/src/core/ConfigValueContainer.cc

    r2171 r2543  
    273273        {
    274274            this->valueVector_.clear();
    275             for (unsigned int i = 0; i < ConfigFileManager::getInstance().getVectorSize(this->type_, this->sectionname_, this->varname_); i++)
     275            unsigned int vectorSize = ConfigFileManager::getInstance().getVectorSize(this->type_, this->sectionname_, this->varname_);
     276            for (unsigned int i = 0; i < vectorSize; i++)
    276277            {
    277278                if (i < this->defvalueStringVector_.size())
  • code/branches/presentation/src/core/ConfigValueContainer.h

    r2171 r2543  
    109109            {
    110110                this->init(type, identifier, sectionname, varname);
    111                 this->initValue((V)defvalue);
     111                this->initValue(static_cast<V>(defvalue));
    112112            }
    113113
     
    217217            inline const std::string& getName() const
    218218                { return this->varname_; }
     219            /** @brief Retuns the name of the section this config value is in. */
     220            inline const std::string& getSectionName() const
     221                { return this->sectionname_; }
    219222            /** @brief Returns true if this config-value is a vector */
    220223            inline bool isVector() const
  • code/branches/presentation/src/core/input/Button.cc

    r2485 r2543  
    6363    }
    6464
     65    Button::~Button()
     66    {
     67        this->clear();
     68
     69        if (this->configContainer_)
     70            delete this->configContainer_;
     71    }
     72
    6573    void Button::clear()
    6674    {
     
    8189            }
    8290        }
    83 
    84         if (this->configContainer_)
    85             delete this->configContainer_;
    86         this->configContainer_ = 0;
    8791    }
    8892
  • code/branches/presentation/src/core/input/Button.h

    r2103 r2543  
    4949    public:
    5050        Button();
    51         virtual ~Button() { clear(); }
     51        virtual ~Button();
    5252        virtual void clear();
    5353        virtual bool addParamCommand(ParamCommand* command) { return false; }
  • code/branches/presentation/src/core/input/InputInterfaces.h

    r1887 r2543  
    378378        const char* const ByString[] =
    379379        {
    380             "Button0",       "Button1",       "Button2",       "Button3",
    381             "Button4",       "Button5",       "Button6",       "Button7",
    382             "Button8",       "Button9",       "Button10",      "Button11",
     380            "Button00",      "Button01",      "Button02",      "Button03",
     381            "Button04",      "Button05",      "Button06",      "Button07",
     382            "Button08",      "Button09",      "Button10",      "Button11",
    383383            "Button12",      "Button13",      "Button14",      "Button15",
    384384            "Button16",      "Button17",      "Button18",      "Button19",
     
    416416            "Slider0", "Slider1", "Slider2", "Slider3",
    417417            "Slider4", "Slider5", "Slider6", "Slider7",
    418             "Axis0",   "Axis1",   "Axis2",   "Axis3",
    419             "Axis4",   "Axis5",   "Axis6",   "Axis7",
    420             "Axis8",   "Axis9",   "Axis10",  "Axis11",
     418            "Axis00",  "Axis01",  "Axis02",  "Axis03",
     419            "Axis04",  "Axis05",  "Axis06",  "Axis07",
     420            "Axis08",  "Axis09",  "Axis10",  "Axis11",
    421421            "Axis12",  "Axis13",  "Axis14",  "Axis15"
    422422        };
  • code/branches/presentation/src/core/input/InputManager.cc

    r2103 r2543  
    6565    SetCommandLineSwitch(keyboard_no_grab);
    6666
    67     std::string InputManager::bindingCommmandString_s = "";
    6867    EmptyHandler InputManager::EMPTY_HANDLER;
    6968    InputManager* InputManager::singletonRef_s = 0;
     
    174173            if (joyStickSupport)
    175174                _initialiseJoySticks();
    176             // Do this anyway to also inform everyone if a joystick was detached.
     175            // Do this anyway to also inform everything when a joystick was detached.
    177176            _configureNumberOfJoySticks();
    178177
     
    492491            }
    493492        }
    494         singletonRef_s = 0;
     493
     494        singletonRef_s = 0;
    495495    }
    496496
     
    660660    /**
    661661    @brief
    662         Updates the InputManager. Tick is called by the Core class.
     662        Updates the states and the InputState situation.
    663663    @param dt
    664664        Delta time
     
    676676
    677677        // check for states to leave
    678         for (std::set<InputState*>::reverse_iterator rit = stateLeaveRequests_.rbegin();
    679             rit != stateLeaveRequests_.rend(); ++rit)
    680         {
    681             (*rit)->onLeave();
    682             // just to be sure that the state actually is registered
    683             assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
    684 
    685             activeStates_.erase((*rit)->getPriority());
    686             _updateActiveStates();
    687         }
    688         stateLeaveRequests_.clear();
     678        if (!stateLeaveRequests_.empty())
     679        {
     680            for (std::set<InputState*>::reverse_iterator rit = stateLeaveRequests_.rbegin();
     681                rit != stateLeaveRequests_.rend(); ++rit)
     682            {
     683                (*rit)->onLeave();
     684                // just to be sure that the state actually is registered
     685                assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
     686
     687                activeStates_.erase((*rit)->getPriority());
     688                _updateActiveStates();
     689            }
     690            stateLeaveRequests_.clear();
     691        }
    689692
    690693        // check for states to enter
    691         for (std::set<InputState*>::reverse_iterator rit = stateEnterRequests_.rbegin();
    692             rit != stateEnterRequests_.rend(); ++rit)
    693         {
    694             // just to be sure that the state actually is registered
    695             assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
    696 
    697             activeStates_[(*rit)->getPriority()] = (*rit);
    698             _updateActiveStates();
    699             (*rit)->onEnter();
    700         }
    701         stateEnterRequests_.clear();
     694        if (!stateEnterRequests_.empty())
     695        {
     696            for (std::set<InputState*>::reverse_iterator rit = stateEnterRequests_.rbegin();
     697                rit != stateEnterRequests_.rend(); ++rit)
     698            {
     699                // just to be sure that the state actually is registered
     700                assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
     701
     702                activeStates_[(*rit)->getPriority()] = (*rit);
     703                _updateActiveStates();
     704                (*rit)->onEnter();
     705            }
     706            stateEnterRequests_.clear();
     707        }
    702708
    703709        // check for states to destroy
    704         for (std::set<InputState*>::reverse_iterator rit = stateDestroyRequests_.rbegin();
    705             rit != stateDestroyRequests_.rend(); ++rit)
    706         {
    707             _destroyState((*rit));
    708         }
    709         stateDestroyRequests_.clear();
     710        if (!stateDestroyRequests_.empty())
     711        {
     712            for (std::set<InputState*>::reverse_iterator rit = stateDestroyRequests_.rbegin();
     713                rit != stateDestroyRequests_.rend(); ++rit)
     714            {
     715                _destroyState((*rit));
     716            }
     717            stateDestroyRequests_.clear();
     718        }
    710719
    711720        // check whether a state has changed its EMPTY_HANDLER situation
     
    11241133
    11251134        // keep in mind that the first 8 axes are reserved for the sliders
    1126         _fireAxis(iJoyStick, axis + 8, arg.state.mAxes[axis].abs);
     1135        _fireAxis(iJoyStick, axis + sliderAxes, arg.state.mAxes[axis].abs);
    11271136
    11281137        return true;
  • code/branches/presentation/src/core/input/InputManager.h

    r2102 r2543  
    136136    public: // variables
    137137        static EmptyHandler                 EMPTY_HANDLER;
     138        static const unsigned int           sliderAxes = 8;
    138139
    139140    private: // functions
     
    192193        SimpleInputState*                   stateEmpty_;
    193194        ExtendedInputState*                 stateMaster_;          //!< Always active master input state
    194         KeyDetector*                        keyDetector_;        //!< KeyDetector instance
     195        KeyDetector*                        keyDetector_;          //!< KeyDetector instance
    195196        InputBuffer*                        calibratorCallbackBuffer_;
    196197
     
    223224        std::vector<std::vector<JoyStickButtonCode::ByEnum> >  joyStickButtonsDown_;
    224225
    225         static std::string                  bindingCommmandString_s;
     226
    226227        static InputManager*                singletonRef_s;
    227228    };
  • code/branches/presentation/src/core/input/KeyBinder.cc

    r2103 r2543  
    3333
    3434#include "KeyBinder.h"
     35
    3536#include <fstream>
    3637#include <string>
     38
    3739#include "util/Convert.h"
    3840#include "util/Debug.h"
     
    6668            std::string keyname = KeyCode::ByString[i];
    6769            if (!keyname.empty())
    68             {
    6970                keys_[i].name_ = std::string("Key") + keyname;
    70             }
    7171            else
    72             {
    73                 // some keys have name "" because the code is not occupied by OIS
    74                 // Use "Key_" plus the number as name to put it at the end of the config file section
    75                 std::string number = convertToString(i);
    76                 if (i < 100)
    77                     number.insert(0, "0");
    78                 keys_[i].name_ = std::string("Key_") + number;
    79             }
     72                keys_[i].name_ = "";
    8073            keys_[i].paramCommandBuffer_ = &paramCommandBuffer_;
    8174            keys_[i].groupName_ = "Keys";
     
    9790        for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
    9891        {
    99             mouseAxes_[i].name_ = std::string("Mouse") + MouseAxisCode::ByString[i >> 1];
     92            mouseAxes_[i].name_ = std::string("Mouse") + MouseAxisCode::ByString[i / 2];
    10093            if (i & 1)
    10194                mouseAxes_[i].name_ += "Pos";
     
    224217        allHalfAxes_.clear();
    225218
     219        // Note: Don't include the dummy keys which don't actually exist in OIS but have a number
    226220        for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++)
    227             allButtons_[keys_[i].name_] = keys_ + i;
     221            if (!keys_[i].name_.empty())
     222                allButtons_[keys_[i].name_] = keys_ + i;
    228223        for (unsigned int i = 0; i < numberOfMouseButtons_; i++)
    229224            allButtons_[mouseButtons_[i].name_] = mouseButtons_ + i;
     
    327322        if (bDeriveMouseInput_)
    328323        {
    329             // only update when derive dt has passed
     324            // only update when derivation dt has passed
    330325            if (deriveTime_ > derivePeriod_)
    331326            {
    332327                for (int i = 0; i < 2; i++)
    333328                {
    334                     if (mouseRelative_[i] > 0)
     329                    if (mouseRelative_[i] < 0)
    335330                    {
    336331                        mouseAxes_[2*i + 0].absVal_
    337                             =  mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;
     332                            = -mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;
    338333                        mouseAxes_[2*i + 1].absVal_ = 0.0f;
    339334                    }
    340                     else if (mouseRelative_[i] < 0)
     335                    else if (mouseRelative_[i] > 0)
    341336                    {
    342337                        mouseAxes_[2*i + 0].absVal_ = 0.0f;
    343338                        mouseAxes_[2*i + 1].absVal_
    344                             = -mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;
     339                            =  mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;
    345340                    }
    346341                    else
     
    363358            // Why dividing relative value by dt? The reason lies in the simple fact, that when you
    364359            // press a button that has relative movement, that value has to be multiplied by dt to be
    365             // frame rate independant. This can easily (and only) be done in tickInput(float).
     360            // frame rate independent. This can easily (and only) be done in tickInput(float).
    366361            // Hence we need to divide by dt here for the mouse to compensate, because the relative
    367362            // move movements have nothing to do with dt.
     
    441436            for (int i = 0; i < 2; i++)
    442437            {
    443                 if (rel[i]) // performance opt. if rel[i] == 0
     438                if (rel[i]) // performance opt. for the case that rel[i] == 0
    444439                {
    445440                    // write absolute values
     
    454449                        mousePosition_[i] = -mouseClippingSize_;
    455450
    456                     if (mousePosition_[i] >= 0)
     451                    if (mousePosition_[i] < 0)
    457452                    {
    458                         mouseAxes_[2*i + 0].absVal_ =   mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_;
     453                        mouseAxes_[2*i + 0].absVal_ =  -mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_;
    459454                        mouseAxes_[2*i + 1].absVal_ =  0.0f;
    460455                    }
     
    462457                    {
    463458                        mouseAxes_[2*i + 0].absVal_ =  0.0f;
    464                         mouseAxes_[2*i + 1].absVal_ =  -mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_;
     459                        mouseAxes_[2*i + 1].absVal_ =   mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_;
    465460                    }
    466461                }
     
    471466        for (int i = 0; i < 2; i++)
    472467        {
    473             if (rel[i] > 0)
    474                 mouseAxes_[0 + 2*i].relVal_ =  ((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_;
     468            if (rel[i] < 0)
     469                mouseAxes_[0 + 2*i].relVal_ = -((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_;
    475470            else
    476                 mouseAxes_[1 + 2*i].relVal_ = -((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_;
     471                mouseAxes_[1 + 2*i].relVal_ =  ((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_;
    477472        }
    478473    }
     
    484479    void KeyBinder::mouseScrolled(int abs, int rel)
    485480    {
    486         if (rel > 0)
    487             for (int i = 0; i < rel/mouseWheelStepSize_; i++)
     481        if (rel < 0)
     482            for (int i = 0; i < -rel/mouseWheelStepSize_; i++)
    488483                mouseButtons_[8].execute(KeybindMode::OnPress, ((float)abs)/mouseWheelStepSize_);
    489484        else
    490             for (int i = 0; i < -rel/mouseWheelStepSize_; i++)
     485            for (int i = 0; i < rel/mouseWheelStepSize_; i++)
    491486                mouseButtons_[9].execute(KeybindMode::OnPress, ((float)abs)/mouseWheelStepSize_);
    492487    }
     
    495490    {
    496491        int i = axis * 2;
    497         if (value >= 0)
    498         {
    499             joyStickAxes_[joyStickID][i].absVal_ = value;
    500             joyStickAxes_[joyStickID][i].relVal_ = value;
     492        if (value < 0)
     493        {
     494            joyStickAxes_[joyStickID][i].absVal_ = -value;
     495            joyStickAxes_[joyStickID][i].relVal_ = -value;
    501496            joyStickAxes_[joyStickID][i].hasChanged_ = true;
    502497            if (joyStickAxes_[joyStickID][i + 1].absVal_ > 0.0f)
     
    509504        else
    510505        {
    511             joyStickAxes_[joyStickID][i + 1].absVal_ = -value;
    512             joyStickAxes_[joyStickID][i + 1].relVal_ = -value;
     506            joyStickAxes_[joyStickID][i + 1].absVal_ = value;
     507            joyStickAxes_[joyStickID][i + 1].relVal_ = value;
    513508            joyStickAxes_[joyStickID][i + 1].hasChanged_ = true;
    514509            if (joyStickAxes_[joyStickID][i].absVal_ > 0.0f)
  • code/branches/presentation/src/core/input/KeyBinder.h

    r2103 r2543  
    3939
    4040#include <vector>
     41#include <cassert>
     42
    4143#include "InputInterfaces.h"
    4244#include "Button.h"
     
    4446#include "InputCommands.h"
    4547#include "JoyStickDeviceNumberListener.h"
    46 #include "core/ConfigFileManager.h"
    4748
    4849namespace orxonox
     
    171172
    172173    inline void KeyBinder::keyPressed (const KeyEvent& evt)
    173     { keys_[evt.key].execute(KeybindMode::OnPress); }
     174    { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnPress); }
    174175
    175176    inline void KeyBinder::keyReleased(const KeyEvent& evt)
    176     { keys_[evt.key].execute(KeybindMode::OnRelease); }
     177    { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnRelease); }
    177178
    178179    inline void KeyBinder::keyHeld    (const KeyEvent& evt)
    179     { keys_[evt.key].execute(KeybindMode::OnHold); }
     180    { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnHold); }
    180181
    181182
Note: See TracChangeset for help on using the changeset viewer.