Compare commits

...

3 commits

Author SHA1 Message Date
72fc88066d Update Rust crate rusqlite to 0.33.0 2025-03-01 06:02:36 +00:00
f90dfb6236 Rename crates 2025-03-01 06:43:44 +01:00
e22381b8e9 Get rendering somewhat working 2025-03-01 06:01:46 +01:00
29 changed files with 130 additions and 64 deletions

View file

@ -2,8 +2,8 @@
resolver = "2"
members = [
"ConfigHandler",
"Networking",
"config_handler",
"networking",
"asset",
"context",
"controllable_thread",
@ -34,7 +34,7 @@ chrono = { version = "0.4.35", features = ["serde"] }
anyhow = { version = "1.0.86", features = ["backtrace"] }
indexmap = { version = "2.2.6", features = ["rayon"] }
shaderc = { version = "0.8.3", features = ["build-from-source"] }
rusqlite = { version = "0.32.0", features = ["bundled"] }
rusqlite = { version = "0.33.0", features = ["bundled"] }
cgmath = "0.18.0"
http = "1.1.0"
iterchunks = "0.5.0"

View file

@ -86,17 +86,10 @@ impl VulkanCore {
// device extensions
let mut dev_exts = DeviceExtensions::default();
presentation_core.activate_vulkan_device_extensions(&mut dev_exts, &physical_device)?;
dev_exts.memory_requirements2 = true;
dev_exts.amd_rasterization_order = true;
dev_exts.descriptor_indexing = true;
dev_exts.maintenance3 = true;
dev_exts.ray_tracing_pipeline = true;
dev_exts.deferred_host_operations = true;
dev_exts.spirv_1_4 = true;
dev_exts.buffer_device_address = true;
dev_exts.acceleration_structure = true;
dev_exts.shader_float_controls = true;
dev_exts.pipeline_library = true;
if vulkan_debug_info.renderdoc {

View file

@ -17,7 +17,7 @@ utilities = { workspace = true }
assetpath = { workspace = true }
shaderc = { workspace = true }
config_handler = { path = "../ConfigHandler" }
config_handler = { path = "../config_handler" }
asset = { path = "../asset" }
loading_screen = { path = "../loading-screen" }
context = { path = "../context", features = ["bundle_sdl2", "sound"] }

View file

@ -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>);

View file

@ -9,13 +9,13 @@ use utilities::prelude::cgmath::{Vector3, Zero};
use super::{
super::{
shared::{bufferhandler::*, safecommandbuffer::SafeCommandBuffer},
ExtensionCheck, RasterizerDescriptorLayouts, RenderingFrontEnd,
shared::{bufferhandler::*, safecommandbuffer::SafeCommandBuffer},
},
SceneInfo,
lights::light_wrapper::LightHandler,
pipelines::RasterizerPipelines,
rasterizershader::RasterizerShader,
SceneInfo,
};
use deferredhandler::{DeferredHandler, FallbackInfo};
@ -352,10 +352,6 @@ impl Rasterizer {
impl ExtensionCheck for Rasterizer {
fn check(device: &Arc<Device>) -> bool {
if !device.enabled_extensions().descriptor_indexing {
return false;
}
let physical_device = device.physical_device();
if physical_device

View file

@ -5,12 +5,12 @@ use utilities::{impl_reprc, prelude::cgmath::Vector3};
use super::{
super::{
shared::position_buffer_reader::PositionBuffer, ExtensionCheck, RaytracerDesciptorLayouts,
RenderingFrontEnd,
ExtensionCheck, RaytracerDesciptorLayouts, RenderingFrontEnd,
shared::position_buffer_reader::PositionBuffer,
},
RenderingCore,
animator::ComputeBasedAnimator,
light::{LightData, RayTracerLight},
RenderingCore,
};
use std::sync::{Arc, Mutex};
@ -488,10 +488,6 @@ where
T: RenderingCore,
{
fn check(device: &Arc<Device>) -> bool {
if !device.enabled_extensions().descriptor_indexing {
return false;
}
let physical_device = device.physical_device();
if physical_device

View file

@ -9,3 +9,4 @@ anyhow.workspace = true
ecs = { path = "../../ecs" }
engine = { path = "../../engine" }
skybox = { path = "../../skybox" }

View file

@ -1,7 +1,10 @@
use std::path::Path;
use anyhow::Result;
use ecs::*;
use engine::prelude::*;
use skybox::SkyBox;
fn main() -> Result<()> {
let mut world_builder = World::builder();
@ -11,6 +14,20 @@ fn main() -> Result<()> {
world_builder.add_system(GameState::update);
world_builder.resources.insert(GameState::Startup);
let dir = Path::new("/home/michaelh/Sync/skybox");
SkyBox::new(
&mut world_builder,
[
dir.join("left.png"),
dir.join("right.png"),
dir.join("front.png"),
dir.join("back.png"),
dir.join("top.png"),
dir.join("bottom.png"),
]
.into_iter(),
)?;
world_builder.build().run()
}

View file

@ -7,7 +7,7 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
config_handler = { path = "../ConfigHandler" }
config_handler = { path = "../config_handler" }
anyhow = { workspace = true }
chrono = { workspace = true }

View file

@ -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);
}

View file

@ -33,9 +33,10 @@ pub struct SkyBox {
}
impl SkyBox {
pub fn new(world: &mut WorldBuilder, images: impl Into<SkyBoxImages>) -> Result<Self> {
pub fn new(world: &mut WorldBuilder, images: impl Into<SkyBoxImages>) -> Result<()> {
let images = images.into();
let context = world.resources.get::<Context>();
let context = world.resources.get_mut::<Context>();
context.render_core_mut().add_render_routine::<Self>(1);
let cube_map = Image::cube_map([
images.left.try_into()?,
@ -49,6 +50,30 @@ impl SkyBox {
.attach_pretty_sampler(context.device())?
.build(context.device(), context.queue())?;
Ok(Self { cube_map })
let me = Self { cube_map };
world.resources.insert(me);
Ok(())
}
}
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!()
}
}