Mass Battle Frameworkv1.20.0

UMassBattleHostMonoProcessor

UCLASS Processor AUTO-DRIVEN · NO SETUP

Source/MassBattle/Public/Processors/MassBattleHostMonoProcessor.h

概述Overview

宿主生命周期处理器:驱动 Actor/特效/音效宿主的生成、回收与闲置销毁。宿主之间构成父子链,子宿主的世界帧由链根一次遍历派生。由插件自动调度;宿主的资产、闲置寿命等在各类 HostConfig 上配置。

The host-lifetime processor: drives spawning, recycling and idle destruction of actor / FX / sound hosts. Hosts form parent-child chains, and a child's world frame is derived in a single pass by its chain root. Auto-scheduled; host assets and idle lifetimes are configured on the HostConfig entries.

继承Inheritance

UMassProcessor → UMassBattleHostMonoProcessor

结构体 FCpuInterpUObjectOpStruct FCpuInterpUObjectOp

FCpuInterpUObjectOp

并行插值段收集、游戏线程串行应用的 UObject 变换操作。SetActorTransform / SetWorldTransform / SetWorldLocationAndRotation 都是 UObject 调用,只能在游戏线程执行,所以分块内只记录操作,分块结束后统一落地。

A UObject transform operation collected during the parallel interp pass and applied serially on the game thread. SetActorTransform / SetWorldTransform / SetWorldLocationAndRotation are UObject calls that may only run on the game thread, so the chunk pass records the operation and the application happens after it.

成员变量Members
名称Name类型Type默认值Default说明Description
EntityFMassEntityHandle—宿主实体。The host entity.
Typeuint80目标类型:0 = Actor,1 = 音效,2 = 未批处理的特效。Target kind: 0 = actor, 1 = sound, 2 = unbatched FX.
WorldXfFTransform—要应用到目标上的世界变换。World transform to apply to the target.

结构体 FChainChildOpStruct FChainChildOp

FChainChildOp

链式宿主的一次破坏性决定:把子宿主从父宿主上解除挂接,或让子宿主进入销毁。两者都不能在父宿主所在的分块里直接写子宿主——那会与子宿主自己的分块竞争——所以并行段只收集,串行尾段统一执行。

One destructive decision for a chain child: unlink it from its parent, or send it into destruction. Neither may be written from the parent's chunk — that would race the child's own chunk — so the parallel pass only collects and the serial tail executes.

成员变量Members
名称Name类型Type默认值Default说明Description
ParentFEntityHandle—操作所归属的父宿主。The parent host the operation belongs to.
ChildFEntityHandle—要解除或销毁的子宿主。The child host to unlink or destroy.

结构体 FHitReactionUpCandidateStruct FHitReactionUpCandidate

FHitReactionUpCandidate

子宿主把受击反馈上递父宿主的候选。并行段按宿主记录收集,确定性模式下尾段按 (ParentUID, ChildUID) 排序,再逐个候选触发父宿主的受击序列——同一父下的多个子宿主不会并发写父宿主的受击状态。

A candidate for a child host to share its hit feedback upward with its parent. The parallel pass collects them per host record; in deterministic mode the tail sorts by (ParentUID, ChildUID) and then starts the parent's hit sequence per candidate — several children under one parent never race on the parent's hit state.

成员变量Members
名称Name类型Type默认值Default说明Description
ParentFEntityHandle—接收受击反馈的父宿主。The parent host that receives the hit feedback.
ChildFEntityHandle—报告受击的子宿主。The child host reporting the hit.
ParentUIDint32-1父宿主的 UID 镜像,排序键;句柄下标不保证跨端一致,所以不用它排序。UID mirror of the parent, used as the sort key; handle indices are not guaranteed to agree across peers, so they are not used for ordering.
ChildUIDint32-1子宿主的 UID 镜像,排序元组第二键。UID mirror of the child, second sort key.

结构体 FChildTargetCandidateStruct FChildTargetCandidate

FChildTargetCandidate

子宿主的有效目标作为父宿主采纳候选上送。尾段按父分组,在二维距离上取最近的一个写给父宿主,重复的父候选因此不会互相覆盖。

A child host's valid target submitted as an adoption candidate for its parent. The tail groups by parent and writes the nearest candidate in 2D distance onto the parent, so repeated candidates for one parent never overwrite each other.

成员变量Members
名称Name类型Type默认值Default说明Description
ParentFEntityHandle—候选目标的目标父宿主。The parent host that may adopt the target.
ChildFEntityHandle—携带该目标的子宿主。The child host carrying the target.
ParentUIDint32-1父宿主的 UID 镜像,排序键。UID mirror of the parent, used as the sort key.
ChildUIDint32-1子宿主的 UID 镜像,排序元组第二键。UID mirror of the child, second sort key.

结构体 FDeathBindCandidateStruct FDeathBindCandidate

FDeathBindCandidate

死亡联动命中:Down 方向下目标侧随触发侧一起死亡,Up 方向反过来。并行段只收集,尾段在串行上下文里构造完整死亡转移(血量归零、FDying、DyingFlag、延迟标签,以及按目标事件开关发死亡事件)。

A death-reaction hit: on the Down direction the target dies with the instigator, on Up it is the other way round. The parallel pass only collects; the tail builds the full death transition in serial context (health to zero, FDying, DyingFlag, the deferred tag, and the death event gated by the target's own event switch).

成员变量Members
名称Name类型Type默认值Default说明Description
TargetFEntityHandle—要死的一侧。The side that dies.
InstigatorFEntityHandle—死亡触发的一侧。The side whose death triggers it.
TargetUIDint32-1目标侧 UID 镜像,排序键。UID mirror of the target, used as the sort key.
InstigatorUIDint32-1触发侧 UID 镜像,排序元组第二键。UID mirror of the instigator, second sort key.

方法Methods

UMassBattleHostMonoProcessor UMassBattleHostMonoProcessor()

构造函数。把处理器从 Mass 自动处理阶段注册中摘出,要求游戏线程执行,并把执行环境打开为 Standalone / Server / Client。

Constructor. Removes the processor from the automatic Mass processing-phase registration, requires game-thread execution, and enables the Standalone / Server / Client execution environments.

Input

无参数。

No parameters.

Output

无返回值。副作用:写入 bAutoRegisterWithProcessingPhases = false、bRequiresGameThreadExecution = true 与三端 ExecutionFlags,供调度层读取。

No return value. Side effect: sets bAutoRegisterWithProcessingPhases = false, bRequiresGameThreadExecution = true and the three-environment ExecutionFlags for the scheduler to read.

TickCpuInterp void

每引擎帧的 CPU 插值入口,由子系统 Tick 直接调用,不经过处理器的执行分发。先用 CpuInterpQuery.HasMatchingEntities() 做一次原型探测,没有 CPU 插值宿主就直接返回;通过后复位成员 gatherer,在并行分块里按 FHostHierarchy 解析出的真值、速度与插值参数推进 InterpState,再按宿主类型分发:已挂载的批处理特效把结果写进 FFxVisualizing 与渲染批数组并置脏标记,未批处理的特效、Actor 与音效则收集成 UObject 变换操作。分块结束后串行落地——脏批推给 Niagara 数组设置器,UObject 变换在游戏线程应用;整个过程只写渲染数据,不回写模拟 fragment。

CPU-interp entry for every engine frame, called directly from the subsystem tick rather than through processor dispatch. A single archetype probe (CpuInterpQuery.HasMatchingEntities()) returns early when no CPU-interp host exists; otherwise the member gatherer is reset, the parallel chunk pass advances InterpState from the resolved ground truth, velocity and interp parameters on FHostHierarchy, and dispatch follows the host type: attached batched FX write the result into FFxVisualizing and the render batch arrays and set a dirty flag, while unbatched FX, actors and sounds are collected as UObject transform operations. After the pass everything lands serially — dirty batches are pushed through the Niagara array setters and UObject transforms are applied on the game thread; the whole function writes render data only and never writes back into simulation fragments.

Input
参数Param类型Type说明Description
EngineDeltaTimefloat引擎帧步长(秒);小于 KINDA_SMALL_NUMBER 时按 0.001 处理。Engine frame delta in seconds; clamped to 0.001 when below KINDA_SMALL_NUMBER.
Output

无返回值。副作用:写 FFxVisualizing 的世界缓存、渲染批数组、Niagara 数组与 UObject 变换;不改变模拟状态。

No return value. Side effects: writes FFxVisualizing world caches, render batch arrays, Niagara arrays and UObject transforms; simulation state is untouched.

ConfigureQueries virtual void (override)

建立两条查询。主查询用 Any 合并六种宿主配置 fragment(读写),要求 FHostHierarchy(读写),可选 FAttaching(读写)与 FTracingShared(只读);关系 fragment 声明为可选,是为了让缺少它的宿主在执行入口的守卫处显式失败,而不是索引空视图。CPU 插值查询单独初始化为轻量查询:要求 FCpuInterpTag 与 FHostHierarchy,可选三种配置(只读);它不向处理器注册,由 TickCpuInterp 在处理器执行之外直接使用。

Builds two queries. The main query merges the six host config fragments with Any (read-write), requires FHostHierarchy (read-write), and declares FAttaching (read-write) and FTracingShared (read-only) as optional; the relation fragment is optional so that a host missing it fails loudly at the execution guard instead of indexing an empty view. The CPU-interp query is initialized separately as a lightweight query: it requires FCpuInterpTag and FHostHierarchy and optionally the three config fragments (read-only); it is not registered with the processor and is used directly by TickCpuInterp outside processor execution.

Input
参数Param类型Type说明Description
EntityManagerconst TSharedRef<FMassEntityManager>&实体管理器,两条查询都以它初始化。Entity manager both queries initialize against.
Output

无返回值。副作用:主查询向本处理器注册(RegisterWithProcessor);CPU 插值查询保持独立,只由本类的插值入口使用。

No return value. Side effect: the main query is registered with this processor (RegisterWithProcessor); the CPU-interp query stays standalone and is used only by this class's interp entry.

Execute virtual void (override)

每帧入口。先取世界并确认有效,再做战斗子系统存在与 ESubFrame::Subtick3 调度门;通过后取步长、宿主与 Mass API / 弹道子系统,以及池闲置寿命。串行头段在游戏线程采样组件锚点(USceneComponent::GetSocketTransform 不能在工作线程调用),写入 FAttaching.ResolvedTarget,锚点已销毁则解除关系。主循环是并行的分块遍历:链式宿主里只有根会被处理,根按挂接来源解析自己的世界帧,再按配置类型(Actor / 特效 / 音效 / 弹道 / 挂载 agent / 掉落)执行池化计数、挂接更新、寿命与父体消失处理、首次生成与概率判定,并把 UObject 操作、生成与回收请求收集进线程本地列表,遍历结束后并入宿主子系统队列;根的生命周期走完后还会遍历整条子树。分块之后是串行尾段:先解除链式子宿主的挂接再标记销毁,然后合并三类跨实体候选——受击上递、死亡联动、子目标采纳——确定性模式下按 UID 排序后逐父或逐目标应用。

Per-frame entry. It resolves a valid world, gates on the battle subsystem and a scheduled ESubFrame::Subtick3, then takes the step, the host and Mass API / projectile subsystems, and the pool idle lifetime. The serial head samples component anchors on the game thread (USceneComponent::GetSocketTransform may not run on a worker) into FAttaching.ResolvedTarget and clears the relation when the anchor is gone. The main loop is a parallel chunk pass: only roots are processed, each root resolves its own world frame from its attachment source, then runs the per-type work (actor / FX / sound / projectile / mounted agent / loot) — pool countdown, attachment update, lifespan and parent-gone handling, first spawn and spawn probability — collecting UObject operations and spawn/recycle requests into thread-local lists that are appended to the host subsystem queues after the walk; once a root's own lifecycle completes it walks its whole subtree. A serial tail follows: chain children are unlinked before being marked for destruction, then the three cross-entity candidate sets — hit-reaction up, death binding, child target adoption — are merged and, in deterministic mode, sorted by UID before being applied per parent or per target.

Input
参数Param类型Type说明Description
EntityManagerFMassEntityManager&实体管理器。Entity manager.
ContextFMassExecutionContext&本帧执行上下文;世界、分块遍历与延迟命令都经由它。Execution context for this frame; the world, the chunk walk and deferred commands go through it.
Output

无返回值。副作用:写宿主配置的运行时状态与 FHostHierarchy 解析帧;同步配对特效实体的位置、旋转与缩放;把 Actor/特效/音效/弹道/掉落操作与回收请求追加进宿主子系统队列;解除或标记链式子宿主;触发父宿主受击、构造死亡联动转移、把最近的子目标写给父宿主;宿主记录被销毁时连带销毁被挂载的 agent。

No return value. Side effects: it writes the host configs' runtime state and the resolved frames on FHostHierarchy; synchronises paired FX entity location, rotation and scale; appends actor / FX / sound / projectile / loot operations and recycle requests to the host subsystem queues; unlinks or marks chain children; triggers parent hit reactions, builds death-binding transitions and writes the nearest child target onto the parent; and destroys a mounted agent when its host record is destroyed.

常量Constants

七个 static constexpr 私有缓存值,把战斗标志枚举预先转换成 EEntityFlags,让每帧密集的标志读写跳过重复转换。它们不对外暴露,也没有配置项。

Seven private static constexpr cached values that convert the battle flag enumerators to EEntityFlags ahead of time, so the dense per-frame flag traffic skips the conversion. They are not exposed and have no configuration.

名称Name值Value说明Description
ActivatedFlagstatic_cast<EEntityFlags>(EBattleFlags::Activated)父体存活判据:外部父体失去该标志即视为父体消失。Parent-alive test: an external parent that loses this flag counts as gone.
HitGlowFlagstatic_cast<EEntityFlags>(EBattleFlags::HitGlow)受击反馈三段之一;上下两个共享方向都用这三个标志判断反馈是否活跃。One of the three hit-feedback flags; both sharing directions read all three to tell whether feedback is active.
HitJiggleFlagstatic_cast<EEntityFlags>(EBattleFlags::HitJiggle)受击反馈三段之一(抖动),用途同上。One of the three hit-feedback flags (jiggle), used the same way.
HitAnimFlagstatic_cast<EEntityFlags>(EBattleFlags::HitAnim)受击反馈三段之一(受击动画),用途同上。One of the three hit-feedback flags (hit animation), used the same way.
BurstFxFlagstatic_cast<EEntityFlags>(EBattleFlags::BurstFx)配对特效实体走一次性爆发渲染而不是挂接渲染;非挂接宿主激活时置位,挂接时清除。Selects one-shot burst rendering instead of attached rendering for the paired FX entity; raised for an unattached host on activation and cleared when attached.
PendingDestroyFlagstatic_cast<EEntityFlags>(EBattleFlags::PendingDestroy)已排队销毁的实体;挂载 agent 随记录销毁时由本类置位。Entities already queued for destruction; this class raises it on a mounted agent when its record is destroyed.
DyingFlagstatic_cast<EEntityFlags>(EBattleFlags::Dying)死亡联动判据:父体带该标志产生 Down 子死亡候选,子体带则产生 Up 父死亡候选。Death-binding test: a parent carrying it yields a Down child-death candidate, a child carrying it yields an Up parent-death candidate.

成员变量Members

名称Name类型Type说明Description
EntityQueryFMassEntityQuery私有。主查询:六种宿主配置任取其一,要求 FHostHierarchy,可选关系与追踪共享 bundle。Private. The main query: any one of the six host configs, FHostHierarchy required, the relation and tracing shared bundle optional.
CpuInterpQueryFMassEntityQuery私有。CPU 插值专用轻量查询:要求 FCpuInterpTag 与 FHostHierarchy,不经过处理器的执行分发。Private. Lightweight CPU-interp query: requires FCpuInterpTag and FHostHierarchy and is not driven by processor dispatch.
CpuInterpUObjectOpsFParallelGatherer<FCpuInterpUObjectOp>私有。每帧收集、串行应用的 UObject 变换操作。作为成员而不是局部量:gatherer 的线程本地缓存按实例地址索引,栈上临时量被复用时会产生假命中与空的合并结果。Private. UObject transform operations collected per frame and applied serially. It is a member rather than a local because the gatherer's thread-local cache keys on the instance address, and a stack local reused across frames yields false cache hits and an empty merge.
ChildTargetCandidatesFParallelGatherer<FChildTargetCandidate>私有。子目标采纳候选,并行收集、尾段按父取最近。Private. Child-target adoption candidates, collected in parallel and reduced to the nearest per parent in the tail.
HitReactionUpCandidatesFParallelGatherer<FHitReactionUpCandidate>私有。受击反馈上递候选,并行收集、尾段按父触发。Private. Hit-feedback-up candidates, collected in parallel and triggered per parent in the tail.
ChainChildUnlinkOpsFParallelGatherer<FChainChildOp>私有。链式子宿主的解除挂接决定,尾段最先执行。Private. Unlink decisions for chain children, executed first in the tail.
ChainChildDestroyOpsFParallelGatherer<FChainChildOp>私有。链式子宿主的销毁决定,尾段在解除之后统一标记。Private. Destroy decisions for chain children, marked after the unlink pass in the tail.
DeathBindCandidatesFParallelGatherer<FDeathBindCandidate>私有。死亡联动命中,尾段构造完整死亡转移。Private. Death-binding hits; the tail builds the full death transition.

私有方法Private Methods

名称Name签名Signature说明Description
ResolveAndWriteAttachedAgentvoid (UMassAPISubsystem& MA, const FMassEntityHandle& HostEntity, FAgentHostConfigRT& Config, const FTransform& ParentWorld, float DeltaTime)解析并写回被挂载 agent 的变换:挂点相对变换乘以父世界帧写入 FLocating / FRotating(先保存上一帧位置与朝向),按 EYawMode 组合朝向,把挂点的刚体速度写进 FMoving.CurrentVelocity 并置 bComponentDrivenPosition;同时处理目标共享与受击/死亡联动候选的收集。Resolves and writes back a mounted agent's transform: the mount-relative transform times the parent world frame goes into FLocating / FRotating (after saving the previous frame's location and facing), facing is composed per EYawMode, the mount's rigid-body velocity is published into FMoving.CurrentVelocity with bComponentDrivenPosition set, and target sharing plus hit/death candidate collection are handled.

