]> git.lizzy.rs Git - nothing.git/blob - src/game/level/level_editor/undo_history.h
3a63fd30778ab5bffccdd89e142ceca4098d2aa5
[nothing.git] / src / game / level / level_editor / undo_history.h
1 #ifndef UNDO_HISTORY_H_
2 #define UNDO_HISTORY_H_
3
4 #include "ring_buffer.h"
5
6 typedef void (*RevertAction)(void *context, size_t context_size);
7
8 typedef struct {
9     RingBuffer actions;
10     Memory *memory;
11 } UndoHistory;
12
13 UndoHistory *create_undo_history_from_memory(Memory *memory);
14
15 void undo_history_push(UndoHistory *undo_history,
16                        RevertAction revert,
17                        void *context_data,
18                        size_t context_data_size);
19 void undo_history_pop(UndoHistory *undo_history);
20
21 void undo_history_clean(UndoHistory *undo_history);
22
23 static inline
24 int undo_history_empty(UndoHistory *undo_history)
25 {
26     return undo_history->actions.count == 0;
27 }
28
29 #endif  // UNDO_HISTORY_H_