diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-04-07 15:59:49 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-04-07 16:09:22 -0400 |
commit | 7b08644490cc1f897f4c327af839f0b2448351c0 (patch) | |
tree | 7d4fe3dbb0d2dbe8fef27a46f320eac40ecf7298 /libdimension/cube.c | |
parent | 03c4f1bb394e6d0bee61a438937e068ccf57e09d (diff) | |
download | dimension-7b08644490cc1f897f4c327af839f0b2448351c0.tar.xz |
Don't use dynamic memory for dmnsn_intersection's.
Drops us from ~400,000 allocs to ~1000. Oops ><.
Diffstat (limited to 'libdimension/cube.c')
-rw-r--r-- | libdimension/cube.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/libdimension/cube.c b/libdimension/cube.c index 033d2fb..19c67b9 100644 --- a/libdimension/cube.c +++ b/libdimension/cube.c @@ -26,8 +26,9 @@ */ /* Cube callbacks */ -static dmnsn_intersection *dmnsn_cube_intersection_fn(const dmnsn_object *cube, - dmnsn_line line); +static bool dmnsn_cube_intersection_fn(const dmnsn_object *cube, + dmnsn_line line, + dmnsn_intersection *intersection); static bool dmnsn_cube_inside_fn(const dmnsn_object *cube, dmnsn_vector point); @@ -44,12 +45,12 @@ dmnsn_new_cube() } /* Intersections callback for a cube */ -static dmnsn_intersection * -dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line) +static bool +dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line, + dmnsn_intersection *intersection) { double t = -1.0, t_temp; dmnsn_vector p, normal; - dmnsn_intersection *intersection = NULL; /* Six ray-plane intersection tests (x, y, z) = +/- 1.0 */ @@ -120,15 +121,15 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line) } if (t >= 0.0) { - intersection = dmnsn_new_intersection(); intersection->ray = line; intersection->t = t; intersection->normal = normal; intersection->texture = cube->texture; intersection->interior = cube->interior; + return true; + } else { + return false; } - - return intersection; } /* Inside callback for a cube */ |