-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The added/removed entity listeners are a foot gun. Should they be removed or refactored? #32
Comments
I don't have concrete proof, but I think it might also be the case that the not filter |
There are a few solutions that come to mind:
|
Another foot gun:
This worked as you might expect. Another example, less obvious:
This last example is confusing, because people might assume The same confusion exists with My gut feeling is this behavior should change, to only track entities that were added/removed from the game, rather than attempting to track when they match the provided filter. I suspect most people just want to know when entities are added/removed rather than when their components match/unmatch the filter. |
Perhaps you could add system hooks for entityAdded/entityRemoved/componentAdded/componentRemoved |
yeah, not a bad idea |
I probably should have split this issue into several because there are several problems in here all related to the add/remove events. I think probably the most serious one is that |
I've split part of this out into #35 |
The solution I've come up with is to do function gameLoop () {
⋮
while (accumulator >= FIXED_STEP_MS) {
accumulator -= FIXED_STEP_MS
ECS.fixedUpdate(world, FIXED_STEP_MS)
ECS.cleanup(world)
}
ECS.update(world, frameTime)
ECS.postUpdate(world, frameTime)
requestAnimationFrame(gameLoop)
} And I handle the add/remove event only within the I don't know of a way around this presently. Perhaps this should go into a guidance section in the docs? |
Here's an example of how one might shoot themselves in the foot with this. Let's say you have a system that handles moving and colliding bullets against entities, and also needs to cleanup bullets in some way:
Let's say your main game loop looks something like this:
the fixed step runs at 120fps. If this game is running at 60 frames per second on a typical monitor, the fixed update steps will run twice for each call to
gameLoop
. When a bullet is removed from the ECS world, the fixed update step in the bullet system will run twice and see the same removed bullet entity each time. This is because theECS.cleanup
call runs at the end of eachgameLoop
, NOT after each fixed step.The text was updated successfully, but these errors were encountered: