Integration of PCVR into the main repo

This commit is contained in:
Simon 2023-07-27 23:08:48 +01:00
parent 9411068172
commit f0eb5262eb
16 changed files with 2338 additions and 49 deletions

191
.gitignore vendored
View file

@ -69,3 +69,194 @@ gradlew.bat
JKXR.iml JKXR.iml
local.properties local.properties
local.properties local.properties
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
.vs
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
[Ff]inal/
[Ff]inal[Bb]uild/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
*.dotCover
winquake.res
## TODO: If you have NuGet Package Restore enabled, uncomment this
#packages/
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
# Visual Studio profiler
*.psess
*.vsp
# ReSharper is a .NET coding add-in
_ReSharper*
# Installshield output folder
[Ee]xpress
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish
# Others
[Bb]in
[Oo]bj
sql
TestResults
*.Cache
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
# Visual Studio Code
.vscode
############
## Windows
############
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist
build
build64
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
# Mac crap
.DS_Store
#############
## Unix
#############
*.o
*.so
#############
## clangd
#############
.clangd
#############
## CLion
#############
.idea

View file

@ -123,12 +123,12 @@ JK3_SRC = \
${SHARED_PATH}/qcommon/safe/string.cpp \ ${SHARED_PATH}/qcommon/safe/string.cpp \
JKXR_SRC_FILES := ${OPENJK_PATH}/JKXR/JKXR_SurfaceView.cpp \ JKXR_SRC_FILES := ${OPENJK_PATH}/JKXR/android/JKXR_SurfaceView.cpp \
${OPENJK_PATH}/JKXR/TBXR_Common.cpp \ ${OPENJK_PATH}/JKXR/android/TBXR_Common.cpp \
${OPENJK_PATH}/JKXR/android/argtable3.c \
${OPENJK_PATH}/JKXR/VrInputCommon.cpp \ ${OPENJK_PATH}/JKXR/VrInputCommon.cpp \
${OPENJK_PATH}/JKXR/VrInputDefault.cpp \ ${OPENJK_PATH}/JKXR/VrInputDefault.cpp \
${OPENJK_PATH}/JKXR/VrInputWeaponAlign.cpp \ ${OPENJK_PATH}/JKXR/VrInputWeaponAlign.cpp \
${OPENJK_PATH}/JKXR/argtable3.c \
${OPENJK_PATH}/JKXR/OpenXrInput.cpp ${OPENJK_PATH}/JKXR/OpenXrInput.cpp
LOCAL_SRC_FILES += $(JK3_SRC) $(JKXR_SRC_FILES) LOCAL_SRC_FILES += $(JK3_SRC) $(JKXR_SRC_FILES)

View file

@ -123,12 +123,12 @@ JK3_SRC = \
${SHARED_PATH}/qcommon/safe/string.cpp \ ${SHARED_PATH}/qcommon/safe/string.cpp \
JKXR_SRC_FILES := ${OPENJK_PATH}/JKXR/JKXR_SurfaceView.cpp \ JKXR_SRC_FILES := ${OPENJK_PATH}/JKXR/android/JKXR_SurfaceView.cpp \
${OPENJK_PATH}/JKXR/TBXR_Common.cpp \ ${OPENJK_PATH}/JKXR/android/TBXR_Common.cpp \
${OPENJK_PATH}/JKXR/android/argtable3.c \
${OPENJK_PATH}/JKXR/VrInputCommon.cpp \ ${OPENJK_PATH}/JKXR/VrInputCommon.cpp \
${OPENJK_PATH}/JKXR/VrInputDefault.cpp \ ${OPENJK_PATH}/JKXR/VrInputDefault.cpp \
${OPENJK_PATH}/JKXR/VrInputWeaponAlign.cpp \ ${OPENJK_PATH}/JKXR/VrInputWeaponAlign.cpp \
${OPENJK_PATH}/JKXR/argtable3.c \
${OPENJK_PATH}/JKXR/OpenXrInput.cpp ${OPENJK_PATH}/JKXR/OpenXrInput.cpp
LOCAL_SRC_FILES += $(JK3_SRC) $(JKXR_SRC_FILES) LOCAL_SRC_FILES += $(JK3_SRC) $(JKXR_SRC_FILES)

View file

@ -6,7 +6,11 @@
#include "VrClientInfo.h" #include "VrClientInfo.h"
#include "TBXR_Common.h" #ifdef _WIN32
#include "windows/TBXR_Common.h"
#else
#include "android/TBXR_Common.h"
#endif
extern long long global_time; extern long long global_time;

View file

