From 8fc5b36510c5964873d88069b61b558bc3ef23f6 Mon Sep 17 00:00:00 2001 From: Julian T Date: Mon, 23 Mar 2020 16:14:53 +0100 Subject: Removed dynamic allocation of color in main.c --- main.c | 8 +++----- ray.c | 6 ++---- ray.h | 2 +- test.png | Bin 693556 -> 693556 bytes 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/main.c b/main.c index 36a9372..0e529ad 100644 --- a/main.c +++ b/main.c @@ -93,12 +93,10 @@ int main() for (int x = TESTW; x; x--) { // Random seed seed = x * y; - color_t *c = ray_trace(&cont->space, x, y, 2, &seed); + color_t c; + ray_trace(&cont->space, x, y, 2, &c, &seed); - if (c) { - pgm_write_pixel(stdout, c); - } - free(c); + pgm_write_pixel(stdout, &c); } diff --git a/ray.c b/ray.c index b2df086..7c86483 100644 --- a/ray.c +++ b/ray.c @@ -309,10 +309,10 @@ exit: return 0; } -color_t *ray_trace(space_t *s, unsigned int x, unsigned int y, unsigned samples, void *seed) +void ray_trace(space_t *s, unsigned int x, unsigned int y, unsigned samples, color_t *c, void *seed) { // Init return color. Will be accumilated with all the detected light. - color_t *c = color_set(NULL, 0, 0, 0); + color_set(c, 0, 0, 0); // Setup primary ray ray_t r; @@ -349,6 +349,4 @@ color_t *ray_trace(space_t *s, unsigned int x, unsigned int y, unsigned samples, // Add ambient color_add(c, c, &s->ambient); - - return c; } diff --git a/ray.h b/ray.h index 4f7fe0c..03756e3 100644 --- a/ray.h +++ b/ray.h @@ -20,7 +20,7 @@ COORD_T ray_intersect_sphere(sphere_t *s, ray_t *ray, bool skip_dist); COORD_T ray_intersect_plane(plane_t *p, ray_t *ray, bool skip_dist); object_t *ray_cast(space_t *s, ray_t *r, COORD_T *dist_ret, bool chk, COORD_T chk_dist); -color_t *ray_trace(space_t *s, unsigned int x, unsigned int y, unsigned samples, void *seed); +void ray_trace(space_t *s, unsigned int x, unsigned int y, unsigned samples, color_t *c, void *seed); #endif diff --git a/test.png b/test.png index 10bb6ce..ae894ba 100644 Binary files a/test.png and b/test.png differ -- cgit v1.2.3