From 963f93e0f8a813b64bfe1e9f9b5c5d3208553a1e Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 28 Dec 2020 11:29:32 +0100 Subject: [PATCH] Replaced the custom math functions with standard C++ functions. --- RELEASES.md | 3 +- es-app/src/FileFilterIndex.cpp | 4 +- es-app/src/guis/GuiMenu.cpp | 4 +- es-app/src/guis/GuiMetaDataEd.cpp | 2 +- es-app/src/guis/GuiScreensaverOptions.cpp | 8 +-- es-app/src/scrapers/ScreenScraper.cpp | 3 +- es-app/src/views/SystemView.cpp | 10 ++-- .../src/views/gamelist/GridGameListView.cpp | 2 +- es-app/src/views/gamelist/IGameListView.cpp | 8 +-- es-core/src/Window.cpp | 4 +- es-core/src/components/ButtonComponent.cpp | 2 +- es-core/src/components/ComponentList.cpp | 4 +- es-core/src/components/HelpComponent.cpp | 2 +- es-core/src/components/ImageComponent.cpp | 22 ++++---- es-core/src/components/ImageGridComponent.h | 14 +++--- es-core/src/components/MenuComponent.cpp | 4 +- es-core/src/components/RatingComponent.cpp | 4 +- es-core/src/components/TextListComponent.h | 4 +- es-core/src/components/VideoVlcComponent.cpp | 26 +++++----- es-core/src/guis/GuiMsgBox.cpp | 6 +-- es-core/src/math/Misc.cpp | 50 +------------------ es-core/src/math/Misc.h | 13 +---- es-core/src/math/Transform4x4f.cpp | 18 ++++--- es-core/src/resources/Font.h | 8 +-- es-core/src/resources/TextureData.cpp | 8 +-- 25 files changed, 92 insertions(+), 141 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 3fa01b2b1..a62ff1042 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -74,13 +74,14 @@ Many bugs have been fixed, and numerous features that were only partially implem * Game counting is now done during sorting instead of every time a system is selected. This should make the UI more responsive in case of large game libraries * All required fonts bundled with the application, no dependencies on the OS to provide them any longer * Made pugixml an external dependency instead of bundling it +* Replaced the custom math functions with standard C++ functions whenever possible * Modernized the audio code, for example using SDL_AudioStream instead of the older SDL_AudioCVT * Overhaul of application settings, now the configuration file is only updated when there have been actual configuration changes * Decreased CPU usage dramatically by only rendering the currently visible view (previously all views were always rendered) * Updated the CMake/CPack install and package configuration files to work as expected (can now generate DEB, RPM, DMG and NSIS installation packages with correct dependencies) * Added support for Clang/LLVM, made the application build with no errors or warnings using this compiler (Unix and macOS only) * License files included for all the libraries and resources that are bundled with the application -* Updated the MAME ROM index files to include ROMs up to MAME version 0.221 and created scripts to easily generate these index files in the future +* Updated the MAME ROM index files to include ROMs up to MAME version 0.226 and created scripts to easily generate these index files in the future * Greatly expanded the application documentation (which is hosted in the ES-DE repository on GitLab) ### Bug fixes diff --git a/es-app/src/FileFilterIndex.cpp b/es-app/src/FileFilterIndex.cpp index 318ce5db2..6325fabb5 100644 --- a/es-app/src/FileFilterIndex.cpp +++ b/es-app/src/FileFilterIndex.cpp @@ -15,6 +15,8 @@ #include "Log.h" #include "Settings.h" +#include + #define UNKNOWN_LABEL "UNKNOWN" #define INCLUDE_UNKNOWN false; @@ -165,7 +167,7 @@ std::string FileFilterIndex::getIndexableKey(FileData* game, // been used for scraping the ratings, or if the gamelist.xml file // has been manually edited. ratingNumber = static_cast( - (Math::ceilf(stof(ratingString) / 0.1) / 10) * 5); + (ceilf(stof(ratingString) / 0.1) / 10) * 5); if (ratingNumber < 0) ratingNumber = 0; diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 007fb37da..fb968f381 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -435,7 +435,7 @@ void GuiMenu::openSoundSettings() s->addWithLabel("SYSTEM VOLUME", system_volume); s->addSaveFunc([system_volume] { VolumeControl::getInstance()-> - setVolume(static_cast(Math::round(system_volume->getValue()))); + setVolume(static_cast(std::round(system_volume->getValue()))); }); #endif @@ -612,7 +612,7 @@ void GuiMenu::openOtherSettings() s->addSaveFunc([max_vram, s] { if (max_vram->getValue() != Settings::getInstance()->getInt("MaxVRAM")) { Settings::getInstance()->setInt("MaxVRAM", - static_cast(Math::round(max_vram->getValue()))); + static_cast(std::round(max_vram->getValue()))); s->setNeedsSaving(); } }); diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index 24cf22063..d267ba920 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -319,7 +319,7 @@ GuiMetaDataEd::GuiMetaDataEd( mGrid.setEntry(mButtons, Vector2i(0, 2), true, false); // Resize + center. - float width = static_cast(Math::min(Renderer::getScreenHeight(), + float width = static_cast(std::min(Renderer::getScreenHeight(), static_cast(Renderer::getScreenWidth() * 0.90f))); setSize(width, Renderer::getScreenHeight() * 0.82f); setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, diff --git a/es-app/src/guis/GuiScreensaverOptions.cpp b/es-app/src/guis/GuiScreensaverOptions.cpp index 7181d6e86..9a6276d0a 100644 --- a/es-app/src/guis/GuiScreensaverOptions.cpp +++ b/es-app/src/guis/GuiScreensaverOptions.cpp @@ -24,10 +24,10 @@ GuiScreensaverOptions::GuiScreensaverOptions(Window* window, const std::string& getInt("ScreensaverTimer") / (1000 * 60))); addWithLabel("START SCREENSAVER AFTER (MINUTES)", screensaver_timer); addSaveFunc([screensaver_timer, this] { - if (static_cast(Math::round(screensaver_timer->getValue()) * (1000 * 60)) != + if (static_cast(std::round(screensaver_timer->getValue()) * (1000 * 60)) != Settings::getInstance()->getInt("ScreensaverTimer")) { Settings::getInstance()->setInt("ScreensaverTimer", - static_cast(Math::round(screensaver_timer->getValue()) * (1000 * 60))); + static_cast(std::round(screensaver_timer->getValue()) * (1000 * 60))); setNeedsSaving(); } }); @@ -108,7 +108,7 @@ void GuiScreensaverOptions::openSlideshowScreensaverOptions() static_cast(Settings::getInstance()-> getInt("ScreensaverSwapImageTimeout") / (1000))) { Settings::getInstance()->setInt("ScreensaverSwapImageTimeout", - static_cast(Math::round(screensaver_swap_image_timeout->getValue()) * + static_cast(std::round(screensaver_swap_image_timeout->getValue()) * (1000))); s->setNeedsSaving(); } @@ -219,7 +219,7 @@ void GuiScreensaverOptions::openVideoScreensaverOptions() static_cast(Settings::getInstance()-> getInt("ScreensaverSwapVideoTimeout") / (1000))) { Settings::getInstance()->setInt("ScreensaverSwapVideoTimeout", - static_cast(Math::round(screensaver_swap_video_timeout->getValue()) * + static_cast(std::round(screensaver_swap_video_timeout->getValue()) * (1000))); s->setNeedsSaving(); } diff --git a/es-app/src/scrapers/ScreenScraper.cpp b/es-app/src/scrapers/ScreenScraper.cpp index 656493fff..706e8c2f0 100644 --- a/es-app/src/scrapers/ScreenScraper.cpp +++ b/es-app/src/scrapers/ScreenScraper.cpp @@ -18,6 +18,7 @@ #include "Settings.h" #include "SystemData.h" +#include #include #include @@ -326,7 +327,7 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc, if (game.child("note")) { float ratingVal = (game.child("note").text().as_int() / 20.0f); // Round up to the closest .1 value, i.e. to the closest half-star. - ratingVal = Math::ceilf(ratingVal / 0.1) / 10; + ratingVal = ceilf(ratingVal / 0.1) / 10; std::stringstream ss; ss << ratingVal; if (ratingVal > 0) { diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index 5a31371d6..5a414e092 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -545,7 +545,7 @@ void SystemView::renderCarousel(const Transform4x4f& trans) } int center = static_cast(mCamOffset); - int logoCount = Math::min(mCarousel.maxLogoCount, static_cast(mEntries.size())); + int logoCount = std::min(mCarousel.maxLogoCount, static_cast(mEntries.size())); // Adding texture loading buffers depending on scrolling speed and status. int bufferIndex = getScrollingVelocity() + 1; @@ -570,12 +570,12 @@ void SystemView::renderCarousel(const Transform4x4f& trans) float distance = i - mCamOffset; float scale = 1.0f + ((mCarousel.logoScale - 1.0f) * (1.0f - fabs(distance))); - scale = Math::min(mCarousel.logoScale, Math::max(1.0f, scale)); + scale = std::min(mCarousel.logoScale, std::max(1.0f, scale)); scale /= mCarousel.logoScale; - int opacity = static_cast(Math::round(0x80 + ((0xFF - 0x80) * + int opacity = static_cast(std::round(0x80 + ((0xFF - 0x80) * (1.0f - fabs(distance))))); - opacity = Math::max(static_cast(0x80), opacity); + opacity = std::max(static_cast(0x80), opacity); const std::shared_ptr &comp = mEntries.at(index).data.logo; if (mCarousel.type == VERTICAL_WHEEL || mCarousel.type == HORIZONTAL_WHEEL) { @@ -706,7 +706,7 @@ void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem) if (elem->has("logoSize")) mCarousel.logoSize = elem->get("logoSize") * mSize; if (elem->has("maxLogoCount")) - mCarousel.maxLogoCount = static_cast(Math::round(elem->get("maxLogoCount"))); + mCarousel.maxLogoCount = static_cast(std::round(elem->get("maxLogoCount"))); if (elem->has("zIndex")) mCarousel.zIndex = elem->get("zIndex"); if (elem->has("logoRotation")) diff --git a/es-app/src/views/gamelist/GridGameListView.cpp b/es-app/src/views/gamelist/GridGameListView.cpp index 2d51938bd..d06c1481f 100644 --- a/es-app/src/views/gamelist/GridGameListView.cpp +++ b/es-app/src/views/gamelist/GridGameListView.cpp @@ -205,7 +205,7 @@ std::string GridGameListView::getQuickSystemSelectLeftButton() bool GridGameListView::input(InputConfig* config, Input input) { - if (input.value == 0 and (config->isMappedLike("left", input) || + if (input.value == 0 && (config->isMappedLike("left", input) || config->isMappedLike("right", input) || (config->isMappedLike("up", input)) || (config->isMappedLike("down", input)) )) diff --git a/es-app/src/views/gamelist/IGameListView.cpp b/es-app/src/views/gamelist/IGameListView.cpp index b55a0a9c9..827d845c9 100644 --- a/es-app/src/views/gamelist/IGameListView.cpp +++ b/es-app/src/views/gamelist/IGameListView.cpp @@ -58,10 +58,10 @@ void IGameListView::render(const Transform4x4f& parentTrans) float scaleX = trans.r0().x(); float scaleY = trans.r1().y(); - Vector2i pos(static_cast(Math::round(trans.translation()[0])), - static_cast(Math::round(trans.translation()[1]))); - Vector2i size(static_cast(Math::round(mSize.x() * scaleX)), - static_cast(Math::round(mSize.y() * scaleY))); + Vector2i pos(static_cast(std::round(trans.translation()[0])), + static_cast(std::round(trans.translation()[1]))); + Vector2i size(static_cast(std::round(mSize.x() * scaleX)), + static_cast(std::round(mSize.y() * scaleY))); Renderer::pushClipRect(pos, size); renderChildren(trans); diff --git a/es-core/src/Window.cpp b/es-core/src/Window.cpp index 01f51ffd4..fa1867a25 100644 --- a/es-core/src/Window.cpp +++ b/es-core/src/Window.cpp @@ -471,8 +471,8 @@ void Window::renderLoadingScreen(std::string text) auto& font = mDefaultFonts.at(1); TextCache* cache = font->buildTextCache(text, 0, 0, 0x656565FF); - float x = Math::round((Renderer::getScreenWidth() - cache->metrics.size.x()) / 2.0f); - float y = Math::round(Renderer::getScreenHeight() * 0.835f); + float x = std::round((Renderer::getScreenWidth() - cache->metrics.size.x()) / 2.0f); + float y = std::round(Renderer::getScreenHeight() * 0.835f); trans = trans.translate(Vector3f(x, y, 0.0f)); Renderer::setMatrix(trans); font->renderTextCache(cache); diff --git a/es-core/src/components/ButtonComponent.cpp b/es-core/src/components/ButtonComponent.cpp index ed4302603..c1c622154 100644 --- a/es-core/src/components/ButtonComponent.cpp +++ b/es-core/src/components/ButtonComponent.cpp @@ -56,7 +56,7 @@ void ButtonComponent::setText(const std::string& text, const std::string& helpTe mTextCache = std::unique_ptr(mFont->buildTextCache(mText, 0, 0, getCurTextColor())); float minWidth = mFont->sizeText("DELETE").x() + 12; - setSize(Math::max(mTextCache->metrics.size.x() + 12, minWidth), mTextCache->metrics.size.y()); + setSize(std::max(mTextCache->metrics.size.x() + 12, minWidth), mTextCache->metrics.size.y()); updateHelpPrompts(); } diff --git a/es-core/src/components/ComponentList.cpp b/es-core/src/components/ComponentList.cpp index 8f0b04c6a..39bca4bc5 100644 --- a/es-core/src/components/ComponentList.cpp +++ b/es-core/src/components/ComponentList.cpp @@ -183,10 +183,10 @@ void ComponentList::render(const Transform4x4f& parentTrans) dim = trans * dim - trans.translation(); Renderer::pushClipRect(Vector2i(static_cast(trans.translation().x()), static_cast(trans.translation().y())), Vector2i(static_cast( - Math::round(dim.x())), static_cast(Math::round(dim.y() + 1)))); + std::round(dim.x())), static_cast(std::round(dim.y() + 1)))); // Scroll the camera. - trans.translate(Vector3f(0, -Math::round(mCameraOffset), 0)); + trans.translate(Vector3f(0, -std::round(mCameraOffset), 0)); // Draw our entries. std::vector drawAfterCursor; diff --git a/es-core/src/components/HelpComponent.cpp b/es-core/src/components/HelpComponent.cpp index 57d051792..b22279ce5 100644 --- a/es-core/src/components/HelpComponent.cpp +++ b/es-core/src/components/HelpComponent.cpp @@ -77,7 +77,7 @@ void HelpComponent::updateGrid() std::vector< std::shared_ptr > labels; float width = 0; - const float height = Math::round(font->getLetterHeight() * 1.25f); + const float height = std::round(font->getLetterHeight() * 1.25f); for (auto it = mPrompts.cbegin(); it != mPrompts.cend(); it++) { auto icon = std::make_shared(mWindow); diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index 41faa63c7..3a35c7742 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -72,8 +72,8 @@ void ImageComponent::resize() // ratios), it can cause cutoff when the aspect ratio breaks. // So we always make sure the resultant height is an integer to make sure cutoff doesn't // happen, and scale width from that (you'll see this scattered throughout the function). - // It's important to use the floorf() function rather than round() for this, as we never - // want to round up since that can lead to the cutoff just described. + // It's important to use the floorf rather than round for this, as we never want to round + // up since that can lead to the cutoff just described. if (mTargetIsMax) { mSize = textureSize; @@ -83,14 +83,14 @@ void ImageComponent::resize() // This will be mTargetSize.x(). We can't exceed it, nor be lower than it. mSize[0] *= resizeScale.x(); // We need to make sure we're not creating an image larger than max size. - mSize[1] = Math::min(Math::floorf(mSize[1] *= resizeScale.x()), mTargetSize.y()); + mSize[1] = std::min(floorf(mSize[1] *= resizeScale.x()), mTargetSize.y()); } else { // This will be mTargetSize.y(). We can't exceed it. - mSize[1] = Math::floorf(mSize[1] * resizeScale.y()); + mSize[1] = floorf(mSize[1] * resizeScale.y()); // For SVG rasterization, always calculate width from rounded height (see comment // above). We need to make sure we're not creating an image larger than max size. - mSize[0] = Math::min((mSize[1] / textureSize.y()) * textureSize.x(), + mSize[0] = std::min((mSize[1] / textureSize.y()) * textureSize.x(), mTargetSize.x()); } } @@ -115,8 +115,8 @@ void ImageComponent::resize() } // For SVG rasterization, always calculate width from rounded height (see comment // above). We need to make sure we're not creating an image smaller than min size. - mSize[1] = Math::max(Math::floorf(mSize[1]), mTargetSize.y()); - mSize[0] = Math::max((mSize[1] / textureSize.y()) * textureSize.x(), mTargetSize.x()); + mSize[1] = std::max(floorf(mSize[1]), mTargetSize.y()); + mSize[0] = std::max((mSize[1] / textureSize.y()) * textureSize.x(), mTargetSize.x()); } else { @@ -128,18 +128,18 @@ void ImageComponent::resize() // For SVG rasterization, we always calculate width from rounded height (see // comment above). if (!mTargetSize.x() && mTargetSize.y()) { - mSize[1] = Math::floorf(mTargetSize.y()); + mSize[1] = floorf(mTargetSize.y()); mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x(); } else if (mTargetSize.x() && !mTargetSize.y()) { - mSize[1] = Math::floorf((mTargetSize.x() / textureSize.x()) * textureSize.y()); + mSize[1] = floorf((mTargetSize.x() / textureSize.x()) * textureSize.y()); mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x(); } } } - mSize[0] = Math::floorf(mSize.x()); - mSize[1] = Math::floorf(mSize.y()); + mSize[0] = floorf(mSize.x()); + mSize[1] = floorf(mSize.y()); // mSize.y() should already be rounded. mTexture->rasterizeAt(static_cast(mSize.x()), static_cast(mSize.y())); diff --git a/es-core/src/components/ImageGridComponent.h b/es-core/src/components/ImageGridComponent.h index 676255193..21eabfe07 100644 --- a/es-core/src/components/ImageGridComponent.h +++ b/es-core/src/components/ImageGridComponent.h @@ -225,10 +225,10 @@ void ImageGridComponent::render(const Transform4x4f& parentTrans) float scaleX = trans.r0().x(); float scaleY = trans.r1().y(); - Vector2i pos(static_cast(Math::round(trans.translation()[0])), - static_cast(Math::round(trans.translation()[1]))); - Vector2i size(static_cast(Math::round(mSize.x() * scaleX)), - static_cast(Math::round(mSize.y() * scaleY))); + Vector2i pos(static_cast(std::round(trans.translation()[0])), + static_cast(std::round(trans.translation()[1]))); + Vector2i size(static_cast(std::round(mSize.x() * scaleX)), + static_cast(std::round(mSize.y() * scaleY))); Renderer::pushClipRect(pos, size); @@ -520,7 +520,7 @@ void ImageGridComponent::buildTiles() if (mCenterSelection) { int dimScrollable = (isVertical() ? mGridDimension.y() : mGridDimension.x()) - 2 * EXTRAITEMS; - mStartPosition -= static_cast(Math::floorf(dimScrollable / 2.0f)); + mStartPosition -= static_cast(floorf(dimScrollable / 2.0f)); } Vector2f tileDistance = mTileSize + mMargin; @@ -683,10 +683,10 @@ void ImageGridComponent::calcGridDimension() if (mAutoLayout.x() != 0 && mAutoLayout.y() != 0) gridDimension = mAutoLayout; - mLastRowPartial = Math::floorf(gridDimension.y()) != gridDimension.y(); + mLastRowPartial = floorf(gridDimension.y()) != gridDimension.y(); // Ceil y dim so we can display partial last row. - mGridDimension = Vector2i(gridDimension.x(), Math::ceilf(gridDimension.y())); + mGridDimension = Vector2i(gridDimension.x(), ceilf(gridDimension.y())); // Grid dimension validation. if (mGridDimension.x() < 1) { diff --git a/es-core/src/components/MenuComponent.cpp b/es-core/src/components/MenuComponent.cpp index c018ed9d8..e890a193b 100644 --- a/es-core/src/components/MenuComponent.cpp +++ b/es-core/src/components/MenuComponent.cpp @@ -95,7 +95,7 @@ void MenuComponent::updateSize() } } - float width = static_cast(Math::min(static_cast(Renderer::getScreenHeight()), + float width = static_cast(std::min(static_cast(Renderer::getScreenHeight()), static_cast(Renderer::getScreenWidth() * 0.90f))); setSize(width, height); } @@ -166,6 +166,6 @@ std::shared_ptr makeArrow(Window* window) { auto bracket = std::make_shared(window); bracket->setImage(":/graphics/arrow.svg"); - bracket->setResize(0, Math::round(Font::get(FONT_SIZE_MEDIUM)->getLetterHeight())); + bracket->setResize(0, std::round(Font::get(FONT_SIZE_MEDIUM)->getLetterHeight())); return bracket; } diff --git a/es-core/src/components/RatingComponent.cpp b/es-core/src/components/RatingComponent.cpp index 4900342a2..560f1910a 100644 --- a/es-core/src/components/RatingComponent.cpp +++ b/es-core/src/components/RatingComponent.cpp @@ -39,7 +39,7 @@ void RatingComponent::setValue(const std::string& value) } else { // Round up to the closest .1 value, i.e. to the closest half-icon. - mValue = Math::ceilf(stof(value) / 0.1) / 10; + mValue = ceilf(stof(value) / 0.1) / 10; mOriginalValue = static_cast(mValue * 10); // If the argument to colorize the rating icons has been passed, set the @@ -104,7 +104,7 @@ void RatingComponent::onSizeChanged() mSize[0] = mSize.y() * NUM_RATING_STARS; if (mSize.y() > 0) { - size_t heightPx = static_cast(Math::round(mSize.y())); + size_t heightPx = static_cast(std::round(mSize.y())); if (mFilledTexture) mFilledTexture->rasterizeAt(heightPx, heightPx); if (mUnfilledTexture) diff --git a/es-core/src/components/TextListComponent.h b/es-core/src/components/TextListComponent.h index 3b16f8a60..773215cd6 100644 --- a/es-core/src/components/TextListComponent.h +++ b/es-core/src/components/TextListComponent.h @@ -156,7 +156,7 @@ void TextListComponent::render(const Transform4x4f& parentTrans) if (size() == 0) return; - const float entrySize = Math::max(font->getHeight(1.0), + const float entrySize = std::max(font->getHeight(1.0), static_cast(font->getSize())) * mLineSpacing; int startEntry = 0; @@ -420,7 +420,7 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, } setFont(Font::getFromTheme(elem, properties, mFont)); - const float selectorHeight = Math::max(mFont->getHeight(1.0), + const float selectorHeight = std::max(mFont->getHeight(1.0), static_cast(mFont->getSize())) * mLineSpacing; setSelectorHeight(selectorHeight); diff --git a/es-core/src/components/VideoVlcComponent.cpp b/es-core/src/components/VideoVlcComponent.cpp index 1230ecdf9..934ab342f 100644 --- a/es-core/src/components/VideoVlcComponent.cpp +++ b/es-core/src/components/VideoVlcComponent.cpp @@ -130,7 +130,7 @@ void VideoVlcComponent::resize() mSize[1] *= resizeScale.y(); } - mSize[1] = Math::round(mSize[1]); + mSize[1] = std::round(mSize[1]); mSize[0] = (mSize[1] / textureSize.y()) * textureSize.x(); } @@ -141,17 +141,17 @@ void VideoVlcComponent::resize() // If only one component is set, we resize in a way that maintains aspect ratio. if (!mTargetSize.x() && mTargetSize.y()) { - mSize[1] = Math::round(mTargetSize.y()); + mSize[1] = std::round(mTargetSize.y()); mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x(); } else if (mTargetSize.x() && !mTargetSize.y()) { - mSize[1] = Math::round((mTargetSize.x() / textureSize.x()) * textureSize.y()); + mSize[1] = std::round((mTargetSize.x() / textureSize.x()) * textureSize.y()); mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x(); } } - mTexture->rasterizeAt(static_cast(Math::round(mSize.x())), - static_cast(Math::round(mSize.y()))); + mTexture->rasterizeAt(static_cast(std::round(mSize.x())), + static_cast(std::round(mSize.y()))); onSizeChanged(); } @@ -261,20 +261,20 @@ void VideoVlcComponent::calculateBlackRectangle() rectHeight = mSize.y(); } // Populate the rectangle coordinates to be used in render(). - mVideoRectangleCoords.push_back(Math::round(mVideoAreaPos.x() - + mVideoRectangleCoords.push_back(std::round(mVideoAreaPos.x() - rectWidth * mOrigin.x())); - mVideoRectangleCoords.push_back(Math::round(mVideoAreaPos.y() - + mVideoRectangleCoords.push_back(std::round(mVideoAreaPos.y() - rectHeight * mOrigin.y())); - mVideoRectangleCoords.push_back(Math::round(rectWidth)); - mVideoRectangleCoords.push_back(Math::round(rectHeight)); + mVideoRectangleCoords.push_back(std::round(rectWidth)); + mVideoRectangleCoords.push_back(std::round(rectHeight)); } // If the option to display pillarboxes is disabled, then make the rectangle equivalent // to the size of the video. else { - mVideoRectangleCoords.push_back(Math::round(mPosition.x() - mSize.x() * mOrigin.x())); - mVideoRectangleCoords.push_back(Math::round(mPosition.y() - mSize.y() * mOrigin.y())); - mVideoRectangleCoords.push_back(Math::round(mSize.x())); - mVideoRectangleCoords.push_back(Math::round(mSize.y())); + mVideoRectangleCoords.push_back(std::round(mPosition.x() - mSize.x() * mOrigin.x())); + mVideoRectangleCoords.push_back(std::round(mPosition.y() - mSize.y() * mOrigin.y())); + mVideoRectangleCoords.push_back(std::round(mSize.x())); + mVideoRectangleCoords.push_back(std::round(mSize.y())); } } } diff --git a/es-core/src/guis/GuiMsgBox.cpp b/es-core/src/guis/GuiMsgBox.cpp index c4816c227..66e7ed8ec 100644 --- a/es-core/src/guis/GuiMsgBox.cpp +++ b/es-core/src/guis/GuiMsgBox.cpp @@ -63,13 +63,13 @@ GuiMsgBox::GuiMsgBox(Window* window, const HelpStyle& helpstyle, const std::stri // Decide final width. if (mMsg->getSize().x() < width && mButtonGrid->getSize().x() < width) { // mMsg and buttons are narrower than width. - width = Math::max(mButtonGrid->getSize().x(), mMsg->getSize().x()); - width = Math::max(width, minWidth); + width = std::max(mButtonGrid->getSize().x(), mMsg->getSize().x()); + width = std::max(width, minWidth); } // Now that we know width, we can find height. mMsg->setSize(width, 0); // mMsg->getSize.y() now returns the proper length. - const float msgHeight = Math::max(Font::get(FONT_SIZE_LARGE)->getHeight(), + const float msgHeight = std::max(Font::get(FONT_SIZE_LARGE)->getHeight(), mMsg->getSize().y()*1.225f); setSize(width + HORIZONTAL_PADDING_PX*2, msgHeight + mButtonGrid->getSize().y()); diff --git a/es-core/src/math/Misc.cpp b/es-core/src/math/Misc.cpp index cc6692d9a..fd4e2b70c 100644 --- a/es-core/src/math/Misc.cpp +++ b/es-core/src/math/Misc.cpp @@ -8,59 +8,13 @@ #include "math/Misc.h" -#include +#include namespace Math { - // Added here to avoid including math.h whenever these are used. - float cosf(const float _num) - { - return ::cosf(_num); - } - - float sinf(const float _num) - { - return ::sinf(_num); - } - - float floorf(const float _num) - { - return ::floorf(_num); - } - - float ceilf(const float _num) - { - return ::ceilf(_num); - } - - int min(const int _num1, const int _num2) - { - return (_num1 < _num2) ? _num1 : _num2; - } - - int max(const int _num1, const int _num2) - { - return (_num1 > _num2) ? _num1 : _num2; - } - - float min(const float _num1, const float _num2) - { - return (_num1 < _num2) ? _num1 : _num2; - } - - float max(const float _num1, const float _num2) - { - return (_num1 > _num2) ? _num1 : _num2; - } - float clamp(const float _num, const float _min, const float _max) { - return max(min(_num, _max), _min); - } - - float round(const float _num) - { - return static_cast(static_cast((_num + 0.5))); + return std::fmax(std::fmin(_num, _max), _min); } float lerp(const float _start, const float _end, const float _fraction) diff --git a/es-core/src/math/Misc.h b/es-core/src/math/Misc.h index 01ee10719..606d0e2ae 100644 --- a/es-core/src/math/Misc.h +++ b/es-core/src/math/Misc.h @@ -15,19 +15,10 @@ namespace Math { - // Added here to avoid including math.h whenever these are used. - float cosf(const float _num); - float sinf(const float _num); - float floorf(const float _num); - float ceilf(const float _num); - - int min(const int _num1, const int _num2); - int max(const int _num1, const int _num2); - float min(const float _num1, const float _num2); - float max(const float _num1, const float _num2); + // When moving to the C++20 standard these functions are no longer required. float clamp(const float _num, const float _min, const float _max); - float round(const float _num); float lerp(const float _start, const float _end, const float _fraction); + float smoothStep(const float _left, const float _right, const float _x); float smootherStep(const float _left, const float _right, const float _x); diff --git a/es-core/src/math/Transform4x4f.cpp b/es-core/src/math/Transform4x4f.cpp index bee11481f..3f27f6fdf 100644 --- a/es-core/src/math/Transform4x4f.cpp +++ b/es-core/src/math/Transform4x4f.cpp @@ -8,6 +8,8 @@ #include "math/Transform4x4f.h" +#include + const Transform4x4f Transform4x4f::operator*(const Transform4x4f& _other) const { const float* tm = reinterpret_cast(this); @@ -187,8 +189,8 @@ Transform4x4f& Transform4x4f::rotate(const float _angle, const Vector3f& _axis) { float* tm = reinterpret_cast(this); const float* av = reinterpret_cast(&_axis); - const float s = Math::sinf(-_angle); - const float c = Math::cosf(-_angle); + const float s = sinf(-_angle); + const float c = cosf(-_angle); const float t = 1 - c; const float x = av[0]; const float y = av[1]; @@ -234,8 +236,8 @@ Transform4x4f& Transform4x4f::rotate(const float _angle, const Vector3f& _axis) Transform4x4f& Transform4x4f::rotateX(const float _angle) { float* tm = reinterpret_cast(this); - const float s = Math::sinf(-_angle); - const float c = Math::cosf(-_angle); + const float s = sinf(-_angle); + const float c = cosf(-_angle); const float temp[6] = { tm[ 4] * c + tm[ 8] * -s, tm[ 5] * c + tm[ 9] * -c, tm[ 6] * c + tm[10] * -s, @@ -256,8 +258,8 @@ Transform4x4f& Transform4x4f::rotateX(const float _angle) Transform4x4f& Transform4x4f::rotateY(const float _angle) { float* tm = reinterpret_cast(this); - const float s = Math::sinf(-_angle); - const float c = Math::cosf(-_angle); + const float s = sinf(-_angle); + const float c = cosf(-_angle); const float temp[6] = { tm[ 0] * c + tm[ 8] * s, tm[ 1] * c + tm[ 9] * s, tm[ 2] * c + tm[10] * s, @@ -278,8 +280,8 @@ Transform4x4f& Transform4x4f::rotateY(const float _angle) Transform4x4f& Transform4x4f::rotateZ(const float _angle) { float* tm = reinterpret_cast(this); - const float s = Math::sinf(-_angle); - const float c = Math::cosf(-_angle); + const float s = sinf(-_angle); + const float c = cosf(-_angle); const float temp[6] = { tm[ 0] * c + tm[ 4] * -s, tm[ 1] * c + tm[ 5] * -s, tm[ 2] * c + tm[ 6] * -s, diff --git a/es-core/src/resources/Font.h b/es-core/src/resources/Font.h index 486531ffd..4c90cf325 100644 --- a/es-core/src/resources/Font.h +++ b/es-core/src/resources/Font.h @@ -22,13 +22,13 @@ class TextCache; -#define FONT_SIZE_MINI (static_cast(0.030f * Math::min(static_cast( \ +#define FONT_SIZE_MINI (static_cast(0.030f * std::min(static_cast( \ Renderer::getScreenHeight()), static_cast(Renderer::getScreenWidth())))) -#define FONT_SIZE_SMALL (static_cast(0.035f * Math::min(static_cast( \ +#define FONT_SIZE_SMALL (static_cast(0.035f * std::min(static_cast( \ Renderer::getScreenHeight()), static_cast(Renderer::getScreenWidth())))) -#define FONT_SIZE_MEDIUM (static_cast(0.045f * Math::min(static_cast( \ +#define FONT_SIZE_MEDIUM (static_cast(0.045f * std::min(static_cast( \ Renderer::getScreenHeight()), static_cast(Renderer::getScreenWidth())))) -#define FONT_SIZE_LARGE (static_cast(0.085f * Math::min(static_cast( \ +#define FONT_SIZE_LARGE (static_cast(0.085f * std::min(static_cast( \ Renderer::getScreenHeight()), static_cast(Renderer::getScreenWidth())))) #define FONT_PATH_LIGHT ":/fonts/opensans_hebrew_condensed_light.ttf" diff --git a/es-core/src/resources/TextureData.cpp b/es-core/src/resources/TextureData.cpp index 02de6d90d..511996a59 100644 --- a/es-core/src/resources/TextureData.cpp +++ b/es-core/src/resources/TextureData.cpp @@ -69,17 +69,17 @@ bool TextureData::initSVGFromMemory(const std::string& fileData) mSourceWidth = svgImage->width; mSourceHeight = svgImage->height; } - mWidth = static_cast(Math::round(mSourceWidth)); - mHeight = static_cast(Math::round(mSourceHeight)); + mWidth = static_cast(std::round(mSourceWidth)); + mHeight = static_cast(std::round(mSourceHeight)); if (mWidth == 0) { // Auto scale width to keep aspect ratio. - mWidth = static_cast(Math::round((static_cast(mHeight) / + mWidth = static_cast(std::round((static_cast(mHeight) / svgImage->height) * svgImage->width)); } else if (mHeight == 0) { // Auto scale height to keep aspect ratio. - mHeight = static_cast(Math::round((static_cast(mWidth) / + mHeight = static_cast(std::round((static_cast(mWidth) / svgImage->width) * svgImage->height)); }