Skip to content

Instantly share code, notes, and snippets.

@nandordudas
Created November 10, 2024 20:32
Show Gist options
  • Save nandordudas/8f359a69b1fef4077d10cd44cbe5d7d2 to your computer and use it in GitHub Desktop.
Save nandordudas/8f359a69b1fef4077d10cd44cbe5d7d2 to your computer and use it in GitHub Desktop.
flowchart TB
    subgraph Server["Game Server"]
        SAB[("SharedArrayBuffer\n(Game State)")]
        Physics["Physics Engine"]
        InputHandler["Input Handler"]
        StateManager["State Manager"]
        
        Physics -->|"Update"| SAB
        InputHandler -->|"Update"| SAB
        SAB -->|"Read"| StateManager
    end

    subgraph Client["Client Architecture"]
        subgraph WorkerSystem["Worker Orchestrator"]
            direction TB
            WO[("Orchestrator\nSharedArrayBuffer")]
            
            subgraph Workers["Worker Pool"]
                direction LR
                IW["Input Worker"]
                RW["Render Worker\n(State Interpolation)"]
                NW["Network Worker\n(State Management)"]
            end
            
            IW -->|"Input"| WO
            NW -->|"Game State"| WO
            WO -->|"Interpolated State"| RW
        end
        
        subgraph UI["UI Thread"]
            Game["Game Component"]
            Canvas["Canvas Element"]
        end
        
        Game -->|"Transfer"| Canvas
        Canvas -->|"OffscreenCanvas"| RW
    end

    %% Network Connections
    IW -->|"Input Events"| NW
    NW <-->|"WebSocket"| InputHandler
    StateManager -->|"SSE"| NW

    %% Styling
    classDef server fill:#f9f,stroke:#333,stroke-width:2px
    classDef client fill:#bbf,stroke:#333,stroke-width:2px
    classDef worker fill:#dfd,stroke:#333,stroke-width:2px
    classDef connection fill:#fdd,stroke:#333,stroke-width:2px
    
    class Server server
    class Client client
    class Workers worker
    class NW connection
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment