paysages : Added layer naming (WIP).

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@380 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-07-05 17:05:03 +00:00 committed by ThunderK
parent a01c97cda3
commit 3eedaf1366
13 changed files with 101 additions and 15 deletions

View file

@ -13,6 +13,7 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <qt4/QtCore/qvariant.h>
BaseForm::BaseForm(QWidget* parent, bool auto_apply, bool with_layers) : QWidget(parent) BaseForm::BaseForm(QWidget* parent, bool auto_apply, bool with_layers) : QWidget(parent)
{ {
@ -187,6 +188,7 @@ void BaseForm::revertConfig()
if (_with_layers) if (_with_layers)
{ {
rebuildLayerList();
if (_layer_list->currentIndex() < 0 && _layer_list->count() > 0) if (_layer_list->currentIndex() < 0 && _layer_list->count() > 0)
{ {
_layer_list->setCurrentIndex(0); _layer_list->setCurrentIndex(0);
@ -215,9 +217,12 @@ void BaseForm::rebuildLayerList()
int selected = _layer_list->currentIndex(); int selected = _layer_list->currentIndex();
_layer_list->clear(); _layer_list->clear();
_layer_names = getLayers();
_layer_count = _layer_names.count();
for (int i = 0; i < _layer_count; i++) for (int i = 0; i < _layer_count; i++)
{ {
_layer_list->addItem(QString(tr("Layer %1")).arg(i + 1)); _layer_list->addItem(QString(tr("Layer %1 - %2")).arg(i + 1).arg(_layer_names[i]));
} }
if (selected >= 0) if (selected >= 0)
{ {
@ -416,22 +421,24 @@ int BaseForm::currentLayer()
} }
} }
void BaseForm::setLayerCount(int layer_count) QStringList BaseForm::getLayers()
{ {
this->_layer_count = layer_count; return QStringList();
rebuildLayerList();
} }
void BaseForm::layerAddedEvent() void BaseForm::layerAddedEvent()
{ {
rebuildLayerList();
} }
void BaseForm::layerDeletedEvent(int layer) void BaseForm::layerDeletedEvent(int)
{ {
rebuildLayerList();
} }
void BaseForm::layerMovedEvent(int layer, int new_position) void BaseForm::layerMovedEvent(int, int)
{ {
rebuildLayerList();
} }
void BaseForm::layerSelectedEvent(int layer) void BaseForm::layerSelectedEvent(int layer)

View file

@ -4,6 +4,7 @@
#include <QWidget> #include <QWidget>
#include <QPushButton> #include <QPushButton>
#include <QComboBox> #include <QComboBox>
#include <QStringList>
#include "basepreview.h" #include "basepreview.h"
#include "baseinput.h" #include "baseinput.h"
#include "../lib_paysages/shared/types.h" #include "../lib_paysages/shared/types.h"
@ -58,7 +59,7 @@ protected:
void disablePreviewsUpdate(); void disablePreviewsUpdate();
int currentLayer(); int currentLayer();
void setLayerCount(int layer_count); virtual QStringList getLayers();
virtual void layerAddedEvent(); virtual void layerAddedEvent();
virtual void layerDeletedEvent(int layer); virtual void layerDeletedEvent(int layer);
@ -71,6 +72,7 @@ private:
bool _with_layers; bool _with_layers;
QComboBox* _layer_list; QComboBox* _layer_list;
int _layer_count; int _layer_count;
QStringList _layer_names;
QPushButton* _layer_new; QPushButton* _layer_new;
QPushButton* _layer_del; QPushButton* _layer_del;
QPushButton* _layer_up; QPushButton* _layer_up;

View file

@ -175,7 +175,6 @@ FormClouds::FormClouds(QWidget *parent):
void FormClouds::revertConfig() void FormClouds::revertConfig()
{ {
sceneryGetClouds(&_definition); sceneryGetClouds(&_definition);
setLayerCount(cloudsGetLayerCount(&_definition));
BaseForm::revertConfig(); BaseForm::revertConfig();
} }
@ -192,11 +191,26 @@ void FormClouds::configChangeEvent()
BaseForm::configChangeEvent(); BaseForm::configChangeEvent();
} }
QStringList FormClouds::getLayers()
{
QStringList result;
CloudsLayerDefinition* layer;
int i, n;
n = cloudsGetLayerCount(&_definition);
for (i = 0; i < n; i++)
{
layer = cloudsGetLayer(&_definition, i);
result << QString(layer->name);
}
return result;
}
void FormClouds::layerAddedEvent() void FormClouds::layerAddedEvent()
{ {
if (cloudsAddLayer(&_definition) >= 0) if (cloudsAddLayer(&_definition) >= 0)
{ {
setLayerCount(cloudsGetLayerCount(&_definition));
BaseForm::layerAddedEvent(); BaseForm::layerAddedEvent();
} }
} }
@ -204,7 +218,6 @@ void FormClouds::layerAddedEvent()
void FormClouds::layerMovedEvent(int layer, int new_position) void FormClouds::layerMovedEvent(int layer, int new_position)
{ {
cloudsMoveLayer(&_definition, layer, new_position); cloudsMoveLayer(&_definition, layer, new_position);
setLayerCount(cloudsGetLayerCount(&_definition));
BaseForm::layerMovedEvent(layer, new_position); BaseForm::layerMovedEvent(layer, new_position);
} }
@ -212,7 +225,6 @@ void FormClouds::layerMovedEvent(int layer, int new_position)
void FormClouds::layerDeletedEvent(int layer) void FormClouds::layerDeletedEvent(int layer)
{ {
cloudsDeleteLayer(&_definition, layer); cloudsDeleteLayer(&_definition, layer);
setLayerCount(cloudsGetLayerCount(&_definition));
BaseForm::layerDeletedEvent(layer); BaseForm::layerDeletedEvent(layer);
} }

View file

@ -20,6 +20,7 @@ protected slots:
virtual void configChangeEvent(); virtual void configChangeEvent();
protected: protected:
virtual QStringList getLayers();
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 layerMovedEvent(int layer, int new_position);

View file

@ -159,7 +159,6 @@ FormTextures::~FormTextures()
void FormTextures::revertConfig() void FormTextures::revertConfig()
{ {
sceneryGetTextures(&_definition); sceneryGetTextures(&_definition);
setLayerCount(texturesGetLayerCount(&_definition));
BaseForm::revertConfig(); BaseForm::revertConfig();
} }
@ -181,11 +180,26 @@ void FormTextures::configChangeEvent()
BaseForm::configChangeEvent(); BaseForm::configChangeEvent();
} }
QStringList FormTextures::getLayers()
{
QStringList result;
TextureLayerDefinition* layer;
int i, n;
n = texturesGetLayerCount(&_definition);
for (i = 0; i < n; i++)
{
layer = texturesGetLayer(&_definition, i);
result << QString(layer->name);
}
return result;
}
void FormTextures::layerAddedEvent() void FormTextures::layerAddedEvent()
{ {
if (texturesAddLayer(&_definition) >= 0) if (texturesAddLayer(&_definition) >= 0)
{ {
setLayerCount(texturesGetLayerCount(&_definition));
BaseForm::layerAddedEvent(); BaseForm::layerAddedEvent();
} }
} }
@ -193,7 +207,6 @@ void FormTextures::layerAddedEvent()
void FormTextures::layerDeletedEvent(int layer) void FormTextures::layerDeletedEvent(int layer)
{ {
texturesDeleteLayer(&_definition, layer); texturesDeleteLayer(&_definition, layer);
setLayerCount(texturesGetLayerCount(&_definition));
BaseForm::layerDeletedEvent(layer); BaseForm::layerDeletedEvent(layer);
} }
@ -201,7 +214,6 @@ void FormTextures::layerDeletedEvent(int layer)
void FormTextures::layerMovedEvent(int layer, int new_position) void FormTextures::layerMovedEvent(int layer, int new_position)
{ {
texturesMoveLayer(&_definition, layer, new_position); texturesMoveLayer(&_definition, layer, new_position);
setLayerCount(texturesGetLayerCount(&_definition));
BaseForm::layerMovedEvent(layer, new_position); BaseForm::layerMovedEvent(layer, new_position);
} }

