diff --git a/Content/Luprex/lxPlayerController.uasset b/Content/Luprex/lxPlayerController.uasset old mode 100755 new mode 100644 index 4e8dc394..c51bb8f3 --- a/Content/Luprex/lxPlayerController.uasset +++ b/Content/Luprex/lxPlayerController.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f4e43d91536417b9529fb4ce5c5d01608b8694a536a4dc5b395458aaf0aeb225 -size 13343 +oid sha256:d690f8771b240cacc7cb77ee747c218b4b3a1283b5f8bbaf0fc8f15a2ef30d12 +size 85529 diff --git a/Integration.code-workspace.tpl.json b/Integration.code-workspace.tpl.json index 413eb5b1..aafbfb12 100644 --- a/Integration.code-workspace.tpl.json +++ b/Integration.code-workspace.tpl.json @@ -3,11 +3,11 @@ "", "The unreal build system generates Integration.code-workspace.", "That generated file is no good. Instead, we generate our own,", - "as part of build-everything.py", + "as part of build.py", "", "Don't edit Integration.code-worspace, instead, edit", "Integration.code-workspace.tpl.json, and then run", - "build-everything.py to rebuild.", + "build.py code-workspace to rebuild.", "" ], "folders": [ @@ -65,7 +65,6 @@ "vadimcn.vscode-lldb", "dfarley1.file-picker", "ms-python.python", - "ms-dotnettools.csharp", "ms-vscode.mono-debug" ] }, @@ -88,15 +87,6 @@ "clear": true }, "problemMatcher": [ - { - "owner": "build-luprex", - "source": "build.py", - "fileLocation": ["relative", "${workspaceFolder}/luprex"], - "pattern": { - "regexp": "^(.*):(\\d+):(\\d+):\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$", - "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 - } - }, { "owner": "build-integration", "source": "build.py", @@ -137,6 +127,7 @@ "initCommands": [ "command script import [UNREALENGINE]/Engine/Extras/LLDBDataFormatters/UEDataFormatters_2ByteChars.py", "settings set target.inline-breakpoint-strategy always", + "process handle SIGTRAP --notify false --pass false --stop false", "target stop-hook add --one-liner \"p ::UngrabAllInputImpl()\"" ] } diff --git a/Source/Integration/LuprexGameModeBase.cpp b/Source/Integration/LuprexGameModeBase.cpp index 03287bfa..d1d70e17 100644 --- a/Source/Integration/LuprexGameModeBase.cpp +++ b/Source/Integration/LuprexGameModeBase.cpp @@ -1,6 +1,7 @@ // Copyright Epic Games, Inc. All Rights Reserved. #include "LuprexGameModeBase.h" +#include "PlayerControllerBase.h" #include "LockedWrapper.h" #include "lpx-drvutil.hpp" #include "Misc/Paths.h" @@ -56,10 +57,6 @@ void ALuprexGameModeBase::ResetToInitialState() // Clear the PlayerID PlayerId = 0; - // Clear the look-at state; - CurrentLookAt.Init(); - MustCallLookAtChanged = false; - // Reset the clocks. EngineSeconds = 0.0; } @@ -171,7 +168,8 @@ void ALuprexGameModeBase::OnWorldPostActorTick(UWorld* InWorld, ELevelTick InLev UpdateConsoleOutput(); UpdateTangibles(); UpdatePossessedTangible(); - UpdateLookAt(); + AlxPlayerControllerBase *PC = Cast(GetWorld()->GetFirstPlayerController()); + if (PC != nullptr) PC->UpdateLookAt(); } } @@ -258,52 +256,3 @@ ALuprexGameModeBase *ALuprexGameModeBase::FromContext(const UObject *context) { } -void ALuprexGameModeBase::SetLookAt(const UObject *Context, const FHitResult &HitResult) -{ - ALuprexGameModeBase *Mode = FromContext(Context); - if (Mode->CurrentLookAt.HitObjectHandle != HitResult.HitObjectHandle) - { - Mode->MustCallLookAtChanged = true; - } - Mode->CurrentLookAt = HitResult; -} - -void ALuprexGameModeBase::SetLookAtChanged(const UObject *Context) -{ - ALuprexGameModeBase *Mode = FromContext(Context); - Mode->MustCallLookAtChanged = true; -} - -FVector2D ALuprexGameModeBase::GetLookAtPixel(const UObject *Context) -{ - ALuprexGameModeBase *Mode = FromContext(Context); - APlayerController *pc = Context->GetWorld()->GetFirstPlayerController(); - if (pc == nullptr) return FVector2D(); - FVector2D ScreenPosition; - if (!UGameplayStatics::ProjectWorldToScreen(pc, Mode->CurrentLookAt.Location, ScreenPosition, false)) - { - return FVector2D(); - } - return ScreenPosition; -} - -void ALuprexGameModeBase::UpdateLookAt() { - // Make sure the world is fully configured before we attempt to cast rays. - UlxTangible *possessed = GetGameInstance()->GetSubsystem()->GetPossessedTangible(); - if (possessed == nullptr) return; - APlayerController *pc = GetWorld()->GetFirstPlayerController(); - if (pc == nullptr) return; - APawn *pawn = pc->GetPawn(); - if (pawn == nullptr) return; - if (possessed->GetActor() != pawn) return; - APlayerCameraManager *cam = pc->PlayerCameraManager; - if (cam == nullptr) return; - - CalculateLookAt(pc); - - if (MustCallLookAtChanged) { - MustCallLookAtChanged = false; - LookAtChanged(); - } -} - diff --git a/Source/Integration/LuprexGameModeBase.h b/Source/Integration/LuprexGameModeBase.h index 37976d57..850bc5cf 100644 --- a/Source/Integration/LuprexGameModeBase.h +++ b/Source/Integration/LuprexGameModeBase.h @@ -3,7 +3,6 @@ #pragma once #include "CoreMinimal.h" -#include "Engine/HitResult.h" #include "GameFramework/GameModeBase.h" #include "LuprexSockets.h" #include "BreakToDebugger.h" @@ -37,32 +36,6 @@ public: UFUNCTION(BlueprintCallable, Category = "Luprex|Miscellaneous") int64 GetPlayerId(); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "Context"), Category = "Luprex|Look-At Detection") - static void SetLookAt(const UObject *Context, const FHitResult &HitResult); - - UFUNCTION(BlueprintPure, meta = (WorldContext = "Context"),Category = "Luprex|Look-At Detection") - static const FHitResult &GetLookAt(const UObject *Context) { return FromContext(Context)->CurrentLookAt; } - - UFUNCTION(BlueprintPure, meta = (WorldContext = "Context"),Category = "Luprex|Look-At Detection") - static const AActor *GetLookAtActor(const UObject *Context) { return FromContext(Context)->CurrentLookAt.GetActor(); } - - UFUNCTION(BlueprintPure, meta = (WorldContext = "Context"),Category = "Luprex|Look-At Detection") - static FVector2D GetLookAtPixel(const UObject *Context); - - UFUNCTION(BlueprintCallable, meta = (WorldContext = "Context"), Category = "Luprex|Look-At Detection") - static void SetLookAtChanged(const UObject* Context); - - // - // Look-At Related Events - // - - UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Look-At Detection") - void CalculateLookAt(APlayerController *PlayerController); - - UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Look-At Detection") - void LookAtChanged(); - - // Transfer console output from the Luprex engine to unreal. void UpdateConsoleOutput(); @@ -75,10 +48,6 @@ public: // Tell the player controller to possess that tangible. void UpdatePossessedTangible(); - // Call 'CalculateLookAt', but only if everything is valid. - // It is up to the blueprint code to actually determine what we're looking at. - void UpdateLookAt(); - // If the engine wants a new copy of the lua source code, // provide it. void UpdateLuaSourceCode(); @@ -94,12 +63,6 @@ public: // Get the current Luprex Game Mode Base, given a Context object. static ALuprexGameModeBase *FromContext(const UObject *Context); - // The actor that the player is looking at, current frame. - UPROPERTY() - FHitResult CurrentLookAt; - - bool MustCallLookAtChanged = false; - // The sensitivity level at which a log message triggers a debugger breakpoint. UPROPERTY(EditAnywhere, Category="Debugging Tools") ElxBreakToDebuggerThreshold BreakToDebuggerLogVerbosity; diff --git a/Source/Integration/PlayerControllerBase.cpp b/Source/Integration/PlayerControllerBase.cpp new file mode 100644 index 00000000..39de819d --- /dev/null +++ b/Source/Integration/PlayerControllerBase.cpp @@ -0,0 +1,74 @@ +#include "PlayerControllerBase.h" +#include "Common.h" +#include "Tangible.h" +#include "TangibleManager.h" +#include "Kismet/GameplayStatics.h" +#include "Engine/GameInstance.h" + +AlxPlayerControllerBase *AlxPlayerControllerBase::FromContext(const UObject *Context) +{ + APlayerController *PC = Context->GetWorld()->GetFirstPlayerController(); + AlxPlayerControllerBase *Result = Cast(PC); + if (Result == nullptr) + { + UE_LOG(LogLuprexIntegration, Fatal, TEXT("Not currently using a Luprex Player Controller.")); + } + return Result; +} + +const FHitResult &AlxPlayerControllerBase::GetLookAt(const UObject *Context) +{ + return FromContext(Context)->CurrentLookAt; +} + +const AActor *AlxPlayerControllerBase::GetLookAtActor(const UObject *Context) +{ + return FromContext(Context)->CurrentLookAt.GetActor(); +} + +void AlxPlayerControllerBase::SetLookAt(const UObject *Context, const FHitResult &HitResult) +{ + AlxPlayerControllerBase *PC = FromContext(Context); + if (PC->CurrentLookAt.HitObjectHandle != HitResult.HitObjectHandle) + { + PC->MustCallLookAtChanged = true; + } + PC->CurrentLookAt = HitResult; +} + +void AlxPlayerControllerBase::SetLookAtChanged(const UObject *Context) +{ + AlxPlayerControllerBase *PC = FromContext(Context); + PC->MustCallLookAtChanged = true; +} + +FVector2D AlxPlayerControllerBase::GetLookAtPixel(const UObject *Context) +{ + AlxPlayerControllerBase *PC = FromContext(Context); + FVector2D ScreenPosition; + if (!UGameplayStatics::ProjectWorldToScreen(PC, PC->CurrentLookAt.Location, ScreenPosition, false)) + { + return FVector2D(); + } + return ScreenPosition; +} + +void AlxPlayerControllerBase::UpdateLookAt() +{ + UlxTangibleManager *TM = GetGameInstance()->GetSubsystem(); + if (TM == nullptr) return; + UlxTangible *Possessed = TM->GetPossessedTangible(); + if (Possessed == nullptr) return; + APawn *Pawn = GetPawn(); + if (Pawn == nullptr) return; + if (Possessed->GetActor() != Pawn) return; + if (PlayerCameraManager == nullptr) return; + + CalculateLookAt(); + + if (MustCallLookAtChanged) + { + MustCallLookAtChanged = false; + LookAtChanged(); + } +} diff --git a/Source/Integration/PlayerControllerBase.h b/Source/Integration/PlayerControllerBase.h new file mode 100644 index 00000000..8e70f54f --- /dev/null +++ b/Source/Integration/PlayerControllerBase.h @@ -0,0 +1,46 @@ +#pragma once + +#include "CoreMinimal.h" +#include "Engine/HitResult.h" +#include "GameFramework/PlayerController.h" +#include "PlayerControllerBase.generated.h" + +UCLASS(BlueprintType, Blueprintable) +class INTEGRATION_API AlxPlayerControllerBase : public APlayerController +{ + GENERATED_BODY() + +public: + UFUNCTION(BlueprintCallable, meta = (WorldContext = "Context"), Category = "Luprex|Look-At Detection") + static void SetLookAt(const UObject *Context, const FHitResult &HitResult); + + UFUNCTION(BlueprintPure, meta = (WorldContext = "Context"), Category = "Luprex|Look-At Detection") + static const FHitResult &GetLookAt(const UObject *Context); + + UFUNCTION(BlueprintPure, meta = (WorldContext = "Context"), Category = "Luprex|Look-At Detection") + static const AActor *GetLookAtActor(const UObject *Context); + + UFUNCTION(BlueprintPure, meta = (WorldContext = "Context"), Category = "Luprex|Look-At Detection") + static FVector2D GetLookAtPixel(const UObject *Context); + + UFUNCTION(BlueprintCallable, meta = (WorldContext = "Context"), Category = "Luprex|Look-At Detection") + static void SetLookAtChanged(const UObject *Context); + + // Blueprint events + UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Look-At Detection") + void CalculateLookAt(); + + UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Look-At Detection") + void LookAtChanged(); + + // Called by GameMode each tick. + void UpdateLookAt(); + + // Get the player controller, cast to AlxPlayerControllerBase. + static AlxPlayerControllerBase *FromContext(const UObject *Context); + + UPROPERTY() + FHitResult CurrentLookAt; + + bool MustCallLookAtChanged = false; +};