Add/Remove system improvement
Follow of : #311
Possibility to add or remove a system during the iteration and that the operation is effective on the current loop if the add/remove system has a lower priority than the current system.
Ex : You are in update loop, your system with priority 10 add a systeme with priority 15. Actually => don't work at all with #311 => the operation is performed at end of engine.update () goal=> operation perform immédialtly and the system.update is called in current loop (if his priority is lower than current)
Thanks for opening the issue. Can you share some more info on your use case and what you're trying to achieve?
Hi ! Its for my Gdx game, it use only ashley in render(dt).
I want sometimes to do some code at specific moment in the engine (but just one time !)
My solution was to create an EngineTaskSystem extends EntitySystem with priority 0 (first in my system list)
EngineTaskSystem contains an Array of EngineTask
Engine Task is like
public interface EngineTask {
void doTask();
int priority();
}
So i use EngineTaskSystem to insert new EntitySystem(task.priority()) and override update(dt) to call task.doTask() and an EngineTaskSystemRemove at last to remove all system created
And when i test i see the problem to modify systems during iteration Actually my solution was to call my engineTaskSystem.insertTaskInEngine() manually before ashley update for add all my systems in ashley. and call engineTaskSystem.removeEngineTaskDone() after engine.update(). (EngineTaskSystemRemove is not a system anyway and he is out of ashley)
it work no problem but i like to keep only engine.update in my render()
Anyway i think we need to do a little fix for fix the case of add/remove system during iteration. (why not throw exception) because actually it do a random behavior because it modified systems array during his iteration.
or this solution :D, perform operation at end of system update loop
Thanks for reading