Separate input component
This commit is contained in:
parent
29e7b5e499
commit
705f498daa
9 changed files with 318 additions and 178 deletions
30
ecs/input_system.odin
Normal file
30
ecs/input_system.odin
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package ecs
|
||||
|
||||
import sa "../sokol/app"
|
||||
|
||||
InputSystem :: struct {
|
||||
using base: SystemBase,
|
||||
}
|
||||
|
||||
input_system_update :: proc(input_system: ^InputSystem, coordinator: ^Coordinator, event: ^sa.Event) {
|
||||
for entity in input_system.entities {
|
||||
input := coordinator_get_component(InputComponent, coordinator, entity)
|
||||
|
||||
#partial switch event.type {
|
||||
case .MOUSE_MOVE:
|
||||
input.mouse_movement += {event.mouse_dx, event.mouse_dy}
|
||||
case .KEY_DOWN:
|
||||
input.key_down[event.key_code] = true
|
||||
case .KEY_UP:
|
||||
input.key_down[event.key_code] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
input_system_mouse_reset :: proc(input_system: ^InputSystem, coordinator: ^Coordinator) {
|
||||
for entity in input_system.entities {
|
||||
input := coordinator_get_component(InputComponent, coordinator, entity)
|
||||
|
||||
input.mouse_movement = { 0, 0 }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue