Skip to content

Commit

Permalink
Adapt to newest fork version
Browse files Browse the repository at this point in the history
  • Loading branch information
vittorioromeo committed Jul 5, 2024
1 parent 473cdae commit 9ff4aaf
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 27 deletions.
31 changes: 24 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,23 @@ set(SFML_ENABLE_PCH true)
CPMAddPackage(
NAME SFML
GITHUB_REPOSITORY vittorioromeo/SFML
GIT_TAG 082d6eabdf5ffd8b79bc6f7beba80adf318b4cf6
GIT_TAG e327277b1d001079a85f3959ba2fc802f7dbbc6b
)

# set_target_properties(sfml-system PROPERTIES UNITY_BUILD ON)
# set_target_properties(sfml-window PROPERTIES UNITY_BUILD ON)
# set_target_properties(sfml-graphics PROPERTIES UNITY_BUILD ON)
# set_target_properties(sfml-audio PROPERTIES UNITY_BUILD ON)
# set_target_properties(sfml-network PROPERTIES UNITY_BUILD ON)
set_target_properties(sfml-system PROPERTIES UNITY_BUILD ON)
set_target_properties(sfml-system PROPERTIES UNITY_BUILD_BATCH_SIZE 512)

set_target_properties(sfml-window PROPERTIES UNITY_BUILD ON)
set_target_properties(sfml-window PROPERTIES UNITY_BUILD_BATCH_SIZE 512)

set_target_properties(sfml-graphics PROPERTIES UNITY_BUILD ON)
set_target_properties(sfml-graphics PROPERTIES UNITY_BUILD_BATCH_SIZE 512)

set_target_properties(sfml-audio PROPERTIES UNITY_BUILD ON)
set_target_properties(sfml-audio PROPERTIES UNITY_BUILD_BATCH_SIZE 512)

set_target_properties(sfml-network PROPERTIES UNITY_BUILD ON)
set_target_properties(sfml-network PROPERTIES UNITY_BUILD_BATCH_SIZE 512)

