tburrows13 / LunarLandings

GNU General Public License v3.0
9 stars 7 forks source link

Use bucket system for on_tick updates #2

Closed RedRafe closed 6 months ago

RedRafe commented 6 months ago

I've moved some of the cached data in global to a bucket system (instead of a dictionary id --> data, it's now a nested dictionary (id % update_interval) --> [id --> data].

Since you have more modules that call on_tick, I've made a separated module Buckets that can be imported and used whenever you need it. Transitioning to it is very easy overall: instead of calling: global.rtgs[entity.unit_number] it is instead Buckets.get(global.rtgs, entity.unit_number)

Default interval is 60 ticks (so entities are updated 1 per second instead of every tick), but can be customized per module.

Added some reallocate and migrate functions ad hoc for you if you feel to change the update interval of a module or to migrate other contents from previous table (this is also used in the migration file to migrate from .12 and earlier).

By all means, I did not run it through profilers and such, but at first glance, seems to help LL_perf

(the oxygenators's fluid box had to be doubled and moved to -1 to allow the fluid box to gather the fluids for a full 1s cycle)