- graphical representation of counters. see graphics/counters/quest.jpg for an example

- rewrote some code dealing with text formatting for a card when rendering in text mode. I could swear my code has been reverted. If somebody has good reason to believe we should re-process the string formatting on every frame, please let me now. I believe my change can help rendering speed of text mode a lot.
- counters change to vector instead of array
This commit is contained in:
wagic.the.homebrew
2011-07-29 17:43:45 +00:00
parent 9631171ad1
commit 794be140ce
14 changed files with 149 additions and 70 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -2484,7 +2484,7 @@ public:
string sourcename = ((MTGCardInstance*)source)->name; string sourcename = ((MTGCardInstance*)source)->name;
tokenText.append(") source: "); tokenText.append(") source: ");
tokenText.append( sourcename); tokenText.append( sourcename);
myToken->text = tokenText; myToken->setText(tokenText);
} }
setTokenOwner(); setTokenOwner();
tokenReciever->game->temp->addCard(myToken); tokenReciever->game->temp->addCard(myToken);

View File

@@ -33,7 +33,7 @@ protected:
*/ */
static void RenderBig(MTGCard * card, const Pos& pos); static void RenderBig(MTGCard * card, const Pos& pos);
void RenderCountersBig(const Pos& pos); static void RenderCountersBig(MTGCard * card, const Pos& pos, int drawMode = DrawMode::kNormal);
static void AlternateRender(MTGCard * card, const Pos& pos); static void AlternateRender(MTGCard * card, const Pos& pos);
static void TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad); static void TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad);

View File

@@ -26,12 +26,15 @@ class CardPrimitive
: public InstanceCounter<CardPrimitive> : public InstanceCounter<CardPrimitive>
#endif #endif
{ {
private:
string text;
vector<string> formattedText;
protected: protected:
string lcname; string lcname;
ManaCost manaCost; ManaCost manaCost;
public: public:
string text;
string name; string name;
int init(); int init();
@@ -67,7 +70,7 @@ public:
int has(int ability); int has(int ability);
void setText(const string& value); void setText(const string& value);
const string& getText(); const vector<string>& getFormattedText();
void addMagicText(string value); void addMagicText(string value);
void addMagicText(string value, string zone); void addMagicText(string value, string zone);

View File

@@ -28,7 +28,7 @@ class Counters
{ {
public: public:
int mCount; int mCount;
Counter * counters[10]; vector<Counter *>counters;
MTGCardInstance * target; MTGCardInstance * target;
Counters(MTGCardInstance * _target); Counters(MTGCardInstance * _target);
~Counters(); ~Counters();

View File

@@ -451,11 +451,11 @@ int AIAction::getEfficiency()
efficiency = 90; efficiency = 90;
} }
if(_target->counters && _target->counters->counters && _target->counters->hasCounter(cc->power,cc->toughness) && _target->counters->hasCounter(cc->power,cc->toughness)->nb > 15) if(_target->counters && _target->counters->hasCounter(cc->power,cc->toughness) && _target->counters->hasCounter(cc->power,cc->toughness)->nb > 15)
{ {
efficiency = _target->counters->hasCounter(cc->power,cc->toughness)->nb; efficiency = _target->counters->hasCounter(cc->power,cc->toughness)->nb;
} }
if(cc->maxNb && _target->counters && _target->counters->counters && _target->counters->hasCounter(cc->power,cc->toughness)->nb >= cc->maxNb) if(cc->maxNb && _target->counters && _target->counters->hasCounter(cc->power,cc->toughness)->nb >= cc->maxNb)
efficiency = 0; efficiency = 0;
} }
} }

View File

