diff options
Diffstat (limited to 'src/phys')
| -rw-r--r-- | src/phys/world.odin | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/phys/world.odin b/src/phys/world.odin index 8470872..51a85a5 100644 --- a/src/phys/world.odin +++ b/src/phys/world.odin @@ -68,11 +68,11 @@ find_bin :: proc(b: Body) -> ^[dynamic]Body_Handle { } @(private="file") -add_to_bins :: proc(b: Body) { - bin := find_bin(b) +add_to_bins :: proc(b: ^Body) { + bin := find_bin(b^) idx := i32(len(bin)) append(bin, b.handle) - world.bodies[b.handle].bin_idx = idx + b.bin_idx = idx } @(private="file") @@ -84,8 +84,10 @@ remove_from_bins :: proc(b: Body) { last := pop(bin) if last != b.handle { + // log.debug(last, b.handle) + last_body := get_body(last) bin[b.bin_idx] = last - world.bodies[last].bin_idx = b.bin_idx + last_body.bin_idx = b.bin_idx } } @@ -113,7 +115,7 @@ add_body :: proc(b: Body) -> (Body_Handle, ^Body) { body := &world.bodies[world.handles[handle]] body.handle = handle - add_to_bins(body^) + add_to_bins(body) return handle, body } @@ -125,11 +127,11 @@ remove_body :: proc(h: Body_Handle) { last := pop(&world.bodies) if last.handle != h { - world.bodies[h] = last + world.bodies[world.handles[h]] = last world.handles[last.handle] = world.handles[h] } - append(&world.unused_handles, b.handle) + append(&world.unused_handles, h) } update_body :: proc(h: Body_Handle) { @@ -207,7 +209,7 @@ set_body_position :: proc(h: Body_Handle, new_pos: Vec2) { if prev_bin != res_bin { remove_from_bins(b^) b.pos = new_pos - add_to_bins(b^) + add_to_bins(b) } else { b.pos = new_pos } |
