aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-10-20 00:20:25 +0200
committermetamuffin <metamuffin@disroot.org>2025-10-20 00:20:25 +0200
commit8961db68d063a2dda427e80601650e4674772685 (patch)
tree5bff20f6f6965c2c93e41005850d10ef269d346f /server
parentab83f982601d93b2399102c4d030fd6e13c4c735 (diff)
downloadhurrycurry-8961db68d063a2dda427e80601650e4674772685.tar
hurrycurry-8961db68d063a2dda427e80601650e4674772685.tar.bz2
hurrycurry-8961db68d063a2dda427e80601650e4674772685.tar.zst
tick perf logging
Diffstat (limited to 'server')
-rw-r--r--server/src/server.rs7
-rw-r--r--server/src/state.rs8
2 files changed, 15 insertions, 0 deletions
diff --git a/server/src/server.rs b/server/src/server.rs
index 45f31e0b..f273564e 100644
--- a/server/src/server.rs
+++ b/server/src/server.rs
@@ -58,6 +58,7 @@ pub enum AnnounceState {
}
pub struct Server {
+ pub tick_perf: (Duration, usize),
pub tx: Sender<PacketC>,
pub connections: HashMap<ConnectionID, ConnectionData>,
pub paused: bool,
@@ -120,6 +121,7 @@ impl GameServerExt for Game {
self.environment_effects.clear();
self.walkable.clear();
self.tile_index.clear();
+ self.item_locations_index.clear();
}
fn load(
&mut self,
@@ -161,6 +163,10 @@ impl GameServerExt for Game {
if !self.data_index.tile_collide[tile.0] {
self.walkable.insert(p);
}
+ self.tile_index.entry(*tile).or_default().insert(p);
+ if item.is_some() {
+ self.item_locations_index.insert(ItemLocation::Tile(p));
+ }
}
for (id, (name, character, class)) in players {
self.join_player(id, name, character, class, serverdata, None, None);
@@ -309,6 +315,7 @@ impl Server {
pub fn new(data_path: PathBuf, tx: Sender<PacketC>) -> Result<Self> {
Ok(Self {
game: Game::default(),
+ tick_perf: (Duration::ZERO, 0),
index: DataIndex::new(data_path).context("Failed to load data index")?,
tx,
announce_state: AnnounceState::Done,
diff --git a/server/src/state.rs b/server/src/state.rs
index 28ef7235..1e01036c 100644
--- a/server/src/state.rs
+++ b/server/src/state.rs
@@ -23,11 +23,19 @@ use anyhow::Result;
use hurrycurry_locale::{TrError, tre, trm};
use hurrycurry_protocol::{Menu, Message, PacketC, PacketS, PlayerID, VERSION};
use log::{debug, info, trace};
+use std::time::{Duration, Instant};
impl Server {
pub fn tick_outer(&mut self, dt: f32) -> anyhow::Result<()> {
if !self.paused {
+ let start = Instant::now();
let r = self.tick(dt);
+ self.tick_perf.0 += start.elapsed();
+ self.tick_perf.1 += 1;
+ if self.tick_perf.1 >= 500 {
+ debug!("tick perf {:?}", self.tick_perf.0 / 500);
+ self.tick_perf = (Duration::ZERO, 0);
+ }
if let Some((name, timer)) = r {
self.scoreboard.save()?;
self.load(self.index.generate_with_book(&name)?, timer);