Expose device and queue via trait

This commit is contained in:
hodasemi 2024-08-31 17:01:42 +02:00
parent 27fc2fc1ea
commit 246234574d
2 changed files with 36 additions and 8 deletions

View file

@ -178,14 +178,6 @@ impl Scene {
Ok(scene) Ok(scene)
} }
pub fn device(&self) -> &Arc<Device> {
&self.device
}
pub fn queue(&self) -> &Arc<Mutex<Queue>> {
&self.queue
}
} }
// object handling // object handling
@ -258,6 +250,8 @@ impl Scene {
pub fn as_scene_contents(&mut self) -> SceneContents<'_> { pub fn as_scene_contents(&mut self) -> SceneContents<'_> {
SceneContents::new( SceneContents::new(
&self.device,
&self.queue,
self.render_type, self.render_type,
self.frame_time, self.frame_time,
self.start_time, self.start_time,
@ -275,6 +269,8 @@ impl Scene {
let mut temp_events = self.events.clone_from_register(); let mut temp_events = self.events.clone_from_register();
let mut scene_content = SceneContents::new( let mut scene_content = SceneContents::new(
&self.device,
&self.queue,
self.render_type, self.render_type,
self.frame_time, self.frame_time,
self.start_time, self.start_time,
@ -328,6 +324,8 @@ impl Scene {
pub fn execute_archetype(&mut self, name: impl ToString) -> Result<()> { pub fn execute_archetype(&mut self, name: impl ToString) -> Result<()> {
let mut scene_content = SceneContents::new( let mut scene_content = SceneContents::new(
&self.device,
&self.queue,
self.render_type, self.render_type,
self.frame_time, self.frame_time,
self.start_time, self.start_time,
@ -657,6 +655,14 @@ impl Scene {
} }
impl SceneEntities for Scene { impl SceneEntities for Scene {
fn device(&self) -> &Arc<Device> {
&self.device
}
fn queue(&self) -> &Arc<Mutex<Queue>> {
&self.queue
}
fn entity(&self, entity: Entity) -> std::result::Result<&EntityObject, EntityNotFoundError> { fn entity(&self, entity: Entity) -> std::result::Result<&EntityObject, EntityNotFoundError> {
self.entities self.entities
.get(&entity) .get(&entity)
@ -810,6 +816,8 @@ impl SceneEntities for Scene {
let p = map as *const Box<dyn Map> as *mut Box<dyn Map>; let p = map as *const Box<dyn Map> as *mut Box<dyn Map>;
let mut scene_content = SceneContents::new( let mut scene_content = SceneContents::new(
&self.device,
&self.queue,
self.render_type, self.render_type,
self.frame_time, self.frame_time,
self.start_time, self.start_time,

View file

@ -2,6 +2,7 @@ use std::{
any::{Any, TypeId}, any::{Any, TypeId},
collections::HashMap, collections::HashMap,
ptr::NonNull, ptr::NonNull,
sync::{Arc, Mutex},
time::{Duration, Instant}, time::{Duration, Instant},
}; };
@ -36,6 +37,9 @@ impl std::fmt::Display for EntityNotFoundError {
impl std::error::Error for EntityNotFoundError {} impl std::error::Error for EntityNotFoundError {}
pub trait SceneEntities { pub trait SceneEntities {
fn device(&self) -> &Arc<Device>;
fn queue(&self) -> &Arc<Mutex<Queue>>;
fn entity(&self, entity: Entity) -> std::result::Result<&EntityObject, EntityNotFoundError>; fn entity(&self, entity: Entity) -> std::result::Result<&EntityObject, EntityNotFoundError>;
fn entity_mut( fn entity_mut(
&mut self, &mut self,
@ -92,6 +96,9 @@ enum ComponentChange {
} }
pub struct SceneContents<'a> { pub struct SceneContents<'a> {
device: &'a Arc<Device>,
queue: &'a Arc<Mutex<Queue>>,
render_type: SceneType, render_type: SceneType,
frame_time: Duration, frame_time: Duration,
@ -113,6 +120,8 @@ pub struct SceneContents<'a> {
impl<'a> SceneContents<'a> { impl<'a> SceneContents<'a> {
pub(crate) fn new( pub(crate) fn new(
device: &'a Arc<Device>,
queue: &'a Arc<Mutex<Queue>>,
render_type: SceneType, render_type: SceneType,
frame_time: Duration, frame_time: Duration,
start_time: Instant, start_time: Instant,
@ -128,6 +137,9 @@ impl<'a> SceneContents<'a> {
resources: &'a mut Resources, resources: &'a mut Resources,
) -> Self { ) -> Self {
Self { Self {
device,
queue,
screen_extents, screen_extents,
frame_time, frame_time,
@ -345,6 +357,14 @@ impl EntityChanges {
} }
impl<'a> SceneEntities for SceneContents<'a> { impl<'a> SceneEntities for SceneContents<'a> {
fn device(&self) -> &Arc<Device> {
&self.device
}
fn queue(&self) -> &Arc<Mutex<Queue>> {
&self.queue
}
fn entity(&self, entity: Entity) -> std::result::Result<&EntityObject, EntityNotFoundError> { fn entity(&self, entity: Entity) -> std::result::Result<&EntityObject, EntityNotFoundError> {
self.entities.entity(entity) self.entities.entity(entity)
} }