diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-10-19 13:59:24 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-10-30 18:11:22 -0400 |
commit | 8e3a7158ecae541692826e7b5998c8ffc810173a (patch) | |
tree | beda4f9f8604f77d0513d5fb02b7ddf53d203d09 | |
parent | e9810a7b1aae15320e58371b657a2f963562834d (diff) | |
download | dimension-8e3a7158ecae541692826e7b5998c8ffc810173a.tar.xz |
Make API more consistent.
Object methods should be dmnsn_<object>_<fn>().
43 files changed, 215 insertions, 182 deletions
diff --git a/dimension/dimension.in b/dimension/dimension.in index 0ea41e4..cd2e82d 100644 --- a/dimension/dimension.in +++ b/dimension/dimension.in @@ -209,12 +209,12 @@ if args.adc_bailout is not None: args.adc_bailout = float(match.group(1))/float(match.group(2)) scene.adc_bailout = float(args.adc_bailout) -# Raytrace the scene +# Ray-trace the scene if scene.nthreads == 1: render_message = "Rendering scene" else: render_message = "Rendering scene (using %d threads)" % scene.nthreads -progress_bar(render_message, scene.raytrace_async()) +progress_bar(render_message, scene.ray_trace_async()) # Write the output file export_timer = Timer() diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd index 403b327..7ba17e9 100644 --- a/libdimension-python/dimension.pxd +++ b/libdimension-python/dimension.pxd @@ -84,8 +84,8 @@ cdef extern from "../libdimension/dimension.h": double user double system - void dmnsn_start_timer(dmnsn_timer *timer) - void dmnsn_stop_timer(dmnsn_timer *timer) + void dmnsn_timer_start(dmnsn_timer *timer) + void dmnsn_timer_stop(dmnsn_timer *timer) ############ # Geometry # @@ -186,11 +186,11 @@ cdef extern from "../libdimension/dimension.h": dmnsn_canvas *dmnsn_new_canvas(size_t width, size_t height) void dmnsn_delete_canvas(dmnsn_canvas *canvas) - dmnsn_color dmnsn_get_pixel(dmnsn_canvas *canvas, size_t x, size_t y) - void dmnsn_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y, - dmnsn_color color) + dmnsn_color dmnsn_canvas_get_pixel(dmnsn_canvas *canvas, size_t x, size_t y) + void dmnsn_canvas_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y, + dmnsn_color color) - void dmnsn_clear_canvas(dmnsn_canvas *canvas, dmnsn_color color) + void dmnsn_canvas_clear(dmnsn_canvas *canvas, dmnsn_color color) int dmnsn_png_optimize_canvas(dmnsn_canvas *canvas) int dmnsn_png_write_canvas(dmnsn_canvas *canvas, FILE *file) @@ -223,7 +223,7 @@ cdef extern from "../libdimension/dimension.h": void dmnsn_delete_map(dmnsn_map *map) - void dmnsn_add_map_entry(dmnsn_map *map, double n, void *obj) + void dmnsn_map_add_entry(dmnsn_map *map, double n, void *obj) size_t dmnsn_map_size(dmnsn_map *map) dmnsn_map *dmnsn_new_pigment_map() @@ -390,8 +390,8 @@ cdef extern from "../libdimension/dimension.h": dmnsn_scene *dmnsn_new_scene() void dmnsn_delete_scene(dmnsn_scene *scene) - void dmnsn_raytrace_scene(dmnsn_scene *scene) - dmnsn_future *dmnsn_raytrace_scene_async(dmnsn_scene *scene) + void dmnsn_ray_trace(dmnsn_scene *scene) + dmnsn_future *dmnsn_ray_trace_async(dmnsn_scene *scene) cdef extern from "platform.h": unsigned int dmnsn_terminal_width() diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx index 7f9fda0..738a63f 100644 --- a/libdimension-python/dimension.pyx +++ b/libdimension-python/dimension.pyx @@ -113,33 +113,41 @@ cdef class Timer: Timing starts as soon as the object is created. """ self._stopped = False - dmnsn_start_timer(&self._timer) + dmnsn_timer_start(&self._timer) def stop(self): """Stop the Timer.""" if self._stopped: raise RuntimeError("timer already stopped.") - dmnsn_stop_timer(&self._timer) + dmnsn_timer_stop(&self._timer) self._stopped = True property real: """Real (wall clock) time.""" def __get__(self): + self._assert_stopped() return self._timer.real property user: """User (CPU) time.""" def __get__(self): + self._assert_stopped() return self._timer.user property system: """System time.""" def __get__(self): + self._assert_stopped() return self._timer.system def __str__(self): + self._assert_stopped() return "%.2fs (user: %.2fs; system: %.2fs)" % \ (self._timer.real, self._timer.user, self._timer.system) + def _assert_stopped(self): + if not self._stopped: + raise RuntimeError("timer still running.") + cdef Timer _Timer(dmnsn_timer timer): """Wrap a Timer object around a dmnsn_timer.""" cdef Timer self = Timer.__new__(Timer) @@ -558,7 +566,7 @@ cdef class Canvas: def clear(self, c): """Clear a canvas with a solid color.""" - dmnsn_clear_canvas(self._canvas, Color(c)._c) + dmnsn_canvas_clear(self._canvas, Color(c)._c) def write_PNG(self, path): """Export the canvas as a PNG file.""" @@ -606,10 +614,10 @@ cdef class _CanvasProxy: return self._canvas.height def __getitem__(self, int y): self._bounds_check(y) - return _Color(dmnsn_get_pixel(self._canvas, self._x, y)) + return _Color(dmnsn_canvas_get_pixel(self._canvas, self._x, y)) def __setitem__(self, int y, color): self._bounds_check(y) - dmnsn_set_pixel(self._canvas, self._x, y, Color(color)._c) + dmnsn_canvas_set_pixel(self._canvas, self._x, y, Color(color)._c) def _bounds_check(self, int y): if y < 0 or y >= self._canvas.height: @@ -743,13 +751,13 @@ cdef class PigmentMap(Pigment): pigment = Pigment(pigment) real_pigment = (<Pigment>pigment)._pigment DMNSN_INCREF(real_pigment) - dmnsn_add_map_entry(pigment_map, i, &real_pigment) + dmnsn_map_add_entry(pigment_map, i, &real_pigment) else: for i, pigment in enumerate(map): pigment = Pigment(pigment) real_pigment = (<Pigment>pigment)._pigment DMNSN_INCREF(real_pigment) - dmnsn_add_map_entry(pigment_map, i/len(map), &real_pigment) + dmnsn_map_add_entry(pigment_map, i/len(map), &real_pigment) cdef dmnsn_pigment_map_flags flags if sRGB: @@ -1498,10 +1506,10 @@ cdef class Scene: def __get__(self): return _Timer(self._scene.render_timer) - def raytrace(self): + def ray_trace(self): """Render the scene.""" - self.raytrace_async().join() - def raytrace_async(self): + self.ray_trace_async().join() + def ray_trace_async(self): """Render the scene, in the background.""" # Account for image dimensions in the camera # Do this here so subregion renders can tell us the broader image size @@ -1518,7 +1526,7 @@ cdef class Scene: # Ensure the default texture is complete cdef Texture default = Texture(pigment = Black) dmnsn_texture_cascade(default._texture, &self._scene.default_texture) - return _Future(dmnsn_raytrace_scene_async(self._scene)) + return _Future(dmnsn_ray_trace_async(self._scene)) def __dealloc__(self): dmnsn_delete_scene(self._scene) diff --git a/libdimension-python/tests/demo.py b/libdimension-python/tests/demo.py index 720a96c..09ae184 100755 --- a/libdimension-python/tests/demo.py +++ b/libdimension-python/tests/demo.py @@ -53,7 +53,7 @@ scene.default_texture = Texture(finish = Ambient(0.1) + Diffuse(0.7)) scene.background = background scene.adc_bailout = 1/255 scene.recursion_limit = 5 -scene.raytrace() +scene.ray_trace() if have_PNG: canvas.write_PNG("demo.png") diff --git a/libdimension/Makefile.am b/libdimension/Makefile.am index 84f880c..73a4ae5 100644 --- a/libdimension/Makefile.am +++ b/libdimension/Makefile.am @@ -103,6 +103,7 @@ libdimension_la_SOURCES = $(nobase_include_HEADERS) \ prtree.c \ prtree.h \ raytrace.c \ + refcount-internal.h \ reflection.c \ scene.c \ solid_pigment.c \ diff --git a/libdimension/bench/polynomial.c b/libdimension/bench/polynomial.c index 0313060..b66648c 100644 --- a/libdimension/bench/polynomial.c +++ b/libdimension/bench/polynomial.c @@ -64,8 +64,8 @@ main(void) } for (size_t i = 0; i < NPOLY; ++i) { - sandglass_bench_fine(&sandglass, dmnsn_solve_polynomial(p[i], i + 1, x)); - printf("dmnsn_solve_polynomial(x^%zu): %ld\n", i + 1, sandglass.grains); + sandglass_bench_fine(&sandglass, dmnsn_polynomial_solve(p[i], i + 1, x)); + printf("dmnsn_polynomial_solve(x^%zu): %ld\n", i + 1, sandglass.grains); } return EXIT_SUCCESS; diff --git a/libdimension/bench/prtree.c b/libdimension/bench/prtree.c index 7db2bbc..6f0908a 100644 --- a/libdimension/bench/prtree.c +++ b/libdimension/bench/prtree.c @@ -84,7 +84,7 @@ main(void) dmnsn_object *object = dmnsn_new_fake_object(); object->texture = texture; DMNSN_INCREF(object->texture); - dmnsn_initialize_object(object); + dmnsn_object_initialize(object); dmnsn_array_push(objects, &object); } diff --git a/libdimension/camera.c b/libdimension/camera.c index f4b9aaa..13b91f0 100644 --- a/libdimension/camera.c +++ b/libdimension/camera.c @@ -23,7 +23,7 @@ * Cameras. */ -#include "dimension.h" +#include "dimension-internal.h" #include <stdlib.h> /* Allocate a new dummy camera */ diff --git a/libdimension/canvas.c b/libdimension/canvas.c index 7d25601..c0e8b2b 100644 --- a/libdimension/canvas.c +++ b/libdimension/canvas.c @@ -23,7 +23,7 @@ * Canveses. */ -#include "dimension.h" +#include "dimension-internal.h" #include <stdlib.h> /* For dmnsn_free() */ /* Allocate a new canvas, of width x and height y */ @@ -62,15 +62,15 @@ dmnsn_delete_canvas(dmnsn_canvas *canvas) /* Set a canvas optimizer */ void -dmnsn_optimize_canvas(dmnsn_canvas *canvas, dmnsn_canvas_optimizer optimizer) +dmnsn_canvas_optimize(dmnsn_canvas *canvas, dmnsn_canvas_optimizer optimizer) { dmnsn_array_push(canvas->optimizers, &optimizer); } /* Set the color of a pixel */ void -dmnsn_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y, - dmnsn_color color) +dmnsn_canvas_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y, + dmnsn_color color) { dmnsn_assert(x < canvas->width && y < canvas->height, "Canvas access out of bounds."); @@ -86,11 +86,11 @@ dmnsn_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y, /* Fill a canvas with a solid color */ void -dmnsn_clear_canvas(dmnsn_canvas *canvas, dmnsn_color color) +dmnsn_canvas_clear(dmnsn_canvas *canvas, dmnsn_color color) { for (size_t x = 0; x < canvas->width; ++x) { for (size_t y = 0; y < canvas->height; ++y) { - dmnsn_set_pixel(canvas, x, y, color); + dmnsn_canvas_set_pixel(canvas, x, y, color); } } } diff --git a/libdimension/canvas_pigment.c b/libdimension/canvas_pigment.c index 8a7e7d3..564ce00 100644 --- a/libdimension/canvas_pigment.c +++ b/libdimension/canvas_pigment.c @@ -33,7 +33,8 @@ dmnsn_canvas_pigment_fn(const dmnsn_pigment *pigment, dmnsn_vector v) size_t x = llround((fmod(v.x, 1.0) + 1.0)*(canvas->width - 1)); size_t y = llround((fmod(v.y, 1.0) + 1.0)*(canvas->height - 1)); - dmnsn_color c = dmnsn_get_pixel(canvas, x%canvas->width, y%canvas->height); + dmnsn_color c = dmnsn_canvas_get_pixel(canvas, + x%canvas->width, y%canvas->height); return c; } diff --git a/libdimension/cone.c b/libdimension/cone.c index 4d4e2cb..ec230a6 100644 --- a/libdimension/cone.c +++ b/libdimension/cone.c @@ -48,7 +48,7 @@ dmnsn_cone_intersection_fn(const dmnsn_object *cone, dmnsn_line l, poly[0] = l.x0.x*l.x0.x + l.x0.z*l.x0.z - (l.x0.y*(r2 - r1) + r2 + r1)*(l.x0.y*(r2 - r1) + r2 + r1)/4.0; - size_t n = dmnsn_solve_polynomial(poly, 2, x); + size_t n = dmnsn_polynomial_solve(poly, 2, x); if (n > 0) { double t = x[0]; diff --git a/libdimension/dimension-internal.h b/libdimension/dimension-internal.h index 4370f6b..a7eb213 100644 --- a/libdimension/dimension-internal.h +++ b/libdimension/dimension-internal.h @@ -29,6 +29,7 @@ #define _GNU_SOURCE #include "dimension.h" +#include "refcount-internal.h" #include "compiler.h" #include "profile.h" #include "platform.h" diff --git a/libdimension/dimension/canvas.h b/libdimension/dimension/canvas.h index 39e159b..48a64c1 100644 --- a/libdimension/dimension/canvas.h +++ b/libdimension/dimension/canvas.h @@ -84,7 +84,7 @@ void dmnsn_delete_canvas(dmnsn_canvas *canvas); * @param[in,out] canvas The canvas to optimize. * @param[in] optimizer The optimizer to use. */ -void dmnsn_optimize_canvas(dmnsn_canvas *canvas, +void dmnsn_canvas_optimize(dmnsn_canvas *canvas, dmnsn_canvas_optimizer optimizer); /* Pixel accessors */ @@ -97,7 +97,7 @@ void dmnsn_optimize_canvas(dmnsn_canvas *canvas, * @return The color of the canvas at (\p x, \p y). */ DMNSN_INLINE dmnsn_color -dmnsn_get_pixel(const dmnsn_canvas *canvas, size_t x, size_t y) +dmnsn_canvas_get_pixel(const dmnsn_canvas *canvas, size_t x, size_t y) { dmnsn_assert(x < canvas->width && y < canvas->height, "Canvas access out of bounds."); @@ -111,12 +111,12 @@ dmnsn_get_pixel(const dmnsn_canvas *canvas, size_t x, size_t y) * @param[in] y The y coordinate of the pixel. * @param[in] color The color to set the pixel at (\p x, \p y) to. */ -void dmnsn_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y, - dmnsn_color color); +void dmnsn_canvas_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y, + dmnsn_color color); /** * Clear a canvas uniformly with a given color. * @param[in,out] canvas The canvas to erase. * @param[in] color The color to paint it with. */ -void dmnsn_clear_canvas(dmnsn_canvas *canvas, dmnsn_color color); +void dmnsn_canvas_clear(dmnsn_canvas *canvas, dmnsn_color color); diff --git a/libdimension/dimension/map.h b/libdimension/dimension/map.h index 0355557..7e12e7e 100644 --- a/libdimension/dimension/map.h +++ b/libdimension/dimension/map.h @@ -49,7 +49,7 @@ void dmnsn_delete_map(dmnsn_map *map); * @param[in] n The index of the entry. * @param[in] obj The value of the entry. */ -void dmnsn_add_map_entry(dmnsn_map *map, double n, const void *obj); +void dmnsn_map_add_entry(dmnsn_map *map, double n, const void *obj); /** * Return the number of entries in a map. @@ -66,7 +66,7 @@ size_t dmnsn_map_size(const dmnsn_map *map); * @param[out] obj1 The first object. * @param[out] obj2 The second object. */ -void dmnsn_evaluate_map(const dmnsn_map *map, double n, +void dmnsn_map_evaluate(const dmnsn_map *map, double n, double *val, void *obj1, void *obj2); /** diff --git a/libdimension/dimension/object.h b/libdimension/dimension/object.h index 8b497ce..24c4785 100644 --- a/libdimension/dimension/object.h +++ b/libdimension/dimension/object.h @@ -109,7 +109,7 @@ void dmnsn_delete_object(dmnsn_object *object); * Initialize an object and potentially its children. * @param[in,out] object The object to initialize. */ -void dmnsn_initialize_object(dmnsn_object *object); +void dmnsn_object_initialize(dmnsn_object *object); /** * Appropriately transform a ray, then test for an intersection. diff --git a/libdimension/dimension/pigment.h b/libdimension/dimension/pigment.h index 487a8dc..716c28b 100644 --- a/libdimension/dimension/pigment.h +++ b/libdimension/dimension/pigment.h @@ -78,7 +78,7 @@ void dmnsn_delete_pigment(dmnsn_pigment *pigment); * initialized for you. * @param[in,out] pigment The pigment to initialize. */ -void dmnsn_initialize_pigment(dmnsn_pigment *pigment); +void dmnsn_pigment_initialize(dmnsn_pigment *pigment); /** * Evaluate the color of a pigment at a point. @@ -86,5 +86,5 @@ void dmnsn_initialize_pigment(dmnsn_pigment *pigment); * @param[in] v The point to color. * @return The color at \p v. */ -dmnsn_color dmnsn_evaluate_pigment(const dmnsn_pigment *pigment, +dmnsn_color dmnsn_pigment_evaluate(const dmnsn_pigment *pigment, dmnsn_vector v); diff --git a/libdimension/dimension/polynomial.h b/libdimension/dimension/polynomial.h index 38e2032..ab95d50 100644 --- a/libdimension/dimension/polynomial.h +++ b/libdimension/dimension/polynomial.h @@ -37,7 +37,7 @@ * @param[in] x The value of the variable at which to evaluate. */ DMNSN_INLINE double -dmnsn_evaluate_polynomial(const double poly[], size_t degree, double x) +dmnsn_polynomial_evaluate(const double poly[], size_t degree, double x) { double ret = poly[degree]; size_t i; @@ -54,7 +54,7 @@ dmnsn_evaluate_polynomial(const double poly[], size_t degree, double x) * @param[in] x The value of the variable at which to evaluate. */ DMNSN_INLINE double -dmnsn_evaluate_polynomial_derivative(const double poly[], size_t degree, +dmnsn_polynomial_evaluate_derivative(const double poly[], size_t degree, double x) { double ret = poly[degree]*degree; @@ -73,7 +73,7 @@ dmnsn_evaluate_polynomial_derivative(const double poly[], size_t degree, * dimension \p degree. * @return The number of positive roots stored in \c x[]. */ -size_t dmnsn_solve_polynomial(const double poly[], size_t degree, double x[]); +size_t dmnsn_polynomial_solve(const double poly[], size_t degree, double x[]); /** * Output a polynomial. The polynomial is printed as a function of x suitable @@ -82,4 +82,4 @@ size_t dmnsn_solve_polynomial(const double poly[], size_t degree, double x[]); * @param[in] poly The coefficients of the polynomial to print. * @param[in] degree The degree of the polynomial. */ -void dmnsn_print_polynomial(FILE *file, const double poly[], size_t degree); +void dmnsn_polynomial_print(FILE *file, const double poly[], size_t degree); diff --git a/libdimension/dimension/raytrace.h b/libdimension/dimension/raytrace.h index 79c148d..82fb759 100644 --- a/libdimension/dimension/raytrace.h +++ b/libdimension/dimension/raytrace.h @@ -24,14 +24,14 @@ */ /** - * Render a scene by raytracing. + * Render a scene by ray tracing. * @param[in,out] scene The scene to render. */ -void dmnsn_raytrace_scene(dmnsn_scene *scene); +void dmnsn_ray_trace(dmnsn_scene *scene); /** * Render a scene in the background. * @param[in,out] scene The scene to render. * @return A \p dmnsn_future object. */ -dmnsn_future *dmnsn_raytrace_scene_async(dmnsn_scene *scene); +dmnsn_future *dmnsn_ray_trace_async(dmnsn_scene *scene); diff --git a/libdimension/dimension/refcount.h b/libdimension/dimension/refcount.h index a0f5b6e..f9f3286 100644 --- a/libdimension/dimension/refcount.h +++ b/libdimension/dimension/refcount.h @@ -40,12 +40,3 @@ typedef unsigned int dmnsn_refcount; ++(object)->refcount; \ } \ } while (0) - -/** - * @internal - * Decrement a reference count. - * @param[in,out] object The reference-counted object to release. - * @return Whether the object is now garbage. - */ -#define DMNSN_DECREF(object) \ - ((object) && ((object)->refcount == 0 || --(object)->refcount == 0)) diff --git a/libdimension/dimension/scene.h b/libdimension/dimension/scene.h index c8abb5a..875c1bb 100644 --- a/libdimension/dimension/scene.h +++ b/libdimension/dimension/scene.h @@ -97,4 +97,4 @@ void dmnsn_delete_scene(dmnsn_scene *scene); * Initialize a scene. * @param[in,out] scene The scene to initalize. */ -void dmnsn_initialize_scene(dmnsn_scene *scene); +void dmnsn_scene_initialize(dmnsn_scene *scene); diff --git a/libdimension/dimension/texture.h b/libdimension/dimension/texture.h index 46e387b..a3cf744 100644 --- a/libdimension/dimension/texture.h +++ b/libdimension/dimension/texture.h @@ -53,7 +53,7 @@ void dmnsn_delete_texture(dmnsn_texture *texture); * initialized for you. * @param[in,out] texture The texture to initialize. */ -void dmnsn_initialize_texture(dmnsn_texture *texture); +void dmnsn_texture_initialize(dmnsn_texture *texture); /** * Fill missing texture properties from a default texture. diff --git a/libdimension/dimension/timer.h b/libdimension/dimension/timer.h index 5725b63..55d66ff 100644 --- a/libdimension/dimension/timer.h +++ b/libdimension/dimension/timer.h @@ -45,10 +45,10 @@ typedef struct dmnsn_timer { * Start a timer. The values of an unfinished timer are undefined. * @param[in,out] timer The timer to start. */ -void dmnsn_start_timer(dmnsn_timer *timer); +void dmnsn_timer_start(dmnsn_timer *timer); /** * Finish timing. The members of the timer struct will now contain timing data. * @param[in,out] timer The timer to stop. */ -void dmnsn_stop_timer(dmnsn_timer *timer); +void dmnsn_timer_stop(dmnsn_timer *timer); diff --git a/libdimension/finish.c b/libdimension/finish.c index 31f3178..90f41ae 100644 --- a/libdimension/finish.c +++ b/libdimension/finish.c @@ -23,7 +23,7 @@ * Finishes. */ -#include "dimension.h" +#include "dimension-internal.h" dmnsn_ambient * dmnsn_new_ambient(void) diff --git a/libdimension/gl.c b/libdimension/gl.c index a2825f9..ff7906c 100644 --- a/libdimension/gl.c +++ b/libdimension/gl.c @@ -34,7 +34,7 @@ dmnsn_gl_optimizer_fn(const dmnsn_canvas *canvas, dmnsn_canvas_optimizer optimizer, size_t x, size_t y) { GLushort *pixel = (GLushort *)optimizer.ptr + 4*(y*canvas->width + x); - dmnsn_color color = dmnsn_get_pixel(canvas, x, y); + dmnsn_color color = dmnsn_canvas_get_pixel(canvas, x, y); color = dmnsn_remove_filter(color); color = dmnsn_color_to_sRGB(color); color = dmnsn_color_saturate(color); @@ -64,7 +64,7 @@ dmnsn_gl_optimize_canvas(dmnsn_canvas *canvas) optimizer.ptr = dmnsn_malloc(4*canvas->width*canvas->height*sizeof(GLushort)); /* Set a new optimizer */ - dmnsn_optimize_canvas(canvas, optimizer); + dmnsn_canvas_optimize(canvas, optimizer); return 0; } @@ -94,7 +94,7 @@ dmnsn_gl_write_canvas(const dmnsn_canvas *canvas) for (size_t x = 0; x < width; ++x) { pixel = pixels + 4*(y*width + x); - color = dmnsn_get_pixel(canvas, x, y); + color = dmnsn_canvas_get_pixel(canvas, x, y); color = dmnsn_remove_filter(color); color = dmnsn_color_to_sRGB(color); color = dmnsn_color_saturate(color); @@ -140,7 +140,7 @@ dmnsn_gl_read_canvas(size_t x0, size_t y0, (double)pixel[3]/UINT16_MAX, 0.0); color = dmnsn_color_from_sRGB(color); - dmnsn_set_pixel(canvas, x, y, color); + dmnsn_canvas_set_pixel(canvas, x, y, color); } } diff --git a/libdimension/interior.c b/libdimension/interior.c index 6568b15..a8e328c 100644 --- a/libdimension/interior.c +++ b/libdimension/interior.c @@ -23,7 +23,7 @@ * Interiors. */ -#include "dimension.h" +#include "dimension-internal.h" #include <stdlib.h> /* Allocate an interior */ diff --git a/libdimension/light.c b/libdimension/light.c index 533f309..358ba2d 100644 --- a/libdimension/light.c +++ b/libdimension/light.c @@ -23,7 +23,7 @@ * Lights. */ -#include "dimension.h" +#include "dimension-internal.h" #include <stdlib.h> /* Allocate a new dummy light */ diff --git a/libdimension/map.c b/libdimension/map.c index e6c7354..37f3c0f 100644 --- a/libdimension/map.c +++ b/libdimension/map.c @@ -58,7 +58,7 @@ dmnsn_delete_map(dmnsn_map *map) } void -dmnsn_add_map_entry(dmnsn_map *map, double n, const void *obj) +dmnsn_map_add_entry(dmnsn_map *map, double n, const void *obj) { dmnsn_map_entry *entry = dmnsn_malloc(sizeof(dmnsn_map_entry) + map->obj_size); @@ -84,7 +84,7 @@ dmnsn_map_size(const dmnsn_map *map) } void -dmnsn_evaluate_map(const dmnsn_map *map, double n, +dmnsn_map_evaluate(const dmnsn_map *map, double n, double *val, void *obj1, void *obj2) { dmnsn_assert(dmnsn_array_size(map->array) > 0, diff --git a/libdimension/object.c b/libdimension/object.c index 66c5166..b1b5fe3 100644 --- a/libdimension/object.c +++ b/libdimension/object.c @@ -23,7 +23,7 @@ * Objects. */ -#include "dimension.h" +#include "dimension-internal.h" #include <stdlib.h> /* Allocate a dummy object */ @@ -66,7 +66,7 @@ dmnsn_delete_object(dmnsn_object *object) /** Recursively initialize objects. */ static void -dmnsn_initialize_object_recursive(dmnsn_object *object, +dmnsn_object_initialize_recursive(dmnsn_object *object, dmnsn_matrix pigment_trans) { dmnsn_assert(!object->initialized, "Object double-initialized."); @@ -74,7 +74,7 @@ dmnsn_initialize_object_recursive(dmnsn_object *object, /* Initialize the texture */ if (!object->texture->initialized) { - dmnsn_initialize_texture(object->texture); + dmnsn_texture_initialize(object->texture); } /* Precalculate object values */ @@ -95,7 +95,7 @@ dmnsn_initialize_object_recursive(dmnsn_object *object, dmnsn_texture_cascade(object->texture, &(*child)->texture); dmnsn_interior_cascade(object->interior, &(*child)->interior); - dmnsn_initialize_object_recursive(*child, child_pigment_trans); + dmnsn_object_initialize_recursive(*child, child_pigment_trans); } /* Initialization callback */ @@ -111,8 +111,8 @@ dmnsn_initialize_object_recursive(dmnsn_object *object, /* Precompute object properties */ void -dmnsn_initialize_object(dmnsn_object *object) +dmnsn_object_initialize(dmnsn_object *object) { dmnsn_matrix pigment_trans = dmnsn_matrix_inverse(object->trans); - dmnsn_initialize_object_recursive(object, pigment_trans); + dmnsn_object_initialize_recursive(object, pigment_trans); } diff --git a/libdimension/pattern.c b/libdimension/pattern.c index 5d93295..6a2e286 100644 --- a/libdimension/pattern.c +++ b/libdimension/pattern.c @@ -23,7 +23,7 @@ * Patterns. */ -#include "dimension.h" +#include "dimension-internal.h" /* Allocate a dummy pattern */ dmnsn_pattern * diff --git a/libdimension/pigment.c b/libdimension/pigment.c index 3650ba3..74159ee 100644 --- a/libdimension/pigment.c +++ b/libdimension/pigment.c @@ -23,7 +23,7 @@ * Pigments. */ -#include "dimension.h" +#include "dimension-internal.h" /* Allocate a dummy pigment */ dmnsn_pigment * @@ -54,7 +54,7 @@ dmnsn_delete_pigment(dmnsn_pigment *pigment) /* Precompute pigment properties */ void -dmnsn_initialize_pigment(dmnsn_pigment *pigment) +dmnsn_pigment_initialize(dmnsn_pigment *pigment) { dmnsn_assert(!pigment->initialized, "Pigment double-initialized."); pigment->initialized = true; @@ -68,7 +68,7 @@ dmnsn_initialize_pigment(dmnsn_pigment *pigment) /* Evaluate a pigment */ dmnsn_color -dmnsn_evaluate_pigment(const dmnsn_pigment *pigment, dmnsn_vector v) +dmnsn_pigment_evaluate(const dmnsn_pigment *pigment, dmnsn_vector v) { if (pigment->pigment_fn) { dmnsn_vector v_trans = dmnsn_transform_point(pigment->trans_inv, v); diff --git a/libdimension/pigment_map.c b/libdimension/pigment_map.c index 943bfc1..09665c0 100644 --- a/libdimension/pigment_map.c +++ b/libdimension/pigment_map.c @@ -30,7 +30,7 @@ static void dmnsn_initialize_mapped_pigment(void *ptr) { dmnsn_pigment **pigment = ptr; - dmnsn_initialize_pigment(*pigment); + dmnsn_pigment_initialize(*pigment); } /** Free a pigment in a pigment map. */ @@ -60,7 +60,7 @@ void dmnsn_pigment_map_add_color(dmnsn_map *map, double n, dmnsn_color color) { dmnsn_pigment *pigment = dmnsn_new_solid_pigment(color); - dmnsn_add_map_entry(map, n, &pigment); + dmnsn_map_add_entry(map, n, &pigment); } /** Free a pigment_map payload. */ @@ -80,10 +80,10 @@ dmnsn_pigment_map_pigment_fn(const dmnsn_pigment *pigment, dmnsn_vector v) const dmnsn_pigment_map_payload *payload = pigment->ptr; double n; dmnsn_pigment *pigment1, *pigment2; - dmnsn_evaluate_map(payload->map, dmnsn_pattern_value(payload->pattern, v), + dmnsn_map_evaluate(payload->map, dmnsn_pattern_value(payload->pattern, v), &n, &pigment1, &pigment2); - dmnsn_color color1 = dmnsn_evaluate_pigment(pigment1, v); - dmnsn_color color2 = dmnsn_evaluate_pigment(pigment2, v); + dmnsn_color color1 = dmnsn_pigment_evaluate(pigment1, v); + dmnsn_color color2 = dmnsn_pigment_evaluate(pigment2, v); if (payload->flags == DMNSN_PIGMENT_MAP_SRGB) { color1 = dmnsn_color_to_sRGB(color1); diff --git a/libdimension/png.c b/libdimension/png.c index d633abb..8fc2c1f 100644 --- a/libdimension/png.c +++ b/libdimension/png.c @@ -52,7 +52,7 @@ dmnsn_png_optimize_canvas(dmnsn_canvas *canvas) optimizer.ptr = dmnsn_malloc(4*canvas->width*canvas->height*sizeof(uint16_t)); - dmnsn_optimize_canvas(canvas, optimizer); + dmnsn_canvas_optimize(canvas, optimizer); return 0; } @@ -64,7 +64,7 @@ dmnsn_png_optimizer_fn(const dmnsn_canvas *canvas, dmnsn_color color; uint16_t *pixel = (uint16_t *)optimizer.ptr + 4*(y*canvas->width + x); - color = dmnsn_get_pixel(canvas, x, y); + color = dmnsn_canvas_get_pixel(canvas, x, y); color = dmnsn_remove_filter(color); color = dmnsn_color_to_sRGB(color); color = dmnsn_color_saturate(color); @@ -238,7 +238,8 @@ dmnsn_png_write_canvas_thread(void *ptr) for (size_t y = 0; y < height; ++y) { for (size_t x = 0; x < width; ++x) { /* Invert the rows. PNG coordinates are fourth quadrant. */ - dmnsn_color color = dmnsn_get_pixel(payload->canvas, x, height - y - 1); + dmnsn_color color = dmnsn_canvas_get_pixel(payload->canvas, + x, height - y - 1); color = dmnsn_remove_filter(color); color = dmnsn_color_to_sRGB(color); color = dmnsn_color_saturate(color); @@ -420,7 +421,7 @@ dmnsn_png_read_canvas_thread(void *ptr) } color = dmnsn_color_from_sRGB(color); - dmnsn_set_pixel(*payload->canvas, x, height - y - 1, color); + dmnsn_canvas_set_pixel(*payload->canvas, x, height - y - 1, color); } dmnsn_future_increment(payload->future); diff --git a/libdimension/polynomial.c b/libdimension/polynomial.c index c793562..56f087d 100644 --- a/libdimension/polynomial.c +++ b/libdimension/polynomial.c @@ -244,15 +244,15 @@ dmnsn_bisect_root(const double poly[], size_t degree, double min, double max) return dmnsn_improve_root(poly, degree, min); } - double evmin = dmnsn_evaluate_polynomial(poly, degree, min); - double evmax = dmnsn_evaluate_polynomial(poly, degree, max); + double evmin = dmnsn_polynomial_evaluate(poly, degree, min); + double evmax = dmnsn_polynomial_evaluate(poly, degree, max); double initial_evmin = fabs(evmin), initial_evmax = fabs(evmax); double mid = 0.0, evmid; int lastsign = -1; do { mid = (min*evmax - max*evmin)/(evmax - evmin); - evmid = dmnsn_evaluate_polynomial(poly, degree, mid); + evmid = dmnsn_polynomial_evaluate(poly, degree, mid); int sign = dmnsn_signbit(evmid); if (mid < min) { @@ -394,7 +394,7 @@ dmnsn_solve_cubic(double poly[4], double x[3]) /* Uspensky's algorithm */ DMNSN_HOT size_t -dmnsn_solve_polynomial(const double poly[], size_t degree, double x[]) +dmnsn_polynomial_solve(const double poly[], size_t degree, double x[]) { /* Copy the polynomial so we can be destructive */ double p[degree + 1]; @@ -454,7 +454,7 @@ dmnsn_solve_polynomial(const double poly[], size_t degree, double x[]) /* Print a polynomial */ void -dmnsn_print_polynomial(FILE *file, const double poly[], size_t degree) +dmnsn_polynomial_print(FILE *file, const double poly[], size_t degree) { for (size_t i = degree + 1; i-- > 0;) { if (i < degree) { diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index e5d2a15..4056f07 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -35,63 +35,63 @@ typedef struct { dmnsn_future *future; dmnsn_scene *scene; dmnsn_prtree *prtree; -} dmnsn_raytrace_payload; +} dmnsn_ray_trace_payload; -/* Raytrace a scene */ +/* Ray-trace a scene */ void -dmnsn_raytrace_scene(dmnsn_scene *scene) +dmnsn_ray_trace(dmnsn_scene *scene) { - dmnsn_future *future = dmnsn_raytrace_scene_async(scene); + dmnsn_future *future = dmnsn_ray_trace_async(scene); if (dmnsn_future_join(future) != 0) { - dmnsn_error("Error occured while raytracing."); + dmnsn_error("Error occured while ray-tracing."); } } /** Background thread callback. */ -static int dmnsn_raytrace_scene_thread(void *ptr); +static int dmnsn_ray_trace_scene_thread(void *ptr); -/* Raytrace a scene in the background */ +/* Ray-trace a scene in the background */ dmnsn_future * -dmnsn_raytrace_scene_async(dmnsn_scene *scene) +dmnsn_ray_trace_async(dmnsn_scene *scene) { dmnsn_future *future = dmnsn_new_future(); - dmnsn_raytrace_payload *payload = - dmnsn_malloc(sizeof(dmnsn_raytrace_payload)); + dmnsn_ray_trace_payload *payload = + dmnsn_malloc(sizeof(dmnsn_ray_trace_payload)); payload->future = future; payload->scene = scene; - dmnsn_new_thread(future, dmnsn_raytrace_scene_thread, payload); + dmnsn_new_thread(future, dmnsn_ray_trace_scene_thread, payload); return future; } /** Worker thread callback. */ -static int dmnsn_raytrace_scene_concurrent(void *ptr, unsigned int thread, - unsigned int nthreads); +static int dmnsn_ray_trace_scene_concurrent(void *ptr, unsigned int thread, + unsigned int nthreads); /* Thread callback -- set up the multithreaded engine */ static int -dmnsn_raytrace_scene_thread(void *ptr) +dmnsn_ray_trace_scene_thread(void *ptr) { - dmnsn_raytrace_payload *payload = ptr; + dmnsn_ray_trace_payload *payload = ptr; /* Pre-calculate bounding box transformations, etc. */ - dmnsn_initialize_scene(payload->scene); + dmnsn_scene_initialize(payload->scene); /* Time the bounding tree construction */ - dmnsn_start_timer(&payload->scene->bounding_timer); + dmnsn_timer_start(&payload->scene->bounding_timer); payload->prtree = dmnsn_new_prtree(payload->scene->objects); - dmnsn_stop_timer(&payload->scene->bounding_timer); + dmnsn_timer_stop(&payload->scene->bounding_timer); /* Set up the future object */ dmnsn_future_set_total(payload->future, payload->scene->canvas->height); /* Time the render itself */ - dmnsn_start_timer(&payload->scene->render_timer); - int ret = dmnsn_execute_concurrently(dmnsn_raytrace_scene_concurrent, + dmnsn_timer_start(&payload->scene->render_timer); + int ret = dmnsn_execute_concurrently(dmnsn_ray_trace_scene_concurrent, payload, payload->scene->nthreads); - dmnsn_stop_timer(&payload->scene->render_timer); + dmnsn_timer_stop(&payload->scene->render_timer); dmnsn_delete_prtree(payload->prtree); dmnsn_free(payload); @@ -100,12 +100,12 @@ dmnsn_raytrace_scene_thread(void *ptr) } /* - * Raytracing algorithm + * Ray-tracing algorithm */ /** The current state of the ray-tracing engine. */ -typedef struct dmnsn_raytrace_state { - const struct dmnsn_raytrace_state *parent; +typedef struct dmnsn_rtstate { + const struct dmnsn_rtstate *parent; const dmnsn_scene *scene; const dmnsn_intersection *intersection; @@ -127,12 +127,12 @@ typedef struct dmnsn_raytrace_state { double ior; dmnsn_color adc_value; -} dmnsn_raytrace_state; +} dmnsn_rtstate; -/** Compute a raytrace state from an intersection. */ +/** Compute a ray-tracing state from an intersection. */ static inline void -dmnsn_initialize_raytrace_state(dmnsn_raytrace_state *state, - const dmnsn_intersection *intersection) +dmnsn_rtstate_initialize(dmnsn_rtstate *state, + const dmnsn_intersection *intersection) { state->intersection = intersection; state->texture = intersection->object->texture; @@ -158,21 +158,20 @@ dmnsn_initialize_raytrace_state(dmnsn_raytrace_state *state, state->additional = dmnsn_black; } -/** Main helper for dmnsn_raytrace_scene_impl - shoot a ray. */ -static dmnsn_color dmnsn_raytrace_shoot(dmnsn_raytrace_state *state, - dmnsn_line ray); +/** Main helper for dmnsn_ray_trace_scene_impl - shoot a ray. */ +static dmnsn_color dmnsn_ray_shoot(dmnsn_rtstate *state, dmnsn_line ray); -/* Actually raytrace a scene */ +/* Actually ray-trace a scene */ static int -dmnsn_raytrace_scene_concurrent(void *ptr, unsigned int thread, - unsigned int nthreads) +dmnsn_ray_trace_scene_concurrent(void *ptr, unsigned int thread, + unsigned int nthreads) { - const dmnsn_raytrace_payload *payload = ptr; + const dmnsn_ray_trace_payload *payload = ptr; dmnsn_future *future = payload->future; dmnsn_scene *scene = payload->scene; dmnsn_prtree *prtree = payload->prtree; - dmnsn_raytrace_state state = { + dmnsn_rtstate state = { .parent = NULL, .scene = scene, .prtree = prtree, @@ -192,9 +191,9 @@ dmnsn_raytrace_scene_concurrent(void *ptr, unsigned int thread, state.reclevel = scene->reclimit; state.ior = 1.0; state.adc_value = dmnsn_white; - dmnsn_color color = dmnsn_raytrace_shoot(&state, ray); + dmnsn_color color = dmnsn_ray_shoot(&state, ray); - dmnsn_set_pixel(scene->canvas, x, y, color); + dmnsn_canvas_set_pixel(scene->canvas, x, y, color); } dmnsn_future_increment(future); @@ -205,11 +204,11 @@ dmnsn_raytrace_scene_concurrent(void *ptr, unsigned int thread, /** Calculate the background color. */ static dmnsn_color -dmnsn_raytrace_background(const dmnsn_raytrace_state *state, dmnsn_line ray) +dmnsn_trace_background(const dmnsn_rtstate *state, dmnsn_line ray) { dmnsn_pigment *background = state->scene->background; if (state->scene->quality & DMNSN_RENDER_PIGMENT) { - return dmnsn_evaluate_pigment(background, dmnsn_vector_normalized(ray.n)); + return dmnsn_pigment_evaluate(background, dmnsn_vector_normalized(ray.n)); } else { return background->quick_color; } @@ -217,11 +216,11 @@ dmnsn_raytrace_background(const dmnsn_raytrace_state *state, dmnsn_line ray) /** Calculate the base pigment at the intersection. */ static void -dmnsn_raytrace_pigment(dmnsn_raytrace_state *state) +dmnsn_trace_pigment(dmnsn_rtstate *state) { dmnsn_pigment *pigment = state->texture->pigment; if (state->scene->quality & DMNSN_RENDER_PIGMENT) { - state->pigment = dmnsn_evaluate_pigment(pigment, state->pigment_r); + state->pigment = dmnsn_pigment_evaluate(pigment, state->pigment_r); } else { state->pigment = pigment->quick_color; } @@ -231,8 +230,7 @@ dmnsn_raytrace_pigment(dmnsn_raytrace_state *state) /** Get the color of a light ray at an intersection point. */ static dmnsn_color -dmnsn_raytrace_light_ray(dmnsn_raytrace_state *state, - const dmnsn_light *light) +dmnsn_trace_light_ray(dmnsn_rtstate *state, const dmnsn_light *light) { /** @todo: Start at the light source */ dmnsn_line shadow_ray = dmnsn_new_line( @@ -265,9 +263,9 @@ dmnsn_raytrace_light_ray(dmnsn_raytrace_state *state, /* Handle transparency */ if (state->scene->quality & DMNSN_RENDER_TRANSPARENCY) { - dmnsn_raytrace_state shadow_state = *state; - dmnsn_initialize_raytrace_state(&shadow_state, &shadow_caster); - dmnsn_raytrace_pigment(&shadow_state); + dmnsn_rtstate shadow_state = *state; + dmnsn_rtstate_initialize(&shadow_state, &shadow_caster); + dmnsn_trace_pigment(&shadow_state); if (shadow_state.pigment.trans >= dmnsn_epsilon) { /* Reflect the light */ @@ -298,7 +296,7 @@ dmnsn_raytrace_light_ray(dmnsn_raytrace_state *state, /** Handle light, shadow, and shading. */ static void -dmnsn_raytrace_lighting(dmnsn_raytrace_state *state) +dmnsn_trace_lighting(dmnsn_rtstate *state) { /* The ambient color */ state->diffuse = dmnsn_black; @@ -311,7 +309,7 @@ dmnsn_raytrace_lighting(dmnsn_raytrace_state *state) /* Iterate over each light */ DMNSN_ARRAY_FOREACH (dmnsn_light **, light, state->scene->lights) { - dmnsn_color light_color = dmnsn_raytrace_light_ray(state, *light); + dmnsn_color light_color = dmnsn_trace_light_ray(state, *light); if (!dmnsn_color_is_black(light_color)) { if (state->scene->quality & DMNSN_RENDER_FINISH) { /* Reflect the light */ @@ -354,7 +352,7 @@ dmnsn_raytrace_lighting(dmnsn_raytrace_state *state) /** Trace a reflected ray. */ static dmnsn_color -dmnsn_raytrace_reflection(const dmnsn_raytrace_state *state) +dmnsn_trace_reflection(const dmnsn_rtstate *state) { dmnsn_color reflected = dmnsn_black; @@ -363,7 +361,7 @@ dmnsn_raytrace_reflection(const dmnsn_raytrace_state *state) dmnsn_line refl_ray = dmnsn_new_line(state->r, state->reflected); refl_ray = dmnsn_line_add_epsilon(refl_ray); - dmnsn_raytrace_state recursive_state = *state; + dmnsn_rtstate recursive_state = *state; /* Calculate ADC value */ recursive_state.adc_value = reflection->reflection_fn( @@ -372,7 +370,7 @@ dmnsn_raytrace_reflection(const dmnsn_raytrace_state *state) ); /* Shoot the reflected ray */ - dmnsn_color rec = dmnsn_raytrace_shoot(&recursive_state, refl_ray); + dmnsn_color rec = dmnsn_ray_shoot(&recursive_state, refl_ray); reflected = reflection->reflection_fn( reflection, rec, state->pigment, state->reflected, state->intersection->normal @@ -386,7 +384,7 @@ dmnsn_raytrace_reflection(const dmnsn_raytrace_state *state) /** Handle transparency - must be called last to work correctly. */ static void -dmnsn_raytrace_transparency(dmnsn_raytrace_state *state) +dmnsn_trace_transparency(dmnsn_rtstate *state) { if (state->pigment.trans >= dmnsn_epsilon) { dmnsn_line trans_ray = dmnsn_new_line(state->r, state->intersection->ray.n); @@ -395,7 +393,7 @@ dmnsn_raytrace_transparency(dmnsn_raytrace_state *state) dmnsn_vector r = dmnsn_vector_normalized(trans_ray.n); dmnsn_vector n = state->intersection->normal; - dmnsn_raytrace_state recursive_state = *state; + dmnsn_rtstate recursive_state = *state; /* Calculate new refractive index */ if (dmnsn_vector_dot(r, n) < 0.0) { @@ -434,7 +432,7 @@ dmnsn_raytrace_transparency(dmnsn_raytrace_state *state) dmnsn_filter_light(state->adc_value, state->pigment); /* Shoot the transmitted ray */ - dmnsn_color rec = dmnsn_raytrace_shoot(&recursive_state, trans_ray); + dmnsn_color rec = dmnsn_ray_shoot(&recursive_state, trans_ray); dmnsn_color filtered = dmnsn_filter_light(rec, state->pigment); /* Conserve energy */ @@ -455,7 +453,7 @@ dmnsn_raytrace_transparency(dmnsn_raytrace_state *state) /* Shoot a ray, and calculate the color */ static dmnsn_color -dmnsn_raytrace_shoot(dmnsn_raytrace_state *state, dmnsn_line ray) +dmnsn_ray_shoot(dmnsn_rtstate *state, dmnsn_line ray) { if (state->reclevel == 0 || dmnsn_color_intensity(state->adc_value) < state->scene->adc_bailout) @@ -469,32 +467,32 @@ dmnsn_raytrace_shoot(dmnsn_raytrace_state *state, dmnsn_line ray) bool reset = state->reclevel == state->scene->reclimit - 1; if (dmnsn_prtree_intersection(state->prtree, ray, &intersection, reset)) { /* Found an intersection */ - dmnsn_initialize_raytrace_state(state, &intersection); + dmnsn_rtstate_initialize(state, &intersection); /* Pigment */ - dmnsn_raytrace_pigment(state); + dmnsn_trace_pigment(state); /* Finishes and shadows */ if (state->scene->quality & DMNSN_RENDER_LIGHTS) { - dmnsn_raytrace_lighting(state); + dmnsn_trace_lighting(state); } /* Reflection */ if (state->scene->quality & DMNSN_RENDER_REFLECTION) { state->additional = dmnsn_color_add( - dmnsn_raytrace_reflection(state), + dmnsn_trace_reflection(state), state->additional ); } /* Transparency */ if (state->scene->quality & DMNSN_RENDER_TRANSPARENCY) { - dmnsn_raytrace_transparency(state); + dmnsn_trace_transparency(state); } return dmnsn_color_add(state->diffuse, state->additional); } else { /* No intersection, return the background color */ - return dmnsn_raytrace_background(state, ray); + return dmnsn_trace_background(state, ray); } } diff --git a/libdimension/refcount-internal.h b/libdimension/refcount-internal.h new file mode 100644 index 0000000..c2321c9 --- /dev/null +++ b/libdimension/refcount-internal.h @@ -0,0 +1,32 @@ +/************************************************************************* + * Copyright (C) 2010-2011 Tavian Barnes <tavianator@tavianator.com> * + * * + * This file is part of The Dimension Library. * + * * + * The Dimension Library is free software; you can redistribute it and/ * + * or modify it under the terms of the GNU Lesser General Public License * + * as published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * The Dimension Library is distributed in the hope that it will be * + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +/** + * @file + * Reference count internal API. + */ + +/** + * Decrement a reference count. + * @param[in,out] object The reference-counted object to release. + * @return Whether the object is now garbage. + */ +#define DMNSN_DECREF(object) \ + ((object) && ((object)->refcount == 0 || --(object)->refcount == 0)) diff --git a/libdimension/scene.c b/libdimension/scene.c index cd8587f..3e3a9f2 100644 --- a/libdimension/scene.c +++ b/libdimension/scene.c @@ -76,7 +76,7 @@ dmnsn_delete_scene(dmnsn_scene *scene) } void -dmnsn_initialize_scene(dmnsn_scene *scene) +dmnsn_scene_initialize(dmnsn_scene *scene) { dmnsn_assert(!scene->initialized, "Scene double-initialized."); scene->initialized = true; @@ -88,13 +88,13 @@ dmnsn_initialize_scene(dmnsn_scene *scene) scene->outer_height = scene->canvas->height; } - dmnsn_initialize_pigment(scene->background); + dmnsn_pigment_initialize(scene->background); - dmnsn_initialize_texture(scene->default_texture); + dmnsn_texture_initialize(scene->default_texture); DMNSN_ARRAY_FOREACH (dmnsn_object **, object, scene->objects) { dmnsn_texture_cascade(scene->default_texture, &(*object)->texture); dmnsn_interior_cascade(scene->default_interior, &(*object)->interior); - dmnsn_initialize_object(*object); + dmnsn_object_initialize(*object); } } diff --git a/libdimension/sphere.c b/libdimension/sphere.c index 881da0c..a3f0c90 100644 --- a/libdimension/sphere.c +++ b/libdimension/sphere.c @@ -36,7 +36,7 @@ dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, dmnsn_line l, poly[1] = 2.0*dmnsn_vector_dot(l.n, l.x0); poly[0] = dmnsn_vector_dot(l.x0, l.x0) - 1.0; - size_t n = dmnsn_solve_polynomial(poly, 2, x); + size_t n = dmnsn_polynomial_solve(poly, 2, x); if (n == 0) { return false; } else { diff --git a/libdimension/tests/polynomial.c b/libdimension/tests/polynomial.c index 5632b49..d66c975 100644 --- a/libdimension/tests/polynomial.c +++ b/libdimension/tests/polynomial.c @@ -40,7 +40,7 @@ main(void) poly[1] = -646.270936; poly[0] = 1447.8216; - size_t n = dmnsn_solve_polynomial(poly, 5, x); + size_t n = dmnsn_polynomial_solve(poly, 5, x); if (n != 4) { fprintf(stderr, "--- Wrong number of roots found (%zu, should be %u) ---\n", @@ -49,9 +49,9 @@ main(void) } for (size_t i = 0; i < n; ++i) { - double evmin = dmnsn_evaluate_polynomial(poly, 5, x[i] - dmnsn_epsilon); - double ev = dmnsn_evaluate_polynomial(poly, 5, x[i]); - double evmax = dmnsn_evaluate_polynomial(poly, 5, x[i] + dmnsn_epsilon); + double evmin = dmnsn_polynomial_evaluate(poly, 5, x[i] - dmnsn_epsilon); + double ev = dmnsn_polynomial_evaluate(poly, 5, x[i]); + double evmax = dmnsn_polynomial_evaluate(poly, 5, x[i] + dmnsn_epsilon); if (fabs(evmin) < ev || fabs(evmax) < ev) { fprintf(stderr, "--- Root %.15g is inaccurate! ---\n", x[i]); return EXIT_FAILURE; diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c index af22691..ae4a644 100644 --- a/libdimension/tests/render.c +++ b/libdimension/tests/render.c @@ -94,7 +94,7 @@ dmnsn_test_scene_add_background(dmnsn_scene *scene) fprintf(stderr, "--- WARNING: Couldn't open or read png2.png! ---\n"); png_pigment = dmnsn_new_solid_pigment(dmnsn_orange); } - dmnsn_add_map_entry(sky_gradient_pigment_map, 0.0, &png_pigment); + dmnsn_map_add_entry(sky_gradient_pigment_map, 0.0, &png_pigment); dmnsn_color background = dmnsn_color_from_sRGB( dmnsn_new_color5(0.0, 0.1, 0.2, 0.1, 0.0) @@ -269,7 +269,7 @@ dmnsn_test_scene_add_ground(dmnsn_scene *scene) dmnsn_scale_matrix(dmnsn_new_vector(1.0/3.0, 1.0/3.0, 1.0/3.0)); dmnsn_map *big_map = dmnsn_new_pigment_map(); dmnsn_pigment_map_add_color(big_map, 0.0, dmnsn_white); - dmnsn_add_map_entry(big_map, 1.0, &small_pigment); + 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); @@ -339,7 +339,7 @@ main(void) } } - dmnsn_clear_canvas(scene->canvas, dmnsn_black); + dmnsn_canvas_clear(scene->canvas, dmnsn_black); /* Create a new glX display */ dmnsn_display *display = NULL; @@ -353,7 +353,7 @@ main(void) /* Render the scene */ printf("Rendering scene\n"); - dmnsn_future *future = dmnsn_raytrace_scene_async(scene); + dmnsn_future *future = dmnsn_ray_trace_async(scene); /* Display the scene as it's rendered */ if (display) { diff --git a/libdimension/tests/test_canvas.c b/libdimension/tests/test_canvas.c index b5d02ad..783914d 100644 --- a/libdimension/tests/test_canvas.c +++ b/libdimension/tests/test_canvas.c @@ -50,7 +50,7 @@ dmnsn_paint_test_canvas(dmnsn_canvas *canvas) color = dmnsn_color_from_sRGB(color); } - dmnsn_set_pixel(canvas, x, y, color); + dmnsn_canvas_set_pixel(canvas, x, y, color); } } } diff --git a/libdimension/texture.c b/libdimension/texture.c index fabe578..3018bcd 100644 --- a/libdimension/texture.c +++ b/libdimension/texture.c @@ -23,7 +23,7 @@ * Textures. */ -#include "dimension.h" +#include "dimension-internal.h" /* Allocate a dummy texture */ dmnsn_texture * @@ -51,7 +51,7 @@ dmnsn_delete_texture(dmnsn_texture *texture) /* Calculate matrix inverses */ void -dmnsn_initialize_texture(dmnsn_texture *texture) +dmnsn_texture_initialize(dmnsn_texture *texture) { dmnsn_assert(!texture->initialized, "Texture double-initialized."); texture->initialized = true; @@ -61,7 +61,7 @@ dmnsn_initialize_texture(dmnsn_texture *texture) if (!texture->pigment->initialized) { texture->pigment->trans = dmnsn_matrix_mul(texture->trans, texture->pigment->trans); - dmnsn_initialize_pigment(texture->pigment); + dmnsn_pigment_initialize(texture->pigment); } } diff --git a/libdimension/timer.c b/libdimension/timer.c index e8d62ba..35bf05d 100644 --- a/libdimension/timer.c +++ b/libdimension/timer.c @@ -26,13 +26,13 @@ #include "dimension-internal.h" void -dmnsn_start_timer(dmnsn_timer *timer) +dmnsn_timer_start(dmnsn_timer *timer) { dmnsn_get_times(timer); } void -dmnsn_stop_timer(dmnsn_timer *timer) +dmnsn_timer_stop(dmnsn_timer *timer) { dmnsn_timer now; dmnsn_get_times(&now); diff --git a/libdimension/torus.c b/libdimension/torus.c index fc0f4ad..b3ccf9f 100644 --- a/libdimension/torus.c +++ b/libdimension/torus.c @@ -56,8 +56,8 @@ dmnsn_torus_bound_intersection(const dmnsn_torus_payload *payload, dmnsn_line l) smallcyl[0] = dist2 - rmin2; double x[4]; - size_t n = dmnsn_solve_polynomial(bigcyl, 2, x); - n += dmnsn_solve_polynomial(smallcyl, 2, x + n); + size_t n = dmnsn_polynomial_solve(bigcyl, 2, x); + n += dmnsn_polynomial_solve(smallcyl, 2, x + n); size_t i; for (i = 0; i < n; ++i) { @@ -105,7 +105,7 @@ dmnsn_torus_intersection_fn(const dmnsn_object *torus, dmnsn_line l, poly[0] = x0x0*x0x0 + R2*(R2 - 2.0*x0x0mod) - r2*(2.0*(R2 + x0x0) - r2); double x[4]; - size_t n = dmnsn_solve_polynomial(poly, 4, x); + size_t n = dmnsn_polynomial_solve(poly, 4, x); if (n == 0) return false; |