diff --git a/src/GameLib.c b/src/GameLib.c index 4521c15..464bbb1 100644 --- a/src/GameLib.c +++ b/src/GameLib.c @@ -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 // diff --git a/src/GameLib.h b/src/GameLib.h index 40bed56..002d378 100644 --- a/src/GameLib.h +++ b/src/GameLib.h @@ -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 //