Skip to content

This is general knowledge or an external-engine reference, not an Apollo architecture or implementation claim. See Apollo's architecture status for target terminology and verified implementation boundaries.

Q2: What Are CellApp and BaseApp Each Responsible for in the BigWorld Architecture? Why Separate Them? ​

Problem Analysis ​

This question tests your understanding of the spatial separation design in the BigWorld/KBEngine architecture:

  • The division of responsibilities between CellApp and BaseApp
  • Why separate them this way
  • The advantages and challenges of this design

CellApp vs BaseApp Comparison ​

Responsibility Comparison Table ​

DimensionBaseAppCellApp
Core responsibilityManages non-spatial EntitiesManages spatial Entities
Has coordinatesNoYes (x, y, z)
Entity characteristicsFixed and immutableMigrates (across CellApps)
Client anchorProxy serves as the communication anchorDoes not interface with clients directly
Typical functionsInventory, friends, quests, mailCombat, movement, AOI, AI
CountMultiple (load balancing)Multiple (spatial partitioning)
Scaling methodAdd instances to share playersAdd instances to share space

Detailed Responsibilities ​

BaseApp Responsibilities ​

┌─────────────────────────────────────────────────────────────┐
│                        BaseApp                               │
├─────────────────────────────────────────────────────────────┤
│  1. Player Proxy management                                 │
│     - Each Proxy corresponds to one client                  │
│     - Serves as the communication anchor for the client     │
│     - Responsible for message redirection                   │
├─────────────────────────────────────────────────────────────┤
│  2. Non-spatial logic                                       │
│     ├── Inventory system (items, equipment)                 │
│     ├── Friend system (friend list, relationships)          │
│     ├── Mail system (sending/receiving mail, attachments)   │
│     ├── Quest system (quest state, progress)                │
│     ├── Mall system (buying, selling)                       │
│     ├── Leaderboard system                                  │
│     └── Guild system (basic management)                     │
├─────────────────────────────────────────────────────────────┤
│  3. Data persistence coordination                           │
│     - Periodically save player data to DBMgr                │
│     - Dirty data detection and synchronization              │
├─────────────────────────────────────────────────────────────┤
│  4. Message routing                                         │
│     - Forward client messages to the correct CellApp        │
│     - Receive CellApp messages and forward to clients       │
└─────────────────────────────────────────────────────────────┘

CellApp Responsibilities ​

┌─────────────────────────────────────────────────────────────┐
│                        CellApp                               │
├─────────────────────────────────────────────────────────────┤
│  1. Spatial region management                               │
│     - Manages Cells (spatial regions)                       │
│     - Maintains Entity position information                 │
│     - Handles Cell boundaries                               │
├─────────────────────────────────────────────────────────────┤
│  2. AOI system                                              │
│     - 3×3 grid / cross-linked list                          │
│     - View management                                       │
│     - Enter/leave events                                    │
├─────────────────────────────────────────────────────────────┤
│  3. Spatial logic                                           │
│     ├── Player movement                                     │
│     ├── Combat system (skills, damage)                       │
│     ├── NPC AI behavior                                     │
│     ├── Pathfinding system                                  │
│     ├── Scene object management                             │
│     └── State synchronization (position, animation)          │
├─────────────────────────────────────────────────────────────┤
│  4. Entity migration                                        │
│     - Cross-CellApp migration                               │
│     - Cross-Cell boundary handling                          │
├─────────────────────────────────────────────────────────────┤
│  5. Ghost synchronization                                   │
│     - Read-only copies of Entities across boundaries        │
│     - Ensures interaction consistency                       │
└─────────────────────────────────────────────────────────────┘

Why Separate Them This Way? ​

Reason 1: The Essential Difference Between Spatial and Non-Spatial Logic ​

flowchart LR
    subgraph Inputs["Player behavior"]
        A["Move"]
        B["Attack"]
        C["Open inventory"]
        D["View friends"]
    end

    subgraph Cell["Spatial logic (requires coordinates)"]
        CellLogic["Handled by CellApp"]
    end

    subgraph Base["Non-spatial logic (does not require coordinates)"]
        BaseLogic["Handled by BaseApp"]
    end

    A --> CellLogic
    B --> CellLogic
    C --> BaseLogic
    D --> BaseLogic

    style CellLogic fill:#ffe1e1
    style BaseLogic fill:#e1f5ff
FeatureSpatial logicNon-spatial logic
Depends on coordinatesYesNo
Compute intensiveYes (AOI, collision, pathfinding)No
Entity migrationFrequentAlmost none
Communication patternArea broadcastPoint-to-point

Reason 2: Supports Dynamic Load Balancing ​

Spatial scenarios:
┌─────────────────────────────────────────────────────────────┐
│                      Game world map                          │
│                                                              │
│  ┌────────────┐  ┌────────────┐  ┌────────────┐            │
│  │ CellApp 1  │  │ CellApp 2  │  │ CellApp 3  │            │
│  │ Load 30%   │  │ Load 85%   │  │ Load 20%   │            │
│  │ Newbie     │  │ Main city  │  │ Wilderness │            │
│  │ village    │  │            │  │            │            │
│  └────────────┘  └────────────┘  └────────────┘            │
│                                                              │
│  CellApp 2 overloaded → dynamic split → add CellApp 4       │
└─────────────────────────────────────────────────────────────┘

