aboutsummaryrefslogtreecommitdiff
path: root/stockton-types/src
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:19 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:19 +0100
commit73d48fe3719b7bbef14a3cffaadabd55df4b4bf2 (patch)
treef8e6ecb0adf76292d19308948a687938fc0cf9f2 /stockton-types/src
parent6ee3384750bb065e4397b02e2cc7f567f96da73a (diff)
feat(types): entity downcasting and fnmut in world creation
Diffstat (limited to 'stockton-types/src')
-rw-r--r--stockton-types/src/entity_store.rs21
-rw-r--r--stockton-types/src/lib.rs16
-rw-r--r--stockton-types/src/world.rs19
3 files changed, 53 insertions, 3 deletions
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() {