aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-12-18 21:01:36 +0100
committermetamuffin <metamuffin@disroot.org>2025-12-18 22:49:18 +0100
commit5cf50403fabbb3e79b771bc157d5a4c57c614570 (patch)
treeb6887878931212c8a35b8650af8527aa5a9f071c /server
parenteb9412a2847a199f04e74d8a17481b7d0c9e36a6 (diff)
downloadhurrycurry-5cf50403fabbb3e79b771bc157d5a4c57c614570.tar
hurrycurry-5cf50403fabbb3e79b771bc157d5a4c57c614570.tar.bz2
hurrycurry-5cf50403fabbb3e79b771bc157d5a4c57c614570.tar.zst
add benchmark to measure movement packet count
Diffstat (limited to 'server')
-rw-r--r--server/game-core/src/lib.rs4
-rw-r--r--server/src/benchmark.rs55
-rw-r--r--server/src/lib.rs1
-rw-r--r--server/src/main.rs10
-rw-r--r--server/src/server.rs7
5 files changed, 75 insertions, 2 deletions
diff --git a/server/game-core/src/lib.rs b/server/game-core/src/lib.rs
index ac0a8ded..8a0b1aa7 100644
--- a/server/game-core/src/lib.rs
+++ b/server/game-core/src/lib.rs
@@ -60,6 +60,8 @@ pub struct Player {
pub communicate_persist: Option<(Message, MessageTimeout)>,
pub movement: MovementBase,
+ pub movement_input_changed: bool,
+ pub movement_must_sync: bool,
}
#[derive(Default)]
@@ -105,6 +107,8 @@ impl Game {
items: (0..self.data.hand_count).map(|_| None).collect(),
communicate_persist: None,
movement: MovementBase::new(position),
+ movement_input_changed: false,
+ movement_must_sync: false,
},
);
}
diff --git a/server/src/benchmark.rs b/server/src/benchmark.rs
new file mode 100644
index 00000000..ec4f10e8
--- /dev/null
+++ b/server/src/benchmark.rs
@@ -0,0 +1,55 @@
+/*
+ Hurry Curry! - a game about cooking
+ Copyright (C) 2025 Hurry Curry! Contributors
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, version 3 of the License only.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+*/
+
+use crate::server::{Server, ServerConfig};
+use anyhow::Result;
+use hurrycurry_protocol::PacketC;
+use std::{path::PathBuf, time::Instant};
+use tokio::sync::broadcast;
+
+pub fn benchmark(data_path: PathBuf) -> Result<()> {
+ let mut server = Server::new(
+ data_path,
+ ServerConfig::default(),
+ broadcast::channel(1024).0,
+ )?;
+
+ server.load(server.index.generate_with_book("junior").unwrap(), None);
+
+ let start = Instant::now();
+ let mut packets = 0;
+ let mut packets_movement = 0;
+ loop {
+ if server.tick(1. / 50.).is_some() {
+ break;
+ }
+ while let Some(p) = server.packet_out.pop_front() {
+ packets += 1;
+ if let PacketC::Movement { .. } = &p {
+ packets_movement += 1;
+ }
+ }
+ }
+ println!("simulation took {:?}", start.elapsed());
+ println!(
+ "packets broadcast: {packets} ({packets_movement} movement, {} other)",
+ packets - packets_movement
+ );
+
+ Ok(())
+}
diff --git a/server/src/lib.rs b/server/src/lib.rs
index 042fcb6c..e5b78644 100644
--- a/server/src/lib.rs
+++ b/server/src/lib.rs
@@ -22,6 +22,7 @@ pub mod network;
pub mod scoreboard;
pub mod server;
pub mod state;
+pub mod benchmark;
use hurrycurry_protocol::glam::Vec2;
use std::{fmt::Display, random::random};
diff --git a/server/src/main.rs b/server/src/main.rs
index cca5ec95..0179feaa 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -22,6 +22,7 @@ use hurrycurry_locale::trm;
use hurrycurry_protocol::{PacketC, PacketS};
use hurrycurry_server::{
ConnectionID,
+ benchmark::benchmark,
server::{Server, ServerConfig},
};
use log::{LevelFilter, debug, info, trace, warn};
@@ -86,6 +87,9 @@ pub(crate) struct Args {
#[cfg(feature = "register")]
#[arg(long, default_value = "https://registry.hurrycurry.org")]
registry_server: String,
+ /// Run benchmarks, then exit
+ #[arg(long)]
+ benchmark: bool,
}
fn main() -> Result<()> {
@@ -102,7 +106,6 @@ fn main() -> Result<()> {
println!("{version} ({distribution})");
exit(0);
}
-
info!("Starting Hurry Curry! Server {version} ({distribution})");
let data_path = if let Some(d) = args.data_dir.clone() {
@@ -111,6 +114,11 @@ fn main() -> Result<()> {
find_data_path()?
};
+ if args.benchmark {
+ benchmark(data_path)?;
+ exit(0);
+ }
+
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()?
diff --git a/server/src/server.rs b/server/src/server.rs
index b2597bc6..b925a577 100644
--- a/server/src/server.rs
+++ b/server/src/server.rs
@@ -336,10 +336,12 @@ impl GameServerExt for Game {
items: (0..self.data.hand_count).map(|_| None).collect(),
character,
class,
- movement: MovementBase::new(position),
communicate_persist: None,
interacting: None,
name: name.clone(),
+ movement: MovementBase::new(position),
+ movement_input_changed: false,
+ movement_must_sync: false,
},
);
self.score.players = self.score.players.max(self.players.len());
@@ -511,6 +513,9 @@ impl Server {
.get_mut(&player)
.ok_or(tre!("s.error.no_player"))?;
+ if pd.movement.input_direction != dir {
+ pd.movement_input_changed = true;
+ }
pd.movement.input(dir, boost);
if let Some(pos) = pos {