major cleanup of preprocessor hell
[rocksndiamonds.git] / src / game_sp / DDSpriteBuffer.c
1 // ----------------------------------------------------------------------------
2 // DDSpriteBuffer.c
3 // ----------------------------------------------------------------------------
4
5 #include "DDSpriteBuffer.h"
6
7
8 static void Blt(int pX, int pY, Bitmap *bitmap, int SpriteX, int SpriteY)
9 {
10   int scx = (mScrollX_last < 0 ? 0 : mScrollX_last);
11   int scy = (mScrollY_last < 0 ? 0 : mScrollY_last);
12   int sx1 = scx - 2 * TILEX;
13   int sy1 = scy - 2 * TILEY;
14   int sx2 = scx + (SCR_FIELDX + 1) * TILEX;
15   int sy2 = scy + (SCR_FIELDY + 1) * TILEY;
16   int sx = pX - sx1;
17   int sy = pY - sy1;
18   int tile_x = sx / TILESIZE;
19   int tile_y = sy / TILESIZE;
20   int move_x = (sx + TILESIZE - 1) / TILESIZE;
21   int move_y = (sy + TILESIZE - 1) / TILESIZE;
22
23   if (NoDisplayFlag)
24     return;
25
26   /* do not draw fields that are outside the visible screen area */
27   if (pX < sx1 || pX > sx2 || pY < sy1 || pY > sy2)
28     return;
29
30   sx = sx * TILESIZE_VAR / TILESIZE;
31   sy = sy * TILESIZE_VAR / TILESIZE;
32
33   BlitBitmap(bitmap, bitmap_db_field_sp, SpriteX, SpriteY,
34              TILEX_VAR, TILEY_VAR, sx, sy);
35
36   redraw[tile_x][tile_y] = TRUE;
37   redraw_tiles++;
38
39   if (move_x != tile_x)
40   {
41     redraw[move_x][tile_y] = TRUE;
42     redraw_tiles++;
43   }
44   else if (move_y != tile_y)
45   {
46     redraw[tile_x][move_y] = TRUE;
47     redraw_tiles++;
48   }
49 }
50
51 void DDSpriteBuffer_BltImg(int pX, int pY, int graphic, int sync_frame)
52 {
53   struct GraphicInfo_SP g;
54
55   if (NoDisplayFlag)
56     return;
57
58   getGraphicSource_SP(&g, graphic, sync_frame, -1, -1);
59
60   Blt(pX, pY, g.bitmap, g.src_x, g.src_y);
61 }