From b31035bf03e0843fb516bee065f9a010424ba546 Mon Sep 17 00:00:00 2001 From: tcmal Date: Sun, 25 Aug 2024 17:44:20 +0100 Subject: refactor(render): update gfx-hal and use staging and index buffers. also some minor changes to types because of deprecation and a bunch of readability improvements --- stockton-types/src/entity_store.rs | 12 ++++++------ stockton-types/src/world.rs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'stockton-types') diff --git a/stockton-types/src/entity_store.rs b/stockton-types/src/entity_store.rs index 375ae74..ae2db82 100644 --- a/stockton-types/src/entity_store.rs +++ b/stockton-types/src/entity_store.rs @@ -54,7 +54,7 @@ impl EntityStore { /// # Returns /// The name & index of the added entity if successful. /// If an entity already exists with the given name, NameConflict is returned. - pub fn add(&mut self, entity: Box, name: String) -> Result { + pub fn add(&mut self, entity: Box, name: String) -> Result { if self.name_to_index.contains_key(&name) { return Err(NameConflict) } @@ -67,7 +67,7 @@ impl EntityStore { /// Remove the entity with the given index, returning it. /// /// Takes O(2n - i) time. - pub fn remove_by_index(&mut self, index: usize) -> Option> { + pub fn remove_by_index(&mut self, index: usize) -> Option> { if index >= self.entities.len() { return None; } @@ -78,7 +78,7 @@ impl EntityStore { /// Removes the entity with the given name, returning it. /// /// Takes O(2n - i) time. - pub fn remove_by_name(&mut self, name: &str) -> Option> { + pub fn remove_by_name(&mut self, name: &str) -> Option> { let mut index: usize = self.entities.len(); self.name_to_index.retain(|k,v| { @@ -99,7 +99,7 @@ impl EntityStore { /// Make a new EntityStore from a list of entities & names. /// /// Returns None in case of name conflicts in list. - pub fn from_entities(entities: Vec<(Box, String)>) -> Option { + pub fn from_entities(entities: Vec<(Box, String)>) -> Option { let mut store = EntityStore { entities: Vec::with_capacity(entities.len()), name_to_index: HashMap::with_capacity(entities.len()) @@ -118,7 +118,7 @@ impl EntityStore { /// Indexes the EntityStore for a specific index. /// If you want to target an entity for longer than one tick, store its name, not an index. impl Index for EntityStore { - type Output = Entity; + type Output = dyn Entity; fn index(&self, index: usize) -> &Self::Output { self.entities[index].as_ref() } @@ -127,7 +127,7 @@ impl Index for EntityStore { /// Indexes the EntityStore for a specific name. /// This is what you should use if you plan to target an entity for more than one tick. impl Index<&str> for EntityStore { - type Output = Entity; + type Output = dyn Entity; fn index(&self, index: &str) -> &Self::Output { self.entities[self.name_to_index[index]].as_ref() } diff --git a/stockton-types/src/world.rs b/stockton-types/src/world.rs index 1196592..e244aa7 100644 --- a/stockton-types/src/world.rs +++ b/stockton-types/src/world.rs @@ -35,9 +35,9 @@ impl<'a> World<'a> { /// /// `mapper` is called for each BSPEntity to map it to a concrete rust type. pub fn new(bsp: Pin>>, mut mapper: F) -> Option> - where F: FnMut(&BSPEntity) -> Option<(Box, String)> { + where F: FnMut(&BSPEntity) -> Option<(Box, String)> { - let mut entities: Vec<(Box, String)> = Vec::with_capacity(bsp.entities.entities.len()); + let mut entities: Vec<(Box, String)> = Vec::with_capacity(bsp.entities.entities.len()); for bsp_ent in bsp.entities.entities.iter() { if let Some(result) = mapper(&bsp_ent) { entities.push(result); -- cgit v1.2.3