From 45ff2734fb0e3904cc542d9916a0687ae0a929fc Mon Sep 17 00:00:00 2001 From: P0ulpy Date: Sun, 6 Oct 2024 01:06:17 +0200 Subject: [PATCH] Editor : Enhanced StepInto & StepOver --- src/Editor/RaycastingCameraViewport.hpp | 2 +- src/Editor/RenderingOrchestrator.hpp | 105 ++++++++++++------------ src/Utils/DrawingHelper.hpp | 9 ++ vendors/rlImGui/rlImGui.cpp | 4 +- 4 files changed, 65 insertions(+), 55 deletions(-) diff --git a/src/Editor/RaycastingCameraViewport.hpp b/src/Editor/RaycastingCameraViewport.hpp index 28ed0a8..65ba659 100644 --- a/src/Editor/RaycastingCameraViewport.hpp +++ b/src/Editor/RaycastingCameraViewport.hpp @@ -27,7 +27,7 @@ class RaycastingCameraViewport void DrawGUI() { - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(3, 0)); ImGui::SetNextWindowSizeConstraints(ImVec2(400, 400), ImVec2((float)GetScreenWidth(), (float)GetScreenHeight())); if (ImGui::Begin("3D View", nullptr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_MenuBar)) diff --git a/src/Editor/RenderingOrchestrator.hpp b/src/Editor/RenderingOrchestrator.hpp index e00bb1d..364f79b 100644 --- a/src/Editor/RenderingOrchestrator.hpp +++ b/src/Editor/RenderingOrchestrator.hpp @@ -4,6 +4,7 @@ #include #include "RaycastingCameraViewport.hpp" +#include "Utils/DrawingHelper.hpp" class RenderingOrchestrator { @@ -18,23 +19,17 @@ class RenderingOrchestrator if(play) { - InitilizeFrame(world, cam); - - if(rasterizer.IsRenderIterationRemains()) + AllRenderItr(world, cam); + } + else + { + switch(invokeEvent) { - OneRenderItr(true); + case StepInto: OneRenderItr(world, cam); break; + case StepOver: AllRenderItr(world, cam); break; } - while(rasterizer.IsRenderIterationRemains()) - { - OneRenderItr(false); - } - } - else if(stepByStepNewFrame) - { - stepByStepNewFrame = false; - InitilizeFrame(world, cam); - OneRenderItr(true); + invokeEvent = None; } } @@ -64,67 +59,75 @@ class RenderingOrchestrator } } - void OneRenderItr(bool firstItr) + void AllRenderItr(World &world, RaycastingCamera &cam) { - if(rasterizer.IsRenderIterationRemains()) + do { - auto& renderTexture = cameraViewport.GetRenderTexture(); - - BeginTextureMode(renderTexture); - - if(firstItr) - { - ClearBackground(MY_BLACK); - } + OneRenderItr(world, cam); + } while(rasterizer.IsRenderIterationRemains()); + } - rasterizer.RenderIteration(); - EndTextureMode(); + void OneRenderItr(World &world, RaycastingCamera &cam) + { + if(!rasterizer.IsRenderIterationRemains()) + { + InitilizeFrame(world, cam); + } - auto& ctx = rasterizer.GetContext(); - assert(rasterizingItrsTextures.size() >= ctx.currentRenderItr); + assert(rasterizer.IsRenderIterationRemains()); - auto& texture = rasterizingItrsTextures.at(ctx.currentRenderItr - 1); + auto& renderTexture = cameraViewport.GetRenderTexture(); + auto& ctx = rasterizer.GetContext(); + + BeginTextureMode(renderTexture); - if(texture.id == 0) + if(ctx.currentRenderItr == 0) { - texture = LoadRenderTexture(renderTexture.texture.width, renderTexture.texture.height); + ClearBackground(MY_BLACK); } - BeginTextureMode(texture); - DrawTexture(renderTexture.texture, 0, 0, WHITE); - EndTextureMode(); - } - else + rasterizer.RenderIteration(); + + EndTextureMode(); + + assert(rasterizingItrsTextures.size() >= ctx.currentRenderItr); + assert(ctx.currentRenderItr > 0); + + auto& texture = rasterizingItrsTextures.at(ctx.currentRenderItr - 1); + + if(texture.id == 0) { - stepByStepNewFrame = true; + texture = LoadRenderTexture(renderTexture.texture.width, renderTexture.texture.height); } + + BeginTextureMode(texture); + DrawTextureFlippedY(renderTexture.texture, 0, 0, WHITE); + EndTextureMode(); } void DrawGUI() { ImGui::Begin("Rendering"); - if(ImGui::Button("Play")) + constexpr const char* LabelPlay = "Play"; + constexpr const char* LabelPause = "Pause"; + + if(ImGui::Button(!play ? LabelPlay : LabelPause)) { - play = true; + play = !play; } ImGui::SameLine(); - if(ImGui::Button("Pause")) - { - play = false; - stepByStepNewFrame = true; - } - ImGui::SameLine(); if(ImGui::Button("> Step") && !play) { - OneRenderItr(stepByStepNewFrame); + invokeEvent = StepInto; } ImGui::SameLine(); if(ImGui::Button(">> Step") && !play) { - + invokeEvent = StepOver; } + // Render Iterations UI { auto& ctx = rasterizer.GetContext(); @@ -145,13 +148,11 @@ class RenderingOrchestrator private: RaycastingCameraViewport& cameraViewport; - - // Step By step - bool play = true; - bool stepByStepNewFrame = false; - WorldRasterizer rasterizer; + bool play = true; + enum InvokeEvent { None, StepInto, StepOver }; + InvokeEvent invokeEvent { None }; std::vector rasterizingItrsTextures; }; diff --git a/src/Utils/DrawingHelper.hpp b/src/Utils/DrawingHelper.hpp index 85e0c43..534a29d 100644 --- a/src/Utils/DrawingHelper.hpp +++ b/src/Utils/DrawingHelper.hpp @@ -23,4 +23,13 @@ inline void DrawArrow(Vector2 start, Vector2 end, Color color = RED, float thick Vector2 arrowTipB = Vector2Add(arrowTipEnd, Vector2Scale(arrowLeftPerpDirection, arrowTipWidth)); DrawTriangle(end, arrowTipA, arrowTipB, color); +} + +void DrawTextureFlippedY(const Texture2D& texture, int posX, int posY, Color tint) +{ + Rectangle sourceRec = { 0.0f, 0.0f, (float)texture.width, (float)-texture.height }; // Flip Y axis + Rectangle destRec = { (float)posX, (float)posY, (float)texture.width, (float)texture.height }; + Vector2 origin = { 0.0f, 0.0f }; + + DrawTexturePro(texture, sourceRec, destRec, origin, 0.0f, tint); } \ No newline at end of file diff --git a/vendors/rlImGui/rlImGui.cpp b/vendors/rlImGui/rlImGui.cpp index 3b1fbdc..dda285d 100644 --- a/vendors/rlImGui/rlImGui.cpp +++ b/vendors/rlImGui/rlImGui.cpp @@ -616,7 +616,7 @@ void rlImGuiImageRenderTextureFit(const RenderTexture* image, bool center) ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (area.y / 2 - sizeY / 2)); } - rlImGuiImageRect(&image->texture, sizeX, sizeY, Rectangle{ 0,0, float(image->texture.width), -float(image->texture.height) }); + rlImGuiImageRect(&image->texture, sizeX, sizeY, Rectangle{ 0, 0, float(image->texture.width), -float(image->texture.height) }); } void rlImGuiImageRenderTextureFitWidth(const RenderTexture* image) @@ -629,7 +629,7 @@ void rlImGuiImageRenderTextureFitWidth(const RenderTexture* image) ImVec2 area = ImGui::GetContentRegionAvail(); - float scale = area.x / image->texture.width; + float scale = area.x / image->texture.width; int sizeX = int(image->texture.width * scale); int sizeY = int(image->texture.height * scale);