SharperUniverse icon indicating copy to clipboard operation
SharperUniverse copied to clipboard

Add Initialize() Finalize() Methods in the System

Open PhoenixICE opened this issue 6 years ago • 1 comments

Allow systems to call an Initialize Method and a Finalize Method aside from just having an Update Method.

The initialize method allows you to contain any initialisation requirements within the system instead of when instantiating the system:

EG:

var fooSystem = new FooSystem(gameRunner);
var entity = gameRunner.CreateEntityAsync();
fooSystem.RegisterComponentAsync(entity);

vs

public class FooSystem : BaseSystemInterface
{
    //add boilerplate etc...
    public async Task Initialize(GameRunner gameRunner)
    {
       var entity = gameRunner.CreateEntityAsync();
       this.RegisterComponentAsync(entity);
    }
}

The Finalize Method would allow you setup the system in a way that it can tear itself down of anything that needs to be cleared between new games (ie/start game -> Initialize -> end game -> Finalize -> new game -> Initialize etc..)

PhoenixICE avatar Jun 04 '18 02:06 PhoenixICE

Would Initialize() now just be the constructor in the current iteration of the ECS?

I can see a need for a Finalize() if things such as state saving needs to happen.

RubyNova avatar Jun 06 '18 02:06 RubyNova