From 07bd127596d52e5cf9bfcde5400f8e30bf14d80a Mon Sep 17 00:00:00 2001 From: Ryan Walters Date: Fri, 5 Sep 2025 15:21:20 -0500 Subject: [PATCH] chore: move ttf context out of game.rs, remove unnecessary window event logging --- src/app.rs | 12 ++---------- src/game.rs | 5 ++--- src/systems/input.rs | 10 ++-------- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/app.rs b/src/app.rs index 5f3ffd4..a8ffb31 100644 --- a/src/app.rs +++ b/src/app.rs @@ -13,10 +13,6 @@ use sdl2::{AudioSubsystem, Sdl}; use tracing::debug; /// Main application wrapper that manages SDL initialization, window lifecycle, and the game loop. -/// -/// Handles platform-specific setup, maintains consistent frame timing, and delegates -/// game logic to the contained `Game` instance. The app manages focus state to -/// optimize CPU usage when the window loses focus. pub struct App { pub game: Game, last_tick: Instant, @@ -29,16 +25,13 @@ pub struct App { impl App { /// Initializes SDL subsystems, creates the game window, and sets up the game state. /// - /// Performs comprehensive initialization including video/audio subsystems, - /// window creation with proper scaling, and canvas configuration. All SDL - /// resources are leaked to maintain 'static lifetimes required by the game architecture. - /// /// # Errors /// /// Returns `GameError::Sdl` if any SDL initialization step fails, or propagates /// errors from `Game::new()` during game state setup. pub fn new() -> GameResult { let sdl_context = sdl2::init().map_err(|e| GameError::Sdl(e.to_string()))?; + let ttf_context = sdl2::ttf::init().map_err(|e| GameError::Sdl(e.to_string()))?; let video_subsystem = sdl_context.video().map_err(|e| GameError::Sdl(e.to_string()))?; let audio_subsystem = sdl_context.audio().map_err(|e| GameError::Sdl(e.to_string()))?; let event_pump = sdl_context.event_pump().map_err(|e| GameError::Sdl(e.to_string()))?; @@ -102,8 +95,7 @@ impl App { let texture_creator = canvas.texture_creator(); - let game = Game::new(canvas, texture_creator, event_pump)?; - // game.audio.set_mute(cfg!(debug_assertions)); + let game = Game::new(canvas, ttf_context, texture_creator, event_pump)?; Ok(App { game, diff --git a/src/game.rs b/src/game.rs index 50c3713..9fbd605 100644 --- a/src/game.rs +++ b/src/game.rs @@ -88,13 +88,12 @@ impl Game { /// errors, or entity initialization issues. pub fn new( mut canvas: Canvas, + ttf_context: sdl2::ttf::Sdl2TtfContext, texture_creator: TextureCreator, mut event_pump: EventPump, ) -> GameResult { Self::disable_sdl_events(&mut event_pump); - let ttf_context = Box::leak(Box::new(sdl2::ttf::init().map_err(|e| GameError::Sdl(e.to_string()))?)); - let (backbuffer, mut map_texture, debug_texture, ttf_atlas) = Self::setup_textures_and_fonts(&mut canvas, &texture_creator, ttf_context)?; @@ -188,7 +187,7 @@ impl Game { fn setup_textures_and_fonts( canvas: &mut Canvas, texture_creator: &TextureCreator, - ttf_context: &'static sdl2::ttf::Sdl2TtfContext, + ttf_context: sdl2::ttf::Sdl2TtfContext, ) -> GameResult<( sdl2::render::Texture, sdl2::render::Texture, diff --git a/src/systems/input.rs b/src/systems/input.rs index a308dff..56bf96b 100644 --- a/src/systems/input.rs +++ b/src/systems/input.rs @@ -12,7 +12,6 @@ use sdl2::{ EventPump, }; use smallvec::{smallvec, SmallVec}; -use tracing::{debug, info}; use crate::systems::components::DeltaTime; use crate::{ @@ -300,15 +299,10 @@ pub fn input_system( } Event::Window { win_event, .. } => match win_event { WindowEvent::Resized(w, h) => { - info!("Window resized to {}x{}", w, h); - } - _ => { - debug!("Window event: {:?}", win_event); + tracing::info!("Window resized to {}x{}", w, h); } + _ => {} }, - Event::RenderTargetsReset { .. } => { - // No-op - } _ => { tracing::warn!("Unhandled event, consider disabling: {:?}", event); }