UMassBattleAgentRenderProcessor
Source/MassBattle/Public/Processors/MassBattleAgentRenderProcessor.h
概述Overview
表现层处理器:推进动画状态机、选择 LOD、把位置/朝向/动画等目标数据交给渲染器。由插件自动调度;你通过 DataAsset 的动画/渲染/LOD 面板与 渲染器 资产控制表现,而不是直接与它交互。
The presentation processor: advances the animation state machine, picks LODs and hands position / orientation / animation targets to the renderer. Auto-scheduled; you steer presentation through the DataAsset animation / render / LOD panels and the renderer asset, never by touching this processor.
继承Inheritance
FMassTextPopWriterFMassTextPopWriter
面向 Niagara Data Channel 的批量飘字写入器。逐条写浮字代价太高,所以这个类型把一批位置、参数与子类型值一次写进通道的变量缓冲;两个 LWC 标记记录缓冲是否承载大世界坐标数值。
A bulk floating-text writer for a Niagara Data Channel. Writing text pops one entry at a time is too expensive, so this type writes a batch of positions, parameters and sub-type values into the channel's variable buffers in one go; two LWC flags record whether a buffer carries large-world-coordinate values.
成员变量Members
| 名称Name | 类型Type | 默认值 | 说明Description |
|---|---|---|---|
PositionBuffer | FNiagaraDataChannelVariableBuffer* | nullptr | 位置通道的变量缓冲指针。Variable buffer pointer for the position channel. |
LocationBuffer | FNiagaraDataChannelVariableBuffer* | nullptr | location 通道的变量缓冲指针;其数值是否为 LWC 由 bLocationIsLWC 记录。Variable buffer pointer for the location channel; bLocationIsLWC records whether its values are large-world coordinates. |
ParamsBuffer | FNiagaraDataChannelVariableBuffer* | nullptr | 参数通道的变量缓冲指针;每条记录是一个 FVector4f(头文件注明 Vector4)。Variable buffer pointer for the parameter channel; each entry is an FVector4f (Vector4 as noted in the header). |
SubTypeBuffer | FNiagaraDataChannelVariableBuffer* | nullptr | 子类型通道的变量缓冲指针。Variable buffer pointer for the sub-type channel. |
bLocationIsLWC | bool | false | location 缓冲是否承载大世界坐标(LWC)数值。Whether the location buffer carries large-world-coordinate values. |
bParamsIsLWC | bool | false | 参数缓冲是否承载大世界坐标(LWC)数值。Whether the parameter buffer carries large-world-coordinate values. |
方法Methods
初始化写入器的缓冲,在批量追加之前调用:把四个通道的变量缓冲接到写入器上。
Initializes the writer's buffers before a bulk append: binds the four channels' variable buffers to the writer.
Input
无参数。
No parameters.
Output
无返回值。副作用:写入器持有可写的缓冲指针。
No return value. Side effect: the writer holds writable buffer pointers.
一次追加整批飘字:按给定的写入偏移,把位置、参数与一个子类型值写入已绑定的缓冲。
Appends a whole batch of text pops in one call: at the given write offset it writes the locations, the parameters and one sub-type value into the bound buffers.
Input
| 参数Param | 类型Type | 说明Description |
|---|---|---|
WriteOffset | int32 | 本批在通道批次内的起始写入偏移。Start offset of this batch inside the channel batch. |
Locs | TConstArrayView<FVector> | 每个条目的位置。Per-entry locations. |
Params | TConstArrayView<FVector4f> | 每个条目的 Vector4 参数。Per-entry Vector4 parameters. |
SubTypeVal | int32 | 整批共用的子类型值。Sub-type value shared by the whole batch. |
Output
无返回值。副作用:按 WriteOffset 把这一批条目写进已绑定的缓冲。
No return value. Side effect: the batch's entries are written into the bound buffers at WriteOffset.
方法Methods
默认构造函数,只配置处理器自身的调度属性:不与引擎处理阶段自动注册,要求游戏线程执行,并在独立、服务端、客户端三种目标上启用。它不持有任何可调参数——表现层的开关全部在 DataAsset 面板与渲染器资产上。
Default constructor. It only configures the processor's own scheduling properties: no automatic registration with the engine's processing phases, game-thread execution required, enabled on the standalone, server and client targets. It holds no tunables — every presentation switch lives on the DataAsset panels and the renderer asset.
Input
无参数。
No parameters.
Output
无返回值。副作用:写入三个处理器属性——bAutoRegisterWithProcessingPhases = false、bRequiresGameThreadExecution = true、ExecutionFlags = Standalone | Server | Client。
No return value. Side effects: three processor properties are written — bAutoRegisterWithProcessingPhases = false, bRequiresGameThreadExecution = true, ExecutionFlags = Standalone | Server | Client.
构建并注册本处理器唯一的实体查询。实体必须带 FAgentTag;FAppearingTag 与 FDyingTag 是可选的结构标记,所以无论单位正在出现、正在死亡还是都没有,都会命中同一条查询。读取面是表现与状态所需的一整组 fragment(位置与朝向、碰撞体、生命与血条、出现/攻击/受击/死亡、移动、防御、debuff、事件与调试、LOD 与共享动画、追踪、骨骼、瞄准与注视),写入面是每帧会被刷新的状态(实体标志、统计、确定性、缩放、可视化、飘字、攻击、移动、动画)。最后以 RegisterWithProcessor 把查询挂到本处理器上。
Builds and registers the processor's single entity query. An entity must carry FAgentTag; FAppearingTag and FDyingTag are optional structural tags, so a unit matches the same query whether it is appearing, dying or neither. The read side is the fragment set presentation and state need (transform, collider, health and health bar, appear / attack / hit / death, move, defence, debuff, event and debug, LOD and shared animation, tracing, bone, aim and look); the write side is the state refreshed every frame (entity flags, statistics, determinism, scaling, visualizing, text pop, attacking, moving, animating). RegisterWithProcessor then attaches the query to this processor.
Input
| 参数Param | 类型Type | 说明Description |
|---|---|---|
EntityManager | const TSharedRef<FMassEntityManager>& | 实体管理器,查询在它上面初始化。Entity manager the query is initialized against. |
Output
无返回值。副作用:EntityQuery 完成初始化并注册到本处理器,之后的 Execute 用它遍历命中实体。
No return value. Side effects: EntityQuery is initialized and registered with this processor, and the following Execute calls walk the matching entities with it.
每帧入口。除非 Subtick3 渲染子帧被调度、且战斗子系统、Mass API 子系统与 agent 子系统全部可用,否则立即返回。专用服务器上跳过渲染器登记收集(Niagara 批系统在无视口环境会失败),但模拟 tick 的 fragment 写入照常进行,快照因此与客户端保持一致。随后清掉已销毁渲染器的登记条目、收集所有存活批次的指针,并行重置每个批次的槽位状态:空闲槽、隐藏标记、空槽的唯一 ID 哨兵值,以及按上一帧是否打包过而结转或清空的混合状态。模拟 tick 上还会按引擎帧的实际经过时间推进已释放槽位的冷却,保证 GPU 至少看到一帧隐藏状态后槽位才会被复用。
Frame entry. It returns immediately unless the Subtick3 render sub-frame is scheduled and the battle, Mass API and agent subsystems are all available. On a dedicated server it skips renderer registration collection (Niagara batch systems fail headless) while the sim-tick fragment writes keep running, so the snapshot stays identical to a client's. It then drops the registration entries of destroyed renderer actors, collects every live batch, and resets each batch's slot state in parallel: free slots, hidden flags, the empty-slot unique-ID sentinel, and blend state carried over or cleared depending on whether the slot was packed last tick. On simulation ticks it also advances the freed-slot cooldown by the engine frame's wall-clock delta, so a slot is reused only after the GPU has observed at least one hidden frame.
Input
| 参数Param | 类型Type | 说明Description |
|---|---|---|
EntityManager | FMassEntityManager& | 实体管理器,处理器通过它访问实体。Entity manager the processor accesses entities through. |
Context | FMassExecutionContext& | 本帧执行上下文;代码从它取世界,以获得引擎帧的 delta 秒数。Execution context for this frame; the code reads its world to obtain the engine frame's delta seconds. |
Output
无返回值。副作用:渲染器表中的失效条目被移除;各批次的槽位数组、隐藏标记、唯一 ID 与混合状态被就地重置;模拟 tick 上槽位冷却递减。
No return value. Side effects: invalid entries are removed from the renderer registry; each batch's slot arrays, hidden flags, unique IDs and blend state are reset in place; on simulation ticks the slot cooldown is decremented.
常量Constants
以下常量把共享战斗标志的枚举值预先缓存成 EEntityFlags,让标志的读写不必每次做枚举到位掩码的转换。它们只是同一批共享标志的别名,不引入新的位;「值」列给出对应的共享标志。
These constants cache the shared battle-flag enum values as EEntityFlags, so flag reads and writes skip the enum-to-bitmask conversion on every call. They are aliases of the shared flags and introduce no new bits; the Value column gives the flag each one mirrors.
| 名称Name | 值Value | 说明Description |
|---|---|---|
AttackingFlag | EBattleFlags::Attacking | 攻击轮进行中的标志。Flag for an attack round in progress. |
DeathAnimFlag | EBattleFlags::DeathAnim | 死亡动画播放中的标志。Flag for a death animation being played. |
AppearAnimFlag | EBattleFlags::AppearAnim | 出现动画播放中的标志。Flag for an appear animation being played. |
AttackAnimFlag | EBattleFlags::AttackAnim | 攻击动画播放中的标志。Flag for an attack animation being played. |
HitAnimFlag | EBattleFlags::HitAnim | 受击动画播放中的标志。Flag for a hit animation being played. |
ActivatedFlag | EBattleFlags::Activated | 实体已激活、参与模拟的标志。Flag for an entity being activated and participating in the simulation. |
NotRenderingFlag | EBattleFlags::NotRendering | 当前不渲染的标志。Flag for the entity not being rendered. |
RenderingFlag | EBattleFlags::Rendering | 当前由批量渲染器绘制的标志。Flag for the entity being drawn by a batched renderer. |
RenderingWithParticleFlag | EBattleFlags::RenderingWithParticle | 走粒子渲染路径的标志。Flag for drawing through the particle path. |
RenderingWithActorFlag | EBattleFlags::RenderingWithActor | 走 Actor 渲染路径的标志。Flag for drawing through the actor path. |
DyingFlag | EBattleFlags::Dying | 处于死亡过程的标志。Flag for the entity being in the death process. |
AppearingFlag | EBattleFlags::Appearing | 处于出现过程的标志。Flag for the entity being in the appear process. |
BeingHitFlag | EBattleFlags::BeingHit | 处于受击反应中的标志。Flag for the entity reacting to a hit. |
PauseAnimChangeFlag | EBattleFlags::PauseAnimChange | 暂停动画状态切换的标志。Flag for pausing animation state changes. |
FallingFlag | EBattleFlags::Falling | 处于下落状态的标志。Flag for the entity being airborne in a fall. |
SlowingFlag | EBattleFlags::Slowing | 处于减速状态的标志。Flag for the entity being slowed. |
BeingSelectFlag | EBattleFlags::BeingSelect | 处于被选中(瞬时)状态的标志。Flag for the transient being-selected state. |
SelectedFlag | EBattleFlags::Selected | 处于选中(持续)状态的标志。Flag for the persistent selected state. |
成员变量Members
| 名称Name | 类型Type | 默认值 | 说明Description |
|---|---|---|---|
EntityQuery | FMassEntityQuery | — | 主实体查询,由 ConfigureQueries 构建,Execute 用它遍历命中实体。Main entity query, built by ConfigureQueries and walked by Execute. |
RegistrationQueue | FParallelGatherer<FMassEntityHandle> | — | 实体句柄的并行收集器,供登记阶段收集本帧需要渲染槽位的实体。Parallel gatherer for entity handles; the registration stage collects the entities that need a render slot this frame. |
NiagaraSpawnFailures | TArray<TWeakObjectPtr<AMassBattleAgentRenderer>> | 空 | 批次被永久拒绝的渲染器 Actor 弱引用列表:就绪预检通过但生成后没有活的系统实例时记录。每个 Actor 只尝试一次;新 Actor(重新烘焙或重新生成)是新键,会得到一次全新尝试。弱键,不参与 GC 跟踪或序列化。Weak list of renderer actors whose batch was refused for good: the readiness pre-check passed but the spawn produced no live system instance. One attempt per renderer actor; a new actor (re-bake or re-spawn) is a new key and gets one fresh attempt. Weak keys — never GC-tracked or serialised. |
NiagaraNotReadyReportedAssets | TSet<FString> | 空 | 首次请求批次时仍在编译的 Niagara 资产路径集合,按资产去重:每个资产只报告一次并只发起一次编辑器内编译请求,下一次通过时重试,就绪的那一帧人群出现。打包版本不发起编译请求。Set of Niagara asset paths that were still compiling when their first batch was requested, deduplicated per asset: one report and one editor-only compile request per asset, retried on the next pass so the crowd appears on the ready frame. Packaged builds issue no compile request. |
私有方法Private Methods
| 名称Name | 返回类型Return | 参数Parameters | 说明Description |
|---|---|---|---|
AddRenderBatch | int32 | AMassBattleAgentRenderer* RendererActor | 现有批次已满时,在该渲染器 Actor 上新建一个批次(例如新的 Niagara 系统),返回新批次下标。Adds a new batch (a new Niagara system, for example) to a renderer actor whose existing batches are full; returns the new batch index. |
TryAcquireRenderSlot | static bool | FAgentRenderBatchData& Data, int32 MaxSlots, int32& OutSlot | 经批次的单调游标预留一个登记槽位;OutSlot 为 INDEX_NONE 表示在末尾追加,返回 false 表示该批次既不能复用也不能扩容。Reserves a registration slot through the batch's monotonic cursor; OutSlot of INDEX_NONE means append a new slot, and false means the batch can neither reuse nor grow. |
UpdateAnimBlendLevel1 | void | 级别状态、共享与动画 fragment、组合行、当前状态、状态与状态机变化标记、帧步长、出现/攻击/受击/死亡、攻击速度倍数、重置输出、死亡与出现进度、移动、带符号移动速度、移动求值Level state, shared and animating fragments, combination row, current state, state and state-machine change flags, delta time, appear / attack / hit / death, attack speed multiplier, reset output, death and appear progress, moving, signed locomotion speed, locomotion evaluation | 第一级混合状态机推进;剪辑经组合行从共享表解析,不用逐 fragment 缓存。Advances the level-1 blend state machine; clips are addressed through the combination row resolved from the shared table, never a per-fragment cache. |
UpdateAnimBlendLevel2 | void | 同上,另加首次更新标记与两个重置输出As above, plus the first-update flag and two reset outputs | 第二级混合状态机推进。Advances the level-2 blend state machine. |
UpdateAnimBlendLevel3 | void | 同上,另加三个重置输出与移动对的重置输出As above, plus three reset outputs and the locomotion-pair reset output | 第三级混合状态机推进:八槽映射(基础 0/1/2、跳跃 3/4、montage 5/6、受击 7),槽位不在层之间共享。Advances the level-3 blend state machine: an eight-slot map (base 0/1/2, jump 3/4, montage 5/6, hit 7); slots are never shared between layers. |
AdvanceFrame | void | FPerLevelAnimState& State, int32 SlotIndex, float DeltaTime, int32 SampleRate, bool bSkipAdvance | 按状态机解析出的速率推进一条轨道(0..7);负速率即创作的反向采样,函数内的回绕本身就会反向推进;bSkipAdvance 跳过推进。Advances one track (0..7) at the rate the level state machine resolved; a negative rate is an authored reverse sample and the wrap inside the function advances such a track backwards; bSkipAdvance skips the advance. |
CopyTrackSlot | static void | FPerLevelAnimState& State, int32 FromSlot, int32 ToSlot | 把一个槽位的整段剪辑状态(索引/速率/帧/范围/循环,0..7)复制到另一个槽位,用于把当前剪辑降级到出槽并在交叉淡化后归一。Copies one slot's whole clip state (index / rate / frame / range / loop, 0..7) onto another slot, used to demote a layer's current clip onto its outgoing slot and to normalise after a crossfade. |
EncodeFrames01 | static float | float Frame0, float Frame1 | 把两个帧号打包进一个参数通道。Packs two frame indices into one parameter lane. |
EncodeFrame2AndLerps | static float | uint16 Frame2, uint8 Lerp0, uint8 Lerp1 | 把第三个帧号与两个 0–255 的插值权重打包进一个参数通道。Packs the third frame index and two 0–255 interpolation weights into one parameter lane. |
EncodeDynamicParams0 | static float | int32 Team, uint8 Dissolve, int32 LOD, bool bDrawLOD, bool bBeingSelect, bool bSelected | 把队伍、溶解、渲染带索引与选择位打包进第一个动态参数通道;布局固定,由材质解码。Packs team, dissolve, render-band index and the selection bits into the first dynamic parameter lane; the layout is fixed and decoded by the materials. |
EncodeAnimTracksA | static FVector4f | uint16 StartFrame0, uint16 EndFrame0, uint16 StartFrame1, uint16 EndFrame1, uint16 StartFrame2, uint16 EndFrame2, float FPS0, float FPS1 | 打包动画轨道向量的第一部分:三条轨道的起止帧与其中两条的采样速率。Packs the first half of the animation-track vector: start/end frames of three tracks plus the sample rate of two of them. |
EncodeAnimTracksB | static FVector4f | float FPS2, bool bFPS0Negative, bool bFPS1Negative, bool bLoop0, bool bLoop1, bool bLoop2, bool bNoFrameExtrap | 打包动画轨道向量的第二部分:第三条轨道的速率、两条轨道的反向标记、三条轨道的循环位与无帧外推位。Packs the second half of the animation-track vector: the third track's rate, the negative-rate flags of two tracks, the loop bits of three tracks and the no-frame-extrapolation bit. |
WriteParentRelativeTransform | static void | FAgentRenderBatchData& Data, int32 InstanceId, const FVector& ParentLoc, const FQuat& FacingRot, const FVector& RenderLoc, const FQuat& RenderRot, const FVector& RenderScale | 父级+相对模型:把父变换写进位置/朝向/缩放数组,并把渲染变换反解成相对位置/旋转/缩放写进对应数组。Parent-plus-relative model: writes the parent transform into the location / orientation / scale arrays and reverse-solves the render transform into the relative location / rotation / scale arrays. |
EncodeStatusEffects | static float | uint8 HitGlow, uint8 Frozen, uint8 Burning, uint8 Poisoned | 把四个材质特效强度(受击闪光、冻结、燃烧、中毒)打包进一个参数通道。Packs four material effect strengths (hit glow, frozen, burning, poisoned) into one parameter lane. |
CalculatePlayRate | static float | float StartFrame, float EndFrame, float TargetDuration, int32 SampleRate | 由起止帧、目标时长与采样率求播放速率。Derives a play rate from the start/end frames, the target duration and the sample rate. |
管线角色Pipeline Role
处理器关闭了与引擎处理阶段的自动注册(bAutoRegisterWithProcessingPhases = false),要求游戏线程执行,并在 Standalone / Server / Client 三种目标上启用;每帧真正的门控是子帧——只有 Subtick3(一个逻辑帧的最后一个子 tick)被调度时才执行,所以渲染数据每逻辑帧只打包一次,其余引擎 tick 直接跳过。查询在 ConfigureQueries 注册后,Execute 遍历命中实体,承担三件事:LOD 选择、动画状态更新与渲染数据打包。专用服务器不收集渲染批次(Niagara 批系统在无视口环境会失败),但模拟 tick 的 fragment 写入照常进行,双端快照保持一致。渲染器 Actor 失效时其登记条目会被清掉,该子类型下一次需要时再生成新的渲染器;已释放的槽位在冷却期内保持锁定,确保 GPU 至少观察到一帧隐藏状态后才会被复用。
The processor turns off automatic registration with the engine's processing phases (bAutoRegisterWithProcessingPhases = false), requires game-thread execution and is enabled on the standalone, server and client targets. The real per-frame gate is the sub-frame: it runs only when Subtick3 (the last sub-tick of a logic frame) is scheduled, so render data is packed once per logic frame and other engine ticks are skipped. With the query registered in ConfigureQueries, Execute walks the matching entities and covers three duties: LOD selection, animation state updates and render data packing. A dedicated server collects no render batches (Niagara batch systems fail without a viewport), while the sim-tick fragment writes keep running so both peers keep the same snapshot. When a renderer actor goes away its registration entry is dropped and a fresh renderer is spawned the next time that subtype needs one; freed slots stay locked for the cooldown so the GPU observes at least one hidden frame before reuse.
补充说明Notes
① 渲染与选中状态是各端本地的:Rendering、NotRendering、RenderingWithParticle、RenderingWithActor、Selected 与 BeingSelect 取决于相机、LOD 与本机选择,按设计不参与跨端一致性校验。
② 批次生成失败不重试:渲染器的就绪预检通过、但生成后仍没有活的系统实例时,该批次被拒绝并记录在案,同一个渲染器 Actor 只尝试一次;重新烘焙或重新生成的 Actor 是新键,会得到一次全新尝试。
③ 仍在编译的资产:首次请求某个 Niagara 资产时它可能还在编译;这种情况按资产报告一次并在下一次通过时重试,就绪的那一帧人群才出现,打包版本不会发起编译请求。
① Render and selection state are peer-local: Rendering, NotRendering, RenderingWithParticle, RenderingWithActor, Selected and BeingSelect depend on the camera, LOD and the local machine's selection, and by design take no part in the cross-peer consistency check.
② A refused batch is not retried: when a renderer's readiness pre-check passes but the spawn still yields no live system instance, the batch is refused and recorded, with one attempt per renderer actor; a re-baked or re-spawned actor is a new key and gets one fresh attempt.
③ Assets still compiling: a Niagara asset may still be compiling when its first batch is requested; that is reported once per asset and retried on the next pass, so the crowd appears on the ready frame, and packaged builds issue no compile request.