Rename crate folders to remove raidillon prefix
This commit is contained in:
parent
176ea52ab0
commit
3458662cfc
29 changed files with 31 additions and 28 deletions
120
core/Cargo.lock
generated
Normal file
120
core/Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hecs"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1cbc675ee8d97b4d206a985137f8ad59666538f56f906474f554467a63c776d"
|
||||
dependencies = [
|
||||
"hashbrown",
|
||||
"spin",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raidillon_core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"hecs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
10
core/Cargo.toml
Normal file
10
core/Cargo.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "raidillon_core"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
hecs = "0.10.5"
|
||||
indexmap = "2.10.0"
|
||||
raidillon_assets = { path = "../assets" }
|
||||
winit = "0.30.12"
|
||||
73
core/src/engine.rs
Normal file
73
core/src/engine.rs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use winit::event::Event;
|
||||
use crate::SceneManager;
|
||||
use crate::system::{SystemContext, SystemManager};
|
||||
use raidillon_assets::{ModelManager, ModelManagerRef};
|
||||
|
||||
pub struct Engine {
|
||||
pub scene_manager: SceneManager,
|
||||
pub system_manager: SystemManager,
|
||||
pub assets_model_manager: Option<ModelManagerRef>,
|
||||
winit_event: Option<Event<()>>,
|
||||
}
|
||||
|
||||
impl Engine {
|
||||
/// Initialize the engine.
|
||||
/// Engine is expected to be initialized after the platform, so reasonably
|
||||
/// it takes platform-dependent structures while being initialized.
|
||||
pub fn new() -> Self {
|
||||
let scene_manager = SceneManager::new();
|
||||
let system_manager = SystemManager::new();
|
||||
Self {
|
||||
scene_manager,
|
||||
system_manager,
|
||||
assets_model_manager: None,
|
||||
winit_event: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Run the first frame, load the world.
|
||||
pub fn initialize(&mut self) {
|
||||
// Engine Loading Stage 1: initialize systems
|
||||
for (system_id, system) in self.system_manager.systems.iter_mut() {
|
||||
system.initialize();
|
||||
}
|
||||
|
||||
let mut ctx = SystemContext {
|
||||
scene: self.scene_manager.current_mut(),
|
||||
event: self.winit_event.clone(),
|
||||
};
|
||||
|
||||
// Engine Loading Stage 2: load world
|
||||
for (system_id, system) in self.system_manager.systems.iter_mut() {
|
||||
system.load_world(&mut ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs every frame
|
||||
pub fn update(&mut self) {
|
||||
let mut ctx = SystemContext {
|
||||
scene: self.scene_manager.current_mut(),
|
||||
event: self.winit_event.clone(),
|
||||
};
|
||||
|
||||
for (system_id, system) in self.system_manager.systems.iter_mut() {
|
||||
system.update(&mut ctx);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_winit_event(&mut self, event: Event<()>) {
|
||||
self.winit_event = Some(event);
|
||||
}
|
||||
|
||||
pub fn set_model_manager(&mut self, model_manager: ModelManagerRef) {
|
||||
self.assets_model_manager = Some(model_manager);
|
||||
}
|
||||
|
||||
// pub fn build_system_context(&mut self) -> SystemContext {
|
||||
// SystemContext {
|
||||
// scene: self.scene_manager.current_mut(),
|
||||
// }
|
||||
// }
|
||||
}
|
||||
7
core/src/lib.rs
Normal file
7
core/src/lib.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
mod scene;
|
||||
mod engine;
|
||||
pub mod system;
|
||||
|
||||
pub use scene::{Scene, SceneManager};
|
||||
pub use engine::Engine;
|
||||
pub use system::{System, SystemManager};
|
||||
74
core/src/scene.rs
Normal file
74
core/src/scene.rs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub struct Scene {
|
||||
title: String,
|
||||
world: hecs::World,
|
||||
skybox_texture_path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Scene {
|
||||
pub fn new(title: String, skybox_texture_path: Option<PathBuf>) -> Self {
|
||||
Self {
|
||||
title,
|
||||
world: hecs::World::new(),
|
||||
skybox_texture_path,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Scene> for Scene {
|
||||
fn as_ref(&self) -> &Scene {
|
||||
&self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Scene> for Scene {
|
||||
fn as_mut(&mut self) -> &mut Scene {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
type SceneID = String;
|
||||
|
||||
pub struct SceneManager {
|
||||
scenes: HashMap<SceneID, Scene>,
|
||||
active_scene: Option<SceneID>,
|
||||
}
|
||||
|
||||
impl SceneManager {
|
||||
pub fn new() -> Self {
|
||||
let scenes = HashMap::new();
|
||||
Self {
|
||||
scenes,
|
||||
active_scene: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn current(&self) -> &Scene {
|
||||
match &self.active_scene {
|
||||
Some(id) => self.scenes[id].as_ref(),
|
||||
None => panic!("No active scene"),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn current_mut(&mut self) -> &mut Scene {
|
||||
match &mut self.active_scene {
|
||||
Some(id) => self.scenes.get_mut(id.as_mut()).unwrap().as_mut(),
|
||||
None => panic!("No active scene"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_active_scene(&mut self, scene: SceneID) {
|
||||
self.active_scene = Some(scene);
|
||||
}
|
||||
|
||||
pub fn add_scene(&mut self, id: SceneID, scene: Scene) {
|
||||
self.scenes.insert(id, scene);
|
||||
}
|
||||
|
||||
pub fn remove_scene(&mut self, id: SceneID) {
|
||||
self.scenes.remove(&id);
|
||||
}
|
||||
}
|
||||
37
core/src/system.rs
Normal file
37
core/src/system.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
use crate::Scene;
|
||||
use indexmap::IndexMap;
|
||||
use winit::event::Event;
|
||||
|
||||
pub struct SystemContext<'a> {
|
||||
// TODO: time delta etc.
|
||||
pub scene: &'a mut Scene,
|
||||
pub event: Option<Event<()>>,
|
||||
}
|
||||
|
||||
pub trait System {
|
||||
/// Initialize the system.
|
||||
fn initialize(&mut self);
|
||||
/// Spawn the first entities of the world.
|
||||
fn load_world(&mut self, ctx: &mut SystemContext);
|
||||
fn update(&mut self, ctx: &mut SystemContext);
|
||||
}
|
||||
|
||||
pub type SystemID = String;
|
||||
pub struct SystemManager {
|
||||
pub systems: IndexMap<SystemID, Box<dyn System>>,
|
||||
}
|
||||
|
||||
impl SystemManager {
|
||||
pub fn new() -> Self {
|
||||
let systems = IndexMap::default();
|
||||
Self { systems }
|
||||
}
|
||||
|
||||
pub fn add_system(&mut self, id: SystemID, system: Box<dyn System>) {
|
||||
self.systems.insert(id, system);
|
||||
}
|
||||
|
||||
pub fn remove_system(&mut self, id: SystemID) {
|
||||
self.systems.shift_remove(&id);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue