wip
This commit is contained in:
parent
cc7921a5fe
commit
3692736a61
22 changed files with 447 additions and 44 deletions
|
|
@ -12,7 +12,7 @@ use raidillon_assets::model_manager::ModelID;
|
|||
|
||||
/// Glium platform asset manager implementation.
|
||||
pub struct GliumAssetManager {
|
||||
pub models: HashMap<PathBuf, Model>,
|
||||
pub models: HashMap<ModelID, Model>,
|
||||
facade: Box<dyn Facade>,
|
||||
}
|
||||
|
||||
|
|
@ -27,13 +27,13 @@ impl GliumAssetManager {
|
|||
}
|
||||
|
||||
impl ModelManager for GliumAssetManager {
|
||||
fn load_gltf(&mut self, path: &Path) {
|
||||
fn load_gltf(&mut self, id: ModelID, path: &Path) {
|
||||
let model = load_gltf(path, self.facade.as_ref()).unwrap();
|
||||
self.models.insert(path.to_path_buf(), model);
|
||||
self.models.insert(id, model);
|
||||
}
|
||||
|
||||
fn unload_model(&mut self, path: &Path) {
|
||||
self.models.remove(&path.to_path_buf());
|
||||
fn unload_model(&mut self, id: ModelID) {
|
||||
self.models.remove(&id);
|
||||
}
|
||||
|
||||
// fn get_model(&mut self, path: &Path) -> &Self::Model {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::cell::RefCell;
|
|||
use std::rc::Rc;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use raidillon_platform::Platform;
|
||||
use raidillon_platform::{Platform, PlatformContext};
|
||||
use glium::winit::event_loop::EventLoop;
|
||||
use glium::winit::window::Window;
|
||||
use glium::backend::glutin::Display;
|
||||
|
|
@ -40,7 +40,6 @@ impl Platform for GliumPlatform {
|
|||
|
||||
let asset_manager: ModelManagerRef = Rc::new(RefCell::new(Box::new(GliumAssetManager::new(Box::new(display.clone())))));
|
||||
let mut rendering_system_manager = RenderingSystemManager::new();
|
||||
engine.set_model_manager(asset_manager.clone());
|
||||
|
||||
// Install rendering systems
|
||||
rendering_system_manager.add_system(
|
||||
|
|
@ -59,7 +58,14 @@ impl Platform for GliumPlatform {
|
|||
}
|
||||
|
||||
fn run(mut self) {
|
||||
self.engine.initialize();
|
||||
let (w, h): (u32, u32) = self.window.inner_size().into();
|
||||
let ctx = PlatformContext {
|
||||
current_event: Event::AboutToWait,
|
||||
asset_manager: self.asset_manager.clone(),
|
||||
frame_width: w as f32,
|
||||
frame_height: h as f32,
|
||||
};
|
||||
self.engine.initialize(ctx);
|
||||
let _ = &self.event_loop.run(move |event, el| {
|
||||
match event {
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
|
|
@ -69,7 +75,7 @@ impl Platform for GliumPlatform {
|
|||
},
|
||||
WindowEvent::RedrawRequested => {
|
||||
let mut target = self.display.draw();
|
||||
target.clear_color(0.0, 0.0, 0.0, 1.0);
|
||||
target.clear_color_and_depth((0.1, 0.1, 0.15, 1.0), 1.0);
|
||||
// TODO: let mut context;
|
||||
let mut context = RenderingContext {
|
||||
scene: self.engine.scene_manager.current_mut(),
|
||||
|
|
@ -85,8 +91,13 @@ impl Platform for GliumPlatform {
|
|||
_ => {},
|
||||
},
|
||||
Event::AboutToWait => {
|
||||
self.engine.set_winit_event(event.clone());
|
||||
self.engine.update();
|
||||
let ctx = PlatformContext {
|
||||
current_event: event.clone(),
|
||||
asset_manager: self.asset_manager.clone(),
|
||||
frame_width: w as f32,
|
||||
frame_height: h as f32,
|
||||
};
|
||||
self.engine.update(ctx);
|
||||
self.window.request_redraw();
|
||||
}
|
||||
_ => {},
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ pub use raidillon_platform::Camera;
|
|||
use glam::Vec3;
|
||||
use glium::uniforms::{MagnifySamplerFilter, MinifySamplerFilter, SamplerWrapFunction};
|
||||
use raidillon_ecs::{Transform, ModelID};
|
||||
use raidillon_ecs::components::ModelHandle;
|
||||
use crate::model::Model;
|
||||
|
||||
/// A basic renderer pipeline step.
|
||||
|
|
@ -65,8 +66,8 @@ impl RenderingSystem for BasicMeshRenderingSystem {
|
|||
|
||||
let asset_manager = ctx.asset_manager.borrow();
|
||||
|
||||
for (_, (tr, mh)) in ctx.scene.world.query::<(&Transform, &ModelID)>().iter() {
|
||||
let model = match asset_manager.get_model(mh) {
|
||||
for (_, (tr, mh)) in ctx.scene.world.query::<(&Transform, &ModelHandle)>().iter() {
|
||||
let model = match asset_manager.get_model(&mh.0) {
|
||||
Some(model) => model,
|
||||
_ => continue,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue