Game State Management

Overview

The game module serves as the core gameplay system within Mirador, implementing a first-person maze navigation experience. The architecture follows a clean separation of concerns with three primary components: input handling, player management, and centralized game state coordination. This module provides collision detection, movement mechanics, and game progression tracking through a maze-based gameplay loop.

Core Structures

GameState - Central Game Coordinator

The GameState struct serves as the central hub for all mutable game data and coordinates between different game systems. It maintains the game loop timing, player state, UI management, and level progression.

#[derive(Debug, Clone)]
pub struct GameState {
    pub player: Player,
    pub last_frame_time: Instant,
    pub delta_time: f32,
    pub frame_count: u32,
    pub current_fps: u32,
    pub last_fps_time: Instant,
    pub title_screen: bool,
    pub maze_path: Option<PathBuf>,
    pub capture_mouse: bool,
    pub collision_system: CollisionSystem,
    pub level: u32,
    pub exit_reached: bool,
    pub exit_cell: Cell,
}

Field Explanations:

Player - Character State and Movement

The Player struct encapsulates all aspects of the player character including spatial positioning, camera orientation, and movement mechanics for the first-person perspective. For more information see Player

#[derive(Debug, Default, Clone)]
pub struct Player {
    pub position: [f32; 3],
    pub pitch: f32,
    pub yaw: f32,
    pub fov: f32,
    pub base_speed: f32,
    pub speed: f32,
    pub mouse_sensitivity: f32,
    pub current_cell: Cell,
}

Field Explanations:

Input Abstraction System

GameKey - Action Abstraction

The GameKey enum provides a hardware-agnostic input abstraction layer that decouples game actions from specific physical input devices.

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum GameKey {
    MouseButtonLeft,
    MouseButtonRight,
    MoveForward,
    MoveBackward,
    MoveLeft,
    MoveRight,
    Sprint,
    Jump,
    ToggleSliders,
    Quit,
    Escape,
    ToggleBoundingBoxes,
}

KeyState - Input State Management

The KeyState struct tracks which game actions are currently active and applies them to the game state each frame.

#[derive(Debug, Default)]
pub struct KeyState {
    pub pressed_keys: HashSet<GameKey>,
}

Field Explanations:

Key Responsibilities

Input Processing and Mapping

Player Movement and Camera Control

Game State Coordination

Collision Detection

For more information on collision detection with bounding volume hierarchies, please refer to the Collision Detection with Bounding Volume Hierarchies page.