diff --git a/Cargo.lock b/Cargo.lock index a66b275..30efbc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,6 +71,12 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "async-stream" version = "0.3.5" @@ -890,6 +896,7 @@ version = "2.0.1" dependencies = [ "anyhow", "arraydeque", + "arrayvec", "async-stream", "bytes", "cached", diff --git a/Cargo.toml b/Cargo.toml index 8908d0c..53f171f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ tracing = "0.1" tracing-subscriber = {version="0.3", features = ["parking_lot"]} tracing-appender = "0.2" chrono = "0.4" +arrayvec = "0.7.4" smallvec = { version = "1.11", features = ["union", "const_generics"]} systemctl = "0.3.1" futures = "0.3" diff --git a/config.ini b/config.ini index 3c86b86..407aaff 100644 --- a/config.ini +++ b/config.ini @@ -9,7 +9,7 @@ force_team_size_parity=false ; If this option is true, a player can't join a team that already has more players than the other team player_max=15 ; Set a password to enable admin mode -; password=12345 +password=12345 welcome=Welcome message 1\nWelcome message 2 ; service=hqm@config ; If you use a Linux- and systemd-based system, you can restart the service with the in-game command /serverrestart diff --git a/src/physics.rs b/src/physics.rs index 2c229d8..3e240a2 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -5,6 +5,7 @@ use crate::game::{ }; use crate::game::{PhysicsEvent, PlayerId}; use crate::server::{HQMServer, PlayerListExt}; +use arrayvec::ArrayVec; use nalgebra::{vector, Point3, Rotation3, Unit, Vector2, Vector3}; use smallvec::SmallVec; use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_8, PI}; @@ -29,9 +30,9 @@ type CollisionList = SmallVec<[Collision; 32]>; impl HQMServer { pub(crate) fn simulate_step(&mut self) -> PhysicsEventList { let mut events: PhysicsEventList = SmallVec::new(); - let mut players: SmallVec<[(PlayerId, &mut SkaterObject, &mut PlayerInput); 32]> = - SmallVec::new(); - let mut pucks: SmallVec<[(usize, &mut Puck); 32]> = SmallVec::new(); + let mut players: ArrayVec<(PlayerId, &mut SkaterObject, &mut PlayerInput), 32> = + ArrayVec::new(); + let mut pucks: ArrayVec<(usize, &mut Puck, Point3), 32> = ArrayVec::new(); for (i, p) in self.state.players.iter_players_mut() { if let Some((_, skater, _)) = &mut p.object { players.push((i, skater, &mut p.input)); @@ -39,7 +40,8 @@ impl HQMServer { } for (i, p) in self.state.pucks.iter_mut().enumerate() { if let Some(p) = p { - pucks.push((i, p)); + let old_pos = p.body.pos.clone(); + pucks.push((i, p, old_pos)); } } @@ -93,10 +95,7 @@ impl HQMServer { } } - let pucks_old_pos: SmallVec<[Point3; 32]> = - pucks.iter().map(|x| x.1.body.pos.clone()).collect(); - - for (_, puck) in pucks.iter_mut() { + for (_, puck, _) in pucks.iter_mut() { puck.body.linear_velocity[1] -= self.physics_config.gravity; } @@ -108,7 +107,7 @@ impl HQMServer { &self.physics_config, ); - for ((puck_index, puck), old_puck_pos) in pucks.iter_mut().zip(pucks_old_pos.iter()) { + for (puck_index, puck, old_puck_pos) in pucks.iter_mut() { if puck.body.linear_velocity.norm() > 1.0 / 65536.0 { let scale = puck.body.linear_velocity.norm().powi(2) * 0.125 * 0.125; let scaled = scale * puck.body.linear_velocity.normalize(); @@ -132,7 +131,7 @@ impl HQMServer { fn update_sticks_and_pucks( players: &mut [(PlayerId, &mut SkaterObject, &mut PlayerInput)], - pucks: &mut [(usize, &mut Puck)], + pucks: &mut [(usize, &mut Puck, Point3)], rink: &Rink, events: &mut PhysicsEventList, physics_config: &PhysicsConfiguration, @@ -141,7 +140,7 @@ fn update_sticks_and_pucks( for (_, player, _) in players.iter_mut() { player.stick_pos += 0.1 * player.stick_velocity; } - for (puck_index, puck) in pucks.iter_mut() { + for (puck_index, puck, _) in pucks.iter_mut() { puck.body.pos += 0.1 * puck.body.linear_velocity; let puck_linear_velocity_before = puck.body.linear_velocity.clone_owned(); @@ -549,7 +548,7 @@ fn apply_collisions( ) { for _ in 0..16 { let original_ball_velocities = - SmallVec::<[_; 32]>::from_iter(players.iter().map(|(_, skater, _)| { + ArrayVec::<_, 32>::from_iter(players.iter().map(|(_, skater, _)| { SmallVec::<[_; 8]>::from_iter( skater .collision_balls diff --git a/src/server.rs b/src/server.rs index 0b8bcd6..0f9e53e 100644 --- a/src/server.rs +++ b/src/server.rs @@ -230,7 +230,7 @@ impl HQMServerState { self.replay_queue.clear(); self.saved_history.clear(); - let mut messages = smallvec::SmallVec::<[(HQMMessage, bool, bool); 32]>::new(); + let mut messages = Vec::new(); for (player_index, (_, p)) in self.players.iter_mut().enumerate() { let player_index = PlayerIndex(player_index); if let Some(player) = p { @@ -1122,9 +1122,9 @@ impl HQMServer { found } - pub fn player_search(&self, name: &str) -> smallvec::SmallVec<[(PlayerId, Rc); 64]> { + pub fn player_search(&self, name: &str) -> Vec<(PlayerId, Rc)> { let name = name.to_lowercase(); - let mut found = smallvec::SmallVec::<[_; 64]>::new(); + let mut found = Vec::new(); for (player_index, player) in self.state.players.iter_players() { if player.player_name.to_lowercase().contains(&name) { found.push((player_index, player.player_name.clone()));