paysages: Fixed saving/loading.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@226 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-18 18:47:46 +00:00 committed by ThunderK
parent 3e3244a036
commit 8c33ce7143
3 changed files with 70 additions and 25 deletions

View file

@ -1,8 +1,8 @@
all:
cd lib_paysages && make
cd cli && make
cd gui_gtk && make
cd gui_qt && qmake && make
@+cd lib_paysages && make
@+cd cli && make
@+cd gui_gtk && make
@+cd gui_qt && qmake && make
clean:
cd lib_paysages && make clean

View file

@ -1,3 +1,4 @@
#include <string.h>
#include <math.h>
#include "shared/types.h"
@ -48,15 +49,19 @@ void cloudsSave(FILE* f)
void cloudsLoad(FILE* f)
{
int i;
int i, n;
CloudsDefinition* layer;
/* FIXME Delete unused noise generators and add missing ones */
_layers_count = toolsLoadInt(f);
for (i = 0; i < _layers_count; i++)
while (_layers_count > 0)
{
layer = _layers + i;
cloudsDeleteLayer(0);
}
n = toolsLoadInt(f);
for (i = 0; i < n; i++)
{
layer = _layers + cloudsAddLayer();
layer->ycenter = toolsLoadDouble(f);
layer->ymin = toolsLoadDouble(f);
layer->ymax = toolsLoadDouble(f);
@ -76,16 +81,31 @@ int cloudsAddLayer()
{
CloudsDefinition* layer;
layer = _layers + _layers_count;
layer->noise = noiseCreateGenerator();
layer->coverage = 0.0;
if (_layers_count < MAX_LAYERS)
{
layer = _layers + _layers_count;
layer->noise = noiseCreateGenerator();
layer->coverage = 0.0;
return _layers_count++;
return _layers_count++;
}
else
{
return _layers_count - 1;
}
}
void cloudsDeleteLayer(int layer)
{
/* TODO */
if (layer >= 0 && layer < _layers_count)
{
noiseDeleteGenerator(_layers[layer].noise);
if (_layers_count > 1 && layer < _layers_count - 1)
{
memmove(_layers + layer, _layers + layer + 1, sizeof(CloudsDefinition) * (_layers_count - layer - 1));
}
_layers_count--;
}
}
CloudsDefinition cloudsCreateDefinition()

View file

@ -25,7 +25,7 @@ void texturesInit()
void texturesSave(FILE* f)
{
int i;
toolsSaveInt(f, _textures_count);
for (i = 0; i < _textures_count; i++)
{
@ -37,7 +37,23 @@ void texturesSave(FILE* f)
void texturesLoad(FILE* f)
{
// TODO
int i, n;
TextureDefinition* texture;
while (_textures_count > 0)
{
texturesDeleteLayer(0);
}
n = toolsLoadInt(f);
for (i = 0; i < n; i++)
{
texture = _textures + texturesAddLayer();
zoneLoad(texture->zone, f);
noiseLoad(texture->bump_noise, f);
texture->color = colorLoad(f);
}
}
int texturesGetLayerCount()
@ -50,7 +66,7 @@ int texturesAddLayer()
if (_textures_count < TEXTURES_MAX)
{
_textures[_textures_count] = texturesCreateDefinition();
return _textures_count++;
}
else
@ -61,7 +77,16 @@ int texturesAddLayer()
void texturesDeleteLayer(int layer)
{
// TODO
if (layer >= 0 && layer < _textures_count)
{
zoneDelete(_textures[layer].zone);
noiseDeleteGenerator(_textures[layer].bump_noise);
if (_textures_count > 1 && layer < _textures_count - 1)
{
memmove(_textures + layer, _textures + layer + 1, sizeof(TextureDefinition) * (_textures_count - layer - 1));
}
_textures_count--;
}
}
TextureDefinition texturesCreateDefinition()
@ -103,7 +128,7 @@ TextureDefinition texturesGetDefinition(int layer)
{
assert(layer >= 0);
assert(layer < _textures_count);
return _textures[layer];
}
@ -159,7 +184,7 @@ Color texturesGetLayerColorCustom(Vector3 location, double shadowing, double det
Color result;
Vector3 normal;
double coverage;
result.a = 0.0;
normal = _getNormal(definition, location, detail * 0.3);
@ -176,7 +201,7 @@ Color texturesGetColorCustom(Vector3 location, double shadowing, double detail,
{
Color result, tex_color;
int i;
result = COLOR_GREEN;
for (i = 0; i < _textures_count; i++)
{
@ -187,16 +212,16 @@ Color texturesGetColorCustom(Vector3 location, double shadowing, double detail,
colorMask(&result, &tex_color);
}
}
return result;
}
Color texturesGetColor(Vector3 location)
{
double shadowing;
/* TODO Use environment to get lights to apply */
shadowing = terrainGetShadow(location, sun_direction_inv);
return texturesGetColorCustom(location, shadowing, renderGetPrecision(location), &_quality, &_environment);
}