Rendering game version on screen
This commit is contained in:
parent
471d78075f
commit
5add6e1c65
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -2,6 +2,7 @@
|
|||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"clippy",
|
"clippy",
|
||||||
"raylib",
|
"raylib",
|
||||||
"renderable"
|
"renderable",
|
||||||
|
"vergen"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ name = "game"
|
|||||||
publish = false
|
publish = false
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -24,6 +25,12 @@ sentry = "0.23"
|
|||||||
image = "0.23"
|
image = "0.23"
|
||||||
tempfile = "3.2"
|
tempfile = "3.2"
|
||||||
approx = "0.5"
|
approx = "0.5"
|
||||||
|
pkg-version = "1.0"
|
||||||
|
cfg-if = "1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
puffin_viewer = "0.6"
|
puffin_viewer = "0.6"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
vergen = "5"
|
||||||
|
anyhow = "1.0"
|
||||||
|
10
game/build.rs
Normal file
10
game/build.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
use anyhow::Result;
|
||||||
|
use vergen::{Config, ShaKind, vergen};
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
|
||||||
|
// Reads local Git information to inject into the executable at build time
|
||||||
|
let mut config = Config::default();
|
||||||
|
*config.git_mut().sha_kind_mut() = ShaKind::Short;
|
||||||
|
vergen(config)
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
#![feature(plugin)]
|
|
||||||
#![feature(derive_default_enum)]
|
#![feature(derive_default_enum)]
|
||||||
|
#![feature(custom_inner_attributes)]
|
||||||
|
#![feature(stmt_expr_attributes)]
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
#![warn(
|
#![warn(
|
||||||
clippy::all,
|
clippy::all,
|
||||||
@ -65,7 +66,6 @@
|
|||||||
nonstandard_style,
|
nonstandard_style,
|
||||||
rust_2018_idioms
|
rust_2018_idioms
|
||||||
)]
|
)]
|
||||||
#![feature(custom_inner_attributes)]
|
|
||||||
#![clippy::msrv = "1.57.0"]
|
#![clippy::msrv = "1.57.0"]
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
@ -73,7 +73,7 @@ impl Action<Scenes, ScreenError, GameContext> for LoadingScreen {
|
|||||||
let duration = Utc::now().signed_duration_since(start_timestamp);
|
let duration = Utc::now().signed_duration_since(start_timestamp);
|
||||||
if duration.num_seconds() >= LOADING_SCREEN_DURATION_SECONDS as i64 {
|
if duration.num_seconds() >= LOADING_SCREEN_DURATION_SECONDS as i64 {
|
||||||
info!("LoadingScreen duration reached, moving to next screen");
|
info!("LoadingScreen duration reached, moving to next screen");
|
||||||
Ok(ActionFlag::SwitchState(Scenes::FsmErrorScreen))
|
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
|
||||||
} else {
|
} else {
|
||||||
Ok(ActionFlag::Continue)
|
Ok(ActionFlag::Continue)
|
||||||
}
|
}
|
||||||
|
83
game/src/scenes/main_menu_screen.rs
Normal file
83
game/src/scenes/main_menu_screen.rs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
use std::ops::{Div, Sub};
|
||||||
|
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use dirty_fsm::{Action, ActionFlag};
|
||||||
|
use pkg_version::pkg_version_major;
|
||||||
|
use raylib::prelude::*;
|
||||||
|
|
||||||
|
use crate::{context::GameContext, utilities::{datastore::{load_texture_from_internal_data, ResourceLoadError}, game_version::get_version_string, math::interpolate_exp, non_ref_raylib::HackedRaylibHandle, render_layer::ScreenSpaceRender}};
|
||||||
|
|
||||||
|
use super::{Scenes, ScreenError};
|
||||||
|
use tracing::{debug, info, trace};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct MainMenuScreen {}
|
||||||
|
|
||||||
|
impl MainMenuScreen {
|
||||||
|
/// Construct a new `MainMenuScreen`
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Action<Scenes, ScreenError, GameContext> for MainMenuScreen {
|
||||||
|
fn on_register(&mut self) -> Result<(), ScreenError> {
|
||||||
|
debug!("Registered");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_first_run(&mut self, _context: &GameContext) -> Result<(), ScreenError> {
|
||||||
|
debug!("Running MainMenuScreen for the first time");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn execute(
|
||||||
|
&mut self,
|
||||||
|
_delta: &chrono::Duration,
|
||||||
|
context: &GameContext,
|
||||||
|
) -> Result<dirty_fsm::ActionFlag<Scenes>, ScreenError> {
|
||||||
|
trace!("execute() called on MainMenuScreen");
|
||||||
|
self.render_screen_space(&mut context.renderer.borrow_mut());
|
||||||
|
|
||||||
|
Ok(ActionFlag::Continue)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> {
|
||||||
|
debug!("Finished MainMenuScreen");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ScreenSpaceRender for MainMenuScreen {
|
||||||
|
fn render_screen_space(
|
||||||
|
&self,
|
||||||
|
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
|
||||||
|
) {
|
||||||
|
// Render the background
|
||||||
|
raylib.clear_background(Color::WHITE);
|
||||||
|
|
||||||
|
// Calculate the logo position
|
||||||
|
let screen_size = raylib.get_screen_size();
|
||||||
|
|
||||||
|
// Only in debug mode, render a debug message
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
{
|
||||||
|
raylib.draw_text(
|
||||||
|
"Game in DEBUG MODE. Do not redistribute!",
|
||||||
|
10,
|
||||||
|
screen_size.y as i32 - 35,
|
||||||
|
15,
|
||||||
|
Color::BLACK,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Render the game version info
|
||||||
|
raylib.draw_text(
|
||||||
|
&format!("Version: {} Commit: {}", get_version_string(), env!("VERGEN_GIT_SHA_SHORT")),
|
||||||
|
10,
|
||||||
|
screen_size.y as i32 - 20,
|
||||||
|
15,
|
||||||
|
Color::BLACK,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,17 @@
|
|||||||
|
use self::{
|
||||||
|
fsm_error_screen::FsmErrorScreen, loading_screen::LoadingScreen,
|
||||||
|
main_menu_screen::MainMenuScreen,
|
||||||
|
};
|
||||||
|
use crate::{
|
||||||
|
context::GameContext,
|
||||||
|
utilities::{datastore::ResourceLoadError, non_ref_raylib::HackedRaylibHandle},
|
||||||
|
};
|
||||||
use dirty_fsm::StateMachine;
|
use dirty_fsm::StateMachine;
|
||||||
use raylib::RaylibThread;
|
use raylib::RaylibThread;
|
||||||
use crate::{context::GameContext, utilities::{datastore::ResourceLoadError, non_ref_raylib::HackedRaylibHandle}};
|
|
||||||
use self::{fsm_error_screen::FsmErrorScreen, loading_screen::LoadingScreen};
|
|
||||||
|
|
||||||
pub mod fsm_error_screen;
|
pub mod fsm_error_screen;
|
||||||
pub mod loading_screen;
|
pub mod loading_screen;
|
||||||
|
pub mod main_menu_screen;
|
||||||
|
|
||||||
/// Defines all scenes
|
/// Defines all scenes
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
|
||||||
@ -12,23 +19,31 @@ pub enum Scenes {
|
|||||||
#[default]
|
#[default]
|
||||||
FsmErrorScreen,
|
FsmErrorScreen,
|
||||||
LoadingScreen,
|
LoadingScreen,
|
||||||
|
MainMenuScreen,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Contains any possible errors thrown while rendering
|
/// Contains any possible errors thrown while rendering
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum ScreenError {
|
pub enum ScreenError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
ResourceLoad(#[from] ResourceLoadError)
|
ResourceLoad(#[from] ResourceLoadError),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build the state machine for all scenes
|
/// Build the state machine for all scenes
|
||||||
pub fn build_screen_state_machine(raylib_handle: &mut HackedRaylibHandle, thread: &RaylibThread) -> Result<
|
pub fn build_screen_state_machine(
|
||||||
|
raylib_handle: &mut HackedRaylibHandle,
|
||||||
|
thread: &RaylibThread,
|
||||||
|
) -> Result<
|
||||||
// StateMachine<Scenes, ScreenError, RefCell<(NonRefDrawHandle, Rc<RefCell<GameContext>>)>>,
|
// StateMachine<Scenes, ScreenError, RefCell<(NonRefDrawHandle, Rc<RefCell<GameContext>>)>>,
|
||||||
StateMachine<Scenes, ScreenError, GameContext>,
|
StateMachine<Scenes, ScreenError, GameContext>,
|
||||||
ScreenError,
|
ScreenError,
|
||||||
> {
|
> {
|
||||||
let mut machine = StateMachine::new();
|
let mut machine = StateMachine::new();
|
||||||
machine.add_action(Scenes::FsmErrorScreen, FsmErrorScreen::new())?;
|
machine.add_action(Scenes::FsmErrorScreen, FsmErrorScreen::new())?;
|
||||||
machine.add_action(Scenes::LoadingScreen, LoadingScreen::new(raylib_handle, thread)?)?;
|
machine.add_action(
|
||||||
|
Scenes::LoadingScreen,
|
||||||
|
LoadingScreen::new(raylib_handle, thread)?,
|
||||||
|
)?;
|
||||||
|
machine.add_action(Scenes::MainMenuScreen, MainMenuScreen::new())?;
|
||||||
Ok(machine)
|
Ok(machine)
|
||||||
}
|
}
|
||||||
|
25
game/src/utilities/game_version.rs
Normal file
25
game/src/utilities/game_version.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
use cfg_if::cfg_if;
|
||||||
|
use pkg_version::*;
|
||||||
|
|
||||||
|
const GAME_VERSION_MAJOR: u32 = pkg_version_major!();
|
||||||
|
const GAME_VERSION_MINOR: u32 = pkg_version_minor!();
|
||||||
|
const GAME_VERSION_PATCH: u32 = pkg_version_patch!();
|
||||||
|
|
||||||
|
/// Get the game version as a string
|
||||||
|
#[inline]
|
||||||
|
pub fn get_version_string() -> String {
|
||||||
|
format!(
|
||||||
|
"v{}.{}.{}{}",
|
||||||
|
GAME_VERSION_MAJOR,
|
||||||
|
GAME_VERSION_MINOR,
|
||||||
|
GAME_VERSION_PATCH,
|
||||||
|
{
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(debug_assertions)] {
|
||||||
|
"-debug"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
@ -5,3 +5,4 @@ pub mod math;
|
|||||||
pub mod shaders;
|
pub mod shaders;
|
||||||
pub mod non_ref_raylib;
|
pub mod non_ref_raylib;
|
||||||
pub mod render_layer;
|
pub mod render_layer;
|
||||||
|
pub mod game_version;
|
||||||
|
Reference in New Issue
Block a user