Files
Bubberstation/code/__HELPERS/stoplag.dm
SkyratBot 8d61e1f93b [MIRROR] Doafter cleanup, disables stoplag dynamic sleeping in unit tests [MDB IGNORE] (#23288)
* Doafter cleanup, disables stoplag dynamic sleeping in unit tests (#77868)

## About The Pull Request

[Makes the do_afters list behave as
expected](b7cd6c520f)

Half the code expected it to be a flat list of things we are acting on,
half expected it to be an assoc list of thing -> interaction count

Let's make that second dream a reality yeah?

[Disables stoplag's lag stoppage for unit
tests](88b2bb371c)

Because of the unique environment of unit tests (High cpu usage, lots of
sleeping) this risks spurious hard deletes from neverending stoplag
runs.

## Why It's Good For The Game

Less errors/guesswork in testing, better code
Potentially addresses #77865

* Doafter cleanup, disables stoplag dynamic sleeping in unit tests

---------

Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
2023-08-23 20:25:43 -04:00

29 lines
1.1 KiB
Plaintext

//Key thing that stops lag. Cornerstone of performance in ss13, Just sitting here, in unsorted.dm. Now with dedicated file!
///Increases delay as the server gets more overloaded, as sleeps aren't cheap and sleeping only to wake up and sleep again is wasteful
#define DELTA_CALC max(((max(TICK_USAGE, world.cpu) / 100) * max(Master.sleep_delta-1,1)), 1)
///returns the number of ticks slept
/proc/stoplag(initial_delay)
if (!Master || Master.init_stage_completed < INITSTAGE_MAX)
sleep(world.tick_lag)
return 1
if (!initial_delay)
initial_delay = world.tick_lag
// Unit tests are not the normal environemnt. The mc can get absolutely thigh crushed, and sleeping procs running for ages is much more common
// We don't want spurious hard deletes off this, so let's only sleep for the requested period of time here yeah?
#ifdef UNIT_TESTS
sleep(initial_delay)
return CEILING(DS2TICKS(initial_delay), 1)
#else
. = 0
var/i = DS2TICKS(initial_delay)
do
. += CEILING(i * DELTA_CALC, 1)
sleep(i * world.tick_lag * DELTA_CALC)
i *= 2
while (TICK_USAGE > min(TICK_LIMIT_TO_RUN, Master.current_ticklimit))
#endif
#undef DELTA_CALC