i guess something like that might work eventually

This commit is contained in:
LunarAkai 2025-08-05 02:06:54 +02:00
commit c44d29ded7
8 changed files with 138 additions and 12 deletions

View file

@ -1,3 +0,0 @@
use moonhare_window::{window_config, MoonhareWindow, WindowResult};
use crate::{basic::node::Node, Game};

View file

@ -1,2 +1 @@
pub mod node;
pub mod game_window;
pub mod node;

View file

@ -1,28 +1,46 @@
//! Base functionality for a Moonhare Game Engine Project
use std::rc::Rc;
use std::{any::Any, rc::Rc};
use moonhare_ecs::world::World;
use moonhare_graphics::{color::Color, glium::{backend::Context, glutin::api::egl::context}};
use moonhare_log::*;
use moonhare_window::{platforms::glfw_window::GLFWWindow};
use crate::systems::system::{BaseSystems, System};
pub mod systems;
pub mod basic;
/// Only one Game may exist per project
#[derive(Debug)]
/* #[derive(Debug)]
pub struct Game {
pub world: World,
pub base_systems: BaseSystems,
pub context: moonhare_window::WindowRenderContext,
pub glfw_window: Option<moonhare_window::platforms::glfw_window::GLFWWindow>,
pub is_running: bool,
pub name: String,
} */
// when creating a game, you can add systems to it, which do _things_
// BaseSystems -> Window, Update, Render
// Hierachy:
// [Game] -> <Systems> -> <Nodes> (-> [Node] -> ... )
//-------------
// [ ] => only 1 --- < > => allow multiple
#[derive(Debug)]
pub struct Game {
pub systems: Option<Vec<Box<dyn System>>>,
pub is_running: bool
}
impl Default for Game {
fn default() -> Self {
Self {
world: World::new(),
is_running: true,
name: default_game_name(),
systems: None,
is_running: true
}
}
}
@ -42,8 +60,23 @@ impl Game {
Game::default()
}
pub fn add_base_systems(&mut self) {
}
pub fn add_system(&mut self, system: Box<dyn System>) {
if self.systems.is_none() {
let a: Vec<Box<dyn System>> = vec![];
self.systems = Some(a);
}
&self.systems.as_mut().unwrap().push(system);
}
pub fn run(self) {
info("Running Game...");
//------------------------------
// Run Init on all Systems
//------------------------------
let glfw_window_unwrapped = self.glfw_window;
let mut graphics_handler: GraphicsHandler = GraphicsHandler { ..Default::default() };
let context: std::rc::Rc<moonhare_graphics::glium::backend::Context>;
@ -56,6 +89,7 @@ impl Game {
handle_window_event(value.as_mut().unwrap());
render(context.clone());
self.base_systems.game_loop();
// update();
}
}

View file

@ -0,0 +1,4 @@
pub mod system;
pub mod window_system;
pub mod update_system;
pub mod render_system;

View file

@ -0,0 +1,15 @@
#[derive(Debug)]
pub struct RenderSystem;
impl Default for RenderSystem {
fn default() -> Self {
Self {
}
}
}
impl RenderSystem {
pub(crate) fn update(&self) {
}
}

View file

@ -0,0 +1,42 @@
use std::fmt::{Debug, Formatter};
use crate::systems::{render_system::RenderSystem, update_system::UpdateSystem, window_system::WindowSystem};
/// Systems are collections of related High Level Game Logic
/// Systems can have Nodes as children
/// These node than do all the concrete/low level stuff they want to do
pub trait System {}
impl Debug for dyn System {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
writeln!(f, "")
}
}
// todo: make this more generic so that new systems can be added by the game application it self
// or systems can be modified to suit the game needs
/// Base Systems/Plugins of the Engine
#[derive(Debug)]
pub struct BaseSystems {
window_system: WindowSystem,
update_system: UpdateSystem,
render_system: RenderSystem,
}
impl BaseSystems {
pub fn new() -> Self {
Self {
window_system: WindowSystem::default(),
update_system: UpdateSystem,
render_system: RenderSystem
}
}
pub fn game_loop(&self) {
self.window_system.update();
self.update_system.update();
self.render_system.update();
}
}

View file

@ -0,0 +1,15 @@
#[derive(Debug)]
pub struct UpdateSystem;
impl Default for UpdateSystem {
fn default() -> Self {
Self {
}
}
}
impl UpdateSystem {
pub(crate) fn update(&self) {
}
}

View file

@ -0,0 +1,20 @@
#[derive(Debug)]
pub struct WindowSystem {
context: moonhare_window::WindowRenderContext,
glfw_window: Option<moonhare_window::platforms::glfw_window::GLFWWindow>,
}
impl Default for WindowSystem {
fn default() -> Self {
Self {
context: moonhare_window::WindowRenderContext::OPENGLGLFW,
glfw_window: None
}
}
}
impl WindowSystem {
pub(crate) fn update(&self) {
}
}