From 2d2d33e7191cd712937e19b592d1cd8038eb585d Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 30 Mar 2020 21:06:24 +0100 Subject: [PATCH] Couple of things.. - Attempt to stop weapon recoil jarring the view - Slight refactoring and renaming of functions --- .../Android/jni/QzDoom/QzDoom_SurfaceView.c | 40 +++++++++---------- Projects/Android/jni/QzDoom/VrCommon.h | 30 ++++++-------- .../src/gl/stereo3d/gl_oculusquest.cpp | 25 +++++------- .../src/p_actionfunctions.cpp | 29 ++++++++++++++ .../jni/gzdoom-g3.3mgw_mobile/src/p_map.cpp | 6 +-- .../jni/gzdoom-g3.3mgw_mobile/src/p_mobj.cpp | 6 +-- .../src/posix/nosdl/glvideo.cpp | 6 +-- .../src/posix/nosdl/video.cpp | 2 +- .../jni/gzdoom-g3.3mgw_mobile/src/v_video.cpp | 2 +- 9 files changed, 83 insertions(+), 63 deletions(-) diff --git a/Projects/Android/jni/QzDoom/QzDoom_SurfaceView.c b/Projects/Android/jni/QzDoom/QzDoom_SurfaceView.c index 951a671..9864213 100644 --- a/Projects/Android/jni/QzDoom/QzDoom_SurfaceView.c +++ b/Projects/Android/jni/QzDoom/QzDoom_SurfaceView.c @@ -154,12 +154,12 @@ LAMBDA1VR Stuff static bool useVirtualScreen = true; extern bool automapactive; -void setUseScreenLayer(bool use) +void QzDoom_setUseScreenLayer(bool use) { useVirtualScreen = use; } -bool useScreenLayer() +bool QzDoom_useScreenLayer() { return useVirtualScreen || automapactive; } @@ -813,15 +813,15 @@ void setHMDPosition( float x, float y, float z, float yaw ) 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 playerHeight = y; } - if (!useScreenLayer()) + if (!QzDoom_useScreenLayer()) { 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_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) return; @@ -1244,7 +1244,7 @@ int m_height; //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; *height = m_height; @@ -1284,9 +1284,9 @@ static ovrApp gAppState; static ovrJava java; 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_SetCurrent(frameBuffer); @@ -1305,9 +1305,9 @@ void prepareEyeBuffer(int eye ) 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]); @@ -1319,7 +1319,7 @@ void finishEyeBuffer(int eye ) ovrFramebuffer_SetNone(); } -bool processMessageQueue() { +bool QzDoom_processMessageQueue() { for ( ; ; ) { ovrMessage message; @@ -1429,7 +1429,7 @@ void * AppThreadFunction(void * parm ) { //First handle any messages in the queue while ( gAppState.Ovr == NULL ) { - processMessageQueue(); + QzDoom_processMessageQueue(); } 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 while (!destroyed && !qzdoom_initialised) { - processMessageQueue(); + QzDoom_processMessageQueue(); incrementFrameIndex(); showLoadingIcon(); } @@ -1467,7 +1467,7 @@ void QzDoom_FrameSetup() vrapi_SetTrackingSpace(gAppState.Ovr, VRAPI_TRACKING_SPACE_LOCAL_FLOOR); } -void processHaptics() {//Handle haptics +void QzDoom_processHaptics() {//Handle haptics static float lastFrameTime = 0.0f; float timestamp = (float)(GetTimeInMilliSeconds()); float frametime = timestamp - lastFrameTime; @@ -1521,7 +1521,7 @@ void showLoadingIcon() 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 // the new eye images will be displayed. The number of frames predicted ahead @@ -1560,7 +1560,7 @@ void incrementFrameIndex() 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); //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}; - if (!useScreenLayer()) { + if (!QzDoom_useScreenLayer()) { ovrLayerProjection2 layer = vrapi_DefaultLayerProjection2(); layer.HeadPose = (*tracking).HeadPose; diff --git a/Projects/Android/jni/QzDoom/VrCommon.h b/Projects/Android/jni/QzDoom/VrCommon.h index c1aca09..1808dbd 100644 --- a/Projects/Android/jni/QzDoom/VrCommon.h +++ b/Projects/Android/jni/QzDoom/VrCommon.h @@ -72,28 +72,24 @@ float nonLinearFilter(float in); bool between(float min, float val, float max); void rotateAboutOrigin(float v1, float v2, float rotation, vec2_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 VR_GetScreenRes(uint32_t *width, uint32_t *height); -void VR_Vibrate( float duration, int channel, float intensity ); -bool processMessageQueue(); + +//Called from engine code +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 C_DoCommandC (const char *cmd); - -float VR_GetRawYaw(); - -void setUseScreenLayer(bool use); - -void processHaptics(); -void getHMDOrientation(ovrTracking2 *tracking); -void getTrackedRemotesOrientation(int vr_control_scheme); +void QzDoom_setUseScreenLayer(bool use); +void QzDoom_processHaptics(); +void QzDoom_getHMDOrientation(ovrTracking2 *tracking); +void QzDoom_getTrackedRemotesOrientation(int vr_control_scheme); void incrementFrameIndex(); -void prepareEyeBuffer(int eye ); -void finishEyeBuffer(int eye ); -void submitFrame(ovrTracking2 *tracking); +void QzDoom_prepareEyeBuffer(int eye ); +void QzDoom_finishEyeBuffer(int eye ); +void QzDoom_submitFrame(ovrTracking2 *tracking); #ifdef __cplusplus } // extern "C" diff --git a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/gl/stereo3d/gl_oculusquest.cpp b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/gl/stereo3d/gl_oculusquest.cpp index 78a9a9f..d421dbb 100644 --- a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/gl/stereo3d/gl_oculusquest.cpp +++ b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/gl/stereo3d/gl_oculusquest.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include "p_trace.h" #include "p_linetracedata.h" #include "gl/system/gl_system.h" @@ -41,15 +40,11 @@ #include "r_utility.h" // viewpitch #include "gl/renderer/gl_renderer.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_statusbar/sbar.h" #include "math/cmath.h" #include "c_cvars.h" #include "cmdlib.h" #include "w_wad.h" -#include "m_joy.h" #include "d_gui.h" #include "d_event.h" @@ -135,13 +130,13 @@ namespace s3d bool OculusQuestEyePose::submitFrame() const { - prepareEyeBuffer( eye ); + QzDoom_prepareEyeBuffer(eye); GLRenderer->mBuffers->BindEyeTexture(eye, 0); GL_IRECT box = {0, 0, GLRenderer->mSceneViewport.width, GLRenderer->mSceneViewport.height}; GLRenderer->DrawPresentTexture(box, true); - finishEyeBuffer( eye ); + QzDoom_finishEyeBuffer(eye); return true; } @@ -232,7 +227,7 @@ namespace s3d eye_ptrs.Push(&rightEyeView); //Get this from my code - VR_GetScreenRes(&sceneWidth, &sceneHeight); + QzDoom_GetScreenRes(&sceneWidth, &sceneHeight); } void OculusQuestMode::getTracking(ovrTracking2 *_tracking) const @@ -339,7 +334,7 @@ namespace s3d leftEyeView.submitFrame(); rightEyeView.submitFrame(); - submitFrame(&tracking); + QzDoom_submitFrame(&tracking); } static int mAngleFromRadians(double radians) @@ -397,7 +392,7 @@ namespace s3d return; } - processMessageQueue(); + QzDoom_processMessageQueue(); // Set VR-appropriate settings { @@ -407,23 +402,23 @@ namespace s3d if (gamestate == GS_LEVEL && !isMenuActive()) { cachedScreenBlocks = screenblocks; screenblocks = 12; - setUseScreenLayer(false); + QzDoom_setUseScreenLayer(false); } else { //Ensure we are drawing on virtual screen - setUseScreenLayer(true); + QzDoom_setUseScreenLayer(true); } - processHaptics(); + QzDoom_processHaptics(); //Get controller state here - getHMDOrientation(&tracking); + QzDoom_getHMDOrientation(&tracking); //Set up stuff used in the tracking code vr_weapon_pitchadjust = vr_weaponRotate; vr_snapturn_angle = vr_snapTurn; 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! if (gamestate != GS_LEVEL || isMenuActive() || (gamestate == GS_LEVEL && resetDoomYaw)) diff --git a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/p_actionfunctions.cpp b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/p_actionfunctions.cpp index d79f6bc..267d03e 100644 --- a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/p_actionfunctions.cpp +++ b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/p_actionfunctions.cpp @@ -1292,6 +1292,13 @@ DEFINE_ACTION_FUNCTION(AActor, A_Recoil) PARAM_SELF_PROLOGUE(AActor); 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); return 0; } @@ -2819,6 +2826,14 @@ DEFINE_ACTION_FUNCTION(AActor, A_SetAngle) PARAM_INT(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) { ref->SetAngle(angle, !!(flags & SPF_INTERPOLATE)); @@ -2843,6 +2858,13 @@ DEFINE_ACTION_FUNCTION(AActor, A_SetPitch) 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) { ref->SetPitch(pitch, !!(flags & SPF_INTERPOLATE), !!(flags & SPF_FORCECLAMP)); @@ -2866,6 +2888,13 @@ DEFINE_ACTION_FUNCTION(AActor, A_SetRoll) PARAM_INT (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) { ref->SetRoll(roll, !!(flags & SPF_INTERPOLATE)); diff --git a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/p_map.cpp b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/p_map.cpp index 1ac4b2e..2ce12ab 100644 --- a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/p_map.cpp +++ b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/p_map.cpp @@ -4391,7 +4391,7 @@ static ETraceStatus CheckForActor(FTraceResults &res, void *userdata) // //========================================================================== 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; AActor *P_LineAttack(AActor *t1, DAngle angle, double distance, @@ -4434,10 +4434,10 @@ AActor *P_LineAttack(AActor *t1, DAngle angle, double distance, //Haptics long rightHanded = vr_control_scheme < 10; - VR_Vibrate( 150, rightHanded ? 1 : 0, 0.8 ); + QzDoom_Vibrate(150, rightHanded ? 1 : 0, 0.8); if (weaponStabilised) { - VR_Vibrate( 150, rightHanded ? 0 : 1, 0.6 ); + QzDoom_Vibrate(150, rightHanded ? 0 : 1, 0.6); } } diff --git a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/p_mobj.cpp b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/p_mobj.cpp index 655f3bc..3ac894c 100644 --- a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/p_mobj.cpp +++ b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/p_mobj.cpp @@ -6678,7 +6678,7 @@ DEFINE_ACTION_FUNCTION(AActor, SpawnSubMissile) ================ */ 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; 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 long rightHanded = vr_control_scheme < 10; - VR_Vibrate( 150, rightHanded ? 1 : 0, 0.8 ); + QzDoom_Vibrate(150, rightHanded ? 1 : 0, 0.8); if (weaponStabilised) { - VR_Vibrate( 150, rightHanded ? 0 : 1, 0.6 ); + QzDoom_Vibrate(150, rightHanded ? 0 : 1, 0.6); } diff --git a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/posix/nosdl/glvideo.cpp b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/posix/nosdl/glvideo.cpp index 7040df2..e7f86a7 100644 --- a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/posix/nosdl/glvideo.cpp +++ b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/posix/nosdl/glvideo.cpp @@ -316,7 +316,7 @@ void NoSDLGLFB::SwapBuffers() int NoSDLGLFB::GetClientWidth() { uint32_t w, h; - VR_GetScreenRes(&w, &h); + QzDoom_GetScreenRes(&w, &h); int width = w; return width; } @@ -324,7 +324,7 @@ int NoSDLGLFB::GetClientWidth() int NoSDLGLFB::GetClientHeight() { uint32_t w, h; - VR_GetScreenRes(&w, &h); + QzDoom_GetScreenRes(&w, &h); int height = h; return height; } @@ -332,7 +332,7 @@ int NoSDLGLFB::GetClientHeight() void NoSDLGLFB::ScaleCoordsFromWindow(int16_t &x, int16_t &y) { 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 // coordinates accordingly. This could be more efficent, but I diff --git a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/posix/nosdl/video.cpp b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/posix/nosdl/video.cpp index fe137ba..f3fd6b0 100644 --- a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/posix/nosdl/video.cpp +++ b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/posix/nosdl/video.cpp @@ -232,7 +232,7 @@ void NoSDLFB::SetVSync (bool vsync) void NoSDLFB::ScaleCoordsFromWindow(int16_t &x, int16_t &y) { 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 diff --git a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/v_video.cpp b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/v_video.cpp index a858c1c..3a80c97 100644 --- a/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/v_video.cpp +++ b/Projects/Android/jni/gzdoom-g3.3mgw_mobile/src/v_video.cpp @@ -1529,7 +1529,7 @@ void V_Init (bool restart) if (height == 0) { uint32_t uWidth, uHeight; - VR_GetScreenRes(&uWidth, &uHeight); + QzDoom_GetScreenRes(&uWidth, &uHeight); width = uWidth; height = uHeight; }