Standardise and make ECS more robust
This commit is contained in:
parent
b9aaeb62c9
commit
2ba1022f79
13 changed files with 245 additions and 232 deletions
|
|
@ -5,23 +5,23 @@ import "core:log"
|
|||
import program_config "../config"
|
||||
|
||||
PhysicsSystem :: struct {
|
||||
using base: SystemBase,
|
||||
using _: 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)
|
||||
gravity := coordinator_get_component(GravityComponent, coordinator, entity)
|
||||
for entity_id in physics_system.entities {
|
||||
rigid_body := coordinator_get_component(coordinator, RigidBodyComponent, entity_id)
|
||||
transform := coordinator_get_component(coordinator, TransformComponent, entity_id)
|
||||
gravity := coordinator_get_component(coordinator, GravityComponent, entity_id)
|
||||
|
||||
transform.position += rigid_body.velocity * dt
|
||||
rigid_body.velocity += gravity.force * dt
|
||||
|
||||
if transform.position.y < program_config.Y_DESPAWN_CUTOFF {
|
||||
append(&entities_to_delete, entity)
|
||||
append(&entities_to_delete, entity_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue