# ankushkun/sh23ds architecture

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

- Interactive diagram: https://gitdiagram.com/ankushkun/sh23ds
- Repository: https://github.com/ankushkun/sh23ds

## Overview

sh23ds is a native Silent Hill 2 port for Nintendo 3DS, using the player’s converted PC Director’s Cut data. The user workflow is: convert the game with the browser packer, install its output on the SD card, then launch and play through the port. The runtime spans progression and events, player/enemy simulation, camera and world rendering, audio, cutscenes, menus, and saves. The README documents these capabilities, but only a small part of the runtime source was sampled; dashed links mark runtime relationships not established by the excerpts.

Main entry points: [`port/source/main.c`](https://github.com/ankushkun/sh23ds/blob/main/port/source/main.c) (Game loop), [`site/packer/worker.js`](https://github.com/ankushkun/sh23ds/blob/main/site/packer/worker.js) (Browser worker), [`site/packer/core.js`](https://github.com/ankushkun/sh23ds/blob/main/site/packer/core.js) (Pack conversion), [`site/packer/texenc.mjs`](https://github.com/ankushkun/sh23ds/blob/main/site/packer/texenc.mjs) (Texture encoder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_conversion["Game conversion"]
  node_packer_worker["Browser worker<br/>[worker.js]"]
  node_packer_core["Pack conversion<br/>[core.js]"]
  node_texenc["Texture encoder<br/>[texenc.mjs]"]
end

subgraph group_runtime["Game runtime"]
  node_game["Game loop<br/>[main.c]"]
  node_progression["Stage progression<br/>[prog.c]"]
  node_events["Events<br/>[events.c]"]
  node_player_move["Player movement<br/>[move.c]"]
  node_combat["Combat<br/>[combat.c]"]
  node_enemies["Enemy simulation<br/>[enemy.c]"]
  node_profile["Console profile<br/>[profile.c]"]
  node_missing_data["Data check<br/>[nodata.c]"]
end

subgraph group_world["World and presentation"]
  node_characters["Characters<br/>[chr.c]"]
  node_camera["PC camera<br/>[sh2cam.c]"]
  node_lighting_fog["Lighting and fog<br/>[fog.c]"]
  node_stage_world["Stage and rooms<br/>[room.c]"]
end

subgraph group_media["Audio and cinematics"]
  node_audio["Audio playback<br/>[audio.c]"]
  node_music["Background music<br/>[bgm.c]"]
  node_cutscenes["Cutscenes<br/>[demo.c]"]
  node_movies["Movie playback<br/>[movie.c]"]
end

subgraph group_interface["Menus and persistence"]
  node_menus["Menus and controls<br/>[optmenu.c]"]
  node_map["Map display<br/>[map.c]"]
  node_save["Save handling<br/>[clearsave.c]"]
end

node_player(("Player"))

node_player -->|"selects game"| node_packer_worker
node_packer_worker -->|"runs conversion"| node_packer_core
node_packer_worker -->|"loads encoder"| node_texenc
node_player -->|"launches"| node_game
node_game -->|"initializes"| node_profile
node_game -->|"checks data"| node_missing_data
node_game -->|"initializes"| node_audio
node_game -.->|"drives"| node_progression
node_game -.->|"runs"| node_events
node_game -.->|"updates"| node_player_move
node_game -.->|"updates"| node_combat
node_game -.->|"updates"| node_enemies
node_game -.->|"renders"| node_characters
node_game -.->|"uses"| node_camera
node_game -.->|"renders"| node_lighting_fog
node_game -.->|"loads"| node_stage_world
node_game -.->|"plays"| node_music
node_game -.->|"runs"| node_cutscenes
node_game -.->|"plays"| node_movies
node_game -.->|"presents"| node_menus
node_game -.->|"displays"| node_map
node_game -.->|"persists"| node_save

click node_packer_worker "https://github.com/ankushkun/sh23ds/blob/main/site/packer/worker.js"
click node_packer_core "https://github.com/ankushkun/sh23ds/blob/main/site/packer/core.js"
click node_texenc "https://github.com/ankushkun/sh23ds/blob/main/site/packer/texenc.mjs"
click node_game "https://github.com/ankushkun/sh23ds/blob/main/port/source/main.c"
click node_progression "https://github.com/ankushkun/sh23ds/blob/main/port/source/prog.c"
click node_events "https://github.com/ankushkun/sh23ds/blob/main/port/source/events.c"
click node_player_move "https://github.com/ankushkun/sh23ds/blob/main/port/source/move.c"
click node_combat "https://github.com/ankushkun/sh23ds/blob/main/port/source/combat.c"
click node_enemies "https://github.com/ankushkun/sh23ds/blob/main/port/source/enemy.c"
click node_characters "https://github.com/ankushkun/sh23ds/blob/main/port/source/chr.c"
click node_camera "https://github.com/ankushkun/sh23ds/blob/main/port/source/game/view/sh2cam.c"
click node_lighting_fog "https://github.com/ankushkun/sh23ds/blob/main/port/source/fog.c"
click node_stage_world "https://github.com/ankushkun/sh23ds/blob/main/port/source/room.c"
click node_audio "https://github.com/ankushkun/sh23ds/blob/main/port/source/audio.c"
click node_music "https://github.com/ankushkun/sh23ds/blob/main/port/source/bgm.c"
click node_cutscenes "https://github.com/ankushkun/sh23ds/blob/main/port/source/demo.c"
click node_movies "https://github.com/ankushkun/sh23ds/blob/main/port/source/movie.c"
click node_menus "https://github.com/ankushkun/sh23ds/blob/main/port/source/optmenu.c"
click node_map "https://github.com/ankushkun/sh23ds/blob/main/port/source/map.c"
click node_save "https://github.com/ankushkun/sh23ds/blob/main/port/source/clearsave.c"
click node_profile "https://github.com/ankushkun/sh23ds/blob/main/port/source/profile.c"
click node_missing_data "https://github.com/ankushkun/sh23ds/blob/main/port/source/nodata.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_packer_worker,node_packer_core,node_texenc toneBlue
class node_game,node_progression,node_events,node_player_move,node_combat,node_enemies,node_profile,node_missing_data toneAmber
class node_characters,node_camera,node_lighting_fog,node_stage_world toneMint
class node_audio,node_music,node_cutscenes,node_movies toneRose
class node_menus,node_map,node_save,node_player toneIndigo
```

## Components

### Game conversion

- [Browser worker](https://github.com/ankushkun/sh23ds/blob/main/site/packer/worker.js): `site/packer/worker.js`
- [Pack conversion](https://github.com/ankushkun/sh23ds/blob/main/site/packer/core.js): `site/packer/core.js`
- [Texture encoder](https://github.com/ankushkun/sh23ds/blob/main/site/packer/texenc.mjs): `site/packer/texenc.mjs`

### Game runtime

- [Game loop](https://github.com/ankushkun/sh23ds/blob/main/port/source/main.c): `port/source/main.c`
- [Stage progression](https://github.com/ankushkun/sh23ds/blob/main/port/source/prog.c): `port/source/prog.c`
- [Events](https://github.com/ankushkun/sh23ds/blob/main/port/source/events.c): `port/source/events.c`
- [Player movement](https://github.com/ankushkun/sh23ds/blob/main/port/source/move.c): `port/source/move.c`
- [Combat](https://github.com/ankushkun/sh23ds/blob/main/port/source/combat.c): `port/source/combat.c`
- [Enemy simulation](https://github.com/ankushkun/sh23ds/blob/main/port/source/enemy.c): `port/source/enemy.c`
- [Console profile](https://github.com/ankushkun/sh23ds/blob/main/port/source/profile.c): `port/source/profile.c`
- [Data check](https://github.com/ankushkun/sh23ds/blob/main/port/source/nodata.c): `port/source/nodata.c`

### World and presentation

- [Characters](https://github.com/ankushkun/sh23ds/blob/main/port/source/chr.c): `port/source/chr.c`
- [PC camera](https://github.com/ankushkun/sh23ds/blob/main/port/source/game/view/sh2cam.c): `port/source/game/view/sh2cam.c`
- [Lighting and fog](https://github.com/ankushkun/sh23ds/blob/main/port/source/fog.c): `port/source/fog.c`
- [Stage and rooms](https://github.com/ankushkun/sh23ds/blob/main/port/source/room.c): `port/source/room.c`

### Audio and cinematics

- [Audio playback](https://github.com/ankushkun/sh23ds/blob/main/port/source/audio.c): `port/source/audio.c`
- [Background music](https://github.com/ankushkun/sh23ds/blob/main/port/source/bgm.c): `port/source/bgm.c`
- [Cutscenes](https://github.com/ankushkun/sh23ds/blob/main/port/source/demo.c): `port/source/demo.c`
- [Movie playback](https://github.com/ankushkun/sh23ds/blob/main/port/source/movie.c): `port/source/movie.c`

### Menus and persistence

- [Menus and controls](https://github.com/ankushkun/sh23ds/blob/main/port/source/optmenu.c): `port/source/optmenu.c`
- [Map display](https://github.com/ankushkun/sh23ds/blob/main/port/source/map.c): `port/source/map.c`
- [Save handling](https://github.com/ankushkun/sh23ds/blob/main/port/source/clearsave.c): `port/source/clearsave.c`

### Other components

- **Player**

## Connections

- Player → Browser worker: selects game (evidence: `README.md`)
- Browser worker → Pack conversion: runs conversion (evidence: `site/packer/worker.js`)
- Browser worker → Texture encoder: loads encoder (evidence: `site/packer/worker.js`)
- Player → Game loop: launches (evidence: `README.md`)
- Game loop → Console profile: initializes (evidence: `port/source/main.c`)
- Game loop → Data check: checks data (evidence: `port/source/main.c`)
- Game loop → Audio playback: initializes (evidence: `port/source/main.c`)
- Game loop → Stage progression: drives
- Game loop → Events: runs
- Game loop → Player movement: updates
- Game loop → Combat: updates
- Game loop → Enemy simulation: updates
- Game loop → Characters: renders
- Game loop → PC camera: uses
- Game loop → Lighting and fog: renders
- Game loop → Stage and rooms: loads
- Game loop → Background music: plays
- Game loop → Cutscenes: runs
- Game loop → Movie playback: plays
- Game loop → Menus and controls: presents
- Game loop → Map display: displays
- Game loop → Save handling: persists
