Implement drawlist updating for decreasing y
This commit is contained in:
parent
f3c9d6ac30
commit
765e2c32c8
44
game/main.c
44
game/main.c
@ -646,6 +646,44 @@ static void update_drawlist(dynentity_t *e, entity_t **drawlist)
|
||||
n->prev->next = (entity_t *)e;
|
||||
n->prev = (entity_t *)e;
|
||||
}
|
||||
} else {
|
||||
// The entity moved up -- this is mostly symmetric with the
|
||||
// above case.
|
||||
entity_t *n = e->e.prev;
|
||||
if (n == NULL)
|
||||
return;
|
||||
|
||||
const int y = dynentity_bottom(e);
|
||||
int prevy = entity_bottom(n);
|
||||
if (y >= prevy)
|
||||
return;
|
||||
|
||||
while (n->prev != NULL && y < prevy) {
|
||||
n = n->prev;
|
||||
prevy = entity_bottom(n);
|
||||
}
|
||||
assert(n != NULL);
|
||||
|
||||
if (y < prevy) {
|
||||
e->e.prev->next = e->e.next;
|
||||
e->e.next->prev = e->e.prev;
|
||||
|
||||
e->e.prev = NULL;
|
||||
e->e.next = n;
|
||||
*drawlist = n->prev = (entity_t *)e;
|
||||
} else {
|
||||
if (e->e.next == NULL) {
|
||||
e->e.prev->next = NULL;
|
||||
} else {
|
||||
e->e.next->prev = e->e.prev;
|
||||
e->e.prev->next = e->e.next;
|
||||
}
|
||||
|
||||
e->e.next = n->next;
|
||||
e->e.prev = n;
|
||||
n->next->prev = (entity_t *)e;
|
||||
n->next = (entity_t *)e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -675,7 +713,8 @@ static void update_dynentity(gamestate_t *state, dynentity_t *e, double dt)
|
||||
e->svar = SPRITE_DIR_UP;
|
||||
}
|
||||
|
||||
// Apply velocity (handling map collisions)
|
||||
// Apply velocity, handling map collisions and updating the
|
||||
// drawlist
|
||||
const double nextx = e->pos.x + dt * e->speed * e->dir.x;
|
||||
const double nexty = e->pos.y + dt * e->speed * e->dir.y;
|
||||
const dvec_t pfb
|
||||
@ -692,8 +731,7 @@ static void update_dynentity(gamestate_t *state, dynentity_t *e, double dt)
|
||||
if (valid) {
|
||||
e->pos.x = nextx;
|
||||
e->pos.y = nexty;
|
||||
|
||||
update_drawlist(e);
|
||||
update_drawlist(e, &state->drawlist);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user