paysages: Save and load methods have been uniformized + end of the functions.h.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@250 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-29 17:39:56 +00:00 committed by ThunderK
parent b46d25628a
commit 23586ee5f4
41 changed files with 543 additions and 479 deletions

1
TODO
View file

@ -2,7 +2,6 @@
- Camera should respect ratio aspect of render area.
- All noises should use the same entropy pool (saved separately), and avoid reallocs.
- Implement light multi-sampling (mainly for skydome).
- All Save and Load methods should have same signature : void ...Save(FILE*, ...*).
- Remove all global variables (render_quality, render_width...), it should all be set in Renderer.
- Implement scaling and scrolling on previews.
- Water and terrain LOD moves with the camera, fix it like in the wanderer.

View file

@ -2,7 +2,6 @@
#include <stdio.h>
#include <string.h>
#include "../lib_paysages/shared/functions.h"
#include "../lib_paysages/auto.h"
#include "../lib_paysages/render.h"
#include "../lib_paysages/scenery.h"

View file

@ -8,7 +8,6 @@
#include "../lib_paysages/render.h"
#include "../lib_paysages/scenery.h"
#include "../lib_paysages/auto.h"
#include "../lib_paysages/shared/functions.h"
class RenderThread:public QThread
{

View file

@ -6,7 +6,6 @@
#include "inputcamera.h"
#include "../lib_paysages/render.h"
#include "../lib_paysages/scenery.h"
#include "../lib_paysages/shared/functions.h"
/**************** Form ****************/
FormRender::FormRender(QWidget *parent) :

View file

@ -9,7 +9,6 @@
#include "../lib_paysages/sky.h"
#include "../lib_paysages/scenery.h"
#include "../lib_paysages/renderer.h"
#include "../lib_paysages/shared/functions.h"
#include "../lib_paysages/shared/constants.h"
static SkyDefinition _definition;

View file

@ -7,7 +7,6 @@
#include "../lib_paysages/terrain.h"
#include "../lib_paysages/scenery.h"
#include "../lib_paysages/shared/functions.h"
#include "../lib_paysages/shared/constants.h"
static TerrainDefinition _definition;

View file

@ -1,17 +1,18 @@
#include "preview.h"
#include "formwater.h"
#include "tools.h"
#include <QColor>
#include <QSlider>
#include <math.h>
#include "../lib_paysages/shared/constants.h"
#include "../lib_paysages/euclid.h"
#include "../lib_paysages/lighting.h"
#include "../lib_paysages/renderer.h"
#include "../lib_paysages/scenery.h"
#include "../lib_paysages/terrain.h"
#include "../lib_paysages/water.h"
#include "../lib_paysages/lighting.h"
#include "../lib_paysages/scenery.h"
#include "../lib_paysages/renderer.h"
#include "../lib_paysages/shared/functions.h"
#include "../lib_paysages/shared/constants.h"
#include "tools.h"
static WaterDefinition _definition;

View file

@ -7,8 +7,6 @@
#include "dialogwanderer.h"
#include "../lib_paysages/shared/functions.h"
InputCamera::InputCamera(QWidget* form, QString label, CameraDefinition* value):BaseInput(form, label)
{
_value = value;

View file

@ -7,8 +7,6 @@
#include "tools.h"
#include "../lib_paysages/shared/functions.h"
class ColorGradationPreview:public QWidget
{
public:

View file

@ -7,8 +7,6 @@
#include "dialognoise.h"
#include "../lib_paysages/shared/functions.h"
class NoiseSmallPreview:public QWidget
{
public:

View file

@ -18,9 +18,9 @@
#include "dialogrender.h"
#include "dialogwanderer.h"
#include "../lib_paysages/main.h"
#include "../lib_paysages/auto.h"
#include "../lib_paysages/scenery.h"
#include "../lib_paysages/shared/functions.h"
int main(int argc, char** argv)
{

View file

@ -4,7 +4,7 @@
#include <QColor>
#include "../lib_paysages/shared/types.h"
#include "../lib_paysages/shared/functions.h"
#include "../lib_paysages/color.h"
static inline QColor colorToQColor(Color color)
{

View file

@ -1,5 +1,4 @@
#include "shared/types.h"
#include "shared/functions.h"
#include "array.h"
#include <stdlib.h>
#include <string.h>

22
lib_paysages/array.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef _PAYSAGES_ARRAY_H_
#define _PAYSAGES_ARRAY_H_
#include "shared/types.h"
#ifdef __cplusplus
extern "C" {
#endif
void arrayCreate(Array* array, int item_size);
void arrayDelete(Array* array);
void* arrayAppend(Array* array, void* item);
void arrayInsert(Array* array, void* item, int position);
void arrayReplace(Array* array, void* item, int position);
void arrayLStrip(Array* array, int count);
void arrayClear(Array* array);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -1,7 +1,10 @@
#include "atmosphere.h"
#include "shared/functions.h"
#include "shared/constants.h"
#include "scenery.h"
#include "euclid.h"
#include "color.h"
#include "tools.h"
void atmosphereInit()
{
@ -9,20 +12,20 @@ void atmosphereInit()
void atmosphereSave(FILE* f, 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(definition->color, f);
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);
}
void atmosphereLoad(FILE* f, AtmosphereDefinition* definition)
{
definition->distance_near = toolsLoadDouble(f);
definition->distance_far = toolsLoadDouble(f);
definition->full_mask = toolsLoadDouble(f);
definition->auto_lock_on_haze = toolsLoadInt(f);
definition->color = colorLoad(f);
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);
atmosphereValidateDefinition(definition);
}

View file

@ -5,20 +5,20 @@
#include <time.h>
#include "shared/types.h"
#include "shared/functions.h"
#include "shared/constants.h"
#include "shared/globals.h"
#include "system.h"
#include "water.h"
#include "clouds.h"
#include "sky.h"
#include "color.h"
#include "lighting.h"
#include "modifiers.h"
#include "render.h"
#include "terrain.h"
#include "textures.h"
#include "lighting.h"
#include "scenery.h"
#include "render.h"
#include "sky.h"
#include "system.h"
#include "water.h"
#include "zone.h"
static int _is_rendering = 0;

View file

@ -2,13 +2,13 @@
#include <stdlib.h>
#include <math.h>
#include "euclid.h"
#include "render.h"
#include "shared/types.h"
#include "shared/globals.h"
#include "shared/constants.h"
#include "shared/functions.h"
#include "scenery.h"
#include "tools.h"
void cameraInit()
{
@ -16,18 +16,18 @@ void cameraInit()
void cameraSave(FILE* f, CameraDefinition* camera)
{
v3Save(camera->location, f);
toolsSaveDouble(f, camera->yaw);
toolsSaveDouble(f, camera->pitch);
toolsSaveDouble(f, camera->roll);
v3Save(f, &camera->location);
toolsSaveDouble(f, &camera->yaw);
toolsSaveDouble(f, &camera->pitch);
toolsSaveDouble(f, &camera->roll);
}
void cameraLoad(FILE* f, CameraDefinition* camera)
{
camera->location = v3Load(f);
camera->yaw = toolsLoadDouble(f);
camera->pitch = toolsLoadDouble(f);
camera->roll = toolsLoadDouble(f);
v3Load(f, &camera->location);
toolsLoadDouble(f, &camera->yaw);
toolsLoadDouble(f, &camera->pitch);
toolsLoadDouble(f, &camera->roll);
cameraValidateDefinition(camera, 0);
}

View file

@ -2,10 +2,11 @@
#include <string.h>
#include <math.h>
#include "color.h"
#include "euclid.h"
#include "lighting.h"
#include "tools.h"
#include "shared/types.h"
#include "shared/functions.h"
#include "shared/constants.h"
#include "shared/globals.h"
@ -29,17 +30,18 @@ void cloudsSave(FILE* f, CloudsDefinition* definition)
int i;
CloudsLayerDefinition* layer;
toolsSaveInt(f, definition->nblayers);
toolsSaveInt(f, &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);
noiseSave(layer->noise, f);
colorSave(layer->color, f);
toolsSaveDouble(f, layer->scaling);
toolsSaveDouble(f, layer->coverage);
toolsSaveDouble(f, &layer->ycenter);
toolsSaveDouble(f, &layer->ymin);
toolsSaveDouble(f, &layer->ymax);
noiseSave(f, layer->noise);
colorSave(f, &layer->color);
toolsSaveDouble(f, &layer->scaling);
toolsSaveDouble(f, &layer->coverage);
}
}
@ -53,18 +55,18 @@ void cloudsLoad(FILE* f, CloudsDefinition* definition)
cloudsDeleteLayer(definition, 0);
}
n = toolsLoadInt(f);
toolsLoadInt(f, &n);
for (i = 0; i < n; i++)
{
layer = definition->layers + cloudsAddLayer(definition);
layer->ycenter = toolsLoadDouble(f);
layer->ymin = toolsLoadDouble(f);
layer->ymax = toolsLoadDouble(f);
noiseLoad(layer->noise, f);
layer->color = colorLoad(f);
layer->scaling = toolsLoadDouble(f);
layer->coverage = toolsLoadDouble(f);
toolsLoadDouble(f, &layer->ycenter);
toolsLoadDouble(f, &layer->ymin);
toolsLoadDouble(f, &layer->ymax);
noiseLoad(f, layer->noise);
colorLoad(f, &layer->color);
toolsLoadDouble(f, &layer->scaling);
toolsLoadDouble(f, &layer->coverage);
}
}

View file

@ -1,9 +1,9 @@
#include "color.h"
#include <stdlib.h>
#include <assert.h>
#include "shared/types.h"
#include "shared/constants.h"
#include "shared/functions.h"
#include "tools.h"
Color COLOR_TRANSPARENT = {0.0, 0.0, 0.0, 0.0};
Color COLOR_BLACK = {0.0, 0.0, 0.0, 1.0};
@ -13,22 +13,20 @@ Color COLOR_BLUE = {0.0, 0.0, 1.0, 1.0};
Color COLOR_WHITE = {1.0, 1.0, 1.0, 1.0};
Color COLOR_GREY = {0.5, 0.5, 0.5, 1.0};
void colorSave(Color col, FILE* f)
void colorSave(FILE* f, Color* col)
{
toolsSaveDouble(f, col.r);
toolsSaveDouble(f, col.g);
toolsSaveDouble(f, col.b);
toolsSaveDouble(f, col.a);
toolsSaveDouble(f, &col->r);
toolsSaveDouble(f, &col->g);
toolsSaveDouble(f, &col->b);
toolsSaveDouble(f, &col->a);
}
Color colorLoad(FILE* f)
void colorLoad(FILE* f, Color* col)
{
Color col;
col.r = toolsLoadDouble(f);
col.g = toolsLoadDouble(f);
col.b = toolsLoadDouble(f);
col.a = toolsLoadDouble(f);
return col;
toolsLoadDouble(f, &col->r);
toolsLoadDouble(f, &col->g);
toolsLoadDouble(f, &col->b);
toolsLoadDouble(f, &col->a);
}
unsigned int colorTo32BitRGBA(Color* col)
@ -124,6 +122,30 @@ int _part_compare(const void* part1, const void* part2)
}
}
void colorGradationSave(FILE* f, ColorGradation* gradation)
{
int i;
toolsSaveInt(f, &gradation->nbparts);
for (i = 0; i < gradation->nbparts; i++)
{
toolsSaveDouble(f, &gradation->parts[i].start);
colorSave(f, &gradation->parts[i].col);
}
}
void colorGradationLoad(FILE* f, ColorGradation* gradation)
{
int i;
toolsLoadInt(f, &gradation->nbparts);
for (i = 0; i < gradation->nbparts; i++)
{
toolsLoadDouble(f, &gradation->parts[i].start);
colorLoad(f, &gradation->parts[i].col);
}
}
void colorGradationAdd(ColorGradation* gradation, double value, Color* col)
{
if (gradation->nbparts == MAX_COLORGRADATION_PARTS)
@ -188,29 +210,3 @@ Color colorGradationGet(ColorGradation* gradation, double value)
}
}
void colorGradationSave(FILE* f, ColorGradation gradation)
{
int i;
toolsSaveInt(f, gradation.nbparts);
for (i = 0; i < gradation.nbparts; i++)
{
toolsSaveDouble(f, gradation.parts[i].start);
colorSave(gradation.parts[i].col, f);
}
}
ColorGradation colorGradationLoad(FILE* f)
{
ColorGradation result;
int i;
result.nbparts = toolsLoadInt(f);
for (i = 0; i < result.nbparts; i++)
{
result.parts[i].start = toolsLoadDouble(f);
result.parts[i].col = colorLoad(f);
}
return result;
}

