From 1d6c1e90aa2fa47d3c522e061d7c2bb4e7b32deb Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 30 Aug 2015 01:20:03 +1000 Subject: Support relative frames w/ start/end args --- source/creator/creator.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/source/creator/creator.c b/source/creator/creator.c index 9d4d57b4134..86922c38ba0 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -403,6 +403,27 @@ static int print_help(int UNUSED(argc), const char **UNUSED(argv), void *data) return 0; } +static int parse_relative_int(const char *str, int pos, int neg, int min, int max) +{ + int ret; + + switch (*str) { + case '+': + ret = pos + atoi(str + 1); + break; + case '-': + ret = (neg - atoi(str + 1)) + 1; + break; + default: + ret = atoi(str); + break; + } + + CLAMP(ret, min, max); + + return ret; +} + static int end_arguments(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data)) { return -1; @@ -1067,23 +1088,11 @@ static int render_frame(int argc, const char **argv, void *data) int frame; ReportList reports; - switch (*argv[1]) { - case '+': - frame = scene->r.sfra + atoi(argv[1] + 1); - break; - case '-': - frame = (scene->r.efra - atoi(argv[1] + 1)) + 1; - break; - default: - frame = atoi(argv[1]); - break; - } + frame = parse_relative_int(argv[1], scene->r.sfra, scene->r.efra, MINAFRAME, MAXFRAME); BLI_begin_threaded_malloc(); BKE_reports_init(&reports, RPT_PRINT); - frame = CLAMPIS(frame, MINAFRAME, MAXFRAME); - RE_SetReports(re, &reports); RE_BlenderAnim(re, bmain, scene, NULL, scene->lay, frame, frame, scene->r.frame_step); RE_SetReports(re, NULL); @@ -1144,8 +1153,8 @@ static int set_start_frame(int argc, const char **argv, void *data) Scene *scene = CTX_data_scene(C); if (scene) { if (argc > 1) { - int frame = atoi(argv[1]); - (scene->r.sfra) = CLAMPIS(frame, MINFRAME, MAXFRAME); + scene->r.sfra = parse_relative_int(argv[1], scene->r.sfra, scene->r.sfra - 1, MINAFRAME, MAXFRAME); + return 1; } else { @@ -1165,8 +1174,7 @@ static int set_end_frame(int argc, const char **argv, void *data) Scene *scene = CTX_data_scene(C); if (scene) { if (argc > 1) { - int frame = atoi(argv[1]); - (scene->r.efra) = CLAMPIS(frame, MINFRAME, MAXFRAME); + scene->r.efra = parse_relative_int(argv[1], scene->r.efra, scene->r.efra - 1, MINAFRAME, MAXFRAME); return 1; } else { @@ -1591,8 +1599,8 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle) BLI_argsAdd(ba, 4, "-f", "--render-frame", "\n\tRender frame and save it.\n\t+ start frame relative, - end frame relative.", render_frame, C); BLI_argsAdd(ba, 4, "-a", "--render-anim", "\n\tRender frames from start to end (inclusive)", render_animation, C); BLI_argsAdd(ba, 4, "-S", "--scene", "\n\tSet the active scene for rendering", set_scene, C); - BLI_argsAdd(ba, 4, "-s", "--frame-start", "\n\tSet start to frame (use before the -a argument)", set_start_frame, C); - BLI_argsAdd(ba, 4, "-e", "--frame-end", "\n\tSet end to frame (use before the -a argument)", set_end_frame, C); + BLI_argsAdd(ba, 4, "-s", "--frame-start", "\n\tSet start to frame , supports +/- for relative frames too.", set_start_frame, C); + BLI_argsAdd(ba, 4, "-e", "--frame-end", "\n\tSet end to frame , supports +/- for relative frames too.", set_end_frame, C); BLI_argsAdd(ba, 4, "-j", "--frame-jump", "\n\tSet number of frames to step forward after each rendered frame", set_skip_frame, C); BLI_argsAdd(ba, 4, "-P", "--python", "\n\tRun the given Python script file", run_python_file, C); BLI_argsAdd(ba, 4, NULL, "--python-text", "\n\tRun the given Python script text block", run_python_text, C); -- cgit v1.2.3