Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial revert of e7767ffb (the code that replaced min/max with clamp) #3334

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading