From efc5f4570f4953c9c2bb868a9185e45b1d73e40d Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 26 Aug 2019 14:52:03 +0200 Subject: [PATCH] Remove duplicate code from control.cpp --- Source/control.cpp | 130 +++++---------------------------------------- Source/control.h | 2 +- 2 files changed, 13 insertions(+), 119 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 71df25bda..93fd773bf 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -170,58 +170,17 @@ int SpellPages[6][7] = { { -1, -1, -1, -1, -1, -1, -1 } }; -void DrawSpellCel(int xp, int yp, BYTE *Trans, int nCel, int w) +void DrawSpellCel(int xp, int yp, BYTE *pCelBuff, int nCel, int nWidth) { - BYTE *dst, *tbl, *end; - - /// ASSERT: assert(gpBuffer); - - dst = &gpBuffer[xp + PitchTbl[yp]]; - tbl = SplTransTbl; - - int i; - BYTE width; - BYTE *src; + int nDataSize; + BYTE *pRLEBytes; DWORD *pFrameTable; - pFrameTable = (DWORD *)&Trans[4 * nCel]; - src = &Trans[pFrameTable[0]]; - end = &src[pFrameTable[1] - pFrameTable[0]]; - - for (; src != end; dst -= BUFFER_WIDTH + w) { - for (i = w; i;) { - width = *src++; - if (!(width & 0x80)) { - i -= width; - // asm_cel_light_edge(width, tbl, dst, src); - if (width & 1) { - dst[0] = tbl[src[0]]; - src++; - dst++; - } - width >>= 1; - if (width & 1) { - dst[0] = tbl[src[0]]; - dst[1] = tbl[src[1]]; - src += 2; - dst += 2; - } - width >>= 1; - for (; width; width--) { - dst[0] = tbl[src[0]]; - dst[1] = tbl[src[1]]; - dst[2] = tbl[src[2]]; - dst[3] = tbl[src[3]]; - src += 4; - dst += 4; - } - } else { - width = -(char)width; - dst += width; - i -= width; - } - } - } + pFrameTable = (DWORD *)pCelBuff; + pRLEBytes = &pCelBuff[pFrameTable[nCel]]; + nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; + + CelDecDatLightOnly(&gpBuffer[xp + PitchTbl[yp]], pRLEBytes, nDataSize, nWidth, SplTransTbl); } void SetSpellTrans(char t) @@ -490,52 +449,20 @@ void CPrintString(int nOffset, int nCel, char col) { /// ASSERT: assert(gpBuffer); - int i; + int i, nDataSize; BYTE width, pix; BYTE *src, *dst, *end; DWORD *pFrameTable; pFrameTable = (DWORD *)&pPanelText[4 * nCel]; src = &pPanelText[pFrameTable[0]]; - end = &src[pFrameTable[1] - pFrameTable[0]]; + nDataSize = pFrameTable[1] - pFrameTable[0]; + end = &src[nDataSize]; dst = &gpBuffer[nOffset]; switch (col) { case COL_WHITE: - for (; src != end; dst -= BUFFER_WIDTH + 13) { - for (i = 13; i;) { - width = *src++; - if (!(width & 0x80)) { - i -= width; - if (width & 1) { - dst[0] = src[0]; - src++; - dst++; - } - width >>= 1; - if (width & 1) { - dst[0] = src[0]; - dst[1] = src[1]; - src += 2; - dst += 2; - } - width >>= 1; - while (width) { - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - dst[3] = src[3]; - src += 4; - dst += 4; - width--; - } - } else { - width = -(char)width; - dst += width; - i -= width; - } - } - } + CelDrawDatOnly(dst, src, nDataSize, 13); break; case COL_BLUE: for (; src != end; dst -= BUFFER_WIDTH + 13) { @@ -1550,39 +1477,6 @@ void DrawChr() ADD_PlrStringXY(143, 332, 174, chrstr, col); } -/** - * @brief Identical to MY_PlrStringXY(x, y, width, pszStr, col, 1) - */ -void ADD_PlrStringXY(int x, int y, int width, char *pszStr, char col) -{ - BYTE c; - char *tmp; - int nOffset, screen_x, line, widthOffset; - - nOffset = x + PitchTbl[y + SCREEN_Y] + 64; - widthOffset = width - x + 1; - line = 0; - screen_x = 0; - tmp = pszStr; - while (*tmp) { - c = gbFontTransTbl[(BYTE)*tmp++]; - screen_x += fontkern[fontframe[c]] + 1; - } - if (screen_x < widthOffset) - line = (widthOffset - screen_x) >> 1; - nOffset += line; - while (*pszStr) { - c = gbFontTransTbl[(BYTE)*pszStr++]; - c = fontframe[c]; - line += fontkern[c] + 1; - if (c) { - if (line < widthOffset) - CPrintString(nOffset, c, col); - } - nOffset += fontkern[c] + 1; - } -} - void MY_PlrStringXY(int x, int y, int width, char *pszStr, char col, int base) { BYTE c; diff --git a/Source/control.h b/Source/control.h index c2e08e0a5..bd9bc8941 100644 --- a/Source/control.h +++ b/Source/control.h @@ -89,7 +89,7 @@ void control_draw_info_str(); void control_print_info_str(int y, char *str, BOOL center, int lines); void PrintGameStr(int x, int y, char *str, int color); void DrawChr(); -void ADD_PlrStringXY(int x, int y, int width, char *pszStr, char col); +#define ADD_PlrStringXY(x, y, width, pszStr, col) MY_PlrStringXY(x, y, width, pszStr, col, 1) void MY_PlrStringXY(int x, int y, int width, char *pszStr, char col, int base); void CheckLvlBtn(); void ReleaseLvlBtn();