Files
integration/Source/Integration/LockedWrapper.h

94 lines
2.2 KiB
C
Raw Normal View History

2023-09-03 02:01:32 -04:00
#pragma once
#include "CoreMinimal.h"
#include "lpx-enginewrapper.hpp"
#include "CommonTypes.h"
2023-09-03 02:01:32 -04:00
// 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;
// Temporary buffers. These are only used
// inside wrapper methods. There's nothing
// persistent in these.
//
TArray<uint32> AQLenBuffer;
TArray<const char*> AQStrBuffer;
2023-09-03 02:01:32 -04:00
public:
friend class FLockedWrapper;
};
class FLockedWrapper {
private:
FLockableWrapper& Lockable;
public:
// Import these types into our Namespace.
using IdArray = CommonTypes::IdArray;
using IdView = CommonTypes::IdView;
using StringViewVec = CommonTypes::StringViewVec;
2023-09-03 02:01:32 -04:00
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();
// 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, for example).
//
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);
2023-09-03 02:01:32 -04:00
};