Various null checks, const correctness, remove unused headers

This commit is contained in:
Arnaud Jamin
2023-12-17 01:02:05 -05:00
parent a90881555b
commit 85a903a341
61 changed files with 346 additions and 369 deletions
@@ -30,9 +30,9 @@ ACogEngineReplicator* ACogEngineReplicator::Spawn(APlayerController* Controller)
}
//--------------------------------------------------------------------------------------------------------------------------
ACogEngineReplicator* ACogEngineReplicator::GetLocalReplicator(UWorld& World)
ACogEngineReplicator* ACogEngineReplicator::GetLocalReplicator(const UWorld& World)
{
for (TActorIterator<ACogEngineReplicator> It(&World, ACogEngineReplicator::StaticClass()); It; ++It)
for (TActorIterator<ACogEngineReplicator> It(&World, StaticClass()); It; ++It)
{
ACogEngineReplicator* Replicator = *It;
return Replicator;
@@ -42,9 +42,9 @@ ACogEngineReplicator* ACogEngineReplicator::GetLocalReplicator(UWorld& World)
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogEngineReplicator::GetRemoteReplicators(UWorld& World, TArray<ACogEngineReplicator*>& Replicators)
void ACogEngineReplicator::GetRemoteReplicators(const UWorld& World, TArray<ACogEngineReplicator*>& Replicators)
{
for (TActorIterator<ACogEngineReplicator> It(&World, ACogEngineReplicator::StaticClass()); It; ++It)
for (TActorIterator<ACogEngineReplicator> It(&World, StaticClass()); It; ++It)
{
ACogEngineReplicator* Replicator = Cast<ACogEngineReplicator>(*It);
Replicators.Add(Replicator);
@@ -73,7 +73,7 @@ void ACogEngineReplicator::BeginPlay()
Super::BeginPlay();
UWorld* World = GetWorld();
const UWorld* World = GetWorld();
check(World);
const ENetMode NetMode = World->GetNetMode();
bHasAuthority = NetMode != NM_Client;
@@ -114,7 +114,7 @@ void ACogEngineReplicator::Server_Spawn_Implementation(const FCogEngineSpawnEntr
else
{
FTransform Transform(FTransform::Identity);
if (APawn* Pawn = GetPlayerController()->GetPawn())
if (const APawn* Pawn = GetPlayerController()->GetPawn())
{
Transform = Pawn->GetTransform();
Transform.SetLocation(Transform.GetLocation() + Transform.GetUnitAxis(EAxis::X) * 200.0f);
@@ -165,11 +165,11 @@ void ACogEngineReplicator::Server_SetTimeDilation_Implementation(float Value)
}
//--------------------------------------------------------------------------------------------------------------------------
void ACogEngineReplicator::OnRep_TimeDilation()
void ACogEngineReplicator::OnRep_TimeDilation() const
{
#if !UE_BUILD_SHIPPING
UWorld* World = GetWorld();
const UWorld* World = GetWorld();
if (World == nullptr)
return;
@@ -4,7 +4,6 @@
#include "CogDebugSettings.h"
#include "CogEngineDataAsset.h"
#include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "Components/BoxComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/PrimitiveComponent.h"
@@ -20,7 +20,7 @@ void FCogEngineWindow_CommandBindings::RenderContent()
{
Super::RenderContent();
APlayerController* PlayerController = GetLocalPlayerController();
const APlayerController* PlayerController = GetLocalPlayerController();
if (PlayerController == nullptr)
{
return;
@@ -90,7 +90,7 @@ void FCogEngineWindow_Inspector::RenderContent()
return;
}
FCogEngineInspectorApplyFunction ApplyFunction = FindObjectApplyFunction(InspectedObject.Get());
const FCogEngineInspectorApplyFunction ApplyFunction = FindObjectApplyFunction(InspectedObject.Get());
ImGui::BeginChild("Inspector", ImVec2(-1, ApplyFunction != nullptr ? -ImGui::GetFrameHeightWithSpacing() : -1), false);
@@ -135,7 +135,7 @@ void FCogEngineWindow_Inspector::RenderMenu()
int32 NewHistoryIndex = INDEX_NONE;
//-----------------------------------
// Backward / Foward
// Backward / Forward
//-----------------------------------
{
if (ImGui::ArrowButton("##Backward", ImGuiDir_Left))
@@ -147,7 +147,7 @@ void FCogEngineWindow_Inspector::RenderMenu()
ImGui::SetTooltip("Backward");
}
if (ImGui::ArrowButton("##Foward", ImGuiDir_Right))
if (ImGui::ArrowButton("##Forward", ImGuiDir_Right))
{
NewHistoryIndex = FMath::Min(History.Num(), HistoryIndex + 1);
}
@@ -161,7 +161,7 @@ void FCogEngineWindow_Inspector::RenderMenu()
// Current Inspected Object
//-----------------------------------
const auto InspectedObjectName = StringCast<ANSICHAR>(*GetNameSafe(InspectedObject.Get()));
ImVec2 Pos = ImGui::GetCursorScreenPos();
const ImVec2 Pos = ImGui::GetCursorScreenPos();
{
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0f, 0.5f));
ImGui::SameLine();
@@ -906,7 +906,7 @@ bool FCogEngineWindow_Inspector::RenderClass(const FClassProperty* ClassProperty
//--------------------------------------------------------------------------------------------------------------------------
bool FCogEngineWindow_Inspector::RenderInterface(const FInterfaceProperty* InterfaceProperty)
{
UClass* Class = InterfaceProperty->InterfaceClass;
const UClass* Class = InterfaceProperty->InterfaceClass;
if (Class == nullptr)
{
ImGui::BeginDisabled();
@@ -927,7 +927,7 @@ bool FCogEngineWindow_Inspector::RenderInterface(const FInterfaceProperty* Inter
bool FCogEngineWindow_Inspector::RenderArray(const FArrayProperty* ArrayProperty, uint8* PointerToValue, bool ShowChildren)
{
FScriptArrayHelper Helper(ArrayProperty, PointerToValue);
int32 Num = Helper.Num();
const int32 Num = Helper.Num();
ImGui::BeginDisabled();
ImGui::Text("%s [%d]", TCHAR_TO_ANSI(*ArrayProperty->Inner->GetClass()->GetName()), Num);
@@ -963,8 +963,8 @@ bool FCogEngineWindow_Inspector::HasPropertyAnyChildren(const FProperty* Propert
}
else if (const FArrayProperty* ArrayProperty = CastField<FArrayProperty>(Property))
{
FScriptArrayHelper Helper(ArrayProperty, PointerToValue);
int32 Num = Helper.Num();
const FScriptArrayHelper Helper(ArrayProperty, PointerToValue);
const int32 Num = Helper.Num();
if (Num == 0)
{
return false;
@@ -978,7 +978,7 @@ bool FCogEngineWindow_Inspector::HasPropertyAnyChildren(const FProperty* Propert
}
else if (const FObjectProperty* ObjectProperty = CastField<FObjectProperty>(Property))
{
UObject* ReferencedObject = ObjectProperty->GetObjectPropertyValue(PointerToValue);
const UObject* ReferencedObject = ObjectProperty->GetObjectPropertyValue(PointerToValue);
if (ReferencedObject == nullptr)
{
return false;
@@ -34,7 +34,7 @@ void FCogEngineWindow_LogCategories::ResetConfig()
{
Super::ResetConfig();
FCogDebugLog::DeactivateAllLogCateories(*GetWorld());
FCogDebugLog::DeactivateAllLogCategories(*GetWorld());
}
//--------------------------------------------------------------------------------------------------------------------------
@@ -56,7 +56,7 @@ void FCogEngineWindow_LogCategories::RenderContent()
{
if (ImGui::MenuItem("Deactivate All"))
{
FCogDebugLog::DeactivateAllLogCateories(*World);
FCogDebugLog::DeactivateAllLogCategories(*World);
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{
@@ -103,6 +103,12 @@ void FCogEngineWindow_LogCategories::RenderContent()
ImGui::EndMenuBar();
}
if (FCogDebugLog::GetLogCategories().Num() == 0)
{
ImGui::Text("No log categories have been added.");
return;
}
const bool IsClient = World->GetNetMode() == NM_Client;
ImGuiStyle& Style = ImGui::GetStyle();
@@ -110,7 +116,7 @@ void FCogEngineWindow_LogCategories::RenderContent()
int Index = 0;
for (const auto& Entry : FCogDebugLog::GetLogCategories())
{
FName CategoryName = Entry.Key;
const FName CategoryName = Entry.Key;
const FCogDebugLogCategoryInfo& CategoryInfo = Entry.Value;
if (CategoryInfo.bVisible == false)
{
@@ -128,7 +134,7 @@ void FCogEngineWindow_LogCategories::RenderContent()
const bool IsControlDown = ImGui::GetIO().KeyCtrl;
if (IsClient)
{
ELogVerbosity::Type Verbosity = FCogDebugLog::GetServerVerbosity(CategoryName);
const ELogVerbosity::Type Verbosity = FCogDebugLog::GetServerVerbosity(CategoryName);
bool IsActive = FCogDebugLog::IsVerbosityActive(Verbosity);
if (Verbosity == ELogVerbosity::VeryVerbose)
@@ -169,7 +175,7 @@ void FCogEngineWindow_LogCategories::RenderContent()
}
{
ELogVerbosity::Type Verbosity = Category->GetVerbosity();
const ELogVerbosity::Type Verbosity = Category->GetVerbosity();
bool IsActive = FCogDebugLog::IsVerbosityActive(Verbosity);
if (Verbosity == ELogVerbosity::VeryVerbose)
@@ -214,14 +220,14 @@ void FCogEngineWindow_LogCategories::RenderContent()
{
if (IsClient)
{
ELogVerbosity::Type CurrentVerbosity = FCogDebugLog::GetServerVerbosity(CategoryName);
const ELogVerbosity::Type CurrentVerbosity = FCogDebugLog::GetServerVerbosity(CategoryName);
FCogWindowWidgets::SetNextItemToShortWidth();
if (ImGui::BeginCombo("##Server", FCogDebugHelper::VerbosityToString(CurrentVerbosity)))
{
for (int32 i = (int32)ELogVerbosity::Error; i <= (int32)ELogVerbosity::VeryVerbose; ++i)
{
bool IsSelected = i == (int32)CurrentVerbosity;
ELogVerbosity::Type Verbosity = (ELogVerbosity::Type)i;
const bool IsSelected = i == (int32)CurrentVerbosity;
const ELogVerbosity::Type Verbosity = (ELogVerbosity::Type)i;
if (ImGui::Selectable(FCogDebugHelper::VerbosityToString(Verbosity), IsSelected))
{
@@ -244,14 +250,14 @@ void FCogEngineWindow_LogCategories::RenderContent()
}
{
ELogVerbosity::Type CurrentVerbosity = Category->GetVerbosity();
const ELogVerbosity::Type CurrentVerbosity = Category->GetVerbosity();
FCogWindowWidgets::SetNextItemToShortWidth();
if (ImGui::BeginCombo("##Local", FCogDebugHelper::VerbosityToString(CurrentVerbosity)))
{
for (int32 i = (int32)ELogVerbosity::Error; i <= (int32)ELogVerbosity::VeryVerbose; ++i)
{
bool IsSelected = i == (int32)CurrentVerbosity;
ELogVerbosity::Type Verbosity = (ELogVerbosity::Type)i;
const bool IsSelected = i == (int32)CurrentVerbosity;
const ELogVerbosity::Type Verbosity = (ELogVerbosity::Type)i;
if (ImGui::Selectable(FCogDebugHelper::VerbosityToString(Verbosity), IsSelected))
{
@@ -1,7 +1,6 @@
#include "CogEngineWindow_Metrics.h"
#include "CogDebugMetric.h"
#include "CogImguiHelper.h"
#include "CogWindowWidgets.h"
#include "imgui.h"
#include "Engine/World.h"
@@ -63,9 +62,7 @@ void FCogEngineWindow_Metrics::RenderContent()
{
if (ImGui::BeginMenu("Options"))
{
bool bSettingModified = false;
FCogWindowWidgets::PushStyleCompact();
FCogWindowWidgets::PushStyleCompact();
ImGui::DragFloat("Auto Restart Delay", &FCogDebugMetric::RestartDelaySetting, 0.1f, 0.0f, FLT_MAX, "%0.1f");
FCogWindowWidgets::PopStyleCompact();
@@ -5,8 +5,6 @@
#include "Engine/Engine.h"
#include "Misc/StringBuilder.h"
//--------------------------------------------------------------------------------------------------------------------------
// UCogEngineWindow_OutputLog
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_OutputLog::Initialize()
{
@@ -67,7 +65,7 @@ void FCogEngineWindow_OutputLog::AddLog(const TCHAR* Message, ELogVerbosity::Typ
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_OutputLog::DrawRow(const char* BufferStart, const FLineInfo& LineInfo, bool IsTableShown)
void FCogEngineWindow_OutputLog::DrawRow(const char* BufferStart, const FLineInfo& LineInfo, bool IsTableShown) const
{
ImU32 Color;
switch (LineInfo.Verbosity)
@@ -175,8 +173,8 @@ void FCogEngineWindow_OutputLog::RenderContent()
{
for (int32 i = (int32)ELogVerbosity::Error; i <= (int32)ELogVerbosity::VeryVerbose; ++i)
{
bool IsSelected = i == Config->VerbosityFilter;
ELogVerbosity::Type Verbosity = (ELogVerbosity::Type)i;
const bool IsSelected = i == Config->VerbosityFilter;
const ELogVerbosity::Type Verbosity = (ELogVerbosity::Type)i;
if (ImGui::Selectable(FCogDebugHelper::VerbosityToString(Verbosity), IsSelected))
{
@@ -316,7 +314,7 @@ FCogLogOutputDevice::~FCogLogOutputDevice()
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogLogOutputDevice::Serialize(const TCHAR* Message, ELogVerbosity::Type Verbosity, const class FName& Category)
void FCogLogOutputDevice::Serialize(const TCHAR* Message, const ELogVerbosity::Type Verbosity, const FName& Category)
{
if (OutputLog != nullptr)
{
@@ -1,12 +1,10 @@
#include "CogEngineWindow_Plots.h"
#include "CogDebugPlot.h"
#include "CogImguiHelper.h"
#include "CogWindowWidgets.h"
#include "Engine/World.h"
#include "imgui.h"
#include "implot_internal.h"
#include "Kismet/GameplayStatics.h"
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_Plots::Initialize()
@@ -169,7 +167,7 @@ void FCogEngineWindow_Plots::RenderPlotsList(TArray<FCogDebugPlotEntry*>& Visibl
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_Plots::RenderPlots(const TArray<FCogDebugPlotEntry*>& VisiblePlots)
void FCogEngineWindow_Plots::RenderPlots(const TArray<FCogDebugPlotEntry*>& VisiblePlots) const
{
if (ImGui::BeginChild("Graph", ImVec2(0, -1)))
{
@@ -186,14 +184,14 @@ void FCogEngineWindow_Plots::RenderPlots(const TArray<FCogDebugPlotEntry*>& Visi
ImPlotAxisFlags HasPlotOnAxisY2 = false;
ImPlotAxisFlags HasPlotOnAxisY3 = false;
for (FCogDebugPlotEntry* PlotPtr : VisiblePlots)
for (const FCogDebugPlotEntry* PlotPtr : VisiblePlots)
{
HasPlotOnAxisY1 |= PlotPtr->CurrentYAxis == ImAxis_Y1 && PlotPtr->CurrentRow == PlotIndex;
HasPlotOnAxisY2 |= PlotPtr->CurrentYAxis == ImAxis_Y2 && PlotPtr->CurrentRow == PlotIndex;
HasPlotOnAxisY3 |= PlotPtr->CurrentYAxis == ImAxis_Y3 && PlotPtr->CurrentRow == PlotIndex;
}
ImPlot::SetupAxis(ImAxis_X1, NULL, ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoGridLines);
ImPlot::SetupAxis(ImAxis_X1, nullptr, ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoGridLines);
ImPlot::SetupAxis(ImAxis_Y1, HasPlotOnAxisY1 ? "" : "[drop here]", (HasPlotOnAxisY1 ? ImPlotAxisFlags_None : (ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoGridLines)) | ImPlotAxisFlags_AutoFit);
ImPlot::SetupAxis(ImAxis_Y2, HasPlotOnAxisY2 ? "" : "[drop here]", (HasPlotOnAxisY2 ? ImPlotAxisFlags_None : (ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoGridLines)) | ImPlotAxisFlags_AutoFit | ImPlotAxisFlags_Opposite);
ImPlot::SetupAxis(ImAxis_Y3, HasPlotOnAxisY3 ? "" : "[drop here]", (HasPlotOnAxisY3 ? ImPlotAxisFlags_None : (ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoGridLines)) | ImPlotAxisFlags_AutoFit | ImPlotAxisFlags_Opposite);
@@ -259,7 +257,7 @@ void FCogEngineWindow_Plots::RenderPlots(const TArray<FCogDebugPlotEntry*>& Visi
&& Mouse.y < PlotMax.y
&& ImGui::GetDragDropPayload() == nullptr)
{
ImVec2 Drag = ImGui::GetMouseDragDelta(0);
const ImVec2 Drag = ImGui::GetMouseDragDelta(0);
if (FMath::Abs(Drag.x) > 10)
{
FCogDebugPlot::Pause = true;
@@ -354,7 +352,7 @@ void FCogEngineWindow_Plots::RenderPlots(const TArray<FCogDebugPlotEntry*>& Visi
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_Plots::RenderTimeMarker()
void FCogEngineWindow_Plots::RenderTimeMarker() const
{
const ImVec2 PlotMin = ImPlot::GetPlotPos();
const ImVec2 PlotSize = ImPlot::GetPlotSize();
@@ -410,7 +408,7 @@ void FCogEngineWindow_Plots::RenderValues(FCogDebugPlotEntry& Entry, const char*
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_Plots::RenderEvents(FCogDebugPlotEntry& Entry, const char* Label, const ImVec2& PlotMin, const ImVec2& PlotMax)
void FCogEngineWindow_Plots::RenderEvents(FCogDebugPlotEntry& Entry, const char* Label, const ImVec2& PlotMin, const ImVec2& PlotMax) const
{
const ImVec2 Mouse = ImGui::GetMousePos();
ImDrawList* PlotDrawList = ImPlot::GetPlotDrawList();
@@ -444,7 +442,7 @@ void FCogEngineWindow_Plots::RenderEvents(FCogDebugPlotEntry& Entry, const char*
const bool IsInstant = Event.StartTime == Event.EndTime;
if (IsInstant)
{
const float Radius = 10.0f;
constexpr float Radius = 10.0f;
PlotDrawList->AddNgon(PosMid, 10, Event.BorderColor, 4);
PlotDrawList->AddNgonFilled(PosMid, 10, Event.FillColor, 4);
PlotDrawList->AddText(ImVec2(PosMid.x + 15, PosMid.y - 6), IM_COL32(255, 255, 255, 255), TCHAR_TO_ANSI(*Event.DisplayName));
@@ -461,7 +459,7 @@ void FCogEngineWindow_Plots::RenderEvents(FCogDebugPlotEntry& Entry, const char*
const ImVec2 Min = ImVec2(PosBot.x, PosBot.y);
const ImVec2 Max = ImVec2(PosEnd.x, PosTop.y);
ImDrawFlags Flags = Event.EndTime == 0.0f ? ImDrawFlags_RoundCornersLeft : ImDrawFlags_RoundCornersAll;
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));
@@ -1,15 +1,12 @@
#include "CogEngineWindow_Scalability.h"
#include "imgui.h"
#include "CogImguiHelper.h"
#include "CogWindowWidgets.h"
#include "Engine/Engine.h"
#include "Scalability.h"
#define SCALABILITY_NUM_LEVELS 5
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_Scalability::RenderHelp()
{
@@ -24,7 +21,7 @@ void FCogEngineWindow_Scalability::RenderContent()
Super::RenderContent();
Scalability::FQualityLevels Levels = Scalability::GetQualityLevels();
FString CurrentQualityName = Scalability::GetQualityLevelText(Levels.GetMinQualityLevel(), SCALABILITY_NUM_LEVELS).ToString();
const FString CurrentQualityName = Scalability::GetQualityLevelText(Levels.GetMinQualityLevel(), SCALABILITY_NUM_LEVELS).ToString();
FCogWindowWidgets::SetNextItemToShortWidth();
if (ImGui::BeginCombo("Scalability", TCHAR_TO_ANSI(*CurrentQualityName)))
{
@@ -1,11 +1,9 @@
#include "CogEngineWindow_Selection.h"
#include "CogDebugDraw.h"
#include "CogDebugSettings.h"
#include "CogEngineReplicator.h"
#include "CogImguiHelper.h"
#include "CogImguiInputHelper.h"
#include "CogImguiModule.h"
#include "CogWindowManager.h"
#include "CogWindowWidgets.h"
#include "Components/PrimitiveComponent.h"
@@ -2,7 +2,6 @@
#include "CogDebugSettings.h"
#include "CogWindowWidgets.h"
#include "Components/LineBatchComponent.h"
#include "Components/SkeletalMeshComponent.h"
#include "DrawDebugHelpers.h"
#include "Engine/SkeletalMesh.h"
@@ -31,7 +31,7 @@ void FCogEngineWindow_Slate::RenderContent()
ImGui::SetNextItemWidth(-1);
if (ImGui::BeginCombo("##User", TCHAR_TO_ANSI(*FString::Printf(TEXT("%d"), SelectedUserIndex))))
{
SlateApp.ForEachUser([this](FSlateUser& User)
SlateApp.ForEachUser([this](const FSlateUser& User)
{
if (ImGui::Selectable(TCHAR_TO_ANSI(*FString::Printf(TEXT("%d"), SelectedUserIndex)), false))
{
@@ -41,7 +41,7 @@ void FCogEngineWindow_Slate::RenderContent()
ImGui::EndCombo();
}
if (TSharedPtr<FSlateUser> User = SlateApp.GetUser(SelectedUserIndex))
if (const TSharedPtr<FSlateUser> User = SlateApp.GetUser(SelectedUserIndex))
{
RenderUser(*User.Get());
}
@@ -54,7 +54,7 @@ void FCogEngineWindow_Slate::RenderUser(FSlateUser& User)
if (ImGui::BeginTable("SlateUser", 2, ImGuiTableFlags_Borders))
{
const ImVec4 LabelColor(1.0f, 1.0f, 1.0f, 0.5f);
constexpr ImVec4 LabelColor(1.0f, 1.0f, 1.0f, 0.5f);
ImGui::TableSetupColumn("Property");
ImGui::TableSetupColumn("Value");
@@ -68,7 +68,7 @@ void FCogEngineWindow_Slate::RenderUser(FSlateUser& User)
ImGui::TextColored(LabelColor, "Focused Widget");
ImGui::TableNextColumn();
FString FocusedWidgetText = "None";
if (TSharedPtr<SWidget> FocusedWidget = User.GetFocusedWidget())
if (const TSharedPtr<SWidget> FocusedWidget = User.GetFocusedWidget())
{
FocusedWidgetText = FocusedWidget->ToString();
}
@@ -81,12 +81,12 @@ void FCogEngineWindow_Slate::RenderUser(FSlateUser& User)
ImGui::TableNextColumn();
ImGui::TextColored(LabelColor, "Cursor Captor");
ImGui::TableNextColumn();
FString CursorCaptoreWidgetText = "None";
if (TSharedPtr<SWidget> CursorCaptoreWidget = User.GetCursorCaptor())
FString CursorCaptorWidgetText = "None";
if (const TSharedPtr<SWidget> CursorCaptorWidget = User.GetCursorCaptor())
{
CursorCaptoreWidgetText = CursorCaptoreWidget->ToString();
CursorCaptorWidgetText = CursorCaptorWidget->ToString();
}
ImGui::Text("%s", TCHAR_TO_ANSI(*CursorCaptoreWidgetText));
ImGui::Text("%s", TCHAR_TO_ANSI(*CursorCaptorWidgetText));
//------------------------
// Cursor Position
@@ -3,7 +3,6 @@
#include "CogEngineDataAsset.h"
#include "CogEngineReplicator.h"
#include "CogImguiHelper.h"
#include "CogWindowHelper.h"
#include "CogWindowWidgets.h"
//--------------------------------------------------------------------------------------------------------------------------
@@ -31,27 +30,40 @@ void FCogEngineWindow_Spawns::RenderContent()
if (Asset == nullptr)
{
ImGui::TextDisabled("Invalid Asset");
return;
}
ACogEngineReplicator* Replicator = ACogEngineReplicator::GetLocalReplicator(*GetWorld());
if (Replicator == nullptr)
{
ImGui::TextDisabled("Invalid Replicator");
return;
}
if (Asset->SpawnGroups.Num() == 0)
{
ImGui::TextDisabled("No spawn group have been defined");
return;
}
for (const FCogEngineSpawnGroup& SpawnGroup : Asset->SpawnGroups)
{
RenderSpawnGroup(SpawnGroup);
RenderSpawnGroup(*Replicator, SpawnGroup);
}
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_Spawns::RenderSpawnGroup(const FCogEngineSpawnGroup& SpawnGroup)
void FCogEngineWindow_Spawns::RenderSpawnGroup(ACogEngineReplicator& Replicator, const FCogEngineSpawnGroup& SpawnGroup)
{
int32 GroupIndex = 0;
ImGui::PushStyleColor(ImGuiCol_Header, IM_COL32(66, 66, 66, 79));
ImGui::PushStyleColor(ImGuiCol_Header, IM_COL32(66, 66, 66, 79));
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, IM_COL32(62, 62, 62, 204));
ImGui::PushStyleColor(ImGuiCol_HeaderActive, IM_COL32(86, 86, 86, 255));
if (ImGui::CollapsingHeader(TCHAR_TO_ANSI(*SpawnGroup.Name), ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::PushID(GroupIndex);
int32 GroupIndex = 0;
ImGui::PushID(GroupIndex);
const bool PushColor = (SpawnGroup.Color != FColor::Transparent);
if (PushColor)
@@ -64,7 +76,7 @@ void FCogEngineWindow_Spawns::RenderSpawnGroup(const FCogEngineSpawnGroup& Spawn
for (const FCogEngineSpawnEntry& SpawnEntry : SpawnGroup.Spawns)
{
if (RenderSpawnAsset(SpawnEntry, SelectedAssetIndex == GroupIndex))
if (RenderSpawnAsset(Replicator, SpawnEntry, SelectedAssetIndex == GroupIndex))
{
SelectedAssetIndex = AssetIndex;
}
@@ -85,7 +97,7 @@ void FCogEngineWindow_Spawns::RenderSpawnGroup(const FCogEngineSpawnGroup& Spawn
}
//--------------------------------------------------------------------------------------------------------------------------
bool FCogEngineWindow_Spawns::RenderSpawnAsset(const FCogEngineSpawnEntry& SpawnEntry, bool IsLastSelected)
bool FCogEngineWindow_Spawns::RenderSpawnAsset(ACogEngineReplicator& Replicator, const FCogEngineSpawnEntry& SpawnEntry, bool IsLastSelected)
{
bool IsPressed = false;
@@ -104,10 +116,8 @@ bool FCogEngineWindow_Spawns::RenderSpawnAsset(const FCogEngineSpawnEntry& Spawn
if (ImGui::Button(TCHAR_TO_ANSI(*EntryName), ImVec2(-1, 0)))
{
if (ACogEngineReplicator* Replicator = ACogEngineReplicator::GetLocalReplicator(*GetWorld()))
{
Replicator->Server_Spawn(SpawnEntry);
}
IsPressed = true;
Replicator.Server_Spawn(SpawnEntry);
}
ImGui::PopStyleVar(1);
@@ -7,7 +7,6 @@
#include "GameFramework/Controller.h"
#include "GameFramework/PlayerController.h"
#include "GameFramework/PlayerState.h"
#include "Net/NetPing.h"
ImVec4 StatRedColor(1.0f, 0.4f, 0.3f, 1.0f);
ImVec4 StatOrangeColor(1.0f, 0.7f, 0.4f, 1.0f);
@@ -49,7 +48,7 @@ void FCogEngineWindow_Stats::RenderContent()
ImGui::TextColored(GetPingColor(Ping), "%0.0fms", Ping);
}
if (UNetConnection* Connection = PlayerController->GetNetConnection())
if (const UNetConnection* Connection = PlayerController->GetNetConnection())
{
const float OutPacketLost = Connection->GetOutLossPercentage().GetAvgLossPercentage() * 100.0f;
ImGui::Text("Packet Loss Out ");
@@ -65,12 +64,12 @@ void FCogEngineWindow_Stats::RenderContent()
}
//--------------------------------------------------------------------------------------------------------------------------
float FCogEngineWindow_Stats::GetMainMenuWidgetWidth(int32 WidgetIndex, float MaxWidth)
float FCogEngineWindow_Stats::GetMainMenuWidgetWidth(const int32 SubWidgetIndex, float MaxWidth)
{
const APlayerController* PlayerController = GetLocalPlayerController();
const UNetConnection* Connection = PlayerController != nullptr ? PlayerController->GetNetConnection() : nullptr;
switch (WidgetIndex)
switch (SubWidgetIndex)
{
case 0: return FCogWindowWidgets::GetFontWidth() * 8;
case 1: return Connection != nullptr ? FCogWindowWidgets::GetFontWidth() * 7 : 0.0f;
@@ -81,9 +80,9 @@ float FCogEngineWindow_Stats::GetMainMenuWidgetWidth(int32 WidgetIndex, float Ma
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_Stats::RenderMainMenuWidget(int32 WidgetIndex, float Width)
void FCogEngineWindow_Stats::RenderMainMenuWidget(const int32 SubWidgetIndex, const float Width)
{
switch (WidgetIndex)
switch (SubWidgetIndex)
{
case 0: RenderMainMenuWidgetFramerate(Width); break;
case 1: RenderMainMenuWidgetPing(Width); break;
@@ -92,10 +91,10 @@ void FCogEngineWindow_Stats::RenderMainMenuWidget(int32 WidgetIndex, float Width
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_Stats::RenderMainMenuWidgetFramerate(float Width)
void FCogEngineWindow_Stats::RenderMainMenuWidgetFramerate(const float Width)
{
extern ENGINE_API float GAverageFPS;
int32 Fps = (int32)GAverageFPS;
const int32 Fps = (int32)GAverageFPS;
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0f, 0.5f));
@@ -129,7 +128,7 @@ void FCogEngineWindow_Stats::RenderMainMenuWidgetFramerate(float Width)
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_Stats::RenderMainMenuWidgetPing(float Width)
void FCogEngineWindow_Stats::RenderMainMenuWidgetPing(const float Width)
{
const APlayerController* PlayerController = GetLocalPlayerController();
const APlayerState* PlayerState = PlayerController != nullptr ? PlayerController->GetPlayerState<APlayerState>() : nullptr;
@@ -164,7 +163,7 @@ void FCogEngineWindow_Stats::RenderMainMenuWidgetPing(float Width)
ImGui::Text("Ping");
ImGui::SameLine();
FNamedNetDriver* SelectedNetDriver = &WorldContext.ActiveNetDrivers[0];
const FNamedNetDriver* SelectedNetDriver = &WorldContext.ActiveNetDrivers[0];
FPacketSimulationSettings Settings = SelectedNetDriver->NetDriver->PacketSimulationSettings;
TArray<int32> Values{ 0, 50, 100, 200, 500, 1000 };
if (FCogWindowWidgets::MultiChoiceButtonsInt(Values, Settings.PktIncomingLagMin, ImVec2(4.5f * FCogWindowWidgets::GetFontWidth(), 0)))
@@ -178,10 +177,10 @@ void FCogEngineWindow_Stats::RenderMainMenuWidgetPing(float Width)
}
//--------------------------------------------------------------------------------------------------------------------------
void FCogEngineWindow_Stats::RenderMainMenuWidgetPacketLoss(float Width)
void FCogEngineWindow_Stats::RenderMainMenuWidgetPacketLoss(const float Width)
{
const APlayerController* PlayerController = GetLocalPlayerController();
UNetConnection* Connection = PlayerController != nullptr ? PlayerController->GetNetConnection() : nullptr;
const UNetConnection* Connection = PlayerController != nullptr ? PlayerController->GetNetConnection() : nullptr;
if (Connection == nullptr)
{
return;
@@ -216,7 +215,7 @@ void FCogEngineWindow_Stats::RenderMainMenuWidgetPacketLoss(float Width)
ImGui::Text("Packet Loss");
ImGui::SameLine();
FNamedNetDriver* SelectedNetDriver = &WorldContext.ActiveNetDrivers[0];
const FNamedNetDriver* SelectedNetDriver = &WorldContext.ActiveNetDrivers[0];
FPacketSimulationSettings Settings = SelectedNetDriver->NetDriver->PacketSimulationSettings;
TArray<int32> Values{ 0, 5, 10, 20, 30, 40, 50 };
@@ -232,7 +231,7 @@ void FCogEngineWindow_Stats::RenderMainMenuWidgetPacketLoss(float Width)
}
//--------------------------------------------------------------------------------------------------------------------------
ImVec4 FCogEngineWindow_Stats::GetFpsColor(float Value, float Good /*= 50.0f*/, float Medium /*= 30.0f*/)
ImVec4 FCogEngineWindow_Stats::GetFpsColor(const float Value, const float Good /*= 50.0f*/, const float Medium /*= 30.0f*/)
{
if (Value > Good)
{
@@ -248,7 +247,7 @@ ImVec4 FCogEngineWindow_Stats::GetFpsColor(float Value, float Good /*= 50.0f*/,
}
//--------------------------------------------------------------------------------------------------------------------------
ImVec4 FCogEngineWindow_Stats::GetPingColor(float Value, float Good /*= 100.0f*/, float Medium /*= 200.0f*/)
ImVec4 FCogEngineWindow_Stats::GetPingColor(const float Value, const float Good /*= 100.0f*/, const float Medium /*= 200.0f*/)
{
if (Value > Medium)
{
@@ -264,7 +263,7 @@ ImVec4 FCogEngineWindow_Stats::GetPingColor(float Value, float Good /*= 100.0f*/
}
//--------------------------------------------------------------------------------------------------------------------------
ImVec4 FCogEngineWindow_Stats::GetPacketLossColor(float Value, float Good /*= 10.0f*/, float Medium /*= 20.0f*/)
ImVec4 FCogEngineWindow_Stats::GetPacketLossColor(const float Value, const float Good /*= 10.0f*/, const float Medium /*= 20.0f*/)
{
if (Value > Medium)
{
@@ -34,19 +34,13 @@ void FCogEngineWindow_TimeScale::RenderContent()
{
Super::RenderContent();
UWorld* World = GetWorld();
if (World == nullptr)
{
return;
}
ACogEngineReplicator* Replicator = ACogEngineReplicator::GetLocalReplicator(*World);
ACogEngineReplicator* Replicator = ACogEngineReplicator::GetLocalReplicator(*GetWorld());
if (Replicator == nullptr)
{
ImGui::TextDisabled("Invalid Replicator");
return;
}
float Value = Replicator->GetTimeDilation();
if (FCogWindowWidgets::MultiChoiceButtonsFloat(TimingScales, Value, ImVec2(3.5f * FCogWindowWidgets::GetFontWidth(), 0)))
{