change occupancy mask from an bool array to a bitmask and clean up some bugs
This commit is contained in:
parent
e601e5e85d
commit
eeddecb63c
@ -498,6 +498,7 @@ add_trile :: (name: string, x: s32, y: s32, z: s32, orientation: u8 = 0) {
|
|||||||
array_add(*chunk.groups, group);
|
array_add(*chunk.groups, group);
|
||||||
}
|
}
|
||||||
invalidate_buried_around(*curworld.world, x, y, z);
|
invalidate_buried_around(*curworld.world, x, y, z);
|
||||||
|
chunk_set_occupancy_mask_at(chunk, lx, ly, lz, true);
|
||||||
} @Command
|
} @Command
|
||||||
|
|
||||||
remove_trile :: (x: s32, y: s32, z: s32) {
|
remove_trile :: (x: s32, y: s32, z: s32) {
|
||||||
@ -524,6 +525,7 @@ remove_trile :: (x: s32, y: s32, z: s32) {
|
|||||||
if removed break;
|
if removed break;
|
||||||
}
|
}
|
||||||
if removed invalidate_buried_around(*curworld.world, x, y, z);
|
if removed invalidate_buried_around(*curworld.world, x, y, z);
|
||||||
|
chunk_set_occupancy_mask_at(chunk, lx, ly, lz, false);
|
||||||
} @Command
|
} @Command
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,12 @@
|
|||||||
is_trile_collision :: (fx: float, fy: float, fz: float) -> bool {
|
is_trile_collision :: (fx: float, fy: float, fz: float) -> bool {
|
||||||
x := cast(s32)fx;
|
x := cast(s32)floor(fx);
|
||||||
y := cast(s32)fy;
|
y := cast(s32)floor(fy);
|
||||||
z := cast(s32)fz;
|
z := cast(s32)floor(fz);
|
||||||
world := get_current_world();
|
world := get_current_world();
|
||||||
key := world_to_chunk_coord(x, y, z);
|
key := world_to_chunk_coord(x, y, z);
|
||||||
chunk := table_find_pointer(*world.world.chunks, key);
|
chunk := table_find_pointer(*world.world.chunks, key);
|
||||||
if !chunk then return false;
|
if !chunk then return false;
|
||||||
|
|
||||||
lx, ly, lz := world_to_local(x, y, z);
|
lx, ly, lz := world_to_local(x, y, z);
|
||||||
|
return chunk_get_occupancy_mask_at(chunk, lx, ly, lz);
|
||||||
print("% % %\n", lx, ly, lz);
|
|
||||||
|
|
||||||
return chunk.occupancy_mask[lx][ly][lz];
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,13 +59,38 @@ Chunk :: struct {
|
|||||||
coord: Chunk_Key;
|
coord: Chunk_Key;
|
||||||
groups: [..]Chunk_Trile_Group;
|
groups: [..]Chunk_Trile_Group;
|
||||||
|
|
||||||
occupancy_mask : [32][32][32]bool;
|
// This goes x,z,y so y is the bitmask because
|
||||||
|
// that is useful when we're checking for ground under
|
||||||
|
// entities
|
||||||
|
occupancy_mask : [32][32]u32;
|
||||||
|
|
||||||
sh_probe_grid: sg_image; // 192x4096 RGBA16F 2D texture (2 probes/trile/axis)
|
sh_probe_grid: sg_image; // 192x4096 RGBA16F 2D texture (2 probes/trile/axis)
|
||||||
sh_valid: bool;
|
sh_valid: bool;
|
||||||
sh_dirty: bool;
|
sh_dirty: bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Note: these are local coords inside the chunk
|
||||||
|
chunk_get_occupancy_mask_at :: inline (chunk: *Chunk, lx: u32, ly: u32, lz: u32) -> bool {
|
||||||
|
return (chunk.occupancy_mask[lx][lz] & (cast(u32)1 << ly)) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Note: these are local coords inside the chunk
|
||||||
|
chunk_set_occupancy_mask_at :: inline (chunk: *Chunk, lx: u32, ly: u32, lz: u32, occupied: bool) {
|
||||||
|
if occupied {
|
||||||
|
chunk.occupancy_mask[lx][lz] |= (cast(u32)1 << ly);
|
||||||
|
} else {
|
||||||
|
chunk.occupancy_mask[lx][lz] &= ~(cast(u32)1 << ly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chunk_clear_full_occupancy_mask :: (chunk: *Chunk) {
|
||||||
|
for i: 0..31 {
|
||||||
|
for j: 0..31 {
|
||||||
|
chunk.occupancy_mask[cast(u32)i][cast(u32)j] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Editor_Note :: struct {
|
Editor_Note :: struct {
|
||||||
position : Chunk_Key;
|
position : Chunk_Key;
|
||||||
text : string;
|
text : string;
|
||||||
@ -100,21 +125,14 @@ World :: struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
calculate_and_set_chunk_occupancy_mask :: (chunk: *Chunk) {
|
calculate_and_set_chunk_occupancy_mask :: (chunk: *Chunk) {
|
||||||
print("Calculating occupancy mask for chunk %\n", chunk.coord);
|
chunk_clear_full_occupancy_mask(chunk);
|
||||||
// Clear it first:
|
|
||||||
for i: 0..15 {
|
|
||||||
for j: 0..15 {
|
|
||||||
for k: 0..15 {
|
|
||||||
chunk.occupancy_mask[i][j][k] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for group: chunk.groups {
|
for group: chunk.groups {
|
||||||
// @ToDo: Handle non-colliding triles by getting the
|
// @ToDo: Handle non-colliding triles by getting the
|
||||||
// trile data here and continuing if it's non-colliding.
|
// trile data here and continuing if it's non-colliding.
|
||||||
for instance : group.instances {
|
for instance : group.instances {
|
||||||
chunk.occupancy_mask[instance.x][instance.y][instance.z] = true;
|
|
||||||
|
chunk_set_occupancy_mask_at(chunk, instance.x, instance.y, instance.z, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user