Skip to content

Commit

Permalink
Rename GameObjectChanges to GameObjectChangeSet, fix MacOS compil…
Browse files Browse the repository at this point in the history
…ation error
  • Loading branch information
Vankata453 committed Oct 22, 2024
1 parent 3de0fa8 commit 3d94696
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
12 changes: 6 additions & 6 deletions src/supertux/game_object_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ GameObjectChange::save(Writer& writer) const
}


GameObjectChanges::GameObjectChanges(const UID& uid_, std::vector<GameObjectChange> objects_) :
GameObjectChangeSet::GameObjectChangeSet(const UID& uid_, std::vector<GameObjectChange> 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())
Expand All @@ -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);
Expand Down
13 changes: 7 additions & 6 deletions src/supertux/game_object_change.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define HEADER_SUPERTUX_SUPERTUX_GAME_OBJECT_CHANGE_HPP

#include <string>
#include <vector>

#include "util/uid.hpp"

Expand Down Expand Up @@ -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<GameObjectChange> objects);
GameObjectChanges(const ReaderMapping& reader);
GameObjectChangeSet(const UID& uid, std::vector<GameObjectChange> objects);
GameObjectChangeSet(const ReaderMapping& reader);

void save(Writer& writer) const;

public:
UID uid;
std::vector<GameObjectChange> objects;
const UID uid;
std::vector<GameObjectChange> changes;
};

#endif
Expand Down
28 changes: 14 additions & 14 deletions src/supertux/game_object_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
{
Expand All @@ -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();
}
Expand All @@ -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
{
Expand All @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/supertux/game_object_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ class GameObjectManager : public ExposableClass
UIDGenerator m_change_uid_generator;
bool m_undo_tracking;
int m_undo_stack_size;
std::vector<GameObjectChanges> m_undo_stack;
std::vector<GameObjectChanges> m_redo_stack;
std::vector<GameObjectChangeSet> m_undo_stack;
std::vector<GameObjectChangeSet> m_redo_stack;
std::vector<GameObjectChange> m_pending_change_stack; // Before a flush, any changes go here
UID m_last_saved_change;

Expand Down

0 comments on commit 3d94696

Please sign in to comment.