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
This commit is contained in:
Michaël Lemaire 2012-01-30 13:10:16 +00:00 committed by ThunderK
parent 878614e13c
commit 4f55c9e2a6
5 changed files with 34 additions and 8 deletions

3
TODO
View file

@ -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).

View file

@ -2,6 +2,7 @@
#include <QGLWidget>
#include <QKeyEvent>
#include <QTime>
#include <math.h>
#include "../lib_paysages/scenery.h"
@ -20,6 +21,8 @@ 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++;
}
}

View file

@ -33,6 +33,9 @@ private:
TerrainDefinition terrain;
WaterDefinition water;
double average_frame_time;
int quality;
int last_mouse_x;
int last_mouse_y;
};

View file

@ -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;

View file

@ -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;
}