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:
@@ -8,7 +8,7 @@
|
||||
#include "../include/Damage.h"
|
||||
#include "../include/ManaCost.h"
|
||||
#include "../include/GameOptions.h"
|
||||
#include "../include/TexturesCache.h"
|
||||
#include "../include/WResourceManager.h"
|
||||
#include "../include/TargetChooser.h"
|
||||
#include "../include/CardGui.h"
|
||||
#include "../include/Translate.h"
|
||||
@@ -24,7 +24,7 @@ int NextGamePhase::resolve(){
|
||||
|
||||
void NextGamePhase::Render(){
|
||||
int nextPhase = (GameObserver::GetInstance()->getCurrentGamePhase() + 1) % Constants::MTG_PHASE_CLEANUP;
|
||||
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT);
|
||||
JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT);
|
||||
mFont->SetBase(0);
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
char buffer[200];
|
||||
@@ -50,14 +50,14 @@ int StackAbility::resolve(){
|
||||
return (ability->resolve());
|
||||
}
|
||||
void StackAbility::Render(){
|
||||
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT);
|
||||
JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT);
|
||||
mFont->SetBase(0);
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
char buffer[200];
|
||||
sprintf(buffer, "%s", _(ability->getMenuText()).c_str());
|
||||
mFont->DrawString(buffer, x + 30 , y, JGETEXT_LEFT);
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
JQuad * quad = cache.getThumb(ability->source);
|
||||
JQuad * quad = resources.RetrieveCard(ability->source,CACHE_THUMB);
|
||||
if (quad){
|
||||
quad->SetColor(ARGB(255,255,255,255));
|
||||
float scale = 30 / quad->mHeight;
|
||||
@@ -183,12 +183,12 @@ MTGCardInstance * Spell::getNextCardTarget(MTGCardInstance * previous){
|
||||
}
|
||||
|
||||
void Spell::Render(){
|
||||
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT);
|
||||
JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT);
|
||||
mFont->SetBase(0);
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
mFont->DrawString(_(source->name).c_str(), x + 30 , y, JGETEXT_LEFT);
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
JQuad * quad = cache.getThumb(source);
|
||||
JQuad * quad = resources.RetrieveCard(source,CACHE_THUMB);
|
||||
if (quad){
|
||||
quad->SetColor(ARGB(255,255,255,255));
|
||||
float scale = mHeight / quad->mHeight;
|
||||
@@ -205,7 +205,7 @@ void Spell::Render(){
|
||||
// just overwrites it.
|
||||
// I stole the render code from RenderBig() in CardGUI.cpp
|
||||
|
||||
quad = cache.getQuad(source);
|
||||
quad = resources.RetrieveCard(source);
|
||||
if (quad){
|
||||
quad->SetColor(ARGB(220,255,255,255));
|
||||
float scale = 257.f / quad->mHeight;
|
||||
@@ -217,7 +217,7 @@ void Spell::Render(){
|
||||
Pos pos = Pos(10 + 90, 20 + 130, 0.9f, 0.0, 255);
|
||||
CardGui::alternateRender(mtgcard, pos);
|
||||
|
||||
quad = cache.getThumb(source);
|
||||
quad = resources.RetrieveCard(source,CACHE_THUMB);
|
||||
if (quad){
|
||||
float scale = 250 / quad->mHeight;
|
||||
quad->SetColor(ARGB(40,255,255,255));
|
||||
@@ -268,7 +268,7 @@ int PutInGraveyard::resolve(){
|
||||
}
|
||||
|
||||
void PutInGraveyard::Render(){
|
||||
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT);
|
||||
JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT);
|
||||
mFont->SetBase(0);
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
if (!removeFromGame){
|
||||
@@ -277,7 +277,7 @@ void PutInGraveyard::Render(){
|
||||
mFont->DrawString(_("is exiled").c_str(), x + 30 , y, JGETEXT_LEFT);
|
||||
}
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
JQuad * quad = cache.getThumb(card);
|
||||
JQuad * quad = resources.RetrieveCard(card,CACHE_THUMB);
|
||||
if (quad){
|
||||
quad->SetColor(ARGB(255,255,255,255));
|
||||
float scale = 30 / quad->mHeight;
|
||||
@@ -305,7 +305,7 @@ int DrawAction::resolve(){
|
||||
}
|
||||
|
||||
void DrawAction::Render(){
|
||||
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT);
|
||||
JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT);
|
||||
mFont->SetBase(0);
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
char buffer[200];
|
||||
@@ -789,13 +789,13 @@ void ActionStack::Render(){
|
||||
if (current->state==NOT_RESOLVED) height += current->mHeight;
|
||||
}
|
||||
|
||||
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT);
|
||||
JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT);
|
||||
mFont->SetBase(0);
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
mFont->SetColor(ARGB(255,255,255,255));
|
||||
JRenderer * renderer = JRenderer::GetInstance();
|
||||
|
||||
//JQuad * back = GameApp::CommonRes->GetQuad("interrupt");
|
||||
//JQuad * back = resources.GetQuad("interrupt");
|
||||
//float xScale = width / back->mWidth;
|
||||
//float yScale = height / back->mHeight;
|
||||
renderer->FillRoundRect(x0 + 16 ,y0 + 16 ,width +2 ,height +2 , 10, ARGB(128,0,0,0));
|
||||
@@ -845,7 +845,7 @@ void ActionStack::Render(){
|
||||
if (current->display) height += current->mHeight;
|
||||
}
|
||||
|
||||
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT);
|
||||
JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT);
|
||||
mFont->SetBase(0);
|
||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user