View file

@ -14,6 +14,7 @@ public:
~FormTextures(); ~FormTextures();
protected: protected:
virtual QStringList getLayers();
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 layerMovedEvent(int layer, int new_position);

View file

@ -147,6 +147,7 @@ void autoGenRealisticLandscape(int seed)
/* Textures */ /* Textures */
textures = texturesCreateDefinition(); textures = texturesCreateDefinition();
texture = texturesGetLayer(&textures, texturesAddLayer(&textures)); texture = texturesGetLayer(&textures, texturesAddLayer(&textures));
texturesLayerSetName(texture, "Ground");
noiseGenerateBaseNoise(texture->bump_noise, 102400); noiseGenerateBaseNoise(texture->bump_noise, 102400);
noiseClearLevels(texture->bump_noise); noiseClearLevels(texture->bump_noise);
noiseAddLevelsSimple(texture->bump_noise, 8, 1.0, 1.0); noiseAddLevelsSimple(texture->bump_noise, 8, 1.0, 1.0);
@ -161,6 +162,7 @@ void autoGenRealisticLandscape(int seed)
texture->slope_range = 0.001; texture->slope_range = 0.001;
texture->thickness_transparency = 0.0; texture->thickness_transparency = 0.0;
texture = texturesGetLayer(&textures, texturesAddLayer(&textures)); texture = texturesGetLayer(&textures, texturesAddLayer(&textures));
texturesLayerSetName(texture, "Grass");
zoneAddHeightRangeQuick(texture->zone, 1.0, -6.0, -5.0, 3.0, 15.0); zoneAddHeightRangeQuick(texture->zone, 1.0, -6.0, -5.0, 3.0, 15.0);
zoneAddSlopeRangeQuick(texture->zone, 1.0, 0.0, 0.0, 0.05, 0.4); zoneAddSlopeRangeQuick(texture->zone, 1.0, 0.0, 0.0, 0.05, 0.4);
noiseGenerateBaseNoise(texture->bump_noise, 102400); noiseGenerateBaseNoise(texture->bump_noise, 102400);

