aboutsummaryrefslogtreecommitdiff
path: root/src/phys
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-03-04 16:12:25 -0500
committeriamcheeseman <[email protected]>2026-03-04 16:12:25 -0500
commit69bfcb3c5fec6957e00264d24990dd2f1263cd50 (patch)
treebab0896b254d9158b31cbe2ae1073562deef230e /src/phys
parentccd4b29cc358d89d231e602522ca7b35d178b120 (diff)
better muntik
Diffstat (limited to 'src/phys')
-rw-r--r--src/phys/body.odin62
-rw-r--r--src/phys/world.odin59
2 files changed, 66 insertions, 55 deletions
diff --git a/src/phys/body.odin b/src/phys/body.odin
index 54177e5..4c9dff1 100644
--- a/src/phys/body.odin
+++ b/src/phys/body.odin
@@ -1,8 +1,9 @@
package phys
+import "core:log"
import "core:math"
import "core:math/linalg"
-import "core:log"
+import hm "core:container/handle_map"
Vec2 :: [2]f32
@@ -45,6 +46,7 @@ Raycast_Collision :: struct {
Body :: struct {
handle: Body_Handle,
+ udata: any,
bin_idx: i32,
rect: Rect,
active: bool,
@@ -157,3 +159,61 @@ raycast_to_aabb :: proc(
return
}
+
+@(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
+}
+
+@(require_results)
+get_udata :: proc(h: Body_Handle) -> any {
+ return hm.get(&world.bodies, h).udata
+}
+
+set_udata :: proc(h: Body_Handle, udata: any) {
+ hm.get(&world.bodies, h).udata = udata
+}
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
-}