From 844bd3db17f24be87289cd0f7d638d71e9541cd5 Mon Sep 17 00:00:00 2001 From: ghostly_zsh Date: Sun, 23 Mar 2025 14:31:35 -0500 Subject: [PATCH] multiple players works --- crates/client/src/assets/venus.svg | 180 +++++++++++++++++++++-- crates/client/src/networking/mod.rs | 44 +++++- crates/client/src/rendering/mod.rs | 2 +- crates/common/src/packet.rs | 3 + crates/server/src/player/client_login.rs | 8 + 5 files changed, 216 insertions(+), 21 deletions(-) diff --git a/crates/client/src/assets/venus.svg b/crates/client/src/assets/venus.svg index f398d61651aa2c43451fdb9b249b00cb283bdc63..491408b66e6e6a1ff03cfbcb800684cbea8f9e6e 100644 --- a/crates/client/src/assets/venus.svg +++ b/crates/client/src/assets/venus.svg @@ -24,12 +24,12 @@ inkscape:deskcolor="#505050" inkscape:document-units="mm" inkscape:zoom="0.046932044" - inkscape:cx="4634.3603" - inkscape:cy="5699.7305" - inkscape:window-width="1272" - inkscape:window-height="1414" - inkscape:window-x="1281" - inkscape:window-y="19" + inkscape:cx="639.22211" + inkscape:cy="5998.0341" + inkscape:window-width="1910" + inkscape:window-height="1046" + inkscape:window-x="4" + inkscape:window-y="28" inkscape:window-maximized="1" inkscape:current-layer="layer1" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/crates/client/src/networking/mod.rs b/crates/client/src/networking/mod.rs index c267da5de520ad5b7c59c592786931820fa1ce4a..94ede9d312edce6e49c253c08833f2d56e7f71df 100644 --- a/crates/client/src/networking/mod.rs +++ b/crates/client/src/networking/mod.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use bevy_ecs::{entity::Entity, event::Events, query::With, world::World}; +use bevy_ecs::{entity::Entity, event::Events, query::{QuerySingleError, With}, world::World}; use nalgebra::{Rotation2, Scale2, Scale3, Translation3}; use starkingdoms_common::{packet::Packet, PartType, PlanetType}; @@ -23,11 +23,33 @@ pub fn process_packets( let mut recv_cursor = recv_packet_events.get_cursor(); for recv in recv_cursor.read(&recv_packet_events) { match &recv.0 { - SpawnPlayer { id, username } => { + LoginResponse { id } => { let mut player_query = world.query_filtered::>(); let entity = player_query.single(world); world.entity_mut(entity).insert(ServerId(*id)); } + PlayerList { players } => { // existing players + // username sync, eventually + for player in players { + world.spawn((Transform { + translation: Translation3::new(0.0, 0.0, 0.0), + rotation: Rotation2::new(0.0), + scale: Scale3::new(25.0, 25.0, 1.0), + }, Texture { + name: "hearty.svg".to_string(), + }, ServerId(player.0), Part)); + } + } + SpawnPlayer { id, username } => { + // username sync, eventually + world.spawn((Transform { + translation: Translation3::new(0.0, 0.0, 0.0), + rotation: Rotation2::new(0.0), + scale: Scale3::new(25.0, 25.0, 1.0), + }, Texture { + name: "hearty.svg".to_string(), + }, ServerId(*id), Part)); + } SpawnPart { id, part } => { use PartType::*; world.spawn((Transform { @@ -49,7 +71,17 @@ pub fn process_packets( for (id, part) in parts { if part.part_type == PartType::Hearty { let mut player_query = world.query_filtered::<&ServerId, With>(); - let server_id = player_query.single(world); + let server_id = match player_query.get_single(world) { + Ok(player) => player, + Err(e) => match e { + QuerySingleError::NoEntities(s) => { + continue; + } + QuerySingleError::MultipleEntities(s) => { + panic!("There should never multiple players marked as players"); + } + } + }; if server_id.0 == *id { let mut camera = world.resource_mut::(); camera.x = -part.transform.x; @@ -91,13 +123,13 @@ pub fn process_packets( PlanetType::Pluto => "pluto.svg",*/ PlanetType::Sun => "sun.svg", PlanetType::Mercury => "moon.svg", - PlanetType::Venus => "mars.svg", + PlanetType::Venus => "venus.svg", PlanetType::Earth => "earth.svg", PlanetType::Moon => "moon.svg", PlanetType::Mars => "mars.svg", PlanetType::Jupiter => "sun.svg", - PlanetType::Saturn => "moon.svg", - PlanetType::Uranus => "sun.svg", + PlanetType::Saturn => "saturn.svg", + PlanetType::Uranus => "venus.svg", PlanetType::Neptune => "mars.svg", PlanetType::Pluto => "earth.svg", }.to_string() diff --git a/crates/client/src/rendering/mod.rs b/crates/client/src/rendering/mod.rs index 590de82a79a0203c90ac37314c897b2d59ee9e27..caf7d0cd091f2317e1d420cb4e55f40690973cb4 100644 --- a/crates/client/src/rendering/mod.rs +++ b/crates/client/src/rendering/mod.rs @@ -201,7 +201,7 @@ impl ApplicationHandler for App { gl.enable_vertex_attrib_array(1); - gl.clear_color(0.7, 0.7, 0.7, 1.0); + gl.clear_color(0.1, 0.1, 0.1, 1.0); gl.viewport(0, 0, window.inner_size().width as i32, window.inner_size().height as i32); gl.enable(glow::BLEND); gl.blend_func(glow::SRC_ALPHA, glow::ONE_MINUS_SRC_ALPHA); diff --git a/crates/common/src/packet.rs b/crates/common/src/packet.rs index aaa753b3bd554ddcbffb8f1aef66bb986d896dfa..c524d85585dc17fb82680c9c7e11af4a43e86439 100644 --- a/crates/common/src/packet.rs +++ b/crates/common/src/packet.rs @@ -106,6 +106,9 @@ pub enum Packet { }, _SpecialDisconnect {}, // clientbound + LoginResponse { + id: u32, + }, SpawnPlayer { id: u32, username: String, diff --git a/crates/server/src/player/client_login.rs b/crates/server/src/player/client_login.rs index 2b01b261b159c8705f123463e05307cc2d26c890..3b098c06cd02dacfc570a51f81848ef71c40fb88 100644 --- a/crates/server/src/player/client_login.rs +++ b/crates/server/src/player/client_login.rs @@ -230,6 +230,14 @@ pub fn packet_stream( >, transform: Transform, ) { + // response in the handshake + let packet = Packet::LoginResponse { + id: index, + }; + event_queue.push(WsEvent::Send { + to: *from, + message: packet.into_message(), + }); // tell this player the planets let mut planets = Vec::new(); for (entity, planet_type, transform) in planet_query.iter() {