From 4d1345041fd9c426236ddb73f1aa4714d619a0a8 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 21 May 2014 22:19:12 +0300 Subject: Dont create speechbuble object for all new beings. But create only if really need show text. --- src/being/being.cpp | 33 +++++++++++++++++++++++---------- src/being/being.h | 2 ++ 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/being/being.cpp b/src/being/being.cpp index adc1313a0..bc5e2cf84 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -161,7 +161,7 @@ Being::Being(const int id, mShowName(false), mIsGM(false), mType(type), - mSpeechBubble(new SpeechBubble), + mSpeechBubble(nullptr), mWalkSpeed(Net::getPlayerHandler()->getDefaultWalkSpeed()), mSpeed(Net::getPlayerHandler()->getDefaultWalkSpeed().x), mIp(), @@ -205,7 +205,6 @@ Being::Being(const int id, mAway(false), mInactive(false) { - mSpeechBubble->postInit(); for (int f = 0; f < 20; f ++) { @@ -270,6 +269,12 @@ Being::~Being() removeAllItemsParticles(); } +void Being::createSpeechBubble() +{ + mSpeechBubble = new SpeechBubble; + mSpeechBubble->postInit(); +} + void Being::setSubtype(const uint16_t subtype, const uint8_t look) { if (!mInfo) @@ -487,6 +492,8 @@ void Being::setSpeech(const std::string &text, const std::string &channel, else { const bool isShowName = (speech == BeingSpeech::NAME_IN_BUBBLE); + if (!mSpeechBubble) + createSpeechBubble(); mSpeechBubble->setCaption(isShowName ? mName : ""); mSpeechBubble->setText(mSpeech, isShowName); } @@ -1695,7 +1702,7 @@ void Being::drawEmotion(Graphics *const graphics, const int offsetX, void Being::drawSpeech(const int offsetX, const int offsetY) { - if (!mSpeechBubble || mSpeech.empty()) + if (mSpeech.empty()) return; const int px = getPixelX() - offsetX; @@ -1705,22 +1712,27 @@ void Being::drawSpeech(const int offsetX, const int offsetY) // Draw speech above this being if (mSpeechTime == 0) { - if (mSpeechBubble->isVisibleLocal()) + if (mSpeechBubble && mSpeechBubble->isVisibleLocal()) mSpeechBubble->setVisible(false); + mSpeech.clear(); } else if (mSpeechTime > 0 && (speech == BeingSpeech::NAME_IN_BUBBLE || speech == BeingSpeech::NO_NAME_IN_BUBBLE)) { delete2(mText) - mSpeechBubble->setPosition(px - (mSpeechBubble->getWidth() / 2), - py - getHeight() - (mSpeechBubble->getHeight())); - mSpeechBubble->setVisible(true); - mSpeechBubble->requestMoveToBackground(); + if (mSpeechBubble) + { + mSpeechBubble->setPosition(px - (mSpeechBubble->getWidth() / 2), + py - getHeight() - (mSpeechBubble->getHeight())); + mSpeechBubble->setVisible(true); + mSpeechBubble->requestMoveToBackground(); + } } else if (mSpeechTime > 0 && speech == BeingSpeech::TEXT_OVERHEAD) { - mSpeechBubble->setVisible(false); + if (mSpeechBubble) + mSpeechBubble->setVisible(false); if (!mText && userPalette) { @@ -1731,7 +1743,8 @@ void Being::drawSpeech(const int offsetX, const int offsetY) } else if (speech == BeingSpeech::NO_SPEECH) { - mSpeechBubble->setVisible(false); + if (mSpeechBubble) + mSpeechBubble->setVisible(false); delete2(mText) } } diff --git a/src/being/being.h b/src/being/being.h index 9ae57d545..65d661142 100644 --- a/src/being/being.h +++ b/src/being/being.h @@ -902,6 +902,8 @@ class Being : public ActorSprite, public ConfigListener void removeItemParticles(const int id); + void createSpeechBubble(); + static int getDefaultEffectId(const int type); BeingInfo *mInfo; -- cgit v1.2.3-60-g2f50