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:
parent
3e3244a036
commit
8c33ce7143
3 changed files with 70 additions and 25 deletions
8
Makefile
8
Makefile
|
@ -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
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -25,7 +25,7 @@ void texturesInit()
|
||||||
void texturesSave(FILE* f)
|
void texturesSave(FILE* f)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
toolsSaveInt(f, _textures_count);
|
toolsSaveInt(f, _textures_count);
|
||||||
for (i = 0; i < _textures_count; i++)
|
for (i = 0; i < _textures_count; i++)
|
||||||
{
|
{
|
||||||
|
@ -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()
|
||||||
|
@ -50,7 +66,7 @@ int texturesAddLayer()
|
||||||
if (_textures_count < TEXTURES_MAX)
|
if (_textures_count < TEXTURES_MAX)
|
||||||
{
|
{
|
||||||
_textures[_textures_count] = texturesCreateDefinition();
|
_textures[_textures_count] = texturesCreateDefinition();
|
||||||
|
|
||||||
return _textures_count++;
|
return _textures_count++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -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()
|
||||||
|
@ -103,7 +128,7 @@ TextureDefinition texturesGetDefinition(int layer)
|
||||||
{
|
{
|
||||||
assert(layer >= 0);
|
assert(layer >= 0);
|
||||||
assert(layer < _textures_count);
|
assert(layer < _textures_count);
|
||||||
|
|
||||||
return _textures[layer];
|
return _textures[layer];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +184,7 @@ Color texturesGetLayerColorCustom(Vector3 location, double shadowing, double det
|
||||||
Color result;
|
Color result;
|
||||||
Vector3 normal;
|
Vector3 normal;
|
||||||
double coverage;
|
double coverage;
|
||||||
|
|
||||||
result.a = 0.0;
|
result.a = 0.0;
|
||||||
normal = _getNormal(definition, location, detail * 0.3);
|
normal = _getNormal(definition, location, detail * 0.3);
|
||||||
|
|
||||||
|
@ -176,7 +201,7 @@ Color texturesGetColorCustom(Vector3 location, double shadowing, double detail,
|
||||||
{
|
{
|
||||||
Color result, tex_color;
|
Color result, tex_color;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
result = COLOR_GREEN;
|
result = COLOR_GREEN;
|
||||||
for (i = 0; i < _textures_count; i++)
|
for (i = 0; i < _textures_count; i++)
|
||||||
{
|
{
|
||||||
|
@ -187,16 +212,16 @@ Color texturesGetColorCustom(Vector3 location, double shadowing, double detail,
|
||||||
colorMask(&result, &tex_color);
|
colorMask(&result, &tex_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color texturesGetColor(Vector3 location)
|
Color texturesGetColor(Vector3 location)
|
||||||
{
|
{
|
||||||
double shadowing;
|
double shadowing;
|
||||||
|
|
||||||
/* TODO Use environment to get lights to apply */
|
/* TODO Use environment to get lights to apply */
|
||||||
shadowing = terrainGetShadow(location, sun_direction_inv);
|
shadowing = terrainGetShadow(location, sun_direction_inv);
|
||||||
|
|
||||||
return texturesGetColorCustom(location, shadowing, renderGetPrecision(location), &_quality, &_environment);
|
return texturesGetColorCustom(location, shadowing, renderGetPrecision(location), &_quality, &_environment);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue