Browse Source

Implement fabiensanglard render mode (press R)

fabiensanglard
Anders Jenbo 6 years ago
parent
commit
966b66e59c
  1. 1
      Source/debug.cpp
  2. 1
      Source/debug.h
  3. 13
      Source/diablo.cpp
  4. 47
      Source/engine.cpp
  5. 17
      Source/palette.cpp
  6. 13
      Source/render.cpp
  7. 11
      Source/scrollrt.cpp
  8. 1
      Source/scrollrt.h
  9. 2
      SourceX/dx.cpp
  10. 7
      SourceX/miniwin/misc.cpp

1
Source/debug.cpp

@ -5,6 +5,7 @@ DEVILUTION_BEGIN_NAMESPACE
#ifdef _DEBUG #ifdef _DEBUG
BOOL update_seed_check = FALSE; BOOL update_seed_check = FALSE;
#endif #endif
BOOL debugRender = FALSE;
int seed_index; int seed_index;
int level_seeds[NUMLEVELS]; int level_seeds[NUMLEVELS];

1
Source/debug.h

@ -2,6 +2,7 @@
#ifndef __DEBUG_H__ #ifndef __DEBUG_H__
#define __DEBUG_H__ #define __DEBUG_H__
extern BOOL debugRender;
extern BYTE *pSquareCel; extern BYTE *pSquareCel;
extern char dMonsDbg[NUMLEVELS][MAXDUNX][MAXDUNY]; extern char dMonsDbg[NUMLEVELS][MAXDUNX][MAXDUNY];
extern char dFlagDbg[NUMLEVELS][MAXDUNX][MAXDUNY]; extern char dFlagDbg[NUMLEVELS][MAXDUNX][MAXDUNY];

13
Source/diablo.cpp

