From b147b4b05f64116b8f9794964db8d8d9fbe2ba2d Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Fri, 27 Oct 2023 10:17:25 -0400 Subject: [PATCH] minor fixes --- .../CogDebug/Private/CogDebugReplicator.cpp | 2 +- .../CogEngine/Private/CogEngineReplicator.cpp | 20 +++++++++++++++++++ .../Private/CogEngineWindow_TimeScale.cpp | 2 +- .../CogEngine/Public/CogEngineReplicator.h | 6 ++++-- Source/CogSample/CogSampleBasicActor.cpp | 17 +++++++++++++++- Source/CogSample/CogSampleBasicActor.h | 2 ++ TODO.txt | 1 + 7 files changed, 45 insertions(+), 5 deletions(-) diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugReplicator.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugReplicator.cpp index a5809a8..c297813 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugReplicator.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugReplicator.cpp @@ -96,7 +96,7 @@ void ACogDebugReplicator::GetLifetimeReplicatedProps(TArray& DOREPLIFETIME_WITH_PARAMS_FAST(ACogDebugReplicator, ReplicatedData, Params); } - + //-------------------------------------------------------------------------------------------------------------------------- void ACogDebugReplicator::TickActor(float DeltaTime, enum ELevelTick TickType, FActorTickFunction& ThisTickFunction) { diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineReplicator.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineReplicator.cpp index 1113b42..b5f1f07 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineReplicator.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineReplicator.cpp @@ -130,6 +130,26 @@ void ACogEngineReplicator::Server_Spawn_Implementation(const FCogEngineSpawnEntr #endif // !UE_BUILD_SHIPPING } + +//-------------------------------------------------------------------------------------------------------------------------- +void ACogEngineReplicator::SetTimeDilation(float Value) +{ +#if !UE_BUILD_SHIPPING + + //------------------------------------- + // Set local time dilation right away + //------------------------------------- + TimeDilation = Value; + OnRep_TimeDilation(); + + //------------------------------------- + // Update server time dilation + //------------------------------------- + Server_SetTimeDilation(Value); + +#endif // !UE_BUILD_SHIPPING +} + //-------------------------------------------------------------------------------------------------------------------------- void ACogEngineReplicator::Server_SetTimeDilation_Implementation(float Value) { diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_TimeScale.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_TimeScale.cpp index 529b8f0..6dbfcda 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_TimeScale.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_TimeScale.cpp @@ -50,7 +50,7 @@ void FCogEngineWindow_TimeScale::RenderContent() float Value = Replicator->GetTimeDilation(); if (FCogWindowWidgets::MultiChoiceButtonsFloat(TimingScales, Value, ImVec2(3.5f * FCogWindowWidgets::GetFontWidth(), 0))) { - Replicator->Server_SetTimeDilation(Value); + Replicator->SetTimeDilation(Value); } } diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineReplicator.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineReplicator.h index 55a1481..b667246 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineReplicator.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineReplicator.h @@ -39,8 +39,7 @@ public: float GetTimeDilation() const { return TimeDilation; } - UFUNCTION(Server, Reliable) - void Server_SetTimeDilation(float Value); + void SetTimeDilation(float Value); UFUNCTION(Server, Reliable) void Server_Possess(APawn* Pawn); @@ -50,6 +49,9 @@ public: protected: + UFUNCTION(Server, Reliable) + void Server_SetTimeDilation(float Value); + UFUNCTION() void OnRep_TimeDilation(); diff --git a/Source/CogSample/CogSampleBasicActor.cpp b/Source/CogSample/CogSampleBasicActor.cpp index f5b71d7..d69c922 100644 --- a/Source/CogSample/CogSampleBasicActor.cpp +++ b/Source/CogSample/CogSampleBasicActor.cpp @@ -1,9 +1,9 @@ #include "CogSampleBasicActor.h" +#include "GameFramework/GameStateBase.h" #include "Net/Core/PushModel/PushModel.h" #include "Net/UnrealNetwork.h" - //-------------------------------------------------------------------------------------------------------------------------- ACogSampleBasicActor::ACogSampleBasicActor(const FObjectInitializer& ObjectInitializer) { @@ -22,6 +22,21 @@ void ACogSampleBasicActor::GetLifetimeReplicatedProps(TArray< FLifetimeProperty DOREPLIFETIME_WITH_PARAMS_FAST(ACogSampleBasicActor, Creator, Params); } +//-------------------------------------------------------------------------------------------------------------------------- +void ACogSampleBasicActor::BeginPlay() +{ + //----------------------------------------------------- + // Set default creator before Super::BeginPlay() + // so component can access it inside they BeginPlay() + //----------------------------------------------------- + if (Creator == nullptr) + { + Creator = GetWorld()->GetGameState(); + } + + Super::BeginPlay(); +} + //-------------------------------------------------------------------------------------------------------------------------- void ACogSampleBasicActor::SetTeam(int32 Value) { diff --git a/Source/CogSample/CogSampleBasicActor.h b/Source/CogSample/CogSampleBasicActor.h index e60e977..06d8a04 100644 --- a/Source/CogSample/CogSampleBasicActor.h +++ b/Source/CogSample/CogSampleBasicActor.h @@ -19,6 +19,8 @@ class ACogSampleBasicActor : public AActor public: ACogSampleBasicActor(const FObjectInitializer& ObjectInitializer); + + virtual void BeginPlay(); UFUNCTION(BlueprintPure) virtual int32 GetTeam() const override { return Team; } diff --git a/TODO.txt b/TODO.txt index 8442c22..a5057fe 100644 --- a/TODO.txt +++ b/TODO.txt @@ -9,6 +9,7 @@ - CogEngine: Add more info in stats tooltip (details, curves, ...) - CogEngine: Add screen settings (fullscreen, borderless, window and resolution) - CogEngine: make a better widget for CheckBoxState for input shortcuts +- CogEngine: save active log categories - CogSample: Add a custom window in sample (changing the character faction) - CogSample: Create more abilities