Browse Source

Drop dpiece_defs_map_1 memory access optimization

This also gets rid of IsometricCoord. They where used to map tiles in a
way that had a simpler access pattern when rendering the screen in
visual oriented rows.
See
https://github.com/diasurgical/devilution/pull/544#issuecomment-450968761
pull/380/head
Anders Jenbo 7 years ago
parent
commit
2079b67475
  1. 23
      Source/gendung.cpp
  2. 3
      Source/gendung.h
  3. 6
      Source/objects.cpp
  4. 6
      Source/player.cpp
  5. 5
      Source/scrollrt.cpp
  6. 6
      Source/town.cpp

23
Source/gendung.cpp

@ -13,7 +13,6 @@ BYTE *pSpeedCels;
int nlevel_frames;
BYTE pdungeon[DMAXX][DMAXY];
char dDead[MAXDUNX][MAXDUNY];
MICROS dpiece_defs_map_1[MAXDUNX * MAXDUNY];
char dPreLight[MAXDUNX][MAXDUNY];
char TransVal;
int MicroTileLen;
@ -334,27 +333,6 @@ void SwapTile(int f1, int f2)
level_frame_sizes[f2] = swap;
}
int IsometricCoord(int x, int y)
{
if (x < MAXDUNY - y)
return (y + y * y + x * (x + 2 * y + 3)) / 2;
x = MAXDUNX - x - 1;
y = MAXDUNY - y - 1;
return MAXDUNX * MAXDUNY - ((y + y * y + x * (x + 2 * y + 3)) / 2) - 1;
}
void SetSpeedCels()
{
int x, y;
for (x = 0; x < MAXDUNX; x++) {
for (y = 0; y < MAXDUNY; y++) {
dpiece_defs_map_1[IsometricCoord(x, y)] = dpiece_defs_map_2[x][y];
}
}
}
void SetDungeonMicros()
{
int i, x, y, lv, blocks;
@ -389,7 +367,6 @@ void SetDungeonMicros()
}
MakeSpeedCels();
SetSpeedCels();
if (zoomflag) {
scr_pix_width = SCREEN_WIDTH;

3
Source/gendung.h

@ -13,7 +13,6 @@ extern BYTE *pSpeedCels;
extern int nlevel_frames;
extern BYTE pdungeon[DMAXX][DMAXY];
extern char dDead[MAXDUNX][MAXDUNY];
extern MICROS dpiece_defs_map_1[MAXDUNX * MAXDUNY];
extern char dPreLight[MAXDUNX][MAXDUNY];
extern char TransVal;
extern int MicroTileLen;
@ -73,8 +72,6 @@ void FillSolidBlockTbls();
void MakeSpeedCels();
void SortTiles(int frames);
void SwapTile(int f1, int f2);
int IsometricCoord(int x, int y);
void SetSpeedCels();
void SetDungeonMicros();
void DRLG_InitTrans();
void DRLG_MRectTrans(int x1, int y1, int x2, int y2);

6
Source/objects.cpp

@ -1816,7 +1816,7 @@ void ObjSetMicro(int dx, int dy, int pn)
dPiece[dx][dy] = pn;
pn--;
defs = &dpiece_defs_map_1[IsometricCoord(dx, dy)];
defs = &dpiece_defs_map_2[dx][dy];
if (leveltype != DTYPE_HELL) {
v = (WORD *)pLevelPieces + 10 * pn;
for (i = 0; i < 10; i++) {
@ -1839,8 +1839,8 @@ void objects_set_door_piece(int x, int y)
v1 = *((WORD *)pLevelPieces + 10 * pn + 8);
v2 = *((WORD *)pLevelPieces + 10 * pn + 9);
dpiece_defs_map_1[IsometricCoord(x, y)].mt[0] = SDL_SwapLE16(v1);
dpiece_defs_map_1[IsometricCoord(x, y)].mt[1] = SDL_SwapLE16(v2);
dpiece_defs_map_2[x][y].mt[0] = SDL_SwapLE16(v1);
dpiece_defs_map_2[x][y].mt[1] = SDL_SwapLE16(v2);
}
void ObjSetMini(int x, int y, int v)

6
Source/player.cpp

@ -967,7 +967,7 @@ void CheckEFlag(int pnum, BOOL flag)
x = plr[pnum].WorldX - 1;
y = plr[pnum].WorldY + 1;
bitflags = 0;
pieces = &dpiece_defs_map_1[IsometricCoord(x, y)];
pieces = &dpiece_defs_map_2[x][y];
for (i = 2; i < 10; i++) {
bitflags |= pieces->mt[i];
@ -986,7 +986,7 @@ void CheckEFlag(int pnum, BOOL flag)
x = plr[pnum].WorldX;
y = plr[pnum].WorldY + 2;
bitflags = 0;
pieces = &dpiece_defs_map_1[IsometricCoord(x, y)];
pieces = &dpiece_defs_map_2[x][y];
for (i = 2; i < 10; i++) {
bitflags |= pieces->mt[i];
@ -999,7 +999,7 @@ void CheckEFlag(int pnum, BOOL flag)
x = plr[pnum].WorldX - 2;
y = plr[pnum].WorldY + 1;
bitflags = 0;
pieces = &dpiece_defs_map_1[IsometricCoord(x, y)];
pieces = &dpiece_defs_map_2[x][y];
for (i = 2; i < 10; i++) {
bitflags |= pieces->mt[i];

5
Source/scrollrt.cpp

@ -432,7 +432,7 @@ static void scrollrt_draw_e_flag(BYTE *pBuff, int x, int y, int sx, int sy)
light_table_index = dLight[x][y];
dst = pBuff;
cel_transparency_active = (BYTE)(nTransTable[level_piece_id] & TransList[dTransVal[x][y]]);
pMap = &dpiece_defs_map_1[IsometricCoord(x, y)];
pMap = &dpiece_defs_map_2[x][y];
arch_draw_type = 1;
level_cel_block = pMap->mt[0];
@ -683,7 +683,6 @@ static void scrollrt_draw(int x, int y, int sx, int sy, int chunks, int dPieceRo
chunks++;
}
pMap = &dpiece_defs_map_1[IsometricCoord(x, y)];
for (j = 0; j < chunks; j++) {
if (y >= 0 && y < MAXDUNY && x >= 0 && x < MAXDUNX) {
@ -691,6 +690,7 @@ static void scrollrt_draw(int x, int y, int sx, int sy, int chunks, int dPieceRo
light_table_index = dLight[x][y];
if (level_piece_id != 0) {
dst = &gpBuffer[sx + sy * BUFFER_WIDTH];
pMap = &dpiece_defs_map_2[x][y];
cel_transparency_active = (BYTE)(nTransTable[level_piece_id] & TransList[dTransVal[x][y]]);
arch_draw_type = 1;
level_cel_block = pMap->mt[0];
@ -722,7 +722,6 @@ static void scrollrt_draw(int x, int y, int sx, int sy, int chunks, int dPieceRo
x++;
y--;
sx += 64;
pMap++;
}
}

6
Source/town.cpp

@ -46,7 +46,7 @@ void town_draw_e_flag(BYTE *pBuff, int x, int y, int capChunks, int sx, int sy)
MICROS *pMap;
dst = pBuff;
pMap = &dpiece_defs_map_1[IsometricCoord(x, y)];
pMap = &dpiece_defs_map_2[x][y];
for (i = 0; i < 7; i++) {
if (capChunks >= i) {
@ -154,7 +154,7 @@ void town_draw(int x, int y, int sx, int sy, int chunks, int dPieceRow)
level_cel_block = dPiece[x][y];
if (level_cel_block != 0) {
dst = &gpBuffer[sx + BUFFER_WIDTH * sy];
pMap = &dpiece_defs_map_1[IsometricCoord(x, y)];
pMap = &dpiece_defs_map_2[x][y];
for (i = 0; i < MicroTileLen >> 1; i++) {
level_cel_block = pMap->mt[2 * i];
if (level_cel_block != 0) {
@ -190,7 +190,7 @@ void SetTownMicros()
for (y = 0; y < MAXDUNY; y++) {
for (x = 0; x < MAXDUNX; x++) {
lv = dPiece[x][y];
pMap = &dpiece_defs_map_1[IsometricCoord(x, y)];
pMap = &dpiece_defs_map_2[x][y];
if (lv != 0) {
lv--;
pPiece = (WORD *)&pLevelPieces[32 * lv];

Loading…
Cancel
Save