[PlayerLoop]:Add Manual Loop Timing

pull/258/head
cuibeibei 2021-04-02 17:19:10 +08:00
parent 18f2746f0d
commit 4f292b57e7
3 changed files with 37 additions and 7 deletions

View File

@ -140,6 +140,9 @@ namespace Cysharp.Threading.Tasks.Internal
LastTimeUpdate(); LastTimeUpdate();
break; break;
#endif #endif
case PlayerLoopTiming.Manual:
ManualUpdate();
break;
default: default:
break; break;
} }
@ -166,6 +169,7 @@ namespace Cysharp.Threading.Tasks.Internal
void TimeUpdate() => RunCore(); void TimeUpdate() => RunCore();
void LastTimeUpdate() => RunCore(); void LastTimeUpdate() => RunCore();
#endif #endif
void ManualUpdate() => RunCore();
[System.Diagnostics.DebuggerHidden] [System.Diagnostics.DebuggerHidden]
void RunCore() void RunCore()

View File

@ -126,6 +126,9 @@ namespace Cysharp.Threading.Tasks.Internal
LastTimeUpdate(); LastTimeUpdate();
break; break;
#endif #endif
case PlayerLoopTiming.Manual:
ManualUpdate();
break;
default: default:
break; break;
} }
@ -152,6 +155,7 @@ namespace Cysharp.Threading.Tasks.Internal
void TimeUpdate() => RunCore(); void TimeUpdate() => RunCore();
void LastTimeUpdate() => RunCore(); void LastTimeUpdate() => RunCore();
#endif #endif
void ManualUpdate() => RunCore();
[System.Diagnostics.DebuggerHidden] [System.Diagnostics.DebuggerHidden]
void RunCore() void RunCore()

View File

@ -96,6 +96,8 @@ namespace Cysharp.Threading.Tasks
TimeUpdate = 14, TimeUpdate = 14,
LastTimeUpdate = 15, LastTimeUpdate = 15,
#endif #endif
Manual
} }
[Flags] [Flags]
@ -393,13 +395,12 @@ namespace Cysharp.Threading.Tasks
public static void Initialize(ref PlayerLoopSystem playerLoop, InjectPlayerLoopTimings injectTimings = InjectPlayerLoopTimings.All) public static void Initialize(ref PlayerLoopSystem playerLoop, InjectPlayerLoopTimings injectTimings = InjectPlayerLoopTimings.All)
{ {
#if UNITY_2020_2_OR_NEWER var manualIndex = (int)PlayerLoopTiming.Manual;
yielders = new ContinuationQueue[16]; yielders = new ContinuationQueue[manualIndex+1];
runners = new PlayerLoopRunner[16]; runners = new PlayerLoopRunner[manualIndex+1];
#else
yielders = new ContinuationQueue[14]; yielders[manualIndex] = new ContinuationQueue(PlayerLoopTiming.Manual);
runners = new PlayerLoopRunner[14]; runners[manualIndex] = new PlayerLoopRunner(PlayerLoopTiming.Manual);
#endif
var copyList = playerLoop.subSystemList.ToArray(); var copyList = playerLoop.subSystemList.ToArray();
@ -485,6 +486,27 @@ namespace Cysharp.Threading.Tasks
PlayerLoop.SetPlayerLoop(playerLoop); PlayerLoop.SetPlayerLoop(playerLoop);
} }
public static void ManualUpdate()
{
if (yielders != null)
{
var item = yielders[(int)PlayerLoopTiming.Manual];
if (item != null)
{
item.Run();
}
}
if (runners != null)
{
var item = runners[(int)PlayerLoopTiming.Manual];
if (item != null)
{
item.Run();
}
}
}
public static void AddAction(PlayerLoopTiming timing, IPlayerLoopItem action) public static void AddAction(PlayerLoopTiming timing, IPlayerLoopItem action)
{ {
var runner = runners[(int)timing]; var runner = runners[(int)timing];