App State Management

Overview

Mirador follows a hierarchical architecture where the App struct serves as the top-level container for the entire program, while AppState contains the operational components including rendering pipelines, game logic, and user interface systems.

Core Structures

App - Top Level Application Container

The App struct is the top-level struct of the entire program and serves as the main application object for Mirador. It manages the fundamental WGPU instance, window system integration, and implements the event-driven architecture through winit::application::ApplicationHandler.

#[derive(Default)]
pub struct App {
    instance: wgpu::Instance,
    state: Option<AppState>,
    window: Option<Arc<Window>>,
}

Key Responsibilities:

AppState - Application Core

The AppState struct contains the meat of the application including the various rendering pipelines, the game state, and all UI elements. This is where all the active components of a running game session reside.

pub struct AppState {
    wgpu_renderer: WgpuRenderer,
    egui_renderer: EguiRenderer,
    ui: UiState,
    game_state: GameState,
    key_state: KeyState,
}

Key Components:

Rendering Pipelines:

Application State:

Architecture Flow

The application follows this initialization and operation flow:

  1. App Creation: The top-level App struct is instantiated with default values
  2. WGPU Initialization: The WGPU instance is created for graphics device management
  3. Window Setup: The application window is created and configured
  4. AppState Initialization: All rendering pipelines, game systems, and UI components are initialized
  5. Event Loop: The winit event loop processes input, updates game state, and triggers rendering

This separation allows for clean resource management where the App handles system-level concerns while AppState focuses on application-specific functionality.