diff --git a/.vscode/settings.json b/.vscode/settings.json index 38a3e51..6715a50 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,76 @@ "files.associations": { "*.h": "c", "xstring": "cpp", - "thread": "cpp" + "thread": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "bitset": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "complex": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdint": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "regex": "cpp", + "source_location": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp", + "variant": "cpp", + "format": "cpp", + "*.m": "cpp" } } \ No newline at end of file diff --git a/imgui.ini b/imgui.ini index 41e57cb..28ec247 100644 --- a/imgui.ini +++ b/imgui.ini @@ -61,12 +61,18 @@ Size=1264,132 Collapsed=0 DockId=0x00000006,0 +[Window][Game Window] +Pos=8,27 +Size=1264,551 +Collapsed=0 +DockId=0x00000001,0 + [Docking][Data] DockSpace ID=0x9076BACA Window=0x34F970D7 Pos=8,27 Size=1264,685 Split=Y Selected=0x6D1308E5 DockNode ID=0x00000005 Parent=0x9076BACA SizeRef=1264,551 Split=X DockNode ID=0x00000003 Parent=0x00000005 SizeRef=282,685 Selected=0x6D1308E5 DockNode ID=0x00000004 Parent=0x00000005 SizeRef=980,685 Split=Y - DockNode ID=0x00000001 Parent=0x00000004 SizeRef=1264,538 CentralNode=1 Selected=0x6D1308E5 + DockNode ID=0x00000001 Parent=0x00000004 SizeRef=1264,538 CentralNode=1 Selected=0x27A02DAA DockNode ID=0x00000002 Parent=0x00000004 SizeRef=1264,145 Selected=0x995FC207 DockNode ID=0x00000006 Parent=0x9076BACA SizeRef=1264,132 Selected=0xBEDDA0C1 diff --git a/include/Application.h b/include/Application.h index 8ad63c0..d761fa0 100644 --- a/include/Application.h +++ b/include/Application.h @@ -2,6 +2,7 @@ #include "ScriptEngine.h" #include "HotReload.h" #include "GuiManager.h" +#include "raylib.h" class Application { public: @@ -19,6 +20,7 @@ private: FILE* logFile; GuiManager guiManager; bool enableEditor; + RenderTexture2D renderTexture; // Declare renderTexture for Raylib rendering static const int WINDOW_WIDTH = 1280; static const int WINDOW_HEIGHT = 720; diff --git a/include/GuiManager.h b/include/GuiManager.h index b7e702d..5294a7e 100644 --- a/include/GuiManager.h +++ b/include/GuiManager.h @@ -11,10 +11,10 @@ public: ~GuiManager(); void Initialize(); - void Render(); + void Render(RenderTexture2D& renderTexture); void Shutdown(); private: - void SetupDockspace(); + void SetupDockspace(RenderTexture2D& renderTexture); void RenderNotifications(); }; \ No newline at end of file diff --git a/scripts/as.predefined b/scripts/as.predefined new file mode 100644 index 0000000..ba2e406 --- /dev/null +++ b/scripts/as.predefined @@ -0,0 +1,11 @@ + +typedef void string; +void Print(const string &in); +void Log(int level, const string &in); +void DrawText(const string &in, int x, int y, int fontSize, int color); +int LOG_TRACE; +int LOG_DEBUG; +int LOG_INFO; +int LOG_WARN; +int LOG_ERROR; +int LOG_FATAL; diff --git a/scripts/update.as b/scripts/update.as index eac9c0d..f4a82de 100644 --- a/scripts/update.as +++ b/scripts/update.as @@ -8,4 +8,4 @@ void Update(float dt) { Print("X position reset!"); Log(LOG_INFO, "Log INFO: reset happened"); } -}// +} diff --git a/src/Application.cpp b/src/Application.cpp index 300d627..f8378a4 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -5,13 +5,12 @@ #include #include #include "log/log.h" -#if HAVE_RLIMGUI + #include "rlImGui.h" #include "imgui.h" #include "extras/IconsFontAwesome6.h" #include "gui/ImGuiNotify.hpp" #include "GuiManager.h" -#endif #ifdef _WIN32 // On Windows, fopen_s is already available, so no need to define it. @@ -22,7 +21,7 @@ const char *Application::WINDOW_TITLE = "Simian"; const char *Application::SCRIPT_FILE = "scripts/test.as"; -Application::Application() : hotReload(nullptr), scriptCompilationError(false), logFile(nullptr) +Application::Application() : hotReload(nullptr), scriptCompilationError(false), logFile(nullptr), renderTexture{} // Initialize renderTexture { } @@ -83,9 +82,10 @@ bool Application::Initialize(int argc, char *argv[]) if (enableEditor) { -#if HAVE_RLIMGUI + guiManager.Initialize(); -#endif + + renderTexture = LoadRenderTexture(WINDOW_WIDTH, WINDOW_HEIGHT); } return true; @@ -125,23 +125,58 @@ void Application::Update(float deltaTime) void Application::Draw() { - BeginDrawing(); - ClearBackground(RAYWHITE); - - // Show script error status in top left if there's an error, otherwise show normal message - if (scriptCompilationError) + if (enableEditor) { - DrawText("SCRIPT ERROR - Check console for details", 10, 10, 16, RED); - } + int screenWidth = GetScreenWidth(); + int screenHeight = GetScreenHeight(); - // Call script Draw function - scriptEngine.CallScriptFunction(scriptEngine.GetDrawFunction()); -if (enableEditor) { -#if HAVE_RLIMGUI - guiManager.Render(); -#endif -} - EndDrawing(); + // Fallback to default values if screen dimensions are invalid + if (screenWidth <= 0 || screenHeight <= 0) + { + log_warn("Invalid screen dimensions: %d x %d. Using default values.", screenWidth, screenHeight); + screenWidth = 800; + screenHeight = 600; + } + + ImGuiIO &io = ImGui::GetIO(); + io.DisplaySize = ImVec2((float)screenWidth, (float)screenHeight); // Set DisplaySize + + BeginTextureMode(renderTexture); + ClearBackground(RAYWHITE); + + // Show script error status in top left if there's an error, otherwise show normal message + if (scriptCompilationError) + { + DrawText("SCRIPT ERROR - Check console for details", 10, 10, 16, RED); + } + + // Call script Draw function + scriptEngine.CallScriptFunction(scriptEngine.GetDrawFunction()); + + EndTextureMode(); + BeginDrawing(); + ClearBackground(RAYWHITE); + + guiManager.Render(renderTexture); // Render the GUI + + EndDrawing(); + } + else + { + BeginDrawing(); + ClearBackground(RAYWHITE); + + // Show script error status in top left if there's an error, otherwise show normal message + if (scriptCompilationError) + { + DrawText("SCRIPT ERROR - Check console for details", 10, 10, 16, RED); + } + + // Call script Draw function + scriptEngine.CallScriptFunction(scriptEngine.GetDrawFunction()); + + EndDrawing(); + } } void Application::Shutdown() @@ -153,10 +188,10 @@ void Application::Shutdown() } scriptEngine.Shutdown(); - -#if HAVE_RLIMGUI - guiManager.Shutdown(); -#endif + if (enableEditor) + { + guiManager.Shutdown(); + } // Shutdown rlImGui first while the GL context and window are still valid rlImGuiShutdown(); diff --git a/src/GuiManager.cpp b/src/GuiManager.cpp index 35b15a4..7898f01 100644 --- a/src/GuiManager.cpp +++ b/src/GuiManager.cpp @@ -3,11 +3,13 @@ #include // Add this to fix the incomplete type error #include #include +#include "log.h" GuiManager::GuiManager() {} GuiManager::~GuiManager() {} -void GuiManager::Initialize() { +void GuiManager::Initialize() +{ rlImGuiSetup(true); ImGuiIO &io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; @@ -23,11 +25,13 @@ void GuiManager::Initialize() { iconsConfig.PixelSnapH = true; iconsConfig.GlyphMinAdvanceX = iconFontSize; io.Fonts->AddFontFromMemoryCompressedTTF(fa_solid_900_compressed_data, fa_solid_900_compressed_size, iconFontSize, &iconsConfig, iconsRanges); + log_trace("GuiManager::Initialize - Started"); } -void GuiManager::Render() { +void GuiManager::Render(RenderTexture2D &renderTexture) +{ rlImGuiBegin(); - SetupDockspace(); + SetupDockspace(renderTexture); // Pass the renderTexture parameter RenderNotifications(); rlImGuiEnd(); @@ -35,17 +39,20 @@ void GuiManager::Render() { ImGui::RenderPlatformWindowsDefault(); } -void GuiManager::Shutdown() { +void GuiManager::Shutdown() +{ rlImGuiShutdown(); } -void GuiManager::SetupDockspace() { +void GuiManager::SetupDockspace(RenderTexture2D &renderTexture) +{ static bool dockspaceOpen = true; static bool opt_fullscreen = true; static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None; ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking; - if (opt_fullscreen) { + if (opt_fullscreen) + { ImGuiViewport *viewport = ImGui::GetMainViewport(); ImGui::SetNextWindowPos(viewport->WorkPos); ImGui::SetNextWindowSize(viewport->WorkSize); @@ -63,6 +70,14 @@ void GuiManager::SetupDockspace() { ImGuiID dockspace_id = ImGui::GetID("MyDockSpace"); ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags); + // Add a Game Window + ImGui::Begin("Game Window"); + + // Render Raylib content to the Game Window + rlImGuiImageRenderTexture(&renderTexture); + + ImGui::End(); + // Log Viewer Window ImGui::Begin("Log Viewer"); static std::string logContent; @@ -70,9 +85,11 @@ void GuiManager::SetupDockspace() { // Read the log file if it has changed std::ifstream logFile("log.txt", std::ios::ate); // Open at the end to get the file size - if (logFile.is_open()) { + if (logFile.is_open()) + { size_t fileSize = logFile.tellg(); - if (fileSize != lastFileSize) { + if (fileSize != lastFileSize) + { lastFileSize = fileSize; logFile.seekg(0, std::ios::beg); // Go back to the beginning logContent.assign((std::istreambuf_iterator(logFile)), @@ -92,7 +109,8 @@ void GuiManager::SetupDockspace() { ImGui::End(); } -void GuiManager::RenderNotifications() { +void GuiManager::RenderNotifications() +{ ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.10f, 0.10f, 0.10f, 1.00f));