diff --git a/TinyEcs.slnx b/TinyEcs.slnx index 5d047c7f..33561469 100644 --- a/TinyEcs.slnx +++ b/TinyEcs.slnx @@ -10,6 +10,6 @@ - + diff --git a/samples/MyBattleground/MyBattleground.csproj b/samples/MyBattleground/MyBattleground.csproj index 109c3d15..4653ad91 100644 --- a/samples/MyBattleground/MyBattleground.csproj +++ b/samples/MyBattleground/MyBattleground.csproj @@ -8,6 +8,9 @@ preview enable true + + true + $(BaseIntermediateOutputPath)\Generated @@ -33,6 +36,7 @@ + diff --git a/samples/MyBattleground/Program.cs b/samples/MyBattleground/Program.cs index fe68ffbc..f7c604a6 100644 --- a/samples/MyBattleground/Program.cs +++ b/samples/MyBattleground/Program.cs @@ -3,14 +3,41 @@ using TinyEcs; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Numerics; const int ENTITIES_COUNT = (524_288 * 2 * 1); using var ecs = new World(); -var scheduler = new Scheduler(ecs); +var scheduler = new Scheduler(ecs, ThreadingMode.Single); +// var sys = new HelloSystem(); +// sys.Initialize(ecs); +// sys.ExecuteOnReady(ecs, ecs.Ticks.ThisRun); +scheduler.AddResource(new CustomResource()); + +// scheduler.AddSystem2(Stages.Startup, new SetupSystem(ENTITIES_COUNT)); +// scheduler.AddSystem2(Stages.Update); +// +// scheduler.AddSystem2(Stages.Update, new HelloSystem()); + +scheduler.AddPlugin(new TestPlugin() { Count = ENTITIES_COUNT }); + + +// scheduler.AddPlugin(); +// scheduler.AddPlugin(); + +// scheduler.AddPlugin(); +// scheduler.AddPlugin(); +// scheduler.RunOnce(); +// +// +// return; +// ecs.Entity(); +// ecs.Entity().Delete(); +// var xx = ecs.Entity().Add(); +// +// xx.Get(); +// Console.WriteLine(""); // scheduler.OnUpdate((Query, Changed> query) => // { @@ -21,8 +48,8 @@ // }, ThreadingMode.Single); -var ab = ecs.Entity() - .Set(new Position()).Set(new Velocity()); +// var ab = ecs.Entity() +// .Set(new Position()).Set(new Velocity()); // ecs.Entity() // .Set(new Position() { X = -1 }); // // var q = ecs.QueryBuilder() @@ -49,7 +76,7 @@ // scheduler.RunOnce(); // scheduler.RunOnce(); -ab.Set(new Position() { X = 2 }); +// ab.Set(new Position() { X = 2 }); // scheduler.RunOnce(); // scheduler.AddState(GameState.Loading); @@ -96,47 +123,75 @@ // while (true) // scheduler.RunOnce(); -for (int i = 0; i < ENTITIES_COUNT; i++) - ecs.Entity() - .Set(new Position()) - .Set(new Velocity()); +// for (var i = 0; i < ENTITIES_COUNT; i++) +// ecs.Entity() +// .Set(new Position()) +// .Set(new Velocity()); // ecs.Entity().Set(new Position()).Set(new Velocity()).Set(new Mass()); +// ecs.Entity() +// .Set(new Velocity()); +// ecs.Entity() +// .Set(new Position()); - -scheduler.AddSystem(( - Query, With> q, - Query, Added> added -) => -{ - foreach ((var pos, var vel) in q) - { - pos.Ref.X *= vel.Ref.X; - pos.Ref.Y *= vel.Ref.Y; - - // pos.Ref.X *= vel.Ref.X; - // pos.Ref.Y *= vel.Ref.Y; - - // if (pos.IsChanged) - // pos.ClearState(); - } - - // foreach ((var pos, var vel) in added) - // { - // pos.Ref.X *= vel.Ref.X; - // pos.Ref.Y *= vel.Ref.Y; - - // // if (pos.IsAdded) - // // pos.ClearState(); - // } -}, threadingType: ThreadingMode.Single); - +// ecs.Entity().Set(new Velocity()).Set(new Position()); +// scheduler.AddSystem([TinySystem] ( +// Query> q, +// Query, Added> added +// ) => +// { +// +// // foreach ((var pos, var vel) in or) +// // { +// // if (pos.IsValid()) +// // { +// // Console.Write("pos is valid "); +// // } +// // else +// // { +// +// // } +// +// // if (vel.IsValid()) +// // { +// // Console.Write("vel is valid"); +// // } +// // else +// // { +// +// // } +// +// // Console.WriteLine(); +// // } +// +// foreach (var (pos, vel) in q) +// { +// pos.Ref.X *= vel.Ref.X; +// pos.Ref.Y *= vel.Ref.Y; +// +// // pos.Ref.X *= vel.Ref.X; +// // pos.Ref.Y *= vel.Ref.Y; +// +// // if (pos.IsChanged) +// // pos.ClearState(); +// } +// +// // foreach ((var pos, var vel) in added) +// // { +// // pos.Ref.X *= vel.Ref.X; +// // pos.Ref.Y *= vel.Ref.Y; +// +// // // if (pos.IsAdded) +// // // pos.ClearState(); +// // } +// }, threadingType: ThreadingMode.Single); +// var query = ecs.QueryBuilder() - .With() - .With() - .Build(); + .With() + .With() + .Build(); var sw = Stopwatch.StartNew(); var start = 0f; @@ -144,78 +199,80 @@ Query, Added> added while (true) { - for (int i = 0; i < 3600; ++i) - { - scheduler.RunOnce(); + for (int i = 0; i < 3600; ++i) + { + scheduler.RunOnce(); - // Execute(query); - // ExecuteIterator(query); + // Execute(query); + // ExecuteIterator(query); - // var it = query.Iter(); - // while (it.Next()) - // { - // var count = it.Count; + // var it = query.Iter(); + // while (it.Next()) + // { + // var count = it.Count; - // ref var pos = ref it.DataRef(0); - // ref var vel = ref it.DataRef(1); - // ref var lastPos = ref Unsafe.Add(ref pos, count); + // ref var pos = ref it.DataRef(0); + // ref var vel = ref it.DataRef(1); + // ref var lastPos = ref Unsafe.Add(ref pos, count); - // while (Unsafe.IsAddressLessThan(ref pos, ref lastPos)) - // { - // pos.X *= vel.X; - // pos.Y *= vel.Y; + // while (Unsafe.IsAddressLessThan(ref pos, ref lastPos)) + // { + // pos.X *= vel.X; + // pos.Y *= vel.Y; - // pos = ref Unsafe.Add(ref pos, 1); - // vel = ref Unsafe.Add(ref vel, 1); - // } - // } - } + // pos = ref Unsafe.Add(ref pos, 1); + // vel = ref Unsafe.Add(ref vel, 1); + // } + // } + } - last = start; - start = sw.ElapsedMilliseconds; + last = start; + start = sw.ElapsedMilliseconds; - Console.WriteLine("query done in {0} ms", start - last); + Console.WriteLine("query done in {0} ms", start - last); } static void Execute(Query query) { - foreach ((var pos, var vel) in Data.CreateIterator(query.Iter())) - { - pos.Ref.X *= vel.Ref.X; - pos.Ref.Y *= vel.Ref.Y; - } + foreach (var (pos, vel) in Data.CreateIterator(query.Iter())) + { + pos.Ref.X *= vel.Ref.X; + pos.Ref.Y *= vel.Ref.Y; + } } -static void ExecuteIterator(Query query) -{ - var it = query.Iter(); - - while (it.Next()) - { - var span0 = it.Data(0); - var span1 = it.Data(1); - var count = it.Count; - for (var i = 0; i < count; ++i) - { - ref var pos = ref span0[i]; - ref var vel = ref span1[i]; - pos.X *= vel.X; - pos.Y *= vel.Y; - } - } -} - -struct Position +// static void ExecuteIterator(Query query) +// { +// var it = query.Iter(); +// +// while (it.Next()) +// { +// var span0 = it.Data(0); +// var span1 = it.Data(1); +// var count = it.Count; +// +// for (var i = 0; i < count; ++i) +// { +// ref var pos = ref span0[i]; +// ref var vel = ref span1[i]; +// +// pos.X *= vel.X; +// pos.Y *= vel.Y; +// } +// } +// } + +public struct Position { - public float X, Y, Z; + public float X, Y, Z; } -struct Velocity +public struct Velocity { - public float X, Y; + public float X, Y; } struct Mass { public float Value; } @@ -225,13 +282,102 @@ struct Tag { } enum GameState { - Loading, - Playing, - Menu, - Menu2 + Loading, + Playing, + Menu, + Menu2 } enum AnotherState { - A, B, C + A, B, C +} + + +class SYSTEMS +{ + [TinySystem] + public bool CheckThis() + { + new CheckThisAdapter(this); + return true; + } +} + + +internal sealed class TestPlugin : IPlugin +{ + public int Count { get; init; } + + public void Build(Scheduler scheduler) + { + scheduler.AddState(GameState.Loading); + + scheduler + .AddSystems(Stage.Startup, new SetupAdapter(this)) + .AddSystems(Stage.Update, new MoveEntitiesAdapter() + .RunIf(new CanRunAdapter(this))) + .AddSystem(Stage.Update); + + scheduler.AddStageAfterOf(Stage.Update, "AFTER_UPDATE"); + scheduler.AddSystems("AFTER_UPDATE", new AcceptAdapter(this)); + + //scheduler.AddSystems(Stage.OnEnter, new TinyStateSystemAdapter(GameState.Playing)); + scheduler.AddSystems(Stage.OnEnter(GameState.Playing), new OnEnterAdapter(this)); + scheduler.AddSystems(Stage.OnExit(GameState.Loading), new OnExitAdapter(this)); + } + + + [TinySystem] + public void Setup(World world) + { + for (var i = 0; i < Count; i++) + world.Entity() + .Set(new Position()) + .Set(new Velocity()); + } + + [TinySystem] + public static void MoveEntities(Query> query) + { + foreach ((var pos, var vel) in query) + { + pos.Ref.X *= vel.Ref.X; + pos.Ref.Y *= vel.Ref.Y; + } + } + + [TinySystem] + public static void PrintSomething(State state) + { + state.Set(GameState.Playing); + } + + [TinySystem] + public void OnEnter(State state) + { + Console.WriteLine("on enter {0}", state.Current); + } + + [TinySystem] + public void OnExit(State state) + { + Console.WriteLine("on exit {0}", state.Current); + } + + [TinySystem] + public bool CanRun() + => true; + + [TinySystem] + public void Accept() + { + } +} + + + +public class CustomResource +{ + } diff --git a/samples/TinyEcsGame/Program.cs b/samples/TinyEcsGame/Program.cs index 3aaa1490..7dc4e3b7 100644 --- a/samples/TinyEcsGame/Program.cs +++ b/samples/TinyEcsGame/Program.cs @@ -3,7 +3,7 @@ using Raylib_cs; -using var app = new App(); +using var app = new App(ThreadingMode.Multi); app.AddPlugin(new RaylibPlugin() { WindowSize = new() { Value = { X = 800, Y = 600 } }, @@ -17,14 +17,14 @@ Velocity = 250 }); -app.Run(() => Raylib.WindowShouldClose(), Raylib.CloseWindow); +app.Run(() => Raylib.IsWindowReady() && Raylib.WindowShouldClose(), Raylib.CloseWindow); // ================================================================================= sealed class App : Scheduler, IDisposable { - public App() : base(new()) { } + public App(ThreadingMode threadingMode = ThreadingMode.Auto) : base(new(), threadingMode) { } public void Dispose() => World?.Dispose(); } @@ -54,6 +54,17 @@ struct RaylibPlugin : IPlugin public bool VSync { get; set; } public readonly void Build(Scheduler scheduler) + { + scheduler.AddSystemParam(new Time()); + scheduler.AddResource(WindowSize); + scheduler.AddResource(new AssetsManager()); + + scheduler.AddSystems(Stage.Startup, new CreateWindowAdapter(this) { Configuration = { ThreadingMode = ThreadingMode.Single } }); + scheduler.AddSystems(Stage.BeforeUpdate, new UpdateTimeAdapter(this)); + } + + [TinySystem] + public void CreateWindow() { ConfigFlags flags = 0; if (VSync) @@ -61,16 +72,13 @@ public readonly void Build(Scheduler scheduler) Raylib.SetConfigFlags(flags); Raylib.InitWindow((int)WindowSize.Value.X, (int)WindowSize.Value.Y, Title); + } - scheduler.AddSystemParam(new Time()); - scheduler.AddResource(WindowSize); - scheduler.AddResource(new AssetsManager()); - - scheduler.AddSystem((Time time) => - { - time.Frame = Raylib.GetFrameTime(); - time.Total += time.Frame; - }, Stages.BeforeUpdate); + [TinySystem] + public void UpdateTime(Time time) + { + time.Frame = Raylib.GetFrameTime(); + time.Total += time.Frame; } } // ================================================================================= @@ -93,16 +101,14 @@ struct GameplayPlugin : IPlugin public void Build(Scheduler scheduler) { - var init = SpawnEntities; - var fn0 = MoveSystem; - var fn1 = CheckBounds; - - scheduler.AddSystem(init, Stages.Startup); - scheduler.AddSystem(fn0); - scheduler.AddSystem(fn1); + scheduler + .AddSystems(Stage.Startup, new SpawnEntitiesAdapter(this) { Configuration = { ThreadingMode = ThreadingMode.Single } } + .RunIf(new CheckIfWindowReadyAdapter())) + .AddSystems(Stage.Update, new MoveSystemAdapter(), new CheckBoundsAdapter()); } - static void MoveSystem(Time time, Query> query) + [TinySystem] + public static void MoveSystem(Time time, Query> query) { foreach ((var pos, var vel, var rot) in query) { @@ -111,7 +117,8 @@ static void MoveSystem(Time time, Query> quer } } - static void CheckBounds(Query> query, Res windowSize) + [TinySystem] + public static void CheckBounds(Query> query, Res windowSize) { foreach ((var pos, var vel) in query) { @@ -139,7 +146,14 @@ static void CheckBounds(Query> query, Res w } } - void SpawnEntities(World ecs, SchedulerState scheduler, Res size, Res assetsManager) + [TinySystem] + public static bool CheckIfWindowReady() + { + return Raylib.IsWindowReady(); + } + + [TinySystem] + public void SpawnEntities(World ecs, SchedulerState scheduler, Res size, Res assetsManager) { var rnd = Random.Shared; var texture = Raylib.LoadTexture(Path.Combine(AppContext.BaseDirectory, "Content", "pepe.png")); @@ -189,29 +203,33 @@ void SpawnEntities(World ecs, SchedulerState scheduler, Res size, Re { public void Build(Scheduler scheduler) { - var fn2 = BeginRenderer; - var fn3 = RenderEntities; - var fn4 = DrawText; - var fn5 = EndRenderer; - - var begin = scheduler.AddSystem(fn2, stage: Stages.FrameEnd, threadingType: ThreadingMode.Single); - var renderEntities = scheduler.AddSystem(fn3, stage: Stages.FrameEnd, threadingType: ThreadingMode.Single); - var renderText = scheduler.AddSystem(fn4, stage: Stages.FrameEnd, threadingType: ThreadingMode.Single); - var end = scheduler.AddSystem(fn5, stage: Stages.FrameEnd, threadingType: ThreadingMode.Single); + scheduler + .AddSystems(Stage.FrameEnd, + SystemOrder.Chain + ( + new BeginRendererAdapter(), + new RenderEntitiesAdapter(), + new DrawTextAdapter(), + new EndRendererAdapter() + ) + .RunIf(new CheckIfWindowReadyAdapter())); } - static void BeginRenderer() + [TinySystem] + public static void BeginRenderer() { Raylib.BeginDrawing(); Raylib.ClearBackground(Color.Black); } - static void EndRenderer() + [TinySystem] + public static void EndRenderer() { Raylib.EndDrawing(); } - static void RenderEntities(Query> query, Res assetsManager) + [TinySystem] + public static void RenderEntities(Query> query, Res assetsManager) { var currTextureId = 0u; Texture2D? texture = null; @@ -229,7 +247,8 @@ static void RenderEntities(Query> query, Res text, Local timeout) + [TinySystem] + public static void DrawText(World ecs, Time time, Local text, Local timeout) { //if (time.Total > timeout) { diff --git a/samples/TinyEcsGame/TinyEcsGame.csproj b/samples/TinyEcsGame/TinyEcsGame.csproj index b2e49a5e..bd3745c2 100644 --- a/samples/TinyEcsGame/TinyEcsGame.csproj +++ b/samples/TinyEcsGame/TinyEcsGame.csproj @@ -40,6 +40,7 @@ + diff --git a/src/Bevy.cs b/src/Bevy.cs index d8ee7a44..588e0817 100644 --- a/src/Bevy.cs +++ b/src/Bevy.cs @@ -6,166 +6,287 @@ namespace TinyEcs; #if NET9_0_OR_GREATER -public sealed partial class FuncSystem where TArg : notnull +[Obsolete("Use the Stage class instead.")] +public enum Stages { - private readonly TArg _arg; - private readonly Func, bool> _fn; - private readonly List> _conditions; - private readonly Func _validator; - private readonly Func _checkInUse; - private readonly Stages _stage; - private readonly ThreadingMode _threadingType; - private readonly LinkedList> _after = new(); - private readonly LinkedList> _before = new(); - internal LinkedListNode>? Node { get; set; } - internal SystemTicks Ticks { get; } = new(); - - - internal FuncSystem(TArg arg, Func, bool> fn, Func checkInUse, Stages stage, ThreadingMode threadingType) - { - _arg = arg; - _fn = fn; - _conditions = new(); - _validator = ValidateConditions; - _checkInUse = checkInUse; - _threadingType = threadingType; - _stage = stage; - } + Startup, + FrameStart, + BeforeUpdate, + Update, + AfterUpdate, + FrameEnd, - internal void Run(uint ticks) - { - Ticks.ThisRun = ticks; + OnEnter, + OnExit +} - foreach (var s in _before) - s.Run(ticks); +public enum ThreadingMode +{ + Auto, + Single, + Multi +} - if (_fn(Ticks, _arg, _validator)) - { - foreach (var s in _after) - s.Run(ticks); - } +public sealed class SystemTicks +{ + public uint LastRun { get; internal set; } + public uint ThisRun { get; internal set; } +} - Ticks.LastRun = Ticks.ThisRun; + +public class Stage +{ + internal Stage(string name, bool runOnce) + { + if (string.IsNullOrWhiteSpace(name)) + throw new ArgumentException("Stage name cannot be null or whitespace.", nameof(name)); + Name = name; + RunOnce = runOnce; } - public FuncSystem RunIf(Func condition) + public string Name { get; } + public bool RunOnce { get; } + + + public static readonly Stage Startup = new(nameof(Startup), true); + public static readonly Stage FrameStart = new(nameof(FrameStart), false); + public static readonly Stage BeforeUpdate = new(nameof(BeforeUpdate), false); + public static readonly Stage Update = new(nameof(Update), false); + public static readonly Stage AfterUpdate = new(nameof(AfterUpdate), false); + public static readonly Stage FrameEnd = new(nameof(FrameEnd), false); + + // These are useful just to headers for the custom OnEnter/OnExit stages + internal static readonly Stage OnEnterInner = new(nameof(OnEnterInner), false); + internal static readonly Stage OnExitInner = new(nameof(OnExitInner), false); + + public static Stage OnEnter(TState state) + where TState : struct, Enum { - _conditions.Add((_, _) => condition()); - return this; + var stage = new OnEnterStage(state, $"__pvt_on_enter_{typeof(TState).ToString()}.{Enum.GetName(state)}", false); + return stage; } - public FuncSystem RunAfter(FuncSystem parent) + public static Stage OnExit(TState state) + where TState : struct, Enum { - if (this == parent || Contains(parent, s => s._after)) - throw new InvalidOperationException("Circular dependency detected"); + var stage = new OnExitStage(state, $"__pvt_on_exit_{typeof(TState).ToString()}.{Enum.GetName(state)}", false); + return stage; + } +} + +public interface IStateStage +{ + ITinySystem CreateSystem(ITinySystem sys); +} - Node?.List?.Remove(Node); - Node = parent._after.AddLast(this); +public interface IStateEnter : IStateStage { } +public interface IStateExit : IStateStage { } + +internal sealed class OnEnterStage(TState state, string name, bool runOnce = false) : Stage(name, runOnce), IStateEnter + where TState : struct, Enum +{ + public ITinySystem CreateSystem(ITinySystem sys) + => new TinyOnEnterSystem(state, sys); +} + +internal sealed class OnExitStage(TState state, string name, bool runOnce = false) : Stage(name, runOnce), IStateExit + where TState : struct, Enum +{ + public ITinySystem CreateSystem(ITinySystem sys) + => new TinyOnExitSystem(state, sys); +} - return this; - } - public FuncSystem RunAfter(params ReadOnlySpan> systems) +internal sealed class StageHandler(Stage stage) +{ + private bool _initialized; + + public Stage Stage { get; } = stage; + internal List Systems { get; } = []; + + + public void AddSystem(ITinySystem system) + => Systems.Add(system); + + public void Initialize(RunHandler runner, World world) { - foreach (var system in systems) - system.RunAfter(this); + if (!_initialized) + { + runner.Initialize(Systems, world); - return this; + _initialized = true; + } } - public FuncSystem RunBefore(FuncSystem parent) + public void Run(RunHandler runner, World world, uint ticks) { - if (this == parent || Contains(parent, s => s._before)) - throw new InvalidOperationException("Circular dependency detected"); + runner.Run(Systems, world, ticks); - Node?.List?.Remove(Node); - Node = parent._before.AddLast(this); + if (Stage.RunOnce) + Systems.Clear(); + } +} - return this; +internal interface IRunHandler +{ + void Initialize(IEnumerable systems, World world); + void Run(IEnumerable systems, World world, uint ticks); +} + +internal sealed class RunHandler : IRunHandler +{ + private readonly List _singleThreads = new(); + private readonly List _multiThreads = new(); + + private static readonly int ProcessorCount = Environment.ProcessorCount; + + public void Initialize(IEnumerable systems, World world) + { + foreach (var sys in systems) + sys.Initialize(world); } - public FuncSystem RunBefore(params ReadOnlySpan> systems) + public void Run(IEnumerable systems, World world, uint ticks) { - foreach (var system in systems) - system.RunBefore(this); + _singleThreads.Clear(); + _multiThreads.Clear(); - return this; + foreach (var sys in systems) + { + if (ProcessorCount <= 1 || sys.ParamsAreLocked()) + { + _singleThreads.Add(sys); + } + else + { + _multiThreads.Add(sys); + } + } + + if (_multiThreads.Count != 0) + Parallel.ForEach(_multiThreads, system => system.ExecuteOnReady(world, ticks)); + + foreach (var system in _singleThreads) + system.ExecuteOnReady(world, ticks); + } +} + + +internal sealed class StageContainer +{ + internal List Stages { get; } = new(); + internal Dictionary StageMap { get; } = new(); + + public Stage Get(string name) + { + if (StageMap.TryGetValue(name, out var handler)) + return handler.Stage; + throw new InvalidOperationException($"Stage '{name}' not found."); } - private bool Contains(FuncSystem system, Func, LinkedList>> direction) + internal void Add(Stage stage) { - var current = this; - while (current != null) + if (!Contains(stage)) { - if (current == system) - return true; - - var nextNode = direction(current)?.First; - current = nextNode?.Value; + var handler = new StageHandler(stage); + Stages.Add(handler); + StageMap.Add(stage.Name, handler); + } + else + { + throw new InvalidOperationException($"Stage '{stage.Name}' already exists."); } - return false; } - internal bool IsResourceInUse() + public StageHandler AddBeforeOf(Stage parent, Stage stage) { - return _threadingType switch - { - ThreadingMode.Multi => false, - ThreadingMode.Single => true, - _ or ThreadingMode.Auto => _checkInUse() - }; + if (!Contains(parent)) + throw new InvalidOperationException($"Parent stage '{parent.Name}' not found."); + + if (Contains(stage)) + throw new InvalidOperationException($"Stage '{stage.Name}' already exists."); + + var index = Stages.FindIndex(s => s.Stage == parent); + if (index == -1) + throw new InvalidOperationException($"Parent stage '{parent.Name}' not found."); + + var handler = new StageHandler(stage); + Stages.Insert(index, handler); + StageMap.Add(stage.Name, handler); + return handler; } - private bool ValidateConditions(SystemTicks ticks, TArg args) + public StageHandler AddAfterOf(Stage parent, Stage stage) { - foreach (var fn in _conditions) - if (!fn(ticks, args)) - return false; - return true; + if (!Contains(parent)) + throw new InvalidOperationException($"Parent stage '{parent.Name}' not found."); + + if (Contains(stage)) + throw new InvalidOperationException($"Stage '{stage.Name}' already exists."); + + var index = Stages.FindIndex(s => s.Stage == parent); + if (index == -1) + throw new InvalidOperationException($"Parent stage '{parent.Name}' not found."); + + var handler = new StageHandler(stage); + Stages.Insert(index + 1, handler); + StageMap.Add(stage.Name, handler); + return handler; } -} -public enum Stages -{ - Startup, - FrameStart, - BeforeUpdate, - Update, - AfterUpdate, - FrameEnd, + public void AddSystem(ITinySystem system, Stage stage) + { + if (!StageMap.TryGetValue(stage.Name, out var handler)) + { + // TODO: is there a better way to handle these special cases? + // the AddAfterOf makes the current stage to be added on head instead of tail. + if (stage is IStateEnter) + { + handler = AddAfterOf(Stage.OnEnterInner, stage); + } + else if (stage is IStateExit) + { + handler = AddAfterOf(Stage.OnExitInner, stage); + } + else + { + throw new InvalidOperationException($"Stage '{stage.Name}' not found."); + } + } - OnEnter, - OnExit -} + if (stage is IStateStage stStage) + { + system = stStage.CreateSystem(system); + } -public enum ThreadingMode -{ - Auto, - Single, - Multi -} + handler.AddSystem(system); + } -public sealed class SystemTicks -{ - public uint LastRun { get; set; } - public uint ThisRun { get; set; } + private bool Contains(Stage stage) + => StageMap.ContainsKey(stage.Name); } public partial class Scheduler { private readonly World _world; - private readonly LinkedList>[] _systems = new LinkedList>[(int)Stages.OnExit + 1]; - private readonly List> _singleThreads = new(); - private readonly List> _multiThreads = new(); private readonly Dictionary _events = new(); + private readonly StageContainer _stageContainer = new(); + private readonly RunHandler _runHandler = new(); + private bool _initialized; public Scheduler(World world, ThreadingMode threadingMode = ThreadingMode.Auto) { _world = world; ThreadingExecutionMode = threadingMode; - for (var i = 0; i < _systems.Length; ++i) - _systems[i] = new LinkedList>(); + _stageContainer.Add(Stage.Startup); + _stageContainer.Add(Stage.OnExitInner); + _stageContainer.Add(Stage.OnEnterInner); + _stageContainer.Add(Stage.FrameStart); + _stageContainer.Add(Stage.BeforeUpdate); + _stageContainer.Add(Stage.Update); + _stageContainer.Add(Stage.AfterUpdate); + _stageContainer.Add(Stage.FrameEnd); AddSystemParam(world); AddSystemParam(new SchedulerState(this)); @@ -176,6 +297,7 @@ public Scheduler(World world, ThreadingMode threadingMode = ThreadingMode.Auto) public ThreadingMode ThreadingExecutionMode { get; } + public void Run(Func checkForExitFn, Action? cleanupFn = null) { while (!checkForExitFn()) @@ -186,78 +308,113 @@ public void Run(Func checkForExitFn, Action? cleanupFn = null) public void RunOnce() { + if (!_initialized) + { + foreach (var stageHandler in _stageContainer.Stages) + stageHandler.Initialize(_runHandler, _world); + + _initialized = true; + } + var ticks = _world.Update(); foreach ((_, var ev) in _events) ev.Clear(); - RunStage(Stages.Startup, ticks); - _systems[(int)Stages.Startup].Clear(); + foreach (var stageHandler in _stageContainer.Stages) + stageHandler.Run(_runHandler, _world, ticks); + } - RunStage(Stages.OnExit, ticks); - RunStage(Stages.OnEnter, ticks); + public Stage AddStageBeforeOf(string parentStageName, string name, bool oneShot = false) + { + var stage = _stageContainer.Get(parentStageName); + if (stage == null) + throw new InvalidOperationException($"Stage '{parentStageName}' not found."); - for (var stage = Stages.FrameStart; stage <= Stages.FrameEnd; stage += 1) - RunStage(stage, ticks); + return AddStageBeforeOf(stage, name, oneShot); } - private void RunStage(Stages stage, uint ticks) + public Stage AddStageBeforeOf(Stage parent, string name, bool oneShot = false) { - _singleThreads.Clear(); - _multiThreads.Clear(); + var stage = new Stage(name, oneShot); + _stageContainer.AddBeforeOf(parent, stage); - var systems = _systems[(int)stage]; + return stage; + } - if (systems.Count == 0) - return; + public Stage AddStageAfterOf(string parentStageName, string name, bool oneShot = false) + { + var stage = _stageContainer.Get(parentStageName); + if (stage == null) + throw new InvalidOperationException($"Stage '{parentStageName}' not found."); + return AddStageAfterOf(stage, name, oneShot); + } - foreach (var sys in systems) - { - if (sys.IsResourceInUse()) - { - _singleThreads.Add(sys); - } - else - { - _multiThreads.Add(sys); - } - } + public Stage AddStageAfterOf(Stage parent, string name, bool oneShot = false) + { + var stage = new Stage(name, oneShot); + _stageContainer.AddAfterOf(parent, stage); + + return stage; + } + + private void Add(ITinySystem sys, Stages stage) + => Add(sys, GetStage(stage)); + + private void Add(ITinySystem sys, Stage stage) + { + sys.Configuration.ThreadingMode ??= ThreadingExecutionMode; + _stageContainer.AddSystem(sys, stage); + } - var multithreading = _multiThreads; - var singlethreading = _singleThreads; + public Scheduler AddSystem(Stage stage) where T : ITinySystem, new() + { + var system = new T(); + Add(system, stage); + return this; + } - if (multithreading.Count > 0) - Parallel.ForEach(multithreading, s => s.Run(ticks)); + public Scheduler AddSystem(string stageName) where T : ITinySystem, new() + { + var stage = _stageContainer.Get(stageName); + if (stage == null) + throw new InvalidOperationException($"Stage '{stageName}' not found."); + return AddSystem(stage); + } - foreach (var system in singlethreading) - system.Run(ticks); + public Scheduler AddSystems(string stageName, params ITinySystem[] systems) + { + var stage = _stageContainer.Get(stageName); + if (stage == null) + throw new InvalidOperationException($"Stage '{stageName}' not found."); + return AddSystems(stage, systems); } - internal void Add(FuncSystem sys, Stages stage) + public Scheduler AddSystems(Stage stage, params ITinySystem[] systems) { - sys.Node = _systems[(int)stage].AddLast(sys); + foreach (var system in systems) + Add(system, stage); + + return this; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) { if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; - var sys = new FuncSystem(_world, (ticks, args, runIf) => + var sys = new TinyDelegateSystem((args, ticks) => { - if (runIf?.Invoke(ticks, args) ?? true) - { - system(); - return true; - } - return false; - }, () => false, stage, threadingType.Value); + system(); + return true; + }); + sys.Configuration.ThreadingMode = threadingType; Add(sys, stage); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum { if (!threadingType.HasValue) @@ -265,23 +422,20 @@ public FuncSystem OnEnter(TState st, Action system, ThreadingMode var stateChangeId = -1; - var sys = new FuncSystem(_world, (ticks, args, runIf) => + var sys = new TinyDelegateSystem((args, ticks) => { - if (runIf?.Invoke(ticks, args) ?? true) - { - system(); - return true; - } - return false; - }, () => false, Stages.OnEnter, threadingType.Value) + system(); + return true; + }) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum { if (!threadingType.HasValue) @@ -289,26 +443,23 @@ public FuncSystem OnExit(TState st, Action system, ThreadingMode? var stateChangeId = -1; - var sys = new FuncSystem(_world, (ticks, args, runIf) => + var sys = new TinyDelegateSystem((args, ticks) => { - if (runIf?.Invoke(ticks, args) ?? true) - { - system(); - return true; - } - return false; - }, () => false, Stages.OnExit, threadingType.Value) + system(); + return true; + }) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public Scheduler AddPlugin() where T : notnull, IPlugin, new() + public Scheduler AddPlugin() where T : IPlugin, new() => AddPlugin(new T()); - public Scheduler AddPlugin(T plugin) where T : IPlugin + public Scheduler AddPlugin(IPlugin plugin) { plugin.Build(this); @@ -336,14 +487,14 @@ public Scheduler AddResource(T resource) where T : notnull return AddSystemParam(new Res() { Value = resource }); } - public Scheduler AddSystemParam(T param) where T : notnull, ISystemParam + public Scheduler AddSystemParam(T param) where T : ISystemParam { _world.Entity>().Set(new Placeholder() { Value = param }); return this; } - internal bool ResourceExists() where T : notnull, ISystemParam + internal bool ResourceExists() where T : ISystemParam { return _world.Entity>().Has>(); } @@ -354,9 +505,25 @@ internal bool InState(T state) where T : struct, Enum return false; return _world.Entity>>().Get>>().Value.InState(state); } + + private static Stage GetStage(Stages stage) + { + return stage switch + { + Stages.Startup => Stage.Startup, + Stages.FrameStart => Stage.FrameStart, + Stages.BeforeUpdate => Stage.BeforeUpdate, + Stages.Update => Stage.Update, + Stages.AfterUpdate => Stage.AfterUpdate, + Stages.FrameEnd => Stage.FrameEnd, + Stages.OnEnter => Stage.OnEnterInner, + Stages.OnExit => Stage.OnExitInner, + _ => throw new ArgumentOutOfRangeException(nameof(stage), stage, null) + }; + } } -internal struct Placeholder where T : ISystemParam { public T Value; } +internal struct Placeholder where T : ISystemParam { public T Value; } public interface IPlugin @@ -395,7 +562,6 @@ public interface ISystemParam public interface ISystemParam : ISystemParam { - } public interface IIntoSystemParam @@ -494,8 +660,6 @@ public static ISystemParam Generate(World arg) partial class World : SystemParam, IIntoSystemParam { - public World() : this(256) { } - public static ISystemParam Generate(World arg) { return arg; @@ -716,12 +880,11 @@ public sealed class Res : SystemParam, IIntoSystemParam public static ISystemParam Generate(World arg) { - if (arg.Entity>>().Has>>()) - return arg.Entity>>().Get>>().Value; + var ent = arg.Entity>>(); + if (ent.Has>>()) + return ent.Get>>().Value; - var res = new Res(); - arg.Entity>>().Set(new Placeholder>() { Value = res }); - return res; + return null; } public static implicit operator T?(Res reference) @@ -1294,7 +1457,11 @@ internal QueryIter(uint lastRun, uint thisRun, QueryIterator iterator) } [UnscopedRef] - public ref D Current => ref _dataIterator; + public ref D Current + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => ref _dataIterator; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() @@ -1315,4 +1482,352 @@ public bool MoveNext() public readonly QueryIter GetEnumerator() => this; } + +[AttributeUsage(AttributeTargets.Method)] +public sealed class TinySystemAttribute : Attribute +{ +} + +public sealed class SystemParamBuilder(World world) +{ + private readonly List> _params = []; + private readonly List>> _paramsFns = []; + + public T Add() where T : ISystemParam, IIntoSystemParam + { + var param = (T)T.Generate(world); + _params.Add(param); + _paramsFns.Add(() => (T)T.Generate(world)); + return param; + } + + public (ISystemParam[], Func>[]) Build() + => ([.. _params], [.. _paramsFns]); +} + +public sealed class SystemParamRef where T : ISystemParam, IIntoSystemParam +{ + private readonly World _world; + private T? _t; + internal SystemParamRef(World world) => _world = world; + + public T Get() => _t ??= (T)T.Generate(_world); +} + +public sealed class SystemConfiguration +{ + public HashSet Conditionals { get; } = []; + public ThreadingMode? ThreadingMode { get; set; } +} + +public sealed class SystemOrder +{ + public LinkedList BeforeSystems { get; internal set; } = new(); + public LinkedList AfterSystems { get; internal set; } = new(); + public LinkedListNode? Node { get; internal set; } + + + public static ITinySystem Chain(params ITinySystem[] systems) + { + if (systems.Length == 0) + throw new ArgumentException("At least one system is required to create a chain.", nameof(systems)); + + var first = systems[0]; + for (var i = 1; i < systems.Length; i++) + systems[i].RunAfter(first); + return first; + } +} + + +public interface ITinyMeta +{ + ISystemParam[] SystemParams { get; set; } + SystemTicks Ticks { get; } + SystemConfiguration Configuration { get; } + + + bool ParamsAreLocked(); + void Initialize(World world); + bool ExecuteOnReady(World world, uint ticks); + + bool BeforeExecute(World world); + bool AfterExecute(World world); +} + +public interface ITinySystem : ITinyMeta +{ + SystemOrder OrderConfiguration { get; } + + bool ParamsAreReady(); + ITinySystem RunIf() where T : ITinyConditionalSystem, new(); + ITinySystem RunIf(params ITinyConditionalSystem[] conditionals); + ITinySystem RunAfter(ITinySystem sys); + ITinySystem RunBefore(ITinySystem sys); +} + +public interface ITinyConditionalSystem : ITinyMeta +{ +} + + +public abstract class TinySystemBase : ITinyMeta +{ + private bool _initialized; + private Func>[] _paramsFns = []; + + public ISystemParam[] SystemParams { get; set; } = []; + public SystemTicks Ticks { get; } = new(); + public SystemConfiguration Configuration { get; } = new(); + + public virtual void Initialize(World world) + { + if (_initialized) + throw new Exception("Already initialized"); + + _initialized = true; + + var builder = new SystemParamBuilder(world); + Setup(builder); + (SystemParams, _paramsFns) = builder.Build(); + + foreach (var conditional in Configuration.Conditionals) + { + conditional.Initialize(world); + } + } + + public virtual bool BeforeExecute(World world) + => true; + + public virtual bool AfterExecute(World world) + => true; + + public bool ExecuteOnReady(World world, uint ticks) + { + if (!ParamsAreReady()) + { + for (var i = 0; i < SystemParams.Length; i++) + { + if (SystemParams[i] == null && i < _paramsFns.Length) + { + SystemParams[i] = _paramsFns[i](); + } + } + + if (!ParamsAreReady()) + return false; + } + + Ticks.ThisRun = ticks; + var canRun = BeforeExecute(world); + + if (canRun) + { + foreach (var conditional in Configuration.Conditionals) + { + if (!conditional.ExecuteOnReady(world, ticks)) + { + canRun = false; + break; + } + } + + if (canRun) + { + canRun = Execute(world); + } + + if (canRun) + { + canRun = AfterExecute(world); + } + } + + Ticks.LastRun = Ticks.ThisRun; + + return canRun; + } + + public bool ParamsAreReady() + { + foreach (var param in SystemParams) + if (param == null) + return false; + + return true; + } + + public bool ParamsAreLocked() + { + return Configuration.ThreadingMode switch + { + ThreadingMode.Single => true, + ThreadingMode.Multi => false, + _ => SystemParams.Any(static p => p is { UseIndex: > 0 }) + }; + } + + protected void Lock() + { + foreach (var param in SystemParams) + param.Lock(Ticks); + } + + protected void Unlock() + { + foreach (var param in SystemParams) + param.Unlock(); + } + + protected abstract void Setup(SystemParamBuilder builder); + protected abstract bool Execute(World world); +} + +public abstract class TinySystem : TinySystemBase, ITinySystem +{ + public SystemOrder OrderConfiguration { get; } = new(); + + public override void Initialize(World world) + { + base.Initialize(world); + + foreach (var afterSys in OrderConfiguration.AfterSystems) + { + afterSys.Initialize(world); + } + } + + public override bool BeforeExecute(World world) + { + var ticks = Ticks.ThisRun; + foreach (var beforeSys in OrderConfiguration.BeforeSystems) + { + if (!beforeSys.ExecuteOnReady(world, ticks)) + { + return false; + } + } + + return true; + } + + public override bool AfterExecute(World world) + { + var ticks = Ticks.ThisRun; + foreach (var afterSys in OrderConfiguration.AfterSystems) + { + if (!afterSys.ExecuteOnReady(world, ticks)) + { + return false; + } + } + + return true; + } + + + public ITinySystem RunIf() where T : ITinyConditionalSystem, new() + => RunIf(new T()); + + public ITinySystem RunIf(params ITinyConditionalSystem[] conditionals) + { + // TODO: Check for duplicates? + foreach (var sys in conditionals) + _ = Configuration.Conditionals.Add(sys); + return this; + } + + public ITinySystem RunAfter(ITinySystem sys) + { + OrderConfiguration.Node?.List?.Remove(OrderConfiguration.Node); + OrderConfiguration.Node = sys.OrderConfiguration.AfterSystems.AddLast(this); + return this; + } + + public ITinySystem RunBefore(ITinySystem sys) + { + OrderConfiguration.Node?.List?.Remove(OrderConfiguration.Node); + OrderConfiguration.Node = sys.OrderConfiguration.BeforeSystems.AddLast(this); + return this; + } +} + +public abstract class TinyConditionalSystem : TinySystemBase, ITinyConditionalSystem +{ +} + +public sealed partial class TinyDelegateSystem : TinySystem, ITinyConditionalSystem +{ + private readonly Func _fn; + + public TinyDelegateSystem(Func fn) + { + _fn = fn; + } + + protected override void Setup(SystemParamBuilder builder) + { + } + + protected override bool Execute(World world) + { + return _fn(world, Ticks); + } +} + +internal abstract class TinyStateSystemAdapter(ITinySystem sys) : TinySystem + where TState : struct, Enum +{ + protected State _state; + protected int _stateChangedId = -1; + + public override void Initialize(World world) + { + base.Initialize(world); + sys.Initialize(world); + } + + protected override void Setup(SystemParamBuilder builder) + { + _state = builder.Add>(); + } +} + +internal sealed class TinyOnEnterSystem(TState st, ITinySystem sys) : TinyStateSystemAdapter(sys) + where TState : struct, Enum +{ + protected override bool Execute(World world) + { + Lock(); + world.BeginDeferred(); + var result = _state.ShouldEnter(st, ref _stateChangedId); + if (result) + { + _ = sys.ExecuteOnReady(world, Ticks.ThisRun); + } + world.EndDeferred(); + Unlock(); + return result; + } +} + +internal sealed class TinyOnExitSystem(TState st, ITinySystem sys) : TinyStateSystemAdapter(sys) + where TState : struct, Enum +{ + protected override bool Execute(World world) + { + Lock(); + world.BeginDeferred(); + var result = _state.ShouldExit(st, ref _stateChangedId); + if (result) + { + _ = sys.ExecuteOnReady(world, Ticks.ThisRun); + } + world.EndDeferred(); + Unlock(); + return result; + } +} + #endif diff --git a/src/TinyEcs.QueryIteratorEach.g.cs b/src/TinyEcs.QueryIteratorEach.g.cs index 14bb32fe..6120af7b 100644 --- a/src/TinyEcs.QueryIteratorEach.g.cs +++ b/src/TinyEcs.QueryIteratorEach.g.cs @@ -1,4 +1,4 @@ -#pragma warning disable 1591 +#pragma warning disable 1591 #nullable enable using System; diff --git a/src/TinyEcs.Systems.DataAndFilter.g.cs b/src/TinyEcs.Systems.DataAndFilter.g.cs index df6c25c9..e00864e0 100644 --- a/src/TinyEcs.Systems.DataAndFilter.g.cs +++ b/src/TinyEcs.Systems.DataAndFilter.g.cs @@ -1,4 +1,4 @@ -#pragma warning disable 1591 +#pragma warning disable 1591 #nullable enable using System; diff --git a/src/TinyEcs.Systems.Interfaces.g.cs b/src/TinyEcs.Systems.Interfaces.g.cs index 62acf267..25fcf6c1 100644 --- a/src/TinyEcs.Systems.Interfaces.g.cs +++ b/src/TinyEcs.Systems.Interfaces.g.cs @@ -1,4 +1,4 @@ -#pragma warning disable 1591 +#pragma warning disable 1591 #nullable enable using System; @@ -9,87 +9,95 @@ namespace TinyEcs { #if NET9_0_OR_GREATER - public sealed partial class FuncSystem + public sealed partial class TinyDelegateSystem { - public FuncSystem RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; - var fn = (SystemTicks ticks, TArg args) => { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); return condition(obj0); }; - _conditions.Add(fn); + + var sys = new TinyDelegateSystem(fn); + Configuration.Conditionals.Add(sys); return this; } - public FuncSystem RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; - var fn = (SystemTicks ticks, TArg args) => { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); return condition(obj0, obj1); }; - _conditions.Add(fn); + + var sys = new TinyDelegateSystem(fn); + Configuration.Conditionals.Add(sys); return this; } - public FuncSystem RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; T2? obj2 = null; - var fn = (SystemTicks ticks, TArg args) => { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); return condition(obj0, obj1, obj2); }; - _conditions.Add(fn); + + var sys = new TinyDelegateSystem(fn); + Configuration.Conditionals.Add(sys); return this; } - public FuncSystem RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam - where T3 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam + where T3 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; T2? obj2 = null; T3? obj3 = null; - var fn = (SystemTicks ticks, TArg args) => { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); obj3 ??= (T3)T3.Generate(args); return condition(obj0, obj1, obj2, obj3); }; - _conditions.Add(fn); + + var sys = new TinyDelegateSystem(fn); + Configuration.Conditionals.Add(sys); return this; } - public FuncSystem RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam - where T3 : class, ISystemParam, IIntoSystemParam - where T4 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam + where T3 : class, ISystemParam, IIntoSystemParam + where T4 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; T2? obj2 = null; T3? obj3 = null; T4? obj4 = null; - var fn = (SystemTicks ticks, TArg args) => { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -97,17 +105,19 @@ public FuncSystem RunIf(Func obj4 ??= (T4)T4.Generate(args); return condition(obj0, obj1, obj2, obj3, obj4); }; - _conditions.Add(fn); + + var sys = new TinyDelegateSystem(fn); + Configuration.Conditionals.Add(sys); return this; } - public FuncSystem RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam - where T3 : class, ISystemParam, IIntoSystemParam - where T4 : class, ISystemParam, IIntoSystemParam - where T5 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam + where T3 : class, ISystemParam, IIntoSystemParam + where T4 : class, ISystemParam, IIntoSystemParam + where T5 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; @@ -115,7 +125,7 @@ public FuncSystem RunIf(Func { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -124,18 +134,20 @@ public FuncSystem RunIf(Func RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam - where T3 : class, ISystemParam, IIntoSystemParam - where T4 : class, ISystemParam, IIntoSystemParam - where T5 : class, ISystemParam, IIntoSystemParam - where T6 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam + where T3 : class, ISystemParam, IIntoSystemParam + where T4 : class, ISystemParam, IIntoSystemParam + where T5 : class, ISystemParam, IIntoSystemParam + where T6 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; @@ -144,7 +156,7 @@ public FuncSystem RunIf(Func { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -154,19 +166,21 @@ public FuncSystem RunIf(Func RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam - where T3 : class, ISystemParam, IIntoSystemParam - where T4 : class, ISystemParam, IIntoSystemParam - where T5 : class, ISystemParam, IIntoSystemParam - where T6 : class, ISystemParam, IIntoSystemParam - where T7 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam + where T3 : class, ISystemParam, IIntoSystemParam + where T4 : class, ISystemParam, IIntoSystemParam + where T5 : class, ISystemParam, IIntoSystemParam + where T6 : class, ISystemParam, IIntoSystemParam + where T7 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; @@ -176,7 +190,7 @@ public FuncSystem RunIf(Func { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -187,20 +201,22 @@ public FuncSystem RunIf(Func RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam - where T3 : class, ISystemParam, IIntoSystemParam - where T4 : class, ISystemParam, IIntoSystemParam - where T5 : class, ISystemParam, IIntoSystemParam - where T6 : class, ISystemParam, IIntoSystemParam - where T7 : class, ISystemParam, IIntoSystemParam - where T8 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam + where T3 : class, ISystemParam, IIntoSystemParam + where T4 : class, ISystemParam, IIntoSystemParam + where T5 : class, ISystemParam, IIntoSystemParam + where T6 : class, ISystemParam, IIntoSystemParam + where T7 : class, ISystemParam, IIntoSystemParam + where T8 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; @@ -211,7 +227,7 @@ public FuncSystem RunIf(Func { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -223,21 +239,23 @@ public FuncSystem RunIf(Func RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam - where T3 : class, ISystemParam, IIntoSystemParam - where T4 : class, ISystemParam, IIntoSystemParam - where T5 : class, ISystemParam, IIntoSystemParam - where T6 : class, ISystemParam, IIntoSystemParam - where T7 : class, ISystemParam, IIntoSystemParam - where T8 : class, ISystemParam, IIntoSystemParam - where T9 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam + where T3 : class, ISystemParam, IIntoSystemParam + where T4 : class, ISystemParam, IIntoSystemParam + where T5 : class, ISystemParam, IIntoSystemParam + where T6 : class, ISystemParam, IIntoSystemParam + where T7 : class, ISystemParam, IIntoSystemParam + where T8 : class, ISystemParam, IIntoSystemParam + where T9 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; @@ -249,7 +267,7 @@ public FuncSystem RunIf(Func { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -262,22 +280,24 @@ public FuncSystem RunIf(Func RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam - where T3 : class, ISystemParam, IIntoSystemParam - where T4 : class, ISystemParam, IIntoSystemParam - where T5 : class, ISystemParam, IIntoSystemParam - where T6 : class, ISystemParam, IIntoSystemParam - where T7 : class, ISystemParam, IIntoSystemParam - where T8 : class, ISystemParam, IIntoSystemParam - where T9 : class, ISystemParam, IIntoSystemParam - where T10 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam + where T3 : class, ISystemParam, IIntoSystemParam + where T4 : class, ISystemParam, IIntoSystemParam + where T5 : class, ISystemParam, IIntoSystemParam + where T6 : class, ISystemParam, IIntoSystemParam + where T7 : class, ISystemParam, IIntoSystemParam + where T8 : class, ISystemParam, IIntoSystemParam + where T9 : class, ISystemParam, IIntoSystemParam + where T10 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; @@ -290,7 +310,7 @@ public FuncSystem RunIf(Func< T8? obj8 = null; T9? obj9 = null; T10? obj10 = null; - var fn = (SystemTicks ticks, TArg args) => { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -304,23 +324,25 @@ public FuncSystem RunIf(Func< obj10 ??= (T10)T10.Generate(args); return condition(obj0, obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8, obj9, obj10); }; - _conditions.Add(fn); + + var sys = new TinyDelegateSystem(fn); + Configuration.Conditionals.Add(sys); return this; } - public FuncSystem RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam - where T3 : class, ISystemParam, IIntoSystemParam - where T4 : class, ISystemParam, IIntoSystemParam - where T5 : class, ISystemParam, IIntoSystemParam - where T6 : class, ISystemParam, IIntoSystemParam - where T7 : class, ISystemParam, IIntoSystemParam - where T8 : class, ISystemParam, IIntoSystemParam - where T9 : class, ISystemParam, IIntoSystemParam - where T10 : class, ISystemParam, IIntoSystemParam - where T11 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam + where T3 : class, ISystemParam, IIntoSystemParam + where T4 : class, ISystemParam, IIntoSystemParam + where T5 : class, ISystemParam, IIntoSystemParam + where T6 : class, ISystemParam, IIntoSystemParam + where T7 : class, ISystemParam, IIntoSystemParam + where T8 : class, ISystemParam, IIntoSystemParam + where T9 : class, ISystemParam, IIntoSystemParam + where T10 : class, ISystemParam, IIntoSystemParam + where T11 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; @@ -334,7 +356,7 @@ public FuncSystem RunIf( T9? obj9 = null; T10? obj10 = null; T11? obj11 = null; - var fn = (SystemTicks ticks, TArg args) => { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -349,24 +371,26 @@ public FuncSystem RunIf( obj11 ??= (T11)T11.Generate(args); return condition(obj0, obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8, obj9, obj10, obj11); }; - _conditions.Add(fn); + + var sys = new TinyDelegateSystem(fn); + Configuration.Conditionals.Add(sys); return this; } - public FuncSystem RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam - where T3 : class, ISystemParam, IIntoSystemParam - where T4 : class, ISystemParam, IIntoSystemParam - where T5 : class, ISystemParam, IIntoSystemParam - where T6 : class, ISystemParam, IIntoSystemParam - where T7 : class, ISystemParam, IIntoSystemParam - where T8 : class, ISystemParam, IIntoSystemParam - where T9 : class, ISystemParam, IIntoSystemParam - where T10 : class, ISystemParam, IIntoSystemParam - where T11 : class, ISystemParam, IIntoSystemParam - where T12 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam + where T3 : class, ISystemParam, IIntoSystemParam + where T4 : class, ISystemParam, IIntoSystemParam + where T5 : class, ISystemParam, IIntoSystemParam + where T6 : class, ISystemParam, IIntoSystemParam + where T7 : class, ISystemParam, IIntoSystemParam + where T8 : class, ISystemParam, IIntoSystemParam + where T9 : class, ISystemParam, IIntoSystemParam + where T10 : class, ISystemParam, IIntoSystemParam + where T11 : class, ISystemParam, IIntoSystemParam + where T12 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; @@ -381,7 +405,7 @@ public FuncSystem RunIf { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -397,25 +421,27 @@ public FuncSystem RunIf RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam - where T3 : class, ISystemParam, IIntoSystemParam - where T4 : class, ISystemParam, IIntoSystemParam - where T5 : class, ISystemParam, IIntoSystemParam - where T6 : class, ISystemParam, IIntoSystemParam - where T7 : class, ISystemParam, IIntoSystemParam - where T8 : class, ISystemParam, IIntoSystemParam - where T9 : class, ISystemParam, IIntoSystemParam - where T10 : class, ISystemParam, IIntoSystemParam - where T11 : class, ISystemParam, IIntoSystemParam - where T12 : class, ISystemParam, IIntoSystemParam - where T13 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam + where T3 : class, ISystemParam, IIntoSystemParam + where T4 : class, ISystemParam, IIntoSystemParam + where T5 : class, ISystemParam, IIntoSystemParam + where T6 : class, ISystemParam, IIntoSystemParam + where T7 : class, ISystemParam, IIntoSystemParam + where T8 : class, ISystemParam, IIntoSystemParam + where T9 : class, ISystemParam, IIntoSystemParam + where T10 : class, ISystemParam, IIntoSystemParam + where T11 : class, ISystemParam, IIntoSystemParam + where T12 : class, ISystemParam, IIntoSystemParam + where T13 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; @@ -431,7 +457,7 @@ public FuncSystem RunIf { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -448,26 +474,28 @@ public FuncSystem RunIf RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam - where T3 : class, ISystemParam, IIntoSystemParam - where T4 : class, ISystemParam, IIntoSystemParam - where T5 : class, ISystemParam, IIntoSystemParam - where T6 : class, ISystemParam, IIntoSystemParam - where T7 : class, ISystemParam, IIntoSystemParam - where T8 : class, ISystemParam, IIntoSystemParam - where T9 : class, ISystemParam, IIntoSystemParam - where T10 : class, ISystemParam, IIntoSystemParam - where T11 : class, ISystemParam, IIntoSystemParam - where T12 : class, ISystemParam, IIntoSystemParam - where T13 : class, ISystemParam, IIntoSystemParam - where T14 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam + where T3 : class, ISystemParam, IIntoSystemParam + where T4 : class, ISystemParam, IIntoSystemParam + where T5 : class, ISystemParam, IIntoSystemParam + where T6 : class, ISystemParam, IIntoSystemParam + where T7 : class, ISystemParam, IIntoSystemParam + where T8 : class, ISystemParam, IIntoSystemParam + where T9 : class, ISystemParam, IIntoSystemParam + where T10 : class, ISystemParam, IIntoSystemParam + where T11 : class, ISystemParam, IIntoSystemParam + where T12 : class, ISystemParam, IIntoSystemParam + where T13 : class, ISystemParam, IIntoSystemParam + where T14 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; @@ -484,7 +512,7 @@ public FuncSystem RunIf { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -502,27 +530,29 @@ public FuncSystem RunIf RunIf(Func condition) - where T0 : class, ISystemParam, IIntoSystemParam - where T1 : class, ISystemParam, IIntoSystemParam - where T2 : class, ISystemParam, IIntoSystemParam - where T3 : class, ISystemParam, IIntoSystemParam - where T4 : class, ISystemParam, IIntoSystemParam - where T5 : class, ISystemParam, IIntoSystemParam - where T6 : class, ISystemParam, IIntoSystemParam - where T7 : class, ISystemParam, IIntoSystemParam - where T8 : class, ISystemParam, IIntoSystemParam - where T9 : class, ISystemParam, IIntoSystemParam - where T10 : class, ISystemParam, IIntoSystemParam - where T11 : class, ISystemParam, IIntoSystemParam - where T12 : class, ISystemParam, IIntoSystemParam - where T13 : class, ISystemParam, IIntoSystemParam - where T14 : class, ISystemParam, IIntoSystemParam - where T15 : class, ISystemParam, IIntoSystemParam + public ITinySystem RunIf(Func condition) + where T0 : class, ISystemParam, IIntoSystemParam + where T1 : class, ISystemParam, IIntoSystemParam + where T2 : class, ISystemParam, IIntoSystemParam + where T3 : class, ISystemParam, IIntoSystemParam + where T4 : class, ISystemParam, IIntoSystemParam + where T5 : class, ISystemParam, IIntoSystemParam + where T6 : class, ISystemParam, IIntoSystemParam + where T7 : class, ISystemParam, IIntoSystemParam + where T8 : class, ISystemParam, IIntoSystemParam + where T9 : class, ISystemParam, IIntoSystemParam + where T10 : class, ISystemParam, IIntoSystemParam + where T11 : class, ISystemParam, IIntoSystemParam + where T12 : class, ISystemParam, IIntoSystemParam + where T13 : class, ISystemParam, IIntoSystemParam + where T14 : class, ISystemParam, IIntoSystemParam + where T15 : class, ISystemParam, IIntoSystemParam { T0? obj0 = null; T1? obj1 = null; @@ -540,7 +570,7 @@ public FuncSystem RunIf { + var fn = (World args, SystemTicks ticks) => { obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -559,7 +589,9 @@ public FuncSystem RunIf + public sealed partial class TinyDelegateSystem { <# for (var i = 0; i < MAX_GENERICS; ++i) { var genericsArgs = GenerateSequence(i + 1, ", ", j => $"T{j}"); - var genericsArgsWhere = GenerateSequence(i + 1, "\n\t\t\t", j => $"where T{j} : class, ISystemParam, IIntoSystemParam"); + var genericsArgsWhere = GenerateSequence(i + 1, "\n\t\t\t", j => $"where T{j} : class, ISystemParam, IIntoSystemParam"); var objs = GenerateSequence(i + 1, "\n\t\t\t", j => $"T{j}? obj{j} = null;"); var objsGen = GenerateSequence(i + 1, "\n\t\t\t\t", j => $"obj{j} ??= (T{j})T{j}.Generate(args);"); var systemCall = GenerateSequence(i + 1, ", ", j => $"obj{j}"); var objsCheckInuse = GenerateSequence(i + 1, " ", j => $"obj{j}?.UseIndex != 0" + (j < i ? "||" : "")); #> - public FuncSystem RunIf<<#= genericsArgs #>>(Func<<#= genericsArgs #>, bool> condition) + public ITinySystem RunIf<<#= genericsArgs #>>(Func<<#= genericsArgs #>, bool> condition) <#= genericsArgsWhere #> { <#= objs #> - var fn = (SystemTicks ticks, TArg args) => { + var fn = (World args, SystemTicks ticks) => { <#= objsGen #> return condition(<#= systemCall #>); }; - _conditions.Add(fn); + + var sys = new TinyDelegateSystem(fn); + Configuration.Conditionals.Add(sys); return this; } diff --git a/src/TinyEcs.Systems.Scheduler.g.cs b/src/TinyEcs.Systems.Scheduler.g.cs index 11c52862..e6384acf 100644 --- a/src/TinyEcs.Systems.Scheduler.g.cs +++ b/src/TinyEcs.Systems.Scheduler.g.cs @@ -1,4 +1,4 @@ -#pragma warning disable 1591 +#pragma warning disable 1591 #nullable enable using System; @@ -12,19 +12,15 @@ namespace TinyEcs #if NET9_0_OR_GREATER public partial class Scheduler { - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam { if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; - var checkInuse = () => obj0?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj0.Lock(ticks); args.BeginDeferred(); @@ -33,12 +29,13 @@ public FuncSystem AddSystem(Action system, Stages stage = Stages. obj0.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam { @@ -47,12 +44,8 @@ public FuncSystem AddSystem(Action system, Stages stage = T0? obj0 = null; T1? obj1 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj0.Lock(ticks); @@ -64,12 +57,13 @@ public FuncSystem AddSystem(Action system, Stages stage = obj1.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -80,12 +74,8 @@ public FuncSystem AddSystem(Action system, Stages T0? obj0 = null; T1? obj1 = null; T2? obj2 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -100,12 +90,13 @@ public FuncSystem AddSystem(Action system, Stages obj2.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -118,12 +109,8 @@ public FuncSystem AddSystem(Action system T1? obj1 = null; T2? obj2 = null; T3? obj3 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -141,12 +128,13 @@ public FuncSystem AddSystem(Action system obj3.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -161,12 +149,8 @@ public FuncSystem AddSystem(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -187,12 +171,13 @@ public FuncSystem AddSystem(Action(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -209,12 +194,8 @@ public FuncSystem AddSystem(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -238,12 +219,13 @@ public FuncSystem AddSystem(Action(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -262,12 +244,8 @@ public FuncSystem AddSystem(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -294,12 +272,13 @@ public FuncSystem AddSystem(Action(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -320,12 +299,8 @@ public FuncSystem AddSystem(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -355,12 +330,13 @@ public FuncSystem AddSystem(Action(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -383,12 +359,8 @@ public FuncSystem AddSystem(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -421,12 +393,13 @@ public FuncSystem AddSystem(Action(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -451,12 +424,8 @@ public FuncSystem AddSystem(Actio T7? obj7 = null; T8? obj8 = null; T9? obj9 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -492,12 +461,13 @@ public FuncSystem AddSystem(Actio obj9.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -524,12 +494,8 @@ public FuncSystem AddSystem( T8? obj8 = null; T9? obj9 = null; T10? obj10 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -568,12 +534,13 @@ public FuncSystem AddSystem( obj10.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -602,12 +569,8 @@ public FuncSystem AddSystem obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -649,12 +612,13 @@ public FuncSystem AddSystem(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -685,12 +649,8 @@ public FuncSystem AddSystem obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -735,12 +695,13 @@ public FuncSystem AddSystem(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -773,12 +734,8 @@ public FuncSystem AddSystem obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -826,12 +783,13 @@ public FuncSystem AddSystem(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -866,12 +824,8 @@ public FuncSystem AddSystem obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -922,12 +876,13 @@ public FuncSystem AddSystem(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } - public FuncSystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem(Action system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -964,12 +919,8 @@ public FuncSystem AddSystem obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0|| obj15?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1023,7 +974,8 @@ public FuncSystem AddSystem(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } diff --git a/src/TinyEcs.Systems.Scheduler.tt b/src/TinyEcs.Systems.Scheduler.tt index dbe10f08..4ed0edea 100644 --- a/src/TinyEcs.Systems.Scheduler.tt +++ b/src/TinyEcs.Systems.Scheduler.tt @@ -45,21 +45,16 @@ namespace TinyEcs var objsLock = GenerateSequence(i + 1, "\n\t\t\t\t", j => $"obj{j}.Lock(ticks);"); var objsUnlock = GenerateSequence(i + 1, "\n\t\t\t\t", j => $"obj{j}.Unlock();"); var systemCall = GenerateSequence(i + 1, ", ", j => $"obj{j}"); - var objsCheckInuse = GenerateSequence(i + 1, " ", j => $"obj{j}?.UseIndex != 0" + (j < i ? "||" : "")); #> - public FuncSystem AddSystem<<#= genericsArgs #>>(Action<<#= genericsArgs #>> system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) + public ITinySystem AddSystem<<#= genericsArgs #>>(Action<<#= genericsArgs #>> system, Stages stage = Stages.Update, ThreadingMode? threadingType = null) <#= genericsArgsWhere #> { if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; <#= objs #> - var checkInuse = () => <#= objsCheckInuse #>; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - <#= objsGen #> <#= objsLock #> args.BeginDeferred(); @@ -68,7 +63,8 @@ namespace TinyEcs <#= objsUnlock #> return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, stage, threadingType.Value); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType.Value; Add(sys, stage); return sys; } diff --git a/src/TinyEcs.Systems.StageSpecific.g.cs b/src/TinyEcs.Systems.StageSpecific.g.cs index d954c236..f90a94ae 100644 --- a/src/TinyEcs.Systems.StageSpecific.g.cs +++ b/src/TinyEcs.Systems.StageSpecific.g.cs @@ -1,4 +1,4 @@ -#pragma warning disable 1591 +#pragma warning disable 1591 #nullable enable using System; @@ -12,19 +12,15 @@ namespace TinyEcs #if NET9_0_OR_GREATER public partial class Scheduler { - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam { if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; - var checkInuse = () => obj0?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj0.Lock(ticks); args.BeginDeferred(); @@ -33,12 +29,13 @@ public FuncSystem OnStartup(Action system, ThreadingMode? threadi obj0.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam { @@ -47,12 +44,8 @@ public FuncSystem OnStartup(Action system, ThreadingMode? T0? obj0 = null; T1? obj1 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj0.Lock(ticks); @@ -64,12 +57,13 @@ public FuncSystem OnStartup(Action system, ThreadingMode? obj1.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -80,12 +74,8 @@ public FuncSystem OnStartup(Action system, Thread T0? obj0 = null; T1? obj1 = null; T2? obj2 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -100,12 +90,13 @@ public FuncSystem OnStartup(Action system, Thread obj2.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -118,12 +109,8 @@ public FuncSystem OnStartup(Action system T1? obj1 = null; T2? obj2 = null; T3? obj3 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -141,12 +128,13 @@ public FuncSystem OnStartup(Action system obj3.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -161,12 +149,8 @@ public FuncSystem OnStartup(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -187,12 +171,13 @@ public FuncSystem OnStartup(Action(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -209,12 +194,8 @@ public FuncSystem OnStartup(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -238,12 +219,13 @@ public FuncSystem OnStartup(Action(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -262,12 +244,8 @@ public FuncSystem OnStartup(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -294,12 +272,13 @@ public FuncSystem OnStartup(Action(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -320,12 +299,8 @@ public FuncSystem OnStartup(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -355,12 +330,13 @@ public FuncSystem OnStartup(Action(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -383,12 +359,8 @@ public FuncSystem OnStartup(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -421,12 +393,13 @@ public FuncSystem OnStartup(Action(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -451,12 +424,8 @@ public FuncSystem OnStartup(Actio T7? obj7 = null; T8? obj8 = null; T9? obj9 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -492,12 +461,13 @@ public FuncSystem OnStartup(Actio obj9.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -524,12 +494,8 @@ public FuncSystem OnStartup( T8? obj8 = null; T9? obj9 = null; T10? obj10 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -568,12 +534,13 @@ public FuncSystem OnStartup( obj10.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -602,12 +569,8 @@ public FuncSystem OnStartup obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -649,12 +612,13 @@ public FuncSystem OnStartup(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -685,12 +649,8 @@ public FuncSystem OnStartup obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -735,12 +695,13 @@ public FuncSystem OnStartup(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -773,12 +734,8 @@ public FuncSystem OnStartup obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -826,12 +783,13 @@ public FuncSystem OnStartup(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -866,12 +824,8 @@ public FuncSystem OnStartup obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -922,12 +876,13 @@ public FuncSystem OnStartup(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -964,12 +919,8 @@ public FuncSystem OnStartup obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0|| obj15?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1023,24 +974,21 @@ public FuncSystem OnStartup(_world, fn, checkInuse, Stages.Startup, threadingType.Value); - Add(sys, Stages.Startup); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam { if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; - var checkInuse = () => obj0?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj0.Lock(ticks); args.BeginDeferred(); @@ -1049,12 +997,13 @@ public FuncSystem OnFrameStart(Action system, ThreadingMode? thre obj0.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam { @@ -1063,12 +1012,8 @@ public FuncSystem OnFrameStart(Action system, ThreadingMo T0? obj0 = null; T1? obj1 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj0.Lock(ticks); @@ -1080,12 +1025,13 @@ public FuncSystem OnFrameStart(Action system, ThreadingMo obj1.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1096,12 +1042,8 @@ public FuncSystem OnFrameStart(Action system, Thr T0? obj0 = null; T1? obj1 = null; T2? obj2 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1116,12 +1058,13 @@ public FuncSystem OnFrameStart(Action system, Thr obj2.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1134,12 +1077,8 @@ public FuncSystem OnFrameStart(Action sys T1? obj1 = null; T2? obj2 = null; T3? obj3 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1157,12 +1096,13 @@ public FuncSystem OnFrameStart(Action sys obj3.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1177,12 +1117,8 @@ public FuncSystem OnFrameStart(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1203,12 +1139,13 @@ public FuncSystem OnFrameStart(Action(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1225,12 +1162,8 @@ public FuncSystem OnFrameStart(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1254,12 +1187,13 @@ public FuncSystem OnFrameStart(Action(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1278,12 +1212,8 @@ public FuncSystem OnFrameStart(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1310,12 +1240,13 @@ public FuncSystem OnFrameStart(Action(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1336,12 +1267,8 @@ public FuncSystem OnFrameStart(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1371,12 +1298,13 @@ public FuncSystem OnFrameStart(Action(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1399,12 +1327,8 @@ public FuncSystem OnFrameStart(Action T6? obj6 = null; T7? obj7 = null; T8? obj8 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1437,12 +1361,13 @@ public FuncSystem OnFrameStart(Action obj8.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1467,12 +1392,8 @@ public FuncSystem OnFrameStart(Ac T7? obj7 = null; T8? obj8 = null; T9? obj9 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1508,12 +1429,13 @@ public FuncSystem OnFrameStart(Ac obj9.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1540,12 +1462,8 @@ public FuncSystem OnFrameStart obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1584,12 +1502,13 @@ public FuncSystem OnFrameStart(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1618,12 +1537,8 @@ public FuncSystem OnFrameStart obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1665,12 +1580,13 @@ public FuncSystem OnFrameStart(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1701,12 +1617,8 @@ public FuncSystem OnFrameStart obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1751,12 +1663,13 @@ public FuncSystem OnFrameStart(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1789,12 +1702,8 @@ public FuncSystem OnFrameStart obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1842,12 +1751,13 @@ public FuncSystem OnFrameStart(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1882,12 +1792,8 @@ public FuncSystem OnFrameStart obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1938,12 +1844,13 @@ public FuncSystem OnFrameStart(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -1980,12 +1887,8 @@ public FuncSystem OnFrameStart obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0|| obj15?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2039,24 +1942,21 @@ public FuncSystem OnFrameStart(_world, fn, checkInuse, Stages.FrameStart, threadingType.Value); - Add(sys, Stages.FrameStart); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam { if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; - var checkInuse = () => obj0?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj0.Lock(ticks); args.BeginDeferred(); @@ -2065,12 +1965,13 @@ public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? th obj0.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam { @@ -2079,12 +1980,8 @@ public FuncSystem OnBeforeUpdate(Action system, Threading T0? obj0 = null; T1? obj1 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj0.Lock(ticks); @@ -2096,12 +1993,13 @@ public FuncSystem OnBeforeUpdate(Action system, Threading obj1.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2112,12 +2010,8 @@ public FuncSystem OnBeforeUpdate(Action system, T T0? obj0 = null; T1? obj1 = null; T2? obj2 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2132,12 +2026,13 @@ public FuncSystem OnBeforeUpdate(Action system, T obj2.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2150,12 +2045,8 @@ public FuncSystem OnBeforeUpdate(Action s T1? obj1 = null; T2? obj2 = null; T3? obj3 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2173,12 +2064,13 @@ public FuncSystem OnBeforeUpdate(Action s obj3.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2193,12 +2085,8 @@ public FuncSystem OnBeforeUpdate(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2219,12 +2107,13 @@ public FuncSystem OnBeforeUpdate(Action(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2241,12 +2130,8 @@ public FuncSystem OnBeforeUpdate(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2270,12 +2155,13 @@ public FuncSystem OnBeforeUpdate(Action(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2294,12 +2180,8 @@ public FuncSystem OnBeforeUpdate(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2326,12 +2208,13 @@ public FuncSystem OnBeforeUpdate(Action(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2352,12 +2235,8 @@ public FuncSystem OnBeforeUpdate(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2387,12 +2266,13 @@ public FuncSystem OnBeforeUpdate(Action(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2415,12 +2295,8 @@ public FuncSystem OnBeforeUpdate(Acti T6? obj6 = null; T7? obj7 = null; T8? obj8 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2453,12 +2329,13 @@ public FuncSystem OnBeforeUpdate(Acti obj8.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2483,12 +2360,8 @@ public FuncSystem OnBeforeUpdate( T7? obj7 = null; T8? obj8 = null; T9? obj9 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2524,12 +2397,13 @@ public FuncSystem OnBeforeUpdate( obj9.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2556,12 +2430,8 @@ public FuncSystem OnBeforeUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2600,12 +2470,13 @@ public FuncSystem OnBeforeUpdate(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2634,12 +2505,8 @@ public FuncSystem OnBeforeUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2681,12 +2548,13 @@ public FuncSystem OnBeforeUpdate(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2717,12 +2585,8 @@ public FuncSystem OnBeforeUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2767,12 +2631,13 @@ public FuncSystem OnBeforeUpdate(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2805,12 +2670,8 @@ public FuncSystem OnBeforeUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2858,12 +2719,13 @@ public FuncSystem OnBeforeUpdate(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2898,12 +2760,8 @@ public FuncSystem OnBeforeUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2954,12 +2812,13 @@ public FuncSystem OnBeforeUpdate(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -2996,12 +2855,8 @@ public FuncSystem OnBeforeUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0|| obj15?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3055,24 +2910,21 @@ public FuncSystem OnBeforeUpdate(_world, fn, checkInuse, Stages.BeforeUpdate, threadingType.Value); - Add(sys, Stages.BeforeUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam { if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; - var checkInuse = () => obj0?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj0.Lock(ticks); args.BeginDeferred(); @@ -3081,12 +2933,13 @@ public FuncSystem OnUpdate(Action system, ThreadingMode? threadin obj0.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam { @@ -3095,12 +2948,8 @@ public FuncSystem OnUpdate(Action system, ThreadingMode? T0? obj0 = null; T1? obj1 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj0.Lock(ticks); @@ -3112,12 +2961,13 @@ public FuncSystem OnUpdate(Action system, ThreadingMode? obj1.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -3128,12 +2978,8 @@ public FuncSystem OnUpdate(Action system, Threadi T0? obj0 = null; T1? obj1 = null; T2? obj2 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3148,12 +2994,13 @@ public FuncSystem OnUpdate(Action system, Threadi obj2.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -3166,12 +3013,8 @@ public FuncSystem OnUpdate(Action system, T1? obj1 = null; T2? obj2 = null; T3? obj3 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3189,12 +3032,13 @@ public FuncSystem OnUpdate(Action system, obj3.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -3209,12 +3053,8 @@ public FuncSystem OnUpdate(Action T2? obj2 = null; T3? obj3 = null; T4? obj4 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3235,12 +3075,13 @@ public FuncSystem OnUpdate(Action obj4.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -3257,12 +3098,8 @@ public FuncSystem OnUpdate(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3286,12 +3123,13 @@ public FuncSystem OnUpdate(Action(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -3310,12 +3148,8 @@ public FuncSystem OnUpdate(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3342,12 +3176,13 @@ public FuncSystem OnUpdate(Action(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -3368,12 +3203,8 @@ public FuncSystem OnUpdate(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3403,12 +3234,13 @@ public FuncSystem OnUpdate(Action(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -3431,12 +3263,8 @@ public FuncSystem OnUpdate(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3469,12 +3297,13 @@ public FuncSystem OnUpdate(Action(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -3499,12 +3328,8 @@ public FuncSystem OnUpdate(Action T7? obj7 = null; T8? obj8 = null; T9? obj9 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3540,12 +3365,13 @@ public FuncSystem OnUpdate(Action obj9.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -3572,12 +3398,8 @@ public FuncSystem OnUpdate(A T8? obj8 = null; T9? obj9 = null; T10? obj10 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3616,12 +3438,13 @@ public FuncSystem OnUpdate(A obj10.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -3650,12 +3473,8 @@ public FuncSystem OnUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3697,12 +3516,13 @@ public FuncSystem OnUpdate(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -3733,12 +3553,8 @@ public FuncSystem OnUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3783,12 +3599,13 @@ public FuncSystem OnUpdate(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -3821,12 +3638,8 @@ public FuncSystem OnUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3874,12 +3687,13 @@ public FuncSystem OnUpdate(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -3914,12 +3728,8 @@ public FuncSystem OnUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -3970,12 +3780,13 @@ public FuncSystem OnUpdate(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4012,12 +3823,8 @@ public FuncSystem OnUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0|| obj15?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4071,24 +3878,21 @@ public FuncSystem OnUpdate(_world, fn, checkInuse, Stages.Update, threadingType.Value); - Add(sys, Stages.Update); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam { if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; - var checkInuse = () => obj0?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj0.Lock(ticks); args.BeginDeferred(); @@ -4097,12 +3901,13 @@ public FuncSystem OnAfterUpdate(Action system, ThreadingMode? thr obj0.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam { @@ -4111,12 +3916,8 @@ public FuncSystem OnAfterUpdate(Action system, ThreadingM T0? obj0 = null; T1? obj1 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj0.Lock(ticks); @@ -4128,12 +3929,13 @@ public FuncSystem OnAfterUpdate(Action system, ThreadingM obj1.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4144,12 +3946,8 @@ public FuncSystem OnAfterUpdate(Action system, Th T0? obj0 = null; T1? obj1 = null; T2? obj2 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4164,12 +3962,13 @@ public FuncSystem OnAfterUpdate(Action system, Th obj2.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4182,12 +3981,8 @@ public FuncSystem OnAfterUpdate(Action sy T1? obj1 = null; T2? obj2 = null; T3? obj3 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4205,12 +4000,13 @@ public FuncSystem OnAfterUpdate(Action sy obj3.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4225,12 +4021,8 @@ public FuncSystem OnAfterUpdate(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4251,12 +4043,13 @@ public FuncSystem OnAfterUpdate(Action(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4273,12 +4066,8 @@ public FuncSystem OnAfterUpdate(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4302,12 +4091,13 @@ public FuncSystem OnAfterUpdate(Action(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4326,12 +4116,8 @@ public FuncSystem OnAfterUpdate(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4358,12 +4144,13 @@ public FuncSystem OnAfterUpdate(Action(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4384,12 +4171,8 @@ public FuncSystem OnAfterUpdate(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4419,12 +4202,13 @@ public FuncSystem OnAfterUpdate(Action(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4447,12 +4231,8 @@ public FuncSystem OnAfterUpdate(Actio T6? obj6 = null; T7? obj7 = null; T8? obj8 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4485,12 +4265,13 @@ public FuncSystem OnAfterUpdate(Actio obj8.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4515,12 +4296,8 @@ public FuncSystem OnAfterUpdate(A T7? obj7 = null; T8? obj8 = null; T9? obj9 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4556,12 +4333,13 @@ public FuncSystem OnAfterUpdate(A obj9.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4588,12 +4366,8 @@ public FuncSystem OnAfterUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4632,12 +4406,13 @@ public FuncSystem OnAfterUpdate(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4666,12 +4441,8 @@ public FuncSystem OnAfterUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4713,12 +4484,13 @@ public FuncSystem OnAfterUpdate(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4749,12 +4521,8 @@ public FuncSystem OnAfterUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4799,12 +4567,13 @@ public FuncSystem OnAfterUpdate(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4837,12 +4606,8 @@ public FuncSystem OnAfterUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4890,12 +4655,13 @@ public FuncSystem OnAfterUpdate(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -4930,12 +4696,8 @@ public FuncSystem OnAfterUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -4986,12 +4748,13 @@ public FuncSystem OnAfterUpdate(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5028,12 +4791,8 @@ public FuncSystem OnAfterUpdate obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0|| obj15?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -5087,24 +4846,21 @@ public FuncSystem OnAfterUpdate(_world, fn, checkInuse, Stages.AfterUpdate, threadingType.Value); - Add(sys, Stages.AfterUpdate); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam { if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; - var checkInuse = () => obj0?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj0.Lock(ticks); args.BeginDeferred(); @@ -5113,12 +4869,13 @@ public FuncSystem OnFrameEnd(Action system, ThreadingMode? thread obj0.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam { @@ -5127,12 +4884,8 @@ public FuncSystem OnFrameEnd(Action system, ThreadingMode T0? obj0 = null; T1? obj1 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj0.Lock(ticks); @@ -5144,12 +4897,13 @@ public FuncSystem OnFrameEnd(Action system, ThreadingMode obj1.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5160,12 +4914,8 @@ public FuncSystem OnFrameEnd(Action system, Threa T0? obj0 = null; T1? obj1 = null; T2? obj2 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -5180,12 +4930,13 @@ public FuncSystem OnFrameEnd(Action system, Threa obj2.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5198,12 +4949,8 @@ public FuncSystem OnFrameEnd(Action syste T1? obj1 = null; T2? obj2 = null; T3? obj3 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -5221,12 +4968,13 @@ public FuncSystem OnFrameEnd(Action syste obj3.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5241,12 +4989,8 @@ public FuncSystem OnFrameEnd(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -5267,12 +5011,13 @@ public FuncSystem OnFrameEnd(Action(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5289,12 +5034,8 @@ public FuncSystem OnFrameEnd(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -5318,12 +5059,13 @@ public FuncSystem OnFrameEnd(Action(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5342,12 +5084,8 @@ public FuncSystem OnFrameEnd(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -5374,12 +5112,13 @@ public FuncSystem OnFrameEnd(Action(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5400,12 +5139,8 @@ public FuncSystem OnFrameEnd(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -5435,12 +5170,13 @@ public FuncSystem OnFrameEnd(Action(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5463,12 +5199,8 @@ public FuncSystem OnFrameEnd(Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -5501,12 +5233,13 @@ public FuncSystem OnFrameEnd(Action(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5531,12 +5264,8 @@ public FuncSystem OnFrameEnd(Acti T7? obj7 = null; T8? obj8 = null; T9? obj9 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -5572,12 +5301,13 @@ public FuncSystem OnFrameEnd(Acti obj9.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5604,12 +5334,8 @@ public FuncSystem OnFrameEnd T8? obj8 = null; T9? obj9 = null; T10? obj10 = null; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -5648,12 +5374,13 @@ public FuncSystem OnFrameEnd obj10.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5682,12 +5409,8 @@ public FuncSystem OnFrameEnd obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -5729,12 +5452,13 @@ public FuncSystem OnFrameEnd(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5765,12 +5489,8 @@ public FuncSystem OnFrameEnd obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -5815,12 +5535,13 @@ public FuncSystem OnFrameEnd(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5853,12 +5574,8 @@ public FuncSystem OnFrameEnd obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -5906,12 +5623,13 @@ public FuncSystem OnFrameEnd(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -5946,12 +5664,8 @@ public FuncSystem OnFrameEnd obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -6002,12 +5716,13 @@ public FuncSystem OnFrameEnd(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam @@ -6044,12 +5759,8 @@ public FuncSystem OnFrameEnd obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0|| obj15?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -6103,116 +5814,111 @@ public FuncSystem OnFrameEnd(_world, fn, checkInuse, Stages.FrameEnd, threadingType.Value); - Add(sys, Stages.FrameEnd); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } - public FuncSystem OnStartup(Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnStartup(Action system, ThreadingMode? threadingType = null) { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; - var sys = new FuncSystem(_world, (ticks, args, runIf) => - { - if (runIf?.Invoke(ticks, args) ?? true) - { - system(); - return true; - } - return false; - }, () => false, Stages.Startup, threadingType); - Add(sys, Stages.Startup); + var fn = (World args, SystemTicks ticks) => + { + system(); + return true; + }; + + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Startup); return sys; } - public FuncSystem OnFrameStart(Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnFrameStart(Action system, ThreadingMode? threadingType = null) { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; - var sys = new FuncSystem(_world, (ticks, args, runIf) => - { - if (runIf?.Invoke(ticks, args) ?? true) - { - system(); - return true; - } - return false; - }, () => false, Stages.FrameStart, threadingType); - Add(sys, Stages.FrameStart); + var fn = (World args, SystemTicks ticks) => + { + system(); + return true; + }; + + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameStart); return sys; } - public FuncSystem OnBeforeUpdate(Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnBeforeUpdate(Action system, ThreadingMode? threadingType = null) { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; - var sys = new FuncSystem(_world, (ticks, args, runIf) => - { - if (runIf?.Invoke(ticks, args) ?? true) - { - system(); - return true; - } - return false; - }, () => false, Stages.BeforeUpdate, threadingType); - Add(sys, Stages.BeforeUpdate); + var fn = (World args, SystemTicks ticks) => + { + system(); + return true; + }; + + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.BeforeUpdate); return sys; } - public FuncSystem OnUpdate(Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnUpdate(Action system, ThreadingMode? threadingType = null) { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; - var sys = new FuncSystem(_world, (ticks, args, runIf) => - { - if (runIf?.Invoke(ticks, args) ?? true) - { - system(); - return true; - } - return false; - }, () => false, Stages.Update, threadingType); - Add(sys, Stages.Update); + var fn = (World args, SystemTicks ticks) => + { + system(); + return true; + }; + + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.Update); return sys; } - public FuncSystem OnAfterUpdate(Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnAfterUpdate(Action system, ThreadingMode? threadingType = null) { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; - var sys = new FuncSystem(_world, (ticks, args, runIf) => - { - if (runIf?.Invoke(ticks, args) ?? true) - { - system(); - return true; - } - return false; - }, () => false, Stages.AfterUpdate, threadingType); - Add(sys, Stages.AfterUpdate); + var fn = (World args, SystemTicks ticks) => + { + system(); + return true; + }; + + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.AfterUpdate); return sys; } - public FuncSystem OnFrameEnd(Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnFrameEnd(Action system, ThreadingMode? threadingType = null) { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; - var sys = new FuncSystem(_world, (ticks, args, runIf) => - { - if (runIf?.Invoke(ticks, args) ?? true) - { - system(); - return true; - } - return false; - }, () => false, Stages.FrameEnd, threadingType); - Add(sys, Stages.FrameEnd); + var fn = (World args, SystemTicks ticks) => + { + system(); + return true; + }; + + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.FrameEnd); return sys; } diff --git a/src/TinyEcs.Systems.StageSpecific.tt b/src/TinyEcs.Systems.StageSpecific.tt index 588acaea..3e275f86 100644 --- a/src/TinyEcs.Systems.StageSpecific.tt +++ b/src/TinyEcs.Systems.StageSpecific.tt @@ -57,21 +57,16 @@ namespace TinyEcs var objsLock = GenerateSequence(i + 1, "\n\t\t\t\t", j => $"obj{j}.Lock(ticks);"); var objsUnlock = GenerateSequence(i + 1, "\n\t\t\t\t", j => $"obj{j}.Unlock();"); var systemCall = GenerateSequence(i + 1, ", ", j => $"obj{j}"); - var objsCheckInuse = GenerateSequence(i + 1, " ", j => $"obj{j}?.UseIndex != 0" + (j < i ? "||" : "")); #> - public FuncSystem <#= stage.MethodName #><<#= genericsArgs #>>(Action<<#= genericsArgs #>> system, ThreadingMode? threadingType = null) + public ITinySystem <#= stage.MethodName #><<#= genericsArgs #>>(Action<<#= genericsArgs #>> system, ThreadingMode? threadingType = null) <#= genericsArgsWhere #> { if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; <#= objs #> - var checkInuse = () => <#= objsCheckInuse #>; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - <#= objsGen #> <#= objsLock #> args.BeginDeferred(); @@ -80,8 +75,9 @@ namespace TinyEcs <#= objsUnlock #> return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.<#= stage.StageName #>, threadingType.Value); - Add(sys, Stages.<#= stage.StageName #>); + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.<#= stage.StageName #>); return sys; } @@ -93,21 +89,20 @@ namespace TinyEcs foreach (var stage in stageNames) { #> - public FuncSystem <#= stage.MethodName #>(Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem <#= stage.MethodName #>(Action system, ThreadingMode? threadingType = null) { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; - var sys = new FuncSystem(_world, (ticks, args, runIf) => - { - if (runIf?.Invoke(ticks, args) ?? true) - { - system(); - return true; - } - return false; - }, () => false, Stages.<#= stage.StageName #>, threadingType); - Add(sys, Stages.<#= stage.StageName #>); + var fn = (World args, SystemTicks ticks) => + { + system(); + return true; + }; + + var sys = new TinyDelegateSystem(fn); + sys.Configuration.ThreadingMode = threadingType; + Add(sys, Stage.<#= stage.StageName #>); return sys; } diff --git a/src/TinyEcs.Systems.StateHandlers.g.cs b/src/TinyEcs.Systems.StateHandlers.g.cs index e7f501cf..bd956496 100644 --- a/src/TinyEcs.Systems.StateHandlers.g.cs +++ b/src/TinyEcs.Systems.StateHandlers.g.cs @@ -1,4 +1,4 @@ -#pragma warning disable 1591 +#pragma warning disable 1591 #nullable enable using System; @@ -12,21 +12,17 @@ namespace TinyEcs #if NET9_0_OR_GREATER public partial class Scheduler { - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj0.Lock(ticks); args.BeginDeferred(); @@ -35,27 +31,24 @@ public FuncSystem OnEnter(TState st, Action system, Threa obj0.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj0.Lock(ticks); args.BeginDeferred(); @@ -64,29 +57,26 @@ public FuncSystem OnExit(TState st, Action system, Thread obj0.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; T1? obj1 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj0.Lock(ticks); @@ -98,29 +88,26 @@ public FuncSystem OnEnter(TState st, Action syste obj1.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; T1? obj1 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj0.Lock(ticks); @@ -132,31 +119,28 @@ public FuncSystem OnExit(TState st, Action system obj1.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; T1? obj1 = null; T2? obj2 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -171,31 +155,28 @@ public FuncSystem OnEnter(TState st, Action(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; T1? obj1 = null; T2? obj2 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -210,20 +191,21 @@ public FuncSystem OnExit(TState st, Action(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam where T3 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -231,12 +213,8 @@ public FuncSystem OnEnter(TState st, Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -254,20 +232,21 @@ public FuncSystem OnEnter(TState st, Action(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam where T2 : class, ISystemParam, IIntoSystemParam where T3 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -275,12 +254,8 @@ public FuncSystem OnExit(TState st, Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -298,13 +273,14 @@ public FuncSystem OnExit(TState st, Action(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -312,7 +288,7 @@ public FuncSystem OnEnter(TState st, Action, IIntoSystemParam where T4 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -321,12 +297,8 @@ public FuncSystem OnEnter(TState st, Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -347,13 +319,14 @@ public FuncSystem OnEnter(TState st, Action(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -361,7 +334,7 @@ public FuncSystem OnExit(TState st, Action, IIntoSystemParam where T4 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -370,12 +343,8 @@ public FuncSystem OnExit(TState st, Action obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -396,13 +365,14 @@ public FuncSystem OnExit(TState st, Action(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -411,7 +381,7 @@ public FuncSystem OnEnter(TState st, Acti where T4 : class, ISystemParam, IIntoSystemParam where T5 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -421,12 +391,8 @@ public FuncSystem OnEnter(TState st, Acti T4? obj4 = null; T5? obj5 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -450,13 +416,14 @@ public FuncSystem OnEnter(TState st, Acti obj5.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -465,7 +432,7 @@ public FuncSystem OnExit(TState st, Actio where T4 : class, ISystemParam, IIntoSystemParam where T5 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -475,12 +442,8 @@ public FuncSystem OnExit(TState st, Actio T4? obj4 = null; T5? obj5 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -504,13 +467,14 @@ public FuncSystem OnExit(TState st, Actio obj5.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -520,7 +484,7 @@ public FuncSystem OnEnter(TState st, where T5 : class, ISystemParam, IIntoSystemParam where T6 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -531,12 +495,8 @@ public FuncSystem OnEnter(TState st, T5? obj5 = null; T6? obj6 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -563,13 +523,14 @@ public FuncSystem OnEnter(TState st, obj6.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -579,7 +540,7 @@ public FuncSystem OnExit(TState st, A where T5 : class, ISystemParam, IIntoSystemParam where T6 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -590,12 +551,8 @@ public FuncSystem OnExit(TState st, A T5? obj5 = null; T6? obj6 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -622,13 +579,14 @@ public FuncSystem OnExit(TState st, A obj6.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -639,7 +597,7 @@ public FuncSystem OnEnter(TState where T6 : class, ISystemParam, IIntoSystemParam where T7 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -651,12 +609,8 @@ public FuncSystem OnEnter(TState T6? obj6 = null; T7? obj7 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -686,13 +640,14 @@ public FuncSystem OnEnter(TState obj7.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -703,7 +658,7 @@ public FuncSystem OnExit(TState s where T6 : class, ISystemParam, IIntoSystemParam where T7 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -715,12 +670,8 @@ public FuncSystem OnExit(TState s T6? obj6 = null; T7? obj7 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -750,13 +701,14 @@ public FuncSystem OnExit(TState s obj7.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -768,7 +720,7 @@ public FuncSystem OnEnter(TSt where T7 : class, ISystemParam, IIntoSystemParam where T8 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -781,12 +733,8 @@ public FuncSystem OnEnter(TSt T7? obj7 = null; T8? obj8 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -819,13 +767,14 @@ public FuncSystem OnEnter(TSt obj8.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -837,7 +786,7 @@ public FuncSystem OnExit(TSta where T7 : class, ISystemParam, IIntoSystemParam where T8 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -850,12 +799,8 @@ public FuncSystem OnExit(TSta T7? obj7 = null; T8? obj8 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -888,13 +833,14 @@ public FuncSystem OnExit(TSta obj8.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -907,7 +853,7 @@ public FuncSystem OnEnter where T8 : class, ISystemParam, IIntoSystemParam where T9 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -921,12 +867,8 @@ public FuncSystem OnEnter T8? obj8 = null; T9? obj9 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -962,13 +904,14 @@ public FuncSystem OnEnter obj9.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -981,7 +924,7 @@ public FuncSystem OnExit( where T8 : class, ISystemParam, IIntoSystemParam where T9 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -995,12 +938,8 @@ public FuncSystem OnExit( T8? obj8 = null; T9? obj9 = null; var stateChangeId = -1; - var checkInuse = () => obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1036,13 +975,14 @@ public FuncSystem OnExit( obj9.Unlock(); return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -1056,7 +996,7 @@ public FuncSystem OnEnter, IIntoSystemParam where T10 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -1071,12 +1011,8 @@ public FuncSystem OnEnter obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1115,13 +1051,14 @@ public FuncSystem OnEnter(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -1135,7 +1072,7 @@ public FuncSystem OnExit, IIntoSystemParam where T10 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -1150,12 +1087,8 @@ public FuncSystem OnExit obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1194,13 +1127,14 @@ public FuncSystem OnExit(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -1215,7 +1149,7 @@ public FuncSystem OnEnter, IIntoSystemParam where T11 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -1231,12 +1165,8 @@ public FuncSystem OnEnter obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1278,13 +1208,14 @@ public FuncSystem OnEnter(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -1299,7 +1230,7 @@ public FuncSystem OnExit, IIntoSystemParam where T11 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -1315,12 +1246,8 @@ public FuncSystem OnExit obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1362,13 +1289,14 @@ public FuncSystem OnExit(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -1384,7 +1312,7 @@ public FuncSystem OnEnter, IIntoSystemParam where T12 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -1401,12 +1329,8 @@ public FuncSystem OnEnter obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1451,13 +1375,14 @@ public FuncSystem OnEnter(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -1473,7 +1398,7 @@ public FuncSystem OnExit, IIntoSystemParam where T12 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -1490,12 +1415,8 @@ public FuncSystem OnExit obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1540,13 +1461,14 @@ public FuncSystem OnExit(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -1563,7 +1485,7 @@ public FuncSystem OnEnter, IIntoSystemParam where T13 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -1581,12 +1503,8 @@ public FuncSystem OnEnter obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1634,13 +1552,14 @@ public FuncSystem OnEnter(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -1657,7 +1576,7 @@ public FuncSystem OnExit, IIntoSystemParam where T13 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -1675,12 +1594,8 @@ public FuncSystem OnExit obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1728,13 +1643,14 @@ public FuncSystem OnExit(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -1752,7 +1668,7 @@ public FuncSystem OnEnter, IIntoSystemParam where T14 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -1771,12 +1687,8 @@ public FuncSystem OnEnter obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1827,13 +1739,14 @@ public FuncSystem OnEnter(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -1851,7 +1764,7 @@ public FuncSystem OnExit, IIntoSystemParam where T14 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -1870,12 +1783,8 @@ public FuncSystem OnExit obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -1926,13 +1835,14 @@ public FuncSystem OnExit(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } - public FuncSystem OnEnter(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -1951,7 +1861,7 @@ public FuncSystem OnEnter, IIntoSystemParam where T15 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -1971,12 +1881,8 @@ public FuncSystem OnEnter obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0|| obj15?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2030,13 +1936,14 @@ public FuncSystem OnEnter(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit(TState st, Action system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit(TState st, Action system, ThreadingMode? threadingType = null) where TState : struct, Enum where T0 : class, ISystemParam, IIntoSystemParam where T1 : class, ISystemParam, IIntoSystemParam @@ -2055,7 +1962,7 @@ public FuncSystem OnExit, IIntoSystemParam where T15 : class, ISystemParam, IIntoSystemParam { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; T0? obj0 = null; @@ -2075,12 +1982,8 @@ public FuncSystem OnExit obj0?.UseIndex != 0|| obj1?.UseIndex != 0|| obj2?.UseIndex != 0|| obj3?.UseIndex != 0|| obj4?.UseIndex != 0|| obj5?.UseIndex != 0|| obj6?.UseIndex != 0|| obj7?.UseIndex != 0|| obj8?.UseIndex != 0|| obj9?.UseIndex != 0|| obj10?.UseIndex != 0|| obj11?.UseIndex != 0|| obj12?.UseIndex != 0|| obj13?.UseIndex != 0|| obj14?.UseIndex != 0|| obj15?.UseIndex != 0; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - obj0 ??= (T0)T0.Generate(args); obj1 ??= (T1)T1.Generate(args); obj2 ??= (T2)T2.Generate(args); @@ -2134,9 +2037,10 @@ public FuncSystem OnExit(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } diff --git a/src/TinyEcs.Systems.StateHandlers.tt b/src/TinyEcs.Systems.StateHandlers.tt index 87eac440..56d41915 100644 --- a/src/TinyEcs.Systems.StateHandlers.tt +++ b/src/TinyEcs.Systems.StateHandlers.tt @@ -45,23 +45,18 @@ namespace TinyEcs var objsLock = GenerateSequence(i + 1, "\n\t\t\t\t", j => $"obj{j}.Lock(ticks);"); var objsUnlock = GenerateSequence(i + 1, "\n\t\t\t\t", j => $"obj{j}.Unlock();"); var systemCall = GenerateSequence(i + 1, ", ", j => $"obj{j}"); - var objsCheckInuse = GenerateSequence(i + 1, " ", j => $"obj{j}?.UseIndex != 0" + (j < i ? "||" : "")); #> - public FuncSystem OnEnter>(TState st, Action<<#= genericsArgs #>> system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnEnter>(TState st, Action<<#= genericsArgs #>> system, ThreadingMode? threadingType = null) where TState : struct, Enum <#= genericsArgsWhere #> { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; <#= objs #> var stateChangeId = -1; - var checkInuse = () => <#= objsCheckInuse #>; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - <#= objsGen #> <#= objsLock #> args.BeginDeferred(); @@ -70,27 +65,24 @@ namespace TinyEcs <#= objsUnlock #> return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnEnter, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldEnter(st, ref stateChangeId)); - Add(sys, Stages.OnEnter); + Add(sys, Stage.OnEnterInner); return sys; } - public FuncSystem OnExit>(TState st, Action<<#= genericsArgs #>> system, ThreadingMode threadingType = ThreadingMode.Auto) + public ITinySystem OnExit>(TState st, Action<<#= genericsArgs #>> system, ThreadingMode? threadingType = null) where TState : struct, Enum <#= genericsArgsWhere #> { - if (threadingType == ThreadingMode.Auto) + if (!threadingType.HasValue) threadingType = ThreadingExecutionMode; <#= objs #> var stateChangeId = -1; - var checkInuse = () => <#= objsCheckInuse #>; - var fn = (SystemTicks ticks, World args, Func runIf) => + var fn = (World args, SystemTicks ticks) => { - if (runIf != null && !runIf.Invoke(ticks, args)) - return false; - <#= objsGen #> <#= objsLock #> args.BeginDeferred(); @@ -99,9 +91,10 @@ namespace TinyEcs <#= objsUnlock #> return true; }; - var sys = new FuncSystem(_world, fn, checkInuse, Stages.OnExit, threadingType) + var sys = new TinyDelegateSystem(fn) + { Configuration = { ThreadingMode = threadingType } } .RunIf((State state) => state.ShouldExit(st, ref stateChangeId)); - Add(sys, Stages.OnExit); + Add(sys, Stage.OnExitInner); return sys; } diff --git a/tools/TinyEcs.SourceGenerator/IndentedStringBuilder.cs b/tools/TinyEcs.SourceGenerator/IndentedStringBuilder.cs new file mode 100644 index 00000000..566c2edc --- /dev/null +++ b/tools/TinyEcs.SourceGenerator/IndentedStringBuilder.cs @@ -0,0 +1,460 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Text; + +namespace TinyEcs.SourceGenerator; + +public class IndentedStringBuilder +{ + private const byte IndentSize = 4; + private int _indent; + private bool _indentPending = true; + + private readonly StringBuilder _stringBuilder = new(); + + public StringBuilder Inner => _stringBuilder; + + /// + /// Gets the current indent level. + /// + /// The current indent level. + public virtual int IndentCount + { + get => _indent; + set => _indent = value < 0 ? 0 : value; + } + + /// + /// The current length of the built string. + /// + public virtual int Length + { + get => _stringBuilder.Length; + set => _stringBuilder.Length = value; + } + + /// + /// Appends the current indent and then the given string to the string being built. + /// + /// The string to append. + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder Append(string value) + { + DoIndent(); + + _stringBuilder.Append(value); + + return this; + } + +#if NET + public virtual IndentedStringBuilder Append(ReadOnlySpan value) + { + DoIndent(); + + _stringBuilder.Append(value); + + return this; + } +#endif + + /// + /// Appends the current indent and then the given string to the string being built. + /// + /// The string to append. + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder Append(object value) + { + DoIndent(); + + _stringBuilder.Append(value); + + return this; + } + + /// + /// Appends the current indent and then the given string to the string being built. + /// + /// The string to append. + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder Append(FormattableString value) + { + DoIndent(); + + _stringBuilder.Append(value); + + return this; + } + + /// + /// Appends the current indent and then the given char to the string being built. + /// + /// The char to append. + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder Append(char value) + { + DoIndent(); + + _stringBuilder.Append(value); + + return this; + } + + /// + /// Appends the current indent and then the given char to the string being built. + /// + /// The char to append. + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder Append(int value) + { + DoIndent(); + + _stringBuilder.Append(value); + + return this; + } + + /// + /// Appends the current indent and then the given strings to the string being built. + /// + /// The strings to append. + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder Append(IEnumerable value) + { + DoIndent(); + + foreach (var str in value) + { + _stringBuilder.Append(str); + } + + return this; + } + + /// + /// Appends the current indent and then the given chars to the string being built. + /// + /// The chars to append. + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder Append(IEnumerable value) + { + DoIndent(); + + foreach (var chr in value) + { + _stringBuilder.Append(chr); + } + + return this; + } + + /// + /// Appends a new line to the string being built. + /// + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder AppendLine() + { + AppendLine(string.Empty); + + return this; + } + + /// + /// Appends the current indent, the given string, and a new line to the string being built. + /// + /// + /// If the given string itself contains a new line, the part of the string after that new line will not be indented. + /// + /// The string to append. + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder AppendLine(string value) + { + if (value.Length != 0) + { + DoIndent(); + } + + _stringBuilder.AppendLine(value); + + _indentPending = true; + + return this; + } + + /// + /// Appends the current indent, the given string, and a new line to the string being built. + /// + /// The string to append. + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder AppendLine(FormattableString value) + { + DoIndent(); + + _stringBuilder.Append(value); + + _indentPending = true; + + return this; + } + + /// + /// Separates the given string into lines, and then appends each line, prefixed + /// by the current indent and followed by a new line, to the string being built. + /// + /// The string to append. + /// If , then the terminating new line is not added after the last line. + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder AppendLines(string value, bool skipFinalNewline = false) + { + using (var reader = new StringReader(value)) + { + var first = true; + string? line; + while ((line = reader.ReadLine()) != null) + { + if (first) + { + first = false; + } + else + { + AppendLine(); + } + + if (line.Length != 0) + { + Append(line); + } + } + } + + if (!skipFinalNewline) + { + AppendLine(); + } + + return this; + } + + /// + /// Concatenates the members of the given collection, using the specified separator between each member, + /// and then appends the resulting string, + /// + /// The values to concatenate. + /// The separator. + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder AppendJoin( + IEnumerable values, + string separator = ", ") + { + DoIndent(); + + using var enumerator = values.GetEnumerator(); + + if (!enumerator.MoveNext()) + { + return this; + } + + _stringBuilder.Append(enumerator.Current); + + while (enumerator.MoveNext()) + { + _stringBuilder.Append(separator); + _stringBuilder.Append(enumerator.Current); + } + + return this; + } + + /// + /// Concatenates the members of the given collection, using the specified separator between each member, + /// and then appends the resulting string, + /// + /// The values to concatenate. + /// The separator. + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder AppendJoin( + string separator, + params string[] values) + { + DoIndent(); + + for (var i = 0; i < values.Length; i++) + { + if (i > 0) + { + _stringBuilder.Append(separator); + } + + _stringBuilder.Append(values[i]); + } + + return this; + } + + /// + /// Resets this builder ready to build a new string. + /// + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder Clear() + { + _stringBuilder.Clear(); + _indent = 0; + + return this; + } + + /// + /// Increments the indent. + /// + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder IncrementIndent() + { + _indent++; + + return this; + } + + /// + /// Decrements the indent. + /// + /// This builder so that additional calls can be chained. + public virtual IndentedStringBuilder DecrementIndent() + { + if (_indent > 0) + { + _indent--; + } + + return this; + } + + /// + /// Creates a scoped indenter that will increment the indent, then decrement it when disposed. + /// + /// An indenter. + public virtual IDisposable Block() + { + AppendLine("{"); + return new Indenter(this, "}"); + } + + public virtual IDisposable Block(string startText, string endText) + { + AppendLine(startText); + return new Indenter(this, endText); + } + + public virtual IDisposable Block(string endText) + { + return new Indenter(this, endText); + } + + /// + /// Creates a scoped indenter that will increment the indent, then decrement it when disposed. + /// + /// An indenter. + public virtual IDisposable Indent() + => new Indenter(this); + + /// + /// Temporarily disables all indentation. Restores the original indentation when the returned object is disposed. + /// + /// An object that restores the original indentation when disposed. + public virtual IDisposable SuspendIndent() + => new IndentSuspender(this); + + /// + /// Clones this , copying the built string and current indent level. + /// + /// New instance of . + public virtual IndentedStringBuilder Clone() + { + var result = new IndentedStringBuilder(); + result._stringBuilder.Append(_stringBuilder); + result._indent = _indent; + result._indentPending = _indentPending; + return result; + } + + /// + /// Returns the built string. + /// + /// The built string. + public override string ToString() + => _stringBuilder.ToString(); + + private void DoIndent() + { + if (_indentPending && _indent > 0) + { + _stringBuilder.Append(' ', _indent * IndentSize); + } + + _indentPending = false; + } + + public Resetter CreateResetter() => new(this); + + private sealed class Indenter : IDisposable + { + private readonly IndentedStringBuilder _stringBuilder; + private readonly string? _closeText; + + public Indenter(IndentedStringBuilder stringBuilder, string? closeText = null) + { + _stringBuilder = stringBuilder; + _closeText = closeText; + + _stringBuilder.IncrementIndent(); + } + + public void Dispose() + { + _stringBuilder.DecrementIndent(); + + if (_closeText is not null) + { + _stringBuilder.AppendLine(_closeText); + } + } + } + + private sealed class IndentSuspender : IDisposable + { + private readonly IndentedStringBuilder _stringBuilder; + private readonly int _indent; + + public IndentSuspender(IndentedStringBuilder stringBuilder) + { + _stringBuilder = stringBuilder; + _indent = _stringBuilder._indent; + _stringBuilder._indent = 0; + } + + public void Dispose() + => _stringBuilder._indent = _indent; + } + + public struct Resetter + { + private readonly IndentedStringBuilder _builder; + private readonly int _length; + private readonly int _indent; + + public Resetter(IndentedStringBuilder builder) + { + _builder = builder; + _length = builder.Length; + _indent = builder.IndentCount; + } + + public void Reset() + { + _builder.Length = _length; + _builder.IndentCount = _indent; + } + } +} diff --git a/tools/TinyEcs.SourceGenerator/Program.cs b/tools/TinyEcs.SourceGenerator/Program.cs new file mode 100644 index 00000000..48e7301f --- /dev/null +++ b/tools/TinyEcs.SourceGenerator/Program.cs @@ -0,0 +1,288 @@ +using System; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +#pragma warning disable IDE0055 +#pragma warning disable IDE0008 +#pragma warning disable IDE0058 + +namespace TinyEcs.SourceGenerator; + +[Generator] +public sealed class Program : IIncrementalGenerator +{ + public void Initialize(IncrementalGeneratorInitializationContext context) + { + // Find IPlugin classes that contain methods with [TinySystem] attributes + var pluginClassesWithTinySystemMethods = context.SyntaxProvider.CreateSyntaxProvider( + static (s, _) => (s is ClassDeclarationSyntax || s is StructDeclarationSyntax) && + s is TypeDeclarationSyntax typeDecl && + typeDecl.Members.OfType() + .Any(m => m.AttributeLists.Count > 0), + static (ctx, _) => + { + var typeDecl = (TypeDeclarationSyntax)ctx.Node; + var typeSymbol = ctx.SemanticModel.GetDeclaredSymbol(typeDecl) as INamedTypeSymbol; + + if (typeSymbol == null) return null; + + // Check if the type implements IPlugin + var implementsIPlugin = typeSymbol.AllInterfaces.Any(i => + i.ToDisplayString() == "TinyEcs.IPlugin"); + + if (!implementsIPlugin) return null; + + // Find methods with [TinySystem] attribute + var tinySystemMethods = typeSymbol.GetMembers() + .OfType() + .Where(m => m.GetAttributes().Any(attr => + attr.AttributeClass?.ToDisplayString() == "TinyEcs.TinySystemAttribute")) + .ToList(); + + if (!tinySystemMethods.Any()) return null; + + return new SystemMethodInfo + { + ContainingType = typeSymbol, + TinySystemMethods = tinySystemMethods, + IsFromPlugin = true + }; + } + ).Where(static info => info != null); + + // Find all methods with [TinySystem] attributes (including those outside IPlugin classes/structs) + var allTinySystemMethods = context.SyntaxProvider.CreateSyntaxProvider( + static (s, _) => s is MethodDeclarationSyntax methodDecl && + methodDecl.AttributeLists.Count > 0, + static (ctx, _) => + { + var methodDecl = (MethodDeclarationSyntax)ctx.Node; + var methodSymbol = ctx.SemanticModel.GetDeclaredSymbol(methodDecl) as IMethodSymbol; + + if (methodSymbol == null) return null; + + // Check if method has [TinySystem] attribute + var hasTinySystemAttribute = methodSymbol.GetAttributes().Any(attr => + attr.AttributeClass?.ToDisplayString() == "TinyEcs.TinySystemAttribute"); + + if (!hasTinySystemAttribute) return null; + + var containingType = methodSymbol.ContainingType; + + // Check if the containing type implements IPlugin + var implementsIPlugin = containingType.AllInterfaces.Any(i => + i.ToDisplayString() == "TinyEcs.IPlugin"); + + // Only include if it's NOT from an IPlugin type (those are handled separately) + if (implementsIPlugin) return null; + + return new SystemMethodInfo + { + ContainingType = containingType, + TinySystemMethods = new List { methodSymbol }, + IsFromPlugin = false + }; + } + ).Where(static info => info != null); + + // Combine both providers + var allSystemMethods = pluginClassesWithTinySystemMethods.Collect() + .Combine(allTinySystemMethods.Collect()) + .Select(static (combined, _) => + { + var (pluginMethods, standaloneMethods) = combined; + var result = new List(); + + if (!pluginMethods.IsDefaultOrEmpty) + result.AddRange(pluginMethods); + + if (!standaloneMethods.IsDefaultOrEmpty) + result.AddRange(standaloneMethods); + + return result.ToImmutableArray(); + }); + + // Generate adapter classes for each method + context.RegisterSourceOutput( + allSystemMethods, + (spc, systemMethods) => + { + if (systemMethods.IsDefaultOrEmpty) return; + + foreach (var systemMethod in systemMethods) + { + foreach (var method in systemMethod.TinySystemMethods) + { + GenerateAdapterClass(spc, systemMethod.ContainingType, method, systemMethod.IsFromPlugin); + } + } + } + ); + } + + private static void GenerateAdapterClass(SourceProductionContext context, INamedTypeSymbol containingType, IMethodSymbol method, bool isFromPlugin) + { + var adapterName = $"{method.Name}Adapter"; + var ns = containingType.ContainingNamespace.IsGlobalNamespace ? "" : containingType.ContainingNamespace.ToDisplayString(); + + // Use fully-qualified type name (global::Namespace.Type) for instance/static references + var instanceTypeName = containingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + + // Validate method requirements for TinySystemAttribute + ValidateMethodRequirements(context, method); + + // Check if method returns bool (for conditional systems) + var returnsBool = method.ReturnType.SpecialType == SpecialType.System_Boolean; + var baseClass = returnsBool ? "TinyEcs.TinyConditionalSystem" : "TinyEcs.TinySystem"; + + // Determine class visibility based on the containing type's visibility + var classVisibility = GetClassVisibility(containingType); + + // Get method parameters for dependency injection + var parameters = method.Parameters.ToList(); + var setupAssignments = new StringBuilder(); + var methodCallParameters = new StringBuilder(); + + // Generate setup assignments and method call parameters + for (int i = 0; i < parameters.Count; i++) + { + var param = parameters[i]; + var paramType = param.Type.ToDisplayString(); + + setupAssignments.AppendLine($" builder.Add<{paramType}>();"); + + if (i > 0) methodCallParameters.Append(", "); + methodCallParameters.Append($"({paramType})SystemParams[{i}]"); + } + + // For non-static methods, add a field for the instance + string instanceField = ""; + string ctor = ""; + string methodCall; + + // Use a single IndentedStringBuilder for all code blocks + var adapterClass = new IndentedStringBuilder(); + + if (!string.IsNullOrEmpty(ns)) + { + adapterClass.AppendLine($"namespace {ns}"); + adapterClass.AppendLine("{"); + adapterClass.IncrementIndent(); + } + + // Make the adapter class sealed and partial with visibility matching the containing type + adapterClass.AppendLine($"{classVisibility} sealed partial class {adapterName} : {baseClass}"); + adapterClass.AppendLine("{"); + adapterClass.IncrementIndent(); + + if (method.IsStatic) + { + // Use namespace-qualified type for static call + methodCall = $"{instanceTypeName}.{method.Name}({methodCallParameters})"; + } + else + { + // Adapter will accept the instance via constructor using namespace-qualified type + instanceField = $"private readonly {instanceTypeName} _instance;"; + ctor = $"public {adapterName}({instanceTypeName} instance) {{ _instance = instance; }}"; + methodCall = $"_instance.{method.Name}({methodCallParameters})"; + adapterClass.AppendLine(instanceField); + adapterClass.AppendLine(); + adapterClass.AppendLine(ctor); + } + + adapterClass.AppendLine(); + + // Setup method + adapterClass.AppendLine("protected override void Setup(TinyEcs.SystemParamBuilder builder)"); + adapterClass.AppendLine("{"); + adapterClass.IncrementIndent(); + foreach (var line in setupAssignments.ToString().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)) + adapterClass.AppendLine(line); + adapterClass.DecrementIndent(); + adapterClass.AppendLine("}"); + + adapterClass.AppendLine(); + + // Execute method + adapterClass.AppendLine("protected override bool Execute(TinyEcs.World world)"); + adapterClass.AppendLine("{"); + adapterClass.IncrementIndent(); + adapterClass.AppendLine("Lock();"); + adapterClass.AppendLine("world.BeginDeferred();"); + if (returnsBool) + { + adapterClass.AppendLine($"bool result = {methodCall};"); + adapterClass.AppendLine("world.EndDeferred();"); + adapterClass.AppendLine("Unlock();"); + adapterClass.AppendLine("return result;"); + } + else + { + adapterClass.AppendLine($"{methodCall};"); + adapterClass.AppendLine("world.EndDeferred();"); + adapterClass.AppendLine("Unlock();"); + adapterClass.AppendLine("return true;"); + } + adapterClass.DecrementIndent(); + adapterClass.AppendLine("}"); + + adapterClass.DecrementIndent(); + adapterClass.AppendLine("}"); + + if (!string.IsNullOrEmpty(ns)) + { + adapterClass.DecrementIndent(); + adapterClass.AppendLine("}"); + } + + var sourceText = adapterClass.ToString(); + context.AddSource($"{adapterName}.g.cs", sourceText); + } + + private static string GetClassVisibility(INamedTypeSymbol containingType) + { + return containingType.DeclaredAccessibility switch + { + Accessibility.Public => "public", + Accessibility.Internal => "internal", + Accessibility.Private => "private", + Accessibility.Protected => "protected", + Accessibility.ProtectedAndInternal => "private protected", + Accessibility.ProtectedOrInternal => "protected internal", + _ => "internal" // Default to internal if accessibility is not recognized + }; + } + + private static void ValidateMethodRequirements(SourceProductionContext context, IMethodSymbol method) + { + var location = method.Locations.FirstOrDefault() ?? Location.None; + + // Check if method is public + if (method.DeclaredAccessibility != Accessibility.Public) + { + var descriptor = new DiagnosticDescriptor( + "TINYECS001", + "TinySystem method must be public", + "Method '{0}' with [TinySystem] attribute must be public", + "TinyEcs", + DiagnosticSeverity.Error, + isEnabledByDefault: true); + + context.ReportDiagnostic(Diagnostic.Create(descriptor, location, method.Name)); + } + + // Check if method is static + } + + private class SystemMethodInfo + { + public INamedTypeSymbol ContainingType { get; set; } + public List TinySystemMethods { get; set; } + public bool IsFromPlugin { get; set; } + } +} diff --git a/tools/TinyEcs.SourceGenerator/Properties/launchSettings.json b/tools/TinyEcs.SourceGenerator/Properties/launchSettings.json new file mode 100644 index 00000000..ece1eb57 --- /dev/null +++ b/tools/TinyEcs.SourceGenerator/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "Generators": { + "commandName": "DebugRoslynComponent", + "targetProject": "../../samples/MyBattleground/MyBattleground.csproj" + } + } +} diff --git a/tools/TinyEcs.SourceGenerator/TinyEcs.SourceGenerator.csproj b/tools/TinyEcs.SourceGenerator/TinyEcs.SourceGenerator.csproj new file mode 100644 index 00000000..91eab70e --- /dev/null +++ b/tools/TinyEcs.SourceGenerator/TinyEcs.SourceGenerator.csproj @@ -0,0 +1,15 @@ + + + + enable + enable + preview + netstandard2.0 + + + + + + + +