diff --git a/projects/mtg/include/CardPrimitive.h b/projects/mtg/include/CardPrimitive.h index faac2c049..1057cf7f4 100644 --- a/projects/mtg/include/CardPrimitive.h +++ b/projects/mtg/include/CardPrimitive.h @@ -53,7 +53,7 @@ public: int has(int ability); void setText(const string& value); - const char * getText(); + const string& getText(); void addMagicText(string value); void addMagicText(string value, string zone); diff --git a/projects/mtg/include/MTGCard.h b/projects/mtg/include/MTGCard.h index f61800f79..ff6d10e77 100644 --- a/projects/mtg/include/MTGCard.h +++ b/projects/mtg/include/MTGCard.h @@ -29,7 +29,6 @@ protected: int mtgid; char rarity; char image_name[MTGCARD_NAME_SIZE]; - vector mFormattedText; int init(); public: @@ -46,8 +45,6 @@ public: //void setImageName( char * value); void setPrimitive(CardPrimitive * cp); - const vector& GetFormattedText(); - int getMTGId() const; int getId() const; char getRarity() const; diff --git a/projects/mtg/src/CardGui.cpp b/projects/mtg/src/CardGui.cpp index aff187fd2..990803f65 100644 --- a/projects/mtg/src/CardGui.cpp +++ b/projects/mtg/src/CardGui.cpp @@ -33,6 +33,18 @@ namespace { return cosf(2 * M_PI * (value - 35) / 256.0f); } + + void FormatText(std::string inText, std::vector& 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) : @@ -368,7 +380,10 @@ void CardGui::AlternateRender(MTGCard * card, const Pos& pos) // Write the description { font->SetScale(kWidthScaleFactor * pos.actZ); - const std::vector txt = card->GetFormattedText(); + + std::vector txt; + FormatText(card->data->getText(), txt); + unsigned i = 0; unsigned h = neofont ? 14 : 11; for (std::vector::const_iterator it = txt.begin(); it != txt.end(); ++it, ++i) @@ -577,7 +592,8 @@ void CardGui::TinyCropRender(MTGCard * card, const Pos& pos, JQuad * quad) renderer->RenderQuad(q.get(), x, pos.actY, pos.actT, scale, scale); } - const std::vector txt = card->GetFormattedText(); + std::vector txt; + FormatText(card->data->getText(), txt); size_t nbTextLines = txt.size(); //Render the image on top of that @@ -790,7 +806,9 @@ void CardGui::RenderCountersBig(const Pos& pos) WFont * font = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT); font->SetColor(ARGB((int)pos.actA, 0, 0, 0)); font->SetScale(kWidthScaleFactor * pos.actZ); - std::vector txt = card->GetFormattedText(); + + std::vector txt; + FormatText(card->data->getText(), txt); unsigned i = txt.size() + 1; Counter * c = NULL; for (int t = 0; t < card->counters->mCount; t++, i++) diff --git a/projects/mtg/src/CardPrimitive.cpp b/projects/mtg/src/CardPrimitive.cpp index 74f1fd96d..24d1762fa 100644 --- a/projects/mtg/src/CardPrimitive.cpp +++ b/projects/mtg/src/CardPrimitive.cpp @@ -218,9 +218,9 @@ void CardPrimitive::setText(const string& value) text = value; } -const char * CardPrimitive::getText() +const string& CardPrimitive::getText() { - return text.c_str(); + return text; } void CardPrimitive::addMagicText(string value) diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index 3b16b10e4..63e2552db 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -475,7 +475,16 @@ void GameStateMenu::Update(float dt) } if (primitivesLoadCounter < (int) (primitives.size())) { +#ifdef _DEBUG + int startTime = JGEGetTime(); +#endif MTGCollection()->load(primitives[primitivesLoadCounter].c_str()); +#if _DEBUG + int endTime = JGEGetTime(); + float elapsedTime = (endTime - startTime); + DebugTrace("Time elapsed while loading " << primitives[primitivesLoadCounter] << " : " << elapsedTime << " ms"); +#endif + primitivesLoadCounter++; break; } diff --git a/projects/mtg/src/MTGCard.cpp b/projects/mtg/src/MTGCard.cpp index 2b971092b..1572373ce 100644 --- a/projects/mtg/src/MTGCard.cpp +++ b/projects/mtg/src/MTGCard.cpp @@ -88,23 +88,3 @@ void MTGCard::setPrimitive(CardPrimitive * cp) { data = cp; } - -const vector& 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; -} \ No newline at end of file