diff --git a/docs/Tasks.todo b/docs/Tasks.todo index 7a261fb..eedcec9 100644 --- a/docs/Tasks.todo +++ b/docs/Tasks.todo @@ -17,7 +17,7 @@ Core: ✔ Dear ImGui class with basic initialization @done (9/10/2021, 1:42:19 PM) ✔ Debug log window @done (9/10/2021, 4:44:48 PM) ☐ Add key to show debug log window -. + ☐ Add checkboxes to disable log categories and levels Input: ✔ Port over the Element2D input system and adjust it to use glfw @done (9/8/2021, 8:20:07 PM) diff --git a/src/core/core.cpp b/src/core/core.cpp index 1687b1a..f804a11 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -182,6 +182,7 @@ namespace lunarium void Core::RunGameLoop() { + //glfwSetInputMode(mpWindow->GetWindow(), GLFW_STICKY_KEYS, GLFW_TRUE); mFrameCounter.Reset(); // TODO: Init frame counter @@ -204,6 +205,12 @@ namespace lunarium mpWindow->SetShouldCloseFlag(true); } + if (mpInput->IsKeyPressed(KeyCode::F3)) + { + //Logger::Log(LogCategory::CORE, LogLevel::INFO, "Toggling the Debug Log Window"); + LogGui::GetInstance().SetShow(!LogGui::GetInstance().IsShown()); + } + // DEBUG: Graphics testing static int width = 500; if (mpInput->IsKeyDown(KeyCode::LEFT)) diff --git a/src/graphics/gui/logGui.cpp b/src/graphics/gui/logGui.cpp index 56f1a28..b07c230 100644 --- a/src/graphics/gui/logGui.cpp +++ b/src/graphics/gui/logGui.cpp @@ -43,7 +43,7 @@ namespace lunarium //////////////////////////////////////////////////////////// LogGui* LogGui::mpInstance = nullptr; LogGui::LogGui() - : mbShow(true), mListener(this) + : mbShow(true), mListener(this), mbOglDebug(false) { } @@ -77,21 +77,45 @@ namespace lunarium if (!mbShow) return; - ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver); + ImGui::SetNextWindowSize(ImVec2(300, 400), ImGuiCond_FirstUseEver); if (!ImGui::Begin("Debug Log", &mbShow)) { ImGui::End(); return; } + ImGui::Checkbox("OGL_DEBUG", &mbOglDebug); + ImGui::Separator(); ImGui::BeginChild("scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); for (int i = 0; i < mMsgHistory.size(); i++) { + if (mMsgHistory[i].find("[OGL_DEBUG]") != std::string::npos && !mbOglDebug) + { + continue; + } + + ImVec4 color(1.0f, 1.0f, 1.0f, 1.0f); + + if (mMsgHistory[i].find("WANRING") != std::string::npos) + { + color = ImVec4(0.75f, 0.75f, 0.0f, 1.0f); + } + + if (mMsgHistory[i].find("ERROR") != std::string::npos) + { + color = ImVec4(1.0f, 0.0f, 0.0f, 1.0f); + } + const char* msg = mMsgHistory[i].c_str(); int len = strlen(msg); - ImGui::TextUnformatted(msg); + + ImGui::PushTextWrapPos(ImGui::GetWindowWidth()); + ImGui::TextColored(color, msg); + ImGui::PopTextWrapPos(); } + ImGui::PopStyleVar(); if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) ImGui::SetScrollHereY(1.0f); diff --git a/src/graphics/gui/logGui.h b/src/graphics/gui/logGui.h index ae3280a..916d22d 100644 --- a/src/graphics/gui/logGui.h +++ b/src/graphics/gui/logGui.h @@ -47,6 +47,8 @@ namespace lunarium friend GuiListener; GuiListener mListener; + bool mbOglDebug; + private: LogGui(); LogGui(const LogGui&) = delete; diff --git a/src/input/inputManager.cpp b/src/input/inputManager.cpp index 8ba6206..283f163 100644 --- a/src/input/inputManager.cpp +++ b/src/input/inputManager.cpp @@ -18,7 +18,7 @@ namespace lunarium InputManager::InputManager() : mpWindow(nullptr) { - memset(mKeyboardState, 0, NUM_KEYS); + memset(mKeyboardState, 0, 512); } void InputManager::Initialize(Window* pWindow) @@ -51,21 +51,21 @@ namespace lunarium bool altHeld = mpWindow->IsKeyDown(KeyCode::ALT); - for (int i = 0; i < NUM_KEYS; i++) + for (int i = 0; i < KeyCodeList.size(); i++) { - Keyboard::Key key = Keyboard::GetInstance()->GetKey((KeyCode)i); + Keyboard::Key key = Keyboard::GetInstance()->GetKey((KeyCode)KeyCodeList[i]); bool keyIsDown = mpWindow->IsKeyDown(KeyCodeList[i]); // Mouse Buttons are a special case - if (IsMouseButton(i)) + if (IsMouseButton(KeyCodeList[i])) { if (keyIsDown) { - mKeyboardState[i] = KEY_DOWN; + mKeyboardState[KeyCodeList[i]] = KEY_DOWN; } else { - mKeyboardState[i] = KEY_UP; + mKeyboardState[KeyCodeList[i]] = KEY_UP; } continue; @@ -83,9 +83,10 @@ namespace lunarium } // Key was just pressed this frame - if (KEY_UP == mKeyboardState[i]) + if (KEY_UP == mKeyboardState[KeyCodeList[i]]) { - mKeyboardState[i] = KEY_DOWN; + //Logger::Log(LogCategory::CORE, LogLevel::INFO, "Key Down: %d, %s", KeyCodeList[i], key.Name.c_str()); + mKeyboardState[KeyCodeList[i]] = KEY_DOWN; KeyPress kp; kp.Key = key; @@ -99,9 +100,9 @@ namespace lunarium else { // Key was just released this frame - if (KEY_DOWN == mKeyboardState[i]) + if (KEY_DOWN == mKeyboardState[KeyCodeList[i]]) { - mKeyboardState[i] = KEY_UP; + mKeyboardState[KeyCodeList[i]] = KEY_UP; mKeyEvents.KeysReleased.push_back(key); } } @@ -137,7 +138,6 @@ namespace lunarium return false; } - // TODO: FIX WINDOWS SPECIFIC CODE: glm::vec2 InputManager::GetMousePosition() { // POINT p; diff --git a/src/input/inputManager.h b/src/input/inputManager.h index 204c328..429e1a6 100644 --- a/src/input/inputManager.h +++ b/src/input/inputManager.h @@ -84,7 +84,7 @@ namespace lunarium private: Window* mpWindow; - unsigned char mKeyboardState[NUM_KEYS]; + unsigned char mKeyboardState[512]; //unsigned char mKeyboardPreviousState[NUM_KEYS]; std::vector mModifiers; }; diff --git a/src/input/keyboard.cpp b/src/input/keyboard.cpp index 0ac1e6b..52399dc 100644 --- a/src/input/keyboard.cpp +++ b/src/input/keyboard.cpp @@ -124,6 +124,21 @@ namespace lunarium mKeyboard.insert(std::pair(KeyCode::RIGHT, { KeyCode::RIGHT, "Right Arrow", "Right Arrow", (char)(0), (char)(0) })); mKeyboard.insert(std::pair(KeyCode::DOWN, { KeyCode::DOWN, "Down Arrow", "Down Arrow", (char)(0), (char)(0) })); + // F Keys + mKeyboard.insert(std::pair(KeyCode::F1, { KeyCode::F1, "F1", "F1", (char)(0), (char)(0) })); + mKeyboard.insert(std::pair(KeyCode::F2, { KeyCode::F2, "F2", "F2", (char)(0), (char)(0) })); + mKeyboard.insert(std::pair(KeyCode::F3, { KeyCode::F3, "F3", "F3", (char)(0), (char)(0) })); + mKeyboard.insert(std::pair(KeyCode::F4, { KeyCode::F4, "F4", "F4", (char)(0), (char)(0) })); + mKeyboard.insert(std::pair(KeyCode::F5, { KeyCode::F5, "F5", "F5", (char)(0), (char)(0) })); + mKeyboard.insert(std::pair(KeyCode::F6, { KeyCode::F6, "F6", "F6", (char)(0), (char)(0) })); + mKeyboard.insert(std::pair(KeyCode::F7, { KeyCode::F7, "F7", "F7", (char)(0), (char)(0) })); + mKeyboard.insert(std::pair(KeyCode::F8, { KeyCode::F8, "F8", "F8", (char)(0), (char)(0) })); + mKeyboard.insert(std::pair(KeyCode::F9, { KeyCode::F9, "F9", "F9", (char)(0), (char)(0) })); + mKeyboard.insert(std::pair(KeyCode::F10, { KeyCode::F10, "F10", "F10", (char)(0), (char)(0) })); + mKeyboard.insert(std::pair(KeyCode::F11, { KeyCode::F11, "F11", "F11", (char)(0), (char)(0) })); + mKeyboard.insert(std::pair(KeyCode::F12, { KeyCode::F12, "F12", "F12", (char)(0), (char)(0) })); + + // Set up the cross references InitKeysByName(); InitKeysByAscii(); diff --git a/src/window/keyCodes.h b/src/window/keyCodes.h index 961e1f1..2b6bcf0 100644 --- a/src/window/keyCodes.h +++ b/src/window/keyCodes.h @@ -11,6 +11,7 @@ #define KEY_CODES_H_ #include "window.h" +#include namespace lunarium { @@ -122,8 +123,6 @@ namespace lunarium MOUSE_X1_BUTTON = GLFW_MOUSE_BUTTON_4, MOUSE_X2_BUTTON = GLFW_MOUSE_BUTTON_5, - NUM_KEYS, - // ALTERNATE NAMES SHIFT = GLFW_KEY_LEFT_SHIFT, CONTROL = GLFW_KEY_LEFT_CONTROL, @@ -132,7 +131,7 @@ namespace lunarium KEY_UNKNOWN = 0xFFFF }; - static int KeyCodeList[] = { + static std::vector KeyCodeList = { KeyCode::A, KeyCode::B, KeyCode::C,