# factor-64/wfx architecture

> Architecture diagram of the GitHub repository factor-64/wfx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/factor-64/wfx
- Repository: https://github.com/factor-64/wfx

## Overview

WFX is a wireframe 3D game/engine for the GBA. Its main loop polls input and dispatches game states into 3D initialization, attract, gameplay, and model-viewer routines; the 3D mode handles player actions, simulation, and drawing. Supporting layers provide level state, entity/model data, enemy behavior, camera math, HUD text, and sound. The supplied mode source is partial, so links to subsystems whose invocation is not visible are omitted; the README documents no further product workflow.

Main entry points: [`source/mode3d.c`](https://github.com/factor-64/wfx/blob/master/source/mode3d.c) (3D Modes), [`source/main.c`](https://github.com/factor-64/wfx/blob/master/source/main.c) (Game Loop), [`source/enemylogic.c`](https://github.com/factor-64/wfx/blob/master/source/enemylogic.c) (Enemy Behavior), [`source/sound.c`](https://github.com/factor-64/wfx/blob/master/source/sound.c) (Sound Effects)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Game Runtime"]
  node_main["Game Loop<br/>[main.c]"]
  node_mode3d["3D Modes<br/>[mode3d.c]"]
  node_global["Game State<br/>[global.c]"]
  node_endless["Endless Mode<br/>[endless.c]"]
end

subgraph group_simulation["World Simulation"]
  node_level["Level State<br/>[level3d.c]"]
  node_entity["Entity Operations<br/>[entity3d.c]"]
  node_enemy["Enemy Behavior<br/>[enemylogic.c]"]
  node_models["Entity Models<br/>[models.h]"]
end

subgraph group_rendering["3D Rendering"]
  node_camera["Camera<br/>[camera.c]"]
  node_renderer["Wireframe Renderer<br/>[mode3d.c]"]
  node_trig["Trig Tables<br/>[trig_lut.c]"]
  node_reciprocal["Reciprocal Table<br/>[recip_lut.c]"]
end

subgraph group_presentation["Audio and UI"]
  node_sound["Sound Effects<br/>[sound.c]"]
  node_message["Messages and Scores<br/>[message3d.c]"]
  node_text["Bitmap Text<br/>[text3d.c]"]
end

node_player(("Player Input"))
node_gba["GBA Display and Audio"]

node_player -->|"provides input"| node_main
node_main -->|"dispatches states"| node_mode3d
node_main -->|"reads state"| node_global
node_main -->|"updates audio"| node_sound
node_main -->|"waits for VBlank"| node_gba
node_mode3d -->|"renders modes"| node_renderer
node_renderer -->|"uses camera"| node_camera
node_renderer -->|"reads angles"| node_trig
node_renderer -->|"reads reciprocals"| node_reciprocal
node_renderer -->|"copies framebuffer"| node_gba
node_mode3d -->|"plays effects"| node_sound
node_mode3d -->|"uses templates"| node_models
node_mode3d -->|"displays messages"| node_message
node_message -->|"draws text"| node_text
node_enemy -->|"applies templates"| node_models
node_enemy -->|"spawns projectiles"| node_entity
node_enemy -->|"plays effects"| node_sound
node_mode3d -->|"uses level state"| node_level
node_mode3d -->|"uses enemy logic"| node_enemy
node_mode3d -.->|"optional mode"| node_endless

click node_main "https://github.com/factor-64/wfx/blob/master/source/main.c"
click node_mode3d "https://github.com/factor-64/wfx/blob/master/source/mode3d.c"
click node_global "https://github.com/factor-64/wfx/blob/master/source/global.c"
click node_endless "https://github.com/factor-64/wfx/blob/master/source/endless.c"
click node_camera "https://github.com/factor-64/wfx/blob/master/source/camera.c"
click node_renderer "https://github.com/factor-64/wfx/blob/master/source/mode3d.c"
click node_trig "https://github.com/factor-64/wfx/blob/master/source/trig_lut.c"
click node_reciprocal "https://github.com/factor-64/wfx/blob/master/source/recip_lut.c"
click node_level "https://github.com/factor-64/wfx/blob/master/source/level3d.c"
click node_entity "https://github.com/factor-64/wfx/blob/master/source/entity3d.c"
click node_enemy "https://github.com/factor-64/wfx/blob/master/source/enemylogic.c"
click node_models "https://github.com/factor-64/wfx/blob/master/models/models.h"
click node_sound "https://github.com/factor-64/wfx/blob/master/source/sound.c"
click node_message "https://github.com/factor-64/wfx/blob/master/source/ui3d/message3d.c"
click node_text "https://github.com/factor-64/wfx/blob/master/source/ui3d/text3d.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_mode3d,node_global,node_endless toneBlue
class node_level,node_entity,node_enemy,node_models toneAmber
class node_camera,node_renderer,node_trig,node_reciprocal toneMint
class node_sound,node_message,node_text toneRose
class node_player,node_gba toneIndigo
```

## Components

### Game Runtime

- [Game Loop](https://github.com/factor-64/wfx/blob/master/source/main.c): `source/main.c`
- [3D Modes](https://github.com/factor-64/wfx/blob/master/source/mode3d.c): `source/mode3d.c`
- [Game State](https://github.com/factor-64/wfx/blob/master/source/global.c): `source/global.c`
- [Endless Mode](https://github.com/factor-64/wfx/blob/master/source/endless.c): `source/endless.c`

### World Simulation

- [Level State](https://github.com/factor-64/wfx/blob/master/source/level3d.c): `source/level3d.c`
- [Entity Operations](https://github.com/factor-64/wfx/blob/master/source/entity3d.c): `source/entity3d.c`
- [Enemy Behavior](https://github.com/factor-64/wfx/blob/master/source/enemylogic.c): `source/enemylogic.c`
- [Entity Models](https://github.com/factor-64/wfx/blob/master/models/models.h): `models/models.h`

### 3D Rendering

- [Camera](https://github.com/factor-64/wfx/blob/master/source/camera.c): `source/camera.c`
- [Wireframe Renderer](https://github.com/factor-64/wfx/blob/master/source/mode3d.c): `source/mode3d.c`
- [Trig Tables](https://github.com/factor-64/wfx/blob/master/source/trig_lut.c): `source/trig_lut.c`
- [Reciprocal Table](https://github.com/factor-64/wfx/blob/master/source/recip_lut.c): `source/recip_lut.c`

### Audio and UI

- [Sound Effects](https://github.com/factor-64/wfx/blob/master/source/sound.c): `source/sound.c`
- [Messages and Scores](https://github.com/factor-64/wfx/blob/master/source/ui3d/message3d.c): `source/ui3d/message3d.c`
- [Bitmap Text](https://github.com/factor-64/wfx/blob/master/source/ui3d/text3d.c): `source/ui3d/text3d.c`

### Other components

- **Player Input**
- **GBA Display and Audio**

## Connections

- Player Input → Game Loop: provides input
- Game Loop → 3D Modes: dispatches states
- Game Loop → Game State: reads state
- Game Loop → Sound Effects: updates audio
- Game Loop → GBA Display and Audio: waits for VBlank
- 3D Modes → Wireframe Renderer: renders modes
- Wireframe Renderer → Camera: uses camera
- Wireframe Renderer → Trig Tables: reads angles
- Wireframe Renderer → Reciprocal Table: reads reciprocals
- Wireframe Renderer → GBA Display and Audio: copies framebuffer
- 3D Modes → Sound Effects: plays effects
- 3D Modes → Entity Models: uses templates
- 3D Modes → Messages and Scores: displays messages
- Messages and Scores → Bitmap Text: draws text
- Enemy Behavior → Entity Models: applies templates
- Enemy Behavior → Entity Operations: spawns projectiles
- Enemy Behavior → Sound Effects: plays effects
- 3D Modes → Level State: uses level state
- 3D Modes → Enemy Behavior: uses enemy logic
- 3D Modes → Endless Mode: optional mode
