Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
94 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,3 @@ Scion is a minimalist, **easy** to use, modulable game engine built on top of le | |
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,36 @@ | ||
use scion::application::Scion; | ||
use scion::legion::{system, Resources, World}; | ||
use scion::utils::time::Time; | ||
use log::{info}; | ||
use log::info; | ||
use scion::utils::window::WindowDimensions; | ||
|
||
|
||
use scion::renderer::{RendererType, ScionRenderer}; | ||
use miniquad::Context; | ||
use scion::game_layer::{SimpleGameLayer, GameLayer, GameLayerType}; | ||
use scion::legion::systems::ParallelRunnable; | ||
use scion::renderer::bidimensional::triangle::Triangle; | ||
|
||
#[system] | ||
fn time(#[resource] time: &Time) { | ||
info!("Last frame duration : {:?}", time.delta_duration()); | ||
info!("Time elapsed in the last frame : {:?}", time.delta_duration()) | ||
} | ||
|
||
#[system] | ||
fn screen(#[resource] screen_dimension: &WindowDimensions) { | ||
info!("Screen dimension : {:?}", screen_dimension); | ||
#[derive(Default)] | ||
struct Layer; | ||
impl SimpleGameLayer for Layer { | ||
fn on_start(&mut self, world: &mut World, _resource: &mut Resources) { | ||
world.push((Triangle,)); | ||
} | ||
|
||
fn update(&mut self, _world: &mut World, _resource: &mut Resources) { | ||
info!("Hello from game Layer"); | ||
} | ||
} | ||
|
||
fn main() { | ||
Scion::app() | ||
.with_system(time_system()) | ||
.with_system(screen_system()) | ||
.with_renderer(RendererType::Scion2D) | ||
.with_game_layer(GameLayer::weak::<Layer>()) | ||
.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use legion::{Resources, World}; | ||
use std::fmt::Debug; | ||
|
||
/// Trait to implement in order to create a `GameLayer`. | ||
pub trait SimpleGameLayer { | ||
fn on_start(&mut self, _world: &mut World, _resource: &mut Resources) {} | ||
fn update(&mut self, _world: &mut World, _resource: &mut Resources) {} | ||
fn late_update(&mut self, _world: &mut World, _resource: &mut Resources) {} | ||
fn on_stop(&mut self, _world: &mut World, _resource: &mut Resources) {} | ||
} | ||
|
||
pub(crate) enum LayerAction { | ||
UPDATE, START, STOP, LATE_UPDATE | ||
} | ||
|
||
pub struct GameLayer{ | ||
pub(crate) layer: GameLayerType | ||
} | ||
|
||
impl GameLayer { | ||
pub fn weak<T: SimpleGameLayer + Default + 'static>() -> Box<GameLayer> { | ||
Box::new(GameLayer{layer: GameLayerType::Weak(Box::new(T::default()))}) | ||
} | ||
|
||
pub fn strong<T: SimpleGameLayer + Default + 'static>() -> Box<GameLayer> { | ||
Box::new(GameLayer{layer: GameLayerType::Strong(Box::new(T::default()))}) | ||
} | ||
} | ||
|
||
/// The `GameLayer` determines if the layer is blocking the execution queue. | ||
pub enum GameLayerType { | ||
/// All the layers that are under the `STRONG` Layers won't be executed. | ||
Strong(Box<dyn SimpleGameLayer>), | ||
/// The next layer under a `WEAK` layer will be executed | ||
Weak(Box<dyn SimpleGameLayer>), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters