refactor(startup): auto acceptor on item add to

This commit is contained in:
Nova
2022-12-10 10:26:26 -05:00
parent 0cb039c1be
commit aa79cb2147
3 changed files with 28 additions and 17 deletions

View File

@@ -33,7 +33,7 @@ lazy_static! {
event_loop: Weak::new(), event_loop: Weak::new(),
index: 0, index: 0,
pid: None, pid: None,
env: None, // env: None,
exe: None, exe: None,
stop_notifier: Default::default(), stop_notifier: Default::default(),
@@ -43,6 +43,7 @@ lazy_static! {
scenegraph: Default::default(), scenegraph: Default::default(),
root: OnceCell::new(), root: OnceCell::new(),
base_resource_prefixes: Default::default(), base_resource_prefixes: Default::default(),
startup_settings: None,
}); });
} }
@@ -63,7 +64,7 @@ pub struct Client {
event_loop: Weak<EventLoop>, event_loop: Weak<EventLoop>,
index: usize, index: usize,
pid: Option<i32>, pid: Option<i32>,
env: Option<FxHashMap<String, String>>, // env: Option<FxHashMap<String, String>>,
exe: Option<PathBuf>, exe: Option<PathBuf>,
stop_notifier: Arc<Notify>, stop_notifier: Arc<Notify>,
join_handle: OnceCell<JoinHandle<Result<()>>>, join_handle: OnceCell<JoinHandle<Result<()>>>,
@@ -72,6 +73,7 @@ pub struct Client {
pub scenegraph: Arc<Scenegraph>, pub scenegraph: Arc<Scenegraph>,
pub root: OnceCell<Arc<Root>>, pub root: OnceCell<Arc<Root>>,
pub base_resource_prefixes: Mutex<Vec<PathBuf>>, pub base_resource_prefixes: Mutex<Vec<PathBuf>>,
pub startup_settings: Option<StartupSettings>,
} }
impl Client { impl Client {
pub fn from_connection( pub fn from_connection(
@@ -93,12 +95,13 @@ impl Client {
let (mut messenger_tx, mut messenger_rx) = messenger::create(connection); let (mut messenger_tx, mut messenger_rx) = messenger::create(connection);
let scenegraph = Arc::new(Scenegraph::default()); let scenegraph = Arc::new(Scenegraph::default());
let startup_settings = env.as_ref().and_then(|env| startup_settings(env));
let client = CLIENTS.add(Client { let client = CLIENTS.add(Client {
event_loop: Arc::downgrade(event_loop), event_loop: Arc::downgrade(event_loop),
index, index,
pid, pid,
env, // env,
exe, exe,
stop_notifier: Default::default(), stop_notifier: Default::default(),
join_handle: OnceCell::new(), join_handle: OnceCell::new(),
@@ -107,6 +110,7 @@ impl Client {
scenegraph: scenegraph.clone(), scenegraph: scenegraph.clone(),
root: OnceCell::new(), root: OnceCell::new(),
base_resource_prefixes: Default::default(), base_resource_prefixes: Default::default(),
startup_settings,
}); });
let _ = client.scenegraph.client.set(Arc::downgrade(&client)); let _ = client.scenegraph.client.set(Arc::downgrade(&client));
let _ = client.root.set(Root::create(&client)); let _ = client.root.set(Root::create(&client));
@@ -119,15 +123,6 @@ impl Client {
input::create_interface(&client); input::create_interface(&client);
startup::create_interface(&client); startup::create_interface(&client);
if let Some(startup_settings) = client.env.as_ref().and_then(|env| startup_settings(env)) {
client
.root
.get()
.unwrap()
.spatial()
.set_local_transform(startup_settings.transform);
}
let _ = client.join_handle.set(tokio::spawn({ let _ = client.join_handle.set(tokio::spawn({
let client = client.clone(); let client = client.clone();
async move { async move {

View File

@@ -105,6 +105,17 @@ impl Item {
ui.handle_create_item(&item); ui.handle_create_item(&item);
} }
let _ = node.item.set(item.clone()); let _ = node.item.set(item.clone());
if let Some(auto_acceptor) = node.get_client().and_then(|client| {
client
.startup_settings
.as_ref()
.and_then(|settings| settings.acceptors.get(type_info))
.and_then(|acceptor| acceptor.upgrade())
}) {
capture(&item, &auto_acceptor);
}
item item
} }
fn make_alias_named( fn make_alias_named(

View File

@@ -21,7 +21,16 @@ impl Root {
node.add_local_signal("subscribe_logic_step", Root::subscribe_logic_step); node.add_local_signal("subscribe_logic_step", Root::subscribe_logic_step);
node.add_local_signal("set_base_prefixes", Root::set_base_prefixes); node.add_local_signal("set_base_prefixes", Root::set_base_prefixes);
let node = node.add_to_scenegraph(); let node = node.add_to_scenegraph();
let _ = Spatial::add_to(&node, None, Mat4::IDENTITY, false); let _ = Spatial::add_to(
&node,
None,
client
.startup_settings
.as_ref()
.map(|settings| settings.transform)
.unwrap_or(Mat4::IDENTITY),
false,
);
ROOT_REGISTRY.add(Root { ROOT_REGISTRY.add(Root {
node, node,
@@ -29,10 +38,6 @@ impl Root {
}) })
} }
pub fn spatial(&self) -> &Arc<Spatial> {
self.node.spatial.get().unwrap()
}
fn subscribe_logic_step(_node: &Node, calling_client: Arc<Client>, _data: &[u8]) -> Result<()> { fn subscribe_logic_step(_node: &Node, calling_client: Arc<Client>, _data: &[u8]) -> Result<()> {
calling_client calling_client
.root .root