2 using System.Collections.Generic;
3 using System.Diagnostics;
9 public static double Time => Timing.TotalTime;
15 return Timing.AccumulatorMax;
19 Timing.AccumulatorMax = value;
23 private class TimerComparer : IComparer<TimedAction>
25 public int Compare(TimedAction timedAction1, TimedAction timedAction2)
27 if (timedAction1 ==
null || timedAction2 ==
null)
29 return -Math.Sign(timedAction2.ExecutionTime - timedAction1.ExecutionTime);
33 private class TimedAction
41 public double ExecutionTime
50 ExecutionTime =
Time + (delayMs / 1000f);
54 private List<TimedAction> timedActions =
new List<TimedAction>();
56 private void AddTimer(TimedAction timedAction)
58 if (timedAction ==
null)
60 throw new ArgumentNullException(nameof(timedAction));
65 int insertionPoint = timedActions.BinarySearch(timedAction,
new TimerComparer());
67 if (insertionPoint < 0)
69 insertionPoint = ~insertionPoint;
72 timedActions.Insert(insertionPoint, timedAction);
80 TimedAction[] timedCopy = timedActions.ToArray();
81 for (
int i = 0; i < timedCopy.Length; i++)
83 TimedAction timedAction = timedCopy[i];
84 if (
Time >= timedAction.ExecutionTime)
95 timedActions.Remove(timedAction);
107 timedActions =
new List<TimedAction>();
112 TimedAction timedAction =
new TimedAction(action, millisecondDelay);
113 AddTimer(timedAction);
118 TimedAction timedAction =
new TimedAction(action, 0);
119 AddTimer(timedAction);
static void HandleException(Exception ex, LuaCsMessageOrigin origin)
static double AccumulatorMax
void NextFrame(LuaCsAction action)
void Wait(LuaCsAction action, int millisecondDelay)
delegate void LuaCsAction(params object[] args)