2019-01-30 12:11:34 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
use log::info;
|
2019-03-03 22:02:38 +00:00
|
|
|
use server::{Input, Event, Server};
|
2019-01-30 12:11:34 +00:00
|
|
|
use common::clock::Clock;
|
|
|
|
|
2019-03-05 00:00:11 +00:00
|
|
|
const TPS: u64 = 20;
|
2019-01-30 12:11:34 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Init logging
|
|
|
|
pretty_env_logger::init();
|
|
|
|
|
|
|
|
info!("Starting server-cli...");
|
|
|
|
|
|
|
|
// Set up an fps clock
|
|
|
|
let mut clock = Clock::new();
|
|
|
|
|
|
|
|
// Create server
|
2019-03-03 22:02:38 +00:00
|
|
|
let mut server = Server::new()
|
|
|
|
.expect("Failed to create server instance");
|
2019-01-30 12:11:34 +00:00
|
|
|
|
|
|
|
loop {
|
2019-03-03 22:02:38 +00:00
|
|
|
let events = server.tick(Input::default(), clock.get_last_delta())
|
2019-01-30 12:11:34 +00:00
|
|
|
.expect("Failed to tick server");
|
|
|
|
|
2019-03-03 22:02:38 +00:00
|
|
|
for event in events {
|
|
|
|
match event {
|
2019-03-05 18:42:42 +00:00
|
|
|
Event::ClientConnected { ecs_entity } => info!("Client connected!"),
|
|
|
|
Event::ClientDisconnected { ecs_entity } => info!("Client disconnected!"),
|
|
|
|
Event::Chat { ecs_entity, msg } => info!("[Client] {}", msg),
|
2019-03-03 22:02:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-30 12:11:34 +00:00
|
|
|
// Clean up the server after a tick
|
|
|
|
server.cleanup();
|
|
|
|
|
|
|
|
// Wait for the next tick
|
2019-03-05 00:00:11 +00:00
|
|
|
clock.tick(Duration::from_millis(1000 / TPS));
|
2019-01-30 12:11:34 +00:00
|
|
|
}
|
|
|
|
}
|