From 01cab0f3a174909aa2c6d289c1128160d8deb321 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 14 Apr 2025 16:34:30 -0400 Subject: [PATCH] Send position and rotation on initial spawn, and keep it updated Now other players won't spawn at 0,0,0 (which is wrong, almost nobody is there) and will reflect their actual position/rotation when spawned in. This is also updated on the server - so new clients are aware of your last position/rotation - and can be used later for visibility checks. --- src/bin/kawari-world.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/bin/kawari-world.rs b/src/bin/kawari-world.rs index 7612749..e1e7954 100644 --- a/src/bin/kawari-world.rs +++ b/src/bin/kawari-world.rs @@ -131,6 +131,15 @@ async fn main_loop(mut recv: Receiver) -> Result<(), std::io::Error> { } } ToServer::ActorMoved(from_id, actor_id, position, rotation) => { + if let Some((_, common)) = data + .actors + .iter_mut() + .find(|actor| *actor.0 == ObjectId(actor_id)) + { + common.pos = position; + common.rotation = rotation; + } + for (id, handle) in &mut data.clients { let id = *id; @@ -388,6 +397,8 @@ async fn client_loop( // tell the server we loaded into the zone, so it can start sending us acors connection.handle.send(ToServer::ZoneLoaded(connection.id)).await; + let common = connection.get_player_common_spawn(exit_position, exit_rotation); + // send player spawn { let ipc = ServerZoneIpcSegment { @@ -400,7 +411,7 @@ async fn client_loop( home_world_id: config.world.world_id, gm_rank: GameMasterRank::Debug, online_status: OnlineStatus::GameMasterBlue, - common: connection.get_player_common_spawn(exit_position, exit_rotation), + common: common.clone(), ..Default::default() }), ..Default::default() @@ -440,7 +451,7 @@ async fn client_loop( exit_rotation = None; // tell the other players we're here - connection.handle.send(ToServer::ActorSpawned(connection.id, Actor { id: ObjectId(connection.player_data.actor_id), hp: 100, spawn_index: 0 }, connection.get_player_common_spawn(None, None))).await; + connection.handle.send(ToServer::ActorSpawned(connection.id, Actor { id: ObjectId(connection.player_data.actor_id), hp: 100, spawn_index: 0 }, common)).await; } ClientZoneIpcData::Unk1 { category, ..