release space client when entity releases. fix aabb test
This commit is contained in:
parent
dc09b65f69
commit
894c2dfa26
@ -118,15 +118,16 @@ struct aabb collider_aabb_from_combined_aabb(struct aabb b0, struct aabb b1)
|
|||||||
|
|
||||||
b32 collider_test_aabb(struct aabb box0, struct aabb box1)
|
b32 collider_test_aabb(struct aabb box0, struct aabb box1)
|
||||||
{
|
{
|
||||||
b32 res = (box0.p0.x >= box1.p0.x && box0.p0.x <= box1.p1.x && box0.p0.y >= box1.p0.y && box0.p0.y <= box1.p1.y) || /* Test box0 top left inside box1 */
|
f32 b0_x0 = box0.p0.x;
|
||||||
(box0.p1.x >= box1.p0.x && box0.p1.x <= box1.p1.x && box0.p0.y >= box1.p0.y && box0.p0.y <= box1.p1.y) || /* Test box0 top right inside box1 */
|
f32 b0_x1 = box0.p1.x;
|
||||||
(box0.p1.x >= box1.p0.x && box0.p1.x <= box1.p1.x && box0.p1.y >= box1.p0.y && box0.p1.y <= box1.p1.y) || /* Test box0 bottom right inside box1 */
|
f32 b1_x0 = box1.p0.x;
|
||||||
(box0.p0.x >= box1.p0.x && box0.p0.x <= box1.p1.x && box0.p1.y >= box1.p0.y && box0.p1.y <= box1.p1.y) || /* Test box0 bottom left inside box1 */
|
f32 b1_x1 = box1.p1.x;
|
||||||
(box1.p0.x >= box0.p0.x && box1.p0.x <= box0.p1.x && box1.p0.y >= box0.p0.y && box1.p0.y <= box0.p1.y) || /* Test box1 top left inside box0 */
|
f32 b0_y0 = box0.p0.y;
|
||||||
(box1.p1.x >= box0.p0.x && box1.p1.x <= box0.p1.x && box1.p0.y >= box0.p0.y && box1.p0.y <= box0.p1.y) || /* Test box1 top right inside box0 */
|
f32 b0_y1 = box0.p1.y;
|
||||||
(box1.p1.x >= box0.p0.x && box1.p1.x <= box0.p1.x && box1.p1.y >= box0.p0.y && box1.p1.y <= box0.p1.y) || /* Test box1 bottom right inside box0 */
|
f32 b1_y0 = box1.p0.y;
|
||||||
(box1.p0.x >= box0.p0.x && box1.p0.x <= box0.p1.x && box1.p1.y >= box0.p0.y && box1.p1.y <= box0.p1.y); /* Test box1 bottom left inside box0 */
|
f32 b1_y1 = box1.p1.y;
|
||||||
return res;
|
return ((b0_x0 >= b1_x0 && b0_x0 <= b1_x1) || (b0_x1 >= b1_x0 && b0_x1 <= b1_x1) || (b1_x0 >= b0_x0 && b1_x0 <= b0_x1) || (b1_x1 >= b0_x0 && b1_x1 <= b0_x1)) &&
|
||||||
|
((b0_y0 >= b1_y0 && b0_y0 <= b1_y1) || (b0_y1 >= b1_y0 && b0_y1 <= b1_y1) || (b1_y0 >= b0_y0 && b1_y0 <= b0_y1) || (b1_y1 >= b0_y0 && b1_y1 <= b0_y1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
|
|||||||
20
src/game.c
20
src/game.c
@ -338,9 +338,7 @@ INTERNAL void release_entities_with_prop(enum entity_prop prop)
|
|||||||
{
|
{
|
||||||
struct temp_arena scratch = scratch_begin_no_conflict();
|
struct temp_arena scratch = scratch_begin_no_conflict();
|
||||||
struct entity_store *store = G.tick.entity_store;
|
struct entity_store *store = G.tick.entity_store;
|
||||||
|
struct space *space = G.space;
|
||||||
/* TODO: Breadth first iteration to only release parent entities (since
|
|
||||||
* child entities will be released along with parent anyway) */
|
|
||||||
|
|
||||||
struct entity **ents_to_release = arena_dry_push(scratch.arena, struct entity *);
|
struct entity **ents_to_release = arena_dry_push(scratch.arena, struct entity *);
|
||||||
u64 ents_to_release_count = 0;
|
u64 ents_to_release_count = 0;
|
||||||
@ -354,10 +352,24 @@ INTERNAL void release_entities_with_prop(enum entity_prop prop)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Release references */
|
||||||
|
for (u64 i = 0; i < ents_to_release_count; ++i) {
|
||||||
|
struct entity *ent = ents_to_release[i];
|
||||||
|
/* Release space client */
|
||||||
|
{
|
||||||
|
struct space_client *space_client = space_client_from_handle(space, ent->space_handle);
|
||||||
|
if (space_client->valid) {
|
||||||
|
space_client_release(space_client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Release from store */
|
||||||
|
/* TODO: Breadth first iteration to only release parent entities (since
|
||||||
|
* child entities will be released along with parent anyway) */
|
||||||
for (u64 i = 0; i < ents_to_release_count; ++i) {
|
for (u64 i = 0; i < ents_to_release_count; ++i) {
|
||||||
struct entity *ent = ents_to_release[i];
|
struct entity *ent = ents_to_release[i];
|
||||||
if (ent->valid) {
|
if (ent->valid) {
|
||||||
/* Release */
|
|
||||||
entity_release(store, ent);
|
entity_release(store, ent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -361,6 +361,7 @@ void phys_prepare_contacts(struct phys_ctx *ctx, u64 phys_iteration)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Mark constraint for removal */
|
/* Mark constraint for removal */
|
||||||
|
constraint_ent->contact_constraint_data.num_points = 0;
|
||||||
entity_disable_prop(constraint_ent, ENTITY_PROP_ACTIVE);
|
entity_disable_prop(constraint_ent, ENTITY_PROP_ACTIVE);
|
||||||
entity_enable_prop(constraint_ent, ENTITY_PROP_RELEASE_THIS_TICK);
|
entity_enable_prop(constraint_ent, ENTITY_PROP_RELEASE_THIS_TICK);
|
||||||
/* Remove from lookup */
|
/* Remove from lookup */
|
||||||
|
|||||||
@ -363,6 +363,7 @@ struct space_client *space_iter_next(struct space_iter *iter)
|
|||||||
struct v2i32 cell_start = iter->cell_start;
|
struct v2i32 cell_start = iter->cell_start;
|
||||||
struct v2i32 cell_end = iter->cell_end;
|
struct v2i32 cell_end = iter->cell_end;
|
||||||
struct v2i32 cell_cur = iter->cell_cur;
|
struct v2i32 cell_cur = iter->cell_cur;
|
||||||
|
i32 span = cell_end.x - cell_start.x;
|
||||||
|
|
||||||
struct space_cell_node *next_node = NULL;
|
struct space_cell_node *next_node = NULL;
|
||||||
if (cell_cur.x >= cell_start.x && cell_cur.x <= cell_end.x && cell_cur.y >= cell_start.y && cell_cur.y <= cell_end.y) {
|
if (cell_cur.x >= cell_start.x && cell_cur.x <= cell_end.x && cell_cur.y >= cell_start.y && cell_cur.y <= cell_end.y) {
|
||||||
@ -391,10 +392,10 @@ struct space_client *space_iter_next(struct space_iter *iter)
|
|||||||
} else {
|
} else {
|
||||||
/* Reached end of cell, find next cell */
|
/* Reached end of cell, find next cell */
|
||||||
b32 nextx = (cell_cur.x + 1) <= cell_end.x;
|
b32 nextx = (cell_cur.x + 1) <= cell_end.x;
|
||||||
b32 nexty = (cell_cur.y + 1) <= cell_end.y;
|
b32 nexty = (nextx == 0) && ((cell_cur.y + 1) <= cell_end.y);
|
||||||
if (nextx || nexty) {
|
if (nextx || nexty) {
|
||||||
cell_cur.x += 1 * nextx;
|
cell_cur.x += nextx - (span * nexty);
|
||||||
cell_cur.y += 1 * nexty;
|
cell_cur.y += nexty;
|
||||||
iter->cell_cur = cell_cur;
|
iter->cell_cur = cell_cur;
|
||||||
struct space_cell *cell = space_get_cell(space, cell_cur);
|
struct space_cell *cell = space_get_cell(space, cell_cur);
|
||||||
next_node = cell->first_node;
|
next_node = cell->first_node;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user