31
lib_paysages/color.h Normal file
View file

@ -0,0 +1,31 @@
#ifndef _PAYSAGES_COLOR_H_
#define _PAYSAGES_COLOR_H_
#include "shared/types.h"
#ifdef __cplusplus
extern "C" {
#endif
void colorSave(FILE* f, Color* col);
void colorLoad(FILE* f, Color* col);
unsigned int colorTo32BitRGBA(Color* col);
unsigned int colorTo32BitBGRA(Color* col);
unsigned int colorTo32BitARGB(Color* col);
unsigned int colorTo32BitABGR(Color* col);
void colorMask(Color* base, Color* mask);
double colorNormalize(Color* col);
double colorGetValue(Color* col);
ColorGradation colorGradationCreate();
void colorGradationSave(FILE* f, ColorGradation* gradation);
void colorGradationLoad(FILE* f, ColorGradation* gradation);
void colorGradationAdd(ColorGradation* gradation, double value, Color* col);
void colorGradationAddRgba(ColorGradation* gradation, double value, double r, double g, double b, double a);
Color colorGradationGet(ColorGradation* gradation, double value);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -1,70 +1,23 @@
#include "euclid.h"
#include <math.h>
#include "shared/functions.h"
#include "shared/types.h"
#include "tools.h"
Vector3 VECTOR_ZERO = {0.0, 0.0, 0.0};
void v3Save(Vector3 v, FILE* f)
void v3Save(FILE* f, Vector3* v)
{
toolsSaveDouble(f, v.x);
toolsSaveDouble(f, v.y);
toolsSaveDouble(f, v.z);
toolsSaveDouble(f, &v->x);
toolsSaveDouble(f, &v->y);
toolsSaveDouble(f, &v->z);
}
Vector3 v3Load(FILE* f)
void v3Load(FILE* f, Vector3* v)
{
Vector3 result;
result.x = toolsLoadDouble(f);
result.y = toolsLoadDouble(f);
result.z = toolsLoadDouble(f);
return result;
}
void m4Save(Matrix4 m, FILE* f)
{
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);
}
Matrix4 m4Load(FILE* f)
{
Matrix4 result;
result.a = toolsLoadDouble(f);
result.b = toolsLoadDouble(f);
result.c = toolsLoadDouble(f);
result.d = toolsLoadDouble(f);
result.e = toolsLoadDouble(f);
result.f = toolsLoadDouble(f);
result.g = toolsLoadDouble(f);
result.h = toolsLoadDouble(f);
result.i = toolsLoadDouble(f);
result.j = toolsLoadDouble(f);
result.k = toolsLoadDouble(f);
result.l = toolsLoadDouble(f);
result.m = toolsLoadDouble(f);
result.n = toolsLoadDouble(f);
result.o = toolsLoadDouble(f);
result.p = toolsLoadDouble(f);
return result;
toolsLoadDouble(f, &v->x);
toolsLoadDouble(f, &v->y);
toolsLoadDouble(f, &v->z);
}
Vector3 v3Translate(Vector3 v1, double x, double y, double z)
@ -144,6 +97,46 @@ Vector3 v3Cross(Vector3 v1, Vector3 v2)
return result;
}
void m4Save(FILE* f, 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);
}
void m4Load(FILE* f, 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);
}
Matrix4 m4NewIdentity()
{
Matrix4 result;

46
lib_paysages/euclid.h Normal file
View file

@ -0,0 +1,46 @@
#ifndef _PAYSAGES_EUCLID_H_
#define _PAYSAGES_EUCLID_H_
#include "shared/types.h"
#ifdef __cplusplus
extern "C" {
#endif
void v3Save(FILE* f, Vector3* v);
void v3Load(FILE* f, Vector3* v);
Vector3 v3Translate(Vector3 v1, double x, double y, double z);
Vector3 v3Add(Vector3 v1, Vector3 v2);
Vector3 v3Sub(Vector3 v1, Vector3 v2);
Vector3 v3Neg(Vector3 v);
Vector3 v3Scale(Vector3 v, double scale);
double v3Norm(Vector3 v);
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);
Matrix4 m4NewIdentity();
Matrix4 m4Mult(Matrix4 m1, Matrix4 m2);
Vector3 m4MultPoint(Matrix4 m, Vector3 v);
Vector3 m4Transform(Matrix4 m, Vector3 v);
Matrix4 m4Transpose(Matrix4 m);
Matrix4 m4NewScale(double x, double y, double z);
Matrix4 m4NewTranslate(double x, double y, double z);
Matrix4 m4NewRotateX(double angle);
Matrix4 m4NewRotateY(double angle);
Matrix4 m4NewRotateZ(double angle);
Matrix4 m4NewRotateAxis(double angle, Vector3 axis);
Matrix4 m4NewRotateEuler(double heading, double attitude, double bank);
Matrix4 m4NewRotateTripleAxis(Vector3 x, Vector3 y, Vector3 z);
Matrix4 m4NewLookAt(Vector3 eye, Vector3 at, Vector3 up);
Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far);
double m4Determinant(Matrix4 m);
Matrix4 m4Inverse(Matrix4 m);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -6,14 +6,16 @@
#include <string.h>
#include "shared/types.h"
#include "shared/functions.h"
#include "shared/constants.h"
#include "shared/globals.h"
#include "sky.h"
#include "water.h"
#include "terrain.h"
#include "color.h"
#include "euclid.h"
#include "renderer.h"
#include "scenery.h"
#include "sky.h"
#include "terrain.h"
#include "tools.h"
#include "water.h"
static LightDefinition _LIGHT_NULL;
@ -33,16 +35,16 @@ void lightingSave(FILE* f, LightingDefinition* definition)
{
int i;
toolsSaveInt(f, definition->autosetfromsky);
toolsSaveInt(f, definition->nblights);
toolsSaveInt(f, &definition->autosetfromsky);
toolsSaveInt(f, &definition->nblights);
for (i = 0; i < definition->nblights; i++)
{
v3Save(definition->lights[i].direction, f);
colorSave(definition->lights[i].color, f);
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(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);
}
}
@ -50,16 +52,16 @@ void lightingLoad(FILE* f, LightingDefinition* definition)
{
int i;
definition->autosetfromsky = toolsLoadInt(f);
definition->nblights = toolsLoadInt(f);
toolsLoadInt(f, &definition->autosetfromsky);
toolsLoadInt(f, &definition->nblights);
for (i = 0; i < definition->nblights; i++)
{
definition->lights[i].direction = v3Load(f);
definition->lights[i].color = colorLoad(f);
definition->lights[i].reflection = toolsLoadDouble(f);
definition->lights[i].filtered = toolsLoadInt(f);
definition->lights[i].masked = toolsLoadInt(f);
definition->lights[i].amplitude = toolsLoadDouble(f);
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);
}
lightingValidateDefinition(definition);

View file

@ -6,7 +6,6 @@
#include "shared/types.h"
#include "shared/constants.h"
#include "shared/functions.h"
#include "shared/globals.h"
#include "auto.h"

16
lib_paysages/main.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef _PAYSAGES_MAIN_H_
#define _PAYSAGES_MAIN_H_
#ifdef __cplusplus
extern "C" {
#endif
void paysagesInit();
void paysagesSave(char* filepath);
void paysagesLoad(char* filepath);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -1,20 +1,18 @@
#include "shared/types.h"
#include "shared/functions.h"
#include "modifiers.h"
#include <stdlib.h>
typedef enum
{
MODE_NULL,
MODE_ADD_VALUE,
MODE_FIX_VALUE
} _EnumMode;
#include "shared/types.h"
#include "tools.h"
#define MODE_NULL 0
#define MODE_ADD_VALUE 1
#define MODE_FIX_VALUE 2
struct HeightModifier
{
Zone* zone;
_EnumMode mode;
int mode;
double value;
};
@ -48,18 +46,18 @@ void modifierDelete(HeightModifier* modifier)
free(modifier);
}
void modifierSave(HeightModifier* modifier, FILE* f)
void modifierSave(FILE* f, HeightModifier* modifier)
{
toolsSaveInt(f, modifier->mode);
toolsSaveDouble(f, modifier->value);
zoneSave(modifier->zone, f);
toolsSaveInt(f, &modifier->mode);
toolsSaveDouble(f, &modifier->value);
zoneSave(f, modifier->zone);
}
void modifierLoad(HeightModifier* modifier, FILE* f)
void modifierLoad(FILE* f, HeightModifier* modifier)
{
modifier->mode = toolsLoadInt(f);
modifier->value = toolsLoadDouble(f);
zoneLoad(modifier->zone, f);
toolsLoadInt(f, &modifier->mode);
toolsLoadDouble(f, &modifier->value);
zoneLoad(f, modifier->zone);
}
Zone* modifierGetZone(HeightModifier* modifier)

