From c2b4dcc7660407f687604afe2c03eff0a4ff3a16 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 30 May 2014 17:42:14 -0400 Subject: camera: Use pool. --- libdimension-python/dimension.pxd | 6 ++---- libdimension-python/dimension.pyx | 6 +----- libdimension/camera.c | 20 ++------------------ libdimension/dimension/camera.h | 18 ++---------------- libdimension/dimension/cameras.h | 5 +++-- libdimension/perspective.c | 4 ++-- libdimension/scene.c | 1 - libdimension/tests/render.c | 6 +++--- 8 files changed, 15 insertions(+), 51 deletions(-) diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd index 6b5c77f..55c2ab8 100644 --- a/libdimension-python/dimension.pxd +++ b/libdimension-python/dimension.pxd @@ -204,7 +204,6 @@ cdef extern from "../libdimension/dimension.h": size_t height dmnsn_canvas *dmnsn_new_canvas(dmnsn_pool *pool, size_t width, size_t height) - void dmnsn_delete_canvas(dmnsn_canvas *canvas) dmnsn_tcolor dmnsn_canvas_get_pixel(dmnsn_canvas *canvas, size_t x, size_t y) void dmnsn_canvas_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y, @@ -373,10 +372,9 @@ cdef extern from "../libdimension/dimension.h": ctypedef struct dmnsn_camera: dmnsn_matrix trans - dmnsn_camera *dmnsn_new_camera() - void dmnsn_delete_camera(dmnsn_camera *camera) + dmnsn_camera *dmnsn_new_camera(dmnsn_pool *pool) - dmnsn_camera *dmnsn_new_perspective_camera() + dmnsn_camera *dmnsn_new_perspective_camera(dmnsn_pool *pool) ########## # Scenes # diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx index 79e4014..28392db 100644 --- a/libdimension-python/dimension.pyx +++ b/libdimension-python/dimension.pyx @@ -1446,9 +1446,6 @@ cdef class Camera(_Transformable): if self._camera == NULL: raise TypeError("attempt to initialize base Camera") - def __dealloc__(self): - dmnsn_delete_camera(self._camera) - def transform(self, Matrix trans not None): """Transform a camera.""" self._camera.trans = dmnsn_matrix_mul(trans._m, self._camera.trans) @@ -1467,7 +1464,7 @@ cdef class PerspectiveCamera(Camera): sky -- the direction of the top of the camera (default: Y) angle -- the field of view angle (from bottom to top) (default: 45) """ - self._camera = dmnsn_new_perspective_camera() + self._camera = dmnsn_new_perspective_camera(_get_pool()) Camera.__init__(self) # Apply the field of view angle @@ -1528,7 +1525,6 @@ cdef class Scene: dmnsn_array_push(self._scene.lights, &l) self._scene.camera = camera._camera - DMNSN_INCREF(self._scene.camera) # Subregion render support property region_x: diff --git a/libdimension/camera.c b/libdimension/camera.c index 38fde35..3db9f2c 100644 --- a/libdimension/camera.c +++ b/libdimension/camera.c @@ -26,16 +26,11 @@ #include "dimension-internal.h" #include -static void dmnsn_default_camera_free_fn(dmnsn_camera *camera) -{ - dmnsn_free(camera); -} - /* Allocate a new dummy camera */ dmnsn_camera * -dmnsn_new_camera(void) +dmnsn_new_camera(dmnsn_pool *pool) { - dmnsn_camera *camera = DMNSN_MALLOC(dmnsn_camera); + dmnsn_camera *camera = DMNSN_PALLOC(pool, dmnsn_camera); dmnsn_init_camera(camera); return camera; } @@ -44,18 +39,7 @@ dmnsn_new_camera(void) void dmnsn_init_camera(dmnsn_camera *camera) { - camera->free_fn = dmnsn_default_camera_free_fn; camera->trans = dmnsn_identity_matrix(); - DMNSN_REFCOUNT_INIT(camera); -} - -/* Free a dummy camera */ -void -dmnsn_delete_camera(dmnsn_camera *camera) -{ - if (DMNSN_DECREF(camera)) { - camera->free_fn(camera); - } } /* Invoke the camera ray function */ diff --git a/libdimension/dimension/camera.h b/libdimension/dimension/camera.h index e94e227..3c6494c 100644 --- a/libdimension/dimension/camera.h +++ b/libdimension/dimension/camera.h @@ -36,28 +36,20 @@ typedef struct dmnsn_camera dmnsn_camera; typedef dmnsn_line dmnsn_camera_ray_fn(const dmnsn_camera *camera, double x, double y); -/** - * Camera destruction callback. - * @param[in,out] camera The camera to delete. - */ -typedef void dmnsn_camera_free_fn(dmnsn_camera *camera); - /** A camera. */ struct dmnsn_camera { /* Callback functions */ dmnsn_camera_ray_fn *ray_fn; /**< Camera ray callback. */ - dmnsn_camera_free_fn *free_fn; /**< Destructor callback. */ dmnsn_matrix trans; /**< Transformation matrix. */ - - DMNSN_REFCOUNT; /**< Reference count. */ }; /** * Create a dummy camera. + * @param[in] pool The memory pool to allocate from. * @return The allocated camera. */ -dmnsn_camera *dmnsn_new_camera(void); +dmnsn_camera *dmnsn_new_camera(dmnsn_pool *pool); /** * Initialize a dmnsn_camera field. @@ -65,12 +57,6 @@ dmnsn_camera *dmnsn_new_camera(void); */ void dmnsn_init_camera(dmnsn_camera *camera); -/** - * Delete a camera. - * @param[in,out] camera The camera to delete. - */ -void dmnsn_delete_camera(dmnsn_camera *camera); - /** * Invoke the camera ray callback, then correctly transform the ray. * @param[in] camera The camera itself. diff --git a/libdimension/dimension/cameras.h b/libdimension/dimension/cameras.h index d7f44b2..9ef2646 100644 --- a/libdimension/dimension/cameras.h +++ b/libdimension/dimension/cameras.h @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * + * Copyright (C) 2009-2014 Tavian Barnes * * * * This file is part of The Dimension Library. * * * @@ -28,6 +28,7 @@ * (0, 0, 1). The feild of view is the section of the plane z = 1 from * (-0.5, -0.5) to (0.5, 0.5). Rays are transformed by the camera's * transformation matrix. + * @param[in] pool The memory pool to allocate from. * @return A perspective camera. */ -dmnsn_camera *dmnsn_new_perspective_camera(void); +dmnsn_camera *dmnsn_new_perspective_camera(dmnsn_pool *pool); diff --git a/libdimension/perspective.c b/libdimension/perspective.c index 10b7c18..a87f673 100644 --- a/libdimension/perspective.c +++ b/libdimension/perspective.c @@ -39,9 +39,9 @@ dmnsn_perspective_camera_ray_fn(const dmnsn_camera *camera, double x, double y) /* Create a new perspective camera. */ dmnsn_camera * -dmnsn_new_perspective_camera(void) +dmnsn_new_perspective_camera(dmnsn_pool *pool) { - dmnsn_camera *camera = dmnsn_new_camera(); + dmnsn_camera *camera = dmnsn_new_camera(pool); camera->ray_fn = dmnsn_perspective_camera_ray_fn; return camera; } diff --git a/libdimension/scene.c b/libdimension/scene.c index cc2ee98..59b4dc5 100644 --- a/libdimension/scene.c +++ b/libdimension/scene.c @@ -66,7 +66,6 @@ dmnsn_delete_scene(dmnsn_scene *scene) dmnsn_delete_array(scene->lights); dmnsn_delete_array(scene->objects); - dmnsn_delete_camera(scene->camera); dmnsn_delete_interior(scene->default_interior); dmnsn_delete_texture(scene->default_texture); dmnsn_delete_pigment(scene->background); diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c index f5ba685..c89a679 100644 --- a/libdimension/tests/render.c +++ b/libdimension/tests/render.c @@ -42,7 +42,7 @@ dmnsn_test_scene_add_canvas(dmnsn_pool *pool, dmnsn_scene *scene) } static void -dmnsn_test_scene_add_camera(dmnsn_scene *scene) +dmnsn_test_scene_add_camera(dmnsn_pool *pool, dmnsn_scene *scene) { /* Set up the transformation matrix for the perspective camera */ dmnsn_matrix trans = dmnsn_scale_matrix( @@ -64,7 +64,7 @@ dmnsn_test_scene_add_camera(dmnsn_scene *scene) ); /* Create a perspective camera */ - scene->camera = dmnsn_new_perspective_camera(); + scene->camera = dmnsn_new_perspective_camera(pool); scene->camera->trans = trans; } @@ -306,7 +306,7 @@ dmnsn_new_test_scene(dmnsn_pool *pool) dmnsn_scene *scene = dmnsn_new_scene(pool); dmnsn_test_scene_set_defaults(scene); dmnsn_test_scene_add_canvas(pool, scene); - dmnsn_test_scene_add_camera(scene); + dmnsn_test_scene_add_camera(pool, scene); dmnsn_test_scene_add_background(pool, scene); dmnsn_test_scene_add_lights(scene); dmnsn_test_scene_add_objects(scene); -- cgit v1.2.3