odyssey-server/src/main.rs

53 lines
1.1 KiB
Rust

mod components;
mod config;
mod network;
mod systems;
use crate::config::Settings;
use crate::network::{listen_websocket, NetworkManager};
use actix::prelude::*;
use env_logger::Env;
use shipyard::World;
use std::time::Duration;
// Minimum delay between updates, in milliseconds
const MIN_UPDATE_MS: u64 = 10;
struct Game {
world: World,
}
impl Actor for Game {
type Context = Context<Game>;
fn started(&mut self, ctx: &mut Self::Context) {
// Start update loop
ctx.run_interval(Duration::from_millis(MIN_UPDATE_MS), |game, _ctx| {
game.world.run_workload("update");
});
}
}
fn main() {
let env = Env::default().filter_or("LOG_LEVEL", "info");
env_logger::init_from_env(env);
let settings = Settings::new().unwrap();
let system = System::new("main");
Game::create(|_ctx| {
// Create world
let world = World::default();
// Create workload
world.add_workload("update").build();
Game { world }
});
NetworkManager::new(settings.bind).start();
system.run().unwrap();
}