View file

@ -2,6 +2,7 @@
#define _PAYSAGES_MODIFIERS_H_
#include <stdio.h>
#include "zone.h"
#ifdef __cplusplus
extern "C" {
@ -12,8 +13,8 @@ typedef struct HeightModifier HeightModifier;
HeightModifier* modifierCreate();
HeightModifier* modifierCreateCopy(HeightModifier* source);
void modifierDelete(HeightModifier* modifier);
void modifierSave(HeightModifier* modifier, FILE* f);
void modifierLoad(HeightModifier* modifier, FILE* f);
void modifierSave(FILE* f, HeightModifier* modifier);
void modifierLoad(FILE* f, HeightModifier* modifier);
Zone* modifierGetZone(HeightModifier* modifier);
void modifierActionAddValue(HeightModifier* modifier, double value);
void modifierActionFixValue(HeightModifier* modifier, double value);

View file

@ -1,3 +1,11 @@
#include "noise.h"
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "tools.h"
struct NoiseLevel;
struct NoiseGenerator
@ -11,14 +19,6 @@ struct NoiseGenerator
struct NoiseLevel* levels;
};
#include "noise.h"
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "shared/functions.h"
static inline double _cubicInterpolate(double* p, double x)
{
return p[1] + 0.5 * x * (p[2] - p[0] + x * (2.0 * p[0] - 5.0 * p[1] + 4.0 * p[2] - p[3] + x * (3.0 * (p[1] - p[2]) + p[3] - p[0])));
@ -49,61 +49,63 @@ void noiseDeleteGenerator(NoiseGenerator* generator)
free(generator);
}
void noiseSave(NoiseGenerator* perlin, FILE* f)
void noiseSave(FILE* f, NoiseGenerator* perlin)
{
int x;
double* it_noise;
toolsSaveInt(f, perlin->size1);
toolsSaveInt(f, perlin->size2);
toolsSaveInt(f, perlin->size3);
toolsSaveDouble(f, perlin->height_offset);
toolsSaveInt(f, perlin->level_count);
toolsSaveInt(f, &perlin->size1);
toolsSaveInt(f, &perlin->size2);
toolsSaveInt(f, &perlin->size3);
toolsSaveDouble(f, &perlin->height_offset);
toolsSaveInt(f, &perlin->level_count);
it_noise = perlin->noise;
for (x = 0; x < perlin->size1; x++)
{
toolsSaveDouble(f, *(it_noise++));
toolsSaveDouble(f, it_noise++);
}
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);
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);
}
}
void noiseLoad(NoiseGenerator* perlin, FILE* f)
void noiseLoad(FILE* f, NoiseGenerator* perlin)
{
int x;
double* it_noise;
perlin->size1 = toolsLoadInt(f);
perlin->size2 = toolsLoadInt(f);
perlin->size3 = toolsLoadInt(f);
perlin->height_offset = toolsLoadDouble(f);
perlin->level_count = toolsLoadInt(f);
toolsLoadInt(f, &perlin->size1);
toolsLoadInt(f, &perlin->size2);
toolsLoadInt(f, &perlin->size3);
toolsLoadDouble(f, &perlin->height_offset);
toolsLoadInt(f, &perlin->level_count);
perlin->noise = realloc(perlin->noise, sizeof(double) * perlin->size1);
it_noise = perlin->noise;
for (x = 0; x < perlin->size1; x++)
{
*(it_noise++) = toolsLoadDouble(f);
toolsLoadDouble(f, it_noise++);
}
perlin->levels = realloc(perlin->levels, sizeof(NoiseLevel) * perlin->level_count);
for (x = 0; x < perlin->level_count; x++)
{
NoiseLevel* level = perlin->levels + x;
level->scaling = toolsLoadDouble(f);
level->height = toolsLoadDouble(f);
level->xoffset = toolsLoadDouble(f);
level->yoffset = toolsLoadDouble(f);
level->zoffset = toolsLoadDouble(f);
toolsLoadDouble(f, &level->scaling);
toolsLoadDouble(f, &level->height);
toolsLoadDouble(f, &level->xoffset);
toolsLoadDouble(f, &level->yoffset);
toolsLoadDouble(f, &level->zoffset);
}
}

