summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Millwood <thebenmachine@gmail.com>2011-04-15 18:53:55 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:18:05 +0000
commitd129834d37592d8ae95a7e4f3a2e3bfc47c11851 (patch)
treeea5211e2f71c663ba98e2139f7cc9cac36539843
parentd31e81e51f139354deb7f262062d69920eb2a448 (diff)
* Refactor G_ClosestEnt to avoid (spurious) unused variable warning
-rw-r--r--src/game/g_utils.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/game/g_utils.c b/src/game/g_utils.c
index 2e08afdf..d4a9ef6a 100644
--- a/src/game/g_utils.c
+++ b/src/game/g_utils.c
@@ -771,14 +771,20 @@ gentity_t *G_ClosestEnt( vec3_t origin, gentity_t **entities, int numEntities )
{
int i;
float nd, d;
- gentity_t *closestEnt = NULL;
+ gentity_t *closestEnt;
- for( i = 0; i < numEntities; i++ )
+ if( numEntities <= 0 )
+ return NULL;
+
+ closestEnt = entities[ 0 ];
+ d = DistanceSquared( origin, closestEnt->s.origin );
+
+ for( i = 1; i < numEntities; i++ )
{
gentity_t *ent = entities[ i ];
nd = DistanceSquared( origin, ent->s.origin );
- if( i == 0 || nd < d )
+ if( nd < d )
{
d = nd;
closestEnt = ent;