diff options
| author | troido <troido@protonmail.com> | 2020-04-08 09:54:20 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-04-08 09:54:20 +0200 |
| commit | 7a4a62eb2804b6b19b4e71eee42d6b3d7ad08a3a (patch) | |
| tree | a3f5fe0b6fdb5ab913bbaafb48f090d217428479 /src/world.rs | |
| parent | 5bef1829e443985e960a3cb64106d3f2e3dbf420 (diff) | |
rooms now share the same default dispatcher
Diffstat (limited to 'src/world.rs')
| -rw-r--r-- | src/world.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/world.rs b/src/world.rs index 1ffacdc..59b3aba 100644 --- a/src/world.rs +++ b/src/world.rs @@ -1,10 +1,13 @@ use std::collections::HashMap; +use specs::Dispatcher; + use crate::{ PlayerId, RoomId, room::Room, + room, worldloader::WorldLoader, persistence::PersistentStorage, playerstate::{PlayerState, RoomPos}, @@ -25,9 +28,11 @@ pub struct World<'a, 'b> { rooms: HashMap<RoomId, Room<'a, 'b>>, room_age: HashMap<RoomId, u32>, encyclopedia: Encyclopedia, - time: Timestamp + time: Timestamp, + default_dispatcher: Dispatcher<'a, 'b> } + impl <'a, 'b>World<'a, 'b> { pub fn new(encyclopedia: Encyclopedia, template_loader: WorldLoader, persistence: Box<dyn PersistentStorage>, default_room: RoomId) -> Self { @@ -39,7 +44,8 @@ impl <'a, 'b>World<'a, 'b> { encyclopedia: encyclopedia, players: HashMap::new(), rooms: HashMap::new(), - room_age: HashMap::new() + room_age: HashMap::new(), + default_dispatcher: room::default_dispatcher() } } @@ -58,15 +64,17 @@ impl <'a, 'b>World<'a, 'b> { let mut room: Room = if id == &purgatory::purgatory_id() { purgatory::create_purgatory(&self.encyclopedia) } else { + let mut room = Room::new(id.clone(), self.encyclopedia.clone(), None); let template = self.template_loader.load_room(id.clone())?; - Room::create(id.clone(), &self.encyclopedia, &template)? + room.load_from_template(&template); + room }; if let Ok(state) = self.persistence.load_room(id.clone()){ room.load_saved(&state); } let last_time = self.time - 1; if room.get_time() < last_time { - room.update(last_time); + room.update(last_time, &mut self.default_dispatcher); } self.rooms.insert(id.clone(), room); } @@ -145,7 +153,7 @@ impl <'a, 'b>World<'a, 'b> { pub fn update(&mut self) { self.migrate(); for room in self.rooms.values_mut() { - room.update(self.time); + room.update(self.time, &mut self.default_dispatcher); } self.time.0 += 1; } |
