diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a00b6b6..cd956144 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) # # @@ -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) @@ -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}") @@ -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() # @@ -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 + # # # ----------------------------------------------------------------------------- diff --git a/extlibs/SSVMenuSystem b/extlibs/SSVMenuSystem index f2a75d1e..4951e7a6 160000 --- a/extlibs/SSVMenuSystem +++ b/extlibs/SSVMenuSystem @@ -1 +1 @@ -Subproject commit f2a75d1e34f5de352d5e38cdef4002b60a59c193 +Subproject commit 4951e7a67f77c1dd831cd4641723f1938692c899 diff --git a/extlibs/SSVStart b/extlibs/SSVStart index 40332ccd..9f0fc363 160000 --- a/extlibs/SSVStart +++ b/extlibs/SSVStart @@ -1 +1 @@ -Subproject commit 40332ccd70608a58155e987275ebfd2cb4907b9a +Subproject commit 9f0fc363652a606a97790ba12e456d1453a00451 diff --git a/extlibs/SSVUtils b/extlibs/SSVUtils index 6200143d..c8848b81 160000 --- a/extlibs/SSVUtils +++ b/extlibs/SSVUtils @@ -1 +1 @@ -Subproject commit 6200143d3f65acc90927936531ad50eff63d0d80 +Subproject commit c8848b81ecb912f9d6b345a169058b4f425677f7 diff --git a/include/SSVOpenHexagon/Global/Audio.hpp b/include/SSVOpenHexagon/Global/Audio.hpp index f7c8b7fa..e3aae668 100644 --- a/include/SSVOpenHexagon/Global/Audio.hpp +++ b/include/SSVOpenHexagon/Global/Audio.hpp @@ -10,8 +10,9 @@ #include namespace sf { +class PlaybackDevice; class SoundBuffer; -} +} // namespace sf namespace hg { @@ -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(); diff --git a/src/SSVOpenHexagon/Core/Audio.cpp b/src/SSVOpenHexagon/Core/Audio.cpp index f4699abb..c8ffc14b 100644 --- a/src/SSVOpenHexagon/Core/Audio.cpp +++ b/src/SSVOpenHexagon/Core/Audio.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -26,6 +27,7 @@ class Audio::AudioImpl { private: // TODO (P2): cleaner way of doing this + sf::PlaybackDevice& _playbackDevice; SoundBufferGetter _soundBufferGetter; MusicPathGetter _musicPathGetter; @@ -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{}, @@ -82,7 +86,7 @@ class Audio::AudioImpl if (_music.has_value()) { _music->setVolume(_musicVolume); - _music->play(); + _music->play(_playbackDevice); } } @@ -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(soundBufferGetter, musicPathGetter)} + : _impl{Utils::makeUnique( + playbackDevice, soundBufferGetter, musicPathGetter)} {} Audio::~Audio() = default; diff --git a/src/SSVOpenHexagon/Core/LuaScripting.cpp b/src/SSVOpenHexagon/Core/LuaScripting.cpp index e677adbe..cd03df7f 100644 --- a/src/SSVOpenHexagon/Core/LuaScripting.cpp +++ b/src/SSVOpenHexagon/Core/LuaScripting.cpp @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") diff --git a/src/SSVOpenHexagon/Core/main.cpp b/src/SSVOpenHexagon/Core/main.cpp index 09db5015..81d42b36 100644 --- a/src/SSVOpenHexagon/Core/main.cpp +++ b/src/SSVOpenHexagon/Core/main.cpp @@ -31,6 +31,9 @@ #include +#include +#include + #include #include #include @@ -389,8 +392,13 @@ getFirstCompressedReplayFilenameFromArgs(const std::vector& 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*