Ontick scripting that offloads non-critical work to non-ontick worker?
Posted: Wed May 20, 2020 1:23 am
I'm a trained/experienced programmer, but I prefer C and other compiled languages. I haven't dabbled with lua scripting outside of things done during game load (so, nothing using ontick()).
I have a mod I want to modify. Fundamentally it places down chest entities and then every second it scans those chests to determine whether it should move the contents somewhere (think factorissimo outside/inside chest transfers; similar to that). The problem is in how the mod's current ontick() handler works. It causes stuttering because it is doing too much work during an ontick() call (around 300ms of work). I have a few ideas of how to fix it, but fundamentally is it possible to have an ontick call go through a LUA list, update a FIFO queue, and then have a blocking FIFO queue somewhere else that can operate outside of the ontick() operation? Or is all runtime code for a mod always running in the same thread no matter what?
I fear it's the latter, but I'd love if there was some way that I could have the ontick() call only do the two things it needed to do (periodically scan and move contents) and have all the other work (picking a destination, scanning the destination status, etc) happen outside of ontick() to keep update times reasonable.
I have a mod I want to modify. Fundamentally it places down chest entities and then every second it scans those chests to determine whether it should move the contents somewhere (think factorissimo outside/inside chest transfers; similar to that). The problem is in how the mod's current ontick() handler works. It causes stuttering because it is doing too much work during an ontick() call (around 300ms of work). I have a few ideas of how to fix it, but fundamentally is it possible to have an ontick call go through a LUA list, update a FIFO queue, and then have a blocking FIFO queue somewhere else that can operate outside of the ontick() operation? Or is all runtime code for a mod always running in the same thread no matter what?
I fear it's the latter, but I'd love if there was some way that I could have the ontick() call only do the two things it needed to do (periodically scan and move contents) and have all the other work (picking a destination, scanning the destination status, etc) happen outside of ontick() to keep update times reasonable.