diff options
author | metamuffin <yvchraiqi@protonmail.com> | 2022-06-09 11:45:05 +0200 |
---|---|---|
committer | metamuffin <yvchraiqi@protonmail.com> | 2022-06-09 11:45:05 +0200 |
commit | f86dc6281977e11bdcdfa28557a90bacb9bb42aa (patch) | |
tree | 230719bad80c51ea907ba64401ccd2eee4cd4886 /client/src | |
parent | b71d1e8272e35aeb6b186740b604dfb26f316827 (diff) | |
download | twclient-f86dc6281977e11bdcdfa28557a90bacb9bb42aa.tar twclient-f86dc6281977e11bdcdfa28557a90bacb9bb42aa.tar.bz2 twclient-f86dc6281977e11bdcdfa28557a90bacb9bb42aa.tar.zst |
input
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/client/mod.rs | 68 |
1 files changed, 17 insertions, 51 deletions
diff --git a/client/src/client/mod.rs b/client/src/client/mod.rs index c72cc0b..c779317 100644 --- a/client/src/client/mod.rs +++ b/client/src/client/mod.rs @@ -1,7 +1,6 @@ pub mod helper; use self::helper::get_map_path; - use super::gamenet::{ enums::{Team, VERSION}, msg::{ @@ -11,7 +10,7 @@ use super::gamenet::{ system::{Ready, RequestMapData}, Game, System, SystemOrGame, }, - snap_obj::{obj_size, PlayerInput}, + snap_obj::obj_size, SnapObj, }; use crate::client::helper::{check_dummy_map, hexdump, WarnSnap}; @@ -38,6 +37,8 @@ use std::{ use tempfile::{NamedTempFile, NamedTempFileOptions}; use warn::Log; +pub use super::gamenet::snap_obj::PlayerInput; + pub struct ClientConfig { pub nick: String, pub clan: String, @@ -55,7 +56,9 @@ pub struct Client { state: ClientState, download: Option<Download>, - _interface_receive: Receiver<ClientMesgIn>, + input: PlayerInput, + + interface_receive: Receiver<ClientMesgIn>, interface_send: Sender<ClientMesgOut>, } @@ -64,7 +67,9 @@ pub struct ClientInterface { pub receive: Receiver<ClientMesgOut>, } -pub enum ClientMesgIn {} +pub enum ClientMesgIn { + Input(PlayerInput), +} pub enum ClientMesgOut { MapChange { name: String, crc: i32 }, Snaps(Vec<(u16, SnapObj)>), @@ -110,8 +115,9 @@ impl Client { dummy_map: false, state: ClientState::Connection, download: None, - _interface_receive: b, + interface_receive: b, interface_send: c, + input: PlayerInput::default(), }, ClientInterface { receive: d, @@ -133,6 +139,11 @@ impl<'a, L: Loop> Application<L> for Client { warn!("exiting peer {}", self.pid); evloop.disconnect(self.pid, b"error"); } + for m in self.interface_receive.try_iter() { + match m { + ClientMesgIn::Input(i) => self.input = i, + } + } } fn on_packet(&mut self, evloop: &mut L, chunk: Chunk) { let pid = chunk.pid; @@ -227,7 +238,6 @@ impl<'a, L: Loop> Application<L> for Client { } System::Snap(_) | System::SnapEmpty(_) | System::SnapSingle(_) => { self.num_snaps_since_reset += 1; - let mut input = PlayerInput::default(); { let res = match *msg { System::Snap(s) => self.snaps.snap(&mut Log, obj_size, s), @@ -253,50 +263,6 @@ impl<'a, L: Loop> Application<L> for Client { self.interface_send .send(ClientMesgOut::Snaps(snaps.clone())) .unwrap(); - - let client_id = snaps - .iter() - .filter_map(|(_id, i)| { - if let SnapObj::PlayerInfo(p) = i { - if p.local != 0 { - Some(p.client_id) - } else { - None - } - } else { - None - } - }) - .next() - .unwrap_or(1 << 15) - as u16; - - let mut target_position = None; - let mut my_position = (0, 0); - for (id, snap) in &snaps { - match snap { - SnapObj::Character(c) => { - let c = c.character_core; - if *id == client_id { - my_position = (c.x, c.y) - } else if c.hook_state != 0 { - target_position = Some((c.x, c.y)) - } - } - _ => {} - } - } - if let Some(target) = target_position { - if target.0 < my_position.0 { - input.direction = -1; - } - if target.0 > my_position.0 { - input.direction = 1; - } - if target.1 - 16 < my_position.1 { - input.jump = 1; - } - } } Ok(None) => { self.num_snaps_since_reset -= 1; @@ -314,7 +280,7 @@ impl<'a, L: Loop> Application<L> for Client { ack_snapshot: tick, intended_tick: tick, input_size: mem::size_of::<PlayerInput>().assert_i32(), - input, + input: self.input, }, ); } |