Replace expect() with unwrap_or_else that logs the bind address and error via tracing before exiting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
58 lines
2.0 KiB
Rust
58 lines
2.0 KiB
Rust
// The Settled Reach - Simulation Server
|
|
// Entry point for standalone simulation binary
|
|
|
|
use bevy_app::prelude::*;
|
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
|
|
|
use settled_reach_server::bridge::tcp::TcpBridge;
|
|
use settled_reach_server::bridge::{BridgePlugin, BridgeResource, ServerRunning};
|
|
use settled_reach_server::simulation::movement::{PlayerCharacter, TilePosition, WalkabilityMap};
|
|
use settled_reach_server::simulation::SimulationPlugin;
|
|
|
|
fn main() {
|
|
// Initialize tracing subscriber for logging
|
|
tracing_subscriber::registry()
|
|
.with(
|
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| "settled_reach_server=debug".into()),
|
|
)
|
|
.with(tracing_subscriber::fmt::layer())
|
|
.init();
|
|
|
|
let addr = std::env::args()
|
|
.nth(1)
|
|
.or_else(|| std::env::var("SR_ADDR").ok())
|
|
.unwrap_or_else(|| "127.0.0.1:9876".to_string());
|
|
|
|
tracing::info!("The Settled Reach - Simulation Server starting");
|
|
tracing::info!("Waiting for client connection on {}", addr);
|
|
|
|
let bridge = TcpBridge::accept(&addr).unwrap_or_else(|e| {
|
|
tracing::error!("Failed to accept client connection on {}: {}", addr, e);
|
|
std::process::exit(1);
|
|
});
|
|
tracing::info!("Client connected, initializing simulation");
|
|
|
|
// Create the bevy App and add plugins
|
|
let mut app = App::new();
|
|
app.add_plugins(SimulationPlugin);
|
|
app.add_plugins(BridgePlugin);
|
|
app.insert_resource(BridgeResource::new(bridge));
|
|
app.insert_resource(WalkabilityMap::new(32, 32, 1));
|
|
app.world_mut()
|
|
.spawn((PlayerCharacter, TilePosition::new(16, 16, 0)));
|
|
|
|
tracing::info!("Simulation initialized, entering game loop");
|
|
|
|
// Game loop: run until client disconnects
|
|
loop {
|
|
app.update();
|
|
// Check ServerRunning resource
|
|
if !app.world().resource::<ServerRunning>().0 {
|
|
break;
|
|
}
|
|
}
|
|
|
|
tracing::info!("Simulation server shutting down");
|
|
}
|