njelly/TofuECS

Adding systems after initilization

Opened this issue · 5 comments

Currently systems are an array, and must be passed when constructing the simulation. This kinda limits the flexibility of Tofu

True.

How would you handle Initialize() for components that are added while the simulation is running? The idea was that all Systems get initialized sequentially at the same time, which makes things less complex imo. There's also the issue of garbage collection associated with Lists.

What sort of problems would be solved by adding/removing systems (i.e., replacing the system array with a system list)?

EDIT: what if instead of requiring an ISystem[] object passed into the constructor, it was an IList<ISystem>? Then users could use an array if they like or keep a reference to a list object outside the simulation, and add/remove systems as needed?

This is done. Simulation now takes in an IList<System> in its constructor rather than forcing an array.

I still recommend just passing in an array, but if adding/removing simulations is desired, it can be done by passing in a List and adding/removing from that outside of the simulation.

On second thought, I've realized that adding/removing systems causes issues with ISystemEventListener, as the simulation caches instances of ISystemEventListener when broadcasting system events. I'm going to revert this change for now and keep this issue open.

Another approach could be keeping framework's core as simple as possible, leaving out additional - not always needed - features that can be implemented on top, same way commonly desired features like this one could be addressed creating and sharing "extensions" like this one for leoecs-lite

https://github.com/Leopotam/ecslite-extendedsystems

@Jlabarca I like the idea of system groups that can be turned on and off. Maybe the array that is passed in to the simulation constructor could be the default group, then the user could register other groups before initialization, and if they don't care they can never worry about system groups? I want to avoid if(mySystem.IsEnabled) checks everywhere in the code, and I want the syntax to be as minimal as possible.