diff options
| author | Joel Stålnacke <joel@saker.fi> | 2026-03-23 19:50:18 +0200 |
|---|---|---|
| committer | Joel Stålnacke <joel@saker.fi> | 2026-03-23 19:50:18 +0200 |
| commit | 3a1f9fe6800ef5fe7bbf1c0a5976720383ba84fe (patch) | |
| tree | f1218eb4085a654f6bb70671b41b4a74e646c052 /lib/systems.odin | |
| parent | 3870982f640260822bf605e693782ce9f5d79cf6 (diff) | |
Rewrite native code in Odin and use ECSodin
Diffstat (limited to 'lib/systems.odin')
| -rw-r--r-- | lib/systems.odin | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/systems.odin b/lib/systems.odin new file mode 100644 index 0000000..288bd01 --- /dev/null +++ b/lib/systems.odin @@ -0,0 +1,44 @@ +package djup + +DELTA: f32 : 1.0 / 60.0 + +@(export = true) +sim_tick :: proc "c" (cur, next: ^Snapshot) { + if cur == nil || next == nil { + return + } + context = next.ctx^ + + next.tick = cur.tick + 1 + copy(next.metadata, cur.metadata) + + player_input_system(cur, next) + ball_movement_system(cur, next) +} + +player_input_system :: proc(cur, next: ^Snapshot) { + for &e, id in soa_zip(m = cur.metadata, input = cur.player_inputs, ball = cur.balls) { + if e.m < {.Exists, .PlayerInput, .Ball} { + continue + } + + PLAYER_ACCELERATION :: 1500 + PLAYER_DRAG :: 2 + + acc := + vec2_normal(e.input.direction) * PLAYER_ACCELERATION + e.ball.velocity * -PLAYER_DRAG + e.ball.velocity += acc * DELTA + next.player_inputs[id] = e.input + } +} + +ball_movement_system :: proc(cur, next: ^Snapshot) { + for &e, id in soa_zip(m = cur.metadata, ball = cur.balls) { + if e.m < {.Exists, .Ball} { + continue + } + + next.balls[id].position = e.ball.velocity * DELTA + next.balls[id].velocity = e.ball.velocity + } +} |
