X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fgame_sp%2FDDScrollBuffer.c;h=62257d0314c403d026e83152cec72c5999d31e95;hp=698d33b8b2003eee24b054d532d428688fd5ddd6;hb=115ce6f2da1914d68b0fe0e5f9082973190dacdd;hpb=3ff2e8a0b5c27b99a9920bdf5ed82bc41bf40181 diff --git a/src/game_sp/DDScrollBuffer.c b/src/game_sp/DDScrollBuffer.c index 698d33b8..62257d03 100644 --- a/src/game_sp/DDScrollBuffer.c +++ b/src/game_sp/DDScrollBuffer.c @@ -11,10 +11,39 @@ int mScrollX, mScrollY; int mScrollX_last, mScrollY_last; int ScreenBuffer[2 + MAX_PLAYFIELD_WIDTH + 2][2 + MAX_PLAYFIELD_HEIGHT + 2]; -boolean redraw[2 + MAX_PLAYFIELD_WIDTH + 2][2 + MAX_PLAYFIELD_HEIGHT + 2]; -void RestorePlayfield() +int getFieldbufferOffsetX_SP(void) +{ + int px = 2 * TILEX + (mScrollX - mScrollX_last) % TILEX; + + /* scroll correction for even number of visible tiles (half tile shifted) */ + px += game_sp.scroll_xoffset; + + if (ExplosionShakeMurphy != 0) + px += TILEX / 2 - GetSimpleRandom(TILEX + 1); + + px = px * TILESIZE_VAR / TILESIZE; + + return px; +} + +int getFieldbufferOffsetY_SP(void) +{ + int py = 2 * TILEY + (mScrollY - mScrollY_last) % TILEY; + + /* scroll correction for even number of visible tiles (half tile shifted) */ + py += game_sp.scroll_yoffset; + + if (ExplosionShakeMurphy != 0) + py += TILEY / 2 - GetSimpleRandom(TILEX + 1); + + py = py * TILESIZE_VAR / TILESIZE; + + return py; +} + +void RestorePlayfield(void) { int x1 = mScrollX / TILEX - 2; int y1 = mScrollY / TILEY - 2; @@ -53,12 +82,6 @@ static void ScrollPlayfield(int dx, int dy) TILEX_VAR * (dx == 1), TILEY_VAR * (dy == 1)); - /* when scrolling the whole playfield, do not redraw single tiles */ - 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; - DrawFrameIfNeeded(); for (y = DisplayMinY; y <= DisplayMaxY; y++) @@ -125,12 +148,12 @@ static void ScrollPlayfieldIfNeededExt(boolean reset) } } -static void ScrollPlayfieldIfNeeded() +static void ScrollPlayfieldIfNeeded(void) { ScrollPlayfieldIfNeededExt(FALSE); } -void InitScrollPlayfield() +void InitScrollPlayfield(void) { ScrollPlayfieldIfNeededExt(TRUE); } @@ -145,6 +168,17 @@ void UpdatePlayfield(boolean force_redraw) int num_redrawn = 0; #endif + if (force_redraw) + { + // force re-initialization of graphics status variables + for (y = DisplayMinY; y <= DisplayMaxY; y++) + for (x = DisplayMinX; x <= DisplayMaxX; x++) + GfxGraphic[x][y] = -1; + + // force complete playfield redraw + DisplayLevel(); + } + for (y = DisplayMinY; y <= DisplayMaxY; y++) { for (x = DisplayMinX; x <= DisplayMaxX; x++) @@ -204,106 +238,24 @@ void UpdatePlayfield(boolean force_redraw) #endif } -/* copy the entire screen to the window at the scroll position */ - 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; + /* copy playfield buffer to target bitmap at scroll position */ + + int px = getFieldbufferOffsetX_SP(); + int py = getFieldbufferOffsetY_SP(); int xsize = SXSIZE; int ysize = SYSIZE; 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); - sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0); - sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0); - - /* scroll correction for even number of visible tiles (half tile shifted) */ - px += game_sp.scroll_xoffset; - py += game_sp.scroll_yoffset; - - if (ExplosionShakeMurphy != 0) - { - px += TILEX / 2 - GetSimpleRandom(TILEX + 1); - py += TILEY / 2 - GetSimpleRandom(TILEX + 1); - } - - px = px * TILESIZE_VAR / TILESIZE; - py = py * TILESIZE_VAR / TILESIZE; + int sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0); + int sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0); + int sxsize = (full_xsize < xsize ? full_xsize : xsize); + int sysize = (full_ysize < ysize ? full_ysize : ysize); 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; - static boolean ExplosionShakeMurphy_last = -1; - boolean scrolling = (mScrollX != scroll_x_last || mScrollY != scroll_y_last); - int x, y; - - SyncDisplay(); - - if (0 || - redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last || - ExplosionShakeMurphy != 0 || ExplosionShakeMurphy_last != 0) - { - BlitScreenToBitmap_SP(window); - } - else - { - 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 = y1; y <= y2; y++) - { - int xx = 2 + x; - int yy = 2 + y; - - if (redraw[xx][yy]) - BlitBitmap(bitmap_db_field_sp, window, - xx * TILEX_VAR, yy * TILEY_VAR, TILEX_VAR, TILEY_VAR, - sx + x * TILEX_VAR - scroll_xoffset, - sy + y * TILEY_VAR - scroll_yoffset); - } - } - - InitGfxClipRegion(FALSE, -1, -1, -1, -1); - } - - FlushDisplay(); - - 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) { if (NoDisplayFlag)