diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-05-04 22:16:16 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-05-04 22:16:16 +0200 |
commit | 315d07f03ad557223906c2becf9a0f12e00e2bcb (patch) | |
tree | 4c567c06600f651dc6ce405f39bea0c9b4f9f2dc | |
parent | 455a7593fae3bbd1870165583598b50a2ae533b5 (diff) | |
download | mana-315d07f03ad557223906c2becf9a0f12e00e2bcb.tar.gz mana-315d07f03ad557223906c2becf9a0f12e00e2bcb.tar.bz2 mana-315d07f03ad557223906c2becf9a0f12e00e2bcb.tar.xz mana-315d07f03ad557223906c2becf9a0f12e00e2bcb.zip |
Made the client show much more path debug information.
First of all, the mouse path is only computed when necessary,
This will save a bit of CPU when in debug view.
Secondly, every being paths, collision radius, and position
are graphically represented now.
This will help code and content developers when checking their
sprite offsets.
Reviewed-by: CodyMartin.
-rw-r--r-- | src/gui/viewport.cpp | 99 |
1 files changed, 68 insertions, 31 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index f6166c8f..cc316e88 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -296,17 +296,6 @@ void Viewport::_drawDebugPath(Graphics *graphics) // Get the current mouse position SDL_GetMouseState(&mMouseX, &mMouseY); - Path debugPath; - - 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)); - // Prepare the walkmask corresponding to the protocol unsigned char walkMask = 0; switch (Net::getNetworkType()) @@ -320,31 +309,79 @@ void Viewport::_drawDebugPath(Graphics *graphics) break; } - // Adapt the path finding to the precision requested - if (Net::getPlayerHandler()->usePixelPrecision()) - { - debugPath = mMap->findPixelPath( - (int) playerPos.x, - (int) playerPos.y, - mMouseX + (int) mPixelViewX, - mMouseY + (int) mPixelViewY, - playerRadius, walkMask); - } - else + static Path debugPath; + static Vector lastMouseDestination = Vector(0.0f, 0.0f); + Vector mouseDestination(mMouseX + (int) mPixelViewX, + mMouseY + (int) mPixelViewY); + + if (mouseDestination.x != lastMouseDestination.x + || mouseDestination.y != lastMouseDestination.y) { - debugPath = mMap->findTilePath( - (int) playerPos.x, - (int) playerPos.y, - mMouseX + (int) mPixelViewX, - mMouseY + (int) mPixelViewY, - walkMask); + const Vector &playerPos = player_node->getPosition(); + + // Adapt the path finding to the precision requested + if (Net::getPlayerHandler()->usePixelPrecision()) + { + debugPath = mMap->findPixelPath((int) playerPos.x, + (int) playerPos.y, + mouseDestination.x, + mouseDestination.y, + player_node->getCollisionRadius(), + walkMask); + } + else + { + debugPath = mMap->findTilePath((int) playerPos.x, + (int) playerPos.y, + mouseDestination.x, + mouseDestination.y, + walkMask); + } + + lastMouseDestination = mouseDestination; } // We draw the path proposed by mouse - _drawPath(graphics, debugPath, gcn::Color(128, 0, 128)); + _drawPath(graphics, debugPath, gcn::Color(128, 0, 128, 150)); + + // Draw the path debug information for every beings. + ActorSpritesConstIterator it, it_end; + const ActorSprites &actors = actorSpriteManager->getAll(); + for (it = actors.begin(), it_end = actors.end() ; it != it_end; it++) + { + Being *being = dynamic_cast<Being*>(*it); + if (being) + { + const Vector &beingPos = being->getPosition(); + int radius = being->getCollisionRadius(); + Path beingPath = being->getPath(); + + // Draw being collision rectangle + graphics->setColor(gcn::Color(128, 128, 0, 150)); + graphics->fillRectangle(gcn::Rectangle( + (int) beingPos.x + - (int) mPixelViewX - radius, + (int) beingPos.y - (int) mPixelViewY + - radius, + radius * 2, radius * 2)); + + _drawPath(graphics, + beingPath, + gcn::Color(0, 0, 255, 150)); + + // Draw also the absolute x, y position using a cross. + graphics->setColor(gcn::Color(0, 0, 255, 255)); + graphics->drawLine((int) beingPos.x - (int) mPixelViewX - 4, + (int) beingPos.y - (int) mPixelViewY - 4, + (int) beingPos.x - (int) mPixelViewX + 4, + (int) beingPos.y - (int) mPixelViewY + 4); + graphics->drawLine((int) beingPos.x - (int) mPixelViewX + 4, + (int) beingPos.y - (int) mPixelViewY - 4, + (int) beingPos.x - (int) mPixelViewX - 4, + (int) beingPos.y - (int) mPixelViewY + 4); - // 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, |