ecs icon indicating copy to clipboard operation
ecs copied to clipboard

System priorities

Open pavelvasev opened this issue 3 years ago • 3 comments

Hi Mike!

In my case there is a need to specify priorities for systems. I understand that there are onFixedUpdate, onPreUpdate,onUpdate,onPostUpdate order, thus priorities (4 ones) are already presented. But I think it will be more usable to use digital priorities. For example:

ECS.addSystem( world, system1, { priority: 10} )
ECS.addSystem( world, system2, { priority: 90} )

Actually I need all these just to catch added and removed "events" carefully. Probably there are other solutions.

One of solution I see is to add a system in a correct order. However in my case it is not an option, because I would like to add systems dynamically via GUI.

One of caveat with approach of specifiyng priority in addSystem is an inability to change that priority dinamically. Aside that it breaks your super-elegant optionless design. Probably better way will be something like this:

var h1 = ECS.addSystem( world, system1 )
var h2 = ECS.addSystem( world, system2 )
...
ECS.setSystemPriority( world, h1, 10 );
ECS.setSystemPriority( world,h2, 90 );
...
ECS.setSystemPriority( world,h1, 25 );
...
ECS.removeSystem( world,h1 ); // this is a subject to another talk.. ;-)

What do you think about that?

pavelvasev avatar Jul 13 '21 18:07 pavelvasev

I've definitely thought about adding a priority system but I haven't given it much careful thought yet.. Something like this could work.

If you need to re-order the systems right now, you can adjust the values in world.systems:

const world = ECS.createWorld()

// swap order of systems 0 and 2
const tmp = world.systems[0]
world.systems[0] = world.systems[2]
world.systems[2] = tmp

mreinstein avatar Jul 14 '21 18:07 mreinstein

Mike thank you for explaining the work-around!

pavelvasev avatar Jul 15 '21 05:07 pavelvasev

Still open to supporting this if you'd like to PR. :)

mreinstein avatar Mar 25 '22 14:03 mreinstein