First pass at reducing the overall memory footprint: moved GetFormattedText() out of CardPrimitives and into MTGCard. The idea being, only keep the formatted text around for cards that are actually in use.
Also fixed a subtle memory pooling issue in the RenderCountersBig() routine: if you're in regular card display mode, the idea is that formatted text is only fetched if you flip into alternate render mode. However, in this function, if counters are being drawn, it would fetch the formatted text in order to determine where to draw the counters, EVEN IF the counters count was zero. So it had nothing to draw, but it meanwhile pooled the formatted strings into memory anyway.
This commit is contained in:
@@ -1409,7 +1409,6 @@ int AIPlayerBaka::computeActions()
|
||||
//am im not interupting my own spell, or the stack contains nothing.
|
||||
{
|
||||
findingCard = true;
|
||||
CardDescriptor cd;
|
||||
ManaCost * icurrentMana = getPotentialMana();
|
||||
bool ipotential = false;
|
||||
if (icurrentMana->getConvertedCost())
|
||||
@@ -1454,7 +1453,6 @@ int AIPlayerBaka::computeActions()
|
||||
}
|
||||
else if(p == this && g->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0)
|
||||
{ //standard actions
|
||||
CardDescriptor cd;
|
||||
switch (currentGamePhase)
|
||||
{
|
||||
case Constants::MTG_PHASE_FIRSTMAIN:
|
||||
|
||||
@@ -368,7 +368,7 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos)
|
||||
// Write the description
|
||||
{
|
||||
font->SetScale(kWidthScaleFactor * pos.actZ);
|
||||
const std::vector<string> txt = card->data->formattedText();
|
||||
const std::vector<string> txt = card->GetFormattedText();
|
||||
unsigned i = 0;
|
||||
unsigned h = neofont ? 14 : 11;
|
||||
for (std::vector<string>::const_iterator it = txt.begin(); it != txt.end(); ++it, ++i)
|
||||
@@ -577,7 +577,7 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad)
|
||||
renderer->RenderQuad(q.get(), x, pos.actY, pos.actT, scale, scale);
|
||||
}
|
||||
|
||||
const std::vector<string> txt = card->data->formattedText();
|
||||
const std::vector<string> txt = card->GetFormattedText();
|
||||
size_t nbTextLines = txt.size();
|
||||
|
||||
//Render the image on top of that
|
||||
@@ -785,12 +785,12 @@ void CardGui::RenderBig(MTGCard* card, const Pos& pos)
|
||||
void CardGui::RenderCountersBig(const Pos& pos)
|
||||
{
|
||||
// Write Named Counters
|
||||
if (card->counters)
|
||||
if (card->counters && card->counters->mCount > 0)
|
||||
{
|
||||
WFont * font = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT);
|
||||
font->SetColor(ARGB((int)pos.actA, 0, 0, 0));
|
||||
font->SetScale(kWidthScaleFactor * pos.actZ);
|
||||
std::vector<string> txt = card->formattedText();
|
||||
std::vector<string> txt = card->GetFormattedText();
|
||||
unsigned i = txt.size() + 1;
|
||||
Counter * c = NULL;
|
||||
for (int t = 0; t < card->counters->mCount; t++, i++)
|
||||
|
||||
@@ -61,23 +61,6 @@ int CardPrimitive::init()
|
||||
return 1;
|
||||
}
|
||||
|
||||
const vector<string>& CardPrimitive::formattedText()
|
||||
{
|
||||
if (ftdText.empty())
|
||||
{
|
||||
std::string s = text;
|
||||
std::string::size_type found = s.find_first_of("{}");
|
||||
while (found != string::npos)
|
||||
{
|
||||
s[found] = '/';
|
||||
found = s.find_first_of("{}", found + 1);
|
||||
}
|
||||
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT);
|
||||
mFont->FormatText(s, ftdText);
|
||||
}
|
||||
return ftdText;
|
||||
}
|
||||
|
||||
bool CardPrimitive::isCreature()
|
||||
{
|
||||
return hasSubtype(Subtypes::TYPE_CREATURE);
|
||||
|
||||
@@ -251,10 +251,11 @@ void GameApp::Create()
|
||||
JSoundSystem::GetInstance()->SetSfxVolume(options[Options::SFXVOLUME].number);
|
||||
JSoundSystem::GetInstance()->SetMusicVolume(options[Options::MUSICVOLUME].number);
|
||||
|
||||
DebugTrace("size of MTGCardInstance: " << sizeof(MTGCardInstance));
|
||||
DebugTrace("size of MTGCard: "<< sizeof(MTGCard));
|
||||
DebugTrace("size of CardPrimitive: "<< sizeof(CardPrimitive));
|
||||
DebugTrace("size of ExtraCost: " << sizeof(ExtraCost));
|
||||
DebugTrace("Size of ManaCost: " << sizeof(ManaCost));
|
||||
DebugTrace("size of ManaCost: " << sizeof(ManaCost));
|
||||
|
||||
LOG("Game Creation Done.");
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ MTGCard::MTGCard(int set_id)
|
||||
init();
|
||||
setId = set_id;
|
||||
}
|
||||
|
||||
MTGCard::MTGCard(MTGCard * source)
|
||||
{
|
||||
|
||||
strcpy(image_name, source->image_name);
|
||||
rarity = source->rarity;
|
||||
mtgid = source->mtgid;
|
||||
@@ -33,6 +33,10 @@ MTGCard::MTGCard(MTGCard * source)
|
||||
data = source->data;
|
||||
}
|
||||
|
||||
MTGCard::~MTGCard()
|
||||
{
|
||||
}
|
||||
|
||||
int MTGCard::init()
|
||||
{
|
||||
setId = 0;
|
||||
@@ -82,3 +86,23 @@ void MTGCard::setPrimitive(CardPrimitive * cp)
|
||||
{
|
||||
data = cp;
|
||||
}
|
||||
|
||||
const vector<string>& MTGCard::GetFormattedText()
|
||||
{
|
||||
if (mFormattedText.empty())
|
||||
{
|
||||
if (data != NULL)
|
||||
{
|
||||
std::string s = data->text;
|
||||
std::string::size_type found = s.find_first_of("{}");
|
||||
while (found != string::npos)
|
||||
{
|
||||
s[found] = '/';
|
||||
found = s.find_first_of("{}", found + 1);
|
||||
}
|
||||
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT);
|
||||
mFont->FormatText(s, mFormattedText);
|
||||
}
|
||||
}
|
||||
return mFormattedText;
|
||||
}
|
||||
Reference in New Issue
Block a user