Jeck - Cache and resource manager merged, streamlined.

This is pretty major, so there'll probably be something wrong with it... even though I did spend a few hours looking.
NOTES:
 * If you've Retrieved it, don't delete it--- Use resources.Release(Whatever). 
    Textures automatically release subordinate quads.
 * Most of the time, use resources.RetrieveQuad to grab a quad. Should handle everything for you.
    RetrieveQuad will load the required texture, if needed.
    Only managed resources have a resource name ("back", "simon", etc). 
    Managed resources can be retrieved with GetTexture/GetQuad/GetWhatever.
    Non managed quads lookup by position/dimensions, defaulting to the whole texture.
 * Use resources.RetrieveTexture only when you need to do something special to it. 
    Calling retrieve texture with RETRIEVE_MANAGE will permanently add a texture to the manager
    RETRIEVE_LOCK and RETRIEVE_VRAM will lock a texture. It will not leave the cache until
    Release(JTexture*) is called, or as a last resort during cache overflow.
 * Try to only store (as a class member) pointers to textures retrieved with RETRIEVE_MANAGE. 
    All others may become invalid, although locked textures do have a high degree of stability. It's
    pretty safe to store a locked texture if you're not going to load much between uses.

There's a lot going on here, so I might have missed something... but it runs through the test suite alright.

TODO: 
 * When called without any arguments, RetrieveQuad sometimes leaves a thin border around the image. 
    This can be bypassed by specifying a quad one or two pixels less than the image size. Why?
 * I've had a crash while runing the Demo mode, something to do with receiveEventMinus? 
    This hasn't exactly reproduced on a clean SVN copy, (being a hang, rather than a crash) so 
    I've probably done something to worsen the problem somehow? I'll look into it tomorrow.
 * Clean up lock/unlock system, memory usage. Streamline interface, consider phasing out calls using GetWhatever() format.
This commit is contained in:
wagic.jeck
2009-09-03 09:28:16 +00:00
parent 7214248494
commit f220d2e9b9
49 changed files with 1587 additions and 1233 deletions

View File

