Mass Battle Frameworkv1.20.0

UMassBattleFxRenderProcessor

UCLASS Processor AUTO-DRIVEN · NO SETUP

Source/MassBattle/Public/Processors/MassBattleFxRenderProcessor.h

概述Overview

特效批次处理器:把爆发/附着特效的目标数据交给 特效渲染器。由插件自动调度;特效资产与生命周期在 FxHostConfig / 事件配置里指定。

The FX-batch processor: hands burst / attached-FX targets to the FX renderer. Auto-scheduled; FX assets and lifetimes are set in FxHostConfig / event configs.

继承Inheritance

UMassProcessor → UMassBattleFxRenderProcessor

结构体 FMassBurstFxWriterStruct FMassBurstFxWriter

面向 Niagara 数据通道的批量爆发特效写入器,派生自 FNDCWriterBase。它把一帧内各批次累积的爆发特效位置、朝向、缩放、样式与子类型写进渲染器指定的数据通道,并按通道布局的元素宽度在双精度与单精度之间转换。处理器在串行阶段用它完成爆发特效的跨批次合并写入。

Bulk burst-FX writer for a Niagara data channel, derived from FNDCWriterBase. It writes the burst-FX positions, orientations, scales, styles and sub-types accumulated by each batch into the data channel named by the renderer, converting between double and single precision according to the element widths of the channel layout. The processor uses it in its serial step to merge and write burst FX across batches.

成员变量Members
名称Name类型Type默认值Default说明Description
PositionBufferFNiagaraDataChannelVariableBuffer*—通道变量 BurstPosition 的缓冲区,InitBuffers 之后才有效;变量不存在时为空。Buffer for the BurstPosition channel variable; valid only after InitBuffers, null when the variable is absent.
LocationBufferFNiagaraDataChannelVariableBuffer*—通道变量 BurstLocation 的缓冲区。Buffer for the BurstLocation channel variable.
OrientationBufferFNiagaraDataChannelVariableBuffer*—通道变量 BurstOrientation 的缓冲区。Buffer for the BurstOrientation channel variable.
ScaleBufferFNiagaraDataChannelVariableBuffer*—通道变量 BurstScale 的缓冲区。Buffer for the BurstScale channel variable.
SubTypeBufferFNiagaraDataChannelVariableBuffer*—通道变量 SubType 的缓冲区;每个元素写入同一个子类型值。Buffer for the SubType channel variable; every element receives the same sub-type value.
StyleBufferFNiagaraDataChannelVariableBuffer*—通道变量 Style 的缓冲区,逐元素写入样式索引。Buffer for the Style channel variable, receiving one style index per element.
bLocationIsLWCboolfalse位置变量的元素宽度等于 FVector(双精度)时为 true;否则按 FVector3f 写入。True when the location variable's element width equals FVector (double precision); otherwise values are written as FVector3f.
bOrientationIsLWCboolfalse朝向变量的元素宽度等于 FQuat(双精度)时为 true;否则按 FQuat4f 写入。True when the orientation variable's element width equals FQuat (double precision); otherwise values are written as FQuat4f.
bScaleIsLWCboolfalse缩放变量的元素宽度等于 FVector(双精度)时为 true;否则按 FVector3f 写入。True when the scale variable's element width equals FVector (double precision); otherwise values are written as FVector3f.
方法Methods
InitBuffers void

按名字从数据通道的游戏数据布局中解析六个变量缓冲区,并记录三个变换变量是否为双精度宽度。同一时间只服务一次写入:由 BeginWrite 成功之后调用,写入结束即失效。

Resolves the six variable buffers from the data channel's game-data layout by name and records whether each of the three transform variables is double-precision. It serves a single write: call it after a successful BeginWrite, and it becomes stale once that write ends.

Input

无参数。

No parameters.

Output

无返回值。副作用:填充六个缓冲区指针与三个 b*IsLWC 标记;布局中不存在的变量保持空指针。

No return value. Side effects: fills the six buffer pointers and the three b*IsLWC flags; variables absent from the layout stay null.

