Add data init and dispose functions to systems #164
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is based on the amethyst discord discussion regarding system initialization and dispose.
In amethyst we have a lot of systems that have to initialize resources that they use prior to first execution. This was achieved by passing
World
andResources
to the system creation function so any required resources could be initialized. It works, but the nested syntax doesn't look too nice. However, there is no way to dispose of those resources once schedule is destroyed. Implementing this would require a big wrapper around all legion types and is really inconvenient. So instead I propose to add these utility function directly into legion.Here is how a system would look like:
Init and dispose functions for all systems are called by
Schedule::init
andSchedule::dispose
in the order of system insertion. It is up to the user to call those functions.Thread local systems are now a
ThreadLocalRunnable
trait which hasinit
,dispose
andrun
functions and implementsRunnable
trait. This simplifiesSchedule
code and API a bit. Unfortunatelly, I couldn't find a way to makeSystemId
static, so I used thelazy_static
library. Any ideas how to solve this without additional lib?This is a rough proposal and I'm looking for feedback