fix: Fixes timer index offset (#1907)
### Summary - Fixes timer intervals not continuing - Fixes `Timer.Index` being off by 1. Should start at 0 for the first OnTick - Simplifies Gift of Renewal end check - Fixes force of nature not applying at the proper time and simplifies the timer logic.
This commit is contained in:
parent
2c9b3ef112
commit
28860b7f53
4 changed files with 35 additions and 47 deletions
|
|
@ -134,13 +134,11 @@ public partial class Timer
|
|||
|
||||
private static void Execute(Timer timer)
|
||||
{
|
||||
var finished = timer.Count != 0 && ++timer.Index >= timer.Count;
|
||||
var finished = timer.Count != 0 && timer.Index + 1 >= timer.Count;
|
||||
|
||||
var prof = timer.GetProfile();
|
||||
prof?.Start();
|
||||
|
||||
var version = timer.Version;
|
||||
|
||||
// Stop the timer from running so that way if Start() is called in OnTick, the timer will be started.
|
||||
if (finished)
|
||||
{
|
||||
|
|
@ -148,25 +146,30 @@ public partial class Timer
|
|||
timer.Version++;
|
||||
}
|
||||
|
||||
var version = timer.Version;
|
||||
|
||||
timer.OnTick();
|
||||
prof?.Finish();
|
||||
|
||||
// If the timer has been altered (restarted, returned etc) then bail
|
||||
if (timer.Version != version)
|
||||
// Starting doesn't change the timer version, so we need to check if it's finished and if it's still running.
|
||||
if (timer.Version != version || finished && timer.Running)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (finished)
|
||||
if (!finished)
|
||||
{
|
||||
timer.Delay = timer.Interval;
|
||||
timer.Next = DateTime.UtcNow + timer.Interval;
|
||||
AddTimer(timer, (long)timer.Delay.TotalMilliseconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Already stopped and detached, now run OnDetach
|
||||
timer.OnDetach();
|
||||
return;
|
||||
}
|
||||
|
||||
timer.Delay = timer.Interval;
|
||||
timer.Next = DateTime.UtcNow + timer.Interval;
|
||||
AddTimer(timer, (long)timer.Delay.TotalMilliseconds);
|
||||
timer.Index++;
|
||||
}
|
||||
|
||||
private static void AddTimer(Timer timer, long delay)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue