mirror of
https://github.com/louis-e/arnis.git
synced 2025-12-24 06:48:00 -05:00
Compare commits
5 Commits
main
...
benchmark-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
996e8756d0 | ||
|
|
0c5bd51ba4 | ||
|
|
7965dc3737 | ||
|
|
c54187b43a | ||
|
|
beb7b73d11 |
@@ -59,6 +59,10 @@ pub struct Args {
|
||||
#[arg(long, value_parser = parse_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)
|
||||
#[arg(skip)]
|
||||
pub spawn_point: Option<(f64, f64)>,
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::element_processing::*;
|
||||
use crate::ground::Ground;
|
||||
use crate::map_renderer;
|
||||
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")]
|
||||
use crate::telemetry::{send_log, LogLevel};
|
||||
use crate::world_editor::WorldEditor;
|
||||
@@ -266,33 +266,54 @@ pub fn generate_world(
|
||||
emit_gui_progress_update(100.0, "Done! World generation completed.");
|
||||
println!("{}", "Done! World generation completed.".green().bold());
|
||||
|
||||
// Generate top-down map preview silently in background after completion
|
||||
let world_path = args.path.clone();
|
||||
let bounds = (
|
||||
xzbbox.min_x(),
|
||||
xzbbox.max_x(),
|
||||
xzbbox.min_z(),
|
||||
xzbbox.max_z(),
|
||||
);
|
||||
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)
|
||||
}));
|
||||
// Generate top-down map preview:
|
||||
// - Always for GUI mode (non-blocking, runs in background)
|
||||
// - Only when --generate-map flag is set for CLI mode (blocking, waits for completion)
|
||||
#[cfg(feature = "gui")]
|
||||
let should_generate_map = true;
|
||||
#[cfg(not(feature = "gui"))]
|
||||
let should_generate_map = args.generate_map;
|
||||
|
||||
match result {
|
||||
Ok(Ok(_path)) => {
|
||||
// Notify the GUI that the map preview is ready
|
||||
crate::progress::emit_map_preview_ready();
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
eprintln!("Warning: Failed to generate map preview: {}", e);
|
||||
}
|
||||
Err(_) => {
|
||||
eprintln!("Warning: Map preview generation panicked unexpectedly");
|
||||
if should_generate_map {
|
||||
let world_path = args.path.clone();
|
||||
let bounds = (
|
||||
xzbbox.min_x(),
|
||||
xzbbox.max_x(),
|
||||
xzbbox.min_z(),
|
||||
xzbbox.max_z(),
|
||||
);
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -825,6 +825,7 @@ fn gui_start_generation(
|
||||
fillground: fillground_enabled,
|
||||
debug: false,
|
||||
timeout: Some(std::time::Duration::from_secs(floodfill_timeout)),
|
||||
generate_map: true,
|
||||
spawn_point,
|
||||
};
|
||||
|
||||
@@ -876,7 +877,6 @@ fn gui_start_generation(
|
||||
&mut xzbbox,
|
||||
&mut ground,
|
||||
);
|
||||
send_log(LogLevel::Info, "Map transformation completed.");
|
||||
|
||||
let _ = data_processing::generate_world(
|
||||
parsed_elements,
|
||||
|
||||
@@ -37,6 +37,7 @@ mod gui;
|
||||
mod progress {
|
||||
pub fn emit_gui_error(_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 {
|
||||
false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user