1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
5 #include "DDSpriteBuffer.h"
7 static void Blt(int pX, int pY, 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;
135 boolean DDSpriteBuffer_CreateAtSize(long Width, long Height, long xSprites, long ySprites)
137 boolean CreateAtSize;
142 SD.lFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
143 SD.ddsCaps.lCaps = DDSCAPS_VIDEOMEMORY;
144 // SD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
149 // --- On Error GoTo CreateAtSizeEH
150 Buffer = DDraw.CreateSurface(SD);
151 // --- On Error GoTo 0
153 mSpriteWidth = Width / xSprites;
154 mSpriteHeight = Height / ySprites;
155 mXSpriteCount = xSprites;
156 mYSpriteCount = ySprites;
161 CreateAtSize = False;
166 void DDSpriteBuffer_Cls(int BackColor)
170 Buffer.BltColorFill(EmptyRect, BackColor);
173 static void Blt(int pX, int pY, int SpriteX, int SpriteY)
180 int sx1 = mScrollX - TILEX;
181 int sy1 = mScrollY - TILEY;
182 int sx2 = mScrollX + SXSIZE + TILEX;
183 int sy2 = mScrollY + SYSIZE + TILEY;
184 int x1 = sx1 / TILEX;
185 int y1 = sy1 / TILEY;
187 int x2 = sx2 / TILEX;
188 int y2 = sy2 / TILEY;
191 int sx = pX - x1 * TILEX;
192 int sy = pY - y1 * TILEY;
195 printf(":1: DDSpriteBuffer.c: Blt(): %d, %d [%ld, %ld]\n",
196 pX, pY, mScrollX, mScrollY);
205 if (pX < sx1 || pX >= sx2 || pY < sy1 || pY >= sy2)
206 printf("::: DDSpriteBuffer.c: Blt(): %d, %d [%d..%d, %d..%d] (%d, %d) [SKIPPED]\n",
207 pX, pY, sx1, sx2, sy1, sy2, mScrollX, mScrollY);
209 printf("::: DDSpriteBuffer.c: Blt(): %d, %d [%d..%d, %d..%d] (%d, %d)\n",
210 pX, pY, sx1, sx2, sy1, sy2, mScrollX, mScrollY);
214 /* do not draw fields that are outside the visible screen area */
215 if (pX < sx1 || pX >= sx2 || pY < sy1 || pY >= sy2)
219 printf(":2: DDSpriteBuffer.c: Blt(): %d, %d [%ld, %ld]\n",
220 pX, pY, mScrollX, mScrollY);
224 DR.left = pX + mDestXOff;
225 DR.top = pY + mDestYOff;
226 DR.right = pX + mSpriteWidth + mDestXOff;
227 DR.bottom = pY + mSpriteHeight + mDestYOff;
230 SR.left = mSpriteWidth * (SpriteX - 1);
231 SR.top = mSpriteHeight * (SpriteY - 1);
232 SR.right = SR.left + mSpriteWidth;
233 SR.bottom = SR.top + mSpriteHeight;
237 printf("::: DDSpriteBuffer.c: Blt(): %d, %d\n", DR.left, DR.top);
241 if (pX == 0 * StretchWidth && pY == 0 * StretchWidth)
242 printf("::: TEST: drawing topleft corner ...\n");
243 if (pX == 59 * StretchWidth && pY == 23 * StretchWidth)
244 printf("::: TEST: drawing bottomright corner ...\n");
250 BlitBitmap(sp_objects, screenBitmap,
252 mSpriteWidth, mSpriteHeight,
255 BlitBitmap(sp_objects, screenBitmap,
257 mSpriteWidth, mSpriteHeight,
262 Tmp = mDest.Blt(DR, &Buffer, SR, DDBLT_WAIT);
268 static void OLD_Blt(int pX, int pY, int SpriteX, int SpriteY)
279 int left = mScrollX / TILEX;
280 int top = mScrollY / TILEY;
283 int sx = pX % (MAX_BUF_XSIZE * TILEX);
284 int sy = pY % (MAX_BUF_YSIZE * TILEY);
287 printf("::: DDSpriteBuffer.c: Blt(): %d, %d [%ld, %ld] [%d, %d]\n",
288 pX, pY, mScrollX, mScrollY, left, top);
294 /* do not draw fields that are outside the visible screen area */
295 if (pX < left || pX >= left + MAX_BUF_XSIZE * TILEX ||
296 pY < top || pY >= top + MAX_BUF_YSIZE * TILEY)
300 DR.left = pX + mDestXOff;
301 DR.top = pY + mDestYOff;
302 DR.right = pX + mSpriteWidth + mDestXOff;
303 DR.bottom = pY + mSpriteHeight + mDestYOff;
306 SR.left = mSpriteWidth * (SpriteX - 1);
307 SR.top = mSpriteHeight * (SpriteY - 1);
308 SR.right = SR.left + mSpriteWidth;
309 SR.bottom = SR.top + mSpriteHeight;
313 printf("::: DDSpriteBuffer.c: Blt(): %d, %d\n", DR.left, DR.top);
317 if (pX == 0 * StretchWidth && pY == 0 * StretchWidth)
318 printf("::: TEST: drawing topleft corner ...\n");
319 if (pX == 59 * StretchWidth && pY == 23 * StretchWidth)
320 printf("::: TEST: drawing bottomright corner ...\n");
326 BlitBitmap(sp_objects, screenBitmap,
328 mSpriteWidth, mSpriteHeight,
331 BlitBitmap(sp_objects, screenBitmap,
333 mSpriteWidth, mSpriteHeight,
338 Tmp = mDest.Blt(DR, &Buffer, SR, DDBLT_WAIT);
344 void DDSpriteBuffer_BltEx(int pX, int pY, int SpritePos)
351 XPos = (SpritePos % mXSpriteCount) + 1;
352 YPos = (SpritePos / mXSpriteCount) + 1;
356 printf("::: DDSpriteBuffer_BltEx(): %d, %d [%d]\n",
360 Blt(pX, pY, XPos, YPos);
363 // Public Function GetStretchCopy(Stretch!) As DDSpriteBuffer
364 // Dim SR As RECT, DR As RECT, Y%, X%, pX%, pY%, Tmp&
365 // // Set GetStretchCopy = New DDSpriteBuffer // (handle this later, if needed)
366 // If Not GetStretchCopy.CreateAtSize(Stretch * Width, Stretch * Height, mXSpriteCount, mYSpriteCount) Then
367 // Set GetStretchCopy = Nothing
369 // For Y = 0 To mYSpriteCount - 1
370 // pY = Y * Stretch * mSpriteHeight
371 // For X = 0 To mXSpriteCount - 1
372 // pX = X * Stretch * mSpriteWidth
376 // .right = pX + mSpriteWidth * Stretch
377 // .bottom = pY + mSpriteHeight * Stretch
380 // .left = mSpriteWidth * X
381 // .top = mSpriteHeight * Y
382 // .right = .left + mSpriteWidth
383 // .bottom = .top + mSpriteHeight
385 // Tmp = GetStretchCopy.Surface.Blt(DR, Buffer, SR, DDBLT_WAIT)
388 // 'GetStretchCopy.Surface.Blt DR, Buffer, DR, DDBLT_WAIT
394 static void Class_Initialize()