2024-01-05 01:52:47 +00:00
|
|
|
use std::ptr::NonNull;
|
|
|
|
|
2024-03-03 02:37:21 +00:00
|
|
|
use lyra_ecs::{World, Entity};
|
2024-01-05 01:52:47 +00:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct ScriptEntity(pub Entity);
|
|
|
|
|
2024-01-07 05:57:19 +00:00
|
|
|
impl std::ops::Deref for ScriptEntity {
|
|
|
|
type Target = Entity;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-05 01:52:47 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct ScriptWorldPtr {
|
|
|
|
pub inner: NonNull<World>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ScriptWorldPtr {
|
|
|
|
/// Creates a world pointer from a world borrow.
|
|
|
|
pub fn from_ref(world: &World) -> Self {
|
|
|
|
Self {
|
|
|
|
inner: NonNull::from(world),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a borrow to the world from the ptr.
|
|
|
|
pub fn as_ref(&self) -> &World {
|
|
|
|
unsafe { self.inner.as_ref() }
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a mutable borrow to the world from the ptr.
|
|
|
|
pub fn as_mut(&mut self) -> &mut World {
|
|
|
|
unsafe { self.inner.as_mut() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::ops::Deref for ScriptWorldPtr {
|
|
|
|
type Target = NonNull<World>;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.inner
|
|
|
|
}
|
|
|
|
}
|