Basic rendering code in progress
This commit is contained in:
parent
f070a34d73
commit
3bf0c5c48e
@ -32,4 +32,7 @@ async fn main() {
|
|||||||
log::info!("Starting game");
|
log::info!("Starting game");
|
||||||
game_logic::entrypoint(args.force_recreate_savefiles).await;
|
game_logic::entrypoint(args.force_recreate_savefiles).await;
|
||||||
log::info!("Goodbye!");
|
log::info!("Goodbye!");
|
||||||
|
|
||||||
|
// Exit the program
|
||||||
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ pub async fn entrypoint(force_recreate_savefiles: bool) {
|
|||||||
.await
|
.await
|
||||||
.expect("Failed to connect to Discord RPC");
|
.expect("Failed to connect to Discord RPC");
|
||||||
let event_loop_discord_tx = discord.get_channel();
|
let event_loop_discord_tx = discord.get_channel();
|
||||||
let _discord_task_handle = discord.begin_thread_non_blocking();
|
let discord_task_handle = discord.begin_thread_non_blocking();
|
||||||
|
|
||||||
// Set a base activity to show in Discord
|
// Set a base activity to show in Discord
|
||||||
{
|
{
|
||||||
@ -77,4 +77,5 @@ pub async fn entrypoint(force_recreate_savefiles: bool) {
|
|||||||
save_state
|
save_state
|
||||||
.save()
|
.save()
|
||||||
.expect("Could not save game save state to disk.");
|
.expect("Could not save game save state to disk.");
|
||||||
|
discord_task_handle.abort();
|
||||||
}
|
}
|
||||||
|
16
game/game_logic/src/rendering/core_renderer_sm.rs
Normal file
16
game/game_logic/src/rendering/core_renderer_sm.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//! This module contains state machine definitions for the backend rendering system.
|
||||||
|
|
||||||
|
sad_machine::state_machine! {
|
||||||
|
RenderBackendStates {
|
||||||
|
InitialStates {
|
||||||
|
Preload
|
||||||
|
}
|
||||||
|
FinishPreload {
|
||||||
|
Preload => Loading
|
||||||
|
}
|
||||||
|
FinishLoading {
|
||||||
|
// TODO: Make this hand off to the main render code
|
||||||
|
Loading => SmFailed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,28 @@
|
|||||||
use raylib::RaylibBuilder;
|
//! The Event Loop module
|
||||||
|
//!
|
||||||
|
//! ## Overview
|
||||||
|
//!
|
||||||
|
//! This is the code that handles beginning each frame and ending it. Do not try to add your own game logic in here.
|
||||||
|
//! The event loop function has its own statemachine (`core_renderer_sm.rs`) that handles the current action.
|
||||||
|
//!
|
||||||
|
//! You can think of this as a bit of bootstrap code for the game. All that happens directly here is rendering of the loading screen and a bit of error handling.
|
||||||
|
|
||||||
use crate::discord::DiscordChannel;
|
use crate::discord::DiscordChannel;
|
||||||
|
use crate::rendering::core_renderer_sm::{PreloadState, RenderBackendStates};
|
||||||
|
use crate::rendering::screens::sm_failure_screen;
|
||||||
|
use raylib::RaylibBuilder;
|
||||||
|
|
||||||
/// Will begin rendering graphics. Returns when the window closes
|
/// Will begin rendering graphics. Returns when the window closes
|
||||||
pub fn handle_graphics_blocking<ConfigBuilder>(config: ConfigBuilder, target_frames_per_second: u32, discord_signaling: DiscordChannel)
|
pub fn handle_graphics_blocking<ConfigBuilder>(
|
||||||
where
|
config: ConfigBuilder,
|
||||||
|
target_frames_per_second: u32,
|
||||||
|
discord_signaling: DiscordChannel,
|
||||||
|
) where
|
||||||
ConfigBuilder: FnOnce(&mut RaylibBuilder),
|
ConfigBuilder: FnOnce(&mut RaylibBuilder),
|
||||||
{
|
{
|
||||||
|
// Set up the backend rendering state machine
|
||||||
|
let mut backend_sm = RenderBackendStates::preload();
|
||||||
|
|
||||||
// Let the caller configure Raylib's internal window stuff
|
// Let the caller configure Raylib's internal window stuff
|
||||||
let (mut raylib_handle, raylib_thread) = {
|
let (mut raylib_handle, raylib_thread) = {
|
||||||
log::trace!("Configuring Raylib");
|
log::trace!("Configuring Raylib");
|
||||||
@ -19,9 +35,27 @@ where
|
|||||||
raylib_handle.set_exit_key(None);
|
raylib_handle.set_exit_key(None);
|
||||||
raylib_handle.set_target_fps(target_frames_per_second);
|
raylib_handle.set_target_fps(target_frames_per_second);
|
||||||
|
|
||||||
|
// Set up the internal screens
|
||||||
|
let mut loading_screen = crate::rendering::screens::loading_screen::LoadingScreen::new();
|
||||||
|
let mut sm_failure_screen = sm_failure_screen::SmFailureScreen::new();
|
||||||
|
|
||||||
// Run the event loop
|
// Run the event loop
|
||||||
log::trace!("Running event loop");
|
log::trace!("Running event loop");
|
||||||
while !raylib_handle.window_should_close() {
|
while !raylib_handle.window_should_close() {
|
||||||
|
// Handle state machine updates
|
||||||
|
match backend_sm {
|
||||||
|
RenderBackendStates::Preload(m @ PreloadState::FromInit) => {
|
||||||
|
backend_sm = m.finish_preload();
|
||||||
|
}
|
||||||
|
RenderBackendStates::Loading(ref m) => {
|
||||||
|
if loading_screen.render(&mut raylib_handle, &raylib_thread, &discord_signaling) {
|
||||||
|
backend_sm = m.finish_loading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RenderBackendStates::SmFailed(ref m) => {
|
||||||
|
sm_failure_screen.render(&mut raylib_handle, &raylib_thread, &discord_signaling);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Tell the profiler that we ended the frame
|
// Tell the profiler that we ended the frame
|
||||||
profiling::finish_frame!();
|
profiling::finish_frame!();
|
||||||
|
@ -2,3 +2,5 @@
|
|||||||
|
|
||||||
pub mod event_loop;
|
pub mod event_loop;
|
||||||
pub mod utilities;
|
pub mod utilities;
|
||||||
|
pub mod screens;
|
||||||
|
mod core_renderer_sm;
|
26
game/game_logic/src/rendering/screens/loading_screen.rs
Normal file
26
game/game_logic/src/rendering/screens/loading_screen.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
use raylib::prelude::*;
|
||||||
|
|
||||||
|
use crate::discord::DiscordChannel;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct LoadingScreen {}
|
||||||
|
|
||||||
|
impl LoadingScreen {
|
||||||
|
/// Construct a new `LoadingScreen`
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn render(
|
||||||
|
&mut self,
|
||||||
|
raylib: &mut RaylibHandle,
|
||||||
|
rl_thread: &RaylibThread,
|
||||||
|
discord: &DiscordChannel,
|
||||||
|
) -> bool {
|
||||||
|
let mut d = raylib.begin_drawing(&rl_thread);
|
||||||
|
|
||||||
|
d.clear_background(raylib::color::Color::WHITE);
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
2
game/game_logic/src/rendering/screens/mod.rs
Normal file
2
game/game_logic/src/rendering/screens/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod loading_screen;
|
||||||
|
pub mod sm_failure_screen;
|
27
game/game_logic/src/rendering/screens/sm_failure_screen.rs
Normal file
27
game/game_logic/src/rendering/screens/sm_failure_screen.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use raylib::prelude::*;
|
||||||
|
|
||||||
|
use crate::discord::DiscordChannel;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SmFailureScreen {}
|
||||||
|
|
||||||
|
impl SmFailureScreen {
|
||||||
|
/// Construct a new `SmFailureScreen`
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn render(
|
||||||
|
&mut self,
|
||||||
|
raylib: &mut RaylibHandle,
|
||||||
|
rl_thread: &RaylibThread,
|
||||||
|
discord: &DiscordChannel,
|
||||||
|
) -> bool {
|
||||||
|
let mut d = raylib.begin_drawing(&rl_thread);
|
||||||
|
|
||||||
|
d.clear_background(raylib::color::Color::RED);
|
||||||
|
d.draw_text("Backend Rendering Broke.\nYou should not be seeing this!", 10, 10, 40, raylib::color::Color::WHITE);
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user