Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added door actors and fixed doors on de_shortdust #66

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Config/DefaultGame.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ bAddPacks = True
InsertPack = (PackSource="StarterContent.upack",PackName="StarterContent")

[/Script/Cloud9.Cloud9DeveloperSettings]
r.IsDrawHitCursorLine=0
r.IsDrawDeprojectedCursorLine=1
r.IsShowMouseCursor=0
r.NetGraph=1
r.CameraVerticalSpeedLag=-1.000000
bIsDrawHitCursorLine=0
bIsDrawDeprojectedCursorLine=0
bIsShowMouseCursor=0
NetGraph=1
CameraVerticalSpeedLag=0.000000
UnUsedEnum=Everything
UnUsedStruct=(IntField0=3,FloatField1=0.000000)

Binary file modified Content/Blueprints/Character/BP_Cloud9Character.uasset
Binary file not shown.
Binary file added Content/Maps/OpenDoorDescriptor.uasset
Binary file not shown.
Binary file modified Content/Maps/de_shortdust.umap
Binary file not shown.
125 changes: 125 additions & 0 deletions Source/Cloud9/Environment/Cloud9LinearDoor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Copyright (c) 2023 Alexei Gladkikh
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.


#include "Cloud9LinearDoor.h"

#include "Cloud9/Cloud9.h"
#include "Cloud9/Tools/Cloud9ToolsLibrary.h"
#include "Cloud9/Tools/Extensions/AActor.h"

ACloud9LinearDoor::ACloud9LinearDoor()
{
PrimaryActorTick.bCanEverTick = true;

bIsOpen = false;
Speed = 1.0f;
Distance = 0.0f;
Direction = EDirection::Right;

bIsMoving = false;
DirectionVector = FVector::ZeroVector;

SetMobility(EComponentMobility::Movable);
}

void ACloud9LinearDoor::Open()
{
if (!bIsOpen)
{
Toggle();
}
}

void ACloud9LinearDoor::Close()
{
if (bIsOpen)
{
Toggle();
}
}

void ACloud9LinearDoor::Toggle()
{
bIsMoving = true;
Shift = (TargetPosition - OriginPosition) * Speed;
}

void ACloud9LinearDoor::BeginPlay()
{
Super::BeginPlay();

let Transform = GetActorTransform();
let LocalVector = this | EAActor::ToDirectionVector(Direction);
DirectionVector = Transform.InverseTransformVector(LocalVector);
DirectionVector.Normalize();

if (DirectionVector.IsZero())
{
SetActorTickEnabled(false);
UE_LOG(LogCloud9, Error, TEXT("Door '%s' can't moved due to incorrect direction vector"), *GetName());
}

if (Speed <= 0.0f)
{
SetActorTickEnabled(false);
UE_LOG(LogCloud9, Warning, TEXT("Door '%s' can't moved due to speed <= 0.0f"), *GetName());
}

if (Distance <= 0.0f)
{
var Origin = FVector::ZeroVector;
var Extents = FVector::ZeroVector;
GetActorBounds(true, Origin, Extents, true);
Distance = (2.0f * Extents * DirectionVector).Size();
}

let ActualDistance = Distance - Extent;

UE_LOG(LogCloud9, Display, TEXT("Door '%s' distance = '%f'"), *GetName(), ActualDistance);

let Sign = bIsOpen ? -1 : 1;
OriginPosition = Transform.GetLocation();
TargetPosition = OriginPosition + Sign * DirectionVector * ActualDistance;
}

void ACloud9LinearDoor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

if (bIsMoving)
{
var NewPosition = GetActorLocation() + Shift * DeltaTime;

if (FVector::DistSquared(OriginPosition, GetActorLocation()) > FMath::Square(Distance - Extent))
{
bIsOpen = !bIsOpen;
bIsMoving = false;
NewPosition = TargetPosition;
TargetPosition = OriginPosition;
OriginPosition = NewPosition;
}

SetActorLocation(NewPosition);
}
}
92 changes: 92 additions & 0 deletions Source/Cloud9/Environment/Cloud9LinearDoor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (c) 2023 Alexei Gladkikh
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

#pragma once

#include "CoreMinimal.h"
#include "Cloud9/Tools/Cloud9Direction.h"
#include "Engine/StaticMeshActor.h"
#include "Cloud9LinearDoor.generated.h"