Non-spatial logic:
┌─────────────────────────────────────────────────────────────┐
│                      BaseApp cluster                         │
│                                                              │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────┐   │
│  │BaseApp 1 │  │BaseApp 2 │  │BaseApp 3 │  │BaseApp 4 │   │
│  │ 1000     │  │ 1000     │  │ 1000     │  │ 1000     │   │
│  │ players  │  │ players  │  │ players  │  │ players  │   │
│  └──────────┘  └──────────┘  └──────────┘  └──────────┘   │
│                                                              │
│  Player A logs in → BaseAppMgr assigns → least-loaded       │
│  BaseApp                                                     │
└─────────────────────────────────────────────────────────────┘

Reason 3: The Complexity of Entity Migration ​

The dual nature of the player Entity:

┌─────────────────────────────────────────────────────────────┐
│                        Player Entity                         │
├─────────────────────────────┬───────────────────────────────┤
│      Base Entity (Proxy)    │      Cell Entity              │
│      (on BaseApp)           │      (on CellApp)             │
├─────────────────────────────┼───────────────────────────────┤
│ - Fixed and immutable       │ - Migrates (across CellApps)  │
│ - No coordinates            │ - Has coordinates (x, y, z)   │
│ - Client's communication    │ - Spatial logic               │
│   anchor                    │                               │
│ - Inventory, friends, mail,  │ - Combat, movement, AOI, etc. │
│   etc.                      │                               │
└─────────────────────────────┴───────────────────────────────┘

Only the Cell Entity needs to migrate during migration:

Player moves from CellApp1 to CellApp2:

┌─────────────┐                    ┌─────────────┐
│  BaseApp    │                    │  BaseApp    │
│  (unchanged)│                    │  (unchanged)│
│  ┌──────┐   │                    │  ┌──────┐   │
│  │Proxy │◄──┼────────────────────┼──┤Proxy │   │
│  └──────┘   │  Communication     │  └──────┘   │
└─────────────┘  anchor never      └─────────────┘
                  changes
       ▲                                   ▲
       │ Message redirection               │ Message redirection
       │                                   │
┌───────┴────────┐              ┌─────────┴────────┐
│   CellApp 1    │              │   CellApp 2     │
│  Cell Entity   │ ───────────► │   Cell Entity   │
│  (old position)│  migration   │   (new position)│
└────────────────┘              └─────────────────┘

Reason 4: Network Communication Optimization ​

Client communication pattern:

┌─────────┐                              ┌─────────┐
│ Client  │ ──────────────────────────►│ BaseApp │
│         │   All messages go here      │  Proxy  │
└─────────┘                              └────────┘
                                              │
                    ┌─────────────────────────┼─────────────────────────┐
                    │                         │                         │
                    ▼                         ▼                         ▼
            ┌───────────┐             ┌───────────┐             ┌───────────┐
            │ CellApp 1 │             │ CellApp 2 │             │ CellApp 3 │
            │ (nearby   │             │ (empty    │             │ (nearby   │
            │ players)  │             │ area)     │             │ players)  │
            └───────────┘             └───────────┘             └───────────┘

Advantages:
1. The client only needs to know one address (BaseApp/Proxy)
2. The Proxy handles message routing; the client does not need to care which CellApp the Entity is on
3. Entity migration is transparent to the client

Advantages and Challenges ​

Advantages ​

AdvantageDescription
Independent scalingCellApp scales by space, BaseApp scales by player count
Fault isolationOne CellApp failure only affects a local area
Flexible deploymentComponent counts can be dynamically adjusted based on load
Transparent migrationEntity migration is transparent to the client
Clear responsibilitiesSpatial and non-spatial logic are separated, with clear code organization

Challenges ​

ChallengeDescription
Increased complexityNeed to manage two sets of Entities and their relationships
Cross-component communicationBaseApp ↔ CellApp communication overhead
Data consistencyBase/Cell data synchronization issues
Difficult debuggingProblems may span multiple components
Ghost mechanismCross-boundary Entities need extra synchronization

Data Flow Examples ​

Player Login Flow ​

sequenceDiagram
    participant C as Client
    participant G as GatewayApp
    participant L as LoginApp
    participant BA as BaseApp
    participant CA as CellApp
    participant DB as DBMgr

    C->>G: Login request
    G->>L: Forward login
    L->>DB: Verify account
    DB-->>L: Verification succeeded
    L->>BA: Create Proxy
    BA->>DB: Load player data
    DB-->>BA: Return data
    BA->>CA: Create Cell Entity
    BA-->>G: Login succeeded
    G-->>C: Return gateway address
    C->>BA: Establish connection

Player Movement Flow ​

sequenceDiagram
    participant C as Client
    participant BA as BaseApp
    participant CA1 as CellApp1
    participant CA2 as CellApp2

    C->>BA: Movement request
    BA->>CA1: Forward movement request
    CA1->>CA1: Update position
    CA1->>CA1: AOI detection
    CA1-->>BA: Return nearby players
    BA-->>C: Broadcast position update

    Note over CA1,CA2: Player moves to the CA2 boundary

    CA1->>CA2: Entity migration request
    CA2->>CA2: Create Entity
    CA2-->>CA1: Migration complete
    CA1->>CA1: Destroy Entity
    CA1-->>BA: Update Entity routing
    BA->>CA2: Subsequent messages forwarded to CA2

Using the Inventory Flow ​

sequenceDiagram
    participant C as Client
    participant BA as BaseApp
    participant DB as DBMgr

    C->>BA: Use item request
    BA->>BA: Verify item quantity
    BA->>BA: Deduct item
    BA->>BA: Apply effect
    BA->>DB: Asynchronous save
    BA-->>C: Return result

References ​

Released under the MIT License