Files
BABA_YAGA/BABA_YAGA_Updater/sections/05_networking.md

85 lines
4.8 KiB
Markdown
Raw Normal View History

2026-06-07 21:17:51 +07:00
<div id="networking"></div>
2026-06-07 20:04:33 +07:00
## <img src="https://api.iconify.design/lucide/globe-2.svg?color=%2333CCFF" width="28" height="28" style="vertical-align: middle;"> Kiến trúc Netcode (Deterministic Networking)
2026-06-07 19:41:43 +07:00
2026-06-07 20:04:33 +07:00
<div align="center">
<img src="https://img.shields.io/badge/ENGINE-PHOTON_FUSION_2.0-0055FF?style=for-the-badge&logo=purescript&logoColor=white" />
<img src="https://img.shields.io/badge/TOPOLOGY-CLIENT_HOSTED_SERVER-FF3333?style=for-the-badge&logo=server&logoColor=white" />
<img src="https://img.shields.io/badge/TICKRATE-60_Hz-00FF55?style=for-the-badge&logo=activity&logoColor=black" />
</div>
> Tựa game với nhịp độ sinh tồn căng thẳng không có chỗ cho sự sai lệch (Desync). **BABA_YAGA** vận hành trên kiến trúc **State Sync (Đồng bộ Trạng thái)** kết hợp quy trình **Dự đoán phía Client (Client-Side Prediction)** và **Bù trừ Độ trễ (Lag Compensation)**, mang lại cảm giác phản hồi tức thì "Zero-Latency" ngay cả ở mức Ping 100ms+.
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border: none;">
<tr>
<td width="50%" style="padding: 15px; background: rgba(51,204,255,0.05); border-left: 3px solid #33CCFF; border-bottom: 1px solid rgba(255,255,255,0.05);">
<strong style="color: #33CCFF;"><img src="https://api.iconify.design/lucide/fast-forward.svg?color=%2333CCFF" width="18" style="vertical-align: middle;"> Client-Side Prediction (Dự đoán cục bộ)</strong><br>
<p style="font-size: 13px; color: #AAA; margin-top: 8px;">Người chơi nội bộ (Local Player) thực thi các lệnh di chuyển, lướt, rọi đèn pin <b>ngay lập tức</b> mà không cần đợi Server cho phép. Tạo cảm giác điều khiển mượt mà như game Offline.</p>
</td>
<td width="50%" style="padding: 15px; background: rgba(255,51,51,0.05); border-left: 3px solid #FF3333; border-bottom: 1px solid rgba(255,255,255,0.05);">
<strong style="color: #FF3333;"><img src="https://api.iconify.design/lucide/shield-check.svg?color=%23FF3333" width="18" style="vertical-align: middle;"> Server Reconciliation (Thuật toán Đối chiếu)</strong><br>
<p style="font-size: 13px; color: #AAA; margin-top: 8px;">Máy chủ vẫn nắm quyền tối thượng (Authority). Nếu Client dự đoán sai (do va chạm với bẫy hoặc bị kẹt), Server sẽ ép Client "Rollback" về trạng thái chuẩn trong tích tắc (Snap Correction).</p>
</td>
</tr>
</table>
<br>
### <img src="https://api.iconify.design/lucide/satellite-dish.svg?color=%23E0E0E0" width="22" height="22" style="vertical-align: middle;"> Network Data Flow (Luồng Đồng bộ Hóa)
> Sơ đồ biểu diễn vòng đời của một **Network Tick** từ khi người chơi nhấn phím đến khi hình ảnh được kết xuất (Render) trên màn hình của những người chơi khác.
2026-06-07 19:41:43 +07:00
```mermaid
sequenceDiagram
autonumber
2026-06-07 21:17:51 +07:00
2026-06-07 20:04:33 +07:00
box rgba(51, 204, 255, 0.05) "⚡ LOCAL ENVIRONMENT (Client Auth)"
2026-06-07 21:17:51 +07:00
participant IR as "🖱️ Input"
participant CP as "💻 Local Player"
2026-06-07 20:04:33 +07:00
end
2026-06-07 21:17:51 +07:00
2026-06-07 20:04:33 +07:00
box rgba(255, 51, 51, 0.05) "👑 SERVER ENVIRONMENT (State Auth)"
2026-06-07 21:17:51 +07:00
participant NT as "📡 Network Layer"
participant S as "🖥️ Server Tick"
2026-06-07 20:04:33 +07:00
end
2026-06-07 21:17:51 +07:00
2026-06-07 20:04:33 +07:00
box rgba(255, 215, 0, 0.05) "👁️ REMOTE OBSERVERS"
2026-06-07 21:17:51 +07:00
participant RP as "👥 Proxies"
2026-06-07 20:04:33 +07:00
end
2026-06-07 19:41:43 +07:00
2026-06-07 21:17:51 +07:00
Note over IR,CP: [PHASE 1] DATA ACQUISITION
2026-06-07 20:04:33 +07:00
IR->>CP: OnMove / OnAbility (Raw Input)
2026-06-07 21:17:51 +07:00
CP->>CP: 📦 Pack NetworkInputStruct
2026-06-07 19:41:43 +07:00
2026-06-07 20:04:33 +07:00
Note over CP: [PHASE 2] FORWARD PREDICTION
2026-06-07 21:17:51 +07:00
CP->>CP: ⚡ Run Local Kinematics (Tick N)
CP->>NT: 📤 Transmit Input Payload
2026-06-07 20:04:33 +07:00
rect rgba(255, 51, 51, 0.1)
2026-06-07 21:17:51 +07:00
Note over NT,S: [PHASE 3] SERVER VALIDATION (Simulation)
2026-06-07 20:04:33 +07:00
NT->>S: Deliver UDP Packet
2026-06-07 21:17:51 +07:00
S->>S: 🛡️ Validate Rules & Apply Physics
S-->>NT: 📢 Broadcast State Snapshot (Tick N)
2026-06-07 20:04:33 +07:00
end
2026-06-07 19:41:43 +07:00
2026-06-07 21:17:51 +07:00
Note over NT,CP: [PHASE 4] RECONCILIATION PROTOCOL
2026-06-07 20:04:33 +07:00
NT-->>CP: State Snapshot (Global Truth)
2026-06-07 21:17:51 +07:00
CP->>CP: ⚖️ Check Desync (Threshold)
CP->>CP: 🔄 Snap Pos & Resimulate if Error
2026-06-07 19:41:43 +07:00
2026-06-07 21:17:51 +07:00
Note over NT,RP: [PHASE 5] PROXY INTERPOLATION
2026-06-07 19:41:43 +07:00
NT-->>RP: State Snapshot
2026-06-07 21:17:51 +07:00
RP->>RP: 〰️ Lerp Position / Rotation Smoothly
2026-06-07 20:04:33 +07:00
2026-06-07 21:17:51 +07:00
Note over CP,RP: [PHASE 6] VISUAL RENDERING
CP->>CP: 🎥 Update Local VFX / Camera Shake
RP->>RP: 👻 Update Animator & Mesh Transforms
```
2026-06-07 20:04:33 +07:00
<br>
<div align="center">
<img src="https://api.iconify.design/lucide/shield-alert.svg?color=%23555555" width="16" style="vertical-align: middle;">
<small style="color: #888;"><i>Tất cả Logic Va chạm (Collision) và Phát hiện Âm thanh (Noise Detection) được phân tách hoàn toàn khỏi luồng Render đồ họa, ngăn chặn hiện tượng rách hình ảnh (Tearing) do lag mạng.</i></small>
</div>
```