UMassBattleBPTaskTemplateBase
Source/MassBattle/Public/Tasks/MassBattleBPTaskTemplateBase.h
概述 Overview
BP 任务模板基类——"创建 + delegate 绑定"逻辑的 CDO 式定义。BP 子类绘制 BindMoveToTask / BindChaseAttackTask(把任务的 delegate AddDynamic 到本实例的处理器),模板键 = BP 类路径,是创建时(写入任务快照记录)与恢复时(LoadClass 解析,每类缓存一个实例)共用的单一来源——BP 事件处理器因此能在 resync 后存活。一个模板实例服务于其类的所有任务与所有 resync,处理器必须对任务无状态(每任务状态只流经任务本身 / 快照记录)。继承 ULockstepVarStoreBase:本实例的 BP 变量是锁步变量——每 tick 折叠进 hash 且 resync 快照恢复,但仅值类型(int/float/bool/FVector/FName/FString/枚举/其数组),引用类型跳过并警告。写入纪律(硬约束):变量只能在任务 Tick 处理器/命令流中写入,UI/广播写入会使双端分叉 → 失步循环;2c 重建窗口内 Bind*Task / OnTaskEnd 处理器只能写可推导状态。无同名 .cpp——纯接口声明。
BP task template base — a CDO-style definition of the "create + delegate bind" logic. BP subclasses draw BindMoveToTask / BindChaseAttackTask (AddDynamic of the task's delegates to this instance's handlers); the template key is the BP class path, the single source used both at creation (recorded into the task snapshot record) and at restore (class resolved via LoadClass, one cached instance per class) — so BP event handlers survive resync. One template instance serves ALL tasks of its class and all resyncs; handlers must be stateless w.r.t. tasks (per-task state flows only through the task itself / snapshot records). Inherits ULockstepVarStoreBase: BP variables on this instance are lockstep variables — folded into the per-tick hash and snapshot-restored on resync, but only value types (int/float/bool/FVector/FName/FString/enum/arrays of those); reference types are skipped with a warning. WRITE DISCIPLINE (hard constraint): variables must only be written inside task tick handlers / command flow — UI/broadcast writes diverge the peers → desync loop; during the 2c rebuild window, Bind*Task / OnTaskEnd handlers must only write derivable state. No same-name .cpp — pure interface declarations.
继承 Inheritance
公开方法 Public Methods
BP 实现:把 MoveTo 任务的 delegate 绑定到本实例的处理器。由 CreateAgentsMoveToTask 在创建任务后调用(先经 IsBindMoveToTaskImplemented 检查,未实现则一次性警告并以无绑定运行)。
BP implements: binds the MoveTo task's delegates to this instance's handlers. Called by CreateAgentsMoveToTask after creating the task (gated by IsBindMoveToTaskImplemented; unimplemented → one-time warning, runs unbound).
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
Task | UMassBattleBPTaskAgentsMoveTo* | 要绑定的 MoveTo 任务实例。The MoveTo task instance to bind. |
Output
无返回值。副作用:BP 侧绑定 delegate。
No return value. Side effect: BP-side delegate binding.
BP 实现:把 ChaseAttack 任务的 delegate 绑定到本实例的处理器。由 CreateAgentsChaseAttackTask 调用,行为与 BindMoveToTask 一致。
BP implements: binds the ChaseAttack task's delegates to this instance's handlers. Called by CreateAgentsChaseAttackTask; behaves like BindMoveToTask.
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
Task | UMassBattleBPTaskAgentsChaseAttack* | 要绑定的 ChaseAttack 任务实例。The ChaseAttack task instance to bind. |
Output
无返回值。副作用:BP 侧绑定 delegate。
No return value. Side effect: BP-side delegate binding.
resync 恢复知会——每次 resync 在所有任务重建并重新绑定后触发一次。实例在 resync 中存活(缓存),其 BP 变量仍是 resync 前的值;实现此事件以重置端侧私有状态。框架托管状态(fragment / 任务状态)已恢复,无需处理。未实现时警告(提示作者端侧私有变量在 resync 后不会被恢复)。
Resync recovery notification — fired ONCE per resync, AFTER every task was rebuilt and re-bound. The instance survived the resync (cached), so its BP variables still hold pre-resync values; implement this to reset any peer-local state. Framework-managed state (fragments / task state) is already restored and needs nothing here. Unimplemented hooks warn (the author's peer-local variables survive resync unrestored).
Input
无参数。
No parameters.
Output
无返回值。副作用:BP 侧重置端侧私有状态。
No return value. Side effect: BP-side reset of peer-local state.
模板键 = BP 类路径(FName(GetClass()->GetPathName()))——TaskRecord.TemplateKey(采集)与 LoadClass(恢复)的单一来源。
Template key = BP class path (FName(GetClass()->GetPathName())) — the single source for TaskRecord.TemplateKey (capture) and LoadClass (restore).
Input
无参数。
No parameters.
Output
返回本类的路径名 FName。
Returns the class path name as an FName.
BP 类是否实际实现了 BindMoveToTask(IsFunctionImplementedInScript)——用于跳过未实现绑定并一次性警告。
Whether the BP class actually implements BindMoveToTask (IsFunctionImplementedInScript) — used to skip unbound templates with a one-time warning.
Input
无参数。
No parameters.
Output
返回是否已实现。
Returns whether implemented.
BP 类是否实际实现了 BindChaseAttackTask,语义同 IsBindMoveToTaskImplemented。
Whether the BP class actually implements BindChaseAttackTask; same semantics as IsBindMoveToTaskImplemented.
Input
无参数。
No parameters.
Output
返回是否已实现。
Returns whether implemented.
BP 类是否实现了恢复钩子——未实现时警告,提示作者端侧私有变量在 resync 后不会被恢复。
Whether the BP class implements the recovery hook — unbound hooks warn so the author knows peer-local variables survive resync unrestored.
Input
无参数。
No parameters.
Output
返回是否已实现。
Returns whether implemented.
管线角色 Pipeline Role
由 UMassBattleSubsystem 经 GetTaskTemplateByKey 实例化/缓存(每类一个实例);模板化创建工厂(CreateAgentsMoveToTask / CreateAgentsChaseAttackTask)在创建任务后调用 Bind*Task;resync 时 RebuildTasksFromSnapshot 用 TemplateKey 解析模板并重新绑定;每次 resync 结束后 OnResyncRecovered 触发一次。BP 变量经 ULockstepVarStoreBase 每 tick 折叠进网络哈希并随快照恢复。
Instantiated/cached by UMassBattleSubsystem via GetTaskTemplateByKey (one instance per class); the template-based factories (CreateAgentsMoveToTask / CreateAgentsChaseAttackTask) call Bind*Task after creating tasks; on resync, RebuildTasksFromSnapshot resolves the template via TemplateKey and re-binds; OnResyncRecovered fires once after each resync. BP variables fold into the network hash every tick and restore with the snapshot via ULockstepVarStoreBase.