Skip to content

Commit

Permalink
Replace keyboard monitor from loop to callback
Browse files Browse the repository at this point in the history
Replace keyboard monitor from loop to callback
  • Loading branch information
UnrealKaraulov committed Dec 6, 2023
1 parent 70656d6 commit 493735b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
15 changes: 3 additions & 12 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
{
g_app->hideGui = !g_app->hideGui;
}

g_app->oldPressed[key] = g_app->pressed[key];
g_app->pressed[key] = action != GLFW_RELEASE;
}

void drop_callback(GLFWwindow* window, int count, const char** paths)
Expand Down Expand Up @@ -349,18 +352,6 @@ void Renderer::renderLoop()
oldRightMouse = curRightMouse;
curRightMouse = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT);

for (int i = GLFW_KEY_SPACE; i < GLFW_KEY_LAST; i++)
{
oldPressed[i] = pressed[i];
oldReleased[i] = released[i];
}

for (int i = GLFW_KEY_SPACE; i < GLFW_KEY_LAST; i++)
{
pressed[i] = glfwGetKey(window, i) == GLFW_PRESS;
released[i] = glfwGetKey(window, i) == GLFW_RELEASE;
}

DebugKeyPressed = pressed[GLFW_KEY_F1];

anyCtrlPressed = pressed[GLFW_KEY_LEFT_CONTROL] || pressed[GLFW_KEY_RIGHT_CONTROL];
Expand Down
2 changes: 0 additions & 2 deletions src/editor/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ class Renderer
int oldScroll;

bool pressed[GLFW_KEY_LAST];
bool released[GLFW_KEY_LAST];
bool oldPressed[GLFW_KEY_LAST];
bool oldReleased[GLFW_KEY_LAST];

bool anyCtrlPressed;
bool anyAltPressed;
Expand Down

0 comments on commit 493735b

Please sign in to comment.