2020-08-11 01:36:57 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# pragma once
# include "Async/TaskGraphInterfaces.h"
# include "Templates/SubclassOf.h"
# include "EntitySystem/MovieSceneEntityManager.h"
# include "EntitySystem/MovieSceneSequenceInstanceHandle.h"
2020-09-01 14:07:48 -04:00
# include "Misc/EnumClassFlags.h"
2020-08-11 01:36:57 -04:00
# include "MovieSceneEntitySystem.generated.h"
class UMovieSceneEntitySystemLinker ;
namespace UE
{
namespace MovieScene
{
struct FSystemTaskPrerequisites ;
struct FSystemSubsequentTasks ;
2020-09-01 14:07:48 -04:00
enum class EEntitySystemContext : uint8
{
None = 0 ,
/** This system is relevant to runtime */
Runtime = 1 < < 0 ,
/** This system is relevant to interrogation */
Interrogation = 1 < < 1 ,
} ;
ENUM_CLASS_FLAGS ( EEntitySystemContext )
2020-08-11 01:36:57 -04:00
} // namespace MovieScene
} // namespace UE
UCLASS ( )
class MOVIESCENE_API UMovieSceneEntitySystem : public UObject
{
public :
GENERATED_BODY ( )
template < typename T >
using TComponentTypeID = UE : : MovieScene : : TComponentTypeID < T > ;
using FComponentTypeID = UE : : MovieScene : : FComponentTypeID ;
using FComponentMask = UE : : MovieScene : : FComponentMask ;
using FSystemTaskPrerequisites = UE : : MovieScene : : FSystemTaskPrerequisites ;
using FSystemSubsequentTasks = UE : : MovieScene : : FSystemSubsequentTasks ;
UMovieSceneEntitySystem ( const FObjectInitializer & ObjInit ) ;
~ UMovieSceneEntitySystem ( ) ;
/**
* Creates a relationship between the two system types that ensures any systems of type UpstreamSystemType always execute before DownstreamSystemType if they are both present
*
* @ param UpstreamSystemType The UClass of the system that should always be a prerequisite of DownstreamSystemType ( ie , runs first )
* @ param DownstreamSystemType The UClass of the system that should always run after UpstreamSystemType
*/
static void DefineImplicitPrerequisite ( TSubclassOf < UMovieSceneEntitySystem > UpstreamSystemType , TSubclassOf < UMovieSceneEntitySystem > DownstreamSystemType ) ;
/**
* Informs the dependency graph that the specified class type produces components of the specified type .
* Any systems set up as consumers of this component type will always be run after
*
* @ param ClassType The UClass of the system that produces the component type
* @ param ComponentType The type of the component produced by the system
*/
static void DefineComponentProducer ( TSubclassOf < UMovieSceneEntitySystem > ClassType , FComponentTypeID ComponentType ) ;
/**
* Informs the dependency graph that the specified class type consumes components of the specified type , and as such should always execute after any producers of that component type .
*
* @ param ClassType The UClass of the system that consumes the component type
* @ param ComponentType The type of the component consumed by the system
*/
static void DefineComponentConsumer ( TSubclassOf < UMovieSceneEntitySystem > ClassType , FComponentTypeID ComponentType ) ;
/**
* Ensure that any systems relevant to the specified linker ' s entity manager are linked
*/
static void LinkRelevantSystems ( UMovieSceneEntitySystemLinker * InLinker ) ;
public :
2021-11-07 23:43:01 -05:00
/** Returns linker contexts for which this system should not exist */
2020-09-01 14:07:48 -04:00
UE : : MovieScene : : EEntitySystemContext GetExclusionContext ( ) const
{
return SystemExclusionContext ;
}
2021-11-07 23:43:01 -05:00
/** Returns the phase(s) during which this system should be run */
2020-08-11 01:36:57 -04:00
UE : : MovieScene : : ESystemPhase GetPhase ( ) const
{
return Phase ;
}
2021-11-07 23:43:01 -05:00
/** Returns the linker that owns this system */
2020-08-11 01:36:57 -04:00
UMovieSceneEntitySystemLinker * GetLinker ( ) const
{
return Linker ;
}
2021-11-07 23:43:01 -05:00
/** Returns the ID of this system in the system graphs */
2020-08-11 01:36:57 -04:00
uint16 GetGraphID ( ) const
{
return GraphID ;
}
2021-11-07 23:43:01 -05:00
/** Sets the ID of this system in the system graphs */
2020-08-11 01:36:57 -04:00
void SetGraphID ( uint16 InGraphID )
{
GraphID = InGraphID ;
}
2021-11-07 23:43:01 -05:00
/** Gets the ID of this system's type in the global dependency graph */
2020-08-11 01:36:57 -04:00
uint16 GetGlobalDependencyGraphID ( ) const
{
return GlobalDependencyGraphID ;
}
2021-11-07 23:43:01 -05:00
/** Called when the system is removed from the linker */
2020-08-11 01:36:57 -04:00
void Unlink ( ) ;
2021-11-07 23:43:01 -05:00
/** Called when the linker is being destroyed */
2020-08-11 01:36:57 -04:00
void Abandon ( ) ;
2021-11-07 23:43:01 -05:00
/** Called when the system is added to a linker */
2020-08-11 01:36:57 -04:00
void Link ( UMovieSceneEntitySystemLinker * InLinker ) ;
2021-11-07 23:43:01 -05:00
/** Called when the system should run its logic */
2020-09-01 14:07:48 -04:00
void Run ( FSystemTaskPrerequisites & InPrerequisites , FSystemSubsequentTasks & Subsequents ) ;
2020-08-11 01:36:57 -04:00
2021-11-07 23:43:01 -05:00
/** Called to know if the system is still relevant and should be kept around */
2020-08-11 01:36:57 -04:00
bool IsRelevant ( UMovieSceneEntitySystemLinker * InLinker ) const ;
void ConditionalLinkSystem ( UMovieSceneEntitySystemLinker * InLinker ) const ;
void TagGarbage ( ) ;
void CleanTaggedGarbage ( ) ;
2021-05-25 02:43:26 -04:00
/**
* Enable this system if it is not already .
*/
void Enable ( ) ;
/**
* Disable this system if it is not already .
* Disabled systems will remain in the system graph , and will stay alive as long as they are relevant , but will not be Run .
*/
void Disable ( ) ;
2020-08-11 01:36:57 -04:00
protected :
virtual bool IsReadyForFinishDestroy ( ) override ;
virtual void FinishDestroy ( ) override ;
private :
virtual void OnLink ( ) { }
virtual void OnRun ( FSystemTaskPrerequisites & InPrerequisites , FSystemSubsequentTasks & Subsequents ) { }
virtual void OnUnlink ( ) { }
virtual bool IsRelevantImpl ( UMovieSceneEntitySystemLinker * InLinker ) const ;
virtual void ConditionalLinkSystemImpl ( UMovieSceneEntitySystemLinker * InLinker ) const ;
virtual void OnTagGarbage ( ) { }
virtual void OnCleanTaggedGarbage ( ) { }
protected :
UPROPERTY ( )
2021-01-27 17:40:25 -04:00
TObjectPtr < UMovieSceneEntitySystemLinker > Linker ;
2020-08-11 01:36:57 -04:00
protected :
/** Defines a single component that makes this system automatically linked when it exists in an entity manager. Override IsRelevantImpl for more complex relevancy definitions. */
FComponentTypeID RelevantComponent ;
UE : : MovieScene : : ESystemPhase Phase ;
uint16 GraphID ;
uint16 GlobalDependencyGraphID ;
2020-09-01 14:07:48 -04:00
UE : : MovieScene : : EEntitySystemContext SystemExclusionContext ;
2021-05-25 02:43:26 -04:00
/** When false, this system will not call its OnRun function, but will still be kept alive as long as IsRelevant is true */
bool bSystemIsEnabled ;
2020-09-24 00:43:27 -04:00
# if STATS || ENABLE_STATNAMEDEVENTS
2020-08-11 01:36:57 -04:00
TStatId StatID ;
# endif
} ;