nadako / Ash-Haxe

Port of Ash entity framework to Haxe
Other
131 stars 37 forks source link

For Each in EngineStateMachine breaks Dependencies #24

Closed IkonOne closed 8 years ago

IkonOne commented 9 years ago

I have the following situation:

var dataSystem:System;
var objectSystem:System;
var cameraSystem:System;

var playState:EngineState = new EngineState()
    .addInstance(dataSystem)
    .addInstance(objectSystem)
    .addInstance(cameraSystem);

engineFSM.switchToState("The Above State");

When switching to the EngineState, the systems are added in any arbitrary order due to the For Each loop here: https://github.com/nadako/Ash-Haxe/blob/master/src/ash/fsm/EngineStateMachine.hx#L114

This breaks things for me because both objectSystem and cameraSystem both depend on dataSystem to be full initialized, and that cannot happen until dataSystem is added to an engine. Because of this, I am of the opinion that that For Each loop should be a regular For loop, that way the order systems are added to a state are preserved.

And on that note, looking at the code, this For Each should probably be changed as well due to similar reasoning: https://github.com/nadako/Ash-Haxe/blob/master/src/ash/fsm/EngineStateMachine.hx#L99

Thanks for porting Ash to haxe!

IkonOne commented 9 years ago

Another possible solution could be to add a signal to Engine that is called when systems are added and removed. I do think that a signal when systems are added/removed would be a useful feature that would incur minimal cost. However, I still am of the opinion that the order that you add systems to EngineState should be preserved. Especially since the one of the key benefits of the chaining(when adding systems) is it is self documenting.