diff options
| author | troido <troido@protonmail.com> | 2020-09-23 13:54:36 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-09-23 13:54:36 +0200 |
| commit | 276e31ee6793aadf6cde3d021803b78410012ecb (patch) | |
| tree | 069b5274f2a33e4d65b1d3e418fd24a63c12a763 /src/world.rs | |
| parent | 00a590a42edd7538c61dacbc4224c1adfc1e6414 (diff) | |
made step duration, save interval and unloading age configurable arguments
Diffstat (limited to 'src/world.rs')
| -rw-r--r-- | src/world.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/world.rs b/src/world.rs index b42a1db..6e65f84 100644 --- a/src/world.rs +++ b/src/world.rs @@ -27,9 +27,9 @@ pub struct World<'a, 'b> { default_room: RoomId, players: HashMap<PlayerId, RoomId>, rooms: HashMap<RoomId, Room<'a, 'b>>, - room_age: HashMap<RoomId, u32>, + room_age: HashMap<RoomId, Timestamp>, encyclopedia: Encyclopedia, - time: Timestamp, + pub time: Timestamp, default_dispatcher: Dispatcher<'a, 'b> } @@ -65,7 +65,7 @@ impl <'a, 'b>World<'a, 'b> { } fn get_room_mut(&mut self, id: &RoomId) -> Result<&mut Room<'a, 'b>> { - self.room_age.insert(id.clone(), 0); + self.room_age.insert(id.clone(), self.time); let result = self.get_room_mut_(id); if let Err(err) = &result { println!("Failed to load room {:?}: {:?}", id, err); @@ -208,15 +208,14 @@ impl <'a, 'b>World<'a, 'b> { } } - pub fn unload_rooms(&mut self){ + pub fn unload_rooms(&mut self, min_age: i64){ let mut to_remove = Vec::new(); for roomid in self.rooms.keys() { if self.rooms[roomid].has_players() { - self.room_age.insert(roomid.clone(), 0); + self.room_age.insert(roomid.clone(), self.time); } else { - let age = *self.room_age.get(&roomid).unwrap_or(&0) + 1; - self.room_age.insert(roomid.clone(), age); - if age > 2 { + let age = self.time - *self.room_age.get(&roomid).unwrap_or(&Timestamp(0)); + if age >= min_age { to_remove.push(roomid.clone()); } } |
