Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreal mqx support #125

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions hl2ss_unreal/Plugins/hl2ss/Source/hl2ss/Private/hl2ss_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ typedef void(*pfn_MQ_SI_Pop)(uint32_t& command, uint8_t* data);
typedef void(*pfn_MQ_SO_Push)(uint32_t id);
typedef void(*pfn_MQ_Restart)();

typedef uint32_t(*pfn_MQX_CO_Peek)();
typedef void(*pfn_MQX_CO_Pop)(uint32_t& id);
typedef void(*pfn_MQX_CI_Push)(uint32_t command, uint32_t size, uint8_t const* data);
typedef void(*pfn_MQX_Restart)();

#if PLATFORM_HOLOLENS
extern "C" { HMODULE LoadLibraryW(LPCWSTR lpLibFileName); }
#endif
Expand All @@ -34,6 +39,11 @@ void* hl2ss_api::p_MQ_SI_Pop = NULL;
void* hl2ss_api::p_MQ_SO_Push = NULL;
void* hl2ss_api::p_MQ_Restart = NULL;

void* hl2ss_api::p_MQX_CO_Peek = NULL;
void* hl2ss_api::p_MQX_CO_Pop = NULL;
void* hl2ss_api::p_MQX_CI_Push = NULL;
void* hl2ss_api::p_MQX_Restart = NULL;

int hl2ss_api::Load()
{
FString path_base = FPaths::ProjectPluginsDir() + L"hl2ss/Binaries/hl2ss/";
Expand Down Expand Up @@ -66,6 +76,11 @@ int hl2ss_api::Load()
p_MQ_SO_Push = GetProcAddress((HMODULE)hmod_hl2ss, "MQ_SO_Push");
p_MQ_Restart = GetProcAddress((HMODULE)hmod_hl2ss, "MQ_Restart");

p_MQX_CO_Peek = GetProcAddress((HMODULE)hmod_hl2ss, "MQX_CO_Peek");
p_MQX_CO_Pop = GetProcAddress((HMODULE)hmod_hl2ss, "MQX_CO_Pop");
p_MQX_CI_Push = GetProcAddress((HMODULE)hmod_hl2ss, "MQX_CI_Push");
p_MQX_Restart = GetProcAddress((HMODULE)hmod_hl2ss, "MQX_Restart");

if (p_InitializeStreams == NULL) { return -7; }
if (p_DebugMessage == NULL) { return -8; }
if (p_OverrideWorldCoordinateSystem == NULL) { return -9; }
Expand All @@ -76,6 +91,11 @@ int hl2ss_api::Load()
if (p_MQ_SO_Push == NULL) { return -13; }
if (p_MQ_Restart == NULL) { return -14; }

if (p_MQX_CO_Peek == NULL) { return -15; }
if (p_MQX_CO_Pop == NULL) { return -16; }
if (p_MQX_CI_Push == NULL) { return -17; }
if (p_MQX_Restart == NULL) { return -18; }

return 1;
}

Expand Down Expand Up @@ -133,3 +153,27 @@ void hl2ss_api::MQ_Restart()
if (p_MQ_Restart == NULL) { return; }
reinterpret_cast<pfn_MQ_Restart>(p_MQ_Restart)();
}

uint32_t hl2ss_api::MQX_CO_Peek()
{
if (p_MQX_CO_Peek == NULL) { return 0xFFFFFFFF; }
return reinterpret_cast<pfn_MQX_CO_Peek>(p_MQX_CO_Peek)();
}

void hl2ss_api::MQX_CO_Pop(uint32_t& id)
{
if (p_MQX_CO_Pop == NULL) { return; }
reinterpret_cast<pfn_MQX_CO_Pop>(p_MQX_CO_Pop)(id);
}

void hl2ss_api::MQX_CI_Push(uint32_t command, uint32_t size, uint8_t const* data)
{
if (p_MQX_CI_Push == NULL) { return; }
reinterpret_cast<pfn_MQX_CI_Push>(p_MQX_CI_Push)(command, size, data);
}

void hl2ss_api::MQX_Restart()
{
if (p_MQX_Restart == NULL) { return; }
reinterpret_cast<pfn_MQX_Restart>(p_MQX_Restart)();
}
10 changes: 10 additions & 0 deletions hl2ss_unreal/Plugins/hl2ss/Source/hl2ss/Public/hl2ss_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class HL2SS_API hl2ss_api
static void* p_MQ_SO_Push;
static void* p_MQ_Restart;

static void* p_MQX_CO_Peek;
static void* p_MQX_CO_Pop;
static void* p_MQX_CI_Push;
static void* p_MQX_Restart;

static int Load();

public:
Expand All @@ -41,6 +46,7 @@ class HL2SS_API hl2ss_api
ENABLE_EET = 512,
ENABLE_EA = 1024,
ENABLE_EV = 2048,
ENABLE_MQX = 4096,

ENABLE_ALL = 0xFFFFFFFF,
};
Expand All @@ -57,4 +63,8 @@ class HL2SS_API hl2ss_api
static void MQ_SI_Pop(uint32_t& command, uint8_t* data);
static void MQ_SO_Push(uint32_t id);
static void MQ_Restart();
static uint32_t MQX_CO_Peek();
static void MQX_CO_Pop(uint32_t& id);
static void MQX_CI_Push(uint32_t command, uint32_t size, uint8_t const* data);
static void MQX_Restart();
};
29 changes: 29 additions & 0 deletions hl2ss_unreal/Source/hl2ss_unreal/hl2ss_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ void Ahl2ss_loader::BeginPlay()
auto ip_address = FString(buffer);
hl2ss_api::DebugMessage(StringCast<ANSICHAR>(*ip_address).Get());

mqx_state = 0;
}

// Called every frame
void Ahl2ss_loader::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

ProcessClientMessage();
ProcessServerMessage();
}

void Ahl2ss_loader::ProcessClientMessage()
{
// Translate and process client messages

uint32_t size = hl2ss_api::MQ_SI_Peek();
Expand Down Expand Up @@ -67,3 +74,25 @@ void Ahl2ss_loader::Tick(float DeltaTime)
if (command == hl2ss_api::CLIENT_DISCONNECTED) { hl2ss_api::MQ_Restart(); }
}

void Ahl2ss_loader::ProcessServerMessage()
{
char const* text = "Hello from HoloLens 2!";
uint32_t status;
uint32_t response;

switch (mqx_state)
{
case 0:
hl2ss_api::MQX_CI_Push(0xFFFFFFFE, (uint32_t)strlen(text), (uint8_t*)text);
mqx_state = 1;
break;
case 1:
status = hl2ss_api::MQX_CO_Peek();
if (status == hl2ss_api::QUEUE_EMPTY) { break; }
hl2ss_api::MQX_CO_Pop(response);
if (response != hl2ss_api::CLIENT_DISCONNECTED) { break; }
hl2ss_api::MQX_Restart();
mqx_state = 0;
break;
}
}
5 changes: 5 additions & 0 deletions hl2ss_unreal/Source/hl2ss_unreal/hl2ss_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ class HL2SS_UNREAL_API Ahl2ss_loader : public AActor
{
GENERATED_BODY()

int mqx_state;

public:
// Sets default values for this actor's properties
Ahl2ss_loader();

void ProcessClientMessage();
void ProcessServerMessage();

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
Expand Down