diff options
| author | iamcheeseman <[email protected]> | 2026-03-04 16:12:25 -0500 |
|---|---|---|
| committer | iamcheeseman <[email protected]> | 2026-03-04 16:12:25 -0500 |
| commit | 69bfcb3c5fec6957e00264d24990dd2f1263cd50 (patch) | |
| tree | bab0896b254d9158b31cbe2ae1073562deef230e /src/phys/world.odin | |
| parent | ccd4b29cc358d89d231e602522ca7b35d178b120 (diff) | |
better muntik
Diffstat (limited to 'src/phys/world.odin')
| -rw-r--r-- | src/phys/world.odin | 59 |
1 files changed, 5 insertions, 54 deletions
diff --git a/src/phys/world.odin b/src/phys/world.odin index f569a5d..ecd636d 100644 --- a/src/phys/world.odin +++ b/src/phys/world.odin @@ -26,12 +26,12 @@ destroy_world :: proc() { hm.dynamic_destroy(&world.bodies) } -@(private = "file") +@(private) _hash_bin :: proc(x: i32, y: i32) -> u32 { return transmute(u32)((x * 73856093) ~ (y * 19349663)) } -@(private = "file") +@(private) _world_to_bin :: proc(point: Vec2) -> (i32, i32) { return \ i32(math.floor(point.x / BIN_SIZE)), @@ -60,13 +60,13 @@ get_surrounding_bins :: proc( return neighbors } -@(private = "file") +@(private) _find_bin :: proc(b: Body) -> ^[dynamic]Body_Handle { bin_x, bin_y := _world_to_bin(b.pos + b.rect.start) return &world.bins[_hash_bin(bin_x, bin_y) % BIN_COUNT] } -@(private = "file") +@(private) _add_to_bins :: proc(b: ^Body) { bin := _find_bin(b^) idx := i32(len(bin)) @@ -74,7 +74,7 @@ _add_to_bins :: proc(b: ^Body) { b.bin_idx = idx } -@(private = "file") +@(private) _remove_from_bins :: proc(b: Body) { bin := _find_bin(b) @@ -306,52 +306,3 @@ update_body :: proc(h: Body_Handle) { set_position(h, res_pos) } - -@(require_results) -get_velocity :: proc(h: Body_Handle) -> Vec2 { - return hm.get(&world.bodies, h).vel -} - -set_velocity :: proc(h: Body_Handle, vel: Vec2) { - hm.get(&world.bodies, h).vel = vel -} - -@(require_results) -get_position :: proc(h: Body_Handle) -> Vec2 { - return hm.get(&world.bodies, h).pos -} - -set_position :: proc(h: Body_Handle, new_pos: Vec2) { - b := hm.get(&world.bodies, h) - - prev_bin := _hash_bin(_world_to_bin(b.pos + b.rect.start)) - res_bin := _hash_bin(_world_to_bin(new_pos + b.rect.start)) - - if prev_bin != res_bin { - _remove_from_bins(b^) - b.pos = new_pos - _add_to_bins(b) - } else { - b.pos = new_pos - } -} - -@(require_results) -get_collisions :: proc(h: Body_Handle) -> bit_set[Collision_Type;u8] { - return hm.get(&world.bodies, h).collisions -} - -@(require_results) -get_rect :: proc(h: Body_Handle) -> Rect { - return hm.get(&world.bodies, h).rect -} - -@(require_results) -get_layers :: proc(h: Body_Handle) -> Layer_Set { - return hm.get(&world.bodies, h).layers -} - -@(require_results) -get_mask :: proc(h: Body_Handle) -> Layer_Set { - return hm.get(&world.bodies, h).mask -} |
