Jeck - Please review: this makes minor changes to a lot of files, and major changes to the WCache flatten() function.
* Removed all calls to Release(JQuad*). * Updated flatten(). Prior flatten was buggy beyond belief. * Done some extensive testing, but if this causes more trouble than it fixes, we'll have to revert. It's too close to release time.
This commit is contained in:
@@ -143,6 +143,7 @@ void GameApp::Create()
|
||||
jq->SetHotSpot(12, 12);
|
||||
jq = resources.RetrieveQuad("shadow.png", 0, 0, 16, 16,"shadow",RETRIEVE_MANAGE);
|
||||
jq->SetHotSpot(8, 8);
|
||||
jq = resources.RetrieveQuad("phasebar.png",0,0,0,0,"phasebar",RETRIEVE_MANAGE);
|
||||
|
||||
collection = NEW MTGAllCards();
|
||||
|
||||
@@ -223,7 +224,6 @@ void GameApp::Destroy()
|
||||
|
||||
void GameApp::Update()
|
||||
{
|
||||
|
||||
if (systemError.size()) return;
|
||||
JGE* mEngine = JGE::GetInstance();
|
||||
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonClick(PSP_CTRL_TRIANGLE))
|
||||
|
||||
@@ -125,7 +125,7 @@ void GameStateDeckViewer::Start()
|
||||
}
|
||||
|
||||
//Grab a texture in VRAM.
|
||||
pspIconsTexture = resources.RetrieveTexture("iconspsp.png");
|
||||
pspIconsTexture = resources.RetrieveTexture("iconspsp.png", RETRIEVE_LOCK);
|
||||
|
||||
char buf[512];
|
||||
for (int i=0; i < 8; i++){
|
||||
@@ -183,9 +183,6 @@ void GameStateDeckViewer::End()
|
||||
SAFE_DELETE(menu);
|
||||
|
||||
resources.Release(pspIconsTexture);
|
||||
for (int i=0; i < 8; i++){
|
||||
resources.Release(pspIcons[i]);
|
||||
}
|
||||
SAFE_DELETE(myCollection);
|
||||
SAFE_DELETE(myDeck);
|
||||
SAFE_DELETE(pricelist);
|
||||
|
||||
@@ -270,7 +270,6 @@ void GameStateMenu::End()
|
||||
JRenderer::GetInstance()->EnableVSync(false);
|
||||
|
||||
resources.Release(bgTexture);
|
||||
resources.Release(mBg);
|
||||
SAFE_DELETE(mGuiController);
|
||||
}
|
||||
|
||||
@@ -292,12 +291,16 @@ void GameStateMenu::Update(float dt)
|
||||
//Force default, if necessary.
|
||||
if(options[Options::ACTIVE_PROFILE].str == "")
|
||||
options[Options::ACTIVE_PROFILE].str = "Default";
|
||||
|
||||
//Release splash texture
|
||||
resources.Release(splashTex);
|
||||
splashTex = NULL;
|
||||
mSplash = NULL;
|
||||
|
||||
//check for deleted collection / first-timer
|
||||
std::ifstream file(options.profileFile(PLAYER_COLLECTION).c_str());
|
||||
if(file){
|
||||
file.close();
|
||||
resources.Release(mSplash);
|
||||
currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_NONE;
|
||||
}else{
|
||||
currentState = MENU_STATE_MAJOR_FIRST_TIME | MENU_STATE_MINOR_NONE;
|
||||
@@ -409,8 +412,10 @@ void GameStateMenu::Render()
|
||||
renderer->ClearScreen(ARGB(0,0,0,0));
|
||||
JLBFont * mFont = resources.GetJLBFont(Constants::MENU_FONT);
|
||||
if ((currentState & MENU_STATE_MAJOR) == MENU_STATE_MAJOR_LOADING_CARDS){
|
||||
if(!mSplash)
|
||||
mSplash = resources.RetrieveQuad("splash.jpg");
|
||||
if(!splashTex){
|
||||
splashTex = resources.RetrieveTexture("splash.jpg",RETRIEVE_LOCK);
|
||||
mSplash = resources.RetrieveTempQuad("splash.jpg");
|
||||
}
|
||||
if (mSplash){
|
||||
renderer->RenderQuad(mSplash,0,0);
|
||||
}else{
|
||||
|
||||
@@ -39,9 +39,14 @@ void GameStateShop::Start()
|
||||
altThumb[5] = resources.RetrieveTexture("white_thumb.jpg", RETRIEVE_LOCK);
|
||||
altThumb[6] = resources.RetrieveTexture("land_thumb.jpg", RETRIEVE_LOCK);
|
||||
altThumb[7] = resources.RetrieveTexture("gold_thumb.jpg", RETRIEVE_LOCK);
|
||||
|
||||
|
||||
mBack = resources.GetQuad("back");
|
||||
//resources.Unmiss("shop.jpg"); //Last resort.
|
||||
mBgTex = resources.RetrieveTexture("shop.jpg",RETRIEVE_LOCK);
|
||||
if(mBgTex)
|
||||
mBg = resources.RetrieveQuad("shop.jpg");
|
||||
else
|
||||
mBg = NULL;
|
||||
|
||||
menuFont = resources.GetJLBFont(Constants::MENU_FONT);
|
||||
itemFont = resources.GetJLBFont(Constants::MAIN_FONT);
|
||||
@@ -123,6 +128,9 @@ void GameStateShop::load(){
|
||||
void GameStateShop::End()
|
||||
{
|
||||
JRenderer::GetInstance()->EnableVSync(false);
|
||||
resources.Release(mBgTex);
|
||||
mBgTex = NULL;
|
||||
mBg = NULL;
|
||||
|
||||
//Release alternate thumbnails.
|
||||
for(int i=0;i<8;i++){
|
||||
@@ -166,7 +174,7 @@ void GameStateShop::Render()
|
||||
//Erase
|
||||
JRenderer * r = JRenderer::GetInstance();
|
||||
r->ClearScreen(ARGB(0,0,0,0));
|
||||
JQuad * mBg = resources.RetrieveQuad("shop.jpg");
|
||||
|
||||
if (mBg) r->RenderQuad(mBg,0,0);
|
||||
|
||||
if (shop)
|
||||
|
||||
@@ -4,23 +4,14 @@
|
||||
|
||||
GuiBackground::GuiBackground()
|
||||
{
|
||||
JTexture* texture = resources.GetTexture("backdrop.jpg");
|
||||
if (texture)
|
||||
quad = NEW JQuad(texture, 0, 0, 480, 255);
|
||||
else
|
||||
{
|
||||
quad = NULL;
|
||||
GameApp::systemError = "Error loading background texture : " __FILE__;
|
||||
}
|
||||
}
|
||||
|
||||
GuiBackground::~GuiBackground()
|
||||
{
|
||||
delete(quad);
|
||||
}
|
||||
|
||||
void GuiBackground::Render()
|
||||
{
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
renderer->RenderQuad(quad, 0, 18);
|
||||
renderer->RenderQuad(resources.RetrieveTempQuad("backdrop.jpg"), 0, 18);
|
||||
}
|
||||
|
||||
@@ -6,44 +6,31 @@ GuiFrame::GuiFrame()
|
||||
{
|
||||
if (resources.GetTexture("wood.png"))
|
||||
wood = resources.RetrieveQuad("wood.png", 0, 0, SCREEN_WIDTH, 28);
|
||||
else
|
||||
{
|
||||
else{
|
||||
wood = NULL;
|
||||
GameApp::systemError += "Can't load wood texture : " __FILE__ "\n";
|
||||
}
|
||||
|
||||
if (resources.GetTexture("gold.png"))
|
||||
{
|
||||
gold1 = resources.RetrieveQuad("gold.png", 0, 0, SCREEN_WIDTH, 6, "gold1");
|
||||
gold2 = resources.RetrieveQuad("gold.png", 0, 6, SCREEN_WIDTH, 6, "gold2");
|
||||
}
|
||||
else
|
||||
{
|
||||
gold1 = gold2 = NULL;
|
||||
GameApp::systemError += "Can't load gold texture : " __FILE__ "\n";
|
||||
}
|
||||
if (resources.GetTexture("goldglow.png"))
|
||||
goldGlow = resources.RetrieveQuad("goldglow.png", 1, 1, SCREEN_WIDTH - 2, 18);
|
||||
else
|
||||
{
|
||||
goldGlow = NULL;
|
||||
GameApp::systemError += "Can't load gold glow texture : " __FILE__ "\n";
|
||||
|
||||
goldGlow = gold1 = gold2 = NULL;
|
||||
if (resources.GetTexture("gold.png")){
|
||||
gold1 = resources.RetrieveQuad("gold.png", 0, 0, SCREEN_WIDTH, 6, "gold1");
|
||||
gold2 = resources.RetrieveQuad("gold.png", 0, 6, SCREEN_WIDTH, 6, "gold2");
|
||||
if (resources.GetTexture("goldglow.png"))
|
||||
goldGlow = resources.RetrieveQuad("goldglow.png", 1, 1, SCREEN_WIDTH - 2, 18);
|
||||
if (gold2){
|
||||
gold2->SetColor(ARGB(127, 255, 255, 255));
|
||||
gold2->SetHFlip(true);
|
||||
}
|
||||
}
|
||||
|
||||
step = 0.0;
|
||||
|
||||
if (gold2){
|
||||
gold2->SetColor(ARGB(127, 255, 255, 255));
|
||||
gold2->SetHFlip(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GuiFrame::~GuiFrame()
|
||||
{
|
||||
resources.Release(gold2);
|
||||
resources.Release(gold1);
|
||||
resources.Release(wood);
|
||||
resources.Release(goldGlow);
|
||||
}
|
||||
|
||||
void GuiFrame::Render()
|
||||
@@ -51,15 +38,21 @@ void GuiFrame::Render()
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
float sized = step / 4; if (sized > SCREEN_WIDTH) sized -= SCREEN_WIDTH;
|
||||
renderer->RenderQuad(wood, 0, 0);
|
||||
renderer->RenderQuad(gold1, -sized, 16);
|
||||
renderer->RenderQuad(gold1, -sized + 479, 16);
|
||||
if(gold1){
|
||||
renderer->RenderQuad(gold1, -sized, 16);
|
||||
renderer->RenderQuad(gold1, -sized + 479, 16);
|
||||
|
||||
if(goldGlow){
|
||||
goldGlow->SetColor(ARGB((100+(rand()%50)), 255, 255, 255));
|
||||
renderer->RenderQuad(goldGlow, -sized, 9);
|
||||
renderer->RenderQuad(goldGlow, -sized + 480, 9);
|
||||
}
|
||||
|
||||
goldGlow->SetColor(ARGB((100+(rand()%50)), 255, 255, 255));
|
||||
renderer->RenderQuad(goldGlow, -sized, 9);
|
||||
renderer->RenderQuad(goldGlow, -sized + 480, 9);
|
||||
|
||||
renderer->RenderQuad(gold2, step / 2, 16);
|
||||
renderer->RenderQuad(gold2, step / 2 - 479, 16);
|
||||
if(gold2){
|
||||
renderer->RenderQuad(gold2, step / 2, 16);
|
||||
renderer->RenderQuad(gold2, step / 2 - 479, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiFrame::Update(float dt)
|
||||
|
||||
@@ -23,19 +23,19 @@ static int colors[] =
|
||||
|
||||
GuiPhaseBar::GuiPhaseBar() : phase(GameObserver::GetInstance()->phaseRing->getCurrentPhase()), angle(0.0f)
|
||||
{
|
||||
JTexture* texture = resources.GetTexture("phasebar.png");
|
||||
if (texture)
|
||||
quad = NEW JQuad(texture, 0, 0, Width, Height);
|
||||
JQuad * quad;
|
||||
if ((quad = resources.GetQuad("phasebar")) != NULL){
|
||||
quad->mHeight = Height;
|
||||
quad->mWidth = Width;
|
||||
}
|
||||
else
|
||||
{
|
||||
quad = NULL;
|
||||
GameApp::systemError = "Error loading phasebar texture : " __FILE__;
|
||||
}
|
||||
{
|
||||
GameApp::systemError = "Error loading phasebar texture : " __FILE__;
|
||||
}
|
||||
}
|
||||
|
||||
GuiPhaseBar::~GuiPhaseBar()
|
||||
{
|
||||
delete(quad);
|
||||
}
|
||||
|
||||
void GuiPhaseBar::Update(float dt)
|
||||
@@ -49,6 +49,7 @@ void GuiPhaseBar::Render()
|
||||
static const float CENTER = SCREEN_HEIGHT_F / 2 + 10;
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
GameObserver * g = GameObserver::GetInstance();
|
||||
JQuad * quad = resources.GetQuad("phasebar");
|
||||
unsigned p = (phase->id + Phases - 4) * (Width+1);
|
||||
float scale;
|
||||
float start = CENTER + (Width / 2) * angle * ICONSCALE / (M_PI / 6) - ICONSCALE * Width / 4;
|
||||
|
||||
@@ -107,9 +107,8 @@ int ShopItem::updateCount(DeckDataWrapper * ddw){
|
||||
|
||||
ShopItem::~ShopItem(){
|
||||
OutputDebugString("delete shopitem\n");
|
||||
if(mRelease){
|
||||
resources.Release(thumb);
|
||||
}
|
||||
if(thumb)
|
||||
resources.Release(thumb->mTex);
|
||||
SAFE_DELETE(mesh);
|
||||
}
|
||||
|
||||
@@ -219,9 +218,12 @@ ShopItems::ShopItems(int id, JGuiListener* listener, JLBFont* font, int x, int y
|
||||
myCollection = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), _collection));
|
||||
showCardList = true;
|
||||
|
||||
mBgAA = resources.RetrieveQuad("shop_aliasing.png");
|
||||
if(mBgAA)
|
||||
mBgAA = NULL;
|
||||
mBgAATex = resources.RetrieveTexture("shop_aliasing.png",RETRIEVE_LOCK);
|
||||
if(mBgAATex){
|
||||
mBgAA = resources.RetrieveQuad("shop_aliasing.png");
|
||||
mBgAA->SetTextureRect(0,0,250,120);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -453,7 +455,7 @@ ShopItems::~ShopItems(){
|
||||
SAFE_DELETE(dialog);
|
||||
safeDeleteDisplay();
|
||||
SAFE_DELETE(myCollection);
|
||||
resources.Release(mBgAA);
|
||||
resources.Release(mBgAATex);
|
||||
}
|
||||
|
||||
ostream& ShopItem::toString(ostream& out) const
|
||||
|
||||
@@ -184,12 +184,6 @@ void SimpleMenu::Close()
|
||||
}
|
||||
|
||||
void SimpleMenu::destroy(){
|
||||
resources.Release(SimpleMenu::spadeR);
|
||||
resources.Release(SimpleMenu::spadeL);
|
||||
resources.Release(SimpleMenu::side);
|
||||
resources.Release(SimpleMenu::spadeRTex);
|
||||
resources.Release(SimpleMenu::spadeLTex);
|
||||
resources.Release(SimpleMenu::sideTex);
|
||||
SAFE_DELETE(SimpleMenu::jewel);
|
||||
SAFE_DELETE(SimpleMenu::stars);
|
||||
SAFE_DELETE(SimpleMenu::jewelTex);
|
||||
|
||||
@@ -84,18 +84,6 @@ WCachedTexture::~WCachedTexture(){
|
||||
JTexture * WCachedTexture::Actual(){
|
||||
return texture;
|
||||
}
|
||||
bool WCachedTexture::isLocked(){
|
||||
if(locks != WRES_UNLOCKED)
|
||||
return true;
|
||||
|
||||
for(vector<WTrackedQuad*>::iterator it=trackedQuads.begin();it!=trackedQuads.end();it++){
|
||||
if((*it)->isLocked())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WCachedTexture::ReleaseQuad(JQuad* quad){
|
||||
if(quad == NULL)
|
||||
return false;
|
||||
@@ -273,8 +261,8 @@ bool WCachedTexture::Attempt(string filename, int submode, int & error){
|
||||
if(submode & TEXTURE_SUB_5551)
|
||||
format = GU_PSM_5551;
|
||||
|
||||
if(!realname.size()){
|
||||
error = CACHE_ERROR_404;
|
||||
if(!realname.size()){ //realname should not be empty, even if file 404s.
|
||||
error = CACHE_ERROR_BAD;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -344,7 +332,6 @@ bool WCachedSample::Attempt(string filename, int submode, int & error){
|
||||
error = CACHE_ERROR_404;
|
||||
else
|
||||
error = CACHE_ERROR_BAD;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <JGE.h>
|
||||
#include <JFileSystem.h>
|
||||
#include <assert.h>
|
||||
#include "../include/WResourceManager.h"
|
||||
|
||||
|
||||
int idCounter = OTHERS_OFFSET;
|
||||
|
||||
WResourceManager resources;
|
||||
@@ -60,7 +60,7 @@ void WResourceManager::DebugRender(){
|
||||
|
||||
|
||||
|
||||
sprintf(buf,"Total Size: %lu (%lu cached, %lu managed)",Size(),SizeCached(),SizeManaged());
|
||||
sprintf(buf,"Time: %u. Total Size: %lu (%lu cached, %lu managed). ",lastTime,Size(),SizeCached(),SizeManaged());
|
||||
font->DrawString(buf, SCREEN_WIDTH-10,SCREEN_HEIGHT-15,JGETEXT_RIGHT);
|
||||
|
||||
#ifdef DEBUG_CACHE
|
||||
@@ -125,7 +125,7 @@ unsigned int WResourceManager::CountManaged(){
|
||||
}
|
||||
|
||||
unsigned int WResourceManager::nowTime(){
|
||||
if(lastTime == 65535)
|
||||
if(lastTime > MAX_CACHE_TIME)
|
||||
FlattenTimes();
|
||||
|
||||
return ++lastTime;
|
||||
@@ -336,25 +336,17 @@ void WResourceManager::Release(JTexture * tex){
|
||||
textureWCache.Release(tex);
|
||||
}
|
||||
|
||||
void WResourceManager::Release(JQuad * quad){
|
||||
if(!quad)
|
||||
return;
|
||||
|
||||
void WResourceManager::Unmiss(string filename){
|
||||
map<int,WCachedTexture*>::iterator it;
|
||||
for(it = textureWCache.cache.begin();it!=textureWCache.cache.end();it++){
|
||||
if(it->second && it->second->ReleaseQuad(quad))
|
||||
break;
|
||||
}
|
||||
|
||||
if(it != textureWCache.cache.end() && it->second)
|
||||
textureWCache.RemoveItem(it->second,false); //won't remove locked.
|
||||
int id = textureWCache.makeID(0,filename,CACHE_NORMAL);
|
||||
textureWCache.RemoveMiss(id);
|
||||
}
|
||||
|
||||
void WResourceManager::ClearUnlocked(){
|
||||
textureWCache.ClearUnlocked();
|
||||
sampleWCache.ClearUnlocked();
|
||||
psiWCache.ClearUnlocked();
|
||||
}
|
||||
|
||||
bool WResourceManager::Cleanup(){
|
||||
int check = 0;
|
||||
|
||||
@@ -1037,10 +1029,9 @@ cacheItem * WCache<cacheItem, cacheActual>::Get(int id, string filename, int sty
|
||||
if(style != RETRIEVE_MANAGE){
|
||||
it = cache.find(lookup);
|
||||
//Well, we've found something...
|
||||
if(it != cache.end()) {
|
||||
if (!it->second)
|
||||
mError = CACHE_ERROR_404;
|
||||
return it->second; //A hit.
|
||||
if(it != cache.end()){
|
||||
mError = CACHE_ERROR_NONE; //We found an entry in cache, so not an error.
|
||||
return it->second; //A hit, or maybe a miss.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1143,23 +1134,35 @@ bool WCache<cacheItem, cacheActual>::Cleanup(){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WCacheSort::operator()(const WResource * l, const WResource * r){
|
||||
if(!l || !r)
|
||||
return false;
|
||||
return (l->lastTime < r->lastTime);
|
||||
}
|
||||
|
||||
template <class cacheItem, class cacheActual>
|
||||
unsigned int WCache<cacheItem, cacheActual>::Flatten(){
|
||||
unsigned int youngest = (unsigned int) 65535;
|
||||
vector<cacheItem*> items;
|
||||
unsigned int oldest = 0;
|
||||
unsigned int lastSet = 0;
|
||||
|
||||
if(!cache.size())
|
||||
return 0;
|
||||
|
||||
for (typename map<int,cacheItem*>::iterator it = cache.begin(); it != cache.end(); ++it){
|
||||
if(!it->second) continue;
|
||||
if(it->second->lastTime < youngest) youngest = it->second->lastTime;
|
||||
if(it->second->lastTime > oldest) oldest = it->second->lastTime;
|
||||
items.push_back(it->second);
|
||||
}
|
||||
|
||||
for (typename map<int,cacheItem*>::iterator it = cache.begin(); it != cache.end(); ++it){
|
||||
if(!it->second) continue;
|
||||
it->second->lastTime -= youngest;
|
||||
sort(items.begin(), items.end(), WCacheSort());
|
||||
|
||||
for (typename vector<cacheItem*>::iterator it = items.begin(); it != items.end(); ++it){
|
||||
assert((*it) && (*it)->lastTime > lastSet);
|
||||
lastSet = (*it)->lastTime;
|
||||
(*it)->lastTime = ++oldest;
|
||||
}
|
||||
|
||||
return (oldest - youngest);
|
||||
return oldest + 1;
|
||||
}
|
||||
|
||||
template <class cacheItem, class cacheActual>
|
||||
|
||||
Reference in New Issue
Block a user