summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-05-30 20:24:03 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-05-30 20:24:03 -0400
commit1de647b9d38528b640f8da473d50c04ef0674c58 (patch)
treec2b4ae1234a4d20142ab70b6e27030082b10b13d
parent72daebf48e4a27de9f6633b2693ab96fb4ef1e44 (diff)
downloaddimension-1de647b9d38528b640f8da473d50c04ef0674c58.tar.xz
scene: Get rid of dmnsn_delete_scene().
-rw-r--r--libdimension-python/dimension.pxd1
-rw-r--r--libdimension-python/dimension.pyx3
-rw-r--r--libdimension/dimension/scene.h6
-rw-r--r--libdimension/scene.c32
-rw-r--r--libdimension/tests/render.c36
5 files changed, 29 insertions, 49 deletions
diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd
index 4303871..36785ee 100644
--- a/libdimension-python/dimension.pxd
+++ b/libdimension-python/dimension.pxd
@@ -409,7 +409,6 @@ cdef extern from "../libdimension/dimension.h":
dmnsn_timer render_timer
dmnsn_scene *dmnsn_new_scene(dmnsn_pool *pool)
- void dmnsn_delete_scene(dmnsn_scene *scene)
void dmnsn_ray_trace(dmnsn_scene *scene)
dmnsn_future *dmnsn_ray_trace_async(dmnsn_scene *scene)
diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx
index 5e02aff..846772a 100644
--- a/libdimension-python/dimension.pyx
+++ b/libdimension-python/dimension.pyx
@@ -1625,9 +1625,6 @@ cdef class Scene:
dmnsn_texture_cascade(default._texture, &self._scene.default_texture)
return _Future(dmnsn_ray_trace_async(self._scene))
- def __dealloc__(self):
- dmnsn_delete_scene(self._scene)
-
def _quality_to_string(int quality):
cdef str s = ""
diff --git a/libdimension/dimension/scene.h b/libdimension/dimension/scene.h
index 321fac2..dd0c1ba 100644
--- a/libdimension/dimension/scene.h
+++ b/libdimension/dimension/scene.h
@@ -89,12 +89,6 @@ typedef struct dmnsn_scene {
dmnsn_scene *dmnsn_new_scene(dmnsn_pool *pool);
/**
- * Delete a scene.
- * @param[in,out] scene The scene to delete.
- */
-void dmnsn_delete_scene(dmnsn_scene *scene);
-
-/**
* Initialize a scene.
* @param[in,out] scene The scene to initalize.
*/
diff --git a/libdimension/scene.c b/libdimension/scene.c
index 6500707..610b8f9 100644
--- a/libdimension/scene.c
+++ b/libdimension/scene.c
@@ -26,11 +26,25 @@
#include "dimension-internal.h"
#include <stdlib.h>
+static void
+dmnsn_scene_cleanup(void *ptr)
+{
+ dmnsn_scene *scene = ptr;
+ DMNSN_ARRAY_FOREACH (dmnsn_object **, object, scene->objects) {
+ dmnsn_delete_object(*object);
+ }
+
+ dmnsn_delete_array(scene->lights);
+ dmnsn_delete_array(scene->objects);
+ dmnsn_delete_texture(scene->default_texture);
+ dmnsn_delete_pigment(scene->background);
+}
+
/* Allocate an empty scene */
dmnsn_scene *
dmnsn_new_scene(dmnsn_pool *pool)
{
- dmnsn_scene *scene = DMNSN_PALLOC(pool, dmnsn_scene);
+ dmnsn_scene *scene = DMNSN_PALLOC_TIDY(pool, dmnsn_scene, dmnsn_scene_cleanup);
scene->background = NULL;
scene->default_texture = dmnsn_new_texture();
@@ -52,22 +66,6 @@ dmnsn_new_scene(dmnsn_pool *pool)
return scene;
}
-/* Free a scene */
-void
-dmnsn_delete_scene(dmnsn_scene *scene)
-{
- if (scene) {
- DMNSN_ARRAY_FOREACH (dmnsn_object **, object, scene->objects) {
- dmnsn_delete_object(*object);
- }
-
- dmnsn_delete_array(scene->lights);
- dmnsn_delete_array(scene->objects);
- dmnsn_delete_texture(scene->default_texture);
- dmnsn_delete_pigment(scene->background);
- }
-}
-
void
dmnsn_scene_initialize(dmnsn_scene *scene)
{
diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c
index 2906717..c6dc537 100644
--- a/libdimension/tests/render.c
+++ b/libdimension/tests/render.c
@@ -316,9 +316,13 @@ dmnsn_new_test_scene(dmnsn_pool *pool)
int
main(void)
{
+ int ret = EXIT_FAILURE;
+
/* Treat warnings as errors for tests */
dmnsn_die_on_warnings(true);
+ dmnsn_display *display = NULL;
+
/* Create the test scene */
dmnsn_pool *pool = dmnsn_new_pool();
dmnsn_scene *scene = dmnsn_new_test_scene(pool);
@@ -330,9 +334,8 @@ main(void)
if (errno == ENOSYS) {
have_png = false;
} else {
- dmnsn_delete_scene(scene);
fprintf(stderr, "--- Couldn't optimize canvas for PNG! ---\n");
- return EXIT_FAILURE;
+ goto exit;
}
}
@@ -343,16 +346,14 @@ main(void)
if (errno == ENOSYS) {
have_gl = false;
} else {
- dmnsn_delete_scene(scene);
fprintf(stderr, "--- Couldn't optimize canvas for GL! ---\n");
- return EXIT_FAILURE;
+ goto exit;
}
}
dmnsn_canvas_clear(scene->canvas, DMNSN_TCOLOR(dmnsn_black));
/* Create a new glX display */
- dmnsn_display *display = NULL;
if (have_gl) {
display = dmnsn_new_display(scene->canvas);
if (!display) {
@@ -370,10 +371,8 @@ main(void)
while (!dmnsn_future_is_done(future)) {
dmnsn_future_pause(future);
if (dmnsn_gl_write_canvas(scene->canvas) != 0) {
- dmnsn_delete_display(display);
- dmnsn_delete_scene(scene);
fprintf(stderr, "--- Drawing to OpenGL failed! ---\n");
- return EXIT_FAILURE;
+ goto exit;
}
dmnsn_future_resume(future);
@@ -382,20 +381,16 @@ main(void)
}
if (dmnsn_future_join(future) != 0) {
- dmnsn_delete_display(display);
- dmnsn_delete_scene(scene);
fprintf(stderr, "--- Raytracing failed! ---\n");
- return EXIT_FAILURE;
+ goto exit;
}
/* Make sure we show the completed rendering */
if (display) {
printf("Drawing to OpenGL\n");
if (dmnsn_gl_write_canvas(scene->canvas) != 0) {
- dmnsn_delete_display(display);
- dmnsn_delete_scene(scene);
fprintf(stderr, "--- Drawing to OpenGL failed! ---\n");
- return EXIT_FAILURE;
+ goto exit;
}
dmnsn_display_flush(display);
}
@@ -404,25 +399,22 @@ main(void)
printf("Writing scene to PNG\n");
FILE *ofile = fopen("render.png", "wb");
if (!ofile) {
- dmnsn_delete_display(display);
- dmnsn_delete_scene(scene);
fprintf(stderr, "--- Couldn't open 'render.png' for writing! ---\n");
- return EXIT_FAILURE;
+ goto exit;
}
if (dmnsn_png_write_canvas(scene->canvas, ofile) != 0) {
fclose(ofile);
- dmnsn_delete_display(display);
- dmnsn_delete_scene(scene);
fprintf(stderr, "--- Writing canvas to PNG failed! ---\n");
- return EXIT_FAILURE;
+ goto exit;
}
fclose(ofile);
}
+ ret = EXIT_SUCCESS;
+ exit:
dmnsn_delete_display(display);
- dmnsn_delete_scene(scene);
dmnsn_delete_pool(pool);
- return EXIT_SUCCESS;
+ return ret;
}