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

tpage.cpp File Reference

#include <Windows.h>
#include <Assert.h>
#include <Stdio.h>
#include "BaseType.h"
#include "TPage.h"

Go to the source code of this file.

Compounds

struct  TPage
struct  TPage_Block
struct  TPage_Mgr

Defines

#define TPAGE_WIDTH   16
#define TPAGE_HEIGHT   16
#define TPAGE_GRID_X   16
#define TPAGE_GRID_Y   16

Typedefs

typedef TPage_Block TPage_Block
typedef TPage TPage
typedef TPage_Mgr TPage_Mgr

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)


Define Documentation

#define TPAGE_GRID_X   16
 

Definition at line 33 of file WireFrame/tpage.cpp.

#define TPAGE_GRID_Y   16
 

Definition at line 34 of file WireFrame/tpage.cpp.

#define TPAGE_HEIGHT   16
 

Definition at line 31 of file WireFrame/tpage.cpp.

#define TPAGE_WIDTH   16
 

Definition at line 30 of file WireFrame/tpage.cpp.


Typedef Documentation

typedef struct TPage TPage
 

typedef struct TPage_Block TPage_Block
 

typedef struct TPage_Mgr TPage_Mgr
 


Function Documentation

geBoolean TPage_AttachBlock TPage Page,
TPage_Block Block
 

Definition at line 437 of file WireFrame/tpage.cpp.

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

Referenced by TPage_Create().

00438 {
00439         assert(TPage_HasBlock(Page, Block) == GE_FALSE);
00440         assert(Block->Prev == NULL);
00441         assert(Block->Next == NULL);
00442 
00443         // Insert the block into the list of blocks for this Page
00444         if (Page->Blocks)
00445                 Page->Blocks->Prev = Block;
00446 
00447         Block->Prev = NULL;
00448         Block->Next = Page->Blocks;
00449 
00450         Page->Blocks = Block;
00451 
00452         return GE_TRUE;
00453 }

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

Definition at line 551 of file WireFrame/tpage.cpp.

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

Referenced by TPage_Create().

00552 {
00553         TPage_Block     *Block;
00554 
00555         Block = (TPage_Block*)malloc(sizeof(TPage_Block));
00556 
00557         if (!Block)
00558                 return NULL;
00559 
00560         memset(Block, 0, sizeof(TPage_Block));
00561 
00562         Surface->AddRef();              // Ref the surface
00563         Texture->AddRef();              // Ditto...
00564 
00565         // Save off the surface, texture, and rect into the surface
00566         Block->Surface = Surface;
00567         Block->Texture = Texture;
00568         Block->Rect = *Rect;
00569 
00570         TPage_BlockCreateRef(Block);            // Create very first ref
00571 
00572         return Block;
00573 }

geBoolean TPage_BlockCreateRef TPage_Block Block  ) 
 

Definition at line 578 of file WireFrame/tpage.cpp.

References GE_TRUE, geBoolean, and TPage_Block::RefCount.

Referenced by TPage_BlockCreate().

00579 {
00580         assert(Block);
00581 
00582         Block->RefCount++;
00583 
00584         return GE_TRUE;
00585 }

void TPage_BlockDestroy TPage_Block **  Block  ) 
 

Definition at line 590 of file WireFrame/tpage.cpp.

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

Referenced by TPage_Destroy().

00591 {
00592         TPage_Block     *Block2;
00593 
00594         assert(Block);
00595         
00596         Block2 = *Block;
00597 
00598         assert(Block2);
00599         assert(Block2->RefCount > 0);
00600 
00601         Block2->RefCount--;
00602 
00603         if (Block2->RefCount > 0)
00604                 return;
00605 
00606         // Destroy references to the surface and texture
00607         if (Block2->Surface)
00608                 Block2->Surface->Release();
00609 
00610         if (Block2->Texture)
00611                 Block2->Texture->Release();
00612         
00613         // Free the block
00614         free(Block2);
00615 
00616         *Block = NULL;
00617 }

const RECT* TPage_BlockGetRect TPage_Block Block  ) 
 

Definition at line 642 of file WireFrame/tpage.cpp.

References TPage_Block::Rect.

00643 {
00644         assert(Block);
00645 
00646         return &Block->Rect;
00647 }

LPDIRECTDRAWSURFACE4 TPage_BlockGetSurface TPage_Block Block  ) 
 

Definition at line 632 of file WireFrame/tpage.cpp.

References TPage_Block::Surface.

00633 {
00634         assert(Block);
00635 
00636         return Block->Surface;
00637 }

LPDIRECT3DTEXTURE2 TPage_BlockGetTexture TPage_Block Block  ) 
 

Definition at line 622 of file WireFrame/tpage.cpp.

References TPage_Block::Texture.

Referenced by SetupLMap().

00623 {
00624         assert(Block);
00625 
00626         return Block->Texture;
00627 }

void* TPage_BlockGetUserData TPage_Block Block  ) 
 

Definition at line 672 of file WireFrame/tpage.cpp.

References TPage_Block::UserData.

Referenced by SetupLMap().

00673 {
00674         assert(Block);
00675 
00676         return Block->UserData;
00677 }

void TPage_BlockSetLRU TPage_Block Block,
uint32  LRU
 

Definition at line 652 of file WireFrame/tpage.cpp.

References TPage_Block::LRU.

Referenced by SetupLMap().

00653 {
00654         assert(Block);
00655 
00656         Block->LRU = LRU;
00657 }

void TPage_BlockSetUserData TPage_Block Block,
void *  UserData
 

Definition at line 662 of file WireFrame/tpage.cpp.

References TPage_Block::UserData.

Referenced by SetupLMap().

00663 {
00664         assert(Block);
00665 
00666         Block->UserData = UserData;
00667 }

TPage* TPage_Create LPDIRECTDRAW4  lpDD,
const DDSURFACEDESC2 *  SurfDesc
 

Definition at line 308 of file WireFrame/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().

00309 {
00310         TPage   *Page;
00311         int32   w, h;
00312 
00313         Page = (TPage*)malloc(sizeof(TPage));
00314 
00315         if (!Page)
00316                 return NULL;
00317 
00318         memset(Page, 0, sizeof(TPage));
00319 
00320         Page->SurfaceDesc = *SurfDesc;
00321 
00322         TPage_CreateRef(Page);          // Create the very first ref
00323 
00324         if (!TPage_CreateSurfaces(Page, lpDD, SurfDesc))
00325         {
00326                 free(Page);
00327                 return NULL;
00328         }
00329 
00330         // Create the blocks
00331         for (h=0; h<TPAGE_HEIGHT/16; h++)
00332         {
00333                 for (w=0; w<TPAGE_WIDTH/16; w++)
00334                 {
00335                         TPage_Block             *Block;
00336                         RECT                    Rect;
00337 
00338                         Rect.left = w*TPAGE_GRID_X;
00339                         Rect.right = Rect.left+(TPAGE_GRID_X-1);
00340                         Rect.top = h*TPAGE_GRID_Y;
00341                         Rect.bottom = Rect.top+(TPAGE_GRID_Y-1);
00342 
00343                         Block = TPage_BlockCreate(Page->Surface, Page->Texture, &Rect);
00344 
00345                         if (!Block)
00346                                 goto ExitWithError;
00347 
00348                         if (!TPage_AttachBlock(Page, Block))
00349                                 goto ExitWithError;
00350                 }
00351         }
00352 
00353         return Page;
00354 
00355         ExitWithError:
00356         {
00357                 if (Page)
00358                         TPage_Destroy(&Page);
00359 
00360                 return NULL;
00361         }
00362 }

void TPage_CreateRef TPage Page  ) 
 

Definition at line 367 of file WireFrame/tpage.cpp.

References TPage::RefCount.

Referenced by TPage_Create().

00368 {
00369         assert(Page->RefCount >= 0);            // Refs can == 0, because thats what they are when TPages are first created
00370 
00371         Page->RefCount++;
00372 }

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

Definition at line 484 of file WireFrame/tpage.cpp.

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

Referenced by TPage_Create().

00485 {
00486         HRESULT                                 Hr;
00487         DDSURFACEDESC2                  ddsd;
00488 
00489         assert(Page);
00490 
00491         memcpy(&ddsd, SurfDesc, sizeof(DDSURFACEDESC2));
00492 
00493         ddsd.dwSize = sizeof(DDSURFACEDESC2);
00494         ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
00495 
00496         ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
00497         ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC;
00498 
00499         ddsd.ddsCaps.dwCaps3 = 0;
00500         ddsd.ddsCaps.dwCaps4 = 0;
00501 
00502         ddsd.dwWidth = TPAGE_WIDTH;
00503         ddsd.dwHeight = TPAGE_HEIGHT;
00504 
00505         Hr = lpDD->CreateSurface(&ddsd, &Page->Surface, NULL);
00506 
00507         if (Hr != DD_OK) 
00508                 return GE_FALSE;
00509 
00510         Hr = Page->Surface->QueryInterface(IID_IDirect3DTexture2, (void**)&Page->Texture);  
00511 
00512         if(Hr != DD_OK) 
00513         { 
00514                 Page->Surface->Release();
00515                 Page->Surface = NULL;
00516                 Page->Texture = NULL;
00517                 return GE_FALSE;
00518         }
00519         
00520         return GE_TRUE;         // All good dude
00521 }

void TPage_Destroy TPage **  Page1  ) 
 

Definition at line 377 of file WireFrame/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().

00378 {
00379         TPage           *Page;
00380         TPage_Block     *Block, *Next;
00381 
00382         assert(Page1);
00383         Page = *Page1;
00384 
00385         assert(Page);
00386         assert(Page->RefCount > 0);
00387 
00388         Page->RefCount--;
00389 
00390         if (Page->RefCount > 0)
00391                 return;
00392 
00393         // Destroy any dd surfaces for this page
00394         TPage_DestroySurfaces(Page);
00395 
00396         // Destroy all the blocks this page has
00397         for (Block = Page->Blocks; Block; Block = Next)
00398         {
00399                 Next = Block->Next;
00400 
00401                 TPage_DetachBlock(Page, Block);
00402                 TPage_BlockDestroy(&Block);
00403         }
00404 
00405         assert(Page->Blocks == NULL);
00406 
00407         free(*Page1);
00408 
00409         *Page1 = NULL;
00410 }

void TPage_DestroySurfaces TPage Page  ) 
 

Definition at line 527 of file WireFrame/tpage.cpp.

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

Referenced by TPage_Destroy().

00528 {
00529         assert(Page);
00530 
00531         if (Page->Texture)
00532         {
00533                 Page->Texture->Release();
00534                 Page->Texture = NULL;
00535         }
00536 
00537         if (Page->Surface)
00538         {
00539                 Page->Surface->Release();
00540                 Page->Surface = NULL;
00541         }
00542 }

void TPage_DetachBlock TPage TPage,
TPage_Block Block
 

Definition at line 458 of file WireFrame/tpage.cpp.

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

Referenced by TPage_Destroy().

00459 {
00460         assert(TPage);
00461         assert(Block);
00462         assert(TPage_HasBlock(TPage, Block) == GE_TRUE);
00463 
00464         if (Block->Next)
00465                 Block->Next->Prev = Block->Prev;
00466 
00467         if (Block->Prev)
00468                 Block->Prev->Next = Block->Prev;
00469         else
00470         {
00471                 // If we get here, this better be the first Block in the list!
00472                 assert(TPage->Blocks == Block);
00473                 TPage->Blocks = Block->Next;
00474         }
00475 
00476         // Reset the Block link
00477         Block->Next = NULL;
00478         Block->Prev = NULL;
00479 }

geBoolean TPage_HasBlock TPage TPage,
TPage_Block Block
 

Definition at line 415 of file WireFrame/tpage.cpp.

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

Referenced by TPage_AttachBlock(), and TPage_DetachBlock().

00416 {
00417         TPage_Block             *Block2;
00418 
00419         assert(TPage);
00420         assert(Block);
00421 
00422         for (Block2 = TPage->Blocks; Block2; Block2 = Block2->Next)
00423         {
00424                 if (Block2 == Block)
00425                 {
00426                         return GE_TRUE;
00427                 }
00428         }
00429 
00430         return GE_FALSE;
00431 }

geBoolean TPage_MgrAttachTPage TPage_Mgr Mgr,
TPage TPage
 

Definition at line 189 of file WireFrame/tpage.cpp.

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

Referenced by TPage_MgrCreate().

00190 {
00191         assert(TPage_MgrHasTPage(Mgr, TPage) == GE_FALSE);
00192         assert(TPage->Prev == NULL);
00193         assert(TPage->Next == NULL);
00194 
00195         if (Mgr->TPages)
00196                 Mgr->TPages->Prev = TPage;
00197 
00198         TPage->Prev = NULL;
00199         TPage->Next = Mgr->TPages;
00200         Mgr->TPages = TPage;
00201 
00202         return GE_TRUE;
00203 }

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

Definition at line 88 of file WireFrame/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().

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

void TPage_MgrDestroy TPage_Mgr **  TPageMgr  ) 
 

Definition at line 134 of file WireFrame/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().

