diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index 97ca5a1..75b5382 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -2,6 +2,7 @@ GameDefaultMap=/Game/Maps/L_Level1.L_Level1 EditorStartupMap=/Game/Maps/L_Level1.L_Level1 GlobalDefaultGameMode="/Script/CogSample.CogSampleGameMode" +GameInstanceClass=/Script/CogSample.CogSampleGameInstance [/Script/Engine.RendererSettings] r.ReflectionMethod=1 diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebug.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebug.cpp index 5084132..ce96a85 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebug.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebug.cpp @@ -9,86 +9,21 @@ #include "Misc/EngineVersionComparison.h" //-------------------------------------------------------------------------------------------------------------------------- -TWeakObjectPtr FCogDebug::Selection[] = {}; + TMap FCogDebug::DebugContexts; FCogDebugSettings FCogDebug::Settings = FCogDebugSettings(); //-------------------------------------------------------------------------------------------------------------------------- -void FCogDebug::Reset() +FCogDebugContext& FCogDebug::Get(const int32 InPieId) { - Settings = FCogDebugSettings(); + FCogDebugContext& Context = DebugContexts.FindOrAdd(InPieId); + return Context; } //-------------------------------------------------------------------------------------------------------------------------- -bool FCogDebug::IsDebugActiveForObject(const UObject* WorldContextObject) +FCogDebugContext& FCogDebug::Get() { - const UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); - if (World == nullptr) - { - return true; - } - - if (World->GetNetMode() == NM_DedicatedServer) - { - return true; - } - - const bool Result = IsDebugActiveForObject_Internal(WorldContextObject, Selection[GetPieSessionId()].Get(), Settings.bIsFilteringBySelection); - - return Result; -} - -//-------------------------------------------------------------------------------------------------------------------------- -bool FCogDebug::IsReplicatedDebugActiveForObject(const UObject* WorldContextObject, const AActor* ServerSelection, bool IsServerFilteringBySelection) -{ - return IsDebugActiveForObject_Internal(WorldContextObject, ServerSelection, IsServerFilteringBySelection); -} - -//-------------------------------------------------------------------------------------------------------------------------- -bool FCogDebug::IsDebugActiveForObject_Internal(const UObject* WorldContextObject, const AActor* InSelection, bool InIsFilteringBySelection) -{ - if (InIsFilteringBySelection == false) - { - return true; - } - - if (WorldContextObject == nullptr) - { - return true; - } - - const AActor* SelectionPtr = InSelection; - if (SelectionPtr == nullptr) - { - return true; - } - - const UObject* Outer = WorldContextObject; - for (;;) - { - if (SelectionPtr == Outer) - { - return true; - } - - if (Cast(Outer)) - { - return false; - } - - const UObject* NewOuter = Outer->GetOuter(); - if (NewOuter == Outer || NewOuter == nullptr) - { - return true; - } - - Outer = NewOuter; - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -AActor* FCogDebug::GetSelection() -{ - return Selection[GetPieSessionId()].Get(); + const int32 PieId = GetPieSessionId(); + return Get(PieId); } //-------------------------------------------------------------------------------------------------------------------------- @@ -107,31 +42,91 @@ int32 FCogDebug::GetPieSessionId() //-------------------------------------------------------------------------------------------------------------------------- -void FCogDebug::SetSelection(const UWorld* World, AActor* Value) +void FCogDebug::Reset() { - Selection[GetPieSessionId()] = Value; + Settings = FCogDebugSettings(); +} - ReplicateSelection(World, Value); +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogDebug::IsDebugActiveForObject(const UObject* WorldContextObject) +{ + const UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); + if (World == nullptr) + { return true; } + + if (World->GetNetMode() == NM_DedicatedServer) + { return true; } + + const bool Result = IsDebugActiveForObject_Internal(WorldContextObject, GetSelection(), Settings.bIsFilteringBySelection); + return Result; +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogDebug::IsReplicatedDebugActiveForObject(const UObject* WorldContextObject, const AActor* ServerSelection, bool IsServerFilteringBySelection) +{ + return IsDebugActiveForObject_Internal(WorldContextObject, ServerSelection, IsServerFilteringBySelection); +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogDebug::IsDebugActiveForObject_Internal(const UObject* WorldContextObject, const AActor* InSelection, bool InIsFilteringBySelection) +{ + if (InIsFilteringBySelection == false) + { return true; } + + if (WorldContextObject == nullptr) + { return true; } + + const AActor* SelectionPtr = InSelection; + if (SelectionPtr == nullptr) + { return true; } + + const UObject* Outer = WorldContextObject; + for (;;) + { + if (SelectionPtr == Outer) + { return true; } + + if (Cast(Outer)) + { return false; } + + const UObject* NewOuter = Outer->GetOuter(); + if (NewOuter == Outer || NewOuter == nullptr) + { return true; } + + Outer = NewOuter; + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +AActor* FCogDebug::GetSelection() +{ + return Get().Selection.Get(); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugTracker& FCogDebug::GetTracker() +{ + return Get().Tracker; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebug::SetSelection(AActor* InValue) +{ + Get().Selection = InValue; } //-------------------------------------------------------------------------------------------------------------------------- void FCogDebug::ReplicateSelection(const UWorld* World, AActor* Value) { if (World == nullptr) - { - return; - } + { return; } ACogDebugReplicator* Replicator = ACogDebugReplicator::GetLocalReplicator(*World); if (Replicator == nullptr) - { - return; - } + { return; } if (Replicator->HasAuthority()) - { - return; - } + { return; } Replicator->Server_SetSelection(Value, Settings.ReplicateSelection); } @@ -172,13 +167,9 @@ float FCogDebug::GetDebugDuration(bool bPersistent) float FCogDebug::GetDebugTextDuration(bool bPersistent) { if (bPersistent) - { - return Settings.Persistent ? 100 : Settings.Duration; - } - else - { - return 0.0f; - } + { return Settings.Persistent ? 100 : Settings.Duration; } + + return 0.0f; } //-------------------------------------------------------------------------------------------------------------------------- @@ -215,14 +206,12 @@ uint8 FCogDebug::GetDebugDepthPriority(float InDepthPriority) FColor FCogDebug::ModulateDebugColor(const UWorld* World, const FColor& Color, bool bPersistent) { if (bPersistent == false) - { - return Color; - } + { return Color; } switch (Settings.RecolorMode) { case ECogDebugRecolorMode::None: - { + { return Color; } @@ -285,9 +274,7 @@ bool FCogDebug::IsSecondarySkeletonBone(FName BoneName) for (const FString& Wildcard : Settings.SecondaryBoneWildcards) { if (BoneString.MatchesWildcard(Wildcard)) - { - return true; - } + { return true; } } return false; @@ -367,4 +354,40 @@ void FCogDebug::GetDebugDrawSweepSettings(FCogDebugDrawSweepParams& Params) GetDebugDrawLineTraceSettings(Params); Params.DrawHitShapes = Settings.CollisionQueryDrawHitShapes; -} \ No newline at end of file +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebug::Plot(const UObject* WorldContextObject, const FCogDebugTrackId& InTrackId, const float Value) +{ + Get().Tracker.Plot(WorldContextObject, InTrackId, Value); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebug::StartEvent(const UObject* WorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId, bool IsInstant, const int32 Row, const FColor& Color) +{ + return Get().Tracker.StartEvent(WorldContextObject, InTrackId, InEventId, IsInstant, Row, Color); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebug::InstantEvent(const UObject* WorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugTrackId& InEventId, const int32 Row, const FColor& Color) +{ + return Get().Tracker.InstantEvent(WorldContextObject, InTrackId, InEventId, Row, Color); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebug::StartEvent(const UObject* WorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugTrackId& InEventId, const int32 Row, const FColor& Color) +{ + return Get().Tracker.StartEvent(WorldContextObject, InTrackId, InEventId, Row, Color); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebug::StopEvent(const UObject* WorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugTrackId& InEventId) +{ + return Get().Tracker.StopEvent(WorldContextObject, InTrackId, InEventId); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebug::ToggleEvent(const UObject* WorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugTrackId& InEventId, const bool ToggleValue, const int32 Row, const FColor& Color) +{ + return Get().Tracker.ToggleEvent(WorldContextObject, InTrackId, InEventId, ToggleValue, Row, Color); +} diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugEvent.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugEvent.cpp new file mode 100644 index 0000000..8baa0ac --- /dev/null +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugEvent.cpp @@ -0,0 +1,76 @@ +#include "CogDebugEvent.h" + +#include "CogDebugTrack.h" +#include "CogDebugTracker.h" + +//-------------------------------------------------------------------------------------------------------------------------- +float FCogDebugEvent::GetActualEndTime() 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; +} + +//-------------------------------------------------------------------------------------------------------------------------- +uint64 FCogDebugEvent::GetActualEndFrame() const +{ + const float ActualEndFame = EndFrame != 0.0f ? EndFrame : GFrameCounter; + return ActualEndFame; +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebugEvent::AddParam(const FCogDebugEventParamId& InParamId, bool InValue) +{ + if (Track == nullptr || Track->Owner == nullptr || Track->Owner->IsVisible == false) + { return *this; } + + return AddParam(InParamId, FString::Printf(TEXT("%s"), InValue ? TEXT("True") : TEXT("False"))); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebugEvent::AddParam(const FCogDebugEventParamId& InParamId, int InValue) +{ + if (Track == nullptr || Track->Owner == nullptr || Track->Owner->IsVisible == false) + { return *this; } + + return AddParam(InParamId, FString::Printf(TEXT("%d"), InValue)); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebugEvent::AddParam(const FCogDebugEventParamId& InParamId, float InValue) +{ + if (Track == nullptr || Track->Owner == nullptr || Track->Owner->IsVisible == false) + { return *this; } + + return AddParam(InParamId, FString::Printf(TEXT("%0.2f"), InValue)); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebugEvent::AddParam(const FCogDebugEventParamId& InParamId, FName InValue) +{ + if (Track == nullptr || Track->Owner == nullptr || Track->Owner->IsVisible == false) + { return *this; } + + return AddParam(InParamId, InValue.ToString()); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebugEvent::AddParam(const FCogDebugEventParamId& InParamId, const FString& InValue) +{ + if (Track == nullptr || Track->Owner == nullptr || Track->Owner->IsVisible == false) + { return *this; } + + if (InParamId == "Name") + { + DisplayName = InValue; + } + else + { + FCogDebugEventParams& Param = Params.AddDefaulted_GetRef(); + Param.Name = InParamId; + Param.Value = InValue; + } + + return *this; +} diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugEventTrack.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugEventTrack.cpp new file mode 100644 index 0000000..f555069 --- /dev/null +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugEventTrack.cpp @@ -0,0 +1,144 @@ +#include "CogDebugEventTrack.h" + +#include "CogDebugTracker.h" +#include "CogDebugHelper.h" +#include "CogImguiHelper.h" +#include "Engine/Engine.h" +#include "Engine/World.h" + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebugEventTrack::AddEvent( + const FString& OwnerName, + const bool IsInstant, + const FName EventId, + const int32 Row, + const FColor& Color) +{ + if (Events.Max() < 200) + { + Events.Reserve(200); + } + + //---------------------------- + // Stop if it already exist. + //---------------------------- + StopEvent(EventId); + + FCogDebugEvent* Event; + int32 AddedIndex; + + if (Events.Num() < Events.Max()) + { + Event = &Events.AddDefaulted_GetRef(); + AddedIndex = Events.Num() - 1; + } + else + { + Event = &Events[EventOffset]; + AddedIndex = EventOffset; + EventOffset = (EventOffset + 1) % Events.Num(); + } + + Event->Id = EventId; + Event->OwnerName = OwnerName; + Event->DisplayName = EventId.ToString(); + Event->StartTime = Time; + Event->EndTime = IsInstant ? Time : 0.0f; + Event->StartFrame = Frame; + Event->EndFrame = IsInstant ? Frame : 0.0f; + Event->Row = (Row == FCogDebugTracker::AutoRow) ? Owner->FindFreeViewRow(GraphIndex) : Row; + + if (IsInstant == false) + { + Owner->OccupyViewRow(GraphIndex, Event->Row); + } + + MaxRow = FMath::Max(Event->Row, MaxRow); + + const FColor BorderColor = FCogDebugHelper::GetAutoColor(EventId, Color).WithAlpha(200); + const FColor FillColor = BorderColor.WithAlpha(100); + Event->BorderColor = FCogImguiHelper::ToImColor(BorderColor); + Event->FillColor = FCogImguiHelper::ToImColor(FillColor); + + Owner->LastAddedEventTrackId = Id; + Owner->LastAddedEventIndex = AddedIndex; + + return *Event; +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebugEventTrack::StopEvent(const FCogDebugEventId EventId) +{ + FCogDebugEvent* Event = FindLastEventByName(EventId); + if (Event == nullptr) + { + return Owner->DefaultEvent; + } + + if (Event->EndTime == 0.0f) + { + Event->EndTime = Time; + Event->EndFrame = Frame; + + Owner->FreeViewRow(GraphIndex, Event->Row); + } + + return *Event; +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent* FCogDebugEventTrack::GetLastEvent() +{ + if (Events.Num() == 0) + { + return nullptr; + } + + int32 Index = Events.Num() - 1; + if (EventOffset != 0) + { + Index = (Index + EventOffset) % Events.Num(); + } + + return &Events[Index]; +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent* FCogDebugEventTrack::FindLastEventByName(FCogDebugEventId EventId) +{ + for (int32 i = Events.Num() - 1; i >= 0; --i) + { + //-------------------------------------------------- + // The array cycle so we must offset the index + //-------------------------------------------------- + int32 Index = i; + if (EventOffset != 0) + { + Index = (i + EventOffset) % Events.Num(); + } + + if (Events[Index].Id == EventId) + { + return &Events[Index]; + } + } + + return nullptr; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugEventTrack::Clear() +{ + FCogDebugTrack::Clear(); + + Owner->ResetLastAddedEvent(); + + MaxRow = 0; + + if (Events.Num() > 0) + { + Events.Empty(); + Events.Shrink(); + EventOffset = 0; + } +} diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugPlot.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugPlot.cpp deleted file mode 100644 index 2c384d0..0000000 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugPlot.cpp +++ /dev/null @@ -1,166 +0,0 @@ -#include "CogDebugPlot.h" - -#include "CogDebug.h" -#include "Engine/Engine.h" -#include "Engine/World.h" - -FCogDebugPlotEvent FCogDebugPlot::DefaultEvent; -TMap FCogDebugPlot::Values; -TMap FCogDebugPlot::Events; -int32 FCogDebugPlot::NumRecordedValues = 2000; -bool FCogDebugPlot::IsVisible = false; -bool FCogDebugPlot::Pause = false; -bool FCogDebugPlot::RecordValuesWhenPause = true; -FName FCogDebugPlot::LastAddedEventPlotName = NAME_None; -int32 FCogDebugPlot::LastAddedEventIndex = INDEX_NONE; -TMap> FCogDebugPlot::OccupationMap; - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugPlot::Reset() -{ - Values.Empty(); - Events.Empty(); - OccupationMap.Empty(); - Pause = false; - ResetLastAddedEvent(); -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugPlot::Clear() -{ - for (auto& kv : Values) - { - kv.Value.Clear(); - } - - for (auto& kv : Events) - { - kv.Value.Clear(); - } - - OccupationMap.Empty(); - ResetLastAddedEvent(); -} - -//-------------------------------------------------------------------------------------------------------------------------- -bool FCogDebugPlot::ShouldRegisterEntry(const UObject* WorldContextObject, const UWorld*& World) -{ - //---------------------------------------------------------- - // When not visible, we don't go further for performances. - //---------------------------------------------------------- - if (IsVisible == false) - { - return false; - } - - World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::ReturnNull); - if (World == nullptr) - { - return false; - } - - if (FCogDebug::IsDebugActiveForObject(WorldContextObject) == false) - { - return false; - } - - return true; -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugPlot::InitializeEntry(FCogDebugHistory& OutValue, const UWorld* InWorld, const FName InName) -{ - const float Time = InWorld->GetTimeSeconds(); - if (Time < OutValue.Time) - { - OutValue.Clear(); - } - - OutValue.Name = InName; - OutValue.World = InWorld; - OutValue.Time = InWorld->GetTimeSeconds(); - OutValue.Frame = GFrameCounter; -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugPlot::OccupyGraphRow(const int32 InGraphIndex, const int32 InRow) -{ - TMap& GraphOccupation = OccupationMap.FindOrAdd(InGraphIndex); - - if (int32* RowOccupation = GraphOccupation.Find(InRow)) - { - (*RowOccupation)++; - } - else - { - GraphOccupation.Add(InRow, 1); - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugPlot::FreeGraphRow(const int32 InGraphIndex, const int32 Row) -{ - TMap* GraphOccupation = OccupationMap.Find(InGraphIndex); - if (GraphOccupation == nullptr) - { return; } - - int32* RowOccupation = GraphOccupation->Find(Row); - if (RowOccupation == nullptr) - { return; } - - (*RowOccupation)--; -} - -//-------------------------------------------------------------------------------------------------------------------------- -int32 FCogDebugPlot::FindFreeGraphRow(const int32 InGraphIndex) -{ - constexpr int32 MaxRows = 100; - - int32 FreeRow = 0; - - TMap* GraphOccupation = OccupationMap.Find(InGraphIndex); - if (GraphOccupation == nullptr) - { - return FreeRow; - } - - for (; FreeRow < MaxRows; ++FreeRow) - { - const int32* Occupation = GraphOccupation->Find(FreeRow); - if (Occupation == nullptr || *Occupation == 0) - { - break; - } - } - - return FreeRow; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugHistory* FCogDebugPlot::FindEntry(const FName InName) -{ - FCogDebugHistory* Entry = Events.Find(InName); - if (Entry != nullptr) - { - return Entry; - } - - Entry = Values.Find(InName); - if (Entry != nullptr) - { - return Entry; - } - - return nullptr; -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugPlot::SetNumRecordedValues(int32 InValue) -{ - NumRecordedValues = InValue; - - for (auto& kv : Values) - { - kv.Value.SetNumRecordedValues(InValue); - } -} diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugPlotBlueprint.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugPlotBlueprint.cpp index 2b61343..861853a 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugPlotBlueprint.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugPlotBlueprint.cpp @@ -1,12 +1,12 @@ #include "CogDebugPlotBlueprint.h" #include "CogCommon.h" -#include "CogDebugPlot.h" +#include "CogDebugTracker.h" //-------------------------------------------------------------------------------------------------------------------------- void UCogDebugPlotBlueprint::Plot(const UObject* Owner, const FName Name, const float Value) { #if ENABLE_COG - FCogDebugPlot::PlotValue(Owner, Name, Value); + FCogDebug::Plot(Owner, Name, Value); #endif //ENABLE_COG } diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugPlotEvent.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugPlotEvent.cpp deleted file mode 100644 index 50c4237..0000000 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugPlotEvent.cpp +++ /dev/null @@ -1,315 +0,0 @@ -#include "CogDebugPlot.h" - -#include "CogDebugHelper.h" -#include "CogImguiHelper.h" -#include "Engine/Engine.h" -#include "Engine/World.h" - -//-------------------------------------------------------------------------------------------------------------------------- -float FCogDebugPlotEvent::GetActualEndTime(const FCogDebugHistory& Plot) const -{ - const UWorld* World = Plot.World.Get(); - const float WorldTime = World != nullptr ? World->GetTimeSeconds() : 0.0f; - const float ActualEndTime = EndTime != 0.0f ? EndTime : WorldTime; - return ActualEndTime; -} - -//-------------------------------------------------------------------------------------------------------------------------- -uint64 FCogDebugPlotEvent::GetActualEndFrame(const FCogDebugHistory& Plot) const -{ - const float ActualEndFame = EndFrame != 0.0f ? EndFrame : GFrameCounter; - return ActualEndFame; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent& FCogDebugPlotEvent::AddParam(const FName Name, bool Value) -{ - if (FCogDebugPlot::IsVisible) - { - AddParam(Name, FString::Printf(TEXT("%s"), Value ? TEXT("True") : TEXT("False"))); - } - - return *this; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent& FCogDebugPlotEvent::AddParam(const FName Name, int Value) -{ - if (FCogDebugPlot::IsVisible) - { - AddParam(Name, FString::Printf(TEXT("%d"), Value)); - } - - return *this; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent& FCogDebugPlotEvent::AddParam(const FName Name, float Value) -{ - if (FCogDebugPlot::IsVisible) - { - AddParam(Name, FString::Printf(TEXT("%0.2f"), Value)); - } - - return *this; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent& FCogDebugPlotEvent::AddParam(const FName Name, FName Value) -{ - if (FCogDebugPlot::IsVisible) - { - AddParam(Name, Value.ToString()); - } - - return *this; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent& FCogDebugPlotEvent::AddParam(const FName Name, const FString& Value) -{ - if (FCogDebugPlot::IsVisible) - { - - if (Name == "Name") - { - DisplayName = Value; - } - else - { - FCogDebugPlotEventParams& Param = Params.AddDefaulted_GetRef(); - Param.Name = Name; - Param.Value = Value; - } - } - - return *this; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent& FCogDebugEventHistory::AddEvent( - const FString& OwnerName, - const bool IsInstant, - const FName EventId, - const int32 Row, - const FColor& Color) -{ - if (Events.Max() < 200) - { - Events.Reserve(200); - } - - //---------------------------- - // Stop if it already exist. - //---------------------------- - StopEvent(EventId); - - FCogDebugPlotEvent* Event; - int32 AddedIndex; - - if (Events.Num() < Events.Max()) - { - Event = &Events.AddDefaulted_GetRef(); - AddedIndex = Events.Num() - 1; - } - else - { - Event = &Events[EventOffset]; - AddedIndex = EventOffset; - EventOffset = (EventOffset + 1) % Events.Num(); - } - - Event->Id = EventId; - Event->OwnerName = OwnerName; - Event->DisplayName = EventId.ToString(); - Event->StartTime = Time; - Event->EndTime = IsInstant ? Time : 0.0f; - Event->StartFrame = Frame; - Event->EndFrame = IsInstant ? Frame : 0.0f; - Event->Row = (Row == FCogDebugPlot::AutoRow) ? FCogDebugPlot::FindFreeGraphRow(GraphIndex) : Row; - - if (IsInstant == false) - { - FCogDebugPlot::OccupyGraphRow(GraphIndex, Event->Row); - } - - MaxRow = FMath::Max(Event->Row, MaxRow); - - const FColor BorderColor = FCogDebugHelper::GetAutoColor(EventId, Color).WithAlpha(200); - const FColor FillColor = BorderColor.WithAlpha(100); - Event->BorderColor = FCogImguiHelper::ToImColor(BorderColor); - Event->FillColor = FCogImguiHelper::ToImColor(FillColor); - - FCogDebugPlot::LastAddedEventPlotName = Name; - FCogDebugPlot::LastAddedEventIndex = AddedIndex; - - return *Event; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent& FCogDebugEventHistory::StopEvent(const FName EventId) -{ - FCogDebugPlotEvent* Event = FindLastEventByName(EventId); - if (Event == nullptr) - { - return FCogDebugPlot::DefaultEvent; - } - - if (Event->EndTime == 0.0f) - { - Event->EndTime = Time; - Event->EndFrame = Frame; - - FCogDebugPlot::FreeGraphRow(GraphIndex, Event->Row); - } - - return *Event; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent* FCogDebugEventHistory::GetLastEvent() -{ - if (Events.Num() == 0) - { - return nullptr; - } - - int32 Index = Events.Num() - 1; - if (EventOffset != 0) - { - Index = (Index + EventOffset) % Events.Num(); - } - - return &Events[Index]; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent* FCogDebugEventHistory::FindLastEventByName(FName EventId) -{ - for (int32 i = Events.Num() - 1; i >= 0; --i) - { - //-------------------------------------------------- - // The array cycle so we must offset the index - //-------------------------------------------------- - int32 Index = i; - if (EventOffset != 0) - { - Index = (i + EventOffset) % Events.Num(); - } - - if (Events[Index].Id == EventId) - { - return &Events[Index]; - } - } - - return nullptr; -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugEventHistory::Clear() -{ - FCogDebugHistory::Clear(); - - FCogDebugPlot::ResetLastAddedEvent(); - - MaxRow = 0; - - if (Events.Num() > 0) - { - Events.Empty(); - Events.Shrink(); - EventOffset = 0; - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent& FCogDebugPlot::PlotEvent(const UObject* WorldContextObject, const FName PlotName, const FName EventId, bool IsInstant, const int32 Row, const FColor& Color) -{ - FCogDebugEventHistory* EventHistory = RegisterEvent(WorldContextObject, PlotName); - if (EventHistory == nullptr) - { - ResetLastAddedEvent(); - return DefaultEvent; - } - - FCogDebugPlotEvent& Event = EventHistory->AddEvent(GetNameSafe(WorldContextObject), IsInstant, EventId, Row, Color); - return Event; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent& FCogDebugPlot::PlotEventInstant(const UObject* WorldContextObject, const FName PlotName, const FName EventId, const int32 Row, const FColor& Color) -{ - FCogDebugPlotEvent& Event = PlotEvent(WorldContextObject, PlotName, EventId, true, Row, Color); - return Event; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent& FCogDebugPlot::PlotEventStart(const UObject* WorldContextObject, const FName PlotName, const FName EventId, const int32 Row, const FColor& Color) -{ - FCogDebugPlotEvent& Event = PlotEvent(WorldContextObject, PlotName, EventId, false, Row, Color); - return Event; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent& FCogDebugPlot::PlotEventStop(const UObject* WorldContextObject, const FName PlotName, const FName EventId) -{ - FCogDebugEventHistory* EventHistory = RegisterEvent(WorldContextObject, PlotName); - if (EventHistory == nullptr) - { - return DefaultEvent; - } - - FCogDebugPlotEvent& Event = EventHistory->StopEvent(EventId); - return Event; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent& FCogDebugPlot::PlotEventToggle(const UObject* WorldContextObject, const FName PlotName, const FName EventId, const bool ToggleValue, const int32 Row, const FColor& Color) -{ - if (ToggleValue) - { - return PlotEventStart(WorldContextObject, PlotName, EventId, Row, Color); - } - else - { - return PlotEventStop(WorldContextObject, PlotName, EventId); - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugEventHistory* FCogDebugPlot::RegisterEvent(const UObject* InWorldContextObject, const FName InName) -{ - - const UWorld* World; - if (ShouldRegisterEntry(InWorldContextObject, World) == false) - { - return nullptr; - } - - FCogDebugEventHistory& Event = Events.FindOrAdd(InName); - Event.Type = FCogDebugHistoryType::Event; - - InitializeEntry(Event, World, InName); - - return &Event; -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugPlot::ResetLastAddedEvent() -{ - LastAddedEventPlotName = NAME_None; - LastAddedEventIndex = INDEX_NONE; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugPlotEvent* FCogDebugPlot::GetLastAddedEvent() -{ - FCogDebugEventHistory* EventHistory = Events.Find(LastAddedEventPlotName); - if (EventHistory == nullptr) - { - return nullptr; - } - - return EventHistory->GetLastEvent(); -} \ No newline at end of file diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugPlotValue.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugPlotValue.cpp deleted file mode 100644 index a9ce059..0000000 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugPlotValue.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "CogDebugPlot.h" - -#include "CogImguiHelper.h" -#include "Engine/Engine.h" -#include "Engine/World.h" - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugValueHistory::SetNumRecordedValues(const int32 Value) -{ - Values.reserve(Value); -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugValueHistory::AddPoint(float X, float Y) -{ - if (Values.Capacity == 0) - { - Values.reserve(FCogDebugPlot::NumRecordedValues); - } - - if (Values.size() < Values.Capacity) - { - Values.push_back(ImVec2(X, Y)); - } - else - { - Values[ValueOffset] = ImVec2(X, Y); - ValueOffset = (ValueOffset + 1) % Values.size(); - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugValueHistory::Clear() -{ - FCogDebugHistory::Clear(); - - if (Values.size() > 0) - { - Values.shrink(0); - ValueOffset = 0; - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -bool FCogDebugValueHistory::FindValue(float x, float& y) const -{ - y = 0.0f; - - bool FoundAfter = false; - bool FoundBefore = false; - - for (int32 i = Values.size() - 1; i >= 0; --i) - { - //-------------------------------------------------- - // The array cycle so we must offset the index - //-------------------------------------------------- - int32 Index = i; - if (ValueOffset != 0) - { - Index = (i + ValueOffset) % Values.size(); - } - - const ImVec2 Point = Values[Index]; - if (Point.x > x) - { - FoundAfter = true; - } - - if (Point.x < x) - { - FoundBefore = true; - } - - if (FoundAfter && FoundBefore) - { - y = Point.y; - return true; - } - } - - return false; -} - -//-------------------------------------------------------------------------------------------------------------------------- -FCogDebugValueHistory* FCogDebugPlot::RegisterValue(const UObject* InWorldContextObject, const FName InName) -{ - const UWorld* World; - if (ShouldRegisterEntry(InWorldContextObject, World) == false) - { - return nullptr; - } - - FCogDebugValueHistory& Value = Values.FindOrAdd(InName); - Value.Type = FCogDebugHistoryType::Value; - - InitializeEntry(Value, World, InName); - - return &Value; -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugPlot::PlotValue(const UObject* WorldContextObject, const FName PlotName, const float Value) -{ - if (Pause && RecordValuesWhenPause == false) - { return; } - - FCogDebugValueHistory* ValueHistory = RegisterValue(WorldContextObject, PlotName); - if (ValueHistory == nullptr) - { return; } - - ValueHistory->AddPoint(ValueHistory->Time, Value); -} diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugReplicator.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugReplicator.cpp index 2517fe3..8314410 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugReplicator.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugReplicator.cpp @@ -217,11 +217,11 @@ void ACogDebugReplicator::Server_SetSelection_Implementation(AActor* Value, bool if (ForceSelection) { - FCogDebug::SetSelection(GetWorld(), Value); + FCogDebug::SetSelection(Value); } else { - FCogDebug::SetSelection(GetWorld(), nullptr); + FCogDebug::SetSelection(nullptr); } diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugTracker.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugTracker.cpp new file mode 100644 index 0000000..5095ab4 --- /dev/null +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugTracker.cpp @@ -0,0 +1,361 @@ +#include "CogDebugTracker.h" + +#include "CogDebug.h" +#include "CogDebugEventTrack.h" +#include "CogDebugPlotTrack.h" +#include "Engine/Engine.h" +#include "Engine/World.h" + +int32 FCogDebugTracker::NumRecordedValues = 2000; +FCogDebugEvent FCogDebugTracker::DefaultEvent; + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugTracker::Reset() +{ + Values.Empty(); + Events.Empty(); + OccupationMap.Empty(); + Pause = false; + ResetLastAddedEvent(); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugTracker::Clear() +{ + for (auto& kv : Values) + { + kv.Value.Clear(); + } + + for (auto& kv : Events) + { + kv.Value.Clear(); + } + + OccupationMap.Empty(); + ResetLastAddedEvent(); +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogDebugTracker::CanCreateTrack(const UObject* WorldContextObject, const UWorld*& World) const +{ + //---------------------------------------------------------- + // When not visible, we don't go further for performances. + //---------------------------------------------------------- + if (IsVisible == false) + { + return false; + } + + World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::ReturnNull); + if (World == nullptr) + { + return false; + } + + if (FCogDebug::IsDebugActiveForObject(WorldContextObject) == false) + { + return false; + } + + return true; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugTracker::InitializeTrack(FCogDebugTrack& OutTrack, const UWorld* InWorld, const FCogDebugTrackId& InTrackId) +{ + const float Time = InWorld->GetTimeSeconds(); + if (Time < OutTrack.Time) + { + OutTrack.Clear(); + } + + OutTrack.Id = InTrackId; + OutTrack.World = InWorld; + OutTrack.Time = InWorld->GetTimeSeconds(); + OutTrack.Frame = GFrameCounter; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugTracker::OccupyViewRow(const int32 InViewIndex, const int32 InRow) +{ + TMap& GraphOccupation = OccupationMap.FindOrAdd(InViewIndex); + + if (int32* RowOccupation = GraphOccupation.Find(InRow)) + { + (*RowOccupation)++; + } + else + { + GraphOccupation.Add(InRow, 1); + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugTracker::FreeViewRow(const int32 InViewIndex, const int32 Row) +{ + TMap* GraphOccupation = OccupationMap.Find(InViewIndex); + if (GraphOccupation == nullptr) + { return; } + + int32* RowOccupation = GraphOccupation->Find(Row); + if (RowOccupation == nullptr) + { return; } + + (*RowOccupation)--; +} + +//-------------------------------------------------------------------------------------------------------------------------- +int32 FCogDebugTracker::FindFreeViewRow(const int32 InViewIndex) +{ + constexpr int32 MaxRows = 100; + + int32 FreeRow = 0; + + TMap* GraphOccupation = OccupationMap.Find(InViewIndex); + if (GraphOccupation == nullptr) + { + return FreeRow; + } + + for (; FreeRow < MaxRows; ++FreeRow) + { + const int32* Occupation = GraphOccupation->Find(FreeRow); + if (Occupation == nullptr || *Occupation == 0) + { + break; + } + } + + return FreeRow; +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugTrack* FCogDebugTracker::FindTrack(const FCogDebugTrackId& InTrackId) +{ + FCogDebugTrack* Track = Events.Find(InTrackId); + if (Track != nullptr) + { + return Track; + } + + Track = Values.Find(InTrackId); + if (Track != nullptr) + { + return Track; + } + + return nullptr; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugTracker::SetNumRecordedValues(const int32 InValue) +{ + NumRecordedValues = InValue; + + for (auto& kv : Values) + { + kv.Value.SetNumPlots(InValue); + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugPlotTrack::SetNumPlots(const int32 Value) +{ + Values.reserve(Value); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugPlotTrack::Plot(float X, float Y) +{ + if (Values.Capacity == 0) + { + Values.reserve(FCogDebugTracker::NumRecordedValues); + } + + if (Values.size() < Values.Capacity) + { + Values.push_back(ImVec2(X, Y)); + } + else + { + Values[ValueOffset] = ImVec2(X, Y); + ValueOffset = (ValueOffset + 1) % Values.size(); + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugPlotTrack::Clear() +{ + FCogDebugTrack::Clear(); + + if (Values.size() > 0) + { + Values.shrink(0); + ValueOffset = 0; + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogDebugPlotTrack::FindValue(float InX, float& OutY) const +{ + OutY = 0.0f; + + bool FoundAfter = false; + bool FoundBefore = false; + + for (int32 i = Values.size() - 1; i >= 0; --i) + { + //-------------------------------------------------- + // The array cycle so we must offset the index + //-------------------------------------------------- + int32 Index = i; + if (ValueOffset != 0) + { + Index = (i + ValueOffset) % Values.size(); + } + + const ImVec2 Point = Values[Index]; + if (Point.x > InX) + { + FoundAfter = true; + } + + if (Point.x < InX) + { + FoundBefore = true; + } + + if (FoundAfter && FoundBefore) + { + OutY = Point.y; + return true; + } + } + + return false; +} + +//-------------------------------------------------------------------------------------------------------------------------- +// Plot Track Creation +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugPlotTrack* FCogDebugTracker::GetOrCreatePlotTrack(const UObject* InWorldContextObject, const FCogDebugTrackId& InTrackId) +{ + const UWorld* World; + if (CanCreateTrack(InWorldContextObject, World) == false) + { + return nullptr; + } + + FCogDebugPlotTrack& Track = Values.FindOrAdd(InTrackId); + Track.Owner = this; + Track.Type = ECogDebugTrackType::Value; + + InitializeTrack(Track, World, InTrackId); + + return &Track; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugTracker::Plot(const UObject* InWorldContextObject, const FName InTrackId, const float Value) +{ + if (Pause && RecordValuesWhenPause == false) + { return; } + + FCogDebugPlotTrack* Track = GetOrCreatePlotTrack(InWorldContextObject, InTrackId); + if (Track == nullptr) + { return; } + + Track->Plot(Track->Time, Value); +} + +//-------------------------------------------------------------------------------------------------------------------------- +// Event Track Creation +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebugTracker::StartEvent(const UObject* InWorldContextObject, const FCogDebugEventId& InTrackId, const FCogDebugEventId& InEventId, bool IsInstant, const int32 Row, const FColor& Color) +{ + FCogDebugEventTrack* Track = GetOrCreateEventTrack(InWorldContextObject, InTrackId); + if (Track == nullptr) + { + ResetLastAddedEvent(); + return DefaultEvent; + } + + FCogDebugEvent& Event = Track->AddEvent(GetNameSafe(InWorldContextObject), IsInstant, InEventId, Row, Color); + return Event; +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebugTracker::InstantEvent(const UObject* InWorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId, const int32 Row, const FColor& Color) +{ + FCogDebugEvent& Event = StartEvent(InWorldContextObject, InTrackId, InEventId, true, Row, Color); + return Event; +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebugTracker::StartEvent(const UObject* InWorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId, const int32 Row, const FColor& Color) +{ + FCogDebugEvent& Event = StartEvent(InWorldContextObject, InTrackId, InEventId, false, Row, Color); + return Event; +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebugTracker::StopEvent(const UObject* InWorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId) +{ + FCogDebugEventTrack* EventHistory = GetOrCreateEventTrack(InWorldContextObject, InTrackId); + if (EventHistory == nullptr) + { + return DefaultEvent; + } + + FCogDebugEvent& Event = EventHistory->StopEvent(InEventId); + return Event; +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent& FCogDebugTracker::ToggleEvent(const UObject* InWorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId, const bool ToggleValue, const int32 Row, const FColor& Color) +{ + if (ToggleValue) + { + return StartEvent(InWorldContextObject, InTrackId, InEventId, Row, Color); + } + else + { + return StopEvent(InWorldContextObject, InTrackId, InEventId); + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEventTrack* FCogDebugTracker::GetOrCreateEventTrack(const UObject* InWorldContextObject, const FCogDebugEventId& InTrackId) +{ + const UWorld* World; + if (CanCreateTrack(InWorldContextObject, World) == false) + { return nullptr; } + + FCogDebugEventTrack& Track = Events.FindOrAdd(InTrackId); + Track.Type = ECogDebugTrackType::Event; + Track.Owner = this; + + InitializeTrack(Track, World, InTrackId); + + return &Track; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugTracker::ResetLastAddedEvent() +{ + LastAddedEventTrackId = NAME_None; + LastAddedEventIndex = INDEX_NONE; +} + +//-------------------------------------------------------------------------------------------------------------------------- +FCogDebugEvent* FCogDebugTracker::GetLastAddedEvent() +{ + FCogDebugEventTrack* EventHistory = Events.Find(LastAddedEventTrackId); + if (EventHistory == nullptr) + { + return nullptr; + } + + return EventHistory->GetLastEvent(); +} diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebug.h b/Plugins/Cog/Source/CogDebug/Public/CogDebug.h index 0ecdc63..a436fd0 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebug.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebug.h @@ -1,9 +1,11 @@ #pragma once #include "CoreMinimal.h" +#include "CogDebugEvent.h" +#include "CogDebugSettings.h" +#include "CogDebugTracker.h" #include "Engine/EngineTypes.h" #include "UObject/WeakObjectPtrTemplates.h" -#include "CogDebug.generated.h" class AActor; class UObject; @@ -12,388 +14,31 @@ struct FCogDebugDrawLineTraceParams; struct FCogDebugDrawOverlapParams; struct FCogDebugDrawSweepParams; -UENUM() -enum class ECogDebugRecolorMode : uint8 +//-------------------------------------------------------------------------------------------------------------------------- +struct FCogDebugContext { - None, - Color, - HueOverTime, - HueOverFrames, -}; - -USTRUCT() -struct FCogDebugSettings -{ - GENERATED_BODY() - - UPROPERTY(Config) - bool bIsFilteringBySelection = true; - - UPROPERTY(Config) - bool ReplicateSelection = true; - - UPROPERTY(Config) - bool Persistent = false; - - UPROPERTY(Config) - bool TextShadow = true; - - UPROPERTY(Config) - bool Fade2D = true; - - UPROPERTY(Config) - float Duration = 3.0f; - - UPROPERTY(Config) - int DepthPriority = 0; - - UPROPERTY(Config) - int Segments = 12; - - UPROPERTY(Config) - float Thickness = 0.0f; - - UPROPERTY(Config) - float ServerThickness = 2.0f; - - UPROPERTY(Config) - float ServerColorMultiplier = 0.8f; - - UPROPERTY(Config) - float ArrowSize = 10.0f; - - UPROPERTY(Config) - float AxesScale = 1.0f; - - UPROPERTY(Config) - ECogDebugRecolorMode RecolorMode = ECogDebugRecolorMode::None; - - UPROPERTY(Config) - float RecolorIntensity = 0.0f; - - UPROPERTY(Config) - FColor RecolorColor = FColor(255, 0, 0, 255); - - UPROPERTY(Config) - float RecolorTimeSpeed = 2.0f; - - UPROPERTY(Config) - int32 RecolorFrameCycle = 6; - - UPROPERTY(Config) - float TextSize = 1.0f; - - UPROPERTY(Config) - bool ActorNameUseLabel = true; - - UPROPERTY(Config) - float GizmoScale = 1.0f; - - UPROPERTY(Config) - bool GizmoUseLocalSpace = false; - - UPROPERTY(Config) - int GizmoZLow = 0; - - UPROPERTY(Config) - int GizmoZHigh = 100; - - UPROPERTY(Config) - float GizmoThicknessZLow = 1.0f; - - UPROPERTY(Config) - float GizmoThicknessZHigh = 0.0f; - - UPROPERTY(Config) - float GizmoCursorDraggingThreshold = 4.0f; - - UPROPERTY(Config) - float GizmoCursorSelectionThreshold = 10.0f; - - UPROPERTY(Config) - float GizmoTranslationAxisLength = 80.0f; - - UPROPERTY(Config) - bool GizmoTranslationSnapEnable = false; - - UPROPERTY(Config) - float GizmoTranslationSnapValue = 10.0f; - - UPROPERTY(Config) - float GizmoTranslationPlaneOffset = 18.0f; - - UPROPERTY(Config) - float GizmoTranslationPlaneExtent = 5.0f; - - UPROPERTY(Config) - bool GizmoRotationSnapEnable = false; - - UPROPERTY(Config) - float GizmoRotationSnapValue = 10.0f; - - UPROPERTY(Config) - float GizmoRotationSpeed = 1.0f; - - UPROPERTY(Config) - float GizmoRotationRadius = 40.0f; - - UPROPERTY(Config) - int GizmoRotationSegments = 8; - - UPROPERTY(Config) - bool GizmoScaleSnapEnable = false; - - UPROPERTY(Config) - float GizmoScaleSnapValue = 1.0f; - - UPROPERTY(Config) - float GizmoScaleBoxOffset = 85.0f; - - UPROPERTY(Config) - float GizmoScaleBoxExtent = 5.0f; - - UPROPERTY(Config) - float GizmoScaleSpeed = 0.01f; - - UPROPERTY(Config) - float GizmoScaleMin = 0.001f; - - UPROPERTY(Config) - float GizmoGroundRaycastLength = 100000.0f; - - UPROPERTY(Config) - TEnumAsByte GizmoGroundRaycastChannel = ECollisionChannel::ECC_WorldStatic; - - UPROPERTY(Config) - float GizmoGroundRaycastCircleRadius = 5.0f; - - UPROPERTY(Config) - FColor GizmoAxisColorsZHighX = FColor(255, 50, 50, 255); - - UPROPERTY(Config) - FColor GizmoAxisColorsZHighY = FColor(50, 255, 50, 255); - - UPROPERTY(Config) - FColor GizmoAxisColorsZHighZ = FColor(50, 50, 255, 255); - - UPROPERTY(Config) - FColor GizmoAxisColorsZHighW = FColor(255, 255, 255, 255); - - UPROPERTY(Config) - FColor GizmoAxisColorsZLowX = FColor(128, 0, 0, 255); - - UPROPERTY(Config) - FColor GizmoAxisColorsZLowY = FColor(0, 128, 0, 255); - - UPROPERTY(Config) - FColor GizmoAxisColorsZLowZ = FColor(0, 0, 128, 255); - - UPROPERTY(Config) - FColor GizmoAxisColorsZLowW = FColor(128, 128, 128, 255); - - UPROPERTY(Config) - FColor GizmoAxisColorsSelectionX = FColor(255, 255, 0, 255); - - UPROPERTY(Config) - FColor GizmoAxisColorsSelectionY = FColor(255, 255, 0, 255); - - UPROPERTY(Config) - FColor GizmoAxisColorsSelectionZ = FColor(255, 255, 0, 255); - - UPROPERTY(Config) - FColor GizmoAxisColorsSelectionW = FColor(255, 255, 0, 255); - - UPROPERTY(Config) - FColor GizmoGroundRaycastColor = FColor(128, 128, 128, 255); - - UPROPERTY(Config) - FColor GizmoGroundRaycastCircleColor = FColor(128, 128, 128, 255); - - UPROPERTY(Config) - FColor GizmoTextColor = FColor(255, 255, 255, 255); - - UPROPERTY(Config) - FColor CollisionQueryHitColor = FColor::Green; - - UPROPERTY(Config) - FColor CollisionQueryNoHitColor = FColor::Red; - - UPROPERTY(Config) - bool CollisionQueryDrawHitPrimitives = true; - - UPROPERTY(Config) - bool CollisionQueryDrawHitPrimitiveActorsName = false; - - UPROPERTY(Config) - bool CollisionQueryHitPrimitiveActorsNameShadow = true; - - UPROPERTY(Config) - float CollisionQueryHitPrimitiveActorsNameSize = 1.0f; - - UPROPERTY(Config) - bool CollisionQueryDrawHitLocation = true; - - UPROPERTY(Config) - bool CollisionQueryDrawHitImpactPoints = true; - - UPROPERTY(Config) - bool CollisionQueryDrawHitNormals = true; - - UPROPERTY(Config) - bool CollisionQueryDrawHitImpactNormals = true; - - UPROPERTY(Config) - float CollisionQueryHitPointSize = 5.0f; - - UPROPERTY(Config) - FColor CollisionQueryNormalColor = FColor::Yellow; - - UPROPERTY(Config) - FColor CollisionQueryImpactNormalColor = FColor::Cyan; - - UPROPERTY(Config) - bool CollisionQueryDrawHitShapes = true; - - UPROPERTY(Config) - FColor ChannelColorWorldStatic = FColor(255, 0, 0, 5); - - UPROPERTY(Config) - FColor ChannelColorWorldDynamic = FColor(255, 0, 188, 5); - - UPROPERTY(Config) - FColor ChannelColorPawn = FColor(105, 0, 255, 5); - - UPROPERTY(Config) - FColor ChannelColorVisibility = FColor(0, 15, 255, 5); - - UPROPERTY(Config) - FColor ChannelColorCamera = FColor(0, 105, 255, 5); - - UPROPERTY(Config) - FColor ChannelColorPhysicsBody = FColor(0, 255, 208, 5); - - UPROPERTY(Config) - FColor ChannelColorVehicle = FColor(52, 255, 0, 5); - - UPROPERTY(Config) - FColor ChannelColorDestructible = FColor(255, 255, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorEngineTraceChannel1 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorEngineTraceChannel2 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorEngineTraceChannel3 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorEngineTraceChannel4 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorEngineTraceChannel5 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorEngineTraceChannel6 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel1 = FColor(255, 105, 0, 5); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel2 = FColor(255, 30, 0, 5); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel3 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel4 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel5 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel6 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel7 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel8 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel9 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel10 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel11 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel12 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel13 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel14 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel15 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel16 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel17 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - FColor ChannelColorGameTraceChannel18 = FColor(0, 0, 0, 0); - - UPROPERTY(Config) - TArray SecondaryBoneWildcards = { - "interaction", - "center_of_mass", - "ik_*", - "index_*", - "middle_*", - "pinky_*", - "ring_*", - "thumb_*", - "wrist_*", - "*_bck_*", - "*_fwd_*", - "*_in_*", - "*_out_*", - "*_pec_*", - "*_scap_*", - "*_bicep_*", - "*_tricep_*", - "*ankle*", - "*knee*", - "*corrective*", - "*twist*", - "*latissimus*", - }; + FCogDebugTracker Tracker; + + TWeakObjectPtr Selection; }; +//-------------------------------------------------------------------------------------------------------------------------- struct COGDEBUG_API FCogDebug { -public: - - //---------------------------------------------------------------------------------------------------------------------- static bool IsDebugActiveForObject(const UObject* WorldContextObject); static bool IsReplicatedDebugActiveForObject(const UObject* WorldContextObject, const AActor* ServerSelection, bool IsServerFilteringBySelection); static AActor* GetSelection(); - static void SetSelection(const UWorld* World, AActor* Value); + static void SetSelection(AActor* InValue); static bool GetIsFilteringBySelection(); static void SetIsFilteringBySelection(const UWorld* World, bool Value); + static FCogDebugTracker& GetTracker(); + static bool GetDebugPersistent(bool bPersistent); static float GetDebugDuration(bool bPersistent); @@ -426,17 +71,32 @@ public: static void GetDebugDrawSweepSettings(FCogDebugDrawSweepParams& Params); + static FCogDebugContext& Get(int32 InPieId); + + static FCogDebugContext& Get(); + + static int32 GetPieSessionId(); + + static void Plot(const UObject* WorldContextObject, const FCogDebugTrackId& InTrackId, const float Value); + + static FCogDebugEvent& StartEvent(const UObject* WorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId, bool IsInstant, const int32 Row = -1, const FColor& Color = FColor::Transparent); + + static FCogDebugEvent& InstantEvent(const UObject* WorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId, const int32 Row = -1, const FColor& Color = FColor::Transparent); + + static FCogDebugEvent& StartEvent(const UObject* WorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId, const int32 Row = -1, const FColor& Color = FColor::Transparent); + + static FCogDebugEvent& StopEvent(const UObject* WorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId); + + static FCogDebugEvent& ToggleEvent(const UObject* WorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId, const bool ToggleValue, const int32 Row = -1, const FColor& Color = FColor::Transparent); + static FCogDebugSettings Settings; private: - static int32 GetPieSessionId(); - static void ReplicateSelection(const UWorld* World, AActor* Value); static bool IsDebugActiveForObject_Internal(const UObject* WorldContextObject, const AActor* InSelection, bool InIsFilteringBySelection); - static constexpr uint32 MaxPie = 16; - - static TWeakObjectPtr Selection[MaxPie]; + static TMap DebugContexts; }; + diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugEvent.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugEvent.h new file mode 100644 index 0000000..75fa2c2 --- /dev/null +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugEvent.h @@ -0,0 +1,57 @@ +#pragma once + +#include "CoreMinimal.h" +#include "imgui.h" + +typedef FName FCogDebugEventId; +typedef FName FCogDebugEventParamId; +struct FCogDebugTrack; + +//-------------------------------------------------------------------------------------------------------------------------- +struct COGDEBUG_API FCogDebugEventParams +{ + FCogDebugEventParamId Name; + FString Value; +}; + +//-------------------------------------------------------------------------------------------------------------------------- +struct COGDEBUG_API FCogDebugEvent +{ + float GetActualEndTime() const; + + uint64 GetActualEndFrame() const; + + FCogDebugEvent& AddParam(const FCogDebugEventParamId& InParamId, bool InValue); + + FCogDebugEvent& AddParam(const FCogDebugEventParamId& InParamId, int InValue); + + FCogDebugEvent& AddParam(const FCogDebugEventParamId& InParamId, float InValue); + + FCogDebugEvent& AddParam(const FCogDebugEventParamId& InParamId, FName InValue); + + FCogDebugEvent& AddParam(const FCogDebugEventParamId& InParamId, const FString& InValue); + + FCogDebugTrack* Track = nullptr; + + FCogDebugEventParamId Id; + + float StartTime = 0.0f; + + float EndTime = 0.0f; + + uint64 StartFrame = 0; + + uint64 EndFrame = 0; + + ImU32 BorderColor; + + ImU32 FillColor; + + int32 Row; + + FString OwnerName; + + FString DisplayName; + + TArray Params; +}; diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugEventTrack.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugEventTrack.h new file mode 100644 index 0000000..cc5cd18 --- /dev/null +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugEventTrack.h @@ -0,0 +1,24 @@ +#pragma once + +#include "CoreMinimal.h" +#include "CogDebugEvent.h" +#include "CogDebugTrack.h" + +struct COGDEBUG_API FCogDebugEventTrack : FCogDebugTrack +{ + FCogDebugEvent& AddEvent(const FString& OwnerName, bool IsInstant, const FCogDebugEventId EventId, const int32 Row, const FColor& Color); + + FCogDebugEvent& StopEvent(const FCogDebugEventId EventId); + + FCogDebugEvent* GetLastEvent(); + + FCogDebugEvent* FindLastEventByName(FCogDebugEventId EventId); + + virtual void Clear() override; + + int32 EventOffset = 0; + + int32 MaxRow = 1; + + TArray Events; +}; diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugPlot.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugPlot.h deleted file mode 100644 index ca43c41..0000000 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebugPlot.h +++ /dev/null @@ -1,192 +0,0 @@ -#pragma once - -#include "CoreMinimal.h" -#include "CogCommon.h" -#include "imgui.h" - -#ifdef ENABLE_COG - -struct FCogDebugHistory; - -//-------------------------------------------------------------------------------------------------------------------------- -struct COGDEBUG_API FCogDebugPlotEventParams -{ - FName Name; - FString Value; -}; - -//-------------------------------------------------------------------------------------------------------------------------- -struct COGDEBUG_API FCogDebugPlotEvent -{ - float GetActualEndTime(const FCogDebugHistory& Plot) const; - - uint64 GetActualEndFrame(const FCogDebugHistory& Plot) const; - - FCogDebugPlotEvent& AddParam(const FName Name, bool Value); - - FCogDebugPlotEvent& AddParam(const FName Name, int Value); - - FCogDebugPlotEvent& AddParam(const FName Name, float Value); - - FCogDebugPlotEvent& AddParam(const FName Name, FName Value); - - FCogDebugPlotEvent& AddParam(const FName Name, const FString& Value); - - FName Id; - float StartTime = 0.0f; - float EndTime = 0.0f; - uint64 StartFrame = 0; - uint64 EndFrame = 0; - ImU32 BorderColor; - ImU32 FillColor; - int32 Row; - FString OwnerName; - FString DisplayName; - TArray Params; -}; - -//-------------------------------------------------------------------------------------------------------------------------- -enum class FCogDebugHistoryType -{ - Value, - Event, -}; - -//-------------------------------------------------------------------------------------------------------------------------- -struct COGDEBUG_API FCogDebugHistory -{ - virtual ~FCogDebugHistory() {} - - virtual void Clear() {} - - FName Name; - - float Time = 0; - - uint64 Frame = 0; - - int32 GraphIndex = 0; - - FCogDebugHistoryType Type = FCogDebugHistoryType::Value; - - TWeakObjectPtr World; -}; - -//-------------------------------------------------------------------------------------------------------------------------- -struct COGDEBUG_API FCogDebugValueHistory : FCogDebugHistory -{ - void AddPoint(float X, float Y); - - bool FindValue(float Time, float& Value) const; - - virtual void Clear() override; - - void SetNumRecordedValues(const int32 Value); - - int32 ValueOffset = 0; - - ImVector Values; - - bool ShowValuesMarkers = false; -}; - -//-------------------------------------------------------------------------------------------------------------------------- -struct COGDEBUG_API FCogDebugEventHistory : FCogDebugHistory -{ - FCogDebugPlotEvent& AddEvent(const FString& OwnerName, bool IsInstant, const FName EventId, const int32 Row, const FColor& Color); - - FCogDebugPlotEvent& StopEvent(const FName EventId); - - FCogDebugPlotEvent* GetLastEvent(); - - FCogDebugPlotEvent* FindLastEventByName(FName EventId); - - virtual void Clear() override; - - int32 EventOffset = 0; - - TArray Events; - - int32 MaxRow = 1; -}; - -//-------------------------------------------------------------------------------------------------------------------------- - -class COGDEBUG_API FCogDebugPlot -{ -public: - static constexpr int32 AutoRow = -1; - - static constexpr int32 MaxNumGraphs = 5; - - static constexpr int32 MaxNumEntriesPerGraph = 10; - - - static void PlotValue(const UObject* WorldContextObject, const FName PlotName, const float Value); - - static FCogDebugPlotEvent& PlotEvent(const UObject* WorldContextObject, const FName PlotName, const FName EventId, bool IsInstant, const int32 Row = AutoRow, const FColor& Color = FColor::Transparent); - - static FCogDebugPlotEvent& PlotEventInstant(const UObject* WorldContextObject, const FName PlotName, const FName EventId, const int32 Row = AutoRow, const FColor& Color = FColor::Transparent); - - static FCogDebugPlotEvent& PlotEventStart(const UObject* WorldContextObject, const FName PlotName, const FName EventId, const int32 Row = AutoRow, const FColor& Color = FColor::Transparent); - - static FCogDebugPlotEvent& PlotEventStop(const UObject* WorldContextObject, const FName PlotName, const FName EventId); - - static FCogDebugPlotEvent& PlotEventToggle(const UObject* WorldContextObject, const FName PlotName, const FName EventId, const bool ToggleValue, const int32 Row = AutoRow, const FColor& Color = FColor::Transparent); - - static FCogDebugHistory* FindEntry(const FName InName); - - static void SetNumRecordedValues(int32 InValue); - - static void Reset(); - - static void Clear(); - - static TMap Values; - - static TMap Events; - - static bool IsVisible; - - static bool Pause; - - static bool RecordValuesWhenPause; - - -private: - friend struct FCogDebugHistory; - friend struct FCogDebugEventHistory; - friend struct FCogDebugValueHistory; - - static void ResetLastAddedEvent(); - - static FCogDebugValueHistory* RegisterValue(const UObject* InWorldContextObject, const FName InName); - - static FCogDebugEventHistory* RegisterEvent(const UObject* InWorldContextObject, const FName InName); - - static bool ShouldRegisterEntry(const UObject* WorldContextObject, const UWorld*& World); - - static void InitializeEntry(FCogDebugHistory& OutValue, const UWorld* InWorld, const FName InName); - - static FCogDebugPlotEvent* GetLastAddedEvent(); - - static void OccupyGraphRow(const int32 InGraphIndex, const int32 InRow); - - static void FreeGraphRow(const int32 InGraphIndex, const int32 InRow); - - static int32 FindFreeGraphRow(const int32 InGraphIndex); - - static int32 NumRecordedValues; - - static FName LastAddedEventPlotName; - - static int32 LastAddedEventIndex; - - static FCogDebugPlotEvent DefaultEvent; - - // graph index to row index to number of objects occupying the row - static TMap> OccupationMap; -}; - -#endif //ENABLE_COG - diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugPlotTrack.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugPlotTrack.h new file mode 100644 index 0000000..c1509f8 --- /dev/null +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugPlotTrack.h @@ -0,0 +1,22 @@ +#pragma once + +#include "CoreMinimal.h" +#include "CogDebugTrack.h" + +//-------------------------------------------------------------------------------------------------------------------------- +struct COGDEBUG_API FCogDebugPlotTrack : FCogDebugTrack +{ + virtual void Clear() override; + + void Plot(float X, float Y); + + bool FindValue(float Time, float& Value) const; + + void SetNumPlots(const int32 Value); + + int32 ValueOffset = 0; + + ImVector Values; + + bool ShowValuesMarkers = false; +}; diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugSettings.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugSettings.h new file mode 100644 index 0000000..37e3661 --- /dev/null +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugSettings.h @@ -0,0 +1,375 @@ +#pragma once + +#include "CoreMinimal.h" +#include "Engine/EngineTypes.h" +#include "CogDebugSettings.generated.h" + +class AActor; +class UObject; +class UWorld; + + +UENUM() +enum class ECogDebugRecolorMode : uint8 +{ + None, + Color, + HueOverTime, + HueOverFrames, +}; + +USTRUCT() +struct FCogDebugSettings +{ + GENERATED_BODY() + + UPROPERTY(Config) + bool bIsFilteringBySelection = true; + + UPROPERTY(Config) + bool ReplicateSelection = true; + + UPROPERTY(Config) + bool Persistent = false; + + UPROPERTY(Config) + bool TextShadow = true; + + UPROPERTY(Config) + bool Fade2D = true; + + UPROPERTY(Config) + float Duration = 3.0f; + + UPROPERTY(Config) + int DepthPriority = 0; + + UPROPERTY(Config) + int Segments = 12; + + UPROPERTY(Config) + float Thickness = 0.0f; + + UPROPERTY(Config) + float ServerThickness = 2.0f; + + UPROPERTY(Config) + float ServerColorMultiplier = 0.8f; + + UPROPERTY(Config) + float ArrowSize = 10.0f; + + UPROPERTY(Config) + float AxesScale = 1.0f; + + UPROPERTY(Config) + ECogDebugRecolorMode RecolorMode = ECogDebugRecolorMode::None; + + UPROPERTY(Config) + float RecolorIntensity = 0.0f; + + UPROPERTY(Config) + FColor RecolorColor = FColor(255, 0, 0, 255); + + UPROPERTY(Config) + float RecolorTimeSpeed = 2.0f; + + UPROPERTY(Config) + int32 RecolorFrameCycle = 6; + + UPROPERTY(Config) + float TextSize = 1.0f; + + UPROPERTY(Config) + bool ActorNameUseLabel = true; + + UPROPERTY(Config) + float GizmoScale = 1.0f; + + UPROPERTY(Config) + bool GizmoUseLocalSpace = false; + + UPROPERTY(Config) + int GizmoZLow = 0; + + UPROPERTY(Config) + int GizmoZHigh = 100; + + UPROPERTY(Config) + float GizmoThicknessZLow = 1.0f; + + UPROPERTY(Config) + float GizmoThicknessZHigh = 0.0f; + + UPROPERTY(Config) + float GizmoCursorDraggingThreshold = 4.0f; + + UPROPERTY(Config) + float GizmoCursorSelectionThreshold = 10.0f; + + UPROPERTY(Config) + float GizmoTranslationAxisLength = 80.0f; + + UPROPERTY(Config) + bool GizmoTranslationSnapEnable = false; + + UPROPERTY(Config) + float GizmoTranslationSnapValue = 10.0f; + + UPROPERTY(Config) + float GizmoTranslationPlaneOffset = 18.0f; + + UPROPERTY(Config) + float GizmoTranslationPlaneExtent = 5.0f; + + UPROPERTY(Config) + bool GizmoRotationSnapEnable = false; + + UPROPERTY(Config) + float GizmoRotationSnapValue = 10.0f; + + UPROPERTY(Config) + float GizmoRotationSpeed = 1.0f; + + UPROPERTY(Config) + float GizmoRotationRadius = 40.0f; + + UPROPERTY(Config) + int GizmoRotationSegments = 8; + + UPROPERTY(Config) + bool GizmoScaleSnapEnable = false; + + UPROPERTY(Config) + float GizmoScaleSnapValue = 1.0f; + + UPROPERTY(Config) + float GizmoScaleBoxOffset = 85.0f; + + UPROPERTY(Config) + float GizmoScaleBoxExtent = 5.0f; + + UPROPERTY(Config) + float GizmoScaleSpeed = 0.01f; + + UPROPERTY(Config) + float GizmoScaleMin = 0.001f; + + UPROPERTY(Config) + float GizmoGroundRaycastLength = 100000.0f; + + UPROPERTY(Config) + TEnumAsByte GizmoGroundRaycastChannel = ECollisionChannel::ECC_WorldStatic; + + UPROPERTY(Config) + float GizmoGroundRaycastCircleRadius = 5.0f; + + UPROPERTY(Config) + FColor GizmoAxisColorsZHighX = FColor(255, 50, 50, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZHighY = FColor(50, 255, 50, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZHighZ = FColor(50, 50, 255, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZHighW = FColor(255, 255, 255, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZLowX = FColor(128, 0, 0, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZLowY = FColor(0, 128, 0, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZLowZ = FColor(0, 0, 128, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZLowW = FColor(128, 128, 128, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsSelectionX = FColor(255, 255, 0, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsSelectionY = FColor(255, 255, 0, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsSelectionZ = FColor(255, 255, 0, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsSelectionW = FColor(255, 255, 0, 255); + + UPROPERTY(Config) + FColor GizmoGroundRaycastColor = FColor(128, 128, 128, 255); + + UPROPERTY(Config) + FColor GizmoGroundRaycastCircleColor = FColor(128, 128, 128, 255); + + UPROPERTY(Config) + FColor GizmoTextColor = FColor(255, 255, 255, 255); + + UPROPERTY(Config) + FColor CollisionQueryHitColor = FColor::Green; + + UPROPERTY(Config) + FColor CollisionQueryNoHitColor = FColor::Red; + + UPROPERTY(Config) + bool CollisionQueryDrawHitPrimitives = true; + + UPROPERTY(Config) + bool CollisionQueryDrawHitPrimitiveActorsName = false; + + UPROPERTY(Config) + bool CollisionQueryHitPrimitiveActorsNameShadow = true; + + UPROPERTY(Config) + float CollisionQueryHitPrimitiveActorsNameSize = 1.0f; + + UPROPERTY(Config) + bool CollisionQueryDrawHitLocation = true; + + UPROPERTY(Config) + bool CollisionQueryDrawHitImpactPoints = true; + + UPROPERTY(Config) + bool CollisionQueryDrawHitNormals = true; + + UPROPERTY(Config) + bool CollisionQueryDrawHitImpactNormals = true; + + UPROPERTY(Config) + float CollisionQueryHitPointSize = 5.0f; + + UPROPERTY(Config) + FColor CollisionQueryNormalColor = FColor::Yellow; + + UPROPERTY(Config) + FColor CollisionQueryImpactNormalColor = FColor::Cyan; + + UPROPERTY(Config) + bool CollisionQueryDrawHitShapes = true; + + UPROPERTY(Config) + FColor ChannelColorWorldStatic = FColor(255, 0, 0, 5); + + UPROPERTY(Config) + FColor ChannelColorWorldDynamic = FColor(255, 0, 188, 5); + + UPROPERTY(Config) + FColor ChannelColorPawn = FColor(105, 0, 255, 5); + + UPROPERTY(Config) + FColor ChannelColorVisibility = FColor(0, 15, 255, 5); + + UPROPERTY(Config) + FColor ChannelColorCamera = FColor(0, 105, 255, 5); + + UPROPERTY(Config) + FColor ChannelColorPhysicsBody = FColor(0, 255, 208, 5); + + UPROPERTY(Config) + FColor ChannelColorVehicle = FColor(52, 255, 0, 5); + + UPROPERTY(Config) + FColor ChannelColorDestructible = FColor(255, 255, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorEngineTraceChannel1 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorEngineTraceChannel2 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorEngineTraceChannel3 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorEngineTraceChannel4 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorEngineTraceChannel5 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorEngineTraceChannel6 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel1 = FColor(255, 105, 0, 5); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel2 = FColor(255, 30, 0, 5); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel3 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel4 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel5 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel6 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel7 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel8 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel9 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel10 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel11 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel12 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel13 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel14 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel15 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel16 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel17 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel18 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + TArray SecondaryBoneWildcards = { + "interaction", + "center_of_mass", + "ik_*", + "index_*", + "middle_*", + "pinky_*", + "ring_*", + "thumb_*", + "wrist_*", + "*_bck_*", + "*_fwd_*", + "*_in_*", + "*_out_*", + "*_pec_*", + "*_scap_*", + "*_bicep_*", + "*_tricep_*", + "*ankle*", + "*knee*", + "*corrective*", + "*twist*", + "*latissimus*", + }; +}; diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugTrack.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugTrack.h new file mode 100644 index 0000000..e6db088 --- /dev/null +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugTrack.h @@ -0,0 +1,36 @@ +#pragma once + +#include "CoreMinimal.h" + +struct FCogDebugTracker; + +typedef FName FCogDebugTrackId; + +//-------------------------------------------------------------------------------------------------------------------------- +enum class ECogDebugTrackType +{ + Value, + Event, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +struct COGDEBUG_API FCogDebugTrack +{ + virtual ~FCogDebugTrack() {} + + virtual void Clear() {} + + FCogDebugTrackId Id; + + float Time = 0; + + uint64 Frame = 0; + + int32 GraphIndex = 0; + + ECogDebugTrackType Type = ECogDebugTrackType::Value; + + TWeakObjectPtr World; + + FCogDebugTracker* Owner = nullptr; + }; diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugTracker.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugTracker.h new file mode 100644 index 0000000..a4b00f4 --- /dev/null +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugTracker.h @@ -0,0 +1,82 @@ +#pragma once + +#include "CoreMinimal.h" + +#include "CogDebugTrack.h" +#include "CogDebugEvent.h" +#include "CogDebugPlotTrack.h" +#include "CogDebugEventTrack.h" + +struct COGDEBUG_API FCogDebugTracker +{ + static constexpr int32 AutoRow = -1; + + static constexpr int32 MaxNumViews = 5; + + static constexpr int32 MaxNumTrackPerView = 10; + + void Plot(const UObject* InWorldContextObject, const FCogDebugTrackId InTrackId, const float Value); + + FCogDebugEvent& InstantEvent(const UObject* InWorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId, const int32 Row = AutoRow, const FColor& Color = FColor::Transparent); + + FCogDebugEvent& StartEvent(const UObject* InWorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId, bool IsInstant, const int32 Row = AutoRow, const FColor& Color = FColor::Transparent); + + FCogDebugEvent& StartEvent(const UObject* InWorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId, const int32 Row = AutoRow, const FColor& Color = FColor::Transparent); + + FCogDebugEvent& StopEvent(const UObject* InWorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId); + + FCogDebugEvent& ToggleEvent(const UObject* InWorldContextObject, const FCogDebugTrackId& InTrackId, const FCogDebugEventId& InEventId, const bool ToggleValue, const int32 Row = AutoRow, const FColor& Color = FColor::Transparent); + + FCogDebugTrack* FindTrack(const FCogDebugTrackId& InTrackId); + + void SetNumRecordedValues(int32 InValue); + + void Reset(); + + void Clear(); + + TMap Values; + + TMap Events; + + bool IsVisible = false; + + bool Pause = false; + + bool RecordValuesWhenPause = true; + +private: + friend struct FCogDebugEvent; + friend struct FCogDebugTrack; + friend struct FCogDebugEventTrack; + friend struct FCogDebugPlotTrack; + + void ResetLastAddedEvent(); + + FCogDebugPlotTrack* GetOrCreatePlotTrack(const UObject* InWorldContextObject, const FCogDebugTrackId& InTrackId); + + FCogDebugEventTrack* GetOrCreateEventTrack(const UObject* InWorldContextObject, const FCogDebugTrackId& InTrackId); + + bool CanCreateTrack(const UObject* WorldContextObject, const UWorld*& World) const; + + static void InitializeTrack(FCogDebugTrack& OutTrack, const UWorld* InWorld, const FCogDebugTrackId& InTrackId); + + FCogDebugEvent* GetLastAddedEvent(); + + void OccupyViewRow(const int32 InViewIndex, const int32 InRow); + + void FreeViewRow(const int32 InViewIndex, const int32 InRow); + + int32 FindFreeViewRow(const int32 InViewIndex); + + static int32 NumRecordedValues; + + static FCogDebugEvent DefaultEvent; + + FCogDebugTrackId LastAddedEventTrackId = NAME_None; + + int32 LastAddedEventIndex = INDEX_NONE; + + // view index to row index to number of objects occupying the row + TMap> OccupationMap; +}; diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp index bb49872..347d76f 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp @@ -47,7 +47,7 @@ void FCogEngineWindow_CollisionTester::RenderContent() NewActor->SetActorLabel(NewActor->GetName().Replace(TEXT("CogEngine"), TEXT(""))); #endif - FCogDebug::SetSelection(GetWorld(), NewActor); + FCogDebug::SetSelection(NewActor); } if (ImGui::BeginItemTooltip()) { @@ -79,7 +79,7 @@ void FCogEngineWindow_CollisionTester::RenderContent() AActor* NewSelection = nullptr; if (FCogWindowWidgets::MenuActorsCombo("CollisionTesters", NewSelection, *GetWorld(), ACogEngineCollisionTester::StaticClass())) { - FCogDebug::SetSelection(GetWorld(), NewSelection); + FCogDebug::SetSelection(NewSelection); } ImGui::EndMenuBar(); diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_OutputLog.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_OutputLog.cpp index ecb6a73..1f336f4 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_OutputLog.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_OutputLog.cpp @@ -221,11 +221,6 @@ void FCogEngineWindow_OutputLog::RenderContent() Clear(); } - if (ImGui::MenuItem("Test")) - { - COG_NOTIFY(TEXT("Test Notification")); - } - ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetFontSize() * 9); diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Plots.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Plots.cpp index 849920f..96af673 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Plots.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Plots.cpp @@ -1,7 +1,9 @@ #include "CogEngineWindow_Plots.h" -#include "CogDebugPlot.h" +#include "CogDebug.h" +#include "CogDebugTracker.h" #include "CogImguiHelper.h" +#include "CogWindowManager.h" #include "CogWindowWidgets.h" #include "Engine/World.h" #include "imgui.h" @@ -14,14 +16,14 @@ void FCogEngineWindow_Plots::Initialize() bHasMenu = true; + auto& Tracker = FCogDebug::GetTracker(); + Tracker.Clear(); + Config = GetConfig(); - if (Config != nullptr) { RefreshPlotSettings(); } - - FCogDebugPlot::Clear(); } //-------------------------------------------------------------------------------------------------------------------------- @@ -44,7 +46,9 @@ void FCogEngineWindow_Plots::ResetConfig() void FCogEngineWindow_Plots::RenderTick(float DeltaTime) { Super::RenderTick(DeltaTime); - FCogDebugPlot::IsVisible = GetIsVisible(); + + FCogDebugTracker& Tracker = FCogDebug::GetTracker(); + Tracker.IsVisible = GetIsVisible(); } //-------------------------------------------------------------------------------------------------------------------------- @@ -64,7 +68,9 @@ void FCogEngineWindow_Plots::RenderContent() { Super::RenderContent(); - RenderMenu(); + FCogDebugTracker& Tracker = FCogDebug::GetTracker(); + + RenderMenu(Tracker); if (Config->DockEntries) { @@ -81,10 +87,10 @@ void FCogEngineWindow_Plots::RenderContent() ImGui::TableNextColumn(); - RenderAllEntriesNames(ImVec2(0, -1)); + RenderAllEntriesNames(Tracker, ImVec2(0, -1)); ImGui::TableNextColumn(); - RenderPlots(); + RenderPlots(Tracker); ImGui::EndTable(); } @@ -92,7 +98,7 @@ void FCogEngineWindow_Plots::RenderContent() } else { - RenderPlots(); + RenderPlots(Tracker); } bApplyTimeScale = false; @@ -101,12 +107,13 @@ void FCogEngineWindow_Plots::RenderContent() //-------------------------------------------------------------------------------------------------------------------------- void FCogEngineWindow_Plots::RefreshPlotSettings() { - FCogDebugPlot::SetNumRecordedValues(Config->NumRecordedValues); - FCogDebugPlot::RecordValuesWhenPause = Config->RecordValuesWhenPaused; + FCogDebugTracker& Tracker = FCogDebug::GetTracker(); + Tracker.SetNumRecordedValues(Config->NumRecordedValues); + Tracker.RecordValuesWhenPause = Config->RecordValuesWhenPaused; } //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Plots::RenderMenu() +void FCogEngineWindow_Plots::RenderMenu(FCogDebugTracker& InTracker) { if (ImGui::BeginMenuBar()) { @@ -114,7 +121,7 @@ void FCogEngineWindow_Plots::RenderMenu() { if (ImGui::BeginMenu("Entries")) { - RenderAllEntriesNames(ImVec2(ImGui::GetFontSize() * 15, ImGui::GetFontSize() * 20)); + RenderAllEntriesNames(InTracker, ImVec2(ImGui::GetFontSize() * 15, ImGui::GetFontSize() * 20)); ImGui::EndMenu(); } } @@ -176,8 +183,8 @@ void FCogEngineWindow_Plots::RenderMenu() if (ImGui::MenuItem("Reset Settings")) { - FCogDebugPlot::Pause = false; - FCogDebugPlot::Reset(); + InTracker.Pause = false; + InTracker.Reset(); ResetConfig(); bApplyTimeScale = true; } @@ -187,17 +194,17 @@ void FCogEngineWindow_Plots::RenderMenu() if (ImGui::MenuItem("Clear")) { - FCogDebugPlot::Clear(); + InTracker.Clear(); } - FCogWindowWidgets::ToggleMenuButton(&FCogDebugPlot::Pause, "Pause", ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); + FCogWindowWidgets::ToggleMenuButton(&InTracker.Pause, "Pause", ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); ImGui::EndMenuBar(); } } //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Plots::RenderEntryName(const int Index, FCogDebugHistory& Entry) +void FCogEngineWindow_Plots::RenderEntryName(FCogDebugTracker& InTracker, const int Index, FCogDebugTrack& Entry) { ImGui::PushID(Index); @@ -206,28 +213,28 @@ void FCogEngineWindow_Plots::RenderEntryName(const int Index, FCogDebugHistory& for (int32 i = 0; i < UCogEngineConfig_Plots::MaxNumGraphs; ++i) { FCogEngineConfig_Plots_GraphInfo& GraphInfo = Config->Graphs[i]; - if (GraphInfo.Entries.ContainsByPredicate([Entry](const auto& InEntry) { return InEntry.Name == Entry.Name; })) + if (GraphInfo.Entries.ContainsByPredicate([Entry](const auto& InEntry) { return InEntry.Name == Entry.Id; })) { IsAssignedToGraph = true; break; } } - if (ImGui::Selectable(TCHAR_TO_ANSI(*Entry.Name.ToString()), IsAssignedToGraph, ImGuiSelectableFlags_AllowDoubleClick)) + if (ImGui::Selectable(TCHAR_TO_ANSI(*Entry.Id.ToString()), IsAssignedToGraph, ImGuiSelectableFlags_AllowDoubleClick)) { if (IsAssignedToGraph) { - UnassignToGraphAndAxis(Entry.Name); + UnassignToGraphAndAxis(InTracker, Entry.Id); } else { - AssignToGraphAndAxis(Entry.Name, 0, ImAxis_Y1); + AssignToGraphAndAxis(InTracker, Entry.Id, 0, ImAxis_Y1); } } if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) { - const auto EntryName = StringCast(*Entry.Name.ToString()); + const auto EntryName = StringCast(*Entry.Id.ToString()); ImGui::SetDragDropPayload("DragAndDrop", EntryName.Get(), EntryName.Length() + 1); ImGui::Text("%s", EntryName.Get()); ImGui::EndDragDropSource(); @@ -237,7 +244,7 @@ void FCogEngineWindow_Plots::RenderEntryName(const int Index, FCogDebugHistory& } //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Plots::RenderAllEntriesNames(const ImVec2& InSize) +void FCogEngineWindow_Plots::RenderAllEntriesNames(FCogDebugTracker& InTracker, const ImVec2& InSize) { const int32 Indent = ImGui::GetFontSize() * 0.5f; @@ -248,15 +255,15 @@ void FCogEngineWindow_Plots::RenderAllEntriesNames(const ImVec2& InSize) if (FCogWindowWidgets::DarkCollapsingHeader("Events", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::Indent(Indent); - if (FCogDebugPlot::Events.IsEmpty()) + if (InTracker.Events.IsEmpty()) { ImGui::TextDisabled("No event added yet"); } else { - for (auto& kv : FCogDebugPlot::Events) + for (auto& kv : InTracker.Events) { - RenderEntryName(Index, kv.Value); + RenderEntryName(InTracker, Index, kv.Value); Index++; } } @@ -266,15 +273,15 @@ void FCogEngineWindow_Plots::RenderAllEntriesNames(const ImVec2& InSize) if (FCogWindowWidgets::DarkCollapsingHeader("Plots", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::Indent(Indent); - if (FCogDebugPlot::Values.IsEmpty()) + if (InTracker.Values.IsEmpty()) { ImGui::TextDisabled("No plot added yet"); } else { - for (auto& kv : FCogDebugPlot::Values) + for (auto& kv : InTracker.Values) { - RenderEntryName(Index, kv.Value); + RenderEntryName(InTracker, Index, kv.Value); Index++; } } @@ -287,14 +294,14 @@ void FCogEngineWindow_Plots::RenderAllEntriesNames(const ImVec2& InSize) { if (const ImGuiPayload* Payload = ImGui::AcceptDragDropPayload("DragAndDrop")) { - UnassignToGraphAndAxis(GetDroppedEntryName(Payload)); + UnassignToGraphAndAxis(InTracker, GetDroppedEntryName(Payload)); } ImGui::EndDragDropTarget(); } } //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Plots::RenderPlots() +void FCogEngineWindow_Plots::RenderPlots(FCogDebugTracker& InTracker) { if (ImGui::BeginChild("Graph", ImVec2(0, -1))) { @@ -302,7 +309,7 @@ void FCogEngineWindow_Plots::RenderPlots() static float ColRatios[] = { 1 }; static ImPlotSubplotFlags SubplotsFlags = ImPlotSubplotFlags_LinkCols; - const bool PushPlotBgStyle = FCogDebugPlot::Pause; + const bool PushPlotBgStyle = InTracker.Pause; if (PushPlotBgStyle) { ImPlot::PushStyleColor(ImPlotCol_PlotBg, FCogImguiHelper::ToImVec4(Config->PauseBackgroundColor)); @@ -340,7 +347,7 @@ void FCogEngineWindow_Plots::RenderPlots() { IsAssigned |= GraphEntry.YAxis == YAxis; - if (FCogDebugEventHistory* EventHistory = FCogDebugPlot::Events.Find(GraphEntry.Name)) + if (FCogDebugEventTrack* EventHistory = InTracker.Events.Find(GraphEntry.Name)) { YMax = FMath::Max(FMath::Max(5, YMax), EventHistory->MaxRow); } @@ -386,7 +393,7 @@ void FCogEngineWindow_Plots::RenderPlots() //-------------------------------------------------------------------------------- // Make the time axis move forward automatically, unless the user pauses or zoom. //-------------------------------------------------------------------------------- - if (FCogDebugPlot::Pause == false && ImGui::GetIO().MouseWheel == 0) + if (InTracker.Pause == false && ImGui::GetIO().MouseWheel == 0) { ImPlot::SetupAxisLimits(ImAxis_X1, Time - TimeRange, Time, ImGuiCond_Always); } @@ -417,14 +424,14 @@ void FCogEngineWindow_Plots::RenderPlots() if (FMath::Abs(Drag.x) > Config->DragPauseSensitivity) { - FCogDebugPlot::Pause = true; + InTracker.Pause = true; } } } if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { - FCogDebugPlot::Pause = false; + InTracker.Pause = false; } //--------------------------------------------------------------------------- @@ -443,7 +450,7 @@ void FCogEngineWindow_Plots::RenderPlots() PlotDrawList->AddLine(ImVec2(ImGui::GetMousePos().x, PlotTop), ImVec2(ImGui::GetMousePos().x, TimeBarBottom), IM_COL32(128, 128, 128, 64)); } - if (Config->ShowTimeBarAtGameTime && FCogDebugPlot::Pause) + if (Config->ShowTimeBarAtGameTime && InTracker.Pause) { const float TimeBarX = ImPlot::PlotToPixels(Time, 0.0f).x; PlotDrawList->AddLine(ImVec2(TimeBarX, PlotTop), ImVec2(TimeBarX, TimeBarBottom), IM_COL32(255, 255, 255, 64)); @@ -456,8 +463,8 @@ void FCogEngineWindow_Plots::RenderPlots() //----------------------------------------------------------- for (FCogEngineConfig_Plots_GraphEntryInfo& Entry : GraphInfo.Entries) { - FCogDebugHistory* History = FCogDebugPlot::FindEntry(Entry.Name); - if (History == nullptr) + FCogDebugTrack* Track = InTracker.FindTrack(Entry.Name); + if (Track == nullptr) { continue; } @@ -470,17 +477,17 @@ void FCogEngineWindow_Plots::RenderPlots() //------------------------------------------------------- // Plot Events //------------------------------------------------------- - switch (History->Type) + switch (Track->Type) { - case FCogDebugHistoryType::Event: + case ECogDebugTrackType::Event: { - RenderEvents(*static_cast(History), Label.Get(), PlotMin, PlotMax); + RenderEvents(*static_cast(Track), Label.Get(), PlotMin, PlotMax); break; } - case FCogDebugHistoryType::Value: + case ECogDebugTrackType::Value: { - RenderValues(*static_cast(History), Label.Get()); + RenderValues(*static_cast(Track), Label.Get()); break; } } @@ -505,7 +512,7 @@ void FCogEngineWindow_Plots::RenderPlots() { if (const ImGuiPayload* Payload = ImGui::AcceptDragDropPayload("DragAndDrop")) { - AssignToGraphAndAxis(GetDroppedEntryName(Payload), GraphIndex, ImAxis_Y1); + AssignToGraphAndAxis(InTracker, GetDroppedEntryName(Payload), GraphIndex, ImAxis_Y1); } ImPlot::EndDragDropTarget(); } @@ -520,7 +527,7 @@ void FCogEngineWindow_Plots::RenderPlots() { if (const ImGuiPayload* Payload = ImGui::AcceptDragDropPayload("DragAndDrop")) { - AssignToGraphAndAxis(GetDroppedEntryName(Payload), GraphIndex, YAxis); + AssignToGraphAndAxis(InTracker, GetDroppedEntryName(Payload), GraphIndex, YAxis); } ImPlot::EndDragDropTarget(); } @@ -533,7 +540,7 @@ void FCogEngineWindow_Plots::RenderPlots() { if (const ImGuiPayload* Payload = ImGui::AcceptDragDropPayload("DragAndDrop")) { - AssignToGraphAndAxis(GetDroppedEntryName(Payload), GraphIndex, ImAxis_Y1); + AssignToGraphAndAxis(InTracker, GetDroppedEntryName(Payload), GraphIndex, ImAxis_Y1); } ImPlot::EndDragDropTarget(); } @@ -557,9 +564,9 @@ void FCogEngineWindow_Plots::RenderPlots() } //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Plots::RenderValues(FCogDebugValueHistory& Entry, const char* Label) const +void FCogEngineWindow_Plots::RenderValues(FCogDebugPlotTrack& Timeline, const char* Label) const { - if (Entry.Values.empty()) + if (Timeline.Values.empty()) { return; } @@ -570,7 +577,7 @@ void FCogEngineWindow_Plots::RenderValues(FCogDebugValueHistory& Entry, const ch if (Config->ShowValueAtCursor && ImPlot::IsPlotHovered()) { float Value; - if (Entry.FindValue(ImPlot::GetPlotMousePos().x, Value)) + if (Timeline.FindValue(ImPlot::GetPlotMousePos().x, Value)) { if (FCogWindowWidgets::BeginTableTooltip()) { @@ -588,26 +595,26 @@ void FCogEngineWindow_Plots::RenderValues(FCogDebugValueHistory& Entry, const ch } } - if (Entry.ShowValuesMarkers) + if (Timeline.ShowValuesMarkers) { ImPlot::SetNextMarkerStyle(ImPlotMarker_Circle); } - ImPlot::PlotLine(Label, &Entry.Values[0].x, &Entry.Values[0].y, Entry.Values.size(), ImPlotLineFlags_None, Entry.ValueOffset, 2 * sizeof(float)); + ImPlot::PlotLine(Label, &Timeline.Values[0].x, &Timeline.Values[0].y, Timeline.Values.size(), ImPlotLineFlags_None, Timeline.ValueOffset, 2 * sizeof(float)); if (ImPlot::BeginLegendPopup(Label)) { if (ImGui::Button("Clear")) { - Entry.Clear(); + Timeline.Clear(); } - ImGui::Checkbox("Show Markers", &Entry.ShowValuesMarkers); + ImGui::Checkbox("Show Markers", &Timeline.ShowValuesMarkers); ImPlot::EndLegendPopup(); } } //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Plots::RenderEvents(FCogDebugEventHistory& Entry, const char* Label, const ImVec2& PlotMin, const ImVec2& PlotMax) const +void FCogEngineWindow_Plots::RenderEvents(FCogDebugEventTrack& InTrack, const char* InLabel, const ImVec2& InPlotMin, const ImVec2& InPlotMax) const { const ImVec2 Mouse = ImGui::GetMousePos(); ImDrawList* PlotDrawList = ImPlot::GetPlotDrawList(); @@ -620,11 +627,11 @@ void FCogEngineWindow_Plots::RenderEvents(FCogDebugEventHistory& Entry, const ch ImVector DummyData; DummyData.push_back(ImVec2(0, 0)); DummyData.push_back(ImVec2(0, 8)); - ImPlot::PlotLine(Label, &DummyData[0].x, &DummyData[0].y, DummyData.size(), Entry.EventOffset, 2 * sizeof(float)); + ImPlot::PlotLine(InLabel, &DummyData[0].x, &DummyData[0].y, DummyData.size(), InTrack.EventOffset, 2 * sizeof(float)); - const FCogDebugPlotEvent* HoveredEvent = nullptr; + const FCogDebugEvent* HoveredEvent = nullptr; - for (const FCogDebugPlotEvent& Event : Entry.Events) + 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)); @@ -645,7 +652,7 @@ void FCogEngineWindow_Plots::RenderEvents(FCogDebugEventHistory& Entry, const ch } else { - const float ActualEndTime = Event.GetActualEndTime(Entry); + 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); @@ -653,7 +660,7 @@ void FCogEngineWindow_Plots::RenderEvents(FCogDebugEventHistory& Entry, const ch const ImDrawFlags Flags = Event.EndTime == 0.0f ? ImDrawFlags_RoundCornersLeft : ImDrawFlags_RoundCornersAll; PlotDrawList->AddRect(Min, Max, Event.BorderColor, 6.0f, Flags); PlotDrawList->AddRectFilled(Min, Max, Event.FillColor, 6.0f, Flags); - PlotDrawList->PushClipRect(ImMax(Min, PlotMin), ImMin(Max, PlotMax)); + PlotDrawList->PushClipRect(ImMax(Min, InPlotMin), ImMin(Max, InPlotMax)); PlotDrawList->AddText(ImVec2(PosMid.x + 5, PosMid.y - 7), IM_COL32(255, 255, 255, 255), TCHAR_TO_ANSI(*Event.DisplayName)); PlotDrawList->PopClipRect(); @@ -669,18 +676,18 @@ void FCogEngineWindow_Plots::RenderEvents(FCogDebugEventHistory& Entry, const ch //------------------------------------------------------- //char Buffer[64]; //ImFormatString(Buffer, 64, "%0.1f %0.1f", Mouse.x, Mouse.y); - //PlotDrawList->AddText(ImVec2(PlotMin.x + 50, PlotMin.y + 100), IM_COL32(255, 255, 255, 255), Buffer); + //PlotDrawList->AddText(ImVec2(InPlotMin.x + 50, InPlotMin.y + 100), IM_COL32(255, 255, 255, 255), Buffer); //------------------------------------------------------- // Hovered event tooltip //------------------------------------------------------- - RenderEventTooltip(HoveredEvent, Entry); + RenderEventTooltip(HoveredEvent, InTrack); ImPlot::PopPlotClipRect(); } //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Plots::RenderEventTooltip(const FCogDebugPlotEvent* HoveredEvent, const FCogDebugHistory& Entry) +void FCogEngineWindow_Plots::RenderEventTooltip(const FCogDebugEvent* HoveredEvent, const FCogDebugTrack& Entry) { if (ImPlot::IsPlotHovered() && HoveredEvent != nullptr) { @@ -711,8 +718,8 @@ void FCogEngineWindow_Plots::RenderEventTooltip(const FCogDebugPlotEvent* Hovere //------------------------ if (HoveredEvent->EndTime != HoveredEvent->StartTime) { - const float ActualEndTime = HoveredEvent->GetActualEndTime(Entry); - const uint64 ActualEndFrame = HoveredEvent->GetActualEndFrame(Entry); + const float ActualEndTime = HoveredEvent->GetActualEndTime(); + const uint64 ActualEndFrame = HoveredEvent->GetActualEndFrame(); ImGui::TableNextRow(); ImGui::TableNextColumn(); @@ -741,7 +748,7 @@ void FCogEngineWindow_Plots::RenderEventTooltip(const FCogDebugPlotEvent* Hovere //------------------------ // Params //------------------------ - for (FCogDebugPlotEventParams Param : HoveredEvent->Params) + for (FCogDebugEventParams Param : HoveredEvent->Params) { ImGui::TableNextRow(); ImGui::TableNextColumn(); @@ -764,11 +771,11 @@ FName FCogEngineWindow_Plots::GetDroppedEntryName(const ImGuiPayload* Payload) } //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Plots::AssignToGraphAndAxis(const FName InName, const int32 InGraphIndex, const ImAxis InYAxis) +void FCogEngineWindow_Plots::AssignToGraphAndAxis(FCogDebugTracker& InTracker, const FName InName, const int32 InGraphIndex, const ImAxis InYAxis) { - UnassignToGraphAndAxis(InName); + UnassignToGraphAndAxis(InTracker, InName); - FCogDebugHistory* History = FCogDebugPlot::FindEntry(InName); + FCogDebugTrack* History = InTracker.FindTrack(InName); if (History == nullptr) { return; } @@ -790,9 +797,9 @@ void FCogEngineWindow_Plots::AssignToGraphAndAxis(const FName InName, const int3 } //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Plots::UnassignToGraphAndAxis(const FName InName) +void FCogEngineWindow_Plots::UnassignToGraphAndAxis(FCogDebugTracker& InTracker, const FName InName) { - const FCogDebugHistory* History = FCogDebugPlot::FindEntry(InName); + const FCogDebugTrack* History = InTracker.FindTrack(InName); if (History == nullptr) { return; } diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp index 495dc58..18584aa 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp @@ -128,7 +128,7 @@ void FCogEngineWindow_Selection::RenderTick(float DeltaTime) { Super::RenderTick(DeltaTime); - if (FCogDebug::GetSelection() == nullptr) + if (GetSelection() == nullptr) { SetGlobalSelection(GetLocalPlayerPawn()); } @@ -236,7 +236,7 @@ bool FCogEngineWindow_Selection::TickSelectionMode() // Prioritize another actor than the selected actor unless we only touch the selected actor. //-------------------------------------------------------------------------------------------------------- TArray IgnoreList; - IgnoreList.Add(FCogDebug::GetSelection()); + IgnoreList.Add(GetSelection()); FHitResult HitResult; for (int i = 0; i < 2; ++i) @@ -328,7 +328,7 @@ void FCogEngineWindow_Selection::RenderActorContextMenu(AActor& Actor) //-------------------------------------------------------------------------------------------------------------------------- void FCogEngineWindow_Selection::SetGlobalSelection(AActor* Value) const { - FCogDebug::SetSelection(GetWorld(), Value); + FCogDebug::SetSelection(Value); } //-------------------------------------------------------------------------------------------------------------------------- diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_TimeScale.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_TimeScale.cpp index fb34b0d..125392f 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_TimeScale.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_TimeScale.cpp @@ -66,7 +66,8 @@ void FCogEngineWindow_TimeScale::RenderMainMenuWidget() ACogEngineReplicator* Replicator = ACogEngineReplicator::GetLocalReplicator(*GetWorld()); if (Replicator == nullptr) { - ImGui::TextDisabled("Invalid Replicator"); + ImGui::TextDisabled("x?"); + ImGui::SetItemTooltip("Invalid Replicator"); return; } diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Plots.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Plots.h index 6d98015..2249316 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Plots.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Plots.h @@ -6,11 +6,12 @@ #include "implot.h" #include "CogEngineWindow_Plots.generated.h" -struct FCogDebugEventHistory; -struct FCogDebugValueHistory; +struct FCogDebugTrack; +struct FCogDebugTracker; +struct FCogDebugPlotTrack; +struct FCogDebugEventTrack; +struct FCogDebugEvent; struct ImVec2; -struct FCogDebugPlotEvent; -struct FCogDebugHistory; class UCogEngineConfig_Plots; //-------------------------------------------------------------------------------------------------------------------------- @@ -34,23 +35,23 @@ protected: virtual void RenderContent() override; - virtual void RenderAllEntriesNames(const ImVec2& InSize); + virtual void RenderAllEntriesNames(FCogDebugTracker& InTracker, const ImVec2& InSize); - virtual void RenderEntryName(const int Index, FCogDebugHistory& Entry); + virtual void RenderEntryName(FCogDebugTracker& InTracker, int Index, FCogDebugTrack& Entry); - virtual void RenderPlots(); + virtual void RenderPlots(FCogDebugTracker& InTracker); - virtual void RenderMenu(); + virtual void RenderMenu(FCogDebugTracker& InTracker); - virtual void RenderValues(FCogDebugValueHistory& Entry, const char* Label) const; + virtual void RenderValues(FCogDebugPlotTrack& Timeline, const char* Label) const; - virtual void RenderEvents(FCogDebugEventHistory& Entry, const char* Label, const ImVec2& PlotMin, const ImVec2& PlotMax) const; + virtual void RenderEvents(FCogDebugEventTrack& InTrack, const char* InLabel, const ImVec2& InPlotMin, const ImVec2& InPlotMax) const; - static void RenderEventTooltip(const FCogDebugPlotEvent* HoveredEvent, const FCogDebugHistory& Entry); + static void RenderEventTooltip(const FCogDebugEvent* HoveredEvent, const FCogDebugTrack& Entry); - virtual void AssignToGraphAndAxis(const FName InName, const int32 InGraphIndex, const ImAxis InYAxis); + virtual void AssignToGraphAndAxis(FCogDebugTracker& InTracker, FName InName, int32 InGraphIndex, ImAxis InYAxis); - virtual void UnassignToGraphAndAxis(const FName InName); + virtual void UnassignToGraphAndAxis(FCogDebugTracker& InTracker, FName InName); virtual void RefreshPlotSettings(); diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiContext.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiContext.cpp index d98b8e5..8610c3d 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiContext.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiContext.cpp @@ -54,11 +54,11 @@ FCogImGuiContextScope::~FCogImGuiContextScope() bool FCogImguiContext::bIsNetImGuiInitialized = false; //-------------------------------------------------------------------------------------------------------------------------- -void FCogImguiContext::Initialize() +void FCogImguiContext::Initialize(UGameViewportClient* InGameViewport) { IMGUI_CHECKVERSION(); - GameViewport = GEngine->GameViewport; + GameViewport = InGameViewport; if (GameViewport != nullptr) { diff --git a/Plugins/Cog/Source/CogImgui/Public/CogImguiContext.h b/Plugins/Cog/Source/CogImgui/Public/CogImguiContext.h index 15f5445..a9dccac 100644 --- a/Plugins/Cog/Source/CogImgui/Public/CogImguiContext.h +++ b/Plugins/Cog/Source/CogImgui/Public/CogImguiContext.h @@ -41,7 +41,7 @@ class COGIMGUI_API FCogImguiContext : public TSharedFromThis { public: - void Initialize(); + void Initialize(UGameViewportClient* InGameViewport); void Shutdown(); diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp index 7343dde..22b27dc 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp @@ -9,6 +9,19 @@ #include "GameFramework/PlayerController.h" #include "Engine/LocalPlayer.h" +//-------------------------------------------------------------------------------------------------------------------------- +void FCogWindow::Initialize() +{ + ensure(bIsInitialized == false); + bIsInitialized = true; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogWindow::Shutdown() +{ + bIsInitialized = false; +} + //-------------------------------------------------------------------------------------------------------------------------- void FCogWindow::SetFullName(const FString& InFullName) { @@ -129,17 +142,18 @@ void FCogWindow::GameTick(float DeltaTime) //-------------------------------------------------------------------------------------------------------------------------- void FCogWindow::SetSelection(AActor* NewSelection) { - if (CurrentSelection == NewSelection) - { - return; - } + AActor* OldActor = GetSelection(); + FCogDebug::SetSelection(NewSelection); - AActor* OldActor = CurrentSelection.Get(); - - CurrentSelection = NewSelection; OnSelectionChanged(OldActor, NewSelection); } +//-------------------------------------------------------------------------------------------------------------------------- +AActor* FCogWindow::GetSelection() const +{ + return FCogDebug::GetSelection(); +} + //-------------------------------------------------------------------------------------------------------------------------- void FCogWindow::SetIsVisible(const bool Value) { diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp index 76ff7e5..957a2d4 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp @@ -1,5 +1,6 @@ #include "CogWindowManager.h" +#include "CogCommon.h" #include "CogDebugDrawImGui.h" #include "CogImguiHelper.h" #include "CogImguiInputHelper.h" @@ -28,9 +29,33 @@ UCogWindowManager::UCogWindowManager() } //-------------------------------------------------------------------------------------------------------------------------- -void UCogWindowManager::InitializeInternal() +void UCogWindowManager::Initialize(FSubsystemCollectionBase& Collection) { - Context.Initialize(); + Super::Initialize(Collection); + FWorldDelegates::OnWorldPostActorTick.AddUObject(this, &ThisClass::Tick); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void UCogWindowManager::Deinitialize() +{ + Super::Deinitialize(); + Shutdown(); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void UCogWindowManager::TryInitializeInternal() +{ + if (IsInitialized) + { return; } + + FWorldContext* WorldContext = GEngine->GetWorldContextFromWorld(GetWorld()); + if (WorldContext == nullptr) + { return; } + + if (WorldContext->GameViewport == nullptr && IsRunningDedicatedServer() == false) + { return; } + + Context.Initialize(WorldContext->GameViewport.Get()); FCogImGuiContextScope ImGuiContextScope(Context); @@ -111,7 +136,6 @@ void UCogWindowManager::InitializeInternal() })); IsInitialized = true; - } //-------------------------------------------------------------------------------------------------------------------------- @@ -155,18 +179,22 @@ void UCogWindowManager::Shutdown() } //-------------------------------------------------------------------------------------------------------------------------- -void UCogWindowManager::Tick(float DeltaTime) +void UCogWindowManager::Tick(UWorld* World, ELevelTick TickType, float DeltaTime) { + //---------------------------------------------------------------------------------------------- + // The tick currently gets called from a static tick function, which tick for all PIE worlds. + // We must not tick for a different world than ours. + // TODO: find a cleaner way to tick only for our world. + //---------------------------------------------------------------------------------------------- + if (GetWorld() != World) + { return; } + FCogImGuiContextScope ImGuiContextScope(Context); - if (GEngine->GameViewport == nullptr && IsRunningDedicatedServer() == false) - { - return; - } - if (IsInitialized == false) { - InitializeInternal(); + TryInitializeInternal(); + return; } if (LayoutToLoad != -1) @@ -247,6 +275,12 @@ void UCogWindowManager::Render(float DeltaTime) //-------------------------------------------------------------------------------------------------------------------------- void UCogWindowManager::AddWindow(FCogWindow* Window, const FString& Name, const bool AddToMainMenu /*= true*/) { + if (Windows.ContainsByPredicate([&](const FCogWindow* w) { return w->GetName() == Name; })) + { + COG_LOG_FUNC(LogCogImGui, ELogVerbosity::Warning, TEXT("Trying to add a window, but one already exist with the same name: %s"), *Name); + return; + } + Window->SetFullName(Name); Window->SetOwner(this); Windows.Add(Window); @@ -745,9 +779,7 @@ void UCogWindowManager::ResetAllWindowsConfig() void UCogWindowManager::AddCommand(UPlayerInput* PlayerInput, const FString& Command, const FKey& Key) { if (PlayerInput == nullptr) - { - return; - } + { return; } //--------------------------------------------------- // Reassign conflicting commands diff --git a/Plugins/Cog/Source/CogWindow/Public/CogWindow.h b/Plugins/Cog/Source/CogWindow/Public/CogWindow.h index ba3c78f..476b2fb 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindow.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindow.h @@ -7,6 +7,7 @@ #include "UObject/ReflectedTypeAccessors.h" #include "UObject/WeakObjectPtrTemplates.h" +struct FCogDebugContext; class AActor; class APawn; class APlayerController; @@ -20,9 +21,9 @@ public: virtual ~FCogWindow() {} - virtual void Initialize() {} + virtual void Initialize(); - virtual void Shutdown() {} + virtual void Shutdown(); virtual void ResetConfig(); @@ -39,7 +40,8 @@ public: /** */ virtual void RenderMainMenuWidget(); - void RenderSettings(); + + virtual void RenderSettings(); ImGuiID GetID() const { return ID; } @@ -51,7 +53,7 @@ public: /** The short name of the window. "Effect" if the window full name is "Gameplay.Character.Effect" */ const FString& GetName() const { return Name; } - AActor* GetSelection() const { return CurrentSelection.Get(); } + AActor* GetSelection() const; void SetSelection(AActor* Actor); @@ -119,8 +121,8 @@ protected: ULocalPlayer* GetLocalPlayer() const; -protected: - + bool bIsInitialized = false; + bool bShowMenu = true; bool bHasMenu = false; @@ -143,10 +145,6 @@ protected: UCogWindowManager* Owner = nullptr; - TWeakObjectPtr CurrentSelection; - - TWeakObjectPtr OverridenSelection; - mutable TArray> ConfigsToResetOnRequest; }; diff --git a/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h b/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h index 5e07959..b4d9a4e 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h @@ -4,6 +4,7 @@ #include "CogImguiContext.h" #include "CogWindow_Settings.h" #include "imgui.h" +#include "Engine/GameInstance.h" #include "CogWindowManager.generated.h" class UCogCommonConfig; @@ -19,7 +20,7 @@ struct ImGuiTextBuffer; struct FKey; UCLASS(Config = Cog) -class COGWINDOW_API UCogWindowManager : public UObject +class COGWINDOW_API UCogWindowManager : public UGameInstanceSubsystem { GENERATED_BODY() @@ -27,14 +28,17 @@ public: UCogWindowManager(); + virtual void Initialize(FSubsystemCollectionBase& Collection) override; + + virtual void Deinitialize() override; + virtual void Shutdown(); virtual void SortMainMenu(); virtual void Render(float DeltaTime); - virtual void Tick(float DeltaTime); - + virtual void Tick(UWorld* World, ELevelTick TickType, float DeltaTime); virtual void AddWindow(FCogWindow* Window, const FString& Name, bool AddToMainMenu = true); @@ -75,15 +79,14 @@ public: FCogImguiContext& GetContext() { return Context; } - - static void AddCommand(UPlayerInput* PlayerInput, const FString& Command, const FKey& Key); - - static void SortCommands(UPlayerInput* PlayerInput); - void OnShortcutsDefined() const; bool IsRenderingMainMenu() const { return IsRenderingInMainMenu; } + static void AddCommand(UPlayerInput* PlayerInput, const FString& Command, const FKey& Key); + + static void SortCommands(UPlayerInput* PlayerInput); + protected: friend class FCogWindow_Layouts; @@ -96,7 +99,7 @@ protected: TArray SubMenus; }; - virtual void InitializeInternal(); + virtual void TryInitializeInternal(); virtual void RenderMainMenu(); @@ -144,7 +147,7 @@ protected: UPROPERTY(Config) bool bShowMainMenu = false; - + FCogImguiContext Context; TArray Windows; diff --git a/README.md b/README.md index f8a0d3b..9f71efa 100644 --- a/README.md +++ b/README.md @@ -250,17 +250,17 @@ Plots values and events overtime. When applicable, only the values and events of - The following code shows how to plot values and events: ```cpp // Plotting a value - FCogDebugPlot::PlotValue(this, "Speed", Velocity.Length()); + FCogDebug::Plot(this, "Speed", Velocity.Length()); // Starting an event - FCogDebugPlot::PlotEvent(this, "Effects", GameplayEffectSpec.Def->GetFName(), GameplayEffectSpec.GetDuration() == 0.0f) + FCogDebug::StartEvent(this, "Effects", GameplayEffectSpec.Def->GetFName(), GameplayEffectSpec.GetDuration() == 0.0f) .AddParam("Name", AbilitySystemComponent->CleanupName(GetNameSafe(GameplayEffectSpec.Def))) .AddParam("Effect Instigator", GetNameSafe(GameplayEffectSpec.GetEffectContext().GetInstigator())) .AddParam("Effect Level", GameplayEffectSpec.GetLevel()) .AddParam("Effect Duration", GameplayEffectSpec.GetDuration()); // Stopping an event - FCogDebugPlot::PlotEventStop(this, "Effects", RemovedGameplayEffect.Spec.Def->GetFName()); + FCogDebug::StopEvent(this, "Effects", RemovedGameplayEffect.Spec.Def->GetFName()); ``` --- diff --git a/Source/CogSample/CogSampleAnimNotify.cpp b/Source/CogSample/CogSampleAnimNotify.cpp index 0f9580c..6eb8bc2 100644 --- a/Source/CogSample/CogSampleAnimNotify.cpp +++ b/Source/CogSample/CogSampleAnimNotify.cpp @@ -6,7 +6,7 @@ #include "Components/SkeletalMeshComponent.h" #if ENABLE_COG -#include "CogDebugPlot.h" +#include "CogDebug.h" #endif //-------------------------------------------------------------------------------------------------------------------------- @@ -22,7 +22,7 @@ void UCogSampleAnimNotify::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenc Super::Notify(MeshComp, Animation, EventReference); #if ENABLE_COG - FCogDebugPlot::PlotEventInstant(MeshComp->GetOwner(), "Anim Notify", GetFName()) + FCogDebug::InstantEvent(MeshComp->GetOwner(), "Anim Notify", GetFName()) .AddParam("Name", GetNameSafe(this)) .AddParam("Animation", GetNameSafe(Animation)) .AddParam("Debug Info", GetDebugInfo()); diff --git a/Source/CogSample/CogSampleAnimNotifyState.cpp b/Source/CogSample/CogSampleAnimNotifyState.cpp index 1469fd1..5c0e5ec 100644 --- a/Source/CogSample/CogSampleAnimNotifyState.cpp +++ b/Source/CogSample/CogSampleAnimNotifyState.cpp @@ -8,7 +8,7 @@ #include "Components/SkeletalMeshComponent.h" #if ENABLE_COG -#include "CogDebugPlot.h" +#include "CogDebug.h" #endif //-------------------------------------------------------------------------------------------------------------------------- @@ -22,7 +22,7 @@ UCogSampleAnimNotifyState::UCogSampleAnimNotifyState(const FObjectInitializer& O void UCogSampleAnimNotifyState::NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float TotalDuration, const FAnimNotifyEventReference& EventReference) { #if ENABLE_COG - FCogDebugPlot::PlotEventStart(MeshComp->GetOwner(), "Anim Notify", GetFName()) + FCogDebug::StartEvent(MeshComp->GetOwner(), "Anim Notify", GetFName()) .AddParam("Name", GetNameSafe(this)) .AddParam("Animation", GetNameSafe(Animation)) .AddParam("Debug Info", GetDebugInfo()); @@ -35,7 +35,7 @@ void UCogSampleAnimNotifyState::NotifyBegin(USkeletalMeshComponent* MeshComp, UA void UCogSampleAnimNotifyState::NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference) { #if ENABLE_COG - FCogDebugPlot::PlotEventStop(MeshComp->GetOwner(), "Anim Notify", GetFName()); + FCogDebug::StopEvent(MeshComp->GetOwner(), "Anim Notify", GetFName()); #endif Super::NotifyEnd(MeshComp, Animation, EventReference); diff --git a/Source/CogSample/CogSampleCharacter.cpp b/Source/CogSample/CogSampleCharacter.cpp index 9a24d42..a2d2bfb 100644 --- a/Source/CogSample/CogSampleCharacter.cpp +++ b/Source/CogSample/CogSampleCharacter.cpp @@ -27,7 +27,7 @@ #if ENABLE_COG #include "CogAbilityReplicator.h" #include "CogDebugMetric.h" -#include "CogDebugPlot.h" +#include "CogDebug.h" #endif //ENABLE_COG //-------------------------------------------------------------------------------------------------------------------------- @@ -402,7 +402,7 @@ void ACogSampleCharacter::OnAbilityInputStarted(const UInputAction* InputAction, COG_LOG_OBJECT(LogCogInput, ELogVerbosity::Verbose, this, TEXT("%d"), Index); #if ENABLE_COG - FCogDebugPlot::PlotEventStart(this, "Input", InputAction->GetFName()); + FCogDebug::StartEvent(this, "Input", InputAction->GetFName()); #endif if (ActiveAbilityHandles.IsValidIndex(Index) == false) @@ -450,7 +450,7 @@ void ACogSampleCharacter::OnAbilityInputCompleted(const UInputAction* InputActio COG_LOG_OBJECT(LogCogInput, ELogVerbosity::Verbose, this, TEXT("%d"), Index); #if ENABLE_COG - FCogDebugPlot::PlotEventStop(this, "Input", InputAction->GetFName()); + FCogDebug::StopEvent(this, "Input", InputAction->GetFName()); #endif if (ActiveAbilityHandles.IsValidIndex(Index) == false) @@ -631,7 +631,7 @@ void ACogSampleCharacter::OnRevived(AActor* InInstigator, AActor* InCauser, cons void ACogSampleCharacter::OnGameplayEffectAdded(UAbilitySystemComponent* AbilitySystemComponent, const FGameplayEffectSpec& GameplayEffectSpec, FActiveGameplayEffectHandle Handle) { #if ENABLE_COG - FCogDebugPlot::PlotEvent(this, "Effects", GameplayEffectSpec.Def->GetFName(), GameplayEffectSpec.GetDuration() == 0.0f) + FCogDebug::StartEvent(this, "Effects", GameplayEffectSpec.Def->GetFName(), GameplayEffectSpec.GetDuration() == 0.0f) .AddParam("Name", AbilitySystemComponent->CleanupName(GetNameSafe(GameplayEffectSpec.Def))) .AddParam("Effect Instigator", GetNameSafe(GameplayEffectSpec.GetEffectContext().GetInstigator())) .AddParam("Effect Level", GameplayEffectSpec.GetLevel()) @@ -643,7 +643,7 @@ void ACogSampleCharacter::OnGameplayEffectAdded(UAbilitySystemComponent* Ability void ACogSampleCharacter::OnGameplayEffectRemoved(const FActiveGameplayEffect& RemovedGameplayEffect) { #if ENABLE_COG - FCogDebugPlot::PlotEventStop(this, "Effects", RemovedGameplayEffect.Spec.Def->GetFName()); + FCogDebug::StopEvent(this, "Effects", RemovedGameplayEffect.Spec.Def->GetFName()); #endif //ENABLE_COG } diff --git a/Source/CogSample/CogSampleCharacterMovementComponent.cpp b/Source/CogSample/CogSampleCharacterMovementComponent.cpp index 0faf51a..f5efda9 100644 --- a/Source/CogSample/CogSampleCharacterMovementComponent.cpp +++ b/Source/CogSample/CogSampleCharacterMovementComponent.cpp @@ -11,7 +11,7 @@ #if ENABLE_COG #include "CogDebugDraw.h" -#include "CogDebugPlot.h" +#include "CogDebug.h" #endif //ENABLE_COG //-------------------------------------------------------------------------------------------------------------------------- @@ -226,10 +226,10 @@ void UCogSampleCharacterMovementComponent::TickComponent(float DeltaTime, enum E if (FCogDebug::IsDebugActiveForObject(GetPawnOwner())) { - FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input X", GetPendingInputVector().X); - FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input Y", GetPendingInputVector().Y); - FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input Local X", FVector::DotProduct(GetPawnOwner()->GetActorRightVector(), GetPendingInputVector())); - FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input Local Y", FVector::DotProduct(GetPawnOwner()->GetActorForwardVector(), GetPendingInputVector())); + FCogDebug::Plot(Character, "Move Input X", GetPendingInputVector().X); + FCogDebug::Plot(Character, "Move Input Y", GetPendingInputVector().Y); + FCogDebug::Plot(Character, "Move Input Local X", FVector::DotProduct(GetPawnOwner()->GetActorRightVector(), GetPendingInputVector())); + FCogDebug::Plot(Character, "Move Input Local Y", FVector::DotProduct(GetPawnOwner()->GetActorForwardVector(), GetPendingInputVector())); } #endif //ENABLE_COG @@ -250,29 +250,29 @@ void UCogSampleCharacterMovementComponent::TickComponent(float DeltaTime, enum E const FVector VelocityDelta = (Velocity - DebugLastVelocity) / DeltaTime; const FVector LocalVelocityDelta = Rotation.UnrotateVector(VelocityDelta); - FCogDebugPlot::PlotValue(Character, "Location X", DebugBottomLocation.X); - FCogDebugPlot::PlotValue(Character, "Location Y", DebugBottomLocation.Y); - FCogDebugPlot::PlotValue(Character, "Location Z", DebugBottomLocation.Z); - FCogDebugPlot::PlotValue(Character, "Rotation Yaw", Character->GetActorRotation().Yaw); - FCogDebugPlot::PlotValue(Character, "Acceleration X", GetCurrentAcceleration().X); - FCogDebugPlot::PlotValue(Character, "Acceleration Y", GetCurrentAcceleration().Y); - FCogDebugPlot::PlotValue(Character, "Acceleration Z", GetCurrentAcceleration().Z); - FCogDebugPlot::PlotValue(Character, "Acceleration Local X", LocalAcceleration.X); - FCogDebugPlot::PlotValue(Character, "Acceleration Local Y", LocalAcceleration.Y); - FCogDebugPlot::PlotValue(Character, "Acceleration Local Z", LocalAcceleration.Z); - FCogDebugPlot::PlotValue(Character, "Velocity X", Velocity.X); - FCogDebugPlot::PlotValue(Character, "Velocity Y", Velocity.Y); - FCogDebugPlot::PlotValue(Character, "Velocity Z", Velocity.Z); - FCogDebugPlot::PlotValue(Character, "Velocity Local X", LocalVelocity.X); - FCogDebugPlot::PlotValue(Character, "Velocity Local Y", LocalVelocity.Y); - FCogDebugPlot::PlotValue(Character, "Velocity Local Z", LocalVelocity.Z); - FCogDebugPlot::PlotValue(Character, "Velocity Delta X", VelocityDelta.X); - FCogDebugPlot::PlotValue(Character, "Velocity Delta Y", VelocityDelta.Y); - FCogDebugPlot::PlotValue(Character, "Velocity Delta Z", VelocityDelta.Z); - FCogDebugPlot::PlotValue(Character, "Velocity Delta Local X", LocalVelocityDelta.X); - FCogDebugPlot::PlotValue(Character, "Velocity Delta Local Y", LocalVelocityDelta.Y); - FCogDebugPlot::PlotValue(Character, "Velocity Delta Local Z", LocalVelocityDelta.Z); - FCogDebugPlot::PlotValue(Character, "Speed", Velocity.Length()); + FCogDebug::Plot(Character, "Location X", DebugBottomLocation.X); + FCogDebug::Plot(Character, "Location Y", DebugBottomLocation.Y); + FCogDebug::Plot(Character, "Location Z", DebugBottomLocation.Z); + FCogDebug::Plot(Character, "Rotation Yaw", Character->GetActorRotation().Yaw); + FCogDebug::Plot(Character, "Acceleration X", GetCurrentAcceleration().X); + FCogDebug::Plot(Character, "Acceleration Y", GetCurrentAcceleration().Y); + FCogDebug::Plot(Character, "Acceleration Z", GetCurrentAcceleration().Z); + FCogDebug::Plot(Character, "Acceleration Local X", LocalAcceleration.X); + FCogDebug::Plot(Character, "Acceleration Local Y", LocalAcceleration.Y); + FCogDebug::Plot(Character, "Acceleration Local Z", LocalAcceleration.Z); + FCogDebug::Plot(Character, "Velocity X", Velocity.X); + FCogDebug::Plot(Character, "Velocity Y", Velocity.Y); + FCogDebug::Plot(Character, "Velocity Z", Velocity.Z); + FCogDebug::Plot(Character, "Velocity Local X", LocalVelocity.X); + FCogDebug::Plot(Character, "Velocity Local Y", LocalVelocity.Y); + FCogDebug::Plot(Character, "Velocity Local Z", LocalVelocity.Z); + FCogDebug::Plot(Character, "Velocity Delta X", VelocityDelta.X); + FCogDebug::Plot(Character, "Velocity Delta Y", VelocityDelta.Y); + FCogDebug::Plot(Character, "Velocity Delta Z", VelocityDelta.Z); + FCogDebug::Plot(Character, "Velocity Delta Local X", LocalVelocityDelta.X); + FCogDebug::Plot(Character, "Velocity Delta Local Y", LocalVelocityDelta.Y); + FCogDebug::Plot(Character, "Velocity Delta Local Z", LocalVelocityDelta.Z); + FCogDebug::Plot(Character, "Speed", Velocity.Length()); const FVector Delta = DebugBottomLocation - DebugLastBottomLocation; const FColor Color = DebugIsPositionCorrected ? FColor::Blue : FColor::Yellow; diff --git a/Source/CogSample/CogSampleGameInstance.cpp b/Source/CogSample/CogSampleGameInstance.cpp new file mode 100644 index 0000000..e9d4a79 --- /dev/null +++ b/Source/CogSample/CogSampleGameInstance.cpp @@ -0,0 +1,24 @@ +#include "CogSampleGameInstance.h" + +#include "CogCommon.h" + +#if ENABLE_COG +#include "CogAll.h" +#include "CogSampleWindow_Team.h" +#include "CogWindowManager.h" +#endif + +//-------------------------------------------------------------------------------------------------------------------------- +void UCogSampleGameInstance::Init() +{ + Super::Init(); + +#if ENABLE_COG + if (UCogWindowManager* CogSubSystem = GetSubsystem()) + { + Cog::AddAllWindows(*CogSubSystem); + CogSubSystem->AddWindow("Gameplay.Team"); + } +#endif +} + diff --git a/Source/CogSample/CogSampleGameInstance.h b/Source/CogSample/CogSampleGameInstance.h new file mode 100644 index 0000000..869b3da --- /dev/null +++ b/Source/CogSample/CogSampleGameInstance.h @@ -0,0 +1,15 @@ +#pragma once + +#include "CoreMinimal.h" +#include "CogSampleGameInstance.generated.h" + +class UCogWindowManager; +class UCogSampleAbilitySystemComponent; + +UCLASS() +class UCogSampleGameInstance : public UGameInstance +{ + GENERATED_BODY() + + virtual void Init() override; +}; diff --git a/Source/CogSample/CogSampleGameState.cpp b/Source/CogSample/CogSampleGameState.cpp index f4bc76e..74365e0 100644 --- a/Source/CogSample/CogSampleGameState.cpp +++ b/Source/CogSample/CogSampleGameState.cpp @@ -8,7 +8,6 @@ #if ENABLE_COG #include "CogAll.h" -#include "CogDebugPlot.h" #include "CogSampleWindow_Team.h" #include "CogWindowManager.h" #endif //ENABLE_COG @@ -40,31 +39,12 @@ void ACogSampleGameState::BeginPlay() Super::BeginPlay(); AbilitySystemComponent->InitAbilityActorInfo(this, this); - -#if ENABLE_COG - CogWindowManager = NewObject(this); - CogWindowManagerRef = CogWindowManager; - - // Add all the built-in windows - Cog::AddAllWindows(*CogWindowManager); - - // Add a custom window - CogWindowManager->AddWindow("Gameplay.Team"); -#endif //ENABLE_COG } //-------------------------------------------------------------------------------------------------------------------------- void ACogSampleGameState::EndPlay(const EEndPlayReason::Type EndPlayReason) { Super::EndPlay(EndPlayReason); - -#if ENABLE_COG - - if (CogWindowManager != nullptr) - { - CogWindowManager->Shutdown(); - } -#endif //ENABLE_COG } //-------------------------------------------------------------------------------------------------------------------------- @@ -88,10 +68,10 @@ void ACogSampleGameState::Tick(float DeltaSeconds) if (GetLocalRole() != ROLE_Authority) { - FCogDebugPlot::PlotValue(this, "Frame Rate Client Raw", GAverageFPS); - FCogDebugPlot::PlotValue(this, "Frame Rate Client Smooth", _ClientFramerateSmooth); - FCogDebugPlot::PlotValue(this, "Frame Rate Server Raw", _ServerFramerateRaw); - FCogDebugPlot::PlotValue(this, "Frame Rate Server Smooth", _ServerFramerateSmooth); + FCogDebug::Plot(this, "Frame Rate Client Raw", GAverageFPS); + FCogDebug::Plot(this, "Frame Rate Client Smooth", _ClientFramerateSmooth); + FCogDebug::Plot(this, "Frame Rate Server Raw", _ServerFramerateRaw); + FCogDebug::Plot(this, "Frame Rate Server Smooth", _ServerFramerateSmooth); if (const ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController()) { @@ -99,16 +79,16 @@ void ACogSampleGameState::Tick(float DeltaSeconds) { if (const APlayerState* PlayerState = PlayerController->GetPlayerState()) { - FCogDebugPlot::PlotValue(this, "Ping", PlayerState->GetPingInMilliseconds()); + FCogDebug::Plot(this, "Ping", PlayerState->GetPingInMilliseconds()); } if (const UNetConnection* Connection = PlayerController->GetNetConnection()) { - FCogDebugPlot::PlotValue(this, + FCogDebug::Plot(this, "Packet Loss In", Connection->GetInLossPercentage().GetAvgLossPercentage() * 100.0f); - FCogDebugPlot::PlotValue(this, + FCogDebug::Plot(this, "Packet Loss Out", Connection->GetOutLossPercentage().GetAvgLossPercentage() * 100.0f); } @@ -117,14 +97,8 @@ void ACogSampleGameState::Tick(float DeltaSeconds) } else { - FCogDebugPlot::PlotValue(this, "Frame Rate Raw", GAverageFPS); - FCogDebugPlot::PlotValue(this, "Frame Rate Smooth", _ClientFramerateSmooth); - } - - - if (CogWindowManager != nullptr) - { - CogWindowManager->Tick(DeltaSeconds); + FCogDebug::Plot(this, "Frame Rate Raw", GAverageFPS); + FCogDebug::Plot(this, "Frame Rate Smooth", _ClientFramerateSmooth); } #endif //ENABLE_COG diff --git a/Source/CogSample/CogSampleGameState.h b/Source/CogSample/CogSampleGameState.h index 654b3f7..26a1fce 100644 --- a/Source/CogSample/CogSampleGameState.h +++ b/Source/CogSample/CogSampleGameState.h @@ -42,8 +42,6 @@ protected: #if ENABLE_COG - void InitializeCog(); - TObjectPtr CogWindowManager = nullptr; float _ClientFramerateSmooth = 0.0f; diff --git a/Source/CogSample/CogSampleGameplayAbility.cpp b/Source/CogSample/CogSampleGameplayAbility.cpp index df867b2..6e0b190 100644 --- a/Source/CogSample/CogSampleGameplayAbility.cpp +++ b/Source/CogSample/CogSampleGameplayAbility.cpp @@ -9,7 +9,7 @@ #include "CogSampleSpawnPredictionComponent.h" #if ENABLE_COG -#include "CogDebugPlot.h" +#include "CogDebug.h" #endif //-------------------------------------------------------------------------------------------------------------------------- @@ -26,7 +26,7 @@ void UCogSampleGameplayAbility::PreActivate(const FGameplayAbilitySpecHandle Han COG_LOG_ABILITY(ELogVerbosity::Verbose, this, TEXT("")); - FCogDebugPlot::PlotEventStart(this, "Ability", GetFName()) + FCogDebug::StartEvent(this, "Ability", GetFName()) .AddParam("Name", GetNameSafe(this)) .AddParam("Owner", GetNameSafe(ActorInfo->OwnerActor.Get())) .AddParam("Avatar", GetNameSafe(ActorInfo->AvatarActor.Get())) @@ -58,7 +58,7 @@ void UCogSampleGameplayAbility::EndAbility(const FGameplayAbilitySpecHandle Hand COG_LOG_ABILITY(ELogVerbosity::Verbose, this, TEXT("")); - FCogDebugPlot::PlotEventStop(this, "Ability", GetFName()); + FCogDebug::StopEvent(this, "Ability", GetFName()); #endif }