summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-05-31 12:32:24 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-05-31 12:32:24 -0400
commitc9c85a530402541518dd585de682bb0ecdf7cf7b (patch)
tree80bc7eede025cd98983c0bcb271859ceed30fa1f /libdimension
parent1de647b9d38528b640f8da473d50c04ef0674c58 (diff)
downloaddimension-c9c85a530402541518dd585de682bb0ecdf7cf7b.tar.xz
array: Add DMNSN_NEW_ARRAY macro.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/bench/prtree.c4
-rw-r--r--libdimension/bvh.c6
-rw-r--r--libdimension/canvas.c2
-rw-r--r--libdimension/cone.c2
-rw-r--r--libdimension/dictionary.c2
-rw-r--r--libdimension/dimension/array.h9
-rw-r--r--libdimension/object.c2
-rw-r--r--libdimension/prtree.c4
-rw-r--r--libdimension/scene.c4
-rw-r--r--libdimension/tests/prtree.c2
-rw-r--r--libdimension/tests/render.c8
11 files changed, 26 insertions, 19 deletions
diff --git a/libdimension/bench/prtree.c b/libdimension/bench/prtree.c
index 11d831b..f05f04c 100644
--- a/libdimension/bench/prtree.c
+++ b/libdimension/bench/prtree.c
@@ -1,5 +1,5 @@
/*************************************************************************
- * Copyright (C) 2009-2012 Tavian Barnes <tavianator@tavianator.com> *
+ * Copyright (C) 2009-2014 Tavian Barnes <tavianator@tavianator.com> *
* *
* This file is part of The Dimension Benchmark Suite. *
* *
@@ -79,7 +79,7 @@ main(void)
return EXIT_FAILURE;
}
- dmnsn_array *objects = dmnsn_new_array(sizeof(dmnsn_object *));
+ dmnsn_array *objects = DMNSN_NEW_ARRAY(dmnsn_object *);
dmnsn_texture *texture = dmnsn_new_texture();
texture->pigment = dmnsn_new_pigment();
for (size_t i = 0; i < nobjects; ++i) {
diff --git a/libdimension/bvh.c b/libdimension/bvh.c
index 972401e..0a31662 100644
--- a/libdimension/bvh.c
+++ b/libdimension/bvh.c
@@ -70,7 +70,7 @@ dmnsn_split_add_object(dmnsn_array *objects, const dmnsn_object *object)
static dmnsn_array *
dmnsn_split_objects(const dmnsn_array *objects)
{
- dmnsn_array *split = dmnsn_new_array(sizeof(dmnsn_object *));
+ dmnsn_array *split = DMNSN_NEW_ARRAY(dmnsn_object *);
DMNSN_ARRAY_FOREACH (const dmnsn_object **, object, objects) {
dmnsn_split_add_object(split, *object);
}
@@ -81,7 +81,7 @@ dmnsn_split_objects(const dmnsn_array *objects)
static dmnsn_array *
dmnsn_split_unbounded(dmnsn_array *objects)
{
- dmnsn_array *unbounded = dmnsn_new_array(sizeof(dmnsn_object *));
+ dmnsn_array *unbounded = DMNSN_NEW_ARRAY(dmnsn_object *);
dmnsn_object **array = dmnsn_array_first(objects);
size_t i, skip;
@@ -122,7 +122,7 @@ dmnsn_flatten_bvh_recursive(dmnsn_bvh_node *node, dmnsn_array *flat)
static dmnsn_array *
dmnsn_flatten_bvh(dmnsn_bvh_node *root)
{
- dmnsn_array *flat = dmnsn_new_array(sizeof(dmnsn_flat_bvh_node));
+ dmnsn_array *flat = DMNSN_NEW_ARRAY(dmnsn_flat_bvh_node);
if (root) {
dmnsn_flatten_bvh_recursive(root, flat);
}
diff --git a/libdimension/canvas.c b/libdimension/canvas.c
index e290910..a86a48a 100644
--- a/libdimension/canvas.c
+++ b/libdimension/canvas.c
@@ -34,7 +34,7 @@ dmnsn_new_canvas(dmnsn_pool *pool, size_t width, size_t height)
dmnsn_canvas *canvas = DMNSN_PALLOC_TIDY(pool, dmnsn_canvas, dmnsn_canvas_cleanup);
canvas->width = width;
canvas->height = height;
- canvas->optimizers = dmnsn_new_array(sizeof(dmnsn_canvas_optimizer));
+ canvas->optimizers = DMNSN_NEW_ARRAY(dmnsn_canvas_optimizer);
canvas->pixels = dmnsn_malloc(sizeof(dmnsn_tcolor)*width*height);
return canvas;
}
diff --git a/libdimension/cone.c b/libdimension/cone.c
index d0ae28e..2e52751 100644
--- a/libdimension/cone.c
+++ b/libdimension/cone.c
@@ -171,7 +171,7 @@ dmnsn_new_cone(double r1, double r2, bool open)
/* Flip the normal around for the top cap */
cap2->intrinsic_trans.n[1][1] = -1.0;
- dmnsn_array *withcaps = dmnsn_new_array(sizeof(dmnsn_object *));
+ dmnsn_array *withcaps = DMNSN_NEW_ARRAY(dmnsn_object *);
dmnsn_array_push(withcaps, &cone);
dmnsn_array_push(withcaps, &cap1);
dmnsn_array_push(withcaps, &cap2);
diff --git a/libdimension/dictionary.c b/libdimension/dictionary.c
index 3264a3c..4001d2f 100644
--- a/libdimension/dictionary.c
+++ b/libdimension/dictionary.c
@@ -39,7 +39,7 @@ dmnsn_new_dictionary(size_t obj_size)
dict->obj_size = obj_size;
dict->prefix = dmnsn_strdup("");
dict->value = NULL;
- dict->children = dmnsn_new_array(sizeof(dmnsn_dictionary *));
+ dict->children = DMNSN_NEW_ARRAY(dmnsn_dictionary *);
return dict;
}
diff --git a/libdimension/dimension/array.h b/libdimension/dimension/array.h
index e0a0f08..6a8249f 100644
--- a/libdimension/dimension/array.h
+++ b/libdimension/dimension/array.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. *
* *
@@ -55,6 +55,13 @@ dmnsn_new_array(size_t obj_size)
}
/**
+ * Allocate an array.
+ * @param[in] type Type type of element to store in the array.
+ * @return An empty array.
+ */
+#define DMNSN_NEW_ARRAY(type) (dmnsn_new_array(sizeof(type)))
+
+/**
* Delete an array.
* @param[in,out] array The array to delete.
*/
diff --git a/libdimension/object.c b/libdimension/object.c
index bf84cfe..7b6bb73 100644
--- a/libdimension/object.c
+++ b/libdimension/object.c
@@ -49,7 +49,7 @@ dmnsn_init_object(dmnsn_object *object)
object->interior = NULL;
object->trans = dmnsn_identity_matrix();
object->intrinsic_trans = dmnsn_identity_matrix();
- object->children = dmnsn_new_array(sizeof(dmnsn_object *));
+ object->children = DMNSN_NEW_ARRAY(dmnsn_object *);
object->split_children = false;
object->intersection_fn = NULL;
object->inside_fn = NULL;
diff --git a/libdimension/prtree.c b/libdimension/prtree.c
index a726982..b4b9e82 100644
--- a/libdimension/prtree.c
+++ b/libdimension/prtree.c
@@ -317,7 +317,7 @@ dmnsn_priority_leaves(const dmnsn_array *leaves, unsigned int nthreads)
size_t buffer_size = nleaves/2;
dmnsn_bvh_node **buffer = dmnsn_malloc(buffer_size*sizeof(dmnsn_bvh_node *));
- dmnsn_array *new_leaves = dmnsn_new_array(sizeof(dmnsn_bvh_node *));
+ dmnsn_array *new_leaves = DMNSN_NEW_ARRAY(dmnsn_bvh_node *);
dmnsn_priority_leaves_recursive(sorted_leaves, nleaves, buffer, new_leaves,
0);
@@ -338,7 +338,7 @@ dmnsn_new_prtree(const dmnsn_array *objects)
}
/* Make the initial array of leaves */
- dmnsn_array *leaves = dmnsn_new_array(sizeof(dmnsn_bvh_node *));
+ dmnsn_array *leaves = DMNSN_NEW_ARRAY(dmnsn_bvh_node *);
DMNSN_ARRAY_FOREACH (dmnsn_object **, object, objects) {
dmnsn_bvh_node *node = dmnsn_new_bvh_leaf_node(*object);
node->data = DMNSN_PRTREE_LEFT; /* Mustn't be _LEAF */
diff --git a/libdimension/scene.c b/libdimension/scene.c
index 610b8f9..3a73c48 100644
--- a/libdimension/scene.c
+++ b/libdimension/scene.c
@@ -54,8 +54,8 @@ dmnsn_new_scene(dmnsn_pool *pool)
scene->region_y = 0;
scene->outer_width = 0;
scene->outer_height = 0;
- scene->objects = dmnsn_new_array(sizeof(dmnsn_object *));
- scene->lights = dmnsn_new_array(sizeof(dmnsn_light *));
+ scene->objects = DMNSN_NEW_ARRAY(dmnsn_object *);
+ scene->lights = DMNSN_NEW_ARRAY(dmnsn_light *);
scene->camera = NULL;
scene->quality = DMNSN_RENDER_FULL;
scene->reclimit = 5;
diff --git a/libdimension/tests/prtree.c b/libdimension/tests/prtree.c
index b2a2be6..5c377e2 100644
--- a/libdimension/tests/prtree.c
+++ b/libdimension/tests/prtree.c
@@ -65,7 +65,7 @@ main(void)
dmnsn_die_on_warnings(true);
const size_t nobjects = 128;
- dmnsn_array *objects = dmnsn_new_array(sizeof(dmnsn_object *));
+ dmnsn_array *objects = DMNSN_NEW_ARRAY(dmnsn_object *);
for (size_t i = 0; i < nobjects; ++i) {
dmnsn_object *object = dmnsn_new_object();
diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c
index c6dc537..3a5f134 100644
--- a/libdimension/tests/render.c
+++ b/libdimension/tests/render.c
@@ -157,7 +157,7 @@ dmnsn_test_scene_add_hollow_cube(dmnsn_pool *pool, dmnsn_scene *scene)
static void
dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene)
{
- dmnsn_array *arrow_array = dmnsn_new_array(sizeof(dmnsn_object *));
+ dmnsn_array *arrow_array = DMNSN_NEW_ARRAY(dmnsn_object *);
dmnsn_object *cylinder = dmnsn_new_cone(0.1, 0.1, false);
cylinder->trans = dmnsn_scale_matrix(dmnsn_new_vector(1.0, 1.25, 1.0));
@@ -192,7 +192,7 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene)
dmnsn_scale_matrix(dmnsn_new_vector(1.0, 2.75, 1.0))
);
- dmnsn_array *torus_array = dmnsn_new_array(sizeof(dmnsn_object *));
+ dmnsn_array *torus_array = DMNSN_NEW_ARRAY(dmnsn_object *);
dmnsn_object *torus1 = dmnsn_new_torus(0.15, 0.05);
torus1->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, -1.0, 0.0));
@@ -211,7 +211,7 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene)
torii->texture->pigment = dmnsn_new_solid_pigment(DMNSN_TCOLOR(dmnsn_blue));
torii->texture->finish.ambient = dmnsn_new_ambient(dmnsn_white);
- dmnsn_array *spike_array = dmnsn_new_array(sizeof(dmnsn_object *));
+ 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);
@@ -225,7 +225,7 @@ dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene)
static void
dmnsn_test_scene_add_triangle_strip(dmnsn_scene *scene)
{
- dmnsn_array *strip_array = dmnsn_new_array(sizeof(dmnsn_object *));
+ dmnsn_array *strip_array = DMNSN_NEW_ARRAY(dmnsn_object *);
dmnsn_vector a = dmnsn_zero;
dmnsn_vector b = dmnsn_new_vector(0.0, sqrt(3.0)/2.0, 0.5);
dmnsn_vector c = dmnsn_z;