31 lines
960 B
Odin
31 lines
960 B
Odin
package ecs
|
|
|
|
import "core:log"
|
|
|
|
import program_config "../config"
|
|
|
|
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)
|
|
gravity := coordinator_get_component(GravityComponent, coordinator, entity)
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
for entity in entities_to_delete {
|
|
coordinator_destroy_entity(coordinator, entity)
|
|
}
|
|
}
|