UMassBattleProjectileMonoProcessor
Source/MassBattle/Public/Processors/MassBattleProjectileMonoProcessor.h
概述 Overview
抛射物实体的合并模拟处理器:移动(Interped 插值 / Ballistic 弹道 / Tracking 追踪,chunk 级 DoesArchetypeHaveFragment 分派)、碰撞检测(网格 SphereSweepForAgents + 物理 LineTrace/SphereTrace 障碍检测)、伤害与 debuff 应用(ApplyPointDamageAndDebuff / ApplyRadialDamageAndDebuff / ApplyBeamDamageAndDebuff)、重复伤害模式(IgnoreList 管理)、生命周期与销毁(池回收或销毁队列)。每个 projectile 携带 FProjectileSpawn 配置的 OnBirth / OnHit / OnRemoval 生成内容,命中与移除事件写入 OnProjectileHitQueue / OnProjectileDeathQueue。
Merged simulation processor for projectile entities: movement (Interped / Ballistic / Tracking, dispatched per chunk via DoesArchetypeHaveFragment), collision detection (grid SphereSweepForAgents plus physical LineTrace/SphereTrace obstacle checks), damage & debuff application (ApplyPointDamageAndDebuff / ApplyRadialDamageAndDebuff / ApplyBeamDamageAndDebuff), repetition modes (IgnoreList management), and lifecycle / despawn (pool recycle or destroy queue). Each projectile carries FProjectileSpawn OnBirth / OnHit / OnRemoval content; hit and removal events go to OnProjectileHitQueue / OnProjectileDeathQueue.
继承 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<FProjectileTag> + All<FEntityFlagFragment>(MARW) + All<FSubType, FScaling, FProjectileEvent, FDeterminism, FProjectileSpawn>(MARO) + All<FProjectileParams, FProjectileParamsRT, FLocating, FRotating, FProjectileVisualizing>(MARW)。移动/伤害变种不在查询中——由 Execute 内 DoesArchetypeHaveFragment 检测后经 GetFragmentRef 访问。
Initializes the entity query: All<FProjectileTag> + All<FEntityFlagFragment>(MARW) + All<FSubType, FScaling, FProjectileEvent, FDeterminism, FProjectileSpawn>(MARO) + All<FProjectileParams, FProjectileParamsRT, FLocating, FRotating, FProjectileVisualizing>(MARW). Movement/damage variants stay out of the query — detected via DoesArchetypeHaveFragment inside Execute and accessed through GetFragmentRef.
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 / UMassBattleHostSubsystem / UMassAPISubsystem / UMassBattleProjectileSubsystem / UMassBattleHashGridSubsystem(任一缺失返回),检查 ESubFrame::Subtick1 子帧门控;记录 MB.ProjectileCount。并行遍历中逐实体:① 计时与 IgnoreList:冷却倒计时;Periodic 模式冷却就绪清空忽略表;OncePerOverlap 模式移除已不再重叠的实体(胶囊-球距离 + 10u 缓冲防抖动);② 出生与移动:首次(bBornFired 门)执行 OnBirth 生成内容并打出生时间戳;三种移动变种分别经 MP.GetProjectilePositionAtTime_Interped/Ballistic/Tracking 推进(bWasBorn 保证出生帧不移动);③ 碰撞检测:实体侧 MG.SphereSweepForAgents(NearToFar,可带 FMassBattleQuery 过滤与忽略表),障碍侧 LineTrace/SphereTrace(Params.Query.ObstacleList);④ 碰撞结算:只撞障碍 → 按 bOnHitObstacle 扣血;只撞实体 → 扣血;两者都撞 → 取近者;⑤ 旋转:bRotationFollowVelocity 时追踪弹用飞行方向、其它用位移方向,QInterpTo 平滑;写 FProjectileVisualizing 速度供 GPU 预测;⑥ 销毁与伤害条件:LifeSpan / Health / 撞障碍 / 到达 / 撞实体五组 RemovalConditions 与 ApplyDmgConditions;⑦ 伤害应用:冷却就绪且条件满足时按 Point/Radial/Beam 变种施加伤害与 debuff(HitFromLocation 可取自施法者位置),伤害目标加入忽略表、执行 OnHit 生成内容与命中事件;bDamageApplied 重置冷却;⑧ 销毁:执行 OnRemoval 生成、移除事件,置 PendingDestroy + 清 Activated,清运行时状态后按 PoolDataAsset 分流到 ProjectileRecycleQueue 或 EntitiesToDestroyQueue。chunk 末把命中/死亡事件 append 到 OnProjectileHitQueue / OnProjectileDeathQueue。
Per-tick entry. Resolves UMassBattleSubsystem / UMassBattleHostSubsystem / UMassAPISubsystem / UMassBattleProjectileSubsystem / UMassBattleHashGridSubsystem (returns early if any is missing), gated on ESubFrame::Subtick1; records MB.ProjectileCount. Per-entity parallel flow: ① timers & IgnoreList: cooldown countdown; Periodic clears the ignore list when the cooldown is ready; OncePerOverlap removes entities no longer overlapping (capsule-sphere distance + 10u anti-flicker buffer); ② birth & movement: first hit (bBornFired gate) fires OnBirth content and stamps the birth time; the three movement variants advance via MP.GetProjectilePositionAtTime_Interped/Ballistic/Tracking (bWasBorn keeps the birth frame movement-free); ③ collision detection: entities via MG.SphereSweepForAgents (NearToFar, optional FMassBattleQuery filter + ignore list), obstacles via LineTrace/SphereTrace (Params.Query.ObstacleList); ④ collision resolution: obstacle-only → health decrement per bOnHitObstacle; entity-only → health decrement; both → nearest wins; ⑤ rotation: bRotationFollowVelocity — tracking projectiles use flight direction, others use position delta, smoothed with QInterpTo; writes FProjectileVisualizing velocities for GPU prediction; ⑥ despawn & damage conditions: LifeSpan / Health / obstacle-hit / arrival / entity-hit under both RemovalConditions and ApplyDmgConditions; ⑦ damage application: when the cooldown is ready and conditions hold, applies damage + debuff per Point/Radial/Beam variant (HitFromLocation may come from the instigator), adds victims to the ignore list, fires OnHit content and hit events; bDamageApplied resets the cooldown; ⑧ despawn: fires OnRemoval content + removal event, sets PendingDestroy + clears Activated, clears runtime state, then routes to ProjectileRecycleQueue or EntitiesToDestroyQueue by PoolDataAsset. Hit/death events are appended to OnProjectileHitQueue / OnProjectileDeathQueue at chunk end.
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
EntityManager | FMassEntityManager& | 实体管理器。Entity manager. |
Context | FMassExecutionContext& | 执行上下文,提供 fragment 视图与实体遍历。Execution context providing fragment views and entity iteration. |
Output
无返回值。副作用:推进全部 projectile 实体的运动/生命/伤害状态;向 MBH 的 spawn 批、MB 的伤害 gatherer / 事件队列 / 销毁队列 / 调试队列写入;更新 MB.ProjectileCount。
No return value. Side effects: advances movement/life/damage state of all projectile entities; writes to MBH spawn batches, MB's damage gatherer / event queues / destroy queue / debug queues; updates MB.ProjectileCount.
成员变量 Members
线程本地临时上下文(消除碰撞/伤害路径的每实体 TArray 分配抖动):HitEntityResult(碰撞检测结果)、EntitiesToRemove(OncePerOverlap 待移除列表)、DamageResults(伤害结果)、LocalHitEvents / LocalDeathEvents(本地事件缓冲)。ResetPerChunk() 重置事件数组并预分配,ResetPerAgent() 重置每实体数组。
Thread-local scratch context (eliminates per-entity TArray allocation churn on collision & damage paths): HitEntityResult (collision results), EntitiesToRemove (OncePerOverlap removal list), DamageResults (damage results), LocalHitEvents / LocalDeathEvents (local event buffers). ResetPerChunk() resets event arrays with reserve; ResetPerAgent() resets per-entity arrays.
管线角色 Pipeline Role
注册于 UMassBattleSubsystem 的 SimStages[1],在 Trace+Behavior 阶段(SimStages[0])之后——Behavior 生成的 projectile(含 launch 集合)本阶段处理,其伤害写入 DmgGatherer 供 SimStages[2] 的 Debuff+Reaction 消费。只在 Subtick1 子帧运行。生成的 Actor/Fx/Sound 宿主由 UMassBattleHostSubsystem 批次在 SimStages[5] 落地。网格查询使用 GridUpdateProcessor 帧起始重建的 Agent/Obstacle 网格。
Registered in UMassBattleSubsystem's SimStages[1], after the Trace+Behavior stage (SimStages[0]) — projectiles spawned by Behavior (including launch collections) are processed here; damage goes into the DmgGatherer for the Debuff+Reaction stage (SimStages[2]). Runs only on the Subtick1 sub-frame. Spawned Actor/Fx/Sound hosts are landed by UMassBattleHostSubsystem batches in SimStages[5]. Grid queries use the Agent/Obstacle grids rebuilt by GridUpdateProcessor at start of frame.