mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
84 lines
1.7 KiB
C++
84 lines
1.7 KiB
C++
/*
|
|
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 <unordered_map>
|
|
#include <array>
|
|
#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<command_setup> commandsetup_sequence;
|
|
typedef std::unordered_map<int, user_command> 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<char, GLFW_KEY_LAST + 1> m_keys;
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|