mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-10 23:48:04 +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;
|
std::pair<uint32_t, Point> firstAccepted;
|
||||||
uint32_t now = GH.input().getTicks();
|
uint32_t now = GH.input().getTicks();
|
||||||
for (auto & x : swipeHistory) {
|
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)
|
if(firstAccepted.first == 0)
|
||||||
firstAccepted = x;
|
firstAccepted = x;
|
||||||
diff += x.second;
|
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)
|
if(diff.length() > 0 && timediff > 0)
|
||||||
{
|
{
|
||||||
@ -157,13 +157,13 @@ void MapView::postSwipe(uint32_t msPassed) {
|
|||||||
swipeHistory.clear();
|
swipeHistory.clear();
|
||||||
} else
|
} else
|
||||||
postSwipeSpeed = 0.0;
|
postSwipeSpeed = 0.0;
|
||||||
if(postSwipeSpeed > 0.1) {
|
if(postSwipeSpeed > postSwipeMinimalSpeed) {
|
||||||
double len = postSwipeSpeed * static_cast<double>(msPassed);
|
double len = postSwipeSpeed * static_cast<double>(msPassed);
|
||||||
Point delta = Point(len * cos(postSwipeAngle), len * sin(postSwipeAngle));
|
Point delta = Point(len * cos(postSwipeAngle), len * sin(postSwipeAngle));
|
||||||
|
|
||||||
controller->setViewCenter(model->getMapViewCenter() + delta, model->getLevel());
|
controller->setViewCenter(model->getMapViewCenter() + delta, model->getLevel());
|
||||||
|
|
||||||
postSwipeSpeed /= 1 + msPassed * 0.006;
|
postSwipeSpeed /= 1 + msPassed * postSwipeSlowdownSpeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +53,10 @@ class MapView : public BasicMapView
|
|||||||
double postSwipeAngle = 0.0;
|
double postSwipeAngle = 0.0;
|
||||||
double postSwipeSpeed = 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);
|
void postSwipe(uint32_t msPassed);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user