paysages : Made fileNew work again.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@509 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-01-30 14:30:06 +00:00 committed by ThunderK
parent 756ff0ec99
commit ed268098a1
13 changed files with 63 additions and 21 deletions

1
TODO
View file

@ -22,7 +22,6 @@ Technology Preview 2 :
=> Add texture shadowing.
- Clouds should keep distance to ground.
- Fix rendering when inside a cloud layer, with other upper or lower layers.
- Make fileNew work again (call auto presets and randomize all noise offsets).
- Improve cloud rendering precision (and beware of precision discontinuity when rendering clouds in front of ground (shorter distance)).
Technlogy Preview 3 :

View file

@ -139,7 +139,7 @@ void FormClouds::layerWriteCurrentTo(void* layer_definition)
void FormClouds::autoPresetSelected(int preset)
{
cloudsAutoPreset(_layer, (CloudsPreset)preset);
cloudsLayerAutoPreset(_layer, (CloudsLayerPreset)preset);
BaseForm::autoPresetSelected(preset);
}

View file

@ -24,11 +24,7 @@ void autoGenRealisticLandscape(int seed)
}
srand(seed);
/* Cloud layer */
CloudsDefinition* clouds = CloudsDefinitionClass.create();
layer = layersAddLayer(clouds->layers, NULL);
scenerySetClouds(clouds);
CloudsDefinitionClass.destroy(clouds);
sceneryAutoPreset();
/* Water */
water = waterCreateDefinition();
@ -42,6 +38,7 @@ void autoGenRealisticLandscape(int seed)
layersSetName(textures.layers, layer, "Ground");
texture = layersGetLayer(textures.layers, layer);
noiseClearLevels(texture->bump_noise);
noiseRandomizeOffsets(texture->bump_noise);
noiseAddLevelsSimple(texture->bump_noise, 8, 1.0, -0.5, 0.5);
texture->bump_height = 0.01;
texture->bump_scaling = 0.045;
@ -59,6 +56,7 @@ void autoGenRealisticLandscape(int seed)
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);
noiseClearLevels(texture->bump_noise);
noiseRandomizeOffsets(texture->bump_noise);
noiseAddLevelsSimple(texture->bump_noise, 5, 1.0, -0.2, 0.2);
noiseAddLevelsSimple(texture->bump_noise, 2, 0.03, -0.04, 0.04);
texture->bump_height = 0.002;

View file

@ -128,7 +128,7 @@ CloudsLayerDefinition* cloudsLayerCreateDefinition()
result->_shape_noise = noiseCreateGenerator();
result->_edge_noise = noiseCreateGenerator();
cloudsAutoPreset(result, CLOUDS_PRESET_CIRRUS);
cloudsLayerAutoPreset(result, CLOUDS_LAYER_PRESET_CIRRUS);
return result;
}

View file

@ -1,13 +1,31 @@
#include "private.h"
#include <math.h>
#include <stdlib.h>
/*
* Clouds presets.
*/
void cloudsAutoPreset(CloudsLayerDefinition* definition, CloudsPreset preset)
void cloudsAutoPreset(CloudsDefinition* definition, CloudsPreset preset)
{
int layer;
layersClear(definition->layers);
if (preset == CLOUDS_PRESET_PARTLY_CLOUDY)
{
layer = layersAddLayer(definition->layers, NULL);
cloudsLayerAutoPreset(layersGetLayer(definition->layers, layer), CLOUDS_LAYER_PRESET_CIRRUS);
}
}
void cloudsLayerAutoPreset(CloudsLayerDefinition* definition, CloudsLayerPreset preset)
{
noiseRandomizeOffsets(definition->_coverage_noise);
noiseRandomizeOffsets(definition->_edge_noise);
noiseRandomizeOffsets(definition->_shape_noise);
definition->material.base.r = 0.7;
definition->material.base.g = 0.7;
definition->material.base.b = 0.7;
@ -15,7 +33,7 @@ void cloudsAutoPreset(CloudsLayerDefinition* definition, CloudsPreset preset)
switch (preset)
{
case CLOUDS_PRESET_CIRRUS:
case CLOUDS_LAYER_PRESET_CIRRUS:
definition->type = CLOUDS_TYPE_CIRRUS;
definition->lower_altitude = 25.0;
definition->thickness = 2.0;
@ -30,7 +48,7 @@ void cloudsAutoPreset(CloudsLayerDefinition* definition, CloudsPreset preset)
definition->edge_length = 0.8;
definition->base_coverage = 0.6;
break;
case CLOUDS_PRESET_CUMULUS:
case CLOUDS_LAYER_PRESET_CUMULUS:
definition->type = CLOUDS_TYPE_CUMULUS;
definition->lower_altitude = 15.0;
definition->thickness = 15.0;
@ -45,7 +63,7 @@ void cloudsAutoPreset(CloudsLayerDefinition* definition, CloudsPreset preset)
definition->edge_length = 0.0;
definition->base_coverage = 0.7;
break;
case CLOUDS_PRESET_STRATOCUMULUS:
case CLOUDS_LAYER_PRESET_STRATOCUMULUS:
definition->type = CLOUDS_TYPE_STRATOCUMULUS;
definition->lower_altitude = 5.0;
definition->thickness = 6.0;
@ -60,7 +78,7 @@ void cloudsAutoPreset(CloudsLayerDefinition* definition, CloudsPreset preset)
definition->edge_length = 0.3;
definition->base_coverage = 0.4;
break;
case CLOUDS_PRESET_STRATUS:
case CLOUDS_LAYER_PRESET_STRATUS:
definition->type = CLOUDS_TYPE_STRATUS;
definition->lower_altitude = 3.0;
definition->thickness = 4.0;

View file

@ -22,12 +22,17 @@ typedef enum
typedef enum
{
CLOUDS_PRESET_CIRRUS,
CLOUDS_PRESET_CUMULUS,
CLOUDS_PRESET_STRATOCUMULUS,
CLOUDS_PRESET_STRATUS
CLOUDS_PRESET_PARTLY_CLOUDY,
} CloudsPreset;
typedef enum
{
CLOUDS_LAYER_PRESET_CIRRUS,
CLOUDS_LAYER_PRESET_CUMULUS,
CLOUDS_LAYER_PRESET_STRATOCUMULUS,
CLOUDS_LAYER_PRESET_STRATUS
} CloudsLayerPreset;
typedef struct
{
CloudsType type;
@ -79,7 +84,8 @@ extern StandardRenderer CloudsRendererClass;
LayerType cloudsGetLayerType();
void cloudsAutoPreset(CloudsLayerDefinition* definition, CloudsPreset preset);
void cloudsAutoPreset(CloudsDefinition* definition, CloudsPreset preset);
void cloudsLayerAutoPreset(CloudsLayerDefinition* definition, CloudsLayerPreset preset);
Renderer* cloudsCreatePreviewCoverageRenderer();
Color cloudsGetPreviewCoverage(Renderer* renderer, double x, double y, double scaling, int perspective);

View file

@ -133,6 +133,14 @@ void layersSetName(Layers* layers, int layer, const char* name)
}
}
void layersClear(Layers* layers)
{
while (layersCount(layers))
{
layersDeleteLayer(layers, 0);
}
}
int layersCount(Layers* layers)
{
return layers->count;

View file

@ -40,6 +40,7 @@ void layersLoad(PackStream* stream, Layers* layers);
const char* layersGetName(Layers* layers, int layer);
void layersSetName(Layers* layers, int layer, const char* name);
void layersClear(Layers* layers);
int layersCount(Layers* layers);
void* layersGetLayer(Layers* layers, int layer);
int layersAddLayer(Layers* layers, void* definition);

View file

@ -221,9 +221,9 @@ void noiseRandomizeOffsets(NoiseGenerator* generator)
int i;
for (i = 0; i < MAX_LEVEL_COUNT; i++)
{
result->levels[i].xoffset = toolsRandom();
result->levels[i].yoffset = toolsRandom();
result->levels[i].zoffset = toolsRandom();
generator->levels[i].xoffset = toolsRandom();
generator->levels[i].yoffset = toolsRandom();
generator->levels[i].zoffset = toolsRandom();
}
}

View file

@ -43,6 +43,13 @@ void sceneryQuit()
noiseQuit();
}
void sceneryAutoPreset()
{
terrainAutoPreset(_terrain, TERRAIN_PRESET_STANDARD);
atmosphereAutoPreset(_atmosphere, ATMOSPHERE_MODEL_BRUNETON);
cloudsAutoPreset(_clouds, CLOUDS_PRESET_PARTLY_CLOUDY);
}
void scenerySetCustomDataCallback(SceneryCustomDataCallback callback_save, SceneryCustomDataCallback callback_load, void* data)
{
_custom_save = callback_save;

View file

@ -26,6 +26,8 @@ typedef void (*SceneryCustomDataCallback)(PackStream* stream, void* data);
void sceneryInit();
void sceneryQuit();
void sceneryAutoPreset();
void scenerySetCustomDataCallback(SceneryCustomDataCallback callback_save, SceneryCustomDataCallback callback_load, void* data);
void scenerySave(PackStream* stream);

View file

@ -12,6 +12,7 @@ void terrainAutoPreset(TerrainDefinition* definition, TerrainPreset preset)
switch (preset)
{
case TERRAIN_PRESET_STANDARD:
noiseRandomizeOffsets(definition->_height_noise);
noiseClearLevels(definition->_height_noise);
noiseAddLevelsSimple(definition->_height_noise, resolution, pow(2.0, resolution - 1), -12.5, 12.5);
noiseSetFunctionParams(definition->_height_noise, NOISE_FUNCTION_SIMPLEX, 0.0, 0.0);

View file

@ -69,6 +69,8 @@ void waterDeleteDefinition(WaterDefinition* definition)
void waterAutoPreset(WaterDefinition* definition, WaterPreset preset)
{
noiseRandomizeOffsets(definition->_waves_noise);
if (preset == WATER_PRESET_LAKE)
{
definition->transparency = 0.5;