Option to schedule on_tick for not-every-tick

sparr
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Option to schedule on_tick for not-every-tick

Post by sparr »

I would like to be able to register an on_tick event handler that runs every 5 or 60 or 3600 ticks. The prevailing paradigm here is to just put an if(tick%60==N) at the top of my on_tick handler.

A) Calling the handler every tick is a waste

B) Checking the condition in Lua instead of C is a waste

C) Calling a handler on_tick when it only contains code that runs every 60 ticks is misleading

but, most importantly...

D) Every mod author picks their own N here, and most of them pick 0 or 1 or 59. This means that some game ticks take much longer than others. On a heavily modded game, this can even be noticeable. If the registration of such handlers were centralized through the API, then it could decide which tick to run each handler on. The naive approach would be to just give tick 0 to the first mod, 29 to the second, 14 to the third, 44 to the fourth, etc. A more intense approach would involve profiling the handlers occasionally and using that information to decide which tick each handler gets run on. I expect that's too much to ask for, though, so I'll stick to asking for the naive option.

So, my actual ask here, is a way to register an on_every_n_ticks handler, with at least minimal logic behind the scene to give me a unique tick to run on relative to other mods.
Post Reply

Return to “Implemented mod requests”