From 4f55c9e2a67f8bdbaf43814a970297e7cfd07b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Mon, 30 Jan 2012 13:10:16 +0000 Subject: [PATCH] paysages : Restored render interrupt + added LOD dynamic adaptation to framerate for wanderer. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@253 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 3 ++- gui_qt/widgetwanderer.cpp | 26 ++++++++++++++++++++++++-- gui_qt/widgetwanderer.h | 3 +++ lib_paysages/render.c | 7 +++---- lib_paysages/renderer.c | 3 ++- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/TODO b/TODO index d66ff25..4055377 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,8 @@ -- Restore render interrupt and progress +- Restore render progress - Clouds are lighted without filtering from ground (clouds lighted at night !) - Camera should respect ratio aspect of render area. - All noises should use the same entropy pool (saved separately), and avoid reallocs. - Implement light multi-sampling (mainly for skydome). - Implement scaling and scrolling on previews. - Water and terrain LOD moves with the camera, fix it like in the wanderer. +- Find the random segfault at start (in PreviewTerrainColor::getColor). \ No newline at end of file diff --git a/gui_qt/widgetwanderer.cpp b/gui_qt/widgetwanderer.cpp index 29e226c..169784c 100644 --- a/gui_qt/widgetwanderer.cpp +++ b/gui_qt/widgetwanderer.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include "../lib_paysages/scenery.h" @@ -19,7 +20,9 @@ WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera): this->water = waterCreateDefinition(); sceneryGetWater(&water); - + + average_frame_time = 0.05; + quality = 3; last_mouse_x = 0; last_mouse_y = 0; } @@ -266,8 +269,13 @@ static void _renderTerrain(TerrainDefinition* terrain, CameraDefinition* camera, void WidgetWanderer::paintGL() { + QTime start_time; + double frame_time; + cameraValidateDefinition(&_current_camera, 1); + start_time = QTime::currentTime(); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(_current_camera.location.x, _current_camera.location.y, _current_camera.location.z, _current_camera.target.x, _current_camera.target.y, _current_camera.target.z, _current_camera.up.x, _current_camera.up.y, _current_camera.up.z); @@ -283,5 +291,19 @@ void WidgetWanderer::paintGL() glVertex3f(500.0, water.height, -500.0); glEnd(); - _renderTerrain(&terrain, &_current_camera, 3); + _renderTerrain(&terrain, &_current_camera, quality); + + frame_time = 0.001 * (double)start_time.msecsTo(QTime::currentTime()); + + average_frame_time = average_frame_time * 0.8 + frame_time * 0.2; + //printf("%d %f\n", quality, average_frame_time); + + if (average_frame_time > 0.1 && quality > 1) + { + quality--; + } + if (average_frame_time < 0.04 && quality < 10) + { + quality++; + } } diff --git a/gui_qt/widgetwanderer.h b/gui_qt/widgetwanderer.h index f0b4ef6..135440f 100644 --- a/gui_qt/widgetwanderer.h +++ b/gui_qt/widgetwanderer.h @@ -32,6 +32,9 @@ private: TerrainDefinition terrain; WaterDefinition water; + + double average_frame_time; + int quality; int last_mouse_x; int last_mouse_y; diff --git a/lib_paysages/render.c b/lib_paysages/render.c index f052b7c..65dab01 100644 --- a/lib_paysages/render.c +++ b/lib_paysages/render.c @@ -634,7 +634,6 @@ void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks) int i; int x, y, dx, dy, nx, ny; int loops, running; - int _interrupt = 0; /* TEMP */ if (nbchunks > MAX_CHUNKS) { @@ -662,7 +661,7 @@ void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks) running = 0; loops = 0; - while ((y < ny && !_interrupt) || running > 0) + while ((y < ny && !renderer->render_interrupt) || running > 0) { timeSleepMs(100); @@ -676,13 +675,13 @@ void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks) chunks[i].thread = NULL; running--; } - else if (_interrupt) + else if (renderer->render_interrupt) { chunks[i].interrupt = 1; } } - if (y < ny && !chunks[i].thread && !_interrupt) + if (y < ny && !chunks[i].thread && !renderer->render_interrupt) { chunks[i].finished = 0; chunks[i].interrupt = 0; diff --git a/lib_paysages/renderer.c b/lib_paysages/renderer.c index 69f1fb5..172307f 100644 --- a/lib_paysages/renderer.c +++ b/lib_paysages/renderer.c @@ -19,7 +19,7 @@ static void* _renderFirstPass(void* data) static int _addRenderProgress(Renderer* renderer, double progress) { - return 1; + return !renderer->render_interrupt; } static double _getPrecision(Renderer* renderer, Vector3 location) @@ -183,4 +183,5 @@ void rendererStart(Renderer* renderer, int width, int height, int quality) void rendererInterrupt(Renderer* renderer) { + renderer->render_interrupt = 1; }