管线角色Pipeline Role

调度形态:构造函数关闭 Mass 自动处理阶段注册,执行限定在游戏线程,实际运行发生在 ESubFrame::Subtick3 被调度的帧——此时完整移动阶段已在前两个子帧完成,本处理器发出的操作携带本逻辑帧的最终实体变换,并排在掉落与渲染消费之前。主循环是并行的自动负载均衡分块遍历,组件锚点采样则被单独放在它之前的串行头段,因为组件查询只能在游戏线程调用。分块之后是串行尾段:链式解除与销毁、受击上递、死亡联动、子目标采纳都在这里落地,这些写入若留在并行段就会与其它分块竞争。另有一个不经过处理器分发的入口 TickCpuInterp,由子系统 Tick 每引擎帧调用,只写渲染数据。

Scheduling: the constructor disables automatic Mass processing-phase registration, execution is limited to the game thread, and the processor runs on frames where ESubFrame::Subtick3 is scheduled — by then the full move phase has completed on the earlier sub-frames, so the operations it emits carry this logic frame's final entity transforms and are ordered before loot and render consumption. The main loop is a parallel auto-balanced chunk pass, while component-anchor sampling is isolated in a serial head before it because component queries may only run on the game thread. A serial tail follows the pass: chain unlink and destroy, hit-reaction up, death binding and child-target adoption all land there, since those writes would race other chunks if left in the parallel section. A separate entry, TickCpuInterp, bypasses processor dispatch entirely and is called from the subsystem tick every engine frame, writing render data only.

