From babda2bc0fd06bf743adb6a2e0258fcba901fac6 Mon Sep 17 00:00:00 2001 From: "wrenczes@gmail.com" Date: Wed, 20 Apr 2011 21:07:24 +0000 Subject: [PATCH] Some minor tweaks to make the image prefetching feel less flickery : when a card goes from a player's library into their hand, trigger a prefetch of the image. Also do the same thing when the AI decides on what card to play and creates an action. The idea being, new cards in play will probably want to be viewed by the player (and in the case of the AI playing a spell, we automatically show the image during the interrupt window before it comes into play). This makes for a much smoother gameplay - we have to get the image at some point anyway, and by doing it before we get to the render call, we no longer have the back card image pop up briefly. --- projects/mtg/include/AIPlayer.h | 8 ++------ projects/mtg/src/AIPlayer.cpp | 26 ++++++++++++++++++++++++++ projects/mtg/src/MTGGameZones.cpp | 18 ++++++++++++++++++ projects/mtg/src/WResourceManager.cpp | 5 ++--- 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/projects/mtg/include/AIPlayer.h b/projects/mtg/include/AIPlayer.h index 79b1062d1..487781e42 100644 --- a/projects/mtg/include/AIPlayer.h +++ b/projects/mtg/include/AIPlayer.h @@ -40,12 +40,8 @@ public: id = currentId++; }; - AIAction(MTGCardInstance * c, MTGCardInstance * t = NULL) - : efficiency(-1), ability(NULL), player(NULL), click(c), target(t) - { - id = currentId++; - }; - + AIAction(MTGCardInstance * c, MTGCardInstance * t = NULL); + AIAction(Player * p) : efficiency(-1), ability(NULL), player(p), click(NULL), target(NULL) { diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index a0bc6e183..39c6790a0 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -2,6 +2,7 @@ #include "AIPlayer.h" #include "CardDescriptor.h" +#include "CardSelectorSingleton.h" #include "AIStats.h" #include "AllAbilities.h" #include "ExtraCost.h" @@ -9,10 +10,35 @@ #include "GameStateDuel.h" #include "DeckManager.h" + const char * const MTG_LAND_TEXTS[] = { "artifact", "forest", "island", "mountain", "swamp", "plains", "other lands" }; int AIAction::currentId = 0; +AIAction::AIAction(MTGCardInstance * c, MTGCardInstance * t) + : efficiency(-1), ability(NULL), player(NULL), click(c), target(t) +{ + id = currentId++; + + // useability tweak - assume that the user is probably going to want to see the full res card, + // so prefetch it. The idea is that we do it here as we want to start the prefetch before it's time to render, + // and waiting for it to actually go into play is too late, as we start drawing the card during the interrupt window. + // This is a good intercept point, as the AI has committed to using this card. + + // if we're not in text mode, always get the thumb + if (CardSelectorSingleton::Instance()->GetDrawMode() != DrawMode::kText) + { + DebugTrace("Prefetching AI card going into play: " << c->getImageName()); + WResourceManager::Instance()->RetrieveCard(c, RETRIEVE_THUMB); + + // also cache the large image if we're using kNormal mode + if (CardSelectorSingleton::Instance()->GetDrawMode() == DrawMode::kNormal) + { + WResourceManager::Instance()->RetrieveCard(c); + } + } +} + int AIAction::Act() { GameObserver * g = GameObserver::GetInstance(); diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index f2ab0f900..8680f26c8 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -1,5 +1,6 @@ #include "PrecompiledHeader.h" +#include "CardSelectorSingleton.h" #include "MTGGameZones.h" #include "Player.h" #include "WEvent.h" @@ -237,6 +238,23 @@ void MTGPlayerCards::drawFromLibrary() } MTGCardInstance * toMove = library->cards[library->nb_cards - 1]; library->lastCardDrawn = toMove; + + // useability tweak - assume that the user is probably going to want to see the new card, + // so prefetch it. + + // if we're not in text mode, always get the thumb + if (CardSelectorSingleton::Instance()->GetDrawMode() != DrawMode::kText) + { + DebugTrace("Prefetching AI card going into play: " << toMove->getImageName()); + WResourceManager::Instance()->RetrieveCard(toMove, RETRIEVE_THUMB); + + // also cache the large image if we're using kNormal mode + if (CardSelectorSingleton::Instance()->GetDrawMode() == DrawMode::kNormal) + { + WResourceManager::Instance()->RetrieveCard(toMove); + } + } + putInZone(toMove, library, hand); } diff --git a/projects/mtg/src/WResourceManager.cpp b/projects/mtg/src/WResourceManager.cpp index bec6b618f..5212b1710 100644 --- a/projects/mtg/src/WResourceManager.cpp +++ b/projects/mtg/src/WResourceManager.cpp @@ -936,8 +936,6 @@ void ResourceManagerImpl::ResetCacheLimits() DebugTrace( "Error, Not enough RAM for Cache: " << myNewSize << " - total Ram: " << ram); } textureWCache.Resize(MIN(myNewSize, HUGE_CACHE_LIMIT), MAX_CACHE_OBJECTS); - - DebugTrace("Texture cache resized to " << myNewSize); #endif return; } @@ -1020,6 +1018,7 @@ template void WCache::Resize(unsigned long size, int items) { maxCacheSize = size; + DebugTrace(typeid(cacheActual).name() << " cache resized to " << size << " bytes"); #ifdef DEBUG_CACHE std::ostringstream stream; @@ -1463,7 +1462,7 @@ bool WCache::Delete(cacheItem * item) cacheItems--; - DebugTrace("Deleting cache item " << ToHex(item)); + DebugTrace("Deleting cache item " << ToHex(item) << ", cache reduced by " << isize << " bytes"); SAFE_DELETE(item); return true; }