- Moved Cast Restriction variables "out" of CardPrimitives (replaced with a pointer). This frees 64bytes off of CardPrimitives on Windows, I assume something similar on the PSP, which gives a result of more than 500kB freed

- fix for issue 716 (text not rendered in some cases) 
Test suite passes
This commit is contained in:
wagic.the.homebrew
2011-08-07 05:05:28 +00:00
parent 9f3a42d0c6
commit 765b6b0412
4 changed files with 99 additions and 69 deletions

View File

@@ -1,3 +1,8 @@
/* CardPrimitive objects represent the cards database.
* For MTG we have thousands of those, that stay constantly in Ram
* on low-end devices such as the PSP, adding stuff to this class can have a very high cost
* As an example, with 16'000 card primitives (the rough number of cards in MTG), adding a simple 16 bytes attribute costs 250kB (2% of the total available ram on the PSP)
*/
#ifndef _CARDPRIMITIVE_H_
#define _CARDPRIMITIVE_H_
@@ -21,6 +26,17 @@ const uint8_t kColorBitMask_White = 0x20;
const uint8_t kColorBitMask_Land = 0x40;
class CastRestrictions {
public:
string restriction;
string otherrestriction;
CastRestrictions * clone() const
{
return NEW CastRestrictions(*this);
};
};
class CardPrimitive
#ifdef TRACK_OBJECT_USAGE
: public InstanceCounter<CardPrimitive>
@@ -29,6 +45,7 @@ class CardPrimitive
private:
string text;
vector<string> formattedText;
CastRestrictions * restrictions;
protected:
string lcname;
@@ -48,9 +65,6 @@ public:
string spellTargetType;
int power;
int toughness;
bool hasRestriction;
string restriction;
string otherrestriction;
int suspendedTime;
vector<int>types;
@@ -102,9 +116,9 @@ public:
void setToughness(int _toughness);
int getToughness();
void setRestrictions(string _restriction);
void getRestrictions();
const string getRestrictions();
void setOtherRestrictions(string _restriction);
void getOtherRestrictions();
const string getOtherRestrictions();
};

View File

@@ -49,12 +49,12 @@ CardPrimitive::CardPrimitive(CardPrimitive * source)
manaCost.alternative->alternativeName = source->getManaCost()->alternative->alternativeName;
text = source->text;
formattedText = source->formattedText;
setName(source->name);
power = source->power;
toughness = source->toughness;
restriction = source->restriction;
otherrestriction = source->otherrestriction;
restrictions = source->restrictions ? source->restrictions->clone() : NULL;
suspendedTime = source->suspendedTime;
magicText = source->magicText;
@@ -66,6 +66,7 @@ CardPrimitive::CardPrimitive(CardPrimitive * source)
CardPrimitive::~CardPrimitive()
{
SAFE_DELETE(restrictions);
}
int CardPrimitive::init()
@@ -78,7 +79,7 @@ int CardPrimitive::init()
magicTexts.clear();
spellTargetType = "";
alias = 0;
hasRestriction = false;
restrictions = NULL;
return 1;
}
@@ -99,22 +100,34 @@ bool CardPrimitive::isSpell()
void CardPrimitive::setRestrictions(string _restriction)
{
restriction = _restriction;
if (!restrictions)
restrictions = NEW CastRestrictions();
restrictions->restriction = _restriction;
}
void CardPrimitive::getRestrictions()
const string CardPrimitive::getRestrictions()
{
restriction;
if (!restrictions)
return "";
return restrictions->restriction;
}
void CardPrimitive::setOtherRestrictions(string _restriction)
{
otherrestriction = _restriction;
if (!restrictions)
restrictions = NEW CastRestrictions();
restrictions->otherrestriction = _restriction;
}
void CardPrimitive::getOtherRestrictions()
const string CardPrimitive::getOtherRestrictions()
{
otherrestriction;
if (!restrictions)
return "";
return restrictions->otherrestriction;
}
void CardPrimitive::setColor(const string& _color, int removeAllOthers)

View File