AppendBatch void

把一批爆发特效数据整体写入缓冲区:写入起点是基类的 StartIndex 加上 WriteOffset,因此同一帧内的多个批次可以连续追加而互不覆盖。每个缓冲区都先做容量检查,元素宽度不匹配时临时转换;子类型缓冲区对每个元素写入同一个值。

Bulk-writes one batch of burst FX into the buffers: the write origin is the base class's StartIndex plus WriteOffset, so multiple batches in the same frame append without clobbering each other. Every buffer is capacity-checked first, values are converted when the element width differs, and the sub-type buffer receives the same value for every element.

Input
参数Param类型Type说明Description
WriteOffsetint32本批次首个元素在本次写入中的偏移,相对基类起点。Offset of this batch's first element within the write, relative to the base-class origin.
LocsTConstArrayView<FVector>世界位置数组,元素数即本批次数量。World locations; the element count is the batch size.
RotsTConstArrayView<FQuat4f>朝向数组,与位置一一对应。Orientations, one per location.
ScalesTConstArrayView<FVector3f>缩放数组,与位置一一对应。Scales, one per location.
StylesTConstArrayView<int32>样式索引数组,与位置一一对应。Style indices, one per location.
SubTypeValint32写入子类型缓冲区的值,整批相同。Value written to the sub-type buffer, identical for the whole batch.
Output

无返回值。副作用:改写数据通道缓冲区内存;批次为空时立即返回,缓冲区容量不足时该数组跳过。

No return value. Side effects: mutates the data-channel buffer memory; returns immediately for an empty batch and skips any array whose buffer lacks capacity.

结构体 FFxRegistrationStruct FFxRegistration

处理器内部的逐实体注册记录。并行段把需要注册的特效连同采集时刻的变换快照写进线程本地槽,仿真 tick 的串行阶段再按记录分配批次与池化槽。它只承载注册所需的数据,不进入快照或哈希。

Per-entity registration record internal to the processor. The parallel phase appends FX that need registration — together with a transform snapshot taken at collection time — into thread-local slots; the serial sim-tick step then allocates batches and pooled slots from those records. It carries only the data registration needs and enters neither snapshots nor hashes.

成员变量Members
名称Name类型Type默认值Default说明Description
EntityFMassEntityHandle—要注册的特效实体;串行阶段据此读 FFxVisualizing 并写回槽绑定。FX entity to register; the serial phase reads its FFxVisualizing and writes the slot binding back.
SubTypeIndexint320子类型索引,用于在战斗子系统的渲染器表中找到对应渲染器。Sub-type index used to look up the matching renderer in the combat subsystem's renderer table.
StyleTypeIndexint320样式索引,写入批次的样式数组。Style index written into the batch's style array.
LocationFVectorFVector::ZeroVector注册位置:爆发特效取事件锚点(有则用事件时刻的位置),否则取缓存的世界位置。Registration location: bursts prefer the event anchor when present, otherwise the cached world location.
RotationQuatFQuat4fFQuat4f::Identity注册朝向,来源与位置相同(事件锚点优先)。Registration orientation from the same source as the location (event anchor first).
Scalefloat1.f均匀缩放,取缓存世界缩放的 X 分量。Uniform scale, taken from the X component of the cached world scale.
bBurstboolfalsetrue = 一次性爆发特效(写入瞬态数组后即清除激活位);false = 附着在宿主上的池化特效。true = one-shot burst FX (appended to transient arrays, then its activation flag is cleared); false = pooled FX attached to a host.

公开方法Public Methods

UMassBattleFxRenderProcessor 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 — it runs in standalone, on dedicated servers and on clients, while the execute body decides whether render data is actually produced.

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)

初始化主查询并注册到本处理器:匹配带 FBatchedFxTag 的实体,读取 FSubType、FStyleType 与 FEntityFlagFragment,并对 FFxVisualizing 申请读写权限——串行注册阶段要把槽绑定写回该 fragment。

