From fdf4b5c82ccb1d30983210a350576b9b3156fbbc Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Thu, 17 Mar 2022 16:48:10 -0400 Subject: [PATCH] Allow blank window rendering --- .vscode/settings.json | 6 +++++- game/game_logic/src/lib.rs | 11 +++++++++- game/game_logic/src/persistent/settings.rs | 5 +++-- game/game_logic/src/rendering/event_loop.rs | 20 +++++++++++++++++++ game/game_logic/src/rendering/mod.rs | 3 +++ .../game_logic/src/rendering/utilities/mod.rs | 0 6 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 game/game_logic/src/rendering/event_loop.rs create mode 100644 game/game_logic/src/rendering/mod.rs create mode 100644 game/game_logic/src/rendering/utilities/mod.rs diff --git a/.vscode/settings.json b/.vscode/settings.json index 93dc280f..6f61c03a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,7 @@ { - "git.detectSubmodules": false + "git.detectSubmodules": false, + "cSpell.words": [ + "msaa", + "vsync" + ] } \ No newline at end of file diff --git a/game/game_logic/src/lib.rs b/game/game_logic/src/lib.rs index b1f9531b..414832f0 100644 --- a/game/game_logic/src/lib.rs +++ b/game/game_logic/src/lib.rs @@ -1,6 +1,9 @@ //! This file is the main entry point for the game logic. +use std::borrow::Borrow; + pub(crate) mod persistent; +pub(crate) mod rendering; /// This is the game logic entrypoint. Despite being async, /// this is expected to block the main thread for rendering and stuff. @@ -15,7 +18,13 @@ pub async fn entrypoint() { let mut save_state = persistent::save_state::GameSaveState::load_or_create() .expect("Failed to parse game save state from disk. Possibly corrupt file?"); - // TODO: Blocking game loop goes here + // Blocking call to the graphics rendering loop. + rendering::event_loop::handle_graphics_blocking( + |builder| { + builder.msaa_4x().vsync(); + }, + settings.target_fps, + ); // Clean up any resources settings diff --git a/game/game_logic/src/persistent/settings.rs b/game/game_logic/src/persistent/settings.rs index 6d2e7268..f74b33d3 100644 --- a/game/game_logic/src/persistent/settings.rs +++ b/game/game_logic/src/persistent/settings.rs @@ -9,13 +9,14 @@ use serde::{Deserialize, Serialize}; /// Please don't add anything relating to gameplay though (no coins, health, etc.). #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PersistentGameSettings { - // TODO: Add settings here. + /// The target framerate for the game + pub target_fps: u32, } // Add any default values here. impl Default for PersistentGameSettings { fn default() -> Self { - Self {} + Self { target_fps: 60 } } } diff --git a/game/game_logic/src/rendering/event_loop.rs b/game/game_logic/src/rendering/event_loop.rs new file mode 100644 index 00000000..cfb693a3 --- /dev/null +++ b/game/game_logic/src/rendering/event_loop.rs @@ -0,0 +1,20 @@ +use raylib::RaylibBuilder; + +pub fn handle_graphics_blocking(config: ConfigBuilder, target_frames_per_second: u32) +where + ConfigBuilder: FnOnce(&mut RaylibBuilder), +{ + // Let the caller configure Raylib's internal window stuff + let (mut raylib_handle, raylib_thread) = { + let mut builder = raylib::init(); + config(&mut builder); + builder.build() + }; + + // Set some important settings on the window + raylib_handle.set_exit_key(None); + raylib_handle.set_target_fps(target_frames_per_second); + + // Run the event loop + while !raylib_handle.window_should_close() {} +} diff --git a/game/game_logic/src/rendering/mod.rs b/game/game_logic/src/rendering/mod.rs new file mode 100644 index 00000000..84cb5be0 --- /dev/null +++ b/game/game_logic/src/rendering/mod.rs @@ -0,0 +1,3 @@ +//! This module contains lower level rendering logic. + +pub mod event_loop; \ No newline at end of file diff --git a/game/game_logic/src/rendering/utilities/mod.rs b/game/game_logic/src/rendering/utilities/mod.rs new file mode 100644 index 00000000..e69de29b