The Omega Refactor(TM) + Input Options
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
#include "snapshots.h"
|
||||
|
||||
// Pushes the undo stack
|
||||
void
|
||||
snapshots_undo_stack_push(Snapshots* self, Snapshot* snapshot)
|
||||
{
|
||||
// If stack over the limit, shift it
|
||||
if (self->undoStack.top >= SNAPSHOT_STACK_MAX)
|
||||
{
|
||||
memmove(&self->undoStack.snapshots[0], &self->undoStack.snapshots[1], sizeof(Snapshot) * (SNAPSHOT_STACK_MAX - 1));
|
||||
for (s32 i = 0; i < SNAPSHOT_STACK_MAX - 1; i++)
|
||||
self->undoStack.snapshots[i] = self->undoStack.snapshots[i + 1];
|
||||
|
||||
self->undoStack.top = SNAPSHOT_STACK_MAX - 1;
|
||||
}
|
||||
|
||||
@@ -13,6 +17,7 @@ snapshots_undo_stack_push(Snapshots* self, Snapshot* snapshot)
|
||||
self->redoStack.top = 0;
|
||||
}
|
||||
|
||||
// Pops the undo stack
|
||||
bool
|
||||
snapshots_undo_stack_pop(Snapshots* self, Snapshot* snapshot)
|
||||
{
|
||||
@@ -24,18 +29,21 @@ snapshots_undo_stack_pop(Snapshots* self, Snapshot* snapshot)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Pushes the redo stack
|
||||
void
|
||||
snapshots_redo_stack_push(Snapshots* self, Snapshot* snapshot)
|
||||
{
|
||||
if (self->redoStack.top >= SNAPSHOT_STACK_MAX)
|
||||
{
|
||||
memmove(&self->redoStack.snapshots[0], &self->redoStack.snapshots[1], sizeof(Snapshot) * (SNAPSHOT_STACK_MAX - 1));
|
||||
for (s32 i = 0; i < SNAPSHOT_STACK_MAX - 1; i++)
|
||||
self->redoStack.snapshots[i] = self->redoStack.snapshots[i + 1];
|
||||
self->redoStack.top = SNAPSHOT_STACK_MAX - 1;
|
||||
}
|
||||
|
||||
self->redoStack.snapshots[self->redoStack.top++] = *snapshot;
|
||||
}
|
||||
|
||||
// Pops the redo stack
|
||||
bool
|
||||
snapshots_redo_stack_pop(Snapshots* self, Snapshot* snapshot)
|
||||
{
|
||||
@@ -46,6 +54,7 @@ snapshots_redo_stack_pop(Snapshots* self, Snapshot* snapshot)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Initializes snapshots
|
||||
void
|
||||
snapshots_init(Snapshots* self, Anm2* anm2, Anm2Reference* reference, f32* time, Input* input)
|
||||
{
|
||||
@@ -55,11 +64,16 @@ snapshots_init(Snapshots* self, Anm2* anm2, Anm2Reference* reference, f32* time,
|
||||
self->input = input;
|
||||
}
|
||||
|
||||
// Ticks snapshots
|
||||
void
|
||||
snapshots_tick(Snapshots* self)
|
||||
{
|
||||
/* Undo */
|
||||
if (key_press(&self->input->keyboard, INPUT_KEYS[INPUT_UNDO]))
|
||||
if (input_press(self->input, INPUT_UNDO))
|
||||
self->isUndo = true;
|
||||
|
||||
// isUndo disconnected, if another part of the program wants to set it
|
||||
if (self->isUndo)
|
||||
{
|
||||
Snapshot snapshot;
|
||||
if (snapshots_undo_stack_pop(self, &snapshot))
|
||||
@@ -71,10 +85,16 @@ snapshots_tick(Snapshots* self)
|
||||
*self->reference = snapshot.reference;
|
||||
*self->time = snapshot.time;
|
||||
}
|
||||
|
||||
self->isUndo = false;
|
||||
}
|
||||
|
||||
/* Redo */
|
||||
if (key_press(&self->input->keyboard, INPUT_KEYS[INPUT_REDO]))
|
||||
if (input_press(self->input, INPUT_REDO))
|
||||
self->isRedo = true;
|
||||
|
||||
// isRedo disconnected, if another part of the program wants to set it
|
||||
if (self->isRedo)
|
||||
{
|
||||
Snapshot snapshot;
|
||||
if (snapshots_redo_stack_pop(self, &snapshot))
|
||||
@@ -86,5 +106,7 @@ snapshots_tick(Snapshots* self)
|
||||
*self->reference = snapshot.reference;
|
||||
*self->time = snapshot.time;
|
||||
}
|
||||
|
||||
self->isRedo = false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user