补充说明Notes

① 所有权规则:宿主链在链内串行、跨链并行——根在自己的分块里走完整条子树,子宿主的 fragment 只由根的这次遍历写,因此两个分块不会触碰同一实体;主循环里遇到链式子宿主直接跳过。
② 宿主原型不变式:每个宿主从出生起就带 FAttaching(默认禁用),缺少它的分块在守卫处显式失败;关系启用期间,FAttaching.ParentEntity 必须与 FHostHierarchy.AttachmentEntity 一致。
③ 父体消失按配置二选一:级联销毁或解除关系转成世界锚点根。视觉类宿主(Actor/特效/音效)的根推迟一 tick 销毁,以便渲染移除帧;弹道与掉落宿主同帧销毁。池化宿主按池闲置寿命倒计时,闲置到期即销毁;宿主记录被销毁时,被挂载的 agent 一起走标准销毁路径,不额外发死亡事件或掉落。

① Ownership rule: a host chain is serial within itself and parallel across chains — the root walks its whole subtree inside its own chunk and is the only writer of its children's fragments, so two chunks never touch the same entity; the main loop skips chain children outright.
② Host archetype invariant: every host carries FAttaching (disabled by default) from birth, a chunk missing it fails loudly at the guard, and while the relation is enabled FAttaching.ParentEntity must agree with FHostHierarchy.AttachmentEntity.
③ Parent-gone follows the configured policy: cascade destruction or unlink into a world-anchor root. The visual host kinds (actor / FX / sound) defer the root's destroy by one tick so the removal frame can render, while projectile and loot hosts destroy in the same frame. Pooled hosts count down their pool idle lifetime and are destroyed when it expires; when a host record is destroyed, the mounted agent takes the standard destruction path with no extra death event or loot.