1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
5 #include "DDSpriteBuffer.h"
7 static void Blt(int pX, int pY, Bitmap *bitmap, int SpriteX, int SpriteY);
9 // --- VERSION 1.0 CLASS
11 // --- MultiUse = -1 'True // True
12 // --- Persistable = 0 'NotPersistable // NotPersistable
13 // --- DataBindingBehavior = 0 'vbNone // vbNone
14 // --- DataSourceBehavior = 0 'vbNone // vbNone
15 // --- MTSTransactionMode = 0 'NotAnMTSObject // NotAnMTSObject
18 // static char *VB_Name = "DDSpriteBuffer";
19 // static boolean VB_GlobalNameSpace = False;
20 // static boolean VB_Creatable = True;
21 // static boolean VB_PredeclaredId = False;
22 // static boolean VB_Exposed = False;
23 // --- Option Explicit
25 // needs reference to: DirectX7 for Visual Basic Type Library
27 DirectDrawSurface7 Buffer;
28 DirectDrawSurface7 mDest;
29 long mXSpriteCount, mYSpriteCount;
30 long mSpriteWidth, mSpriteHeight;
31 long mDestXOff, mDestYOff;
33 void DDSpriteBuffer_Let_DestXOff(long NewVal)
38 long DDSpriteBuffer_Get_DestXOff()
47 void DDSpriteBuffer_Let_DestYOff(long NewVal)
52 long DDSpriteBuffer_Get_DestYOff()
61 int DDSpriteBuffer_Set_DestinationSurface(DirectDrawSurface7 DSurface)
63 int DestinationSurface;
67 return DestinationSurface;
70 DirectDrawSurface7 DDSpriteBuffer_Get_Surface()
72 DirectDrawSurface7 Surface;
79 long DDSpriteBuffer_Get_Width()
83 Width = mSpriteWidth * mXSpriteCount;
88 int DDSpriteBuffer_Get_Height()
92 Height = mSpriteHeight * mYSpriteCount;
97 boolean DDSpriteBuffer_CreateFromFile(char *Path, long xSprites, long ySprites)
99 boolean CreateFromFile;
104 SD.lFlags = DDSD_CAPS; // Or DDSD_WIDTH Or DDSD_HEIGHT
105 SD.ddsCaps.lCaps = DDSCAPS_VIDEOMEMORY; // DDSCAPS_SYSTEMMEMORY 'DDSCAPS_OFFSCREENPLAIN
108 // --- On Error GoTo CreateFromFileEH
110 SD.LWidth = 16 * TILEX;
111 SD.LHeight = 16 * TILEY;
113 Buffer = DDraw.CreateSurfaceFromFile(Path, SD);
115 // --- On Error GoTo 0
118 Buffer.GetSurfaceDesc(SD);
121 mSpriteWidth = SD.LWidth / xSprites;
122 mSpriteHeight = SD.LHeight / ySprites;
123 mXSpriteCount = xSprites;
124 mYSpriteCount = ySprites;
126 CreateFromFile = True;
127 return CreateFromFile;
130 CreateFromFile = False;
132 return CreateFromFile;
137 boolean DDSpriteBuffer_CreateAtSize(long Width, long Height, long xSprites, long ySprites)
139 boolean CreateAtSize;
144 SD.lFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
145 SD.ddsCaps.lCaps = DDSCAPS_VIDEOMEMORY;
146 // SD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
151 // --- On Error GoTo CreateAtSizeEH
152 Buffer = DDraw.CreateSurface(SD);
153 // --- On Error GoTo 0
155 mSpriteWidth = Width / xSprites;
156 mSpriteHeight = Height / ySprites;
157 mXSpriteCount = xSprites;
158 mYSpriteCount = ySprites;
163 CreateAtSize = False;
172 void DDSpriteBuffer_Cls(int BackColor)
176 Buffer.BltColorFill(EmptyRect, BackColor);
181 static void Blt(int pX, int pY, Bitmap *bitmap, int SpriteX, int SpriteY)
190 int scx = (mScrollX_last < 0 ? 0 : mScrollX_last);
191 int scy = (mScrollY_last < 0 ? 0 : mScrollY_last);
192 int sx1 = scx - 2 * TILEX;
193 int sy1 = scy - 2 * TILEY;
194 int sx2 = scx + SXSIZE + 1 * TILEX;
195 int sy2 = scy + SYSIZE + 1 * TILEY;
202 int sx1 = mScrollX - TILEX;
203 int sy1 = mScrollY - TILEY;
204 int sx2 = mScrollX + SXSIZE + TILEX;
205 int sy2 = mScrollY + SYSIZE + TILEY;
206 int x1 = sx1 / TILEX;
207 int y1 = sy1 / TILEY;
210 int x2 = sx2 / TILEX;
211 int y2 = sy2 / TILEY;
214 int sx = pX - x1 * TILEX;
215 int sy = pY - y1 * TILEY;
220 printf(":1: DDSpriteBuffer.c: Blt(): %d, %d [%ld, %ld]\n",
221 pX, pY, mScrollX, mScrollY);
230 if (pX < sx1 || pX > sx2 || pY < sy1 || pY > sy2)
231 printf("::: DDSpriteBuffer.c: Blt(): %d, %d [%d..%d, %d..%d] (%ld, %ld) (%ld, %ld) [SKIPPED]\n",
232 pX, pY, sx1, sx2, sy1, sy2, mScrollX, mScrollY, mScrollX_last, mScrollY_last);
234 printf("::: DDSpriteBuffer.c: Blt(): %d, %d [%d..%d, %d..%d] (%ld, %ld) (%ld, %ld)\n",
235 pX, pY, sx1, sx2, sy1, sy2, mScrollX, mScrollY, mScrollX_last, mScrollY_last);
239 /* do not draw fields that are outside the visible screen area */
240 if (pX < sx1 || pX > sx2 || pY < sy1 || pY > sy2)
244 printf(":2: DDSpriteBuffer.c: Blt(): %d, %d [%ld, %ld]\n",
245 pX, pY, mScrollX, mScrollY);
249 DR.left = pX + mDestXOff;
250 DR.top = pY + mDestYOff;
251 DR.right = pX + mSpriteWidth + mDestXOff;
252 DR.bottom = pY + mSpriteHeight + mDestYOff;
259 SR.left = mSpriteWidth * (SpriteX - 1);
260 SR.top = mSpriteHeight * (SpriteY - 1);
262 SR.right = SR.left + mSpriteWidth;
263 SR.bottom = SR.top + mSpriteHeight;
267 printf("::: DDSpriteBuffer.c: Blt(): %d, %d\n", DR.left, DR.top);
271 printf("::: DDSpriteBuffer.c: Blt(): %d, %d\n", sx, sy);
275 if (pX == 0 * StretchWidth && pY == 0 * StretchWidth)
276 printf("::: TEST: drawing topleft corner ...\n");
277 if (pX == 59 * StretchWidth && pY == 23 * StretchWidth)
278 printf("::: TEST: drawing bottomright corner ...\n");
284 BlitBitmap(bitmap, screenBitmap,
286 mSpriteWidth, mSpriteHeight,
289 BlitBitmap(sp_objects, screenBitmap,
291 mSpriteWidth, mSpriteHeight,
296 Tmp = mDest.Blt(DR, &Buffer, SR, DDBLT_WAIT);
302 static void OLD_Blt(int pX, int pY, int SpriteX, int SpriteY)
313 int left = mScrollX / TILEX;
314 int top = mScrollY / TILEY;
317 int sx = pX % (MAX_BUF_XSIZE * TILEX);
318 int sy = pY % (MAX_BUF_YSIZE * TILEY);
321 printf("::: DDSpriteBuffer.c: Blt(): %d, %d [%ld, %ld] [%d, %d]\n",
322 pX, pY, mScrollX, mScrollY, left, top);
328 /* do not draw fields that are outside the visible screen area */
329 if (pX < left || pX >= left + MAX_BUF_XSIZE * TILEX ||
330 pY < top || pY >= top + MAX_BUF_YSIZE * TILEY)
334 DR.left = pX + mDestXOff;
335 DR.top = pY + mDestYOff;
336 DR.right = pX + mSpriteWidth + mDestXOff;
337 DR.bottom = pY + mSpriteHeight + mDestYOff;
340 SR.left = mSpriteWidth * (SpriteX - 1);
341 SR.top = mSpriteHeight * (SpriteY - 1);
342 SR.right = SR.left + mSpriteWidth;
343 SR.bottom = SR.top + mSpriteHeight;
347 printf("::: DDSpriteBuffer.c: Blt(): %d, %d\n", DR.left, DR.top);
351 if (pX == 0 * StretchWidth && pY == 0 * StretchWidth)
352 printf("::: TEST: drawing topleft corner ...\n");
353 if (pX == 59 * StretchWidth && pY == 23 * StretchWidth)
354 printf("::: TEST: drawing bottomright corner ...\n");
360 BlitBitmap(sp_objects, screenBitmap,
362 mSpriteWidth, mSpriteHeight,
365 BlitBitmap(sp_objects, screenBitmap,
367 mSpriteWidth, mSpriteHeight,
372 Tmp = mDest.Blt(DR, &Buffer, SR, DDBLT_WAIT);
378 void DDSpriteBuffer_BltEx(int pX, int pY, int SpritePos)
386 XPos = mSpriteWidth * (SpritePos % mXSpriteCount);
387 YPos = mSpriteHeight * (SpritePos / mXSpriteCount);
389 XPos = (SpritePos % mXSpriteCount) + 1;
390 YPos = (SpritePos / mXSpriteCount) + 1;
394 printf("::: BltEx: %d, %d, %d, %d\n", pX, pY, XPos, YPos);
399 printf("::: DDSpriteBuffer_BltEx(): %d, %d [%d]\n",
403 Blt(pX, pY, sp_objects, XPos, YPos);
406 void DDSpriteBuffer_BltImg(int pX, int pY, int graphic, int sync_frame)
408 struct GraphicInfo_SP g;
413 getGraphicSource_SP(&g, graphic, sync_frame, -1, -1);
416 printf("::: BltImg: %d, %d, %d, %d\n", pX, pY, g.src_x, g.src_y);
419 Blt(pX, pY, g.bitmap, g.src_x, g.src_y);
422 // Public Function GetStretchCopy(Stretch!) As DDSpriteBuffer
423 // Dim SR As RECT, DR As RECT, Y%, X%, pX%, pY%, Tmp&
424 // // Set GetStretchCopy = New DDSpriteBuffer // (handle this later, if needed)
425 // If Not GetStretchCopy.CreateAtSize(Stretch * Width, Stretch * Height, mXSpriteCount, mYSpriteCount) Then
426 // Set GetStretchCopy = Nothing
428 // For Y = 0 To mYSpriteCount - 1
429 // pY = Y * Stretch * mSpriteHeight
430 // For X = 0 To mXSpriteCount - 1
431 // pX = X * Stretch * mSpriteWidth
435 // .right = pX + mSpriteWidth * Stretch
436 // .bottom = pY + mSpriteHeight * Stretch
439 // .left = mSpriteWidth * X
440 // .top = mSpriteHeight * Y
441 // .right = .left + mSpriteWidth
442 // .bottom = .top + mSpriteHeight
444 // Tmp = GetStretchCopy.Surface.Blt(DR, Buffer, SR, DDBLT_WAIT)
447 // 'GetStretchCopy.Surface.Blt DR, Buffer, DR, DDBLT_WAIT
453 static void Class_Initialize()