2019-03-03 22:02:38 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
use log::info;
|
|
|
|
use client::{Input, Client, Event};
|
2019-04-10 17:23:27 +00:00
|
|
|
use common::{
|
|
|
|
comp,
|
|
|
|
clock::Clock,
|
|
|
|
};
|
2019-03-03 22:02:38 +00:00
|
|
|
|
|
|
|
const FPS: u64 = 60;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Init logging
|
|
|
|
pretty_env_logger::init();
|
|
|
|
|
|
|
|
info!("Starting chat-cli...");
|
|
|
|
|
|
|
|
// Set up an fps clock
|
|
|
|
let mut clock = Clock::new();
|
|
|
|
|
|
|
|
// Create client
|
2019-04-22 10:07:48 +00:00
|
|
|
let mut client = Client::new(([127, 0, 0, 1], 59003), 300)
|
2019-03-03 22:02:38 +00:00
|
|
|
.expect("Failed to create client instance");
|
|
|
|
|
2019-04-22 10:07:48 +00:00
|
|
|
client.register(comp::Player::new("test".to_string()));
|
|
|
|
|
2019-04-02 11:59:42 +00:00
|
|
|
client.send_chat("Hello!".to_string());
|
|
|
|
|
2019-03-03 22:02:38 +00:00
|
|
|
loop {
|
2019-03-05 00:00:11 +00:00
|
|
|
let events = match client.tick(Input::default(), clock.get_last_delta()) {
|
|
|
|
Ok(events) => events,
|
|
|
|
Err(err) => {
|
|
|
|
println!("Error: {:?}", err);
|
|
|
|
break;
|
|
|
|
},
|
|
|
|
};
|
2019-03-03 22:02:38 +00:00
|
|
|
|
|
|
|
for event in events {
|
|
|
|
match event {
|
|
|
|
Event::Chat(msg) => println!("[chat] {}", msg),
|
2019-04-23 12:28:45 +00:00
|
|
|
Event::Disconnect => {} // TODO
|
2019-03-03 22:02:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up the server after a tick
|
|
|
|
client.cleanup();
|
|
|
|
|
|
|
|
// Wait for the next tick
|
|
|
|
clock.tick(Duration::from_millis(1000 / FPS));
|
|
|
|
}
|
|
|
|
}
|