aboutsummaryrefslogtreecommitdiff
path: root/client/src/client.rs
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/client.rs')
-rw-r--r--client/src/client.rs35
1 files changed, 23 insertions, 12 deletions
diff --git a/client/src/client.rs b/client/src/client.rs
index 9f23c41..3ebccca 100644
--- a/client/src/client.rs
+++ b/client/src/client.rs
@@ -21,26 +21,37 @@ use std::{
io::Write,
net::{IpAddr, Ipv4Addr},
path::PathBuf,
+ sync::mpsc::{Receiver, Sender, channel},
+ thread::spawn,
};
use twsnap::{Snap, SnapObj};
-pub struct Client {}
+pub struct Client {
+ pub incoming: Receiver<(i32, Snap)>,
+}
impl Client {
pub fn new() -> Result<Self> {
- let mut sloop = SocketLoop::client();
- sloop.connect(Addr {
- ip: IpAddr::V4(Ipv4Addr::LOCALHOST),
- port: 8303,
- });
- sloop.run(ClientNetwork {
- state: NetworkState::New,
+ let (incoming_tx, incoming_rx) = channel();
+ spawn(move || {
+ let mut sloop = SocketLoop::client();
+ sloop.connect(Addr {
+ ip: IpAddr::V4(Ipv4Addr::LOCALHOST),
+ port: 8303,
+ });
+ sloop.run(ClientNetwork {
+ state: NetworkState::New,
+ events: incoming_tx,
+ });
});
- Ok(Self {})
+ Ok(Self {
+ incoming: incoming_rx,
+ })
}
}
pub struct ClientNetwork {
state: NetworkState,
+ events: Sender<(i32, Snap)>,
}
enum NetworkState {
New,
@@ -117,8 +128,8 @@ impl<L: Loop> Application<L> for ClientNetwork {
country: -1,
skin: b"limekittygirl",
use_custom_color: true,
- color_body: 0xFF00FF,
- color_feet: 0x550055,
+ color_body: 0xFF00FFFFu32 as i32,
+ color_feet: 0x550055FFu32 as i32,
});
self.state = NetworkState::Ingame {
snap: Snap::default(),
@@ -146,7 +157,7 @@ impl<L: Loop> Application<L> for ClientNetwork {
})
.collect::<Vec<_>>();
snap.process_next(objs.iter());
- debug!("{snap:#?}");
+ self.events.send((p.tick, snap.clone())).unwrap();
}
}
}