From 3d946965ade4b6ce925038acdda62fd9fc8243f7 Mon Sep 17 00:00:00 2001 From: Vankata453 <78196474+Vankata453@users.noreply.github.com> Date: Tue, 22 Oct 2024 16:13:56 +0300 Subject: [PATCH] Rename `GameObjectChanges` to `GameObjectChangeSet`, fix MacOS compilation error --- src/supertux/game_object_change.cpp | 12 ++++++------ src/supertux/game_object_change.hpp | 13 +++++++------ src/supertux/game_object_manager.cpp | 28 ++++++++++++++-------------- src/supertux/game_object_manager.hpp | 4 ++-- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/supertux/game_object_change.cpp b/src/supertux/game_object_change.cpp index 8ca144b8c88..68d88a6df01 100644 --- a/src/supertux/game_object_change.cpp +++ b/src/supertux/game_object_change.cpp @@ -55,15 +55,15 @@ GameObjectChange::save(Writer& writer) const } -GameObjectChanges::GameObjectChanges(const UID& uid_, std::vector objects_) : +GameObjectChangeSet::GameObjectChangeSet(const UID& uid_, std::vector objects_) : uid(uid_), - objects(std::move(objects_)) + changes(std::move(objects_)) { } -GameObjectChanges::GameObjectChanges(const ReaderMapping& reader) : +GameObjectChangeSet::GameObjectChangeSet(const ReaderMapping& reader) : uid(), - objects() + changes() { auto iter = reader.get_iter(); while (iter.next()) @@ -79,9 +79,9 @@ GameObjectChanges::GameObjectChanges(const ReaderMapping& reader) : } void -GameObjectChanges::save(Writer& writer) const +GameObjectChangeSet::save(Writer& writer) const { - for (const auto& change : objects) + for (const auto& change : changes) { writer.start_list("object-change"); change.save(writer); diff --git a/src/supertux/game_object_change.hpp b/src/supertux/game_object_change.hpp index 39c6b91d1be..0f8c67af8cd 100644 --- a/src/supertux/game_object_change.hpp +++ b/src/supertux/game_object_change.hpp @@ -18,6 +18,7 @@ #define HEADER_SUPERTUX_SUPERTUX_GAME_OBJECT_CHANGE_HPP #include +#include #include "util/uid.hpp" @@ -51,18 +52,18 @@ class GameObjectChange final Action action; // The action which triggered a state change }; -/** Stores multiple GameObjectChanges. */ -class GameObjectChanges final +/** Stores multiple GameObjectChange-s. */ +class GameObjectChangeSet final { public: - GameObjectChanges(const UID& uid, std::vector objects); - GameObjectChanges(const ReaderMapping& reader); + GameObjectChangeSet(const UID& uid, std::vector objects); + GameObjectChangeSet(const ReaderMapping& reader); void save(Writer& writer) const; public: - UID uid; - std::vector objects; + const UID uid; + std::vector changes; }; #endif diff --git a/src/supertux/game_object_manager.cpp b/src/supertux/game_object_manager.cpp index d0d10ec46f3..9e346ad2470 100644 --- a/src/supertux/game_object_manager.cpp +++ b/src/supertux/game_object_manager.cpp @@ -424,9 +424,9 @@ GameObjectManager::apply_object_change(const GameObjectChange& change, bool trac } void -GameObjectManager::apply_object_changes(const GameObjectChanges& changes, bool track_undo) +GameObjectManager::apply_object_changes(const GameObjectChangeSet& change_set, bool track_undo) { - for (const auto& change : changes.objects) + for (const auto& change : change_set.changes) { try { @@ -444,10 +444,10 @@ void GameObjectManager::undo() { if (m_undo_stack.empty()) return; - GameObjectChanges& changes = m_undo_stack.back(); + GameObjectChangeSet& change_set = m_undo_stack.back(); - auto it = changes.objects.begin(); - while (it != changes.objects.end()) + auto it = change_set.changes.begin(); + while (it != change_set.changes.end()) { try { @@ -457,14 +457,14 @@ GameObjectManager::undo() catch (const std::exception& err) { log_warning << "Cannot process object change: " << err.what() << std::endl; - it = changes.objects.erase(it); // Drop invalid changes + it = change_set.changes.erase(it); // Drop invalid changes } } - if (!changes.objects.empty()) + if (!change_set.changes.empty()) { // Changes have been reversed for redo - m_redo_stack.push_back(std::move(changes)); + m_redo_stack.push_back(std::move(change_set)); } m_undo_stack.pop_back(); } @@ -473,10 +473,10 @@ void GameObjectManager::redo() { if (m_redo_stack.empty()) return; - GameObjectChanges& changes = m_redo_stack.back(); + GameObjectChangeSet& change_set = m_redo_stack.back(); - auto it = changes.objects.begin(); - while (it != changes.objects.end()) + auto it = change_set.changes.begin(); + while (it != change_set.changes.end()) { try { @@ -486,14 +486,14 @@ GameObjectManager::redo() catch (const std::exception& err) { log_warning << "Cannot process object change: " << err.what() << std::endl; - it = changes.objects.erase(it); // Drop invalid changes + it = change_set.changes.erase(it); // Drop invalid changes } } - if (!changes.objects.empty()) + if (!change_set.changes.empty()) { // Changes have been reversed for undo - m_undo_stack.push_back(std::move(changes)); + m_undo_stack.push_back(std::move(change_set)); } m_redo_stack.pop_back(); } diff --git a/src/supertux/game_object_manager.hpp b/src/supertux/game_object_manager.hpp index e2ac2c02fc0..e279866a177 100644 --- a/src/supertux/game_object_manager.hpp +++ b/src/supertux/game_object_manager.hpp @@ -346,8 +346,8 @@ class GameObjectManager : public ExposableClass UIDGenerator m_change_uid_generator; bool m_undo_tracking; int m_undo_stack_size; - std::vector m_undo_stack; - std::vector m_redo_stack; + std::vector m_undo_stack; + std::vector m_redo_stack; std::vector m_pending_change_stack; // Before a flush, any changes go here UID m_last_saved_change;