summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-05-30 18:20:51 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-05-30 18:21:04 -0400
commit57ee9bfb0dddba7ea06fd0e09c8aa2d80b8eb46d (patch)
treeb30dea9a9c82a7dcd47494cafcf43230dc05bed9 /libdimension
parentc2b4dcc7660407f687604afe2c03eff0a4ff3a16 (diff)
downloaddimension-57ee9bfb0dddba7ea06fd0e09c8aa2d80b8eb46d.tar.xz
light: Use pool.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/dimension/light.h22
-rw-r--r--libdimension/dimension/lights.h5
-rw-r--r--libdimension/light.c21
-rw-r--r--libdimension/point_light.c4
-rw-r--r--libdimension/scene.c3
-rw-r--r--libdimension/tests/render.c5
6 files changed, 14 insertions, 46 deletions
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;
}