Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 30, 2010, 12:13:33 PM (15 years ago)
Author:
rgrieder
Message:

Implemented indirect function calls for input events. It simply means that when you hit the mouse button, the resulting call stack will not include OIS nor an InputState anymore.
—> You can reload the InputManager (happens when mouse mode changes) or even modify the InputState situation (like InputManager::leaveState or even destroyState) directly now.
—> I was able to remove the indirect execution of following methods in the InputManager: leaveInputState, enterInputState, destroyInputState and reload.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamestate/src/libraries/core/input/InputState.h

    r6656 r6657  
    3535#include <string>
    3636#include <vector>
     37#include <boost/function.hpp>
     38#include <boost/bind.hpp>
    3739
    3840#include "util/TriBool.h"
    3941#include "InputHandler.h"
     42#include "InputManager.h"
    4043#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__)))
    4147
    4248namespace orxonox
     
    128134
    129135        //! Generic function that distributes all 9 button events
    130         template <typename EventType, class Traits>
    131         void buttonEvent(unsigned int device, const typename Traits::ButtonTypeParam button);
     136        template <typename EventType, class ButtonTypeParam>
     137        void buttonEvent(unsigned int device, ButtonTypeParam button);
    132138
    133139        //! Event handler
     
    174180        for (unsigned int i = 0; i < handlers_.size(); ++i)
    175181            if (handlers_[i] != NULL)
    176                 handlers_[i]->allDevicesUpdated(dt);
     182                INPUT_STATE_PUSH_CALL(i, allDevicesUpdated, dt);
    177183    }
    178184
     
    183189        case InputDeviceEnumerator::Keyboard:
    184190            if (handlers_[keyboardIndex_s] != NULL)
    185                 handlers_[keyboardIndex_s]->keyboardUpdated(dt);
     191                INPUT_STATE_PUSH_CALL(keyboardIndex_s, keyboardUpdated, dt);
    186192            break;
    187193
    188194        case InputDeviceEnumerator::Mouse:
    189195            if (handlers_[mouseIndex_s] != NULL)
    190                 handlers_[mouseIndex_s]->mouseUpdated(dt);
     196                INPUT_STATE_PUSH_CALL(mouseIndex_s, mouseUpdated, dt);
    191197            break;
    192198
    193199        default: // joy sticks
    194200            if (handlers_[device] != NULL)
    195                 handlers_[device]->joyStickUpdated(device - firstJoyStickIndex_s, dt);
     201                INPUT_STATE_PUSH_CALL(device, joyStickUpdated, device - firstJoyStickIndex_s, dt);
    196202            break;
    197203        }
    198204    }
    199205
    200     template <typename EventType, class Traits>
    201     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)
    202208    {
    203209        assert(device < handlers_.size());
    204210        if (handlers_[device] != NULL)
    205             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        }
    206216    }
    207217
     
    209219    {
    210220        if (handlers_[mouseIndex_s] != NULL)
    211             handlers_[mouseIndex_s]->mouseMoved(abs, rel, clippingSize);
     221            INPUT_STATE_PUSH_CALL(mouseIndex_s, mouseMoved, abs, rel, clippingSize);
    212222    }
    213223
     
    215225    {
    216226        if (handlers_[mouseIndex_s] != NULL)
    217             handlers_[mouseIndex_s]->mouseScrolled(abs, rel);
     227            INPUT_STATE_PUSH_CALL(mouseIndex_s, mouseScrolled, abs, rel);
    218228    }
    219229
     
    222232        assert(device < handlers_.size());
    223233        if (handlers_[device] != NULL)
    224             handlers_[device]->axisMoved(device - firstJoyStickIndex_s, axis, value);
     234            INPUT_STATE_PUSH_CALL(device, axisMoved, device - firstJoyStickIndex_s, axis, value);
    225235    }
    226236}
Note: See TracChangeset for help on using the changeset viewer.