Class Tangible can now recreate its Actor

This commit is contained in:
2023-09-26 17:00:30 -04:00
parent cc6509a69c
commit 0efd0dd3ad
12 changed files with 261 additions and 207 deletions

View File

@@ -2,73 +2,60 @@
#include "TangibleManager.h"
#include "TangibleInterface.h"
#include "IntegrationGameState.h"
#include "TangibleComponent.h"
#include "Tangible.h"
#include "DebugPrint.h"
using namespace DebugPrint;
UTangibleManager::UTangibleManager() {
UlxTangibleManager::UlxTangibleManager() {
World = nullptr;
ClassTangibleActor = nullptr;
Player = 0;
Near = IdView();
}
void UTangibleManager::Init(UWorld *world, UClass* tanact) {
void UlxTangibleManager::Init(UWorld* world, UClass* tanact) {
World = world;
ClassTangibleActor = tanact;
Player = 0;
Near = IdView();
}
UTangibleComponent *UTangibleManager::GetTangible(int64 id) {
AActor **p = IdToActor.Find(id);
UlxTangible* UlxTangibleManager::GetTangible(int64 id) {
UlxTangible** p = IdToTangible.Find(id);
if (p == nullptr) {
return nullptr;
} else {
AActor* a = *p;
UTangibleComponent* comp = a->FindComponentByClass<UTangibleComponent>();
check(comp != nullptr);
return comp;
}
else {
return *p;
}
}
UTangibleComponent *UTangibleManager::MakeTangible(int64 id) {
AActor *& p = IdToActor.FindOrAdd(id);
if (p == nullptr) {
FActorSpawnParameters params;
FVector location(0, 0, 0);
FRotator rotation(0, 0, 0);
UWorld* w = GetWorld();
AActor* a = w->SpawnActor(ClassTangibleActor, &location, &rotation, params);
check(a != nullptr);
check(a->GetClass()->ImplementsInterface(UlxTangibleInterface::StaticClass()));
// Insert a TangibleComponent into the actor.
UActorComponent* ac = a->AddComponentByClass(UTangibleComponent::StaticClass(), false, FTransform::Identity, false);
UTangibleComponent* tc = Cast<UTangibleComponent>(ac);
check(tc != nullptr);
tc->Init(this, a, id);
p = a;
return tc;
} else {
UTangibleComponent* comp = p->FindComponentByClass<UTangibleComponent>();
check(comp != nullptr);
return comp;
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(ClassTangibleActor);
}
return t;
}
void UTangibleManager::DeleteTangible(int64 id) {
void UlxTangibleManager::DeleteTangible(int64 id) {
// IMPLEMENT ME
}
UTangibleManager::IdArray UTangibleManager::GetLive() {
UlxTangibleManager::IdArray UlxTangibleManager::GetLive() {
IdArray result;
result.SetNum(IdToActor.Num());
result.SetNum(IdToTangible.Num());
int next = 0;
for (auto &pair : IdToActor) {
for (auto& pair : IdToTangible) {
result[next++] = pair.Key;
}
return result;
}