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.

This commit is contained in:
wrenczes@gmail.com
2011-04-20 21:07:24 +00:00
parent d06965d95e
commit babda2bc0f
4 changed files with 48 additions and 9 deletions

View File

@@ -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)
{

View File

@@ -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();

View File

@@ -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);
}

View File

@@ -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<class cacheItem, class cacheActual>
void WCache<cacheItem, cacheActual>::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<cacheItem, cacheActual>::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;
}