diff -r 62508d957a22 -r 6b266e907f89 src/scene.c --- a/src/scene.c Tue Jul 22 20:57:13 2025 +0200 +++ b/src/scene.c Tue Jul 22 21:38:02 2025 +0200 @@ -30,6 +30,7 @@ #include "ascension/scene.h" #include "ascension/behavior.h" #include "ascension/shader.h" +#include "ascension/util.h" #include #include @@ -38,29 +39,32 @@ #include -void asc_scene_init_(AscScene *scene, struct asc_camera_init_args args) { - if (scene->root != NULL) { - asc_wprintf("Scene %"PRIxPTR" is already initialized - initialization skipped.", (uintptr_t) scene); - return; - } +void asc_scene_init_(AscScene *scene, const char *name, struct asc_camera_init_args args) { + assert(scene->root == NULL); asc_camera_init_(&scene->camera, args); scene->root = asc_scene_node_empty(); for (unsigned i = 0 ; i < ASC_RENDER_GROUP_COUNT ; i++) { scene->internal.render_groups[i] = cxArrayListCreateSimple(CX_STORE_POINTERS, 32); } - - asc_dprintf("Initialized scene %"PRIxPTR, (uintptr_t) scene); + if (name == NULL) { + scene->name = asc_util_gen_name(scene); + } else { + scene->name.ptr = strdup(name); + scene->name.length = strlen(name); + } + asc_dprintf("Initialized scene %"CX_PRIstr, CX_SFMT(scene->name)); } void asc_scene_destroy(AscScene *scene) { - if (scene->root == NULL) return; + if (scene == NULL || scene->root == NULL) return; for (unsigned i = 0 ; i < ASC_RENDER_GROUP_COUNT ; i++) { cxListFree(scene->internal.render_groups[i]); scene->internal.render_groups[i] = NULL; } - // TODO: add names to scenes - asc_dprintf("Destroyed scene %"PRIxPTR, (uintptr_t) scene); asc_scene_node_free(scene->root); + scene->root = NULL; + asc_dprintf("Destroyed scene %"CX_PRIstr, CX_SFMT(scene->name)); + cx_strfree(&scene->name); } void asc_scene_execute_behaviors(AscScene *scene) {