Couple of things..

- Attempt to stop weapon recoil jarring the view
- Slight refactoring and renaming of functions
This commit is contained in:
Simon 2020-03-30 21:06:24 +01:00
parent dbf0170cc2
commit 2d2d33e719
9 changed files with 83 additions and 63 deletions

View file

@ -154,12 +154,12 @@ LAMBDA1VR Stuff
static bool useVirtualScreen = true; static bool useVirtualScreen = true;
extern bool automapactive; extern bool automapactive;
void setUseScreenLayer(bool use) void QzDoom_setUseScreenLayer(bool use)
{ {
useVirtualScreen = use; useVirtualScreen = use;
} }
bool useScreenLayer() bool QzDoom_useScreenLayer()
{ {
return useVirtualScreen || automapactive; return useVirtualScreen || automapactive;
} }
@ -813,15 +813,15 @@ void setHMDPosition( float x, float y, float z, float yaw )
VectorSet(hmdPosition, x, y, z); VectorSet(hmdPosition, x, y, z);
if (s_useScreen != useScreenLayer()) if (s_useScreen != QzDoom_useScreenLayer())
{ {
s_useScreen = useScreenLayer(); s_useScreen = QzDoom_useScreenLayer();
//Record player height on transition //Record player height on transition
playerHeight = y; playerHeight = y;
} }
if (!useScreenLayer()) if (!QzDoom_useScreenLayer())
{ {
playerYaw = yaw; playerYaw = yaw;
} }
@ -835,7 +835,7 @@ bool isMultiplayer()
/* /*
======================== ========================
VR_Vibrate QzDoom_Vibrate
======================== ========================
*/ */
@ -843,7 +843,7 @@ VR_Vibrate
float vibration_channel_duration[2] = {0.0f, 0.0f}; float vibration_channel_duration[2] = {0.0f, 0.0f};
float vibration_channel_intensity[2] = {0.0f, 0.0f}; float vibration_channel_intensity[2] = {0.0f, 0.0f};
void VR_Vibrate( float duration, int channel, float intensity ) void QzDoom_Vibrate(float duration, int channel, float intensity )
{ {
if (vibration_channel_duration[channel] > 0.0f) if (vibration_channel_duration[channel] > 0.0f)
return; return;
@ -1244,7 +1244,7 @@ int m_height;
//qboolean R_SetMode( void ); //qboolean R_SetMode( void );
void VR_GetScreenRes(uint32_t *width, uint32_t *height) void QzDoom_GetScreenRes(uint32_t *width, uint32_t *height)
{ {
*width = m_width; *width = m_width;
*height = m_height; *height = m_height;
@ -1284,9 +1284,9 @@ static ovrApp gAppState;
static ovrJava java; static ovrJava java;
static bool destroyed = false; static bool destroyed = false;
void prepareEyeBuffer(int eye ) void QzDoom_prepareEyeBuffer(int eye )
{ {
ovrRenderer *renderer = useScreenLayer() ? &gAppState.Scene.CylinderRenderer : &gAppState.Renderer; ovrRenderer *renderer = QzDoom_useScreenLayer() ? &gAppState.Scene.CylinderRenderer : &gAppState.Renderer;
ovrFramebuffer *frameBuffer = &(renderer->FrameBuffer[eye]); ovrFramebuffer *frameBuffer = &(renderer->FrameBuffer[eye]);
ovrFramebuffer_SetCurrent(frameBuffer); ovrFramebuffer_SetCurrent(frameBuffer);
@ -1305,9 +1305,9 @@ void prepareEyeBuffer(int eye )
GL(glDisable(GL_SCISSOR_TEST)); GL(glDisable(GL_SCISSOR_TEST));
} }
void finishEyeBuffer(int eye ) void QzDoom_finishEyeBuffer(int eye )
{ {
ovrRenderer *renderer = useScreenLayer() ? &gAppState.Scene.CylinderRenderer : &gAppState.Renderer; ovrRenderer *renderer = QzDoom_useScreenLayer() ? &gAppState.Scene.CylinderRenderer : &gAppState.Renderer;
ovrFramebuffer *frameBuffer = &(renderer->FrameBuffer[eye]); ovrFramebuffer *frameBuffer = &(renderer->FrameBuffer[eye]);
@ -1319,7 +1319,7 @@ void finishEyeBuffer(int eye )
ovrFramebuffer_SetNone(); ovrFramebuffer_SetNone();
} }
bool processMessageQueue() { bool QzDoom_processMessageQueue() {
for ( ; ; ) for ( ; ; )
{ {
ovrMessage message; ovrMessage message;
@ -1429,7 +1429,7 @@ void * AppThreadFunction(void * parm ) {
//First handle any messages in the queue //First handle any messages in the queue
while ( gAppState.Ovr == NULL ) { while ( gAppState.Ovr == NULL ) {
processMessageQueue(); QzDoom_processMessageQueue();
} }
ovrRenderer_Create(m_width, m_height, &gAppState.Renderer, &java); ovrRenderer_Create(m_width, m_height, &gAppState.Renderer, &java);
@ -1446,7 +1446,7 @@ void * AppThreadFunction(void * parm ) {
//Run loading loop until we are ready to start QzDoom //Run loading loop until we are ready to start QzDoom
while (!destroyed && !qzdoom_initialised) { while (!destroyed && !qzdoom_initialised) {
processMessageQueue(); QzDoom_processMessageQueue();
incrementFrameIndex(); incrementFrameIndex();
showLoadingIcon(); showLoadingIcon();
} }
@ -1467,7 +1467,7 @@ void QzDoom_FrameSetup()
vrapi_SetTrackingSpace(gAppState.Ovr, VRAPI_TRACKING_SPACE_LOCAL_FLOOR); vrapi_SetTrackingSpace(gAppState.Ovr, VRAPI_TRACKING_SPACE_LOCAL_FLOOR);
} }
void processHaptics() {//Handle haptics void QzDoom_processHaptics() {//Handle haptics
static float lastFrameTime = 0.0f; static float lastFrameTime = 0.0f;
float timestamp = (float)(GetTimeInMilliSeconds()); float timestamp = (float)(GetTimeInMilliSeconds());
float frametime = timestamp - lastFrameTime; float frametime = timestamp - lastFrameTime;
@ -1521,7 +1521,7 @@ void showLoadingIcon()
vrapi_SubmitFrame2( gAppState.Ovr, &frameDesc ); vrapi_SubmitFrame2( gAppState.Ovr, &frameDesc );
} }
void getHMDOrientation(ovrTracking2 *tracking) {//Get orientation void QzDoom_getHMDOrientation(ovrTracking2 *tracking) {//Get orientation
// Get the HMD pose, predicted for the middle of the time period during which // Get the HMD pose, predicted for the middle of the time period during which
// the new eye images will be displayed. The number of frames predicted ahead // the new eye images will be displayed. The number of frames predicted ahead
@ -1560,7 +1560,7 @@ void incrementFrameIndex()
gAppState.FrameIndex); gAppState.FrameIndex);
} }
void getTrackedRemotesOrientation(int vr_control_scheme) {//Get info for tracked remotes void QzDoom_getTrackedRemotesOrientation(int vr_control_scheme) {//Get info for tracked remotes
acquireTrackedRemotesData(gAppState.Ovr, gAppState.DisplayTime); acquireTrackedRemotesData(gAppState.Ovr, gAppState.DisplayTime);
//Call additional control schemes here //Call additional control schemes here
@ -1579,11 +1579,11 @@ void getTrackedRemotesOrientation(int vr_control_scheme) {//Get info for tracked
} }
} }
void submitFrame(ovrTracking2 *tracking) void QzDoom_submitFrame(ovrTracking2 *tracking)
{ {
ovrSubmitFrameDescription2 frameDesc = {0}; ovrSubmitFrameDescription2 frameDesc = {0};
if (!useScreenLayer()) { if (!QzDoom_useScreenLayer()) {
ovrLayerProjection2 layer = vrapi_DefaultLayerProjection2(); ovrLayerProjection2 layer = vrapi_DefaultLayerProjection2();
layer.HeadPose = (*tracking).HeadPose; layer.HeadPose = (*tracking).HeadPose;

View file

@ -72,28 +72,24 @@ float nonLinearFilter(float in);
bool between(float min, float val, float max); bool between(float min, float val, float max);
void rotateAboutOrigin(float v1, float v2, float rotation, vec2_t out); void rotateAboutOrigin(float v1, float v2, float rotation, vec2_t out);
void QuatToYawPitchRoll(ovrQuatf q, vec3_t rotation, vec3_t out); void QuatToYawPitchRoll(ovrQuatf q, vec3_t rotation, vec3_t out);
bool useScreenLayer();
void handleTrackedControllerButton(ovrInputStateTrackedRemote * trackedRemoteState, ovrInputStateTrackedRemote * prevTrackedRemoteState, uint32_t button, int key); void handleTrackedControllerButton(ovrInputStateTrackedRemote * trackedRemoteState, ovrInputStateTrackedRemote * prevTrackedRemoteState, uint32_t button, int key);
void VR_GetScreenRes(uint32_t *width, uint32_t *height);
void VR_Vibrate( float duration, int channel, float intensity ); //Called from engine code
bool processMessageQueue(); bool QzDoom_useScreenLayer();
void QzDoom_GetScreenRes(uint32_t *width, uint32_t *height);
void QzDoom_Vibrate(float duration, int channel, float intensity );
bool QzDoom_processMessageQueue();
void QzDoom_FrameSetup(); void QzDoom_FrameSetup();
void QzDoom_setUseScreenLayer(bool use);
void C_DoCommandC (const char *cmd); void QzDoom_processHaptics();
void QzDoom_getHMDOrientation(ovrTracking2 *tracking);
float VR_GetRawYaw(); void QzDoom_getTrackedRemotesOrientation(int vr_control_scheme);
void setUseScreenLayer(bool use);
void processHaptics();
void getHMDOrientation(ovrTracking2 *tracking);
void getTrackedRemotesOrientation(int vr_control_scheme);
void incrementFrameIndex(); void incrementFrameIndex();
void prepareEyeBuffer(int eye ); void QzDoom_prepareEyeBuffer(int eye );
void finishEyeBuffer(int eye ); void QzDoom_finishEyeBuffer(int eye );
void submitFrame(ovrTracking2 *tracking); void QzDoom_submitFrame(ovrTracking2 *tracking);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"

View file

@ -30,7 +30,6 @@
#include <string> #include <string>
#include <map> #include <map>
#include <cmath> #include <cmath>
#include <VrApi_Ext.h>
#include "p_trace.h" #include "p_trace.h"
#include "p_linetracedata.h" #include "p_linetracedata.h"
#include "gl/system/gl_system.h" #include "gl/system/gl_system.h"
@ -41,15 +40,11 @@
#include "r_utility.h" // viewpitch #include "r_utility.h" // viewpitch
#include "gl/renderer/gl_renderer.h" #include "gl/renderer/gl_renderer.h"
#include "gl/renderer/gl_renderbuffers.h" #include "gl/renderer/gl_renderbuffers.h"
#include "gl/renderer/gl_2ddrawer.h" // crosshair
#include "gl/models/gl_models.h"
#include "g_levellocals.h" // pixelstretch #include "g_levellocals.h" // pixelstretch
#include "g_statusbar/sbar.h"
#include "math/cmath.h" #include "math/cmath.h"
#include "c_cvars.h" #include "c_cvars.h"
#include "cmdlib.h" #include "cmdlib.h"
#include "w_wad.h" #include "w_wad.h"
#include "m_joy.h"
#include "d_gui.h" #include "d_gui.h"
#include "d_event.h" #include "d_event.h"
@ -135,13 +130,13 @@ namespace s3d
bool OculusQuestEyePose::submitFrame() const bool OculusQuestEyePose::submitFrame() const
{ {
prepareEyeBuffer( eye ); QzDoom_prepareEyeBuffer(eye);
GLRenderer->mBuffers->BindEyeTexture(eye, 0); GLRenderer->mBuffers->BindEyeTexture(eye, 0);
GL_IRECT box = {0, 0, GLRenderer->mSceneViewport.width, GLRenderer->mSceneViewport.height}; GL_IRECT box = {0, 0, GLRenderer->mSceneViewport.width, GLRenderer->mSceneViewport.height};
GLRenderer->DrawPresentTexture(box, true); GLRenderer->DrawPresentTexture(box, true);
finishEyeBuffer( eye ); QzDoom_finishEyeBuffer(eye);
return true; return true;
} }
@ -232,7 +227,7 @@ namespace s3d
eye_ptrs.Push(&rightEyeView); eye_ptrs.Push(&rightEyeView);
//Get this from my code //Get this from my code
VR_GetScreenRes(&sceneWidth, &sceneHeight); QzDoom_GetScreenRes(&sceneWidth, &sceneHeight);
} }
void OculusQuestMode::getTracking(ovrTracking2 *_tracking) const void OculusQuestMode::getTracking(ovrTracking2 *_tracking) const
@ -339,7 +334,7 @@ namespace s3d
leftEyeView.submitFrame(); leftEyeView.submitFrame();
rightEyeView.submitFrame(); rightEyeView.submitFrame();
submitFrame(&tracking); QzDoom_submitFrame(&tracking);
} }
static int mAngleFromRadians(double radians) static int mAngleFromRadians(double radians)
@ -397,7 +392,7 @@ namespace s3d
return; return;
} }
processMessageQueue(); QzDoom_processMessageQueue();
// Set VR-appropriate settings // Set VR-appropriate settings
{ {
@ -407,23 +402,23 @@ namespace s3d
if (gamestate == GS_LEVEL && !isMenuActive()) { if (gamestate == GS_LEVEL && !isMenuActive()) {
cachedScreenBlocks = screenblocks; cachedScreenBlocks = screenblocks;
screenblocks = 12; screenblocks = 12;
setUseScreenLayer(false); QzDoom_setUseScreenLayer(false);
} }
else { else {
//Ensure we are drawing on virtual screen //Ensure we are drawing on virtual screen
setUseScreenLayer(true); QzDoom_setUseScreenLayer(true);
} }
processHaptics(); QzDoom_processHaptics();
//Get controller state here //Get controller state here
getHMDOrientation(&tracking); QzDoom_getHMDOrientation(&tracking);
//Set up stuff used in the tracking code //Set up stuff used in the tracking code
vr_weapon_pitchadjust = vr_weaponRotate; vr_weapon_pitchadjust = vr_weaponRotate;
vr_snapturn_angle = vr_snapTurn; vr_snapturn_angle = vr_snapTurn;
vr_walkdirection = !vr_moveFollowsOffHand; vr_walkdirection = !vr_moveFollowsOffHand;
getTrackedRemotesOrientation(vr_control_scheme); QzDoom_getTrackedRemotesOrientation(vr_control_scheme);
//Some crazy stuff to ascertain the actual yaw that doom is using at the right times! //Some crazy stuff to ascertain the actual yaw that doom is using at the right times!
if (gamestate != GS_LEVEL || isMenuActive() || (gamestate == GS_LEVEL && resetDoomYaw)) if (gamestate != GS_LEVEL || isMenuActive() || (gamestate == GS_LEVEL && resetDoomYaw))

View file

@ -1292,6 +1292,13 @@ DEFINE_ACTION_FUNCTION(AActor, A_Recoil)
PARAM_SELF_PROLOGUE(AActor); PARAM_SELF_PROLOGUE(AActor);
PARAM_FLOAT(xyvel); PARAM_FLOAT(xyvel);
//We don't want to adjust the player's camera - that could make them sick
player_t* player = r_viewpoint.camera ? r_viewpoint.camera->player : nullptr;
if (player != nullptr && self != nullptr && player->mo == self)
{
return 0;
}
self->Thrust(self->Angles.Yaw + 180., xyvel); self->Thrust(self->Angles.Yaw + 180., xyvel);
return 0; return 0;
} }
@ -2819,6 +2826,14 @@ DEFINE_ACTION_FUNCTION(AActor, A_SetAngle)
PARAM_INT(ptr); PARAM_INT(ptr);
AActor *ref = COPY_AAPTR(self, ptr); AActor *ref = COPY_AAPTR(self, ptr);
//We don't want to adjust the player's camera - that could make them sick
player_t* player = r_viewpoint.camera ? r_viewpoint.camera->player : nullptr;
if (player != nullptr && ref != nullptr && player->mo == ref)
{
return 0;
}
if (ref != NULL) if (ref != NULL)
{ {
ref->SetAngle(angle, !!(flags & SPF_INTERPOLATE)); ref->SetAngle(angle, !!(flags & SPF_INTERPOLATE));
@ -2843,6 +2858,13 @@ DEFINE_ACTION_FUNCTION(AActor, A_SetPitch)
AActor *ref = COPY_AAPTR(self, ptr); AActor *ref = COPY_AAPTR(self, ptr);
//We don't want to adjust the player's camera - that could make them sick
player_t* player = r_viewpoint.camera ? r_viewpoint.camera->player : nullptr;
if (player != nullptr && ref != nullptr && player->mo == ref)
{
return 0;
}
if (ref != NULL) if (ref != NULL)
{ {
ref->SetPitch(pitch, !!(flags & SPF_INTERPOLATE), !!(flags & SPF_FORCECLAMP)); ref->SetPitch(pitch, !!(flags & SPF_INTERPOLATE), !!(flags & SPF_FORCECLAMP));
@ -2866,6 +2888,13 @@ DEFINE_ACTION_FUNCTION(AActor, A_SetRoll)
PARAM_INT (ptr) ; PARAM_INT (ptr) ;
AActor *ref = COPY_AAPTR(self, ptr); AActor *ref = COPY_AAPTR(self, ptr);
//We don't want to adjust the player's camera - that could make them sick
player_t* player = r_viewpoint.camera ? r_viewpoint.camera->player : nullptr;
if (player != nullptr && ref != nullptr && player->mo == ref)
{
return 0;
}
if (ref != NULL) if (ref != NULL)
{ {
ref->SetRoll(roll, !!(flags & SPF_INTERPOLATE)); ref->SetRoll(roll, !!(flags & SPF_INTERPOLATE));

View file

@ -4391,7 +4391,7 @@ static ETraceStatus CheckForActor(FTraceResults &res, void *userdata)
// //
//========================================================================== //==========================================================================
EXTERN_CVAR(Int, vr_control_scheme) EXTERN_CVAR(Int, vr_control_scheme)
extern "C" void VR_Vibrate( float duration, int channel, float intensity ); extern "C" void QzDoom_Vibrate(float duration, int channel, float intensity );
extern bool weaponStabilised; extern bool weaponStabilised;
AActor *P_LineAttack(AActor *t1, DAngle angle, double distance, AActor *P_LineAttack(AActor *t1, DAngle angle, double distance,
@ -4434,10 +4434,10 @@ AActor *P_LineAttack(AActor *t1, DAngle angle, double distance,
//Haptics //Haptics
long rightHanded = vr_control_scheme < 10; long rightHanded = vr_control_scheme < 10;
VR_Vibrate( 150, rightHanded ? 1 : 0, 0.8 ); QzDoom_Vibrate(150, rightHanded ? 1 : 0, 0.8);
if (weaponStabilised) if (weaponStabilised)
{ {
VR_Vibrate( 150, rightHanded ? 0 : 1, 0.6 ); QzDoom_Vibrate(150, rightHanded ? 0 : 1, 0.6);
} }
} }

View file

@ -6678,7 +6678,7 @@ DEFINE_ACTION_FUNCTION(AActor, SpawnSubMissile)
================ ================
*/ */
EXTERN_CVAR(Int, vr_control_scheme) EXTERN_CVAR(Int, vr_control_scheme)
extern "C" void VR_Vibrate( float duration, int channel, float intensity ); extern "C" void QzDoom_Vibrate(float duration, int channel, float intensity );
extern bool weaponStabilised; extern bool weaponStabilised;
AActor *P_SpawnPlayerMissile (AActor *source, double x, double y, double z, AActor *P_SpawnPlayerMissile (AActor *source, double x, double y, double z,
@ -6774,10 +6774,10 @@ AActor *P_SpawnPlayerMissile (AActor *source, double x, double y, double z,
//Haptics //Haptics
long rightHanded = vr_control_scheme < 10; long rightHanded = vr_control_scheme < 10;
VR_Vibrate( 150, rightHanded ? 1 : 0, 0.8 ); QzDoom_Vibrate(150, rightHanded ? 1 : 0, 0.8);
if (weaponStabilised) if (weaponStabilised)
{ {
VR_Vibrate( 150, rightHanded ? 0 : 1, 0.6 ); QzDoom_Vibrate(150, rightHanded ? 0 : 1, 0.6);
} }

View file

@ -316,7 +316,7 @@ void NoSDLGLFB::SwapBuffers()
int NoSDLGLFB::GetClientWidth() int NoSDLGLFB::GetClientWidth()
{ {
uint32_t w, h; uint32_t w, h;
VR_GetScreenRes(&w, &h); QzDoom_GetScreenRes(&w, &h);
int width = w; int width = w;
return width; return width;
} }
@ -324,7 +324,7 @@ int NoSDLGLFB::GetClientWidth()
int NoSDLGLFB::GetClientHeight() int NoSDLGLFB::GetClientHeight()
{ {
uint32_t w, h; uint32_t w, h;
VR_GetScreenRes(&w, &h); QzDoom_GetScreenRes(&w, &h);
int height = h; int height = h;
return height; return height;
} }
@ -332,7 +332,7 @@ int NoSDLGLFB::GetClientHeight()
void NoSDLGLFB::ScaleCoordsFromWindow(int16_t &x, int16_t &y) void NoSDLGLFB::ScaleCoordsFromWindow(int16_t &x, int16_t &y)
{ {
uint32_t w, h; uint32_t w, h;
VR_GetScreenRes(&w, &h); QzDoom_GetScreenRes(&w, &h);
// Detect if we're doing scaling in the Window and adjust the mouse // Detect if we're doing scaling in the Window and adjust the mouse
// coordinates accordingly. This could be more efficent, but I // coordinates accordingly. This could be more efficent, but I

View file

@ -232,7 +232,7 @@ void NoSDLFB::SetVSync (bool vsync)
void NoSDLFB::ScaleCoordsFromWindow(int16_t &x, int16_t &y) void NoSDLFB::ScaleCoordsFromWindow(int16_t &x, int16_t &y)
{ {
uint32_t w, h; uint32_t w, h;
VR_GetScreenRes(&w, &h); QzDoom_GetScreenRes(&w, &h);
// Detect if we're doing scaling in the Window and adjust the mouse // Detect if we're doing scaling in the Window and adjust the mouse

View file

@ -1529,7 +1529,7 @@ void V_Init (bool restart)
if (height == 0) if (height == 0)
{ {
uint32_t uWidth, uHeight; uint32_t uWidth, uHeight;
VR_GetScreenRes(&uWidth, &uHeight); QzDoom_GetScreenRes(&uWidth, &uHeight);
width = uWidth; width = uWidth;
height = uHeight; height = uHeight;
} }