UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
EscalationStates.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5
6#include "Containers/Array.h"
10#include "CoreMinimal.h"
11#include "Math/UnrealMathSSE.h"
14#include "Templates/EnableIf.h"
15#include "Templates/Function.h"
16#include "Templates/IsEnum.h"
17#include "Templates/Models.h"
20#include "UObject/Class.h"
21#include "UObject/Object.h"
25
26#include "EscalationStates.generated.h"
27
28class UObject;
29
30
101// Defines
102
104#define ESCALATION_QUOTA_DEBUG 0
105
106
107// Forward declarations
109
110namespace UE
111{
112 namespace Net
113 {
114 class FEscalationManager;
115 struct FEscalationCounter;
116 }
117}
118
119
123enum class EQuotaType : uint8
124{
125 EscalateQuota, // Check quota for escalating to a higher state
126 DeescalateQuota // Check quota for de-escalating to a lower state
127};
128
151
152
157USTRUCT()
159{
162
164
165
168 {
169 Optional,
170 MustBeSet
171 };
172
173
174public:
176 UPROPERTY(config)
177 bool bLogEscalate = false;
178
180 UPROPERTY(config)
181 bool bDormant = false;
182
184 UPROPERTY(config)
185 int16 CooloffTime = -1;
186
188 UPROPERTY(config)
189 int16 AutoEscalateTime = -1;
190
191
196 UPROPERTY()
197 int8 HighestTimePeriod = 0;
198
200 UPROPERTY()
201 TArray<int8> AllTimePeriods;
202
203
204public:
208 NETCORE_API bool IsDormant() const;
209
215 NETCORE_API int8 GetHighestTimePeriod() const;
216
222 NETCORE_API const TArray<int8>& GetAllTimePeriods() const;
223
224
226 NETCORE_API virtual void ValidateConfigInternal() override;
227
235 NETCORE_API void ValidateTimePeriod(int8& Value, const TCHAR* PropertyName, EValidateTime Requirement=EValidateTime::Optional);
236
237
238private:
248 virtual bool HasHitAnyQuota(FHasHitAnyQuotaParms Parms) const
249 {
250 return false;
251 }
252};
253
257template<class T>
259{
263 static inline const TCHAR* GetConfigSection()
264 {
265 return T::GetConfigSection();
266 }
267
271 static inline UClass* GetBaseConfigClass()
272 {
273 return T::GetBaseConfigClass();
274 }
275};
276
277
278namespace UE
279{
280namespace Net
281{
282// Forward declarations
283enum class ESeverityUpdate : uint8;
284
285
286// Typedefs
287
295using FNotifySeverityUpdate = TUniqueFunction<void(const FEscalationState& OldState, const FEscalationState& NewState, ESeverityUpdate UpdateType)>;
296
297
302{
305
307 double AccumTime = 0.0;
308
309#if ESCALATION_QUOTA_DEBUG
311 double DebugAccumTime = 0.0;
312#endif
313
314
315public:
320 {
321 Counter = 0;
322 AccumTime = 0.0;
323
324#if ESCALATION_QUOTA_DEBUG
325 DebugAccumTime = 0.0;
326#endif
327 }
328
335 {
336 Counter += InCounter.Counter;
337 AccumTime += InCounter.AccumTime;
338
339#if ESCALATION_QUOTA_DEBUG
340 DebugAccumTime += InCounter.DebugAccumTime;
341#endif
342 }
343};
344
349{
350 Escalate, // Escalating to a higher escalation state
351 AutoEscalate, // Automatic/non-quota escalation to a higher escalation state, e.g. when too much time was spent in a lower state
352 Deescalate // Deescalating to a lower escalation state
353};
354
359{
360 QuotaLimit, // Escalation quota's were hit (followed by additional ReasonContext)
361 AutoEscalate, // Automatic escalation from a lower state, e.g. after spending too much time in a lower state
362 Deescalate // Deescalation to a lower state
363};
364
369{
370 Escalated, // Escalated to a higher/more-severe state
371 Deescalated, // De-escalated to a lower/less-severe state
372 NoChange // No state change occurred
373};
374
375
380{
381 template<typename, typename, typename> friend class TEscalationManager;
383
384private:
388 template<typename T, typename = decltype(TBaseStructure<T>::Get())>
389 class TStructOnScopeLite final : public FStructOnScope
390 {
391 public:
392 TStructOnScopeLite(const UStruct* InScriptStruct, uint8* Data)
394 {
396 }
397
398 T* Get() const
399 {
400 return reinterpret_cast<T*>(SampleStructMemory);
401 }
402
403 T* operator->() const
404 {
405 return Get();
406 }
407
408 explicit operator bool() const
409 {
410 return IsValid();
411 }
412
413 template<typename U>
414 U* Cast()
415 {
417 {
418 return reinterpret_cast<U*>(SampleStructMemory);
419 }
420 return nullptr;
421 }
422
423 template<typename U>
424 const U* Cast() const
425 {
426 return const_cast<TStructOnScopeLite*>(this)->Cast<U>();
427 }
428 };
429
430
431 struct FEscalationManagerParms
432 {
433 int32 NumCounters = 0;
434 const TArrayView<TArrayView<int32>> RegisteredCountersCache = {};
435 const UStruct* StateStruct = nullptr;
436 uint8* StateMemory = nullptr;
437 };
438
439 struct FEscalationManagerInitParms
440 {
441 const TArrayView<FEscalationCounter> FrameCounters = {};
442 const TArrayView<FEscalationCounter> SecondCounters = {};
443 const TArrayView<FEscalationCounter> CountersPerPeriodHistoryAlloc = {};
444 };
445
446
447private:
448 NETCORE_API FEscalationManager(FEscalationManagerParms Parms);
449
450 NETCORE_API void InitParms(FEscalationManagerInitParms Parms);
451
452 FEscalationManager() = delete;
453
459 NETCORE_API void InitConfig(FStateConfigParms ConfigParms);
460
470
480
481 NETCORE_API int32 GetHighestHistoryRequirement() const;
482
486 NETCORE_API void ResetAllCounters();
487
488 NETCORE_API int32 AddNewCounter_Internal(int32 Count, const TArrayView<FEscalationCounter>& CountersPerPeriodAlloc);
489
490public:
498 {
499 check(CounterIndex < NumCounters);
500
501 return FrameCounters[CounterIndex];
502 }
503
508
515 NETCORE_API void TickRealtime(double TimeSeconds);
516
522 bool DoesRequireTick() const
523 {
524 return !IsDormant();
525 }
526
527
528 // Accessors
529
533 NETCORE_API bool IsDormant() const;
534
539
544
549
550
551private:
553 const UEscalationManagerConfig* BaseConfig = nullptr;
554
556 FString ManagerContext;
557
559 FNotifySeverityUpdate NotifySeverityUpdate;
560
562 int32 NumCounters = 0;
563
565 bool bEnabled = false;
566
567
569 TStructOnScopeLite<FEscalationState> State;
570
572 int8 ActiveState = 0;
573
575 double LastMetEscalationConditions = 0.0;
576
577
579 TArrayView<FEscalationCounter> FrameCounters;
580
582 TArrayView<FEscalationCounter> SecondCounters;
583
585 double LastPerSecQuotaBegin = 0.0;
586
588 TArray<TArrayView<FEscalationCounter>> CountersPerSecHistory;
589
591 TArray<FEscalationCounter> CountersPerSecHistoryAlloc;
592
594 int32 LastCountersPerSecHistoryIdx = 0;
595
597 TArrayView<FEscalationCounter> CountersPerPeriodHistory[16] = {};
598
599
601 const TArrayView<TArrayView<int32>> RegisteredCounters;
602};
603
609
610
617template<typename CountersEnum, typename EscalationStateType, typename CounterCategoriesEnum=EEmptyCategories>
619{
620 static_assert(TIsEnum<CountersEnum>::Value, "CountersEnum must be an enum");
621 static_assert(TIsEnum<CounterCategoriesEnum>::Value, "CounterCategoriesEnum must be an enum");
622 static_assert(TIsDerivedFrom<EscalationStateType, FEscalationState>::Value, "EscalationStateType must be a subclass of FEscalationState");
623
624
625 struct CHasEnumPreallocNum
626 {
627 template<typename T>
628 auto Requires() -> decltype(
629 T::NumPrealloc
630 );
631 };
632
633 // 'typename = typename TEnableIf' does not work here, unusually
634 template<typename T, typename TEnableIf<TModels_V<CHasEnumPreallocNum, T>>::Type* = nullptr>
635 inline static constexpr int32 GetCounterNumPrealloc()
636 {
637 return FMath::Max((int32)T::NumPrealloc, (int32)T::Max);
638 }
639
640 template<typename T, typename TEnableIf<!TModels_V<CHasEnumPreallocNum, T>>::Type* = nullptr>
641 inline static constexpr int32 GetCounterNumPrealloc()
642 {
643 return (int32)T::Max;
644 }
645
647 static constexpr int32 TNum = (int32)CountersEnum::Max;
648
650 static constexpr int32 TNumPrealloc = GetCounterNumPrealloc<CountersEnum>();
651
653 static constexpr int32 TNumCategories = (int32)CounterCategoriesEnum::Max;
654
655
656public:
662 FEscalationManagerParms
663 {
664 TNum, MakeArrayView(RegisteredCountersCacheAlloc, TNumCategories),
665 EscalationStateType::StaticStruct(), (uint8*)&StateAlloc //-V1050
666 })
667 {
668 static_assert(UE_ARRAY_COUNT(CountersPerPeriodHistory) == 16,
669 "CountersPerPeriodAlloc initialization must match CountersPerPeriodHistory length");
670
671 FrameCountersAlloc.SetNum(TNumPrealloc);
672 SecondCountersAlloc.SetNum(TNumPrealloc);
673 CountersPerPeriodAlloc.SetNum(TNumPrealloc * UE_ARRAY_COUNT(CountersPerPeriodHistory));
674
675 InitParms(
676 FEscalationManagerInitParms
677 {
678 MakeArrayView(FrameCountersAlloc.GetData(), TNum), MakeArrayView(SecondCountersAlloc.GetData(), TNum),
679 MakeArrayView(CountersPerPeriodAlloc.GetData(), TNum * UE_ARRAY_COUNT(CountersPerPeriodHistory))
680 });
681 }
682
688 void Init(FString ConfigContext)
689 {
690 FEscalationManager::InitConfig({TEscalationStateStatics<EscalationStateType>::GetConfigSection(), ConfigContext,
692 EscalationStateType::StaticStruct()
693 });
694 }
695
704 {
705 FrameCountersAlloc.AddDefaulted(Count);
706 SecondCountersAlloc.AddDefaulted(Count);
707 CountersPerPeriodAlloc.AddDefaulted(Count * UE_ARRAY_COUNT(CountersPerPeriodHistory));
708
709 FrameCounters = MakeArrayView(FrameCountersAlloc);
710 SecondCounters = MakeArrayView(SecondCountersAlloc);
711
712 return AddNewCounter_Internal(Count, MakeArrayView(CountersPerPeriodAlloc));
713 }
714
722 void RegisterCounterCategory(int32 CategoryIndex, int32 CounterIndex)
723 {
724 check(CategoryIndex < UE_ARRAY_COUNT(RegisteredCountersAlloc));
725 check(CounterIndex >= 0);
726
727 TArray<int32, TInlineAllocator<TNumPrealloc>>& CurRegisteredCounters = RegisteredCountersAlloc[CategoryIndex];
728
729 CurRegisteredCounters.AddUnique(CounterIndex);
730 RegisteredCounters[CategoryIndex] = MakeArrayView(CurRegisteredCounters);
731 }
732
733private:
736 EscalationStateType StateAlloc;
737
740 TArray<FEscalationCounter, TInlineAllocator<TNumPrealloc * UE_ARRAY_COUNT(CountersPerPeriodHistory)>> CountersPerPeriodAlloc;
741 TArray<int32, TInlineAllocator<TNumPrealloc>> RegisteredCountersAlloc[FMath::Max(TNumCategories, 1)];
742 TArrayView<int32> RegisteredCountersCacheAlloc[FMath::Max(TNumCategories, 1)];
743};
744
745}
746}
747
748
754UCLASS(config=Engine, PerObjectConfig, MinimalAPI)
756{
758
759private:
760 NETCORE_API virtual void LoadStateConfig() override;
761
762
763public:
765 UPROPERTY(config)
766 TArray<FString> EscalationSeverity;
767
769 TArray<TStructOnScope<FEscalationState>> EscalationSeverityState;
770};
771
772
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
constexpr auto MakeArrayView(OtherRangeType &&Other)
Definition ArrayView.h:873
#define check(expr)
Definition AssertionMacros.h:314
@ INDEX_NONE
Definition CoreMiscDefines.h:150
FPlatformTypes::int16 int16
A 16-bit signed integer.
Definition Platform.h:1123
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
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
TCopyQualifiersFromTo_T< From, To > * Cast(From *Src)
Definition Casts.h:95
EQuotaType
Definition EscalationStates.h:124
const bool
Definition NetworkReplayStreaming.h:178
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UCLASS(...)
Definition ObjectMacros.h:776
#define USTRUCT(...)
Definition ObjectMacros.h:746
#define UE_ARRAY_COUNT(array)
Definition UnrealTemplate.h:212
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Engine.Build.cs:7
Definition StructOnScope.h:13
virtual const UStruct * GetStruct() const
Definition StructOnScope.h:72
uint8 * SampleStructMemory
Definition StructOnScope.h:16
virtual bool IsValid() const
Definition StructOnScope.h:85
Definition ArrayView.h:139
Definition Array.h:670
Definition ContainerAllocationPolicies.h:894
Definition StructOnScope.h:142
Definition Class.h:3793
Definition EscalationStates.h:380
NETCORE_API void SetNotifySeverityUpdate(FNotifySeverityUpdate &&InNotifySeverityUpdate)
Definition EscalationStates.cpp:526
NETCORE_API void SetManagerContext(FString InManagerContext)
Definition EscalationStates.cpp:521
NETCORE_API bool IsDormant() const
Definition EscalationStates.cpp:511
NETCORE_API void CheckQuotas()
Definition EscalationStates.cpp:502
NETCORE_API void TickRealtime(double TimeSeconds)
Definition EscalationStates.cpp:306
bool DoesRequireTick() const
Definition EscalationStates.h:522
FEscalationCounter & GetFrameCounter(int32 CounterIndex)
Definition EscalationStates.h:497
NETCORE_API const UEscalationManagerConfig * GetBaseConfig() const
Definition EscalationStates.cpp:516
Definition EscalationStates.h:619
void RegisterCounterCategory(int32 CategoryIndex, int32 CounterIndex)
Definition EscalationStates.h:722
void Init(FString ConfigContext)
Definition EscalationStates.h:688
int32 AddNewCounter(int32 Count=1)
Definition EscalationStates.h:703
TEscalationManager()
Definition EscalationStates.h:660
Definition EscalationStates.h:756
Definition Object.h:95
Definition StateStruct.h:205
Definition Class.h:480
EEscalateResult
Definition EscalationStates.h:369
ESeverityUpdate
Definition EscalationStates.h:349
EEmptyCategories
Definition EscalationStates.h:606
@ Max
Definition EscalationStates.h:607
EEscalateReason
Definition EscalationStates.h:359
Definition AdvancedWidgetsModule.cpp:13
@ false
Definition radaudio_common.h:23
Definition EscalationStates.h:159
EValidateTime
Definition EscalationStates.h:168
friend UEscalationManagerConfig
Definition EscalationStates.h:161
Definition EscalationStates.h:133
const TArrayView< FEscalationCounter > & SecondCounters
Definition EscalationStates.h:143
const TArrayView< TArrayView< int32 > > & RegisteredCounters
Definition EscalationStates.h:137
EQuotaType QuotaType
Definition EscalationStates.h:149
const TArrayView< FEscalationCounter > & FrameCounters
Definition EscalationStates.h:146
Definition StateStruct.h:108
Definition StateStruct.h:128
Definition Class.h:5288
Definition EscalationStates.h:259
static UClass * GetBaseConfigClass()
Definition EscalationStates.h:271
static const TCHAR * GetConfigSection()
Definition EscalationStates.h:263
Definition UnrealTypeTraits.h:40
Definition IsEnum.h:7
Definition EscalationStates.h:302
void AccumulateCounter(const FEscalationCounter &InCounter)
Definition EscalationStates.h:334
double AccumTime
Definition EscalationStates.h:307
int32 Counter
Definition EscalationStates.h:304
void ResetCounters()
Definition EscalationStates.h:319