X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fgame_sp%2FDDScrollBuffer.c;h=271a6404a8626b0a52815798daa59f87a9250ea6;hp=eeecf2a784ff7945c658f17296e20e9b26972789;hb=14d7691c65ca4a466ce9b9448153e8fbe8351a81;hpb=c6d59064aa782b8ad71eddac2797fdc50e4858f9 diff --git a/src/game_sp/DDScrollBuffer.c b/src/game_sp/DDScrollBuffer.c index eeecf2a7..271a6404 100644 --- a/src/game_sp/DDScrollBuffer.c +++ b/src/game_sp/DDScrollBuffer.c @@ -7,16 +7,11 @@ #include -long mScrollX, mScrollY; -long mScrollX_last, mScrollY_last; +int mScrollX, mScrollY; +int mScrollX_last, mScrollY_last; -#if 1 -long ScreenBuffer[2 + MAX_PLAYFIELD_WIDTH + 2][2 + MAX_PLAYFIELD_HEIGHT + 2]; +int ScreenBuffer[2 + MAX_PLAYFIELD_WIDTH + 2][2 + MAX_PLAYFIELD_HEIGHT + 2]; boolean redraw[2 + MAX_PLAYFIELD_WIDTH + 2][2 + MAX_PLAYFIELD_HEIGHT + 2]; -#else -long ScreenBuffer[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; -boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; -#endif void RestorePlayfield() @@ -51,16 +46,16 @@ static void ScrollPlayfield(int dx, int dy) int x, y; BlitBitmap(bitmap_db_field_sp, bitmap_db_field_sp, - TILEX * (dx == -1), - TILEY * (dy == -1), - (MAX_BUF_XSIZE * TILEX) - TILEX * (dx != 0), - (MAX_BUF_YSIZE * TILEY) - TILEY * (dy != 0), - TILEX * (dx == 1), - TILEY * (dy == 1)); + TILEX_VAR * (dx == -1), + TILEY_VAR * (dy == -1), + (MAX_BUF_XSIZE * TILEX_VAR) - TILEX_VAR * (dx != 0), + (MAX_BUF_YSIZE * TILEY_VAR) - TILEY_VAR * (dy != 0), + TILEX_VAR * (dx == 1), + TILEY_VAR * (dy == 1)); /* when scrolling the whole playfield, do not redraw single tiles */ - for (x = 0; x < MAX_BUF_XSIZE; x++) - for (y = 0; y < MAX_BUF_YSIZE; y++) + for (x = 0; x < 2 + MAX_PLAYFIELD_WIDTH + 2; x++) + for (y = 0; y < 2 + MAX_PLAYFIELD_HEIGHT + 2; y++) redraw[x][y] = FALSE; redraw_tiles = 0; @@ -75,9 +70,9 @@ static void ScrollPlayfield(int dx, int dy) int sx = x - x1; int sy = y - y1; int tsi = GetSI(x, y); - long id = ((PlayField16[tsi]) | - (PlayField8[tsi] << 16) | - (DisPlayField[tsi] << 24)); + int id = ((PlayField16[tsi]) | + (PlayField8[tsi] << 16) | + (DisPlayField[tsi] << 24)); if ((dx == -1 && x == x2) || (dx == +1 && x == x1) || @@ -106,13 +101,8 @@ static void ScrollPlayfieldIfNeededExt(boolean reset) if (mScrollX_last == -1 || mScrollY_last == -1) { -#if 1 mScrollX_last = (mScrollX / TILESIZE) * TILESIZE; mScrollY_last = (mScrollY / TILESIZE) * TILESIZE; -#else - mScrollX_last = mScrollX; - mScrollY_last = mScrollY; -#endif return; } @@ -145,10 +135,13 @@ void InitScrollPlayfield() ScrollPlayfieldIfNeededExt(TRUE); } +#define DEBUG_REDRAW 0 + void UpdatePlayfield(boolean force_redraw) { int x, y; -#if 1 + +#if DEBUG_REDRAW int num_redrawn = 0; #endif @@ -161,10 +154,6 @@ void UpdatePlayfield(boolean force_redraw) int sync_frame = GfxFrame[x][y]; boolean redraw = force_redraw; -#if 0 - redraw = TRUE; // !!! TEST ONLY -- ALWAYS REDRAW !!! -#endif - if (graphic < 0) { GfxGraphicLast[x][y] = GfxGraphic[x][y]; @@ -201,20 +190,16 @@ void UpdatePlayfield(boolean force_redraw) int sx = x * StretchWidth; int sy = y * StretchWidth; -#if 0 - printf("::: REDRAW (%d, %d): %d, %d\n", x, y, graphic, sync_frame); -#endif - DDSpriteBuffer_BltImg(sx, sy, graphic, sync_frame); -#if 1 +#if DEBUG_REDRAW num_redrawn++; #endif } } } -#if 0 +#if DEBUG_REDRAW printf("::: FRAME %d: %d redrawn\n", FrameCounter, num_redrawn); #endif } @@ -226,20 +211,10 @@ void BlitScreenToBitmap_SP(Bitmap *target_bitmap) int px = 2 * TILEX + (mScrollX - mScrollX_last) % TILEX; int py = 2 * TILEY + (mScrollY - mScrollY_last) % TILEY; int sx, sy, sxsize, sysize; - -#if 0 - printf("::: %d, %d / %d, %d / %ld, %ld (%ld, %ld) / %d, %d\n", - MurphyScreenXPos, MurphyScreenYPos, - ScreenScrollXPos, ScreenScrollYPos, - mScrollX, mScrollY, - mScrollX_last, mScrollY_last, - px, py); -#endif - int xsize = SXSIZE; int ysize = SYSIZE; - int full_xsize = (FieldWidth - (menBorder ? 0 : 1)) * TILEX; - int full_ysize = (FieldHeight - (menBorder ? 0 : 1)) * TILEY; + int full_xsize = (FieldWidth - (menBorder ? 0 : 1)) * TILEX_VAR; + int full_ysize = (FieldHeight - (menBorder ? 0 : 1)) * TILEY_VAR; sxsize = (full_xsize < xsize ? full_xsize : xsize); sysize = (full_ysize < ysize ? full_ysize : ysize); @@ -250,59 +225,79 @@ void BlitScreenToBitmap_SP(Bitmap *target_bitmap) px += game_sp.scroll_xoffset; py += game_sp.scroll_yoffset; -#if 1 if (ExplosionShakeMurphy != 0) { - printf("::: ExplosionShakeMurphy\n"); - px += TILEX / 2 - GetSimpleRandom(TILEX + 1); py += TILEY / 2 - GetSimpleRandom(TILEX + 1); } -#endif + + px = px * TILESIZE_VAR / TILESIZE; + py = py * TILESIZE_VAR / TILESIZE; BlitBitmap(bitmap_db_field_sp, target_bitmap, px, py, sxsize, sysize, sx, sy); } void BackToFront_SP(void) { + static int scroll_x_last = -1, scroll_y_last = -1; static boolean scrolling_last = FALSE; - int left = mScrollX / TILEX; - int top = mScrollY / TILEY; - boolean scrolling = (mScrollX % TILEX != 0 || mScrollY % TILEY != 0); + static boolean ExplosionShakeMurphy_last = -1; + boolean scrolling = (mScrollX != scroll_x_last || mScrollY != scroll_y_last); int x, y; - SyncDisplay(); - - if (1 || - redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last) + if (0 || + redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last || + ExplosionShakeMurphy != 0 || ExplosionShakeMurphy_last != 0) { BlitScreenToBitmap_SP(window); } else { - for (x = 0; x < SCR_FIELDX; x++) + int scroll_xoffset = mScrollX - mScrollX_last + game_sp.scroll_xoffset; + int scroll_yoffset = mScrollY - mScrollY_last + game_sp.scroll_yoffset; + int x1 = 0, x2 = SCR_FIELDX - (scroll_xoffset != 0 ? 0 : 1); + int y1 = 0, y2 = SCR_FIELDY - (scroll_yoffset != 0 ? 0 : 1); + int full_xsize = (FieldWidth - (menBorder ? 0 : 1)) * TILEX_VAR; + int full_ysize = (FieldHeight - (menBorder ? 0 : 1)) * TILEY_VAR; + int xsize = SXSIZE; + int ysize = SYSIZE; + int sxsize = (full_xsize < xsize ? full_xsize : xsize); + int sysize = (full_ysize < ysize ? full_ysize : ysize); + int sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0); + int sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0); + + InitGfxClipRegion(TRUE, sx, sy, sxsize, sysize); + + scroll_xoffset = scroll_xoffset * TILESIZE_VAR / TILESIZE; + scroll_yoffset = scroll_yoffset * TILESIZE_VAR / TILESIZE; + + for (x = x1; x <= x2; x++) { - for (y = 0; y < SCR_FIELDY; y++) + for (y = y1; y <= y2; y++) { - int xx = (left + x) % MAX_BUF_XSIZE; - int yy = (top + y) % MAX_BUF_YSIZE; + int xx = 2 + x; + int yy = 2 + y; if (redraw[xx][yy]) BlitBitmap(bitmap_db_field_sp, window, - xx * TILEX, yy * TILEY, TILEX, TILEY, - SX + x * TILEX, SY + y * TILEY); + xx * TILEX_VAR, yy * TILEY_VAR, TILEX_VAR, TILEY_VAR, + sx + x * TILEX_VAR - scroll_xoffset, + sy + y * TILEY_VAR - scroll_yoffset); } } - } - FlushDisplay(); + InitGfxClipRegion(FALSE, -1, -1, -1, -1); + } - for (x = 0; x < MAX_BUF_XSIZE; x++) - for (y = 0; y < MAX_BUF_YSIZE; y++) + for (x = 0; x < 2 + MAX_PLAYFIELD_WIDTH + 2; x++) + for (y = 0; y < 2 + MAX_PLAYFIELD_HEIGHT + 2; y++) redraw[x][y] = FALSE; redraw_tiles = 0; + scroll_x_last = mScrollX; + scroll_y_last = mScrollY; scrolling_last = scrolling; + ExplosionShakeMurphy_last = ExplosionShakeMurphy; } void DDScrollBuffer_ScrollTo(int X, int Y) @@ -341,12 +336,12 @@ void DDScrollBuffer_ScrollTowards(int X, int Y, double Step) ScrollPlayfieldIfNeeded(); } -void DDScrollBuffer_SoftScrollTo(int X, int Y, long TimeMS, int FPS) +void DDScrollBuffer_SoftScrollTo(int X, int Y, int TimeMS, int FPS) { double dx, dY; - long dT, StepCount; + int StepCount; double T, tStep; - long oldX, oldY, maxD; + int oldX, oldY, maxD; static boolean AlreadyRunning = False; if (NoDisplayFlag) @@ -368,7 +363,6 @@ void DDScrollBuffer_SoftScrollTo(int X, int Y, long TimeMS, int FPS) if (StepCount == 0) StepCount = 1; - dT = 1000 / FPS; tStep = (double)1 / StepCount; oldX = mScrollX; oldY = mScrollY;