Files
integration/Source/Integration/LockedWrapper.h

123 lines
2.8 KiB
C++

////////////////////////////////////////////////////////////
//
// LockedWrapper.h
//
// Mutex-guarded access to the EngineWrapper.
//
////////////////////////////////////////////////////////////
#pragma once
#include "CoreMinimal.h"
#include "lpx-enginewrapper.hpp"
#include "Common.h"
////////////////////////////////////////////////////////////
//
// FlxLockableWrapper
//
// Contains the EngineWrapper and a Mutex to lock it.
// This class has no methods. To access the
// EngineWrapper, construct a FlxLockedWrapper.
//
////////////////////////////////////////////////////////////
class FlxLockableWrapper {
private:
FCriticalSection Mutex;
EngineWrapper Wrapper;
// Temporary buffers used only inside wrapper
// methods. Nothing persistent in these.
//
TArray<uint32> AQLenBuffer;
TArray<const char*> AQStrBuffer;
public:
friend class FlxLockedWrapper;
};
////////////////////////////////////////////////////////////
//
// FlxLockedWrapper
//
// RAII lock guard. The constructor claims the mutex,
// the destructor releases it. Use operator-> to
// access the EngineWrapper.
//
////////////////////////////////////////////////////////////
class FlxLockedWrapper {
private:
FlxLockableWrapper& Lockable;
// Called by luprex to output debugging messages.
// A thin wrapper around UE_LOG.
//
static void DPrintHook(const char *Msg, size_t Size);
public:
// Import these types into our namespace.
//
using IdArray = LpxCommonTypes::IdArray;
using IdView = LpxCommonTypes::IdView;
using StringViewVec = LpxCommonTypes::StringViewVec;
public:
// The constructor claims the mutex.
//
FlxLockedWrapper(FlxLockableWrapper& w) : Lockable(w) {
Lockable.Mutex.Lock();
}
// The destructor releases the mutex.
//
~FlxLockedWrapper() {
Lockable.Mutex.Unlock();
}
// Operator-> accesses the EngineWrapper.
//
EngineWrapper* operator ->() {
return &Lockable.Wrapper;
}
// Get a pointer to the EngineWrapper. Not very
// safe because you could keep the pointer after
// the LockedWrapper is destroyed. Don't do that.
//
EngineWrapper* Get() {
return &Lockable.Wrapper;
}
// Initialize the engine wrapper if it's not
// already. All this does is open the DLL and
// hook up all the function pointers in the
// wrapper to point into the DLL.
//
void InitWrapper();
// Fetch Stdout as a string.
//
FString FetchStdout();
// Get the current Actor ID.
//
int64 GetActor();
// Get the list of tangibles near the actor.
//
// This function is fast but not free. You should
// fetch this once per frame and then store the
// IdView somewhere (like in the TangibleManager).
//
IdView GetNear(int64 id, double rx, double ry, double rz);
// Get animation queues.
//
// The array returned by this is valid until the
// next time you call this.
//
StringViewVec GetAnimationQueues(IdView ids);
};