2024-02-23 18:34:40 +08:00
using DCFApixels.DragonECS.Internal ;
using DCFApixels.DragonECS.RunnersCore ;
2023-05-27 23:02:32 +08:00
using System ;
2023-03-11 17:11:40 +08:00
using System.Linq ;
2023-05-26 04:25:09 +08:00
using static DCFApixels . DragonECS . EcsDebugUtility ;
2023-03-11 17:11:40 +08:00
namespace DCFApixels.DragonECS
{
2024-06-13 18:04:18 +08:00
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.OTHER_GROUP)]
[MetaDescription(EcsConsts.AUTHOR, "...")]
[MetaTags(MetaTags.HIDDEN)]
2024-10-12 00:08:12 +08:00
[MetaID("EF8A557C9201E6F04D4A76DC670BDE19")]
2024-06-05 14:39:19 +08:00
public interface IEcsProcess : IEcsMember { }
2023-03-16 01:49:14 +08:00
2023-04-23 17:55:01 +08:00
namespace RunnersCore
2023-03-11 17:11:40 +08:00
{
2024-02-23 18:34:40 +08:00
public abstract class EcsRunner
2023-03-11 17:11:40 +08:00
{
2024-02-23 18:34:40 +08:00
internal abstract void Init_Internal ( EcsPipeline source ) ;
2023-03-11 17:11:40 +08:00
2024-02-23 18:34:40 +08:00
#region CheckRunnerValide
public static void CheckRunnerTypeIsValide ( Type runnerType , Type processInterfaceType )
2023-12-06 21:15:35 +08:00
{
2024-02-23 18:34:40 +08:00
#region DEBUG
#pragma warning disable IL2070 // 'this' argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The parameter of method does not have matching annotations.
Type targetInterface = processInterfaceType ;
if ( runnerType . IsAbstract | | runnerType . IsInterface )
2023-12-06 21:15:35 +08:00
{
2024-02-23 18:34:40 +08:00
Throw . UndefinedException ( ) ;
2023-12-06 21:15:35 +08:00
}
2024-01-08 13:39:38 +08:00
Type GetRunnerBaseType ( Type inType )
2023-12-06 21:15:35 +08:00
{
2024-01-08 13:39:38 +08:00
if ( inType . IsGenericType & & inType . GetGenericTypeDefinition ( ) = = typeof ( EcsRunner < > ) )
2024-02-23 18:34:40 +08:00
{
2024-01-08 13:39:38 +08:00
return inType ;
2024-02-23 18:34:40 +08:00
}
2024-01-08 13:39:38 +08:00
if ( inType . BaseType ! = null )
2024-02-23 18:34:40 +08:00
{
2024-01-08 13:39:38 +08:00
return GetRunnerBaseType ( inType . BaseType ) ;
2024-02-23 18:34:40 +08:00
}
2023-12-06 21:15:35 +08:00
return null ;
}
2024-02-23 18:34:40 +08:00
Type baseType = GetRunnerBaseType ( runnerType ) ;
2023-12-06 21:15:35 +08:00
Type baseTypeArgument = baseType . GenericTypeArguments [ 0 ] ;
if ( baseTypeArgument ! = targetInterface )
{
2024-02-23 18:34:40 +08:00
Throw . UndefinedException ( ) ;
2023-12-06 21:15:35 +08:00
}
2024-02-23 18:34:40 +08:00
if ( ! runnerType . GetInterfaces ( ) . Any ( o = > o = = targetInterface ) )
2023-12-06 20:34:33 +08:00
{
2024-02-23 18:34:40 +08:00
throw new EcsRunnerImplementationException ( $"Runner {GetGenericTypeFullName(runnerType, 1)} does not implement interface {GetGenericTypeFullName(baseTypeArgument, 1)}." ) ;
2023-12-06 20:34:33 +08:00
}
2024-02-23 18:34:40 +08:00
#pragma warning restore IL2070 // 'this' argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The parameter of method does not have matching annotations.
#endregion
2023-04-23 17:55:01 +08:00
}
#endregion
2024-02-23 18:34:40 +08:00
}
2024-06-13 18:04:18 +08:00
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.OTHER_GROUP)]
[MetaDescription(EcsConsts.AUTHOR, "...")]
[MetaTags(MetaTags.HIDDEN)]
2024-10-12 00:08:12 +08:00
[MetaID("E49B557C92010E46DF1602972BC988BC")]
2024-02-23 18:34:40 +08:00
public interface IEcsRunner : IEcsProcess
{
EcsPipeline Pipeline { get ; }
Type Interface { get ; }
EcsProcessRaw ProcessRaw { get ; }
bool IsEmpty { get ; }
}
2023-12-20 23:21:10 +08:00
2024-06-13 18:04:18 +08:00
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.OTHER_GROUP)]
[MetaDescription(EcsConsts.AUTHOR, "...")]
[MetaTags(MetaTags.HIDDEN)]
2024-10-12 00:08:12 +08:00
[MetaID("7DB3557C9201F85E0E1C17D7B19D9CEE")]
2024-02-23 18:34:40 +08:00
public abstract class EcsRunner < TProcess > : EcsRunner , IEcsRunner , IEcsProcess
where TProcess : IEcsProcess
{
2023-04-23 17:55:01 +08:00
private EcsPipeline _source ;
2024-02-22 15:39:37 +08:00
private EcsProcess < TProcess > _process ;
2024-02-23 18:34:40 +08:00
private bool _isInit = false ;
2023-03-26 11:19:03 +08:00
2023-04-23 17:55:01 +08:00
#region Properties
2024-02-22 15:39:37 +08:00
public EcsPipeline Pipeline
{
get { return _source ; }
}
public Type Interface
{
get { return typeof ( TProcess ) ; }
}
public EcsProcessRaw ProcessRaw
{
get { return _process ; }
}
public EcsProcess < TProcess > Process
{
get { return _process ; }
}
public bool IsEmpty
{
2024-02-22 23:48:10 +08:00
get { return _process . IsNullOrEmpty ; }
2024-02-22 15:39:37 +08:00
}
2023-04-23 17:55:01 +08:00
#endregion
2023-03-27 17:34:12 +08:00
2024-02-23 18:34:40 +08:00
#region Constructor Init OnSetup
public EcsRunner ( ) { }
internal override sealed void Init_Internal ( EcsPipeline source )
2023-04-23 17:55:01 +08:00
{
2024-02-23 18:34:40 +08:00
if ( _isInit )
{
2024-04-22 17:49:24 +08:00
Throw . Exception ( "Reinitialization." ) ;
2024-02-23 18:34:40 +08:00
}
_isInit = true ;
2023-04-23 17:55:01 +08:00
_source = source ;
2024-02-23 18:34:40 +08:00
_process = source . GetProcess < TProcess > ( ) ;
2023-04-23 17:55:01 +08:00
OnSetup ( ) ;
}
2024-02-23 18:34:40 +08:00
protected virtual void OnSetup ( ) { }
#endregion
2023-04-23 17:55:01 +08:00
}
2023-03-11 17:11:40 +08:00
}
2023-05-26 04:25:09 +08:00
2023-03-30 01:57:10 +08:00
#region Extensions
2024-02-23 18:34:40 +08:00
public static class IEcsProcessExtensions
2023-03-30 01:57:10 +08:00
{
2024-02-22 22:16:03 +08:00
public static bool IsRunner ( this IEcsProcess self )
2023-03-30 01:57:10 +08:00
{
return self is IEcsRunner ;
}
}
#endregion
2023-03-11 17:11:40 +08:00
}