Quadtree fixes.
This commit is contained in:
parent
7f257f2740
commit
ef9d6db851
|
@ -329,10 +329,10 @@ static void checkPlatformContact(void)
|
||||||
int i;
|
int i;
|
||||||
SDL_Rect srcRect;
|
SDL_Rect srcRect;
|
||||||
|
|
||||||
srcRect.x = self->x - MAP_TILE_SIZE;
|
srcRect.x = self->x;
|
||||||
srcRect.y = self->y - MAP_TILE_SIZE;
|
srcRect.y = self->y;
|
||||||
srcRect.w = self->w + MAP_TILE_SIZE * 2;
|
srcRect.w = self->w;
|
||||||
srcRect.h = self->h + MAP_TILE_SIZE * 2;
|
srcRect.h = self->h + 8;
|
||||||
|
|
||||||
candidates = getAllEntsWithin(srcRect.x, srcRect.y, srcRect.w, srcRect.h, NULL);
|
candidates = getAllEntsWithin(srcRect.x, srcRect.y, srcRect.w, srcRect.h, NULL);
|
||||||
|
|
||||||
|
|
|
@ -68,33 +68,35 @@ void initQuadtree(Quadtree *root)
|
||||||
node->ents = malloc(sizeof(Entity*) * node->capacity);
|
node->ents = malloc(sizeof(Entity*) * node->capacity);
|
||||||
memset(node->ents, 0, sizeof(Entity*) * node->capacity);
|
memset(node->ents, 0, sizeof(Entity*) * node->capacity);
|
||||||
|
|
||||||
if (i == 0)
|
switch (i)
|
||||||
{
|
{
|
||||||
node->x = root->x;
|
case 0:
|
||||||
node->y = root->y;
|
node->x = root->x;
|
||||||
node->w = w;
|
node->y = root->y;
|
||||||
node->h = h;
|
node->w = w;
|
||||||
}
|
node->h = h;
|
||||||
else if (i == 1)
|
break;
|
||||||
{
|
|
||||||
node->x = root->x + w;
|
case 1:
|
||||||
node->y = root->y;
|
node->x = root->x + w;
|
||||||
node->w = w;
|
node->y = root->y;
|
||||||
node->h = h;
|
node->w = w;
|
||||||
}
|
node->h = h;
|
||||||
else if (i == 2)
|
break;
|
||||||
{
|
|
||||||
node->x = root->x;
|
case 2:
|
||||||
node->y = root->y + h;
|
node->x = root->x;
|
||||||
node->w = w;
|
node->y = root->y + h;
|
||||||
node->h = h;
|
node->w = w;
|
||||||
}
|
node->h = h;
|
||||||
else
|
break;
|
||||||
{
|
|
||||||
node->x = root->x + w;
|
default:
|
||||||
node->y = root->y + h;
|
node->x = root->x + w;
|
||||||
node->w = w;
|
node->y = root->y + h;
|
||||||
node->h = h;
|
node->w = w;
|
||||||
|
node->h = h;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
initQuadtree(node);
|
initQuadtree(node);
|
||||||
|
@ -110,7 +112,7 @@ void addToQuadtree(Entity *e, Quadtree *root)
|
||||||
|
|
||||||
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->y, e->w, e->h);
|
||||||
|
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
{
|
||||||
|
@ -152,7 +154,7 @@ static int getIndex(Quadtree *root, int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
if (topQuadrant)
|
if (topQuadrant)
|
||||||
{
|
{
|
||||||
index = 1;
|
index = 0;
|
||||||
}
|
}
|
||||||
else if (bottomQuadrant)
|
else if (bottomQuadrant)
|
||||||
{
|
{
|
||||||
|
@ -163,7 +165,7 @@ static int getIndex(Quadtree *root, int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
if (topQuadrant)
|
if (topQuadrant)
|
||||||
{
|
{
|
||||||
index = 0;
|
index = 1;
|
||||||
}
|
}
|
||||||
else if (bottomQuadrant)
|
else if (bottomQuadrant)
|
||||||
{
|
{
|
||||||
|
@ -182,7 +184,7 @@ void removeFromQuadtree(Entity *e, Quadtree *root)
|
||||||
{
|
{
|
||||||
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->y, e->w, e->h);
|
||||||
|
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue