summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-03-05 23:13:55 -0700
committerIra Rice <irarice@gmail.com>2009-03-05 23:13:55 -0700
commitaa4229cbb9f2b264ca96c3beedc66b1c79ccc1f5 (patch)
tree19c5a75a766b7df51ae468fb6b8fdbcfd2c6cc72 /src/being.cpp
parent93e45964f3b7a0735984616f622ec32b40a21781 (diff)
downloadmana-aa4229cbb9f2b264ca96c3beedc66b1c79ccc1f5.tar.gz
mana-aa4229cbb9f2b264ca96c3beedc66b1c79ccc1f5.tar.bz2
mana-aa4229cbb9f2b264ca96c3beedc66b1c79ccc1f5.tar.xz
mana-aa4229cbb9f2b264ca96c3beedc66b1c79ccc1f5.zip
Made some optimizations based on some profiling done by Octalot, as well
as some other optimizations that I could see that cut down on some unneeded redraws, which in turn improved frame rates slightly. Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp61
1 files changed, 20 insertions, 41 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 312904ad..c31dae6d 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -70,6 +70,7 @@ Being::Being(int id, int job, Map *map):
mAction(STAND),
mWalkTime(0),
mEmotion(0), mEmotionTime(0),
+ mSpeechTime(0),
mAttackSpeed(350),
mId(id),
mWalkSpeed(150),
@@ -81,7 +82,6 @@ Being::Being(int id, int job, Map *map):
mEquippedWeapon(NULL),
mHairStyle(1), mHairColor(0),
mGender(GENDER_UNSPECIFIED),
- mSpeechTime(0),
mPx(0), mPy(0),
mSprites(VECTOREND_SPRITE, NULL),
mSpriteIDs(VECTOREND_SPRITE, 0),
@@ -136,9 +136,7 @@ Being::~Being()
instances--;
if (instances == 0)
- {
delete_all(emotionSet);
- }
delete mSpeechBubble;
delete mText;
@@ -328,13 +326,10 @@ void Being::setAction(Action action)
break;
case ATTACK:
if (mEquippedWeapon)
- {
currentAction = mEquippedWeapon->getAttackType();
- }
else
- {
currentAction = ACTION_ATTACK;
- }
+
for (int i = 0; i < VECTOREND_SPRITE; i++)
{
if (mSprites[i])
@@ -385,21 +380,13 @@ SpriteDirection Being::getSpriteDirection() const
SpriteDirection dir;
if (mDirection & UP)
- {
dir = DIRECTION_UP;
- }
else if (mDirection & DOWN)
- {
dir = DIRECTION_DOWN;
- }
else if (mDirection & RIGHT)
- {
dir = DIRECTION_RIGHT;
- }
else
- {
- dir = DIRECTION_LEFT;
- }
+ dir = DIRECTION_LEFT;
return dir;
}
@@ -445,7 +432,7 @@ void Being::logic()
if (mSpeechTime > 0)
mSpeechTime--;
- // Remove text if speech boxes aren't being used
+ // Remove text and speechbubbles if speech boxes aren't being used
if (mSpeechTime == 0 && mText)
{
delete mText;
@@ -482,9 +469,7 @@ void Being::logic()
}
// Update particle effects
- mChildParticleEffects.moveTo((float) mPx + 16.0f,
- (float) mPy + 32.0f);
-
+ mChildParticleEffects.moveTo((float) mPx + 16.0f, (float) mPy + 32.0f);
}
void Being::draw(Graphics *graphics, int offsetX, int offsetY) const
@@ -493,16 +478,12 @@ void Being::draw(Graphics *graphics, int offsetX, int offsetY) const
int py = mPy + offsetY;
if (mUsedTargetCursor != NULL)
- {
mUsedTargetCursor->draw(graphics, px, py);
- }
for (int i = 0; i < VECTOREND_SPRITE; i++)
{
if (mSprites[i])
- {
mSprites[i]->draw(graphics, px, py);
- }
}
}
@@ -511,8 +492,8 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY)
if (!mEmotion)
return;
- const int px = mPx + offsetX + 3;
- const int py = mPy + offsetY - 60;
+ const int px = mPx - offsetX;
+ const int py = mPy - offsetY - 64;
const int emotionIndex = mEmotion - 1;
if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast())
@@ -521,20 +502,25 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY)
void Being::drawSpeech(int offsetX, int offsetY)
{
- const int px = mPx + offsetX;
- const int py = mPy + offsetY;
+ const int px = mPx - offsetX;
+ const int py = mPy - offsetY;
const int speech = (int) config.getValue("speech", NAME_IN_BUBBLE);
// Draw speech above this being
- if (mSpeechTime > 0 && (speech == NAME_IN_BUBBLE ||
- speech == NO_NAME_IN_BUBBLE))
+ if (mSpeechTime == 0)
+ {
+ if (mSpeechBubble->isVisible())
+ mSpeechBubble->setVisible(false);
+ }
+ else if (mSpeechTime > 0 && (speech == NAME_IN_BUBBLE ||
+ speech == NO_NAME_IN_BUBBLE))
{
const bool showName = (speech == NAME_IN_BUBBLE);
if (mText)
{
delete mText;
- mText = 0;
+ mText = NULL;
}
mSpeechBubble->setCaption(showName ? mName : "", mNameColor);
@@ -550,6 +536,7 @@ void Being::drawSpeech(int offsetX, int offsetY)
else if (mSpeechTime > 0 && speech == TEXT_OVERHEAD)
{
mSpeechBubble->setVisible(false);
+
// don't introduce a memory leak
if (mText)
delete mText;
@@ -560,14 +547,12 @@ void Being::drawSpeech(int offsetX, int offsetY)
else if (speech == NO_SPEECH)
{
mSpeechBubble->setVisible(false);
+
if (mText)
delete mText;
+
mText = NULL;
}
- else if (mSpeechTime == 0)
- {
- mSpeechBubble->setVisible(false);
- }
}
Being::Type Being::getType() const
@@ -579,24 +564,18 @@ int Being::getOffset(char pos, char neg) const
{
// Check whether we're walking in the requested direction
if (mAction != WALK || !(mDirection & (pos | neg)))
- {
return 0;
- }
int offset = (get_elapsed_time(mWalkTime) * 32) / mWalkSpeed;
// We calculate the offset _from_ the _target_ location
offset -= 32;
if (offset > 0)
- {
offset = 0;
- }
// Going into negative direction? Invert the offset.
if (mDirection & pos)
- {
offset = -offset;
- }
return offset;
}