From 64a7b8e54a4e7aef475308911b75e0d84deca931 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 15 Aug 2021 22:03:17 +0200 Subject: [PATCH] Replaced the internal Vector3f and Vector4f data types and functions with the GLM library equivalents. --- es-app/src/guis/GuiMetaDataEd.cpp | 4 ++-- es-app/src/guis/GuiScraperSearch.cpp | 20 +++++++--------- es-core/src/ThemeData.cpp | 18 +++++++-------- es-core/src/ThemeData.h | 11 ++++----- es-core/src/components/DateTimeComponent.cpp | 2 +- es-core/src/components/DateTimeComponent.h | 2 +- .../src/components/DateTimeEditComponent.cpp | 6 ++--- .../src/components/DateTimeEditComponent.h | 2 +- es-core/src/components/GridTileComponent.cpp | 10 ++++---- es-core/src/components/GridTileComponent.h | 2 +- es-core/src/components/ImageGridComponent.h | 23 +++++++++---------- es-core/src/components/TextComponent.cpp | 8 ++----- es-core/src/components/TextComponent.h | 2 +- es-core/src/renderers/Shader_GL21.h | 1 - 14 files changed, 50 insertions(+), 61 deletions(-) diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index 29d4d41ca..72ac65353 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -78,8 +78,8 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, folderPath + Utils::FileSystem::getFileName(scraperParams.game->getPath()) + " [" + Utils::String::toUpper(scraperParams.system->getName()) + "]" + (scraperParams.game->getType() == FOLDER ? " " + ViewController::FOLDER_CHAR : ""), - Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER, Vector3f(0.0f, 0.0f, 0.0f), - Vector2f(0.0f, 0.0f), 0x00000000, 0.05f); + Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER, glm::vec3 {}, Vector2f(0.0f, 0.0f), + 0x00000000, 0.05f); mHeaderGrid->setEntry(mTitle, Vector2i(0, 1), false, true); mHeaderGrid->setEntry(mSubtitle, Vector2i(0, 3), false, true); diff --git a/es-app/src/guis/GuiScraperSearch.cpp b/es-app/src/guis/GuiScraperSearch.cpp index 02afc5a48..30a13a08e 100644 --- a/es-app/src/guis/GuiScraperSearch.cpp +++ b/es-app/src/guis/GuiScraperSearch.cpp @@ -87,18 +87,14 @@ GuiScraperSearch::GuiScraperSearch(Window* window, SearchType type, unsigned int mMD_ReleaseDate = std::make_shared(mWindow); mMD_ReleaseDate->setColor(mdColor); mMD_ReleaseDate->setUppercase(true); - mMD_Developer = - std::make_shared(mWindow, "", font, mdColor, ALIGN_LEFT, Vector3f::Zero(), - Vector2f::Zero(), 0x00000000, 0.02f); - mMD_Publisher = - std::make_shared(mWindow, "", font, mdColor, ALIGN_LEFT, Vector3f::Zero(), - Vector2f::Zero(), 0x00000000, 0.02f); - mMD_Genre = - std::make_shared(mWindow, "", font, mdColor, ALIGN_LEFT, Vector3f::Zero(), - Vector2f::Zero(), 0x00000000, 0.02f); - mMD_Players = - std::make_shared(mWindow, "", font, mdColor, ALIGN_LEFT, Vector3f::Zero(), - Vector2f::Zero(), 0x00000000, 0.02f); + mMD_Developer = std::make_shared( + mWindow, "", font, mdColor, ALIGN_LEFT, glm::vec3 {}, Vector2f::Zero(), 0x00000000, 0.02f); + mMD_Publisher = std::make_shared( + mWindow, "", font, mdColor, ALIGN_LEFT, glm::vec3 {}, Vector2f::Zero(), 0x00000000, 0.02f); + mMD_Genre = std::make_shared(mWindow, "", font, mdColor, ALIGN_LEFT, + glm::vec3 {}, Vector2f::Zero(), 0x00000000, 0.02f); + mMD_Players = std::make_shared( + mWindow, "", font, mdColor, ALIGN_LEFT, glm::vec3 {}, Vector2f::Zero(), 0x00000000, 0.02f); mMD_Filler = std::make_shared(mWindow, "", font, mdColor); if (Settings::getInstance()->getString("Scraper") != "thegamesdb") diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 72dbe06b1..35abe9179 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -450,20 +450,20 @@ void ThemeData::parseElement(const pugi::xml_node& root, switch (typeIt->second) { case NORMALIZED_RECT: { - Vector4f val; + glm::vec4 val; auto splits = Utils::String::delimitedStringToVector(str, " "); if (splits.size() == 2) { - val = Vector4f(static_cast(atof(splits.at(0).c_str())), - static_cast(atof(splits.at(1).c_str())), - static_cast(atof(splits.at(0).c_str())), - static_cast(atof(splits.at(1).c_str()))); + val = glm::vec4(static_cast(atof(splits.at(0).c_str())), + static_cast(atof(splits.at(1).c_str())), + static_cast(atof(splits.at(0).c_str())), + static_cast(atof(splits.at(1).c_str()))); } else if (splits.size() == 4) { - val = Vector4f(static_cast(atof(splits.at(0).c_str())), - static_cast(atof(splits.at(1).c_str())), - static_cast(atof(splits.at(2).c_str())), - static_cast(atof(splits.at(3).c_str()))); + val = glm::vec4(static_cast(atof(splits.at(0).c_str())), + static_cast(atof(splits.at(1).c_str())), + static_cast(atof(splits.at(2).c_str())), + static_cast(atof(splits.at(3).c_str()))); } element.properties[node.name()] = val; diff --git a/es-core/src/ThemeData.h b/es-core/src/ThemeData.h index d3e008b64..c64a29f3e 100644 --- a/es-core/src/ThemeData.h +++ b/es-core/src/ThemeData.h @@ -12,7 +12,6 @@ #define ES_CORE_THEME_DATA_H #include "math/Vector2f.h" -#include "math/Vector4f.h" #include "utils/FileSystemUtil.h" #include @@ -103,11 +102,11 @@ public: std::string type; struct Property { - void operator=(const Vector4f& value) + void operator=(const glm::vec4& value) { r = value; - const Vector4f initVector = value; - v = Vector2f(initVector.x(), initVector.y()); + const glm::vec4 initVector = value; + v = Vector2f(initVector.x, initVector.y); } void operator=(const Vector2f& value) { v = value; } void operator=(const std::string& value) { s = value; } @@ -115,7 +114,7 @@ public: void operator=(const float& value) { f = value; } void operator=(const bool& value) { b = value; } - Vector4f r; + glm::vec4 r; Vector2f v; std::string s; unsigned int i; @@ -137,7 +136,7 @@ public: return *(const T*)&properties.at(prop).f; else if (std::is_same::value) return *(const T*)&properties.at(prop).b; - else if (std::is_same::value) + else if (std::is_same::value) return *(const T*)&properties.at(prop).r; return T(); } diff --git a/es-core/src/components/DateTimeComponent.cpp b/es-core/src/components/DateTimeComponent.cpp index e07001ce3..c09659192 100644 --- a/es-core/src/components/DateTimeComponent.cpp +++ b/es-core/src/components/DateTimeComponent.cpp @@ -27,7 +27,7 @@ DateTimeComponent::DateTimeComponent(Window* window, const std::shared_ptr& font, unsigned int color, Alignment align, - Vector3f pos, + glm::vec3 pos, Vector2f size, unsigned int bgcolor) : TextComponent(window, text, font, color, align, pos, size, bgcolor) diff --git a/es-core/src/components/DateTimeComponent.h b/es-core/src/components/DateTimeComponent.h index 9864ffcb9..fdfa3ee88 100644 --- a/es-core/src/components/DateTimeComponent.h +++ b/es-core/src/components/DateTimeComponent.h @@ -26,7 +26,7 @@ public: const std::shared_ptr& font, unsigned int color = 0x000000FF, Alignment align = ALIGN_LEFT, - Vector3f pos = Vector3f::Zero(), + glm::vec3 pos = {}, Vector2f size = Vector2f::Zero(), unsigned int bgcolor = 0x00000000); diff --git a/es-core/src/components/DateTimeEditComponent.cpp b/es-core/src/components/DateTimeEditComponent.cpp index ab55e8520..16912ea20 100644 --- a/es-core/src/components/DateTimeEditComponent.cpp +++ b/es-core/src/components/DateTimeEditComponent.cpp @@ -303,19 +303,19 @@ void DateTimeEditComponent::updateTextCache() Vector2f start(0, 0); Vector2f end = font->sizeText(dispString.substr(0, 4)); Vector2f diff = end - start; - mCursorBoxes.push_back(Vector4f(start[0], start[1], diff[0], diff[1])); + mCursorBoxes.push_back(glm::vec4(start[0], start[1], diff[0], diff[1])); // Month. start[0] = font->sizeText(dispString.substr(0, 5)).x(); end = font->sizeText(dispString.substr(0, 7)); diff = end - start; - mCursorBoxes.push_back(Vector4f(start[0], start[1], diff[0], diff[1])); + mCursorBoxes.push_back(glm::vec4(start[0], start[1], diff[0], diff[1])); // Day. start[0] = font->sizeText(dispString.substr(0, 8)).x(); end = font->sizeText(dispString.substr(0, 10)); diff = end - start; - mCursorBoxes.push_back(Vector4f(start[0], start[1], diff[0], diff[1])); + mCursorBoxes.push_back(glm::vec4(start[0], start[1], diff[0], diff[1])); // The logic for handling time for 'mode = DISP_DATE_TIME' is missing, but // nobody will use it anyway so it's not worthwhile implementing. diff --git a/es-core/src/components/DateTimeEditComponent.h b/es-core/src/components/DateTimeEditComponent.h index 1a70a49b6..a2c7ab58f 100644 --- a/es-core/src/components/DateTimeEditComponent.h +++ b/es-core/src/components/DateTimeEditComponent.h @@ -82,7 +82,7 @@ private: int mRelativeUpdateAccumulator; std::unique_ptr mTextCache; - std::vector mCursorBoxes; + std::vector mCursorBoxes; unsigned int mColor; Utils::Time::DateTime mOriginalValue; diff --git a/es-core/src/components/GridTileComponent.cpp b/es-core/src/components/GridTileComponent.cpp index ed0d00db3..2dafdf391 100644 --- a/es-core/src/components/GridTileComponent.cpp +++ b/es-core/src/components/GridTileComponent.cpp @@ -184,15 +184,15 @@ void GridTileComponent::setSelected(bool selected, cancelAnimation(3); this->setSelectedZoom(1); - mAnimPosition = Vector3f(0, 0, 0); + mAnimPosition = {}; resize(); } else { - mAnimPosition = Vector3f(pPosition->x, pPosition->y, pPosition->z); + mAnimPosition = glm::vec3(pPosition->x, pPosition->y, pPosition->z); auto func = [this](float t) { - t -= 1; // Cubic ease out. + t -= 1; float pct = Math::lerp(0, 1, t * t * t + 1); this->setSelectedZoom(pct); }; @@ -202,7 +202,7 @@ void GridTileComponent::setSelected(bool selected, new LambdaAnimation(func, 250), 0, [this] { this->setSelectedZoom(1); - mAnimPosition = Vector3f(0, 0, 0); + mAnimPosition = {}; }, false, 3); } @@ -218,7 +218,7 @@ void GridTileComponent::setSelected(bool selected, this->setSelectedZoom(1); auto func = [this](float t) { - t -= 1.0f; // Cubic ease out. + t -= 1.0f; float pct = Math::lerp(0, 1, t * t * t + 1.0f); this->setSelectedZoom(1.0f - pct); }; diff --git a/es-core/src/components/GridTileComponent.h b/es-core/src/components/GridTileComponent.h index bae039151..a4429e3f0 100644 --- a/es-core/src/components/GridTileComponent.h +++ b/es-core/src/components/GridTileComponent.h @@ -73,7 +73,7 @@ private: bool mSelected; bool mVisible; - Vector3f mAnimPosition; + glm::vec3 mAnimPosition; }; #endif // ES_CORE_COMPONENTS_GRID_TILE_COMPONENT_H diff --git a/es-core/src/components/ImageGridComponent.h b/es-core/src/components/ImageGridComponent.h index 22af36a65..0f6ef62af 100644 --- a/es-core/src/components/ImageGridComponent.h +++ b/es-core/src/components/ImageGridComponent.h @@ -101,7 +101,7 @@ private: Vector2f mAutoLayout; float mAutoLayoutZoom; - Vector4f mPadding; + glm::vec4 mPadding; Vector2f mMargin; Vector2f mTileSize; Vector2i mGridDimension; @@ -144,7 +144,7 @@ ImageGridComponent::ImageGridComponent(Window* window) mSize = screen * 0.80f; mMargin = screen * 0.07f; - mPadding = Vector4f::Zero(); + mPadding = {}; mTileSize = GridTileComponent::getDefaultTileSize(); mAnimate = true; @@ -280,8 +280,8 @@ void ImageGridComponent::applyTheme(const std::shared_ptr& theme, mMargin = elem->get("margin") * screen; if (elem->has("padding")) - mPadding = elem->get("padding") * - Vector4f(screen.x(), screen.y(), screen.x(), screen.y()); + mPadding = elem->get("padding") * + glm::vec4(screen.x(), screen.y(), screen.x(), screen.y()); if (elem->has("autoLayout")) mAutoLayout = elem->get("autoLayout"); @@ -506,7 +506,7 @@ template void ImageGridComponent::onCursorChanged(const CursorSt if (!moveCamera) return; - t -= 1.0f; // Cubic ease out. + t -= 1.0f; float pct = Math::lerp(0, 1.0f, t * t * t + 1.0f); t = startPos * (1.0f - pct) + endPos * pct; mCamera = t; @@ -538,12 +538,10 @@ template void ImageGridComponent::buildTiles() Vector2f tileDistance = mTileSize + mMargin; if (mAutoLayout.x() != 0.0f && mAutoLayout.y() != 0.0f) { - auto x = - (mSize.x() - (mMargin.x() * (mAutoLayout.x() - 1.0f)) - mPadding.x() - mPadding.z()) / - static_cast(mAutoLayout.x()); - auto y = - (mSize.y() - (mMargin.y() * (mAutoLayout.y() - 1.0f)) - mPadding.y() - mPadding.w()) / - static_cast(mAutoLayout.y()); + auto x = (mSize.x() - (mMargin.x() * (mAutoLayout.x() - 1.0f)) - mPadding.x - mPadding.z) / + static_cast(mAutoLayout.x()); + auto y = (mSize.y() - (mMargin.y() * (mAutoLayout.y() - 1.0f)) - mPadding.y - mPadding.w) / + static_cast(mAutoLayout.y()); mTileSize = Vector2f(x, y); tileDistance = mTileSize + mMargin; @@ -551,7 +549,8 @@ template void ImageGridComponent::buildTiles() bool vert = isVertical(); Vector2f startPosition = mTileSize / 2.0f; - startPosition += mPadding.v2(); + startPosition.x() += mPadding.x; + startPosition.y() += mPadding.y; int X; int Y; diff --git a/es-core/src/components/TextComponent.cpp b/es-core/src/components/TextComponent.cpp index c90e0d95a..0ca01fa57 100644 --- a/es-core/src/components/TextComponent.cpp +++ b/es-core/src/components/TextComponent.cpp @@ -33,7 +33,7 @@ TextComponent::TextComponent(Window* window, const std::shared_ptr& font, unsigned int color, Alignment align, - Vector3f pos, + glm::vec3 pos, Vector2f size, unsigned int bgcolor, float margin) @@ -54,11 +54,7 @@ TextComponent::TextComponent(Window* window, setColor(color); setBackgroundColor(bgcolor); setText(text); - - // TEMPORARY - glm::vec3 tempvec = { pos.x(), pos.y(), pos.z() }; - - setPosition(tempvec); + setPosition(pos); setSize(size); } diff --git a/es-core/src/components/TextComponent.h b/es-core/src/components/TextComponent.h index c9bf4f34f..05cbdb72a 100644 --- a/es-core/src/components/TextComponent.h +++ b/es-core/src/components/TextComponent.h @@ -30,7 +30,7 @@ public: const std::shared_ptr& font, unsigned int color = 0x000000FF, Alignment align = ALIGN_LEFT, - Vector3f pos = Vector3f::Zero(), + glm::vec3 pos = {}, Vector2f size = Vector2f::Zero(), unsigned int bgcolor = 0x00000000, float margin = 0.0f); diff --git a/es-core/src/renderers/Shader_GL21.h b/es-core/src/renderers/Shader_GL21.h index 2d64daea2..d7080ed7c 100644 --- a/es-core/src/renderers/Shader_GL21.h +++ b/es-core/src/renderers/Shader_GL21.h @@ -12,7 +12,6 @@ #define GL_GLEXT_PROTOTYPES #include "math/Misc.h" -#include "math/Vector3f.h" #if defined(_WIN64) #include