raidillon/game/src/main.rs
reo 0c0d5cdb2a Fix imgui renderer once and for all
Finally solved the problems with the imgui renderer after a long chat with clankers. Fixed some other stuff as well.

Reminder to keep the rendered_this_frame check as that's what solved it. Probably a deeper issue down there that caused us to render twice, but whatever.
2025-09-10 01:31:43 +03:00

111 lines
3.6 KiB
Rust

use std::path::Path;
use glam::{Quat, Vec3};
use raidillon_engine::{Engine, system::System};
use raidillon_engine::system::SystemContext;
use raidillon_platform::{Platform, Camera};
use raidillon_assets::model_path;
use raidillon_core::engine::EngineTrait;
use raidillon_ecs::components::ModelHandle;
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";
struct UpdateAspectRatioSystem;
impl System for UpdateAspectRatioSystem {
fn initialize(&mut self) {}
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;
});
}
_ => {}
},
_ => {}
}
}
}
struct RenderingTestSystem;
impl System for RenderingTestSystem {
fn initialize(&mut self) {}
fn load_world(&mut self, ctx: &mut SystemContext) {
ctx.scene.world.spawn((Camera {
eye: Vec3::new(0.0, 0.0, 2.0),
center: Vec3::ZERO,
up: Vec3::Y,
fovy: 60_f32.to_radians(),
aspect: ctx.platform_context.frame_width / ctx.platform_context.frame_height,
znear: 0.1,
zfar: 100.0,
},));
let mut am = ctx.platform_context.asset_manager.borrow_mut();
am.load_gltf(TEST_GLTF, &model_path(TEST_GLTF));
ctx.scene.world.spawn((
Transform {
translation: Vec3::new(0.0, 0.0, 0.0),
rotation: Quat::IDENTITY,
scale: Vec3::new(1.0, 1.0, 1.0),
},
ModelHandle(TEST_GLTF),
));
}
fn update(&mut self, ctx: &mut SystemContext) {
// if let Some(mut debug_ui) = ctx.platform_context.imgui_ui.as_ref().map(|ui| ui.borrow_mut()) {
// debug_ui.text("Hello World!");
// }
ctx.debug_ui_buffer.borrow_mut().text("Hello World!".to_owned());
}
}
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));
// Set up the scene
let main_scene = Scene::new(
MAIN_SCENE_ID.to_owned(),
None,
);
engine.scene_manager.add_scene(MAIN_SCENE_ID, main_scene);
engine.scene_manager.set_active_scene(MAIN_SCENE_ID);
#[cfg(feature = "glium")]
{
let mut platform = GliumPlatform::initialize(
engine,
"Raidillon".to_string(),
1920,
1080,
);
platform.run()
};
#[cfg(not(any(feature = "glium")))]
compile_error!("No platform feature enabled.");
}