]> git.lizzy.rs Git - mt_client.git/blob - src/main.rs
Basic map rendering
[mt_client.git] / src / main.rs
1 mod gfx;
2 mod net;
3
4 use cgmath::{Deg, Point3};
5 use std::collections::HashMap;
6 use tokio::sync::mpsc;
7
8 #[derive(Debug, Clone)]
9 pub enum GfxEvent {
10     Close,
11     Media(HashMap<String, Vec<u8>>, bool),
12     NodeDefs(HashMap<u16, mt_net::NodeDef>),
13     MapBlock(Point3<i16>, Box<mt_net::MapBlock>),
14     PlayerPos(Point3<f32>, Deg<f32>, Deg<f32>),
15 }
16
17 #[derive(Debug, Clone)]
18 pub enum NetEvent {
19     PlayerPos(Point3<f32>, Deg<f32>, Deg<f32>),
20     Ready,
21 }
22
23 fn main() {
24     println!(include_str!("../assets/ascii-art.txt"));
25     println!("Early WIP. Expext breakage. Trans rights <3");
26
27     let (net_tx, net_rx) = mpsc::unbounded_channel();
28     let event_loop = winit::event_loop::EventLoopBuilder::<GfxEvent>::with_user_event().build();
29     let event_loop_proxy = event_loop.create_proxy();
30
31     let runtime = tokio::runtime::Builder::new_multi_thread()
32         .enable_io()
33         .enable_time()
34         .thread_name("network")
35         .build()
36         .unwrap();
37
38     let net_thread = runtime.spawn(net::run(event_loop_proxy, net_rx));
39
40     // graphics code is pseudo async: the winit event loop is blocking
41     // so we can't really use async capabilities
42     futures::executor::block_on(gfx::run(event_loop, net_tx));
43
44     // wait for net to finish
45     runtime.block_on(net_thread).unwrap();
46 }