Make TangibleManager a GameInstance subsystem

This commit is contained in:
2026-02-25 14:59:54 -05:00
parent b149714f20
commit 199a6bb813
5 changed files with 18 additions and 48 deletions

View File

@@ -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;