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

View file

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