ent_draw: remove all those multiplies, ORCA uses a multiply to index into an array of structures, ent_ents[i] accesses keep doing multiplies. Recode to use a pointer (something a more modern compiler would just do under the hood)

This commit is contained in:
dwsJason 2018-09-19 21:10:26 -04:00
parent 760db6899c
commit be72cb1705
1 changed files with 35 additions and 31 deletions

View File

@ -343,6 +343,8 @@ ent_draw(void)
#endif #endif
S16 dx, dy; S16 dx, dy;
ent_t *pEnt;
draw_tilesBank = map_tilesBank; draw_tilesBank = map_tilesBank;
/* reset rectangles list */ /* reset rectangles list */
@ -354,89 +356,91 @@ ent_draw(void)
/* /*
* background loop : erase all entities that were visible * background loop : erase all entities that were visible
*/ */
for (i = 0; ent_ents[i].n != 0xff; i++) { for (pEnt=ent_ents; pEnt->n != 0xff; ++pEnt)
{
#ifdef ENABLE_CHEATS #ifdef ENABLE_CHEATS
if (ent_ents[i].prev_n && (ch3 || ent_ents[i].prev_s)) if (pEnt->prev_n && (ch3 || pEnt->prev_s))
#else #else
if (ent_ents[i].prev_n && ent_ents[i].prev_s) if (pEnt->prev_n && pEnt->prev_s)
#endif #endif
/* if entity was active, then erase it (redraw the map) */ /* if entity was active, then erase it (redraw the map) */
draw_spriteBackground(ent_ents[i].prev_x, ent_ents[i].prev_y); draw_spriteBackground(pEnt->prev_x, pEnt->prev_y);
} }
/* /*
* foreground loop : draw all entities that are visible * foreground loop : draw all entities that are visible
*/ */
for (i = 0; ent_ents[i].n != 0xff; i++) { for (pEnt=ent_ents; pEnt->n != 0xff; ++pEnt) {
/* /*
* If entity is active now, draw the sprite. If entity was * If entity is active now, draw the sprite. If entity was
* not active before, add a rectangle for the sprite. * not active before, add a rectangle for the sprite.
*/ */
#ifdef ENABLE_CHEATS #ifdef ENABLE_CHEATS
if (ent_ents[i].n && (game_cheat3 || ent_ents[i].sprite)) if (pEnt->n && (game_cheat3 || pEnt->sprite))
#else #else
if (ent_ents[i].n && ent_ents[i].sprite) if (pEnt->n && pEnt->sprite)
#endif #endif
/* If entitiy is active, draw the sprite. */ /* If entitiy is active, draw the sprite. */
draw_sprite2(ent_ents[i].sprite, draw_sprite2(pEnt->sprite,
ent_ents[i].x, ent_ents[i].y, pEnt->x, pEnt->y,
ent_ents[i].front); pEnt->front);
} }
/* /*
* rectangles loop : figure out which parts of the screen have been * rectangles loop : figure out which parts of the screen have been
* impacted and need to be refreshed, then save state * impacted and need to be refreshed, then save state
*/ */
for (i = 0; ent_ents[i].n != 0xff; i++) { for (pEnt=ent_ents; pEnt->n != 0xff; ++pEnt) {
#ifdef ENABLE_CHEATS #ifdef ENABLE_CHEATS
if (ent_ents[i].prev_n && (ch3 || ent_ents[i].prev_s)) { if (pEnt->prev_n && (ch3 || pEnt->prev_s)) {
#else #else
if (ent_ents[i].prev_n && ent_ents[i].prev_s) { if (pEnt->prev_n && pEnt->prev_s) {
#endif #endif
/* (1) if entity was active and has been drawn ... */ /* (1) if entity was active and has been drawn ... */
#ifdef ENABLE_CHEATS #ifdef ENABLE_CHEATS
if (ent_ents[i].n && (game_cheat3 || ent_ents[i].sprite)) { if (pEnt->n && (game_cheat3 || pEnt->sprite)) {
#else #else
if (ent_ents[i].n && ent_ents[i].sprite) { if (pEnt->n && pEnt->sprite) {
#endif #endif
/* (1.1) ... and is still active now and still needs to be drawn, */ /* (1.1) ... and is still active now and still needs to be drawn, */
/* then check if rectangles intersect */ /* then check if rectangles intersect */
dx = abs(ent_ents[i].x - ent_ents[i].prev_x); dx = abs(pEnt->x - pEnt->prev_x);
dy = abs(ent_ents[i].y - ent_ents[i].prev_y); dy = abs(pEnt->y - pEnt->prev_y);
if (dx < 0x20 && dy < 0x16) { if (dx < 0x20 && dy < 0x16) {
/* (1.1.1) if they do, then create one rectangle */ /* (1.1.1) if they do, then create one rectangle */
ent_addrect((ent_ents[i].prev_x < ent_ents[i].x) ent_addrect((pEnt->prev_x < pEnt->x)
? ent_ents[i].prev_x : ent_ents[i].x, ? pEnt->prev_x : pEnt->x,
(ent_ents[i].prev_y < ent_ents[i].y) (pEnt->prev_y < pEnt->y)
? ent_ents[i].prev_y : ent_ents[i].y, ? pEnt->prev_y : pEnt->y,
dx + 0x20, dy + 0x15); dx + 0x20, dy + 0x15);
} }
else { else {
/* (1.1.2) else, create two rectangles */ /* (1.1.2) else, create two rectangles */
ent_addrect(ent_ents[i].x, ent_ents[i].y, 0x20, 0x15); ent_addrect(pEnt->x, pEnt->y, 0x20, 0x15);
ent_addrect(ent_ents[i].prev_x, ent_ents[i].prev_y, 0x20, 0x15); ent_addrect(pEnt->prev_x, pEnt->prev_y, 0x20, 0x15);
} }
} }
else else
/* (1.2) ... and is not active anymore or does not need to be drawn */ /* (1.2) ... and is not active anymore or does not need to be drawn */
/* then create one single rectangle */ /* then create one single rectangle */
ent_addrect(ent_ents[i].prev_x, ent_ents[i].prev_y, 0x20, 0x15); ent_addrect(pEnt->prev_x, pEnt->prev_y, 0x20, 0x15);
} }
#ifdef ENABLE_CHEATS #ifdef ENABLE_CHEATS
else if (ent_ents[i].n && (game_cheat3 || ent_ents[i].sprite)) { else if (pEnt->n && (game_cheat3 || pEnt->sprite)) {
#else #else
else if (ent_ents[i].n && ent_ents[i].sprite) { else if (pEnt->n && pEnt->sprite) {
#endif #endif
/* (2) if entity is active and needs to be drawn, */ /* (2) if entity is active and needs to be drawn, */
/* then create one rectangle */ /* then create one rectangle */
ent_addrect(ent_ents[i].x, ent_ents[i].y, 0x20, 0x15); ent_addrect(pEnt->x, pEnt->y, 0x20, 0x15);
} }
/* save state */ /* save state */
ent_ents[i].prev_x = ent_ents[i].x; pEnt->prev_x = pEnt->x;
ent_ents[i].prev_y = ent_ents[i].y; pEnt->prev_y = pEnt->y;
ent_ents[i].prev_n = ent_ents[i].n; pEnt->prev_n = pEnt->n;
ent_ents[i].prev_s = ent_ents[i].sprite; pEnt->prev_s = pEnt->sprite;
} }
#ifdef ENABLE_CHEATS #ifdef ENABLE_CHEATS