summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-21 22:19:12 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-21 22:19:12 +0300
commit4d1345041fd9c426236ddb73f1aa4714d619a0a8 (patch)
treee7879e72eb4db9d2a4d129c6341b6682bcc84b5c /src
parentf4fe732ccbd65fd584b7787f3b5aec904a85d11b (diff)
downloadmanaverse-4d1345041fd9c426236ddb73f1aa4714d619a0a8.tar.gz
manaverse-4d1345041fd9c426236ddb73f1aa4714d619a0a8.tar.bz2
manaverse-4d1345041fd9c426236ddb73f1aa4714d619a0a8.tar.xz
manaverse-4d1345041fd9c426236ddb73f1aa4714d619a0a8.zip
Dont create speechbuble object for all new beings.
But create only if really need show text.
Diffstat (limited to 'src')
-rw-r--r--src/being/being.cpp33
-rw-r--r--src/being/being.h2
2 files changed, 25 insertions, 10 deletions
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;