Files
integration/Source/Integration/LockedWrapper.cpp

77 lines
2.2 KiB
C++
Raw Normal View History

2023-09-03 02:01:32 -04:00
#include "LockedWrapper.h"
#include "DebugPrint.h"
#include "lpx-drvutil.hpp"
2023-09-03 02:01:32 -04:00
using namespace CommonTypes;
2023-09-15 13:28:18 -04:00
void FlxLockedWrapper::InitWrapper() {
2023-09-03 02:01:32 -04:00
if (Lockable.Wrapper.play_initialize != nullptr) {
// Already initialized.
return;
}
void* DLL = FPlatformProcess::GetDllHandle(TEXT("c:\\Luprex\\build\\visual\\luprexlib.dll"));
if (DLL != nullptr) {
using InitFn = void (*)(EngineWrapper*);
InitFn init = (InitFn)FPlatformProcess::GetDllExport(DLL, TEXT("init_engine_wrapper"));
if (init != nullptr) {
init(&Lockable.Wrapper);
2023-09-04 03:21:23 -04:00
Lockable.Wrapper.hook_dprint(DebugPrint::DPrint);
2023-09-03 02:01:32 -04:00
}
}
}
2023-09-15 13:28:18 -04:00
FString FlxLockedWrapper::FetchStdout() {
uint32_t ndata; const char* data;
Lockable.Wrapper.get_outgoing(Get(), 0, &ndata, &data);
if (ndata == 0) {
return FString();
}
std::string_view src(data, ndata);
int consumed;
std::u16string cps = drvutil::utf8_to_ucs2(src, &consumed);
Lockable.Wrapper.play_sent_outgoing(Get(), 0, consumed);
return FString(cps.size(), (const UCS2CHAR*)(&cps[0]));
}
2023-09-15 13:28:18 -04:00
int64 FlxLockedWrapper::GetActor() {
return Lockable.Wrapper.get_actor_id(Get());
}
2023-09-15 13:28:18 -04:00
IdView FlxLockedWrapper::GetNear(int64 id, double rx, double ry, double rz) {
uint32 size;
int64* data;
2023-10-16 15:08:11 -04:00
Lockable.Wrapper.get_tangibles_near(Get(), id, rx, ry, rz, &size, (int64_t**)&data);
return IdView(data, size);
}
2023-09-15 13:28:18 -04:00
StringViewVec FlxLockedWrapper::GetAnimationQueues(IdView ids) {
// How many animation queues are we fetching?
int num = ids.Num();
// Enlarge the static 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);
}
// Get pointers to the static buffers.
uint32* LenBuf = Lockable.AQLenBuffer.GetData();
const char** StrBuf = Lockable.AQStrBuffer.GetData();
// Get the animation queues into the static buffers.
2023-10-16 15:08:11 -04:00
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
StringViewVec result;
result.SetNum(num);
for (int i = 0; i < num; i++) {
result[i] = std::string_view(StrBuf[i], LenBuf[i]);
}
return result;
2023-10-16 15:08:11 -04:00
}