Refactor system registration to use TypeIds
This commit is contained in:
parent
0c0d5cdb2a
commit
75fd59a504
5 changed files with 68 additions and 73 deletions
|
|
@ -1,4 +1,3 @@
|
|||
use std::path::Path;
|
||||
use glam::{Quat, Vec3};
|
||||
use raidillon_engine::{Engine, system::System};
|
||||
use raidillon_engine::system::SystemContext;
|
||||
|
|
@ -10,31 +9,32 @@ use raidillon_ecs::Transform;
|
|||
use raidillon_core::scene::Scene;
|
||||
#[cfg(feature = "glium")]
|
||||
use raidillon_glium::GliumPlatform;
|
||||
use raidillon_core::DebugUIBuffer;
|
||||
use winit::event::{Event, WindowEvent};
|
||||
|
||||
const TEST_GLTF: &str = "pink-monkey.gltf";
|
||||
|
||||
const RENDERING_TEST_SYSTEM: &str = "rendering_test_system";
|
||||
|
||||
const UPDATE_ASPECT_RATIO_SYSTEM: &str = "update_aspect_ratio_system";
|
||||
|
||||
const MAIN_SCENE_ID: &str = "main_scene";
|
||||
|
||||
#[derive(Default)]
|
||||
struct UpdateAspectRatioSystem;
|
||||
impl System for UpdateAspectRatioSystem {
|
||||
fn initialize(&mut self) {}
|
||||
|
||||
fn load_world(&mut self, ctx: &mut SystemContext) {}
|
||||
fn load_world(&mut self, _ctx: &mut SystemContext) {}
|
||||
|
||||
fn update(&mut self, ctx: &mut SystemContext) {
|
||||
// FIXME: Need an event handler rework for systems.
|
||||
match &ctx.platform_context.current_event {
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::Resized(sz) => {
|
||||
let _ = ctx.scene.world.query_mut::<&mut Camera>().into_iter().map(|mut cam| {
|
||||
cam.1.aspect = sz.width as f32 / sz.height as f32;
|
||||
});
|
||||
let _ = ctx
|
||||
.scene
|
||||
.world
|
||||
.query_mut::<&mut Camera>()
|
||||
.into_iter()
|
||||
.map(|(_, cam)| {
|
||||
cam.aspect = sz.width as f32 / sz.height as f32;
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
|
|
@ -43,6 +43,7 @@ impl System for UpdateAspectRatioSystem {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct RenderingTestSystem;
|
||||
impl System for RenderingTestSystem {
|
||||
fn initialize(&mut self) {}
|
||||
|
|
@ -82,10 +83,8 @@ impl System for RenderingTestSystem {
|
|||
fn main() {
|
||||
let mut engine = Engine::new();
|
||||
// Define systems
|
||||
// engine.system_manager.add_system("spawn_chunks".to_string(), ChunkSystem);
|
||||
// engine.system_manager.add_system("movement".to_string(), MovementSystem);
|
||||
engine.system_manager.add_system(RENDERING_TEST_SYSTEM, Box::new(RenderingTestSystem));
|
||||
engine.system_manager.add_system(UPDATE_ASPECT_RATIO_SYSTEM, Box::new(UpdateAspectRatioSystem));
|
||||
engine.system_manager.add::<RenderingTestSystem>();
|
||||
engine.system_manager.add::<UpdateAspectRatioSystem>();
|
||||
|
||||
// Set up the scene
|
||||
let main_scene = Scene::new(
|
||||
|
|
@ -97,7 +96,7 @@ fn main() {
|
|||
|
||||
#[cfg(feature = "glium")]
|
||||
{
|
||||
let mut platform = GliumPlatform::initialize(
|
||||
let platform = GliumPlatform::initialize(
|
||||
engine,
|
||||
"Raidillon".to_string(),
|
||||
1920,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue