From 199a6bb813423060ffb33561b61161aa1361750a Mon Sep 17 00:00:00 2001 From: jyelon Date: Wed, 25 Feb 2026 14:59:54 -0500 Subject: [PATCH] Make TangibleManager a GameInstance subsystem --- Source/Integration/LuprexGameModeBase.cpp | 32 +++++++++-------------- Source/Integration/LuprexGameModeBase.h | 4 --- Source/Integration/Tangible.cpp | 2 +- Source/Integration/TangibleManager.cpp | 9 ++----- Source/Integration/TangibleManager.h | 19 +++----------- 5 files changed, 18 insertions(+), 48 deletions(-) diff --git a/Source/Integration/LuprexGameModeBase.cpp b/Source/Integration/LuprexGameModeBase.cpp index 4462ab32..80db45c1 100644 --- a/Source/Integration/LuprexGameModeBase.cpp +++ b/Source/Integration/LuprexGameModeBase.cpp @@ -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(); 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(); + UlxTangible *ptan = TM->GetPossessedTangible(); + UlxTangible *tan = TM->GetTangible(PlayerId); APlayerController *ctrl = GetWorld()->GetFirstPlayerController(); APawn *pawn = nullptr; if (tan != nullptr) pawn = Cast(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(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()->GetPossessedTangible(); if (possessed == nullptr) return; APlayerController *pc = GetWorld()->GetFirstPlayerController(); if (pc == nullptr) return; diff --git a/Source/Integration/LuprexGameModeBase.h b/Source/Integration/LuprexGameModeBase.h index 8acdea73..152005e9 100644 --- a/Source/Integration/LuprexGameModeBase.h +++ b/Source/Integration/LuprexGameModeBase.h @@ -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; diff --git a/Source/Integration/Tangible.cpp b/Source/Integration/Tangible.cpp index 08e0ba16..3081f63d 100644 --- a/Source/Integration/Tangible.cpp +++ b/Source/Integration/Tangible.cpp @@ -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); } diff --git a/Source/Integration/TangibleManager.cpp b/Source/Integration/TangibleManager.cpp index 774b4e7e..74adbe64 100644 --- a/Source/Integration/TangibleManager.cpp +++ b/Source/Integration/TangibleManager.cpp @@ -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) { diff --git a/Source/Integration/TangibleManager.h b/Source/Integration/TangibleManager.h index 38837e5e..48f15091 100644 --- a/Source/Integration/TangibleManager.h +++ b/Source/Integration/TangibleManager.h @@ -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; - // A pointer to our game mode. - UPROPERTY() - TWeakObjectPtr 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 //