Mass Battle Frameworkv1.20.0

UMassBattleNetworkProcessor

UCLASS Processor AUTO-DRIVEN · NO SETUP

Source/MassBattle/Public/Processors/MassBattleNetworkProcessor.h

概述Overview

帧末网络处理器:计算逐实体状态哈希并按周期捕获快照,是锁步校验与恢复的数据来源。由插件自动调度,无需配置;你与网络层的全部交互都通过 GameMode/GameState/PlayerController 基类与蓝图命令进行。

The end-of-frame network processor: folds per-entity state hashes and periodically captures snapshots — the data source behind lockstep validation and recovery. Auto-scheduled; all your interaction with the network layer goes through the GameMode / GameState / PlayerController base classes and Blueprint commands.

继承Inheritance

UMassProcessor → UMassBattleNetworkProcessor

公开方法Public Methods

UMassBattleNetworkProcessor constructor

构造函数关闭 Mass 处理阶段的自动注册(调度由插件驱动),声明必须在游戏线程执行,并把执行域设为 Standalone / Server / Client 三态——跨端锁步工作是否发生,由执行期按当前会话是否为网络会话判断。

The constructor disables auto-registration with Mass processing phases (the plugin drives scheduling), declares game-thread execution, and sets the execution domain to Standalone / Server / Client — whether cross-peer lockstep work happens is decided at execution time from whether the session is networked.

Input

无参数。

No parameters.

Output

无返回值。副作用:设置 bAutoRegisterWithProcessingPhases=false、bRequiresGameThreadExecution=true 与三态 ExecutionFlags。

No return value. Side effects: sets bAutoRegisterWithProcessingPhases=false, bRequiresGameThreadExecution=true and the three-mode ExecutionFlags.

ConfigureQueries virtual void (override)

建立唯一一条网络查询:以 FNetworkTag 为锚,以 Any<FAgentTag, FDebuffTag, FBatchedFxTag, FProjectileTag, FLootTag, FHostControllerTag, FObstacleTag> 做类别门,所有 fragment 按 Optional 注册,共享查询包按读写绑定。每个 chunk 在执行期用主类型标签分派到对应类别的哈希与捕获块,因此注册不承担"某类实体 fragment 齐全"的保证——那是组成不变式。注册完成后还会预构建快照布局缓存与哈希布局缓存;开启逐实体哈希诊断时,同时打开 UID 失败闸门与 UID 铸造追踪。

Builds a single network query: anchored on FNetworkTag and gated by Any<FAgentTag, FDebuffTag, FBatchedFxTag, FProjectileTag, FLootTag, FHostControllerTag, FObstacleTag>, with every fragment registered as Optional and both shared query bundles bound for read-write. At execution time each chunk dispatches on its main-type tag into the matching category's hash-and-capture block, so the registration does not guarantee that a category's fragments are complete — that is a composition invariant. After registration it also pre-builds the snapshot-layout and hash-layout caches; when per-entity hash diagnostics are enabled, it arms the UID-failure gate and the UID-mint trace at the same time.

Input
参数Param类型Type说明Description
EntityManagerconst TSharedRef<FMassEntityManager>&实体管理器,用于初始化查询。Entity manager used to initialize the query.
Output

无返回值。副作用:UnifiedNetworkQuery 就绪并绑定;网络子系统的布局缓存被预构建;逐实体哈希诊断开启时,UID 失败闸门与铸造追踪同时打开。

No return value. Side effects: UnifiedNetworkQuery is initialized and bound; the network subsystem's layout caches are pre-built; with per-entity hash diagnostics on, both the UID-failure gate and the mint trace are armed.

Execute virtual void (override)

帧末执行体,只在一个逻辑帧末尾的子帧(ESubFrame::Subtick3)运行。非网络会话在这里短路:不做哈希与快照,只执行一次 UID 映射卫生检查。网络会话中先决定本 tick 是否捕获快照(强制标志或 SnapshotIntervalTicks 周期命中),重置逐 tick 的哈希条目收集器;可选地执行 UID 注册审计(只检测缺口并记录,不修复)与编辑器字段注册审计;随后一条并行 chunk 波按类别折叠每个实体的 FNetworking.EntityHash(注册表字段 + 行为标记位 + 标签,片段间顺序固定),把条目写入哈希收集器,并在需要捕获时写入快照记录(模板 Key、UID 与 fragment 数据块,agent 记录另带标签增量与标记位)。