#
#
Expand All @@ -125,6 +134,9 @@ CPMAddPackage(
set(LUAJIT_DISABLE_FFI true)
set(LUAJIT_DISABLE_FFI ON CACHE BOOL "" FORCE)

set_target_properties(libluajit PROPERTIES UNITY_BUILD ON)
set_target_properties(libluajit PROPERTIES UNITY_BUILD_BATCH_SIZE 512)

# Remove linking against libm on MinGW
if(WIN32)
file(READ "${luajit_SOURCE_DIR}/src/CMakeLists.txt" CONTENTS)
Expand All @@ -144,6 +156,8 @@ CPMAddPackage(
GIT_TAG cacf7f1d4e3d44d871b605da3b647f07d718623f
)

set_target_properties(zlib PROPERTIES UNITY_BUILD OFF) # not supported

# Remove example binaries from CMakeLists
file(READ "${zlib_SOURCE_DIR}/CMakeLists.txt" CONTENTS)
string(REGEX REPLACE "Example binaries.*" "" STRIPPED1 "${CONTENTS}")
Expand Down Expand Up @@ -187,10 +201,11 @@ if(NOT SSVOH_ANDROID)
CPMAddPackage(
NAME imgui-sfml
GITHUB_REPOSITORY vittorioromeo/imgui-sfml
GIT_TAG ea57da2bf7c7d4d66a10009371d96a31718bca45
GIT_TAG 6ea83b31a67876fe8c3061297e2ac39033a8e0f3
)

set_target_properties(ImGui-SFML PROPERTIES UNITY_BUILD ON)
set_target_properties(ImGui-SFML PROPERTIES UNITY_BUILD_BATCH_SIZE 512)
endif()

#
Expand All @@ -212,6 +227,8 @@ CPMAddPackage(
set(SODIUM_DISABLE_TESTS ON)
set(SODIUM_DISABLE_TESTS ON CACHE BOOL "" FORCE)

set_target_properties(sodium PROPERTIES UNITY_BUILD OFF) # not supported

#
#
# -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion extlibs/SSVMenuSystem
2 changes: 1 addition & 1 deletion extlibs/SSVStart
2 changes: 1 addition & 1 deletion extlibs/SSVUtils
6 changes: 4 additions & 2 deletions include/SSVOpenHexagon/Global/Audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
#include <functional>

namespace sf {
class PlaybackDevice;
class SoundBuffer;
}
} // namespace sf

namespace hg {

Expand All @@ -33,7 +34,8 @@ class Audio
[[nodiscard]] AudioImpl& impl() noexcept;

public:
explicit Audio(const SoundBufferGetter& soundBufferGetter,
explicit Audio(sf::PlaybackDevice& playbackDevice,
const SoundBufferGetter& soundBufferGetter,
const MusicPathGetter& musicPathGetter);

~Audio();
Expand Down
18 changes: 12 additions & 6 deletions src/SSVOpenHexagon/Core/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <SFML/Audio/SoundBuffer.hpp>
#include <SFML/Audio/Music.hpp>
#include <SFML/Audio/PlaybackDevice.hpp>

#include <optional>
#include <string>
Expand All @@ -26,6 +27,7 @@ class Audio::AudioImpl
{
private:
// TODO (P2): cleaner way of doing this
sf::PlaybackDevice& _playbackDevice;
SoundBufferGetter _soundBufferGetter;
MusicPathGetter _musicPathGetter;

Expand All @@ -43,14 +45,16 @@ class Audio::AudioImpl
if (sf::SoundBuffer* soundBuffer = _soundBufferGetter(assetId);
soundBuffer != nullptr)
{
_soundPlayer.play(*soundBuffer, mode);
_soundPlayer.play(_playbackDevice, *soundBuffer, mode);
}
}

public:
explicit AudioImpl(const SoundBufferGetter& soundBufferGetter,
explicit AudioImpl(sf::PlaybackDevice& playbackDevice,
const SoundBufferGetter& soundBufferGetter,
const MusicPathGetter& musicPathGetter)
: _soundBufferGetter{soundBufferGetter},
: _playbackDevice{playbackDevice},
_soundBufferGetter{soundBufferGetter},
_musicPathGetter{musicPathGetter},
_soundPlayer{},
_music{},
Expand Down Expand Up @@ -82,7 +86,7 @@ class Audio::AudioImpl
if (_music.has_value())
{
_music->setVolume(_musicVolume);
_music->play();
_music->play(_playbackDevice);
}
}

Expand Down Expand Up @@ -223,9 +227,11 @@ class Audio::AudioImpl
return *_impl;
}

Audio::Audio(const SoundBufferGetter& soundBufferGetter,
Audio::Audio(sf::PlaybackDevice& playbackDevice,
const SoundBufferGetter& soundBufferGetter,
const MusicPathGetter& musicPathGetter)
: _impl{Utils::makeUnique<AudioImpl>(soundBufferGetter, musicPathGetter)}
: _impl{Utils::makeUnique<AudioImpl>(
playbackDevice, soundBufferGetter, musicPathGetter)}
{}

Audio::~Audio() = default;
Expand Down
61 changes: 52 additions & 9 deletions src/SSVOpenHexagon/Core/LuaScripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,13 @@ static void initShaders(Lua::LuaContext& lua, HGAssets& assets,
const std::size_t shaderId, const std::string& name, const float a)
{
withValidShaderId("shdr_setUniformF", shaderId,
[&](sf::Shader& shader) { shader.setUniformUnsafe(name, a); });
[&](sf::Shader& shader)
{
const auto location =
shader.getUniformLocation(name)
.value(); // TODO: optimization opportunity
shader.setUniformUnsafe(location, a);
});
})
.arg("shaderId")
.arg("name")
Expand All @@ -1389,7 +1395,12 @@ static void initShaders(Lua::LuaContext& lua, HGAssets& assets,
{
withValidShaderId("shdr_setUniformFVec2", shaderId,
[&](sf::Shader& shader)
{ shader.setUniformUnsafe(name, sf::Glsl::Vec2{a, b}); });
{
const auto location =
shader.getUniformLocation(name)
.value(); // TODO: optimization opportunity
shader.setUniformUnsafe(location, sf::Glsl::Vec2{a, b});
});
})
.arg("shaderId")
.arg("name")
Expand All @@ -1405,7 +1416,12 @@ static void initShaders(Lua::LuaContext& lua, HGAssets& assets,
{
withValidShaderId("shdr_setUniformFVec3", shaderId,
[&](sf::Shader& shader)
{ shader.setUniformUnsafe(name, sf::Glsl::Vec3{a, b, c}); });
{
const auto location =
shader.getUniformLocation(name)
.value(); // TODO: optimization opportunity
shader.setUniformUnsafe(location, sf::Glsl::Vec3{a, b, c});
});
})
.arg("shaderId")
.arg("name")
Expand All @@ -1422,7 +1438,13 @@ static void initShaders(Lua::LuaContext& lua, HGAssets& assets,
{
withValidShaderId("shdr_setUniformFVec4", shaderId,
[&](sf::Shader& shader)
{ shader.setUniformUnsafe(name, sf::Glsl::Vec4{a, b, c, d}); });
{
const auto location =
shader.getUniformLocation(name)
.value(); // TODO: optimization opportunity
shader.setUniformUnsafe(
location, sf::Glsl::Vec4{a, b, c, d});
});
})
.arg("shaderId")
.arg("name")
Expand All @@ -1442,7 +1464,13 @@ static void initShaders(Lua::LuaContext& lua, HGAssets& assets,
const std::size_t shaderId, const std::string& name, const int a)
{
withValidShaderId("shdr_setUniformI", shaderId,
[&](sf::Shader& shader) { shader.setUniformUnsafe(name, a); });
[&](sf::Shader& shader)
{
const auto location =
shader.getUniformLocation(name)
.value(); // TODO: optimization opportunity
shader.setUniformUnsafe(location, a);
});
})
.arg("shaderId")
.arg("name")
Expand All @@ -1457,7 +1485,12 @@ static void initShaders(Lua::LuaContext& lua, HGAssets& assets,
{
withValidShaderId("shdr_setUniformIVec2", shaderId,
[&](sf::Shader& shader)
{ shader.setUniformUnsafe(name, sf::Glsl::Ivec2{a, b}); });
{
const auto location =
shader.getUniformLocation(name)
.value(); // TODO: optimization opportunity
shader.setUniformUnsafe(location, sf::Glsl::Ivec2{a, b});
});
})
.arg("shaderId")
.arg("name")
Expand All @@ -1473,7 +1506,12 @@ static void initShaders(Lua::LuaContext& lua, HGAssets& assets,
{
withValidShaderId("shdr_setUniformIVec3", shaderId,
[&](sf::Shader& shader)
{ shader.setUniformUnsafe(name, sf::Glsl::Ivec3{a, b, c}); });
{
const auto location =
shader.getUniformLocation(name)
.value(); // TODO: optimization opportunity
shader.setUniformUnsafe(location, sf::Glsl::Ivec3{a, b, c});
});
})
.arg("shaderId")
.arg("name")
Expand All @@ -1489,8 +1527,13 @@ static void initShaders(Lua::LuaContext& lua, HGAssets& assets,
const int a, const int b, const int c, const int d)
{
withValidShaderId("shdr_setUniformIVec4", shaderId,
[&](sf::Shader& shader) {
shader.setUniformUnsafe(name, sf::Glsl::Ivec4{a, b, c, d});
[&](sf::Shader& shader)
{
const auto location =
shader.getUniformLocation(name)
.value(); // TODO: optimization opportunity
shader.setUniformUnsafe(
location, sf::Glsl::Ivec4{a, b, c, d});
});
})
.arg("shaderId")
Expand Down
8 changes: 8 additions & 0 deletions src/SSVOpenHexagon/Core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

#include <SFML/Graphics/Image.hpp>

#include <SFML/Audio/AudioContext.hpp>
#include <SFML/Audio/PlaybackDevice.hpp>

#include <csignal>
#include <cstdio>
#include <cstdlib>
Expand Down Expand Up @@ -389,8 +392,13 @@ getFirstCompressedReplayFilenameFromArgs(const std::vector<std::string>& args)
//
// ------------------------------------------------------------------------
// Initialize audio
auto audioContext = sf::AudioContext::create().value();
auto playbackDevice =
sf::PlaybackDevice::createDefault(audioContext).value();

hg::Audio audio{
//
playbackDevice,
[&assets](const std::string& assetId) -> sf::SoundBuffer*
{ return assets.getSoundBuffer(assetId); }, //
[&assets](const std::string& assetId) -> const std::string*
Expand Down

0 comments on commit 9ff4aaf

Please sign in to comment.