Files
integration/Source/Integration/LuprexGameModeBase.h
2026-02-27 18:40:29 -05:00

128 lines
4.3 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Engine/HitResult.h"
#include "GameFramework/GameModeBase.h"
#include "LuprexSockets.h"
#include "BreakToDebugger.h"
#include "LuprexGameModeBase.generated.h"
/**
*
*/
UCLASS(BlueprintType)
class INTEGRATION_API ALuprexGameModeBase : public AGameModeBase
{
GENERATED_BODY()
public:
ALuprexGameModeBase();
~ALuprexGameModeBase();
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason);
// Delete all the state created in BeginPlay. That
// includes: the Luprex engine, the thread, and the socket state.
void ResetToInitialState();
// Initialize the Luprex DLL, and do other global initialization.
void InitializeGlobalState();
// Send prints into Unreal, for display on the virtual console.
UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Miscellaneous")
void ConsoleAddOutput(const FString& text);
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();
// Update the tangibles according to what Luprex tells us.
// This also includes calling 'AnimationQueueChanged' on all
// tangibles that have been changed.
void UpdateTangibles();
// Look for a tangible whose ID is equal to the current actor ID.
// 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();
// Update Sockets and Lua. Feeds socket data into the luprex engine,
// and also calls play_update, the main Lua update function that causes
// Luprex to execute the majority of all the Lua code that needs processing.
void UpdateSocketsAndLua();
// Post-tick function.
void OnWorldPostActorTick(UWorld* InWorld, ELevelTick InLevelTick, float InDeltaSeconds);
// 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;
// Luprex socket system.
TUniquePtr<FlxSockets> Sockets;
// True if 'BeginPlay' has been successfully completed.
bool Playing = false;
// This is always true unless you use the debugger to set it to false.
bool TickEnabled = true;
// Current Player ID
int64 PlayerId = 0;
// Amount of elapsed time since BeginPlay.
float EngineSeconds = 0.0f;
// This allows us to post-tick.
FDelegateHandle OnWorldPostActorTickHandle;
// The device that implements BreakToDebuggerLogVerbosity, above.
TUniquePtr<FlxBreakToDebuggerOutputDevice> BreakToDebuggerLogVerbosityDevice;
};