# cff29546/pzmap2dzi architecture

> Architecture diagram of the GitHub repository cff29546/pzmap2dzi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cff29546/pzmap2dzi
- Repository: https://github.com/cff29546/pzmap2dzi

## Overview

##### Major Components
- Command-Line Interface & Entry Points: The main entry points are in files like main.py and the various run*.bat scripts. These load configuration files from the conf directory (especially conf/conf.yaml) and kick off the rendering process.
- Configuration Management: The “conf” directory holds configuration files (mod maps, default settings, versioning) that determine input paths (e.g., for the game data) and output paths.
- Core Rendering Engine: The bulk of the logic resides in the pzmap2dzi package, where modules such as render.py, render_impl (with submodules for base, objects, zombie, etc.), geometry, scheduling, and shared_memory_image define the different aspects of the rendering process. This is where multi-threading and shared memory acceleration are implemented.
- Auxiliary Scripts and Tools: Under scripts/ you see ancillary Python scripts (such as generating example configs, collecting mod map data, tile checks, etc.) that support or extend the core functionality.
- Testing Framework: The test directory contains well-defined test cases and batch scripts to validate the functionality.
- HTML Viewer & Server: The html directory holds the viewer files (pzmap.html, pzmap.js, openseadragon integration) and related batch/server files (server.py, run_server.bat). These work together to display the Deep Zoom output and offer interactive features such as mod map overlays, grid toggling, and layer switching.

##### Relationships & Data Flow
- Input Flow: The system starts with configuration settings (conf/conf.yaml) and command-line arguments or bat files that define what outputs to generate (different views, overlays, etc.). These settings then trigger the main.py which invokes pzmap2dzi’s modules.
- Core Processing: Within pzmap2dzi, modules communicate to perform tasks – for example, the cell, geometry, and scheduling modules work together to partition the map and schedule rendering tasks across threads. Render modules (render.py and the render_impl package) process the graphical data including details like basements, overlays (zombie heatmap, foraging zones, etc.), and i18n.
- Output Flow: Once rendered, map data is written to the output directory (also configured in conf), which includes the HTML folder that supports interactive map viewing via a local server. The HTML viewer fetches these Deep Zoom tiles through directional paths and server communication (handled by server.py and associated bat files).
- Additional Tools: The mod support (adding mod maps, internationalization) and trimming functionality are extra sub-components interacting with core processing and viewer components.

