Michael преди 2 години
родител
ревизия
b77bccdc24
променени са 2 файла, в които са добавени 8 реда и са изтрити 4 реда
  1. 4 4
      client/mapView/MapView.cpp
  2. 4 0
      client/mapView/MapView.h

+ 4 - 4
client/mapView/MapView.cpp

@@ -139,14 +139,14 @@ void MapView::postSwipe(uint32_t msPassed) {
 			std::pair<uint32_t, Point> firstAccepted;
 			uint32_t now = GH.input().getTicks();
 			for (auto & x : swipeHistory) {
-				if(now - x.first < 150) { // only the last 150 ms are catched
+				if(now - x.first < postSwipeCatchIntervalMs) { // only the last x ms are catched
 					if(firstAccepted.first == 0)
 						firstAccepted = x;
 					diff += x.second;
 				}
 			}
 
-			uint32_t timediff = swipeHistory.rbegin()->first - firstAccepted.first;
+			uint32_t timediff = swipeHistory.back().first - firstAccepted.first;
 
 			if(diff.length() > 0 && timediff > 0)
 			{
@@ -157,13 +157,13 @@ void MapView::postSwipe(uint32_t msPassed) {
 		swipeHistory.clear();
 	} else
 		postSwipeSpeed = 0.0;
-	if(postSwipeSpeed > 0.1) {
+	if(postSwipeSpeed > postSwipeMinimalSpeed) {
 		double len = postSwipeSpeed * static_cast<double>(msPassed);
 		Point delta = Point(len * cos(postSwipeAngle), len * sin(postSwipeAngle));
 
 		controller->setViewCenter(model->getMapViewCenter() + delta, model->getLevel());
 
-		postSwipeSpeed /= 1 + msPassed * 0.006;
+		postSwipeSpeed /= 1 + msPassed * postSwipeSlowdownSpeed;
 	}
 }
 

+ 4 - 0
client/mapView/MapView.h

@@ -52,6 +52,10 @@ class MapView : public BasicMapView
 	std::vector<std::pair<uint32_t, Point>> swipeHistory;
 	double postSwipeAngle = 0.0;
 	double postSwipeSpeed = 0.0;
+	
+	const int postSwipeCatchIntervalMs = 150;
+	const double postSwipeSlowdownSpeed = 0.006;
+	const double postSwipeMinimalSpeed = 0.1;
 
 	void postSwipe(uint32_t msPassed);