Browse Source

Change KeyCode from an extern variable to a function

master
Riyyi 4 years ago
parent
commit
d5edec17eb
  1. 2
      inferno/src/inferno/application.cpp
  2. 13
      inferno/src/inferno/inputcodes.cpp
  3. 4
      inferno/src/inferno/inputcodes.h

2
inferno/src/inferno/application.cpp

@ -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);
}

13
inferno/src/inferno/inputcodes.cpp

@ -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);
}
}

4
inferno/src/inferno/inputcodes.h

@ -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);
}

Loading…
Cancel
Save