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