Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Undo System - It's time #414

Open
AlexvZyl opened this issue Jun 22, 2022 · 3 comments
Open

Undo System - It's time #414

AlexvZyl opened this issue Jun 22, 2022 · 3 comments
Assignees
Labels
Application Issues regarding the application in general. Feature Request Request to add a feature to the application.

Comments

@AlexvZyl
Copy link
Owner

AlexvZyl commented Jun 22, 2022

Check at 21:40.

Command pattern Wikipedia.

@UlrichLouwEnerdyne Vir as jy wil inloer hier.

@AlexvZyl AlexvZyl added Feature Request Request to add a feature to the application. Application Issues regarding the application in general. labels Jun 22, 2022
@AlexvZyl
Copy link
Owner Author

AlexvZyl commented Jun 22, 2022

Command parent class:

class Command
{
public:
    inline virtual void execute() = 0;
    inline virtual void undo() = 0;

protected:
    // We do no want instances of Command.
    inline Command() = default;

private:
    // Children will have data here required for the command.

}

I think having a CommandLog is nice, similarly to how we have an EventLog with events.

class CommandLog
{
public:

    static void undo()
    {
        if(!m_commandHistory.size()) return;
    
        m_commandHistory.back()->undo();
        m_commandHistory.pop_back();
    }
    
    static void log(const Command& command)
    {
        m_commandHistory.push_back(command);
    }
    
    static void execute(Command& command)
    {
        command.execute();
        log(command);
    }

    static const auto& getHistory()
    {
        return m_commandHistory;
    }

private:

    // Probably want to put a max size on this.
    std::vector<std::unique_ptr<Command>> m_commandHistory;
    
    // Do not want an instance.
    inline CommandLog() = default;
}

If we want we can also add wrappers in Application for the log, since the engines would want to use the log.

However, this will require a relatively large rework, since everything that we want to be able to redo has to fit into this. But I think it is worth it.

@AlexvZyl AlexvZyl pinned this issue Jun 22, 2022
@Cullen-Enerdyne
Copy link
Collaborator

Changes to above:

  • Made CommandLog non-static. We will likely log commands per engine.

@AlexvZyl
Copy link
Owner Author

Changes to above:

  • Made CommandLog non-static. We will likely log commands per engine.

Yes, we definitely want this.

@AlexvZyl AlexvZyl unpinned this issue Jun 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Application Issues regarding the application in general. Feature Request Request to add a feature to the application.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants