From e047039ed926f0be2fb5e1071658912892c5f212 Mon Sep 17 00:00:00 2001 From: Valtteri Koskivuori Date: Sun, 12 Nov 2023 21:41:58 +0200 Subject: [PATCH] Set asset path via API Temporary, as eventually the library shouldn't care about file paths at all. --- include/c-ray/c-ray.h | 4 +--- src/api/c-ray.c | 14 ++++++-------- src/main.c | 7 +++++++ src/renderer/renderer.c | 1 + 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/c-ray/c-ray.h b/include/c-ray/c-ray.h index 0e807dee..36147582 100644 --- a/include/c-ray/c-ray.h +++ b/include/c-ray/c-ray.h @@ -21,7 +21,6 @@ char *cr_get_git_hash(void); //The current git hash of the build char *cr_get_file_path(char *full_path); - struct cr_renderer; struct cr_renderer *cr_new_renderer(void); @@ -35,6 +34,7 @@ enum cr_renderer_param { cr_renderer_tile_order, //TODO: Renderer shouldn't know these cr_renderer_output_path, + cr_renderer_asset_path, cr_renderer_output_name, cr_renderer_output_filetype, cr_renderer_output_num, @@ -108,8 +108,6 @@ char *cr_get_output_path(struct cr_renderer *r); void cr_set_file_name(struct cr_renderer *r, char *fileName); char *cr_get_file_name(struct cr_renderer *r); -void cr_set_asset_path(struct cr_renderer *r); - //Single frame void cr_start_renderer(struct cr_renderer *r); diff --git a/src/api/c-ray.c b/src/api/c-ray.c index 2453b549..f22d43d2 100644 --- a/src/api/c-ray.c +++ b/src/api/c-ray.c @@ -59,9 +59,7 @@ char *cr_get_file_path(char *full_path) { struct cr_renderer; struct cr_renderer *cr_new_renderer() { - struct renderer *r = renderer_new(); - cr_set_asset_path((struct cr_renderer *)r); - return (struct cr_renderer *)r; + return (struct cr_renderer *)renderer_new(); } bool cr_renderer_set_num_pref(struct cr_renderer *ext, enum cr_renderer_param p, uint64_t num) { @@ -137,6 +135,11 @@ bool cr_renderer_set_str_pref(struct cr_renderer *ext, enum cr_renderer_param p, r->prefs.imgFilePath = stringCopy(str); return true; } + case cr_renderer_asset_path: { + if (r->prefs.assetPath) free(r->prefs.assetPath); + r->prefs.assetPath = stringCopy(str); + return true; + } case cr_renderer_output_name: { if (r->prefs.imgFileName) free(r->prefs.imgFileName); r->prefs.imgFileName = stringCopy(str); @@ -372,11 +375,6 @@ int cr_get_bounces(struct cr_renderer *ext) { return r->prefs.bounces; } -void cr_set_asset_path(struct cr_renderer *ext) { - struct renderer *r = (struct renderer *)ext; - r->prefs.assetPath = args_is_set("inputFile") ? cr_get_file_path(args_path()) : args_is_set("asset_path") ? stringCopy(args_asset_path()) : stringCopy("./"); -} - void cr_start_renderer(struct cr_renderer *ext) { struct renderer *r = (struct renderer *)ext; if (args_is_set("use_clustering")) { diff --git a/src/main.c b/src/main.c index c8e03500..2a1d050d 100644 --- a/src/main.c +++ b/src/main.c @@ -20,6 +20,13 @@ int main(int argc, char *argv[]) { logr(info, "c-ray v%s [%.8s], © 2015-2023 Valtteri Koskivuori\n", cr_get_version(), cr_get_git_hash()); args_parse(argc, argv); struct cr_renderer *renderer = cr_new_renderer(); + + if (args_is_set("asset_path")) { + cr_renderer_set_str_pref(renderer, cr_renderer_asset_path, args_asset_path()); + } else if (args_is_set("inputFile")) { + cr_renderer_set_str_pref(renderer, cr_renderer_asset_path, get_file_path(args_path())); + } + if (!args_is_set("is_worker")) { size_t bytes = 0; char *input = args_is_set("inputFile") ? load_file(args_path(), &bytes, NULL) : read_stdin(&bytes); diff --git a/src/renderer/renderer.c b/src/renderer/renderer.c index c1e54c95..5f4e47d5 100644 --- a/src/renderer/renderer.c +++ b/src/renderer/renderer.c @@ -363,6 +363,7 @@ static struct prefs defaults() { .tileWidth = 32, .tileHeight = 32, .imgFilePath = stringCopy("./"), + .assetPath = stringCopy("./"), .imgFileName = stringCopy("rendered"), .imgCount = 0, .override_dimensions = false,