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 <QHBoxLayout>
#include <QLabel>
#include <qt4/QtCore/qvariant.h>
BaseForm::BaseForm(QWidget* parent, bool auto_apply, bool with_layers) : QWidget(parent)
{
@ -187,6 +188,7 @@ void BaseForm::revertConfig()
if (_with_layers)
{
rebuildLayerList();
if (_layer_list->currentIndex() < 0 && _layer_list->count() > 0)
{
_layer_list->setCurrentIndex(0);
@ -214,10 +216,13 @@ void BaseForm::rebuildLayerList()
{
int selected = _layer_list->currentIndex();
_layer_list->clear();
_layer_names = getLayers();
_layer_count = _layer_names.count();
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)
{
@ -416,22 +421,24 @@ int BaseForm::currentLayer()
}
}
void BaseForm::setLayerCount(int layer_count)
QStringList BaseForm::getLayers()
{
this->_layer_count = layer_count;
rebuildLayerList();
return QStringList();
}
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)

View file

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

View file

@ -175,7 +175,6 @@ FormClouds::FormClouds(QWidget *parent):
void FormClouds::revertConfig()
{
sceneryGetClouds(&_definition);
setLayerCount(cloudsGetLayerCount(&_definition));
BaseForm::revertConfig();
}
@ -192,11 +191,26 @@ void FormClouds::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()
{
if (cloudsAddLayer(&_definition) >= 0)
{
setLayerCount(cloudsGetLayerCount(&_definition));
BaseForm::layerAddedEvent();
}
}
@ -204,7 +218,6 @@ void FormClouds::layerAddedEvent()
void FormClouds::layerMovedEvent(int layer, int new_position)
{
cloudsMoveLayer(&_definition, layer, new_position);
setLayerCount(cloudsGetLayerCount(&_definition));
BaseForm::layerMovedEvent(layer, new_position);
}
@ -212,7 +225,6 @@ void FormClouds::layerMovedEvent(int layer, int new_position)
void FormClouds::layerDeletedEvent(int layer)
{
cloudsDeleteLayer(&_definition, layer);
setLayerCount(cloudsGetLayerCount(&_definition));
BaseForm::layerDeletedEvent(layer);
}

View file

@ -20,6 +20,7 @@ protected slots:
virtual void configChangeEvent();
protected:
virtual QStringList getLayers();
virtual void layerAddedEvent();
virtual void layerDeletedEvent(int layer);
virtual void layerMovedEvent(int layer, int new_position);

View file

@ -159,7 +159,6 @@ FormTextures::~FormTextures()
void FormTextures::revertConfig()
{
sceneryGetTextures(&_definition);
setLayerCount(texturesGetLayerCount(&_definition));
BaseForm::revertConfig();
}
@ -181,11 +180,26 @@ void FormTextures::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()
{
if (texturesAddLayer(&_definition) >= 0)
{
setLayerCount(texturesGetLayerCount(&_definition));
BaseForm::layerAddedEvent();
}
}
@ -193,7 +207,6 @@ void FormTextures::layerAddedEvent()
void FormTextures::layerDeletedEvent(int layer)
{
texturesDeleteLayer(&_definition, layer);
setLayerCount(texturesGetLayerCount(&_definition));
BaseForm::layerDeletedEvent(layer);
}
@ -201,7 +214,6 @@ void FormTextures::layerDeletedEvent(int layer)
void FormTextures::layerMovedEvent(int layer, int new_position)
{
texturesMoveLayer(&_definition, layer, new_position);
setLayerCount(texturesGetLayerCount(&_definition));
BaseForm::layerMovedEvent(layer, new_position);
}

View file

@ -14,6 +14,7 @@ public:
~FormTextures();
protected:
virtual QStringList getLayers();
virtual void layerAddedEvent();
virtual void layerDeletedEvent(int layer);
virtual void layerMovedEvent(int layer, int new_position);

View file

@ -147,6 +147,7 @@ void autoGenRealisticLandscape(int seed)
/* Textures */
textures = texturesCreateDefinition();
texture = texturesGetLayer(&textures, texturesAddLayer(&textures));
texturesLayerSetName(texture, "Ground");
noiseGenerateBaseNoise(texture->bump_noise, 102400);
noiseClearLevels(texture->bump_noise);
noiseAddLevelsSimple(texture->bump_noise, 8, 1.0, 1.0);
@ -161,6 +162,7 @@ void autoGenRealisticLandscape(int seed)
texture->slope_range = 0.001;
texture->thickness_transparency = 0.0;
texture = texturesGetLayer(&textures, texturesAddLayer(&textures));
texturesLayerSetName(texture, "Grass");
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);
noiseGenerateBaseNoise(texture->bump_noise, 102400);

View file

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

View file

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

View file

@ -3,8 +3,10 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <math.h>
#include <unistd.h>
#include "color.h"
#include "euclid.h"
@ -138,3 +140,23 @@ void packReadInt(PackStream* stream, int* value)
read = fscanf(stream->fd, "%d;", value);
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 packWriteInt(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
}

View file

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

View file

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