UCLASS()
class CLOUD9_API ACloud9LinearDoor : public AStaticMeshActor
{
GENERATED_BODY()

public: // functions
ACloud9LinearDoor();

UFUNCTION(BlueprintCallable)
void Open();

UFUNCTION(BlueprintCallable)
void Close();

UFUNCTION(BlueprintCallable)
void Toggle();

protected: // functions
virtual void BeginPlay() override;

public: // functions
virtual void Tick(float DeltaTime) override;

protected: // variables
bool bIsMoving;

FVector OriginPosition;
FVector TargetPosition;
FVector Shift;
FVector DirectionVector;

/**
* Whether door is currently open or closed
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Door, meta = (AllowPrivateAccess = "true"))
bool bIsOpen;

/**
* Direction where to move door
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Door, meta = (AllowPrivateAccess = "true"))
EDirection Direction;

/**
* Door moving speed when open or close
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Door, meta = (AllowPrivateAccess = "true"))
float Speed;

/**
* How far move door from current position
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Door, meta = (AllowPrivateAccess = "true"))
float Distance;

/**
* Extent when move distance to make door not open on full size (if distance not specified)
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Door, meta = (AllowPrivateAccess = "true"))
float Extent;
};
79 changes: 41 additions & 38 deletions Source/Cloud9/Game/Cloud9DeveloperSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ void UCloud9DeveloperSettings::Save()
Log();
}

template <typename TObject, typename TProperty>
auto RegisterConsoleVariable(TObject* Object, TProperty* Property)
template <typename TValue>
auto UCloud9DeveloperSettings::RegisterConsoleVariable(TValue& ValueRef, const TCHAR* Name, const TCHAR* Help)
{
using TCppType = typename TProperty::TCppType;

let ConsoleVariable = Property->GetMetaData(TEXT("ConsoleVariable"));
let ToolTip = Property->GetMetaData(TEXT("ToolTip"));

let ValuePtr = Property->template ContainerPtrToValuePtr<TCppType>(Object);
static_assert(
TIsSame<TValue, int>::Value ||
TIsSame<TValue, float>::Value ||
TIsSame<TValue, bool>::Value ||
TIsSame<TValue, FString>::Value,
"TValue must be int, float, bool or FString"
);

let ConsoleManager = &IConsoleManager::Get();

// FAutoConsoleVariableSink
let CVar = ConsoleManager->RegisterConsoleVariableRef(*ConsoleVariable, *ValuePtr, *ToolTip);
let CVar = ConsoleManager->RegisterConsoleVariableRef(Name, ValueRef, Help);

CVar->AsVariable()->SetOnChangedCallback(
FConsoleVariableDelegate::CreateLambda([Object](auto Arg) { Object->Save(); })
FConsoleVariableDelegate::CreateLambda([this](auto Arg) { Save(); })
);

return CVar;
Expand All @@ -74,30 +74,35 @@ void UCloud9DeveloperSettings::InitializeCVars()
{
bIsConsoleInitialized = true;

for (TFieldIterator<FProperty> It(GetClass()); It; ++It)
{
if (let Property = *It; Property->HasMetaData(TEXT("ConsoleVariable")))
{
// TODO: Refactor with EachOrNone
let CVar = Property | WhenOrNone{
[this](FBoolProperty* Arg) { return RegisterConsoleVariable(this, Arg); },
[this](FIntProperty* Arg) { return RegisterConsoleVariable(this, Arg); },
[this](FFloatProperty* Arg) { return RegisterConsoleVariable(this, Arg); },
};

if (!CVar)
{
UE_LOG(
LogCloud9,
Warning,
TEXT("Property with meta key 'ConsoleVariable' %s wasn't registered"
" as console variable due to unsupported type '%s'"),
*Property->GetName(),
*Property->GetCPPType()
)
}
}
}
RegisterConsoleVariable(
bIsShowMouseCursor,
TEXT("r.IsShowMouseCursor"),
TEXT("Whether to draw line from character to GetHitUnderCursor point")
);

RegisterConsoleVariable(
bIsDrawDeprojectedCursorLine,
TEXT("r.IsDrawDeprojectedCursorLine"),
TEXT("Whether to draw line from character to deprojected mouse cursor")
);

RegisterConsoleVariable(
bIsShowMouseCursor,
TEXT("r.IsShowMouseCursor"),
TEXT("Whether to show mouse cursor on screen or not in game")
);

RegisterConsoleVariable(
NetGraph,
TEXT("r.NetGraph"),
TEXT("Whether to show FPS and other specific debug info")
);

RegisterConsoleVariable(
CameraVerticalSpeedLag,
TEXT("r.CameraVerticalSpeedLag"),
TEXT("Configure how smoothly does the camera change its position vertically")
);

Log();
}
Expand All @@ -109,19 +114,17 @@ void UCloud9DeveloperSettings::Log() const
UE_LOG(LogCloud9, Display, TEXT("%s"), *String);
}

#if WITH_EDITOR
void UCloud9DeveloperSettings::PostInitProperties()
{
InitializeCVars();
Super::PostInitProperties();
#if WITH_EDITOR
if (IsTemplate())
{
ImportConsoleVariableValues();
}
#endif
}

#if WITH_EDITOR
void UCloud9DeveloperSettings::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
InitializeCVars();
Expand Down
Loading