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

View File

@@ -105,6 +105,17 @@ impl Item {
ui.handle_create_item(&item);
}
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
}
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("set_base_prefixes", Root::set_base_prefixes);
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 {
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<()> {
calling_client
.root