@@ -2601,10 +2601,9 @@ int ATransformer::addToGame()
int ATransformer::reapplyCountersBonus(MTGCardInstance * rtarget,bool powerapplied,bool toughnessapplied) int ATransformer::reapplyCountersBonus(MTGCardInstance * rtarget,bool powerapplied,bool toughnessapplied)
{ {
if(!rtarget->counters) if(!rtarget->counters || !rtarget->counters->counters.size())
return 0; return 0;
Counter * c = NULL; Counter * c = rtarget->counters->counters[0];
c = rtarget->counters->counters[0];
int rNewPower = 0; int rNewPower = 0;
int rNewToughness = 0; int rNewToughness = 0;
for (int t = 0; t < rtarget->counters->mCount; t++) for (int t = 0; t < rtarget->counters->mCount; t++)

View File

@@ -34,17 +34,6 @@ namespace
return cosf(2 * M_PI * (value - 35) / 256.0f); return cosf(2 * M_PI * (value - 35) / 256.0f);
} }
void FormatText(std::string inText, std::vector<string>& outFormattedText)
{
std::string::size_type found = inText.find_first_of("{}");
while (found != string::npos)
{
inText[found] = '/';
found = inText.find_first_of("{}", found + 1);
}
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT);
mFont->FormatText(inText, outFormattedText);
}
} }
CardGui::CardGui(MTGCardInstance* card, float x, float y) CardGui::CardGui(MTGCardInstance* card, float x, float y)
@@ -119,10 +108,6 @@ void CardGui::Update(float dt)
void CardGui::DrawCard(const Pos& inPosition, int inMode) void CardGui::DrawCard(const Pos& inPosition, int inMode)
{ {
DrawCard(card, inPosition, inMode); DrawCard(card, inPosition, inMode);
if (inMode != DrawMode::kHidden)
{
RenderCountersBig(inPosition);
}
} }
void CardGui::DrawCard(MTGCard* inCard, const Pos& inPosition, int inMode) void CardGui::DrawCard(MTGCard* inCard, const Pos& inPosition, int inMode)
@@ -253,6 +238,7 @@ void CardGui::Render()
mFont->SetScale(1); mFont->SetScale(1);
} }
} }
if (tc && !tc->canTarget(card)) if (tc && !tc->canTarget(card))
{ {
if (!shadow) if (!shadow)
@@ -394,8 +380,7 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos)
{ {
font->SetScale(kWidthScaleFactor * pos.actZ); font->SetScale(kWidthScaleFactor * pos.actZ);
std::vector<string> txt; std::vector<string> txt = card->data->getFormattedText();
FormatText(card->data->getText(), txt);
unsigned i = 0; unsigned i = 0;
unsigned h = neofont ? 14 : 11; unsigned h = neofont ? 14 : 11;
@@ -549,6 +534,8 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos)
} }
font->SetScale(backup_scale); font->SetScale(backup_scale);
RenderCountersBig(card, pos, DrawMode::kText);
} }
void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad)
@@ -605,8 +592,7 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad)
renderer->RenderQuad(q.get(), x, pos.actY, pos.actT, scale, scale); renderer->RenderQuad(q.get(), x, pos.actY, pos.actT, scale, scale);
} }
std::vector<string> txt; std::vector<string> txt = card->data->getFormattedText();
FormatText(card->data->getText(), txt);
size_t nbTextLines = txt.size(); size_t nbTextLines = txt.size();
//Render the image on top of that //Render the image on top of that
@@ -783,6 +769,8 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad)
} }
font->SetScale(backup_scale); font->SetScale(backup_scale);
RenderCountersBig(card, pos);
} }
//Renders a big card on screen. Defaults to the "alternate" rendering if no image is found //Renders a big card on screen. Defaults to the "alternate" rendering if no image is found
@@ -802,6 +790,7 @@ void CardGui::RenderBig(MTGCard* card, const Pos& pos)
quad->SetColor(ARGB(255,255,255,255)); quad->SetColor(ARGB(255,255,255,255));
float scale = pos.actZ * 250.f / quad->mHeight; float scale = pos.actZ * 250.f / quad->mHeight;
renderer->RenderQuad(quad.get(), x, pos.actY, pos.actT, scale, scale); renderer->RenderQuad(quad.get(), x, pos.actY, pos.actT, scale, scale);
RenderCountersBig(card, pos);
return; return;
} }
@@ -811,47 +800,114 @@ void CardGui::RenderBig(MTGCard* card, const Pos& pos)
AlternateRender(card, pos); AlternateRender(card, pos);
} }
void CardGui::RenderCountersBig(const Pos& pos) void CardGui::RenderCountersBig(MTGCard * mtgcard, const Pos& pos, int drawMode)
{ {
// Write Named Counters MTGCardInstance * card = dynamic_cast<MTGCardInstance*> (mtgcard);
if (card->counters && card->counters->mCount > 0) if (!card)
{ return;
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; if (!card->counters)
FormatText(card->data->getText(), txt); return;
unsigned i = txt.size() + 1; if (!card->counters->mCount)
Counter * c = NULL; return;
for (int t = 0; t < card->counters->mCount; t++, i++)
// Write Named Counters
WFont * font = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT);
font->SetColor(ARGB((int)pos.actA, 0, 0, 0));
font->SetScale(kWidthScaleFactor * pos.actZ);
unsigned i = 0;
if (drawMode == DrawMode::kText)
{
std::vector<string> txt = card->data->getFormattedText();
i = txt.size() + 1;
}
for (size_t t = 0; t < card->counters->counters.size(); t++)
{
Counter * c = card->counters->counters[t];
if (!c || c->nb <= 0)
continue;
char buf[512];
bool renderText = true;
string gfx = "";
//TODO cache the gfx fetch results?
if (c->name.size())
{ {
if (c) if (c->nb < 6) //we only render a counter's specific quad if there are 5 counters of this type or less. Otherwise we will use the generic one
{ {
c = card->counters->getNext(c); string gfxRelativeName = "counters/";
} gfxRelativeName.append(c->name);
else gfxRelativeName.append(".png");
{ gfx = WResourceManager::Instance()->graphicsFile(gfxRelativeName);
c = card->counters->counters[0]; if (fileExists(gfx.c_str()))
}
if (c != NULL && c->nb > 0)
{
char buf[512];
if (c->name != "")
{ {
std::string s = c->name; renderText = false;
s[0] = toupper(s[0]); }
sprintf(buf, _("%s counters: %i").c_str(), s.c_str(), c->nb); else
{
gfx = "";
}
}
if (renderText)
{
std::string s = c->name;
s[0] = toupper(s[0]);
sprintf(buf, _("%s: %i").c_str(), s.c_str(), c->nb);
}
}
else
{
sprintf(buf, _("%s%i/%s%i").c_str(), ((c->power > 0) ? "+": ""), c->power * c->nb, ((c->toughness > 0) ? "+": ""),c->toughness* c->nb);
}
if (!gfx.size())
{
gfx = WResourceManager::Instance()->graphicsFile("counters/default.png");
if (!fileExists(gfx.c_str()))
gfx = "";
}
float x = pos.actX + (22 - BigWidth / 2) * pos.actZ;
float y = pos.actY + (-BigHeight / 2 + 80 + 11 * i + 21 * t) * pos.actZ;
if (y > pos.actY + 105)
{
y = (-BigHeight / 2 + 80 + 11 * i) * pos.actZ + (y - 105 - 21);
x += (BigWidth / 2) * pos.actZ;
}
if (gfx.size())
{
JQuadPtr q = WResourceManager::Instance()->RetrieveTempQuad(gfx);
if (q.get() && q->mTex)
{
float scale = 20.f / q->mHeight;
if (renderText)
{
float scaleX = (font->GetStringWidth(buf) + 20) / q->mWidth;
JRenderer::GetInstance()->RenderQuad(q.get(), x, y, 0, scaleX, scale);
} }
else else
{ {
sprintf(buf, _("%i/%i counters: %i").c_str(), c->power, c->toughness, c->nb); for (int j = 0; j < c->nb; ++j)
{
JRenderer::GetInstance()->RenderQuad(q.get(), x + (scale * q->mWidth * j), y, 0, scale, scale);
}
} }
font->DrawString(buf, pos.actX + (22 - BigWidth / 2) * pos.actZ, pos.actY + (-BigHeight / 2 + 80 + 11 * i)
* pos.actZ);
} }
} }
if (renderText)
{
font->SetColor(ARGB(255,0,0,0));
font->DrawString(buf, x + 5, y + 5);
}
} }
} }
MTGCardInstance* CardView::getCard() MTGCardInstance* CardView::getCard()