@@ -32,7 +32,7 @@ void CardGui::Update(float dt)
void CardGui::Render()
{
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT);
JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT);
JRenderer * renderer = JRenderer::GetInstance();
GameObserver * game = GameObserver::GetInstance();
@@ -40,31 +40,31 @@ void CardGui::Render()
TargetChooser * tc = NULL;
if (game) tc = game->getCurrentTargetChooser();
JQuad * quad = cache.getThumb(card);
JQuad * quad = resources.RetrieveCard(card,CACHE_THUMB);
if (quad) {
const float scale = actZ * 40 / quad->mHeight;
renderer->RenderQuad(GameApp::CommonRes->GetQuad("shadow"), actX + (scale-1)*15, actY + (scale-1)*15, actT, 28*scale, 40*scale);
renderer->RenderQuad(resources.GetQuad("shadow"), actX + (scale-1)*15, actY + (scale-1)*15, actT, 28*scale, 40*scale);
quad->SetColor(ARGB(static_cast<unsigned char>(actA),255,255,255));
renderer->RenderQuad(quad, actX, actY, actT, scale, scale);
}
else {
const float scale = actZ;
renderer->RenderQuad(GameApp::CommonRes->GetQuad("shadow"), actX + (scale-1)*15, actY + (scale-1)*15, actT, 28*scale, 40*scale);
renderer->RenderQuad(resources.GetQuad("shadow"), actX + (scale-1)*15, actY + (scale-1)*15, actT, 28*scale, 40*scale);
mFont->SetColor(ARGB(static_cast<unsigned char>(actA), 0, 0, 0));
JQuad * icon = NULL;
if (card->hasSubtype("plains"))
icon = GameApp::CommonRes->GetQuad("c_white");
icon = resources.GetQuad("c_white");
else if (card->hasSubtype("swamp"))
icon = GameApp::CommonRes->GetQuad("c_black");
icon = resources.GetQuad("c_black");
else if (card->hasSubtype("forest"))
icon = GameApp::CommonRes->GetQuad("c_green");
icon = resources.GetQuad("c_green");
else if (card->hasSubtype("mountain"))
icon = GameApp::CommonRes->GetQuad("c_red");
icon = resources.GetQuad("c_red");
else if (card->hasSubtype("island"))
icon = GameApp::CommonRes->GetQuad("c_blue");
icon = resources.GetQuad("c_blue");
if (icon) icon->SetHotSpot(16,16);
JQuad* q = alternateThumbQuad(card);
@@ -96,13 +96,15 @@ JQuad * CardGui::alternateThumbQuad(MTGCard * card){
JQuad * q;
switch(card->getColor())
{
case Constants::MTG_COLOR_GREEN: q = cache.getQuad("sets/green_thumb.jpg");break;
case Constants::MTG_COLOR_BLUE : q = cache.getQuad("sets/blue_thumb.jpg");break;
case Constants::MTG_COLOR_RED : q = cache.getQuad("sets/red_thumb.jpg");break;
case Constants::MTG_COLOR_BLACK: q = cache.getQuad("sets/black_thumb.jpg");break;
case Constants::MTG_COLOR_WHITE: q = cache.getQuad("sets/white_thumb.jpg");break;
default: q = cache.getQuad("sets/black_thumb.jpg");break;
case Constants::MTG_COLOR_GREEN: q = resources.RetrieveQuad("green_thumb.jpg");break;
case Constants::MTG_COLOR_BLUE : q = resources.RetrieveQuad("blue_thumb.jpg");break;
case Constants::MTG_COLOR_RED : q = resources.RetrieveQuad("red_thumb.jpg");break;
case Constants::MTG_COLOR_BLACK: q = resources.RetrieveQuad("black_thumb.jpg");break;
case Constants::MTG_COLOR_WHITE: q = resources.RetrieveQuad("white_thumb.jpg");break;
default: q = resources.RetrieveQuad("black_thumb.jpg");break;
}
if(q && q->mTex)
q->SetHotSpot(q->mTex->mWidth/2,q->mTex->mHeight/2);
return q;
}
@@ -112,19 +114,22 @@ void CardGui::alternateRender(MTGCard * card, const Pos& pos){
JQuad * q;
switch(card->getColor())
{
case Constants::MTG_COLOR_GREEN: q = cache.getQuad("sets/green.jpg");break;
case Constants::MTG_COLOR_BLUE : q = cache.getQuad("sets/blue.jpg");break;
case Constants::MTG_COLOR_RED : q = cache.getQuad("sets/red.jpg");break;
case Constants::MTG_COLOR_BLACK: q = cache.getQuad("sets/black.jpg");break;
case Constants::MTG_COLOR_WHITE: q = cache.getQuad("sets/white.jpg");break;
default: q = cache.getQuad("sets/black.jpg");break;
case Constants::MTG_COLOR_GREEN: q = resources.RetrieveQuad("green.jpg");break;
case Constants::MTG_COLOR_BLUE : q = resources.RetrieveQuad("blue.jpg");break;
case Constants::MTG_COLOR_RED : q = resources.RetrieveQuad("red.jpg");break;
case Constants::MTG_COLOR_BLACK: q = resources.RetrieveQuad("black.jpg");break;
case Constants::MTG_COLOR_WHITE: q = resources.RetrieveQuad("white.jpg");break;
default: q = resources.RetrieveQuad("black.jpg");break;
}
if(q && q->mTex)
q->SetHotSpot(q->mTex->mWidth/2,q->mTex->mHeight/2);
float scale = pos.actZ * 250 / q->mHeight;
q->SetColor(ARGB((int)pos.actA,255,255,255));
renderer->RenderQuad(q, pos.actX, pos.actY, pos.actT, scale, scale);
// Write the title
JLBFont * font = GameApp::CommonRes->GetJLBFont("magic");
JLBFont * font = resources.GetJLBFont("magic");
float backup_scale = font->GetScale();
font->SetColor(ARGB((int)pos.actA, 0, 0, 0));
font->SetScale(0.8 * pos.actZ);
@@ -217,7 +222,7 @@ void CardGui::alternateRender(MTGCard * card, const Pos& pos){
void CardGui::RenderBig(const Pos& pos){
JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = cache.getQuad(card);
JQuad * quad = resources.RetrieveCard(card);
if (quad){
quad->SetColor(ARGB((int)pos.actA,255,255,255));
float scale = pos.actZ * 257.f / quad->mHeight;
@@ -226,7 +231,7 @@ void CardGui::RenderBig(const Pos& pos){
}
JQuad * q;
if ((q = cache.getThumb(card)))
if ((q = resources.RetrieveCard(card,CACHE_THUMB)))
{
float scale = pos.actZ * 250 / q->mHeight;
q->SetColor(ARGB((int)pos.actA,255,255,255));