UMassBattleProjectileMonoProcessor
Source/MassBattle/Public/Processors/MassBattleProjectileMonoProcessor.h
概述Overview
投射物处理器:逐帧推进静态/弹道/插值/跟踪四种移动模式、命中检测与事件触发。由插件自动调度;投射物的速度、伤害、命中事件在投射物 DataAsset 上配置。
The projectile processor: advances the static / ballistic / interped / tracking movement modes, hit detection and event firing every frame. Auto-scheduled; speed, damage and hit events are configured on the projectile DataAsset.
继承Inheritance
结构体 FProjectileScratchContextStruct FProjectileScratchContext
线程局部的分块临时缓冲,用来消除逐实体的 TArray 分配抖动:命中结果、待移除列表、伤害结果与两个复用实体列表都在这里复用。两个复位入口分别对应分块边界与逐实体边界,调用方在进入下一层循环前清掉上一层的数据。
Thread-local scratch buffer for a chunk, removing per-entity TArray allocation churn: hit results, the removal list, damage results and two reused entity lists are all reused here. Two reset entry points cover the chunk boundary and the per-entity boundary, so the caller clears one layer's data before entering the next loop.
成员变量Members
| 名称Name | 类型Type | 默认值Default | 说明Description |
|---|---|---|---|
HitEntityResult | TArray<FTraceResult> | — | 本实体的碰撞检测结果(近到远排序),首个元素即命中目标。Collision results for this entity (near to far); the first element is the hit target. |
EntitiesToRemove | TArray<FEntityHandle> | — | OncePerOverlap 模式下,本帧要从忽略列表里剔除的实体。In OncePerOverlap mode, entities to drop from the ignore list this frame. |
DamageResults | TArray<FDmgResult> | — | 伤害应用结果,同时用于把受伤实体补进忽略列表。Damage application results; also used to add the damaged entities to the ignore list. |
SweepIgnore | FEntityArray | — | 持握武器体积扫掠的忽略列表:忽略名单拷贝加宿主本身,每 tick 复用。Ignore list for held-weapon volume sweeps: a copy of the ignore list plus the host itself, reused every tick. |
SingleTarget | FEntityArray | — | 只含一个实体的列表,供逐候选与逐命中的伤害调用使用。Single-entity list for per-candidate and per-hit damage calls. |
LocalHitEvents | TArray<FHitData> | — | 本分块的命中事件,遍历结束后并入子系统队列。Hit events for this chunk, appended to the subsystem queue after the walk. |
LocalDeathEvents | TArray<FDeathData> | — | 本分块的移除事件,遍历结束后并入子系统队列。Removal events for this chunk, appended to the subsystem queue after the walk. |
方法Methods
| 名称Name | 说明Description |
|---|---|
ResetPerChunk | 复位两个事件数组并预留容量(命中 32 条、移除 8 条),无参数、无返回值。Resets the two event arrays and reserves capacity (32 hits, 8 removals); no parameters, no return value. |
ResetPerAgent | 复位命中、待移除与伤害结果数组,以及两个复用列表,为下一个实体准备;无参数、无返回值。Resets the hit, removal and damage result arrays plus the two reused lists for the next entity; no parameters, no return value. |
方法Methods
构造函数。把处理器从 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.
初始化并注册弹道实体查询:要求 FProjectileTag、可写的标志与位置/参数 fragment,以及只读的缩放、事件、确定性与生成内容。共享 fragment FProjectileQueryShared(碰撞与障碍过滤所用的 trace 查询包)以可选声明挂进查询——GetSharedFragmentPtr 只能看到本查询自己声明的共享需求,漏声明会让每个分块都取到空指针;声明为可选而不是强制,则让缺少该包的分块在守卫处显式失败,而不是静默掉出查询、把弹道冻在空中。
Initializes and registers the projectile query: it requires FProjectileTag, writable flag and location/parameter fragments, and read-only scaling, event, determinism and spawn content. The shared FProjectileQueryShared bundle (the trace query used for collision and obstacle filtering) is declared optional — GetSharedFragmentPtr only sees shared requirements declared by this query, and a missing row would hand every chunk a null pointer; declaring it optional rather than required makes a chunk without the bundle fail loudly at the guard instead of silently dropping out of the query and freezing its projectiles in the air.
Input
| 参数Param | 类型Type | 说明Description |
|---|---|---|
EntityManager | const TSharedRef<FMassEntityManager>& | 实体管理器,查询以它初始化。Entity manager the query initializes against. |
Output
无返回值。副作用:查询向本处理器注册(RegisterWithProcessor),此后随处理器的每一次 Execute 生效。
No return value. Side effect: the query is registered with this processor (RegisterWithProcessor) and takes effect on every subsequent Execute.
每帧入口。门检查确认战斗子系统存在且 ESubFrame::Subtick1 被调度,再取步长、模拟时间并让宿主、Mass API、弹道、哈希网格四个子系统就绪,同时把查询命中的实体数发布到 ProjectileCount。分块遍历先按原型判定移动形态(插值 / 弹道 / 跟踪)与伤害形态(点 / 径向 / 光束),再逐个实体推进:冷却与重复模式维护忽略列表,未出生的一次性执行 OnBirth 内容并播下渲染速度,运动门打开时按形态求解新位置,随后做 agent 球扫与障碍 trace 并按最近者裁决碰撞,持握武器另走宿主攻击轮次的通道窗口扫掠,最后按移除条件与伤害条件结算、发命中/移除事件,并把实体路由到弹道回收队列或销毁队列。分块结束后把本块的命中与移除事件并入子系统队列。
Per-frame entry. The gates confirm the battle subsystem and a scheduled ESubFrame::Subtick1, then the step and simulation time are taken, the host, Mass API, projectile and hash-grid subsystems are resolved, and the matching entity count is published to ProjectileCount. The chunk walk first derives the movement form (interped / ballistic / tracking) and the damage form (point / radial / beam) from the archetype, then walks the entities: cooldowns and repetition modes maintain the ignore list, an unborn entity runs its OnBirth content once and seeds render velocity, the motion gate solves a new position per form, agent sphere sweeps and obstacle traces are arbitrated by nearest hit, a held weapon instead runs the host attack round's channel-window sweep, and the removal and damage conditions are resolved, hit/removal events emitted, and the entity routed to the projectile recycle queue or the destroy queue. After the walk the chunk's hit and removal events are appended to the subsystem queues.
Input
| 参数Param | 类型Type | 说明Description |
|---|---|---|
EntityManager | FMassEntityManager& | 实体管理器。Entity manager. |
Context | FMassExecutionContext& | 本帧执行上下文;分块遍历、共享 fragment 读取与延迟命令都经由它。Execution context for this frame; the chunk walk, shared-fragment reads and deferred commands go through it. |
Output
无返回值。副作用:推进弹道的位置、朝向与渲染速度缓存;写冷却与忽略列表;通过 Mass API 应用点/径向/光束伤害与减益;把命中与移除事件并入子系统队列;到期的弹道置 PendingDestroy 并清 Activated,带池数据资产的进入弹道回收队列,其余进入销毁队列。
No return value. Side effects: it advances projectile location, facing and the render velocity cache; writes cooldowns and the ignore list; applies point, radial or beam damage and debuffs through the Mass API; appends hit and removal events to the subsystem queues; and an expiring projectile is marked PendingDestroy with Activated cleared, entering the projectile recycle queue when it carries a pool data asset and the destroy queue otherwise.
常量Constants
两个 static constexpr 私有缓存值,把战斗标志枚举预先转换成 EEntityFlags,省去每帧重复转换。它们不对外暴露,也没有配置项。
Two private static constexpr cached values that convert the battle flag enumerators to EEntityFlags ahead of time, saving the per-frame conversion. They are not exposed and have no configuration.
| 名称Name | 值Value | 说明Description |
|---|---|---|
ActivatedFlag | static_cast<EEntityFlags>(EBattleFlags::Activated) | 弹道是否激活;未激活的实体在本帧被跳过,回收与移除时清除。Whether the projectile is active; inactive entities are skipped for the frame and the flag is cleared on recycle or removal. |
PendingDestroyFlag | static_cast<EEntityFlags>(EBattleFlags::PendingDestroy) | 已排队销毁/回收的实体,本帧剩余时间里保持休眠。Entities already queued for destruction or recycling stay dormant for the rest of the frame. |
成员变量Members
| 名称Name | 类型Type | 说明Description |
|---|---|---|
EntityQuery | FMassEntityQuery | 私有。唯一的弹道查询;移动与伤害形态由每个分块的原型决定,不写进查询条件。Private. The single projectile query; movement and damage forms are decided per chunk from the archetype rather than encoded in the query. |
管线角色Pipeline Role
构造函数关闭 Mass 自动处理阶段注册,执行限定在游戏线程,实际运行只发生在 ESubFrame::Subtick1 被调度的帧;分块遍历是并行的自动负载均衡通道。它依赖弹道与哈希网格两个子系统:位置求解(插值、弹道、跟踪)由弹道子系统提供,agent 球扫由哈希网格提供,伤害与减益走 Mass API 的批量入口。生成内容通过宿主子系统批量创建弹道、Actor、特效与音效;移除时带池数据资产的实体进入弹道回收队列,其余进入销毁队列——回收由宿主侧统一排空。
The constructor disables automatic Mass processing-phase registration, execution is limited to the game thread, and the processor only runs on frames where ESubFrame::Subtick1 is scheduled; the chunk walk is a parallel auto-balanced pass. It depends on the projectile and hash-grid subsystems: position solving (interped, ballistic, tracking) comes from the projectile subsystem, agent sphere sweeps from the hash grid, and damage and debuffs go through the Mass API batch entries. Spawn content is batch-created through the host subsystem (projectiles, actors, FX, sounds); on removal an entity with a pool data asset enters the projectile recycle queue and the rest enter the destroy queue, with the host side draining both.
补充说明Notes
① 出生内容由 FProjectileParamsRT.bBornFired 逐实体门控,因此新建与池化复用的弹道都会执行一次 OnBirth。
② 持握武器是运动关闭的弹道实体:运动分支整段跳过,伤害只来自宿主攻击轮次内打开的通道窗口,窗口相位由宿主的攻击时钟推导;落地冻结(bFreezeOnLanding)则让弹道停在落点而不是消失。
③ 忽略列表的维护随 EDamageRepetitionMode 变化:周期模式在冷却就绪时清空,OncePerOverlap 每帧按体积-胶囊重叠复核并剔除已离开的实体,另外两种模式不动列表。
① OnBirth content is gated per entity by FProjectileParamsRT.bBornFired, so both freshly built and pooled projectiles run it once.
② A held weapon is a projectile entity with motion disabled: the movement branch is skipped entirely, damage only comes from the channel windows opened during the host's attack round (the window phase is derived from the host's attack clock), and landing freeze (bFreezeOnLanding) leaves the projectile resting at the impact point instead of vanishing.
③ Ignore-list maintenance follows EDamageRepetitionMode: periodic mode clears it when the cooldown is ready, OncePerOverlap rechecks volume-versus-capsule overlap every frame and drops entities that left, and the other two modes leave the list alone.