00135 {
00136         TPage_Mgr       *Mgr;
00137         TPage           *Page, *Next;
00138 
00139         assert(TPageMgr);
00140 
00141         Mgr = *TPageMgr;
00142 
00143         assert(Mgr);
00144         
00145         // Free the pages
00146         for (Page = Mgr->TPages; Page; Page = Next)
00147         {
00148                 Next = Page->Next;
00149 
00150                 TPage_MgrDetachTPage(Mgr, Page);
00151                 TPage_Destroy(&Page);
00152         }
00153 
00154         assert(Mgr->TPages == NULL);
00155 
00156         // Release our ref on the DD object
00157         Mgr->lpDD->Release();                   
00158 
00159         free(*TPageMgr);
00160 
00161         *TPageMgr = NULL;
00162 }

void TPage_MgrDetachTPage TPage_Mgr Mgr,
TPage TPage
 

Definition at line 208 of file WireFrame/tpage.cpp.

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

Referenced by TPage_MgrDestroy().

00209 {
00210         assert(Mgr);
00211         assert(TPage);
00212         assert(TPage_MgrHasTPage(Mgr, TPage) == GE_TRUE);
00213 
00214         if (TPage->Next)
00215                 TPage->Next->Prev = TPage->Prev;
00216 
00217         if (TPage->Prev)
00218                 TPage->Prev->Next = TPage->Prev;
00219         else
00220         {
00221                 // If we get here, this better be the first TPage in the list!
00222                 assert(Mgr->TPages == TPage);
00223                 Mgr->TPages = TPage->Next;
00224         }
00225 
00226         TPage->Next = NULL;
00227         TPage->Prev = NULL;
00228 }

TPage_Block* TPage_MgrFindOptimalBlock TPage_Mgr Mgr,
uint32  LRU
 

Definition at line 233 of file WireFrame/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().

00234 {
00235 #if 0
00236         TPage           *Page, *BestPage;
00237         TPage_Block     *Block, *BestBlock;
00238         uint32          BestLRU;
00239 
00240         // We really should make a TPage_GetOptimalBlock...
00241 
00242         // First, find the page that has the highest LRU
00243         BestLRU = 0;
00244         BestPage = Mgr->TPages;
00245 
00246         for (Page = Mgr->TPages; Page; Page = Page->Next)
00247         {
00248                 if (Page->LRU > BestLRU && Page->NumFull)
00249                 {
00250                         BestPage = Page;
00251                         BestLRU = Page->LRU;
00252                 }
00253         }
00254 
00255         // Now, find the block with the lowest LRU in this page
00256         BestBlock = BestPage->Blocks;
00257         BestLRU = 0xffffffff;
00258 
00259         for (Block = BestPage->Blocks; Block; Block = Block->Next)
00260         {
00261                 if (Block->LRU < BestLRU)
00262                 {
00263                         BestBlock = Block;
00264                         BestLRU = Block->LRU;
00265                 }
00266         }
00267         /*
00268         if (BestBlock->LRU == LRU)
00269                 BestPage->NumFull++;
00270         else
00271         */
00272                 BestBlock->LRU = LRU;
00273         BestPage->LRU = LRU;
00274 #else
00275         TPage           *Page;
00276         TPage_Block     *Block, *BestBlock;
00277         uint32          BestLRU;
00278 
00279         // We really should make a TPage_GetOptimalBlock...
00280         BestBlock = NULL;
00281         BestLRU = 0xffffffff;
00282 
00283         for (Page = Mgr->TPages; Page; Page = Page->Next)
00284         {
00285                 for (Block = Page->Blocks; Block; Block = Block->Next)
00286                 {
00287                         if (Block->LRU < BestLRU)
00288                         {
00289                                 BestBlock = Block;
00290                                 BestLRU = Block->LRU;
00291                         }
00292                 }
00293         }
00294 
00295         BestBlock->LRU = LRU;
00296 #endif
00297 
00298         return BestBlock;
00299 }

geBoolean TPage_MgrHasTPage TPage_Mgr Mgr,
TPage Page
 

Definition at line 167 of file WireFrame/tpage.cpp.

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

Referenced by TPage_MgrAttachTPage(), and TPage_MgrDetachTPage().

00168 {
00169         TPage   *Page2;
00170 
00171         assert(Mgr);
00172         assert(Page);
00173 
00174         for (Page2 = Mgr->TPages; Page2; Page2 = Page2->Next)
00175         {
00176                 if (Page2 == Page)
00177                 {
00178                         return GE_TRUE;
00179                 }
00180         }
00181         
00182         return GE_FALSE;
00183 }


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