2013-03-31 20:27:21 +00:00
|
|
|
#include "private.h"
|
2013-09-27 21:28:06 +00:00
|
|
|
#include "scenery.h"
|
2013-03-31 20:27:21 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
/******************** Global definition ********************/
|
|
|
|
static void _validateDefinition(TexturesDefinition* definition)
|
|
|
|
{
|
|
|
|
layersValidate(definition->layers);
|
|
|
|
}
|
|
|
|
|
|
|
|
static TexturesDefinition* _createDefinition()
|
|
|
|
{
|
|
|
|
TexturesDefinition* definition = malloc(sizeof(TexturesDefinition));
|
|
|
|
|
|
|
|
definition->layers = layersCreate(texturesGetLayerType(), TEXTURES_MAX_LAYERS);
|
|
|
|
|
|
|
|
return definition;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _deleteDefinition(TexturesDefinition* definition)
|
|
|
|
{
|
|
|
|
layersDelete(definition->layers);
|
|
|
|
free(definition);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _copyDefinition(TexturesDefinition* source, TexturesDefinition* destination)
|
|
|
|
{
|
|
|
|
layersCopy(source->layers, destination->layers);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _saveDefinition(PackStream* stream, TexturesDefinition* definition)
|
|
|
|
{
|
|
|
|
layersSave(stream, definition->layers);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _loadDefinition(PackStream* stream, TexturesDefinition* definition)
|
|
|
|
{
|
|
|
|
layersLoad(stream, definition->layers);
|
|
|
|
}
|
|
|
|
|
|
|
|
StandardDefinition TexturesDefinitionClass = {
|
|
|
|
(FuncObjectCreate)_createDefinition,
|
|
|
|
(FuncObjectDelete)_deleteDefinition,
|
|
|
|
(FuncObjectCopy)_copyDefinition,
|
|
|
|
(FuncObjectValidate)_validateDefinition,
|
|
|
|
(FuncObjectSave)_saveDefinition,
|
|
|
|
(FuncObjectLoad)_loadDefinition
|
|
|
|
};
|
|
|
|
|
|
|
|
/*** Layer definition ***/
|
|
|
|
|
|
|
|
static void _layerValidateDefinition(TexturesLayerDefinition* definition)
|
|
|
|
{
|
|
|
|
if (definition->displacement_scaling < 0.000001)
|
|
|
|
{
|
|
|
|
definition->displacement_scaling = 0.000001;
|
|
|
|
}
|
|
|
|
|
|
|
|
noiseClearLevels(definition->_displacement_noise);
|
2013-06-11 21:31:44 +00:00
|
|
|
noiseAddLevelsSimple(definition->_displacement_noise, 9, 1.0, -1.0, 1.0, 0.0);
|
2013-04-04 20:44:49 +00:00
|
|
|
noiseNormalizeAmplitude(definition->_displacement_noise, -1.0, 1.0, 0);
|
2013-03-31 20:27:21 +00:00
|
|
|
noiseValidate(definition->_displacement_noise);
|
2013-04-11 14:38:40 +00:00
|
|
|
|
|
|
|
noiseClearLevels(definition->_detail_noise);
|
2013-06-11 21:31:44 +00:00
|
|
|
noiseAddLevelsSimple(definition->_detail_noise, 7, 0.01, -1.0, 1.0, 0.0);
|
|
|
|
noiseNormalizeAmplitude(definition->_detail_noise, -0.008, 0.008, 0);
|
2013-04-11 14:38:40 +00:00
|
|
|
noiseValidate(definition->_detail_noise);
|
2013-09-18 15:10:34 +00:00
|
|
|
|
|
|
|
materialValidate(&definition->material);
|
2013-09-27 21:28:06 +00:00
|
|
|
|
|
|
|
/* Update zone height range */
|
|
|
|
TerrainDefinition* terrain = sceneryGetTerrainDirect();
|
|
|
|
HeightInfo height_info = terrainGetHeightInfo(terrain);
|
|
|
|
zoneSetRelativeHeight(definition->terrain_zone, height_info.min_height, height_info.base_height, height_info.max_height);
|
2013-03-31 20:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static TexturesLayerDefinition* _layerCreateDefinition()
|
|
|
|
{
|
|
|
|
TexturesLayerDefinition* result;
|
|
|
|
|
|
|
|
result = malloc(sizeof(TexturesLayerDefinition));
|
|
|
|
|
|
|
|
result->terrain_zone = zoneCreate();
|
|
|
|
result->_displacement_noise = noiseCreateGenerator();
|
2013-04-11 14:38:40 +00:00
|
|
|
result->_detail_noise = noiseCreateGenerator();
|
2013-03-31 20:27:21 +00:00
|
|
|
|
2013-04-12 20:11:29 +00:00
|
|
|
texturesLayerAutoPreset(result, TEXTURES_LAYER_PRESET_ROCK);
|
|
|
|
|
2013-04-03 20:37:29 +00:00
|
|
|
_layerValidateDefinition(result);
|
|
|
|
|
2013-03-31 20:27:21 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _layerDeleteDefinition(TexturesLayerDefinition* definition)
|
|
|
|
{
|
|
|
|
zoneDelete(definition->terrain_zone);
|
|
|
|
noiseDeleteGenerator(definition->_displacement_noise);
|
2013-04-11 14:38:40 +00:00
|
|
|
noiseDeleteGenerator(definition->_detail_noise);
|
2013-03-31 20:27:21 +00:00
|
|
|
free(definition);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _layerCopyDefinition(TexturesLayerDefinition* source, TexturesLayerDefinition* destination)
|
|
|
|
{
|
|
|
|
zoneCopy(source->terrain_zone, destination->terrain_zone);
|
|
|
|
destination->displacement_scaling = source->displacement_scaling;
|
|
|
|
destination->displacement_height = source->displacement_height;
|
|
|
|
destination->displacement_offset = source->displacement_offset;
|
|
|
|
destination->material = source->material;
|
|
|
|
|
|
|
|
noiseCopy(source->_displacement_noise, destination->_displacement_noise);
|
2013-04-11 14:38:40 +00:00
|
|
|
noiseCopy(source->_detail_noise, destination->_detail_noise);
|
2013-03-31 20:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void _layerSave(PackStream* stream, TexturesLayerDefinition* layer)
|
|
|
|
{
|
|
|
|
zoneSave(stream, layer->terrain_zone);
|
|
|
|
packWriteDouble(stream, &layer->displacement_scaling);
|
|
|
|
packWriteDouble(stream, &layer->displacement_height);
|
|
|
|
packWriteDouble(stream, &layer->displacement_offset);
|
|
|
|
materialSave(stream, &layer->material);
|
|
|
|
|
|
|
|
noiseSaveGenerator(stream, layer->_displacement_noise);
|
2013-04-11 14:38:40 +00:00
|
|
|
noiseSaveGenerator(stream, layer->_detail_noise);
|
2013-03-31 20:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void _layerLoad(PackStream* stream, TexturesLayerDefinition* layer)
|
|
|
|
{
|
|
|
|
zoneLoad(stream, layer->terrain_zone);
|
|
|
|
packReadDouble(stream, &layer->displacement_scaling);
|
|
|
|
packReadDouble(stream, &layer->displacement_height);
|
|
|
|
packReadDouble(stream, &layer->displacement_offset);
|
|
|
|
materialLoad(stream, &layer->material);
|
|
|
|
|
|
|
|
noiseLoadGenerator(stream, layer->_displacement_noise);
|
2013-04-11 14:38:40 +00:00
|
|
|
noiseLoadGenerator(stream, layer->_detail_noise);
|
2013-03-31 20:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LayerType texturesGetLayerType()
|
|
|
|
{
|
|
|
|
LayerType result;
|
|
|
|
|
|
|
|
result.callback_create = (LayerCallbackCreate)_layerCreateDefinition;
|
|
|
|
result.callback_delete = (LayerCallbackDelete)_layerDeleteDefinition;
|
|
|
|
result.callback_copy = (LayerCallbackCopy)_layerCopyDefinition;
|
|
|
|
result.callback_validate = (LayerCallbackValidate)_layerValidateDefinition;
|
|
|
|
result.callback_save = (LayerCallbackSave)_layerSave;
|
|
|
|
result.callback_load = (LayerCallbackLoad)_layerLoad;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|