Some progress toward tangible GC:

This commit is contained in:
2023-09-26 19:26:09 -04:00
parent 0efd0dd3ad
commit 9116a7b8fe
4 changed files with 60 additions and 47 deletions

View File

@@ -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<uint64> aborted = t->AnimTracker.GetAborted();
for (uint64 hash : aborted) {
IlxTangibleInterface::Execute_AbortAnimation(t->GetActor(), hash);

View File

@@ -6,6 +6,8 @@
UlxTangible::UlxTangible()
{
TangibleId = -1;
NearAccordingToLuprex = false;
}
void UlxTangible::Init(UlxTangibleManager* tm, int64 id)

View File

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

View File

@@ -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<UlxTangible*>;
// A pointer to our world.
UPROPERTY()
@@ -31,12 +32,6 @@ public:
UPROPERTY()
TMap<int64, UlxTangible*> 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);
};