View file

@ -41,6 +41,7 @@ void cloudsSave(PackStream* stream, CloudsDefinition* definition)
{ {
layer = definition->layers + i; layer = definition->layers + i;
packWriteString(stream, layer->name, CLOUDS_MAX_NAME_LENGTH);
packWriteDouble(stream, &layer->lower_altitude); packWriteDouble(stream, &layer->lower_altitude);
packWriteDouble(stream, &layer->thickness); packWriteDouble(stream, &layer->thickness);
curveSave(stream, layer->coverage_by_altitude); curveSave(stream, layer->coverage_by_altitude);
@ -73,6 +74,7 @@ void cloudsLoad(PackStream* stream, CloudsDefinition* definition)
{ {
layer = definition->layers + cloudsAddLayer(definition); layer = definition->layers + cloudsAddLayer(definition);
packReadString(stream, layer->name, CLOUDS_MAX_NAME_LENGTH);
packReadDouble(stream, &layer->lower_altitude); packReadDouble(stream, &layer->lower_altitude);
packReadDouble(stream, &layer->thickness); packReadDouble(stream, &layer->thickness);
curveLoad(stream, layer->coverage_by_altitude); curveLoad(stream, layer->coverage_by_altitude);
@ -148,6 +150,7 @@ CloudsLayerDefinition cloudsLayerCreateDefinition()
{ {
CloudsLayerDefinition result; CloudsLayerDefinition result;
cloudsLayerSetName(&result, "Unnamed");
result.lower_altitude = 4.0; result.lower_altitude = 4.0;
result.thickness = 6.0; result.thickness = 6.0;
result.coverage_by_altitude = curveCreate(); result.coverage_by_altitude = curveCreate();
@ -210,6 +213,7 @@ void cloudsLayerCopyDefinition(CloudsLayerDefinition* source, CloudsLayerDefinit
void cloudsLayerValidateDefinition(CloudsLayerDefinition* definition) void cloudsLayerValidateDefinition(CloudsLayerDefinition* definition)
{ {
definition->name[CLOUDS_MAX_NAME_LENGTH] = '\0';
if (definition->shape_scaling < 0.0001) if (definition->shape_scaling < 0.0001)
{ {
definition->shape_scaling = 0.00001; definition->shape_scaling = 0.00001;
@ -224,6 +228,11 @@ void cloudsLayerValidateDefinition(CloudsLayerDefinition* definition)
} }
} }
void cloudsLayerSetName(CloudsLayerDefinition* definition, const char* name)
{
strncpy(definition->name, name, CLOUDS_MAX_NAME_LENGTH);
}
int cloudsGetLayerCount(CloudsDefinition* definition) int cloudsGetLayerCount(CloudsDefinition* definition)
{ {
return definition->nblayers; return definition->nblayers;

View file

@ -11,6 +11,7 @@ extern "C" {
#endif #endif
#define CLOUDS_MAX_LAYERS 6 #define CLOUDS_MAX_LAYERS 6
#define CLOUDS_MAX_NAME_LENGTH 50
typedef struct CloudsLayerDefinition CloudsLayerDefinition; typedef struct CloudsLayerDefinition CloudsLayerDefinition;
@ -18,6 +19,7 @@ typedef double (*CloudCoverageFunc)(CloudsLayerDefinition* definition, Vector3 p
struct CloudsLayerDefinition struct CloudsLayerDefinition
{ {
char name[CLOUDS_MAX_NAME_LENGTH + 1];
double lower_altitude; double lower_altitude;
double thickness; double thickness;
double base_coverage; double base_coverage;
@ -55,6 +57,7 @@ CloudsLayerDefinition cloudsLayerCreateDefinition();
void cloudsLayerDeleteDefinition(CloudsLayerDefinition* definition); void cloudsLayerDeleteDefinition(CloudsLayerDefinition* definition);
void cloudsLayerCopyDefinition(CloudsLayerDefinition* source, CloudsLayerDefinition* destination); void cloudsLayerCopyDefinition(CloudsLayerDefinition* source, CloudsLayerDefinition* destination);
void cloudsLayerValidateDefinition(CloudsLayerDefinition* definition); void cloudsLayerValidateDefinition(CloudsLayerDefinition* definition);
void cloudsLayerSetName(CloudsLayerDefinition* definition, const char* name);
int cloudsGetLayerCount(CloudsDefinition* definition); int cloudsGetLayerCount(CloudsDefinition* definition);
CloudsLayerDefinition* cloudsGetLayer(CloudsDefinition* definition, int layer); CloudsLayerDefinition* cloudsGetLayer(CloudsDefinition* definition, int layer);

View file

@ -3,8 +3,10 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include <math.h> #include <math.h>
#include <unistd.h>
#include "color.h" #include "color.h"
#include "euclid.h" #include "euclid.h"
@ -138,3 +140,23 @@ void packReadInt(PackStream* stream, int* value)
read = fscanf(stream->fd, "%d;", value); read = fscanf(stream->fd, "%d;", value);
assert(read == 1); assert(read == 1);
} }
void packWriteString(PackStream* stream, char* value, int max_length)
{
int len = strnlen(value, max_length - 1);
packWriteInt(stream, &len);
fwrite(value, len + 1, 1, stream->fd);
}
void packReadString(PackStream* stream, char* value, int max_length)
{
int read;
int len;
packReadInt(stream, &len);
if (len > max_length - 1)
{
len = max_length - 1;
}
read = fread(value, len + 1, 1, stream->fd);
assert(read == len + 1);
}

View file

@ -15,6 +15,8 @@ void packWriteDouble(PackStream* stream, double* value);
void packReadDouble(PackStream* stream, double* value); void packReadDouble(PackStream* stream, double* value);
void packWriteInt(PackStream* stream, int* value); void packWriteInt(PackStream* stream, int* value);
void packReadInt(PackStream* stream, int* value); void packReadInt(PackStream* stream, int* value);
void packWriteString(PackStream* stream, char* value, int max_length);
void packReadString(PackStream* stream, char* value, int max_length);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -39,6 +39,7 @@ void texturesSave(PackStream* stream, TexturesDefinition* definition)
packWriteInt(stream, &definition->nblayers); packWriteInt(stream, &definition->nblayers);
for (i = 0; i < definition->nblayers; i++) for (i = 0; i < definition->nblayers; i++)
{ {
packWriteString(stream, definition->layers[i].name, TEXTURES_MAX_NAME_LENGTH);
zoneSave(stream, definition->layers[i].zone); zoneSave(stream, definition->layers[i].zone);
noiseSaveGenerator(stream, definition->layers[i].bump_noise); noiseSaveGenerator(stream, definition->layers[i].bump_noise);
packWriteDouble(stream, &definition->layers[i].bump_height); packWriteDouble(stream, &definition->layers[i].bump_height);
@ -65,6 +66,7 @@ void texturesLoad(PackStream* stream, TexturesDefinition* definition)
{ {
layer = definition->layers + texturesAddLayer(definition); layer = definition->layers + texturesAddLayer(definition);
packReadString(stream, layer->name, TEXTURES_MAX_NAME_LENGTH);
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);
@ -124,6 +126,7 @@ TextureLayerDefinition texturesLayerCreateDefinition()
{ {
TextureLayerDefinition result; TextureLayerDefinition result;
texturesLayerSetName(&result, "Unnamed");
result.zone = zoneCreate(); result.zone = zoneCreate();
result.bump_noise = noiseCreateGenerator(); result.bump_noise = noiseCreateGenerator();
noiseGenerateBaseNoise(result.bump_noise, 102400); noiseGenerateBaseNoise(result.bump_noise, 102400);
@ -148,6 +151,7 @@ void texturesLayerDeleteDefinition(TextureLayerDefinition* definition)
void texturesLayerCopyDefinition(TextureLayerDefinition* source, TextureLayerDefinition* destination) void texturesLayerCopyDefinition(TextureLayerDefinition* source, TextureLayerDefinition* destination)
{ {
strncpy(destination->name, source->name, TEXTURES_MAX_NAME_LENGTH);
destination->material = source->material; destination->material = source->material;
destination->bump_height = source->bump_height; destination->bump_height = source->bump_height;
destination->bump_scaling = source->bump_scaling; destination->bump_scaling = source->bump_scaling;
@ -160,6 +164,7 @@ void texturesLayerCopyDefinition(TextureLayerDefinition* source, TextureLayerDef
void texturesLayerValidateDefinition(TextureLayerDefinition* definition) void texturesLayerValidateDefinition(TextureLayerDefinition* definition)
{ {
definition->name[TEXTURES_MAX_NAME_LENGTH] = '\0';
if (definition->bump_scaling < 0.000001) if (definition->bump_scaling < 0.000001)
{ {
definition->bump_scaling = 0.000001; definition->bump_scaling = 0.000001;
@ -170,6 +175,11 @@ void texturesLayerValidateDefinition(TextureLayerDefinition* definition)
} }
} }
void texturesLayerSetName(TextureLayerDefinition* definition, const char* name)
{
strncpy(definition->name, name, TEXTURES_MAX_NAME_LENGTH);
}
int texturesGetLayerCount(TexturesDefinition* definition) int texturesGetLayerCount(TexturesDefinition* definition)
{ {
return definition->nblayers; return definition->nblayers;

View file

@ -12,9 +12,11 @@ extern "C" {
#endif #endif
#define TEXTURES_MAX_LAYERS 50 #define TEXTURES_MAX_LAYERS 50
#define TEXTURES_MAX_NAME_LENGTH 50
typedef struct typedef struct
{ {
char name[TEXTURES_MAX_NAME_LENGTH + 1];
Zone* zone; Zone* zone;
NoiseGenerator* bump_noise; NoiseGenerator* bump_noise;
double bump_scaling; double bump_scaling;
@ -45,6 +47,7 @@ TextureLayerDefinition texturesLayerCreateDefinition();
void texturesLayerDeleteDefinition(TextureLayerDefinition* definition); void texturesLayerDeleteDefinition(TextureLayerDefinition* definition);
void texturesLayerCopyDefinition(TextureLayerDefinition* source, TextureLayerDefinition* destination); void texturesLayerCopyDefinition(TextureLayerDefinition* source, TextureLayerDefinition* destination);
void texturesLayerValidateDefinition(TextureLayerDefinition* definition); void texturesLayerValidateDefinition(TextureLayerDefinition* definition);
void texturesLayerSetName(TextureLayerDefinition* definition, const char* name);
int texturesGetLayerCount(TexturesDefinition* definition); int texturesGetLayerCount(TexturesDefinition* definition);
TextureLayerDefinition* texturesGetLayer(TexturesDefinition* definition, int layer); TextureLayerDefinition* texturesGetLayer(TexturesDefinition* definition, int layer);