diff --git a/es-app/src/SystemScreensaver.cpp b/es-app/src/SystemScreensaver.cpp index 7698171db..9d43826aa 100644 --- a/es-app/src/SystemScreensaver.cpp +++ b/es-app/src/SystemScreensaver.cpp @@ -256,8 +256,8 @@ void SystemScreensaver::renderScreensaver() if (mVideoScreensaver && screensaverType == "video") { // Render a black background below the video. Renderer::setMatrix(Transform4x4f::Identity()); - Renderer::drawRect(0.0f, 0.0f, Renderer::getScreenWidth(), - Renderer::getScreenHeight(), 0x000000FF, 0x000000FF); + Renderer::drawRect(0.0f, 0.0f, static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF); // Only render the video if the state requires it. if (static_cast(mState) >= STATE_FADE_IN_VIDEO) { @@ -268,8 +268,8 @@ void SystemScreensaver::renderScreensaver() else if (mImageScreensaver && screensaverType == "slideshow") { // Render a black background below the image. Renderer::setMatrix(Transform4x4f::Identity()); - Renderer::drawRect(0.0f, 0.0f, Renderer::getScreenWidth(), - Renderer::getScreenHeight(), 0x000000FF, 0x000000FF); + Renderer::drawRect(0.0f, 0.0f, static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF); // Only render the image if the state requires it. if (static_cast(mState) >= STATE_FADE_IN_VIDEO) { @@ -319,7 +319,7 @@ void SystemScreensaver::renderScreensaver() Renderer::getScreenHeight(), 0x000000FF, 0x000000FF, mDimValue); #endif if (mDimValue > 0.0) - mDimValue = Math::clamp(mDimValue-0.045, 0.0, 1.0); + mDimValue = Math::clamp(mDimValue - 0.045f, 0.0f, 1.0f); } } if (Settings::getInstance()->getString("ScreensaverType") == "video") { @@ -361,7 +361,7 @@ void SystemScreensaver::renderScreensaver() Renderer::getScreenHeight(), 0x000000FF, 0x000000FF, mDimValue); #endif if (mDimValue > 0.0) - mDimValue = Math::clamp(mDimValue-0.045, 0.0, 1.0); + mDimValue = Math::clamp(mDimValue - 0.045f, 0.0f, 1.0f); } } @@ -371,11 +371,11 @@ void SystemScreensaver::renderScreensaver() dimParameters.fragmentDimValue = mDimValue; Renderer::shaderPostprocessing(Renderer::SHADER_DIM, dimParameters); if (mDimValue > 0.4) - mDimValue = Math::clamp(mDimValue-0.021, 0.4, 1.0); + mDimValue = Math::clamp(mDimValue - 0.021f, 0.4f, 1.0f); dimParameters.fragmentSaturation = mSaturationAmount; Renderer::shaderPostprocessing(Renderer::SHADER_DESATURATE, dimParameters); if (mSaturationAmount > 0.0) - mSaturationAmount = Math::clamp(mSaturationAmount-0.035, 0.0, 1.0); + mSaturationAmount = Math::clamp(mSaturationAmount - 0.035f, 0.0f, 1.0f); #else Renderer::drawRect(0.0f, 0.0f, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x000000A0, 0x000000A0); @@ -387,7 +387,7 @@ void SystemScreensaver::renderScreensaver() blackParameters.fragmentDimValue = mDimValue; Renderer::shaderPostprocessing(Renderer::SHADER_DIM, blackParameters); if (mDimValue > 0.0) - mDimValue = Math::clamp(mDimValue-0.045, 0.0, 1.0); + mDimValue = Math::clamp(mDimValue - 0.045f, 0.0f, 1.0f); #else Renderer::drawRect(0.0f, 0.0f, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x000000FF, 0x000000FF); @@ -515,7 +515,8 @@ void SystemScreensaver::pickRandomImage(std::string& path) std::random_device randDev; // Mersenne Twister pseudorandom number generator. std::mt19937 engine{randDev()}; - std::uniform_int_distribution uniform_dist(0, mImageFiles.size() - 1); + std::uniform_int_distribution + uniform_dist(0, static_cast(mImageFiles.size()) - 1); index = uniform_dist(engine); } while (mPreviousGame && mImageFiles.at(index) == mPreviousGame); @@ -546,7 +547,8 @@ void SystemScreensaver::pickRandomVideo(std::string& path) std::random_device randDev; // Mersenne Twister pseudorandom number generator. std::mt19937 engine{randDev()}; - std::uniform_int_distribution uniform_dist(0, mVideoFiles.size() - 1); + std::uniform_int_distribution + uniform_dist(0, static_cast(mVideoFiles.size()) - 1); index = uniform_dist(engine); } while (mPreviousGame && mVideoFiles.at(index) == mPreviousGame); @@ -574,7 +576,8 @@ void SystemScreensaver::pickRandomCustomImage(std::string& path) std::random_device randDev; // Mersenne Twister pseudorandom number generator. std::mt19937 engine{randDev()}; - std::uniform_int_distribution uniform_dist(0, mImageCustomFiles.size() - 1); + std::uniform_int_distribution + uniform_dist(0, static_cast(mImageCustomFiles.size()) - 1); index = uniform_dist(engine); } while (mPreviousCustomImage != "" && mImageCustomFiles.at(index) == mPreviousCustomImage); @@ -590,8 +593,8 @@ void SystemScreensaver::generateOverlayInfo() if (mGameName == "" || mSystemName == "") return; - float posX = static_cast(Renderer::getWindowWidth()) * 0.023; - float posY = static_cast(Renderer::getWindowHeight()) * 0.02; + float posX = static_cast(Renderer::getWindowWidth()) * 0.023f; + float posY = static_cast(Renderer::getWindowHeight()) * 0.02f; std::string favoriteChar; if (mCurrentGame->getFavorite()) @@ -618,7 +621,7 @@ void SystemScreensaver::generateOverlayInfo() else textSizeX = mGameOverlayFont[0].get()->sizeText(systemName).x(); - float marginX = Renderer::getWindowWidth() * 0.01; + float marginX = Renderer::getWindowWidth() * 0.01f; mGameOverlayRectangleCoords.clear(); mGameOverlayRectangleCoords.push_back(posX - marginX); diff --git a/es-core/src/AudioManager.cpp b/es-core/src/AudioManager.cpp index 8c83c7a6a..f1d643024 100644 --- a/es-core/src/AudioManager.cpp +++ b/es-core/src/AudioManager.cpp @@ -152,7 +152,7 @@ void AudioManager::mixAudio(void* /*unused*/, Uint8* stream, int len) // Mix sample into stream. SDL_MixAudioFormat(stream, &(sound->getData()[sound->getPosition()]), sAudioFormat.format, restLength, - Settings::getInstance()->getInt("SoundVolumeNavigation") * 1.28); + Settings::getInstance()->getInt("SoundVolumeNavigation") * 1.28f); if (sound->getPosition() + restLength < sound->getLength()) { // Sample hasn't ended yet. stillPlaying = true; diff --git a/es-core/src/GuiComponent.cpp b/es-core/src/GuiComponent.cpp index 8da686e11..bea0e02e8 100644 --- a/es-core/src/GuiComponent.cpp +++ b/es-core/src/GuiComponent.cpp @@ -245,7 +245,7 @@ int GuiComponent::getChildIndex() const std::find(getParent()->mChildren.begin(), getParent()->mChildren.end(), this); if (it != getParent()->mChildren.end()) - return std::distance(getParent()->mChildren.begin(), it); + return static_cast(std::distance(getParent()->mChildren.begin(), it)); else return -1; } @@ -295,7 +295,7 @@ void GuiComponent::setColor(unsigned int color) float GuiComponent::getSaturation() const { - return mColor; + return static_cast(mColor); } void GuiComponent::setSaturation(float saturation) diff --git a/es-core/src/HttpReq.cpp b/es-core/src/HttpReq.cpp index ca8822071..b9c998074 100644 --- a/es-core/src/HttpReq.cpp +++ b/es-core/src/HttpReq.cpp @@ -32,7 +32,7 @@ std::string HttpReq::urlEncode(const std::string &s) else { escaped.append("%"); char buf[3]; - sprintf(buf, "%.2X", static_cast(s[i])); + snprintf(buf, 3, "%.2X", static_cast(s[i])); escaped.append(buf); } } diff --git a/es-core/src/Window.cpp b/es-core/src/Window.cpp index fa1867a25..f2c21fa2c 100644 --- a/es-core/src/Window.cpp +++ b/es-core/src/Window.cpp @@ -275,7 +275,7 @@ void Window::update(int deltaTime) textureTotalUsageMiB << " MiB"; mFrameDataText = std::unique_ptr (mDefaultFonts.at(0)->buildTextCache(ss.str(), Renderer::getScreenWidth() * - 0.02 , Renderer::getScreenHeight() * 0.02, 0xFF00FFFF, 1.3)); + 0.02f, Renderer::getScreenHeight() * 0.02f, 0xFF00FFFF, 1.3f)); } mFrameTimeElapsed = 0; @@ -341,7 +341,7 @@ void Window::render() // it with the blurring leads to very strange and severe artifacts. // This is for sure a bug that needs to be resolved at some later date. Renderer::shaderParameters blackParameters; - blackParameters.fragmentDimValue = 0.6; + blackParameters.fragmentDimValue = 0.6f; Renderer::shaderPostprocessing(Renderer::SHADER_DIM, blackParameters, processedTexture); @@ -375,7 +375,7 @@ void Window::render() // Menu opening effects (scale-up and fade-in). if (Settings::getInstance()->getString("MenuOpeningEffect") == "scale-up") { if (mTopScale < 1.0) - mTopScale = Math::clamp(mTopScale+0.07, 0, 1.0); + mTopScale = Math::clamp(mTopScale + 0.07f, 0.0f, 1.0f); Vector2f topCenter = top->getCenter(); top->setOrigin({0.5, 0.5}); top->setPosition({topCenter.x(), topCenter.y(), 0}); @@ -458,8 +458,8 @@ void Window::renderLoadingScreen(std::string text) { Transform4x4f trans = Transform4x4f::Identity(); Renderer::setMatrix(trans); - Renderer::drawRect(0.0f, 0.0f, Renderer::getScreenWidth(), - Renderer::getScreenHeight(), 0x000000FF, 0x000000FF); + Renderer::drawRect(0.0f, 0.0f, static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF); ImageComponent splash(this, true); splash.setResize(Renderer::getScreenWidth() * 0.6f, 0.0f); diff --git a/es-core/src/components/VideoComponent.cpp b/es-core/src/components/VideoComponent.cpp index 68fad2766..143e4307d 100644 --- a/es-core/src/components/VideoComponent.cpp +++ b/es-core/src/components/VideoComponent.cpp @@ -292,9 +292,9 @@ void VideoComponent::update(int deltaTime) // video screensaver that is running, or if it's the video in the gamelist. if (mScreensaverMode && mFadeIn < 1.0f) mFadeIn = Math::clamp(mFadeIn + (deltaTime / - static_cast(SCREENSAVER_FADE_IN_TIME)), 0.0, 1.0); + static_cast(SCREENSAVER_FADE_IN_TIME)), 0.0f, 1.0f); else if (mFadeIn < 1.0f) - mFadeIn = Math::clamp(mFadeIn + 0.01, 0.0f, 1.0f); + mFadeIn = Math::clamp(mFadeIn + 0.01f, 0.0f, 1.0f); GuiComponent::update(deltaTime); } diff --git a/es-core/src/math/Misc.cpp b/es-core/src/math/Misc.cpp index fd4e2b70c..352c50ff8 100644 --- a/es-core/src/math/Misc.cpp +++ b/es-core/src/math/Misc.cpp @@ -8,29 +8,24 @@ #include "math/Misc.h" -#include +#include namespace Math { - float clamp(const float _num, const float _min, const float _max) - { - return std::fmax(std::fmin(_num, _max), _min); - } - float lerp(const float _start, const float _end, const float _fraction) { - return (_start + ((_end - _start) * clamp(_fraction, 0, 1))); + return (_start + ((_end - _start) * clamp(_fraction, 0.0f, 1.0f))); } float smoothStep(const float _left, const float _right, const float _x) { - const float x = clamp((_x - _left)/(_right - _left), 0, 1); + const float x = clamp((_x - _left)/(_right - _left), 0.0f, 1.0f); return x * x * (3 - (2 * x)); } float smootherStep(const float _left, const float _right, const float _x) { - const float x = clamp((_x - _left)/(_right - _left), 0, 1); + const float x = clamp((_x - _left)/(_right - _left), 0.0f, 1.0f); return x * x * x * (x * ((x * 6) - 15) + 10); } diff --git a/es-core/src/math/Misc.h b/es-core/src/math/Misc.h index 606d0e2ae..15193ab43 100644 --- a/es-core/src/math/Misc.h +++ b/es-core/src/math/Misc.h @@ -16,7 +16,12 @@ namespace Math { // When moving to the C++20 standard these functions are no longer required. - float clamp(const float _num, const float _min, const float _max); + template + T const& clamp(const T& _num, const T& _min, const T& _max) + { + T newVal = std::max(std::min(_num, _max), _min); + return std::max(std::min(_num, _max), _min); + } float lerp(const float _start, const float _end, const float _fraction); float smoothStep(const float _left, const float _right, const float _x); diff --git a/es-core/src/renderers/Renderer.h b/es-core/src/renderers/Renderer.h index 6ed6bada0..dae740ae4 100644 --- a/es-core/src/renderers/Renderer.h +++ b/es-core/src/renderers/Renderer.h @@ -39,11 +39,11 @@ namespace Renderer unsigned int shaderPasses; shaderParameters() - : textureSize({0.0, 0.0}), - textureCoordinates({0.0, 0.0, 0.0, 0.0}), - fragmentSaturation(1.0), - fragmentDimValue(0.4), - fragmentOpacity(1.0), + : textureSize({0.0f, 0.0f}), + textureCoordinates({0.0f, 0.0f, 0.0f, 0.0f}), + fragmentSaturation(1.0f), + fragmentDimValue(0.4f), + fragmentOpacity(1.0f), shaderPasses(1) {}; };