summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-05-05 20:09:38 -0600
committerTavian Barnes <tavianator@gmail.com>2010-05-05 22:47:44 -0600
commit6c2943e735c99579b5b861f67f2d98e5ddd6306f (patch)
treee882a1dda2726dd9dfca3fe2dd44750b17b1edda /libdimension
parentb14506e501770aeaf54d1160c0073398cc29a038 (diff)
downloaddimension-6c2943e735c99579b5b861f67f2d98e5ddd6306f.tar.xz
Use C99 for loop initializers.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/canvas.c19
-rw-r--r--libdimension/dimension/canvas.h12
-rw-r--r--libdimension/dimension/gl.h4
-rw-r--r--libdimension/geometry.c15
-rw-r--r--libdimension/gl-stubs.c4
-rw-r--r--libdimension/gl.c27
-rw-r--r--libdimension/list.c3
-rw-r--r--libdimension/png.c35
-rw-r--r--libdimension/progress.c5
-rw-r--r--libdimension/prtree.c26
-rw-r--r--libdimension/raytrace.c22
-rw-r--r--libdimension/scene.c5
12 files changed, 78 insertions, 99 deletions
diff --git a/libdimension/canvas.c b/libdimension/canvas.c
index db51cda..4ed7fd5 100644
--- a/libdimension/canvas.c
+++ b/libdimension/canvas.c
@@ -24,7 +24,7 @@
/* Allocate a new canvas, of width x and height y */
dmnsn_canvas *
-dmnsn_new_canvas(unsigned int x, unsigned int y)
+dmnsn_new_canvas(size_t x, size_t y)
{
/* Allocate the dmnsn_canvas struct */
dmnsn_canvas *canvas = dmnsn_malloc(sizeof(dmnsn_canvas));
@@ -46,12 +46,10 @@ dmnsn_new_canvas(unsigned int x, unsigned int y)
void
dmnsn_delete_canvas(dmnsn_canvas *canvas)
{
- unsigned int i;
- dmnsn_canvas_optimizer optimizer;
-
if (canvas) {
/* Free the optimizers */
- for (i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
+ dmnsn_canvas_optimizer optimizer;
dmnsn_array_get(canvas->optimizers, i, &optimizer);
if (optimizer.free_fn) {
(*optimizer.free_fn)(optimizer.ptr);
@@ -74,17 +72,16 @@ dmnsn_optimize_canvas(dmnsn_canvas *canvas, dmnsn_canvas_optimizer optimizer)
/* Set the color of a pixel */
void
-dmnsn_set_pixel(dmnsn_canvas *canvas, unsigned int x, unsigned int y,
+dmnsn_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y,
dmnsn_color color)
{
- unsigned int i;
dmnsn_canvas_optimizer optimizer;
/* Set the pixel */
canvas->pixels[y*canvas->x + x] = color;
/* Call the optimizers */
- for (i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
dmnsn_array_get(canvas->optimizers, i, &optimizer);
(*optimizer.optimizer_fn)(canvas, optimizer, x, y);
}
@@ -94,10 +91,8 @@ dmnsn_set_pixel(dmnsn_canvas *canvas, unsigned int x, unsigned int y,
void
dmnsn_clear_canvas(dmnsn_canvas *canvas, dmnsn_color color)
{
- unsigned int x;
- for (x = 0; x < canvas->x; ++x) {
- unsigned int y;
- for (y = 0; y < canvas->y; ++y) {
+ for (size_t x = 0; x < canvas->x; ++x) {
+ for (size_t y = 0; y < canvas->y; ++y) {
dmnsn_set_pixel(canvas, x, y, color);
}
}
diff --git a/libdimension/dimension/canvas.h b/libdimension/dimension/canvas.h
index 306b55c..7caae69 100644
--- a/libdimension/dimension/canvas.h
+++ b/libdimension/dimension/canvas.h
@@ -25,9 +25,11 @@
#ifndef DIMENSION_CANVAS_H
#define DIMENSION_CANVAS_H
+#include <stddef.h>
+
typedef struct {
/* width, height */
- unsigned int x, y;
+ size_t x, y;
/* An array of dmnsn_canvas_optimizer's */
dmnsn_array *optimizers;
@@ -45,7 +47,7 @@ typedef struct dmnsn_canvas_optimizer dmnsn_canvas_optimizer;
/* Canvas optimizer callback types */
typedef void dmnsn_canvas_optimizer_fn(dmnsn_canvas *canvas,
dmnsn_canvas_optimizer optimizer,
- unsigned int x, unsigned int y);
+ size_t x, size_t y);
/* Canvas optimizer */
struct dmnsn_canvas_optimizer {
@@ -58,7 +60,7 @@ struct dmnsn_canvas_optimizer {
};
/* Allocate and free a canvas */
-dmnsn_canvas *dmnsn_new_canvas(unsigned int x, unsigned int y);
+dmnsn_canvas *dmnsn_new_canvas(size_t x, size_t y);
void dmnsn_delete_canvas(dmnsn_canvas *canvas);
/* Set a canvas optimizer */
@@ -68,12 +70,12 @@ void dmnsn_optimize_canvas(dmnsn_canvas *canvas,
/* Pixel accessors */
DMNSN_INLINE dmnsn_color
-dmnsn_get_pixel(const dmnsn_canvas *canvas, unsigned int x, unsigned int y)
+dmnsn_get_pixel(const dmnsn_canvas *canvas, size_t x, size_t y)
{
return canvas->pixels[y*canvas->x + x];
}
-void dmnsn_set_pixel(dmnsn_canvas *canvas, unsigned int x, unsigned int y,
+void dmnsn_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y,
dmnsn_color color);
void dmnsn_clear_canvas(dmnsn_canvas *canvas, dmnsn_color color);
diff --git a/libdimension/dimension/gl.h b/libdimension/dimension/gl.h
index fb68229..d1b23f7 100644
--- a/libdimension/dimension/gl.h
+++ b/libdimension/dimension/gl.h
@@ -33,7 +33,7 @@ int dmnsn_gl_optimize_canvas(dmnsn_canvas *canvas);
int dmnsn_gl_write_canvas(const dmnsn_canvas *canvas);
/* Read a canvas from a GL framebuffer. Returns NULL on failure. */
-dmnsn_canvas *dmnsn_gl_read_canvas(unsigned int x0, unsigned int y0,
- unsigned int width, unsigned int height);
+dmnsn_canvas *dmnsn_gl_read_canvas(size_t x0, size_t y0,
+ size_t width, size_t height);
#endif /* DIMENSION_GL_H */
diff --git a/libdimension/geometry.c b/libdimension/geometry.c
index faeb30b..50a6869 100644
--- a/libdimension/geometry.c
+++ b/libdimension/geometry.c
@@ -244,24 +244,23 @@ dmnsn_matrix_inverse_generic(dmnsn_matrix A)
*/
dmnsn_matrix inv;
double det = 0.0, C;
- unsigned int i, j;
/* Perform a Laplace expansion along the first row to give us the adjugate's
first column and the determinant */
- for (j = 0; j < 4; ++j) {
+ for (size_t j = 0; j < 4; ++j) {
C = dmnsn_matrix_cofactor(A, 0, j);
det += A.n[0][j]*C;
inv.n[j][0] = C;
}
/* Divide the first column by the determinant */
- for (j = 0; j < 4; ++j) {
+ for (size_t j = 0; j < 4; ++j) {
inv.n[j][0] /= det;
}
/* Find columns 2 through 4 */
- for (i = 1; i < 4; ++i) {
- for (j = 0; j < 4; ++j) {
+ for (size_t i = 1; i < 4; ++i) {
+ for (size_t j = 0; j < 4; ++j) {
inv.n[j][i] = dmnsn_matrix_cofactor(A, i, j)/det;
}
}
@@ -276,10 +275,10 @@ dmnsn_matrix_cofactor(dmnsn_matrix A, unsigned int row, unsigned int col)
{
/* 9 multiplications, 5 additions */
double n[9], C;
- unsigned int i, j, k = 0;
+ unsigned int k = 0;
- for (i = 0; i < 4; ++i) {
- for (j = 0; j < 4; ++j) {
+ for (size_t i = 0; i < 4; ++i) {
+ for (size_t j = 0; j < 4; ++j) {
if (i != row && j != col) {
n[k] = A.n[i][j];
++k;
diff --git a/libdimension/gl-stubs.c b/libdimension/gl-stubs.c
index 4c0d8b4..1d6946d 100644
--- a/libdimension/gl-stubs.c
+++ b/libdimension/gl-stubs.c
@@ -38,8 +38,8 @@ dmnsn_gl_write_canvas(const dmnsn_canvas *canvas)
}
dmnsn_canvas *
-dmnsn_gl_read_canvas(unsigned int x0, unsigned int y0,
- unsigned int width, unsigned int height)
+dmnsn_gl_read_canvas(size_t x0, size_t y0,
+ size_t width, size_t height)
{
errno = ENOTSUP;
return NULL;
diff --git a/libdimension/gl.c b/libdimension/gl.c
index c93a3c4..84dcc91 100644
--- a/libdimension/gl.c
+++ b/libdimension/gl.c
@@ -26,17 +26,16 @@
/* GL optimizer callback */
static void dmnsn_gl_optimizer_fn(dmnsn_canvas *canvas,
dmnsn_canvas_optimizer optimizer,
- unsigned int x, unsigned int y);
+ size_t x, size_t y);
/* Optimize canvas for GL drawing */
int
dmnsn_gl_optimize_canvas(dmnsn_canvas *canvas)
{
dmnsn_canvas_optimizer optimizer;
- unsigned int i;
/* Check if we've already optimized this canvas */
- for (i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
dmnsn_array_get(canvas->optimizers, i, &optimizer);
if (optimizer.optimizer_fn == &dmnsn_gl_optimizer_fn) {
return 0;
@@ -63,13 +62,12 @@ dmnsn_gl_write_canvas(const dmnsn_canvas *canvas)
GLushort *pixel;
dmnsn_sRGB sRGB;
dmnsn_color color;
- unsigned int i, x, y, width, height;
- width = canvas->x;
- height = canvas->y;
+ size_t width = canvas->x;
+ size_t height = canvas->y;
/* Check if we can optimize this */
- for (i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
dmnsn_array_get(canvas->optimizers, i, &optimizer);
if (optimizer.optimizer_fn == &dmnsn_gl_optimizer_fn) {
glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_SHORT, optimizer.ptr);
@@ -80,8 +78,8 @@ dmnsn_gl_write_canvas(const dmnsn_canvas *canvas)
/* We couldn't, so transform the canvas to RGB now */
pixels = dmnsn_malloc(4*width*height*sizeof(GLushort));
- for (y = 0; y < height; ++y) {
- for (x = 0; x < width; ++x) {
+ for (size_t y = 0; y < height; ++y) {
+ for (size_t x = 0; x < width; ++x) {
pixel = pixels + 4*(y*width + x);
color = dmnsn_get_pixel(canvas, x, y);
@@ -126,15 +124,14 @@ dmnsn_gl_write_canvas(const dmnsn_canvas *canvas)
/* Read a canvas from a GL framebuffer. Returns NULL on failure. */
dmnsn_canvas *
-dmnsn_gl_read_canvas(unsigned int x0, unsigned int y0,
- unsigned int width, unsigned int height)
+dmnsn_gl_read_canvas(size_t x0, size_t y0,
+ size_t width, size_t height)
{
dmnsn_canvas *canvas;
GLushort *pixels; /* Array of 16-bit ints in RGBA order */
GLushort *pixel;
dmnsn_sRGB sRGB;
dmnsn_color color;
- unsigned int x, y;
canvas = dmnsn_new_canvas(width, height);
pixels = dmnsn_malloc(4*width*height*sizeof(GLushort));
@@ -147,8 +144,8 @@ dmnsn_gl_read_canvas(unsigned int x0, unsigned int y0,
return NULL;
}
- for (y = 0; y < height; ++y) {
- for (x = 0; x < width; ++x) {
+ for (size_t y = 0; y < height; ++y) {
+ for (size_t x = 0; x < width; ++x) {
pixel = pixels + 4*(y*width + x);
sRGB.R = ((double)pixel[0])/UINT16_MAX;
@@ -168,7 +165,7 @@ dmnsn_gl_read_canvas(unsigned int x0, unsigned int y0,
/* GL optimizer callback */
static void
dmnsn_gl_optimizer_fn(dmnsn_canvas *canvas, dmnsn_canvas_optimizer optimizer,
- unsigned int x, unsigned int y)
+ size_t x, size_t y)
{
dmnsn_color color;
dmnsn_sRGB sRGB;
diff --git a/libdimension/list.c b/libdimension/list.c
index 0bd8f1e..5b03209 100644
--- a/libdimension/list.c
+++ b/libdimension/list.c
@@ -25,8 +25,7 @@ dmnsn_list_from_array(const dmnsn_array *array)
{
dmnsn_list *list = dmnsn_new_list(array->obj_size);
- size_t i;
- for (i = 0; i < dmnsn_array_size(array); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(array); ++i) {
dmnsn_list_push(list, dmnsn_array_at(array, i));
}
diff --git a/libdimension/png.c b/libdimension/png.c
index 76bace9..021b9f2 100644
--- a/libdimension/png.c
+++ b/libdimension/png.c
@@ -30,17 +30,16 @@
/* PNG optimizer callback */
static void dmnsn_png_optimizer_fn(dmnsn_canvas *canvas,
dmnsn_canvas_optimizer optimizer,
- unsigned int x, unsigned int y);
+ size_t x, size_t y);
/* Optimize canvas for PNG exporting */
int
dmnsn_png_optimize_canvas(dmnsn_canvas *canvas)
{
dmnsn_canvas_optimizer optimizer;
- unsigned int i;
/* Check if we've already optimized this canvas */
- for (i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
dmnsn_array_get(canvas->optimizers, i, &optimizer);
if (optimizer.optimizer_fn == &dmnsn_png_optimizer_fn) {
return 0;
@@ -59,7 +58,7 @@ dmnsn_png_optimize_canvas(dmnsn_canvas *canvas)
/* PNG optimizer callback */
static void
dmnsn_png_optimizer_fn(dmnsn_canvas *canvas, dmnsn_canvas_optimizer optimizer,
- unsigned int x, unsigned int y)
+ size_t x, size_t y)
{
dmnsn_color color;
dmnsn_sRGB sRGB;
@@ -231,7 +230,6 @@ dmnsn_png_write_canvas_impl(dmnsn_progress *progress,
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 width, height;
- unsigned int i, x, y;
uint16_t *row = NULL;
dmnsn_color color;
dmnsn_sRGB sRGB;
@@ -289,10 +287,10 @@ dmnsn_png_write_canvas_impl(dmnsn_progress *progress,
}
/* Check if we can optimize this */
- for (i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
dmnsn_array_get(canvas->optimizers, i, &optimizer);
if (optimizer.optimizer_fn == &dmnsn_png_optimizer_fn) {
- for (y = 0; y < height; ++y) {
+ for (size_t y = 0; y < height; ++y) {
/* Invert the rows. PNG coordinates are fourth quadrant. */
uint16_t *row = (uint16_t *)optimizer.ptr + 4*(height - y - 1)*width;
png_write_row(png_ptr, (png_bytep)row);
@@ -310,8 +308,8 @@ dmnsn_png_write_canvas_impl(dmnsn_progress *progress,
row = dmnsn_malloc(4*sizeof(uint16_t)*width);
/* Write the pixels */
- for (y = 0; y < height; ++y) {
- for (x = 0; x < width; ++x) {
+ for (size_t y = 0; y < height; ++y) {
+ for (size_t x = 0; x < width; ++x) {
/* Invert the rows. PNG coordinates are fourth quadrant. */
color = dmnsn_get_pixel(canvas, x, height - y - 1);
sRGB = dmnsn_sRGB_from_color(color);
@@ -388,7 +386,6 @@ dmnsn_png_read_canvas_impl(dmnsn_progress *progress, FILE *file)
number_of_passes;
png_bytep image = NULL;
png_bytep *row_pointers = NULL;
- unsigned int x, y;
dmnsn_color color;
dmnsn_sRGB sRGB;
png_bytep png_pixel;
@@ -500,7 +497,7 @@ dmnsn_png_read_canvas_impl(dmnsn_progress *progress, FILE *file)
/* Allocate and set an array of pointers to rows in image */
row_pointers = dmnsn_malloc(sizeof(png_bytep)*height);
- for (y = 0; y < height; ++y) {
+ for (size_t y = 0; y < height; ++y) {
row_pointers[y] = image + y*rowbytes;
}
@@ -517,8 +514,8 @@ dmnsn_png_read_canvas_impl(dmnsn_progress *progress, FILE *file)
loops, although that doesn't really matter for a decent compiler. */
if (bit_depth == 16) {
if (color_type & PNG_COLOR_MASK_ALPHA) {
- for (y = 0; y < height; ++y) {
- for (x = 0; x < width; ++x) {
+ for (size_t y = 0; y < height; ++y) {
+ for (size_t x = 0; x < width; ++x) {
png_pixel = image + 8*(y*width + x);
sRGB.R = ((double)((png_pixel[0] << UINT16_C(8)) + png_pixel[1]))
@@ -536,8 +533,8 @@ dmnsn_png_read_canvas_impl(dmnsn_progress *progress, FILE *file)
dmnsn_increment_progress(progress);
}
} else {
- for (y = 0; y < height; ++y) {
- for (x = 0; x < width; ++x) {
+ for (size_t y = 0; y < height; ++y) {
+ for (size_t x = 0; x < width; ++x) {
png_pixel = image + 6*(y*width + x);
sRGB.R = ((double)((png_pixel[0] << UINT16_C(8)) + png_pixel[1]))
@@ -556,8 +553,8 @@ dmnsn_png_read_canvas_impl(dmnsn_progress *progress, FILE *file)
} else {
/* Bit depth is 8 */
if (color_type & PNG_COLOR_MASK_ALPHA) {
- for (y = 0; y < height; ++y) {
- for (x = 0; x < width; ++x) {
+ for (size_t y = 0; y < height; ++y) {
+ for (size_t x = 0; x < width; ++x) {
png_pixel = image + 4*(y*width + x);
sRGB.R = ((double)png_pixel[0])/UINT8_MAX;
@@ -571,8 +568,8 @@ dmnsn_png_read_canvas_impl(dmnsn_progress *progress, FILE *file)
dmnsn_increment_progress(progress);
}
} else {
- for (y = 0; y < height; ++y) {
- for (x = 0; x < width; ++x) {
+ for (size_t y = 0; y < height; ++y) {
+ for (size_t x = 0; x < width; ++x) {
png_pixel = image + 3*(y*width + x);
sRGB.R = ((double)png_pixel[0])/UINT8_MAX;
diff --git a/libdimension/progress.c b/libdimension/progress.c
index 515fd81..81cafab 100644
--- a/libdimension/progress.c
+++ b/libdimension/progress.c
@@ -108,11 +108,10 @@ dmnsn_get_progress(const dmnsn_progress *progress)
{
dmnsn_progress_element *element;
double prog = 0.0;
- unsigned int i, size;
dmnsn_progress_rdlock(progress);
- size = dmnsn_array_size(progress->elements);
- for (i = 0; i < size; ++i) {
+ size_t size = dmnsn_array_size(progress->elements);
+ for (size_t i = 0; i < size; ++i) {
element = dmnsn_array_at(progress->elements, size - i - 1);
prog += element->progress;
prog /= element->total;
diff --git a/libdimension/prtree.c b/libdimension/prtree.c
index baf41b0..6c9371c 100644
--- a/libdimension/prtree.c
+++ b/libdimension/prtree.c
@@ -219,8 +219,10 @@ dmnsn_priority_search(dmnsn_list *leaves, bool are_objects, int comparator)
if (i) {
double candidate = dmnsn_priority_get(i, are_objects, comparator);
- dmnsn_list_iterator *j;
- for (j = dmnsn_list_next(i); j != NULL; j = dmnsn_list_next(j)) {
+ for (dmnsn_list_iterator *j = dmnsn_list_next(i);
+ j != NULL;
+ j = dmnsn_list_next(j))
+ {
double new_candidate = dmnsn_priority_get(j, are_objects, comparator);
if (new_candidate < candidate) {
candidate = new_candidate;
@@ -286,13 +288,12 @@ dmnsn_new_pseudo_prtree(dmnsn_list *leaves, bool are_objects, int comparator)
} else {
/* Make an internal node */
pseudo->is_leaf = false;
- size_t i;
- for (i = 0; i < 6; ++i) {
+ for (size_t i = 0; i < 6; ++i) {
pseudo->node.children[i].is_leaf = are_objects;
}
/* Fill the priority leaves */
- size_t j;
+ size_t i, j;
for (i = 0; i < DMNSN_PRTREE_B; ++i) {
for (j = 0; j < 6; ++j) {
dmnsn_list_iterator *k = dmnsn_priority_search(leaves, are_objects, j);
@@ -377,8 +378,7 @@ dmnsn_new_prtree_node(const dmnsn_pseudo_prleaf *leaf)
node->is_leaf = leaf->is_leaf;
node->bounding_box = leaf->bounding_box;
- size_t i;
- for (i = 0; i < DMNSN_PRTREE_B; ++i) {
+ for (size_t i = 0; i < DMNSN_PRTREE_B; ++i) {
node->children[i] = leaf->children[i];
}
@@ -403,8 +403,7 @@ dmnsn_pseudo_prtree_leaves_recursive(const dmnsn_pseudo_prtree *node,
if (node->is_leaf) {
dmnsn_pseudo_prtree_add_leaf(&node->leaf, leaves);
} else {
- size_t i;
- for (i = 0; i < 6; ++i) {
+ for (size_t i = 0; i < 6; ++i) {
dmnsn_pseudo_prtree_add_leaf(&node->node.children[i], leaves);
}
dmnsn_pseudo_prtree_leaves_recursive(node->node.left, leaves);
@@ -431,8 +430,7 @@ dmnsn_pseudo_prtree_leaves(const dmnsn_pseudo_prtree *pseudo)
dmnsn_prtree *
dmnsn_new_prtree(const dmnsn_array *objects)
{
- size_t i;
- for (i = 0; i < dmnsn_array_size(objects); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(objects); ++i) {
dmnsn_object *object;
dmnsn_array_get(objects, i, &object);
dmnsn_object_precompute(object);
@@ -463,8 +461,7 @@ dmnsn_delete_prtree(dmnsn_prtree *tree)
{
if (tree) {
if (!tree->is_leaf) {
- size_t i;
- for (i = 0; i < DMNSN_PRTREE_B; ++i) {
+ for (size_t i = 0; i < DMNSN_PRTREE_B; ++i) {
dmnsn_delete_prtree(tree->children[i]);
}
}
@@ -480,8 +477,7 @@ dmnsn_prtree_search_recursive(const dmnsn_prtree *node, dmnsn_line ray,
dmnsn_intersection *intersection, double *t)
{
if (dmnsn_ray_box_intersection(ray, node->bounding_box, *t)) {
- size_t i;
- for (i = 0; i < DMNSN_PRTREE_B; ++i) {
+ for (size_t i = 0; i < DMNSN_PRTREE_B; ++i) {
if (!node->children[i])
break;
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c
index 8946303..f5d0885 100644
--- a/libdimension/raytrace.c
+++ b/libdimension/raytrace.c
@@ -96,7 +96,7 @@ dmnsn_raytrace_scene_multithread(dmnsn_raytrace_payload *payload)
dmnsn_raytrace_payload *payloads;
pthread_t *threads;
- unsigned int nthreads = payload->scene->nthreads;
+ int nthreads = payload->scene->nthreads;
/* Sanity check */
if (nthreads < 1)
nthreads = 1;
@@ -109,15 +109,14 @@ dmnsn_raytrace_scene_multithread(dmnsn_raytrace_payload *payload)
payload->scene->canvas->y);
/* Create the payloads */
- unsigned int i;
- for (i = 0; i < nthreads; ++i) {
+ for (int i = 0; i < nthreads; ++i) {
payloads[i] = *payload;
payloads[i].index = i;
payloads[i].threads = nthreads;
}
/* Create the threads */
- for (i = 0; i < nthreads; ++i) {
+ for (int i = 0; i < nthreads; ++i) {
if (pthread_create(&threads[i], NULL,
&dmnsn_raytrace_scene_multithread_thread,
&payloads[i]) != 0)
@@ -127,7 +126,7 @@ dmnsn_raytrace_scene_multithread(dmnsn_raytrace_payload *payload)
}
}
- for (i = 0; i < nthreads; ++i) {
+ for (int i = 0; i < nthreads; ++i) {
if (pthread_join(threads[i], NULL)) {
dmnsn_error(DMNSN_SEVERITY_MEDIUM,
"Couldn't join worker thread in raytrace engine.");
@@ -194,14 +193,12 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene,
.ior = 1.0
};
- unsigned int width = scene->canvas->x;
- unsigned int height = scene->canvas->y;
+ size_t width = scene->canvas->x;
+ size_t height = scene->canvas->y;
/* Iterate through each pixel */
- unsigned int y;
- for (y = index; y < height; y += threads) {
- unsigned int x;
- for (x = 0; x < width; ++x) {
+ for (size_t y = index; y < height; y += threads) {
+ for (size_t x = 0; x < width; ++x) {
/* Set the pixel to the background color */
dmnsn_color color = scene->background;
@@ -319,10 +316,9 @@ dmnsn_raytrace_lighting(dmnsn_raytrace_state *state)
}
const dmnsn_light *light;
- unsigned int i;
/* Iterate over each light */
- for (i = 0; i < dmnsn_array_size(state->scene->lights); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(state->scene->lights); ++i) {
dmnsn_array_get(state->scene->lights, i, &light);
dmnsn_color light_color = dmnsn_raytrace_light_ray(state, light);
diff --git a/libdimension/scene.c b/libdimension/scene.c
index 48ca702..177e7fe 100644
--- a/libdimension/scene.c
+++ b/libdimension/scene.c
@@ -50,16 +50,15 @@ void
dmnsn_delete_scene(dmnsn_scene *scene)
{
if (scene) {
- unsigned int i;
dmnsn_light *light;
dmnsn_object *object;
- for (i = 0; i < dmnsn_array_size(scene->lights); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(scene->lights); ++i) {
dmnsn_array_get(scene->lights, i, &light);
dmnsn_delete_light(light);
}
- for (i = 0; i < dmnsn_array_size(scene->objects); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(scene->objects); ++i) {
dmnsn_array_get(scene->objects, i, &object);
dmnsn_delete_object(object);
}