diff --git a/LICENSE.md b/LICENSE.md index 5554a18..a4aaeb9 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2012 - 2022 leopotam@yandex.ru +Copyright (c) 2012 - 2023 leopotam@yandex.ru Данное программное обеспечение и сопутствующая документация (далее - Продукт) выпускается на условиях двойного лицензирования - под собственнической/коммерческой diff --git a/README.md b/README.md index 686a7e2..33e6df2 100644 --- a/README.md +++ b/README.md @@ -84,25 +84,29 @@ struct Component1 { ## Система Является контейнером для основной логики для обработки отфильтрованных сущностей. Существует в виде пользовательского класса, реализующего как минимум один из `IEcsInitSystem`, `IEcsDestroySystem`, `IEcsRunSystem` (и прочих поддерживаемых) интерфейсов: ```c# -class UserSystem : IEcsPreInitSystem, IEcsInitSystem, IEcsRunSystem, IEcsDestroySystem, IEcsPostDestroySystem { +class UserSystem : IEcsPreInitSystem, IEcsInitSystem, IEcsRunSystem, IEcsPostRunSystem, IEcsDestroySystem, IEcsPostDestroySystem { public void PreInit (IEcsSystems systems) { - // Будет вызван один раз в момент работы IEcsSystems.Init() и до срабатывания IEcsInitSystem.Init(). + // Будет вызван один раз в момент работы IEcsSystems.Init() и до срабатывания IEcsInitSystem.Init() у всех систем. } public void Init (IEcsSystems systems) { - // Будет вызван один раз в момент работы IEcsSystems.Init() и после срабатывания IEcsPreInitSystem.PreInit(). + // Будет вызван один раз в момент работы IEcsSystems.Init() и после срабатывания IEcsPreInitSystem.PreInit() у всех систем. } public void Run (IEcsSystems systems) { // Будет вызван один раз в момент работы IEcsSystems.Run(). } + + public void PostRun (IEcsSystems systems) { + // Будет вызван один раз в момент работы IEcsSystems.Run() после срабатывания IEcsRunSystem.Run() у всех систем. + } public void Destroy (IEcsSystems systems) { - // Будет вызван один раз в момент работы IEcsSystems.Destroy() и до срабатывания IEcsPostDestroySystem.PostDestroy(). + // Будет вызван один раз в момент работы IEcsSystems.Destroy() и до срабатывания IEcsPostDestroySystem.PostDestroy() у всех систем. } public void PostDestroy (IEcsSystems systems) { - // Будет вызван один раз в момент работы IEcsSystems.Destroy() и после срабатывания IEcsDestroySystem.Destroy(). + // Будет вызван один раз в момент работы IEcsSystems.Destroy() и после срабатывания IEcsDestroySystem.Destroy() у всех систем. } } ``` diff --git a/package.json b/package.json index 6f6f617..b0362c5 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "displayName": "LeoECS Lite", "description": "LeoECS Lite - легковесный ECS-фреймворк, основанный на структурах. Производительность, нулевые или минимальные аллокации, минимизация использования памяти, отсутствие зависимостей от любого игрового движка - это основные цели данного фреймворка.", "unity": "2020.3", - "version": "2022.12.22", + "version": "2023.1.22", "keywords": [ "leoecslite", "leoecs", diff --git a/src/components.cs b/src/components.cs index c7e1bfb..78cbe48 100644 --- a/src/components.cs +++ b/src/components.cs @@ -1,6 +1,6 @@ // ---------------------------------------------------------------------------- // The Proprietary or MIT-Red License -// Copyright (c) 2012-2022 Leopotam +// Copyright (c) 2012-2023 Leopotam // ---------------------------------------------------------------------------- using System; diff --git a/src/entities.cs b/src/entities.cs index 7bfd24f..155aae3 100644 --- a/src/entities.cs +++ b/src/entities.cs @@ -1,6 +1,6 @@ // ---------------------------------------------------------------------------- // The Proprietary or MIT-Red License -// Copyright (c) 2012-2022 Leopotam +// Copyright (c) 2012-2023 Leopotam // ---------------------------------------------------------------------------- using System.Runtime.CompilerServices; diff --git a/src/filters.cs b/src/filters.cs index d85e57b..1a8dbdb 100644 --- a/src/filters.cs +++ b/src/filters.cs @@ -1,6 +1,6 @@ // ---------------------------------------------------------------------------- // The Proprietary or MIT-Red License -// Copyright (c) 2012-2022 Leopotam +// Copyright (c) 2012-2023 Leopotam // ---------------------------------------------------------------------------- using System; diff --git a/src/systems.cs b/src/systems.cs index f891884..bcc78e8 100644 --- a/src/systems.cs +++ b/src/systems.cs @@ -1,6 +1,6 @@ // ---------------------------------------------------------------------------- // The Proprietary or MIT-Red License -// Copyright (c) 2012-2022 Leopotam +// Copyright (c) 2012-2023 Leopotam // ---------------------------------------------------------------------------- using System.Collections.Generic; @@ -24,6 +24,10 @@ public interface IEcsRunSystem : IEcsSystem { void Run (IEcsSystems systems); } + public interface IEcsPostRunSystem : IEcsSystem { + void PostRun (IEcsSystems systems); + } + public interface IEcsDestroySystem : IEcsSystem { void Destroy (IEcsSystems systems); } @@ -53,6 +57,7 @@ public class EcsSystems : IEcsSystems { readonly Dictionary _worlds; readonly List _allSystems; readonly List _runSystems; + readonly List _postRunSystems; readonly object _shared; #if DEBUG bool _inited; @@ -64,6 +69,7 @@ public EcsSystems (EcsWorld defaultWorld, object shared = null) { _worlds = new Dictionary (8); _allSystems = new List (128); _runSystems = new List (128); + _postRunSystems = new List (128); } public virtual T GetShared () where T : class { @@ -101,6 +107,9 @@ public virtual IEcsSystems Add (IEcsSystem system) { if (system is IEcsRunSystem runSystem) { _runSystems.Add (runSystem); } + if (system is IEcsPostRunSystem postRunSystem) { + _postRunSystems.Add (postRunSystem); + } return this; } @@ -144,6 +153,13 @@ public virtual void Run () { #if DEBUG && !LEOECSLITE_NO_SANITIZE_CHECKS var worldName = CheckForLeakedEntities (this); if (worldName != null) { throw new System.Exception ($"Empty entity detected in world \"{worldName}\" after {_runSystems[i].GetType ().Name}.Run()."); } +#endif + } + for (int i = 0, iMax = _postRunSystems.Count; i < iMax; i++) { + _postRunSystems[i].PostRun (this); +#if DEBUG && !LEOECSLITE_NO_SANITIZE_CHECKS + var worldName = CheckForLeakedEntities (this); + if (worldName != null) { throw new System.Exception ($"Empty entity detected in world \"{worldName}\" after {_postRunSystems[i].GetType ().Name}.PostRun()."); } #endif } } diff --git a/src/worlds.cs b/src/worlds.cs index e6b41c0..7e6963b 100644 --- a/src/worlds.cs +++ b/src/worlds.cs @@ -1,6 +1,6 @@ // ---------------------------------------------------------------------------- // The Proprietary or MIT-Red License -// Copyright (c) 2012-2022 Leopotam +// Copyright (c) 2012-2023 Leopotam // ---------------------------------------------------------------------------- using System;