From f43ce278866a2c42f67f75972c2e4abe46f8fd82 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Thu, 17 Apr 2008 20:14:24 +0000 Subject: Moved walking calls flooding control when dragging mouse to viewport. --- src/gui/viewport.cpp | 26 +++++++++++++++----------- src/gui/viewport.h | 4 ++++ 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'src/gui') 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 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. */ }; -- cgit v1.2.3-70-g09d2