1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-04-21 23:17:45 +00:00

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.
This commit is contained in:
Joshua Goins 2025-04-14 16:34:30 -04:00
parent ba91ca4291
commit 01cab0f3a1

View file

@ -131,6 +131,15 @@ async fn main_loop(mut recv: Receiver<ToServer>) -> Result<(), std::io::Error> {
} }
} }
ToServer::ActorMoved(from_id, actor_id, position, rotation) => { 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 { for (id, handle) in &mut data.clients {
let id = *id; 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 // tell the server we loaded into the zone, so it can start sending us acors
connection.handle.send(ToServer::ZoneLoaded(connection.id)).await; connection.handle.send(ToServer::ZoneLoaded(connection.id)).await;
let common = connection.get_player_common_spawn(exit_position, exit_rotation);
// send player spawn // send player spawn
{ {
let ipc = ServerZoneIpcSegment { let ipc = ServerZoneIpcSegment {
@ -400,7 +411,7 @@ async fn client_loop(
home_world_id: config.world.world_id, home_world_id: config.world.world_id,
gm_rank: GameMasterRank::Debug, gm_rank: GameMasterRank::Debug,
online_status: OnlineStatus::GameMasterBlue, online_status: OnlineStatus::GameMasterBlue,
common: connection.get_player_common_spawn(exit_position, exit_rotation), common: common.clone(),
..Default::default() ..Default::default()
}), }),
..Default::default() ..Default::default()
@ -440,7 +451,7 @@ async fn client_loop(
exit_rotation = None; exit_rotation = None;
// tell the other players we're here // 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 { ClientZoneIpcData::Unk1 {
category, .. category, ..