diff options
author | metamuffin <metamuffin@disroot.org> | 2024-09-21 18:25:01 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-09-21 18:25:01 +0200 |
commit | 22723935cea1d9e38df8402b332acbd7d27c8d44 (patch) | |
tree | 05191400f1cc39ccfeca124f6b3fcfd2ff793fc2 /server/registry/src/lobby.rs | |
parent | 362363b3fd1f1fbffe2a3f81d73e71939addd34b (diff) | |
download | hurrycurry-22723935cea1d9e38df8402b332acbd7d27c8d44.tar hurrycurry-22723935cea1d9e38df8402b332acbd7d27c8d44.tar.bz2 hurrycurry-22723935cea1d9e38df8402b332acbd7d27c8d44.tar.zst |
reg: circular arrangement
Diffstat (limited to 'server/registry/src/lobby.rs')
-rw-r--r-- | server/registry/src/lobby.rs | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/server/registry/src/lobby.rs b/server/registry/src/lobby.rs index f74dd48e..8b501c46 100644 --- a/server/registry/src/lobby.rs +++ b/server/registry/src/lobby.rs @@ -1,7 +1,7 @@ use crate::Registry; use anyhow::Result; use hurrycurry_protocol::{ - glam::{ivec2, IVec2, Vec2}, + glam::{ivec2, vec2, IVec2, Vec2}, movement::MovementBase, registry::Entry, Gamedata, PacketC, PacketS, PlayerID, TileIndex, VERSION, @@ -10,6 +10,7 @@ use log::{error, info, warn}; use rocket::futures::{SinkExt, StreamExt}; use std::{ collections::{HashMap, HashSet}, + f32::consts::PI, net::SocketAddr, sync::Arc, time::Instant, @@ -48,13 +49,20 @@ async fn handle_conn(sock: TcpStream, addr: SocketAddr, entries: &[Entry]) -> Re let sock = tokio_tungstenite::accept_async(sock).await?; info!("{addr} connected via websocket"); + let ecount = entries.len().max(2) as f32; + let radius = ecount * 5. / PI; + let portal_location = |i: usize| { + let t = i as f32 / ecount * PI * 2.; + vec2(t.sin() * radius, t.cos() * radius).round().as_ivec2() + }; + let mut tiles = HashMap::<IVec2, TileIndex>::new(); - for x in -5..5 + 5 * entries.len() as i32 { - for y in -5..5 { + let bounds = (radius + 5.).ceil() as i32; + for x in -bounds..bounds { + for y in -bounds..bounds { tiles.insert(ivec2(x, y), TileIndex(0)); } } - let portal_location = |i: usize| ivec2(i as i32 * 5 + 5, 0); for (i, _) in entries.iter().enumerate() { tiles.insert(portal_location(i), TileIndex(1)); } @@ -128,6 +136,13 @@ async fn handle_conn(sock: TcpStream, addr: SocketAddr, entries: &[Entry]) -> Re character, name, }); + for (i, e) in entries.iter().enumerate() { + out.push(PacketC::ServerHint { + position: Some(portal_location(i)), + message: Some(hurrycurry_protocol::Message::Text(e.name.clone())), + player: PlayerID(0), + }); + } joined = true; } PacketS::Leave { .. } if joined => { @@ -148,7 +163,11 @@ async fn handle_conn(sock: TcpStream, addr: SocketAddr, entries: &[Entry]) -> Re out.push(movement.movement_packet_c(player)); if !redirected { for (i, e) in entries.iter().enumerate() { - if movement.position.distance(portal_location(i).as_vec2()) < 0.5 { + if movement + .position + .distance(portal_location(i).as_vec2() + 0.5) + < 0.5 + { redirected = true; out.push(PacketC::Redirect { uri: e.address.clone(), |