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: all:
cd lib_paysages && make @+cd lib_paysages && make
cd cli && make @+cd cli && make
cd gui_gtk && make @+cd gui_gtk && make
cd gui_qt && qmake && make @+cd gui_qt && qmake && make
clean: clean:
cd lib_paysages && make clean cd lib_paysages && make clean

View file

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

View file

@ -37,7 +37,23 @@ void texturesSave(FILE* f)
void texturesLoad(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() int texturesGetLayerCount()
@ -61,7 +77,16 @@ int texturesAddLayer()
void texturesDeleteLayer(int layer) 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() TextureDefinition texturesCreateDefinition()