View File

@@ -246,10 +246,32 @@ void CardPrimitive::setText(const string& value)
text = value; text = value;
} }
const string& CardPrimitive::getText() /* This alters the card structure, but this is intentional for performance and
* space purpose: The only time we get the card text is to render it
* on the screen, in a formatted way.
* Formatting the string every frame is not efficient, especially since we always display it the same way
* Formatting all strings at startup is inefficient too.
* Instead, we format when requested, but only once, and cache the result.
* To avoid memory to blow up, in exchange of the cached result, we erase the original string
*/
const vector<string>& CardPrimitive::getFormattedText()
{ {
return text; if (!text.size())
} return formattedText;
std::string::size_type found = text.find_first_of("{}");
while (found != string::npos)
{
text[found] = '/';
found = text.find_first_of("{}", found + 1);
}
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT);
mFont->FormatText(text, formattedText);
text = "";
return formattedText;
};
void CardPrimitive::addMagicText(string value) void CardPrimitive::addMagicText(string value)
{ {

View File

@@ -92,7 +92,7 @@ int Counters::addCounter(const char * _name, int _power, int _toughness)
} }
} }
Counter * counter = NEW Counter(target, _name, _power, _toughness); Counter * counter = NEW Counter(target, _name, _power, _toughness);
counters[mCount] = counter; counters.push_back(counter);
counter->added(); counter->added();
mCount++; mCount++;
return mCount; return mCount;

