Refactoring to move things from GameMode into UlxEngineWrapper subsystem.

This commit is contained in:
2026-02-27 17:00:46 -05:00
parent 0aea1e0798
commit 7bb4854844
6 changed files with 99 additions and 119 deletions

View File

@@ -5,18 +5,13 @@
using namespace LpxCommonTypes;
UlxEngineWrapper* UlxEngineWrapper::Instance = nullptr;
void FlxLockedWrapper::DPrintHook(const char *Msg, size_t Size)
{
FString FMessage(Size, (const UTF8CHAR *)Msg);
UE_LOG(LogLuprex, Error, TEXT("%s"), *FMessage);
}
void UlxEngineWrapper::Initialize(FSubsystemCollectionBase& Collection) {
Super::Initialize(Collection);
Instance = this;
void FlxLockedWrapper::InitWrapper() {
if (Lockable.Wrapper.play_initialize != nullptr) {
// Already initialized.
return;
}
// Open the DLL and hook up all the function pointers.
#if PLATFORM_LINUX
FString dll = FPaths::Combine(FPaths::ProjectDir(), TEXT("luprex/build/Linux/luprexlib.so"));
#elif PLATFORM_WINDOWS
@@ -30,12 +25,24 @@ void FlxLockedWrapper::InitWrapper() {
using InitFn = void (*)(EngineWrapper*);
InitFn init = (InitFn)FPlatformProcess::GetDllExport(DLL, TEXT("init_engine_wrapper"));
if (init != nullptr) {
init(&Lockable.Wrapper);
Lockable.Wrapper.hook_dprint(DPrintHook);
init(&Wrapper);
Wrapper.hook_dprint(DPrintHook);
}
}
}
void UlxEngineWrapper::Deinitialize() {
Instance = nullptr;
Super::Deinitialize();
}
void UlxEngineWrapper::DPrintHook(const char *Msg, size_t Size)
{
FString FMessage(Size, (const UTF8CHAR *)Msg);
UE_LOG(LogLuprex, Error, TEXT("%s"), *FMessage);
}
FString FlxLockedWrapper::ChannelPrints() {
if (Lockable.Wrapper.get_have_prints(Get()))
{
@@ -62,22 +69,27 @@ IdView FlxLockedWrapper::GetNear(int64 id, double rx, double ry, double rz) {
}
StringViewVec FlxLockedWrapper::GetAnimationQueues(IdView ids) {
// This is only called from the game thread, so
// these static buffers are safe without locking.
static TArray<uint32> AQLenBuffer;
static TArray<const char*> AQStrBuffer;
// How many animation queues are we fetching?
int num = ids.Num();
// Enlarge the static buffers if necessary.
// Enlarge the buffers if necessary.
// Add a little extra space so we don't have to enlarge
// the buffers every time we get a new tangible.
if (num > Lockable.AQLenBuffer.Num()) {
Lockable.AQLenBuffer.SetNum(num + 1000);
Lockable.AQStrBuffer.SetNum(num + 1000);
if (num > AQLenBuffer.Num()) {
AQLenBuffer.SetNum(num + 1000);
AQStrBuffer.SetNum(num + 1000);
}
// Get pointers to the static buffers.
uint32* LenBuf = Lockable.AQLenBuffer.GetData();
const char** StrBuf = Lockable.AQStrBuffer.GetData();
// Get pointers to the buffers.
uint32* LenBuf = AQLenBuffer.GetData();
const char** StrBuf = AQStrBuffer.GetData();
// Get the animation queues into the static buffers.
// Get the animation queues into the buffers.
Lockable.Wrapper.get_animation_queues(Get(), num, (const int64_t *)ids.GetData(), LenBuf, StrBuf);
// Transfer data from static buffers into an array of string_view