48 lines
1.1 KiB
Rust
48 lines
1.1 KiB
Rust
mod components;
|
|
mod config;
|
|
mod game;
|
|
mod messages;
|
|
mod network;
|
|
mod systems;
|
|
|
|
use crate::config::Settings;
|
|
use crate::game::Game;
|
|
use crate::network::listen;
|
|
use async_std::sync::Arc;
|
|
use async_std::sync::RwLock;
|
|
use async_std::{sync::channel, task};
|
|
use env_logger::Env;
|
|
use std::time::Duration;
|
|
|
|
// Minimum delay between updates, in milliseconds
|
|
const MIN_UPDATE_MS: u64 = 10;
|
|
|
|
async fn run() {
|
|
let env = Env::default().filter_or("LOG_LEVEL", "info");
|
|
env_logger::init_from_env(env);
|
|
|
|
let settings = Settings::new().unwrap();
|
|
|
|
let (in_s, in_r) = channel(10);
|
|
let (out_s, out_r) = channel(10);
|
|
|
|
let game = Arc::new(RwLock::new(Game::new(out_s)));
|
|
|
|
let game_read_loop = game.clone();
|
|
task::spawn(Game::read_loop(game_read_loop, in_r));
|
|
|
|
task::spawn(async move {
|
|
loop {
|
|
let game = game.clone();
|
|
task::spawn(async move { game.read().await.update().expect("update failed") });
|
|
task::sleep(Duration::from_millis(MIN_UPDATE_MS)).await;
|
|
}
|
|
});
|
|
|
|
task::block_on(listen(settings.bind, in_s, out_r));
|
|
}
|
|
|
|
fn main() {
|
|
task::block_on(run());
|
|
}
|