Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

TPage.h File Reference

#include <Windows.h>
#include <DDraw.h>
#include <D3D.H>

Go to the source code of this file.

Typedefs

typedef TPage_Mgr TPage_Mgr
typedef TPage TPage
typedef TPage_Block TPage_Block

Functions

TPage_MgrTPage_MgrCreate (LPDIRECTDRAW4 lpDD, const DDSURFACEDESC2 *SurfaceDesc, int32 NumPages)
void TPage_MgrDestroy (TPage_Mgr **TPageMgr)
geBoolean TPage_MgrHasTPage (TPage_Mgr *Mgr, TPage *Page)
geBoolean TPage_MgrAttachTPage (TPage_Mgr *Mgr, TPage *TPage)
void TPage_MgrDetachTPage (TPage_Mgr *Mgr, TPage *TPage)
TPage_BlockTPage_MgrFindOptimalBlock (TPage_Mgr *Mgr, uint32 LRU)
TPageTPage_Create (LPDIRECTDRAW4 lpDD, const DDSURFACEDESC2 *SurfDesc)
void TPage_CreateRef (TPage *Page)
void TPage_Destroy (TPage **Page1)
geBoolean TPage_HasBlock (TPage *TPage, TPage_Block *Block)
geBoolean TPage_AttachBlock (TPage *Page, TPage_Block *Block)
void TPage_DetachBlock (TPage *TPage, TPage_Block *Block)
geBoolean TPage_CreateSurfaces (TPage *Page, LPDIRECTDRAW4 lpDD, const DDSURFACEDESC2 *SurfDesc)
void TPage_DestroySurfaces (TPage *Page)
TPage_BlockTPage_BlockCreate (LPDIRECTDRAWSURFACE4 Surface, LPDIRECT3DTEXTURE2 Texture, const RECT *Rect)
geBoolean TPage_BlockCreateRef (TPage_Block *Block)
void TPage_BlockDestroy (TPage_Block **Block)
LPDIRECT3DTEXTURE2 TPage_BlockGetTexture (TPage_Block *Block)
LPDIRECTDRAWSURFACE4 TPage_BlockGetSurface (TPage_Block *Block)
const RECTTPage_BlockGetRect (TPage_Block *Block)
void TPage_BlockSetLRU (TPage_Block *Block, uint32 LRU)
void TPage_BlockSetUserData (TPage_Block *Block, void *UserData)
void * TPage_BlockGetUserData (TPage_Block *Block)


Typedef Documentation

typedef struct TPage TPage
 

Definition at line 31 of file WireFrame/TPage.h.

typedef struct TPage_Block TPage_Block
 

Definition at line 32 of file WireFrame/TPage.h.

typedef struct TPage_Mgr TPage_Mgr
 

Definition at line 30 of file WireFrame/TPage.h.


Function Documentation

geBoolean TPage_AttachBlock TPage Page,
TPage_Block Block
 

Definition at line 465 of file D3D7xDrv/tpage.cpp.

References TPage::Blocks, GE_FALSE, GE_TRUE, geBoolean, TPage_Block::Next, NULL, TPage_Block::Prev, and TPage_HasBlock().

Referenced by TPage_Create().

00466 {
00467         assert(TPage_HasBlock(Page, Block) == GE_FALSE);
00468         assert(Block->Prev == NULL);
00469         assert(Block->Next == NULL);
00470 
00471         // Insert the block into the list of blocks for this Page
00472         if (Page->Blocks)
00473                 Page->Blocks->Prev = Block;
00474 
00475         Block->Prev = NULL;
00476         Block->Next = Page->Blocks;
00477 
00478         Page->Blocks = Block;
00479 
00480         return GE_TRUE;
00481 }

TPage_Block* TPage_BlockCreate LPDIRECTDRAWSURFACE4  Surface,
LPDIRECT3DTEXTURE2  Texture,
const RECT Rect
 

Definition at line 470 of file D3D8Drv/tpage.cpp.

References NULL, TPage_Block::Rect, TPage_Block::Surface, TPage_Block::Texture, TPage_Block, and TPage_BlockCreateRef().

Referenced by TPage_Create().

