diff --git a/Editor/src/EditorLayer.cpp b/Editor/src/EditorLayer.cpp index 2b8d8425..37f3672b 100644 --- a/Editor/src/EditorLayer.cpp +++ b/Editor/src/EditorLayer.cpp @@ -3,6 +3,8 @@ #include "Windows/EditorInterface.h" #include "Misc/GizmoDrawer.h" +#include "src/Core/Input.h" + #include @@ -65,6 +67,8 @@ void EditorLayer::OnUpdate() m_EditorInterface->Draw(); m_EditorInterface->Update(Nuake::Engine::GetTimestep()); Nuake::Engine::EndDraw(); + + Nuake::Input::Update(); } void EditorLayer::OnDetach() diff --git a/Editor/src/NewEditor.cpp b/Editor/src/NewEditor.cpp index 0dbc2f2d..35d8bb0f 100644 --- a/Editor/src/NewEditor.cpp +++ b/Editor/src/NewEditor.cpp @@ -31,7 +31,7 @@ namespace Nuake bool dragging2 = false; void NewEditor::Update(Timestep ts) { - if (Input::IsKeyPressed(GLFW_KEY_F1)) + if (Input::IsKeyPressed(Key::F1)) { m_UserInterface->Reload(); FetchNodes(); diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 05140942..ccbbe035 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -327,7 +327,7 @@ namespace Nuake { if (Engine::IsPlayMode() && Engine::GetTimeScale() != 0.0f) { - if (ImGui::Button(ICON_FA_PAUSE, ImVec2(30, 30)) || (Input::IsKeyDown(GLFW_KEY_F5))) + if (ImGui::Button(ICON_FA_PAUSE, ImVec2(30, 30)) || (Input::IsKeyPressed(Key::F6))) { Engine::SetGameState(GameState::Paused); @@ -336,7 +336,7 @@ namespace Nuake { } else { - if (ImGui::Button(ICON_FA_PLAY, ImVec2(30, 30))) + if (ImGui::Button(ICON_FA_PLAY, ImVec2(30, 30)) || Input::IsKeyPressed(Key::F5)) { if (Engine::GetGameState() == GameState::Paused) { @@ -380,7 +380,7 @@ namespace Nuake { ImGui::BeginDisabled(); } - if ((ImGui::Button(ICON_FA_STOP, ImVec2(30, 30)) || Input::IsKeyPressed(GLFW_KEY_F5)) && Engine::IsPlayMode()) + if ((ImGui::Button(ICON_FA_STOP, ImVec2(30, 30)) || Input::IsKeyPressed(Key::F5)) && Engine::IsPlayMode()) { Engine::ExitPlayMode(); @@ -1967,17 +1967,17 @@ namespace Nuake { if (ImGui::Begin("Example: Simple overlay", &m_ShowOverlay, window_flags)) { ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 100); - if (ImGui::Button(ICON_FA_ARROWS_ALT) || Input::IsKeyDown(GLFW_KEY_W)) + if (ImGui::Button(ICON_FA_ARROWS_ALT) || Input::IsKeyDown(Key::W)) { CurrentOperation = ImGuizmo::OPERATION::TRANSLATE; } ImGui::SameLine(); - if (ImGui::Button(ICON_FA_SYNC_ALT) || Input::IsKeyDown(GLFW_KEY_E)) + if (ImGui::Button(ICON_FA_SYNC_ALT) || Input::IsKeyDown(Key::E)) { CurrentOperation = ImGuizmo::OPERATION::ROTATE; } ImGui::SameLine(); - if (ImGui::Button(ICON_FA_EXPAND_ALT) || Input::IsKeyDown(GLFW_KEY_R)) + if (ImGui::Button(ICON_FA_EXPAND_ALT) || Input::IsKeyDown(Key::R)) { CurrentOperation = ImGuizmo::OPERATION::SCALE; } @@ -2388,13 +2388,13 @@ namespace Nuake { editorCam->Update(ts, m_IsHoveringViewport && m_IsViewportFocused); const bool entityIsSelected = Selection.Type == EditorSelectionType::Entity && Selection.Entity.IsValid(); - if (editorCam->IsFlying() && entityIsSelected && Input::IsKeyPressed(GLFW_KEY_F)) + if (editorCam->IsFlying() && entityIsSelected && Input::IsKeyPressed(Key::F)) { editorCam->IsMoving = true; editorCam->TargetPos = Selection.Entity.GetComponent().GetGlobalPosition(); } - if (entityIsSelected && Input::IsKeyPressed(GLFW_KEY_ESCAPE)) + if (entityIsSelected && Input::IsKeyPressed(Key::ESCAPE)) { Selection = EditorSelection(); } diff --git a/Nuake/Engine.cpp b/Nuake/Engine.cpp index ae89eaed..73c095f3 100644 --- a/Nuake/Engine.cpp +++ b/Nuake/Engine.cpp @@ -71,9 +71,11 @@ namespace Nuake s_FixedUpdateDifference -= s_FixedUpdateRate; } + + Input::Update(); } - Input::Update(); + } void Engine::EnterPlayMode() diff --git a/Nuake/src/Core/Input.cpp b/Nuake/src/Core/Input.cpp index 81166c4f..bda51eef 100644 --- a/Nuake/src/Core/Input.cpp +++ b/Nuake/src/Core/Input.cpp @@ -22,29 +22,27 @@ namespace Nuake #pragma region Keys // Only true if the key is currently being pressed - bool Input::IsKeyDown(int keycode) + bool Input::IsKeyDown(Key keycode) { auto window = Window::Get()->GetHandle(); - int state = glfwGetKey(window, keycode); + int state = glfwGetKey(window, (int)keycode); bool result = state == GLFW_PRESS; - m_Keys[keycode] = state; - return result; } // Only true if the key is pressed for the first frame. no repeat. - bool Input::IsKeyPressed(int keycode) + bool Input::IsKeyPressed(Key keycode) { auto window = Window::Get()->GetHandle(); - int state = glfwGetKey(window, keycode); + int state = glfwGetKey(window, (int)keycode); bool result = state == GLFW_PRESS; // First time pressed? - if (m_Keys.find(keycode) == m_Keys.end() || m_Keys[keycode] == false) + if (m_Keys.find((int)keycode) == m_Keys.end() || m_Keys[(int)keycode] == false) { if (result) - m_Keys[keycode] = true; + m_Keys[(int)keycode] = true; return result; } @@ -172,7 +170,7 @@ namespace Nuake // Reset all input to false. for (auto& k : m_Keys) { - if (!IsKeyDown(k.first)) + if (!IsKeyDown((Key)k.first)) { k.second = false; } diff --git a/Nuake/src/Core/Input.h b/Nuake/src/Core/Input.h index d83b937c..4629c9b5 100644 --- a/Nuake/src/Core/Input.h +++ b/Nuake/src/Core/Input.h @@ -138,8 +138,8 @@ namespace Nuake static bool m_MouseButtons[5]; static std::map m_Keys; public: - static bool IsKeyPressed(int keycode); - static bool IsKeyDown(int keycode); + static bool IsKeyPressed(Key keycode); + static bool IsKeyDown(Key keycode); static bool IsKeyReleased(int keycode); static float YScroll; diff --git a/Nuake/src/Scene/EditorCamera.cpp b/Nuake/src/Scene/EditorCamera.cpp index 6f007b0c..e27cea4e 100644 --- a/Nuake/src/Scene/EditorCamera.cpp +++ b/Nuake/src/Scene/EditorCamera.cpp @@ -61,7 +61,7 @@ namespace Nuake Input::HideMouse(); } - if (Input::IsKeyDown(GLFW_KEY_LEFT_ALT)) + if (Input::IsKeyDown(Key::LEFT_ALT)) { if (Input::YScroll != 0.0f) { @@ -96,31 +96,31 @@ namespace Nuake if (m_Type == CAMERA_TYPE::ORTHO) { - if (Input::IsKeyDown(GLFW_KEY_RIGHT)) + if (Input::IsKeyDown(Key::RIGHT)) Translation.x += Speed * ts; - if (Input::IsKeyDown(GLFW_KEY_LEFT)) + if (Input::IsKeyDown(Key::LEFT)) Translation.x -= Speed * ts; - if (Input::IsKeyDown(GLFW_KEY_UP)) + if (Input::IsKeyDown(Key::UP)) Translation.y += Speed * ts; - if (Input::IsKeyDown(GLFW_KEY_DOWN)) + if (Input::IsKeyDown(Key::DOWN)) Translation.y -= Speed * ts; } else { auto movement = Vector3(0, 0, 0); - if (Input::IsKeyDown(GLFW_KEY_D)) + if (Input::IsKeyDown(Key::D)) movement -= Right * (Speed * ts); - if (Input::IsKeyDown(GLFW_KEY_A)) + if (Input::IsKeyDown(Key::A)) movement += Right * (Speed * ts); - if (Input::IsKeyDown(GLFW_KEY_W)) + if (Input::IsKeyDown(Key::W)) movement += Direction * (Speed * ts); - if (Input::IsKeyDown(GLFW_KEY_S)) + if (Input::IsKeyDown(Key::S)) movement -= Direction * (Speed * ts); - if (Input::IsKeyDown(GLFW_KEY_LEFT_SHIFT)) + if (Input::IsKeyDown(Key::LEFT_SHIFT)) movement -= Up * (Speed * ts); - if (Input::IsKeyDown(GLFW_KEY_SPACE)) + if (Input::IsKeyDown(Key::SPACE)) movement += Up * (Speed * ts); Translation += Vector3(movement); diff --git a/Nuake/src/Scripting/Modules/InputModule.h b/Nuake/src/Scripting/Modules/InputModule.h index 64784d1c..bfc43123 100644 --- a/Nuake/src/Scripting/Modules/InputModule.h +++ b/Nuake/src/Scripting/Modules/InputModule.h @@ -69,14 +69,14 @@ namespace Nuake { static void IsKeyDown(WrenVM* vm) { int key = (int)wrenGetSlotDouble(vm, 1); - bool result = Input::IsKeyDown(key); + bool result = Input::IsKeyDown((Key)key); wrenSetSlotBool(vm, 0, result); } static void IsKeyPressed(WrenVM* vm) { int key = (int)wrenGetSlotDouble(vm, 1); - bool result = Input::IsKeyPressed(key); + bool result = Input::IsKeyPressed((Key)key); wrenSetSlotBool(vm, 0, result); } diff --git a/Nuake/src/Scripting/NetModules/InputNetAPI.cpp b/Nuake/src/Scripting/NetModules/InputNetAPI.cpp index 20a2a866..013f9727 100644 --- a/Nuake/src/Scripting/NetModules/InputNetAPI.cpp +++ b/Nuake/src/Scripting/NetModules/InputNetAPI.cpp @@ -25,12 +25,12 @@ namespace Nuake { bool IsKeyDown(int keyCode) { - return Input::IsKeyDown(keyCode); + return Input::IsKeyDown((Key)keyCode); } bool IsKeyPressed(int keyCode) { - return Input::IsKeyPressed(keyCode); + return Input::IsKeyPressed((Key)keyCode); } Coral::Array GetMousePosition()