wip: week of changes

This commit is contained in:
reo 2025-08-16 21:24:10 +03:00
parent 03e8f34dba
commit 176ea52ab0
20 changed files with 171 additions and 47 deletions

View file

@ -10,5 +10,6 @@ glium = { version = "0.35.0", features = ["glutin_backend", "simple_window_build
gltf = { version = "1.4.1", features = ["import", "utils", "KHR_texture_transform"] }
raidillon_platform = { path = "../raidillon_platform" }
raidillon_core = { path = "../raidillon_core" }
raidillon_assets = { path = "../raidillon_assets" }
winit = "0.30.12"
indexmap = "2.10.0"

View file

@ -1,4 +1,4 @@
use raidillon_platform::assets::AssetManager;
use raidillon_assets::{ModelManagerRef, ModelManager};
use crate::model::Model;
use std::path::{Path, PathBuf};
use crate::gltf_loader::load_gltf;
@ -22,9 +22,7 @@ impl GliumAssetManager {
}
}
impl AssetManager for GliumAssetManager {
type Model = Model;
impl ModelManager for GliumAssetManager {
fn load_gltf(&mut self, path: &Path) {
let model = load_gltf(path, self.facade.as_ref()).unwrap();
self.models.insert(path.to_path_buf(), model);
@ -34,14 +32,14 @@ impl AssetManager for GliumAssetManager {
self.models.remove(&path.to_path_buf());
}
fn get_model(&mut self, path: &Path) -> &Self::Model {
let path_buf = path.to_path_buf();
match self.models.entry(path_buf) {
Entry::Occupied(entry) => entry.into_mut(),
Entry::Vacant(entry) => {
let model = load_gltf(path, self.facade.as_ref()).unwrap();
entry.insert(model)
}
}
}
// fn get_model(&mut self, path: &Path) -> &Self::Model {
// let path_buf = path.to_path_buf();
// match self.models.entry(path_buf) {
// Entry::Occupied(entry) => entry.into_mut(),
// Entry::Vacant(entry) => {
// let model = load_gltf(path, self.facade.as_ref()).unwrap();
// entry.insert(model)
// }
// }
// }
}

View file

@ -1,3 +1,5 @@
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::{Arc, RwLock};
use raidillon_platform::Platform;
use glium::winit::event_loop::EventLoop;
@ -8,20 +10,22 @@ use glium::backend::glutin::SimpleWindowBuilder;
use glium::Surface;
use crate::system::{RenderingSystemManager, RenderingSystem, RenderingContext};
use winit::event::{Event, WindowEvent};
use raidillon_assets::{ModelManager, ModelManagerRef};
use raidillon_core::Engine;
use crate::GliumAssetManager;
use crate::render::BasicRenderingSystem;
pub struct GliumPlatform<RS: RenderingSystem> {
pub struct GliumPlatform {
event_loop: EventLoop<()>,
window: Window,
display: Display<WindowSurface>,
rendering_system_manager: RenderingSystemManager<RS>,
asset_manager: Arc<RwLock<GliumAssetManager>>,
rendering_system_manager: RenderingSystemManager,
asset_manager: ModelManagerRef,
engine: Engine,
}
impl<RS: RenderingSystem> Platform for GliumPlatform<RS> {
fn initialize(title: String, width: u32, height: u32) -> Self {
impl Platform for GliumPlatform {
fn initialize(mut engine: Engine, title: String, width: u32, height: u32) -> Self {
let event_loop = glium::winit::event_loop::EventLoop::builder()
.build()
.expect("create event-loop");
@ -31,18 +35,20 @@ impl<RS: RenderingSystem> Platform for GliumPlatform<RS> {
.with_inner_size(width, height)
.build(&event_loop);
let asset_manager = Arc::new(RwLock::new(GliumAssetManager::new(Box::new(display.clone()))));
let asset_manager: ModelManagerRef = Rc::new(RefCell::new(Box::new(GliumAssetManager::new(Box::new(display.clone())))));
let rendering_system_manager = RenderingSystemManager::new();
engine.set_model_manager(asset_manager.clone());
Self {
event_loop,
window,
display,
rendering_system_manager,
asset_manager,
engine
}
}
fn run(mut self, engine: Engine) {
fn run(mut self) {
let _ = &self.event_loop.run(move |event, el| {
match event {
Event::WindowEvent { event, .. } => match event {
@ -51,15 +57,22 @@ impl<RS: RenderingSystem> Platform for GliumPlatform<RS> {
let mut target = self.display.draw();
target.clear_color(0.0, 0.0, 0.0, 1.0);
// TODO: let mut context;
let mut context = RenderingContext {
scene: self.engine.scene_manager.current_mut(),
target: &mut target,
asset_manager: self.asset_manager.clone(),
};
for (system_id, system) in self.rendering_system_manager.systems.iter_mut() {
todo!();
system.render(&mut context);
}
target.finish().unwrap();
}
_ => {},
},
Event::AboutToWait => {
// TODO: Run <engine: Engine> systems here
self.engine.set_winit_event(event.clone());
self.engine.update();
self.window.request_redraw();
}
_ => {},

View file

@ -1,4 +1,3 @@
use glium::Surface;
use crate::RenderingSystem;
use crate::system::RenderingContext;
@ -6,7 +5,7 @@ use crate::system::RenderingContext;
pub struct BasicRenderingSystem;
impl RenderingSystem for BasicRenderingSystem {
fn render<S: Surface>(ctx: &mut RenderingContext<S>) {
fn render(&mut self, ctx: &mut RenderingContext) {
todo!()
}
}

View file

@ -2,11 +2,12 @@ use raidillon_core::Scene;
use glium::Frame;
use crate::GliumAssetManager;
use indexmap::IndexMap;
use raidillon_assets::ModelManagerRef;
pub struct RenderingContext<'a> {
pub scene: &'a Scene,
pub target: &'a mut Frame,
pub asset_manager: &'a mut GliumAssetManager,
pub asset_manager: ModelManagerRef,
}
/// The internal "rendering system" trait of raidillon_glium.