Mass Battle Frameworkv1.20.0

架构Architecture

交互式图表Interactive Diagrams

依据 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.

点击节点打开 API 页 · 悬停高亮连线Click nodes to open API pages · hover to highlight edges
帧起始Frame start Stage 0 Stage 1 Stage 2 Stage 3 Stage 4 Stage 5 Post-sim 帧末网络End-of-frame network 渲染Render GridUpdateProcessor 帧首准备Frame setup AgentTraceProcessor 感知Perception AgentBehaviorProcessor 生成投射物 / 收集击退Spawn projectiles / collect knockback ProjectileMonoProcessor 命中特效 / 伤害Hit FX / damage DebuffMonoProcessor 伤害入账Damage bookkeeping AgentReactionProcessor 受击 / 死亡特效Hit / death FX LootMonoProcessor 死亡掉落Death loot AgentMoveProcessor 移动积分(浮点)Move integration (float) AgentMoveProcessorFP 移动积分(定点)Move integration (fixed-point) PhysicsProcessor 移动之后 · PBD 碰撞求解(可开关)After move · PBD solve (toggle) 击退在同一逻辑帧内生效Knockback lands in the same logic tick HostMonoProcessor Actor / 特效 / 音效宿主Actor / FX / sound host 子系统 ExecuteTick · 事件队列Subsystem ExecuteTick · event queues 回收 / 销毁 / 命令冲刷Recycle / destroy / command flush NetworkProcessor 帧末 · 哈希与快照校验End of frame · hash & snapshot check FxRenderProcessor 渲染 · 特效批次Render · FX batch AgentRenderProcessor 渲染 · Agent 批次Render · agent batch 生成抛射物与击退Spawn projectiles & knockback 施加伤害Deals damage 标记死亡Marks deaths 哈希与快照Hash & snapshot

② 渲染路径 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.

点击节点打开 API 页Click nodes to open API pages
Fragment 数据Fragment data Render.h · 每实体状态Render.h · per-entity state RenderProcessor 逐单位收集Per-unit gather Slot 批量数组Slot batch arrays 每单位固定一格One fixed slot per unit SetNiagaraArray* 整批推送Whole-batch push GPU CustomHLSL 插值 / 外推Interpolate / extrapolate DynamicParameter 材质读取表现参数Material reads presentation

③ 网络锁步 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.

点击节点打开 API 页Click nodes to open API pages
SERVER · 锁步主机SERVER · lockstep host CLIENT · 对端CLIENT · peer 确定性模拟 Sim TickDeterministic Sim Tick SimStages 0–5 · UID 分配 · 池状态SimStages 0–5 · UID allocation · pool state 状态哈希State hash 帧末哈希校验End-of-frame hash validation Snapshot 捕获Snapshot capture MassBattleSnapshotRegistry · 骨架模板 KeyMassBattleSnapshotRegistry · skeleton template key TCP 传输TCP transport 端口冲突自愈 · 探测存活Port-conflict self-healing · liveness probing 确定性模拟 Sim TickDeterministic Sim Tick 同输入同输出 — 与主机对称Same input, same output — symmetric with the host Hash 校验Hash validation 与主机哈希历史比对 · 失步检测Compare hash history with the host · desync detection 一致 → 继续Match → continue 双端同步推进Both peers advance in lockstep 失步 → ResyncDesync → Resync TriggerResync · 快照恢复TriggerResync · snapshot restore 快照恢复 RestoreSnapshot Restore 注册表布局 · 骨架模板重建 · 本地视觉层重链Registry layout · skeleton template rebuild · local-visual relink 快照Snapshot 哈希Hash 哈希 / 快照Hash / snapshot resync 请求 / 快照下发resync request / snapshot delivery

④ 模块依赖 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.

点击模块打开 API 目录Click a module to open its API index
Editor / UncookedOnly 层Editor / UncookedOnly layer Runtime 层Runtime layer MassAPIUncooked UncookedOnly · fragment/tag/flag 蓝图节点UncookedOnly · fragment/tag/flag Blueprint nodes K2Node_* 系列K2Node_* family MagnusUncooked UncookedOnly · 结构体操作节点UncookedOnly · struct-operation nodes Loop / Map / Struct 节点Loop / Map / Struct nodes MassBattleEditor Editor · 编辑器工具与 FuncLibEditor · editor tools & FuncLibs 依赖 MassBattleDepends on MassBattle MassAPI Runtime · Mass 实体管理 APIRuntime · Mass entity-management API EntitySubsystem / Fragment 操作EntitySubsystem / fragment operations Magnus Runtime · 自定义属性/节点框架Runtime · custom-property/node framework FuncLib / NodeCompiler FlowFieldCanvas Runtime · 流场寻路Runtime · flow-field pathfinding FlowField · Cost/Dir Modifier MassBattle Runtime · 核心:处理器/子系统/网络Runtime · core: processors/subsystems/networking Fragments · Processors · Subsystems MassBattle → MassAPI · FlowFieldCanvas