Exemple #1
0
 internal FrameTimingPoint(IHostScreen screen, FrameTiming timing)
 {
     Debug.Assert(timing.IsSpecified());
     _screen     = screen;
     _eventQueue = new AsyncEventQueueCore();
     _timing     = timing;
 }
Exemple #2
0
 public FrameTimingPoint TimingOf(FrameTiming timing)
 {
     if (TryGetTimingOf(timing, out var timingPoint) == false)
     {
         ThrowTimingNotSpecified();
     }
     return(timingPoint);
 }
            internal Enumerator(CoroutineState coroutineState, FrameTiming timing)
            {
                Debug.Assert(timing.IsSpecified());
                var screen = coroutineState.Screen;

                _frameObject = coroutineState.FrameObject;
                _startTime   = screen.Time + screen.FrameDelta;
                _startFrame  = screen.FrameNum + 1;
                _timingPoint = screen.TimingPoints.TimingOf(timing);
            }
Exemple #4
0
 private static void CheckArgs(object parent, Delegate coroutine, FrameTiming timing)
 {
     Debug.Assert(parent is FrameObject || parent is IHostScreen || parent is null);
     if (parent is null)
     {
         ThrowNullArg(nameof(parent));
     }
     if (coroutine is null)
     {
         ThrowNullArg(nameof(coroutine));
     }
     timing.ThrowArgExceptionIfNotSpecified();
 }
Exemple #5
0
        public bool TryGetTimingOf(FrameTiming timing, [MaybeNullWhen(false)] out FrameTimingPoint timingPoint)
        {
            // [NOTE]
            // Only for public timing point

            if (timing == FrameTiming.FrameInitializing)
            {
                timingPoint = _frameInitializingPoint;
                return(true);
            }
            else if (timing == FrameTiming.EarlyUpdate)
            {
                timingPoint = _earlyUpdatePoint;
                return(true);
            }
            else if (timing == FrameTiming.Update)
            {
                timingPoint = _updatePoint;
                return(true);
            }
            else if (timing == FrameTiming.LateUpdate)
            {
                timingPoint = _lateUpdatePoint;
                return(true);
            }
            else if (timing == FrameTiming.BeforeRendering)
            {
                timingPoint = _beforeRenderingPoint;
                return(true);
            }
            else if (timing == FrameTiming.AfterRendering)
            {
                timingPoint = _afterRenderingPoint;
                return(true);
            }
            else
            {
                timingPoint = null;
                return(false);
            }
        }
Exemple #6
0
 public static void StartOrReserveCoroutine <TParent, TState>(this TParent parent, TState state, Func <CoroutineState, TState, UniTask> coroutine, FrameTiming timing)
     where TParent : FrameObject
 {
     Coroutine.StartOrReserve(parent, state, coroutine, timing);
 }
Exemple #7
0
 public static UniTask Start <TState>(IHostScreen parent, TState state, Func <CoroutineState, TState, UniTask> coroutine, FrameTiming timing)
 {
     CheckArgs(parent, coroutine, timing);
     return(StartPrivate(parent, state, coroutine, timing));
 }
Exemple #8
0
 public static UniTask StartCoroutine <TState>(this IHostScreen parent, TState state, Func <CoroutineState, TState, UniTask> coroutine, FrameTiming timing)
 {
     return(Coroutine.Start(parent, state, coroutine, timing));
 }
Exemple #9
0
 public static void StartOrReserveCoroutine(this IHostScreen parent, Func <CoroutineState, UniTask> coroutine, FrameTiming timing)
 {
     Coroutine.StartOrReserve(parent, coroutine, timing);
 }
Exemple #10
0
 public static void StartOrReserveWithCatch <TState>(IHostScreen parent, TState state, Func <CoroutineState, TState, UniTask> coroutine, Action <Exception> onCatch, FrameTiming timing)
 {
     CheckArgs(parent, coroutine, timing);
     StartOrReservePrivate(parent, state, coroutine, onCatch, timing);
 }
