From 420d386b855558f2c74881d0a897098a3b7c53ed Mon Sep 17 00:00:00 2001 From: Facundo Villa Date: Sun, 11 Feb 2024 03:10:23 -0300 Subject: [PATCH] Added listening for traits. --- src/core/entity.rs | 10 +- src/core/listener.rs | 65 +++++------ src/core/mod.rs | 11 +- src/core/orchestrator.rs | 107 +++++++++--------- src/gameplay/object.rs | 9 +- src/gameplay/space.rs | 10 +- src/input_manager.rs | 17 ++- src/physics/mod.rs | 11 +- src/rendering/renderer.rs | 8 +- src/rendering/ssgi_render_pass.rs | 4 +- .../visibility_model/render_domain.rs | 28 ++--- src/window_system.rs | 8 +- 12 files changed, 133 insertions(+), 155 deletions(-) diff --git a/src/core/entity.rs b/src/core/entity.rs index 59347fa6..e45be102 100644 --- a/src/core/entity.rs +++ b/src/core/entity.rs @@ -16,6 +16,10 @@ pub trait Entity: intertrait::CastFrom + downcast_rs::Downcast + std::any::Any + } fn get_traits(&self) -> Vec { vec![] } + + fn call_listeners(&self, listener: &BasicListener, handle: EntityHandle) where Self: Sized { + listener.invoke_for(handle, self); + } } pub unsafe fn get_entity_trait_for_type() -> EntityTrait { @@ -177,7 +181,7 @@ pub struct EntityBuilder<'c, T> { pub(super) subscribe_to: Vec) + 'c>>, } -impl <'c, T: 'static> EntityBuilder<'c, T> { +impl <'c, T: Entity + 'static> EntityBuilder<'c, T> { fn default(create: std::boxed::Box>) -> Self { Self { create, @@ -214,13 +218,13 @@ impl <'c, T: 'static> EntityBuilder<'c, T> { self } - pub fn listen_to(mut self,) -> Self where T: std::any::Any + EntitySubscriber + 'static, C: 'static { + pub fn listen_to(mut self,) -> Self where T: EntitySubscriber { self.listens_to.push(Box::new(move |domain_handle, e| { let l = domain_handle.write_sync(); let l = l.deref(); if let Some(l) = l.get_listener() { - l.add_listener::(e); + l.add_listener(e); } else { log::error!("Entity listens to but wasn't spawned in a domain."); } diff --git a/src/core/listener.rs b/src/core/listener.rs index ccbc5618..6f882dac 100644 --- a/src/core/listener.rs +++ b/src/core/listener.rs @@ -1,46 +1,47 @@ -use std::ops::{Deref, DerefMut}; +use std::{any::Any, borrow::Borrow, ops::{Deref, DerefMut}}; use intertrait::cast::CastMut; +use crate::utils; + use super::{entity::{get_entity_trait_for_type, EntityTrait, TraitObject}, Entity, EntityHandle}; pub trait Listener: Entity { /// Notifies all listeners of the given type that the given entity has been created. - fn invoke_for(&self, handle: EntityHandle); - fn invoke_for_trait(&self, handle: EntityHandle, r#type: EntityTrait); + fn invoke_for(&self, handle: EntityHandle, reference: &T); /// Subscribes the given listener `L` to the given entity type `T`. - fn add_listener(&self, listener: EntityHandle) where L: EntitySubscriber + 'static; + fn add_listener(&self, listener: EntityHandle>); } -pub trait EntitySubscriber { - fn on_create<'a>(&'a mut self, handle: EntityHandle, params: &T) -> impl std::future::Future; - fn on_update(&'static mut self, handle: EntityHandle, params: &T) -> impl std::future::Future; +pub trait EntitySubscriber: Entity { + fn on_create<'a>(&'a mut self, handle: EntityHandle, params: &'a T) -> utils::BoxedFuture<'a, ()>; } pub struct BasicListener { - listeners: std::sync::RwLock>, + listeners: std::sync::RwLock>>, } -struct List { - l: Vec)>>, +struct List { + /// List of listeners for a given entity type. (EntityHandle>) + listeners: Vec>>, } -impl List { +impl List { fn new() -> Self { List { - l: Vec::new(), + listeners: Vec::new(), } } - fn invoke_for(&self, listenee: EntityHandle) { - for f in &self.l { - f(listenee.clone()); + fn invoke_for(&self, listenee_handle: EntityHandle, listenee: &T) { + for f in &self.listeners { + smol::block_on(f.write_sync().deref_mut().on_create(listenee_handle.clone(), listenee)); } } - fn push(&mut self, f: Box)>) { - self.l.push(f); + fn push(&mut self, f: EntityHandle>) { + self.listeners.push(f); } } @@ -53,36 +54,24 @@ impl BasicListener { } impl Listener for BasicListener { - fn invoke_for(&self, handle: EntityHandle) { + fn invoke_for(&self, handle: EntityHandle, reference: &T) { let listeners = self.listeners.read().unwrap(); if let Some(listeners) = listeners.get(&unsafe { get_entity_trait_for_type::() }) { - listeners.invoke_for(handle); - } - } - - fn invoke_for_trait(&self, handle: EntityHandle, r#type: EntityTrait) { - let listeners = self.listeners.read().unwrap(); - - if let Some(listeners) = listeners.get(&r#type) { - listeners.invoke_for(handle); + if let Some(listeners) = listeners.downcast_ref::>() { + listeners.invoke_for(handle, reference); + } } } - fn add_listener(&self, listener: EntityHandle) where L: EntitySubscriber + 'static { + fn add_listener(&self, listener: EntityHandle>) { let mut listeners = self.listeners.write().unwrap(); - let listeners = listeners.entry(unsafe { get_entity_trait_for_type::() }).or_insert_with(|| List::new()); + let listeners = listeners.entry(unsafe { get_entity_trait_for_type::() }).or_insert_with(|| Box::new(List::::new())); - listeners.push(Box::new( - move |handle| { - if let Some(cast_handle) = handle.downcast::() { - let s = cast_handle.read_sync(); - let s = s.deref(); - smol::block_on(listener.write_sync().deref_mut().on_create(cast_handle, s)); - } - } - )); + if let Some(listeners) = listeners.downcast_mut::>() { + listeners.push(listener,); + } } } diff --git a/src/core/mod.rs b/src/core/mod.rs index eb833c1f..fb8b3e23 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -22,9 +22,8 @@ use self::entity::EntityTrait; struct NoneListener {} impl Listener for NoneListener { - fn invoke_for(&self, _: EntityHandle) {} - fn invoke_for_trait(&self, _: EntityHandle, _: EntityTrait) {} - fn add_listener(&self, _: EntityHandle) where L: EntitySubscriber + 'static { } + fn invoke_for(&self, _: EntityHandle, _: &T) {} + fn add_listener(&self, _: EntityHandle>) {} } impl Entity for NoneListener {} @@ -59,11 +58,7 @@ impl SpawnHandler for R { if let Some(listener) = listener { if let Some(listener) = listener.write_sync().deref().get_listener() { - for r#trait in traits { - listener.invoke_for_trait(handle.clone(), r#trait) - } - - listener.invoke_for(handle.clone()); + handle.read_sync().deref().call_listeners(listener, handle.clone()); } } diff --git a/src/core/orchestrator.rs b/src/core/orchestrator.rs index 97a8b119..6019a994 100644 --- a/src/core/orchestrator.rs +++ b/src/core/orchestrator.rs @@ -117,10 +117,10 @@ mod tests { } impl EntitySubscriber for System { - async fn on_create<'a>(&'a mut self, handle: EntityHandle, component: &Component) { + fn on_create<'a>(&'a mut self, handle: EntityHandle, component: &Component) -> utils::BoxedFuture<'a, ()> { + println!("Component created: {} {}", component.name, component.value); + Box::pin(async move { }) } - - async fn on_update(&'static mut self, handle: EntityHandle, params: &Component) {} } let _: EntityHandle = spawn(System::new()); @@ -156,13 +156,13 @@ mod tests { static mut COUNTER: u32 = 0; impl EntitySubscriber for System { - async fn on_create<'a>(&'a mut self, _: EntityHandle, _: &Component) { - unsafe { - COUNTER += 1; - } + fn on_create<'a>(&'a mut self, _: EntityHandle, _: &Component) -> utils::BoxedFuture<()> { + Box::pin(async move { + unsafe { + COUNTER += 1; + } + }) } - - async fn on_update(&'static mut self, _: EntityHandle, _: &Component) {} } let listener_handle = spawn(BasicListener::new()); @@ -176,65 +176,68 @@ mod tests { assert_eq!(unsafe { COUNTER }, 1); } - // #[test] - // fn listen_for_traits() { - // let orchestrator = Orchestrator::new_handle(); - - // trait Boo: Entity { - // fn get_name(&self) -> String; - // fn get_value(&self) -> u32; - // } + #[test] + fn listen_for_traits() { + let orchestrator = Orchestrator::new_handle(); - // struct Component { - // name: String, - // value: u32, - // } + trait Boo: Entity { + fn get_name(&self) -> String; + fn get_value(&self) -> u32; + } - // impl Entity for Component { - // fn get_traits(&self) -> Vec { vec![unsafe { get_entity_trait_for_type::() }] } - // } + struct Component { + name: String, + value: u32, + } - // impl Boo for Component { - // fn get_name(&self) -> String { self.name.clone() } - // fn get_value(&self) -> u32 { self.value } - // } + impl Entity for Component { + fn get_traits(&self) -> Vec { vec![unsafe { get_entity_trait_for_type::() }] } + fn call_listeners(&self, listener: &BasicListener, handle: EntityHandle) where Self: Sized { + // listener.invoke_for(handle); + listener.invoke_for(handle as EntityHandle, self); + } + } - // let handle: EntityHandle = spawn(Component { name: "test".to_string(), value: 1 }); + impl Boo for Component { + fn get_name(&self) -> String { self.name.clone() } + fn get_value(&self) -> u32 { self.value } + } - // struct System { + let handle: EntityHandle = spawn(Component { name: "test".to_string(), value: 1 }); - // } + struct System { - // impl Entity for System {} + } - // impl System { - // fn new() -> EntityBuilder<'static, System> { - // EntityBuilder::new(System {}).listen_to::() - // } - // } + impl Entity for System {} - // static mut COUNTER: u32 = 0; + impl System { + fn new() -> EntityBuilder<'static, System> { + EntityBuilder::new(System {}).listen_to::() + } + } - // impl EntitySubscriber for System { - // async fn on_create<'a>(&'a mut self, _: EntityHandle, _: &(dyn Boo + 'static)) { - // unsafe { - // COUNTER += 1; - // } - // } + static mut COUNTER: u32 = 0; - // async fn on_update(&'static mut self, _: EntityHandle, _: &(dyn Boo + 'static)) {} - // } + impl EntitySubscriber for System { + fn on_create<'a>(&'a mut self, _: EntityHandle, _: &(dyn Boo + 'static)) -> utils::BoxedFuture<'a, ()> { + unsafe { + COUNTER += 1; + } + Box::pin(async move { }) + } + } - // let listener_handle = spawn(BasicListener::new()); + let listener_handle = spawn(BasicListener::new()); - // let _: EntityHandle = spawn_as_child(listener_handle.clone(), System::new()); + let _: EntityHandle = spawn_as_child(listener_handle.clone(), System::new()); - // assert_eq!(unsafe { COUNTER }, 0); + assert_eq!(unsafe { COUNTER }, 0); - // let component: EntityHandle = spawn_as_child(listener_handle.clone(), Component { name: "test".to_string(), value: 1 }); + let component: EntityHandle = spawn_as_child(listener_handle.clone(), Component { name: "test".to_string(), value: 1 }); - // assert_eq!(unsafe { COUNTER }, 1); - // } + assert_eq!(unsafe { COUNTER }, 1); + } #[test] fn events() { diff --git a/src/gameplay/object.rs b/src/gameplay/object.rs index eddab161..453b7156 100644 --- a/src/gameplay/object.rs +++ b/src/gameplay/object.rs @@ -1,6 +1,6 @@ use maths_rs::mat::{MatScale, MatTranslate}; -use crate::{core::{entity::{get_entity_trait_for_type, EntityBuilder, EntityTrait}, event::Event, spawn, spawn_as_child, Entity, EntityHandle}, physics, rendering::mesh, Vector3}; +use crate::{core::{entity::{get_entity_trait_for_type, EntityBuilder, EntityTrait}, event::Event, listener::{BasicListener, EntitySubscriber, Listener}, spawn, spawn_as_child, Entity, EntityHandle}, physics, rendering::mesh, Vector3}; pub struct Object { position: Vector3, @@ -25,6 +25,13 @@ impl Object { impl Entity for Object { fn get_traits(&self) -> Vec { vec![unsafe { get_entity_trait_for_type::() }] } + + fn call_listeners(&self, listener: &BasicListener, handle: EntityHandle,) where Self: Sized { + let s: EntityHandle = handle.clone(); + + listener.invoke_for(handle, self); + listener.invoke_for(s, self); + } } impl physics::PhysicsEntity for Object { diff --git a/src/gameplay/space.rs b/src/gameplay/space.rs index 0e42fb84..884094a1 100644 --- a/src/gameplay/space.rs +++ b/src/gameplay/space.rs @@ -17,14 +17,12 @@ impl Domain for Space { } impl Listener for Space { - fn invoke_for(&self, handle: EntityHandle) { - self.listener.invoke_for(handle); + fn invoke_for(&self, handle: EntityHandle, reference: &T) { + self.listener.invoke_for(handle, reference); } - fn invoke_for_trait(&self, handle: EntityHandle, r#type: EntityTrait) { self.listener.invoke_for_trait(handle, r#type); } - - fn add_listener(&self, listener: EntityHandle) where L: EntitySubscriber + 'static { - self.listener.add_listener::(listener); + fn add_listener(&self, listener: EntityHandle>) { + self.listener.add_listener::(listener); } } diff --git a/src/input_manager.rs b/src/input_manager.rs index b1c80698..3069e533 100644 --- a/src/input_manager.rs +++ b/src/input_manager.rs @@ -21,7 +21,7 @@ use std::{f32::consts::PI, collections::HashMap}; use log::warn; -use crate::{RGBA, Vector2, Vector3, insert_return_length, Quaternion, core::{entity::EntityBuilder, listener::{Listener, EntitySubscriber}, orchestrator::{self, }, property::Property, Entity, EntityHandle}}; +use crate::{core::{entity::EntityBuilder, listener::{EntitySubscriber, Listener}, orchestrator, property::Property, Entity, EntityHandle}, insert_return_length, utils, Quaternion, Vector2, Vector3, RGBA}; /// A device class represents a type of device. Such as a keyboard, mouse, or gamepad. /// It can have associated input sources, such as the UP key on a keyboard or the left trigger on a gamepad. @@ -832,7 +832,7 @@ impl InputManager { } impl EntitySubscriber> for InputManager { - async fn on_create<'a>(&'a mut self, handle: EntityHandle>, action: &Action) { + fn on_create<'a>(&'a mut self, handle: EntityHandle>, action: &Action) -> utils::BoxedFuture<()> { let (name, r#type, input_events,) = (action.name, Types::Bool, &action.bindings); let input_event = InputAction { @@ -850,14 +850,13 @@ impl EntitySubscriber> for InputManager { }; self.actions.push(input_event); - } - async fn on_update(&'static mut self, handle: EntityHandle>, params: &Action) { + Box::pin(async {}) } } impl EntitySubscriber> for InputManager { - async fn on_create<'a>(&'a mut self, handle: EntityHandle>, action: &Action>) { + fn on_create<'a>(&'a mut self, handle: EntityHandle>, action: &Action>) -> utils::BoxedFuture<()> { let (name, r#type, input_events,) = (action.name, Types::Vector2, &action.bindings); let input_event = InputAction { @@ -875,14 +874,13 @@ impl EntitySubscriber> for InputManager { }; self.actions.push(input_event); - } - async fn on_update(&'static mut self, handle: EntityHandle>, params: &Action) { + Box::pin(async {}) } } impl EntitySubscriber> for InputManager { - async fn on_create<'a>(&'a mut self, handle: EntityHandle>, action: &Action>) { + fn on_create<'a>(&'a mut self, handle: EntityHandle>, action: &Action>) -> utils::BoxedFuture<()> { let (name, r#type, input_events,) = (action.name, Types::Vector3, &action.bindings); let input_event = InputAction { @@ -900,9 +898,8 @@ impl EntitySubscriber> for InputManager { }; self.actions.push(input_event); - } - async fn on_update(&'static mut self, handle: EntityHandle>, params: &Action) { + Box::pin(async {}) } } diff --git a/src/physics/mod.rs b/src/physics/mod.rs index 947fb957..aee843dc 100644 --- a/src/physics/mod.rs +++ b/src/physics/mod.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use maths_rs::{Vec3f, mag}; -use crate::core::{entity::{EntityBuilder, EntityHash}, event::{Event, EventLike,}, listener::{EntitySubscriber, Listener}, orchestrator::{self, EventDescription,}, property::Property, Entity, EntityHandle}; +use crate::{core::{entity::{EntityBuilder, EntityHash}, event::{Event, EventLike,}, listener::{EntitySubscriber, Listener}, orchestrator::{self, EventDescription,}, property::Property, Entity, EntityHandle}, utils}; pub trait PhysicsEntity: Entity { fn on_collision(&mut self) -> &mut Event>; @@ -58,7 +58,7 @@ impl PhysicsWorld { } pub fn new_as_system<'c>() -> EntityBuilder<'c, Self> { - EntityBuilder::new(Self::new())/*.listen_to::()*/ + EntityBuilder::new(Self::new()).listen_to::() } fn add_sphere(&mut self, sphere: InternalSphere) -> usize { @@ -98,12 +98,9 @@ impl PhysicsWorld { impl Entity for PhysicsWorld {} impl EntitySubscriber for PhysicsWorld { - async fn on_create<'a>(&'a mut self, handle: EntityHandle, params: &dyn PhysicsEntity) { + fn on_create<'a>(&'a mut self, handle: EntityHandle, params: &dyn PhysicsEntity) -> utils::BoxedFuture<()> { let index = self.add_sphere(InternalSphere{ position: params.get_position(), velocity: params.get_velocity(), radius: 1.0f32, handle: handle.clone() }); self.spheres_map.insert(EntityHash::from(&handle), index); - } - - async fn on_update(&'static mut self, handle: EntityHandle, params: &dyn PhysicsEntity) { - + Box::pin(async move {}) } } \ No newline at end of file diff --git a/src/rendering/renderer.rs b/src/rendering/renderer.rs index 0ce573f1..411fc8e0 100644 --- a/src/rendering/renderer.rs +++ b/src/rendering/renderer.rs @@ -1,6 +1,6 @@ use std::{ops::{DerefMut, Deref}, rc::Rc, sync::RwLock}; -use crate::{core::{self, orchestrator::{self,}, Entity, EntityHandle, listener::{Listener, EntitySubscriber}, entity::EntityBuilder}, window_system::{self, WindowSystem}, Extent, resource_management::resource_manager::ResourceManager, ghi::{self, GraphicsHardwareInterface}, ui::render_model::UIRenderModel}; +use crate::{core::{self, entity::EntityBuilder, listener::{EntitySubscriber, Listener}, orchestrator, Entity, EntityHandle}, ghi::{self, GraphicsHardwareInterface}, resource_management::resource_manager::ResourceManager, ui::render_model::UIRenderModel, utils, window_system::{self, WindowSystem}, Extent}; use super::{aces_tonemap_render_pass::AcesToneMapPass, shadow_render_pass::ShadowRenderingPass, ssao_render_pass::ScreenSpaceAmbientOcclusionPass, tonemap_render_pass::ToneMapRenderPass, visibility_model::render_domain::VisibilityWorldRenderDomain, world_render_domain::WorldRenderDomain}; @@ -135,7 +135,7 @@ impl Renderer { } impl EntitySubscriber for Renderer { - async fn on_create<'a>(&'a mut self, handle: EntityHandle, window: &window_system::Window) { + fn on_create<'a>(&'a mut self, handle: EntityHandle, window: &window_system::Window) -> utils::BoxedFuture<()> { let os_handles = self.window_system.map(|e| { let e = e.read_sync(); e.get_os_handles(&handle) @@ -146,10 +146,8 @@ impl EntitySubscriber for Renderer { let swapchain_handle = ghi.bind_to_window(&os_handles); self.swapchain_handles.push(swapchain_handle); - } - async fn on_update(&'static mut self, handle: EntityHandle, params: &window_system::Window) { - + Box::pin(async move {}) } } diff --git a/src/rendering/ssgi_render_pass.rs b/src/rendering/ssgi_render_pass.rs index 22372509..261e4887 100644 --- a/src/rendering/ssgi_render_pass.rs +++ b/src/rendering/ssgi_render_pass.rs @@ -1,7 +1,7 @@ //! SSGI Render Pass //! This module contains the implementation of the Screen Space Global Illumination (SSGI) render pass. -use crate::{core::entity::EntityBuilder, ghi, shader_generator, Extent}; +use crate::{core::{entity::EntityBuilder, Entity}, ghi, shader_generator, Extent}; use super::shader_strings; @@ -16,6 +16,8 @@ pub struct SSGIRenderPass { ray_march: ghi::PipelineHandle, } +impl Entity for SSGIRenderPass {} + impl SSGIRenderPass { pub fn new(ghi: &mut dyn ghi::GraphicsHardwareInterface) -> EntityBuilder<'static, Self> { let normals = ghi.create_image(Some("Normals"), Extent::rectangle(1920, 1080), ghi::Formats::RGBA8(ghi::Encodings::SignedNormalized), None, ghi::Uses::Image, ghi::DeviceAccesses::GpuRead | ghi::DeviceAccesses::GpuWrite, ghi::UseCases::DYNAMIC); diff --git a/src/rendering/visibility_model/render_domain.rs b/src/rendering/visibility_model/render_domain.rs index c16c52be..d654b4f4 100644 --- a/src/rendering/visibility_model/render_domain.rs +++ b/src/rendering/visibility_model/render_domain.rs @@ -667,12 +667,9 @@ impl VisibilityWorldRenderDomain { } impl EntitySubscriber for VisibilityWorldRenderDomain { - async fn on_create<'a>(&'a mut self, handle: EntityHandle, camera: &camera::Camera) { + fn on_create<'a>(&'a mut self, handle: EntityHandle, camera: &camera::Camera) -> utils::BoxedFuture<()> { self.camera = Some(handle); - } - - async fn on_update(&'static mut self, handle: EntityHandle, params: &camera::Camera) { - + Box::pin(async move {}) } } @@ -727,8 +724,8 @@ struct MaterialData { } impl EntitySubscriber for VisibilityWorldRenderDomain { - async fn on_create<'a>(&'a mut self, handle: EntityHandle, mesh: &mesh::Mesh) { - + fn on_create<'a>(&'a mut self, handle: EntityHandle, mesh: &'a mesh::Mesh) -> utils::BoxedFuture<'a, ()> { + Box::pin(async move { if !self.material_evaluation_materials.contains_key(mesh.get_material_id()) { let response_and_data = { let resource_manager = self.resource_manager.read().await; @@ -932,15 +929,12 @@ impl EntitySubscriber for VisibilityWorldRenderDomain { assert!((self.visibility_info.vertex_count as usize) < MAX_VERTICES, "Vertex count exceeded"); assert!((self.visibility_info.vertex_count as usize) < MAX_PRIMITIVE_TRIANGLES, "Primitive triangle count exceeded"); assert!((self.visibility_info.triangle_count as usize) < MAX_TRIANGLES, "Triangle count exceeded"); - } - - async fn on_update(&'static mut self, handle: EntityHandle, params: &mesh::Mesh) { - + }) } } impl EntitySubscriber for VisibilityWorldRenderDomain { - async fn on_create<'a>(&'a mut self, handle: EntityHandle, light: &directional_light::DirectionalLight) { + fn on_create<'a>(&'a mut self, handle: EntityHandle, light: &directional_light::DirectionalLight) -> utils::BoxedFuture<()> { let ghi = self.ghi.write().unwrap(); let lighting_data = unsafe { (ghi.get_mut_buffer_slice(self.light_data_buffer).as_mut_ptr() as *mut LightingData).as_mut().unwrap() }; @@ -967,15 +961,13 @@ impl EntitySubscriber for VisibilityWorldRe self.lights.push(lighting_data.lights[light_index]); assert!(lighting_data.count < MAX_LIGHTS as u32, "Light count exceeded"); - } - async fn on_update(&'static mut self, handle: EntityHandle, params: &directional_light::DirectionalLight) { - + Box::pin(async move { }) } } impl EntitySubscriber for VisibilityWorldRenderDomain { - async fn on_create<'a>(&'a mut self, handle: EntityHandle, light: &point_light::PointLight) { + fn on_create<'a>(&'a mut self, handle: EntityHandle, light: &point_light::PointLight) -> utils::BoxedFuture<()> { let ghi = self.ghi.write().unwrap(); let lighting_data = unsafe { (ghi.get_mut_buffer_slice(self.light_data_buffer).as_mut_ptr() as *mut LightingData).as_mut().unwrap() }; @@ -992,10 +984,8 @@ impl EntitySubscriber for VisibilityWorldRenderDomain { lighting_data.count += 1; assert!(lighting_data.count < MAX_LIGHTS as u32, "Light count exceeded"); - } - async fn on_update(&'static mut self, handle: EntityHandle, params: &point_light::PointLight) { - + Box::pin(async move { }) } } diff --git a/src/window_system.rs b/src/window_system.rs index 9a51a909..62a3f247 100644 --- a/src/window_system.rs +++ b/src/window_system.rs @@ -6,7 +6,7 @@ use component_derive::component; use log::trace; use xcb::{Xid, x}; -use crate::{Extent, core::{orchestrator::{ self}, Entity, EntityHandle, listener::{Listener, EntitySubscriber}, entity::EntityBuilder}}; +use crate::{core::{entity::EntityBuilder, listener::{EntitySubscriber, Listener}, orchestrator, Entity, EntityHandle}, utils, Extent}; #[derive(Debug, Clone, Copy)] /// The keys that can be pressed on a keyboard. @@ -700,12 +700,10 @@ impl WindowSystem { } impl EntitySubscriber for WindowSystem { - async fn on_create<'a>(&'a mut self, handle: EntityHandle, _window: &Window) { + fn on_create<'a>(&'a mut self, handle: EntityHandle, _window: &Window) -> utils::BoxedFuture<()> { let h = self.create_window(handle, "Main Window", Extent { width: 1920, height: 1080, depth: 1 }, "main_window"); - } - async fn on_update(&'static mut self, handle: EntityHandle, params: &Window) { - + Box::pin(async move { }) } }