From 2f5baf2e9ff78455be3bf03e1660f386189dfa32 Mon Sep 17 00:00:00 2001 From: teppy999 Date: Mon, 25 Sep 2023 14:25:24 -0400 Subject: [PATCH] Make TangibleManager a UObject --- Content/TangibleActor.uasset | 4 ++-- Source/Integration/AnimQueue.cpp | 2 +- Source/Integration/AnimQueue.h | 5 ----- .../Integration/IntegrationGameModeBase.cpp | 21 ++++++++++++------- Source/Integration/IntegrationGameModeBase.h | 2 +- Source/Integration/Tangible.h | 6 ++++-- Source/Integration/TangibleManager.cpp | 14 ++++++------- Source/Integration/TangibleManager.h | 7 ++++--- 8 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Content/TangibleActor.uasset b/Content/TangibleActor.uasset index 84081bce..4f16996b 100644 --- a/Content/TangibleActor.uasset +++ b/Content/TangibleActor.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cb67f71a0d3b103417566d3386575bf84b4819ef2c1589792812dfcc2499fb35 -size 140290 +oid sha256:1c38181c8e0c13615ed114567f6afa150dc6f06f49f7aefc66629b624d5f2834 +size 140308 diff --git a/Source/Integration/AnimQueue.cpp b/Source/Integration/AnimQueue.cpp index 28983a7a..a0b8d060 100644 --- a/Source/Integration/AnimQueue.cpp +++ b/Source/Integration/AnimQueue.cpp @@ -42,7 +42,7 @@ static bool SetProperty(const FString& name, UObject* obj, const FlxAnimationFie FDoubleProperty* fprop = FindFProperty(uclass, nname); if (fprop == nullptr) return false; double* pptr = fprop->ContainerPtrToValuePtr(obj); - fprop->SetPropertyValue(pptr, field.X); + *pptr = field.X; return true; } case ElxAnimValueType::BOOLEAN: { diff --git a/Source/Integration/AnimQueue.h b/Source/Integration/AnimQueue.h index 3673796c..0d9bb512 100644 --- a/Source/Integration/AnimQueue.h +++ b/Source/Integration/AnimQueue.h @@ -129,18 +129,13 @@ public: UFUNCTION(BlueprintCallable, BlueprintPure, Category = Luprex) static bool AnimationStepGetBool(const FlxAnimationStep& step, const FString& name); - }; //////////////////////////////////////////////// // -// Exposing functions to blueprints. // //////////////////////////////////////////////// -//UFUNCTION(BlueprintCallable) -//void Unpack(const FString& prefix, UObject* into, bool preclear = true); - struct FlxAnimationStepView { uint64 Hash; std::string_view Body; diff --git a/Source/Integration/IntegrationGameModeBase.cpp b/Source/Integration/IntegrationGameModeBase.cpp index 2f6dfb69..cab1292e 100644 --- a/Source/Integration/IntegrationGameModeBase.cpp +++ b/Source/Integration/IntegrationGameModeBase.cpp @@ -16,6 +16,7 @@ using namespace CommonTypes; AIntegrationGameModeBase::AIntegrationGameModeBase() { + TangibleManager = NewObject(); EngineSeconds = 0.0; NextThreadTrigger = 1.0; //PrimaryActorTick.bCanEverTick = true; // Probably wrong @@ -47,6 +48,11 @@ void AIntegrationGameModeBase::ResetToInitialState() { Playing = false; + if (TangibleManager != nullptr) { + TangibleManager->ConditionalBeginDestroy(); + TangibleManager = nullptr; + } + // Shut down the thread LuprexUpdateTask.Shutdown(); @@ -117,18 +123,18 @@ void AIntegrationGameModeBase::UpdateTangibles() { if (!Playing) return; FlxLockedWrapper w(LockableWrapper); int64 actor = w.GetActor(); - TangibleManager.SetActor(actor); - TangibleManager.SetNear(w.GetNear(actor, 100, 100, 100)); - for (int64 id : TangibleManager.GetNear()) { - TangibleManager.MakeTangible(id); + TangibleManager->SetActor(actor); + TangibleManager->SetNear(w.GetNear(actor, 100, 100, 100)); + for (int64 id : TangibleManager->GetNear()) { + TangibleManager->MakeTangible(id); } // Update animation queues of live tangibles. - IdArray tanids = TangibleManager.GetLive(); + IdArray tanids = TangibleManager->GetLive(); StringViewVec aqueues = w.GetAnimationQueues(tanids); for (int i = 0; i < tanids.Num(); i++) { uint64_t tanid = tanids[i]; std::string_view aqueue = aqueues[i]; - UlxTangible* t = TangibleManager.GetTangible(tanid); + UlxTangible* t = TangibleManager->GetTangible(tanid); check(t != nullptr); t->AnimTracker.Update(aqueue); @@ -237,7 +243,8 @@ void AIntegrationGameModeBase::BeginPlay() } // Initialize the tangible manager. - TangibleManager.Init(GetWorld(), ClassTangibleActor); + TangibleManager = NewObject(); + TangibleManager->Init(GetWorld(), ClassTangibleActor); } void AIntegrationGameModeBase::EndPlay(const EEndPlayReason::Type EndPlayReason) diff --git a/Source/Integration/IntegrationGameModeBase.h b/Source/Integration/IntegrationGameModeBase.h index fa72e6ad..b6ec9d0f 100644 --- a/Source/Integration/IntegrationGameModeBase.h +++ b/Source/Integration/IntegrationGameModeBase.h @@ -57,7 +57,7 @@ public: virtual uint32 Run() override; UPROPERTY() - FTangibleManager TangibleManager; + UTangibleManager *TangibleManager; // This stores the entire text currently visible in the console. FlxConsoleOutput ConsoleOutput; diff --git a/Source/Integration/Tangible.h b/Source/Integration/Tangible.h index 84f0686f..590d03b8 100644 --- a/Source/Integration/Tangible.h +++ b/Source/Integration/Tangible.h @@ -22,8 +22,10 @@ public: FlxAnimTracker AnimTracker; - void Init(AActor* a) { + FString Plane; + + void Init(AActor* a, const FString &plane) { Actor = a; + Plane = plane; } }; - diff --git a/Source/Integration/TangibleManager.cpp b/Source/Integration/TangibleManager.cpp index 046d42c7..06a07c18 100644 --- a/Source/Integration/TangibleManager.cpp +++ b/Source/Integration/TangibleManager.cpp @@ -7,21 +7,21 @@ using namespace DebugPrint; -FTangibleManager::FTangibleManager() { +UTangibleManager::UTangibleManager() { World = nullptr; ClassTangibleActor = nullptr; Actor = 0; Near = IdView(); } -void FTangibleManager::Init(UWorld *world, UClass* tanact) { +void UTangibleManager::Init(UWorld *world, UClass* tanact) { World = world; ClassTangibleActor = tanact; Actor = 0; Near = IdView(); } -UlxTangible *FTangibleManager::GetTangible(int64 id) { +UlxTangible *UTangibleManager::GetTangible(int64 id) { UlxTangible **p = IdToTangible.Find(id); if (p == nullptr) { return nullptr; @@ -30,7 +30,7 @@ UlxTangible *FTangibleManager::GetTangible(int64 id) { } } -UlxTangible *FTangibleManager::MakeTangible(int64 id) { +UlxTangible *UTangibleManager::MakeTangible(int64 id) { UlxTangible *& p = IdToTangible.FindOrAdd(id); if (p == nullptr) { FVector location(0,0,0); @@ -40,16 +40,16 @@ UlxTangible *FTangibleManager::MakeTangible(int64 id) { check(a != nullptr); check(a->GetClass()->ImplementsInterface(UlxTangibleInterface::StaticClass())); p = NewObject(); - p->Init(a); + p->Init(a, TEXT("")); } return p; } -void FTangibleManager::DeleteTangible(int64 id) { +void UTangibleManager::DeleteTangible(int64 id) { // IMPLEMENT ME } -FTangibleManager::IdArray FTangibleManager::GetLive() { +UTangibleManager::IdArray UTangibleManager::GetLive() { IdArray result; result.SetNum(IdToTangible.Num()); int next = 0; diff --git a/Source/Integration/TangibleManager.h b/Source/Integration/TangibleManager.h index 9a4e1a06..60f305b5 100644 --- a/Source/Integration/TangibleManager.h +++ b/Source/Integration/TangibleManager.h @@ -8,10 +8,11 @@ #include "Tangible.h" #include "TangibleManager.generated.h" -USTRUCT() -struct INTEGRATION_API FTangibleManager +UCLASS() +class INTEGRATION_API UTangibleManager : public UObject { GENERATED_BODY() + public: // Import these types into our Namespace. using IdArray = CommonTypes::IdArray; @@ -35,7 +36,7 @@ public: IdView Near; public: - FTangibleManager(); + UTangibleManager(); // Initialize the tangible manager. //