paysages: Added PackStream to load/save.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@303 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-04-22 17:12:39 +00:00 committed by ThunderK
parent 3c7c682e07
commit e56489062a
41 changed files with 556 additions and 480 deletions

View file

@ -23,4 +23,13 @@ run_cli:
run_qt:
LD_LIBRARY_PATH=${BUILDPATH} ${BUILDPATH}/paysages-qt
profile:
sudo opcontrol --setup --no-vmlinux --event=CPU_CLK_UNHALTED:3000000:0:1:1 --buffer-size=65536 --callgraph=5 --separate=none
sudo opcontrol --reset
sudo opcontrol --start
LD_LIBRARY_PATH=${BUILDPATH} ${BUILDPATH}/paysages-qt || true
sudo opcontrol --shutdown
opannotate --source --output-dir=annotated ${BUILDPATH}/libpaysages.so --base-dirs=. --search-dirs=lib_paysages
opreport -l ${BUILDPATH}/libpaysages.so -c -g | less
.PHONY:all clean release

7
TODO
View file

@ -1,14 +1,13 @@
Technology Preview 1 :
- Find a licence and apply it.
Technology Preview 2 :
- Render tab previews should not rerender when changing render options.
- Compute shadows only once for all textures at a same location.
- Add antialiasing option (pay attention to memory usage).
- Add an OSD ability on previews and use it for camera location and user landmarks.
- Add a material editor dialog.
- Add a zone editor dialog for localized textures.
- Add a terrain modifier dialog with zones.
- Add a noise filler (and maybe noise intervals ?).
- Improve curve editor.
- Replace FILE* by a custom type for Save and Load.
- Water and terrain LOD moves with the camera, fix it like in the wanderer.
- Implement a file header/versioning.

View file

