From ae3a91970fa4fb86ff0d39ceeeb4f03c0a500bc7 Mon Sep 17 00:00:00 2001 From: louis-e <44675238+louis-e@users.noreply.github.com> Date: Sun, 29 Dec 2024 00:41:20 +0100 Subject: [PATCH] Add floodfill timeout support --- README.md | 15 +++++++-------- gui-src/css/styles.css | 4 ++-- gui-src/index.html | 6 ++++++ gui-src/js/main.js | 6 +++++- src/args.rs | 2 +- src/element_processing/highways.rs | 2 +- src/floodfill.rs | 4 ++-- src/main.rs | 3 ++- 8 files changed, 26 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 2797956..705a434 100644 --- a/README.md +++ b/README.md @@ -60,19 +60,18 @@ The project is named after the smallest city in Germany, Arnis[^2]. The city's s ## :memo: ToDo and Known Bugs Feel free to choose an item from the To-Do or Known Bugs list, or bring your own idea to the table. Bug reports shall be raised as a Github issue. Contributions are highly welcome and appreciated! -- [ ] Memory optimization +- [ ] Mapping real coordinates to Minecraft coordinates (https://github.com/louis-e/arnis/issues/29) +- [ ] Evaluate and implement elevation (https://github.com/louis-e/arnis/issues/66) - [ ] Fix Github Action Workflow for releasing Linux & MacOS Binary -- [ ] Evaluate and implement multithreaded region saving -- [ ] Better code documentation +- [ ] Evaluate and implement faster region saving +- [ ] Automatic new world creation instead of using an existing world - [ ] Implement house roof types -- [ ] Refactor railway implementation - [ ] Refactor bridges implementation +- [ ] Refactor railway implementation +- [ ] Better code documentation - [ ] Refactor fountain structure implementation -- [ ] Automatic new world creation instead of using an existing world -- [ ] Tool for mapping real coordinates to Minecraft coordinates - [ ] Add interior to buildings -- [ ] Evaluate and implement elevation -- [ ] Implement memory mapped storing of chunks to reduce memory usage +- [x] Memory optimization - [x] Design and implement a GUI - [x] Fix faulty empty chunks ([https://github.com/owengage/fastnbt/issues/120](https://github.com/owengage/fastnbt/issues/120)) (workaround found) - [x] Setup fork of [https://github.com/aaronr/bboxfinder.com](https://github.com/aaronr/bboxfinder.com) for easy bbox picking diff --git a/gui-src/css/styles.css b/gui-src/css/styles.css index 1832253..d0e6c5d 100644 --- a/gui-src/css/styles.css +++ b/gui-src/css/styles.css @@ -309,7 +309,7 @@ button:hover { #bbox-coords { width: 100%; padding: 8px; - border: 1px solid #ccc; + border: 1px solid #fecc44; border-radius: 4px; font-size: 14px; } @@ -317,7 +317,7 @@ button:hover { #bbox-coords:focus { outline: none; border-color: #fecc44; - box-shadow: 0 0 5px rgba(0, 123, 255, 0.5); + box-shadow: 0 0 5px #fecc44; } diff --git a/gui-src/index.html b/gui-src/index.html index a9db4cd..cce3e11 100644 --- a/gui-src/index.html +++ b/gui-src/index.html @@ -95,6 +95,12 @@

Customization Settings

+ + +
+ + +
diff --git a/gui-src/js/main.js b/gui-src/js/main.js index adcaede..bbb6d12 100644 --- a/gui-src/js/main.js +++ b/gui-src/js/main.js @@ -267,9 +267,13 @@ async function startGeneration() { var winter_mode = document.getElementById("winter-toggle").checked; var scale = parseFloat(document.getElementById("scale-value-slider").value); + var floodfill_timeout = parseInt(document.getElementById("floodfill-timeout").value, 10); + + // Validate the floodfill timeout + floodfill_timeout = isNaN(floodfill_timeout) || floodfill_timeout < 0 ? 20 : floodfill_timeout; // Pass the bounding box and selected world to the Rust backend - await invoke("gui_start_generation", { bboxText: selectedBBox, selectedWorld: worldPath, worldScale: scale, winterMode: winter_mode }); + await invoke("gui_start_generation", { bboxText: selectedBBox, selectedWorld: worldPath, worldScale: scale, winterMode: winter_mode, floodfillTimeout: floodfill_timeout }); console.log("Generation process started."); generationButtonEnabled = false; diff --git a/src/args.rs b/src/args.rs index 53c0f57..0827019 100644 --- a/src/args.rs +++ b/src/args.rs @@ -41,7 +41,7 @@ pub struct Args { #[arg(long, default_value_t = false, action = clap::ArgAction::SetTrue)] pub debug: bool, - /// Set floodfill timeout (seconds) (optional) // TODO + /// Set floodfill timeout (seconds) (optional) #[arg(long, value_parser = parse_duration)] pub timeout: Option, } diff --git a/src/element_processing/highways.rs b/src/element_processing/highways.rs index 068d2cc..afc2aec 100644 --- a/src/element_processing/highways.rs +++ b/src/element_processing/highways.rs @@ -105,7 +105,7 @@ pub fn generate_highways( let mut previous_node: Option<(i32, i32)> = None; let mut block_type = BLACK_CONCRETE; let mut block_range: i32 = 2; - let mut add_stripe = false; // Flag for adding stripes + let mut add_stripe = false; // Skip if 'layer' or 'level' is negative in the tags if let Some(layer) = element.tags().get("layer") { diff --git a/src/floodfill.rs b/src/floodfill.rs index da66681..1287afd 100644 --- a/src/floodfill.rs +++ b/src/floodfill.rs @@ -56,7 +56,7 @@ pub fn flood_fill_area( while let Some((start_x, start_z)) = candidate_points.pop_front() { if let Some(timeout) = timeout { if &start_time.elapsed() > timeout { - eprintln!("Floodfill timeout"); // TODO only print when debug arg is set? + eprintln!("Floodfill timeout"); break; } } @@ -70,7 +70,7 @@ pub fn flood_fill_area( while let Some((x, z)) = queue.pop_front() { if let Some(timeout) = timeout { if &start_time.elapsed() > timeout { - eprintln!("Floodfill timeout"); // TODO only print when debug arg is set? + eprintln!("Floodfill timeout"); break; } } diff --git a/src/main.rs b/src/main.rs index 68e0a4e..b8ef51e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -213,6 +213,7 @@ fn gui_start_generation( selected_world: String, world_scale: f64, winter_mode: bool, + floodfill_timeout: u64, ) -> Result<(), String> { tauri::async_runtime::spawn(async move { if let Err(e) = tokio::task::spawn_blocking(move || { @@ -240,7 +241,7 @@ fn gui_start_generation( scale: world_scale, winter: winter_mode, debug: false, - timeout: None, + timeout: Some(std::time::Duration::from_secs(floodfill_timeout)), }; // Reorder bounding box coordinates for further processing