solstice

Compute collected power and efficiencies of a solar plant
git clone git://git.meso-star.com/solstice.git
Log | Files | Refs | README | LICENSE

commit 5adce6172f84fad272b8d70252af2857862d03cd
parent cdbb0f0972e7ccf2ba0f22a7326a1fce624390a3
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 26 Jan 2017 16:01:40 +0100

Handle virtual materials in solstice

Diffstat:
Msrc/solstice.c | 7+++++++
Msrc/solstice.h | 1+
Msrc/solstice_material.c | 57+++++++++++++++++++++++++++++++--------------------------
3 files changed, 39 insertions(+), 26 deletions(-)

diff --git a/src/solstice.c b/src/solstice.c @@ -365,6 +365,12 @@ solstice_init goto error; } + res = ssol_material_create_virtual(solstice->ssol, &solstice->mtl_virtual); + if(res != RES_OK) { + fprintf(stderr, "Could not create the global virtual material.\n"); + goto error; + } + res = solparser_create(allocator, &solstice->parser); if(res != RES_OK) { fprintf(stderr, "Could not create the Solstice Parser.\n"); @@ -438,6 +444,7 @@ solstice_release(struct solstice* solstice) if(solstice->camera) SSOL(camera_ref_put(solstice->camera)); if(solstice->framebuffer) SSOL(image_ref_put(solstice->framebuffer)); if(solstice->output && solstice->output != stdout) fclose(solstice->output); + if(solstice->mtl_virtual) SSOL(material_ref_put(solstice->mtl_virtual)); htable_material_release(&solstice->materials); htable_object_release(&solstice->objects); htable_anchor_release(&solstice->anchors); diff --git a/src/solstice.h b/src/solstice.h @@ -119,6 +119,7 @@ struct solstice { struct htable_receiver receivers; struct darray_nodes roots; struct darray_nodes pivots; + struct ssol_material* mtl_virtual; /* Shared virtual material */ /* Rendering */ struct ssol_camera* camera; diff --git a/src/solstice_material.c b/src/solstice_material.c @@ -208,40 +208,45 @@ solstice_create_ssol_material const struct solparser_material_id mtl_id, struct ssol_material** out_ssol_mtl) { + const struct solparser_material* mtl; struct ssol_material* ssol_mtl = NULL; struct ssol_material** pssol_mtl = NULL; res_T res = RES_OK; ASSERT(solstice); - pssol_mtl = htable_material_find(&solstice->materials, &mtl_id.i); - if(pssol_mtl) { - ssol_mtl = *pssol_mtl; - } else { - const struct solparser_material* mtl; - const struct solparser_material_matte* matte; - const struct solparser_material_mirror* mirror; + mtl = solparser_get_material(solstice->parser, mtl_id); + ASSERT(mtl); - mtl = solparser_get_material(solstice->parser, mtl_id); - ASSERT(mtl); + if(mtl->type == SOLPARSER_MATERIAL_VIRTUAL) { + /* Use the global solstice virtual material */ + ssol_mtl = solstice->mtl_virtual; + } else { + pssol_mtl = htable_material_find(&solstice->materials, &mtl_id.i); + if(pssol_mtl) { + ssol_mtl = *pssol_mtl; + } else { + const struct solparser_material_matte* matte; + const struct solparser_material_mirror* mirror; - switch(mtl->type) { - case SOLPARSER_MATERIAL_MIRROR: - mirror = solparser_get_material_mirror(solstice->parser, mtl->data.mirror); - res = create_material_mirror(solstice, mirror, &ssol_mtl); - break; - case SOLPARSER_MATERIAL_MATTE: - matte = solparser_get_material_matte(solstice->parser, mtl->data.matte); - res = create_material_matte(solstice, matte, &ssol_mtl); - break; - default: FATAL("Unreachable code.\n"); break; - } - if(res != RES_OK) goto error; + switch(mtl->type) { + case SOLPARSER_MATERIAL_MIRROR: + mirror = solparser_get_material_mirror(solstice->parser, mtl->data.mirror); + res = create_material_mirror(solstice, mirror, &ssol_mtl); + break; + case SOLPARSER_MATERIAL_MATTE: + matte = solparser_get_material_matte(solstice->parser, mtl->data.matte); + res = create_material_matte(solstice, matte, &ssol_mtl); + break; + default: FATAL("Unreachable code.\n"); break; + } + if(res != RES_OK) goto error; - /* Cache the created material for future use. */ - res = htable_material_set(&solstice->materials, &mtl_id.i, &ssol_mtl); - if(res != RES_OK) { - fprintf(stderr, "Could not register the material into solstice.\n"); - goto error; + /* Cache the created material for future use. */ + res = htable_material_set(&solstice->materials, &mtl_id.i, &ssol_mtl); + if(res != RES_OK) { + fprintf(stderr, "Could not register the material into solstice.\n"); + goto error; + } } }