From 731c55b70f6d4c29a8ddaac229272caa4bd30084 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 26 Jul 2024 18:51:21 +0200 Subject: refactor environment effects --- server/src/game.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'server/src/game.rs') diff --git a/server/src/game.rs b/server/src/game.rs index 69272159..d7e62413 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -25,8 +25,8 @@ use anyhow::{anyhow, bail, Result}; use hurrycurry_protocol::{ glam::{IVec2, Vec2}, movement::MovementBase, - ClientGamedata, Environment, ItemIndex, ItemLocation, Menu, Message, PacketC, PacketS, - PlayerID, RecipeIndex, Score, TileIndex, + ClientGamedata, ItemIndex, ItemLocation, Menu, Message, PacketC, PacketS, PlayerID, + RecipeIndex, Score, TileIndex, }; use log::{info, warn}; use std::{ @@ -76,8 +76,7 @@ pub struct Game { end: Option, pub lobby: bool, - pub environment_next_update: Instant, - pub environment: Environment, + pub environment_effects: HashSet, pub score_changed: bool, pub score: Score, } @@ -95,13 +94,12 @@ impl Game { data: Gamedata::default().into(), players: HashMap::new(), tiles: HashMap::new(), - environment_next_update: Instant::now(), walkable: HashSet::new(), end: None, entities: Arc::new(RwLock::new(vec![])), players_spatial_index: SpatialIndex::default(), score: Score::default(), - environment: Environment::default(), + environment_effects: HashSet::default(), score_changed: false, } } @@ -123,7 +121,7 @@ impl Game { } self.score = Score::default(); self.end = None; - self.environment = Environment::default(); + self.environment_effects.clear(); self.walkable.clear(); } pub fn load( @@ -222,7 +220,9 @@ impl Game { .collect(), }, }); - out.push(PacketC::UpdateEnvironment(self.environment.clone())); + out.push(PacketC::Environment { + effects: self.environment_effects.clone(), + }); for (&id, player) in &self.players { out.push(PacketC::AddPlayer { id, @@ -599,11 +599,6 @@ impl Game { let now = Instant::now(); - if self.environment_next_update < now { - packet_out.push_back(PacketC::UpdateEnvironment(self.environment.clone())); - self.environment_next_update += Duration::from_secs(5); - } - if let Some(end) = self.end { self.score.time_remaining = (end - now).as_secs_f64(); if end < now { -- cgit v1.2.3-70-g09d2