Implement MenuSystem, reimplement the mouse grab and menu system, add a new common module in the game systems for common functions, various other fixes

This commit is contained in:
reo 2025-11-22 14:15:53 +03:00
parent 47c3b2b111
commit b17a7636d8
7 changed files with 219 additions and 150 deletions

View file

@ -6,7 +6,8 @@ use rapier3d::dynamics::{CoefficientCombineRule, RigidBodyType};
use rapier3d::prelude::ColliderBuilder;
use winit::event::{Event, WindowEvent};
use systems::debug_camera::FPSDebugCameraSystem;
use crate::systems::{KeybindsSystem, KinematicCharacterController, PhysicsSystem};
use crate::systems::common::should_draw_menu;
use crate::systems::{KeybindsSystem, KinematicCharacterController, MenuSystem, PhysicsSystem};
const TEST_GLTF: &str = "sphere.glb";
const PLANE_GLTF: &str = "plane.glb";
@ -96,22 +97,23 @@ impl System for MainSystem {
InputState,
)>().unwrap();
let mut egui_queue = pctx.egui_queue.borrow_mut();
let time_ctx = pctx.time_ctx.clone();
let mut character_pos = Vec3::ZERO;
for (_ent, (tr, ch_component)) in scene.world.query::<(&Transform, &CharacterBodyComponent)>().iter() {
character_pos = tr.translation;
}
egui_queue.queue(move |egui_ctx| {
egui::Window::new("Debug").show(egui_ctx, |ui| {
ui.label("Hello World!");
ui.label(format!("Frame Delta: {}", time_ctx.frame_dt));
ui.label(format!("Fixed Delta: {}", time_ctx.fixed_dt));
ui.label(format!("FPS: {}", 1.0 / time_ctx.frame_dt));
ui.label(format!("Character POS: {}", character_pos));
if should_draw_menu(scene) {
let mut egui_queue = pctx.egui_queue.borrow_mut();
let time_ctx = pctx.time_ctx.clone();
let mut character_pos = Vec3::ZERO;
for (_ent, (tr, ch_component)) in scene.world.query::<(&Transform, &CharacterBodyComponent)>().iter() {
character_pos = tr.translation;
}
egui_queue.queue(move |egui_ctx| {
egui::Window::new("Debug").show(egui_ctx, |ui| {
ui.label("Hello World!");
ui.label(format!("Frame Delta: {}", time_ctx.frame_dt));
ui.label(format!("Fixed Delta: {}", time_ctx.fixed_dt));
ui.label(format!("FPS: {}", 1.0 / time_ctx.frame_dt));
ui.label(format!("Character POS: {}", character_pos));
});
});
});
}
}
}
@ -121,6 +123,7 @@ fn main() {
.add_system::<KeybindsSystem>()
.add_system::<KinematicCharacterController>()
.add_system::<FPSDebugCameraSystem>()
.add_system::<MenuSystem>()
.add_system::<MainSystem>()
.add_system::<UpdateAspectRatioSystem>()
.add_scene(MAIN_SCENE_ID, Scene::new(MAIN_SCENE_ID.to_owned(), None))