summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bench/libdimension/array.c9
-rw-r--r--bench/libdimension/prtree.c7
-rw-r--r--configure.ac3
-rw-r--r--dimension/common.prologue3
-rw-r--r--dimension/common.rules6
-rw-r--r--dimension/directives.rules9
-rw-r--r--dimension/lexer.l6
-rw-r--r--dimension/parse.c39
-rw-r--r--dimension/progressbar.c4
-rw-r--r--dimension/realize.c33
-rw-r--r--dimension/tokenize.c5
-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
-rw-r--r--tests/libdimension/prtree.c3
24 files changed, 127 insertions, 177 deletions
diff --git a/bench/libdimension/array.c b/bench/libdimension/array.c
index dae7c98..f9ac22d 100644
--- a/bench/libdimension/array.c
+++ b/bench/libdimension/array.c
@@ -29,7 +29,6 @@ main()
uint32_t object = 1;
void *ptr;
size_t size;
- unsigned int i;
const unsigned int count = 32;
sandglass_t sandglass;
@@ -53,7 +52,7 @@ main()
printf("dmnsn_array_push():");
- for (i = 0; i < count; ++i) {
+ for (unsigned int i = 0; i < count; ++i) {
sandglass_bench_noprecache(&sandglass, dmnsn_array_push(array, &object));
printf(" %ld", sandglass.grains);
}
@@ -87,7 +86,7 @@ main()
printf("dmnsn_array_insert():");
- for (i = 0; i < count; ++i) {
+ for (size_t i = 0; i < count; ++i) {
sandglass_bench_noprecache(&sandglass,
dmnsn_array_insert(array, count/2, &object));
printf(" %ld", sandglass.grains);
@@ -98,7 +97,7 @@ main()
printf("dmnsn_array_remove():");
- for (i = 0; i < count; ++i) {
+ for (size_t i = 0; i < count; ++i) {
sandglass_bench_noprecache(&sandglass,
dmnsn_array_remove(array, count/2));
printf(" %ld", sandglass.grains);
@@ -109,7 +108,7 @@ main()
printf("dmnsn_array_pop():");
- for (i = 0; i < count; ++i) {
+ for (size_t i = 0; i < count; ++i) {
sandglass_bench_noprecache(&sandglass, dmnsn_array_pop(array, &object));
printf(" %ld", sandglass.grains);
}
diff --git a/bench/libdimension/prtree.c b/bench/libdimension/prtree.c
index b3bee13..d4b3ed7 100644
--- a/bench/libdimension/prtree.c
+++ b/bench/libdimension/prtree.c
@@ -52,9 +52,8 @@ main()
dmnsn_prtree *tree;
dmnsn_intersection intersection;
dmnsn_line ray;
- const unsigned int nobjects = 128;
+ const size_t nobjects = 128;
dmnsn_array *objects;
- unsigned int i;
sandglass_t sandglass;
if (sandglass_init_monotonic(&sandglass, SANDGLASS_CPUTIME) != 0) {
@@ -63,7 +62,7 @@ main()
}
objects = dmnsn_new_array(sizeof(dmnsn_object *));
- for (i = 0; i < nobjects; ++i) {
+ for (size_t i = 0; i < nobjects; ++i) {
dmnsn_object *object = dmnsn_new_object();
/* Generate a bounding box in (-1, -1, -1), (1, 1, 1) */
dmnsn_randomize_bounding_box(object);
@@ -87,7 +86,7 @@ main()
/* Cleanup */
dmnsn_delete_prtree(tree);
- for (i = 0; i < nobjects; ++i) {
+ for (size_t i = 0; i < nobjects; ++i) {
dmnsn_object *object;
dmnsn_array_get(objects, i, &object);
dmnsn_delete_object(object);
diff --git a/configure.ac b/configure.ac
index 4ffb5a7..0a90faa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,6 +20,9 @@ AC_INIT(Dimension, 0.0.0, tavianator@gmail.com, dimension,
[http://dmnsn.googlecode.com])
AM_INIT_AUTOMAKE([parallel-tests])
+dnl Use C99 mode with GNU extensions
+CFLAGS="-std=gnu99 $CFLAGS"
+
dnl Programs
AC_PROG_CC
AM_PROG_CC_C_O
diff --git a/dimension/common.prologue b/dimension/common.prologue
index 4fdfcee..8bbeaea 100644
--- a/dimension/common.prologue
+++ b/dimension/common.prologue
@@ -65,8 +65,7 @@ dmnsn_new_astnode(dmnsn_astnode_type type, YYLTYPE lloc)
static void
dmnsn_copy_children(dmnsn_astnode dest, dmnsn_astnode src)
{
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(src.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(src.children); ++i) {
dmnsn_astnode node;
dmnsn_array_get(src.children, i, &node);
++*node.refcount;
diff --git a/dimension/common.rules b/dimension/common.rules
index 9a72b44..4644627 100644
--- a/dimension/common.rules
+++ b/dimension/common.rules
@@ -152,8 +152,7 @@ OBJECT: FINITE_SOLID_OBJECT
*modifiers = dmnsn_new_astnode(DMNSN_AST_OBJECT_MODIFIERS, @4);
dmnsn_copy_children(*modifiers, orig_modifiers);
- unsigned int i;
- for (i = 0; i < dmnsn_array_size($4.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size($4.children); ++i) {
dmnsn_astnode astnode;
dmnsn_array_get($4.children, i, &astnode);
++*astnode.refcount;
@@ -186,8 +185,7 @@ OBJECT: FINITE_SOLID_OBJECT
dmnsn_array_size($$.children) - 1,
&modifiers);
- unsigned int i;
- for (i = 0; i < dmnsn_array_size($4.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size($4.children); ++i) {
dmnsn_astnode astnode;
dmnsn_array_get($4.children, i, &astnode);
++*astnode.refcount;
diff --git a/dimension/directives.rules b/dimension/directives.rules
index e199fe3..84358f6 100644
--- a/dimension/directives.rules
+++ b/dimension/directives.rules
@@ -77,19 +77,18 @@ LANGUAGE_DIRECTIVE: "#include" STRING {
"Attempt to expand non-macro.");
dmnsn_delete_astnode($1);
- unsigned int nparams = dmnsn_array_size(node->children);
- unsigned int nparams_given = dmnsn_array_size($3.children);
+ size_t nparams = dmnsn_array_size(node->children);
+ size_t nparams_given = dmnsn_array_size($3.children);
if (nparams_given != nparams) {
dmnsn_diagnostic(@$, "wrong number of macro arguments"
- " (%u; should be %u)",
+ " (%zu; should be %zu)",
nparams_given, nparams);
dmnsn_delete_astnode($3);
YYERROR;
}
- unsigned int i;
- for (i = 0; i < nparams; ++i) {
+ for (size_t i = 0; i < nparams; ++i) {
dmnsn_astnode id, param;
dmnsn_array_get(node->children, i, &id);
dmnsn_array_get($3.children, i, &param);
diff --git a/dimension/lexer.l b/dimension/lexer.l
index 1abb4b8..6198fea 100644
--- a/dimension/lexer.l
+++ b/dimension/lexer.l
@@ -422,8 +422,7 @@ void
dmnsn_delete_tokens(dmnsn_array *tokens)
{
dmnsn_token token;
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(tokens); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(tokens); ++i) {
dmnsn_array_get(tokens, i, &token);
dmnsn_delete_token(token);
}
@@ -455,7 +454,6 @@ void
dmnsn_print_token_sexpr(FILE *file, const dmnsn_array *tokens)
{
dmnsn_token token;
- unsigned int i;
if (dmnsn_array_size(tokens) == 0) {
fprintf(file, "()");
@@ -464,7 +462,7 @@ dmnsn_print_token_sexpr(FILE *file, const dmnsn_array *tokens)
dmnsn_array_get(tokens, 0, &token);
dmnsn_print_token(file, token);
- for (i = 1; i < dmnsn_array_size(tokens); ++i) {
+ for (size_t i = 1; i < dmnsn_array_size(tokens); ++i) {
fprintf(file, " ");
dmnsn_array_get(tokens, i, &token);
dmnsn_print_token(file, token);
diff --git a/dimension/parse.c b/dimension/parse.c
index 802a3e5..da22cb2 100644
--- a/dimension/parse.c
+++ b/dimension/parse.c
@@ -44,8 +44,7 @@ dmnsn_delete_patricia_trie(dmnsn_patricia_trie *trie)
if (trie->leaf)
dmnsn_delete_astnode(trie->value);
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(trie->children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(trie->children); ++i) {
dmnsn_patricia_trie *subtrie;
dmnsn_array_get(trie->children, i, &subtrie);
dmnsn_delete_patricia_trie(subtrie);
@@ -289,8 +288,7 @@ dmnsn_declare_symbol(dmnsn_symbol_table *symtable,
void
dmnsn_undef_symbol(dmnsn_symbol_table *symtable, const char *id)
{
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(symtable); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(symtable); ++i) {
dmnsn_patricia_trie *trie;
dmnsn_array_get(symtable, dmnsn_array_size(symtable) - i - 1, &trie);
if (dmnsn_patricia_remove(trie, id))
@@ -303,8 +301,7 @@ dmnsn_find_symbol(dmnsn_symbol_table *symtable, const char *id)
{
dmnsn_astnode *symbol = NULL;
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(symtable); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(symtable); ++i) {
dmnsn_patricia_trie *trie;
dmnsn_array_get(symtable, dmnsn_array_size(symtable) - i - 1, &trie);
@@ -472,8 +469,7 @@ void
dmnsn_delete_astree(dmnsn_astree *astree)
{
if (astree) {
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(astree); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(astree); ++i) {
dmnsn_astnode node;
dmnsn_array_get(astree, i, &node);
dmnsn_delete_astnode(node);
@@ -518,8 +514,7 @@ dmnsn_vector_promote(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
if (astnode.type == DMNSN_AST_VECTOR) {
dmnsn_astnode component;
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(astnode.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(astnode.children); ++i) {
dmnsn_array_get(astnode.children, i, &component);
component = dmnsn_eval_scalar(component, symtable);
@@ -609,8 +604,6 @@ dmnsn_eval_zeroary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
static dmnsn_astnode
dmnsn_eval_unary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
{
- unsigned int i;
-
dmnsn_astnode rhs;
dmnsn_array_get(astnode.children, 0, &rhs);
rhs = dmnsn_eval(rhs, symtable);
@@ -684,7 +677,7 @@ dmnsn_eval_unary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_astnode op = dmnsn_copy_astnode(astnode);
dmnsn_array_resize(op.children, 1);
- for (i = 0; i < DMNSN_VECTOR_NELEM; ++i) {
+ for (size_t i = 0; i < DMNSN_VECTOR_NELEM; ++i) {
dmnsn_array_get(rhs.children, i, dmnsn_array_at(op.children, 0));
dmnsn_astnode temp = dmnsn_eval_unary(op, symtable);
dmnsn_array_set(ret.children, i, &temp);
@@ -957,8 +950,6 @@ dmnsn_eval_unary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
static dmnsn_astnode
dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
{
- unsigned int i;
-
dmnsn_astnode lhs, rhs;
dmnsn_array_get(astnode.children, 0, &lhs);
dmnsn_array_get(astnode.children, 1, &rhs);
@@ -998,7 +989,7 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_array_push(rewrite.children, &l);
dmnsn_array_push(rewrite.children, &r);
- for (i = 1; i < DMNSN_VECTOR_NELEM; ++i) {
+ for (size_t i = 1; i < DMNSN_VECTOR_NELEM; ++i) {
dmnsn_astnode temp = dmnsn_copy_astnode(astnode);
dmnsn_array_get(lhs.children, i, &l);
dmnsn_array_get(rhs.children, i, &r);
@@ -1031,7 +1022,7 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_array_push(rewrite.children, &l);
dmnsn_array_push(rewrite.children, &r);
- for (i = 1; i < DMNSN_VECTOR_NELEM; ++i) {
+ for (size_t i = 1; i < DMNSN_VECTOR_NELEM; ++i) {
dmnsn_astnode temp = dmnsn_copy_astnode(astnode);
dmnsn_array_get(lhs.children, i, &l);
dmnsn_array_get(rhs.children, i, &r);
@@ -1065,7 +1056,7 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_array_push(rewrite.children, &l);
dmnsn_array_push(rewrite.children, &r);
- for (i = 1; i < DMNSN_VECTOR_NELEM; ++i) {
+ for (size_t i = 1; i < DMNSN_VECTOR_NELEM; ++i) {
dmnsn_astnode temp = dmnsn_copy_astnode(astnode);
temp.type = DMNSN_AST_OR;
dmnsn_array_get(lhs.children, i, &l);
@@ -1100,7 +1091,7 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_array_push(rewrite.children, &l);
dmnsn_array_push(rewrite.children, &r);
- for (i = 1; i < DMNSN_VECTOR_NELEM; ++i) {
+ for (size_t i = 1; i < DMNSN_VECTOR_NELEM; ++i) {
dmnsn_astnode temp = dmnsn_copy_astnode(astnode);
temp.type = DMNSN_AST_OR;
dmnsn_array_get(lhs.children, i, &l);
@@ -1218,7 +1209,7 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_array_push(rewrite.children, &l);
dmnsn_array_push(rewrite.children, &r);
- for (i = 1; i < 3; ++i) {
+ for (size_t i = 1; i < 3; ++i) {
dmnsn_astnode temp = dmnsn_copy_astnode(astnode);
temp.type = DMNSN_AST_MUL;
dmnsn_array_get(lhs.children, i, &l);
@@ -1288,7 +1279,7 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_astnode op = dmnsn_copy_astnode(astnode);
dmnsn_array_resize(op.children, 2);
- for (i = 0; i < DMNSN_VECTOR_NELEM; ++i) {
+ for (size_t i = 0; i < DMNSN_VECTOR_NELEM; ++i) {
dmnsn_array_get(lhs.children, i, dmnsn_array_at(op.children, 0));
dmnsn_array_get(rhs.children, i, dmnsn_array_at(op.children, 1));
dmnsn_astnode temp = dmnsn_eval_binary(op, symtable);
@@ -1780,13 +1771,12 @@ dmnsn_print_astnode(FILE *file, dmnsn_astnode astnode)
static void
dmnsn_print_astree(FILE *file, dmnsn_astnode astnode)
{
- unsigned int i;
dmnsn_astnode child;
if (astnode.children && dmnsn_array_size(astnode.children) > 0) {
fprintf(file, "(");
dmnsn_print_astnode(file, astnode);
- for (i = 0; i < dmnsn_array_size(astnode.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(astnode.children); ++i) {
dmnsn_array_get(astnode.children, i, &child);
fprintf(file, " ");
dmnsn_print_astree(file, child);
@@ -1801,7 +1791,6 @@ void
dmnsn_print_astree_sexpr(FILE *file, const dmnsn_astree *astree)
{
dmnsn_astnode astnode;
- unsigned int i;
if (dmnsn_array_size(astree) == 0) {
fprintf(file, "()");
@@ -1810,7 +1799,7 @@ dmnsn_print_astree_sexpr(FILE *file, const dmnsn_astree *astree)
dmnsn_array_get(astree, 0, &astnode);
dmnsn_print_astree(file, astnode);
- for (i = 1; i < dmnsn_array_size(astree); ++i) {
+ for (size_t i = 1; i < dmnsn_array_size(astree); ++i) {
fprintf(file, " ");
dmnsn_array_get(astree, i, &astnode);
dmnsn_print_astree(file, astnode);
diff --git a/dimension/progressbar.c b/dimension/progressbar.c
index 6abcbd6..a8bf11c 100644
--- a/dimension/progressbar.c
+++ b/dimension/progressbar.c
@@ -45,8 +45,8 @@ dmnsn_progressbar(const char *format, const dmnsn_progress *progress, ...)
width = ws.ws_col;
}
- unsigned int i, increments = width - (len % width);
- for (i = 0; i < increments; ++i) {
+ unsigned int increments = width - (len % width);
+ for (unsigned int i = 0; i < increments; ++i) {
dmnsn_wait_progress(progress, ((double)(i + 1))/increments);
printf(".");
diff --git a/dimension/realize.c b/dimension/realize.c
index 6771782..05eae07 100644
--- a/dimension/realize.c
+++ b/dimension/realize.c
@@ -190,8 +190,7 @@ dmnsn_realize_global_settings(dmnsn_astnode astnode, dmnsn_scene *scene)
dmnsn_assert(astnode.type == DMNSN_AST_GLOBAL_SETTINGS,
"Expected global settings.");
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(astnode.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(astnode.children); ++i) {
dmnsn_astnode item, child;
dmnsn_array_get(astnode.children, i, &item);
@@ -228,8 +227,7 @@ dmnsn_realize_camera(dmnsn_astnode astnode)
dmnsn_camera *camera = NULL;
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(astnode.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(astnode.children); ++i) {
dmnsn_astnode item;
dmnsn_array_get(astnode.children, i, &item);
@@ -410,8 +408,7 @@ dmnsn_realize_pigment_modifiers(dmnsn_astnode astnode, dmnsn_pigment *pigment)
dmnsn_assert(astnode.type == DMNSN_AST_PIGMENT_MODIFIERS,
"Expected pigment modifiers.");
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(astnode.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(astnode.children); ++i) {
dmnsn_astnode modifier;
dmnsn_array_get(astnode.children, i, &modifier);
@@ -510,8 +507,7 @@ dmnsn_realize_reflection(dmnsn_astnode astnode)
dmnsn_astnode items;
dmnsn_array_get(astnode.children, 2, &items);
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(items.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(items.children); ++i) {
dmnsn_astnode item, child;
dmnsn_array_get(items.children, i, &item);
@@ -549,8 +545,7 @@ dmnsn_realize_finish(dmnsn_astnode astnode)
dmnsn_finish *reflection = NULL;
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(astnode.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(astnode.children); ++i) {
dmnsn_astnode item, child;
dmnsn_array_get(astnode.children, i, &item);
@@ -621,8 +616,7 @@ dmnsn_realize_texture(dmnsn_astnode astnode)
dmnsn_texture *texture = dmnsn_new_texture();
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(astnode.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(astnode.children); ++i) {
dmnsn_astnode item;
dmnsn_array_get(astnode.children, i, &item);
@@ -659,8 +653,7 @@ dmnsn_realize_interior(dmnsn_astnode astnode)
dmnsn_interior *interior = dmnsn_new_interior();
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(astnode.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(astnode.children); ++i) {
dmnsn_astnode item, child;
dmnsn_array_get(astnode.children, i, &item);
@@ -687,8 +680,7 @@ dmnsn_realize_object_modifiers(dmnsn_astnode astnode, dmnsn_object *object)
/* Save the pre-existing transformations */
dmnsn_matrix existing_trans = dmnsn_matrix_inverse(object->trans);
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(astnode.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(astnode.children); ++i) {
dmnsn_astnode modifier;
dmnsn_array_get(astnode.children, i, &modifier);
@@ -746,8 +738,7 @@ dmnsn_realize_light_source_modifiers(dmnsn_astnode astnode, dmnsn_light *light)
dmnsn_assert(astnode.type == DMNSN_AST_OBJECT_MODIFIERS,
"Expected object modifiers.");
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(astnode.children); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(astnode.children); ++i) {
dmnsn_astnode modifier;
dmnsn_array_get(astnode.children, i, &modifier);
@@ -899,7 +890,7 @@ dmnsn_realize_csg(dmnsn_astnode astnode, dmnsn_array *lights,
dmnsn_array_get(astnode.children, 0, &objects);
dmnsn_array_get(astnode.children, 1, &modifiers);
- unsigned int i;
+ size_t i;
dmnsn_object *csg = NULL;
for (i = 0; i < dmnsn_array_size(objects.children) && !csg; ++i) {
dmnsn_astnode onode;
@@ -1019,9 +1010,7 @@ dmnsn_realize_astree(const dmnsn_astree *astree)
*/
dmnsn_astnode astnode;
- unsigned int i;
-
- for (i = 0; i < dmnsn_array_size(astree); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(astree); ++i) {
dmnsn_array_get(astree, i, &astnode);
dmnsn_light *light;
diff --git a/dimension/tokenize.c b/dimension/tokenize.c
index 707d0df..efa1064 100644
--- a/dimension/tokenize.c
+++ b/dimension/tokenize.c
@@ -38,7 +38,7 @@ typedef struct dmnsn_token_buffer {
dmnsn_parse_location lloc;
dmnsn_array *buffered;
- unsigned int i;
+ size_t i;
struct dmnsn_token_buffer *prev;
@@ -67,8 +67,7 @@ dmnsn_delete_token_buffer(void *ptr)
{
dmnsn_token_buffer *tbuffer = ptr;
if (tbuffer) {
- unsigned int i;
- for (i = 0; i < dmnsn_array_size(tbuffer->buffered); ++i) {
+ for (size_t i = 0; i < dmnsn_array_size(tbuffer->buffered); ++i) {
dmnsn_buffered_token buffered;
dmnsn_array_get(tbuffer->buffered, i, &buffered);
free(buffered.lval.value);
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);
}
diff --git a/tests/libdimension/prtree.c b/tests/libdimension/prtree.c
index b3e5d52..0684d55 100644
--- a/tests/libdimension/prtree.c
+++ b/tests/libdimension/prtree.c
@@ -59,8 +59,7 @@ main()
const size_t nobjects = 128;
dmnsn_scene *scene = dmnsn_new_scene();
- size_t i;
- for (i = 0; i < nobjects; ++i) {
+ for (size_t i = 0; i < nobjects; ++i) {
dmnsn_object *object = dmnsn_new_object();
dmnsn_randomize_bounding_box(object);
object->intersection_fn = &dmnsn_fake_intersection_fn;