View File

@@ -64,7 +64,7 @@ void MTGCardInstance::copy(MTGCardInstance * card)
manaCost.copy(data->getManaCost()); manaCost.copy(data->getManaCost());
text = data->text; setText(""); //The text is retrieved from the data anyways
setName(data->name); setName(data->name);
power = data->power; power = data->power;

View File

@@ -1049,7 +1049,6 @@ void MTGDeck::printDetailedDeckText(std::ofstream& file )
MTGSetInfo *setInfo = setlist.getInfo(card->setId); MTGSetInfo *setInfo = setlist.getInfo(card->setId);
string setName = setInfo->id; string setName = setInfo->id;
string cardName = card->data->getName(); string cardName = card->data->getName();
string description = card->data->getText();
currentCard << "#" << nbCards << " x " << cardName << " (" << setName << "), "; currentCard << "#" << nbCards << " x " << cardName << " (" << setName << "), ";

View File

@@ -289,12 +289,6 @@
<ClCompile Include="src\WResourceManager.cpp"> <ClCompile Include="src\WResourceManager.cpp">
<Filter>src</Filter> <Filter>src</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Pos.cpp">
<Filter>inc</Filter>
</ClCompile>
<ClCompile Include="src\PriceList.cpp">
<Filter>inc</Filter>
</ClCompile>
<ClCompile Include="src\SimplePopup.cpp"> <ClCompile Include="src\SimplePopup.cpp">
<Filter>src</Filter> <Filter>src</Filter>
</ClCompile> </ClCompile>
@@ -313,6 +307,12 @@
<ClCompile Include="src\IconButton.cpp"> <ClCompile Include="src\IconButton.cpp">
<Filter>src</Filter> <Filter>src</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Pos.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\PriceList.cpp">
<Filter>src</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="include\ActionElement.h"> <ClInclude Include="include\ActionElement.h">