Performance improvements/cleanup: card->hasType("foo") performs a string lookup for an integer id. Now that our primitives have over 1000 types (1018, I believe is the number I saw while debugging), this is not the cheapest lookup. Over the course of time, a lot of new rules have crept in the code - support for 'aura', 'equipment', and recently 'planeswalker'. While profiling, I saw an inordinate amount of time being used doing map lookups for these strings. Since they're used so frequently, I've added them to the SubTypes enumeration, and swapped out doing the string lookup in favour of using the int ID directly. I also found a few places where we were using hasType("Creature") or hasType("land") when we already had helper functions to do the int lookup, so I swapped these in as appropriate, as well as a couple of places where we had hasType("instant") instead of hasType(Subtypes::TYPE_INSTANT), etc.

This commit is contained in:
wrenczes@gmail.com
2011-04-10 00:07:34 +00:00
parent 62da8e7ad8
commit 99ed83c5e8
12 changed files with 67 additions and 61 deletions

View File

@@ -3,6 +3,7 @@
#include "CardSelectorSingleton.h"
#include "GameApp.h"
#include "GuiPlay.h"
#include "Subtypes.h"
#include "Trash.h"
#define CARD_WIDTH (31)
@@ -10,6 +11,7 @@
const float GuiPlay::HORZWIDTH = 300.0f;
const float GuiPlay::VERTHEIGHT = 80.0f;
void GuiPlay::CardStack::reset(unsigned total, float x, float y)
{
this->total = total;
@@ -177,7 +179,7 @@ GuiPlay::~GuiPlay()
bool isSpell(CardView* c)
{
return c->card->isSpell() && !c->card->isCreature() && !c->card->hasType("Planeswalker");
return c->card->isSpell() && !c->card->isCreature() && !c->card->hasType(Subtypes::TYPE_PLANESWALKER);
}
void GuiPlay::Replace()
{
@@ -189,7 +191,7 @@ void GuiPlay::Replace()
for (iterator it = cards.begin(); it != end_spells; ++it)
if (!(*it)->card->target)
{
if(!(*it)->card->hasSubtype("aura") && !(*it)->card->hasType("Planeswalker"))
if(!(*it)->card->hasSubtype(Subtypes::TYPE_AURA) && !(*it)->card->hasType(Subtypes::TYPE_PLANESWALKER))
{
if (game->players[0] == (*it)->card->controller())
++selfSpellsN;
@@ -210,7 +212,7 @@ void GuiPlay::Replace()
else
++opponentCreaturesN;
}
else if ((*it)->card->isLand() || (*it)->card->hasType("Planeswalker"))
else if ((*it)->card->isLand() || (*it)->card->hasType(Subtypes::TYPE_PLANESWALKER))
{
if (game->players[0] == (*it)->card->controller())
++selfLandsN;
@@ -225,7 +227,7 @@ void GuiPlay::Replace()
for (iterator it = cards.begin(); it != end_spells; ++it)
if (!(*it)->card->target)
{
if(!(*it)->card->hasSubtype("aura") && !(*it)->card->hasType("Planeswalker"))
if(!(*it)->card->hasSubtype(Subtypes::TYPE_AURA) && !(*it)->card->hasType(Subtypes::TYPE_PLANESWALKER))
{
if (game->players[0] == (*it)->card->controller())
selfSpells.Enstack(*it);
@@ -268,7 +270,7 @@ void GuiPlay::Replace()
//rerun the iter reattaching planes walkers to the back of the lands.
for (iterator it = end_spells; it != cards.end(); ++it)
{
if ((*it)->card->hasType("Planeswalker"))
if ((*it)->card->hasType(Subtypes::TYPE_PLANESWALKER))
{
if (game->players[0] == (*it)->card->controller())
selfLands.Enstack(*it);
@@ -297,7 +299,7 @@ void GuiPlay::Render()
else
opponentCreatures.Render(*it, cards.begin(), end_spells);
}
else if(!(*it)->card->hasType("Planeswalker"))
else if(!(*it)->card->hasType(Subtypes::TYPE_PLANESWALKER))
{
if (!(*it)->card->target)
{