60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "enginewrapper.hpp"
|
|
|
|
// Class FLockableWrapper
|
|
//
|
|
// Contains the EngineWrapper and a Mutex to lock it.
|
|
// This class has no methods. To access the EngineWrapper,
|
|
// construct a FLockedWrapper, and then dereference it
|
|
// using operator right arrow.
|
|
//
|
|
class FLockableWrapper {
|
|
private:
|
|
FCriticalSection Mutex;
|
|
EngineWrapper Wrapper;
|
|
public:
|
|
friend class FLockedWrapper;
|
|
};
|
|
|
|
class FLockedWrapper {
|
|
private:
|
|
FLockableWrapper& Lockable;
|
|
|
|
public:
|
|
// The constructor of the FLockedWrapper claims the mutex.
|
|
FLockedWrapper(FLockableWrapper& w) : Lockable(w) {
|
|
Lockable.Mutex.Lock();
|
|
}
|
|
|
|
// The destructor of the FLockedWrapper releases the mutex.
|
|
~FLockedWrapper() {
|
|
Lockable.Mutex.Unlock();
|
|
}
|
|
|
|
// Operator right arrow accesses the EngineWrapper.
|
|
EngineWrapper* operator ->() {
|
|
return &Lockable.Wrapper;
|
|
}
|
|
|
|
// Get a pointer to the enginewrapper. This is 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();
|
|
};
|