Make TangibleManager a GameInstance subsystem
This commit is contained in:
@@ -19,7 +19,6 @@ using namespace LpxCommonTypes;
|
||||
|
||||
ALuprexGameModeBase::ALuprexGameModeBase()
|
||||
{
|
||||
TangibleManager = nullptr;
|
||||
PlayerId = 0;
|
||||
EngineSeconds = 0.0;
|
||||
MustCallLookAtChanged = false;
|
||||
@@ -65,11 +64,6 @@ void ALuprexGameModeBase::ResetToInitialState()
|
||||
Playing = false;
|
||||
TickEnabled = true;
|
||||
|
||||
if (TangibleManager != nullptr) {
|
||||
TangibleManager->ConditionalBeginDestroy();
|
||||
TangibleManager = nullptr;
|
||||
}
|
||||
|
||||
// Stop the tick functions.
|
||||
FWorldDelegates::OnWorldPreActorTick.Remove(OnWorldPreActorTickHandle);
|
||||
FWorldDelegates::OnWorldPostActorTick.Remove(OnWorldPostActorTickHandle);
|
||||
@@ -131,14 +125,15 @@ void ALuprexGameModeBase::UpdateTangibles() {
|
||||
double radius = 1000.0; // Hardwired for now.
|
||||
using TanArray = UlxTangibleManager::TanArray;
|
||||
if (!Playing) return;
|
||||
UlxTangibleManager *TM = GetGameInstance()->GetSubsystem<UlxTangibleManager>();
|
||||
TanArray alltans;
|
||||
{
|
||||
FlxLockedWrapper w(LockableWrapper);
|
||||
PlayerId = w.GetActor();
|
||||
IdView nearids = w.GetNear(PlayerId, radius, radius, radius);
|
||||
TangibleManager->UpdateNearAccordingToLuprex(nearids);
|
||||
alltans = TangibleManager->GetAllTangibles();
|
||||
IdArray allids = TangibleManager->GetIds(alltans);
|
||||
TM->UpdateNearAccordingToLuprex(nearids);
|
||||
alltans = TM->GetAllTangibles();
|
||||
IdArray allids = TM->GetIds(alltans);
|
||||
StringViewVec allqueues = w.GetAnimationQueues(allids);
|
||||
for (int i = 0; i < alltans.Num(); i++) {
|
||||
alltans[i]->UpdateAnimationQueue(allqueues[i]);
|
||||
@@ -158,24 +153,25 @@ void ALuprexGameModeBase::UpdateTangibles() {
|
||||
for (int i = 0; i < alltans.Num(); i++) {
|
||||
alltans[i]->MaybeExecuteAnimStateChanged();
|
||||
}
|
||||
TangibleManager->RecalcNearAccordingToUnreal(PlayerId, radius);
|
||||
TangibleManager->DeleteFarawayTangibles();
|
||||
TM->RecalcNearAccordingToUnreal(PlayerId, radius);
|
||||
TM->DeleteFarawayTangibles();
|
||||
}
|
||||
|
||||
void ALuprexGameModeBase::UpdatePossessedTangible() {
|
||||
UlxTangible *ptan = TangibleManager->GetPossessedTangible();
|
||||
UlxTangible *tan = TangibleManager->GetTangible(PlayerId);
|
||||
UlxTangibleManager *TM = GetGameInstance()->GetSubsystem<UlxTangibleManager>();
|
||||
UlxTangible *ptan = TM->GetPossessedTangible();
|
||||
UlxTangible *tan = TM->GetTangible(PlayerId);
|
||||
APlayerController *ctrl = GetWorld()->GetFirstPlayerController();
|
||||
APawn *pawn = nullptr;
|
||||
if (tan != nullptr) pawn = Cast<APawn>(tan->GetActor());
|
||||
if (pawn == nullptr) {
|
||||
if (ptan != nullptr) {
|
||||
TangibleManager->SetPossessedTangible(nullptr);
|
||||
TM->SetPossessedTangible(nullptr);
|
||||
ctrl->Possess(nullptr);
|
||||
}
|
||||
} else {
|
||||
if (ptan != tan) {
|
||||
TangibleManager->SetPossessedTangible(tan);
|
||||
TM->SetPossessedTangible(tan);
|
||||
ctrl->Possess(pawn);
|
||||
}
|
||||
}
|
||||
@@ -268,10 +264,6 @@ void ALuprexGameModeBase::InitializeGlobalState()
|
||||
OnWorldPostActorTickHandle = FWorldDelegates::OnWorldPostActorTick.AddUObject(this, &ALuprexGameModeBase::OnWorldPostActorTick);
|
||||
}
|
||||
|
||||
// Initialize the tangible manager.
|
||||
TangibleManager = NewObject<UlxTangibleManager>(this);
|
||||
TangibleManager->Init(this);
|
||||
|
||||
// If somebody generates a log message that's severe enough, break to debugger.
|
||||
BreakToDebuggerLogVerbosityDevice.Reset(
|
||||
new FlxBreakToDebuggerOutputDevice(BreakToDebuggerLogVerbosity));
|
||||
@@ -327,7 +319,7 @@ FVector2D ALuprexGameModeBase::GetLookAtPixel(const UObject *Context)
|
||||
|
||||
void ALuprexGameModeBase::UpdateLookAt() {
|
||||
// Make sure the world is fully configured before we attempt to cast rays.
|
||||
UlxTangible *possessed = TangibleManager->GetPossessedTangible();
|
||||
UlxTangible *possessed = GetGameInstance()->GetSubsystem<UlxTangibleManager>()->GetPossessedTangible();
|
||||
if (possessed == nullptr) return;
|
||||
APlayerController *pc = GetWorld()->GetFirstPlayerController();
|
||||
if (pc == nullptr) return;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "GameFramework/GameModeBase.h"
|
||||
#include "lpx-enginewrapper.hpp"
|
||||
#include "StreamBuffer.h"
|
||||
#include "TangibleManager.h"
|
||||
#include "LuprexSockets.h"
|
||||
#include "TriggeredTask.h"
|
||||
#include "BreakToDebugger.h"
|
||||
@@ -101,9 +100,6 @@ public:
|
||||
// Get the current Luprex Game Mode Base, given a Context object.
|
||||
static ALuprexGameModeBase *FromContext(const UObject *Context);
|
||||
|
||||
UPROPERTY()
|
||||
UlxTangibleManager *TangibleManager;
|
||||
|
||||
// The actor that the player is looking at, current frame.
|
||||
UPROPERTY()
|
||||
FHitResult CurrentLookAt;
|
||||
|
||||
@@ -291,7 +291,7 @@ void UlxTangible::SetTangiblePlane(AActor* target, const FString& plane) {
|
||||
bool UlxTangible::IsCurrentPlayer(AActor* target) {
|
||||
UlxTangible *tan = GetActorTangibleQuiet(target);
|
||||
if (tan == nullptr) return false;
|
||||
ALuprexGameModeBase *gamemode = tan->Manager->GetGameMode();
|
||||
ALuprexGameModeBase *gamemode = ALuprexGameModeBase::FromContext(target);
|
||||
return (tan->TangibleId == gamemode->PlayerId);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,19 +3,14 @@
|
||||
|
||||
#include "TangibleManager.h"
|
||||
#include "Tangible.h"
|
||||
#include "LuprexGameModeBase.h"
|
||||
#include "AssetRegistry/AssetRegistryModule.h"
|
||||
#include "AssetRegistry/ARFilter.h"
|
||||
|
||||
|
||||
UlxTangibleManager::UlxTangibleManager() {
|
||||
void UlxTangibleManager::Initialize(FSubsystemCollectionBase& Collection) {
|
||||
Super::Initialize(Collection);
|
||||
PossessedTangible = nullptr;
|
||||
}
|
||||
|
||||
void UlxTangibleManager::Init(ALuprexGameModeBase *gamemode) {
|
||||
GameMode = gamemode;
|
||||
}
|
||||
|
||||
UlxTangible* UlxTangibleManager::GetTangible(int64 id) const {
|
||||
UlxTangible*const* p = IdToTangible.Find(id);
|
||||
if (p == nullptr) {
|
||||
|
||||
@@ -4,14 +4,13 @@
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/NoExportTypes.h"
|
||||
#include "Subsystems/GameInstanceSubsystem.h"
|
||||
#include "Common.h"
|
||||
#include "Tangible.h"
|
||||
#include "TangibleManager.generated.h"
|
||||
|
||||
class ALuprexGameModeBase;
|
||||
|
||||
UCLASS()
|
||||
class INTEGRATION_API UlxTangibleManager : public UObject
|
||||
class INTEGRATION_API UlxTangibleManager : public UGameInstanceSubsystem
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
@@ -21,9 +20,7 @@ public:
|
||||
using IdArray = LpxCommonTypes::IdArray;
|
||||
using TanArray = TArray<UlxTangible*>;
|
||||
|
||||
// A pointer to our game mode.
|
||||
UPROPERTY()
|
||||
TWeakObjectPtr<ALuprexGameModeBase> GameMode;
|
||||
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
||||
|
||||
// Given a tangible ID, look up the TangibleComponent of that actor.
|
||||
UPROPERTY()
|
||||
@@ -31,16 +28,6 @@ public:
|
||||
|
||||
// The Tangible ID of the possessed tangible, if any.
|
||||
UlxTangible *PossessedTangible;
|
||||
|
||||
public:
|
||||
UlxTangibleManager();
|
||||
|
||||
// Initialize the tangible manager.
|
||||
//
|
||||
void Init(ALuprexGameModeBase *gamemode);
|
||||
|
||||
// Get a pointer to our game mode.
|
||||
ALuprexGameModeBase *GetGameMode() { return GameMode.Get(); }
|
||||
|
||||
// Get the tangible if it exists, otherwise return NULL
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user