@@ -67,12 +67,12 @@ int MTGAbility::parseCastRestrictions(MTGCardInstance * card,Player * player,str
int MTGAbility::allowedToCast(MTGCardInstance * card,Player * player)
{
return parseCastRestrictions(card,player,card->restriction,"");
return parseCastRestrictions(card,player,card->getRestrictions(),"");
}
int MTGAbility::allowedToAltCast(MTGCardInstance * card,Player * player)
{
return parseCastRestrictions(card,player,"",card->otherrestriction);
return parseCastRestrictions(card,player,"",card->getOtherRestrictions());
}
int AbilityFactory::parseCastRestrictions(MTGCardInstance * card,Player * player,string restrictions,string otherRestrictions)

View File

@@ -94,6 +94,16 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
}
break;
case 'b': //buyback
if (!primitive) primitive = NEW CardPrimitive();
if (ManaCost * cost = primitive->getManaCost())
{
string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
cost->BuyBack = ManaCost::parseManaCost(value);
}
break;
case 'c': //color
if (!primitive) primitive = NEW CardPrimitive();
{
@@ -109,10 +119,36 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
}
break;
case 'f': //flashback//morph
{
if (!primitive) primitive = NEW CardPrimitive();
if(ManaCost * cost = primitive->getManaCost())
{
if( s.find("facedown") != string::npos)//morph
{
string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
cost->morph = ManaCost::parseManaCost(value);
}
else
{
string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
cost->FlashBack = ManaCost::parseManaCost(value);
}
}
break;
}
case 'g': //grade
if (s.size() - i - 1 > 2) currentGrade = getGrade(val[2]);
break;
case 'i': //id
if (!card) card = NEW MTGCard();
card->setMTGId(atoi(val));
break;
case 'k': //kicker
if (!primitive) primitive = NEW CardPrimitive();
if (ManaCost * cost = primitive->getManaCost())
@@ -123,7 +159,21 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
}
break;
case 'o': //othercost
case 'm': //mana
if (!primitive) primitive = NEW CardPrimitive();
{
string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
primitive->setManaCost(value);
}
break;
case 'n': //name
if (!primitive) primitive = NEW CardPrimitive();
primitive->setName(val);
break;
case 'o': //othercost/otherrestriction
if (!primitive) primitive = NEW CardPrimitive();
if(key[5] == 'r')//otherrestrictions
{
@@ -151,54 +201,6 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
}
break;
case 'b': //buyback
if (!primitive) primitive = NEW CardPrimitive();
if (ManaCost * cost = primitive->getManaCost())
{
string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
cost->BuyBack = ManaCost::parseManaCost(value);
}
break;
case 'f': //flashback//morph
{
if (!primitive) primitive = NEW CardPrimitive();
if(ManaCost * cost = primitive->getManaCost())
{
if( s.find("facedown") != string::npos)//morph
{
string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
cost->morph = ManaCost::parseManaCost(value);
}
else
{
string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
cost->FlashBack = ManaCost::parseManaCost(value);
}
}
break;
}
case 'i': //id
if (!card) card = NEW MTGCard();
card->setMTGId(atoi(val));
break;
case 'm': //mana
if (!primitive) primitive = NEW CardPrimitive();
{
string value = val;
std::transform(value.begin(), value.end(), value.begin(), ::tolower);
primitive->setManaCost(value);
}
break;
case 'n': //name
if (!primitive) primitive = NEW CardPrimitive();
primitive->setName(val);
break;
case 'p':
if ('r' == key[1])
{ // primitive
@@ -213,13 +215,12 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
}
break;
case 'r': //retrace/rarity
case 'r': //retrace/rarity//restrictions
if('s' == key[2] && 't' == key[3])//restrictions
{
if (!primitive) primitive = NEW CardPrimitive();
string value = val;
primitive->setRestrictions(value);
primitive->hasRestriction = true;
}
else if ('e' == key[1] && 't' == key[2])
{ //retrace
@@ -237,6 +238,7 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
card->setRarity(val[0]);
}
break;
case 's': //subtype, suspend
{
if (s.find("suspend") != string::npos)
@@ -263,6 +265,7 @@ int MTGAllCards::processConfLine(string &s, MTGCard *card, CardPrimitive * primi
}
break;
}
case 't':
if (!primitive) primitive = NEW CardPrimitive();
if (0 == strcmp("target", key))
@@ -1068,8 +1071,8 @@ void MTGDeck::printDetailedDeckText(std::ofstream& file )
currentCard << card->data->getPower() << "/" << card->data->getToughness() << ", ";
if ( card->data->hasRestriction )
currentCard << ", " << card->data->otherrestriction;
if ( card->data->getOtherRestrictions().size() )
currentCard << ", " << card->data->getOtherRestrictions();
for (size_t x = 0; x < card->data->basicAbilities.size(); ++x)
{