mirror of
https://github.com/louis-e/arnis.git
synced 2026-01-24 14:07:51 -05:00
Compare commits
5 Commits
tilecache-
...
benchmark-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
996e8756d0 | ||
|
|
0c5bd51ba4 | ||
|
|
7965dc3737 | ||
|
|
c54187b43a | ||
|
|
beb7b73d11 |
@@ -59,6 +59,10 @@ pub struct Args {
|
|||||||
#[arg(long, value_parser = parse_duration)]
|
#[arg(long, value_parser = parse_duration)]
|
||||||
pub timeout: Option<Duration>,
|
pub timeout: Option<Duration>,
|
||||||
|
|
||||||
|
/// Generate a top-down map preview image after world generation (optional)
|
||||||
|
#[arg(long)]
|
||||||
|
pub generate_map: bool,
|
||||||
|
|
||||||
/// Spawn point coordinates (lat, lng)
|
/// Spawn point coordinates (lat, lng)
|
||||||
#[arg(skip)]
|
#[arg(skip)]
|
||||||
pub spawn_point: Option<(f64, f64)>,
|
pub spawn_point: Option<(f64, f64)>,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::element_processing::*;
|
|||||||
use crate::ground::Ground;
|
use crate::ground::Ground;
|
||||||
use crate::map_renderer;
|
use crate::map_renderer;
|
||||||
use crate::osm_parser::ProcessedElement;
|
use crate::osm_parser::ProcessedElement;
|
||||||
use crate::progress::emit_gui_progress_update;
|
use crate::progress::{emit_gui_progress_update, emit_map_preview_ready};
|
||||||
#[cfg(feature = "gui")]
|
#[cfg(feature = "gui")]
|
||||||
use crate::telemetry::{send_log, LogLevel};
|
use crate::telemetry::{send_log, LogLevel};
|
||||||
use crate::world_editor::WorldEditor;
|
use crate::world_editor::WorldEditor;
|
||||||
@@ -266,33 +266,54 @@ pub fn generate_world(
|
|||||||
emit_gui_progress_update(100.0, "Done! World generation completed.");
|
emit_gui_progress_update(100.0, "Done! World generation completed.");
|
||||||
println!("{}", "Done! World generation completed.".green().bold());
|
println!("{}", "Done! World generation completed.".green().bold());
|
||||||
|
|
||||||
// Generate top-down map preview silently in background after completion
|
// Generate top-down map preview:
|
||||||
let world_path = args.path.clone();
|
// - Always for GUI mode (non-blocking, runs in background)
|
||||||
let bounds = (
|
// - Only when --generate-map flag is set for CLI mode (blocking, waits for completion)
|
||||||
xzbbox.min_x(),
|
#[cfg(feature = "gui")]
|
||||||
xzbbox.max_x(),
|
let should_generate_map = true;
|
||||||
xzbbox.min_z(),
|
#[cfg(not(feature = "gui"))]
|
||||||
xzbbox.max_z(),
|
let should_generate_map = args.generate_map;
|
||||||
);
|
|
||||||
std::thread::spawn(move || {
|
|
||||||
// Use catch_unwind to prevent any panic from affecting the application
|
|
||||||
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
|
||||||
map_renderer::render_world_map(&world_path, bounds.0, bounds.1, bounds.2, bounds.3)
|
|
||||||
}));
|
|
||||||
|
|
||||||
match result {
|
if should_generate_map {
|
||||||
Ok(Ok(_path)) => {
|
let world_path = args.path.clone();
|
||||||
// Notify the GUI that the map preview is ready
|
let bounds = (
|
||||||
crate::progress::emit_map_preview_ready();
|
xzbbox.min_x(),
|
||||||
}
|
xzbbox.max_x(),
|
||||||
Ok(Err(e)) => {
|
xzbbox.min_z(),
|
||||||
eprintln!("Warning: Failed to generate map preview: {}", e);
|
xzbbox.max_z(),
|
||||||
}
|
);
|
||||||
Err(_) => {
|
|
||||||
eprintln!("Warning: Map preview generation panicked unexpectedly");
|
let map_thread = std::thread::spawn(move || {
|
||||||
|
// Use catch_unwind to prevent any panic from affecting the application
|
||||||
|
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||||
|
map_renderer::render_world_map(&world_path, bounds.0, bounds.1, bounds.2, bounds.3)
|
||||||
|
}));
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(Ok(_path)) => {
|
||||||
|
// Notify the GUI that the map preview is ready
|
||||||
|
emit_map_preview_ready();
|
||||||
|
}
|
||||||
|
Ok(Err(e)) => {
|
||||||
|
eprintln!("Warning: Failed to generate map preview: {}", e);
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
eprintln!("Warning: Map preview generation panicked unexpectedly");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// In CLI mode, wait for map generation to complete before exiting
|
||||||
|
// In GUI mode, let it run in background to keep UI responsive
|
||||||
|
#[cfg(not(feature = "gui"))]
|
||||||
|
{
|
||||||
|
let _ = map_thread.join();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
// In GUI mode, we don't join, let the thread run in background
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
|
drop(map_thread);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -825,6 +825,7 @@ fn gui_start_generation(
|
|||||||
fillground: fillground_enabled,
|
fillground: fillground_enabled,
|
||||||
debug: false,
|
debug: false,
|
||||||
timeout: Some(std::time::Duration::from_secs(floodfill_timeout)),
|
timeout: Some(std::time::Duration::from_secs(floodfill_timeout)),
|
||||||
|
generate_map: true,
|
||||||
spawn_point,
|
spawn_point,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -876,7 +877,6 @@ fn gui_start_generation(
|
|||||||
&mut xzbbox,
|
&mut xzbbox,
|
||||||
&mut ground,
|
&mut ground,
|
||||||
);
|
);
|
||||||
send_log(LogLevel::Info, "Map transformation completed.");
|
|
||||||
|
|
||||||
let _ = data_processing::generate_world(
|
let _ = data_processing::generate_world(
|
||||||
parsed_elements,
|
parsed_elements,
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ mod gui;
|
|||||||
mod progress {
|
mod progress {
|
||||||
pub fn emit_gui_error(_message: &str) {}
|
pub fn emit_gui_error(_message: &str) {}
|
||||||
pub fn emit_gui_progress_update(_progress: f64, _message: &str) {}
|
pub fn emit_gui_progress_update(_progress: f64, _message: &str) {}
|
||||||
|
pub fn emit_map_preview_ready() {}
|
||||||
pub fn is_running_with_gui() -> bool {
|
pub fn is_running_with_gui() -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user