You've already forked flecs_tests
Reorganized the code structure, fix a lot of issues.
This commit is contained in:
@@ -75,7 +75,6 @@ static void hist_apply_prop(shape_t *s, hist_prop_t prop, const float val[4]) {
|
||||
}
|
||||
}
|
||||
|
||||
// -- history API --
|
||||
|
||||
/**
|
||||
* Zero-initialize the history stack. Call once during app init.
|
||||
@@ -206,7 +205,37 @@ static void history_end_edit(history_t *h, vector_t *shapes) {
|
||||
* @param shapes the shapes vector to modify
|
||||
* @param forward true to use new_val (redo), false to use old_val (undo)
|
||||
*/
|
||||
static void history_apply_entry(hist_entry_t *entry, vector_t *shapes, bool forward) {
|
||||
// -- batch API for multi-shape operations (move, rotate, resize) --
|
||||
|
||||
typedef struct {
|
||||
hist_change_t *changes;
|
||||
int count;
|
||||
int capacity;
|
||||
} hist_batch_t;
|
||||
|
||||
static void history_batch_init(hist_batch_t *batch, int count) {
|
||||
batch->changes = (hist_change_t*) ALLOC((size_t)count * sizeof(hist_change_t));
|
||||
batch->count = 0;
|
||||
batch->capacity = count;
|
||||
}
|
||||
|
||||
static void history_batch_add(hist_batch_t *batch, int shape_index, hist_prop_t prop,
|
||||
const float old_val[4], const float new_val[4]) {
|
||||
hist_change_t *c = &batch->changes[batch->count++];
|
||||
c->shape_index = shape_index;
|
||||
c->prop = prop;
|
||||
memcpy(c->old_val, old_val, sizeof(float[4]));
|
||||
memcpy(c->new_val, new_val, sizeof(float[4]));
|
||||
}
|
||||
|
||||
static void history_batch_commit(hist_batch_t *batch, history_t *h) {
|
||||
hist_entry_t entry = { .changes = batch->changes, .count = batch->count };
|
||||
history_push_entry(h, entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply every change in an entry to the shapes vector and regenerate buffers.
|
||||
*/static void history_apply_entry(hist_entry_t *entry, vector_t *shapes, bool forward) {
|
||||
for (int i = 0; i < entry->count; i++) {
|
||||
hist_change_t *c = &entry->changes[i];
|
||||
if (c->shape_index >= shapes->count) continue;
|
||||
@@ -217,37 +246,19 @@ static void history_apply_entry(hist_entry_t *entry, vector_t *shapes, bool forw
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undo the most recent history entry.
|
||||
*
|
||||
* @param h history stack
|
||||
* @param shapes the shapes vector to revert
|
||||
* @param selected_count out-parameter for updated selection count (currently passed through)
|
||||
* @return true if state was changed, false if nothing to undo
|
||||
*/
|
||||
static bool history_undo(history_t *h, vector_t *shapes, int *selected_count) {
|
||||
static bool history_undo(history_t *h, vector_t *shapes) {
|
||||
if (h->current < 0) return false;
|
||||
|
||||
history_apply_entry(&h->entries[h->current], shapes, false);
|
||||
h->current--;
|
||||
(void)selected_count;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redo the next history entry.
|
||||
*
|
||||
* @param h history stack
|
||||
* @param shapes the shapes vector to advance
|
||||
* @param selected_count out-parameter (currently passed through)
|
||||
* @return true if state was changed, false if nothing to redo
|
||||
*/
|
||||
static bool history_redo(history_t *h, vector_t *shapes, int *selected_count) {
|
||||
static bool history_redo(history_t *h, vector_t *shapes) {
|
||||
if (h->current + 1 >= h->count) return false;
|
||||
|
||||
h->current++;
|
||||
history_apply_entry(&h->entries[h->current], shapes, true);
|
||||
(void)selected_count;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user