Experimental scenery generate/save/load from UI

This commit is contained in:
Michaël Lemaire 2015-08-19 20:06:47 +02:00
parent 3599c3aecf
commit 87acc42041
5 changed files with 49 additions and 2 deletions

View file

@ -10,6 +10,7 @@
#include "TerrainDefinition.h" #include "TerrainDefinition.h"
#include "TexturesDefinition.h" #include "TexturesDefinition.h"
#include "WaterDefinition.h" #include "WaterDefinition.h"
#include "Logs.h"
static const double APP_HEADER = 19866544632.125; static const double APP_HEADER = 19866544632.125;
static const int DATA_VERSION = 1; static const int DATA_VERSION = 1;
@ -65,6 +66,7 @@ Scenery::FileOperationResult Scenery::saveGlobal(const std::string &filepath) co
stream.write(&version_header); stream.write(&version_header);
stream.write(&app_header); stream.write(&app_header);
Logs::debug() << "Scenery saved to file: " << filepath << std::endl;
return FILE_OPERATION_OK; return FILE_OPERATION_OK;
} }
@ -108,6 +110,7 @@ Scenery::FileOperationResult Scenery::loadGlobal(const std::string &filepath)
return FILE_OPERATION_APP_MISMATCH; return FILE_OPERATION_APP_MISMATCH;
} }
Logs::debug() << "Scenery loaded from file: " << filepath << std::endl;
return FILE_OPERATION_OK; return FILE_OPERATION_OK;
} }
@ -134,6 +137,8 @@ void Scenery::autoPreset(int seed)
camera->setTarget(VECTOR_NORTH); camera->setTarget(VECTOR_NORTH);
validate(); validate();
Logs::debug() << "New scenery generated from seed " << seed << ":\n" << toString() << std::endl;
} }
void Scenery::setAtmosphere(AtmosphereDefinition* atmosphere) void Scenery::setAtmosphere(AtmosphereDefinition* atmosphere)

View file

@ -20,8 +20,6 @@ MainModelerWindow::MainModelerWindow()
scenery = new Scenery(); scenery = new Scenery();
scenery->autoPreset(); scenery->autoPreset();
Logs::debug() << "Initialized scenery:\n" << scenery->toString() << std::endl;
renderer = new OpenGLRenderer(scenery); renderer = new OpenGLRenderer(scenery);
render_preview_provider = new RenderPreviewProvider(); render_preview_provider = new RenderPreviewProvider();
@ -114,6 +112,29 @@ void MainModelerWindow::keyReleaseEvent(QKeyEvent *event)
QGuiApplication::instance()->exit(); QGuiApplication::instance()->exit();
} }
} }
else if (event->key() == Qt::Key_N)
{
if (event->modifiers() & Qt::ControlModifier)
{
getScenery()->autoPreset();
renderer->reset();
}
}
else if (event->key() == Qt::Key_S)
{
if (event->modifiers() & Qt::ControlModifier)
{
getScenery()->saveGlobal("saved.p3d");
}
}
else if (event->key() == Qt::Key_L or event->key() == Qt::Key_O)
{
if (event->modifiers() & Qt::ControlModifier)
{
getScenery()->loadGlobal("saved.p3d");
renderer->reset();
}
}
else if (event->key() == Qt::Key_Z) else if (event->key() == Qt::Key_Z)
{ {
if (event->modifiers() & Qt::ControlModifier) if (event->modifiers() & Qt::ControlModifier)

View file

@ -146,6 +146,18 @@ void OpenGLRenderer::paint()
} }
} }
void OpenGLRenderer::reset()
{
if (ready)
{
skybox->updateScenery();
water->updateScenery();
terrain->updateScenery();
cameraChangeEvent(render_camera);
}
}
void OpenGLRenderer::pause() void OpenGLRenderer::pause()
{ {
paused = true; paused = true;

View file

@ -26,6 +26,11 @@ public:
void resize(int width, int height); void resize(int width, int height);
void paint(); void paint();
/**
* Reset the whole state (when the scenery has been massively updated).
*/
void reset();
/** /**
* Pause the rendering process. * Pause the rendering process.
* *

View file

@ -90,6 +90,10 @@ void OpenGLTerrain::initialize()
void OpenGLTerrain::update() void OpenGLTerrain::update()
{ {
for (auto &chunk: _chunks)
{
chunk->askReset(true, true);
}
} }
void OpenGLTerrain::render() void OpenGLTerrain::render()