#include <math.h>
-long mWidth, mHeight;
-long mhWnd;
-long mScrollX, mScrollY;
-long mScrollX_last, mScrollY_last;
-long mDestXOff, mDestYOff;
+int mScrollX, mScrollY;
+int mScrollX_last, mScrollY_last;
-long ScreenBuffer[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
-boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
+int ScreenBuffer[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;
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;
-
-#if 1
+ BlitBitmap(bitmap_db_field_sp, bitmap_db_field_sp,
+ 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));
+
DrawFrameIfNeeded();
-#endif
for (y = DisplayMinY; y <= DisplayMaxY; y++)
{
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) ||
if (mScrollX_last == -1 || mScrollY_last == -1)
{
- mScrollX_last = mScrollX;
- mScrollY_last = mScrollY;
+ mScrollX_last = (mScrollX / TILESIZE) * TILESIZE;
+ mScrollY_last = (mScrollY / TILESIZE) * TILESIZE;
return;
}
- /* check if scrolling the playfield requires redrawing the viewport bitmap */
+ // check if scrolling the playfield requires redrawing the viewport bitmap
if ((mScrollX != mScrollX_last ||
mScrollY != mScrollY_last) &&
(ABS(mScrollX - mScrollX_last) >= TILEX ||
}
}
-static void ScrollPlayfieldIfNeeded()
+static void ScrollPlayfieldIfNeeded(void)
{
ScrollPlayfieldIfNeededExt(FALSE);
}
-void InitScrollPlayfield()
+void InitScrollPlayfield(void)
{
ScrollPlayfieldIfNeededExt(TRUE);
}
+#define DEBUG_REDRAW 0
+
void UpdatePlayfield(boolean force_redraw)
{
int x, y;
-#if 1
+
+#if DEBUG_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++)
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];
if (element != GfxElementLast[x][y] &&
graphic == GfxGraphicLast[x][y])
{
- /* element changed, but not graphic => disable updating graphic */
+ // element changed, but not graphic => disable updating graphic
GfxElementLast[x][y] = element;
GfxGraphicLast[x][y] = GfxGraphic[x][y] = -1;
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);
- StretchedSprites.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
}
-/* 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.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);
-
- if (!menBorder.Checked)
- {
- px += TILEX / 2;
- py += TILEY / 2;
- }
-
- BlitBitmap(screenBitmap, target_bitmap, px, py, sxsize, sysize, sx, sy);
-}
-
-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;
-
- SyncDisplay();
-
- 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);
- }
- }
- }
-
- 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;
-}
-
-void DDScrollBuffer_Blt()
-{
- BackToFront_SP();
+ int full_xsize = (FieldWidth - (menBorder ? 0 : 1)) * TILEX_VAR;
+ int full_ysize = (FieldHeight - (menBorder ? 0 : 1)) * TILEY_VAR;
+ 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 DDScrollBuffer_ScrollTo(int X, int Y)
if (NoDisplayFlag)
return;
- X = X / Stretch;
- Y = Y / Stretch;
- mScrollX = X;
- mScrollY = Y;
- ScrollX = mScrollX;
- ScrollY = mScrollY;
+ ScrollX = mScrollX = X;
+ ScrollY = mScrollY = Y;
-#if 1
ScrollPlayfieldIfNeeded();
-#endif
}
void DDScrollBuffer_ScrollTowards(int X, int Y, double Step)
if (NoDisplayFlag)
return;
- X = X / Stretch;
- Y = Y / Stretch;
dx = X - mScrollX;
dY = Y - mScrollY;
+
r = Sqr(dx * dx + dY * dY);
- if (r == 0) // we are there already
+ if (r == 0) // we are there already
return;
if (Step < r)
else
r = 1;
- mScrollX = mScrollX + dx * r;
- mScrollY = mScrollY + dY * r;
- ScrollX = mScrollX;
- ScrollY = mScrollY;
+ ScrollX = mScrollX = mScrollX + dx * r;
+ ScrollY = mScrollY = mScrollY + dY * r;
-#if 1
ScrollPlayfieldIfNeeded();
-#endif
}
-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)
return;
if (AlreadyRunning)
- {
return;
- }
AlreadyRunning = True;
- X = X / Stretch;
- Y = Y / Stretch;
+
dx = X - mScrollX;
dY = Y - mScrollY;
maxD = (Abs(dx) < Abs(dY) ? Abs(dY) : Abs(dx));
+
StepCount = FPS * (TimeMS / (double)1000);
if (StepCount > maxD)
StepCount = maxD;
if (StepCount == 0)
StepCount = 1;
- dT = 1000 / FPS;
tStep = (double)1 / StepCount;
oldX = mScrollX;
oldY = mScrollY;
- // R = Sqr(dX * dX + dY * dY)
- // If R = 0 Then Exit Sub 'we are there already
+
for (T = (double)tStep; T <= (double)1; T += tStep)
{
- if (UserDragFlag)
- goto SoftScrollEH;
-
- mScrollX = oldX + T * dx;
- mScrollY = oldY + T * dY;
- ScrollX = mScrollX;
- ScrollY = mScrollY;
+ ScrollX = mScrollX = oldX + T * dx;
+ ScrollY = mScrollY = oldY + T * dY;
}
- if (UserDragFlag)
- goto SoftScrollEH;
+ ScrollX = mScrollX = X;
+ ScrollY = mScrollY = Y;
- mScrollX = X;
- mScrollY = Y;
- ScrollX = mScrollX;
- ScrollY = mScrollY;
-
-SoftScrollEH:
AlreadyRunning = False;
-#if 1
ScrollPlayfieldIfNeeded();
-#endif
}