From 23586ee5f478aab679b991cf5cbad8c24da0a04e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 29 Jan 2012 17:39:56 +0000 Subject: [PATCH] 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 --- TODO | 1 - cli/main.c | 1 - gui_qt/dialogrender.cpp | 1 - gui_qt/formrender.cpp | 1 - gui_qt/formsky.cpp | 1 - gui_qt/formterrain.cpp | 1 - gui_qt/formwater.cpp | 13 ++-- gui_qt/inputcamera.cpp | 2 - gui_qt/inputcolorgradation.cpp | 2 - gui_qt/inputnoise.cpp | 2 - gui_qt/mainwindow.cpp | 2 +- gui_qt/tools.h | 2 +- lib_paysages/array.c | 3 +- lib_paysages/array.h | 22 +++++++ lib_paysages/atmosphere.c | 25 ++++---- lib_paysages/auto.c | 14 ++-- lib_paysages/camera.c | 20 +++--- lib_paysages/clouds.c | 38 +++++------ lib_paysages/color.c | 78 +++++++++++------------ lib_paysages/color.h | 31 +++++++++ lib_paysages/euclid.c | 109 +++++++++++++++----------------- lib_paysages/euclid.h | 46 ++++++++++++++ lib_paysages/lighting.c | 42 ++++++------ lib_paysages/main.c | 1 - lib_paysages/main.h | 16 +++++ lib_paysages/modifiers.c | 32 +++++----- lib_paysages/modifiers.h | 5 +- lib_paysages/noise.c | 68 ++++++++++---------- lib_paysages/noise.h | 4 +- lib_paysages/render.c | 4 +- lib_paysages/scenery.c | 6 +- lib_paysages/shared/functions.h | 101 ----------------------------- lib_paysages/shared/types.h | 2 + lib_paysages/sky.c | 34 +++++----- lib_paysages/terrain.c | 24 +++---- lib_paysages/textures.c | 26 ++++---- lib_paysages/tools.c | 45 +++++++------ lib_paysages/tools.h | 26 ++++++++ lib_paysages/water.c | 40 ++++++------ lib_paysages/zone.c | 106 +++++++++++++++---------------- lib_paysages/zone.h | 25 ++++++++ 41 files changed, 543 insertions(+), 479 deletions(-) create mode 100644 lib_paysages/array.h create mode 100644 lib_paysages/color.h create mode 100644 lib_paysages/euclid.h create mode 100644 lib_paysages/main.h delete mode 100644 lib_paysages/shared/functions.h create mode 100644 lib_paysages/tools.h create mode 100644 lib_paysages/zone.h diff --git a/TODO b/TODO index cba5a72..46e4bc7 100644 --- a/TODO +++ b/TODO @@ -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. diff --git a/cli/main.c b/cli/main.c index e9d9f95..2e977ea 100644 --- a/cli/main.c +++ b/cli/main.c @@ -2,7 +2,6 @@ #include #include -#include "../lib_paysages/shared/functions.h" #include "../lib_paysages/auto.h" #include "../lib_paysages/render.h" #include "../lib_paysages/scenery.h" diff --git a/gui_qt/dialogrender.cpp b/gui_qt/dialogrender.cpp index 64427ab..750dde7 100644 --- a/gui_qt/dialogrender.cpp +++ b/gui_qt/dialogrender.cpp @@ -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 { diff --git a/gui_qt/formrender.cpp b/gui_qt/formrender.cpp index 1fdc932..b0aedf7 100644 --- a/gui_qt/formrender.cpp +++ b/gui_qt/formrender.cpp @@ -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) : diff --git a/gui_qt/formsky.cpp b/gui_qt/formsky.cpp index d36712d..8108a93 100644 --- a/gui_qt/formsky.cpp +++ b/gui_qt/formsky.cpp @@ -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; diff --git a/gui_qt/formterrain.cpp b/gui_qt/formterrain.cpp index 9a38f51..51b7a5e 100644 --- a/gui_qt/formterrain.cpp +++ b/gui_qt/formterrain.cpp @@ -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; diff --git a/gui_qt/formwater.cpp b/gui_qt/formwater.cpp index 7a453ed..b366f40 100644 --- a/gui_qt/formwater.cpp +++ b/gui_qt/formwater.cpp @@ -1,17 +1,18 @@ #include "preview.h" #include "formwater.h" -#include "tools.h" + #include #include #include +#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; diff --git a/gui_qt/inputcamera.cpp b/gui_qt/inputcamera.cpp index ffd5cc1..d6f1988 100644 --- a/gui_qt/inputcamera.cpp +++ b/gui_qt/inputcamera.cpp @@ -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; diff --git a/gui_qt/inputcolorgradation.cpp b/gui_qt/inputcolorgradation.cpp index 6b3948e..768a9a9 100644 --- a/gui_qt/inputcolorgradation.cpp +++ b/gui_qt/inputcolorgradation.cpp @@ -7,8 +7,6 @@ #include "tools.h" -#include "../lib_paysages/shared/functions.h" - class ColorGradationPreview:public QWidget { public: diff --git a/gui_qt/inputnoise.cpp b/gui_qt/inputnoise.cpp index e771a21..a43e308 100644 --- a/gui_qt/inputnoise.cpp +++ b/gui_qt/inputnoise.cpp @@ -7,8 +7,6 @@ #include "dialognoise.h" -#include "../lib_paysages/shared/functions.h" - class NoiseSmallPreview:public QWidget { public: diff --git a/gui_qt/mainwindow.cpp b/gui_qt/mainwindow.cpp index 30bb08d..c21b183 100644 --- a/gui_qt/mainwindow.cpp +++ b/gui_qt/mainwindow.cpp @@ -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) { diff --git a/gui_qt/tools.h b/gui_qt/tools.h index eccfb61..54fe7b1 100644 --- a/gui_qt/tools.h +++ b/gui_qt/tools.h @@ -4,7 +4,7 @@ #include #include "../lib_paysages/shared/types.h" -#include "../lib_paysages/shared/functions.h" +#include "../lib_paysages/color.h" static inline QColor colorToQColor(Color color) { diff --git a/lib_paysages/array.c b/lib_paysages/array.c index 7665b79..f0c3a07 100644 --- a/lib_paysages/array.c +++ b/lib_paysages/array.c @@ -1,5 +1,4 @@ -#include "shared/types.h" -#include "shared/functions.h" +#include "array.h" #include #include diff --git a/lib_paysages/array.h b/lib_paysages/array.h new file mode 100644 index 0000000..f523a74 --- /dev/null +++ b/lib_paysages/array.h @@ -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 diff --git a/lib_paysages/atmosphere.c b/lib_paysages/atmosphere.c index 5f1133e..c160201 100644 --- a/lib_paysages/atmosphere.c +++ b/lib_paysages/atmosphere.c @@ -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); } diff --git a/lib_paysages/auto.c b/lib_paysages/auto.c index 3c6455d..ebde561 100644 --- a/lib_paysages/auto.c +++ b/lib_paysages/auto.c @@ -5,20 +5,20 @@ #include #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; diff --git a/lib_paysages/camera.c b/lib_paysages/camera.c index 9db35cc..5521fd0 100644 --- a/lib_paysages/camera.c +++ b/lib_paysages/camera.c @@ -2,13 +2,13 @@ #include #include - +#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); } diff --git a/lib_paysages/clouds.c b/lib_paysages/clouds.c index 9e8e017..3b7b211 100644 --- a/lib_paysages/clouds.c +++ b/lib_paysages/clouds.c @@ -2,10 +2,11 @@ #include #include - +#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); } } diff --git a/lib_paysages/color.c b/lib_paysages/color.c index fcc1673..cef8725 100644 --- a/lib_paysages/color.c +++ b/lib_paysages/color.c @@ -1,9 +1,9 @@ +#include "color.h" + #include #include - -#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; -} diff --git a/lib_paysages/color.h b/lib_paysages/color.h new file mode 100644 index 0000000..3e17ade --- /dev/null +++ b/lib_paysages/color.h @@ -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 diff --git a/lib_paysages/euclid.c b/lib_paysages/euclid.c index ceafb98..e2fb997 100644 --- a/lib_paysages/euclid.c +++ b/lib_paysages/euclid.c @@ -1,70 +1,23 @@ +#include "euclid.h" + #include -#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; diff --git a/lib_paysages/euclid.h b/lib_paysages/euclid.h new file mode 100644 index 0000000..3328433 --- /dev/null +++ b/lib_paysages/euclid.h @@ -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 diff --git a/lib_paysages/lighting.c b/lib_paysages/lighting.c index b718a51..9a23850 100644 --- a/lib_paysages/lighting.c +++ b/lib_paysages/lighting.c @@ -6,14 +6,16 @@ #include #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); diff --git a/lib_paysages/main.c b/lib_paysages/main.c index b3b2e55..a268141 100644 --- a/lib_paysages/main.c +++ b/lib_paysages/main.c @@ -6,7 +6,6 @@ #include "shared/types.h" #include "shared/constants.h" -#include "shared/functions.h" #include "shared/globals.h" #include "auto.h" diff --git a/lib_paysages/main.h b/lib_paysages/main.h new file mode 100644 index 0000000..96188ec --- /dev/null +++ b/lib_paysages/main.h @@ -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 diff --git a/lib_paysages/modifiers.c b/lib_paysages/modifiers.c index 05af690..599a6bf 100644 --- a/lib_paysages/modifiers.c +++ b/lib_paysages/modifiers.c @@ -1,20 +1,18 @@ -#include "shared/types.h" -#include "shared/functions.h" #include "modifiers.h" #include -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) diff --git a/lib_paysages/modifiers.h b/lib_paysages/modifiers.h index a0506b3..d63d42c 100644 --- a/lib_paysages/modifiers.h +++ b/lib_paysages/modifiers.h @@ -2,6 +2,7 @@ #define _PAYSAGES_MODIFIERS_H_ #include +#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); diff --git a/lib_paysages/noise.c b/lib_paysages/noise.c index f42fcec..b72433b 100644 --- a/lib_paysages/noise.c +++ b/lib_paysages/noise.c @@ -1,3 +1,11 @@ +#include "noise.h" + +#include +#include +#include + +#include "tools.h" + struct NoiseLevel; struct NoiseGenerator @@ -11,14 +19,6 @@ struct NoiseGenerator struct NoiseLevel* levels; }; -#include "noise.h" - -#include -#include -#include - -#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); } } diff --git a/lib_paysages/noise.h b/lib_paysages/noise.h index e1c3021..1cc2d82 100644 --- a/lib_paysages/noise.h +++ b/lib_paysages/noise.h @@ -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); diff --git a/lib_paysages/render.c b/lib_paysages/render.c index 484f245..c9b0bac 100644 --- a/lib_paysages/render.c +++ b/lib_paysages/render.c @@ -2,13 +2,13 @@ #include #include - #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; diff --git a/lib_paysages/scenery.c b/lib_paysages/scenery.c index 5e36ed4..618fff8 100644 --- a/lib_paysages/scenery.c +++ b/lib_paysages/scenery.c @@ -1,9 +1,10 @@ #include "scenery.h" #include -#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); } diff --git a/lib_paysages/shared/functions.h b/lib_paysages/shared/functions.h deleted file mode 100644 index 5f35d38..0000000 --- a/lib_paysages/shared/functions.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef _PAYSAGES_FUNCTIONS_H_ -#define _PAYSAGES_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "types.h" -#include - -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 diff --git a/lib_paysages/shared/types.h b/lib_paysages/shared/types.h index 6dbb6fa..12c831b 100644 --- a/lib_paysages/shared/types.h +++ b/lib_paysages/shared/types.h @@ -1,6 +1,8 @@ #ifndef _PAYSAGES_TYPES_H_ #define _PAYSAGES_TYPES_H_ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/lib_paysages/sky.c b/lib_paysages/sky.c index b5cfc5a..8d323c3 100644 --- a/lib_paysages/sky.c +++ b/lib_paysages/sky.c @@ -4,12 +4,14 @@ #include #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); } diff --git a/lib_paysages/terrain.c b/lib_paysages/terrain.c index 244ea9a..0ff4f88 100644 --- a/lib_paysages/terrain.c +++ b/lib_paysages/terrain.c @@ -6,13 +6,13 @@ #include #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); } diff --git a/lib_paysages/textures.c b/lib_paysages/textures.c index 798fdfd..f88e373 100644 --- a/lib_paysages/textures.c +++ b/lib_paysages/textures.c @@ -1,16 +1,18 @@ +#include "textures.h" + #include #include #include #include #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); diff --git a/lib_paysages/tools.c b/lib_paysages/tools.c index 28eb617..f63f8fc 100644 --- a/lib_paysages/tools.c +++ b/lib_paysages/tools.c @@ -1,7 +1,10 @@ +#include "tools.h" + +#include #include -#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); } diff --git a/lib_paysages/tools.h b/lib_paysages/tools.h new file mode 100644 index 0000000..68cece3 --- /dev/null +++ b/lib_paysages/tools.h @@ -0,0 +1,26 @@ +#ifndef _PAYSAGES_TOOLS_H_ +#define _PAYSAGES_TOOLS_H_ + +#include +#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 diff --git a/lib_paysages/water.c b/lib_paysages/water.c index 101d2c2..d604689 100644 --- a/lib_paysages/water.c +++ b/lib_paysages/water.c @@ -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 @@ -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); } diff --git a/lib_paysages/zone.c b/lib_paysages/zone.c index 325fc1d..5c281b5 100644 --- a/lib_paysages/zone.c +++ b/lib_paysages/zone.c @@ -1,5 +1,8 @@ +#include "zone.h" + #include #include +#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); } } diff --git a/lib_paysages/zone.h b/lib_paysages/zone.h new file mode 100644 index 0000000..9e13ad6 --- /dev/null +++ b/lib_paysages/zone.h @@ -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