Don't recurse into quads that haven't had anything added to them.
This commit is contained in:
parent
6d8856deae
commit
7e752ccae4
|
@ -106,6 +106,8 @@ void addToQuadtree(Entity *e, Quadtree *root)
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
root->addedTo = 1;
|
||||||
|
|
||||||
if (root->node[0])
|
if (root->node[0])
|
||||||
{
|
{
|
||||||
index = getIndex(root, e->x - (e->w / 2), e->y - (e->h / 2), e->w, e->h);
|
index = getIndex(root, e->x - (e->w / 2), e->y - (e->h / 2), e->w, e->h);
|
||||||
|
@ -176,6 +178,8 @@ void removeFromQuadtree(Entity *e, Quadtree *root)
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
if (root->addedTo)
|
||||||
|
{
|
||||||
if (root->node[0])
|
if (root->node[0])
|
||||||
{
|
{
|
||||||
index = getIndex(root, e->x - (e->w / 2), e->y - (e->h / 2), e->w, e->h);
|
index = getIndex(root, e->x - (e->w / 2), e->y - (e->h / 2), e->w, e->h);
|
||||||
|
@ -189,6 +193,7 @@ void removeFromQuadtree(Entity *e, Quadtree *root)
|
||||||
|
|
||||||
removeEntity(e, root);
|
removeEntity(e, root);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void removeEntity(Entity *e, Quadtree *root)
|
static void removeEntity(Entity *e, Quadtree *root)
|
||||||
{
|
{
|
||||||
|
@ -222,6 +227,8 @@ static void getAllEntsWithinNode(int x, int y, int w, int h, Entity *ignore, Qua
|
||||||
{
|
{
|
||||||
int index, i;
|
int index, i;
|
||||||
|
|
||||||
|
if (root->addedTo)
|
||||||
|
{
|
||||||
if (root->node[0])
|
if (root->node[0])
|
||||||
{
|
{
|
||||||
index = getIndex(root, x, y, w, h);
|
index = getIndex(root, x, y, w, h);
|
||||||
|
@ -249,6 +256,7 @@ static void getAllEntsWithinNode(int x, int y, int w, int h, Entity *ignore, Qua
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void resizeCandidates(void)
|
static void resizeCandidates(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
||||||
#define QT_MAX_DEPTH 6
|
#define QT_MAX_DEPTH 5
|
||||||
#define QT_INITIAL_CAPACITY 8
|
#define QT_INITIAL_CAPACITY 8
|
||||||
|
|
||||||
extern void *resize(void *array, int oldSize, int newSize);
|
extern void *resize(void *array, int oldSize, int newSize);
|
||||||
|
|
|
@ -304,6 +304,7 @@ struct Quadtree {
|
||||||
Entity **ents;
|
Entity **ents;
|
||||||
int capacity;
|
int capacity;
|
||||||
int numEnts;
|
int numEnts;
|
||||||
|
int addedTo;
|
||||||
Quadtree *node[4];
|
Quadtree *node[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue