From 9116a7b8fed0d8243d3f5d34c83d67c6e582caf4 Mon Sep 17 00:00:00 2001 From: teppy999 Date: Tue, 26 Sep 2023 19:26:09 -0400 Subject: [PATCH] Some progress toward tangible GC: --- .../Integration/IntegrationGameModeBase.cpp | 23 ++++------- Source/Integration/Tangible.cpp | 2 + Source/Integration/TangibleManager.cpp | 41 ++++++++++++++----- Source/Integration/TangibleManager.h | 41 +++++++++---------- 4 files changed, 60 insertions(+), 47 deletions(-) diff --git a/Source/Integration/IntegrationGameModeBase.cpp b/Source/Integration/IntegrationGameModeBase.cpp index 04dfc472..b9efd041 100644 --- a/Source/Integration/IntegrationGameModeBase.cpp +++ b/Source/Integration/IntegrationGameModeBase.cpp @@ -121,22 +121,17 @@ void AIntegrationGameModeBase::MaybeTriggerUpdateTask(float deltaseconds) { #pragma optimize("", off) void AIntegrationGameModeBase::UpdateTangibles() { + using TanArray = UlxTangibleManager::TanArray; if (!Playing) return; FlxLockedWrapper w(LockableWrapper); - int64 actor = w.GetActor(); - TangibleManager->SetPlayer(actor); - IdView near = w.GetNear(actor, 100, 100, 100); - TangibleManager->SetNear(near); - for (int64 id : near) { - TangibleManager->MakeTangible(id); - } - // Update animation queues of live tangibles. - IdArray tanids = TangibleManager->GetLive(); - StringViewVec aqueues = w.GetAnimationQueues(tanids); - for (int i = 0; i < tanids.Num(); i++) { - uint64_t tanid = tanids[i]; - UlxTangible *t = TangibleManager->GetTangible(tanid); - t->AnimTracker.Update(aqueues[i]); + int64 player = w.GetActor(); + TangibleManager->UpdateNear(w.GetNear(player, 100, 100, 100)); + TanArray alltans = TangibleManager->GetAllTangibles(); + IdArray allids = TangibleManager->GetIds(alltans); + StringViewVec allqueues = w.GetAnimationQueues(allids); + for (int i = 0; i < alltans.Num(); i++) { + UlxTangible *t = alltans[i]; + t->AnimTracker.Update(allqueues[i]); TArray aborted = t->AnimTracker.GetAborted(); for (uint64 hash : aborted) { IlxTangibleInterface::Execute_AbortAnimation(t->GetActor(), hash); diff --git a/Source/Integration/Tangible.cpp b/Source/Integration/Tangible.cpp index c12838c9..17b97851 100644 --- a/Source/Integration/Tangible.cpp +++ b/Source/Integration/Tangible.cpp @@ -6,6 +6,8 @@ UlxTangible::UlxTangible() { + TangibleId = -1; + NearAccordingToLuprex = false; } void UlxTangible::Init(UlxTangibleManager* tm, int64 id) diff --git a/Source/Integration/TangibleManager.cpp b/Source/Integration/TangibleManager.cpp index 30c4ff1e..0559b5de 100644 --- a/Source/Integration/TangibleManager.cpp +++ b/Source/Integration/TangibleManager.cpp @@ -6,27 +6,24 @@ #include "DebugPrint.h" using namespace DebugPrint; +using TanArray = UlxTangibleManager::TanArray; +using IdArray = UlxTangibleManager::IdArray; UlxTangibleManager::UlxTangibleManager() { World = nullptr; ClassTangibleActor = nullptr; - Player = 0; - Near = IdView(); } void UlxTangibleManager::Init(UWorld* world, UClass* tanact) { World = world; ClassTangibleActor = tanact; - Player = 0; - Near = IdView(); } -UlxTangible* UlxTangibleManager::GetTangible(int64 id) { - UlxTangible** p = IdToTangible.Find(id); +UlxTangible* UlxTangibleManager::GetTangible(int64 id) const { + UlxTangible*const* p = IdToTangible.Find(id); if (p == nullptr) { return nullptr; - } - else { + } else { return *p; } } @@ -49,12 +46,34 @@ void UlxTangibleManager::DeleteTangible(int64 id) { // IMPLEMENT ME } -UlxTangibleManager::IdArray UlxTangibleManager::GetLive() { - IdArray result; +TanArray UlxTangibleManager::GetAllTangibles() const { + TanArray result; result.SetNum(IdToTangible.Num()); int next = 0; for (auto& pair : IdToTangible) { - result[next++] = pair.Key; + result[next++] = pair.Value; + } + return result; +} + +void UlxTangibleManager::UpdateNear(IdView near) { + // Clear all the 'NearAccordingToLuprex' flags. + for (const auto& pair : IdToTangible) { + pair.Value->NearAccordingToLuprex = false; + } + // For every ID on the list, create it if it doesn't exist, + // mark it, and return it. + for (int64 id : near) { + UlxTangible* tan = MakeTangible(id); + tan->NearAccordingToLuprex = true; + } +} + +IdArray UlxTangibleManager::GetIds(const TanArray &arr) { + IdArray result; + result.SetNum(arr.Num()); + for (int i = 0; i < arr.Num(); i++) { + result[i] = arr[i]->TangibleId; } return result; } diff --git a/Source/Integration/TangibleManager.h b/Source/Integration/TangibleManager.h index 4a307540..ca83831b 100644 --- a/Source/Integration/TangibleManager.h +++ b/Source/Integration/TangibleManager.h @@ -14,9 +14,10 @@ class INTEGRATION_API UlxTangibleManager : public UObject GENERATED_BODY() public: - // Import these types into our Namespace. - using IdArray = CommonTypes::IdArray; + // Types used frequently. using IdView = CommonTypes::IdView; + using IdArray = CommonTypes::IdArray; + using TanArray = TArray; // A pointer to our world. UPROPERTY() @@ -31,12 +32,6 @@ public: UPROPERTY() TMap IdToTangible; - // Player's tangible Id. - int64 Player; - - // Tangibles near the actor. - IdView Near; - public: UlxTangibleManager(); @@ -49,28 +44,30 @@ public: UWorld* GetWorld() const override { return World.Get(); } // Get the tangible if it exists, otherwise return NULL - UlxTangible* GetTangible(int64 id); + // + UlxTangible* GetTangible(int64 id) const; // Get the tangible if it exists, otherwise create it. + // UlxTangible* MakeTangible(int64 id); // Delete the tangible. + // void DeleteTangible(int64 id); - // Get/Set the Id of the actor. - // - int64 GetPlayer() const { return Player; }; - void SetPlayer(int64 id) { Player = id; } + // Get an array of all tangibles. + // + TanArray GetAllTangibles() const; + + // Update the 'NearAccordingToLuprex' flags. + // + // Also creates any tangibles that are in the near-list, + // if they don't already exist. + // + void UpdateNear(IdView near); - // Get/Set the list of tangibles near the player, according to Luprex. + // Given an array of tangibles, return an array of tangible Ids. // - IdView GetNear() const { return Near; } - void SetNear(IdView near) { Near = near; } - - // Get the Live list. - // - // Efficiency note: this makes a copy of the array. - // - IdArray GetLive(); + static IdArray GetIds(const TanArray &tans); };