From f93f97ed3878e748b01a68a5cdb9a1f0bca5b279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 17 Jun 2012 16:46:30 +0000 Subject: [PATCH] paysages : Small optimization. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@353 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 25 +++++++++++-------------- lib_paysages/noise.c | 36 +++++++++++++++++++++++++++--------- lib_paysages/noise.h | 1 + 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/TODO b/TODO index 2217f43..74d394e 100644 --- a/TODO +++ b/TODO @@ -6,7 +6,6 @@ Technology Preview 2 : - Add "hardness to light" and shadow control ("minimum lighting") to material. - Render tab previews should not rerender when changing render options. - Add layer sorting/naming. -- Disable specular lighting in explorer (and everything camera dependent). - Add logarithmic sliders for some float values. - Save GUI config (views, render params). - Add an OSD ability on previews and use it for camera location and user landmarks. @@ -14,22 +13,11 @@ Technology Preview 2 : - Add a terrain modifier dialog with zones. - Use the curve editor in noise editor - Add a noise filler (and maybe noise intervals ?). -- Optimize the use of noiseGetMaxValue (limit its use or cache it). - Fix the distorted sun appearance. - Improve curve editor. => Add curve modes => Add axis labels and grid => Add logarithmic mode -- Improve 3d explorer - => Restore LOD and intelligent poly count (and raise max tessellation) - => Interrupt chunk rendering when quitting dialog - => Don't display the water if it's below all ground - => Try to overcome the near frustum cutting - => Disable texture reflection of light (dependant on camera location) - => Add toggles (for water...) - => Max texture size should depend on GPU memory available -- Water and terrain LOD moves with the camera, fix it like in the wanderer. -- Interrupt preview chunk renderings that will be discarded at commit, or that are no more visible. - Fix "RGB parameters out of range" (and segfault) on preview while moving render params fast in render tab. => May need to change the updateData system. => Previews need to be paused while updating data. @@ -49,8 +37,17 @@ Technology Preview 3 : - Mark modified tabs and ask for losing modifications (idem for layers). - Fix potential holes in land rendering. - Progressive final render. -- Propose several backgrounds for water rendering (grid, sinus...). -- If we can't remove clouds artifacts, blur them. +- Propose several backgrounds for water preview (grid, sinus...). +- Water and terrain LOD moves with the camera, fix it like in the wanderer. +- Improve 3d explorer + => Restore LOD and intelligent poly count (and raise max tessellation) + => Interrupt chunk rendering when quitting dialog + => Don't display the water if it's below all ground + => Try to overcome the near frustum cutting + => Disable specular lighting (dependant on camera location) + => Add toggles (for water...) + => Max texture size should depend on GPU memory available +- Interrupt preview chunk renderings that will be discarded at commit, or that are no more visible. Release Candidate : - Polish all features and UI. diff --git a/lib_paysages/noise.c b/lib_paysages/noise.c index 9a65416..2096d0a 100644 --- a/lib_paysages/noise.c +++ b/lib_paysages/noise.c @@ -18,6 +18,8 @@ struct NoiseGenerator double height_offset; int level_count; struct NoiseLevel levels[MAX_LEVEL_COUNT]; + + double _max_height; }; static int _noise_pool_size; @@ -80,6 +82,8 @@ NoiseGenerator* noiseCreateGenerator() result->size3 = 1; result->level_count = 0; result->height_offset = 0.0; + + noiseValidate(result); return result; } @@ -131,6 +135,8 @@ void noiseLoadGenerator(PackStream* stream, NoiseGenerator* perlin) packReadDouble(stream, &level->yoffset); packReadDouble(stream, &level->zoffset); } + + noiseValidate(perlin); } void noiseCopy(NoiseGenerator* source, NoiseGenerator* destination) @@ -142,6 +148,21 @@ void noiseCopy(NoiseGenerator* source, NoiseGenerator* destination) destination->level_count = source->level_count; memcpy(destination->levels, source->levels, sizeof(NoiseLevel) * destination->level_count); + + noiseValidate(destination); +} + +void noiseValidate(NoiseGenerator* generator) +{ + int x; + double max_height = generator->height_offset; + + for (x = 0; x < generator->level_count; x++) + { + max_height += generator->levels[x].height / 2.0; + } + + generator->_max_height = max_height; } void noiseGenerateBaseNoise(NoiseGenerator* generator, int size) @@ -161,15 +182,7 @@ int noiseGetBaseSize(NoiseGenerator* generator) double noiseGetMaxValue(NoiseGenerator* generator) { - int x; - double result = generator->height_offset; - - for (x = 0; x < generator->level_count; x++) - { - result += generator->levels[x].height / 2.0; - } - - return result; + return generator->_max_height; } int noiseGetLevelCount(NoiseGenerator* generator) @@ -180,6 +193,7 @@ int noiseGetLevelCount(NoiseGenerator* generator) void noiseClearLevels(NoiseGenerator* generator) { generator->level_count = 0; + noiseValidate(generator); } void noiseAddLevel(NoiseGenerator* generator, NoiseLevel level) @@ -188,6 +202,7 @@ void noiseAddLevel(NoiseGenerator* generator, NoiseLevel level) { generator->levels[generator->level_count] = level; generator->level_count++; + noiseValidate(generator); } } @@ -240,6 +255,7 @@ void noiseRemoveLevel(NoiseGenerator* generator, int level) memmove(generator->levels + level, generator->levels + level + 1, sizeof(NoiseLevel) * (generator->level_count - level - 1)); } generator->level_count--; + noiseValidate(generator); } } @@ -261,6 +277,7 @@ void noiseSetLevel(NoiseGenerator* generator, int level, NoiseLevel params) if (level >= 0 && level < generator->level_count) { generator->levels[level] = params; + noiseValidate(generator); } } @@ -301,6 +318,7 @@ void noiseNormalizeHeight(NoiseGenerator* generator, double min_height, double m } } generator->height_offset = min_height + target_height / 2.0; + noiseValidate(generator); } diff --git a/lib_paysages/noise.h b/lib_paysages/noise.h index 4c6dec9..a2d2823 100644 --- a/lib_paysages/noise.h +++ b/lib_paysages/noise.h @@ -28,6 +28,7 @@ void noiseDeleteGenerator(NoiseGenerator* generator); void noiseSaveGenerator(PackStream* stream, NoiseGenerator* perlin); void noiseLoadGenerator(PackStream* stream, NoiseGenerator* perlin); void noiseCopy(NoiseGenerator* source, NoiseGenerator* destination); +void noiseValidate(NoiseGenerator* generator); void noiseGenerateBaseNoise(NoiseGenerator* generator, int size); int noiseGetBaseSize(NoiseGenerator* generator); double noiseGetMaxValue(NoiseGenerator* generator);