/** 如果设置,条件滴答将使用剩余时间形成节点的内存 */
uint8 bTickIntervals:1;
//BTAuxiliaryNode.h
UCLASS(Abstract)
class AIMODULE_API UBTAuxiliaryNode : public UBTNode
{
/** if set, conditional tick will use remaining time form node's memory */
uint8 bTickIntervals : 1;
逻辑待看
bool UBTAuxiliaryNode::WrappedTickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds, float& NextNeededDeltaTime) const
{
if (bNotifyTick || HasInstance())
{
const UBTAuxiliaryNode* NodeOb = HasInstance() ? static_cast<UBTAuxiliaryNode*>(GetNodeInstance(OwnerComp, NodeMemory)) : this;
ensure(NodeOb);
if (NodeOb != nullptr && NodeOb->bNotifyTick)
{
float UseDeltaTime = DeltaSeconds;
if (NodeOb->bTickIntervals)
{
FBTAuxiliaryMemory* AuxMemory = GetSpecialNodeMemory<FBTAuxiliaryMemory>(NodeMemory);
AuxMemory->NextTickRemainingTime -= DeltaSeconds;
AuxMemory->AccumulatedDeltaTime += DeltaSeconds;
const bool bTick = AuxMemory->NextTickRemainingTime <= 0.0f;
if (bTick)
{
UseDeltaTime = AuxMemory->AccumulatedDeltaTime;
AuxMemory->AccumulatedDeltaTime = 0.0f;
const_cast<UBTAuxiliaryNode*>(NodeOb)->TickNode(OwnerComp, NodeMemory, UseDeltaTime);
}
if (AuxMemory->NextTickRemainingTime < NextNeededDeltaTime)
{
NextNeededDeltaTime = AuxMemory->NextTickRemainingTime;
}
return bTick;
}
else
{
const_cast<UBTAuxiliaryNode*>(NodeOb)->TickNode(OwnerComp, NodeMemory, UseDeltaTime);
NextNeededDeltaTime = 0.0f;
return true;
}
}
}
return false;
}
本文探讨了游戏开发中行为树的一个辅助节点UBTAuxiliaryNode的实现逻辑,特别是其WrappedTickNode方法如何根据设置来调整滴答行为,并管理节点内存以实现周期性的节点执行。
4101

被折叠的 条评论
为什么被折叠?



