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;
if (_layers_count < MAX_LAYERS)
{
layer = _layers + _layers_count;
layer->noise = noiseCreateGenerator();
layer->coverage = 0.0;
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

@ -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()
@ -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()