Reducing impact of ontick event scripts
Posted: Mon Dec 29, 2014 4:58 pm
So, in the control.lua script I have a ontick event handler. Every tick it goes through a table, does some stuff with each entity in the table. Pretty standard stuff.
To prevent wasted cycles I currently skip the handler if there is no entities. This is simple, and works fine.
Does anyone have a good example of a way for an entity to 'back off' when it's not very busy?
I'm thinking about using something like:
if current tick % backoff == 0 then
if entityDidStuff() then
backoff = 1
else
backoff = backoff + 6(one tenth of a second, could be any number really)
if backoff > 60 (one second, but whatever makes sense)
backoff = 60
I'd like to know anyone else's experience with this sort of system, or if they have some sort of improvements. I'm not worried about having actual code here(although if we find a nice general solution, I'll add it to the op), pseudo code is just fine.
Any other tips and tricks for reducing your script impact are welcome here as well.
To prevent wasted cycles I currently skip the handler if there is no entities. This is simple, and works fine.
Does anyone have a good example of a way for an entity to 'back off' when it's not very busy?
I'm thinking about using something like:
if current tick % backoff == 0 then
if entityDidStuff() then
backoff = 1
else
backoff = backoff + 6(one tenth of a second, could be any number really)
if backoff > 60 (one second, but whatever makes sense)
backoff = 60
I'd like to know anyone else's experience with this sort of system, or if they have some sort of improvements. I'm not worried about having actual code here(although if we find a nice general solution, I'll add it to the op), pseudo code is just fine.
Any other tips and tricks for reducing your script impact are welcome here as well.