diff options
| author | Xander Swan <no email> | 2025-12-23 21:17:29 -0500 |
|---|---|---|
| committer | Xander Swan <no email> | 2025-12-23 21:17:29 -0500 |
| commit | 673c84b1e56f65bcda448b2304e98ff4831100fd (patch) | |
| tree | 5d3f3c58f4dc5e784a8eecd11c136aab7779aeda /src/phys | |
| parent | 2838358993ade2ac1b770d675af9126749074e8f (diff) | |
Move physics objects between bins correctly
Diffstat (limited to 'src/phys')
| -rw-r--r-- | src/phys/world.odin | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/phys/world.odin b/src/phys/world.odin index 66479e8..0f03de7 100644 --- a/src/phys/world.odin +++ b/src/phys/world.odin @@ -72,13 +72,14 @@ add_to_bins :: proc(b: Body) { bin := find_bin(b) idx := i32(len(bin)) append(bin, b.handle) - world.bodies[bin[idx]].bin_idx = idx + world.bodies[b.handle].bin_idx = idx } @(private="file") remove_from_bins :: proc(b: Body) { bin := find_bin(b) + assert(len(bin) > 0) assert(bin[b.bin_idx] == b.handle) last := pop(bin) @@ -194,14 +195,15 @@ update_body :: proc(h: Body_Handle) { b.vel.y = 0 } - b.pos = res_pos - prev_bin := hash_bin(world_to_bin(b.pos + b.rect.start)) res_bin := hash_bin(world_to_bin(res_pos + b.rect.start)) if prev_bin != res_bin { remove_from_bins(b^) + b.pos = res_pos add_to_bins(b^) + } else { + b.pos = res_pos } } |
