aboutsummaryrefslogtreecommitdiff
path: root/server/src/game.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/game.rs')
-rw-r--r--server/src/game.rs23
1 files changed, 19 insertions, 4 deletions
diff --git a/server/src/game.rs b/server/src/game.rs
index d649d87e..69272159 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, ItemIndex, ItemLocation, Menu, Message, PacketC, PacketS, PlayerID,
- RecipeIndex, Score, TileIndex,
+ ClientGamedata, Environment, ItemIndex, ItemLocation, Menu, Message, PacketC, PacketS,
+ PlayerID, RecipeIndex, Score, TileIndex,
};
use log::{info, warn};
use std::{
@@ -76,6 +76,8 @@ pub struct Game {
end: Option<Instant>,
pub lobby: bool,
+ pub environment_next_update: Instant,
+ pub environment: Environment,
pub score_changed: bool,
pub score: Score,
}
@@ -93,11 +95,13 @@ 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(),
score_changed: false,
}
}
@@ -117,6 +121,9 @@ impl Game {
neighbors: [None, None, None, None],
})
}
+ self.score = Score::default();
+ self.end = None;
+ self.environment = Environment::default();
self.walkable.clear();
}
pub fn load(
@@ -215,6 +222,7 @@ impl Game {
.collect(),
},
});
+ out.push(PacketC::UpdateEnvironment(self.environment.clone()));
for (&id, player) in &self.players {
out.push(PacketC::AddPlayer {
id,
@@ -589,9 +597,16 @@ 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 - Instant::now()).as_secs_f64();
- if end < Instant::now() {
+ self.score.time_remaining = (end - now).as_secs_f64();
+ if end < now {
let relative_score = (self.score.points * 100) / self.data.score_baseline.max(1);
self.score.stars = match relative_score {
100.. => 3,