Code & git cleanup #6

Merged
oleg.petruny merged 15 commits from Documentation into master 2024-12-15 13:32:54 +00:00
12 changed files with 81 additions and 48 deletions
Showing only changes of commit 2774995fab - Show all commits

Binary file not shown.

Binary file not shown.

View File

@ -53,25 +53,6 @@ TArray<int32> UCommonFunctions::GetRandomIntArray(int32 size, int32 min, int32 m
ALevelBase* UCommonFunctions::GetCurrentLevelScript(UObject* obj)
{
if(auto world = obj->GetWorld())
if(auto level = world->GetCurrentLevel())
if(auto script = level->GetLevelScriptActor())
return Cast<ALevelBase>(script);
return nullptr;
}
APlayerBase* UCommonFunctions::GetPlayer(UObject* obj)
{
if(auto pc = UGameplayStatics::GetPlayerController(obj->GetWorld(), 0))
if(auto pawn = pc->GetPawn())
return Cast<APlayerBase>(pawn);
return nullptr;
}
namespace SlowMotion
{
FTimerHandle timer;

View File

@ -2,34 +2,33 @@
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "CommonFunctions.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWorldDilationChangedDelegate, float, newDilation);
/**
* Collection of common/universal/without own scope/specific functions.
*/
UCLASS()
class UCommonFunctions : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/** Returns true if the object is UE class template (used for copy/archetype/meta system but not on the level) */
UFUNCTION(BlueprintPure)
static bool IsNonGameObject(class UObject* object);
/** "Overload" of the built-in keys translator (to not build own engine copy) */
UFUNCTION(BlueprintPure)
static FText GetKeyDisplayName(struct FKey key);
/** Recursively destroy actor and all its childs (the default Destroy doesn't have consistent behavior) */
UFUNCTION(BlueprintCallable, Category = Actor)
static void DestroyActorRecursively(class AActor* actor);
UFUNCTION(BlueprintPure)
static TArray<int32> GetRandomIntArray(int32 size = 16, int32 min = 0, int32 max = 16);
UFUNCTION(BlueprintCallable, Category = Level)
static class ALevelBase* GetCurrentLevelScript(class UObject* obj);
UFUNCTION(BlueprintCallable, Category = Player)
static class APlayerBase* GetPlayer(class UObject* obj);
UFUNCTION(BlueprintCallable, Category = World)
@ -41,6 +40,10 @@ public:
static FWorldDilationChangedDelegate& GetWorldDilationChangedDelegate();
UFUNCTION(BlueprintPure)
static TArray<int32> GetRandomIntArray(int32 size = 16, int32 min = 0, int32 max = 16);
template<typename T>
static TArray<T> ArrayDiff(const TArray<T>& a, const TArray<T>& b);
template<typename T>

View File

@ -1,12 +1,12 @@
// Oleg Petruny proprietary.
#include "ContentLoader.h"
#include "CommonFunctions.h"
#include "IPlatformFilePak.h"
#include "Misc/FileHelper.h"
#include "CommonFunctions.h"
#include <regex>
#include <string>
#include <vector>

View File

@ -10,13 +10,16 @@
UENUM(BlueprintType)
enum class EContentDownloadMethod : uint8
{
ClearRandom = 0,
NonRepeatRandom,
RatingOftenRandom
ClearRandom = 0, //!< Always random from 0 to n
NonRepeatRandom, //!< Download the one that isn't downloaded in current runtime (Reset on full set)
RatingOftenRandom //!< NonRepeatRandom combined with asset rating [WIP]
};
DECLARE_DYNAMIC_DELEGATE_OneParam(FContentDownloadedCallback, FString, pakFilePath);
/*
* High language wrapper for Paks(Assets) download and loading.
*/
UCLASS(BlueprintType)
class UContentLoader : public UObject
{
@ -35,12 +38,18 @@ public:
protected:
virtual void BeginDestroy() override;
/** Sends http get request */
void HttpGet(const FString& url, FHttpRequestCompleteDelegate requestCompleteCallback);
/** Parses assets html/json index */
TArray<FString> ParseDirectoryIndex(const TArray<uint8>& content, const FString& contentType);
/** Selects item by desired method */
FString SelectContentByMethod(const TArray<FString>& content, const EContentDownloadMethod method);
/** Reads Pak content */
FString GetPakMountContent(const FString& pakFilePath, TArray<FString>* content = nullptr);
/** Returns mount path to desired content item */
UClass* GetPakClass(const FString& pakContentPath);
/** Cache of already downloaded content at runtime (used by EContentDownloadMethod::NonRepeatRandom)*/
TArray<FString> downloadedContent;
};

View File

@ -5,7 +5,6 @@
#include "Kismet/GameplayStatics.h"
#include "Kismet/KismetSystemLibrary.h"
#include "CommonFunctions.h"
#include "ContentLoader.h"
#include "Levels/LevelBase.h"
#include "PlayerBase.h"
@ -37,13 +36,14 @@ UContentLoader* UCustomGameInstance::GetContentLoader()
void UCustomGameInstance::SaveGame(FName checkpointName)
{
auto levelScript = UCommonFunctions::GetCurrentLevelScript(this);
auto levelScript = ALevelBase::Get();
if(!levelScript)
return;
auto player = UCommonFunctions::GetPlayer(this);
auto player = APlayerBase::Get();
if(!player)
return;
saveData->level = GetWorld()->GetFName();
saveData->state = levelScript->GetState();
saveData->checkpoint = checkpointName;

View File

@ -9,7 +9,6 @@
#include "Kismet/GameplayStatics.h"
#include "LevelSequencePlayer.h"
#include "CommonFunctions.h"
#include "CustomGameInstance.h"
#include "CustomPlayerController.h"
#include "Interactable/Interactable.h"
@ -19,6 +18,13 @@
#include "PlayerBase.h"
#include "SaveData.h"
ALevelBase* ALevelBase::Get()
{
if(auto GM = AMainGameModeBase::Get())
return GM->leadLevel.Get();
return nullptr;
}
void ALevelBase::BeginPlay()
{
AMainGameModeBase::leadLevel = TStrongObjectPtr<ALevelBase>{ this };
@ -78,7 +84,7 @@ void ALevelBase::ApplySaveData()
IterateToState(GI->saveData->state);
auto player = UCommonFunctions::GetPlayer(this);
auto player = APlayerBase::Get();
if(!player)
return;

View File

@ -19,6 +19,10 @@ class ALevelBase : public ALevelScriptActor
GENERATED_BODY()
public:
/** Returns lead level script */
UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Lead Level Script"))
static ALevelBase* Get();
/** Iterates throught level states */
UFUNCTION(BlueprintCallable)
inline void CallNextState() { ++state; NextState(); }

View File

@ -2,6 +2,8 @@
#include "Minigame.h"
#include "InputMappingContext.h"
#include "CustomPlayerController.h"
#include "PlayerBase.h"

View File

@ -1,6 +1,5 @@
// Oleg Petruny proprietary.
#include "PlayerBase.h"
#include "Camera/CameraComponent.h"
@ -63,6 +62,13 @@ void APlayerBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponen
ACharacter::SetupPlayerInputComponent(PlayerInputComponent);
}
APlayerBase* APlayerBase::Get()
{
if(auto PC = ACustomPlayerController::Get())
return Cast<APlayerBase>(PC->GetPawn());
return nullptr;
}
void APlayerBase::BeginPlay()
{
ACharacter::BeginPlay();
@ -226,6 +232,11 @@ void APlayerBase::LoadInteractablesActivators()
TSet<UClass*> instancedActivators;
for(auto& act : AInteractable::interactionActivators)
{
if(act.Get())
if(auto obj = Cast<UInteractableActivator>(act.Get()->GetDefaultObject()))
if(!obj->AutoInstantiateInPlayer())
continue;
if(instancedActivators.Contains(act.Get()))
continue;
instancedActivators.Add(act.Get());

View File

@ -8,8 +8,9 @@
enum class EActivatorType : uint8;
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FPlayerMovedDelegate);
/**
* Bit collection of player locks.
*/
USTRUCT(BlueprintType)
struct FPlayerLock
{
@ -25,17 +26,27 @@ struct FPlayerLock
static FPlayerLock All();
};
/**
* Base class for player pawn.
* Synchronizes movement speed with fps, manages camera and inventory,
* prepares for work with interactables, and manages basic player input.
*/
UCLASS(Blueprintable, BlueprintType)
class APlayerBase : public ACharacter
{
GENERATED_BODY()
public:
/** setup input context, camera and inventory */
APlayerBase();
virtual void Tick(float DeltaTime) override;
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Player Base Pawn"))
static APlayerBase* Get();
UFUNCTION(BlueprintPure)
bool IsMoving();
UFUNCTION(BlueprintPure)
@ -46,22 +57,27 @@ public:
void LockPlayer(const FPlayerLock lock);
void UnlockPlayer(const FPlayerLock lock);
void FlyMode(bool on);
/** Force interactable activators reset */
void ResetInteractions();
/** Switch camera possesion to passed Actor */
UFUNCTION(BlueprintCallable, Category = Character)
void SwitchToView(class AActor* target);
/** Posess player camera */
UFUNCTION(BlueprintCallable, Category = Character)
void ReturnPlayerView();
/** Place item into first inventory */
UFUNCTION(BlueprintCallable, Category = Character)
void TakeItemToLeftHand(class AActor* actor);
/** Place item into second inventory */
UFUNCTION(BlueprintCallable, Category = Character)
void TakeItemToRightHand(class AActor* actor);
/** Check if Actor is in inventory */
UFUNCTION(BlueprintCallable, Category = Character)
bool IsInInventory(const class AActor* actor);
UPROPERTY(BlueprintAssignable)
FPlayerMovedDelegate OnPlayerMoved;
FVector moveVector;
class AActor* leftPocketItem = nullptr;
@ -81,6 +97,7 @@ protected:
UFUNCTION(BlueprintCallable, Category = Character)
void SwitchRun(bool run);
/** Sets camera pitch range */
UFUNCTION(BlueprintCallable, Category = Character)
void UpdatePitch(float min, float max);