Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 31, 2010, 1:05:28 AM (15 years ago)
Author:
rgrieder
Message:

Merged revisions 6621-6661 to gamestates2.

Location:
code/branches/gamestates2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamestates2

  • code/branches/gamestates2/src/libraries/core/input/InputState.h

    r6595 r6662  
    3535#include <string>
    3636#include <vector>
    37 
    38 #include "util/OrxEnum.h"
     37#include <boost/function.hpp>
     38#include <boost/bind.hpp>
     39
    3940#include "util/TriBool.h"
    4041#include "InputHandler.h"
     42#include "InputManager.h"
    4143#include "JoyStickQuantityListener.h"
     44
     45#define INPUT_STATE_PUSH_CALL(deviceIndex, functionName, ...) \
     46    InputManager::getInstance().pushCall(boost::function<void ()>(boost::bind(&InputHandler::functionName, handlers_[deviceIndex], __VA_ARGS__)))
    4247
    4348namespace orxonox
    4449{
    45     //! Enumeration wrapper for input state priorities
    46     struct InputStatePriority : OrxEnum<InputStatePriority>
    47     {
    48         OrxEnumConstructors(InputStatePriority);
    49 
    50         static const int Empty        = -1;
    51         static const int Dynamic      = 0;
    52 
    53         static const int HighPriority = 1000;
    54         static const int Console      = HighPriority + 0;
    55         static const int Calibrator   = HighPriority + 1;
    56         static const int Detector     = HighPriority + 2;
    57     };
    58 
    59 
    6050    /**
    6151    @brief
     
    144134
    145135        //! Generic function that distributes all 9 button events
    146         template <typename EventType, class Traits>
    147         void buttonEvent(unsigned int device, const typename Traits::ButtonTypeParam button);
     136        template <typename EventType, class ButtonTypeParam>
     137        void buttonEvent(unsigned int device, ButtonTypeParam button);
    148138
    149139        //! Event handler
     
    190180        for (unsigned int i = 0; i < handlers_.size(); ++i)
    191181            if (handlers_[i] != NULL)
    192                 handlers_[i]->allDevicesUpdated(dt);
     182                INPUT_STATE_PUSH_CALL(i, allDevicesUpdated, dt);
    193183    }
    194184
     
    199189        case InputDeviceEnumerator::Keyboard:
    200190            if (handlers_[keyboardIndex_s] != NULL)
    201                 handlers_[keyboardIndex_s]->keyboardUpdated(dt);
     191                INPUT_STATE_PUSH_CALL(keyboardIndex_s, keyboardUpdated, dt);
    202192            break;
    203193
    204194        case InputDeviceEnumerator::Mouse:
    205195            if (handlers_[mouseIndex_s] != NULL)
    206                 handlers_[mouseIndex_s]->mouseUpdated(dt);
     196                INPUT_STATE_PUSH_CALL(mouseIndex_s, mouseUpdated, dt);
    207197            break;
    208198
    209199        default: // joy sticks
    210200            if (handlers_[device] != NULL)
    211                 handlers_[device]->joyStickUpdated(device - firstJoyStickIndex_s, dt);
     201                INPUT_STATE_PUSH_CALL(device, joyStickUpdated, device - firstJoyStickIndex_s, dt);
    212202            break;
    213203        }
    214204    }
    215205
    216     template <typename EventType, class Traits>
    217     FORCEINLINE void InputState::buttonEvent(unsigned int device, const typename Traits::ButtonTypeParam button)
     206    template <typename EventType, class ButtonTypeParam>
     207    FORCEINLINE void InputState::buttonEvent(unsigned int device, typename ButtonTypeParam button)
    218208    {
    219209        assert(device < handlers_.size());
    220210        if (handlers_[device] != NULL)
    221             handlers_[device]->buttonEvent(device, button, EventType());
     211        {
     212            // We have to store the function pointer to tell the compiler about its actual type because of overloading
     213            void (InputHandler::*function)(unsigned int, ButtonTypeParam, EventType) = &InputHandler::buttonEvent<ButtonTypeParam>;
     214            InputManager::getInstance().pushCall(boost::function<void ()>(boost::bind(function, handlers_[device], device, button, EventType())));
     215        }
    222216    }
    223217
     
    225219    {
    226220        if (handlers_[mouseIndex_s] != NULL)
    227             handlers_[mouseIndex_s]->mouseMoved(abs, rel, clippingSize);
     221            INPUT_STATE_PUSH_CALL(mouseIndex_s, mouseMoved, abs, rel, clippingSize);
    228222    }
    229223
     
    231225    {
    232226        if (handlers_[mouseIndex_s] != NULL)
    233             handlers_[mouseIndex_s]->mouseScrolled(abs, rel);
     227            INPUT_STATE_PUSH_CALL(mouseIndex_s, mouseScrolled, abs, rel);
    234228    }
    235229
     
    238232        assert(device < handlers_.size());
    239233        if (handlers_[device] != NULL)
    240             handlers_[device]->axisMoved(device - firstJoyStickIndex_s, axis, value);
     234            INPUT_STATE_PUSH_CALL(device, axisMoved, device - firstJoyStickIndex_s, axis, value);
    241235    }
    242236}
Note: See TracChangeset for help on using the changeset viewer.