From: Holger Schemel Date: Tue, 24 Nov 2009 00:28:49 +0000 (+0100) Subject: rnd-20091124-1-src X-Git-Tag: 3.3.0.0^2~62 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=ed873d89bc59f4e641134f9019ce216234b9f38f;p=rocksndiamonds.git rnd-20091124-1-src * changed internal playfield bitmap handling from playfield sized bitmap to screen sized bitmap (visible scrolling area), therefore speeding up graphics operations (by eliminating bitmap updates in invisible areas) and removing playfield size limitations due to increasing bitmap size for larger playfield sizes (while the new implementation always uses a fixed playfield bitmap size for arbitrary internal playfield sizes) --- diff --git a/ChangeLog b/ChangeLog index 8f62c76e..dd42c76d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-11-24 + * changed internal playfield bitmap handling from playfield sized bitmap + to screen sized bitmap (visible scrolling area), therefore speeding up + graphics operations (by eliminating bitmap updates in invisible areas) + and removing playfield size limitations due to increasing bitmap size + for larger playfield sizes (while the new implementation always uses + a fixed playfield bitmap size for arbitrary internal playfield sizes) + 2009-11-12 * fixed bug with single step mode (there were some cases where the game did not automatically return to pause mode, e.g. when trying to push diff --git a/src/conftime.h b/src/conftime.h index db5c8315..a8578e71 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2009-11-23 21:41" +#define COMPILE_DATE_STRING "2009-11-24 01:16" diff --git a/src/game_sp/DDScrollBuffer.c b/src/game_sp/DDScrollBuffer.c index e11c561c..859fb35d 100644 --- a/src/game_sp/DDScrollBuffer.c +++ b/src/game_sp/DDScrollBuffer.c @@ -40,30 +40,13 @@ boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; int TEST_flag = 0; -static void ScrollPlayfield() +static void ScrollPlayfield(int dx, int dy) { - int sx_last = mScrollX_last / TILEX; - int sy_last = mScrollY_last / TILEY; - int sx = mScrollX / TILEX; - int sy = mScrollY / TILEY; - int dx = (sx < sx_last ? +1 : sx > sx_last ? -1 : 0); - int dy = (sy < sy_last ? +1 : sy > sy_last ? -1 : 0); + int x1 = mScrollX_last / TILEX - 2; + int y1 = mScrollY_last / TILEY - 2; + int x2 = mScrollX_last / TILEX + (SCR_FIELDX - 1) + 2; + int y2 = mScrollY_last / TILEY + (SCR_FIELDY - 1) + 2; int x, y; - int sx1 = mScrollX - TILEX; - int sy1 = mScrollY - TILEY; - int sx2 = mScrollX + SXSIZE + TILEX; - int sy2 = mScrollY + SYSIZE + TILEY; - int x1 = sx1 / TILEX; - int y1 = sy1 / TILEY; - int x2 = sx2 / TILEX; - int y2 = sy2 / TILEY; -#if 1 - int buf_xsize = SCR_FIELDX + 2; - int buf_ysize = SCR_FIELDY + 2; -#else - int buf_xsize = MAX_BUF_XSIZE; - int buf_ysize = MAX_BUF_YSIZE; -#endif BlitBitmap(screenBitmap, screenBitmap, TILEX * (dx == -1), @@ -79,11 +62,15 @@ static void ScrollPlayfield() redraw[x][y] = FALSE; redraw_tiles = 0; +#if 1 + DrawFrameIfNeeded(); +#endif + for (y = DisplayMinY; y <= DisplayMaxY; y++) { for (x = DisplayMinX; x <= DisplayMaxX; x++) { - if (x >= x1 && x < x2 && y >= y1 && y < y2) + if (x >= x1 && x <= x2 && y >= y1 && y <= y2) { int sx = x - x1; int sy = y - y1; @@ -101,12 +88,14 @@ static void ScrollPlayfield() #endif #endif - if ((dx == -1 && sx == buf_xsize - 1) || - (dx == +1 && sx == 0) || - (dy == -1 && sy == buf_ysize - 1) || - (dy == +1 && sy == 0)) + if ((dx == -1 && x == x2) || + (dx == +1 && x == x1) || + (dy == -1 && y == y2) || + (dy == +1 && y == y1)) { +#if 0 printf("::: %d, %d\n", sx, sy); +#endif TEST_flag = 1; @@ -124,12 +113,6 @@ static void ScrollPlayfield() static void ScrollPlayfieldIfNeededExt(boolean reset) { - int sx_last = mScrollX_last / TILEX; - int sy_last = mScrollY_last / TILEY; - int sx = mScrollX / TILEX; - int sy = mScrollY / TILEY; - boolean initialized = (mScrollX_last != -1 && mScrollY_last != -1); - if (reset) { mScrollX_last = -1; @@ -138,7 +121,6 @@ static void ScrollPlayfieldIfNeededExt(boolean reset) return; } -#if 0 if (mScrollX_last == -1 || mScrollY_last == -1) { mScrollX_last = mScrollX; @@ -146,13 +128,19 @@ static void ScrollPlayfieldIfNeededExt(boolean reset) return; } -#endif - if (initialized && (sx != sx_last || sy != sy_last)) - ScrollPlayfield(); + /* check if scrolling the playfield reached the destination tile position */ + if ((mScrollX != mScrollX_last || mScrollY != mScrollY_last) && + mScrollX % TILEX == 0 && mScrollY % TILEY == 0) + { + int dx = (mScrollX < mScrollX_last ? 1 : mScrollX > mScrollX_last ? -1 : 0); + int dy = (mScrollY < mScrollY_last ? 1 : mScrollY > mScrollY_last ? -1 : 0); + + mScrollX_last = mScrollX; + mScrollY_last = mScrollY; - mScrollX_last = mScrollX; - mScrollY_last = mScrollY; + ScrollPlayfield(dx, dy); + } } static void ScrollPlayfieldIfNeeded() @@ -167,21 +155,17 @@ void InitScrollPlayfield() void UpdatePlayfield() { + int x1 = mScrollX_last / TILEX - 2; + int y1 = mScrollY_last / TILEY - 2; + int x2 = mScrollX_last / TILEX + (SCR_FIELDX - 1) + 2; + int y2 = mScrollY_last / TILEY + (SCR_FIELDY - 1) + 2; int x, y; - int sx1 = mScrollX - TILEX; - int sy1 = mScrollY - TILEY; - int sx2 = mScrollX + SXSIZE + TILEX; - int sy2 = mScrollY + SYSIZE + TILEY; - int x1 = sx1 / TILEX; - int y1 = sy1 / TILEY; - int x2 = sx2 / TILEX; - int y2 = sy2 / TILEY; for (y = DisplayMinY; y <= DisplayMaxY; y++) { for (x = DisplayMinX; x <= DisplayMaxX; x++) { - if (x >= x1 && x < x2 && y >= y1 && y < y2) + if (x >= x1 && x <= x2 && y >= y1 && y <= y2) { int sx = x - x1; int sy = y - y1; @@ -348,11 +332,31 @@ void DDScrollBuffer_Cls(int BackColor) void BlitScreenToBitmap_SP(Bitmap *target_bitmap) { - int sx = TILEX + mScrollX % TILEX; - int sy = TILEY + mScrollY % TILEY; + int px = 2 * TILEX + (mScrollX - mScrollX_last) % TILEX; + int py = 2 * TILEY + (mScrollY - mScrollY_last) % TILEY; + int sx, sy, sxsize, sysize; + +#if 1 + int xsize = SXSIZE; + int ysize = SYSIZE; + int full_xsize = (FieldWidth - (menBorder.Checked ? 0 : 1)) * TILEX; + int full_ysize = (FieldHeight - (menBorder.Checked ? 0 : 1)) * TILEY; + + sxsize = (full_xsize < xsize ? full_xsize : xsize); + sysize = (full_ysize < ysize ? full_ysize : ysize); + sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0); + sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0); +#endif + +#if 1 + if (!menBorder.Checked) + { + px += TILEX / 2; + py += TILEY / 2; + } +#endif - BlitBitmap(screenBitmap, target_bitmap, sx, sy, - SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY); + BlitBitmap(screenBitmap, target_bitmap, px, py, sxsize, sysize, sx, sy); } void OLD_BlitScreenToBitmap_SP(Bitmap *target_bitmap) @@ -413,11 +417,15 @@ void BackToFront_SP(void) if (1 || redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last) { +#if 1 + BlitScreenToBitmap_SP(window); +#else /* blit all (up to four) parts of the scroll buffer to the backbuffer */ BlitScreenToBitmap_SP(backbuffer); /* blit the completely updated backbuffer to the window (in one blit) */ BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY); +#endif } else { @@ -521,8 +529,8 @@ void DDScrollBuffer_Blt_Ext(Bitmap *target_bitmap) #if 1 if (!menBorder.Checked) { - SR.left += 16; - SR.top += 16; + SR.left += TILEX / 2; + SR.top += TILEY / 2; } #endif diff --git a/src/game_sp/DDScrollBuffer.h b/src/game_sp/DDScrollBuffer.h index d8633813..402cdcad 100644 --- a/src/game_sp/DDScrollBuffer.h +++ b/src/game_sp/DDScrollBuffer.h @@ -13,6 +13,7 @@ #include "global.h" extern long mScrollX, mScrollY; +extern long mScrollX_last, mScrollY_last; extern boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; diff --git a/src/game_sp/DDSpriteBuffer.c b/src/game_sp/DDSpriteBuffer.c index 95ac25a3..00e49d7a 100644 --- a/src/game_sp/DDSpriteBuffer.c +++ b/src/game_sp/DDSpriteBuffer.c @@ -177,12 +177,25 @@ static void Blt(int pX, int pY, int SpriteX, int SpriteY) long Tmp; #endif +#if 1 + + int sx1 = mScrollX_last - 2 * TILEX; + int sy1 = mScrollY_last - 2 * TILEY; + int sx2 = mScrollX_last + SXSIZE + 1 * TILEX; + int sy2 = mScrollY_last + SYSIZE + 1 * TILEY; + + int sx = pX - sx1; + int sy = pY - sy1; + +#else + int sx1 = mScrollX - TILEX; int sy1 = mScrollY - TILEY; int sx2 = mScrollX + SXSIZE + TILEX; int sy2 = mScrollY + SYSIZE + TILEY; int x1 = sx1 / TILEX; int y1 = sy1 / TILEY; + #if 0 int x2 = sx2 / TILEX; int y2 = sy2 / TILEY; @@ -191,6 +204,8 @@ static void Blt(int pX, int pY, int SpriteX, int SpriteY) int sx = pX - x1 * TILEX; int sy = pY - y1 * TILEY; +#endif + #if 0 printf(":1: DDSpriteBuffer.c: Blt(): %d, %d [%ld, %ld]\n", pX, pY, mScrollX, mScrollY); @@ -199,20 +214,20 @@ static void Blt(int pX, int pY, int SpriteX, int SpriteY) if (NoDisplayFlag) return; -#if 1 +#if 0 if (TEST_flag) { - if (pX < sx1 || pX >= sx2 || pY < sy1 || pY >= sy2) - printf("::: DDSpriteBuffer.c: Blt(): %d, %d [%d..%d, %d..%d] (%d, %d) [SKIPPED]\n", - pX, pY, sx1, sx2, sy1, sy2, mScrollX, mScrollY); + if (pX < sx1 || pX > sx2 || pY < sy1 || pY > sy2) + printf("::: DDSpriteBuffer.c: Blt(): %d, %d [%d..%d, %d..%d] (%ld, %ld) (%ld, %ld) [SKIPPED]\n", + pX, pY, sx1, sx2, sy1, sy2, mScrollX, mScrollY, mScrollX_last, mScrollY_last); else - printf("::: DDSpriteBuffer.c: Blt(): %d, %d [%d..%d, %d..%d] (%d, %d)\n", - pX, pY, sx1, sx2, sy1, sy2, mScrollX, mScrollY); + printf("::: DDSpriteBuffer.c: Blt(): %d, %d [%d..%d, %d..%d] (%ld, %ld) (%ld, %ld)\n", + pX, pY, sx1, sx2, sy1, sy2, mScrollX, mScrollY, mScrollX_last, mScrollY_last); } #endif /* do not draw fields that are outside the visible screen area */ - if (pX < sx1 || pX >= sx2 || pY < sy1 || pY >= sy2) + if (pX < sx1 || pX > sx2 || pY < sy1 || pY > sy2) return; #if 0 diff --git a/src/game_sp/MainForm.c b/src/game_sp/MainForm.c index 9897250e..a2dfbbeb 100644 --- a/src/game_sp/MainForm.c +++ b/src/game_sp/MainForm.c @@ -1003,6 +1003,17 @@ static boolean InstanceStillRunning(char *TmpFile) #endif +void DrawFrameIfNeeded() +{ + DrawFrame(0); + + /* !!! CHECK THIS !!! */ +#if 1 + if (! menBorder.Checked) + DrawFrame(1); +#endif +} + void DisplayLevel() { int X, Y; diff --git a/src/game_sp/MainForm.h b/src/game_sp/MainForm.h index 9846ce2c..0dc8547d 100644 --- a/src/game_sp/MainForm.h +++ b/src/game_sp/MainForm.h @@ -12,6 +12,8 @@ #include "global.h" +extern void DrawFrameIfNeeded(); + extern void DisplayLevel(); extern void DrawField(int X, int Y); extern void DrawFieldAnimated(int X, int Y);