View file

@ -20,8 +20,8 @@ typedef struct NoiseGenerator NoiseGenerator;
NoiseGenerator* noiseCreateGenerator();
void noiseDeleteGenerator(NoiseGenerator* generator);
void noiseSave(NoiseGenerator* perlin, FILE* f);
void noiseLoad(NoiseGenerator* perlin, FILE* f);
void noiseSave(FILE* f, NoiseGenerator* perlin);
void noiseLoad(FILE* f, NoiseGenerator* perlin);
void noiseCopy(NoiseGenerator* source, NoiseGenerator* destination);
void noiseGenerateBaseNoise(NoiseGenerator* generator, int size);
int noiseGetBaseSize(NoiseGenerator* generator);

View file

@ -2,13 +2,13 @@
#include <stdlib.h>
#include <math.h>
#include "IL/il.h"
#include "IL/ilu.h"
#include "shared/types.h"
#include "shared/constants.h"
#include "shared/functions.h"
#include "array.h"
#include "color.h"
#include "system.h"
int render_width;

View file

@ -1,9 +1,10 @@
#include "scenery.h"
#include <stdio.h>
#include "shared/functions.h"
#include "system.h"
#include "color.h"
#include "euclid.h"
#include "render.h"
#include "system.h"
AtmosphereDefinition _atmosphere;
CameraDefinition _camera;
@ -48,6 +49,7 @@ void scenerySaveToFile(char* filepath)
texturesSave(f, &_textures);
waterSave(f, &_water);
fflush(f);
fclose(f);
}

View file

