diff options
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/dimension/scene.h | 3 | ||||
-rw-r--r-- | libdimension/raytrace.c | 14 | ||||
-rw-r--r-- | libdimension/scene.c | 13 |
3 files changed, 18 insertions, 12 deletions
diff --git a/libdimension/dimension/scene.h b/libdimension/dimension/scene.h index 2064792..ffc8517 100644 --- a/libdimension/dimension/scene.h +++ b/libdimension/dimension/scene.h @@ -57,6 +57,9 @@ typedef struct { /* Recursion limit */ unsigned int limit; + + /* Number of paralell threads */ + unsigned int nthreads; } dmnsn_scene; /* Create a scene */ diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index 0e197a9..31ce24e 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -109,18 +109,20 @@ static void *dmnsn_raytrace_scene_multithread_thread(void *ptr); static int dmnsn_raytrace_scene_multithread(dmnsn_raytrace_payload *payload) { - int i, j, nthreads; + int i, j, nthreads = payload->scene->nthreads; void *ptr; int retval = 0; dmnsn_raytrace_payload *payloads; pthread_t *threads; - /* Find the number of processors/cores running (TODO: do this portably) */ - nthreads = sysconf(_SC_NPROCESSORS_ONLN); - if (nthreads < 1) { - nthreads = 1; + if (!nthreads) { + /* Find the number of processors/cores running (TODO: do this portably) */ + nthreads = sysconf(_SC_NPROCESSORS_ONLN); + if (nthreads < 1) { + nthreads = 1; + } + /* End non-portable section */ } - /* End non-portable section */ payloads = malloc(nthreads*sizeof(dmnsn_raytrace_payload)); if (!payloads) { diff --git a/libdimension/scene.c b/libdimension/scene.c index 78e1ffb..aec9b12 100644 --- a/libdimension/scene.c +++ b/libdimension/scene.c @@ -33,12 +33,13 @@ dmnsn_new_scene() return NULL; } - scene->camera = NULL; - scene->canvas = NULL; - scene->objects = dmnsn_new_array(sizeof(dmnsn_object *)); - scene->lights = dmnsn_new_array(sizeof(dmnsn_light *)); - scene->quality = DMNSN_RENDER_FULL; - scene->limit = 10; + scene->camera = NULL; + scene->canvas = NULL; + scene->objects = dmnsn_new_array(sizeof(dmnsn_object *)); + scene->lights = dmnsn_new_array(sizeof(dmnsn_light *)); + scene->quality = DMNSN_RENDER_FULL; + scene->limit = 10; + scene->nthreads = 0; } return scene; } |