UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
NetworkPhysicsComponent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4#include "RewindData.h"
9#include "Engine/World.h"
13#include "Chaos/PhysicsObject.h"
16
17#include "NetworkPhysicsComponent.generated.h"
18
19#ifndef DEBUG_NETWORK_PHYSICS_DELTASERIALIZATION
20#define DEBUG_NETWORK_PHYSICS_DELTASERIALIZATION 0
21#endif
22
24
27DECLARE_MULTICAST_DELEGATE_TwoParams(FOnInjectInputsExternal, const int32 /* PhysicsStep */, const int32 /* NumSteps */);
28
30template<typename DataType, bool bLegacyData = false>
32{
34
35 TNetRewindHistory(const int32 FrameCount, const bool bIsHistoryLocal) :
36 Super(FrameCount, bIsHistoryLocal)
37 {
38 }
39
40 TNetRewindHistory(const int32 FrameCount) :
41 Super(FrameCount)
42 {
43 }
44
45 virtual ~TNetRewindHistory() {}
46
53
58
59 virtual void ValidateDataInHistory(const void* ActorComponent) override
60 {
61 if constexpr (bLegacyData)
62 {
63 const UActorComponent* NetworkComponent = static_cast<const UActorComponent*>(ActorComponent);
64 for (int32 FrameIndex = 0; FrameIndex < Super::NumFrames; ++FrameIndex)
65 {
66 DataType& FrameData = Super::DataHistory[FrameIndex];
67 FrameData.ValidateData(NetworkComponent);
68 }
69 }
70 }
71
72 virtual int32 CountValidData(const uint32 StartFrame, const uint32 EndFrame, const bool bIncludeUnimportant = true, const bool bIncludeImportant = false) override
73 {
74 // Find how many entries are valid in frame range
75 DataType FrameData;
76 int32 Count = 0;
77 for (uint32 Frame = StartFrame; Frame <= EndFrame; ++Frame)
78 {
80 if (Frame == Super::DataHistory[Index].LocalFrame)
81 {
82 FrameData = Super::DataHistory[Index];
83
84 // Check if we should include unimportant and/or important data
85 if ((!FrameData.bImportant && bIncludeUnimportant) || (FrameData.bImportant && bIncludeImportant))
86 {
87 Count++;
88 }
89 }
90 }
91 return Count;
92 }
93
94 virtual int32 CountAlteredData(const bool bIncludeUnimportant = true, const bool bIncludeImportant = false) override
95 {
96 DataType FrameData;
97 int32 Count = 0;
98 for (int32 Index = 0; Index < Super::NumFrames; ++Index)
99 {
100 FrameData = Super::DataHistory[Index];
101
102 // Check if we should include unimportant and/or important data
103 if (FrameData.bDataAltered && ((!FrameData.bImportant && bIncludeUnimportant) || (FrameData.bImportant && bIncludeImportant)))
104 {
105 Count++;
106 }
107 }
108 return Count;
109 }
110
111 virtual void SetImportant(const bool bImportant, const int32 Frame = INDEX_NONE) override
112 {
113 if (Frame > INDEX_NONE)
114 {
116 {
117 // Set importance on specified frame
118 Super::DataHistory[Super::CurrentIndex].bImportant = bImportant;
119 }
120 }
121 else
122 {
123 // Set importance on all frames
124 for (int32 Index = 0; Index < Super::NumFrames; ++Index)
125 {
126 Super::DataHistory[Index].bImportant = bImportant;
127 }
128 }
129
130 }
131
132 virtual void ApplyDataRange(const int32 FromFrame, const int32 ToFrame, void* ActorComponent, const bool bOnlyImportant = false) override
133 {
134 if constexpr (bLegacyData)
135 {
136 UActorComponent* NetworkComponent = static_cast<UActorComponent*>(ActorComponent);
137
138 for (int32 ApplyFrame = FromFrame; ApplyFrame <= ToFrame; ++ApplyFrame)
139 {
141 DataType& FrameData = Super::DataHistory[ApplyIndex];
142 if (ApplyFrame == FrameData.LocalFrame && (!bOnlyImportant || FrameData.bImportant))
143 {
144 FrameData.ApplyData(NetworkComponent);
145 }
146 }
147 }
148 }
149
151 {
153 bool bHasCopiedData = false;
154
155 DataType FrameData;
156 for (int32 CopyIndex = 0; CopyIndex < Super::NumFrames; ++CopyIndex)
157 {
158 FrameData = Super::DataHistory[CopyIndex];
159
160 // Check if we should include unimportant and/or important data
161 if ((!FrameData.bImportant && bIncludeUnimportant) || (FrameData.bImportant && bIncludeImportant))
162 {
163 OutNetHistory.RecordData(FrameData.LocalFrame, &FrameData);
164 bHasCopiedData = true;
165 }
166 }
167 return bHasCopiedData;
168 }
169
171 {
173 bool bHasCopiedData = false;
174
175 DataType FrameData;
176 for (int32 CopyIndex = 0; CopyIndex < Super::NumFrames; ++CopyIndex)
177 {
178 FrameData = Super::DataHistory[CopyIndex];
179
180 // Check if we should include unimportant and/or important data
181 if (FrameData.bDataAltered && ((!FrameData.bImportant && bIncludeUnimportant) || (FrameData.bImportant && bIncludeImportant)))
182 {
183 OutNetHistory.RecordData(FrameData.LocalFrame, &FrameData);
184 bHasCopiedData = true;
185 }
186 }
187 return bHasCopiedData;
188 }
189
190 virtual bool CopyData(Chaos::FBaseRewindHistory& OutHistory, const uint32 StartFrame, const uint32 EndFrame, bool bIncludeUnimportant = true, bool bIncludeImportant = false) override
191 {
193 bool bHasCopiedData = false;
194
195 DataType FrameData;
196 for (uint32 CopyFrame = StartFrame; CopyFrame <= EndFrame; ++CopyFrame)
197 {
198 const int32 CopyIndex = Super::GetFrameIndex(CopyFrame);
199 if (CopyFrame == Super::DataHistory[CopyIndex].LocalFrame)
200 {
201 FrameData = Super::DataHistory[CopyIndex];
202
203 // Check if we should include unimportant and/or important data
204 if ((!FrameData.bImportant && bIncludeUnimportant) || (FrameData.bImportant && bIncludeImportant))
205 {
206 OutNetHistory.RecordData(CopyFrame, &FrameData);
207 bHasCopiedData = true;
208 }
209 }
210 }
211 return bHasCopiedData;
212 }
213
214 virtual TUniquePtr<Chaos::FBaseRewindHistory> CopyFramesWithOffset(const uint32 StartFrame, const uint32 EndFrame, const int32 FrameOffset) override
215 {
217
219
220 DataType FrameData;
221 for (uint32 CopyFrame = StartFrame; CopyFrame < EndFrame; ++CopyFrame)
222 {
223 const int32 CopyIndex = Super::GetFrameIndex(CopyFrame);
224 if (CopyFrame == Super::DataHistory[CopyIndex].LocalFrame)
225 {
226 FrameData = Super::DataHistory[CopyIndex];
227 FrameData.ServerFrame = FrameData.LocalFrame + FrameOffset;
228 Copy->RecordData(CopyFrame, &FrameData);
229 }
230 }
231
232 return Copy;
233 }
234
235 virtual int32 ReceiveNewData(Chaos::FBaseRewindHistory& NewData, const int32 FrameOffset, bool CompareDataForRewind = false, const bool bImportant = false, int32 TryInjectAtFrame = INDEX_NONE) override
236 {
237 TNetRewindHistory& NetNewData = static_cast<TNetRewindHistory&>(NewData);
238
241
242 for (int32 Itr = 0; Itr < NetNewData.GetHistorySize(); Itr++)
243 {
244 DataType* NextReceiveData = NetNewData.GetAndLoadNextIncrementalData();
245
246 ReceiveData.bImportant = bImportant;
247 ReceiveData.bReceivedData = true; // Received data is marked to differentiate from locally predicted data
248
249 ReceiveData.LocalFrame = ReceiveData.ServerFrame - FrameOffset;
250
252 {
254 {
255 RewindFrame = ReceiveData.LocalFrame;
256 }
257
259 }
260
261 if (NextReceiveData)
262 {
264 }
265 else
266 {
267 // Record a copy of the last data at specified frame if the history doesn't have data for that frame yet
269 {
270#if DEBUG_NETWORK_PHYSICS
271 UE_LOG(LogChaos, Log, TEXT("SERVER | PT | Input Buffer Empty, Injecting Received Input at frame %d || LocalFrame = %d || ServerFrame = %d || bDataAltered = %d || Data: %s")
272 , TryInjectAtFrame, ReceiveData.LocalFrame, ReceiveData.ServerFrame, ReceiveData.bDataAltered, *ReceiveData.DebugData());
273#endif
274
275 DataType InjectData = ReceiveData;
276 InjectData.bReceivedData = false;
277 InjectData.bDataAltered = true;
278 InjectData.LocalFrame = TryInjectAtFrame;
279 InjectData.ServerFrame = TryInjectAtFrame + FrameOffset;
280
282 }
283
284 break;
285 }
286 }
287
288 return RewindFrame;
289 }
290
293 virtual bool ShouldRecordReceivedDataOnFrame(const DataType& ReceivedData, DataType* NextReceivedData = nullptr)
294 {
295 if (ReceivedData.LocalFrame < 0)
296 {
297 return false;
298 }
299
300 // Get the cached data at the index slot for the received data
301 Super::LoadData(ReceivedData.LocalFrame);
302 DataType& Data = Super::DataHistory[Super::CurrentIndex];
303
304 if (Data.LocalFrame < ReceivedData.LocalFrame)
305 {
306 // Allow recording the received data if it's newer than the already recorded data on this index
307 return true;
308 }
309 else if (!Data.bReceivedData && Data.LocalFrame == ReceivedData.LocalFrame)
310 {
311 // If the data exist but is not marked as received and marked as altered, the server has produced this input via extrapolation or interpolation, don't overwrite it with data from the client.
312 if (Data.bDataAltered)
313 {
314 // If we have a newer received data (since we receive multiple data at the same time) merge this data into the newer which can either get recorded or injected at the front of the input buffer on the server.
315 if (NextReceivedData != nullptr)
316 {
317 NextReceivedData->MergeData(ReceivedData);
318 NextReceivedData->bDataAltered = true;
319 }
320
321 // Mark the already cached data as received so that we don't perform this merge again when receiving redundant inputs / states
322 Data.bReceivedData = true;
323 return false;
324 }
325 else
326 {
327 // Allow recording the received data if we already have data for the same frame cached, not marked as altered, meaning it was predicted data on the client
328 return true;
329 }
330 }
331 return false;
332 }
333
335 virtual bool TriggerRewindFromNewData(DataType& NewData)
336 {
337 if (Super::EvalData(NewData.LocalFrame) && !Super::DataHistory[Super::CurrentIndex].bReceivedData)
338 {
339 return !NewData.CompareData(Super::DataHistory[Super::CurrentIndex]);
340 }
341
342 return false;
343 }
344
345 UE_DEPRECATED(5.6, "Deprecated, use the NetSerialize call with parameter that takes a function DataSetupFunction, pass in nullptr to opt out of implementing a function.")
347 {
348 NetSerialize(Ar, InPackageMap, [](void* Data, const int32 DataIndex) {});
349 }
350
351 virtual void NetSerialize(FArchive& Ar, UPackageMap* InPackageMap, TUniqueFunction<void(void* Data, const int32 DataIndex)> DataSetupFunction) override
352 {
353 bool bOneEntry = Super::NumFrames == 1;
354 Ar.SerializeBits(&bOneEntry, 1);
355
356 if (!bOneEntry)
357 {
361 }
362 else
363 {
365 }
366
367 if (Super::NumFrames > GetMaxArraySize())
368 {
369 UE_LOG(LogTemp, Warning, TEXT("TNetRewindHistory: serialized array of size %d exceeds maximum size %d."), Super::NumFrames, GetMaxArraySize());
370 Ar.SetError();
371 return;
372 }
373
374 if (Ar.IsLoading())
375 {
377 }
378
379 for (int32 I = 0; I < Super::DataHistory.Num(); I++)
380 {
381 DataType& Data = Super::DataHistory[I];
382
383 // Set the implementation component pointer and stateful delta serialization source
385 {
386 DataSetupFunction(&Data, I);
387 }
388
389 // Set the internal delta serialization source (between data entries in the collection)
390 if (I > 0)
391 {
392 if constexpr (bLegacyData)
393 {
394 Data.SetDeltaSourceData(&Super::DataHistory[I - 1]);
395 }
396 }
397 }
398
399 for (DataType& Data : Super::DataHistory)
400 {
401 NetSerializeData(Data, Ar, InPackageMap);
402
403 // Clear delta source and strong pointer to implementation component after serialization
404 if constexpr (bLegacyData)
405 {
406 Data.ClearImplementationComponent();
407 Data.ClearDeltaSourceData();
408 }
409 }
410
412 }
413
416 {
418
419 if(NetDebugHistory.NumFrames >= 0)
420 {
421 LocalFrames.SetNum(NetDebugHistory.NumFrames);
422 ServerFrames.SetNum(NetDebugHistory.NumFrames);
423 InputFrames.SetNum(NetDebugHistory.NumFrames);
424
425 DataType FrameData;
426 for (int32 FrameIndex = 0; FrameIndex < NetDebugHistory.NumFrames; ++FrameIndex)
427 {
428 FrameData = NetDebugHistory.DataHistory[FrameIndex];
429 LocalFrames[FrameIndex] = FrameData.LocalFrame;
430 ServerFrames[FrameIndex] = FrameData.ServerFrame;
431 InputFrames[FrameIndex] = FrameData.bDataAltered ? 1 : 0; // For now we show the altered state inside the InputFrames array, since that was the main usecase for it when it was implemented
432 }
433 }
434 }
435
437 virtual void DebugData(const FString& DebugText) override
438 {
439 UE_LOG(LogChaos, Log, TEXT("%s"), *DebugText);
440 UE_LOG(LogChaos, Log, TEXT(" NumFrames in data collection: %d"), Super::NumFrames);
441
442 if (Super::NumFrames >= 0)
443 {
444 for (int32 FrameIndex = 0; FrameIndex < Super::NumFrames; ++FrameIndex)
445 {
446 UE_LOG(LogChaos, Log, TEXT(" Index: %d || LocalFrame = %d || ServerFrame = %d || bDataAltered = %d || bReceivedData = %d || bImportant = %d || Data: %s")
447 , FrameIndex
448 , Super::DataHistory[FrameIndex].LocalFrame
449 , Super::DataHistory[FrameIndex].ServerFrame
450 , Super::DataHistory[FrameIndex].bDataAltered
451 , Super::DataHistory[FrameIndex].bReceivedData
452 , Super::DataHistory[FrameIndex].bImportant
453 , *Super::DataHistory[FrameIndex].DebugData());
454 }
455 }
456 }
457
458private :
459
461 static int32 GetMaxArraySize()
462 {
464 return MaxArraySize;
465 }
466
468 bool NetSerializeData(DataType& FrameData, FArchive& Ar, UPackageMap* PackageMap) const
469 {
470 bool bOutSuccess = false;
471 UScriptStruct* ScriptStruct = DataType::StaticStruct();
472 if (ScriptStruct->StructFlags & STRUCT_NetSerializeNative)
473 {
474 ScriptStruct->GetCppStructOps()->NetSerialize(Ar, PackageMap, bOutSuccess, &FrameData);
475 }
476 else
477 {
478 UE_LOG(LogTemp, Error, TEXT("TNetRewindHistory::NetSerializeData called on data struct %s without a native NetSerialize"), *ScriptStruct->GetName());
479
480 // Not working for now since the packagemap could be null
481 // UNetConnection* Connection = CastChecked<UPackageMapClient>(PackageMap)->GetConnection();
482 // UNetDriver* NetDriver = Connection ? Connection->GetDriver() : nullptr;
483 // TSharedPtr<FRepLayout> RepLayout = NetDriver ? NetDriver->GetStructRepLayout(ScriptStruct) : nullptr;
484 //
485 // if (RepLayout.IsValid())
486 // {
487 // bool bHasUnmapped = false;
488 // RepLayout->SerializePropertiesForStruct(ScriptStruct, Ar, PackageMap, &FrameData, bHasUnmapped);
489 //
490 // bOutSuccess = true;
491 // }
492 }
493 return bOutSuccess;
494 }
495};
496
500USTRUCT()
502{
504
506
508 bool operator==(const FNetworkPhysicsRewindDataProxy& Other) const { return false; }
509
510protected:
511 UE_DEPRECATED(5.6, "Deprecated, use the NetSerializeBase call with parameter that takes a function GetDeltaSourceData, pass in nullptr to opt out of implementing a source for delta compression")
512 bool NetSerializeBase(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess, TUniqueFunction<TUniquePtr<Chaos::FBaseRewindHistory>()> CreateHistoryFunction) { return NetSerializeBase(Ar, Map, bOutSuccess, [&](){ return CreateHistoryFunction(); }, nullptr); };
513
515
516public:
519
521 UPROPERTY()
523
525 bool bDeltaSerializationIssue = false;
526};
527
531USTRUCT()
533{
535
536 bool NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess);
537};
538
539template<>
540struct TStructOpsTypeTraits<FNetworkPhysicsRewindDataInputProxy> : public TStructOpsTypeTraitsBase2<FNetworkPhysicsRewindDataInputProxy>
541{
542 enum
543 {
546 };
547};
548
552USTRUCT()
554{
556
557 bool NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess);
558};
559
560template<>
561struct TStructOpsTypeTraits<FNetworkPhysicsRewindDataRemoteInputProxy> : public TStructOpsTypeTraitsBase2<FNetworkPhysicsRewindDataRemoteInputProxy>
562{
563 enum
564 {
567 };
568};
569
573USTRUCT()
575{
577
578 bool NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess);
579};
580
581template<>
582struct TStructOpsTypeTraits<FNetworkPhysicsRewindDataStateProxy> : public TStructOpsTypeTraitsBase2<FNetworkPhysicsRewindDataStateProxy>
583{
584 enum
585 {
588 };
589};
593USTRUCT()
595{
597
598 bool NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess);
599};
600
601template<>
602struct TStructOpsTypeTraits<FNetworkPhysicsRewindDataImportantInputProxy> : public TStructOpsTypeTraitsBase2<FNetworkPhysicsRewindDataImportantInputProxy>
603{
604 enum
605 {
608 };
609};
610
614USTRUCT()
616{
618
619 bool NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess);
620};
621
622template<>
623struct TStructOpsTypeTraits<FNetworkPhysicsRewindDataImportantStateProxy> : public TStructOpsTypeTraitsBase2<FNetworkPhysicsRewindDataImportantStateProxy>
624{
625 enum
626 {
629 };
630};
631
632
636USTRUCT()
638{
640
641 bool NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess);
642};
643
644template<>
645struct TStructOpsTypeTraits<FNetworkPhysicsRewindDataDeltaSourceStateProxy> : public TStructOpsTypeTraitsBase2<FNetworkPhysicsRewindDataDeltaSourceStateProxy>
646{
647 enum
648 {
651 };
652};
653
657USTRUCT()
659{
661
662 bool NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess);
663};
664
665template<>
666struct TStructOpsTypeTraits<FNetworkPhysicsRewindDataDeltaSourceInputProxy> : public TStructOpsTypeTraitsBase2<FNetworkPhysicsRewindDataDeltaSourceInputProxy>
667{
668 enum
669 {
672 };
673};
674
675
680{
683
684 // Delegate on the internal inputs process
687 // Bind to this for additional processing on the GT during InjectInputs_External()
689
690 // Rewind API
691 virtual void InjectInputs_External(int32 PhysicsStep, int32 NumSteps) override;
692 virtual void ProcessInputs_External(int32 PhysicsStep, const TArray<Chaos::FSimCallbackInputAndObject>& SimCallbackInputs);
693 virtual void ProcessInputs_Internal(int32 PhysicsStep, const TArray<Chaos::FSimCallbackInputAndObject>& SimCallbackInputs) override;
694 virtual void PreResimStep_Internal(int32 PhysicsStep, bool bFirst) override;
695 virtual void PostResimStep_Internal(int32 PhysicsStep) override;
698 {
699 if (SimCallbackObject && SimCallbackObject->HasOption(Chaos::ESimCallbackOptions::Rewind))
700 {
701 RewindableCallbackObjects.Add(SimCallbackObject);
702 }
703 }
704
706 {
707 RewindableCallbackObjects.Remove(SimCallbackObject);
708 }
709
710 // World owning that callback
711 UWorld* World = nullptr;
712
713 // List of rewindable sim callback objects
715};
716
717
721UCLASS(MinimalAPI)
723{
724public:
725
728
730
731 // Subsystem Init/Deinit
733 ENGINE_API virtual void Deinitialize() override;
734
735 // Delegate at world init
736 ENGINE_API void OnWorldPostInit(UWorld* World, const UWorld::InitializationValues);
737};
738
739
742USTRUCT()
744{
746
748
749 UPROPERTY()
750 int32 ServerFrame = 0;
751
752 mutable int32 LocalFrame = 0; // TEMP: Mutable because we need to set this after receiving it via RPC where it's const
753
760 virtual void InterpolateData(const FNetworkPhysicsPayload& MinData, const FNetworkPhysicsPayload& MaxData, float LerpAlpha) {}
761
768
774 virtual void DecayData(float DecayAmount) {}
775
781 virtual bool CompareData(const FNetworkPhysicsPayload& PredictedData) const { return true; }
782
784 virtual const FString DebugData() { return FString(" - DebugData() not implemented - "); } // TODO, Deprecate non-const version
785 virtual const FString DebugData() const { return FString(" - DebugData() not implemented - "); }
786
787 // If this data was altered so that it doesn't correspond the produced source data (from merging, interpolating or extrapolating)
788 bool bDataAltered = false;
789
790 // If this data was received over the network or locally predicted
791 bool bReceivedData = false;
792
793 // If this data is marked as important (replicated reliably)
794 bool bImportant = false;
795
796 void PrepareFrame(int32 CurrentFrame, bool bIsServer, int32 ClientFrameOffset)
797 {
798 LocalFrame = CurrentFrame;
799 ServerFrame = bIsServer ? CurrentFrame : CurrentFrame + ClientFrameOffset;
800 bDataAltered = false;
801 bReceivedData = false;
802 bImportant = false;
803 }
804
806 UE_DEPRECATED(5.7, "Temporary virtual function for backwards compatibility with FNetworkPhysicsData. Use the InterpolateData function that passes the LerpAlpha instead")
808 {
809 float LerpAlpha = 0.5f;
810 if (MaxData.LocalFrame != MinData.LocalFrame)
811 {
812 LerpAlpha = static_cast<float>(LocalFrame - MinData.LocalFrame) / static_cast<float>(MaxData.LocalFrame - MinData.LocalFrame);
813 LerpAlpha = FMath::Clamp(LerpAlpha, 0.0f, 1.0f);
814 }
815 InterpolateData(MinData, MaxData, LerpAlpha);
816 }
817};
818
819USTRUCT()
821{
823
824 UPROPERTY()
826
827 // TEMP, handle this via FNetworkPhysicsPayloadNetSerializer (but without offset, just set LocalFrame = ServerFrame)
828 void UpdateLocalFrameFromServerFrame(const int32 ClientFrameOffset) const
829 {
831 {
832 const FNetworkPhysicsPayload& Data = DataInstance.Get();
833 Data.LocalFrame = Data.ServerFrame - ClientFrameOffset;
834 }
835 }
836
837 void DebugCollection(const FString& DebugText) const
838 {
839 UE_LOG(LogChaos, Log, TEXT("%s"), *DebugText);
840 UE_LOG(LogChaos, Log, TEXT(" NumFrames in data collection: %d"), DataArray.Num());
841
842 if (DataArray.Num() >= 0)
843 {
844 for (int32 FrameIndex = 0; FrameIndex < DataArray.Num(); ++FrameIndex)
845 {
846 const TInstancedStruct<FNetworkPhysicsPayload>& DataInstance = DataArray[FrameIndex];
848
849 if (Data)
850 {
851 UE_LOG(LogChaos, Log, TEXT(" Index: %d || LocalFrame = %d || ServerFrame = %d || bDataAltered = %d || bReceivedData = %d || bImportant = %d || Data: %s")
852 , FrameIndex
853 , Data->LocalFrame
854 , Data->ServerFrame
855 , Data->bDataAltered
856 , Data->bReceivedData
857 , Data->bImportant
858 , *Data->DebugData());
859 }
860 else
861 {
862 UE_LOG(LogChaos, Log, TEXT(" No data in collection"));
863 }
864 }
865 }
866 }
867
868};
869
870// Game Thread Input and State Interface API
872{
873protected:
875
876public:
878};
879
880template<typename InputType, typename StateType>
882{
883protected:
885
886private:
887 // Wrapper for non-templated base
888 void ValidateInput(FNetworkPhysicsPayload& Input) const override { ValidateInput_External(static_cast<InputType&>(Input)); }
889
890public:
894 virtual void ValidateInput_External(InputType& Input) const = 0;
895};
896
897// Physics Thread Input and State Interface API
899{
900protected:
902
903public:
904 virtual void BuildInput(FNetworkPhysicsPayload& Input) const = 0;
906 virtual void ApplyInput(const FNetworkPhysicsPayload& Input) = 0;
907
908 virtual void BuildState(FNetworkPhysicsPayload& State) const = 0;
909 virtual void ApplyState(const FNetworkPhysicsPayload& State) = 0;
910};
911
912template<typename InputType, typename StateType>
914{
915protected:
917
918private:
919 // Wrapper for non-templated base
920 void BuildInput(FNetworkPhysicsPayload& Input) const override { BuildInput_Internal(static_cast<InputType&>(Input)); }
921 void ValidateInput(FNetworkPhysicsPayload& Input) const override { ValidateInput_Internal(static_cast<InputType&>(Input)); }
922 void ApplyInput(const FNetworkPhysicsPayload& Input) override { ApplyInput_Internal(static_cast<const InputType&>(Input)); }
923
924 void BuildState(FNetworkPhysicsPayload& State) const override { BuildState_Internal(static_cast<StateType&>(State)); }
925 void ApplyState(const FNetworkPhysicsPayload& State) override { ApplyState_Internal(static_cast<const StateType&>(State)); }
926
927public:
929 virtual void BuildInput_Internal(InputType& Input) const = 0;
930
934 virtual void ValidateInput_Internal(InputType& Input) const = 0;
935
937 virtual void ApplyInput_Internal(const InputType& Input) = 0;
938
940 virtual void BuildState_Internal(StateType& State) const = 0;
941
943 virtual void ApplyState_Internal(const StateType& State) = 0;
944};
945
952USTRUCT()
954{
956
957 PRAGMA_DISABLE_DEPRECATION_WARNINGS // Needed while we have a deprecated property inside the struct
959 virtual ~FNetworkPhysicsData() = default;
965
966#if WITH_EDITORONLY_DATA
967 // InputFrame is no longer replicated or used. Use bDataAltered to check if an input has been altered
968 UE_DEPRECATED(5.6, "InputFrame is no longer replicated or used. Use bDataAltered to check if an input has been altered.")
969 UPROPERTY(meta = (DeprecatedProperty, DeprecationMessage = "InputFrame is no longer replicated or populated. Use bDataAltered to check if an input has been altered"))
971#endif
972
975 TStrongObjectPtr<UActorComponent> ImplementationComponent = nullptr;
976
981 void ClearImplementationComponent() { ImplementationComponent = nullptr; }
982
984 FNetworkPhysicsData* DeltaSourceData = nullptr;
985
990 void ClearDeltaSourceData() { DeltaSourceData = nullptr; }
991
992 // Serialize the data into/from the archive
994 {
995 // Delta Serialization
996 if (DeltaSourceData)
997 {
999
1000 bool bIncrememtalFrame = false;
1001 if (Ar.IsLoading())
1002 {
1004 if (!bIncrememtalFrame)
1005 {
1006 bool bFrameDeltaNegative = false;
1007 Ar.SerializeBits(&bFrameDeltaNegative, 1); // Get if the delta is negative
1009 Ar.SerializeIntPacked(FrameDeltaUnsigned); // Get the frame delta
1010
1011 // Apply the frame delta to the delta source to get the ServerFrame value
1012 ServerFrame = bFrameDeltaNegative ? (DeltaSourceData->ServerFrame - FrameDeltaUnsigned) : (DeltaSourceData->ServerFrame + FrameDeltaUnsigned);
1013 }
1014 else
1015 {
1016 // Increment the delta source ServerFrame once to get the ServerFrame value
1017 ServerFrame = DeltaSourceData->ServerFrame + 1;
1018 }
1019
1020 LocalFrame = ServerFrame; // Temporarily set LocalFrame to ServerFrame, it will get recalculated later in TRewindHistory::ReceiveNewData
1021 }
1022 else
1023 {
1024 bIncrememtalFrame = ServerFrame == (DeltaSourceData->ServerFrame + 1);
1025 Ar.SerializeBits(&bIncrememtalFrame, 1); // Write if the frame delta is just +1, which is most common for internal deltas
1026 if (!bIncrememtalFrame)
1027 {
1028 int32 FrameDelta = ServerFrame - DeltaSourceData->ServerFrame; // Get the frame delta
1029 bool bFrameDeltaNegative = FrameDelta < 0;
1030 Ar.SerializeBits(&bFrameDeltaNegative, 1); // Write if the delta is negative
1031 uint32 FrameDeltaUnsigned = FMath::Abs(FrameDelta);
1032 Ar.SerializeIntPacked(FrameDeltaUnsigned); // Write the unsigned delta frame
1033 }
1034 }
1035 }
1036 else // Standard Serialization
1037 {
1039 if (Ar.IsLoading()) // Deserializing
1040 {
1042 ServerFrame = static_cast<int32>(ServerFrameUnsigned) - 1;
1043 LocalFrame = ServerFrame; // Temporarily set LocalFrame to ServerFrame, it will get recalculated later in TRewindHistory::ReceiveNewData
1044 }
1045 else // Serializing
1046 {
1047 check((ServerFrame + 1) >= 0);
1048 ServerFrameUnsigned = static_cast<uint32>(ServerFrame + 1);
1050 }
1051 }
1052 }
1053
1057 {
1058 bImportant = bIsImportant;
1059 }
1060
1061 // Apply the data onto the network physics component
1063
1064 // Build the data from the network physics component
1066
1073
1079 virtual void DecayData(float DecayAmount) override { }
1080
1086 virtual void MergeData(const FNetworkPhysicsData& FromData) { }
1087
1093
1099 virtual bool CompareData(const FNetworkPhysicsData& PredictedData) { return true; }
1100
1102 virtual const FString DebugData() { return FString(" - DebugData() not implemented - "); }
1103
1105 {
1106 return ServerFrame == Other.ServerFrame && LocalFrame == Other.LocalFrame;
1107 }
1108
1109 // Base API Wrapper
1110 UE_DEPRECATED(5.7, "Temporary virtual function for backwards compatibility with FNetworkPhysicsData. Use the InterpolateData function that passes the LerpAlpha instead")
1111 void DoInterpolateData(const FNetworkPhysicsPayload& MinData, const FNetworkPhysicsPayload& MaxData) override { this->InterpolateData(static_cast<const FNetworkPhysicsData&>(MinData), static_cast<const FNetworkPhysicsData&>(MaxData)); }
1112 void MergeData(const FNetworkPhysicsPayload& FromData) override { this->MergeData(static_cast<const FNetworkPhysicsData&>(FromData)); }
1113 bool CompareData(const FNetworkPhysicsPayload& PredictedData) const override { return const_cast<FNetworkPhysicsData*>(this)->CompareData(static_cast<const FNetworkPhysicsData&>(PredictedData)); }
1114 using FNetworkPhysicsPayload::InterpolateData; // Silence warning for FNetworkPhysicsData::InterpolateData not overriding a function in FNetworkPhysicsPayload, which is intended
1115};
1116
1119{
1120 virtual ~FNetworkPhysicsDataHelper() = default;
1121
1125 virtual bool IsUsingLegacyData() = 0;
1126
1129
1132
1135
1138
1141
1144
1147
1148/* // Importance is not implemented into the new network flow (yet?)
1149 virtual void ApplyDataRange(const Chaos::FBaseRewindHistory* History, const int32 FromFrame, const int32 ToFrame, INetworkPhysicsInputState_Internal& Interface) = 0;
1150*/
1151};
1152
1154template<typename DataType, bool bLegacyData = false>
1156{
1162
1165 {
1167
1168 // Record at same index as taken from
1169 int32 Idx = 0;
1171 {
1172 const DataType& Data = DataInstance.Get<DataType>();
1173 NetHistory->RecordData(Idx, &Data);
1174 Idx++;
1175 }
1176 }
1177
1180 {
1181 if (ensure(To.DataArray.Num() > 0) == false)
1182 {
1183 return;
1184 }
1185
1187 const TArray<DataType>& HistoryArray = NetHistory->GetDataHistoryConst();
1188 for (int32 FromIdx = 0; FromIdx < NetHistory->GetHistorySize(); FromIdx++)
1189 {
1190 const int32 ToIdx = FromIdx % To.DataArray.Num();
1192 }
1193 }
1194
1197 {
1198 if (ensure(To.DataArray.Num() > 0) == false)
1199 {
1200 return;
1201 }
1203
1204 const TArray<DataType>& HistoryArray = NetHistory->GetDataHistoryConst();
1205 for (int32 FromIdx = 0; FromIdx < NetHistory->GetHistorySize(); FromIdx++)
1206 {
1207 const DataType& FromData = HistoryArray[FromIdx];
1208
1209 const int32 ToIdx = FromIdx % To.DataArray.Num();
1210 const FNetworkPhysicsPayload* ToData = To.DataArray[ToIdx].GetPtr<FNetworkPhysicsPayload>();
1211
1212 // Only copy the data if it's newer than the already cached data
1213 if (!ToData || ToData->LocalFrame < FromData.LocalFrame)
1214 {
1216 }
1217 }
1218 }
1219
1222 {
1223 bool bHasCopiedData = false;
1224 if (ensure(To.DataArray.Num() > 0) == false)
1225 {
1226 return bHasCopiedData;
1227 }
1228
1230
1231 const TArray<DataType>& HistoryArray = NetHistory->GetDataHistoryConst();
1232 for (int32 FromIdx = 0; FromIdx < NetHistory->GetHistorySize(); FromIdx++)
1233 {
1234 const DataType& FromData = HistoryArray[FromIdx];
1235
1236 // Only copy the data that has been altered
1237 if (FromData.bDataAltered)
1238 {
1239 const int32 ToIdx = FromIdx % To.DataArray.Num();
1241 bHasCopiedData = true;
1242 }
1243 }
1244
1245 return bHasCopiedData;
1246 }
1247
1258
1261 {
1263 TArray<DataType>& HistoryArray = NetHistory->GetDataHistory();
1264
1265 for (int32 Idx = 0; Idx < NetHistory->GetHistorySize(); Idx++)
1266 {
1268 if (Data.LocalFrame > LatestValidatedInput_External)
1269 {
1270 Interface.ValidateInput(Data);
1271 }
1272 }
1273 LatestValidatedInput_External = FMath::Max(LatestValidatedInput_External, NetHistory->GetLatestFrame());
1274 }
1275
1278 {
1280 TArray<DataType>& HistoryArray = NetHistory->GetDataHistory();
1281
1282 for (int32 Idx = 0; Idx < NetHistory->GetHistorySize(); Idx++)
1283 {
1285 if (Data.LocalFrame > LatestValidatedInput_Internal)
1286 {
1287 Interface.ValidateInput(Data);
1288 }
1289 }
1290 LatestValidatedInput_Internal = FMath::Max(LatestValidatedInput_Internal, NetHistory->GetLatestFrame());
1291 }
1292
1293/* // Important is not implemented into the new network flow (yet?)
1294 void ApplyDataRange(const Chaos::FBaseRewindHistory* History, const int32 FromFrame, const int32 ToFrame, INetworkPhysicsInputState_Internal& Interface) override
1295 {
1296 const Chaos::TDataRewindHistory<DataType>* NetHistory = static_cast<const Chaos::TDataRewindHistory<DataType>*>(History);
1297 const TArray<DataType>& HistoryArray = NetHistory->GetDataHistoryConst();
1298
1299 for (int32 ApplyFrame = FromFrame; ApplyFrame <= ToFrame; ++ApplyFrame)
1300 {
1301 const int32 ApplyIndex = NetHistory->GetFrameIndex(ApplyFrame);
1302 const DataType& Data = HistoryArray[ApplyIndex];
1303 if (ApplyFrame == Data.LocalFrame)
1304 {
1305 Interface.ApplyInput(Data);
1306 }
1307 }
1308 }
1309*/
1310
1311private:
1312 int32 LatestValidatedInput_External = 0;
1313 int32 LatestValidatedInput_Internal = 0;
1314};
1315
1320UCLASS(BlueprintType, MinimalAPI)
1322{
1324public:
1326
1327 // Get the player controller
1328 ENGINE_API virtual APlayerController* GetPlayerController() const;
1329
1330 // Get the controller for this pawn
1331 ENGINE_API virtual AController* GetController() const;
1332
1333 // Init the network physics component
1334 ENGINE_API void InitPhysics();
1335
1336 // Called every frame
1337 ENGINE_API virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
1338
1339 // Function to init the replicated properties
1340 ENGINE_API virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifeTimeProps) const override;
1341
1342 // Function called just before replication, alter the active state of replicated properties
1343 ENGINE_API virtual void PreReplication(IRepChangedPropertyTracker& ChangedPropertyTracker) override;
1344
1345 // Used to create any physics engine information for this component
1346 ENGINE_API virtual void BeginPlay() override;
1347
1348 // Register the component into the network manager
1349 ENGINE_API virtual void InitializeComponent() override;
1350
1351 // Unregister the component from the network manager
1352 ENGINE_API virtual void UninitializeComponent() override;
1353
1354 // Remove state/input history from rewind data
1355 ENGINE_API void RemoveDataHistory();
1356
1357 // Add state/input history to rewind data
1358 ENGINE_API void AddDataHistory();
1359
1360 // Get the GameThread state history (not guaranteed to be the exact data used in physics, for that use GetStateHistory_Internal on PhysicsThread)
1362
1363 // Get the PhysicsThread state history (if there is none it returns the GameThread history)
1364 ENGINE_API TSharedPtr<Chaos::FBaseRewindHistory>& GetStateHistory_Internal();
1365
1366 // Get the GameThread input history (not guaranteed to be the exact data used in physics, for that use GetInputHistory_Internal on PhysicsThread)
1368
1369 // Get the PhysicsThread input history (if there is none it returns the GameThread history)
1370 ENGINE_API TSharedPtr<Chaos::FBaseRewindHistory>& GetInputHistory_Internal();
1371
1372 // Check if the world is on server
1373 ENGINE_API bool HasServerWorld() const;
1374
1375 // Check if this is controlled locally through relayed inputs or an existing local player controller
1376 ENGINE_API bool IsLocallyControlled() const;
1377
1378 // Check if networked physics is setup with a synchronized physics tick offset
1379 ENGINE_API bool IsNetworkPhysicsTickOffsetAssigned() const;
1380
1385 {
1386 bIsRelayingLocalInputs = bInRelayingLocalInputs;
1387 }
1388
1393 {
1394 if (bIsRelayingLocalInputs)
1395 {
1396 bStopRelayingLocalInputsDeferred = true;
1397 }
1398 }
1399
1401 const bool GetIsRelayingLocalInputs() const { return bIsRelayingLocalInputs; }
1402
1405 ENGINE_API void SetCompareStateToTriggerRewind(const bool bInCompareStateToTriggerRewind, const bool bInIncludeSimProxies = false);
1406
1408 ENGINE_API void SetCompareInputToTriggerRewind(const bool bInCompareInputToTriggerRewind);
1409
1411 FAsyncNetworkPhysicsComponent* GetNetworkPhysicsComponent_Internal() { return NetworkPhysicsComponent_Internal; }
1412
1416
1417protected:
1418
1419 // repnotify for input, used for delta serialization
1420 UFUNCTION()
1421 ENGINE_API void OnRep_SetReplicatedDeltaSourceInput();
1422
1423 // repnotify for state, used for delta serialization
1424 UFUNCTION()
1425 ENGINE_API void OnRep_SetReplicatedDeltaSourceState();
1426
1427 // replicated physics input, used for delta serialization
1428 UPROPERTY(Transient, ReplicatedUsing = OnRep_SetReplicatedDeltaSourceInput)
1430
1431 // replicated physics states, used for delta serialization
1432 UPROPERTY(Transient, ReplicatedUsing = OnRep_SetReplicatedDeltaSourceState)
1434
1437 ENGINE_API void ServerReceiveDeltaSourceInputFrame(const int32 Frame);
1438
1441 ENGINE_API void ServerReceiveDeltaSourceStateFrame(const int32 Frame);
1442
1443
1444 // Server RPC to receive inputs from client
1447
1448 // Server RPC to receive important inputs from client
1450 ENGINE_API void ServerReceiveImportantInputData(const FNetworkPhysicsRewindDataImportantInputProxy& ClientInputs);
1451
1452 // Client RPC to receive important inputs from server
1453 UFUNCTION(NetMulticast, reliable)
1454 ENGINE_API void MulticastReceiveImportantInputData(const FNetworkPhysicsRewindDataImportantInputProxy& ServerInputs);
1455
1456 // Client RPC to receive important states from server
1457 UFUNCTION(NetMulticast, reliable)
1458 ENGINE_API void MulticastReceiveImportantStateData(const FNetworkPhysicsRewindDataImportantStateProxy& ServerStates);
1459
1460 // replicated important physics input
1463
1464 // replicated important physics state
1467
1468 // repnotify for inputs on owner client
1469 UFUNCTION()
1470 ENGINE_API void OnRep_SetReplicatedInputs();
1471
1472 // repnotify for inputs on remote clients
1473 UFUNCTION()
1474 ENGINE_API void OnRep_SetReplicatedRemoteInputs();
1475
1476 // repnotify for the states on the client
1477 UFUNCTION()
1478 ENGINE_API void OnRep_SetReplicatedStates();
1479
1480 // replicated physics inputs for owner client
1481 UPROPERTY(Transient, ReplicatedUsing = OnRep_SetReplicatedInputs)
1483
1484 // replicated physics inputs for remote clients
1485 UPROPERTY(Transient, ReplicatedUsing = OnRep_SetReplicatedRemoteInputs)
1487
1488 // replicated physics states
1489 UPROPERTY(Transient, ReplicatedUsing = OnRep_SetReplicatedStates)
1491
1492
1494 // Server RPC to receive inputs from client
1496 ENGINE_API void ServerReceiveInputCollection(const FNetworkPhysicsDataCollection& ClientInputCollection);
1497
1498 // repnotify for inputs on owner client
1499 UFUNCTION()
1500 ENGINE_API void OnRep_SetReplicatedInputCollection();
1501
1502 // repnotify for inputs on remote clients
1503 UFUNCTION()
1504 ENGINE_API void OnRep_SetReplicatedRemoteInputCollection();
1505
1506 // repnotify for the states on the client
1507 UFUNCTION()
1508 ENGINE_API void OnRep_SetReplicatedStateCollection();
1509
1510 // replicated physics inputs for owner client
1511 UPROPERTY(Transient, ReplicatedUsing = OnRep_SetReplicatedInputCollection)
1512 FNetworkPhysicsDataCollection ReplicatedInputCollection;
1513
1514 // replicated physics inputs for remote clients
1515 UPROPERTY(Transient, ReplicatedUsing = OnRep_SetReplicatedRemoteInputCollection)
1516 FNetworkPhysicsDataCollection ReplicatedRemoteInputCollection;
1517
1518 // replicated physics states
1519 UPROPERTY(Transient, ReplicatedUsing = OnRep_SetReplicatedStateCollection)
1520 FNetworkPhysicsDataCollection ReplicatedStateCollection;
1521
1522
1523private:
1525 void NetworkMarshaledData();
1526
1528 void UpdateAsyncComponent(const bool bFullUpdate);
1529
1531 ENGINE_API void CreateAsyncDataHistory();
1532
1536 void SetNumberOfInputsToNetwork(const uint16 NumInputs)
1537 {
1538 InputsToNetwork_OwnerDefault = FMath::Max(NumInputs, static_cast<uint16>(1));
1539 InputsToNetwork_Owner = InputsToNetwork_OwnerDefault;
1540 }
1541
1544 void SetNumberOfRemoteInputsToNetwork(const uint16 NumInputs)
1545 {
1546 InputsToNetwork_Simulated = FMath::Max(NumInputs, static_cast<uint16>(1));
1547 }
1548
1550 void SetNumberOfStatesToNetwork(const uint16 NumInputs)
1551 {
1552 StatesToNetwork = FMath::Max(NumInputs, static_cast<uint16>(1));
1553 }
1554
1556 void AddDeltaSourceInput();
1557
1559 void AddDeltaSourceState();
1560
1562 const int32 GetNextDeltaSourceInputIndex() const { return GetDeltaSourceIndexForFrame(LatestCachedDeltaSourceInputIndex + 1); }
1563
1565 const int32 GetNextDeltaSourceStateIndex() const { return GetDeltaSourceIndexForFrame(LatestCachedDeltaSourceStateIndex + 1); }
1566
1568 const bool IsValidNextDeltaSourceInput(const int32 Frame) const { return GetDeltaSourceIndexForFrame(Frame) == GetNextDeltaSourceInputIndex(); }
1569
1571 const bool IsValidNextDeltaSourceState(const int32 Frame) const { return GetDeltaSourceIndexForFrame(Frame) == GetNextDeltaSourceStateIndex(); }
1572
1573public:
1577 FNetworkPhysicsData* GetDeltaSourceInput(const int32 Value, const bool bValueIsIndexElseFrame);
1578
1582 FNetworkPhysicsData* GetDeltaSourceState(const int32 Value, const bool bValueIsIndexElseFrame);
1583
1585 static const int32 DeltaSourceBufferSize = 10;
1586
1588 static const int32 GetDeltaSourceIndexForFrame(const int32 Frame) { return FMath::Abs(Frame % DeltaSourceBufferSize); }
1589
1591 template<typename PhysicsTraits>
1592 void CreateDataHistory(UActorComponent* HistoryComponent);
1593
1597 template<class InputsType>
1598 void CreateInputHistory(UActorComponent* HistoryComponent);
1599
1601 template<typename Input, typename State>
1603
1604private:
1605
1614
1615 INetworkPhysicsInputState_Internal* ImplementationInterface_Internal = nullptr;
1616 INetworkPhysicsInputState_External* ImplementationInterface_External = nullptr;
1617
1618 bool bIsUsingLegacyData = false;
1619
1620 // Network Physics Component data internal to the physics thread
1621 FAsyncNetworkPhysicsComponent* NetworkPhysicsComponent_Internal;
1622
1623 // States history on GameThread
1625
1626 // Inputs history on GameThread
1628
1629 // Helper for the creation of input data and history with correct derived type
1631
1632 // Helper for the creation of state data and history with correct derived type
1634
1635 // Local default input data in legacy type
1636 TUniquePtr<FNetworkPhysicsData> InputDataDefault_Legacy;
1637
1638 // Local default state data in legacy type
1639 TUniquePtr<FNetworkPhysicsData> StateDataDefault_Legacy;
1640
1641 // The number of inputs the owning client should send to the server with each RPC, replicated from the server. This is dynamically scaled based on when there are holes in the inputs buffer if np2.Resim.DynamicInputScaling.Enabled is enabled
1643 uint16 InputsToNetwork_Owner = 3;
1644
1645 // The default value for number for InputsToNetwork_Owner, acts as the initial value and the cap when dynamically adjusting InputsToNetwork_Owner
1646 uint16 InputsToNetwork_OwnerDefault = 3;
1647
1648 // Send last N number of inputs each replication call from server to remote clients
1649 uint16 InputsToNetwork_Simulated = 2;
1650
1651 // Send last N number of states each replication call from server to remote clients
1652 uint16 StatesToNetwork = 1;
1653
1654 // Array of delta sources, used as a base for delta serialization
1655 TArray<TUniquePtr<FNetworkPhysicsData>> DeltaSourceInputs;
1656 int32 LatestAcknowledgedDeltaSourceInputIndex = 0;
1657 int32 LatestCachedDeltaSourceInputIndex = 0;
1658 double TimeToSyncDeltaSourceInput = 0;
1659
1660 // Array of delta sources, used as a base for delta serialization
1661 TArray<TUniquePtr<FNetworkPhysicsData>> DeltaSourceStates;
1662 int32 LatestAcknowledgedDeltaSourceStateIndex = 0;
1663 int32 LatestCachedDeltaSourceStateIndex = 0;
1664 double TimeToSyncDeltaSourceState = 0;
1665
1666public:
1667 // Actor component that will be used to fill the histories
1668 TWeakObjectPtr<UActorComponent> ActorComponent = nullptr;
1669
1670private:
1671 // Root components physics object
1672 Chaos::FConstPhysicsObjectHandle PhysicsObject = nullptr;
1673
1674 // Locally relayed inputs makes this component act as if it's a locally controlled pawn.
1675 bool bIsRelayingLocalInputs = false;
1676
1677 // If we are currently relaying inputs and will stop after next network send.
1678 bool bStopRelayingLocalInputsDeferred = false;
1679
1680 // Compare state / input to trigger rewind via FNetworkPhysicsPayload::CompareData
1681 bool bCompareStateToTriggerRewind = false;
1682 bool bCompareStateToTriggerRewindIncludeSimProxies = false; // Include simulated proxies when bCompareStateToTriggerRewind is enabled
1683 bool bCompareInputToTriggerRewind = false;
1684
1685 // ToDo, retrieve from NetworkPhysicsSettingsComponent so changes at runtime gets picked up
1686 bool bEnableUnreliableFlow = true;
1687 bool bEnableReliableFlow = false;
1688 bool bValidateDataOnGameThread = false;
1689
1691private:
1692#if WITH_EDITORONLY_DATA
1693 UE_DEPRECATED(5.6, "Deprecated, use InputsToNetwork_Owner instead")
1695 UE_DEPRECATED(5.6, "Deprecated, use InputsToNetwork_Simulated instead")
1697#endif
1698};
1699
1700template<typename Input, typename State>
1702{
1703 bIsUsingLegacyData = false;
1704
1705 ImplementationInterface_Internal = Implementation_Internal;
1706 ImplementationInterface_External = Implementation_External;
1707
1708 InputHelper = MakeUnique<TNetworkPhysicsDataHelper<Input, /*bLegacyData*/ false>>();
1709 StateHelper = MakeUnique<TNetworkPhysicsDataHelper<State, /*bLegacyData*/ false>>();
1710
1711 CreateAsyncDataHistory();
1712}
1713
1714template<typename PhysicsTraits>
1716{
1717 bIsUsingLegacyData = true;
1718
1719 InputHelper = MakeUnique<TNetworkPhysicsDataHelper<typename PhysicsTraits::InputsType, /*bLegacyData*/ true>>();
1720 StateHelper = MakeUnique<TNetworkPhysicsDataHelper<typename PhysicsTraits::StatesType, /*bLegacyData*/ true>>();
1721
1722 InputDataDefault_Legacy = MakeUnique<typename PhysicsTraits::InputsType>();
1723 StateDataDefault_Legacy = MakeUnique<typename PhysicsTraits::StatesType>();
1724
1725 // Initialize delta source arrays
1726 for (int32 I = 0; I < DeltaSourceBufferSize; I++)
1727 {
1730 }
1731
1732 ReplicatedInputs.History = InputHelper->CreateUniqueRewindHistory(InputsToNetwork_OwnerDefault);
1733 ReplicatedInputs.Owner = this;
1734
1735 ReplicatedRemoteInputs.History = InputHelper->CreateUniqueRewindHistory(InputsToNetwork_Simulated);
1737
1738 ReplicatedStates.History = StateHelper->CreateUniqueRewindHistory(StatesToNetwork);
1739 ReplicatedStates.Owner = this;
1740
1741 ReplicatedImportantInput.History = InputHelper->CreateUniqueRewindHistory(1);
1743
1744 ReplicatedImportantState.History = StateHelper->CreateUniqueRewindHistory(1);
1746
1747 ReplicatedDeltaSourceInput.History = InputHelper->CreateUniqueRewindHistory(1);
1749
1750 ReplicatedDeltaSourceState.History = StateHelper->CreateUniqueRewindHistory(1);
1752
1754
1755 CreateAsyncDataHistory();
1756}
1757
1758template<class InputsType>
1760{
1761 bIsUsingLegacyData = true;
1762
1763 InputHelper = MakeUnique<TNetworkPhysicsDataHelper<InputsType, /*bLegacyData*/ true>>();
1764
1765 InputDataDefault_Legacy = MakeUnique<InputsType>();
1766
1767 // Initialize delta source array
1768 for (int32 I = 0; I < DeltaSourceBufferSize; I++)
1769 {
1770 DeltaSourceInputs.Add(MakeUnique<InputsType>());
1771 }
1772
1773 ReplicatedInputs.History = InputHelper->CreateUniqueRewindHistory(InputsToNetwork_OwnerDefault);
1774 ReplicatedInputs.Owner = this;
1775
1776 ReplicatedRemoteInputs.History = InputHelper->CreateUniqueRewindHistory(InputsToNetwork_Simulated);
1778
1779 ReplicatedImportantInput.History = InputHelper->CreateUniqueRewindHistory(1);
1781
1782 ReplicatedDeltaSourceInput.History = InputHelper->CreateUniqueRewindHistory(1);
1784
1786
1787 CreateAsyncDataHistory();
1788}
1789
1790
1791// --------------------------- PhysicsThread Network Physics Component ---------------------------
1792
1794{
1813
1816
1819
1856};
1857
1886
1888 FAsyncNetworkPhysicsComponentInput,
1889 FAsyncNetworkPhysicsComponentOutput,
1890 Chaos::ESimCallbackOptions::PhysicsObjectUnregister>
1891{
1893
1894public:
1897
1898 // Get reference to async output for current internal frame and initialize it if not already done
1900
1901 // If this network physics component is locally controlled, can be either server or autonomous proxy
1902 const bool IsLocallyControlled() const { return bIsLocallyControlled; }
1903
1904 // If we are on the server
1905 const bool IsServer() const { return (NetMode == ENetMode::NM_DedicatedServer || NetMode == ENetMode::NM_ListenServer); }
1906
1907 // Get the ENetRole
1908 const ENetRole GetNetRole() const { return NetRole; }
1909
1910 // Get actor name
1911 const FString GetActorName() const { return ActorName; }
1912
1913 // Get the physics tick offset (add to clients physics tick to get the servers corresponding physics tick)
1914 const int32 GetNetworkPhysicsTickOffset() const { return NetworkPhysicsTickOffset; }
1915
1916 // Get the physics replication mode used
1917 const EPhysicsReplicationMode GetPhysicsReplicationMode() const { return PhysicsReplicationMode; }
1918
1919 // Add state/input history to rewind data
1921
1922 // Remove state/input history from rewind data
1924
1925 // Enable RewindData history caching and return the history size
1926 const int32 SetupRewindData();
1927
1928private:
1929 // Initialize, bind delegates etc.
1930 void OnInitialize_Internal();
1931
1932 // Uninitialize, unbind delegates etc.
1933 void OnUninitialize_Internal();
1934
1935 virtual void OnPhysicsObjectUnregistered_Internal(Chaos::FConstPhysicsObjectHandle PhysicsObject) override;
1936
1937 // Delegate ran at the start of FNetworkPhysicsCallback::ProcessInputs_Internal, used to receive and apply inputs and states if needed.
1938 void OnPreProcessInputs_Internal(const int32 PhysicsStep);
1939
1940 // Delegate ran at the end of FNetworkPhysicsCallback::ProcessInputs_Internal, used to record and send inputs and states if needed.
1941 void OnPostProcessInputs_Internal(const int32 PhysicsStep);
1942
1943 // Consume data from async input
1944 void ConsumeAsyncInput(const int32 PhysicsStep);
1945
1947 Chaos::FPBDRigidsSolver* GetRigidSolver();
1948
1950 Chaos::FPBDRigidsEvolution* GetEvolution();
1951
1953 const FNetworkPhysicsSettingsNetworkPhysicsComponent& GetComponentSettings() const;
1954
1956 void TriggerResimulation(int32 ResimFrame);
1957
1959 const float GetCurrentInputDecay(const FNetworkPhysicsPayload* PhysicsData);
1960
1962 void SendInputData_Internal(FAsyncNetworkPhysicsComponentOutput& AsyncOutput, const int32 PhysicsStep);
1963
1965 void SendStateData_Internal(FAsyncNetworkPhysicsComponentOutput& AsyncOutput, const int32 PhysicsStep);
1966
1968 void UpdateDynamicInputScaling();
1969
1970private:
1971 bool bIsLocallyControlled;
1972 ENetMode NetMode;
1973 ENetRole NetRole;
1974 int32 NetworkPhysicsTickOffset;
1975 EPhysicsReplicationMode PhysicsReplicationMode;
1976 FString ActorName;
1977 bool bIsUsingLegacyData;
1978
1979 int32 LastInputSendFrame = INDEX_NONE;
1980 int32 LastStateSendFrame = INDEX_NONE;
1981 int32 NewImportantInputFrame = INT_MAX;
1982
1983 // Component settings
1985 static const FNetworkPhysicsSettingsNetworkPhysicsComponent SettingsNetworkPhysicsComponent_Default;
1986
1987 // Actor component that will be used to fill the histories
1988 TWeakObjectPtr<UActorComponent> ActorComponent;
1989
1990 // Implementation of input / state interface
1991 INetworkPhysicsInputState_Internal* ImplementationInterface_Internal;
1992
1993 // Root components physics object
1995
1996 // Helper for the creation of input data and history with correct derived type
1998
1999 // Helper for the creation of state data and history with correct derived type
2001
2002 // States history uses to rewind simulation
2004
2005 // Inputs history used during simulation
2007
2008 // Local temporary inputs data used by pre/post process inputs functions
2010
2011 // Local temporary inputs data used by ConsumeAsyncInput
2012 TUniquePtr<FNetworkPhysicsPayload> LatestInputReceiveData;
2013
2014 // Local temporary states data used by pre/post process inputs functions
2016
2017 // Send last N number of inputs each replication call
2018 uint16 InputsToNetwork_OwnerDefault = 3; // Default value for owning client
2019 uint16 InputsToNetwork_Owner = 3; // From owning client, i.e. autonomous proxy or client owning an actor with bIsRelayingLocalInputs enabled
2020 uint16 InputsToNetwork_Simulated = 2; // To simulated proxies
2021
2022 // Properties for dynamic scaling of inputs
2023 float TimeOfLastDynamicInputScaling = 0.0f;
2024 float DynamicInputScalingAverageInputs = 0.0f;
2025 int32 MissingInputCount = 0;
2026
2027 // Send last N number of states each replication call
2028 uint16 StatesToNetwork = 1;
2029
2030 // Cache predicted states and then compare incoming states via FNetworkPhysicsData::CompareData to trigger a resim if they desync
2031 bool bCompareStateToTriggerRewind;
2032
2033 // Include simulated proxies when bCompareStateToTriggerRewind is enabled
2034 bool bCompareStateToTriggerRewindIncludeSimProxies;
2035
2036 // Cache compare incoming inputs with locally predicted inputs via FNetworkPhysicsData::CompareData to trigger a resim if they desync
2037 bool bCompareInputToTriggerRewind;
2038
2039 FDelegateHandle DelegateOnPreProcessInputs_Internal;
2040 FDelegateHandle DelegateOnPostProcessInputs_Internal;
2041};
2042
2044{
2045 // Returns the index of the frame about to be simulated, in the server timeline
2047}
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define check(expr)
Definition AssertionMacros.h:314
#define ensure( InExpression)
Definition AssertionMacros.h:464
@ STRUCT_NetSerializeNative
Definition Class.h:1048
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_MULTICAST_DELEGATE_TwoParams(DelegateName, Param1Type, Param2Type)
Definition DelegateCombinations.h:58
#define DECLARE_MULTICAST_DELEGATE_OneParam(DelegateName, Param1Type)
Definition DelegateCombinations.h:49
ENetMode
Definition EngineBaseTypes.h:937
@ NM_DedicatedServer
Definition EngineBaseTypes.h:942
@ NM_ListenServer
Definition EngineBaseTypes.h:945
ELevelTick
Definition EngineBaseTypes.h:70
ENetRole
Definition EngineTypes.h:3346
EPhysicsReplicationMode
Definition EngineTypes.h:3378
#define PRAGMA_ENABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:12
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:8
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
const bool
Definition NetworkReplayStreaming.h:178
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
#define USTRUCT(...)
Definition ObjectMacros.h:746
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
UE_FORCEINLINE_HINT TUniquePtr< T > MakeUnique(TArgs &&... Args)
Definition UniquePtr.h:918
uint32 Size
Definition VulkanMemory.cpp:4034
if(Failed) console_printf("Failed.\n")
UEBinkAudioDecodeInterface * Interface
Definition binka_ue_decode_test.cpp:24
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Controller.h:41
Definition PlayerController.h:261
Definition PBDRigidsEvolutionGBF.h:51
Definition PBDRigidsSolver.h:84
Definition RewindData.h:2189
Definition SimCallbackObject.h:68
bool HasOption(const ESimCallbackOptions Option) const
Definition SimCallbackObject.h:212
Definition SimCallbackObject.h:521
Definition Archive.h:1208
virtual CORE_API void SerializeIntPacked(uint32 &Value)
Definition Archive.cpp:1328
UE_FORCEINLINE_HINT bool IsLoading() const
Definition Archive.h:236
CORE_API void SetError()
Definition Archive.cpp:314
virtual void SerializeBits(void *V, int64 LengthBits)
Definition Archive.h:1707
Definition NetworkPhysicsComponent.h:1891
void RegisterDataHistoryInRewindData()
Definition NetworkPhysicsComponent.cpp:2587
FAsyncNetworkPhysicsComponentOutput & GetAsyncOutput_Internal()
Definition NetworkPhysicsComponent.cpp:1969
const bool IsLocallyControlled() const
Definition NetworkPhysicsComponent.h:1902
const FString GetActorName() const
Definition NetworkPhysicsComponent.h:1911
const int32 GetNetworkPhysicsTickOffset() const
Definition NetworkPhysicsComponent.h:1914
const ENetRole GetNetRole() const
Definition NetworkPhysicsComponent.h:1908
void UnregisterDataHistoryFromRewindData()
Definition NetworkPhysicsComponent.cpp:2610
const bool IsServer() const
Definition NetworkPhysicsComponent.h:1905
FAsyncNetworkPhysicsComponent()
Definition NetworkPhysicsComponent.cpp:1698
const EPhysicsReplicationMode GetPhysicsReplicationMode() const
Definition NetworkPhysicsComponent.h:1917
const int32 SetupRewindData()
Definition NetworkPhysicsComponent.cpp:2625
~FAsyncNetworkPhysicsComponent()
Definition NetworkPhysicsComponent.h:1896
Definition IDelegateInstance.h:14
Definition UnrealType.h:3087
Definition SubsystemCollection.h:15
Definition NetworkPhysicsComponent.h:872
virtual void ValidateInput(FNetworkPhysicsPayload &Input) const =0
virtual ~INetworkPhysicsInputState_External()
Definition NetworkPhysicsComponent.h:874
Definition NetworkPhysicsComponent.h:899
virtual void ValidateInput(FNetworkPhysicsPayload &Input) const =0
virtual ~INetworkPhysicsInputState_Internal()
Definition NetworkPhysicsComponent.h:901
virtual void BuildInput(FNetworkPhysicsPayload &Input) const =0
virtual void ApplyState(const FNetworkPhysicsPayload &State)=0
virtual void ApplyInput(const FNetworkPhysicsPayload &Input)=0
virtual void BuildState(FNetworkPhysicsPayload &State) const =0
Definition CoreNet.h:570
Definition Array.h:670
SizeType Remove(const ElementType &Item)
Definition Array.h:3091
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Reset(SizeType NewSize=0)
Definition Array.h:2246
void SetNum(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2308
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
Definition NetworkPhysicsComponent.h:882
virtual void ValidateInput_External(InputType &Input) const =0
virtual ~TNetworkPhysicsInputState_External()
Definition NetworkPhysicsComponent.h:884
Definition NetworkPhysicsComponent.h:914
virtual void BuildInput_Internal(InputType &Input) const =0
virtual ~TNetworkPhysicsInputState_Internal()
Definition NetworkPhysicsComponent.h:916
virtual void BuildState_Internal(StateType &State) const =0
virtual void ApplyState_Internal(const StateType &State)=0
virtual void ApplyInput_Internal(const InputType &Input)=0
virtual void ValidateInput_Internal(InputType &Input) const =0
Definition SharedPointer.h:692
Definition StrongObjectPtrTemplates.h:26
Definition FunctionFwd.h:19
Definition UniquePtr.h:107
Definition SharedPointer.h:1295
Definition ActorComponent.h:152
Definition NetworkPhysicsComponent.h:1322
FNetworkPhysicsRewindDataImportantStateProxy ReplicatedImportantState
Definition NetworkPhysicsComponent.h:1466
TSharedPtr< Chaos::FBaseRewindHistory > & GetInputHistory_External()
Definition NetworkPhysicsComponent.h:1367
FNetworkPhysicsRewindDataDeltaSourceInputProxy ReplicatedDeltaSourceInput
Definition NetworkPhysicsComponent.h:1429
const bool GetIsRelayingLocalInputs() const
Definition NetworkPhysicsComponent.h:1401
FNetworkPhysicsRewindDataImportantInputProxy ReplicatedImportantInput
Definition NetworkPhysicsComponent.h:1462
FNetworkPhysicsRewindDataDeltaSourceStateProxy ReplicatedDeltaSourceState
Definition NetworkPhysicsComponent.h:1433
void SetIsRelayingLocalInputs(bool bInRelayingLocalInputs)
Definition NetworkPhysicsComponent.h:1384
static const int32 DeltaSourceBufferSize
Definition NetworkPhysicsComponent.h:1585
TWeakObjectPtr< UActorComponent > ActorComponent
Definition NetworkPhysicsComponent.h:1668
void CreateInputHistory(UActorComponent *HistoryComponent)
Definition NetworkPhysicsComponent.h:1759
TSharedPtr< Chaos::FBaseRewindHistory > & GetStateHistory_External()
Definition NetworkPhysicsComponent.h:1361
FNetworkPhysicsRewindDataInputProxy ReplicatedInputs
Definition NetworkPhysicsComponent.h:1482
void StopRelayingLocalInputsDeferred()
Definition NetworkPhysicsComponent.h:1392
FNetworkPhysicsRewindDataStateProxy ReplicatedStates
Definition NetworkPhysicsComponent.h:1490
static const int32 GetDeltaSourceIndexForFrame(const int32 Frame)
Definition NetworkPhysicsComponent.h:1588
FNetworkPhysicsRewindDataRemoteInputProxy ReplicatedRemoteInputs
Definition NetworkPhysicsComponent.h:1486
void CreateDataHistory(UActorComponent *HistoryComponent)
Definition NetworkPhysicsComponent.h:1715
FAsyncNetworkPhysicsComponent * GetNetworkPhysicsComponent_Internal()
Definition NetworkPhysicsComponent.h:1411
Definition NetworkPhysicsComponent.h:723
UE_FORCEINLINE_HINT FString GetName() const
Definition UObjectBaseUtility.h:439
Definition CoreNet.h:191
int32 GetPhysicsHistoryCount() const
Definition PhysicsSettings.h:380
static UPhysicsSettings * Get()
Definition PhysicsSettings.h:377
Definition Class.h:1720
ICppStructOps * GetCppStructOps() const
Definition Class.h:2292
EStructFlags StructFlags
Definition Class.h:2224
Definition WorldSubsystem.h:16
Definition World.h:918
Definition SkeletalMeshComponent.h:307
Definition NetworkPhysicsComponent.cpp:2657
int32 GetUpcomingServerFrame_External(UWorld *World)
Definition NetworkPhysicsComponent.cpp:2658
@ false
Definition radaudio_common.h:23
U16 Index
Definition radfft.cpp:71
Definition RewindData.h:32
virtual void ResetFast()
Definition RewindData.h:158
virtual void ResizeDataHistory(const int32 FrameCount, const EAllowShrinking AllowShrinking=EAllowShrinking::Default)
Definition RewindData.h:155
Definition PhysicsObjectInternal.h:16
Definition SimCallbackInput.h:34
Definition SimCallbackInput.h:18
Definition RewindData.h:164
DataType & GetAndLoadEarliestData()
Definition RewindData.h:405
int32 NumFrames
Definition RewindData.h:547
virtual void Initialize()
Definition RewindData.h:179
TArray< DataType > DataHistory
Definition RewindData.h:535
int32 CurrentIndex
Definition RewindData.h:544
FORCEINLINE const uint32 GetFrameIndex(const int32 Frame) const
Definition RewindData.h:503
FORCEINLINE bool EvalData(const int32 EvalFrame)
Definition RewindData.h:317
virtual const int32 GetLatestFrame() const override
Definition RewindData.h:459
virtual FORCEINLINE bool RecordData(const int32 RecordFrame, const void *HistoryData) override
Definition RewindData.h:329
bool bIsLocalHistory
Definition RewindData.h:529
FORCEINLINE bool LoadData(const int32 LoadFrame)
Definition RewindData.h:308
virtual FORCEINLINE bool RecordDataGrowingOrdered(const void *HistoryData) override
Definition RewindData.h:347
FORCEINLINE uint32 NumValidData(const uint32 StartFrame, const uint32 EndFrame) const
Definition RewindData.h:441
Definition EngineBaseTypes.h:571
Definition NetworkPhysicsComponent.h:1794
TOptional< int32 > NetworkPhysicsTickOffset
Definition NetworkPhysicsComponent.h:1798
TOptional< Chaos::FConstPhysicsObjectHandle > PhysicsObject
Definition NetworkPhysicsComponent.h:1803
TOptional< bool > bCompareStateToTriggerRewindIncludeSimProxies
Definition NetworkPhysicsComponent.h:1810
void Reset()
Definition NetworkPhysicsComponent.h:1820
TOptional< uint16 > InputsToNetwork_Owner
Definition NetworkPhysicsComponent.h:1799
TOptional< bool > bRegisterDataHistoryInRewindData
Definition NetworkPhysicsComponent.h:1807
TOptional< TUniquePtr< FNetworkPhysicsDataHelper > > StateHelper
Definition NetworkPhysicsComponent.h:1806
TOptional< bool > bCompareInputToTriggerRewind
Definition NetworkPhysicsComponent.h:1811
TUniquePtr< Chaos::FBaseRewindHistory > InputData
Definition NetworkPhysicsComponent.h:1814
TUniquePtr< Chaos::FBaseRewindHistory > StateData
Definition NetworkPhysicsComponent.h:1815
TOptional< INetworkPhysicsInputState_Internal * > ImplementationInterface_Internal
Definition NetworkPhysicsComponent.h:1802
TOptional< EPhysicsReplicationMode > PhysicsReplicationMode
Definition NetworkPhysicsComponent.h:1800
TOptional< TWeakObjectPtr< UActorComponent > > ActorComponent
Definition NetworkPhysicsComponent.h:1801
TOptional< ENetMode > NetMode
Definition NetworkPhysicsComponent.h:1796
TOptional< TWeakPtr< const FNetworkPhysicsSettingsData > > SettingsComponent
Definition NetworkPhysicsComponent.h:1812
TOptional< FString > ActorName
Definition NetworkPhysicsComponent.h:1804
TOptional< TUniquePtr< FNetworkPhysicsDataHelper > > InputHelper
Definition NetworkPhysicsComponent.h:1805
TArray< TUniquePtr< Chaos::FBaseRewindHistory > > StateDataImportant
Definition NetworkPhysicsComponent.h:1818
TOptional< bool > bUnregisterDataHistoryFromRewindData
Definition NetworkPhysicsComponent.h:1808
TOptional< ENetRole > NetRole
Definition NetworkPhysicsComponent.h:1797
TArray< TUniquePtr< Chaos::FBaseRewindHistory > > InputDataImportant
Definition NetworkPhysicsComponent.h:1817
TOptional< bool > bIsLocallyControlled
Definition NetworkPhysicsComponent.h:1795
TOptional< bool > bCompareStateToTriggerRewind
Definition NetworkPhysicsComponent.h:1809
Definition NetworkPhysicsComponent.h:1859
TOptional< uint16 > InputsToNetwork_Owner
Definition NetworkPhysicsComponent.h:1860
TUniquePtr< Chaos::FBaseRewindHistory > InputData
Definition NetworkPhysicsComponent.h:1862
TArray< TUniquePtr< Chaos::FBaseRewindHistory > > StateDataImportant
Definition NetworkPhysicsComponent.h:1866
TUniquePtr< Chaos::FBaseRewindHistory > StateData
Definition NetworkPhysicsComponent.h:1863
TArray< TUniquePtr< Chaos::FBaseRewindHistory > > InputDataImportant
Definition NetworkPhysicsComponent.h:1865
void Reset()
Definition NetworkPhysicsComponent.h:1868
static constexpr UE_FORCEINLINE_HINT T Clamp(const T X, const T MinValue, const T MaxValue)
Definition UnrealMathUtility.h:592
Definition NetworkPhysicsComponent.h:680
FNetworkPhysicsCallback(UWorld *InWorld)
Definition NetworkPhysicsComponent.h:681
virtual void PreResimStep_Internal(int32 PhysicsStep, bool bFirst) override
Definition NetworkPhysicsComponent.cpp:317
virtual int32 TriggerRewindIfNeeded_Internal(int32 LatestStepCompleted) override
Definition NetworkPhysicsComponent.cpp:333
virtual void ProcessInputs_External(int32 PhysicsStep, const TArray< Chaos::FSimCallbackInputAndObject > &SimCallbackInputs)
Definition NetworkPhysicsComponent.cpp:372
TArray< Chaos::ISimCallbackObject * > RewindableCallbackObjects
Definition NetworkPhysicsComponent.h:714
FOnInjectInputsExternal InjectInputsExternal
Definition NetworkPhysicsComponent.h:688
FOnPreProcessInputsInternal PreProcessInputsInternal
Definition NetworkPhysicsComponent.h:685
virtual void UnregisterRewindableSimCallback_Internal(Chaos::ISimCallbackObject *SimCallbackObject) override
Definition NetworkPhysicsComponent.h:705
FOnPostProcessInputsInternal PostProcessInputsInternal
Definition NetworkPhysicsComponent.h:686
virtual void ProcessInputs_Internal(int32 PhysicsStep, const TArray< Chaos::FSimCallbackInputAndObject > &SimCallbackInputs) override
Definition NetworkPhysicsComponent.cpp:307
virtual void PostResimStep_Internal(int32 PhysicsStep) override
Definition NetworkPhysicsComponent.cpp:328
virtual void RegisterRewindableSimCallback_Internal(Chaos::ISimCallbackObject *SimCallbackObject) override
Definition NetworkPhysicsComponent.h:697
virtual void InjectInputs_External(int32 PhysicsStep, int32 NumSteps) override
Definition NetworkPhysicsComponent.cpp:367
UWorld * World
Definition NetworkPhysicsComponent.h:711
Definition NetworkPhysicsComponent.h:821
TArray< TInstancedStruct< FNetworkPhysicsPayload > > DataArray
Definition NetworkPhysicsComponent.h:825
void DebugCollection(const FString &DebugText) const
Definition NetworkPhysicsComponent.h:837
Definition NetworkPhysicsComponent.h:1119
virtual TUniquePtr< FNetworkPhysicsDataHelper > Clone() const =0
virtual void ValidateData(Chaos::FBaseRewindHistory *History, INetworkPhysicsInputState_Internal &Interface)=0
virtual void CopyData(const FNetworkPhysicsDataCollection &From, Chaos::FBaseRewindHistory *To)=0
virtual void CopyIncrementalData(const Chaos::FBaseRewindHistory *From, FNetworkPhysicsDataCollection &To)=0
virtual bool IsUsingLegacyData()=0
virtual ~FNetworkPhysicsDataHelper()=default
virtual void ValidateData(Chaos::FBaseRewindHistory *History, INetworkPhysicsInputState_External &Interface)=0
virtual TUniquePtr< Chaos::FBaseRewindHistory > CreateUniqueRewindHistory(const int32 Size) const =0
virtual void CopyDataGrowingOrdered(const FNetworkPhysicsDataCollection &From, Chaos::FBaseRewindHistory *To)=0
virtual TUniquePtr< FNetworkPhysicsPayload > CreateUniqueData() const =0
virtual bool CopyAlteredData(const Chaos::FBaseRewindHistory *From, FNetworkPhysicsDataCollection &To)=0
virtual void CopyData(const Chaos::FBaseRewindHistory *From, FNetworkPhysicsDataCollection &To)=0
Definition NetworkPhysicsComponent.h:954
virtual void ApplyData(UActorComponent *NetworkComponent) const
Definition NetworkPhysicsComponent.h:1062
FNetworkPhysicsData(const FNetworkPhysicsData &)=default
void SetImportant(bool bIsImportant)
Definition NetworkPhysicsComponent.h:1056
PRAGMA_DISABLE_DEPRECATION_WARNINGS FNetworkPhysicsData()=default
virtual void ValidateData(const UActorComponent *NetworkComponent)
Definition NetworkPhysicsComponent.h:1092
bool CompareData(const FNetworkPhysicsPayload &PredictedData) const override
Definition NetworkPhysicsComponent.h:1113
virtual const FString DebugData()
Definition NetworkPhysicsComponent.h:1102
void MergeData(const FNetworkPhysicsPayload &FromData) override
Definition NetworkPhysicsComponent.h:1112
void SerializeFrames(FArchive &Ar)
Definition NetworkPhysicsComponent.h:993
FNetworkPhysicsData(FNetworkPhysicsData &&)=default
virtual void BuildData(const UActorComponent *NetworkComponent)
Definition NetworkPhysicsComponent.h:1065
virtual bool CompareData(const FNetworkPhysicsData &PredictedData)
Definition NetworkPhysicsComponent.h:1099
virtual void DecayData(float DecayAmount) override
Definition NetworkPhysicsComponent.h:1079
virtual void MergeData(const FNetworkPhysicsData &FromData)
Definition NetworkPhysicsComponent.h:1086
void SetDeltaSourceData(FNetworkPhysicsData *IntDeltaSourceData)
Definition NetworkPhysicsComponent.h:986
FNetworkPhysicsData & operator=(FNetworkPhysicsData &&)=default
FNetworkPhysicsData & operator=(const FNetworkPhysicsData &)=default
void SetImplementationComponent(UActorComponent *InImplementationComponent)
Definition NetworkPhysicsComponent.h:977
virtual void InterpolateData(const FNetworkPhysicsData &MinData, const FNetworkPhysicsData &MaxData)
Definition NetworkPhysicsComponent.h:1072
bool operator==(const FNetworkPhysicsData &Other) const
Definition NetworkPhysicsComponent.h:1104
virtual ~FNetworkPhysicsData()=default
void ClearImplementationComponent()
Definition NetworkPhysicsComponent.h:981
void ClearDeltaSourceData()
Definition NetworkPhysicsComponent.h:990
Definition NetworkPhysicsComponent.h:744
virtual const FString DebugData()
Definition NetworkPhysicsComponent.h:784
virtual void DecayData(float DecayAmount)
Definition NetworkPhysicsComponent.h:774
virtual bool CompareData(const FNetworkPhysicsPayload &PredictedData) const
Definition NetworkPhysicsComponent.h:781
int32 ServerFrame
Definition NetworkPhysicsComponent.h:750
virtual const FString DebugData() const
Definition NetworkPhysicsComponent.h:785
virtual void MergeData(const FNetworkPhysicsPayload &FromData)
Definition NetworkPhysicsComponent.h:767
void PrepareFrame(int32 CurrentFrame, bool bIsServer, int32 ClientFrameOffset)
Definition NetworkPhysicsComponent.h:796
virtual void InterpolateData(const FNetworkPhysicsPayload &MinData, const FNetworkPhysicsPayload &MaxData, float LerpAlpha)
Definition NetworkPhysicsComponent.h:760
Definition NetworkPhysicsComponent.h:659
Definition NetworkPhysicsComponent.h:638
Definition NetworkPhysicsComponent.h:595
Definition NetworkPhysicsComponent.h:616
Definition NetworkPhysicsComponent.h:533
Definition NetworkPhysicsComponent.h:502
TUniquePtr< Chaos::FBaseRewindHistory > History
Definition NetworkPhysicsComponent.h:518
bool NetSerializeBase(FArchive &Ar, class UPackageMap *Map, bool &bOutSuccess, TUniqueFunction< TUniquePtr< Chaos::FBaseRewindHistory >()> CreateHistoryFunction)
Definition NetworkPhysicsComponent.h:512
bool operator==(const FNetworkPhysicsRewindDataProxy &Other) const
Definition NetworkPhysicsComponent.h:508
TObjectPtr< UNetworkPhysicsComponent > Owner
Definition NetworkPhysicsComponent.h:522
Definition NetworkPhysicsComponent.h:554
Definition NetworkPhysicsComponent.h:575
Definition NetworkPhysicsSettingsComponent.h:473
Definition WorldInitializationValues.h:9
Definition InstancedStruct.h:307
static TInstancedStruct Make()
Definition InstancedStruct.h:379
Definition NetworkPhysicsComponent.h:32
virtual void NetSerialize(FArchive &Ar, UPackageMap *InPackageMap) override
Definition NetworkPhysicsComponent.h:346
virtual void SetImportant(const bool bImportant, const int32 Frame=INDEX_NONE) override
Definition NetworkPhysicsComponent.h:111
virtual TUniquePtr< Chaos::FBaseRewindHistory > CopyFramesWithOffset(const uint32 StartFrame, const uint32 EndFrame, const int32 FrameOffset) override
Definition NetworkPhysicsComponent.h:214
virtual void ValidateDataInHistory(const void *ActorComponent) override
Definition NetworkPhysicsComponent.h:59
virtual void ApplyDataRange(const int32 FromFrame, const int32 ToFrame, void *ActorComponent, const bool bOnlyImportant=false) override
Definition NetworkPhysicsComponent.h:132
TNetRewindHistory(const int32 FrameCount, const bool bIsHistoryLocal)
Definition NetworkPhysicsComponent.h:35
virtual TUniquePtr< Chaos::FBaseRewindHistory > Clone() const
Definition NetworkPhysicsComponent.h:54
TNetRewindHistory(const int32 FrameCount)
Definition NetworkPhysicsComponent.h:40
virtual TUniquePtr< Chaos::FBaseRewindHistory > CreateNew() const
Definition NetworkPhysicsComponent.h:47
virtual bool ShouldRecordReceivedDataOnFrame(const DataType &ReceivedData, DataType *NextReceivedData=nullptr)
Definition NetworkPhysicsComponent.h:293
virtual bool CopyAlteredData(Chaos::FBaseRewindHistory &OutHistory, bool bIncludeUnimportant=true, bool bIncludeImportant=false) override
Definition NetworkPhysicsComponent.h:170
virtual int32 CountValidData(const uint32 StartFrame, const uint32 EndFrame, const bool bIncludeUnimportant=true, const bool bIncludeImportant=false) override
Definition NetworkPhysicsComponent.h:72
virtual void NetSerialize(FArchive &Ar, UPackageMap *InPackageMap, TUniqueFunction< void(void *Data, const int32 DataIndex)> DataSetupFunction) override
Definition NetworkPhysicsComponent.h:351
virtual ~TNetRewindHistory()
Definition NetworkPhysicsComponent.h:45
virtual void DebugData(const FString &DebugText) override
Definition NetworkPhysicsComponent.h:437
virtual bool CopyAllData(Chaos::FBaseRewindHistory &OutHistory, bool bIncludeUnimportant=true, bool bIncludeImportant=false) override
Definition NetworkPhysicsComponent.h:150
virtual bool TriggerRewindFromNewData(DataType &NewData)
Definition NetworkPhysicsComponent.h:335
virtual bool CopyData(Chaos::FBaseRewindHistory &OutHistory, const uint32 StartFrame, const uint32 EndFrame, bool bIncludeUnimportant=true, bool bIncludeImportant=false) override
Definition NetworkPhysicsComponent.h:190
virtual int32 ReceiveNewData(Chaos::FBaseRewindHistory &NewData, const int32 FrameOffset, bool CompareDataForRewind=false, const bool bImportant=false, int32 TryInjectAtFrame=INDEX_NONE) override
Definition NetworkPhysicsComponent.h:235
virtual int32 CountAlteredData(const bool bIncludeUnimportant=true, const bool bIncludeImportant=false) override
Definition NetworkPhysicsComponent.h:94
virtual void DebugData(const Chaos::FBaseRewindHistory &DebugHistory, TArray< int32 > &LocalFrames, TArray< int32 > &ServerFrames, TArray< int32 > &InputFrames) override
Definition NetworkPhysicsComponent.h:415
Definition NetworkPhysicsComponent.h:1156
void ValidateData(Chaos::FBaseRewindHistory *History, INetworkPhysicsInputState_External &Interface) override
Definition NetworkPhysicsComponent.h:1260
void CopyDataGrowingOrdered(const FNetworkPhysicsDataCollection &From, Chaos::FBaseRewindHistory *To) override
Definition NetworkPhysicsComponent.h:1249
void ValidateData(Chaos::FBaseRewindHistory *History, INetworkPhysicsInputState_Internal &Interface) override
Definition NetworkPhysicsComponent.h:1277
void CopyData(const FNetworkPhysicsDataCollection &From, Chaos::FBaseRewindHistory *To) override
Definition NetworkPhysicsComponent.h:1164
TUniquePtr< Chaos::FBaseRewindHistory > CreateUniqueRewindHistory(const int32 Size) const override
Definition NetworkPhysicsComponent.h:1160
~TNetworkPhysicsDataHelper()=default
TUniquePtr< FNetworkPhysicsPayload > CreateUniqueData() const override
Definition NetworkPhysicsComponent.h:1159
bool CopyAlteredData(const Chaos::FBaseRewindHistory *From, FNetworkPhysicsDataCollection &To) override
Definition NetworkPhysicsComponent.h:1221
bool IsUsingLegacyData()
Definition NetworkPhysicsComponent.h:1161
void CopyIncrementalData(const Chaos::FBaseRewindHistory *From, FNetworkPhysicsDataCollection &To) override
Definition NetworkPhysicsComponent.h:1196
void CopyData(const Chaos::FBaseRewindHistory *From, FNetworkPhysicsDataCollection &To) override
Definition NetworkPhysicsComponent.h:1179
TUniquePtr< FNetworkPhysicsDataHelper > Clone() const override
Definition NetworkPhysicsComponent.h:1158
Definition ObjectPtr.h:488
Definition Optional.h:131
void Reset()
Definition Optional.h:306
Definition StructOpsTypeTraits.h:11
@ WithIdenticalViaEquality
Definition StructOpsTypeTraits.h:18
@ WithNetSerializer
Definition StructOpsTypeTraits.h:26
Definition StructOpsTypeTraits.h:46
Definition WeakObjectPtrTemplates.h:25
bool NetSerialize(FArchive &Ar, UPackageMap *Map, bool &bOutSuccess, void *Data)
Definition Class.h:1861