bindings, controls.json file
This commit is contained in:
@@ -14,6 +14,7 @@ bool Events::_cursor_locked = false;
|
||||
bool Events::_cursor_started = false;
|
||||
std::vector<uint> Events::codepoints;
|
||||
std::vector<int> Events::pressedKeys;
|
||||
std::unordered_map<std::string, Binding> Events::bindings;
|
||||
|
||||
int Events::initialize(){
|
||||
_keys = new bool[1032];
|
||||
@@ -64,4 +65,47 @@ void Events::pullEvents(){
|
||||
codepoints.clear();
|
||||
pressedKeys.clear();
|
||||
glfwPollEvents();
|
||||
|
||||
for (auto& entry : bindings) {
|
||||
auto& binding = entry.second;
|
||||
binding.justChange = false;
|
||||
|
||||
bool newstate = false;
|
||||
switch (binding.type) {
|
||||
case inputtype::keyboard: newstate = pressed(binding.code); break;
|
||||
case inputtype::button: newstate = clicked(binding.code); break;
|
||||
}
|
||||
|
||||
if (newstate) {
|
||||
if (!binding.state) {
|
||||
binding.state = true;
|
||||
binding.justChange = true;
|
||||
}
|
||||
} else {
|
||||
if (binding.state) {
|
||||
binding.state = false;
|
||||
binding.justChange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Events::bind(std::string name, inputtype type, int code) {
|
||||
bindings[name] = {type, code, false, false};
|
||||
}
|
||||
|
||||
bool Events::active(std::string name) {
|
||||
const auto& found = bindings.find(name);
|
||||
if (found == bindings.end()) {
|
||||
return false;
|
||||
}
|
||||
return found->second.active();
|
||||
}
|
||||
|
||||
bool Events::jactive(std::string name) {
|
||||
const auto& found = bindings.find(name);
|
||||
if (found == bindings.end()) {
|
||||
return false;
|
||||
}
|
||||
return found->second.jactive();
|
||||
}
|
||||
|
||||
@@ -3,8 +3,32 @@
|
||||
|
||||
#include "Window.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
typedef unsigned int uint;
|
||||
|
||||
enum class inputtype {
|
||||
keyboard,
|
||||
button,
|
||||
};
|
||||
|
||||
struct Binding {
|
||||
inputtype type;
|
||||
int code;
|
||||
bool state = false;
|
||||
bool justChange = false;
|
||||
|
||||
bool active() const {
|
||||
return state;
|
||||
}
|
||||
|
||||
bool jactive() const {
|
||||
return state && justChange;
|
||||
}
|
||||
};
|
||||
|
||||
class Events {
|
||||
public:
|
||||
static bool* _keys;
|
||||
@@ -18,6 +42,7 @@ public:
|
||||
static bool _cursor_started;
|
||||
static std::vector<uint> codepoints;
|
||||
static std::vector<int> pressedKeys;
|
||||
static std::unordered_map<std::string, Binding> bindings;
|
||||
|
||||
static int initialize();
|
||||
static void finalize();
|
||||
@@ -30,6 +55,10 @@ public:
|
||||
static bool jclicked(int button);
|
||||
|
||||
static void toggleCursor();
|
||||
|
||||
static void bind(std::string name, inputtype type, int code);
|
||||
static bool active(std::string name);
|
||||
static bool jactive(std::string name);
|
||||
};
|
||||
|
||||
#define _MOUSE_BUTTONS 1024
|
||||
|
||||
Reference in New Issue
Block a user