Files
integration/Source/Integration/LuprexGameModeBase.h

153 lines
5.0 KiB
C
Raw Normal View History

2023-06-08 17:10:14 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Engine/HitResult.h"
2023-06-08 17:10:14 -04:00
#include "GameFramework/GameModeBase.h"
#include "lpx-enginewrapper.hpp"
2026-02-25 14:48:14 -05:00
#include "StreamBuffer.h"
#include "LuprexSockets.h"
#include "TriggeredTask.h"
#include "BreakToDebugger.h"
#include "LuprexGameModeBase.generated.h"
2023-06-08 17:10:14 -04:00
/**
2026-02-25 14:48:14 -05:00
*
2023-06-08 17:10:14 -04:00
*/
2025-04-07 16:48:27 -04:00
UCLASS(BlueprintType)
class INTEGRATION_API ALuprexGameModeBase : public AGameModeBase, public FRunnable
2023-06-08 17:10:14 -04:00
{
GENERATED_BODY()
public:
ALuprexGameModeBase();
~ALuprexGameModeBase();
2023-06-08 17:10:14 -04:00
virtual void BeginPlay() override;
2023-06-09 16:47:46 -04:00
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason);
2023-06-08 17:10:14 -04:00
2023-06-23 16:27:23 -04:00
// 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();
2026-02-09 13:54:00 -05:00
// Send prints into Unreal, for display on the virtual console.
UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Miscellaneous")
2025-12-09 02:42:13 -05:00
void ConsoleAddOutput(const FString& text);
2023-06-08 17:10:14 -04:00
UFUNCTION(BlueprintCallable, Category = "Luprex|Miscellaneous")
int64 GetPlayerId();
UFUNCTION(BlueprintCallable, meta = (WorldContext = "Context"), Category = "Luprex|Look-At Detection")
2025-04-07 16:48:27 -04:00
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(); }
2025-04-07 16:48:27 -04:00
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);
2025-04-07 16:48:27 -04:00
//
// Look-At Related Events
//
UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Look-At Detection")
void CalculateLookAt(APlayerController *PlayerController);
UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Look-At Detection")
void LookAtChanged();
2024-09-17 17:22:47 -04:00
// The Lua Call Assembly Buffer. Used by
// UlxLuaCallLibrary to build up a call across
// multiple UFUNCTION invocations.
2025-12-09 02:42:13 -05:00
//
FlxStreamBuffer &GetLuaCallBuffer() { return LuaCallBuffer; }
2024-09-04 23:15:13 -04:00
2023-06-23 12:45:23 -04:00
// 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();
// Pre-tick and post-tick functions.
void OnWorldPreActorTick(UWorld* InWorld, ELevelTick InLevelTick, float InDeltaSeconds);
void OnWorldPostActorTick(UWorld* InWorld, ELevelTick InLevelTick, float InDeltaSeconds);
2023-06-23 12:45:23 -04:00
// The run function is called by a background thread
// to update luprex sockets and update luprex itself.
virtual uint32 Run() override;
// 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.
2024-09-17 17:22:47 -04:00
UPROPERTY()
FHitResult CurrentLookAt;
2024-09-17 17:22:47 -04:00
bool MustCallLookAtChanged;
// The sensitivity level at which a log message triggers a debugger breakpoint.
UPROPERTY(EditAnywhere, Category="Debugging Tools")
ElxBreakToDebuggerThreshold BreakToDebuggerLogVerbosity;
2023-09-03 02:01:32 -04:00
// The Luprex EngineWrapper, with a Mutex to protect it.
2023-09-15 13:28:18 -04:00
// To access it, construct a FlxLockedWrapper.
//
2023-09-15 13:28:18 -04:00
FlxLockableWrapper LockableWrapper;
2023-06-23 16:27:23 -04:00
// Get the LockableWrapper.
//
FlxLockableWrapper& GetLockableWrapper() { return LockableWrapper; }
// The Lua Call Assembly Buffer.
2024-08-31 16:42:07 -04:00
FlxStreamBuffer LuaCallBuffer;
// This utility runs the luprex update and socket update in a thread.
FTriggeredTask LuprexUpdateTask;
2023-06-23 16:27:23 -04:00
// Luprex socket system. Aside from construction, only touched by Luprex thread.
2023-09-15 13:28:18 -04:00
TUniquePtr<FlxSockets> Sockets;
2023-06-23 16:27:23 -04:00
// True if 'BeginPlay' has been successfully completed.
bool Playing;
// This is always true unless you use the debugger to set it to false.
bool TickEnabled;
// Current Player ID
int64 PlayerId;
// Amount of elapsed time since BeginPlay.
2023-06-08 17:10:14 -04:00
float EngineSeconds;
2023-06-23 12:45:23 -04:00
// When do we next rotate the cube.
float NextRotateCube;
// These allow us to pre-tick and post-tick.
FDelegateHandle OnWorldPreActorTickHandle;
FDelegateHandle OnWorldPostActorTickHandle;
// The device that implements BreakToDebuggerLogVerbosity, above.
TUniquePtr<FlxBreakToDebuggerOutputDevice> BreakToDebuggerLogVerbosityDevice;
2023-06-08 17:10:14 -04:00
};