Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/Remove system improvement #312

Open
fabiitch opened this issue May 11, 2023 · 2 comments
Open

Add/Remove system improvement #312

fabiitch opened this issue May 11, 2023 · 2 comments

Comments

@fabiitch
Copy link
Contributor

fabiitch commented May 11, 2023

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)

@dsaltares
Copy link
Member

Thanks for opening the issue.
Can you share some more info on your use case and what you're trying to achieve?

@fabiitch
Copy link
Contributor Author

fabiitch commented May 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants