Skip to content

Commit

Permalink
Merge pull request #3334 from Ghabry/issue-3333
Browse files Browse the repository at this point in the history
Partial revert of e7767ff (the code that replaced min/max with clamp)
  • Loading branch information
fdelapena authored Jan 22, 2025
2 parents f787328 + 576cb9a commit e374637
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/game_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,9 @@ void Game_Map::Scroll(int dx, int dy) {
// that acc changed by.
static void ClampingAdd(int low, int high, int& acc, int& inc) {
int original_acc = acc;
acc = std::clamp(acc + inc, low, high);
// Do not use std::clamp here. When the map is smaller than the screen the
// upper bound is smaller than the lower bound making the function fail.
acc = std::max(low, std::min(high, acc + inc));
inc = acc - original_acc;
}

Expand Down Expand Up @@ -1648,7 +1650,9 @@ void Game_Map::SetPositionX(int x, bool reset_panorama) {
if (LoopHorizontal()) {
x = Utils::PositiveModulo(x, map_width);
} else {
x = std::clamp(x, 0, map_width - screen_width);
// Do not use std::clamp here. When the map is smaller than the screen the
// upper bound is smaller than the lower bound making the function fail.
x = std::max(0, std::min(map_width - screen_width, x));
}
map_info.position_x = x;
if (reset_panorama) {
Expand All @@ -1670,7 +1674,9 @@ void Game_Map::SetPositionY(int y, bool reset_panorama) {
if (LoopVertical()) {
y = Utils::PositiveModulo(y, map_height);
} else {
y = std::clamp(y, 0, map_height - screen_height);
// Do not use std::clamp here. When the map is smaller than the screen the
// upper bound is smaller than the lower bound making the function fail.
y = std::max(0, std::min(map_height - screen_height, y));
}
map_info.position_y = y;
if (reset_panorama) {
Expand Down

0 comments on commit e374637

Please sign in to comment.