Files
integration/Source/Integration/TangibleManager.cpp

118 lines
3.1 KiB
C++
Raw Normal View History

2023-09-02 01:33:11 -04:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "TangibleManager.h"
#include "Tangible.h"
2023-09-15 00:01:41 -04:00
#include "DebugPrint.h"
2023-09-02 01:33:11 -04:00
2023-09-15 00:01:41 -04:00
using namespace DebugPrint;
2023-09-26 19:26:09 -04:00
using TanArray = UlxTangibleManager::TanArray;
using IdArray = UlxTangibleManager::IdArray;
2023-09-02 01:33:11 -04:00
UlxTangibleManager::UlxTangibleManager() {
World = nullptr;
ClassTangibleStaticMesh = LoadObject<UClass>(nullptr, TEXT("/Game/Tangibles/TangibleStaticMesh.TangibleStaticMesh_C"));
check(ClassTangibleStaticMesh != nullptr);
}
void UlxTangibleManager::Init(UWorld* world) {
World = world;
}
2023-09-26 19:26:09 -04:00
UlxTangible* UlxTangibleManager::GetTangible(int64 id) const {
UlxTangible*const* p = IdToTangible.Find(id);
if (p == nullptr) {
return nullptr;
2023-09-26 19:26:09 -04:00
} else {
return *p;
}
}
#pragma optimize("", off)
UlxTangible* UlxTangibleManager::MakeTangible(int64 id) {
UlxTangible*& t = IdToTangible.FindOrAdd(id);
if (t == nullptr) {
t = NewObject<UlxTangible>();
t->Init(this, id);
// TODO: fix this. The blueprint needs to be assigned
// during animation queue parsing, based on the animation
// queue keyword 'bp'.
t->SetActorBlueprintClass(ClassTangibleStaticMesh);
}
return t;
}
void UlxTangibleManager::DeleteTangible(int64 id) {
// IMPLEMENT ME
}
2023-09-26 19:26:09 -04:00
TanArray UlxTangibleManager::GetAllTangibles() const {
TanArray result;
result.SetNum(IdToTangible.Num());
int next = 0;
for (auto& pair : IdToTangible) {
2023-09-26 19:26:09 -04:00
result[next++] = pair.Value;
}
return result;
}
#pragma optimize("", off)
void UlxTangibleManager::UpdateNearAccordingToLuprex(IdView near) {
2023-09-26 19:26:09 -04:00
// 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;
}
}
#pragma optimize("", off)
void UlxTangibleManager::RecalcNearAccordingToUnreal(int64 player, double radius) {
UlxTangible *p = GetTangible(player);
check (p != nullptr);
FVector playerpos = p->CurrentActor->GetActorLocation();
FName playerplane = p->Plane;
double radiussq = radius * radius;
for (const auto& pair : IdToTangible) {
UlxTangible *tan = pair.Value;
if (tan->Plane != playerplane) {
tan->NearAccordingToUnreal = false;
} else {
FVector pos = tan->GetLocation();
double distsq = FVector::DistSquared(pos, playerpos);
tan->NearAccordingToUnreal = (distsq <= radiussq);
}
}
}
void UlxTangibleManager::DeleteFarawayTangibles() {
// Make a list of tangibles that need to be deleted.
TanArray faraway;
for (const auto& pair : IdToTangible) {
UlxTangible *tan = pair.Value;
if (!(tan->NearAccordingToLuprex || tan->NearAccordingToUnreal)) {
faraway.Add(tan);
}
}
for (UlxTangible *tan : faraway) {
IdToTangible.Remove(tan->TangibleId);
tan->Destroy(); // Remove the actor from the scene.
}
}
2023-09-26 19:26:09 -04:00
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;
}