diff --git a/cli/main.c b/cli/main.c index 73f8343..92241c4 100644 --- a/cli/main.c +++ b/cli/main.c @@ -1,10 +1,114 @@ #include #include +#include #include "../lib_paysages/shared/functions.h" +void startRender(char* outputpath) +{ + printf("\rRendering %s ... \n", outputpath); + autoRenderSceneTwoPass(0); + printf("\rSaving %s ... \n", outputpath); + remove(outputpath); + renderSaveToFile(outputpath); +} + +void displayHelp() +{ + printf("Usage : TODO\n"); +} + +void _previewUpdate(double progress) +{ + printf("\rProgress : %0.1f%% ", progress * 100.0); + fflush(stdout); +} + int main(int argc, char** argv) { + int conf_render_width = 800; + int conf_render_height = 600; + int conf_render_quality = 5; + int conf_nb_pictures = 1; + double conf_daytime_start = 0.4; + double conf_daytime_step = 0.0; + int outputcount; + char outputpath[500]; + + argc--; + argv++; + + while (argc--) + { + if (strcmp(*argv, "-h") == 0 || strcmp(*argv, "--help") == 0) + { + displayHelp(); + return 0; + } + else if (strcmp(*argv, "-n") == 0 || strcmp(*argv, "--count") == 0) + { + if (argc--) + { + conf_nb_pictures = atoi(*(++argv)); + } + } + else if (strcmp(*argv, "-rw") == 0 || strcmp(*argv, "--width") == 0) + { + if (argc--) + { + conf_render_width = atoi(*(++argv)); + } + } + else if (strcmp(*argv, "-rh") == 0 || strcmp(*argv, "--height") == 0) + { + if (argc--) + { + conf_render_height = atoi(*(++argv)); + } + } + else if (strcmp(*argv, "-rq") == 0 || strcmp(*argv, "--quality") == 0) + { + if (argc--) + { + conf_render_quality = atoi(*(++argv)); + } + } + else if (strcmp(*argv, "-di") == 0 || strcmp(*argv, "--daystart") == 0) + { + if (argc--) + { + conf_daytime_start = atof(*(++argv)); + } + } + else if (strcmp(*argv, "-ds") == 0 || strcmp(*argv, "--daystep") == 0) + { + if (argc--) + { + conf_daytime_step = atof(*(++argv)); + } + } + + argv++; + } + + printf("Initializing ...\n"); paysagesInit(); + + renderSetSize(conf_render_width, conf_render_height); + renderSetQuality(conf_render_quality); + renderSetPreviewCallbacks(NULL, NULL, NULL, _previewUpdate); + + for (outputcount = 0; outputcount < conf_nb_pictures; outputcount++) + { + autoSetDaytimeFraction(conf_daytime_start); + + sprintf(outputpath, "output/pic%05d.png", outputcount); + startRender(outputpath); + + conf_daytime_start += conf_daytime_step; + } + + printf("\rDone. \n"); + return 0; } diff --git a/lib_paysages/auto.c b/lib_paysages/auto.c index d068ae5..546cb6f 100644 --- a/lib_paysages/auto.c +++ b/lib_paysages/auto.c @@ -51,6 +51,7 @@ void autoInit() terrainInit(); waterInit(); + renderInit(); } void autoSave(char* filepath) @@ -197,7 +198,7 @@ void autoGenRealisticLandscape(int seed) noiseAddLevelSimple(cloud.noise, 50.0 / 800.0, 0.001); noiseAddLevelSimple(cloud.noise, 50.0 / 1000.0, 0.0005); layer = cloudsAddLayer(); - //cloudsSetDefinition(layer, cloud); + cloudsSetDefinition(layer, cloud); /* Water */ water.height = 0.0; diff --git a/lib_paysages/render.c b/lib_paysages/render.c index ec2f9a6..04331ad 100644 --- a/lib_paysages/render.c +++ b/lib_paysages/render.c @@ -53,6 +53,11 @@ void renderLoad(FILE* f) { } +void renderInit() +{ + _lock = mutexCreate(); +} + void renderSetSize(int width, int height) { int x; @@ -73,11 +78,6 @@ void renderSetSize(int width, int height) free(scanline_down); } - if (_lock == NULL) - { - _lock = mutexCreate(); - } - render_width = width; render_height = height; render_zone = malloc(sizeof(Array) * width * height); diff --git a/lib_paysages/shared/functions.h b/lib_paysages/shared/functions.h index d031ae7..09bb827 100644 --- a/lib_paysages/shared/functions.h +++ b/lib_paysages/shared/functions.h @@ -135,6 +135,7 @@ double noiseGet3DTotal(NoiseGenerator* generator, double x, double y, double z); double noiseGet3DDetail(NoiseGenerator* generator, double x, double y, double z, double detail); /* render.c */ +void renderInit(); void renderSave(FILE* f); void renderLoad(FILE* f); void renderSetSize(int width, int height);