diff options
Diffstat (limited to 'source/30-game/main.cpp')
-rw-r--r-- | source/30-game/main.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/source/30-game/main.cpp b/source/30-game/main.cpp index d98f225..59d6fea 100644 --- a/source/30-game/main.cpp +++ b/source/30-game/main.cpp @@ -3,6 +3,7 @@ #include "AppConfig.hpp" #include "CommonVertexIndex.hpp" #include "ImGuiGuizmo.hpp" +#include "Input.hpp" #include "Ires.hpp" #include "Level.hpp" #include "Material.hpp" @@ -36,6 +37,23 @@ void GlfwErrorCallback(int error, const char* description) { fprintf(stderr, "[GLFW] Error %d: %s\n", error, description); } +void GlfwKeyboardCallback(GLFWkeyboard* keyboard, int event) { + if (InputState::instance == nullptr) { + // Called before initialization, skipping because we'll do a collect pass anyways when initializing + return; + } + + switch (event) { + case GLFW_CONNECTED: { + InputState::instance->ConnectKeyboard(keyboard); + } break; + + case GLFW_DISCONNECTED: { + InputState::instance->DisconnectKeyboard(keyboard); + } break; + } +} + void OpenGLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) { fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message); } @@ -194,6 +212,7 @@ int main(int argc, char* argv[]) { } glfwSetErrorCallback(&GlfwErrorCallback); + glfwSetKeyboardCallback(&GlfwKeyboardCallback); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); @@ -276,6 +295,16 @@ int main(int argc, char* argv[]) { ImGui_ImplOpenGL2_Init(); } + InputState::instance = new InputState(); + { + int count; + GLFWkeyboard** list = glfwGetKeyboards(&count); + for (int i = 0; i < count; ++i) { + GLFWkeyboard* keyboard = list[i]; + InputState::instance->ConnectKeyboard(keyboard); + } + } + IresManager::instance = new IresManager(); IresManager::instance->DiscoverFilesDesignatedLocation(); |