Change KeyCode from an extern variable to a function

This commit is contained in:
Riyyi
2021-01-02 03:26:28 +01:00
parent b8f2f0fe31
commit d5edec17eb
3 changed files with 14 additions and 5 deletions
+1 -1
View File
@@ -170,7 +170,7 @@ namespace Inferno {
e.getKey());
// Stop the main loop on 'Escape' keypress
if (e.getKey() == KeyCode["GLFW_KEY_ESCAPE"]) {
if (e.getKey() == KeyCode("GLFW_KEY_ESCAPE")) {
m_window->setShouldClose(true);
}
+12 -1
View File
@@ -1,10 +1,13 @@
#include <unordered_map> // std::unordered_map
#include <GLFW/glfw3.h>
#include "inferno/assertions.h"
#include "inferno/inputcodes.h"
namespace Inferno {
std::unordered_map<const char*, int> KeyCode ({
static std::unordered_map<const char*, int> keys ({
{ MAP_KEY(GLFW_KEY_UNKNOWN) },
{ MAP_KEY(GLFW_KEY_SPACE) },
{ MAP_KEY(GLFW_KEY_APOSTROPHE) },
@@ -128,4 +131,12 @@ namespace Inferno {
{ MAP_KEY(GLFW_KEY_MENU) },
});
// -----------------------------------------
int KeyCode(const char* name)
{
ASSERT(keys.find(name) != keys.end(), "Could not find KeyCode");
return keys.at(name);
}
}
+1 -3
View File
@@ -3,11 +3,9 @@
#define MAP_KEY(key) #key, key
#include <unordered_map> // std::unordered_map
namespace Inferno {
extern std::unordered_map<const char*, int> KeyCode;
int KeyCode(const char* name);
}