????
This commit is contained in:
parent
d594b3f568
commit
62438e0d24
15 changed files with 157 additions and 7 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
|
@ -769,6 +769,15 @@ dependencies = [
|
||||||
"adler2",
|
"adler2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "moonhare_derives"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "moonhare_ecs"
|
name = "moonhare_ecs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
@ -791,6 +800,7 @@ version = "0.1.0"
|
||||||
name = "moonhare_game"
|
name = "moonhare_game"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"moonhare_derives",
|
||||||
"moonhare_ecs",
|
"moonhare_ecs",
|
||||||
"moonhare_graphics",
|
"moonhare_graphics",
|
||||||
"moonhare_log",
|
"moonhare_log",
|
||||||
|
|
@ -811,6 +821,7 @@ dependencies = [
|
||||||
name = "moonhare_internal"
|
name = "moonhare_internal"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"moonhare_derives",
|
||||||
"moonhare_ecs",
|
"moonhare_ecs",
|
||||||
"moonhare_event",
|
"moonhare_event",
|
||||||
"moonhare_game",
|
"moonhare_game",
|
||||||
|
|
|
||||||
14
crates/moonhare_derives/Cargo.toml
Normal file
14
crates/moonhare_derives/Cargo.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
[package]
|
||||||
|
edition = "2024"
|
||||||
|
name = "moonhare_derives"
|
||||||
|
version.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
syn = "2.0"
|
||||||
|
proc-macro2 = "1"
|
||||||
|
quote = "1"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
proc-macro = true
|
||||||
|
|
||||||
32
crates/moonhare_derives/src/lib.rs
Normal file
32
crates/moonhare_derives/src/lib.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
|
use syn::{parse_macro_input, parse_quote, DeriveInput, GenericParam, Generics};
|
||||||
|
use proc_macro::{self, TokenStream};
|
||||||
|
|
||||||
|
mod node;
|
||||||
|
mod system;
|
||||||
|
|
||||||
|
#[proc_macro_derive(System)]
|
||||||
|
pub fn system(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||||
|
let input = parse_macro_input!(input as DeriveInput);
|
||||||
|
|
||||||
|
system::system(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[proc_macro_derive(Node)]
|
||||||
|
pub fn node(input: proc_macro::TokenStream) -> TokenStream {
|
||||||
|
let input = parse_macro_input!(input as DeriveInput);
|
||||||
|
|
||||||
|
TokenStream::from(node::node(input))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a bound `T: Node` to every type parameter T.
|
||||||
|
fn add_trait_bounds(mut generics: Generics) -> Generics {
|
||||||
|
for param in &mut generics.params {
|
||||||
|
if let GenericParam::Type(ref mut type_param) = *param {
|
||||||
|
type_param.bounds.push(parse_quote!(node::Node));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
generics
|
||||||
|
}
|
||||||
24
crates/moonhare_derives/src/node.rs
Normal file
24
crates/moonhare_derives/src/node.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
use proc_macro::TokenStream;
|
||||||
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
|
use quote::quote;
|
||||||
|
use syn::DeriveInput;
|
||||||
|
|
||||||
|
use crate::add_trait_bounds;
|
||||||
|
|
||||||
|
pub fn node(input: DeriveInput) -> TokenStream2 {
|
||||||
|
let name = input.ident;
|
||||||
|
|
||||||
|
let expanded = quote! {
|
||||||
|
impl Node for #name {
|
||||||
|
fn init(&mut self) {
|
||||||
|
self.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self) {
|
||||||
|
self.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
expanded
|
||||||
|
}
|
||||||
31
crates/moonhare_derives/src/system.rs
Normal file
31
crates/moonhare_derives/src/system.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
use proc_macro::TokenStream;
|
||||||
|
use quote::quote;
|
||||||
|
use syn::DeriveInput;
|
||||||
|
|
||||||
|
use crate::add_trait_bounds;
|
||||||
|
|
||||||
|
|
||||||
|
pub fn system(input: DeriveInput) -> TokenStream {
|
||||||
|
let name = input.ident;
|
||||||
|
|
||||||
|
let generics = add_trait_bounds(input.generics);
|
||||||
|
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
|
||||||
|
|
||||||
|
let expanded = quote! {
|
||||||
|
impl #name {
|
||||||
|
fn init(&mut self) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_child(&mut self, child: Self) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
proc_macro::TokenStream::from(expanded)
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,9 @@ version.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
moonhare_derives = { path = "../moonhare_derives" }
|
||||||
moonhare_ecs = { path = "../moonhare_ecs" }
|
moonhare_ecs = { path = "../moonhare_ecs" }
|
||||||
moonhare_graphics = { path = "../moonhare_graphics" }
|
moonhare_graphics = { path = "../moonhare_graphics" }
|
||||||
moonhare_log = { path = "../moonhare_log" }
|
moonhare_log = { path = "../moonhare_log" }
|
||||||
moonhare_window = { path = "../moonhare_window" }
|
moonhare_window = { path = "../moonhare_window" }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
pub mod node;
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
pub trait Node {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -10,9 +10,7 @@ use moonhare_window::{platforms::glfw_window::GLFWWindow};
|
||||||
use crate::systems::system::{BaseSystems, System};
|
use crate::systems::system::{BaseSystems, System};
|
||||||
|
|
||||||
pub mod systems;
|
pub mod systems;
|
||||||
pub mod basic;
|
pub mod nodes;
|
||||||
|
|
||||||
/// Only one Game may exist per project
|
|
||||||
/* #[derive(Debug)]
|
/* #[derive(Debug)]
|
||||||
pub struct Game {
|
pub struct Game {
|
||||||
pub base_systems: BaseSystems,
|
pub base_systems: BaseSystems,
|
||||||
|
|
@ -22,6 +20,7 @@ pub struct Game {
|
||||||
pub name: String,
|
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
|
// BaseSystems -> Window, Update, Render
|
||||||
|
|
||||||
|
|
@ -73,6 +72,8 @@ impl Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(self) {
|
pub fn run(self) {
|
||||||
|
|
||||||
|
|
||||||
info("Running Game...");
|
info("Running Game...");
|
||||||
//------------------------------
|
//------------------------------
|
||||||
// Run Init on all Systems
|
// Run Init on all Systems
|
||||||
|
|
@ -116,3 +117,4 @@ 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);
|
moonhare_graphics::draw_background_color(Color::color_from_rgb(255, 255, 255), target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
crates/moonhare_game/src/nodes/mod.rs
Normal file
2
crates/moonhare_game/src/nodes/mod.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod node;
|
||||||
|
pub mod window;
|
||||||
16
crates/moonhare_game/src/nodes/node.rs
Normal file
16
crates/moonhare_game/src/nodes/node.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
use moonhare_derives::Node;
|
||||||
|
|
||||||
|
pub trait Node {
|
||||||
|
fn init(&mut self);
|
||||||
|
fn update(&mut self);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Node for Box<T> {
|
||||||
|
fn init(&mut self) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
17
crates/moonhare_game/src/nodes/window.rs
Normal file
17
crates/moonhare_game/src/nodes/window.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
use moonhare_derives::Node;
|
||||||
|
use crate::nodes::node::Node;
|
||||||
|
|
||||||
|
#[derive(Node)]
|
||||||
|
struct Window {
|
||||||
|
a: Box<String>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Window {
|
||||||
|
fn init(&mut self) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ authors.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
|
moonhare_derives = { path = "../moonhare_derives" }
|
||||||
moonhare_ecs = { path = "../moonhare_ecs" }
|
moonhare_ecs = { path = "../moonhare_ecs" }
|
||||||
moonhare_event = { path = "../moonhare_event" }
|
moonhare_event = { path = "../moonhare_event" }
|
||||||
moonhare_game = { path = "../moonhare_game" }
|
moonhare_game = { path = "../moonhare_game" }
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
pub use moonhare_derives as moon_derives;
|
||||||
pub use moonhare_ecs as ecs;
|
pub use moonhare_ecs as ecs;
|
||||||
pub use moonhare_event as event;
|
pub use moonhare_event as event;
|
||||||
pub use moonhare_game as game;
|
pub use moonhare_game as game;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use std::fs::File;
|
||||||
|
|
||||||
use moonhare_engine::{game::Game, log};
|
use moonhare_engine::{game::Game, log};
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = log::configere_logger();
|
let _ = log::configere_logger();
|
||||||
log::info("test");
|
log::info("test");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue