diff --git a/TODO b/TODO index f400dad..32a4b3e 100644 --- a/TODO +++ b/TODO @@ -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 : diff --git a/gui_qt/formclouds.cpp b/gui_qt/formclouds.cpp index 558ba35..fe132d9 100644 --- a/gui_qt/formclouds.cpp +++ b/gui_qt/formclouds.cpp @@ -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); } diff --git a/lib_paysages/auto.c b/lib_paysages/auto.c index e3023a1..9e42109 100644 --- a/lib_paysages/auto.c +++ b/lib_paysages/auto.c @@ -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; diff --git a/lib_paysages/clouds/definition.c b/lib_paysages/clouds/definition.c index e78d045..43a7edd 100644 --- a/lib_paysages/clouds/definition.c +++ b/lib_paysages/clouds/definition.c @@ -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; } diff --git a/lib_paysages/clouds/presets.c b/lib_paysages/clouds/presets.c index 4f007d4..ed1981c 100644 --- a/lib_paysages/clouds/presets.c +++ b/lib_paysages/clouds/presets.c @@ -1,13 +1,31 @@ #include "private.h" #include +#include /* * 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; diff --git a/lib_paysages/clouds/public.h b/lib_paysages/clouds/public.h index 89660f8..9bb6016 100644 --- a/lib_paysages/clouds/public.h +++ b/lib_paysages/clouds/public.h @@ -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); diff --git a/lib_paysages/layers.c b/lib_paysages/layers.c index 18d16a9..f4791fe 100644 --- a/lib_paysages/layers.c +++ b/lib_paysages/layers.c @@ -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; diff --git a/lib_paysages/layers.h b/lib_paysages/layers.h index 8c16965..194747c 100644 --- a/lib_paysages/layers.h +++ b/lib_paysages/layers.h @@ -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); diff --git a/lib_paysages/noise.c b/lib_paysages/noise.c index 78aa073..9df57ad 100644 --- a/lib_paysages/noise.c +++ b/lib_paysages/noise.c @@ -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(); } } diff --git a/lib_paysages/scenery.c b/lib_paysages/scenery.c index 9988252..430092a 100644 --- a/lib_paysages/scenery.c +++ b/lib_paysages/scenery.c @@ -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; diff --git a/lib_paysages/scenery.h b/lib_paysages/scenery.h index 31b2c50..e8611bc 100644 --- a/lib_paysages/scenery.h +++ b/lib_paysages/scenery.h @@ -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); diff --git a/lib_paysages/terrain/presets.c b/lib_paysages/terrain/presets.c index 37d12f0..f71519f 100644 --- a/lib_paysages/terrain/presets.c +++ b/lib_paysages/terrain/presets.c @@ -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); diff --git a/lib_paysages/water.c b/lib_paysages/water.c index 87b364b..fafb5d5 100644 --- a/lib_paysages/water.c +++ b/lib_paysages/water.c @@ -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;