/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #pragma once #include #include #include "command.h" class keyboard_input { public: // constructors keyboard_input() { default_bindings(); } // methods bool init() { return recall_bindings(); } bool recall_bindings(); bool key( int const Key, int const Action ); void poll(); inline user_command const command() const { return m_command; } private: // types enum keymodifier : int { shift = 0x10000, control = 0x20000 }; struct command_setup { int binding; }; typedef std::vector commandsetup_sequence; typedef std::unordered_map usercommand_map; struct bindings_cache { int forward{ -1 }; int back{ -1 }; int left{ -1 }; int right{ -1 }; int up{ -1 }; int down{ -1 }; }; // methods void default_bindings(); void bind(); bool is_movement_key( int const Key ) const; // members commandsetup_sequence m_commands; user_command m_command { user_command::none }; // last, if any, issued command usercommand_map m_bindings; command_relay m_relay; bool m_shift { false }; bool m_ctrl { false }; bindings_cache m_bindingscache; glm::vec2 m_movementhorizontal { 0.f }; float m_movementvertical { 0.f }; std::array m_keys; }; //---------------------------------------------------------------------------