Skip to content

Commit 43afcd5

Browse files
authored
VR Lua interface (scp-fs2open#5858)
* Allow lua to check whether VR is enabled * Add global hook condition * Add missing descriptionm
1 parent b98544d commit 43afcd5

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

code/scripting/api/libs/graphics.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <freespace.h>
2424
#include <globalincs/systemvars.h>
2525
#include <graphics/2d.h>
26+
#include <graphics/openxr.h>
2627
#include <graphics/material.h>
2728
#include <graphics/matrix.h>
2829
#include <hud/hudbrackets.h>
@@ -2269,5 +2270,10 @@ ADE_FUNC(createColor,
22692270
return ade_set_args(L, "o", l_Color.Set(thisColor));
22702271
}
22712272

2273+
ADE_FUNC(isVR, l_Graphics, nullptr, "Queries whether or not FSO is currently trying to render to a head-mounted VR display.", "boolean", "true if FSO is currently outputting frames to a VR headset.")
2274+
{
2275+
return ade_set_args(L, "b", openxr_enabled());
2276+
}
2277+
22722278
} // namespace api
22732279
} // namespace scripting

code/scripting/scripting.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "bmpman/bmpman.h"
1212
#include "controlconfig/controlsconfig.h"
1313
#include "gamesequence/gamesequence.h"
14+
#include "graphics/openxr.h"
1415
#include "hud/hud.h"
1516
#include "io/key.h"
1617
#include "mission/missioncampaign.h"
@@ -41,6 +42,7 @@ flag_def_list Script_conditions[] =
4142
{"Version", CHC_VERSION, 0},
4243
{"Application", CHC_APPLICATION, 0},
4344
{"Multi type", CHC_MULTI_SERVER, 0},
45+
{"VR device", CHC_VR_MODE, 0}
4446
};
4547

4648
int Num_script_conditions = sizeof(Script_conditions) / sizeof(flag_def_list);
@@ -263,6 +265,10 @@ static bool global_condition_valid(const script_condition& condition)
263265
return static_cast<bool>(condition.condition_cached_value == 1) == static_cast<bool>(MULTIPLAYER_MASTER);
264266
}
265267

268+
case CHC_VR_MODE: {
269+
return static_cast<bool>(condition.condition_cached_value == 1) == openxr_enabled();
270+
}
271+
266272
default:
267273
break;
268274
}
@@ -310,6 +316,17 @@ int cache_condition(ConditionalType type, const SCP_string& value){
310316
return 0;
311317
}
312318
}
319+
case CHC_VR_MODE:
320+
{
321+
if (stricmp("VR", value.c_str()) == 0 || stricmp("HMD", value.c_str()) == 0 || stricmp("enabled", value.c_str()) == 0)
322+
{
323+
return 1;
324+
}
325+
else
326+
{
327+
return 0;
328+
}
329+
}
313330
default:
314331
return -1;
315332
}

code/scripting/scripting.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ enum ConditionalType {
6262
CHC_KEYPRESS,
6363
CHC_VERSION,
6464
CHC_APPLICATION,
65-
CHC_MULTI_SERVER
65+
CHC_MULTI_SERVER,
66+
CHC_VR_MODE
6667
};
6768

6869
//Actions

0 commit comments

Comments
 (0)