Quadtree fixes.

This commit is contained in:
Steve 2018-02-12 18:27:12 +00:00
parent 7f257f2740
commit ef9d6db851
2 changed files with 36 additions and 34 deletions

View File

@ -329,10 +329,10 @@ static void checkPlatformContact(void)
int i;
SDL_Rect srcRect;
srcRect.x = self->x - MAP_TILE_SIZE;
srcRect.y = self->y - MAP_TILE_SIZE;
srcRect.w = self->w + MAP_TILE_SIZE * 2;
srcRect.h = self->h + MAP_TILE_SIZE * 2;
srcRect.x = self->x;
srcRect.y = self->y;
srcRect.w = self->w;
srcRect.h = self->h + 8;
candidates = getAllEntsWithin(srcRect.x, srcRect.y, srcRect.w, srcRect.h, NULL);

View File

@ -68,33 +68,35 @@ void initQuadtree(Quadtree *root)
node->ents = malloc(sizeof(Entity*) * node->capacity);
memset(node->ents, 0, sizeof(Entity*) * node->capacity);
if (i == 0)
switch (i)
{
case 0:
node->x = root->x;
node->y = root->y;
node->w = w;
node->h = h;
}
else if (i == 1)
{
break;
case 1:
node->x = root->x + w;
node->y = root->y;
node->w = w;
node->h = h;
}
else if (i == 2)
{
break;
case 2:
node->x = root->x;
node->y = root->y + h;
node->w = w;
node->h = h;
}
else
{
break;
default:
node->x = root->x + w;
node->y = root->y + h;
node->w = w;
node->h = h;
break;
}
initQuadtree(node);
@ -110,7 +112,7 @@ void addToQuadtree(Entity *e, Quadtree *root)
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)
{
@ -152,7 +154,7 @@ static int getIndex(Quadtree *root, int x, int y, int w, int h)
{
if (topQuadrant)
{
index = 1;
index = 0;
}
else if (bottomQuadrant)
{
@ -163,7 +165,7 @@ static int getIndex(Quadtree *root, int x, int y, int w, int h)
{
if (topQuadrant)
{
index = 0;
index = 1;
}
else if (bottomQuadrant)
{
@ -182,7 +184,7 @@ void removeFromQuadtree(Entity *e, Quadtree *root)
{
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)
{