Browse Source

Eliminate overdraw in cell functions

pull/380/head
Anders Jenbo 7 years ago
parent
commit
7d1b0f24f7
  1. 26
      Source/engine.cpp
  2. 1
      Source/init.cpp
  3. 18
      Source/render.cpp
  4. 15
      Source/scrollrt.cpp
  5. 1
      Source/scrollrt.h

26
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];

1
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();
}

18
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

15
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)

1
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;

Loading…
Cancel
Save