Changes related to 'SetPossessedTangible'

This commit is contained in:
2024-03-25 14:50:06 -04:00
parent 0d94b1b9af
commit d520189a94
6 changed files with 49 additions and 3 deletions

Binary file not shown.

View File

@@ -120,6 +120,12 @@ void AIntegrationGameModeBase::UpdateTangibles() {
for (int i = 0; i < alltans.Num(); i++) { for (int i = 0; i < alltans.Num(); i++) {
alltans[i]->UpdateAnimationQueue(allqueues[i]); alltans[i]->UpdateAnimationQueue(allqueues[i]);
} }
// Maybe call 'BecomePossessed' on some tangible.
UlxTangible *poss = TangibleManager->SetPossessedTangible(PlayerId);
if (poss != nullptr) {
IlxTangibleInterface::Execute_BecomePossessed(poss->GetActor());
}
} }
// This is where we run the blueprint code that updates animation // This is where we run the blueprint code that updates animation
// states. Be aware that the blueprint code could call back // states. Be aware that the blueprint code could call back

View File

@@ -52,7 +52,13 @@ void UlxTangible::SetActorBlueprint(const FString &name) {
// Now destroy the actor itself. According to various // Now destroy the actor itself. According to various
// documents I've read online, it may be necessary to take // documents I've read online, it may be necessary to take
// further steps to delete the object. Not clear. // further steps to delete the object. Not clear.
CurrentActor->Destroy(); CurrentActor->Destroy();
// If this actor previously was posessed by a player controller,
// then it's not posessed anymore, because there is no actor any more.
if (Manager->PossessedTangible == this) {
Manager->PossessedTangible = nullptr;
};
} }
// Update the blueprint name // Update the blueprint name

View File

@@ -34,6 +34,9 @@ class INTEGRATION_API IlxTangibleInterface
public: public:
UFUNCTION(BlueprintImplementableEvent, Category = "Tangible Functionality") UFUNCTION(BlueprintImplementableEvent, Category = "Tangible Functionality")
bool AnimationStateChanged(); bool AnimationStateChanged();
UFUNCTION(BlueprintImplementableEvent, Category = "Tangible Functionality")
void BecomePossessed();
}; };

View File

@@ -35,6 +35,7 @@ UClass *UlxTangibleManager::GetTangibleClass(const FString &name) {
UlxTangibleManager::UlxTangibleManager() { UlxTangibleManager::UlxTangibleManager() {
World = nullptr; World = nullptr;
PossessedTangible = nullptr;
} }
void UlxTangibleManager::Init(UWorld* world, AIntegrationGameModeBase *gamemode) { void UlxTangibleManager::Init(UWorld* world, AIntegrationGameModeBase *gamemode) {
@@ -53,6 +54,7 @@ UlxTangible* UlxTangibleManager::GetTangible(int64 id) const {
#pragma optimize("", off) #pragma optimize("", off)
UlxTangible* UlxTangibleManager::MakeTangible(int64 id) { UlxTangible* UlxTangibleManager::MakeTangible(int64 id) {
check(id > 0);
UlxTangible*& t = IdToTangible.FindOrAdd(id); UlxTangible*& t = IdToTangible.FindOrAdd(id);
if (t == nullptr) { if (t == nullptr) {
t = NewObject<UlxTangible>(); t = NewObject<UlxTangible>();
@@ -75,6 +77,19 @@ TanArray UlxTangibleManager::GetAllTangibles() const {
return result; return result;
} }
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;
}
}
#pragma optimize("", off) #pragma optimize("", off)
void UlxTangibleManager::UpdateNearAccordingToLuprex(IdView near) { void UlxTangibleManager::UpdateNearAccordingToLuprex(IdView near) {
// Clear all the 'NearAccordingToLuprex' flags. // Clear all the 'NearAccordingToLuprex' flags.

View File

@@ -33,6 +33,9 @@ public:
UPROPERTY() UPROPERTY()
TMap<int64, UlxTangible*> IdToTangible; TMap<int64, UlxTangible*> IdToTangible;
// The Tangible ID of the posessed tangible, if any.
UlxTangible *PossessedTangible;
public: public:
UlxTangibleManager(); UlxTangibleManager();
@@ -63,6 +66,19 @@ public:
// //
TanArray GetAllTangibles() const; TanArray GetAllTangibles() const;
// Set the currently-posessed tangible.
//
// If the specified tangible is invalid:
// Sets the possessed tangible to nullptr and returns nullptr.
//
// If the specified tangible is valid, but it's already possessed:
// Does nothing and returns nullptr.
//
// If the specified tangible is valid, and is not already possessed:
// Sets the possessed tangible as specified and returns it.
//
UlxTangible *SetPossessedTangible(int64 playerid);
// Update the 'NearAccordingToLuprex' flags. // Update the 'NearAccordingToLuprex' flags.
// //
// Also creates stub tangibles for every Id in the list. // Also creates stub tangibles for every Id in the list.