├── .gitignore
├── Assets
├── Code.meta
├── Code
│ ├── AsyncSystem.meta
│ ├── AsyncSystem
│ │ ├── AsyncSystem.cs
│ │ ├── AsyncSystem.cs.meta
│ │ ├── StateSystem.cs
│ │ ├── StateSystem.cs.meta
│ │ ├── Utils.meta
│ │ └── Utils
│ │ │ ├── IHaveAspect.cs
│ │ │ ├── IHaveAspect.cs.meta
│ │ │ ├── ModuleExtensions.cs
│ │ │ ├── ModuleExtensions.cs.meta
│ │ │ ├── ProtoAspectInjectUtil.cs
│ │ │ ├── ProtoAspectInjectUtil.cs.meta
│ │ │ ├── UiExtensions.cs
│ │ │ └── UiExtensions.cs.meta
│ ├── GameAspect.cs
│ ├── GameAspect.cs.meta
│ ├── Lib.meta
│ ├── Lib
│ │ ├── Proto.meta
│ │ ├── Proto
│ │ │ └── cs.meta
│ │ ├── Routines.meta
│ │ ├── Routines
│ │ │ ├── Awaiters.meta
│ │ │ ├── Awaiters
│ │ │ │ ├── ActionAwaiter.cs
│ │ │ │ ├── ActionAwaiter.cs.meta
│ │ │ │ ├── AllAwaiter.cs
│ │ │ │ ├── AllAwaiter.cs.meta
│ │ │ │ ├── AnyAwaiter.cs
│ │ │ │ ├── AnyAwaiter.cs.meta
│ │ │ │ ├── FirstAwaiter.cs
│ │ │ │ ├── FirstAwaiter.cs.meta
│ │ │ │ ├── ForeverAwaiter.cs
│ │ │ │ ├── ForeverAwaiter.cs.meta
│ │ │ │ ├── FuncAwaiter.cs
│ │ │ │ ├── FuncAwaiter.cs.meta
│ │ │ │ ├── ProxyAwaiter.cs
│ │ │ │ ├── ProxyAwaiter.cs.meta
│ │ │ │ ├── SelfRollbackAwaiter.cs
│ │ │ │ ├── SelfRollbackAwaiter.cs.meta
│ │ │ │ ├── TryAwaiter.cs
│ │ │ │ ├── TryAwaiter.cs.meta
│ │ │ │ ├── YieldAwaiter.cs
│ │ │ │ ├── YieldAwaiter.cs.meta
│ │ │ │ ├── YieldAwaiterTicks.cs
│ │ │ │ └── YieldAwaiterTicks.cs.meta
│ │ │ ├── Builders.meta
│ │ │ ├── Builders
│ │ │ │ ├── RoutineBuilder.cs
│ │ │ │ ├── RoutineBuilder.cs.meta
│ │ │ │ ├── RoutineBuilder_T.cs
│ │ │ │ └── RoutineBuilder_T.cs.meta
│ │ │ ├── IRoutine.cs
│ │ │ ├── IRoutine.cs.meta
│ │ │ ├── InternalsVisibleTo.cs
│ │ │ ├── InternalsVisibleTo.cs.meta
│ │ │ ├── README_ROUTINE.md
│ │ │ ├── README_ROUTINE.md.meta
│ │ │ ├── Routine.cs
│ │ │ ├── Routine.cs.meta
│ │ │ ├── RoutineApi.cs
│ │ │ ├── RoutineApi.cs.meta
│ │ │ ├── Routine_T.cs
│ │ │ ├── Routine_T.cs.meta
│ │ │ ├── Utils.meta
│ │ │ └── Utils
│ │ │ │ ├── Asr.cs
│ │ │ │ ├── Asr.cs.meta
│ │ │ │ ├── CalledOnceGuard.cs
│ │ │ │ ├── CalledOnceGuard.cs.meta
│ │ │ │ ├── DebugFileInfo.cs
│ │ │ │ ├── DebugFileInfo.cs.meta
│ │ │ │ ├── InfLoopSafety.cs
│ │ │ │ ├── InfLoopSafety.cs.meta
│ │ │ │ ├── Option.cs
│ │ │ │ ├── Option.cs.meta
│ │ │ │ ├── Pool.cs
│ │ │ │ ├── Pool.cs.meta
│ │ │ │ ├── Utils.cs
│ │ │ │ └── Utils.cs.meta
│ │ ├── Scope.meta
│ │ └── Scope
│ │ │ ├── ISafeScope.cs
│ │ │ ├── ISafeScope.cs.meta
│ │ │ ├── README_SCOPE.md
│ │ │ ├── README_SCOPE.md.meta
│ │ │ ├── Scope.cs
│ │ │ ├── Scope.cs.meta
│ │ │ ├── ScopeExtensions.cs
│ │ │ └── ScopeExtensions.cs.meta
│ ├── SceneContext.cs
│ ├── SceneContext.cs.meta
│ ├── Startup.cs
│ ├── Startup.cs.meta
│ ├── SysGameFlow.cs
│ ├── SysGameFlow.cs.meta
│ ├── SysInitGame.cs
│ ├── SysInitGame.cs.meta
│ ├── SysUnit.cs
│ ├── SysUnit.cs.meta
│ ├── UnitView.cs
│ └── UnitView.cs.meta
├── Scenes.meta
├── Scenes
│ ├── SampleScene.unity
│ ├── SampleScene.unity.meta
│ ├── Unit.prefab
│ └── Unit.prefab.meta
├── TextMesh Pro.meta
└── TextMesh Pro
│ ├── Fonts.meta
│ ├── Fonts
│ ├── LiberationSans - OFL.txt
│ ├── LiberationSans - OFL.txt.meta
│ ├── LiberationSans.ttf
│ └── LiberationSans.ttf.meta
│ ├── Resources.meta
│ ├── Resources
│ ├── Fonts & Materials.meta
│ ├── Fonts & Materials
│ │ ├── LiberationSans SDF - Drop Shadow.mat
│ │ ├── LiberationSans SDF - Drop Shadow.mat.meta
│ │ ├── LiberationSans SDF - Fallback.asset
│ │ ├── LiberationSans SDF - Fallback.asset.meta
│ │ ├── LiberationSans SDF - Outline.mat
│ │ ├── LiberationSans SDF - Outline.mat.meta
│ │ ├── LiberationSans SDF.asset
│ │ └── LiberationSans SDF.asset.meta
│ ├── LineBreaking Following Characters.txt
│ ├── LineBreaking Following Characters.txt.meta
│ ├── LineBreaking Leading Characters.txt
│ ├── LineBreaking Leading Characters.txt.meta
│ ├── Sprite Assets.meta
│ ├── Sprite Assets
│ │ ├── EmojiOne.asset
│ │ └── EmojiOne.asset.meta
│ ├── Style Sheets.meta
│ ├── Style Sheets
│ │ ├── Default Style Sheet.asset
│ │ └── Default Style Sheet.asset.meta
│ ├── TMP Settings.asset
│ └── TMP Settings.asset.meta
│ ├── Shaders.meta
│ ├── Shaders
│ ├── SDFFunctions.hlsl
│ ├── SDFFunctions.hlsl.meta
│ ├── TMP_Bitmap-Custom-Atlas.shader
│ ├── TMP_Bitmap-Custom-Atlas.shader.meta
│ ├── TMP_Bitmap-Mobile.shader
│ ├── TMP_Bitmap-Mobile.shader.meta
│ ├── TMP_Bitmap.shader
│ ├── TMP_Bitmap.shader.meta
│ ├── TMP_SDF Overlay.shader
│ ├── TMP_SDF Overlay.shader.meta
│ ├── TMP_SDF SSD.shader
│ ├── TMP_SDF SSD.shader.meta
│ ├── TMP_SDF-HDRP LIT.shadergraph
│ ├── TMP_SDF-HDRP LIT.shadergraph.meta
│ ├── TMP_SDF-HDRP UNLIT.shadergraph
│ ├── TMP_SDF-HDRP UNLIT.shadergraph.meta
│ ├── TMP_SDF-Mobile Masking.shader
│ ├── TMP_SDF-Mobile Masking.shader.meta
│ ├── TMP_SDF-Mobile Overlay.shader
│ ├── TMP_SDF-Mobile Overlay.shader.meta
│ ├── TMP_SDF-Mobile SSD.shader
│ ├── TMP_SDF-Mobile SSD.shader.meta
│ ├── TMP_SDF-Mobile-2-Pass.shader
│ ├── TMP_SDF-Mobile-2-Pass.shader.meta
│ ├── TMP_SDF-Mobile.shader
│ ├── TMP_SDF-Mobile.shader.meta
│ ├── TMP_SDF-Surface-Mobile.shader
│ ├── TMP_SDF-Surface-Mobile.shader.meta
│ ├── TMP_SDF-Surface.shader
│ ├── TMP_SDF-Surface.shader.meta
│ ├── TMP_SDF-URP Lit.shadergraph
│ ├── TMP_SDF-URP Lit.shadergraph.meta
│ ├── TMP_SDF-URP Unlit.shadergraph
│ ├── TMP_SDF-URP Unlit.shadergraph.meta
│ ├── TMP_SDF.shader
│ ├── TMP_SDF.shader.meta
│ ├── TMP_Sprite.shader
│ ├── TMP_Sprite.shader.meta
│ ├── TMPro.cginc
│ ├── TMPro.cginc.meta
│ ├── TMPro_Mobile.cginc
│ ├── TMPro_Mobile.cginc.meta
│ ├── TMPro_Properties.cginc
│ ├── TMPro_Properties.cginc.meta
│ ├── TMPro_Surface.cginc
│ └── TMPro_Surface.cginc.meta
│ ├── Sprites.meta
│ └── Sprites
│ ├── EmojiOne Attribution.txt
│ ├── EmojiOne Attribution.txt.meta
│ ├── EmojiOne.json
│ ├── EmojiOne.json.meta
│ ├── EmojiOne.png
│ └── EmojiOne.png.meta
├── LICENSE
├── Packages
├── manifest.json
└── packages-lock.json
├── ProjectSettings
├── AudioManager.asset
├── ClusterInputManager.asset
├── DynamicsManager.asset
├── EditorBuildSettings.asset
├── EditorSettings.asset
├── GraphicsSettings.asset
├── InputManager.asset
├── MemorySettings.asset
├── MultiplayerManager.asset
├── NavMeshAreas.asset
├── NotificationsSettings.asset
├── PackageManagerSettings.asset
├── Physics2DSettings.asset
├── PresetManager.asset
├── ProjectSettings.asset
├── ProjectVersion.txt
├── QualitySettings.asset
├── SceneTemplateSettings.json
├── ShaderGraphSettings.asset
├── TagManager.asset
├── TimeManager.asset
├── URPProjectSettings.asset
├── UnityConnectSettings.asset
├── VFXManager.asset
├── VersionControlSettings.asset
└── XRSettings.asset
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | Leopotam.EcsProto*
2 | Leopotam.EcsProto.QoL*
3 | PerformanceTestRun*
4 | /.utmp
5 | *_DoNotShip/
6 | *_BackUpThisFolder_ButDontShipItWithYourGame/
7 | /[Uu]ser[Ss]ettings/
8 | /[Ll]ibrary/
9 | /[Tt]emp/
10 | /[Oo]bj/
11 | /[Bb]uild/
12 | /[Bb]uilds/
13 | /.idea/
14 | /.gradle/
15 | /Logs/
16 | /.vs/
17 | _TerrainAutoUpgrade*
18 |
19 | build_BackUpThisFolder_ButDontShipItWithYourGame
20 | build_BurstDebugInformation_DoNotShip
21 |
22 | /*.csproj
23 | /*.sln
24 | *.suo
25 | *.user
26 | *.DotSettings
27 | *.apk
--------------------------------------------------------------------------------
/Assets/Code.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3e6bec1a38d3c3d478a435306306c782
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Code/AsyncSystem.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b2f6644b86aef4543b563a49fe8e5dc5
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Code/AsyncSystem/AsyncSystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Leopotam.EcsProto;
3 | using Leopotam.EcsProto.QoL;
4 | using Mk.Routines;
5 |
6 | namespace AsyncSystem {
7 | ///
8 | /// Базовый класс для асинхронных систем в ProtoECS.
9 | /// Позволяет писать логику в синтаксисе `async/await`, в рамках сущности попадающей в указанный итератор
10 | ///
11 | /// Тип наследуемой системы.
12 | public abstract class AsyncSystem : IHaveAspect, IProtoRunSystem, IProtoInitSystem, IProtoDestroySystem
13 | where TSelf : AsyncSystem {
14 | _Aspect _self;
15 | Inc _incMode;
16 |
17 | ProtoItExc _routineStart;
18 | Slice<(Routine routine, ProtoPackedEntityWithWorld entity)> _buf = new ();
19 |
20 | public IProtoAspect GetAspect () => new _Aspect ();
21 |
22 | protected abstract Routine Run (ProtoEntity entity);
23 |
24 | protected abstract IProtoIt GetProtoIt ();
25 |
26 |
27 | public void Init (IProtoSystems systems) {
28 | _self = systems.World ().Aspect<_Aspect> ();
29 | var world = _self.World ();
30 | var sourceIt = GetProtoIt ();
31 | if (sourceIt is ProtoIt inc) {
32 | _incMode = new () {
33 | Source = inc,
34 | End = new (new[] { typeof (_Routine) })
35 | };
36 | _incMode.Source.Init (world);
37 | _incMode.End.Init (world);
38 | var protoPools = inc.Includes ();
39 | var inc1 = new Type[protoPools.Length];
40 | for (var i = protoPools.Length - 1; i >= 0; i--) {
41 | inc1[i] = protoPools[i].ItemType ();
42 | }
43 |
44 | _routineStart = new (inc1, It.Exc<_Routine> ());
45 | }
46 | else {
47 | throw new NotImplementedException ();
48 | }
49 |
50 | _routineStart.Init (world);
51 |
52 | Run ();
53 | }
54 |
55 | public void Run () {
56 | foreach (var e in _routineStart) {
57 | _self._routine.Add (e).Routine = Run (e);
58 | }
59 |
60 | var either = _incMode;
61 | foreach (var e in either.End) {
62 | if (either.Source.Has (e)) {
63 | _buf.Add ((_self._routine.Get (e).Routine, _self._world.PackEntityWithWorld (e)));
64 | }
65 | else {
66 | _self._routine.DelIfExists (e);
67 | }
68 | }
69 |
70 | for (var i = 0; i < _buf.Len (); i++) {
71 | ref var valueTuple = ref _buf.Get (i);
72 | if (!valueTuple.entity.TryUnpack (out _, out _)) {
73 | continue;
74 | }
75 |
76 | valueTuple.routine.Tick ();
77 | }
78 |
79 | _buf.Clear ();
80 | }
81 |
82 | public void Destroy () {
83 | foreach (var e in _incMode.End) {
84 | _self._routine.DelIfExists (e);
85 | }
86 | }
87 |
88 | class _Aspect : IProtoAspect {
89 | public ProtoWorld _world;
90 | public ProtoPool<_Routine> _routine;
91 |
92 | ProtoAspectInjectUtil.Result _res;
93 |
94 | public void Init (ProtoWorld world) {
95 | _res = ProtoAspectInjectUtil.Init (this, world);
96 | Asr.IsTrue (_world == null);
97 | _world = world;
98 | ProtoAspectInjectUtil.GetPool (_world, ref _routine);
99 | }
100 |
101 | public void PostInit () {
102 | ProtoAspectInjectUtil.PostInit (_res);
103 | }
104 |
105 | public ProtoWorld World () {
106 | return _world;
107 | }
108 | }
109 |
110 | class Inc {
111 | public ProtoIt Source;
112 | public ProtoIt End;
113 | }
114 |
115 | struct _Routine : IProtoHandlers<_Routine> {
116 | public Routine Routine;
117 |
118 | public void SetHandlers (IProtoPool<_Routine> pool) {
119 | pool.SetResetHandler (AutoReset);
120 | }
121 |
122 | static void AutoReset (ref _Routine c) {
123 | c.Routine?.Dispose ();
124 | c = default;
125 | }
126 | }
127 | }
128 | }
--------------------------------------------------------------------------------
/Assets/Code/AsyncSystem/AsyncSystem.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9ac7a4d3439433b48a7ee866fec2e875
--------------------------------------------------------------------------------
/Assets/Code/AsyncSystem/StateSystem.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6f770e3e40604cba924b93134536b0cc
3 | timeCreated: 1749021552
--------------------------------------------------------------------------------
/Assets/Code/AsyncSystem/Utils.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9eee3341f249aae41a3c11c427dac69a
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Code/AsyncSystem/Utils/IHaveAspect.cs:
--------------------------------------------------------------------------------
1 | using Leopotam.EcsProto;
2 |
3 | namespace AsyncSystem {
4 | public interface IHaveAspect {
5 | public IProtoAspect GetAspect ();
6 | }
7 | }
--------------------------------------------------------------------------------
/Assets/Code/AsyncSystem/Utils/IHaveAspect.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 257cfd7107c98784d901b2000785b0d1
--------------------------------------------------------------------------------
/Assets/Code/AsyncSystem/Utils/ModuleExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Leopotam.EcsProto;
3 | using Leopotam.EcsProto.QoL;
4 |
5 | namespace AsyncSystem.Utils {
6 | public static class ModuleExtensions {
7 | public static void AddSystem (this ProtoModules modules, T system)where T : IProtoSystem {
8 | if (system is IHaveAspect asyncSystem) {
9 | modules.AddAspect (asyncSystem.GetAspect ());
10 | }
11 |
12 | modules.AddModule (new SystemModule (system));
13 | }
14 |
15 | public static void AddModulesFrom (this ProtoModules modules, ProtoModules toAdd) {
16 | foreach (var m in toAdd.Modules ()) {
17 | modules.AddModule (m);
18 | }
19 |
20 | modules.AddAspect (toAdd.BuildAspect ());
21 | }
22 |
23 | // ReSharper disable once UnusedTypeParameter
24 | class SystemModule : IProtoModule {
25 | readonly IProtoSystem _system;
26 |
27 | public SystemModule (IProtoSystem system) {
28 | _system = system;
29 | }
30 |
31 | public void Init (IProtoSystems systems) {
32 | systems.AddSystem (_system);
33 | }
34 |
35 | public IProtoAspect[] Aspects () {
36 | return null;
37 | }
38 |
39 | public Type[] Dependencies () {
40 | return null;
41 | }
42 |
43 | public IProtoModule[] Modules () {
44 | return null;
45 | }
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/Assets/Code/AsyncSystem/Utils/ModuleExtensions.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 83958bcb4e4d456ea0e36f2aec646517
3 | timeCreated: 1739715296
--------------------------------------------------------------------------------
/Assets/Code/AsyncSystem/Utils/ProtoAspectInjectUtil.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3cdd366911ba05d4dae613f5c49c18e6
--------------------------------------------------------------------------------
/Assets/Code/AsyncSystem/Utils/UiExtensions.cs:
--------------------------------------------------------------------------------
1 | using Mk.Routines;
2 | using Mk.Scopes;
3 | using UnityEngine;
4 | using UnityEngine.Events;
5 | using UnityEngine.UI;
6 |
7 | namespace AsyncSystem.Utils {
8 | static class UiExtensions {
9 | public static void AddListenerScoped (this UnityEvent e, ISafeScope scope, UnityAction callback) {
10 | e.AddListener (callback);
11 | scope.Add (() => e.RemoveListener (callback));
12 | }
13 |
14 | public static void SetActiveScoped (this GameObject e, ISafeScope scope, bool value) {
15 | if (e.activeSelf == value) {
16 | return;
17 | }
18 |
19 | e.SetActive (value);
20 | scope.Add (() => e.SetActive (!value));
21 | }
22 |
23 | public static async Routine WaitForClick (this Button button) {
24 | var clicked = false;
25 | var scope = await Routine.GetScope ();
26 | button.onClick.AddListenerScoped (scope, () => clicked = true);
27 |
28 | await Routine.When (() => clicked);
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/Assets/Code/AsyncSystem/Utils/UiExtensions.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ed98eb78dfbf4f1f8a3cf96554cbedf9
3 | timeCreated: 1739719286
--------------------------------------------------------------------------------
/Assets/Code/GameAspect.cs:
--------------------------------------------------------------------------------
1 | using Leopotam.EcsProto;
2 | using Leopotam.EcsProto.QoL;
3 |
4 | struct CGame { }
5 |
6 | struct CUnit {
7 | public int Health;
8 | }
9 |
10 | class GameAspect : ProtoAspectInject {
11 | public ProtoPool CUnit = default;
12 | public ProtoPool CGame = default;
13 |
14 | public ProtoIt UnitIt = new (It.Inc ());
15 | }
--------------------------------------------------------------------------------
/Assets/Code/GameAspect.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b8cfd1c1461344f09f0cbad7379d9c71
3 | timeCreated: 1739720751
--------------------------------------------------------------------------------
/Assets/Code/Lib.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4153765a19f2e384ca1f94abc5858263
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Code/Lib/Proto.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ed9778619ff432c4da394e1e561e6582
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Code/Lib/Proto/cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7f29d4ca29ba0e04b899b246ac93b7ad
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3c889601d0a59dd42816b823f83eab5e
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4c1ec2f333ba7014f9f301a0c12bb266
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/ActionAwaiter.cs:
--------------------------------------------------------------------------------
1 | // ----------------------------------------------------------------------------
2 | // Async Routines framework https://github.com/korchoon/mk.routines
3 | // Copyright (c) 2016-2023 Mikhail Korchun
4 | // ----------------------------------------------------------------------------
5 |
6 | using System;
7 | using System.Runtime.CompilerServices;
8 | using Mk.Scopes;
9 |
10 | namespace Mk.Routines {
11 | #line hidden
12 | public class ActionAwaiter : IRoutine, ICriticalNotifyCompletion {
13 | public Func DoWhile;
14 | public Action OnUpdate;
15 | public Action BeforeDispose;
16 | public Action OnStart;
17 | Scope _scope;
18 | bool _started;
19 |
20 | public ActionAwaiter () { }
21 |
22 | void IDisposable.Dispose () {
23 | IsCompleted = true;
24 | BeforeDispose?.Invoke ();
25 | _scope?.Dispose ();
26 | }
27 |
28 | void IRoutine.UpdateParent () {
29 | if (Utils.TrySetNull (ref _continuation, out var c)) {
30 | c.Invoke ();
31 | }
32 | }
33 |
34 | void IRoutine.Tick () {
35 | if (IsCompleted) {
36 | return;
37 | }
38 |
39 | if (DoWhile != null && !DoWhile.Invoke ()) {
40 | this.DisposeAndUpdateParent ();
41 | return;
42 | }
43 |
44 | if (!_started) {
45 | _started = true;
46 | if (OnStart != null) {
47 | _scope = new ();
48 | OnStart.Invoke (_scope);
49 | }
50 | }
51 |
52 | OnUpdate?.Invoke ();
53 | }
54 |
55 | #region async
56 |
57 | Action _continuation;
58 |
59 | public ActionAwaiter GetAwaiter () {
60 | return this;
61 | }
62 |
63 | public void GetResult () { }
64 |
65 | public void OnCompleted (Action continuation) {
66 | if (IsCompleted) {
67 | continuation.Invoke ();
68 | return;
69 | }
70 |
71 | Asr.IsTrue (_continuation == null);
72 | _continuation = continuation;
73 | }
74 |
75 | public void UnsafeOnCompleted (Action continuation) => OnCompleted (continuation);
76 |
77 | public bool IsCompleted { get; private set; }
78 |
79 | #endregion
80 | }
81 | #line default
82 | }
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/ActionAwaiter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e31c0b238fb64c3c89d1aac576457631
3 | timeCreated: 1618072301
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/AllAwaiter.cs:
--------------------------------------------------------------------------------
1 | // ----------------------------------------------------------------------------
2 | // Async Routines framework https://github.com/korchoon/mk.routines
3 | // Copyright (c) 2016-2023 Mikhail Korchun
4 | // ----------------------------------------------------------------------------
5 |
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Runtime.CompilerServices;
9 | using JetBrains.Annotations;
10 |
11 | namespace Mk.Routines {
12 | #line hidden
13 | public class AllAwaiter : IRoutine, ICriticalNotifyCompletion {
14 | public IReadOnlyList Args;
15 | Action _continuation;
16 |
17 | public void Dispose () {
18 | if (IsCompleted) return;
19 | IsCompleted = true;
20 | foreach (var u in Args) u.Dispose ();
21 | }
22 |
23 | public void UpdateParent () {
24 | if (Utils.TrySetNull (ref _continuation, out var c)) c.Invoke ();
25 | }
26 |
27 | public void Tick () {
28 | if (IsCompleted) return;
29 |
30 | var all = true;
31 | for (var index = 0; index < Args.Count; index++) {
32 | var u = Args[index];
33 | u.Tick ();
34 | all &= u.IsCompleted;
35 | }
36 |
37 | if (all) {
38 | this.DisposeAndUpdateParent ();
39 | }
40 | }
41 |
42 | #region async
43 |
44 | [UsedImplicitly]
45 | public AllAwaiter GetAwaiter () {
46 | return this;
47 | }
48 |
49 | [UsedImplicitly]
50 | public void GetResult () { }
51 |
52 | [UsedImplicitly]
53 | public void OnCompleted (Action continuation) {
54 | if (IsCompleted) {
55 | continuation.Invoke ();
56 | return;
57 | }
58 |
59 | Asr.IsTrue (_continuation == null);
60 | _continuation = continuation;
61 | }
62 |
63 | [UsedImplicitly]
64 | public void UnsafeOnCompleted (Action continuation) {
65 | OnCompleted (continuation);
66 | }
67 |
68 | [UsedImplicitly]
69 | public bool IsCompleted { get; private set; }
70 |
71 | #endregion
72 | }
73 | #line default
74 | #line hidden
75 | public class AllAwaiter : IRoutine>>, ICriticalNotifyCompletion {
76 | public IReadOnlyList> Args;
77 |
78 | Action _continuation;
79 |
80 | public void Dispose () {
81 | if (IsCompleted) return;
82 | IsCompleted = true;
83 | foreach (var u in Args) u.Dispose ();
84 | }
85 |
86 | public void UpdateParent () {
87 | if (Utils.TrySetNull (ref _continuation, out var c)) c.Invoke ();
88 | }
89 |
90 | public void Tick () {
91 | if (IsCompleted) return;
92 |
93 | var all = true;
94 | for (var index = 0; index < Args.Count; index++) {
95 | var u = Args[index];
96 | u.Tick ();
97 | all &= u.IsCompleted;
98 | }
99 |
100 | if (all) {
101 | this.DisposeAndUpdateParent ();
102 | }
103 | }
104 |
105 | #region async
106 |
107 | [UsedImplicitly]
108 | public AllAwaiter GetAwaiter () {
109 | return this;
110 | }
111 |
112 | [UsedImplicitly]
113 | public IReadOnlyList> GetResult()
114 | {
115 | return Args;
116 |
117 | }
118 |
119 | [UsedImplicitly]
120 | public void OnCompleted (Action continuation) {
121 | if (IsCompleted) {
122 | continuation.Invoke ();
123 | return;
124 | }
125 |
126 | Asr.IsTrue (_continuation == null);
127 | _continuation = continuation;
128 | }
129 |
130 | [UsedImplicitly]
131 | public void UnsafeOnCompleted (Action continuation) {
132 | OnCompleted (continuation);
133 | }
134 |
135 | [UsedImplicitly]
136 | public bool IsCompleted { get; private set; }
137 |
138 | #endregion
139 | }
140 | #line default
141 | }
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/AllAwaiter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 359c7ebaf9a04407ac31e91f9e7a54c6
3 | timeCreated: 1602582178
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/AnyAwaiter.cs:
--------------------------------------------------------------------------------
1 | // ----------------------------------------------------------------------------
2 | // Async Routines framework https://github.com/korchoon/mk.routines
3 | // Copyright (c) 2016-2023 Mikhail Korchun
4 | // ----------------------------------------------------------------------------
5 |
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Runtime.CompilerServices;
9 | using JetBrains.Annotations;
10 |
11 | namespace Mk.Routines {
12 | #line hidden
13 | public class AnyAwaiter : IRoutine>, ICriticalNotifyCompletion {
14 | public IReadOnlyList Args;
15 | bool[] _result;
16 | Action _continuation;
17 |
18 | public void Dispose () {
19 | if (IsCompleted) return;
20 | IsCompleted = true;
21 | foreach (var u in Args) u.Dispose ();
22 | }
23 |
24 | public void UpdateParent () {
25 | if (Utils.TrySetNull (ref _continuation, out var c)) c.Invoke ();
26 | }
27 |
28 | public void Tick () {
29 | if (IsCompleted) return;
30 |
31 | var any = false;
32 | for (var index = 0; index < Args.Count; index++) {
33 | var u = Args[index];
34 | u.Tick ();
35 | _result[index] = u.IsCompleted;
36 | any |= u.IsCompleted;
37 | }
38 |
39 | if (any) {
40 | this.DisposeAndUpdateParent ();
41 | }
42 | }
43 |
44 | #region async
45 |
46 | CalledOnceGuard _guard;
47 |
48 | [UsedImplicitly]
49 | public AnyAwaiter GetAwaiter () {
50 | _result = new bool[Args.Count];
51 | _guard.Assert ();
52 | return this;
53 | }
54 |
55 | [UsedImplicitly]
56 | public IReadOnlyList GetResult () {
57 | return _result;
58 | }
59 |
60 | [UsedImplicitly]
61 | public void OnCompleted (Action continuation) {
62 | if (IsCompleted) {
63 | continuation.Invoke ();
64 | return;
65 | }
66 |
67 | Asr.IsTrue (_continuation == null);
68 | _continuation = continuation;
69 | }
70 |
71 | [UsedImplicitly]
72 | public void UnsafeOnCompleted (Action continuation) => OnCompleted (continuation);
73 |
74 | [UsedImplicitly]
75 | public bool IsCompleted { get; private set; }
76 |
77 | #endregion
78 | }
79 | public class AnyAwaiter : IRoutine[]>, ICriticalNotifyCompletion {
80 | public IRoutine[] Args;
81 | Action _continuation;
82 |
83 | public void Dispose () {
84 | if (IsCompleted) return;
85 | IsCompleted = true;
86 | foreach (var u in Args) u.Dispose ();
87 | }
88 |
89 | public void UpdateParent () {
90 | if (Utils.TrySetNull (ref _continuation, out var c)) c.Invoke ();
91 | }
92 |
93 | public void Tick () {
94 | if (IsCompleted) return;
95 |
96 | var any = false;
97 | for (var index = 0; index < Args.Length; index++) {
98 | ref var result = ref Args[index];
99 | result.Tick ();
100 | // result.Item1 = result.Item2.IsCompleted;
101 | any |= result.IsCompleted;
102 | }
103 |
104 | if (any) {
105 | this.DisposeAndUpdateParent ();
106 | }
107 | }
108 |
109 | #region async
110 |
111 | CalledOnceGuard _guard;
112 |
113 | [UsedImplicitly]
114 | public AnyAwaiter GetAwaiter () {
115 | _guard.Assert ();
116 | return this;
117 | }
118 |
119 | [UsedImplicitly]
120 | public IRoutine[] GetResult () {
121 | return Args;
122 | }
123 |
124 | [UsedImplicitly]
125 | public void OnCompleted (Action continuation) {
126 | if (IsCompleted) {
127 | continuation.Invoke ();
128 | return;
129 | }
130 |
131 | Asr.IsTrue (_continuation == null);
132 | _continuation = continuation;
133 | }
134 |
135 | [UsedImplicitly]
136 | public void UnsafeOnCompleted (Action continuation) => OnCompleted (continuation);
137 |
138 | [UsedImplicitly]
139 | public bool IsCompleted { get; private set; }
140 |
141 | #endregion
142 | }
143 | #line default
144 | }
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/AnyAwaiter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2c573c91d0a6449cb413ccb09c8d6ad2
3 | timeCreated: 1602582112
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/FirstAwaiter.cs:
--------------------------------------------------------------------------------
1 | // ----------------------------------------------------------------------------
2 | // Async Routines framework https://github.com/korchoon/mk.routines
3 | // Copyright (c) 2016-2023 Mikhail Korchun
4 | // ----------------------------------------------------------------------------
5 |
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Runtime.CompilerServices;
9 | using JetBrains.Annotations;
10 |
11 | namespace Mk.Routines {
12 | #line hidden
13 | public class FirstAwaiter : IRoutine, ICriticalNotifyCompletion {
14 | public IReadOnlyList Args;
15 | Action _continuation;
16 | bool _has;
17 | int _index;
18 |
19 | public void Dispose () {
20 | if (IsCompleted) return;
21 | IsCompleted = true;
22 | foreach (var u in Args) u.Dispose ();
23 | }
24 |
25 | public void UpdateParent () {
26 | if (Utils.TrySetNull (ref _continuation, out var c)) c.Invoke ();
27 | }
28 |
29 | public void Tick () {
30 | if (IsCompleted) return;
31 |
32 | var any = false;
33 | for (var index = 0; index < Args.Count; index++) {
34 | var u = Args[index];
35 | u.Tick ();
36 | if (!_has && u.IsCompleted) {
37 | _has = true;
38 | _index = index;
39 | }
40 |
41 | any |= u.IsCompleted;
42 | }
43 |
44 | if (any) {
45 | this.DisposeAndUpdateParent ();
46 | }
47 | }
48 |
49 | #region async
50 |
51 | CalledOnceGuard _guard;
52 |
53 | [UsedImplicitly]
54 | public FirstAwaiter GetAwaiter () {
55 | _guard.Assert ();
56 | return this;
57 | }
58 |
59 | [UsedImplicitly]
60 | public int GetResult () {
61 | Asr.IsTrue (_has);
62 | return _index;
63 | }
64 |
65 | [UsedImplicitly]
66 | public void OnCompleted (Action continuation) {
67 | if (IsCompleted) {
68 | continuation.Invoke ();
69 | return;
70 | }
71 |
72 | Asr.IsTrue (_continuation == null);
73 | _continuation = continuation;
74 | }
75 |
76 | [UsedImplicitly]
77 | public void UnsafeOnCompleted (Action continuation) => OnCompleted (continuation);
78 |
79 | [UsedImplicitly]
80 | public bool IsCompleted { get; private set; }
81 |
82 | #endregion
83 | }
84 |
85 | public class FirstAwaiter : IRoutine, ICriticalNotifyCompletion {
86 | public IReadOnlyList> Args;
87 | Action _continuation;
88 | T _result;
89 | bool _has;
90 |
91 | public void Dispose () {
92 | if (IsCompleted) return;
93 | IsCompleted = true;
94 | foreach (var u in Args) u.Dispose ();
95 | }
96 |
97 | public void UpdateParent () {
98 | if (Utils.TrySetNull (ref _continuation, out var c)) c.Invoke ();
99 | }
100 |
101 | public void Tick () {
102 | if (IsCompleted) return;
103 |
104 | var any = false;
105 | for (var index = 0; index < Args.Count; index++) {
106 | var u = Args[index];
107 | u.Tick ();
108 | if (!_has && u.IsCompleted) {
109 | _has = true;
110 | _result = u.GetResult ();
111 | }
112 |
113 | any |= u.IsCompleted;
114 | }
115 |
116 | if (any) {
117 | this.DisposeAndUpdateParent ();
118 | }
119 | }
120 |
121 | #region async
122 |
123 | CalledOnceGuard _guard;
124 |
125 | [UsedImplicitly]
126 | public FirstAwaiter GetAwaiter () {
127 | _guard.Assert ();
128 | return this;
129 | }
130 |
131 | [UsedImplicitly]
132 | public T GetResult () {
133 | Asr.IsTrue (_has);
134 | return _result;
135 | }
136 |
137 | [UsedImplicitly]
138 | public void OnCompleted (Action continuation) {
139 | if (IsCompleted) {
140 | continuation.Invoke ();
141 | return;
142 | }
143 |
144 | Asr.IsTrue (_continuation == null);
145 | _continuation = continuation;
146 | }
147 |
148 | [UsedImplicitly]
149 | public void UnsafeOnCompleted (Action continuation) => OnCompleted (continuation);
150 |
151 | [UsedImplicitly]
152 | public bool IsCompleted { get; private set; }
153 |
154 | #endregion
155 | }
156 | #line default
157 | }
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/FirstAwaiter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 123d5e866c814895acb4661c26fe4600
3 | timeCreated: 1613069565
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/ForeverAwaiter.cs:
--------------------------------------------------------------------------------
1 | // ----------------------------------------------------------------------------
2 | // Async Routines framework https://github.com/korchoon/mk.routines
3 | // Copyright (c) 2016-2023 Mikhail Korchun
4 | // ----------------------------------------------------------------------------
5 |
6 | using System;
7 | using System.Runtime.CompilerServices;
8 | using JetBrains.Annotations;
9 |
10 | namespace Mk.Routines {
11 | public class ForeverAwaiter : IRoutine, ICriticalNotifyCompletion {
12 | public static ForeverAwaiter Instance { get; } = new ();
13 |
14 | ForeverAwaiter() { }
15 |
16 | public void UpdateParent() { }
17 | public void Tick() { }
18 | public void Dispose() { }
19 |
20 | #region async
21 |
22 | [UsedImplicitly]
23 | public bool IsCompleted { get; } = false;
24 |
25 | [UsedImplicitly]
26 | public void GetResult() { }
27 |
28 | [UsedImplicitly]
29 | public void OnCompleted(Action _) { }
30 |
31 | [UsedImplicitly]
32 | public void UnsafeOnCompleted(Action _) { }
33 |
34 | [UsedImplicitly]
35 | public ForeverAwaiter GetAwaiter() => this;
36 |
37 | #endregion
38 | }
39 | }
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/ForeverAwaiter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2c48ee13fd8341b8987d0e0b80bc89be
3 | timeCreated: 1591815743
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/FuncAwaiter.cs:
--------------------------------------------------------------------------------
1 | // ----------------------------------------------------------------------------
2 | // Async Routines framework https://github.com/korchoon/mk.routines
3 | // Copyright (c) 2016-2023 Mikhail Korchun
4 | // ----------------------------------------------------------------------------
5 |
6 | using System;
7 | using System.Runtime.CompilerServices;
8 | using JetBrains.Annotations;
9 |
10 | namespace Mk.Routines {
11 | #line hidden
12 | public class FuncAwaiter : IRoutine, ICriticalNotifyCompletion where T : IOption {
13 | public Func TryGet;
14 | public Action OnDispose;
15 | Action _continuation;
16 | T _cached;
17 |
18 | public void Dispose () {
19 | if (IsCompleted) return;
20 | IsCompleted = true;
21 | OnDispose?.Invoke ();
22 | }
23 |
24 | void IRoutine.UpdateParent () {
25 | if (Utils.TrySetNull (ref _continuation, out var c)) c.Invoke ();
26 | }
27 |
28 | public void Tick () {
29 | if (IsCompleted) return;
30 |
31 | _cached = TryGet.Invoke ();
32 | if (_cached.HasValue) {
33 | this.DisposeAndUpdateParent ();
34 | }
35 | }
36 |
37 | #region async
38 |
39 | CalledOnceGuard _guard;
40 |
41 | [UsedImplicitly]
42 | public FuncAwaiter GetAwaiter () {
43 | _guard.Assert ();
44 | return this;
45 | }
46 |
47 | [UsedImplicitly]
48 | public bool IsCompleted { get; private set; }
49 |
50 | [UsedImplicitly]
51 | public T GetResult () => _cached;
52 |
53 | [UsedImplicitly]
54 | public void OnCompleted (Action continuation) {
55 | if (IsCompleted) {
56 | continuation.Invoke ();
57 | return;
58 | }
59 |
60 | Asr.IsTrue (_continuation == null);
61 | _continuation = continuation;
62 | }
63 |
64 | [UsedImplicitly]
65 | public void UnsafeOnCompleted (Action continuation) => OnCompleted (continuation);
66 |
67 | #endregion
68 | }
69 | #line default
70 | }
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/FuncAwaiter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3865ef35b90a4eb8aadeb96c0b32cc53
3 | timeCreated: 1628312147
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/ProxyAwaiter.cs:
--------------------------------------------------------------------------------
1 | // ----------------------------------------------------------------------------
2 | // Async Routines framework https://github.com/korchoon/mk.routines
3 | // Copyright (c) 2016-2023 Mikhail Korchun
4 | // ----------------------------------------------------------------------------
5 |
6 | using System;
7 | using System.Reflection;
8 | using System.Runtime.CompilerServices;
9 | using Mk.Scopes;
10 |
11 | namespace Mk.Routines {
12 | #line hidden
13 | public class ProxyAwaiter : IRoutine, ICriticalNotifyCompletion {
14 | public Func DoWhile;
15 | public Action OnStart;
16 | public Action OnBreak;
17 | public Action BeforeUpdate;
18 | public Action AfterUpdate;
19 | public Action BeforeDispose;
20 | internal IRoutine Main;
21 | bool _started;
22 | Scope _scope;
23 |
24 | void IDisposable.Dispose () {
25 | IsCompleted = true;
26 | BeforeDispose?.Invoke ();
27 | Main.Dispose ();
28 | _scope?.Dispose ();
29 | }
30 |
31 | void IRoutine.UpdateParent () {
32 | Main.UpdateParent ();
33 | if (Utils.TrySetNull (ref _continuation, out var c)) {
34 | c.Invoke ();
35 | }
36 | }
37 |
38 | void IRoutine.Tick () {
39 | if (IsCompleted) {
40 | return;
41 | }
42 |
43 | if (DoWhile != null && !DoWhile.Invoke ()) {
44 | OnBreak?.Invoke ();
45 | this.DisposeAndUpdateParent ();
46 | return;
47 | }
48 |
49 | if (!_started) {
50 | _started = true;
51 | if (OnStart != null) {
52 | _scope = new ();
53 | _scope.Add (Main.Dispose);
54 | OnStart.Invoke (_scope);
55 | }
56 | }
57 |
58 |
59 | BeforeUpdate?.Invoke ();
60 | Main.Tick ();
61 | if (Main.IsCompleted) {
62 | this.DisposeAndUpdateParent ();
63 | return;
64 | }
65 |
66 | // todo bug: afterUpdate got called after disposal
67 | AfterUpdate?.Invoke ();
68 | }
69 |
70 | #region async
71 |
72 | CalledOnceGuard _guard;
73 | Action _continuation;
74 |
75 | public ProxyAwaiter GetAwaiter () {
76 | _guard.Assert ();
77 | return this;
78 | }
79 |
80 | public void GetResult () { }
81 |
82 | public void OnCompleted (Action continuation) {
83 | if (IsCompleted) {
84 | continuation.Invoke ();
85 | return;
86 | }
87 |
88 | Asr.IsTrue (_continuation == null);
89 | _continuation = continuation;
90 | // Main.OnCompleted(continuation);
91 | }
92 |
93 | public void UnsafeOnCompleted (Action continuation) => OnCompleted (continuation);
94 |
95 | public bool IsCompleted { get; private set; }
96 |
97 | #endregion
98 | }
99 |
100 | public class ProxyAwaiter : IRoutine, ICriticalNotifyCompletion {
101 | public Action BeforeUpdateAction;
102 | public Action BeforeDisposeAction;
103 | public Action AfterUpdateAction;
104 | public IRoutine MainRoutine;
105 |
106 | Action _continuation;
107 |
108 | public void Dispose () {
109 | IsCompleted = true;
110 | BeforeDisposeAction?.Invoke ();
111 | MainRoutine.Dispose ();
112 | }
113 |
114 | public void UpdateParent () {
115 | MainRoutine.UpdateParent ();
116 | if (Utils.TrySetNull (ref _continuation, out var c)) c.Invoke ();
117 | }
118 |
119 | public void Tick () {
120 | if (IsCompleted) return;
121 |
122 | BeforeUpdateAction?.Invoke ();
123 | MainRoutine.Tick ();
124 | if (MainRoutine.IsCompleted) {
125 | this.DisposeAndUpdateParent ();
126 | return;
127 | }
128 |
129 | AfterUpdateAction?.Invoke ();
130 | }
131 |
132 | #region async
133 |
134 | public ProxyAwaiter GetAwaiter () => this;
135 |
136 | public T GetResult () {
137 | return MainRoutine.GetResult ();
138 | }
139 |
140 | public void OnCompleted (Action continuation) {
141 | if (IsCompleted) {
142 | continuation.Invoke ();
143 | return;
144 | }
145 |
146 | Asr.IsTrue (_continuation == null);
147 | _continuation = continuation;
148 | // MainRoutine.OnCompleted(continuation);
149 | }
150 |
151 | public void UnsafeOnCompleted (Action continuation) => OnCompleted (continuation);
152 |
153 | public bool IsCompleted { get; private set; }
154 |
155 | #endregion
156 | }
157 | #line default
158 | }
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/ProxyAwaiter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 49e995903d51479f90422edf9cf0b460
3 | timeCreated: 1602583413
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/SelfRollbackAwaiter.cs:
--------------------------------------------------------------------------------
1 | // ----------------------------------------------------------------------------
2 | // Async Routines framework https://github.com/korchoon/mk.routines
3 | // Copyright (c) 2016-2023 Mikhail Korchun
4 | // ----------------------------------------------------------------------------
5 |
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Runtime.CompilerServices;
9 | using JetBrains.Annotations;
10 | using Mk.Scopes;
11 | using UnityEngine;
12 |
13 | namespace Mk.Routines {
14 | [Serializable]
15 | public class AttachedRoutines {
16 | [SerializeReference] internal List Routines = new ();
17 |
18 | public void AttachUpdate (Action action) {
19 | Attach (Routine.FromActions (action));
20 | }
21 |
22 | public void Attach (IRoutine r) {
23 | Routines.Add (r);
24 | r.Tick (); // todo ?
25 | }
26 |
27 | public void AttachScoped (ISafeScope scope, IRoutine r) {
28 | Attach (r);
29 | scope.Add (() => {
30 | r.Dispose ();
31 | Detach (r);
32 | });
33 | }
34 |
35 | public void Detach (IRoutine r) {
36 | Routines.Remove (r);
37 | }
38 | }
39 |
40 | public class SelfParallelAwaiter : IRoutine, ICriticalNotifyCompletion {
41 | internal AttachedRoutines Value;
42 | public void UpdateParent () { }
43 | public void Tick () { }
44 | public void Dispose () { }
45 |
46 | #region async
47 |
48 | CalledOnceGuard _guard;
49 |
50 | [UsedImplicitly]
51 | public SelfParallelAwaiter GetAwaiter () {
52 | _guard.Assert ();
53 | return this;
54 | }
55 |
56 | [UsedImplicitly]
57 | public bool IsCompleted { [UsedImplicitly] get; private set; }
58 |
59 | [UsedImplicitly]
60 | public AttachedRoutines GetResult () => Value;
61 |
62 | [UsedImplicitly]
63 | public void OnCompleted (Action continuation) => IsCompleted = true;
64 |
65 | [UsedImplicitly]
66 | public void UnsafeOnCompleted (Action continuation) => OnCompleted (continuation);
67 |
68 | #endregion
69 | }
70 |
71 | public class SelfRollbackAwaiter : IRoutine, ICriticalNotifyCompletion {
72 | internal Scope Value;
73 | public void UpdateParent () { }
74 | public void Tick () { }
75 | public void Dispose () { }
76 |
77 | #region async
78 |
79 | CalledOnceGuard _guard;
80 |
81 | [UsedImplicitly]
82 | public SelfRollbackAwaiter GetAwaiter () {
83 | _guard.Assert ();
84 | return this;
85 | }
86 |
87 | [UsedImplicitly]
88 | public bool IsCompleted { [UsedImplicitly] get; private set; }
89 |
90 | [UsedImplicitly]
91 | public Scope GetResult () => Value;
92 |
93 | [UsedImplicitly]
94 | public void OnCompleted (Action continuation) => IsCompleted = true;
95 |
96 | [UsedImplicitly]
97 | public void UnsafeOnCompleted (Action continuation) => OnCompleted (continuation);
98 |
99 | #endregion
100 | }
101 | }
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/SelfRollbackAwaiter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cad0a02d4a28c95498e3cd17de17a249
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/Assets/Code/Lib/Routines/Awaiters/TryAwaiter.cs:
--------------------------------------------------------------------------------
1 | // ----------------------------------------------------------------------------
2 | // Async Routines framework https://github.com/korchoon/mk.routines
3 | // Copyright (c) 2016-2023 Mikhail Korchun
4 | // ----------------------------------------------------------------------------
5 |
6 | using System;
7 | using System.Runtime.CompilerServices;
8 | using JetBrains.Annotations;
9 |
10 | namespace Mk.Routines {
11 | #line hidden
12 | public class TryAwaiter : IRoutine, ICriticalNotifyCompletion {
13 | public Func TryGet;
14 | public Action OnDispose;
15 | Action _continuation;
16 |
17 | public void Dispose () {
18 | if (IsCompleted) return;
19 | IsCompleted = true;
20 | OnDispose?.Invoke ();
21 | }
22 |
23 | void IRoutine.UpdateParent () {
24 | if (Utils.TrySetNull (ref _continuation, out var c)) c.Invoke ();
25 | }
26 |
27 | public void Tick () {
28 | if (IsCompleted) return;
29 | if (!TryGet.Invoke ()) return;
30 | this.DisposeAndUpdateParent ();
31 | }
32 |
33 | #region async
34 |
35 | CalledOnceGuard _guard;
36 |
37 | [UsedImplicitly]
38 | public TryAwaiter GetAwaiter () {
39 | _guard.Assert ();
40 | return this;
41 | }
42 |
43 | [UsedImplicitly]
44 | public bool IsCompleted { get; private set; }
45 |
46 | [UsedImplicitly]
47 | public void GetResult () { }
48 |
49 | [UsedImplicitly]
50 | public void OnCompleted (Action continuation) {
51 | if (IsCompleted) {
52 | continuation.Invoke ();
53 | return;
54 | }
55 |
56 | Asr.IsTrue (_continuation == null);
57 | _continuation = continuation;
58 | }
59 |
60 | [UsedImplicitly]
61 | public void UnsafeOnCompleted (Action continuation) => OnCompleted (continuation);
62 |
63 | #endregion
64 | }
65 |
66 | public class TryAwaiter : IRoutine, ICriticalNotifyCompletion {
67 | public Func