level pack loading added, pawn walking camera fixed

This commit is contained in:
C
2022-05-31 16:17:21 +05:00
parent a1c5a6fd1c
commit 7e150b04a8
18 changed files with 143 additions and 36 deletions
@@ -45,6 +45,19 @@ void AResComFloorManager::AddLevelToPack(FApartmentLocation loc, FFloorLevelStre
}
}
bool AResComFloorManager::GetPack(FApartmentLocation loc, FFloorPack* pack)
{
for (int i = 0; i < packs.Num(); ++i)
{
if (packs[i].location == loc)
{
pack = &(packs[i]);
return true;
}
}
return false;
}
bool AResComFloorManager::GetPack(FApartmentLocation loc, FFloorPack& pack) const
{
for (auto& packCurr : packs)
@@ -58,45 +71,22 @@ bool AResComFloorManager::GetPack(FApartmentLocation loc, FFloorPack& pack) cons
return false;
}
bool AResComFloorManager::LoadPack(FApartmentLocation loc, const FOnPreview& delegatePreview, const FOnShouldBeVisible& delegateShouldBeVisible, const FOnShouldBeLoaded& delegateShouldBeLoaded)
//bool AResComFloorManager::LoadPack(FApartmentLocation loc, const FOnPreview& delegatePreview, const FOnShouldBeVisible& delegateShouldBeVisible, const FOnShouldBeLoaded& delegateShouldBeLoaded)
bool AResComFloorManager::LoadPack(FApartmentLocation loc, const FOnLoaded& delegateOnLoaded)
{
FFloorPack pack;
FFloorPack* pack = nullptr;
if (!GetPack(loc, pack))
return false;
OnLoaded = delegateOnLoaded;
//OnPreview = delegatePreview;
//OnShouldBeVisible = delegateShouldBeVisible;
//OnShouldBeLoaded = delegateShouldBeLoaded;
OnPreview = delegatePreview;
OnShouldBeVisible = delegateShouldBeVisible;
OnShouldBeLoaded = delegateShouldBeLoaded;
FLatentActionInfo latentInfo;
latentInfo.CallbackTarget = this;
latentInfo.UUID = 0;
latentInfo.Linkage = 0;
/*latentInfo.ExecutionFunction = "OnLevelPreview";
for (auto& level : pack.levelsPreview)
{
++queueElem.visibleCnt;
++latentInfo.UUID;
UGameplayStatics::LoadStreamLevel(this, *level, true, true, latentInfo);
}
latentInfo.ExecutionFunction = "OnLevelVisible";
for (auto& level : pack.levelsShouldBeVisible)
{
++queueElem.previewCnt;
++latentInfo.UUID;
UGameplayStatics::LoadStreamLevel(this, *level, true, true, latentInfo);
}
latentInfo.ExecutionFunction = "OnLevelLoaded";
for (auto& level : pack.levelsShouldBeLoaded)
{
queueElem.loadedCnt;
++latentInfo.UUID;
UGameplayStatics::LoadStreamLevel(this, *level, true, true, latentInfo);
}*/
FVector Location(0.0f, 0.0f, 0.0f);
FRotator Rotation(0.0f, 0.0f, 0.0f);
FActorSpawnParameters SpawnInfo;
GetWorld()->SpawnActor<AResComLevelPackLoader>(Location, Rotation, SpawnInfo);
return true;
}
@@ -0,0 +1,64 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "ResComLevelPackLoader.h"
// Sets default values
AResComLevelPackLoader::AResComLevelPackLoader()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.TickInterval = 0.5f;
}
// Called when the game starts or when spawned
void AResComLevelPackLoader::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AResComLevelPackLoader::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (packLoading->IsLoaded())
{
Destroy();
}
}
void AResComLevelPackLoader::LoadPack(FFloorPack* pack)
{
FLatentActionInfo latentInfo;
latentInfo.CallbackTarget = this;
latentInfo.UUID = 0;
latentInfo.Linkage = 0;
latentInfo.ExecutionFunction = "OnLevelPreview";
for (auto& level : pack.levelsPreview)
{
++queueElem.visibleCnt;
++latentInfo.UUID;
UGameplayStatics::LoadStreamLevel(this, *level, true, true, latentInfo);
}
latentInfo.ExecutionFunction = "OnLevelVisible";
for (auto& level : pack.levelsShouldBeVisible)
{
++queueElem.previewCnt;
++latentInfo.UUID;
UGameplayStatics::LoadStreamLevel(this, *level, true, true, latentInfo);
}
latentInfo.ExecutionFunction = "OnLevelLoaded";
for (auto& level : pack.levelsShouldBeLoaded)
{
queueElem.loadedCnt;
++latentInfo.UUID;
UGameplayStatics::LoadStreamLevel(this, *level, true, true, latentInfo);
}
return true;
}
@@ -1,6 +1,7 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "ResComLevelPackLoader.h"
#include "Engine/LevelStreaming.h"
#include "Kismet/GameplayStatics.h"
#include "ResComApartmentManager.h"
@@ -13,6 +14,7 @@
DECLARE_DYNAMIC_DELEGATE(FOnPreview);
DECLARE_DYNAMIC_DELEGATE(FOnShouldBeVisible);
DECLARE_DYNAMIC_DELEGATE(FOnShouldBeLoaded);
DECLARE_DYNAMIC_DELEGATE(FOnLoaded);
UENUM(BlueprintType)
enum Enum_LevelType
@@ -47,6 +49,23 @@ struct FFloorPack
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FFloorLevelStreaming> levels;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool loaded = false;
bool IsLoaded()
{
loaded = false;
for (auto& level : levels)
{
if (!IsValid(level.level))
return loaded;
if (!(level.level->IsLevelVisible()))
return loaded;
}
loaded = true;
return loaded;
}
};
UCLASS()
@@ -63,6 +82,7 @@ private:
void OnLevelVisible();
UFUNCTION()
void OnLevelLoaded();
bool GetPack(FApartmentLocation loc, FFloorPack* pack);
public:
// Sets default values for this actor's properties
AResComFloorManager();
@@ -78,6 +98,8 @@ protected:
FOnShouldBeVisible OnShouldBeVisible;
UPROPERTY()
FOnShouldBeLoaded OnShouldBeLoaded;
UPROPERTY()
FOnLoaded OnLoaded;
UFUNCTION(BlueprintCallable, Category = "Pack")
void AddLevelToPack(FApartmentLocation loc, FFloorLevelStreaming level);
@@ -93,7 +115,8 @@ public:
virtual void Tick(float DeltaTime) override;
UFUNCTION(BlueprintCallable, Category="Pack")
bool LoadPack(FApartmentLocation loc, const FOnPreview& delegatePreview, const FOnShouldBeVisible& delegateShouldBeVisible, const FOnShouldBeLoaded& delegateShouldBeLoaded);
//bool LoadPack(FApartmentLocation loc, const FOnPreview& delegatePreview, const FOnShouldBeVisible& delegateShouldBeVisible, const FOnShouldBeLoaded& delegateShouldBeLoaded);
bool LoadPack(FApartmentLocation loc, const FOnLoaded& delegateOnLoaded);
UFUNCTION(BlueprintCallable, Category = "Pack")
bool UnloadPack(FApartmentLocation loc, const FOnPreview& delegatePreview, const FOnShouldBeVisible& delegateShouldBeVisible, const FOnShouldBeLoaded& delegateShouldBeLoaded);
@@ -0,0 +1,30 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "ResComFloorManager.h"
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ResComLevelPackLoader.generated.h"
UCLASS()
class FORTIS_TAKTIKA_API AResComLevelPackLoader : public AActor
{
GENERATED_BODY()
private:
FFloorPack* packLoading;
public:
// Sets default values for this actor's properties
AResComLevelPackLoader();
AResComLevelPackLoader(FFloorPack* pack) : packLoading(pack){}
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
void LoadPack(FFloorPack* pack);
};