2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-06-10 13:56:35 -04:00
# include "GameplayDebuggerPrivate.h"
2014-08-07 17:34:29 -04:00
# include "Engine/GameInstance.h"
2014-08-07 08:36:40 -04:00
# include "Debug/DebugDrawService.h"
2014-06-25 09:28:40 -04:00
# include "GameFramework/HUD.h"
2014-06-10 13:56:35 -04:00
# include "GameplayDebuggingComponent.h"
# include "GameplayDebuggingHUDComponent.h"
# include "GameplayDebuggingReplicator.h"
2014-06-11 09:53:20 -04:00
# include "BehaviorTreeDelegates.h"
# if WITH_EDITOR
# include "Editor/EditorEngine.h"
2014-08-21 20:30:51 -04:00
# include "LevelEditorViewport.h"
2014-06-11 09:53:20 -04:00
# endif // WITH_EDITOR
2014-06-10 13:56:35 -04:00
# include "UnrealNetwork.h"
2014-08-07 17:34:29 -04:00
FOnSelectionChanged AGameplayDebuggingReplicator : : OnSelectionChangedDelegate ;
2014-10-14 10:29:11 -04:00
AGameplayDebuggingReplicator : : AGameplayDebuggingReplicator ( const FObjectInitializer & ObjectInitializer )
: Super ( ObjectInitializer )
2014-09-22 15:19:39 -04:00
, MaxEQSQueries ( 5 )
2014-08-07 17:34:29 -04:00
, bIsGlobalInWorld ( true )
2014-06-10 13:56:35 -04:00
, LastDrawAtFrame ( 0 )
2014-08-07 17:34:29 -04:00
, PlayerControllersUpdateDelay ( 0 )
2014-06-10 13:56:35 -04:00
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-09-29 21:43:13 -04:00
// Structure to hold one-time initialization
struct FConstructorStatics
{
ConstructorHelpers : : FObjectFinderOptional < UTexture2D > RedIcon ;
ConstructorHelpers : : FObjectFinderOptional < UTexture2D > GreenIcon ;
2015-02-23 15:58:14 -05:00
// both icons are needed to debug AI
2014-09-29 21:43:13 -04:00
FConstructorStatics ( )
: RedIcon ( TEXT ( " /Engine/EngineResources/AICON-Red.AICON-Red " ) )
, GreenIcon ( TEXT ( " /Engine/EngineResources/AICON-Green.AICON-Green " ) )
{
}
} ;
static FConstructorStatics ConstructorStatics ;
2015-02-23 15:58:14 -05:00
DefaultTexture_Red = ConstructorStatics . RedIcon . Get ( ) ;
DefaultTexture_Green = ConstructorStatics . GreenIcon . Get ( ) ;
2014-08-07 17:34:29 -04:00
PrimaryActorTick . bCanEverTick = true ;
2014-08-25 11:07:28 -04:00
PrimaryActorTick . bStartWithTickEnabled = false ;
2014-08-07 17:34:29 -04:00
2015-02-10 04:34:10 -05:00
USceneComponent * SceneComponent = CreateDefaultSubobject < USceneComponent > ( TEXT ( " SceneComponent " ) ) ;
2014-06-10 13:56:35 -04:00
RootComponent = SceneComponent ;
2014-06-25 09:28:40 -04:00
2014-08-18 15:30:21 -04:00
# if WITH_EDITOR
2014-08-21 20:30:51 -04:00
SetIsTemporarilyHiddenInEditor ( true ) ;
2014-08-18 15:30:21 -04:00
# endif
# if WITH_EDITORONLY_DATA
2014-09-09 12:17:30 -04:00
SetTickableWhenPaused ( true ) ;
SetActorHiddenInGame ( false ) ;
2014-08-21 20:30:51 -04:00
bHiddenEdLevel = true ;
bHiddenEdLayer = true ;
bHiddenEd = true ;
2014-06-13 11:09:59 -04:00
bEditable = false ;
2014-06-13 14:50:38 -04:00
# endif
2014-06-25 09:28:40 -04:00
DebuggerShowFlags = GameplayDebuggerSettings ( ) . DebuggerShowFlags ;
2014-09-09 12:17:30 -04:00
FGameplayDebuggerSettings Settings = GameplayDebuggerSettings ( this ) ;
# define UPDATE_VIEW_PROPS(__FlagName__) __FlagName__ = Settings.CheckFlag(EAIDebugDrawDataView::__FlagName__);
UPDATE_VIEW_PROPS ( OverHead ) ;
UPDATE_VIEW_PROPS ( Basic ) ;
UPDATE_VIEW_PROPS ( BehaviorTree ) ;
UPDATE_VIEW_PROPS ( EQS ) ;
UPDATE_VIEW_PROPS ( Perception ) ;
UPDATE_VIEW_PROPS ( GameView1 ) ;
UPDATE_VIEW_PROPS ( GameView2 ) ;
UPDATE_VIEW_PROPS ( GameView3 ) ;
UPDATE_VIEW_PROPS ( GameView4 ) ;
UPDATE_VIEW_PROPS ( GameView5 ) ;
# undef UPDATE_VIEW_PROPS
EnableEQSOnHUD = true ;
2014-06-25 09:28:40 -04:00
if ( ! HasAnyFlags ( RF_ClassDefaultObject ) )
{
SetActorTickEnabled ( true ) ;
bReplicates = false ;
SetRemoteRoleForBackwardsCompat ( ROLE_SimulatedProxy ) ;
SetReplicates ( true ) ;
2014-08-07 17:34:29 -04:00
2015-02-19 07:14:31 -05:00
AGameplayDebuggingReplicator : : OnSelectionChangedDelegate . AddUObject ( this , & AGameplayDebuggingReplicator : : ServerSetActorToDebug ) ;
2014-06-25 09:28:40 -04:00
}
2015-02-27 09:26:32 -05:00
# endif //!(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-06-10 13:56:35 -04:00
}
void AGameplayDebuggingReplicator : : GetLifetimeReplicatedProps ( TArray < FLifetimeProperty > & OutLifetimeProps ) const
{
Super : : GetLifetimeReplicatedProps ( OutLifetimeProps ) ;
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-06-25 09:28:40 -04:00
DOREPLIFETIME_CONDITION ( AGameplayDebuggingReplicator , DebugComponent , COND_OwnerOnly ) ;
DOREPLIFETIME_CONDITION ( AGameplayDebuggingReplicator , LocalPlayerOwner , COND_OwnerOnly ) ;
2014-08-07 17:34:29 -04:00
DOREPLIFETIME_CONDITION ( AGameplayDebuggingReplicator , bIsGlobalInWorld , COND_OwnerOnly ) ;
2014-09-09 12:17:30 -04:00
DOREPLIFETIME_CONDITION ( AGameplayDebuggingReplicator , LastSelectedActorToDebug , COND_OwnerOnly ) ;
2014-06-10 13:56:35 -04:00
# endif
}
2015-04-03 17:34:52 -04:00
bool AGameplayDebuggingReplicator : : IsNetRelevantFor ( const AActor * RealViewer , const AActor * ViewTarget , const FVector & SrcLocation ) const
2014-06-10 13:56:35 -04:00
{
2014-06-25 09:28:40 -04:00
return LocalPlayerOwner = = RealViewer ;
2014-06-10 13:56:35 -04:00
}
void AGameplayDebuggingReplicator : : PostInitializeComponents ( )
{
Super : : PostInitializeComponents ( ) ;
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-08-07 17:34:29 -04:00
SetActorTickEnabled ( true ) ;
2015-02-27 09:26:32 -05:00
# endif
2014-08-07 17:34:29 -04:00
}
2014-09-09 12:17:30 -04:00
# if WITH_EDITOR
void AGameplayDebuggingReplicator : : PostEditChangeProperty ( FPropertyChangedEvent & PropertyChangedEvent )
{
Super : : PostEditChangeProperty ( PropertyChangedEvent ) ;
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-09-09 12:17:30 -04:00
if ( ! PropertyChangedEvent . Property )
{
return ;
}
FGameplayDebuggerSettings Settings = GameplayDebuggerSettings ( this ) ;
# define CHECK_AND_UPDATE_FLAGS(__FlagName_) \
if ( PropertyChangedEvent . Property - > GetFName ( ) = = GET_MEMBER_NAME_CHECKED ( AGameplayDebuggingReplicator , __FlagName_ ) ) \
{ \
__FlagName_ ? Settings . SetFlag ( EAIDebugDrawDataView : : __FlagName_ ) : Settings . ClearFlag ( EAIDebugDrawDataView : : __FlagName_ ) ; \
GetDebugComponent ( ) - > ServerReplicateData ( Settings . CheckFlag ( EAIDebugDrawDataView : : __FlagName_ ) ? EDebugComponentMessage : : ActivateDataView : EDebugComponentMessage : : DeactivateDataView , EAIDebugDrawDataView : : __FlagName_ ) ; \
} else
CHECK_AND_UPDATE_FLAGS ( OverHead )
CHECK_AND_UPDATE_FLAGS ( Basic )
CHECK_AND_UPDATE_FLAGS ( BehaviorTree )
CHECK_AND_UPDATE_FLAGS ( EQS )
CHECK_AND_UPDATE_FLAGS ( Perception )
CHECK_AND_UPDATE_FLAGS ( GameView1 )
CHECK_AND_UPDATE_FLAGS ( GameView2 )
CHECK_AND_UPDATE_FLAGS ( GameView3 )
CHECK_AND_UPDATE_FLAGS ( GameView4 )
CHECK_AND_UPDATE_FLAGS ( GameView5 ) { }
# if WITH_EQS
if ( PropertyChangedEvent . Property - > GetFName ( ) = = GET_MEMBER_NAME_CHECKED ( AGameplayDebuggingReplicator , EQS ) )
{
2014-09-10 05:48:38 -04:00
GetDebugComponent ( ) - > EnableClientEQSSceneProxy ( EQS ) ;
GetDebugComponent ( ) - > SetEQSIndex ( ActiveEQSIndex ) ;
2014-09-09 12:17:30 -04:00
GetDebugComponent ( ) - > MarkRenderStateDirty ( ) ;
}
if ( PropertyChangedEvent . Property - > GetFName ( ) = = GET_MEMBER_NAME_CHECKED ( AGameplayDebuggingReplicator , ActiveEQSIndex ) )
{
GetDebugComponent ( ) - > SetEQSIndex ( ActiveEQSIndex ) ;
}
# endif // WITH_EQS
# undef CHECK_AND_UPDATE_FLAGS
2015-02-27 09:26:32 -05:00
# endif //!(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-09-09 12:17:30 -04:00
}
2015-02-27 09:26:32 -05:00
# endif //WITH_EDITOR
2014-09-09 12:17:30 -04:00
2014-08-07 17:34:29 -04:00
void AGameplayDebuggingReplicator : : BeginPlay ( )
{
Super : : BeginPlay ( ) ;
2014-08-21 20:30:51 -04:00
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-09-09 12:17:30 -04:00
if ( Role = = ROLE_Authority )
{
bReplicates = false ;
SetRemoteRoleForBackwardsCompat ( ROLE_SimulatedProxy ) ;
SetReplicates ( true ) ;
if ( ! DebugComponentClass . IsValid ( ) & & GetWorld ( ) & & GetNetMode ( ) < ENetMode : : NM_Client )
{
DebugComponentClass = StaticLoadClass ( UGameplayDebuggingComponent : : StaticClass ( ) , NULL , * DebugComponentClassName , NULL , LOAD_None , NULL ) ;
if ( ! DebugComponentClass . IsValid ( ) )
{
DebugComponentClass = UGameplayDebuggingComponent : : StaticClass ( ) ;
}
}
GetDebugComponent ( ) ;
}
2014-09-10 05:48:38 -04:00
if ( GetWorld ( ) & & GetNetMode ( ) ! = ENetMode : : NM_DedicatedServer )
{
if ( GIsEditor )
{
UDebugDrawService : : Register ( TEXT ( " DebugAI " ) , FDebugDrawDelegate : : CreateUObject ( this , & AGameplayDebuggingReplicator : : OnDebugAIDelegate ) ) ;
}
UDebugDrawService : : Register ( TEXT ( " Game " ) , FDebugDrawDelegate : : CreateUObject ( this , & AGameplayDebuggingReplicator : : DrawDebugDataDelegate ) ) ;
if ( ! DebugComponentHUDClass . IsValid ( ) )
{
DebugComponentHUDClass = StaticLoadClass ( AGameplayDebuggingHUDComponent : : StaticClass ( ) , NULL , * DebugComponentHUDClassName , NULL , LOAD_None , NULL ) ;
if ( ! DebugComponentHUDClass . IsValid ( ) )
{
DebugComponentHUDClass = AGameplayDebuggingHUDComponent : : StaticClass ( ) ;
}
}
}
2014-08-21 20:30:51 -04:00
# if WITH_EDITOR
const UEditorEngine * EEngine = Cast < UEditorEngine > ( GEngine ) ;
2015-02-19 04:40:17 -05:00
if ( EEngine & & ( EEngine - > bIsSimulatingInEditor | | EEngine - > EditorWorld ) & & GetWorld ( ) ! = EEngine - > EditorWorld & & ! IsGlobalInWorld ( ) & & GCurrentLevelEditingViewportClient & & GCurrentLevelEditingViewportClient - > EngineShowFlags . DebugAI )
2014-08-21 20:30:51 -04:00
{
SetIsTemporarilyHiddenInEditor ( false ) ;
SetActorHiddenInGame ( false ) ;
bHiddenEdLevel = false ;
bHiddenEdLayer = false ;
bHiddenEd = false ;
bEditable = true ;
2014-09-09 12:17:30 -04:00
if ( DebugComponent )
{
DebugComponent - > ServerReplicateData ( EDebugComponentMessage : : ActivateReplication , EAIDebugDrawDataView : : Empty ) ;
2014-11-25 09:36:16 -05:00
FGameplayDebuggerSettings Settings = GameplayDebuggerSettings ( this ) ;
DebugComponent - > ServerReplicateData ( Settings . CheckFlag ( EAIDebugDrawDataView : : OverHead ) ? EDebugComponentMessage : : ActivateDataView : EDebugComponentMessage : : DeactivateDataView , EAIDebugDrawDataView : : OverHead ) ;
DebugComponent - > ServerReplicateData ( Settings . CheckFlag ( EAIDebugDrawDataView : : Basic ) ? EDebugComponentMessage : : ActivateDataView : EDebugComponentMessage : : DeactivateDataView , EAIDebugDrawDataView : : Basic ) ;
DebugComponent - > ServerReplicateData ( Settings . CheckFlag ( EAIDebugDrawDataView : : BehaviorTree ) ? EDebugComponentMessage : : ActivateDataView : EDebugComponentMessage : : DeactivateDataView , EAIDebugDrawDataView : : BehaviorTree ) ;
DebugComponent - > ServerReplicateData ( Settings . CheckFlag ( EAIDebugDrawDataView : : EQS ) ? EDebugComponentMessage : : ActivateDataView : EDebugComponentMessage : : DeactivateDataView , EAIDebugDrawDataView : : EQS ) ;
DebugComponent - > ServerReplicateData ( Settings . CheckFlag ( EAIDebugDrawDataView : : Perception ) ? EDebugComponentMessage : : ActivateDataView : EDebugComponentMessage : : DeactivateDataView , EAIDebugDrawDataView : : Perception ) ;
DebugComponent - > ServerReplicateData ( Settings . CheckFlag ( EAIDebugDrawDataView : : GameView1 ) ? EDebugComponentMessage : : ActivateDataView : EDebugComponentMessage : : DeactivateDataView , EAIDebugDrawDataView : : GameView1 ) ;
DebugComponent - > ServerReplicateData ( Settings . CheckFlag ( EAIDebugDrawDataView : : GameView2 ) ? EDebugComponentMessage : : ActivateDataView : EDebugComponentMessage : : DeactivateDataView , EAIDebugDrawDataView : : GameView2 ) ;
DebugComponent - > ServerReplicateData ( Settings . CheckFlag ( EAIDebugDrawDataView : : GameView3 ) ? EDebugComponentMessage : : ActivateDataView : EDebugComponentMessage : : DeactivateDataView , EAIDebugDrawDataView : : GameView3 ) ;
DebugComponent - > ServerReplicateData ( Settings . CheckFlag ( EAIDebugDrawDataView : : GameView4 ) ? EDebugComponentMessage : : ActivateDataView : EDebugComponentMessage : : DeactivateDataView , EAIDebugDrawDataView : : GameView4 ) ;
DebugComponent - > ServerReplicateData ( Settings . CheckFlag ( EAIDebugDrawDataView : : GameView5 ) ? EDebugComponentMessage : : ActivateDataView : EDebugComponentMessage : : DeactivateDataView , EAIDebugDrawDataView : : GameView5 ) ;
2014-09-09 12:17:30 -04:00
}
2014-08-21 20:30:51 -04:00
}
else
{
SetTickableWhenPaused ( true ) ;
SetIsTemporarilyHiddenInEditor ( true ) ;
SetActorHiddenInGame ( false ) ;
bHiddenEdLevel = true ;
bHiddenEdLayer = true ;
bHiddenEd = true ;
bEditable = false ;
2014-09-09 12:17:30 -04:00
if ( DebugComponent )
{
DebugComponent - > ServerReplicateData ( EDebugComponentMessage : : DeactivateDataView , EAIDebugDrawDataView : : Empty ) ;
}
2014-08-21 20:30:51 -04:00
}
# endif
2014-06-25 09:28:40 -04:00
if ( GetWorld ( ) & & GetNetMode ( ) ! = ENetMode : : NM_DedicatedServer )
2014-06-10 13:56:35 -04:00
{
if ( GIsEditor )
{
UDebugDrawService : : Register ( TEXT ( " DebugAI " ) , FDebugDrawDelegate : : CreateUObject ( this , & AGameplayDebuggingReplicator : : OnDebugAIDelegate ) ) ;
}
UDebugDrawService : : Register ( TEXT ( " Game " ) , FDebugDrawDelegate : : CreateUObject ( this , & AGameplayDebuggingReplicator : : DrawDebugDataDelegate ) ) ;
if ( ! DebugComponentHUDClass . IsValid ( ) )
{
DebugComponentHUDClass = StaticLoadClass ( AGameplayDebuggingHUDComponent : : StaticClass ( ) , NULL , * DebugComponentHUDClassName , NULL , LOAD_None , NULL ) ;
if ( ! DebugComponentHUDClass . IsValid ( ) )
{
DebugComponentHUDClass = AGameplayDebuggingHUDComponent : : StaticClass ( ) ;
}
}
}
2015-02-23 15:58:14 -05:00
if ( bAutoActivate )
{
OnRep_AutoActivate ( ) ;
}
2015-02-27 09:26:32 -05:00
# endif //!(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2015-02-23 15:58:14 -05:00
}
2015-05-27 12:43:28 -04:00
void AGameplayDebuggingReplicator : : BeginDestroy ( )
{
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2015-06-09 06:57:31 -04:00
if ( GEngine )
{
GEngine - > bEnableOnScreenDebugMessages = true ;
}
2015-05-27 12:43:28 -04:00
if ( IsDrawEnabled ( ) )
{
EnableDraw ( false ) ;
}
# endif
Super : : BeginDestroy ( ) ;
}
2015-02-23 15:58:14 -05:00
void AGameplayDebuggingReplicator : : PostNetInit ( )
{
Super : : PostNetInit ( ) ;
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2015-02-23 15:58:14 -05:00
if ( bAutoActivate )
{
OnRep_AutoActivate ( ) ;
}
2015-02-27 09:26:32 -05:00
# endif
2015-02-23 15:58:14 -05:00
}
void AGameplayDebuggingReplicator : : ClientAutoActivate_Implementation ( )
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2015-02-23 15:58:14 -05:00
// we are already replicated so let's activate tool
if ( GetWorld ( ) & & GetNetMode ( ) = = ENetMode : : NM_Client & & ! IsToolCreated ( ) & & ! IsGlobalInWorld ( ) )
{
CreateTool ( ) ;
EnableTool ( ) ;
}
2015-02-27 09:26:32 -05:00
# endif
2014-10-01 08:53:33 -04:00
}
2014-06-10 13:56:35 -04:00
2014-10-01 08:53:33 -04:00
void AGameplayDebuggingReplicator : : OnRep_AutoActivate ( )
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-09-29 21:43:13 -04:00
// we are already replicated so let's activate tool
if ( GetWorld ( ) & & GetNetMode ( ) = = ENetMode : : NM_Client & & ! IsToolCreated ( ) & & ! IsGlobalInWorld ( ) )
{
CreateTool ( ) ;
EnableTool ( ) ;
}
2015-02-27 09:26:32 -05:00
# endif
2014-06-25 09:28:40 -04:00
}
UGameplayDebuggingComponent * AGameplayDebuggingReplicator : : GetDebugComponent ( )
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2015-02-23 15:58:14 -05:00
if ( IsPendingKill ( ) = = false & & ! DebugComponent & & DebugComponentClass . IsValid ( ) & & GetNetMode ( ) < ENetMode : : NM_Client )
2014-06-25 09:28:40 -04:00
{
2015-07-16 09:03:00 -04:00
DebugComponent = NewObject < UGameplayDebuggingComponent > ( this , DebugComponentClass . Get ( ) , TEXT ( " DebugComponent " ) , RF_Transient ) ;
2014-06-25 09:28:40 -04:00
DebugComponent - > SetIsReplicated ( true ) ;
DebugComponent - > RegisterComponent ( ) ;
DebugComponent - > Activate ( ) ;
}
2015-02-27 09:26:32 -05:00
# endif
2014-06-25 09:28:40 -04:00
return DebugComponent ;
2014-06-10 13:56:35 -04:00
}
2015-04-03 17:34:52 -04:00
class UNetConnection * AGameplayDebuggingReplicator : : GetNetConnection ( ) const
2014-06-10 13:56:35 -04:00
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2015-02-23 15:58:14 -05:00
if ( LocalPlayerOwner & & LocalPlayerOwner - > IsPendingKill ( ) = = false & & IsPendingKill ( ) = = false )
2014-06-10 13:56:35 -04:00
{
2014-06-25 09:28:40 -04:00
return LocalPlayerOwner - > GetNetConnection ( ) ;
2014-06-10 13:56:35 -04:00
}
2015-02-27 09:26:32 -05:00
# endif
2014-06-10 13:56:35 -04:00
return NULL ;
}
2015-02-19 07:14:31 -05:00
bool AGameplayDebuggingReplicator : : ClientEnableTargetSelection_Validate ( bool , APlayerController * )
2014-06-10 13:56:35 -04:00
{
return true ;
}
2015-02-19 07:14:31 -05:00
void AGameplayDebuggingReplicator : : ClientEnableTargetSelection_Implementation ( bool bEnable , APlayerController * Context )
2014-06-10 13:56:35 -04:00
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-06-25 09:28:40 -04:00
if ( GetDebugComponent ( ) )
2014-06-10 13:56:35 -04:00
{
2015-02-19 07:14:31 -05:00
GetDebugComponent ( ) - > ClientEnableTargetSelection ( bEnable ) ;
2014-06-10 13:56:35 -04:00
}
2015-02-27 09:26:32 -05:00
# endif
2014-06-10 13:56:35 -04:00
}
bool AGameplayDebuggingReplicator : : ClientReplicateMessage_Validate ( class AActor * Actor , uint32 InMessage , uint32 DataView )
{
return true ;
}
void AGameplayDebuggingReplicator : : ClientReplicateMessage_Implementation ( class AActor * Actor , uint32 InMessage , uint32 DataView )
{
}
bool AGameplayDebuggingReplicator : : ServerReplicateMessage_Validate ( class AActor * Actor , uint32 InMessage , uint32 DataView )
{
return true ;
}
void AGameplayDebuggingReplicator : : ServerReplicateMessage_Implementation ( class AActor * Actor , uint32 InMessage , uint32 DataView )
{
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-09-09 12:17:30 -04:00
if ( ( EDebugComponentMessage : : Type ) InMessage = = EDebugComponentMessage : : DeactivateReplilcation )
{
2015-02-19 07:14:31 -05:00
ServerSetActorToDebug ( NULL ) ;
2014-09-09 12:17:30 -04:00
MarkComponentsRenderStateDirty ( ) ;
}
2014-06-25 09:28:40 -04:00
if ( GetDebugComponent ( ) )
2014-06-10 13:56:35 -04:00
{
2014-06-25 09:28:40 -04:00
GetDebugComponent ( ) - > ServerReplicateData ( ( EDebugComponentMessage : : Type ) InMessage , ( EAIDebugDrawDataView : : Type ) DataView ) ;
2014-06-10 13:56:35 -04:00
}
# endif //!(UE_BUILD_SHIPPING || UE_BUILD_TEST)
}
bool AGameplayDebuggingReplicator : : IsDrawEnabled ( )
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-06-10 13:56:35 -04:00
return bEnabledDraw & & GetWorld ( ) & & GetNetMode ( ) ! = ENetMode : : NM_DedicatedServer ;
2015-02-27 09:26:32 -05:00
# else
return false ;
# endif
2014-06-10 13:56:35 -04:00
}
void AGameplayDebuggingReplicator : : EnableDraw ( bool bEnable )
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-06-10 13:56:35 -04:00
bEnabledDraw = bEnable ;
2014-06-25 09:28:40 -04:00
if ( AHUD * const GameHUD = LocalPlayerOwner ? LocalPlayerOwner - > GetHUD ( ) : NULL )
2014-06-10 13:56:35 -04:00
{
GameHUD - > bShowHUD = bEnable ? false : true ;
}
GEngine - > bEnableOnScreenDebugMessages = bEnable ? false : true ;
2014-09-09 12:17:30 -04:00
if ( DebugComponent )
{
const bool bEnabledEQSView = GameplayDebuggerSettings ( this ) . CheckFlag ( EAIDebugDrawDataView : : EQS ) ;
DebugComponent - > EnableClientEQSSceneProxy ( bEnable & & bEnabledEQSView ? true : false ) ;
DebugComponent - > MarkRenderStateDirty ( ) ;
}
2015-02-27 09:26:32 -05:00
# endif
2014-06-10 13:56:35 -04:00
}
bool AGameplayDebuggingReplicator : : IsToolCreated ( )
{
UGameplayDebuggingControllerComponent * GDC = FindComponentByClass < UGameplayDebuggingControllerComponent > ( ) ;
2014-06-25 09:28:40 -04:00
return LocalPlayerOwner & & GDC ;
2014-06-10 13:56:35 -04:00
}
2014-06-25 09:28:40 -04:00
void AGameplayDebuggingReplicator : : CreateTool ( )
2014-06-10 13:56:35 -04:00
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-06-10 13:56:35 -04:00
if ( GetWorld ( ) & & GetNetMode ( ) ! = ENetMode : : NM_DedicatedServer )
{
UGameplayDebuggingControllerComponent * GDC = FindComponentByClass < UGameplayDebuggingControllerComponent > ( ) ;
if ( ! GDC )
{
2014-12-11 11:44:40 -05:00
DebugComponentControllerClass = StaticLoadClass ( UGameplayDebuggingControllerComponent : : StaticClass ( ) , NULL , * DebugComponentControllerClassName , NULL , LOAD_None , NULL ) ;
if ( ! DebugComponentControllerClass . IsValid ( ) )
{
DebugComponentControllerClass = AGameplayDebuggingHUDComponent : : StaticClass ( ) ;
}
2015-02-03 05:40:57 -05:00
GDC = NewObject < UGameplayDebuggingControllerComponent > ( this , DebugComponentControllerClass . Get ( ) ) ;
2014-06-25 09:28:40 -04:00
GDC - > SetPlayerOwner ( LocalPlayerOwner ) ;
2014-06-10 13:56:35 -04:00
GDC - > RegisterComponent ( ) ;
}
}
2015-02-27 09:26:32 -05:00
# endif
2014-06-10 13:56:35 -04:00
}
void AGameplayDebuggingReplicator : : EnableTool ( )
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-06-10 13:56:35 -04:00
if ( GetWorld ( ) & & GetNetMode ( ) ! = ENetMode : : NM_DedicatedServer )
{
UGameplayDebuggingControllerComponent * GDC = FindComponentByClass < UGameplayDebuggingControllerComponent > ( ) ;
if ( GDC )
{
// simulate key press
GDC - > OnActivationKeyPressed ( ) ;
GDC - > OnActivationKeyReleased ( ) ;
}
}
2015-02-27 09:26:32 -05:00
# endif
2014-06-10 13:56:35 -04:00
}
2014-08-07 17:34:29 -04:00
void AGameplayDebuggingReplicator : : TickActor ( float DeltaTime , enum ELevelTick TickType , FActorTickFunction & ThisTickFunction )
{
Super : : TickActor ( DeltaTime , TickType , ThisTickFunction ) ;
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-08-07 17:34:29 -04:00
UWorld * World = GetWorld ( ) ;
if ( ! IsGlobalInWorld ( ) | | ! World | | GetNetMode ( ) = = ENetMode : : NM_Client | | ! IGameplayDebugger : : IsAvailable ( ) )
{
// global level replicator don't have any local player and it's prepared to work only on servers
return ;
}
UGameInstance * GameInstance = World - > GetGameInstance ( ) ;
if ( ! GameInstance | | ! World - > IsGameWorld ( ) )
{
return ;
}
PlayerControllersUpdateDelay - = DeltaTime ;
if ( PlayerControllersUpdateDelay < = 0 )
{
for ( FConstPlayerControllerIterator Iterator = World - > GetPlayerControllerIterator ( ) ; Iterator ; Iterator + + )
{
APlayerController * PC = * Iterator ;
if ( PC )
{
IGameplayDebugger & Debugger = IGameplayDebugger : : Get ( ) ;
Debugger . CreateGameplayDebuggerForPlayerController ( PC ) ;
}
}
PlayerControllersUpdateDelay = 5 ;
}
2015-02-27 09:26:32 -05:00
# endif
2014-08-07 17:34:29 -04:00
}
2015-02-19 07:14:31 -05:00
bool AGameplayDebuggingReplicator : : ServerSetActorToDebug_Validate ( AActor * InActor )
{
return true ;
}
void AGameplayDebuggingReplicator : : ServerSetActorToDebug_Implementation ( AActor * InActor )
2014-08-07 17:34:29 -04:00
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-09-09 12:17:30 -04:00
if ( LastSelectedActorToDebug ! = InActor )
2014-08-07 17:34:29 -04:00
{
2014-09-09 12:17:30 -04:00
LastSelectedActorToDebug = InActor ;
2014-08-07 17:34:29 -04:00
UGameplayDebuggingComponent : : OnDebuggingTargetChangedDelegate . Broadcast ( InActor , InActor ? InActor - > IsSelected ( ) : false ) ;
APawn * TargetPawn = Cast < APawn > ( InActor ) ;
if ( TargetPawn )
{
FBehaviorTreeDelegates : : OnDebugSelected . Broadcast ( TargetPawn ) ;
}
}
2015-03-04 13:46:55 -05:00
if ( UGameplayDebuggingComponent * DebuggingComponent = GetDebugComponent ( ) )
2014-08-07 17:34:29 -04:00
{
2015-03-04 13:46:55 -05:00
DebuggingComponent - > SetActorToDebug ( InActor ) ;
2014-08-07 17:34:29 -04:00
}
2015-02-27 09:26:32 -05:00
# endif
2014-08-07 17:34:29 -04:00
}
2014-06-10 13:56:35 -04:00
void AGameplayDebuggingReplicator : : OnDebugAIDelegate ( class UCanvas * Canvas , class APlayerController * PC )
{
2015-02-27 09:26:32 -05:00
# if WITH_EDITOR && !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-06-10 13:56:35 -04:00
if ( ! GIsEditor )
{
return ;
}
2014-08-07 17:34:29 -04:00
if ( ! LocalPlayerOwner | | IsGlobalInWorld ( ) )
{
return ;
}
2014-06-10 13:56:35 -04:00
UEditorEngine * EEngine = Cast < UEditorEngine > ( GEngine ) ;
if ( GFrameNumber = = LastDrawAtFrame | | ! EEngine | | ! EEngine - > bIsSimulatingInEditor )
{
return ;
}
2014-11-28 09:26:40 -05:00
if ( ! Canvas | | ! Canvas - > SceneView | | Canvas - > SceneView - > bIsGameView = = false )
{
return ;
}
2014-06-10 13:56:35 -04:00
LastDrawAtFrame = GFrameNumber ;
FEngineShowFlags EngineShowFlags = Canvas & & Canvas - > SceneView & & Canvas - > SceneView - > Family ? Canvas - > SceneView - > Family - > EngineShowFlags : FEngineShowFlags ( GIsEditor ? EShowFlagInitMode : : ESFIM_Editor : EShowFlagInitMode : : ESFIM_Game ) ;
if ( ! EngineShowFlags . DebugAI )
{
return ;
}
2014-09-10 05:48:38 -04:00
EnableDraw ( true ) ;
2014-06-10 13:56:35 -04:00
UWorld * World = GetWorld ( ) ;
2015-03-04 13:46:55 -05:00
UGameplayDebuggingComponent * DebuggingComponent = GetDebugComponent ( ) ;
if ( World & & DebuggingComponent & & DebuggingComponent - > GetOwnerRole ( ) = = ROLE_Authority )
2014-06-10 13:56:35 -04:00
{
2014-08-21 20:30:51 -04:00
UGameplayDebuggingControllerComponent * GDC = FindComponentByClass < UGameplayDebuggingControllerComponent > ( ) ;
TArray < int32 > OryginalReplicateViewDataCounters ;
2015-03-04 13:46:55 -05:00
OryginalReplicateViewDataCounters = DebuggingComponent - > ReplicateViewDataCounters ;
2015-02-23 15:58:14 -05:00
for ( uint32 Index = 0 ; Index < EAIDebugDrawDataView : : MAX ; + + Index )
2014-08-21 20:30:51 -04:00
{
2015-03-04 13:46:55 -05:00
DebuggingComponent - > ReplicateViewDataCounters [ Index ] = GameplayDebuggerSettings ( this ) . CheckFlag ( ( EAIDebugDrawDataView : : Type ) Index ) ? 1 : 0 ;
2014-08-21 20:30:51 -04:00
}
2014-06-11 09:13:09 -04:00
2014-06-10 13:56:35 -04:00
// looks like Simulate in UE4 Editor - let's find selected Pawn to debug
2014-09-09 12:17:30 -04:00
AActor * FullSelectedTarget = NULL ;
2014-06-10 13:56:35 -04:00
for ( FConstPawnIterator Iterator = World - > GetPawnIterator ( ) ; Iterator ; + + Iterator )
{
AActor * NewTarget = Cast < AActor > ( * Iterator ) ;
2014-09-09 12:17:30 -04:00
if ( NewTarget - > IsSelected ( ) & & ! FullSelectedTarget )
{
FullSelectedTarget = NewTarget ;
continue ;
}
2014-06-10 13:56:35 -04:00
//We needs to collect data manually in Simulate
2015-03-04 13:46:55 -05:00
DebuggingComponent - > SetActorToDebug ( NewTarget ) ;
DebuggingComponent - > CollectDataToReplicate ( NewTarget - > IsSelected ( ) ) ;
2014-06-10 13:56:35 -04:00
DrawDebugData ( Canvas , PC ) ;
}
2014-06-11 09:13:09 -04:00
2014-09-09 12:17:30 -04:00
const AActor * OldActor = LastSelectedActorToDebug ;
2015-02-19 07:14:31 -05:00
ServerSetActorToDebug ( FullSelectedTarget ) ;
2014-09-09 12:17:30 -04:00
if ( FullSelectedTarget )
2014-06-11 09:13:09 -04:00
{
2015-03-04 13:46:55 -05:00
DebuggingComponent - > CollectDataToReplicate ( true ) ;
DebuggingComponent - > SetEQSIndex ( ActiveEQSIndex ) ;
2014-09-09 12:17:30 -04:00
DrawDebugData ( Canvas , PC ) ;
}
if ( GetSelectedActorToDebug ( ) ! = OldActor )
{
2015-03-04 13:46:55 -05:00
DebuggingComponent - > MarkRenderStateDirty ( ) ;
2014-06-11 09:13:09 -04:00
}
2014-08-21 20:30:51 -04:00
2015-03-04 13:46:55 -05:00
DebuggingComponent - > ReplicateViewDataCounters = OryginalReplicateViewDataCounters ;
2014-08-21 20:30:51 -04:00
2014-06-10 13:56:35 -04:00
}
# endif
}
void AGameplayDebuggingReplicator : : DrawDebugDataDelegate ( class UCanvas * Canvas , class APlayerController * PC )
{
2015-06-02 11:44:27 -04:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-06-10 13:56:35 -04:00
if ( GetWorld ( ) = = NULL | | IsPendingKill ( ) | | Canvas = = NULL | | Canvas - > IsPendingKill ( ) )
{
return ;
}
2014-08-25 11:07:28 -04:00
if ( ! LocalPlayerOwner | | IsGlobalInWorld ( ) | | ! IsDrawEnabled ( ) )
2014-08-07 17:34:29 -04:00
{
return ;
}
2014-06-10 13:56:35 -04:00
if ( Canvas - > SceneView ! = NULL & & ! Canvas - > SceneView - > bIsGameView )
{
return ;
}
if ( GFrameNumber = = LastDrawAtFrame )
{
return ;
}
LastDrawAtFrame = GFrameNumber ;
2014-06-25 09:28:40 -04:00
const UGameplayDebuggingControllerComponent * GDC = FindComponentByClass < UGameplayDebuggingControllerComponent > ( ) ;
2014-08-25 11:07:28 -04:00
if ( ! GDC )
2014-06-10 13:56:35 -04:00
{
return ;
}
if ( GetWorld ( ) - > bPlayersOnly & & Role = = ROLE_Authority )
{
for ( FConstPawnIterator Iterator = GetWorld ( ) - > GetPawnIterator ( ) ; Iterator ; + + Iterator )
{
AActor * NewTarget = Cast < AActor > ( * Iterator ) ;
2014-08-07 17:34:29 -04:00
if ( NewTarget - > IsSelected ( ) & & GetSelectedActorToDebug ( ) ! = NewTarget )
{
2015-02-19 07:14:31 -05:00
ServerSetActorToDebug ( NewTarget ) ;
2014-08-07 17:34:29 -04:00
}
2014-06-25 09:28:40 -04:00
GetDebugComponent ( ) - > SetActorToDebug ( NewTarget ) ;
GetDebugComponent ( ) - > CollectDataToReplicate ( true ) ;
2014-06-10 13:56:35 -04:00
}
}
DrawDebugData ( Canvas , PC ) ;
2015-02-27 09:26:32 -05:00
# endif
2014-06-10 13:56:35 -04:00
}
void AGameplayDebuggingReplicator : : DrawDebugData ( class UCanvas * Canvas , class APlayerController * PC )
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2014-08-07 17:34:29 -04:00
if ( ! LocalPlayerOwner )
{
return ;
}
2015-04-13 06:23:53 -04:00
bool bAllowToDraw = Canvas & & Canvas - > SceneView & & ( Canvas - > SceneView - > ViewActor = = LocalPlayerOwner - > AcknowledgedPawn | | Canvas - > SceneView - > ViewActor = = LocalPlayerOwner - > GetPawnOrSpectator ( ) ) ;
2014-06-25 09:28:40 -04:00
if ( ! bAllowToDraw )
{
2015-04-13 06:23:53 -04:00
// check for spectator debug camera
UGameplayDebuggingControllerComponent * GDC = FindComponentByClass < UGameplayDebuggingControllerComponent > ( ) ;
2015-08-05 15:54:57 -04:00
// bAllowToDraw here used to check GDC->GetDebugCameraController().IsValid(), but it doesn't seem to be necessary, and it was preventing display in some desired cases.
bAllowToDraw = GDC & & ( Canvas - > SceneView - > ViewActor - > GetInstigatorController ( ) = = GDC - > GetDebugCameraController ( ) . Get ( ) ) ;
2015-04-13 06:23:53 -04:00
if ( ! bAllowToDraw )
{
return ;
}
2014-06-25 09:28:40 -04:00
}
2014-06-10 13:56:35 -04:00
if ( ! DebugRenderer . IsValid ( ) & & DebugComponentHUDClass . IsValid ( ) )
{
FActorSpawnParameters SpawnInfo ;
SpawnInfo . Owner = NULL ;
SpawnInfo . Instigator = NULL ;
2015-07-15 13:13:35 -04:00
SpawnInfo . SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod : : AlwaysSpawn ;
2014-06-10 13:56:35 -04:00
DebugRenderer = GetWorld ( ) - > SpawnActor < AGameplayDebuggingHUDComponent > ( DebugComponentHUDClass . Get ( ) , SpawnInfo ) ;
DebugRenderer - > SetCanvas ( Canvas ) ;
2014-06-25 09:28:40 -04:00
DebugRenderer - > SetPlayerOwner ( LocalPlayerOwner ) ;
2014-06-10 13:56:35 -04:00
DebugRenderer - > SetWorld ( GetWorld ( ) ) ;
}
if ( DebugRenderer ! = NULL )
{
DebugRenderer - > SetCanvas ( Canvas ) ;
DebugRenderer - > Render ( ) ;
}
# endif
}
2015-01-15 11:57:16 -05:00
void AGameplayDebuggingReplicator : : DebugNextPawn ( UClass * CompareClass , APawn * CurrentPawn )
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2015-01-15 11:57:16 -05:00
APawn * LastSeen = nullptr ;
APawn * FirstSeen = nullptr ;
// Search through the list looking for the next one of this type
for ( FConstPawnIterator It = GetWorld ( ) - > GetPawnIterator ( ) ; It ; It + + )
{
APawn * IterPawn = * It ;
if ( IterPawn - > IsA ( CompareClass ) )
{
if ( LastSeen = = CurrentPawn )
{
2015-02-19 07:14:31 -05:00
ServerSetActorToDebug ( IterPawn ) ;
2015-01-15 11:57:16 -05:00
return ;
}
LastSeen = IterPawn ;
if ( FirstSeen = = nullptr )
{
FirstSeen = IterPawn ;
}
}
}
// See if we need to wrap around the list
if ( FirstSeen ! = nullptr )
{
2015-02-19 07:14:31 -05:00
ServerSetActorToDebug ( FirstSeen ) ;
2015-01-15 11:57:16 -05:00
}
2015-02-27 09:26:32 -05:00
# endif
2015-01-15 11:57:16 -05:00
}
void AGameplayDebuggingReplicator : : DebugPrevPawn ( UClass * CompareClass , APawn * CurrentPawn )
{
2015-02-27 09:26:32 -05:00
# if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
2015-01-15 11:57:16 -05:00
APawn * LastSeen = nullptr ;
APawn * PrevSeen = nullptr ;
APawn * FirstSeen = nullptr ;
// Search through the list looking for the prev one of this type
for ( FConstPawnIterator It = GetWorld ( ) - > GetPawnIterator ( ) ; It ; It + + )
{
APawn * IterPawn = * It ;
if ( IterPawn - > IsA ( CompareClass ) )
{
if ( LastSeen = = CurrentPawn & & FirstSeen ! = CurrentPawn )
{
2015-02-19 07:14:31 -05:00
ServerSetActorToDebug ( PrevSeen ) ;
2015-01-15 11:57:16 -05:00
return ;
}
PrevSeen = LastSeen ;
LastSeen = IterPawn ;
if ( FirstSeen = = nullptr )
{
FirstSeen = IterPawn ;
if ( CurrentPawn = = nullptr )
{
2015-02-19 07:14:31 -05:00
ServerSetActorToDebug ( FirstSeen ) ;
2015-01-15 11:57:16 -05:00
return ;
}
}
}
}
// Wrap from the beginning to the end
if ( FirstSeen = = CurrentPawn )
{
2015-02-19 07:14:31 -05:00
ServerSetActorToDebug ( LastSeen ) ;
2015-01-15 11:57:16 -05:00
}
// Handle getting the previous to the end
else if ( LastSeen = = CurrentPawn )
{
2015-02-19 07:14:31 -05:00
ServerSetActorToDebug ( PrevSeen ) ;
2015-01-15 11:57:16 -05:00
}
2015-02-27 09:26:32 -05:00
# endif
2015-01-15 11:57:16 -05:00
}