Entitas-csharp: [Question] Multiple sets of systems?

Created on 12 Jun 2016  路  12Comments  路  Source: sschmid/Entitas-CSharp

It is advisable to create two or more sets of systems? Looking at the code briefly I don't see anything that would prevent this or break with multiple sets of systems, I've just never seen it in any of the example projects.

question

All 12 comments

Using multiple pools to separate behaviour is a better choice in most cases, but allow multiple systems, why not? Maybe in very big applications come in handy (multithreading?)

Do you mean different sets of systems that you execute in different 'Phases' of the game?

Yeah, what I actually needed to do was a set of systems that could be paused and another set of systems that were unpausable. So one set of systems only runs if there is no pause component in the pool and the other runs all the time.

I've implemented this and so far haven't had any issues. I looked deeper into the systems class itself and it doesn't seem like is anything magical there, just two lists for keeping track of what's running.

You can definitely nest systems RootSystemBehaviour.cs

You could also create some kind of GuardSystem which inherits from Systems (or better: Feature) and the add child systems to it

public class GuardSystems : Feature, ISetPool
{

    readonly Func<Pool, bool> _guardFunc;
    Pool _pool;

    public GuardSystems(string name, Func<Pool, bool> guardFunc) : base(name)
    {
        _guardFunc = guardFunc;
    }

    public void SetPool(Pool pool)
    {
        _pool = pool;
    }

    public override void Execute()
    {
        if (_guardFunc(_pool)) {
            base.Execute();
        }
    }
}
new GuardSystems("Pause Systems", pool => pool.isPaused)
    .Add(someChildSystem);

That's fairly eloquent, I actually just ended up doing the following in my update method:

unpausableSystems.Execute();
if (!pool.isPaused)
{
    pausableSystems.Execute();
} 

No nesting involved.

Fair enough :)

With GuardSystems you can create more complex system trees and end up with a single parent Systems which can be nice. In your case not really necessary, I see :)

Yeah I didn't realize they were nestable. May eventually go back and refactoring it, got a million other things to do to get this game out though 馃懢

i think this can post into wiki, i think its good to use!

@sschmid i use your GuardSystems for control some kinds of systems.
but i found some thing error.
please look my post > https://github.com/sschmid/Entitas-CSharp/issues/122

by the way i have test, this works, DestroySystem is worked.

``` c#
void InitSystems(Pool gamePool,Pool corePool)
{
_systems = new Feature("BattleSystems")

        // init sys
        .Add(gamePool.CreateSystem<CreateBattleSystem>())

        // add render view
        .Add(gamePool.CreateSystem<RemoveViewSystem>())
        .Add(gamePool.CreateSystem<AddViewSystem>())
        .Add(gamePool.CreateSystem<UpdateViewSystem>())

        // add gizmos systems
        .Add(gamePool.CreateSystem<GizmosMoveSystem>())

        // add tick logic systems.
        //.Add(new GuardSystems("LogicSystems", _pool => _pool.isTickPause)

                .Add(corePool.CreateSystem<TickSystem>())

                //.Add(pool.CreateSystem<InputSystem>())

                // reactive
                .Add(gamePool.CreateSystem<MoveSystem>())


                .Add(corePool.CreateSystem<DestroySystem>())
                .Add(gamePool.CreateSystem<DestroySystem>())

        //) // add tick logic systems end.

        ;


    _systems.Initialize();
}

```

@sschmid i solve the ISetPool wont call in ISystems implement

``` C#
using System;
using Entitas;
using TinyTeam.Debuger;

public class GuardSystems : Feature {

Pool _pool;

readonly Func<Pool, bool> _guardFunc;

public GuardSystems(string name, Func<Pool, bool> guardFunc,Pool pool) : base(name)
{
    _guardFunc = guardFunc;
    _pool = pool;
}

public override void Execute()
{
    if (!_guardFunc(_pool))
    {
        base.Execute();
    }
}

}

```

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CCludts picture CCludts  路  3Comments

zhuchun picture zhuchun  路  4Comments

xkyii picture xkyii  路  3Comments

yanjingzhaisun picture yanjingzhaisun  路  4Comments

KumoKairo picture KumoKairo  路  4Comments