Skip to content

Commit

Permalink
Shuffle main() around a bit to reduce indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vkoskiv committed Nov 12, 2023
1 parent e047039 commit 16eb2d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions include/c-ray/c-ray.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// c-ray.h
// C-ray
// c-ray
//
// Created by Valtteri on 5.1.2020.
// Copyright © 2020-2021 Valtteri Koskivuori. All rights reserved.
// Copyright © 2020-2023 Valtteri Koskivuori. All rights reserved.
//

#pragma once
Expand Down
43 changes: 22 additions & 21 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,32 @@ int main(int argc, char *argv[]) {
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);
if (!input) {
logr(info, "No input provided, exiting.\n");
cr_destroy_renderer(renderer);
args_destroy();
return -1;
}
logr(info, "%zi bytes of input JSON loaded from %s, parsing.\n", bytes, args_is_set("inputFile") ? "file" : "stdin");
if (cr_load_scene_from_buf(renderer, input) < 0) {
logr(warning, "Scene parse failed, exiting.\n");
cr_destroy_renderer(renderer);
args_destroy();
return 0;
}

cr_start_renderer(renderer);
cr_write_image(renderer);
} else {
int ret = 0;
if (args_is_set("is_worker")) {
cr_start_render_worker();
goto done;
}

size_t bytes = 0;
char *input = args_is_set("inputFile") ? load_file(args_path(), &bytes, NULL) : read_stdin(&bytes);
if (!input) {
logr(info, "No input provided, exiting.\n");
ret = -1;
goto done;
}
logr(info, "%zi bytes of input JSON loaded from %s, parsing.\n", bytes, args_is_set("inputFile") ? "file" : "stdin");
if (cr_load_scene_from_buf(renderer, input) < 0) {
logr(warning, "Scene parse failed, exiting.\n");
ret = -1;
goto done;
}

cr_start_renderer(renderer);
cr_write_image(renderer);

done:
cr_destroy_renderer(renderer);
args_destroy();
logr(info, "Render finished, exiting.\n");
return 0;
return ret;
}

0 comments on commit 16eb2d4

Please sign in to comment.