# hobr/sa-mp-android architecture

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

- Interactive diagram: https://gitdiagram.com/hobr/sa-mp-android
- Repository: https://github.com/hobr/sa-mp-android

## Overview

##### Main Components
- Android Application Package (APK):
- Represented by the “files/build69.apk” and the supporting files (apktool.bat, apktool.jar) used in the build process.
- Native Code Layer (JNI):
- The “jni” directory constitutes the heart of the application’s logic. This layer is further subdivided into several functional modules:
– Game Engine & Core Logic (e.g., game/game.cpp, game/entity.cpp, game/camera.cpp, game/util.cpp)
These files handle typical game functionalities such as rendering, physics calculations, and general game mechanics.
– RenderWare Integration:
The “jni/game/RW” subfolder (with RenderWare.cpp, RenderWare.h, rwcore.h, rwlpcore.h) indicates that the project leverages the RenderWare engine for graphics and possibly other functionalities.
– Network Communication Module:
The “jni/net” directory includes components like netgame.cpp, netgame.h, scriptrpc.cpp, and various pool management files. This module is designed to handle multiplayer synchronization, remote player management, and data exchange between clients and servers.
– GUI & Input Handling:
The “jni/gui” folder (containing gui.cpp, gui.h, and imgui_impl_renderware.cpp) alongside “jni/keyboard.cpp” suggests this part manages the user interface and input events.
– Auxiliary Components:
Additional functional units such as “chatwindow”, “dialog”, “debug”, “spawnscreen” indicate supplementary user interaction elements and debugging support.
- Data & Asset Management:
- The “data” directory, specifically within the “data/Android/obb/com.rockstargames.gtasa” path, includes game configurations, SAMP-specific assets, fonts, textures (in “texdb”), and other configuration files (handling.cfg, settings.ini, etc.). This represents the external resources that the native code loads and uses.
- Build & Configuration Ecosystem:
- Files like Android.mk, Application.mk in the “jni” folder, as well as build scripts and APK tooling in the “files” directory, indicate the build process using the Android NDK and appropriate packaging mechanisms.

##### Relationships and Interactions
- APK as the Container:
- The final Android APK (built using the provided scripts and apktool utilities) encapsulates the native libraries compiled from the “jni” sources along with packaged assets from the “data” folder.
- Native Application Workflow:
- At runtime, the Android OS loads the APK, which initializes native components. The game engine built on RenderWare drives the rendering loop and core gameplay.
- The network components communicate with external SA-MP servers to manage multiplayer interactions, with clear interconnections between local game state (from the “game” module) and remote state (via the “net” module).
- The GUI and input handlers capture player actions and overlay game-specific information, interfacing with the game engine.
- Asset Loading:
- External assets (textures, configurations, scripts) are read from the dedicated OBB files and data directories to support game functionalities.

##### Architectural Patterns and Design Principles
- Modular Architecture:
- The project’s structure clearly separates concerns across different modules (game, network, GUI, utility). This helps in isolating functionalities, making the system more maintainable.
- Native Performance:
- The use of native C++ code through JNI suggests an emphasis on performance in game rendering and network processing.
- Integration with Established Libraries:
- The RenderWare engine integration provides a robust base for graphics processing, while use of standard Android build practices (NDK, Makefiles) ensures compatibility.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Container
    APK["Android APK"]:::container
    BUILD["Build & Config Ecosystem"]:::build
    ASSETS["Data & Asset Management"]:::asset

    %% Native Code Layer Subgraph
    subgraph "Native Code Layer"
        NATIVE["Native Code (JNI)"]:::native
        GE["Game Engine & Core Logic"]:::module
        RW["RenderWare Integration"]:::module
        NET["Network Module"]:::module
        GUI["GUI/Input Handling"]:::module
        AUX["Auxiliary Components"]:::module
    end

    %% Build and Packaging Process
    BUILD -->|"builds"| APK
    APK -->|"loads"| NATIVE

    %% Native Module Relationships
    GE -->|"integrates"| RW
    GUI -->|"triggers"| GE
    NET <-->|"syncs"| GE
    ASSETS -->|"supplies data"| GE
    AUX -->|"aids operations"| GE

    %% Click Events
    click APK "https://github.com/hobr/sa-mp-android/blob/master/files/build69.apk"
    click BUILD "https://github.com/hobr/sa-mp-android/blob/master/jni/Android.mk"
    click ASSETS "https://github.com/hobr/sa-mp-android/blob/master/data/Android/obb/com.rockstargames.gtasa"
    click NATIVE "https://github.com/hobr/sa-mp-android/tree/master/jni"
    click GE "https://github.com/hobr/sa-mp-android/tree/master/jni/game"
    click RW "https://github.com/hobr/sa-mp-android/tree/master/jni/game/RW"
    click NET "https://github.com/hobr/sa-mp-android/tree/master/jni/net"
    click GUI "https://github.com/hobr/sa-mp-android/tree/master/jni/gui"
    click AUX "https://github.com/hobr/sa-mp-android/blob/master/jni/chatwindow.cpp"

    %% Styles
    classDef container fill:#FFD700,stroke:#B8860B,stroke-width:2px;
    classDef build fill:#DDA0DD,stroke:#9932CC,stroke-width:2px;
    classDef asset fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
    classDef native fill:#ADFF2F,stroke:#32CD32,stroke-width:2px;
    classDef module fill:#87CEFA,stroke:#4682B4,stroke-width:2px;
```
