Reducing the memory footprint: reworked the concept of 'colors' in CardPrimitives. What used to be an array of ints (ie 28 bytes) is now contained in a single byte, we use bit masking to support setting multiple colors on this variable. This also eliminates a lot of silly loops for setting colors in the code - now it's a straight byte copy.

Also thrown in are a couple of string to const string& conversions.
This commit is contained in:
wrenczes@gmail.com
2011-04-25 11:20:07 +00:00
parent b8310838f4
commit 1cbf3db582
8 changed files with 162 additions and 120 deletions

View File

@@ -11,6 +11,7 @@
#define CD_OR 1
#define CD_AND 2
#define CD_NOT 3
enum ENUM_COMPARISON_MODES
{
@@ -23,10 +24,12 @@ enum ENUM_COMPARISON_MODES
COMPARISON_UNEQUAL
};
class CardDescriptor: public MTGCardInstance{
class CardDescriptor: public MTGCardInstance
{
protected:
MTGCardInstance * match_or(MTGCardInstance * card);
MTGCardInstance * match_and(MTGCardInstance * card);
MTGCardInstance * match_or(MTGCardInstance * card);
MTGCardInstance * match_and(MTGCardInstance * card);
MTGCardInstance * match_not(MTGCardInstance * card);
bool valueInRange(int comparisonMode, int value, int criterion);
public:
int mode;

View File

@@ -11,6 +11,15 @@
using namespace std;
const uint8_t kColorBitMask_Artifact = 0x01;
const uint8_t kColorBitMask_Green = 0x02;
const uint8_t kColorBitMask_Blue = 0x04;
const uint8_t kColorBitMask_Red = 0x08;
const uint8_t kColorBitMask_Black = 0x10;
const uint8_t kColorBitMask_White = 0x20;
const uint8_t kColorBitMask_Land = 0x40;
class CardPrimitive
#ifdef TRACK_OBJECT_USAGE
: public InstanceCounter<CardPrimitive>
@@ -25,7 +34,7 @@ public:
string name;
int init();
int colors[Constants::MTG_NB_COLORS];
uint8_t colors;
map<int,int> basicAbilities;
map<string,string> magicTexts;
string magicText;
@@ -44,10 +53,10 @@ public:
virtual ~CardPrimitive();
void setColor(int _color, int removeAllOthers = 0);
void setColor(string _color, int removeAllOthers = 0);
void setColor(const string& _color, int removeAllOthers = 0);
void removeColor(int color);
int getColor();
int hasColor(int _color);
bool hasColor(int inColor);
int countColors();
int has(int ability);
@@ -70,11 +79,11 @@ public:
int removeType(int value, int removeAll = 0);
bool hasSubtype(int _subtype);
bool hasSubtype(const char * _subtype);
bool hasSubtype(string _subtype);
bool hasSubtype(const string& _subtype);
bool hasType(int _type);
bool hasType(const char * type);
void setManaCost(string value);
void setManaCost(const string& value);
ManaCost * getManaCost();
bool isCreature();
bool isLand();