GameLib: Implement GameLib_SearchEntInArea

Queries the `BucketGrid` to return entities in an area.
This commit is contained in:
2024-10-07 19:28:39 +02:00
parent 83e50e79e3
commit 30be2c6f33
2 changed files with 28 additions and 2 deletions

View File

@@ -613,7 +613,7 @@ void GameLib_ForEachEnt(int (*func)(Entity ent)) {
/////////////////////////////
// GameLib_SearchEnt
//
// Searches throught the entities.
// Searches through the entities.
Entity GameLib_SearchEnt(int (*func)(Entity ent, void *d), void *d) {
Entity ent = NULL;
for (int i = 0; i < g_NumEntities; i++) {
@@ -628,6 +628,26 @@ Entity GameLib_SearchEnt(int (*func)(Entity ent, void *d), void *d) {
return ent;
}
/////////////////////////////
// GameLib_SearchEntInArea
//
// Searches through the entities, in an area.
Entity GameLib_SearchEntInArea(int (*func)(Entity ent, void *d), void *d, BBox area) {
TBucket searchBucket;
BucketGrid_Query(&g_BucketGrid, area, &searchBucket);
Entity ent = NULL;
for (int i = 0; i < searchBucket.count; i++) {
ent = searchBucket.bbox[i]->parent;
if (!ent) {
continue;
}
if (func(ent, d)) {
break;
}
}
return ent;
}
/////////////////////////////
// GameLib_EntityCustomCheckCollision
//

View File

@@ -94,9 +94,15 @@ void GameLib_ForEachEnt(int (*func)(Entity ent));
/////////////////////////////
// GameLib_SearchEnt
//
// Searches throught the entities.
// Searches through the entities.
Entity GameLib_SearchEnt(int (*func)(Entity ent, void *d), void *d);
/////////////////////////////
// GameLib_SearchEntInArea
//
// Searches through the entities, in an area.
Entity GameLib_SearchEntInArea(int (*func)(Entity ent, void *d), void *d, BBox area);
/////////////////////////////
// GameLib_EntityCustomCheckCollision
//