i guess something like that might work eventually
This commit is contained in:
parent
022fac5966
commit
c44d29ded7
8 changed files with 138 additions and 12 deletions
|
|
@ -1,3 +0,0 @@
|
||||||
use moonhare_window::{window_config, MoonhareWindow, WindowResult};
|
|
||||||
|
|
||||||
use crate::{basic::node::Node, Game};
|
|
||||||
|
|
@ -1,2 +1 @@
|
||||||
pub mod node;
|
pub mod node;
|
||||||
pub mod game_window;
|
|
||||||
|
|
@ -1,28 +1,46 @@
|
||||||
//! Base functionality for a Moonhare Game Engine Project
|
//! 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_graphics::{color::Color, glium::{backend::Context, glutin::api::egl::context}};
|
||||||
use moonhare_log::*;
|
use moonhare_log::*;
|
||||||
use moonhare_window::{platforms::glfw_window::GLFWWindow};
|
use moonhare_window::{platforms::glfw_window::GLFWWindow};
|
||||||
|
|
||||||
|
use crate::systems::system::{BaseSystems, System};
|
||||||
|
|
||||||
|
pub mod systems;
|
||||||
pub mod basic;
|
pub mod basic;
|
||||||
|
|
||||||
/// Only one Game may exist per project
|
/// Only one Game may exist per project
|
||||||
#[derive(Debug)]
|
/* #[derive(Debug)]
|
||||||
pub struct Game {
|
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 is_running: bool,
|
||||||
pub name: String,
|
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 {
|
impl Default for Game {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
world: World::new(),
|
systems: None,
|
||||||
is_running: true,
|
is_running: true
|
||||||
name: default_game_name(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -42,8 +60,23 @@ impl Game {
|
||||||
Game::default()
|
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) {
|
pub fn run(self) {
|
||||||
info("Running Game...");
|
info("Running Game...");
|
||||||
|
//------------------------------
|
||||||
|
// Run Init on all Systems
|
||||||
|
//------------------------------
|
||||||
let glfw_window_unwrapped = self.glfw_window;
|
let glfw_window_unwrapped = self.glfw_window;
|
||||||
let mut graphics_handler: GraphicsHandler = GraphicsHandler { ..Default::default() };
|
let mut graphics_handler: GraphicsHandler = GraphicsHandler { ..Default::default() };
|
||||||
let context: std::rc::Rc<moonhare_graphics::glium::backend::Context>;
|
let context: std::rc::Rc<moonhare_graphics::glium::backend::Context>;
|
||||||
|
|
@ -56,6 +89,7 @@ impl Game {
|
||||||
handle_window_event(value.as_mut().unwrap());
|
handle_window_event(value.as_mut().unwrap());
|
||||||
render(context.clone());
|
render(context.clone());
|
||||||
|
|
||||||
|
self.base_systems.game_loop();
|
||||||
// update();
|
// update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
crates/moonhare_game/src/systems/mod.rs
Normal file
4
crates/moonhare_game/src/systems/mod.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
pub mod system;
|
||||||
|
pub mod window_system;
|
||||||
|
pub mod update_system;
|
||||||
|
pub mod render_system;
|
||||||
15
crates/moonhare_game/src/systems/render_system.rs
Normal file
15
crates/moonhare_game/src/systems/render_system.rs
Normal 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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
42
crates/moonhare_game/src/systems/system.rs
Normal file
42
crates/moonhare_game/src/systems/system.rs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
15
crates/moonhare_game/src/systems/update_system.rs
Normal file
15
crates/moonhare_game/src/systems/update_system.rs
Normal 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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
20
crates/moonhare_game/src/systems/window_system.rs
Normal file
20
crates/moonhare_game/src/systems/window_system.rs
Normal 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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue