Tangible creation and destruction in place

This commit is contained in:
2023-09-28 14:32:48 -04:00
parent 9116a7b8fe
commit 642b444d13
7 changed files with 174 additions and 32 deletions

View File

@@ -28,6 +28,7 @@ UlxTangible* UlxTangibleManager::GetTangible(int64 id) const {
}
}
#pragma optimize("", off)
UlxTangible* UlxTangibleManager::MakeTangible(int64 id) {
UlxTangible*& t = IdToTangible.FindOrAdd(id);
if (t == nullptr) {
@@ -56,7 +57,8 @@ TanArray UlxTangibleManager::GetAllTangibles() const {
return result;
}
void UlxTangibleManager::UpdateNear(IdView near) {
#pragma optimize("", off)
void UlxTangibleManager::UpdateNearAccordingToLuprex(IdView near) {
// Clear all the 'NearAccordingToLuprex' flags.
for (const auto& pair : IdToTangible) {
pair.Value->NearAccordingToLuprex = false;
@@ -69,6 +71,41 @@ void UlxTangibleManager::UpdateNear(IdView near) {
}
}
#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.
}
}
IdArray UlxTangibleManager::GetIds(const TanArray &arr) {
IdArray result;
result.SetNum(arr.Num());