A multiplayer VR framework w/voice chat

player updating stuff

phaz.uk fb5db721 44e6ece8

verified
Changed files
+51 -3
src
+2
src/net/client/mod.rs
··· 6 6 let mut tcp = TcpStream::connect("127.0.0.1:2603")?; 7 7 let udp = UdpSocket::bind("0.0.0.0:0")?; 8 8 9 + // TODO: Proper player networking controller 10 + 9 11 thread::spawn(move || { 10 12 let mut buf = [0; 1024]; 11 13
+3 -1
src/net/packet.rs
··· 3 3 packets::{ 4 4 link_udp::LinkUDP, 5 5 notify_connection_info::NotifyConnectionInfo, 6 - null::Null 6 + null::Null, update_server_position::UpdateServerPositions 7 7 } 8 8 }; 9 9 10 10 #[derive(Debug)] 11 11 pub enum PacketTypes{ 12 + UpdateServerPositions(UpdateServerPositions), 12 13 NotifyConnectionInfo(NotifyConnectionInfo), 13 14 LinkUDP(LinkUDP), 14 15 Null(Null) ··· 25 26 match id{ 26 27 0 => PacketTypes::NotifyConnectionInfo(NotifyConnectionInfo::from_buf(buf)), 27 28 1 => PacketTypes::LinkUDP(LinkUDP::from_buf(buf)), 29 + 2 => PacketTypes::UpdateServerPositions(UpdateServerPositions::from_buf(buf)), 28 30 _ => PacketTypes::Null(Null::from_buf(buf)) 29 31 } 30 32 }
+3 -1
src/net/packets/mod.rs
··· 1 1 pub mod notify_connection_info; 2 2 pub mod link_udp; 3 - pub mod null; 3 + pub mod update_server_position; 4 + 5 + pub mod null;
+34
src/net/packets/update_server_position.rs
··· 1 + use bevy::math::{Quat, Vec3}; 2 + 3 + use crate::net::{buffer::Buffer, packet::Packet}; 4 + 5 + #[derive(Debug)] 6 + pub struct UpdateServerPositions{ 7 + pub position: Vec3, 8 + pub rotation: Quat 9 + } 10 + 11 + impl Packet for UpdateServerPositions{ 12 + fn to_buf(&self) -> Buffer { 13 + let mut buf = Buffer::empty(); 14 + buf.set_u16(2); 15 + 16 + buf.set_f32(self.position.x); 17 + buf.set_f32(self.position.y); 18 + buf.set_f32(self.position.z); 19 + 20 + buf.set_f32(self.rotation.x); 21 + buf.set_f32(self.rotation.y); 22 + buf.set_f32(self.rotation.z); 23 + buf.set_f32(self.rotation.w); 24 + 25 + buf 26 + } 27 + 28 + fn from_buf(mut buf: Buffer) -> Self { 29 + Self { 30 + position: Vec3 { x: buf.get_f32(), y: buf.get_f32(), z: buf.get_f32() }, 31 + rotation: Quat::from_xyzw(buf.get_f32(), buf.get_f32(), buf.get_f32(), buf.get_f32()) 32 + } 33 + } 34 + }
+5 -1
src/net/server/mod.rs
··· 1 1 use std::{collections::HashMap, net::{SocketAddr, TcpListener, TcpStream, UdpSocket}, sync::mpsc::channel, thread}; 2 2 3 + use bevy::math::{Quat, Vec3, VectorSpace}; 4 + 3 5 use crate::net::{packet::{self, PacketTypes}, server::{connection::Connection, remote_player::RemotePlayer}}; 4 6 5 7 pub mod connection; ··· 52 54 NetServerCommand::CreateConnection(socket) => { 53 55 let conn = Connection::new(socket, sender_3.clone()); 54 56 let player = RemotePlayer { 55 - id: conn.id.clone() 57 + id: conn.id.clone(), 58 + position: Vec3::default(), 59 + rotation: Quat::default() 56 60 }; 57 61 58 62 println!("[INFO] Connected {}", conn.id);
+4
src/net/server/remote_player.rs
··· 1 + use bevy::math::{ Quat, Vec3 }; 2 + 1 3 pub struct RemotePlayer{ 2 4 pub id: String, 5 + pub position: Vec3, 6 + pub rotation: Quat 3 7 }