00471 {
00472         TPage_Block     *Block;
00473 
00474         Block = (TPage_Block*)malloc(sizeof(TPage_Block));
00475 
00476         if (!Block)
00477                 return NULL;
00478 
00479         memset(Block, 0, sizeof(TPage_Block));
00480 
00481         Surface->AddRef();              // Ref the surface
00482         Texture->AddRef();              // Ditto...
00483 
00484         // Save off the surface, texture, and rect into the surface
00485         Block->Surface = Surface;
00486         Block->Texture = Texture;
00487         Block->Rect = *Rect;
00488 
00489         TPage_BlockCreateRef(Block);            // Create very first ref
00490 
00491         return Block;
00492 }

geBoolean TPage_BlockCreateRef TPage_Block Block  ) 
 

Definition at line 626 of file D3D7xDrv/tpage.cpp.

References GE_TRUE, geBoolean, and TPage_Block::RefCount.

Referenced by TPage_BlockCreate().

00627 {
00628         assert(Block);
00629 
00630         Block->RefCount++;
00631 
00632         return GE_TRUE;
00633 }

void TPage_BlockDestroy TPage_Block **  Block  ) 
 

Definition at line 638 of file D3D7xDrv/tpage.cpp.

References NULL, TPage_Block::RefCount, TPage_Block::Surface, TPage_Block::Texture, and TPage_Block.

Referenced by TPage_Destroy().

00639 {
00640         TPage_Block     *Block2;
00641 
00642         assert(Block);
00643         
00644         Block2 = *Block;
00645 
00646         assert(Block2);
00647         assert(Block2->RefCount > 0);
00648 
00649         Block2->RefCount--;
00650 
00651         if (Block2->RefCount > 0)
00652                 return;
00653 
00654         // Destroy references to the surface and texture
00655         if (Block2->Surface)
00656                 Block2->Surface->Release();
00657 
00658 /*   02/25/2001 Wendell Buckner
00659 /*    This texture pointer is no longer valid under directx 7.  Set it to TRUE so there is
00660 /*    something there when  the code does assert checks.        
00661         if (Block2->Texture)
00662                 Block2->Texture->Release();*/
00663 
00664         
00665         // Free the block
00666         free(Block2);
00667 
00668         *Block = NULL;
00669 }

const RECT* TPage_BlockGetRect TPage_Block Block  ) 
 

Definition at line 704 of file D3D7xDrv/tpage.cpp.

References TPage_Block::Rect.

00705 {
00706         assert(Block);
00707 
00708         return &Block->Rect;
00709 }

LPDIRECTDRAWSURFACE4 TPage_BlockGetSurface TPage_Block Block  ) 
 

Definition at line 693 of file D3D7xDrv/tpage.cpp.

References TPage_Block::Surface.

00695 {
00696         assert(Block);
00697 
00698         return Block->Surface;
00699 }

LPDIRECT3DTEXTURE2 TPage_BlockGetTexture TPage_Block Block  ) 
 

Definition at line 678 of file D3D7xDrv/tpage.cpp.

References TPage_Block::Texture.

Referenced by SetupLMap().

00680 {
00681         assert(Block);
00682 
00683         return Block->Texture;
00684 }

void* TPage_BlockGetUserData TPage_Block Block  ) 
 

Definition at line 734 of file D3D7xDrv/tpage.cpp.

References TPage_Block::UserData.

Referenced by SetupLMap().

00735 {
00736         assert(Block);
00737 
00738         return Block->UserData;
00739 }

void TPage_BlockSetLRU TPage_Block Block,
uint32  LRU
 

Definition at line 714 of file D3D7xDrv/tpage.cpp.

References TPage_Block::LRU.

Referenced by SetupLMap().

00715 {
00716         assert(Block);
00717 
00718         Block->LRU = LRU;
00719 }

void TPage_BlockSetUserData TPage_Block Block,
void *  UserData
 

Definition at line 724 of file D3D7xDrv/tpage.cpp.

References TPage_Block::UserData.

Referenced by SetupLMap().

00725 {
00726         assert(Block);
00727 
00728         Block->UserData = UserData;
00729 }

TPage* TPage_Create LPDIRECTDRAW4  lpDD,
const DDSURFACEDESC2 *  SurfDesc
 

Definition at line 254 of file D3D8Drv/tpage.cpp.

References tagRECT::bottom, int32, tagRECT::left, lpDD, NULL, tagRECT::right, TPage::Surface, TPage::SurfaceDesc, TPage::Texture, tagRECT::top, TPage, TPage_AttachBlock(), TPage_Block, TPage_BlockCreate(), TPage_CreateRef(), TPage_CreateSurfaces(), TPage_Destroy(), TPAGE_GRID_X, TPAGE_GRID_Y, TPAGE_HEIGHT, and TPAGE_WIDTH.

Referenced by TPage_MgrCreate().

00255 {
00256         TPage   *Page;
00257         int32   w, h;
00258 
00259         Page = (TPage*)malloc(sizeof(TPage));
00260 
00261         if (!Page)
00262                 return NULL;
00263 
00264         memset(Page, 0, sizeof(TPage));
00265 
00266         Page->SurfaceDesc = *SurfDesc;
00267 
00268         TPage_CreateRef(Page);          // Create the very first ref
00269 
00270         if (!TPage_CreateSurfaces(Page, lpDD, SurfDesc))
00271         {
00272                 free(Page);
00273                 return NULL;
00274         }
00275 
00276         // Create the blocks
00277         for (h=0; h<TPAGE_HEIGHT/16; h++)
00278         {
00279                 for (w=0; w<TPAGE_WIDTH/16; w++)
00280                 {
00281                         TPage_Block             *Block;
00282                         RECT                    Rect;
00283 
00284                         Rect.left = w*TPAGE_GRID_X;
00285                         Rect.right = Rect.left+(TPAGE_GRID_X-1);
00286                         Rect.top = h*TPAGE_GRID_Y;
00287                         Rect.bottom = Rect.top+(TPAGE_GRID_Y-1);
00288 
00289                         Block = TPage_BlockCreate(Page->Surface, Page->Texture, &Rect);
00290 
00291                         if (!Block)
00292                                 goto ExitWithError;
00293 
00294                         if (!TPage_AttachBlock(Page, Block))
00295                                 goto ExitWithError;
00296                 }
00297         }
00298 
00299         return Page;
00300 
00301         ExitWithError:
00302         {
00303                 if (Page)
00304                         TPage_Destroy(&Page);
00305 
00306                 return NULL;
00307         }
00308 }

void TPage_CreateRef TPage Page  ) 
 

Definition at line 395 of file D3D7xDrv/tpage.cpp.

References TPage::RefCount.

Referenced by TPage_Create().

00396 {
00397         assert(Page->RefCount >= 0);            // Refs can == 0, because thats what they are when TPages are first created
00398 
00399         Page->RefCount++;
00400 }

geBoolean TPage_CreateSurfaces TPage Page,
LPDIRECTDRAW4  lpDD,
const DDSURFACEDESC2 *  SurfDesc
 

Definition at line 410 of file D3D8Drv/tpage.cpp.

References GE_FALSE, GE_TRUE, geBoolean, lpDD, NULL, TPage::Surface, TPage::Texture, TPAGE_HEIGHT, and TPAGE_WIDTH.

Referenced by TPage_Create().

00411 {
00412         HRESULT                                 Hr;
00413         DDSURFACEDESC2                  ddsd;
00414 
00415         memcpy(&ddsd, SurfDesc, sizeof(DDSURFACEDESC2));
00416 
00417         ddsd.dwSize = sizeof(DDSURFACEDESC2);
00418         ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
00419         ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
00420         ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC;
00421         ddsd.ddsCaps.dwCaps3 = 0;
00422         ddsd.ddsCaps.dwCaps4 = 0;
00423         ddsd.dwWidth = TPAGE_WIDTH;
00424         ddsd.dwHeight = TPAGE_HEIGHT;
00425 
00426         Hr = lpDD->CreateSurface(&ddsd, &Page->Surface, NULL);
00427 
00428         if (Hr != DD_OK) 
00429                 return GE_FALSE;
00430 
00431         Hr = Page->Surface->QueryInterface(IID_IDirect3DTexture2, (void**)&Page->Texture);  
00432 
00433         if(Hr != DD_OK) 
00434         { 
00435                 Page->Surface->Release();
00436                 Page->Surface = NULL;
00437                 Page->Texture = NULL;
00438                 return GE_FALSE;
00439         }
00440         
00441         return GE_TRUE;         // All good dude
00442 }

void TPage_Destroy TPage **  Page1  ) 
 

Definition at line 405 of file D3D7xDrv/tpage.cpp.

References TPage::Blocks, TPage_Block::Next, NULL, TPage::RefCount, TPage, TPage_Block, TPage_BlockDestroy(), TPage_DestroySurfaces(), and TPage_DetachBlock().

Referenced by TPage_Create(), and TPage_MgrDestroy().

00406 {
00407         TPage           *Page;
00408         TPage_Block     *Block, *Next;
00409 
00410         assert(Page1);
00411         Page = *Page1;
00412 
00413         assert(Page);
00414         assert(Page->RefCount > 0);
00415 
00416         Page->RefCount--;
00417 
00418         if (Page->RefCount > 0)
00419                 return;
00420 
00421         // Destroy any dd surfaces for this page
00422         TPage_DestroySurfaces(Page);
00423 
00424         // Destroy all the blocks this page has
00425         for (Block = Page->Blocks; Block; Block = Next)
00426         {
00427                 Next = Block->Next;
00428 
00429                 TPage_DetachBlock(Page, Block);
00430                 TPage_BlockDestroy(&Block);
00431         }
00432 
00433         assert(Page->Blocks == NULL);
00434 
00435         free(*Page1);
00436 
00437         *Page1 = NULL;
00438 }

void TPage_DestroySurfaces TPage Page  ) 
 

Definition at line 563 of file D3D7xDrv/tpage.cpp.

References NULL, TPage::Surface, and TPage::Texture.

Referenced by TPage_Destroy().

00564 {
00565         assert(Page);
00566 
00567         if (Page->Texture)
00568         {
00569 /*   02/25/2001 Wendell Buckner
00570 /*    This texture pointer is no longer valid under directx 7.  Set it to TRUE so there is
00571 /*    something there when  the code does assert checks.        
00572                 Page->Texture->Release();*/
00573                 Page->Texture = NULL;
00574         }
00575 
00576         if (Page->Surface)
00577         {
00578                 Page->Surface->Release();
00579                 Page->Surface = NULL;
00580         }
00581 }

void TPage_DetachBlock TPage TPage,
TPage_Block Block
 

Definition at line 486 of file D3D7xDrv/tpage.cpp.

References TPage::Blocks, GE_TRUE, TPage_Block::Next, NULL, TPage_Block::Prev, TPage, and TPage_HasBlock().

Referenced by TPage_Destroy().

00487 {
00488         assert(TPage);
00489         assert(Block);
00490         assert(TPage_HasBlock(TPage, Block) == GE_TRUE);
00491 
00492         if (Block->Next)
00493                 Block->Next->Prev = Block->Prev;
00494 
00495         if (Block->Prev)
00496                 Block->Prev->Next = Block->Prev;
00497         else
00498         {
00499                 // If we get here, this better be the first Block in the list!
00500                 assert(TPage->Blocks == Block);
00501                 TPage->Blocks = Block->Next;
00502         }
00503 
00504         // Reset the Block link
00505         Block->Next = NULL;
00506         Block->Prev = NULL;
00507 }

geBoolean TPage_HasBlock TPage TPage,
TPage_Block Block
 

Definition at line 443 of file D3D7xDrv/tpage.cpp.

References TPage::Blocks, GE_FALSE, GE_TRUE, geBoolean, TPage_Block::Next, TPage, and TPage_Block.

Referenced by TPage_AttachBlock(), and TPage_DetachBlock().

00444 {
00445         TPage_Block             *Block2;
00446 
00447         assert(TPage);
00448         assert(Block);
00449 
00450         for (Block2 = TPage->Blocks; Block2; Block2 = Block2->Next)
00451         {
00452                 if (Block2 == Block)
00453                 {
00454                         return GE_TRUE;
00455                 }
00456         }
00457 
00458         return GE_FALSE;
00459 }

geBoolean TPage_MgrAttachTPage TPage_Mgr Mgr,
TPage TPage
 

Definition at line 212 of file D3D7xDrv/tpage.cpp.

References GE_FALSE, GE_TRUE, geBoolean, TPage::Next, NULL, TPage::Prev, TPage, TPage_MgrHasTPage(), and TPage_Mgr::TPages.

Referenced by TPage_MgrCreate().

00213 {
00214         assert(TPage_MgrHasTPage(Mgr, TPage) == GE_FALSE);
00215         assert(TPage->Prev == NULL);
00216         assert(TPage->Next == NULL);
00217 
00218         if (Mgr->TPages)
00219                 Mgr->TPages->Prev = TPage;
00220 
00221         TPage->Prev = NULL;
00222         TPage->Next = Mgr->TPages;
00223         Mgr->TPages = TPage;
00224 
00225         return GE_TRUE;
00226 }

TPage_Mgr* TPage_MgrCreate LPDIRECTDRAW4  lpDD,
const DDSURFACEDESC2 *  SurfaceDesc,
int32  NumPages
 

Definition at line 93 of file D3D8Drv/tpage.cpp.

References int32, lpDD, TPage_Mgr::lpDD, NULL, TPage_Mgr::NumPages, TPage, TPage_Create(), TPage_MgrAttachTPage(), TPage_MgrDestroy(), and TPageMgr.

Referenced by THandle_Startup().

00094 {
00095         TPage_Mgr       *TPageMgr;
00096         int32           i;
00097 
00098         TPageMgr = (TPage_Mgr*)malloc(sizeof(TPage_Mgr));
00099 
00100         if (!TPageMgr)
00101                 return NULL;
00102 
00103         memset(TPageMgr, 0, sizeof(TPage_Mgr));
00104 
00105         // Remeber the DD object
00106         TPageMgr->lpDD = lpDD;
00107         // Ref the dd object
00108         lpDD->AddRef();                 
00109 
00110         TPageMgr->NumPages = NumPages;
00111 
00112         // Create the pages
00113         for (i=0; i<NumPages; i++)
00114         {
00115                 TPage   *Page;
00116 
00117                 Page = TPage_Create(lpDD, SurfaceDesc);
00118 
00119                 if (!Page)
00120                         goto ExitWithError;
00121 
00122                 if (!TPage_MgrAttachTPage(TPageMgr, Page))
00123                         goto ExitWithError;
00124         }
00125 
00126         return TPageMgr;
00127 
00128         ExitWithError:
00129         {
00130                 if (TPageMgr)
00131                         TPage_MgrDestroy(&TPageMgr);
00132                 return NULL;
00133         }
00134 }

void TPage_MgrDestroy TPage_Mgr **  TPageMgr  ) 
 

Definition at line 157 of file D3D7xDrv/tpage.cpp.

References TPage_Mgr::lpDD, TPage::Next, NULL, TPage, TPage_Destroy(), TPage_MgrDetachTPage(), TPageMgr, and TPage_Mgr::TPages.

Referenced by FreeAllCaches(), and TPage_MgrCreate().

00158 {
00159         TPage_Mgr       *Mgr;
00160         TPage           *Page, *Next;
00161 
00162         assert(TPageMgr);
00163 
00164         Mgr = *TPageMgr;
00165 
00166         assert(Mgr);
00167         
00168         // Free the pages
00169         for (Page = Mgr->TPages; Page; Page = Next)
00170         {
00171                 Next = Page->Next;
00172 
00173                 TPage_MgrDetachTPage(Mgr, Page);
00174                 TPage_Destroy(&Page);
00175         }
00176 
00177         assert(Mgr->TPages == NULL);
00178 
00179         // Release our ref on the DD object
00180         Mgr->lpDD->Release();                   
00181 
00182         free(*TPageMgr);
00183 
00184         *TPageMgr = NULL;
00185 }

void TPage_MgrDetachTPage TPage_Mgr Mgr,
TPage TPage
 

Definition at line 231 of file D3D7xDrv/tpage.cpp.

References GE_TRUE, TPage::Next, NULL, TPage::Prev, TPage, TPage_MgrHasTPage(), and TPage_Mgr::TPages.

