summaryrefslogtreecommitdiffstats
path: root/libdimension/tests
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-05-31 15:34:59 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-05-31 15:34:59 -0400
commit180714c96505c53d380e2f205034f587cab0466d (patch)
tree62d1c654189abc715f2499e82345305417d31565 /libdimension/tests
parent74323fa54010d29737281579e4f3b4038da94989 (diff)
downloaddimension-180714c96505c53d380e2f205034f587cab0466d.tar.xz
object: Use pool.
Diffstat (limited to 'libdimension/tests')
-rw-r--r--libdimension/tests/prtree.c11
-rw-r--r--libdimension/tests/render.c28
2 files changed, 19 insertions, 20 deletions
diff --git a/libdimension/tests/prtree.c b/libdimension/tests/prtree.c
index 5c377e2..a7db68e 100644
--- a/libdimension/tests/prtree.c
+++ b/libdimension/tests/prtree.c
@@ -64,11 +64,13 @@ main(void)
/* Treat warnings as errors for tests */
dmnsn_die_on_warnings(true);
+ dmnsn_pool *pool = dmnsn_new_pool();
+
const size_t nobjects = 128;
- dmnsn_array *objects = DMNSN_NEW_ARRAY(dmnsn_object *);
+ dmnsn_array *objects = DMNSN_PALLOC_ARRAY(pool, dmnsn_object *);
for (size_t i = 0; i < nobjects; ++i) {
- dmnsn_object *object = dmnsn_new_object();
+ dmnsn_object *object = dmnsn_new_object(pool);
dmnsn_randomize_bounding_box(object);
object->intersection_fn = dmnsn_fake_intersection_fn;
object->trans_inv = dmnsn_identity_matrix();
@@ -96,9 +98,6 @@ main(void)
}
dmnsn_delete_bvh(bvh);
- DMNSN_ARRAY_FOREACH (dmnsn_object **, object, objects) {
- dmnsn_delete_object(*object);
- }
- dmnsn_delete_array(objects);
+ dmnsn_delete_pool(pool);
return EXIT_SUCCESS;
}
diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c
index d093947..f12aa8b 100644
--- a/libdimension/tests/render.c
+++ b/libdimension/tests/render.c
@@ -118,7 +118,7 @@ dmnsn_test_scene_add_lights(dmnsn_pool *pool, dmnsn_scene *scene)
static void
dmnsn_test_scene_add_hollow_cube(dmnsn_pool *pool, dmnsn_scene *scene)
{
- dmnsn_object *cube = dmnsn_new_cube();
+ dmnsn_object *cube = dmnsn_new_cube(pool);
cube->trans = dmnsn_rotation_matrix(
dmnsn_new_vector(dmnsn_radians(45.0), 0.0, 0.0)
);
@@ -133,13 +133,13 @@ dmnsn_test_scene_add_hollow_cube(dmnsn_pool *pool, dmnsn_scene *scene)
cube->interior = dmnsn_new_interior(pool);
cube->interior->ior = 1.1;
- dmnsn_object *sphere = dmnsn_new_sphere();
+ dmnsn_object *sphere = dmnsn_new_sphere(pool);
sphere->texture = dmnsn_new_texture(pool);
sphere->texture->pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_green));
sphere->texture->finish.specular = dmnsn_new_phong(pool, dmnsn_sRGB_inverse_gamma(0.2), 40.0);
sphere->trans = dmnsn_scale_matrix(dmnsn_new_vector(1.25, 1.25, 1.25));
- dmnsn_object *hollow_cube = dmnsn_new_csg_difference(cube, sphere);
+ dmnsn_object *hollow_cube = dmnsn_new_csg_difference(pool, cube, sphere);
dmnsn_array_push(scene->objects, &hollow_cube);
}
@@ -155,18 +155,18 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene)
{
dmnsn_array *arrow_array = DMNSN_NEW_ARRAY(dmnsn_object *);
- dmnsn_object *cylinder = dmnsn_new_cone(0.1, 0.1, false);
+ dmnsn_object *cylinder = dmnsn_new_cone(pool, 0.1, 0.1, false);
cylinder->trans = dmnsn_scale_matrix(dmnsn_new_vector(1.0, 1.25, 1.0));
dmnsn_array_push(arrow_array, &cylinder);
- dmnsn_object *cone = dmnsn_new_cone(0.1, 0.0, true);
+ dmnsn_object *cone = dmnsn_new_cone(pool, 0.1, 0.0, true);
cone->trans = dmnsn_matrix_mul(
dmnsn_translation_matrix(dmnsn_new_vector(0.0, 1.375, 0.0)),
dmnsn_scale_matrix(dmnsn_new_vector(1.0, 0.125, 1.0))
);
dmnsn_array_push(arrow_array, &cone);
- dmnsn_object *arrow = dmnsn_new_csg_union(arrow_array);
+ dmnsn_object *arrow = dmnsn_new_csg_union(pool, arrow_array);
dmnsn_delete_array(arrow_array);
dmnsn_pattern *gradient = dmnsn_new_gradient_pattern(pool, dmnsn_y);
dmnsn_map *gradient_pigment_map = dmnsn_new_pigment_map(pool);
@@ -190,18 +190,18 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene)
dmnsn_array *torus_array = DMNSN_NEW_ARRAY(dmnsn_object *);
- dmnsn_object *torus1 = dmnsn_new_torus(0.15, 0.05);
+ dmnsn_object *torus1 = dmnsn_new_torus(pool, 0.15, 0.05);
torus1->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, -1.0, 0.0));
dmnsn_array_push(torus_array, &torus1);
- dmnsn_object *torus2 = dmnsn_new_torus(0.15, 0.05);
+ dmnsn_object *torus2 = dmnsn_new_torus(pool, 0.15, 0.05);
dmnsn_array_push(torus_array, &torus2);
- dmnsn_object *torus3 = dmnsn_new_torus(0.15, 0.05);
+ dmnsn_object *torus3 = dmnsn_new_torus(pool, 0.15, 0.05);
torus3->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, 1.0, 0.0));
dmnsn_array_push(torus_array, &torus3);
- dmnsn_object *torii = dmnsn_new_csg_union(torus_array);
+ dmnsn_object *torii = dmnsn_new_csg_union(pool, torus_array);
dmnsn_delete_array(torus_array);
torii->texture = dmnsn_new_texture(pool);
torii->texture->pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_blue));
@@ -210,7 +210,7 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene)
dmnsn_array *spike_array = DMNSN_NEW_ARRAY(dmnsn_object *);
dmnsn_array_push(spike_array, &arrow);
dmnsn_array_push(spike_array, &torii);
- dmnsn_object *spike = dmnsn_new_csg_union(spike_array);
+ dmnsn_object *spike = dmnsn_new_csg_union(pool, spike_array);
dmnsn_delete_array(spike_array);
spike->trans = dmnsn_rotation_matrix(
dmnsn_new_vector(dmnsn_radians(-45.0), 0.0, 0.0)
@@ -234,7 +234,7 @@ dmnsn_test_scene_add_triangle_strip(dmnsn_pool *pool, dmnsn_scene *scene)
strip_textures[1]->pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_orange));
strip_textures[2]->pigment = dmnsn_new_solid_pigment(pool, DMNSN_TCOLOR(dmnsn_yellow));
for (unsigned int i = 0; i < 128; ++i) {
- dmnsn_object *triangle = dmnsn_new_flat_triangle(a, b, c);
+ dmnsn_object *triangle = dmnsn_new_flat_triangle(pool, a, b, c);
triangle->texture = strip_textures[i%3];
dmnsn_array_push(strip_array, &triangle);
@@ -243,7 +243,7 @@ dmnsn_test_scene_add_triangle_strip(dmnsn_pool *pool, dmnsn_scene *scene)
c = dmnsn_vector_add(a, dmnsn_z);
}
- dmnsn_object *strip = dmnsn_new_csg_union(strip_array);
+ dmnsn_object *strip = dmnsn_new_csg_union(pool, strip_array);
dmnsn_delete_array(strip_array);
strip->trans = dmnsn_translation_matrix(dmnsn_new_vector(5.0, -2.0, -4.0));
dmnsn_array_push(scene->objects, &strip);
@@ -252,7 +252,7 @@ dmnsn_test_scene_add_triangle_strip(dmnsn_pool *pool, dmnsn_scene *scene)
static void
dmnsn_test_scene_add_ground(dmnsn_pool *pool, dmnsn_scene *scene)
{
- dmnsn_object *plane = dmnsn_new_plane(dmnsn_new_vector(0.0, 1.0, 0.0));
+ dmnsn_object *plane = dmnsn_new_plane(pool, dmnsn_new_vector(0.0, 1.0, 0.0));
plane->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, -2.0, 0.0));
dmnsn_pattern *checker = dmnsn_new_checker_pattern(pool);
dmnsn_map *small_map = dmnsn_new_pigment_map(pool);