diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-03-15 17:28:16 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-03-15 17:28:16 +0100 |
commit | 21e8d502d07c6cae9580a34dde7587d58e6d3a28 (patch) | |
tree | fd8c9fa711d0e2e60f50333f82dbe43ebd9214a5 /src/gui/viewport.cpp | |
parent | 25a2abd09e3b76115ed0b6b1a02cdddc6c1c5bfc (diff) | |
download | mana-21e8d502d07c6cae9580a34dde7587d58e6d3a28.tar.gz mana-21e8d502d07c6cae9580a34dde7587d58e6d3a28.tar.bz2 mana-21e8d502d07c6cae9580a34dde7587d58e6d3a28.tar.xz mana-21e8d502d07c6cae9580a34dde7587d58e6d3a28.zip |
Basically merged the two movement algorithms into one.
This was made in favour of the manaserv way of doing things.
I also added a way to keep the original server speed value
so the pixel value can be recomputed at each map change, as this
was necessary since the speed is given before the first map
is loaded.
The code is much more simpler now about movement handling,
and we can already see improvements on other characters
movements in The Mana World with this.
Everything can't be perfect the first time; here are bugs
identified so far:
- Monsters direction isn't updated on TmwAthena for obscure reasons.
- Remote players walking animation is sometimes reset on each steps.
- When changing map, the local player sometimes walks randomly
until the player reacts.
Stay tuned!
Diffstat (limited to 'src/gui/viewport.cpp')
-rw-r--r-- | src/gui/viewport.cpp | 119 |
1 files changed, 35 insertions, 84 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index ac910d5f..459edab5 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -261,43 +261,27 @@ void Viewport::_drawDebugPath(Graphics *graphics) Path debugPath; - if (Net::getNetworkType() == ServerInfo::TMWATHENA) - { - const int mouseTileX = (mMouseX + (int) mPixelViewX) / 32; - const int mouseTileY = (mMouseY + (int) mPixelViewY) / 32; - const Vector &playerPos = player_node->getPosition(); - - debugPath = mMap->findPath( - (int) (playerPos.x - 16) / 32, - (int) (playerPos.y - 32) / 32, - mouseTileX, mouseTileY, 0xFF); - - _drawPath(graphics, debugPath); - } - else if (Net::getNetworkType() == ServerInfo::MANASERV) - { - const Vector &playerPos = player_node->getPosition(); - const int playerRadius = player_node->getCollisionRadius(); - // Draw player collision rectangle - graphics->setColor(gcn::Color(128, 128, 0, 120)); - graphics->fillRectangle( - gcn::Rectangle((int) playerPos.x - (int) mPixelViewX - playerRadius, - (int) playerPos.y - (int) mPixelViewY - playerRadius, - playerRadius * 2, playerRadius * 2)); - - debugPath = mMap->findPixelPath( - (int) playerPos.x, - (int) playerPos.y, - mMouseX + (int) mPixelViewX, - mMouseY + (int) mPixelViewY, - playerRadius, 0xFF); - - // We draw the path proposed by mouse - _drawPath(graphics, debugPath, gcn::Color(128, 0, 128)); - - // But also the one currently walked on. - _drawPath(graphics, player_node->getPath(), gcn::Color(0, 0, 255)); - } + const Vector &playerPos = player_node->getPosition(); + const int playerRadius = player_node->getCollisionRadius(); + // Draw player collision rectangle + graphics->setColor(gcn::Color(128, 128, 0, 120)); + graphics->fillRectangle( + gcn::Rectangle((int) playerPos.x - (int) mPixelViewX - playerRadius, + (int) playerPos.y - (int) mPixelViewY - playerRadius, + playerRadius * 2, playerRadius * 2)); + + debugPath = mMap->findPixelPath( + (int) playerPos.x, + (int) playerPos.y, + mMouseX + (int) mPixelViewX, + mMouseY + (int) mPixelViewY, + playerRadius, 0xFF); + + // We draw the path proposed by mouse + _drawPath(graphics, debugPath, gcn::Color(128, 0, 128)); + + // But also the one currently walked on. + _drawPath(graphics, player_node->getPath(), gcn::Color(0, 0, 255)); } void Viewport::_drawPath(Graphics *graphics, const Path &path, @@ -305,33 +289,16 @@ void Viewport::_drawPath(Graphics *graphics, const Path &path, { graphics->setColor(color); - if (Net::getNetworkType() == ServerInfo::TMWATHENA) + for (Path::const_iterator i = path.begin(); i != path.end(); ++i) { - for (Path::const_iterator i = path.begin(); i != path.end(); ++i) - { - int squareX = i->x * 32 - (int) mPixelViewX + 12; - int squareY = i->y * 32 - (int) mPixelViewY + 12; - - graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8)); - graphics->drawText( - toString(mMap->getMetaTile(i->x, i->y)->Gcost), - squareX + 4, squareY + 12, gcn::Graphics::CENTER); - } - } - else if (Net::getNetworkType() == ServerInfo::MANASERV) - { - for (Path::const_iterator i = path.begin(); i != path.end(); ++i) - { - int squareX = i->x - (int) mPixelViewX; - int squareY = i->y - (int) mPixelViewY; - - graphics->fillRectangle(gcn::Rectangle(squareX - 4, squareY - 4, - 8, 8)); - graphics->drawText( - toString(mMap->getMetaTile(i->x / 32, i->y / 32)->Gcost), - squareX + 4, squareY + 12, gcn::Graphics::CENTER); - } - + int squareX = i->x - (int) mPixelViewX; + int squareY = i->y - (int) mPixelViewY; + + graphics->fillRectangle(gcn::Rectangle(squareX - 4, squareY - 4, + 8, 8)); + graphics->drawText( + toString(mMap->getMetaTile(i->x / 32, i->y / 32)->Gcost), + squareX + 4, squareY + 12, gcn::Graphics::CENTER); } } @@ -441,25 +408,12 @@ void Viewport::mouseDragged(gcn::MouseEvent &event) if (mPlayerFollowMouse && !event.isShiftPressed()) { - if (Net::getNetworkType() == ServerInfo::MANASERV) + if (get_elapsed_time(mLocalWalkTime) >= walkingMouseDelay) { - if (get_elapsed_time(mLocalWalkTime) >= walkingMouseDelay) - { - mLocalWalkTime = tick_time; - player_node->setDestination(event.getX() + (int) mPixelViewX, - event.getY() + (int) mPixelViewY); - player_node->pathSetByMouse(); - } - } - else - { - if (mLocalWalkTime != player_node->getActionTime()) - { - mLocalWalkTime = player_node->getActionTime(); - int destX = (event.getX() + mPixelViewX) / mMap->getTileWidth(); - int destY = (event.getY() + mPixelViewY) / mMap->getTileHeight(); - player_node->setDestination(destX, destY); - } + mLocalWalkTime = tick_time; + player_node->setDestination(event.getX() + (int) mPixelViewX, + event.getY() + (int) mPixelViewY); + player_node->pathSetByMouse(); } } } @@ -467,9 +421,6 @@ void Viewport::mouseDragged(gcn::MouseEvent &event) void Viewport::mouseReleased(gcn::MouseEvent &event) { mPlayerFollowMouse = false; - - // Only useful for eAthena but doesn't hurt under ManaServ - mLocalWalkTime = -1; } void Viewport::showPopup(Window *parent, int x, int y, Item *item, |