Initializes the main query and registers it with this processor: it matches entities carrying FBatchedFxTag, reads FSubType, FStyleType and FEntityFlagFragment, and requests read-write access to FFxVisualizing — the serial registration step writes the slot binding back into that fragment.

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

无返回值。副作用:EntityQuery 就绪并绑定到本处理器。

No return value. Side effect: EntityQuery is initialized and bound to this processor.

Execute virtual void (override)

每帧执行体,只在一个逻辑帧末尾的渲染子帧(ESubFrame::Subtick3)运行,其它引擎 tick 直接跳过。执行分三段:仿真 tick 上先并行重置各渲染批次的空闲槽与绑定数组;随后以并行 chunk 波遍历查询实体——休眠的池化特效跳过,爆发特效与尚未绑定槽的附着特效收集成注册记录,已绑定的附着特效就地更新世界变换与父级预测输入(CPU 插值槽的变换数组由插值阶段独占,这里跳过),并同步武器动画行;最后在仿真 tick 上串行排空注册队列,为附着特效分配池化槽与全局唯一的渲染身份,把绑定写回 FFxVisualizing,回收空闲批次,再并行把各批次数组推送给 Niagara 并串行写入爆发特效数据通道。专用服务器上只保留爆发特效的激活位清除这一仿真可见副作用,不创建任何 Niagara 批次。

Per-frame execute body, run only on the render sub-frame at the end of a logic frame (ESubFrame::Subtick3); other engine ticks skip it. It runs in three steps: on sim ticks it first resets every render batch's free slots and binding arrays in parallel; then a parallel chunk wave walks the query — dormant pooled FX are skipped, bursts and attached FX without a slot are collected as registration records, and bound attached FX update their world transform and parent-prediction inputs in place (CPU-interpolated slots keep those arrays owned by the interpolation stage and are skipped here) and sync their weapon animation rows; finally, on sim ticks, the registration queue is drained serially, assigning pooled slots and a globally unique render identity to attached FX, writing the binding back into FFxVisualizing, reclaiming idle batches, then pushing each batch's arrays to Niagara in parallel and writing burst FX into the data channel serially. On a dedicated server only the burst activation-flag clear — a sim-visible side effect — is kept, and no Niagara batch is ever created.

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

无返回值。副作用:写 FFxVisualizing 的槽绑定与标识字段,改写渲染批次数组,清除爆发特效的激活位,创建或销毁批次的 Niagara 组件,向 Niagara 推送数组,并向数据通道写入爆发特效记录。

No return value. Side effects: writes the slot binding and identity fields of FFxVisualizing, rewrites render-batch arrays, clears burst FX activation flags, creates or destroys batch Niagara components, pushes arrays into Niagara, and writes burst FX into the data channel.

常量Constants

两个缓存的状态位枚举值,供 HasFlag / SetFlag / ClearFlag 直接比较,避免逐实体做枚举转换。

Two cached state-bit enum values, compared directly by HasFlag / SetFlag / ClearFlag so no per-entity enum conversion is needed.

名称Name值Value说明Description
ActivatedFlagEBattleFlags::Activated池化特效的激活位:未设置的实体被视为休眠,实体遍历直接跳过;爆发特效注册后由处理器清除。Activation bit for pooled FX: entities without it are dormant and skipped by the entity walk; the processor clears it on burst FX after registration.
BurstFxFlagEBattleFlags::BurstFx一次性爆发特效标记:置位时走瞬态批次(数据通道)路径,而不是池化附着路径。One-shot burst FX marker: when set, the entity takes the transient-batch (data channel) path instead of the pooled attached path.

成员变量Members

