paysages : Textures are now on the new layers system.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@419 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-08-26 13:06:42 +00:00 committed by ThunderK
parent 623fbaa2e3
commit a98185c5e1
11 changed files with 212 additions and 329 deletions

3
TODO
View file

@ -13,7 +13,8 @@ Technology Preview 2 :
- Improve terrain canvas editor.
=> Add GeoArea editor.
=> Resample map on changing resolution.
=> Map loading should not choose arbitrary resolution.
=> GeoAreas should not overlap.
=> Map loading should not choose arbitrary resolution, choose the closer one and resample.
- Improve textures (current model is greatly incorrect).
=> Separate models (basic texture and covering texture).
=> Covering texture height should inpact terrain height.

View file

@ -4,38 +4,65 @@
BaseFormLayer::BaseFormLayer(QWidget* parent, Layers* layers) : BaseForm(parent, false, true)
{
_layers_original = layers;
_layers_modified = layersCreateCopy(_layers_original);
_layers_original = NULL;
_layers_modified = NULL;
if (layers)
{
setLayers(layers);
}
}
BaseFormLayer::~BaseFormLayer()
{
if (_layers_modified)
{
layersDelete(_layers_modified);
}
}
void BaseFormLayer::revertConfig()
{
if (_layers_original && _layers_modified)
{
layersCopy(_layers_original, _layers_modified);
layerSelectedEvent(currentLayer());
}
BaseForm::revertConfig();
}
void BaseFormLayer::applyConfig()
{
if (_layers_original && _layers_modified)
{
layersCopy(_layers_modified, _layers_original);
}
BaseForm::applyConfig();
}
void BaseFormLayer::setLayers(Layers* layers)
{
_layers_original = layers;
if (_layers_modified)
{
layersDelete(_layers_modified);
}
_layers_modified = layersCreateCopy(_layers_original);
revertConfig();
}
void BaseFormLayer::afterLayerAdded(void*)
{
}
void BaseFormLayer::configChangeEvent()
{
if (_layers_modified)
{
layerApply(layersGetLayer(_layers_modified, currentLayer()));
layersValidate(_layers_modified);
}
BaseForm::configChangeEvent();
}
@ -44,15 +71,20 @@ QStringList BaseFormLayer::getLayers()
{
QStringList result;
if (_layers_modified)
{
for (int i = 0; i < layersCount(_layers_modified); i++)
{
result << QString::fromUtf8(layersGetName(_layers_modified, i));
}
}
return result;
}
void BaseFormLayer::layerAddedEvent()
{
if (_layers_modified)
{
QString layer_name = QInputDialog::getText(this, tr("Create layer"), tr("Layer name :"), QLineEdit::Normal, tr("Unnamed layer"));
if (not layer_name.isEmpty())
@ -68,31 +100,44 @@ void BaseFormLayer::layerAddedEvent()
}
}
}
}
void BaseFormLayer::layerDeletedEvent(int layer)
{
if (_layers_modified)
{
layersDeleteLayer(_layers_modified, layer);
}
BaseForm::layerDeletedEvent(layer);
}
void BaseFormLayer::layerMovedEvent(int layer, int new_position)
{
if (_layers_modified)
{
layersMove(_layers_modified, layer, new_position);
}
BaseForm::layerMovedEvent(layer, new_position);
}
void BaseFormLayer::layerRenamedEvent(int layer, QString new_name)
{
if (_layers_modified)
{
layersSetName(_layers_modified, layer, new_name.toUtf8().data());
}
BaseForm::layerRenamedEvent(layer, new_name);
}
void BaseFormLayer::layerSelectedEvent(int layer)
{
if (_layers_modified)
{
layerGetCopy(layersGetLayer(_layers_modified, layer));
}
BaseForm::layerSelectedEvent(layer);
}

View file

@ -11,7 +11,7 @@ class BaseFormLayer:public BaseForm
Q_OBJECT
public:
BaseFormLayer(QWidget* parent, Layers* layers);
BaseFormLayer(QWidget* parent, Layers* layers=NULL);
~BaseFormLayer();
public slots:
@ -19,6 +19,7 @@ public slots:
virtual void applyConfig();
protected:
void setLayers(Layers* layers);
virtual void layerGetCopy(void* layer_definition) = 0;
virtual void layerApply(void* layer_definition) = 0;
virtual void afterLayerAdded(void* layer_definition);

View file

@ -85,8 +85,7 @@ public:
_terrain = terrainCreateDefinition();
_textures = texturesCreateDefinition();
texturesAddLayer(&_textures);
texture = texturesGetLayer(&_textures, 0);
texture = (TextureLayerDefinition*)layersGetLayer(_textures.layers, layersAddLayer(_textures.layers, NULL));
texture->material.base = COLOR_WHITE;
texture->material.reflection = 0.3;
texture->material.shininess = 2.0;

View file

@ -4,9 +4,6 @@
#include "../lib_paysages/scenery.h"
#include "tools.h"
static TexturesDefinition _definition;
static TextureLayerDefinition _layer;
typedef struct
{
Curve* height_curve;
@ -18,7 +15,7 @@ static TextureSupp _supp;
class PreviewTexturesCoverage:public BasePreview
{
public:
PreviewTexturesCoverage(QWidget* parent):BasePreview(parent)
PreviewTexturesCoverage(QWidget* parent, TextureLayerDefinition* layer):BasePreview(parent)
{
_terrain = terrainCreateDefinition();
@ -27,6 +24,7 @@ public:
_renderer.getTerrainHeight = _getTerrainHeight;
_renderer.customData[0] = &_terrain;
_original_layer = layer;
_preview_layer = texturesLayerCreateDefinition();
addOsd(QString("geolocation"));
@ -34,6 +32,10 @@ public:
configScaling(0.5, 200.0, 1.0, 50.0);
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
~PreviewTexturesCoverage()
{
texturesLayerDeleteDefinition(_preview_layer);
}
protected:
QColor getColor(double x, double y)
{
@ -42,13 +44,13 @@ protected:
location.x = x;
location.y = terrainGetHeight(&_terrain, x, y);
location.z = y;
coverage = texturesGetLayerCoverage(&_preview_layer, &_renderer, location, this->scaling);
coverage = texturesGetLayerCoverage(_preview_layer, &_renderer, location, this->scaling);
return QColor::fromRgbF(coverage, coverage, coverage, 1.0);
}
void updateData()
{
sceneryGetTerrain(&_terrain);
texturesLayerCopyDefinition(&_layer, &_preview_layer);
texturesLayerCopyDefinition(_original_layer, _preview_layer);
}
private:
@ -58,17 +60,19 @@ private:
}
Renderer _renderer;
TextureLayerDefinition _preview_layer;
TextureLayerDefinition* _original_layer;
TextureLayerDefinition* _preview_layer;
TerrainDefinition _terrain;
};
class PreviewTexturesColor:public BasePreview
{
public:
PreviewTexturesColor(QWidget* parent):BasePreview(parent)
PreviewTexturesColor(QWidget* parent, TextureLayerDefinition* layer):BasePreview(parent)
{
LightDefinition light;
_original_layer = layer;
_preview_layer = texturesLayerCreateDefinition();
_lighting = lightingCreateDefinition();
@ -95,6 +99,10 @@ public:
configScaling(0.01, 1.0, 0.01, 0.1);
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
~PreviewTexturesColor()
{
texturesLayerDeleteDefinition(_preview_layer);
}
protected:
QColor getColor(double x, double y)
{
@ -102,17 +110,18 @@ protected:
location.x = x;
location.y = 0.0;
location.z = y;
return colorToQColor(texturesGetLayerColor(&_preview_layer, &_renderer, location, this->scaling));
return colorToQColor(texturesGetLayerColor(_preview_layer, &_renderer, location, this->scaling));
}
void updateData()
{
texturesLayerCopyDefinition(&_layer, &_preview_layer);
zoneCopy(_zone, _preview_layer.zone);
texturesLayerCopyDefinition(_original_layer, _preview_layer);
zoneCopy(_zone, _preview_layer->zone);
}
private:
Zone* _zone;
Renderer _renderer;
TextureLayerDefinition _preview_layer;
TextureLayerDefinition* _original_layer;
TextureLayerDefinition* _preview_layer;
LightingDefinition _lighting;
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
@ -123,35 +132,35 @@ private:
/**************** Form ****************/
FormTextures::FormTextures(QWidget *parent):
BaseForm(parent, false, true)
BaseFormLayer(parent)
{
_definition = texturesCreateDefinition();
_layer = texturesLayerCreateDefinition();
_supp.height_curve = curveCreate();
_supp.slope_curve = curveCreate();
previewCoverage = new PreviewTexturesCoverage(this);
previewColor = new PreviewTexturesColor(this);
previewCoverage = new PreviewTexturesCoverage(this, _layer);
previewColor = new PreviewTexturesColor(this, _layer);
addPreview(previewCoverage, tr("Coverage preview"));
addPreview(previewColor, tr("Lighted sample"));
addInputNoise(tr("Surface noise"), _layer.bump_noise);
addInputDouble(tr("Surface noise height"), &_layer.bump_height, 0.0, 0.1, 0.001, 0.01);
addInputDouble(tr("Surface noise scaling"), &_layer.bump_scaling, 0.001, 0.1, 0.001, 0.01);
addInputMaterial(tr("Material"), &_layer.material);
addInputNoise(tr("Surface noise"), _layer->bump_noise);
addInputDouble(tr("Surface noise height"), &_layer->bump_height, 0.0, 0.1, 0.001, 0.01);
addInputDouble(tr("Surface noise scaling"), &_layer->bump_scaling, 0.001, 0.1, 0.001, 0.01);
addInputMaterial(tr("Material"), &_layer->material);
addInputCurve(tr("Coverage by altitude"), _supp.height_curve, -20.0, 20.0, 0.0, 1.0, tr("Terrain altitude"), tr("Texture coverage"));
addInputCurve(tr("Coverage by slope"), _supp.slope_curve, 0.0, 5.0, 0.0, 1.0, tr("Terrain slope"), tr("Texture coverage"));
addInputDouble(tr("Amplitude for slope coverage"), &_layer.slope_range, 0.001, 0.1, 0.001, 0.01);
addInputDouble(tr("Layer thickness"), &_layer.thickness, 0.0, 0.1, 0.001, 0.01);
addInputDouble(tr("Transparency thickness"), &_layer.thickness_transparency, 0.0, 0.1, 0.001, 0.01);
addInputDouble(tr("Amplitude for slope coverage"), &_layer->slope_range, 0.001, 0.1, 0.001, 0.01);
addInputDouble(tr("Layer thickness"), &_layer->thickness, 0.0, 0.1, 0.001, 0.01);
addInputDouble(tr("Transparency thickness"), &_layer->thickness_transparency, 0.0, 0.1, 0.001, 0.01);
revertConfig();
setLayers(_definition.layers);
}
FormTextures::~FormTextures()
{
texturesDeleteDefinition(&_definition);
texturesLayerDeleteDefinition(&_layer);
texturesLayerDeleteDefinition(_layer);
curveDelete(_supp.height_curve);
curveDelete(_supp.slope_curve);
}
@ -159,81 +168,21 @@ FormTextures::~FormTextures()
void FormTextures::revertConfig()
{
sceneryGetTextures(&_definition);
BaseForm::revertConfig();
BaseFormLayer::revertConfig();
}
void FormTextures::applyConfig()
{
configChangeEvent();
BaseFormLayer::applyConfig();
scenerySetTextures(&_definition);
BaseForm::applyConfig();
}
void FormTextures::configChangeEvent()
void FormTextures::layerGetCopy(void* layer_definition)
{
texturesLayerCopyDefinition(&_layer, texturesGetLayer(&_definition, currentLayer()));
zoneSetHeightCurve(_layer.zone, _supp.height_curve);
zoneSetSlopeCurve(_layer.zone, _supp.slope_curve);
texturesValidateDefinition(&_definition);
BaseForm::configChangeEvent();
texturesLayerCopyDefinition((TextureLayerDefinition*)layer_definition, _layer);
}
QStringList FormTextures::getLayers()
void FormTextures::layerApply(void* layer_definition)
{
QStringList result;
TextureLayerDefinition* layer;
int i, n;
n = texturesGetLayerCount(&_definition);
for (i = 0; i < n; i++)
{
layer = texturesGetLayer(&_definition, i);
result << QString::fromUtf8(layer->name);
}
return result;
}
void FormTextures::layerAddedEvent()
{
if (texturesAddLayer(&_definition) >= 0)
{
BaseForm::layerAddedEvent();
}
}
void FormTextures::layerDeletedEvent(int layer)
{
texturesDeleteLayer(&_definition, layer);
BaseForm::layerDeletedEvent(layer);
}
void FormTextures::layerMovedEvent(int layer, int new_position)
{
texturesMoveLayer(&_definition, layer, new_position);
BaseForm::layerMovedEvent(layer, new_position);
}
void FormTextures::layerRenamedEvent(int layer, QString new_name)
{
TextureLayerDefinition* layer_def;
layer_def = texturesGetLayer(&_definition, layer);
texturesLayerSetName(layer_def, new_name.toUtf8().data());
BaseForm::layerRenamedEvent(layer, new_name);
}
void FormTextures::layerSelectedEvent(int layer)
{
texturesLayerCopyDefinition(texturesGetLayer(&_definition, layer), &_layer);
zoneGetHeightCurve(_layer.zone, _supp.height_curve);
zoneGetSlopeCurve(_layer.zone, _supp.slope_curve);
BaseForm::layerSelectedEvent(layer);
texturesLayerCopyDefinition(_layer, (TextureLayerDefinition*)layer_definition);
}

View file

@ -3,9 +3,10 @@
#include <QWidget>
#include "basepreview.h"
#include "baseform.h"
#include "baseformlayer.h"
#include "../lib_paysages/textures.h"
class FormTextures : public BaseForm
class FormTextures : public BaseFormLayer
{
Q_OBJECT
@ -13,22 +14,17 @@ public:
explicit FormTextures(QWidget *parent = 0);
~FormTextures();
protected:
virtual QStringList getLayers();
virtual void layerAddedEvent();
virtual void layerDeletedEvent(int layer);
virtual void layerMovedEvent(int layer, int new_position);
virtual void layerRenamedEvent(int layer, QString new_name);
virtual void layerSelectedEvent(int layer);
public slots:
virtual void revertConfig();
virtual void applyConfig();
protected slots:
virtual void configChangeEvent();
protected:
virtual void layerGetCopy(void* layer_definition);
virtual void layerApply(void* layer_definition);
private:
TexturesDefinition _definition;
TextureLayerDefinition* _layer;
BasePreview* previewCoverage;
BasePreview* previewColor;
};

View file

@ -80,37 +80,37 @@ QMainWindow(parent)
form = new FormTerrain(tabs);
tabs->addTab(form, tr("Terrain"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);
form = new FormTextures(tabs);
tabs->addTab(form, tr("Textures"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);
form = new FormWater(tabs);
tabs->addTab(form, tr("Water"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);
form = new FormSky(tabs);
tabs->addTab(form, tr("Sky"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);
form = new FormAtmosphere(tabs);
tabs->addTab(form, tr("Atmosphere"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);
form = new FormClouds(tabs);
tabs->addTab(form, tr("Clouds"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);
/*form = new FormLighting(tabs);
tabs->addTab(form, tr("Lighting"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);*/
_form_render = new FormRender(tabs);

View file

@ -64,6 +64,7 @@ void autoGenRealisticLandscape(int seed)
SkyDefinition sky;
TexturesDefinition textures;
TextureLayerDefinition* texture;
int layer;
if (!seed)
{
@ -146,8 +147,9 @@ void autoGenRealisticLandscape(int seed)
/* Textures */
textures = texturesCreateDefinition();
texture = texturesGetLayer(&textures, texturesAddLayer(&textures));
texturesLayerSetName(texture, "Ground");
layer = layersAddLayer(textures.layers, NULL);
layersSetName(textures.layers, layer, "Ground");
texture = layersGetLayer(textures.layers, layer);
noiseGenerateBaseNoise(texture->bump_noise, 102400);
noiseClearLevels(texture->bump_noise);
noiseAddLevelsSimple(texture->bump_noise, 8, 1.0, 1.0);
@ -161,8 +163,9 @@ void autoGenRealisticLandscape(int seed)
texture->thickness = 0.001;
texture->slope_range = 0.001;
texture->thickness_transparency = 0.0;
texture = texturesGetLayer(&textures, texturesAddLayer(&textures));
texturesLayerSetName(texture, "Grass");
layer = layersAddLayer(textures.layers, NULL);
layersSetName(textures.layers, layer, "Grass");
texture = layersGetLayer(textures.layers, layer);
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

@ -26,7 +26,6 @@ void sceneryInit()
noiseInit();
cloudsInit();
lightingInit();
texturesInit();
_atmosphere = atmosphereCreateDefinition();
_camera = cameraCreateDefinition();
@ -56,7 +55,6 @@ void sceneryQuit()
cloudsQuit();
lightingQuit();
texturesQuit();
noiseQuit();
}

View file

@ -12,7 +12,7 @@
#include "terrain.h"
#include "tools.h"
static TextureLayerDefinition _NULL_LAYER;
#define TEXTURES_MAX_LAYERS 50
typedef struct
{
@ -22,27 +22,8 @@ typedef struct
TextureLayerDefinition* definition;
} TextureResult;
void texturesInit()
static void texturesLayerSave(PackStream* stream, TextureLayerDefinition* layer)
{
_NULL_LAYER = texturesLayerCreateDefinition();
}
void texturesQuit()
{
texturesLayerDeleteDefinition(&_NULL_LAYER);
}
void texturesSave(PackStream* stream, TexturesDefinition* definition)
{
TextureLayerDefinition* layer;
int i;
packWriteInt(stream, &definition->nblayers);
for (i = 0; i < definition->nblayers; i++)
{
layer = definition->layers + i;
packWriteString(stream, layer->name, TEXTURES_MAX_NAME_LENGTH);
zoneSave(stream, layer->zone);
noiseSaveGenerator(stream, layer->bump_noise);
packWriteDouble(stream, &layer->bump_height);
@ -52,24 +33,9 @@ void texturesSave(PackStream* stream, TexturesDefinition* definition)
packWriteDouble(stream, &layer->slope_range);
packWriteDouble(stream, &layer->thickness_transparency);
}
}
void texturesLoad(PackStream* stream, TexturesDefinition* definition)
static void texturesLayerLoad(PackStream* stream, TextureLayerDefinition* layer)
{
TextureLayerDefinition* layer;
int i, n;
while (definition->nblayers > 0)
{
texturesDeleteLayer(definition, 0);
}
packReadInt(stream, &n);
for (i = 0; i < n; i++)
{
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);
@ -80,68 +46,72 @@ void texturesLoad(PackStream* stream, TexturesDefinition* definition)
packReadDouble(stream, &layer->thickness_transparency);
}
texturesValidateDefinition(definition);
}
TexturesDefinition texturesCreateDefinition()
{
TexturesDefinition result;
result.nblayers = 0;
result.layers = layersCreate(texturesGetLayerType(), TEXTURES_MAX_LAYERS);
return result;
}
void texturesDeleteDefinition(TexturesDefinition* definition)
{
while (definition->nblayers > 0)
{
texturesDeleteLayer(definition, 0);
}
layersDelete(definition->layers);
}
void texturesCopyDefinition(TexturesDefinition* source, TexturesDefinition* destination)
{
TextureLayerDefinition* layer;
int i;
while (destination->nblayers > 0)
{
texturesDeleteLayer(destination, 0);
}
for (i = 0; i < source->nblayers; i++)
{
layer = texturesGetLayer(destination, texturesAddLayer(destination));
texturesLayerCopyDefinition(source->layers + i, layer);
}
layersCopy(source->layers, destination->layers);
}
void texturesValidateDefinition(TexturesDefinition* definition)
{
int i;
for (i = 0; i < definition->nblayers; i++)
{
texturesLayerValidateDefinition(definition->layers + i);
}
layersValidate(definition->layers);
}
TextureLayerDefinition texturesLayerCreateDefinition()
void texturesSave(PackStream* stream, TexturesDefinition* definition)
{
TextureLayerDefinition result;
layersSave(stream, definition->layers);
}
texturesLayerSetName(&result, "Unnamed");
result.zone = zoneCreate();
result.bump_noise = noiseCreateGenerator();
noiseGenerateBaseNoise(result.bump_noise, 102400);
noiseAddLevelsSimple(result.bump_noise, 8, 1.0, 1.0);
result.bump_height = 0.1;
result.bump_scaling = 0.1;
result.material.base = COLOR_WHITE;
result.material.reflection = 0.0;
result.material.shininess = 0.0;
result.thickness = 0.0;
result.slope_range = 0.001;
result.thickness_transparency = 0.0;
void texturesLoad(PackStream* stream, TexturesDefinition* definition)
{
layersLoad(stream, definition->layers);
}
LayerType texturesGetLayerType()
{
LayerType result;
result.callback_create = (LayerCallbackCreate)texturesLayerCreateDefinition;
result.callback_delete = (LayerCallbackDelete)texturesLayerDeleteDefinition;
result.callback_copy = (LayerCallbackCopy)texturesLayerCopyDefinition;
result.callback_validate = (LayerCallbackValidate)texturesLayerValidateDefinition;
result.callback_save = (LayerCallbackSave)texturesLayerSave;
result.callback_load = (LayerCallbackLoad)texturesLayerLoad;
return result;
}
TextureLayerDefinition* texturesLayerCreateDefinition()
{
TextureLayerDefinition* result;
result = malloc(sizeof(TextureLayerDefinition));
result->zone = zoneCreate();
result->bump_noise = noiseCreateGenerator();
noiseGenerateBaseNoise(result->bump_noise, 102400);
noiseAddLevelsSimple(result->bump_noise, 8, 1.0, 1.0);
result->bump_height = 0.1;
result->bump_scaling = 0.1;
result->material.base = COLOR_WHITE;
result->material.reflection = 0.0;
result->material.shininess = 0.0;
result->thickness = 0.0;
result->slope_range = 0.001;
result->thickness_transparency = 0.0;
return result;
}
@ -150,11 +120,11 @@ void texturesLayerDeleteDefinition(TextureLayerDefinition* definition)
{
zoneDelete(definition->zone);
noiseDeleteGenerator(definition->bump_noise);
free(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;
@ -167,7 +137,6 @@ 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;
@ -178,73 +147,6 @@ 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;
}
TextureLayerDefinition* texturesGetLayer(TexturesDefinition* definition, int layer)
{
if (layer >= 0 && layer < definition->nblayers)
{
return definition->layers + layer;
}
else
{
return &_NULL_LAYER;
}
}
int texturesAddLayer(TexturesDefinition* definition)
{
if (definition->nblayers < TEXTURES_MAX_LAYERS)
{
definition->layers[definition->nblayers] = texturesLayerCreateDefinition();
return definition->nblayers++;
}
else
{
return -1;
}
}
void texturesDeleteLayer(TexturesDefinition* definition, int layer)
{
if (layer >= 0 && layer < definition->nblayers)
{
texturesLayerDeleteDefinition(definition->layers + layer);
if (definition->nblayers > 1 && layer < definition->nblayers - 1)
{
memmove(definition->layers + layer, definition->layers + layer + 1, sizeof(TextureLayerDefinition) * (definition->nblayers - layer - 1));
}
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 + 1, definition->layers + new_position, sizeof(TextureLayerDefinition) * (layer - new_position));
}
definition->layers[new_position] = temp;
}
}
static inline Vector3 _getNormal4(Vector3 center, Vector3 north, Vector3 east, Vector3 south, Vector3 west)
{
Vector3 dnorth, deast, dsouth, dwest, normal;
@ -385,24 +287,25 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl
TextureResult results[TEXTURES_MAX_LAYERS + 1];
Color result, color;
double thickness, last_height;
int i, start;
int i, start, nblayers;
detail *= 0.1;
results[0] = _getTerrainResult(renderer, x, z, detail);
for (i = 0; i < definition->nblayers; i++)
nblayers = layersCount(definition->layers);
for (i = 0; i < nblayers; i++)
{
results[i + 1] = _getLayerResult(definition->layers + i, renderer, x, z, detail);
results[i + 1] = _getLayerResult(layersGetLayer(definition->layers, i), renderer, x, z, detail);
}
qsort(results, definition->nblayers + 1, sizeof(TextureResult), _cmpResults);
qsort(results, nblayers + 1, sizeof(TextureResult), _cmpResults);
/* Pre compute alpha channel */
start = 0;
last_height = results[0].thickness;
results[0].thickness = 1.0;
for (i = 1; i <= definition->nblayers; i++)
for (i = 1; i <= nblayers; i++)
{
thickness = results[i].thickness - last_height;
last_height = results[i].thickness;
@ -440,7 +343,7 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl
{
result = COLOR_GREEN;
}
for (i = start + 1; i <= definition->nblayers; i++)
for (i = start + 1; i <= nblayers; i++)
{
if (results[i].thickness)
{

View file

@ -2,6 +2,7 @@
#define _PAYSAGES_TEXTURES_H_
#include "shared/types.h"
#include "layers.h"
#include "noise.h"
#include "lighting.h"
#include "pack.h"
@ -11,12 +12,8 @@
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;
@ -29,31 +26,22 @@ typedef struct
typedef struct
{
int nblayers;
TextureLayerDefinition layers[TEXTURES_MAX_LAYERS];
Layers* layers;
} TexturesDefinition;
void texturesInit();
void texturesQuit();
void texturesSave(PackStream* stream, TexturesDefinition* definition);
void texturesLoad(PackStream* stream, TexturesDefinition* definition);
TexturesDefinition texturesCreateDefinition();
void texturesDeleteDefinition(TexturesDefinition* definition);
void texturesCopyDefinition(TexturesDefinition* source, TexturesDefinition* destination);
void texturesValidateDefinition(TexturesDefinition* definition);
TextureLayerDefinition texturesLayerCreateDefinition();
void texturesSave(PackStream* stream, TexturesDefinition* definition);
void texturesLoad(PackStream* stream, TexturesDefinition* definition);
LayerType texturesGetLayerType();
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);
int texturesAddLayer(TexturesDefinition* definition);
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);
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);