X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fgame%2Flevel%2Flevel_editor%2Fundo_history.h;h=e5af7ccbefd655566bf38133f085426640bf0a2d;hb=f95f6c77920df1cd11145385a6061afbac9e705f;hp=953bc1cdebc563138a8d5ab8c6c8fba4780c803a;hpb=d3dc4dbed941753d12cc33b40b34a36a0c63cf8f;p=nothing.git diff --git a/src/game/level/level_editor/undo_history.h b/src/game/level/level_editor/undo_history.h index 953bc1cd..e5af7ccb 100644 --- a/src/game/level/level_editor/undo_history.h +++ b/src/game/level/level_editor/undo_history.h @@ -1,28 +1,32 @@ #ifndef UNDO_HISTORY_H_ #define UNDO_HISTORY_H_ -#include "layer.h" +#include "ring_buffer.h" -#define CONTEXT_SIZE 32 +typedef void (*RevertAction)(void *context, size_t context_size); typedef struct { - char data[CONTEXT_SIZE]; -} Context; + RingBuffer actions; +} UndoHistory; -typedef void (*RevertAction)(void *layer, Context context); +UndoHistory create_undo_history(void); -typedef struct { - void *layer; - Context context; - RevertAction revert; -} Action; - -typedef struct UndoHistory UndoHistory; +static inline +void destroy_undo_history(UndoHistory undo_history) +{ + destroy_ring_buffer(undo_history.actions); +} -UndoHistory *create_undo_history(void); -void destroy_undo_history(UndoHistory *undo_history); - -void undo_history_push(UndoHistory *undo_history, Action 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); +static inline +int undo_history_empty(UndoHistory *undo_history) +{ + return undo_history->actions.count == 0; +} + #endif // UNDO_HISTORY_H_