From 2c1d620de863a23cbe89d80a33c71c9c1fc677fe Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 26 Sep 2021 16:45:07 -0400 Subject: [PATCH] working on custom render layer --- .vscode/settings.json | 5 +++-- game/assets/configs/application.json | 9 ++++++-- game/src/gfx/mod.rs | 1 + game/src/gfx/util/mod.rs | 1 + game/src/gfx/util/scene.rs | 20 +++++++++++++++++ game/src/lib.rs | 2 ++ game/src/utilities/game_config.rs | 6 +++++- game/src/utilities/mod.rs | 3 ++- game/src/utilities/statemachine.rs | 32 ++++++++++++++++++++++++++++ 9 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 game/src/gfx/mod.rs create mode 100644 game/src/gfx/util/mod.rs create mode 100644 game/src/gfx/util/scene.rs create mode 100644 game/src/utilities/statemachine.rs diff --git a/.vscode/settings.json b/.vscode/settings.json index ab1db25..a2d525d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "cSpell.words": [ - "raylib" + "raylib", + "renderable" ] -} \ No newline at end of file +} diff --git a/game/assets/configs/application.json b/game/assets/configs/application.json index 8bc0372..5f4b42b 100644 --- a/game/assets/configs/application.json +++ b/game/assets/configs/application.json @@ -2,7 +2,12 @@ "name": "Unnamed game", "authors": [ { - "github": "ewpratten" + "name": "Evan Pratten", + "url": "https://va3zza.com", + "roles": [ + "Team Lead", + "Developer" + ] } ] -} \ No newline at end of file +} diff --git a/game/src/gfx/mod.rs b/game/src/gfx/mod.rs new file mode 100644 index 0000000..812d1ed --- /dev/null +++ b/game/src/gfx/mod.rs @@ -0,0 +1 @@ +pub mod util; diff --git a/game/src/gfx/util/mod.rs b/game/src/gfx/util/mod.rs new file mode 100644 index 0000000..ccbeeae --- /dev/null +++ b/game/src/gfx/util/mod.rs @@ -0,0 +1 @@ +pub mod scene; diff --git a/game/src/gfx/util/scene.rs b/game/src/gfx/util/scene.rs new file mode 100644 index 0000000..9c89177 --- /dev/null +++ b/game/src/gfx/util/scene.rs @@ -0,0 +1,20 @@ +use raylib::prelude::RaylibDrawHandle; + +/// Defines any renderable scene +pub trait Scene { + /// Render the hud layer (screen-space rendering) + fn render_hud( + &mut self, + gfx: &mut RaylibDrawHandle, + delta_seconds: f64, + ctx: &Context, + ) -> Result<(), Error>; + + /// Render the world layer (world-space rendering) + fn render_world( + &mut self, + gfx: &mut RaylibDrawHandle, + delta_seconds: f64, + ctx: &Context, + ) -> Result<(), Error>; +} diff --git a/game/src/lib.rs b/game/src/lib.rs index 9dae3ea..e0dc451 100644 --- a/game/src/lib.rs +++ b/game/src/lib.rs @@ -19,6 +19,7 @@ extern crate serde; mod shaders; mod utilities; +mod gfx; /// The game entrypoint pub async fn game_begin() { @@ -66,6 +67,7 @@ pub async fn game_begin() { .msaa_4x() .resizable() .build(); + rl.set_exit_key(None); // Create a dynamic texture to draw to for processing by shaders info!("Allocating a resizable texture for the screen"); diff --git a/game/src/utilities/game_config.rs b/game/src/utilities/game_config.rs index d578d46..ae50296 100644 --- a/game/src/utilities/game_config.rs +++ b/game/src/utilities/game_config.rs @@ -1,10 +1,14 @@ //! Contains the general configuration data for the game +//! This data is immutable, and should only be edited by hand use rust_embed::EmbeddedFile; +/// Defines one of the game's authors #[derive(Debug, Clone, Deserialize)] pub struct Author { - pub github: String, + pub name: String, + pub url: Option, + pub roles: Vec } #[derive(Debug, Clone, Deserialize)] diff --git a/game/src/utilities/mod.rs b/game/src/utilities/mod.rs index 22dbd14..8df9ece 100644 --- a/game/src/utilities/mod.rs +++ b/game/src/utilities/mod.rs @@ -1,4 +1,5 @@ pub mod discord; pub mod datastore; pub mod game_config; -pub mod math; \ No newline at end of file +pub mod math; +pub mod statemachine; diff --git a/game/src/utilities/statemachine.rs b/game/src/utilities/statemachine.rs new file mode 100644 index 0000000..550ab35 --- /dev/null +++ b/game/src/utilities/statemachine.rs @@ -0,0 +1,32 @@ +use std::{collections::HashMap, fmt::Display, hash::Hash}; + +pub struct StateMachine +where + State: Eq + Hash + Clone + Display + Default, +{ + default_state: State, + callback_map: HashMap>, +} + +impl StateMachine +where + State: Eq + Hash + Clone + Display + Default, +{ + /// Construct a new StateMachine + pub fn new() -> Self { + Self { + default_state: State::default(), + callback_map: HashMap::new(), + } + } + + /// Override the default state function + pub fn set_default_handler(&mut self, callback: Box) { + self.callback_map.insert(self.default_state.clone(), callback); + } + + /// Add a new state function + pub fn add_state(&mut self, state: State, callback: Box) { + self.callback_map.insert(state, callback); + } +}