]> git.lizzy.rs Git - nothing.git/blobdiff - src/game/level/level_editor/undo_history.h
Merge pull request #1255 from tsoding/1253
[nothing.git] / src / game / level / level_editor / undo_history.h
index 2e6cbac99f8d8da2d0dc94c95bcfe9790d8f0ba3..1c3cd43d159200b3c04ef6d03659cf7da4918b36 100644 (file)
@@ -1,52 +1,29 @@
 #ifndef UNDO_HISTORY_H_
 #define UNDO_HISTORY_H_
 
-#include "layer.h"
+#include "ring_buffer.h"
 
-#define CONTEXT_SIZE 256
-
-#define ASSERT_CONTEXT_SIZE(context)               \
-    trace_assert(sizeof(context) <= CONTEXT_SIZE)
+typedef void (*RevertAction)(void *context, size_t context_size);
 
 typedef struct {
-    char data[CONTEXT_SIZE];
-} Context;
+    RingBuffer actions;
+    Memory *memory;
+} UndoHistory;
 
-typedef void (*RevertAction)(void *layer, Context context);
+UndoHistory *create_undo_history(Memory *memory);
 
-typedef struct {
-    void *layer;
-    Context context;
-    RevertAction revert;
-} Action;
+void undo_history_push(UndoHistory *undo_history,
+                       RevertAction revert,
+                       void *context_data,
+                       size_t context_data_size);
+void undo_history_pop(UndoHistory *undo_history);
+
+void undo_history_clean(UndoHistory *undo_history);
 
 static inline
-Action create_action(void *layer, RevertAction revert,
-                     void *context_data,
-                     size_t context_data_size)
+int undo_history_empty(UndoHistory *undo_history)
 {
-    trace_assert(layer);
-    trace_assert(revert);
-    trace_assert(context_data_size < CONTEXT_SIZE);
-
-    Action action = {
-        .layer = layer,
-        .revert = revert
-    };
-
-    if (context_data) {
-        memcpy(action.context.data, context_data, context_data_size);
-    }
-
-    return action;
+    return undo_history->actions.count == 0;
 }
 
-typedef struct UndoHistory UndoHistory;
-
-UndoHistory *create_undo_history(void);
-void destroy_undo_history(UndoHistory *undo_history);
-
-void undo_history_push(UndoHistory *undo_history, Action action);
-void undo_history_pop(UndoHistory *undo_history);
-
 #endif  // UNDO_HISTORY_H_