Moved spritesheet texture handling to anm2 instead of resources; added undoing for spritesheet texture changes; refactoring
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "snapshots.h"
|
||||
|
||||
static void _snapshot_stack_push(SnapshotStack* stack, const Snapshot* snapshot)
|
||||
static void _snapshot_stack_push(SnapshotStack* stack, Snapshot* snapshot)
|
||||
{
|
||||
if (stack->top >= SNAPSHOT_STACK_MAX)
|
||||
{
|
||||
@@ -11,20 +11,29 @@ static void _snapshot_stack_push(SnapshotStack* stack, const Snapshot* snapshot)
|
||||
stack->snapshots[stack->top++] = *snapshot;
|
||||
}
|
||||
|
||||
static bool _snapshot_stack_pop(SnapshotStack* stack, Snapshot* snapshot)
|
||||
static Snapshot* _snapshot_stack_pop(SnapshotStack* stack)
|
||||
{
|
||||
if (stack->top == 0) return false;
|
||||
|
||||
*snapshot = stack->snapshots[--stack->top];
|
||||
return true;
|
||||
if (stack->top == 0) return nullptr;
|
||||
return &stack->snapshots[--stack->top];
|
||||
}
|
||||
|
||||
static void _snapshot_set(Snapshots* self, const Snapshot& snapshot)
|
||||
static void _snapshot_set(Snapshots* self, Snapshot* snapshot)
|
||||
{
|
||||
*self->anm2 = snapshot.anm2;
|
||||
*self->reference = snapshot.reference;
|
||||
self->preview->time = snapshot.time;
|
||||
self->action = snapshot.action;
|
||||
if (!snapshot) return;
|
||||
|
||||
*self->anm2 = snapshot->anm2;
|
||||
*self->reference = snapshot->reference;
|
||||
self->preview->time = snapshot->time;
|
||||
self->action = snapshot->action;
|
||||
|
||||
anm2_spritesheet_texture_pixels_upload(self->anm2);
|
||||
}
|
||||
|
||||
Snapshot snapshot_get(Snapshots* self)
|
||||
{
|
||||
Snapshot snapshot = {*self->anm2, *self->reference, self->preview->time, self->action};
|
||||
anm2_spritesheet_texture_pixels_download(&snapshot.anm2);
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
void snapshots_init(Snapshots* self, Anm2* anm2, Anm2Reference* reference, Preview* preview)
|
||||
@@ -41,18 +50,17 @@ void snapshots_reset(Snapshots* self)
|
||||
self->action.clear();
|
||||
}
|
||||
|
||||
void snapshots_undo_push(Snapshots* self, const Snapshot* snapshot)
|
||||
void snapshots_undo_push(Snapshots* self, Snapshot* snapshot)
|
||||
{
|
||||
_snapshot_stack_push(&self->undoStack, snapshot);
|
||||
self->redoStack.top = 0;
|
||||
_snapshot_stack_push(&self->undoStack, snapshot);
|
||||
}
|
||||
|
||||
void snapshots_undo(Snapshots* self)
|
||||
{
|
||||
Snapshot snapshot;
|
||||
if (_snapshot_stack_pop(&self->undoStack, &snapshot))
|
||||
if (Snapshot* snapshot = _snapshot_stack_pop(&self->undoStack))
|
||||
{
|
||||
Snapshot current = {*self->anm2, *self->reference, self->preview->time, self->action};
|
||||
Snapshot current = snapshot_get(self);
|
||||
_snapshot_stack_push(&self->redoStack, ¤t);
|
||||
_snapshot_set(self, snapshot);
|
||||
}
|
||||
@@ -60,10 +68,9 @@ void snapshots_undo(Snapshots* self)
|
||||
|
||||
void snapshots_redo(Snapshots* self)
|
||||
{
|
||||
Snapshot snapshot;
|
||||
if (_snapshot_stack_pop(&self->redoStack, &snapshot))
|
||||
if (Snapshot* snapshot = _snapshot_stack_pop(&self->redoStack))
|
||||
{
|
||||
Snapshot current = {*self->anm2, *self->reference, self->preview->time, self->action};
|
||||
Snapshot current = snapshot_get(self);
|
||||
_snapshot_stack_push(&self->undoStack, ¤t);
|
||||
_snapshot_set(self, snapshot);
|
||||
}
|
||||
|
Reference in New Issue
Block a user