Referenced by TPage_MgrDestroy().

00232 {
00233         assert(Mgr);
00234         assert(TPage);
00235         assert(TPage_MgrHasTPage(Mgr, TPage) == GE_TRUE);
00236 
00237         if (TPage->Next)
00238                 TPage->Next->Prev = TPage->Prev;
00239 
00240         if (TPage->Prev)
00241                 TPage->Prev->Next = TPage->Prev;
00242         else
00243         {
00244                 // If we get here, this better be the first TPage in the list!
00245                 assert(Mgr->TPages == TPage);
00246                 Mgr->TPages = TPage->Next;
00247         }
00248 
00249         TPage->Next = NULL;
00250         TPage->Prev = NULL;
00251 }

TPage_Block* TPage_MgrFindOptimalBlock TPage_Mgr Mgr,
uint32  LRU
 

Definition at line 256 of file D3D7xDrv/tpage.cpp.

References TPage::Blocks, TPage_Block::LRU, TPage::LRU, TPage_Block::Next, TPage::Next, NULL, TPage, TPage_Block, TPage_Mgr::TPages, and uint32.

Referenced by SetupLMap().

00257 {
00258 #if 0
00259         TPage           *Page, *BestPage;
00260         TPage_Block     *Block, *BestBlock;
00261         uint32          BestLRU;
00262 
00263         // We really should make a TPage_GetOptimalBlock...
00264 
00265         // First, find the page that has the highest LRU
00266         BestLRU = 0;
00267         BestPage = Mgr->TPages;
00268 
00269         for (Page = Mgr->TPages; Page; Page = Page->Next)
00270         {
00271                 if (Page->LRU > BestLRU && Page->NumFull)
00272                 {
00273                         BestPage = Page;
00274                         BestLRU = Page->LRU;
00275                 }
00276         }
00277 
00278         // Now, find the block with the lowest LRU in this page
00279         BestBlock = BestPage->Blocks;
00280         BestLRU = 0xffffffff;
00281 
00282         for (Block = BestPage->Blocks; Block; Block = Block->Next)
00283         {
00284                 if (Block->LRU < BestLRU)
00285                 {
00286                         BestBlock = Block;
00287                         BestLRU = Block->LRU;
00288                 }
00289         }
00290         /*
00291         if (BestBlock->LRU == LRU)
00292                 BestPage->NumFull++;
00293         else
00294         */
00295                 BestBlock->LRU = LRU;
00296         BestPage->LRU = LRU;
00297 #else
00298         TPage           *Page;
00299         TPage_Block     *Block, *BestBlock;
00300         uint32          BestLRU;
00301 
00302         // We really should make a TPage_GetOptimalBlock...
00303         BestBlock = NULL;
00304         BestLRU = 0xffffffff;
00305 
00306         for (Page = Mgr->TPages; Page; Page = Page->Next)
00307         {
00308                 for (Block = Page->Blocks; Block; Block = Block->Next)
00309                 {
00310                         if (Block->LRU < BestLRU)
00311                         {
00312                                 BestBlock = Block;
00313                                 BestLRU = Block->LRU;
00314                         }
00315                 }
00316         }
00317 
00318         BestBlock->LRU = LRU;
00319 #endif
00320 
00321         return BestBlock;
00322 }

geBoolean TPage_MgrHasTPage TPage_Mgr Mgr,
TPage Page
 

Definition at line 190 of file D3D7xDrv/tpage.cpp.

References GE_FALSE, GE_TRUE, geBoolean, TPage::Next, TPage, and TPage_Mgr::TPages.

Referenced by TPage_MgrAttachTPage(), and TPage_MgrDetachTPage().

00191 {
00192         TPage   *Page2;
00193 
00194         assert(Mgr);
00195         assert(Page);
00196 
00197         for (Page2 = Mgr->TPages; Page2; Page2 = Page2->Next)
00198         {
00199                 if (Page2 == Page)
00200                 {
00201                         return GE_TRUE;
00202                 }
00203         }
00204         
00205         return GE_FALSE;
00206 }


Generated on Tue Sep 30 12:38:17 2003 for GTestAndEngine by doxygen 1.3.2