From f31cac0ee0633c4102c43293977e4d9ef8af694d Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 11 Jun 2019 00:30:34 +0200 Subject: [PATCH] Clean up Cl2DecodeFrm3, Cl2DecodeFrm5, Cl2DecodeLightTbl & Cl2DecodeFrm6 --- Source/engine.cpp | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/Source/engine.cpp b/Source/engine.cpp index d9bd34d81..1435ea007 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -2897,7 +2897,7 @@ void Cl2DecDatFrm2(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, */ void Cl2DecodeFrm3(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light) { - int nDataStart, nDataSize, nDataCap, idx; + int nDataStart, nDataSize, idx, nSize; BYTE *pRLEBytes, *pDecodeTo; DWORD *pFrameTable; @@ -2925,6 +2925,10 @@ void Cl2DecodeFrm3(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Cel if (!nDataSize) nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; + nSize = nDataSize - nDataStart; + pRLEBytes += nDataStart; + pDecodeTo = &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]]; + idx = light4flag ? 1024 : 4096; if (light == 2) idx += 256; @@ -2932,9 +2936,9 @@ void Cl2DecodeFrm3(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Cel idx += (light - 1) << 8; Cl2DecDatLightTbl1( - &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]], - &pRLEBytes[nDataStart], - nDataSize - nDataStart, + pDecodeTo, + pRLEBytes, + nSize, nWidth, &pLightTbl[idx]); } @@ -3097,7 +3101,7 @@ void Cl2DecDatLightTbl1(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWi */ void Cl2DecodeLightTbl(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { - int nDataStart, nDataSize; + int nDataStart, nDataSize, nSize; BYTE *pRLEBytes, *pDecodeTo; DWORD *pFrameTable; @@ -3125,12 +3129,14 @@ void Cl2DecodeLightTbl(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int if (!nDataSize) nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; + nSize = nDataSize - nDataStart; + pRLEBytes += nDataStart; pDecodeTo = &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]]; if (light_table_index) - Cl2DecDatLightTbl1(pDecodeTo, &pRLEBytes[nDataStart], nDataSize - nDataStart, nWidth, &pLightTbl[light_table_index * 256]); + Cl2DecDatLightTbl1(pDecodeTo, pRLEBytes, nSize, nWidth, &pLightTbl[light_table_index * 256]); else - Cl2DecDatFrm1(pDecodeTo, &pRLEBytes[nDataStart], nDataSize - nDataStart, nWidth); + Cl2DecDatFrm1(pDecodeTo, pRLEBytes, nSize, nWidth); } // 69BEF8: using guessed type int light_table_index; @@ -3555,8 +3561,8 @@ void Cl2DecDatClrHL(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth, */ void Cl2DecodeFrm5(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap, char light) { - int nDataStart, nDataSize, idx; - BYTE *pRLEBytes; + int nDataStart, nDataSize, idx, nSize; + BYTE *pRLEBytes, *pDecodeTo; DWORD *pFrameTable; /// ASSERT: assert(gpBuffer != NULL); @@ -3583,6 +3589,10 @@ void Cl2DecodeFrm5(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Cel if (!nDataSize) nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; + nSize = nDataSize - nDataStart; + pRLEBytes += nDataStart; + pDecodeTo = &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]]; + idx = light4flag ? 1024 : 4096; if (light == 2) idx += 256; @@ -3590,9 +3600,9 @@ void Cl2DecodeFrm5(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Cel idx += (light - 1) << 8; Cl2DecDatLightTbl2( - &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]], - &pRLEBytes[nDataStart], - nDataSize - nDataStart, + pDecodeTo, + pRLEBytes, + nSize, nWidth, &pLightTbl[idx]); } @@ -3769,7 +3779,7 @@ void Cl2DecDatLightTbl2(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWi */ void Cl2DecodeFrm6(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { - int nDataStart, nDataSize; + int nDataStart, nDataSize, nSize; BYTE *pRLEBytes, *pDecodeTo; DWORD *pFrameTable; @@ -3797,12 +3807,14 @@ void Cl2DecodeFrm6(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Cel if (!nDataSize) nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; + nSize = nDataSize - nDataStart; + pRLEBytes += nDataStart; pDecodeTo = &gpBuffer[sx + PitchTbl[sy - 16 * CelSkip]]; if (light_table_index) - Cl2DecDatLightTbl2(pDecodeTo, &pRLEBytes[nDataStart], nDataSize - nDataStart, nWidth, &pLightTbl[light_table_index * 256]); + Cl2DecDatLightTbl2(pDecodeTo, pRLEBytes, nSize, nWidth, &pLightTbl[light_table_index * 256]); else - Cl2DecDatFrm4(pDecodeTo, &pRLEBytes[nDataStart], nDataSize - nDataStart, nWidth); + Cl2DecDatFrm4(pDecodeTo, pRLEBytes, nSize, nWidth); } // 69BEF8: using guessed type int light_table_index;