CogEngine: improve plot events automatic row manangement

CogSample: plot Ability Activate/End event
This commit is contained in:
Arnaud Jamin
2025-01-16 19:30:12 -05:00
parent 4491614a0d
commit dcce0f1b47
6 changed files with 106 additions and 64 deletions
+4
View File
@@ -1,3 +1,4 @@
;METADATA=(Diff=true, UseCommands=true)
[/Script/GameplayTags.GameplayTagsSettings] [/Script/GameplayTags.GameplayTagsSettings]
ImportTagsFromConfig=True ImportTagsFromConfig=True
WarnOnInvalidTags=True WarnOnInvalidTags=True
@@ -5,9 +6,12 @@ ClearInvalidTags=False
AllowEditorTagUnloading=True AllowEditorTagUnloading=True
AllowGameTagUnloading=False AllowGameTagUnloading=False
FastReplication=False FastReplication=False
bDynamicReplication=False
InvalidTagCharacters="\"\'," InvalidTagCharacters="\"\',"
NumBitsForContainerSize=6 NumBitsForContainerSize=6
NetIndexFirstBitSegment=16 NetIndexFirstBitSegment=16
+GameplayTagList=(Tag="Effect.Type.Damage.Magical",DevComment="")
+GameplayTagList=(Tag="Effect.Type.Damage.Physical",DevComment="")
+GameplayTagList=(Tag="GameplayCue.Ability.Hero1.Poison",DevComment="") +GameplayTagList=(Tag="GameplayCue.Ability.Hero1.Poison",DevComment="")
+GameplayTagList=(Tag="GameplayCue.Ability.Hero1.PuhBack",DevComment="") +GameplayTagList=(Tag="GameplayCue.Ability.Hero1.PuhBack",DevComment="")
+GameplayTagList=(Tag="GameplayCue.Ability.Hero1.Shield",DevComment="") +GameplayTagList=(Tag="GameplayCue.Ability.Hero1.Shield",DevComment="")
@@ -1,7 +1,6 @@
#include "CogDebugPlot.h" #include "CogDebugPlot.h"
#include "CogDebug.h" #include "CogDebug.h"
#include "CogDebugDraw.h"
#include "CogDebugHelper.h" #include "CogDebugHelper.h"
#include "CogImguiHelper.h" #include "CogImguiHelper.h"
#include "Engine/Engine.h" #include "Engine/Engine.h"
@@ -13,6 +12,7 @@ bool FCogDebugPlot::IsVisible = false;
bool FCogDebugPlot::Pause = false; bool FCogDebugPlot::Pause = false;
FName FCogDebugPlot::LastAddedEventPlotName = NAME_None; FName FCogDebugPlot::LastAddedEventPlotName = NAME_None;
int32 FCogDebugPlot::LastAddedEventIndex = INDEX_NONE; int32 FCogDebugPlot::LastAddedEventIndex = INDEX_NONE;
TMap<int32, int32> FCogDebugPlot::OccupiedRowMap;
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// FCogPlotEvent // FCogPlotEvent
@@ -131,10 +131,9 @@ FCogDebugPlotEvent& FCogDebugPlotEntry::AddEvent(
Events.Reserve(200); Events.Reserve(200);
} }
//----------------------------------------------------------------------- //----------------------------
// We currently having two events with the same name at the same time. // Stop if any already exist.
// So we stop the current one if any exist. //----------------------------
//-----------------------------------------------------------------------
StopEvent(EventId); StopEvent(EventId);
FCogDebugPlotEvent* Event = nullptr; FCogDebugPlotEvent* Event = nullptr;
@@ -159,7 +158,12 @@ FCogDebugPlotEvent& FCogDebugPlotEntry::AddEvent(
Event->EndTime = IsInstant ? OwnwePlot.Time : 0.0f; Event->EndTime = IsInstant ? OwnwePlot.Time : 0.0f;
Event->StartFrame = OwnwePlot.Frame; Event->StartFrame = OwnwePlot.Frame;
Event->EndFrame = IsInstant ? OwnwePlot.Frame : 0.0f; Event->EndFrame = IsInstant ? OwnwePlot.Frame : 0.0f;
Event->Row = (Row == FCogDebugPlot::AutoRow) ? OwnwePlot.FindFreeRow() : Row; Event->Row = (Row == FCogDebugPlot::AutoRow) ? FCogDebugPlot::FindFreeEventRow() : Row;
if (IsInstant == false)
{
FCogDebugPlot::OccupyRow(Event->Row);
}
MaxRow = FMath::Max(Event->Row, MaxRow); MaxRow = FMath::Max(Event->Row, MaxRow);
@@ -187,6 +191,8 @@ FCogDebugPlotEvent& FCogDebugPlotEntry::StopEvent(const FName EventId)
{ {
Event->EndTime = Time; Event->EndTime = Time;
Event->EndFrame = Frame; Event->EndFrame = Frame;
FCogDebugPlot::FreeRow(Event->Row);
} }
return *Event; return *Event;
@@ -239,54 +245,6 @@ FCogDebugPlotEvent* FCogDebugPlotEntry::FindLastEventByName(FName EventId)
return nullptr; return nullptr;
} }
//--------------------------------------------------------------------------------------------------------------------------
int32 FCogDebugPlotEntry::FindFreeRow() const
{
static float InstantTimeThreshold = 1.0f;
static float TotalTimeThreshold = 10.0f;
TSet<int32> OccupiedRows;
for (int32 i = Events.Num() - 1; i >= 0; --i)
{
int32 Index = i;
if (EventOffset != 0)
{
Index = (i + EventOffset) % Events.Num();
}
const FCogDebugPlotEvent& Event = Events[Index];
if (Event.EndTime != 0.0f && Time > Event.EndTime + TotalTimeThreshold)
{
break;
}
if (Event.StartTime == Event.EndTime && Time > Event.EndTime + InstantTimeThreshold)
{
continue;
}
if (Event.EndTime != 0.0f)
{
continue;
}
OccupiedRows.Add(Event.Row);
}
int32 FreeRow = 0;
while (true)
{
if (OccupiedRows.Contains(FreeRow) == false)
{
break;
}
FreeRow++;
}
return FreeRow;
}
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugPlotEntry::AssignAxis(int32 Row, ImAxis YAxis) void FCogDebugPlotEntry::AssignAxis(int32 Row, ImAxis YAxis)
{ {
@@ -368,6 +326,7 @@ bool FCogDebugPlotEntry::FindValue(float x, float& y) const
void FCogDebugPlot::Reset() void FCogDebugPlot::Reset()
{ {
Plots.Empty(); Plots.Empty();
OccupiedRowMap.Empty();
Pause = false; Pause = false;
ResetLastAddedEvent(); ResetLastAddedEvent();
} }
@@ -375,11 +334,12 @@ void FCogDebugPlot::Reset()
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugPlot::Clear() void FCogDebugPlot::Clear()
{ {
for (FCogDebugPlotEntry& Entry : FCogDebugPlot::Plots) for (FCogDebugPlotEntry& Entry : Plots)
{ {
Entry.Clear(); Entry.Clear();
} }
OccupiedRowMap.Empty();
ResetLastAddedEvent(); ResetLastAddedEvent();
} }
@@ -522,3 +482,45 @@ FCogDebugPlotEvent& FCogDebugPlot::PlotEventToggle(const UObject* WorldContextOb
return PlotEventStop(WorldContextObject, PlotName, EventId); return PlotEventStop(WorldContextObject, PlotName, EventId);
} }
} }
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugPlot::OccupyRow(const int32 Row)
{
if (int32* RowOccupation = OccupiedRowMap.Find(Row))
{
(*RowOccupation)++;
}
else
{
OccupiedRowMap.Add(Row, 1);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogDebugPlot::FreeRow(const int32 Row)
{
if (int32* RowOccupation = OccupiedRowMap.Find(Row))
{
(*RowOccupation)--;
}
}
//--------------------------------------------------------------------------------------------------------------------------
int32 FCogDebugPlot::FindFreeEventRow()
{
constexpr int32 MaxRows = 100;
int32 FreeRow = 0;
for (; FreeRow < MaxRows; ++FreeRow)
{
const int32* Occupation = OccupiedRowMap.Find(FreeRow);
if (Occupation == nullptr || *Occupation == 0)
{
break;
}
}
return FreeRow;
}
@@ -57,7 +57,6 @@ struct COGDEBUG_API FCogDebugPlotEntry
FCogDebugPlotEvent& AddEvent(const FCogDebugPlotEntry& OwnwePlot, FString OwnerName, bool IsInstant, const FName EventId, const int32 Row, const FColor& Color); FCogDebugPlotEvent& AddEvent(const FCogDebugPlotEntry& OwnwePlot, FString OwnerName, bool IsInstant, const FName EventId, const int32 Row, const FColor& Color);
FCogDebugPlotEvent& StopEvent(const FName EventId); FCogDebugPlotEvent& StopEvent(const FName EventId);
void UpdateTime(const UWorld* World); void UpdateTime(const UWorld* World);
int32 FindFreeRow() const;
FCogDebugPlotEvent* GetLastEvent(); FCogDebugPlotEvent* GetLastEvent();
FCogDebugPlotEvent* FindLastEventByName(FName EventId); FCogDebugPlotEvent* FindLastEventByName(FName EventId);
@@ -109,14 +108,24 @@ private:
friend struct FCogDebugPlotEntry; friend struct FCogDebugPlotEntry;
static void ResetLastAddedEvent(); static void ResetLastAddedEvent();
static FCogDebugPlotEntry* RegisterPlot(const UObject* Owner, const FName PlotName, bool IsEventPlot);
FCogDebugPlotEventParams* PlotEventAddParam(const FName Name); static FCogDebugPlotEntry* RegisterPlot(const UObject* Owner, const FName PlotName, bool IsEventPlot);
static FCogDebugPlotEvent* GetLastAddedEvent(); static FCogDebugPlotEvent* GetLastAddedEvent();
static void OccupyRow(const int32 Row);
static void FreeRow(const int32 Row);
static int32 FindFreeEventRow();
static FName LastAddedEventPlotName; static FName LastAddedEventPlotName;
static int32 LastAddedEventIndex;
static int32 LastAddedEventIndex;
static FCogDebugPlotEvent DefaultEvent; static FCogDebugPlotEvent DefaultEvent;
static TMap<int32, int32> OccupiedRowMap;
}; };
#endif //ENABLE_COG #endif //ENABLE_COG
@@ -106,11 +106,6 @@ void FCogEngineWindow_Plots::RenderMenu()
if (ImGui::BeginMenu("Options")) if (ImGui::BeginMenu("Options"))
{ {
if (ImGui::MenuItem("Clear data"))
{
FCogDebugPlot::Clear();
}
if (ImGui::MenuItem("Reset")) if (ImGui::MenuItem("Reset"))
{ {
FCogDebugPlot::Pause = false; FCogDebugPlot::Pause = false;
@@ -154,6 +149,11 @@ void FCogEngineWindow_Plots::RenderMenu()
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::MenuItem("Clear"))
{
FCogDebugPlot::Clear();
}
FCogWindowWidgets::ToggleMenuButton(&FCogDebugPlot::Pause, "Pause", ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); FCogWindowWidgets::ToggleMenuButton(&FCogDebugPlot::Pause, "Pause", ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
ImGui::EndMenuBar(); ImGui::EndMenuBar();
@@ -8,6 +8,10 @@
#include "CogSamplePlayerController.h" #include "CogSamplePlayerController.h"
#include "CogSampleSpawnPredictionComponent.h" #include "CogSampleSpawnPredictionComponent.h"
#if ENABLE_COG
#include "CogDebugPlot.h"
#endif
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
UCogSampleGameplayAbility::UCogSampleGameplayAbility() UCogSampleGameplayAbility::UCogSampleGameplayAbility()
{ {
@@ -18,8 +22,24 @@ UCogSampleGameplayAbility::UCogSampleGameplayAbility()
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void UCogSampleGameplayAbility::PreActivate(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, FOnGameplayAbilityEnded::FDelegate* OnGameplayAbilityEndedDelegate, const FGameplayEventData* TriggerEventData) void UCogSampleGameplayAbility::PreActivate(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, FOnGameplayAbilityEnded::FDelegate* OnGameplayAbilityEndedDelegate, const FGameplayEventData* TriggerEventData)
{ {
#if ENABLE_COG
COG_LOG_ABILITY(ELogVerbosity::Verbose, this, TEXT("")); COG_LOG_ABILITY(ELogVerbosity::Verbose, this, TEXT(""));
FCogDebugPlot::PlotEventStart(this, "Ability", GetFName())
.AddParam("Name", GetNameSafe(this))
.AddParam("Owner", GetNameSafe(ActorInfo->OwnerActor.Get()))
.AddParam("Avatar", GetNameSafe(ActorInfo->AvatarActor.Get()))
.AddParam("Player Controller", GetNameSafe(ActorInfo->PlayerController.Get()))
.AddParam("Prediction Key", ActivationInfo.GetActivationPredictionKey().ToString())
.AddParam("Event Tag", TriggerEventData ? *TriggerEventData->EventTag.ToString() : FString("None"))
.AddParam("Event Magnitude", TriggerEventData ? TriggerEventData->EventMagnitude : 0.0f);
#endif
Super::PreActivate(Handle, ActorInfo, ActivationInfo, OnGameplayAbilityEndedDelegate, TriggerEventData); Super::PreActivate(Handle, ActorInfo, ActivationInfo, OnGameplayAbilityEndedDelegate, TriggerEventData);
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -33,7 +53,14 @@ void UCogSampleGameplayAbility::ActivateAbility(const FGameplayAbilitySpecHandle
void UCogSampleGameplayAbility::EndAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, bool bReplicateEndAbility, bool bWasCancelled) void UCogSampleGameplayAbility::EndAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, bool bReplicateEndAbility, bool bWasCancelled)
{ {
Super::EndAbility(Handle, ActorInfo, ActivationInfo, bReplicateEndAbility, bWasCancelled); Super::EndAbility(Handle, ActorInfo, ActivationInfo, bReplicateEndAbility, bWasCancelled);
#if ENABLE_COG
COG_LOG_ABILITY(ELogVerbosity::Verbose, this, TEXT("")); COG_LOG_ABILITY(ELogVerbosity::Verbose, this, TEXT(""));
FCogDebugPlot::PlotEventStop(this, "Ability", GetFName());
#endif
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------