diff options
-rw-r--r-- | libdimension-python/dimension.pxd | 5 | ||||
-rw-r--r-- | libdimension-python/dimension.pyx | 6 | ||||
-rw-r--r-- | libdimension/dimension/light.h | 22 | ||||
-rw-r--r-- | libdimension/dimension/lights.h | 5 | ||||
-rw-r--r-- | libdimension/light.c | 21 | ||||
-rw-r--r-- | libdimension/point_light.c | 4 | ||||
-rw-r--r-- | libdimension/scene.c | 3 | ||||
-rw-r--r-- | libdimension/tests/render.c | 5 |
8 files changed, 17 insertions, 54 deletions
diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd index 55c2ab8..55d47ab 100644 --- a/libdimension-python/dimension.pxd +++ b/libdimension-python/dimension.pxd @@ -360,10 +360,9 @@ cdef extern from "../libdimension/dimension.h": ctypedef struct dmnsn_light: dmnsn_vector x0 - dmnsn_light *dmnsn_new_light() - void dmnsn_delete_light(dmnsn_light *light) + dmnsn_light *dmnsn_new_light(dmnsn_pool *pool) - dmnsn_light *dmnsn_new_point_light(dmnsn_vector x0, dmnsn_color color) + dmnsn_light *dmnsn_new_point_light(dmnsn_pool *pool, dmnsn_vector x0, dmnsn_color color) ########### # Cameras # diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx index 28392db..da45f32 100644 --- a/libdimension-python/dimension.pyx +++ b/libdimension-python/dimension.pyx @@ -1415,9 +1415,6 @@ cdef class Light: """A light.""" cdef dmnsn_light *_light - def __dealloc__(self): - dmnsn_delete_light(self._light) - cdef class PointLight(Light): """A point light.""" def __init__(self, location, color): @@ -1428,7 +1425,7 @@ cdef class PointLight(Light): location -- the origin of the light rays color -- the color and intensity of the light """ - self._light = dmnsn_new_point_light(Vector(location)._v, Color(color)._c) + self._light = dmnsn_new_point_light(_get_pool(), Vector(location)._v, Color(color)._c) Light.__init__(self) ########### @@ -1521,7 +1518,6 @@ cdef class Scene: cdef dmnsn_light *l for light in lights: l = (<Light?>light)._light - DMNSN_INCREF(l) dmnsn_array_push(self._scene.lights, &l) self._scene.camera = camera._camera diff --git a/libdimension/dimension/light.h b/libdimension/dimension/light.h index aebb2d8..218611d 100644 --- a/libdimension/dimension/light.h +++ b/libdimension/dimension/light.h @@ -54,37 +54,23 @@ typedef dmnsn_color dmnsn_light_illumination_fn(const dmnsn_light *light, */ typedef bool dmnsn_light_shadow_fn(const dmnsn_light *light, double t); -/** - * Light destruction callback. - * @param[in,out] light The light to free. - */ -typedef void dmnsn_light_free_fn(dmnsn_light *light); - /** A light. */ struct dmnsn_light { /* Callbacks */ - dmnsn_light_direction_fn *direction_fn; /**< Direction callback. */ + dmnsn_light_direction_fn *direction_fn; /**< Direction callback. */ dmnsn_light_illumination_fn *illumination_fn; /**< Illumination callback. */ - dmnsn_light_shadow_fn *shadow_fn; /**< Shadow callback. */ - dmnsn_light_free_fn *free_fn; /**< Desctructor callback. */ - - DMNSN_REFCOUNT; /**< Reference count. */ + dmnsn_light_shadow_fn *shadow_fn; /**< Shadow callback. */ }; /** * Create a dummy light. + * @param[in] pool The memory pool to allocate from. * @return The allocated light. */ -dmnsn_light *dmnsn_new_light(void); +dmnsn_light *dmnsn_new_light(dmnsn_pool *pool); /** * Initialize a dmnsn_light field. * @param[out] light The light to initialize. */ void dmnsn_init_light(dmnsn_light *light); - -/** - * Delete a light. - * @param[in,out] light The light to delete. - */ -void dmnsn_delete_light(dmnsn_light *light); diff --git a/libdimension/dimension/lights.h b/libdimension/dimension/lights.h index 41ffad9..e7de4cc 100644 --- a/libdimension/dimension/lights.h +++ b/libdimension/dimension/lights.h @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes <tavianator@tavianator.com> * + * Copyright (C) 2009-2014 Tavian Barnes <tavianator@tavianator.com> * * * * This file is part of The Dimension Library. * * * @@ -25,8 +25,9 @@ /** * A point light. + * @param[in] pool The memory pool to allocate from. * @param[in] x0 The origin of the light. * @param[in] color The color of the light. * @return A point light. */ -dmnsn_light *dmnsn_new_point_light(dmnsn_vector x0, dmnsn_color color); +dmnsn_light *dmnsn_new_point_light(dmnsn_pool *pool, dmnsn_vector x0, dmnsn_color color); diff --git a/libdimension/light.c b/libdimension/light.c index daabe6f..b1d2108 100644 --- a/libdimension/light.c +++ b/libdimension/light.c @@ -26,17 +26,11 @@ #include "dimension-internal.h" #include <stdlib.h> -static void -dmnsn_default_light_free_fn(dmnsn_light *light) -{ - dmnsn_free(light); -} - /* Allocate a new dummy light */ dmnsn_light * -dmnsn_new_light(void) +dmnsn_new_light(dmnsn_pool *pool) { - dmnsn_light *light = DMNSN_MALLOC(dmnsn_light); + dmnsn_light *light = DMNSN_PALLOC(pool, dmnsn_light); dmnsn_init_light(light); return light; } @@ -48,15 +42,4 @@ dmnsn_init_light(dmnsn_light *light) light->direction_fn = NULL; light->illumination_fn = NULL; light->shadow_fn = NULL; - light->free_fn = dmnsn_default_light_free_fn; - DMNSN_REFCOUNT_INIT(light); -} - -/* Free a dummy light */ -void -dmnsn_delete_light(dmnsn_light *light) -{ - if (DMNSN_DECREF(light)) { - light->free_fn(light); - } } diff --git a/libdimension/point_light.c b/libdimension/point_light.c index 2f994b2..62857d8 100644 --- a/libdimension/point_light.c +++ b/libdimension/point_light.c @@ -57,9 +57,9 @@ dmnsn_point_light_shadow_fn(const dmnsn_light *light, double t) } dmnsn_light * -dmnsn_new_point_light(dmnsn_vector x0, dmnsn_color color) +dmnsn_new_point_light(dmnsn_pool *pool, dmnsn_vector x0, dmnsn_color color) { - dmnsn_point_light *point_light = DMNSN_MALLOC(dmnsn_point_light); + dmnsn_point_light *point_light = DMNSN_PALLOC(pool, dmnsn_point_light); point_light->origin = x0; point_light->color = color; diff --git a/libdimension/scene.c b/libdimension/scene.c index 59b4dc5..ea605e6 100644 --- a/libdimension/scene.c +++ b/libdimension/scene.c @@ -57,9 +57,6 @@ void dmnsn_delete_scene(dmnsn_scene *scene) { if (scene) { - DMNSN_ARRAY_FOREACH (dmnsn_light **, light, scene->lights) { - dmnsn_delete_light(*light); - } DMNSN_ARRAY_FOREACH (dmnsn_object **, object, scene->objects) { dmnsn_delete_object(*object); } diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c index c89a679..ebdc557 100644 --- a/libdimension/tests/render.c +++ b/libdimension/tests/render.c @@ -106,9 +106,10 @@ dmnsn_test_scene_add_background(dmnsn_pool *pool, dmnsn_scene *scene) } static void -dmnsn_test_scene_add_lights(dmnsn_scene *scene) +dmnsn_test_scene_add_lights(dmnsn_pool *pool, dmnsn_scene *scene) { dmnsn_light *light = dmnsn_new_point_light( + pool, dmnsn_new_vector(-15.0, 20.0, 10.0), dmnsn_white ); @@ -308,7 +309,7 @@ dmnsn_new_test_scene(dmnsn_pool *pool) dmnsn_test_scene_add_canvas(pool, 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_lights(pool, scene); dmnsn_test_scene_add_objects(scene); return scene; } |