Skip to content

Instantly share code, notes, and snippets.

@TuckerBMorgan
Last active March 25, 2022 22:51
Show Gist options
  • Select an option

  • Save TuckerBMorgan/298b92735f112b45eaf1a8549796e0df to your computer and use it in GitHub Desktop.

Select an option

Save TuckerBMorgan/298b92735f112b45eaf1a8549796e0df to your computer and use it in GitHub Desktop.
Working on stuff
pub const INPUT_WINDOW_MESSAGE : usize = PLAYER_MESSAGE_TYPE_BASE + 1;
#[derive(Encode, Decode, PartialEq, Debug)]
#[repr(C)]
pub struct InputWindowMessage {
pub message_type: usize,
pub input_messages: Vec<u8>
}
impl InputWindowMessage {
pub fn new(inputs: Vec<u8>) -> InputWindowMessage {
InputWindowMessage {
message_type: INPUT_WINDOW_MESSAGE,
input_messages: inputs
}
}
}
pub const AWK_FRAME_MESSAGE : usize = INPUT_WINDOW_MESSAGE + 1;
#[derive(Encode, Decode, PartialEq, Debug)]
#[repr(C)]
pub struct AwkFrameMessage {
pub message_type: usize,
pub frame_number: usize
}
impl AwkFrameMessage {
pub fn new(frame_number: usize) -> AwkFrameMessage {
AwkFrameMessage {
message_type: AWK_FRAME_MESSAGE,
frame_number
}
}
}
pub fn handle_player_messsage() {
let buf = &mut buf[..amt];
match msg.message_type {
AWK_FRAME_MESSAGE => {
if msg.frame_number > self.last_awked_game_state {
println!("Player 1 awked frame number {}", msg.frame_number);
self.last_awked_game_state = msg.frame_number;
}
},
INPUT_WINDOW_MESSAGE => {
println!("Player 1 just sent input message {}", msg.data);
let (msg, len) : (AwkFrameMessage, usize) = bincode::decode_from_slice(&buf[..], config).unwrap();
/*
self.inputs.push(PlayerInput::new(msg.data));
if self.inputs.len() > NUMBER_OF_PLAYER_INPUTS_IN_BUFFER {
self.inputs.pop();
}
*/
},
_ => {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment