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),
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;
#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;
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;
return;
}
-#if 0
if (mScrollX_last == -1 || mScrollY_last == -1)
{
mScrollX_last = mScrollX;
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()
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;
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)
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
{
#if 1
if (!menBorder.Checked)
{
- SR.left += 16;
- SR.top += 16;
+ SR.left += TILEX / 2;
+ SR.top += TILEY / 2;
}
#endif
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;
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);
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