summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-27 14:26:23 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-27 14:34:30 +0100
commit31c28bbd0349475079ed2111c32b3cd07400554e (patch)
treef3068b3760b1782321143e3a06fe55fca8ae48f1
parent057e55c47ef3194ad56a09128eaa959984f2fd4a (diff)
downloadMana-31c28bbd0349475079ed2111c32b3cd07400554e.tar.gz
Mana-31c28bbd0349475079ed2111c32b3cd07400554e.tar.bz2
Mana-31c28bbd0349475079ed2111c32b3cd07400554e.tar.xz
Mana-31c28bbd0349475079ed2111c32b3cd07400554e.zip
Fixed position of dots on minimap
Also made mPx and mPy private and synchronize with mPos on setPosition(). The side effects of setting destination and clearing the path have been removed from setPosition(). Only the tmwserv PlayerHandler seemed to rely on that feature. Mantis-issue: 672
-rw-r--r--src/being.cpp59
-rw-r--r--src/being.h19
-rw-r--r--src/gui/minimap.cpp7
-rw-r--r--src/localplayer.cpp10
-rw-r--r--src/monster.cpp9
-rw-r--r--src/net/tmwserv/playerhandler.cpp1
-rw-r--r--src/npc.cpp14
-rw-r--r--src/player.cpp13
-rw-r--r--src/position.h3
9 files changed, 50 insertions, 85 deletions
diff --git a/src/being.cpp b/src/being.cpp
index e143d506..b0666e8a 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -100,7 +100,6 @@ Being::Being(int id, int job, Map *map):
#endif
mHairColor(0),
mGender(GENDER_UNSPECIFIED),
- mPx(0), mPy(0),
mStunMode(0),
mSprites(VECTOREND_SPRITE, NULL),
mSpriteIDs(VECTOREND_SPRITE, 0),
@@ -113,6 +112,7 @@ Being::Being(int id, int job, Map *map):
#else
mWalkSpeed(150),
#endif
+ mPx(0), mPy(0),
mUsedTargetCursor(NULL)
{
setMap(map);
@@ -141,8 +141,12 @@ Being::~Being()
void Being::setPosition(const Vector &pos)
{
mPos = pos;
- mDest = pos;
- mPath.clear();
+
+ // Update pixel coordinates (convert once, for performance reasons)
+ mPx = (int) pos.x;
+ mPy = (int) pos.y;
+
+ updateCoords();
}
#ifdef EATHENA_SUPPORT
@@ -432,13 +436,8 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type)
// Show damage number
particleEngine->addTextSplashEffect(damage,
-#ifdef TMWSERV_SUPPORT
- (int) mPos.x + 16,
- (int) mPos.y + 16,
-#else
mPx + 16, mPy + 16,
-#endif
- color, font, true);
+ color, font, true);
if (amount > 0)
{
@@ -649,7 +648,7 @@ void Being::logic()
// the jigger caused by moving too far.
if (length > 2.0f) {
const float speed = mWalkSpeed / 100.0f;
- mPos += dir / (length / speed);
+ setPosition(mPos + (dir / (length / speed)));
if (mAction != WALK)
setAction(WALK);
@@ -672,17 +671,9 @@ void Being::logic()
setAction(STAND);
}
#else
- int oldPx = mPx;
- int oldPy = mPy;
-
// Update pixel coordinates
- mPx = mX * 32 + getXOffset();
- mPy = mY * 32 + getYOffset();
-
- if (mPx != oldPx || mPy != oldPy)
- {
- updateCoords();
- }
+ setPosition(mX * 32 + getXOffset(),
+ mY * 32 + getYOffset());
#endif
if (mEmotion != 0)
@@ -714,23 +705,13 @@ void Being::logic()
}
// Update particle effects
-#ifdef TMWSERV_SUPPORT
- mChildParticleEffects.moveTo((float) mPx + 16.0f,
- (float) mPy + 32.0f);
-#else
mChildParticleEffects.moveTo(mPos.x, mPos.y);
-#endif
}
void Being::draw(Graphics *graphics, int offsetX, int offsetY) const
{
-#ifdef TMWSERV_SUPPORT
- int px = (int) mPos.x + offsetX;
- int py = (int) mPos.y + offsetY;
-#else
- int px = mPx + offsetX;
- int py = mPy + offsetY;
-#endif
+ const int px = mPx + offsetX;
+ const int py = mPy + offsetY;
if (mUsedTargetCursor)
mUsedTargetCursor->draw(graphics, px, py);
@@ -755,13 +736,8 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY)
if (!mEmotion)
return;
-#ifdef TMWSERV_SUPPORT
- const int px = (int) mPos.x + offsetX;
- const int py = (int) mPos.y + offsetY - 64;
-#else
const int px = mPx - offsetX;
const int py = mPy - offsetY - 64;
-#endif
const int emotionIndex = mEmotion - 1;
if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast())
@@ -770,13 +746,8 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY)
void Being::drawSpeech(int offsetX, int offsetY)
{
-#ifdef TMWSERV_SUPPORT
- int px = (int) mPos.x - offsetX;
- int py = (int) mPos.y - offsetY;
-#else
const int px = mPx - offsetX;
const int py = mPy - offsetY;
-#endif
const int speech = (int) config.getValue("speech", NAME_IN_BUBBLE);
// Draw speech above this being
@@ -814,7 +785,9 @@ void Being::drawSpeech(int offsetX, int offsetY)
if (mText)
delete mText;
- mText = new Text(mSpeech, mPx + X_SPEECH_OFFSET, mPy - Y_SPEECH_OFFSET,
+ mText = new Text(mSpeech,
+ mPx + X_SPEECH_OFFSET,
+ mPy - Y_SPEECH_OFFSET,
gcn::Graphics::CENTER,
&guiPalette->getColor(Palette::PARTICLE));
}
diff --git a/src/being.h b/src/being.h
index 158f2f72..0faf794e 100644
--- a/src/being.h
+++ b/src/being.h
@@ -387,24 +387,16 @@ class Being : public Sprite
virtual void draw(Graphics *graphics, int offsetX, int offsetY) const;
/**
- * Returns the pixel X coordinate.
+ * Returns the X coordinate in pixels.
*/
-#ifdef TMWSERV_SUPPORT
- int getPixelX() const { return (int) mPos.x; }
-#else
int getPixelX() const { return mPx; }
-#endif
/**
- * Returns the pixel Y coordinate.
+ * Returns the Y coordinate in pixels.
*
* @see Sprite::getPixelY()
*/
-#ifdef TMWSERV_SUPPORT
- int getPixelY() const { return (int) mPos.y; }
-#else
int getPixelY() const { return mPy; }
-#endif
#ifdef EATHENA_SUPPORT
/**
@@ -421,8 +413,7 @@ class Being : public Sprite
#endif
/**
- * Sets the position of this being. When the being was walking, it also
- * clears the destination and the path.
+ * Sets the position of this being.
*/
void setPosition(const Vector &pos);
@@ -545,7 +536,7 @@ class Being : public Sprite
void setPath(const Path &path);
/**
- * Let the sub-classes react to a replacement
+ * Let the sub-classes react to a replacement.
*/
virtual void updateCoords() {}
@@ -608,7 +599,6 @@ class Being : public Sprite
int mHairStyle;
int mHairColor;
Gender mGender;
- int mPx, mPy; /**< Pixel coordinates */
Uint16 mStunMode; /**< Stun mode; zero if not stunned */
std::set<int> mStatusEffects; /**< set of active status effects */
@@ -640,6 +630,7 @@ class Being : public Sprite
Vector mPos;
Vector mDest;
+ int mPx, mPy; /**< Position in pixels */
// Target cursor being used
SimpleAnimation* mUsedTargetCursor;
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index 93a55688..6bca796d 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -119,14 +119,9 @@ void Minimap::draw(gcn::Graphics *graphics)
if (mMapImage->getWidth() > a.width ||
mMapImage->getHeight() > a.height)
{
-#ifdef TMWSERV_SUPPORT
const Vector &p = player_node->getPosition();
mapOriginX = (int) (((a.width) / 2) - (int) (p.x * mProportion) / 32);
mapOriginY = (int) (((a.height) / 2) - (int) (p.y * mProportion) / 32);
-#else
- mapOriginX = (int) (((a.width) / 2) - (player_node->mX * mProportion));
- mapOriginY = (int) (((a.height) / 2) - (player_node->mY * mProportion));
-#endif
const int minOriginX = a.width - mMapImage->getWidth();
const int minOriginY = a.height - mMapImage->getHeight();
@@ -181,7 +176,7 @@ void Minimap::draw(gcn::Graphics *graphics)
graphics->fillRectangle(gcn::Rectangle(
(int) (pos.x * mProportion) / 32 + mapOriginX - offset,
- (int) (pos.x * mProportion) / 32 + mapOriginY - offset,
+ (int) (pos.y * mProportion) / 32 + mapOriginY - offset,
dotSize, dotSize));
}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 4dd8f05f..6046459c 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -1068,7 +1068,10 @@ void LocalPlayer::setXp(int xp)
const std::string text = toString(xp - mXp) + " xp";
// Show XP number
- particleEngine->addTextRiseFadeOutEffect(text, mPx + 16, mPy - 16,
+ particleEngine->addTextRiseFadeOutEffect(
+ text,
+ getPixelX() + 16,
+ getPixelY() - 16,
&guiPalette->getColor(Palette::EXP_INFO),
gui->getInfoParticleFont(), true);
}
@@ -1082,7 +1085,10 @@ void LocalPlayer::pickedUp(const std::string &item)
if (mMap)
{
// Show pickup notification
- particleEngine->addTextRiseFadeOutEffect(item, mPx + 16, mPy - 16,
+ particleEngine->addTextRiseFadeOutEffect(
+ item,
+ getPixelX() + 16,
+ getPixelY() - 16,
&guiPalette->getColor(Palette::PICKUP_INFO),
gui->getInfoParticleFont (), true);
}
diff --git a/src/monster.cpp b/src/monster.cpp
index eaea6225..f786471d 100644
--- a/src/monster.cpp
+++ b/src/monster.cpp
@@ -217,8 +217,9 @@ void Monster::setShowName(bool show)
if (show)
{
- mText = new Text(getInfo().getName(), mPx + NAME_X_OFFSET,
- mPy + NAME_Y_OFFSET - getHeight(),
+ mText = new Text(getInfo().getName(),
+ getPixelX() + NAME_X_OFFSET,
+ getPixelY() + NAME_Y_OFFSET - getHeight(),
gcn::Graphics::CENTER,
&guiPalette->getColor(Palette::MONSTER));
}
@@ -232,7 +233,7 @@ void Monster::updateCoords()
{
if (mText)
{
- mText->adviseXY(mPx + NAME_X_OFFSET,
- mPy + NAME_Y_OFFSET - getHeight());
+ mText->adviseXY(getPixelX() + NAME_X_OFFSET,
+ getPixelY() + NAME_Y_OFFSET - getHeight());
}
}
diff --git a/src/net/tmwserv/playerhandler.cpp b/src/net/tmwserv/playerhandler.cpp
index 863fcb65..f02ed4c1 100644
--- a/src/net/tmwserv/playerhandler.cpp
+++ b/src/net/tmwserv/playerhandler.cpp
@@ -322,6 +322,7 @@ void PlayerHandler::handleMapChangeMessage(MessageIn &msg)
player_node->setAction(Being::STAND);
player_node->setPosition(x, y);
+ player_node->setDestination(x, y);
logger->log("Adjust scrolling by %d,%d", (int) scrollOffsetX,
(int) scrollOffsetY);
diff --git a/src/npc.cpp b/src/npc.cpp
index d0a1a523..133f11c6 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -95,7 +95,9 @@ void NPC::setName(const std::string &name)
const std::string displayName = name.substr(0, name.find('#', 0));
delete mName;
- mName = new Text(displayName, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET,
+ mName = new Text(displayName,
+ getPixelX() + NAME_X_OFFSET,
+ getPixelY() + NAME_Y_OFFSET,
gcn::Graphics::CENTER,
&guiPalette->getColor(Palette::NPC));
Being::setName(displayName + " (NPC)");
@@ -142,14 +144,8 @@ void NPC::updateCoords()
{
if (mName)
{
-#ifdef TMWSERV_SUPPORT
- const Vector &pos = getPosition();
- const int px = (int) pos.x + NAME_X_OFFSET;
- const int py = (int) pos.y + NAME_Y_OFFSET;
-#else
- const int px = mPx + NAME_X_OFFSET;
- const int py = mPy + NAME_Y_OFFSET;
-#endif
+ const int px = getPixelX() + NAME_X_OFFSET;
+ const int py = getPixelY() + NAME_Y_OFFSET;
mName->adviseXY(px, py);
}
}
diff --git a/src/player.cpp b/src/player.cpp
index de4a012b..b966e891 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -58,14 +58,18 @@ void Player::setName(const std::string &name)
if (mIsGM)
{
mNameColor = &guiPalette->getColor(Palette::GM);
- mName = new FlashText("(GM) " + name, mPx + NAME_X_OFFSET, mPy +
- NAME_Y_OFFSET, gcn::Graphics::CENTER,
+ mName = new FlashText("(GM) " + name,
+ getPixelX() + NAME_X_OFFSET,
+ getPixelY() + NAME_Y_OFFSET,
+ gcn::Graphics::CENTER,
&guiPalette->getColor(Palette::GM_NAME));
}
else
{
mNameColor = &guiPalette->getColor(Palette::PLAYER);
- mName = new FlashText(name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET,
+ mName = new FlashText(name,
+ getPixelX() + NAME_X_OFFSET,
+ getPixelY() + NAME_Y_OFFSET,
gcn::Graphics::CENTER,
(this == player_node) ?
&guiPalette->getColor(Palette::SELF) :
@@ -233,7 +237,8 @@ void Player::setSprite(int slot, int id, const std::string &color)
void Player::updateCoords()
{
if (mName)
- mName->adviseXY(mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET);
+ mName->adviseXY(getPixelX() + NAME_X_OFFSET,
+ getPixelY() + NAME_Y_OFFSET);
}
#ifdef TMWSERV_SUPPORT
diff --git a/src/position.h b/src/position.h
index cbcf8c99..9cc86602 100644
--- a/src/position.h
+++ b/src/position.h
@@ -30,9 +30,6 @@
*/
struct Position
{
- /**
- * Constructor.
- */
Position(int x, int y):
x(x), y(y)
{ }