架构Architecture
依据 1.20.0 发布源码 · 节点可点击跳转对应 API 页Based on the 1.20.0 release source · click nodes to open API pages
概述 Overview
本页用四张交互式图呈现 Mass Battle 的整体结构:① 每帧模拟流程——一帧内从感知、行为到移动、渲染各阶段依次发生什么;② 渲染路径——单位数据如何到达屏幕;③ 网络锁步——双端哈希校验与快照恢复;④ 模块依赖——插件的模块分层。图中节点可点击跳转到对应 API 文档页,悬停可高亮关联连线。
This page presents Mass Battle's overall structure with four interactive diagrams: ① Per-frame simulation flow — what happens in each stage from perception and behavior to movement and rendering; ② Rendering path — how unit data reaches the screen; ③ Network lockstep — cross-peer hash validation and snapshot restore; ④ Module dependencies — the plugin's modules in layers. Nodes are clickable (jump to API pages) and hovering highlights connected edges.
① 每帧模拟流程 Per-Frame Simulation Flow
每个模拟帧按固定顺序经过六个阶段:先更新空间网格与帧首准备,然后依次是感知(谁看见谁)、行为(睡眠/巡逻/追击/攻击等状态决策,含投射物生成与击退收集)、投射物/伤害/受击(命中、特效、伤害入账)、掉落,最后是移动与碰撞(移动放在最后,使击退等施加在同一逻辑帧内生效)。渲染收集在帧尾把全部单位的表现数据交给 GPU;帧末的网络阶段在一切模拟与队列处理完成之后运行,保证联机哈希与快照反映的是真正的帧末状态。整个顺序由插件固定维护,你不需要(也不应该)手动调度任何处理器——配置好 DataAsset,剩下的自动发生。点击图中节点可跳到对应模块的 API 页。
Every simulation frame walks six fixed stages: spatial-grid update and frame setup first, then perception (who sees whom), behavior (sleep / patrol / chase / attack decisions, projectile spawning and knockback collection), projectiles / damage / reactions (hits, FX, damage bookkeeping), loot, and finally movement and collision (movement runs last so knockback and other impulses land within the same logic tick). Render gathering hands every unit's presentation data to the GPU at the end of the frame; the network stage runs after all simulation and queue processing so the online hash and snapshot reflect the true end-of-frame state. The plugin owns this order — you never schedule anything by hand. Configure your DataAssets and the rest happens automatically. Click diagram nodes to open the matching API pages.
② 渲染路径 Rendering Path
所有单位(人群、特效、血条、跳字)都经同一条渲染路径到达屏幕:模拟帧结束时,插件把每个单位的位置/朝向/动画等目标数据整批交给 Niagara;两次模拟帧之间,GPU 负责插值与外推,让 30Hz 的逻辑模拟呈现出满帧率的平滑画面——这也是「CPU 逻辑帧 + GPU 渲染帧插值」能同屏承载十万级单位的原因。材质侧读取队伍色、受击发光、冰冻/燃烧/中毒、溶解、LOD 与选中态等表现参数,走的是原生材质 + 材质函数:Creator 复制单位的源材质,把 MF_MassBattleMaterialFunction 嫁接进去(适配器契约:恰好一个 InAttributes 输入引脚,类型为 material attributes;至少一个 Out 输出),材质实例再以那份副本为父——所以不存在一份固定的、随插件发行的 PBR 主材质供你手改,每个源材质各带一份自己的主材质;sprite 单位不复制源材质,其母材质由图集资产(UMassBattleATADataAsset)的 MasterMaterial 指定。旧的 M_VATMaster 只为 37 份历史演示材质(/MassBattle/Demo/Agent/*/Gen_*)保留,不再是新内容的路径。相关着色器见 GPU 着色器页。日常使用不需要接触这条路径的任何环节。这套资产怎么烘出来见制作与烘焙,产物在系统里如何组织见渲染管线。
Everything on screen (crowds, FX, health bars, text pops) travels one rendering path: at the end of each simulation frame the plugin hands every unit's target data — position, orientation, animation — to Niagara in whole batches; between simulation frames the GPU interpolates and extrapolates, so a 30Hz logic simulation renders as smooth full-framerate motion. That "CPU logic frame + GPU render-frame interpolation" split is what lets 100K-scale crowds share the screen. Materials read the presentation parameters (team color, hit glow, freeze/burn/poison, dissolve, LOD, selection) through native material + material function: the Creator duplicates the unit's source material, grafts MF_MassBattleMaterialFunction into it (adapter contract: exactly one InAttributes input pin of material-attributes type, and at least one Out output), and the material instance parents that copy — so there is no fixed, shipped PBR master to hand-edit; each source material carries its own, and sprite units copy no source material at all — their master comes from the atlas asset's (UMassBattleATADataAsset) MasterMaterial. The old M_VATMaster is kept only as the parent of the 37 legacy demo materials under /MassBattle/Demo/Agent/*/Gen_* and is no longer the path for new content. The shaders live on the GPU shaders page. Day-to-day use never touches this path. How those assets are baked is on Authoring & Baking; how they are organized inside the system is on the Render Pipeline page.
③ 网络锁步 Network Lockstep
Mass Battle 采用确定性锁步:双端各自运行同一套确定性模拟,网络上只传玩家命令;每帧双方交换一份状态哈希做校验,一致则继续,失配则自动进入恢复(resync)——落后端从快照重建世界并追帧,通常一秒内完成。你自己项目里的框选高亮、点击特效等端本地表现不参与同步,由框架自动隔离。完整的原理讲解、从零接入的蓝图流程与调试工具见 网络同步指南。
Mass Battle uses deterministic lockstep: both peers run the same deterministic simulation and only player commands travel the wire; each frame the peers exchange a state hash for validation — matching hashes continue, a mismatch automatically triggers recovery (resync), where the lagging peer rebuilds the world from a snapshot and fast-forwards, usually within a second. Your own peer-local presentation (selection highlights, click FX) never syncs — the framework isolates it automatically. For the full walkthrough, the from-zero Blueprint guide and the debugging tools, see the Network Sync guide.
④ 模块依赖 Module Dependencies
插件包含的模块(依据插件清单与各 Build.cs):五个 Runtime 模块(MassBattle 核心、MassAPI Mass 实体管理 API、FlowFieldCanvas 流场寻路、Magnus 自定义属性与节点框架,以及随核心一同发布的着色层)、三个 UncookedOnly 模块(MassAPIUncooked / MagnusUncooked / MassBattleUncooked,蓝图节点定义,编辑器专用)与 MassBattleEditor(Editor,含烘焙与 Assembly 工具)。依赖方向:Editor/Uncooked → Runtime;核心模块依赖 Mass 实体 API、流场寻路与着色层。
The modules shipped with the plugin (per the plugin manifest and each Build.cs): five Runtime modules (MassBattle core, MassAPI Mass entity-management API, FlowFieldCanvas flow-field pathfinding, Magnus custom-property & node framework, and the shader layer that ships with the core), three UncookedOnly modules (MassAPIUncooked / MagnusUncooked / MassBattleUncooked — Blueprint node definitions, editor-only), and MassBattleEditor (Editor — it also hosts the baking and Assembly tools). Dependencies: Editor/Uncooked → Runtime; the core depends on the Mass entity API, flow-field pathfinding and the shader layer.