End-of-frame execute body, run only on the sub-frame at the end of a logic frame (ESubFrame::Subtick3). Non-networked sessions short-circuit here: no hashing and no snapshotting, only one UID-map hygiene check. In a networked session it first decides whether this tick captures a snapshot (a force flag, or the periodic SnapshotIntervalTicks hit) and resets the per-tick hash-entry gatherer; optionally it runs the UID registration audit (detects gaps and logs them, never heals) and the editor field-registration audit; then one parallel chunk wave folds each entity's FNetworking.EntityHash per category (registry fields + behavior flag bits + tags, with a fixed order between fragments), appends entries to the hash gatherer, and — when capture is due — writes a snapshot record (template key, UID and fragment blobs; agent records also carry the tag delta and flag bits).

Input
参数Param类型Type说明Description
EntityManagerFMassEntityManager&实体管理器,提供查询与 fragment 访问。Entity manager providing query and fragment access.
ContextFMassExecutionContext&本处理器查询的执行上下文,含 chunk 实体范围与 archetype 标签。Execution context of this processor's query, carrying the chunk's entity range and archetype tags.
Output

无返回值。副作用:写每个实体的 FNetworking.EntityHash;向网络子系统缓冲逐实体哈希条目与快照记录;审计开启时输出注册缺口日志。

No return value. Side effects: writes each entity's FNetworking.EntityHash; buffers per-entity hash entries and snapshot records in the network subsystem; emits registration-gap logs when the audits are enabled.

成员变量Members

名称Name类型Type默认值Default说明Description
UnifiedNetworkQueryFMassEntityQuery—唯一查询(私有):哈希与快照波、UID 注册审计共用同一匹配集;配置见 ConfigureQueries。The single query (private): the hash-and-capture wave and the UID registration audit share the same match set; configured in ConfigureQueries.
私有头文件方法Private Header Methods
名称Name签名Signature说明Description
AuditFieldRegistrationvoid (FMassEntityManager&, FMassExecutionContext&, UMassBattleSubsystem&, UMassBattleNetworkSubsystem&)仅编辑器编译;按 FieldAuditIntervalTicks 节流的串行审计:每个 chunk 取一个代表实体,对照注册表报告 fragment 级与 UPROPERTY 字段级的静态注册缺口;只诊断,不修复。Editor-only; a serial audit throttled by FieldAuditIntervalTicks: it takes one representative entity per chunk and reports fragment-level and UPROPERTY-field-level static registration gaps against the registry; diagnostics only, never heals.

管线角色Pipeline Role

位置:逻辑帧最后一个子帧(Subtick3)的帧末阶段,游戏线程,Standalone / Server / Client 三态都注册。它遍历查询命中的实体,把逐实体哈希与周期快照交给 UMassBattleNetworkSubsystem——这正是锁步校验与恢复的数据来源。非网络会话在此只做 UID 映射卫生;网络会话中快照节拍由 SnapshotIntervalTicks 与强制标志决定,所有 peer 在同一 tick 捕获。查询覆盖 Agent、Debuff、批量特效、投射物、掉落、宿主控制器与障碍七类主类型;哈希条目在折叠前按 (类别, UID) 归一,快照负载顺序在下游按 UID 排序。

Position: the end-of-frame stage on the last sub-frame of a logic frame (Subtick3), on the game thread, registered for all three modes — Standalone / Server / Client. It walks the entities matched by its query and hands per-entity hashes and periodic snapshots to UMassBattleNetworkSubsystem — the data source behind lockstep validation and recovery. Non-networked sessions only do UID-map hygiene here; in networked sessions snapshot cadence is decided by SnapshotIntervalTicks and the force flags, and all peers capture on the same tick. The query covers seven main types: Agent, Debuff, batched FX, Projectile, Loot, host controller and Obstacle; hash entries are normalized by (category, UID) before folding, and snapshot payload order is sorted by UID downstream.

补充说明Notes

① 审计只检测不修复:UID 注册缺口记录为 [UID_REG_MISS] 错误日志;修复点在缺失注册的生成处,而不是这里——在这里补注册会掩盖真正的缺口。
② 非网络短路:没有锁步消费者时,处理器不做任何哈希或快照工作,只保留 UID 映射卫生。
③ 编辑器审计:字段注册审计只在编辑器构建中存在,并按间隔节流;打包版没有这段代码。
④ 哈希与快照同波:同一个类别块既计算哈希,又在需要时写快照记录,两者读取同一批 fragment 视图。

① Audits detect, never heal: a UID registration gap is logged as an [UID_REG_MISS] error; the fix belongs at the spawn site that missed registration, not here — healing here would hide the real gap.
② Non-networked short-circuit: with no lockstep consumer, the processor does no hash or snapshot work and keeps only UID-map hygiene.
③ Editor audit: the field-registration audit exists only in editor builds and is throttled by an interval; packaged builds compile it out.
④ Hash and capture in one wave: a category block computes the hash and, when due, writes the snapshot record from the same fragment views.