Skip to content

Commit

Permalink
Don't double-call inline timers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Cole committed Apr 24, 2024
1 parent 93a5e33 commit 770668f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions YSI_Extra/y_inline_timers.inc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ static stock

static stock Timer_InlineRepeat(Func:func<>)
{
Debug_Print5("Timer_InlineRepeat called: %d", _:func);
// Normal repeating timer.
@.func();
}
Expand All @@ -124,28 +125,31 @@ static stock Timer_InlineRepeat(Func:func<>)

static stock Timer_InlineCount(Func:func<>, time, count)
{
--count;
if (count == -1)
Debug_Print5("Timer_InlineCount called: %d, %d, %d", _:func, time, count);
switch (--count)
{
case -1:
{
// Initial repeating timer, to set the time offset.
//printf("delay = %d", timer);
Indirect_SetMeta(func, SetTimerEx(&Timer_InlineRepeat<tF@_@:>, time, true, __const(YSI_gcI), _:func));
// Call the function after setting the meta, incase it kills the timer.
@.func();
}
if (count == 0)
case 0:
{
// Call before release.
@.func();
Indirect_Release(func);
Debug_Print7("y_inlineTimerCount ending: %d (%d)", _:func, ++YSI_gsCalls);
}
else
default:
{
// Call after meta.
Indirect_SetMeta(func, SetTimerEx(&Timer_InlineCount<tF@_@:ii>, time, false, __const(YSI_gcIII), _:func, time, count));
@.func();
}
}
}

/*-------------------------------------------------------------------------*//**
Expand Down Expand Up @@ -186,6 +190,7 @@ static stock Timer_InlineCount(Func:func<>, time, count)

stock Timer_CreateCallback(Func:func<>, initialOrTime, timeOrCount = 0, count = -1)
{
Debug_Print3("Timer_CreateCallback called: %d, %d, %d, %d", _:func, initialOrTime, timeOrCount, count);
if (count == -1)
{
// No `initial` time.
Expand Down Expand Up @@ -238,6 +243,7 @@ stock SetCallbackTimer(Func:func<>, initialOrTime, timeOrCount = 0, count = -1)

stock Timer_KillCallback(func)
{
Debug_Print3("Timer_KillCallback called: %d", func);
new timer = Indirect_GetMeta(func);
Indirect_Release(func);
return KillTimer(timer);
Expand Down

0 comments on commit 770668f

Please sign in to comment.