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::{
|
use bevy::{
|
||||||
ecs::{
|
ecs::{
|
||||||
component::ComponentId,
|
component::ComponentId,
|
||||||
|
@ -19,6 +19,22 @@ pub(crate) struct EcsSubscriptions {
|
||||||
pub world_and_queries: Box<HashSet<ScopeId>>,
|
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 {
|
pub fn use_world<'a>(cx: &'a ScopeState) -> &'a World {
|
||||||
let world = EcsContext::get_world(cx);
|
let world = EcsContext::get_world(cx);
|
||||||
|
|
||||||
|
|
25
src/tick.rs
25
src/tick.rs
|
@ -1,6 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
apply_mutations::apply_mutations, deferred_system::DeferredSystemRegistry,
|
apply_mutations::apply_mutations,
|
||||||
events::EventReaders, hooks::EcsSubscriptions, DioxusUiRoot,
|
deferred_system::DeferredSystemRegistry,
|
||||||
|
events::EventReaders,
|
||||||
|
hooks::{EcsContext, EcsSubscriptions},
|
||||||
|
DioxusUiRoot,
|
||||||
};
|
};
|
||||||
use bevy::{
|
use bevy::{
|
||||||
ecs::{
|
ecs::{
|
||||||
|
@ -11,7 +14,7 @@ use bevy::{
|
||||||
prelude::{Deref, DerefMut},
|
prelude::{Deref, DerefMut},
|
||||||
utils::synccell::SyncCell,
|
utils::synccell::SyncCell,
|
||||||
};
|
};
|
||||||
use dioxus::core::{Element, Scope, ScopeState, VirtualDom};
|
use dioxus::core::{Element, Scope, VirtualDom};
|
||||||
use std::{mem, rc::Rc, sync::Arc};
|
use std::{mem, rc::Rc, sync::Arc};
|
||||||
|
|
||||||
pub fn tick_dioxus_ui(world: &mut World) {
|
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)]
|
#[derive(Deref, DerefMut)]
|
||||||
pub struct VirtualDomUnsafe(pub SyncCell<VirtualDom>);
|
pub struct VirtualDomUnsafe(pub SyncCell<VirtualDom>);
|
||||||
unsafe impl Send for VirtualDomUnsafe {}
|
unsafe impl Send for VirtualDomUnsafe {}
|
||||||
|
|
Loading…
Reference in a new issue