Skip to content

Commit

Permalink
GameObject change undo/redo refactor to track different options (#3085
Browse files Browse the repository at this point in the history
)

`GameObject`, instead of comparing all options against each other, now saves the state of and compares individual ones, so the change data is more memory-efficient.

This way of tracking object changes also allows for proper undo/redo tracking with multiple remote users (regarding the [remote level editing concept](https://github.com/SuperTux/supertux/tree/editor-remote-level-networking), which branch these changes originate from).

`TileMap` tile changes are now saved in a way more memory-efficient way. Instead of saving the whole tiles array for each change, only the changed tiles are saved in a list of pairs (tile index, old/new tile ID).
  • Loading branch information
Vankata453 authored Oct 24, 2024
1 parent 792eaa0 commit bda676b
Show file tree
Hide file tree
Showing 21 changed files with 973 additions and 149 deletions.
30 changes: 19 additions & 11 deletions src/editor/layers_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,7 @@ EditorLayersWidget::draw(DrawingContext& context)
void
EditorLayersWidget::update(float dt_sec)
{
auto it = m_layer_icons.begin();
while (it != m_layer_icons.end())
{
auto layer_icon = (*it).get();
if (!layer_icon->is_valid())
{
it = m_layer_icons.erase(it);
continue;
}
++it;
}
remove_invalid_layers();

TileMap* selected_tilemap = get_selected_tilemap();
if (selected_tilemap)
Expand Down Expand Up @@ -460,6 +450,8 @@ EditorLayersWidget::add_layer(GameObject* layer, bool initial)
void
EditorLayersWidget::update_tip()
{
remove_invalid_layers();

if (m_hovered_layer == m_layer_icons.size())
m_object_tip->set_info(_("Add Layer"));
else if (m_hovered_layer > m_layer_icons.size())
Expand All @@ -477,6 +469,22 @@ EditorLayersWidget::update_current_tip()
update_tip();
}

void
EditorLayersWidget::remove_invalid_layers()
{
auto it = m_layer_icons.begin();
while (it != m_layer_icons.end())
{
auto layer_icon = (*it).get();
if (!layer_icon->is_valid())
{
it = m_layer_icons.erase(it);
continue;
}
++it;
}
}

TileMap*
EditorLayersWidget::get_selected_tilemap() const
{
Expand Down
2 changes: 2 additions & 0 deletions src/editor/layers_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class EditorLayersWidget final : public Widget
private:
Vector get_layer_coords(const int pos) const;
int get_layer_pos(const Vector& coords) const;

void update_tip();
void remove_invalid_layers();

private:
Editor& m_editor;
Expand Down
Loading

0 comments on commit bda676b

Please sign in to comment.