@ -1057,6 +1057,10 @@ void PressChar(int vkey)
} }
switch (vkey) { switch (vkey) {
case 'R':
case 'r':
debugRender = !debugRender;
return;
case 'G': case 'G':
case 'g': case 'g':
DecreaseGamma(); DecreaseGamma();
@ -1268,15 +1272,6 @@ void PressChar(int vkey)
case 'm': case 'm':
GetDebugMonster(); GetDebugMonster();
return; return;
case 'R':
case 'r':
sprintf(tempstr, "seed = %i", glSeedTbl[currlevel]);
NetSendCmdString(1 << myplr, tempstr);
sprintf(tempstr, "Mid1 = %i : Mid2 = %i : Mid3 = %i", glMid1Seed[currlevel], glMid2Seed[currlevel], glMid3Seed[currlevel]);
NetSendCmdString(1 << myplr, tempstr);
sprintf(tempstr, "End = %i", glEndSeed[currlevel]);
NetSendCmdString(1 << myplr, tempstr);
return;
case 'T': case 'T':
case 't': case 't':
if (debug_mode_key_inverted_v) { if (debug_mode_key_inverted_v) {

47
Source/engine.cpp

@ -113,6 +113,7 @@ void CelDrawLightRed(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, char
w -= width; w -= width;
while (width) { while (width) {
*dst = tbl[*pRLEBytes]; *dst = tbl[*pRLEBytes];
StepRender();
pRLEBytes++; pRLEBytes++;
dst++; dst++;
width--; width--;
@ -150,6 +151,7 @@ void CelBlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth)
i -= width; i -= width;
if (dst < gpBufEnd && dst > gpBufStart) { if (dst < gpBufEnd && dst > gpBufStart) {
memcpy(dst, src, width); memcpy(dst, src, width);
StepRender();
} }
src += width; src += width;
dst += width; dst += width;
@ -206,22 +208,29 @@ void CelBlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidt
if (dst < gpBufEnd && dst > gpBufStart) { if (dst < gpBufEnd && dst > gpBufStart) {
if (width & 1) { if (width & 1) {
dst[0] = tbl[src[0]]; dst[0] = tbl[src[0]];
StepRender();
src++; src++;
dst++; dst++;
} }
width >>= 1; width >>= 1;
if (width & 1) { if (width & 1) {
dst[0] = tbl[src[0]]; dst[0] = tbl[src[0]];
StepRender();
dst[1] = tbl[src[1]]; dst[1] = tbl[src[1]];
StepRender();
src += 2; src += 2;
dst += 2; dst += 2;
} }
width >>= 1; width >>= 1;
for (; width; width--) { for (; width; width--) {
dst[0] = tbl[src[0]]; dst[0] = tbl[src[0]];
StepRender();
dst[1] = tbl[src[1]]; dst[1] = tbl[src[1]];
StepRender();
dst[2] = tbl[src[2]]; dst[2] = tbl[src[2]];
StepRender();
dst[3] = tbl[src[3]]; dst[3] = tbl[src[3]];
StepRender();
src += 4; src += 4;
dst += 4; dst += 4;
} }
@ -277,13 +286,16 @@ void CelBlitLightTransSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int
width >>= 1; width >>= 1;
if (width & 1) { if (width & 1) {
dst[0] = tbl[src[0]]; dst[0] = tbl[src[0]];
StepRender();
src += 2; src += 2;
dst += 2; dst += 2;
} }
width >>= 1; width >>= 1;
for (; width; width--) { for (; width; width--) {
dst[0] = tbl[src[0]]; dst[0] = tbl[src[0]];
StepRender();
dst[2] = tbl[src[2]]; dst[2] = tbl[src[2]];
StepRender();
src += 4; src += 4;
dst += 4; dst += 4;
} }
@ -293,19 +305,23 @@ void CelBlitLightTransSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int
goto L_EVEN; goto L_EVEN;
} else { } else {
dst[0] = tbl[src[0]]; dst[0] = tbl[src[0]];
StepRender();
src++; src++;
dst++; dst++;
L_ODD: L_ODD:
width >>= 1; width >>= 1;
if (width & 1) { if (width & 1) {
dst[1] = tbl[src[1]]; dst[1] = tbl[src[1]];
StepRender();
src += 2; src += 2;
dst += 2; dst += 2;
} }
width >>= 1; width >>= 1;
for (; width; width--) { for (; width; width--) {
dst[1] = tbl[src[1]]; dst[1] = tbl[src[1]];
StepRender();
dst[3] = tbl[src[3]]; dst[3] = tbl[src[3]];
StepRender();
src += 4; src += 4;
dst += 4; dst += 4;
} }
@ -373,6 +389,7 @@ void CelDrawLightRedSafe(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, c
if (dst < gpBufEnd && dst > gpBufStart) { if (dst < gpBufEnd && dst > gpBufStart) {
while (width) { while (width) {
*dst = tbl[*pRLEBytes]; *dst = tbl[*pRLEBytes];
StepRender();
pRLEBytes++; pRLEBytes++;
dst++; dst++;
width--; width--;
@ -413,6 +430,7 @@ void CelBlitWidth(BYTE *pBuff, int x, int y, int wdt, BYTE *pCelBuff, int nCel,
if (!(width & 0x80)) { if (!(width & 0x80)) {
i -= width; i -= width;
memcpy(dst, pRLEBytes, width); memcpy(dst, pRLEBytes, width);
StepRender();
dst += width; dst += width;
pRLEBytes += width; pRLEBytes += width;
} else { } else {
@ -447,8 +465,11 @@ void CelBlitOutline(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWid
while (width) { while (width) {
if (*src++) { if (*src++) {
dst[-BUFFER_WIDTH] = col; dst[-BUFFER_WIDTH] = col;
StepRender();
dst[-1] = col; dst[-1] = col;
StepRender();
dst[1] = col; dst[1] = col;
StepRender();
} }
dst++; dst++;
width--; width--;
@ -457,9 +478,13 @@ void CelBlitOutline(char col, int sx, int sy, BYTE *pCelBuff, int nCel, int nWid
while (width) { while (width) {
if (*src++) { if (*src++) {
dst[-BUFFER_WIDTH] = col; dst[-BUFFER_WIDTH] = col;
StepRender();
dst[-1] = col; dst[-1] = col;
StepRender();
dst[1] = col; dst[1] = col;
StepRender();
dst[BUFFER_WIDTH] = col; dst[BUFFER_WIDTH] = col;
StepRender();
} }
dst++; dst++;
width--; width--;
@ -489,8 +514,10 @@ void ENG_set_pixel(int sx, int sy, BYTE col)
dst = &gpBuffer[sx + BUFFER_WIDTH * sy]; dst = &gpBuffer[sx + BUFFER_WIDTH * sy];
if (dst < gpBufEnd && dst > gpBufStart) if (dst < gpBufEnd && dst > gpBufStart) {
*dst = col; *dst = col;
StepRender();
}
} }
void engine_draw_pixel(int sx, int sy) void engine_draw_pixel(int sx, int sy)
@ -509,8 +536,10 @@ void engine_draw_pixel(int sx, int sy)
dst = &gpBuffer[sx + BUFFER_WIDTH * sy]; dst = &gpBuffer[sx + BUFFER_WIDTH * sy];
} }
if (dst < gpBufEnd && dst > gpBufStart) if (dst < gpBufEnd && dst > gpBufStart) {
*dst = gbPixelCol; *dst = gbPixelCol;
StepRender();
}
} }
// Exact copy from https://github.com/erich666/GraphicsGems/blob/dad26f941e12c8bf1f96ea21c1c04cd2206ae7c9/gems/DoubleLine.c // Exact copy from https://github.com/erich666/GraphicsGems/blob/dad26f941e12c8bf1f96ea21c1c04cd2206ae7c9/gems/DoubleLine.c
@ -883,12 +912,14 @@ void Cl2ApplyTrans(BYTE *p, BYTE *ttbl, int nCel)
nDataSize--; nDataSize--;
assert(nDataSize >= 0); assert(nDataSize >= 0);
*dst = ttbl[*dst]; *dst = ttbl[*dst];
StepRender();
dst++; dst++;
} else { } else {
nDataSize -= width; nDataSize -= width;
assert(nDataSize >= 0); assert(nDataSize >= 0);
while (width) { while (width) {
*dst = ttbl[*dst]; *dst = ttbl[*dst];
StepRender();
dst++; dst++;
width--; width--;
} }
@ -940,6 +971,7 @@ void Cl2BlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth)
w -= width; w -= width;
while (width) { while (width) {
*dst = fill; *dst = fill;
StepRender();
dst++; dst++;
width--; width--;
} }
@ -955,6 +987,7 @@ void Cl2BlitSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth)
w -= width; w -= width;
while (width) { while (width) {
*dst = *src; *dst = *src;
StepRender();
src++; src++;
dst++; dst++;
width--; width--;
@ -1029,10 +1062,14 @@ void Cl2BlitOutlineSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWi
if (*src++ && dst < gpBufEnd && dst > gpBufStart) { if (*src++ && dst < gpBufEnd && dst > gpBufStart) {
w -= width; w -= width;
dst[-1] = col; dst[-1] = col;
StepRender();
dst[width] = col; dst[width] = col;
StepRender();
while (width) { while (width) {
dst[-BUFFER_WIDTH] = col; dst[-BUFFER_WIDTH] = col;
StepRender();
dst[BUFFER_WIDTH] = col; dst[BUFFER_WIDTH] = col;
StepRender();
dst++; dst++;
width--; width--;
} }
@ -1049,9 +1086,13 @@ void Cl2BlitOutlineSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWi
while (width) { while (width) {
if (*src++) { if (*src++) {
dst[-1] = col; dst[-1] = col;
StepRender();
dst[1] = col; dst[1] = col;
StepRender();
dst[-BUFFER_WIDTH] = col; dst[-BUFFER_WIDTH] = col;
StepRender();
dst[BUFFER_WIDTH] = col; dst[BUFFER_WIDTH] = col;
StepRender();
} }
dst++; dst++;
width--; width--;
@ -1135,6 +1176,7 @@ void Cl2BlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidt
w -= width; w -= width;
while (width) { while (width) {
*dst = fill; *dst = fill;
StepRender();
dst++; dst++;
width--; width--;
} }
@ -1150,6 +1192,7 @@ void Cl2BlitLightSafe(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidt
w -= width; w -= width;
while (width) { while (width) {
*dst = pTable[*src]; *dst = pTable[*src];
StepRender();
src++; src++;
dst++; dst++;
width--; width--;

17
Source/palette.cpp

@ -185,9 +185,9 @@ void PaletteFadeIn(int fr)
ApplyGamma(logical_palette, orig_palette, 256); ApplyGamma(logical_palette, orig_palette, 256);
DWORD tc = SDL_GetTicks(); DWORD tc = SDL_GetTicks();
for (i = 0; i < 256; i = (SDL_GetTicks() - tc) / 2.083) { // 32 frames @ 60hz //for (i = 0; i < 256; i = (SDL_GetTicks() - tc) / 2.083) { // 32 frames @ 60hz
SetFadeLevel(i); // SetFadeLevel(i);
} //}
SetFadeLevel(256); SetFadeLevel(256);
memcpy(logical_palette, orig_palette, sizeof(orig_palette)); memcpy(logical_palette, orig_palette, sizeof(orig_palette));
sgbFadedIn = TRUE; sgbFadedIn = TRUE;
@ -198,11 +198,12 @@ void PaletteFadeOut(int fr)
int i; int i;
if (sgbFadedIn) { if (sgbFadedIn) {
DWORD tc = SDL_GetTicks(); //DWORD tc = SDL_GetTicks();
for (i = 256; i > 0; i = 256 - (SDL_GetTicks() - tc) / 2.083) { // 32 frames @ 60hz //for (i = 256; i > 0; i = 256 - (SDL_GetTicks() - tc) / 2.083) { // 32 frames @ 60hz
SetFadeLevel(i); // SetFadeLevel(i);
} //}
SetFadeLevel(0); ApplyGamma(logical_palette, orig_palette, 256);
SetFadeLevel(256);
sgbFadedIn = FALSE; sgbFadedIn = FALSE;
} }
} }

13
Source/render.cpp

@ -104,15 +104,18 @@ inline static void RenderLine(BYTE **dst, BYTE **src, int n, BYTE *tbl, DWORD ma
if (mask == 0xFFFFFFFF) { if (mask == 0xFFFFFFFF) {
if (light_table_index == lightmax) { if (light_table_index == lightmax) {
memset(*dst, 0, n); memset(*dst, 0, n);
StepRender();
(*src) += n; (*src) += n;
(*dst) += n; (*dst) += n;
} else if (light_table_index == 0) { } else if (light_table_index == 0) {
memcpy(*dst, *src, n); memcpy(*dst, *src, n);
StepRender();
(*src) += n; (*src) += n;
(*dst) += n; (*dst) += n;
} else { } else {
for (i = 0; i < n; i++, (*src)++, (*dst)++) { for (i = 0; i < n; i++, (*src)++, (*dst)++) {
(*dst)[0] = tbl[(*src)[0]]; (*dst)[0] = tbl[(*src)[0]];
StepRender();
} }
} }
} else { } else {
@ -121,18 +124,21 @@ inline static void RenderLine(BYTE **dst, BYTE **src, int n, BYTE *tbl, DWORD ma
for (i = 0; i < n; i++, (*dst)++, mask <<= 1) { for (i = 0; i < n; i++, (*dst)++, mask <<= 1) {
if (mask & 0x80000000) { if (mask & 0x80000000) {
(*dst)[0] = 0; (*dst)[0] = 0;
StepRender();
} }
} }
} else if (light_table_index == 0) { } else if (light_table_index == 0) {
for (i = 0; i < n; i++, (*src)++, (*dst)++, mask <<= 1) { for (i = 0; i < n; i++, (*src)++, (*dst)++, mask <<= 1) {
if (mask & 0x80000000) { if (mask & 0x80000000) {
(*dst)[0] = (*src)[0]; (*dst)[0] = (*src)[0];
StepRender();
} }
} }
} else { } else {
for (i = 0; i < n; i++, (*src)++, (*dst)++, mask <<= 1) { for (i = 0; i < n; i++, (*src)++, (*dst)++, mask <<= 1) {
if (mask & 0x80000000) { if (mask & 0x80000000) {
(*dst)[0] = tbl[(*src)[0]]; (*dst)[0] = tbl[(*src)[0]];
StepRender();
} }
} }
} }
@ -266,10 +272,12 @@ void world_draw_black_tile(int sx, int sy)
for (i = 30, j = 1; i >= 0; i -= 2, j++, dst -= BUFFER_WIDTH + 2) { for (i = 30, j = 1; i >= 0; i -= 2, j++, dst -= BUFFER_WIDTH + 2) {
memset(dst, 0, 4 * j); memset(dst, 0, 4 * j);
StepRender();
} }
dst += 4; dst += 4;
for (i = 2, j = 15; i != 32; i += 2, j--, dst -= BUFFER_WIDTH - 2) { for (i = 2, j = 15; i != 32; i += 2, j--, dst -= BUFFER_WIDTH - 2) {
memset(dst, 0, 4 * j); memset(dst, 0, 4 * j);
StepRender();
} }
} }
@ -283,8 +291,11 @@ void trans_rect(int sx, int sy, int width, int height)
BYTE *pix = &gpBuffer[SCREENXY(sx, sy)]; BYTE *pix = &gpBuffer[SCREENXY(sx, sy)];
for (row = 0; row < height; row++) { for (row = 0; row < height; row++) {
for (col = 0; col < width; col++) { for (col = 0; col < width; col++) {
if ((row & 1 && col & 1) || (!(row & 1) && !(col & 1))) if ((row & 1 && col & 1) || (!(row & 1) && !(col & 1))) {
*pix = 0; *pix = 0;
StepRender();
}
pix++; pix++;
} }
pix += BUFFER_WIDTH - width; pix += BUFFER_WIDTH - width;

11
Source/scrollrt.cpp

@ -1089,6 +1089,15 @@ static void DoBlitScreen(DWORD dwX, DWORD dwY, DWORD dwWdt, DWORD dwHgt)
BltFast(dwX, dwY, &SrcRect); BltFast(dwX, dwY, &SrcRect);
} }
void StepRender()
{
if (!debugRender)
return;
DoBlitScreen(0, 0, 640, 480);
RenderPresent();
}
/** /**
* @brief Check render pipline and blit indivudal screen parts * @brief Check render pipline and blit indivudal screen parts
* @param dwHgt Section of screen to update from top to bottom * @param dwHgt Section of screen to update from top to bottom
@ -1184,6 +1193,8 @@ void DrawAndBlit()
if (!gbRunGame) { if (!gbRunGame) {
return; return;
} }
force_redraw = 255;
memset(&gpBuffer[SCREEN_Y * BUFFER_WIDTH], 0, BUFFER_WIDTH * 480);
if (SCREEN_WIDTH > PANEL_WIDTH || SCREEN_HEIGHT > VIEWPORT_HEIGHT + PANEL_HEIGHT || force_redraw == 255) { if (SCREEN_WIDTH > PANEL_WIDTH || SCREEN_HEIGHT > VIEWPORT_HEIGHT + PANEL_HEIGHT || force_redraw == 255) {
drawhpflag = TRUE; drawhpflag = TRUE;

1
Source/scrollrt.h

@ -21,6 +21,7 @@ void ClearScreenBuffer();
void ScrollView(); void ScrollView();
#endif #endif
void EnableFrameCount(); void EnableFrameCount();
void StepRender();
void scrollrt_draw_game_screen(BOOL draw_cursor); void scrollrt_draw_game_screen(BOOL draw_cursor);
void DrawAndBlit(); void DrawAndBlit();

2
SourceX/dx.cpp

@ -248,7 +248,7 @@ void RenderPresent()
if (SDL_UpdateWindowSurface(window) <= -1) { if (SDL_UpdateWindowSurface(window) <= -1) {
ErrSdl(); ErrSdl();
} }
LimitFrameRate(); //LimitFrameRate();
} }
#else #else
if (SDL_Flip(surface) <= -1) { if (SDL_Flip(surface) <= -1) {

7
SourceX/miniwin/misc.cpp

@ -88,10 +88,11 @@ bool SpawnWindow(LPCSTR lpWindowName, int nWidth, int nHeight)
InitController(); InitController();
#endif #endif
int upscale = 1; int upscale = 0;
DvlIntSetting("upscale", &upscale); //DvlIntSetting("upscale", &upscale);
if (fullscreen) if (fullscreen = 0)
DvlIntSetting("fullscreen", (int *)&fullscreen); DvlIntSetting("fullscreen", (int *)&fullscreen);
fullscreen = 0;
int grabInput = 1; int grabInput = 1;
DvlIntSetting("grab input", &grabInput); DvlIntSetting("grab input", &grabInput);

Loading…
Cancel
Save