From fae2dd034462c5a6b086e46b3437ea6e2456d5eb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 19 Apr 2018 23:01:50 -0400 Subject: [PATCH] math_util: Remove the Clamp() function C++17 adds clamp() to the standard library, so we can remove ours in favor of it. --- src/common/math_util.h | 5 ---- src/core/perf_stats.cpp | 3 ++- src/input_common/motion_emu.cpp | 5 ++-- .../renderer_opengl/gl_rasterizer.cpp | 25 ++++++++++--------- .../renderer_opengl/gl_rasterizer_cache.cpp | 8 +++--- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/common/math_util.h b/src/common/math_util.h index 45a1ed3670..c6a83c9539 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h @@ -17,11 +17,6 @@ inline bool IntervalsIntersect(unsigned start0, unsigned length0, unsigned start return (std::max(start0, start1) < std::min(start0 + length0, start1 + length1)); } -template -inline T Clamp(const T val, const T& min, const T& max) { - return std::max(min, std::min(max, val)); -} - template struct Rectangle { T left; diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp index ad3b56fcc8..5f53b16d34 100644 --- a/src/core/perf_stats.cpp +++ b/src/core/perf_stats.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include #include @@ -87,7 +88,7 @@ void FrameLimiter::DoFrameLimiting(u64 current_system_time_us) { frame_limiting_delta_err += microseconds(current_system_time_us - previous_system_time_us); frame_limiting_delta_err -= duration_cast(now - previous_walltime); frame_limiting_delta_err = - MathUtil::Clamp(frame_limiting_delta_err, -MAX_LAG_TIME_US, MAX_LAG_TIME_US); + std::clamp(frame_limiting_delta_err, -MAX_LAG_TIME_US, MAX_LAG_TIME_US); if (frame_limiting_delta_err > microseconds::zero()) { std::this_thread::sleep_for(frame_limiting_delta_err); diff --git a/src/input_common/motion_emu.cpp b/src/input_common/motion_emu.cpp index 59a035e701..caffe48cbd 100644 --- a/src/input_common/motion_emu.cpp +++ b/src/input_common/motion_emu.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include #include @@ -43,8 +44,8 @@ public: tilt_angle = 0; } else { tilt_direction = mouse_move.Cast(); - tilt_angle = MathUtil::Clamp(tilt_direction.Normalize() * sensitivity, 0.0f, - MathUtil::PI * 0.5f); + tilt_angle = + std::clamp(tilt_direction.Normalize() * sensitivity, 0.0f, MathUtil::PI * 0.5f); } } } diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 13e2a77cec..1705485288 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include #include @@ -290,18 +291,18 @@ void RasterizerOpenGL::DrawArrays() { : (depth_surface == nullptr ? 1u : depth_surface->res_scale); MathUtil::Rectangle draw_rect{ - static_cast(MathUtil::Clamp(static_cast(surfaces_rect.left) + - viewport_rect.left * res_scale, - surfaces_rect.left, surfaces_rect.right)), // Left - static_cast(MathUtil::Clamp(static_cast(surfaces_rect.bottom) + - viewport_rect.top * res_scale, - surfaces_rect.bottom, surfaces_rect.top)), // Top - static_cast(MathUtil::Clamp(static_cast(surfaces_rect.left) + - viewport_rect.right * res_scale, - surfaces_rect.left, surfaces_rect.right)), // Right - static_cast(MathUtil::Clamp(static_cast(surfaces_rect.bottom) + - viewport_rect.bottom * res_scale, - surfaces_rect.bottom, surfaces_rect.top))}; // Bottom + static_cast( + std::clamp(static_cast(surfaces_rect.left) + viewport_rect.left * res_scale, + surfaces_rect.left, surfaces_rect.right)), // Left + static_cast( + std::clamp(static_cast(surfaces_rect.bottom) + viewport_rect.top * res_scale, + surfaces_rect.bottom, surfaces_rect.top)), // Top + static_cast( + std::clamp(static_cast(surfaces_rect.left) + viewport_rect.right * res_scale, + surfaces_rect.left, surfaces_rect.right)), // Right + static_cast(std::clamp(static_cast(surfaces_rect.bottom) + + viewport_rect.bottom * res_scale, + surfaces_rect.bottom, surfaces_rect.top))}; // Bottom // Bind the framebuffer surfaces BindFramebufferSurfaces(color_surface, depth_surface, has_stencil); diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 561c6913d5..6c1c6775ad 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -1086,10 +1086,10 @@ SurfaceSurfaceRect_Tuple RasterizerCacheOpenGL::GetFramebufferSurfaces( } MathUtil::Rectangle viewport_clamped{ - static_cast(MathUtil::Clamp(viewport.left, 0, static_cast(config.width))), - static_cast(MathUtil::Clamp(viewport.top, 0, static_cast(config.height))), - static_cast(MathUtil::Clamp(viewport.right, 0, static_cast(config.width))), - static_cast(MathUtil::Clamp(viewport.bottom, 0, static_cast(config.height)))}; + static_cast(std::clamp(viewport.left, 0, static_cast(config.width))), + static_cast(std::clamp(viewport.top, 0, static_cast(config.height))), + static_cast(std::clamp(viewport.right, 0, static_cast(config.width))), + static_cast(std::clamp(viewport.bottom, 0, static_cast(config.height)))}; // get color and depth surfaces SurfaceParams color_params;