Files
UnrealEngineUWP/Engine/Plugins/AI/MassAI/Source/MassZoneGraphNavigation/Private/MassZoneGraphNavigationUtils.cpp
mikko mononen f21d1720b8 Mass Movement and Navigation cleanup
- Removed ununed processors and fragments
- Separated ZoneGraph specific things from common movement and navigation fragments and processors
- First attempt at cleaner separation between Mass Movement and Mass Navigation
- Moved configs and hard coded values to shared fragments
- Simplified and clarified parameters

#jira none
#rb Aris.Theophanidis
#preflight 61f283b61e5d78c383072b4a

#ROBOMERGE-AUTHOR: mikko.mononen
#ROBOMERGE-SOURCE: CL 18752305 in //UE5/Release-5.0/... via CL 18752314 via CL 18752372
#ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v903-18687472)

[CL 18752384 by mikko mononen in ue5-main branch]
2022-01-27 07:28:47 -05:00

128 lines
4.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "MassZoneGraphNavigationUtils.h"
#include "MassCommonTypes.h"
#include "MassNavigationFragments.h"
#include "MassZoneGraphNavigationFragments.h"
#include "ZoneGraphSubsystem.h"
#include "VisualLogger/VisualLogger.h"
namespace UE::MassNavigation
{
static constexpr float InflateDistance = 200.0f; // @todo: make a setting.
bool ActivateActionMove(const UWorld& World,
const UObject* Requester,
const FMassEntityHandle Entity,
const UZoneGraphSubsystem& ZoneGraphSubsystem,
const FMassZoneGraphLaneLocationFragment& LaneLocation,
const FZoneGraphShortPathRequest& PathRequest,
const float AgentRadius,
const float DesiredSpeed,
FMassMoveTargetFragment& MoveTarget,
FMassZoneGraphShortPathFragment& ShortPath,
FMassZoneGraphCachedLaneFragment& CachedLane)
{
ShortPath.Reset();
CachedLane.Reset();
MoveTarget.DistanceToGoal = 0.0f;
MoveTarget.DesiredSpeed.Set(0.0f);
if (!ensureMsgf(MoveTarget.GetCurrentAction() == EMassMovementAction::Move, TEXT("Expecting action 'Move': Invalid action %s"), MoveTarget.GetCurrentAction()))
{
return false;
}
const FZoneGraphStorage* ZoneGraphStorage = ZoneGraphSubsystem.GetZoneGraphStorage(LaneLocation.LaneHandle.DataHandle);
if (ZoneGraphStorage == nullptr)
{
UE_VLOG(Requester, LogMassNavigation, Error, TEXT("Entity [%s] move request failed: missing ZoneGraph Storage for current lane %s."),
*Entity.DebugGetDescription(),
*LaneLocation.LaneHandle.ToString());
return false;
}
MoveTarget.IntentAtGoal = EMassMovementAction::Stand;
MoveTarget.DesiredSpeed.Set(DesiredSpeed);
CachedLane.CacheLaneData(*ZoneGraphStorage, LaneLocation.LaneHandle, LaneLocation.DistanceAlongLane, PathRequest.TargetDistance, InflateDistance);
if (ShortPath.RequestPath(CachedLane, PathRequest, LaneLocation.DistanceAlongLane, AgentRadius))
{
MoveTarget.IntentAtGoal = ShortPath.EndOfPathIntent;
MoveTarget.DistanceToGoal = (ShortPath.NumPoints > 0) ? ShortPath.Points[ShortPath.NumPoints - 1].DistanceAlongLane.Get() : 0.0f;
#if WITH_MASSGAMEPLAY_DEBUG
UE_CVLOG(UE::Mass::Debug::IsDebuggingEntity(Entity),
Requester,
LogMassNavigation,
Log,
TEXT("Move %s, on lane %s, from %.1fcm to %.1fcm, next lane %s."),
PathRequest.bMoveReverse ? TEXT("reverse") : TEXT("forward"),
*LaneLocation.LaneHandle.ToString(),
LaneLocation.DistanceAlongLane,
PathRequest.TargetDistance,
*PathRequest.NextLaneHandle.ToString());
#endif // WITH_MASSGAMEPLAY_DEBUG
}
else
{
UE_VLOG(Requester, LogMassNavigation, Error, TEXT("Entity [%s] move request failed: unable to request path on lane %s."),
*Entity.DebugGetDescription(),
*LaneLocation.LaneHandle.ToString());
return false;
}
UE_VLOG(Requester, LogMassNavigation, Log, TEXT("Entity [%s] successfully requested %s"), *Entity.DebugGetDescription(), *MoveTarget.ToString());
return true;
}
bool ActivateActionStand(const UWorld& World,
const UObject* Requester,
const FMassEntityHandle Entity,
const UZoneGraphSubsystem& ZoneGraphSubsystem,
const FMassZoneGraphLaneLocationFragment& LaneLocation,
const float DesiredSpeed,
FMassMoveTargetFragment& MoveTarget,
FMassZoneGraphShortPathFragment& ShortPath,
FMassZoneGraphCachedLaneFragment& CachedLane)
{
ShortPath.Reset();
CachedLane.Reset();
MoveTarget.DistanceToGoal = 0.0f;
MoveTarget.DesiredSpeed.Set(0.0f);
if (!ensureMsgf(MoveTarget.GetCurrentAction() == EMassMovementAction::Stand, TEXT("Expecting action 'Stand': Invalid action %s"), MoveTarget.GetCurrentAction()))
{
return false;
}
const FZoneGraphStorage* ZoneGraphStorage = ZoneGraphSubsystem.GetZoneGraphStorage(LaneLocation.LaneHandle.DataHandle);
MoveTarget.IntentAtGoal = EMassMovementAction::Stand;
MoveTarget.DesiredSpeed.Set(DesiredSpeed);
CachedLane.CacheLaneData(*ZoneGraphStorage, LaneLocation.LaneHandle, LaneLocation.DistanceAlongLane, LaneLocation.DistanceAlongLane, InflateDistance);
UE_VLOG(Requester, LogMassNavigation, Log, TEXT("Entity [%s] successfully requested %s"), *Entity.DebugGetDescription(), *MoveTarget.ToString());
return true;
}
bool ActivateActionAnimate(const UWorld& World,
const UObject* Requester,
const FMassEntityHandle Entity,
FMassMoveTargetFragment& MoveTarget)
{
MoveTarget.DistanceToGoal = 0.0f;
MoveTarget.DesiredSpeed.Set(0.0f);
if (!ensureMsgf(MoveTarget.GetCurrentAction() == EMassMovementAction::Animate, TEXT("Expecting action 'Animate': Invalid action %s"), MoveTarget.GetCurrentAction()))
{
return false;
}
MoveTarget.IntentAtGoal = EMassMovementAction::Stand;
UE_VLOG(Requester, LogMassNavigation, Log, TEXT("Entity [%s] successfully requested %s"), *Entity.DebugGetDescription(), *MoveTarget.ToString());
return true;
}
}