Update directive utilities plugin
This commit is contained in:
@@ -1,12 +1,70 @@
|
||||
#pragma once
|
||||
// Copyright (c) 2026 Unreal Directive. Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Interface.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "GameFramework/SaveGame.h"
|
||||
#include "Engine/HitResult.h"
|
||||
#include "Tasks/DirectiveUtilTask_MoveToLocation.h"
|
||||
#include "DirectiveUtilTestObject.generated.h"
|
||||
|
||||
class UWorld;
|
||||
class UGameInstance;
|
||||
|
||||
UINTERFACE()
|
||||
class UDirectiveUtilTestInterface : public UInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
};
|
||||
|
||||
class IDirectiveUtilTestInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FDirectiveUtilCollisionValue
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
int32 Value = 0;
|
||||
|
||||
bool operator==(const FDirectiveUtilCollisionValue& Other) const
|
||||
{
|
||||
return Value == Other.Value;
|
||||
}
|
||||
|
||||
friend uint32 GetTypeHash(const FDirectiveUtilCollisionValue&)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct TStructOpsTypeTraits<FDirectiveUtilCollisionValue> : TStructOpsTypeTraitsBase2<FDirectiveUtilCollisionValue>
|
||||
{
|
||||
enum
|
||||
{
|
||||
WithIdenticalViaEquality = true
|
||||
};
|
||||
};
|
||||
|
||||
USTRUCT()
|
||||
struct FDirectiveUtilPodValue
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY()
|
||||
int32 Index;
|
||||
|
||||
UPROPERTY()
|
||||
float Weight;
|
||||
};
|
||||
|
||||
static_assert(TIsPODType<FDirectiveUtilPodValue>::Value);
|
||||
|
||||
UCLASS()
|
||||
class UDirectiveUtilTestObject : public UObject
|
||||
@@ -17,6 +75,66 @@ public:
|
||||
UPROPERTY()
|
||||
TArray<int32> TestArray;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
TArray<FString> TestStringArray;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<FName> TestNameArray;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<FText> TestTextArray;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
TArray<bool> TestBoolArray;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
TArray<FDirectiveUtilCollisionValue> TestCollisionArray;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<FDirectiveUtilPodValue> TestPodArray;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
TArray<TObjectPtr<UObject>> TestObjectArray;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
TArray<bool> TestBoolSourceArray;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
TArray<FString> TestStringSourceArray;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
TArray<FDirectiveUtilCollisionValue> TestCollisionSourceArray;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
TArray<TObjectPtr<UObject>> TestObjectSourceArray;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
TArray<int32> TestIndices;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
bool TestBoolItem = false;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
FString TestStringItem;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
FDirectiveUtilCollisionValue TestCollisionItem;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
TObjectPtr<UObject> TestObjectItem;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
bool TestInsertResult = false;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
int32 TestRemovedCount = 0;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Directive Utilities|Tests")
|
||||
bool TestRemoveAllResult = false;
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void RunArrayThunkScenario();
|
||||
|
||||
UPROPERTY()
|
||||
TMap<int32, int32> TestMap;
|
||||
|
||||
@@ -25,9 +143,17 @@ public:
|
||||
|
||||
UPROPERTY()
|
||||
TMap<FString, int32> TestStringKeyMap;
|
||||
|
||||
UPROPERTY()
|
||||
TMap<FString, FString> TestStringMap;
|
||||
|
||||
UPROPERTY()
|
||||
TMap<FString, FString> TestStringMap2;
|
||||
|
||||
UPROPERTY()
|
||||
TMap<FName, FDirectiveUtilCollisionValue> TestStructValueMap;
|
||||
};
|
||||
|
||||
/** Concrete save-game subclass for tests (USaveGame itself is abstract and cannot be instantiated). */
|
||||
UCLASS()
|
||||
class UDirectiveUtilTestSaveGame : public USaveGame
|
||||
{
|
||||
@@ -38,11 +164,6 @@ public:
|
||||
int32 TestValue = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Listener for exercising the async-task dynamic multicast delegates from automation tests.
|
||||
* Dynamic delegates can only bind to UFUNCTIONs, so the handlers live on a UObject. The
|
||||
* Keepalive property lets a rooted listener keep the async task itself alive across frames.
|
||||
*/
|
||||
UCLASS()
|
||||
class UDirectiveUtilDelegateListener : public UObject
|
||||
{
|
||||
@@ -58,58 +179,139 @@ public:
|
||||
UPROPERTY()
|
||||
int32 CompletedCount = 0;
|
||||
|
||||
/** Number of hits reported by the most recent trace completion. */
|
||||
UPROPERTY()
|
||||
int32 HitCount = 0;
|
||||
|
||||
/** Success flag from the most recent bool-payload completion (e.g. move-to-location). */
|
||||
UPROPERTY()
|
||||
int32 UpdatedCount = 0;
|
||||
|
||||
UPROPERTY()
|
||||
int32 IterationCount = 0;
|
||||
|
||||
UPROPERTY()
|
||||
float LastElapsedTime = 0.0f;
|
||||
|
||||
UPROPERTY()
|
||||
float LastDeltaTime = 0.0f;
|
||||
|
||||
UPROPERTY()
|
||||
float LastAlpha = 0.0f;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<int32> IterationIndices;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<int32> IterationRemaining;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<float> UpdateElapsedTimes;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<float> UpdateDeltaTimes;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<float> UpdateAlphas;
|
||||
|
||||
UPROPERTY()
|
||||
bool bLastSuccess = false;
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<UObject> LastObject = nullptr;
|
||||
|
||||
/** The object array from the most recent batch completion (e.g. async load assets). */
|
||||
UPROPERTY()
|
||||
TArray<TObjectPtr<UObject>> LastObjects;
|
||||
|
||||
/** Holds a strong reference to the async task so it survives GC while the test waits. */
|
||||
UPROPERTY()
|
||||
TObjectPtr<UObject> Keepalive = nullptr;
|
||||
|
||||
/** The transient world a latent delay scenario ticks and tears down when it settles. */
|
||||
UPROPERTY()
|
||||
TObjectPtr<UWorld> ScenarioWorld = nullptr;
|
||||
|
||||
/** Handler for parameterless completion delegates (e.g. the cancellable delay). */
|
||||
UPROPERTY()
|
||||
TObjectPtr<UGameInstance> ScenarioGameInstance = nullptr;
|
||||
|
||||
UFUNCTION()
|
||||
void OnCompleted() { bCompleted = true; ++CompletedCount; }
|
||||
|
||||
/** Handler for object-payload completion delegates (e.g. async load asset). */
|
||||
UFUNCTION()
|
||||
void OnObjectCompleted(UObject* Object) { bCompleted = true; ++CompletedCount; LastObject = Object; }
|
||||
|
||||
/** Handler for object-payload failure delegates. */
|
||||
UFUNCTION()
|
||||
void OnObjectFailed(UObject* Object) { bFailed = true; }
|
||||
|
||||
/** Handler for object-array-payload completion delegates (e.g. async load assets). */
|
||||
UFUNCTION()
|
||||
void OnObjectsCompleted(const TArray<UObject*>& Objects) { bCompleted = true; ++CompletedCount; LastObjects.Reset(); LastObjects.Append(Objects); }
|
||||
|
||||
/** Handler for class-payload completion delegates (e.g. async load class). */
|
||||
UFUNCTION()
|
||||
void OnClassCompleted(UClass* Class) { bCompleted = true; ++CompletedCount; LastObject = Class; }
|
||||
|
||||
/** Handler for class-payload failure delegates. */
|
||||
UFUNCTION()
|
||||
void OnClassFailed(UClass* Class) { bFailed = true; }
|
||||
|
||||
/** Handler for trace completion delegates. */
|
||||
UFUNCTION()
|
||||
void OnTraceCompleted(const TArray<FHitResult>& Hits) { bCompleted = true; ++CompletedCount; HitCount = Hits.Num(); }
|
||||
|
||||
/** Handler for bool-payload completion delegates (e.g. move-to-location). */
|
||||
UFUNCTION()
|
||||
void OnBoolCompleted(bool bSuccess) { bCompleted = true; ++CompletedCount; bLastSuccess = bSuccess; }
|
||||
};
|
||||
|
||||
UFUNCTION()
|
||||
void OnDurationUpdated(float ElapsedTime, float DeltaTime, float Alpha) { ++UpdatedCount; LastElapsedTime = ElapsedTime; LastDeltaTime = DeltaTime; LastAlpha = Alpha; UpdateElapsedTimes.Add(ElapsedTime); UpdateDeltaTimes.Add(DeltaTime); UpdateAlphas.Add(Alpha); }
|
||||
|
||||
UFUNCTION()
|
||||
void OnRepeatIteration(int32 Index, int32 Remaining) { ++IterationCount; IterationIndices.Add(Index); IterationRemaining.Add(Remaining); }
|
||||
|
||||
};
|
||||
|
||||
UCLASS()
|
||||
class UDirectiveUtilTestMoveToLocationTask : public UDirectiveUtilTask_MoveToLocation
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
void Configure(AController* InController, const FVector InDestination, const bool bInCheckStuckMovement)
|
||||
{
|
||||
Controller = InController;
|
||||
Destination = InDestination;
|
||||
bCheckStuckMovement = bInCheckStuckMovement;
|
||||
}
|
||||
|
||||
void ClearController()
|
||||
{
|
||||
Controller = nullptr;
|
||||
}
|
||||
|
||||
void Complete()
|
||||
{
|
||||
ExecuteCompleted(false);
|
||||
}
|
||||
|
||||
void RegisterTimersForTest(UWorld* World);
|
||||
bool HasRegisteredTimers() const;
|
||||
};
|
||||
|
||||
UCLASS()
|
||||
class UDirectiveUtilTestMoveToActorTask : public UDirectiveUtilTask_MoveToActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
void Configure(AController* InController, AActor* InGoal, const bool bInCheckStuckMovement)
|
||||
{
|
||||
Controller = InController;
|
||||
Goal = InGoal;
|
||||
bCheckStuckMovement = bInCheckStuckMovement;
|
||||
}
|
||||
|
||||
void ClearController()
|
||||
{
|
||||
Controller = nullptr;
|
||||
}
|
||||
|
||||
void Complete()
|
||||
{
|
||||
ExecuteCompleted(false);
|
||||
}
|
||||
|
||||
void RegisterTimersForTest(UWorld* World);
|
||||
bool HasRegisteredTimers() const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user