Skip to content

Commit

Permalink
Removed some usages of SmallVec
Browse files Browse the repository at this point in the history
  • Loading branch information
migomipo committed Jun 18, 2024
1 parent f483cb3 commit 20c6103
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions src/physics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -29,17 +30,18 @@ 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<f32>), 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));
}
}
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));
}
}

Expand Down Expand Up @@ -93,10 +95,7 @@ impl HQMServer {
}
}

let pucks_old_pos: SmallVec<[Point3<f32>; 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;
}

Expand All @@ -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();
Expand All @@ -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<f32>)],
rink: &Rink,
events: &mut PhysicsEventList,
physics_config: &PhysicsConfiguration,
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1122,9 +1122,9 @@ impl HQMServer {
found
}

pub fn player_search(&self, name: &str) -> smallvec::SmallVec<[(PlayerId, Rc<str>); 64]> {
pub fn player_search(&self, name: &str) -> Vec<(PlayerId, Rc<str>)> {
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()));
Expand Down

0 comments on commit 20c6103

Please sign in to comment.