Skip to content

Commit

Permalink
VR Lua interface (scp-fs2open#5858)
Browse files Browse the repository at this point in the history
* Allow lua to check whether VR is enabled

* Add global hook condition

* Add missing descriptionm
  • Loading branch information
BMagnu authored Dec 4, 2023
1 parent b98544d commit 43afcd5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions code/scripting/api/libs/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <freespace.h>
#include <globalincs/systemvars.h>
#include <graphics/2d.h>
#include <graphics/openxr.h>
#include <graphics/material.h>
#include <graphics/matrix.h>
#include <hud/hudbrackets.h>
Expand Down Expand Up @@ -2269,5 +2270,10 @@ ADE_FUNC(createColor,
return ade_set_args(L, "o", l_Color.Set(thisColor));
}

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.")
{
return ade_set_args(L, "b", openxr_enabled());
}

} // namespace api
} // namespace scripting
17 changes: 17 additions & 0 deletions code/scripting/scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "bmpman/bmpman.h"
#include "controlconfig/controlsconfig.h"
#include "gamesequence/gamesequence.h"
#include "graphics/openxr.h"
#include "hud/hud.h"
#include "io/key.h"
#include "mission/missioncampaign.h"
Expand Down Expand Up @@ -41,6 +42,7 @@ flag_def_list Script_conditions[] =
{"Version", CHC_VERSION, 0},
{"Application", CHC_APPLICATION, 0},
{"Multi type", CHC_MULTI_SERVER, 0},
{"VR device", CHC_VR_MODE, 0}
};

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

case CHC_VR_MODE: {
return static_cast<bool>(condition.condition_cached_value == 1) == openxr_enabled();
}

default:
break;
}
Expand Down Expand Up @@ -310,6 +316,17 @@ int cache_condition(ConditionalType type, const SCP_string& value){
return 0;
}
}
case CHC_VR_MODE:
{
if (stricmp("VR", value.c_str()) == 0 || stricmp("HMD", value.c_str()) == 0 || stricmp("enabled", value.c_str()) == 0)
{
return 1;
}
else
{
return 0;
}
}
default:
return -1;
}
Expand Down
3 changes: 2 additions & 1 deletion code/scripting/scripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ enum ConditionalType {
CHC_KEYPRESS,
CHC_VERSION,
CHC_APPLICATION,
CHC_MULTI_SERVER
CHC_MULTI_SERVER,
CHC_VR_MODE
};

//Actions
Expand Down

0 comments on commit 43afcd5

Please sign in to comment.