commit aa697c2ba3390cc5f1bde02939e7aa8bb2aae1fa
parent 02c298e2bf73fb62b806e0424f37573f5210141d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 11 Jan 2017 11:31:53 +0100
Remove the core library
The score_node data structure was the only functionality provided by the
core library. It thus became useless to maintain a sub-project for this
small data structure. The node data type is now directly integrated into
the main Solstice library.
Diffstat:
18 files changed, 410 insertions(+), 1809 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -56,7 +56,6 @@ include_directories(
# Build subprojects
################################################################################
add_subdirectory(parser)
-add_subdirectory(core)
################################################################################
# Generate files
@@ -69,7 +68,7 @@ set(SOLSTICE_ARGS_DEFAULT_CAMERA_FOV "1.22173047639603070383") # In radians
set(SOLSTICE_ARGS_DEFAULT_IMG_WIDTH "800")
set(SOLSTICE_ARGS_DEFAULT_IMG_HEIGHT "600")
-configure_file(${SOLSTICE_SOURCE_DIR}/solstice_args.h.in
+configure_file(${SOLSTICE_SOURCE_DIR}/solstice_args.h.in
${CMAKE_CURRENT_BINARY_DIR}/solstice_args.h @ONLY)
################################################################################
@@ -86,6 +85,7 @@ set(SOLSTICE_FILES_SRC
solstice_draw.c
solstice_entity.c
solstice_material.c
+ solstice_node.c
solstice_object.c)
set(SOLSTICE_FILES_INC
solstice.h
@@ -109,7 +109,7 @@ endif()
add_library(sollib STATIC ${SOLSTICE_FILES_SRC} ${SOLSTICE_FILES_INC})
add_executable(solstice ${SOLSTICE_SOURCE_DIR}/main.c)
target_link_libraries(solstice ${MATH_LIB} ${GETOPT_LIB}
- LibYAML RSys sollib solparser solstice-core SolAnim SolSolver Star3DUT)
+ LibYAML RSys sollib solparser SolAnim SolSolver Star3DUT)
set_target_properties(solstice PROPERTIES
VERSION ${VERSION}
SOVERSION ${VERSION_MAJOR})
diff --git a/src/core/solstice_core.h b/src/core/solstice_core.h
@@ -1,159 +0,0 @@
-/* Copyright (C) CNRS 2016-2017
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef SOLSTICE_CORE_H
-#define SOLSTICE_CORE_H
-
-#include <rsys/rsys.h>
-#include <rsys/dynamic_array.h>
-
-/* Forward declaration of external types */
-struct logger;
-struct mem_allocator;
-struct sanim_pivot;
-struct sanim_tracking;
-struct ssol_atmosphere;
-struct ssol_estimator;
-struct ssol_instance;
-struct ssol_object;
-struct ssol_sun;
-struct ssol_vertex_data;
-struct ssp_rng;
-
-struct score_device;
-struct score_node;
-
-/*******************************************************************************
- * Device API - Main entry point of Solstice core. Applications
- * use the score_device to create others Solstice core resources.
- ******************************************************************************/
-extern LOCAL_SYM res_T
-score_device_create
- (struct logger* logger, /* May be NULL <=> use default logger */
- struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
- const int verbose, /* Make the library more verbose */
- struct score_device** dev);
-
-extern LOCAL_SYM void
-score_device_ref_get
- (struct score_device* dev);
-
-extern LOCAL_SYM void
-score_device_ref_put
- (struct score_device* dev);
-
-/*******************************************************************************
- * Node API
- ******************************************************************************/
-extern LOCAL_SYM res_T
-score_node_geometry_create
- (struct score_device* dev,
- struct score_node** geom);
-
-extern LOCAL_SYM res_T
-score_node_pivot_create
- (struct score_device* dev,
- struct score_node** node);
-
-extern LOCAL_SYM res_T
-score_node_empty_create
- (struct score_device* dev,
- struct score_node** node);
-
-extern LOCAL_SYM res_T
-score_node_tracking_target_create
- (struct score_device* dev,
- struct score_node** node);
-
-extern LOCAL_SYM void
-score_node_ref_get
- (struct score_node* node);
-
-extern LOCAL_SYM void
-score_node_ref_put
- (struct score_node* node);
-
-extern LOCAL_SYM res_T
-score_node_geometry_setup
- (struct score_node* node,
- struct ssol_instance* geom);
-
-extern LOCAL_SYM res_T
-score_node_pivot_setup
- (struct score_node* node,
- const struct sanim_pivot* pivot,
- const struct sanim_tracking* tracking);
-
-extern LOCAL_SYM void
-score_node_track_me
- (const struct score_node* node,
- struct sanim_tracking* tracking);
-
-extern LOCAL_SYM res_T
-score_node_add_child
- (struct score_node* father,
- struct score_node* child);
-
-extern LOCAL_SYM void
-score_node_set_translation
- (struct score_node* node,
- const double translation[3]);
-
-extern LOCAL_SYM void
-score_node_get_translation
- (const struct score_node* node,
- double translation[3]);
-
-extern LOCAL_SYM void
-score_node_set_rotations
- (struct score_node* node,
- const double rotations[3]);
-
-extern LOCAL_SYM void
-score_node_get_rotations
- (const struct score_node* node,
- double rotations[3]);
-
-extern LOCAL_SYM void
-score_node_set_receiver
- (struct score_node* node,
- const int mask);
-
-/* Define whether or not the node is sampled.
- * By default a node is sampled. */
-extern LOCAL_SYM void
-score_node_sample
- (struct score_node* node,
- const int sample);
-
-/*******************************************************************************
- * Miscellaneous functions
- ******************************************************************************/
-extern LOCAL_SYM void
-score_scene_clear
- (struct score_device* dev);
-
-extern LOCAL_SYM res_T
-score_reset_simulation
- (struct score_device* dev,
- const double sun_dir[3]);
-
-extern LOCAL_SYM res_T
-score_update_simulation
- (struct score_device* dev,
- const double sun_dir[3]);
-
-#endif /* SOLSTICE_CORE_H */
-
diff --git a/src/core/solstice_core_device.c b/src/core/solstice_core_device.c
@@ -1,135 +0,0 @@
-/* Copyright (C) CNRS 2016-2017
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "solstice_core.h"
-#include "solstice_core_device.h"
-
-#include <rsys/logger.h>
-#include <rsys/mem_allocator.h>
-
-#include <solstice/ssol.h>
-
-#include <omp.h>
-
-/*******************************************************************************
-* Helper functions
-******************************************************************************/
-static INLINE void
-log_msg
- (struct score_device* dev,
- const enum log_type stream,
- const char* msg,
- va_list vargs)
-{
- ASSERT(dev && msg);
- if (dev->verbose) {
- res_T res; (void) res;
- res = logger_vprint(dev->logger, stream, msg, vargs);
- ASSERT(res == RES_OK);
- }
-}
-
-static void
-device_release(ref_T* ref)
-{
- struct score_device* dev;
- ASSERT(ref);
- dev = CONTAINER_OF(ref, struct score_device, ref);
- ASSERT(dev && dev->allocator);
- darray_nodes_release(&dev->instances);
- darray_nodes_release(&dev->pivots);
- MEM_RM(dev->allocator, dev);
-}
-
-/*******************************************************************************
- * Exported score_device functions
- ******************************************************************************/
-res_T
-score_device_create
- (struct logger* logger,
- struct mem_allocator* mem_allocator,
- const int verbose,
- struct score_device** out_dev)
-{
- struct score_device* dev = NULL;
- struct mem_allocator* allocator;
- res_T res = RES_OK;
-
- ASSERT(out_dev);
-
- allocator = mem_allocator ? mem_allocator : &mem_default_allocator;
- dev = MEM_CALLOC(allocator, 1, sizeof(struct score_device));
- if (!dev) {
- res = RES_MEM_ERR;
- goto error;
- }
- ref_init(&dev->ref);
- dev->logger = logger ? logger : LOGGER_DEFAULT;
- dev->allocator = allocator;
- dev->verbose = verbose;
-
- darray_nodes_init(dev->allocator, &dev->instances);
- darray_nodes_init(dev->allocator, &dev->pivots);
-
-exit:
- if (out_dev) *out_dev = dev;
- return res;
-error:
- if (dev) {
- score_device_ref_put(dev);
- dev = NULL;
- }
- goto exit;
-}
-
-void
-score_device_ref_get(struct score_device* dev)
-{
- ASSERT(dev);
- ref_get(&dev->ref);
-}
-
-void
-score_device_ref_put(struct score_device* dev)
-{
- ASSERT(dev);
- ref_put(&dev->ref, device_release);
-}
-
-/*******************************************************************************
- * Local functions
- ******************************************************************************/
-void
-log_error(struct score_device* dev, const char* msg, ...)
-{
- va_list vargs_list;
- ASSERT(dev && msg);
-
- va_start(vargs_list, msg);
- log_msg(dev, LOG_ERROR, msg, vargs_list);
- va_end(vargs_list);
-}
-
-void
-log_warning(struct score_device* dev, const char* msg, ...)
-{
- va_list vargs_list;
- ASSERT(dev && msg);
-
- va_start(vargs_list, msg);
- log_msg(dev, LOG_WARNING, msg, vargs_list);
- va_end(vargs_list);
-}
-
diff --git a/src/core/solstice_core_device.h b/src/core/solstice_core_device.h
@@ -1,63 +0,0 @@
-/* Copyright (C) CNRS 2016-2017
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef SOLSTICE_CORE_DEVICE_H
-#define SOLSTICE_CORE_DEVICE_H
-
-#include "solstice_core_node.h"
-
-#include <rsys/ref_count.h>
-#include <rsys/mem_allocator.h>
-
-struct logger;
-struct ssol_device;
-
-struct score_device {
- struct logger* logger;
- struct mem_allocator* allocator;
- int verbose;
-
- struct darray_nodes instances;
- struct darray_nodes pivots;
-
- ref_T ref;
-};
-
-/* Conditionally log a message on the LOG_ERROR stream of the device logger,
- * with respect to the device verbose flag */
-extern LOCAL_SYM void
-log_error
- (struct score_device* dev,
- const char* msg,
- ...)
-#ifdef COMPILER_GCC
- __attribute((format(printf, 2, 3)))
-#endif
- ;
-
-/* Conditionally log a message on the LOG_WARNING stream of the device logger,
- * with respect to the device verbose flag */
-extern LOCAL_SYM void
-log_warning
- (struct score_device* dev,
- const char* msg,
- ...)
-#ifdef COMPILER_GCC
- __attribute((format(printf, 2, 3)))
-#endif
- ;
-
-#endif /* SOLSTICE_CORE_DEVICE_H */
-
diff --git a/src/core/solstice_core_node.c b/src/core/solstice_core_node.c
@@ -1,365 +0,0 @@
-/* Copyright (C) CNRS 2016-2017
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "solstice_core.h"
-#include "solstice_core_node.h"
-#include "solstice_core_device.h"
-
-#include <rsys/mem_allocator.h>
-#include <rsys/algorithm.h>
-
-#include <solstice/ssol.h>
-#include <solstice/sanim.h>
-
-/*
- * NOTE: There is a weakness in the Solstice-Anim API that forbids the
- * initialization of the pivot node on its creation contraty to the common node.
- */
-
-/*******************************************************************************
- * Helper functions
- ******************************************************************************/
-static void
-node_release(ref_T* ref)
-{
- struct score_device* dev;
- struct score_node* node = CONTAINER_OF(ref, struct score_node, ref);
- ASSERT(ref);
- dev = node->device;
- ASSERT(dev && dev->allocator);
- switch (node->type) {
- case NODE_GEOMETRY:
- if (node->data.geometry_node.solver_instance)
- SSOL(instance_ref_put(node->data.geometry_node.solver_instance));
- break;
- case NODE_TRACKING_TARGET: /* Do nothing */ break;
- case NODE_PIVOT: /* Do nothing */ break;
- case NODE_EMPTY: /* Do nothing */ break;
- default: FATAL("Unreachable code.\n"); break;
- }
- node_ref_put_children(&node->anim);
- SANIM(node_release(&node->anim));
- MEM_RM(dev->allocator, node);
- score_device_ref_put(dev);
-}
-
-struct data {
- const struct ssol_object* searched;
- struct ssol_instance* result;
-};
-
-/*******************************************************************************
- * Local functions
- ******************************************************************************/
-res_T
-node_create
- (struct score_device* dev,
- struct score_node** out_node,
- const enum node_type type)
-{
- struct score_node* node = NULL;
- res_T res = RES_OK;
-
- ASSERT(dev && out_node && type < NODE_TYPES_COUNT__);
-
- node = MEM_CALLOC(dev->allocator, 1, sizeof(struct score_node));
- if (!node) {
- res = RES_MEM_ERR;
- goto error;
- }
-
- score_device_ref_get(dev);
- node->device = dev;
- ref_init(&node->ref);
- node->type = type;
- node->anim = SANIM_NODE_NULL;
-
-exit:
- if (out_node) *out_node = node;
- return res;
-error:
- if (node) {
- score_node_ref_put(node);
- node = NULL;
- }
- goto exit;
-}
-
-void
-node_ref_put_children(struct sanim_node* node)
-{
- size_t count, i;
- int init;
- ASSERT(node);
- SANIM(node_is_initialized(node, &init));
- if (!init) return;
- SANIM(node_get_children_count(node, &count));
- for (i = 0; i < count; i++) {
- struct sanim_node* child_;
- struct score_node *child;
- SANIM(node_get_child(node, i, &child_));
- child = CONTAINER_OF(child_, struct score_node, anim);
- score_node_ref_put(child);
- }
-}
-
-/*******************************************************************************
- * Exported score_node functions
- ******************************************************************************/
-res_T
-score_node_geometry_create(struct score_device* dev, struct score_node** geom)
-{
- struct score_node* node = NULL;
- res_T res = RES_OK;
- ASSERT(dev && geom);
-
- res = node_create(dev, &node, NODE_GEOMETRY);
- if (res != RES_OK) goto error;
-
-exit:
- *geom = node;
- return res;
-error:
- if (node) {
- score_node_ref_put(node);
- node = NULL;
- }
- goto exit;
-}
-
-res_T
-score_node_pivot_create(struct score_device* dev, struct score_node** pivot)
-{
- struct score_node* node = NULL;
- res_T res = RES_OK;
- ASSERT(dev && pivot);
-
- res = node_create(dev, &node, NODE_PIVOT);
- if (res != RES_OK) goto error;
-
-exit:
- *pivot = node;
- return res;
-error:
- if (node) {
- score_node_ref_put(node);
- node = NULL;
- }
- goto exit;
-}
-
-res_T
-score_node_empty_create(struct score_device* dev, struct score_node** empty)
-{
- struct score_node* node = NULL;
- res_T res = RES_OK;
- ASSERT(dev && empty);
-
- res = node_create(dev, &node, NODE_EMPTY);
- if (res != RES_OK) goto error;
-
- res = sanim_node_initialize(node->device->allocator, &node->anim);
- if (res != RES_OK) goto error;
-
-exit:
- *empty = node;
- return res;
-error:
- if (node) {
- score_node_ref_put(node);
- node = NULL;
- }
- goto exit;
-}
-
-res_T
-score_node_tracking_target_create
- (struct score_device* dev, struct score_node** tracking)
-{
- struct score_node* node = NULL;
- res_T res = RES_OK;
- ASSERT(dev && tracking);
-
- res = node_create(dev, &node, NODE_TRACKING_TARGET);
- if (res != RES_OK) goto error;
-
- res = sanim_node_initialize(node->device->allocator, &node->anim);
- if (res != RES_OK) goto error;
-
-exit:
- *tracking = node;
- return res;
-error:
- if (node) {
- score_node_ref_put(node);
- node = NULL;
- }
- goto exit;
-}
-
-res_T
-score_node_geometry_setup
- (struct score_node* node, struct ssol_instance* instance)
-{
- int is_init = 0;
- res_T res = RES_OK;
- ASSERT(node && instance && node->type == NODE_GEOMETRY);
-
- SANIM(node_is_initialized(&node->anim, &is_init));
- if(is_init) {
- SANIM(node_release(&node->anim));
- node->anim = SANIM_NODE_NULL;
- }
-
- res = sanim_node_initialize(node->device->allocator, &node->anim);
- if (res != RES_OK) goto error;
- node->data.geometry_node.solver_instance = instance;
- SSOL(instance_ref_get(instance));
-
-exit:
- return res;
-error:
- if (node->data.geometry_node.solver_instance) {
- SSOL(instance_ref_put(node->data.geometry_node.solver_instance));
- node->data.geometry_node.solver_instance = NULL;
- }
- if (node->anim.data) {
- SANIM(node_release(&node->anim));
- node->anim = SANIM_NODE_NULL;
- }
- goto exit;
-}
-
-res_T
-score_node_pivot_setup
- (struct score_node* node,
- const struct sanim_pivot* pivot,
- const struct sanim_tracking* tracking)
-{
- int is_init = 0;
- res_T res = RES_OK;
- ASSERT(node && pivot && tracking && node->type == NODE_PIVOT);
-
- SANIM(node_is_initialized(&node->anim, &is_init));
- if(is_init) {
- SANIM(node_release(&node->anim));
- node->anim = SANIM_NODE_NULL;
- }
-
- res = sanim_node_initialize_pivot
- (node->device->allocator, pivot, tracking, &node->anim);
- if (res != RES_OK) goto error;
-
-exit:
- return res;
-error:
- if (node->anim.data) {
- SANIM(node_release(&node->anim));
- node->anim = SANIM_NODE_NULL;
- }
- goto exit;
-}
-
-void
-score_node_track_me
- (const struct score_node* node,
- struct sanim_tracking* tracking)
-{
- ASSERT(node && tracking && node->type == NODE_TRACKING_TARGET);
- SANIM(node_track_me(&node->anim, tracking));
-}
-
-res_T
-score_node_add_child(struct score_node* father, struct score_node* child)
-{
- res_T res = RES_OK;
- ASSERT(father && child
- && father->type != NODE_TRACKING_TARGET);
- res = sanim_node_add_child(&father->anim, &child->anim);
- if (res != RES_OK) return res;
- score_node_ref_get(child);
- return RES_OK;
-}
-
-void
-score_node_ref_get(struct score_node* node)
-{
- ASSERT(node) ;
- ref_get(&node->ref);
-}
-
-void
-score_node_ref_put(struct score_node* node)
-{
- ASSERT(node);
- ref_put(&node->ref, node_release);
-}
-
-void
-score_node_set_translation
- (struct score_node* node,
- const double translation[3])
-{
- ASSERT(node && translation);
- SANIM(node_set_translation(&node->anim, translation));
-}
-
-void
-score_node_get_translation
- (const struct score_node* node,
- double translation[3])
-{
- ASSERT(node && translation);
- SANIM(node_get_translation(&node->anim, translation));
-}
-
-void
-score_node_set_rotations
- (struct score_node* node,
- const double rotations[3])
-{
- ASSERT(node && rotations
- && node->type != NODE_TRACKING_TARGET);
- SANIM(node_set_rotations(&node->anim, rotations));
-}
-
-void
-score_node_get_rotations
- (const struct score_node* node,
- double rotations[3])
-{
- ASSERT(node && rotations
- && node->type != NODE_TRACKING_TARGET);
- SANIM(node_get_rotations(&node->anim, rotations));
-}
-
-void
-score_node_set_receiver
- (struct score_node* node,
- const int mask)
-{
- ASSERT(node && node->type == NODE_GEOMETRY);
- node->data.geometry_node.receiver_mask = mask;
-}
-
-void
-score_node_sample
- (struct score_node* node,
- const int sample)
-{
- ASSERT(node && node->type == NODE_GEOMETRY);
- node->data.geometry_node.sample = sample;
-}
-
diff --git a/src/core/solstice_core_node.h b/src/core/solstice_core_node.h
@@ -1,73 +0,0 @@
-/* Copyright (C) CNRS 2016-2017
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef SOLSTICE_CORE_NODE_H
-#define SOLSTICE_CORE_NODE_H
-
-#include <solstice/sanim.h>
-
-#include <rsys/dynamic_array.h>
-#include <rsys/ref_count.h>
-
-struct score_node;
-
-/* Define the darray_nodes data structure */
-#define DARRAY_NAME nodes
-#define DARRAY_DATA struct score_node*
-#include <rsys/dynamic_array.h>
-
-struct score_device;
-struct score_node;
-struct score_scene;
-struct ssol_object;
-struct ssol_instance;
-
-enum node_type {
- NODE_GEOMETRY,
- NODE_TRACKING_TARGET,
- NODE_PIVOT,
- NODE_EMPTY,
-
- NODE_TYPES_COUNT__
-};
-
-struct geometry_node_data {
- struct ssol_instance* solver_instance;
- int receiver_mask;
- int sample;
-};
-
-struct score_node {
- enum node_type type;
- struct score_device* device;
- struct sanim_node anim;
- union {
- /* only types of nodes with specific data.
- * TODO remove the useless union (?) */
- struct geometry_node_data geometry_node;
- } data;
- ref_T ref;
-};
-
-res_T
-node_create
- (struct score_device* dev,
- struct score_node** out_node,
- enum node_type type);
-
-void
-node_ref_put_children(struct sanim_node* node);
-
-#endif /* SOLSTICE_CORE_NODE_H */
diff --git a/src/core/test_core_device.c b/src/core/test_core_device.c
@@ -1,59 +0,0 @@
-/* Copyright (C) CNRS 2016-2017
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "solstice_core.h"
-#include "test_core_utils.h"
-#include "test_solstice_utils.h"
-
-#include <rsys/logger.h>
-
-int
-main(int argc, char** argv)
-{
- struct logger logger;
- struct mem_allocator allocator;
- struct score_device* dev;
- (void) argc, (void) argv;
-
- CHECK(score_device_create(NULL, NULL, 1, 0, &dev), RES_OK);
- score_device_ref_put(dev);
-
- mem_init_proxy_allocator(&allocator, &mem_default_allocator);
-
- CHECK(MEM_ALLOCATED_SIZE(&allocator), 0);
- CHECK(score_device_create(NULL, &allocator, 1, 0, &dev), RES_OK);
- score_device_ref_put(dev);
- CHECK(MEM_ALLOCATED_SIZE(&allocator), 0);
-
- CHECK(logger_init(&allocator, &logger), RES_OK);
- logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
- logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
- logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
-
- CHECK(score_device_create(&logger, NULL, 1, 0, &dev), RES_OK);
- score_device_ref_put(dev);
-
- CHECK(score_device_create(&logger, &allocator, 1, 0, &dev), RES_OK);
- score_device_ref_put(dev);
-
- CHECK(score_device_create(&logger, &allocator, 1, 0, &dev), RES_OK);
- score_device_ref_put(dev);
-
- logger_release(&logger);
- check_memory_allocator(&allocator);
- mem_shutdown_proxy_allocator(&allocator);
- CHECK(mem_allocated_size(), 0);
- return 0;
-}
diff --git a/src/core/test_core_node.c b/src/core/test_core_node.c
@@ -1,167 +0,0 @@
-/* Copyright (C) CNRS 2016-2017
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "solstice_core.h"
-#include "test_core_utils.h"
-#include "test_solstice_utils.h"
-
-#include <solstice/ssol.h>
-#include <solstice/sanim.h>
-
-#include <rsys/logger.h>
-#include <rsys/double3.h>
-
-int
-main(int argc, char** argv)
-{
- struct logger logger;
- struct mem_allocator allocator;
- struct score_device* dev = NULL;
- struct score_node *temp = NULL, *inst = NULL, *piv = NULL, *piv2 = NULL,
- *geom1 = NULL, *geom2 = NULL, *tgt = NULL;
- struct sanim_pivot pivot = SANIM_PIVOT_NULL;
- struct sanim_tracking tracking = SANIM_TRACKING_NULL;
- struct ssol_device* sol_dev = NULL;
- struct ssol_punched_surface punched = SSOL_PUNCHED_SURFACE_NULL;
- struct ssol_carving carving = SSOL_CARVING_NULL;
- struct ssol_quadric quadric = SSOL_QUADRIC_DEFAULT;
- struct ssol_shape *shape1 = NULL, *shape2 = NULL;
- struct ssol_material* mtl = NULL;
- struct ssol_object *obj1 = NULL, *obj2 = NULL;
- struct ssol_vertex_data attribs[1] = { SSOL_VERTEX_DATA_NULL__ };
- double polygon [] = {
- -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.f, -2.f
- };
- double transl[3], rot[3];
- const size_t npolygon_verts = sizeof(polygon) / sizeof(double[2]);
- (void) argc, (void) argv;
-
- mem_init_proxy_allocator(&allocator, &mem_default_allocator);
-
- CHECK(logger_init(&allocator, &logger), RES_OK);
- logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
- logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
- logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
-
- CHECK(ssol_device_create(
- &logger, &allocator, SSOL_NTHREADS_DEFAULT, 0, &sol_dev), RES_OK);
-
- score_device_create(&logger, &allocator, 1, 0, &dev);
-
- CHECK(score_node_template_create(dev, &temp), RES_OK);
- score_node_ref_put(temp);
-
- CHECK(score_node_create_object(dev, &geom1), RES_OK);
- score_node_ref_put(geom1);
-
- CHECK(score_node_pivot_create(dev, &piv), RES_OK);
- score_node_ref_put(piv);
-
- CHECK(score_node_tracking_target_create(dev, &tgt), RES_OK);
- score_node_ref_put(tgt);
-
- CHECK(score_node_template_create(dev, &temp), RES_OK);
- CHECK(score_node_create_object(dev, &geom1), RES_OK);
- CHECK(score_node_create_object(dev, &geom2), RES_OK);
- CHECK(score_node_pivot_create(dev, &piv), RES_OK);
- CHECK(score_node_pivot_create(dev, &piv2), RES_OK);
- CHECK(score_node_tracking_target_create(dev, &tgt), RES_OK);
-
- tracking.data.node_target.tracked_node = NULL;
- tracking.policy = TRACKING_NODE_TARGET;
- score_node_track_me(tgt, &tracking);
- CHECK(tracking.policy, TRACKING_NODE_TARGET);
- /* cannot check tracking.data.node_target.tracked_node validity */
-
- CHECK(score_node_instantiate(temp, &inst), RES_OK);
- score_node_ref_put(inst);
-
- CHECK(score_node_instantiate(temp, &inst), RES_OK);
-
- score_node_set_receiver(geom1, 0);
- score_node_set_receiver(geom2, 0);
-
- score_node_sample(geom1, 0);
- score_node_sample(geom2, 1);
-
- CHECK(ssol_material_create_virtual(sol_dev, &mtl), RES_OK);
- CHECK(ssol_object_create(sol_dev, &obj1), RES_OK);
- CHECK(ssol_object_create(sol_dev, &obj2), RES_OK);
-
- attribs[0].usage = SSOL_POSITION;
- attribs[0].get = get_position;
- CHECK(ssol_shape_create_mesh(sol_dev, &shape1), RES_OK);
- CHECK(ssol_mesh_setup(shape1, RECT_NTRIS__, get_ids, RECT_NVERTS__,
- attribs, 1, (void*) &RECT_DESC__), RES_OK);
- CHECK(ssol_object_add_shaded_shape(obj1, shape1, mtl, mtl), RES_OK);
-
- tracking.policy = TRACKING_SUN;
- pivot.type = PIVOT_SINGLE_AXIS;
- d3(pivot.data.pivot1.ref_normal, 0, 0, 1);
- CHECK(score_node_object_setup(geom1, obj1), RES_OK);
-
- CHECK(score_node_pivot_setup(piv, &pivot, &tracking), RES_OK);
- CHECK(score_node_pivot_setup(piv2, &pivot, &tracking), RES_OK);
-
- carving.get = get_polygon_vertices;
- carving.operation = SSOL_AND;
- carving.nb_vertices = npolygon_verts;
- carving.context = &polygon;
- quadric.type = SSOL_QUADRIC_PLANE;
- punched.nb_carvings = 1;
- punched.quadric = &quadric;
- punched.carvings = &carving;
- CHECK(ssol_shape_create_punched_surface(sol_dev, &shape2), RES_OK);
- CHECK(ssol_punched_surface_setup(shape2, &punched), RES_OK);
- CHECK(ssol_object_add_shaded_shape(obj2, shape2, mtl, mtl), RES_OK);
- CHECK(score_node_object_setup(geom2, obj2), RES_OK);
-
- CHECK(ssol_material_ref_put(mtl), RES_OK);
- CHECK(ssol_object_ref_put(obj1), RES_OK);
- CHECK(ssol_object_ref_put(obj2), RES_OK);
- CHECK(ssol_shape_ref_put(shape1), RES_OK);
- CHECK(ssol_shape_ref_put(shape2), RES_OK);
- CHECK(ssol_device_ref_put(sol_dev), RES_OK);
-
- CHECK(score_node_add_child(temp, geom1), RES_OK);
- CHECK(score_node_add_child(geom1, piv), RES_OK);
- score_node_ref_put(piv2);
-
- score_node_set_translation(inst, transl);
- score_node_set_translation(piv, transl);
- score_node_set_translation(geom1, transl);
- score_node_set_translation(geom2, transl);
- score_node_set_translation(tgt, transl);
-
- score_node_set_rotations(inst, rot);
- score_node_set_rotations(piv, rot);
- score_node_set_rotations(geom1, rot);
- score_node_set_rotations(geom2, rot);
-
- score_node_ref_put(inst);
- score_node_ref_put(piv);
- score_node_ref_put(geom1);
- score_node_ref_put(geom2);
- score_node_ref_put(temp);
- score_node_ref_put(tgt);
-
- score_device_ref_put(dev);
-
- logger_release(&logger);
- check_memory_allocator(&allocator);
- mem_shutdown_proxy_allocator(&allocator);
- CHECK(mem_allocated_size(), 0);
- return 0;
-}
diff --git a/src/core/test_core_scene.c b/src/core/test_core_scene.c
@@ -1,210 +0,0 @@
-/* Copyright (C) CNRS 2016-2017
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "solstice_core.h"
-#include "test_core_utils.h"
-#include "test_solstice_utils.h"
-
-#include <solstice/ssol.h>
-#include <solstice/sanim.h>
-
-#include <star/ssp.h>
-
-#include <rsys/logger.h>
-#include <rsys/double3.h>
-
-int
-main(int argc, char** argv)
-{
- struct logger logger;
- struct mem_allocator allocator;
- struct score_device* dev = NULL;
- struct score_scene* scene = NULL;
- struct score_node *temp1 = NULL, *inst1 = NULL, *temp2 = NULL, *inst2 = NULL,
- *piv = NULL, *geom1 = NULL, *geom2 = NULL, *tgt = NULL;
- struct sanim_pivot pivot = SANIM_PIVOT_NULL;
- struct sanim_tracking tracking = SANIM_TRACKING_NULL;
- struct ssol_device* sol_dev = NULL;
- struct ssol_punched_surface punched = SSOL_PUNCHED_SURFACE_NULL;
- struct ssol_carving carving = SSOL_CARVING_NULL;
- struct ssol_quadric quadric = SSOL_QUADRIC_DEFAULT;
- struct ssol_shape *shape1 = NULL, *shape2 = NULL;
- struct ssol_material *v_mtl = NULL, *m_mtl = NULL;
- struct ssol_object *obj1 = NULL, *obj2 = NULL;
- struct ssol_sun* sun = NULL;
- struct ssol_estimator* estimator = NULL;
- struct ssol_spectrum* spectrum = NULL;
- struct ssol_vertex_data attribs[1] = { SSOL_VERTEX_DATA_NULL__ };
- struct ssol_mirror_shader shader = SSOL_MIRROR_SHADER_NULL;
- struct ssp_rng* rng = NULL;
- double sun_dir[3];
- double transl[3], rot[3];
- double polygon [] = {
- -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.f, -2.f
- };
- double wavelengths[3] = { 1, 2, 3 };
- double intensities[3] = { 1, 0.8, 1 };
- const size_t npolygon_verts = sizeof(polygon) / sizeof(double[2]);
- FILE* tmp = NULL;
- (void) argc, (void) argv;
-
- mem_init_proxy_allocator(&allocator, &mem_default_allocator);
-
- CHECK(logger_init(&allocator, &logger), RES_OK);
- logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
- logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
- logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
-
- CHECK(ssol_device_create(
- &logger, &allocator, SSOL_NTHREADS_DEFAULT, 0, &sol_dev), RES_OK);
-
- CHECK(score_device_create(&logger, &allocator, 1, 0, &dev), RES_OK);
-
- /* create a template of a virtual 'target' */
-
- attribs[0].usage = SSOL_POSITION;
- attribs[0].get = get_position;
- CHECK(ssol_shape_create_mesh(sol_dev, &shape2), RES_OK);
- CHECK(ssol_mesh_setup(shape2, RECT_NTRIS__, get_ids, RECT_NVERTS__,
- attribs, 1, (void*) &RECT_DESC__), RES_OK);
- CHECK(ssol_material_create_virtual(sol_dev, &v_mtl), RES_OK);
- CHECK(ssol_object_create(sol_dev, &obj2), RES_OK);
- CHECK(ssol_object_add_shaded_shape(obj2, shape2, v_mtl, v_mtl), RES_OK);
- CHECK(score_node_create_object(dev, &geom2), RES_OK);
- CHECK(score_node_object_setup(geom2, obj2), RES_OK);
-
- CHECK(score_node_template_create(dev, &temp2), RES_OK);
- CHECK(score_node_add_child(temp2, geom2), RES_OK);
- /* define a tracking target at the geom2 center */
- CHECK(score_node_tracking_target_create(dev, &tgt), RES_OK);
- CHECK(score_node_add_child(geom2, tgt), RES_OK);
- score_node_set_receiver(geom2, SSOL_FRONT);
- score_node_sample(geom2, 0);
- d3(transl, 10, 0, 3);
- score_node_set_translation(geom2, transl);
- d3(rot, 0, PI / 2, 0);
- score_node_set_rotations(geom2, rot);
- CHECK(score_node_instantiate(temp2, &inst2), RES_OK);
-
- CHECK(ssol_material_ref_put(v_mtl), RES_OK);
- CHECK(ssol_object_ref_put(obj2), RES_OK);
- CHECK(ssol_shape_ref_put(shape2), RES_OK);
-
- /* create a template of a 'heliostat' */
-
- carving.get = get_polygon_vertices;
- carving.operation = SSOL_AND;
- carving.nb_vertices = npolygon_verts;
- carving.context = &polygon;
- quadric.type = SSOL_QUADRIC_PLANE;
- punched.nb_carvings = 1;
- punched.quadric = &quadric;
- punched.carvings = &carving;
- CHECK(ssol_shape_create_punched_surface(sol_dev, &shape1), RES_OK);
- CHECK(ssol_punched_surface_setup(shape1, &punched), RES_OK);
- CHECK(ssol_object_create(sol_dev, &obj1), RES_OK);
- CHECK(ssol_material_create_mirror(sol_dev, &m_mtl), RES_OK);
- shader.normal = get_shader_normal;
- shader.reflectivity = get_shader_reflectivity;
- shader.roughness = get_shader_roughness;
- CHECK(ssol_mirror_set_shader(m_mtl, &shader), RES_OK);
- CHECK(ssol_object_add_shaded_shape(obj1, shape1, m_mtl, m_mtl), RES_OK);
- CHECK(score_node_create_object(dev, &geom1), RES_OK);
-
- score_node_track_me(tgt, &tracking);
- pivot.type = PIVOT_SINGLE_AXIS;
- d3(pivot.data.pivot1.ref_point, 0, 0, 0);
- d3(pivot.data.pivot1.ref_normal, 0, 0, 1);
- CHECK(score_node_object_setup(geom1, obj1), RES_OK);
-
- CHECK(score_node_pivot_create(dev, &piv), RES_OK);
- CHECK(score_node_pivot_setup(piv, &pivot, &tracking), RES_OK);
- d3(transl, 0, 0, 3);
- score_node_set_translation(piv, transl);
- d3(rot, 0, 0, PI / 2);
- score_node_set_rotations(piv, rot);
-
- CHECK(score_node_template_create(dev, &temp1), RES_OK);
- CHECK(score_node_add_child(temp1, piv), RES_OK);
- CHECK(score_node_add_child(piv, geom1), RES_OK);
- CHECK(score_node_instantiate(temp1, &inst1), RES_OK);
-
- CHECK(ssol_material_ref_put(m_mtl), RES_OK);
- CHECK(ssol_object_ref_put(obj1), RES_OK);
- CHECK(ssol_shape_ref_put(shape1), RES_OK);
- CHECK(ssol_device_ref_put(sol_dev), RES_OK);
-
- /* some scene API tests */
- CHECK(score_scene_create(dev, &scene), RES_OK);
- score_scene_ref_put(scene);
-
- CHECK(score_scene_create(dev, &scene), RES_OK);
-
-#define N__ 10000
- NCHECK(tmp = tmpfile(), 0);
- CHECK(ssp_rng_create(&allocator, &ssp_rng_threefry, &rng), RES_OK);
- CHECK(ssol_estimator_create(sol_dev, &estimator), RES_OK);
- CHECK(score_scene_attach_instance(scene, inst1), RES_OK);
-
- score_scene_detach_instance(scene, inst1);
-
- /* create and attach a sun, including API tests */
-
- CHECK(ssol_spectrum_create(sol_dev, &spectrum), RES_OK);
- CHECK(ssol_spectrum_setup(spectrum, wavelengths, intensities, 3), RES_OK);
- CHECK(ssol_sun_create_directional(sol_dev, &sun), RES_OK);
- d3(sun_dir, 0, 0, -1);
- CHECK(ssol_sun_set_direction(sun, sun_dir), RES_OK);
- CHECK(ssol_sun_set_spectrum(sun, spectrum), RES_OK);
- CHECK(ssol_sun_set_dni(sun, 1000), RES_OK);
- score_scene_attach_sun(scene, sun);
- score_scene_detach_sun(scene, sun);
-
- CHECK(ssol_spectrum_ref_put(spectrum), RES_OK);
-
- /* fill up the scene */
-
- CHECK(score_scene_attach_instance(scene, inst1), RES_OK);
- CHECK(score_scene_attach_instance(scene, inst2), RES_OK);
- /* no sun to get a direction to track */
- score_scene_attach_sun(scene, sun);
- CHECK(score_scene_reset_simulation(scene), RES_OK);
-
- CHECK(fclose(tmp), 0);
-
- /* clean up memory */
-
- CHECK(ssol_sun_ref_put(sun), RES_OK);
- CHECK(ssp_rng_ref_put(rng), RES_OK);
- CHECK(ssol_estimator_ref_put(estimator), RES_OK);
-
- score_scene_ref_put(scene);
-
- score_node_ref_put(inst1);
- score_node_ref_put(inst2);
- score_node_ref_put(piv);
- score_node_ref_put(geom1);
- score_node_ref_put(geom2);
- score_node_ref_put(temp1);
- score_node_ref_put(temp2);
- score_node_ref_put(tgt);
- score_device_ref_put(dev);
-
- logger_release(&logger);
- check_memory_allocator(&allocator);
- mem_shutdown_proxy_allocator(&allocator);
- CHECK(mem_allocated_size(), 0);
- return 0;
-}
diff --git a/src/core/test_core_solve1.c b/src/core/test_core_solve1.c
@@ -1,204 +0,0 @@
-/* Copyright (C) CNRS 2016-2017
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "solstice_core.h"
-#include "test_core_utils.h"
-#include "test_solstice_utils.h"
-
-#include <solstice/ssol.h>
-#include <solstice/sanim.h>
-
-#include <star/ssp.h>
-
-#include <rsys/logger.h>
-#include <rsys/double3.h>
-
-int
-main(int argc, char** argv)
-{
- struct logger logger;
- struct mem_allocator allocator;
- struct score_device* dev = NULL;
- struct score_scene* scene = NULL;
- struct score_node *temp1 = NULL, *inst1 = NULL, *temp2 = NULL, *inst2 = NULL,
- *piv = NULL, *geom1 = NULL, *geom2 = NULL, *tgt = NULL;
- struct sanim_pivot pivot = SANIM_PIVOT_NULL;
- struct sanim_tracking tracking = SANIM_TRACKING_NULL;
- struct ssol_device* sol_dev = NULL;
- struct ssol_punched_surface punched = SSOL_PUNCHED_SURFACE_NULL;
- struct ssol_carving carving = SSOL_CARVING_NULL;
- struct ssol_quadric quadric = SSOL_QUADRIC_DEFAULT;
- struct ssol_shape *shape1 = NULL, *shape2 = NULL;
- struct ssol_material *v_mtl = NULL, *m_mtl = NULL;
- struct ssol_object *obj1 = NULL, *obj2 = NULL;
- struct ssol_sun* sun = NULL;
- struct ssol_estimator* estimator = NULL;
- struct ssol_spectrum* spectrum = NULL;
- struct ssol_vertex_data attribs[1] = { SSOL_VERTEX_DATA_NULL__ };
- struct ssol_mirror_shader shader = SSOL_MIRROR_SHADER_NULL;
- struct ssol_instance* solver_instance = NULL;
- struct ssp_rng* rng = NULL;
- double sun_dir[3];
- double transl[3], rot[3];
- double polygon [] = {
- -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.f, -2.f
- };
- double wavelengths[3] = { 1, 2, 3 };
- double intensities[3] = { 1, 0.8, 1 };
- const size_t npolygon_verts = sizeof(polygon) / sizeof(double[2]);
- size_t count;
- uint32_t r_id;
- double m, std;
- FILE* tmp = NULL;
- (void) argc, (void) argv;
-
- mem_init_proxy_allocator(&allocator, &mem_default_allocator);
-
- CHECK(logger_init(&allocator, &logger), RES_OK);
- logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
- logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
- logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
-
- CHECK(score_device_create(&logger, &allocator, 1, 0, &dev), RES_OK);
-
- sol_dev = score_device_get_solver_device(dev);
-
- /* create a template of a virtual 'target' */
-
- attribs[0].usage = SSOL_POSITION;
- attribs[0].get = get_position;
- CHECK(ssol_shape_create_mesh(sol_dev, &shape2), RES_OK);
- CHECK(ssol_mesh_setup(shape2, RECT_NTRIS__, get_ids, RECT_NVERTS__,
- attribs, 1, (void*) &RECT_DESC__), RES_OK);
- CHECK(ssol_material_create_virtual(sol_dev, &v_mtl), RES_OK);
- CHECK(ssol_object_create(sol_dev, &obj2), RES_OK);
- CHECK(ssol_object_add_shaded_shape(obj2, shape2, v_mtl, v_mtl), RES_OK);
- CHECK(score_node_create_object(dev, &geom2), RES_OK);
- CHECK(score_node_object_setup(geom2, obj2), RES_OK);
-
- CHECK(score_node_template_create(dev, &temp2), RES_OK);
- CHECK(score_node_add_child(temp2, geom2), RES_OK);
- /* define a tracking target at the geom2 center */
- CHECK(score_node_tracking_target_create(dev, &tgt), RES_OK);
- CHECK(score_node_add_child(geom2, tgt), RES_OK);
- score_node_set_receiver(geom2, SSOL_FRONT);
- score_node_sample(geom2, 0);
- d3(transl, 10, 0, 3);
- score_node_set_translation(geom2, transl);
- d3(rot, 0, -PI / 2, 0);
- score_node_set_rotations(geom2, rot);
- CHECK(score_node_instantiate(temp2, &inst2), RES_OK);
-
- /* create a template of a 'heliostat' */
-
- carving.get = get_polygon_vertices;
- carving.operation = SSOL_AND;
- carving.nb_vertices = npolygon_verts;
- carving.context = &polygon;
- quadric.type = SSOL_QUADRIC_PLANE;
- punched.nb_carvings = 1;
- punched.quadric = &quadric;
- punched.carvings = &carving;
- CHECK(ssol_shape_create_punched_surface(sol_dev, &shape1), RES_OK);
- CHECK(ssol_punched_surface_setup(shape1, &punched), RES_OK);
- CHECK(ssol_object_create(sol_dev, &obj1), RES_OK);
- CHECK(ssol_material_create_mirror(sol_dev, &m_mtl), RES_OK);
- shader.normal = get_shader_normal;
- shader.reflectivity = get_shader_reflectivity;
- shader.roughness = get_shader_roughness;
- CHECK(ssol_mirror_set_shader(m_mtl, &shader), RES_OK);
- CHECK(ssol_object_add_shaded_shape(obj1, shape1, m_mtl, m_mtl), RES_OK);
- CHECK(score_node_create_object(dev, &geom1), RES_OK);
-
- score_node_track_me(tgt, &tracking);
- pivot.type = PIVOT_SINGLE_AXIS;
- d3(pivot.data.pivot1.ref_point, 0, 0, 0);
- d3(pivot.data.pivot1.ref_normal, 0, 0, 1);
- CHECK(score_node_object_setup(geom1, obj1), RES_OK);
-
- CHECK(score_node_pivot_create(dev, &piv), RES_OK);
- CHECK(score_node_pivot_setup(piv, &pivot, &tracking), RES_OK);
- d3(transl, 0, 0, 3);
- score_node_set_translation(piv, transl);
- d3(rot, 0, 0, PI / 2);
- score_node_set_rotations(piv, rot);
-
- CHECK(score_node_template_create(dev, &temp1), RES_OK);
- CHECK(score_node_add_child(temp1, piv), RES_OK);
- CHECK(score_node_add_child(piv, geom1), RES_OK);
- CHECK(score_node_instantiate(temp1, &inst1), RES_OK);
-
- /* create scene */
-
- CHECK(score_scene_create(dev, &scene), RES_OK);
-
-#define N__ 10000
- NCHECK(tmp = tmpfile(), 0);
- CHECK(ssp_rng_create(&allocator, &ssp_rng_threefry, &rng), RES_OK);
- CHECK(ssol_estimator_create(sol_dev, &estimator), RES_OK);
-
- CHECK(ssol_spectrum_create(sol_dev, &spectrum), RES_OK);
- CHECK(ssol_spectrum_setup(spectrum, wavelengths, intensities, 3), RES_OK);
- CHECK(ssol_sun_create_directional(sol_dev, &sun), RES_OK);
- d3(sun_dir, 0, 0, -1);
- CHECK(ssol_sun_set_direction(sun, sun_dir), RES_OK);
- CHECK(ssol_sun_set_spectrum(sun, spectrum), RES_OK);
- CHECK(ssol_sun_set_dni(sun, 1000), RES_OK);
-
- CHECK(score_scene_attach_instance(scene, inst1), RES_OK);
- CHECK(score_scene_attach_instance(scene, inst2), RES_OK);
- score_scene_attach_sun(scene, sun);
- CHECK(score_scene_reset_simulation(scene), RES_OK);
-
- CHECK(score_solve(scene, rng, N__, tmp, estimator), RES_OK);
- CHECK(ssol_estimator_get_count(estimator, &count), RES_OK);
- CHECK(count, N__);
- score_node_get_instance_of(inst2, geom2, &solver_instance);
- NCHECK(solver_instance, NULL);
- CHECK(ssol_instance_get_id(solver_instance, &r_id), RES_OK);
- CHECK(pp_sum(tmp, (int32_t) r_id, count, &m, &std), RES_OK);
-
- CHECK(fclose(tmp), 0);
-
- /* clean up memory */
-
- CHECK(ssol_material_ref_put(m_mtl), RES_OK);
- CHECK(ssol_object_ref_put(obj1), RES_OK);
- CHECK(ssol_shape_ref_put(shape1), RES_OK);
- CHECK(ssol_material_ref_put(v_mtl), RES_OK);
- CHECK(ssol_object_ref_put(obj2), RES_OK);
- CHECK(ssol_shape_ref_put(shape2), RES_OK);
- CHECK(ssol_spectrum_ref_put(spectrum), RES_OK);
- CHECK(ssol_sun_ref_put(sun), RES_OK);
- CHECK(ssp_rng_ref_put(rng), RES_OK);
- CHECK(ssol_estimator_ref_put(estimator), RES_OK);
-
- score_scene_ref_put(scene);
- score_node_ref_put(inst1);
- score_node_ref_put(inst2);
- score_node_ref_put(piv);
- score_node_ref_put(geom1);
- score_node_ref_put(geom2);
- score_node_ref_put(temp1);
- score_node_ref_put(temp2);
- score_node_ref_put(tgt);
- score_device_ref_put(dev);
-
- logger_release(&logger);
- check_memory_allocator(&allocator);
- mem_shutdown_proxy_allocator(&allocator);
- CHECK(mem_allocated_size(), 0);
- return 0;
-}
diff --git a/src/core/test_core_utils.c b/src/core/test_core_utils.c
@@ -1,167 +0,0 @@
-/* Copyright (C) CNRS 2016-2017
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "test_core_utils.h"
-
-#include <solstice/ssol.h>
-
-#include <rsys/mem_allocator.h>
-#include <rsys/logger.h>
-
-#define _POSIX_C_SOURCE 200809L /* snprintf support */
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
-
-void
-log_stream(const char* msg, void* ctx)
-{
- ASSERT(msg);
- (void) msg, (void) ctx;
- printf("%s\n", msg);
-}
-
-const float VERTICES__ [] = {
- -1, -1, 0.f,
- 1, -1, 0.f,
- 1, 1, 0.f,
- -1, 1, 0.f
-};
-
-const unsigned RECT_NVERTS__ = sizeof(VERTICES__) / sizeof(float[3]);
-
-const unsigned TRG_IDS__ [] = { 0, 2, 1, 2, 0, 3 };
-const unsigned RECT_NTRIS__ = sizeof(TRG_IDS__) / sizeof(unsigned[3]);
-
-const struct desc RECT_DESC__ = { VERTICES__, TRG_IDS__ };
-
-void
-get_position(const unsigned ivert, float position[3], void* data)
-{
- struct desc* desc = data;
- NCHECK(desc, NULL);
- NCHECK(position, NULL);
- position[0] = desc->vertices[ivert * 3 + 0];
- position[1] = desc->vertices[ivert * 3 + 1];
- position[2] = desc->vertices[ivert * 3 + 2];
-}
-
-void
-get_ids(const unsigned itri, unsigned ids[3], void* data)
-{
- const unsigned id = itri * 3;
- struct desc* desc = data;
- NCHECK(desc, NULL);
- NCHECK(ids, NULL);
- ids[0] = desc->indices[id + 0];
- ids[1] = desc->indices[id + 1];
- ids[2] = desc->indices[id + 2];
-}
-
-void
-get_polygon_vertices(const size_t ivert, double position[2], void* ctx)
-{
- const double* verts = ctx;
- NCHECK(position, NULL);
- NCHECK(ctx, NULL);
- position[0] = verts[ivert * 2 + 0];
- position[1] = verts[ivert * 2 + 1];
-}
-
-void
-get_shader_normal
- (struct ssol_device* dev,
- struct ssol_param_buffer* buf,
- const double wavelength,
- const double P[3],
- const double Ng[3],
- const double Ns[3],
- const double uv[2],
- const double w[3],
- double* val)
-{
- int i;
- (void)dev, (void)buf, (void)wavelength, (void)P, (void)Ng, (void)uv, (void)w;
- FOR_EACH(i, 0, 3) val[i] = Ns[i];
-}
-
-void
-get_shader_reflectivity
- (struct ssol_device* dev,
- struct ssol_param_buffer* buf,
- const double wavelength,
- const double P[3],
- const double Ng[3],
- const double Ns[3],
- const double uv[2],
- const double w[3],
- double* val)
-{
- (void)dev, (void)buf, (void)wavelength, (void)P, (void)Ng, (void)Ns, (void)uv, (void)w;
- *val = 1;
-}
-
-void
-get_shader_roughness
- (struct ssol_device* dev,
- struct ssol_param_buffer* buf,
- const double wavelength,
- const double P[3],
- const double Ng[3],
- const double Ns[3],
- const double uv[2],
- const double w[3],
- double* val)
-{
- (void)dev, (void)buf, (void)wavelength, (void)P, (void)Ng, (void)Ns, (void)uv, (void)w;
- *val = 0;
-}
-
-res_T
-pp_sum
- (FILE* f,
- const int32_t receiver_id,
- const size_t count,
- double* mean,
- double* std)
-{
- struct ssol_receiver_data hit;
- double sum = 0;
- double sum2 = 0;
- double E, V, SE;
-
- if (!f || !mean || !std || !count)
- return RES_BAD_ARG;
-
- rewind(f);
- while (1 == fread(&hit, sizeof(struct ssol_receiver_data), 1, f)) {
- if (ferror(f))
- return RES_BAD_ARG;
-
- if (receiver_id != hit.receiver_id)
- continue;
-
- sum += hit.weight;
- sum2 += hit.weight * hit.weight;
- }
-
- E = sum / (double) count;
- V = MMAX(sum2 / (double) count - E*E, 0);
- SE = sqrt(V / (double) count);
-
- *mean = E;
- *std = SE;
- return RES_OK;
-}
diff --git a/src/core/test_core_utils.h b/src/core/test_core_utils.h
@@ -1,105 +0,0 @@
-/* Copyright (C) CNRS 2016-2017
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef TEST_CORE_UTILS_H
-#define TEST_CORE_UTILS_H
-
-#include "solstice_core.h"
-
-#include <rsys/rsys.h>
-#include <stdio.h>
-
-struct mem_allocator;
-struct ssol_device;
-struct ssol_param_buffer;
-
-/*******************************************************************************
- * Utilities
- ******************************************************************************/
-void
-log_stream(const char* msg, void* ctx);
-
-/*******************************************************************************
- * Mesh stuff
- ******************************************************************************/
-struct desc {
- const float* vertices;
- const unsigned* indices;
-};
-
-extern const float EDGES__ [];
-
-extern const unsigned RECT_NVERTS__;
-
-extern const unsigned TRG_IDS__ [];
-extern const unsigned RECT_NTRIS__;
-
-extern const struct desc RECT_DESC__;
-
-void
-get_position(const unsigned ivert, float position[3], void* data);
-
-void
-get_ids(const unsigned itri, unsigned ids[3], void* data);
-
-void
-get_polygon_vertices(const size_t ivert, double position[2], void* ctx);
-
-void
-get_shader_normal
- (struct ssol_device* dev,
- struct ssol_param_buffer* buf,
- const double wavelength,
- const double P[3],
- const double Ng[3],
- const double Ns[3],
- const double uv[2],
- const double w[3],
- double* val);
-
-void
-get_shader_reflectivity
- (struct ssol_device* dev,
- struct ssol_param_buffer* buf,
- const double wavelength,
- const double P[3],
- const double Ng[3],
- const double Ns[3],
- const double uv[2],
- const double w[3],
- double* val);
-
-void
-get_shader_roughness
- (struct ssol_device* dev,
- struct ssol_param_buffer* buf,
- const double wavelength,
- const double P[3],
- const double Ng[3],
- const double Ns[3],
- const double uv[2],
- const double w[3],
- double* val);
-
-res_T
-pp_sum
- (FILE* f,
- const int32_t receiver_id,
- const size_t count,
- double* mean,
- double* std);
-
-#endif /* TEST_CORE_UTILS_H */
-
diff --git a/src/solstice.c b/src/solstice.c
@@ -17,7 +17,6 @@
#include "solstice_c.h"
#include "solstice_args.h"
#include "parser/solparser.h"
-#include "core/solstice_core.h"
#include <solstice/ssol.h>
@@ -63,7 +62,7 @@ clear_nodes(struct darray_nodes* nodes)
ASSERT(nodes);
n = darray_nodes_size_get(nodes);
FOR_EACH(i, 0, n) {
- score_node_ref_put(darray_nodes_data_get(nodes)[i]);
+ solstice_node_ref_put(darray_nodes_data_get(nodes)[i]);
}
darray_nodes_clear(nodes);
}
@@ -289,12 +288,6 @@ solstice_init
goto error;
}
- res = score_device_create(NULL, allocator, 1/*verbose*/, &solstice->score);
- if(res != RES_OK) {
- fprintf(stderr, "Could not create the Solstice Core device.\n");
- goto error;
- }
-
if(args->rendering) {
res = setup_camera(solstice, args);
if(res != RES_OK) goto error;
@@ -338,7 +331,6 @@ solstice_release(struct solstice* solstice)
if(solstice->ssol) SSOL(device_ref_put(solstice->ssol));
if(solstice->scene) SSOL(scene_ref_put(solstice->scene));
if(solstice->parser) solparser_ref_put(solstice->parser);
- if(solstice->score) score_device_ref_put(solstice->score);
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);
diff --git a/src/solstice.h b/src/solstice.h
@@ -24,12 +24,15 @@
struct solparser;
struct solstice_args;
+struct solstice_node;
struct ssol_device;
struct ssol_material;
struct ssol_object;
struct sanim_node;
-struct score_device;
-struct score_node;
+
+#define DARRAY_NAME nodes
+#define DARRAY_DATA struct solstice_node*
+#include <rsys/dynamic_array.h>
#define HTABLE_NAME material
#define HTABLE_KEY size_t
@@ -44,17 +47,14 @@ struct score_node;
#define HTABLE_NAME anchor
#define HTABLE_KEY size_t
-#define HTABLE_DATA struct score_node*
+#define HTABLE_DATA struct solstice_node*
#include <rsys/hash_table.h>
-#include "core/solstice_core_node.h"
-
struct solstice {
struct ssol_device* ssol;
struct ssol_scene* scene;
struct solparser* parser;
- struct score_device* score;
struct htable_material materials;
struct htable_object objects;
diff --git a/src/solstice_c.h b/src/solstice_c.h
@@ -19,6 +19,26 @@
#include "solstice.h"
#include "parser/solparser.h"
+#include <rsys/ref_count.h>
+#include <solstice/sanim.h>
+
+enum solstice_node_type {
+ SOLSTICE_NODE_GEOMETRY,
+ SOLSTICE_NODE_TARGET,
+ SOLSTICE_NODE_PIVOT,
+ SOLSTICE_NODE_EMPTY,
+ SOLSTICE_NODE_TYPES_COUNT__
+};
+
+struct solstice_node {
+ struct sanim_node anim;
+ enum solstice_node_type type;
+ struct ssol_instance* instance; /* Available for geometry nodes */
+
+ ref_T ref;
+ struct mem_allocator* allocator;
+};
+
struct ssol_instance;
extern LOCAL_SYM res_T
@@ -46,5 +66,64 @@ solstice_instantiate_geometry
const struct solparser_geometry_id geom_id,
struct ssol_instance** inst);
+extern LOCAL_SYM res_T
+solstice_node_geometry_create
+ (struct mem_allocator* allocator,
+ struct ssol_instance* instance,
+ struct solstice_node** node);
+
+extern LOCAL_SYM res_T
+solstice_node_empty_create
+ (struct mem_allocator* allocator,
+ struct solstice_node** node);
+
+extern LOCAL_SYM res_T
+solstice_node_pivot_create
+ (struct mem_allocator* allocator,
+ const struct sanim_pivot* pivot,
+ const struct sanim_tracking* tracking,
+ struct solstice_node** node);
+
+extern LOCAL_SYM res_T
+solstice_node_target_create
+ (struct mem_allocator* allocator,
+ struct solstice_node** node);
+
+extern LOCAL_SYM void
+solstice_node_ref_get
+ (struct solstice_node* node);
+
+extern LOCAL_SYM void
+solstice_node_ref_put
+ (struct solstice_node* node);
+
+extern LOCAL_SYM void
+solstice_node_target_get_tracking
+ (const struct solstice_node* node,
+ struct sanim_tracking* tracking);
+
+extern LOCAL_SYM res_T
+solstice_node_add_child
+ (struct solstice_node* node,
+ struct solstice_node* child);
+
+static INLINE void
+solstice_node_set_translation
+ (struct solstice_node* node,
+ const double translation[3])
+{
+ ASSERT(node && translation);
+ SANIM(node_set_translation(&node->anim, translation));
+}
+
+static INLINE void
+solstice_node_set_rotations
+ (struct solstice_node* node,
+ const double rotations[3])
+{
+ ASSERT(node && rotations && node->type != SOLSTICE_NODE_TARGET);
+ SANIM(node_set_rotations(&node->anim, rotations));
+}
+
#endif /* SOLSTICE_C_H */
diff --git a/src/solstice_entity.c b/src/solstice_entity.c
@@ -18,7 +18,6 @@
#include <solstice/ssol.h>
#include <solstice/sanim.h>
-#include "core/solstice_core.h"
/*******************************************************************************
* Helper function
@@ -27,79 +26,71 @@ static res_T
update_instance_transform
(const struct sanim_node* n, const double transform[12], void* data)
{
- struct score_node* node;
+ struct solstice_node* node;
ASSERT(n && transform);
(void)data;
- node = CONTAINER_OF(n, struct score_node, anim);
- if(node->type != NODE_GEOMETRY) return RES_OK;
- return ssol_instance_set_transform
- (node->data.geometry_node.solver_instance, transform);
+ node = CONTAINER_OF(n, struct solstice_node, anim);
+ if(node->type != SOLSTICE_NODE_GEOMETRY) return RES_OK;
+ return ssol_instance_set_transform(node->instance, transform);
}
-static struct score_node*
-setup_entity_empty
+static struct solstice_node*
+create_empty_node
(struct solstice* solstice, const struct solparser_entity* entity)
{
- struct score_node* empty_node = NULL;
+ struct solstice_node* node = NULL;
res_T res = RES_OK;
ASSERT(solstice && entity);
+ (void)entity;
- res = score_node_empty_create(solstice->score, &empty_node);
+ res = solstice_node_empty_create(solstice->allocator, &node);
if(res != RES_OK) goto error;
- score_node_set_translation(empty_node, entity->translation);
- score_node_set_rotations(empty_node, entity->rotation);
-
exit:
- return empty_node;
+ return node;
error:
- if(empty_node) {
- score_node_ref_put(empty_node);
- empty_node = NULL;
+ if(node) {
+ solstice_node_ref_put(node);
+ node = NULL;
}
goto exit;
}
-static struct score_node*
-setup_entity_geometry
+static struct solstice_node*
+create_geometry_node
(struct solstice* solstice, const struct solparser_entity* entity)
{
- struct score_node* geometry_node = NULL;
+ struct solstice_node* node = NULL;
struct ssol_instance* instance = NULL;
res_T res = RES_OK;
ASSERT(solstice && entity);
- res = score_node_geometry_create(solstice->score, &geometry_node);
- if(res != RES_OK) goto error;
-
res = solstice_instantiate_geometry
(solstice, entity->data.geometry, &instance);
if(res != RES_OK) goto error;
- res = score_node_geometry_setup(geometry_node, instance);
+ res = solstice_node_geometry_create(solstice->allocator, instance, &node);
if(res != RES_OK) goto error;
- score_node_set_translation(geometry_node, entity->translation);
- score_node_set_rotations(geometry_node, entity->rotation);
-
exit:
if(instance) SSOL(instance_ref_put(instance));
- return geometry_node;
+ return node;
error:
- if(geometry_node) {
- score_node_ref_put(geometry_node);
- geometry_node = NULL;
+ if(node) {
+ solstice_node_ref_put(node);
+ node = NULL;
}
goto exit;
}
-static struct score_node*
-setup_entity_pivot
+static struct solstice_node*
+create_pivot_node
(struct solstice* solstice,
const struct solparser_entity* entity)
{
- struct score_node* pivot_node = NULL;
+ struct solstice_node* node = NULL;
+ struct solstice_node* target = NULL;
const struct solparser_pivot* parser_pivot = NULL;
struct sanim_pivot anim_pivot = SANIM_PIVOT_NULL;
struct sanim_tracking anim_tracking = SANIM_TRACKING_NULL;
@@ -107,23 +98,20 @@ setup_entity_pivot
ASSERT(solstice && entity);
parser_pivot = solparser_get_pivot(solstice->parser, entity->data.pivot);
- res = score_node_pivot_create(solstice->score, &pivot_node);
- if(res != RES_OK) goto error;
- /* TODO: 2-axis pivots */
+ /* Setup the pivot descriptor TODO: 2-axis pivots */
anim_pivot.type = PIVOT_SINGLE_AXIS;
d3_set(anim_pivot.data.pivot1.ref_normal, parser_pivot->normal);
d3_set(anim_pivot.data.pivot1.ref_point, parser_pivot->point);
+
+ /* Setup the tracking descriptor */
switch (parser_pivot->target_type) {
case SOLPARSER_TARGET_ANCHOR:
- {
- struct score_node** ptgt = NULL;
- const struct solparser_anchor_id id = parser_pivot->target.anchor;
anim_tracking.policy = TRACKING_NODE_TARGET;
- ptgt = htable_anchor_find(&solstice->anchors, &id.i);
- score_node_track_me(*ptgt, &anim_tracking);
+ target = *htable_anchor_find
+ (&solstice->anchors, &parser_pivot->target.anchor.i);
+ solstice_node_target_get_tracking(target, &anim_tracking);
break;
- }
case SOLPARSER_TARGET_DIRECTION:
anim_tracking.policy = TRACKING_OUT_DIR;
d3_set(anim_tracking.data.out_dir.u, parser_pivot->target.direction);
@@ -139,58 +127,61 @@ setup_entity_pivot
default: FATAL("Unreachable code.\n"); break;
}
- res = score_node_pivot_setup(pivot_node, &anim_pivot, &anim_tracking);
+ res = solstice_node_pivot_create
+ (solstice->allocator, &anim_pivot, &anim_tracking, &node);
if(res != RES_OK) goto error;
- score_node_set_translation(pivot_node, entity->translation);
- score_node_set_rotations(pivot_node, entity->rotation);
- res = darray_nodes_push_back(&solstice->pivots, &pivot_node);
+ res = darray_nodes_push_back(&solstice->pivots, &node);
if(res != RES_OK) goto error;
exit:
- return pivot_node;
+ return node;
error:
- if(pivot_node) {
- score_node_ref_put(pivot_node);
- pivot_node = NULL;
+ if(node) {
+ solstice_node_ref_put(node);
+ node = NULL;
}
goto exit;
}
-static struct score_node*
-setup_entity(struct solstice* solstice, const struct solparser_entity* entity)
+static struct solstice_node*
+create_node(struct solstice* solstice, const struct solparser_entity* entity)
{
- struct score_node* entity_node = NULL;
- struct score_node* tgt = NULL;
- struct score_node* child_root = NULL;
+ struct solstice_node* node = NULL;
+ struct solstice_node* tgt = NULL;
+ struct solstice_node* child = NULL;
size_t i;
res_T res = RES_OK;
- ASSERT(solstice && solstice->parser && solstice->score && entity);
+ ASSERT(solstice && entity);
+ /* Create the entity node */
switch(entity->type) {
case SOLPARSER_ENTITY_EMPTY:
- entity_node = setup_entity_empty(solstice, entity);
+ node = create_empty_node(solstice, entity);
break;
case SOLPARSER_ENTITY_GEOMETRY:
- entity_node = setup_entity_geometry(solstice, entity);
+ node = create_geometry_node(solstice, entity);
break;
case SOLPARSER_ENTITY_PIVOT:
- entity_node = setup_entity_pivot(solstice, entity);
+ node = create_pivot_node(solstice, entity);
break;
default: FATAL("Unreachable code.\n"); break;
}
-
- if(!entity_node) {
+ if(!node) {
fprintf(stderr, "Could not setup the entity node.\n");
goto error;
}
- /* Register anchors */
+ /* Setup the entity transform */
+ solstice_node_set_translation(node, entity->translation);
+ solstice_node_set_rotations(node, entity->rotation);
+
+ /* Register entity anchors */
FOR_EACH(i, 0, solparser_entity_get_anchors_count(entity)) {
struct solparser_anchor_id id;
const struct solparser_anchor* anchor = NULL;
- res = score_node_tracking_target_create(solstice->score, &tgt);
+ res = solstice_node_target_create(solstice->allocator, &tgt);
if(res != RES_OK) goto error;
id = solparser_entity_get_anchor(entity, i);
@@ -199,8 +190,9 @@ setup_entity(struct solstice* solstice, const struct solparser_entity* entity)
res = htable_anchor_set(&solstice->anchors, &id.i, &tgt);
if(res != RES_OK) goto error;
- score_node_set_translation(tgt, anchor->position);
- res = score_node_add_child(entity_node, tgt);
+ solstice_node_set_translation(tgt, anchor->position);
+
+ res = solstice_node_add_child(node, tgt);
if(res != RES_OK) goto error;
tgt = NULL;
@@ -209,28 +201,28 @@ setup_entity(struct solstice* solstice, const struct solparser_entity* entity)
/* Setup children */
FOR_EACH(i, 0, solparser_entity_get_children_count(entity)) {
struct solparser_entity_id id;
- const struct solparser_entity* child;
+ const struct solparser_entity* child_entity;
id = solparser_entity_get_child(entity, i);
- child = solparser_get_entity(solstice->parser, id);
+ child_entity = solparser_get_entity(solstice->parser, id);
- child_root = setup_entity(solstice, child);
- if(!child_root) goto error;
+ child = create_node(solstice, child_entity);
+ if(!child) goto error;
- res = score_node_add_child(entity_node, child_root);
+ res = solstice_node_add_child(node, child);
if(res != RES_OK) goto error;
- score_node_ref_put(child_root);
- child_root = NULL;
+ solstice_node_ref_put(child);
+ child = NULL;
}
exit:
- return entity_node;
+ return node;
error:
- if(tgt) score_node_ref_put(tgt);
- if(child_root) score_node_ref_put(child_root);
- if(entity_node) score_node_ref_put(entity_node);
- entity_node = NULL;
+ if(tgt) solstice_node_ref_put(tgt);
+ if(child) solstice_node_ref_put(child);
+ if(node) solstice_node_ref_put(node);
+ node = NULL;
goto exit;
}
@@ -241,10 +233,10 @@ res_T
solstice_setup_entities(struct solstice* solstice)
{
struct solparser_entity_iterator it, it_end;
- struct score_node* root = NULL;
+ struct solstice_node* root = NULL;
const double dummy_sun_dir[3] = {0, 0, -1};
res_T res = RES_OK;
- ASSERT(solstice && solstice->parser && solstice->score);
+ ASSERT(solstice);
/* Release possible previous roots (incomplete, TODO) */
/*score_scene_clear(solstice->score);*/
@@ -259,7 +251,7 @@ solstice_setup_entities(struct solstice* solstice)
entity_id = solparser_entity_iterator_get(&it);
entity = solparser_get_entity(solstice->parser, entity_id);
- root = setup_entity(solstice, entity);
+ root = create_node(solstice, entity);
if(!root) goto error;
/* Initialialised the world space position of the entity geometry */
@@ -284,7 +276,7 @@ solstice_setup_entities(struct solstice* solstice)
exit:
return res;
error:
- if(root) score_node_ref_put(root);
+ if(root) solstice_node_ref_put(root);
goto exit;
}
@@ -297,7 +289,7 @@ solstice_update_entities(struct solstice* solstice, const double sun_dir[3])
n = darray_nodes_size_get(&solstice->roots);
FOR_EACH(i, 0, n) {
- struct score_node* node = darray_nodes_data_get(&solstice->roots)[i];
+ struct solstice_node* node = darray_nodes_data_get(&solstice->roots)[i];
/* Initialialised the world space position of the entity geometry */
res = sanim_node_visit_tree
diff --git a/src/solstice_node.c b/src/solstice_node.c
@@ -0,0 +1,246 @@
+/* Copyright (C) CNRS 2016-2017
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "solstice_c.h"
+#include <solstice/ssol.h>
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static res_T
+node_create
+ (struct mem_allocator* allocator,
+ const enum solstice_node_type type,
+ struct solstice_node** out_node)
+{
+ struct solstice_node* node = NULL;
+ res_T res = RES_OK;
+ ASSERT(allocator && out_node && type < SOLSTICE_NODE_TYPES_COUNT__);
+
+ node = MEM_CALLOC(allocator, 1, sizeof(struct solstice_node));
+ if(!node) {
+ fprintf(stderr, "Could not allocate a Solstice node.\n");
+ res = RES_MEM_ERR;
+ goto error;
+ }
+
+ ref_init(&node->ref);
+ node->type = type;
+ node->anim = SANIM_NODE_NULL;
+ node->allocator = allocator;
+
+exit:
+ if(out_node) *out_node = node;
+ return res;
+error:
+ if(node) {
+ solstice_node_ref_put(node);
+ node = NULL;
+ }
+ goto exit;
+}
+
+static void
+node_release(ref_T* ref)
+{
+ struct solstice_node* node;
+ int is_init;
+ ASSERT(ref);
+
+ node = CONTAINER_OF(ref, struct solstice_node, ref);
+ if(node->instance) SSOL(instance_ref_put(node->instance));
+
+ SANIM(node_is_initialized(&node->anim, &is_init));
+ if(is_init) {
+ size_t i, n;
+ SANIM(node_get_children_count(&node->anim, &n));
+ FOR_EACH(i, 0, n) {
+ struct sanim_node* child_anim;
+ struct solstice_node* child;
+ SANIM(node_get_child(&node->anim, i, &child_anim));
+ child = CONTAINER_OF(child_anim, struct solstice_node, anim);
+ solstice_node_ref_put(child);
+ }
+ SANIM(node_release(&node->anim));
+ }
+ MEM_RM(node->allocator, node);
+}
+
+/*******************************************************************************
+ * Exported functions
+ ******************************************************************************/
+res_T
+solstice_node_geometry_create
+ (struct mem_allocator* allocator,
+ struct ssol_instance* instance,
+ struct solstice_node** out_node)
+{
+ struct solstice_node* node = NULL;
+ res_T res = RES_OK;
+ ASSERT(allocator && instance && out_node);
+
+ res = node_create(allocator, SOLSTICE_NODE_GEOMETRY, &node);
+ if(res != RES_OK) goto error;
+
+ res = sanim_node_initialize(allocator, &node->anim);
+ if(res != RES_OK) {
+ fprintf(stderr,
+ "Could not initialize the anim field of a Solstice geometry node.\n");
+ goto error;
+ }
+
+ SSOL(instance_ref_get(instance));
+ node->instance = instance;
+
+exit:
+ *out_node = node;
+ return res;
+error:
+ if(node) {
+ solstice_node_ref_put(node);
+ node = NULL;
+ }
+ goto exit;
+}
+
+res_T
+solstice_node_empty_create
+ (struct mem_allocator* allocator,
+ struct solstice_node** out_node)
+{
+ struct solstice_node* node = NULL;
+ res_T res = RES_OK;
+ ASSERT(allocator && out_node);
+
+ res = node_create(allocator, SOLSTICE_NODE_EMPTY, &node);
+ if(res != RES_OK) goto error;
+
+ res = sanim_node_initialize(allocator, &node->anim);
+ if(res != RES_OK) {
+ fprintf(stderr,
+ "Could not initialize the anim field of a Solstice empty node.\n");
+ goto error;
+ }
+
+exit:
+ *out_node = node;
+ return res;
+error:
+ if(node) {
+ solstice_node_ref_put(node);
+ node = NULL;
+ }
+ goto exit;
+}
+
+res_T
+solstice_node_pivot_create
+ (struct mem_allocator* allocator,
+ const struct sanim_pivot* pivot,
+ const struct sanim_tracking* tracking,
+ struct solstice_node** out_node)
+{
+ struct solstice_node* node = NULL;
+ res_T res = RES_OK;
+ ASSERT(allocator && pivot && tracking && out_node);
+
+ res = node_create(allocator, SOLSTICE_NODE_PIVOT, &node);
+ if(res != RES_OK) goto error;
+
+ res = sanim_node_initialize_pivot(allocator, pivot, tracking, &node->anim);
+ if(res != RES_OK) {
+ fprintf(stderr,
+ "Could not initialize the anim field of a Solstice pivot node.\n");
+ goto error;
+ }
+
+exit:
+ *out_node = node;
+ return res;
+error:
+ if(node) {
+ solstice_node_ref_put(node);
+ node = NULL;
+ }
+ goto exit;
+}
+
+res_T
+solstice_node_target_create
+ (struct mem_allocator* allocator,
+ struct solstice_node** out_node)
+{
+ struct solstice_node* node = NULL;
+ res_T res = RES_OK;
+ ASSERT(allocator && out_node);
+
+ res = node_create(allocator, SOLSTICE_NODE_TARGET, &node);
+ if(res != RES_OK) goto error;
+
+ res = sanim_node_initialize(allocator, &node->anim);
+ if(res != RES_OK) {
+ fprintf(stderr,
+ "Could not initialize the anim field of a Solstice target node.\n");
+ goto error;
+ }
+
+exit:
+ *out_node = node;
+ return res;
+error:
+ if(node) {
+ solstice_node_ref_put(node);
+ node = NULL;
+ }
+ goto exit;
+}
+
+void
+solstice_node_ref_get(struct solstice_node* node)
+{
+ ASSERT(node);
+ ref_get(&node->ref);
+}
+
+void
+solstice_node_ref_put(struct solstice_node* node)
+{
+ ASSERT(node);
+ ref_put(&node->ref, node_release);
+}
+
+void
+solstice_node_target_get_tracking
+ (const struct solstice_node* node,
+ struct sanim_tracking* tracking)
+{
+ ASSERT(node && tracking && node->type == SOLSTICE_NODE_TARGET);
+ SANIM(node_track_me(&node->anim, tracking));
+}
+
+res_T
+solstice_node_add_child(struct solstice_node* node, struct solstice_node* child)
+{
+ res_T res = RES_OK;
+ ASSERT(node && child && node->type != SOLSTICE_NODE_TARGET);
+ res = sanim_node_add_child(&node->anim, &child->anim);
+ if(res != RES_OK) {
+ fprintf(stderr, "Could not add a child node.\n");
+ return res;
+ }
+ solstice_node_ref_get(child);
+ return RES_OK;
+}
+
diff --git a/src/solstice_object.c b/src/solstice_object.c
@@ -460,7 +460,6 @@ solstice_instantiate_geometry
res = create_shaded_shape(solstice, obj_id, &front, &back, &shape);
if(res != RES_OK) goto error;
-
res = ssol_object_add_shaded_shape(ssol_obj, shape, front, back);
if(res != RES_OK) {
fprintf(stderr,