Fix plotted event not correctly rendered when not the event is not ended

This commit is contained in:
Arnaud Jamin
2025-02-24 23:05:13 -05:00
parent f8e1f98e37
commit 2fc8a64173
5 changed files with 22 additions and 18 deletions
@@ -4,12 +4,13 @@
#include "CogDebugTracker.h"
//--------------------------------------------------------------------------------------------------------------------------
float FCogDebugEvent::GetActualEndTime() const
float FCogDebugEvent::GetActualEndTime(const UWorld& World) const
{
const UWorld* World = Track != nullptr ? Track->World.Get() : nullptr;
const float WorldTime = World != nullptr ? World->GetTimeSeconds() : 0.0f;
const float ActualEndTime = EndTime != 0.0f ? EndTime : WorldTime;
return ActualEndTime;
if (EndTime != 0.0f)
{ return EndTime; }
const float WorldTime = World.GetTimeSeconds();
return WorldTime;
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -71,7 +71,6 @@ void FCogDebugTracker::InitializeTrack(FCogDebugTrack& OutTrack, const UWorld* I
}
OutTrack.Id = InTrackId;
OutTrack.World = InWorld;
OutTrack.Time = InWorld->GetTimeSeconds();
OutTrack.Frame = GFrameCounter;
}
@@ -17,7 +17,7 @@ struct COGDEBUG_API FCogDebugEventParams
//--------------------------------------------------------------------------------------------------------------------------
struct COGDEBUG_API FCogDebugEvent
{
float GetActualEndTime() const;
float GetActualEndTime(const UWorld& World) const;
uint64 GetActualEndFrame() const;
@@ -383,7 +383,8 @@ void FCogEngineWindow_Plots::RenderPlots(FCogDebugTracker& InTracker)
Config->TimeRange = TimeRange;
}
const float Time = GetWorld() ? GetWorld()->GetTimeSeconds() : 0.0;
const UWorld* World = GetWorld();
const float Time = World != nullptr ? World->GetTimeSeconds() : 0.0;
//------------------------------------------------------------------
// Setup all the X axis limits. Must be done before calling
@@ -633,9 +634,14 @@ void FCogEngineWindow_Plots::RenderEvents(FCogDebugEventTrack& InTrack, const ch
for (const FCogDebugEvent& Event : InTrack.Events)
{
const ImVec2 PosBot = ImPlot::PlotToPixels(ImPlotPoint(Event.StartTime, Event.Row + 0.8f));
const ImVec2 PosTop = ImPlot::PlotToPixels(ImPlotPoint(Event.StartTime, Event.Row + 0.2f));
const ImVec2 PosMid(PosBot.x, PosBot.y + (PosTop.y - PosBot.y) * 0.5f);
const ImVec2 PosStartBot = ImPlot::PlotToPixels(ImPlotPoint(Event.StartTime, Event.Row + 0.8f));
const ImVec2 PosStartTop = ImPlot::PlotToPixels(ImPlotPoint(Event.StartTime, Event.Row + 0.2f));
const ImVec2 PosMid(PosStartBot.x, PosStartBot.y + (PosStartTop.y - PosStartBot.y) * 0.5f);
const ImVec2 PosEnd = ImPlot::PlotToPixels(ImPlotPoint(Event.GetActualEndTime(*GetWorld()), 0));
// Clipping
if (PosStartBot.x > InPlotMax.x || PosEnd.x < InPlotMin.x)
{ continue; }
const bool IsInstant = Event.StartTime == Event.EndTime;
if (IsInstant)
@@ -652,10 +658,8 @@ void FCogEngineWindow_Plots::RenderEvents(FCogDebugEventTrack& InTrack, const ch
}
else
{
const float ActualEndTime = Event.GetActualEndTime();
const ImVec2 PosEnd = ImPlot::PlotToPixels(ImPlotPoint(ActualEndTime, 0));
const ImVec2 Min = ImVec2(PosBot.x, PosBot.y);
const ImVec2 Max = ImVec2(PosEnd.x, PosTop.y);
const ImVec2 Min = ImVec2(PosStartBot.x, PosStartBot.y);
const ImVec2 Max = ImVec2(PosEnd.x, PosStartTop.y);
const ImDrawFlags Flags = Event.EndTime == 0.0f ? ImDrawFlags_RoundCornersLeft : ImDrawFlags_RoundCornersAll;
PlotDrawList->AddRect(Min, Max, Event.BorderColor, 6.0f, Flags);
@@ -687,7 +691,7 @@ void FCogEngineWindow_Plots::RenderEvents(FCogDebugEventTrack& InTrack, const ch
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_Plots::RenderEventTooltip(const FCogDebugEvent* HoveredEvent, const FCogDebugTrack& Entry)
void FCogEngineWindow_Plots::RenderEventTooltip(const FCogDebugEvent* HoveredEvent, const FCogDebugTrack& Entry) const
{
if (ImPlot::IsPlotHovered() && HoveredEvent != nullptr)
{
@@ -718,7 +722,7 @@ void FCogEngineWindow_Plots::RenderEventTooltip(const FCogDebugEvent* HoveredEve
//------------------------
if (HoveredEvent->EndTime != HoveredEvent->StartTime)
{
const float ActualEndTime = HoveredEvent->GetActualEndTime();
const float ActualEndTime = HoveredEvent->GetActualEndTime(*GetWorld());
const uint64 ActualEndFrame = HoveredEvent->GetActualEndFrame();
ImGui::TableNextRow();
@@ -47,7 +47,7 @@ protected:
virtual void RenderEvents(FCogDebugEventTrack& InTrack, const char* InLabel, const ImVec2& InPlotMin, const ImVec2& InPlotMax) const;
static void RenderEventTooltip(const FCogDebugEvent* HoveredEvent, const FCogDebugTrack& Entry);
virtual void RenderEventTooltip(const FCogDebugEvent* HoveredEvent, const FCogDebugTrack& Entry) const;
virtual void AssignToGraphAndAxis(FCogDebugTracker& InTracker, FName InName, int32 InGraphIndex, ImAxis InYAxis);