format
This commit is contained in:
parent
b873398a79
commit
e2d5748733
41 changed files with 291 additions and 268 deletions
|
|
@ -1 +1 @@
|
|||
pub mod world;
|
||||
pub mod world;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
use crate::nodes::node::Node;
|
||||
|
||||
/// World holds Nodes
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct World {
|
||||
nodes: Vec<Box<dyn Node>>
|
||||
nodes: Vec<Box<dyn Node>>,
|
||||
}
|
||||
|
||||
impl World {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
nodes: vec![]
|
||||
}
|
||||
Self { nodes: vec![] }
|
||||
}
|
||||
|
||||
pub fn add_node(&mut self, node: Box<dyn Node>) {
|
||||
|
|
@ -27,4 +26,4 @@ impl World {
|
|||
node.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,16 +2,21 @@
|
|||
|
||||
use std::{any::Any, rc::Rc};
|
||||
|
||||
|
||||
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_window::{platforms::glfw_window::GLFWWindow};
|
||||
use moonhare_window::platforms::glfw_window::GLFWWindow;
|
||||
|
||||
use crate::{basic::world::{self, World}, systems::system::{BaseSystems, System}};
|
||||
use crate::{
|
||||
basic::world::{self, World},
|
||||
systems::system::{BaseSystems, System},
|
||||
};
|
||||
|
||||
pub mod systems;
|
||||
pub mod basic;
|
||||
pub mod nodes;
|
||||
pub mod systems;
|
||||
/* #[derive(Debug)]
|
||||
pub struct Game {
|
||||
pub base_systems: BaseSystems,
|
||||
|
|
@ -21,32 +26,30 @@ pub struct Game {
|
|||
pub name: String,
|
||||
} */
|
||||
|
||||
|
||||
// when creating a game, you can add systems to it, which do _things_
|
||||
// when creating a game, you can add systems to it, which do _things_
|
||||
// BaseSystems -> Window, Update, Render
|
||||
|
||||
// Hierachy:
|
||||
// [Game] -> <Systems> -> <Nodes> (-> <Nodes> -> ... )
|
||||
// [Game] -> <World> -> <Nodes> (-> <Nodes> -> ... )
|
||||
//-------------
|
||||
// [ ] => only 1 --- < > => allow multiple
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Game {
|
||||
pub world: Vec<World>,
|
||||
pub is_running: bool
|
||||
pub is_running: bool,
|
||||
}
|
||||
|
||||
|
||||
impl Default for Game {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
Self {
|
||||
world: vec![],
|
||||
is_running: true
|
||||
is_running: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GraphicsHandler {
|
||||
pub context: Option<Rc<Context>>
|
||||
pub context: Option<Rc<Context>>,
|
||||
}
|
||||
|
||||
impl Default for GraphicsHandler {
|
||||
|
|
@ -81,12 +84,8 @@ impl Game {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
fn default_game_name() -> String {
|
||||
"Moonhare Game".to_owned()
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,21 +8,14 @@ pub trait Node: DynClone {
|
|||
}
|
||||
dyn_clone::clone_trait_object!(Node);
|
||||
|
||||
|
||||
|
||||
|
||||
impl Debug for dyn Node {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||
writeln!(f, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Clone> Node for Box<T> {
|
||||
fn init(&mut self) {
|
||||
|
||||
}
|
||||
fn init(&mut self) {}
|
||||
|
||||
fn update(&mut self) {
|
||||
|
||||
}
|
||||
fn update(&mut self) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,26 @@
|
|||
use std::rc::Rc;
|
||||
|
||||
use crate::nodes::node::Node;
|
||||
use moonhare_derives::Node;
|
||||
use moonhare_graphics::{color::Color, glium::backend::Context};
|
||||
use moonhare_window::{glfw::RenderContext, platforms::glfw_window::{self, GLFWWindow}};
|
||||
use crate::nodes::node::Node;
|
||||
use moonhare_window::{
|
||||
glfw::RenderContext,
|
||||
platforms::glfw_window::{self, GLFWWindow},
|
||||
};
|
||||
|
||||
#[derive(Node, Clone)]
|
||||
pub struct Window {
|
||||
context: moonhare_window::WindowRenderContext,
|
||||
glfw_window: Option<moonhare_window::platforms::glfw_window::GLFWWindow>,
|
||||
render_context: Option<Rc<Context>>
|
||||
render_context: Option<Rc<Context>>,
|
||||
}
|
||||
|
||||
impl Default for Window {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
context: moonhare_window::WindowRenderContext::OPENGLGLFW,
|
||||
glfw_window: None,
|
||||
render_context: None
|
||||
Self {
|
||||
context: moonhare_window::WindowRenderContext::OPENGLGLFW,
|
||||
glfw_window: None,
|
||||
render_context: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,7 +30,9 @@ impl Window {
|
|||
Self {
|
||||
context: moonhare_window::WindowRenderContext::OPENGLGLFW,
|
||||
glfw_window: Some(moonhare_window::Window::create(self.context)),
|
||||
render_context: Some(moonhare_graphics::build_context(self.glfw_window.clone().unwrap().glfw_window))
|
||||
render_context: Some(moonhare_graphics::build_context(
|
||||
self.glfw_window.clone().unwrap().glfw_window,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -40,11 +45,15 @@ impl Window {
|
|||
fn handle_window_event(glfw_window: &GLFWWindow) {
|
||||
glfw_window.glfw_window.borrow_mut().glfw.poll_events();
|
||||
for (_, event) in moonhare_window::glfw::flush_messages(&glfw_window.events.borrow()) {
|
||||
moonhare_window::platforms::glfw_window::GLFWWindow::handle_window_event(&glfw_window, event);
|
||||
}
|
||||
moonhare_window::platforms::glfw_window::GLFWWindow::handle_window_event(
|
||||
&glfw_window,
|
||||
event,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn render(context: Rc<Context>) {
|
||||
let target = moonhare_graphics::glium::Frame::new(context.clone(), context.get_framebuffer_dimensions());
|
||||
let target =
|
||||
moonhare_graphics::glium::Frame::new(context.clone(), context.get_framebuffer_dimensions());
|
||||
moonhare_graphics::draw_background_color(Color::color_from_rgb(255, 255, 255), target);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
pub mod render_system;
|
||||
pub mod system;
|
||||
pub mod window_system;
|
||||
pub mod update_system;
|
||||
pub mod render_system;
|
||||
pub mod window_system;
|
||||
|
|
|
|||
|
|
@ -3,13 +3,9 @@ pub struct RenderSystem;
|
|||
|
||||
impl Default for RenderSystem {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
}
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
impl RenderSystem {
|
||||
pub(crate) fn update(&self) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
pub(crate) fn update(&self) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
use std::fmt::{Debug, Formatter};
|
||||
|
||||
use crate::systems::{render_system::RenderSystem, update_system::UpdateSystem, window_system::WindowSystem};
|
||||
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
|
||||
|
|
@ -10,7 +12,7 @@ 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
|
||||
|
|
@ -26,10 +28,10 @@ pub struct BaseSystems {
|
|||
|
||||
impl BaseSystems {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
window_system: WindowSystem::default(),
|
||||
update_system: UpdateSystem,
|
||||
render_system: RenderSystem
|
||||
Self {
|
||||
window_system: WindowSystem::default(),
|
||||
update_system: UpdateSystem,
|
||||
render_system: RenderSystem,
|
||||
}
|
||||
}
|
||||
pub fn game_loop(&self) {
|
||||
|
|
@ -37,6 +39,6 @@ impl BaseSystems {
|
|||
|
||||
self.update_system.update();
|
||||
|
||||
self.render_system.update();
|
||||
self.render_system.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,10 @@ pub struct UpdateSystem;
|
|||
|
||||
impl Default for UpdateSystem {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
}
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl UpdateSystem {
|
||||
pub(crate) fn update(&self) {
|
||||
|
||||
}
|
||||
}
|
||||
pub(crate) fn update(&self) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,13 @@ pub struct WindowSystem {
|
|||
|
||||
impl Default for WindowSystem {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
context: moonhare_window::WindowRenderContext::OPENGLGLFW,
|
||||
glfw_window: None
|
||||
Self {
|
||||
context: moonhare_window::WindowRenderContext::OPENGLGLFW,
|
||||
glfw_window: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WindowSystem {
|
||||
pub(crate) fn update(&self) {
|
||||
|
||||
}
|
||||
}
|
||||
pub(crate) fn update(&self) {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue