mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
code review
This commit is contained in:
parent
d1d0d6d62e
commit
b77bccdc24
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user