@ -22,7 +22,7 @@ DialogWanderer::DialogWanderer(QWidget* parent, CameraDefinition* camera, bool c
panel->setLayout(new QVBoxLayout());
panel->setMaximumWidth(230);
panel->layout()->addWidget(new QLabel(tr("COMMANDS\n\nLeft click : Look around\nRight click : Pan (adjust framing)\nWheel : Move forward/backward\nHold SHIFT : Slower\nHold CTRL : Faster"), panel));
panel->layout()->addWidget(new QLabel(tr("COMMANDS\n\nLeft click : Look around\nRight click : Pan (adjust framing)\nWheel : Move forward/backward\nHold SHIFT : Faster\nHold CTRL : Slower"), panel));
button = new QPushButton(tr("Reset camera"), panel);
panel->layout()->addWidget(button);

View file

@ -8,9 +8,6 @@ MOC_DIR = ./moc/$$BUILDMODE/
DESTDIR = ../build/$$BUILDMODE/
CONFIG += $$BUILDMODE
QMAKE_CXXFLAGS_DEBUG += -pg
QMAKE_LFLAGS_DEBUG += -pg
unix:LIBS += -L$$DESTDIR -lpaysages
win32:LIBS += ../libpaysages.a -lDevIL -lILU -lILUT -lglib-2.0 -lgthread-2.0

View file

@ -42,11 +42,11 @@ void WidgetWanderer::keyPressEvent(QKeyEvent* event)
{
double factor;
if (event->modifiers() & Qt::ShiftModifier)
if (event->modifiers() & Qt::ControlModifier)
{
factor = 0.1;
}
else if (event->modifiers() & Qt::ControlModifier)
else if (event->modifiers() & Qt::ShiftModifier)
{
factor = 10.0;
}
@ -104,11 +104,11 @@ void WidgetWanderer::mouseMoveEvent(QMouseEvent* event)
{
double factor;
if (event->modifiers() & Qt::ShiftModifier)
if (event->modifiers() & Qt::ControlModifier)
{
factor = 0.01;
}
else if (event->modifiers() & Qt::ControlModifier)
else if (event->modifiers() & Qt::ShiftModifier)
{
factor = 1.0;
}
@ -145,11 +145,11 @@ void WidgetWanderer::wheelEvent(QWheelEvent* event)
{
double factor;
if (event->modifiers() & Qt::ShiftModifier)
if (event->modifiers() & Qt::ControlModifier)
{
factor = 0.01;
}
else if (event->modifiers() & Qt::ControlModifier)
else if (event->modifiers() & Qt::ShiftModifier)
{
factor = 1.0;
}

View file

@ -169,6 +169,7 @@ Cliquez avec le bouton droit sur un point pour le supprimer.</translation>
<translation>Paysages 3D - Exploration</translation>
</message>
<message>
<location filename="../gui_qt/dialogwanderer.cpp" line="25"/>
<source>COMMANDS
Left click : Look around
@ -176,16 +177,15 @@ Right click : Pan (adjust framing)
Wheel : Move forward/backward
Hold SHIFT : Faster
Hold CTRL : Slower</source>
<translation type="obsolete">COMMANDES
<translation>COMMANDES
Clic gauche : Regarder autour
Clic droit : Déplacer le cadrage
Molette : Avancer/reculer
Maintenir MAJ : Plus rapide
Maintenir Maj : Plus rapide
Maintenir Ctrl : Plus lent</translation>
</message>
<message>
<location filename="../gui_qt/dialogwanderer.cpp" line="25"/>
<source>COMMANDS
Left click : Look around
@ -193,7 +193,7 @@ Right click : Pan (adjust framing)
Wheel : Move forward/backward
Hold SHIFT : Slower
Hold CTRL : Faster</source>
<translation>COMMANDES
<translation type="obsolete">COMMANDES
Clic gauche : Regarder autour
Clic droit : Déplacer le cadrage

View file

@ -14,22 +14,22 @@ void atmosphereQuit()
{
}
void atmosphereSave(FILE* f, AtmosphereDefinition* definition)
void atmosphereSave(PackStream* stream, AtmosphereDefinition* definition)
{
toolsSaveDouble(f, &definition->distance_near);
toolsSaveDouble(f, &definition->distance_far);
toolsSaveDouble(f, &definition->full_mask);
toolsSaveInt(f, &definition->auto_lock_on_haze);
colorSave(f, &definition->color);
packWriteDouble(stream, &definition->distance_near);
packWriteDouble(stream, &definition->distance_far);
packWriteDouble(stream, &definition->full_mask);
packWriteInt(stream, &definition->auto_lock_on_haze);
colorSave(stream, &definition->color);
}
void atmosphereLoad(FILE* f, AtmosphereDefinition* definition)
void atmosphereLoad(PackStream* stream, AtmosphereDefinition* definition)
{
toolsLoadDouble(f, &definition->distance_near);
toolsLoadDouble(f, &definition->distance_far);
toolsLoadDouble(f, &definition->full_mask);
toolsLoadInt(f, &definition->auto_lock_on_haze);
colorLoad(f, &definition->color);
packReadDouble(stream, &definition->distance_near);
packReadDouble(stream, &definition->distance_far);
packReadDouble(stream, &definition->full_mask);
packReadInt(stream, &definition->auto_lock_on_haze);
colorLoad(stream, &definition->color);
atmosphereValidateDefinition(definition);
}

View file

@ -2,6 +2,7 @@
#define _PAYSAGES_ATMOSPHERE_H_
#include "shared/types.h"
#include "pack.h"
#include "lighting.h"
#include <stdio.h>
@ -20,8 +21,8 @@ typedef struct
void atmosphereInit();
void atmosphereQuit();
void atmosphereSave(FILE* f, AtmosphereDefinition* definition);
void atmosphereLoad(FILE* f, AtmosphereDefinition* definition);
void atmosphereSave(PackStream* stream, AtmosphereDefinition* definition);
void atmosphereLoad(PackStream* stream, AtmosphereDefinition* definition);
AtmosphereDefinition atmosphereCreateDefinition();
void atmosphereDeleteDefinition(AtmosphereDefinition* definition);

View file

@ -17,20 +17,20 @@ void cameraQuit()
{
}
void cameraSave(FILE* f, CameraDefinition* camera)
void cameraSave(PackStream* stream, CameraDefinition* camera)
{
v3Save(f, &camera->location);
toolsSaveDouble(f, &camera->yaw);
toolsSaveDouble(f, &camera->pitch);
toolsSaveDouble(f, &camera->roll);
v3Save(stream, &camera->location);
packWriteDouble(stream, &camera->yaw);
packWriteDouble(stream, &camera->pitch);
packWriteDouble(stream, &camera->roll);
}
void cameraLoad(FILE* f, CameraDefinition* camera)
void cameraLoad(PackStream* stream, CameraDefinition* camera)
{
v3Load(f, &camera->location);
toolsLoadDouble(f, &camera->yaw);
toolsLoadDouble(f, &camera->pitch);
toolsLoadDouble(f, &camera->roll);
v3Load(stream, &camera->location);
packReadDouble(stream, &camera->yaw);
packReadDouble(stream, &camera->pitch);
packReadDouble(stream, &camera->roll);
cameraValidateDefinition(camera, 0);
}

View file

@ -1,9 +1,9 @@
#ifndef _PAYSAGES_CAMERA_H_
#define _PAYSAGES_CAMERA_H_
#include <stdio.h>
#include "shared/types.h"
#include "renderer.h"
#include "pack.h"
#ifdef __cplusplus
extern "C" {
@ -11,8 +11,8 @@ extern "C" {
void cameraInit();
void cameraQuit();
void cameraSave(FILE* f, CameraDefinition* camera);
void cameraLoad(FILE* f, CameraDefinition* camera);
void cameraSave(PackStream* stream, CameraDefinition* camera);
void cameraLoad(PackStream* stream, CameraDefinition* camera);
CameraDefinition cameraCreateDefinition();
void cameraDeleteDefinition(CameraDefinition* definition);

View file

@ -32,30 +32,30 @@ void cloudsQuit()
cloudsLayerDeleteDefinition(&NULL_LAYER);
}
void cloudsSave(FILE* f, CloudsDefinition* definition)
void cloudsSave(PackStream* stream, CloudsDefinition* definition)
{
int i;
CloudsLayerDefinition* layer;
toolsSaveInt(f, &definition->nblayers);
packWriteInt(stream, &definition->nblayers);
for (i = 0; i < definition->nblayers; i++)
{
layer = definition->layers + i;
toolsSaveDouble(f, &layer->ycenter);
toolsSaveDouble(f, &layer->ymin);
toolsSaveDouble(f, &layer->ymax);
noiseSaveGenerator(f, layer->noise);
materialSave(f, &layer->material);
toolsSaveDouble(f, &layer->transparencydepth);
toolsSaveDouble(f, &layer->lighttraversal);
toolsSaveDouble(f, &layer->minimumlight);
toolsSaveDouble(f, &layer->scaling);
toolsSaveDouble(f, &layer->coverage);
packWriteDouble(stream, &layer->ycenter);
packWriteDouble(stream, &layer->ymin);
packWriteDouble(stream, &layer->ymax);
noiseSaveGenerator(stream, layer->noise);
materialSave(stream, &layer->material);
packWriteDouble(stream, &layer->transparencydepth);
packWriteDouble(stream, &layer->lighttraversal);
packWriteDouble(stream, &layer->minimumlight);
packWriteDouble(stream, &layer->scaling);
packWriteDouble(stream, &layer->coverage);
}
}
void cloudsLoad(FILE* f, CloudsDefinition* definition)
void cloudsLoad(PackStream* stream, CloudsDefinition* definition)
{
int i, n;
CloudsLayerDefinition* layer;
@ -65,21 +65,21 @@ void cloudsLoad(FILE* f, CloudsDefinition* definition)
cloudsDeleteLayer(definition, 0);
}
toolsLoadInt(f, &n);
packReadInt(stream, &n);
for (i = 0; i < n; i++)
{
layer = definition->layers + cloudsAddLayer(definition);
toolsLoadDouble(f, &layer->ycenter);
toolsLoadDouble(f, &layer->ymin);
toolsLoadDouble(f, &layer->ymax);
noiseLoadGenerator(f, layer->noise);
materialLoad(f, &layer->material);
toolsLoadDouble(f, &layer->transparencydepth);
toolsLoadDouble(f, &layer->lighttraversal);
toolsLoadDouble(f, &layer->minimumlight);
toolsLoadDouble(f, &layer->scaling);
toolsLoadDouble(f, &layer->coverage);
packReadDouble(stream, &layer->ycenter);
packReadDouble(stream, &layer->ymin);
packReadDouble(stream, &layer->ymax);
noiseLoadGenerator(stream, layer->noise);
materialLoad(stream, &layer->material);
packReadDouble(stream, &layer->transparencydepth);
packReadDouble(stream, &layer->lighttraversal);
packReadDouble(stream, &layer->minimumlight);
packReadDouble(stream, &layer->scaling);
packReadDouble(stream, &layer->coverage);
}
}

View file

@ -39,8 +39,8 @@ typedef struct
void cloudsInit();
void cloudsQuit();
void cloudsSave(FILE* f, CloudsDefinition* definition);
void cloudsLoad(FILE* f, CloudsDefinition* definition);
void cloudsSave(PackStream* stream, CloudsDefinition* definition);
void cloudsLoad(PackStream* stream, CloudsDefinition* definition);
CloudsDefinition cloudsCreateDefinition();
void cloudsDeleteDefinition(CloudsDefinition* definition);

View file

@ -22,20 +22,20 @@ struct ColorGradation
Curve* blue;
};
void colorSave(FILE* f, Color* col)
void colorSave(PackStream* stream, Color* col)
{
toolsSaveDouble(f, &col->r);
toolsSaveDouble(f, &col->g);
toolsSaveDouble(f, &col->b);
toolsSaveDouble(f, &col->a);
packWriteDouble(stream, &col->r);
packWriteDouble(stream, &col->g);
packWriteDouble(stream, &col->b);
packWriteDouble(stream, &col->a);
}
void colorLoad(FILE* f, Color* col)
void colorLoad(PackStream* stream, Color* col)
{
toolsLoadDouble(f, &col->r);
toolsLoadDouble(f, &col->g);
toolsLoadDouble(f, &col->b);
toolsLoadDouble(f, &col->a);
packReadDouble(stream, &col->r);
packReadDouble(stream, &col->g);
packReadDouble(stream, &col->b);
packReadDouble(stream, &col->a);
}
unsigned int colorTo32BitRGBA(Color* col)
@ -137,18 +137,18 @@ void colorGradationCopy(ColorGradation* source, ColorGradation* destination)
curveCopy(source->blue, destination->blue);
}
void colorGradationSave(FILE* f, ColorGradation* gradation)
void colorGradationSave(PackStream* stream, ColorGradation* gradation)
{
curveSave(f, gradation->red);
curveSave(f, gradation->green);
curveSave(f, gradation->blue);
curveSave(stream, gradation->red);
curveSave(stream, gradation->green);
curveSave(stream, gradation->blue);
}
void colorGradationLoad(FILE* f, ColorGradation* gradation)
void colorGradationLoad(PackStream* stream, ColorGradation* gradation)
{
curveLoad(f, gradation->red);
curveLoad(f, gradation->green);
curveLoad(f, gradation->blue);
curveLoad(stream, gradation->red);
curveLoad(stream, gradation->green);
curveLoad(stream, gradation->blue);
}
void colorGradationGetRedCurve(ColorGradation* gradation, Curve* curve)

View file

@ -10,8 +10,8 @@ extern "C" {
#endif
/* Color */
void colorSave(FILE* f, Color* col);
void colorLoad(FILE* f, Color* col);
void colorSave(PackStream* stream, Color* col);
void colorLoad(PackStream* stream, Color* col);
unsigned int colorTo32BitRGBA(Color* col);
unsigned int colorTo32BitBGRA(Color* col);
@ -29,8 +29,8 @@ ColorGradation* colorGradationCreate();
void colorGradationDelete(ColorGradation* gradation);
void colorGradationCopy(ColorGradation* source, ColorGradation* destination);
void colorGradationSave(FILE* f, ColorGradation* gradation);
void colorGradationLoad(FILE* f, ColorGradation* gradation);
void colorGradationSave(PackStream* stream, ColorGradation* gradation);
void colorGradationLoad(PackStream* stream, ColorGradation* gradation);
void colorGradationGetRedCurve(ColorGradation* gradation, Curve* curve);
void colorGradationGetGreenCurve(ColorGradation* gradation, Curve* curve);

View file

@ -32,27 +32,27 @@ void curveCopy(Curve* source, Curve* destination)
*destination = *source;
}
void curveSave(FILE* f, Curve* curve)
void curveSave(PackStream* stream, Curve* curve)
{
int i;
toolsSaveInt(f, &curve->nbpoints);
packWriteInt(stream, &curve->nbpoints);
for (i = 0; i < curve->nbpoints; i++)
{
toolsSaveDouble(f, &curve->points[i].position);
toolsSaveDouble(f, &curve->points[i].value);
packWriteDouble(stream, &curve->points[i].position);
packWriteDouble(stream, &curve->points[i].value);
}
}
void curveLoad(FILE* f, Curve* curve)
void curveLoad(PackStream* stream, Curve* curve)
{
int i;
toolsLoadInt(f, &curve->nbpoints);
packReadInt(stream, &curve->nbpoints);
for (i = 0; i < curve->nbpoints; i++)
{
toolsLoadDouble(f, &curve->points[i].position);
toolsLoadDouble(f, &curve->points[i].value);
packReadDouble(stream, &curve->points[i].position);
packReadDouble(stream, &curve->points[i].value);
}
}

View file

@ -1,7 +1,7 @@
#ifndef _PAYSAGES_CURVE_H_
#define _PAYSAGES_CURVE_H_
#include <stdio.h>
#include "pack.h"
#ifdef __cplusplus
extern "C" {
@ -17,8 +17,8 @@ Curve* curveCreate();
void curveDelete(Curve* curve);
void curveCopy(Curve* source, Curve* destination);
void curveSave(FILE* f, Curve* curve);
void curveLoad(FILE* f, Curve* curve);
void curveSave(PackStream* stream, Curve* curve);
void curveLoad(PackStream* stream, Curve* curve);
void curveClear(Curve* curve);
int curveAddPoint(Curve* curve, CurvePoint* point);

View file

@ -6,18 +6,18 @@
Vector3 VECTOR_ZERO = {0.0, 0.0, 0.0};
void v3Save(FILE* f, Vector3* v)
void v3Save(PackStream* stream, Vector3* v)
{
toolsSaveDouble(f, &v->x);
toolsSaveDouble(f, &v->y);
toolsSaveDouble(f, &v->z);
packWriteDouble(stream, &v->x);
packWriteDouble(stream, &v->y);
packWriteDouble(stream, &v->z);
}
void v3Load(FILE* f, Vector3* v)
void v3Load(PackStream* stream, Vector3* v)
{
toolsLoadDouble(f, &v->x);
toolsLoadDouble(f, &v->y);
toolsLoadDouble(f, &v->z);
packReadDouble(stream, &v->x);
packReadDouble(stream, &v->y);
packReadDouble(stream, &v->z);
}
Vector3 v3Translate(Vector3 v1, double x, double y, double z)
@ -97,44 +97,44 @@ Vector3 v3Cross(Vector3 v1, Vector3 v2)
return result;
}
void m4Save(FILE* f, Matrix4* m)
void m4Save(PackStream* stream, Matrix4* m)
{
toolsSaveDouble(f, &m->a);
toolsSaveDouble(f, &m->b);
toolsSaveDouble(f, &m->c);
toolsSaveDouble(f, &m->d);
toolsSaveDouble(f, &m->e);
toolsSaveDouble(f, &m->f);
toolsSaveDouble(f, &m->g);
toolsSaveDouble(f, &m->h);
toolsSaveDouble(f, &m->i);
toolsSaveDouble(f, &m->j);
toolsSaveDouble(f, &m->k);
toolsSaveDouble(f, &m->l);
toolsSaveDouble(f, &m->m);
toolsSaveDouble(f, &m->n);
toolsSaveDouble(f, &m->o);
toolsSaveDouble(f, &m->p);
packWriteDouble(stream, &m->a);
packWriteDouble(stream, &m->b);
packWriteDouble(stream, &m->c);
packWriteDouble(stream, &m->d);
packWriteDouble(stream, &m->e);
packWriteDouble(stream, &m->f);
packWriteDouble(stream, &m->g);
packWriteDouble(stream, &m->h);
packWriteDouble(stream, &m->i);
packWriteDouble(stream, &m->j);
packWriteDouble(stream, &m->k);
packWriteDouble(stream, &m->l);
packWriteDouble(stream, &m->m);
packWriteDouble(stream, &m->n);
packWriteDouble(stream, &m->o);
packWriteDouble(stream, &m->p);
}
void m4Load(FILE* f, Matrix4* m)
void m4Load(PackStream* stream, Matrix4* m)
{
toolsLoadDouble(f, &m->a);
toolsLoadDouble(f, &m->b);
toolsLoadDouble(f, &m->c);
toolsLoadDouble(f, &m->d);
toolsLoadDouble(f, &m->e);
toolsLoadDouble(f, &m->f);
toolsLoadDouble(f, &m->g);
toolsLoadDouble(f, &m->h);
toolsLoadDouble(f, &m->i);
toolsLoadDouble(f, &m->j);
toolsLoadDouble(f, &m->k);
toolsLoadDouble(f, &m->l);
toolsLoadDouble(f, &m->m);
toolsLoadDouble(f, &m->n);
toolsLoadDouble(f, &m->o);
toolsLoadDouble(f, &m->p);
packReadDouble(stream, &m->a);
packReadDouble(stream, &m->b);
packReadDouble(stream, &m->c);
packReadDouble(stream, &m->d);
packReadDouble(stream, &m->e);
packReadDouble(stream, &m->f);
packReadDouble(stream, &m->g);
packReadDouble(stream, &m->h);
packReadDouble(stream, &m->i);
packReadDouble(stream, &m->j);
packReadDouble(stream, &m->k);
packReadDouble(stream, &m->l);
packReadDouble(stream, &m->m);
packReadDouble(stream, &m->n);
packReadDouble(stream, &m->o);
packReadDouble(stream, &m->p);
}
Matrix4 m4NewIdentity()

View file

@ -2,13 +2,14 @@
#define _PAYSAGES_EUCLID_H_
#include "shared/types.h"
#include "pack.h"
#ifdef __cplusplus
extern "C" {
#endif
void v3Save(FILE* f, Vector3* v);
void v3Load(FILE* f, Vector3* v);
void v3Save(PackStream* stream, Vector3* v);
void v3Load(PackStream* stream, Vector3* v);
Vector3 v3Translate(Vector3 v1, double x, double y, double z);
Vector3 v3Add(Vector3 v1, Vector3 v2);
Vector3 v3Sub(Vector3 v1, Vector3 v2);
@ -19,8 +20,8 @@ Vector3 v3Normalize(Vector3 v);
double v3Dot(Vector3 v1, Vector3 v2);
Vector3 v3Cross(Vector3 v1, Vector3 v2);
void m4Save(FILE* f, Matrix4* m);
void m4Load(FILE* f, Matrix4* m);
void m4Save(PackStream* stream, Matrix4* m);
void m4Load(PackStream* stream, Matrix4* m);
Matrix4 m4NewIdentity();
Matrix4 m4Mult(Matrix4 m1, Matrix4 m2);
Vector3 m4MultPoint(Matrix4 m, Vector3 v);

View file

@ -34,37 +34,37 @@ void lightingQuit()
{
}
void lightingSave(FILE* f, LightingDefinition* definition)
void lightingSave(PackStream* stream, LightingDefinition* definition)
{
int i;
toolsSaveInt(f, &definition->autosetfromsky);
toolsSaveInt(f, &definition->nblights);
packWriteInt(stream, &definition->autosetfromsky);
packWriteInt(stream, &definition->nblights);
for (i = 0; i < definition->nblights; i++)
{
v3Save(f, &definition->lights[i].direction);
colorSave(f, &definition->lights[i].color);
toolsSaveDouble(f, &definition->lights[i].reflection);
toolsSaveInt(f, &definition->lights[i].filtered);
toolsSaveInt(f, &definition->lights[i].masked);
toolsSaveDouble(f, &definition->lights[i].amplitude);
v3Save(stream, &definition->lights[i].direction);
colorSave(stream, &definition->lights[i].color);
packWriteDouble(stream, &definition->lights[i].reflection);
packWriteInt(stream, &definition->lights[i].filtered);
packWriteInt(stream, &definition->lights[i].masked);
packWriteDouble(stream, &definition->lights[i].amplitude);
}
}
void lightingLoad(FILE* f, LightingDefinition* definition)
void lightingLoad(PackStream* stream, LightingDefinition* definition)
{
int i;
toolsLoadInt(f, &definition->autosetfromsky);
toolsLoadInt(f, &definition->nblights);
packReadInt(stream, &definition->autosetfromsky);
packReadInt(stream, &definition->nblights);
for (i = 0; i < definition->nblights; i++)
{
v3Load(f, &definition->lights[i].direction);
colorLoad(f, &definition->lights[i].color);
toolsLoadDouble(f, &definition->lights[i].reflection);
toolsLoadInt(f, &definition->lights[i].filtered);
toolsLoadInt(f, &definition->lights[i].masked);
toolsLoadDouble(f, &definition->lights[i].amplitude);
v3Load(stream, &definition->lights[i].direction);
colorLoad(stream, &definition->lights[i].color);
packReadDouble(stream, &definition->lights[i].reflection);
packReadInt(stream, &definition->lights[i].filtered);
packReadInt(stream, &definition->lights[i].masked);
packReadDouble(stream, &definition->lights[i].amplitude);
}
lightingValidateDefinition(definition);

View file

@ -3,7 +3,7 @@
#include "shared/types.h"
#include "renderer.h"
#include <stdio.h>
#include "pack.h"
#ifdef __cplusplus
extern "C" {
@ -32,8 +32,8 @@ typedef struct
void lightingInit();
void lightingQuit();
void lightingSave(FILE* f, LightingDefinition* definition);
void lightingLoad(FILE* f, LightingDefinition* definition);
void lightingSave(PackStream* stream, LightingDefinition* definition);
void lightingLoad(PackStream* stream, LightingDefinition* definition);
LightingDefinition lightingCreateDefinition();
void lightingDeleteDefinition(LightingDefinition* definition);

View file

@ -46,18 +46,18 @@ void modifierDelete(HeightModifier* modifier)
free(modifier);
}
void modifierSave(FILE* f, HeightModifier* modifier)
void modifierSave(PackStream* stream, HeightModifier* modifier)
{
toolsSaveInt(f, &modifier->mode);
toolsSaveDouble(f, &modifier->value);
zoneSave(f, modifier->zone);
packWriteInt(stream, &modifier->mode);
packWriteDouble(stream, &modifier->value);
zoneSave(stream, modifier->zone);
}
void modifierLoad(FILE* f, HeightModifier* modifier)
void modifierLoad(PackStream* stream, HeightModifier* modifier)
{
toolsLoadInt(f, &modifier->mode);
toolsLoadDouble(f, &modifier->value);
zoneLoad(f, modifier->zone);
packReadInt(stream, &modifier->mode);
packReadDouble(stream, &modifier->value);
zoneLoad(stream, modifier->zone);
}
Zone* modifierGetZone(HeightModifier* modifier)

View file

@ -1,7 +1,7 @@
#ifndef _PAYSAGES_MODIFIERS_H_
#define _PAYSAGES_MODIFIERS_H_
#include <stdio.h>
#include "pack.h"
#include "zone.h"
#ifdef __cplusplus
@ -13,8 +13,8 @@ typedef struct HeightModifier HeightModifier;
HeightModifier* modifierCreate();
HeightModifier* modifierCreateCopy(HeightModifier* source);
void modifierDelete(HeightModifier* modifier);
void modifierSave(FILE* f, HeightModifier* modifier);
void modifierLoad(FILE* f, HeightModifier* modifier);
void modifierSave(PackStream* stream, HeightModifier* modifier);
void modifierLoad(PackStream* stream, HeightModifier* modifier);
Zone* modifierGetZone(HeightModifier* modifier);
void modifierActionAddValue(HeightModifier* modifier, double value);
void modifierActionFixValue(HeightModifier* modifier, double value);

View file

@ -46,26 +46,26 @@ void noiseQuit()
free(_noise_pool);
}
void noiseSave(FILE* f)
void noiseSave(PackStream* stream)
{
int i;
toolsSaveInt(f, &_noise_pool_size);
packWriteInt(stream, &_noise_pool_size);
for (i = 0; i < _noise_pool_size; i++)
{
toolsSaveDouble(f, _noise_pool + i);
packWriteDouble(stream, _noise_pool + i);
}
}
void noiseLoad(FILE* f)
void noiseLoad(PackStream* stream)
{
int i;
toolsLoadInt(f, &_noise_pool_size);
packReadInt(stream, &_noise_pool_size);
_noise_pool = realloc(_noise_pool, sizeof(double) * _noise_pool_size);
for (i = 0; i < _noise_pool_size; i++)
{
toolsLoadDouble(f, _noise_pool + i);
packReadDouble(stream, _noise_pool + i);
}
}
@ -89,47 +89,47 @@ void noiseDeleteGenerator(NoiseGenerator* generator)
free(generator);
}
void noiseSaveGenerator(FILE* f, NoiseGenerator* perlin)
void noiseSaveGenerator(PackStream* stream, NoiseGenerator* perlin)
{
int x;
toolsSaveInt(f, &perlin->size1);
toolsSaveInt(f, &perlin->size2);
toolsSaveInt(f, &perlin->size3);
toolsSaveDouble(f, &perlin->height_offset);
toolsSaveInt(f, &perlin->level_count);
packWriteInt(stream, &perlin->size1);
packWriteInt(stream, &perlin->size2);
packWriteInt(stream, &perlin->size3);
packWriteDouble(stream, &perlin->height_offset);
packWriteInt(stream, &perlin->level_count);
for (x = 0; x < perlin->level_count; x++)
{
NoiseLevel* level = perlin->levels + x;
toolsSaveDouble(f, &level->scaling);
toolsSaveDouble(f, &level->height);
toolsSaveDouble(f, &level->xoffset);
toolsSaveDouble(f, &level->yoffset);
toolsSaveDouble(f, &level->zoffset);
packWriteDouble(stream, &level->scaling);
packWriteDouble(stream, &level->height);
packWriteDouble(stream, &level->xoffset);
packWriteDouble(stream, &level->yoffset);
packWriteDouble(stream, &level->zoffset);
}
}
void noiseLoadGenerator(FILE* f, NoiseGenerator* perlin)
void noiseLoadGenerator(PackStream* stream, NoiseGenerator* perlin)
{
int x;
toolsLoadInt(f, &perlin->size1);
toolsLoadInt(f, &perlin->size2);
toolsLoadInt(f, &perlin->size3);
toolsLoadDouble(f, &perlin->height_offset);
toolsLoadInt(f, &perlin->level_count);
packReadInt(stream, &perlin->size1);
packReadInt(stream, &perlin->size2);
packReadInt(stream, &perlin->size3);
packReadDouble(stream, &perlin->height_offset);
packReadInt(stream, &perlin->level_count);
for (x = 0; x < perlin->level_count; x++)
{
NoiseLevel* level = perlin->levels + x;
toolsLoadDouble(f, &level->scaling);
toolsLoadDouble(f, &level->height);
toolsLoadDouble(f, &level->xoffset);
toolsLoadDouble(f, &level->yoffset);
toolsLoadDouble(f, &level->zoffset);
packReadDouble(stream, &level->scaling);
packReadDouble(stream, &level->height);
packReadDouble(stream, &level->xoffset);
packReadDouble(stream, &level->yoffset);
packReadDouble(stream, &level->zoffset);
}
}

View file

@ -1,7 +1,7 @@
#ifndef _PAYSAGES_NOISE_H_
#define _PAYSAGES_NOISE_H_
#include <stdio.h>
#include "pack.h"
#ifdef __cplusplus
extern "C" {
@ -20,13 +20,13 @@ typedef struct NoiseGenerator NoiseGenerator;
void noiseInit();
void noiseQuit();
void noiseSave(FILE* f);
void noiseLoad(FILE* f);
void noiseSave(PackStream* stream);
void noiseLoad(PackStream* stream);
NoiseGenerator* noiseCreateGenerator();
void noiseDeleteGenerator(NoiseGenerator* generator);
void noiseSaveGenerator(FILE* f, NoiseGenerator* perlin);
void noiseLoadGenerator(FILE* f, NoiseGenerator* perlin);
void noiseSaveGenerator(PackStream* stream, NoiseGenerator* perlin);
void noiseLoadGenerator(PackStream* stream, NoiseGenerator* perlin);
void noiseCopy(NoiseGenerator* source, NoiseGenerator* destination);
void noiseGenerateBaseNoise(NoiseGenerator* generator, int size);
int noiseGetBaseSize(NoiseGenerator* generator);

139
lib_paysages/pack.c Normal file
View file

@ -0,0 +1,139 @@
#include "pack.h"
#include <assert.h>
#include <stdlib.h>
#include <inttypes.h>
#include <math.h>
#include "color.h"
#include "euclid.h"
struct PackStream
{
FILE* fd;
int write;
};
#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;
}
PackStream* packReadFile(char* filepath)
{
PackStream* result;
result = malloc(sizeof(PackStream));
result->fd = fopen(filepath, "rb");
result->write = 0;
return result;
}
PackStream* packWriteFile(char* filepath)
{
PackStream* result;
result = malloc(sizeof(PackStream));
result->fd = fopen(filepath, "wb");
result->write = 1;
return result;
}
void packCloseStream(PackStream* stream)
{
if (stream->write)
{
fflush(stream->fd);
}
fclose(stream->fd);
free(stream);
}
void packWriteDouble(PackStream* stream, double* value)
{
uint64_t servalue;
servalue = pack754_64(*value);
fwrite(&servalue, sizeof(uint64_t), 1, stream->fd);
}
void packReadDouble(PackStream* stream, double* value)
{
int read;
uint64_t servalue;
read = fread(&servalue, sizeof(uint64_t), 1, stream->fd);
assert(read == 1);
*value = unpack754_64(servalue);
}
void packWriteInt(PackStream* stream, int* value)
{
fprintf(stream->fd, "%d;", *value);
}
void packReadInt(PackStream* stream, int* value)
{
int read;
read = fscanf(stream->fd, "%d;", value);
assert(read == 1);
}

26
lib_paysages/pack.h Normal file
View file

@ -0,0 +1,26 @@
#ifndef _PAYSAGES_PACK_H_
#define _PAYSAGES_PACK_H_
#include <stdio.h>
#include "shared/types.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct PackStream PackStream;
PackStream* packReadFile(char* filepath);
PackStream* packWriteFile(char* filepath);
void packCloseStream(PackStream* stream);
void packWriteDouble(PackStream* stream, double* value);
void packReadDouble(PackStream* stream, double* value);
void packWriteInt(PackStream* stream, int* value);
void packReadInt(PackStream* stream, int* value);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -67,39 +67,38 @@ void sceneryQuit()
void scenerySaveToFile(char* filepath)
{
FILE* f = fopen(filepath, "wb");
PackStream* stream = packWriteFile(filepath);
noiseSave(f);
atmosphereSave(f, &_atmosphere);
cameraSave(f, &_camera);
cloudsSave(f, &_clouds);
lightingSave(f, &_lighting);
skySave(f, &_sky);
terrainSave(f, &_terrain);
texturesSave(f, &_textures);
vegetationSave(f, _vegetation);
waterSave(f, &_water);
noiseSave(stream);
atmosphereSave(stream, &_atmosphere);
cameraSave(stream, &_camera);
cloudsSave(stream, &_clouds);
lightingSave(stream, &_lighting);
skySave(stream, &_sky);
terrainSave(stream, &_terrain);
texturesSave(stream, &_textures);
vegetationSave(stream, _vegetation);
waterSave(stream, &_water);
fflush(f);
fclose(f);
packCloseStream(stream);
}
void sceneryLoadFromFile(char* filepath)
{
FILE* f = fopen(filepath, "rb");
PackStream* stream = packReadFile(filepath);
/* TODO Use intermediary definitions ? */
noiseLoad(f);
atmosphereLoad(f, &_atmosphere);
cameraLoad(f, &_camera);
cloudsLoad(f, &_clouds);
lightingLoad(f, &_lighting);
skyLoad(f, &_sky);
terrainLoad(f, &_terrain);
texturesLoad(f, &_textures);
vegetationLoad(f, _vegetation);
waterLoad(f, &_water);
noiseLoad(stream);
atmosphereLoad(stream, &_atmosphere);
cameraLoad(stream, &_camera);
cloudsLoad(stream, &_clouds);
lightingLoad(stream, &_lighting);
skyLoad(stream, &_sky);
terrainLoad(stream, &_terrain);
texturesLoad(stream, &_textures);
vegetationLoad(stream, _vegetation);
waterLoad(stream, &_water);
atmosphereValidateDefinition(&_atmosphere);
cameraValidateDefinition(&_camera, 0);
@ -111,7 +110,7 @@ void sceneryLoadFromFile(char* filepath)
vegetationValidateDefinition(_vegetation);
waterValidateDefinition(&_water);
fclose(f);
packCloseStream(stream);
}
void scenerySetAtmosphere(AtmosphereDefinition* atmosphere)

View file

@ -22,26 +22,26 @@ void skyQuit()
{
}
void skySave(FILE* f, SkyDefinition* definition)
void skySave(PackStream* stream, SkyDefinition* definition)
{
toolsSaveDouble(f, &definition->daytime);
colorGradationSave(f, definition->sun_color);
toolsSaveDouble(f, &definition->sun_radius);
colorGradationSave(f, definition->zenith_color);
colorGradationSave(f, definition->haze_color);
toolsSaveDouble(f, &definition->haze_height);
toolsSaveDouble(f, &definition->haze_smoothing);
packWriteDouble(stream, &definition->daytime);
colorGradationSave(stream, definition->sun_color);
packWriteDouble(stream, &definition->sun_radius);
colorGradationSave(stream, definition->zenith_color);
colorGradationSave(stream, definition->haze_color);
packWriteDouble(stream, &definition->haze_height);
packWriteDouble(stream, &definition->haze_smoothing);
}
void skyLoad(FILE* f, SkyDefinition* definition)
void skyLoad(PackStream* stream, SkyDefinition* definition)
{
toolsLoadDouble(f, &definition->daytime);
colorGradationLoad(f, definition->sun_color);
toolsLoadDouble(f, &definition->sun_radius);
colorGradationLoad(f, definition->zenith_color);
colorGradationLoad(f, definition->haze_color);
toolsLoadDouble(f, &definition->haze_height);
toolsLoadDouble(f, &definition->haze_smoothing);
packReadDouble(stream, &definition->daytime);
colorGradationLoad(stream, definition->sun_color);
packReadDouble(stream, &definition->sun_radius);
colorGradationLoad(stream, definition->zenith_color);
colorGradationLoad(stream, definition->haze_color);
packReadDouble(stream, &definition->haze_height);
packReadDouble(stream, &definition->haze_smoothing);
skyValidateDefinition(definition);
}

View file

@ -4,7 +4,7 @@
#include "shared/types.h"
#include "color.h"
#include "lighting.h"
#include <stdio.h>
#include "pack.h"
#ifdef __cplusplus
extern "C" {
@ -24,8 +24,8 @@ typedef struct
void skyInit();
void skyQuit();
void skySave(FILE* f, SkyDefinition* definition);
void skyLoad(FILE* f, SkyDefinition* definition);
void skySave(PackStream* stream, SkyDefinition* definition);
void skyLoad(PackStream* stream, SkyDefinition* definition);
SkyDefinition skyCreateDefinition();
void skyDeleteDefinition(SkyDefinition* definition);

View file

@ -21,39 +21,39 @@ void terrainQuit()
{
}
void terrainSave(FILE* f, TerrainDefinition* definition)
void terrainSave(PackStream* stream, TerrainDefinition* definition)
{
int i;
noiseSaveGenerator(f, definition->height_noise);
toolsSaveDouble(f, &definition->height_factor);
toolsSaveDouble(f, &definition->scaling);
noiseSaveGenerator(stream, definition->height_noise);
packWriteDouble(stream, &definition->height_factor);
packWriteDouble(stream, &definition->scaling);
toolsSaveInt(f, &definition->height_modifiers_count);
packWriteInt(stream, &definition->height_modifiers_count);
for (i = 0; i < definition->height_modifiers_count; i++)
{
modifierSave(f, definition->height_modifiers[i]);
modifierSave(stream, definition->height_modifiers[i]);
}
}
void terrainLoad(FILE* f, TerrainDefinition* definition)
void terrainLoad(PackStream* stream, TerrainDefinition* definition)
{
int i, n;
HeightModifier* modifier;
noiseLoadGenerator(f, definition->height_noise);
toolsLoadDouble(f, &definition->height_factor);
toolsLoadDouble(f, &definition->scaling);
noiseLoadGenerator(stream, definition->height_noise);
packReadDouble(stream, &definition->height_factor);
packReadDouble(stream, &definition->scaling);
while (definition->height_modifiers_count > 0)
{
terrainDelModifier(definition, 0);
}
toolsLoadInt(f, &n);
packReadInt(stream, &n);
for (i = 0; i < n; i++)
{
modifier = modifierCreate();
modifierLoad(f, modifier);
modifierLoad(stream, modifier);
terrainAddModifier(definition, modifier);
modifierDelete(modifier);
}

View file

@ -5,7 +5,7 @@
#include "modifiers.h"
#include "noise.h"
#include "lighting.h"
#include <stdio.h>
#include "pack.h"
#ifdef __cplusplus
extern "C" {
@ -26,8 +26,8 @@ typedef struct
void terrainInit();
void terrainQuit();
void terrainSave(FILE* f, TerrainDefinition* definition);
void terrainLoad(FILE* f, TerrainDefinition* definition);
void terrainSave(PackStream* stream, TerrainDefinition* definition);
void terrainLoad(PackStream* stream, TerrainDefinition* definition);
TerrainDefinition terrainCreateDefinition();
void terrainDeleteDefinition(TerrainDefinition* definition);

View file

@ -25,22 +25,22 @@ void texturesQuit()
texturesLayerDeleteDefinition(&_NULL_LAYER);
}
void texturesSave(FILE* f, TexturesDefinition* definition)
void texturesSave(PackStream* stream, TexturesDefinition* definition)
{
int i;
toolsSaveInt(f, &definition->nbtextures);
packWriteInt(stream, &definition->nbtextures);
for (i = 0; i < definition->nbtextures; i++)
{
zoneSave(f, definition->textures[i].zone);
noiseSaveGenerator(f, definition->textures[i].bump_noise);
toolsSaveDouble(f, &definition->textures[i].bump_height);
toolsSaveDouble(f, &definition->textures[i].bump_scaling);
materialSave(f, &definition->textures[i].material);
zoneSave(stream, definition->textures[i].zone);
noiseSaveGenerator(stream, definition->textures[i].bump_noise);
packWriteDouble(stream, &definition->textures[i].bump_height);
packWriteDouble(stream, &definition->textures[i].bump_scaling);
materialSave(stream, &definition->textures[i].material);
}
}
void texturesLoad(FILE* f, TexturesDefinition* definition)
void texturesLoad(PackStream* stream, TexturesDefinition* definition)
{
TextureLayerDefinition* layer;
int i, n;
@ -50,16 +50,16 @@ void texturesLoad(FILE* f, TexturesDefinition* definition)
texturesDeleteLayer(definition, 0);
}
toolsLoadInt(f, &n);
packReadInt(stream, &n);
for (i = 0; i < n; i++)
{
layer = definition->textures + texturesAddLayer(definition);
zoneLoad(f, layer->zone);
noiseLoadGenerator(f, layer->bump_noise);
toolsLoadDouble(f, &layer->bump_height);
toolsLoadDouble(f, &layer->bump_scaling);
materialLoad(f, &layer->material);
zoneLoad(stream, layer->zone);
noiseLoadGenerator(stream, layer->bump_noise);
packReadDouble(stream, &layer->bump_height);
packReadDouble(stream, &layer->bump_scaling);
materialLoad(stream, &layer->material);
}
texturesValidateDefinition(definition);

View file

@ -4,7 +4,7 @@
#include "shared/types.h"
#include "noise.h"
#include "lighting.h"
#include <stdio.h>
#include "pack.h"
#ifdef __cplusplus
extern "C" {
@ -29,8 +29,8 @@ typedef struct
void texturesInit();
void texturesQuit();
void texturesSave(FILE* f, TexturesDefinition* definition);
void texturesLoad(FILE* f, TexturesDefinition* definition);
void texturesSave(PackStream* stream, TexturesDefinition* definition);
void texturesLoad(PackStream* stream, TexturesDefinition* definition);
TexturesDefinition texturesCreateDefinition();
void texturesDeleteDefinition(TexturesDefinition* definition);

View file

@ -8,66 +8,6 @@
#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;
@ -127,48 +67,16 @@ double toolsGetDistance2D(double x1, double y1, double x2, double y2)
return sqrt(dx * dx + dy * dy);
}
void toolsSaveDouble(FILE* f, double* value)
void materialSave(PackStream* stream, SurfaceMaterial* material)
{
uint64_t servalue;
servalue = pack754_64(*value);
fwrite(&servalue, sizeof(uint64_t), 1, f);
colorSave(stream, &material->base);
packWriteDouble(stream, &material->reflection);
packWriteDouble(stream, &material->shininess);
}
void toolsLoadDouble(FILE* f, double* value)
void materialLoad(PackStream* stream, SurfaceMaterial* material)
{
int read;
uint64_t servalue;
read = fread(&servalue, sizeof(uint64_t), 1, f);
assert(read == 1);
*value = unpack754_64(servalue);
}
void toolsSaveInt(FILE* f, int* value)
{
fprintf(f, "%d;", *value);
}
void toolsLoadInt(FILE* f, int* value)
{
int read;
read = fscanf(f, "%d;", value);
assert(read == 1);
}
void materialSave(FILE* f, SurfaceMaterial* material)
{
colorSave(f, &material->base);
toolsSaveDouble(f, &material->reflection);
toolsSaveDouble(f, &material->shininess);
}
void materialLoad(FILE* f, SurfaceMaterial* material)
{
colorLoad(f, &material->base);
toolsLoadDouble(f, &material->reflection);
toolsLoadDouble(f, &material->shininess);
colorLoad(stream, &material->base);
packReadDouble(stream, &material->reflection);
packReadDouble(stream, &material->shininess);
}

View file

@ -1,7 +1,7 @@
#ifndef _PAYSAGES_TOOLS_H_
#define _PAYSAGES_TOOLS_H_
#include <stdio.h>
#include "pack.h"
#include "shared/types.h"
#ifdef __cplusplus
@ -13,12 +13,8 @@ double toolsBicubicInterpolate(double stencil[16], double x, double y);
void toolsFloat2DMapCopy(double* src, double* dest, int src_xstart, int src_ystart, int dest_xstart, int dest_ystart, int xsize, int ysize, int src_xstep, int src_ystep, int dest_xstep, int dest_ystep);
Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right);
double toolsGetDistance2D(double x1, double y1, double x2, double y2);
void toolsSaveDouble(FILE* f, double* value);
void toolsLoadDouble(FILE* f, double* value);
void toolsSaveInt(FILE* f, int* value);
void toolsLoadInt(FILE* f, int* value);
void materialSave(FILE* f, SurfaceMaterial* material);
void materialLoad(FILE* f, SurfaceMaterial* material);
void materialSave(PackStream* stream, SurfaceMaterial* material);
void materialLoad(PackStream* stream, SurfaceMaterial* material);
#ifdef __cplusplus
}

View file

@ -15,11 +15,11 @@ void vegetationQuit()
{
}
void vegetationSave(FILE* f, VegetationDefinition* definition)
void vegetationSave(PackStream* stream, VegetationDefinition* definition)
{
}
void vegetationLoad(FILE* f, VegetationDefinition* definition)
void vegetationLoad(PackStream* stream, VegetationDefinition* definition)
{
}

View file

@ -1,7 +1,7 @@
#ifndef _PAYSAGES_VEGETATION_H_
#define _PAYSAGES_VEGETATION_H_
#include <stdio.h>
#include "pack.h"
#include "zone.h"
#ifdef __cplusplus
@ -20,8 +20,8 @@ typedef struct VegetationDefinition VegetationDefinition;
void vegetationInit();
void vegetationQuit();
void vegetationSave(FILE* f, VegetationDefinition* definition);
void vegetationLoad(FILE* f, VegetationDefinition* definition);
void vegetationSave(PackStream* stream, VegetationDefinition* definition);
void vegetationLoad(PackStream* stream, VegetationDefinition* definition);
VegetationDefinition* vegetationCreateDefinition();
void vegetationDeleteDefinition(VegetationDefinition* definition);

View file

@ -19,32 +19,32 @@ void waterQuit()
{
}
void waterSave(FILE* f, WaterDefinition* definition)
void waterSave(PackStream* stream, WaterDefinition* definition)
{
toolsSaveDouble(f, &definition->height);
materialSave(f, &definition->material);
colorSave(f, &definition->depth_color);
toolsSaveDouble(f, &definition->transparency_depth);
toolsSaveDouble(f, &definition->transparency);
toolsSaveDouble(f, &definition->reflection);
toolsSaveDouble(f, &definition->lighting_depth);
noiseSaveGenerator(f, definition->waves_noise);
toolsSaveDouble(f, &definition->waves_noise_height);
toolsSaveDouble(f, &definition->waves_noise_scale);
packWriteDouble(stream, &definition->height);
materialSave(stream, &definition->material);
colorSave(stream, &definition->depth_color);
packWriteDouble(stream, &definition->transparency_depth);
packWriteDouble(stream, &definition->transparency);
packWriteDouble(stream, &definition->reflection);
packWriteDouble(stream, &definition->lighting_depth);
noiseSaveGenerator(stream, definition->waves_noise);
packWriteDouble(stream, &definition->waves_noise_height);
packWriteDouble(stream, &definition->waves_noise_scale);
}
void waterLoad(FILE* f, WaterDefinition* definition)
void waterLoad(PackStream* stream, WaterDefinition* definition)
{
toolsLoadDouble(f, &definition->height);
materialLoad(f, &definition->material);
colorLoad(f, &definition->depth_color);
toolsLoadDouble(f, &definition->transparency_depth);
toolsLoadDouble(f, &definition->transparency);
toolsLoadDouble(f, &definition->reflection);
toolsLoadDouble(f, &definition->lighting_depth);
noiseLoadGenerator(f, definition->waves_noise);
toolsLoadDouble(f, &definition->waves_noise_height);
toolsLoadDouble(f, &definition->waves_noise_scale);
packReadDouble(stream, &definition->height);
materialLoad(stream, &definition->material);
colorLoad(stream, &definition->depth_color);
packReadDouble(stream, &definition->transparency_depth);
packReadDouble(stream, &definition->transparency);
packReadDouble(stream, &definition->reflection);
packReadDouble(stream, &definition->lighting_depth);
noiseLoadGenerator(stream, definition->waves_noise);
packReadDouble(stream, &definition->waves_noise_height);
packReadDouble(stream, &definition->waves_noise_scale);
waterValidateDefinition(definition);
}

View file

@ -5,7 +5,7 @@
#include "renderer.h"
#include "lighting.h"
#include "noise.h"
#include <stdio.h>
#include "pack.h"
#ifdef __cplusplus
extern "C" {
@ -36,8 +36,8 @@ typedef struct
void waterInit();
void waterQuit();
void waterSave(FILE* f, WaterDefinition* definition);
void waterLoad(FILE* f, WaterDefinition* definition);
void waterSave(PackStream* stream, WaterDefinition* definition);
void waterLoad(PackStream* stream, WaterDefinition* definition);
WaterDefinition waterCreateDefinition();
void waterDeleteDefinition(WaterDefinition* definition);

View file

@ -48,93 +48,93 @@ void zoneDelete(Zone* zone)
free(zone);
}
void zoneSave(FILE* f, Zone* zone)
void zoneSave(PackStream* stream, Zone* zone)
{
int i;
toolsSaveInt(f, &zone->height_ranges_count);
packWriteInt(stream, &zone->height_ranges_count);
for (i = 0; i < zone->height_ranges_count; i++)
{
toolsSaveDouble(f, &zone->height_ranges[i].value);
toolsSaveDouble(f, &zone->height_ranges[i].hardmin);
toolsSaveDouble(f, &zone->height_ranges[i].softmin);
toolsSaveDouble(f, &zone->height_ranges[i].softmax);
toolsSaveDouble(f, &zone->height_ranges[i].hardmax);
packWriteDouble(stream, &zone->height_ranges[i].value);
packWriteDouble(stream, &zone->height_ranges[i].hardmin);
packWriteDouble(stream, &zone->height_ranges[i].softmin);
packWriteDouble(stream, &zone->height_ranges[i].softmax);
packWriteDouble(stream, &zone->height_ranges[i].hardmax);
}
toolsSaveInt(f, &zone->slope_ranges_count);
packWriteInt(stream, &zone->slope_ranges_count);
for (i = 0; i < zone->slope_ranges_count; i++)
{
toolsSaveDouble(f, &zone->slope_ranges[i].value);
toolsSaveDouble(f, &zone->slope_ranges[i].hardmin);
toolsSaveDouble(f, &zone->slope_ranges[i].softmin);
toolsSaveDouble(f, &zone->slope_ranges[i].softmax);
toolsSaveDouble(f, &zone->slope_ranges[i].hardmax);
packWriteDouble(stream, &zone->slope_ranges[i].value);
packWriteDouble(stream, &zone->slope_ranges[i].hardmin);
packWriteDouble(stream, &zone->slope_ranges[i].softmin);
packWriteDouble(stream, &zone->slope_ranges[i].softmax);
packWriteDouble(stream, &zone->slope_ranges[i].hardmax);
}
toolsSaveInt(f, &zone->circles_included_count);
packWriteInt(stream, &zone->circles_included_count);
for (i = 0; i < zone->circles_included_count; i++)
{
toolsSaveDouble(f, &zone->circles_included[i].value);
toolsSaveDouble(f, &zone->circles_included[i].centerx);
toolsSaveDouble(f, &zone->circles_included[i].centerz);
toolsSaveDouble(f, &zone->circles_included[i].softradius);
toolsSaveDouble(f, &zone->circles_included[i].hardradius);
packWriteDouble(stream, &zone->circles_included[i].value);
packWriteDouble(stream, &zone->circles_included[i].centerx);
packWriteDouble(stream, &zone->circles_included[i].centerz);
packWriteDouble(stream, &zone->circles_included[i].softradius);
packWriteDouble(stream, &zone->circles_included[i].hardradius);
}
toolsSaveInt(f, &zone->circles_excluded_count);
packWriteInt(stream, &zone->circles_excluded_count);
for (i = 0; i < zone->circles_excluded_count; i++)
{
toolsSaveDouble(f, &zone->circles_excluded[i].value);
toolsSaveDouble(f, &zone->circles_excluded[i].centerx);
toolsSaveDouble(f, &zone->circles_excluded[i].centerz);
toolsSaveDouble(f, &zone->circles_excluded[i].softradius);
toolsSaveDouble(f, &zone->circles_excluded[i].hardradius);
packWriteDouble(stream, &zone->circles_excluded[i].value);
packWriteDouble(stream, &zone->circles_excluded[i].centerx);
packWriteDouble(stream, &zone->circles_excluded[i].centerz);
packWriteDouble(stream, &zone->circles_excluded[i].softradius);
packWriteDouble(stream, &zone->circles_excluded[i].hardradius);
}
}
void zoneLoad(FILE* f, Zone* zone)
void zoneLoad(PackStream* stream, Zone* zone)
{
int i;
toolsLoadInt(f, &zone->height_ranges_count);
packReadInt(stream, &zone->height_ranges_count);
for (i = 0; i < zone->height_ranges_count; i++)
{
toolsLoadDouble(f, &zone->height_ranges[i].value);
toolsLoadDouble(f, &zone->height_ranges[i].hardmin);
toolsLoadDouble(f, &zone->height_ranges[i].softmin);
toolsLoadDouble(f, &zone->height_ranges[i].softmax);
toolsLoadDouble(f, &zone->height_ranges[i].hardmax);
packReadDouble(stream, &zone->height_ranges[i].value);
packReadDouble(stream, &zone->height_ranges[i].hardmin);
packReadDouble(stream, &zone->height_ranges[i].softmin);
packReadDouble(stream, &zone->height_ranges[i].softmax);
packReadDouble(stream, &zone->height_ranges[i].hardmax);
}
toolsLoadInt(f, &zone->slope_ranges_count);
packReadInt(stream, &zone->slope_ranges_count);
for (i = 0; i < zone->slope_ranges_count; i++)
{
toolsLoadDouble(f, &zone->slope_ranges[i].value);
toolsLoadDouble(f, &zone->slope_ranges[i].hardmin);
toolsLoadDouble(f, &zone->slope_ranges[i].softmin);
toolsLoadDouble(f, &zone->slope_ranges[i].softmax);
toolsLoadDouble(f, &zone->slope_ranges[i].hardmax);
packReadDouble(stream, &zone->slope_ranges[i].value);
packReadDouble(stream, &zone->slope_ranges[i].hardmin);
packReadDouble(stream, &zone->slope_ranges[i].softmin);
packReadDouble(stream, &zone->slope_ranges[i].softmax);
packReadDouble(stream, &zone->slope_ranges[i].hardmax);
}
toolsLoadInt(f, &zone->circles_included_count);
packReadInt(stream, &zone->circles_included_count);
for (i = 0; i < zone->circles_included_count; i++)
{
toolsLoadDouble(f, &zone->circles_included[i].value);
toolsLoadDouble(f, &zone->circles_included[i].centerx);
toolsLoadDouble(f, &zone->circles_included[i].centerz);
toolsLoadDouble(f, &zone->circles_included[i].softradius);
toolsLoadDouble(f, &zone->circles_included[i].hardradius);
packReadDouble(stream, &zone->circles_included[i].value);
packReadDouble(stream, &zone->circles_included[i].centerx);
packReadDouble(stream, &zone->circles_included[i].centerz);
packReadDouble(stream, &zone->circles_included[i].softradius);
packReadDouble(stream, &zone->circles_included[i].hardradius);
}
toolsLoadInt(f, &zone->circles_excluded_count);
packReadInt(stream, &zone->circles_excluded_count);
for (i = 0; i < zone->circles_excluded_count; i++)
{
toolsLoadDouble(f, &zone->circles_excluded[i].value);
toolsLoadDouble(f, &zone->circles_excluded[i].centerx);
toolsLoadDouble(f, &zone->circles_excluded[i].centerz);
toolsLoadDouble(f, &zone->circles_excluded[i].softradius);
toolsLoadDouble(f, &zone->circles_excluded[i].hardradius);
packReadDouble(stream, &zone->circles_excluded[i].value);
packReadDouble(stream, &zone->circles_excluded[i].centerx);
packReadDouble(stream, &zone->circles_excluded[i].centerz);
packReadDouble(stream, &zone->circles_excluded[i].softradius);
packReadDouble(stream, &zone->circles_excluded[i].hardradius);
}
}

View file

@ -2,6 +2,7 @@
#define _PAYSAGES_ZONE_H_
#include "shared/types.h"
#include "pack.h"
#ifdef __cplusplus
extern "C" {
@ -18,8 +19,8 @@ typedef struct
Zone* zoneCreate();
void zoneDelete(Zone* zone);
void zoneSave(FILE* f, Zone* zone);
void zoneLoad(FILE* f, Zone* zone);
void zoneSave(PackStream* stream, Zone* zone);
void zoneLoad(PackStream* stream, Zone* zone);
void zoneCopy(Zone* source, Zone* destination);
void zoneIncludeCircleArea(Zone* zone, double value, double centerx, double centerz, double softradius, double hardradius);
void zoneExcludeCircleArea(Zone* zone, double centerx, double centerz, double softradius, double hardradius);