@ -1,101 +0,0 @@
#ifndef _PAYSAGES_FUNCTIONS_H_
#define _PAYSAGES_FUNCTIONS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "types.h"
#include <stdio.h>
void paysagesInit();
void paysagesSave(char* filepath);
void paysagesLoad(char* filepath);
/* array.c */
void arrayCreate(Array* array, int item_size);
void arrayDelete(Array* array);
void* arrayAppend(Array* array, void* item);
void arrayInsert(Array* array, void* item, int position);
void arrayReplace(Array* array, void* item, int position);
void arrayLStrip(Array* array, int count);
void arrayClear(Array* array);
/* color.c */
void colorSave(Color col, FILE* f);
Color colorLoad(FILE* f);
unsigned int colorTo32BitRGBA(Color* col);
unsigned int colorTo32BitBGRA(Color* col);
unsigned int colorTo32BitARGB(Color* col);
unsigned int colorTo32BitABGR(Color* col);
void colorMask(Color* base, Color* mask);
double colorNormalize(Color* col);
double colorGetValue(Color* col);
ColorGradation colorGradationCreate();
void colorGradationAdd(ColorGradation* gradation, double value, Color* col);
void colorGradationAddRgba(ColorGradation* gradation, double value, double r, double g, double b, double a);
Color colorGradationGet(ColorGradation* gradation, double value);
void colorGradationSave(FILE* f, ColorGradation gradation);
ColorGradation colorGradationLoad(FILE* f);
/* euclid.c */
void v3Save(Vector3 v, FILE* f);
Vector3 v3Load(FILE* f);
void m4Save(Matrix4 m, FILE* f);
Matrix4 m4Load(FILE* f);
Vector3 v3Translate(Vector3 v1, double x, double y, double z);
Vector3 v3Add(Vector3 v1, Vector3 v2);
Vector3 v3Sub(Vector3 v1, Vector3 v2);
Vector3 v3Neg(Vector3 v);
Vector3 v3Scale(Vector3 v, double scale);
double v3Norm(Vector3 v);
Vector3 v3Normalize(Vector3 v);
double v3Dot(Vector3 v1, Vector3 v2);
Vector3 v3Cross(Vector3 v1, Vector3 v2);
Matrix4 m4NewIdentity();
Matrix4 m4Mult(Matrix4 m1, Matrix4 m2);
Vector3 m4MultPoint(Matrix4 m, Vector3 v);
Vector3 m4Transform(Matrix4 m, Vector3 v);
Matrix4 m4Transpose(Matrix4 m);
Matrix4 m4NewScale(double x, double y, double z);
Matrix4 m4NewTranslate(double x, double y, double z);
Matrix4 m4NewRotateX(double angle);
Matrix4 m4NewRotateY(double angle);
Matrix4 m4NewRotateZ(double angle);
Matrix4 m4NewRotateAxis(double angle, Vector3 axis);
Matrix4 m4NewRotateEuler(double heading, double attitude, double bank);
Matrix4 m4NewRotateTripleAxis(Vector3 x, Vector3 y, Vector3 z);
Matrix4 m4NewLookAt(Vector3 eye, Vector3 at, Vector3 up);
Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far);
double m4Determinant(Matrix4 m);
Matrix4 m4Inverse(Matrix4 m);
/* tools.c */
double toolsRandom();
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);
void toolsSaveDouble(FILE* f, double value);
double toolsLoadDouble(FILE* f);
void toolsSaveInt(FILE* f, int value);
int toolsLoadInt(FILE* f);
void materialSave(FILE* f, SurfaceMaterial* material);
void materialLoad(FILE* f, SurfaceMaterial* material);
/* zone.c */
Zone* zoneCreate();
void zoneDelete(Zone* zone);
void zoneSave(Zone* zone, FILE* f);
void zoneLoad(Zone* zone, FILE* f);
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);
void zoneAddHeightRange(Zone* zone, double value, double hardmin, double softmin, double softmax, double hardmax);
void zoneAddSteepnessRange(Zone* zone, double value, double hardmin, double softmin, double softmax, double hardmax);
double zoneGetValue(Zone* zone, Vector3 location, Vector3 normal);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -1,6 +1,8 @@
#ifndef _PAYSAGES_TYPES_H_
#define _PAYSAGES_TYPES_H_
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif

View file

@ -4,12 +4,14 @@
#include <math.h>
#include "shared/types.h"
#include "shared/functions.h"
#include "shared/globals.h"
#include "shared/constants.h"
#include "render.h"
#include "color.h"
#include "clouds.h"
#include "euclid.h"
#include "lighting.h"
#include "render.h"
#include "tools.h"
#define SPHERE_SIZE 1000.0
@ -19,24 +21,24 @@ void skyInit()
void skySave(FILE* f, 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);
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);
}
void skyLoad(FILE* f, SkyDefinition* definition)
{
definition->daytime = toolsLoadDouble(f);
definition->sun_color = colorGradationLoad(f);
definition->sun_radius = toolsLoadDouble(f);
definition->zenith_color = colorGradationLoad(f);
definition->haze_color = colorGradationLoad(f);
definition->haze_height = toolsLoadDouble(f);
definition->haze_smoothing = toolsLoadDouble(f);
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);
skyValidateDefinition(definition);
}

View file

