GameLib: Implement GameLib_SearchEntInArea
Queries the `BucketGrid` to return entities in an area.
This commit is contained in:
@@ -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
|
||||
//
|
||||
|
||||
@@ -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
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user