From 48d2c8f0c7c7822ecd4262bbf2c1a04a55734ac4 Mon Sep 17 00:00:00 2001 From: Maik Marschner Date: Tue, 24 Sep 2024 01:49:30 +0200 Subject: [PATCH 1/5] Use y-clipping settings from the map view when creating a new scene or loading chunks from it and fix requiring two reloads after changing the y-clipping settings of a scene. --- .../renderer/scene/SynchronousSceneManager.java | 12 +++++++++--- chunky/src/java/se/llbit/chunky/ui/ChunkMap.java | 14 ++++++++++---- .../se/llbit/chunky/ui/render/tabs/GeneralTab.java | 6 ++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java b/chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java index 1432dd9588..8ac135250c 100644 --- a/chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java +++ b/chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java @@ -235,15 +235,21 @@ public void saveScene(SceneIOProvider ioContext, Scene scene) throws Interrupted @Override public void loadFreshChunks(World world, Collection chunksToLoad) { synchronized (scene) { + int yClipMin = scene.getYClipMin(); + int yClipMax = scene.getYClipMax(); scene.clear(); - scene.loadChunks(taskTracker, world, chunksToLoad); scene.resetScene(null, context.getChunky().getSceneFactory()); + scene.setYClipMin(yClipMin); + scene.setYClipMax(yClipMax); context.setSceneDirectory(new File(context.getChunky().options.sceneDir, scene.name)); + scene.loadChunks(taskTracker, world, chunksToLoad); scene.refresh(); scene.setResetReason(ResetReason.SCENE_LOADED); scene.setRenderMode(RenderMode.PREVIEW); } + System.out.println(scene.getYClipMin()+" min, 2 max "+scene.getYClipMax()); onSceneLoaded.run(); + System.out.println(scene.getYClipMin()+" min, 3 max "+scene.getYClipMax()); } @Override public void loadChunks(World world, Collection chunksToLoad) { @@ -253,9 +259,9 @@ public void saveScene(SceneIOProvider ioContext, Scene scene) throws Interrupted if (prevChunkCount == 0) { scene.moveCameraToCenter(); } - scene.refresh(); scene.setResetReason(ResetReason.SCENE_LOADED); scene.setRenderMode(RenderMode.PREVIEW); + scene.refresh(); } onChunksLoaded.run(); } @@ -263,9 +269,9 @@ public void saveScene(SceneIOProvider ioContext, Scene scene) throws Interrupted @Override public void reloadChunks() { synchronized (scene) { scene.reloadChunks(taskTracker); - scene.refresh(); scene.setResetReason(ResetReason.SCENE_LOADED); scene.setRenderMode(RenderMode.PREVIEW); + scene.refresh(); } onChunksLoaded.run(); } diff --git a/chunky/src/java/se/llbit/chunky/ui/ChunkMap.java b/chunky/src/java/se/llbit/chunky/ui/ChunkMap.java index 76b1f9d510..411e8740be 100644 --- a/chunky/src/java/se/llbit/chunky/ui/ChunkMap.java +++ b/chunky/src/java/se/llbit/chunky/ui/ChunkMap.java @@ -159,16 +159,22 @@ public ChunkMap(WorldMapLoader loader, ChunkyFxController controller, newScene.setGraphic(new ImageView(Icon.sky.fxImage())); newScene.setOnAction(event -> { SceneManager sceneManager = controller.getRenderController().getSceneManager(); - sceneManager - .loadFreshChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection()); + sceneManager.getSceneProvider().withEditSceneProtected(scene -> { + scene.setYClipMin(mapView.getYMin()); + scene.setYClipMax(mapView.getYMax()); + }); + sceneManager.loadFreshChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection()); }); newScene.setDisable(chunkSelection.isEmpty()); MenuItem loadSelection = new MenuItem("Load selected chunks"); loadSelection.setOnAction(event -> { SceneManager sceneManager = controller.getRenderController().getSceneManager(); - sceneManager - .loadChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection()); + sceneManager.getSceneProvider().withEditSceneProtected(scene -> { + scene.setYClipMin(mapView.getYMin()); + scene.setYClipMax(mapView.getYMax()); + }); + sceneManager.loadChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection()); }); loadSelection.setDisable(chunkSelection.isEmpty()); diff --git a/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java b/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java index b46ac8e1ea..9cfbd73e91 100644 --- a/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java +++ b/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java @@ -187,6 +187,12 @@ public GeneralTab() throws IOException { canvasSizeInput.setSize(scene.canvasConfig.getCropWidth(), scene.canvasConfig.getCropHeight()); } + @Override + public void onChunksLoaded() { + yMin.set(scene.getYClipMin()); + yMax.set(scene.getYClipMax()); + } + @Override public String getTabTitle() { return "Scene"; } From 28f8465a132662daee8a3ac55ca80dd5b1d8e7fc Mon Sep 17 00:00:00 2001 From: Maik Marschner Date: Tue, 24 Sep 2024 10:55:51 +0200 Subject: [PATCH 2/5] Remove debug output. --- .../se/llbit/chunky/renderer/scene/SynchronousSceneManager.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java b/chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java index 8ac135250c..2ca51a41bf 100644 --- a/chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java +++ b/chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java @@ -247,9 +247,7 @@ public void saveScene(SceneIOProvider ioContext, Scene scene) throws Interrupted scene.setResetReason(ResetReason.SCENE_LOADED); scene.setRenderMode(RenderMode.PREVIEW); } - System.out.println(scene.getYClipMin()+" min, 2 max "+scene.getYClipMax()); onSceneLoaded.run(); - System.out.println(scene.getYClipMin()+" min, 3 max "+scene.getYClipMax()); } @Override public void loadChunks(World world, Collection chunksToLoad) { From 8789d957d49ea7377d11dc243f9abeee23c94a39 Mon Sep 17 00:00:00 2001 From: Maik Marschner Date: Tue, 24 Sep 2024 11:16:33 +0200 Subject: [PATCH 3/5] Do not ignore scene loaded as reset reason for the scene and update outdated getResetReason javadoc. --- chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java b/chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java index 54a69d051c..9b01b75a90 100644 --- a/chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java +++ b/chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java @@ -3073,17 +3073,15 @@ public Collection getChunks() { } /** - * Clears the reset reason and returns the previous reason. + * Get the reset reason. * @return the current reset reason */ - public synchronized ResetReason getResetReason() { + public ResetReason getResetReason() { return resetReason; } public void setResetReason(ResetReason resetReason) { - if (this.resetReason != ResetReason.SCENE_LOADED) { - this.resetReason = resetReason; - } + this.resetReason = resetReason; } public void importMaterials() { From 275c711e86b2a190cd007fd86c6911ce35f06e7a Mon Sep 17 00:00:00 2001 From: Maik Marschner Date: Tue, 24 Sep 2024 19:00:06 +0200 Subject: [PATCH 4/5] Fix changing the map y clip sliders resetting the scene y clip sliders. --- .../se/llbit/chunky/ui/render/tabs/GeneralTab.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java b/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java index 9cfbd73e91..3f6325b186 100644 --- a/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java +++ b/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java @@ -514,14 +514,16 @@ private void updateCanvasCrop() { private void updateYClipSlidersRanges(World world) { if (world != null && world.getVersionId() >= World.VERSION_21W06A) { yMin.setRange(-64, 320); - yMin.set(-64); yMax.setRange(-64, 320); - yMax.set(320); } else { yMin.setRange(0, 256); - yMin.set(0); + if (yMin.get() < 0) { + yMin.set(0); + } yMax.setRange(0, 256); - yMax.set(256); + if (yMax.get() > 256) { + yMax.set(256); + } } } } From fffe570b39654f9b5e0fbbac817f5e3f4e36a502 Mon Sep 17 00:00:00 2001 From: Maik Marschner Date: Tue, 24 Sep 2024 19:01:21 +0200 Subject: [PATCH 5/5] Don't change the scene's y clipping at all when changing the map y clipping. --- .../src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java b/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java index 3f6325b186..31dce0c75f 100644 --- a/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java +++ b/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java @@ -517,13 +517,7 @@ private void updateYClipSlidersRanges(World world) { yMax.setRange(-64, 320); } else { yMin.setRange(0, 256); - if (yMin.get() < 0) { - yMin.set(0); - } yMax.setRange(0, 256); - if (yMax.get() > 256) { - yMax.set(256); - } } } }