From d10d3e0368bd1178085ab8abd2ea24afe912b26f Mon Sep 17 00:00:00 2001 From: troido Date: Sat, 3 Oct 2020 15:47:42 +0200 Subject: removed dispatcher: call systems directly --- src/purgatory.rs | 23 +++-------------- src/room.rs | 78 +++++++++++++++++++++++++++++--------------------------- src/world.rs | 27 ++++++++------------ 3 files changed, 56 insertions(+), 72 deletions(-) (limited to 'src') diff --git a/src/purgatory.rs b/src/purgatory.rs index 41015f4..028df34 100644 --- a/src/purgatory.rs +++ b/src/purgatory.rs @@ -2,35 +2,20 @@ use serde_json::json; use serde::Deserialize; -use specs::{ - DispatcherBuilder -}; use crate::{ RoomId, Encyclopedia, - room::Room, - roomtemplate::RoomTemplate, - systems::{ - Move, - ControlInput, - UpdateCooldowns, - ControlAI, - } + room::{Room, RoomType}, + roomtemplate::RoomTemplate }; pub fn purgatory_id() -> RoomId { RoomId(String::from("+")) } -pub fn create_purgatory<'a, 'b>(encyclopedia: &Encyclopedia) -> Room<'a, 'b> { - let dispatcher = DispatcherBuilder::new() - .with(UpdateCooldowns, "cool_down", &[]) - .with(ControlInput, "controlinput", &["cool_down"]) - .with(ControlAI, "controlai", &["cool_down"]) - .with(Move, "move", &["controlinput", "controlai"]) - .build(); - let mut room = Room::new(purgatory_id(), encyclopedia.clone(), Some(dispatcher)); +pub fn create_purgatory<'a, 'b>(encyclopedia: &Encyclopedia) -> Room { + let mut room = Room::new(purgatory_id(), encyclopedia.clone(), RoomType::Purgatory); room.load_from_template(&RoomTemplate::deserialize(&json!({ "width": 15, "height": 20, diff --git a/src/room.rs b/src/room.rs index 4f0aa47..e629791 100644 --- a/src/room.rs +++ b/src/room.rs @@ -4,8 +4,6 @@ use std::collections::HashMap; use specs::{ World, WorldExt, - DispatcherBuilder, - Dispatcher, Join, Entity, RunNow @@ -75,36 +73,18 @@ use crate::{ } }; -pub fn default_dispatcher<'a, 'b>() -> Dispatcher<'a, 'b> { - DispatcherBuilder::new() - .with(Replace, "replace", &[]) - .with(Timeout, "timeout", &[]) - .with(UpdateCooldowns, "cool_down", &[]) - .with(Spawn, "spawn", &[]) - .with(SpawnCheck, "spawncheck", &["spawn"]) - .with(ControlInput, "controlinput", &["cool_down"]) - .with(ControlAI, "controlai", &["cool_down"]) - .with(Take, "take", &["controlinput", "controlai"]) - .with(Use, "use", &["controlinput", "controlai"]) - .with(Interact, "interact", &["controlinput", "controlai"]) - .with(SpawnTrigger, "spawntrigger", &["spawncheck", "replace"]) - .with(Move, "move", &["controlinput", "controlai"]) - .with(Trapping, "trapping", &["move"]) - .with(Fight, "fight", &["move"]) - .with(Heal, "heal", &[]) - .with(Attacking, "attacking", &["use", "trapping", "fight", "heal", "interact", "spawntrigger"]) - .with(Die, "die", &["attacking"]) - .with(DropLoot, "droploot", &["attacking"]) - .with(Building, "building", &["attacking"]) - .with(Migrate, "migrate", &["move", "attacking", "die"]) - .build() +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RoomType { + Normal, + Purgatory } -pub struct Room<'a, 'b> { + +pub struct Room { world: World, - dispatcher: Option>, pub id: RoomId, - places: HashMap + places: HashMap, + room_type: RoomType } macro_rules! register_insert { @@ -119,9 +99,9 @@ macro_rules! register_insert { } -impl <'a, 'b>Room<'a, 'b> { +impl Room { - pub fn new(id: RoomId, encyclopedia: Encyclopedia, dispatcher: Option>) -> Room<'a, 'b> { + pub fn new(id: RoomId, encyclopedia: Encyclopedia, room_type: RoomType) -> Room { let mut world = World::new(); world.insert(NewEntities::new(encyclopedia)); register_insert!( @@ -132,9 +112,9 @@ impl <'a, 'b>Room<'a, 'b> { Room { world, - dispatcher, id, - places: HashMap::new() + places: HashMap::new(), + room_type } } @@ -165,12 +145,36 @@ impl <'a, 'b>Room<'a, 'b> { self.world.fetch::().output.clone() } - pub fn update(&mut self, timestamp: Timestamp, default_dispatcher: &mut Dispatcher) { + pub fn update(&mut self, timestamp: Timestamp) { self.world.fetch_mut::