From 18942b5db8b3e475fc4463e5dca24f39bb78ea01 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Fri, 1 Apr 2022 23:42:40 -0400 Subject: [PATCH] Add project constants to all render code --- game/game_logic/src/rendering/event_loop.rs | 19 ++++++----- game/game_logic/src/scenes/mod.rs | 17 +++++++--- .../src/scenes/player_interaction.rs | 32 ++++++++++++++----- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/game/game_logic/src/rendering/event_loop.rs b/game/game_logic/src/rendering/event_loop.rs index 1a87b4fc..3b9dc90a 100644 --- a/game/game_logic/src/rendering/event_loop.rs +++ b/game/game_logic/src/rendering/event_loop.rs @@ -14,9 +14,9 @@ use crate::project_constants::ProjectConstants; use crate::rendering::core_renderer_sm::{PreloadState, RenderBackendStates}; use crate::rendering::screens::sm_failure_screen; use crate::scenes::SceneRenderDelegate; -use raylib::RaylibBuilder; use raylib::consts::KeyboardKey; use raylib::prelude::RaylibDraw; +use raylib::RaylibBuilder; /// Will begin rendering graphics. Returns when the window closes pub async fn handle_graphics_blocking( @@ -48,7 +48,7 @@ pub async fn handle_graphics_blocking( // Set up the main render delegate let mut render_delegate = - SceneRenderDelegate::on_game_start(&mut raylib_handle, &raylib_thread); + SceneRenderDelegate::on_game_start(&mut raylib_handle, &raylib_thread, constants); // Handle loading the resources and rendering the loading screen log::trace!("Running event loop"); @@ -102,12 +102,15 @@ pub async fn handle_graphics_blocking( .await; } RenderBackendStates::RenderGame(ref m) => { - render_delegate.process_ingame_frame( - &mut raylib_handle, - &raylib_thread, - &discord_signaling, - &global_resources, - ).await; + render_delegate + .process_ingame_frame( + &mut raylib_handle, + &raylib_thread, + &discord_signaling, + &global_resources, + constants, + ) + .await; } _ => backend_sm = RenderBackendStates::sm_failed(), }; diff --git a/game/game_logic/src/scenes/mod.rs b/game/game_logic/src/scenes/mod.rs index a5ebcdea..940ccafd 100644 --- a/game/game_logic/src/scenes/mod.rs +++ b/game/game_logic/src/scenes/mod.rs @@ -5,7 +5,10 @@ //! This will probably become a messy module over time. Stick your rendering code here use raylib::prelude::*; -use crate::{discord::DiscordChannel, global_resource_package::GlobalResources}; +use crate::{ + discord::DiscordChannel, global_resource_package::GlobalResources, + project_constants::ProjectConstants, +}; use self::{player_interaction::PlayableScene, test_fox::TestFoxScene}; mod player_interaction; @@ -21,12 +24,16 @@ pub struct SceneRenderDelegate { impl SceneRenderDelegate { /// This is called when the game first loads - pub fn on_game_start(raylib: &mut RaylibHandle, rl_thread: &RaylibThread) -> Self { + pub fn on_game_start( + raylib: &mut RaylibHandle, + rl_thread: &RaylibThread, + constants: &ProjectConstants, + ) -> Self { // TODO: Stick any init code you want here. // Init some scenes let scene_test_fox = TestFoxScene::new(raylib, rl_thread); - let scene_playable = PlayableScene::new(raylib, rl_thread); + let scene_playable = PlayableScene::new(raylib, rl_thread, constants); Self { scene_test_fox, @@ -43,10 +50,12 @@ impl SceneRenderDelegate { rl_thread: &RaylibThread, discord: &DiscordChannel, global_resources: &GlobalResources, + constants: &ProjectConstants, ) { // For now, we will just render the game scene self.scene_playable - .render_frame(raylib, rl_thread, &discord, global_resources).await; + .render_frame(raylib, rl_thread, &discord, global_resources, constants) + .await; } } diff --git a/game/game_logic/src/scenes/player_interaction.rs b/game/game_logic/src/scenes/player_interaction.rs index 1df9bd26..db34e0bd 100644 --- a/game/game_logic/src/scenes/player_interaction.rs +++ b/game/game_logic/src/scenes/player_interaction.rs @@ -4,22 +4,29 @@ use nalgebra as na; use raylib::prelude::*; use crate::{ - discord::{DiscordChannel, DiscordRpcSignal}, global_resource_package::GlobalResources, - rendering::utilities::anim_texture::AnimatedTexture, model::player::Player, + discord::{DiscordChannel, DiscordRpcSignal}, + global_resource_package::GlobalResources, + model::player::Player, + project_constants::ProjectConstants, + rendering::utilities::anim_texture::AnimatedTexture, }; #[derive(Debug)] pub struct PlayableScene { has_updated_discord_rpc: bool, - player: Player + player: Player, } impl PlayableScene { /// Construct a new `PlayableScene` - pub fn new(raylib_handle: &mut RaylibHandle, thread: &RaylibThread) -> Self { + pub fn new( + raylib_handle: &mut RaylibHandle, + thread: &RaylibThread, + constants: &ProjectConstants, + ) -> Self { Self { has_updated_discord_rpc: false, - player: Player::new(na::Vector2::new(10.0, 10.0)) + player: Player::new(na::Vector2::new(10.0, 10.0)), } } @@ -30,12 +37,21 @@ impl PlayableScene { rl_thread: &RaylibThread, discord: &DiscordChannel, global_resources: &GlobalResources, + constants: &ProjectConstants, ) { - // Handle updating discord RPC if !self.has_updated_discord_rpc { - discord.send(DiscordRpcSignal::BeginGameTimer).await.unwrap(); - discord.send(DiscordRpcSignal::ChangeDetails { details: "Playing the game".to_string(), party_status: None }).await.unwrap(); + discord + .send(DiscordRpcSignal::BeginGameTimer) + .await + .unwrap(); + discord + .send(DiscordRpcSignal::ChangeDetails { + details: "Playing the game".to_string(), + party_status: None, + }) + .await + .unwrap(); self.has_updated_discord_rpc = true; }