Skip to content

Commit

Permalink
Editor : Enhanced StepInto & StepOver
Browse files Browse the repository at this point in the history
  • Loading branch information
P0ulpy committed Oct 5, 2024
1 parent 8d4a03c commit 45ff273
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/Editor/RaycastingCameraViewport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
105 changes: 53 additions & 52 deletions src/Editor/RenderingOrchestrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <vector>

#include "RaycastingCameraViewport.hpp"
#include "Utils/DrawingHelper.hpp"

class RenderingOrchestrator
{
Expand All @@ -18,23 +19,17 @@ class RenderingOrchestrator

if(play)
{
InitilizeFrame(world, cam);

if(rasterizer.IsRenderIterationRemains())
AllRenderItr(world, cam);
}
else
{
switch(invokeEvent)

Check warning on line 26 in src/Editor/RenderingOrchestrator.hpp

View workflow job for this annotation

GitHub Actions / macos-latest-clang-Debug-Build

enumeration value 'None' not handled in switch [-Wswitch]

Check warning on line 26 in src/Editor/RenderingOrchestrator.hpp

View workflow job for this annotation

GitHub Actions / macos-latest-gcc-Debug-Build

enumeration value 'None' not handled in switch [-Wswitch]

Check warning on line 26 in src/Editor/RenderingOrchestrator.hpp

View workflow job for this annotation

GitHub Actions / macos-latest-clang-Release-Build

enumeration value 'None' not handled in switch [-Wswitch]

Check warning on line 26 in src/Editor/RenderingOrchestrator.hpp

View workflow job for this annotation

GitHub Actions / macos-latest-gcc-Release-Build

enumeration value 'None' not handled in switch [-Wswitch]
{
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;
}
}

Expand Down Expand Up @@ -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();

Expand All @@ -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<RenderTexture> rasterizingItrsTextures;
};

9 changes: 9 additions & 0 deletions src/Utils/DrawingHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions vendors/rlImGui/rlImGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit 45ff273

Please sign in to comment.