Reduce warnings
This commit is contained in:
parent
834b06e34d
commit
418f8c51d6
9 changed files with 116 additions and 71 deletions
|
@ -229,7 +229,7 @@ pub enum ComponentRequestType {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ComponentNotFoundError {
|
pub struct ComponentNotFoundError {
|
||||||
request_type: ComponentRequestType,
|
pub request_type: ComponentRequestType,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ComponentNotFoundError {
|
impl ComponentNotFoundError {
|
||||||
|
|
|
@ -341,7 +341,7 @@ pub struct ArchetypeInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ArchetypeInfo {
|
impl ArchetypeInfo {
|
||||||
pub(crate) fn new(entities: Vec<(Entity, Option<String>)>) -> Self {
|
pub fn new(entities: Vec<(Entity, Option<String>)>) -> Self {
|
||||||
Self { entities }
|
Self { entities }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,7 +388,7 @@ impl Archetype {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn entities(
|
pub fn entities(
|
||||||
&self,
|
&self,
|
||||||
) -> &IndexMap<Entity, Box<dyn Fn(Entity, &mut World) -> Result<()> + Send + Sync>> {
|
) -> &IndexMap<Entity, Box<dyn Fn(Entity, &mut World) -> Result<()> + Send + Sync>> {
|
||||||
&self.entities
|
&self.entities
|
||||||
|
@ -572,12 +572,12 @@ impl Updates {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn clear(&mut self) {
|
// pub(crate) fn clear(&mut self) {
|
||||||
self.updates.clear();
|
// self.updates.clear();
|
||||||
|
|
||||||
#[cfg(feature = "timings")]
|
// #[cfg(feature = "timings")]
|
||||||
self.timings.clear();
|
// self.timings.clear();
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub(crate) fn add(&mut self, name: &str, priority: u32, update: Update) -> Result<()> {
|
pub(crate) fn add(&mut self, name: &str, priority: u32, update: Update) -> Result<()> {
|
||||||
#[cfg(feature = "timings")]
|
#[cfg(feature = "timings")]
|
||||||
|
|
|
@ -13,9 +13,7 @@ use crate::prelude::*;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct GuiHandlerRenderer {
|
pub struct GuiHandlerRenderer;
|
||||||
pub gui_handler: Arc<GuiHandler>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TScene for GuiHandlerRenderer {
|
impl TScene for GuiHandlerRenderer {
|
||||||
fn process(
|
fn process(
|
||||||
|
@ -23,9 +21,12 @@ impl TScene for GuiHandlerRenderer {
|
||||||
buffer_recorder: &mut CommandBufferRecorder<'_>,
|
buffer_recorder: &mut CommandBufferRecorder<'_>,
|
||||||
_images: &TargetMode<Vec<Arc<Image>>>,
|
_images: &TargetMode<Vec<Arc<Image>>>,
|
||||||
indices: &TargetMode<usize>,
|
indices: &TargetMode<usize>,
|
||||||
_world: &World,
|
world: &World,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.gui_handler.process(buffer_recorder, indices)
|
world
|
||||||
|
.resources
|
||||||
|
.get::<Arc<GuiHandler>>()
|
||||||
|
.process(buffer_recorder, indices)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resize(
|
fn resize(
|
||||||
|
@ -33,16 +34,17 @@ impl TScene for GuiHandlerRenderer {
|
||||||
window_width: f32,
|
window_width: f32,
|
||||||
window_height: f32,
|
window_height: f32,
|
||||||
images: &TargetMode<Vec<Arc<Image>>>,
|
images: &TargetMode<Vec<Arc<Image>>>,
|
||||||
|
world: &World,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.gui_handler
|
world.resources.get::<Arc<GuiHandler>>().resize(
|
||||||
.resize(window_width as u32, window_height as u32, images)
|
window_width as u32,
|
||||||
|
window_height as u32,
|
||||||
|
images,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Engine {
|
pub struct Engine {
|
||||||
// loads and keeps track of raw data
|
|
||||||
asset_manager: AssetManager,
|
|
||||||
|
|
||||||
pub(crate) resource_base_path: String,
|
pub(crate) resource_base_path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,14 +173,9 @@ impl Engine {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let asset_manager = AssetManager::new(&engine_settings)?;
|
let asset_manager = AssetManager::new(&engine_settings)?;
|
||||||
|
let gui_handler = GuiHandler::new(create_info.gui_info, &context)?;
|
||||||
let gui_handler = GuiHandlerRenderer {
|
|
||||||
gui_handler: GuiHandler::new(create_info.gui_info, &context)?,
|
|
||||||
};
|
|
||||||
|
|
||||||
let engine = Engine {
|
let engine = Engine {
|
||||||
asset_manager,
|
|
||||||
|
|
||||||
resource_base_path: create_info.resource_base_path,
|
resource_base_path: create_info.resource_base_path,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -205,7 +202,7 @@ impl Engine {
|
||||||
|
|
||||||
world.resources.insert(gui_handler);
|
world.resources.insert(gui_handler);
|
||||||
world.resources.insert(InputMap { direction_mapping });
|
world.resources.insert(InputMap { direction_mapping });
|
||||||
|
world.resources.insert(asset_manager);
|
||||||
world.resources.insert(engine);
|
world.resources.insert(engine);
|
||||||
world.resources.insert(engine_settings);
|
world.resources.insert(engine_settings);
|
||||||
world.resources.insert(scene);
|
world.resources.insert(scene);
|
||||||
|
@ -254,25 +251,18 @@ impl Engine {
|
||||||
|
|
||||||
impl Engine {
|
impl Engine {
|
||||||
fn main_system<T: EventConsumer>(world: &mut World) -> Result<bool> {
|
fn main_system<T: EventConsumer>(world: &mut World) -> Result<bool> {
|
||||||
let gui_handler = world.resources.get_unchecked::<GuiHandlerRenderer>();
|
let gui_handler = world.resources.get_unchecked::<Arc<GuiHandler>>();
|
||||||
let input_map = world.resources.get_unchecked::<InputMap>();
|
let input_map = world.resources.get_unchecked::<InputMap>();
|
||||||
let context = world.resources.get_unchecked::<Context>();
|
let context = world.resources.get_unchecked::<Context>();
|
||||||
|
|
||||||
let res = world.resources.get_mut_unchecked::<Context>().next_frame(
|
let res = world.resources.get_mut_unchecked::<Context>().next_frame(
|
||||||
world,
|
world,
|
||||||
|world, consumer: &mut T, event| {
|
|world, consumer: &mut T, event| {
|
||||||
Self::event(
|
Self::event(world, context, gui_handler, input_map, consumer, event)
|
||||||
world,
|
|
||||||
context,
|
|
||||||
&gui_handler.gui_handler,
|
|
||||||
input_map,
|
|
||||||
consumer,
|
|
||||||
event,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
gui_handler.gui_handler.process_callbacks()?;
|
gui_handler.process_callbacks()?;
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::prelude::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use utilities::{
|
use utilities::{
|
||||||
impl_reprc,
|
impl_reprc,
|
||||||
prelude::cgmath::{vec3, InnerSpace, Rad, Vector3, Zero},
|
prelude::cgmath::{InnerSpace, Rad, Vector3, Zero, vec3},
|
||||||
};
|
};
|
||||||
|
|
||||||
use utilities::prelude::cgmath::{Matrix4, SquareMatrix};
|
use utilities::prelude::cgmath::{Matrix4, SquareMatrix};
|
||||||
|
@ -127,15 +127,15 @@ pub struct Light {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Light {
|
impl Light {
|
||||||
pub(crate) fn point_light(device: &Arc<Device>) -> Result<Light> {
|
pub fn point_light(device: &Arc<Device>) -> Result<Light> {
|
||||||
Self::new(LightType::Point, device)
|
Self::new(LightType::Point, device)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn directional_light(device: &Arc<Device>) -> Result<Light> {
|
pub fn directional_light(device: &Arc<Device>) -> Result<Light> {
|
||||||
Self::new(LightType::Direction, device)
|
Self::new(LightType::Direction, device)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn spot_light(device: &Arc<Device>) -> Result<Light> {
|
pub fn spot_light(device: &Arc<Device>) -> Result<Light> {
|
||||||
Self::new(LightType::Spot, device)
|
Self::new(LightType::Spot, device)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ use super::super::timings::Timings;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use ecs::*;
|
use ecs::*;
|
||||||
use rayon::prelude::*;
|
|
||||||
use utilities::prelude::cgmath::{Matrix4, Vector3, vec3};
|
use utilities::prelude::cgmath::{Matrix4, Vector3, vec3};
|
||||||
|
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
@ -28,9 +27,6 @@ pub struct Scene {
|
||||||
screen_width: f32,
|
screen_width: f32,
|
||||||
screen_height: f32,
|
screen_height: f32,
|
||||||
|
|
||||||
device: Arc<Device>,
|
|
||||||
queue: Arc<Mutex<Queue>>,
|
|
||||||
|
|
||||||
render_type: SceneType,
|
render_type: SceneType,
|
||||||
|
|
||||||
last_frame: Duration,
|
last_frame: Duration,
|
||||||
|
@ -92,9 +88,6 @@ impl Scene {
|
||||||
|
|
||||||
render_type,
|
render_type,
|
||||||
|
|
||||||
device: device.clone(),
|
|
||||||
queue: queue.clone(),
|
|
||||||
|
|
||||||
frustum_check: None,
|
frustum_check: None,
|
||||||
|
|
||||||
renderer,
|
renderer,
|
||||||
|
@ -486,6 +479,7 @@ impl TScene for Scene {
|
||||||
window_width: f32,
|
window_width: f32,
|
||||||
window_height: f32,
|
window_height: f32,
|
||||||
images: &TargetMode<Vec<Arc<Image>>>,
|
images: &TargetMode<Vec<Arc<Image>>>,
|
||||||
|
_world: &World,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
self.screen_width = window_width;
|
self.screen_width = window_width;
|
||||||
self.screen_height = window_height;
|
self.screen_height = window_height;
|
||||||
|
|
|
@ -1,40 +1,60 @@
|
||||||
use context::prelude::*;
|
use context::prelude::*;
|
||||||
|
|
||||||
use std::{sync::Arc, thread};
|
use std::{
|
||||||
|
sync::{
|
||||||
|
Arc,
|
||||||
|
mpsc::{Receiver, channel},
|
||||||
|
},
|
||||||
|
thread,
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
pub struct LoadingScreen;
|
pub struct LoadingScreen<T: Send + Sync + 'static> {
|
||||||
|
result: Option<T>,
|
||||||
|
receiver: Receiver<T>,
|
||||||
|
}
|
||||||
|
|
||||||
impl LoadingScreen {
|
impl<T: Send + Sync + 'static> LoadingScreen<T> {
|
||||||
pub fn load<T, R, L, G>(
|
pub fn load<R, L, G>(gui: Arc<G>, loader: L) -> Result<Self>
|
||||||
context: &Arc<Context>,
|
|
||||||
gui: Option<Arc<G>>,
|
|
||||||
loader: L,
|
|
||||||
on_ready: R,
|
|
||||||
) -> Result<()>
|
|
||||||
where
|
where
|
||||||
R: Fn(T) -> Result<()> + Send + Sync + 'static,
|
R: Fn(T) -> Result<()> + Send + Sync + 'static,
|
||||||
T: Send + Sync + 'static,
|
T: Send + Sync + 'static,
|
||||||
L: FnOnce() -> T + Send + Sync + 'static,
|
L: FnOnce() -> T + Send + Sync + 'static,
|
||||||
G: TopLevelGui + TopGui + Send + Sync + 'static,
|
G: TopLevelGui + TopGui + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
if let Some(gui) = &gui {
|
|
||||||
gui.enable()?;
|
gui.enable()?;
|
||||||
}
|
|
||||||
|
|
||||||
let context = context.clone();
|
let (sender, receiver) = channel();
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let result = loader();
|
let _ = sender.send(loader());
|
||||||
if let Some(gui) = &gui {
|
let _ = gui.disable();
|
||||||
gui.disable().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
todo!();
|
|
||||||
// context.push_event(move || (on_ready)(result));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(Self {
|
||||||
|
result: None,
|
||||||
|
receiver,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check_ready(&mut self) -> bool {
|
||||||
|
if self.result.is_some() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
match self.receiver.try_recv() {
|
||||||
|
Ok(result) => {
|
||||||
|
self.result = Some(result);
|
||||||
|
true
|
||||||
|
}
|
||||||
|
Err(_) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Will panic if there is no result.
|
||||||
|
/// Use `check_ready` before calling this.
|
||||||
|
pub fn take_result(mut self) -> T {
|
||||||
|
self.result.take().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ impl SceneHandle {
|
||||||
world
|
world
|
||||||
.resources
|
.resources
|
||||||
.get_mut_unchecked::<T>()
|
.get_mut_unchecked::<T>()
|
||||||
.resize(width, height, images)
|
.resize(width, height, images, world)
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ pub trait TScene: Send + Sync + 'static {
|
||||||
window_width: f32,
|
window_width: f32,
|
||||||
window_height: f32,
|
window_height: f32,
|
||||||
images: &TargetMode<Vec<Arc<Image>>>,
|
images: &TargetMode<Vec<Arc<Image>>>,
|
||||||
|
world: &World,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@ impl<T: ExactSizeIterator<Item = PathBuf>> From<T> for SkyBoxImages {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SkyBox {
|
pub struct SkyBox {
|
||||||
|
enabled: bool,
|
||||||
|
|
||||||
_cube_map: Arc<Image>,
|
_cube_map: Arc<Image>,
|
||||||
cube_buffer: Arc<Buffer<VertexPoint>>,
|
cube_buffer: Arc<Buffer<VertexPoint>>,
|
||||||
|
|
||||||
|
@ -160,6 +162,8 @@ impl SkyBox {
|
||||||
.submit()?;
|
.submit()?;
|
||||||
|
|
||||||
let me = Self {
|
let me = Self {
|
||||||
|
enabled: true,
|
||||||
|
|
||||||
_cube_map: cube_map,
|
_cube_map: cube_map,
|
||||||
cube_buffer,
|
cube_buffer,
|
||||||
|
|
||||||
|
@ -175,6 +179,14 @@ impl SkyBox {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn enable(&mut self) {
|
||||||
|
self.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn disable(&mut self) {
|
||||||
|
self.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
fn create_render_target(
|
fn create_render_target(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
sample_count: VkSampleCountFlags,
|
sample_count: VkSampleCountFlags,
|
||||||
|
@ -256,6 +268,10 @@ impl TScene for SkyBox {
|
||||||
indices: &TargetMode<usize>,
|
indices: &TargetMode<usize>,
|
||||||
_world: &World,
|
_world: &World,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
if !self.enabled {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
self.render_target
|
self.render_target
|
||||||
.chain(indices)
|
.chain(indices)
|
||||||
.chain(&self.pipeline)
|
.chain(&self.pipeline)
|
||||||
|
@ -279,10 +295,34 @@ impl TScene for SkyBox {
|
||||||
|
|
||||||
fn resize(
|
fn resize(
|
||||||
&mut self,
|
&mut self,
|
||||||
window_width: f32,
|
_window_width: f32,
|
||||||
window_height: f32,
|
_window_height: f32,
|
||||||
images: &TargetMode<Vec<Arc<Image>>>,
|
_images: &TargetMode<Vec<Arc<Image>>>,
|
||||||
|
world: &World,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let sample_count = world
|
||||||
|
.resources
|
||||||
|
.get::<EngineSettings>()
|
||||||
|
.graphics_info()?
|
||||||
|
.sample_count;
|
||||||
|
|
||||||
|
let context = world.resources.get::<Context>();
|
||||||
|
|
||||||
|
let pipeline_layout = match &self.pipeline {
|
||||||
|
TargetMode::Mono(p) => p.pipeline_layout().clone(),
|
||||||
|
TargetMode::Stereo(p, _) => p.pipeline_layout().clone(),
|
||||||
|
};
|
||||||
|
|
||||||
|
self.render_target = Self::create_render_target(context, sample_count)?;
|
||||||
|
self.pipeline = Self::create_pipeline(
|
||||||
|
context,
|
||||||
|
sample_count,
|
||||||
|
&self.render_target,
|
||||||
|
&pipeline_layout,
|
||||||
|
&self.vertex_shader,
|
||||||
|
&self.fragment_shader,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue