paysages : Layer sorting (WIP).

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@378 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-07-05 15:01:58 +00:00 committed by ThunderK
parent d3718bde00
commit 50226f0000
10 changed files with 98 additions and 41 deletions

View file

@ -29,6 +29,7 @@ GUI :
* Added grid and axis labels to curve editor. * Added grid and axis labels to curve editor.
* Added camera location to previews. * Added camera location to previews.
* Added toggles and choices to configure some previews. * Added toggles and choices to configure some previews.
* Added layer sorting.
Misc : Misc :
* Version handling in saved files. * Version handling in saved files.

2
TODO
View file

@ -6,7 +6,7 @@ Technology Preview 2 :
- Keep skydome lights in cache for a render. - Keep skydome lights in cache for a render.
- Add buttons to restore "auto" default values in tabs and dialogs. - Add buttons to restore "auto" default values in tabs and dialogs.
- Add "hardness to light" and shadow control ("minimum lighting") to material. - Add "hardness to light" and shadow control ("minimum lighting") to material.
- Add layer sorting/naming. - Add layer naming.
- Add logarithmic sliders for some float values. - Add logarithmic sliders for some float values.
- Improve previews. - Improve previews.
=> Add user markers on OSD => Add user markers on OSD

View file

@ -201,6 +201,14 @@ void FormClouds::layerAddedEvent()
} }
} }
void FormClouds::layerMovedEvent(int layer, int new_position)
{
cloudsMoveLayer(&_definition, layer, new_position);
setLayerCount(cloudsGetLayerCount(&_definition));
BaseForm::layerMovedEvent(layer, new_position);
}
void FormClouds::layerDeletedEvent(int layer) void FormClouds::layerDeletedEvent(int layer)
{ {
cloudsDeleteLayer(&_definition, layer); cloudsDeleteLayer(&_definition, layer);

View file

@ -22,6 +22,7 @@ protected slots:
protected: protected:
virtual void layerAddedEvent(); virtual void layerAddedEvent();
virtual void layerDeletedEvent(int layer); virtual void layerDeletedEvent(int layer);
virtual void layerMovedEvent(int layer, int new_position);
virtual void layerSelectedEvent(int layer); virtual void layerSelectedEvent(int layer);
private: private:

View file

@ -198,6 +198,14 @@ void FormTextures::layerDeletedEvent(int layer)
BaseForm::layerDeletedEvent(layer); BaseForm::layerDeletedEvent(layer);
} }
void FormTextures::layerMovedEvent(int layer, int new_position)
{
texturesMoveLayer(&_definition, layer, new_position);
setLayerCount(texturesGetLayerCount(&_definition));
BaseForm::layerMovedEvent(layer, new_position);
}
void FormTextures::layerSelectedEvent(int layer) void FormTextures::layerSelectedEvent(int layer)
{ {
texturesLayerCopyDefinition(texturesGetLayer(&_definition, layer), &_layer); texturesLayerCopyDefinition(texturesGetLayer(&_definition, layer), &_layer);

View file

@ -16,6 +16,7 @@ public:
protected: protected:
virtual void layerAddedEvent(); virtual void layerAddedEvent();
virtual void layerDeletedEvent(int layer); virtual void layerDeletedEvent(int layer);
virtual void layerMovedEvent(int layer, int new_position);
virtual void layerSelectedEvent(int layer); virtual void layerSelectedEvent(int layer);
public slots: public slots:

View file

@ -271,6 +271,24 @@ void cloudsDeleteLayer(CloudsDefinition* definition, int layer)
} }
} }
void cloudsMoveLayer(CloudsDefinition* definition, int layer, int new_position)
{
if (layer >= 0 && layer < definition->nblayers && new_position != layer && new_position >= 0 && new_position < definition->nblayers)
{
CloudsLayerDefinition temp;
temp = definition->layers[layer];
if (new_position > layer)
{
memmove(definition->layers + layer, definition->layers + layer + 1, sizeof(CloudsLayerDefinition) * (new_position - layer));
}
else
{
memmove(definition->layers + new_position, definition->layers + new_position + 1, sizeof(CloudsLayerDefinition) * (layer - new_position));
}
definition->layers[new_position] = temp;
}
}
static inline double _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3 position) static inline double _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3 position)
{ {
double density, coverage, val; double density, coverage, val;

View file

@ -60,6 +60,7 @@ int cloudsGetLayerCount(CloudsDefinition* definition);
CloudsLayerDefinition* cloudsGetLayer(CloudsDefinition* definition, int layer); CloudsLayerDefinition* cloudsGetLayer(CloudsDefinition* definition, int layer);
int cloudsAddLayer(CloudsDefinition* definition); int cloudsAddLayer(CloudsDefinition* definition);
void cloudsDeleteLayer(CloudsDefinition* definition, int layer); void cloudsDeleteLayer(CloudsDefinition* definition, int layer);
void cloudsMoveLayer(CloudsDefinition* definition, int layer, int new_position);
Color cloudsApplyLayer(CloudsLayerDefinition* definition, Color base, Renderer* renderer, Vector3 start, Vector3 end); Color cloudsApplyLayer(CloudsLayerDefinition* definition, Color base, Renderer* renderer, Vector3 start, Vector3 end);
Color cloudsApply(CloudsDefinition* definition, Color base, Renderer* renderer, Vector3 start, Vector3 end); Color cloudsApply(CloudsDefinition* definition, Color base, Renderer* renderer, Vector3 start, Vector3 end);

View file

@ -36,17 +36,17 @@ void texturesSave(PackStream* stream, TexturesDefinition* definition)
{ {
int i; int i;
packWriteInt(stream, &definition->nbtextures); packWriteInt(stream, &definition->nblayers);
for (i = 0; i < definition->nbtextures; i++) for (i = 0; i < definition->nblayers; i++)
{ {
zoneSave(stream, definition->textures[i].zone); zoneSave(stream, definition->layers[i].zone);
noiseSaveGenerator(stream, definition->textures[i].bump_noise); noiseSaveGenerator(stream, definition->layers[i].bump_noise);
packWriteDouble(stream, &definition->textures[i].bump_height); packWriteDouble(stream, &definition->layers[i].bump_height);
packWriteDouble(stream, &definition->textures[i].bump_scaling); packWriteDouble(stream, &definition->layers[i].bump_scaling);
materialSave(stream, &definition->textures[i].material); materialSave(stream, &definition->layers[i].material);
packWriteDouble(stream, &definition->textures[i].thickness); packWriteDouble(stream, &definition->layers[i].thickness);
packWriteDouble(stream, &definition->textures[i].slope_range); packWriteDouble(stream, &definition->layers[i].slope_range);
packWriteDouble(stream, &definition->textures[i].thickness_transparency); packWriteDouble(stream, &definition->layers[i].thickness_transparency);
} }
} }
@ -55,7 +55,7 @@ void texturesLoad(PackStream* stream, TexturesDefinition* definition)
TextureLayerDefinition* layer; TextureLayerDefinition* layer;
int i, n; int i, n;
while (definition->nbtextures > 0) while (definition->nblayers > 0)
{ {
texturesDeleteLayer(definition, 0); texturesDeleteLayer(definition, 0);
} }
@ -63,16 +63,16 @@ void texturesLoad(PackStream* stream, TexturesDefinition* definition)
packReadInt(stream, &n); packReadInt(stream, &n);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
layer = definition->textures + texturesAddLayer(definition); layer = definition->layers + texturesAddLayer(definition);
zoneLoad(stream, layer->zone); zoneLoad(stream, layer->zone);
noiseLoadGenerator(stream, layer->bump_noise); noiseLoadGenerator(stream, layer->bump_noise);
packReadDouble(stream, &layer->bump_height); packReadDouble(stream, &layer->bump_height);
packReadDouble(stream, &layer->bump_scaling); packReadDouble(stream, &layer->bump_scaling);
materialLoad(stream, &layer->material); materialLoad(stream, &layer->material);
packReadDouble(stream, &definition->textures[i].thickness); packReadDouble(stream, &definition->layers[i].thickness);
packReadDouble(stream, &definition->textures[i].slope_range); packReadDouble(stream, &definition->layers[i].slope_range);
packReadDouble(stream, &definition->textures[i].thickness_transparency); packReadDouble(stream, &definition->layers[i].thickness_transparency);
} }
texturesValidateDefinition(definition); texturesValidateDefinition(definition);
@ -82,14 +82,14 @@ TexturesDefinition texturesCreateDefinition()
{ {
TexturesDefinition result; TexturesDefinition result;
result.nbtextures = 0; result.nblayers = 0;
return result; return result;
} }
void texturesDeleteDefinition(TexturesDefinition* definition) void texturesDeleteDefinition(TexturesDefinition* definition)
{ {
while (definition->nbtextures > 0) while (definition->nblayers > 0)
{ {
texturesDeleteLayer(definition, 0); texturesDeleteLayer(definition, 0);
} }
@ -100,23 +100,23 @@ void texturesCopyDefinition(TexturesDefinition* source, TexturesDefinition* dest
TextureLayerDefinition* layer; TextureLayerDefinition* layer;
int i; int i;
while (destination->nbtextures > 0) while (destination->nblayers > 0)
{ {
texturesDeleteLayer(destination, 0); texturesDeleteLayer(destination, 0);
} }
for (i = 0; i < source->nbtextures; i++) for (i = 0; i < source->nblayers; i++)
{ {
layer = texturesGetLayer(destination, texturesAddLayer(destination)); layer = texturesGetLayer(destination, texturesAddLayer(destination));
texturesLayerCopyDefinition(source->textures + i, layer); texturesLayerCopyDefinition(source->layers + i, layer);
} }
} }
void texturesValidateDefinition(TexturesDefinition* definition) void texturesValidateDefinition(TexturesDefinition* definition)
{ {
int i; int i;
for (i = 0; i < definition->nbtextures; i++) for (i = 0; i < definition->nblayers; i++)
{ {
texturesLayerValidateDefinition(definition->textures + i); texturesLayerValidateDefinition(definition->layers + i);
} }
} }
@ -172,14 +172,14 @@ void texturesLayerValidateDefinition(TextureLayerDefinition* definition)
int texturesGetLayerCount(TexturesDefinition* definition) int texturesGetLayerCount(TexturesDefinition* definition)
{ {
return definition->nbtextures; return definition->nblayers;
} }
TextureLayerDefinition* texturesGetLayer(TexturesDefinition* definition, int layer) TextureLayerDefinition* texturesGetLayer(TexturesDefinition* definition, int layer)
{ {
if (layer >= 0 && layer < definition->nbtextures) if (layer >= 0 && layer < definition->nblayers)
{ {
return definition->textures + layer; return definition->layers + layer;
} }
else else
{ {
@ -189,11 +189,11 @@ TextureLayerDefinition* texturesGetLayer(TexturesDefinition* definition, int lay
int texturesAddLayer(TexturesDefinition* definition) int texturesAddLayer(TexturesDefinition* definition)
{ {
if (definition->nbtextures < TEXTURES_MAX_LAYERS) if (definition->nblayers < TEXTURES_MAX_LAYERS)
{ {
definition->textures[definition->nbtextures] = texturesLayerCreateDefinition(); definition->layers[definition->nblayers] = texturesLayerCreateDefinition();
return definition->nbtextures++; return definition->nblayers++;
} }
else else
{ {
@ -203,14 +203,32 @@ int texturesAddLayer(TexturesDefinition* definition)
void texturesDeleteLayer(TexturesDefinition* definition, int layer) void texturesDeleteLayer(TexturesDefinition* definition, int layer)
{ {
if (layer >= 0 && layer < definition->nbtextures) if (layer >= 0 && layer < definition->nblayers)
{ {
texturesLayerDeleteDefinition(definition->textures + layer); texturesLayerDeleteDefinition(definition->layers + layer);
if (definition->nbtextures > 1 && layer < definition->nbtextures - 1) if (definition->nblayers > 1 && layer < definition->nblayers - 1)
{ {
memmove(definition->textures + layer, definition->textures + layer + 1, sizeof(TextureLayerDefinition) * (definition->nbtextures - layer - 1)); memmove(definition->layers + layer, definition->layers + layer + 1, sizeof(TextureLayerDefinition) * (definition->nblayers - layer - 1));
} }
definition->nbtextures--; definition->nblayers--;
}
}
void texturesMoveLayer(TexturesDefinition* definition, int layer, int new_position)
{
if (layer >= 0 && layer < definition->nblayers && new_position != layer && new_position >= 0 && new_position < definition->nblayers)
{
TextureLayerDefinition temp;
temp = definition->layers[layer];
if (new_position > layer)
{
memmove(definition->layers + layer, definition->layers + layer + 1, sizeof(TextureLayerDefinition) * (new_position - layer));
}
else
{
memmove(definition->layers + new_position, definition->layers + new_position + 1, sizeof(TextureLayerDefinition) * (layer - new_position));
}
definition->layers[new_position] = temp;
} }
} }
@ -360,17 +378,17 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl
results[0] = _getTerrainResult(renderer, x, z, detail); results[0] = _getTerrainResult(renderer, x, z, detail);
for (i = 0; i < definition->nbtextures; i++) for (i = 0; i < definition->nblayers; i++)
{ {
results[i + 1] = _getLayerResult(definition->textures + i, renderer, x, z, detail); results[i + 1] = _getLayerResult(definition->layers + i, renderer, x, z, detail);
} }
qsort(results, definition->nbtextures + 1, sizeof(TextureResult), _cmpResults); qsort(results, definition->nblayers + 1, sizeof(TextureResult), _cmpResults);
/* Pre compute alpha channel */ /* Pre compute alpha channel */
start = 0; start = 0;
last_height = results[0].thickness; last_height = results[0].thickness;
for (i = 1; i <= definition->nbtextures; i++) for (i = 1; i <= definition->nblayers; i++)
{ {
thickness = results[i].thickness - last_height; thickness = results[i].thickness - last_height;
last_height = results[i].thickness; last_height = results[i].thickness;
@ -411,7 +429,7 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl
{ {
result = COLOR_GREEN; result = COLOR_GREEN;
} }
for (i = start; i <= definition->nbtextures; i++) for (i = start; i <= definition->nblayers; i++)
{ {
if (results[i].thickness) if (results[i].thickness)
{ {

View file

@ -27,8 +27,8 @@ typedef struct
typedef struct typedef struct
{ {
int nbtextures; int nblayers;
TextureLayerDefinition textures[TEXTURES_MAX_LAYERS]; TextureLayerDefinition layers[TEXTURES_MAX_LAYERS];
} TexturesDefinition; } TexturesDefinition;
void texturesInit(); void texturesInit();
@ -50,6 +50,7 @@ int texturesGetLayerCount(TexturesDefinition* definition);
TextureLayerDefinition* texturesGetLayer(TexturesDefinition* definition, int layer); TextureLayerDefinition* texturesGetLayer(TexturesDefinition* definition, int layer);
int texturesAddLayer(TexturesDefinition* definition); int texturesAddLayer(TexturesDefinition* definition);
void texturesDeleteLayer(TexturesDefinition* definition, int layer); void texturesDeleteLayer(TexturesDefinition* definition, int layer);
void texturesMoveLayer(TexturesDefinition* definition, int layer, int new_position);
double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail); double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail); Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);