From e9504890815c0df68c7c85a5f914bf8e193f40a2 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Wed, 29 Sep 2021 17:12:19 -0400 Subject: [PATCH] working on loading screen --- game/src/scenes/loading_screen.rs | 48 ++++++++++++++++++++++++++----- game/src/scenes/mod.rs | 24 ++++------------ 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/game/src/scenes/loading_screen.rs b/game/src/scenes/loading_screen.rs index 1889201..692ef62 100644 --- a/game/src/scenes/loading_screen.rs +++ b/game/src/scenes/loading_screen.rs @@ -1,28 +1,62 @@ -use dirty_fsm::Action; +use chrono::{DateTime, Utc}; +use dirty_fsm::{Action, ActionFlag}; -use crate::context::GameContext; +use crate::{context::GameContext, gfx::render_layer::ScreenSpaceRender}; use super::{Scenes, ScreenError}; +use tracing::{debug, error, info, trace}; #[derive(Debug)] pub struct LoadingScreen { + start_timestamp: Option> +} +impl LoadingScreen { + /// Construct a new LoadingScreen + pub fn new() -> Self { + Self { + start_timestamp: None + } + } } impl Action for LoadingScreen { fn on_register(&mut self) -> Result<(), ScreenError> { - todo!() + debug!("Registered"); + Ok(()) } - fn on_first_run(&mut self, context: &mut GameContext) -> Result<(), ScreenError> { - todo!() + fn on_first_run(&mut self, context: &GameContext) -> Result<(), ScreenError> { + debug!("Running LoadingScreen for the first time"); + + // Keep track of when this screen is opened + self.start_timestamp = Some(Utc::now()); + + Ok(()) } - fn execute(&mut self, delta: &chrono::Duration, context: &mut GameContext) -> Result, ScreenError> { - todo!() + fn execute( + &mut self, + delta: &chrono::Duration, + context: &GameContext, + ) -> Result, ScreenError> { + trace!("execute() called on LoadingScreen"); + self.render_screen_space(&mut context.renderer.borrow_mut()); + Ok(ActionFlag::Continue) } fn on_finish(&mut self, interrupted: bool) -> Result<(), ScreenError> { + debug!("Finished LoadingScreen"); + + // Reset the start timestamp + self.start_timestamp = None; + + Ok(()) + } +} + +impl ScreenSpaceRender for LoadingScreen { + fn render_screen_space(&self, raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle) { todo!() } } diff --git a/game/src/scenes/mod.rs b/game/src/scenes/mod.rs index 4e5dc40..c4f3252 100644 --- a/game/src/scenes/mod.rs +++ b/game/src/scenes/mod.rs @@ -1,24 +1,9 @@ -use std::{ - borrow::Borrow, - cell::{Cell, RefCell, RefMut}, - rc::Rc, -}; - -use dirty_fsm::{Action, StateMachine}; -use raylib::{ - prelude::{RaylibDraw, RaylibDrawHandle}, - RaylibHandle, -}; - -use crate::{context::GameContext, gfx::render_layer::{FrameUpdate, ScreenSpaceRender, WorldSpaceRender}, utilities::non_ref_raylib::HackedRaylibHandle}; - -use self::fsm_error_screen::FsmErrorScreen; +use dirty_fsm::StateMachine; +use crate::context::GameContext; +use self::{fsm_error_screen::FsmErrorScreen, loading_screen::LoadingScreen}; pub mod fsm_error_screen; -// pub mod loading_screen; - -/// Data passed to all scenes upon render -// pub type RenderContext<'a, 'b> = (&'b mut RaylibDrawHandle<'a>, &'b mut GameContext); +pub mod loading_screen; /// Defines all scenes #[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)] @@ -40,5 +25,6 @@ pub fn build_screen_state_machine() -> Result< > { let mut machine = StateMachine::new(); machine.add_action(Scenes::FsmErrorScreen, FsmErrorScreen::new())?; + machine.add_action(Scenes::LoadingScreen, LoadingScreen::new())?; Ok(machine) }