diff --git a/examples/hello-world/main.rs b/examples/hello-world/main.rs index 5842e28..bdca38c 100644 --- a/examples/hello-world/main.rs +++ b/examples/hello-world/main.rs @@ -1,11 +1,19 @@ use scion::application::Scion; -use scion::legion::system; +use scion::legion::{system, Resources, World}; use scion::utils::time::Time; use log::info; use scion::utils::window::WindowDimensions; use scion::config::scion_config::{ScionConfig, ScionConfigBuilder}; use scion::config::window_config::{WindowConfig, WindowConfigBuilder}; +use scion::renderer::{RendererType, ScionRenderer}; +use miniquad::Context; +struct T; +impl ScionRenderer for T{ + fn draw(&mut self, context: &mut Context, world: &mut World, resource: &mut Resources) { + unimplemented!() + } +} #[system] fn time(#[resource] time: &Time) { @@ -21,5 +29,6 @@ fn main() { Scion::app() .with_system(time_system()) .with_system(screen_system()) + .with_renderer(RendererType::Custom(Box::new(T))) .run(); -} +} \ No newline at end of file diff --git a/src/application.rs b/src/application.rs index 566b780..935c19c 100644 --- a/src/application.rs +++ b/src/application.rs @@ -6,6 +6,7 @@ use miniquad::{conf, Context, EventHandlerFree, UserData}; use crate::config::scion_config::{ScionConfig, ScionConfigReader}; use crate::utils::time::Time; use crate::utils::window::WindowDimensions; +use crate::renderer::RendererType; /// `Scion` is the entry point of any application made with Scion engine. pub struct Scion { @@ -68,6 +69,7 @@ impl Scion { pub struct ScionBuilder { config: ScionConfig, schedule_builder: Builder, + renderer: RendererType } impl ScionBuilder { @@ -75,6 +77,7 @@ impl ScionBuilder { Self { config, schedule_builder: Default::default(), + renderer: Default::default() } } @@ -88,7 +91,7 @@ impl ScionBuilder { self } - fn with_thread_local_fn( + pub fn with_thread_local_fn( mut self, function: F, ) -> Self { @@ -96,6 +99,11 @@ impl ScionBuilder { self } + pub fn with_renderer(mut self, renderer_type: RendererType) -> Self{ + self.renderer = renderer_type; + self + } + /// Builds, setups and runs the Scion application pub fn run(mut self) { let scion = Scion { diff --git a/src/config/scion_config.rs b/src/config/scion_config.rs index c7d78db..402da6c 100644 --- a/src/config/scion_config.rs +++ b/src/config/scion_config.rs @@ -23,7 +23,7 @@ impl Default for ScionConfig { Self { app_name: "Scion game".to_string(), logger_config: Some(Default::default()), - window_config: Some(Default::default()) + window_config: Some(Default::default()), } } } diff --git a/src/lib.rs b/src/lib.rs index 44713fc..4a59669 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,3 +4,4 @@ pub use legion; pub mod application; pub mod config; pub mod utils; +pub mod renderer; diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs new file mode 100644 index 0000000..fe9a1ba --- /dev/null +++ b/src/renderer/mod.rs @@ -0,0 +1,20 @@ +use miniquad::Context; +use legion::{World, Resources}; + +/// Trait to implement in order to create a renderer to use in a `Scion` application +pub trait ScionRenderer { + /// The draw method is called each frame + fn draw(&mut self, context: &mut Context, world: &mut World, resource: &mut Resources); +} + +/// Type of renderer to use to render the game. +pub enum RendererType { + Scion2D, + Custom(Box) +} + +impl Default for RendererType{ + fn default() -> Self { + RendererType::Scion2D + } +} \ No newline at end of file