veloren/chat-cli/src/main.rs
timokoesters 5cb368dddc Fix chat-cli not compiling
Former-commit-id: b69c0e8208374af3eef0d996137a5e7ebbfe9a16
2019-04-23 14:28:45 +02:00

51 lines
1.1 KiB
Rust

use std::time::Duration;
use log::info;
use client::{Input, Client, Event};
use common::{
comp,
clock::Clock,
};
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
let mut client = Client::new(([127, 0, 0, 1], 59003), 300)
.expect("Failed to create client instance");
client.register(comp::Player::new("test".to_string()));
client.send_chat("Hello!".to_string());
loop {
let events = match client.tick(Input::default(), clock.get_last_delta()) {
Ok(events) => events,
Err(err) => {
println!("Error: {:?}", err);
break;
},
};
for event in events {
match event {
Event::Chat(msg) => println!("[chat] {}", msg),
Event::Disconnect => {} // TODO
}
}
// Clean up the server after a tick
client.cleanup();
// Wait for the next tick
clock.tick(Duration::from_millis(1000 / FPS));
}
}