diff --git a/src/definition/Scenery.cpp b/src/definition/Scenery.cpp index bc4ab71..5bf666c 100644 --- a/src/definition/Scenery.cpp +++ b/src/definition/Scenery.cpp @@ -10,6 +10,7 @@ #include "TerrainDefinition.h" #include "TexturesDefinition.h" #include "WaterDefinition.h" +#include "Logs.h" static const double APP_HEADER = 19866544632.125; 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(&app_header); + Logs::debug() << "Scenery saved to file: " << filepath << std::endl; return FILE_OPERATION_OK; } @@ -108,6 +110,7 @@ Scenery::FileOperationResult Scenery::loadGlobal(const std::string &filepath) return FILE_OPERATION_APP_MISMATCH; } + Logs::debug() << "Scenery loaded from file: " << filepath << std::endl; return FILE_OPERATION_OK; } @@ -134,6 +137,8 @@ void Scenery::autoPreset(int seed) camera->setTarget(VECTOR_NORTH); validate(); + + Logs::debug() << "New scenery generated from seed " << seed << ":\n" << toString() << std::endl; } void Scenery::setAtmosphere(AtmosphereDefinition* atmosphere) diff --git a/src/interface/modeler/quickapp/MainModelerWindow.cpp b/src/interface/modeler/quickapp/MainModelerWindow.cpp index 1d37d72..46b1db4 100644 --- a/src/interface/modeler/quickapp/MainModelerWindow.cpp +++ b/src/interface/modeler/quickapp/MainModelerWindow.cpp @@ -20,8 +20,6 @@ MainModelerWindow::MainModelerWindow() scenery = new Scenery(); scenery->autoPreset(); - Logs::debug() << "Initialized scenery:\n" << scenery->toString() << std::endl; - renderer = new OpenGLRenderer(scenery); render_preview_provider = new RenderPreviewProvider(); @@ -114,6 +112,29 @@ void MainModelerWindow::keyReleaseEvent(QKeyEvent *event) 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) { if (event->modifiers() & Qt::ControlModifier) diff --git a/src/render/opengl/OpenGLRenderer.cpp b/src/render/opengl/OpenGLRenderer.cpp index 44e415c..02a8f85 100644 --- a/src/render/opengl/OpenGLRenderer.cpp +++ b/src/render/opengl/OpenGLRenderer.cpp @@ -146,6 +146,18 @@ void OpenGLRenderer::paint() } } +void OpenGLRenderer::reset() +{ + if (ready) + { + skybox->updateScenery(); + water->updateScenery(); + terrain->updateScenery(); + + cameraChangeEvent(render_camera); + } +} + void OpenGLRenderer::pause() { paused = true; diff --git a/src/render/opengl/OpenGLRenderer.h b/src/render/opengl/OpenGLRenderer.h index c3f840b..0d0de51 100644 --- a/src/render/opengl/OpenGLRenderer.h +++ b/src/render/opengl/OpenGLRenderer.h @@ -26,6 +26,11 @@ public: void resize(int width, int height); void paint(); + /** + * Reset the whole state (when the scenery has been massively updated). + */ + void reset(); + /** * Pause the rendering process. * diff --git a/src/render/opengl/OpenGLTerrain.cpp b/src/render/opengl/OpenGLTerrain.cpp index 070e330..ee6aee2 100644 --- a/src/render/opengl/OpenGLTerrain.cpp +++ b/src/render/opengl/OpenGLTerrain.cpp @@ -90,6 +90,10 @@ void OpenGLTerrain::initialize() void OpenGLTerrain::update() { + for (auto &chunk: _chunks) + { + chunk->askReset(true, true); + } } void OpenGLTerrain::render()