@ -131,7 +131,19 @@ void sendButtonAction(const char* action, long buttonDown)
Cbuf_AddText( command ); Cbuf_AddText( command );
} }
#ifndef _WIN32
void PortableMouseAbs(float x,float y); void PortableMouseAbs(float x,float y);
#else
void PortableMouseAbs(float x, float y)
{
int absx = 0, absy = 0;
absx = x * 640;
absy = y * 480;
CL_MouseEvent(absx, absy, 0);
}
#endif
float clamp(float _min, float _val, float _max) float clamp(float _min, float _val, float _max)
{ {
return fmax(fmin(_val, _max), _min); return fmax(fmin(_val, _max), _min);

View file

@ -7,28 +7,28 @@ Authors : Simon Brown
*************************************************************************************/ *************************************************************************************/
#include <android/keycodes.h>
#include "VrInput.h" #include "VrInput.h"
#include "VrCvars.h" #include "VrCvars.h"
#include "qcommon/q_shared.h" #include "qcommon/q_shared.h"
#include <qcommon/qcommon.h> #include <qcommon/qcommon.h>
#include <client/client.h> #include <client/client.h>
#ifndef _WIN32
#include <android/keycodes.h>
#include <statindex.h> #include <statindex.h>
#include "android/sys_local.h" #include "android/sys_local.h"
#endif
#include "VrTBDC.h" #include "VrTBDC.h"
#ifdef JK2_MODE #include "game/weapons.h"
#include "../OpenJK/codeJK2/game/weapons.h" #include "game/bg_public.h"
#include "../OpenJK/codeJK2/game/bg_public.h" #include "game/wp_saber.h"
#include "../OpenJK/codeJK2/game/wp_saber.h" #include "game/g_vehicles.h"
#else
#include "../OpenJK/code/game/weapons.h" void Sys_QueEvent(int time, sysEventType_t type, int value, int value2, int ptrLength, void* ptr);
#include "../OpenJK/codeJK2/game/bg_public.h"
#include "../OpenJK/code/game/wp_saber.h"
#include "../OpenJK/code/game/g_vehicles.h"
#endif
void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTrackedController* pDominantTracking, void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTrackedController* pDominantTracking,
ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTrackedController* pOffTracking, ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTrackedController* pOffTracking,
@ -58,6 +58,8 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
int secondaryButton1; int secondaryButton1;
bool secondaryButton2New; bool secondaryButton2New;
bool secondaryButton2Old; bool secondaryButton2Old;
bool secondaryButton1New;
bool secondaryButton1Old;
int primaryThumb; int primaryThumb;
int secondaryThumb; int secondaryThumb;
if (vr_control_scheme->integer == LEFT_HANDED_DEFAULT && vr_switch_sticks->integer) if (vr_control_scheme->integer == LEFT_HANDED_DEFAULT && vr_switch_sticks->integer)
@ -107,6 +109,8 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
primaryButton2Old = domButton2 & pDominantTrackedRemoteOld->Buttons; primaryButton2Old = domButton2 & pDominantTrackedRemoteOld->Buttons;
secondaryButton2New = offButton2 & pOffTrackedRemoteNew->Buttons; secondaryButton2New = offButton2 & pOffTrackedRemoteNew->Buttons;
secondaryButton2Old = offButton2 & pOffTrackedRemoteOld->Buttons; secondaryButton2Old = offButton2 & pOffTrackedRemoteOld->Buttons;
secondaryButton1New = offButton1 & pOffTrackedRemoteNew->Buttons;
secondaryButton1Old = offButton1 & pOffTrackedRemoteOld->Buttons;
//Allow weapon alignment mode toggle on x //Allow weapon alignment mode toggle on x
if (vr_align_weapons->value) if (vr_align_weapons->value)
@ -232,6 +236,11 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
Sys_QueEvent(0, SE_KEY, A_TAB, true, 0, NULL); Sys_QueEvent(0, SE_KEY, A_TAB, true, 0, NULL);
} }
//Close the menu
if (secondaryButton1New && !secondaryButton1Old) {
Sys_QueEvent(0, SE_KEY, A_ESCAPE, true, 0, NULL);
}
} }
else else
{ {
@ -436,8 +445,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
int mode = (int) Cvar_VariableValue("cg_thirdPerson"); int mode = (int) Cvar_VariableValue("cg_thirdPerson");
static bool switched = false; static bool switched = false;
if (between(-0.2f, primaryJoystickX, 0.2f) && if (between(-0.2f, primaryJoystickX, 0.2f) &&
(between(0.8f, pPrimaryJoystick->y, 1.0f) || between(-1.0f, pPrimaryJoystick->y, -0.8f)) {
between(-1.0f, pPrimaryJoystick->y, -0.8f))) {
if (!switched) { if (!switched) {
mode = 1 - mode; mode = 1 - mode;
sendButtonActionSimple(va("cg_thirdPerson %i", mode)); sendButtonActionSimple(va("cg_thirdPerson %i", mode));
@ -463,6 +471,21 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
} }
} }
//Switch movement speed
{
static bool switched = false;
if (between(-0.2f, primaryJoystickX, 0.2f) &&
between(0.8f, pPrimaryJoystick->y, 1.0f)) {
if (!switched) {
vr.move_speed = (++vr.move_speed) % 3;
switched = true;
}
}
else {
switched = false;
}
}
/* /*
//Parameter Changer //Parameter Changer
static bool changed = false; static bool changed = false;
@ -715,7 +738,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
//Positional movement speed correction for when we are not hitting target framerate //Positional movement speed correction for when we are not hitting target framerate
static double lastframetime = 0; static double lastframetime = 0;
int refresh = TBXR_GetRefresh(); int refresh = TBXR_GetRefresh();
double newframetime = TBXR_GetTimeInMilliSeconds(); double newframetime = Sys_Milliseconds();
float multiplier = (float) ((1000.0 / refresh) / (newframetime - lastframetime)); float multiplier = (float) ((1000.0 / refresh) / (newframetime - lastframetime));
lastframetime = newframetime; lastframetime = newframetime;
@ -728,11 +751,6 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
positional_movementSideways = v[0]; positional_movementSideways = v[0];
positional_movementForward = v[1]; positional_movementForward = v[1];
ALOGV(" positional_movementSideways: %f, positional_movementForward: %f",
positional_movementSideways,
positional_movementForward);
//Jump (A Button) //Jump (A Button)
if ((primaryButtonsNew & primaryButton1) != (primaryButtonsOld & primaryButton1)) { if ((primaryButtonsNew & primaryButton1) != (primaryButtonsOld & primaryButton1)) {
sendButtonAction("+moveup", (primaryButtonsNew & primaryButton1)); sendButtonAction("+moveup", (primaryButtonsNew & primaryButton1));
@ -854,16 +872,13 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
v[0] * (vr.move_speed == 0 ? 0.75f : (vr.move_speed == 1 ? 1.0f : 0.5f)); v[0] * (vr.move_speed == 0 ? 0.75f : (vr.move_speed == 1 ? 1.0f : 0.5f));
remote_movementForward = remote_movementForward =
v[1] * (vr.move_speed == 0 ? 0.75f : (vr.move_speed == 1 ? 1.0f : 0.5f)); v[1] * (vr.move_speed == 0 ? 0.75f : (vr.move_speed == 1 ? 1.0f : 0.5f));
ALOGV(" remote_movementSideways: %f, remote_movementForward: %f",
remote_movementSideways,
remote_movementForward);
if (((secondaryButtonsNew & secondaryButton1) != //X button invokes menu now
(secondaryButtonsOld & secondaryButton1)) && if ((secondaryButtonsNew & secondaryButton1) &&
(secondaryButtonsNew & secondaryButton1)) { !(secondaryButtonsOld & secondaryButton1))
//Toggle walk/run somehow?! {
vr.move_speed = (++vr.move_speed) % 3; Sys_QueEvent(0, SE_KEY, A_ESCAPE, true, 0, NULL);
} }
//Open the datapad //Open the datapad

View file

@ -7,8 +7,6 @@ Authors : Simon Brown
*************************************************************************************/ *************************************************************************************/
#include <android/keycodes.h>
#include "VrInput.h" #include "VrInput.h"
#include "VrCvars.h" #include "VrCvars.h"

View file

@ -320,6 +320,7 @@ void VR_Init()
positional_movementForward = 0.0f; positional_movementForward = 0.0f;
vr.snapTurn = 0.0f; vr.snapTurn = 0.0f;
vr.immersive_cinematics = true; vr.immersive_cinematics = true;
vr.move_speed = 1; // Default to full speed now
//init randomiser //init randomiser
srand(time(NULL)); srand(time(NULL));

View file

@ -1654,7 +1654,7 @@ void TBXR_InitialiseOpenXR()
instanceInfo.next = NULL; instanceInfo.next = NULL;
OXR(xrGetInstanceProperties(gAppState.Instance, &instanceInfo)); OXR(xrGetInstanceProperties(gAppState.Instance, &instanceInfo));
ALOGV( ALOGV(
"Runtime %s: Version : %u.%u.%u", "OpenXR Runtime %s: Version : %u.%u.%u",
instanceInfo.runtimeName, instanceInfo.runtimeName,
XR_VERSION_MAJOR(instanceInfo.runtimeVersion), XR_VERSION_MAJOR(instanceInfo.runtimeVersion),
XR_VERSION_MINOR(instanceInfo.runtimeVersion), XR_VERSION_MINOR(instanceInfo.runtimeVersion),
@ -1894,11 +1894,11 @@ void TBXR_finishEyeBuffer(int eye )
void TBXR_updateProjections() void TBXR_updateProjections()
{ {
XrViewLocateInfo projectionInfo = {}; XrViewLocateInfo viewLocateInfo = {};
projectionInfo.type = XR_TYPE_VIEW_LOCATE_INFO; viewLocateInfo.type = XR_TYPE_VIEW_LOCATE_INFO;
projectionInfo.viewConfigurationType = gAppState.ViewportConfig.viewConfigurationType; viewLocateInfo.viewConfigurationType = gAppState.ViewportConfig.viewConfigurationType;
projectionInfo.displayTime = gAppState.FrameState.predictedDisplayTime; viewLocateInfo.displayTime = gAppState.FrameState.predictedDisplayTime;
projectionInfo.space = gAppState.LocalSpace; viewLocateInfo.space = gAppState.LocalSpace;
XrViewState viewState = {XR_TYPE_VIEW_STATE, NULL}; XrViewState viewState = {XR_TYPE_VIEW_STATE, NULL};
@ -1907,7 +1907,7 @@ void TBXR_updateProjections()
OXR(xrLocateViews( OXR(xrLocateViews(
gAppState.Session, gAppState.Session,
&projectionInfo, &viewLocateInfo,
&viewState, &viewState,
projectionCapacityInput, projectionCapacityInput,
&projectionCountOutput, &projectionCountOutput,

View file

@ -0,0 +1,487 @@
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <time.h>
#include "VrInput.h"
#include "VrCvars.h"
#include <client/client.h>
#include <client/client_ui.h>
#ifdef JK2_MODE
#include "game/weapons.h"
#else
#include "game/weapons.h"
#include "game/g_vehicles.h"
#endif
/*
================================================================================
JKXR Stuff
================================================================================
*/
bool VR_UseScreenLayer()
{
vr.using_screen_layer = _UI_IsFullscreen() ||
(bool)((vr.cin_camera && !vr.immersive_cinematics) ||
vr.misc_camera ||
(CL_IsRunningInGameCinematic() || CL_InGameCinematicOnStandBy()) ||
(cls.state == CA_CINEMATIC) ||
(cls.state == CA_LOADING) ||
( Key_GetCatcher( ) & KEYCATCH_UI ) ||
( Key_GetCatcher( ) & KEYCATCH_CONSOLE ));
return vr.using_screen_layer;
}
float VR_GetScreenLayerDistance()
{
return (2.0f + vr_screen_dist->value);
}
void VR_SetHMDOrientation(float pitch, float yaw, float roll)
{
//Orientation
VectorSet(vr.hmdorientation, pitch, yaw, roll);
VectorSubtract(vr.hmdorientation_last, vr.hmdorientation, vr.hmdorientation_delta);
//Keep this for our records
VectorCopy(vr.hmdorientation, vr.hmdorientation_last);
if (!vr.third_person && !vr.remote_npc && !vr.remote_turret
#ifndef JK2_MODE
&& !vr.in_vehicle
#endif
)
{
VectorCopy(vr.hmdorientation, vr.hmdorientation_first);
}
if (!vr.remote_turret)
{
VectorCopy(vr.weaponangles[ANGLES_ADJUSTED], vr.weaponangles_first[ANGLES_ADJUSTED]);
}
// View yaw delta
float clientview_yaw = vr.clientviewangles[YAW] - vr.hmdorientation[YAW];
vr.clientview_yaw_delta = vr.clientview_yaw_last - clientview_yaw;
vr.clientview_yaw_last = clientview_yaw;
// Max-height is set only once on start, or after re-calibration
// (ignore too low value which is sometimes provided on start)
if (!vr.maxHeight || vr.maxHeight < 1.0) {
vr.maxHeight = vr.hmdposition[1];
}
//GB Instantiate initial velocity
if(!vr.tempWeaponVelocity)
{
vr.tempWeaponVelocity = 400.0f;
}
vr.curHeight = vr.hmdposition[1];
}
void VR_SetHMDPosition(float x, float y, float z )
{
static bool s_useScreen = qfalse;
VectorSet(vr.hmdposition, x, y, z);
//Can be set elsewhere
vr.take_snap |= s_useScreen != VR_UseScreenLayer();
if (vr.take_snap)
{
s_useScreen = VR_UseScreenLayer();
//Record player position on transition
VectorSet(vr.hmdposition_snap, x, y, z);
VectorCopy(vr.hmdorientation, vr.hmdorientation_snap);
if (vr.cin_camera)
{
//Reset snap turn too if in a cinematic
vr.snapTurn = 0;
}
vr.take_snap = false;
}
VectorSubtract(vr.hmdposition, vr.hmdposition_snap, vr.hmdposition_offset);
//Position
VectorSubtract(vr.hmdposition_last, vr.hmdposition, vr.hmdposition_delta);
//Keep this for our records
VectorCopy(vr.hmdposition, vr.hmdposition_last);
}
void VR_GetMove(float *forward, float *side, float *pos_forward, float *pos_side, float *up,
float *yaw, float *pitch, float *roll)
{
if (vr.remote_turret) {
*forward = 0.0f;
*pos_forward = 0.0f;
*up = 0.0f;
*side = 0.0f;
*pos_side = 0.0f;
*yaw = vr.snapTurn + vr.hmdorientation_first[YAW] +
vr.weaponangles[ANGLES_ADJUSTED][YAW] - vr.weaponangles_first[ANGLES_ADJUSTED][YAW];
*pitch = vr.weaponangles[ANGLES_ADJUSTED][PITCH];
*roll = 0.0f;
}
else if (vr.cgzoommode == 2 || vr.cgzoommode == 4)
{
*forward = 0.0f;
*pos_forward = 0.0f;
*up = 0.0f;
*side = 0.0f;
*pos_side = 0.0f;
*yaw = vr.snapTurn;
*pitch = vr.weaponangles[ANGLES_ADJUSTED][PITCH];
*roll = 0.0f;//vr.hmdorientation[ROLL];
}
else if (vr.remote_npc) {
*forward = remote_movementForward;
*pos_forward = 0.0f;
*up = 0.0f;
*side = remote_movementSideways;
*pos_side = 0.0f;
*yaw = vr.hmdorientation[YAW] + vr.snapTurn;
*pitch = vr.hmdorientation[PITCH];
*roll = 0.0f;
}
#ifndef JK2_MODE
//Special code for JKA's vehicles
else if (vr.in_vehicle) {
//in vehicle
*forward = remote_movementForward;
*pos_forward = 0.0f;
*up = 0.0f;
*side = remote_movementSideways;
*pos_side = 0.0f;
if (vr_vehicle_use_hmd_direction->integer)
{
*yaw = vr.hmdorientation[YAW] + vr.snapTurn;
*pitch = vr.hmdorientation[PITCH];
}
else
{
*yaw = vr.snapTurn + vr.hmdorientation_first[YAW];
if (vr.vehicle_type == VH_FIGHTER || vr.vehicle_type == VH_FLIER)
{
*pitch = (vr.weaponangles[ANGLES_ADJUSTED][PITCH] + vr.offhandangles[ANGLES_ADJUSTED][PITCH]) / 2.0f;
}
else
{
*pitch = 0.0f;
}
}
*roll = 0.0f;
}
#endif
else if (!vr.third_person) {
*forward = remote_movementForward;
*pos_forward = positional_movementForward;
*up = remote_movementUp;
*side = remote_movementSideways;
*pos_side = positional_movementSideways;
*yaw = vr.hmdorientation[YAW] + vr.snapTurn;
*pitch = vr.hmdorientation[PITCH];
*roll = 0.0f;//vr.hmdorientation[ROLL];
} else {
//in third person just send the bare minimum
*forward = remote_movementForward;
*pos_forward = 0.0f;
*up = 0.0f;
*side = remote_movementSideways;
*pos_side = 0.0f;
*yaw = vr.snapTurn + vr.hmdorientation_first[YAW];
*pitch = 0.0f;
*roll = 0.0f;
}
}
void VR_Init()
{
GlInitExtensions();
//First - all the OpenXR stuff and nonsense
TBXR_InitialiseOpenXR();
TBXR_EnterVR();
TBXR_InitRenderer();
TBXR_InitActions();
TBXR_WaitForSessionActive();
//Initialise all our variables
remote_movementSideways = 0.0f;
remote_movementForward = 0.0f;
remote_movementUp = 0.0f;
positional_movementSideways = 0.0f;
positional_movementForward = 0.0f;
vr.snapTurn = 0.0f;
vr.immersive_cinematics = true;
vr.move_speed = 1; // Default to full speed now
//init randomiser
srand(time(NULL));
//Create Cvars
vr_turn_mode = Cvar_Get( "vr_turn_mode", "0", CVAR_ARCHIVE); // 0 = snap, 1 = smooth (3rd person only), 2 = smooth (all modes)
vr_turn_angle = Cvar_Get( "vr_turn_angle", "45", CVAR_ARCHIVE);
vr_positional_factor = Cvar_Get( "vr_positional_factor", "12", CVAR_ARCHIVE);
vr_walkdirection = Cvar_Get( "vr_walkdirection", "1", CVAR_ARCHIVE);
vr_weapon_pitchadjust = Cvar_Get( "vr_weapon_pitchadjust", "-20.0", CVAR_ARCHIVE);
vr_virtual_stock = Cvar_Get( "vr_virtual_stock", "0", CVAR_ARCHIVE);
//Defaults
vr_control_scheme = Cvar_Get( "vr_control_scheme", "0", CVAR_ARCHIVE);
vr_switch_sticks = Cvar_Get( "vr_switch_sticks", "0", CVAR_ARCHIVE);
vr_immersive_cinematics = Cvar_Get("vr_immersive_cinematics", "1", CVAR_ARCHIVE);
vr_screen_dist = Cvar_Get( "vr_screen_dist", "3.5", CVAR_ARCHIVE);
vr_weapon_velocity_trigger = Cvar_Get( "vr_weapon_velocity_trigger", "2.0", CVAR_ARCHIVE);
vr_force_velocity_trigger = Cvar_Get( "vr_force_velocity_trigger", "2.09", CVAR_ARCHIVE);
vr_force_distance_trigger = Cvar_Get( "vr_force_distance_trigger", "0.15", CVAR_ARCHIVE);
vr_two_handed_weapons = Cvar_Get ("vr_two_handed_weapons", "1", CVAR_ARCHIVE);
vr_force_motion_controlled = Cvar_Get ("vr_force_motion_controlled", "1", CVAR_ARCHIVE);
vr_force_motion_push = Cvar_Get ("vr_force_motion_push", "3", CVAR_ARCHIVE);
vr_force_motion_pull = Cvar_Get ("vr_force_motion_pull", "4", CVAR_ARCHIVE);
vr_motion_enable_saber = Cvar_Get ("vr_motion_enable_saber", "0", CVAR_ARCHIVE);
vr_crouch_toggle = Cvar_Get ("vr_crouch_toggle", "0", CVAR_ARCHIVE);
vr_irl_crouch_enabled = Cvar_Get ("vr_irl_crouch_enabled", "0", CVAR_ARCHIVE);
vr_irl_crouch_to_stand_ratio = Cvar_Get ("vr_irl_crouch_to_stand_ratio", "0.65", CVAR_ARCHIVE);
vr_saber_block_debounce_time = Cvar_Get ("vr_saber_block_debounce_time", "200", CVAR_ARCHIVE);
vr_haptic_intensity = Cvar_Get ("vr_haptic_intensity", "1.0", CVAR_ARCHIVE);
vr_comfort_vignette = Cvar_Get ("vr_comfort_vignette", "0.0", CVAR_ARCHIVE);
vr_saber_3rdperson_mode = Cvar_Get ("vr_saber_3rdperson_mode", "1", CVAR_ARCHIVE);
vr_vehicle_use_hmd_direction = Cvar_Get ("vr_vehicle_use_hmd_direction", "0", CVAR_ARCHIVE);
vr_vehicle_use_3rd_person = Cvar_Get ("vr_vehicle_use_3rd_person", "0", CVAR_ARCHIVE);
vr_vehicle_use_controller_for_speed = Cvar_Get ("vr_vehicle_use_controller_for_speed", "1", CVAR_ARCHIVE);
vr_gesture_triggered_use = Cvar_Get ("vr_gesture_triggered_use", "1", CVAR_ARCHIVE);
vr_use_gesture_boundary = Cvar_Get ("vr_use_gesture_boundary", "0.35", CVAR_ARCHIVE);
vr_align_weapons = Cvar_Get ("vr_align_weapons", "0", CVAR_ARCHIVE);
vr_refresh = Cvar_Get ("vr_refresh", "72", CVAR_ARCHIVE);
cvar_t *expanded_menu_enabled = Cvar_Get ("expanded_menu_enabled", "0", CVAR_ARCHIVE);
if (FS_FileExists("expanded_menu.pk3") || FS_BaseFileExists("expanded_menu.pk3")) {
Cvar_Set( "expanded_menu_enabled", "1" );
} else {
Cvar_Set( "expanded_menu_enabled", "0" );
}
vr.menu_right_handed = vr_control_scheme->integer == 0;
Cvar_Get ("openXRHMD", gAppState.OpenXRHMD, CVAR_ARCHIVE);
}
int VR_SetRefreshRate(int refreshRate)
{
// if (strstr(gAppState.OpenXRHMD, "meta") != NULL)
// {
// OXR(gAppState.pfnRequestDisplayRefreshRate(gAppState.Session, (float) refreshRate));
// return refreshRate;
// }
return 0;
}
//All the stuff we want to do each frame specifically for this game
void VR_FrameSetup()
{
static float refresh = 0;
if (refresh != vr_refresh->value)
{
refresh = vr_refresh->value;
VR_SetRefreshRate(vr_refresh->value);
}
//get any cvar values required here
vr.immersive_cinematics = (vr_immersive_cinematics->value != 0.0f);
}
bool VR_GetVRProjection(int eye, float zNear, float zFar, float zZoomX, float zZoomY, float* projection)
{
//Don't use our projection if playing a cinematic and we are not immersive
if (vr.cin_camera && !vr.immersive_cinematics)
{
return false;
}
//Just use game-calculated FOV when showing the quad screen
if (vr.using_screen_layer)
{
return false;
}
XrFovf fov = gAppState.Views[eye].fov;
fov.angleLeft /= zZoomX;
fov.angleRight /= zZoomX;
fov.angleUp /= zZoomY;
fov.angleDown /= zZoomY;
XrMatrix4x4f_CreateProjectionFov(
(XrMatrix4x4f*)projection, GRAPHICS_OPENGL,
fov, zNear, zFar);
return true;
}
void VR_ExternalHapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight )
{
}
void VR_HapticUpdateEvent(const char* event, int intensity, float angle )
{
}
void VR_HapticEndFrame()
{
}
void VR_HapticStopEvent(const char* event)
{
}
void VR_HapticEnable()
{
}
void VR_HapticDisable()
{
}
/*
* event - name of event
* position - for the use of external haptics providers to indicate which bit of haptic hardware should be triggered
* flags - a way for the code to specify which controller to produce haptics on, if 0 then weaponFireChannel is calculated in this function
* intensity - 0-100
* angle - yaw angle (again for external haptics devices) to place the feedback correctly
* yHeight - for external haptics devices to place the feedback correctly
*/
void VR_HapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight )
{
if (vr_haptic_intensity->value == 0.0f)
{
return;
}
//Pass on to any external services
VR_ExternalHapticEvent(event, position, flags, intensity, angle, yHeight);
float fIntensity = intensity / 100.0f;
//Controller Haptic Support
int weaponFireChannel = vr.weapon_stabilised ? 3 : (vr_control_scheme->integer ? 2 : 1);
if (flags != 0)
{
weaponFireChannel = flags;
}
if (strcmp(event, "pickup_shield") == 0 ||
strcmp(event, "pickup_weapon") == 0 ||
strstr(event, "pickup_item") != NULL)
{
TBXR_Vibrate(100, 3, 1.0);
}
else if (strcmp(event, "weapon_switch") == 0)
{
TBXR_Vibrate(250, vr_control_scheme->integer ? 2 : 1, 0.8);
}
else if (strcmp(event, "shotgun") == 0 || strcmp(event, "fireball") == 0)
{
TBXR_Vibrate(400, 3, fIntensity);
}
else if (strcmp(event, "bullet") == 0)
{
TBXR_Vibrate(150, 3, fIntensity);
}
else if (strcmp(event, "chainsaw_fire") == 0) // Saber
{
//Special handling for dual sabers / melee
if (vr.dualsabers || cl.frame.ps.weapon == WP_MELEE)
{
if (position == 4 ||
position == 0) // both hands
{
weaponFireChannel = 3;
}
else if (position == 1) // left hand
{
weaponFireChannel = 2;
}
else if (position == 2) // right hand
{
weaponFireChannel = 1;
}
else
{
//no longer need to trigger haptic
return;
}
}
TBXR_Vibrate(300, weaponFireChannel, fIntensity);
}
else if (strcmp(event, "RTCWQuest:fire_tesla") == 0) // Weapon power build up
{
TBXR_Vibrate(500, weaponFireChannel, fIntensity);
}
else if (strcmp(event, "machinegun_fire") == 0 || strcmp(event, "plasmagun_fire") == 0)
{
TBXR_Vibrate(90, weaponFireChannel, fIntensity);
}
else if (strcmp(event, "shotgun_fire") == 0)
{
TBXR_Vibrate(250, weaponFireChannel, fIntensity);
}
else if (strcmp(event, "rocket_fire") == 0 ||
strcmp(event, "RTCWQuest:fire_sniper") == 0 ||
strcmp(event, "bfg_fire") == 0 ||
strcmp(event, "handgrenade_fire") == 0 )
{
TBXR_Vibrate(400, weaponFireChannel, fIntensity);
}
else if (strcmp(event, "selector_icon") == 0 ||
strcmp(event, "use_button") == 0 )
{
//Quick blip
TBXR_Vibrate(50, flags, fIntensity);
}
}
void VR_HandleControllerInput() {
TBXR_UpdateControllers();
//Call additional control schemes here
switch (vr_control_scheme->integer)
{
case RIGHT_HANDED_DEFAULT:
HandleInput_Default(&rightTrackedRemoteState_new, &rightTrackedRemoteState_old, &rightRemoteTracking_new,
&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, &leftRemoteTracking_new,
xrButton_A, xrButton_B, xrButton_X, xrButton_Y);
break;
case LEFT_HANDED_DEFAULT:
HandleInput_Default(&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, &leftRemoteTracking_new,
&rightTrackedRemoteState_new, &rightTrackedRemoteState_old, &rightRemoteTracking_new,
xrButton_X, xrButton_Y, xrButton_A, xrButton_B);
break;
case WEAPON_ALIGN:
HandleInput_WeaponAlign(&rightTrackedRemoteState_new, &rightTrackedRemoteState_old, &rightRemoteTracking_new,
&leftTrackedRemoteState_new, &leftTrackedRemoteState_old, &leftRemoteTracking_new,
xrButton_A, xrButton_B, xrButton_X, xrButton_Y);
break;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,271 @@
#if !defined(tbxr_common_h)
#define tbxr_common_h
#if defined(_WIN32)
// OpenXR Header
#include <Unknwn.h>
#include <openxr.h>
#include <openxr_platform.h>
#include <openxr_helpers.h>
#include <GL/gl.h>
//#define GL_GLEXT_PROTOTYPES
#define GL_EXT_color_subtable
#include <GL/glext.h>
#include <GL/wglext.h>
extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
extern PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer;
extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
extern PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
extern PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
extern PFNGLISRENDERBUFFERPROC glIsRenderbuffer;
extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
extern PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample;
extern PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC glRenderbufferStorageMultisampleEXT;
extern PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
extern PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer;
extern PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC glFramebufferTextureMultiviewOVR;
extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
extern PFNGLCHECKNAMEDFRAMEBUFFERSTATUSPROC glCheckNamedFramebufferStatus;
void GlInitExtensions();
#define GL_RGBA16F 0x881A
#endif
#ifndef NDEBUG
#define DEBUG 1
#endif
#define LOG_TAG "TBXR"
#define ALOGE(...) Com_Printf(__VA_ARGS__)
#if DEBUG
#define ALOGV(...) Com_Printf(__VA_ARGS__)
#else
#define ALOGV(...)
#endif
enum { ovrMaxLayerCount = 3 };
enum { ovrMaxNumEyes = 2 };
typedef enum xrButton_ {
xrButton_A = 0x00000001, // Set for trigger pulled on the Gear VR and Go Controllers
xrButton_B = 0x00000002,
xrButton_RThumb = 0x00000004,
xrButton_RShoulder = 0x00000008,
xrButton_X = 0x00000100,
xrButton_Y = 0x00000200,
xrButton_LThumb = 0x00000400,
xrButton_LShoulder = 0x00000800,
xrButton_Up = 0x00010000,
xrButton_Down = 0x00020000,
xrButton_Left = 0x00040000,
xrButton_Right = 0x00080000,
xrButton_Enter = 0x00100000,
xrButton_Back = 0x00200000,
xrButton_GripTrigger = 0x04000000,
xrButton_Trigger = 0x20000000,
xrButton_Joystick = 0x80000000,
//Define additional controller touch points (not button presses)
xrButton_ThumbRest = 0x00000010,
xrButton_EnumSize = 0x7fffffff
} xrButton;
typedef struct {
uint32_t Buttons;
uint32_t Touches;
float IndexTrigger;
float GripTrigger;
XrVector2f Joystick;
} ovrInputStateTrackedRemote;
typedef struct {
GLboolean Active;
XrPosef Pose;
XrSpaceVelocity Velocity;
} ovrTrackedController;
typedef enum control_scheme {
RIGHT_HANDED_DEFAULT = 0,
LEFT_HANDED_DEFAULT = 10,
WEAPON_ALIGN = 99
} control_scheme_t;
typedef struct {
float M[4][4];
} ovrMatrix4f;
typedef struct {
XrSwapchain Handle;
uint32_t Width;
uint32_t Height;
} ovrSwapChain;
typedef struct {
int Width;
int Height;
uint32_t TextureSwapChainLength;
uint32_t TextureSwapChainIndex;
ovrSwapChain ColorSwapChain;
XrSwapchainImageOpenGLKHR* ColorSwapChainImage;
GLuint* DepthBuffers;
GLuint* FrameBuffers;
} ovrFramebuffer;
/*
================================================================================
ovrRenderer
================================================================================
*/
typedef struct
{
ovrFramebuffer FrameBuffer[ovrMaxNumEyes];
ovrFramebuffer NullFrameBuffer; // Used to draw black projection view when showing quad layer
} ovrRenderer;
#define GL(func) func;
// Forward declarations
XrInstance TBXR_GetXrInstance();
#if defined(DEBUG)
static void
OXR_CheckErrors(XrInstance instance, XrResult result, const char* function, bool failOnError) {
if (XR_FAILED(result)) {
char errorBuffer[XR_MAX_RESULT_STRING_SIZE];
xrResultToString(instance, result, errorBuffer);
if (failOnError) {
//ALOGE("OpenXR error: %s: %s\n", function, errorBuffer);
} else {
//ALOGV("OpenXR error: %s: %s\n", function, errorBuffer);
}
}
}
#endif
#if defined(DEBUG)
#define OXR(func) OXR_CheckErrors(TBXR_GetXrInstance(), func, #func, true);
#else
#define OXR(func) func;
#endif
typedef struct
{
bool Initialised;
bool Resumed;
bool Focused;
bool FrameSetup;
char* OpenXRHMD;
float Width;
float Height;
XrInstance Instance;
XrSession Session;
XrViewConfigurationProperties ViewportConfig;
XrViewConfigurationView ViewConfigurationView[ovrMaxNumEyes];
XrSystemId SystemId;
XrSpace LocalSpace;
XrSpace ViewSpace;
XrSpace StageSpace;
GLboolean SessionActive;
XrPosef xfStageFromHead;
XrView* Views;
XrMatrix4x4f ProjectionMatrices[2];
float currentDisplayRefreshRate;
float* SupportedDisplayRefreshRates;
uint32_t RequestedDisplayRefreshRateIndex;
uint32_t NumSupportedDisplayRefreshRates;
PFN_xrGetDisplayRefreshRateFB pfnGetDisplayRefreshRate;
PFN_xrRequestDisplayRefreshRateFB pfnRequestDisplayRefreshRate;
XrFrameState FrameState;
int SwapInterval;
int MainThreadTid;
int RenderThreadTid;
ovrRenderer Renderer;
ovrTrackedController TrackedController[2];
} ovrApp;
enum
{
MESSAGE_ON_CREATE,
MESSAGE_ON_START,
MESSAGE_ON_RESUME,
MESSAGE_ON_PAUSE,
MESSAGE_ON_STOP,
MESSAGE_ON_DESTROY,
MESSAGE_ON_SURFACE_CREATED,
MESSAGE_ON_SURFACE_DESTROYED
};
extern ovrApp gAppState;
void ovrTrackedController_Clear(ovrTrackedController* controller);
void * AppThreadFunction(void * parm );
//Functions that need to be implemented by the game specific code
void VR_FrameSetup();
bool VR_UseScreenLayer();
float VR_GetScreenLayerDistance();
bool VR_GetVRProjection(int eye, float zNear, float zFar, float zZoomX, float zZoomY, float* projection);
void VR_HandleControllerInput();
void VR_SetHMDOrientation(float pitch, float yaw, float roll );
void VR_SetHMDPosition(float x, float y, float z );
void VR_HapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight );
void VR_HapticUpdateEvent(const char* event, int intensity, float angle );
void VR_HapticEndFrame();
void VR_HapticStopEvent(const char* event);
void VR_HapticEnable();
void VR_HapticDisable();
//Reusable Team Beef OpenXR stuff (in TBXR_Common.cpp)
double TBXR_GetTimeInMilliSeconds();
int TBXR_GetRefresh();
void TBXR_Recenter();
void TBXR_InitialiseOpenXR();
void TBXR_WaitForSessionActive();
void TBXR_InitRenderer();
void TBXR_EnterVR();
void TBXR_GetScreenRes(int *width, int *height);
void TBXR_InitActions( void );
void TBXR_Vibrate(int duration, int channel, float intensity );
void TBXR_ProcessHaptics();
void TBXR_FrameSetup();
void TBXR_updateProjections();
void TBXR_UpdateControllers( );
void TBXR_prepareEyeBuffer(int eye );
void TBXR_finishEyeBuffer(int eye );
void TBXR_submitFrame();
#endif //vrcommon_h

View file

@ -340,10 +340,10 @@ if(BuildSPEngine OR BuildJK2SPEngine)
# JKXR files # JKXR files
set(SPEngineJKXRFiles set(SPEngineJKXRFiles
"${CMAKE_SOURCE_DIR}/JKXR/JKXR_SurfaceView.cpp" "${CMAKE_SOURCE_DIR}/JKXR/windows/JKXR_SurfaceView.cpp"
"${CMAKE_SOURCE_DIR}/JKXR/windows/TBXR_Common.cpp"
"${CMAKE_SOURCE_DIR}/JKXR/windows/TBXR_Common.h"
"${CMAKE_SOURCE_DIR}/JKXR/OpenXrInput.cpp" "${CMAKE_SOURCE_DIR}/JKXR/OpenXrInput.cpp"
"${CMAKE_SOURCE_DIR}/JKXR/TBXR_Common.cpp"
"${CMAKE_SOURCE_DIR}/JKXR/TBXR_Common.h"
"${CMAKE_SOURCE_DIR}/JKXR/VrClientInfo.h" "${CMAKE_SOURCE_DIR}/JKXR/VrClientInfo.h"
"${CMAKE_SOURCE_DIR}/JKXR/VrCommon.h" "${CMAKE_SOURCE_DIR}/JKXR/VrCommon.h"
"${CMAKE_SOURCE_DIR}/JKXR/VrInputCommon.cpp" "${CMAKE_SOURCE_DIR}/JKXR/VrInputCommon.cpp"