summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-05-30 19:03:33 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-05-30 19:03:33 -0400
commit8807ab192b36acbc94e11790e9261c799ce77892 (patch)
tree7b37684cb5679c132d21f3bd8c2ff47a11e3df55 /libdimension
parent4781d3a2a7ec463ee712c8de6362d8b6c872c31b (diff)
downloaddimension-8807ab192b36acbc94e11790e9261c799ce77892.tar.xz
pattern: Use pool.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/checker.c6
-rw-r--r--libdimension/dimension/pattern.h20
-rw-r--r--libdimension/dimension/patterns.h11
-rw-r--r--libdimension/gradient.c4
-rw-r--r--libdimension/leopard.c6
-rw-r--r--libdimension/pattern.c24
-rw-r--r--libdimension/pigment_map.c1
-rw-r--r--libdimension/tests/render.c19
8 files changed, 27 insertions, 64 deletions
diff --git a/libdimension/checker.c b/libdimension/checker.c
index 2971a82..01b19f3 100644
--- a/libdimension/checker.c
+++ b/libdimension/checker.c
@@ -1,5 +1,5 @@
/*************************************************************************
- * Copyright (C) 2010 Tavian Barnes <tavianator@tavianator.com> *
+ * Copyright (C) 2010-2014 Tavian Barnes <tavianator@tavianator.com> *
* *
* This file is part of The Dimension Library. *
* *
@@ -54,12 +54,10 @@ dmnsn_checker_pattern_fn(const dmnsn_pattern *checker, dmnsn_vector v)
/** The singleton instance. */
static dmnsn_pattern dmnsn_checker_instance = {
.pattern_fn = dmnsn_checker_pattern_fn,
- DMNSN_REFCOUNT_INITIALIZER,
};
dmnsn_pattern *
-dmnsn_new_checker_pattern(void)
+dmnsn_new_checker_pattern(dmnsn_pool *pool)
{
- DMNSN_INCREF(&dmnsn_checker_instance);
return &dmnsn_checker_instance;
}
diff --git a/libdimension/dimension/pattern.h b/libdimension/dimension/pattern.h
index 6e8c42f..2caed07 100644
--- a/libdimension/dimension/pattern.h
+++ b/libdimension/dimension/pattern.h
@@ -35,25 +35,17 @@ typedef struct dmnsn_pattern dmnsn_pattern;
*/
typedef double dmnsn_pattern_fn(const dmnsn_pattern *pattern, dmnsn_vector v);
-/**
- * Pattern destruction callback.
- * @param[in,out] pattern The pattern to destroy.
- */
-typedef void dmnsn_pattern_free_fn(dmnsn_pattern *pattern);
-
/** A pattern. */
struct dmnsn_pattern {
dmnsn_pattern_fn *pattern_fn; /**< The pattern callback. */
- dmnsn_pattern_free_fn *free_fn; /**< The destructor callback. */
-
- DMNSN_REFCOUNT; /**< Reference count. */
};
/**
- * Allocate an dummy pattern.
+ * Allocate a dummy pattern.
+ * @param[in] pool The memory pool to allocate from.
* @return A pattern with no callbacks set.
*/
-dmnsn_pattern *dmnsn_new_pattern(void);
+dmnsn_pattern *dmnsn_new_pattern(dmnsn_pool *pool);
/**
* Initialize a dmnsn_pattern field.
@@ -62,12 +54,6 @@ dmnsn_pattern *dmnsn_new_pattern(void);
void dmnsn_init_pattern(dmnsn_pattern *pattern);
/**
- * Delete a pattern.
- * @param[in,out] pattern The pattern to destroy.
- */
-void dmnsn_delete_pattern(dmnsn_pattern *pattern);
-
-/**
* Invoke the pattern callback.
* @param[in] pattern The pattern to evaluate.
* @param[in] v The point to get the pattern value for.
diff --git a/libdimension/dimension/patterns.h b/libdimension/dimension/patterns.h
index c956b91..59b7fec 100644
--- a/libdimension/dimension/patterns.h
+++ b/libdimension/dimension/patterns.h
@@ -1,5 +1,5 @@
/*************************************************************************
- * Copyright (C) 2009-2011 Tavian Barnes <tavianator@tavianator.com> *
+ * Copyright (C) 2009-2014 Tavian Barnes <tavianator@tavianator.com> *
* *
* This file is part of The Dimension Library. *
* *
@@ -26,20 +26,23 @@
/**
* A checker pattern. The pattern is composed of tesselating unit cubes
* alternating between 0 and 1.
+ * @param[in] pool The memory pool to allocate from.
* @return A checker pattern.
*/
-dmnsn_pattern *dmnsn_new_checker_pattern(void);
+dmnsn_pattern *dmnsn_new_checker_pattern(dmnsn_pool *pool);
/**
* A gradient. The value starts at 0 at the origin, and goes linearly to 1 in
* the direction of \p orientation, then repeats after a distance of 1.
+ * @param[in] pool The memory pool to allocate from.
* @param[in] orientation The direction of the gradient.
* @return A gradient pattern.
*/
-dmnsn_pattern *dmnsn_new_gradient_pattern(dmnsn_vector orientation);
+dmnsn_pattern *dmnsn_new_gradient_pattern(dmnsn_pool *pool, dmnsn_vector orientation);
/**
* A leopard pattern.
+ * @param[in] pool The memory pool to allocate from.
* @return A leopard pattern.
*/
-dmnsn_pattern *dmnsn_new_leopard_pattern(void);
+dmnsn_pattern *dmnsn_new_leopard_pattern(dmnsn_pool *pool);
diff --git a/libdimension/gradient.c b/libdimension/gradient.c
index bdd6e86..2e28974 100644
--- a/libdimension/gradient.c
+++ b/libdimension/gradient.c
@@ -44,9 +44,9 @@ dmnsn_gradient_pattern_fn(const dmnsn_pattern *pattern, dmnsn_vector v)
}
dmnsn_pattern *
-dmnsn_new_gradient_pattern(dmnsn_vector orientation)
+dmnsn_new_gradient_pattern(dmnsn_pool *pool, dmnsn_vector orientation)
{
- dmnsn_gradient *gradient = DMNSN_MALLOC(dmnsn_gradient);
+ dmnsn_gradient *gradient = DMNSN_PALLOC(pool, dmnsn_gradient);
gradient->orientation = dmnsn_vector_normalized(orientation);
dmnsn_pattern *pattern = &gradient->pattern;
diff --git a/libdimension/leopard.c b/libdimension/leopard.c
index 072f032..110c69c 100644
--- a/libdimension/leopard.c
+++ b/libdimension/leopard.c
@@ -1,5 +1,5 @@
/*************************************************************************
- * Copyright (C) 2011 Tavian Barnes <tavianator@tavianator.com> *
+ * Copyright (C) 2011-2014 Tavian Barnes <tavianator@tavianator.com> *
* *
* This file is part of The Dimension Library. *
* *
@@ -37,12 +37,10 @@ dmnsn_leopard_pattern_fn(const dmnsn_pattern *leopard, dmnsn_vector v)
/** The singleton instance. */
static dmnsn_pattern dmnsn_leopard_instance = {
.pattern_fn = dmnsn_leopard_pattern_fn,
- DMNSN_REFCOUNT_INITIALIZER,
};
dmnsn_pattern *
-dmnsn_new_leopard_pattern(void)
+dmnsn_new_leopard_pattern(dmnsn_pool *pool)
{
- DMNSN_INCREF(&dmnsn_leopard_instance);
return &dmnsn_leopard_instance;
}
diff --git a/libdimension/pattern.c b/libdimension/pattern.c
index 56c7c48..22f5c13 100644
--- a/libdimension/pattern.c
+++ b/libdimension/pattern.c
@@ -25,39 +25,19 @@
#include "dimension-internal.h"
-static void
-dmnsn_default_pattern_free_fn(dmnsn_pattern *pattern)
-{
- dmnsn_free(pattern);
-}
-
-/* Allocate a dummy pattern */
dmnsn_pattern *
-dmnsn_new_pattern(void)
+dmnsn_new_pattern(dmnsn_pool *pool)
{
- dmnsn_pattern *pattern = DMNSN_MALLOC(dmnsn_pattern);
+ dmnsn_pattern *pattern = DMNSN_PALLOC(pool, dmnsn_pattern);
dmnsn_init_pattern(pattern);
return pattern;
}
-/* Initialize a pattern */
void
dmnsn_init_pattern(dmnsn_pattern *pattern)
{
- pattern->free_fn = dmnsn_default_pattern_free_fn;
- DMNSN_REFCOUNT_INIT(pattern);
-}
-
-/* Delete a pattern */
-void
-dmnsn_delete_pattern(dmnsn_pattern *pattern)
-{
- if (DMNSN_DECREF(pattern)) {
- pattern->free_fn(pattern);
- }
}
-/* Invoke the pattern callback with the right transformation */
double
dmnsn_pattern_value(const dmnsn_pattern *pattern, dmnsn_vector v)
{
diff --git a/libdimension/pigment_map.c b/libdimension/pigment_map.c
index a3e5dfd..6f07f15 100644
--- a/libdimension/pigment_map.c
+++ b/libdimension/pigment_map.c
@@ -63,7 +63,6 @@ dmnsn_pigment_map_free_fn(dmnsn_pigment *pigment)
{
dmnsn_pigment_map *pigment_map = (dmnsn_pigment_map *)pigment;
dmnsn_delete_map(pigment_map->map);
- dmnsn_delete_pattern(pigment_map->pattern);
dmnsn_free(pigment_map);
}
diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c
index 3c551da..4c230e1 100644
--- a/libdimension/tests/render.c
+++ b/libdimension/tests/render.c
@@ -71,7 +71,7 @@ dmnsn_test_scene_add_camera(dmnsn_pool *pool, dmnsn_scene *scene)
static void
dmnsn_test_scene_add_background(dmnsn_pool *pool, dmnsn_scene *scene)
{
- dmnsn_pattern *sky_gradient = dmnsn_new_gradient_pattern(dmnsn_y);
+ dmnsn_pattern *sky_gradient = dmnsn_new_gradient_pattern(pool, dmnsn_y);
dmnsn_map *sky_gradient_pigment_map = dmnsn_new_pigment_map();
dmnsn_canvas *png_canvas = NULL;
@@ -155,7 +155,7 @@ dmnsn_test_scene_add_hollow_cube(dmnsn_pool *pool, dmnsn_scene *scene)
} while (0)
static void
-dmnsn_test_scene_add_spike(dmnsn_scene *scene)
+dmnsn_test_scene_add_spike(dmnsn_pool *pool, dmnsn_scene *scene)
{
dmnsn_array *arrow_array = dmnsn_new_array(sizeof(dmnsn_object *));
@@ -172,7 +172,7 @@ dmnsn_test_scene_add_spike(dmnsn_scene *scene)
dmnsn_object *arrow = dmnsn_new_csg_union(arrow_array);
dmnsn_delete_array(arrow_array);
- dmnsn_pattern *gradient = dmnsn_new_gradient_pattern(dmnsn_y);
+ dmnsn_pattern *gradient = dmnsn_new_gradient_pattern(pool, dmnsn_y);
dmnsn_map *gradient_pigment_map = dmnsn_new_pigment_map();
dmnsn_pigment_map_add_color(gradient_pigment_map, 0.0, dmnsn_red);
dmnsn_pigment_map_add_color(gradient_pigment_map, 1.0/6.0, dmnsn_orange);
@@ -261,17 +261,16 @@ dmnsn_test_scene_add_triangle_strip(dmnsn_scene *scene)
}
static void
-dmnsn_test_scene_add_ground(dmnsn_scene *scene)
+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));
plane->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, -2.0, 0.0));
- dmnsn_pattern *checker1 = dmnsn_new_checker_pattern();
- dmnsn_pattern *checker2 = dmnsn_new_checker_pattern();
+ dmnsn_pattern *checker = dmnsn_new_checker_pattern(pool);
dmnsn_map *small_map = dmnsn_new_pigment_map();
dmnsn_pigment_map_add_color(small_map, 0.0, dmnsn_black);
dmnsn_pigment_map_add_color(small_map, 1.0, dmnsn_white);
dmnsn_pigment *small_pigment =
- dmnsn_new_pigment_map_pigment(checker1, small_map,
+ dmnsn_new_pigment_map_pigment(checker, small_map,
DMNSN_PIGMENT_MAP_REGULAR);
small_pigment->trans =
dmnsn_scale_matrix(dmnsn_new_vector(1.0/3.0, 1.0/3.0, 1.0/3.0));
@@ -280,7 +279,7 @@ dmnsn_test_scene_add_ground(dmnsn_scene *scene)
dmnsn_map_add_entry(big_map, 1.0, &small_pigment);
plane->texture = dmnsn_new_texture();
plane->texture->pigment =
- dmnsn_new_pigment_map_pigment(checker2, big_map, DMNSN_PIGMENT_MAP_REGULAR);
+ dmnsn_new_pigment_map_pigment(checker, big_map, DMNSN_PIGMENT_MAP_REGULAR);
plane->texture->pigment->quick_color = DMNSN_TCOLOR(
dmnsn_color_from_sRGB(
dmnsn_new_color(1.0, 0.5, 0.75)
@@ -293,9 +292,9 @@ static void
dmnsn_test_scene_add_objects(dmnsn_pool *pool, dmnsn_scene *scene)
{
dmnsn_test_scene_add_hollow_cube(pool, scene);
- dmnsn_test_scene_add_spike(scene);
+ dmnsn_test_scene_add_spike(pool, scene);
dmnsn_test_scene_add_triangle_strip(scene);
- dmnsn_test_scene_add_ground(scene);
+ dmnsn_test_scene_add_ground(pool, scene);
}
/*