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:
@@ -75,7 +75,7 @@ void GameStateDuel::Start()
|
||||
|
||||
mGamePhase = DUEL_STATE_CHOOSE_DECK1;
|
||||
credits = NEW Credits();
|
||||
mFont = GameApp::CommonRes->GetJLBFont(Constants::MENU_FONT);
|
||||
mFont = resources.GetJLBFont(Constants::MENU_FONT);
|
||||
mFont->SetBase(0);
|
||||
opponentMenuFont = mFont;
|
||||
|
||||
@@ -115,7 +115,7 @@ void GameStateDuel::loadPlayerRandom(int playerId, int isAI, int mode){
|
||||
string lands[] = {"forest", "forest", "island", "mountain", "swamp", "plains", "forest"};
|
||||
|
||||
|
||||
MTGDeck * tempDeck = NEW MTGDeck(NULL, mParent->collection);
|
||||
MTGDeck * tempDeck = NEW MTGDeck(mParent->collection);
|
||||
tempDeck->addRandomCards(9,0,0,-1,lands[color1].c_str());
|
||||
tempDeck->addRandomCards(9,0,0,-1,lands[color2].c_str());
|
||||
tempDeck->addRandomCards(1,0,0,'U',"land",colors,nbcolors);
|
||||
@@ -141,7 +141,7 @@ void GameStateDuel::loadPlayerRandom(int playerId, int isAI, int mode){
|
||||
void GameStateDuel::loadPlayerMomir(int playerId, int isAI){
|
||||
string deckFileSmall = "momir";
|
||||
char empty[] = "";
|
||||
MTGDeck * tempDeck = NEW MTGDeck(options.profileFile("momir.txt").c_str(), NULL, mParent->collection);
|
||||
MTGDeck * tempDeck = NEW MTGDeck(options.profileFile("momir.txt").c_str(), mParent->collection);
|
||||
deck[playerId] = NEW MTGPlayerCards(mParent->collection, tempDeck);
|
||||
if (!isAI) // Human Player
|
||||
mPlayers[playerId] = NEW HumanPlayer(deck[playerId], options.profileFile("momir.txt").c_str(), deckFileSmall);
|
||||
@@ -160,7 +160,7 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){
|
||||
sprintf(deckFile, "%s/deck%i.txt",options.profileFile().c_str(), decknb);
|
||||
char deckFileSmall[255];
|
||||
sprintf(deckFileSmall, "player_deck%i",decknb);
|
||||
MTGDeck * tempDeck = NEW MTGDeck(deckFile, NULL, mParent->collection);
|
||||
MTGDeck * tempDeck = NEW MTGDeck(deckFile, mParent->collection);
|
||||
deck[playerId] = NEW MTGPlayerCards(mParent->collection,tempDeck);
|
||||
delete tempDeck;
|
||||
mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFile, deckFileSmall);
|
||||
|
||||
Reference in New Issue
Block a user