DavidPeicho / ecstra

Fast & Flexible EntityComponentSystem (ECS) for JavaScript & TypeScript
MIT License
51 stars 2 forks source link

Command Buffer: delay removal of entity / component #18

Open DavidPeicho opened 3 years ago

DavidPeicho commented 3 years ago

It looks like the community still needs deferred removal. I think a good way to go for that, would be to implement CommandBuffer in the same way other ECS work.

Command

Commands contain semantic about how to apply the its state onto the world. We would need command such as:

Later on, this can go even further with other types of commands.

CommandBuffer

CommandBuffer's contain a set of command to apply. For instance, an entire group of system could register command in a single buffer that will later be applied.

The key here is to let the user choose when to apply the commands. We could create default basic command buffers:

Internals

Using command buffers would make the implementation simple. There is no need for the internals to track what is removed and when to remove it.

Drawbacks

No deferred removal possible outside of systems

With an implementation like that, it seems impossible for someone to remove in a deferred fashion a component / entity. For me, it doesn't make sense to remove something deferred when not executing the world, but maybe some people have use cases for that?

EDIT

Turns out #21 raised a really good point. If deferred removal is done only when ticking, then resources might leak (exemple with WebGL object allocated in systems). Command buffers should then be exposed to users outside of systems as well! The good thing is that it shouldn't be hard to implement

DavidPeicho commented 3 years ago

Hopefully I will land a first draft soon.