MassBattle Docsv1.19.20

AMassBattleAgentRenderer

UCLASS Actor

Source/MassBattle/Public/Renderers/MassBattleAgentRenderer.h

概述 Overview

agent 的合批渲染器 Actor:一个 SubType 对应一个渲染器实例,持有该子类型 agent 的批量槽位(SpawnedRenderBatches,FAgentRenderBatchData 记录)与 Niagara 系统资产。核心职责是每帧把预测插值经过时间推送给 Niagara——重型插值在 GPU 执行(自定义 HLSL 外推),CPU 只做推送。FSubType 成员同时是配置与运行时标识:它决定此渲染器服务的实体子类型(渲染处理器按 SubType 索引查找对应渲染器)。

The batched rendering actor for agents: one renderer instance per SubType, holding the batch slots (SpawnedRenderBatches of FAgentRenderBatchData) and the Niagara system asset for that subtype's agents. Its core duty is pushing the per-frame prediction-interp elapsed time to Niagara each tick — the heavy interpolation runs on the GPU (custom HLSL extrapolation); the CPU only pushes. The FSubType member is both config and runtime identity: it decides which entity subtype this renderer serves (the render processor looks up renderers by SubType index).

继承 Inheritance

AActor → AMassBattleAgentRenderer

公开方法 Public Methods

AMassBattleAgentRenderer() 构造函数

默认构造:开启每帧 tick(bCanEverTick / bStartWithTickEnabled),tick 组设为 TG_PostUpdateWork——在子系统 Tick + 处理器之后运行,保证批量数组已刷新。

Default constructor: enables per-frame tick (bCanEverTick / bStartWithTickEnabled) and sets the tick group to TG_PostUpdateWork — after the subsystem tick + processors, so the batch arrays are fresh.

Input

无参数。

No parameters.

Output

无返回值。副作用:配置 tick 组。

No return value. Side effect: configures the tick group.

BeginPlay virtual void

生命周期入口,当前仅调用父类实现,无额外初始化逻辑。

Lifecycle entry; currently only calls the parent implementation, no extra initialization.

Input

无参数。

No parameters.

Output

无返回值,无副作用。

No return value, no side effects.

EndPlay virtual void

生命周期出口,当前仅调用父类实现。

Lifecycle exit; currently only calls the parent implementation.

Input
参数 Param类型 Type说明 Description
EndPlayReasonEEndPlayReason::Type结束原因,由引擎传入。End-play reason provided by the engine.
Output

无返回值,无副作用。

No return value, no side effects.

Tick virtual void

每帧调用——推送预测经过时间到 Niagara:User.ElapsedSinceLogicTick 变量设为 UMassBattleSubsystem::GetRenderInterpElapsed(),GPU 端据此做外推插值。DedicatedServer 或无批量槽位时直接返回。

Called every frame — pushes the prediction elapsed to Niagara: sets the User.ElapsedSinceLogicTick variable to UMassBattleSubsystem::GetRenderInterpElapsed(), which the GPU uses for extrapolation. Returns early on dedicated servers or with no batch slots.

Input
参数 Param类型 Type说明 Description
DeltaTimefloat本帧时间步长(秒),当前未直接使用。Frame delta time in seconds; not used directly.
Output

无返回值。副作用:对每个批量槽位的 Niagara 组件写入 User.ElapsedSinceLogicTick 变量。

No return value. Side effect: writes the User.ElapsedSinceLogicTick variable on every batch slot's Niagara component.

成员变量 Members

名称 Name类型 Type默认值说明 Description
SubTypeFSubType—此渲染器服务的实体子类型(配置 + 运行时标识)。Entity subtype this renderer serves (config + runtime identity).
OffsetFTransformIdentity渲染偏移变换。Render offset transform.
RenderBatchSizeint325000渲染批量槽位数量。Render batch slot count.
RenderBatchIdleRemoveCoolDownfloat5.0f空闲批量槽位的移除冷却(秒)。Idle batch-slot removal cooldown (seconds).
PoollingCoolDownfloat1.0f槽位复用冷却(秒)。防止释放的槽位在冷却到期前被回收,保证 GPU 至少看到一帧 IsHidden=true,WasHidden 跳变机制正常工作。Slot reuse cooldown (seconds). Prevents a freed slot from being recycled until the cooldown expires, guaranteeing the GPU sees at least one IsHidden=true frame so the WasHidden snap mechanism works.
NiagaraSystemAssetTObjectPtr<UNiagaraSystem>—批量渲染用的 Niagara 系统资产。Niagara system asset for batched rendering.
AgentMeshTObjectPtr<UStaticMesh>—agent 静态网格资产。Agent static mesh asset.
NDC_TextPopTObjectPtr<UNiagaraDataChannelAsset>—文本弹出(飘字)的 Niagara 数据通道资产。Niagara data channel asset for text popups.
BoneAnimDataAssetTObjectPtr<UAnimToTextureDataAsset>—骨骼模式的 AnimToTexture 数据资产——驱动骨骼档(ISKM 骨骼 CS 管线,M2)的组件空间烘焙骨骼库;留空即停用管线。在每 SubType 的渲染器 BP 里填写即可启用骨骼档:按头文件注释,处理器在 AddRenderBatch 创建每批 RT 对与 MID、并行段打包每槽位动画状态、Tick 派发骨骼计算着色器。AnimToTexture data asset in BONE mode — the baked component-space bone library driving the bone tier (ISKM bone CS pipeline, M2); leave empty to disable the pipeline. Fill it in the per-subtype renderer BP to enable the bone tier: per the header comment, the processor creates the per-batch RT pair + MID at AddRenderBatch, packs per-slot anim states in the parallel walk, and Tick dispatches the bone compute shader.
BoneBaseMaterialTObjectPtr<UMaterialInterface>—每批 MID 的基础材质(读实例骨骼纹理的骨骼分支)。Base material for the per-batch MID (the bone branch reading the instance bone textures).
BoneMaterialVariableNameFName"BoneMaterial"每批骨骼 MID 推送到的 NS User 材质变量名(SetVariableMaterial)。NS User material variable name the per-batch bone MID is pushed to (SetVariableMaterial).
SpawnedRenderBatchesTMap<int32, FAgentRenderBatchData>空已生成的渲染批量记录(Key = 渲染批量 ID),含每个槽位的 Niagara 组件与状态。Spawned render batch records (key = render batch ID), holding per-slot Niagara components and state.
CurrentWorldTObjectPtr<UWorld>nullptr缓存的世界指针。Cached world pointer.
MassBattleSubsystemTObjectPtr<UMassBattleSubsystem>nullptr缓存的 MassBattle 子系统指针。Cached MassBattle subsystem pointer.
NextRenderBatchIdint320下一个渲染批量 ID 计数器。Next render batch ID counter.

管线角色 Pipeline Role

由渲染处理器/子系统按 SubType 查找并驱动:每帧在 TG_PostUpdateWork tick 组(处理器之后)推送 User.ElapsedSinceLogicTick 给各批量槽位 Niagara 组件,GPU 端做外推插值——CPU 侧不逐实体做插值。槽位池化(释放冷却)由渲染器设置项与 FAgentRenderBatchData 记录配合管理。

Looked up and driven by the render processor/subsystem by SubType: each frame in the TG_PostUpdateWork tick group (after the processors) it pushes User.ElapsedSinceLogicTick to each batch slot's Niagara component, with the GPU doing the extrapolation — no per-entity CPU interpolation. Slot pooling (release cooldown) is managed via the renderer settings and the FAgentRenderBatchData records.