# fragglet/sdl-sopwith architecture

> Architecture diagram of the GitHub repository fragglet/sdl-sopwith, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fragglet/sdl-sopwith
- Repository: https://github.com/fragglet/sdl-sopwith

## Overview

##### Main Components

a) Core Game Engine Components:
- Game Logic (swmain.c, swgames.c, swmove.c)
- Collision Detection (swcollsn.c)
- Object Management (swobject.c)
- Configuration System (swconf.c)

b) Input/Output Layer:
- SDL Interface (src/sdl/* files)
- Video System (video.c, swgrpha.c)
- Sound System (swsound.c, pcsound.c)
- Controller Input (controller.c)

c) Networking Component:
- TCP/IP Multiplayer (tcpcomm.c)

d) User Interface:
- Menu System (swmenu.c)
- Status Bar (swstbar.c)
- Text Rendering (swtext.c)

**┌─────────────────────────────────────┐**
- User Interface           │
- ┤
- Game Logic              │
- ┤
- SDL Abstraction Layer       │
- ┤
- Platform-Specific Code         │
- ┘

##### Component Relationships

- Main game loop (swmain.c) → Game state management
- Input handling → Game logic
- Game logic → Rendering pipeline
- Network component ↔ Game state synchronization
- Configuration system → All components

##### Technical Details

- SDL dependency
- TCP/IP networking capabilities
- PC speaker emulation system
- Multiple palette support
- Medal system integration

##### Implementation Notes

- The modular nature of the codebase
- Clear separation between game logic and platform-specific code
- The role of SDL as the primary abstraction layer
- Network play architecture
- Resource management (sounds, graphics, configurations)

Remember to maintain a balance between showing the overall architecture while including enough detail to understand the game's unique features like custom level support and multiplayer functionality.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef core fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef io fill:#90EE90,stroke:#333,stroke-width:2px
    classDef network fill:#ffff99,stroke:#333,stroke-width:2px
    classDef ui fill:#ffb366,stroke:#333,stroke-width:2px
    classDef platform fill:#e6e6e6,stroke:#333,stroke-width:2px
    classDef resource fill:#d9b3ff,stroke:#333,stroke-width:2px

    subgraph User_Interface
        Menu[Menu System]:::ui
        Status[Status Bar]:::ui
        Text[Text Rendering]:::ui
        Title[Title Screen]:::ui
        EndGame[End Game]:::ui
    end

    subgraph Core_Engine
        Main[Main Game Logic]:::core
        GameState[Game State Management]:::core
        Movement[Movement System]:::core
        Collision[Collision Detection]:::core
        ObjectMgmt[Object Management]:::core
        Config[Configuration System]:::core
    end

    subgraph SDL_Layer
        SDLInterface[SDL Interface]:::io
        Video[Video System]:::io
        Sound[Sound System]:::io
        Controller[Controller Input]:::io
        Timer[Timer System]:::io
    end

    subgraph Network
        TCP[TCP/IP Multiplayer]:::network
    end

    subgraph Platform_Specific
        Windows[Windows Support]:::platform
        MacOS[MacOS Support]:::platform
        Web[Emscripten Web Support]:::platform
    end

    subgraph Resource_Management
        Font[Font System]:::resource
        Graphics[Graphics System]:::resource
        Symbol[Symbol Management]:::resource
    end

    %% Relationships
    Main --> GameState
    Main --> Movement
    Movement --> Collision
    GameState --> ObjectMgmt
    Config --> Core_Engine
    Config --> SDL_Layer

    Controller --> Main
    Main --> Video
    Main --> Sound
    Timer --> Main

    TCP <--> GameState

    Main --> Menu
    Menu --> Status
    Menu --> Text
    Menu --> Title
    GameState --> EndGame

    %% Click Events
    click Main "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/swmain.c"
    click GameState "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/swgames.c"
    click Movement "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/swmove.c"
    click Collision "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/swcollsn.c"
    click ObjectMgmt "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/swobject.c"
    click Config "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/swconf.c"
    click SDLInterface "https://github.com/fragglet/sdl-sopwith/tree/trunk/src/sdl/"
    click Video "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/sdl/video.c"
    click Sound "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/sdl/pcsound.c"
    click Controller "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/sdl/controller.c"
    click Timer "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/sdl/timer.c"
    click TCP "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/tcpcomm.c"
    click Menu "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/swmenu.c"
    click Status "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/swstbar.c"
    click Text "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/swtext.c"
    click Title "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/swtitle.c"
    click EndGame "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/swend.c"
    click Windows "https://github.com/fragglet/sdl-sopwith/tree/trunk/pkg/win32/"
    click MacOS "https://github.com/fragglet/sdl-sopwith/tree/trunk/pkg/macos/"
    click Web "https://github.com/fragglet/sdl-sopwith/tree/trunk/pkg/emscripten/"
    click Font "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/font.h"
    click Graphics "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/swgrpha.c"
    click Symbol "https://github.com/fragglet/sdl-sopwith/blob/trunk/src/swsymbol.c"
```
