Add design persistence, world rendering, metrics overlay and logs
M3: STL/OBJ import with mesh validation, mass/COM/inertia, material database, RON scene with content-addressed blobs and v0->v1 migration. M4: deterministic heightmap terrain, trimesh colliders, wgpu renderer with instancing and depth, winit app with 1 kHz physics, fly camera, on-screen metrics overlay and per-frame CSV/dev logs. Docs: UI, logging, network and headless CLI plans.
This commit is contained in:
parent
878d144b77
commit
190ef9cc4b
111 changed files with 14801 additions and 63 deletions
|
|
@ -1 +1,101 @@
|
|||
//! fabrilis-app :: runtime - stub (see docs/ARCHITECTURE.md)
|
||||
//! winit application loop for the M4c vertical slice.
|
||||
|
||||
mod application;
|
||||
mod camera;
|
||||
mod config;
|
||||
mod devlog;
|
||||
mod error;
|
||||
mod gpu;
|
||||
mod metrics;
|
||||
mod scene;
|
||||
mod sim;
|
||||
|
||||
pub use error::AppError;
|
||||
|
||||
use devlog::DevLog;
|
||||
use devlog::startup::StartupInfo;
|
||||
use gpu::WindowRenderer;
|
||||
use scene::View;
|
||||
use winit::window::Window;
|
||||
|
||||
use config::Config;
|
||||
use metrics::CsvLog;
|
||||
|
||||
/// Runs the window loop until the user closes the window or presses Escape.
|
||||
pub fn run() -> Result<(), AppError> {
|
||||
application::run()
|
||||
}
|
||||
|
||||
/// Parses the flags and environment, printing usage or the error.
|
||||
fn parse_config() -> Config {
|
||||
match Config::from_process() {
|
||||
Ok(config::Outcome::Run(config)) => config,
|
||||
Ok(config::Outcome::Help) => {
|
||||
print!("{}", config::USAGE);
|
||||
std::process::exit(0);
|
||||
}
|
||||
Err(error) => {
|
||||
eprintln!("fabrilis: {error}");
|
||||
eprintln!("{}", config::USAGE);
|
||||
std::process::exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens the metrics CSV when a path was configured.
|
||||
fn open_csv(config: &Config) -> Result<Option<CsvLog>, AppError> {
|
||||
let Some(path) = &config.metrics_log else {
|
||||
return Ok(None);
|
||||
};
|
||||
CsvLog::open(path, config.append)
|
||||
.map(Some)
|
||||
.map_err(|error| AppError::Log(format!("{}: {error}", path.display())))
|
||||
}
|
||||
|
||||
/// Writes the startup banner, reporting a write failure without stopping the app.
|
||||
fn log_startup(
|
||||
dev: Option<&mut DevLog>,
|
||||
config: &Config,
|
||||
view: &View,
|
||||
renderer: &WindowRenderer,
|
||||
window: &Window,
|
||||
) {
|
||||
let Some(dev) = dev else {
|
||||
return;
|
||||
};
|
||||
let gpu = renderer.info();
|
||||
let size = window.inner_size();
|
||||
let metrics_path = config
|
||||
.metrics_log
|
||||
.as_ref()
|
||||
.map(|path| path.display().to_string());
|
||||
let log_path = config.log.as_ref().map(|path| path.display().to_string());
|
||||
let info = StartupInfo {
|
||||
window: (size.width, size.height),
|
||||
scale: window.scale_factor(),
|
||||
terrain: view.terrain_config,
|
||||
boxes: sim::DROPS.len(),
|
||||
box_mass_kg: sim::BOX_MASS,
|
||||
box_size_m: sim::BOX_SIZE,
|
||||
eye: view.camera.eye(),
|
||||
target: view.camera.target(),
|
||||
adapter: &gpu.adapter,
|
||||
driver: &gpu.driver,
|
||||
surface: &gpu.surface,
|
||||
metrics_path: metrics_path.as_deref(),
|
||||
log_path: log_path.as_deref(),
|
||||
dev: config.dev,
|
||||
append: config.append,
|
||||
};
|
||||
if let Err(error) = devlog::startup::write(dev, &info) {
|
||||
eprintln!("fabrilis: dev log write failed: {error}");
|
||||
}
|
||||
}
|
||||
|
||||
fn aspect(size: winit::dpi::PhysicalSize<u32>) -> f32 {
|
||||
if size.height == 0 {
|
||||
1.0
|
||||
} else {
|
||||
size.width as f32 / size.height as f32
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue