rnd-20100224-1-src
[rocksndiamonds.git] / src / game_sp / DDSpriteBuffer.c
index 7572c919d2e415d6d8e0aecd4c89ba21af02da79..36d271f1818d4f0ca0c023b8dd0fd9dbc7e1dc3f 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "DDSpriteBuffer.h"
 
-static void Blt(int pX, int pY, int SpriteX, int SpriteY);
+static void Blt(int pX, int pY, Bitmap *bitmap, int SpriteX, int SpriteY);
 
 // --- VERSION 1.0 CLASS
 // --- BEGIN
@@ -132,6 +132,8 @@ boolean DDSpriteBuffer_CreateFromFile(char *Path, long xSprites, long ySprites)
   return CreateFromFile;
 }
 
+#if 0
+
 boolean DDSpriteBuffer_CreateAtSize(long Width, long Height, long xSprites, long ySprites)
 {
   boolean CreateAtSize;
@@ -163,6 +165,10 @@ boolean DDSpriteBuffer_CreateAtSize(long Width, long Height, long xSprites, long
   return CreateAtSize;
 }
 
+#endif
+
+#if 0
+
 void DDSpriteBuffer_Cls(int BackColor)
 {
   RECT EmptyRect;
@@ -170,25 +176,46 @@ void DDSpriteBuffer_Cls(int BackColor)
   Buffer.BltColorFill(EmptyRect, BackColor);
 }
 
-static void Blt(int pX, int pY, int SpriteX, int SpriteY)
+#endif
+
+static void Blt(int pX, int pY, Bitmap *bitmap, int SpriteX, int SpriteY)
 {
-  RECT DR, SR;
+  MyRECT DR, SR;
 #if 0
   long Tmp;
 #endif
 
+#if 1
+
+  int scx = (mScrollX_last < 0 ? 0 : mScrollX_last);
+  int scy = (mScrollY_last < 0 ? 0 : mScrollY_last);
+  int sx1 = scx - 2 * TILEX;
+  int sy1 = scy - 2 * TILEY;
+  int sx2 = scx + SXSIZE + 1 * TILEX;
+  int sy2 = scy + 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;
+#endif
 
   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);
@@ -197,8 +224,20 @@ static void Blt(int pX, int pY, int SpriteX, int SpriteY)
   if (NoDisplayFlag)
     return;
 
+#if 0
+  if (TEST_flag)
+  {
+    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] (%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
@@ -213,8 +252,13 @@ static void Blt(int pX, int pY, int SpriteX, int SpriteY)
     DR.bottom = pY + mSpriteHeight + mDestYOff;
   }
   {
+#if 1
+    SR.left = SpriteX;
+    SR.top = SpriteY;
+#else
     SR.left = mSpriteWidth * (SpriteX - 1);
     SR.top = mSpriteHeight * (SpriteY - 1);
+#endif
     SR.right = SR.left + mSpriteWidth;
     SR.bottom = SR.top + mSpriteHeight;
   }
@@ -223,6 +267,10 @@ static void Blt(int pX, int pY, int SpriteX, int SpriteY)
   printf("::: DDSpriteBuffer.c: Blt(): %d, %d\n", DR.left, DR.top);
 #endif
 
+#if 0
+  printf("::: DDSpriteBuffer.c: Blt(): %d, %d\n", sx, sy);
+#endif
+
 #if 0
   if (pX == 0 * StretchWidth && pY == 0 * StretchWidth)
     printf("::: TEST: drawing topleft corner ...\n");
@@ -233,7 +281,7 @@ static void Blt(int pX, int pY, int SpriteX, int SpriteY)
 #if 1
 
 #if 1
-  BlitBitmap(sp_objects, screenBitmap,
+  BlitBitmap(bitmap, screenBitmap,
             SR.left, SR.top,
             mSpriteWidth, mSpriteHeight,
             sx, sy);
@@ -249,6 +297,8 @@ static void Blt(int pX, int pY, int SpriteX, int SpriteY)
 #endif
 }
 
+#if 0
+
 static void OLD_Blt(int pX, int pY, int SpriteX, int SpriteY)
 {
   RECT DR, SR;
@@ -323,6 +373,10 @@ static void OLD_Blt(int pX, int pY, int SpriteX, int SpriteY)
 #endif
 }
 
+#endif
+
+#if 0
+
 void DDSpriteBuffer_BltEx(int pX, int pY, int SpritePos)
 {
   int XPos, YPos;
@@ -330,10 +384,43 @@ void DDSpriteBuffer_BltEx(int pX, int pY, int SpritePos)
   if (NoDisplayFlag)
     return;
 
+#if 1
+  XPos = mSpriteWidth  * (SpritePos % mXSpriteCount);
+  YPos = mSpriteHeight * (SpritePos / mXSpriteCount);
+#else
   XPos = (SpritePos % mXSpriteCount) + 1;
   YPos = (SpritePos / mXSpriteCount) + 1;
+#endif
+
+#if 0
+  printf("::: BltEx: %d, %d, %d, %d\n", pX, pY, XPos, YPos);
+#endif
+
+#if 0
+  if (TEST_flag)
+    printf("::: DDSpriteBuffer_BltEx(): %d, %d [%d]\n",
+          pX, pY, SpritePos);
+#endif
+
+  Blt(pX, pY, sp_objects, XPos, YPos);
+}
+
+#endif
+
+void DDSpriteBuffer_BltImg(int pX, int pY, int graphic, int sync_frame)
+{
+  struct GraphicInfo_SP g;
+
+  if (NoDisplayFlag)
+    return;
+
+  getGraphicSource_SP(&g, graphic, sync_frame, -1, -1);
+
+#if 0
+  printf("::: BltImg: %d, %d, %d, %d\n", pX, pY, g.src_x, g.src_y);
+#endif
 
-  Blt(pX, pY, XPos, YPos);
+  Blt(pX, pY, g.bitmap, g.src_x, g.src_y);
 }
 
 // Public Function GetStretchCopy(Stretch!) As DDSpriteBuffer