From 6cd74cc33b70d08d47b986d2b9f1fef195651311 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Fri, 24 May 2024 23:43:39 +0200 Subject: [PATCH 01/77] recordings: - add json serializer, atm only to_json is implemented - use static version constant instead of hardcoded magic value for recording file version --- src/helper/utils.hpp | 12 + src/recordings/additional_information.cpp | 22 +- src/recordings/additional_information.hpp | 39 +++- .../executable/command_line_arguments.hpp | 2 - src/recordings/executable/main.cpp | 44 +++- src/recordings/meson.build | 5 +- src/recordings/recording.hpp | 3 +- src/recordings/recording_json_wrapper.hpp | 206 ++++++++++++++++++ src/recordings/recording_reader.cpp | 14 +- src/recordings/recording_reader.hpp | 3 +- src/recordings/recording_writer.hpp | 1 - src/recordings/tetrion_snapshot.cpp | 16 ++ src/recordings/tetrion_snapshot.hpp | 8 + 13 files changed, 351 insertions(+), 24 deletions(-) create mode 100644 src/recordings/recording_json_wrapper.hpp diff --git a/src/helper/utils.hpp b/src/helper/utils.hpp index f88aa08b..b571898e 100644 --- a/src/helper/utils.hpp +++ b/src/helper/utils.hpp @@ -114,6 +114,18 @@ namespace utils { return is_child_class(parent.get()); } + template + struct IsIterator : std::false_type { }; + + template + struct IsIterator::iterator_category>> : std::true_type { }; + +#if __cpp_static_assert >= 202306L +#define STATIC_ASSERT_WITH_MESSAGE(check, msg) static_assert(check, msg); // NOLINT(cppcoreguidelines-macro-usage) +#else +#define STATIC_ASSERT_WITH_MESSAGE(check, msg) static_assert(check); // NOLINT(cppcoreguidelines-macro-usage) +#endif + } // namespace utils diff --git a/src/recordings/additional_information.cpp b/src/recordings/additional_information.cpp index 692339f7..8be23c5b 100644 --- a/src/recordings/additional_information.cpp +++ b/src/recordings/additional_information.cpp @@ -390,8 +390,7 @@ recorder::InformationValue::read_value_from_istream( // NOLINT(misc-no-recursion }; } -recorder::AdditionalInformation::AdditionalInformation(std::unordered_map&& values) - : m_values{ std::move(values) } { } +recorder::AdditionalInformation::AdditionalInformation(UnderlyingContainer&& values) : m_values{ std::move(values) } { } recorder::AdditionalInformation::AdditionalInformation() = default; @@ -414,7 +413,7 @@ helper::expected recorder::Additio return helper::unexpected{ "unable to read number of pairs" }; } - std::unordered_map values{}; + UnderlyingContainer values{}; values.reserve(num_pairs.value()); for (u32 i = 0; i < num_pairs.value(); ++i) { @@ -547,3 +546,20 @@ helper::optional recorder::AdditionalInformation::ge return sha256_creator.get_hash(); } + + +recorder::AdditionalInformation::iterator recorder::AdditionalInformation::begin() { + return m_values.begin(); +} + +recorder::AdditionalInformation::const_iterator recorder::AdditionalInformation::begin() const { + return m_values.begin(); +} + +recorder::AdditionalInformation::iterator recorder::AdditionalInformation::end() { + return m_values.end(); +} + +recorder::AdditionalInformation::const_iterator recorder::AdditionalInformation::end() const { + return m_values.end(); +} diff --git a/src/recordings/additional_information.hpp b/src/recordings/additional_information.hpp index feeefa84..d0893a82 100644 --- a/src/recordings/additional_information.hpp +++ b/src/recordings/additional_information.hpp @@ -20,9 +20,11 @@ namespace recorder { struct InformationValue { + using UnderlyingType = std:: + variant>; + private: - std::variant> - m_value; + UnderlyingType m_value; enum class ValueType : u8 { String = 0, Float, Double, Bool, U8, I8, U32, I32, U64, I64, Vector }; constexpr static u32 max_recursion_depth = 15; @@ -59,6 +61,9 @@ namespace recorder { return std::get(m_value); } + [[nodiscard]] const UnderlyingType& underlying() const { + return m_value; + } [[nodiscard]] std::string to_string(u32 recursion_depth = 0) const; @@ -129,9 +134,12 @@ namespace recorder { struct AdditionalInformation { private: static constexpr u32 magic_start_byte = 0xABCDEF01; - std::unordered_map m_values{}; - AdditionalInformation(std::unordered_map&& values); + using UnderlyingContainer = std::unordered_map; + + UnderlyingContainer m_values{}; + + explicit AdditionalInformation(UnderlyingContainer&& values); public: explicit AdditionalInformation(); @@ -170,7 +178,30 @@ namespace recorder { [[nodiscard]] helper::expected, std::string> to_bytes() const; [[nodiscard]] helper::expected get_checksum() const; + + // iterator trait + using iterator = UnderlyingContainer::iterator; //NOLINT(readability-identifier-naming) + using const_iterator = UnderlyingContainer::const_iterator; //NOLINT(readability-identifier-naming) + using difference_type = UnderlyingContainer::difference_type; //NOLINT(readability-identifier-naming) + using value_type = UnderlyingContainer::value_type; //NOLINT(readability-identifier-naming) + using pointer = UnderlyingContainer::pointer; //NOLINT(readability-identifier-naming) + using reference = UnderlyingContainer::reference; //NOLINT(readability-identifier-naming) + using iterator_category = std::bidirectional_iterator_tag; //NOLINT(readability-identifier-naming) + + + [[nodiscard]] iterator begin(); + + [[nodiscard]] const_iterator begin() const; + + [[nodiscard]] iterator end(); + + [[nodiscard]] const_iterator end() const; }; + STATIC_ASSERT_WITH_MESSAGE( + utils::IsIterator::value, + "AdditionalInformation has to be an iterator" + ); + } // namespace recorder diff --git a/src/recordings/executable/command_line_arguments.hpp b/src/recordings/executable/command_line_arguments.hpp index 67fa914c..7fab0140 100644 --- a/src/recordings/executable/command_line_arguments.hpp +++ b/src/recordings/executable/command_line_arguments.hpp @@ -1,13 +1,11 @@ #pragma once -#include "helper/optional.hpp" #include #include #include #include #include -#include enum class Command { Info, Dump }; diff --git a/src/recordings/executable/main.cpp b/src/recordings/executable/main.cpp index 85488de4..dd5decf9 100644 --- a/src/recordings/executable/main.cpp +++ b/src/recordings/executable/main.cpp @@ -1,10 +1,27 @@ #include "command_line_arguments.hpp" +#include "recording_json_wrapper.hpp" #include "recording_reader.hpp" #include #include +void print_info(const recorder::RecordingReader& recording_reader) { + //TODO(Totto): Implement + UNUSED(recording_reader); + std::cerr << "NOT IMPLEMENTED\n"; +} + +void dump_json(const recorder::RecordingReader& recording_reader) { + + nlohmann::json json_value; + + nlohmann::adl_serializer::to_json(json_value, recording_reader); + + json_value.dump(); +} + + int main(int argc, char** argv) noexcept { const auto arguments = CommandLineArguments(argc, argv); @@ -15,7 +32,32 @@ int main(int argc, char** argv) noexcept { } - const auto parsed = recorder::RecordingReader::from_path(arguments.recording_path); + auto parsed = recorder::RecordingReader::from_path(arguments.recording_path); + + if (not parsed.has_value()) { + std::cerr << fmt::format( + "An error occurred during parsing of the recording file '{}': {}\n", arguments.recording_path.string(), + parsed.error() + ); + return 1; + } + + + const auto recording_reader = std::move(parsed.value()); + + switch (arguments.command) { + case Command::Info: + print_info(recording_reader); + return 0; + case Command::Dump: + dump_json(recording_reader); + return 0; + default: + std::cerr << "Unknown command: ?\n"; + + return 1; + } + return 0; } diff --git a/src/recordings/meson.build b/src/recordings/meson.build index 5b6aa214..29605fe2 100644 --- a/src/recordings/meson.build +++ b/src/recordings/meson.build @@ -3,12 +3,13 @@ recordings_src_files = files( 'additional_information.hpp', 'checksum_helper.cpp', 'checksum_helper.hpp', - 'recording.cpp', - 'recording.hpp', + 'recording_json_wrapper.hpp', 'recording_reader.cpp', 'recording_reader.hpp', 'recording_writer.cpp', 'recording_writer.hpp', + 'recording.cpp', + 'recording.hpp', 'tetrion_snapshot.cpp', 'tetrion_snapshot.hpp', ) diff --git a/src/recordings/recording.hpp b/src/recordings/recording.hpp index 433d78e7..94ac56bf 100644 --- a/src/recordings/recording.hpp +++ b/src/recordings/recording.hpp @@ -40,7 +40,6 @@ namespace recorder { }; struct Recording { - protected: std::vector m_tetrion_headers; AdditionalInformation m_information; @@ -50,6 +49,8 @@ namespace recorder { m_information{ std::move(information) } { } public: + constexpr const static u8 version_number = 1; + Recording(const Recording&) = delete; Recording(Recording&&) = delete; Recording& operator=(const Recording&) = delete; diff --git a/src/recordings/recording_json_wrapper.hpp b/src/recordings/recording_json_wrapper.hpp new file mode 100644 index 00000000..503a88d3 --- /dev/null +++ b/src/recordings/recording_json_wrapper.hpp @@ -0,0 +1,206 @@ + + +#pragma once + +#include "additional_information.hpp" +#include "game/mino_stack.hpp" +#include "helper/magic_enum_wrapper.hpp" +#include "helper/parse_json.hpp" +#include "recording.hpp" +#include "recording_reader.hpp" +#include "tetrion_snapshot.hpp" + +namespace nlohmann { + template<> + struct adl_serializer { + static recorder::InformationValue from_json(const json& /* obj */) { + //TODO(Totto): Implement + throw std::runtime_error{ "NOT IMPLEMENTED" }; + } + + static void to_json(json& obj, const recorder::InformationValue& information) { + std::visit( + helper::overloaded{ + [&obj](const std::string& value) { obj = value; }, + [&obj](const float& value) { obj = value; }, [&obj](const double& value) { obj = value; }, + [&obj](const bool& value) { obj = value; }, [&obj](const u8& value) { obj = value; }, + [&obj](const i8& value) { obj = value; }, [&obj](const u32& value) { obj = value; }, + [&obj](const i32& value) { obj = value; }, [&obj](const u64& value) { obj = value; }, + [&obj](const i64& value) { obj = value; }, + [&obj](const std::vector& value) { // NOLINT(misc-no-recursion) + obj = value; + } }, + information.underlying() + ); + } + }; + + template<> + struct adl_serializer { + static recorder::AdditionalInformation from_json(const json& /* obj */) { + //TODO(Totto): Implement + throw std::runtime_error{ "NOT IMPLEMENTED" }; + } + + static void to_json(json& obj, const recorder::AdditionalInformation& information) { + + for (const auto& [key, value] : information) { + auto& context = obj.at(key); + nlohmann::adl_serializer::to_json(context, value); + } + } + }; + + template<> + struct adl_serializer { + static recorder::TetrionHeader from_json(const json& /* obj */) { + //TODO(Totto): Implement + throw std::runtime_error{ "NOT IMPLEMENTED" }; + } + + static void to_json(json& obj, const recorder::TetrionHeader& tetrion_header) { + obj = nlohmann::json{ + { "seed", tetrion_header.seed }, + { "starting_level", tetrion_header.starting_level } + }; + } + }; + + template<> + struct adl_serializer { + static InputEvent from_json(const json& /* obj */) { + //TODO(Totto): Implement + throw std::runtime_error{ "NOT IMPLEMENTED" }; + } + + static void to_json(json& obj, const InputEvent& event) { + + obj = magic_enum::enum_name(event); + } + }; + + template<> + struct adl_serializer { + static recorder::Record from_json(const json& /* obj */) { + //TODO(Totto): Implement + throw std::runtime_error{ "NOT IMPLEMENTED" }; + } + + static void to_json(json& obj, const recorder::Record& record) { + + obj = nlohmann::json{ + { "tetrion_index", record.tetrion_index }, + { "simulation_step_index", record.simulation_step_index }, + { "event", record.event } + }; + } + }; + + + template + struct adl_serializer> { + static shapes::AbstractPoint from_json(const json& /* obj */) { + //TODO(Totto): Implement + throw std::runtime_error{ "NOT IMPLEMENTED" }; + } + + static void to_json(json& obj, const shapes::AbstractPoint& point) { + obj = nlohmann::json{ + { "x", point.x }, + { "y", point.y } + }; + } + }; + + + template<> + struct adl_serializer { + static helper::TetrominoType from_json(const json& /* obj */) { + //TODO(Totto): Implement + throw std::runtime_error{ "NOT IMPLEMENTED" }; + } + + static void to_json(json& obj, const helper::TetrominoType& type) { + obj = magic_enum::enum_name(type); + } + }; + + + template<> + struct adl_serializer { + static Mino from_json(const json& /* obj */) { + //TODO(Totto): Implement + throw std::runtime_error{ "NOT IMPLEMENTED" }; + } + + static void to_json(json& obj, const Mino& mino) { + obj = nlohmann::json{ + { "position", mino.position() }, + { "type", mino.type() } + }; + } + }; + + + template<> + struct adl_serializer { + static TetrionSnapshot from_json(const json& /* obj */) { + //TODO(Totto): Implement + throw std::runtime_error{ "NOT IMPLEMENTED" }; + } + + static void to_json(json& obj, const TetrionSnapshot& snapshot) { + + json mino_stack_json; + nlohmann::adl_serializer>::to_json(mino_stack_json, snapshot.mino_stack().minos()); + + + obj = nlohmann::json{ + { "tetrion_index", snapshot.tetrion_index() }, + { "level", snapshot.level() }, + { "score", snapshot.score() }, + { "lines_cleared", snapshot.lines_cleared() }, + { "simulation_step_index", snapshot.simulation_step_index() }, + { "mino_stack", mino_stack_json } + }; + } + }; + + + template<> + struct adl_serializer { + static recorder::RecordingReader from_json(const json& /* obj */) { + //TODO(Totto): Implement + throw std::runtime_error{ "NOT IMPLEMENTED" }; + } + + static void to_json(json& obj, const recorder::RecordingReader& recording_reader) { + + json information_json; + nlohmann::adl_serializer::to_json( + information_json, recording_reader.information() + ); + + json tetrion_headers_json; + nlohmann::adl_serializer>::to_json( + tetrion_headers_json, recording_reader.tetrion_headers() + ); + + json records_json; + nlohmann::adl_serializer>::to_json(records_json, recording_reader.records()); + + json snapshots_json; + nlohmann::adl_serializer>>::to_json( + snapshots_json, recording_reader.snapshots() + ); + + obj = nlohmann::json{ + { "version", recorder::Recording::version_number }, + { "information", information_json }, + { "tetrion_headers", tetrion_headers_json }, + { "records", records_json }, + { "snapshots", snapshots_json }, + }; + } + }; +} // namespace nlohmann diff --git a/src/recordings/recording_reader.cpp b/src/recordings/recording_reader.cpp index ceac9cfa..31deff07 100644 --- a/src/recordings/recording_reader.cpp +++ b/src/recordings/recording_reader.cpp @@ -50,10 +50,11 @@ recorder::RecordingReader::get_header_from_path(const std::filesystem::path& pat if (not version_number.has_value()) { return helper::unexpected{ "unable to read recording version from recorded game" }; } - if (version_number.value() != 1) { - return helper::unexpected{ - fmt::format("only supported version at the moment is {}, but got {}", 1, version_number.value()) - }; + if (version_number.value() != Recording::version_number) { + return helper::unexpected{ fmt::format( + "only supported version at the moment is {}, but got {}", Recording::version_number, + version_number.value() + ) }; } const auto num_tetrions = helper::reader::read_integral_from_file(file); @@ -172,12 +173,9 @@ helper::expected recorder::RecordingRead return m_records.cend(); } -[[nodiscard]] const std::vector& recorder::RecordingReader::records() { +[[nodiscard]] const std::vector& recorder::RecordingReader::records() const { return m_records; } -[[nodiscard]] const std::vector& recorder::RecordingReader::snapshots() { - return m_snapshots; -} [[nodiscard]] const std::vector& recorder::RecordingReader::snapshots() const { return m_snapshots; diff --git a/src/recordings/recording_reader.hpp b/src/recordings/recording_reader.hpp index 0841f75d..1cc2bff9 100644 --- a/src/recordings/recording_reader.hpp +++ b/src/recordings/recording_reader.hpp @@ -32,8 +32,7 @@ namespace recorder { [[nodiscard]] auto begin() const; [[nodiscard]] auto end() const; - [[nodiscard]] const std::vector& records(); - [[nodiscard]] const std::vector& snapshots(); + [[nodiscard]] const std::vector& records() const; [[nodiscard]] const std::vector& snapshots() const; diff --git a/src/recordings/recording_writer.hpp b/src/recordings/recording_writer.hpp index 509f7987..90189720 100644 --- a/src/recordings/recording_writer.hpp +++ b/src/recordings/recording_writer.hpp @@ -13,7 +13,6 @@ namespace recorder { struct RecordingWriter : public Recording { private: std::ofstream m_output_file; - constexpr static u8 version_number = 1; explicit RecordingWriter( std::ofstream&& output_file, diff --git a/src/recordings/tetrion_snapshot.cpp b/src/recordings/tetrion_snapshot.cpp index 0dff1256..8352d21c 100644 --- a/src/recordings/tetrion_snapshot.cpp +++ b/src/recordings/tetrion_snapshot.cpp @@ -103,10 +103,26 @@ TetrionSnapshot::TetrionSnapshot( return m_tetrion_index; } +[[nodiscard]] TetrionSnapshot::Level TetrionSnapshot::level() const { + return m_level; +} + +[[nodiscard]] TetrionSnapshot::Score TetrionSnapshot::score() const { + return m_score; +} + +[[nodiscard]] TetrionSnapshot::LineCount TetrionSnapshot::lines_cleared() const { + return m_lines_cleared; +} + [[nodiscard]] u64 TetrionSnapshot::simulation_step_index() const { return m_simulation_step_index; } +[[nodiscard]] const MinoStack& TetrionSnapshot::mino_stack() const { + return m_mino_stack; +} + [[nodiscard]] std::vector TetrionSnapshot::to_bytes() const { auto bytes = std::vector{}; diff --git a/src/recordings/tetrion_snapshot.hpp b/src/recordings/tetrion_snapshot.hpp index 31264ae4..761df5fc 100644 --- a/src/recordings/tetrion_snapshot.hpp +++ b/src/recordings/tetrion_snapshot.hpp @@ -45,8 +45,16 @@ struct TetrionSnapshot final { [[nodiscard]] u8 tetrion_index() const; + [[nodiscard]] Level level() const; + + [[nodiscard]] Score score() const; + + [[nodiscard]] LineCount lines_cleared() const; + [[nodiscard]] u64 simulation_step_index() const; + [[nodiscard]] const MinoStack& mino_stack() const; + [[nodiscard]] std::vector to_bytes() const; [[nodiscard]] helper::expected compare_to(const TetrionSnapshot& other) const; From 9c737748342538da31eb97ee79a532d152639d1b Mon Sep 17 00:00:00 2001 From: Totto16 Date: Fri, 24 May 2024 23:59:05 +0200 Subject: [PATCH 02/77] recordings: fix a few errors in the json serialization --- src/recordings/recording_json_wrapper.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/recordings/recording_json_wrapper.hpp b/src/recordings/recording_json_wrapper.hpp index 503a88d3..24c793e1 100644 --- a/src/recordings/recording_json_wrapper.hpp +++ b/src/recordings/recording_json_wrapper.hpp @@ -44,9 +44,13 @@ namespace nlohmann { static void to_json(json& obj, const recorder::AdditionalInformation& information) { + obj = nlohmann::json::object(); + for (const auto& [key, value] : information) { - auto& context = obj.at(key); - nlohmann::adl_serializer::to_json(context, value); + + json value_json; + nlohmann::adl_serializer::to_json(value_json, value); + obj[key] = value_json; } } }; From 28843cd397d4e24c0a579ca76bec3cd032cbc26b Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 00:20:47 +0200 Subject: [PATCH 03/77] recordings: use better command parser to also specify json dump options --- .../executable/command_line_arguments.hpp | 53 +++++++++++++------ src/recordings/executable/main.cpp | 33 +++++++----- 2 files changed, 56 insertions(+), 30 deletions(-) diff --git a/src/recordings/executable/command_line_arguments.hpp b/src/recordings/executable/command_line_arguments.hpp index 7fab0140..e42c7e98 100644 --- a/src/recordings/executable/command_line_arguments.hpp +++ b/src/recordings/executable/command_line_arguments.hpp @@ -7,44 +7,65 @@ #include #include -enum class Command { Info, Dump }; + +struct Dump { + bool ensure_ascii; + bool pretty_print; +}; + +struct Info { }; + struct CommandLineArguments final { private: public: std::filesystem::path recording_path{}; - Command command{ Command::Info }; + std::variant value; + CommandLineArguments(int argc, char** argv) { argparse::ArgumentParser parser{ argc >= 1 ? argv[0] //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) : "oopetris_recording_utility", "0.0.1", argparse::default_arguments::all }; - parser.add_argument("command") - .help("specify the command") - .default_value(std::string{ "info" }) - .choices("info", "i", "dump", "d") - .required(); parser.add_argument("-r", "--recording").help("the path of a recorded game file").required(); + + + // git add subparser + argparse::ArgumentParser dump_parser("dump"); + dump_parser.add_description("Dump JSON value"); + dump_parser.add_argument("-a", "--ensure-ascii") + .help("Only use ASCII characters and escape sequences (\\uXXXX)") + .flag(); + dump_parser.add_argument("-p", "--pretty-print").help("Pretty print the JSON").flag(); + + argparse::ArgumentParser info_parser("info"); + info_parser.add_description("Print hHuman readable Info"); + + + parser.add_subparser(dump_parser); + parser.add_subparser(info_parser); + try { parser.parse_args(argc, argv); - recording_path = parser.get("--recording"); + this->recording_path = parser.get("--recording"); - const auto command_string = parser.get("command"); + if (parser.is_subcommand_used(dump_parser)) { + const auto ensure_ascii = dump_parser.get("--ensure-ascii"); + const auto pretty_print = dump_parser.get("--pretty-print"); + this->value = Dump{ .ensure_ascii = ensure_ascii, .pretty_print = pretty_print }; - if (command_string == "info" or command_string == "i") { - command = Command::Info; - } else if (command_string == "dump" || command_string == "d") { - command = Command::Dump; + } else if (parser.is_subcommand_used(info_parser)) { + this->value = Info{}; } else { - throw std::runtime_error(fmt::format("Unknown command: '{}'", command_string)); + throw std::runtime_error("Unknown or no subcommand used"); } - } catch (const std::exception& err) { - std::cerr << err.what(); + } catch (const std::exception& error) { + std::cerr << error.what(); std::exit(1); } } diff --git a/src/recordings/executable/main.cpp b/src/recordings/executable/main.cpp index dd5decf9..7e5ab061 100644 --- a/src/recordings/executable/main.cpp +++ b/src/recordings/executable/main.cpp @@ -12,13 +12,23 @@ void print_info(const recorder::RecordingReader& recording_reader) { std::cerr << "NOT IMPLEMENTED\n"; } -void dump_json(const recorder::RecordingReader& recording_reader) { +void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_print, bool ensure_ascii) { nlohmann::json json_value; nlohmann::adl_serializer::to_json(json_value, recording_reader); - json_value.dump(); + int indent = -1; + char indent_char = ' '; + if (pretty_print) { + indent = 4; + } + + std::cout << json_value.dump(indent, indent_char, ensure_ascii); + + if (pretty_print) { + std::cout << "\n"; + } } @@ -45,18 +55,13 @@ int main(int argc, char** argv) noexcept { const auto recording_reader = std::move(parsed.value()); - switch (arguments.command) { - case Command::Info: - print_info(recording_reader); - return 0; - case Command::Dump: - dump_json(recording_reader); - return 0; - default: - std::cerr << "Unknown command: ?\n"; - - return 1; - } + std::visit( + helper::overloaded{ [&recording_reader](const Dump& dump) { + dump_json(recording_reader, dump.pretty_print, dump.ensure_ascii); + }, + [&recording_reader](const Info& /* info */) { print_info(recording_reader); } }, + arguments.value + ); return 0; From 27e04a84ad23ed222a501a5ba76ed06abf74a6ff Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 02:46:36 +0200 Subject: [PATCH 04/77] meson improvements: - be subproject agnostic (e.g,. this project can be used as subproject) - override teh declared dependencies, so that it's easier to use those dependencies elsewhere --- src/meson.build | 7 +++---- src/recordings/meson.build | 5 ++--- tools/options/meson.build | 11 +++++++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/meson.build b/src/meson.build index 9152205c..6c26d606 100644 --- a/src/meson.build +++ b/src/meson.build @@ -25,12 +25,10 @@ if online_multiplayer_supported subdir('lobby') endif - if have_discord_sdk subdir('discord') endif - core_lib += { 'src_files': [core_lib.get('src_files'), core_src_files], 'inc_dirs': [core_lib.get('inc_dirs'), include_directories('.')], @@ -69,7 +67,7 @@ liboopetris_core_dep = declare_dependency( dependencies: core_lib.get('deps'), version: meson.project_version(), ) - +meson.override_dependency('oopetris-core', liboopetris_core_dep) recordings_lib += { 'deps': [recordings_lib.get('deps'), liboopetris_core_dep, global_deps], @@ -96,12 +94,12 @@ liboopetris_recordings_dep = declare_dependency( dependencies: recordings_lib.get('deps'), version: meson.project_version(), ) +meson.override_dependency('oopetris-recordings', liboopetris_recordings_dep) graphics_lib += { 'deps': [graphics_lib.get('deps'), liboopetris_recordings_dep, global_deps], } - liboopetris_graphics = library( 'oopetris_graphics', graphics_lib.get('src_files'), @@ -123,6 +121,7 @@ liboopetris_graphics_dep = declare_dependency( dependencies: graphics_lib.get('deps'), version: meson.project_version(), ) +meson.override_dependency('oopetris-graphics', liboopetris_graphics_dep) # setting this to strings, so += {...} gets detected as an error, if it is done after that core_lib = 'undefined' diff --git a/src/recordings/meson.build b/src/recordings/meson.build index 29605fe2..b30b0833 100644 --- a/src/recordings/meson.build +++ b/src/recordings/meson.build @@ -3,18 +3,17 @@ recordings_src_files = files( 'additional_information.hpp', 'checksum_helper.cpp', 'checksum_helper.hpp', + 'recording.cpp', + 'recording.hpp', 'recording_json_wrapper.hpp', 'recording_reader.cpp', 'recording_reader.hpp', 'recording_writer.cpp', 'recording_writer.hpp', - 'recording.cpp', - 'recording.hpp', 'tetrion_snapshot.cpp', 'tetrion_snapshot.hpp', ) - subdir('executable') recordings_lib += { diff --git a/tools/options/meson.build b/tools/options/meson.build index a7e1a144..f025906e 100644 --- a/tools/options/meson.build +++ b/tools/options/meson.build @@ -55,8 +55,15 @@ elif cpp.get_id() == 'clang' endif if build_with_libcpp - add_global_link_arguments('-stdlib=libc++', language: ['cpp']) - add_global_arguments('-stdlib=libc++', language: ['cpp']) + if not meson.is_subproject() + add_global_link_arguments('-stdlib=libc++', language: ['cpp']) + add_global_arguments('-stdlib=libc++', language: ['cpp']) + else + add_project_link_arguments('-stdlib=libc++', language: ['cpp']) + add_project_arguments('-stdlib=libc++', language: ['cpp']) + + endif + global_deps += [cpp.find_library('c++'), cpp.find_library('c++abi')] endif From 47aacea76471465d9c71a06917494deb5a39b062 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 15:35:07 +0200 Subject: [PATCH 05/77] - add pkg-config files to install target - fix a few meson things --- src/meson.build | 7 ++++--- tools/dependencies/meson.build | 7 ++----- tools/install/meson.build | 27 ++++++++++++++++++++++----- tools/options/meson.build | 3 --- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/meson.build b/src/meson.build index 6c26d606..30e019f7 100644 --- a/src/meson.build +++ b/src/meson.build @@ -30,16 +30,16 @@ if have_discord_sdk endif core_lib += { - 'src_files': [core_lib.get('src_files'), core_src_files], + 'src_files': [core_src_files], 'inc_dirs': [core_lib.get('inc_dirs'), include_directories('.')], } recordings_lib += { - 'src_files': [recordings_lib.get('src_files'), recordings_src_files], + 'src_files': [recordings_src_files], } graphics_lib += { - 'src_files': [graphics_lib.get('src_files'), graphics_src_files], + 'src_files': [graphics_src_files], } core_lib += { @@ -123,6 +123,7 @@ liboopetris_graphics_dep = declare_dependency( ) meson.override_dependency('oopetris-graphics', liboopetris_graphics_dep) + # setting this to strings, so += {...} gets detected as an error, if it is done after that core_lib = 'undefined' recordings_lib = 'undefined' diff --git a/tools/dependencies/meson.build b/tools/dependencies/meson.build index fa88ca90..1a3b1e9b 100644 --- a/tools/dependencies/meson.build +++ b/tools/dependencies/meson.build @@ -243,7 +243,7 @@ else 'cpp-httplib_zlib': 'enabled', }, ) - core_lib += {'deps': [core_lib.get('deps'), cpp_httlib_dep]} + graphics_lib += {'deps': [graphics_lib.get('deps'), cpp_httlib_dep]} endif utf8cpp_dep = dependency( @@ -296,10 +296,7 @@ endif if is_flatpak_build app_name = 'com.github.mgerhold.OOPetris' core_lib += { - 'compile_args': [ - core_lib.get('compile_args'), - '-DFLATPAK_BUILD' - ], + 'compile_args': [core_lib.get('compile_args'), '-DFLATPAK_BUILD'], } endif diff --git a/tools/install/meson.build b/tools/install/meson.build index 5c99cdd4..cfbabcb4 100644 --- a/tools/install/meson.build +++ b/tools/install/meson.build @@ -1,4 +1,3 @@ - ## TODO: only install needed ones, since sometimes we only need e.g. flacs or mp3 and no icons etc. ## install assets install_subdir( @@ -18,16 +17,13 @@ conf.set('APP_NAME', app_name) datadir = get_option('prefix') / get_option('datadir') - if host_machine.system() == 'linux' fs = import('fs') magic_dir = datadir / 'misc' magic_file = magic_dir / 'magic' - oopetris_magic_file = ( - meson.project_source_root() / 'assets' / 'recordings.magic' - ) + oopetris_magic_file = (meson.project_source_root() / 'assets' / 'recordings.magic') if fs.exists(magic_file) @@ -85,3 +81,24 @@ foreach logo : logos rename: [app_name + '.' + ext], ) endforeach + +# generate pkgconfig filres +pkg = import('pkgconfig') +pkg.generate( + liboopetris_core, + name: 'oopetris-core', + filebase: 'oopetris-core', + +) + +pkg.generate( + liboopetris_recordings, + name: 'oopetris-recordings', + filebase: 'oopetris-recordings', +) + +pkg.generate( + liboopetris_graphics, + name: 'oopetris-graphics', + filebase: 'oopetris-graphics', +) diff --git a/tools/options/meson.build b/tools/options/meson.build index f025906e..af84d266 100644 --- a/tools/options/meson.build +++ b/tools/options/meson.build @@ -1,5 +1,4 @@ core_lib = { - 'src_files': [], 'inc_dirs': [], 'compile_args': [ '-DOOPETRIS_VERSION=' + meson.project_version(), @@ -10,14 +9,12 @@ core_lib = { } recordings_lib = { - 'src_files': [], 'inc_dirs': [], 'compile_args': [], 'deps': [], } graphics_lib = { - 'src_files': [], 'inc_dirs': [], 'compile_args': [], 'deps': [], From 7a90eb0f31d10f72854b6efcf91576a0a23eaf56 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 16:10:39 +0200 Subject: [PATCH 06/77] clean up meson file --- src/meson.build | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/meson.build b/src/meson.build index 30e019f7..c9daca7f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -30,25 +30,13 @@ if have_discord_sdk endif core_lib += { - 'src_files': [core_src_files], 'inc_dirs': [core_lib.get('inc_dirs'), include_directories('.')], -} - -recordings_lib += { - 'src_files': [recordings_src_files], -} - -graphics_lib += { - 'src_files': [graphics_src_files], -} - -core_lib += { 'deps': [core_lib.get('deps'), global_deps], } liboopetris_core = library( 'oopetris_core', - core_lib.get('src_files'), + core_src_files, include_directories: core_lib.get('inc_dirs'), dependencies: core_lib.get('deps'), cpp_args: core_lib.get('compile_args'), @@ -75,7 +63,7 @@ recordings_lib += { liboopetris_recordings = library( 'oopetris_recordings', - recordings_lib.get('src_files'), + recordings_src_files, include_directories: recordings_lib.get('inc_dirs'), dependencies: recordings_lib.get('deps'), cpp_args: recordings_lib.get('compile_args'), @@ -102,7 +90,7 @@ graphics_lib += { liboopetris_graphics = library( 'oopetris_graphics', - graphics_lib.get('src_files'), + graphics_src_files, include_directories: graphics_lib.get('inc_dirs'), dependencies: graphics_lib.get('deps'), cpp_args: graphics_lib.get('compile_args'), @@ -123,7 +111,6 @@ liboopetris_graphics_dep = declare_dependency( ) meson.override_dependency('oopetris-graphics', liboopetris_graphics_dep) - # setting this to strings, so += {...} gets detected as an error, if it is done after that core_lib = 'undefined' recordings_lib = 'undefined' From 64fe4f62aeb331b8bb1ab7f96fd444d6e0a786ec Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 16:14:20 +0200 Subject: [PATCH 07/77] RecordingReade: fix name shadowing --- src/recordings/recording_reader.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/recordings/recording_reader.cpp b/src/recordings/recording_reader.cpp index 31deff07..9cdcb7e6 100644 --- a/src/recordings/recording_reader.cpp +++ b/src/recordings/recording_reader.cpp @@ -46,14 +46,14 @@ recorder::RecordingReader::get_header_from_path(const std::filesystem::path& pat }; } - const auto version_number = helper::reader::read_integral_from_file(file); - if (not version_number.has_value()) { + const auto read_version_number = helper::reader::read_integral_from_file(file); + if (not read_version_number.has_value()) { return helper::unexpected{ "unable to read recording version from recorded game" }; } - if (version_number.value() != Recording::version_number) { + if (read_version_number.value() != Recording::version_number) { return helper::unexpected{ fmt::format( "only supported version at the moment is {}, but got {}", Recording::version_number, - version_number.value() + read_version_number.value() ) }; } From cf7c2fa830721aae030e9ddc76745eab54cbd7b0 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 16:16:49 +0200 Subject: [PATCH 08/77] fix overridden dependencies --- src/meson.build | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/meson.build b/src/meson.build index c9daca7f..7db1ed8c 100644 --- a/src/meson.build +++ b/src/meson.build @@ -55,7 +55,7 @@ liboopetris_core_dep = declare_dependency( dependencies: core_lib.get('deps'), version: meson.project_version(), ) -meson.override_dependency('oopetris-core', liboopetris_core_dep) +meson.override_dependency('liboopetris-core', liboopetris_core_dep) recordings_lib += { 'deps': [recordings_lib.get('deps'), liboopetris_core_dep, global_deps], @@ -82,7 +82,7 @@ liboopetris_recordings_dep = declare_dependency( dependencies: recordings_lib.get('deps'), version: meson.project_version(), ) -meson.override_dependency('oopetris-recordings', liboopetris_recordings_dep) +meson.override_dependency('liboopetris-recordings', liboopetris_recordings_dep) graphics_lib += { 'deps': [graphics_lib.get('deps'), liboopetris_recordings_dep, global_deps], @@ -109,7 +109,7 @@ liboopetris_graphics_dep = declare_dependency( dependencies: graphics_lib.get('deps'), version: meson.project_version(), ) -meson.override_dependency('oopetris-graphics', liboopetris_graphics_dep) +meson.override_dependency('liboopetris-graphics', liboopetris_graphics_dep) # setting this to strings, so += {...} gets detected as an error, if it is done after that core_lib = 'undefined' From 8a6343ed9e11a26f34179ea9a6a9684e68b97fdf Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 16:21:19 +0200 Subject: [PATCH 09/77] fix small refactoring error --- src/recordings/recording_reader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/recordings/recording_reader.cpp b/src/recordings/recording_reader.cpp index 9cdcb7e6..bb28c212 100644 --- a/src/recordings/recording_reader.cpp +++ b/src/recordings/recording_reader.cpp @@ -81,7 +81,7 @@ recorder::RecordingReader::get_header_from_path(const std::filesystem::path& pat const auto calculated_checksum = - Recording::get_header_checksum(version_number.value(), tetrion_headers, information.value()); + Recording::get_header_checksum(read_version_number.value(), tetrion_headers, information.value()); const auto read_checksum = helper::reader::read_array_from_file( From 32eca5b8f695a7610a21dfcf0b70eb81adf1a73d Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 16:47:59 +0200 Subject: [PATCH 10/77] fix name shadowing once and for all --- src/recordings/recording.hpp | 2 +- src/recordings/recording_json_wrapper.hpp | 10 +++++----- src/recordings/recording_reader.cpp | 12 ++++++------ src/recordings/recording_writer.cpp | 8 +++++--- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/recordings/recording.hpp b/src/recordings/recording.hpp index 94ac56bf..191d240d 100644 --- a/src/recordings/recording.hpp +++ b/src/recordings/recording.hpp @@ -49,7 +49,7 @@ namespace recorder { m_information{ std::move(information) } { } public: - constexpr const static u8 version_number = 1; + constexpr const static u8 current_supported_version_number = 1; Recording(const Recording&) = delete; Recording(Recording&&) = delete; diff --git a/src/recordings/recording_json_wrapper.hpp b/src/recordings/recording_json_wrapper.hpp index 24c793e1..0e1cd5db 100644 --- a/src/recordings/recording_json_wrapper.hpp +++ b/src/recordings/recording_json_wrapper.hpp @@ -199,11 +199,11 @@ namespace nlohmann { ); obj = nlohmann::json{ - { "version", recorder::Recording::version_number }, - { "information", information_json }, - { "tetrion_headers", tetrion_headers_json }, - { "records", records_json }, - { "snapshots", snapshots_json }, + { "version", recorder::Recording::current_supported_version_number }, + { "information", information_json }, + { "tetrion_headers", tetrion_headers_json }, + { "records", records_json }, + { "snapshots", snapshots_json }, }; } }; diff --git a/src/recordings/recording_reader.cpp b/src/recordings/recording_reader.cpp index bb28c212..1822f9b3 100644 --- a/src/recordings/recording_reader.cpp +++ b/src/recordings/recording_reader.cpp @@ -46,14 +46,14 @@ recorder::RecordingReader::get_header_from_path(const std::filesystem::path& pat }; } - const auto read_version_number = helper::reader::read_integral_from_file(file); - if (not read_version_number.has_value()) { + const auto version_number = helper::reader::read_integral_from_file(file); + if (not version_number.has_value()) { return helper::unexpected{ "unable to read recording version from recorded game" }; } - if (read_version_number.value() != Recording::version_number) { + if (version_number.value() != Recording::current_supported_version_number) { return helper::unexpected{ fmt::format( - "only supported version at the moment is {}, but got {}", Recording::version_number, - read_version_number.value() + "only supported version at the moment is {}, but got {}", Recording::current_supported_version_number, + version_number.value() ) }; } @@ -81,7 +81,7 @@ recorder::RecordingReader::get_header_from_path(const std::filesystem::path& pat const auto calculated_checksum = - Recording::get_header_checksum(read_version_number.value(), tetrion_headers, information.value()); + Recording::get_header_checksum(version_number.value(), tetrion_headers, information.value()); const auto read_checksum = helper::reader::read_array_from_file( diff --git a/src/recordings/recording_writer.cpp b/src/recordings/recording_writer.cpp index 7b876ce3..b0ee8398 100644 --- a/src/recordings/recording_writer.cpp +++ b/src/recordings/recording_writer.cpp @@ -1,4 +1,5 @@ #include "recording_writer.hpp" +#include "recording.hpp" #include "tetrion_snapshot.hpp" recorder::RecordingWriter::RecordingWriter( @@ -35,8 +36,8 @@ helper::expected recorder::RecordingWrit return helper::unexpected{ fmt::format("error while writing: {}", result.error()) }; } - static_assert(sizeof(RecordingWriter::version_number) == 1); - result = helper::writer::write_integral_to_file(output_file, RecordingWriter::version_number); + static_assert(sizeof(Recording::current_supported_version_number) == 1); + result = helper::writer::write_integral_to_file(output_file, Recording::current_supported_version_number); if (not result.has_value()) { return helper::unexpected{ fmt::format("error while writing: {}", result.error()) }; } @@ -156,7 +157,8 @@ helper::expected recorder::RecordingWriter::write_checksum_to const AdditionalInformation& information ) { - const auto checksum = Recording::get_header_checksum(RecordingWriter::version_number, tetrion_headers, information); + const auto checksum = + Recording::get_header_checksum(Recording::current_supported_version_number, tetrion_headers, information); static_assert(sizeof(decltype(checksum)) == 32); helper::expected result{ true }; From b5f82da5f30c42c83ca979ba33b27c6057f2a89f Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 17:05:25 +0200 Subject: [PATCH 11/77] fix clang-tidy warnings --- src/recordings/additional_information.hpp | 2 +- src/recordings/executable/main.cpp | 8 +++++--- src/recordings/recording_json_wrapper.hpp | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/recordings/additional_information.hpp b/src/recordings/additional_information.hpp index d0893a82..3a6794a0 100644 --- a/src/recordings/additional_information.hpp +++ b/src/recordings/additional_information.hpp @@ -137,7 +137,7 @@ namespace recorder { using UnderlyingContainer = std::unordered_map; - UnderlyingContainer m_values{}; + UnderlyingContainer m_values; explicit AdditionalInformation(UnderlyingContainer&& values); diff --git a/src/recordings/executable/main.cpp b/src/recordings/executable/main.cpp index 7e5ab061..f5c44d18 100644 --- a/src/recordings/executable/main.cpp +++ b/src/recordings/executable/main.cpp @@ -6,7 +6,7 @@ #include #include -void print_info(const recorder::RecordingReader& recording_reader) { +void print_info(const recorder::RecordingReader& recording_reader) noexcept { //TODO(Totto): Implement UNUSED(recording_reader); std::cerr << "NOT IMPLEMENTED\n"; @@ -20,8 +20,10 @@ void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_pr int indent = -1; char indent_char = ' '; + if (pretty_print) { - indent = 4; + indent = 1; + indent_char = '\t'; } std::cout << json_value.dump(indent, indent_char, ensure_ascii); @@ -32,7 +34,7 @@ void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_pr } -int main(int argc, char** argv) noexcept { +int main(int argc, char** argv) { const auto arguments = CommandLineArguments(argc, argv); diff --git a/src/recordings/recording_json_wrapper.hpp b/src/recordings/recording_json_wrapper.hpp index 0e1cd5db..f05e7938 100644 --- a/src/recordings/recording_json_wrapper.hpp +++ b/src/recordings/recording_json_wrapper.hpp @@ -18,7 +18,7 @@ namespace nlohmann { throw std::runtime_error{ "NOT IMPLEMENTED" }; } - static void to_json(json& obj, const recorder::InformationValue& information) { + static void to_json(json& obj, const recorder::InformationValue& information) { // NOLINT(misc-no-recursion) std::visit( helper::overloaded{ [&obj](const std::string& value) { obj = value; }, From 5b94097ccd3c0dcbd6fd3df64e37df935f52db58 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 17:05:42 +0200 Subject: [PATCH 12/77] try to force std::optional and std::expected in all cases --- tools/dependencies/meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/dependencies/meson.build b/tools/dependencies/meson.build index 1a3b1e9b..a96450ad 100644 --- a/tools/dependencies/meson.build +++ b/tools/dependencies/meson.build @@ -172,7 +172,7 @@ int main() { ) if not have_std_expected - message('Compiler doesn\'t support std::expected, using fallback') + error('Compiler doesn\'t support std::expected, using fallback') tl_exp_dep = dependency('tl-expected', required: true) core_lib += { @@ -196,7 +196,7 @@ int main() { ) if not have_std_optional - message('Compiler doesn\'t support std::optional, using fallback') + error('Compiler doesn\'t support std::optional, using fallback') tl_opt_dep = dependency('tl-optional', required: true) core_lib += { 'compile_args': [core_lib.get('compile_args'), '-D_USE_TL_OPTIONAL'], From f8bcb3f1795517d56fe1e5bf8afb3717ef65f126 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 17:10:42 +0200 Subject: [PATCH 13/77] adding '-stdlib=libc++' to arguments, so that detecting works as expected --- tools/options/meson.build | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/options/meson.build b/tools/options/meson.build index af84d266..22b80faa 100644 --- a/tools/options/meson.build +++ b/tools/options/meson.build @@ -52,6 +52,11 @@ elif cpp.get_id() == 'clang' endif if build_with_libcpp + + core_lib += { + 'compile_args': [core_lib.get('compile_args'), '-stdlib=libc++'], + } + if not meson.is_subproject() add_global_link_arguments('-stdlib=libc++', language: ['cpp']) add_global_arguments('-stdlib=libc++', language: ['cpp']) From b3f741e1c66e87aafdbfeccbc66bab5d2047451f Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 17:18:32 +0200 Subject: [PATCH 14/77] circumvent the issue with clang + stdlibc++ for std::expected --- tools/dependencies/meson.build | 6 +++++- tools/options/meson.build | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/dependencies/meson.build b/tools/dependencies/meson.build index a96450ad..98534224 100644 --- a/tools/dependencies/meson.build +++ b/tools/dependencies/meson.build @@ -172,7 +172,11 @@ int main() { ) if not have_std_expected - error('Compiler doesn\'t support std::expected, using fallback') + if not allow_tl_expected_fallback + error('Compiler doesn\'t support std::expected') + endif + + message('Compiler doesn\'t support std::expected, using fallback') tl_exp_dep = dependency('tl-expected', required: true) core_lib += { diff --git a/tools/options/meson.build b/tools/options/meson.build index 22b80faa..62065b46 100644 --- a/tools/options/meson.build +++ b/tools/options/meson.build @@ -27,6 +27,8 @@ cpp = meson.get_compiler('cpp') build_with_libcpp = false +allow_tl_expected_fallback = false + if cpp.get_id() == 'gcc' add_project_arguments('-Wold-style-cast', language: ['cpp']) elif cpp.get_id() == 'clang' @@ -67,6 +69,9 @@ elif cpp.get_id() == 'clang' endif global_deps += [cpp.find_library('c++'), cpp.find_library('c++abi')] + else + # TODO: once clang with libstdc++ (gcc c++ stdlib) supports std::expectedt, remove this special behaviour + allow_tl_expected_fallback = true endif endif From a5b172e3829cb1d8146a5c6017596be2664d636c Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 19:55:24 +0200 Subject: [PATCH 15/77] - clean up meson files - radically change the structure of the whole game so that it: - can be used as dependency - is subproject agnsotic - installs headers correctly - generates correct package files - make include files all use correct headers, so that they work when installed - remove helper helper::optional, since every compiler we support supports std::optional WIP --- meson.build | 85 ---- src/{ => executables/game}/application.cpp | 4 +- src/{ => executables/game}/application.hpp | 8 +- .../game}/command_line_arguments.hpp | 6 +- src/{ => executables/game}/main.cpp | 0 src/executables/game/meson.build | 6 + src/executables/meson.build | 94 ++++ .../utility}/command_line_arguments.hpp | 0 .../utility}/main.cpp | 11 +- src/executables/utility/meson.build | 1 + src/game/meson.build | 12 - src/game/tetrion.cpp | 4 +- src/game/tetrion.hpp | 16 +- src/graphics/meson.build | 1 - src/helper/clock_source.cpp | 2 +- src/helper/clock_source.hpp | 6 +- src/helper/constants.hpp | 2 +- src/helper/graphic_utils.cpp | 4 +- src/helper/graphic_utils.hpp | 4 +- src/helper/meson.build | 32 +- src/helper/nfd.cpp | 6 +- src/helper/nfd_include.hpp | 8 +- src/helper/optional.hpp | 30 -- src/input/controller_input.cpp | 34 +- src/input/controller_input.hpp | 9 +- src/input/game_input.hpp | 4 +- src/input/input.cpp | 16 +- src/input/input.hpp | 10 +- src/input/input_creator.cpp | 4 +- src/input/input_creator.hpp | 6 +- src/input/joystick_input.cpp | 46 +- src/input/joystick_input.hpp | 15 +- src/input/keyboard_input.cpp | 15 +- src/input/keyboard_input.hpp | 6 +- src/input/mouse_input.cpp | 14 +- src/input/mouse_input.hpp | 4 +- src/input/replay_input.cpp | 7 +- src/input/replay_input.hpp | 2 +- src/input/touch_input.cpp | 32 +- src/input/touch_input.hpp | 10 +- src/libs/core/core.hpp | 32 ++ src/{ => libs/core}/game/grid_properties.hpp | 2 +- src/libs/core/game/meson.build | 12 + src/{ => libs/core}/game/mino.cpp | 2 +- src/{ => libs/core}/game/mino.hpp | 8 +- src/{ => libs/core}/game/mino_stack.cpp | 6 +- src/{ => libs/core}/game/mino_stack.hpp | 4 +- src/{ => libs/core}/game/tetromino_type.cpp | 2 +- src/{ => libs/core}/game/tetromino_type.hpp | 4 +- .../core}/hash-library/LICENSE | 0 src/libs/core/hash-library/meson.build | 7 + .../core}/hash-library/readme.md | 0 .../core}/hash-library/sha256.cpp | 2 +- .../core}/hash-library/sha256.h | 0 .../core}/hash-library/url.txt | 0 src/{ => libs/core}/helper/bool_wrapper.hpp | 9 +- src/{ => libs/core}/helper/color.cpp | 8 +- src/{ => libs/core}/helper/color.hpp | 9 +- src/{ => libs/core}/helper/color_literals.hpp | 6 +- src/{ => libs/core}/helper/const_utils.hpp | 2 +- src/{ => libs/core}/helper/date.cpp | 2 +- src/{ => libs/core}/helper/date.hpp | 4 +- src/{ => libs/core}/helper/errors.cpp | 2 +- src/{ => libs/core}/helper/errors.hpp | 0 src/{ => libs/core}/helper/expected.hpp | 0 .../core/helper}/input_event.hpp | 2 +- .../core}/helper/magic_enum_wrapper.hpp | 0 src/libs/core/helper/meson.build | 30 ++ src/{ => libs/core}/helper/parse_json.cpp | 2 +- src/{ => libs/core}/helper/parse_json.hpp | 14 +- src/{graphics => libs/core/helper}/point.hpp | 2 +- src/{ => libs/core}/helper/random.cpp | 3 +- src/{ => libs/core}/helper/random.hpp | 2 +- src/{ => libs/core}/helper/sleep.cpp | 2 +- src/{ => libs/core}/helper/sleep.hpp | 0 src/{ => libs/core}/helper/static_string.hpp | 2 +- .../core}/helper/string_manipulation.cpp | 2 +- .../core}/helper/string_manipulation.hpp | 0 src/{ => libs/core}/helper/timer.hpp | 0 src/{ => libs/core}/helper/types.hpp | 0 src/{ => libs/core}/helper/utils.hpp | 12 +- src/libs/core/meson.build | 43 ++ src/libs/meson.build | 12 + src/libs/recordings/meson.build | 50 +++ .../utility}/additional_information.cpp | 8 +- .../utility}/additional_information.hpp | 17 +- .../recordings/utility}/checksum_helper.cpp | 2 +- .../recordings/utility}/checksum_helper.hpp | 4 +- .../recordings/utility}/helper.hpp | 20 +- .../recordings/utility}/meson.build | 6 - .../recordings/utility}/recording.cpp | 3 +- .../recordings/utility}/recording.hpp | 10 +- .../utility}/recording_json_wrapper.hpp | 14 +- .../recordings/utility}/recording_reader.cpp | 7 +- .../recordings/utility}/recording_reader.hpp | 8 +- .../recordings/utility}/recording_writer.cpp | 6 +- .../recordings/utility}/recording_writer.hpp | 10 +- .../utility}/tetrion_core_information.hpp | 2 +- .../recordings/utility}/tetrion_snapshot.cpp | 11 +- .../recordings/utility}/tetrion_snapshot.hpp | 11 +- src/lobby/types.hpp | 4 +- src/manager/event_dispatcher.hpp | 4 +- src/manager/meson.build | 1 - src/manager/music_manager.cpp | 47 +- src/manager/music_manager.hpp | 18 +- src/manager/sdl_key.cpp | 8 +- src/manager/service_provider.hpp | 6 +- src/manager/settings_manager.cpp | 2 +- src/manager/settings_manager.hpp | 4 +- src/meson.build | 167 +++---- src/recordings/executable/meson.build | 3 - src/scenes/about_page/about_page.cpp | 2 +- src/scenes/main_menu/main_menu.cpp | 10 +- src/scenes/main_menu/main_menu.hpp | 2 +- .../multiplayer_menu/multiplayer_menu.cpp | 4 +- .../multiplayer_menu/multiplayer_menu.hpp | 2 +- src/scenes/online_lobby/online_lobby.cpp | 2 +- src/scenes/online_lobby/online_lobby.hpp | 2 +- .../play_select_menu/play_select_menu.cpp | 8 +- .../play_select_menu/play_select_menu.hpp | 2 +- .../recording_selector/recording_selector.cpp | 10 +- .../recording_selector/recording_selector.hpp | 2 +- src/scenes/replay_game/replay_game.cpp | 4 +- src/scenes/replay_game/replay_game.hpp | 2 +- src/scenes/scene.hpp | 2 +- .../settings_menu/color_setting_row.cpp | 2 +- src/scenes/settings_menu/settings_menu.cpp | 17 +- src/scenes/settings_menu/settings_menu.hpp | 6 +- src/scenes/single_player_game/game_over.cpp | 2 +- src/scenes/single_player_game/pause.cpp | 2 +- .../single_player_game/single_player_game.cpp | 4 +- .../single_player_game/single_player_game.hpp | 2 +- src/thirdparty/hash-library/meson.build | 10 - src/thirdparty/meson.build | 4 - src/ui/layouts/focus_layout.cpp | 22 +- src/ui/layouts/focus_layout.hpp | 6 +- src/ui/layouts/scroll_layout.cpp | 6 +- src/ui/layouts/scroll_layout.hpp | 4 +- src/ui/widget.cpp | 4 +- src/ui/widget.hpp | 6 +- tests/utils/printer.hpp | 4 +- tools/dependencies/meson.build | 415 +++++++++--------- tools/install/meson.build | 21 - tools/options/meson.build | 28 +- 144 files changed, 968 insertions(+), 931 deletions(-) rename src/{ => executables/game}/application.cpp (98%) rename src/{ => executables/game}/application.hpp (92%) rename src/{helper => executables/game}/command_line_arguments.hpp (95%) rename src/{ => executables/game}/main.cpp (100%) create mode 100644 src/executables/game/meson.build create mode 100644 src/executables/meson.build rename src/{recordings/executable => executables/utility}/command_line_arguments.hpp (100%) rename src/{recordings/executable => executables/utility}/main.cpp (89%) create mode 100644 src/executables/utility/meson.build delete mode 100644 src/helper/optional.hpp create mode 100644 src/libs/core/core.hpp rename src/{ => libs/core}/game/grid_properties.hpp (96%) create mode 100644 src/libs/core/game/meson.build rename src/{ => libs/core}/game/mino.cpp (95%) rename src/{ => libs/core}/game/mino.hpp (83%) rename src/{ => libs/core}/game/mino_stack.cpp (96%) rename src/{ => libs/core}/game/mino_stack.hpp (92%) rename src/{ => libs/core}/game/tetromino_type.cpp (97%) rename src/{ => libs/core}/game/tetromino_type.hpp (85%) rename src/{thirdparty => libs/core}/hash-library/LICENSE (100%) create mode 100644 src/libs/core/hash-library/meson.build rename src/{thirdparty => libs/core}/hash-library/readme.md (100%) rename src/{thirdparty => libs/core}/hash-library/sha256.cpp (99%) rename src/{thirdparty => libs/core}/hash-library/sha256.h (100%) rename src/{thirdparty => libs/core}/hash-library/url.txt (100%) rename src/{ => libs/core}/helper/bool_wrapper.hpp (70%) rename src/{ => libs/core}/helper/color.cpp (97%) rename src/{ => libs/core}/helper/color.hpp (98%) rename src/{ => libs/core}/helper/color_literals.hpp (99%) rename src/{ => libs/core}/helper/const_utils.hpp (99%) rename src/{ => libs/core}/helper/date.cpp (99%) rename src/{ => libs/core}/helper/date.hpp (92%) rename src/{ => libs/core}/helper/errors.cpp (98%) rename src/{ => libs/core}/helper/errors.hpp (100%) rename src/{ => libs/core}/helper/expected.hpp (100%) rename src/{manager => libs/core/helper}/input_event.hpp (92%) rename src/{ => libs/core}/helper/magic_enum_wrapper.hpp (100%) create mode 100644 src/libs/core/helper/meson.build rename src/{ => libs/core}/helper/parse_json.cpp (98%) rename src/{ => libs/core}/helper/parse_json.hpp (91%) rename src/{graphics => libs/core/helper}/point.hpp (99%) rename src/{ => libs/core}/helper/random.cpp (93%) rename src/{ => libs/core}/helper/random.hpp (96%) rename src/{ => libs/core}/helper/sleep.cpp (98%) rename src/{ => libs/core}/helper/sleep.hpp (100%) rename src/{ => libs/core}/helper/static_string.hpp (99%) rename src/{ => libs/core}/helper/string_manipulation.cpp (97%) rename src/{ => libs/core}/helper/string_manipulation.hpp (100%) rename src/{ => libs/core}/helper/timer.hpp (100%) rename src/{ => libs/core}/helper/types.hpp (100%) rename src/{ => libs/core}/helper/utils.hpp (93%) create mode 100644 src/libs/core/meson.build create mode 100644 src/libs/meson.build create mode 100644 src/libs/recordings/meson.build rename src/{recordings => libs/recordings/utility}/additional_information.cpp (99%) rename src/{recordings => libs/recordings/utility}/additional_information.hpp (94%) rename src/{recordings => libs/recordings/utility}/checksum_helper.cpp (93%) rename src/{recordings => libs/recordings/utility}/checksum_helper.hpp (94%) rename src/{recordings => libs/recordings/utility}/helper.hpp (91%) rename src/{recordings => libs/recordings/utility}/meson.build (76%) rename src/{recordings => libs/recordings/utility}/recording.cpp (98%) rename src/{recordings => libs/recordings/utility}/recording.hpp (90%) rename src/{recordings => libs/recordings/utility}/recording_json_wrapper.hpp (96%) rename src/{recordings => libs/recordings/utility}/recording_reader.cpp (98%) rename src/{recordings => libs/recordings/utility}/recording_reader.hpp (94%) rename src/{recordings => libs/recordings/utility}/recording_writer.cpp (98%) rename src/{recordings => libs/recordings/utility}/recording_writer.hpp (91%) rename src/{recordings => libs/recordings/utility}/tetrion_core_information.hpp (93%) rename src/{recordings => libs/recordings/utility}/tetrion_snapshot.cpp (97%) rename src/{recordings => libs/recordings/utility}/tetrion_snapshot.hpp (89%) delete mode 100644 src/recordings/executable/meson.build delete mode 100644 src/thirdparty/hash-library/meson.build delete mode 100644 src/thirdparty/meson.build diff --git a/meson.build b/meson.build index 5d93863e..92a48ed4 100644 --- a/meson.build +++ b/meson.build @@ -14,9 +14,6 @@ project( version: '0.5.6', ) -oopetris_author = 'Coder2k' -oopetris_name = 'OOPetris' - subdir('tools/options') subdir('tools/dependencies') @@ -25,88 +22,6 @@ subdir('src') subdir('tools/install') -if meson.is_cross_build() and host_machine.system() == 'android' - - library( - 'oopetris', - main_files, - dependencies: [liboopetris_graphics_dep, graphic_application_deps], - override_options: { - 'warning_level': '3', - 'werror': true, - }, - ) - -elif meson.is_cross_build() and host_machine.system() == 'switch' - switch_options = [ - app_name, - main_files, - [liboopetris_graphics_dep, graphic_application_deps], - ] - subdir('platforms/switch') -elif meson.is_cross_build() and host_machine.system() == '3ds' - _3ds_options = [ - app_name, - main_files, - [liboopetris_graphics_dep, graphic_application_deps], - ] - subdir('platforms/3ds') -else - - if host_machine.system() == 'windows' - subdir('platforms/windows') - endif - - oopetris_exe = executable( - 'oopetris', - main_files, - dependencies: [liboopetris_graphics_dep, graphic_application_deps], - override_options: { - 'warning_level': '3', - 'werror': true, - }, - install: true, - win_subsystem: 'windows', - ) - - oopetris_recordings_utility_exe = executable( - 'oopetris_recordings_utility', - recordings_main_files, - dependencies: liboopetris_recordings_dep, - override_options: { - 'warning_level': '3', - 'werror': true, - }, - install: true, - win_subsystem: 'console', - ) - - if build_installer - if host_machine.system() == 'windows' - - makensis = find_program('makensis') - - nsis_script = meson.project_source_root() / 'tools' / 'installer' / 'setup.nsi' - - run_target( - 'windows_installer', - command: [ - makensis, - '-DVERSION=' + meson.project_version(), - '-DNAME=' + oopetris_name, - '-DAUTHOR=' + oopetris_author, - '-DPROJECT_SOURCE_DIR=' + meson.project_source_root(), - '-DPROJECT_BUILD_DIR=' + meson.project_build_root(), - nsis_script, - ], - depends: [oopetris_exe, oopetris_recordings_utility_exe], - ) - - endif - endif - -endif - if get_option('tests') subdir('tests') endif diff --git a/src/application.cpp b/src/executables/game/application.cpp similarity index 98% rename from src/application.cpp rename to src/executables/game/application.cpp index f6f20c0e..27b999b0 100644 --- a/src/application.cpp +++ b/src/executables/game/application.cpp @@ -389,11 +389,11 @@ void Application::load_resources() { #if defined(_HAVE_DISCORD_SDK) -[[nodiscard]] helper::optional& Application::discord_instance() { +[[nodiscard]] std::optional& Application::discord_instance() { return m_discord_instance; } -[[nodiscard]] const helper::optional& Application::discord_instance() const { +[[nodiscard]] const std::optional& Application::discord_instance() const { return m_discord_instance; } diff --git a/src/application.hpp b/src/executables/game/application.hpp similarity index 92% rename from src/application.hpp rename to src/executables/game/application.hpp index 676e910c..7ff10608 100644 --- a/src/application.hpp +++ b/src/executables/game/application.hpp @@ -25,7 +25,7 @@ struct Application final : public EventListener, public ServiceProvider { CommandLineArguments m_command_line_arguments; std::shared_ptr m_window; Renderer m_renderer; - helper::optional m_target_framerate; + std::optional m_target_framerate; // these fields are initalized asynchronously in a separate thread std::unique_ptr m_music_manager; @@ -39,7 +39,7 @@ struct Application final : public EventListener, public ServiceProvider { #endif #if defined(_HAVE_DISCORD_SDK) - helper::optional m_discord_instance{ helper::nullopt }; + std::optional m_discord_instance{ std::nullopt }; #endif protected: @@ -130,8 +130,8 @@ struct Application final : public EventListener, public ServiceProvider { #if defined(_HAVE_DISCORD_SDK) - [[nodiscard]] helper::optional& discord_instance() override; - [[nodiscard]] const helper::optional& discord_instance() const override; + [[nodiscard]] std::optional& discord_instance() override; + [[nodiscard]] const std::optional& discord_instance() const override; #endif diff --git a/src/helper/command_line_arguments.hpp b/src/executables/game/command_line_arguments.hpp similarity index 95% rename from src/helper/command_line_arguments.hpp rename to src/executables/game/command_line_arguments.hpp index 2f372650..7db18593 100644 --- a/src/helper/command_line_arguments.hpp +++ b/src/executables/game/command_line_arguments.hpp @@ -2,7 +2,7 @@ #include "helper/constants.hpp" #include "helper/graphic_utils.hpp" -#include "helper/optional.hpp" + #include "helper/types.hpp" #include "helper/utils.hpp" @@ -18,8 +18,8 @@ struct CommandLineArguments final { static inline constexpr auto default_starting_level = u32{ 0 }; public: - helper::optional recording_path{}; - helper::optional target_fps{}; + std::optional recording_path{}; + std::optional target_fps{}; std::remove_cvref_t starting_level{ default_starting_level }; bool silent{ false }; diff --git a/src/main.cpp b/src/executables/game/main.cpp similarity index 100% rename from src/main.cpp rename to src/executables/game/main.cpp diff --git a/src/executables/game/meson.build b/src/executables/game/meson.build new file mode 100644 index 00000000..29903893 --- /dev/null +++ b/src/executables/game/meson.build @@ -0,0 +1,6 @@ +main_files += files( + 'application.cpp', + 'application.hpp', + 'command_line_arguments.hpp' + 'main.cpp',, +) diff --git a/src/executables/meson.build b/src/executables/meson.build new file mode 100644 index 00000000..796c664c --- /dev/null +++ b/src/executables/meson.build @@ -0,0 +1,94 @@ +if build_application + + main_filers = [] + + subdir('game') + + if meson.is_cross_build() and host_machine.system() == 'android' + + library( + 'oopetris', + main_files, + dependencies: [liboopetris_graphics_dep, graphic_application_deps], + override_options: { + 'warning_level': '3', + 'werror': true, + }, + ) + + elif meson.is_cross_build() and host_machine.system() == 'switch' + switch_options = [ + app_name, + main_files, + [liboopetris_graphics_dep, graphic_application_deps], + ] + subdir('../../platforms/switch') + elif meson.is_cross_build() and host_machine.system() == '3ds' + _3ds_options = [ + app_name, + main_files, + [liboopetris_graphics_dep, graphic_application_deps], + ] + subdir('../../platforms/3ds') + else + + if host_machine.system() == 'windows' + subdir('../../platforms/windows') + endif + + oopetris_exe = executable( + 'oopetris', + main_files, + dependencies: [liboopetris_graphics_dep, graphic_application_deps], + override_options: { + 'warning_level': '3', + 'werror': true, + }, + install: true, + win_subsystem: 'windows', + ) + + recordings_main_files = [] + + subdir('utility') + + oopetris_recordings_utility_exe = executable( + 'oopetris_recordings_utility', + recordings_main_files, + dependencies: [liboopetris_recordings_dep, recordings_application_deps], + override_options: { + 'warning_level': '3', + 'werror': true, + }, + install: true, + win_subsystem: 'console', + ) + + if build_installer + if host_machine.system() == 'windows' + + makensis = find_program('makensis') + + nsis_script = meson.project_source_root() / 'tools' / 'installer' / 'setup.nsi' + + run_target( + 'windows_installer', + command: [ + makensis, + '-DVERSION=' + meson.project_version(), + '-DNAME=' + oopetris_name, + '-DAUTHOR=' + oopetris_author, + '-DPROJECT_SOURCE_DIR=' + + meson.project_source_root(), + '-DPROJECT_BUILD_DIR=' + meson.project_build_root(), + nsis_script, + ], + depends: [oopetris_exe, oopetris_recordings_utility_exe], + ) + + endif + endif + + endif + +endif diff --git a/src/recordings/executable/command_line_arguments.hpp b/src/executables/utility/command_line_arguments.hpp similarity index 100% rename from src/recordings/executable/command_line_arguments.hpp rename to src/executables/utility/command_line_arguments.hpp diff --git a/src/recordings/executable/main.cpp b/src/executables/utility/main.cpp similarity index 89% rename from src/recordings/executable/main.cpp rename to src/executables/utility/main.cpp index f5c44d18..f446e488 100644 --- a/src/recordings/executable/main.cpp +++ b/src/executables/utility/main.cpp @@ -1,7 +1,8 @@ #include "command_line_arguments.hpp" -#include "recording_json_wrapper.hpp" -#include "recording_reader.hpp" + +#include +#include #include #include @@ -12,10 +13,12 @@ void print_info(const recorder::RecordingReader& recording_reader) noexcept { std::cerr << "NOT IMPLEMENTED\n"; } -void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_print, bool ensure_ascii) { +void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_print, bool ensure_ascii) noexcept { nlohmann::json json_value; + //TODO: use parse_json helper + nlohmann::adl_serializer::to_json(json_value, recording_reader); int indent = -1; @@ -34,7 +37,7 @@ void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_pr } -int main(int argc, char** argv) { +int main(int argc, char** argv) noexcept { const auto arguments = CommandLineArguments(argc, argv); diff --git a/src/executables/utility/meson.build b/src/executables/utility/meson.build new file mode 100644 index 00000000..b78a3d8e --- /dev/null +++ b/src/executables/utility/meson.build @@ -0,0 +1 @@ +recordings_main_files += files('command_line_arguments.hpp' 'main.cpp',) diff --git a/src/game/meson.build b/src/game/meson.build index 5e360af8..cc33d589 100644 --- a/src/game/meson.build +++ b/src/game/meson.build @@ -1,10 +1,3 @@ -core_src_files += files( - 'mino.cpp', - 'mino.hpp', - 'mino_stack.cpp', - 'mino_stack.hpp', -) - graphics_src_files += files( 'bag.cpp', 'bag.hpp', @@ -14,15 +7,10 @@ graphics_src_files += files( 'graphic_helpers.hpp', 'grid.cpp', 'grid.hpp', - 'grid_properties.hpp', 'rotation.cpp', 'rotation.hpp', 'tetrion.cpp', 'tetrion.hpp', 'tetromino.cpp', 'tetromino.hpp', - 'tetromino_type.cpp', - 'tetromino_type.hpp', ) - - diff --git a/src/game/tetrion.cpp b/src/game/tetrion.cpp index abff894e..eb660217 100644 --- a/src/game/tetrion.cpp +++ b/src/game/tetrion.cpp @@ -20,7 +20,7 @@ Tetrion::Tetrion( const Random::Seed random_seed, const u32 starting_level, ServiceProvider* const service_provider, - helper::optional> recording_writer, + std::optional> recording_writer, const ui::Layout& layout, bool is_top_level ) @@ -631,7 +631,7 @@ bool Tetrion::move(const Tetrion::MoveDirection move_direction) { UNREACHABLE(); } -helper::optional Tetrion::get_wall_kick_table() const { +std::optional Tetrion::get_wall_kick_table() const { assert(m_active_tetromino.has_value() and "no active tetromino"); const auto type = m_active_tetromino->type(); // NOLINT(bugprone-unchecked-optional-access) switch (type) { diff --git a/src/game/tetrion.hpp b/src/game/tetrion.hpp index 83f8a3ae..ed218d34 100644 --- a/src/game/tetrion.hpp +++ b/src/game/tetrion.hpp @@ -2,7 +2,7 @@ #include "bag.hpp" #include "grid.hpp" -#include "helper/optional.hpp" + #include "helper/random.hpp" #include "helper/types.hpp" #include "input/game_input.hpp" @@ -61,7 +61,7 @@ struct Tetrion final : public ui::Widget { u32 m_num_executed_lock_delays = 0; u64 m_lock_delay_step_index; ServiceProvider* const m_service_provider; - helper::optional> m_recording_writer; + std::optional> m_recording_writer; MinoStack m_mino_stack; Random m_random; u32 m_level; @@ -70,10 +70,10 @@ struct Tetrion final : public ui::Widget { int m_sequence_index = 0; u64 m_score = 0; std::array m_sequence_bags{ Bag{ m_random }, Bag{ m_random } }; - helper::optional m_active_tetromino; - helper::optional m_ghost_tetromino; - helper::optional m_tetromino_on_hold; - std::array, num_preview_tetrominos> m_preview_tetrominos{}; + std::optional m_active_tetromino; + std::optional m_ghost_tetromino; + std::optional m_tetromino_on_hold; + std::array, num_preview_tetrominos> m_preview_tetrominos{}; u8 m_tetrion_index; u64 m_next_gravity_simulation_step_index; ui::TileLayout m_main_layout; @@ -84,7 +84,7 @@ struct Tetrion final : public ui::Widget { Random::Seed random_seed, u32 starting_level, ServiceProvider* service_provider, - helper::optional> recording_writer, + std::optional> recording_writer, const ui::Layout& layout, bool is_top_level); void update_step(SimulationStep simulation_step_index); @@ -130,7 +130,7 @@ struct Tetrion final : public ui::Widget { bool rotate(RotationDirection rotation_direction); bool move(MoveDirection move_direction); - [[nodiscard]] helper::optional get_wall_kick_table() const; + [[nodiscard]] std::optional get_wall_kick_table() const; void reset_lock_delay(SimulationStep simulation_step_index); void refresh_texts(); void clear_fully_occupied_lines(); diff --git a/src/graphics/meson.build b/src/graphics/meson.build index fb095fdc..098f6680 100644 --- a/src/graphics/meson.build +++ b/src/graphics/meson.build @@ -1,5 +1,4 @@ graphics_src_files += files( - 'point.hpp', 'rect.hpp', 'renderer.cpp', 'renderer.hpp', diff --git a/src/helper/clock_source.cpp b/src/helper/clock_source.cpp index f003e28c..385d8247 100644 --- a/src/helper/clock_source.cpp +++ b/src/helper/clock_source.cpp @@ -41,7 +41,7 @@ double LocalClock::resume() { } const auto duration = elapsed_time() - *m_paused_at; m_start_time += duration; - m_paused_at = helper::nullopt; + m_paused_at = std::nullopt; spdlog::info("resuming clock (duration of pause: {} s)", duration); return duration; } diff --git a/src/helper/clock_source.hpp b/src/helper/clock_source.hpp index 5818f3e6..2cd0e80a 100644 --- a/src/helper/clock_source.hpp +++ b/src/helper/clock_source.hpp @@ -1,7 +1,7 @@ #pragma once -#include "helper/optional.hpp" -#include "helper/types.hpp" + +#include #include @@ -28,7 +28,7 @@ struct LocalClock : public ClockSource { private: double m_start_time; double m_step_duration; - helper::optional m_paused_at{}; + std::optional m_paused_at{}; public: explicit LocalClock(u32 target_frequency); diff --git a/src/helper/constants.hpp b/src/helper/constants.hpp index 1c497b52..767e3d2d 100644 --- a/src/helper/constants.hpp +++ b/src/helper/constants.hpp @@ -1,6 +1,6 @@ #pragma once -#include "helper/static_string.hpp" +#include "./helper/static_string.hpp" namespace constants { diff --git a/src/helper/graphic_utils.cpp b/src/helper/graphic_utils.cpp index 75f2191a..1167eaf5 100644 --- a/src/helper/graphic_utils.cpp +++ b/src/helper/graphic_utils.cpp @@ -90,7 +90,7 @@ std::vector utils::supported_features() { #endif } -helper::optional utils::log_error(const std::string& error) { +std::optional utils::log_error(const std::string& error) { spdlog::error(error); - return helper::nullopt; + return std::nullopt; } diff --git a/src/helper/graphic_utils.hpp b/src/helper/graphic_utils.hpp index 3977bd61..2f0a6455 100644 --- a/src/helper/graphic_utils.hpp +++ b/src/helper/graphic_utils.hpp @@ -3,7 +3,7 @@ #include "color.hpp" #include "helper/constants.hpp" -#include "helper/optional.hpp" + #include #include @@ -18,5 +18,5 @@ namespace utils { [[nodiscard]] std::filesystem::path get_root_folder(); - helper::optional log_error(const std::string& error); + std::optional log_error(const std::string& error); } // namespace utils diff --git a/src/helper/meson.build b/src/helper/meson.build index a8956e18..7d037666 100644 --- a/src/helper/meson.build +++ b/src/helper/meson.build @@ -1,33 +1,3 @@ -core_src_files += files( - 'bool_wrapper.hpp', - 'color.cpp', - 'color.hpp', - 'color_literals.hpp', - 'command_line_arguments.hpp', - 'const_utils.hpp', - 'constants.hpp', - 'date.cpp', - 'date.hpp', - 'errors.cpp', - 'errors.hpp', - 'expected.hpp', - 'git_helper.hpp', - 'magic_enum_wrapper.hpp', - 'optional.hpp', - 'parse_json.cpp', - 'parse_json.hpp', - 'random.cpp', - 'random.hpp', - 'sleep.cpp', - 'sleep.hpp', - 'static_string.hpp', - 'string_manipulation.cpp', - 'string_manipulation.hpp', - 'timer.hpp', - 'types.hpp', - 'utils.hpp', -) - graphics_src_files += files( 'clock_source.cpp', 'clock_source.hpp', @@ -39,7 +9,9 @@ graphics_src_files += files( 'message_box.hpp', 'music_utils.hpp', 'platform.cpp', + 'git_helper.hpp', 'platform.hpp', + 'constants.hpp' ) if have_file_dialogs diff --git a/src/helper/nfd.cpp b/src/helper/nfd.cpp index a840f498..541a436d 100644 --- a/src/helper/nfd.cpp +++ b/src/helper/nfd.cpp @@ -69,7 +69,7 @@ namespace { helper::expected helper::openFileDialog( const std::vector& allowed_files, - helper::optional default_path + std::optional default_path ) { NFD::UniquePathU8 out_path{}; @@ -109,7 +109,7 @@ helper::expected helper::openFileDialog( [[nodiscard]] helper::expected, std::string> helper::openMultipleFilesDialog( const std::vector& allowed_files, - helper::optional default_path + std::optional default_path ) { NFD::UniquePathSet out_paths{}; @@ -160,7 +160,7 @@ helper::expected helper::openFileDialog( } [[nodiscard]] helper::expected helper::openFolderDialog( - helper::optional default_path + std::optional default_path ) { NFD::UniquePathU8 out_path{}; diff --git a/src/helper/nfd_include.hpp b/src/helper/nfd_include.hpp index 0bb65f61..ad7cd61d 100644 --- a/src/helper/nfd_include.hpp +++ b/src/helper/nfd_include.hpp @@ -4,7 +4,7 @@ #if defined(_HAVE_FILE_DIALOGS) #include "helper/expected.hpp" -#include "helper/optional.hpp" + #define NFD_THROWS_EXCEPTIONS #ifdef _WIN32 @@ -29,16 +29,16 @@ namespace helper { //NOTE: this API is blocking and can't be asynchronous, due to os (linux, windows, macos) restrictions, it HAS to be launched in the same thread NFD_Init() was launched /the main thread) [[nodiscard]] helper::expected openFileDialog( const std::vector& allowed_files = {}, - helper::optional default_path = helper::nullopt + std::optional default_path = std::nullopt ); [[nodiscard]] helper::expected, std::string> openMultipleFilesDialog( const std::vector& allowed_files = {}, - helper::optional default_path = helper::nullopt + std::optional default_path = std::nullopt ); [[nodiscard]] helper::expected openFolderDialog( - helper::optional default_path = helper::nullopt + std::optional default_path = std::nullopt ); } // namespace helper diff --git a/src/helper/optional.hpp b/src/helper/optional.hpp deleted file mode 100644 index bf44d7cb..00000000 --- a/src/helper/optional.hpp +++ /dev/null @@ -1,30 +0,0 @@ - -#pragma once - -#ifdef __USE_TL_OPTIONAL -#include -#else -#include -#endif - - -namespace helper { - -#ifdef __USE_TL_OPTIONAL - - template - using optional = tl::optional; - - constexpr auto nullopt = tl::nullopt; - -#else - - template - using optional = std::optional; - - constexpr auto nullopt = std::nullopt; - -#endif - - -} // namespace helper diff --git a/src/input/controller_input.cpp b/src/input/controller_input.cpp index abd1fa45..4f8a8703 100644 --- a/src/input/controller_input.cpp +++ b/src/input/controller_input.cpp @@ -77,13 +77,12 @@ input::ControllerInput::get_by_device_index(int device_index) { } -[[nodiscard]] helper::optional input::ControllerInput::get_navigation_event( - const SDL_Event& event +[[nodiscard]] std::optional input::ControllerInput::get_navigation_event(const SDL_Event& event ) const { if (event.type == SDL_CONTROLLERBUTTONDOWN) { if (event.cbutton.which != instance_id()) { - return helper::nullopt; + return std::nullopt; } switch (event.cbutton.button) { @@ -100,7 +99,7 @@ input::ControllerInput::get_by_device_index(int device_index) { case SDL_CONTROLLER_BUTTON_BACK: return NavigationEvent::BACK; default: - return helper::nullopt; + return std::nullopt; //note, that NavigationEvent::TAB is not supported } @@ -131,7 +130,7 @@ input::ControllerInput::get_by_device_index(int device_index) { } -[[nodiscard]] helper::optional input::ControllerInput::handle_axis_navigation_event( +[[nodiscard]] std::optional input::ControllerInput::handle_axis_navigation_event( const SDL_Event& event ) const { if (event.type == SDL_CONTROLLERAXISMOTION) { @@ -144,7 +143,7 @@ input::ControllerInput::get_by_device_index(int device_index) { static_cast(static_cast(SDL_JOYSTICK_AXIS_MAX) * axis_threshold_percentage); if (event.caxis.which != instance_id()) { - return helper::nullopt; + return std::nullopt; } // x axis movement @@ -157,7 +156,7 @@ input::ControllerInput::get_by_device_index(int device_index) { return NavigationEvent::LEFT; } - return helper::nullopt; + return std::nullopt; } // y axis movement @@ -170,15 +169,15 @@ input::ControllerInput::get_by_device_index(int device_index) { return NavigationEvent::UP; } - return helper::nullopt; + return std::nullopt; } //Note: not all types of SDL_GameControllerAxis are handled, since they are not needed for navigation events - return helper::nullopt; + return std::nullopt; } - return helper::nullopt; + return std::nullopt; } @@ -205,12 +204,11 @@ input::ControllerGameInput::ControllerGameInput( } -[[nodiscard]] helper::optional input::ControllerGameInput::get_menu_event(const SDL_Event& event -) const { +[[nodiscard]] std::optional input::ControllerGameInput::get_menu_event(const SDL_Event& event) const { if (event.type == SDL_CONTROLLERBUTTONDOWN) { if (event.cbutton.which != underlying_input()->instance_id()) { - return helper::nullopt; + return std::nullopt; } const auto button = sdl::ControllerKey{ static_cast(event.cbutton.button) }; @@ -223,7 +221,7 @@ input::ControllerGameInput::ControllerGameInput( } } - return helper::nullopt; + return std::nullopt; // } @@ -240,12 +238,12 @@ input::ControllerGameInput::ControllerGameInput( } -[[nodiscard]] helper::optional input::ControllerGameInput::sdl_event_to_input_event(const SDL_Event& event +[[nodiscard]] std::optional input::ControllerGameInput::sdl_event_to_input_event(const SDL_Event& event ) const { if (event.type == SDL_CONTROLLERBUTTONDOWN) { if (event.cbutton.which != underlying_input()->instance_id()) { - return helper::nullopt; + return std::nullopt; } //TODO(Totto): use switch case @@ -275,7 +273,7 @@ input::ControllerGameInput::ControllerGameInput( } else if (event.type == SDL_CONTROLLERBUTTONUP) { if (event.cbutton.which != underlying_input()->instance_id()) { - return helper::nullopt; + return std::nullopt; } const auto button = sdl::ControllerKey{ static_cast(event.cbutton.button) }; @@ -302,7 +300,7 @@ input::ControllerGameInput::ControllerGameInput( return InputEvent::HoldReleased; } } - return helper::nullopt; + return std::nullopt; } diff --git a/src/input/controller_input.hpp b/src/input/controller_input.hpp index 8561cdbb..873945b7 100644 --- a/src/input/controller_input.hpp +++ b/src/input/controller_input.hpp @@ -27,13 +27,12 @@ namespace input { int device_index ); - [[nodiscard]] helper::optional get_navigation_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional get_navigation_event(const SDL_Event& event) const override; [[nodiscard]] std::string describe_navigation_event(NavigationEvent event) const override; private: - [[nodiscard]] helper::optional handle_axis_navigation_event(const SDL_Event& event - ) const; + [[nodiscard]] std::optional handle_axis_navigation_event(const SDL_Event& event) const; }; struct ControllerSettings { @@ -79,14 +78,14 @@ namespace input { ControllerInput* underlying_input ); - [[nodiscard]] helper::optional get_menu_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional get_menu_event(const SDL_Event& event) const override; [[nodiscard]] std::string describe_menu_event(MenuEvent event) const override; [[nodiscard]] const ControllerInput* underlying_input() const override; protected: - [[nodiscard]] helper::optional sdl_event_to_input_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional sdl_event_to_input_event(const SDL_Event& event) const override; }; diff --git a/src/input/game_input.hpp b/src/input/game_input.hpp index add8cc76..e473f285 100644 --- a/src/input/game_input.hpp +++ b/src/input/game_input.hpp @@ -1,7 +1,7 @@ #pragma once #include "helper/clock_source.hpp" -#include "helper/optional.hpp" + #include "helper/random.hpp" #include "helper/types.hpp" #include "manager/event_listener.hpp" @@ -77,7 +77,7 @@ namespace input { virtual void update(SimulationStep simulation_step_index); virtual void late_update(SimulationStep /*simulation_step*/){}; - [[nodiscard]] virtual helper::optional get_menu_event(const SDL_Event& event) const = 0; + [[nodiscard]] virtual std::optional get_menu_event(const SDL_Event& event) const = 0; [[nodiscard]] virtual std::string describe_menu_event(MenuEvent event) const = 0; diff --git a/src/input/input.cpp b/src/input/input.cpp index f6f4bab3..d53ff3db 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -1,6 +1,6 @@ #include "input.hpp" #include "helper/expected.hpp" -#include "helper/optional.hpp" + #include "helper/utils.hpp" #include "input/controller_input.hpp" #include "joystick_input.hpp" @@ -96,7 +96,7 @@ input::InputManager::InputManager(const std::shared_ptr& window) { } -[[nodiscard]] helper::optional input::InputManager::get_navigation_event(const SDL_Event& event +[[nodiscard]] std::optional input::InputManager::get_navigation_event(const SDL_Event& event ) const { for (const auto& input : m_inputs) { @@ -105,10 +105,10 @@ input::InputManager::InputManager(const std::shared_ptr& window) { } } - return helper::nullopt; + return std::nullopt; } -[[nodiscard]] helper::optional input::InputManager::get_pointer_event(const SDL_Event& event +[[nodiscard]] std::optional input::InputManager::get_pointer_event(const SDL_Event& event ) const { for (const auto& input : m_inputs) { if (const auto pointer_input = utils::is_child_class(input); pointer_input.has_value()) { @@ -118,7 +118,7 @@ input::InputManager::InputManager(const std::shared_ptr& window) { } } - return helper::nullopt; + return std::nullopt; } @@ -284,7 +284,7 @@ namespace { } - helper::optional> + std::optional> get_game_input_by_input(ServiceProvider* service_provider, const std::unique_ptr& input) { const auto& settings = service_provider->settings_manager().settings(); @@ -311,7 +311,7 @@ namespace { if (not game_input.has_value()) { spdlog::warn("Not possible to get joystick by settings: {}", game_input.error()); - return helper::nullopt; + return std::nullopt; } @@ -340,7 +340,7 @@ namespace { } - return helper::nullopt; + return std::nullopt; } diff --git a/src/input/input.hpp b/src/input/input.hpp index 3d52f3af..fa5506ce 100644 --- a/src/input/input.hpp +++ b/src/input/input.hpp @@ -9,7 +9,7 @@ #include "graphics/window.hpp" #include "helper/bool_wrapper.hpp" #include "helper/expected.hpp" -#include "helper/optional.hpp" + #include "manager/service_provider.hpp" @@ -45,7 +45,7 @@ namespace input { [[nodiscard]] const std::string& name() const; [[nodiscard]] InputType type() const; - [[nodiscard]] virtual helper::optional get_navigation_event(const SDL_Event& event) const = 0; + [[nodiscard]] virtual std::optional get_navigation_event(const SDL_Event& event) const = 0; [[nodiscard]] virtual std::string describe_navigation_event(NavigationEvent event) const = 0; }; @@ -75,7 +75,7 @@ namespace input { struct PointerInput : Input { explicit PointerInput(const std::string& name); - [[nodiscard]] virtual helper::optional get_pointer_event(const SDL_Event& event) const = 0; + [[nodiscard]] virtual std::optional get_pointer_event(const SDL_Event& event) const = 0; [[nodiscard]] virtual SDL_Event offset_pointer_event(const SDL_Event& event, const shapes::IPoint& point) const = 0; @@ -90,9 +90,9 @@ namespace input { [[nodiscard]] const std::vector>& inputs() const; - [[nodiscard]] helper::optional get_navigation_event(const SDL_Event& event) const; + [[nodiscard]] std::optional get_navigation_event(const SDL_Event& event) const; - [[nodiscard]] helper::optional get_pointer_event(const SDL_Event& event) const; + [[nodiscard]] std::optional get_pointer_event(const SDL_Event& event) const; /** * @brief Offsets a pointer event, only safe to call, if get_pointer_event returns a non null optional diff --git a/src/input/input_creator.cpp b/src/input/input_creator.cpp index 5a1a360b..61943370 100644 --- a/src/input/input_creator.cpp +++ b/src/input/input_creator.cpp @@ -6,7 +6,7 @@ #include "helper/date.hpp" #include "helper/errors.hpp" #include "helper/expected.hpp" -#include "helper/optional.hpp" + #include "input.hpp" #include "input/replay_input.hpp" @@ -84,7 +84,7 @@ input::get_game_parameters_for_replay( const auto starting_level = header.starting_level; const tetrion::StartingParameters starting_parameters = { target_fps, seed, starting_level, tetrion_index, - helper::nullopt }; + std::nullopt }; result.emplace_back(std::move(input), starting_parameters); } diff --git a/src/input/input_creator.hpp b/src/input/input_creator.hpp index d73f87a0..5d544d8a 100644 --- a/src/input/input_creator.hpp +++ b/src/input/input_creator.hpp @@ -2,7 +2,7 @@ #pragma once #include "helper/date.hpp" -#include "helper/optional.hpp" + #include "input/game_input.hpp" #include "manager/service_provider.hpp" #include "recordings/recording_writer.hpp" @@ -15,14 +15,14 @@ namespace tetrion { Random::Seed seed; u32 starting_level; u8 tetrion_index; - helper::optional> recording_writer; + std::optional> recording_writer; StartingParameters( u32 target_fps, Random::Seed seed, u32 starting_level, // NOLINT(bugprone-easily-swappable-parameters) u8 tetrion_index, - helper::optional> recording_writer = helper::nullopt + std::optional> recording_writer = std::nullopt ) : target_fps{ target_fps }, seed{ seed }, diff --git a/src/input/joystick_input.cpp b/src/input/joystick_input.cpp index dac72192..0119c3f7 100644 --- a/src/input/joystick_input.cpp +++ b/src/input/joystick_input.cpp @@ -4,7 +4,7 @@ #include "controller_input.hpp" #include "helper/expected.hpp" #include "helper/graphic_utils.hpp" -#include "helper/optional.hpp" + #include "helper/utils.hpp" #include "input/game_input.hpp" #include "input/input.hpp" @@ -42,7 +42,7 @@ input::JoystickInput& input::JoystickInput::operator=(const JoystickInput& input input::JoystickInput::JoystickInput(JoystickInput&& input) noexcept = default; input::JoystickInput& input::JoystickInput::operator=(JoystickInput&& input) noexcept = default; -[[nodiscard]] helper::optional> input::JoystickInput::get_joystick_by_guid( +[[nodiscard]] std::optional> input::JoystickInput::get_joystick_by_guid( const sdl::GUID& guid, SDL_Joystick* joystick, SDL_JoystickID instance_id, @@ -67,7 +67,7 @@ input::JoystickInput& input::JoystickInput::operator=(JoystickInput&& input) noe UNUSED(instance_id); UNUSED(name); - return helper::nullopt; + return std::nullopt; } @@ -339,13 +339,13 @@ input::SwitchJoystickInput_Type1::SwitchJoystickInput_Type1( } { } -[[nodiscard]] helper::optional input::SwitchJoystickInput_Type1::get_navigation_event( +[[nodiscard]] std::optional input::SwitchJoystickInput_Type1::get_navigation_event( const SDL_Event& event ) const { if (event.type == SDL_JOYBUTTONDOWN) { if (event.jbutton.which != instance_id()) { - return helper::nullopt; + return std::nullopt; } switch (event.jbutton.button) { @@ -370,7 +370,7 @@ input::SwitchJoystickInput_Type1::SwitchJoystickInput_Type1( case JOYCON_MINUS: return NavigationEvent::BACK; default: - return helper::nullopt; + return std::nullopt; //note, that NavigationEvent::TAB is not supported } @@ -518,13 +518,13 @@ input::_3DSJoystickInput_Type1::_3DSJoystickInput_Type1( } { } -[[nodiscard]] helper::optional input::_3DSJoystickInput_Type1::get_navigation_event( +[[nodiscard]] std::optional input::_3DSJoystickInput_Type1::get_navigation_event( const SDL_Event& event ) const { if (event.type == SDL_JOYBUTTONDOWN) { if (event.jbutton.which != instance_id()) { - return helper::nullopt; + return std::nullopt; } switch (event.jbutton.button) { @@ -549,7 +549,7 @@ input::_3DSJoystickInput_Type1::_3DSJoystickInput_Type1( case JOYCON_B: return NavigationEvent::BACK; default: - return helper::nullopt; + return std::nullopt; //note, that NavigationEvent::TAB is not supported } @@ -695,7 +695,7 @@ input::JoystickGameInput::JoystickGameInput(EventDispatcher* event_dispatcher, J } namespace { - [[nodiscard]] helper::optional> get_game_joystick_by_guid( + [[nodiscard]] std::optional> get_game_joystick_by_guid( const sdl::GUID& guid, const input::JoystickSettings& settings, EventDispatcher* event_dispatcher, @@ -719,7 +719,7 @@ namespace { UNUSED(event_dispatcher); UNUSED(underlying_input); - return helper::nullopt; + return std::nullopt; } @@ -777,7 +777,7 @@ input::ConsoleJoystickInput::ConsoleJoystickInput( return to_normal_settings(default_settings_raw()); } -[[nodiscard]] helper::optional input::ConsoleJoystickInput::handle_axis_navigation_event( +[[nodiscard]] std::optional input::ConsoleJoystickInput::handle_axis_navigation_event( const SDL_Event& event ) const { if (event.type == SDL_JOYAXISMOTION) { @@ -790,7 +790,7 @@ input::ConsoleJoystickInput::ConsoleJoystickInput( static_cast(static_cast(SDL_JOYSTICK_AXIS_MAX) * axis_threshold_percentage); if (event.jaxis.which != instance_id()) { - return helper::nullopt; + return std::nullopt; } // x axis movement @@ -803,7 +803,7 @@ input::ConsoleJoystickInput::ConsoleJoystickInput( return NavigationEvent::LEFT; } - return helper::nullopt; + return std::nullopt; } // y axis movement @@ -816,13 +816,13 @@ input::ConsoleJoystickInput::ConsoleJoystickInput( return NavigationEvent::UP; } - return helper::nullopt; + return std::nullopt; } throw std::runtime_error(fmt::format("Reached unsupported axis for SDL_JOYAXISMOTION {}", event.jaxis.axis)); } - return helper::nullopt; + return std::nullopt; } @@ -856,11 +856,11 @@ input::ConsoleJoystickGameInput::~ConsoleJoystickGameInput() = default; // game_input uses Input to handle events, but stores the config settings for the specific button -helper::optional input::ConsoleJoystickGameInput::sdl_event_to_input_event(const SDL_Event& event) const { +std::optional input::ConsoleJoystickGameInput::sdl_event_to_input_event(const SDL_Event& event) const { if (event.type == SDL_JOYBUTTONDOWN) { if (event.jbutton.which != underlying_input()->instance_id()) { - return helper::nullopt; + return std::nullopt; } //TODO(Totto): use switch case @@ -889,7 +889,7 @@ helper::optional input::ConsoleJoystickGameInput::sdl_event_to_input } else if (event.type == SDL_JOYBUTTONUP) { if (event.jbutton.which != underlying_input()->instance_id()) { - return helper::nullopt; + return std::nullopt; } const auto button = event.jbutton.button; @@ -915,15 +915,15 @@ helper::optional input::ConsoleJoystickGameInput::sdl_event_to_input return InputEvent::HoldReleased; } } - return helper::nullopt; + return std::nullopt; } -[[nodiscard]] helper::optional input::ConsoleJoystickGameInput::get_menu_event(const SDL_Event& event +[[nodiscard]] std::optional input::ConsoleJoystickGameInput::get_menu_event(const SDL_Event& event ) const { if (event.type == SDL_JOYBUTTONDOWN) { if (event.jbutton.which != underlying_input()->instance_id()) { - return helper::nullopt; + return std::nullopt; } const auto button = event.jbutton.button; @@ -936,7 +936,7 @@ helper::optional input::ConsoleJoystickGameInput::sdl_event_to_input } } - return helper::nullopt; + return std::nullopt; } diff --git a/src/input/joystick_input.hpp b/src/input/joystick_input.hpp index 3e3a6e80..8953b82a 100644 --- a/src/input/joystick_input.hpp +++ b/src/input/joystick_input.hpp @@ -88,7 +88,7 @@ namespace input { [[nodiscard]] virtual JoystickSettings default_settings() const = 0; - [[nodiscard]] static helper::optional> get_joystick_by_guid( + [[nodiscard]] static std::optional> get_joystick_by_guid( const sdl::GUID& guid, SDL_Joystick* joystick, SDL_JoystickID instance_id, @@ -147,8 +147,7 @@ namespace input { [[nodiscard]] virtual AbstractJoystickSettings default_settings_raw() const = 0; - [[nodiscard]] helper::optional handle_axis_navigation_event(const SDL_Event& event - ) const; + [[nodiscard]] std::optional handle_axis_navigation_event(const SDL_Event& event) const; }; #if defined(__SWITCH__) @@ -159,7 +158,7 @@ namespace input { }; SwitchJoystickInput_Type1(SDL_Joystick* joystick, SDL_JoystickID instance_id, const std::string& name); - [[nodiscard]] helper::optional get_navigation_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional get_navigation_event(const SDL_Event& event) const override; [[nodiscard]] std::string describe_navigation_event(NavigationEvent event) const override; @@ -183,7 +182,7 @@ namespace input { }; _3DSJoystickInput_Type1(SDL_Joystick* joystick, SDL_JoystickID instance_id, const std::string& name); - [[nodiscard]] helper::optional get_navigation_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional get_navigation_event(const SDL_Event& event) const override; [[nodiscard]] std::string describe_navigation_event(NavigationEvent event) const override; @@ -253,7 +252,7 @@ namespace input { void update(SimulationStep simulation_step_index) override; protected: - [[nodiscard]] virtual helper::optional sdl_event_to_input_event(const SDL_Event& event) const = 0; + [[nodiscard]] virtual std::optional sdl_event_to_input_event(const SDL_Event& event) const = 0; }; @@ -309,12 +308,12 @@ namespace input { virtual ~ConsoleJoystickGameInput(); - [[nodiscard]] helper::optional get_menu_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional get_menu_event(const SDL_Event& event) const override; [[nodiscard]] std::string describe_menu_event(MenuEvent event) const override; protected: - [[nodiscard]] helper::optional sdl_event_to_input_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional sdl_event_to_input_event(const SDL_Event& event) const override; }; #if !defined(__SWITCH__) && !defined(__3DS__) #error "unsupported console" diff --git a/src/input/keyboard_input.cpp b/src/input/keyboard_input.cpp index 679963f2..afd19ac6 100644 --- a/src/input/keyboard_input.cpp +++ b/src/input/keyboard_input.cpp @@ -1,5 +1,5 @@ #include "keyboard_input.hpp" -#include "helper/optional.hpp" + #include "helper/utils.hpp" #include "input/game_input.hpp" #include "input/input.hpp" @@ -8,7 +8,7 @@ input::KeyboardInput::KeyboardInput() : input::Input{ "keyboard", InputType::Keyboard } { } -[[nodiscard]] helper::optional input::KeyboardInput::get_navigation_event(const SDL_Event& event +[[nodiscard]] std::optional input::KeyboardInput::get_navigation_event(const SDL_Event& event ) const { @@ -50,7 +50,7 @@ input::KeyboardInput::KeyboardInput() : input::Input{ "keyboard", InputType::Key } } - return helper::nullopt; + return std::nullopt; } @@ -95,7 +95,7 @@ void input::KeyboardGameInput::update(SimulationStep simulation_step_index) { GameInput::update(simulation_step_index); } -helper::optional input::KeyboardGameInput::sdl_event_to_input_event(const SDL_Event& event) const { +std::optional input::KeyboardGameInput::sdl_event_to_input_event(const SDL_Event& event) const { if (event.type == SDL_KEYDOWN and event.key.repeat == 0) { const auto key = sdl::Key{ event.key.keysym }; if (key == m_settings.rotate_left) { @@ -143,7 +143,7 @@ helper::optional input::KeyboardGameInput::sdl_event_to_input_event( return InputEvent::HoldReleased; } } - return helper::nullopt; + return std::nullopt; } input::KeyboardGameInput::KeyboardGameInput(const KeyboardSettings& settings, EventDispatcher* event_dispatcher) @@ -190,8 +190,7 @@ sdl::Key json_helper::get_key(const nlohmann::json& obj, const std::string& name } -[[nodiscard]] helper::optional input::KeyboardGameInput::get_menu_event(const SDL_Event& event -) const { +[[nodiscard]] std::optional input::KeyboardGameInput::get_menu_event(const SDL_Event& event) const { if (event.type == SDL_KEYDOWN and event.key.repeat == 0) { const auto key = sdl::Key{ event.key.keysym }; @@ -203,7 +202,7 @@ sdl::Key json_helper::get_key(const nlohmann::json& obj, const std::string& name } } - return helper::nullopt; + return std::nullopt; } [[nodiscard]] std::string input::KeyboardGameInput::describe_menu_event(MenuEvent event) const { diff --git a/src/input/keyboard_input.hpp b/src/input/keyboard_input.hpp index a09e5a12..870e6375 100644 --- a/src/input/keyboard_input.hpp +++ b/src/input/keyboard_input.hpp @@ -19,7 +19,7 @@ namespace input { public: KeyboardInput(); - [[nodiscard]] helper::optional get_navigation_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional get_navigation_event(const SDL_Event& event) const override; [[nodiscard]] std::string describe_navigation_event(NavigationEvent event) const override; }; @@ -77,14 +77,14 @@ namespace input { void update(SimulationStep simulation_step_index) override; - [[nodiscard]] helper::optional get_menu_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional get_menu_event(const SDL_Event& event) const override; [[nodiscard]] std::string describe_menu_event(MenuEvent event) const override; [[nodiscard]] const KeyboardInput* underlying_input() const override; private: - [[nodiscard]] helper::optional sdl_event_to_input_event(const SDL_Event& event) const; + [[nodiscard]] std::optional sdl_event_to_input_event(const SDL_Event& event) const; }; } // namespace input diff --git a/src/input/mouse_input.cpp b/src/input/mouse_input.cpp index 0cd16ffc..fc118e12 100644 --- a/src/input/mouse_input.cpp +++ b/src/input/mouse_input.cpp @@ -2,7 +2,7 @@ #include "mouse_input.hpp" #include "graphics/point.hpp" -#include "helper/optional.hpp" + #include "input/input.hpp" @@ -35,16 +35,16 @@ input::MouseInput::MouseInput() : PointerInput("mouse") { } } -[[nodiscard]] helper::optional -input::MouseInput::get_navigation_event(const SDL_Event& /*event*/) const { - return helper::nullopt; +[[nodiscard]] std::optional input::MouseInput::get_navigation_event(const SDL_Event& /*event*/) + const { + return std::nullopt; } [[nodiscard]] std::string input::MouseInput::describe_navigation_event(NavigationEvent /*event*/) const { throw std::runtime_error("not supported"); } -[[nodiscard]] helper::optional input::MouseInput::get_pointer_event(const SDL_Event& event +[[nodiscard]] std::optional input::MouseInput::get_pointer_event(const SDL_Event& event ) const { auto pointer_event = input::PointerEvent::PointerUp; @@ -66,11 +66,11 @@ input::MouseInput::get_navigation_event(const SDL_Event& /*event*/) const { case SDL_MOUSEBUTTONUP: break; default: - return helper::nullopt; + return std::nullopt; } if (event.button.button != SDL_BUTTON_LEFT) { - return helper::nullopt; + return std::nullopt; } const shapes::IPoint pos{ event.button.x, event.button.y }; diff --git a/src/input/mouse_input.hpp b/src/input/mouse_input.hpp index 4ac37c82..cd3a4c4d 100644 --- a/src/input/mouse_input.hpp +++ b/src/input/mouse_input.hpp @@ -9,11 +9,11 @@ namespace input { public: MouseInput(); - [[nodiscard]] helper::optional get_navigation_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional get_navigation_event(const SDL_Event& event) const override; [[nodiscard]] std::string describe_navigation_event(NavigationEvent event) const override; - [[nodiscard]] helper::optional get_pointer_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional get_pointer_event(const SDL_Event& event) const override; [[nodiscard]] SDL_Event offset_pointer_event(const SDL_Event& event, const shapes::IPoint& point) const override; diff --git a/src/input/replay_input.cpp b/src/input/replay_input.cpp index ccb99119..cd5fe4db 100644 --- a/src/input/replay_input.cpp +++ b/src/input/replay_input.cpp @@ -1,7 +1,7 @@ #include "replay_input.hpp" #include "game/tetrion.hpp" #include "helper/magic_enum_wrapper.hpp" -#include "helper/optional.hpp" + input::ReplayGameInput::ReplayGameInput( std::shared_ptr recording_reader, @@ -81,9 +81,8 @@ void input::ReplayGameInput::late_update(const SimulationStep simulation_step_in } -[[nodiscard]] helper::optional input::ReplayGameInput::get_menu_event(const SDL_Event& /*event*/) - const { - return helper::nullopt; +[[nodiscard]] std::optional input::ReplayGameInput::get_menu_event(const SDL_Event& /*event*/) const { + return std::nullopt; } [[nodiscard]] std::string input::ReplayGameInput::describe_menu_event(MenuEvent /*event*/) const { diff --git a/src/input/replay_input.hpp b/src/input/replay_input.hpp index d4301b5a..311c2e5b 100644 --- a/src/input/replay_input.hpp +++ b/src/input/replay_input.hpp @@ -21,7 +21,7 @@ namespace input { void update(SimulationStep simulation_step_index) override; void late_update(SimulationStep simulation_step_index) override; - [[nodiscard]] helper::optional get_menu_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional get_menu_event(const SDL_Event& event) const override; [[nodiscard]] std::string describe_menu_event(MenuEvent event) const override; diff --git a/src/input/touch_input.cpp b/src/input/touch_input.cpp index febc580f..6c1e84a9 100644 --- a/src/input/touch_input.cpp +++ b/src/input/touch_input.cpp @@ -1,6 +1,6 @@ #include "touch_input.hpp" #include "graphics/point.hpp" -#include "helper/optional.hpp" + #include "helper/utils.hpp" #include "input/game_input.hpp" #include "input/input.hpp" @@ -26,11 +26,11 @@ void input::TouchGameInput::update(SimulationStep simulation_step_index) { GameInput::update(simulation_step_index); } -helper::optional input::TouchGameInput::sdl_event_to_input_event(const SDL_Event& event) { +std::optional input::TouchGameInput::sdl_event_to_input_event(const SDL_Event& event) { if (event.tfinger.touchId != m_underlying_input->m_id) { - return helper::nullopt; + return std::nullopt; } //TODO(Totto): to handle those things better, holding has to be supported @@ -44,7 +44,7 @@ helper::optional input::TouchGameInput::sdl_event_to_input_event(con if (m_finger_state.contains(finger_id) and m_finger_state.at(finger_id).has_value()) { // there are some valid reasons, this can occur now - return helper::nullopt; + return std::nullopt; } const auto x_pos = event.tfinger.x; @@ -53,7 +53,7 @@ helper::optional input::TouchGameInput::sdl_event_to_input_event(con m_finger_state.insert_or_assign( finger_id, - helper::optional{ + std::optional{ PressedState{ timestamp, x_pos, y_pos } } ); @@ -68,13 +68,13 @@ helper::optional input::TouchGameInput::sdl_event_to_input_event(con if (!m_finger_state.contains(finger_id)) { // there are some valid reasons, this can occur now - return helper::nullopt; + return std::nullopt; } const auto& finger_state = m_finger_state.at(finger_id); if (!finger_state.has_value()) { - return helper::nullopt; + return std::nullopt; } const auto& pressed_state = finger_state.value(); @@ -95,7 +95,7 @@ helper::optional input::TouchGameInput::sdl_event_to_input_event(con const auto threshold_x = m_settings.move_x_threshold; const auto threshold_y = m_settings.move_y_threshold; - m_finger_state.insert_or_assign(finger_id, helper::nullopt); + m_finger_state.insert_or_assign(finger_id, std::nullopt); if (duration < m_settings.rotation_duration_threshold) { if (dx_abs < threshold_x and dy_abs < threshold_y) { // tap on the right side of the screen @@ -138,7 +138,7 @@ helper::optional input::TouchGameInput::sdl_event_to_input_event(con } - return helper::nullopt; + return std::nullopt; } @@ -162,13 +162,13 @@ input::TouchGameInput::~TouchGameInput() { input::TouchGameInput::TouchGameInput(TouchGameInput&& input) noexcept = default; [[nodiscard]] input::TouchGameInput& input::TouchGameInput::operator=(TouchGameInput&& input) noexcept = default; -[[nodiscard]] helper::optional input::TouchGameInput::get_menu_event(const SDL_Event& event) const { +[[nodiscard]] std::optional input::TouchGameInput::get_menu_event(const SDL_Event& event) const { if (event.type == SDL_KEYDOWN and event.key.keysym.sym == SDLK_AC_BACK) { return MenuEvent::Pause; } - return helper::nullopt; + return std::nullopt; } [[nodiscard]] std::string input::TouchGameInput::describe_menu_event(MenuEvent event) const { @@ -213,14 +213,14 @@ input::TouchInput::get_by_device_index(const std::shared_ptr& window, in } -[[nodiscard]] helper::optional input::TouchInput::get_navigation_event(const SDL_Event& event +[[nodiscard]] std::optional input::TouchInput::get_navigation_event(const SDL_Event& event ) const { //technically no touch event, but it's a navigation event, and by APi design it can also handle those if (event.type == SDL_KEYDOWN and event.key.keysym.sym == SDLK_AC_BACK) { return input::NavigationEvent::BACK; } - return helper::nullopt; + return std::nullopt; } [[nodiscard]] std::string input::TouchInput::describe_navigation_event(NavigationEvent event) const { @@ -239,7 +239,7 @@ input::TouchInput::get_by_device_index(const std::shared_ptr& window, in } } -[[nodiscard]] helper::optional input::TouchInput::get_pointer_event(const SDL_Event& event +[[nodiscard]] std::optional input::TouchInput::get_pointer_event(const SDL_Event& event ) const { auto pointer_event = input::PointerEvent::PointerUp; @@ -254,11 +254,11 @@ input::TouchInput::get_by_device_index(const std::shared_ptr& window, in case SDL_FINGERUP: break; default: - return helper::nullopt; + return std::nullopt; } if (event.tfinger.touchId != m_id) { - return helper::nullopt; + return std::nullopt; } // These are doubles, from 0-1 (or if using virtual layouts > 0) in percent, the have to be casted to absolut x coordinates! diff --git a/src/input/touch_input.hpp b/src/input/touch_input.hpp index 4b75dcbc..674903f4 100644 --- a/src/input/touch_input.hpp +++ b/src/input/touch_input.hpp @@ -20,11 +20,11 @@ namespace input { [[nodiscard]] static helper::expected, std::string> get_by_device_index(const std::shared_ptr& window, int device_index); - [[nodiscard]] helper::optional get_navigation_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional get_navigation_event(const SDL_Event& event) const override; [[nodiscard]] std::string describe_navigation_event(NavigationEvent event) const override; - [[nodiscard]] helper::optional get_pointer_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional get_pointer_event(const SDL_Event& event) const override; [[nodiscard]] SDL_Event offset_pointer_event(const SDL_Event& event, const shapes::IPoint& point) const override; @@ -70,7 +70,7 @@ namespace input { private: TouchSettings m_settings; - std::unordered_map> m_finger_state; + std::unordered_map> m_finger_state; std::vector m_event_buffer; EventDispatcher* m_event_dispatcher; TouchInput* m_underlying_input; @@ -94,14 +94,14 @@ namespace input { void handle_event(const SDL_Event& event) override; void update(SimulationStep simulation_step_index) override; - [[nodiscard]] helper::optional get_menu_event(const SDL_Event& event) const override; + [[nodiscard]] std::optional get_menu_event(const SDL_Event& event) const override; [[nodiscard]] std::string describe_menu_event(MenuEvent event) const override; [[nodiscard]] const TouchInput* underlying_input() const override; private: - [[nodiscard]] helper::optional sdl_event_to_input_event(const SDL_Event& event); + [[nodiscard]] std::optional sdl_event_to_input_event(const SDL_Event& event); }; } // namespace input diff --git a/src/libs/core/core.hpp b/src/libs/core/core.hpp new file mode 100644 index 00000000..cdcc451e --- /dev/null +++ b/src/libs/core/core.hpp @@ -0,0 +1,32 @@ + + +#pragma once + +// this is a easy public header, that you can include, to get all header of liboopetris_core + + +#include "./game/grid_properties.hpp" +#include "./game/mino.hpp" +#include "./game/mino_stack.hpp" +#include "./game/tetromino_type.hpp" + +#include "./hash-library/sha256.h" + +#include "./helper/bool_wrapper.hpp" +#include "./helper/color.hpp" +#include "./helper/color_literals.hpp" +#include "./helper/const_utils.hpp" +#include "./helper/date.hpp" +#include "./helper/errors.hpp" +#include "./helper/expected.hpp" +#include "./helper/input_event.hpp" +#include "./helper/magic_enum_wrapper.hpp" +#include "./helper/parse_json.hpp" +#include "./helper/point.hpp" +#include "./helper/random.hpp" +#include "./helper/sleep.hpp" +#include "./helper/static_string.hpp" +#include "./helper/string_manipulation.hpp" +#include "./helper/timer.hpp" +#include "./helper/types.hpp" +#include "./helper/utils.hpp" diff --git a/src/game/grid_properties.hpp b/src/libs/core/game/grid_properties.hpp similarity index 96% rename from src/game/grid_properties.hpp rename to src/libs/core/game/grid_properties.hpp index 4aa6d41b..0d67c5a0 100644 --- a/src/game/grid_properties.hpp +++ b/src/libs/core/game/grid_properties.hpp @@ -2,7 +2,7 @@ #pragma once -#include "graphics/point.hpp" +#include "../helper/point.hpp" namespace grid { diff --git a/src/libs/core/game/meson.build b/src/libs/core/game/meson.build new file mode 100644 index 00000000..024eaefd --- /dev/null +++ b/src/libs/core/game/meson.build @@ -0,0 +1,12 @@ +core_src_files += files( + 'mino.cpp', + 'mino_stack.cpp', + 'tetromino_type.cpp', +) + +core_header_files += files( + 'grid_properties.hpp', + 'mino.hpp', + 'mino_stack.hpp', + 'tetromino_type.hpp', +) diff --git a/src/game/mino.cpp b/src/libs/core/game/mino.cpp similarity index 95% rename from src/game/mino.cpp rename to src/libs/core/game/mino.cpp index 3b22ff96..0856d8d4 100644 --- a/src/game/mino.cpp +++ b/src/libs/core/game/mino.cpp @@ -1,4 +1,4 @@ -#include "mino.hpp" +#include "./mino.hpp" [[nodiscard]] helper::TetrominoType Mino::type() const { return m_type; diff --git a/src/game/mino.hpp b/src/libs/core/game/mino.hpp similarity index 83% rename from src/game/mino.hpp rename to src/libs/core/game/mino.hpp index 1e14123e..016a9759 100644 --- a/src/game/mino.hpp +++ b/src/libs/core/game/mino.hpp @@ -1,9 +1,9 @@ #pragma once -#include "graphics/point.hpp" -#include "grid_properties.hpp" -#include "helper/types.hpp" -#include "tetromino_type.hpp" +#include "../helper/point.hpp" +#include "../helper/types.hpp" +#include "./grid_properties.hpp" +#include "./tetromino_type.hpp" #include struct Mino final { diff --git a/src/game/mino_stack.cpp b/src/libs/core/game/mino_stack.cpp similarity index 96% rename from src/game/mino_stack.cpp rename to src/libs/core/game/mino_stack.cpp index 770774d6..a4b655fe 100644 --- a/src/game/mino_stack.cpp +++ b/src/libs/core/game/mino_stack.cpp @@ -1,6 +1,6 @@ -#include "mino_stack.hpp" -#include "grid_properties.hpp" -#include "helper/magic_enum_wrapper.hpp" +#include "./mino_stack.hpp" +#include "./grid_properties.hpp" +#include "./helper/magic_enum_wrapper.hpp" #include diff --git a/src/game/mino_stack.hpp b/src/libs/core/game/mino_stack.hpp similarity index 92% rename from src/game/mino_stack.hpp rename to src/libs/core/game/mino_stack.hpp index fc9a62a6..161c74b9 100644 --- a/src/game/mino_stack.hpp +++ b/src/libs/core/game/mino_stack.hpp @@ -1,7 +1,7 @@ #pragma once -#include "helper/types.hpp" -#include "mino.hpp" +#include "../helper/types.hpp" +#include "./mino.hpp" #include diff --git a/src/game/tetromino_type.cpp b/src/libs/core/game/tetromino_type.cpp similarity index 97% rename from src/game/tetromino_type.cpp rename to src/libs/core/game/tetromino_type.cpp index 2cc949c2..944dfb3b 100644 --- a/src/game/tetromino_type.cpp +++ b/src/libs/core/game/tetromino_type.cpp @@ -1,5 +1,5 @@ -#include "tetromino_type.hpp" +#include "./tetromino_type.hpp" [[nodiscard]] Color helper::get_foreground_color(TetrominoType type, u8 alpha) { diff --git a/src/game/tetromino_type.hpp b/src/libs/core/game/tetromino_type.hpp similarity index 85% rename from src/game/tetromino_type.hpp rename to src/libs/core/game/tetromino_type.hpp index e88875f5..5ed6e5c4 100644 --- a/src/game/tetromino_type.hpp +++ b/src/libs/core/game/tetromino_type.hpp @@ -1,6 +1,8 @@ #pragma once -#include "helper/color.hpp" +#include "../helper/color.hpp" +#include "../helper/types.hpp" + namespace helper { enum class TetrominoType : u8 { diff --git a/src/thirdparty/hash-library/LICENSE b/src/libs/core/hash-library/LICENSE similarity index 100% rename from src/thirdparty/hash-library/LICENSE rename to src/libs/core/hash-library/LICENSE diff --git a/src/libs/core/hash-library/meson.build b/src/libs/core/hash-library/meson.build new file mode 100644 index 00000000..02a9348c --- /dev/null +++ b/src/libs/core/hash-library/meson.build @@ -0,0 +1,7 @@ +core_src_files += files( + 'sha256.cpp', +) + +core_header_files += files( + 'sha256.h', +) diff --git a/src/thirdparty/hash-library/readme.md b/src/libs/core/hash-library/readme.md similarity index 100% rename from src/thirdparty/hash-library/readme.md rename to src/libs/core/hash-library/readme.md diff --git a/src/thirdparty/hash-library/sha256.cpp b/src/libs/core/hash-library/sha256.cpp similarity index 99% rename from src/thirdparty/hash-library/sha256.cpp rename to src/libs/core/hash-library/sha256.cpp index 66edea18..d085a97e 100644 --- a/src/thirdparty/hash-library/sha256.cpp +++ b/src/libs/core/hash-library/sha256.cpp @@ -6,7 +6,7 @@ // Altered by Totto16 to fix some bugs and compiler warnings / errors -#include "sha256.h" +#include "./sha256.h" // big endian architectures need #define __BYTE_ORDER __BIG_ENDIAN #if defined(_MSC_VER) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) diff --git a/src/thirdparty/hash-library/sha256.h b/src/libs/core/hash-library/sha256.h similarity index 100% rename from src/thirdparty/hash-library/sha256.h rename to src/libs/core/hash-library/sha256.h diff --git a/src/thirdparty/hash-library/url.txt b/src/libs/core/hash-library/url.txt similarity index 100% rename from src/thirdparty/hash-library/url.txt rename to src/libs/core/hash-library/url.txt diff --git a/src/helper/bool_wrapper.hpp b/src/libs/core/helper/bool_wrapper.hpp similarity index 70% rename from src/helper/bool_wrapper.hpp rename to src/libs/core/helper/bool_wrapper.hpp index 0fb4a36b..0a898195 100644 --- a/src/helper/bool_wrapper.hpp +++ b/src/libs/core/helper/bool_wrapper.hpp @@ -1,6 +1,5 @@ #pragma once -#include "helper/optional.hpp" namespace helper { @@ -8,16 +7,16 @@ namespace helper { struct BoolWrapper { private: bool m_value; - helper::optional additional; + std::optional additional; public: - BoolWrapper(bool value) : m_value{ value }, additional{ helper::nullopt } { } + BoolWrapper(bool value) : m_value{ value }, additional{ std::nullopt } { } BoolWrapper(bool value, const T& additional) : m_value{ value }, additional{ additional } { } - BoolWrapper(bool value, const helper::optional& additional) : m_value{ value }, additional{ additional } { } + BoolWrapper(bool value, const std::optional& additional) : m_value{ value }, additional{ additional } { } - const helper::optional& get_additional() const { + const std::optional& get_additional() const { return additional; } diff --git a/src/helper/color.cpp b/src/libs/core/helper/color.cpp similarity index 97% rename from src/helper/color.cpp rename to src/libs/core/helper/color.cpp index f6a0fc16..51b24a72 100644 --- a/src/helper/color.cpp +++ b/src/libs/core/helper/color.cpp @@ -1,9 +1,9 @@ -#include "color.hpp" -#include "color_literals.hpp" -#include "helper/expected.hpp" -#include "helper/utils.hpp" +#include "./color.hpp" +#include "./color_literals.hpp" +#include "./helper/expected.hpp" +#include "./helper/utils.hpp" #include diff --git a/src/helper/color.hpp b/src/libs/core/helper/color.hpp similarity index 98% rename from src/helper/color.hpp rename to src/libs/core/helper/color.hpp index 81090220..fa51b236 100644 --- a/src/helper/color.hpp +++ b/src/libs/core/helper/color.hpp @@ -1,9 +1,10 @@ #pragma once -#include "const_utils.hpp" -#include "helper/expected.hpp" -#include "helper/types.hpp" -#include "helper/utils.hpp" +#include + +#include "./const_utils.hpp" +#include "./types.hpp" +#include "./utils.hpp" #include #include diff --git a/src/helper/color_literals.hpp b/src/libs/core/helper/color_literals.hpp similarity index 99% rename from src/helper/color_literals.hpp rename to src/libs/core/helper/color_literals.hpp index 8d0f5cee..35ce8f2b 100644 --- a/src/helper/color_literals.hpp +++ b/src/libs/core/helper/color_literals.hpp @@ -1,8 +1,8 @@ #pragma once -#include "color.hpp" -#include "const_utils.hpp" -#include "helper/types.hpp" +#include "./color.hpp" +#include "./const_utils.hpp" +#include "./helper/types.hpp" #include #include diff --git a/src/helper/const_utils.hpp b/src/libs/core/helper/const_utils.hpp similarity index 99% rename from src/helper/const_utils.hpp rename to src/libs/core/helper/const_utils.hpp index 0dda909b..233348b6 100644 --- a/src/helper/const_utils.hpp +++ b/src/libs/core/helper/const_utils.hpp @@ -1,7 +1,7 @@ #pragma once -#include "helper/utils.hpp" +#include "./utils.hpp" #include #include diff --git a/src/helper/date.cpp b/src/libs/core/helper/date.cpp similarity index 99% rename from src/helper/date.cpp rename to src/libs/core/helper/date.cpp index c938404d..dc78b9e8 100644 --- a/src/helper/date.cpp +++ b/src/libs/core/helper/date.cpp @@ -1,5 +1,5 @@ -#include "date.hpp" +#include "./date.hpp" #include #include diff --git a/src/helper/date.hpp b/src/libs/core/helper/date.hpp similarity index 92% rename from src/helper/date.hpp rename to src/libs/core/helper/date.hpp index 95dfc44c..4a3377e3 100644 --- a/src/helper/date.hpp +++ b/src/libs/core/helper/date.hpp @@ -1,7 +1,7 @@ #pragma once -#include "helper/expected.hpp" -#include "helper/types.hpp" +#include "./helper/expected.hpp" +#include "./helper/types.hpp" #include #include diff --git a/src/helper/errors.cpp b/src/libs/core/helper/errors.cpp similarity index 98% rename from src/helper/errors.cpp rename to src/libs/core/helper/errors.cpp index 659dc7f0..37eb4017 100644 --- a/src/helper/errors.cpp +++ b/src/libs/core/helper/errors.cpp @@ -1,4 +1,4 @@ -#include "errors.hpp" +#include "./errors.hpp" helper::GeneralError::GeneralError(const std::string& message, error::Severity severity) noexcept : m_message{ message }, diff --git a/src/helper/errors.hpp b/src/libs/core/helper/errors.hpp similarity index 100% rename from src/helper/errors.hpp rename to src/libs/core/helper/errors.hpp diff --git a/src/helper/expected.hpp b/src/libs/core/helper/expected.hpp similarity index 100% rename from src/helper/expected.hpp rename to src/libs/core/helper/expected.hpp diff --git a/src/manager/input_event.hpp b/src/libs/core/helper/input_event.hpp similarity index 92% rename from src/manager/input_event.hpp rename to src/libs/core/helper/input_event.hpp index a2f4dcfa..a0fb4642 100644 --- a/src/manager/input_event.hpp +++ b/src/libs/core/helper/input_event.hpp @@ -1,6 +1,6 @@ #pragma once -#include "helper/types.hpp" +#include "./types.hpp" enum class InputEvent : u8 { RotateLeftPressed, diff --git a/src/helper/magic_enum_wrapper.hpp b/src/libs/core/helper/magic_enum_wrapper.hpp similarity index 100% rename from src/helper/magic_enum_wrapper.hpp rename to src/libs/core/helper/magic_enum_wrapper.hpp diff --git a/src/libs/core/helper/meson.build b/src/libs/core/helper/meson.build new file mode 100644 index 00000000..fd56c15b --- /dev/null +++ b/src/libs/core/helper/meson.build @@ -0,0 +1,30 @@ +core_src_files += files( + 'color.cpp', + 'date.cpp', + 'errors.cpp', + 'parse_json.cpp', + 'random.cpp', + 'sleep.cpp', + 'string_manipulation.cpp', +) + +core_header_files += files( + 'bool_wrapper.hpp', + 'color.hpp', + 'color_literals.hpp', + 'const_utils.hpp', + 'date.hpp', + 'errors.hpp', + 'expected.hpp', + 'input_event.hpp', + 'magic_enum_wrapper.hpp', + 'parse_json.hpp', + 'point.hpp', + 'random.hpp', + 'sleep.hpp', + 'static_string.hpp', + 'string_manipulation.hpp', + 'timer.hpp', + 'types.hpp', + 'utils.hpp', +) diff --git a/src/helper/parse_json.cpp b/src/libs/core/helper/parse_json.cpp similarity index 98% rename from src/helper/parse_json.cpp rename to src/libs/core/helper/parse_json.cpp index 76415fc5..1a05b99d 100644 --- a/src/helper/parse_json.cpp +++ b/src/libs/core/helper/parse_json.cpp @@ -1,6 +1,6 @@ -#include "parse_json.hpp" +#include "./parse_json.hpp" std::string json::get_json_type(const nlohmann::json::value_t& type) { diff --git a/src/helper/parse_json.hpp b/src/libs/core/helper/parse_json.hpp similarity index 91% rename from src/helper/parse_json.hpp rename to src/libs/core/helper/parse_json.hpp index ceb790f1..f5552148 100644 --- a/src/helper/parse_json.hpp +++ b/src/libs/core/helper/parse_json.hpp @@ -8,8 +8,8 @@ #include -#include "helper/expected.hpp" -#include "helper/optional.hpp" +#include "./helper/expected.hpp" + #include #include @@ -19,12 +19,12 @@ // START: general json parser helper -//helper for helper::optional json conversion +//helper for std::optional json conversion NLOHMANN_JSON_NAMESPACE_BEGIN template -struct adl_serializer> { - static void to_json(json& obj, const helper::optional& opt) { +struct adl_serializer> { + static void to_json(json& obj, const std::optional& opt) { if (not opt) { obj = nullptr; } else { @@ -33,9 +33,9 @@ struct adl_serializer> { } } - static void from_json(const json& obj, helper::optional& opt) { + static void from_json(const json& obj, std::optional& opt) { if (obj.is_null()) { - opt = helper::nullopt; + opt = std::nullopt; } else { opt = obj.template get(); // same as above, but with // adl_serializer::from_json diff --git a/src/graphics/point.hpp b/src/libs/core/helper/point.hpp similarity index 99% rename from src/graphics/point.hpp rename to src/libs/core/helper/point.hpp index b0849901..d7443388 100644 --- a/src/graphics/point.hpp +++ b/src/libs/core/helper/point.hpp @@ -4,7 +4,7 @@ #include #include -#include "helper/types.hpp" +#include "../helper/types.hpp" namespace shapes { template diff --git a/src/helper/random.cpp b/src/libs/core/helper/random.cpp similarity index 93% rename from src/helper/random.cpp rename to src/libs/core/helper/random.cpp index 0481b7f5..de74f572 100644 --- a/src/helper/random.cpp +++ b/src/libs/core/helper/random.cpp @@ -1,4 +1,5 @@ -#include "helper/random.hpp" +#include "./helper/random.hpp" + #include Random::Random() : Random{ generate_seed() } { } diff --git a/src/helper/random.hpp b/src/libs/core/helper/random.hpp similarity index 96% rename from src/helper/random.hpp rename to src/libs/core/helper/random.hpp index 226a5e89..06c913ec 100644 --- a/src/helper/random.hpp +++ b/src/libs/core/helper/random.hpp @@ -1,6 +1,6 @@ #pragma once -#include "helper/utils.hpp" +#include "./utils.hpp" #include diff --git a/src/helper/sleep.cpp b/src/libs/core/helper/sleep.cpp similarity index 98% rename from src/helper/sleep.cpp rename to src/libs/core/helper/sleep.cpp index 18049cd1..9ddde9d2 100644 --- a/src/helper/sleep.cpp +++ b/src/libs/core/helper/sleep.cpp @@ -1,7 +1,7 @@ -#include "sleep.hpp" +#include "./sleep.hpp" #if defined(_MSC_VER) #ifndef NOMINMAX diff --git a/src/helper/sleep.hpp b/src/libs/core/helper/sleep.hpp similarity index 100% rename from src/helper/sleep.hpp rename to src/libs/core/helper/sleep.hpp diff --git a/src/helper/static_string.hpp b/src/libs/core/helper/static_string.hpp similarity index 99% rename from src/helper/static_string.hpp rename to src/libs/core/helper/static_string.hpp index 5b4a96e0..237c9639 100644 --- a/src/helper/static_string.hpp +++ b/src/libs/core/helper/static_string.hpp @@ -1,6 +1,6 @@ #pragma once -#include "helper/types.hpp" +#include "./helper/types.hpp" #include #include diff --git a/src/helper/string_manipulation.cpp b/src/libs/core/helper/string_manipulation.cpp similarity index 97% rename from src/helper/string_manipulation.cpp rename to src/libs/core/helper/string_manipulation.cpp index 881ae20c..30bcc4d7 100644 --- a/src/helper/string_manipulation.cpp +++ b/src/libs/core/helper/string_manipulation.cpp @@ -1,5 +1,5 @@ -#include "string_manipulation.hpp" +#include "./string_manipulation.hpp" #include #include diff --git a/src/helper/string_manipulation.hpp b/src/libs/core/helper/string_manipulation.hpp similarity index 100% rename from src/helper/string_manipulation.hpp rename to src/libs/core/helper/string_manipulation.hpp diff --git a/src/helper/timer.hpp b/src/libs/core/helper/timer.hpp similarity index 100% rename from src/helper/timer.hpp rename to src/libs/core/helper/timer.hpp diff --git a/src/helper/types.hpp b/src/libs/core/helper/types.hpp similarity index 100% rename from src/helper/types.hpp rename to src/libs/core/helper/types.hpp diff --git a/src/helper/utils.hpp b/src/libs/core/helper/utils.hpp similarity index 93% rename from src/helper/utils.hpp rename to src/libs/core/helper/utils.hpp index b571898e..93cdad60 100644 --- a/src/helper/utils.hpp +++ b/src/libs/core/helper/utils.hpp @@ -1,7 +1,7 @@ #pragma once -#include "helper/optional.hpp" -#include "helper/types.hpp" + +#include "./types.hpp" #include #include @@ -94,23 +94,23 @@ namespace utils { template - constexpr helper::optional is_child_class(S* parent) { + constexpr std::optional is_child_class(S* parent) { auto* result = dynamic_cast(parent); if (result == nullptr) { - return helper::nullopt; + return std::nullopt; } return result; } template - constexpr helper::optional is_child_class(const std::unique_ptr& parent) { + constexpr std::optional is_child_class(const std::unique_ptr& parent) { return is_child_class(parent.get()); } template - constexpr helper::optional is_child_class(const std::shared_ptr& parent) { + constexpr std::optional is_child_class(const std::shared_ptr& parent) { return is_child_class(parent.get()); } diff --git a/src/libs/core/meson.build b/src/libs/core/meson.build new file mode 100644 index 00000000..ec710d94 --- /dev/null +++ b/src/libs/core/meson.build @@ -0,0 +1,43 @@ +core_src_files = [] +core_header_files = [files('core.hpp')] + +subdir('game') +subdir('hash-library') +subdir('helper') + +liboopetris_core = library( + 'oopetris_core', + core_src_files, + core_header_files, + include_directories: core_lib.get('inc_dirs'), + dependencies: core_lib.get('deps'), + cpp_args: core_lib.get('compile_args'), + override_options: { + 'warning_level': '3', + 'werror': true, + }, + version: meson.project_version(), + install: true, +) + +liboopetris_core_dep = declare_dependency( + link_with: liboopetris_core, + include_directories: core_lib.get('inc_dirs'), + compile_args: core_lib.get('compile_args'), + dependencies: core_lib.get('deps'), + version: meson.project_version(), +) +meson.override_dependency('liboopetris-core', liboopetris_core_dep) + +# setting this to strings, so += {...} gets detected as an error, if it is done after that +core_lib = 'undefined' + +install_headers(core_header_files, subdir: 'oopetris/core', preserve_path: true) + +# generate pkgconfig files +pkg = import('pkgconfig') +pkg.generate( + liboopetris_core, + name: 'oopetris-core', + filebase: 'oopetris-core', +) diff --git a/src/libs/meson.build b/src/libs/meson.build new file mode 100644 index 00000000..dcb9a76c --- /dev/null +++ b/src/libs/meson.build @@ -0,0 +1,12 @@ + +core_lib += { + 'inc_dirs': [core_lib.get('inc_dirs'), include_directories('.')], +} + +subdir('core') + +recordings_lib += { + 'inc_dirs': [recordings_lib.get('inc_dirs'), include_directories('.')], +} + +subdir('recordings') diff --git a/src/libs/recordings/meson.build b/src/libs/recordings/meson.build new file mode 100644 index 00000000..db33ece9 --- /dev/null +++ b/src/libs/recordings/meson.build @@ -0,0 +1,50 @@ +recordings_src_files = [] +recordings_header_files = [] + +subdir('utility') + +recordings_lib += { + 'deps': [recordings_lib.get('deps'), liboopetris_core_dep], + 'inc_dirs': [recordings_lib.get('inc_dirs'), include_directories('.')], +} + +liboopetris_recordings = library( + 'oopetris_recordings', + recordings_src_files, + recordings_header_files, + include_directories: recordings_lib.get('inc_dirs'), + dependencies: recordings_lib.get('deps'), + cpp_args: recordings_lib.get('compile_args'), + override_options: { + 'warning_level': '3', + 'werror': true, + }, + version: meson.project_version(), + install: true, +) + +liboopetris_recordings_dep = declare_dependency( + link_with: liboopetris_recordings, + include_directories: recordings_lib.get('inc_dirs'), + compile_args: recordings_lib.get('compile_args'), + dependencies: recordings_lib.get('deps'), + version: meson.project_version(), +) +meson.override_dependency('liboopetris-recordings', liboopetris_recordings_dep) + +# setting this to strings, so += {...} gets detected as an error, if it is done after that +recordings_lib = 'undefined' + +install_headers( + recordings_header_files, + subdir: 'oopetris/recordings', + preserve_path: true, +) + +# generate pkgconfig files +pkg = import('pkgconfig') +pkg.generate( + liboopetris_recordings, + name: 'oopetris-recordings', + filebase: 'oopetris-recordings', +) diff --git a/src/recordings/additional_information.cpp b/src/libs/recordings/utility/additional_information.cpp similarity index 99% rename from src/recordings/additional_information.cpp rename to src/libs/recordings/utility/additional_information.cpp index 8be23c5b..1321b094 100644 --- a/src/recordings/additional_information.cpp +++ b/src/libs/recordings/utility/additional_information.cpp @@ -1,7 +1,7 @@ -#include "additional_information.hpp" -#include "helper.hpp" +#include "./additional_information.hpp" +#include "./helper.hpp" #include #include @@ -467,10 +467,10 @@ void recorder::AdditionalInformation::add_value(const std::string& key, const In m_values.insert_or_assign(key, value); } -helper::optional recorder::AdditionalInformation::get(const std::string& key) const { +std::optional recorder::AdditionalInformation::get(const std::string& key) const { if (not has(key)) { - return helper::nullopt; + return std::nullopt; } return m_values.at(key); diff --git a/src/recordings/additional_information.hpp b/src/libs/recordings/utility/additional_information.hpp similarity index 94% rename from src/recordings/additional_information.hpp rename to src/libs/recordings/utility/additional_information.hpp index 3a6794a0..c414a5bf 100644 --- a/src/recordings/additional_information.hpp +++ b/src/libs/recordings/utility/additional_information.hpp @@ -1,11 +1,10 @@ #pragma once -#include "checksum_helper.hpp" -#include "helper.hpp" -#include "helper/expected.hpp" -#include "helper/optional.hpp" -#include "helper/types.hpp" +#include "./checksum_helper.hpp" +#include "./helper.hpp" +#include +#include #include #include @@ -155,21 +154,21 @@ namespace recorder { add_value(key, value, overwrite); } - [[nodiscard]] helper::optional get(const std::string& key) const; + [[nodiscard]] std::optional get(const std::string& key) const; [[nodiscard]] bool has(const std::string& key) const; template - [[nodiscard]] helper::optional get_if(const std::string& key) const { + [[nodiscard]] std::optional get_if(const std::string& key) const { if (not has(key)) { - return helper::nullopt; + return std::nullopt; } const auto& value = m_values.at(key); if (not value.is()) { - return helper::nullopt; + return std::nullopt; } return value.as(); diff --git a/src/recordings/checksum_helper.cpp b/src/libs/recordings/utility/checksum_helper.cpp similarity index 93% rename from src/recordings/checksum_helper.cpp rename to src/libs/recordings/utility/checksum_helper.cpp index df1083cc..25fb8258 100644 --- a/src/recordings/checksum_helper.cpp +++ b/src/libs/recordings/utility/checksum_helper.cpp @@ -1,6 +1,6 @@ -#include "checksum_helper.hpp" +#include "./checksum_helper.hpp" Sha256Stream::Sha256Stream() = default; diff --git a/src/recordings/checksum_helper.hpp b/src/libs/recordings/utility/checksum_helper.hpp similarity index 94% rename from src/recordings/checksum_helper.hpp rename to src/libs/recordings/utility/checksum_helper.hpp index dc54a516..6f259b84 100644 --- a/src/recordings/checksum_helper.hpp +++ b/src/libs/recordings/utility/checksum_helper.hpp @@ -2,10 +2,10 @@ #pragma once -#include "helper/utils.hpp" +#include +#include #include -#include #include #include diff --git a/src/recordings/helper.hpp b/src/libs/recordings/utility/helper.hpp similarity index 91% rename from src/recordings/helper.hpp rename to src/libs/recordings/utility/helper.hpp index 8479b411..3bd19fe5 100644 --- a/src/recordings/helper.hpp +++ b/src/libs/recordings/utility/helper.hpp @@ -3,9 +3,9 @@ #pragma once -#include "helper/expected.hpp" -#include "helper/types.hpp" -#include "helper/utils.hpp" +#include +#include +#include #include #include @@ -79,9 +79,9 @@ namespace helper { } template - [[nodiscard]] helper::optional read_from_istream(std::istream& istream) { + [[nodiscard]] std::optional read_from_istream(std::istream& istream) { if (not istream) { - return helper::nullopt; + return std::nullopt; } auto value = Integral{}; istream.read( @@ -90,29 +90,29 @@ namespace helper { ); if (not istream) { - return helper::nullopt; + return std::nullopt; } return utils::from_little_endian(value); } template - [[nodiscard]] helper::optional> read_array_from_istream(std::istream& istream) { + [[nodiscard]] std::optional> read_array_from_istream(std::istream& istream) { if (not istream) { - return helper::nullopt; + return std::nullopt; } std::array result{}; for (decltype(Size) i = 0; i < Size; ++i) { const auto read_data = read_from_istream(istream); if (not read_data.has_value()) { - return helper::nullopt; + return std::nullopt; } result.at(i) = read_data.value(); } if (not istream) { - return helper::nullopt; + return std::nullopt; } return result; diff --git a/src/recordings/meson.build b/src/libs/recordings/utility/meson.build similarity index 76% rename from src/recordings/meson.build rename to src/libs/recordings/utility/meson.build index b30b0833..c823aae2 100644 --- a/src/recordings/meson.build +++ b/src/libs/recordings/utility/meson.build @@ -13,9 +13,3 @@ recordings_src_files = files( 'tetrion_snapshot.cpp', 'tetrion_snapshot.hpp', ) - -subdir('executable') - -recordings_lib += { - 'inc_dirs': [recordings_lib.get('inc_dirs'), include_directories('.')], -} diff --git a/src/recordings/recording.cpp b/src/libs/recordings/utility/recording.cpp similarity index 98% rename from src/recordings/recording.cpp rename to src/libs/recordings/utility/recording.cpp index 53efdce5..7c621ac0 100644 --- a/src/recordings/recording.cpp +++ b/src/libs/recordings/utility/recording.cpp @@ -1,5 +1,6 @@ -#include "recording.hpp" +#include "./recording.hpp" + #include diff --git a/src/recordings/recording.hpp b/src/libs/recordings/utility/recording.hpp similarity index 90% rename from src/recordings/recording.hpp rename to src/libs/recordings/utility/recording.hpp index 191d240d..f010cffb 100644 --- a/src/recordings/recording.hpp +++ b/src/libs/recordings/utility/recording.hpp @@ -1,11 +1,11 @@ #pragma once +#include +#include +#include -#include "additional_information.hpp" -#include "checksum_helper.hpp" -#include "helper/random.hpp" -#include "helper/types.hpp" -#include "manager/input_event.hpp" +#include "./additional_information.hpp" +#include "./checksum_helper.hpp" #include #include diff --git a/src/recordings/recording_json_wrapper.hpp b/src/libs/recordings/utility/recording_json_wrapper.hpp similarity index 96% rename from src/recordings/recording_json_wrapper.hpp rename to src/libs/recordings/utility/recording_json_wrapper.hpp index f05e7938..2fdecca6 100644 --- a/src/recordings/recording_json_wrapper.hpp +++ b/src/libs/recordings/utility/recording_json_wrapper.hpp @@ -2,13 +2,13 @@ #pragma once -#include "additional_information.hpp" -#include "game/mino_stack.hpp" -#include "helper/magic_enum_wrapper.hpp" -#include "helper/parse_json.hpp" -#include "recording.hpp" -#include "recording_reader.hpp" -#include "tetrion_snapshot.hpp" +#include "./additional_information.hpp" +#include "./game/mino_stack.hpp" +#include "./helper/magic_enum_wrapper.hpp" +#include "./helper/parse_json.hpp" +#include "./recording.hpp" +#include "./recording_reader.hpp" +#include "./tetrion_snapshot.hpp" namespace nlohmann { template<> diff --git a/src/recordings/recording_reader.cpp b/src/libs/recordings/utility/recording_reader.cpp similarity index 98% rename from src/recordings/recording_reader.cpp rename to src/libs/recordings/utility/recording_reader.cpp index 1822f9b3..58f04d96 100644 --- a/src/recordings/recording_reader.cpp +++ b/src/libs/recordings/utility/recording_reader.cpp @@ -1,7 +1,8 @@ -#include "recording_reader.hpp" -#include "helper/magic_enum_wrapper.hpp" -#include "recordings/additional_information.hpp" +#include + +#include "./additional_information.hpp" +#include "./recording_reader.hpp" #include #include diff --git a/src/recordings/recording_reader.hpp b/src/libs/recordings/utility/recording_reader.hpp similarity index 94% rename from src/recordings/recording_reader.hpp rename to src/libs/recordings/utility/recording_reader.hpp index 1cc2bff9..a6cc6ca8 100644 --- a/src/recordings/recording_reader.hpp +++ b/src/libs/recordings/utility/recording_reader.hpp @@ -1,9 +1,9 @@ #pragma once -#include "helper.hpp" -#include "helper/optional.hpp" -#include "recording.hpp" -#include "tetrion_snapshot.hpp" +#include "./helper.hpp" + +#include "./recording.hpp" +#include "./tetrion_snapshot.hpp" #include diff --git a/src/recordings/recording_writer.cpp b/src/libs/recordings/utility/recording_writer.cpp similarity index 98% rename from src/recordings/recording_writer.cpp rename to src/libs/recordings/utility/recording_writer.cpp index b0ee8398..dc2686a3 100644 --- a/src/recordings/recording_writer.cpp +++ b/src/libs/recordings/utility/recording_writer.cpp @@ -1,6 +1,6 @@ -#include "recording_writer.hpp" -#include "recording.hpp" -#include "tetrion_snapshot.hpp" +#include "./recording_writer.hpp" +#include "./recording.hpp" +#include "./tetrion_snapshot.hpp" recorder::RecordingWriter::RecordingWriter( std::ofstream&& output_file, diff --git a/src/recordings/recording_writer.hpp b/src/libs/recordings/utility/recording_writer.hpp similarity index 91% rename from src/recordings/recording_writer.hpp rename to src/libs/recordings/utility/recording_writer.hpp index 90189720..5dcefdd4 100644 --- a/src/recordings/recording_writer.hpp +++ b/src/libs/recordings/utility/recording_writer.hpp @@ -1,10 +1,10 @@ #pragma once -#include "helper.hpp" -#include "helper/expected.hpp" -#include "recording.hpp" -#include "recordings/additional_information.hpp" -#include "tetrion_core_information.hpp" +#include "./helper.hpp" +#include +#include "./recording.hpp" +#include "./additional_information.hpp" +#include "./tetrion_core_information.hpp" #include diff --git a/src/recordings/tetrion_core_information.hpp b/src/libs/recordings/utility/tetrion_core_information.hpp similarity index 93% rename from src/recordings/tetrion_core_information.hpp rename to src/libs/recordings/utility/tetrion_core_information.hpp index a9384f50..f41a727a 100644 --- a/src/recordings/tetrion_core_information.hpp +++ b/src/libs/recordings/utility/tetrion_core_information.hpp @@ -1,7 +1,7 @@ #pragma once -#include "game/mino_stack.hpp" +#include struct TetrionCoreInformation { u8 tetrion_index; diff --git a/src/recordings/tetrion_snapshot.cpp b/src/libs/recordings/utility/tetrion_snapshot.cpp similarity index 97% rename from src/recordings/tetrion_snapshot.cpp rename to src/libs/recordings/utility/tetrion_snapshot.cpp index 8352d21c..cf284c14 100644 --- a/src/recordings/tetrion_snapshot.cpp +++ b/src/libs/recordings/utility/tetrion_snapshot.cpp @@ -1,8 +1,9 @@ -#include "tetrion_snapshot.hpp" -#include "helper.hpp" -#include "helper/expected.hpp" -#include "helper/magic_enum_wrapper.hpp" -#include "tetrion_core_information.hpp" +#include +#include + +#include "./helper.hpp" +#include "./tetrion_core_information.hpp" +#include "./tetrion_snapshot.hpp" #include #include diff --git a/src/recordings/tetrion_snapshot.hpp b/src/libs/recordings/utility/tetrion_snapshot.hpp similarity index 89% rename from src/recordings/tetrion_snapshot.hpp rename to src/libs/recordings/utility/tetrion_snapshot.hpp index 761df5fc..a8ee37cf 100644 --- a/src/recordings/tetrion_snapshot.hpp +++ b/src/libs/recordings/utility/tetrion_snapshot.hpp @@ -1,13 +1,12 @@ #pragma once -#include "game/mino_stack.hpp" -#include "helper/expected.hpp" -#include "helper/utils.hpp" -#include "tetrion_core_information.hpp" +#include +#include +#include + +#include "./tetrion_core_information.hpp" -#include #include -#include #include struct TetrionSnapshot final { diff --git a/src/lobby/types.hpp b/src/lobby/types.hpp index 08fefae2..41bd138a 100644 --- a/src/lobby/types.hpp +++ b/src/lobby/types.hpp @@ -3,7 +3,7 @@ #include -#include "helper/optional.hpp" + #include "helper/parse_json.hpp" namespace lobby { @@ -42,7 +42,7 @@ namespace lobby { int size; PlayerInfo host_info; std::vector player_infos; - helper::optional gameserver_port; + std::optional gameserver_port; }; diff --git a/src/manager/event_dispatcher.hpp b/src/manager/event_dispatcher.hpp index 66b245ad..2f00636e 100644 --- a/src/manager/event_dispatcher.hpp +++ b/src/manager/event_dispatcher.hpp @@ -1,7 +1,7 @@ #pragma once #include "graphics/rect.hpp" -#include "helper/optional.hpp" + #include "manager/event_listener.hpp" #include "sdl_key.hpp" @@ -76,7 +76,7 @@ struct EventDispatcher final { } } - void start_text_input(const helper::optional& rect) { + void start_text_input(const std::optional& rect) { if (m_input_activated) { return; } diff --git a/src/manager/meson.build b/src/manager/meson.build index fd1240c0..8258817b 100644 --- a/src/manager/meson.build +++ b/src/manager/meson.build @@ -3,7 +3,6 @@ graphics_src_files += files( 'event_listener.hpp', 'font.cpp', 'font.hpp', - 'input_event.hpp', 'music_manager.cpp', 'music_manager.hpp', 'sdl_controller_key.cpp', diff --git a/src/manager/music_manager.cpp b/src/manager/music_manager.cpp index a60ca0a6..f10184f2 100644 --- a/src/manager/music_manager.cpp +++ b/src/manager/music_manager.cpp @@ -2,7 +2,7 @@ #include "helper/command_line_arguments.hpp" #include "helper/constants.hpp" #include "helper/errors.hpp" -#include "helper/optional.hpp" + #include "helper/types.hpp" #include "manager/sdl_key.hpp" @@ -20,7 +20,7 @@ MusicManager::MusicManager(ServiceProvider* service_provider, u8 channel_size) m_channel_size{ channel_size }, m_chunk_map{ std::unordered_map{} }, m_service_provider{ service_provider }, - volume{ m_service_provider->command_line_arguments().silent ? helper::nullopt : std::optional{ 1.0F } } { + volume{ m_service_provider->command_line_arguments().silent ? std::nullopt : std::optional{ 1.0F } } { if (s_instance != nullptr) { spdlog::error("it's not allowed to create more than one MusicManager instance"); return; @@ -83,10 +83,9 @@ MusicManager::~MusicManager() noexcept { Mix_Quit(); } -helper::optional -MusicManager::load_and_play_music(const std::filesystem::path& location, const usize delay) { +std::optional MusicManager::load_and_play_music(const std::filesystem::path& location, const usize delay) { if (not validate_instance()) { - return helper::nullopt; + return std::nullopt; } Mix_Music* music = Mix_LoadMUS(location.string().c_str()); @@ -102,7 +101,7 @@ MusicManager::load_and_play_music(const std::filesystem::path& location, const u Mix_FreeMusic(m_music); } m_music = music; - return helper::nullopt; + return std::nullopt; } @@ -128,7 +127,7 @@ MusicManager::load_and_play_music(const std::filesystem::path& location, const u return ("an error occurred while trying to play the music: " + std::string{ Mix_GetError() }); } - return helper::nullopt; + return std::nullopt; } @@ -151,7 +150,7 @@ MusicManager::load_and_play_music(const std::filesystem::path& location, const u if (result == 0) { return "UNREACHABLE: m_music was not null but not playing, this is an implementation error!"; } - return helper::nullopt; + return std::nullopt; } const int result = Mix_PlayMusic(music, -1); @@ -159,13 +158,13 @@ MusicManager::load_and_play_music(const std::filesystem::path& location, const u return ("an error occurred while trying to play the music: " + std::string{ Mix_GetError() }); } - return helper::nullopt; + return std::nullopt; } -helper::optional MusicManager::load_effect(const std::string& name, std::filesystem::path& location) { +std::optional MusicManager::load_effect(const std::string& name, std::filesystem::path& location) { if (not validate_instance()) { - return helper::nullopt; + return std::nullopt; } if (m_chunk_map.contains(name)) { @@ -178,12 +177,12 @@ helper::optional MusicManager::load_effect(const std::string& name, } m_chunk_map.insert({ name, chunk }); - return helper::nullopt; + return std::nullopt; } -helper::optional MusicManager::play_effect(const std::string& name, u8 channel_num, int loop) { +std::optional MusicManager::play_effect(const std::string& name, u8 channel_num, int loop) { if (not validate_instance()) { - return helper::nullopt; + return std::nullopt; } if (m_chunk_map.contains(name)) { @@ -201,7 +200,7 @@ helper::optional MusicManager::play_effect(const std::string& name, return "couldn't play on channel: " + std::to_string(channel_num); } - return helper::nullopt; + return std::nullopt; } void MusicManager::hook_music_finished() { @@ -240,11 +239,11 @@ void MusicManager::hook_music_finished() { } -[[nodiscard]] helper::optional MusicManager::get_volume() const { +[[nodiscard]] std::optional MusicManager::get_volume() const { #if !defined(NDEBUG) int result = Mix_VolumeMusic(-1); if (result == 0) { - return helper::nullopt; + return std::nullopt; } return static_cast(result) / MIX_MAX_VOLUME; @@ -254,7 +253,7 @@ void MusicManager::hook_music_finished() { } void MusicManager::set_volume( - const helper::optional new_volume, + const std::optional new_volume, const bool force_update, const bool notify_listeners ) { @@ -269,7 +268,7 @@ void MusicManager::set_volume( Mix_HaltMusic(); } - volume = helper::nullopt; + volume = std::nullopt; } @@ -298,14 +297,14 @@ void MusicManager::set_volume( } } -helper::optional MusicManager::change_volume(const std::int8_t steps) { +std::optional MusicManager::change_volume(const std::int8_t steps) { const auto current_volume = get_volume(); if (steps == 0) { return current_volume; } - helper::optional new_volume = current_volume; + std::optional new_volume = current_volume; if (steps > 0) { @@ -330,18 +329,18 @@ helper::optional MusicManager::change_volume(const std::int8_t steps) { if (not current_volume.has_value()) { - return helper::nullopt; + return std::nullopt; } if (current_volume <= 0.0F) { - new_volume = helper::nullopt; + new_volume = std::nullopt; } else { new_volume = current_volume.value() + MusicManager::step_width * static_cast(steps); if (new_volume <= 0.0F) { - new_volume = helper::nullopt; + new_volume = std::nullopt; } } } diff --git a/src/manager/music_manager.hpp b/src/manager/music_manager.hpp index 496ee7bb..78a4dc36 100644 --- a/src/manager/music_manager.hpp +++ b/src/manager/music_manager.hpp @@ -1,6 +1,6 @@ #pragma once -#include "helper/optional.hpp" + #include "helper/types.hpp" #include "input/input.hpp" #include "manager/service_provider.hpp" @@ -21,7 +21,7 @@ struct MusicManager final { static inline MusicManager* s_instance{ nullptr }; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) static const constexpr double step_width = 0.05F; - using VolumeChangeFunction = std::function volume)>; + using VolumeChangeFunction = std::function volume)>; Mix_Music* m_music; std::atomic m_queued_music; @@ -30,7 +30,7 @@ struct MusicManager final { static constexpr unsigned fade_ms = 500; usize m_delay = MusicManager::fade_ms; ServiceProvider* m_service_provider; - helper::optional volume; + std::optional volume; std::unordered_map volume_listeners; public: @@ -41,17 +41,17 @@ struct MusicManager final { MusicManager& operator=(MusicManager&&) = delete; ~MusicManager() noexcept; - helper::optional + std::optional load_and_play_music(const std::filesystem::path& location, usize delay = MusicManager::fade_ms); - helper::optional load_effect(const std::string& name, std::filesystem::path& location); - helper::optional play_effect(const std::string& name, u8 channel_num = 1, int loop = 0); + std::optional load_effect(const std::string& name, std::filesystem::path& location); + std::optional play_effect(const std::string& name, u8 channel_num = 1, int loop = 0); //TODO(Totto): atm the volume changers only work on the music channel, when adding more effects, this should support channels via https://wiki.libsdl.org/SDL2_mixer/Mix_Volume - [[nodiscard]] helper::optional get_volume() const; - void set_volume(helper::optional new_volume, bool force_update = false, bool notify_listeners = true); + [[nodiscard]] std::optional get_volume() const; + void set_volume(std::optional new_volume, bool force_update = false, bool notify_listeners = true); // no nodiscard, since the return value is only a side effect, that is maybe useful - helper::optional change_volume(std::int8_t steps); + std::optional change_volume(std::int8_t steps); bool handle_event(const std::shared_ptr& input_manager, const SDL_Event& event); diff --git a/src/manager/sdl_key.cpp b/src/manager/sdl_key.cpp index c0ead7ef..ed4a4457 100644 --- a/src/manager/sdl_key.cpp +++ b/src/manager/sdl_key.cpp @@ -1,6 +1,6 @@ #include "sdl_key.hpp" -#include "helper/optional.hpp" + #include "helper/string_manipulation.hpp" #include "helper/utils.hpp" @@ -223,10 +223,10 @@ namespace { } - helper::optional modifier_from_string(const std::string& modifier) { + std::optional modifier_from_string(const std::string& modifier) { if (modifier.empty()) { - return helper::nullopt; + return std::nullopt; } const auto lower_case = string::to_lower_case(modifier); @@ -255,7 +255,7 @@ namespace { return map.at(lower_case); } - return helper::nullopt; + return std::nullopt; } } // namespace diff --git a/src/manager/service_provider.hpp b/src/manager/service_provider.hpp index 44160039..e72ff38a 100644 --- a/src/manager/service_provider.hpp +++ b/src/manager/service_provider.hpp @@ -6,7 +6,7 @@ #if defined(_HAVE_DISCORD_SDK) && !defined(_OOPETRIS_RECORDING_UTILITY) #include "discord/core.hpp" -#include "helper/optional.hpp" + #endif @@ -55,8 +55,8 @@ struct ServiceProvider { #if defined(_HAVE_DISCORD_SDK) && !defined(_OOPETRIS_RECORDING_UTILITY) - [[nodiscard]] virtual helper::optional& discord_instance() = 0; - [[nodiscard]] virtual const helper::optional& discord_instance() const = 0; + [[nodiscard]] virtual std::optional& discord_instance() = 0; + [[nodiscard]] virtual const std::optional& discord_instance() const = 0; #endif }; diff --git a/src/manager/settings_manager.cpp b/src/manager/settings_manager.cpp index 0ec6caee..ff1d99ad 100644 --- a/src/manager/settings_manager.cpp +++ b/src/manager/settings_manager.cpp @@ -18,7 +18,7 @@ SettingsManager::SettingsManager(ServiceProvider* service_provider) : m_service_ spdlog::warn("applying default settings"); m_settings = { - detail::Settings{ {}, helper::nullopt, 1.0, false } + detail::Settings{ {}, std::nullopt, 1.0, false } }; } } diff --git a/src/manager/settings_manager.hpp b/src/manager/settings_manager.hpp index e1da0be2..3d84765f 100644 --- a/src/manager/settings_manager.hpp +++ b/src/manager/settings_manager.hpp @@ -1,6 +1,6 @@ #pragma once -#include "helper/optional.hpp" + #include "input/controller_input.hpp" #include "input/joystick_input.hpp" #include "input/keyboard_input.hpp" @@ -71,7 +71,7 @@ namespace detail { struct Settings { std::vector controls; - helper::optional selected; + std::optional selected; float volume{ 0.2F }; bool discord{ false }; //changing this requires a restart }; diff --git a/src/meson.build b/src/meson.build index 7db1ed8c..86650198 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,117 +1,54 @@ -core_src_files = [] -recordings_src_files = [] -graphics_src_files = [] +subdir('libs') + +if build_application + + graphics_src_files = [] + + subdir('game') + subdir('graphics') + subdir('helper') + subdir('input') + subdir('manager') + subdir('scenes') + subdir('ui') + + if online_multiplayer_supported + subdir('lobby') + endif + + if have_discord_sdk + subdir('discord') + endif + + graphics_lib += { + 'deps': [graphics_lib.get('deps'), liboopetris_recordings_dep], + 'inc_dirs': [graphics_lib.get('inc_dirs'), include_directories('.')], + } + + liboopetris_graphics = library( + 'oopetris_graphics', + graphics_src_files, + include_directories: graphics_lib.get('inc_dirs'), + dependencies: graphics_lib.get('deps'), + cpp_args: graphics_lib.get('compile_args'), + override_options: { + 'warning_level': '3', + 'werror': true, + }, + version: meson.project_version(), + install: true, + ) + + liboopetris_graphics_dep = declare_dependency( + link_with: liboopetris_graphics, + include_directories: graphics_lib.get('inc_dirs'), + compile_args: graphics_lib.get('compile_args'), + dependencies: graphics_lib.get('deps'), + version: meson.project_version(), + ) + meson.override_dependency('liboopetris-graphics', liboopetris_graphics_dep) + + # setting this to strings, so += {...} gets detected as an error, if it is done after that + graphics_lib = 'undefined' -graphics_src_files += files( - 'application.cpp', - 'application.hpp', -) - -main_files = files( - 'main.cpp', -) - -subdir('game') -subdir('graphics') -subdir('helper') -subdir('input') -subdir('manager') -subdir('recordings') -subdir('scenes') -subdir('thirdparty') -subdir('ui') - -if online_multiplayer_supported - subdir('lobby') -endif - -if have_discord_sdk - subdir('discord') endif - -core_lib += { - 'inc_dirs': [core_lib.get('inc_dirs'), include_directories('.')], - 'deps': [core_lib.get('deps'), global_deps], -} - -liboopetris_core = library( - 'oopetris_core', - core_src_files, - include_directories: core_lib.get('inc_dirs'), - dependencies: core_lib.get('deps'), - cpp_args: core_lib.get('compile_args'), - override_options: { - 'warning_level': '3', - 'werror': true, - }, - version: meson.project_version(), - install: true, -) - -liboopetris_core_dep = declare_dependency( - link_with: liboopetris_core, - include_directories: core_lib.get('inc_dirs'), - compile_args: core_lib.get('compile_args'), - dependencies: core_lib.get('deps'), - version: meson.project_version(), -) -meson.override_dependency('liboopetris-core', liboopetris_core_dep) - -recordings_lib += { - 'deps': [recordings_lib.get('deps'), liboopetris_core_dep, global_deps], -} - -liboopetris_recordings = library( - 'oopetris_recordings', - recordings_src_files, - include_directories: recordings_lib.get('inc_dirs'), - dependencies: recordings_lib.get('deps'), - cpp_args: recordings_lib.get('compile_args'), - override_options: { - 'warning_level': '3', - 'werror': true, - }, - version: meson.project_version(), - install: true, -) - -liboopetris_recordings_dep = declare_dependency( - link_with: liboopetris_recordings, - include_directories: recordings_lib.get('inc_dirs'), - compile_args: recordings_lib.get('compile_args'), - dependencies: recordings_lib.get('deps'), - version: meson.project_version(), -) -meson.override_dependency('liboopetris-recordings', liboopetris_recordings_dep) - -graphics_lib += { - 'deps': [graphics_lib.get('deps'), liboopetris_recordings_dep, global_deps], -} - -liboopetris_graphics = library( - 'oopetris_graphics', - graphics_src_files, - include_directories: graphics_lib.get('inc_dirs'), - dependencies: graphics_lib.get('deps'), - cpp_args: graphics_lib.get('compile_args'), - override_options: { - 'warning_level': '3', - 'werror': true, - }, - version: meson.project_version(), - install: true, -) - -liboopetris_graphics_dep = declare_dependency( - link_with: liboopetris_graphics, - include_directories: graphics_lib.get('inc_dirs'), - compile_args: graphics_lib.get('compile_args'), - dependencies: graphics_lib.get('deps'), - version: meson.project_version(), -) -meson.override_dependency('liboopetris-graphics', liboopetris_graphics_dep) - -# setting this to strings, so += {...} gets detected as an error, if it is done after that -core_lib = 'undefined' -recordings_lib = 'undefined' -graphics_lib = 'undefined' diff --git a/src/recordings/executable/meson.build b/src/recordings/executable/meson.build deleted file mode 100644 index 79c61ea0..00000000 --- a/src/recordings/executable/meson.build +++ /dev/null @@ -1,3 +0,0 @@ - -recordings_main_files = files('main.cpp') - diff --git a/src/scenes/about_page/about_page.cpp b/src/scenes/about_page/about_page.cpp index e7fea40d..b76333fd 100644 --- a/src/scenes/about_page/about_page.cpp +++ b/src/scenes/about_page/about_page.cpp @@ -91,7 +91,7 @@ namespace scenes { if (m_should_exit) { return UpdateResult{ SceneUpdate::StopUpdating, Scene::Pop{} }; } - return UpdateResult{ SceneUpdate::StopUpdating, helper::nullopt }; + return UpdateResult{ SceneUpdate::StopUpdating, std::nullopt }; } void AboutPage::render(const ServiceProvider& service_provider) { diff --git a/src/scenes/main_menu/main_menu.cpp b/src/scenes/main_menu/main_menu.cpp index 144ac6f3..41d3440e 100644 --- a/src/scenes/main_menu/main_menu.cpp +++ b/src/scenes/main_menu/main_menu.cpp @@ -111,28 +111,28 @@ namespace scenes { switch (m_next_command.value()) { case Command::OpenPlaySelection: // perform a push and reset the command, so that the music keeps playing the entire time - m_next_command = helper::nullopt; + m_next_command = std::nullopt; return UpdateResult{ SceneUpdate::StopUpdating, Scene::Push{ SceneId::PlaySelectMenu, ui::FullScreenLayout{ m_service_provider->window() } } }; case Command::OpenAboutPage: // perform a push and reset the command, so that the music keeps playing the entire time - m_next_command = helper::nullopt; + m_next_command = std::nullopt; return UpdateResult{ SceneUpdate::StopUpdating, Scene::Push{ SceneId::AboutPage, ui::FullScreenLayout{ m_service_provider->window() } } }; case Command::OpenSettingsMenu: // perform a push and reset the command, so that the music keeps playing the entire time - m_next_command = helper::nullopt; + m_next_command = std::nullopt; return UpdateResult{ SceneUpdate::StopUpdating, Scene::Push{ SceneId::SettingsMenu, ui::FullScreenLayout{ m_service_provider->window() } } }; case Command::OpenAchievements: // perform a push and reset the command, so that the music keeps playing the entire time - m_next_command = helper::nullopt; + m_next_command = std::nullopt; return UpdateResult{ SceneUpdate::StopUpdating, Scene::Push{ SceneId::AchievementsPage, ui::FullScreenLayout{ m_service_provider->window() } } @@ -143,7 +143,7 @@ namespace scenes { UNREACHABLE(); } } - return UpdateResult{ SceneUpdate::StopUpdating, helper::nullopt }; + return UpdateResult{ SceneUpdate::StopUpdating, std::nullopt }; } void MainMenu::render(const ServiceProvider& service_provider) { diff --git a/src/scenes/main_menu/main_menu.hpp b/src/scenes/main_menu/main_menu.hpp index c513ab10..7e9fc2a1 100644 --- a/src/scenes/main_menu/main_menu.hpp +++ b/src/scenes/main_menu/main_menu.hpp @@ -18,7 +18,7 @@ namespace scenes { }; ui::GridLayout m_main_grid; - helper::optional m_next_command; + std::optional m_next_command; public: explicit MainMenu(ServiceProvider* service_provider, const ui::Layout& layout); diff --git a/src/scenes/multiplayer_menu/multiplayer_menu.cpp b/src/scenes/multiplayer_menu/multiplayer_menu.cpp index 49f36442..c4852bde 100644 --- a/src/scenes/multiplayer_menu/multiplayer_menu.cpp +++ b/src/scenes/multiplayer_menu/multiplayer_menu.cpp @@ -92,7 +92,7 @@ namespace scenes { }; case Command::OnlineMultiPlayer: // perform a push and reset the command, so that the music keeps playing the entire time - m_next_command = helper::nullopt; + m_next_command = std::nullopt; return UpdateResult{ SceneUpdate::StopUpdating, Scene::Push{ SceneId::OnlineLobby, ui::FullScreenLayout{ m_service_provider->window() } } @@ -108,7 +108,7 @@ namespace scenes { UNREACHABLE(); } } - return UpdateResult{ SceneUpdate::StopUpdating, helper::nullopt }; + return UpdateResult{ SceneUpdate::StopUpdating, std::nullopt }; } void MultiPlayerMenu::render(const ServiceProvider& service_provider) { diff --git a/src/scenes/multiplayer_menu/multiplayer_menu.hpp b/src/scenes/multiplayer_menu/multiplayer_menu.hpp index b498b418..68f4fdbe 100644 --- a/src/scenes/multiplayer_menu/multiplayer_menu.hpp +++ b/src/scenes/multiplayer_menu/multiplayer_menu.hpp @@ -12,7 +12,7 @@ namespace scenes { enum class Command : u8 { LocalMultiPlayer, OnlineMultiPlayer, AIMultiPlayer, Return }; ui::GridLayout m_main_grid; - helper::optional m_next_command; + std::optional m_next_command; public: explicit MultiPlayerMenu(ServiceProvider* service_provider, const ui::Layout& layout); diff --git a/src/scenes/online_lobby/online_lobby.cpp b/src/scenes/online_lobby/online_lobby.cpp index 8ade0c8b..34340e3c 100644 --- a/src/scenes/online_lobby/online_lobby.cpp +++ b/src/scenes/online_lobby/online_lobby.cpp @@ -109,7 +109,7 @@ namespace scenes { UNREACHABLE(); } } - return UpdateResult{ SceneUpdate::StopUpdating, helper::nullopt }; + return UpdateResult{ SceneUpdate::StopUpdating, std::nullopt }; } void OnlineLobby::render(const ServiceProvider& service_provider) { diff --git a/src/scenes/online_lobby/online_lobby.hpp b/src/scenes/online_lobby/online_lobby.hpp index e391bc3a..b266313e 100644 --- a/src/scenes/online_lobby/online_lobby.hpp +++ b/src/scenes/online_lobby/online_lobby.hpp @@ -15,7 +15,7 @@ namespace scenes { enum class Command : u8 { Play, Return }; ui::TileLayout m_main_layout; - helper::optional m_next_command; + std::optional m_next_command; std::unique_ptr client{ nullptr }; public: diff --git a/src/scenes/play_select_menu/play_select_menu.cpp b/src/scenes/play_select_menu/play_select_menu.cpp index ac1f8b91..b6c26b5b 100644 --- a/src/scenes/play_select_menu/play_select_menu.cpp +++ b/src/scenes/play_select_menu/play_select_menu.cpp @@ -78,21 +78,21 @@ namespace scenes { if (m_next_command.has_value()) { switch (m_next_command.value()) { case Command::SinglePlayer: - m_next_command = helper::nullopt; + m_next_command = std::nullopt; return UpdateResult{ SceneUpdate::StopUpdating, Scene::Switch{ SceneId::SinglePlayerGame, ui::FullScreenLayout{ m_service_provider->window() } } }; case Command::MultiPlayer: // perform a push and reset the command, so that the music keeps playing the entire time - m_next_command = helper::nullopt; + m_next_command = std::nullopt; return UpdateResult{ SceneUpdate::StopUpdating, Scene::Push{ SceneId::MultiPlayerModeSelectMenu, ui::FullScreenLayout{ m_service_provider->window() } } }; case Command::RecordingSelector: // perform a push and reset the command, so that the music keeps playing the entire time - m_next_command = helper::nullopt; + m_next_command = std::nullopt; return UpdateResult{ SceneUpdate::StopUpdating, Scene::Push{ SceneId::RecordingSelectorMenu, ui::FullScreenLayout{ m_service_provider->window() } } @@ -103,7 +103,7 @@ namespace scenes { UNREACHABLE(); } } - return UpdateResult{ SceneUpdate::StopUpdating, helper::nullopt }; + return UpdateResult{ SceneUpdate::StopUpdating, std::nullopt }; } void PlaySelectMenu::render(const ServiceProvider& service_provider) { diff --git a/src/scenes/play_select_menu/play_select_menu.hpp b/src/scenes/play_select_menu/play_select_menu.hpp index b362dd52..ad5bb577 100644 --- a/src/scenes/play_select_menu/play_select_menu.hpp +++ b/src/scenes/play_select_menu/play_select_menu.hpp @@ -12,7 +12,7 @@ namespace scenes { enum class Command : u8 { SinglePlayer, MultiPlayer, RecordingSelector, Return }; ui::GridLayout m_main_grid; - helper::optional m_next_command; + std::optional m_next_command; public: explicit PlaySelectMenu(ServiceProvider* service_provider, const ui::Layout& layout); diff --git a/src/scenes/recording_selector/recording_selector.cpp b/src/scenes/recording_selector/recording_selector.cpp index 17c63795..148e9fe5 100644 --- a/src/scenes/recording_selector/recording_selector.cpp +++ b/src/scenes/recording_selector/recording_selector.cpp @@ -8,7 +8,7 @@ #include "graphics/window.hpp" #include "helper/constants.hpp" -#include "helper/optional.hpp" + #include "manager/resource_manager.hpp" #include "recording_component.hpp" #include "recording_selector.hpp" @@ -87,7 +87,7 @@ namespace scenes { const auto recording_path = recording_component.value()->metadata().path; // action is a reference to a structure inside m_next_command, so resetting it means, we need to copy everything out of it - m_next_command = helper::nullopt; + m_next_command = std::nullopt; return UpdateResult{ SceneUpdate::StopUpdating, @@ -111,9 +111,9 @@ namespace scenes { add_all_recordings(); // action is a reference to a structure inside m_next_command, so resetting it means, we need to copy everything out of it - m_next_command = helper::nullopt; + m_next_command = std::nullopt; - return UpdateResult{ SceneUpdate::StopUpdating, helper::nullopt }; + return UpdateResult{ SceneUpdate::StopUpdating, std::nullopt }; } #endif @@ -123,7 +123,7 @@ namespace scenes { ); } - return UpdateResult{ SceneUpdate::StopUpdating, helper::nullopt }; + return UpdateResult{ SceneUpdate::StopUpdating, std::nullopt }; } void RecordingSelector::render(const ServiceProvider& service_provider) { diff --git a/src/scenes/recording_selector/recording_selector.hpp b/src/scenes/recording_selector/recording_selector.hpp index dcdd40c6..51bc8484 100644 --- a/src/scenes/recording_selector/recording_selector.hpp +++ b/src/scenes/recording_selector/recording_selector.hpp @@ -33,7 +33,7 @@ namespace scenes { struct RecordingSelector : public Scene { private: ui::TileLayout m_main_layout; - helper::optional m_next_command{ helper::nullopt }; + std::optional m_next_command{ std::nullopt }; std::vector m_chosen_paths{}; public: diff --git a/src/scenes/replay_game/replay_game.cpp b/src/scenes/replay_game/replay_game.cpp index 8680a559..c649ea15 100644 --- a/src/scenes/replay_game/replay_game.cpp +++ b/src/scenes/replay_game/replay_game.cpp @@ -97,7 +97,7 @@ namespace scenes { if (m_next_scene.has_value()) { const auto next_scene = m_next_scene.value(); - m_next_scene = helper::nullopt; + m_next_scene = std::nullopt; for (auto& game : m_games) { game->set_paused(true); } @@ -122,7 +122,7 @@ namespace scenes { UNREACHABLE(); } } - return UpdateResult{ SceneUpdate::StopUpdating, helper::nullopt }; + return UpdateResult{ SceneUpdate::StopUpdating, std::nullopt }; } void ReplayGame::render(const ServiceProvider& service_provider) { diff --git a/src/scenes/replay_game/replay_game.hpp b/src/scenes/replay_game/replay_game.hpp index 0c6ad5cb..cd671b39 100644 --- a/src/scenes/replay_game/replay_game.hpp +++ b/src/scenes/replay_game/replay_game.hpp @@ -10,7 +10,7 @@ namespace scenes { enum class NextScene : u8 { Pause, Settings }; - helper::optional m_next_scene{}; + std::optional m_next_scene{}; std::vector> m_games; public: diff --git a/src/scenes/scene.hpp b/src/scenes/scene.hpp index 5f2b4ed4..f1e3c410 100644 --- a/src/scenes/scene.hpp +++ b/src/scenes/scene.hpp @@ -59,7 +59,7 @@ namespace scenes { struct Exit { }; using Change = std::variant; - using UpdateResult = std::pair>; + using UpdateResult = std::pair>; protected: ServiceProvider* m_service_provider; diff --git a/src/scenes/settings_menu/color_setting_row.cpp b/src/scenes/settings_menu/color_setting_row.cpp index c4cec4f9..be326e15 100644 --- a/src/scenes/settings_menu/color_setting_row.cpp +++ b/src/scenes/settings_menu/color_setting_row.cpp @@ -97,7 +97,7 @@ detail::ColorPickerScene::ColorPickerScene( if (m_should_exit) { return UpdateResult{ scenes::SceneUpdate::StopUpdating, Scene::Pop{} }; } - return UpdateResult{ scenes::SceneUpdate::StopUpdating, helper::nullopt }; + return UpdateResult{ scenes::SceneUpdate::StopUpdating, std::nullopt }; } void detail::ColorPickerScene::render(const ServiceProvider& service_provider) { diff --git a/src/scenes/settings_menu/settings_menu.cpp b/src/scenes/settings_menu/settings_menu.cpp index f3f35b8b..4780dc43 100644 --- a/src/scenes/settings_menu/settings_menu.cpp +++ b/src/scenes/settings_menu/settings_menu.cpp @@ -1,7 +1,7 @@ #include "settings_menu.hpp" #include "color_setting_row.hpp" #include "helper/color_literals.hpp" -#include "helper/optional.hpp" + #include "helper/utils.hpp" #include "manager/music_manager.hpp" #include "manager/resource_manager.hpp" @@ -18,17 +18,16 @@ namespace scenes { using namespace details::settings::menu; SettingsMenu::SettingsMenu(ServiceProvider* service_provider, const ui::Layout& layout) - : SettingsMenu{ service_provider, layout, helper::nullopt } { } + : SettingsMenu{ service_provider, layout, std::nullopt } { } SettingsMenu::SettingsMenu( ServiceProvider* service_provider, const ui::Layout& layout, const std::shared_ptr& game_input ) - : SettingsMenu{ service_provider, layout, helper::optional>{ game_input } } { - } + : SettingsMenu{ service_provider, layout, std::optional>{ game_input } } { } - SettingsMenu::SettingsMenu(ServiceProvider* service_provider, const ui::Layout& layout, const helper::optional>& game_input) : Scene{service_provider, layout} + SettingsMenu::SettingsMenu(ServiceProvider* service_provider, const ui::Layout& layout, const std::optional>& game_input) : Scene{service_provider, layout} , m_main_layout{ utils::size_t_identity<3>(), 0, ui::Direction::Vertical, @@ -70,7 +69,7 @@ namespace scenes { return value.has_value() ? value.value() : 0.0F; }, [service_provider](double amount) { - const auto mapped_amount = amount <= 0.0F ? helper::nullopt : helper::optional{ amount }; + const auto mapped_amount = amount <= 0.0F ? std::nullopt : std::optional{ amount }; service_provider->music_manager().set_volume(mapped_amount, false, false); }, 0.05F, std::pair{ 0.6, 1.0 }, @@ -79,7 +78,7 @@ namespace scenes { service_provider->music_manager().add_volume_listener( listener_name, - [this, scroll_layout_index, slider_index](helper::optional) { + [this, scroll_layout_index, slider_index](std::optional) { auto* scroll_layout = this->m_main_layout.get(scroll_layout_index); scroll_layout->get(slider_index)->on_change(); } @@ -136,7 +135,7 @@ namespace scenes { auto change_scene = settings_details.value()->get_details_scene(); // action is a reference to a structure inside m_next_command, so resetting it means, we need to copy everything out of it - m_next_command = helper::nullopt; + m_next_command = std::nullopt; return UpdateResult{ SceneUpdate::StopUpdating, std::move(change_scene) }; } @@ -148,7 +147,7 @@ namespace scenes { ); } - return UpdateResult{ SceneUpdate::StopUpdating, helper::nullopt }; + return UpdateResult{ SceneUpdate::StopUpdating, std::nullopt }; } void SettingsMenu::render(const ServiceProvider& service_provider) { diff --git a/src/scenes/settings_menu/settings_menu.hpp b/src/scenes/settings_menu/settings_menu.hpp index 80b52ed4..1f5e7e65 100644 --- a/src/scenes/settings_menu/settings_menu.hpp +++ b/src/scenes/settings_menu/settings_menu.hpp @@ -32,18 +32,18 @@ namespace scenes { struct SettingsMenu : public Scene { private: - helper::optional m_next_command{ helper::nullopt }; + std::optional m_next_command{ std::nullopt }; ui::TileLayout m_main_layout; //todo migrate to settings state std::vector m_colors; - helper::optional> m_game_input; + std::optional> m_game_input; const std::string listener_name = "settings_menu"; explicit SettingsMenu( ServiceProvider* service_provider, const ui::Layout& layout, - const helper::optional>& game_input + const std::optional>& game_input ); public: diff --git a/src/scenes/single_player_game/game_over.cpp b/src/scenes/single_player_game/game_over.cpp index 7b8c1e67..44f8ab1e 100644 --- a/src/scenes/single_player_game/game_over.cpp +++ b/src/scenes/single_player_game/game_over.cpp @@ -41,7 +41,7 @@ namespace scenes { Scene::Switch{ SceneId::MainMenu, ui::FullScreenLayout{ m_service_provider->window() } } }; } - return UpdateResult{ SceneUpdate::StopUpdating, helper::nullopt }; + return UpdateResult{ SceneUpdate::StopUpdating, std::nullopt }; } void SinglePlayerGameOver::render(const ServiceProvider& service_provider) { diff --git a/src/scenes/single_player_game/pause.cpp b/src/scenes/single_player_game/pause.cpp index 59694e87..54c1cbde 100644 --- a/src/scenes/single_player_game/pause.cpp +++ b/src/scenes/single_player_game/pause.cpp @@ -35,7 +35,7 @@ namespace scenes { Scene::Switch{ SceneId::MainMenu, ui::FullScreenLayout{ m_service_provider->window() } } }; } - return UpdateResult{ SceneUpdate::StopUpdating, helper::nullopt }; + return UpdateResult{ SceneUpdate::StopUpdating, std::nullopt }; } void SinglePlayerPause::render(const ServiceProvider& service_provider) { diff --git a/src/scenes/single_player_game/single_player_game.cpp b/src/scenes/single_player_game/single_player_game.cpp index 3c7de69c..605ddd01 100644 --- a/src/scenes/single_player_game/single_player_game.cpp +++ b/src/scenes/single_player_game/single_player_game.cpp @@ -81,7 +81,7 @@ namespace scenes { if (m_next_scene.has_value()) { const auto next_scene = m_next_scene.value(); - m_next_scene = helper::nullopt; + m_next_scene = std::nullopt; m_game->set_paused(true); switch (next_scene) { @@ -108,7 +108,7 @@ namespace scenes { UNREACHABLE(); } } - return UpdateResult{ SceneUpdate::StopUpdating, helper::nullopt }; + return UpdateResult{ SceneUpdate::StopUpdating, std::nullopt }; } void SinglePlayerGame::render(const ServiceProvider& service_provider) { diff --git a/src/scenes/single_player_game/single_player_game.hpp b/src/scenes/single_player_game/single_player_game.hpp index 254205c3..39ef31b2 100644 --- a/src/scenes/single_player_game/single_player_game.hpp +++ b/src/scenes/single_player_game/single_player_game.hpp @@ -11,7 +11,7 @@ namespace scenes { enum class NextScene : u8 { Pause, Settings }; - helper::optional m_next_scene{}; + std::optional m_next_scene{}; std::unique_ptr m_game; public: diff --git a/src/thirdparty/hash-library/meson.build b/src/thirdparty/hash-library/meson.build deleted file mode 100644 index a9f518dd..00000000 --- a/src/thirdparty/hash-library/meson.build +++ /dev/null @@ -1,10 +0,0 @@ -core_src_files += files( - 'sha256.cpp', - 'sha256.h', -) - - -core_lib += { - 'inc_dirs': [core_lib.get('inc_dirs'), include_directories('.')], -} - diff --git a/src/thirdparty/meson.build b/src/thirdparty/meson.build deleted file mode 100644 index 75d9d183..00000000 --- a/src/thirdparty/meson.build +++ /dev/null @@ -1,4 +0,0 @@ - - -subdir('hash-library') - diff --git a/src/ui/layouts/focus_layout.cpp b/src/ui/layouts/focus_layout.cpp index a7707994..55db9e98 100644 --- a/src/ui/layouts/focus_layout.cpp +++ b/src/ui/layouts/focus_layout.cpp @@ -1,6 +1,6 @@ #include "focus_layout.hpp" -#include "helper/optional.hpp" + #include "input/input.hpp" #include "ui/widget.hpp" @@ -127,11 +127,11 @@ ui::Widget::EventHandleResult ui::FocusLayout::handle_focus_change_events( return handled; } -[[nodiscard]] helper::optional -ui::FocusLayout::handle_event_result(const helper::optional& result, Widget* widget) { +[[nodiscard]] std::optional +ui::FocusLayout::handle_event_result(const std::optional& result, Widget* widget) { if (not result.has_value()) { - return helper::nullopt; + return std::nullopt; } auto value = result.value(); @@ -144,13 +144,13 @@ ui::FocusLayout::handle_event_result(const helper::optionalfocus_id(); if (m_focus_id.value() == widget_focus_id) { - return helper::nullopt; + return std::nullopt; } auto current_focusable = as_focusable(m_widgets.at(focusable_index_by_id(m_focus_id.value())).get()); @@ -165,11 +165,11 @@ ui::FocusLayout::handle_event_result(const helper::optionalfocus_id(); if (m_focus_id.value() != widget_focus_id) { - return helper::nullopt; + return std::nullopt; } // try to unfocus, in forward direction, if that fails request unfocus of they container / layout itself, also test backwards, if not wrapping! @@ -201,7 +201,7 @@ ui::FocusLayout::handle_event_result(const helper::optional m_focus_id{}; + std::optional m_focus_id{}; std::vector> m_widgets{}; public: @@ -114,8 +114,8 @@ namespace ui { const SDL_Event& event ); - [[nodiscard]] helper::optional - handle_event_result(const helper::optional& result, Widget* widget); + [[nodiscard]] std::optional + handle_event_result(const std::optional& result, Widget* widget); [[nodiscard]] u32 focusable_index_by_id(u32 id) const; diff --git a/src/ui/layouts/scroll_layout.cpp b/src/ui/layouts/scroll_layout.cpp index 19d5ed4b..c91d44a2 100644 --- a/src/ui/layouts/scroll_layout.cpp +++ b/src/ui/layouts/scroll_layout.cpp @@ -39,7 +39,7 @@ ui::ScrollLayout::ScrollLayout( : FocusLayout{ layout, focus_id, FocusOptions{ is_top_level, is_top_level }, is_top_level}, // if on top, we support tab and wrap around, otherwise not gap{ gap }, - m_texture{ helper::nullopt }, + m_texture{ std::nullopt }, m_service_provider{ service_provider }, m_step_size{ static_cast(layout.get_rect().height() * 0.05) } { @@ -283,8 +283,8 @@ ui::Widget::EventHandleResult ui::ScrollLayout::handle_focus_change_events( void ui::ScrollLayout::clear_widgets() { m_widgets.clear(); - m_texture = helper::nullopt; - m_focus_id = helper::nullopt; + m_texture = std::nullopt; + m_focus_id = std::nullopt; recalculate_sizes(0); } diff --git a/src/ui/layouts/scroll_layout.hpp b/src/ui/layouts/scroll_layout.hpp index e2ae2303..5827c4b7 100644 --- a/src/ui/layouts/scroll_layout.hpp +++ b/src/ui/layouts/scroll_layout.hpp @@ -5,7 +5,7 @@ #include "graphics/rect.hpp" #include "graphics/renderer.hpp" #include "graphics/texture.hpp" -#include "helper/optional.hpp" + #include "helper/types.hpp" #include @@ -44,7 +44,7 @@ namespace ui { struct ScrollLayout : public FocusLayout { private: Margin gap; - helper::optional m_texture; + std::optional m_texture; ServiceProvider* m_service_provider; shapes::URect main_rect; shapes::URect scrollbar_rect; diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index b3db6555..909eb53b 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -3,10 +3,10 @@ #include "helper/utils.hpp" -[[nodiscard]] helper::optional ui::as_focusable(ui::Widget* const widget) { +[[nodiscard]] std::optional ui::as_focusable(ui::Widget* const widget) { return utils::is_child_class(widget); } -[[nodiscard]] helper::optional ui::as_hoverable(ui::Widget* const widget) { +[[nodiscard]] std::optional ui::as_hoverable(ui::Widget* const widget) { return utils::is_child_class(widget); } diff --git a/src/ui/widget.hpp b/src/ui/widget.hpp index 92cd6a6a..c455ce08 100644 --- a/src/ui/widget.hpp +++ b/src/ui/widget.hpp @@ -1,7 +1,7 @@ #pragma once #include "helper/bool_wrapper.hpp" -#include "helper/optional.hpp" + #include "manager/service_provider.hpp" #include "ui/focusable.hpp" #include "ui/hoverable.hpp" @@ -59,9 +59,9 @@ namespace ui { handle_event(const std::shared_ptr& input_manager, const SDL_Event& event) = 0; }; - [[nodiscard]] helper::optional as_focusable(Widget* widget); + [[nodiscard]] std::optional as_focusable(Widget* widget); - [[nodiscard]] helper::optional as_hoverable(Widget* widget); + [[nodiscard]] std::optional as_hoverable(Widget* widget); } // namespace ui diff --git a/tests/utils/printer.hpp b/tests/utils/printer.hpp index 216a57f9..d190719e 100644 --- a/tests/utils/printer.hpp +++ b/tests/utils/printer.hpp @@ -3,7 +3,7 @@ #pragma once #include "helper/expected.hpp" -#include "helper/optional.hpp" + #include @@ -42,7 +42,7 @@ namespace #endif { - // make helper::optional printable + // make std::optional printable template void PrintTo(const optional& value, std::ostream* os) { //NOLINT(cert-dcl58-cpp) if (value.has_value()) { diff --git a/tools/dependencies/meson.build b/tools/dependencies/meson.build index 98534224..ad357e9f 100644 --- a/tools/dependencies/meson.build +++ b/tools/dependencies/meson.build @@ -1,4 +1,5 @@ only_allow_native_libs = false + if meson.is_cross_build() if host_machine.system() == 'switch' or host_machine.system() == '3ds' # we do not link to code that was compiled with gcc 10.1 / gcc 7.1, the code we link with is all compiled with gcc 13.2 @@ -26,92 +27,6 @@ if meson.is_cross_build() endif endif -sdl2_dep = dependency( - 'sdl2', - 'SDL2', - allow_fallback: false, - required: only_allow_native_libs, - version: '>=2.26.0', -) - -if sdl2_dep.found() - graphics_lib += { - 'deps': [graphics_lib.get('deps'), sdl2_dep], - } -else - sdl2_dep = dependency( - 'sdl2', - required: true, - default_options: {'test': false}, - version: '>=2.24.0', - ) - sdl2main_dep = dependency( - 'sdl2main', - required: true, - fallback: 'sdl2', - version: '>=2.24.0', - ) - - graphic_application_deps += sdl2main_dep - - graphics_lib += { - 'deps': [graphics_lib.get('deps'), sdl2_dep], - } -endif - -sdl2_ttf_dep = dependency( - 'sdl2_ttf', - 'SDL2_ttf', - allow_fallback: not only_allow_native_libs, - required: true, -) -graphics_lib += { - 'deps': [graphics_lib.get('deps'), sdl2_ttf_dep], -} - -sdl2_image_dep = dependency( - 'sdl2_image', - 'SDL2_image', - allow_fallback: not only_allow_native_libs, - required: true, -) -graphics_lib += { - 'deps': [graphics_lib.get('deps'), sdl2_image_dep], -} - -# a dirty thing atm, until mpg123 is ported to meson (maybe never...) -mpg123_dep = dependency( - 'mpg123', - allow_fallback: true, - required: false, -) -sdl2_mixer_flags = {'flac': 'enabled'} -sdl2_mixer_defines = ['-DAUDIO_WITH_FLAC_SUPPORT'] -if mpg123_dep.found() - sdl2_mixer_flags += {'mpg123': 'enabled'} - sdl2_mixer_defines += '-DAUDIO_WITH_MP3_SUPPORT' -else - mpg123_dep = cpp.find_library('mpg123', required: false) - if mpg123_dep.found() - sdl2_mixer_flags += {'mpg123': 'enabled'} - sdl2_mixer_defines += '-DAUDIO_WITH_MP3_SUPPORT' - - meson.override_dependency('mpg123', mpg123_dep) - endif -endif - -sdl2_mixer_dep = dependency( - 'sdl2_mixer', - 'SDL2_mixer', - allow_fallback: not only_allow_native_libs, - required: true, - default_options: sdl2_mixer_flags, -) -graphics_lib += { - 'deps': [graphics_lib.get('deps'), sdl2_mixer_dep], - 'compile_args': [graphics_lib.get('compile_args'), sdl2_mixer_defines], -} - fmt_use_header_only = false if ( @@ -138,21 +53,6 @@ endif core_lib += {'deps': [core_lib.get('deps'), fmt_dep]} -spdlog_dep = dependency( - 'spdlog', - required: true, - default_options: {'tests': 'disabled'}, -) -graphics_lib += { - 'deps': [graphics_lib.get('deps'), spdlog_dep], -} - -if (meson.is_cross_build() and host_machine.system() == '3ds') - graphics_lib += { - 'compile_args': [graphics_lib.get('compile_args'), '-DSPDLOG_NO_TLS'], - } -endif - nlohmann_json_dep = dependency( 'nlohmann_json', required: true, @@ -183,8 +83,6 @@ if not have_std_expected 'compile_args': [core_lib.get('compile_args'), '-D_USE_TL_EXPECTED'], 'deps': [core_lib.get('deps'), tl_exp_dep], } -else - message('Compiler support std::expected, using that') endif # check std::optional support @@ -200,14 +98,7 @@ int main() { ) if not have_std_optional - error('Compiler doesn\'t support std::optional, using fallback') - tl_opt_dep = dependency('tl-optional', required: true) - core_lib += { - 'compile_args': [core_lib.get('compile_args'), '-D_USE_TL_OPTIONAL'], - 'deps': [core_lib.get('deps'), tl_opt_dep], - } -else - message('Compiler support std::optional, using that') + error('Compiler doesn\'t support std::optional') endif magic_enum_dep = dependency( @@ -217,125 +108,237 @@ magic_enum_dep = dependency( ) core_lib += {'deps': [core_lib.get('deps'), magic_enum_dep]} -argparse_dep = dependency('argparse', required: true) -core_lib += {'deps': [core_lib.get('deps'), argparse_dep]} +utf8cpp_dep = dependency( + 'utf8cpp', + required: true, + version: '>=4.0.0', +) +core_lib += {'deps': [core_lib.get('deps'), utf8cpp_dep]} -online_multiplayer_supported = true +if build_application -if ( - meson.is_cross_build() - and (host_machine.system() == 'switch' or host_machine.system() == '3ds') -) - online_multiplayer_supported = false + graphic_application_deps = [] + recordings_application_deps = [] - # TODO: use libcurl and - # https://github.com/uctakeoff/uc-curl - # or https://github.com/JosephP91/curlcpp + sdl2_dep = dependency( + 'sdl2', + 'SDL2', + allow_fallback: false, + required: only_allow_native_libs, + version: '>=2.26.0', + ) - core_lib += { - 'compile_args': [ - core_lib.get('compile_args'), - '-D_ONLINE_MULTIPLAYER_NOT_SUPPORTED', - ], + if sdl2_dep.found() + graphics_lib += { + 'deps': [graphics_lib.get('deps'), sdl2_dep], + } + else + sdl2_dep = dependency( + 'sdl2', + required: true, + default_options: {'test': false}, + version: '>=2.24.0', + ) + sdl2main_dep = dependency( + 'sdl2main', + required: true, + fallback: 'sdl2', + version: '>=2.24.0', + ) + + graphic_application_deps += sdl2main_dep + + graphics_lib += { + 'deps': [graphics_lib.get('deps'), sdl2_dep], + } + endif + + sdl2_ttf_dep = dependency( + 'sdl2_ttf', + 'SDL2_ttf', + allow_fallback: not only_allow_native_libs, + required: true, + ) + graphics_lib += { + 'deps': [graphics_lib.get('deps'), sdl2_ttf_dep], } -else - cpp_httlib_dep = dependency( - 'cpp-httplib', + + sdl2_image_dep = dependency( + 'sdl2_image', + 'SDL2_image', + allow_fallback: not only_allow_native_libs, required: true, - default_options: { - 'cpp-httplib_openssl': 'enabled', - 'cpp-httplib_zlib': 'enabled', - }, ) - graphics_lib += {'deps': [graphics_lib.get('deps'), cpp_httlib_dep]} -endif + graphics_lib += { + 'deps': [graphics_lib.get('deps'), sdl2_image_dep], + } -utf8cpp_dep = dependency( - 'utf8cpp', - required: true, - version: '>=4.0.0', -) -core_lib += {'deps': [core_lib.get('deps'), utf8cpp_dep]} + # a dirty thing atm, until mpg123 is ported to meson (maybe never...) + mpg123_dep = dependency( + 'mpg123', + allow_fallback: true, + required: false, + ) + sdl2_mixer_flags = {'flac': 'enabled'} + sdl2_mixer_defines = ['-DAUDIO_WITH_FLAC_SUPPORT'] + if mpg123_dep.found() + sdl2_mixer_flags += {'mpg123': 'enabled'} + sdl2_mixer_defines += '-DAUDIO_WITH_MP3_SUPPORT' + else + mpg123_dep = cpp.find_library('mpg123', required: false) + if mpg123_dep.found() + sdl2_mixer_flags += {'mpg123': 'enabled'} + sdl2_mixer_defines += '-DAUDIO_WITH_MP3_SUPPORT' -build_installer = get_option('build_installer') + meson.override_dependency('mpg123', mpg123_dep) + endif + endif + + sdl2_mixer_dep = dependency( + 'sdl2_mixer', + 'SDL2_mixer', + allow_fallback: not only_allow_native_libs, + required: true, + default_options: sdl2_mixer_flags, + ) + graphics_lib += { + 'deps': [graphics_lib.get('deps'), sdl2_mixer_dep], + 'compile_args': [graphics_lib.get('compile_args'), sdl2_mixer_defines], + } + + spdlog_dep = dependency( + 'spdlog', + required: true, + default_options: {'tests': 'disabled'}, + ) + graphics_lib += { + 'deps': [graphics_lib.get('deps'), spdlog_dep], + } + + if (meson.is_cross_build() and host_machine.system() == '3ds') + graphics_lib += { + 'compile_args': [graphics_lib.get('compile_args'), '-DSPDLOG_NO_TLS'], + } + endif + + online_multiplayer_supported = true + + if ( + meson.is_cross_build() + and ( + host_machine.system() == 'switch' + or host_machine.system() == '3ds' + ) + ) + online_multiplayer_supported = false -is_flatpak_build = false + # TODO: use libcurl and + # https://github.com/uctakeoff/uc-curl + # or https://github.com/JosephP91/curlcpp -# some sanity checks for the installer -if build_installer - if get_option('buildtype') != 'release' - error( - 'buildtype needs to be \'release\', when building the installer, but was: ' - + get_option('buildtype'), + graphics_lib += { + 'compile_args': [ + graphics_lib.get('compile_args'), + '-D_ONLINE_MULTIPLAYER_NOT_SUPPORTED', + ], + } + else + cpp_httlib_dep = dependency( + 'cpp-httplib', + required: true, + default_options: { + 'cpp-httplib_openssl': 'enabled', + 'cpp-httplib_zlib': 'enabled', + }, ) + graphics_lib += {'deps': [graphics_lib.get('deps'), cpp_httlib_dep]} endif - if host_machine.system() == 'linux' - if get_option('prefix') == '/app' - is_flatpak_build = true + build_installer = get_option('build_installer') + + is_flatpak_build = false + + # some sanity checks for the installer + if build_installer + if get_option('buildtype') != 'release' + error( + 'buildtype needs to be \'release\', when building the installer, but was: ' + + get_option('buildtype'), + ) + endif + + if host_machine.system() == 'linux' + if get_option('prefix') == '/app' + is_flatpak_build = true + else + error( + 'only support flatpak builds, when building the installer for linux', + ) + endif + elif host_machine.system() == 'windows' + message('Adding a windows installer target: \'windows_installer\'') else error( - 'only support flatpak builds, when building the installer for linux', + 'unsuported system for building the installer: ' + + host_machine.system(), ) + endif - elif host_machine.system() == 'windows' - message('Adding a windows installer target: \'windows_installer\'') - else - error( - 'unsuported system for building the installer: ' - + host_machine.system(), - ) + + core_lib += { + 'compile_args': [ + core_lib.get('compile_args'), + '-DBUILD_INSTALLER', + ], + } endif - core_lib += { - 'compile_args': [ - core_lib.get('compile_args'), - '-DBUILD_INSTALLER', - ], - } + if is_flatpak_build + app_name = 'com.github.mgerhold.OOPetris' + core_lib += { + 'compile_args': [core_lib.get('compile_args'), '-DFLATPAK_BUILD'], + } + endif -endif + have_file_dialogs = false + have_discord_sdk = false -if is_flatpak_build - app_name = 'com.github.mgerhold.OOPetris' - core_lib += { - 'compile_args': [core_lib.get('compile_args'), '-DFLATPAK_BUILD'], - } -endif + nfde_dep = dependency( + 'nativefiledialog-extended', + required: not meson.is_cross_build(), + default_options: { + 'xdg-desktop-portal': is_flatpak_build ? 'enabled' : 'auto', + }, + ) + if nfde_dep.found() + have_file_dialogs = true + graphics_lib += { + 'compile_args': [ + graphics_lib.get('compile_args'), + '-D_HAVE_FILE_DIALOGS', + ], + 'deps': [graphics_lib.get('deps'), nfde_dep], + } + endif -have_file_dialogs = false -have_discord_sdk = false + discord_sdk_dep = dependency( + 'discord-game-sdk', + required: not meson.is_cross_build(), + ) + if discord_sdk_dep.found() + have_discord_sdk = true + graphics_lib += { + 'compile_args': [ + graphics_lib.get('compile_args'), + '-D_HAVE_DISCORD_SDK', + ], + 'deps': [graphics_lib.get('deps'), discord_sdk_dep], + } + endif -nfde_dep = dependency( - 'nativefiledialog-extended', - required: not meson.is_cross_build(), - default_options: { - 'xdg-desktop-portal': is_flatpak_build ? 'enabled' : 'auto', - }, -) -if nfde_dep.found() - have_file_dialogs = true - graphics_lib += { - 'compile_args': [ - graphics_lib.get('compile_args'), - '-D_HAVE_FILE_DIALOGS', - ], - 'deps': [graphics_lib.get('deps'), nfde_dep], - } -endif + argparse_dep = dependency('argparse', required: true) -discord_sdk_dep = dependency( - 'discord-game-sdk', - required: not meson.is_cross_build(), -) -if discord_sdk_dep.found() - have_discord_sdk = true - graphics_lib += { - 'compile_args': [ - graphics_lib.get('compile_args'), - '-D_HAVE_DISCORD_SDK', - ], - 'deps': [graphics_lib.get('deps'), discord_sdk_dep], - } + graphic_application_deps += argparse_dep + recordings_application_deps += argparse_dep endif diff --git a/tools/install/meson.build b/tools/install/meson.build index cfbabcb4..da4648d6 100644 --- a/tools/install/meson.build +++ b/tools/install/meson.build @@ -81,24 +81,3 @@ foreach logo : logos rename: [app_name + '.' + ext], ) endforeach - -# generate pkgconfig filres -pkg = import('pkgconfig') -pkg.generate( - liboopetris_core, - name: 'oopetris-core', - filebase: 'oopetris-core', - -) - -pkg.generate( - liboopetris_recordings, - name: 'oopetris-recordings', - filebase: 'oopetris-recordings', -) - -pkg.generate( - liboopetris_graphics, - name: 'oopetris-graphics', - filebase: 'oopetris-graphics', -) diff --git a/tools/options/meson.build b/tools/options/meson.build index 62065b46..ee2244d6 100644 --- a/tools/options/meson.build +++ b/tools/options/meson.build @@ -1,9 +1,9 @@ +oopetris_author = 'Coder2k' +oopetris_name = 'OOPetris' + core_lib = { 'inc_dirs': [], 'compile_args': [ - '-DOOPETRIS_VERSION=' + meson.project_version(), - '-DOOPETRIS_NAME=' + oopetris_name, - '-DOOPETRIS_AUTHOR=' + oopetris_author, ], 'deps': [], } @@ -16,13 +16,14 @@ recordings_lib = { graphics_lib = { 'inc_dirs': [], - 'compile_args': [], + 'compile_args': [ + '-DOOPETRIS_VERSION=' + meson.project_version(), + '-DOOPETRIS_NAME=' + oopetris_name, + '-DOOPETRIS_AUTHOR=' + oopetris_author, + ], 'deps': [], } -global_deps = [] -graphic_application_deps = [] - cpp = meson.get_compiler('cpp') build_with_libcpp = false @@ -57,6 +58,11 @@ elif cpp.get_id() == 'clang' core_lib += { 'compile_args': [core_lib.get('compile_args'), '-stdlib=libc++'], + 'deps': [ + core_lib.get('deps'), + cpp.find_library('c++'), + cpp.find_library('c++abi'), + ], } if not meson.is_subproject() @@ -68,10 +74,16 @@ elif cpp.get_id() == 'clang' endif - global_deps += [cpp.find_library('c++'), cpp.find_library('c++abi')] else # TODO: once clang with libstdc++ (gcc c++ stdlib) supports std::expectedt, remove this special behaviour allow_tl_expected_fallback = true endif endif + +build_application = true + +## only build, if we are at the root, not if this is used as subproject in e.g. wrap files +if meson.is_subproject() + build_application = false +endif From 938c264bb6630c4b3120c2426c33bc887b9c2793 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 21:54:01 +0200 Subject: [PATCH 16/77] Fix all include errors --- src/discord/core.cpp | 5 +- src/discord/core.hpp | 2 +- src/executables/game/application.cpp | 10 ++-- src/executables/game/application.hpp | 6 +- src/executables/game/main.cpp | 38 ++++++++++--- src/executables/game/meson.build | 4 +- ...{command_line_arguments.hpp => parser.hpp} | 57 ++++++++----------- src/executables/meson.build | 4 +- .../utility/command_line_arguments.hpp | 33 ++++++++--- src/executables/utility/main.cpp | 15 +++-- src/executables/utility/meson.build | 2 +- src/game/bag.hpp | 4 +- src/game/command_line_arguments.cpp | 16 ++++++ src/game/command_line_arguments.hpp | 29 ++++++++++ src/game/game.cpp | 5 +- src/game/game.hpp | 3 +- src/game/graphic_helpers.cpp | 3 +- src/game/graphic_helpers.hpp | 7 +-- src/game/grid.hpp | 6 +- src/game/meson.build | 2 + src/game/rotation.hpp | 2 +- src/game/tetrion.cpp | 9 +-- src/game/tetrion.hpp | 10 ++-- src/game/tetromino.hpp | 5 +- src/graphics/rect.hpp | 2 +- src/graphics/renderer.cpp | 4 +- src/graphics/renderer.hpp | 3 +- src/graphics/sdl_context.cpp | 3 +- src/graphics/text.hpp | 3 +- src/graphics/texture.cpp | 4 +- src/graphics/texture.hpp | 7 ++- src/graphics/window.hpp | 3 +- src/helper/clock_source.hpp | 1 + src/helper/console_helpers.cpp | 3 +- src/helper/constants.hpp | 2 +- src/helper/graphic_utils.hpp | 3 +- src/helper/music_utils.hpp | 2 +- src/helper/nfd.cpp | 7 ++- src/helper/nfd_include.hpp | 2 +- src/helper/platform.hpp | 2 +- src/input/controller_input.cpp | 2 +- src/input/game_input.hpp | 8 +-- src/input/guid.cpp | 3 +- src/input/guid.hpp | 6 +- src/input/input.cpp | 6 +- src/input/input.hpp | 6 +- src/input/input_creator.cpp | 16 +++--- src/input/input_creator.hpp | 5 +- src/input/joystick_input.cpp | 8 +-- src/input/joystick_input.hpp | 4 +- src/input/keyboard_input.cpp | 4 +- src/input/keyboard_input.hpp | 5 +- src/input/mouse_input.cpp | 2 +- src/input/replay_input.cpp | 2 +- src/input/replay_input.hpp | 3 +- src/input/touch_input.cpp | 6 +- src/input/touch_input.hpp | 4 +- src/libs/core/helper/bool_wrapper.hpp | 2 + src/libs/core/helper/color.hpp | 3 +- src/libs/core/helper/color_literals.hpp | 2 +- src/libs/core/helper/date.hpp | 4 +- src/libs/core/helper/parse_json.hpp | 8 +-- src/libs/core/helper/static_string.hpp | 2 +- src/libs/recordings/recordings.hpp | 16 ++++++ src/libs/recordings/utility/meson.build | 16 ++++-- .../utility/recording_json_wrapper.hpp | 7 ++- src/lobby/api.hpp | 5 +- src/lobby/types.hpp | 2 +- src/manager/music_manager.cpp | 12 ++-- src/manager/music_manager.hpp | 3 +- src/manager/resource_manager.hpp | 2 +- src/manager/sdl_controller_key.hpp | 2 +- src/manager/sdl_key.cpp | 7 ++- src/manager/sdl_key.hpp | 5 +- src/meson.build | 2 + src/scenes/about_page/about_page.cpp | 5 +- src/scenes/loading_screen/loading_screen.cpp | 7 ++- src/scenes/loading_screen/loading_screen.hpp | 3 +- src/scenes/logo/logo.cpp | 6 +- src/scenes/main_menu/main_menu.cpp | 1 + src/scenes/online_lobby/online_lobby.cpp | 9 +-- .../recording_selector/recording_chooser.cpp | 3 +- .../recording_selector/recording_chooser.hpp | 3 +- .../recording_component.cpp | 6 +- .../recording_component.hpp | 5 +- .../recording_selector/recording_selector.cpp | 9 +-- src/scenes/replay_game/replay_game.cpp | 2 + src/scenes/scene.hpp | 2 +- src/scenes/scene_id.hpp | 2 +- .../settings_menu/color_setting_row.cpp | 7 ++- src/scenes/settings_menu/settings_menu.cpp | 8 +-- src/scenes/settings_menu/settings_menu.hpp | 3 +- src/scenes/single_player_game/game_over.cpp | 1 + .../single_player_game/single_player_game.cpp | 11 ++-- src/ui/components/button.hpp | 3 +- src/ui/components/color_picker.cpp | 6 +- src/ui/components/color_picker.hpp | 5 +- src/ui/components/slider.cpp | 6 +- src/ui/components/textinput.cpp | 6 +- src/ui/components/textinput.hpp | 5 +- src/ui/focusable.hpp | 2 +- src/ui/hoverable.hpp | 7 ++- src/ui/layout.hpp | 5 +- src/ui/layouts/focus_layout.hpp | 3 +- src/ui/layouts/grid_layout.hpp | 2 +- src/ui/layouts/scroll_layout.cpp | 4 +- src/ui/layouts/scroll_layout.hpp | 4 +- src/ui/layouts/tile_layout.hpp | 2 +- src/ui/widget.cpp | 3 +- src/ui/widget.hpp | 2 +- 110 files changed, 416 insertions(+), 260 deletions(-) rename src/executables/game/{command_line_arguments.hpp => parser.hpp} (50%) create mode 100644 src/game/command_line_arguments.cpp create mode 100644 src/game/command_line_arguments.hpp create mode 100644 src/libs/recordings/recordings.hpp diff --git a/src/discord/core.cpp b/src/discord/core.cpp index 5b0c5c4f..72dcd3b4 100644 --- a/src/discord/core.cpp +++ b/src/discord/core.cpp @@ -1,9 +1,8 @@ +#include +#include #include "core.hpp" -#include "helper/magic_enum_wrapper.hpp" -#include "helper/utils.hpp" -#include "types.h" #include #include diff --git a/src/discord/core.hpp b/src/discord/core.hpp index ffad0d68..c7b3db05 100644 --- a/src/discord/core.hpp +++ b/src/discord/core.hpp @@ -2,7 +2,7 @@ #pragma once -#include "helper/expected.hpp" +#include #include #ifdef _WIN32 diff --git a/src/executables/game/application.cpp b/src/executables/game/application.cpp index 27b999b0..daee4af1 100644 --- a/src/executables/game/application.cpp +++ b/src/executables/game/application.cpp @@ -1,8 +1,10 @@ +#include +#include +#include + #include "application.hpp" -#include "helper/errors.hpp" -#include "helper/magic_enum_wrapper.hpp" +#include "helper/graphic_utils.hpp" #include "helper/message_box.hpp" -#include "helper/sleep.hpp" #include "input/input.hpp" #include "manager/music_manager.hpp" #include "scenes/loading_screen/loading_screen.hpp" @@ -35,7 +37,7 @@ namespace { } // namespace -Application::Application(std::shared_ptr&& window, const std::vector& arguments) try +Application::Application(std::shared_ptr&& window, CommandLineArguments&& arguments) try : m_command_line_arguments{ arguments }, m_window{ std::move(window) }, m_renderer{ *m_window, m_command_line_arguments.target_fps.has_value() ? Renderer::VSync::Disabled diff --git a/src/executables/game/application.hpp b/src/executables/game/application.hpp index 7ff10608..69b1a981 100644 --- a/src/executables/game/application.hpp +++ b/src/executables/game/application.hpp @@ -1,9 +1,9 @@ #pragma once +#include + #include "graphics/renderer.hpp" #include "graphics/window.hpp" -#include "helper/command_line_arguments.hpp" -#include "helper/types.hpp" #include "input/input.hpp" #include "manager/event_dispatcher.hpp" #include "manager/event_listener.hpp" @@ -49,7 +49,7 @@ struct Application final : public EventListener, public ServiceProvider { std::vector> m_scene_stack; public: - Application(std::shared_ptr&& window, const std::vector& arguments); + Application(std::shared_ptr&& window, CommandLineArguments&& arguments); Application(const Application&) = delete; Application& operator=(const Application&) = delete; diff --git a/src/executables/game/main.cpp b/src/executables/game/main.cpp index 0f1a564d..7d542bd1 100644 --- a/src/executables/game/main.cpp +++ b/src/executables/game/main.cpp @@ -1,7 +1,12 @@ + + +#include "./parser.hpp" + +#include +#include + #include "application.hpp" -#include "helper/errors.hpp" #include "helper/message_box.hpp" -#include "helper/utils.hpp" #include #include @@ -47,16 +52,33 @@ int main(int argc, char** argv) { spdlog::set_level(spdlog::level::err); #endif - std::vector arguments{}; - arguments.reserve(argc); + std::vector arguments_vector{}; + arguments_vector.reserve(argc); for (auto i = 0; i < argc; ++i) { - arguments.emplace_back(argv[i]); //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + arguments_vector.emplace_back(argv[i]); //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + } + + if (arguments_vector.empty()) { + arguments_vector.emplace_back("oopetris"); } - if (arguments.empty()) { - arguments.emplace_back("oopetris"); + auto parsed_arguments = helper::parse_args(arguments_vector); + + if (not parsed_arguments.has_value()) { + + spdlog::error("error parsing command line arguments: {}", parsed_arguments.error()); +#if defined(__ANDROID__) + // calling exit() in android doesn't do the correct job, it completely avoids resource cleanup by the underlying SDLActivity.java + // (java wrapper), that calls the main and expects it to return ALWAYS and throwing an exception in a catch statement is bad, + // but is required here + throw std::runtime_error{ "exit with status code 1: " + std::string{ err.what() } }; +#else + std::exit(1); +#endif } + auto arguments = std::move(parsed_arguments.value()); + constexpr auto window_name = constants::program_name.c_str(); std::shared_ptr window{ nullptr }; @@ -83,7 +105,7 @@ int main(int argc, char** argv) { try { - Application app{ std::move(window), arguments }; + Application app{ std::move(window), std::move(arguments) }; app.run(); return EXIT_SUCCESS; diff --git a/src/executables/game/meson.build b/src/executables/game/meson.build index 29903893..f58b20cb 100644 --- a/src/executables/game/meson.build +++ b/src/executables/game/meson.build @@ -1,6 +1,6 @@ main_files += files( 'application.cpp', 'application.hpp', - 'command_line_arguments.hpp' - 'main.cpp',, + 'command_line_arguments.hpp', + 'main.cpp', ) diff --git a/src/executables/game/command_line_arguments.hpp b/src/executables/game/parser.hpp similarity index 50% rename from src/executables/game/command_line_arguments.hpp rename to src/executables/game/parser.hpp index 7db18593..867da8c9 100644 --- a/src/executables/game/command_line_arguments.hpp +++ b/src/executables/game/parser.hpp @@ -1,51 +1,45 @@ #pragma once +#include + +#include "game/command_line_arguments.hpp" + #include "helper/constants.hpp" #include "helper/graphic_utils.hpp" -#include "helper/types.hpp" -#include "helper/utils.hpp" - #include -#include #include #include #include #include -struct CommandLineArguments final { -private: - static inline constexpr auto default_starting_level = u32{ 0 }; - -public: - std::optional recording_path{}; - std::optional target_fps{}; - std::remove_cvref_t starting_level{ default_starting_level }; - bool silent{ false }; - CommandLineArguments(const std::vector& arguments) { +namespace helper { + helper::expected parse_args(const std::vector& arguments) { argparse::ArgumentParser parser{ constants::program_name, constants::version, argparse::default_arguments::all }; parser.add_argument("-r", "--recording").help("the path of a recorded game used for replay"); parser.add_argument("-f", "--target-fps").help("the number of simulation steps per second").scan<'i', u32>(); parser.add_argument("-l", "--level") .help("the starting level of the game") - .scan<'i', decltype(starting_level)>() - .default_value(default_starting_level); + .scan<'i', CommandLineArguments::Level>() + .default_value(CommandLineArguments::default_starting_level); parser.add_argument("-s", "--silent").help("disable audio output").default_value(false).implicit_value(true); try { parser.parse_args(arguments); + CommandLineArguments result{ std::nullopt, std::nullopt }; + if (auto path = parser.present("--recording")) { spdlog::info("recording is present"); - recording_path = utils::get_root_folder() / *path; + result.recording_path = utils::get_root_folder() / *path; } const auto fps = parser.present("--target-fps"); if (fps.has_value()) { if (fps.value() >= 1) { - target_fps = fps.value(); + result.target_fps = fps.value(); } else { spdlog::error( "invalid value for target fps ({}), using default value instead (VSYNC)", fps.value() @@ -53,26 +47,23 @@ struct CommandLineArguments final { } } - const auto level = parser.get("--level"); + const auto level = parser.get("--level"); if (level <= 30) { - starting_level = level; + result.starting_level = level; } else { spdlog::error( - "invalid value for starting level ({}), using default value instead ({})", level, starting_level + "invalid value for starting level ({}), using default value instead ({})", level, + CommandLineArguments::default_starting_level ); + result.starting_level = CommandLineArguments::default_starting_level; } - silent = parser.get("--silent"); - } catch (const std::exception& err) { - spdlog::error("error parsing command line arguments: {}", err.what()); -#if defined(__ANDROID__) - // calling exit() in android doesn't do the correct job, it completely avoids resource cleanup by the underlying SDLActivity.java - // (java wrapper), that calls the main and expects it to return ALWAYS and throwing an exception in a catch statement is bad, - // but is required here - throw std::runtime_error{ "exit with status code 1: " + std::string{ err.what() } }; -#else - std::exit(1); -#endif + result.silent = parser.get("--silent"); + + return result; + + } catch (const std::exception& error) { + return helper::unexpected{ error.what() }; } } -}; +} // namespace helper diff --git a/src/executables/meson.build b/src/executables/meson.build index 796c664c..29c5e089 100644 --- a/src/executables/meson.build +++ b/src/executables/meson.build @@ -1,6 +1,6 @@ if build_application - main_filers = [] + main_files = [] subdir('game') @@ -35,7 +35,7 @@ if build_application if host_machine.system() == 'windows' subdir('../../platforms/windows') endif - + oopetris_exe = executable( 'oopetris', main_files, diff --git a/src/executables/utility/command_line_arguments.hpp b/src/executables/utility/command_line_arguments.hpp index e42c7e98..38f64c89 100644 --- a/src/executables/utility/command_line_arguments.hpp +++ b/src/executables/utility/command_line_arguments.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -19,11 +20,22 @@ struct Info { }; struct CommandLineArguments final { private: public: - std::filesystem::path recording_path{}; + std::filesystem::path recording_path; std::variant value; - CommandLineArguments(int argc, char** argv) { + template + CommandLineArguments(std::filesystem::path recording_path, T&& type) + : recording_path{ recording_path }, + value{ std::move(type) } { } + + template + CommandLineArguments(std::filesystem::path recording_path, const T& type) + : recording_path{ recording_path }, + value{ type } { } + + + [[nodiscard]] static helper::expected from_args(int argc, char** argv) noexcept { argparse::ArgumentParser parser{ argc >= 1 ? argv[0] //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) : "oopetris_recording_utility", "0.0.1", argparse::default_arguments::all }; @@ -51,22 +63,27 @@ struct CommandLineArguments final { parser.parse_args(argc, argv); - this->recording_path = parser.get("--recording"); + const auto recording_path = parser.get("--recording"); if (parser.is_subcommand_used(dump_parser)) { const auto ensure_ascii = dump_parser.get("--ensure-ascii"); const auto pretty_print = dump_parser.get("--pretty-print"); - this->value = Dump{ .ensure_ascii = ensure_ascii, .pretty_print = pretty_print }; + + return CommandLineArguments{ + recording_path, Dump{ .ensure_ascii = ensure_ascii, .pretty_print = pretty_print } + }; } else if (parser.is_subcommand_used(info_parser)) { - this->value = Info{}; + return CommandLineArguments{ + recording_path, + Info{}, + }; } else { - throw std::runtime_error("Unknown or no subcommand used"); + return helper::unexpected{ "Unknown or no subcommand used" }; } } catch (const std::exception& error) { - std::cerr << error.what(); - std::exit(1); + return helper::unexpected{ error.what() }; } } }; diff --git a/src/executables/utility/main.cpp b/src/executables/utility/main.cpp index f446e488..003d3bf2 100644 --- a/src/executables/utility/main.cpp +++ b/src/executables/utility/main.cpp @@ -1,8 +1,7 @@ -#include "command_line_arguments.hpp" +#include "./command_line_arguments.hpp" -#include -#include +#include #include #include @@ -39,7 +38,15 @@ void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_pr int main(int argc, char** argv) noexcept { - const auto arguments = CommandLineArguments(argc, argv); + const auto arguments_result = CommandLineArguments::from_args(argc, argv); + + if (not arguments_result.has_value()) { + std::cerr << arguments_result.error(); + std::exit(1); + } + + const auto arguments = arguments_result.value(); + if (not std::filesystem::exists(arguments.recording_path)) { std::cerr << arguments.recording_path << " does not exist!\n"; diff --git a/src/executables/utility/meson.build b/src/executables/utility/meson.build index b78a3d8e..96961618 100644 --- a/src/executables/utility/meson.build +++ b/src/executables/utility/meson.build @@ -1 +1 @@ -recordings_main_files += files('command_line_arguments.hpp' 'main.cpp',) +recordings_main_files += files('command_line_arguments.hpp', 'main.cpp',) diff --git a/src/game/bag.hpp b/src/game/bag.hpp index dba8f1fd..2774d31c 100644 --- a/src/game/bag.hpp +++ b/src/game/bag.hpp @@ -1,7 +1,7 @@ #pragma once -#include "game/tetromino_type.hpp" -#include "helper/random.hpp" +#include +#include #include diff --git a/src/game/command_line_arguments.cpp b/src/game/command_line_arguments.cpp new file mode 100644 index 00000000..79bcc4b1 --- /dev/null +++ b/src/game/command_line_arguments.cpp @@ -0,0 +1,16 @@ + + + +#include "command_line_arguments.hpp" + + +CommandLineArguments::CommandLineArguments( + std::optional recording_path, + std::optional target_fps, + Level starting_level, + bool silent +) + : recording_path{ recording_path }, + target_fps{ target_fps }, + starting_level{ starting_level }, + silent{ silent } { } diff --git a/src/game/command_line_arguments.hpp b/src/game/command_line_arguments.hpp new file mode 100644 index 00000000..a7efcde1 --- /dev/null +++ b/src/game/command_line_arguments.hpp @@ -0,0 +1,29 @@ + + +#pragma once + +#include +#include +#include + +#include +#include + +struct CommandLineArguments final { + + static inline const constexpr auto default_starting_level = u32{ 0 }; + static inline const constexpr auto default_silent = bool{ true }; + + std::optional recording_path; + std::optional target_fps; + using Level = std::remove_cvref_t; + Level starting_level; + bool silent; + + CommandLineArguments( + std::optional recording_path, + std::optional target_fps, + Level starting_level = default_starting_level, + bool silent = default_silent + ); +}; diff --git a/src/game/game.cpp b/src/game/game.cpp index dc71f83c..282c3d81 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1,7 +1,8 @@ +#include +#include + #include "game.hpp" -#include "helper/magic_enum_wrapper.hpp" -#include "helper/utils.hpp" #include "input/replay_input.hpp" Game::Game( diff --git a/src/game/game.hpp b/src/game/game.hpp index bc566c10..fbd8e005 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -1,8 +1,9 @@ #pragma once +#include + #include "helper/clock_source.hpp" #include "input/input_creator.hpp" -#include "recordings/recording.hpp" #include "tetrion.hpp" #include "ui/widget.hpp" diff --git a/src/game/graphic_helpers.cpp b/src/game/graphic_helpers.cpp index fd08cf87..5630713d 100644 --- a/src/game/graphic_helpers.cpp +++ b/src/game/graphic_helpers.cpp @@ -1,6 +1,7 @@ +#include + #include "graphic_helpers.hpp" #include "graphics/renderer.hpp" -#include "helper/utils.hpp" #include diff --git a/src/game/graphic_helpers.hpp b/src/game/graphic_helpers.hpp index 2dff9d97..c25e49d1 100644 --- a/src/game/graphic_helpers.hpp +++ b/src/game/graphic_helpers.hpp @@ -1,10 +1,9 @@ #pragma once -#include "graphics/point.hpp" -#include "helper/types.hpp" +#include + #include "manager/service_provider.hpp" -#include "mino.hpp" -#include "mino_stack.hpp" + enum class MinoTransparency : u8 { // here the enum value is used as index into the preview alpha array diff --git a/src/game/grid.hpp b/src/game/grid.hpp index 44a59da8..a0ad6bd9 100644 --- a/src/game/grid.hpp +++ b/src/game/grid.hpp @@ -1,9 +1,9 @@ #pragma once -#include "graphics/point.hpp" +#include +#include + #include "graphics/rect.hpp" -#include "grid_properties.hpp" -#include "helper/color.hpp" #include "manager/service_provider.hpp" #include "ui/layout.hpp" #include "ui/widget.hpp" diff --git a/src/game/meson.build b/src/game/meson.build index cc33d589..3013e4a2 100644 --- a/src/game/meson.build +++ b/src/game/meson.build @@ -13,4 +13,6 @@ graphics_src_files += files( 'tetrion.hpp', 'tetromino.cpp', 'tetromino.hpp', + 'command_line_arguments.hpp', + 'command_line_arguments.cpp', ) diff --git a/src/game/rotation.hpp b/src/game/rotation.hpp index a71b4d42..3d8e37f4 100644 --- a/src/game/rotation.hpp +++ b/src/game/rotation.hpp @@ -1,6 +1,6 @@ #pragma once -#include "helper/types.hpp" +#include enum class Rotation : u8 { North = 0, diff --git a/src/game/tetrion.cpp b/src/game/tetrion.cpp index eb660217..1e8b68e8 100644 --- a/src/game/tetrion.cpp +++ b/src/game/tetrion.cpp @@ -1,13 +1,14 @@ -#include "tetrion.hpp" +#include +#include +#include + #include "helper/constants.hpp" #include "helper/graphic_utils.hpp" -#include "helper/magic_enum_wrapper.hpp" #include "helper/music_utils.hpp" #include "helper/platform.hpp" -#include "helper/utils.hpp" #include "manager/music_manager.hpp" #include "manager/resource_manager.hpp" -#include "recordings/recording_writer.hpp" +#include "tetrion.hpp" #include "ui/components/label.hpp" #include diff --git a/src/game/tetrion.hpp b/src/game/tetrion.hpp index ed218d34..cbff250f 100644 --- a/src/game/tetrion.hpp +++ b/src/game/tetrion.hpp @@ -1,14 +1,14 @@ #pragma once +#include +#include +#include +#include + #include "bag.hpp" #include "grid.hpp" - -#include "helper/random.hpp" -#include "helper/types.hpp" #include "input/game_input.hpp" #include "manager/service_provider.hpp" -#include "mino_stack.hpp" -#include "recordings/tetrion_core_information.hpp" #include "tetromino.hpp" #include "ui/layout.hpp" #include "ui/layouts/grid_layout.hpp" diff --git a/src/game/tetromino.hpp b/src/game/tetromino.hpp index 8bc98ec8..5b83840a 100644 --- a/src/game/tetromino.hpp +++ b/src/game/tetromino.hpp @@ -1,10 +1,9 @@ #pragma once +#include + #include "graphic_helpers.hpp" -#include "graphics/point.hpp" -#include "mino.hpp" #include "rotation.hpp" -#include "tetromino_type.hpp" #include diff --git a/src/graphics/rect.hpp b/src/graphics/rect.hpp index 50a3985b..bd955d70 100644 --- a/src/graphics/rect.hpp +++ b/src/graphics/rect.hpp @@ -1,6 +1,6 @@ #pragma once -#include "graphics/point.hpp" +#include #include #include diff --git a/src/graphics/renderer.cpp b/src/graphics/renderer.cpp index 4e7bc42a..b5f71f80 100644 --- a/src/graphics/renderer.cpp +++ b/src/graphics/renderer.cpp @@ -1,5 +1,7 @@ +#include + #include "renderer.hpp" -#include "helper/errors.hpp" + //TODO(Totto): assert return values of all sdl functions diff --git a/src/graphics/renderer.hpp b/src/graphics/renderer.hpp index 2686201f..44715b02 100644 --- a/src/graphics/renderer.hpp +++ b/src/graphics/renderer.hpp @@ -1,6 +1,7 @@ #pragma once -#include "helper/color.hpp" +#include + #include "manager/font.hpp" #include "rect.hpp" #include "texture.hpp" diff --git a/src/graphics/sdl_context.cpp b/src/graphics/sdl_context.cpp index 24ed8b03..e0c426f1 100644 --- a/src/graphics/sdl_context.cpp +++ b/src/graphics/sdl_context.cpp @@ -1,5 +1,6 @@ +#include + #include "graphics/sdl_context.hpp" -#include "helper/errors.hpp" #include #include diff --git a/src/graphics/text.hpp b/src/graphics/text.hpp index eb1c8688..319b6132 100644 --- a/src/graphics/text.hpp +++ b/src/graphics/text.hpp @@ -1,6 +1,7 @@ #pragma once -#include "helper/color.hpp" +#include + #include "manager/font.hpp" #include "manager/service_provider.hpp" #include "rect.hpp" diff --git a/src/graphics/texture.cpp b/src/graphics/texture.cpp index 2fb3b879..0ec8e501 100644 --- a/src/graphics/texture.cpp +++ b/src/graphics/texture.cpp @@ -1,7 +1,7 @@ +#include -#include "texture.hpp" -#include "graphics/point.hpp" #include "helper/graphic_utils.hpp" +#include "texture.hpp" Texture::Texture(SDL_Texture* raw_texture) : m_raw_texture{ raw_texture } { } diff --git a/src/graphics/texture.hpp b/src/graphics/texture.hpp index ae82a16d..872b38e1 100644 --- a/src/graphics/texture.hpp +++ b/src/graphics/texture.hpp @@ -2,10 +2,11 @@ #pragma once -#include "helper/color.hpp" -#include "helper/utils.hpp" +#include +#include +#include + #include "manager/font.hpp" -#include "point.hpp" #include "rect.hpp" #include diff --git a/src/graphics/window.hpp b/src/graphics/window.hpp index ee630d9d..7ea426c6 100644 --- a/src/graphics/window.hpp +++ b/src/graphics/window.hpp @@ -1,6 +1,7 @@ #pragma once -#include "graphics/point.hpp" +#include + #include "graphics/rect.hpp" #include "helper/message_box.hpp" #include "sdl_context.hpp" diff --git a/src/helper/clock_source.hpp b/src/helper/clock_source.hpp index 2cd0e80a..3aa72413 100644 --- a/src/helper/clock_source.hpp +++ b/src/helper/clock_source.hpp @@ -3,6 +3,7 @@ #include +#include #include struct ClockSource { diff --git a/src/helper/console_helpers.cpp b/src/helper/console_helpers.cpp index 99af1e49..c94d6ac9 100644 --- a/src/helper/console_helpers.cpp +++ b/src/helper/console_helpers.cpp @@ -1,5 +1,6 @@ -#include "helper/errors.hpp" +#include + #if defined(__NINTENDO_CONSOLE__) #include "console_helpers.hpp" diff --git a/src/helper/constants.hpp b/src/helper/constants.hpp index 767e3d2d..79e11f35 100644 --- a/src/helper/constants.hpp +++ b/src/helper/constants.hpp @@ -1,6 +1,6 @@ #pragma once -#include "./helper/static_string.hpp" +#include namespace constants { diff --git a/src/helper/graphic_utils.hpp b/src/helper/graphic_utils.hpp index 2f0a6455..be6b3eee 100644 --- a/src/helper/graphic_utils.hpp +++ b/src/helper/graphic_utils.hpp @@ -1,7 +1,8 @@ #pragma once -#include "color.hpp" +#include + #include "helper/constants.hpp" diff --git a/src/helper/music_utils.hpp b/src/helper/music_utils.hpp index 7707eade..8482c976 100644 --- a/src/helper/music_utils.hpp +++ b/src/helper/music_utils.hpp @@ -1,6 +1,6 @@ #pragma once -#include "static_string.hpp" +#include namespace utils { diff --git a/src/helper/nfd.cpp b/src/helper/nfd.cpp index 541a436d..ffdbf135 100644 --- a/src/helper/nfd.cpp +++ b/src/helper/nfd.cpp @@ -1,9 +1,10 @@ -#include "nfd.hpp" -#include "helper/utils.hpp" + #if defined(_HAVE_FILE_DIALOGS) -#include "helper/types.hpp" +#include +#include + #include "nfd_include.hpp" #include diff --git a/src/helper/nfd_include.hpp b/src/helper/nfd_include.hpp index ad7cd61d..a56ada95 100644 --- a/src/helper/nfd_include.hpp +++ b/src/helper/nfd_include.hpp @@ -3,7 +3,7 @@ #if defined(_HAVE_FILE_DIALOGS) -#include "helper/expected.hpp" +#include #define NFD_THROWS_EXCEPTIONS diff --git a/src/helper/platform.hpp b/src/helper/platform.hpp index 42e7249f..305a7c8e 100644 --- a/src/helper/platform.hpp +++ b/src/helper/platform.hpp @@ -2,7 +2,7 @@ #pragma once -#include "helper/types.hpp" +#include #include diff --git a/src/input/controller_input.cpp b/src/input/controller_input.cpp index 4f8a8703..d9b5a921 100644 --- a/src/input/controller_input.cpp +++ b/src/input/controller_input.cpp @@ -1,7 +1,7 @@ +#include #include "controller_input.hpp" -#include "helper/string_manipulation.hpp" #include "input/input.hpp" #include "input/joystick_input.hpp" #include "manager/sdl_controller_key.hpp" diff --git a/src/input/game_input.hpp b/src/input/game_input.hpp index e473f285..bda37d19 100644 --- a/src/input/game_input.hpp +++ b/src/input/game_input.hpp @@ -1,11 +1,11 @@ #pragma once -#include "helper/clock_source.hpp" +#include +#include +#include -#include "helper/random.hpp" -#include "helper/types.hpp" +#include "helper/clock_source.hpp" #include "manager/event_listener.hpp" -#include "manager/input_event.hpp" #include #include diff --git a/src/input/guid.cpp b/src/input/guid.cpp index bbdaeb2b..0ec5105e 100644 --- a/src/input/guid.cpp +++ b/src/input/guid.cpp @@ -1,6 +1,7 @@ +#include + #include "guid.hpp" -#include "helper/utils.hpp" #include #include diff --git a/src/input/guid.hpp b/src/input/guid.hpp index 274b9f70..c0c7b208 100644 --- a/src/input/guid.hpp +++ b/src/input/guid.hpp @@ -1,9 +1,9 @@ #pragma once -#include "helper/const_utils.hpp" -#include "helper/expected.hpp" -#include "helper/types.hpp" +#include +#include +#include #include #include diff --git a/src/input/input.cpp b/src/input/input.cpp index d53ff3db..008673cd 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -1,7 +1,7 @@ -#include "input.hpp" -#include "helper/expected.hpp" +#include +#include -#include "helper/utils.hpp" +#include "input.hpp" #include "input/controller_input.hpp" #include "joystick_input.hpp" #include "keyboard_input.hpp" diff --git a/src/input/input.hpp b/src/input/input.hpp index fa5506ce..fa925de1 100644 --- a/src/input/input.hpp +++ b/src/input/input.hpp @@ -2,13 +2,13 @@ #pragma once +#include +#include +#include #include "game_input.hpp" -#include "graphics/point.hpp" #include "graphics/rect.hpp" #include "graphics/window.hpp" -#include "helper/bool_wrapper.hpp" -#include "helper/expected.hpp" #include "manager/service_provider.hpp" diff --git a/src/input/input_creator.cpp b/src/input/input_creator.cpp index 61943370..ac1b5697 100644 --- a/src/input/input_creator.cpp +++ b/src/input/input_creator.cpp @@ -1,14 +1,16 @@ -#include "input_creator.hpp" -#include "additional_information.hpp" -#include "helper/command_line_arguments.hpp" -#include "helper/date.hpp" -#include "helper/errors.hpp" -#include "helper/expected.hpp" - +#include +#include +#include +#include + +#include "game/command_line_arguments.hpp" +#include "helper/constants.hpp" +#include "helper/graphic_utils.hpp" #include "input.hpp" #include "input/replay_input.hpp" +#include "input_creator.hpp" #include #include diff --git a/src/input/input_creator.hpp b/src/input/input_creator.hpp index 5d544d8a..5e720fd7 100644 --- a/src/input/input_creator.hpp +++ b/src/input/input_creator.hpp @@ -1,11 +1,12 @@ #pragma once -#include "helper/date.hpp" +#include +#include #include "input/game_input.hpp" #include "manager/service_provider.hpp" -#include "recordings/recording_writer.hpp" + #include diff --git a/src/input/joystick_input.cpp b/src/input/joystick_input.cpp index 0119c3f7..6c2d4a49 100644 --- a/src/input/joystick_input.cpp +++ b/src/input/joystick_input.cpp @@ -1,13 +1,13 @@ -#include "joystick_input.hpp" +#include +#include + #include "controller_input.hpp" -#include "helper/expected.hpp" #include "helper/graphic_utils.hpp" - -#include "helper/utils.hpp" #include "input/game_input.hpp" #include "input/input.hpp" +#include "joystick_input.hpp" #include #include diff --git a/src/input/joystick_input.hpp b/src/input/joystick_input.hpp index 8953b82a..892b9f17 100644 --- a/src/input/joystick_input.hpp +++ b/src/input/joystick_input.hpp @@ -1,9 +1,9 @@ #pragma once +#include +#include #include "guid.hpp" -#include "helper/expected.hpp" -#include "helper/parse_json.hpp" #include "input.hpp" #include "input/console_buttons.hpp" #include "input/game_input.hpp" diff --git a/src/input/keyboard_input.cpp b/src/input/keyboard_input.cpp index afd19ac6..88ede9d1 100644 --- a/src/input/keyboard_input.cpp +++ b/src/input/keyboard_input.cpp @@ -1,8 +1,8 @@ -#include "keyboard_input.hpp" +#include -#include "helper/utils.hpp" #include "input/game_input.hpp" #include "input/input.hpp" +#include "keyboard_input.hpp" input::KeyboardInput::KeyboardInput() : input::Input{ "keyboard", InputType::Keyboard } { } diff --git a/src/input/keyboard_input.hpp b/src/input/keyboard_input.hpp index 870e6375..58695c78 100644 --- a/src/input/keyboard_input.hpp +++ b/src/input/keyboard_input.hpp @@ -1,8 +1,9 @@ #pragma once +#include +#include + #include "game_input.hpp" -#include "helper/expected.hpp" -#include "helper/parse_json.hpp" #include "input.hpp" #include "manager/event_dispatcher.hpp" #include "manager/sdl_key.hpp" diff --git a/src/input/mouse_input.cpp b/src/input/mouse_input.cpp index fc118e12..f286b75d 100644 --- a/src/input/mouse_input.cpp +++ b/src/input/mouse_input.cpp @@ -1,7 +1,7 @@ +#include #include "mouse_input.hpp" -#include "graphics/point.hpp" #include "input/input.hpp" diff --git a/src/input/replay_input.cpp b/src/input/replay_input.cpp index cd5fe4db..5913ffc0 100644 --- a/src/input/replay_input.cpp +++ b/src/input/replay_input.cpp @@ -1,6 +1,6 @@ #include "replay_input.hpp" #include "game/tetrion.hpp" -#include "helper/magic_enum_wrapper.hpp" +#include input::ReplayGameInput::ReplayGameInput( diff --git a/src/input/replay_input.hpp b/src/input/replay_input.hpp index 311c2e5b..3d00afa8 100644 --- a/src/input/replay_input.hpp +++ b/src/input/replay_input.hpp @@ -1,7 +1,8 @@ #pragma once +#include + #include "game_input.hpp" -#include "recordings/recording_reader.hpp" #include diff --git a/src/input/touch_input.cpp b/src/input/touch_input.cpp index 6c1e84a9..2f607ef2 100644 --- a/src/input/touch_input.cpp +++ b/src/input/touch_input.cpp @@ -1,9 +1,9 @@ -#include "touch_input.hpp" -#include "graphics/point.hpp" +#include +#include -#include "helper/utils.hpp" #include "input/game_input.hpp" #include "input/input.hpp" +#include "touch_input.hpp" #include #include diff --git a/src/input/touch_input.hpp b/src/input/touch_input.hpp index 674903f4..c27e9d56 100644 --- a/src/input/touch_input.hpp +++ b/src/input/touch_input.hpp @@ -1,8 +1,8 @@ #pragma once +#include +#include -#include "helper/expected.hpp" -#include "helper/parse_json.hpp" #include "input.hpp" #include "input/game_input.hpp" #include "manager/event_dispatcher.hpp" diff --git a/src/libs/core/helper/bool_wrapper.hpp b/src/libs/core/helper/bool_wrapper.hpp index 0a898195..3341c815 100644 --- a/src/libs/core/helper/bool_wrapper.hpp +++ b/src/libs/core/helper/bool_wrapper.hpp @@ -1,6 +1,8 @@ #pragma once +#include + namespace helper { template diff --git a/src/libs/core/helper/color.hpp b/src/libs/core/helper/color.hpp index fa51b236..8b6e1f48 100644 --- a/src/libs/core/helper/color.hpp +++ b/src/libs/core/helper/color.hpp @@ -1,8 +1,7 @@ #pragma once -#include - #include "./const_utils.hpp" +#include "./expected.hpp" #include "./types.hpp" #include "./utils.hpp" diff --git a/src/libs/core/helper/color_literals.hpp b/src/libs/core/helper/color_literals.hpp index 35ce8f2b..d96fcd5b 100644 --- a/src/libs/core/helper/color_literals.hpp +++ b/src/libs/core/helper/color_literals.hpp @@ -2,7 +2,7 @@ #include "./color.hpp" #include "./const_utils.hpp" -#include "./helper/types.hpp" +#include "./types.hpp" #include #include diff --git a/src/libs/core/helper/date.hpp b/src/libs/core/helper/date.hpp index 4a3377e3..36f50b47 100644 --- a/src/libs/core/helper/date.hpp +++ b/src/libs/core/helper/date.hpp @@ -1,7 +1,7 @@ #pragma once -#include "./helper/expected.hpp" -#include "./helper/types.hpp" +#include "./expected.hpp" +#include "./types.hpp" #include #include diff --git a/src/libs/core/helper/parse_json.hpp b/src/libs/core/helper/parse_json.hpp index f5552148..e7c8434e 100644 --- a/src/libs/core/helper/parse_json.hpp +++ b/src/libs/core/helper/parse_json.hpp @@ -8,7 +8,7 @@ #include -#include "./helper/expected.hpp" +#include "./expected.hpp" #include @@ -51,7 +51,7 @@ namespace json { template - [[nodiscard]] helper::expected try_parse_json(const std::string& content) { + [[nodiscard]] helper::expected try_parse_json(const std::string& content) noexcept { try { T result = nlohmann::json::parse(content); @@ -69,7 +69,7 @@ namespace json { } template - [[nodiscard]] helper::expected try_parse_json_file(const std::filesystem::path& file) { + [[nodiscard]] helper::expected try_parse_json_file(const std::filesystem::path& file) noexcept { if (not std::filesystem::exists(file)) { return helper::unexpected{ fmt::format("File '{}' doesn't exist", file.string()) }; @@ -90,7 +90,7 @@ namespace json { template [[nodiscard]] helper::expected - try_json_to_string(const T& type, const bool pretty = false) { + try_json_to_string(const T& type, const bool pretty = false) noexcept { try { const nlohmann::json value = type; diff --git a/src/libs/core/helper/static_string.hpp b/src/libs/core/helper/static_string.hpp index 237c9639..f7ec92f1 100644 --- a/src/libs/core/helper/static_string.hpp +++ b/src/libs/core/helper/static_string.hpp @@ -1,6 +1,6 @@ #pragma once -#include "./helper/types.hpp" +#include "./types.hpp" #include #include diff --git a/src/libs/recordings/recordings.hpp b/src/libs/recordings/recordings.hpp new file mode 100644 index 00000000..68660430 --- /dev/null +++ b/src/libs/recordings/recordings.hpp @@ -0,0 +1,16 @@ + + +#pragma once + +// this is a easy public header, that you can include, to get all header of liboopetris_recordings + + +#include "./utility/additional_information.hpp" +#include "./utility/checksum_helper.hpp" +#include "./utility/helper.hpp" +#include "./utility/recording.hpp" +#include "./utility/recording_json_wrapper.hpp" +#include "./utility/recording_reader.hpp" +#include "./utility/recording_writer.hpp" +#include "./utility/tetrion_core_information.hpp" +#include "./utility/tetrion_snapshot.hpp" diff --git a/src/libs/recordings/utility/meson.build b/src/libs/recordings/utility/meson.build index c823aae2..e5defa80 100644 --- a/src/libs/recordings/utility/meson.build +++ b/src/libs/recordings/utility/meson.build @@ -1,15 +1,21 @@ recordings_src_files = files( 'additional_information.cpp', - 'additional_information.hpp', 'checksum_helper.cpp', - 'checksum_helper.hpp', 'recording.cpp', + 'recording_reader.cpp', + 'recording_writer.cpp', + 'tetrion_snapshot.cpp', +) + + +recordings_header_files = files( + 'additional_information.hpp', + 'checksum_helper.hpp', 'recording.hpp', 'recording_json_wrapper.hpp', - 'recording_reader.cpp', 'recording_reader.hpp', - 'recording_writer.cpp', 'recording_writer.hpp', - 'tetrion_snapshot.cpp', 'tetrion_snapshot.hpp', + 'helper.hpp', + 'tetrion_core_information.hpp', ) diff --git a/src/libs/recordings/utility/recording_json_wrapper.hpp b/src/libs/recordings/utility/recording_json_wrapper.hpp index 2fdecca6..f13babb3 100644 --- a/src/libs/recordings/utility/recording_json_wrapper.hpp +++ b/src/libs/recordings/utility/recording_json_wrapper.hpp @@ -2,10 +2,11 @@ #pragma once +#include +#include +#include + #include "./additional_information.hpp" -#include "./game/mino_stack.hpp" -#include "./helper/magic_enum_wrapper.hpp" -#include "./helper/parse_json.hpp" #include "./recording.hpp" #include "./recording_reader.hpp" #include "./tetrion_snapshot.hpp" diff --git a/src/lobby/api.hpp b/src/lobby/api.hpp index 2e04aa52..7918bd96 100644 --- a/src/lobby/api.hpp +++ b/src/lobby/api.hpp @@ -25,8 +25,9 @@ #include #include -#include "helper/expected.hpp" -#include "helper/static_string.hpp" +#include +#include + #include "lobby/types.hpp" namespace constants { diff --git a/src/lobby/types.hpp b/src/lobby/types.hpp index 41bd138a..5d446895 100644 --- a/src/lobby/types.hpp +++ b/src/lobby/types.hpp @@ -4,7 +4,7 @@ #include -#include "helper/parse_json.hpp" +#include namespace lobby { diff --git a/src/manager/music_manager.cpp b/src/manager/music_manager.cpp index f10184f2..5228931f 100644 --- a/src/manager/music_manager.cpp +++ b/src/manager/music_manager.cpp @@ -1,9 +1,9 @@ -#include "manager/music_manager.hpp" -#include "helper/command_line_arguments.hpp" -#include "helper/constants.hpp" -#include "helper/errors.hpp" +#include +#include -#include "helper/types.hpp" +#include "game/command_line_arguments.hpp" +#include "helper/constants.hpp" +#include "manager/music_manager.hpp" #include "manager/sdl_key.hpp" #include @@ -12,7 +12,7 @@ #include #include #include - +#include MusicManager::MusicManager(ServiceProvider* service_provider, u8 channel_size) : m_music{ nullptr }, diff --git a/src/manager/music_manager.hpp b/src/manager/music_manager.hpp index 78a4dc36..b2939c9e 100644 --- a/src/manager/music_manager.hpp +++ b/src/manager/music_manager.hpp @@ -1,7 +1,8 @@ #pragma once -#include "helper/types.hpp" +#include + #include "input/input.hpp" #include "manager/service_provider.hpp" diff --git a/src/manager/resource_manager.hpp b/src/manager/resource_manager.hpp index ebada413..8fed50c3 100644 --- a/src/manager/resource_manager.hpp +++ b/src/manager/resource_manager.hpp @@ -1,6 +1,6 @@ #pragma once -#include "helper/types.hpp" +#include #include "manager/font.hpp" #include diff --git a/src/manager/sdl_controller_key.hpp b/src/manager/sdl_controller_key.hpp index 9816ba84..c8a578ad 100644 --- a/src/manager/sdl_controller_key.hpp +++ b/src/manager/sdl_controller_key.hpp @@ -1,6 +1,6 @@ #pragma once -#include "helper/expected.hpp" +#include #include diff --git a/src/manager/sdl_key.cpp b/src/manager/sdl_key.cpp index ed4a4457..4a755720 100644 --- a/src/manager/sdl_key.cpp +++ b/src/manager/sdl_key.cpp @@ -1,8 +1,9 @@ -#include "sdl_key.hpp" -#include "helper/string_manipulation.hpp" -#include "helper/utils.hpp" +#include +#include + +#include "sdl_key.hpp" #include #include diff --git a/src/manager/sdl_key.hpp b/src/manager/sdl_key.hpp index 279850b5..28e479d0 100644 --- a/src/manager/sdl_key.hpp +++ b/src/manager/sdl_key.hpp @@ -1,8 +1,7 @@ #pragma once -#include "helper/expected.hpp" - -#include "helper/types.hpp" +#include +#include #include #include diff --git a/src/meson.build b/src/meson.build index 86650198..bb75edb5 100644 --- a/src/meson.build +++ b/src/meson.build @@ -51,4 +51,6 @@ if build_application # setting this to strings, so += {...} gets detected as an error, if it is done after that graphics_lib = 'undefined' + subdir('executables') + endif diff --git a/src/scenes/about_page/about_page.cpp b/src/scenes/about_page/about_page.cpp index b76333fd..8e47c0ee 100644 --- a/src/scenes/about_page/about_page.cpp +++ b/src/scenes/about_page/about_page.cpp @@ -1,9 +1,11 @@ +#include + #include "about_page.hpp" #include "graphics/window.hpp" #include "helper/constants.hpp" #include "helper/git_helper.hpp" +#include "helper/graphic_utils.hpp" #include "helper/platform.hpp" -#include "helper/utils.hpp" #include "manager/resource_manager.hpp" #include "ui/components/image_view.hpp" #include "ui/components/link_label.hpp" @@ -11,6 +13,7 @@ #include #include + namespace scenes { AboutPage::AboutPage(ServiceProvider* service_provider, const ui::Layout& layout) : Scene{service_provider, layout} diff --git a/src/scenes/loading_screen/loading_screen.cpp b/src/scenes/loading_screen/loading_screen.cpp index 35b53046..5fe75625 100644 --- a/src/scenes/loading_screen/loading_screen.cpp +++ b/src/scenes/loading_screen/loading_screen.cpp @@ -1,11 +1,12 @@ -#include "loading_screen.hpp" +#include +#include + #include "game/graphic_helpers.hpp" -#include "game/tetromino_type.hpp" -#include "graphics/point.hpp" #include "graphics/rect.hpp" #include "graphics/renderer.hpp" #include "graphics/window.hpp" #include "helper/platform.hpp" +#include "loading_screen.hpp" #include "manager/service_provider.hpp" #include "scenes/logo/logo.hpp" #include "ui/layout.hpp" diff --git a/src/scenes/loading_screen/loading_screen.hpp b/src/scenes/loading_screen/loading_screen.hpp index 5fc114c6..994d92a7 100644 --- a/src/scenes/loading_screen/loading_screen.hpp +++ b/src/scenes/loading_screen/loading_screen.hpp @@ -1,7 +1,8 @@ #pragma once +#include + #include "../logo/logo.hpp" -#include "game/mino.hpp" #include "graphics/rect.hpp" #include "manager/service_provider.hpp" diff --git a/src/scenes/logo/logo.cpp b/src/scenes/logo/logo.cpp index add3a065..2a07c408 100644 --- a/src/scenes/logo/logo.cpp +++ b/src/scenes/logo/logo.cpp @@ -1,9 +1,9 @@ +#include +#include -#include "logo.hpp" #include "game/graphic_helpers.hpp" -#include "game/mino.hpp" -#include "graphics/point.hpp" #include "graphics/renderer.hpp" +#include "logo.hpp" #include diff --git a/src/scenes/main_menu/main_menu.cpp b/src/scenes/main_menu/main_menu.cpp index 41d3440e..9f7ea881 100644 --- a/src/scenes/main_menu/main_menu.cpp +++ b/src/scenes/main_menu/main_menu.cpp @@ -1,6 +1,7 @@ #include "main_menu.hpp" #include "graphics/window.hpp" #include "helper/constants.hpp" +#include "helper/graphic_utils.hpp" #include "helper/music_utils.hpp" #include "helper/platform.hpp" #include "manager/music_manager.hpp" diff --git a/src/scenes/online_lobby/online_lobby.cpp b/src/scenes/online_lobby/online_lobby.cpp index 34340e3c..307d94ce 100644 --- a/src/scenes/online_lobby/online_lobby.cpp +++ b/src/scenes/online_lobby/online_lobby.cpp @@ -1,12 +1,13 @@ -#include "online_lobby.hpp" +#include +#include +#include + #include "graphics/window.hpp" #include "helper/constants.hpp" -#include "helper/errors.hpp" -#include "helper/magic_enum_wrapper.hpp" #include "helper/platform.hpp" -#include "helper/utils.hpp" #include "manager/music_manager.hpp" #include "manager/resource_manager.hpp" +#include "online_lobby.hpp" #include "ui/components/textinput.hpp" #include "ui/layout.hpp" #include "ui/layouts/scroll_layout.hpp" diff --git a/src/scenes/recording_selector/recording_chooser.cpp b/src/scenes/recording_selector/recording_chooser.cpp index 85c193fc..6541469a 100644 --- a/src/scenes/recording_selector/recording_chooser.cpp +++ b/src/scenes/recording_selector/recording_chooser.cpp @@ -1,13 +1,12 @@ #include "recording_chooser.hpp" +#include #include "helper/nfd_include.hpp" #include "manager/event_dispatcher.hpp" #include "manager/font.hpp" #include "manager/resource_manager.hpp" -#include "recordings/recording.hpp" -#include "recordings/recording_reader.hpp" #include "ui/components/text_button.hpp" custom_ui::RecordingFileChooser::RecordingFileChooser( diff --git a/src/scenes/recording_selector/recording_chooser.hpp b/src/scenes/recording_selector/recording_chooser.hpp index 7b824c66..a80b5190 100644 --- a/src/scenes/recording_selector/recording_chooser.hpp +++ b/src/scenes/recording_selector/recording_chooser.hpp @@ -2,7 +2,8 @@ #pragma once -#include "helper/color_literals.hpp" +#include + #include "ui/components/label.hpp" #include "ui/focusable.hpp" #include "ui/hoverable.hpp" diff --git a/src/scenes/recording_selector/recording_component.cpp b/src/scenes/recording_selector/recording_component.cpp index 97d50ff0..17fc7421 100644 --- a/src/scenes/recording_selector/recording_component.cpp +++ b/src/scenes/recording_selector/recording_component.cpp @@ -1,10 +1,10 @@ +#include +#include -#include "recording_component.hpp" -#include "helper/date.hpp" -#include "helper/magic_enum_wrapper.hpp" #include "input/input.hpp" #include "manager/font.hpp" #include "manager/resource_manager.hpp" +#include "recording_component.hpp" #include "ui/widget.hpp" #include diff --git a/src/scenes/recording_selector/recording_component.hpp b/src/scenes/recording_selector/recording_component.hpp index 4e554b92..9773cddf 100644 --- a/src/scenes/recording_selector/recording_component.hpp +++ b/src/scenes/recording_selector/recording_component.hpp @@ -2,8 +2,9 @@ #pragma once -#include "helper/color_literals.hpp" -#include "recordings/recording.hpp" +#include +#include + #include "ui/components/label.hpp" #include "ui/focusable.hpp" #include "ui/hoverable.hpp" diff --git a/src/scenes/recording_selector/recording_selector.cpp b/src/scenes/recording_selector/recording_selector.cpp index 148e9fe5..373e504c 100644 --- a/src/scenes/recording_selector/recording_selector.cpp +++ b/src/scenes/recording_selector/recording_selector.cpp @@ -1,18 +1,19 @@ -#include "helper/platform.hpp" -#include "helper/utils.hpp" +#include +#include "helper/platform.hpp" #if defined(_HAVE_FILE_DIALOGS) #include "recording_chooser.hpp" #endif +#include + #include "graphics/window.hpp" #include "helper/constants.hpp" - +#include "helper/graphic_utils.hpp" #include "manager/resource_manager.hpp" #include "recording_component.hpp" #include "recording_selector.hpp" -#include "recordings/recording_reader.hpp" #include "scenes/replay_game/replay_game.hpp" #include "ui/components/text_button.hpp" #include "ui/layout.hpp" diff --git a/src/scenes/replay_game/replay_game.cpp b/src/scenes/replay_game/replay_game.cpp index c649ea15..4a2362aa 100644 --- a/src/scenes/replay_game/replay_game.cpp +++ b/src/scenes/replay_game/replay_game.cpp @@ -1,6 +1,8 @@ #include "replay_game.hpp" #include "../single_player_game/game_over.hpp" #include "../single_player_game/pause.hpp" +#include "helper/constants.hpp" +#include "helper/graphic_utils.hpp" #include "helper/music_utils.hpp" #include "manager/music_manager.hpp" #include "scenes/scene.hpp" diff --git a/src/scenes/scene.hpp b/src/scenes/scene.hpp index f1e3c410..fa7622f2 100644 --- a/src/scenes/scene.hpp +++ b/src/scenes/scene.hpp @@ -1,6 +1,6 @@ #pragma once -#include "helper/command_line_arguments.hpp" +#include "game/command_line_arguments.hpp" #include "input/input.hpp" #include "manager/event_listener.hpp" #include "manager/service_provider.hpp" diff --git a/src/scenes/scene_id.hpp b/src/scenes/scene_id.hpp index 845470fc..8f2e18b9 100644 --- a/src/scenes/scene_id.hpp +++ b/src/scenes/scene_id.hpp @@ -1,6 +1,6 @@ #pragma once -#include "helper/types.hpp" +#include enum class SceneId : u8 { AboutPage, diff --git a/src/scenes/settings_menu/color_setting_row.cpp b/src/scenes/settings_menu/color_setting_row.cpp index be326e15..c6a6316a 100644 --- a/src/scenes/settings_menu/color_setting_row.cpp +++ b/src/scenes/settings_menu/color_setting_row.cpp @@ -1,8 +1,9 @@ +#include +#include +#include + #include "color_setting_row.hpp" -#include "helper/errors.hpp" -#include "helper/magic_enum_wrapper.hpp" -#include "helper/utils.hpp" #include "input/input.hpp" #include "ui/components/label.hpp" #include "ui/focusable.hpp" diff --git a/src/scenes/settings_menu/settings_menu.cpp b/src/scenes/settings_menu/settings_menu.cpp index 4780dc43..ecfdeee1 100644 --- a/src/scenes/settings_menu/settings_menu.cpp +++ b/src/scenes/settings_menu/settings_menu.cpp @@ -1,11 +1,11 @@ -#include "settings_menu.hpp" -#include "color_setting_row.hpp" -#include "helper/color_literals.hpp" +#include +#include -#include "helper/utils.hpp" +#include "color_setting_row.hpp" #include "manager/music_manager.hpp" #include "manager/resource_manager.hpp" #include "settings_details.hpp" +#include "settings_menu.hpp" #include "ui/components/label.hpp" #include "ui/components/slider.hpp" #include "ui/components/text_button.hpp" diff --git a/src/scenes/settings_menu/settings_menu.hpp b/src/scenes/settings_menu/settings_menu.hpp index 1f5e7e65..425b10c4 100644 --- a/src/scenes/settings_menu/settings_menu.hpp +++ b/src/scenes/settings_menu/settings_menu.hpp @@ -1,6 +1,7 @@ #pragma once -#include "helper/color.hpp" +#include + #include "scenes/scene.hpp" #include "ui/layouts/tile_layout.hpp" #include "ui/widget.hpp" diff --git a/src/scenes/single_player_game/game_over.cpp b/src/scenes/single_player_game/game_over.cpp index 44f8ab1e..9b04d836 100644 --- a/src/scenes/single_player_game/game_over.cpp +++ b/src/scenes/single_player_game/game_over.cpp @@ -1,5 +1,6 @@ #include "game_over.hpp" #include "graphics/renderer.hpp" +#include "helper/graphic_utils.hpp" #include "helper/music_utils.hpp" #include "helper/platform.hpp" #include "input/input.hpp" diff --git a/src/scenes/single_player_game/single_player_game.cpp b/src/scenes/single_player_game/single_player_game.cpp index 605ddd01..e1a23899 100644 --- a/src/scenes/single_player_game/single_player_game.cpp +++ b/src/scenes/single_player_game/single_player_game.cpp @@ -1,16 +1,19 @@ -#include "single_player_game.hpp" -#include "helper/date.hpp" -#include "helper/errors.hpp" +#include +#include +#include + +#include "helper/constants.hpp" +#include "helper/graphic_utils.hpp" #include "helper/music_utils.hpp" #include "helper/platform.hpp" #include "input/game_input.hpp" #include "input/input.hpp" -#include "magic_enum.hpp" #include "manager/music_manager.hpp" #include "scenes/scene.hpp" #include "scenes/settings_menu/settings_menu.hpp" #include "scenes/single_player_game/game_over.hpp" #include "scenes/single_player_game/pause.hpp" +#include "single_player_game.hpp" namespace scenes { diff --git a/src/ui/components/button.hpp b/src/ui/components/button.hpp index 8367fc43..e89ae33f 100644 --- a/src/ui/components/button.hpp +++ b/src/ui/components/button.hpp @@ -1,12 +1,13 @@ #pragma once +#include + #include #include #include #include "graphics/rect.hpp" #include "graphics/renderer.hpp" -#include "helper/color_literals.hpp" #include "input/input.hpp" #include "ui/focusable.hpp" #include "ui/hoverable.hpp" diff --git a/src/ui/components/color_picker.cpp b/src/ui/components/color_picker.cpp index 0ce5a0ef..d7bca826 100644 --- a/src/ui/components/color_picker.cpp +++ b/src/ui/components/color_picker.cpp @@ -1,11 +1,11 @@ +#include +#include +#include #include "color_picker.hpp" -#include "graphics/point.hpp" #include "graphics/rect.hpp" -#include "helper/color.hpp" #include "helper/graphic_utils.hpp" -#include "helper/utils.hpp" #include "input/input.hpp" #include "manager/resource_manager.hpp" #include "ui/components/textinput.hpp" diff --git a/src/ui/components/color_picker.hpp b/src/ui/components/color_picker.hpp index 89b96775..2b4935a9 100644 --- a/src/ui/components/color_picker.hpp +++ b/src/ui/components/color_picker.hpp @@ -1,9 +1,10 @@ #pragma once -#include "graphics/point.hpp" +#include +#include + #include "graphics/rect.hpp" -#include "helper/color.hpp" #include "ui/components/abstract_slider.hpp" #include "ui/components/image_button.hpp" #include "ui/components/textinput.hpp" diff --git a/src/ui/components/slider.cpp b/src/ui/components/slider.cpp index 8f07cadf..f5c22c2b 100644 --- a/src/ui/components/slider.cpp +++ b/src/ui/components/slider.cpp @@ -1,8 +1,8 @@ +#include +#include -#include "slider.hpp" #include "graphics/renderer.hpp" -#include "helper/color.hpp" -#include "helper/color_literals.hpp" +#include "slider.hpp" ui::Slider::Slider( u32 focus_id, diff --git a/src/ui/components/textinput.cpp b/src/ui/components/textinput.cpp index acdde28e..debd2271 100644 --- a/src/ui/components/textinput.cpp +++ b/src/ui/components/textinput.cpp @@ -1,10 +1,10 @@ +#include +#include -#include "textinput.hpp" #include "graphics/renderer.hpp" -#include "helper/color_literals.hpp" -#include "helper/errors.hpp" #include "manager/event_dispatcher.hpp" +#include "textinput.hpp" using namespace std::chrono_literals; diff --git a/src/ui/components/textinput.hpp b/src/ui/components/textinput.hpp index 0d0924cb..f3d4de6a 100644 --- a/src/ui/components/textinput.hpp +++ b/src/ui/components/textinput.hpp @@ -1,8 +1,9 @@ #pragma once +#include +#include + #include "graphics/texture.hpp" -#include "helper/color.hpp" -#include "helper/timer.hpp" #include "ui/focusable.hpp" #include "ui/hoverable.hpp" #include "ui/widget.hpp" diff --git a/src/ui/focusable.hpp b/src/ui/focusable.hpp index a5d6c233..ea144e7d 100644 --- a/src/ui/focusable.hpp +++ b/src/ui/focusable.hpp @@ -1,6 +1,6 @@ #pragma once -#include "helper/types.hpp" +#include #include diff --git a/src/ui/hoverable.hpp b/src/ui/hoverable.hpp index 1be0f48f..02a6f7f3 100644 --- a/src/ui/hoverable.hpp +++ b/src/ui/hoverable.hpp @@ -1,9 +1,10 @@ #pragma once +#include +#include +#include + #include "graphics/rect.hpp" -#include "helper/bool_wrapper.hpp" -#include "helper/types.hpp" -#include "helper/utils.hpp" #include "input/input.hpp" namespace ui { diff --git a/src/ui/layout.hpp b/src/ui/layout.hpp index e5b8e9c0..112f3ceb 100644 --- a/src/ui/layout.hpp +++ b/src/ui/layout.hpp @@ -1,9 +1,10 @@ #pragma once +#include +#include + #include "graphics/rect.hpp" #include "graphics/window.hpp" -#include "helper/types.hpp" -#include "helper/utils.hpp" #include diff --git a/src/ui/layouts/focus_layout.hpp b/src/ui/layouts/focus_layout.hpp index 939658d2..04a18d89 100644 --- a/src/ui/layouts/focus_layout.hpp +++ b/src/ui/layouts/focus_layout.hpp @@ -1,7 +1,8 @@ #pragma once -#include "helper/utils.hpp" +#include + #include "ui/focusable.hpp" #include "ui/widget.hpp" diff --git a/src/ui/layouts/grid_layout.hpp b/src/ui/layouts/grid_layout.hpp index 9c7e6885..1790ac8c 100644 --- a/src/ui/layouts/grid_layout.hpp +++ b/src/ui/layouts/grid_layout.hpp @@ -1,8 +1,8 @@ #pragma once +#include #include "focus_layout.hpp" -#include "helper/types.hpp" namespace ui { struct GridLayout : public FocusLayout { diff --git a/src/ui/layouts/scroll_layout.cpp b/src/ui/layouts/scroll_layout.cpp index c91d44a2..6dd029be 100644 --- a/src/ui/layouts/scroll_layout.cpp +++ b/src/ui/layouts/scroll_layout.cpp @@ -1,7 +1,7 @@ +#include -#include "scroll_layout.hpp" -#include "helper/color_literals.hpp" #include "input/input.hpp" +#include "scroll_layout.hpp" ui::ItemSize::ItemSize(const u32 height, ItemSizeType type) : height{ height }, type{ type } { } diff --git a/src/ui/layouts/scroll_layout.hpp b/src/ui/layouts/scroll_layout.hpp index 5827c4b7..d2a36f2f 100644 --- a/src/ui/layouts/scroll_layout.hpp +++ b/src/ui/layouts/scroll_layout.hpp @@ -1,13 +1,13 @@ #pragma once +#include + #include "focus_layout.hpp" #include "graphics/rect.hpp" #include "graphics/renderer.hpp" #include "graphics/texture.hpp" -#include "helper/types.hpp" - #include namespace ui { diff --git a/src/ui/layouts/tile_layout.hpp b/src/ui/layouts/tile_layout.hpp index 1fa12c1f..da68fdcb 100644 --- a/src/ui/layouts/tile_layout.hpp +++ b/src/ui/layouts/tile_layout.hpp @@ -1,9 +1,9 @@ #pragma once +#include #include "focus_layout.hpp" #include "graphics/renderer.hpp" -#include "helper/types.hpp" #include "ui/focusable.hpp" #include "ui/hoverable.hpp" #include "ui/layouts/grid_layout.hpp" diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index 909eb53b..672bc187 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -1,6 +1,7 @@ +#include + #include "widget.hpp" -#include "helper/utils.hpp" [[nodiscard]] std::optional ui::as_focusable(ui::Widget* const widget) { diff --git a/src/ui/widget.hpp b/src/ui/widget.hpp index c455ce08..9dd33b9a 100644 --- a/src/ui/widget.hpp +++ b/src/ui/widget.hpp @@ -1,6 +1,6 @@ #pragma once -#include "helper/bool_wrapper.hpp" +#include #include "manager/service_provider.hpp" #include "ui/focusable.hpp" From fcba29ae9ead2f4ebe91d453485bcfde88ab2e0d Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 21:57:34 +0200 Subject: [PATCH 17/77] fix meson artifact upload path --- .github/workflows/meson.yml | 5 ++--- tools/dependencies/meson.build | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml index ade23f75..dd902bb5 100644 --- a/.github/workflows/meson.yml +++ b/.github/workflows/meson.yml @@ -197,12 +197,11 @@ jobs: if: matrix.config.os == 'macos' with: name: ${{ matrix.config.name }} Executable - path: build/oopetris - # TODO: create a proper installer: https://mesonbuild.com/Creating-OSX-packages.html + path: build/src/executables/oopetris - name: Upload artifacts - Windows uses: actions/upload-artifact@v4 if: matrix.config.os == 'windows' with: name: ${{ matrix.config.name }} Executable - path: build/oopetris.exe + path: build/src/executables/oopetris.exe diff --git a/tools/dependencies/meson.build b/tools/dependencies/meson.build index ad357e9f..f3c3199d 100644 --- a/tools/dependencies/meson.build +++ b/tools/dependencies/meson.build @@ -278,6 +278,7 @@ if build_application elif host_machine.system() == 'windows' message('Adding a windows installer target: \'windows_installer\'') else + # TODO: create a proper installer for macOS : https://mesonbuild.com/Creating-OSX-packages.html error( 'unsuported system for building the installer: ' + host_machine.system(), From c5fe5068ca38adde4f23e1d4b07c15879b13c8a8 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 22:14:43 +0200 Subject: [PATCH 18/77] fix android build --- platforms/android/app/jni/Android.mk | 7 ++++--- src/executables/game/main.cpp | 2 +- src/executables/game/meson.build | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/platforms/android/app/jni/Android.mk b/platforms/android/app/jni/Android.mk index 38fd350d..9e12052d 100644 --- a/platforms/android/app/jni/Android.mk +++ b/platforms/android/app/jni/Android.mk @@ -84,14 +84,14 @@ include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := liboopetris_core -LIB_PATH := $(BUILD_PATH)/src +LIB_PATH := $(BUILD_PATH)/src/libs/core LOCAL_SRC_FILES := $(LIB_PATH)/liboopetris_core.so include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := liboopetris_recordings -LIB_PATH := $(BUILD_PATH)/src +LIB_PATH := $(BUILD_PATH)/src/libs/recordings LOCAL_SRC_FILES := $(LIB_PATH)/liboopetris_recordings.so include $(PREBUILT_SHARED_LIBRARY) @@ -105,7 +105,8 @@ include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := liboopetris -LOCAL_SRC_FILES := $(BUILD_PATH)/liboopetris.so +LIB_PATH := $(BUILD_PATH)/src/executables +LOCAL_SRC_FILES := $(LIB_PATH)/liboopetris.so include $(PREBUILT_SHARED_LIBRARY) diff --git a/src/executables/game/main.cpp b/src/executables/game/main.cpp index 7d542bd1..704465b5 100644 --- a/src/executables/game/main.cpp +++ b/src/executables/game/main.cpp @@ -71,7 +71,7 @@ int main(int argc, char** argv) { // calling exit() in android doesn't do the correct job, it completely avoids resource cleanup by the underlying SDLActivity.java // (java wrapper), that calls the main and expects it to return ALWAYS and throwing an exception in a catch statement is bad, // but is required here - throw std::runtime_error{ "exit with status code 1: " + std::string{ err.what() } }; + throw std::runtime_error{ "exit with status code 1: " + parsed_arguments.error() }; #else std::exit(1); #endif diff --git a/src/executables/game/meson.build b/src/executables/game/meson.build index f58b20cb..97fb2935 100644 --- a/src/executables/game/meson.build +++ b/src/executables/game/meson.build @@ -1,6 +1,6 @@ main_files += files( 'application.cpp', 'application.hpp', - 'command_line_arguments.hpp', + 'parser.hpp', 'main.cpp', ) From 87cc95acee15892deb5b6db35abe9428825d44d2 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 22:16:41 +0200 Subject: [PATCH 19/77] fix tests --- tests/core/color.cpp | 5 +++-- tests/graphics/sdl_key.cpp | 3 ++- tests/utils/printer.hpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/core/color.cpp b/tests/core/color.cpp index 4f274ba5..38442a7f 100644 --- a/tests/core/color.cpp +++ b/tests/core/color.cpp @@ -1,6 +1,7 @@ -#include "helper/color.hpp" -#include "helper/magic_enum_wrapper.hpp" +#include +#include + #include "utils/helper.hpp" #include diff --git a/tests/graphics/sdl_key.cpp b/tests/graphics/sdl_key.cpp index 5d9e2377..91d29d7f 100644 --- a/tests/graphics/sdl_key.cpp +++ b/tests/graphics/sdl_key.cpp @@ -1,6 +1,7 @@ +#include + #include "manager/sdl_key.hpp" -#include "helper/expected.hpp" #include "utils/helper.hpp" #include diff --git a/tests/utils/printer.hpp b/tests/utils/printer.hpp index d190719e..092f4e6d 100644 --- a/tests/utils/printer.hpp +++ b/tests/utils/printer.hpp @@ -2,7 +2,7 @@ #pragma once -#include "helper/expected.hpp" +#include #include From f21f4a86adb5f4fb34d3ca98251c94565ac9a9d6 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 22:29:09 +0200 Subject: [PATCH 20/77] fix switch / 3ds build --- meson.build | 2 ++ src/executables/meson.build | 6 +++--- {platforms => src/executables/platforms}/3ds/meson.build | 0 {platforms => src/executables/platforms}/switch/meson.build | 0 .../executables/platforms}/windows/meson.build | 0 .../executables/platforms}/windows/oopetris.rc.in | 0 src/helper/console_helpers.cpp | 2 +- src/libs/core/helper/utils.hpp | 1 + src/meson.build | 2 -- src/scenes/scene.hpp | 2 +- 10 files changed, 8 insertions(+), 7 deletions(-) rename {platforms => src/executables/platforms}/3ds/meson.build (100%) rename {platforms => src/executables/platforms}/switch/meson.build (100%) rename {platforms => src/executables/platforms}/windows/meson.build (100%) rename {platforms => src/executables/platforms}/windows/oopetris.rc.in (100%) diff --git a/meson.build b/meson.build index 92a48ed4..cf65a850 100644 --- a/meson.build +++ b/meson.build @@ -22,6 +22,8 @@ subdir('src') subdir('tools/install') +subdir('src/executables') + if get_option('tests') subdir('tests') endif diff --git a/src/executables/meson.build b/src/executables/meson.build index 29c5e089..bbbc7de3 100644 --- a/src/executables/meson.build +++ b/src/executables/meson.build @@ -22,18 +22,18 @@ if build_application main_files, [liboopetris_graphics_dep, graphic_application_deps], ] - subdir('../../platforms/switch') + subdir('platforms/switch') elif meson.is_cross_build() and host_machine.system() == '3ds' _3ds_options = [ app_name, main_files, [liboopetris_graphics_dep, graphic_application_deps], ] - subdir('../../platforms/3ds') + subdir('platforms/3ds') else if host_machine.system() == 'windows' - subdir('../../platforms/windows') + subdir('platforms/windows') endif oopetris_exe = executable( diff --git a/platforms/3ds/meson.build b/src/executables/platforms/3ds/meson.build similarity index 100% rename from platforms/3ds/meson.build rename to src/executables/platforms/3ds/meson.build diff --git a/platforms/switch/meson.build b/src/executables/platforms/switch/meson.build similarity index 100% rename from platforms/switch/meson.build rename to src/executables/platforms/switch/meson.build diff --git a/platforms/windows/meson.build b/src/executables/platforms/windows/meson.build similarity index 100% rename from platforms/windows/meson.build rename to src/executables/platforms/windows/meson.build diff --git a/platforms/windows/oopetris.rc.in b/src/executables/platforms/windows/oopetris.rc.in similarity index 100% rename from platforms/windows/oopetris.rc.in rename to src/executables/platforms/windows/oopetris.rc.in diff --git a/src/helper/console_helpers.cpp b/src/helper/console_helpers.cpp index c94d6ac9..c804a0ac 100644 --- a/src/helper/console_helpers.cpp +++ b/src/helper/console_helpers.cpp @@ -5,7 +5,7 @@ #include "console_helpers.hpp" -#include "helper/utils.hpp" +#include #if defined(__SWITCH__) #include diff --git a/src/libs/core/helper/utils.hpp b/src/libs/core/helper/utils.hpp index 93cdad60..2260b841 100644 --- a/src/libs/core/helper/utils.hpp +++ b/src/libs/core/helper/utils.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/src/meson.build b/src/meson.build index bb75edb5..86650198 100644 --- a/src/meson.build +++ b/src/meson.build @@ -51,6 +51,4 @@ if build_application # setting this to strings, so += {...} gets detected as an error, if it is done after that graphics_lib = 'undefined' - subdir('executables') - endif diff --git a/src/scenes/scene.hpp b/src/scenes/scene.hpp index fa7622f2..a0481587 100644 --- a/src/scenes/scene.hpp +++ b/src/scenes/scene.hpp @@ -8,7 +8,7 @@ #include "ui/layout.hpp" #include - +#include namespace scenes { enum class SceneUpdate : u8 { From 593b912f5094e21e2b32c7a28df86818fd88ed78 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 22:31:11 +0200 Subject: [PATCH 21/77] bump used gradle build version --- platforms/android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/android/build.gradle b/platforms/android/build.gradle index 70aed58f..0c4c2c36 100644 --- a/platforms/android/build.gradle +++ b/platforms/android/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:8.4.0' + classpath 'com.android.tools.build:gradle:8.4.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From f24103b616e352ac813890d185dfa117ccbcc9b4 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sat, 25 May 2024 22:49:11 +0200 Subject: [PATCH 22/77] fix flatpak build --- src/helper/nfd_include.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helper/nfd_include.hpp b/src/helper/nfd_include.hpp index a56ada95..7b8117e3 100644 --- a/src/helper/nfd_include.hpp +++ b/src/helper/nfd_include.hpp @@ -13,10 +13,10 @@ #include #include +#include #include #include - namespace helper { From 866e373055b69360f1b98b950b5088576fea52d6 Mon Sep 17 00:00:00 2001 From: "Totto16 (Windows VM)" Date: Sun, 26 May 2024 00:48:16 +0200 Subject: [PATCH 23/77] fix mingw error, since "winsock2.h" has to bre included before "windows.h", so everything that includes "api.hpp" needs to do that, even if it sucks, since header order shouldn't matter, but it does on windows xD --- src/scenes/online_lobby/online_lobby.cpp | 4 +++- src/scenes/online_lobby/online_lobby.hpp | 1 + src/scenes/scene.cpp | 9 ++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/scenes/online_lobby/online_lobby.cpp b/src/scenes/online_lobby/online_lobby.cpp index 307d94ce..f11ade0d 100644 --- a/src/scenes/online_lobby/online_lobby.cpp +++ b/src/scenes/online_lobby/online_lobby.cpp @@ -1,3 +1,5 @@ +#include "online_lobby.hpp" + #include #include #include @@ -7,7 +9,7 @@ #include "helper/platform.hpp" #include "manager/music_manager.hpp" #include "manager/resource_manager.hpp" -#include "online_lobby.hpp" + #include "ui/components/textinput.hpp" #include "ui/layout.hpp" #include "ui/layouts/scroll_layout.hpp" diff --git a/src/scenes/online_lobby/online_lobby.hpp b/src/scenes/online_lobby/online_lobby.hpp index b266313e..4503db98 100644 --- a/src/scenes/online_lobby/online_lobby.hpp +++ b/src/scenes/online_lobby/online_lobby.hpp @@ -1,6 +1,7 @@ #pragma once #include "lobby/api.hpp" + #include "scenes/scene.hpp" #include "ui/components/label.hpp" #include "ui/components/text_button.hpp" diff --git a/src/scenes/scene.cpp b/src/scenes/scene.cpp index a7f41891..3294d434 100644 --- a/src/scenes/scene.cpp +++ b/src/scenes/scene.cpp @@ -1,3 +1,9 @@ + +#if !defined(_ONLINE_MULTIPLAYER_NOT_SUPPORTED) +#include "online_lobby/online_lobby.hpp" +#endif + + #include "scenes/scene.hpp" #include "about_page/about_page.hpp" #include "main_menu/main_menu.hpp" @@ -8,9 +14,6 @@ #include "settings_menu/settings_menu.hpp" #include "single_player_game/single_player_game.hpp" -#if !defined(_ONLINE_MULTIPLAYER_NOT_SUPPORTED) -#include "online_lobby/online_lobby.hpp" -#endif namespace scenes { From 85a12c815f4260749d54db31b51e980491629fc8 Mon Sep 17 00:00:00 2001 From: "Totto16 (Windows VM)" Date: Sun, 26 May 2024 00:58:26 +0200 Subject: [PATCH 24/77] fix installer generation, copy executable from correct place --- tools/installer/setup.nsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/installer/setup.nsi b/tools/installer/setup.nsi index 279a4c04..17519eae 100644 --- a/tools/installer/setup.nsi +++ b/tools/installer/setup.nsi @@ -120,7 +120,7 @@ Section "Core App" CoreApp ; install executable SetOutPath "$INSTDIR" - File /a "${PROJECT_BUILD_DIR}\${APPFILE}" + File /a "${PROJECT_BUILD_DIR}\src\executables\${APPFILE}" ; install dynamic libraries SetOutPath "$INSTDIR" From 5f85e73678ec1179503720b6c29b4a15ca20e922 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 01:17:45 +0200 Subject: [PATCH 25/77] libs: fix installation of header files into correct folders --- src/libs/core/game/meson.build | 10 +++++++++- src/libs/core/hash-library/meson.build | 10 +++++++++- src/libs/core/helper/meson.build | 9 ++++++++- src/libs/core/meson.build | 8 +++++++- src/libs/meson.build | 1 + src/libs/recordings/meson.build | 8 +++++--- src/libs/recordings/utility/meson.build | 15 +++++++++++---- 7 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/libs/core/game/meson.build b/src/libs/core/game/meson.build index 024eaefd..c5f6f48c 100644 --- a/src/libs/core/game/meson.build +++ b/src/libs/core/game/meson.build @@ -4,9 +4,17 @@ core_src_files += files( 'tetromino_type.cpp', ) -core_header_files += files( +_header_files = files( 'grid_properties.hpp', 'mino.hpp', 'mino_stack.hpp', 'tetromino_type.hpp', ) + +core_header_files += _header_files + +install_headers( + _header_files, + install_dir: core_include_dir / 'game', + preserve_path: true, +) diff --git a/src/libs/core/hash-library/meson.build b/src/libs/core/hash-library/meson.build index 02a9348c..df1ddcc6 100644 --- a/src/libs/core/hash-library/meson.build +++ b/src/libs/core/hash-library/meson.build @@ -2,6 +2,14 @@ core_src_files += files( 'sha256.cpp', ) -core_header_files += files( +_header_files = files( 'sha256.h', ) + +core_header_files += _header_files + +install_headers( + _header_files, + install_dir: core_include_dir / 'hash-library', + preserve_path: true, +) diff --git a/src/libs/core/helper/meson.build b/src/libs/core/helper/meson.build index fd56c15b..1b371c15 100644 --- a/src/libs/core/helper/meson.build +++ b/src/libs/core/helper/meson.build @@ -8,7 +8,7 @@ core_src_files += files( 'string_manipulation.cpp', ) -core_header_files += files( +_header_files = files( 'bool_wrapper.hpp', 'color.hpp', 'color_literals.hpp', @@ -28,3 +28,10 @@ core_header_files += files( 'types.hpp', 'utils.hpp', ) +core_header_files += _header_files + +install_headers( + _header_files, + install_dir: core_include_dir / 'helper', + preserve_path: true, +) diff --git a/src/libs/core/meson.build b/src/libs/core/meson.build index ec710d94..2c4f12ac 100644 --- a/src/libs/core/meson.build +++ b/src/libs/core/meson.build @@ -1,6 +1,8 @@ core_src_files = [] core_header_files = [files('core.hpp')] +core_include_dir = include_dir / 'oopetris' / 'core' + subdir('game') subdir('hash-library') subdir('helper') @@ -32,7 +34,11 @@ meson.override_dependency('liboopetris-core', liboopetris_core_dep) # setting this to strings, so += {...} gets detected as an error, if it is done after that core_lib = 'undefined' -install_headers(core_header_files, subdir: 'oopetris/core', preserve_path: true) +install_headers( + files('core.hpp'), + install_dir: core_include_dir, + preserve_path: true, +) # generate pkgconfig files pkg = import('pkgconfig') diff --git a/src/libs/meson.build b/src/libs/meson.build index dcb9a76c..7f80bbb9 100644 --- a/src/libs/meson.build +++ b/src/libs/meson.build @@ -1,3 +1,4 @@ +include_dir = get_option('prefix') / get_option('includedir') core_lib += { 'inc_dirs': [core_lib.get('inc_dirs'), include_directories('.')], diff --git a/src/libs/recordings/meson.build b/src/libs/recordings/meson.build index db33ece9..3cccdb37 100644 --- a/src/libs/recordings/meson.build +++ b/src/libs/recordings/meson.build @@ -1,5 +1,7 @@ recordings_src_files = [] -recordings_header_files = [] +recordings_header_files = [files('recordings.hpp')] + +recordings_include_dir = include_dir / 'oopetris' / 'recordings' subdir('utility') @@ -36,8 +38,8 @@ meson.override_dependency('liboopetris-recordings', liboopetris_recordings_dep) recordings_lib = 'undefined' install_headers( - recordings_header_files, - subdir: 'oopetris/recordings', + files('recordings.hpp'), + install_dir: recordings_include_dir, preserve_path: true, ) diff --git a/src/libs/recordings/utility/meson.build b/src/libs/recordings/utility/meson.build index e5defa80..d6a782e0 100644 --- a/src/libs/recordings/utility/meson.build +++ b/src/libs/recordings/utility/meson.build @@ -7,15 +7,22 @@ recordings_src_files = files( 'tetrion_snapshot.cpp', ) - -recordings_header_files = files( +_header_files = files( 'additional_information.hpp', 'checksum_helper.hpp', + 'helper.hpp', 'recording.hpp', 'recording_json_wrapper.hpp', 'recording_reader.hpp', 'recording_writer.hpp', - 'tetrion_snapshot.hpp', - 'helper.hpp', 'tetrion_core_information.hpp', + 'tetrion_snapshot.hpp', +) + +recordings_header_files += _header_files + +install_headers( + _header_files, + install_dir: recordings_include_dir / 'utility', + preserve_path: true, ) From bf36137e14998ee24933a1619b95a12e577dcdbe Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 01:40:29 +0200 Subject: [PATCH 26/77] - format all meson files --- src/executables/game/meson.build | 2 +- src/executables/meson.build | 2 +- src/executables/platforms/3ds/meson.build | 24 ++++--------------- src/executables/platforms/windows/meson.build | 2 +- src/executables/utility/meson.build | 5 +++- src/game/meson.build | 4 ++-- src/helper/meson.build | 6 ++--- src/libs/core/meson.build | 10 +++++--- src/scenes/single_player_game/meson.build | 4 ++-- .../discord_game_sdk/cpp/meson.build | 12 +++------- .../discord_game_sdk/examples/cpp/meson.build | 2 -- .../discord_game_sdk/meson_options.txt | 2 -- tests/core/meson.build | 2 -- tests/graphics/meson.build | 2 -- tools/options/meson.build | 3 +-- 15 files changed, 29 insertions(+), 53 deletions(-) diff --git a/src/executables/game/meson.build b/src/executables/game/meson.build index 97fb2935..d9fc4ddb 100644 --- a/src/executables/game/meson.build +++ b/src/executables/game/meson.build @@ -1,6 +1,6 @@ main_files += files( 'application.cpp', 'application.hpp', - 'parser.hpp', 'main.cpp', + 'parser.hpp', ) diff --git a/src/executables/meson.build b/src/executables/meson.build index bbbc7de3..fb9b687c 100644 --- a/src/executables/meson.build +++ b/src/executables/meson.build @@ -35,7 +35,7 @@ if build_application if host_machine.system() == 'windows' subdir('platforms/windows') endif - + oopetris_exe = executable( 'oopetris', main_files, diff --git a/src/executables/platforms/3ds/meson.build b/src/executables/platforms/3ds/meson.build index 8b05e307..f8524f36 100644 --- a/src/executables/platforms/3ds/meson.build +++ b/src/executables/platforms/3ds/meson.build @@ -1,11 +1,9 @@ - ## get the options object and "unpack" it _3ds_exe_name = _3ds_options[0] _3ds_src_files = _3ds_options[1] _3ds_deps = _3ds_options[2] - # libraries _3ds_dependencies = [ @@ -29,7 +27,6 @@ _3ds_dependencies_native = [ 'SDL2main', ] - _3ds_library_dirs = meson.get_external_property('library_dirs', ['']) if _3ds_library_dirs.length() == 0 error('property \'library_dirs\' has to be set!') @@ -53,7 +50,6 @@ foreach dep : _3ds_dependencies_native ) endforeach - ## compilation _3ds_elf_file = build_target( @@ -72,7 +68,6 @@ use_smdh = ['true', 'True', '1', true].contains( meson.get_external_property('USE_SMDH', ''), ) - _3dsxtool = find_program('3dsxtool') _3DSX_FLAGS = [_3dsxtool, _3ds_elf_file.full_path(), _3ds_exe_name + '.3dsx'] @@ -95,7 +90,6 @@ if use_smdh endif SMDH_FLAGS += APP_DESC - APP_AUTHOR = meson.get_external_property('APP_AUTHOR', '') if APP_AUTHOR == '' error('If USE_SMDH is set, you have to provide an APP_AUTHOR') @@ -115,19 +109,13 @@ if use_smdh APP_ICON = meson.project_source_root() / APP_ICON endif - if not fs.exists(APP_ICON) error('APP_ICON should exist, but doesn\'t: \'' + APP_ICON + '\'') endif SMDH_FLAGS += APP_ICON - - SMDH_FLAGS += ( - _3ds_exe_name + '.smdh' # outfile - ) - - + SMDH_FLAGS += (_3ds_exe_name + '.smdh') APP_SMALL_ICON = meson.get_external_property('APP_SMALL_ICON', '') @@ -136,19 +124,17 @@ if use_smdh APP_SMALL_ICON = meson.project_source_root() / APP_SMALL_ICON endif - if not fs.exists(APP_SMALL_ICON) error( - 'APP_SMALL_ICON should exist, but doesn\'t: \'' + APP_SMALL_ICON + - '\'', + 'APP_SMALL_ICON should exist, but doesn\'t: \'' + + APP_SMALL_ICON + + '\'', ) endif SMDH_FLAGS += APP_SMALL_ICON endif - - # smdhtool --create <_3ds_exe_name>.smdh [] smdh_file = custom_target( _3ds_exe_name + '.smdh', @@ -161,8 +147,6 @@ if use_smdh endif - - APP_ROMFS = meson.get_external_property('APP_ROMFS', '') if APP_ROMFS != '' diff --git a/src/executables/platforms/windows/meson.build b/src/executables/platforms/windows/meson.build index 5d91bbdb..5a684a93 100644 --- a/src/executables/platforms/windows/meson.build +++ b/src/executables/platforms/windows/meson.build @@ -25,4 +25,4 @@ oopetris_win_rc = configure_file( oopetris_resource_windows = windows.compile_resources(oopetris_win_rc) -main_files += oopetris_resource_windows \ No newline at end of file +main_files += oopetris_resource_windows diff --git a/src/executables/utility/meson.build b/src/executables/utility/meson.build index 96961618..997e8923 100644 --- a/src/executables/utility/meson.build +++ b/src/executables/utility/meson.build @@ -1 +1,4 @@ -recordings_main_files += files('command_line_arguments.hpp', 'main.cpp',) +recordings_main_files += files( + 'command_line_arguments.hpp', + 'main.cpp', +) diff --git a/src/game/meson.build b/src/game/meson.build index 3013e4a2..0399f90a 100644 --- a/src/game/meson.build +++ b/src/game/meson.build @@ -1,6 +1,8 @@ graphics_src_files += files( 'bag.cpp', 'bag.hpp', + 'command_line_arguments.cpp', + 'command_line_arguments.hpp', 'game.cpp', 'game.hpp', 'graphic_helpers.cpp', @@ -13,6 +15,4 @@ graphics_src_files += files( 'tetrion.hpp', 'tetromino.cpp', 'tetromino.hpp', - 'command_line_arguments.hpp', - 'command_line_arguments.cpp', ) diff --git a/src/helper/meson.build b/src/helper/meson.build index 7d037666..f7210ff3 100644 --- a/src/helper/meson.build +++ b/src/helper/meson.build @@ -3,15 +3,15 @@ graphics_src_files += files( 'clock_source.hpp', 'console_helpers.cpp', 'console_helpers.hpp', + 'constants.hpp', + 'git_helper.hpp', 'graphic_utils.cpp', 'graphic_utils.hpp', 'message_box.cpp', 'message_box.hpp', 'music_utils.hpp', 'platform.cpp', - 'git_helper.hpp', 'platform.hpp', - 'constants.hpp' ) if have_file_dialogs @@ -21,7 +21,7 @@ endif git = find_program('git') vcs_dep = vcs_tag( - command: ['git', 'describe', '--tags', '--always', '--abbrev=12'], + command: [git, 'describe', '--tags', '--always', '--abbrev=12'], input: 'git_version.hpp.in', output: 'git_version.hpp', replace_string: '@GIT_VERSION@', diff --git a/src/libs/core/meson.build b/src/libs/core/meson.build index 2c4f12ac..3313eae0 100644 --- a/src/libs/core/meson.build +++ b/src/libs/core/meson.build @@ -31,9 +31,6 @@ liboopetris_core_dep = declare_dependency( ) meson.override_dependency('liboopetris-core', liboopetris_core_dep) -# setting this to strings, so += {...} gets detected as an error, if it is done after that -core_lib = 'undefined' - install_headers( files('core.hpp'), install_dir: core_include_dir, @@ -44,6 +41,13 @@ install_headers( pkg = import('pkgconfig') pkg.generate( liboopetris_core, + description: 'The core library for oopetris', + libraries: core_lib.get('deps'), name: 'oopetris-core', filebase: 'oopetris-core', + subdirs: 'oopetris', + extra_cflags: core_lib.get('compile_args'), ) + +# setting this to strings, so += {...} gets detected as an error, if it is done after that +core_lib = 'undefined' diff --git a/src/scenes/single_player_game/meson.build b/src/scenes/single_player_game/meson.build index 39c173eb..ff8d9e88 100644 --- a/src/scenes/single_player_game/meson.build +++ b/src/scenes/single_player_game/meson.build @@ -1,8 +1,8 @@ graphics_src_files += files( - 'pause.cpp', - 'pause.hpp', 'game_over.cpp', 'game_over.hpp', + 'pause.cpp', + 'pause.hpp', 'single_player_game.cpp', 'single_player_game.hpp', ) diff --git a/subprojects/packagefiles/discord_game_sdk/cpp/meson.build b/subprojects/packagefiles/discord_game_sdk/cpp/meson.build index 7bb508cd..af4886ba 100644 --- a/subprojects/packagefiles/discord_game_sdk/cpp/meson.build +++ b/subprojects/packagefiles/discord_game_sdk/cpp/meson.build @@ -1,4 +1,3 @@ - inc_dirs = include_directories('.') header_files = files( @@ -85,7 +84,6 @@ if c.get_id() == 'msvc' lib_name = 'discord_game_sdk.dll' endif - discord_lib_c = c.find_library( lib_name, dirs: [meson.project_source_root() / lib_dir], @@ -110,8 +108,7 @@ else objdump_result = run_command( objdump, - '-p', - meson.project_source_root() / lib_dir / dynamic_lib, + '-p', meson.project_source_root() / lib_dir / dynamic_lib, check: true, ).stdout().strip() @@ -123,11 +120,10 @@ else patchelf = find_program('patchelf') - #TODO: file issue to discord, to set SONAME + #TODO: file issue to discord, to set SONAME run_command( patchelf, - '--set-soname', - dynamic_lib_rename, + '--set-soname', dynamic_lib_rename, meson.project_source_root() / lib_dir / dynamic_lib, check: true, ) @@ -150,7 +146,6 @@ else endif - discord_lib = library( 'discord-game-sdk', src_files, @@ -165,4 +160,3 @@ discord_dep = declare_dependency( version: meson.project_version(), link_with: discord_lib, ) - diff --git a/subprojects/packagefiles/discord_game_sdk/examples/cpp/meson.build b/subprojects/packagefiles/discord_game_sdk/examples/cpp/meson.build index 2e6d27a4..f23b51ff 100644 --- a/subprojects/packagefiles/discord_game_sdk/examples/cpp/meson.build +++ b/subprojects/packagefiles/discord_game_sdk/examples/cpp/meson.build @@ -1,5 +1,3 @@ - - executable( 'main', files('main.cpp'), diff --git a/subprojects/packagefiles/discord_game_sdk/meson_options.txt b/subprojects/packagefiles/discord_game_sdk/meson_options.txt index 847cd6dc..fff7c896 100644 --- a/subprojects/packagefiles/discord_game_sdk/meson_options.txt +++ b/subprojects/packagefiles/discord_game_sdk/meson_options.txt @@ -1,5 +1,3 @@ - - option( 'examples', type: 'boolean', diff --git a/tests/core/meson.build b/tests/core/meson.build index 1964cd9d..3e51508e 100644 --- a/tests/core/meson.build +++ b/tests/core/meson.build @@ -1,3 +1 @@ - - core_test_src += files('color.cpp') diff --git a/tests/graphics/meson.build b/tests/graphics/meson.build index 50a19049..c1538b2d 100644 --- a/tests/graphics/meson.build +++ b/tests/graphics/meson.build @@ -1,3 +1 @@ - - graphics_test_src += files('sdl_key.cpp') diff --git a/tools/options/meson.build b/tools/options/meson.build index ee2244d6..9f0b62a0 100644 --- a/tools/options/meson.build +++ b/tools/options/meson.build @@ -3,8 +3,7 @@ oopetris_name = 'OOPetris' core_lib = { 'inc_dirs': [], - 'compile_args': [ - ], + 'compile_args': [], 'deps': [], } From d859d93d6b877b7183e8e009c88c1b136f7154f1 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 02:01:12 +0200 Subject: [PATCH 27/77] - fix pkconfig generation for core, by removing libraries, this is added automatically, by providing liboopetris_core - now fmt works with clang, so not using header only lib anymore --- src/libs/core/meson.build | 2 +- tools/dependencies/meson.build | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libs/core/meson.build b/src/libs/core/meson.build index 3313eae0..89c80342 100644 --- a/src/libs/core/meson.build +++ b/src/libs/core/meson.build @@ -39,10 +39,10 @@ install_headers( # generate pkgconfig files pkg = import('pkgconfig') + pkg.generate( liboopetris_core, description: 'The core library for oopetris', - libraries: core_lib.get('deps'), name: 'oopetris-core', filebase: 'oopetris-core', subdirs: 'oopetris', diff --git a/tools/dependencies/meson.build b/tools/dependencies/meson.build index f3c3199d..41ad9861 100644 --- a/tools/dependencies/meson.build +++ b/tools/dependencies/meson.build @@ -34,9 +34,6 @@ if ( and (host_machine.system() == 'switch' or host_machine.system() == '3ds') ) fmt_use_header_only = true - # clang with libc++ creates some really long and confusing linker errors, so just use the header only library -elif cpp.get_id() == 'clang' and build_with_libcpp - fmt_use_header_only = true endif if fmt_use_header_only From 8aad3df1b582ae3edc8ea75f41ba3f5760fe3760 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 02:03:09 +0200 Subject: [PATCH 28/77] fix pkgconfig file genration for liboopetris_recordings --- src/libs/recordings/meson.build | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/recordings/meson.build b/src/libs/recordings/meson.build index 3cccdb37..e1a93e85 100644 --- a/src/libs/recordings/meson.build +++ b/src/libs/recordings/meson.build @@ -34,9 +34,6 @@ liboopetris_recordings_dep = declare_dependency( ) meson.override_dependency('liboopetris-recordings', liboopetris_recordings_dep) -# setting this to strings, so += {...} gets detected as an error, if it is done after that -recordings_lib = 'undefined' - install_headers( files('recordings.hpp'), install_dir: recordings_include_dir, @@ -47,6 +44,12 @@ install_headers( pkg = import('pkgconfig') pkg.generate( liboopetris_recordings, + description: 'The recordings library for oopetris', name: 'oopetris-recordings', filebase: 'oopetris-recordings', + subdirs: 'oopetris', + extra_cflags: recordings_lib.get('compile_args'), ) + +# setting this to strings, so += {...} gets detected as an error, if it is done after that +recordings_lib = 'undefined' From 23a29f07b502dde70ce01003e23da2d2190ecda0 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 02:34:24 +0200 Subject: [PATCH 29/77] dependencies: make tl- expected installable --- .../packagefiles/expected-1.1.0_installable.diff | 14 ++++++++++++++ subprojects/tl-expected.wrap | 2 ++ 2 files changed, 16 insertions(+) create mode 100644 subprojects/packagefiles/expected-1.1.0_installable.diff diff --git a/subprojects/packagefiles/expected-1.1.0_installable.diff b/subprojects/packagefiles/expected-1.1.0_installable.diff new file mode 100644 index 00000000..20cf408b --- /dev/null +++ b/subprojects/packagefiles/expected-1.1.0_installable.diff @@ -0,0 +1,14 @@ +diff --git a/meson.build b/meson.build +index cf5efb7..4882184 100644 +--- a/meson.build ++++ b/meson.build +@@ -12,3 +12,9 @@ tl_expected_dep = declare_dependency( + if meson.version().version_compare('>=0.54.0') + meson.override_dependency('tl-expected', tl_expected_dep) + endif ++ ++ ++install_headers( ++ files('include/tl/expected.hpp'), ++ subdir: 'tl', ++) diff --git a/subprojects/tl-expected.wrap b/subprojects/tl-expected.wrap index 9559e649..ee1dd8a5 100644 --- a/subprojects/tl-expected.wrap +++ b/subprojects/tl-expected.wrap @@ -9,5 +9,7 @@ patch_hash = 8b1aa60a1ddd604494628f0c6b0ed569b9e1e2dc17dfdc09d5de5563ae8adfe3 source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/tl-expected_1.1.0-1/expected-1.1.0.tar.gz wrapdb_version = 1.1.0-1 +diff_files = expected-1.1.0_installable.diff + [provide] tl-expected = tl_expected_dep From e321bd1acfa030029e031b77b5bc0351e6d0baa0 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 02:34:44 +0200 Subject: [PATCH 30/77] dependencies: make magic-enum installable --- src/libs/core/helper/magic_enum_wrapper.hpp | 2 +- subprojects/magic_enum.wrap | 2 ++ .../magic_enum-0.9.5_installed.diff | 32 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 subprojects/packagefiles/magic_enum-0.9.5_installed.diff diff --git a/src/libs/core/helper/magic_enum_wrapper.hpp b/src/libs/core/helper/magic_enum_wrapper.hpp index d62cd664..b3b64dd7 100644 --- a/src/libs/core/helper/magic_enum_wrapper.hpp +++ b/src/libs/core/helper/magic_enum_wrapper.hpp @@ -8,4 +8,4 @@ #define MAGIC_ENUM_RANGE_MAX 256 // NOLINT(cppcoreguidelines-macro-usage) #endif -#include +#include diff --git a/subprojects/magic_enum.wrap b/subprojects/magic_enum.wrap index a1870879..cd0237cf 100644 --- a/subprojects/magic_enum.wrap +++ b/subprojects/magic_enum.wrap @@ -6,5 +6,7 @@ source_hash = 44ad80db5a72f5047e01d90e18315751d9ac90c0ab42cbea7a6f9ec66a4cd679 source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/magic_enum_0.9.5-1/magic_enum-v0.9.5.tar.gz wrapdb_version = 0.9.5-1 +diff_files = magic_enum-0.9.5_installed.diff + [provide] magic_enum = magic_enum_dep diff --git a/subprojects/packagefiles/magic_enum-0.9.5_installed.diff b/subprojects/packagefiles/magic_enum-0.9.5_installed.diff new file mode 100644 index 00000000..c695f85e --- /dev/null +++ b/subprojects/packagefiles/magic_enum-0.9.5_installed.diff @@ -0,0 +1,32 @@ +diff --git a/meson.build b/meson.build +index c231c7f..66f96ac 100644 +--- a/meson.build ++++ b/meson.build +@@ -4,7 +4,7 @@ project( + version: '0.9.5', + ) + +-magic_enum_include = include_directories('include/magic_enum') ++magic_enum_include = include_directories('include') + + magic_enum_args = [] + +@@ -20,3 +20,18 @@ magic_enum_dep = declare_dependency( + if get_option('test') + subdir('test') + endif ++ ++install_headers( ++ files( ++ 'include/magic_enum/magic_enum.hpp', ++ 'include/magic_enum/magic_enum_all.hpp', ++ 'include/magic_enum/magic_enum_containers.hpp', ++ 'include/magic_enum/magic_enum_flags.hpp', ++ 'include/magic_enum/magic_enum_format.hpp', ++ 'include/magic_enum/magic_enum_fuse.hpp', ++ 'include/magic_enum/magic_enum_iostream.hpp', ++ 'include/magic_enum/magic_enum_switch.hpp', ++ 'include/magic_enum/magic_enum_utility.hpp', ++ ), ++ subdir: 'magic_enum', ++) From f1de2a9b81afd33e95a13840a79e8fb3c3a5ea5f Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 02:40:31 +0200 Subject: [PATCH 31/77] dependencies: make nlohmann_json installable --- subprojects/nlohmann_json.wrap | 2 ++ .../nlohmann_json-3.11.2_installable.diff | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 subprojects/packagefiles/nlohmann_json-3.11.2_installable.diff diff --git a/subprojects/nlohmann_json.wrap b/subprojects/nlohmann_json.wrap index bf5d7000..994dec25 100644 --- a/subprojects/nlohmann_json.wrap +++ b/subprojects/nlohmann_json.wrap @@ -6,5 +6,7 @@ source_filename = nlohmann_json-3.11.2.zip source_hash = e5c7a9f49a16814be27e4ed0ee900ecd0092bfb7dbfca65b5a421b774dccaaed wrapdb_version = 3.11.2-1 +diff_files = nlohmann_json-3.11.2_installable.diff + [provide] nlohmann_json = nlohmann_json_dep diff --git a/subprojects/packagefiles/nlohmann_json-3.11.2_installable.diff b/subprojects/packagefiles/nlohmann_json-3.11.2_installable.diff new file mode 100644 index 00000000..8ab3d7f1 --- /dev/null +++ b/subprojects/packagefiles/nlohmann_json-3.11.2_installable.diff @@ -0,0 +1,20 @@ +diff --git a/meson.build b/meson.build +index e2fb86f..4ddae11 100644 +--- a/meson.build ++++ b/meson.build +@@ -12,13 +12,12 @@ nlohmann_json_multiple_headers = declare_dependency( + include_directories: include_directories('include') + ) + +-if not meson.is_subproject() ++ + install_headers('single_include/nlohmann/json.hpp', subdir: 'nlohmann') +-install_headers('single_include/nlohmann/json_fwd.hpp', subdir: 'nlohmann') + + pkgc = import('pkgconfig') + pkgc.generate(name: 'nlohmann_json', + version: meson.project_version(), + description: 'JSON for Modern C++' + ) +-endif ++ From 58adee0ecb28c656fdf66e4316414add012adc66 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 02:58:19 +0200 Subject: [PATCH 32/77] - add more noexcept methods for working with json - use them, to be really noexcept in the utility --- src/executables/utility/main.cpp | 12 +++++++----- src/libs/core/helper/parse_json.hpp | 28 ++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/executables/utility/main.cpp b/src/executables/utility/main.cpp index 003d3bf2..0040fbb9 100644 --- a/src/executables/utility/main.cpp +++ b/src/executables/utility/main.cpp @@ -7,18 +7,20 @@ #include void print_info(const recorder::RecordingReader& recording_reader) noexcept { - //TODO(Totto): Implement + //TODO(Totto): Implement, print basic information and final result for each simulation UNUSED(recording_reader); std::cerr << "NOT IMPLEMENTED\n"; } void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_print, bool ensure_ascii) noexcept { - nlohmann::json json_value; + auto result = json::try_convert_to_json(recording_reader); - //TODO: use parse_json helper + if (not result.has_value()) { + std::cerr << fmt::format("An error occurred during converting to json: {}\n", result.error()); + std::exit(1); + } - nlohmann::adl_serializer::to_json(json_value, recording_reader); int indent = -1; char indent_char = ' '; @@ -28,7 +30,7 @@ void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_pr indent_char = '\t'; } - std::cout << json_value.dump(indent, indent_char, ensure_ascii); + std::cout << result.value().dump(indent, indent_char, ensure_ascii); if (pretty_print) { std::cout << "\n"; diff --git a/src/libs/core/helper/parse_json.hpp b/src/libs/core/helper/parse_json.hpp index e7c8434e..cd6923f2 100644 --- a/src/libs/core/helper/parse_json.hpp +++ b/src/libs/core/helper/parse_json.hpp @@ -49,7 +49,6 @@ NLOHMANN_JSON_NAMESPACE_END namespace json { - template [[nodiscard]] helper::expected try_parse_json(const std::string& content) noexcept { @@ -88,17 +87,38 @@ namespace json { } + template + [[nodiscard]] helper::expected try_convert_to_json(const T& input) noexcept { + + try { + nlohmann::json value = input; + return value; + } catch (nlohmann::json::type_error& type_error) { + return helper::unexpected{ fmt::format("type error: {}", type_error.what()) }; + } catch (nlohmann::json::exception& exception) { + return helper::unexpected{ fmt::format("unknown json exception: {}", exception.what()) }; + } catch (std::exception& exception) { + return helper::unexpected{ fmt::format("unknown exception: {}", exception.what()) }; + } + } + + template [[nodiscard]] helper::expected try_json_to_string(const T& type, const bool pretty = false) noexcept { try { - const nlohmann::json value = type; + auto value = try_convert_to_json(type); + + if (not value.has_value()) { + return helper::unexpected{ value.error() }; + } + if (pretty) { - return value.dump(1, '\t'); + return value.value().dump(1, '\t'); } - return value.dump(-1, ' '); + return value.value().dump(-1, ' '); } catch (nlohmann::json::type_error& type_error) { return helper::unexpected{ fmt::format("type error: {}", type_error.what()) }; From 985befab1f39835f055fb086f3352caf051f0f10 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 03:45:34 +0200 Subject: [PATCH 33/77] fix utility executable for windows installer --- tools/installer/setup.nsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/installer/setup.nsi b/tools/installer/setup.nsi index 17519eae..88d15ace 100644 --- a/tools/installer/setup.nsi +++ b/tools/installer/setup.nsi @@ -214,7 +214,7 @@ SectionEnd Section "Additional Binaries" AdditionalBinaries ; install helper binaries SetOutPath "$INSTDIR\bin" - File /a "${PROJECT_BUILD_DIR}\oopetris_recordings_utility.exe" + File /a "${PROJECT_BUILD_DIR}\src\executables\oopetris_recordings_utility.exe" ; add the bin dir to the path EnVar::SetHKCU From deab69d12d49996d29845c7642a31ce5044ccad9 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 17:01:31 +0200 Subject: [PATCH 34/77] add a few things regarding version to the core library, so taht it can be used in wrappers --- src/helper/constants.hpp | 3 +++ src/libs/core/core.hpp | 1 + src/libs/core/helper/meson.build | 1 + src/libs/core/helper/versions.hpp | 28 ++++++++++++++++++++++++++++ tools/options/meson.build | 4 +++- 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/libs/core/helper/versions.hpp diff --git a/src/helper/constants.hpp b/src/helper/constants.hpp index 79e11f35..d9189081 100644 --- a/src/helper/constants.hpp +++ b/src/helper/constants.hpp @@ -19,6 +19,9 @@ namespace constants { constexpr auto recordings_directory = "recordings"; constexpr u32 simulation_frequency = 60; +#undef STRINGIFY +#undef STRINGIFY_HELPER_ + #if not defined(AUDIO_QUALITY) #define AUDIO_QUALITY 0 // NOLINT(cppcoreguidelines-macro-usage) #endif diff --git a/src/libs/core/core.hpp b/src/libs/core/core.hpp index cdcc451e..9c15c3dd 100644 --- a/src/libs/core/core.hpp +++ b/src/libs/core/core.hpp @@ -30,3 +30,4 @@ #include "./helper/timer.hpp" #include "./helper/types.hpp" #include "./helper/utils.hpp" +#include "./helper/versions.hpp" diff --git a/src/libs/core/helper/meson.build b/src/libs/core/helper/meson.build index 1b371c15..b0e2eecf 100644 --- a/src/libs/core/helper/meson.build +++ b/src/libs/core/helper/meson.build @@ -27,6 +27,7 @@ _header_files = files( 'timer.hpp', 'types.hpp', 'utils.hpp', + 'versions.hpp', ) core_header_files += _header_files diff --git a/src/libs/core/helper/versions.hpp b/src/libs/core/helper/versions.hpp new file mode 100644 index 00000000..dd95efc8 --- /dev/null +++ b/src/libs/core/helper/versions.hpp @@ -0,0 +1,28 @@ +#include + + +namespace utils { + + +#define STRINGIFY(a) STRINGIFY_HELPER_(a) //NOLINT(cppcoreguidelines-macro-usage) +#define STRINGIFY_HELPER_(a) #a //NOLINT(cppcoreguidelines-macro-usage) + + +#if !defined(OOPETRIS_VERSION) +#error "OOPETRIS_VERSION not defined" +#endif + + + + [[nodiscard]] inline std::string version() { + + + return STRINGIFY(OOPETRIS_VERSION); + } + + +#undef STRINGIFY +#undef STRINGIFY_HELPER_ + + +} // namespace utils diff --git a/tools/options/meson.build b/tools/options/meson.build index 9f0b62a0..bc36429c 100644 --- a/tools/options/meson.build +++ b/tools/options/meson.build @@ -3,7 +3,9 @@ oopetris_name = 'OOPetris' core_lib = { 'inc_dirs': [], - 'compile_args': [], + 'compile_args': [ + '-DOOPETRIS_VERSION=' + meson.project_version(), + ], 'deps': [], } From dcc1946125532d8a1917f08ce4fbdaf3622625e1 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 17:01:38 +0200 Subject: [PATCH 35/77] add wrapper readme --- wrapper/README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 wrapper/README.md diff --git a/wrapper/README.md b/wrapper/README.md new file mode 100644 index 00000000..5ca2d7bc --- /dev/null +++ b/wrapper/README.md @@ -0,0 +1,25 @@ +# OOPetris wrapper + +## What is this + +This are wrappers of some OOPEtris functionaility in other languages + +They currently wrap this: +- OOPetris Recordings + +Planned: +- OOPetris AI support + +## Languages + + +Current: +- Node.js + +Planned: +- Python +- Lua + +## Other + +For more information on how to get / build those, refer to the subfolders of the languages From 7a00c8de6aa64a2320863ae7e5765f9b4fdc8b6a Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 17:06:55 +0200 Subject: [PATCH 36/77] add node js wrapper --- wrapper/javascript/.gitignore | 7 + wrapper/javascript/.npmrc | 1 + wrapper/javascript/README.md | 23 + wrapper/javascript/binding.gyp | 33 + wrapper/javascript/jest.config.ts | 9 + wrapper/javascript/package.json | 49 + wrapper/javascript/src/cpp/wrapper.cpp | 144 + wrapper/javascript/src/meson.build | 1 + wrapper/javascript/src/ts/index.ts | 110 + wrapper/javascript/tests/files/correct.rec | Bin 0 -> 18189 bytes .../tests/files/correct.serialized.json | 6725 +++++++++++++++++ wrapper/javascript/tests/files/incorrect.rec | Bin 0 -> 50 bytes wrapper/javascript/tests/raw.test.ts | 126 + wrapper/javascript/tests/test.spec.ts | 87 + wrapper/javascript/tsconfig.json | 26 + 15 files changed, 7341 insertions(+) create mode 100644 wrapper/javascript/.gitignore create mode 100644 wrapper/javascript/.npmrc create mode 100644 wrapper/javascript/README.md create mode 100644 wrapper/javascript/binding.gyp create mode 100644 wrapper/javascript/jest.config.ts create mode 100644 wrapper/javascript/package.json create mode 100644 wrapper/javascript/src/cpp/wrapper.cpp create mode 100644 wrapper/javascript/src/meson.build create mode 100644 wrapper/javascript/src/ts/index.ts create mode 100644 wrapper/javascript/tests/files/correct.rec create mode 100644 wrapper/javascript/tests/files/correct.serialized.json create mode 100644 wrapper/javascript/tests/files/incorrect.rec create mode 100644 wrapper/javascript/tests/raw.test.ts create mode 100644 wrapper/javascript/tests/test.spec.ts create mode 100644 wrapper/javascript/tsconfig.json diff --git a/wrapper/javascript/.gitignore b/wrapper/javascript/.gitignore new file mode 100644 index 00000000..0014accc --- /dev/null +++ b/wrapper/javascript/.gitignore @@ -0,0 +1,7 @@ +/build/ + +node_modules/ + +package-lock.json + +/dist \ No newline at end of file diff --git a/wrapper/javascript/.npmrc b/wrapper/javascript/.npmrc new file mode 100644 index 00000000..134dfd1e --- /dev/null +++ b/wrapper/javascript/.npmrc @@ -0,0 +1 @@ +registry=https://verdaccio.totto.lt/ diff --git a/wrapper/javascript/README.md b/wrapper/javascript/README.md new file mode 100644 index 00000000..500de2e1 --- /dev/null +++ b/wrapper/javascript/README.md @@ -0,0 +1,23 @@ +# OOpetris Noe.js Wrapper + + +## What is this? + +This wraps oopetris functionality for Node.js + + + + + +## Platform support + +We officially support Linux, Windows and MacOS, if any error occurs regarding those platform, feel free to open an issue + +## How to obtain + +A prebuilt package is WIP and they can be obtained, by using [Totto's private node package registry](https://verdaccio.totto.lt/) + + +## How to build it yourself + +This uses node-gyp to build the wrapper, you need to install `libboopetris_recordings` to be able to use this. diff --git a/wrapper/javascript/binding.gyp b/wrapper/javascript/binding.gyp new file mode 100644 index 00000000..a4ee2396 --- /dev/null +++ b/wrapper/javascript/binding.gyp @@ -0,0 +1,33 @@ +# type: ignore +{ + "targets": [ + { + "cflags_cc": [ + "-std=c++23", + "-Wall", + "-Wextra", + "-Wno-unused-parameter", + "-O3", + "-Werror", + "-Wpedantic", + "-fexceptions", + "-frtti", + "-Wno-cast-function-type", # since nan.h -> node.h has some warnings regarding that + " + +#include +#include + +NAN_METHOD(isRecordingFile) { + + if (info.Length() != 1) { + info.GetIsolate()->ThrowException(Nan::TypeError("Wrong number of arguments")); + return; + } + + if (!info[0]->IsString()) { + info.GetIsolate()->ThrowException( + Nan::TypeError("First argument must be string")); + return; + } + + auto filePath = std::string{*Nan::Utf8String(info[0])}; + + if (not std::filesystem::exists(filePath)) { + + info.GetReturnValue().Set(Nan::False()); + return; + } + + auto parsed = recorder::RecordingReader::from_path(filePath); + + if (not parsed.has_value()) { + info.GetReturnValue().Set(Nan::False()); + return; + } + + info.GetReturnValue().Set(Nan::True()); + return; +} + +NAN_METHOD(getInformation) { + + if (info.Length() != 1) { + info.GetIsolate()->ThrowException(Nan::TypeError("Wrong number of arguments")); + return; + } + + if (!info[0]->IsString()) { + info.GetIsolate()->ThrowException( + Nan::TypeError("First argument must be string")); + return; + } + + auto filePath = std::string{*Nan::Utf8String(info[0])}; + + if (not std::filesystem::exists(filePath)) { + std::string error = "File '"; + error += filePath; + error += "' doesn't exist!"; + + info.GetIsolate()->ThrowException( + Nan::Error(Nan::New(error).ToLocalChecked())); + return; + } + + auto parsed = recorder::RecordingReader::from_path(filePath); + + if (not parsed.has_value()) { + std::string error = + "An error occurred during parsing of the recording file '"; + error += filePath; + error += "': "; + error += parsed.error(); + + info.GetIsolate()->ThrowException( + Nan::Error(Nan::New(error).ToLocalChecked())); + return; + } + + const auto recording_reader = std::move(parsed.value()); + + auto json_value = + json::try_convert_to_json(recording_reader); + + if (not json_value.has_value()) { + std::string error = "An error occurred during converting to json:"; + error += json_value.error(); + + info.GetIsolate()->ThrowException( + Nan::Error(Nan::New(error).ToLocalChecked())); + return; + } + + const auto result_string_json = json_value->dump(-1, ' ', false); + + v8::Local js_json_string = + Nan::New(result_string_json).ToLocalChecked(); + + Nan::JSON NanJSON; + Nan::MaybeLocal result = NanJSON.Parse(js_json_string); + if (!result.IsEmpty()) { + v8::Local val = result.ToLocalChecked(); + info.GetReturnValue().Set(val); + return; + } + + info.GetIsolate()->ThrowException( + Nan::Error("Failed to parse internal JSON structure!")); + return; +} + +NAN_MODULE_INIT(InitAll) { + Nan::Set(target, Nan::New("isRecordingFile").ToLocalChecked(), + Nan::GetFunction(Nan::New(isRecordingFile)) + .ToLocalChecked()); + + Nan::Set(target, Nan::New("getInformation").ToLocalChecked(), + Nan::GetFunction(Nan::New(getInformation)) + .ToLocalChecked()); + + Nan::Set(target, Nan::New("version").ToLocalChecked(), + Nan::New(utils::version()).ToLocalChecked()); + + v8::Local properties = Nan::New(); + + std::vector> properties_vector{ + {"height", grid::height_in_tiles}, {"width", grid::width_in_tiles}}; + + v8::Local grid_properties = Nan::New(); + + for (const auto &[key, value] : properties_vector) { + v8::Local keyValue = Nan::New(key).ToLocalChecked(); + grid_properties + ->Set(Nan::GetCurrentContext(), keyValue, Nan::New(value)) + .Check(); + } + + properties + ->Set(Nan::GetCurrentContext(), + Nan::New("gridProperties").ToLocalChecked(), + grid_properties) + .Check(); + + Nan::Set(target, Nan::New("properties").ToLocalChecked(), properties); +} + +NODE_MODULE(RecordingsWrapper, InitAll) diff --git a/wrapper/javascript/src/meson.build b/wrapper/javascript/src/meson.build new file mode 100644 index 00000000..0da0da81 --- /dev/null +++ b/wrapper/javascript/src/meson.build @@ -0,0 +1 @@ +src_files += files('cpp/wrapper.cpp') diff --git a/wrapper/javascript/src/ts/index.ts b/wrapper/javascript/src/ts/index.ts new file mode 100644 index 00000000..a41bb907 --- /dev/null +++ b/wrapper/javascript/src/ts/index.ts @@ -0,0 +1,110 @@ +import fs from "fs" + +const oopetris = require("bindings")("oopetris") //require("./build/Release/oopetris.node") + +export type AdditionalInformation = Record + +export type InputEvent = + | "RotateLeftPressed" + | "RotateRightPressed" + | "MoveLeftPressed" + | "MoveRightPressed" + | "MoveDownPressed" + | "DropPressed" + | "HoldPressed" + | "RotateLeftReleased" + | "RotateRightReleased" + | "MoveLeftReleased" + | "MoveRightReleased" + | "MoveDownReleased" + | "DropReleased" + | "HoldReleased" + +export type TetrionRecord = { + event: InputEvent + simulation_step_index: number + tetrion_index: number +} + +export type MinoPosition = { + x: number + y: number +} + +export type TetrominoType = "I" | "J" | "L" | "O" | "S" | "T" | "Z" + +export type Mino = { + position: MinoPosition + type: TetrominoType +} + +export type TetrionSnapshot = { + level: number + lines_cleared: number + mino_stack: Mino[] + score: number + simulation_step_index: number + tetrion_index: number +} + +export type TetrionHeader = { + seed: number + starting_level: number +} + +export type RecordingInformation = { + information: AdditionalInformation + records: TetrionRecord[] + snapshots: TetrionSnapshot[] + tetrion_headers: TetrionHeader[] + version: number +} + +export type GridProperties = { + height: number + width: number +} + +export type RecordingsProperties = { + gridProperties: GridProperties +} + +export class RecordingsUtility { + static isRecordingFile(file: string): boolean { + try { + // this throws, when file is not an string or not there at all, just be safe for JS land + return oopetris.isRecordingFile(file) + } catch (_err) { + return false + } + } + + static getInformation(file: string): null | RecordingInformation { + if (!fs.existsSync(file)) { + return null + } + + try { + if (!RecordingsUtility.isRecordingFile(file)) { + return null + } + + // this throws, when file is not an string, not there at all, or some other error regarding serialization from c++ land to JS land occurs, just be safe for JS land + return oopetris.getInformation(file) + } catch (_err) { + return null + } + } + + static get properties(): GridProperties { + return oopetris.properties + } + + static get version(): string { + return oopetris.version + } + + private get cppModulePath(): string { + return oopetris.path + } +} diff --git a/wrapper/javascript/tests/files/correct.rec b/wrapper/javascript/tests/files/correct.rec new file mode 100644 index 0000000000000000000000000000000000000000..4d1a9cead3d4679bc936f50937eb5609e3fbe034 GIT binary patch literal 18189 zcmdU%3$#?#dB@LtX70T1%tfn~g@lDduc*WadW{mKYO>l`sL_IrO??1rLW-71>d6B43OB7?9`kRR|2{wSjEiT?y72rU za&OK`_&e>4i>H_S`reoh2hMQ*tZCDOI&jgs7o0tF`k(WeOQv6V)Xx_DUGiYE>cvAB zuNpCT{(roD&7~XndFkM1uKLk|M;^2C;HQro{kd;U*mv0*XJ2voiajHg7)n z@ufpo+`4$el^Z5r-y8gu>ws6>8!XHz2z!I8gyr5~u~~04>(|VBn_2G_rU&%Hk$UU? z@kK5c_o}qgN;@sL(@Ia;8+<1>23@_uL&92b@O@#_8$2bf^aei_;_)wpeC%x@&WB;n zIA0May+KP@?G5%6((Z7pu%D1F4inN?pOD7J3+ecHA&vcskS;!J)-#24F-<5@mda80 zk1ujb;9f;h(w-#aXeXsMO;1-NM0&0efzB7=vPYb|XkdrW^*5dW@kKS+w$@?X3gdQ| zw8ONG2L4k7^9A!`j`{IL^TQ*4%(c26rGZ!7dEtw?x5K5R6{W2x#9-BFo+(J>&1aCj&aMnUcP9g-fznUEM|K#vx>u2 zl&k1sTnmy~kk*2%Mka1F8HdR!#2qQDv)Tz6{>eh3oFZfmJYT3xoTj%f8ecT}LkO+X z%qrbknWIHObL166ahZ^H(Pcf^uh+3{jOeF5gh@3Lz>l7E<9RAtK&k z);rC*T8OldT7}1isQiT0ea7lOXB9S@^%b)Y(YBJ2-baX&V}$f}h>$M&%sSDmQ-wrv znvf{w3pF?+edi2_FFI(K7@V-0hP5=RrD2^p@D;hu=qwSU%r}K7^U%P!e3H7;gD*N{ zmy0W@XDLS`%iNaW`xfI`i}9xx<1<1=|9K&!zgegey|gf*zG&Po9eG+!(pr*n)LHl6 zP&kZqnC54&^WnUrrI!Z{sjuRr$ zF+wEzxYeC#btefW+@}h{`JxHCv2bZumR7TbqsF=P(+U>lPBk^o79!UyA#%+XqUSuJ zG+HW++!XXhojx<<7X-GNRt>%eL}XLGNk~benp^2h^^ip^u19(Ll&W#L8s`~=3Te%$ zKmziup6~WSoq(@YXee@vkX%|Sq{7#QC~~_HMV4EIl~&;aAuV{Mh1K@4?^@k;LTS3D zps6qF^tol{Xc|_dh@%!ob#(Z-!bIO!g;;+hM9ESqpIr#mC8R=4i0Z?I66%G5P`;?s z3;)g+DyXDER~mMuL6vR&2!)J1qlD;pu#hvuI3bJSL?Qb9z7Wy=OeoQ2`jaPG`=UT$Uqv&#?bE>DO$;OtOKgL=vZtjsO=XD9?BpCu$QE*2uq0wH=_ zEkuuNg^K*9Lgc=v)BFC;MjqFbgrnwm|GmKt3I`SLw0Iw|cpny`&ErC}`H5M7X4aR4 z(#G%FoJ788r?2DNl@vaXm_KC8y8@?79jXz28s#r~GX9_ii-^Q0_fp8T#^_Z1@K zN36nVA)0jr$+u4lY4;?dn}1e!y49U+);VUqOsG*=SIAgjwA0T79T}CR8m1gw zVOl|*1qzc9T4XwWRY--Kg@}5Kkg-@IMAW;5jKyjpAA8g){6xqIJu9TK4MOSrT0vi5 zw9`)@9oILkW)Vj%i`_o&MTP8UgAk?O5+Y?%$)~cST8IzF3(<12)t%z&9?WlG?F~Z2dRd5AuLuz<(DNl&*|zt;uyzZ{n_)t7cRwMyJ66byKSIciA8&O}5Yp}> zA?;2TBDcGNG14y~urC^&JF(rFSG>i(CEB zhIhze;=D&loNI)P;SYq2;lBxyXPuB1o)wY>FA34)4I!GmBc!p!Jsii2#>zr^s|#s& zsE`)=gtXvMs?IB@>Wg;tY|yFXDXLnoCFOcj;c$2T$14sLK2eAgpBAFT6d_8?5Te8a zAxc~=M2YK#QsSr$!dW-A$$KSxq&CJ`d`>*yXf#a;IR+c>#R>U>Oyw#NyH_C%|2x>?UP>xDwU zb`=8mMLT-k>9^)qM*kzXdnI$ucs{Ed(yUo1qLzZEk2Hw%&R zTS8h`A>?EC2x;toAs_pJP};4Rc5dbKMPoXdGy~GbCkpw&(?%{onr@QinUPDAZyC~N znl;l>lbym^IgC=9gar4xMZ|-V{V(LH3DM+_go^WIZ71BM^F{j)R-E}+nh44F0b8JE z7;|*v|H*QXsAdWoz1c#B>`OxG&KELzYlN&6PY78lUbMO|Tis1U+WjA^@UD<9oSW`N zyCosL)yz6n=vE*h%JvF<21!{rAiik0YnIoRXR?crA8&aSm?v%rOt+SM-Y)-Y!X~HO zo#0@;jn0!O>2})jEuZIfOB^ly8Y^eeae{e!ig`Ojhzb`734M-GF_d-UcQN>)k^K=2 zehkI5=S#XABcA!@`B#Jt&tf4#+$d!HmRQ}}t?r#xVTD=mGwZ`b8hb=2MUE~g;)}Ly zd;OF4gEXo|MJkQ7(oDA1Uypra;v*Y zNQ^hw$8Ho7?#)74SY>q|u?mj~Y4=$nK0GgEJ=`c{J$yw-Z?6gI;%y-<)Y^Fx(83-< z>JAkW&M+O%oE? zc|yXu#H?R3>jI%7TUm(A7j4^m_`xH~y5mxJoVDVTyFzu993#rbLaet68L58|GCa$L z#D15M*jEaPeT`Y4H0wIEZZPYAn)ScT`fDLRyeFi$tS29JtTmy_ETPLRAwG<>x?`;F zVM50B7$JFliq$>M>Ygqn_;Z8=Kg+Ba3vuT!til(Ccy_7Poo^MsDpU^mZ!K=c@kQHq z2Iy=Kr1dD{Xhc~PC6~xa^5HfiVcso7l6!=N>5&Te%ZgB|t?r{{{gHjlqjVUeou<>l z7j4-g55me@oaM#2P}G5qu{$O5*PRvD%Xc){EJUea3(2{+g~$`=M@R@!6CzJrh-gEF zv@k+Q3!{Y6#D7_Hn)srz`5btkJ>THvMo|-dx|gvjF_`unm@ zsm|()q*%Z&G4uUl{tK|Qo#{t*?Fa#qb{4m@pdEzmDB|eB(@km|1xkD5A`@$mkXSw9 z|K76V|Nd6@P$3l#w~zH%-N{1Knj%E4vxM~a*Ft*ps92vW#OjOW@OH;q>PgBR?WE#< zjk!pD68A0U$?fLJau!G75hvWE4&{>se-BpRfxag@8p>){Z|$A z_eC;ohyGzZjN0xuv~drfmDL4f(GU{x-a;Zia-a`y7JTqUa(D-Q;1*)cjl@Qgy6OXfEe`(LTBE9f*i459L-;;c&C_ zoALs+zb!=V`-OP?pb(Fr6w1vP<0BIN3bTQf=I zwd#n$ep-lsuM2VN9U)G=E5z$mzw6~=ZJ}KCXB1c07x{If)RX3(L_Klb6XOhvSEVPx znUMegKo2LhAZZ6l4=1#})hyoZFJ#mY6f)|^4ea+R>EZhIMSgy4d%sCD { + it("should throw an error, when no first argument was given", async () => { + try { + oopetris.isRecordingFile() + + fail("it should not reach here") + } catch (e) { + expect((e as any).toString()).toEqual( + "TypeError: Wrong number of arguments" + ) + } + }) + + it("should throw an error, when the first argument is not a string", async () => { + try { + oopetris.isRecordingFile(1) + + fail("it should not reach here") + } catch (e) { + expect((e as any).toString()).toEqual( + "TypeError: First argument must be string" + ) + } + }) + + it("should return false, when the file doesn't exist", async () => { + const file = getFilePath("NON-EXISTENT.rec") + expect(fs.existsSync(file)).toBe(false) + + const result = oopetris.isRecordingFile(file) + expect(result).toBe(false) + }) +}) + +describe("getInformation", () => { + it("should throw an error, when no first argument was given", async () => { + try { + oopetris.getInformation() + + fail("it should not reach here") + } catch (e) { + expect((e as any).toString()).toEqual( + "TypeError: Wrong number of arguments" + ) + } + }) + + it("should throw an error, when the first argument is not a string", async () => { + try { + oopetris.getInformation(1) + + fail("it should not reach here") + } catch (e) { + expect((e as any).toString()).toEqual( + "TypeError: First argument must be string" + ) + } + }) + + it("should throw an error, when the file doesn't exist", async () => { + const file = getFilePath("NON-EXISTENT.rec") + expect(fs.existsSync(file)).toBe(false) + + try { + oopetris.getInformation(file) + + fail("it should not reach here") + } catch (e) { + expect((e as any).toString()).toEqual( + `Error: File '${file}' doesn't exist!` + ) + } + }) +}) + +describe("exported properties", () => { + it("should only have known properties", async () => { + const expectedKeys = [ + "isRecordingFile", + "getInformation", + "version", + "properties", + "path", + ] + + const keys = Object.keys(oopetris) + expect(keys).toStrictEqual(expectedKeys) + }) + + it("should have the expected properties", async () => { + const expectedProperties: Record = { + isRecordingFile: () => {}, + getInformation: () => {}, + version: "0.5.6", + properties: { gridProperties: { height: 20, width: 10 } }, + } + + for (const key in expectedProperties) { + const value = expectedProperties[key] + const rawValue = oopetris[key] + + if (typeof value === "string") { + expect(value).toBe(rawValue) + } else if (typeof value === "function") { + expect(rawValue).toStrictEqual(expect.any(Function)) + } else { + expect(value).toMatchObject(rawValue) + } + } + }) +}) diff --git a/wrapper/javascript/tests/test.spec.ts b/wrapper/javascript/tests/test.spec.ts new file mode 100644 index 00000000..7c088283 --- /dev/null +++ b/wrapper/javascript/tests/test.spec.ts @@ -0,0 +1,87 @@ +import { RecordingsUtility } from "../src/ts/index" +import { expect } from "@jest/globals" +import path from "path" +import fs from "fs" + +function fail(reason = "fail was called in a test."): never { + throw new Error(reason) +} + +global.fail = fail + +function getFilePath(name: string): string { + return path.join(__dirname, `files`, name) +} + +describe("isRecordingFile: works as expected", () => { + it("should return false for non existent file", async () => { + const file = getFilePath("NON-EXISTENT.rec") + + expect(fs.existsSync(file)).toBe(false) + + const result = RecordingsUtility.isRecordingFile(file) + expect(result).toBe(false) + }) + + it("should return false for incorrect file", async () => { + const file = getFilePath("incorrect.rec") + + expect(fs.existsSync(file)).toBe(true) + + const result = RecordingsUtility.isRecordingFile(file) + expect(result).toBe(false) + }) + + it("should return true for correct file", async () => { + const file = getFilePath("correct.rec") + + expect(fs.existsSync(file)).toBe(true) + + const result = RecordingsUtility.isRecordingFile(file) + expect(result).toBe(true) + }) +}) + +describe("getInformation: works as expected", () => { + it("should return null for non existent file", async () => { + const file = getFilePath("NON-EXISTENT.rec") + + expect(fs.existsSync(file)).toBe(false) + + const result = RecordingsUtility.getInformation(file) + expect(result).toBe(null) + }) + + it("should return null for incorrect file", async () => { + const file = getFilePath("incorrect.rec") + + expect(fs.existsSync(file)).toBe(true) + + const result = RecordingsUtility.getInformation(file) + expect(result).toBe(null) + }) + + it("should return an object for correct file", async () => { + const file = getFilePath("correct.rec") + + expect(fs.existsSync(file)).toBe(true) + + const result = RecordingsUtility.getInformation(file) + expect(result).not.toBe(null) + }) + + it("should return correct object for correct file", async () => { + const file = getFilePath("correct.rec") + expect(fs.existsSync(file)).toBe(true) + + const serializedFile = getFilePath("correct.serialized.json") + expect(fs.existsSync(serializedFile)).toBe(true) + + const correctResult = JSON.parse( + fs.readFileSync(serializedFile).toString() + ) + + const result = RecordingsUtility.getInformation(file) + expect(result).toMatchObject(correctResult) + }) +}) diff --git a/wrapper/javascript/tsconfig.json b/wrapper/javascript/tsconfig.json new file mode 100644 index 00000000..4137b627 --- /dev/null +++ b/wrapper/javascript/tsconfig.json @@ -0,0 +1,26 @@ +{ + "include": ["src/ts/*.ts"], + "exclude": ["node_modules"], + "compilerOptions": { + "target": "es2021", + "module": "CommonJS", + "moduleResolution": "node", + "lib": ["es2021"], + "outDir": "dist", + "allowJs": true, + "rootDir": "src/ts/", + "strict": true, + "noImplicitAny": true, + "esModuleInterop": true, + "resolveJsonModule": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "declaration": true + }, + "rules": { + "triple-equals": true, + "curly": true, + "strict-boolean-expressions": true, + "no-unnecessary-condition": true + } +} From 22986defd75deb70673dc36145eab98e53bdc080 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 17:11:34 +0200 Subject: [PATCH 37/77] properly support only building libs --- meson.options | 8 ++++++++ tools/dependencies/meson.build | 2 ++ tools/options/meson.build | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/meson.options b/meson.options index b7888d6d..5593a8ea 100644 --- a/meson.options +++ b/meson.options @@ -18,3 +18,11 @@ option( value: false, description: 'whether or not tests should be built', ) + +option( + 'only_build_libs', + type: 'boolean', + value: false, + description: 'if you only want to build the libs, enable this', +) + diff --git a/tools/dependencies/meson.build b/tools/dependencies/meson.build index 41ad9861..4e702877 100644 --- a/tools/dependencies/meson.build +++ b/tools/dependencies/meson.build @@ -112,6 +112,8 @@ utf8cpp_dep = dependency( ) core_lib += {'deps': [core_lib.get('deps'), utf8cpp_dep]} +is_flatpak_build = false + if build_application graphic_application_deps = [] diff --git a/tools/options/meson.build b/tools/options/meson.build index bc36429c..77687208 100644 --- a/tools/options/meson.build +++ b/tools/options/meson.build @@ -85,6 +85,10 @@ endif build_application = true ## only build, if we are at the root, not if this is used as subproject in e.g. wrap files -if meson.is_subproject() +if meson.is_subproject() or get_option('only_build_libs') build_application = false + + if get_option('build_installer') and get_option('only_build_libs') + error('Can\'t build installer when \'only_build_libs\' is enabled') + endif endif From fe95873f9e4d1957be3abb2c17b3762e2e000dd3 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 18:30:12 +0200 Subject: [PATCH 38/77] use node-gyp-build, so that ww can ship prebuilt modules on npm / the package registry --- wrapper/javascript/.gitignore | 3 ++- wrapper/javascript/.npmignore | 12 ++++++++++++ wrapper/javascript/binding.gyp | 2 +- wrapper/javascript/package.json | 19 +++++++++---------- wrapper/javascript/src/meson.build | 1 - wrapper/javascript/src/ts/index.ts | 8 +++----- wrapper/javascript/tests/raw.test.ts | 5 +++-- 7 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 wrapper/javascript/.npmignore delete mode 100644 wrapper/javascript/src/meson.build diff --git a/wrapper/javascript/.gitignore b/wrapper/javascript/.gitignore index 0014accc..adcdd192 100644 --- a/wrapper/javascript/.gitignore +++ b/wrapper/javascript/.gitignore @@ -4,4 +4,5 @@ node_modules/ package-lock.json -/dist \ No newline at end of file +/dist +/prebuilds/ diff --git a/wrapper/javascript/.npmignore b/wrapper/javascript/.npmignore new file mode 100644 index 00000000..daf03f64 --- /dev/null +++ b/wrapper/javascript/.npmignore @@ -0,0 +1,12 @@ +node_modules +lib/binding +build +tests +*.tgz +npm-debug.log +.npmignore +.gitignore +.helper +jest.config.ts +tsconfig.json +src/ts/ diff --git a/wrapper/javascript/binding.gyp b/wrapper/javascript/binding.gyp index a4ee2396..71aa37b4 100644 --- a/wrapper/javascript/binding.gyp +++ b/wrapper/javascript/binding.gyp @@ -2,6 +2,7 @@ { "targets": [ { + "target_name": "oopetris", "cflags_cc": [ "-std=c++23", "-Wall", @@ -16,7 +17,6 @@ " @@ -103,8 +105,4 @@ export class RecordingsUtility { static get version(): string { return oopetris.version } - - private get cppModulePath(): string { - return oopetris.path - } } diff --git a/wrapper/javascript/tests/raw.test.ts b/wrapper/javascript/tests/raw.test.ts index 6c27a579..06af3a94 100644 --- a/wrapper/javascript/tests/raw.test.ts +++ b/wrapper/javascript/tests/raw.test.ts @@ -11,7 +11,9 @@ global.fail = fail function getFilePath(name: string): string { return path.join(__dirname, `files`, name) } -const oopetris = require("bindings")("oopetris") + +const rootDir = path.join(__dirname, "..") +const oopetris = require("node-gyp-build")(rootDir) describe("isRecordingFile", () => { it("should throw an error, when no first argument was given", async () => { @@ -95,7 +97,6 @@ describe("exported properties", () => { "getInformation", "version", "properties", - "path", ] const keys = Object.keys(oopetris) From 5a3182a25203ee5a8ac5aa0b7292c9666917ef5a Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 19:10:22 +0200 Subject: [PATCH 39/77] - fix some compilation error on node 14, since not using NAN::Set, which is version independent - use prebuildify, so that we can ship prebuild modules correctly --- wrapper/javascript/package.json | 26 +++- wrapper/javascript/src/cpp/wrapper.cpp | 182 ++++++++++++------------- 2 files changed, 105 insertions(+), 103 deletions(-) diff --git a/wrapper/javascript/package.json b/wrapper/javascript/package.json index 29c3a431..3cd60275 100644 --- a/wrapper/javascript/package.json +++ b/wrapper/javascript/package.json @@ -5,18 +5,26 @@ "gypfile": true, "main": "./dist/index.js", "types": "./dist/index.d.ts", + "files": [ + "dist/", + "prebuilds/", + "src/cpp/", + "binding.gyp", + "package.json", + "README.md" + ], "private": false, "scripts": { + "install": "node-gyp-build", "build": "npm run build:gyp && npm run compile", - "build:gyp": "node-gyp-build --all --strip", - "build:debug": " node-gyp-build --debug", + "build:gyp": "prebuildify -t 20.13.1 -t 18.20.3 -t 22.2.0 --strip", + "build:debug": "prebuildify -t 20.13.1 -t 18.20.3 -t 22.2.0 --debug", "compile": "npm run build:tsc", "build:tsc": "tsc", "test": "npx jest", "build:test": "npm run build && npm run test", - "publish": "npm run build:test && npm publish --tag latest --access public" + "publish:package": "npm run build:test && npm publish --tag latest --access public" }, - "install": "node-gyp-build", "keywords": [ "oopetris", "cpp", @@ -28,11 +36,16 @@ }, "license": "MIT", "engines": { - "node": "^20.0.0" + "node": "^18.0.0 || ^20.0.0 || ^22.0.0 " }, + "os": [ + "darwin", + "linux", + "win32" + ], "repository": { "type": "git", - "url": "git+https://github.com/OpenBrickProtocolFoundation/oopetris" + "url": "git+https://github.com/OpenBrickProtocolFoundation/oopetris.git" }, "dependencies": { "node-gyp-build": "^4.8.1" @@ -41,6 +54,7 @@ "@types/jest": "^29.5.12", "jest": "^29.7.0", "nan": "^2.19.0", + "prebuildify": "^5.0.1", "ts-jest": "^29.1.3", "ts-node": "^10.9.2", "typescript": "^5.4.5" diff --git a/wrapper/javascript/src/cpp/wrapper.cpp b/wrapper/javascript/src/cpp/wrapper.cpp index 3bc0c054..4fd72658 100644 --- a/wrapper/javascript/src/cpp/wrapper.cpp +++ b/wrapper/javascript/src/cpp/wrapper.cpp @@ -5,140 +5,128 @@ NAN_METHOD(isRecordingFile) { - if (info.Length() != 1) { - info.GetIsolate()->ThrowException(Nan::TypeError("Wrong number of arguments")); - return; - } + if (info.Length() != 1) { + info.GetIsolate()->ThrowException(Nan::TypeError("Wrong number of arguments")); + return; + } - if (!info[0]->IsString()) { - info.GetIsolate()->ThrowException( - Nan::TypeError("First argument must be string")); - return; - } + if (!info[0]->IsString()) { + info.GetIsolate()->ThrowException(Nan::TypeError("First argument must be string")); + return; + } - auto filePath = std::string{*Nan::Utf8String(info[0])}; + auto filePath = std::string{ *Nan::Utf8String(info[0]) }; - if (not std::filesystem::exists(filePath)) { + if (not std::filesystem::exists(filePath)) { - info.GetReturnValue().Set(Nan::False()); - return; - } + info.GetReturnValue().Set(Nan::False()); + return; + } - auto parsed = recorder::RecordingReader::from_path(filePath); + auto parsed = recorder::RecordingReader::from_path(filePath); - if (not parsed.has_value()) { - info.GetReturnValue().Set(Nan::False()); - return; - } + if (not parsed.has_value()) { + info.GetReturnValue().Set(Nan::False()); + return; + } - info.GetReturnValue().Set(Nan::True()); - return; + info.GetReturnValue().Set(Nan::True()); + return; } NAN_METHOD(getInformation) { - if (info.Length() != 1) { - info.GetIsolate()->ThrowException(Nan::TypeError("Wrong number of arguments")); - return; - } + if (info.Length() != 1) { + info.GetIsolate()->ThrowException(Nan::TypeError("Wrong number of arguments")); + return; + } - if (!info[0]->IsString()) { - info.GetIsolate()->ThrowException( - Nan::TypeError("First argument must be string")); - return; - } + if (!info[0]->IsString()) { + info.GetIsolate()->ThrowException(Nan::TypeError("First argument must be string")); + return; + } - auto filePath = std::string{*Nan::Utf8String(info[0])}; + auto filePath = std::string{ *Nan::Utf8String(info[0]) }; - if (not std::filesystem::exists(filePath)) { - std::string error = "File '"; - error += filePath; - error += "' doesn't exist!"; + if (not std::filesystem::exists(filePath)) { + std::string error = "File '"; + error += filePath; + error += "' doesn't exist!"; - info.GetIsolate()->ThrowException( - Nan::Error(Nan::New(error).ToLocalChecked())); - return; - } + info.GetIsolate()->ThrowException(Nan::Error(Nan::New(error).ToLocalChecked())); + return; + } - auto parsed = recorder::RecordingReader::from_path(filePath); + auto parsed = recorder::RecordingReader::from_path(filePath); - if (not parsed.has_value()) { - std::string error = - "An error occurred during parsing of the recording file '"; - error += filePath; - error += "': "; - error += parsed.error(); + if (not parsed.has_value()) { + std::string error = "An error occurred during parsing of the recording file '"; + error += filePath; + error += "': "; + error += parsed.error(); - info.GetIsolate()->ThrowException( - Nan::Error(Nan::New(error).ToLocalChecked())); - return; - } + info.GetIsolate()->ThrowException(Nan::Error(Nan::New(error).ToLocalChecked())); + return; + } - const auto recording_reader = std::move(parsed.value()); + const auto recording_reader = std::move(parsed.value()); - auto json_value = - json::try_convert_to_json(recording_reader); + auto json_value = json::try_convert_to_json(recording_reader); - if (not json_value.has_value()) { - std::string error = "An error occurred during converting to json:"; - error += json_value.error(); + if (not json_value.has_value()) { + std::string error = "An error occurred during converting to json:"; + error += json_value.error(); - info.GetIsolate()->ThrowException( - Nan::Error(Nan::New(error).ToLocalChecked())); - return; - } + info.GetIsolate()->ThrowException(Nan::Error(Nan::New(error).ToLocalChecked())); + return; + } - const auto result_string_json = json_value->dump(-1, ' ', false); + const auto result_string_json = json_value->dump(-1, ' ', false); - v8::Local js_json_string = - Nan::New(result_string_json).ToLocalChecked(); + v8::Local js_json_string = Nan::New(result_string_json).ToLocalChecked(); - Nan::JSON NanJSON; - Nan::MaybeLocal result = NanJSON.Parse(js_json_string); - if (!result.IsEmpty()) { - v8::Local val = result.ToLocalChecked(); - info.GetReturnValue().Set(val); - return; - } + Nan::JSON NanJSON; + Nan::MaybeLocal result = NanJSON.Parse(js_json_string); + if (!result.IsEmpty()) { + v8::Local val = result.ToLocalChecked(); + info.GetReturnValue().Set(val); + return; + } - info.GetIsolate()->ThrowException( - Nan::Error("Failed to parse internal JSON structure!")); - return; + info.GetIsolate()->ThrowException(Nan::Error("Failed to parse internal JSON structure!")); + return; } NAN_MODULE_INIT(InitAll) { - Nan::Set(target, Nan::New("isRecordingFile").ToLocalChecked(), - Nan::GetFunction(Nan::New(isRecordingFile)) - .ToLocalChecked()); + Nan::Set( + target, Nan::New("isRecordingFile").ToLocalChecked(), + Nan::GetFunction(Nan::New(isRecordingFile)).ToLocalChecked() + ); - Nan::Set(target, Nan::New("getInformation").ToLocalChecked(), - Nan::GetFunction(Nan::New(getInformation)) - .ToLocalChecked()); + Nan::Set( + target, Nan::New("getInformation").ToLocalChecked(), + Nan::GetFunction(Nan::New(getInformation)).ToLocalChecked() + ); - Nan::Set(target, Nan::New("version").ToLocalChecked(), - Nan::New(utils::version()).ToLocalChecked()); + Nan::Set(target, Nan::New("version").ToLocalChecked(), Nan::New(utils::version()).ToLocalChecked()); - v8::Local properties = Nan::New(); + v8::Local properties = Nan::New(); - std::vector> properties_vector{ - {"height", grid::height_in_tiles}, {"width", grid::width_in_tiles}}; + std::vector> properties_vector{ + { "height", grid::height_in_tiles }, + { "width", grid::width_in_tiles } + }; - v8::Local grid_properties = Nan::New(); + v8::Local grid_properties = Nan::New(); - for (const auto &[key, value] : properties_vector) { - v8::Local keyValue = Nan::New(key).ToLocalChecked(); - grid_properties - ->Set(Nan::GetCurrentContext(), keyValue, Nan::New(value)) - .Check(); - } + for (const auto& [key, value] : properties_vector) { + v8::Local keyValue = Nan::New(key).ToLocalChecked(); + Nan::Set(grid_properties, keyValue, Nan::New(value)).Check(); + } - properties - ->Set(Nan::GetCurrentContext(), - Nan::New("gridProperties").ToLocalChecked(), - grid_properties) - .Check(); + Nan::Set(properties, Nan::New("gridProperties").ToLocalChecked(), grid_properties).Check(); - Nan::Set(target, Nan::New("properties").ToLocalChecked(), properties); + Nan::Set(target, Nan::New("properties").ToLocalChecked(), properties); } NODE_MODULE(RecordingsWrapper, InitAll) From 608f2d20be40b141527e1a292e3407ac66370b77 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 19:21:38 +0200 Subject: [PATCH 40/77] Add wrapper CI --- .github/workflows/wrapper.yml | 114 ++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 .github/workflows/wrapper.yml diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml new file mode 100644 index 00000000..fd40dcc7 --- /dev/null +++ b/.github/workflows/wrapper.yml @@ -0,0 +1,114 @@ +name: Wrapper CI + +on: + push: + branches: ["main"] + pull_request: + workflow_dispatch: + +jobs: + build: + name: ${{ matrix.config.name }} + runs-on: ${{ matrix.config.os }}-${{ matrix.config.os-version }} + + strategy: + fail-fast: false + matrix: + config: + - name: Windows + os: windows + os-version: 2022 + + - name: Linux + os: ubuntu + os-version: 24.04 + + - name: MacOS + os: macos + os-version: 13 + + - name: MacOS (Arm64) + os: macos + os-version: 14 + + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: "0" + + - name: Setup MSVC (Windows) + if: matrix.config.os == 'windows' + uses: TheMrMilchmann/setup-msvc-dev@v3 + with: + arch: x64 + toolset: 14.39 + + - name: Setup GCC (Linux) + if: matrix.config.os == 'ubuntu' + uses: egor-tensin/setup-gcc@v1 + with: + version: 14 + platform: x64 + + - name: Setup Clang (MacOS) + if: matrix.config.os == 'macos' + run: | + brew update + brew install llvm@18 + echo "$(brew --prefix)/opt/llvm/bin" >> $GITHUB_PATH + echo "LDFLAGS=-L$(brew --prefix)/opt/llvm/lib -L$(brew --prefix)/opt/llvm/lib/c++ -Wl,-rpath,$(brew --prefix)/opt/llvm/lib/c++" >> "$GITHUB_ENV" + echo "CPPFLAGS=-I$(brew --prefix)/opt/llvm/include" >> "$GITHUB_ENV" + echo "CC=clang" >> "$GITHUB_ENV" + echo "CXX=clang++" >> "$GITHUB_ENV" + echo "OBJC=clang" >> "$GITHUB_ENV" + echo "CC_LD=lld" >> "$GITHUB_ENV" + echo "CXX_LD=lld" >> "$GITHUB_ENV" + echo "OBJC_LD=lld" >> "$GITHUB_ENV" + + - name: Setup meson (MacOS) + if: matrix.config.os == 'macos' + run: | + brew update + brew install meson + + # NOTE: meson has no dependencies, so --break-system-packages doesn't really break anything! + - name: Setup meson + if: matrix.config.os != 'macos' + run: | + pip install meson --break-system-packages + + - name: Install dependencies (Linux) + if: matrix.config.os == 'ubuntu' + run: | + sudo apt-get update + sudo apt-get install ninja-build -y + + - name: Install dependencies (MacOS) + if: matrix.config.os == 'macos' + run: | + brew update + brew install ninja + + - name: Configure + run: meson setup build -Dbuildtype=release -Ddefault_library=static -Dclang_libcpp=disabled -Donly_build_libs=true + + - name: Build and install Libs + run: meson install -C build + + - uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Build package + run: | + npm install -D + npm run build + npm pack + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.config.name }} Node.js Wrapper + path: oopetris*.tgz + \ No newline at end of file From 6babfdc5cb5a5a0b43b4452fe98a5aef3f8eee8e Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 19:25:09 +0200 Subject: [PATCH 41/77] - adjust the Node.js wrapper README - add running the tests to the Wrapper CI - adjust directory in wrapper CI --- .github/workflows/wrapper.yml | 4 +++- wrapper/javascript/README.md | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml index fd40dcc7..cee01f4a 100644 --- a/.github/workflows/wrapper.yml +++ b/.github/workflows/wrapper.yml @@ -102,13 +102,15 @@ jobs: - name: Build package run: | + cd wrapper/javascript npm install -D npm run build + npm run test npm pack - name: Upload artifacts uses: actions/upload-artifact@v4 with: name: ${{ matrix.config.name }} Node.js Wrapper - path: oopetris*.tgz + path: wrapper/javascript/oopetris*.tgz \ No newline at end of file diff --git a/wrapper/javascript/README.md b/wrapper/javascript/README.md index 500de2e1..29965db2 100644 --- a/wrapper/javascript/README.md +++ b/wrapper/javascript/README.md @@ -15,7 +15,7 @@ We officially support Linux, Windows and MacOS, if any error occurs regarding th ## How to obtain -A prebuilt package is WIP and they can be obtained, by using [Totto's private node package registry](https://verdaccio.totto.lt/) +A prebuilt package is available and can be obtained, by using [Totto's private node package registry](https://verdaccio.totto.lt/) ## How to build it yourself From 48ae763c28b2ae11559b925f80dc24f6c24361c8 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 19:27:13 +0200 Subject: [PATCH 42/77] CI: fix usage of sudo in wrapper CI --- .github/workflows/wrapper.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml index cee01f4a..c4d5a3f6 100644 --- a/.github/workflows/wrapper.yml +++ b/.github/workflows/wrapper.yml @@ -94,8 +94,13 @@ jobs: run: meson setup build -Dbuildtype=release -Ddefault_library=static -Dclang_libcpp=disabled -Donly_build_libs=true - name: Build and install Libs + if: matrix.config.os != 'ubuntu' run: meson install -C build + - name: Build and install Libs (Linux) + if: matrix.config.os == 'ubuntu' + run: sudo meson install -C build + - uses: actions/setup-node@v4 with: node-version: 20 From 284965ee09ddfd7f47c79d5bcba6409d0c045041 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 19:28:16 +0200 Subject: [PATCH 43/77] fix formatting of some files --- src/libs/core/helper/versions.hpp | 3 +-- src/libs/recordings/utility/additional_information.hpp | 2 +- src/libs/recordings/utility/recording_writer.hpp | 4 ++-- src/manager/music_manager.cpp | 2 +- src/manager/resource_manager.hpp | 1 + src/scenes/scene.cpp | 3 +-- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/libs/core/helper/versions.hpp b/src/libs/core/helper/versions.hpp index dd95efc8..d4c48eda 100644 --- a/src/libs/core/helper/versions.hpp +++ b/src/libs/core/helper/versions.hpp @@ -8,12 +8,11 @@ namespace utils { #define STRINGIFY_HELPER_(a) #a //NOLINT(cppcoreguidelines-macro-usage) -#if !defined(OOPETRIS_VERSION) +#if !defined(OOPETRIS_VERSION) #error "OOPETRIS_VERSION not defined" #endif - [[nodiscard]] inline std::string version() { diff --git a/src/libs/recordings/utility/additional_information.hpp b/src/libs/recordings/utility/additional_information.hpp index c414a5bf..8c937564 100644 --- a/src/libs/recordings/utility/additional_information.hpp +++ b/src/libs/recordings/utility/additional_information.hpp @@ -3,8 +3,8 @@ #include "./checksum_helper.hpp" #include "./helper.hpp" -#include #include +#include #include #include diff --git a/src/libs/recordings/utility/recording_writer.hpp b/src/libs/recordings/utility/recording_writer.hpp index 5dcefdd4..e8a87098 100644 --- a/src/libs/recordings/utility/recording_writer.hpp +++ b/src/libs/recordings/utility/recording_writer.hpp @@ -1,10 +1,10 @@ #pragma once +#include "./additional_information.hpp" #include "./helper.hpp" -#include #include "./recording.hpp" -#include "./additional_information.hpp" #include "./tetrion_core_information.hpp" +#include #include diff --git a/src/manager/music_manager.cpp b/src/manager/music_manager.cpp index 5228931f..057f3163 100644 --- a/src/manager/music_manager.cpp +++ b/src/manager/music_manager.cpp @@ -10,9 +10,9 @@ #include #include #include +#include #include #include -#include MusicManager::MusicManager(ServiceProvider* service_provider, u8 channel_size) : m_music{ nullptr }, diff --git a/src/manager/resource_manager.hpp b/src/manager/resource_manager.hpp index 8fed50c3..fdbeffb4 100644 --- a/src/manager/resource_manager.hpp +++ b/src/manager/resource_manager.hpp @@ -1,6 +1,7 @@ #pragma once #include + #include "manager/font.hpp" #include diff --git a/src/scenes/scene.cpp b/src/scenes/scene.cpp index 3294d434..b1e27f9c 100644 --- a/src/scenes/scene.cpp +++ b/src/scenes/scene.cpp @@ -4,18 +4,17 @@ #endif -#include "scenes/scene.hpp" #include "about_page/about_page.hpp" #include "main_menu/main_menu.hpp" #include "multiplayer_menu/multiplayer_menu.hpp" #include "play_select_menu/play_select_menu.hpp" #include "recording_selector/recording_selector.hpp" #include "replay_game/replay_game.hpp" +#include "scenes/scene.hpp" #include "settings_menu/settings_menu.hpp" #include "single_player_game/single_player_game.hpp" - namespace scenes { Scene::Scene(ServiceProvider* service_provider, const ui::Layout& layout) : m_service_provider{ service_provider }, From 9e9c1563558bc3d5e54362eea817448182d67138 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 19:38:32 +0200 Subject: [PATCH 44/77] CI: fix a few CI warnings, that are the result of some changes in this PR --- .github/workflows/meson.yml | 21 +++------------------ .github/workflows/wrapper.yml | 6 ------ 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml index dd902bb5..b3b9f5d9 100644 --- a/.github/workflows/meson.yml +++ b/.github/workflows/meson.yml @@ -177,7 +177,7 @@ jobs: if: matrix.config.os == 'macos' run: | brew update - brew install ninja sdl2 sdl2_ttf sdl2_mixer sdl2_image + brew install sdl2 sdl2_ttf sdl2_mixer sdl2_image - name: Configure run: meson setup build -Dbuildtype=${{ matrix.config.buildtype }} -Ddefault_library=${{ matrix.config.library_type }} -Dclang_libcpp=${{ ( ( matrix.config.os == 'ubuntu' && matrix.config.use-clang == true && matrix.config.use-clang_stdlib ) || matrix.config.os == 'macos' ) && 'enabled' || 'disabled' }} @@ -185,23 +185,8 @@ jobs: - name: Build run: meson compile -C build - - name: Upload artifacts - Linux + - name: Upload artifacts uses: actions/upload-artifact@v4 - if: matrix.config.os == 'ubuntu' - with: - name: ${{ matrix.config.name }} Executable - path: build/oopetris - - - name: Upload artifacts - MacOS - uses: actions/upload-artifact@v4 - if: matrix.config.os == 'macos' - with: - name: ${{ matrix.config.name }} Executable - path: build/src/executables/oopetris - - - name: Upload artifacts - Windows - uses: actions/upload-artifact@v4 - if: matrix.config.os == 'windows' with: name: ${{ matrix.config.name }} Executable - path: build/src/executables/oopetris.exe + path: build/src/executables/oopetris* diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml index c4d5a3f6..a4498626 100644 --- a/.github/workflows/wrapper.yml +++ b/.github/workflows/wrapper.yml @@ -84,12 +84,6 @@ jobs: sudo apt-get update sudo apt-get install ninja-build -y - - name: Install dependencies (MacOS) - if: matrix.config.os == 'macos' - run: | - brew update - brew install ninja - - name: Configure run: meson setup build -Dbuildtype=release -Ddefault_library=static -Dclang_libcpp=disabled -Donly_build_libs=true From c7a3090a77d5649da8c16d3a8564ffe64dc3a959 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 19:50:26 +0200 Subject: [PATCH 45/77] CI: wrapper, fix pkg-config path on windows --- .github/workflows/wrapper.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml index a4498626..53fb8aa7 100644 --- a/.github/workflows/wrapper.yml +++ b/.github/workflows/wrapper.yml @@ -95,6 +95,15 @@ jobs: if: matrix.config.os == 'ubuntu' run: sudo meson install -C build + - name: Build and install Libs (Linux) + if: matrix.config.os == 'ubuntu' + run: sudo meson install -C build + + - name: Fix pkg-config PATH on Windows + if: matrix.config.os == 'windows' + run: | + echo "PKG_CONFIG_PATH=c:/lib/pkgconfig" >> "$GITHUB_ENV" + - uses: actions/setup-node@v4 with: node-version: 20 From f1a23c2c3168057e85dbddb0f28eaca9b9a17d66 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 19:51:23 +0200 Subject: [PATCH 46/77] CI: wrapper - fix linux build --- .github/workflows/wrapper.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml index 53fb8aa7..903ab29e 100644 --- a/.github/workflows/wrapper.yml +++ b/.github/workflows/wrapper.yml @@ -83,6 +83,7 @@ jobs: run: | sudo apt-get update sudo apt-get install ninja-build -y + sudo pip install meson --break-system-packages - name: Configure run: meson setup build -Dbuildtype=release -Ddefault_library=static -Dclang_libcpp=disabled -Donly_build_libs=true @@ -97,7 +98,7 @@ jobs: - name: Build and install Libs (Linux) if: matrix.config.os == 'ubuntu' - run: sudo meson install -C build + run: meson install -C build - name: Fix pkg-config PATH on Windows if: matrix.config.os == 'windows' From 3837d3247046a979ca2465cecf2547b0337a9098 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 19:55:09 +0200 Subject: [PATCH 47/77] JS wrapper: fix mac build --- wrapper/javascript/binding.gyp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wrapper/javascript/binding.gyp b/wrapper/javascript/binding.gyp index 71aa37b4..d2c27c10 100644 --- a/wrapper/javascript/binding.gyp +++ b/wrapper/javascript/binding.gyp @@ -16,6 +16,12 @@ "-Wno-cast-function-type", # since nan.h -> node.h has some warnings regarding that " Date: Sun, 26 May 2024 19:57:42 +0200 Subject: [PATCH 48/77] CI: wrapper, fix linux build --- .github/workflows/wrapper.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml index 903ab29e..bcc8e7f1 100644 --- a/.github/workflows/wrapper.yml +++ b/.github/workflows/wrapper.yml @@ -96,10 +96,6 @@ jobs: if: matrix.config.os == 'ubuntu' run: sudo meson install -C build - - name: Build and install Libs (Linux) - if: matrix.config.os == 'ubuntu' - run: meson install -C build - - name: Fix pkg-config PATH on Windows if: matrix.config.os == 'windows' run: | From 8b7698161e03de478de7f4f43bd4a6c267620ab4 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 20:05:27 +0200 Subject: [PATCH 49/77] CI: wrapper - remove that **** Strawberry perl from the earth --- .github/workflows/wrapper.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml index bcc8e7f1..7dd6dc92 100644 --- a/.github/workflows/wrapper.yml +++ b/.github/workflows/wrapper.yml @@ -96,12 +96,14 @@ jobs: if: matrix.config.os == 'ubuntu' run: sudo meson install -C build - - name: Fix pkg-config PATH on Windows + - name: Remove Strawberry perl pkg-config if: matrix.config.os == 'windows' - run: | - echo "PKG_CONFIG_PATH=c:/lib/pkgconfig" >> "$GITHUB_ENV" + uses: JesseTG/rm@v1.0.3 + with: + path: C:/Strawberry/ - - uses: actions/setup-node@v4 + - name: Install Node.js + uses: actions/setup-node@v4 with: node-version: 20 From b17fb92a402bc68e811882ace9c33611dc7ef685 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 20:15:52 +0200 Subject: [PATCH 50/77] CI: wrapper - add verbose flag, to see failures --- .github/workflows/wrapper.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml index 7dd6dc92..89b583f8 100644 --- a/.github/workflows/wrapper.yml +++ b/.github/workflows/wrapper.yml @@ -111,7 +111,7 @@ jobs: run: | cd wrapper/javascript npm install -D - npm run build + npm run build --verbose npm run test npm pack From 37322df518fa99f386cc62ebebc881976e5ff77a Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 21:25:08 +0200 Subject: [PATCH 51/77] fix a few clang-tidy errors --- src/executables/game/application.cpp | 2 +- src/executables/game/main.cpp | 2 + src/executables/game/meson.build | 1 + src/executables/game/parser.cpp | 63 +++++++++++++++++++ src/executables/game/parser.hpp | 58 +---------------- .../utility/command_line_arguments.hpp | 27 ++++---- 6 files changed, 83 insertions(+), 70 deletions(-) create mode 100644 src/executables/game/parser.cpp diff --git a/src/executables/game/application.cpp b/src/executables/game/application.cpp index daee4af1..707c2ca2 100644 --- a/src/executables/game/application.cpp +++ b/src/executables/game/application.cpp @@ -38,7 +38,7 @@ namespace { Application::Application(std::shared_ptr&& window, CommandLineArguments&& arguments) try - : m_command_line_arguments{ arguments }, + : m_command_line_arguments{ std::move(arguments) }, m_window{ std::move(window) }, m_renderer{ *m_window, m_command_line_arguments.target_fps.has_value() ? Renderer::VSync::Disabled : Renderer::VSync::Enabled }, diff --git a/src/executables/game/main.cpp b/src/executables/game/main.cpp index 704465b5..f85e0122 100644 --- a/src/executables/game/main.cpp +++ b/src/executables/game/main.cpp @@ -6,6 +6,8 @@ #include #include "application.hpp" +#include "helper/constants.hpp" +#include "helper/graphic_utils.hpp" #include "helper/message_box.hpp" #include diff --git a/src/executables/game/meson.build b/src/executables/game/meson.build index d9fc4ddb..90b4c0b2 100644 --- a/src/executables/game/meson.build +++ b/src/executables/game/meson.build @@ -2,5 +2,6 @@ main_files += files( 'application.cpp', 'application.hpp', 'main.cpp', + 'parser.cpp', 'parser.hpp', ) diff --git a/src/executables/game/parser.cpp b/src/executables/game/parser.cpp new file mode 100644 index 00000000..591a5e31 --- /dev/null +++ b/src/executables/game/parser.cpp @@ -0,0 +1,63 @@ + +#include "parser.hpp" + +#include + +#include "game/command_line_arguments.hpp" + +#include "helper/constants.hpp" +#include "helper/graphic_utils.hpp" + + +#include +#include + + +helper::expected helper::parse_args(const std::vector& arguments) { + argparse::ArgumentParser parser{ constants::program_name, constants::version, argparse::default_arguments::all }; + parser.add_argument("-r", "--recording").help("the path of a recorded game used for replay"); + parser.add_argument("-f", "--target-fps").help("the number of simulation steps per second").scan<'i', u32>(); + parser.add_argument("-l", "--level") + .help("the starting level of the game") + .scan<'i', CommandLineArguments::Level>() + .default_value(CommandLineArguments::default_starting_level); + parser.add_argument("-s", "--silent").help("disable audio output").default_value(false).implicit_value(true); + try { + parser.parse_args(arguments); + + CommandLineArguments result{ std::nullopt, std::nullopt }; + + + if (auto path = parser.present("--recording")) { + spdlog::info("recording is present"); + result.recording_path = utils::get_root_folder() / *path; + } + + const auto fps = parser.present("--target-fps"); + if (fps.has_value()) { + if (fps.value() >= 1) { + result.target_fps = fps; + } else { + spdlog::error("invalid value for target fps ({}), using default value instead (VSYNC)", fps.value()); + } + } + + const auto level = parser.get("--level"); + if (level <= 30) { + result.starting_level = level; + } else { + spdlog::error( + "invalid value for starting level ({}), using default value instead ({})", level, + CommandLineArguments::default_starting_level + ); + result.starting_level = CommandLineArguments::default_starting_level; + } + + result.silent = parser.get("--silent"); + + return result; + + } catch (const std::exception& error) { + return helper::unexpected{ error.what() }; + } +} diff --git a/src/executables/game/parser.hpp b/src/executables/game/parser.hpp index 867da8c9..211c7f7d 100644 --- a/src/executables/game/parser.hpp +++ b/src/executables/game/parser.hpp @@ -4,66 +4,10 @@ #include "game/command_line_arguments.hpp" -#include "helper/constants.hpp" -#include "helper/graphic_utils.hpp" -#include -#include -#include #include -#include namespace helper { - helper::expected parse_args(const std::vector& arguments) { - argparse::ArgumentParser parser{ constants::program_name, constants::version, - argparse::default_arguments::all }; - parser.add_argument("-r", "--recording").help("the path of a recorded game used for replay"); - parser.add_argument("-f", "--target-fps").help("the number of simulation steps per second").scan<'i', u32>(); - parser.add_argument("-l", "--level") - .help("the starting level of the game") - .scan<'i', CommandLineArguments::Level>() - .default_value(CommandLineArguments::default_starting_level); - parser.add_argument("-s", "--silent").help("disable audio output").default_value(false).implicit_value(true); - try { - parser.parse_args(arguments); - - CommandLineArguments result{ std::nullopt, std::nullopt }; - - - if (auto path = parser.present("--recording")) { - spdlog::info("recording is present"); - result.recording_path = utils::get_root_folder() / *path; - } - - const auto fps = parser.present("--target-fps"); - if (fps.has_value()) { - if (fps.value() >= 1) { - result.target_fps = fps.value(); - } else { - spdlog::error( - "invalid value for target fps ({}), using default value instead (VSYNC)", fps.value() - ); - } - } - - const auto level = parser.get("--level"); - if (level <= 30) { - result.starting_level = level; - } else { - spdlog::error( - "invalid value for starting level ({}), using default value instead ({})", level, - CommandLineArguments::default_starting_level - ); - result.starting_level = CommandLineArguments::default_starting_level; - } - - result.silent = parser.get("--silent"); - - return result; - - } catch (const std::exception& error) { - return helper::unexpected{ error.what() }; - } - } + helper::expected parse_args(const std::vector& arguments); } // namespace helper diff --git a/src/executables/utility/command_line_arguments.hpp b/src/executables/utility/command_line_arguments.hpp index 38f64c89..22be1a88 100644 --- a/src/executables/utility/command_line_arguments.hpp +++ b/src/executables/utility/command_line_arguments.hpp @@ -25,14 +25,14 @@ struct CommandLineArguments final { template - CommandLineArguments(std::filesystem::path recording_path, T&& type) - : recording_path{ recording_path }, - value{ std::move(type) } { } + CommandLineArguments(std::filesystem::path&& recording_path, T&& value) + : recording_path{ std::move(recording_path) }, + value{ std::forward(value) } { } template - CommandLineArguments(std::filesystem::path recording_path, const T& type) - : recording_path{ recording_path }, - value{ type } { } + CommandLineArguments(std::filesystem::path&& recording_path, const T& value) + : recording_path{ std::move(recording_path) }, + value{ value } { } [[nodiscard]] static helper::expected from_args(int argc, char** argv) noexcept { @@ -63,7 +63,7 @@ struct CommandLineArguments final { parser.parse_args(argc, argv); - const auto recording_path = parser.get("--recording"); + auto recording_path = parser.get("--recording"); if (parser.is_subcommand_used(dump_parser)) { const auto ensure_ascii = dump_parser.get("--ensure-ascii"); @@ -71,17 +71,20 @@ struct CommandLineArguments final { return CommandLineArguments{ - recording_path, Dump{ .ensure_ascii = ensure_ascii, .pretty_print = pretty_print } + std::move(recording_path), Dump{ .ensure_ascii = ensure_ascii, .pretty_print = pretty_print } }; + } - } else if (parser.is_subcommand_used(info_parser)) { + if (parser.is_subcommand_used(info_parser)) { return CommandLineArguments{ - recording_path, + std::move(recording_path), Info{}, }; - } else { - return helper::unexpected{ "Unknown or no subcommand used" }; } + + + return helper::unexpected{ "Unknown or no subcommand used" }; + } catch (const std::exception& error) { return helper::unexpected{ error.what() }; } From bde46f2e3fa44baa0a8cf9a0015d3b02b362eee2 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 23:36:24 +0200 Subject: [PATCH 52/77] only install needed things in lib_only mode --- tools/install/meson.build | 142 ++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 69 deletions(-) diff --git a/tools/install/meson.build b/tools/install/meson.build index da4648d6..69d8f1b3 100644 --- a/tools/install/meson.build +++ b/tools/install/meson.build @@ -1,83 +1,87 @@ -## TODO: only install needed ones, since sometimes we only need e.g. flacs or mp3 and no icons etc. -## install assets -install_subdir( - meson.project_source_root() / 'assets', - install_dir: 'share/oopetris', - exclude_files: ['oopetris.desktop.in', 'OOPetris.svg', 'recordings.magic'], - exclude_directories: ['icon'], -) - -app_name = 'oopetris' -if is_flatpak_build - app_name = 'com.github.mgerhold.OOPetris' -endif +if build_application -conf = configuration_data() -conf.set('APP_NAME', app_name) + ## TODO: only install needed ones, since sometimes we only need e.g. flacs or mp3 and no icons etc. + ## install assets + install_subdir( + meson.project_source_root() / 'assets', + install_dir: 'share/oopetris', + exclude_files: ['oopetris.desktop.in', 'OOPetris.svg', 'recordings.magic'], + exclude_directories: ['icon'], + ) -datadir = get_option('prefix') / get_option('datadir') + app_name = 'oopetris' + if is_flatpak_build + app_name = 'com.github.mgerhold.OOPetris' + endif -if host_machine.system() == 'linux' + conf = configuration_data() + conf.set('APP_NAME', app_name) - fs = import('fs') + datadir = get_option('prefix') / get_option('datadir') - magic_dir = datadir / 'misc' - magic_file = magic_dir / 'magic' - oopetris_magic_file = (meson.project_source_root() / 'assets' / 'recordings.magic') + if host_machine.system() == 'linux' - if fs.exists(magic_file) + fs = import('fs') - cat_prog = find_program('cat') + magic_dir = datadir / 'misc' + magic_file = magic_dir / 'magic' + oopetris_magic_file = (meson.project_source_root() / 'assets' / 'recordings.magic') - custom_target( - 'magic_file_append', - command: [cat_prog, '@INPUT@'], - capture: true, - input: [oopetris_magic_file, magic_file], - output: 'magic', - install_dir: magic_dir, - ) + if fs.exists(magic_file) - else + cat_prog = find_program('cat') - install_data( - oopetris_magic_file, - install_dir: magic_dir, - rename: ['magic'], - ) + custom_target( + 'magic_file_append', + command: [cat_prog, '@INPUT@'], + capture: true, + input: [oopetris_magic_file, magic_file], + output: 'magic', + install_dir: magic_dir, + ) + + else + + install_data( + oopetris_magic_file, + install_dir: magic_dir, + rename: ['magic'], + ) + endif endif -endif -configure_file( - input: meson.project_source_root() / 'assets/oopetris.desktop.in', - output: app_name + '.desktop', - configuration: conf, - install: true, - install_dir: datadir / 'applications', -) - -logos = [ - '24x24.png', - '48x48.png', - '64x64.png', - '72x72.png', - '96x96.png', - '128x128.png', - '144x144.png', - '160x160.png', - '192x192.png', - '256x256.png', - '512x512.png', - 'scalable.svg', -] - -foreach logo : logos - name = logo.split('.')[0] - ext = logo.split('.')[1] - install_data( - meson.project_source_root() / 'assets' / 'icon' / logo, - install_dir: datadir / 'icons' / 'hicolor' / name / 'apps', - rename: [app_name + '.' + ext], + configure_file( + input: meson.project_source_root() / 'assets/oopetris.desktop.in', + output: app_name + '.desktop', + configuration: conf, + install: true, + install_dir: datadir / 'applications', ) -endforeach + + logos = [ + '24x24.png', + '48x48.png', + '64x64.png', + '72x72.png', + '96x96.png', + '128x128.png', + '144x144.png', + '160x160.png', + '192x192.png', + '256x256.png', + '512x512.png', + 'scalable.svg', + ] + + foreach logo : logos + name = logo.split('.')[0] + ext = logo.split('.')[1] + install_data( + meson.project_source_root() / 'assets' / 'icon' / logo, + install_dir: datadir / 'icons' / 'hicolor' / name / 'apps', + rename: [app_name + '.' + ext], + ) + endforeach + +endif From bececd80841e78b8325ea1f73920aef8e0329b5c Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 23:42:24 +0200 Subject: [PATCH 53/77] Wrapper, Js: nan.h only support node <= 21, 22 not yet, so remove it from supported node versions --- wrapper/javascript/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wrapper/javascript/package.json b/wrapper/javascript/package.json index 3cd60275..84d1b439 100644 --- a/wrapper/javascript/package.json +++ b/wrapper/javascript/package.json @@ -17,8 +17,8 @@ "scripts": { "install": "node-gyp-build", "build": "npm run build:gyp && npm run compile", - "build:gyp": "prebuildify -t 20.13.1 -t 18.20.3 -t 22.2.0 --strip", - "build:debug": "prebuildify -t 20.13.1 -t 18.20.3 -t 22.2.0 --debug", + "build:gyp": "prebuildify -t 18.20.3 -t 19.9.0 -t 20.13.1 -t 21.7.3 --strip", + "build:debug": "prebuildify -t 18.20.3 -t 19.9.0 -t 20.13.1 -t 21.7.3 --debug", "compile": "npm run build:tsc", "build:tsc": "tsc", "test": "npx jest", @@ -36,7 +36,7 @@ }, "license": "MIT", "engines": { - "node": "^18.0.0 || ^20.0.0 || ^22.0.0 " + "node": "^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0 " }, "os": [ "darwin", From 06e20a4c0d06db0d7d64cc7891a6258897bd0965 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Sun, 26 May 2024 23:47:19 +0200 Subject: [PATCH 54/77] Wrapper, JS: add support for node 22 back, since it seems to work, fix it by specifying a flag, to disable a gcc-14 warning --- wrapper/javascript/binding.gyp | 1 + wrapper/javascript/package.json | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/wrapper/javascript/binding.gyp b/wrapper/javascript/binding.gyp index d2c27c10..93c7f0ed 100644 --- a/wrapper/javascript/binding.gyp +++ b/wrapper/javascript/binding.gyp @@ -14,6 +14,7 @@ "-fexceptions", "-frtti", "-Wno-cast-function-type", # since nan.h -> node.h has some warnings regarding that + "-Wno-template-id-cdtor", # since nan.h -> node.h has some warnings regarding that " Date: Mon, 27 May 2024 00:06:27 +0200 Subject: [PATCH 55/77] CI: wrapper, try to fix it for windows --- .github/workflows/wrapper.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml index 89b583f8..cbaf0319 100644 --- a/.github/workflows/wrapper.yml +++ b/.github/workflows/wrapper.yml @@ -85,6 +85,13 @@ jobs: sudo apt-get install ninja-build -y sudo pip install meson --break-system-packages + - name: Fix pkg-config (Windows) + if: matrix.config.os == 'windows' + run: | + Remove-Item -Path C:\Strawberry\ -Recurse + choco install pkgconfiglite + echo "PKG_CONFIG_PATH=C:/lib/pkgconfig" >> "$GITHUB_ENV" + - name: Configure run: meson setup build -Dbuildtype=release -Ddefault_library=static -Dclang_libcpp=disabled -Donly_build_libs=true @@ -96,12 +103,6 @@ jobs: if: matrix.config.os == 'ubuntu' run: sudo meson install -C build - - name: Remove Strawberry perl pkg-config - if: matrix.config.os == 'windows' - uses: JesseTG/rm@v1.0.3 - with: - path: C:/Strawberry/ - - name: Install Node.js uses: actions/setup-node@v4 with: From dddc747f6c888eff4e64b0b4dee1ae4727c405a9 Mon Sep 17 00:00:00 2001 From: "Totto16 (Windows VM)" Date: Mon, 27 May 2024 01:58:54 +0200 Subject: [PATCH 56/77] Wrapper, JS: make it windows comaptible: - add the NOMINMAX hack (I hate windows.h xD) - fix building with many hacks in the bindings.py - fix compilation in CI, since we have to use static stdlib --- .github/workflows/wrapper.yml | 2 +- wrapper/javascript/binding.gyp | 38 +++++++++++++++++++++++--- wrapper/javascript/src/cpp/wrapper.cpp | 6 ++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml index cbaf0319..50d5abbd 100644 --- a/.github/workflows/wrapper.yml +++ b/.github/workflows/wrapper.yml @@ -93,7 +93,7 @@ jobs: echo "PKG_CONFIG_PATH=C:/lib/pkgconfig" >> "$GITHUB_ENV" - name: Configure - run: meson setup build -Dbuildtype=release -Ddefault_library=static -Dclang_libcpp=disabled -Donly_build_libs=true + run: meson setup build -Dbuildtype=release -Ddefault_library=static -Dclang_libcpp=disabled -Donly_build_libs=true ${{ matrix.config.os == 'windows' && '-Db_vscrt=static_from_buildtype' || '' }} - name: Build and install Libs if: matrix.config.os != 'ubuntu' diff --git a/wrapper/javascript/binding.gyp b/wrapper/javascript/binding.gyp index 93c7f0ed..9e7b0ab3 100644 --- a/wrapper/javascript/binding.gyp +++ b/wrapper/javascript/binding.gyp @@ -21,7 +21,23 @@ [ 'OS == "mac"', {"cflags_cc!": ["-std=c++23"], "cflags_cc+": ["-std=c++20"]}, - ] + ], + [ + 'OS != "win"', + { + "libraries": [ + " node.h has some warnings regarding that + ".a via some sed magic + ], + }, + }, } ], } diff --git a/wrapper/javascript/src/cpp/wrapper.cpp b/wrapper/javascript/src/cpp/wrapper.cpp index 4fd72658..25a4adbd 100644 --- a/wrapper/javascript/src/cpp/wrapper.cpp +++ b/wrapper/javascript/src/cpp/wrapper.cpp @@ -1,3 +1,9 @@ +#ifdef _WIN32 +#ifndef NOMINMAX +#define NOMINMAX +#endif +#endif + #include #include From 27e99e88b3dcbb4459ad4b5883a038d2ff1250c8 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 02:25:08 +0200 Subject: [PATCH 57/77] Wrapper, JS: use static build also on linux /mac os --- wrapper/javascript/binding.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/wrapper/javascript/binding.gyp b/wrapper/javascript/binding.gyp index 9e7b0ab3..19d0f594 100644 --- a/wrapper/javascript/binding.gyp +++ b/wrapper/javascript/binding.gyp @@ -16,6 +16,7 @@ "-Wno-cast-function-type", # since nan.h -> node.h has some warnings regarding that "-Wno-template-id-cdtor", # since nan.h -> node.h has some warnings regarding that " Date: Mon, 27 May 2024 02:43:20 +0200 Subject: [PATCH 58/77] try to fix windows PKG_CONFIG_PATH --- .github/workflows/wrapper.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml index 50d5abbd..a1f7b2e3 100644 --- a/.github/workflows/wrapper.yml +++ b/.github/workflows/wrapper.yml @@ -90,7 +90,7 @@ jobs: run: | Remove-Item -Path C:\Strawberry\ -Recurse choco install pkgconfiglite - echo "PKG_CONFIG_PATH=C:/lib/pkgconfig" >> "$GITHUB_ENV" + echo "PKG_CONFIG_PATH=C:/lib/pkgconfig" | Out-File -FilePath $env:GITHUB_ENV -Append - name: Configure run: meson setup build -Dbuildtype=release -Ddefault_library=static -Dclang_libcpp=disabled -Donly_build_libs=true ${{ matrix.config.os == 'windows' && '-Db_vscrt=static_from_buildtype' || '' }} From 163b8cdc6d4e88f541326d57fd52e64668fc837a Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 02:43:36 +0200 Subject: [PATCH 59/77] Wrapper, JS: fix clang builds --- wrapper/javascript/binding.gyp | 1 - wrapper/javascript/src/cpp/wrapper.cpp | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/wrapper/javascript/binding.gyp b/wrapper/javascript/binding.gyp index 19d0f594..56dd3e6c 100644 --- a/wrapper/javascript/binding.gyp +++ b/wrapper/javascript/binding.gyp @@ -14,7 +14,6 @@ "-fexceptions", "-frtti", "-Wno-cast-function-type", # since nan.h -> node.h has some warnings regarding that - "-Wno-template-id-cdtor", # since nan.h -> node.h has some warnings regarding that " +#if defined(__GNUC__) & !defined(__clang__) +#pragma GCC diagnostic pop +#endif + + #include #include From 1bf4668ba0442257f8950cd24169753dc12643c9 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 03:10:50 +0200 Subject: [PATCH 60/77] Wrapper, JS: - fix Ci, by using libcpp in macos build - fix binding.gyp build on mac --- .github/workflows/wrapper.yml | 2 +- wrapper/javascript/binding.gyp | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml index a1f7b2e3..7cf26919 100644 --- a/.github/workflows/wrapper.yml +++ b/.github/workflows/wrapper.yml @@ -93,7 +93,7 @@ jobs: echo "PKG_CONFIG_PATH=C:/lib/pkgconfig" | Out-File -FilePath $env:GITHUB_ENV -Append - name: Configure - run: meson setup build -Dbuildtype=release -Ddefault_library=static -Dclang_libcpp=disabled -Donly_build_libs=true ${{ matrix.config.os == 'windows' && '-Db_vscrt=static_from_buildtype' || '' }} + run: meson setup build -Dbuildtype=release -Ddefault_library=static -Dclang_libcpp=-Dclang_libcpp=${{ matrix.config.os == 'macos' && 'enabled' || 'disabled' }} -Donly_build_libs=true ${{ matrix.config.os == 'windows' && '-Db_vscrt=static_from_buildtype' || '' }} - name: Build and install Libs if: matrix.config.os != 'ubuntu' diff --git a/wrapper/javascript/binding.gyp b/wrapper/javascript/binding.gyp index 56dd3e6c..39745b7b 100644 --- a/wrapper/javascript/binding.gyp +++ b/wrapper/javascript/binding.gyp @@ -20,7 +20,25 @@ "conditions": [ [ 'OS == "mac"', - {"cflags_cc!": ["-std=c++23"], "cflags_cc+": ["-std=c++20"]}, + { + "xcode_settings": { + "OTHER_CFLAGS+": [ + "-std=c++23", + "-Wall", + "-Wextra", + "-Wno-unused-parameter", + "-O3", + "-Werror", + "-Wpedantic", + "-fexceptions", + "-frtti", + "-Wno-cast-function-type", # since nan.h -> node.h has some warnings regarding that + " Date: Mon, 27 May 2024 03:17:35 +0200 Subject: [PATCH 61/77] CI: wrapper: fix mistype --- .github/workflows/wrapper.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wrapper.yml b/.github/workflows/wrapper.yml index 7cf26919..5f5bf15d 100644 --- a/.github/workflows/wrapper.yml +++ b/.github/workflows/wrapper.yml @@ -93,7 +93,7 @@ jobs: echo "PKG_CONFIG_PATH=C:/lib/pkgconfig" | Out-File -FilePath $env:GITHUB_ENV -Append - name: Configure - run: meson setup build -Dbuildtype=release -Ddefault_library=static -Dclang_libcpp=-Dclang_libcpp=${{ matrix.config.os == 'macos' && 'enabled' || 'disabled' }} -Donly_build_libs=true ${{ matrix.config.os == 'windows' && '-Db_vscrt=static_from_buildtype' || '' }} + run: meson setup build -Dbuildtype=release -Ddefault_library=static -Dclang_libcpp=${{ matrix.config.os == 'macos' && 'enabled' || 'disabled' }} -Donly_build_libs=true ${{ matrix.config.os == 'windows' && '-Db_vscrt=static_from_buildtype' || '' }} - name: Build and install Libs if: matrix.config.os != 'ubuntu' From e602fea0617b2adaa752cb97e57a880469a57c7d Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 15:40:38 +0200 Subject: [PATCH 62/77] use prebuildify 6.0.2 --- wrapper/javascript/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrapper/javascript/package.json b/wrapper/javascript/package.json index 2ba7c87d..807a58fc 100644 --- a/wrapper/javascript/package.json +++ b/wrapper/javascript/package.json @@ -54,7 +54,7 @@ "@types/jest": "^29.5.12", "jest": "^29.7.0", "nan": "^2.19.0", - "prebuildify": "^5.0.1", + "prebuildify": "^6.0.2", "ts-jest": "^29.1.3", "ts-node": "^10.9.2", "typescript": "^5.4.5" From 92dafbe7e286bfbe402309162a5e649309226003 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 15:49:18 +0200 Subject: [PATCH 63/77] fix flatpak build --- src/executables/game/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/executables/game/main.cpp b/src/executables/game/main.cpp index f85e0122..6f7357e3 100644 --- a/src/executables/game/main.cpp +++ b/src/executables/game/main.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #if defined(__ANDROID__) #include From dedb9cbd212fb1148ae23470b983b0d328e283bc Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 15:54:43 +0200 Subject: [PATCH 64/77] fix switch / 3ds build --- src/executables/game/parser.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/executables/game/parser.hpp b/src/executables/game/parser.hpp index 211c7f7d..790b35eb 100644 --- a/src/executables/game/parser.hpp +++ b/src/executables/game/parser.hpp @@ -6,6 +6,7 @@ #include +#include namespace helper { From 3aebac0420e1e81f9a1d973a0e5f6a6d332a944f Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 16:15:48 +0200 Subject: [PATCH 65/77] CI: flatpak add verbose option, if enabled by github --- .github/workflows/flatpak.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/flatpak.yml b/.github/workflows/flatpak.yml index 716db255..a0e81d00 100644 --- a/.github/workflows/flatpak.yml +++ b/.github/workflows/flatpak.yml @@ -21,3 +21,4 @@ jobs: with: bundle: oopetris.flatpak manifest-path: com.github.mgerhold.OOPetris.yml + verbose: ${{ runner.debug == '1' && 'true' || 'false' }} From 21b05ae37ee2b859b4894f0765013841cba11b04 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 16:16:15 +0200 Subject: [PATCH 66/77] Wrapper, JS: bump version and upload all supported archs to selfhosted registry --- wrapper/javascript/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrapper/javascript/package.json b/wrapper/javascript/package.json index 807a58fc..70b52b1a 100644 --- a/wrapper/javascript/package.json +++ b/wrapper/javascript/package.json @@ -1,6 +1,6 @@ { "name": "oopetris", - "version": "1.0.0", + "version": "1.0.1", "description": "Node js wrapper for oopetris", "gypfile": true, "main": "./dist/index.js", From 9337379979e3f233c03d573a455a6f15ed1f6c5c Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 16:52:28 +0200 Subject: [PATCH 67/77] - fix a few clang-tidy issues - wrap all main functions in a try catch, to print the exception message - replace all usage of helper::expected with helper::expected, where only true is used as teh state of the bool, just to signify .has_value() --- src/executables/game/main.cpp | 133 ++++++++++-------- src/executables/utility/main.cpp | 68 +++++---- src/game/command_line_arguments.cpp | 2 +- src/game/command_line_arguments.hpp | 4 +- src/helper/clock_source.hpp | 2 +- src/input/controller_input.cpp | 2 +- src/input/controller_input.hpp | 2 +- src/input/input.hpp | 4 +- src/input/joystick_input.hpp | 2 +- src/input/keyboard_input.cpp | 2 +- src/input/keyboard_input.hpp | 2 +- src/input/touch_input.cpp | 4 +- src/input/touch_input.hpp | 4 +- src/libs/core/helper/bool_wrapper.hpp | 18 +-- src/libs/recordings/utility/helper.hpp | 8 +- .../recordings/utility/recording_writer.cpp | 18 +-- .../recordings/utility/recording_writer.hpp | 12 +- .../recordings/utility/tetrion_snapshot.cpp | 10 +- .../recordings/utility/tetrion_snapshot.hpp | 2 +- src/lobby/api.hpp | 24 ++-- 20 files changed, 179 insertions(+), 144 deletions(-) diff --git a/src/executables/game/main.cpp b/src/executables/game/main.cpp index 6f7357e3..7ea3fa28 100644 --- a/src/executables/game/main.cpp +++ b/src/executables/game/main.cpp @@ -10,6 +10,7 @@ #include "helper/graphic_utils.hpp" #include "helper/message_box.hpp" +#include #include #include #include @@ -29,92 +30,110 @@ #include -int main(int argc, char** argv) { - const auto logs_path = utils::get_root_folder() / "logs"; - if (not std::filesystem::exists(logs_path)) { - std::filesystem::create_directory(logs_path); - } +namespace { + void initialize_spdlog() { + + const auto logs_path = utils::get_root_folder() / "logs"; + if (not std::filesystem::exists(logs_path)) { + std::filesystem::create_directory(logs_path); + } - std::vector sinks; + std::vector sinks; #if defined(__ANDROID__) - sinks.push_back(std::make_shared()); + sinks.push_back(std::make_shared()); #elif defined(__CONSOLE__) - sinks.push_back(std::make_shared()); + sinks.push_back(std::make_shared()); #else - sinks.push_back(std::make_shared()); + sinks.push_back(std::make_shared()); #endif - sinks.push_back(std::make_shared( - fmt::format("{}/oopetris.log", logs_path.string()), 1024 * 1024 * 10, 5, true - )); - auto combined_logger = std::make_shared("combined_logger", begin(sinks), end(sinks)); - spdlog::set_default_logger(combined_logger); + sinks.push_back(std::make_shared( + fmt::format("{}/oopetris.log", logs_path.string()), 1024 * 1024 * 10, 5, true + )); + auto combined_logger = std::make_shared("combined_logger", begin(sinks), end(sinks)); + spdlog::set_default_logger(combined_logger); #if !defined(NDEBUG) - spdlog::set_level(spdlog::level::debug); + spdlog::set_level(spdlog::level::debug); #else - spdlog::set_level(spdlog::level::err); + spdlog::set_level(spdlog::level::err); #endif - - std::vector arguments_vector{}; - arguments_vector.reserve(argc); - for (auto i = 0; i < argc; ++i) { - arguments_vector.emplace_back(argv[i]); //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } - if (arguments_vector.empty()) { - arguments_vector.emplace_back("oopetris"); - } - auto parsed_arguments = helper::parse_args(arguments_vector); +} // namespace - if (not parsed_arguments.has_value()) { +int main(int argc, char** argv) noexcept { - spdlog::error("error parsing command line arguments: {}", parsed_arguments.error()); -#if defined(__ANDROID__) - // calling exit() in android doesn't do the correct job, it completely avoids resource cleanup by the underlying SDLActivity.java - // (java wrapper), that calls the main and expects it to return ALWAYS and throwing an exception in a catch statement is bad, - // but is required here - throw std::runtime_error{ "exit with status code 1: " + parsed_arguments.error() }; -#else - std::exit(1); -#endif - } + std::shared_ptr window{ nullptr }; - auto arguments = std::move(parsed_arguments.value()); + try { - constexpr auto window_name = constants::program_name.c_str(); + initialize_spdlog(); - std::shared_ptr window{ nullptr }; + std::vector arguments_vector{}; + arguments_vector.reserve(argc); + for (auto i = 0; i < argc; ++i) { + arguments_vector.emplace_back(argv[i]); //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + } - try { + if (arguments_vector.empty()) { + arguments_vector.emplace_back("oopetris"); + } + + auto parsed_arguments = helper::parse_args(arguments_vector); + + if (not parsed_arguments.has_value()) { + + spdlog::error("error parsing command line arguments: {}", parsed_arguments.error()); + return EXIT_FAILURE; + } + + auto arguments = std::move(parsed_arguments.value()); + + [[maybe_unused]] constexpr auto window_name = constants::program_name.c_str(); + + + try { #if defined(__ANDROID__) or defined(__CONSOLE__) - window = std::make_shared(window_name, WindowPosition::Centered); + window = std::make_shared(window_name, WindowPosition::Centered); #else - static constexpr int width = 1280; - static constexpr int height = 720; - - window = std::make_shared(window_name, WindowPosition::Centered, width, height); + [[maybe_unused]] static constexpr int width = 1280; + [[maybe_unused]] static constexpr int height = 720; + window = std::make_shared(window_name, WindowPosition::Centered, width, height); #endif - } catch (const helper::GeneralError& general_error) { - spdlog::error("{}", general_error.message()); - } - - if (window == nullptr) { - helper::MessageBox::show_simple( - helper::MessageBox::Type::Error, "Initialization Error", "failed to create SDL window", nullptr - ); - return EXIT_FAILURE; - } + } catch (const helper::GeneralError& general_error) { + spdlog::error("Couldn't initialize window: {}", general_error.message()); + } + if (window == nullptr) { + helper::MessageBox::show_simple( + helper::MessageBox::Type::Error, "Initialization Error", "failed to create SDL window", nullptr + ); + return EXIT_FAILURE; + } - try { Application app{ std::move(window), std::move(arguments) }; app.run(); return EXIT_SUCCESS; - } catch (const helper::GeneralError& general_error) { + } catch (const helper::GeneralError& general_error) { spdlog::error("{}", general_error.message()); + + + if (window == nullptr) { + helper::MessageBox::show_simple( + helper::MessageBox::Type::Error, "Initialization Error", general_error.message(), nullptr + ); + } else { + window->show_simple(helper::MessageBox::Type::Error, "Initialization Error", general_error.message()); + } + + + return EXIT_FAILURE; + } catch (const std::exception& error) { + // this is the last resort, so using std::cerr and no sdl show_simple messagebox! + std::cerr << error.what(); return EXIT_FAILURE; } } diff --git a/src/executables/utility/main.cpp b/src/executables/utility/main.cpp index 0040fbb9..2315bf8c 100644 --- a/src/executables/utility/main.cpp +++ b/src/executables/utility/main.cpp @@ -3,6 +3,7 @@ #include +#include #include #include @@ -30,7 +31,14 @@ void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_pr indent_char = '\t'; } - std::cout << result.value().dump(indent, indent_char, ensure_ascii); + try { + + std::cout << result.value().dump(indent, indent_char, ensure_ascii); + + } catch (const std::exception& error) { + std::cerr << error.what(); + std::exit(1); + } if (pretty_print) { std::cout << "\n"; @@ -40,43 +48,49 @@ void dump_json(const recorder::RecordingReader& recording_reader, bool pretty_pr int main(int argc, char** argv) noexcept { - const auto arguments_result = CommandLineArguments::from_args(argc, argv); + try { - if (not arguments_result.has_value()) { - std::cerr << arguments_result.error(); - std::exit(1); - } - const auto arguments = arguments_result.value(); + auto arguments_result = CommandLineArguments::from_args(argc, argv); + if (not arguments_result.has_value()) { + std::cerr << arguments_result.error(); + std::exit(1); + } - if (not std::filesystem::exists(arguments.recording_path)) { - std::cerr << arguments.recording_path << " does not exist!\n"; - return 1; - } + auto arguments = std::move(arguments_result.value()); + if (not std::filesystem::exists(arguments.recording_path)) { + std::cerr << arguments.recording_path << " does not exist!\n"; + return 1; + } - auto parsed = recorder::RecordingReader::from_path(arguments.recording_path); - if (not parsed.has_value()) { - std::cerr << fmt::format( - "An error occurred during parsing of the recording file '{}': {}\n", arguments.recording_path.string(), - parsed.error() - ); - return 1; - } + auto parsed = recorder::RecordingReader::from_path(arguments.recording_path); + if (not parsed.has_value()) { + std::cerr << fmt::format( + "An error occurred during parsing of the recording file '{}': {}\n", + arguments.recording_path.string(), parsed.error() + ); + return 1; + } - const auto recording_reader = std::move(parsed.value()); - std::visit( - helper::overloaded{ [&recording_reader](const Dump& dump) { - dump_json(recording_reader, dump.pretty_print, dump.ensure_ascii); - }, - [&recording_reader](const Info& /* info */) { print_info(recording_reader); } }, - arguments.value - ); + const auto recording_reader = std::move(parsed.value()); + std::visit( + helper::overloaded{ [&recording_reader](const Dump& dump) { + dump_json(recording_reader, dump.pretty_print, dump.ensure_ascii); + }, + [&recording_reader](const Info& /* info */) { print_info(recording_reader); } }, + arguments.value + ); + + } catch (const std::exception& error) { + std::cerr << error.what(); + return 1; + } return 0; } diff --git a/src/game/command_line_arguments.cpp b/src/game/command_line_arguments.cpp index 79bcc4b1..48f068aa 100644 --- a/src/game/command_line_arguments.cpp +++ b/src/game/command_line_arguments.cpp @@ -10,7 +10,7 @@ CommandLineArguments::CommandLineArguments( Level starting_level, bool silent ) - : recording_path{ recording_path }, + : recording_path{ std::move(recording_path) }, target_fps{ target_fps }, starting_level{ starting_level }, silent{ silent } { } diff --git a/src/game/command_line_arguments.hpp b/src/game/command_line_arguments.hpp index a7efcde1..274e6b58 100644 --- a/src/game/command_line_arguments.hpp +++ b/src/game/command_line_arguments.hpp @@ -11,8 +11,8 @@ struct CommandLineArguments final { - static inline const constexpr auto default_starting_level = u32{ 0 }; - static inline const constexpr auto default_silent = bool{ true }; + static const constexpr auto default_starting_level = u32{ 0 }; + static const constexpr auto default_silent = true; std::optional recording_path; std::optional target_fps; diff --git a/src/helper/clock_source.hpp b/src/helper/clock_source.hpp index 3aa72413..91db02c6 100644 --- a/src/helper/clock_source.hpp +++ b/src/helper/clock_source.hpp @@ -29,7 +29,7 @@ struct LocalClock : public ClockSource { private: double m_start_time; double m_step_duration; - std::optional m_paused_at{}; + std::optional m_paused_at; public: explicit LocalClock(u32 target_frequency); diff --git a/src/input/controller_input.cpp b/src/input/controller_input.cpp index d9b5a921..5841a542 100644 --- a/src/input/controller_input.cpp +++ b/src/input/controller_input.cpp @@ -181,7 +181,7 @@ input::ControllerInput::get_by_device_index(int device_index) { } -[[nodiscard]] helper::expected input::ControllerSettings::validate() const { +[[nodiscard]] helper::expected input::ControllerSettings::validate() const { const std::vector to_use{ rotate_left, rotate_right, move_left, move_right, move_down, drop, hold, pause, open_settings }; diff --git a/src/input/controller_input.hpp b/src/input/controller_input.hpp index 873945b7..7d2a577e 100644 --- a/src/input/controller_input.hpp +++ b/src/input/controller_input.hpp @@ -48,7 +48,7 @@ namespace input { sdl::ControllerKey open_settings; - [[nodiscard]] helper::expected validate() const; + [[nodiscard]] helper::expected validate() const; [[nodiscard]] static ControllerSettings default_settings() { diff --git a/src/input/input.hpp b/src/input/input.hpp index fa925de1..f6c75b77 100644 --- a/src/input/input.hpp +++ b/src/input/input.hpp @@ -116,7 +116,7 @@ namespace input { struct InputSettings { template - [[nodiscard]] static helper::expected has_unique_members(const std::vector& to_check) { + [[nodiscard]] static helper::expected has_unique_members(const std::vector& to_check) { std::vector already_bound{}; @@ -129,7 +129,7 @@ namespace input { already_bound.push_back(single_check); } - return true; + return {}; } }; diff --git a/src/input/joystick_input.hpp b/src/input/joystick_input.hpp index 892b9f17..add8bf27 100644 --- a/src/input/joystick_input.hpp +++ b/src/input/joystick_input.hpp @@ -44,7 +44,7 @@ namespace input { T open_settings; - [[nodiscard]] helper::expected validate() const { + [[nodiscard]] helper::expected validate() const { const std::vector to_use{ rotate_left, rotate_right, move_left, move_right, move_down, drop, hold, pause, open_settings }; diff --git a/src/input/keyboard_input.cpp b/src/input/keyboard_input.cpp index 88ede9d1..da37ce6e 100644 --- a/src/input/keyboard_input.cpp +++ b/src/input/keyboard_input.cpp @@ -163,7 +163,7 @@ input::KeyboardGameInput::KeyboardGameInput(KeyboardGameInput&& input) noexcept ) noexcept = default; -[[nodiscard]] helper::expected input::KeyboardSettings::validate() const { +[[nodiscard]] helper::expected input::KeyboardSettings::validate() const { const std::vector to_use{ rotate_left, rotate_right, move_left, move_right, move_down, drop, hold, pause, open_settings }; diff --git a/src/input/keyboard_input.hpp b/src/input/keyboard_input.hpp index 58695c78..ef2f5368 100644 --- a/src/input/keyboard_input.hpp +++ b/src/input/keyboard_input.hpp @@ -39,7 +39,7 @@ namespace input { sdl::Key open_settings; - [[nodiscard]] helper::expected validate() const; + [[nodiscard]] helper::expected validate() const; [[nodiscard]] static KeyboardSettings default_settings() { return KeyboardSettings{ .rotate_left = sdl::Key{ SDLK_LEFT }, diff --git a/src/input/touch_input.cpp b/src/input/touch_input.cpp index 2f607ef2..b7654f01 100644 --- a/src/input/touch_input.cpp +++ b/src/input/touch_input.cpp @@ -299,7 +299,7 @@ input::TouchInput::get_by_device_index(const std::shared_ptr& window, in return new_event; } -[[nodiscard]] helper::expected input::TouchSettings::validate() const { +[[nodiscard]] helper::expected input::TouchSettings::validate() const { if (move_x_threshold > 1.0 || move_x_threshold < 0.0) { return helper::unexpected{ @@ -313,7 +313,7 @@ input::TouchInput::get_by_device_index(const std::shared_ptr& window, in }; } - return true; + return {}; } diff --git a/src/input/touch_input.hpp b/src/input/touch_input.hpp index c27e9d56..134c9e9c 100644 --- a/src/input/touch_input.hpp +++ b/src/input/touch_input.hpp @@ -45,7 +45,7 @@ namespace input { u32 rotation_duration_threshold; u32 drop_duration_threshold; - [[nodiscard]] helper::expected validate() const; + [[nodiscard]] helper::expected validate() const; [[nodiscard]] static TouchSettings default_settings() { return TouchSettings{ .move_x_threshold = 150.0 / 2160.0, @@ -116,7 +116,7 @@ namespace json_helper { template [[nodiscard]] T get_number(const nlohmann::json& obj, const std::string& name) { - helper::expected error = true; + helper::expected error{}; auto context = obj.at(name); diff --git a/src/libs/core/helper/bool_wrapper.hpp b/src/libs/core/helper/bool_wrapper.hpp index 3341c815..32c41eb7 100644 --- a/src/libs/core/helper/bool_wrapper.hpp +++ b/src/libs/core/helper/bool_wrapper.hpp @@ -9,29 +9,31 @@ namespace helper { struct BoolWrapper { private: bool m_value; - std::optional additional; + std::optional m_additional; public: - BoolWrapper(bool value) : m_value{ value }, additional{ std::nullopt } { } + BoolWrapper(bool value) //NOLINT(google-explicit-constructor) + : m_value{ value }, + m_additional{ std::nullopt } { } - BoolWrapper(bool value, const T& additional) : m_value{ value }, additional{ additional } { } + BoolWrapper(bool value, const T& additional) : m_value{ value }, m_additional{ additional } { } - BoolWrapper(bool value, const std::optional& additional) : m_value{ value }, additional{ additional } { } + BoolWrapper(bool value, const std::optional& additional) : m_value{ value }, m_additional{ additional } { } const std::optional& get_additional() const { - return additional; + return m_additional; } [[nodiscard]] bool has_additional() const { - return additional.has_value(); + return m_additional.has_value(); } bool is(const T& value) const { - return value == additional; + return value == m_additional; } - operator bool() const { + operator bool() const { //NOLINT(google-explicit-constructor) return m_value; } }; diff --git a/src/libs/recordings/utility/helper.hpp b/src/libs/recordings/utility/helper.hpp index 3bd19fe5..3f50c671 100644 --- a/src/libs/recordings/utility/helper.hpp +++ b/src/libs/recordings/utility/helper.hpp @@ -124,7 +124,7 @@ namespace helper { namespace writer { template - helper::expected write_integral_to_file(std::ofstream& file, const Integral data) { + helper::expected write_integral_to_file(std::ofstream& file, const Integral data) { if (not file) { return helper::unexpected{ fmt::format("failed to write data \"{}\"", data) }; } @@ -137,12 +137,12 @@ namespace helper { sizeof(little_endian_data) ); - return true; + return {}; } template - helper::expected write_vector_to_file(std::ofstream& file, const std::vector& values) { - helper::expected result{ true }; + helper::expected write_vector_to_file(std::ofstream& file, const std::vector& values) { + helper::expected result{}; for (const auto& value : values) { result = write_integral_to_file(file, value); if (not result.has_value()) { diff --git a/src/libs/recordings/utility/recording_writer.cpp b/src/libs/recordings/utility/recording_writer.cpp index dc2686a3..9da53ff9 100644 --- a/src/libs/recordings/utility/recording_writer.cpp +++ b/src/libs/recordings/utility/recording_writer.cpp @@ -28,7 +28,7 @@ helper::expected recorder::RecordingWrit return helper::unexpected{ fmt::format("failed to open output file \"{}\"", path.string()) }; } - helper::expected result{ true }; + helper::expected result{}; static_assert(sizeof(constants::recording::magic_file_byte) == 4); result = helper::writer::write_integral_to_file(output_file, constants::recording::magic_file_byte); @@ -74,14 +74,14 @@ helper::expected recorder::RecordingWrit return RecordingWriter{ std::move(output_file), std::move(tetrion_headers), std::move(information) }; } -helper::expected recorder::RecordingWriter::add_event( +helper::expected recorder::RecordingWriter::add_event( const u8 tetrion_index, // NOLINT(bugprone-easily-swappable-parameters) const u64 simulation_step_index, const InputEvent event ) { assert(tetrion_index < m_tetrion_headers.size()); - helper::expected result{ true }; + helper::expected result{}; static_assert(sizeof(std::underlying_type_t) == 1); result = write(utils::to_underlying(MagicByte::Record)); @@ -107,13 +107,13 @@ helper::expected recorder::RecordingWriter::add_event( return result; } -helper::expected recorder::RecordingWriter::add_snapshot( +helper::expected recorder::RecordingWriter::add_snapshot( const u8 tetrion_index, const u64 simulation_step_index, std::unique_ptr information ) { - helper::expected result{ true }; + helper::expected result{}; static_assert(sizeof(std::underlying_type_t) == 1); result = write(utils::to_underlying(MagicByte::Snapshot)); @@ -132,9 +132,9 @@ helper::expected recorder::RecordingWriter::add_snapshot( } -helper::expected +helper::expected recorder::RecordingWriter::write_tetrion_header_to_file(std::ofstream& file, const TetrionHeader& header) { - helper::expected result{ true }; + helper::expected result{}; static_assert(sizeof(decltype(header.seed)) == 8); result = helper::writer::write_integral_to_file(file, header.seed); @@ -151,7 +151,7 @@ recorder::RecordingWriter::write_tetrion_header_to_file(std::ofstream& file, con return result; } -helper::expected recorder::RecordingWriter::write_checksum_to_file( +helper::expected recorder::RecordingWriter::write_checksum_to_file( std::ofstream& file, const std::vector& tetrion_headers, const AdditionalInformation& information @@ -161,7 +161,7 @@ helper::expected recorder::RecordingWriter::write_checksum_to Recording::get_header_checksum(Recording::current_supported_version_number, tetrion_headers, information); static_assert(sizeof(decltype(checksum)) == 32); - helper::expected result{ true }; + helper::expected result{}; for (const auto& checksum_byte : checksum) { result = helper::writer::write_integral_to_file(file, checksum_byte); diff --git a/src/libs/recordings/utility/recording_writer.hpp b/src/libs/recordings/utility/recording_writer.hpp index e8a87098..13d42441 100644 --- a/src/libs/recordings/utility/recording_writer.hpp +++ b/src/libs/recordings/utility/recording_writer.hpp @@ -29,32 +29,32 @@ namespace recorder { AdditionalInformation&& information ); - helper::expected add_event( + helper::expected add_event( u8 tetrion_index, // NOLINT(bugprone-easily-swappable-parameters) u64 simulation_step_index, InputEvent event ); - helper::expected + helper::expected add_snapshot(u8 tetrion_index, u64 simulation_step_index, std::unique_ptr information); private: - static helper::expected + static helper::expected write_tetrion_header_to_file(std::ofstream& file, const TetrionHeader& header); - static helper::expected write_checksum_to_file( + static helper::expected write_checksum_to_file( std::ofstream& file, const std::vector& tetrion_headers, const AdditionalInformation& information ); template - helper::expected write(Integral data) { + helper::expected write(Integral data) { const auto result = helper::writer::write_integral_to_file(m_output_file, data); if (not result.has_value()) { return helper::unexpected{ fmt::format("error while writing: {}", result.error()) }; } - return true; + return {}; } }; diff --git a/src/libs/recordings/utility/tetrion_snapshot.cpp b/src/libs/recordings/utility/tetrion_snapshot.cpp index cf284c14..fca9d6bb 100644 --- a/src/libs/recordings/utility/tetrion_snapshot.cpp +++ b/src/libs/recordings/utility/tetrion_snapshot.cpp @@ -165,19 +165,19 @@ TetrionSnapshot::TetrionSnapshot( namespace { template - helper::expected + helper::expected compare_values(const std::string_view name, const Value& this_value, const Value& other_value) { if (this_value != other_value) { return helper::unexpected{ fmt::format("{} do not match:\n {} vs. {}", name, this_value, other_value) }; } - return true; + return {}; } } // namespace -helper::expected TetrionSnapshot::compare_to(const TetrionSnapshot& other) const { - helper::expected result{ true }; +helper::expected TetrionSnapshot::compare_to(const TetrionSnapshot& other) const { + helper::expected result{}; result = compare_values("tetrion indices", m_tetrion_index, other.m_tetrion_index); if (not result.has_value()) { @@ -214,5 +214,5 @@ helper::expected TetrionSnapshot::compare_to(const TetrionSna return helper::unexpected{ fmt::format("mino stacks do not match:\n {}", string_stream.str()) }; } - return true; + return {}; } diff --git a/src/libs/recordings/utility/tetrion_snapshot.hpp b/src/libs/recordings/utility/tetrion_snapshot.hpp index a8ee37cf..4aa7a11a 100644 --- a/src/libs/recordings/utility/tetrion_snapshot.hpp +++ b/src/libs/recordings/utility/tetrion_snapshot.hpp @@ -56,5 +56,5 @@ struct TetrionSnapshot final { [[nodiscard]] std::vector to_bytes() const; - [[nodiscard]] helper::expected compare_to(const TetrionSnapshot& other) const; + [[nodiscard]] helper::expected compare_to(const TetrionSnapshot& other) const; }; diff --git a/src/lobby/api.hpp b/src/lobby/api.hpp index 7918bd96..4d6b43d4 100644 --- a/src/lobby/api.hpp +++ b/src/lobby/api.hpp @@ -34,7 +34,7 @@ namespace constants { const std::string json_content_type = "application/json"; } -namespace { +namespace { //NOLINT(cert-dcl59-cpp, google-build-namespaces) inline helper::expected is_json_response(const httplib::Result& result) { @@ -67,7 +67,7 @@ namespace { return helper::unexpected{ fmt::format("Couldn't parse json with error: {}", parsed.error()) }; } - inline helper::expected is_request_ok(const httplib::Result& result, int ok_code = 200) { + inline helper::expected is_request_ok(const httplib::Result& result, int ok_code = 200) { if (not result) { return helper::unexpected{ @@ -105,7 +105,7 @@ namespace { ) }; } - return true; + return {}; }; @@ -146,7 +146,7 @@ namespace lobby { // lobby commit used: https://github.com/OpenBrickProtocolFoundation/lobby/commit/2e0c8d05592f4e4d08437e6cb754a30f02c4e97c static constexpr StaticString supported_version{ "0.1.0" }; - helper::expected check_compatibility() { + helper::expected check_compatibility() { const auto server_version = get_version(); if (not server_version.has_value()) { @@ -166,10 +166,10 @@ namespace lobby { ) }; } - return true; + return {}; } - helper::expected check_reachability() { + helper::expected check_reachability() { auto result = m_client.Get("/"); @@ -179,7 +179,7 @@ namespace lobby { }; } - return true; + return {}; } explicit Client(const std::string& api_url) : m_client{ api_url } { @@ -277,7 +277,7 @@ namespace lobby { } - helper::expected join_lobby(int lobby_id) { + helper::expected join_lobby(int lobby_id) { if (not is_authenticated()) { return helper::unexpected{ "Authentication needed for this " @@ -303,7 +303,7 @@ namespace lobby { return get_json_from_request(res); } - helper::expected delete_lobby(int lobby_id) { + helper::expected delete_lobby(int lobby_id) { if (not is_authenticated()) { return helper::unexpected{ "Authentication needed for this " @@ -316,7 +316,7 @@ namespace lobby { return is_request_ok(res, 204); } - helper::expected leave_lobby(int lobby_id) { + helper::expected leave_lobby(int lobby_id) { if (not is_authenticated()) { return helper::unexpected{ "Authentication needed for this " @@ -329,7 +329,7 @@ namespace lobby { return is_request_ok(res, 204); } - helper::expected start_lobby(int lobby_id) { + helper::expected start_lobby(int lobby_id) { if (not is_authenticated()) { return helper::unexpected{ "Authentication needed for this " @@ -367,7 +367,7 @@ namespace lobby { return get_json_from_request>(res); } - helper::expected register_user(const RegisterRequest& register_request) { + helper::expected register_user(const RegisterRequest& register_request) { const auto json_result = json::try_json_to_string(register_request); if (not json_result.has_value()) { return helper::unexpected{ json_result.error() }; From 2e08e127c84f0550531518658ffdfe809afd6581 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 17:11:07 +0200 Subject: [PATCH 68/77] lobby: split api.hpp to separate cpp and hpp file --- src/lobby/api.cpp | 339 ++++++++++++++++++++++++++++++++++++++++++ src/lobby/api.hpp | 337 ++++------------------------------------- src/lobby/meson.build | 2 +- 3 files changed, 365 insertions(+), 313 deletions(-) create mode 100644 src/lobby/api.cpp diff --git a/src/lobby/api.cpp b/src/lobby/api.cpp new file mode 100644 index 00000000..27df24dd --- /dev/null +++ b/src/lobby/api.cpp @@ -0,0 +1,339 @@ + + +#include "api.hpp" + + +namespace { + + + inline helper::expected is_json_response(const httplib::Result& result) { + if (not result->has_header("Content-Type")) { + return helper::unexpected{ "Content-Type not set!" }; + } + + if (const auto value = result->get_header_value("Content-Type"); value != constants::json_content_type) { + return helper::unexpected{ fmt::format("Content-Type is not json but {}", value) }; + } + + return result->body; + } + + + inline helper::expected is_error_message_response(const httplib::Result& result + ) { + + const auto body = is_json_response(result); + if (not body.has_value()) { + return helper::unexpected{ body.error() }; + } + + const auto parsed = json::try_parse_json(body.value()); + + if (parsed.has_value()) { + return parsed.value(); + } + + return helper::unexpected{ fmt::format("Couldn't parse json with error: {}", parsed.error()) }; + } + + inline helper::expected is_request_ok(const httplib::Result& result, int ok_code = 200) { + + if (not result) { + return helper::unexpected{ + fmt::format("Request failed with: {}", httplib::to_string(result.error())) + }; + } + + if (result->status == 401) { + + const auto error_type = is_error_message_response(result); + + if (error_type.has_value()) { + return helper::unexpected{ fmt::format("Unauthorized: {}", error_type.value().message) }; + } + + return helper::unexpected{ "Unauthorized" }; + } + + + if (result->status != ok_code) { + + const auto error_type = is_error_message_response(result); + + if (error_type.has_value()) { + return helper::unexpected{ fmt::format( + "Got error response with status code {}: '{}' and message: {}", result->status, + httplib::status_message(result->status), error_type.value().message + ) }; + } + + + return helper::unexpected{ fmt::format( + "Got error response with status code {}: '{}' but expected {}", result->status, + httplib::status_message(result->status), ok_code + ) }; + } + + return {}; + }; + + + template + helper::expected get_json_from_request(const httplib::Result& result, int ok_code = 200) { + + const auto temp = is_request_ok(result, ok_code); + if (not temp.has_value()) { + return helper::unexpected{ temp.error() }; + } + + const auto body = is_json_response(result); + if (not body.has_value()) { + return helper::unexpected{ body.error() }; + } + + const auto parsed = json::try_parse_json(body.value()); + + if (parsed.has_value()) { + return parsed.value(); + } + + return helper::unexpected{ fmt::format("Couldn't parse json with error: {}", parsed.error()) }; + } + + +} // namespace + + +helper::expected lobby::Client::check_compatibility() { + const auto server_version = get_version(); + + if (not server_version.has_value()) { + return helper::unexpected{ fmt::format( + "Connecting to unsupported server, he can't report his version\nGot error: {}", server_version.error() + ) }; + } + + const auto& version = server_version.value(); + + //TODO(Totto): if version is semver, support semver comparison + if (Client::supported_version.string() != version.version) { + return helper::unexpected{ fmt::format( + "Connecting to unsupported server, version is {}, but we support only {}", + Client::supported_version.string(), version.version + ) }; + } + + return {}; +} + +helper::expected lobby::Client::check_reachability() { + + auto result = m_client.Get("/"); + + if (not result) { + return helper::unexpected{ + fmt::format("Server not reachable: {}", httplib::to_string(result.error())) + }; + } + + return {}; +} + +lobby::Client::Client(const std::string& api_url) : m_client{ api_url } { + + // clang-format off + m_client.set_default_headers({ +#if defined(CPPHTTPLIB_ZLIB_SUPPORT) || defined(CPPHTTPLIB_BROTLI_SUPPORT) + { "Accept-Encoding", + +#if defined(CPPHTTPLIB_ZLIB_SUPPORT) + "gzip, deflate" +#endif +#if defined(CPPHTTPLIB_ZLIB_SUPPORT) && defined(CPPHTTPLIB_BROTLI_SUPPORT) + ", " +#endif +#if defined(CPPHTTPLIB_BROTLI_SUPPORT) + "br" +#endif + }, +#endif + // clang-format on + { "Accept", constants::json_content_type } }); + +#if defined(CPPHTTPLIB_ZLIB_SUPPORT) || defined(CPPHTTPLIB_BROTLI_SUPPORT) + m_client.set_compress(true); + m_client.set_decompress(true); +#endif +} + +helper::expected lobby::Client::get_version() { + auto res = m_client.Get("/version"); + + return get_json_from_request(res); +} + + +lobby::Client::Client(Client&& other) noexcept + : m_client{ std::move(other.m_client) }, + m_authentication_token{ std::move(other.m_authentication_token) } { } + +lobby::Client::~Client() = default; + +helper::expected lobby::Client::get_client(const std::string& url) { + + Client client{ url }; + + const auto reachable = client.check_reachability(); + + if (not reachable.has_value()) { + return helper::unexpected{ reachable.error() }; + } + + //TODO(Totto): once version is standard, check here if the version is supported + + return client; +} + + +helper::expected lobby::Client::login(const Credentials& credentials) { + const auto json_result = json::try_json_to_string(credentials); + if (not json_result.has_value()) { + return helper::unexpected{ json_result.error() }; + } + + auto res = m_client.Post("/login", json_result.value(), constants::json_content_type); + + return get_json_from_request(res); +} + + +bool lobby::Client::is_authenticated() { + return m_authentication_token.has_value(); +} + +bool lobby::Client::authenticate(const Credentials& credentials) { + + const auto result = login(credentials); + + if (not result.has_value()) { + spdlog::error("Failed authenticating user {}: {}", credentials.username, result.error()); + m_authentication_token = std::nullopt; + return false; + } + + m_authentication_token = result.value().jwt; + + m_client.set_bearer_token_auth(m_authentication_token.value()); + + return true; +} + +helper::expected, std::string> lobby::Client::get_lobbies() { + auto res = m_client.Get("/lobbies"); + + return get_json_from_request>(res); +} + + +helper::expected lobby::Client::join_lobby(int lobby_id) { + if (not is_authenticated()) { + return helper::unexpected{ + "Authentication needed for this " + "endpoint, but not authenticated!" + }; + } + + auto res = m_client.Post(fmt::format("/lobbies/{}", lobby_id)); + + return is_request_ok(res, 204); +} + +helper::expected lobby::Client::get_lobby_detail(int lobby_id) { + if (not is_authenticated()) { + return helper::unexpected{ + "Authentication needed for this " + "endpoint, but not authenticated!" + }; + } + + auto res = m_client.Get(fmt::format("/lobbies/{}", lobby_id)); + + return get_json_from_request(res); +} + +helper::expected lobby::Client::delete_lobby(int lobby_id) { + if (not is_authenticated()) { + return helper::unexpected{ + "Authentication needed for this " + "endpoint, but not authenticated!" + }; + } + + auto res = m_client.Delete(fmt::format("/lobbies/{}", lobby_id)); + + return is_request_ok(res, 204); +} + +helper::expected lobby::Client::leave_lobby(int lobby_id) { + if (not is_authenticated()) { + return helper::unexpected{ + "Authentication needed for this " + "endpoint, but not authenticated!" + }; + } + + auto res = m_client.Put(fmt::format("/lobbies/{}/leave", lobby_id)); + + return is_request_ok(res, 204); +} + +helper::expected lobby::Client::start_lobby(int lobby_id) { + if (not is_authenticated()) { + return helper::unexpected{ + "Authentication needed for this " + "endpoint, but not authenticated!" + }; + } + + auto res = m_client.Post(fmt::format("/lobbies/{}/start", lobby_id)); + + return is_request_ok(res, 204); +} + +helper::expected lobby::Client::create_lobby( + const CreateLobbyRequest& arguments +) { + if (not is_authenticated()) { + return helper::unexpected{ + "Authentication needed for this " + "endpoint, but not authenticated!" + }; + } + + const auto json_result = json::try_json_to_string(arguments); + if (not json_result.has_value()) { + return helper::unexpected{ json_result.error() }; + } + + auto res = m_client.Post("/lobbies", json_result.value(), constants::json_content_type); + + return get_json_from_request(res, 201); +} + +helper::expected, std::string> lobby::Client::get_users() { + + auto res = m_client.Get("/users"); + + return get_json_from_request>(res); +} + +helper::expected lobby::Client::register_user(const RegisterRequest& register_request) { + const auto json_result = json::try_json_to_string(register_request); + if (not json_result.has_value()) { + return helper::unexpected{ json_result.error() }; + } + + auto res = m_client.Post("/register", json_result.value(), constants::json_content_type); + + return is_request_ok(res, 204); +} diff --git a/src/lobby/api.hpp b/src/lobby/api.hpp index 4d6b43d4..75e35a0f 100644 --- a/src/lobby/api.hpp +++ b/src/lobby/api.hpp @@ -23,6 +23,7 @@ #endif #include +#include #include #include @@ -31,352 +32,64 @@ #include "lobby/types.hpp" namespace constants { - const std::string json_content_type = "application/json"; + const constexpr auto json_content_type = "application/json"; } -namespace { //NOLINT(cert-dcl59-cpp, google-build-namespaces) - - - inline helper::expected is_json_response(const httplib::Result& result) { - if (not result->has_header("Content-Type")) { - return helper::unexpected{ "Content-Type not set!" }; - } - - if (const auto value = result->get_header_value("Content-Type"); value != constants::json_content_type) { - return helper::unexpected{ fmt::format("Content-Type is not json but {}", value) }; - } - - return result->body; - } - - - inline helper::expected is_error_message_response(const httplib::Result& result - ) { - - const auto body = is_json_response(result); - if (not body.has_value()) { - return helper::unexpected{ body.error() }; - } - - const auto parsed = json::try_parse_json(body.value()); - - if (parsed.has_value()) { - return parsed.value(); - } - - return helper::unexpected{ fmt::format("Couldn't parse json with error: {}", parsed.error()) }; - } - - inline helper::expected is_request_ok(const httplib::Result& result, int ok_code = 200) { - - if (not result) { - return helper::unexpected{ - fmt::format("Request failed with: {}", httplib::to_string(result.error())) - }; - } - - if (result->status == 401) { - - const auto error_type = is_error_message_response(result); - - if (error_type.has_value()) { - return helper::unexpected{ fmt::format("Unauthorized: {}", error_type.value().message) }; - } - - return helper::unexpected{ "Unauthorized" }; - } - - - if (result->status != ok_code) { - - const auto error_type = is_error_message_response(result); - - if (error_type.has_value()) { - return helper::unexpected{ fmt::format( - "Got error response with status code {}: '{}' and message: {}", result->status, - httplib::status_message(result->status), error_type.value().message - ) }; - } - - - return helper::unexpected{ fmt::format( - "Got error response with status code {}: '{}' but expected {}", result->status, - httplib::status_message(result->status), ok_code - ) }; - } - - return {}; - }; - - - template - helper::expected get_json_from_request(const httplib::Result& result, int ok_code = 200) { - - const auto temp = is_request_ok(result, ok_code); - if (not temp.has_value()) { - return helper::unexpected{ temp.error() }; - } - - const auto body = is_json_response(result); - if (not body.has_value()) { - return helper::unexpected{ body.error() }; - } - - const auto parsed = json::try_parse_json(body.value()); - - if (parsed.has_value()) { - return parsed.value(); - } - - return helper::unexpected{ fmt::format("Couldn't parse json with error: {}", parsed.error()) }; - } - - -} // namespace - - namespace lobby { struct Client { private: httplib::Client m_client; - std::string authentication_token{}; + std::optional m_authentication_token; // lobby commit used: https://github.com/OpenBrickProtocolFoundation/lobby/commit/2e0c8d05592f4e4d08437e6cb754a30f02c4e97c static constexpr StaticString supported_version{ "0.1.0" }; - helper::expected check_compatibility() { - const auto server_version = get_version(); - - if (not server_version.has_value()) { - return helper::unexpected{ fmt::format( - "Connecting to unsupported server, he can't report his version\nGot error: {}", - server_version.error() - ) }; - } + helper::expected check_compatibility(); - const auto& version = server_version.value(); + helper::expected check_reachability(); - //TODO(Totto): if version is semver, support semver comparison - if (Client::supported_version.string() != version.version) { - return helper::unexpected{ fmt::format( - "Connecting to unsupported server, version is {}, but we support only {}", - Client::supported_version.string(), version.version - ) }; - } + explicit Client(const std::string& api_url); - return {}; - } + helper::expected get_version(); - helper::expected check_reachability() { - - auto result = m_client.Get("/"); - - if (not result) { - return helper::unexpected{ - fmt::format("Server not reachable: {}", httplib::to_string(result.error())) - }; - } - - return {}; - } - - explicit Client(const std::string& api_url) : m_client{ api_url } { - - // clang-format off - m_client.set_default_headers({ -#if defined(CPPHTTPLIB_ZLIB_SUPPORT) || defined(CPPHTTPLIB_BROTLI_SUPPORT) - { "Accept-Encoding", - -#if defined(CPPHTTPLIB_ZLIB_SUPPORT) - "gzip, deflate" -#endif -#if defined(CPPHTTPLIB_ZLIB_SUPPORT) && defined(CPPHTTPLIB_BROTLI_SUPPORT) - ", " -#endif -#if defined(CPPHTTPLIB_BROTLI_SUPPORT) - "br" -#endif - }, -#endif - // clang-format on - { "Accept", constants::json_content_type } }); - -#if defined(CPPHTTPLIB_ZLIB_SUPPORT) || defined(CPPHTTPLIB_BROTLI_SUPPORT) - m_client.set_compress(true); - m_client.set_decompress(true); -#endif - } - - helper::expected get_version() { - auto res = m_client.Get("/version"); - - return get_json_from_request(res); - } - - public: - Client(Client&& other) noexcept - : m_client{ std::move(other.m_client) }, - authentication_token{ std::move(other.authentication_token) } { } - - helper::expected static get_client(const std::string& url) { - - Client client{ url }; - - const auto reachable = client.check_reachability(); - - if (not reachable.has_value()) { - return helper::unexpected{ reachable.error() }; - } - - //TODO(Totto): once version is standard, check here if the version is supported - - return client; - } - - private: - helper::expected login(const Credentials& credentials) { - const auto json_result = json::try_json_to_string(credentials); - if (not json_result.has_value()) { - return helper::unexpected{ json_result.error() }; - } - - auto res = m_client.Post("/login", json_result.value(), constants::json_content_type); - - return get_json_from_request(res); - } + helper::expected login(const lobby::Credentials& credentials); public: - bool is_authenticated() { - return not authentication_token.empty(); - } - - bool authenticate(const Credentials& credentials) { - - const auto result = login(credentials); - - if (not result.has_value()) { - spdlog::error("Failed authenticating user {}: {}", credentials.username, result.error()); - authentication_token = ""; - return false; - } - - authentication_token = result.value().jwt; - - m_client.set_bearer_token_auth(authentication_token); - - return true; - } - - helper::expected, std::string> get_lobbies() { - auto res = m_client.Get("/lobbies"); - - return get_json_from_request>(res); - } - - - helper::expected join_lobby(int lobby_id) { - if (not is_authenticated()) { - return helper::unexpected{ - "Authentication needed for this " - "endpoint, but not authenticated!" - }; - } - - auto res = m_client.Post(fmt::format("/lobbies/{}", lobby_id)); - - return is_request_ok(res, 204); - } - - helper::expected get_lobby_detail(int lobby_id) { - if (not is_authenticated()) { - return helper::unexpected{ - "Authentication needed for this " - "endpoint, but not authenticated!" - }; - } - - auto res = m_client.Get(fmt::format("/lobbies/{}", lobby_id)); - - return get_json_from_request(res); - } - - helper::expected delete_lobby(int lobby_id) { - if (not is_authenticated()) { - return helper::unexpected{ - "Authentication needed for this " - "endpoint, but not authenticated!" - }; - } - - auto res = m_client.Delete(fmt::format("/lobbies/{}", lobby_id)); - - return is_request_ok(res, 204); - } - - helper::expected leave_lobby(int lobby_id) { - if (not is_authenticated()) { - return helper::unexpected{ - "Authentication needed for this " - "endpoint, but not authenticated!" - }; - } + Client(Client&& other) noexcept; + Client& operator=(Client&& other) noexcept = delete; - auto res = m_client.Put(fmt::format("/lobbies/{}/leave", lobby_id)); + Client(const Client& other) = delete; + Client& operator=(const Client& other) = delete; - return is_request_ok(res, 204); - } + ~Client(); - helper::expected start_lobby(int lobby_id) { - if (not is_authenticated()) { - return helper::unexpected{ - "Authentication needed for this " - "endpoint, but not authenticated!" - }; - } + helper::expected static get_client(const std::string& url); - auto res = m_client.Post(fmt::format("/lobbies/{}/start", lobby_id)); - return is_request_ok(res, 204); - } + bool is_authenticated(); - helper::expected create_lobby(const CreateLobbyRequest& arguments) { - if (not is_authenticated()) { - return helper::unexpected{ - "Authentication needed for this " - "endpoint, but not authenticated!" - }; - } + bool authenticate(const Credentials& credentials); - const auto json_result = json::try_json_to_string(arguments); - if (not json_result.has_value()) { - return helper::unexpected{ json_result.error() }; - } + helper::expected, std::string> get_lobbies(); - auto res = m_client.Post("/lobbies", json_result.value(), constants::json_content_type); + helper::expected join_lobby(int lobby_id); - return get_json_from_request(res, 201); - } + helper::expected get_lobby_detail(int lobby_id); - helper::expected, std::string> get_users() { + helper::expected delete_lobby(int lobby_id); - auto res = m_client.Get("/users"); + helper::expected leave_lobby(int lobby_id); - return get_json_from_request>(res); - } + helper::expected start_lobby(int lobby_id); - helper::expected register_user(const RegisterRequest& register_request) { - const auto json_result = json::try_json_to_string(register_request); - if (not json_result.has_value()) { - return helper::unexpected{ json_result.error() }; - } + helper::expected create_lobby(const CreateLobbyRequest& arguments); - auto res = m_client.Post("/register", json_result.value(), constants::json_content_type); + helper::expected, std::string> get_users(); - return is_request_ok(res, 204); - } + helper::expected register_user(const RegisterRequest& register_request); }; diff --git a/src/lobby/meson.build b/src/lobby/meson.build index 315429a6..6bf0b698 100644 --- a/src/lobby/meson.build +++ b/src/lobby/meson.build @@ -1 +1 @@ -graphics_src_files += files('api.hpp', 'types.hpp') +graphics_src_files += files('api.cpp', 'api.hpp', 'types.hpp') From b50d5ae4394add127bf37922158cabceb82abd60 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 17:32:56 +0200 Subject: [PATCH 69/77] fix (hopefully) all clang-tidy errors --- .github/workflows/cpp-linter.yml | 2 +- src/manager/music_manager.cpp | 18 +++++++++--------- src/manager/music_manager.hpp | 12 ++++++------ .../recording_selector/recording_selector.hpp | 2 +- src/scenes/replay_game/replay_game.hpp | 2 +- .../single_player_game/single_player_game.hpp | 2 +- src/ui/layouts/focus_layout.hpp | 6 ++++-- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index f576c835..23701e16 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -48,7 +48,7 @@ jobs: tidy-checks: "" step-summary: true file-annotations: true - ignore: subprojects|build|android|assets|recordings|docs|toolchains|platforms|src/thirdparty + ignore: subprojects|build|android|assets|recordings|docs|toolchains|platforms|src/libs/core/hash-library|wrapper/javascript/ - name: Fail CI run if linter checks failed if: steps.linter.outputs.checks-failed != 0 diff --git a/src/manager/music_manager.cpp b/src/manager/music_manager.cpp index 057f3163..1b3b036d 100644 --- a/src/manager/music_manager.cpp +++ b/src/manager/music_manager.cpp @@ -20,7 +20,7 @@ MusicManager::MusicManager(ServiceProvider* service_provider, u8 channel_size) m_channel_size{ channel_size }, m_chunk_map{ std::unordered_map{} }, m_service_provider{ service_provider }, - volume{ m_service_provider->command_line_arguments().silent ? std::nullopt : std::optional{ 1.0F } } { + m_volume{ m_service_provider->command_line_arguments().silent ? std::nullopt : std::optional{ 1.0F } } { if (s_instance != nullptr) { spdlog::error("it's not allowed to create more than one MusicManager instance"); return; @@ -57,7 +57,7 @@ MusicManager::MusicManager(ServiceProvider* service_provider, u8 channel_size) s_instance = this; - set_volume(volume, true); + set_volume(m_volume, true); } MusicManager::~MusicManager() noexcept { @@ -95,7 +95,7 @@ std::optional MusicManager::load_and_play_music(const std::filesyst } // if we are mute, set the current music to this - if (not volume.has_value()) { + if (not m_volume.has_value()) { assert(m_queued_music == nullptr && "No queued music is possible, when muted!"); if (m_music != nullptr) { Mix_FreeMusic(m_music); @@ -258,7 +258,7 @@ void MusicManager::set_volume( const bool notify_listeners ) { - if (volume == new_volume and not force_update) { + if (m_volume == new_volume and not force_update) { return; } @@ -268,7 +268,7 @@ void MusicManager::set_volume( Mix_HaltMusic(); } - volume = std::nullopt; + m_volume = std::nullopt; } @@ -276,7 +276,7 @@ void MusicManager::set_volume( not new_volume.has_value() ? 0 : static_cast(MIX_MAX_VOLUME * new_volume.value()); Mix_VolumeMusic(new_volume_mapped); - if (not volume.has_value()) { + if (not m_volume.has_value()) { if (m_music != nullptr) { const int result = Mix_PlayMusic(m_music, -1); @@ -289,10 +289,10 @@ void MusicManager::set_volume( } - volume = new_volume; + m_volume = new_volume; if (notify_listeners) { - for (const auto& [_, listener] : volume_listeners) { - listener(volume); + for (const auto& [_, listener] : m_volume_listeners) { + listener(m_volume); } } } diff --git a/src/manager/music_manager.hpp b/src/manager/music_manager.hpp index b2939c9e..8c85eac8 100644 --- a/src/manager/music_manager.hpp +++ b/src/manager/music_manager.hpp @@ -31,8 +31,8 @@ struct MusicManager final { static constexpr unsigned fade_ms = 500; usize m_delay = MusicManager::fade_ms; ServiceProvider* m_service_provider; - std::optional volume; - std::unordered_map volume_listeners; + std::optional m_volume; + std::unordered_map m_volume_listeners; public: explicit MusicManager(ServiceProvider* service_provider, u8 channel_size = 2); @@ -58,20 +58,20 @@ struct MusicManager final { bool add_volume_listener(const std::string& name, VolumeChangeFunction change_function) { - if (volume_listeners.contains(name)) { + if (m_volume_listeners.contains(name)) { return false; } - volume_listeners.insert_or_assign(name, std::move(change_function)); + m_volume_listeners.insert_or_assign(name, std::move(change_function)); return true; } bool remove_volume_listener(const std::string& name) { - if (not volume_listeners.contains(name)) { + if (not m_volume_listeners.contains(name)) { return false; } - volume_listeners.erase(name); + m_volume_listeners.erase(name); return true; } diff --git a/src/scenes/recording_selector/recording_selector.hpp b/src/scenes/recording_selector/recording_selector.hpp index 51bc8484..4f0861a1 100644 --- a/src/scenes/recording_selector/recording_selector.hpp +++ b/src/scenes/recording_selector/recording_selector.hpp @@ -34,7 +34,7 @@ namespace scenes { private: ui::TileLayout m_main_layout; std::optional m_next_command{ std::nullopt }; - std::vector m_chosen_paths{}; + std::vector m_chosen_paths; public: explicit RecordingSelector(ServiceProvider* service_provider, const ui::Layout& layout); diff --git a/src/scenes/replay_game/replay_game.hpp b/src/scenes/replay_game/replay_game.hpp index cd671b39..1cc0d44a 100644 --- a/src/scenes/replay_game/replay_game.hpp +++ b/src/scenes/replay_game/replay_game.hpp @@ -10,7 +10,7 @@ namespace scenes { enum class NextScene : u8 { Pause, Settings }; - std::optional m_next_scene{}; + std::optional m_next_scene; std::vector> m_games; public: diff --git a/src/scenes/single_player_game/single_player_game.hpp b/src/scenes/single_player_game/single_player_game.hpp index 39ef31b2..d7389579 100644 --- a/src/scenes/single_player_game/single_player_game.hpp +++ b/src/scenes/single_player_game/single_player_game.hpp @@ -11,7 +11,7 @@ namespace scenes { enum class NextScene : u8 { Pause, Settings }; - std::optional m_next_scene{}; + std::optional m_next_scene; std::unique_ptr m_game; public: diff --git a/src/ui/layouts/focus_layout.hpp b/src/ui/layouts/focus_layout.hpp index 04a18d89..f4eae925 100644 --- a/src/ui/layouts/focus_layout.hpp +++ b/src/ui/layouts/focus_layout.hpp @@ -26,8 +26,10 @@ namespace ui { FocusOptions m_options; protected: - std::optional m_focus_id{}; - std::vector> m_widgets{}; + std::optional + m_focus_id; // NOLINT(misc-non-private-member-variables-in-classes,cppcoreguidelines-non-private-member-variables-in-classes) + std::vector> + m_widgets; // NOLINT(misc-non-private-member-variables-in-classes,cppcoreguidelines-non-private-member-variables-in-classes) public: explicit FocusLayout(const Layout& layout, u32 focus_id, FocusOptions options, bool is_top_level); From 5f19eef1d8bd3af7cc301fa78617daaf0a081e01 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 17:36:37 +0200 Subject: [PATCH 70/77] SDL: move noexcept function to another name instead of main, since that may be replaced by "#define main SDL_main" and doesn't like the noexcept attribute --- src/executables/game/main.cpp | 110 ++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/src/executables/game/main.cpp b/src/executables/game/main.cpp index 7ea3fa28..6d223aca 100644 --- a/src/executables/game/main.cpp +++ b/src/executables/game/main.cpp @@ -60,80 +60,86 @@ namespace { } -} // namespace + int main_no_sdl_replace(int argc, char** argv) noexcept { -int main(int argc, char** argv) noexcept { + std::shared_ptr window{ nullptr }; - std::shared_ptr window{ nullptr }; + try { - try { + initialize_spdlog(); - initialize_spdlog(); + std::vector arguments_vector{}; + arguments_vector.reserve(argc); + for (auto i = 0; i < argc; ++i) { + arguments_vector.emplace_back(argv[i]); //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + } - std::vector arguments_vector{}; - arguments_vector.reserve(argc); - for (auto i = 0; i < argc; ++i) { - arguments_vector.emplace_back(argv[i]); //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - } + if (arguments_vector.empty()) { + arguments_vector.emplace_back("oopetris"); + } - if (arguments_vector.empty()) { - arguments_vector.emplace_back("oopetris"); - } + auto parsed_arguments = helper::parse_args(arguments_vector); - auto parsed_arguments = helper::parse_args(arguments_vector); + if (not parsed_arguments.has_value()) { - if (not parsed_arguments.has_value()) { + spdlog::error("error parsing command line arguments: {}", parsed_arguments.error()); + return EXIT_FAILURE; + } - spdlog::error("error parsing command line arguments: {}", parsed_arguments.error()); - return EXIT_FAILURE; - } + auto arguments = std::move(parsed_arguments.value()); - auto arguments = std::move(parsed_arguments.value()); + [[maybe_unused]] constexpr auto window_name = constants::program_name.c_str(); - [[maybe_unused]] constexpr auto window_name = constants::program_name.c_str(); - - try { + try { #if defined(__ANDROID__) or defined(__CONSOLE__) - window = std::make_shared(window_name, WindowPosition::Centered); + window = std::make_shared(window_name, WindowPosition::Centered); #else - [[maybe_unused]] static constexpr int width = 1280; - [[maybe_unused]] static constexpr int height = 720; - window = std::make_shared(window_name, WindowPosition::Centered, width, height); + [[maybe_unused]] static constexpr int width = 1280; + [[maybe_unused]] static constexpr int height = 720; + window = std::make_shared(window_name, WindowPosition::Centered, width, height); #endif - } catch (const helper::GeneralError& general_error) { - spdlog::error("Couldn't initialize window: {}", general_error.message()); - } + } catch (const helper::GeneralError& general_error) { + spdlog::error("Couldn't initialize window: {}", general_error.message()); + } - if (window == nullptr) { - helper::MessageBox::show_simple( - helper::MessageBox::Type::Error, "Initialization Error", "failed to create SDL window", nullptr - ); - return EXIT_FAILURE; - } + if (window == nullptr) { + helper::MessageBox::show_simple( + helper::MessageBox::Type::Error, "Initialization Error", "failed to create SDL window", nullptr + ); + return EXIT_FAILURE; + } - Application app{ std::move(window), std::move(arguments) }; + Application app{ std::move(window), std::move(arguments) }; - app.run(); - return EXIT_SUCCESS; + app.run(); + return EXIT_SUCCESS; - } catch (const helper::GeneralError& general_error) { - spdlog::error("{}", general_error.message()); + } catch (const helper::GeneralError& general_error) { + spdlog::error("{}", general_error.message()); - if (window == nullptr) { - helper::MessageBox::show_simple( - helper::MessageBox::Type::Error, "Initialization Error", general_error.message(), nullptr - ); - } else { - window->show_simple(helper::MessageBox::Type::Error, "Initialization Error", general_error.message()); - } + if (window == nullptr) { + helper::MessageBox::show_simple( + helper::MessageBox::Type::Error, "Initialization Error", general_error.message(), nullptr + ); + } else { + window->show_simple(helper::MessageBox::Type::Error, "Initialization Error", general_error.message()); + } - return EXIT_FAILURE; - } catch (const std::exception& error) { - // this is the last resort, so using std::cerr and no sdl show_simple messagebox! - std::cerr << error.what(); - return EXIT_FAILURE; + return EXIT_FAILURE; + } catch (const std::exception& error) { + // this is the last resort, so using std::cerr and no sdl show_simple messagebox! + std::cerr << error.what(); + return EXIT_FAILURE; + } } + + +} // namespace + + +int main(int argc, char** argv) { + return main_no_sdl_replace(argc, argv); } From a1628888ee216dbdb711ed54ca807023340a043c Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 18:01:34 +0200 Subject: [PATCH 71/77] fix small bug in refactoring, that only shows in release mode --- src/manager/music_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manager/music_manager.cpp b/src/manager/music_manager.cpp index 1b3b036d..cd27d4c6 100644 --- a/src/manager/music_manager.cpp +++ b/src/manager/music_manager.cpp @@ -248,7 +248,7 @@ void MusicManager::hook_music_finished() { return static_cast(result) / MIX_MAX_VOLUME; #else - return volume; + return m_volume; #endif } From 3dfdd87b63a3cb6fb4b3d083aaccaa15c7e0cf67 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 18:15:59 +0200 Subject: [PATCH 72/77] android: add option to build an universalApk --- platforms/android/app/build.gradle | 40 ++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/platforms/android/app/build.gradle b/platforms/android/app/build.gradle index 9f8c3279..f7b96c63 100644 --- a/platforms/android/app/build.gradle +++ b/platforms/android/app/build.gradle @@ -72,6 +72,13 @@ static boolean isValidVersion(String version) { return true; } +/** + * Internal helper function + */ +static List getSupportedABIs() { + return ["armeabi-v7a", "arm64-v8a", "x86", "x86_64"]; +} + /** * Read the Android ABI from user input. * supported ANDROID_ABIs are 'arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64' @@ -80,7 +87,7 @@ static boolean isValidVersion(String version) { List getAndroidABIs() { String property = project.findProperty('ANDROID_ABI') - List supportedABIs = ["armeabi-v7a", "arm64-v8a", "x86", "x86_64"]; + List supportedABIs = getSupportedABIs() List AbiFilters = new ArrayList() if (property == null) { @@ -193,8 +200,37 @@ String getVersion() { } +/** + * Detect if we need to build an universal apk + * this first checks, if this is manually request by the cli args, than it checks, if all supported ABIs are given, if that is the case, enable it too + * @return Boolean + */ +Boolean shouldBuildUniversalApk(List abisToUse) { + String property = project.findProperty('BUILD_UNIVERSAL_APK') + + + if (property != null) { + return true + } + + List supportedABIs = getSupportedABIs() + + // return true, if all abis, we support are specified + for (abi in supportedABIs) { + if (!abisToUse.contains(abi)) { + return false; + } + } + + return true; + + +} + + List abisToUse = getAndroidABIs() String versionString = getVersion() +Boolean buildUniversalApk = shouldBuildUniversalApk(abisToUse) System.out.printf("DEBUG: Using abis: %s%n", abisToUse.join(", ")) System.out.printf("DEBUG: Using version: %s%n", versionString) @@ -271,7 +307,7 @@ android { // Specifies a list of ABIs for Gradle to create APKs for. include(*abisToUse) // Specifies that you don't want to also generate a universal APK that includes all ABIs. - universalApk false + universalApk(buildUniversalApk) } } From 2eb5f98f89e04535da3197309ad2054f1d971ad0 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 18:17:44 +0200 Subject: [PATCH 73/77] - android: handle exits correctly, since as stated in SDl2 docs, std::exit() doesn't work, so trowing an exception, catching it in the main a,dn exiting via return there - core/errors.hpp: add virtual override for std::exception what(), so that it gets a correct message, if it's used wrongly --- src/executables/game/application.cpp | 3 ++- src/executables/game/main.cpp | 3 +++ src/helper/graphic_utils.cpp | 23 +++++++++++++++++++++++ src/helper/graphic_utils.hpp | 16 ++++++++++++++++ src/libs/core/helper/errors.cpp | 5 +++++ src/libs/core/helper/errors.hpp | 2 ++ 6 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/executables/game/application.cpp b/src/executables/game/application.cpp index 707c2ca2..933e4743 100644 --- a/src/executables/game/application.cpp +++ b/src/executables/game/application.cpp @@ -361,7 +361,8 @@ void Application::initialize() { spdlog::debug("Aborted loading after {}", duration); // just exit immediately, without cleaning up, since than we would have to cancel the loading thread somehow, which is way rto complicated, let the OS clean up our mess we create her xD - std::exit(0); + + utils::exit(0); } diff --git a/src/executables/game/main.cpp b/src/executables/game/main.cpp index 6d223aca..a58daae8 100644 --- a/src/executables/game/main.cpp +++ b/src/executables/game/main.cpp @@ -129,6 +129,9 @@ namespace { return EXIT_FAILURE; + } catch (const utils::ExitException& exit_exception) { + spdlog::debug("Requested exit with status code {}", exit_exception.status_code()); + return exit_exception.status_code(); } catch (const std::exception& error) { // this is the last resort, so using std::cerr and no sdl show_simple messagebox! std::cerr << error.what(); diff --git a/src/helper/graphic_utils.cpp b/src/helper/graphic_utils.cpp index 1167eaf5..080969c2 100644 --- a/src/helper/graphic_utils.cpp +++ b/src/helper/graphic_utils.cpp @@ -1,5 +1,6 @@ #include "graphic_utils.hpp" +#include SDL_Color utils::sdl_color_from_color(const Color& color) { return SDL_Color{ color.r, color.g, color.b, color.a }; @@ -94,3 +95,25 @@ std::optional utils::log_error(const std::string& error) { spdlog::error(error); return std::nullopt; } + +utils::ExitException::ExitException(int status_code) noexcept : m_status_code{ status_code } { } + +[[nodiscard]] int utils::ExitException::status_code() const { + return m_status_code; +} + +[[nodiscard]] const char* utils::ExitException::what() const noexcept { + return "An exit exception occurred"; +} + +void utils::exit(int status_code) { +#if defined(__ANDROID__) + // calling exit() in android doesn't do the correct job, it completely avoids resource cleanup by the underlying SDLActivity.java + // (java wrapper), that calls the main and expects it to return ALWAYS and throwing an exception in a catch statement is bad, + // but is required here + // see: https://github.com/libsdl-org/SDL/blob/main/docs/README-android.md + throw utils::ExitException{ status_code }; +#else + std::exit(status_code); +#endif +} diff --git a/src/helper/graphic_utils.hpp b/src/helper/graphic_utils.hpp index be6b3eee..4550ce0a 100644 --- a/src/helper/graphic_utils.hpp +++ b/src/helper/graphic_utils.hpp @@ -20,4 +20,20 @@ namespace utils { [[nodiscard]] std::filesystem::path get_root_folder(); std::optional log_error(const std::string& error); + + struct ExitException : std::exception { + private: + int m_status_code; + + public: + explicit ExitException(int status_code) noexcept; + + [[nodiscard]] int status_code() const; + + [[nodiscard]] const char* what() const noexcept override; + }; + + + [[noreturn]] void exit(int status_code); + } // namespace utils diff --git a/src/libs/core/helper/errors.cpp b/src/libs/core/helper/errors.cpp index 37eb4017..a8377eed 100644 --- a/src/libs/core/helper/errors.cpp +++ b/src/libs/core/helper/errors.cpp @@ -21,6 +21,11 @@ helper::GeneralError::GeneralError(GeneralError&& error) noexcept = default; return m_message; } +[[nodiscard]] const char* helper::GeneralError::what() const noexcept { + return m_message.c_str(); +} + + [[nodiscard]] helper::error::Severity helper::GeneralError::severity() const { return m_severity; } diff --git a/src/libs/core/helper/errors.hpp b/src/libs/core/helper/errors.hpp index f1c6550f..1c66dfad 100644 --- a/src/libs/core/helper/errors.hpp +++ b/src/libs/core/helper/errors.hpp @@ -31,6 +31,8 @@ namespace helper { [[nodiscard]] const std::string& message() const; [[nodiscard]] error::Severity severity() const; + + [[nodiscard]] const char* what() const noexcept override; }; struct FatalError : public GeneralError { From d4b5c6499563f8f92f841d3eb1bfc307799e9fe5 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 19:50:47 +0200 Subject: [PATCH 74/77] joystick, controller, fix mistake, so that controllers were not able to be removed from an internal array due to not using JoystickLikeInput but JoystickInput --- src/input/joystick_input.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/input/joystick_input.cpp b/src/input/joystick_input.cpp index 6c2d4a49..6608fb66 100644 --- a/src/input/joystick_input.cpp +++ b/src/input/joystick_input.cpp @@ -114,9 +114,8 @@ void input::JoyStickInputManager::discover_devices(std::vectorget()->name() + ); + inputs.push_back(std::move(joystick.value())); + } else { spdlog::warn( "Failed to add newly attached {}: {}", @@ -250,7 +255,8 @@ void input::JoyStickInputManager::remove_device( ) { for (auto it = inputs.cbegin(); it != inputs.cend(); it++) { - if (const auto joystick_input = utils::is_child_class(*it); joystick_input.has_value()) { + if (const auto joystick_input = utils::is_child_class(*it); + joystick_input.has_value()) { if (joystick_input.value()->instance_id() == instance_id) { //TODO(Totto): if we use this joystick as game input we have to notify the user about it,and pause the game, until he is inserted again @@ -261,8 +267,9 @@ void input::JoyStickInputManager::remove_device( } } - spdlog::warn(fmt::format( - "Failed to remove removed {} from internal input vector (maybe he was not recognized in the first place)", + //this happens way to often, since Sdl outputs both SDL_JOYDEVICEREMOVED and SDL_CONTROLLERDEVICEREMOVED at the same time, in case of a controller, so the second time, this is reached :( + spdlog::debug(fmt::format( + "Failed to remove removed {} from internal input vector", type == input::JoystickLikeType::Joystick ? "joystick" : "controller" )); } From c7d9937b78b6cf5b01eb1a5b6f09f16432c888f1 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 20:57:35 +0200 Subject: [PATCH 75/77] android: fix a bug in music handling, - remove service_provider member from MusicManager, it is not needed - android handle a few special events --- src/executables/game/application.cpp | 21 +++++++++--- src/input/input.cpp | 31 ++++++++++++++++++ src/manager/music_manager.cpp | 49 ++++++++++++++++++++-------- src/manager/music_manager.hpp | 5 ++- 4 files changed, 88 insertions(+), 18 deletions(-) diff --git a/src/executables/game/application.cpp b/src/executables/game/application.cpp index 933e4743..d0fee17d 100644 --- a/src/executables/game/application.cpp +++ b/src/executables/game/application.cpp @@ -119,6 +119,11 @@ void Application::handle_event(const SDL_Event& event) { m_is_running = false; } + // special event for android and IOS + if (event.type == SDL_APP_TERMINATING) { + m_is_running = false; + } + auto handled = false; for (const auto& scene : std::ranges::views::reverse(m_scene_stack)) { @@ -301,7 +306,6 @@ void Application::initialize() { : 0s; auto start_execution_time = std::chrono::steady_clock::now(); - bool finished_loading = false; // this is a duplicate of below in some cases, but it's just for the loading screen and can't be factored out easily @@ -324,6 +328,15 @@ void Application::initialize() { if (event.type == SDL_QUIT) { m_is_running = false; } + + // special event for android and IOS + if (event.type == SDL_APP_TERMINATING) { + m_is_running = false; + } + } + + if (not m_is_running) { + break; } loading_screen.update(); @@ -355,12 +368,12 @@ void Application::initialize() { const auto duration = std::chrono::milliseconds(SDL_GetTicks64() - start_time); - // we can reach this via SDL_QUIT or (not console::inMainLoop()) - if (not finished_loading) { + // we can reach this via SDL_QUIT, SDL_APP_TERMINATING or (not console::inMainLoop()) + if (not finished_loading or not m_is_running) { spdlog::debug("Aborted loading after {}", duration); - // just exit immediately, without cleaning up, since than we would have to cancel the loading thread somehow, which is way rto complicated, let the OS clean up our mess we create her xD + // just exit immediately, without cleaning up, since than we would have to cancel the loading thread somehow, which is way to complicated, let the OS clean up our mess we created here xD utils::exit(0); } diff --git a/src/input/input.cpp b/src/input/input.cpp index 008673cd..fa40c5ec 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -151,7 +151,38 @@ input::InputManager::InputManager(const std::shared_ptr& window) { break; } break; + //TODO(Totto): handle those types correctly, to e.g. pause the game automatically on background enter + case SDL_APP_TERMINATING: + /* Terminate the app. + Shut everything down before returning from this function. + */ + return true; + case SDL_APP_LOWMEMORY: + /* You will get this when your app is paused and iOS wants more memory. + Release as much memory as possible. + */ + return true; + case SDL_APP_WILLENTERBACKGROUND: + /* Prepare your app to go into the background. Stop loops, etc. + This gets called when the user hits the home button, or gets a call. + */ + return true; + case SDL_APP_DIDENTERBACKGROUND: + /* This will get called if the user accepted whatever sent your app to the background. + If the user got a phone call and canceled it, you'll instead get an SDL_APP_DID_ENTER_FOREGROUND event and restart your loops. + When you get this, you have 5 seconds to save all your state or the app will be terminated. + Your app is NOT active at this point. + */ + return true; + case SDL_APP_WILLENTERFOREGROUND: + /* This call happens when your app is coming back to the foreground. + Restore all your state here. + */ + return true; + case SDL_APP_DIDENTERFOREGROUND: + default: + break; } diff --git a/src/manager/music_manager.cpp b/src/manager/music_manager.cpp index cd27d4c6..50ece3cc 100644 --- a/src/manager/music_manager.cpp +++ b/src/manager/music_manager.cpp @@ -19,10 +19,12 @@ MusicManager::MusicManager(ServiceProvider* service_provider, u8 channel_size) m_queued_music{ nullptr }, m_channel_size{ channel_size }, m_chunk_map{ std::unordered_map{} }, - m_service_provider{ service_provider }, - m_volume{ m_service_provider->command_line_arguments().silent ? std::nullopt : std::optional{ 1.0F } } { + m_volume{ service_provider->command_line_arguments().silent ? std::nullopt : std::optional{ 1.0F } } { if (s_instance != nullptr) { - spdlog::error("it's not allowed to create more than one MusicManager instance"); + spdlog::error( + "it's not allowed to create more than one MusicManager instance: {} != {}", + static_cast(s_instance), static_cast(this) + ); return; } @@ -37,13 +39,21 @@ MusicManager::MusicManager(ServiceProvider* service_provider, u8 channel_size) throw helper::InitializationError{ fmt::format("Failed to initialize any audio codec: {}", SDL_GetError()) }; } - // see: https://wiki.libsdl.org/SDL2_mixer/Mix_AllocateChannels - auto allocated_channels = Mix_AllocateChannels(channel_size); - if (allocated_channels != channel_size) { - throw helper::InitializationError{ fmt::format( - "Failed to initialize the requested channels, requested {} but only got {}: {}", channel_size, - allocated_channels, SDL_GetError() - ) }; + // retrieve allocated channels + auto allocated_channels = Mix_AllocateChannels(-1); + + spdlog::debug("SDL_MIX: allocated_channels = {}", allocated_channels); + + if (allocated_channels == 0) { + + // see: https://wiki.libsdl.org/SDL2_mixer/Mix_AllocateChannels + auto newly_allocated_channels = Mix_AllocateChannels(channel_size); + if (newly_allocated_channels != channel_size) { + throw helper::InitializationError{ fmt::format( + "Failed to initialize the requested channels, requested {} but only got {}: {}", channel_size, + newly_allocated_channels, SDL_GetError() + ) }; + } } // 2 here means STEREO, note that channels above means tracks, e.g. simultaneous playing source that are mixed, @@ -66,7 +76,10 @@ MusicManager::~MusicManager() noexcept { } // stop sounds and free loaded data - Mix_HaltChannel(-1); + int result = Mix_HaltChannel(-1); + if (result != 0) { + spdlog::warn("Mix_HaltChannel failed with error: {}", SDL_GetError()); + } if (m_music != nullptr) { Mix_FreeMusic(m_music); @@ -79,8 +92,11 @@ MusicManager::~MusicManager() noexcept { for (const auto& [_, value] : m_chunk_map) { Mix_FreeChunk(value); } + Mix_CloseAudio(); Mix_Quit(); + + s_instance = nullptr; } std::optional MusicManager::load_and_play_music(const std::filesystem::path& location, const usize delay) { @@ -141,7 +157,11 @@ std::optional MusicManager::load_and_play_music(const std::filesyst m_queued_music = music; m_delay = delay; Mix_HookMusicFinished([]() { - assert(s_instance != nullptr and "there must be a MusicManager instance"); + // this can happen on e.g. android, where if we exit the application, we don't close the window, so its reused, but the music manager is destroyed, but the hook is called later xD + /* if (s_instance == nullptr) { + return; + } */ + s_instance->hook_music_finished(); }); @@ -232,7 +252,10 @@ void MusicManager::hook_music_finished() { [[nodiscard]] bool MusicManager::validate_instance() { if (s_instance != this) { - spdlog::error("this MusicManager instance is not the instance that is used globally"); + spdlog::error( + "this MusicManager instance is not the instance that is used globally: {} != {}", + static_cast(s_instance), static_cast(this) + ); return false; } return true; diff --git a/src/manager/music_manager.hpp b/src/manager/music_manager.hpp index 8c85eac8..54128369 100644 --- a/src/manager/music_manager.hpp +++ b/src/manager/music_manager.hpp @@ -30,16 +30,19 @@ struct MusicManager final { std::unordered_map m_chunk_map; static constexpr unsigned fade_ms = 500; usize m_delay = MusicManager::fade_ms; - ServiceProvider* m_service_provider; + std::optional m_volume; std::unordered_map m_volume_listeners; public: explicit MusicManager(ServiceProvider* service_provider, u8 channel_size = 2); + MusicManager(const MusicManager&) = delete; MusicManager& operator=(const MusicManager&) = delete; + MusicManager(const MusicManager&&) = delete; MusicManager& operator=(MusicManager&&) = delete; + ~MusicManager() noexcept; std::optional From cc1fe4ddb304ed5109be18546935f7f2dd816657 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 21:00:09 +0200 Subject: [PATCH 76/77] clang-tidy: fix all errors --- .github/workflows/cpp-linter.yml | 2 +- src/scenes/online_lobby/online_lobby.cpp | 2 +- src/scenes/online_lobby/online_lobby.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index 23701e16..a26fdee5 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -48,7 +48,7 @@ jobs: tidy-checks: "" step-summary: true file-annotations: true - ignore: subprojects|build|android|assets|recordings|docs|toolchains|platforms|src/libs/core/hash-library|wrapper/javascript/ + ignore: subprojects|build|android|assets|recordings|docs|toolchains|platforms|wrapper|src/libs/core/hash-library - name: Fail CI run if linter checks failed if: steps.linter.outputs.checks-failed != 0 diff --git a/src/scenes/online_lobby/online_lobby.cpp b/src/scenes/online_lobby/online_lobby.cpp index f11ade0d..9f2156a8 100644 --- a/src/scenes/online_lobby/online_lobby.cpp +++ b/src/scenes/online_lobby/online_lobby.cpp @@ -31,7 +31,7 @@ namespace scenes { //TODO(Totto): after the settings have been reworked, make this url changeable! auto maybe_client = lobby::Client::get_client("http://127.0.0.1:5000"); if (maybe_client.has_value()) { - client = std::make_unique(std::move(maybe_client.value())); + m_client = std::make_unique(std::move(maybe_client.value())); } else { spdlog::error("Error in connecting to lobby client: {}", maybe_client.error()); } diff --git a/src/scenes/online_lobby/online_lobby.hpp b/src/scenes/online_lobby/online_lobby.hpp index 4503db98..78872e93 100644 --- a/src/scenes/online_lobby/online_lobby.hpp +++ b/src/scenes/online_lobby/online_lobby.hpp @@ -17,7 +17,7 @@ namespace scenes { ui::TileLayout m_main_layout; std::optional m_next_command; - std::unique_ptr client{ nullptr }; + std::unique_ptr m_client{ nullptr }; public: explicit OnlineLobby(ServiceProvider* service_provider, const ui::Layout& layout); From ba7b483c0add286d8a8e87db4c9fdee6adc62fc8 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 27 May 2024 21:46:46 +0200 Subject: [PATCH 77/77] clang-tidy: fix all errors --- src/input/input.cpp | 9 ++------- src/manager/music_manager.cpp | 7 ++++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/input/input.cpp b/src/input/input.cpp index fa40c5ec..90b34c49 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -156,33 +156,28 @@ input::InputManager::InputManager(const std::shared_ptr& window) { /* Terminate the app. Shut everything down before returning from this function. */ - return true; case SDL_APP_LOWMEMORY: /* You will get this when your app is paused and iOS wants more memory. Release as much memory as possible. */ - return true; + case SDL_APP_WILLENTERBACKGROUND: /* Prepare your app to go into the background. Stop loops, etc. This gets called when the user hits the home button, or gets a call. */ - return true; case SDL_APP_DIDENTERBACKGROUND: /* This will get called if the user accepted whatever sent your app to the background. If the user got a phone call and canceled it, you'll instead get an SDL_APP_DID_ENTER_FOREGROUND event and restart your loops. When you get this, you have 5 seconds to save all your state or the app will be terminated. Your app is NOT active at this point. */ - return true; case SDL_APP_WILLENTERFOREGROUND: /* This call happens when your app is coming back to the foreground. Restore all your state here. */ - return true; case SDL_APP_DIDENTERFOREGROUND: - + return true; default: - break; } diff --git a/src/manager/music_manager.cpp b/src/manager/music_manager.cpp index 50ece3cc..ecd4201e 100644 --- a/src/manager/music_manager.cpp +++ b/src/manager/music_manager.cpp @@ -40,7 +40,7 @@ MusicManager::MusicManager(ServiceProvider* service_provider, u8 channel_size) } // retrieve allocated channels - auto allocated_channels = Mix_AllocateChannels(-1); + const auto allocated_channels = Mix_AllocateChannels(-1); spdlog::debug("SDL_MIX: allocated_channels = {}", allocated_channels); @@ -76,7 +76,8 @@ MusicManager::~MusicManager() noexcept { } // stop sounds and free loaded data - int result = Mix_HaltChannel(-1); + const int result = Mix_HaltChannel(-1); + if (result != 0) { spdlog::warn("Mix_HaltChannel failed with error: {}", SDL_GetError()); } @@ -264,7 +265,7 @@ void MusicManager::hook_music_finished() { [[nodiscard]] std::optional MusicManager::get_volume() const { #if !defined(NDEBUG) - int result = Mix_VolumeMusic(-1); + const int result = Mix_VolumeMusic(-1); if (result == 0) { return std::nullopt; }