Get rendering somewhat working
This commit is contained in:
parent
0daf0a858a
commit
e22381b8e9
3 changed files with 95 additions and 36 deletions
|
@ -176,33 +176,18 @@ impl Engine {
|
|||
gui_handler: GuiHandler::new(create_info.gui_info, &context)?,
|
||||
};
|
||||
|
||||
context
|
||||
.render_core_mut()
|
||||
.add_render_routine::<GuiHandlerRenderer>(10_000_000);
|
||||
|
||||
world.resources.insert(gui_handler);
|
||||
|
||||
// default keyboard navigation
|
||||
let mut direction_mapping = HashMap::new();
|
||||
// direction_mapping.insert(Keycode::A, GuiDirection::Left);
|
||||
// direction_mapping.insert(Keycode::D, GuiDirection::Right);
|
||||
// direction_mapping.insert(Keycode::W, GuiDirection::Up);
|
||||
// direction_mapping.insert(Keycode::S, GuiDirection::Down);
|
||||
direction_mapping.insert(Keycode::Left, GuiDirection::Left);
|
||||
direction_mapping.insert(Keycode::Right, GuiDirection::Right);
|
||||
direction_mapping.insert(Keycode::Up, GuiDirection::Up);
|
||||
direction_mapping.insert(Keycode::Down, GuiDirection::Down);
|
||||
|
||||
let engine = Engine {
|
||||
asset_manager,
|
||||
|
||||
resource_base_path: create_info.resource_base_path,
|
||||
};
|
||||
|
||||
world.resources.insert(InputMap { direction_mapping });
|
||||
context
|
||||
.render_core_mut()
|
||||
.add_render_routine::<GuiHandlerRenderer>(10_000_000);
|
||||
context.render_core_mut().add_render_routine::<Scene>(100);
|
||||
|
||||
world.resources.insert(context);
|
||||
world.resources.insert(engine);
|
||||
world.resources.insert(engine_settings);
|
||||
|
||||
let scene = Scene::new(
|
||||
create_info.rasterizer_info,
|
||||
|
@ -211,6 +196,18 @@ impl Engine {
|
|||
world,
|
||||
)?;
|
||||
|
||||
// default keyboard navigation
|
||||
let mut direction_mapping = HashMap::new();
|
||||
direction_mapping.insert(Keycode::Left, GuiDirection::Left);
|
||||
direction_mapping.insert(Keycode::Right, GuiDirection::Right);
|
||||
direction_mapping.insert(Keycode::Up, GuiDirection::Up);
|
||||
direction_mapping.insert(Keycode::Down, GuiDirection::Down);
|
||||
|
||||
world.resources.insert(gui_handler);
|
||||
world.resources.insert(InputMap { direction_mapping });
|
||||
|
||||
world.resources.insert(engine);
|
||||
world.resources.insert(engine_settings);
|
||||
world.resources.insert(scene);
|
||||
|
||||
world.add_system(Self::main_system::<T>);
|
||||
|
|
|
@ -49,6 +49,52 @@ impl Default for VRTransformations {
|
|||
}
|
||||
}
|
||||
|
||||
struct SceneHandle {
|
||||
type_id: TypeId,
|
||||
priority: u32,
|
||||
|
||||
render: Box<
|
||||
dyn FnMut(
|
||||
&mut CommandBufferRecorder<'_>,
|
||||
&TargetMode<Vec<Arc<Image>>>,
|
||||
&TargetMode<usize>,
|
||||
&mut World,
|
||||
) -> Result<()>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
>,
|
||||
|
||||
resize: Box<
|
||||
dyn FnMut(f32, f32, &TargetMode<Vec<Arc<Image>>>, &mut World) -> Result<()>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
>,
|
||||
}
|
||||
|
||||
impl SceneHandle {
|
||||
fn new<T: TScene>(priority: u32) -> Self {
|
||||
Self {
|
||||
type_id: TypeId::of::<T>(),
|
||||
priority,
|
||||
render: Box::new(|recorder, images, indices, world| {
|
||||
world
|
||||
.resources
|
||||
.get_mut_unchecked::<T>()
|
||||
.process(recorder, images, indices, world)
|
||||
}),
|
||||
|
||||
resize: Box::new(|width, height, images, world| {
|
||||
world
|
||||
.resources
|
||||
.get_mut_unchecked::<T>()
|
||||
.resize(width, height, images)
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RenderBackend {
|
||||
device: Arc<Device>,
|
||||
queue: Arc<Mutex<Queue>>,
|
||||
|
@ -61,7 +107,7 @@ pub struct RenderBackend {
|
|||
|
||||
command_buffer: Arc<CommandBuffer>,
|
||||
|
||||
render_routines: Vec<(u32, TypeId)>,
|
||||
render_routines: Vec<SceneHandle>,
|
||||
}
|
||||
|
||||
impl RenderBackend {
|
||||
|
@ -169,17 +215,13 @@ impl RenderBackend {
|
|||
// make a call to the connected scenes
|
||||
self.render_routines
|
||||
.iter_mut()
|
||||
.try_for_each(|(_, type_id)| -> Result<()> {
|
||||
let scene: &mut dyn TScene = world.resources.get_mut_by_type_id_untyped(*type_id);
|
||||
|
||||
scene.process(
|
||||
.try_for_each(|scene_handle| {
|
||||
(scene_handle.render)(
|
||||
&mut buffer_recorder,
|
||||
&*self.swapchain_images.lock().unwrap(),
|
||||
&image_indices,
|
||||
world,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(&self.command_buffer)
|
||||
|
@ -205,10 +247,8 @@ impl RenderBackend {
|
|||
|
||||
self.render_routines
|
||||
.iter_mut()
|
||||
.try_for_each(|(_, type_id)| -> Result<()> {
|
||||
let scene: &mut dyn TScene = world.resources.get_mut_by_type_id_untyped(*type_id);
|
||||
|
||||
scene.resize(width as f32, height as f32, &images)
|
||||
.try_for_each(|scene_handle| {
|
||||
(scene_handle.resize)(width as f32, height as f32, &images, world)
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
|
@ -216,15 +256,16 @@ impl RenderBackend {
|
|||
|
||||
/// lower priority means it is more important
|
||||
pub fn add_render_routine<T: TScene>(&mut self, priority: u32) {
|
||||
self.render_routines.push((priority, TypeId::of::<T>()));
|
||||
self.render_routines.sort_by_key(|(p, _)| *p);
|
||||
self.render_routines.push(SceneHandle::new::<T>(priority));
|
||||
self.render_routines
|
||||
.sort_by_key(|scene_handle| scene_handle.priority);
|
||||
}
|
||||
|
||||
pub fn remove_render_routine<T: TScene>(&mut self) {
|
||||
if let Some(&(index, _)) = self
|
||||
if let Some(index) = self
|
||||
.render_routines
|
||||
.iter()
|
||||
.find(|(_, type_id)| *type_id == TypeId::of::<T>())
|
||||
.position(|scene_handle| scene_handle.type_id == TypeId::of::<T>())
|
||||
{
|
||||
self.render_routines.remove(index as usize);
|
||||
}
|
||||
|
|
|
@ -52,3 +52,24 @@ impl SkyBox {
|
|||
Ok(Self { cube_map })
|
||||
}
|
||||
}
|
||||
|
||||
impl TScene for SkyBox {
|
||||
fn process(
|
||||
&mut self,
|
||||
buffer_recorder: &mut CommandBufferRecorder<'_>,
|
||||
images: &TargetMode<Vec<Arc<Image>>>,
|
||||
indices: &TargetMode<usize>,
|
||||
world: &World,
|
||||
) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn resize(
|
||||
&mut self,
|
||||
window_width: f32,
|
||||
window_height: f32,
|
||||
images: &TargetMode<Vec<Arc<Image>>>,
|
||||
) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue