New crate: raidillon_app, refactor game/main.rs to use the new crate
This commit is contained in:
parent
82f3b27732
commit
47c3b2b111
12 changed files with 140 additions and 96 deletions
21
Cargo.lock
generated
21
Cargo.lock
generated
|
|
@ -2091,6 +2091,19 @@ version = "5.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||
|
||||
[[package]]
|
||||
name = "raidillon_app"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"raidillon_assets",
|
||||
"raidillon_core",
|
||||
"raidillon_ecs",
|
||||
"raidillon_engine",
|
||||
"raidillon_glium",
|
||||
"raidillon_physics",
|
||||
"raidillon_platform",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raidillon_assets"
|
||||
version = "0.1.0"
|
||||
|
|
@ -2137,13 +2150,7 @@ dependencies = [
|
|||
"egui",
|
||||
"glam 0.30.9",
|
||||
"hecs",
|
||||
"raidillon_assets",
|
||||
"raidillon_core",
|
||||
"raidillon_ecs",
|
||||
"raidillon_engine",
|
||||
"raidillon_glium",
|
||||
"raidillon_physics",
|
||||
"raidillon_platform",
|
||||
"raidillon_app",
|
||||
"rapier3d",
|
||||
"winit",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@ members = [
|
|||
"game",
|
||||
"ecs",
|
||||
"engine",
|
||||
"physics",
|
||||
"physics", "app",
|
||||
]
|
||||
|
|
|
|||
16
app/Cargo.toml
Normal file
16
app/Cargo.toml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
[package]
|
||||
name = "raidillon_app"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
raidillon_engine = { path = "../engine" }
|
||||
raidillon_platform = { path = "../platform" }
|
||||
raidillon_assets = { path = "../asset" }
|
||||
raidillon_ecs = { path = "../ecs" }
|
||||
raidillon_physics = { path = "../physics" }
|
||||
raidillon_glium = { path = "../glium_platform", optional = true }
|
||||
raidillon_core = { path = "../core" }
|
||||
|
||||
[features]
|
||||
glium = ["raidillon_glium"]
|
||||
45
app/src/lib.rs
Normal file
45
app/src/lib.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
pub mod prelude;
|
||||
|
||||
pub use prelude::*;
|
||||
|
||||
pub struct App {
|
||||
pub engine: Option<Engine>,
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new() -> Self {
|
||||
let engine = Engine::new();
|
||||
Self { engine: Some(engine) }
|
||||
}
|
||||
|
||||
pub fn add_system<S: System + Default + 'static>(&mut self) -> &mut Self {
|
||||
self.engine.as_mut().unwrap().system_manager.add::<S>();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_scene(&mut self, id: SceneID, scene: Scene) -> &mut Self {
|
||||
self.engine.as_mut().unwrap().scene_manager.add_scene(id, scene);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_active_scene(&mut self, id: SceneID) -> &mut Self {
|
||||
self.engine.as_mut().unwrap().scene_manager.set_active_scene(id);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn run(&mut self, title: String, width: u32, height: u32) {
|
||||
#[cfg(feature = "glium")]
|
||||
{
|
||||
let platform = GliumPlatform::initialize(
|
||||
self.engine.take().unwrap(),
|
||||
title,
|
||||
width,
|
||||
height,
|
||||
);
|
||||
platform.run();
|
||||
}
|
||||
|
||||
#[cfg(not(any(feature = "glium")))]
|
||||
compile_error!("No platform feature enabled.");
|
||||
}
|
||||
}
|
||||
43
app/src/prelude.rs
Normal file
43
app/src/prelude.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
pub use raidillon_engine::{
|
||||
Engine,
|
||||
system::System,
|
||||
EngineResources,
|
||||
InputState,
|
||||
system::SystemContext,
|
||||
};
|
||||
|
||||
pub use raidillon_platform::{
|
||||
Platform,
|
||||
Camera,
|
||||
PlatformContext,
|
||||
TimeContext,
|
||||
};
|
||||
|
||||
pub use raidillon_assets::{
|
||||
ModelManagerRef,
|
||||
model_path,
|
||||
};
|
||||
|
||||
pub use raidillon_ecs::{
|
||||
components::{
|
||||
CameraMode,
|
||||
CharacterBodyComponent,
|
||||
ModelHandle,
|
||||
RigidBodyComponent,
|
||||
Transform,
|
||||
},
|
||||
};
|
||||
|
||||
pub use raidillon_physics::Physics;
|
||||
|
||||
pub use raidillon_core::{
|
||||
scene::{Scene, SceneID},
|
||||
EguiQueue,
|
||||
engine::EngineTrait,
|
||||
};
|
||||
|
||||
#[cfg(feature = "glium")]
|
||||
pub use raidillon_glium::{
|
||||
GliumPlatform,
|
||||
RenderingSystem,
|
||||
};
|
||||
|
|
@ -40,7 +40,7 @@ impl AsMut<Scene> for Scene {
|
|||
}
|
||||
}
|
||||
|
||||
type SceneID = &'static str;
|
||||
pub type SceneID = &'static str;
|
||||
|
||||
pub struct SceneManager {
|
||||
scenes: HashMap<SceneID, Scene>,
|
||||
|
|
|
|||
|
|
@ -3,18 +3,8 @@ name = "raidillon_game"
|
|||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[features]
|
||||
default = ["glium"]
|
||||
glium = ["raidillon_glium"]
|
||||
|
||||
[dependencies]
|
||||
raidillon_core = { path = "../core" }
|
||||
raidillon_platform = { path = "../platform" }
|
||||
raidillon_assets = { path = "../asset" }
|
||||
raidillon_ecs = { path = "../ecs" }
|
||||
raidillon_engine = { path = "../engine" }
|
||||
raidillon_physics = { path = "../physics" }
|
||||
raidillon_glium = { path = "../glium_platform", optional = true }
|
||||
raidillon_app = { path = "../app", features = ["glium"] }
|
||||
glam = "0.30.5"
|
||||
winit = "0.30.12"
|
||||
rapier3d = "0.30.1"
|
||||
|
|
|
|||
|
|
@ -1,25 +1,11 @@
|
|||
use raidillon_app::prelude::*;
|
||||
|
||||
mod systems;
|
||||
use std::fmt::format;
|
||||
use glam::{Quat, Vec3};
|
||||
use rapier3d::dynamics::{CoefficientCombineRule, RigidBodyType};
|
||||
use rapier3d::prelude::ColliderBuilder;
|
||||
use raidillon_engine::{Engine, system::System, EngineResources, InputState};
|
||||
use raidillon_engine::system::SystemContext;
|
||||
use raidillon_platform::{Platform, Camera, PlatformContext};
|
||||
use raidillon_assets::model_path;
|
||||
use raidillon_core::engine::EngineTrait;
|
||||
use raidillon_ecs::components::{CameraMode, CharacterBodyComponent, ModelHandle, RigidBodyComponent};
|
||||
use raidillon_ecs::Transform;
|
||||
use raidillon_core::scene::Scene;
|
||||
#[cfg(feature = "glium")]
|
||||
use raidillon_glium::GliumPlatform;
|
||||
use winit::event::{ElementState, Event, WindowEvent};
|
||||
use winit::event::DeviceEvent::MouseMotion;
|
||||
use winit::keyboard::{KeyCode, PhysicalKey};
|
||||
use raidillon_core::{EguiQueue};
|
||||
use winit::event::{Event, WindowEvent};
|
||||
use systems::debug_camera::FPSDebugCameraSystem;
|
||||
use raidillon_glium::RenderingSystem;
|
||||
use raidillon_physics::Physics;
|
||||
use crate::systems::{KeybindsSystem, KinematicCharacterController, PhysicsSystem};
|
||||
|
||||
const TEST_GLTF: &str = "sphere.glb";
|
||||
|
|
@ -46,9 +32,9 @@ impl System for UpdateAspectRatioSystem {
|
|||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct RenderingTestSystem;
|
||||
struct MainSystem;
|
||||
|
||||
impl System for RenderingTestSystem {
|
||||
impl System for MainSystem {
|
||||
fn load_world(&mut self, res: &mut EngineResources, scene: &mut Scene) {
|
||||
let pctx = res.get::<PlatformContext>().expect("PlatformContext missing").clone();
|
||||
let physics = scene.resources.get_mut::<Physics>().expect("Physics missing");
|
||||
|
|
@ -130,35 +116,14 @@ impl System for RenderingTestSystem {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let mut engine = Engine::new();
|
||||
// Define systems
|
||||
engine.system_manager.add::<PhysicsSystem>();
|
||||
engine.system_manager.add::<KeybindsSystem>();
|
||||
engine.system_manager.add::<KinematicCharacterController>();
|
||||
engine.system_manager.add::<FPSDebugCameraSystem>();
|
||||
engine.system_manager.add::<RenderingTestSystem>();
|
||||
engine.system_manager.add::<UpdateAspectRatioSystem>();
|
||||
// engine.system_manager.add::<InputTestSystem>();
|
||||
|
||||
// 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 platform = GliumPlatform::initialize(
|
||||
engine,
|
||||
"Raidillon".to_string(),
|
||||
2560,
|
||||
1080,
|
||||
);
|
||||
platform.run()
|
||||
};
|
||||
|
||||
#[cfg(not(any(feature = "glium")))]
|
||||
compile_error!("No platform feature enabled.");
|
||||
raidillon_app::App::new()
|
||||
.add_system::<PhysicsSystem>()
|
||||
.add_system::<KeybindsSystem>()
|
||||
.add_system::<KinematicCharacterController>()
|
||||
.add_system::<FPSDebugCameraSystem>()
|
||||
.add_system::<MainSystem>()
|
||||
.add_system::<UpdateAspectRatioSystem>()
|
||||
.add_scene(MAIN_SCENE_ID, Scene::new(MAIN_SCENE_ID.to_owned(), None))
|
||||
.set_active_scene(MAIN_SCENE_ID)
|
||||
.run("Raidillon".to_string(), 2560, 1080);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,9 @@
|
|||
use raidillon_engine::system::{System, SystemContext};
|
||||
use glam::{Quat, Vec3};
|
||||
use winit::event::DeviceEvent::MouseMotion;
|
||||
use winit::event::{ElementState, Event, MouseButton, WindowEvent};
|
||||
use winit::keyboard::{KeyCode, PhysicalKey};
|
||||
use winit::window::CursorGrabMode;
|
||||
use raidillon_assets::model_path;
|
||||
use raidillon_platform::{Camera, PlatformContext};
|
||||
use raidillon_engine::InputState;
|
||||
use raidillon_engine::EngineResources;
|
||||
use raidillon_core::scene::Scene;
|
||||
use raidillon_ecs::components::CameraMode;
|
||||
use raidillon_app::prelude::*;
|
||||
|
||||
pub struct FPSDebugCameraSystem {
|
||||
mouse_delta: (f64, f64),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
use winit::keyboard::KeyCode;
|
||||
use raidillon_core::scene::Scene;
|
||||
use raidillon_ecs::components::CameraMode;
|
||||
use raidillon_engine::{EngineResources, InputState};
|
||||
use raidillon_engine::system::System;
|
||||
use raidillon_platform::{Camera, PlatformContext};
|
||||
use raidillon_app::prelude::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct KeybindsSystem {
|
||||
|
|
|
|||
|
|
@ -1,18 +1,12 @@
|
|||
use glam::{Quat, Vec3};
|
||||
use rapier3d::prelude::{nalgebra, ColliderBuilder, QueryFilter, RigidBodyBuilder};
|
||||
use rapier3d::prelude::vector;
|
||||
use raidillon_core::scene::Scene;
|
||||
use raidillon_engine::{EngineResources, InputState};
|
||||
use raidillon_engine::system::System;
|
||||
use rapier3d::control::KinematicCharacterController as RapierKinematicCharacterController;
|
||||
use rapier3d::na::{Isometry3, Vector3};
|
||||
use winit::event::DeviceEvent::MouseMotion;
|
||||
use winit::event::Event;
|
||||
use winit::keyboard::KeyCode;
|
||||
use raidillon_ecs::components::{CameraMode, CharacterBodyComponent};
|
||||
use raidillon_ecs::Transform;
|
||||
use raidillon_physics::Physics;
|
||||
use raidillon_platform::{Camera, PlatformContext};
|
||||
use raidillon_app::prelude::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct KinematicCharacterController {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,4 @@
|
|||
use raidillon_core::scene::Scene;
|
||||
use raidillon_ecs::components::RigidBodyComponent;
|
||||
use raidillon_ecs::Transform;
|
||||
use raidillon_engine::EngineResources;
|
||||
use raidillon_engine::system::System;
|
||||
use raidillon_physics::Physics;
|
||||
use raidillon_platform::PlatformContext;
|
||||
use raidillon_app::prelude::*;
|
||||
|
||||
/// Do physics calculations and apply to world.
|
||||
#[derive(Default)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue