Skip to content

Commit

Permalink
Merge pull request #47 from xthebat/37-debug-draw-line
Browse files Browse the repository at this point in the history
Added console/configuration file parameters
  • Loading branch information
xthebat authored Nov 3, 2023
2 parents c9d9e2d + 1fdd6df commit 05bff10
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 59 deletions.
20 changes: 14 additions & 6 deletions Config/DefaultGame.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
[/Script/EngineSettings.GeneralProjectSettings]
ProjectID=BACFB3F848AE10EDFB548D9F7BDABCA4
ProjectName=Cloud9
ProjectID = BACFB3F848AE10EDFB548D9F7BDABCA4
ProjectName = Cloud9

[/Script/Cloud9.Cloud9Character]
FixedCameraPitch=-45.0
FixedCameraDistance=1500.0
FixedCameraPitch = -45.0
FixedCameraDistance = 1500.0

[StartupActions]
bAddPacks=True
InsertPack=(PackSource="StarterContent.upack",PackName="StarterContent")
bAddPacks = True
InsertPack = (PackSource="StarterContent.upack",PackName="StarterContent")

[/Script/Cloud9.Cloud9DeveloperSettings]
bIsDrawHitCursorLine = False
bIsDrawDeprojectedCursorLine = False
bIsShowMouseCursor = True
NetGraph = 0
bIsShowMouseCursor=False
NetGraph=1

Binary file modified Content/Blueprints/Character/BP_Cloud9Character.uasset
Binary file not shown.
Binary file modified Content/Blueprints/Game/BP_Cloud9Console.uasset
Binary file not shown.
68 changes: 36 additions & 32 deletions Source/Cloud9/Character/Cloud9Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "UObject/ConstructorHelpers.h"
#include "Camera/CameraComponent.h"
#include "Cloud9/Cloud9.h"
#include "Cloud9/Game/Cloud9DeveloperSettings.h"
#include "Cloud9/Game/Cloud9PlayerController.h"
#include "Components/DecalComponent.h"
#include "Components/CapsuleComponent.h"
Expand All @@ -15,6 +16,7 @@
#include "GameFramework/SpringArmComponent.h"
#include "Materials/Material.h"
#include "Engine/World.h"
#include "GameFramework/GameUserSettings.h"
#include "Kismet/KismetMathLibrary.h"

class UCloud9SpringArmComponent;
Expand Down Expand Up @@ -107,38 +109,40 @@ void ACloud9Character::SetViewDirection(const FHitResult& HitResult, bool bIsHit
SetCursorIsHidden(false);
}

FVector WorldLocation;
FVector WorldDirection;
FVector2D MousePosition;

GetCloud9Controller()->GetMousePosition(MousePosition.X, MousePosition.Y);
GetCloud9Controller()->DeprojectScreenPositionToWorld(
MousePosition.X,
MousePosition.Y,
WorldLocation,
WorldDirection);

DrawDebugLine(
GetWorld(),
GetActorLocation(),
WorldLocation,
FColor::Red,
false,
/*LifeTime=*/0.0,
/*DepthPriority=*/0,
/*Thickness=*/0.f);

DrawDebugLine(
GetWorld(),
GetActorLocation(),
HitResult.Location,
FColor::Green,
false,
/*LifeTime=*/0.0,
/*DepthPriority=*/0,
/*Thickness=*/0.f);

// UE_LOG(LogCloud9, Display, TEXT("%s"), *HitResult.Location.ToString());
const auto Settings = UCloud9DeveloperSettings::GetCloud9DeveloperSettings();

if (Settings->bIsDrawHitCursorLine)
{
DrawDebugLine(
GetWorld(),
GetActorLocation(),
HitResult.Location,
FColor::Green,
false,
0.0);
}

if (Settings->bIsDrawDeprojectedCursorLine)
{
FVector WorldLocation;
FVector WorldDirection;
FVector2D MousePosition;

GetCloud9Controller()->GetMousePosition(MousePosition.X, MousePosition.Y);
GetCloud9Controller()->DeprojectScreenPositionToWorld(
MousePosition.X,
MousePosition.Y,
WorldLocation,
WorldDirection);

DrawDebugLine(
GetWorld(),
GetActorLocation(),
WorldLocation,
FColor::Red,
false,
0.0);
}

if (bIsHitValid)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Cloud9/Character/Cloud9Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "Cloud9Character.generated.h"


UCLASS(Blueprintable)
UCLASS(config=Game, Blueprintable)
class ACloud9Character : public ACharacter
{
GENERATED_BODY()
Expand Down
1 change: 1 addition & 0 deletions Source/Cloud9/Cloud9.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public Cloud9(ReadOnlyTargetRules Target) : base(Target)
"InputCore",
"HeadMountedDisplay",
"NavigationSystem",
"DeveloperSettings",
"AIModule",
"Niagara"
});
Expand Down
1 change: 1 addition & 0 deletions Source/Cloud9/Game/Cloud9DeveloperSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Cloud9DeveloperSettings.h"
47 changes: 47 additions & 0 deletions Source/Cloud9/Game/Cloud9DeveloperSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include "CoreMinimal.h"
#include "Cloud9/Cloud9.h"
#include "Cloud9DeveloperSettings.generated.h"

UCLASS(Config=Game, defaultconfig, meta = (DisplayName="Save Game Settings"))
class CLOUD9_API UCloud9DeveloperSettings : public UDeveloperSettings
{
GENERATED_BODY()

public:
UFUNCTION(BlueprintCallable, Category=Settings)
static const UCloud9DeveloperSettings* GetCloud9DeveloperSettings()
{
static auto bIsLoaded = false;
static const auto Settings = GetDefault<UCloud9DeveloperSettings>();

if (!bIsLoaded)
{
UE_LOG(LogCloud9, Display, TEXT("IsDrawHitCursorLine: %d"), Settings->bIsShowMouseCursor);
UE_LOG(LogCloud9, Display, TEXT("IsDrawDeprojectedCursorLine: %d"), Settings->bIsDrawDeprojectedCursorLine);
UE_LOG(LogCloud9, Display, TEXT("IsShowMouseCursor: %d"), Settings->bIsShowMouseCursor);
UE_LOG(LogCloud9, Display, TEXT("NetGraph: %d"), Settings->NetGraph);
bIsLoaded = true;
}

return Settings;
}

UFUNCTION(BlueprintCallable)
void Save() { UpdateDefaultConfigFile(); }

// Debug

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool bIsDrawHitCursorLine;

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool bIsDrawDeprojectedCursorLine;

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Debug")
bool bIsShowMouseCursor;

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Debug")
int NetGraph;
};
11 changes: 6 additions & 5 deletions Source/Cloud9/Game/Cloud9GameMode.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "Cloud9GameMode.h"

#include "Cloud9DeveloperSettings.h"
#include "Cloud9PlayerController.h"
#include "Cloud9/Character/Cloud9Character.h"
#include "UObject/ConstructorHelpers.h"
Expand All @@ -9,24 +11,23 @@ ACloud9GameMode::ACloud9GameMode()
PrimaryActorTick.bStartWithTickEnabled = true;
PlayerControllerClass = ACloud9PlayerController::StaticClass();
DefaultPawnClass = ACloud9Character::StaticClass();
NetGraph = 1;
}

ACloud9Character* ACloud9GameMode::GetCharacter() const
{
return Cast<ACloud9Character>(GetWorld()->GetFirstPlayerController()->GetCharacter());
}

void ACloud9GameMode::SetNetGraph(int Value) { NetGraph = Value; }

void ACloud9GameMode::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);

if (NetGraph > 0)
const auto Settings = UCloud9DeveloperSettings::GetCloud9DeveloperSettings();

