You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
- Removed gated delay (transition will be delayed until it has been "pressed" for N seconds) - Delay now triggers after the delay duration has passed (single trigger, not "pressed", works with events too) - Added random variation for the delay - Tick/Event transitions has precedence over completion transitions (that is, they are handled before completion transitions) - Removed delay and blocking from completion transitions - Small improvements for transitions UI #rb Mieszko.Zielinski #preflight 6389e0b435192facc1b95cdb [CL 23371519 by mikko mononen in ue5-main branch]
233 lines
6.7 KiB
C++
233 lines
6.7 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "Engine/DataAsset.h"
|
|
#include "StateTreeTypes.h"
|
|
#include "StateTreeSchema.h"
|
|
#include "InstancedStruct.h"
|
|
#include "InstancedStructArray.h"
|
|
#include "StateTreePropertyBindings.h"
|
|
#include "StateTreeInstanceData.h"
|
|
#include "Misc/ScopeRWLock.h"
|
|
#include "StateTree.generated.h"
|
|
|
|
|
|
/** Custom serialization version for StateTree Asset */
|
|
struct STATETREEMODULE_API FStateTreeCustomVersion
|
|
{
|
|
enum Type
|
|
{
|
|
// Before any version changes were made in the plugin
|
|
BeforeCustomVersionWasAdded = 0,
|
|
// Separated conditions to shared instance data.
|
|
SharedInstanceData,
|
|
// Moved evaluators to be global.
|
|
GlobalEvaluators,
|
|
// Moved instance data to arrays.
|
|
InstanceDataArrays,
|
|
// Added index types.
|
|
IndexTypes,
|
|
// Added events.
|
|
AddedEvents,
|
|
// Testing mishap
|
|
AddedFoo,
|
|
// Changed transition delay
|
|
TransitionDelay,
|
|
|
|
// -----<new versions can be added above this line>-------------------------------------------------
|
|
VersionPlusOne,
|
|
LatestVersion = VersionPlusOne - 1
|
|
};
|
|
|
|
/** The GUID for this custom version number */
|
|
const static FGuid GUID;
|
|
|
|
private:
|
|
FStateTreeCustomVersion() {}
|
|
};
|
|
|
|
|
|
#if WITH_EDITOR
|
|
/** Struct containing information about the StateTree runtime memory usage. */
|
|
struct FStateTreeMemoryUsage
|
|
{
|
|
FStateTreeMemoryUsage() = default;
|
|
FStateTreeMemoryUsage(const FString InName, const FStateTreeStateHandle InHandle = FStateTreeStateHandle::Invalid)
|
|
: Name(InName)
|
|
, Handle(InHandle)
|
|
{
|
|
}
|
|
|
|
void AddUsage(FConstStructView View);
|
|
void AddUsage(const UObject* Object);
|
|
|
|
FString Name;
|
|
FStateTreeStateHandle Handle;
|
|
int32 NodeCount = 0;
|
|
int32 EstimatedMemoryUsage = 0;
|
|
int32 ChildNodeCount = 0;
|
|
int32 EstimatedChildMemoryUsage = 0;
|
|
};
|
|
#endif
|
|
|
|
|
|
/**
|
|
* StateTree asset. Contains the StateTree definition in both editor and runtime (baked) formats.
|
|
*/
|
|
UCLASS(BlueprintType)
|
|
class STATETREEMODULE_API UStateTree : public UDataAsset
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
|
|
/** @return Shared instance data. */
|
|
TSharedPtr<FStateTreeInstanceData> GetSharedInstanceData() const;
|
|
|
|
/** @return Number of data views required for StateTree execution (Evaluators, Tasks, Conditions, External data). */
|
|
int32 GetNumDataViews() const { return NumDataViews; }
|
|
|
|
/** @return List of external data required by the state tree */
|
|
TConstArrayView<FStateTreeExternalDataDesc> GetExternalDataDescs() const { return ExternalDataDescs; }
|
|
|
|
/** @return List of context data enforced by the schema that must be provided through the execution context. */
|
|
TConstArrayView<FStateTreeExternalDataDesc> GetContextDataDescs() const { return ContextDataDescs; }
|
|
|
|
/** @return List of default parameters of the state tree. Default parameter values can be overridden at runtime by the execution context. */
|
|
const FInstancedPropertyBag& GetDefaultParameters() const { return Parameters; }
|
|
|
|
/** @return true if the tree asset can be used at runtime. */
|
|
bool IsReadyToRun() const;
|
|
|
|
/** @return schema that was used to compile the StateTree. */
|
|
const UStateTreeSchema* GetSchema() const { return Schema; }
|
|
|
|
#if WITH_EDITOR
|
|
/** Resets the compiled data to empty. */
|
|
void ResetCompiled();
|
|
|
|
/** Calculates runtime memory usage for different sections of the tree. */
|
|
TArray<FStateTreeMemoryUsage> CalculateEstimatedMemoryUsage() const;
|
|
#endif
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
/** Edit time data for the StateTree, instance of UStateTreeEditorData */
|
|
UPROPERTY()
|
|
TObjectPtr<UObject> EditorData;
|
|
|
|
/** Hash of the editor data from last compile. */
|
|
UPROPERTY()
|
|
uint32 LastCompiledEditorDataHash = 0;
|
|
#endif
|
|
|
|
protected:
|
|
|
|
/**
|
|
* Resolves references between data in the StateTree.
|
|
* @return true if all references to internal and external data are resolved properly, false otherwise.
|
|
*/
|
|
[[nodiscard]] bool Link();
|
|
|
|
virtual void PostLoad() override;
|
|
#if WITH_EDITORONLY_DATA
|
|
static void DeclareConstructClasses(TArray<FTopLevelAssetPath>& OutConstructClasses, const UClass* SpecificSubclass);
|
|
#endif
|
|
virtual void Serialize(FStructuredArchiveRecord Record) override;
|
|
|
|
#if WITH_EDITOR
|
|
virtual void GetAssetRegistryTags(TArray<FAssetRegistryTag>& OutTags) const override;
|
|
virtual void PostLoadAssetRegistryTags(const FAssetData& InAssetData, TArray<FAssetRegistryTag>& OutTagsAndValuesToUpdate) const;
|
|
#endif
|
|
|
|
static void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector);
|
|
|
|
private:
|
|
|
|
/**
|
|
* Reset the data generated by Link(), this in turn will cause IsReadyToRun() to return false.
|
|
* Used during linking, or to invalidate the linked data when data version is old (requires recompile).
|
|
*/
|
|
void ResetLinked();
|
|
|
|
// Data created during compilation, source data in EditorData.
|
|
|
|
/** Schema used to compile the StateTree. */
|
|
UPROPERTY(Instanced)
|
|
TObjectPtr<UStateTreeSchema> Schema = nullptr;
|
|
|
|
/** Runtime states, root state at index 0 */
|
|
UPROPERTY()
|
|
TArray<FCompactStateTreeState> States;
|
|
|
|
/** Runtime transitions. */
|
|
UPROPERTY()
|
|
TArray<FCompactStateTransition> Transitions;
|
|
|
|
/** Evaluators, Tasks, and Condition nodes. */
|
|
UPROPERTY()
|
|
FInstancedStructArray Nodes;
|
|
|
|
/** Default node instance data (e.g. evaluators, tasks). */
|
|
UPROPERTY()
|
|
FStateTreeInstanceData DefaultInstanceData;
|
|
|
|
/** Shared node instance data (e.g. conditions). */
|
|
UPROPERTY()
|
|
FStateTreeInstanceData SharedInstanceData;
|
|
|
|
mutable FRWLock PerThreadSharedInstanceDataLock;
|
|
mutable TArray<TSharedPtr<FStateTreeInstanceData>> PerThreadSharedInstanceData;
|
|
|
|
/** List of names external data enforced by the schema, created at compilation. */
|
|
UPROPERTY()
|
|
TArray<FStateTreeExternalDataDesc> ContextDataDescs;
|
|
|
|
UPROPERTY()
|
|
FStateTreePropertyBindings PropertyBindings;
|
|
|
|
/**
|
|
* Parameters that could be used for bindings within the Tree.
|
|
* Default values are stored within the asset but StateTreeReference can be used to parameterized the tree.
|
|
* @see FStateTreeReference
|
|
*/
|
|
UPROPERTY()
|
|
FInstancedPropertyBag Parameters;
|
|
|
|
/** Data view index of the tree Parameters */
|
|
UPROPERTY()
|
|
FStateTreeIndex8 ParametersDataViewIndex = FStateTreeIndex8::Invalid;
|
|
|
|
/** Index of first evaluator in Nodes. */
|
|
UPROPERTY()
|
|
uint16 EvaluatorsBegin = 0;
|
|
|
|
/** Number of evaluators. */
|
|
UPROPERTY()
|
|
uint16 EvaluatorsNum = 0;
|
|
|
|
// Data created during linking.
|
|
|
|
/** List of external data required by the state tree, created during linking. */
|
|
UPROPERTY(Transient)
|
|
TArray<FStateTreeExternalDataDesc> ExternalDataDescs;
|
|
|
|
/** Base index of external data, created during linking. */
|
|
UPROPERTY(Transient)
|
|
int32 ExternalDataBaseIndex = 0;
|
|
|
|
/** Total number of data views, created during linking. */
|
|
UPROPERTY(Transient)
|
|
int32 NumDataViews = 0;
|
|
|
|
/** True if the StateTree was linked successfully. */
|
|
bool bIsLinked = false;
|
|
|
|
friend struct FStateTreeInstance;
|
|
friend struct FStateTreeExecutionContext;
|
|
#if WITH_EDITORONLY_DATA
|
|
friend struct FStateTreeCompiler;
|
|
#endif
|
|
};
|
|
|