mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
blackboard for visitor
This commit is contained in:
@@ -28,6 +28,7 @@ use crate::{
|
||||
use base64::Engine;
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
use fxhash::FxHashMap;
|
||||
use std::any::TypeId;
|
||||
use std::{
|
||||
any::Any,
|
||||
cell::{Cell, RefCell},
|
||||
@@ -1064,6 +1065,36 @@ impl<'a> Drop for RegionGuard<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Blackboard {
|
||||
items: FxHashMap<TypeId, Arc<dyn Any>>,
|
||||
}
|
||||
|
||||
impl Blackboard {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
items: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register<T: Any>(&mut self, value: T) {
|
||||
self.items.insert(value.type_id(), Arc::new(value));
|
||||
}
|
||||
|
||||
pub fn get<T: Any>(&self) -> Option<&T> {
|
||||
self.items
|
||||
.get(&TypeId::of::<T>())
|
||||
.and_then(|v| v.downcast_ref())
|
||||
}
|
||||
|
||||
pub fn inner(&self) -> &FxHashMap<TypeId, Arc<dyn Any>> {
|
||||
&self.items
|
||||
}
|
||||
|
||||
pub fn inner_mut(&mut self) -> &mut FxHashMap<TypeId, Arc<dyn Any>> {
|
||||
&mut self.items
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Visitor {
|
||||
nodes: Pool<VisitorNode>,
|
||||
rc_map: FxHashMap<u64, Rc<dyn Any>>,
|
||||
@@ -1071,7 +1102,7 @@ pub struct Visitor {
|
||||
reading: bool,
|
||||
current_node: Handle<VisitorNode>,
|
||||
root: Handle<VisitorNode>,
|
||||
pub environment: Option<Arc<dyn Any>>,
|
||||
pub blackboard: Blackboard,
|
||||
}
|
||||
|
||||
pub trait Visit {
|
||||
@@ -1097,7 +1128,7 @@ impl Visitor {
|
||||
reading: false,
|
||||
current_node: root,
|
||||
root,
|
||||
environment: None,
|
||||
blackboard: Blackboard::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1284,7 +1315,7 @@ impl Visitor {
|
||||
reading: true,
|
||||
current_node: Handle::NONE,
|
||||
root: Handle::NONE,
|
||||
environment: None,
|
||||
blackboard: Blackboard::new(),
|
||||
};
|
||||
visitor.root = visitor.load_node_binary(&mut reader)?;
|
||||
visitor.current_node = visitor.root;
|
||||
|
||||
@@ -16,3 +16,4 @@ rust-version = "1.56"
|
||||
|
||||
[dependencies]
|
||||
fyrox-core = { path = "../fyrox-core", version = "0.23.0" }
|
||||
fxhash = "0.2.1"
|
||||
|
||||
Reference in New Issue
Block a user