Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

423 lines
8.4 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (c) 1995 - 1997 Microsoft Corporation. All Rights Reserved.
  4. * Copyright (C) 1994-1995 ATI Technologies Inc. All Rights Reserved.
  5. *
  6. * File: plane.c
  7. * Content: plane manipulation functions
  8. *
  9. ***************************************************************************/
  10. #include "foxbear.h"
  11. /*
  12. * CreatePlane
  13. */
  14. HPLANE *CreatePlane ( USHORT width, USHORT height, USHORT denom )
  15. {
  16. HPLANE *hPlane;
  17. USHORT num_elems;
  18. USHORT elem_size;
  19. num_elems = width * height;
  20. elem_size = sizeof (GFX_HBM);
  21. hPlane = MemAlloc( sizeof (HPLANE) );
  22. if( hPlane == NULL )
  23. {
  24. ErrorMessage( "hPlane in CreatePlane" );
  25. }
  26. hPlane->hBM = CMemAlloc( num_elems, elem_size );
  27. hPlane->surface = CMemAlloc( num_elems, sizeof hPlane->surface );
  28. hPlane->x = 0;
  29. hPlane->y = 0;
  30. hPlane->width = width;
  31. hPlane->height = height;
  32. hPlane->denom = denom;
  33. hPlane->xslide = 0;
  34. hPlane->xincrem = 0;
  35. hPlane->xv = 0;
  36. if( hPlane->hBM == NULL )
  37. {
  38. MemFree( hPlane );
  39. ErrorMessage( "hPlane->hBM in CreatePlane" );
  40. }
  41. return hPlane;
  42. } /* CreatePlane */
  43. /*
  44. * TilePlane
  45. */
  46. BOOL TilePlane( HPLANE *hPlane, HBITMAPLIST *hTileList, HPOSLIST *posList )
  47. {
  48. USHORT i;
  49. for( i = 0; i < hPlane->width * hPlane->height; ++i )
  50. {
  51. hPlane->surface[i] = FALSE;
  52. if( posList[i] >= 0 )
  53. {
  54. hPlane->hBM[i] = hTileList[ posList[i] ].hBM;
  55. }
  56. else
  57. {
  58. hPlane->hBM[i] = NULL;
  59. }
  60. }
  61. return TRUE;
  62. } /* TilePlane */
  63. /*
  64. * SurfacePlane
  65. */
  66. BOOL SurfacePlane( HPLANE *hPlane, HSURFACELIST *hSurfaceList )
  67. {
  68. USHORT i;
  69. for( i = 0; i < hPlane->width * hPlane->height; ++i )
  70. {
  71. if( hSurfaceList[i] == FALSE )
  72. {
  73. hPlane->surface[i] = FALSE;
  74. }
  75. else
  76. {
  77. hPlane->surface[i] = TRUE;
  78. }
  79. }
  80. return TRUE;
  81. } /* SurfacePlane */
  82. /*
  83. * SetSurface
  84. */
  85. BOOL SetSurface( HPLANE *hPlane, HSPRITE *hSprite )
  86. {
  87. SHORT c;
  88. SHORT n;
  89. SHORT x;
  90. SHORT y;
  91. c = hSprite->currentBitmap;
  92. x = (hSprite->x >> 16) / C_TILE_W;
  93. y = (SHORT) hSprite->y >> 16;
  94. y += hSprite->hSBM[c].y + hSprite->hSBM[c].height;
  95. y /= C_TILE_H;
  96. n = (x % hPlane->width) + y * hPlane->width;
  97. if( hPlane->surface[n] == FALSE )
  98. {
  99. if( !hPlane->surface[n + hPlane->width] == FALSE )
  100. {
  101. y += 1;
  102. }
  103. if( !hPlane->surface[n - hPlane->width] == FALSE )
  104. {
  105. y -= 1;
  106. }
  107. }
  108. y *= C_TILE_H;
  109. y -= hSprite->hSBM[c].y + hSprite->hSBM[c].height;
  110. SetSpriteY( hSprite, y << 16, P_ABSOLUTE );
  111. return TRUE;
  112. } /* SetSurface */
  113. /*
  114. * GetSurface
  115. */
  116. BOOL GetSurface( HPLANE *hPlane, HSPRITE *hSprite )
  117. {
  118. SHORT c;
  119. SHORT x;
  120. SHORT y;
  121. c = hSprite->currentBitmap;
  122. x = ((hSprite->x >> 16) + hSprite->width / 2) / C_TILE_H;
  123. y = ((hSprite->y >> 16) + hSprite->hSBM[c].y + hSprite->hSBM[c].height) / C_TILE_W;
  124. return hPlane->surface[(x % hPlane->width) + y * hPlane->width];
  125. } /* GetSurface */
  126. /*
  127. * SetPlaneX
  128. */
  129. BOOL SetPlaneX( HPLANE *hPlane, LONG x, POSITION position )
  130. {
  131. LONG xincrem;
  132. if( position == P_ABSOLUTE )
  133. {
  134. hPlane->x = x;
  135. }
  136. else if( position == P_RELATIVE )
  137. {
  138. hPlane->x += x;
  139. }
  140. else if( position == P_AUTOMATIC )
  141. {
  142. if( hPlane->xslide > 0 )
  143. {
  144. xincrem = hPlane->xincrem;
  145. }
  146. else if( hPlane->xslide < 0 )
  147. {
  148. xincrem = -hPlane->xincrem;
  149. }
  150. else
  151. {
  152. xincrem = 0;
  153. }
  154. hPlane->x += (hPlane->xv + xincrem) / hPlane->denom;
  155. hPlane->xslide -= xincrem;
  156. hPlane->xv = 0;
  157. if( abs(hPlane->xslide) < hPlane->xincrem )
  158. {
  159. hPlane->x += hPlane->xslide / hPlane->denom;
  160. hPlane->xslide = 0;
  161. hPlane->xincrem = 0;
  162. }
  163. }
  164. if( hPlane->x < 0 )
  165. {
  166. hPlane->x += (hPlane->width * C_TILE_W) << 16;
  167. }
  168. else if( hPlane->x >= (hPlane->width * C_TILE_W) << 16 )
  169. {
  170. hPlane->x -= (hPlane->width * C_TILE_W) << 16;
  171. }
  172. return TRUE;
  173. } /* SetPlaneX */
  174. /*
  175. * GetPlaneX
  176. */
  177. LONG GetPlaneX( HPLANE *hPlane )
  178. {
  179. return hPlane->x;
  180. } /* GetPlaneX */
  181. /*
  182. * SetPlaneY
  183. */
  184. BOOL SetPlaneY( HPLANE *hPlane, LONG y, POSITION position )
  185. {
  186. if( position == P_ABSOLUTE )
  187. {
  188. hPlane->y = y;
  189. }
  190. else
  191. {
  192. hPlane->y += y;
  193. }
  194. if( hPlane->y < 0 )
  195. {
  196. hPlane->y += (hPlane->height * C_TILE_H) << 16;
  197. }
  198. else if( hPlane->y >= (hPlane->height * C_TILE_H) << 16 )
  199. {
  200. hPlane->y -= (hPlane->height * C_TILE_H) << 16;
  201. }
  202. return TRUE;
  203. } /* SetPlaneY */
  204. /*
  205. * GetPlaneY
  206. */
  207. LONG GetPlaneY( HPLANE *hPlane )
  208. {
  209. return hPlane->y;
  210. } /* GetPlaneY */
  211. /*
  212. * SetPlaneSlideX
  213. */
  214. BOOL SetPlaneSlideX( HPLANE *hPlane, LONG xslide, POSITION position )
  215. {
  216. if( position == P_ABSOLUTE )
  217. {
  218. hPlane->xslide = xslide;
  219. }
  220. else if( position == P_RELATIVE )
  221. {
  222. hPlane->xslide += xslide;
  223. }
  224. return TRUE;
  225. } /* SetPlaneSlideX */
  226. /*
  227. * SetPlaneVelX
  228. */
  229. BOOL SetPlaneVelX( HPLANE *hPlane, LONG xv, POSITION position )
  230. {
  231. if( position == P_ABSOLUTE )
  232. {
  233. hPlane->xv = xv;
  234. }
  235. else if( position == P_RELATIVE )
  236. {
  237. hPlane->xv += xv;
  238. }
  239. return TRUE;
  240. } /* SetPlaneVelX */
  241. /*
  242. * SetPlaneIncremX
  243. */
  244. BOOL SetPlaneIncremX( HPLANE *hPlane, LONG xincrem, POSITION position )
  245. {
  246. if( position == P_ABSOLUTE )
  247. {
  248. hPlane->xincrem = xincrem;
  249. }
  250. else if( position == P_RELATIVE )
  251. {
  252. hPlane->xincrem += xincrem;
  253. }
  254. return TRUE;
  255. } /* SetPlaneIncremX */
  256. /*
  257. * ScrollPlane
  258. */
  259. BOOL ScrollPlane( HSPRITE *hSprite )
  260. {
  261. if( (GetSpriteX(hSprite) <= C_FOX_STARTX) && (GetSpriteVelX(hSprite) < 0) )
  262. {
  263. return TRUE;
  264. }
  265. if( (GetSpriteX(hSprite) >= C_FOX_STARTX) && (GetSpriteVelX(hSprite) > 0) )
  266. {
  267. return TRUE;
  268. }
  269. return FALSE;
  270. } /* ScrollPlane */
  271. /*
  272. * DisplayPlane
  273. */
  274. BOOL DisplayPlane ( GFX_HBM hBuffer, HPLANE *hPlane )
  275. {
  276. USHORT n;
  277. USHORT i;
  278. USHORT j;
  279. USHORT x1;
  280. USHORT y1;
  281. USHORT x2;
  282. USHORT y2;
  283. USHORT xmod;
  284. USHORT ymod;
  285. POINT src;
  286. RECT dst;
  287. x1 = (hPlane->x >> 16) / C_TILE_W;
  288. y1 = (hPlane->y >> 16) / C_TILE_H;
  289. x2 = x1 + C_SCREEN_W / C_TILE_W;
  290. y2 = y1 + C_SCREEN_H / C_TILE_H;
  291. xmod = (hPlane->x >> 16) % C_TILE_W;
  292. ymod = (hPlane->y >> 16) % C_TILE_H;
  293. for( j = y1; j < y2; ++j )
  294. {
  295. for( i = x1; i <= x2; ++i )
  296. {
  297. n = (i % hPlane->width) + j * hPlane->width;
  298. if( hPlane->hBM[n] != NULL )
  299. {
  300. if( i == x1 )
  301. {
  302. dst.left = 0;
  303. dst.right = dst.left + C_TILE_W - xmod;
  304. src.x = xmod;
  305. }
  306. else if( i == x2 )
  307. {
  308. dst.left = (i - x1) * C_TILE_W - xmod;
  309. dst.right = dst.left + xmod;
  310. src.x = 0;
  311. } else {
  312. dst.left = (i - x1) * C_TILE_W - xmod;
  313. dst.right = dst.left + C_TILE_W;
  314. src.x = 0;
  315. }
  316. if( j == y1 )
  317. {
  318. dst.top = 0;
  319. dst.bottom = dst.top + C_TILE_H - ymod;
  320. src.y = ymod;
  321. }
  322. else if( j == y2 )
  323. {
  324. dst.top = (j - y1) * C_TILE_H - ymod;
  325. dst.bottom = dst.top + ymod;
  326. src.y = 0;
  327. } else {
  328. dst.top = (j - y1) * C_TILE_H - ymod;
  329. dst.bottom = dst.top + C_TILE_H;
  330. src.y = 0;
  331. }
  332. gfxBlt(&dst,hPlane->hBM[n],&src);
  333. }
  334. }
  335. }
  336. return TRUE;
  337. } /* DisplayPlane */
  338. /*
  339. * DestroyPlane
  340. */
  341. BOOL DestroyPlane ( HPLANE *hPlane )
  342. {
  343. if( hPlane == NULL )
  344. {
  345. ErrorMessage( "hPlane in DestroyPlane" );
  346. }
  347. if( hPlane->hBM == NULL )
  348. {
  349. ErrorMessage( "hPlane->hBM in DestroyPlane" );
  350. }
  351. MemFree( hPlane->hBM );
  352. MemFree( hPlane );
  353. return TRUE;
  354. } /* DestroyPlane */