working on custom render layer

This commit is contained in:
Evan Pratten 2021-09-26 16:45:07 -04:00
parent 94b34e0aa0
commit 2c1d620de8
9 changed files with 73 additions and 6 deletions

@ -1,5 +1,6 @@
{
"cSpell.words": [
"raylib"
"raylib",
"renderable"
]
}
}

@ -2,7 +2,12 @@
"name": "Unnamed game",
"authors": [
{
"github": "ewpratten"
"name": "Evan Pratten",
"url": "https://va3zza.com",
"roles": [
"Team Lead",
"Developer"
]
}
]
}
}

1
game/src/gfx/mod.rs Normal file

@ -0,0 +1 @@
pub mod util;

1
game/src/gfx/util/mod.rs Normal file

@ -0,0 +1 @@
pub mod scene;

@ -0,0 +1,20 @@
use raylib::prelude::RaylibDrawHandle;
/// Defines any renderable scene
pub trait Scene<Context, Error> {
/// 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>;
}

@ -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");

@ -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<String>,
pub roles: Vec<String>
}
#[derive(Debug, Clone, Deserialize)]

@ -1,4 +1,5 @@
pub mod discord;
pub mod datastore;
pub mod game_config;
pub mod math;
pub mod math;
pub mod statemachine;

@ -0,0 +1,32 @@
use std::{collections::HashMap, fmt::Display, hash::Hash};
pub struct StateMachine<State, Data>
where
State: Eq + Hash + Clone + Display + Default,
{
default_state: State,
callback_map: HashMap<State, Box<dyn Fn(&mut Data)>>,
}
impl<State, Data> StateMachine<State, Data>
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<dyn Fn(&mut Data)>) {
self.callback_map.insert(self.default_state.clone(), callback);
}
/// Add a new state function
pub fn add_state(&mut self, state: State, callback: Box<dyn Fn(&mut Data)>) {
self.callback_map.insert(state, callback);
}
}