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

View File

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

View File

@ -96,6 +96,8 @@ namespace Cysharp.Threading.Tasks
TimeUpdate = 14,
LastTimeUpdate = 15,
#endif
Manual
}
[Flags]
@ -393,13 +395,12 @@ namespace Cysharp.Threading.Tasks
public static void Initialize(ref PlayerLoopSystem playerLoop, InjectPlayerLoopTimings injectTimings = InjectPlayerLoopTimings.All)
{
#if UNITY_2020_2_OR_NEWER
yielders = new ContinuationQueue[16];
runners = new PlayerLoopRunner[16];
#else
yielders = new ContinuationQueue[14];
runners = new PlayerLoopRunner[14];
#endif
var manualIndex = (int)PlayerLoopTiming.Manual;
yielders = new ContinuationQueue[manualIndex+1];
runners = new PlayerLoopRunner[manualIndex+1];
yielders[manualIndex] = new ContinuationQueue(PlayerLoopTiming.Manual);
runners[manualIndex] = new PlayerLoopRunner(PlayerLoopTiming.Manual);
var copyList = playerLoop.subSystemList.ToArray();
@ -485,6 +486,27 @@ namespace Cysharp.Threading.Tasks
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)
{
var runner = runners[(int)timing];