/* This file is part of Daydream Engine. Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung Daydream Engine is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Daydream Engine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Daydream Engine. If not, see . */ #ifndef InputSystem_h__ #define InputSystem_h__ #include #include #include "Core/System.h" #include "Core/EKeyUp.h" #include "Core/EKeyDown.h" #include "Core/EMousePress.h" #include "Core/EMouseRelease.h" #include "Core/EGamepadAxis.h" #include "Core/EGamepadButton.h" #include "Core/Util/EnumClassHash.h" #include "EBindKey.h" #include "EBindMouseButton.h" #include "EBindGamepadAxis.h" #include "EBindGamepadButton.h" #include "EInputCommand.h" namespace dd { namespace Systems { class InputSystem : public System { public: InputSystem(World* world, std::shared_ptr eventBroker) : System(world, eventBroker) { } void RegisterComponents(ComponentFactory* cf) override; void Initialize() override; void Update(double dt) override; private: std::unordered_map> m_CommandKeyboardValues; // command string -> keyboard key value for command std::unordered_map> m_CommandMouseButtonValues; // command string -> mouse button value for command std::unordered_map> m_CommandGamepadAxisValues; // command string -> gamepad axis value for command std::unordered_map> m_CommandGamepadButtonValues; // command string -> gamepad button value for command // Input binding tables std::unordered_multimap> m_KeyBindings; // GLFW_KEY... -> command string & value std::unordered_multimap> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string std::unordered_multimap, EnumClassHash> m_GamepadAxisBindings; // Gamepad::Axis -> command string & value std::unordered_multimap, EnumClassHash> m_GamepadButtonBindings; // Gamepad::Button -> command string // Input events EventRelay m_EKeyDown; bool OnKeyDown(const Events::KeyDown &event); EventRelay m_EKeyUp; bool OnKeyUp(const Events::KeyUp &event); EventRelay m_EMousePress; bool OnMousePress(const Events::MousePress &event); EventRelay m_EMouseRelease; bool OnMouseRelease(const Events::MouseRelease &event); EventRelay m_EGamepadAxis; bool OnGamepadAxis(const Events::GamepadAxis &event); EventRelay m_EGamepadButtonDown; bool OnGamepadButtonDown(const Events::GamepadButtonDown &event); EventRelay m_EGamepadButtonUp; bool OnGamepadButtonUp(const Events::GamepadButtonUp &event); // Input binding events EventRelay m_EBindKey; bool OnBindKey(const Events::BindKey &event); EventRelay m_EBindMouseButton; bool OnBindMouseButton(const Events::BindMouseButton &event); EventRelay m_EBindGamepadAxis; bool OnBindGamepadAxis(const Events::BindGamepadAxis &event); EventRelay m_EBindGamepadButton; bool OnBindGamepadButton(const Events::BindGamepadButton &event); float GetCommandTotalValue(std::string command); void PublishCommand(int playerID, std::string command, float value); }; } } #endif // InputSystem_h__