Move tangible state into TangibleComponent
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "TangibleManager.h"
|
||||
#include "TangibleInterface.h"
|
||||
#include "IntegrationGameState.h"
|
||||
#include "TangibleComponent.h"
|
||||
#include "DebugPrint.h"
|
||||
|
||||
using namespace DebugPrint;
|
||||
@@ -10,39 +12,51 @@ using namespace DebugPrint;
|
||||
UTangibleManager::UTangibleManager() {
|
||||
World = nullptr;
|
||||
ClassTangibleActor = nullptr;
|
||||
Actor = 0;
|
||||
Player = 0;
|
||||
Near = IdView();
|
||||
}
|
||||
|
||||
void UTangibleManager::Init(UWorld *world, UClass* tanact) {
|
||||
World = world;
|
||||
ClassTangibleActor = tanact;
|
||||
Actor = 0;
|
||||
Player = 0;
|
||||
Near = IdView();
|
||||
}
|
||||
|
||||
UlxTangible *UTangibleManager::GetTangible(int64 id) {
|
||||
UlxTangible **p = IdToTangible.Find(id);
|
||||
UTangibleComponent *UTangibleManager::GetTangible(int64 id) {
|
||||
AActor **p = IdToActor.Find(id);
|
||||
if (p == nullptr) {
|
||||
return nullptr;
|
||||
} else {
|
||||
return *p;
|
||||
AActor* a = *p;
|
||||
UTangibleComponent* comp = a->FindComponentByClass<UTangibleComponent>();
|
||||
check(comp != nullptr);
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
|
||||
UlxTangible *UTangibleManager::MakeTangible(int64 id) {
|
||||
UlxTangible *& p = IdToTangible.FindOrAdd(id);
|
||||
UTangibleComponent *UTangibleManager::MakeTangible(int64 id) {
|
||||
AActor *& p = IdToActor.FindOrAdd(id);
|
||||
if (p == nullptr) {
|
||||
FVector location(0,0,0);
|
||||
FRotator rotation(0, 0, 0);
|
||||
FActorSpawnParameters params;
|
||||
AActor* a = World->SpawnActor(ClassTangibleActor, &location, &rotation, 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()));
|
||||
p = NewObject<UlxTangible>();
|
||||
p->Init(a, TEXT(""));
|
||||
// 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;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void UTangibleManager::DeleteTangible(int64 id) {
|
||||
@@ -51,10 +65,10 @@ void UTangibleManager::DeleteTangible(int64 id) {
|
||||
|
||||
UTangibleManager::IdArray UTangibleManager::GetLive() {
|
||||
IdArray result;
|
||||
result.SetNum(IdToTangible.Num());
|
||||
result.SetNum(IdToActor.Num());
|
||||
int next = 0;
|
||||
for (auto &pair : IdToTangible) {
|
||||
for (auto &pair : IdToActor) {
|
||||
result[next++] = pair.Key;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user