From 473cdaef699d9ff6159e0ce911e0d1d1d3b737a5 Mon Sep 17 00:00:00 2001 From: vittorioromeo Date: Tue, 2 Jul 2024 19:08:10 +0200 Subject: [PATCH] Adapt to newest SFML --- CMakeLists.txt | 2 +- include/SSVOpenHexagon/Components/CWall.hpp | 3 +- include/SSVOpenHexagon/Core/HexagonGame.hpp | 4 --- include/SSVOpenHexagon/Global/PCH.hpp | 7 +--- include/SSVOpenHexagon/Utils/TinyVariant.hpp | 20 ++++++----- src/SSVOpenHexagon/Components/CPlayer.cpp | 35 +++++++++---------- src/SSVOpenHexagon/Components/CWall.cpp | 10 +++--- .../Core/CCustomWallManager.cpp | 17 +++++++-- src/SSVOpenHexagon/Core/HGUpdate.cpp | 30 ++++++++++------ src/SSVOpenHexagon/Core/HexagonGame.cpp | 1 - src/SSVOpenHexagon/Core/MenuGame.cpp | 15 ++++---- src/SSVOpenHexagon/Data/StyleData.cpp | 14 ++++---- src/SSVOpenHexagon/Utils/Utils.cpp | 1 - 13 files changed, 82 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ce4e378..1a00b6b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,7 @@ set(SFML_ENABLE_PCH true) CPMAddPackage( NAME SFML GITHUB_REPOSITORY vittorioromeo/SFML - GIT_TAG 901d09fc3f4d9bc0c5249066e592244642130d3a + GIT_TAG 082d6eabdf5ffd8b79bc6f7beba80adf318b4cf6 ) # set_target_properties(sfml-system PROPERTIES UNITY_BUILD ON) diff --git a/include/SSVOpenHexagon/Components/CWall.hpp b/include/SSVOpenHexagon/Components/CWall.hpp index 6c12a197..cba6ef7a 100644 --- a/include/SSVOpenHexagon/Components/CWall.hpp +++ b/include/SSVOpenHexagon/Components/CWall.hpp @@ -51,8 +51,7 @@ class CWall vertex.y = tempX * xSin + tempY * xCos + centerPos.y; } - [[gnu::always_inline]] float getCurveRadians( - const float ft) const noexcept + [[gnu::always_inline]] float getCurveRadians(const float ft) const noexcept { constexpr float divBy60 = 1.f / 60.f; return _curve._speed * divBy60 * ft; diff --git a/include/SSVOpenHexagon/Core/HexagonGame.hpp b/include/SSVOpenHexagon/Core/HexagonGame.hpp index d82cce90..b2b10d0e 100644 --- a/include/SSVOpenHexagon/Core/HexagonGame.hpp +++ b/include/SSVOpenHexagon/Core/HexagonGame.hpp @@ -25,8 +25,6 @@ #include #include -#include - #include #include #include @@ -159,8 +157,6 @@ class HexagonGame std::optional preShakeCenters; - ssvu::TimelineManager effectTimelineManager; - const sf::Vector2f centerPos{0.f, 0.f}; Lua::LuaContext lua; diff --git a/include/SSVOpenHexagon/Global/PCH.hpp b/include/SSVOpenHexagon/Global/PCH.hpp index 464a4f95..d719f10a 100644 --- a/include/SSVOpenHexagon/Global/PCH.hpp +++ b/include/SSVOpenHexagon/Global/PCH.hpp @@ -149,16 +149,11 @@ // SSVUtils // ---------------------------------------------------------------------------- -#include -#include - +#include #include #include -#include -#include #include #include -#include // // diff --git a/include/SSVOpenHexagon/Utils/TinyVariant.hpp b/include/SSVOpenHexagon/Utils/TinyVariant.hpp index 53eee36b..6a20064a 100644 --- a/include/SSVOpenHexagon/Utils/TinyVariant.hpp +++ b/include/SSVOpenHexagon/Utils/TinyVariant.hpp @@ -650,8 +650,9 @@ class [[nodiscard]] tinyvariant return static_cast&&>(as>()); } - template ()( - impl::declval&>()))> + template ()( + impl::declval&>()))> [[nodiscard, gnu::always_inline]] R recursive_visit(Visitor&& visitor) & { if constexpr (sizeof...(Alternatives) >= 10) @@ -670,8 +671,9 @@ class [[nodiscard]] tinyvariant } } - template ()( - impl::declval&>()))> + template ()( + impl::declval&>()))> [[nodiscard, gnu::always_inline]] R recursive_visit( Visitor&& visitor) const& { @@ -707,8 +709,9 @@ class [[nodiscard]] tinyvariant return recursive_visit(impl::overload_set{static_cast(fs)...}); } - template ()( - impl::declval&>()))> + template ()( + impl::declval&>()))> [[nodiscard, gnu::always_inline]] R linear_visit(Visitor&& visitor) & { if constexpr (impl::is_reference) @@ -734,8 +737,9 @@ class [[nodiscard]] tinyvariant } - template ()( - impl::declval&>()))> + template ()( + impl::declval&>()))> [[nodiscard, gnu::always_inline]] R linear_visit(Visitor&& visitor) const& { if constexpr (impl::is_reference) diff --git a/src/SSVOpenHexagon/Components/CPlayer.cpp b/src/SSVOpenHexagon/Components/CPlayer.cpp index eace649b..cb1d39b2 100644 --- a/src/SSVOpenHexagon/Components/CPlayer.cpp +++ b/src/SSVOpenHexagon/Components/CPlayer.cpp @@ -90,17 +90,17 @@ void CPlayer::draw(const unsigned int sides, const sf::Color& colorMain, const float tiltedAngle = _angle + (_currTiltedAngle * Utils::toRad(24.f) * angleTiltIntensity); - const sf::Vector2f pLeft = _pos.movedAndRotatedBy( + const sf::Vector2f pLeft = _pos.movedTowards( _size + _triangleWidth, sf::radians(tiltedAngle - Utils::toRad(100.f))); - const sf::Vector2f pRight = _pos.movedAndRotatedBy( + const sf::Vector2f pRight = _pos.movedTowards( _size + _triangleWidth, sf::radians(tiltedAngle + Utils::toRad(100.f))); playerTris.reserve_more(3); playerTris.batch_unsafe_emplace_back( swapBlinkingEffect ? getColorAdjustedForSwap(colorPlayer) : getColor(colorPlayer), - _pos.movedAndRotatedBy(_size, sf::radians(tiltedAngle)), pLeft, pRight); + _pos.movedTowards(_size, sf::radians(tiltedAngle)), pLeft, pRight); } void CPlayer::drawPivot(const unsigned int sides, const sf::Color& colorMain, @@ -118,12 +118,12 @@ void CPlayer::drawPivot(const unsigned int sides, const sf::Color& colorMain, const float sAngle{div * 2.f * i}; const sf::Vector2f p1{ - _startPos.movedAndRotatedBy(pRadius, sf::radians(sAngle - div))}; + _startPos.movedTowards(pRadius, sf::radians(sAngle - div))}; const sf::Vector2f p2{ - _startPos.movedAndRotatedBy(pRadius, sf::radians(sAngle + div))}; - const sf::Vector2f p3{_startPos.movedAndRotatedBy( + _startPos.movedTowards(pRadius, sf::radians(sAngle + div))}; + const sf::Vector2f p3{_startPos.movedTowards( pRadius + baseThickness, sf::radians(sAngle + div))}; - const sf::Vector2f p4{_startPos.movedAndRotatedBy( + const sf::Vector2f p4{_startPos.movedTowards( pRadius + baseThickness, sf::radians(sAngle - div))}; wallQuads.batch_unsafe_emplace_back_quad(colorMain, p1, p2, p3, p4); @@ -146,13 +146,13 @@ void CPlayer::drawDeathEffect(Utils::FastVertexVectorTris& wallQuads) const float sAngle{div * 2.f * i}; const sf::Vector2f p1{ - _pos.movedAndRotatedBy(dRadius, sf::radians(sAngle - div))}; + _pos.movedTowards(dRadius, sf::radians(sAngle - div))}; const sf::Vector2f p2{ - _pos.movedAndRotatedBy(dRadius, sf::radians(sAngle + div))}; - const sf::Vector2f p3{_pos.movedAndRotatedBy( - dRadius + thickness, sf::radians(sAngle + div))}; - const sf::Vector2f p4{_pos.movedAndRotatedBy( - dRadius + thickness, sf::radians(sAngle - div))}; + _pos.movedTowards(dRadius, sf::radians(sAngle + div))}; + const sf::Vector2f p3{ + _pos.movedTowards(dRadius + thickness, sf::radians(sAngle + div))}; + const sf::Vector2f p4{ + _pos.movedTowards(dRadius + thickness, sf::radians(sAngle - div))}; wallQuads.batch_unsafe_emplace_back_quad(colorMain, p1, p2, p3, p4); } @@ -177,7 +177,7 @@ void CPlayer::kill(const bool fatal) { // Move back position to graphically show the tip of the triangle // hitting the wall rather than the center of the triangle. - _pos = _lastPos.movedAndRotatedBy(-_size, sf::radians(_angle)); + _pos = _lastPos.movedTowards(-_size, sf::radians(_angle)); } } } @@ -486,12 +486,11 @@ void CPlayer::updatePosition(const float radius) { _radius = radius; - _prePushPos = _pos = - _startPos.movedAndRotatedBy(_radius, sf::radians(_angle)); - _lastPos = _startPos.movedAndRotatedBy(_radius, sf::radians(_lastAngle)); + _prePushPos = _pos = _startPos.movedTowards(_radius, sf::radians(_angle)); + _lastPos = _startPos.movedTowards(_radius, sf::radians(_lastAngle)); _maxSafeDistance = - (_lastPos - _startPos.movedAndRotatedBy(_radius, + (_lastPos - _startPos.movedTowards(_radius, sf::radians(_lastAngle + Utils::toRad(_currentSpeed)))) .lengthSq() + 32.f; diff --git a/src/SSVOpenHexagon/Components/CWall.cpp b/src/SSVOpenHexagon/Components/CWall.cpp index 687f1736..1a9bf988 100644 --- a/src/SSVOpenHexagon/Components/CWall.cpp +++ b/src/SSVOpenHexagon/Components/CWall.cpp @@ -24,18 +24,16 @@ CWall::CWall(const unsigned int sides, const float wallAngleLeft, const float angleN = angle - div; const float angleP = angle + div; - _vertexPositions[0] = - centerPos.movedAndRotatedBy(distance, sf::radians(angleN)); + _vertexPositions[0] = centerPos.movedTowards(distance, sf::radians(angleN)); - _vertexPositions[1] = - centerPos.movedAndRotatedBy(distance, sf::radians(angleP)); + _vertexPositions[1] = centerPos.movedTowards(distance, sf::radians(angleP)); _vertexPositions[2] = - centerPos.movedAndRotatedBy(distance + thickness + wallSkewLeft, + centerPos.movedTowards(distance + thickness + wallSkewLeft, sf::radians(angleP + wallAngleLeft)); _vertexPositions[3] = - centerPos.movedAndRotatedBy(distance + thickness + wallSkewRight, + centerPos.movedTowards(distance + thickness + wallSkewRight, sf::radians(angleN + wallAngleRight)); } diff --git a/src/SSVOpenHexagon/Core/CCustomWallManager.cpp b/src/SSVOpenHexagon/Core/CCustomWallManager.cpp index eb6d0afc..09149f7c 100644 --- a/src/SSVOpenHexagon/Core/CCustomWallManager.cpp +++ b/src/SSVOpenHexagon/Core/CCustomWallManager.cpp @@ -9,7 +9,18 @@ #include "SSVOpenHexagon/Components/CPlayer.hpp" #include -#include + + +namespace { + +template +inline bool contains(const TC& mContainer, const TV& mValue) +{ + return std::find(mContainer.begin(), mContainer.end(), mValue) != + std::end(mContainer); +} + +} // namespace namespace hg { @@ -30,7 +41,7 @@ namespace hg { << "Attempted to " << msg << " of invalid custom wall " << h << '\n'; - SSVOH_ASSERT(ssvu::contains(_freeHandles, h)); + SSVOH_ASSERT(contains(_freeHandles, h)); return false; } @@ -103,7 +114,7 @@ void CCustomWallManager::destroyUnchecked(const CCustomWallHandle cwHandle) _handleAvailable[cwHandle] = true; --_count; - SSVOH_ASSERT(!ssvu::contains(_freeHandles, cwHandle)); + SSVOH_ASSERT(!contains(_freeHandles, cwHandle)); _freeHandles.emplace_back(cwHandle); } diff --git a/src/SSVOpenHexagon/Core/HGUpdate.cpp b/src/SSVOpenHexagon/Core/HGUpdate.cpp index b8a21b54..7d285cca 100644 --- a/src/SSVOpenHexagon/Core/HGUpdate.cpp +++ b/src/SSVOpenHexagon/Core/HGUpdate.cpp @@ -16,7 +16,6 @@ #include "SSVOpenHexagon/Utils/Clock.hpp" #include "SSVOpenHexagon/Utils/Concat.hpp" #include "SSVOpenHexagon/Utils/Easing.hpp" -#include "SSVOpenHexagon/Utils/LevelValidator.hpp" #include "SSVOpenHexagon/Utils/Math.hpp" #include "SSVOpenHexagon/Utils/MoveTowards.hpp" #include "SSVOpenHexagon/Utils/Split.hpp" @@ -27,7 +26,9 @@ #include "SSVOpenHexagon/Core/Joystick.hpp" #include "SSVOpenHexagon/Core/LuaScripting.hpp" #include "SSVOpenHexagon/Core/Steam.hpp" -#include "SSVUtils/Core/Utils/Rnd.hpp" + +#include +#include #ifndef SSVOH_ANDROID #include @@ -35,18 +36,27 @@ #include #endif -#include - #include #include -#include #include #include #include #include +namespace { + +template +[[gnu::always_inline]] inline void eraseRemoveIf(TC& mContainer, TP mPredicate) +{ + mContainer.erase( + std::remove_if(mContainer.begin(), mContainer.end(), mPredicate), + std::end(mContainer)); +} + +} // namespace + namespace hg { void HexagonGame::fastForwardTo(const double target) @@ -164,7 +174,6 @@ void HexagonGame::update(float mFT, const float timescale) if (!debugPause) { updateFlash(mFT); - effectTimelineManager.update(mFT); if (!mustReplayInput()) { @@ -318,8 +327,7 @@ void HexagonGame::update(float mFT, const float timescale) player.updatePosition(getRadius()); updateWalls(mFT); - ssvu::eraseRemoveIf( - walls, [](const CWall& w) { return w.isDead(); }); + eraseRemoveIf(walls, [](const CWall& w) { return w.isDead(); }); updateCustomWalls(mFT); } @@ -959,7 +967,7 @@ void HexagonGame::updateParticles(float mFT) return p; }; - ssvu::eraseRemoveIf(particles, isOutOfBounds); + eraseRemoveIf(particles, isOutOfBounds); for (Particle& p : particles) { @@ -1007,7 +1015,7 @@ void HexagonGame::updateTrailParticles(float mFT) return p; }; - ssvu::eraseRemoveIf(trailParticles, isDead); + eraseRemoveIf(trailParticles, isDead); for (TrailParticle& p : trailParticles) { @@ -1062,7 +1070,7 @@ void HexagonGame::updateSwapParticles(float mFT) return p; }; - ssvu::eraseRemoveIf(swapParticles, isDead); + eraseRemoveIf(swapParticles, isDead); for (SwapParticle& p : swapParticles) { diff --git a/src/SSVOpenHexagon/Core/HexagonGame.cpp b/src/SSVOpenHexagon/Core/HexagonGame.cpp index d48823a8..00f28ed4 100644 --- a/src/SSVOpenHexagon/Core/HexagonGame.cpp +++ b/src/SSVOpenHexagon/Core/HexagonGame.cpp @@ -725,7 +725,6 @@ void HexagonGame::newGame(const std::string& mPackId, const std::string& mId, timeline.clear(); timelineRunner = {}; - effectTimelineManager.clear(); mustChangeSides = false; mustStart = false; diff --git a/src/SSVOpenHexagon/Core/MenuGame.cpp b/src/SSVOpenHexagon/Core/MenuGame.cpp index c2405bc0..a1ffa4f9 100644 --- a/src/SSVOpenHexagon/Core/MenuGame.cpp +++ b/src/SSVOpenHexagon/Core/MenuGame.cpp @@ -943,8 +943,7 @@ void MenuGame::initInput() addTidInput(Tid::Down, t::Once, [this](float) { downAction(); }); - addTidInput( - Tid::NextPack, t::Once, [this](float) { changePackAction(1); }); + addTidInput(Tid::NextPack, t::Once, [this](float) { changePackAction(1); }); addTidInput( Tid::PreviousPack, t::Once, [this](float) { changePackAction(-1); }); @@ -4174,13 +4173,13 @@ void MenuGame::drawLoadResults() { const float sAngle{div * 2.f * (i + hexagonRotation)}; - const sf::Vector2f nw{centerPos.movedAndRotatedBy( - hexagonRadius, sf::radians(sAngle - div))}; - const sf::Vector2f ne{centerPos.movedAndRotatedBy( - hexagonRadius, sf::radians(sAngle + div))}; - const sf::Vector2f se{centerPos.movedAndRotatedBy( + const sf::Vector2f nw{ + centerPos.movedTowards(hexagonRadius, sf::radians(sAngle - div))}; + const sf::Vector2f ne{ + centerPos.movedTowards(hexagonRadius, sf::radians(sAngle + div))}; + const sf::Vector2f se{centerPos.movedTowards( hexagonRadius + 10.f, sf::radians(sAngle + div))}; - const sf::Vector2f sw{centerPos.movedAndRotatedBy( + const sf::Vector2f sw{centerPos.movedTowards( hexagonRadius + 10.f, sf::radians(sAngle - div))}; menuQuads.batch_unsafe_emplace_back_quad( diff --git a/src/SSVOpenHexagon/Data/StyleData.cpp b/src/SSVOpenHexagon/Data/StyleData.cpp index 8e4fb080..c946f1c6 100644 --- a/src/SSVOpenHexagon/Data/StyleData.cpp +++ b/src/SSVOpenHexagon/Data/StyleData.cpp @@ -227,10 +227,8 @@ void StyleData::drawBackgroundImpl(Utils::FastVertexVectorTris& vertices, } vertices.batch_unsafe_emplace_back(currentColor, mCenterPos, - mCenterPos.movedAndRotatedBy( - distance, sf::radians(angle + halfDiv)), - mCenterPos.movedAndRotatedBy( - distance, sf::radians(angle - halfDiv))); + mCenterPos.movedTowards(distance, sf::radians(angle + halfDiv)), + mCenterPos.movedTowards(distance, sf::radians(angle - halfDiv))); } } @@ -253,15 +251,15 @@ void StyleData::drawBackgroundMenuHexagonImpl( const float angle{Utils::toRad(BGRotOff) + div * i}; vertices.batch_unsafe_emplace_back(colorMain, mCenterPos, - mCenterPos.movedAndRotatedBy( + mCenterPos.movedTowards( hexagonRadius + 10.f, sf::radians(angle + halfDiv)), - mCenterPos.movedAndRotatedBy( + mCenterPos.movedTowards( hexagonRadius + 10.f, sf::radians(angle - halfDiv))); vertices.batch_unsafe_emplace_back(colorCap, mCenterPos, - mCenterPos.movedAndRotatedBy( + mCenterPos.movedTowards( hexagonRadius, sf::radians(angle + halfDiv)), - mCenterPos.movedAndRotatedBy( + mCenterPos.movedTowards( hexagonRadius, sf::radians(angle - halfDiv))); } } diff --git a/src/SSVOpenHexagon/Utils/Utils.cpp b/src/SSVOpenHexagon/Utils/Utils.cpp index c2503c1d..ab6046c2 100644 --- a/src/SSVOpenHexagon/Utils/Utils.cpp +++ b/src/SSVOpenHexagon/Utils/Utils.cpp @@ -12,7 +12,6 @@ #include -#include #include #include