Debug log and LUA console gui windows implemented

Gui_Panel_Refactor
Joeyrp 4 years ago
parent cc811b2a7e
commit 4486eb8890

@ -11,6 +11,14 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
set(OpenGL_MAJOR_VERSION 4)
set(OpenGL_MINOR_VERSION 5)
# Option to build without the editor
set(BUILD_NO_EDITOR 0)
option(NO_EDITOR "Build with no editor" OFF)
if (NO_EDITOR)
message(STATUS "Building without the editor")
set(BUILD_NO_EDITOR 1)
endif ()
configure_file(LunariumConfig.h.in LunariumConfig.h)
# Source Files
@ -40,6 +48,7 @@ set(LUNARIUM_SRC
"src/input/inputManager.cpp"
"src/graphics/gui/gui.cpp"
"src/graphics/gui/logGui.cpp"
"src/graphics/gui/luaConsole.cpp"
"src/assets/types/image.cpp"
)

@ -4,4 +4,6 @@
#define Lunarium_VERSION_PATCH @Lunarium_VERSION_PATCH@
#define OPENGL_MAJOR_VERSION @OpenGL_MAJOR_VERSION@
#define OPENGL_MINOR_VERSION @OpenGL_MINOR_VERSION@
#define OPENGL_MINOR_VERSION @OpenGL_MINOR_VERSION@
#define BUILD_NO_EDITOR @BUILD_NO_EDITOR@

@ -1,11 +1,13 @@
Build System:
☐ Add a build option to do a build without the editor
✔ Add a build option to do a build without the editor @done (9/17/2021, 7:25:08 PM)
☐ Modify .sh scripts to recognize the noeditor flag
Core:
☐ Add log settings to the state file
✔ Add run modes (Editor, Game, Test) to state file @done (9/15/2021, 7:27:03 PM)
✔ Add run mode interface class @done (9/15/2021, 8:22:35 PM)
☐ Read the window size and position on shutdown and write these to the state file
Graphics:
✔ Decide on a font/text rendering system @done (9/7/2021, 1:39:53 PM)
@ -14,8 +16,7 @@ Core:
✔ Make the text renderer smarter about breaking up words on multiple lines @low @done (9/8/2021, 2:23:03 PM)
✔ Implement the Image creation methods @done (9/9/2021, 2:50:20 PM)
✔ Implement Render to Texture @done (9/15/2021, 7:00:33 PM)
☐ Adjust the font loading code to use the binary file buffer instead of ifstream
("b. From Memory": https://www.freetype.org/freetype2/docs/tutorial/step1.html)
✔ Adjust the font loading code to use the binary file buffer instead of ifstream @done (9/17/2021, 6:11:06 PM)
GUI:
@ -76,9 +77,11 @@ Game:
Editor:
✔ Come up with project directory structure @done (9/17/2021, 6:46:44 PM)
☐ Implement Run Mode interface class
☐ Reference raw asset files in a "content" folder
☐ Platform independant file browsing
☐ Scan script files to make sure they don't overwrite globals
Raw Asset Loaders:
- Need classes to load raw resource files for the editor
@ -117,6 +120,11 @@ Assets:
Loaders:
- Need class (or classes?) to load resources from the packed format that the pipeline generates
Come up with binary file formats for each type:
☐ .xml (This will probably be multiple different formats depending on what the .xml file is describing)
☐ Image
☐ Script
☐ Audio
Asset Pipeline:
☐ Read through the contents folder and generate asset files in a custom format (useable by the engine)

@ -0,0 +1,27 @@
The root project folder needs to contain a project.xml file that describes the project (See ??? for details)
Project directory structure (this should be auto-generated by the editor when creating a new project):
Project root
├── project.xml
├── engine/
│ └── Lunarium_NE.exe (non-editor version of the engine. Used for creating a release build of the project)
├── contents/
│ ├── content_meta.xml - (Associates each asset with a unique id, and whatever else is needed to compile the assets)
│ └── assets/
│ └── (Can be organized however the user wants)
└─ release/
├── (This directory is generated by the editor when building the project)
├── game_name.exe - (The non-editor version of the engine renamed to the game name)
└── data/ - (The data folder generated by the asset compiler, contains all the assets for the game in binary formats)
├──
└─

@ -3,4 +3,8 @@ REM This script expects to be run from the parent directory
REM ex. scripts/cmconfig.bat
@echo on
cmake -Wno-dev -DGLFW_BUILD_DOCS=OFF -B build/ -S . -G "Visual Studio 16 2019" -A x64
IF "%~1" == "noedit" (
cmake -Wno-dev -DNO_EDITOR=ON -DGLFW_BUILD_DOCS=OFF -B build/ -S . -G "Visual Studio 16 2019" -A x64
) ELSE (
cmake -Wno-dev -DGLFW_BUILD_DOCS=OFF -B build/ -S . -G "Visual Studio 16 2019" -A x64
)

@ -9,22 +9,25 @@
#include "core.h"
#include "version.h"
#include <imgui.h>
// Run modes
#include <tester/tester.h>
// Sub Systems
#include <window/window.h>
//#include <assets/types/image.h>
#include <input/inputManager.h>
#include <graphics/opengl/glGraphics.h>
#include <graphics/gui/gui.h>
#include <graphics/gui/logGui.h>
#include <graphics/gui/luaConsole.h>
namespace lunarium
{
Core* Core::mpInstance = nullptr;
Core::Core()
: mbIsInit(false), mpArgs(nullptr), mpWindow(nullptr), mpGraphics(nullptr), mpInput(nullptr),
mGUI(GUI::GetInstance()), mbMidRender(false), mbMidTextureRender(false), mpRunMode(nullptr)
mGUI(GUI::GetInstance()), mbMidRender(false), mbMidTextureRender(false), mpRunMode(nullptr), mbShowGuiDemo(false)
{
}
@ -49,8 +52,16 @@ namespace lunarium
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Lunarium is shutting down!");
mpInstance->mpWindow->GetFramebufferSize(&mpInstance->mState.Display.WindowedSize.Width,
&mpInstance->mState.Display.WindowedSize.Height);
mpInstance->mpWindow->GetPosition(&mpInstance->mState.Display.WindowStartPosition.X,
&mpInstance->mState.Display.WindowStartPosition.Y);
mpInstance->mState.SaveToFile("lunarium_state.xml");
// Shutdown subsystems
// LuaConsole::FreeInstance();
LogGui::FreeInstance();
GUI::GetInstance().Shutdown();
GUI::FreeInstance();
@ -212,6 +223,11 @@ namespace lunarium
return mState;
}
void Core::SignalShutdown()
{
mpWindow->SetShouldCloseFlag(true);
}
////////////////////////////////////////////////////////////
// GAME LOOP
////////////////////////////////////////////////////////////
@ -231,29 +247,54 @@ namespace lunarium
// Poll input
Window::PollEvents();
mKeyEvents = mpInput->PollKeys();
auto keyEvents = mpInput->PollKeys();
// HACK: Temporary solution to close the program
if (mpInput->IsKeyDown(KeyCode::ESCAPE))
// HIDE/SHOW THE DEBUG WINDOWS
if (mpInput->IsKeyPressed(KeyCode::F2, true))
{
mpWindow->SetShouldCloseFlag(true);
mbShowGuiDemo = !mbShowGuiDemo;
}
if (mpInput->IsKeyPressed(KeyCode::F3))
if (mpInput->IsKeyPressed(KeyCode::F3, true))
{
//Logger::Log(LogCategory::CORE, LogLevel::INFO, "Toggling the Debug Log Window");
LogGui::GetInstance().SetShow(!LogGui::GetInstance().IsShown());
}
if (mpInput->IsKeyPressed(KeyCode::F4, true))
{
LuaConsole::GetInstance().SetShow(!LuaConsole::GetInstance().IsShown());
}
// TODO: Send input events
if (!ImGui::GetIO().WantCaptureKeyboard)
{
// Send key events
for (int i = 0; i < keyEvents.KeysPressed.size(); i++)
{
mpRunMode->OnKeyPress(keyEvents.KeysPressed[i]);
}
for (int i = 0; i < keyEvents.KeysReleased.size(); i++)
{
mpRunMode->OnKeyRelease(keyEvents.KeysReleased[i]);
}
}
else
{
// Check if there is a new LUA command
std::string command;
if (LuaConsole::GetInstance().GetNewCommand(command))
{
Logger::Log(LogCategory::CORE, LogLevel::INFO, "New LUA command: %s", command.c_str());
}
}
// Update game state
// UPDATE game state
mpRunMode->OnTick(mFrameCounter.GetFrameData().LastFrameTime);
// Render
// REDNER
if (mbMidTextureRender)
{
Logger::Log(LogCategory::CORE, LogLevel::WARNING, "Render to texture was not ended!");
@ -264,12 +305,19 @@ namespace lunarium
mpGraphics->BeginDraw();
mbMidRender = true;
// DEBUG: Render test ImGUI window
// mGUI.ShowDemoWindow();
// Gui windows
if (mbShowGuiDemo)
{
mGUI.ShowDemoWindow();
}
LogGui::GetInstance().Show();
LuaConsole::GetInstance().Show();
// Run mode
mpRunMode->OnRender(mpGraphics);
// END RENDER
mGUI.EndFrame();
mpGraphics->EndDraw();
mbMidRender = false;

@ -11,7 +11,6 @@
#include "state.h"
#include "iRunMode.h"
#include <input/inputManager.h>
#include <utils/logger.h>
#include <utils/args.h>
#include <utils/frameCounter.h>
@ -24,6 +23,7 @@ namespace lunarium
class GUI;
class IGraphics;
class Window;
class InputManager;
class Core
{
@ -32,6 +32,7 @@ namespace lunarium
static void Shutdown();
void Initialize(int argc, char** argv);
void SignalShutdown();
bool IsInit() const;
const State& GetState() const;
@ -52,6 +53,7 @@ namespace lunarium
iRunMode* mpRunMode;
bool mbMidRender;
bool mbMidTextureRender;
bool mbShowGuiDemo;
// Log Files
std::ofstream mMasterLogFile;
@ -64,8 +66,6 @@ namespace lunarium
InputManager* mpInput;
GUI& mGUI;
InputManager::_KeyEvents mKeyEvents;
public: // SUBSYSTEM GETTERS
static Window& MainWindow();

@ -88,6 +88,11 @@ namespace lunarium
mbIsInit = false;
}
bool GUI::WantCaptureKeyboard() const
{
return ImGui::GetIO().WantCaptureKeyboard;
}
void GUI::NewFrame()
{
if (!mbIsInit)

@ -26,6 +26,8 @@ namespace lunarium
void EndFrame();
void ShowDemoWindow();
bool WantCaptureKeyboard() const;
private:
GUI();
GUI(const GUI&) = delete;

@ -7,6 +7,8 @@
******************************************************************************/
#include "logGui.h"
#include <core/core.h>
#include <window/window.h>
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
@ -43,7 +45,7 @@ namespace lunarium
////////////////////////////////////////////////////////////
LogGui* LogGui::mpInstance = nullptr;
LogGui::LogGui()
: mbShow(true), mListener(this), mbOglDebug(false), mbInfoVerbose(false)
: mbShow(false), mListener(this), mbOglDebug(false), mbInfoVerbose(false)
{
}
@ -77,8 +79,17 @@ namespace lunarium
if (!mbShow)
return;
ImGui::SetNextWindowSize(ImVec2(300, 400), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("Debug Log", &mbShow))
int x, y;
Core::MainWindow().GetPosition(&x, &y);
int width, height;
Core::MainWindow().GetFramebufferSize(&width, &height);
int logHeight = height / 2.0f;
ImGui::SetNextWindowPos(ImVec2(x, y + logHeight), ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2((width / 3.0f) * 2.0f, logHeight), ImGuiCond_Always);
if (!ImGui::Begin("Debug Log", &mbShow, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove
| ImGuiWindowFlags_NoSavedSettings))
{
ImGui::End();
return;

@ -0,0 +1,125 @@
/******************************************************************************
* File - luaConsole.cpp
* Author - Joey Pollack
* Date - 2021/09/17 (y/m/d)
* Mod Date - 2021/09/17 (y/m/d)
* Description - GUI window for the LUA console
******************************************************************************/
#include "luaConsole.h"
#include <core/core.h>
#include <input/inputManager.h>
#include <window/window.h>
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
#include <cstring>
namespace lunarium
{
LuaConsole* LuaConsole::mpInstance = nullptr;
LuaConsole::LuaConsole()
: mbShow(false), mbNewCommand(false)
{
memset(mBuffer, 0, LUA_CON_BUFFER_SIZE);
}
LuaConsole& LuaConsole::GetInstance()
{
if (!mpInstance)
{
mpInstance = new LuaConsole;
}
return *mpInstance;
}
void LuaConsole::FreeInstance()
{
delete mpInstance;
mpInstance = nullptr;
}
OpRes LuaConsole::Initialize()
{
return OpRes::OK();
}
void LuaConsole::Show()
{
// TODO: LuaConsole::Show
if (!mbShow)
return;
int x, y;
Core::MainWindow().GetPosition(&x, &y);
int width, height;
Core::MainWindow().GetFramebufferSize(&width, &height);
ImGui::SetNextWindowPos(ImVec2(x, y), ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(width / 3.0f, height / 3.0f), ImGuiCond_Always);
if (!ImGui::Begin("LUA Console", &mbShow, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove
| ImGuiWindowFlags_NoSavedSettings))
{
ImGui::End();
return;
}
ImGui::BeginChild("history", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
for (int i = 0; i < mCommandHistory.size(); i++)
{
const char* msg = mCommandHistory[i].c_str();
int len = strlen(msg);
ImGui::TextUnformatted(msg);
}
ImGui::EndChild();
ImGui::Separator();
ImGui::InputText("command", mBuffer, LUA_CON_BUFFER_SIZE);
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
ImGui::SetScrollHereY(1.0f);
ImGui::End();
if (Core::Input().IsKeyPressed(KeyCode::RETURN) && strlen(mBuffer) > 1)
{
mCommandHistory.push_back(mBuffer);
memset(mBuffer, 0, LUA_CON_BUFFER_SIZE);
mbNewCommand = true;
}
}
void LuaConsole::SetShow(bool show)
{
mbShow = show;
}
bool LuaConsole::IsShown() const
{
return mbShow;
}
const std::vector<std::string>* LuaConsole::GetCommandHistory() const
{
return &mCommandHistory;
}
std::string LuaConsole::GetLastCommand()
{
return mCommandHistory.back();
}
bool LuaConsole::GetNewCommand(std::string& command)
{
if (mbNewCommand)
{
command = mCommandHistory.back();
mbNewCommand = false;
return true;
}
return false;
}
}

@ -0,0 +1,50 @@
/******************************************************************************
* File - luaConsole.h
* Author - Joey Pollack
* Date - 2021/09/17 (y/m/d)
* Mod Date - 2021/09/17 (y/m/d)
* Description - GUI window for the LUA console
******************************************************************************/
#ifndef LUA_CONSOLE_H_
#define LUA_CONSOLE_H_
#include <utils/opRes.h>
#include <string>
#include <vector>
namespace lunarium
{
const int LUA_CON_BUFFER_SIZE = 64;
class LuaConsole
{
public:
static LuaConsole& GetInstance();
static void FreeInstance();
OpRes Initialize();
void Show();
void SetShow(bool show);
bool IsShown() const;
const std::vector<std::string>* GetCommandHistory() const;
std::string GetLastCommand();
bool GetNewCommand(std::string& command); // returns true if there is a new and false if not
private:
static LuaConsole* mpInstance;
bool mbShow;
char mBuffer[LUA_CON_BUFFER_SIZE];
std::vector<std::string> mCommandHistory;
bool mbNewCommand;
private:
LuaConsole();
LuaConsole(const LuaConsole&) = delete;
const LuaConsole& operator=(const LuaConsole&) = delete;
};
}
#endif // LUA_CONSOLE_H_

@ -10,6 +10,7 @@
#include <window/window.h>
#include "inputManager.h"
#include <graphics/gui/gui.h>
#include <utils/logger.h>
#include <cstring>
@ -120,13 +121,19 @@ namespace lunarium
keyCode == KeyCode::MOUSE_X2_BUTTON );
}
bool InputManager::IsKeyDown(KeyCode key)
bool InputManager::IsKeyDown(KeyCode key, bool ignoreWantCapture)
{
if (GUI::GetInstance().WantCaptureKeyboard() && !ignoreWantCapture)
return false;
return (mKeyboardState[key] == KEY_DOWN);
}
bool InputManager::IsKeyPressed(KeyCode key)
bool InputManager::IsKeyPressed(KeyCode key, bool ignoreWantCapture)
{
if (GUI::GetInstance().WantCaptureKeyboard() && !ignoreWantCapture)
return false;
for (int i = 0; i < mKeyEvents.KeysPressed.size(); i++)
{
if (mKeyEvents.KeysPressed[i].Key.Code == key)

@ -72,10 +72,10 @@ namespace lunarium
public:
// Returns true if a key is down and was NOT down last frame
bool IsKeyPressed(KeyCode key);
bool IsKeyPressed(KeyCode key, bool ignoreWantCapture = false);
// Returns true if a key is down
bool IsKeyDown(KeyCode key);
bool IsKeyDown(KeyCode key, bool ignoreWantCapture = false);
// Returns the mouse position in screen coordinates
glm::vec2 GetMousePosition();

@ -117,6 +117,7 @@ namespace lunarium
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::TAB, { KeyCode::TAB, "tab", "tab", (char)(9), (char)(9) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::RETURN, { KeyCode::RETURN, "return", "return", (char)(10), (char)(10) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::ESCAPE, { KeyCode::ESCAPE, "escape", "escape", (char)(27), (char)(27) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::SPACE, { KeyCode::SPACE, "space", "space", (char)(32), (char)(32) }));
// Arrow Keys
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::LEFT, { KeyCode::LEFT, "Left Arrow", "Left Arrow", (char)(0), (char)(0) }));

@ -13,6 +13,7 @@
#include <graphics/igraphics.h>
#include <input/inputManager.h>
#include <assets/types/image.h>
#include <LunariumConfig.h>
namespace lunarium
{
@ -27,6 +28,13 @@ namespace lunarium
mLogCat = Logger::RegisterCategory("TESTER");
#if BUILD_NO_EDITOR
Logger::Log(mLogCat, LogLevel::INFO, "BUILDING NO EDITOR!");
#else
Logger::Log(mLogCat, LogLevel::INFO, "BUILDING WITH THE EDITOR!");
#endif
mTextBoxWidth = 500;
// Currently the full default window size
@ -43,6 +51,11 @@ namespace lunarium
void Tester::OnTick(double delta)
{
if (Core::Input().IsKeyDown(KeyCode::ESCAPE))
{
Core::GetInstance().SignalShutdown();
}
// Textbox size adjustment
if (Core::Input().IsKeyDown(KeyCode::LEFT))
{

@ -177,6 +177,10 @@ namespace lunarium
glfwGetFramebufferSize(mpWindow, width, height);
}
void Window::GetPosition(int* x, int* y) const
{
glfwGetWindowPos(mpWindow, x, y);
}
bool Window::ShouldWindowClose() const
{

@ -38,6 +38,7 @@ namespace lunarium
void ChangeDisplayMode(bool fullscreen, int xPos, int yPos, int width, int height);
void GetFramebufferSize(int* width, int* height) const;
void GetPosition(int* x, int* y) const;
void SetShouldCloseFlag(bool should_close);
bool ShouldWindowClose() const;

Loading…
Cancel
Save