UMassBattleFxRenderProcessor
Source/MassBattle/Public/Processors/MassBattleFxRenderProcessor.h
概述 Overview
FX 渲染处理器,统一处理新 FX 注册与已有 FX 渲染数据更新。并行阶段逐实体把需要注册的 FX(带 FBatchedFxTag)收集进 RegistrationQueue,单线程阶段按确定性 UID 排序后注册进渲染批次槽位;每模拟帧重置槽位状态、执行批次 GC。附加 FX 每帧把 FFxVisualizing 预计算值(HostMonoProcessor 填充)写入批次数组并经 Niagara DataInterface 推送;一次性 Burst FX 聚合到 NDC_BurstFx 数据通道。渲染只跑在 Subtick3 子帧,其它引擎帧跳过(Niagara GPU 自插值)。
FX render processor, unifying new FX registration and existing FX render-data updates. The parallel phase gathers FX needing registration (carrying FBatchedFxTag) into RegistrationQueue; the single-threaded phase sorts by deterministic UID and registers them into render-batch slots. Each sim tick resets slot state and runs batch GC. Attached FX writes pre-computed FFxVisualizing values (filled by HostMonoProcessor) into batch arrays and pushes them via Niagara DataInterface every frame; one-shot Burst FX aggregate into the NDC_BurstFx data channel. Rendering runs only on the Subtick3 sub-frame; other engine ticks skip (Niagara self-interpolates on GPU).
继承 Inheritance
公开方法 Public Methods
构造函数。设置 bAutoRegisterWithProcessingPhases = false(手动派发)、bRequiresGameThreadExecution = true、ExecutionFlags = Standalone | Server | Client。
Constructor. Sets bAutoRegisterWithProcessingPhases = false (manually dispatched), bRequiresGameThreadExecution = true, and ExecutionFlags = Standalone | Server | Client.
Input
无参数。
No parameters.
Output
无返回值。副作用:注册为手动派发、游戏线程专用的处理器。
No return value. Side effect: registers as a manually-dispatched, game-thread-only processor.
初始化实体查询:All<FBatchedFxTag> + All<FSubType, FStyleType, FEntityFlagFragment>(MARO) + All<FFxVisualizing>(MARW)。
Initializes the entity query: All<FBatchedFxTag> + All<FSubType, FStyleType, FEntityFlagFragment>(MARO) + All<FFxVisualizing>(MARW).
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
EntityManager | const TSharedRef<FMassEntityManager> | Mass 实体管理器,查询初始化目标。Mass entity manager; query initialization target. |
Output
无返回值。副作用:EntityQuery 注册进处理器。
No return value. Side effect: EntityQuery registered with the processor.
每 tick 执行入口。取 UMassBattleSubsystem(缺失返回),检查 ESubFrame::Subtick3 子帧门控。流程:① 重置槽位状态(仅模拟帧):对全部渲染批次并行重置 FreeSlotArray / IsHiddenArray / NiagaraID* / NextFreeSlot 游标;② 逐实体更新(并行):跳过休眠 FX(无 Activated);Burst(BurstFx 旗标)每次激活都入注册队列(写 NDC 数据后清 Activated);附加 FX 无有效槽位(InstanceId/RenderBatchId 无效或批次已不存在)时入注册队列;有槽位的每帧原地更新——模拟帧标记槽位占用,每帧从预计算值写变换通道与 GPU 预测输入(父级真值 / 速度 / 角速度 / 插值参数 / 相对变换,ParentGTLoc 近零时回退到 CachedWorldLocation);③ 槽位冷却(仅模拟帧):冷却中的空闲槽位保持占用并递减;④ 注册(仅模拟帧,单线程):Merge() 后按确定性模式以预提取的 UID 键排序(禁止 Entity.Index 键——resync 重建后句柄 Index 与服务器不一致);Burst 追加到任意批的 *_Burst 瞬态数组并清 Activated;附加 FX 按 NextFreeSlot 游标 O(1) 找空闲槽(复用或 Add 扩容),分配全局唯一 (Epoch, Counter) 渲染身份(AllocateFxRenderId,GPU 复用跳变检测),把槽位绑定写回 FFxVisualizing;⑤ 批次 GC(仅模拟帧):空闲批次按 IdleRemoveCountdown 倒计时销毁 Niagara 组件并移除;⑥ Niagara 推送(并行):按新模型(带 Rel 数组,父级+相对 GPU 组合)或旧模型(FX 世界变换直写)推送各数组;⑦ NDC BurstFx(串行):跨批次聚合 burst 数据经 FMassBurstFxWriter 写数据通道并置 EnableBurstFx 变量。
Per-tick entry. Resolves UMassBattleSubsystem (returns early if missing), gated on ESubFrame::Subtick3. Flow: ① slot-state reset (sim tick only): parallel reset of FreeSlotArray / IsHiddenArray / NiagaraID* / NextFreeSlot cursor across all render batches; ② per-entity update (parallel): skip dormant FX (no Activated); Burst (BurstFx flag) enqueues registration on every activation (clears Activated after the NDC write); attached FX with no valid slot (invalid InstanceId/RenderBatchId or missing batch) enqueues registration; slotted FX updates in place every frame — sim tick marks the slot occupied, every frame writes transform channels and GPU-prediction inputs from pre-computed values (parent ground truth / velocity / angular velocity / interp params / relative transform; ParentGTLoc near-zero falls back to CachedWorldLocation); ③ slot cooldown (sim tick only): cooling free slots stay occupied and decrement; ④ registration (sim tick only, single-threaded): after Merge(), sorts by pre-extracted UID keys in deterministic mode (no Entity.Index keys — handle indexes diverge after resync rebuild); Burst appends to any batch's transient *_Burst arrays and clears Activated; attached FX finds a free slot O(1) via the NextFreeSlot cursor (reuse or Add grow), allocates a globally-unique (Epoch, Counter) render identity (AllocateFxRenderId, GPU snap-on-reuse detection), and writes the slot binding back to FFxVisualizing; ⑤ batch GC (sim tick only): idle batches count down IdleRemoveCountdown, then destroy the Niagara component and remove the batch; ⑥ Niagara push (parallel): new model (with Rel arrays — parent + relative GPU compose) or old model (FX world transform direct) per batch; ⑦ NDC BurstFx (serial): aggregates burst data across batches via FMassBurstFxWriter and sets the EnableBurstFx variable.
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
EntityManager | FMassEntityManager& | 实体管理器。Entity manager. |
Context | FMassExecutionContext& | 执行上下文,提供 fragment 视图与实体遍历。Execution context providing fragment views and entity iteration. |
Output
无返回值。副作用:写渲染批次的全部槽位数组;写 FFxVisualizing 的槽位绑定(InstanceId/RenderBatchId/RendererActor/NiagaraIdIndex/NiagaraAcquireTag);清 Burst 实体的 Activated 旗标;向 Niagara 组件与 NDC_BurstFx 数据通道推送数据;销毁并移除空闲批次。
No return value. Side effects: writes all slot arrays of render batches; writes FFxVisualizing slot bindings (InstanceId/RenderBatchId/RendererActor/NiagaraIdIndex/NiagaraAcquireTag); clears Activated on Burst entities; pushes data to Niagara components and the NDC_BurstFx data channel; destroys and removes idle batches.
成员变量 Members
通过 NDC 批量写入 Burst FX 的自定义 Writer(FNDCWriterBase 派生)。成员为各通道的 FNiagaraDataChannelVariableBuffer 指针(BurstPosition / BurstLocation / BurstOrientation / BurstScale / SubType / Style),LWC 精度由变量字节大小自动检测(bLocationIsLWC 等)。InitBuffers() 按名查找缓冲;带 LWC 标志的通道在 AppendBatch 中做 FVector↔FVector3f 精度转换后批量 memcpy。
Custom writer for bulk Burst FX via NDC (derived from FNDCWriterBase). Members are FNiagaraDataChannelVariableBuffer pointers per channel (BurstPosition / BurstLocation / BurstOrientation / BurstScale / SubType / Style); LWC precision is auto-detected from variable byte sizes (bLocationIsLWC etc.). InitBuffers() resolves buffers by name; LWC-flagged channels convert FVector↔FVector3f in AppendBatch before bulk memcpy.
Stage 1 并行段预提取的注册数据,使单线程 Stage 3 循环免于逐实体 GetFragmentRef 查找。字段:Entity(实体句柄)、SubTypeIndex / StyleTypeIndex(渲染器键)、Location / RotationQuat / Scale(世界变换,来自 FFxVisualizing.CachedWorld*)、bBurst(true = 一次性 burst 瞬态批;false = 附加池化 FX)。
Registration data pre-extracted in the Stage 1 parallel pass so the single-threaded Stage 3 loop avoids per-entity GetFragmentRef lookups. Fields: Entity, SubTypeIndex / StyleTypeIndex (renderer keys), Location / RotationQuat / Scale (world transform from FFxVisualizing.CachedWorld*), bBurst (true = one-shot burst transient batch; false = attached pooled FX).
并行段收集的注册请求,单线程注册阶段 Merge + 排序 + 排空。
Registration requests gathered in parallel; merged, sorted, and drained in the single-threaded registration phase.
渲染专用 FX 身份分配器。FX 实体及其宿主均池化,任何派生自它们的 id 在多次激活间重复,无法在 GPU 检测池复用——本分配器在槽位获取时发放不重复的 (Epoch, Counter) 对(计数器溢出时 Epoch 递增)。本处理器是所有渲染器/批次 FX 注册的唯一漏斗,故成员计数器全局唯一。仅游戏线程调用,无需原子操作。
Render-only FX identity allocator. FX entities and their hosts are pooled, so any id derived from them repeats across activations and can't detect pool reuse on the GPU — this allocator hands out a never-repeating (Epoch, Counter) pair at slot acquisition (counter overflow bumps the epoch). This processor is the single funnel for all FX registration, so the member counter is globally unique. Game-thread only; no atomics needed.
管线角色 Pipeline Role
注册于 UMassBattleSubsystem 的 RenderProcessors 组(帧末排空之后运行,旧 FrameEnd 位置),与 UMassBattleAgentRenderProcessor 并列。只在 Subtick3 子帧渲染;渲染实体由 UMassBattleHostMonoProcessor 激活配对 FX 实体(或池耗尽 fallback 的 FxEntitySpawns 串行生成),本处理器消费 FFxVisualizing 预计算值并写渲染批次;批次 Niagara 组件由 AddRenderBatch 创建(AMassBattleFxRenderer 持有)。
Registered in UMassBattleSubsystem's RenderProcessors group (runs after the end-of-frame drain — the old FrameEnd position), alongside UMassBattleAgentRenderProcessor. Renders only on the Subtick3 sub-frame. Render entities are activated by UMassBattleHostMonoProcessor (paired FX entity, or serial FxEntitySpawns fallback when the pool is exhausted); this processor consumes pre-computed FFxVisualizing values and writes render batches; batch Niagara components are created by AddRenderBatch (owned by AMassBattleFxRenderer).