Exemple #11
0
 public static UniTask StartCoroutine <TParent, TState>(this TParent parent, TState state, Func <CoroutineState, TState, UniTask> coroutine, FrameTiming timing)
     where TParent : FrameObject
 {
     return(Coroutine.Start(parent, state, coroutine, timing));
 }
Exemple #12
0
 public static void StartOrReserveWithCatch(FrameObject parent, Func <CoroutineState, UniTask> coroutine, Action <Exception> onCatch, FrameTiming timing)
 {
     CheckArgs(parent, coroutine, timing);
     StartOrReservePrivate(parent, DummyState.Null, coroutine, onCatch, timing);
 }
 internal CoroutineFrameAsyncEnumerable(CoroutineState coroutineState, FrameTiming timing)
 {
     Debug.Assert(timing.IsSpecified());
     _coroutineState = coroutineState;
     _timing         = timing;
 }
Exemple #14
0
 private static void StartOrReservePrivate <TParent, TState>(TParent parent, TState state, Delegate coroutine, Action <Exception>?onCatch, FrameTiming timing) where TParent : class
 {
     if (typeof(TParent) == typeof(IHostScreen))
     {
         var parentScreen = SafeCast.As <IHostScreen>(parent);
         if (parentScreen.IsRunning == false)
         {
             ReserveCoroutine(parentScreen, state, coroutine, onCatch, timing);
         }
         else
         {
             StartCoroutine(new CoroutineState(parentScreen), state, coroutine, onCatch, timing).Forget();
         }
     }
     else if (typeof(TParent) == typeof(FrameObject))
     {
         var parentFrameObject = SafeCast.As <FrameObject>(parent);
         if (parentFrameObject.LifeState.IsBefore(LifeState.Alive))
         {
             ReserveCoroutine(parentFrameObject, state, coroutine, null, timing);
         }
         else
         {
             StartCoroutine(new CoroutineState(parentFrameObject), state, coroutine, null, timing).Forget();
         }
     }
     else
     {
         Debug.Fail("Something wrong");
     }
 }
Exemple #15
0
 public static UniTask Start(IHostScreen parent, Func <CoroutineState, UniTask> coroutine, FrameTiming timing)
 {
     CheckArgs(parent, coroutine, timing);
     return(StartPrivate(parent, DummyState.Null, coroutine, timing));
 }
Exemple #16
0
        private static async UniTask StartCoroutine <TState>(CoroutineState coroutineState, TState state, Delegate coroutine, Action <Exception>?onCatch, FrameTiming timing)
        {
            var fo = coroutineState.FrameObject;

            if (fo is null)
            {
                if (coroutineState.Screen.IsRunning == false)
                {
                    return;
                }
            }
            else
            {
                Debug.Assert(fo.LifeState.IsSameOrAfter(LifeState.Alive));
                if (fo.LifeState == LifeState.Dead)
                {
                    return;
                }
            }
            try {
                await coroutineState.TimingOf(timing).Next();

                if (typeof(TState) == typeof(DummyState))
                {
                    var noStateCoroutine = SafeCast.As <Func <CoroutineState, UniTask> >(coroutine);
                    await noStateCoroutine(coroutineState);
                }
                else
                {
                    var statefulCoroutine = SafeCast.As <Func <CoroutineState, TState, UniTask> >(coroutine);
                    await statefulCoroutine(coroutineState, state);
                }
            }
            catch (Exception ex) {
                if (onCatch != null)
                {
                    onCatch.Invoke(ex);
                }
                else
                {
                    if (EngineSetting.UserCodeExceptionCatchMode == UserCodeExceptionCatchMode.Throw)
                    {
                        throw;
                    }
                }
            }
        }
Exemple #17
0
 private static void ReserveCoroutine <TParent, TState>(TParent parent, TState state, Delegate coroutine, Action <Exception>?onCatch, FrameTiming timing)
     where TParent : class
 {
     if (typeof(TParent) == typeof(IHostScreen))
     {
         var parentScreen = SafeCast.As <IHostScreen>(parent);
         if (typeof(TState) == typeof(DummyState))
         {
             if (onCatch is null)
             {
                 // [capture] coroutine, timing
                 parentScreen.Initialized += p => StartCoroutine(new CoroutineState(p), DummyState.Null, coroutine, null, timing).Forget();
             }
             else
             {
                 // [capture] coroutine, onCatch, timing
                 parentScreen.Initialized += p => StartCoroutine(new CoroutineState(p), DummyState.Null, coroutine, onCatch, timing).Forget();
             }
             return;
         }
         else
         {
             if (onCatch is null)
             {
                 // [capture] state, coroutine, timing
                 parentScreen.Initialized += p => StartCoroutine(new CoroutineState(p), state, coroutine, null, timing).Forget();
             }
             else
             {
                 // [capture] state, coroutine, onCatch, timing
                 parentScreen.Initialized += p => StartCoroutine(new CoroutineState(p), state, coroutine, onCatch, timing).Forget();
             }
             return;
         }
     }
     else if (typeof(TParent) == typeof(FrameObject))
     {
         var parentFrameObject = SafeCast.As <FrameObject>(parent);
         if (typeof(TState) == typeof(DummyState))
         {
             if (onCatch is null)
             {
                 // [capture] coroutine, timing
                 parentFrameObject.Alive += f => StartCoroutine(new CoroutineState(f), DummyState.Null, coroutine, null, timing).Forget();
             }
             else
             {
                 // [capture] coroutine, onCatch, timing
                 parentFrameObject.Alive += f => StartCoroutine(new CoroutineState(f), DummyState.Null, coroutine, onCatch, timing).Forget();
             }
             return;
         }
         else
         {
             if (onCatch is null)
             {
                 // [capture] state, coroutine, timing
                 parentFrameObject.Alive += f => StartCoroutine(new CoroutineState(f), state, coroutine, null, timing).Forget();
             }
             else
             {
                 // [capture] state, coroutine, onCatch, timing
                 parentFrameObject.Alive += f => StartCoroutine(new CoroutineState(f), state, coroutine, onCatch, timing).Forget();
             }
             return;
         }
     }
     else
     {
         Debug.Fail("Something wrong");
         return;
     }
 }
Exemple #18
0
 private static UniTask StartPrivate <TParent, TState>(TParent parent, TState state, Delegate coroutine, FrameTiming timing) where TParent : class
 {
     if (typeof(TParent) == typeof(IHostScreen))
     {
         var parentScreen = SafeCast.As <IHostScreen>(parent);
         if (parentScreen.IsRunning == false)
         {
             ThrowParentNotAlive();
             return(UniTask.CompletedTask);
         }
         else
         {
             return(StartCoroutine(new CoroutineState(parentScreen), state, coroutine, null, timing));
         }
     }
     else if (typeof(TParent) == typeof(FrameObject))
     {
         var parentFrameObject = SafeCast.As <FrameObject>(parent);
         if (parentFrameObject.LifeState.IsBefore(LifeState.Alive))
         {
             ThrowParentNotAlive();
             return(UniTask.CompletedTask);
         }
         else
         {
             return(StartCoroutine(new CoroutineState(parentFrameObject), state, coroutine, null, timing));
         }
     }
     else
     {
         Debug.Fail("Something wrong");
         return(UniTask.CompletedTask);
     }
 }
Exemple #19
0
 public static void StartOrReserve(IHostScreen parent, Func <CoroutineState, UniTask> coroutine, FrameTiming timing)
 {
     CheckArgs(parent, coroutine, timing);
     StartOrReservePrivate(parent, DummyState.Null, coroutine, null, timing);
 }
Exemple #20
0
 public static void StartOrReserve <TState>(FrameObject parent, TState state, Func <CoroutineState, TState, UniTask> coroutine, FrameTiming timing)
 {
     CheckArgs(parent, coroutine, timing);
     StartOrReservePrivate(parent, state, coroutine, null, timing);
 }