diff options
author | Yohann Ferreira <bertram@cegetel.net> | 2008-04-17 20:14:24 +0000 |
---|---|---|
committer | Yohann Ferreira <bertram@cegetel.net> | 2008-04-17 20:14:24 +0000 |
commit | f43ce278866a2c42f67f75972c2e4abe46f8fd82 (patch) | |
tree | 95650923c9ba0bde20fe8eea86981c6d733124e7 /src/gui | |
parent | 346442e0aa15705910dd12e61e2a662fba0fced6 (diff) | |
download | mana-f43ce278866a2c42f67f75972c2e4abe46f8fd82.tar.gz mana-f43ce278866a2c42f67f75972c2e4abe46f8fd82.tar.bz2 mana-f43ce278866a2c42f67f75972c2e4abe46f8fd82.tar.xz mana-f43ce278866a2c42f67f75972c2e4abe46f8fd82.zip |
Moved walking calls flooding control when dragging mouse to viewport.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/viewport.cpp | 26 | ||||
-rw-r--r-- | src/gui/viewport.h | 4 |
2 files changed, 19 insertions, 11 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 1b6cfa1c..a8fd452c 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -49,13 +49,15 @@ #include <cassert> extern volatile int tick_time; +extern int get_elapsed_time(int start_time); Viewport::Viewport(): mMap(0), mViewX(0.0f), mViewY(0.0f), mShowDebugPath(false), - mPlayerFollowMouse(false) + mPlayerFollowMouse(false), + mLocalWalkTime(-1) { setOpaque(false); addMouseListener(this); @@ -251,11 +253,12 @@ Viewport::logic() Uint8 button = SDL_GetMouseState(&mouseX, &mouseY); if (mPlayerFollowMouse && button & SDL_BUTTON(1) && - mWalkTime != player_node->mWalkTime) + mWalkTime != player_node->mWalkTime && + get_elapsed_time(mLocalWalkTime) >= walkingMouseDelay) { + mLocalWalkTime = tick_time; player_node->setDestination(mouseX + (int) mViewX, - mouseY + (int) mViewY, - BY_MOUSE); + mouseY + (int) mViewY); mWalkTime = player_node->mWalkTime; } @@ -399,12 +402,12 @@ Viewport::mousePressed(gcn::MouseEvent &event) { // FIXME: REALLY UGLY! Uint8 *keys = SDL_GetKeyState(NULL); - if (!(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT])) + if (!(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]) && + get_elapsed_time(mLocalWalkTime) >= walkingMouseDelay) { - + mLocalWalkTime = tick_time; player_node->setDestination(event.getX() + (int) mViewX, - event.getY() + (int) mViewY, - BY_MOUSE); + event.getY() + (int) mViewY); } mPlayerFollowMouse = true; } @@ -429,11 +432,12 @@ Viewport::mouseDragged(gcn::MouseEvent &event) if (!mMap || !player_node) return; - if (mPlayerFollowMouse && mWalkTime == player_node->mWalkTime) + if (mPlayerFollowMouse && mWalkTime == player_node->mWalkTime + && get_elapsed_time(mLocalWalkTime) >= walkingMouseDelay) { + mLocalWalkTime = tick_time; player_node->setDestination(event.getX() + (int) mViewX, - event.getY() + (int) mViewY, - BY_MOUSE); + event.getY() + (int) mViewY); } } diff --git a/src/gui/viewport.h b/src/gui/viewport.h index c8f7a9ec..cb47b5fe 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -39,6 +39,9 @@ class PopupMenu; class Graphics; class SimpleAnimation; +/** Delay between two mouse calls when dragging mouse and move the player */ +const int walkingMouseDelay = 500; + /** * The viewport on the map. Displays the current map and handles mouse input * and the popup menu. @@ -182,6 +185,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener, bool mPlayerFollowMouse; int mWalkTime; + int mLocalWalkTime; /**< Timestamp before the next walk can be sent. */ PopupMenu *mPopupMenu; /**< Popup menu. */ }; |