@ -6,13 +6,13 @@
#include <assert.h>
#include "shared/types.h"
#include "shared/functions.h"
#include "shared/globals.h"
#include "shared/constants.h"
#include "euclid.h"
#include "render.h"
#include "textures.h"
#include "water.h"
#include "tools.h"
void terrainInit()
{
@ -22,14 +22,14 @@ void terrainSave(FILE* f, TerrainDefinition* definition)
{
int i;
noiseSave(definition->height_noise, f);
toolsSaveDouble(f, definition->height_factor);
toolsSaveDouble(f, definition->scaling);
noiseSave(f, definition->height_noise);
toolsSaveDouble(f, &definition->height_factor);
toolsSaveDouble(f, &definition->scaling);
toolsSaveInt(f, definition->height_modifiers_count);
toolsSaveInt(f, &definition->height_modifiers_count);
for (i = 0; i < definition->height_modifiers_count; i++)
{
modifierSave(definition->height_modifiers[i], f);
modifierSave(f, definition->height_modifiers[i]);
}
}
@ -38,19 +38,19 @@ void terrainLoad(FILE* f, TerrainDefinition* definition)
int i, n;
HeightModifier* modifier;
noiseLoad(definition->height_noise, f);
definition->height_factor = toolsLoadDouble(f);
definition->scaling = toolsLoadDouble(f);
noiseLoad(f, definition->height_noise);
toolsLoadDouble(f, &definition->height_factor);
toolsLoadDouble(f, &definition->scaling);
while (definition->height_modifiers_count > 0)
{
terrainDelModifier(definition, 0);
}
n = toolsLoadInt(f);
toolsLoadInt(f, &n);
for (i = 0; i < n; i++)
{
modifier = modifierCreate();
modifierLoad(modifier, f);
modifierLoad(f, modifier);
terrainAddModifier(definition, modifier);
modifierDelete(modifier);
}

View file

@ -1,16 +1,18 @@
#include "textures.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "shared/types.h"
#include "shared/functions.h"
#include "shared/constants.h"
#include "shared/globals.h"
#include "textures.h"
#include "terrain.h"
#include "color.h"
#include "euclid.h"
#include "lighting.h"
#include "terrain.h"
#include "tools.h"
static TextureLayerDefinition _NULL_LAYER;
@ -23,12 +25,12 @@ void texturesSave(FILE* f, TexturesDefinition* definition)
{
int i;
toolsSaveInt(f, definition->nbtextures);
toolsSaveInt(f, &definition->nbtextures);
for (i = 0; i < definition->nbtextures; i++)
{
zoneSave(definition->textures[i].zone, f);
noiseSave(definition->textures[i].bump_noise, f);
colorSave(definition->textures[i].color, f);
zoneSave(f, definition->textures[i].zone);
noiseSave(f, definition->textures[i].bump_noise);
colorSave(f, &definition->textures[i].color);
}
}
@ -42,14 +44,14 @@ void texturesLoad(FILE* f, TexturesDefinition* definition)
texturesDeleteLayer(definition, 0);
}
n = toolsLoadInt(f);
toolsLoadInt(f, &n);
for (i = 0; i < n; i++)
{
layer = definition->textures + texturesAddLayer(definition);
zoneLoad(layer->zone, f);
noiseLoad(layer->bump_noise, f);
layer->color = colorLoad(f);
zoneLoad(f, layer->zone);
noiseLoad(f, layer->bump_noise);
colorLoad(f, &layer->color);
}
texturesValidateDefinition(definition);

View file

@ -1,7 +1,10 @@
#include "tools.h"
#include <assert.h>
#include <stdlib.h>
#include "shared/types.h"
#include "shared/functions.h"
#include "color.h"
#include "euclid.h"
double toolsRandom()
{
@ -55,40 +58,42 @@ Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right
return v3Normalize(v3Cross(dz, dx));
}
void toolsSaveDouble(FILE* f, double value)
void toolsSaveDouble(FILE* f, double* value)
{
fprintf(f, "%.20le;", value);
fprintf(f, "%.20le;", *value);
}
double toolsLoadDouble(FILE* f)
void toolsLoadDouble(FILE* f, double* value)
{
double value;
fscanf(f, "%le;", &value);
return value;
int read;
read = fscanf(f, "%le;", value);
assert(read == 1);
}
void toolsSaveInt(FILE* f, int value)
void toolsSaveInt(FILE* f, int* value)
{
fprintf(f, "%d;", value);
fprintf(f, "%d;", *value);
}
int toolsLoadInt(FILE* f)
void toolsLoadInt(FILE* f, int* value)
{
int value;
fscanf(f, "%d;", &value);
return value;
int read;
read = fscanf(f, "%d;", value);
assert(read == 1);
}
void materialSave(FILE* f, SurfaceMaterial* material)
{
colorSave(material->base, f);
toolsSaveDouble(f, material->reflection);
toolsSaveDouble(f, material->shininess);
colorSave(f, &material->base);
toolsSaveDouble(f, &material->reflection);
toolsSaveDouble(f, &material->shininess);
}
void materialLoad(FILE* f, SurfaceMaterial* material)
{
material->base = colorLoad(f);
material->reflection = toolsLoadDouble(f);
material->shininess = toolsLoadDouble(f);
colorLoad(f, &material->base);
toolsLoadDouble(f, &material->reflection);
toolsLoadDouble(f, &material->shininess);
}

26
lib_paysages/tools.h Normal file
View file

@ -0,0 +1,26 @@
#ifndef _PAYSAGES_TOOLS_H_
#define _PAYSAGES_TOOLS_H_
#include <stdio.h>
#include "shared/types.h"
#ifdef __cplusplus
extern "C" {
#endif
double toolsRandom();
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);
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);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -1,12 +1,14 @@
#include "water.h"
#include "shared/types.h"
#include "shared/functions.h"
#include "shared/constants.h"
#include "shared/globals.h"
#include "color.h"
#include "euclid.h"
#include "render.h"
#include "terrain.h"
#include "lighting.h"
#include "tools.h"
#include <math.h>
@ -16,30 +18,30 @@ void waterInit()
void waterSave(FILE* f, WaterDefinition* definition)
{
toolsSaveDouble(f, definition->height);
toolsSaveDouble(f, &definition->height);
materialSave(f, &definition->material);
colorSave(definition->depth_color, f);
toolsSaveDouble(f, definition->transparency_depth);
toolsSaveDouble(f, definition->transparency);
toolsSaveDouble(f, definition->reflection);
toolsSaveDouble(f, definition->lighting_depth);
noiseSave(definition->waves_noise, f);
toolsSaveDouble(f, definition->waves_noise_height);
toolsSaveDouble(f, definition->waves_noise_scale);
colorSave(f, &definition->depth_color);
toolsSaveDouble(f, &definition->transparency_depth);
toolsSaveDouble(f, &definition->transparency);
toolsSaveDouble(f, &definition->reflection);
toolsSaveDouble(f, &definition->lighting_depth);
noiseSave(f, definition->waves_noise);
toolsSaveDouble(f, &definition->waves_noise_height);
toolsSaveDouble(f, &definition->waves_noise_scale);
}
void waterLoad(FILE* f, WaterDefinition* definition)
{
definition->height = toolsLoadDouble(f);
toolsLoadDouble(f, &definition->height);
materialLoad(f, &definition->material);
definition->depth_color = colorLoad(f);
definition->transparency_depth = toolsLoadDouble(f);
definition->transparency = toolsLoadDouble(f);
definition->reflection = toolsLoadDouble(f);
definition->lighting_depth = toolsLoadDouble(f);
noiseLoad(definition->waves_noise, f);
definition->waves_noise_height = toolsLoadDouble(f);
definition->waves_noise_scale = toolsLoadDouble(f);
colorLoad(f, &definition->depth_color);
toolsLoadDouble(f, &definition->transparency_depth);
toolsLoadDouble(f, &definition->transparency);
toolsLoadDouble(f, &definition->reflection);
toolsLoadDouble(f, &definition->lighting_depth);
noiseLoad(f, definition->waves_noise);
toolsLoadDouble(f, &definition->waves_noise_height);
toolsLoadDouble(f, &definition->waves_noise_scale);
waterValidateDefinition(definition);
}

