Skip to content

Commit

Permalink
Adapt to newest SFML
Browse files Browse the repository at this point in the history
  • Loading branch information
vittorioromeo committed Jul 2, 2024
1 parent 6fa692d commit 473cdae
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 77 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions include/SSVOpenHexagon/Components/CWall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions include/SSVOpenHexagon/Core/HexagonGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include <SSVStart/GameSystem/GameSystem.hpp>
#include <SSVStart/Camera/Camera.hpp>

#include <SSVUtils/Timeline/Timeline.hpp>

#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
Expand Down Expand Up @@ -159,8 +157,6 @@ class HexagonGame

std::optional<PreShakeCenters> preShakeCenters;

ssvu::TimelineManager effectTimelineManager;

const sf::Vector2f centerPos{0.f, 0.f};

Lua::LuaContext lua;
Expand Down
7 changes: 1 addition & 6 deletions include/SSVOpenHexagon/Global/PCH.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,11 @@
// SSVUtils
// ----------------------------------------------------------------------------

#include <SSVUtils/Core/Detection/Detection.hpp>
#include <SSVUtils/Core/Common/Common.hpp>

#include <SSVUtils/Core/Common/Frametime.hpp>
#include <SSVUtils/Core/FileSystem/FileSystem.hpp>
#include <SSVUtils/Core/Log/Log.hpp>
#include <SSVUtils/Core/Utils/Containers.hpp>
#include <SSVUtils/Core/Utils/Math.hpp>
#include <SSVUtils/Core/Utils/Rnd.hpp>
#include <SSVUtils/Internal/PCG/PCG.hpp>
#include <SSVUtils/Timeline/Timeline.hpp>

//
//
Expand Down
20 changes: 12 additions & 8 deletions include/SSVOpenHexagon/Utils/TinyVariant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,9 @@ class [[nodiscard]] tinyvariant
return static_cast<nth_type<I>&&>(as<nth_type<I>>());
}

template <typename Visitor, typename R = decltype(impl::declval<Visitor&&>()(
impl::declval<nth_type<0>&>()))>
template <typename Visitor,
typename R = decltype(impl::declval<Visitor&&>()(
impl::declval<nth_type<0>&>()))>
[[nodiscard, gnu::always_inline]] R recursive_visit(Visitor&& visitor) &
{
if constexpr (sizeof...(Alternatives) >= 10)
Expand All @@ -670,8 +671,9 @@ class [[nodiscard]] tinyvariant
}
}

template <typename Visitor, typename R = decltype(impl::declval<Visitor&&>()(
impl::declval<const nth_type<0>&>()))>
template <typename Visitor,
typename R = decltype(impl::declval<Visitor&&>()(
impl::declval<const nth_type<0>&>()))>
[[nodiscard, gnu::always_inline]] R recursive_visit(
Visitor&& visitor) const&
{
Expand Down Expand Up @@ -707,8 +709,9 @@ class [[nodiscard]] tinyvariant
return recursive_visit(impl::overload_set{static_cast<Fs&&>(fs)...});
}

template <typename Visitor, typename R = decltype(impl::declval<Visitor&&>()(
impl::declval<nth_type<0>&>()))>
template <typename Visitor,
typename R = decltype(impl::declval<Visitor&&>()(
impl::declval<nth_type<0>&>()))>
[[nodiscard, gnu::always_inline]] R linear_visit(Visitor&& visitor) &
{
if constexpr (impl::is_reference<R>)
Expand All @@ -734,8 +737,9 @@ class [[nodiscard]] tinyvariant
}


template <typename Visitor, typename R = decltype(impl::declval<Visitor&&>()(
impl::declval<nth_type<0>&>()))>
template <typename Visitor,
typename R = decltype(impl::declval<Visitor&&>()(
impl::declval<nth_type<0>&>()))>
[[nodiscard, gnu::always_inline]] R linear_visit(Visitor&& visitor) const&
{
if constexpr (impl::is_reference<R>)
Expand Down
35 changes: 17 additions & 18 deletions src/SSVOpenHexagon/Components/CPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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));
}
}
}
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions src/SSVOpenHexagon/Components/CWall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
17 changes: 14 additions & 3 deletions src/SSVOpenHexagon/Core/CCustomWallManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@
#include "SSVOpenHexagon/Components/CPlayer.hpp"

#include <SSVUtils/Core/Log/Log.hpp>
#include <SSVUtils/Core/Utils/Containers.hpp>


namespace {

template <typename TC, typename TV>
inline bool contains(const TC& mContainer, const TV& mValue)
{
return std::find(mContainer.begin(), mContainer.end(), mValue) !=
std::end(mContainer);
}

} // namespace

namespace hg {

Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down
30 changes: 19 additions & 11 deletions src/SSVOpenHexagon/Core/HGUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -27,26 +26,37 @@
#include "SSVOpenHexagon/Core/Joystick.hpp"
#include "SSVOpenHexagon/Core/LuaScripting.hpp"
#include "SSVOpenHexagon/Core/Steam.hpp"
#include "SSVUtils/Core/Utils/Rnd.hpp"

#include <SSVUtils/Core/Utils/Rnd.hpp>
#include <SSVUtils/Core/Common/Frametime.hpp>

#ifndef SSVOH_ANDROID
#include <imgui.h>
#include <misc/cpp/imgui_stdlib.h>
#include <imgui-SFML.h>
#endif

#include <SSVUtils/Core/Utils/Containers.hpp>

#include <SFML/Graphics/Color.hpp>
#include <SFML/System/Vector2.hpp>

#include <array>
#include <optional>
#include <stdexcept>

#include <cstring>
#include <cstdint>

namespace {

template <typename TC, typename TP>
[[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)
Expand Down Expand Up @@ -164,7 +174,6 @@ void HexagonGame::update(float mFT, const float timescale)
if (!debugPause)
{
updateFlash(mFT);
effectTimelineManager.update(mFT);

if (!mustReplayInput())
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -959,7 +967,7 @@ void HexagonGame::updateParticles(float mFT)
return p;
};

ssvu::eraseRemoveIf(particles, isOutOfBounds);
eraseRemoveIf(particles, isOutOfBounds);

for (Particle& p : particles)
{
Expand Down Expand Up @@ -1007,7 +1015,7 @@ void HexagonGame::updateTrailParticles(float mFT)
return p;
};

ssvu::eraseRemoveIf(trailParticles, isDead);
eraseRemoveIf(trailParticles, isDead);

for (TrailParticle& p : trailParticles)
{
Expand Down Expand Up @@ -1062,7 +1070,7 @@ void HexagonGame::updateSwapParticles(float mFT)
return p;
};

ssvu::eraseRemoveIf(swapParticles, isDead);
eraseRemoveIf(swapParticles, isDead);

for (SwapParticle& p : swapParticles)
{
Expand Down
1 change: 0 additions & 1 deletion src/SSVOpenHexagon/Core/HexagonGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,6 @@ void HexagonGame::newGame(const std::string& mPackId, const std::string& mId,
timeline.clear();
timelineRunner = {};

effectTimelineManager.clear();
mustChangeSides = false;
mustStart = false;

Expand Down
15 changes: 7 additions & 8 deletions src/SSVOpenHexagon/Core/MenuGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
Expand Down Expand Up @@ -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(
Expand Down
Loading

0 comments on commit 473cdae

Please sign in to comment.