# wchen777/copied-city architecture

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

- Interactive diagram: https://gitdiagram.com/wchen777/copied-city
- Repository: https://github.com/wchen777/copied-city

## Overview

The project is a realtime procedural city generator built using OpenGL. Its primary goal is to replicate the visual style of Nier Automata’s Copied City, featuring effects such as Screen Space Ambient Occlusion (SSAO), shadow mapping, texture and skybox mapping, and fog. The system uses external libraries (GLEW for OpenGL extension handling and GLM for mathematical computations) and organizes its own source code into several logical domains (camera, city generation, rendering, utilities, and mesh definitions).

##### Main Components
- Core Application & Main Loop: Represent the entry point (src/main.cpp) and main window (src/mainwindow.cpp/h) that initialize the application, set up the rendering loop, and manage overall state.
- Camera System: Include the modules under “src/camera” (camera.cpp, transforms.cpp) that handle view and projection matrices, user input, and scene navigation.
- City Renderer: Illustrate the components in “src/cityrenderer” for handling the visual aspects of the procedural city. This module deals with rendering shadows, sky, SSAO, and texture mapping (renderssao.cpp, rendershadow.cpp, rendersky.cpp, blocktexture.cpp).
- Mesh and Geometry: Outline the “src/trimeshes” module that represents basic geometric primitives and OBJ mesh loading (cube, obj_mesh implementations).

##### Relationships and Interactions
- The Main Application initializes the Camera, City Generator, and Rendering Engine.
- The City Generator produces procedural layout data and geometry (possibly in the form of mesh data) that is passed to the Renderer via the City Renderer module.
- The Camera system provides the view and projection matrices to the rendering pipeline.
- The renderer uses shader programs (loaded from “resources/shaders”) and textures (from “resources/textures”) to render the scene with multimedia effects such as SSAO, shadow mapping, and skybox rendering.
- Utility modules support scene parsing and asset management, feeding data into the core rendering process.
- External libraries (GLEW and GLM) are foundational and are part of the build as referenced by CMake (CMakeLists.txt and build scripts).

##### Architectural Patterns and Design Principles
- Layered/MVC-like Separation: Distinct separation between data generation (City Generator), business logic (Renderer Engine), and presentation (City Renderer, UI from mainwindow).
- Module isolation: Each subdirectory within “src” targets a discrete concern (e.g., camera handling, procedural generation, meshes, utilities), making it easier to manage dependencies.
- Use of External Libraries: Clearly mark GLEW and GLM as support libraries that the entire rendering stack depends on, indicating their integration in the build process.

##### Technologies and Frameworks
- OpenGL: Core rendering API.
- GLEW: For handling OpenGL extensions.
- GLM: For mathematical computations specific to graphics.
- CMake/Ninja: For build management based on the CMakeLists.txt and build.ninja files.
- Procedural Generation Algorithms: Represented in the City Generator module.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Application Layer
    subgraph "Core Application"
        MainEntry["Main.cpp"]:::core
        MainWindowCPP["MainWindow.cpp"]:::core
        MainWindowH["MainWindow.h"]:::core
        RealtimeCPP["Realtime.cpp"]:::core
        RealtimeH["Realtime.h"]:::core
    end

    %% Camera System
    subgraph "Camera System"
        Camera["Camera Module"]:::camera
        Transforms["Transforms"]:::camera
    end

    %% City Generator
    subgraph "City Generator"
        Generator["Generator"]:::generator
        CityFacade["City Facade"]:::generator
        CubeGrowths["Cube Growths"]:::generator
    end

    %% Renderer Engine
    subgraph "Renderer Engine"
        subgraph "City Renderer"
            SSAO["SSAO (renderssao)"]:::renderer
            ShadowMapping["Shadow Mapping (rendershadow)"]:::renderer
            SkyRendering["Sky Rendering (rendersky)"]:::renderer
            BlockTexture["Block Texture (blocktexture)"]:::renderer
            RenderCity["Render City (rendercity)"]:::renderer
        end
        RenderFunctions["Render Functions"]:::renderer
        Primitive["Primitive"]:::renderer
        Debug["Debug"]:::renderer
        ShaderLoader["Shader Loader"]:::renderer
    end

    %% Mesh and Geometry
    subgraph "Mesh and Geometry"
        CubeMesh["Cube Mesh"]:::mesh
        OBJMesh["OBJ Mesh"]:::mesh
        TrimeshNode["Trimesh"]:::mesh
    end

    %% Utilities
    subgraph "Utilities"
        SceneParser["Scene Parser"]:::utility
        SceneFileReader["Scene File Reader"]:::utility
        RGBA["RGBA / Scene Data"]:::utility
    end

    %% External Libraries
    subgraph "External Libraries"
        GLEW["GLEW"]:::external
        GLM["GLM"]:::external
    end

    %% Assets
    Assets["Resources"]:::assets

    %% Relationships and Interactions
    MainEntry -->|"init"| Camera
    MainEntry -->|"init"| Generator
    MainEntry -->|"init"| RenderFunctions

    Camera -->|"view/proj"| RenderFunctions
    Generator -->|"data"| SSAO
    Generator -->|"data"| Primitive
    CubeGrowths -->|"procedural_geo"| CubeMesh

    %% Utilities supporting City Generator and Renderer Engine
    SceneParser -->|"parse"| Generator
    SceneFileReader -->|"read"| Generator
    RGBA -->|"color"| RenderFunctions
    SceneParser -->|"assist"| RenderFunctions
    SceneFileReader -->|"assist"| RenderFunctions

    %% Mesh and Geometry integration
    CubeMesh -->|"mesh_data"| Primitive
    OBJMesh -->|"mesh_data"| Primitive
    TrimeshNode -->|"mesh_data"| Primitive

    %% Renderer Engine internal interactions
    RenderFunctions -->|"calls"| SSAO
    RenderFunctions -->|"calls"| ShadowMapping
    RenderFunctions -->|"calls"| SkyRendering
    RenderFunctions -->|"calls"| BlockTexture
    RenderFunctions -->|"calls"| RenderCity
    Primitive -->|"renders_geo"| RenderCity

    %% External Libraries and Assets support
    GLEW -->|"OpenGL_ext"| RenderFunctions
    GLM -->|"math_support"| Camera
    GLM -->|"math_support"| RenderFunctions
    Assets -->|"shaders_textures"| ShaderLoader

    %% Connections within Core Application
    MainWindowCPP --- MainEntry
    MainWindowH --- MainEntry
    RealtimeCPP --- MainEntry
    RealtimeH --- MainEntry

    %% City Generator feeds procedural data into City Renderer
    Generator -->|"procedural_data"| RenderCity

    %% Styles
    classDef core fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef camera fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef generator fill:#A9DFBF,stroke:#333,stroke-width:2px;
    classDef renderer fill:#FAD7A0,stroke:#333,stroke-width:2px;
    classDef mesh fill:#D7BDE2,stroke:#333,stroke-width:2px;
    classDef utility fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#333,stroke-width:2px;
    classDef assets fill:#FCF3CF,stroke:#333,stroke-width:2px;

    %% Click Events for Core Application
    click MainEntry "https://github.com/wchen777/copied-city/blob/master/src/main.cpp"
    click MainWindowCPP "https://github.com/wchen777/copied-city/blob/master/src/mainwindow.cpp"
    click MainWindowH "https://github.com/wchen777/copied-city/blob/master/src/mainwindow.h"
    click RealtimeCPP "https://github.com/wchen777/copied-city/blob/master/src/realtime.cpp"
    click RealtimeH "https://github.com/wchen777/copied-city/blob/master/src/realtime.h"

    %% Click Events for Camera System
    click Camera "https://github.com/wchen777/copied-city/blob/master/src/camera/camera.cpp"
    click Transforms "https://github.com/wchen777/copied-city/blob/master/src/camera/transforms.cpp"

    %% Click Events for City Generator
    click Generator "https://github.com/wchen777/copied-city/blob/master/src/citygenerator/generator.cpp"
    click CityFacade "https://github.com/wchen777/copied-city/blob/master/src/citygenerator/cityfacade.cpp"
    click CubeGrowths "https://github.com/wchen777/copied-city/blob/master/src/citygenerator/cubegrowths.cpp"

    %% Click Events for City Renderer
    click SSAO "https://github.com/wchen777/copied-city/blob/master/src/cityrenderer/renderssao.cpp"
    click ShadowMapping "https://github.com/wchen777/copied-city/blob/master/src/cityrenderer/rendershadow.cpp"
    click SkyRendering "https://github.com/wchen777/copied-city/blob/master/src/cityrenderer/rendersky.cpp"
    click BlockTexture "https://github.com/wchen777/copied-city/blob/master/src/cityrenderer/blocktexture.cpp"
    click RenderCity "https://github.com/wchen777/copied-city/blob/master/src/cityrenderer/rendercity.cpp"

    %% Click Events for Renderer Engine
    click RenderFunctions "https://github.com/wchen777/copied-city/blob/master/src/renderer/render.cpp"
    click Primitive "https://github.com/wchen777/copied-city/blob/master/src/renderer/primitive.cpp"
    click Debug "https://github.com/wchen777/copied-city/blob/master/src/renderer/debug.h"
    click ShaderLoader "https://github.com/wchen777/copied-city/blob/master/src/utils/shaderloader.h"

    %% Click Events for Mesh and Geometry
    click CubeMesh "https://github.com/wchen777/copied-city/blob/master/src/trimeshes/cube.cpp"
    click OBJMesh "https://github.com/wchen777/copied-city/blob/master/src/trimeshes/obj_mesh.cpp"
    click TrimeshNode "https://github.com/wchen777/copied-city/blob/master/src/trimeshes/trimesh.h"

    %% Click Events for Utilities
    click SceneParser "https://github.com/wchen777/copied-city/blob/master/src/utils/sceneparser.cpp"
    click SceneFileReader "https://github.com/wchen777/copied-city/blob/master/src/utils/scenefilereader.cpp"
    click RGBA "https://github.com/wchen777/copied-city/blob/master/src/utils/rgba.h"

    %% Click Events for External Libraries
    click GLEW "https://github.com/wchen777/copied-city/tree/master/glew"
    click GLM "https://github.com/wchen777/copied-city/tree/master/glm"

    %% Click Event for Assets
    click Assets "https://github.com/wchen777/copied-city/tree/master/resources"
```
