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/raytrace.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/raytrace.c')
-rw-r--r-- | libdimension/raytrace.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index 812b6a6..9b87364 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -286,30 +286,28 @@ dmnsn_raytrace_light_ray(const dmnsn_raytrace_state *state, unsigned int reclevel = state->reclevel; while (reclevel) { - dmnsn_intersection *shadow_caster - = dmnsn_bvst_search(state->bvst, shadow_ray); + dmnsn_intersection shadow_caster; + bool shadow_casted + = dmnsn_bvst_search(state->bvst, shadow_ray, &shadow_caster); - if (!shadow_caster || shadow_caster->t > 1.0) { - dmnsn_delete_intersection(shadow_caster); + if (!shadow_casted || shadow_caster.t > 1.0) { break; } dmnsn_raytrace_state shadow_state = *state; - shadow_state.intersection = shadow_caster; + shadow_state.intersection = &shadow_caster; shadow_state.reclevel = reclevel; dmnsn_raytrace_pigment(&shadow_state); if (shadow_state.pigment.filter || shadow_state.pigment.trans) { color = dmnsn_color_filter(color, shadow_state.pigment); - shadow_ray.x0 = dmnsn_line_point(shadow_ray, shadow_caster->t); + shadow_ray.x0 = dmnsn_line_point(shadow_ray, shadow_caster.t); shadow_ray.n = dmnsn_vector_sub(light->x0, shadow_ray.x0); shadow_ray = dmnsn_line_add_epsilon(shadow_ray); } else { - dmnsn_delete_intersection(shadow_caster); return dmnsn_black; } - dmnsn_delete_intersection(shadow_caster); --reclevel; } @@ -448,12 +446,12 @@ dmnsn_raytrace_shoot(dmnsn_raytrace_state *state, dmnsn_line ray) return dmnsn_black; --state->reclevel; - dmnsn_intersection *intersection - = dmnsn_bvst_search(state->bvst, ray); + dmnsn_intersection intersection; + bool intersected = dmnsn_bvst_search(state->bvst, ray, &intersection); dmnsn_color color = state->scene->background; - if (intersection) { - state->intersection = intersection; + if (intersected) { + state->intersection = &intersection; state->r = dmnsn_line_point(state->intersection->ray, state->intersection->t); state->viewer = dmnsn_vector_normalize( @@ -494,8 +492,6 @@ dmnsn_raytrace_shoot(dmnsn_raytrace_state *state, dmnsn_line ray) } color = dmnsn_color_add(state->diffuse, state->additional); - - dmnsn_delete_intersection(intersection); } return color; |