##### Architectural Patterns & Principles
- Separation of Concerns: The design keeps configuration, rendering logic, and client viewing separate. The pzmap2dzi library focuses solely on processing while the html component handles the front end.
- Modular Design: The densely organized file tree (with dedicated directories for core logic, configuration, scripts, tests, and HTML) emphasizes a modular design. Each module (for tasks like geometry, scheduling, shared memory, specific modul mapping implementations) encapsulates its functionality.
- Scalability with Multi-threading: The rendering processes are designed to scale with additional threads and shared memory, critical for handling enormous output sizes.
- Extensibility: With separate directories for docs, mod maps, and i18n support, the project naturally supports extensions and customizations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration & Control Layer
    subgraph "Configuration & Control Layer"
        main_py["main.py"]:::cli
        run_bat["run.bat"]:::cli
        run_iso["run_isometric_only.bat"]:::cli
        run_top["run_top_view_only.bat"]:::cli
        config_file["Config File (conf/conf.yaml)"]:::config
    end

    %% Processing Layer
    subgraph "Processing Layer"
        render_engine["Render Engine (pzmap2dzi/render.py)"]:::processing
        render_impl["Render Impl (pzmap2dzi/render_impl/)"]:::processing
        geometry["Geometry (pzmap2dzi/geometry.py)"]:::processing
        scheduler["Scheduler (pzmap2dzi/scheduling.py)"]:::processing
        shared_memory["Shared Memory (pzmap2dzi/shared_memory_image.py)"]:::processing
    end

    %% Viewer Layer
    subgraph "Viewer Layer"
        html_viewer["HTML Viewer (html/pzmap.html)"]:::viewer
        html_script["HTML Script (html/pzmap.js)"]:::viewer
        server["Server (html/server.py)"]:::viewer
        run_server["Run Server (html/run_server.bat)"]:::viewer
    end

    %% Auxiliary & Testing
    subgraph "Auxiliary & Testing"
        gen_example_conf["Gen Example Config (scripts/gen_example_conf.py)"]:::aux
        collect_mod_map["Collect Mod Map Data (scripts/collect_mod_map_data.py)"]:::aux
        check_tiles["Check Tiles (scripts/check_tiles.py)"]:::aux
        get_mod_dep["Get Mod Dependencies (scripts/get_mod_dep.py)"]:::aux
        test_suite["Test Suite (test directory)"]:::aux
    end

    %% Data Flow Connections
    config_file -->|"drives"| render_engine
    main_py -->|"initiates"| render_engine
    run_bat -->|"triggers"| render_engine
    run_iso -->|"triggers"| render_engine
    run_top -->|"triggers"| render_engine

    render_engine -->|"calls render_impl"| render_impl
    render_engine -->|"uses"| geometry
    render_engine -->|"schedules tasks with"| scheduler
    render_engine -->|"accelerates via"| shared_memory

    render_engine -->|"produces tiles"| html_viewer
    render_engine -->|"generates metadata"| html_script
    server -->|"serves"| html_viewer
    run_server -->|"launches"| server

    %% Auxiliary Assistance
    gen_example_conf -->|"assists config"| config_file
    collect_mod_map -->|"supports rendering"| render_engine
    check_tiles -->|"verifies output"| html_viewer
    get_mod_dep -->|"analyzes dependencies"| render_engine
    test_suite -->|"validates"| render_engine

    %% Classes for styling colors
    classDef cli fill:#aaf,stroke:#333,stroke-width:2px;
    classDef config fill:#aef,stroke:#333,stroke-width:2px;
    classDef processing fill:#afa,stroke:#333,stroke-width:2px;
    classDef viewer fill:#ff9,stroke:#333,stroke-width:2px;
    classDef aux fill:#faa,stroke:#333,stroke-width:2px;

    %% Click Events for Command-Line Interface & Entry Points
    click main_py "https://github.com/cff29546/pzmap2dzi/blob/main/main.py"
    click run_bat "https://github.com/cff29546/pzmap2dzi/blob/main/run.bat"
    click run_iso "https://github.com/cff29546/pzmap2dzi/blob/main/run_isometric_only.bat"
    click run_top "https://github.com/cff29546/pzmap2dzi/blob/main/run_top_view_only.bat"

    %% Click Event for Configuration
    click config_file "https://github.com/cff29546/pzmap2dzi/blob/main/conf/conf.yaml"

    %% Click Events for Core Rendering Engine
    click render_engine "https://github.com/cff29546/pzmap2dzi/blob/main/pzmap2dzi/render.py"
    click render_impl "https://github.com/cff29546/pzmap2dzi/tree/main/pzmap2dzi/render_impl/"
    click geometry "https://github.com/cff29546/pzmap2dzi/blob/main/pzmap2dzi/geometry.py"
    click scheduler "https://github.com/cff29546/pzmap2dzi/blob/main/pzmap2dzi/scheduling.py"
    click shared_memory "https://github.com/cff29546/pzmap2dzi/blob/main/pzmap2dzi/shared_memory_image.py"

    %% Click Events for Auxiliary Scripts and Tools
    click gen_example_conf "https://github.com/cff29546/pzmap2dzi/blob/main/scripts/gen_example_conf.py"
    click collect_mod_map "https://github.com/cff29546/pzmap2dzi/blob/main/scripts/collect_mod_map_data.py"
    click check_tiles "https://github.com/cff29546/pzmap2dzi/blob/main/scripts/check_tiles.py"
    click get_mod_dep "https://github.com/cff29546/pzmap2dzi/blob/main/scripts/get_mod_dep.py"

    %% Click Event for Testing Framework
    click test_suite "https://github.com/cff29546/pzmap2dzi/tree/main/test"

    %% Click Events for HTML Viewer & Server
    click html_viewer "https://github.com/cff29546/pzmap2dzi/blob/main/html/pzmap.html"
    click html_script "https://github.com/cff29546/pzmap2dzi/blob/main/html/pzmap.js"
    click server "https://github.com/cff29546/pzmap2dzi/blob/main/html/server.py"
    click run_server "https://github.com/cff29546/pzmap2dzi/blob/main/html/run_server.bat"
```
