From 7d1b0f24f7ccea0fb155166ad688ed05586c24eb Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 20 Oct 2019 01:00:27 +0200 Subject: [PATCH] Eliminate overdraw in cell functions --- Source/engine.cpp | 26 +++++++++++++------------- Source/init.cpp | 1 + Source/render.cpp | 18 ++++-------------- Source/scrollrt.cpp | 15 +++++++++++---- Source/scrollrt.h | 1 + 5 files changed, 30 insertions(+), 31 deletions(-) diff --git a/Source/engine.cpp b/Source/engine.cpp index 1646621cd..1ff92fc7f 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -196,7 +196,7 @@ void CelBlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) width = *src++; if (!(width & 0x80)) { i -= width; - if (dst < gpBufEnd) { + if (dst < gpBufEnd && dst > gpBufStart) { if (width & 1) { dst[0] = src[0]; src++; @@ -290,7 +290,7 @@ void CelBlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidt width = *src++; if (!(width & 0x80)) { i -= width; - if (dst < gpBufEnd) { + if (dst < gpBufEnd && dst > gpBufStart) { if (width & 1) { dst[0] = tbl[src[0]]; src++; @@ -359,7 +359,7 @@ void CelBlitLightTransSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int width = *src++; if (!(width & 0x80)) { i -= width; - if (dst < gpBufEnd) { + if (dst < gpBufEnd && dst > gpBufStart) { if (((BYTE)(size_t)dst & 1) == shift) { if (!(width & 1)) { goto L_ODD; @@ -483,7 +483,7 @@ void CelDrawLightRedSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, i width = *pRLEBytes++; if (!(width & 0x80)) { w -= width; - if (dst < gpBufEnd) { + if (dst < gpBufEnd && dst > gpBufStart) { while (width) { *dst = tbl[*pRLEBytes]; pRLEBytes++; @@ -590,7 +590,7 @@ void CelBlitOutline(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWid width = *src++; if (!(width & 0x80)) { w -= width; - if (dst < gpBufEnd) { + if (dst < gpBufEnd && dst > gpBufStart) { if (dst >= gpBufEnd - BUFFER_WIDTH) { while (width) { if (*src++) { @@ -637,7 +637,7 @@ void ENG_set_pixel(int sx, int sy, BYTE col) dst = &gpBuffer[sx + BUFFER_WIDTH * sy]; - if (dst < gpBufEnd) + if (dst < gpBufEnd && dst > gpBufStart) *dst = col; } @@ -657,7 +657,7 @@ void engine_draw_pixel(int sx, int sy) dst = &gpBuffer[sx + BUFFER_WIDTH * sy]; } - if (dst < gpBufEnd) + if (dst < gpBufEnd && dst > gpBufStart) *dst = gbPixelCol; } @@ -1096,7 +1096,7 @@ void Cl2BlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) width -= 65; nDataSize--; fill = *src++; - if (dst < gpBufEnd) { + if (dst < gpBufEnd && dst > gpBufStart) { w -= width; while (width) { *dst = fill; @@ -1111,7 +1111,7 @@ void Cl2BlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) } } else { nDataSize -= width; - if (dst < gpBufEnd) { + if (dst < gpBufEnd && dst > gpBufStart) { w -= width; while (width) { *dst = *src; @@ -1198,7 +1198,7 @@ void Cl2BlitOutlineSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWi if (width > 65) { width -= 65; nDataSize--; - if (*src++ && dst < gpBufEnd) { + if (*src++ && dst < gpBufEnd && dst > gpBufStart) { w -= width; dst[-1] = col; dst[width] = col; @@ -1216,7 +1216,7 @@ void Cl2BlitOutlineSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWi } } else { nDataSize -= width; - if (dst < gpBufEnd) { + if (dst < gpBufEnd && dst > gpBufStart) { w -= width; while (width) { if (*src++) { @@ -1316,7 +1316,7 @@ void Cl2BlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidt width -= 65; nDataSize--; fill = pTable[*src++]; - if (dst < gpBufEnd) { + if (dst < gpBufEnd && dst > gpBufStart) { w -= width; while (width) { *dst = fill; @@ -1331,7 +1331,7 @@ void Cl2BlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidt } } else { nDataSize -= width; - if (dst < gpBufEnd) { + if (dst < gpBufEnd && dst > gpBufStart) { w -= width; while (width) { *dst = pTable[*src]; diff --git a/Source/init.cpp b/Source/init.cpp index 6d549afd0..9e65c741f 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -52,6 +52,7 @@ void init_create_window() app_fatal("Unable to create main window"); dx_init(NULL); gbActive = true; + gpBufStart = &gpBuffer[BUFFER_WIDTH * SCREEN_Y]; gpBufEnd = &gpBuffer[BUFFER_WIDTH * (SCREEN_HEIGHT + SCREEN_Y)]; SDL_DisableScreenSaver(); } diff --git a/Source/render.cpp b/Source/render.cpp index 7be7fe55a..b11126800 100644 --- a/Source/render.cpp +++ b/Source/render.cpp @@ -94,20 +94,10 @@ inline static void RenderLine(BYTE **dst, BYTE **src, int n, BYTE *tbl, DWORD ma int i; #ifdef NO_OVERDRAW - if (zoomflag) { - if ((*dst) < &gpBuffer[(0 + 160) * BUFFER_WIDTH] - || (*dst) > &gpBuffer[(VIEWPORT_HEIGHT + 160) * BUFFER_WIDTH]) { - (*src) += n; - (*dst) += n; - return; - } - } else { - if ((*dst) < &gpBuffer[(-17 + 160) * BUFFER_WIDTH] - || (*dst) > &gpBuffer[(160 + 160) * BUFFER_WIDTH]) { - (*src) += n; - (*dst) += n; - return; - } + if (*dst < gpBufStart || *dst > gpBufEnd) { + *src += n; + *dst += n; + return; } #endif diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 5d2c45002..9a486e618 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -6,6 +6,7 @@ int light_table_index; DWORD sgdwCursWdtOld; DWORD sgdwCursX; DWORD sgdwCursY; +BYTE *gpBufStart; BYTE *gpBufEnd; DWORD sgdwCursHgt; DWORD level_cel_block; @@ -658,19 +659,25 @@ static void DrawGame(int x, int y) int i, sx, sy, chunks, blocks; int wdt, nSrcOff, nDstOff; - sx = ScrollInfo._sxoff + 64; + sx = ScrollInfo._sxoff + SCREEN_X; if (zoomflag) { - sy = ScrollInfo._syoff + 175; + sy = ScrollInfo._syoff + SCREEN_Y + 15; chunks = ceil(SCREEN_WIDTH / 64); // Fill screen + keep evaulating untill MicroTiles can't affect screen blocks = ceil(VIEWPORT_HEIGHT / 32) + ceil(MicroTileLen / 2); + + gpBufStart = &gpBuffer[BUFFER_WIDTH * SCREEN_Y]; + gpBufEnd = &gpBuffer[BUFFER_WIDTH * (VIEWPORT_HEIGHT + SCREEN_Y)]; } else { - sy = ScrollInfo._syoff + 143; + sy = ScrollInfo._syoff + -17 + SCREEN_Y ; chunks = ceil(SCREEN_WIDTH / 2 / 64) + 1; // TODO why +1? // Fill screen + keep evaulating untill MicroTiles can't affect screen blocks = ceil(VIEWPORT_HEIGHT / 2 / 32) + ceil(MicroTileLen / 2); + + gpBufStart = &gpBuffer[(-17 + SCREEN_Y) * BUFFER_WIDTH]; + gpBufEnd = &gpBuffer[(160 + SCREEN_Y) * BUFFER_WIDTH]; } // Center screen @@ -741,7 +748,6 @@ static void DrawGame(int x, int y) } /// ASSERT: assert(gpBuffer); - gpBufEnd = &gpBuffer[BUFFER_WIDTH * (VIEWPORT_HEIGHT + SCREEN_Y)]; for (i = 0; i < (blocks << 1); i++) { scrollrt_draw(x, y, sx, sy, chunks, i); sy += 16; @@ -750,6 +756,7 @@ static void DrawGame(int x, int y) else x++; } + gpBufStart = &gpBuffer[BUFFER_WIDTH * SCREEN_Y]; gpBufEnd = &gpBuffer[BUFFER_WIDTH * (SCREEN_HEIGHT + SCREEN_Y)]; if (zoomflag) diff --git a/Source/scrollrt.h b/Source/scrollrt.h index fe63cc18b..b9813aa22 100644 --- a/Source/scrollrt.h +++ b/Source/scrollrt.h @@ -3,6 +3,7 @@ #define __SCROLLRT_H__ extern int light_table_index; +extern BYTE *gpBufStart; extern BYTE *gpBufEnd; extern DWORD level_cel_block; extern char arch_draw_type;