diff --git a/TODO b/TODO index 447a034..05d44ff 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -- ColorGradation dialog. - All noises should use the same entropy pool (saved separately), and avoid reallocs. - Implement scaling and scrolling on previews. - Water and terrain LOD moves with the camera, fix it like in the wanderer. diff --git a/cli/main.c b/cli/main.c index 261808c..82c6ddc 100644 --- a/cli/main.c +++ b/cli/main.c @@ -18,7 +18,16 @@ void startRender(Renderer* renderer, char* outputpath, int width, int height, in void displayHelp() { - printf("Usage : TODO\n"); + printf("Usage : paysages-cli [options]\n"); + printf("Options :\n"); + printf(" -h Show this help\n"); + printf(" -f x Saved file to load (str)\n"); + printf(" -n Number of pictures in the sequence\n"); + printf(" -rw x Render width (int)\n"); + printf(" -rh x Render height (int)\n"); + printf(" -rq x Render quality (int, 1 to 10)\n"); + printf(" -di x Day start time (float, 0.0 to 1.0)\n"); + printf(" -ds x Day step time (float)\n"); } void _previewUpdate(double progress) @@ -30,6 +39,7 @@ void _previewUpdate(double progress) int main(int argc, char** argv) { Renderer renderer; + char* conf_file_path = NULL; int conf_render_width = 800; int conf_render_height = 600; int conf_render_quality = 5; @@ -49,6 +59,13 @@ int main(int argc, char** argv) displayHelp(); return 0; } + else if (strcmp(*argv, "-f") == 0 || strcmp(*argv, "--file") == 0) + { + if (argc--) + { + conf_file_path = *(++argv); + } + } else if (strcmp(*argv, "-n") == 0 || strcmp(*argv, "--count") == 0) { if (argc--) @@ -97,6 +114,11 @@ int main(int argc, char** argv) printf("Initializing ...\n"); paysagesInit(); + + if (conf_file_path) + { + paysagesLoad(conf_file_path); + } renderer = sceneryCreateStandardRenderer(); rendererSetPreviewCallbacks(&renderer, NULL, NULL, _previewUpdate); diff --git a/lib_paysages/tools.c b/lib_paysages/tools.c index f63f8fc..57be3db 100644 --- a/lib_paysages/tools.c +++ b/lib_paysages/tools.c @@ -2,10 +2,71 @@ #include #include +#include #include "color.h" #include "euclid.h" +#define pack754_32(f) (pack754((f), 32, 8)) +#define pack754_64(f) (pack754((f), 64, 11)) +#define unpack754_32(i) (unpack754((i), 32, 8)) +#define unpack754_64(i) (unpack754((i), 64, 11)) + +static uint64_t pack754(double f, unsigned bits, unsigned expbits) +{ + double fnorm; + int shift; + long long sign, exp, significand; + unsigned significandbits = bits - expbits - 1; // -1 for sign bit + + if (f == 0.0) return 0; // get this special case out of the way + + // check sign and begin normalization + if (f < 0) { sign = 1; fnorm = -f; } + else { sign = 0; fnorm = f; } + + // get the normalized form of f and track the exponent + shift = 0; + while(fnorm >= 2.0) { fnorm /= 2.0; shift++; } + while(fnorm < 1.0) { fnorm *= 2.0; shift--; } + fnorm = fnorm - 1.0; + + // calculate the binary form (non-float) of the significand data + significand = fnorm * ((1LL<>significandbits)&((1LL< 0) { result *= 2.0; shift--; } + while(shift < 0) { result /= 2.0; shift++; } + + // sign it + result *= (i>>(bits-1))&1? -1.0: 1.0; + + return result; +} + double toolsRandom() { return (double)rand() / (double)RAND_MAX; @@ -60,15 +121,21 @@ Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right void toolsSaveDouble(FILE* f, double* value) { - fprintf(f, "%.20le;", *value); + uint64_t servalue; + + servalue = pack754_64(*value); + fwrite(&servalue, sizeof(uint64_t), 1, f); } void toolsLoadDouble(FILE* f, double* value) { int read; + uint64_t servalue; - read = fscanf(f, "%le;", value); + read = fread(&servalue, sizeof(uint64_t), 1, f); assert(read == 1); + + *value = unpack754_64(servalue); } void toolsSaveInt(FILE* f, int* value)