Fix component pool entity removal
This commit is contained in:
parent
77c5c23cf5
commit
6d43f30c09
5 changed files with 48 additions and 18 deletions
|
|
@ -1,10 +1,15 @@
|
|||
package ecs
|
||||
|
||||
import "core:log"
|
||||
|
||||
PhysicsSystem :: struct {
|
||||
using base: SystemBase,
|
||||
}
|
||||
|
||||
physics_system_update :: proc(physics_system: ^PhysicsSystem, coordinator: ^Coordinator, dt: f32) {
|
||||
entities_to_delete := make([dynamic]EntityID)
|
||||
defer delete(entities_to_delete)
|
||||
|
||||
for entity in physics_system.entities {
|
||||
rigid_body := coordinator_get_component(RigidBodyComponent, coordinator, entity)
|
||||
transform := coordinator_get_component(TransformComponent, coordinator, entity)
|
||||
|
|
@ -12,5 +17,13 @@ physics_system_update :: proc(physics_system: ^PhysicsSystem, coordinator: ^Coor
|
|||
|
||||
transform.position += rigid_body.velocity * dt
|
||||
rigid_body.velocity += gravity.force * dt
|
||||
|
||||
if transform.position.y < -15 {
|
||||
append(&entities_to_delete, entity)
|
||||
}
|
||||
}
|
||||
|
||||
for entity in entities_to_delete {
|
||||
coordinator_destroy_entity(coordinator, entity)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue