diff options
-rw-r--r-- | stockton-types/Cargo.toml | 3 | ||||
-rw-r--r-- | stockton-types/src/entity_store.rs | 21 | ||||
-rw-r--r-- | stockton-types/src/lib.rs | 16 | ||||
-rw-r--r-- | stockton-types/src/world.rs | 19 |
4 files changed, 55 insertions, 4 deletions
diff --git a/stockton-types/Cargo.toml b/stockton-types/Cargo.toml index af69084..b97f983 100644 --- a/stockton-types/Cargo.toml +++ b/stockton-types/Cargo.toml @@ -6,4 +6,5 @@ edition = "2018" [dependencies] nalgebra = "0.18.0" -stockton-bsp = "1.0.0"
\ No newline at end of file +stockton-bsp = "1.0.0" +downcast-rs = "1.0.4"
\ No newline at end of file diff --git a/stockton-types/src/entity_store.rs b/stockton-types/src/entity_store.rs index 9984c0a..375ae74 100644 --- a/stockton-types/src/entity_store.rs +++ b/stockton-types/src/entity_store.rs @@ -1,12 +1,29 @@ +// Copyright (C) Oscar Shrimpton 2019 + +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. + +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. + +// You should have received a copy of the GNU General Public License along +// with this program. If not, see <http://www.gnu.org/licenses/>. //! Stores entities in a world. use std::collections::HashMap; use std::boxed::Box; use std::ops::Index; + +use downcast_rs::Downcast; + use crate::Vector3; /// An entity, capable of recieving events. -pub trait Entity { +pub trait Entity: Downcast { /// Should return the position of this entity in 3d space. /// @@ -15,6 +32,8 @@ pub trait Entity { } +impl_downcast!(Entity); + /// Stores all the entities in a live world. The BSPFile only specifies the starting entities, /// whereas this is mutable and thus is used to represent the current state of the world's entities. /// diff --git a/stockton-types/src/lib.rs b/stockton-types/src/lib.rs index 0612e86..7e6c9ea 100644 --- a/stockton-types/src/lib.rs +++ b/stockton-types/src/lib.rs @@ -1,7 +1,23 @@ +// Copyright (C) Oscar Shrimpton 2019 + +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. + +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. + +// You should have received a copy of the GNU General Public License along +// with this program. If not, see <http://www.gnu.org/licenses/>. //! Common types for all stockton crates. extern crate stockton_bsp; extern crate nalgebra as na; +#[macro_use] +extern crate downcast_rs; pub mod entity_store; pub use entity_store::{EntityStore, Entity}; diff --git a/stockton-types/src/world.rs b/stockton-types/src/world.rs index f687f5e..18a0edf 100644 --- a/stockton-types/src/world.rs +++ b/stockton-types/src/world.rs @@ -1,3 +1,18 @@ +// Copyright (C) Oscar Shrimpton 2019 + +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. + +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. + +// You should have received a copy of the GNU General Public License along +// with this program. If not, see <http://www.gnu.org/licenses/>. + //! The thing you play on and all the associated state. use crate::{EntityStore, Entity}; @@ -19,8 +34,8 @@ impl<'a> World<'a> { /// Returns None if any entities in the map have name conflicts. /// /// `mapper` is called for each BSPEntity to map it to a concrete rust type. - pub fn new<F>(bsp: Pin<Box<BSPFile<'a>>>, mapper: F) -> Option<World<'a>> - where F: Fn(&BSPEntity) -> (Box<Entity>, String) { + pub fn new<F>(bsp: Pin<Box<BSPFile<'a>>>, mut mapper: F) -> Option<World<'a>> + where F: FnMut(&BSPEntity) -> (Box<Entity>, String) { let mut entities: Vec<(Box<Entity>, String)> = Vec::with_capacity(bsp.entities.entities.len()); for bsp_ent in bsp.entities.entities.iter() { |