if (Settings->NetGraph > 0)
{
const auto Fps = 1.0f / DeltaSeconds;

const auto Location = GetCharacter()->GetActorLocation();
const auto Velocity = GetCharacter()->GetVelocity();
const auto Text = FString::Printf(
Expand Down
10 changes: 1 addition & 9 deletions Source/Cloud9/Game/Cloud9GameMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "GameFramework/GameModeBase.h"
#include "Cloud9GameMode.generated.h"

class UCloud9DeveloperSettings;
class ACloud9Character;

UCLASS(minimalapi)
Expand All @@ -19,15 +20,6 @@ class ACloud9GameMode : public AGameModeBase
UFUNCTION(BlueprintCallable)
ACloud9Character* GetCharacter() const;

UFUNCTION(BlueprintCallable)
void SetNetGraph(int Value);

public:
virtual void Tick(float DeltaSeconds) override;

private:
int NetGraph;
};



26 changes: 20 additions & 6 deletions Source/Cloud9/Game/Cloud9PlayerController.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Cloud9PlayerController.h"

#include "Cloud9DeveloperSettings.h"
#include "Cloud9KeyboardController.h"
#include "Cloud9MouseController.h"
#include "Cloud9/Console/Cloud9ConsoleComponent.h"
Expand All @@ -11,7 +12,6 @@ const FName ACloud9PlayerController::MouseControllerName = TEXT("MouseController

ACloud9PlayerController::ACloud9PlayerController()
{
bShowMouseCursor = true;
DefaultMouseCursor = EMouseCursor::Crosshairs;

ConsoleComponent = CreateDefaultSubobject<UCloud9ConsoleComponent>(ConsoleName);
Expand All @@ -22,6 +22,9 @@ ACloud9PlayerController::ACloud9PlayerController()
void ACloud9PlayerController::PlayerTick(float DeltaTime)
{
Super::PlayerTick(DeltaTime);

const auto Settings = UCloud9DeveloperSettings::GetCloud9DeveloperSettings();
bShowMouseCursor = Settings->bIsShowMouseCursor;
}

void ACloud9PlayerController::SetupInputComponent()
Expand All @@ -30,7 +33,7 @@ void ACloud9PlayerController::SetupInputComponent()

InputComponent->BindAxis("MoveForward", KeyboardController, &UCloud9KeyboardController::OnMoveForward);
InputComponent->BindAxis("MoveRight", KeyboardController, &UCloud9KeyboardController::OnMoveRight);

InputComponent->BindAction("Crouch", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnCrouchPressed);
InputComponent->BindAction("Crouch", IE_Released, KeyboardController, &UCloud9KeyboardController::OnCrouchReleased);

Expand All @@ -39,17 +42,26 @@ void ACloud9PlayerController::SetupInputComponent()

InputComponent->BindAction("Jump", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnJumpPressed);
InputComponent->BindAction("Jump", IE_Released, KeyboardController, &UCloud9KeyboardController::OnJumpReleased);

InputComponent->BindAxis("CameraZoom", MouseController, &UCloud9MouseController::OnCameraZoom);
InputComponent->BindAction("CameraRotation", IE_Pressed, MouseController, &UCloud9MouseController::OnCameraRotationPressed);
InputComponent->BindAction("CameraRotation", IE_Released, MouseController, &UCloud9MouseController::OnCameraRotationReleased);
InputComponent->BindAction(
"CameraRotation",
IE_Pressed,
MouseController,
&UCloud9MouseController::OnCameraRotationPressed);

InputComponent->BindAction(
"CameraRotation",
IE_Released,
MouseController,
&UCloud9MouseController::OnCameraRotationReleased);

InputComponent->BindAction("Slot1", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnSlot1);
InputComponent->BindAction("Slot2", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnSlot2);
InputComponent->BindAction("Slot3", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnSlot3);
InputComponent->BindAction("Slot4", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnSlot4);
InputComponent->BindAction("Slot5", IE_Pressed, KeyboardController, &UCloud9KeyboardController::OnSlot5);

InputComponent->BindAction("Reload", IE_Pressed, KeyboardController, &UCloud9KeyboardController::Reload);

KeyboardController->OnMoveDelegate.AddDynamic(MouseController, &UCloud9MouseController::OnCharacterMove);
Expand All @@ -60,7 +72,9 @@ bool ACloud9PlayerController::ProcessConsoleExec(const TCHAR* Cmd, FOutputDevice
bool bHandled = Super::ProcessConsoleExec(Cmd, Ar, Executor);

if (!bHandled && ConsoleComponent != nullptr)
{
bHandled |= ConsoleComponent->ProcessConsoleExec(Cmd, Ar, Executor);
}

return bHandled;
}

0 comments on commit 05bff10

Please sign in to comment.