From efb4d71bcb183848ea3acee40dfa11b29d19bd9d Mon Sep 17 00:00:00 2001 From: fjacomme Date: Wed, 9 Aug 2023 12:49:05 +0400 Subject: [PATCH 1/2] Make ApplyToOwner work with clamping --- Source/DISRuntime/Private/DISReceiveComponent.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Source/DISRuntime/Private/DISReceiveComponent.cpp b/Source/DISRuntime/Private/DISReceiveComponent.cpp index 57b3090..348db6d 100644 --- a/Source/DISRuntime/Private/DISReceiveComponent.cpp +++ b/Source/DISRuntime/Private/DISReceiveComponent.cpp @@ -17,7 +17,8 @@ UDISReceiveComponent::UDISReceiveComponent() { bWantsInitializeComponent = true; PrimaryComponentTick.bCanEverTick = true; - PrimaryComponentTick.bStartWithTickEnabled = false; + PrimaryComponentTick.bStartWithTickEnabled = true; + PrimaryComponentTick.TickGroup = ETickingGroup::TG_PrePhysics; } void UDISReceiveComponent::InitializeComponent() @@ -57,6 +58,7 @@ void UDISReceiveComponent::BeginPlay() void UDISReceiveComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + ApplyToOwnerIfActivated(MostRecentDeadReckonedEntityStatePDU); } void UDISReceiveComponent::HandleEntityStatePDU(FEntityStatePDU NewEntityStatePDU) @@ -75,10 +77,9 @@ void UDISReceiveComponent::HandleEntityStatePDU(FEntityStatePDU NewEntityStatePD EntityForceID = NewEntityStatePDU.ForceID; EntityMarking = NewEntityStatePDU.Marking; - ApplyToOwnerIfActivated(NewEntityStatePDU); OnReceivedEntityStatePDU.Broadcast(NewEntityStatePDU); - if (!PerformDeadReckoning) + if (!PerformDeadReckoning && !ApplyToOwner) { GroundClamping(); } @@ -100,7 +101,7 @@ void UDISReceiveComponent::HandleEntityStateUpdatePDU(FEntityStateUpdatePDU NewE ApplyToOwnerIfActivated(MostRecentEntityStatePDU); OnReceivedEntityStateUpdatePDU.Broadcast(NewEntityStateUpdatePDU); - if (!PerformDeadReckoning) + if (!PerformDeadReckoning && !ApplyToOwner) { GroundClamping(); } @@ -193,12 +194,8 @@ void UDISReceiveComponent::DoDeadReckoning(float DeltaTime) MostRecentDeadReckonedEntityStatePDU = SmoothDeadReckoning(MostRecentDeadReckonedEntityStatePDU); } - ApplyToOwnerIfActivated(MostRecentDeadReckonedEntityStatePDU); OnDeadReckoningUpdate.Broadcast(MostRecentDeadReckonedEntityStatePDU); } - - //Perform ground clamping last - GroundClamping(); } } @@ -282,4 +279,5 @@ void UDISReceiveComponent::ApplyToOwnerIfActivated(FEntityStatePDU const& StateP FRotator newRotation; UDIS_BPFL::GetUnrealLocationAndOrientationFromEntityStatePdu(StatePDU, GeoReferencingSystem, newLocation, newRotation); GetOwner()->SetActorLocationAndRotation(newLocation, newRotation); + GroundClamping(); } \ No newline at end of file From 2391fe9c9171731f6adec50820e174b588883214 Mon Sep 17 00:00:00 2001 From: fjacomme Date: Thu, 10 Aug 2023 12:09:53 +0400 Subject: [PATCH 2/2] Optimize ticking of DISReceiver --- Source/DISRuntime/Private/DISGameManager.cpp | 26 ------------------- .../Private/DISReceiveComponent.cpp | 7 +++++ Source/DISRuntime/Public/DISGameManager.h | 1 - 3 files changed, 7 insertions(+), 27 deletions(-) diff --git a/Source/DISRuntime/Private/DISGameManager.cpp b/Source/DISRuntime/Private/DISGameManager.cpp index b104b8b..a9d4a05 100644 --- a/Source/DISRuntime/Private/DISGameManager.cpp +++ b/Source/DISRuntime/Private/DISGameManager.cpp @@ -99,32 +99,6 @@ void ADISGameManager::BeginPlay() } } -void ADISGameManager::Tick(float DeltaTime) -{ - Super::Tick(DeltaTime); - - for (std::pair DisEntity : RawDISActorMappings) - { - if (IsValid(DisEntity.second)) - { - UDISReceiveComponent* DISComponent = IDISInterface::Execute_GetActorDISReceiveComponent(DisEntity.second); - - if (DISComponent) - { - DISComponent->DoDeadReckoning(DeltaTime); - } - else - { - UE_LOG(LogDISGameManager, Warning, TEXT("Cannot find DISComponent on entity %s"), *DisEntity.second->GetName()) - } - } - else - { - UE_LOG(LogDISGameManager, Error, TEXT("Encountered null reference within RawDISActorMapping! Check C++ side usage of RawDISActorMapping to verify using properly!")); - } - } -} - void ADISGameManager::HandleOnDISEntityDestroyed(AActor* DestroyedActor) { bool anyRemoved = false; diff --git a/Source/DISRuntime/Private/DISReceiveComponent.cpp b/Source/DISRuntime/Private/DISReceiveComponent.cpp index 348db6d..78db8d1 100644 --- a/Source/DISRuntime/Private/DISReceiveComponent.cpp +++ b/Source/DISRuntime/Private/DISReceiveComponent.cpp @@ -18,6 +18,7 @@ UDISReceiveComponent::UDISReceiveComponent() bWantsInitializeComponent = true; PrimaryComponentTick.bCanEverTick = true; PrimaryComponentTick.bStartWithTickEnabled = true; + // The PrePhysics tick group ensures that there is no jittering with camera using SpringArms or equivalent PrimaryComponentTick.TickGroup = ETickingGroup::TG_PrePhysics; } @@ -58,6 +59,7 @@ void UDISReceiveComponent::BeginPlay() void UDISReceiveComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + DoDeadReckoning(DeltaTime); ApplyToOwnerIfActivated(MostRecentDeadReckonedEntityStatePDU); } @@ -196,6 +198,11 @@ void UDISReceiveComponent::DoDeadReckoning(float DeltaTime) OnDeadReckoningUpdate.Broadcast(MostRecentDeadReckonedEntityStatePDU); } + if (!ApplyToOwner) + { + //Perform ground clamping last + GroundClamping(); + } } } diff --git a/Source/DISRuntime/Public/DISGameManager.h b/Source/DISRuntime/Public/DISGameManager.h index 26fcf13..71d3f8f 100644 --- a/Source/DISRuntime/Public/DISGameManager.h +++ b/Source/DISRuntime/Public/DISGameManager.h @@ -177,7 +177,6 @@ class DISRUNTIME_API ADISGameManager : public AInfo protected: virtual void BeginPlay() override; - virtual void Tick(float DeltaTime) override; UFUNCTION() void HandleOnDISEntityDestroyed(AActor* DestroyedActor);