mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Use HashSet instead of Vec
This commit is contained in:
parent
211ab02897
commit
b1718cf578
@ -1,6 +1,6 @@
|
|||||||
use specs::Component;
|
use specs::Component;
|
||||||
use specs_idvs::IdvStorage;
|
use specs_idvs::IdvStorage;
|
||||||
use std::mem;
|
use std::{collections::HashSet, mem};
|
||||||
|
|
||||||
use crate::trade::SiteId;
|
use crate::trade::SiteId;
|
||||||
|
|
||||||
@ -11,11 +11,11 @@ use crate::trade::SiteId;
|
|||||||
/// state when needed
|
/// state when needed
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone, Debug)]
|
||||||
pub struct Behavior {
|
pub struct Behavior {
|
||||||
tags: Vec<BehaviorTag>,
|
tags: HashSet<BehaviorTag>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Versatile tags attached to behaviors
|
/// Versatile tags attached to behaviors
|
||||||
#[derive(PartialEq, Clone, Debug)]
|
#[derive(Hash, Eq, PartialEq, Clone, Debug)]
|
||||||
pub enum BehaviorTag {
|
pub enum BehaviorTag {
|
||||||
/// The entity is allowed to speak
|
/// The entity is allowed to speak
|
||||||
CanSpeak,
|
CanSpeak,
|
||||||
@ -40,20 +40,14 @@ impl Behavior {
|
|||||||
/// Apply a tag to the Behavior
|
/// Apply a tag to the Behavior
|
||||||
pub fn add_tag(&mut self, tag: BehaviorTag) {
|
pub fn add_tag(&mut self, tag: BehaviorTag) {
|
||||||
if !self.has_tag(&tag) {
|
if !self.has_tag(&tag) {
|
||||||
self.tags.push(tag);
|
self.tags.insert(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Revoke a tag to the Behavior
|
/// Revoke a tag to the Behavior
|
||||||
pub fn remove_tag(&mut self, tag: BehaviorTag) {
|
pub fn remove_tag(&mut self, tag: BehaviorTag) {
|
||||||
if self.has_tag(&tag) {
|
if self.has_tag(&tag) {
|
||||||
while let Some(position) = self
|
self.tags.remove(&tag);
|
||||||
.tags
|
|
||||||
.iter()
|
|
||||||
.position(|behavior_tag| behavior_tag == &tag)
|
|
||||||
{
|
|
||||||
self.tags.remove(position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user