X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame_sp%2FDDScrollBuffer.c;h=0f1191ce1eb6153ba86abbba68070b6a6849179b;hb=d45b35552f4ca1ada1266fb7e8b6968d878019a6;hp=09d037933ea70cb821d14046c4733e9382c6a63f;hpb=2d62255a9cc1edc3692c2597cf338ce50744da96;p=rocksndiamonds.git diff --git a/src/game_sp/DDScrollBuffer.c b/src/game_sp/DDScrollBuffer.c index 09d03793..0f1191ce 100644 --- a/src/game_sp/DDScrollBuffer.c +++ b/src/game_sp/DDScrollBuffer.c @@ -7,302 +7,285 @@ #include -// --- VERSION 1.0 CLASS -// --- BEGIN -// --- MultiUse = -1 'True // True -// --- Persistable = 0 'NotPersistable // NotPersistable -// --- DataBindingBehavior = 0 'vbNone // vbNone -// --- DataSourceBehavior = 0 'vbNone // vbNone -// --- MTSTransactionMode = 0 'NotAnMTSObject // NotAnMTSObject -// --- END - -// static char *VB_Name = "DDScrollBuffer"; -// static boolean VB_GlobalNameSpace = False; -// static boolean VB_Creatable = True; -// static boolean VB_PredeclaredId = False; -// static boolean VB_Exposed = False; - -// --- Option Explicit - -// needs reference to: DirectX7 for Visual Basic Type Library - -DirectDrawSurface7 Buffer; -DirectDrawSurface7 mPrimary; long mWidth, mHeight; long mhWnd; long mScrollX, mScrollY; +long mScrollX_last, mScrollY_last; long mDestXOff, mDestYOff; -void DDScrollBuffer_Let_DestXOff(long NewVal) -{ - mDestXOff = NewVal; -} - -long DDScrollBuffer_Get_DestXOff() -{ - long DestXOff; +long ScreenBuffer[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; +boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; - DestXOff = mDestXOff; - return DestXOff; -} - -void DDScrollBuffer_Let_DestYOff(long NewVal) +void RestorePlayfield() { - mDestYOff = NewVal; -} + int x1 = mScrollX / TILEX - 2; + int y1 = mScrollY / TILEY - 2; + int x2 = mScrollX / TILEX + (SCR_FIELDX - 1) + 2; + int y2 = mScrollY / TILEY + (SCR_FIELDY - 1) + 2; + int x, y; -long DDScrollBuffer_Get_DestYOff() -{ - long DestYOff; + DrawFrameIfNeeded(); - DestYOff = mDestYOff; - - return DestYOff; -} - -DirectDrawSurface7 DDScrollBuffer_Get_Surface() -{ - DirectDrawSurface7 Surface; - - Surface = Buffer; - - return Surface; -} - -long DDScrollBuffer_Get_Width() -{ - long Width; - - Width = mWidth; - - return Width; + for (y = DisplayMinY; y <= DisplayMaxY; y++) + { + for (x = DisplayMinX; x <= DisplayMaxX; x++) + { + if (x >= x1 && x <= x2 && y >= y1 && y <= y2) + { + DrawFieldNoAnimated(x, y); + DrawFieldAnimated(x, y); + } + } + } } -int DDScrollBuffer_Get_Height() +static void ScrollPlayfield(int dx, int dy) { - int Height; + 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; + + BlitBitmap(screenBitmap, screenBitmap, + 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)); + + /* 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++) + redraw[x][y] = FALSE; + redraw_tiles = 0; - Height = mHeight; +#if 1 + DrawFrameIfNeeded(); +#endif - return Height; + for (y = DisplayMinY; y <= DisplayMaxY; y++) + { + for (x = DisplayMinX; x <= DisplayMaxX; x++) + { + if (x >= x1 && x <= x2 && y >= y1 && y <= y2) + { + int sx = x - x1; + int sy = y - y1; + int tsi = GetSI(x, y); + long id = ((PlayField16[tsi]) | + (PlayField8[tsi] << 16) | + (DisPlayField[tsi] << 24)); + + if ((dx == -1 && x == x2) || + (dx == +1 && x == x1) || + (dy == -1 && y == y2) || + (dy == +1 && y == y1)) + { + DrawFieldNoAnimated(x, y); + DrawFieldAnimated(x, y); + } + + ScreenBuffer[sx][sy] = id; + } + } + } } -long DDScrollBuffer_CreateAtSize(long Width, long Height, long hWndViewPort) +static void ScrollPlayfieldIfNeededExt(boolean reset) { - long CreateAtSize; + if (reset) + { + mScrollX_last = -1; + mScrollY_last = -1; - DDSURFACEDESC2 SD; + return; + } - CreateAtSize = 0; - mhWnd = hWndViewPort; - // Create ScrollBuffer: + if (mScrollX_last == -1 || mScrollY_last == -1) { - SD.lFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; - SD.ddsCaps.lCaps = DDSCAPS_VIDEOMEMORY; - // SD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN - SD.LWidth = Width; - SD.LHeight = Height; - } + mScrollX_last = mScrollX; + mScrollY_last = mScrollY; - // --- On Error Resume Next - Buffer = DDraw.CreateSurface(SD); - if (Err.Number != 0) - return CreateAtSize; + return; + } - // --- On Error GoTo 0 + /* check if scrolling the playfield requires redrawing the viewport bitmap */ + if ((mScrollX != mScrollX_last || + mScrollY != mScrollY_last) && + (ABS(mScrollX - mScrollX_last) >= TILEX || + ABS(mScrollY - mScrollY_last) >= TILEY)) + { + int dx = (ABS(mScrollX - mScrollX_last) < TILEX ? 0 : + mScrollX < mScrollX_last ? 1 : mScrollX > mScrollX_last ? -1 : 0); + int dy = (ABS(mScrollY - mScrollY_last) < TILEY ? 0 : + mScrollY < mScrollY_last ? 1 : mScrollY > mScrollY_last ? -1 : 0); - mWidth = Width; - mHeight = Height; - mScrollX = 0; - mScrollY = 0; - CreateAtSize = -1; + mScrollX_last -= dx * TILEX; + mScrollY_last -= dy * TILEY; - return CreateAtSize; + ScrollPlayfield(dx, dy); + } } -void DDScrollBuffer_Cls(int BackColor) +static void ScrollPlayfieldIfNeeded() { - RECT EmptyRect; - - if (NoDisplayFlag) - return; - - Buffer.BltColorFill(EmptyRect, BackColor); + ScrollPlayfieldIfNeededExt(FALSE); } -void DDScrollBuffer_Blt() +void InitScrollPlayfield() { - RECT DR, SR; - long tX, tY, L; - // RECT ERect; - // long Restore; - - if (NoDisplayFlag) - return; + ScrollPlayfieldIfNeededExt(TRUE); +} -#if 0 - // --- On Error GoTo BltEH - DirectX.GetWindowRect(mhWnd, DR); - // --- On Error GoTo 0 +void UpdatePlayfield(boolean force_redraw) +{ + int x, y; +#if 1 + int num_redrawn = 0; #endif + for (y = DisplayMinY; y <= DisplayMaxY; y++) { - tX = (DR.right - DR.left) / Stretch; - tY = (DR.bottom - DR.top) / Stretch; - } - { - SR.left = mScrollX + mDestXOff; - SR.top = mScrollY + mDestYOff; - SR.right = SR.left + tX; - SR.bottom = SR.top + tY; - // If mWidth < SR.right Then - // SR.right = mWidth - // DR.right = DR.left + Stretch * (SR.right - SR.left) - // End If - // If mHeight < SR.bottom Then - // SR.bottom = mHeight - // DR.bottom = DR.top + Stretch * (SR.bottom - SR.top) - // End If - // If (mScrollX + mDestXOff) < 0 Then - // SR.left = 0 - // DR.left = DR.left - Stretch * (mScrollX + mDestXOff) - // End If - // If (mScrollY + mDestYOff) < 0 Then - // SR.top = 0 - // DR.top = DR.top - Stretch * (mScrollY + mDestYOff) - // End If - } - -#if 1 - -#if 0 - printf("::: DDScrollBuffer.c: DDScrollBuffer_Blt(): blit from %d, %d [%ld, %ld] [%ld, %ld]\n", - SR.left, SR.top, mScrollX, mScrollY, mDestXOff, mDestYOff); -#endif + for (x = DisplayMinX; x <= DisplayMaxX; x++) + { + int element = LowByte(PlayField16[GetSI(x, y)]); + int graphic = GfxGraphic[x][y]; + int sync_frame = GfxFrame[x][y]; + boolean redraw = force_redraw; #if 0 - BlitBitmap(screenBitmap, window, - 1600, 320, - SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY); -#else - BlitBitmap(screenBitmap, window, - SR.left, SR.top, - SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY); -#endif - - return; + redraw = TRUE; // !!! TEST ONLY -- ALWAYS REDRAW !!! #endif - // DDraw.WaitForVerticalBlank DDWAITVB_BLOCKBEGIN, 0 - if (IS_NOTHING(&Buffer, sizeof(Buffer))) - return; + if (graphic < 0) + { + GfxGraphicLast[x][y] = GfxGraphic[x][y]; - if (IS_NOTHING(&PrimarySurface, sizeof(PrimarySurface))) - return; - - L = PrimarySurface.Blt(DR, &Buffer, SR, DDBLT_WAIT); - if (L != DD_OK) - { - switch (L) - { -#if 0 - case DDERR_GENERIC: - Debug.Assert(False); - break; + continue; + } - case DDERR_INVALIDCLIPLIST: - Debug.Assert(False); - break; + if (element != GfxElementLast[x][y] && + graphic == GfxGraphicLast[x][y]) + { + /* element changed, but not graphic => disable updating graphic */ - case DDERR_INVALIDOBJECT: - Debug.Assert(False); - break; + GfxElementLast[x][y] = element; + GfxGraphicLast[x][y] = GfxGraphic[x][y] = -1; - case DDERR_INVALIDPARAMS: - Debug.Assert(False); - break; + continue; + } - case DDERR_INVALIDRECT: - Debug.Assert(False); - break; + if (graphic != GfxGraphicLast[x][y]) // new graphic + { + redraw = TRUE; - case DDERR_NOALPHAHW: - Debug.Assert(False); - break; + GfxElementLast[x][y] = element; + GfxGraphicLast[x][y] = GfxGraphic[x][y]; + sync_frame = GfxFrame[x][y] = 0; + } + else if (isNextAnimationFrame_SP(graphic, sync_frame)) // new frame + { + redraw = TRUE; + } - case DDERR_NOBLTHW: - Debug.Assert(False); - break; + if (redraw) + { + int sx = x * StretchWidth; + int sy = y * StretchWidth; - case DDERR_NOCLIPLIST: - Debug.Assert(False); - break; +#if 0 + printf("::: REDRAW (%d, %d): %d, %d\n", x, y, graphic, sync_frame); +#endif - case DDERR_NODDROPSHW: - Debug.Assert(False); - break; + StretchedSprites.BltImg(sx, sy, graphic, sync_frame); - case DDERR_NOMIRRORHW: - Debug.Assert(False); - break; +#if 1 + num_redrawn++; +#endif + } + } + } - case DDERR_NORASTEROPHW: - Debug.Assert(False); - break; +#if 0 + printf("::: FRAME %d: %d redrawn\n", FrameCounter, num_redrawn); +#endif +} - case DDERR_NOROTATIONHW: - Debug.Assert(False); - break; +/* copy the entire screen to the window at the scroll position */ - case DDERR_NOSTRETCHHW: - Debug.Assert(False); - break; +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; - case DDERR_NOZBUFFERHW: - Debug.Assert(False); - break; + int xsize = SXSIZE; + int ysize = SYSIZE; + int full_xsize = (FieldWidth - (menBorder.Checked ? 0 : 1)) * TILEX; + int full_ysize = (FieldHeight - (menBorder.Checked ? 0 : 1)) * TILEY; - case DDERR_SURFACEBUSY: - Debug.Assert(False); - break; -#endif + 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); - case DDERR_SURFACELOST: - DDraw.RestoreAllSurfaces(); - if (! PrimarySurface.isLost()) - { - subDisplayLevel(); - // Blt(); - } + if (!menBorder.Checked) + { + px += TILEX / 2; + py += TILEY / 2; + } - // RestorePrimarySurface - // ClipToWindow 0 - break; + BlitBitmap(screenBitmap, target_bitmap, px, py, sxsize, sysize, sx, sy); +} -#if 0 - case DDERR_UNSUPPORTED: - Debug.Assert(False); - break; +void BackToFront_SP(void) +{ + static boolean scrolling_last = FALSE; + int left = mScrollX / TILEX; + int top = mScrollY / TILEY; + boolean scrolling = (mScrollX % TILEX != 0 || mScrollY % TILEY != 0); + int x, y; - case DDERR_WASSTILLDRAWING: - Debug.Assert(False); - break; + SyncDisplay(); - default: - Debug.Assert(False); - break; -#endif + if (1 || + redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last) + { + BlitScreenToBitmap_SP(window); + } + else + { + for (x = 0; x < SCR_FIELDX; x++) + { + for (y = 0; y < SCR_FIELDY; y++) + { + int xx = (left + x) % MAX_BUF_XSIZE; + int yy = (top + y) % MAX_BUF_YSIZE; + + if (redraw[xx][yy]) + BlitBitmap(screenBitmap, window, + xx * TILEX, yy * TILEY, TILEX, TILEY, + SX + x * TILEX, SY + y * TILEY); + } } } -#if 0 - // Buffer.UpdateOverlay SR, PrimarySurface, DR, DDOVER_SHOW - if (EditFlag) - FMark.RefreshMarker(); -#endif + FlushDisplay(); + + for (x = 0; x < MAX_BUF_XSIZE; x++) + for (y = 0; y < MAX_BUF_YSIZE; y++) + redraw[x][y] = FALSE; + redraw_tiles = 0; + + scrolling_last = scrolling; +} - // BltEH: +void DDScrollBuffer_Blt() +{ + BackToFront_SP(); } void DDScrollBuffer_ScrollTo(int X, int Y) @@ -317,9 +300,8 @@ void DDScrollBuffer_ScrollTo(int X, int Y) ScrollX = mScrollX; ScrollY = mScrollY; -#if 0 - printf("::: DDScrollBuffer.c: DDScrollBuffer_ScrollTo(): mScroll: %ld, %ld [%d, %d]\n", - mScrollX, mScrollY, X, Y); +#if 1 + ScrollPlayfieldIfNeeded(); #endif } @@ -330,11 +312,6 @@ void DDScrollBuffer_ScrollTowards(int X, int Y, double Step) if (NoDisplayFlag) return; -#if 0 - printf("::: DDScrollBuffer.c: DDScrollBuffer_ScrollTowards(): (1) mScroll: %ld, %ld [%d, %d, %f]\n", - mScrollX, mScrollY, X, Y, Step); -#endif - X = X / Stretch; Y = Y / Stretch; dx = X - mScrollX; @@ -353,18 +330,14 @@ void DDScrollBuffer_ScrollTowards(int X, int Y, double Step) ScrollX = mScrollX; ScrollY = mScrollY; -#if 0 - printf("::: DDScrollBuffer.c: DDScrollBuffer_ScrollTowards(): (2) mScroll: %ld, %ld [%d, %d, %f]\n", - mScrollX, mScrollY, X, Y, Step); +#if 1 + ScrollPlayfieldIfNeeded(); #endif } void DDScrollBuffer_SoftScrollTo(int X, int Y, long TimeMS, int FPS) { double dx, dY; -#if 0 - TickCountObject Tick; -#endif long dT, StepCount; double T, tStep; long oldX, oldY, maxD; @@ -402,37 +375,24 @@ void DDScrollBuffer_SoftScrollTo(int X, int Y, long TimeMS, int FPS) if (UserDragFlag) goto SoftScrollEH; - // If Claim Then Exit For - -#if 0 - Tick.DelayMS(dT, False); -#endif - mScrollX = oldX + T * dx; mScrollY = oldY + T * dY; ScrollX = mScrollX; ScrollY = mScrollY; - // Blt(); } if (UserDragFlag) goto SoftScrollEH; -#if 0 - Tick.DelayMS(dT, False); -#endif - mScrollX = X; mScrollY = Y; ScrollX = mScrollX; ScrollY = mScrollY; - // Blt(); SoftScrollEH: AlreadyRunning = False; -#if 0 - printf("::: DDScrollBuffer.c: DDScrollBuffer_SoftScrollTo(): mScroll: %ld, %ld\n", - mScrollX, mScrollY); +#if 1 + ScrollPlayfieldIfNeeded(); #endif }