View file

@ -1,5 +1,8 @@
#include "zone.h"
#include <stdlib.h>
#include <math.h>
#include "tools.h"
#define MAX_RANGES 20
#define MAX_CIRCLES 20
@ -36,9 +39,6 @@ struct Zone {
int circles_excluded_count;
};
#include "shared/types.h"
#include "shared/functions.h"
Zone* zoneCreate()
{
Zone* result;
@ -57,93 +57,93 @@ void zoneDelete(Zone* zone)
free(zone);
}
void zoneSave(Zone* zone, FILE* f)
void zoneSave(FILE* f, Zone* zone)
{
int i;
toolsSaveInt(f, zone->height_ranges_count);
toolsSaveInt(f, &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);
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);
}
toolsSaveInt(f, zone->steepness_ranges_count);
toolsSaveInt(f, &zone->steepness_ranges_count);
for (i = 0; i < zone->steepness_ranges_count; i++)
{
toolsSaveDouble(f, zone->steepness_ranges[i].value);
toolsSaveDouble(f, zone->steepness_ranges[i].hardmin);
toolsSaveDouble(f, zone->steepness_ranges[i].softmin);
toolsSaveDouble(f, zone->steepness_ranges[i].softmax);
toolsSaveDouble(f, zone->steepness_ranges[i].hardmax);
toolsSaveDouble(f, &zone->steepness_ranges[i].value);
toolsSaveDouble(f, &zone->steepness_ranges[i].hardmin);
toolsSaveDouble(f, &zone->steepness_ranges[i].softmin);
toolsSaveDouble(f, &zone->steepness_ranges[i].softmax);
toolsSaveDouble(f, &zone->steepness_ranges[i].hardmax);
}
toolsSaveInt(f, zone->circles_included_count);
toolsSaveInt(f, &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);
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);
}
toolsSaveInt(f, zone->circles_excluded_count);
toolsSaveInt(f, &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);
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);
}
}
void zoneLoad(Zone* zone, FILE* f)
void zoneLoad(FILE* f, Zone* zone)
{
int i;
zone->height_ranges_count = toolsLoadInt(f);
toolsLoadInt(f, &zone->height_ranges_count);
for (i = 0; i < zone->height_ranges_count; i++)
{
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 = toolsLoadDouble(f);
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);
}
zone->steepness_ranges_count = toolsLoadInt(f);
toolsLoadInt(f, &zone->steepness_ranges_count);
for (i = 0; i < zone->steepness_ranges_count; i++)
{
zone->steepness_ranges[i].value = toolsLoadDouble(f);
zone->steepness_ranges[i].hardmin = toolsLoadDouble(f);
zone->steepness_ranges[i].softmin = toolsLoadDouble(f);
zone->steepness_ranges[i].softmax = toolsLoadDouble(f);
zone->steepness_ranges[i].hardmax = toolsLoadDouble(f);
toolsLoadDouble(f, &zone->steepness_ranges[i].value);
toolsLoadDouble(f, &zone->steepness_ranges[i].hardmin);
toolsLoadDouble(f, &zone->steepness_ranges[i].softmin);
toolsLoadDouble(f, &zone->steepness_ranges[i].softmax);
toolsLoadDouble(f, &zone->steepness_ranges[i].hardmax);
}
zone->circles_included_count = toolsLoadInt(f);
toolsLoadInt(f, &zone->circles_included_count);
for (i = 0; i < zone->circles_included_count; i++)
{
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 = toolsLoadDouble(f);
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);
}
zone->circles_excluded_count = toolsLoadInt(f);
toolsLoadInt(f, &zone->circles_excluded_count);
for (i = 0; i < zone->circles_excluded_count; i++)
{
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 = toolsLoadDouble(f);
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);
}
}

25
lib_paysages/zone.h Normal file
View file

@ -0,0 +1,25 @@
#ifndef _PAYSAGES_ZONE_H_
#define _PAYSAGES_ZONE_H_
#include "shared/types.h"
#ifdef __cplusplus
extern "C" {
#endif
Zone* zoneCreate();
void zoneDelete(Zone* zone);
void zoneSave(FILE* f, Zone* zone);
void zoneLoad(FILE* f, 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);
void zoneAddHeightRange(Zone* zone, double value, double hardmin, double softmin, double softmax, double hardmax);
void zoneAddSteepnessRange(Zone* zone, double value, double hardmin, double softmin, double softmax, double hardmax);
double zoneGetValue(Zone* zone, Vector3 location, Vector3 normal);
#ifdef __cplusplus
}
#endif
#endif