From d0f1100983845e80fa8c730a1a44cde62334dfe6 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 18 Oct 2019 19:50:14 +0200 Subject: [PATCH] Drop speedcel optimizations Even on VC6 this appears to not improve performance in any noticable way --- Source/diablo.cpp | 5 -- Source/gendung.cpp | 220 --------------------------------------------- Source/gendung.h | 9 -- Source/render.cpp | 24 ----- 4 files changed, 258 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 8b4c4ed03..080e90356 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -73,7 +73,6 @@ void FreeGameMem() MemFreeDbg(pMegaTiles); MemFreeDbg(pLevelPieces); MemFreeDbg(pSpecialCels); - MemFreeDbg(pSpeedCels); FreeMissiles(); FreeMonsters(); @@ -1361,8 +1360,6 @@ void LoadLvlGFX() void LoadAllGFX() { - /// ASSERT: assert(! pSpeedCels); - pSpeedCels = DiabloAllocPtr(0x100000); IncProgress(); IncProgress(); InitObjectGFX(); @@ -1550,8 +1547,6 @@ void LoadGameLevel(BOOL firstflag, int lvldir) ResyncMPQuests(); #ifndef SPAWN } else { - /// ASSERT: assert(! pSpeedCels); - pSpeedCels = DiabloAllocPtr(0x100000); LoadSetMap(); IncProgress(); GetLevelMTypes(); diff --git a/Source/gendung.cpp b/Source/gendung.cpp index 5942581ef..dbf717ebe 100644 --- a/Source/gendung.cpp +++ b/Source/gendung.cpp @@ -9,8 +9,6 @@ BOOLEAN nTransTable[2049]; int dMonster[MAXDUNX][MAXDUNY]; BYTE dungeon[DMAXX][DMAXY]; char dObject[MAXDUNX][MAXDUNY]; -BYTE *pSpeedCels; -int nlevel_frames; BYTE pdungeon[DMAXX][DMAXY]; char dDead[MAXDUNX][MAXDUNY]; char dPreLight[MAXDUNX][MAXDUNY]; @@ -20,7 +18,6 @@ char dflags[DMAXX][DMAXY]; int dPiece[MAXDUNX][MAXDUNY]; char dLight[MAXDUNX][MAXDUNY]; int setloadflag_2; -int tile_defs[MAXTILES]; BYTE *pMegaTiles; BYTE *pLevelPieces; int gnDifficulty; @@ -32,10 +29,8 @@ BYTE leveltype; BYTE currlevel; BOOLEAN TransList[256]; BOOLEAN nSolidTable[2049]; -int level_frame_count[MAXTILES]; ScrollStruct ScrollInfo; BYTE *pDungeonCels; -int SpeedFrameTbl[128][16]; THEME_LOC themeLoc[MAXTHEMES]; char dPlayer[MAXDUNX][MAXDUNY]; int dword_5C2FF8; @@ -48,7 +43,6 @@ BYTE *pSpecialCels; char dFlags[MAXDUNX][MAXDUNY]; char dItem[MAXDUNX][MAXDUNY]; BYTE setlvlnum; -int level_frame_sizes[MAXTILES]; BOOLEAN nMissileTable[2049]; char *pSetPiece_2; char setlvltype; @@ -121,218 +115,6 @@ void FillSolidBlockTbls() mem_free_dbg(pSBFile); } -void MakeSpeedCels() -{ - int i, j, x, y, mt, t, z; - int total_frames, blocks, total_size, frameidx, blk_cnt, nDataSize; - WORD m; - BOOL blood_flag; - DWORD *pFrameTable; - MICROS *pMap; - int l, k; - BYTE width, pix; - BYTE *src, *dst, *tbl; - - for (i = 0; i < MAXTILES; i++) { - tile_defs[i] = i; - level_frame_count[i] = 0; - level_frame_types[i] = 0; - } - - if (leveltype != DTYPE_HELL) - blocks = 10; - else - blocks = 12; - - for (y = 0; y < MAXDUNY; y++) { - for (x = 0; x < MAXDUNX; x++) { - for (i = 0; i < blocks; i++) { - pMap = &dpiece_defs_map_2[x][y]; - mt = pMap->mt[i]; - if (mt) { - level_frame_count[pMap->mt[i] & 0xFFF]++; - level_frame_types[pMap->mt[i] & 0xFFF] = mt & 0x7000; - } - } - } - } - - pFrameTable = (DWORD *)pDungeonCels; - nDataSize = SwapLE32(pFrameTable[0]); - nlevel_frames = nDataSize & 0xFFFF; - - for (i = 1; i < nlevel_frames; i++) { - z = i; - nDataSize = CelGetFrameSize(pDungeonCels, i); - level_frame_sizes[i] = nDataSize & 0xFFFF; - } - - level_frame_sizes[0] = 0; - - if (leveltype == DTYPE_HELL) { - for (i = 0; i < nlevel_frames; i++) { - if (i == 0) - level_frame_count[0] = 0; - z = i; - blood_flag = TRUE; - if (level_frame_count[i] != 0) { - if (level_frame_types[i] != 0x1000) { - src = CelGetFrameStart(pDungeonCels, i); - for (j = level_frame_sizes[i]; j; j--) { - pix = *src++; - if (pix && pix < 32) - blood_flag = FALSE; - } - } else { - src = CelGetFrameStart(pDungeonCels, i); - for (k = 32; k; k--) { - for (l = 32; l;) { - width = *src++; - if (!(width & 0x80)) { - l -= width; - while (width) { - pix = *src++; - if (pix && pix < 32) - blood_flag = FALSE; - width--; - } - } else { - width = -(char)width; - l -= width; - } - } - } - } - if (!blood_flag) - level_frame_count[i] = 0; - } - } - } - - SortTiles(MAXTILES - 1); - total_size = 0; - total_frames = 0; - - if (light4flag) { - while (total_size < 0x100000) { - total_size += level_frame_sizes[total_frames] << 1; - total_frames++; - } - } else { - while (total_size < 0x100000) { - total_size += (level_frame_sizes[total_frames] << 4) - (level_frame_sizes[total_frames] << 1); - total_frames++; - } - } - - total_frames--; - if (total_frames > 128) - total_frames = 128; - - frameidx = 0; /* move into loop ? */ - - if (light4flag) - blk_cnt = 3; - else - blk_cnt = 15; - - for (i = 0; i < total_frames; i++) { - z = tile_defs[i]; - SpeedFrameTbl[i][0] = z; - if (level_frame_types[i] != 0x1000) { - t = level_frame_sizes[i]; - for (j = 1; j < blk_cnt; j++) { - SpeedFrameTbl[i][j] = frameidx; - src = CelGetFrameStart(pDungeonCels, z); - dst = &pSpeedCels[frameidx]; - tbl = &pLightTbl[256 * j]; - for (k = t; k; k--) { - *dst++ = tbl[*src++]; - } - frameidx += t; - } - } else { - for (j = 1; j < blk_cnt; j++) { - SpeedFrameTbl[i][j] = frameidx; - src = CelGetFrameStart(pDungeonCels, z); - dst = &pSpeedCels[frameidx]; - tbl = &pLightTbl[256 * j]; - for (k = 32; k; k--) { - for (l = 32; l;) { - width = *src++; - *dst++ = width; - if (!(width & 0x80)) { - l -= width; - while (width) { - *dst++ = tbl[*src++]; - width--; - } - } else { - width = -(char)width; - l -= width; - } - } - } - frameidx += level_frame_sizes[i]; - } - } - } - - for (y = 0; y < MAXDUNY; y++) { - for (x = 0; x < MAXDUNX; x++) { - if (dPiece[x][y]) { - pMap = &dpiece_defs_map_2[x][y]; - for (i = 0; i < blocks; i++) { - if (pMap->mt[i]) { - for (m = 0; m < total_frames; m++) { - if ((pMap->mt[i] & 0xFFF) == tile_defs[m]) { - pMap->mt[i] = m + level_frame_types[m] + 0x8000; - m = total_frames; - } - } - } - } - } - } - } -} - -void SortTiles(int frames) -{ - int i; - BOOL doneflag; - - doneflag = FALSE; - while (frames > 0 && !doneflag) { - doneflag = TRUE; - for (i = 0; i < frames; i++) { - if (level_frame_count[i] < level_frame_count[i + 1]) { - SwapTile(i, i + 1); - doneflag = FALSE; - } - } - frames--; - } -} - -void SwapTile(int f1, int f2) -{ - int swap; - - swap = level_frame_count[f1]; - level_frame_count[f1] = level_frame_count[f2]; - level_frame_count[f2] = swap; - swap = tile_defs[f1]; - tile_defs[f1] = tile_defs[f2]; - tile_defs[f2] = swap; - swap = level_frame_types[f1]; - level_frame_types[f1] = level_frame_types[f2]; - level_frame_types[f2] = swap; - swap = level_frame_sizes[f1]; - level_frame_sizes[f1] = level_frame_sizes[f2]; - level_frame_sizes[f2] = swap; -} - void SetDungeonMicros() { int i, x, y, lv, blocks; @@ -366,8 +148,6 @@ void SetDungeonMicros() } } - MakeSpeedCels(); - if (zoomflag) { scr_pix_width = SCREEN_WIDTH; scr_pix_height = VIEWPORT_HEIGHT; diff --git a/Source/gendung.h b/Source/gendung.h index 262464106..6f79f2a3b 100644 --- a/Source/gendung.h +++ b/Source/gendung.h @@ -9,8 +9,6 @@ extern BOOLEAN nTransTable[2049]; extern int dMonster[MAXDUNX][MAXDUNY]; extern BYTE dungeon[DMAXX][DMAXY]; extern char dObject[MAXDUNX][MAXDUNY]; -extern BYTE *pSpeedCels; -extern int nlevel_frames; extern BYTE pdungeon[DMAXX][DMAXY]; extern char dDead[MAXDUNX][MAXDUNY]; extern char dPreLight[MAXDUNX][MAXDUNY]; @@ -20,7 +18,6 @@ extern char dflags[DMAXX][DMAXY]; extern int dPiece[MAXDUNX][MAXDUNY]; extern char dLight[MAXDUNX][MAXDUNY]; extern int setloadflag_2; -extern int tile_defs[MAXTILES]; extern BYTE *pMegaTiles; extern BYTE *pLevelPieces; extern int gnDifficulty; @@ -32,10 +29,8 @@ extern BYTE leveltype; extern BYTE currlevel; extern BOOLEAN TransList[256]; extern BOOLEAN nSolidTable[2049]; -extern int level_frame_count[MAXTILES]; extern ScrollStruct ScrollInfo; extern BYTE *pDungeonCels; -extern int SpeedFrameTbl[128][16]; extern THEME_LOC themeLoc[MAXTHEMES]; extern char dPlayer[MAXDUNX][MAXDUNY]; extern int dword_5C2FF8; @@ -48,7 +43,6 @@ extern BYTE *pSpecialCels; extern char dFlags[MAXDUNX][MAXDUNY]; extern char dItem[MAXDUNX][MAXDUNY]; extern BYTE setlvlnum; -extern int level_frame_sizes[MAXTILES]; extern BOOLEAN nMissileTable[2049]; extern char *pSetPiece_2; extern char setlvltype; @@ -69,9 +63,6 @@ extern int dminy; extern MICROS dpiece_defs_map_2[MAXDUNX][MAXDUNY]; void FillSolidBlockTbls(); -void MakeSpeedCels(); -void SortTiles(int frames); -void SwapTile(int f1, int f2); void SetDungeonMicros(); void DRLG_InitTrans(); void DRLG_MRectTrans(int x1, int y1, int x2, int y2); diff --git a/Source/render.cpp b/Source/render.cpp index c11acc051..6b43d7587 100644 --- a/Source/render.cpp +++ b/Source/render.cpp @@ -3,7 +3,6 @@ DEVILUTION_BEGIN_NAMESPACE #define NO_OVERDRAW -#define USE_SPEEDCELS typedef enum { RT_SQUARE, @@ -118,11 +117,7 @@ inline static void RenderLine(BYTE **dst, BYTE **src, int n, BYTE *tbl, DWORD ma for (i = 0; i < n; i++, (*dst)++) { (*dst)[0] = 0; } -#ifdef USE_SPEEDCELS - } else if (tbl == NULL) { -#else } else if (light_table_index == 0) { -#endif for (i = n & 3; i != 0; i--, (*src)++, (*dst)++) { (*dst)[0] = (*src)[0]; } @@ -143,11 +138,7 @@ inline static void RenderLine(BYTE **dst, BYTE **src, int n, BYTE *tbl, DWORD ma (*dst)[0] = 0; } } -#ifdef USE_SPEEDCELS - } else if (tbl == NULL) { -#else } else if (light_table_index == 0) { -#endif for (i = 0; i < n; i++, (*src)++, (*dst)++, mask <<= 1) { if (mask & 0x80000000) { (*dst)[0] = (*src)[0]; @@ -180,21 +171,6 @@ void RenderTile(BYTE *pBuff) tile = (level_cel_block & 0x7000) >> 12; tbl = &pLightTbl[256 * light_table_index]; -#ifdef USE_SPEEDCELS - if (light_table_index == lightmax || light_table_index == 0) { - if (level_cel_block & 0x8000) { - level_cel_block = SpeedFrameTbl[level_cel_block & 0xFFF][0] + (level_cel_block & 0xF000); - } - src = &pDungeonCels[SDL_SwapLE32(pFrameTable[level_cel_block & 0xFFF])]; - tile = (level_cel_block & 0x7000) >> 12; - tbl = NULL; - } else if (level_cel_block & 0x8000) { - src = &pSpeedCels[SpeedFrameTbl[level_cel_block & 0xFFF][light_table_index]]; - tile = (level_cel_block & 0x7000) >> 12; - tbl = NULL; - } -#endif - mask = &SolidMask[31]; if (cel_transparency_active) {