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