impl multi delete

This commit is contained in:
2025-01-06 18:51:42 +00:00
parent adadd8a92a
commit aac1844ad8

View File

@@ -268,6 +268,7 @@ entity_t *entity_alloc(state_t *state, size_t point_count) {
entity->points = point_list_alloc(point_count); entity->points = point_list_alloc(point_count);
} }
entity->flags = 0;
entity->next = NULL; entity->next = NULL;
entity->prev = NULL; entity->prev = NULL;
@@ -281,10 +282,7 @@ void entity_recycle(state_t *state, entity_t *entity) {
point_list_clear(&entity->points); point_list_clear(&entity->points);
} }
void entity_free(entity_t *entity) { void entity_free(entity_t *entity) { point_list_free(&entity->points); }
printf("entity_free\n");
point_list_free(&entity->points);
}
void push_entity(state_t *state, entity_t *entity) { void push_entity(state_t *state, entity_t *entity) {
entity->next = state->entities; entity->next = state->entities;
@@ -294,15 +292,26 @@ void push_entity(state_t *state, entity_t *entity) {
state->entities = entity; state->entities = entity;
} }
void remove_entity(state_t *state, entity_t *entity) { void remove_selected_entites(state_t *state) {
if (state->entities == entity) { entity_t *last_removed_entity = NULL;
state->entities = entity->next; for (entity_t *entity = state->entities; entity != NULL;
} entity = entity->next) {
if (entity->prev) { if (last_removed_entity) {
entity->prev->next = entity->next; entity_recycle(state, last_removed_entity);
} last_removed_entity = NULL;
if (entity->next) { }
entity->next->prev = entity->prev; if (entity->flags & entity_flag_selected) {
if (state->entities == entity) {
state->entities = entity->next;
}
if (entity->prev) {
entity->prev->next = entity->next;
}
if (entity->next) {
entity->next->prev = entity->prev;
}
last_removed_entity = entity;
}
} }
if (state->entities == NULL) { if (state->entities == NULL) {
@@ -313,18 +322,9 @@ void remove_entity(state_t *state, entity_t *entity) {
state->freed_entity = NULL; state->freed_entity = NULL;
arena_free(state->arena); arena_free(state->arena);
state->arena = arena_alloc(ARENA_INITIAL_SIZE); state->arena = arena_alloc(ARENA_INITIAL_SIZE);
} else {
entity_recycle(state, entity);
} }
}
void remove_selected_entites(state_t *state) { state->has_selected_entities = false;
for (entity_t *entity = state->entities; entity != NULL;
entity = entity->next) {
if (entity->flags & entity_flag_selected) {
remove_entity(state, entity);
}
}
} }
void create_entity(state_t *state) { void create_entity(state_t *state) {
@@ -642,7 +642,6 @@ static void frame(void) {
if (igIsKeyPressed_Bool(ImGuiKey_Backspace, false)) { if (igIsKeyPressed_Bool(ImGuiKey_Backspace, false)) {
remove_selected_entites(&state); remove_selected_entites(&state);
state.has_selected_entities = false;
} }
//======= draw entities to canvas ========= //======= draw entities to canvas =========