paysages: Improved CLI and double serialization.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@272 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-02-26 11:28:47 +00:00 committed by ThunderK
parent fabcec1cfd
commit 58605687e2
3 changed files with 92 additions and 4 deletions

1
TODO
View file

@ -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.

View file

@ -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);

View file

@ -2,10 +2,71 @@
#include <assert.h>
#include <stdlib.h>
#include <inttypes.h>
#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) + 0.5f);
// get the biased exponent
exp = shift + ((1<<(expbits-1)) - 1); // shift + bias
// return the final answer
return (sign<<(bits-1)) | (exp<<(bits-expbits-1)) | significand;
}
static double unpack754(uint64_t i, unsigned bits, unsigned expbits)
{
double result;
long long shift;
unsigned bias;
unsigned significandbits = bits - expbits - 1; // -1 for sign bit
if (i == 0) return 0.0;
// pull the significand
result = (i&((1LL<<significandbits)-1)); // mask
result /= (1LL<<significandbits); // convert back to float
result += 1.0f; // add the one back on
// deal with the exponent
bias = (1<<(expbits-1)) - 1;
shift = ((i>>significandbits)&((1LL<<expbits)-1)) - bias;
while(shift > 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)