名称Name类型Type默认值Default说明Description
EntityQueryFMassEntityQuery—主查询(私有):匹配 FBatchedFxTag 实体,配置见 ConfigureQueries。Main query (private): matches FBatchedFxTag entities; configured in ConfigureQueries.
RegistrationQueueFParallelGatherer<FFxRegistration>—注册记录的并行收集器(私有):并行段写线程本地槽,仿真 tick 的串行阶段合并、可选排序后排空。Parallel gatherer for registration records (private): the parallel phase appends to thread-local slots; the serial sim-tick phase merges, optionally sorts, then drains it.
FxRenderIdCounterint320渲染身份计数器(私有):每次分配递增;抵达 MAX_int32 时归零并把 FxRenderIdEpoch 加一。Render-identity counter (private): increments on each allocation; at MAX_int32 it wraps to zero and increments FxRenderIdEpoch.
FxRenderIdEpochint320渲染身份纪元(私有):与计数器组成永不重复的 (epoch, counter) 对,用于在池复用后仍能区分实例。Render-identity epoch (private): pairs with the counter into a never-repeating (epoch, counter) value so a reused pool slot is still distinguishable.
私有头文件方法Private Header Methods
名称Name签名Signature说明Description
AllocateFxRenderIdvoid (int32& OutEpoch, int32& OutCounter)游戏线程专用的渲染身份分配器,输出一组 (epoch, counter);只由串行注册循环调用,因此不需要原子操作。Game-thread-only render-identity allocator returning an (epoch, counter) pair; called only from the serial registration loop, so it needs no atomics.
AddRenderBatchint32 (AMassBattleFxRenderer* RendererActor)为渲染器新建一个批次:分配批次 ID、按批次容量预留数组、生成批次的 Niagara 系统,并探测系统暴露的 User 数组与固定包围盒模式;返回新批次 ID。Creates a new batch for the renderer: allocates a batch id, reserves arrays to the batch size, spawns the batch's Niagara system, and probes which User arrays and fixed-bounds mode the system exposes; returns the new batch id.

管线角色Pipeline Role

调度与执行域:构造函数关闭阶段自动注册,实际调度由插件在逻辑帧末尾的渲染子帧驱动;执行域为 Standalone / Server / Client,且必须在游戏线程运行。查询以 FBatchedFxTag 为锚,实体遍历是一条自动负载均衡的并行 chunk 波,注册与爆发特效写入是串行段,Niagara 数组推送按批次并行。渲染器按 FSubType 从战斗子系统的渲染器表中查找;所有特效注册都经本处理器这一个漏斗,因此渲染身份计数器在渲染器与批次之间全局唯一。

Scheduling and execution domain: the constructor disables phase auto-registration, and the plugin drives the actual schedule on the render sub-frame at the end of a logic frame; the execution domain is Standalone / Server / Client and execution must happen on the game thread. The query is anchored on FBatchedFxTag; the entity walk is one auto-balanced parallel chunk wave, registration and burst writing are serial stages, and Niagara array pushes run per batch in parallel. Renderers are looked up by FSubType in the combat subsystem's renderer table; every FX registration goes through this one processor, so the render-identity counter is globally unique across renderers and batches.

补充说明Notes

① 生命周期由标记表达:池化特效的休眠、待注册与已绑定三种状态由激活位与 FFxVisualizing.InstanceId 表达(-1 表示需要注册),不需要额外的状态字段。
② 渲染身份:每次获得池化槽都分配一个 (epoch, counter) 对,池复用后仍不重复,Niagara 侧据此识别实例身份。
③ 注册是单一入口:所有特效注册都经本处理器,身份计数器因此跨渲染器、跨批次全局唯一。
④ 专用服务器:批量 Niagara 在无头环境不可用,注册循环在服务器上只清除爆发特效的激活位——池状态参与哈希,这一副作用必须保留。

① Lifecycle is expressed by flags: the three states — dormant, needs registration, bound — are carried by the activation bit and FFxVisualizing.InstanceId (-1 means registration is needed), with no separate state field.
② Render identity: every pooled-slot acquisition gets an (epoch, counter) pair that never repeats across pool reuse, which is how the Niagara side distinguishes instances.
③ Registration is a single funnel: all FX registration goes through this processor, so the identity counter is globally unique across renderers and batches.
④ Dedicated server: batch Niagara is unavailable headless, so the registration loop only clears burst FX activation flags on a server — pool state is hashed, and that side effect must be preserved.