/* * InfiniPaint * Copyright (C) 2025-2026 Yousef Khadadeh * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include #include #include #include class World; class WorldUndoManager; class WorldUndoAction { public: virtual std::string get_name() const = 0; virtual bool undo(WorldUndoManager& undoMan) = 0; virtual bool redo(WorldUndoManager& undoMan) = 0; virtual void scale_up(const WorldScalar& scaleAmount); virtual ~WorldUndoAction(); }; class WorldUndoManager { public: typedef uint64_t UndoObjectID; WorldUndoManager(World& initWorld); void push(std::unique_ptr undoAction); void push_on_last(std::unique_ptr undoAction); void undo(); void redo(); void clear(); bool can_undo(); bool can_redo(); void scale_up(const WorldScalar& scaleAmount); void reassign_netid(const NetworkingObjects::NetObjID& oldNetObjID, const NetworkingObjects::NetObjID& newNetObjID); void remove_by_netid(const NetworkingObjects::NetObjID& netObjID); void remove_by_undoid(UndoObjectID undoID); UndoObjectID get_undoid_from_netid(const NetworkingObjects::NetObjID& netObjID); void register_new_netid_to_existing_undoid(UndoObjectID existingUndoID, const NetworkingObjects::NetObjID& netObjID); std::optional get_netid_from_undoid(UndoObjectID undoID); bool fill_netid_list_from_undoid_list(std::vector& netIDList, const std::vector& undoIDList); std::vector get_front_undo_queue_names(unsigned count); void set_save_action(); World& world; private: void push_undo(std::vector> undoAction); void push_redo(std::vector> undoAction); constexpr static size_t UNDO_QUEUE_LIMIT = 250; std::unordered_map undoIDToNetID; std::unordered_map netIDToUndoID; std::deque>> undoQueue; std::deque>> redoQueue; std::optional undoActionSavedAt = nullptr; void set_world_has_unsaved_local_changes(); UndoObjectID lastUndoObjectID = 0; };