mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-06 01:15:42 -06:00
chore: move ttf context out of game.rs, remove unnecessary window event logging
This commit is contained in:
12
src/app.rs
12
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<Self> {
|
||||
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,
|
||||
|
||||
@@ -88,13 +88,12 @@ impl Game {
|
||||
/// errors, or entity initialization issues.
|
||||
pub fn new(
|
||||
mut canvas: Canvas<Window>,
|
||||
ttf_context: sdl2::ttf::Sdl2TtfContext,
|
||||
texture_creator: TextureCreator<WindowContext>,
|
||||
mut event_pump: EventPump,
|
||||
) -> GameResult<Game> {
|
||||
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<Window>,
|
||||
texture_creator: &TextureCreator<WindowContext>,
|
||||
ttf_context: &'static sdl2::ttf::Sdl2TtfContext,
|
||||
ttf_context: sdl2::ttf::Sdl2TtfContext,
|
||||
) -> GameResult<(
|
||||
sdl2::render::Texture,
|
||||
sdl2::render::Texture,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user