From 7b08644490cc1f897f4c327af839f0b2448351c0 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 7 Apr 2010 15:59:49 -0400 Subject: Don't use dynamic memory for dmnsn_intersection's. Drops us from ~400,000 allocs to ~1000. Oops ><. --- libdimension/raytrace.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'libdimension/raytrace.c') 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; -- cgit v1.2.3