diff options
author | Vittorio Romeo <vittorio.romeo@outlook.com> | 2021-04-12 14:19:37 +0100 |
---|---|---|
committer | Vittorio Romeo <vittorio.romeo@outlook.com> | 2021-04-12 14:19:37 +0100 |
commit | eabd9d76fd2c69654ea3516aff65f215de632ac0 (patch) | |
tree | d7560ec60ac0f31aceebb42c5d2d2e15eed13815 | |
parent | c844898f7624ef9306c59a0f3a104cd8de91bacc (diff) | |
parent | d8ece4c5c382dc03a33ca1ec01a2333a50d9505e (diff) |
59 files changed, 1012 insertions, 1064 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 16ad0ad5..63e0f481 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,8 +33,8 @@ set(SFML_STATIC_LIBRARIES false) CPMAddPackage( NAME SFML - GITHUB_REPOSITORY SFML/SFML - GIT_TAG eaeb9777005eab322f25f809966043feca937960 + GITHUB_REPOSITORY SuperV1234/SFML + GIT_TAG a65f86606e8b3bcc13154f17371c24fc3b02512d ) # diff --git a/_RELEASE/Packs/cube/Styles/commando.json b/_RELEASE/Packs/cube/Styles/commando.json index 5b09e0bf..be758085 100644 --- a/_RELEASE/Packs/cube/Styles/commando.json +++ b/_RELEASE/Packs/cube/Styles/commando.json @@ -16,7 +16,7 @@ // 3D options "3D_depth": 7, "3D_skew": 0.20, - "3D_spacing": 0.9, + "3D_spacing": 0.7, "3D_darken_multiplier": 1.6, "3D_alpha_multiplier": 1, "3D_alpha_falloff": 0.1, diff --git a/_RELEASE/Packs/cube/Styles/euclideanpc.json b/_RELEASE/Packs/cube/Styles/euclideanpc.json index d71566ed..3ab4db55 100644 --- a/_RELEASE/Packs/cube/Styles/euclideanpc.json +++ b/_RELEASE/Packs/cube/Styles/euclideanpc.json @@ -16,7 +16,7 @@ // 3D options "3D_depth": 12, "3D_skew": 0.15, - "3D_spacing": 1.4, + "3D_spacing": 1.2, "3D_darken_multiplier": 1.1, "3D_alpha_multiplier": 0.4, "3D_alpha_falloff": 1.0, diff --git a/_RELEASE/Packs/cube/Styles/labyrinth.json b/_RELEASE/Packs/cube/Styles/labyrinth.json index c7bcf4e0..06e654e3 100644 --- a/_RELEASE/Packs/cube/Styles/labyrinth.json +++ b/_RELEASE/Packs/cube/Styles/labyrinth.json @@ -16,7 +16,7 @@ // 3D options "3D_depth": 4, "3D_skew": 0.20, - "3D_spacing": 1.2, + "3D_spacing": 0.7, // Main color diff --git a/_RELEASE/Packs/cube/Styles/pi.json b/_RELEASE/Packs/cube/Styles/pi.json index f442df3d..1cc86117 100644 --- a/_RELEASE/Packs/cube/Styles/pi.json +++ b/_RELEASE/Packs/cube/Styles/pi.json @@ -16,7 +16,7 @@ // 3D options "3D_depth": 4, "3D_skew": 0.15, - "3D_spacing": 2.5, + "3D_spacing": 1.5, // Main color "main": { "main": true, "dynamic": false, "value": [0, 0, 0, 225], "pulse": [99, 30, 165, 0] }, diff --git a/_RELEASE/Packs/cube/Styles/seconddimension.json b/_RELEASE/Packs/cube/Styles/seconddimension.json index 5d5803d0..88174b0f 100644 --- a/_RELEASE/Packs/cube/Styles/seconddimension.json +++ b/_RELEASE/Packs/cube/Styles/seconddimension.json @@ -16,10 +16,10 @@ // 3D options "3D_depth": 7, "3D_skew": 0.15, - "3D_spacing": 1.5, + "3D_spacing": 0.8, "3D_darken_multiplier": 1.5, - "3D_alpha_multiplier": 0.5, - "3D_alpha_falloff": 19.0, + "3D_alpha_multiplier": 1.65, + "3D_alpha_falloff": 16.0, "3D_override_color": [45, 45, 45, 255], // Main color diff --git a/_RELEASE/Packs/hypercube/Styles/evotutorial.json b/_RELEASE/Packs/hypercube/Styles/evotutorial.json index 1e74bccc..9bfdf546 100644 --- a/_RELEASE/Packs/hypercube/Styles/evotutorial.json +++ b/_RELEASE/Packs/hypercube/Styles/evotutorial.json @@ -16,7 +16,7 @@ // 3D options "3D_depth": 7, "3D_skew": 0.15, - "3D_spacing": 1.5, + "3D_spacing": 1.0, "3D_darken_multiplier": 1.5, "3D_alpha_multiplier": 0.5, "3D_alpha_falloff": 19.0, diff --git a/_RELEASE/Packs/hypercube/Styles/reppaws.json b/_RELEASE/Packs/hypercube/Styles/reppaws.json index 5ab242ea..2df50c06 100644 --- a/_RELEASE/Packs/hypercube/Styles/reppaws.json +++ b/_RELEASE/Packs/hypercube/Styles/reppaws.json @@ -14,9 +14,9 @@ "pulse_increment": 0.025, // 3D options - "3D_depth": 3, + "3D_depth": 4, "3D_skew": 0.15, - "3D_spacing": 3.4, + "3D_spacing": 1.4, // Main color "main": { "main": true, "dynamic": true, "value": [0, 0, 0, 225], "pulse": [99, 30, 165, 0] }, diff --git a/_RELEASE/Packs/orthoplex/Styles/arcadia.json b/_RELEASE/Packs/orthoplex/Styles/arcadia.json index 408ddd35..9dfdedee 100644 --- a/_RELEASE/Packs/orthoplex/Styles/arcadia.json +++ b/_RELEASE/Packs/orthoplex/Styles/arcadia.json @@ -16,7 +16,7 @@ // 3D options "3D_depth": 7, "3D_skew": 0.15, - "3D_spacing": 1.5, + "3D_spacing": 1.1, "3D_darken_multiplier": 1.5, "3D_alpha_multiplier": 0.5, "3D_alpha_falloff": 19.0, diff --git a/_RELEASE/Packs/tutorial/Scripts/Levels/babysteps.lua b/_RELEASE/Packs/tutorial/Scripts/Levels/babysteps.lua index 5273a086..71f3cfc7 100644 --- a/_RELEASE/Packs/tutorial/Scripts/Levels/babysteps.lua +++ b/_RELEASE/Packs/tutorial/Scripts/Levels/babysteps.lua @@ -19,6 +19,7 @@ shuffle(keys) index = 0 achievementUnlocked = false challengeFailed = false +challengeFailedText = "yes, so far..." step0 = false step1 = false @@ -40,18 +41,18 @@ step1_trFocus = "nope" -- onInit is an hardcoded function that is called when the level is first loaded function onInit() - l_setSpeedMult(0.70) + l_setSpeedMult(0.65) l_setSpeedInc(0.15) l_setRotationSpeed(0.04) l_setRotationSpeedMax(0.4) l_setRotationSpeedInc(0.04) - l_setDelayMult(1.45) + l_setDelayMult(1.65) l_setDelayInc(0.0) l_setFastSpin(0.0) l_setSides(6) l_setSidesMin(6) l_setSidesMax(6) - l_setIncTime(15) + l_setIncTime(1500) l_setTutorialMode(true) l_setBeatPulseMax(14) @@ -119,6 +120,8 @@ function onUpdate(mFrameTime) if not step0 then step0 = true + l_resetTime() + e_messageAddImportant("welcome to open hexagon 2!", 120) e_messageAddImportant("let's learn about the controls", 120) e_messageAddImportant("use left/right to rotate around the center", 200) @@ -129,8 +132,8 @@ function onUpdate(mFrameTime) if not step1 and l_getLevelTime() > 0.2 then step1 = true - l_addTracked("step0_trRotateLeft", "rotated left") - l_addTracked("step0_trRotateRight", "rotated right") + l_addTracked("step0_trRotateLeft", "rotated counter-clockwise") + l_addTracked("step0_trRotateRight", "rotated clockwise") end if step1 and not step2 and step0_trRotateLeft == "yes!" and step0_trRotateRight == "yes!" then @@ -151,6 +154,8 @@ function onUpdate(mFrameTime) step0_trRotateRight = "nope" l_addTracked("step1_trFocus", "focused") + l_addTracked("step0_trRotateLeft", "rotated counter-clockwise while focusing") + l_addTracked("step0_trRotateRight", "rotated clockwise while focusing") end if step25 and not step3 and step0_trRotateLeft == "yes!" and step0_trRotateRight == "yes!" and step1_trFocus == "yes!" then @@ -167,7 +172,10 @@ function onUpdate(mFrameTime) step35 = true l_clearTracked() + l_addTracked("challengeFailedText", "surived until the end") + l_resetTime() + l_setIncTime(15) end if step35 and not step4 and l_getLevelTime() > 30 then @@ -218,6 +226,7 @@ end function onPreDeath() if challengeFailed == false and l_getLevelTime() < 42 then challengeFailed = true + challengeFailedText = "not this time!" e_messageAddImportant("whoops!", 60) end end diff --git a/_RELEASE/Packs/tutorial/Styles/babysteps.json b/_RELEASE/Packs/tutorial/Styles/babysteps.json index 0e35ee22..b86336d6 100644 --- a/_RELEASE/Packs/tutorial/Styles/babysteps.json +++ b/_RELEASE/Packs/tutorial/Styles/babysteps.json @@ -14,12 +14,12 @@ "pulse_increment": 0.025, // 3D options - "3D_depth": 4, + "3D_depth": 5, "3D_skew": 0.15, - "3D_spacing": 1.9, + "3D_spacing": 1.5, "3D_darken_multiplier": 1.1, - "3D_alpha_multiplier": 0.4, - "3D_alpha_falloff": 15.0, + "3D_alpha_multiplier": 1.3, + "3D_alpha_falloff": 55.0, "3D_override_color": [85, 95, 155, 255], // Main color diff --git a/_RELEASE/config.json b/_RELEASE/config.json index 4390dfc8..7b8b1184 100644 --- a/_RELEASE/config.json +++ b/_RELEASE/config.json @@ -14,9 +14,9 @@ "first_time_playing" : false,
"flash_enabled" : true,
"fullscreen" : false,
- "fullscreen_auto_resolution" : false,
- "fullscreen_height" : 657,
- "fullscreen_width" : 948,
+ "fullscreen_auto_resolution" : true,
+ "fullscreen_height" : 1080,
+ "fullscreen_width" : 1920,
"invincible" : true,
"j_add_favorite" : 8,
"j_exit" : 2,
@@ -42,7 +42,7 @@ "no_music" : false,
"no_rotation" : false,
"no_sound" : false,
- "official" : true,
+ "official" : false,
"online" : true,
"pixel_multiplier" : 1,
"player_focus_speed" : 4.6250,
@@ -182,7 +182,7 @@ "timescale" : 1.0,
"vsync" : false,
"windowed_auto_resolution" : false,
- "windowed_height" : 603,
- "windowed_width" : 1176,
- "zoom_factor" : 1.273631811141968
+ "windowed_height" : 768,
+ "windowed_width" : 1366,
+ "zoom_factor" : 1.0
}
diff --git a/_RELEASE/default_config.json b/_RELEASE/default_config.json deleted file mode 120000 index 398e6083..00000000 --- a/_RELEASE/default_config.json +++ /dev/null @@ -1 +0,0 @@ -../misc/default_config.json
\ No newline at end of file diff --git a/build/cmake_msys2_timetrace.sh b/build/cmake_msys2_timetrace.sh new file mode 100644 index 00000000..62db680e --- /dev/null +++ b/build/cmake_msys2_timetrace.sh @@ -0,0 +1,2 @@ +#!/bin/bash
+cmake .. -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DCMAKE_CXX_FLAGS="-ftime-trace -Wall -Wextra -Wpedantic -Wno-braced-scalar-init"
diff --git a/build/copylibs.sh b/build/copylibs.sh new file mode 100644 index 00000000..84e79442 --- /dev/null +++ b/build/copylibs.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +cp ./_deps/imgui-sfml-build/libImGui-SFML_d.dll ../_RELEASE/ + +cp ./_deps/sfml-build/lib/libsfml-graphics-d-2.dll ../_RELEASE/ +cp ./_deps/sfml-build/lib/libsfml-system-d-2.dll ../_RELEASE/ +cp ./_deps/sfml-build/lib/libsfml-window-d-2.dll ../_RELEASE/ +cp ./_deps/sfml-build/lib/libsfml-network-d-2.dll ../_RELEASE/ +cp ./_deps/sfml-build/lib/libsfml-audio-d-2.dll ../_RELEASE/ + +cp ./_deps/sfml-src/extlibs/bin/x64/openal32.dll ../_RELEASE/ + +cp ./_deps/libsodium-cmake-build/libsodium.dll ../_RELEASE/ + +cp ./_deps/luajit-build/src/libluajit.dll ../_RELEASE/ + +cp ./_deps/zlib-build/libzlib1.dll ../_RELEASE/ @@ -1,3 +1,3 @@ #!/bin/bash
-(cd ../_RELEASE && ./SSVOpenHexagon.exe)
+(cp ./SSVOpenHexagon.exe ../_RELEASE && cd ../_RELEASE && ./SSVOpenHexagon.exe)
diff --git a/extlibs/SSVMenuSystem b/extlibs/SSVMenuSystem -Subproject 8d961cf5e0d326bcc4d2a44b3ed557a6a923527 +Subproject 2615adfa38e1e7d1b201d7d4111f311a6fa241e diff --git a/extlibs/SSVStart b/extlibs/SSVStart -Subproject 438e154f9d1f14b4f9c9fa901f9ca394b5a94ad +Subproject 7956abcfe3a617570365e99b9f80f991a792ed4 diff --git a/extlibs/SSVUtils b/extlibs/SSVUtils -Subproject 7435fb996e7c03394aff7c4d92d6b25269b799e +Subproject cb67a26e2f7c84d09f26c7121288faf8b99d43d diff --git a/include/SSVOpenHexagon/Core/HexagonDialogBox.hpp b/include/SSVOpenHexagon/Core/HexagonDialogBox.hpp index 9bae7623..5cbd0224 100644 --- a/include/SSVOpenHexagon/Core/HexagonDialogBox.hpp +++ b/include/SSVOpenHexagon/Core/HexagonDialogBox.hpp @@ -4,21 +4,22 @@ #pragma once -#include "SSVOpenHexagon/Utils/FastVertexVector.hpp" - #include <SFML/Graphics/Color.hpp> #include <SFML/Graphics/Font.hpp> #include <SFML/Graphics/Text.hpp> #include <SFML/Window/Keyboard.hpp> #include <string> +#include <vector> namespace ssvs { - class GameWindow; - } +namespace hg::Utils { +class FastVertexVectorQuads; +} // namespace hg::Utils + namespace hg { enum class DBoxDraw @@ -32,13 +33,11 @@ class HexagonDialogBox { private: using KKey = sf::Keyboard::Key; - using DrawFunc = std::function<void(const sf::Color&, const sf::Color&)>; ssvs::GameWindow& window; - DrawFunc drawFunc; + DBoxDraw drawMode; - Utils::FastVertexVectorQuads dialogFrame; std::vector<std::string> dialogText; sf::Text txtDialog; @@ -57,11 +56,10 @@ private: bool inputBoxPassword{false}; std::string input; - [[nodiscard]] DrawFunc drawModeToDrawFunc(DBoxDraw drawMode); - void drawText( const sf::Color& txtColor, const float xOffset, const float yOffset); - void drawBox(const sf::Color& frameColor, const float x1, const float x2, + void drawBox(Utils::FastVertexVectorQuads& quads, + const sf::Color& frameColor, const float x1, const float x2, const float y1, const float y2); void drawCenter(const sf::Color& txtColor, const sf::Color& backdropColor); void drawCenterUpperHalf( @@ -85,42 +83,16 @@ public: const float mFrameSize, const DBoxDraw mDrawMode); void draw(const sf::Color& txtColor, const sf::Color& backdropColor); + void clearDialogBox(); - [[nodiscard]] KKey getKeyToClose() const noexcept - { - return keyToClose; - } - - [[nodiscard]] bool empty() const noexcept - { - return dialogText.empty(); - } - - [[nodiscard]] bool isInputBox() const noexcept - { - return inputBox; - } - - [[nodiscard]] std::string& getInput() noexcept - { - return input; - } - - [[nodiscard]] const std::string& getInput() const noexcept - { - return input; - } - - void setInputBoxPassword(const bool x) noexcept - { - inputBoxPassword = x; - } - - [[nodiscard]] bool getInputBoxPassword() noexcept - { - return inputBoxPassword; - } + [[nodiscard]] KKey getKeyToClose() const noexcept; + [[nodiscard]] bool empty() const noexcept; + [[nodiscard]] bool isInputBox() const noexcept; + [[nodiscard]] std::string& getInput() noexcept; + [[nodiscard]] const std::string& getInput() const noexcept; + void setInputBoxPassword(const bool x) noexcept; + [[nodiscard]] bool getInputBoxPassword() noexcept; }; } // namespace hg diff --git a/include/SSVOpenHexagon/Data/LevelData.hpp b/include/SSVOpenHexagon/Data/LevelData.hpp index 4b029de8..cc226675 100644 --- a/include/SSVOpenHexagon/Data/LevelData.hpp +++ b/include/SSVOpenHexagon/Data/LevelData.hpp @@ -4,10 +4,6 @@ #pragma once -#include "SSVOpenHexagon/Data/TrackedVariable.hpp" - -#include <SSVUtils/Core/FileSystem/FileSystem.hpp> - #include <string> #include <vector> @@ -23,7 +19,7 @@ namespace hg { struct LevelData { - ssvufs::Path packPath; + std::string packPath; std::string packId; std::string id; @@ -35,11 +31,11 @@ struct LevelData std::string musicId; std::string soundId; std::string styleId; - ssvufs::Path luaScriptPath; + std::string luaScriptPath; std::vector<float> difficultyMults; bool unscored; - LevelData(const ssvuj::Obj& mRoot, const ssvufs::Path& mPackPath, + LevelData(const ssvuj::Obj& mRoot, const std::string& mPackPath, const std::string& mPackId); }; diff --git a/include/SSVOpenHexagon/Data/LevelStatus.hpp b/include/SSVOpenHexagon/Data/LevelStatus.hpp index e1114bcf..12e4a762 100644 --- a/include/SSVOpenHexagon/Data/LevelStatus.hpp +++ b/include/SSVOpenHexagon/Data/LevelStatus.hpp @@ -4,18 +4,14 @@ #pragma once -#include "SSVOpenHexagon/Data/TrackedVariable.hpp" - -#include <SSVUtils/Core/FileSystem/FileSystem.hpp> - #include <string> -#include <vector> +#include <unordered_map> namespace hg { struct LevelStatus { - std::vector<TrackedVariable> trackedVariables; + std::unordered_map<std::string, std::string> trackedVariables; // Allows alternative scoring to be possible bool scoreOverridden{false}; diff --git a/include/SSVOpenHexagon/Data/PackInfo.hpp b/include/SSVOpenHexagon/Data/PackInfo.hpp index 5dd208af..9e6ad756 100644 --- a/include/SSVOpenHexagon/Data/PackInfo.hpp +++ b/include/SSVOpenHexagon/Data/PackInfo.hpp @@ -4,8 +4,6 @@ #pragma once -#include <SSVUtils/Core/FileSystem/FileSystem.hpp> - #include <string> namespace hg { @@ -13,7 +11,7 @@ namespace hg { struct PackInfo { std::string id; - ssvufs::Path path; + std::string path; }; } // namespace hg diff --git a/include/SSVOpenHexagon/Data/ProfileData.hpp b/include/SSVOpenHexagon/Data/ProfileData.hpp index c24d83ee..c607fc44 100644 --- a/include/SSVOpenHexagon/Data/ProfileData.hpp +++ b/include/SSVOpenHexagon/Data/ProfileData.hpp @@ -5,10 +5,11 @@ #pragma once #include "SSVOpenHexagon/Global/Version.hpp" -#include "SSVOpenHexagon/SSVUtilsJson/SSVUtilsJson.hpp" #include <unordered_set> +#include <unordered_map> #include <string> +#include <vector> namespace hg { @@ -17,91 +18,41 @@ class ProfileData private: GameVersion version; std::string name; - ssvuj::Obj scores; + std::unordered_map<std::string, float> scores; std::vector<std::string> trackedNames; std::unordered_set<std::string> favoriteLevelsDataIDs; public: ProfileData(const GameVersion mVersion, const std::string& mName, - const ssvuj::Obj& mScores, + const std::unordered_map<std::string, float>& mScores, const std::vector<std::string>& mTrackedNames, - const std::vector<std::string>& mFavorites) - : version{mVersion}, - name{mName}, - scores{mScores}, - trackedNames{mTrackedNames}, - favoriteLevelsDataIDs{mFavorites.begin(), mFavorites.end()} - {} + const std::vector<std::string>& mFavorites); - [[nodiscard]] constexpr GameVersion getVersion() const noexcept - { - return version; - } - - [[nodiscard]] const std::string& getName() const noexcept - { - return name; - } - - [[nodiscard]] const ssvuj::Obj& getScores() const noexcept - { - return scores; - } + [[nodiscard]] GameVersion getVersion() const noexcept; + [[nodiscard]] const std::string& getName() const noexcept; + [[nodiscard]] const std::unordered_map<std::string, float>& + getScores() const noexcept; [[nodiscard]] const std::vector<std::string>& - getTrackedNames() const noexcept - { - return trackedNames; - } + getTrackedNames() const noexcept; [[nodiscard]] std::unordered_set<std::string>& - getFavoriteLevelIds() noexcept - { - return favoriteLevelsDataIDs; - } + getFavoriteLevelIds() noexcept; [[nodiscard]] const std::unordered_set<std::string>& - getFavoriteLevelIds() const noexcept - { - return favoriteLevelsDataIDs; - } - - void setScore(const std::string& mId, const float mScore) - { - ssvuj::arch(scores, mId, mScore); - } - - [[nodiscard]] float getScore(const std::string& mId) const - { - return ssvuj::getExtr<float>(scores, mId); - } - - void addTrackedName(const std::string& mTrackedName) - { - trackedNames.emplace_back(ssvu::toLower(mTrackedName)); - } + getFavoriteLevelIds() const noexcept; - void clearTrackedNames() - { - trackedNames.clear(); - } + void setScore(const std::string& mId, const float mScore); + [[nodiscard]] float getScore(const std::string& mId) const; - void addFavoriteLevel(const std::string& mLevelID) - { - favoriteLevelsDataIDs.emplace(mLevelID); - } + void addTrackedName(const std::string& mTrackedName); + void clearTrackedNames(); - void removeFavoriteLevel(const std::string& mLevelID) - { - favoriteLevelsDataIDs.erase(mLevelID); - } + void addFavoriteLevel(const std::string& mLevelID); + void removeFavoriteLevel(const std::string& mLevelID); [[nodiscard]] bool isLevelFavorite( - const std::string& mLevelID) const noexcept - { - return favoriteLevelsDataIDs.find(mLevelID) != - favoriteLevelsDataIDs.end(); - } + const std::string& mLevelID) const noexcept; }; } // namespace hg diff --git a/include/SSVOpenHexagon/Data/StyleData.hpp b/include/SSVOpenHexagon/Data/StyleData.hpp index cc08298c..69de7669 100644 --- a/include/SSVOpenHexagon/Data/StyleData.hpp +++ b/include/SSVOpenHexagon/Data/StyleData.hpp @@ -42,13 +42,14 @@ private: float currentHue{0}; float currentSwapTime{0}; float pulseFactor{0}; - sf::Color currentMainColor; - sf::Color currentPlayerColor; - sf::Color currentTextColor; - sf::Color current3DOverrideColor; + sf::Color currentMainColor{sf::Color::Black}; + sf::Color currentPlayerColor{sf::Color::Black}; + sf::Color currentTextColor{sf::Color::Black}; + sf::Color current3DOverrideColor{sf::Color::Black}; std::vector<sf::Color> currentColors; - sf::Color calculateColor(const ColorData& mColorData) const; + [[nodiscard]] static sf::Color calculateColor(const float mCurrentHue, + const float mPulseFactor, const ColorData& mColorData); [[nodiscard]] static ColorData colorDataFromObjOrDefault( const ssvuj::Obj& mRoot, const std::string& mKey, @@ -89,6 +90,7 @@ public: unsigned int BGColorOffset{0}; float BGRotOff{0}; // In degrees +private: sf::Color _3dOverrideColor; ColorData mainColorData; ColorData playerColor; @@ -98,6 +100,7 @@ public: std::vector<ColorData> colorDatas; +public: explicit StyleData(); explicit StyleData(const ssvuj::Obj& mRoot); @@ -113,11 +116,14 @@ public: const sf::Vector2f& mCenterPos, const unsigned int sides, const bool darkenUnevenBackgroundChunk) const; + void setCapColor(const CapColor& mCapColor); + [[nodiscard]] const sf::Color& getMainColor() const noexcept; [[nodiscard]] const sf::Color& getPlayerColor() const noexcept; [[nodiscard]] const sf::Color& getTextColor() const noexcept; [[nodiscard]] const std::vector<sf::Color>& getColors() const noexcept; - [[nodiscard]] const sf::Color& getColor(int mIdx) const noexcept; + [[nodiscard]] const sf::Color& getColor( + const std::size_t mIdx) const noexcept; [[nodiscard]] float getCurrentHue() const noexcept; [[nodiscard]] float getCurrentSwapTime() const noexcept; [[nodiscard]] const sf::Color& get3DOverrideColor() const noexcept; diff --git a/include/SSVOpenHexagon/Data/TrackedVariable.hpp b/include/SSVOpenHexagon/Data/TrackedVariable.hpp deleted file mode 100644 index 9a310807..00000000 --- a/include/SSVOpenHexagon/Data/TrackedVariable.hpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2013-2020 Vittorio Romeo -// License: Academic Free License ("AFL") v. 3.0 -// AFL License page: https://opensource.org/licenses/AFL-3.0 - -#pragma once - -#include <string> - -namespace hg { - -struct TrackedVariable -{ - std::string variableName, displayName; -}; - -} // namespace hg diff --git a/include/SSVOpenHexagon/Global/Assert.hpp b/include/SSVOpenHexagon/Global/Assert.hpp index 734d96ff..b34c9dc6 100644 --- a/include/SSVOpenHexagon/Global/Assert.hpp +++ b/include/SSVOpenHexagon/Global/Assert.hpp @@ -4,6 +4,34 @@ #pragma once -#include <SSVUtils/Core/Assert/Assert.hpp> +#include <SSVUtils/Core/Common/LikelyUnlikely.hpp> -#define SSVOH_ASSERT SSVU_ASSERT +#include <vrm/pp/sep_to_str.hpp> + +namespace hg::Impl { + +[[gnu::cold]] void assertionFailure( + const char* code, const char* file, const int line); + +} + +#ifndef NDEBUG + +#define SSVOH_ASSERT(...) \ + do \ + { \ + constexpr const char* assert_code = \ + VRM_PP_SEP_TOSTR(" ", VRM_PP_EMPTY(), __VA_ARGS__); \ + \ + if(SSVU_UNLIKELY(!static_cast<bool>(__VA_ARGS__))) \ + { \ + ::hg::Impl::assertionFailure(assert_code, __FILE__, __LINE__); \ + } \ + } \ + while(false) + +#else + +#define SSVOH_ASSERT(...) + +#endif diff --git a/include/SSVOpenHexagon/Global/Assets.hpp b/include/SSVOpenHexagon/Global/Assets.hpp index 9cb3ef0b..fcdf7d20 100644 --- a/include/SSVOpenHexagon/Global/Assets.hpp +++ b/include/SSVOpenHexagon/Global/Assets.hpp @@ -11,24 +11,28 @@ #include "SSVOpenHexagon/Data/LoadInfo.hpp" #include "SSVOpenHexagon/Data/PackInfo.hpp" -#include <SSVStart/Assets/Assets.hpp> -#include <SSVStart/Assets/AssetManager.hpp> - -#include <SSVUtils/Core/FileSystem/Path.hpp> - -#include <unordered_map> +#include <cstddef> #include <map> -#include <vector> +#include <memory> #include <string> -#include <cstddef> +#include <unordered_map> +#include <vector> namespace sf { - class SoundBuffer; class Music; - } // namespace sf +namespace ssvu::FileSystem { +class Path; +} + +namespace ssvufs = ssvu::FileSystem; + +namespace ssvs { +class DefaultAssetManager; +} + namespace hg { namespace Steam { @@ -44,7 +48,7 @@ private: bool levelsOnly{false}; - ssvs::AssetManager<> assetManager; + std::unique_ptr<ssvs::DefaultAssetManager> assetManager; std::unordered_map<std::string, LevelData> levelDatas; std::unordered_map<std::string, std::vector<std::string>> @@ -80,8 +84,6 @@ public: [[nodiscard]] LoadInfo& getLoadResults(); - [[nodiscard]] auto& operator()(); - template <typename T> [[nodiscard]] T& get(const std::string& mId); @@ -166,6 +168,7 @@ public: void pSaveAll(); void pSetCurrent(const std::string& mName); void pCreate(const std::string& mName); + void pRemove(const std::string& mName); [[nodiscard]] sf::SoundBuffer* getSoundBuffer(const std::string& assetId); [[nodiscard]] sf::Music* getMusic(const std::string& assetId); diff --git a/include/SSVOpenHexagon/Global/Config.hpp b/include/SSVOpenHexagon/Global/Config.hpp index 190deb47..3b26893d 100644 --- a/include/SSVOpenHexagon/Global/Config.hpp +++ b/include/SSVOpenHexagon/Global/Config.hpp @@ -37,8 +37,7 @@ void saveConfig(); void recalculateSizes(); void setFullscreen(ssvs::GameWindow& mWindow, bool mFullscreen); -void setCurrentResolution( - ssvs::GameWindow& mWindow, unsigned int mWidth, unsigned int mHeight); +void setCurrentResolution(unsigned int mWidth, unsigned int mHeight); void setCurrentResolutionAuto(ssvs::GameWindow& mWindow); void setVsync(ssvs::GameWindow& mWindow, bool mValue); @@ -46,7 +45,6 @@ void setLimitFPS(ssvs::GameWindow& mWindow, bool mValue); void setMaxFPS(ssvs::GameWindow& mWindow, unsigned int mValue); void setAntialiasingLevel(ssvs::GameWindow& mWindow, unsigned int mValue); -void setOnline(bool mOnline); void setOfficial(bool mOfficial); void setDebug(bool mDebug); void setNoRotation(bool mNoRotation); @@ -63,8 +61,6 @@ void setMusicVolume(float mVolume); void setFlash(bool mFlash); void setMusicSpeedDMSync(bool mValue); void setShowFPS(bool mValue); -void setServerLocal(bool mValue); -void setServerVerbose(bool mValue); void setMouseVisible(bool mValue); void setMusicSpeedMult(float mValue); void setDrawTextOutlines(bool mX); @@ -85,7 +81,6 @@ void setServerIp(const std::string& mX); void setServerPort(unsigned short mX); void setServerControlPort(unsigned short mX); -[[nodiscard]] bool getOnline(); [[nodiscard]] bool getOfficial(); [[nodiscard]] const std::string& getUneligibilityReason(); [[nodiscard]] float getSizeX(); @@ -132,8 +127,6 @@ void setServerControlPort(unsigned short mX); [[nodiscard]] unsigned int getMaxFPS(); [[nodiscard]] bool getShowFPS(); [[nodiscard]] unsigned int getAntialiasingLevel(); -[[nodiscard]] bool getServerLocal(); -[[nodiscard]] bool getServerVerbose(); [[nodiscard]] bool getMouseVisible(); [[nodiscard]] float getMusicSpeedMult(); [[nodiscard]] bool getDrawTextOutlines(); diff --git a/include/SSVOpenHexagon/Global/UtilsJson.hpp b/include/SSVOpenHexagon/Global/UtilsJson.hpp index 29ae8feb..4c1642bc 100644 --- a/include/SSVOpenHexagon/Global/UtilsJson.hpp +++ b/include/SSVOpenHexagon/Global/UtilsJson.hpp @@ -6,86 +6,80 @@ #include "SSVOpenHexagon/SSVUtilsJson/SSVUtilsJson.hpp" -#include <SSVStart/Global/Typedefs.hpp> -#include <SSVStart/Input/Enums.hpp> -#include <SSVStart/Input/Combo.hpp> -#include <SSVStart/Input/Trigger.hpp> -#include <SSVStart/Utils/Input.hpp> -#include <SSVStart/Assets/AssetManager.hpp> - -#include <SSVUtils/Core/Log/Log.hpp> -#include <SSVUtils/Core/FileSystem/FileSystem.hpp> +#include <SFML/Window/Mouse.hpp> +#include <SFML/Window/Keyboard.hpp> #include <SFML/System/Vector2.hpp> -#include <SFML/Graphics/Color.hpp> + +namespace ssvu::FileSystem { +class Path; +} namespace ssvs { +class DefaultAssetManager; +} + +namespace ssvs::Input { +class Trigger; +class Combo; +} // namespace ssvs::Input -void loadAssetsFromJson(ssvs::AssetManager<>& mAM, - const ssvufs::Path& mRootPath, const ssvuj::Obj& mObj); +namespace sf { +class Color; +} + +namespace ssvs { + +void loadAssetsFromJson(ssvs::DefaultAssetManager& mAM, + const ssvu::FileSystem::Path& mRootPath, const ssvuj::Obj& mObj); } // namespace ssvs namespace ssvuj { -template <typename T> -SSVUJ_CNV_SIMPLE(sf::Vector2<T>, mObj, mV) +template <> +struct Converter<sf::Vector2f> { - ssvuj::convertArray(mObj, mV.x, mV.y); -} -SSVUJ_CNV_SIMPLE_END(); + using T = sf::Vector2f; + + static void fromObj(const Obj& mObj, T& mValue); + static void toObj(Obj& mObj, const T& mValue); +}; template <> -SSVUJ_CNV_SIMPLE(sf::Color, mObj, mV) +struct Converter<sf::Color> { - ssvuj::convertArray(mObj, mV.r, mV.g, mV.b, mV.a); -} -SSVUJ_CNV_SIMPLE_END(); + using T = sf::Color; + + static void fromObj(const Obj& mObj, T& mValue); + static void toObj(Obj& mObj, const T& mValue); +}; template <> -SSVUJ_CNV_SIMPLE(ssvs::Input::Trigger, mObj, mV) +struct Converter<ssvs::Input::Trigger> { - ssvuj::convert(mObj, mV.getCombos()); -} -SSVUJ_CNV_SIMPLE_END(); + using T = ssvs::Input::Trigger; + + static void fromObj(const Obj& mObj, T& mValue); + static void toObj(Obj& mObj, const T& mValue); +}; template <> -struct Converter<ssvs::KKey> +struct Converter<sf::Keyboard::Key> { - using T = ssvs::KKey; - - static void fromObj(const Obj& mObj, T& mValue) - { - mValue = ssvs::getKKey(getExtr<std::string>(mObj)); - } - - static void toObj(Obj& mObj, const T& mValue) - { - if(mValue == T::Unknown) - { - std::string empty; - arch(mObj, empty); // TODO (P2): using `""` seems to be bugged - return; - } - - arch(mObj, ssvs::getKKeyName(mValue)); - } + using T = sf::Keyboard::Key; + + static void fromObj(const Obj& mObj, T& mValue); + static void toObj(Obj& mObj, const T& mValue); }; template <> -struct Converter<ssvs::MBtn> +struct Converter<sf::Mouse::Button> { - using T = ssvs::MBtn; - - static void fromObj(const Obj& mObj, T& mValue) - { - mValue = ssvs::getMBtn(getExtr<std::string>(mObj)); - } + using T = sf::Mouse::Button; - static void toObj(Obj& mObj, const T& mValue) - { - arch(mObj, ssvs::getMBtnName(mValue)); - } + static void fromObj(const Obj& mObj, T& mValue); + static void toObj(Obj& mObj, const T& mValue); }; template <> @@ -93,68 +87,8 @@ struct Converter<ssvs::Input::Combo> { using T = ssvs::Input::Combo; - static void fromObj(const Obj& mObj, T& mValue) - { - mValue.clearBind(); - - std::string str; - - for(const auto& i : mObj) - { - str = getExtr<std::string>(i); - - if(str.empty()) - { - mValue.addKey(ssvs::KKey::Unknown); - } - else if(ssvs::isKKeyNameValid(str)) - { - mValue.addKey(getExtr<ssvs::KKey>(i)); - } - else if(ssvs::isMBtnNameValid(str)) - { - mValue.addBtn(getExtr<ssvs::MBtn>(i)); - } - else - { - ssvu::lo("ssvs::getInputComboFromJSON") - << "<" << i - << "> is not a valid input name, an empty bind has been " - "put in its place\n"; - - mValue.addKey(ssvs::KKey::Unknown); - } - } - } - - static void toObj(Obj& mObj, const T& mValue) - { - if(mValue.isUnbound()) - { - arch(mObj, 0, ssvs::KKey(-1)); - return; - } - - auto i(0u); - const auto& keys(mValue.getKeys()); - const auto& btns(mValue.getBtns()); - - for(auto j(0u); j < ssvs::kKeyCount; ++j) - { - if(ssvs::getKeyBit(keys, ssvs::KKey(j))) - { - arch(mObj, i++, ssvs::KKey(j)); - } - } - - for(auto j(0u); j < ssvs::mBtnCount; ++j) - { - if(ssvs::getBtnBit(btns, ssvs::MBtn(j))) - { - arch(mObj, i++, ssvs::MBtn(j)); - } - } - } + static void fromObj(const Obj& mObj, T& mValue); + static void toObj(Obj& mObj, const T& mValue); }; } // namespace ssvuj diff --git a/include/SSVOpenHexagon/Online/Database.hpp b/include/SSVOpenHexagon/Online/Database.hpp index 64f02be2..3ff7c9ce 100644 --- a/include/SSVOpenHexagon/Online/Database.hpp +++ b/include/SSVOpenHexagon/Online/Database.hpp @@ -12,6 +12,8 @@ #include <vector> #include <chrono> +// TODO (P2): remove reliance on steam ID for future platforms + namespace hg::Database { using Clock = std::chrono::high_resolution_clock; diff --git a/include/SSVOpenHexagon/SSVUtilsJson/LinkedValue/LinkedValue.hpp b/include/SSVOpenHexagon/SSVUtilsJson/LinkedValue/LinkedValue.hpp index 9e33b3a4..f84db65e 100644 --- a/include/SSVOpenHexagon/SSVUtilsJson/LinkedValue/LinkedValue.hpp +++ b/include/SSVOpenHexagon/SSVUtilsJson/LinkedValue/LinkedValue.hpp @@ -4,7 +4,13 @@ #pragma once -#include "SSVOpenHexagon/SSVUtilsJson/Utils/Main.hpp" +namespace Json { +class Value; +} + +namespace ssvuj { +using Obj = Json::Value; +} namespace ssvuj { @@ -12,38 +18,22 @@ template <typename T> class LinkedValue { private: - const char* name; + const char* const name; T value; + const T defValue; public: - constexpr explicit LinkedValue(const char* mLinkedName) : name{mLinkedName} - {} - - [[nodiscard]] operator T&() noexcept - { - return value; - } - - [[nodiscard]] operator const T&() const noexcept - { - return value; - } - - auto& operator=(const T& mValue) - { - value = mValue; - return *this; - } - - void syncFrom(const Obj& mObj) - { - extr(mObj, name, value); - } - - void syncTo(Obj& mObj) const - { - arch(mObj, name, value); - } + explicit LinkedValue(const char* mLinkedName, const T& mDefault); + + [[nodiscard]] operator T&() noexcept; + [[nodiscard]] operator const T&() const noexcept; + + LinkedValue& operator=(const T& mValue); + + void syncFrom(const Obj& mObj); + void syncTo(Obj& mObj) const; + + void resetToDefault(); }; } // namespace ssvuj diff --git a/include/SSVOpenHexagon/SSVUtilsJson/SSVUtilsJson.hpp b/include/SSVOpenHexagon/SSVUtilsJson/SSVUtilsJson.hpp index 1accd73e..c8785ae2 100644 --- a/include/SSVOpenHexagon/SSVUtilsJson/SSVUtilsJson.hpp +++ b/include/SSVOpenHexagon/SSVUtilsJson/SSVUtilsJson.hpp @@ -7,4 +7,3 @@ #include "SSVOpenHexagon/SSVUtilsJson/JsonCpp/JsonCpp.hpp" #include "SSVOpenHexagon/SSVUtilsJson/Global/Common.hpp" #include "SSVOpenHexagon/SSVUtilsJson/Utils/Utils.hpp" -#include "SSVOpenHexagon/SSVUtilsJson/LinkedValue/LinkedValue.hpp" diff --git a/include/SSVOpenHexagon/SSVUtilsJson/Utils/BasicConverters.hpp b/include/SSVOpenHexagon/SSVUtilsJson/Utils/BasicConverters.hpp index e3aaadfe..987e2ffd 100644 --- a/include/SSVOpenHexagon/SSVUtilsJson/Utils/BasicConverters.hpp +++ b/include/SSVOpenHexagon/SSVUtilsJson/Utils/BasicConverters.hpp @@ -4,37 +4,18 @@ #pragma once -#include <type_traits> +#include "SSVOpenHexagon/SSVUtilsJson/Utils/Main.hpp" + +#include <string> #include <tuple> +#include <type_traits> +#include <unordered_map> #include <utility> #include <vector> -#include <map> -#include <string> -#include <unordered_map> - -/// @macro Class mixin that allows SSVUJ converters to access the current -/// class's private members. -#define SSVUJ_CNV_FRIEND() \ - template <typename> \ - friend struct ssvuj::Converter - -/// @macro Shortcut to serialize a class member as an object with the same name -/// as the member. -#define SSVUJ_CNV_OBJ_AUTO(mValue, mVar) #mVar, mValue.mVar - -/// @macro Defines a simple converter template specialization to convert classes -/// that do not require special behavior. -#define SSVUJ_CNV_SIMPLE(mType, mObjName, mValueName) \ - struct Converter<mType> final : ssvuj::Impl::ConverterSimpleImpl<mType> \ - { \ - template <typename TObj, typename TValue> \ - static void impl(TObj mObjName, TValue mValueName) - -/// @macro End macro, required after defining a simple converter. -#define SSVUJ_CNV_SIMPLE_END() } namespace ssvuj { // Convert enums + template <typename T> struct Converter { @@ -43,6 +24,7 @@ struct Converter { mValue = T(getExtr<std::underlying_type_t<T>>(mObj)); } + static void toObj(Obj& mObj, const T& mValue, std::enable_if_t<std::is_enum_v<T>>* = nullptr) { @@ -52,18 +34,6 @@ struct Converter }; namespace Impl { -template <typename T> -struct ConverterSimpleImpl -{ - static void fromObj(const Obj& mObjName, T& mValueName) - { - Converter<T>::template impl<const Obj&, T&>(mObjName, mValueName); - } - static void toObj(Obj& mObjName, const T& mValueName) - { - Converter<T>::template impl<Obj&, const T&>(mObjName, mValueName); - } -}; template <typename T> struct ConverterBaseImpl @@ -74,34 +44,6 @@ struct ConverterBaseImpl } }; -template <std::size_t I, typename TTpl> -using TplArg = - std::tuple_element_t<I, std::remove_const_t<std::remove_reference_t<TTpl>>>; - -template <std::size_t I = 0, typename... TArgs> -std::enable_if_t<I == sizeof...(TArgs)> toTpl(const Obj&, std::tuple<TArgs...>&) -{} -template <std::size_t I = 0, typename... TArgs> - std::enable_if_t < - I<sizeof...(TArgs)> toTpl(const Obj& mObj, std::tuple<TArgs...>& mTpl) -{ - Converter<TplArg<I, decltype(mTpl)>>::fromObj( - mObj[Idx(I)], std::get<I>(mTpl)); - toTpl<I + 1, TArgs...>(mObj, mTpl); -} - -template <std::size_t I = 0, typename... TArgs> -std::enable_if_t<I == sizeof...(TArgs)> fromTpl( - Obj&, const std::tuple<TArgs...>&) -{} -template <std::size_t I = 0, typename... TArgs> - std::enable_if_t < - I<sizeof...(TArgs)> fromTpl(Obj& mObj, const std::tuple<TArgs...>& mTpl) -{ - Converter<TplArg<I, decltype(mTpl)>>::toObj( - mObj[Idx(I)], std::get<I>(mTpl)); - fromTpl<I + 1, TArgs...>(mObj, mTpl); -} } // namespace Impl #define SSVUJ_IMPL_CNV_BASE(mType, ...) \ @@ -140,6 +82,7 @@ struct Converter<long> mObj = Json::Int64(mValue); } }; + template <> struct Converter<unsigned int> { @@ -181,6 +124,7 @@ struct Converter<unsigned long> mObj = Json::UInt64(mValue); } }; + template <typename TItem, typename TAlloc> struct Converter<std::vector<TItem, TAlloc>> { @@ -196,25 +140,7 @@ struct Converter<std::vector<TItem, TAlloc>> for(auto i(0u); i < mValue.size(); ++i) arch(mObj, i, mValue[i]); } }; -template <typename TKey, typename TValue, typename TComp, typename TAlloc> -struct Converter<std::map<TKey, TValue, TComp, TAlloc>> -{ - using T = std::map<TKey, TValue, TComp, TAlloc>; - static void fromObj(const Obj& mObj, T& mValue) - { - for(auto& p : mObj) - { - const auto& valueKey(getExtr<TKey>(p, 0)); - extr(p, 1, mValue[valueKey]); - } - } - static void toObj(Obj& mObj, const T& mValue) - { - Idx idx{0}; - for(const auto& p : mValue) - arch<std::pair<TKey, TValue>>(getObj(mObj, idx++), p); - } -}; + template <typename TKey, typename TValue, typename THash, typename TKeyEqual, typename TAlloc> struct Converter<std::unordered_map<TKey, TValue, THash, TKeyEqual, TAlloc>> @@ -222,47 +148,18 @@ struct Converter<std::unordered_map<TKey, TValue, THash, TKeyEqual, TAlloc>> using T = std::unordered_map<TKey, TValue, THash, TKeyEqual, TAlloc>; static void fromObj(const Obj& mObj, T& mValue) { - for(auto& p : mObj) + for(const auto& id : mObj.getMemberNames()) { - const auto& valueKey(getExtr<TKey>(p, 0)); - extr(p, 1, mValue[valueKey]); + mValue.emplace(id, getExtr<TValue>(mObj[id])); } } - static void toObj(Obj& mObj, const T& mValue) - { - Idx idx{0}; - for(const auto& p : mValue) - arch<std::pair<TKey, TValue>>(getObj(mObj, idx++), p); - } -}; - -template <typename T1, typename T2> -struct Converter<std::pair<T1, T2>> -{ - using T = std::pair<T1, T2>; - static void fromObj(const Obj& mObj, T& mValue) - { - extr<Impl::TplArg<0, T>>(mObj, 0, std::get<0>(mValue)); - extr<Impl::TplArg<1, T>>(mObj, 1, std::get<1>(mValue)); - } - static void toObj(Obj& mObj, const T& mValue) - { - arch<Impl::TplArg<0, T>>(mObj, 0, std::get<0>(mValue)); - arch<Impl::TplArg<1, T>>(mObj, 1, std::get<1>(mValue)); - } -}; -template <typename... TArgs> -struct Converter<std::tuple<TArgs...>> -{ - using T = std::tuple<TArgs...>; - static void fromObj(const Obj& mObj, T& mValue) - { - Impl::toTpl(mObj, mValue); - } static void toObj(Obj& mObj, const T& mValue) { - Impl::fromTpl(mObj, mValue); + for(const auto& [k, v] : mValue) + { + arch(mObj, k, v); + } } }; @@ -279,4 +176,5 @@ struct Converter<TItem[TN]> for(auto i(0u); i < TN; ++i) arch(mObj, i, mValue[i]); } }; + } // namespace ssvuj diff --git a/include/SSVOpenHexagon/SSVUtilsJson/Utils/Main.hpp b/include/SSVOpenHexagon/SSVUtilsJson/Utils/Main.hpp index a015c99b..6c4794b0 100644 --- a/include/SSVOpenHexagon/SSVUtilsJson/Utils/Main.hpp +++ b/include/SSVOpenHexagon/SSVUtilsJson/Utils/Main.hpp @@ -5,6 +5,9 @@ #pragma once #include "SSVOpenHexagon/SSVUtilsJson/Global/Common.hpp" +#include "SSVOpenHexagon/SSVUtilsJson/Utils/TypeChecker.hpp" + +#include <utility> namespace ssvuj { /// @brief Gets a JSON Obj from another JSON Obj. @@ -70,7 +73,7 @@ inline auto getObjSize(const Obj& mArray, Idx mIdx) noexcept /// @param mKey Key of the child. inline bool hasObj(const Obj& mObj, const Key& mKey) noexcept { - return mObj.isMember(mKey); + return mObj.isObject() && mObj.isMember(mKey); } /// @brief Checks whether a JSON Obj array has a certain member. @@ -78,7 +81,7 @@ inline bool hasObj(const Obj& mObj, const Key& mKey) noexcept /// @param mIdx Index of the child. inline bool hasObj(const Obj& mArray, Idx mIdx) noexcept { - return mArray.isValidIndex(mIdx); + return mArray.isArray() && mArray.isValidIndex(mIdx); } /// @brief Checks if a JSON Obj is an array. @@ -258,189 +261,4 @@ inline auto end(const Obj& mObj) noexcept return mObj.end(); } -namespace Impl { -template <Idx TIdx, typename TArg> -inline void extrArrayHelper(const Obj& mArray, TArg& mArg) -{ - extr(mArray, TIdx, mArg); -} -template <Idx TIdx, typename TArg, typename... TArgs> -inline void extrArrayHelper(const Obj& mArray, TArg& mArg, TArgs&... mArgs) -{ - extrArrayHelper<TIdx>(mArray, mArg); - extrArrayHelper<TIdx + 1>(mArray, mArgs...); -} - -template <Idx TIdx, typename TArg> -inline void archArrayHelper(Obj& mArray, const TArg& mArg) -{ - arch(mArray, TIdx, mArg); -} -template <Idx TIdx, typename TArg, typename... TArgs> -inline void archArrayHelper( - Obj& mArray, const TArg& mArg, const TArgs&... mArgs) -{ - archArrayHelper<TIdx>(mArray, mArg); - archArrayHelper<TIdx + 1>(mArray, mArgs...); -} - -template <typename TArg> -inline void extrObjHelper(const Obj& mObj, const Key& mKey, TArg& mArg) -{ - extr(mObj, mKey, mArg); -} -template <typename TArg, typename... TArgs> -inline void extrObjHelper( - const Obj& mObj, const Key& mKey, TArg& mArg, TArgs&... mArgs) -{ - extrObjHelper(mObj, mKey, mArg); - extrObjHelper(mObj, mArgs...); -} - -template <typename TArg> -inline void archObjHelper(Obj& mObj, const Key& mKey, const TArg& mArg) -{ - arch(mObj, mKey, mArg); -} -template <typename TArg, typename... TArgs> -inline void archObjHelper( - Obj& mObj, const Key& mKey, const TArg& mArg, const TArgs&... mArgs) -{ - archObjHelper(mObj, mKey, mArg); - archObjHelper(mObj, mArgs...); -} -} // namespace Impl - -/// @brief Extracts a JSON array into value references. -/// @param mArray Array to extract. -/// @param mArgs References to be assigned after the extraction. -template <typename... TArgs> -inline void extrArray(const Obj& mArray, TArgs&... mArgs) -{ - Impl::extrArrayHelper<0>(mArray, mArgs...); -} - -/// @brief Archives any number of values into a JSON array. -/// @param mArray Array to archive the values in. -/// @param mArgs Const references to the values to archive. -template <typename... TArgs> -inline void archArray(Obj& mArray, const TArgs&... mArgs) -{ - Impl::archArrayHelper<0>(mArray, mArgs...); -} - -/// @brief Returns a new JSON array instance with any number of values -/// archived -/// in it. -/// @param mArgs Const references to the values to archive. -template <typename... TArgs> -inline Obj getArchArray(const TArgs&... mArgs) -{ - Obj result; - archArray(result, mArgs...); - return result; -} - -/// @brief Extracts any number of values from a JSON Obj. -/// @param mObj Object to extract the values from. -/// @param mArgs For every value extracted, pass a key and a reference to -/// the -/// value. -template <typename... TArgs> -inline void extrObj(const Obj& mObj, TArgs&... mArgs) -{ - Impl::extrObjHelper(mObj, mArgs...); -} - -/// @brief Archives any number of values into a JSON Obj. -/// @param mObj Object to archive the values in. -/// @param mArgs For every value archived, pass a key and a const reference -/// to -/// the value. -template <typename... TArgs> -inline void archObj(Obj& mObj, const TArgs&... mArgs) -{ - Impl::archObjHelper(mObj, mArgs...); -} - -/// @brief Returns a new JSON Obj instance with any number of values -/// archived in -/// it. -/// @param mArgs For every value archived, pass a key and a const reference -/// to -/// the value. -template <typename... TArgs> -inline Obj getArchObj(const TArgs&... mArgs) -{ - Obj result; - archObj(result, mArgs...); - return result; -} - -/// @brief Archives/extracts a value into/from a JSON Obj, depending from -/// the -/// constness. -/// @param mObj Object to extract. -/// @param mValue Value to extract. -template <typename T> -inline void convert(const Obj& mObj, T& mValue) -{ - extr(mObj, mValue); -} - -/// @brief Archives/extracts a value into/from a JSON Obj, depending from -/// the -/// constness. -/// @param mObj Object to archive. -/// @param mValue Value to archive. -template <typename T> -inline void convert(Obj& mObj, const T& mValue) -{ - arch(mObj, mValue); -} - -/// @brief Archives/extracts any number of values into/from a JSON array, -/// depending from the constness. -/// @param mObj Object to extract. -/// @param mArgs Values to extract. -template <typename... TArgs> -inline void convertArray(const Obj& mObj, TArgs&... mArgs) -{ - extrArray(mObj, mArgs...); -} - -/// @brief Archives/extracts any number of values into/from a JSON array, -/// depending from the constness. -/// @param mObj Object to archive. -/// @param mArgs Values to archive. -template <typename... TArgs> -inline void convertArray(Obj& mObj, const TArgs&... mArgs) -{ - archArray(mObj, mArgs...); -} - -/// @brief Archives/extracts any number of values into/from a JSON Obj, -/// depending from the constness. -/// @param mObj Object to extract. -/// @param mArgs For every value extracted, pass a key and a reference to -/// the -/// value. -template <typename... TArgs> -inline void convertObj(const Obj& mObj, TArgs&... mArgs) -{ - extrObj(mObj, mArgs...); -} - -/// @brief Archives/extracts any number of values into/from a JSON Obj, -/// depending from the constness. -/// @param mObj Object to archive. -/// @param mArgs For every value archived, pass a key and a const reference -/// to -/// the value. -template <typename... TArgs> -inline void convertObj(Obj& mObj, const TArgs&... mArgs) -{ - archObj(mObj, mArgs...); -} - } // namespace ssvuj diff --git a/include/SSVOpenHexagon/Utils/Color.hpp b/include/SSVOpenHexagon/Utils/Color.hpp index 08049ace..96a81e94 100644 --- a/include/SSVOpenHexagon/Utils/Color.hpp +++ b/include/SSVOpenHexagon/Utils/Color.hpp @@ -4,6 +4,8 @@ #pragma once +#include "SSVOpenHexagon/Global/Assert.hpp" + #include <SFML/Graphics/Color.hpp> #include <cmath> @@ -13,9 +15,12 @@ namespace hg::Utils { [[nodiscard, gnu::always_inline, gnu::pure]] inline sf::Color getColorDarkened( sf::Color mColor, const float mMultiplier) { - mColor.r /= mMultiplier; - mColor.b /= mMultiplier; - mColor.g /= mMultiplier; + SSVOH_ASSERT(mMultiplier != 0.f); + + mColor.r = static_cast<float>(mColor.r) / mMultiplier; + mColor.b = static_cast<float>(mColor.b) / mMultiplier; + mColor.g = static_cast<float>(mColor.g) / mMultiplier; + return mColor; } @@ -43,4 +48,46 @@ namespace hg::Utils { }; } +[[nodiscard, gnu::always_inline, gnu::pure]] inline sf::Color getColorFromHue( + const float hue) noexcept +{ + SSVOH_ASSERT(hue >= 0.f && hue <= 1.f); + + const int i = std::floor(hue * 6.f); + + const float f = (hue * 6.f) - i; + const float q = 1.f - f; + const float t = f; + + const auto ret = [](const float r, const float g, const float b) + { return sf::Color(r * 255.f, g * 255.f, b * 255.f); }; + + switch(i) + { + case 0: return ret(1.f, t, 0.f); + case 1: return ret(q, 1.f, 0.f); + case 2: return ret(0.f, 1.f, t); + case 3: return ret(0.f, q, 1.f); + case 4: return ret(t, 0.f, 1.f); + } + + return ret(1.f, 0.f, q); +} + +[[nodiscard, gnu::always_inline, gnu::pure]] inline sf::Uint8 componentClamp( + const float value) +{ + if(value > 255.f) + { + return sf::Uint8(255); + } + + if(value < 0.f) + { + return sf::Uint8(0); + } + + return static_cast<sf::Uint8>(value); +} + } // namespace hg::Utils diff --git a/include/SSVOpenHexagon/Utils/LuaMetadataProxy.hpp b/include/SSVOpenHexagon/Utils/LuaMetadataProxy.hpp index 6006e9b8..f8a4b0ee 100644 --- a/include/SSVOpenHexagon/Utils/LuaMetadataProxy.hpp +++ b/include/SSVOpenHexagon/Utils/LuaMetadataProxy.hpp @@ -40,10 +40,10 @@ private: types.emplace_back(typeToStr(TypeWrapper<std::decay_t<ArgT>>{})); } - template <typename F> + template <typename FOp> [[nodiscard]] static std::string makeArgsString(LuaMetadataProxy* self) { - using AE = Utils::ArgExtractor<decltype(&F::operator())>; + using AE = Utils::ArgExtractor<FOp>; std::vector<std::string> types; @@ -78,22 +78,21 @@ private: [[nodiscard]] std::string resolveArgNames(const std::string& docs); + template <typename FOp> + [[nodiscard]] static std::string makeErasedRet(LuaMetadataProxy*) + { + using AE = Utils::ArgExtractor<FOp>; + return typeToStr(TypeWrapper<std::decay_t<typename AE::Return>>{}); + } + public: - template <typename F> + template <typename F, typename FOp = decltype(&std::decay_t<F>::operator())> explicit LuaMetadataProxy( TypeWrapper<F>, LuaMetadata& mLuaMetadata, const std::string& mName) : luaMetadata{mLuaMetadata}, name{mName}, - erasedRet{[](LuaMetadataProxy*) -> std::string - { - using AE = Utils::ArgExtractor<decltype( - &std::decay_t<F>::operator())>; - - return typeToStr( - TypeWrapper<std::decay_t<typename AE::Return>>{}); - }}, - erasedArgs{[](LuaMetadataProxy* self) - { return makeArgsString<std::decay_t<F>>(self); }} + erasedRet{&makeErasedRet<FOp>}, + erasedArgs{&makeArgsString<FOp>} {} ~LuaMetadataProxy(); diff --git a/include/SSVOpenHexagon/Utils/LuaWrapper.hpp b/include/SSVOpenHexagon/Utils/LuaWrapper.hpp index 248d62bb..361cb16a 100644 --- a/include/SSVOpenHexagon/Utils/LuaWrapper.hpp +++ b/include/SSVOpenHexagon/Utils/LuaWrapper.hpp @@ -36,7 +36,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SSVOpenHexagon/Global/Assert.hpp" -#include <algorithm> #include <cstring> #include <limits> #include <map> diff --git a/misc/default_config.json b/old/default_config.json index 81bfec31..41763859 100644 --- a/misc/default_config.json +++ b/old/default_config.json @@ -36,13 +36,12 @@ "mouse_visible": false, "music_speed_dm_sync": true, "music_speed_mult": 1.0, - "music_volume": 30.0, + "music_volume": 100.0, "no_background": false, "no_music": false, "no_rotation": false, "no_sound": false, "official": true, - "online": true, "pixel_multiplier": 1, "player_focus_speed": 4.625, "player_size": 7.3, @@ -53,8 +52,6 @@ "server_ip": "139.162.199.162", "server_port": 50505, "server_control_port": 50506, - "server_local": true, - "server_verbose": true, "show_fps": false, "show_key_icons": false, "show_level_info": false, @@ -62,7 +59,7 @@ "show_status_text": true, "show_tracked_variables": true, "show_timer": true, - "sound_volume": 75.0, + "sound_volume": 100.0, "t_down" : [ [ "kS" ], diff --git a/prepare_release.sh b/prepare_release.sh index 6c2845d3..72410ba1 100644 --- a/prepare_release.sh +++ b/prepare_release.sh @@ -32,7 +32,6 @@ cp ./_RELEASE/discord_game_sdk.dll ./_PREPARED_RELEASE cp ./_RELEASE/libsodium.dll ./_PREPARED_RELEASE cp ./_RELEASE/sdkencryptedappticket64.dll ./_PREPARED_RELEASE -cp ./misc/default_config.json ./_PREPARED_RELEASE/default_config.json cp ./_RELEASE/steam_appid.txt ./_PREPARED_RELEASE cp ./_RELEASE/windowed.bat ./_PREPARED_RELEASE cp ./_RELEASE/windowed_no3D.bat ./_PREPARED_RELEASE diff --git a/src/SSVOpenHexagon/Components/CPlayer.cpp b/src/SSVOpenHexagon/Components/CPlayer.cpp index 9646b796..5d89a578 100644 --- a/src/SSVOpenHexagon/Components/CPlayer.cpp +++ b/src/SSVOpenHexagon/Components/CPlayer.cpp @@ -64,10 +64,9 @@ void CPlayer::draw(const unsigned int sides, const sf::Color& colorMain, drawDeathEffect(wallQuads); } - sf::Color adjustedColorMain{ - !_deadEffectTimer.isRunning() - ? colorPlayer - : ssvs::getColorFromHSV(_hue / 360.f, 1.f, 1.f)}; + sf::Color adjustedColorMain{!_deadEffectTimer.isRunning() + ? colorPlayer + : Utils::getColorFromHue(_hue / 360.f)}; const sf::Vector2f pLeft = ssvs::getOrbitRad( _pos, _angle - ssvu::toRad(100.f), _size + _triangleWidth); @@ -77,8 +76,8 @@ void CPlayer::draw(const unsigned int sides, const sf::Color& colorMain, if(!_swapTimer.isRunning() && !_dead) { - adjustedColorMain = ssvs::getColorFromHSV( - (_swapBlinkTimer.getCurrent() * 15) / 360.f, 1, 1); + adjustedColorMain = + Utils::getColorFromHue((_swapBlinkTimer.getCurrent() * 15) / 360.f); } playerTris.reserve_more(3); @@ -120,8 +119,7 @@ void CPlayer::drawDeathEffect(Utils::FastVertexVectorQuads& wallQuads) const float dRadius{_hue / 8.f}; const float thickness{_hue / 20.f}; - const sf::Color colorMain{ - ssvs::getColorFromHSV((360.f - _hue) / 360.f, 1.f, 1.f)}; + const sf::Color colorMain{Utils::getColorFromHue((360.f - _hue) / 360.f)}; for(auto i(0u); i < 6; ++i) { diff --git a/src/SSVOpenHexagon/Core/HGGraphics.cpp b/src/SSVOpenHexagon/Core/HGGraphics.cpp index 3d6d6e24..e6931136 100644 --- a/src/SSVOpenHexagon/Core/HGGraphics.cpp +++ b/src/SSVOpenHexagon/Core/HGGraphics.cpp @@ -4,6 +4,7 @@ #include "SSVOpenHexagon/Core/HexagonGame.hpp" +#include "SSVOpenHexagon/Global/Assert.hpp" #include "SSVOpenHexagon/Global/Config.hpp" #include "SSVOpenHexagon/Utils/String.hpp" #include "SSVOpenHexagon/Utils/Color.hpp" @@ -13,6 +14,10 @@ #include <imgui-SFML.h> #include <SSVStart/Utils/Vector2.hpp> +#include <SSVStart/Utils/SFML.hpp> + +#include <SSVUtils/Core/Log/Log.hpp> +#include <SSVUtils/Core/Utils/Rnd.hpp> namespace hg { @@ -135,6 +140,17 @@ void HexagonGame::draw() playerTris3D.unsafe_emplace_other(playerTris); } + const auto adjustAlpha = [&](sf::Color& c, const float i) + { + SSVOH_ASSERT(styleData._3dAlphaMult != 0.f); + + const float newAlpha = + (static_cast<float>(c.a) / styleData._3dAlphaMult) - + i * styleData._3dAlphaFalloff; + + c.a = Utils::componentClamp(newAlpha); + }; + for(int j(0); j < static_cast<int>(depth); ++j) { const float i(depth - j - 1); @@ -148,8 +164,7 @@ void HexagonGame::draw() sf::Color overrideColor{Utils::getColorDarkened( styleData.get3DOverrideColor(), styleData._3dDarkenMult)}; - overrideColor.a /= styleData._3dAlphaMult; - overrideColor.a -= i * styleData._3dAlphaFalloff; + adjustAlpha(overrideColor, i); for(std::size_t k = j * numWallQuads; k < (j + 1) * numWallQuads; ++k) @@ -163,8 +178,8 @@ void HexagonGame::draw() { overrideColor = Utils::getColorDarkened( styleData.getPlayerColor(), styleData._3dDarkenMult); - overrideColor.a /= styleData._3dAlphaMult; - overrideColor.a -= i * styleData._3dAlphaFalloff; + + adjustAlpha(overrideColor, i); } for(std::size_t k = j * numPlayerTris; k < (j + 1) * numPlayerTris; @@ -385,20 +400,18 @@ void HexagonGame::updateText(ssvu::FT mFT) if(Config::getShowTrackedVariables() && !trackedVariables.empty()) { os << '\n'; - for(const auto& t : trackedVariables) + for(const auto& [variableName, display] : trackedVariables) { - if(!lua.doesVariableExist(t.variableName)) + if(!lua.doesVariableExist(variableName)) { continue; } - std::string name{t.displayName}; - Utils::uppercasify(name); - - std::string var{lua.readVariable<std::string>(t.variableName)}; - Utils::uppercasify(var); + const std::string value{ + lua.readVariable<std::string>(variableName)}; - os << name << ": " << var << '\n'; + os << Utils::toUppercase(display) << ": " + << Utils::toUppercase(value) << '\n'; } } } diff --git a/src/SSVOpenHexagon/Core/HGScripting.cpp b/src/SSVOpenHexagon/Core/HGScripting.cpp index 02e3c1a7..e0df69ec 100644 --- a/src/SSVOpenHexagon/Core/HGScripting.cpp +++ b/src/SSVOpenHexagon/Core/HGScripting.cpp @@ -17,10 +17,15 @@ #include "SSVOpenHexagon/Utils/TypeWrapper.hpp" #include "SSVOpenHexagon/Core/Steam.hpp" +#include <SSVUtils/Core/Log/Log.hpp> + #include <SFML/Graphics.hpp> #include <SFML/System.hpp> -#include <algorithm> +#include <iostream> +#include <string> +#include <chrono> +#include <cmath> namespace hg { @@ -28,6 +33,7 @@ template <typename F> Utils::LuaMetadataProxy addLuaFn( Lua::LuaContext& lua, const std::string& name, F&& f) { + // TODO (P2): reduce instantiations by using captureless lambdas lua.writeVariable(name, std::forward<F>(f)); return Utils::LuaMetadataProxy{ Utils::TypeWrapper<F>{}, LuaScripting::getMetadata(), name}; @@ -59,9 +65,8 @@ void HexagonGame::initLua_Utils() addLuaFn(lua, "u_execScript", // [this](const std::string& mScriptName) { - runLuaFile( - Utils::getDependentScriptFilename(execScriptPackPathContext, - levelData->packPath.getStr(), mScriptName)); + runLuaFile(Utils::getDependentScriptFilename( + execScriptPackPathContext, levelData->packPath, mScriptName)); }) .arg("scriptFilename") .doc("Execute the script located at `<pack>/Scripts/$0`."); @@ -506,7 +511,7 @@ void HexagonGame::initLua_LevelControl() std::cout << "[l_overrideScore] Runtime error on overriding score " << "with level \"" << levelData->name << "\": \n" - << ssvu::toStr(mError.what()) << '\n' + << mError.what() << '\n' << std::endl; if(!Config::getDebug()) { diff --git a/src/SSVOpenHexagon/Core/HGUpdate.cpp b/src/SSVOpenHexagon/Core/HGUpdate.cpp index f306e23b..539dd156 100644 --- a/src/SSVOpenHexagon/Core/HGUpdate.cpp +++ b/src/SSVOpenHexagon/Core/HGUpdate.cpp @@ -28,8 +28,6 @@ #include <SSVUtils/Core/Common/Frametime.hpp> #include <SSVUtils/Core/Utils/Containers.hpp> -#include <sodium.h> - #include <optional> #include <array> #include <cstring> @@ -246,64 +244,8 @@ void HexagonGame::update(ssvu::FT mFT) rng.advance(fixup(status.fastSpin)); rng.advance(fixup(status.flashEffect)); rng.advance(fixup(levelStatus.rotationSpeed)); + // TODO (P1): stuff from style? } - -// TODO (P0): decide what to do with this, definitely broken on the server -#if 0 - // Advance random number generator state with various level and - // style values to avoid cheating by modifying Lua scripts - if(!status.hasDied) - { - constexpr std::array<unsigned char, crypto_generichash_KEYBYTES> - key{}; - - std::array<unsigned char, crypto_generichash_BYTES> hash{}; - crypto_generichash_state state{}; - - crypto_generichash_init( - &state, key.data(), key.size(), hash.size()); - - const auto addHash = [&]<typename T>(const T& x) { - crypto_generichash_update(&state, - reinterpret_cast<const unsigned char*>(&x), sizeof(T)); - }; - - addHash(static_cast<std::int32_t>(status.pulse)); - addHash(static_cast<std::int32_t>(status.pulse3D)); - addHash(static_cast<std::int32_t>(status.fastSpin)); - addHash(static_cast<std::int32_t>(status.flashEffect)); - addHash(static_cast<std::int32_t>(levelStatus.rotationSpeed)); - addHash(styleData.getMainColor().toInteger()); - addHash(styleData.getPlayerColor().toInteger()); - for(const sf::Color& c : styleData.getColors()) - { - addHash(c.toInteger()); - } - addHash(static_cast<std::int32_t>(styleData.getCurrentHue())); - addHash( - static_cast<std::int32_t>(styleData.getCurrentSwapTime())); - addHash(styleData.get3DOverrideColor().toInteger()); - addHash(styleData.getCapColorResult().toInteger()); - - crypto_generichash_final(&state, hash.data(), hash.size()); - - using state_type = random_number_generator::state_type; - constexpr std::size_t state_type_size = sizeof(state_type); - static_assert(hash.size() % state_type_size == 0); - constexpr std::size_t inc = hash.size() / state_type_size; - - for(std::size_t i = 0; i < inc; ++i) - { - const unsigned char* b = &hash[i * inc]; - - state_type delta; - std::memcpy(static_cast<void*>(&delta), - static_cast<const void*>(b), inc); - - rng.advance(delta); - } - } -#endif } if(window != nullptr) diff --git a/src/SSVOpenHexagon/Core/HexagonDialogBox.cpp b/src/SSVOpenHexagon/Core/HexagonDialogBox.cpp index 6594b08e..cd529293 100644 --- a/src/SSVOpenHexagon/Core/HexagonDialogBox.cpp +++ b/src/SSVOpenHexagon/Core/HexagonDialogBox.cpp @@ -4,12 +4,19 @@ #include "SSVOpenHexagon/Utils/FontHeight.hpp" #include "SSVOpenHexagon/Data/StyleData.hpp" #include "SSVOpenHexagon/Global/Config.hpp" +#include "SSVOpenHexagon/Utils/FastVertexVector.hpp" #include <SSVStart/Utils/SFML.hpp> #include <SSVStart/GameSystem/GameWindow.hpp> namespace hg { +[[nodiscard]] static Utils::FastVertexVectorQuads& getDialogFrame() +{ + thread_local Utils::FastVertexVectorQuads result; + return result; +} + HexagonDialogBox::HexagonDialogBox(sf::Font& mFont, ssvs::GameWindow& mWindow) : window{mWindow}, txtDialog{"", mFont, 0} {} @@ -23,7 +30,7 @@ void HexagonDialogBox::create(const std::string& output, const int charSize, dialogWidth = ssvs::getGlobalWidth(txtDialog); frameSize = mFrameSize; doubleFrameSize = 2.f * frameSize; - drawFunc = drawModeToDrawFunc(mDrawMode); + drawMode = mDrawMode; xPos = mXPos; yPos = mYPos; inputBox = mInputBox; @@ -70,50 +77,42 @@ void HexagonDialogBox::createInput(const std::string& output, keyToClose = KKey::Enter; } -HexagonDialogBox::DrawFunc HexagonDialogBox::drawModeToDrawFunc( - DBoxDraw drawMode) +void HexagonDialogBox::draw( + const sf::Color& txtColor, const sf::Color& backdropColor) { switch(drawMode) { case DBoxDraw::topLeft: { - return [this](const sf::Color& txtColor, - const sf::Color& backdropColor) - { drawTopLeft(txtColor, backdropColor); }; + drawTopLeft(txtColor, backdropColor); + break; } case DBoxDraw::center: { - return [this](const sf::Color& txtColor, - const sf::Color& backdropColor) - { drawCenter(txtColor, backdropColor); }; + drawCenter(txtColor, backdropColor); + break; } default: { SSVOH_ASSERT(drawMode == DBoxDraw::centerUpperHalf); - return [this](const sf::Color& txtColor, - const sf::Color& backdropColor) - { drawCenterUpperHalf(txtColor, backdropColor); }; + drawCenterUpperHalf(txtColor, backdropColor); + break; } } } -void HexagonDialogBox::draw( - const sf::Color& txtColor, const sf::Color& backdropColor) -{ - drawFunc(txtColor, backdropColor); -} - -void HexagonDialogBox::drawBox(const sf::Color& frameColor, const float x1, - const float x2, const float y1, const float y2) +void HexagonDialogBox::drawBox(Utils::FastVertexVectorQuads& quads, + const sf::Color& frameColor, const float x1, const float x2, const float y1, + const float y2) { const sf::Vector2f topLeft{x1, y1}; const sf::Vector2f topRight{x2, y1}; const sf::Vector2f bottomRight{x2, y2}; const sf::Vector2f bottomLeft{x1, y2}; - dialogFrame.batch_unsafe_emplace_back( + quads.batch_unsafe_emplace_back( frameColor, topLeft, topRight, bottomRight, bottomLeft); } @@ -162,15 +161,16 @@ inline constexpr float fontHeightDifferential = 0.9f; void HexagonDialogBox::drawTopLeft( const sf::Color& txtColor, const sf::Color& backdropColor) { + Utils::FastVertexVectorQuads& dialogFrame = getDialogFrame(); dialogFrame.clear(); dialogFrame.reserve(8); // outer frame - drawBox(txtColor, xPos, 2.f * doubleFrameSize + dialogWidth + xPos, yPos, - totalHeight + yPos); + drawBox(dialogFrame, txtColor, xPos, + 2.f * doubleFrameSize + dialogWidth + xPos, yPos, totalHeight + yPos); // text backdrop - drawBox(backdropColor, frameSize + xPos, + drawBox(dialogFrame, backdropColor, frameSize + xPos, doubleFrameSize + frameSize + dialogWidth + xPos, frameSize + yPos, totalHeight - frameSize + yPos); @@ -193,16 +193,18 @@ void HexagonDialogBox::drawCenter( rightBorder = (w + dialogWidth) / 2.f + xPos, halfHeight = totalHeight / 2.f; + Utils::FastVertexVectorQuads& dialogFrame = getDialogFrame(); dialogFrame.clear(); dialogFrame.reserve(8); // outer frame - drawBox(txtColor, leftBorder - doubleFrameSize, + drawBox(dialogFrame, txtColor, leftBorder - doubleFrameSize, rightBorder + doubleFrameSize, h - halfHeight, h + halfHeight); // text backdrop - drawBox(backdropColor, leftBorder - frameSize, rightBorder + frameSize, - h - halfHeight + frameSize, h + halfHeight - frameSize); + drawBox(dialogFrame, backdropColor, leftBorder - frameSize, + rightBorder + frameSize, h - halfHeight + frameSize, + h + halfHeight - frameSize); window.draw(dialogFrame); @@ -222,16 +224,17 @@ void HexagonDialogBox::drawCenterUpperHalf( const float leftBorder = (w - dialogWidth) / 2.f + xPos, rightBorder = (w + dialogWidth) / 2.f + xPos; + Utils::FastVertexVectorQuads& dialogFrame = getDialogFrame(); dialogFrame.clear(); dialogFrame.reserve(8); // outer frame - drawBox(txtColor, leftBorder - doubleFrameSize, + drawBox(dialogFrame, txtColor, leftBorder - doubleFrameSize, rightBorder + doubleFrameSize, h - totalHeight, h); // text backdrop - drawBox(backdropColor, leftBorder - frameSize, rightBorder + frameSize, - h - totalHeight + frameSize, h - frameSize); + drawBox(dialogFrame, backdropColor, leftBorder - frameSize, + rightBorder + frameSize, h - totalHeight + frameSize, h - frameSize); window.draw(dialogFrame); @@ -243,7 +246,7 @@ void HexagonDialogBox::drawCenterUpperHalf( void HexagonDialogBox::clearDialogBox() { - dialogFrame.clear(); + getDialogFrame().clear(); dialogText.clear(); input.clear(); inputBox = false; @@ -251,4 +254,39 @@ void HexagonDialogBox::clearDialogBox() keyToClose = KKey::Unknown; } +[[nodiscard]] ssvs::KKey HexagonDialogBox::getKeyToClose() const noexcept +{ + return keyToClose; +} + +[[nodiscard]] bool HexagonDialogBox::empty() const noexcept +{ + return dialogText.empty(); +} + +[[nodiscard]] bool HexagonDialogBox::isInputBox() const noexcept +{ + return inputBox; +} + +[[nodiscard]] std::string& HexagonDialogBox::getInput() noexcept +{ + return input; +} + +[[nodiscard]] const std::string& HexagonDialogBox::getInput() const noexcept +{ + return input; +} + +void HexagonDialogBox::setInputBoxPassword(const bool x) noexcept +{ + inputBoxPassword = x; +} + +[[nodiscard]] bool HexagonDialogBox::getInputBoxPassword() noexcept +{ + return inputBoxPassword; +} + } // namespace hg diff --git a/src/SSVOpenHexagon/Core/HexagonGame.cpp b/src/SSVOpenHexagon/Core/HexagonGame.cpp index e077bf75..a9b8d9da 100644 --- a/src/SSVOpenHexagon/Core/HexagonGame.cpp +++ b/src/SSVOpenHexagon/Core/HexagonGame.cpp @@ -23,11 +23,13 @@ #include <imgui.h> #include <imgui-SFML.h> +#include <SSVStart/Utils/Input.hpp> #include <SSVStart/Utils/Vector2.hpp> -#include <SSVStart/SoundPlayer/SoundPlayer.hpp> +#include <SSVStart/Utils/SFML.hpp> #include <SSVStart/Input/Trigger.hpp> #include <SSVUtils/Core/Common/Frametime.hpp> +#include <SSVUtils/Core/Log/Log.hpp> #include <SFML/Graphics.hpp> @@ -550,6 +552,9 @@ void HexagonGame::newGame(const std::string& mPackId, const std::string& mId, { lastPlayedScore = tempReplayScore; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wbraced-scalar-init" + activeReplay.emplace(replay_file{ ._version{0}, @@ -564,6 +569,8 @@ void HexagonGame::newGame(const std::string& mPackId, const std::string& mId, ._difficulty_mult{mDifficultyMult}, ._played_score{lastPlayedScore}, }); + +#pragma GCC diagnostic pop } activeReplay->replayPlayer.reset(); @@ -842,6 +849,9 @@ void HexagonGame::death(bool mForce) ? assets.getCurrentLocalProfile().getName() : "no_profile"; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wbraced-scalar-init" + const replay_file rf{ ._version{0}, ._player_name{rfName}, @@ -854,6 +864,8 @@ void HexagonGame::death(bool mForce) ._played_score{getReplayScore(status)}, }; +#pragma GCC diagnostic pop + if(onReplayCreated) { onReplayCreated(rf); @@ -1102,9 +1114,13 @@ void HexagonGame::setLevelData( const LevelData& mLevelData, bool mMusicFirstPlay) { levelData = &mLevelData; + levelStatus = LevelStatus{Config::getMusicSpeedDMSync(), Config::getSpawnDistance()}; + styleData = assets.getStyleData(levelData->packId, levelData->styleId); + styleData.computeColors(); + musicData = assets.getMusicData(levelData->packId, levelData->musicId); musicData.firstPlay = mMusicFirstPlay; } diff --git a/src/SSVOpenHexagon/Core/LuaScripting.cpp b/src/SSVOpenHexagon/Core/LuaScripting.cpp index 6bbbb5cd..ff521075 100644 --- a/src/SSVOpenHexagon/Core/LuaScripting.cpp +++ b/src/SSVOpenHexagon/Core/LuaScripting.cpp @@ -875,15 +875,21 @@ static void initLevelControl( "increment."); addLuaFn(lua, "l_addTracked", // - [&levelStatus](const std::string& mVar, const std::string& mName) { - levelStatus.trackedVariables.push_back({mVar, mName}); - }) + [&levelStatus](const std::string& mVar, const std::string& mName) + { levelStatus.trackedVariables[mVar] = mName; }) .arg("variable") .arg("name") .doc( - "Add the variable `$0` to the list of tracked variables, with name " - "`$1`. Tracked variables are displayed in game, below the game " - "timer. *NOTE: Your variable must be global for this to work.*"); + "Add or set the variable `$0` to the list of tracked variables, " + "with name `$1`. Tracked variables are displayed in game, below " + "the game timer. *NOTE: Your variable must be global for this to " + "work.*"); + + addLuaFn(lua, "l_removeTracked", // + [&levelStatus](const std::string& mVar) + { levelStatus.trackedVariables.erase(mVar); }) + .arg("variable") + .doc("Remove the variable `$0` from the list of tracked variables"); addLuaFn(lua, "l_clearTracked", // [&levelStatus] { levelStatus.trackedVariables.clear(); }) @@ -1108,20 +1114,20 @@ static void initStyleControl(Lua::LuaContext& lua, StyleData& styleData) "Sets the rotation offset of the background panels to `$0` degrees."); addLuaFn(lua, "s_setCapColorMain", // - [&styleData] { styleData.capColor = CapColorMode::Main{}; }) + [&styleData] { styleData.setCapColor(CapColorMode::Main{}); }) .doc( "Set the color of the center polygon to match the main style " "color."); addLuaFn(lua, "s_setCapColorMainDarkened", // - [&styleData] { styleData.capColor = CapColorMode::MainDarkened{}; }) + [&styleData] { styleData.setCapColor(CapColorMode::MainDarkened{}); }) .doc( "Set the color of the center polygon to match the main style " "color, darkened."); addLuaFn(lua, "s_setCapColorByIndex", // [&styleData](int mIndex) - { styleData.capColor = CapColorMode::ByIndex{mIndex}; }) + { styleData.setCapColor(CapColorMode::ByIndex{mIndex}); }) .arg("index") .doc( "Set the color of the center polygon to match the style color with " diff --git a/src/SSVOpenHexagon/Core/MenuGame.cpp b/src/SSVOpenHexagon/Core/MenuGame.cpp index 51b75b5c..3d0db55e 100644 --- a/src/SSVOpenHexagon/Core/MenuGame.cpp +++ b/src/SSVOpenHexagon/Core/MenuGame.cpp @@ -43,6 +43,8 @@ #include "SSVOpenHexagon/Utils/Utils.hpp" #include <SSVStart/Input/Input.hpp> +#include <SSVStart/Utils/SFML.hpp> +#include <SSVStart/Utils/Input.hpp> #include <SSVStart/Utils/Vector2.hpp> #include <SSVStart/GameSystem/GameSystem.hpp> @@ -915,7 +917,8 @@ void MenuGame::changeResolutionTo(unsigned int mWidth, unsigned int mHeight) return; } - Config::setCurrentResolution(window, mWidth, mHeight); + Config::setCurrentResolution(mWidth, mHeight); + window.getRenderWindow().setSize(sf::Vector2u{mWidth, mHeight}); refreshCamera(); adjustLevelsOffset(); @@ -946,9 +949,8 @@ void MenuGame::initLua() lua.writeVariable("u_execScript", [this](const std::string& mScriptName) { - runLuaFile( - Utils::getDependentScriptFilename(execScriptPackPathContext, - levelData->packPath.getStr(), mScriptName)); + runLuaFile(Utils::getDependentScriptFilename( + execScriptPackPathContext, levelData->packPath, mScriptName)); }); lua.writeVariable("u_execDependencyScript", // @@ -2200,6 +2202,11 @@ void MenuGame::eraseAction() return; } + else + { + // Remove profile from memory as well + assets.pRemove(name); + } // Remove the item from the menu profileSelectionMenu.getCategory().remove(); @@ -3406,7 +3413,7 @@ std::string MenuGame::formatSurvivalTime(ProfileData* data) int time{0}; for(auto& s : data->getScores()) { - time += s.asInt(); + time += s.second; } std::stringstream stream; @@ -5151,7 +5158,7 @@ void MenuGame::draw() overlayCamera.apply(); // Draw the profile name. - if(mainOrAbove && state != States::LevelSelection && Config::getOnline()) + if(mainOrAbove && state != States::LevelSelection) { renderText("CURRENT PROFILE: " + assets.pGetName(), txtSelectionSmall.font, @@ -5346,7 +5353,8 @@ void MenuGame::drawGraphics() void MenuGame::drawOnlineStatus() { - overlayCamera.unapply(); + window.getRenderWindow().setView( + sf::View{{0.f, 0.f, getWindowWidth(), getWindowHeight()}}); const float onlineStatusScaling = 1.5f; const float scaling = onlineStatusScaling / Config::getZoomFactor(); diff --git a/src/SSVOpenHexagon/Core/main.cpp b/src/SSVOpenHexagon/Core/main.cpp index c1cf6289..5d71bba0 100644 --- a/src/SSVOpenHexagon/Core/main.cpp +++ b/src/SSVOpenHexagon/Core/main.cpp @@ -24,6 +24,10 @@ #include <SSVStart/GameSystem/GameWindow.hpp> +#include <SSVUtils/Core/Log/Log.hpp> +#include <SSVUtils/Core/Log/Log.inl> +#include <SSVUtils/Core/FileSystem/FileSystem.hpp> + #include <string> #include <optional> #include <vector> @@ -378,10 +382,10 @@ int main(int argc, char* argv[]) const std::string& levelId, bool firstPlay, float diffMult, bool executeLastReplay) { - window->setGameState(hg->getGame()); - hg->newGame( packId, levelId, firstPlay, diffMult, executeLastReplay); + + window->setGameState(hg->getGame()); }; mg->fnHGUpdateRichPresenceCallbacks = [&] // @@ -391,9 +395,10 @@ int main(int argc, char* argv[]) hg->fnGoToMenu = [&](const bool error) { - window->setGameState(mg->getGame()); mg->returnToLevelSelection(); mg->init(error); + + window->setGameState(mg->getGame()); }; } @@ -411,8 +416,9 @@ int main(int argc, char* argv[]) const auto gotoMenu = [&] { - window->setGameState(mg->getGame()); mg->init(false /* mError */); + + window->setGameState(mg->getGame()); }; const auto gotoGameReplay = [&](const hg::replay_file& replayFile) diff --git a/src/SSVOpenHexagon/Data/LevelData.cpp b/src/SSVOpenHexagon/Data/LevelData.cpp index d808a744..6daa486e 100644 --- a/src/SSVOpenHexagon/Data/LevelData.cpp +++ b/src/SSVOpenHexagon/Data/LevelData.cpp @@ -6,14 +6,12 @@ #include "SSVOpenHexagon/SSVUtilsJson/SSVUtilsJson.hpp" -#include <SSVUtils/Core/FileSystem/FileSystem.hpp> - #include <string> #include <vector> namespace hg { -LevelData::LevelData(const ssvuj::Obj& mRoot, const ssvufs::Path& mPackPath, +LevelData::LevelData(const ssvuj::Obj& mRoot, const std::string& mPackPath, const std::string& mPackId) : packPath{mPackPath}, packId{mPackId}, diff --git a/src/SSVOpenHexagon/Data/ProfileData.cpp b/src/SSVOpenHexagon/Data/ProfileData.cpp index c7c816a4..19a5aef5 100644 --- a/src/SSVOpenHexagon/Data/ProfileData.cpp +++ b/src/SSVOpenHexagon/Data/ProfileData.cpp @@ -3,3 +3,102 @@ // AFL License page: https://opensource.org/licenses/AFL-3.0 #include "SSVOpenHexagon/Data/ProfileData.hpp" + +#include "SSVOpenHexagon/Global/Version.hpp" + +#include <SSVUtils/Core/String/Utils.hpp> + +#include <unordered_set> +#include <string> + +namespace hg { + +ProfileData::ProfileData(const GameVersion mVersion, const std::string& mName, + const std::unordered_map<std::string, float>& mScores, + const std::vector<std::string>& mTrackedNames, + const std::vector<std::string>& mFavorites) + : version{mVersion}, + name{mName}, + scores{mScores}, + trackedNames{mTrackedNames}, + favoriteLevelsDataIDs{mFavorites.begin(), mFavorites.end()} +{} + +[[nodiscard]] GameVersion ProfileData::getVersion() const noexcept +{ + return version; +} + +[[nodiscard]] const std::string& ProfileData::getName() const noexcept +{ + return name; +} + +[[nodiscard]] const std::unordered_map<std::string, float>& +ProfileData::getScores() const noexcept +{ + return scores; +} + +[[nodiscard]] const std::vector<std::string>& +ProfileData::getTrackedNames() const noexcept +{ + return trackedNames; +} + +[[nodiscard]] std::unordered_set<std::string>& +ProfileData::getFavoriteLevelIds() noexcept +{ + return favoriteLevelsDataIDs; +} + +[[nodiscard]] const std::unordered_set<std::string>& +ProfileData::getFavoriteLevelIds() const noexcept +{ + return favoriteLevelsDataIDs; +} + +void ProfileData::setScore(const std::string& mId, const float mScore) +{ + scores[mId] = mScore; +} + +[[nodiscard]] float ProfileData::getScore(const std::string& mId) const +{ + const auto it = scores.find(mId); + + if(it == scores.end()) + { + return 0.f; + } + + return it->second; +} + +void ProfileData::addTrackedName(const std::string& mTrackedName) +{ + trackedNames.emplace_back(ssvu::toLower(mTrackedName)); +} + +void ProfileData::clearTrackedNames() +{ + trackedNames.clear(); +} + +void ProfileData::addFavoriteLevel(const std::string& mLevelID) +{ + favoriteLevelsDataIDs.emplace(mLevelID); +} + +void ProfileData::removeFavoriteLevel(const std::string& mLevelID) +{ + favoriteLevelsDataIDs.erase(mLevelID); +} + +[[nodiscard]] bool ProfileData::isLevelFavorite( + const std::string& mLevelID) const noexcept +{ + return favoriteLevelsDataIDs.find(mLevelID) != favoriteLevelsDataIDs.end(); +} + +} // namespace hg diff --git a/src/SSVOpenHexagon/Data/StyleData.cpp b/src/SSVOpenHexagon/Data/StyleData.cpp index 2095118d..3620fbbd 100644 --- a/src/SSVOpenHexagon/Data/StyleData.cpp +++ b/src/SSVOpenHexagon/Data/StyleData.cpp @@ -13,7 +13,6 @@ #include "SSVOpenHexagon/Global/UtilsJson.hpp" #include <SSVUtils/Core/Utils/Math.hpp> -#include <SSVUtils/Core/FileSystem/FileSystem.hpp> #include <SSVStart/Utils/Vector2.hpp> #include <SSVStart/Utils/SFML.hpp> @@ -58,7 +57,6 @@ StyleData::StyleData(const ssvuj::Obj& mRoot) ssvuj::getExtr<float>(mRoot, "3D_perspective_multiplier", 1.f)}, _3dOverrideColor{ssvuj::getExtr<sf::Color>( mRoot, "3D_override_color", sf::Color::Transparent)}, - mainColorData{ssvuj::getObj(mRoot, "main")}, // playerColor{ colorDataFromObjOrDefault(mRoot, "player_color", mainColorData)}, // @@ -78,16 +76,17 @@ StyleData::StyleData(const ssvuj::Obj& mRoot) } } -sf::Color StyleData::calculateColor(const ColorData& mColorData) const +sf::Color StyleData::calculateColor(const float mCurrentHue, + const float mPulseFactor, const ColorData& mColorData) { sf::Color color{mColorData.color}; if(mColorData.dynamic) { const float hue = - std::fmod(currentHue + mColorData.hueShift, 360.f) / 360.f; + std::fmod(mCurrentHue + mColorData.hueShift, 360.f) / 360.f; - const sf::Color dynamicColor = ssvs::getColorFromHSV(hue, 1.f, 1.f); + const sf::Color dynamicColor = Utils::getColorFromHue(hue); if(!mColorData.main) { @@ -112,26 +111,11 @@ sf::Color StyleData::calculateColor(const ColorData& mColorData) const } } - const auto componentClamp = [](const float value) -> sf::Uint8 - { - if(value > 255.f) - { - return sf::Uint8(255); - } - - if(value < 0) - { - return sf::Uint8(0); - } - - return static_cast<sf::Uint8>(value); - }; - return sf::Color( // - componentClamp(color.r + mColorData.pulse.r * pulseFactor), - componentClamp(color.g + mColorData.pulse.g * pulseFactor), - componentClamp(color.b + mColorData.pulse.b * pulseFactor), - componentClamp(color.a + mColorData.pulse.a * pulseFactor)); + Utils::componentClamp(color.r + mColorData.pulse.r * mPulseFactor), + Utils::componentClamp(color.g + mColorData.pulse.g * mPulseFactor), + Utils::componentClamp(color.b + mColorData.pulse.b * mPulseFactor), + Utils::componentClamp(color.a + mColorData.pulse.a * mPulseFactor)); } void StyleData::update(ssvu::FT mFT, float mMult) @@ -185,9 +169,9 @@ void StyleData::update(ssvu::FT mFT, float mMult) void StyleData::computeColors() { - currentMainColor = calculateColor(mainColorData); - currentPlayerColor = calculateColor(playerColor); - currentTextColor = calculateColor(textColor); + currentMainColor = calculateColor(currentHue, pulseFactor, mainColorData); + currentPlayerColor = calculateColor(currentHue, pulseFactor, playerColor); + currentTextColor = calculateColor(currentHue, pulseFactor, textColor); current3DOverrideColor = _3dOverrideColor.a != 0 ? _3dOverrideColor : getMainColor(); @@ -196,7 +180,7 @@ void StyleData::computeColors() for(const ColorData& cd : colorDatas) { - currentColors.emplace_back(calculateColor(cd)); + currentColors.emplace_back(calculateColor(currentHue, pulseFactor, cd)); } if(currentColors.size() > 1) @@ -296,6 +280,11 @@ void StyleData::drawBackgroundMenu(Utils::FastVertexVectorTris& mTris, drawBackgroundMenuHexagonImpl(mTris, mCenterPos, sides, fourByThree); } +void StyleData::setCapColor(const CapColor& mCapColor) +{ + capColor = mCapColor; +} + [[nodiscard]] const sf::Color& StyleData::getMainColor() const noexcept { return currentMainColor; @@ -317,7 +306,8 @@ StyleData::getColors() const noexcept return currentColors; } -[[nodiscard]] const sf::Color& StyleData::getColor(int mIdx) const noexcept +[[nodiscard]] const sf::Color& StyleData::getColor( + const std::size_t mIdx) const noexcept { SSVOH_ASSERT(!currentColors.empty()); return ssvu::getByModIdx(currentColors, mIdx); @@ -346,7 +336,8 @@ sf::Color StyleData::getCapColorResult() const noexcept [this](CapColorMode::MainDarkened) { return Utils::getColorDarkened(getMainColor(), 1.4f); }, // [this](CapColorMode::ByIndex x) { return getColor(x._index); }, // - [this](ColorData data) { return calculateColor(data); }); + [this](const ColorData& data) + { return calculateColor(currentHue, pulseFactor, data); }); } } // namespace hg diff --git a/src/SSVOpenHexagon/Global/Assert.cpp b/src/SSVOpenHexagon/Global/Assert.cpp new file mode 100644 index 00000000..0920b261 --- /dev/null +++ b/src/SSVOpenHexagon/Global/Assert.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2013-2020 Vittorio Romeo +// License: Academic Free License ("AFL") v. 3.0 +// AFL License page: https://opensource.org/licenses/AFL-3.0 + +#include "SSVOpenHexagon/Global/Assert.hpp" + +#include <cstdio> +#include <cstdlib> + +namespace hg::Impl { + +[[gnu::cold]] void assertionFailure( + const char* code, const char* file, const int line) +{ + std::printf("ASSERTION FAILED\n %s:%d\n %s\n", file, line, code); + std::abort(); +} + +} // namespace hg::Impl diff --git a/src/SSVOpenHexagon/Global/Assets.cpp b/src/SSVOpenHexagon/Global/Assets.cpp index dcee2ae6..8e190979 100644 --- a/src/SSVOpenHexagon/Global/Assets.cpp +++ b/src/SSVOpenHexagon/Global/Assets.cpp @@ -15,7 +15,7 @@ #include "SSVOpenHexagon/Global/UtilsJson.hpp" #include "SSVOpenHexagon/Core/Steam.hpp" -#include <SSVStart/SoundPlayer/SoundPlayer.hpp> +#include <SSVStart/Assets/AssetManager.hpp> #include <SSVUtils/Core/FileSystem/FileSystem.hpp> @@ -40,7 +40,9 @@ namespace hg { HGAssets::HGAssets( Steam::steam_manager* mSteamManager, bool mHeadless, bool mLevelsOnly) - : steamManager{mSteamManager}, levelsOnly{mLevelsOnly} + : steamManager{mSteamManager}, + levelsOnly{mLevelsOnly}, + assetManager{std::make_unique<ssvs::DefaultAssetManager>()} { if(!levelsOnly && !mHeadless) { @@ -56,7 +58,7 @@ HGAssets::HGAssets( auto [object, error] = ssvuj::getFromFileWithErrors("Assets/assets.json"); - loadAssetsFromJson(assetManager, "Assets/", object); + loadAssetsFromJson(*assetManager, "Assets/", object); loadInfo.addFormattedError(error); } @@ -231,7 +233,7 @@ HGAssets::~HGAssets() catch(...) { errorMutex.lock(); - + errorMessage = "Exception during asset loading: unknown.\n"; loadInfo.errorMessages.emplace_back("FATAL ERROR, " + errorMessage); @@ -252,17 +254,12 @@ HGAssets::~HGAssets() return loadInfo; } -[[nodiscard]] auto& HGAssets::operator()() -{ - return assetManager; -} - // ---------------------------------------------------------------------------- template <typename T> [[nodiscard]] T& HGAssets::get(const std::string& mId) { - return assetManager.get<T>(mId); + return assetManager->get<T>(mId); } template sf::Texture& HGAssets::get(const std::string& mId); @@ -381,7 +378,7 @@ HGAssets::getPackDatas() const noexcept // ------------------------------------------------------------------------ // Load packs from `Packs/` folder. - for(const std::string& packPath: + for(const std::string& packPath: ssvufs::getScan<ssvufs::Mode::Single, ssvufs::Type::Folder>("Packs/")) { tryLoadPackFromPath(packPath); @@ -418,10 +415,10 @@ HGAssets::getPackDatas() const noexcept errorMessage = Utils::concat("Error loading pack info '", packId, '\n'); loadInfo.errorMessages.emplace_back(errorMessage); - + errorMutex.unlock(); - ssvu::lo("::loadAssets") << errorMessage; + ssvu::lo("::loadAssets") << errorMessage; } }); } @@ -505,7 +502,7 @@ void HGAssets::loadCustomSounds( { assetManagerMutex.lock(); - assetManager.load<sf::SoundBuffer>( + assetManager->load<sf::SoundBuffer>( Utils::concat(mPackId, '_', p.getFileName()), p); assetManagerMutex.unlock(); @@ -520,8 +517,9 @@ void HGAssets::loadMusic(const std::string& mPackId, const ssvufs::Path& mPath) { assetManagerMutex.lock(); - auto& music(assetManager.load<sf::Music>( + auto& music(assetManager->load<sf::Music>( Utils::concat(mPackId, '_', p.getFileNameNoExtensions()), p)); + music.setLoop(true); assetManagerMutex.unlock(); @@ -577,7 +575,7 @@ void HGAssets::loadLevelData( for(const auto& p : scanSingleByExt(mPath + "Levels/", ".json")) { auto [object, error] = ssvuj::getFromFileWithErrors(p); - + loadLevelDataMtx.lock(); loadInfo.addFormattedError(error); @@ -687,7 +685,7 @@ void HGAssets::saveAllProfiles() [[nodiscard]] const MusicData& HGAssets::getMusicData( const std::string& mPackId, const std::string& mId) { - const std::string assetId = mPackId + "_" + mId; + const std::string assetId = Utils::concat(mPackId, '_', mId); const auto it = musicDataMap.find(assetId); if(it == musicDataMap.end()) @@ -704,7 +702,7 @@ void HGAssets::saveAllProfiles() [[nodiscard]] const StyleData& HGAssets::getStyleData( const std::string& mPackId, const std::string& mId) { - const std::string assetId = mPackId + "_" + mId; + const std::string assetId = Utils::concat(mPackId, '_', mId); const auto it = styleDataMap.find(assetId); if(it == styleDataMap.end()) @@ -798,9 +796,9 @@ void HGAssets::saveAllProfiles() for(const auto& p : scanSingleByExt(mPath + "Music/", ".ogg")) { temp = mPackId + "_" + p.getFileNameNoExtensions(); - if(!assetManager.has<sf::Music>(temp)) + if(!assetManager->has<sf::Music>(temp)) { - auto& music(assetManager.load<sf::Music>(temp, p)); + auto& music(assetManager->load<sf::Music>(temp, p)); music.setLoop(true); } } @@ -818,9 +816,9 @@ void HGAssets::saveAllProfiles() for(const auto& p : scanSingleByExt(mPath + "Sounds/", ".ogg")) { temp = mPackId + "_" + p.getFileName(); - if(!assetManager.has<sf::SoundBuffer>(temp)) + if(!assetManager->has<sf::SoundBuffer>(temp)) { - assetManager.load<sf::SoundBuffer>(temp, p); + assetManager->load<sf::SoundBuffer>(temp, p); } } output += "Custom sound files successfully reloaded\n"; @@ -930,7 +928,7 @@ void HGAssets::saveAllProfiles() else if(levelData.musicId != "nullMusicId") { assetId = mPackId + "_" + levelData.musicId; - if(assetManager.has<sf::Music>(assetId)) + if(assetManager->has<sf::Music>(assetId)) { output += "music file " + levelData.musicId + ".ogg is already loaded\n"; @@ -945,7 +943,7 @@ void HGAssets::saveAllProfiles() else { auto& music( - assetManager.load<sf::Music>(assetId, musicFile[0])); + assetManager->load<sf::Music>(assetId, musicFile[0])); music.setLoop(true); output += "new music file " + levelData.musicId + ".ogg successfully loaded\n"; @@ -970,7 +968,7 @@ void HGAssets::saveAllProfiles() // Check if this custom sound file is already loaded assetId = mPackId + "_" + levelData.soundId; - if(assetManager.has<sf::SoundBuffer>(assetId)) + if(assetManager->has<sf::SoundBuffer>(assetId)) { output += "custom sound file " + levelData.soundId + ".ogg is already loaded\n"; @@ -984,7 +982,7 @@ void HGAssets::saveAllProfiles() return output; } - assetManager.load<sf::SoundBuffer>(assetId, soundFile[0]); + assetManager->load<sf::SoundBuffer>(assetId, soundFile[0]); output += "new custom sound file " + levelData.soundId + ".ogg successfully loaded\n"; @@ -1120,27 +1118,32 @@ void HGAssets::pCreate(const std::string& mName) createLocalProfile(mName); } +void HGAssets::pRemove(const std::string& mName) +{ + profileDataMap.erase(mName); +} + [[nodiscard]] sf::SoundBuffer* HGAssets::getSoundBuffer( const std::string& assetId) { // TODO (P2): remove assetmanager - if(!assetManager.has<sf::SoundBuffer>(assetId)) + if(!assetManager->has<sf::SoundBuffer>(assetId)) { return nullptr; } - return &assetManager.get<sf::SoundBuffer>(assetId); + return &assetManager->get<sf::SoundBuffer>(assetId); } [[nodiscard]] sf::Music* HGAssets::getMusic(const std::string& assetId) { // TODO (P2): remove assetmanager - if(!assetManager.has<sf::Music>(assetId)) + if(!assetManager->has<sf::Music>(assetId)) { return nullptr; } - return &assetManager.get<sf::Music>(assetId); + return &assetManager->get<sf::Music>(assetId); } } // namespace hg diff --git a/src/SSVOpenHexagon/Global/Config.cpp b/src/SSVOpenHexagon/Global/Config.cpp index f4dc1942..0c452bd1 100644 --- a/src/SSVOpenHexagon/Global/Config.cpp +++ b/src/SSVOpenHexagon/Global/Config.cpp @@ -3,13 +3,16 @@ // AFL License page: https://opensource.org/licenses/AFL-3.0 #include "SSVOpenHexagon/Global/Config.hpp" -#include "SSVOpenHexagon/Utils/String.hpp" -#include "SSVOpenHexagon/Utils/Concat.hpp" -#include "SSVOpenHexagon/SSVUtilsJson/SSVUtilsJson.hpp" + #include "SSVOpenHexagon/Global/UtilsJson.hpp" +#include "SSVOpenHexagon/Utils/Concat.hpp" +#include "SSVOpenHexagon/Utils/String.hpp" #include "SSVOpenHexagon/Utils/Casts.hpp" #include "SSVOpenHexagon/Core/Joystick.hpp" +#include "SSVOpenHexagon/SSVUtilsJson/SSVUtilsJson.hpp" +#include "SSVOpenHexagon/SSVUtilsJson/LinkedValue/LinkedValue.hpp" + #include <SSVStart/Utils/Input.hpp> #include <SSVStart/Input/Input.hpp> #include <SSVStart/GameSystem/GameWindow.hpp> @@ -17,103 +20,110 @@ #include <iostream> #include <fstream> -#define X_LINKEDVALUES_BINDS_JOYSTICK \ - X(joystickSelect, unsigned int, "j_select") \ - X(joystickExit, unsigned int, "j_exit") \ - X(joystickFocus, unsigned int, "j_focus") \ - X(joystickSwap, unsigned int, "j_swap") \ - X(joystickForceRestart, unsigned int, "j_force_restart") \ - X(joystickRestart, unsigned int, "j_restart") \ - X(joystickReplay, unsigned int, "j_replay") \ - X(joystickScreenshot, unsigned int, "j_screenshot") \ - X(joystickNextPack, unsigned int, "j_next") \ - X(joystickPreviousPack, unsigned int, "j_previous") \ - X(joystickAddToFavorites, unsigned int, "j_add_favorite") \ - X(joystickFavoritesMenu, unsigned int, "j_favorite_menu") - -#define X_LINKEDVALUES_BINDS_TRIGGERS \ - X(triggerRotateCCW, ssvs::Input::Trigger, "t_rotate_ccw") \ - X(triggerRotateCW, ssvs::Input::Trigger, "t_rotate_cw") \ - X(triggerFocus, ssvs::Input::Trigger, "t_focus") \ - X(triggerSelect, ssvs::Input::Trigger, "t_select") \ - X(triggerExit, ssvs::Input::Trigger, "t_exit") \ - X(triggerForceRestart, ssvs::Input::Trigger, "t_force_restart") \ - X(triggerRestart, ssvs::Input::Trigger, "t_restart") \ - X(triggerReplay, ssvs::Input::Trigger, "t_replay") \ - X(triggerScreenshot, ssvs::Input::Trigger, "t_screenshot") \ - X(triggerSwap, ssvs::Input::Trigger, "t_swap") \ - X(triggerUp, ssvs::Input::Trigger, "t_up") \ - X(triggerDown, ssvs::Input::Trigger, "t_down") \ - X(triggerNextPack, ssvs::Input::Trigger, "t_next") \ - X(triggerPreviousPack, ssvs::Input::Trigger, "t_previous") \ - X(triggerLuaConsole, ssvs::Input::Trigger, "t_lua_console") \ - X(triggerPause, ssvs::Input::Trigger, "t_pause") +using uint = unsigned int; +using ushort = unsigned short; +using trig = ssvs::Input::Trigger; +using k = ssvs::KKey; +using m = ssvs::MBtn; + +#define X_LINKEDVALUES_BINDS_JOYSTICK \ + X(joystickSelect, uint, "j_select", 1) \ + X(joystickExit, uint, "j_exit", 2) \ + X(joystickFocus, uint, "j_focus", 4) \ + X(joystickSwap, uint, "j_swap", 5) \ + X(joystickForceRestart, uint, "j_force_restart", 3) \ + X(joystickRestart, uint, "j_restart", 0) \ + X(joystickReplay, uint, "j_replay", 6) \ + X(joystickScreenshot, uint, "j_screenshot", 7) \ + X(joystickNextPack, uint, "j_next", 11) \ + X(joystickPreviousPack, uint, "j_previous", 10) \ + X(joystickAddToFavorites, uint, "j_add_favorite", 8) \ + X(joystickFavoritesMenu, uint, "j_favorite_menu", 9) + +#define X_LINKEDVALUES_BINDS_TRIGGERS \ + X(triggerRotateCCW, trig, "t_rotate_ccw", \ + {{{k::A}}, {{k::Left}}, {{}, {m::Left}}}) \ + X(triggerRotateCW, trig, "t_rotate_cw", \ + {{{k::D}}, {{k::Right}}, {{}, {m::Right}}}) \ + X(triggerFocus, trig, "t_focus", {{{k::LShift}}, {{}, {m::XButton1}}}) \ + X(triggerSelect, trig, "t_select", {{{k::Space}}, {{}, {m::Middle}}}) \ + X(triggerExit, trig, "t_exit", {{{k::T}}}) \ + X(triggerForceRestart, trig, "t_force_restart", {{{k::Up}}, {{k::R}}}) \ + X(triggerRestart, trig, "t_restart", \ + {{{k::Space}}, {{k::Return}}, {{}, {m::Middle}}}) \ + X(triggerReplay, trig, "t_replay", {{{k::Y}}}) \ + X(triggerScreenshot, trig, "t_screenshot", {{{k::F12}}}) \ + X(triggerSwap, trig, "t_swap", {{{k::Space}}, {{}, {m::Middle}}}) \ + X(triggerUp, trig, "t_up", {{{k::W}}}) \ + X(triggerDown, trig, "t_down", {{{k::S}}}) \ + X(triggerNextPack, trig, "t_next", {{{k::PageDown}}}) \ + X(triggerPreviousPack, trig, "t_previous", {{{k::PageUp}}}) \ + X(triggerLuaConsole, trig, "t_lua_console", {{{k::F1}}}) \ + X(triggerPause, trig, "t_pause", {{{k::F2}}}) #define X_LINKEDVALUES_BINDS \ X_LINKEDVALUES_BINDS_JOYSTICK \ X_LINKEDVALUES_BINDS_TRIGGERS -#define X_LINKEDVALUES \ - X(online, bool, "online") \ - X(official, bool, "official") \ - X(noRotation, bool, "no_rotation") \ - X(noBackground, bool, "no_background") \ - X(noSound, bool, "no_sound") \ - X(noMusic, bool, "no_music") \ - X(blackAndWhite, bool, "black_and_white") \ - X(pulseEnabled, bool, "pulse_enabled") \ - X(_3DEnabled, bool, "3D_enabled") \ - X(_3DMultiplier, float, "3D_multiplier") \ - X(_3DMaxDepth, unsigned int, "3D_max_depth") \ - X(invincible, bool, "invincible") \ - X(autoRestart, bool, "auto_restart") \ - X(soundVolume, float, "sound_volume") \ - X(musicVolume, float, "music_volume") \ - X(flashEnabled, bool, "flash_enabled") \ - X(zoomFactor, float, "zoom_factor") \ - X(pixelMultiplier, int, "pixel_multiplier") \ - X(playerSpeed, float, "player_speed") \ - X(playerFocusSpeed, float, "player_focus_speed") \ - X(playerSize, float, "player_size") \ - X(limitFPS, bool, "limit_fps") \ - X(vsync, bool, "vsync") \ - X(autoZoomFactor, bool, "auto_zoom_factor") \ - X(fullscreen, bool, "fullscreen") \ - X(windowedAutoResolution, bool, "windowed_auto_resolution") \ - X(fullscreenAutoResolution, bool, "fullscreen_auto_resolution") \ - X(fullscreenWidth, unsigned int, "fullscreen_width") \ - X(fullscreenHeight, unsigned int, "fullscreen_height") \ - X(windowedWidth, unsigned int, "windowed_width") \ - X(windowedHeight, unsigned int, "windowed_height") \ - X(showMessages, bool, "show_messages") \ - X(debug, bool, "debug") \ - X(beatPulse, bool, "beatpulse_enabled") \ - X(showTrackedVariables, bool, "show_tracked_variables") \ - X(musicSpeedDMSync, bool, "music_speed_dm_sync") \ - X(maxFPS, unsigned int, "max_fps") \ - X(antialiasingLevel, unsigned int, "antialiasing_level") \ - X(showFPS, bool, "show_fps") \ - X(serverLocal, bool, "server_local") \ - X(serverVerbose, bool, "server_verbose") \ - X(mouseVisible, bool, "mouse_visible") \ - X(musicSpeedMult, float, "music_speed_mult") \ - X(drawTextOutlines, bool, "draw_text_outlines") \ - X(darkenUnevenBackgroundChunk, bool, "darken_uneven_background_chunk") \ - X(rotateToStart, bool, "rotate_to_start") \ - X(joystickDeadzone, float, "joystick_deadzone") \ - X(textPadding, float, "text_padding") \ - X(textScaling, float, "text_scaling") \ - X(timescale, float, "timescale") \ - X(showKeyIcons, bool, "show_key_icons") \ - X(keyIconsScale, float, "key_icons_scale") \ - X(firstTimePlaying, bool, "first_time_playing") \ - X(saveLocalBestReplayToFile, bool, "save_local_best_replay_to_file") \ - X(showLevelInfo, bool, "show_level_info") \ - X(showTimer, bool, "show_timer") \ - X(showStatusText, bool, "show_status_text") \ - X(serverIp, std::string, "server_ip") \ - X(serverPort, unsigned short, "server_port") \ - X(serverControlPort, unsigned short, "server_control_port") \ +#define X_LINKEDVALUES \ + X(official, bool, "official", true) \ + X(noRotation, bool, "no_rotation", false) \ + X(noBackground, bool, "no_background", false) \ + X(noSound, bool, "no_sound", false) \ + X(noMusic, bool, "no_music", false) \ + X(blackAndWhite, bool, "black_and_white", false) \ + X(pulseEnabled, bool, "pulse_enabled", true) \ + X(_3DEnabled, bool, "3D_enabled", true) \ + X(_3DMultiplier, float, "3D_multiplier", 1.f) \ + X(_3DMaxDepth, uint, "3D_max_depth", 100) \ + X(invincible, bool, "invincible", false) \ + X(autoRestart, bool, "auto_restart", false) \ + X(soundVolume, float, "sound_volume", 100.f) \ + X(musicVolume, float, "music_volume", 100.f) \ + X(flashEnabled, bool, "flash_enabled", true) \ + X(zoomFactor, float, "zoom_factor", 1.27f) \ + X(pixelMultiplier, int, "pixel_multiplier", 1) \ + X(playerSpeed, float, "player_speed", 9.45f) \ + X(playerFocusSpeed, float, "player_focus_speed", 4.625f) \ + X(playerSize, float, "player_size", 7.3f) \ + X(limitFPS, bool, "limit_fps", true) \ + X(vsync, bool, "vsync", false) \ + X(autoZoomFactor, bool, "auto_zoom_factor", true) \ + X(fullscreen, bool, "fullscreen", false) \ + X(windowedAutoResolution, bool, "windowed_auto_resolution", false) \ + X(fullscreenAutoResolution, bool, "fullscreen_auto_resolution", false) \ + X(fullscreenWidth, uint, "fullscreen_width", 1920) \ + X(fullscreenHeight, uint, "fullscreen_height", 1080) \ + X(windowedWidth, uint, "windowed_width", 800) \ + X(windowedHeight, uint, "windowed_height", 600) \ + X(showMessages, bool, "show_messages", true) \ + X(debug, bool, "debug", false) \ + X(beatPulse, bool, "beatpulse_enabled", true) \ + X(showTrackedVariables, bool, "show_tracked_variables", true) \ + X(musicSpeedDMSync, bool, "music_speed_dm_sync", true) \ + X(maxFPS, uint, "max_fps", 200) \ + X(antialiasingLevel, uint, "antialiasing_level", 4) \ + X(showFPS, bool, "show_fps", false) \ + X(mouseVisible, bool, "mouse_visible", false) \ + X(musicSpeedMult, float, "music_speed_mult", 1.0f) \ + X(drawTextOutlines, bool, "draw_text_outlines", true) \ + X(darkenUnevenBackgroundChunk, bool, "darken_uneven_background_chunk", \ + true) \ + X(rotateToStart, bool, "rotate_to_start", false) \ + X(joystickDeadzone, float, "joystick_deadzone", 5.0f) \ + X(textPadding, float, "text_padding", 8.0f) \ + X(textScaling, float, "text_scaling", 1.0f) \ + X(timescale, float, "timescale", 1.0f) \ + X(showKeyIcons, bool, "show_key_icons", false) \ + X(keyIconsScale, float, "key_icons_scale", 0.75f) \ + X(firstTimePlaying, bool, "first_time_playing", true) \ + X(saveLocalBestReplayToFile, bool, "save_local_best_replay_to_file", true) \ + X(showLevelInfo, bool, "show_level_info", false) \ + X(showTimer, bool, "show_timer", true) \ + X(showStatusText, bool, "show_status_text", true) \ + X(serverIp, std::string, "server_ip", "139.162.199.162") \ + X(serverPort, ushort, "server_port", 50505) \ + X(serverControlPort, ushort, "server_control_port", 50506) \ X_LINKEDVALUES_BINDS namespace hg::Config { @@ -130,36 +140,30 @@ namespace hg::Config { return ssvuj::getFromFile("config.json"); } - if(ssvufs::Path{"default_config.json"}.exists<ssvufs::Type::File>()) - { - ssvu::lo("hg::Config::root()") - << "User `config.json` file not found, looking for " - "default\n"; - - ssvu::lo("hg::Config::root()") - << "Default `default_config.json` file found\n"; - - return ssvuj::getFromFile("default_config.json"); - } - ssvu::lo("hg::Config::root()") - << "FATAL ERROR: No suitable config file found\n"; + << "No suitable config file found, using defaults\n"; - std::abort(); + return ssvuj::Obj{}; }(); return res; } -#define X(name, type, key) \ - [[nodiscard]] static auto& name() noexcept \ - { \ - static auto res = ::ssvuj::LinkedValue<type>(key); \ - return res; \ + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wbraced-scalar-init" + +#define X(name, type, key, ...) \ + [[nodiscard]] static auto& name() noexcept \ + { \ + static auto res = ::ssvuj::LinkedValue<type>(key, type{__VA_ARGS__}); \ + return res; \ } X_LINKEDVALUES #undef X +#pragma GCC diagnostic pop + static void fixupMissingTriggers() { const auto doIt = [](ssvs::Input::Trigger& trig) @@ -179,14 +183,14 @@ static void fixupMissingTriggers() } }; -#define X(name, type, key) doIt(name()); +#define X(name, type, key, ...) doIt(name()); X_LINKEDVALUES_BINDS_TRIGGERS #undef X } static void syncAllFromObj() { -#define X(name, type, key) name().syncFrom(root()); +#define X(name, type, key, ...) name().syncFrom(root()); X_LINKEDVALUES #undef X @@ -195,23 +199,21 @@ static void syncAllFromObj() static void syncAllToObj() { -#define X(name, type, key) name().syncTo(root()); +#define X(name, type, key, ...) name().syncTo(root()); X_LINKEDVALUES #undef X } -static void resetAllFromObj() +static void resetAllFromDefault() { -#define X(name, type, key) \ - name().syncFrom(ssvuj::getFromFile("default_config.json")); +#define X(name, type, key, ...) name().resetToDefault(); X_LINKEDVALUES #undef X } -static void resetBindsFromObj() +static void resetBindsFromDefault() { -#define X(name, type, key) \ - name().syncFrom(ssvuj::getFromFile("default_config.json")); +#define X(name, type, key, ...) name().resetToDefault(); X_LINKEDVALUES_BINDS #undef X } @@ -280,16 +282,7 @@ void resetConfigToDefaults() { ssvu::lo("::resetConfigToDefaults") << "resetting configs\n"; - if(!ssvufs::Path{"default_config.json"}.exists<ssvufs::Type::File>()) - { - ssvu::lo("hg::Config::resetConfigToDefaults()") - << "`default_config.json` file not found, config reset " - "aborted\n"; - - return; - } - - resetAllFromObj(); + resetAllFromDefault(); if(getWindowedAutoResolution()) { @@ -308,16 +301,7 @@ void resetBindsToDefaults() { ssvu::lo("::resetBindsToDefaults") << "resetting binds to defaults\n"; - if(!ssvufs::Path{"default_config.json"}.exists<ssvufs::Type::File>()) - { - ssvu::lo("hg::Config::resetBindsToDefaults()") - << "`default_config.json` file not found, config reset " - "aborted\n"; - - return; - } - - resetBindsFromObj(); + resetBindsFromDefault(); } void saveConfig() @@ -406,8 +390,7 @@ void setFullscreen(ssvs::GameWindow& mWindow, bool mFullscreen) recalculateSizes(); } -void setCurrentResolution( - ssvs::GameWindow& mWindow, unsigned int mWidth, unsigned int mHeight) +void setCurrentResolution(unsigned int mWidth, unsigned int mHeight) { if(getFullscreen()) { @@ -422,7 +405,7 @@ void setCurrentResolution( windowedHeight() = mHeight; } - setFullscreen(mWindow, getFullscreen()); + recalculateSizes(); } void setCurrentResolutionAuto(ssvs::GameWindow& mWindow) @@ -468,11 +451,6 @@ void setAntialiasingLevel(ssvs::GameWindow& mWindow, unsigned int mValue) } } -void setOnline(bool mOnline) -{ - online() = mOnline; -} - void setOfficial(bool mOfficial) { official() = mOfficial; @@ -553,16 +531,6 @@ void setShowFPS(bool mValue) showFPS() = mValue; } -void setServerLocal(bool mValue) -{ - serverLocal() = mValue; -} - -void setServerVerbose(bool mValue) -{ - serverVerbose() = mValue; -} - void setMouseVisible(bool mValue) { mouseVisible() = mValue; @@ -658,11 +626,6 @@ void setServerControlPort(unsigned short mX) serverControlPort() = mX; } -[[nodiscard]] bool getOnline() -{ - return online(); -} - [[nodiscard]] bool getOfficial() { return official(); @@ -883,16 +846,6 @@ void setServerControlPort(unsigned short mX) return showFPS(); } -[[nodiscard]] bool getServerLocal() -{ - return serverLocal(); -} - -[[nodiscard]] bool getServerVerbose() -{ - return serverVerbose(); -} - [[nodiscard]] bool getMouseVisible() { return mouseVisible(); diff --git a/src/SSVOpenHexagon/Global/UtilsJson.cpp b/src/SSVOpenHexagon/Global/UtilsJson.cpp index 14192ff2..1e7d7673 100644 --- a/src/SSVOpenHexagon/Global/UtilsJson.cpp +++ b/src/SSVOpenHexagon/Global/UtilsJson.cpp @@ -4,21 +4,35 @@ #include "SSVOpenHexagon/Global/UtilsJson.hpp" -#include <SFML/System.hpp> - +#include <SSVStart/Assets/AssetManager.hpp> #include <SSVStart/Global/Typedefs.hpp> -#include <SSVStart/Input/Enums.hpp> #include <SSVStart/Input/Combo.hpp> +#include <SSVStart/Input/Enums.hpp> #include <SSVStart/Input/Trigger.hpp> #include <SSVStart/Utils/Input.hpp> -#include <SSVStart/Assets/AssetManager.hpp> -#include <SSVUtils/Core/FileSystem/FileSystem.hpp> +#include <SSVUtils/Core/Log/Log.hpp> + +#include <SSVUtils/Core/FileSystem/Path.hpp> + +#include <SFML/Graphics/Font.hpp> +#include <SFML/Graphics/Image.hpp> +#include <SFML/Graphics/Texture.hpp> +#include <SFML/Graphics/Shader.hpp> +#include <SFML/Graphics/Color.hpp> + +#include <SFML/Audio/SoundBuffer.hpp> +#include <SFML/Audio/Music.hpp> + +#include <SFML/Window/Mouse.hpp> +#include <SFML/Window/Keyboard.hpp> + +#include <SFML/System/Vector2.hpp> namespace ssvs { -void loadAssetsFromJson(ssvs::AssetManager<>& mAM, - const ssvufs::Path& mRootPath, const ssvuj::Obj& mObj) +void loadAssetsFromJson(ssvs::DefaultAssetManager& mAM, + const ssvu::FileSystem::Path& mRootPath, const ssvuj::Obj& mObj) { for(const auto& f : ssvuj::getExtr<std::vector<std::string>>(mObj, "fonts")) { @@ -65,3 +79,135 @@ void loadAssetsFromJson(ssvs::AssetManager<>& mAM, } } // namespace ssvs + +namespace ssvuj { + +void Converter<sf::Vector2f>::fromObj(const Obj& mObj, T& mValue) +{ + extr(mObj, 0, mValue.x); + extr(mObj, 1, mValue.y); +} + +void Converter<sf::Vector2f>::toObj(Obj& mObj, const T& mValue) +{ + arch(mObj, 0, mValue.x); + arch(mObj, 1, mValue.y); +} + +void Converter<sf::Color>::fromObj(const Obj& mObj, T& mValue) +{ + extr(mObj, 0, mValue.r); + extr(mObj, 1, mValue.g); + extr(mObj, 2, mValue.b); + extr(mObj, 3, mValue.a); +} + +void Converter<sf::Color>::toObj(Obj& mObj, const T& mValue) +{ + arch(mObj, 0, mValue.r); + arch(mObj, 1, mValue.g); + arch(mObj, 2, mValue.b); + arch(mObj, 3, mValue.a); +} + +void Converter<ssvs::Input::Trigger>::fromObj(const Obj& mObj, T& mValue) +{ + extr(mObj, mValue.getCombos()); +} + +void Converter<ssvs::Input::Trigger>::toObj(Obj& mObj, const T& mValue) +{ + arch(mObj, mValue.getCombos()); +} + +void Converter<ssvs::KKey>::fromObj(const Obj& mObj, T& mValue) +{ + mValue = ssvs::getKKey(getExtr<std::string>(mObj)); +} + +void Converter<ssvs::KKey>::toObj(Obj& mObj, const T& mValue) +{ + if(mValue == T::Unknown) + { + std::string empty; + arch(mObj, empty); // TODO (P2): using `""` seems to be bugged + return; + } + + arch(mObj, ssvs::getKKeyName(mValue)); +} + +void Converter<ssvs::MBtn>::fromObj(const Obj& mObj, T& mValue) +{ + mValue = ssvs::getMBtn(getExtr<std::string>(mObj)); +} + +void Converter<ssvs::MBtn>::toObj(Obj& mObj, const T& mValue) +{ + arch(mObj, ssvs::getMBtnName(mValue)); +} + +void Converter<ssvs::Input::Combo>::fromObj(const Obj& mObj, T& mValue) +{ + mValue.clearBind(); + + std::string str; + + for(const auto& i : mObj) + { + str = getExtr<std::string>(i); + + if(str.empty()) + { + mValue.addKey(ssvs::KKey::Unknown); + } + else if(ssvs::isKKeyNameValid(str)) + { + mValue.addKey(getExtr<ssvs::KKey>(i)); + } + else if(ssvs::isMBtnNameValid(str)) + { + mValue.addBtn(getExtr<ssvs::MBtn>(i)); + } + else + { + ssvu::lo("ssvs::getInputComboFromJSON") + << "<" << i + << "> is not a valid input name, an empty bind has been " + "put in its place\n"; + + mValue.addKey(ssvs::KKey::Unknown); + } + } +} + +void Converter<ssvs::Input::Combo>::toObj(Obj& mObj, const T& mValue) +{ + if(mValue.isUnbound()) + { + arch(mObj, 0, ssvs::KKey(-1)); + return; + } + + auto i(0u); + const auto& keys(mValue.getKeys()); + const auto& btns(mValue.getBtns()); + + for(auto j(0u); j < ssvs::kKeyCount; ++j) + { + if(ssvs::getKeyBit(keys, ssvs::KKey(j))) + { + arch(mObj, i++, ssvs::KKey(j)); + } + } + + for(auto j(0u); j < ssvs::mBtnCount; ++j) + { + if(ssvs::getBtnBit(btns, ssvs::MBtn(j))) + { + arch(mObj, i++, ssvs::MBtn(j)); + } + } +} + +} // namespace ssvuj diff --git a/src/SSVOpenHexagon/Online/Compression.cpp b/src/SSVOpenHexagon/Online/Compression.cpp index e77bbb70..d2ff8509 100644 --- a/src/SSVOpenHexagon/Online/Compression.cpp +++ b/src/SSVOpenHexagon/Online/Compression.cpp @@ -9,6 +9,8 @@ #include <sstream> #include <cstring> +// TODO (P1): consider compressing replays/packets + namespace hg { std::string getZLibCompress(const std::string& mStr) diff --git a/src/SSVOpenHexagon/SSVUtilsJson/LinkedValue.cpp b/src/SSVOpenHexagon/SSVUtilsJson/LinkedValue.cpp new file mode 100644 index 00000000..661368ff --- /dev/null +++ b/src/SSVOpenHexagon/SSVUtilsJson/LinkedValue.cpp @@ -0,0 +1,69 @@ +// Copyright (c) 2013-2020 Vittorio Romeo +// License: Academic Free License ("AFL") v. 3.0 +// AFL License page: https://opensource.org/licenses/AFL-3.0 + +#include "SSVOpenHexagon/SSVUtilsJson/LinkedValue/LinkedValue.hpp" + +#include "SSVOpenHexagon/SSVUtilsJson/Global/Common.hpp" +#include "SSVOpenHexagon/SSVUtilsJson/Utils/Main.hpp" +#include "SSVOpenHexagon/SSVUtilsJson/Utils/BasicConverters.hpp" + +#include "SSVOpenHexagon/Global/UtilsJson.hpp" + +#include <SSVStart/Input/Input.hpp> + +#include <string> + +namespace ssvuj { + +template <typename T> +LinkedValue<T>::LinkedValue(const char* mLinkedName, const T& mDefault) + : name{mLinkedName}, value{mDefault}, defValue{mDefault} +{} + +template <typename T> +[[nodiscard]] LinkedValue<T>::operator T&() noexcept +{ + return value; +} + +template <typename T> +[[nodiscard]] LinkedValue<T>::operator const T&() const noexcept +{ + return value; +} + +template <typename T> +LinkedValue<T>& LinkedValue<T>::operator=(const T& mValue) +{ + value = mValue; + return *this; +} + +template <typename T> +void LinkedValue<T>::syncFrom(const Obj& mObj) +{ + value = getExtr(mObj, name, defValue); +} + +template <typename T> +void LinkedValue<T>::syncTo(Obj& mObj) const +{ + arch(mObj, name, value); +} + +template <typename T> +void LinkedValue<T>::resetToDefault() +{ + value = defValue; +} + +template class LinkedValue<bool>; +template class LinkedValue<int>; +template class LinkedValue<float>; +template class LinkedValue<unsigned int>; +template class LinkedValue<unsigned short>; +template class LinkedValue<std::string>; +template class LinkedValue<ssvs::Input::Trigger>; + +} // namespace ssvuj diff --git a/src/SSVOpenHexagon/Utils/LoadFromJson.cpp b/src/SSVOpenHexagon/Utils/LoadFromJson.cpp index 88b5efcb..2c955acc 100644 --- a/src/SSVOpenHexagon/Utils/LoadFromJson.cpp +++ b/src/SSVOpenHexagon/Utils/LoadFromJson.cpp @@ -44,7 +44,7 @@ namespace hg::Utils { : GameVersion{-1, 0, 0}; return {version, ssvuj::getExtr<std::string>(mRoot, "name"), - ssvuj::getObj(mRoot, "scores"), + ssvuj::getExtr<std::unordered_map<std::string, float>>(mRoot, "scores"), ssvuj::getExtr<std::vector<std::string>>(mRoot, "tracked_names", {}), ssvuj::getExtr<std::vector<std::string>>(mRoot, "favorites", {})}; } |