Misc
This commit is contained in:
parent
adb8fcd12d
commit
98a22580a1
18
src/hooks.rs
18
src/hooks.rs
|
@ -1,4 +1,4 @@
|
|||
use crate::{deferred_system::new_deferred_system, tick::EcsContext};
|
||||
use crate::deferred_system::new_deferred_system;
|
||||
use bevy::{
|
||||
ecs::{
|
||||
component::ComponentId,
|
||||
|
@ -19,6 +19,22 @@ pub(crate) struct EcsSubscriptions {
|
|||
pub world_and_queries: Box<HashSet<ScopeId>>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct EcsContext {
|
||||
pub world: *mut World,
|
||||
}
|
||||
|
||||
impl EcsContext {
|
||||
fn get_world(cx: &ScopeState) -> &mut World {
|
||||
unsafe {
|
||||
&mut *cx
|
||||
.consume_context::<EcsContext>()
|
||||
.expect("Must be used from a dioxus component within a DioxusUiRoot bevy component")
|
||||
.world
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn use_world<'a>(cx: &'a ScopeState) -> &'a World {
|
||||
let world = EcsContext::get_world(cx);
|
||||
|
||||
|
|
25
src/tick.rs
25
src/tick.rs
|
@ -1,6 +1,9 @@
|
|||
use crate::{
|
||||
apply_mutations::apply_mutations, deferred_system::DeferredSystemRegistry,
|
||||
events::EventReaders, hooks::EcsSubscriptions, DioxusUiRoot,
|
||||
apply_mutations::apply_mutations,
|
||||
deferred_system::DeferredSystemRegistry,
|
||||
events::EventReaders,
|
||||
hooks::{EcsContext, EcsSubscriptions},
|
||||
DioxusUiRoot,
|
||||
};
|
||||
use bevy::{
|
||||
ecs::{
|
||||
|
@ -11,7 +14,7 @@ use bevy::{
|
|||
prelude::{Deref, DerefMut},
|
||||
utils::synccell::SyncCell,
|
||||
};
|
||||
use dioxus::core::{Element, Scope, ScopeState, VirtualDom};
|
||||
use dioxus::core::{Element, Scope, VirtualDom};
|
||||
use std::{mem, rc::Rc, sync::Arc};
|
||||
|
||||
pub fn tick_dioxus_ui(world: &mut World) {
|
||||
|
@ -112,22 +115,6 @@ pub fn tick_dioxus_ui(world: &mut World) {
|
|||
});
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct EcsContext {
|
||||
world: *mut World,
|
||||
}
|
||||
|
||||
impl EcsContext {
|
||||
pub fn get_world(cx: &ScopeState) -> &mut World {
|
||||
unsafe {
|
||||
&mut *cx
|
||||
.consume_context::<EcsContext>()
|
||||
.expect("Must be used from a dioxus component within a DioxusUiRoot bevy component")
|
||||
.world
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deref, DerefMut)]
|
||||
pub struct VirtualDomUnsafe(pub SyncCell<VirtualDom>);
|
||||
unsafe impl Send for VirtualDomUnsafe {}
|
||||
|
|
Loading…
Reference in a new issue