eliasku / ecx

ECX is Entity Component System framework for Haxe
52 stars 10 forks source link

How to reset world? #15

Closed Glidias closed 7 years ago

Glidias commented 7 years ago

Any documented way to try and reset the world by removing all entities and being able to recreate them again?

I tried something like this....but doesn't seem to work.

public function end():Void {

    for ( i in 1..world.capacity ){  // somehow, re-creating new entities after this doesn't work?
        world.destroy( world.getEntity(i));
    }
    world.invalidate();  // this is needed?
}

Also, how to add/remove Systems? Based on the architecture of ECX, i'd assume you have to set the system flags to use SystemFlags.IDLE or not, right? But how to do this dynamically at runtime since the _systemFlags is private?

Glidias commented 7 years ago

Ok, solved it. Apparently, the code is correct and does work (invalidation does what it needs, invalidating everything immediately to clean up space for new entities to be re-added from pool). I just accidentally re-initialized my game module twice after reset ..my bad :( -D ecx_debug is good to check if pool exceeded and such...

OvermindDL1 commented 7 years ago

Hehe, cool, I could not figure out the issue you were having as my little programs have worked fine. ^.^;