Change KeyCode from an extern variable to a function
This commit is contained in:
@@ -170,7 +170,7 @@ namespace Inferno {
|
|||||||
e.getKey());
|
e.getKey());
|
||||||
|
|
||||||
// Stop the main loop on 'Escape' keypress
|
// 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);
|
m_window->setShouldClose(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
|
#include <unordered_map> // std::unordered_map
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#include "inferno/assertions.h"
|
||||||
#include "inferno/inputcodes.h"
|
#include "inferno/inputcodes.h"
|
||||||
|
|
||||||
namespace Inferno {
|
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_UNKNOWN) },
|
||||||
{ MAP_KEY(GLFW_KEY_SPACE) },
|
{ MAP_KEY(GLFW_KEY_SPACE) },
|
||||||
{ MAP_KEY(GLFW_KEY_APOSTROPHE) },
|
{ MAP_KEY(GLFW_KEY_APOSTROPHE) },
|
||||||
@@ -128,4 +131,12 @@ namespace Inferno {
|
|||||||
{ MAP_KEY(GLFW_KEY_MENU) },
|
{ MAP_KEY(GLFW_KEY_MENU) },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// -----------------------------------------
|
||||||
|
|
||||||
|
int KeyCode(const char* name)
|
||||||
|
{
|
||||||
|
ASSERT(keys.find(name) != keys.end(), "Could not find KeyCode");
|
||||||
|
return keys.at(name);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,9 @@
|
|||||||
|
|
||||||
#define MAP_KEY(key) #key, key
|
#define MAP_KEY(key) #key, key
|
||||||
|
|
||||||
#include <unordered_map> // std::unordered_map
|
|
||||||
|
|
||||||
namespace Inferno {
|
namespace Inferno {
|
||||||
|
|
||||||
extern std::unordered_map<const char*, int> KeyCode;
|
int KeyCode(const char* name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user