wip: week of changes

This commit is contained in:
reo 2025-08-16 21:24:10 +03:00
parent 03e8f34dba
commit 176ea52ab0
20 changed files with 171 additions and 47 deletions

View file

@ -6,4 +6,5 @@ edition = "2024"
[dependencies]
hecs = "0.10.5"
indexmap = "2.10.0"
raidillon_platform = { path = "../raidillon_platform" }
raidillon_assets = { path = "../raidillon_assets" }
winit = "0.30.12"

View file

@ -1,25 +1,34 @@
use std::alloc::System;
use std::cell::RefCell;
use std::rc::Rc;
use winit::event::Event;
use crate::SceneManager;
use crate::system::{SystemContext, SystemManager};
use raidillon_platform::EngineTrait;
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 EngineTrait for Engine {
fn new() -> Self {
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.
fn initialize(&mut self) -> bool {
pub fn initialize(&mut self) {
// Engine Loading Stage 1: initialize systems
for (system_id, system) in self.system_manager.systems.iter_mut() {
system.initialize();
@ -27,20 +36,20 @@ impl EngineTrait for Engine {
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);
}
true
}
/// Runs every frame
fn update(&mut self) {
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() {
@ -48,6 +57,14 @@ impl EngineTrait for Engine {
}
}
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(),

View file

@ -1,9 +1,20 @@
use std::collections::HashMap;
use std::path::{Path, PathBuf};
pub struct Scene {
title: String,
world: hecs::World,
skybox_texture_path: String,
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 {

View file

@ -1,9 +1,11 @@
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 {