diff --git a/src/game/game.cpp b/src/game/game.cpp index 282c3d81..c44ee8bd 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -35,7 +35,8 @@ Game::Game( tetrion_index](InputEvent event, SimulationStep simulation_step_index) { spdlog::debug("event: {} (step {})", magic_enum::enum_name(event), simulation_step_index); - recording_writer->add_event(tetrion_index, simulation_step_index, event); + //TODO(Totto): Remove all occurrences of std::ignore, where we shouldn't ignore this return value + std::ignore = recording_writer->add_record(tetrion_index, simulation_step_index, event); }); } } diff --git a/src/game/tetrion.cpp b/src/game/tetrion.cpp index 1e8b68e8..8e2629b8 100644 --- a/src/game/tetrion.cpp +++ b/src/game/tetrion.cpp @@ -252,7 +252,7 @@ void Tetrion::spawn_next_tetromino(const helper::TetrominoType type, const Simul spdlog::info("game over"); if (m_recording_writer.has_value()) { spdlog::info("writing snapshot"); - m_recording_writer.value()->add_snapshot(m_tetrion_index, simulation_step_index, core_information()); + std::ignore = m_recording_writer.value()->add_snapshot(simulation_step_index, core_information()); } m_active_tetromino = {}; m_ghost_tetromino = {}; @@ -456,7 +456,7 @@ void Tetrion::lock_active_tetromino(const SimulationStep simulation_step_index) #if !defined(NDEBUG) if (m_recording_writer) { spdlog::debug("adding snapshot at step {}", simulation_step_index); - (*m_recording_writer)->add_snapshot(m_tetrion_index, simulation_step_index, core_information()); + std::ignore = (*m_recording_writer)->add_snapshot(simulation_step_index, core_information()); } #endif } diff --git a/src/libs/recordings/utility/recording_writer.cpp b/src/libs/recordings/utility/recording_writer.cpp index 9da53ff9..ad2f8231 100644 --- a/src/libs/recordings/utility/recording_writer.cpp +++ b/src/libs/recordings/utility/recording_writer.cpp @@ -19,10 +19,22 @@ recorder::RecordingWriter::RecordingWriter(RecordingWriter&& old) noexcept helper::expected recorder::RecordingWriter::get_writer( const std::filesystem::path& path, std::vector&& tetrion_headers, - AdditionalInformation&& information + AdditionalInformation&& information, + bool overwrite ) { + auto mode = std::ios::out | std::ios::binary; + if (overwrite) { + if (std::filesystem::exists(path)) { + return helper::unexpected{ + fmt::format("file already exists, not overwriting it: \"{}\"", path.string()) + }; + } + } else { + mode |= std::ios::trunc; + } + - auto output_file = std::ofstream{ path, std::ios::out | std::ios::binary }; + auto output_file = std::ofstream{ path, mode }; if (not output_file) { return helper::unexpected{ fmt::format("failed to open output file \"{}\"", path.string()) }; @@ -74,7 +86,7 @@ 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_record( const u8 tetrion_index, // NOLINT(bugprone-easily-swappable-parameters) const u64 simulation_step_index, const InputEvent event @@ -108,7 +120,6 @@ helper::expected recorder::RecordingWriter::add_event( } helper::expected recorder::RecordingWriter::add_snapshot( - const u8 tetrion_index, const u64 simulation_step_index, std::unique_ptr information ) { @@ -121,9 +132,8 @@ helper::expected recorder::RecordingWriter::add_snapshot( return helper::unexpected{ result.error() }; } - const auto snapshot = TetrionSnapshot{ tetrion_index, information->level, - information->score, information->lines_cleared, - simulation_step_index, information->mino_stack }; + const auto snapshot = TetrionSnapshot{ information->tetrion_index, information->level, information->score, + information->lines_cleared, simulation_step_index, information->mino_stack }; const auto bytes = snapshot.to_bytes(); result = helper::writer::write_vector_to_file(m_output_file, bytes); diff --git a/src/libs/recordings/utility/recording_writer.hpp b/src/libs/recordings/utility/recording_writer.hpp index 13d42441..e23e190b 100644 --- a/src/libs/recordings/utility/recording_writer.hpp +++ b/src/libs/recordings/utility/recording_writer.hpp @@ -26,16 +26,17 @@ namespace recorder { static helper::expected get_writer( const std::filesystem::path& path, std::vector&& tetrion_headers, - AdditionalInformation&& information + AdditionalInformation&& information, + bool overwrite = false ); - helper::expected add_event( + [[nodiscard]] helper::expected add_record( u8 tetrion_index, // NOLINT(bugprone-easily-swappable-parameters) u64 simulation_step_index, InputEvent event ); - helper::expected - add_snapshot(u8 tetrion_index, u64 simulation_step_index, std::unique_ptr information); + [[nodiscard]] helper::expected + add_snapshot(u64 simulation_step_index, std::unique_ptr information); private: static helper::expected diff --git a/src/lobby/api.hpp b/src/lobby/api.hpp index 75e35a0f..39b1565b 100644 --- a/src/lobby/api.hpp +++ b/src/lobby/api.hpp @@ -46,9 +46,9 @@ namespace lobby { // lobby commit used: https://github.com/OpenBrickProtocolFoundation/lobby/commit/2e0c8d05592f4e4d08437e6cb754a30f02c4e97c static constexpr StaticString supported_version{ "0.1.0" }; - helper::expected check_compatibility(); + [[nodiscard]] helper::expected check_compatibility(); - helper::expected check_reachability(); + [[nodiscard]] helper::expected check_reachability(); explicit Client(const std::string& api_url); @@ -66,30 +66,32 @@ namespace lobby { ~Client(); - helper::expected static get_client(const std::string& url); + [[nodiscard]] helper::expected static get_client(const std::string& url); - bool is_authenticated(); + [[nodiscard]] bool is_authenticated(); - bool authenticate(const Credentials& credentials); + [[nodiscard]] bool authenticate(const Credentials& credentials); - helper::expected, std::string> get_lobbies(); + [[nodiscard]] helper::expected, std::string> get_lobbies(); - helper::expected join_lobby(int lobby_id); + [[nodiscard]] helper::expected join_lobby(int lobby_id); - helper::expected get_lobby_detail(int lobby_id); + [[nodiscard]] helper::expected get_lobby_detail(int lobby_id); - helper::expected delete_lobby(int lobby_id); + [[nodiscard]] helper::expected delete_lobby(int lobby_id); - helper::expected leave_lobby(int lobby_id); + [[nodiscard]] helper::expected leave_lobby(int lobby_id); - helper::expected start_lobby(int lobby_id); + [[nodiscard]] helper::expected start_lobby(int lobby_id); - helper::expected create_lobby(const CreateLobbyRequest& arguments); + [[nodiscard]] helper::expected create_lobby( + const CreateLobbyRequest& arguments + ); - helper::expected, std::string> get_users(); + [[nodiscard]] helper::expected, std::string> get_users(); - helper::expected register_user(const RegisterRequest& register_request); + [[nodiscard]] helper::expected register_user(const RegisterRequest& register_request); }; diff --git a/wrapper/c b/wrapper/c index 84991e89..8434173d 160000 --- a/wrapper/c +++ b/wrapper/c @@ -1 +1 @@ -Subproject commit 84991e89e8611155d30eafb93b92f181aa35c02a +Subproject commit 8434173d7a4a551c20c90372d54bcd0744b75529