2023-09-02 01:33:11 -04:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "TangibleManager.h"
|
2023-09-26 17:00:30 -04:00
|
|
|
#include "Tangible.h"
|
2023-09-15 00:01:41 -04:00
|
|
|
#include "DebugPrint.h"
|
2024-02-02 15:48:27 -05:00
|
|
|
#include "IntegrationGameModeBase.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
|
|
|
|
2024-01-24 14:51:21 -05:00
|
|
|
UClass *UlxTangibleManager::GetTangibleClass(const FString &name) {
|
|
|
|
|
if (name.IsEmpty()) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FString path(TEXT("/Game/Tangibles/"));
|
|
|
|
|
path += name;
|
|
|
|
|
path += TCHAR('.');
|
|
|
|
|
path += name;
|
|
|
|
|
path += TCHAR('_');
|
|
|
|
|
path += TCHAR('C');
|
|
|
|
|
UClass *result = LoadObject<UClass>(nullptr, *path);
|
|
|
|
|
if (result != nullptr) {
|
|
|
|
|
if (!result->IsChildOf(AActor::StaticClass())) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (!result->ImplementsInterface(UlxTangibleInterface::StaticClass())) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 17:00:30 -04:00
|
|
|
UlxTangibleManager::UlxTangibleManager() {
|
2023-09-06 23:25:37 -04:00
|
|
|
World = nullptr;
|
2024-03-25 14:50:06 -04:00
|
|
|
PossessedTangible = nullptr;
|
2023-09-06 23:25:37 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-02 15:48:27 -05:00
|
|
|
void UlxTangibleManager::Init(UWorld* world, AIntegrationGameModeBase *gamemode) {
|
2023-09-02 01:39:35 -04:00
|
|
|
World = world;
|
2024-02-02 15:48:27 -05:00
|
|
|
GameMode = gamemode;
|
2023-09-02 01:39:35 -04:00
|
|
|
}
|
|
|
|
|
|
2023-09-26 19:26:09 -04:00
|
|
|
UlxTangible* UlxTangibleManager::GetTangible(int64 id) const {
|
|
|
|
|
UlxTangible*const* p = IdToTangible.Find(id);
|
2023-09-02 01:43:44 -04:00
|
|
|
if (p == nullptr) {
|
|
|
|
|
return nullptr;
|
2023-09-26 19:26:09 -04:00
|
|
|
} else {
|
2023-09-26 17:00:30 -04:00
|
|
|
return *p;
|
2023-09-02 01:43:44 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-28 14:32:48 -04:00
|
|
|
#pragma optimize("", off)
|
2023-09-26 17:00:30 -04:00
|
|
|
UlxTangible* UlxTangibleManager::MakeTangible(int64 id) {
|
2024-03-25 14:50:06 -04:00
|
|
|
check(id > 0);
|
2023-09-26 17:00:30 -04:00
|
|
|
UlxTangible*& t = IdToTangible.FindOrAdd(id);
|
|
|
|
|
if (t == nullptr) {
|
|
|
|
|
t = NewObject<UlxTangible>();
|
|
|
|
|
t->Init(this, id);
|
2023-09-02 01:43:44 -04:00
|
|
|
}
|
2023-09-26 17:00:30 -04:00
|
|
|
return t;
|
2023-09-02 01:43:44 -04:00
|
|
|
}
|
|
|
|
|
|
2023-09-26 17:00:30 -04:00
|
|
|
void UlxTangibleManager::DeleteTangible(int64 id) {
|
2023-09-02 01:43:44 -04:00
|
|
|
// IMPLEMENT ME
|
|
|
|
|
}
|
2023-09-07 23:50:49 -04:00
|
|
|
|
2023-09-26 19:26:09 -04:00
|
|
|
TanArray UlxTangibleManager::GetAllTangibles() const {
|
|
|
|
|
TanArray result;
|
2023-09-26 17:00:30 -04:00
|
|
|
result.SetNum(IdToTangible.Num());
|
2023-09-07 23:50:49 -04:00
|
|
|
int next = 0;
|
2023-09-26 17:00:30 -04:00
|
|
|
for (auto& pair : IdToTangible) {
|
2023-09-26 19:26:09 -04:00
|
|
|
result[next++] = pair.Value;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-25 14:50:06 -04:00
|
|
|
UlxTangible *UlxTangibleManager::SetPossessedTangible(int64 id) {
|
|
|
|
|
UlxTangible *t = GetTangible(id);
|
|
|
|
|
if ((t == nullptr) || (t->GetActor() == nullptr)) {
|
|
|
|
|
PossessedTangible = nullptr;
|
|
|
|
|
return nullptr;
|
|
|
|
|
} else if (t == PossessedTangible) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
} else {
|
|
|
|
|
PossessedTangible = t;
|
|
|
|
|
return t;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-28 14:32:48 -04:00
|
|
|
#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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-28 14:32:48 -04:00
|
|
|
#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;
|
2023-09-07 23:50:49 -04:00
|
|
|
}
|
|
|
|
|
return result;
|
2023-09-25 18:00:34 -04:00
|
|
|
}
|
2023-09-26 17:00:30 -04:00
|
|
|
|