Files
UnrealEngineUWP/Engine/Plugins/Runtime/StateTree/Source/StateTreeModule/Public/StateTreeInstanceData.h
mikko mononen 66e1f36595 StateTree: Changed runtime data to contain only active tasks
- Commented and cleaned up the members of UStateTree a bit
- Changed StateTree Node storage to FInstancedStructArray (contiguous memory)
- Changed StateTree SharedData to FInstancedStructArray
- Changed StateTree instance data to use FInstancedStructArray
- StateTree statistics shows estimated mem usage per state and max for tree (heaviest linked chain)
- Added explicit bLinked state for UStateTree
- Cleaned up UStateTree::ResetCompiled()/ResetLinked()
- Changed StateTree execution context to allocate task instance data on Start() and EnterState()
- StateTree tick uses execution order counters to access the instance data instead of compile time specific index

#jira  UE-153269
#rb Stephen.Holmes Yoan.StAmant
#preflight 628df39faf7a2e956bb45dc5

[CL 20361823 by mikko mononen in ue5-main branch]
2022-05-25 05:34:50 -04:00

86 lines
3.0 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "InstancedStructArray.h"
#include "StructView.h"
#include "StateTreeInstanceData.generated.h"
/**
* StateTree instance data is used to store the runtime state of a StateTree.
* The layout of the data is described in a FStateTreeInstanceDataLayout.
*
* Note: Serialization is supported only for FArchive::IsModifyingWeakAndStrongReferences(), that is replacing object references.
*/
USTRUCT()
struct STATETREEMODULE_API FStateTreeInstanceData
{
GENERATED_BODY()
FStateTreeInstanceData() = default;
~FStateTreeInstanceData() { Reset(); }
/** Initializes the array with specified items. */
void Init(UObject& InOwner, TConstArrayView<FInstancedStruct> InStructs, TConstArrayView<UObject*> InObjects);
void Init(UObject& InOwner, TConstArrayView<FConstStructView> InStructs, TConstArrayView<UObject*> InObjects);
/** Appends new items to the instance. */
void Append(UObject& InOwner, TConstArrayView<FInstancedStruct> InStructs, TConstArrayView<UObject*> InObjects);
void Append(UObject& InOwner, TConstArrayView<FConstStructView> InStructs, TConstArrayView<UObject*> InObjects);
/** Prunes the array sizes to specified lengths. */
void Prune(const int32 NumStructs, const int32 NumObjects);
/** Shares the layout from another instance data, and copies the data over. */
void CopyFrom(UObject& InOwner, const FStateTreeInstanceData& InOther);
/** Resets the data to empty. */
void Reset();
/** @return true if the instance is correctly initialized. */
bool IsValid() const { return InstanceStructs.Num() > 0 || InstanceObjects.Num() > 0; }
/** @return Number of items in the instance data. */
int32 NumStructs() const { return InstanceStructs.Num(); }
/** @return mutable view to the struct at specified index. */
FStructView GetMutableStruct(const int32 Index) const { return InstanceStructs[Index]; }
/** @return const view to the struct at specified index. */
FConstStructView GetStruct(const int32 Index) const { return InstanceStructs[Index]; }
/** @return number of instance objects */
int32 NumObjects() const { return InstanceObjects.Num(); }
/** @return pointer to an instance object */
UObject* GetMutableObject(const int32 Index) const { return InstanceObjects[Index]; }
/** @return const pointer to an instance object */
const UObject* GetObject(const int32 Index) const { return InstanceObjects[Index]; }
int32 GetEstimatedMemoryUsage() const;
int32 GetNumItems() const;
/** Type traits */
bool Identical(const FStateTreeInstanceData* Other, uint32 PortFlags) const;
private:
/** Struct instances */
UPROPERTY()
FInstancedStructArray InstanceStructs;
/** Object instances. */
UPROPERTY()
TArray<TObjectPtr<UObject>> InstanceObjects;
};
template<>
struct TStructOpsTypeTraits<FStateTreeInstanceData> : public TStructOpsTypeTraitsBase2<FStateTreeInstanceData>
{
enum
{
WithIdentical = true,
};
};