ImageHandler.cpp
上传用户:cydong117
上传日期:2009-11-10
资源大小:638k
文件大小:11k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. /******************************************************************************************************************
  2.                                                                                                                    
  3. 葛碘疙:
  4. 累己磊:
  5. 累己老:
  6. [老磊][荐沥磊] : 荐沥 郴侩
  7.                                                                                                                    
  8. *******************************************************************************************************************/
  9. #include "StdAfx.h"
  10. /******************************************************************************************************************
  11. CImageHandler Class
  12. *******************************************************************************************************************/
  13. /******************************************************************************************************************
  14. 窃荐疙 : CImageHandler::CImageHandler()
  15. 累己磊 : 
  16. 累己老 : 
  17. 格利   : 
  18. 免仿   : 
  19. [老磊][荐沥磊] : 荐沥郴侩
  20. *******************************************************************************************************************/
  21. CImageHandler::CImageHandler()
  22. {
  23. INT nCnt;
  24. ZeroMemory(m_xImageList, sizeof(CWHWilImageData)*_MAX_IMAGE);
  25. ZeroMemory(m_nLoadedMagic, sizeof(INT)*_MAX_MAGIC);
  26. for ( nCnt = 0; nCnt < _MAX_TEXTR_FILE; nCnt++ )
  27. {
  28. m_xTextrFileList[nCnt].ClearAllNodes();
  29. }
  30. }
  31. /******************************************************************************************************************
  32. 窃荐疙 : CImageHandler::~CImageHandler()
  33. 累己磊 : 
  34. 累己老 : 
  35. 格利   : 
  36. 免仿   : 
  37. [老磊][荐沥磊] : 荐沥郴侩
  38. *******************************************************************************************************************/
  39. CImageHandler::~CImageHandler()
  40. {
  41. DeleteAllImage();
  42. }
  43. /******************************************************************************************************************
  44. 窃荐疙 : CImageHandler::LoadAllImage()
  45. 累己磊 : 
  46. 累己老 : 
  47. 格利   : 
  48. 涝仿   : BOOL bIsMemMapped
  49.          BOOL bComp
  50. 免仿   : VOID 
  51. [老磊][荐沥磊] : 荐沥郴侩
  52. *******************************************************************************************************************/
  53. VOID CImageHandler::LoadAllImage(BOOL bIsMemMapped, BOOL bComp)
  54. {
  55. /* IMAGE DEFINE巩苞 老摹秦具茄促.--------------------------------------------------------------*/
  56. CHAR* szFileList[] = 
  57. {
  58. //~~~ 硅版捞固瘤. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. ".\Data\tilesc.wil", //0
  60. ".\Data\tiles30c.wil", //1
  61. ".\Data\Tiles5c.wil", //2
  62. ".\Data\smtilesc.wil", //3
  63. ".\Data\housesc.wil", //4
  64. ".\Data\cliffsc.wil", //5
  65. ".\Data\dungeonsc.wil", //6
  66. ".\Data\innersc.wil", //7
  67. ".\Data\furnituresc.wil", //8
  68. ".\Data\wallsc.wil", //9
  69. ".\Data\smobjectsc.wil", //10
  70. ".\Data\animationsc.wil", //11
  71. ".\Data\object1c.wil", //12
  72. ".\Data\object2c.wil", //13
  73. //~~~ 牢磐其捞胶捞固瘤. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  74. ".\Data\GameInter.wil", //14 
  75. //~~~ 巢磊捞固瘤. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76. ".\Data\M-Hum.wil", //15 
  77. ".\Data\M-Hair.wil", //16 
  78. ".\Data\M-Weapon1.wil", //17
  79. ".\Data\M-Weapon2.wil", //18
  80. ".\Data\M-Weapon3.wil", //19
  81. ".\Data\M-Weapon4.wil", //20
  82. //~~~ 咯磊捞固瘤. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  83. ".\Data\WM-Hum.wil", //21
  84. ".\Data\WM-Hair.wil", //22
  85. ".\Data\WM-Weapon1.wil", //23
  86. ".\Data\WM-Weapon2.wil", //24
  87. ".\Data\WM-Weapon3.wil", //25
  88. ".\Data\WM-Weapon4.wil", //26
  89. //~~~ 酒捞袍 棺 牢磐其捞胶, 付过, 扁鸥捞固瘤. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90. ".\Data\Magic.wil", //27
  91. ".\Data\Inventory.wil", //29
  92. ".\Data\Equip.wil", //29
  93. ".\Data\Ground.wil", //30
  94. ".\Data\MIcon.wil", //31
  95. ".\Data\ProgUse.wil", //32
  96. ".\Data\Horse.wil", //33
  97. //~~~ 阁胶磐捞固瘤. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  98. ".\Data\Mon-1.wil", //34
  99. ".\Data\Mon-2.wil", //35
  100. ".\Data\Mon-3.wil", //36
  101. ".\Data\Mon-4.wil", //37
  102. ".\Data\Mon-5.wil", //38
  103. ".\Data\Mon-6.wil", //39
  104. ".\Data\Mon-7.wil", //40
  105. ".\Data\Mon-8.wil", //41
  106. ".\Data\Mon-9.wil", //42
  107. ".\Data\Mon-10.wil", //43
  108. ".\Data\Mon-11.wil", //44
  109. ".\Data\Mon-12.wil", //45
  110. //~~~ 阁胶磐弊覆磊捞固瘤. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111. ".\Data\MonS-1.wil", //46
  112. ".\Data\MonS-2.wil", //47
  113. ".\Data\MonS-3.wil", //48
  114. ".\Data\MonS-4.wil", //49
  115. ".\Data\MonS-5.wil", //40
  116. ".\Data\MonS-6.wil", //51
  117. ".\Data\MonS-7.wil", //52
  118. ".\Data\MonS-8.wil", //53
  119. ".\Data\MonS-9.wil", //54
  120. ".\Data\MonS-10.wil", //55
  121. ".\Data\MonS-11.wil", //56
  122. ".\Data\MonS-12.wil", //57
  123. //~~~ NPC 捞固瘤. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  124. ".\Data\NPC.wil", //58
  125. //~~~ 阁胶磐付过 捞固瘤. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  126. ".\Data\MonMagic.wil", //59
  127. //~~~ 牢磐其捞胶EX 捞固瘤. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  128. ".\Data\interfacec2.wil", //60
  129. };
  130. InitAllImage();
  131. for ( INT nCnt = 0; nCnt < _MAX_IMAGE; nCnt++ )
  132. m_xImageList[nCnt].NewLoad(szFileList[nCnt], bIsMemMapped, bComp);
  133. }
  134. VOID CImageHandler::InitAllImage()
  135. {
  136. for ( INT nCnt = 0; nCnt < _MAX_IMAGE; nCnt++ )
  137. m_xImageList[nCnt].Init();
  138. ZeroMemory(m_nLoadedMagic, sizeof(INT)*_MAX_MAGIC);
  139.   D3DVECTOR vNorm(0, 0, -1);
  140. m_avBillBoard[0]  = D3DVERTEX(D3DVECTOR(-0.5f, 0.5f, 0), vNorm, 0, 0);
  141. m_avBillBoard[1]  = D3DVERTEX(D3DVECTOR(-0.5f,-0.5f, 0), vNorm, 0, 1);
  142. m_avBillBoard[2]  = D3DVERTEX(D3DVECTOR( 0.5f, 0.5f, 0), vNorm, 1, 0);
  143. m_avBillBoard[3]  = D3DVERTEX(D3DVECTOR( 0.5f,-0.5f, 0), vNorm, 1, 1);
  144. for ( nCnt = 0; nCnt < _MAX_TEXTR_FILE; nCnt++ )
  145. {
  146. m_xTextrFileList[nCnt].ClearAllNodes();
  147. }
  148. }
  149. /******************************************************************************************************************
  150. 窃荐疙 : CImageHandler::DeleteAllImage()
  151. 累己磊 : 
  152. 累己老 : 
  153. 格利   : 
  154. 免仿   : VOID 
  155. [老磊][荐沥磊] : 荐沥郴侩
  156. *******************************************************************************************************************/
  157. VOID CImageHandler::DeleteAllImage()
  158. {
  159. INT nCnt;
  160. for ( nCnt = 0; nCnt < _MAX_IMAGE; nCnt++ )
  161. m_xImageList[nCnt].Destroy();
  162. ZeroMemory(m_nLoadedMagic, sizeof(INT)*_MAX_MAGIC);
  163. for ( nCnt = 0; nCnt < _MAX_TEXTR_FILE; nCnt++ )
  164. {
  165. m_xTextrFileList[nCnt].ClearAllNodes();
  166. }
  167. }
  168. VOID CImageHandler::AddTextr(WORD wFileType, WORD wFileIdx, WORD wImgIdx)
  169. {
  170. if ( wFileType < _MAX_TEXTR_FILE )
  171. {
  172. if ( m_xImageList[wFileIdx].NewSetIndex(wImgIdx) )
  173. {
  174. if ( D3DWILTextr_CreateEmptyTexture(m_xImageList[wFileIdx].m_szWilFileName, wImgIdx, 
  175.     m_xImageList[wFileIdx].m_lpstNewCurrWilImageInfo->shWidth,
  176. m_xImageList[wFileIdx].m_lpstNewCurrWilImageInfo->shHeight,
  177. (WORD*)m_xImageList[wFileIdx].m_pbCurrImage, D3DTEXTR_TRANSPARENTBLACK) )
  178. {
  179. LPTEXTUREFILE pstTexFile = new TEXTUREFILE;
  180. pstTexFile->wFileIdx  = wFileIdx;
  181. pstTexFile->wImgIdx  = wImgIdx;
  182. pstTexFile->lpddsTextr  = D3DWILTextr_RestoreEx(m_xImageList[wFileIdx].m_szWilFileName, wImgIdx, g_xMainWnd.Get3DDevice());
  183. m_xTextrFileList[wFileType].AddNode(pstTexFile);
  184. return;
  185. }
  186. }
  187. }
  188. }
  189. VOID CImageHandler::DelTextr(WORD wFileType, WORD wFileIdx, WORD wImgIdx)
  190. {
  191. if ( wFileType < _MAX_TEXTR_FILE )
  192. {
  193. D3DWILTextr_Invalidate(m_xImageList[wFileIdx].m_szWilFileName, wImgIdx);
  194. D3DWILTextr_DestroyTexture(m_xImageList[wFileIdx].m_szWilFileName, wImgIdx);
  195. m_xTextrFileList[wFileType].MoveCurrentToTop();
  196. for ( INT nCnt = 0; nCnt < m_xTextrFileList[wFileType].GetCounter(); nCnt++ )
  197. {
  198. LPTEXTUREFILE pstTexFile = m_xTextrFileList[wFileType].GetCurrentData();
  199. if ( pstTexFile->wFileIdx == wFileIdx && pstTexFile->wImgIdx == wImgIdx )
  200. {
  201. m_xTextrFileList[wFileType].DeleteCurrentNode();
  202. return;
  203. }
  204. m_xTextrFileList[wFileType].MoveNextNode();
  205. }
  206. }
  207. }
  208. LPDIRECTDRAWSURFACE7 CImageHandler::GetTextrImg(WORD wFileType, WORD wFileIdx, WORD wImgIdx)
  209. {
  210. if ( wFileType < _MAX_TEXTR_FILE )
  211. {
  212. m_xTextrFileList[wFileType].MoveCurrentToTop();
  213. for ( INT nCnt = 0; nCnt < m_xTextrFileList[wFileType].GetCounter(); nCnt++ )
  214. {
  215. LPTEXTUREFILE pstTexFile = m_xTextrFileList[wFileType].GetCurrentData();
  216. if ( pstTexFile->wFileIdx == wFileIdx && pstTexFile->wImgIdx == wImgIdx )
  217. {
  218. return pstTexFile->lpddsTextr;
  219. }
  220. m_xTextrFileList[wFileType].MoveNextNode();
  221. }
  222. }
  223. return NULL;
  224. }
  225. VOID CImageHandler::DelAllTextrFileList()
  226. {
  227. INT nCnt;
  228. for ( nCnt = 0; nCnt < _MAX_TEXTR_FILE; nCnt++ )
  229. {
  230. m_xTextrFileList[nCnt].ClearAllNodes();
  231. }
  232. }
  233. HRESULT CImageHandler::DrawBillBoard(LPDIRECT3DDEVICE7 lpDevice, D3DVECTOR vTrans, D3DVECTOR vScale, /*D3DVECTOR vRot, */D3DMATERIAL7 mtrl, /*FLOAT fRotRad, */LPDIRECTDRAWSURFACE7 lpddsTextr)
  234. {
  235. if ( lpDevice )
  236. {
  237. if( SUCCEEDED(lpDevice->BeginScene()) )
  238. {
  239. D3DMATRIX matTrans;
  240. D3DMATRIX matScale;
  241. D3DMATRIX matRot;
  242. D3DMATRIX matWorld;
  243. D3DMATRIX matTempWorld;
  244. D3DMATRIX matWorldOriginal;
  245. lpDevice->GetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);
  246. vTrans.x = vTrans.x+vScale.x/2-400;
  247. vTrans.y = -vTrans.y-vScale.y/2+300;
  248. D3DUtil_SetTranslateMatrix(matTrans, vTrans);
  249. D3DUtil_SetScaleMatrix(matScale, vScale.x, vScale.y, vScale.z);
  250. // D3DUtil_SetRotationMatrix(matRot, vRot, fRotRad);
  251. D3DMath_MatrixMultiply(/*matTempWorld*/matWorld, matScale, matTrans);
  252. // D3DMath_MatrixMultiply(matWorld, matRot, matTempWorld);
  253. lpDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorld);
  254. SetBlendRenderState(lpDevice, _BLEND_NORMAL, mtrl);
  255. lpDevice->SetMaterial(&mtrl);
  256. lpDevice->SetTexture(0, lpddsTextr);
  257. lpDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX, m_avBillBoard, 4, NULL);
  258. // 盔惑汗蓖.
  259. ZeroMemory(&mtrl, sizeof(mtrl));
  260. mtrl.diffuse.r = mtrl.diffuse.g = mtrl.diffuse.b = 0.1f;
  261. mtrl.ambient.r = mtrl.ambient.g = mtrl.ambient.b = 1.0f;
  262. lpDevice->SetMaterial(&mtrl);
  263. ResetBlendenderState(lpDevice);
  264. lpDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);
  265. }
  266. lpDevice->EndScene();
  267. return S_OK;
  268. }
  269. return E_FAIL;
  270. }