From c9475afb2a37ce4126b5519b456f6e3ea4f9f978 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 15 May 2024 14:09:58 -0400 Subject: [PATCH] add release checks --- CMakeLists.txt | 2 +- include/blt/gfx/input.h | 4 ++++ include/blt/gfx/window.h | 4 ++++ src/blt/gfx/window.cpp | 15 ++++++++++++--- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cd7f6a..73ea275 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.25) -set(BLT_GRAPHICS_VERSION 0.13.18) +set(BLT_GRAPHICS_VERSION 0.13.19) set(BLT_GRAPHICS_TEST_VERSION 0.0.1) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) diff --git a/include/blt/gfx/input.h b/include/blt/gfx/input.h index f676f17..ab43edf 100644 --- a/include/blt/gfx/input.h +++ b/include/blt/gfx/input.h @@ -33,7 +33,9 @@ namespace blt::gfx double scroll = 0; bool mouse_moved = false; bool key_pressed = false; + bool key_released = false; bool mouse_pressed = false; + bool mouse_released = false; private: KEY_STATE* key_state; MOUSE_STATE* mouse_state; @@ -81,8 +83,10 @@ namespace blt::gfx void clear() { key_pressed = false; + key_released = false; mouse_moved = false; mouse_pressed = false; + mouse_released = false; } bool isKeyPressed(std::size_t key) diff --git a/include/blt/gfx/window.h b/include/blt/gfx/window.h index 59059a1..745e280 100644 --- a/include/blt/gfx/window.h +++ b/include/blt/gfx/window.h @@ -120,11 +120,15 @@ namespace blt::gfx bool mousePressedLastFrame(); + bool mouseReleaseLastFrame(); + bool isKeyPressed(int key); // TODO: maybe make this per key? bool keyPressedLastFrame(); + bool keyReleasedLastFrame(); + double getFrameDeltaSeconds(); double getFrameDeltaMilliseconds(); diff --git a/src/blt/gfx/window.cpp b/src/blt/gfx/window.cpp index 7eadff9..79f3005 100644 --- a/src/blt/gfx/window.cpp +++ b/src/blt/gfx/window.cpp @@ -35,7 +35,7 @@ void gl_error_callback(GLenum source, GLenum type, GLuint id, GLenum severity, G if (type == GL_DEBUG_TYPE_ERROR) { BLT_ERROR("[OpenGL Error] message = '%s', type = 0x%x, severity = 0x%x, source = 0x%x, id = %d", - message, type, severity, source, id); + message, type, severity, source, id); } else { BLT_WARN("[OpenGL Error] message = '%s', type = 0x%x, severity = 0x%x, source = 0x%x, id = %d", @@ -74,15 +74,17 @@ namespace blt::gfx { case GLFW_PRESS: state = KEY_STATE::PRESS; + window_state.inputManager.key_pressed = true; break; case GLFW_REPEAT: state = KEY_STATE::REPEAT; break; default: state = KEY_STATE::RELEASE; + window_state.inputManager.key_released = true; + break; } window_state.inputManager.key(key) = state; - window_state.inputManager.key_pressed = true; }); /* Setup mouse button callback */ @@ -94,13 +96,14 @@ namespace blt::gfx { case GLFW_PRESS: state = MOUSE_STATE::PRESS; + window_state.inputManager.mouse_pressed = true; break; default: state = MOUSE_STATE::RELEASE; + window_state.inputManager.mouse_released = true; break; } window_state.inputManager.mouse(button) = state; - window_state.inputManager.mouse_pressed = true; }); /* Setup mouse cursor callback */ @@ -385,6 +388,12 @@ namespace blt::gfx i32 getWindowWidth() { return window_state.width; } + bool keyReleasedLastFrame() + { return window_state.inputManager.key_released; } + + bool mouseReleaseLastFrame() + { return window_state.inputManager.mouse_released; } + window_data& window_data::setWindowSize(int32_t new_width, int32_t new_height) { width = new_width;