- Timestamp:
- Mar 30, 2010, 12:13:33 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gamestate/src/libraries/core/input/InputState.h
r6656 r6657 35 35 #include <string> 36 36 #include <vector> 37 #include <boost/function.hpp> 38 #include <boost/bind.hpp> 37 39 38 40 #include "util/TriBool.h" 39 41 #include "InputHandler.h" 42 #include "InputManager.h" 40 43 #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__))) 41 47 42 48 namespace orxonox … … 128 134 129 135 //! 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); 132 138 133 139 //! Event handler … … 174 180 for (unsigned int i = 0; i < handlers_.size(); ++i) 175 181 if (handlers_[i] != NULL) 176 handlers_[i]->allDevicesUpdated(dt);182 INPUT_STATE_PUSH_CALL(i, allDevicesUpdated, dt); 177 183 } 178 184 … … 183 189 case InputDeviceEnumerator::Keyboard: 184 190 if (handlers_[keyboardIndex_s] != NULL) 185 handlers_[keyboardIndex_s]->keyboardUpdated(dt);191 INPUT_STATE_PUSH_CALL(keyboardIndex_s, keyboardUpdated, dt); 186 192 break; 187 193 188 194 case InputDeviceEnumerator::Mouse: 189 195 if (handlers_[mouseIndex_s] != NULL) 190 handlers_[mouseIndex_s]->mouseUpdated(dt);196 INPUT_STATE_PUSH_CALL(mouseIndex_s, mouseUpdated, dt); 191 197 break; 192 198 193 199 default: // joy sticks 194 200 if (handlers_[device] != NULL) 195 handlers_[device]->joyStickUpdated(device - firstJoyStickIndex_s, dt);201 INPUT_STATE_PUSH_CALL(device, joyStickUpdated, device - firstJoyStickIndex_s, dt); 196 202 break; 197 203 } 198 204 } 199 205 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) 202 208 { 203 209 assert(device < handlers_.size()); 204 210 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 } 206 216 } 207 217 … … 209 219 { 210 220 if (handlers_[mouseIndex_s] != NULL) 211 handlers_[mouseIndex_s]->mouseMoved(abs, rel, clippingSize);221 INPUT_STATE_PUSH_CALL(mouseIndex_s, mouseMoved, abs, rel, clippingSize); 212 222 } 213 223 … … 215 225 { 216 226 if (handlers_[mouseIndex_s] != NULL) 217 handlers_[mouseIndex_s]->mouseScrolled(abs, rel);227 INPUT_STATE_PUSH_CALL(mouseIndex_s, mouseScrolled, abs, rel); 218 228 } 219 229 … … 222 232 assert(device < handlers_.size()); 223 233 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); 225 235 } 226 236 }
Note: See TracChangeset
for help on using the changeset viewer.