2019-01-30 12:11:34 +00:00
|
|
|
use common::clock::Clock;
|
2019-07-23 23:44:33 +00:00
|
|
|
use heaptrack::track_mem;
|
2019-04-29 20:37:19 +00:00
|
|
|
use log::info;
|
2019-06-29 16:41:26 +00:00
|
|
|
use server::{Event, Input, Server, ServerSettings};
|
2019-04-29 20:37:19 +00:00
|
|
|
use std::time::Duration;
|
2019-01-30 12:11:34 +00:00
|
|
|
|
2019-07-23 23:44:33 +00:00
|
|
|
track_mem!();
|
|
|
|
|
2019-03-19 19:53:35 +00:00
|
|
|
const TPS: u64 = 30;
|
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
|
2019-07-01 20:42:43 +00:00
|
|
|
let mut clock = Clock::start();
|
2019-07-04 09:38:17 +00:00
|
|
|
|
2019-06-29 16:41:26 +00:00
|
|
|
// Load settings
|
|
|
|
let settings = ServerSettings::load();
|
2019-01-30 12:11:34 +00:00
|
|
|
|
|
|
|
// Create server
|
2019-06-29 16:41:26 +00:00
|
|
|
let mut server = Server::new(settings).expect("Failed to create server instance!");
|
2019-01-30 12:11:34 +00:00
|
|
|
|
|
|
|
loop {
|
2019-04-29 20:37:19 +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-06-06 14:48:41 +00:00
|
|
|
Event::ClientConnected { entity: _ } => info!("Client connected!"),
|
|
|
|
Event::ClientDisconnected { entity: _ } => info!("Client disconnected!"),
|
|
|
|
Event::Chat { entity: _, msg } => info!("[Client] {}", msg),
|
2019-03-03 22:02:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// Clean up the server after a tick.
|
2019-01-30 12:11:34 +00:00
|
|
|
server.cleanup();
|
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|