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 15, 2024
1 parent 9ff4aaf commit 88ade05
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 139 deletions.
4 changes: 2 additions & 2 deletions 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 e327277b1d001079a85f3959ba2fc802f7dbbc6b
GIT_TAG 0608821ff4e8de462d5aa44343df42d989f8102a
)

set_target_properties(sfml-system PROPERTIES UNITY_BUILD ON)
Expand Down Expand Up @@ -201,7 +201,7 @@ if(NOT SSVOH_ANDROID)
CPMAddPackage(
NAME imgui-sfml
GITHUB_REPOSITORY vittorioromeo/imgui-sfml
GIT_TAG 6ea83b31a67876fe8c3061297e2ac39033a8e0f3
GIT_TAG 32b2c1588b78b2946f8c7c61420fbd8a45ae4e9c
)

set_target_properties(ImGui-SFML PROPERTIES UNITY_BUILD ON)
Expand Down
8 changes: 7 additions & 1 deletion include/SSVOpenHexagon/Core/HexagonGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/Texture.hpp>

#include <SFML/Window/GraphicsContext.hpp>

#include <SFML/System/Vector2.hpp>
#include <SFML/System/Clock.hpp>

Expand Down Expand Up @@ -101,6 +103,9 @@ class HexagonGame
TextUI(HGAssets& mAssets);
};

sf::GraphicsContext* graphicsContext;
sf::base::Optional<sf::Texture> nullTexture;

Steam::steam_manager* steamManager;
Discord::discord_manager* discordManager;
bool discordHung{false};
Expand Down Expand Up @@ -453,7 +458,8 @@ class HexagonGame
public:
std::function<void(const bool)> fnGoToMenu;

HexagonGame(Steam::steam_manager* mSteamManager,
HexagonGame(sf::GraphicsContext* graphicsContext,
Steam::steam_manager* mSteamManager,
Discord::discord_manager* mDiscordManager, HGAssets& mAssets,
Audio* mAudio, ssvs::GameWindow* mGameWindow,
HexagonClient* mHexagonClient);
Expand Down
6 changes: 5 additions & 1 deletion include/SSVOpenHexagon/Core/MenuGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/Texture.hpp>

#include <SFML/Window/GraphicsContext.hpp>

#include <SFML/System/Vector2.hpp>

#include <array>
Expand Down Expand Up @@ -97,6 +99,7 @@ class MenuGame
//---------------------------------------
// Classes

sf::GraphicsContext& graphicsContext;
Steam::steam_manager& steamManager;
Discord::discord_manager& discordManager;
HGAssets& assets;
Expand Down Expand Up @@ -572,7 +575,8 @@ class MenuGame
const std::string& extra = "");

public:
MenuGame(Steam::steam_manager& mSteamManager,
MenuGame(sf::GraphicsContext& mGraphicsContext,
Steam::steam_manager& mSteamManager,
Discord::discord_manager& mDiscordManager, HGAssets& mAssets,
Audio& mAudio, ssvs::GameWindow& mGameWindow,
HexagonClient& mHexagonClient);
Expand Down
9 changes: 6 additions & 3 deletions include/SSVOpenHexagon/Global/AssetStorage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

#pragma once

#include "Imgui.hpp"
#include "SSVOpenHexagon/Utils/UniquePtr.hpp"

#include <string>

namespace sf {

class Font;
class GraphicsContext;
class SoundBuffer;
class Texture;
class Font;

} // namespace sf

Expand All @@ -32,10 +34,11 @@ class AssetStorage
explicit AssetStorage();
~AssetStorage();

[[nodiscard]] bool loadTexture(
[[nodiscard]] bool loadTexture(sf::GraphicsContext& graphicsContext,
const std::string& id, const std::string& path);

[[nodiscard]] bool loadFont(const std::string& id, const std::string& path);
[[nodiscard]] bool loadFont(sf::GraphicsContext& graphicsContext,
const std::string& id, const std::string& path);

[[nodiscard]] bool loadSoundBuffer(
const std::string& id, const std::string& path);
Expand Down
12 changes: 7 additions & 5 deletions include/SSVOpenHexagon/Global/Assets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
#include <vector>

namespace sf {
class SoundBuffer;
class Font;
class Texture;
class GraphicsContext;
class Shader;
class SoundBuffer;
class Texture;
} // namespace sf

namespace ssvu::FileSystem {
Expand Down Expand Up @@ -46,7 +47,8 @@ class HGAssets
Utils::UniquePtr<HGAssetsImpl> _impl;

public:
HGAssets(Steam::steam_manager* mSteamManager, bool mHeadless,
HGAssets(sf::GraphicsContext* graphicsContext,
Steam::steam_manager* mSteamManager, bool mHeadless,
bool mLevelsOnly = false);

~HGAssets();
Expand All @@ -55,8 +57,8 @@ class HGAssets

[[nodiscard]] LoadInfo& getLoadResults();

[[nodiscard]] bool hasTexture(const std::string& mId);
[[nodiscard]] sf::Texture& getTexture(const std::string& mId);
[[nodiscard]] sf::Texture& getTextureOrNullTexture(const std::string& mId);

[[nodiscard]] sf::Font& getFont(const std::string& mId);

Expand Down Expand Up @@ -99,7 +101,7 @@ class HGAssets
[[nodiscard]] sf::Shader* getShaderByShaderId(const std::size_t mShaderId);
[[nodiscard]] bool isValidShaderId(const std::size_t mShaderId) const;

void reloadAllShaders();
void reloadAllShaders(sf::GraphicsContext& graphicsContext);
[[nodiscard]] std::string reloadPack(
const std::string& mPackId, const std::string& mPath);
[[nodiscard]] std::string reloadLevel(const std::string& mPackId,
Expand Down
3 changes: 2 additions & 1 deletion include/SSVOpenHexagon/Global/Imgui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

namespace sf {
class Event;
class GraphicsContext;
class RenderTarget;
class RenderWindow;
class Window;
} // namespace sf

namespace hg::Imgui {

[[nodiscard]] bool initialize(sf::RenderWindow&);
[[nodiscard]] bool initialize(sf::GraphicsContext&, sf::RenderWindow&);
void shutdown();
[[nodiscard]] bool wantCaptureKeyboard();
[[nodiscard]] bool wantCaptureMouse();
Expand Down
24 changes: 13 additions & 11 deletions src/SSVOpenHexagon/Core/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <SFML/Audio/Music.hpp>
#include <SFML/Audio/PlaybackDevice.hpp>

#include <SFML/Base/Optional.hpp>

#include <optional>
#include <string>

Expand All @@ -34,7 +36,7 @@ class Audio::AudioImpl
// TODO (P2): remove these, roll own system
ssvs::SoundPlayer _soundPlayer;

std::optional<sf::Music> _music;
sf::base::Optional<sf::Music> _music;
float _musicVolume;
std::string _lastLoadedMusicPath;

Expand Down Expand Up @@ -75,15 +77,15 @@ class Audio::AudioImpl
SSVOH_ASSERT(volume >= 0.f && volume <= 100.f);
_musicVolume = volume;

if (_music.has_value())
if (_music.hasValue())
{
_music->setVolume(_musicVolume);
}
}

void resumeMusic()
{
if (_music.has_value())
if (_music.hasValue())
{
_music->setVolume(_musicVolume);
_music->play(_playbackDevice);
Expand All @@ -92,39 +94,39 @@ class Audio::AudioImpl

void pauseMusic()
{
if (_music.has_value())
if (_music.hasValue())
{
_music->pause();
}
}

void stopMusic()
{
if (_music.has_value())
if (_music.hasValue())
{
_music->stop();
}
}

void setMusicPlayingOffsetSeconds(const float seconds)
{
if (_music.has_value())
if (_music.hasValue())
{
_music->setPlayingOffset(sf::seconds(seconds));
}
}

void setMusicPlayingOffsetMilliseconds(const int milliseconds)
{
if (_music.has_value())
if (_music.hasValue())
{
_music->setPlayingOffset(sf::milliseconds(milliseconds));
}
}

[[nodiscard]] float getMusicPlayingOffsetSeconds() const
{
if (_music.has_value())
if (_music.hasValue())
{
return _music->getPlayingOffset().asSeconds();
}
Expand All @@ -134,7 +136,7 @@ class Audio::AudioImpl

[[nodiscard]] int getMusicPlayingOffsetMilliseconds() const
{
if (_music.has_value())
if (_music.hasValue())
{
return _music->getPlayingOffset().asMilliseconds();
}
Expand Down Expand Up @@ -197,7 +199,7 @@ class Audio::AudioImpl
_lastLoadedMusicPath = *path;
}

SSVOH_ASSERT(_music.has_value());
SSVOH_ASSERT(_music.hasValue());

_music->setLoop(true);
setMusicPlayingOffsetSeconds(playingOffsetSeconds);
Expand All @@ -208,7 +210,7 @@ class Audio::AudioImpl

void setCurrentMusicPitch(const float pitch)
{
if (_music.has_value())
if (_music.hasValue())
{
_music->setPitch(pitch);
}
Expand Down
3 changes: 2 additions & 1 deletion src/SSVOpenHexagon/Core/HGGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ void HexagonGame::draw()
{
if (window != nullptr)
{
window->saveScreenshot("screenshot.png");
SSVOH_ASSERT(graphicsContext != nullptr);
window->saveScreenshot(*graphicsContext, "screenshot.png");
}

mustTakeScreenshot = false;
Expand Down
4 changes: 2 additions & 2 deletions src/SSVOpenHexagon/Core/HGScripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

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

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window/Mouse.hpp>
#include <SFML/Window/Keyboard.hpp>

#include <iostream>
#include <string>
Expand Down
8 changes: 4 additions & 4 deletions src/SSVOpenHexagon/Core/HGUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ void HexagonGame::updateTrailParticles(float mFT)
TrailParticle p{sf::Sprite{txSmallCircle->getRect()}};

p.sprite.setPosition(player.getPosition());
p.sprite.setOrigin(sf::Vector2f{txSmallCircle->getSize()} / 2.f);
p.sprite.setOrigin(txSmallCircle->getSize().to<sf::Vector2f>() / 2.f);

const float scale = Config::getPlayerTrailScale();
p.sprite.setScale({scale, scale});
Expand Down Expand Up @@ -1030,7 +1030,7 @@ void HexagonGame::updateTrailParticles(float mFT)
p.sprite.setScale(p.sprite.getScale() * 0.98f);

p.sprite.setPosition(
sf::Vector2f(status.radius + 2.4f, sf::radians(p.angle)));
sf::Vector2f::fromAngle(status.radius + 2.4f, sf::radians(p.angle)));
}

if (player.hasChangedAngle())
Expand All @@ -1054,7 +1054,7 @@ void HexagonGame::updateSwapParticles(float mFT)
SwapParticle p{sf::Sprite(txSmallCircle->getRect())};

p.sprite.setPosition(si.position);
p.sprite.setOrigin(sf::Vector2f{txSmallCircle->getSize()} / 2.f);
p.sprite.setOrigin(txSmallCircle->getSize().to<sf::Vector2f>() / 2.f);

const float scale = ssvu::getRndR(0.65f, 1.35f) * scaleMult;
p.sprite.setScale({scale, scale});
Expand All @@ -1064,7 +1064,7 @@ void HexagonGame::updateSwapParticles(float mFT)
c.a = alpha;
p.sprite.setColor(c);

p.velocity = sf::Vector2f(ssvu::getRndR(0.1f, 10.f) * speedMult,
p.velocity = sf::Vector2f::fromAngle(ssvu::getRndR(0.1f, 10.f) * speedMult,
sf::radians(si.angle + ssvu::getRndR(-expand, expand)));

return p;
Expand Down
Loading

0 comments on commit 88ade05

Please sign in to comment.