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

模拟服务器

开发平台:

Visual C++

  1. /******************************************************************************************************************
  2.                                                                                                                    
  3. 葛碘疙:
  4. 累己磊:
  5. 累己老:
  6. [老磊][荐沥磊] : 荐沥 郴侩
  7.                                                                                                                    
  8. *******************************************************************************************************************/
  9. #include "StdAfx.h"
  10. struct WILTextureContainer
  11. {
  12.     WILTextureContainer* m_pNext;
  13.     TCHAR   m_strWilFileName[80];
  14. INT m_nIdx;
  15. WORD* m_pwData; // Surface肺 肺爹矫懦锭父 蔼捞 沥狼等促. 弊寇浚 亲惑 NULL捞促.<---???
  16.     DWORD   m_dwFlags;
  17.     DWORD   m_dwWidth;
  18.     DWORD   m_dwHeight;
  19.     LPDIRECTDRAWSURFACE7 m_pddsSurface;
  20. public:
  21. //  HRESULT LoadImageData();
  22.     HRESULT Restore(LPDIRECT3DDEVICE7 pd3dDevice);
  23.     HRESULT CopyDataToSurface();
  24. HRESULT CopyDataToSurfaceToSurface();
  25.     WILTextureContainer(TCHAR* strWilFileName, INT nIndex, DWORD dwFlags);
  26.     ~WILTextureContainer();
  27. };
  28. static WILTextureContainer* g_ptcWILTextureList = NULL;
  29. class CD3DWILTextureManager
  30. {
  31. public:
  32.     CD3DWILTextureManager () {}
  33.     ~CD3DWILTextureManager() { if ( g_ptcWILTextureList ) delete g_ptcWILTextureList; }
  34. };
  35. CD3DWILTextureManager g_StaticWILTextureEngine;
  36. struct TEXTURESEARCHINFO
  37. {
  38.     DWORD dwDesiredBPP;
  39.     BOOL  bUseAlpha;
  40.     BOOL  bUsePalette;
  41.     BOOL  bFoundGoodFormat;
  42.     DDPIXELFORMAT* pddpf;
  43. };
  44. static HRESULT CALLBACK TextureSearchCallback(DDPIXELFORMAT* pddpf, VOID* param)
  45. {
  46.     if ( NULL==pddpf || NULL==param )
  47.         return DDENUMRET_OK;
  48.     TEXTURESEARCHINFO* ptsi = (TEXTURESEARCHINFO*)param;
  49.     if ( pddpf->dwFlags & (DDPF_LUMINANCE|DDPF_BUMPLUMINANCE|DDPF_BUMPDUDV) )
  50.         return DDENUMRET_OK;
  51.     if ( ptsi->bUsePalette )
  52.     {
  53.         if( !(pddpf->dwFlags & DDPF_PALETTEINDEXED8) )
  54.             return DDENUMRET_OK;
  55.         memcpy(ptsi->pddpf, pddpf, sizeof(DDPIXELFORMAT));
  56.         ptsi->bFoundGoodFormat = TRUE;
  57.         return DDENUMRET_CANCEL;
  58.     }
  59.     if ( pddpf->dwRGBBitCount < 16 )
  60.         return DDENUMRET_OK;
  61.     if ( pddpf->dwFourCC != 0 )
  62.         return DDENUMRET_OK;
  63.     if( pddpf->dwRGBAlphaBitMask == 0x0000f000 )
  64.         return DDENUMRET_OK;
  65.     if ( (ptsi->bUseAlpha==TRUE) && !(pddpf->dwFlags&DDPF_ALPHAPIXELS) )
  66.         return DDENUMRET_OK;
  67.     if ( (ptsi->bUseAlpha==FALSE) && (pddpf->dwFlags&DDPF_ALPHAPIXELS) )
  68.         return DDENUMRET_OK;
  69.     if ( pddpf->dwRGBBitCount == ptsi->dwDesiredBPP )
  70.     {
  71.         memcpy(ptsi->pddpf, pddpf, sizeof(DDPIXELFORMAT));
  72.         ptsi->bFoundGoodFormat = TRUE;
  73.         return DDENUMRET_CANCEL;
  74.     }
  75.     return DDENUMRET_OK;
  76. }
  77. static WILTextureContainer* FindWilTexture(TCHAR* strWilFileName, INT nIdx)
  78. {
  79.     WILTextureContainer* ptcWILTexture = g_ptcWILTextureList;
  80.     while ( ptcWILTexture )
  81.     {
  82.         if ( !lstrcmpi(strWilFileName, ptcWILTexture->m_strWilFileName) &&
  83.  nIdx == ptcWILTexture->m_nIdx )
  84. {
  85.             return ptcWILTexture;
  86. }
  87.         ptcWILTexture = ptcWILTexture->m_pNext;
  88.     }
  89.     return NULL;
  90. }
  91. BOOL D3DWILTextr_IsTextrExisted(TCHAR* strWilFileName, INT nIdx)
  92. {
  93.     if ( NULL != FindWilTexture(strWilFileName, nIdx) )
  94.         return TRUE;
  95. return FALSE;
  96. }
  97. WILTextureContainer::WILTextureContainer(TCHAR* strWilFileName, INT nIndex, DWORD dwFlags)
  98. {
  99.     lstrcpy(m_strWilFileName, strWilFileName);
  100. m_nIdx = nIndex;
  101.     m_dwWidth = 0;
  102.     m_dwHeight = 0;
  103.     m_dwFlags = dwFlags;
  104.     m_pddsSurface = NULL;
  105. m_pwData = NULL;
  106.     m_pNext = g_ptcWILTextureList;
  107.     g_ptcWILTextureList = this;
  108. }
  109. WILTextureContainer::~WILTextureContainer()
  110. {
  111.     SAFE_RELEASE( m_pddsSurface );
  112.     if ( g_ptcWILTextureList == this )
  113.         g_ptcWILTextureList = m_pNext;
  114.     else
  115.     {
  116.         for ( WILTextureContainer* ptc = g_ptcWILTextureList; ptc; ptc=ptc->m_pNext )
  117.             if ( ptc->m_pNext == this )
  118.                 ptc->m_pNext = m_pNext;
  119.     }
  120. }
  121. HRESULT WILTextureContainer::Restore(LPDIRECT3DDEVICE7 pd3dDevice)
  122. {
  123.     SAFE_RELEASE(m_pddsSurface);
  124.     if( NULL == pd3dDevice )
  125.         return DDERR_INVALIDPARAMS;
  126.     D3DDEVICEDESC7 ddDesc;
  127.     if ( FAILED(pd3dDevice->GetCaps(&ddDesc)) )
  128.         return E_FAIL;
  129.     DDSURFACEDESC2 ddsd;
  130.     D3DUtil_InitSurfaceDesc( ddsd );
  131.     ddsd.dwFlags         = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|
  132.                            /*DDSD_PIXELFORMAT|*/DDSD_TEXTURESTAGE;
  133.     ddsd.ddsCaps.dwCaps  = DDSCAPS_TEXTURE;
  134.     ddsd.dwTextureStage  = 0;
  135.     ddsd.dwWidth         = m_dwWidth;
  136.     ddsd.dwHeight        = m_dwHeight;
  137.     if ( ddDesc.deviceGUID == IID_IDirect3DHALDevice || ddDesc.deviceGUID == IID_IDirect3DTnLHalDevice )
  138.         ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
  139.     else
  140.         ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
  141. // Setting Power of 2
  142.     if ( ddDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2 )
  143.     {
  144.         for ( ddsd.dwWidth =1; m_dwWidth>ddsd.dwWidth;   ddsd.dwWidth<<=1 );
  145.         for ( ddsd.dwHeight=1; m_dwHeight>ddsd.dwHeight; ddsd.dwHeight<<=1 );
  146.     }
  147.     DWORD dwMaxWidth  = ddDesc.dwMaxTextureWidth;
  148.     DWORD dwMaxHeight = ddDesc.dwMaxTextureHeight;
  149.     ddsd.dwWidth  = min(ddsd.dwWidth,  (dwMaxWidth  ? dwMaxWidth  : 256));
  150.     ddsd.dwHeight = min(ddsd.dwHeight, (dwMaxHeight ? dwMaxHeight : 256));
  151. // 流荤阿屈狼 咆胶苗甫 瘤盔窍瘤 臼绰促搁...
  152.     if ( ddDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY )
  153.     {
  154.         if ( ddsd.dwWidth > ddsd.dwHeight ) ddsd.dwHeight = ddsd.dwWidth;
  155.         else                                ddsd.dwWidth  = ddsd.dwHeight;
  156.     }
  157. // 咆胶苗 侨伎器杆技泼...
  158.     TEXTURESEARCHINFO tsi;
  159.     tsi.bFoundGoodFormat = FALSE;
  160.     tsi.pddpf            = &ddsd.ddpfPixelFormat;
  161.     tsi.dwDesiredBPP     = 16;
  162.     tsi.bUsePalette      = ( 16 <= 8 );
  163.     tsi.bUseAlpha        = FALSE;
  164.     tsi.dwDesiredBPP  = 16;
  165.     pd3dDevice->EnumTextureFormats( TextureSearchCallback, &tsi );
  166.     if( FALSE == tsi.bFoundGoodFormat )
  167.     {
  168. return E_FAIL;
  169.     }
  170.     LPDIRECTDRAW7        pDD;
  171.     LPDIRECTDRAWSURFACE7 pddsRender;
  172.     pd3dDevice->GetRenderTarget(&pddsRender);
  173.     pddsRender->GetDDInterface((VOID**)&pDD);
  174.     pddsRender->Release();
  175.     HRESULT hr = pDD->CreateSurface(&ddsd, &m_pddsSurface, NULL);
  176.     pDD->Release();
  177.     if( FAILED(hr) )
  178.         return hr;
  179. if ( ddsd.dwWidth == m_dwWidth && ddsd.dwHeight == m_dwHeight )
  180. CopyDataToSurface();
  181. else
  182. CopyDataToSurfaceToSurface();
  183. // 拿矾虐甫 技泼茄促.
  184. DDSetColorKey(m_pddsSurface, RGB(0, 0, 0));
  185.     return S_OK;
  186. }
  187. HRESULT WILTextureContainer::CopyDataToSurfaceToSurface()
  188. {
  189. LPDIRECTDRAW7 pDD;
  190.     m_pddsSurface->GetDDInterface((VOID**)&pDD);
  191.     DDSURFACEDESC2 ddsd;
  192.     ddsd.dwSize = sizeof(ddsd);
  193.     m_pddsSurface->GetSurfaceDesc(&ddsd);
  194.     ddsd.dwFlags         = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|//DDSD_PIXELFORMAT|
  195.                            DDSD_TEXTURESTAGE;
  196.     ddsd.ddsCaps.dwCaps  = DDSCAPS_TEXTURE|DDSCAPS_SYSTEMMEMORY;
  197.     ddsd.ddsCaps.dwCaps2 = 0L;
  198.     ddsd.dwWidth         = m_dwWidth;
  199.     ddsd.dwHeight        = m_dwHeight;
  200.     LPDIRECTDRAWSURFACE7 pddsTempSurface;
  201.     HRESULT hr;
  202.     if ( FAILED(hr = pDD->CreateSurface(&ddsd, &pddsTempSurface, NULL) ) )
  203.     {
  204.         pDD->Release();
  205.         return NULL;
  206.     }
  207.     while ( pddsTempSurface->Lock(NULL, &ddsd, 0, 0) == DDERR_WASSTILLDRAWING );
  208.     DWORD lPitch = ddsd.lPitch;
  209.     WORD* pwData = (WORD*)ddsd.lpSurface;
  210. RECT rc;
  211. SetRect(&rc, 0, 0, m_dwWidth, m_dwHeight);
  212. WORD* pwdDst = pwData;
  213. INT nWidthStart = 0;
  214. INT nWidthEnd = 0;
  215. INT nCurrWidth  = 0;
  216. INT nCntCopyWord = 0;
  217. INT nYCnt =0;
  218. INT nLastWidth = 0;
  219. // y绵 努府俏.
  220. for ( nYCnt=0 ; nYCnt < rc.top ; nYCnt++ )
  221. {
  222. nWidthEnd += m_pwData[nWidthStart];
  223. nWidthStart++;
  224. nWidthEnd++;
  225. nWidthStart = nWidthEnd;
  226. }
  227. // y绵俊 措秦辑 角力肺 风俏矫懦 Count父阑 沥茄促.
  228. for ( nYCnt=rc.top ; nYCnt < rc.bottom ; nYCnt++ )
  229. {
  230. // 茄扼牢狼 辨捞甫 掘绢柯促.(窜困绰 况靛)
  231. nWidthEnd += m_pwData[nWidthStart];
  232. nWidthStart++;
  233. // 扼牢狼 辨捞父怒 拳搁俊 谎妨霖促.
  234. for ( INT x = nWidthStart; x < nWidthEnd ; )
  235. {
  236. if ( m_pwData[x] == 0xC0 )
  237. {
  238. x++;
  239. nCntCopyWord = m_pwData[x];
  240. x++;
  241. nCurrWidth += nCntCopyWord;
  242. }
  243. else if ( m_pwData[x] == 0xC1 )
  244. {
  245. x++;
  246. nCntCopyWord = m_pwData[x];
  247. x++;
  248. nLastWidth = nCurrWidth;
  249. nCurrWidth += nCntCopyWord;
  250. if ( rc.left > nCurrWidth || rc.right < nLastWidth )
  251. {
  252. x += nCntCopyWord;
  253. }
  254. else
  255. {
  256. // rc.left痢阑 扁霖栏肺 墨乔且 康开捞 吧赴 版快.
  257. if ( nLastWidth < rc.left && rc.left <= nCurrWidth )
  258. {
  259. x += (rc.left-nLastWidth);
  260. memcpy(&pwdDst[((nYCnt) * (ddsd.lPitch >> 1)) + (rc.left)], &m_pwData[x], sizeof(WORD)*(nCurrWidth-rc.left));
  261. x += (nCurrWidth-rc.left);
  262. }
  263. // rc.right痢阑 扁霖栏肺 墨乔且 康开捞 吧赴 版快.
  264. else if ( nLastWidth <= rc.right && rc.right < nCurrWidth )
  265. {
  266. memcpy(&pwdDst[((nYCnt) * (ddsd.lPitch >> 1)) + (nLastWidth)], &m_pwData[x], sizeof(WORD)*(rc.right-nLastWidth));
  267. x += nCntCopyWord;
  268. }
  269. else
  270. {
  271. memcpy(&pwdDst[((nYCnt) * (ddsd.lPitch >> 1)) + (nLastWidth)], &m_pwData[x], sizeof(WORD)*nCntCopyWord);
  272. x += nCntCopyWord;
  273. }
  274. }
  275. }
  276. }
  277. // 扼牢狼 场阑 促澜 扼牢狼 矫累栏肺 颗败霖促.
  278. nWidthEnd++;
  279. nWidthStart = nWidthEnd;
  280. nCurrWidth = 0;
  281. }
  282.     
  283. pddsTempSurface->Unlock(0);
  284.     m_pddsSurface->Blt(NULL, pddsTempSurface, NULL, DDBLT_WAIT, NULL);
  285.     pddsTempSurface->Release();
  286.     pDD->Release();
  287.     return S_OK;
  288. }
  289. HRESULT WILTextureContainer::CopyDataToSurface()
  290. {
  291. /*  
  292. LPDIRECTDRAW7 pDD;
  293.     m_pddsSurface->GetDDInterface((VOID**)&pDD);
  294.     DDSURFACEDESC2 ddsd;
  295.     ddsd.dwSize = sizeof(ddsd);
  296.     m_pddsSurface->GetSurfaceDesc(&ddsd);
  297.     ddsd.dwFlags         = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|//DDSD_PIXELFORMAT|
  298.                            DDSD_TEXTURESTAGE;
  299.     ddsd.ddsCaps.dwCaps  = DDSCAPS_TEXTURE|DDSCAPS_SYSTEMMEMORY;
  300.     ddsd.ddsCaps.dwCaps2 = 0L;
  301.     ddsd.dwWidth         = m_dwWidth;
  302.     ddsd.dwHeight        = m_dwHeight;
  303.     LPDIRECTDRAWSURFACE7 pddsTempSurface;
  304.     HRESULT hr;
  305.     if ( FAILED(hr = pDD->CreateSurface(&ddsd, &pddsTempSurface, NULL) ) )
  306.     {
  307.         pDD->Release();
  308.         return NULL;
  309.     }
  310.     while ( pddsTempSurface->Lock(NULL, &ddsd, 0, 0) == DDERR_WASSTILLDRAWING );
  311.     DWORD lPitch = ddsd.lPitch;
  312.     WORD* pwData = (WORD*)ddsd.lpSurface;
  313. memcpy(pwData, m_pwData, sizeof(WORD)*m_dwWidth*m_dwHeight);
  314.     pddsTempSurface->Unlock(0);
  315.     m_pddsSurface->Blt(NULL, pddsTempSurface, NULL, DDBLT_WAIT, NULL);
  316.     pddsTempSurface->Release();
  317.     pDD->Release();
  318. */
  319. RECT rc;
  320. DDSURFACEDESC2 ddsd;
  321. SetRect(&rc, 0, 0, m_dwWidth, m_dwHeight);
  322. ddsd.dwSize = sizeof(DDSURFACEDESC2);
  323. ddsd.lpSurface = NULL;
  324. m_pddsSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
  325. if ( !ddsd.lpSurface )
  326. return NULL;
  327. WORD* pwdDst;
  328. pwdDst = (WORD*)ddsd.lpSurface;
  329. INT nWidthStart = 0;
  330. INT nWidthEnd = 0;
  331. INT nCurrWidth  = 0;
  332. INT nCntCopyWord = 0;
  333. INT nYCnt =0;
  334. INT nLastWidth = 0;
  335. // y绵 努府俏.
  336. for ( nYCnt=0 ; nYCnt < rc.top ; nYCnt++ )
  337. {
  338. nWidthEnd += m_pwData[nWidthStart];
  339. nWidthStart++;
  340. nWidthEnd++;
  341. nWidthStart = nWidthEnd;
  342. }
  343. // y绵俊 措秦辑 角力肺 风俏矫懦 Count父阑 沥茄促.
  344. for ( nYCnt=rc.top ; nYCnt < rc.bottom ; nYCnt++ )
  345. {
  346. // 茄扼牢狼 辨捞甫 掘绢柯促.(窜困绰 况靛)
  347. nWidthEnd += m_pwData[nWidthStart];
  348. nWidthStart++;
  349. // 扼牢狼 辨捞父怒 拳搁俊 谎妨霖促.
  350. for ( INT x = nWidthStart; x < nWidthEnd ; )
  351. {
  352. if ( m_pwData[x] == 0xC0 )
  353. {
  354. x++;
  355. nCntCopyWord = m_pwData[x];
  356. x++;
  357. nCurrWidth += nCntCopyWord;
  358. }
  359. else if ( m_pwData[x] == 0xC1 )
  360. {
  361. x++;
  362. nCntCopyWord = m_pwData[x];
  363. x++;
  364. nLastWidth = nCurrWidth;
  365. nCurrWidth += nCntCopyWord;
  366. if ( rc.left > nCurrWidth || rc.right < nLastWidth )
  367. {
  368. x += nCntCopyWord;
  369. }
  370. else
  371. {
  372. // rc.left痢阑 扁霖栏肺 墨乔且 康开捞 吧赴 版快.
  373. if ( nLastWidth < rc.left && rc.left <= nCurrWidth )
  374. {
  375. x += (rc.left-nLastWidth);
  376. memcpy(&pwdDst[((nYCnt) * (ddsd.lPitch >> 1)) + (rc.left)], &m_pwData[x], sizeof(WORD)*(nCurrWidth-rc.left));
  377. x += (nCurrWidth-rc.left);
  378. }
  379. // rc.right痢阑 扁霖栏肺 墨乔且 康开捞 吧赴 版快.
  380. else if ( nLastWidth <= rc.right && rc.right < nCurrWidth )
  381. {
  382. memcpy(&pwdDst[((nYCnt) * (ddsd.lPitch >> 1)) + (nLastWidth)], &m_pwData[x], sizeof(WORD)*(rc.right-nLastWidth));
  383. x += nCntCopyWord;
  384. }
  385. else
  386. {
  387. memcpy(&pwdDst[((nYCnt) * (ddsd.lPitch >> 1)) + (nLastWidth)], &m_pwData[x], sizeof(WORD)*nCntCopyWord);
  388. x += nCntCopyWord;
  389. }
  390. }
  391. }
  392. }
  393. // 扼牢狼 场阑 促澜 扼牢狼 矫累栏肺 颗败霖促.
  394. nWidthEnd++;
  395. nWidthStart = nWidthEnd;
  396. nCurrWidth = 0;
  397. }
  398. m_pddsSurface->Unlock(NULL);
  399.     return S_OK;
  400. }
  401. /*
  402. HRESULT D3DTextr_CreateWILTextureFromFile(TCHAR* strWilFileName, INT nIndex, DWORD dwFlags)
  403. {
  404.     if ( NULL == strWilFileName )
  405.         return E_INVALIDARG;
  406.     if ( NULL != FindWilTexture(strWilFileName, nIndex) )
  407.         return S_OK;
  408.     WILTextureContainer* ptcWILTexture = new WILTextureContainer(strWilFileName, dwFlags);
  409.     if ( NULL == ptcWILTexture )
  410.         return E_OUTOFMEMORY;
  411.     if ( FAILED(ptcWILTexture->LoadImageData()) )
  412.     {
  413.         delete ptcWILTexture;
  414.         return E_FAIL;
  415.     }
  416. //  ptcWILTexture->m_dwWidth  = ;
  417. //  ptcWILTexture->m_dwHeight = ;
  418.     return S_OK;
  419. }
  420. */
  421. BOOL D3DWILTextr_CreateEmptyTexture(TCHAR* strWilFileName, INT nIndex, 
  422.    DWORD dwWidth, DWORD dwHeight, WORD* pwData, DWORD dwFlags)
  423. {
  424.     if ( NULL == strWilFileName )
  425.         return FALSE;
  426.     if ( NULL != FindWilTexture(strWilFileName, nIndex) )
  427.         return FALSE;
  428.     WILTextureContainer* ptcWILTexture = new WILTextureContainer(strWilFileName, nIndex, dwFlags);
  429.     if ( NULL == ptcWILTexture )
  430.         return FALSE;
  431.     ptcWILTexture->m_dwWidth  = dwWidth;
  432.     ptcWILTexture->m_dwHeight = dwHeight;
  433. ptcWILTexture->m_pwData   = pwData;
  434.     return TRUE;
  435. }
  436. HRESULT D3DWILTextr_Restore(TCHAR* strWilFileName, INT nIndex, LPDIRECT3DDEVICE7 pd3dDevice)
  437. {
  438.     WILTextureContainer* ptcWILTexture = FindWilTexture(strWilFileName, nIndex);
  439.     if ( NULL == ptcWILTexture )
  440.         return DDERR_NOTFOUND;
  441.     return ptcWILTexture->Restore(pd3dDevice);
  442. }
  443. LPDIRECTDRAWSURFACE7 D3DWILTextr_RestoreEx(TCHAR* strWilFileName, INT nIndex, LPDIRECT3DDEVICE7 pd3dDevice)
  444. {
  445.     WILTextureContainer* ptcWILTexture = FindWilTexture(strWilFileName, nIndex);
  446. if ( ptcWILTexture )
  447. {
  448. if ( ptcWILTexture->m_pddsSurface )
  449. {
  450. return ptcWILTexture->m_pddsSurface;
  451. }
  452. else
  453. {
  454. if ( (ptcWILTexture->Restore(pd3dDevice) == S_OK) )
  455. {
  456. return ptcWILTexture->m_pddsSurface;
  457. }
  458. else
  459. return NULL;
  460. }
  461. }
  462. return NULL;
  463. }
  464. HRESULT D3DWILTextr_RestoreAllTextures(LPDIRECT3DDEVICE7 pd3dDevice)
  465. {
  466.     WILTextureContainer* ptcWILTexture = g_ptcWILTextureList;
  467.     while ( ptcWILTexture && ptcWILTexture->m_pddsSurface )
  468.     {
  469.         D3DWILTextr_Restore(ptcWILTexture->m_strWilFileName, ptcWILTexture->m_nIdx, pd3dDevice);
  470.         ptcWILTexture = ptcWILTexture->m_pNext;
  471.     }
  472.     return S_OK;
  473. }
  474. HRESULT D3DWILTextr_Invalidate(TCHAR* strWilFileName, INT nIndex)
  475. {
  476.     WILTextureContainer* ptcWILTexture = FindWilTexture(strWilFileName, nIndex);
  477.     if ( NULL == ptcWILTexture )
  478.         return DDERR_NOTFOUND;
  479.     SAFE_RELEASE(ptcWILTexture->m_pddsSurface);
  480.     return S_OK;
  481. }
  482. HRESULT D3DWILTextr_InvalidateAllTextures()
  483. {
  484.     WILTextureContainer* ptcWILTexture = g_ptcWILTextureList;
  485.     while( ptcWILTexture )
  486.     {
  487.         SAFE_RELEASE(ptcWILTexture->m_pddsSurface);
  488.         ptcWILTexture = ptcWILTexture->m_pNext;
  489.     }
  490.     return S_OK;
  491. }
  492. HRESULT D3DWILTextr_DestroyAllTextures()
  493. {
  494.     WILTextureContainer* ptcWILTexture = g_ptcWILTextureList;
  495. WILTextureContainer* ptcWILMextTexture = NULL;
  496.     while( ptcWILTexture )
  497.     {
  498.         ptcWILMextTexture = ptcWILTexture->m_pNext;
  499. SAFE_DELETE(ptcWILTexture);
  500. ptcWILTexture = ptcWILMextTexture;
  501.     }
  502.     return S_OK;
  503. }
  504. HRESULT D3DWILTextr_DestroyTexture(TCHAR* strWilFileName, INT nIndex)
  505. {
  506.     WILTextureContainer* ptcWILTexture = FindWilTexture(strWilFileName, nIndex);
  507.     SAFE_DELETE(ptcWILTexture);
  508.     return S_OK;
  509. }
  510. LPDIRECTDRAWSURFACE7 D3DWILTextr_GetSurface(TCHAR* strWilFileName, INT nIndex)
  511. {
  512.     WILTextureContainer* ptcWILTexture = FindWilTexture(strWilFileName, nIndex);
  513.     return ptcWILTexture ? ptcWILTexture->m_pddsSurface : NULL;
  514. }
  515. /*
  516. POINT D3DWILTextr_GetImageSize(TCHAR* strWilFileName, INT nIndex)
  517. {
  518. POINT ptSize = {0 , 0};
  519.     WILTextureContainer* ptcWILTexture = FindWilTexture(strWilFileName, nIndex);
  520. if ( ptcWILTexture )
  521. {
  522. ptSize.x = ptcWILTexture->m_dwWidth; 
  523. ptSize.y = ptcWILTexture->m_dwHeight;
  524. }
  525.     return ptSize;
  526. }
  527. */
  528. INT GetRandomNum(INT nFrom, INT nTo)
  529. {
  530. INT nRandNum = 0;
  531. INT nRand = ((INT)rand()-(INT)rand());
  532. if ( nRand < 0 )
  533. nRand = -nRand;
  534. nRandNum = nRand % (nTo-nFrom+1) + nFrom;
  535. return nRandNum;
  536. }