that's multiplayer. that counts
parent
2135bb0f24
commit
06c173e6da
|
@ -24,50 +24,58 @@ async fn main () -> anyhow::Result <()> {
|
|||
|
||||
let connected_players = Arc::new (Mutex::new (vec! []));
|
||||
|
||||
use opengl_rust::timestep::TimeStep;
|
||||
|
||||
let mut player_seq = 0;
|
||||
let incoming_conn = incoming.next ().await.unwrap ();
|
||||
let new_conn = incoming_conn.await.unwrap ();
|
||||
println! (
|
||||
"[server] connection accepted: addr={}",
|
||||
new_conn.connection.remote_address ()
|
||||
);
|
||||
|
||||
let quinn::NewConnection {
|
||||
connection,
|
||||
mut datagrams,
|
||||
..
|
||||
} = new_conn;
|
||||
|
||||
{
|
||||
let mut guard = connected_players.lock ().await;
|
||||
guard.push (ConnectedPlayer {
|
||||
connection,
|
||||
cmd: NetworkCommand::default (),
|
||||
position: (32.0, 32.0),
|
||||
});
|
||||
}
|
||||
|
||||
// Read player commands
|
||||
{
|
||||
let player_seq = player_seq;
|
||||
let connected_players = Arc::clone (&connected_players);
|
||||
|
||||
tokio::spawn (async move {
|
||||
while let Some (Ok (datagram)) = datagrams.next ().await {
|
||||
let cmd: NetworkCommand = rmp_serde::from_slice (&datagram)?;
|
||||
let mut guard = connected_players.lock ().await;
|
||||
guard [player_seq].cmd = cmd;
|
||||
let mut player_seq = 0;
|
||||
|
||||
while let Some (incoming_conn) = incoming.next ().await {
|
||||
let new_conn = incoming_conn.await?;
|
||||
println! (
|
||||
"[server] connection accepted: addr={}",
|
||||
new_conn.connection.remote_address ()
|
||||
);
|
||||
|
||||
let quinn::NewConnection {
|
||||
connection,
|
||||
mut datagrams,
|
||||
..
|
||||
} = new_conn;
|
||||
|
||||
{
|
||||
let mut guard = connected_players.lock ().await;
|
||||
guard.push (ConnectedPlayer {
|
||||
connection,
|
||||
cmd: NetworkCommand::default (),
|
||||
position: (32.0, 32.0),
|
||||
});
|
||||
}
|
||||
|
||||
// Read player commands
|
||||
{
|
||||
let player_seq = player_seq;
|
||||
let connected_players = Arc::clone (&connected_players);
|
||||
|
||||
tokio::spawn (async move {
|
||||
while let Some (Ok (datagram)) = datagrams.next ().await {
|
||||
let cmd: NetworkCommand = rmp_serde::from_slice (&datagram)?;
|
||||
let mut guard = connected_players.lock ().await;
|
||||
guard [player_seq].cmd = cmd;
|
||||
}
|
||||
|
||||
Ok::<_, anyhow::Error> (())
|
||||
});
|
||||
}
|
||||
|
||||
player_seq += 1;
|
||||
}
|
||||
|
||||
Ok::<_, anyhow::Error> (())
|
||||
});
|
||||
}
|
||||
|
||||
player_seq += 1;
|
||||
|
||||
let mut time_step = TimeStep::new (120, 1000);
|
||||
let mut time_step = opengl_rust::timestep::TimeStep::new (120, 1000);
|
||||
let mut state = NetworkedState {
|
||||
positions: vec! [
|
||||
(32.0, 32.0),
|
||||
|
|
Loading…
Reference in New Issue