TangibleCharacter can now be interactively controlled
This commit is contained in:
@@ -17,6 +17,7 @@ using namespace CommonTypes;
|
||||
AIntegrationGameModeBase::AIntegrationGameModeBase()
|
||||
{
|
||||
TangibleManager = NewObject<UlxTangibleManager>();
|
||||
PlayerId = 0;
|
||||
EngineSeconds = 0.0;
|
||||
NextThreadTrigger = 1.0;
|
||||
//PrimaryActorTick.bCanEverTick = true; // Probably wrong
|
||||
@@ -113,14 +114,13 @@ void AIntegrationGameModeBase::MaybeTriggerUpdateTask(float deltaseconds) {
|
||||
|
||||
|
||||
#pragma optimize("", off)
|
||||
|
||||
void AIntegrationGameModeBase::UpdateTangibles() {
|
||||
double radius = 1000.0; // Hardwired for now.
|
||||
using TanArray = UlxTangibleManager::TanArray;
|
||||
if (!Playing) return;
|
||||
FlxLockedWrapper w(LockableWrapper);
|
||||
int64 player = w.GetActor();
|
||||
IdView nearids = w.GetNear(player, radius, radius, radius);
|
||||
PlayerId = w.GetActor();
|
||||
IdView nearids = w.GetNear(PlayerId, radius, radius, radius);
|
||||
TangibleManager->UpdateNearAccordingToLuprex(nearids);
|
||||
TanArray alltans = TangibleManager->GetAllTangibles();
|
||||
IdArray allids = TangibleManager->GetIds(alltans);
|
||||
@@ -128,7 +128,7 @@ void AIntegrationGameModeBase::UpdateTangibles() {
|
||||
for (int i = 0; i < alltans.Num(); i++) {
|
||||
alltans[i]->UpdateAnimationQueue(allqueues[i]);
|
||||
}
|
||||
TangibleManager->RecalcNearAccordingToUnreal(player, radius);
|
||||
TangibleManager->RecalcNearAccordingToUnreal(PlayerId, radius);
|
||||
TangibleManager->DeleteFarawayTangibles();
|
||||
}
|
||||
|
||||
@@ -155,6 +155,10 @@ void AIntegrationGameModeBase::ExecuteDebuggingCommand(const FString &fs) {
|
||||
|
||||
void AIntegrationGameModeBase::ConsoleSendInput(const FString& fs)
|
||||
{
|
||||
if (fs.IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
FlxLockedWrapper w(LockableWrapper);
|
||||
if (w->engine != nullptr)
|
||||
{
|
||||
@@ -253,7 +257,7 @@ void AIntegrationGameModeBase::BeginPlay()
|
||||
|
||||
// Initialize the tangible manager.
|
||||
TangibleManager = NewObject<UlxTangibleManager>();
|
||||
TangibleManager->Init(GetWorld());
|
||||
TangibleManager->Init(GetWorld(), this);
|
||||
}
|
||||
|
||||
void AIntegrationGameModeBase::EndPlay(const EEndPlayReason::Type EndPlayReason)
|
||||
@@ -261,3 +265,6 @@ void AIntegrationGameModeBase::EndPlay(const EEndPlayReason::Type EndPlayReason)
|
||||
ResetToInitialState();
|
||||
}
|
||||
|
||||
int64 AIntegrationGameModeBase::GetPlayerId() {
|
||||
return PlayerId;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,9 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "Luprex")
|
||||
void ConsoleSendInput(const FString& text);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Luprex")
|
||||
int64 GetPlayerId();
|
||||
|
||||
// Execute a debugging command, typed on the GUI.
|
||||
void ExecuteDebuggingCommand(const FString &fs);
|
||||
|
||||
@@ -72,9 +75,11 @@ public:
|
||||
TUniquePtr<FlxSockets> Sockets;
|
||||
|
||||
// True if 'BeginPlay' has been successfully completed.
|
||||
//
|
||||
bool Playing;
|
||||
|
||||
// Current Player ID
|
||||
int64 PlayerId;
|
||||
|
||||
// Amount of elapsed time since BeginPlay.
|
||||
float EngineSeconds;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "Tangible.h"
|
||||
#include "TangibleManager.h"
|
||||
#include "IntegrationGameModeBase.h"
|
||||
|
||||
#define DEFAULT_BLUEPRINT (TEXT("TangibleStaticMesh"))
|
||||
|
||||
@@ -59,23 +60,37 @@ void UlxTangible::SetActorBlueprint(const FString &name) {
|
||||
|
||||
// Now create a new actor, unless the BP is nullptr.
|
||||
if (blueprint != nullptr) {
|
||||
// Create the actor.
|
||||
FActorSpawnParameters params;
|
||||
FVector location(0, 0, 0);
|
||||
FRotator rotation(0, 0, 0);
|
||||
UWorld* w = Manager->GetWorld();
|
||||
FActorSpawnParameters params;
|
||||
|
||||
// Currently, the actor is spawned at (0,0,0), which is not good.
|
||||
// We should spawn at the actor's current location. I'll get to it
|
||||
// eventually.
|
||||
FTransform transform;
|
||||
transform.SetLocation(FVector(0,0,0));
|
||||
transform.SetRotation(FQuat(FRotator(0,0,0)));
|
||||
|
||||
// Create the actor at the specified location even if there's something in the way.
|
||||
params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||
AActor* a = w->SpawnActor(blueprint, &location, &rotation, params);
|
||||
|
||||
// Normally, SpawnActor runs the BeginPlay entry point. We
|
||||
// want to delay that until after we've had a chance to set
|
||||
// up the TangibleComponent.
|
||||
params.bDeferConstruction = true;
|
||||
AActor* a = w->SpawnActor(blueprint, &transform, params);
|
||||
check(a != nullptr);
|
||||
|
||||
// Insert a TangibleComponent into the actor.
|
||||
// Link the actor to its tangible, and the tangible to its actor.
|
||||
UActorComponent* ac = a->AddComponentByClass(UlxTangibleComponent::StaticClass(), false, FTransform::Identity, false);
|
||||
UlxTangibleComponent* tc = Cast<UlxTangibleComponent>(ac);
|
||||
check(tc != nullptr);
|
||||
|
||||
// Make the tangible point to the actor and vice versa.
|
||||
tc->Tangible = this;
|
||||
CurrentActor = a;
|
||||
|
||||
// This executes the BeginPlay entry point. We have to do this here
|
||||
// because we deferred it in SpawnActor.
|
||||
a->FinishSpawning(transform, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,3 +155,8 @@ void UlxTangible::SetTangiblePlane(AActor* target, const FString& plane) {
|
||||
GetActorTangible(target)->Plane = FName(plane);
|
||||
}
|
||||
|
||||
bool UlxTangible::IsCurrentPlayer(AActor* target) {
|
||||
UlxTangible *tan = GetActorTangible(target);
|
||||
AIntegrationGameModeBase *gamemode = tan->Manager->GetGameMode();
|
||||
return (tan->TangibleId == gamemode->PlayerId);
|
||||
}
|
||||
@@ -160,6 +160,9 @@ public:
|
||||
|
||||
UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = Luprex)
|
||||
static void SetTangiblePlane(AActor* target, const FString& plane);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = Luprex)
|
||||
static bool IsCurrentPlayer(AActor *target);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "TangibleManager.h"
|
||||
#include "Tangible.h"
|
||||
#include "DebugPrint.h"
|
||||
#include "IntegrationGameModeBase.h"
|
||||
|
||||
using namespace DebugPrint;
|
||||
using TanArray = UlxTangibleManager::TanArray;
|
||||
@@ -36,8 +37,9 @@ UlxTangibleManager::UlxTangibleManager() {
|
||||
World = nullptr;
|
||||
}
|
||||
|
||||
void UlxTangibleManager::Init(UWorld* world) {
|
||||
void UlxTangibleManager::Init(UWorld* world, AIntegrationGameModeBase *gamemode) {
|
||||
World = world;
|
||||
GameMode = gamemode;
|
||||
}
|
||||
|
||||
UlxTangible* UlxTangibleManager::GetTangible(int64 id) const {
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include "Tangible.h"
|
||||
#include "TangibleManager.generated.h"
|
||||
|
||||
class AIntegrationGameModeBase;
|
||||
|
||||
UCLASS()
|
||||
class INTEGRATION_API UlxTangibleManager : public UObject
|
||||
{
|
||||
@@ -23,6 +25,10 @@ public:
|
||||
UPROPERTY()
|
||||
TWeakObjectPtr<UWorld> World;
|
||||
|
||||
// A pointer to our game mode.
|
||||
UPROPERTY()
|
||||
TWeakObjectPtr<AIntegrationGameModeBase> GameMode;
|
||||
|
||||
// Given a tangible ID, look up the TangibleComponent of that actor.
|
||||
UPROPERTY()
|
||||
TMap<int64, UlxTangible*> IdToTangible;
|
||||
@@ -32,12 +38,15 @@ public:
|
||||
|
||||
// Initialize the tangible manager.
|
||||
//
|
||||
void Init(UWorld *world);
|
||||
void Init(UWorld *world, AIntegrationGameModeBase *gamemode);
|
||||
|
||||
// Get a pointer to our world.
|
||||
//
|
||||
UWorld* GetWorld() const override { return World.Get(); }
|
||||
|
||||
// Get a pointer to our game mode.
|
||||
AIntegrationGameModeBase *GetGameMode() { return GameMode.Get(); }
|
||||
|
||||
// Get the tangible if it exists, otherwise return NULL
|
||||
//
|
||||
UlxTangible* GetTangible(int64 id) const;
|
||||
|
||||
Reference in New Issue
Block a user