aboutsummaryrefslogtreecommitdiff
path: root/src/phys
diff options
context:
space:
mode:
Diffstat (limited to 'src/phys')
-rw-r--r--src/phys/body.odin30
-rw-r--r--src/phys/world.odin23
2 files changed, 27 insertions, 26 deletions
diff --git a/src/phys/body.odin b/src/phys/body.odin
index 0fe6c51..d568186 100644
--- a/src/phys/body.odin
+++ b/src/phys/body.odin
@@ -7,15 +7,15 @@ Rect :: struct {
size: Vec2,
}
-Layer :: enum(u16) {
+Layer :: enum (u16) {
DEFAULT,
- HARD, // hard collisions; don't let bodies intersect at all
- SOFT, // soft collisions; push away other bodies with a force
- ENEMY, // enemy hitboxes
+ HARD, // hard collisions; don't let bodies intersect at all
+ SOFT, // soft collisions; push away other bodies with a force
+ ENEMY, // enemy hitboxes
PLAYER, // player hitboxes
}
-Collision_Type :: enum(u8) {
+Collision_Type :: enum (u8) {
UP,
DOWN,
RIGHT,
@@ -31,20 +31,23 @@ Body :: struct {
active: bool,
pos: Vec2,
vel: Vec2,
- collisions: bit_set[Collision_Type; u8],
- layers: bit_set[Layer; u16],
- mask: bit_set[Layer; u16],
+ collisions: bit_set[Collision_Type;u8],
+ layers: bit_set[Layer;u16],
+ mask: bit_set[Layer;u16],
}
make_body :: proc(
rect: Rect,
- layers := bit_set[Layer; u16]{.DEFAULT},
- mask := bit_set[Layer; u16]{.DEFAULT},
-) -> (Body_Handle, ^Body) {
+ layers := bit_set[Layer;u16]{.DEFAULT},
+ mask := bit_set[Layer;u16]{.DEFAULT},
+) -> (
+ Body_Handle,
+ ^Body,
+) {
b := Body {
- rect = rect,
+ rect = rect,
layers = layers,
- mask = mask,
+ mask = mask,
active = true,
}
return add_body(b)
@@ -61,4 +64,3 @@ aabb_vert :: proc(a: Rect, b: Rect) -> bool {
aabb :: proc(a: Rect, b: Rect) -> bool {
return aabb_hori(a, b) && aabb_vert(a, b)
}
-
diff --git a/src/phys/world.odin b/src/phys/world.odin
index 51a85a5..c263459 100644
--- a/src/phys/world.odin
+++ b/src/phys/world.odin
@@ -26,19 +26,19 @@ destroy_world :: proc() {
delete(world.bodies)
}
-@(private="file")
+@(private = "file")
hash_bin :: proc(x: i32, y: i32) -> u32 {
return transmute(u32)((x * 73856093) ~ (y * 19349663))
}
-@(private="file")
+@(private = "file")
world_to_bin :: proc(point: Vec2) -> (i32, i32) {
- return \
- i32(math.floor(point.x / BIN_SIZE)),
- i32(math.floor(point.y / BIN_SIZE))
+ return i32(
+ math.floor(point.x / BIN_SIZE),
+ ), i32(math.floor(point.y / BIN_SIZE))
}
-@(private="file")
+@(private = "file")
get_surrounding_bins :: proc(
pos: Vec2,
allocator := context.temp_allocator,
@@ -49,8 +49,8 @@ get_surrounding_bins :: proc(
idx := 0
- for offset_x in -1..=1 {
- for offset_y in -1..=1 {
+ for offset_x in -1 ..= 1 {
+ for offset_y in -1 ..= 1 {
bin_idx := hash_bin(center_x + i32(offset_x), center_y + i32(offset_y))
bin := &world.bins[bin_idx % BIN_COUNT]
neighbors[idx] = bin
@@ -61,13 +61,13 @@ get_surrounding_bins :: proc(
return neighbors
}
-@(private="file")
+@(private = "file")
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 = "file")
add_to_bins :: proc(b: ^Body) {
bin := find_bin(b^)
idx := i32(len(bin))
@@ -75,7 +75,7 @@ add_to_bins :: proc(b: ^Body) {
b.bin_idx = idx
}
-@(private="file")
+@(private = "file")
remove_from_bins :: proc(b: Body) {
bin := find_bin(b)
@@ -214,4 +214,3 @@ set_body_position :: proc(h: Body_Handle, new_pos: Vec2) {
b.pos = new_pos
}
}
-