From 3678133c677b4d9d7b2aec48be8c843df6762d7d Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 6 Feb 2022 15:31:17 +0000 Subject: [PATCH] Made the victory podium scenes full VR --- android/app/src/main/AndroidManifest.xml | 4 +- code/cgame/cg_draw.c | 5 ++ code/cgame/cg_view.c | 11 +++ code/client/cl_scrn.c | 46 +++++++++--- code/client/cl_ui.c | 8 +++ code/q3_ui/ui_atoms.c | 89 +++++++++++++++++------- code/q3_ui/ui_main.c | 9 +++ code/qcommon/q_math.c | 2 +- code/renderergl2/tr_backend.c | 2 +- code/ui/ui_public.h | 4 +- code/ui/ui_shared.c | 27 +++++-- code/vr/vr_base.c | 6 +- code/vr/vr_input.c | 8 +-- 13 files changed, 169 insertions(+), 52 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index cf3b90db..39882fbf 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -2,8 +2,8 @@ + android:versionCode="11" + android:versionName="0.7.1"> diff --git a/code/cgame/cg_draw.c b/code/cgame/cg_draw.c index a57e3346..c935160a 100644 --- a/code/cgame/cg_draw.c +++ b/code/cgame/cg_draw.c @@ -1948,6 +1948,11 @@ static void CG_DrawCrosshair3D(void) return; } + if (cg.snap->ps.pm_type == PM_INTERMISSION) + { + return; + } + if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR) { return; } diff --git a/code/cgame/cg_view.c b/code/cgame/cg_view.c index d8e38ff9..2a977f99 100644 --- a/code/cgame/cg_view.c +++ b/code/cgame/cg_view.c @@ -651,6 +651,17 @@ static int CG_CalcViewValues( void ) { static float hmdYaw = 0; if ( ps->pm_type == PM_INTERMISSION ) { VectorCopy( ps->origin, cg.refdef.vieworg ); + + static vec3_t mins = { -1, -1, -1 }; + static vec3_t maxs = { 1, 1, 1 }; + trace_t trace; + vec3_t forward; + vec3_t end; + AngleVectors(ps->viewangles, forward, NULL, NULL); + VectorMA(ps->origin, -80, forward, end); + CG_Trace( &trace, ps->origin, mins, maxs, end, cg.predictedPlayerState.clientNum, MASK_SOLID ); + VectorCopy(trace.endpos, cg.refdef.vieworg); + VectorCopy(cgVR->hmdorientation, cg.refdefViewAngles); cg.refdefViewAngles[YAW] += (ps->viewangles[YAW] - hmdYaw); AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis ); diff --git a/code/client/cl_scrn.c b/code/client/cl_scrn.c index 853a821e..d7e572d1 100644 --- a/code/client/cl_scrn.c +++ b/code/client/cl_scrn.c @@ -22,6 +22,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // cl_scrn.c -- master for refresh, status bar, console, chat, notify, etc #include "client.h" +#include "../vr/vr_clientinfo.h" + +extern vr_clientinfo_t vr; qboolean scr_initialized; // ready to draw @@ -70,17 +73,38 @@ void SCR_AdjustFrom640( float *x, float *y, float *w, float *h ) { // scale for screen sizes xscale = cls.glconfig.vidWidth / 640.0; yscale = cls.glconfig.vidHeight / 480.0; - if ( x ) { - *x *= xscale; - } - if ( y ) { - *y *= yscale; - } - if ( w ) { - *w *= xscale; - } - if ( h ) { - *h *= yscale; + + if (vr.virtual_screen) { + if (x) { + *x *= xscale; + } + if (y) { + *y *= yscale; + } + if (w) { + *w *= xscale; + } + if (h) { + *h *= yscale; + } + } else { + float screenXScale = xscale / 2.75f; + float screenYScale = yscale / 2.25f; + + if (x) { + *x *= screenXScale; + *x += (cls.glconfig.vidWidth - (640 * screenXScale)) / 2.0f; + } + if (y) { + *y *= screenYScale; + *y += (cls.glconfig.vidHeight - (480 * screenYScale)) / 2.0f; + } + if (w) { + *w *= screenXScale; + } + if (h) { + *h *= screenYScale; + } } } diff --git a/code/client/cl_ui.c b/code/client/cl_ui.c index 71436484..eb427a73 100644 --- a/code/client/cl_ui.c +++ b/code/client/cl_ui.c @@ -23,8 +23,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "client.h" #include "../botlib/botlib.h" +#include "../vr/vr_clientinfo.h" extern botlib_export_t *botlib_export; +extern vr_clientinfo_t vr; vm_t *uivm; @@ -1140,6 +1142,12 @@ void CL_InitUI( void ) { // init for this gamestate VM_Call( uivm, UI_INIT, (clc.state >= CA_AUTHORIZING && clc.state < CA_ACTIVE) ); } + + { + long val = (long)(&vr); + int *ptr = (int*)(&val); //HACK!! + VM_Call( uivm, UI_SET_VR_CLIENT_INFO, ptr[0], ptr[1] ); + } } #ifndef STANDALONE diff --git a/code/q3_ui/ui_atoms.c b/code/q3_ui/ui_atoms.c index ac17814f..20288510 100644 --- a/code/q3_ui/ui_atoms.c +++ b/code/q3_ui/ui_atoms.c @@ -26,10 +26,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA User interface building blocks and support functions. **********************************************************************/ #include "ui_local.h" +#include "../vr/vr_clientinfo.h" uiStatic_t uis; qboolean m_entersound; // after a frame, so caching won't disrupt the sound +extern vr_clientinfo_t *uiVR; + void QDECL Com_Error( int level, const char *error, ... ) { va_list argptr; char text[1024]; @@ -52,6 +55,42 @@ void QDECL Com_Printf( const char *msg, ... ) { trap_Print( text ); } +float UI_GetXScale() +{ + if (uiVR == NULL || uiVR->virtual_screen) { + return uis.xscale; + } else { + return uis.xscale / 2.75f; + } +} + +float UI_GetYScale() +{ + if (uiVR == NULL || uiVR->virtual_screen) { + return uis.yscale; + } else { + return uis.yscale / 3.25f; + } +} + +float UI_GetXOffset() +{ + if (uiVR == NULL || uiVR->virtual_screen) { + return 0; + } else { + return (uis.glconfig.vidWidth - (640 * UI_GetXScale())) / 2.0f; + } +} + +float UI_GetYOffset() +{ + if (uiVR == NULL || uiVR->virtual_screen) { + return 0; + } else { + return (uis.glconfig.vidHeight - (480 * UI_GetYScale())) / 2.0f; + } +} + /* ================= UI_ClampCvar @@ -351,15 +390,15 @@ static void UI_DrawBannerString2( int x, int y, const char* str, vec4_t color ) // draw the colored text trap_R_SetColor( color ); - ax = x * uis.xscale + uis.bias; - ay = y * uis.yscale; + ax = x * UI_GetXScale() + uis.bias + UI_GetXOffset(); + ay = y * UI_GetYScale() + UI_GetYOffset(); s = str; while ( *s ) { ch = *s & 127; if ( ch == ' ' ) { - ax += ((float)PROPB_SPACE_WIDTH + (float)PROPB_GAP_WIDTH)* uis.xscale; + ax += ((float)PROPB_SPACE_WIDTH + (float)PROPB_GAP_WIDTH)* UI_GetXScale(); } else if ( ch >= 'A' && ch <= 'Z' ) { ch -= 'A'; @@ -367,10 +406,10 @@ static void UI_DrawBannerString2( int x, int y, const char* str, vec4_t color ) frow = (float)propMapB[ch][1] / 256.0f; fwidth = (float)propMapB[ch][2] / 256.0f; fheight = (float)PROPB_HEIGHT / 256.0f; - aw = (float)propMapB[ch][2] * uis.xscale; - ah = (float)PROPB_HEIGHT * uis.yscale; + aw = (float)propMapB[ch][2] * UI_GetXScale(); + ah = (float)PROPB_HEIGHT * UI_GetYScale(); trap_R_DrawStretchPic( ax, ay, aw, ah, fcol, frow, fcol+fwidth, frow+fheight, uis.charsetPropB ); - ax += (aw + (float)PROPB_GAP_WIDTH * uis.xscale); + ax += (aw + (float)PROPB_GAP_WIDTH * UI_GetXScale()); } s++; } @@ -461,27 +500,27 @@ static void UI_DrawProportionalString2( int x, int y, const char* str, vec4_t co // draw the colored text trap_R_SetColor( color ); - ax = x * uis.xscale + uis.bias; - ay = y * uis.yscale; + ax = x * UI_GetXScale() + uis.bias + UI_GetXOffset(); + ay = y * UI_GetYScale() + UI_GetYOffset(); s = str; while ( *s ) { ch = *s & 127; if ( ch == ' ' ) { - aw = (float)PROP_SPACE_WIDTH * uis.xscale * sizeScale; + aw = (float)PROP_SPACE_WIDTH * UI_GetXScale() * sizeScale; } else if ( propMap[ch][2] != -1 ) { fcol = (float)propMap[ch][0] / 256.0f; frow = (float)propMap[ch][1] / 256.0f; fwidth = (float)propMap[ch][2] / 256.0f; fheight = (float)PROP_HEIGHT / 256.0f; - aw = (float)propMap[ch][2] * uis.xscale * sizeScale; - ah = (float)PROP_HEIGHT * uis.yscale * sizeScale; + aw = (float)propMap[ch][2] * UI_GetXScale() * sizeScale; + ah = (float)PROP_HEIGHT * UI_GetYScale() * sizeScale; trap_R_DrawStretchPic( ax, ay, aw, ah, fcol, frow, fcol+fwidth, frow+fheight, charset ); } - ax += (aw + (float)PROP_GAP_WIDTH * uis.xscale * sizeScale); + ax += (aw + (float)PROP_GAP_WIDTH * UI_GetXScale() * sizeScale); s++; } @@ -656,10 +695,10 @@ static void UI_DrawString2( int x, int y, const char* str, vec4_t color, int cha // draw the colored text trap_R_SetColor( color ); - ax = x * uis.xscale + uis.bias; - ay = y * uis.yscale; - aw = charw * uis.xscale; - ah = charh * uis.yscale; + ax = x * UI_GetXScale() + uis.bias + UI_GetXOffset(); + ay = y * UI_GetYScale() + UI_GetYOffset(); + aw = charw * UI_GetXScale(); + ah = charh * UI_GetYScale(); s = str; while ( *s ) @@ -883,7 +922,7 @@ void UI_MouseEvent( int dx, int dy ) return; // convert X bias to 640 coords - bias = uis.bias / uis.xscale; + bias = uis.bias / UI_GetXScale(); // update mouse screen position uis.cursorx += dx; @@ -1078,12 +1117,14 @@ void UI_Init( void ) { // for 640x480 virtualized screen uis.xscale = uis.glconfig.vidWidth * (1.0/640.0); uis.yscale = uis.glconfig.vidHeight * (1.0/480.0); - if ( uis.glconfig.vidWidth * 480 > uis.glconfig.vidHeight * 640 ) { +/* if ( uis.glconfig.vidWidth * 480 > uis.glconfig.vidHeight * 640 ) { // wide screen uis.bias = 0.5 * ( uis.glconfig.vidWidth - ( uis.glconfig.vidHeight * (640.0/480.0) ) ); - uis.xscale = uis.yscale; + UI_GetXScale() = UI_GetYScale(); } - else { + else + */ + { // no wide screen uis.bias = 0; } @@ -1104,10 +1145,10 @@ Adjusted for resolution and screen aspect ratio */ void UI_AdjustFrom640( float *x, float *y, float *w, float *h ) { // expect valid pointers - *x = *x * uis.xscale + uis.bias; - *y *= uis.yscale; - *w *= uis.xscale; - *h *= uis.yscale; + *x = *x * UI_GetXScale() + uis.bias + UI_GetXOffset(); + *y = *y * UI_GetYScale() + UI_GetYOffset(); + *w *= UI_GetXScale(); + *h *= UI_GetYScale(); } void UI_DrawNamedPic( float x, float y, float width, float height, const char *picname ) { diff --git a/code/q3_ui/ui_main.c b/code/q3_ui/ui_main.c index 57933d48..9f681a50 100644 --- a/code/q3_ui/ui_main.c +++ b/code/q3_ui/ui_main.c @@ -30,7 +30,9 @@ USER INTERFACE MAIN #include "ui_local.h" +#include "../vr/vr_clientinfo.h" +vr_clientinfo_t *uiVR = NULL; /* ================ @@ -80,6 +82,13 @@ Q_EXPORT intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, i return 0; case UI_HASUNIQUECDKEY: // mod authors need to observe this return qtrue; // change this to qfalse for mods! + + case UI_SET_VR_CLIENT_INFO:{ + int ptr[2] = {arg0, arg1}; + uiVR = (vr_clientinfo_t *) (*(long*)(ptr)); + return 0; + } + } return -1; diff --git a/code/qcommon/q_math.c b/code/qcommon/q_math.c index 39382256..8e48545f 100644 --- a/code/qcommon/q_math.c +++ b/code/qcommon/q_math.c @@ -447,7 +447,7 @@ void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal ) inv_denom = DotProduct( normal, normal ); #ifndef Q3_VM - assert( Q_fabs(inv_denom) != 0.0f ); // zero vectors get here +// assert( Q_fabs(inv_denom) != 0.0f ); // zero vectors get here #endif inv_denom = 1.0f / inv_denom; diff --git a/code/renderergl2/tr_backend.c b/code/renderergl2/tr_backend.c index dc914555..fbd3f6c4 100644 --- a/code/renderergl2/tr_backend.c +++ b/code/renderergl2/tr_backend.c @@ -739,7 +739,7 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte * // FIXME: HUGE hack if (glRefConfig.framebufferObject) { - FBO_Bind(backEnd.framePostProcessed ? NULL : tr.renderFbo); + FBO_Bind(tr.renderFbo); } RB_SetGL2D(); diff --git a/code/ui/ui_public.h b/code/ui/ui_public.h index bcc72356..04563bce 100644 --- a/code/ui/ui_public.h +++ b/code/ui/ui_public.h @@ -182,10 +182,12 @@ typedef enum { UI_DRAW_CONNECT_SCREEN, // void UI_DrawConnectScreen( qboolean overlay ); - UI_HASUNIQUECDKEY + UI_HASUNIQUECDKEY, // if !overlay, the background will be drawn, otherwise it will be // overlayed over whatever the cgame has drawn. // a GetClientState syscall will be made to get the current strings + + UI_SET_VR_CLIENT_INFO } uiExport_t; #endif diff --git a/code/ui/ui_shared.c b/code/ui/ui_shared.c index 74bc77eb..c9d94984 100644 --- a/code/ui/ui_shared.c +++ b/code/ui/ui_shared.c @@ -23,12 +23,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // string allocation/management #include "ui_shared.h" +#include "../vr/vr_clientinfo.h" #define SCROLL_TIME_START 500 #define SCROLL_TIME_ADJUST 150 #define SCROLL_TIME_ADJUSTOFFSET 40 #define SCROLL_TIME_FLOOR 20 +extern vr_clientinfo_t *uiVR; + typedef struct scrollInfo_s { int nextScrollTime; int nextAdjustTime; @@ -3641,11 +3644,25 @@ qboolean Item_Bind_HandleKey(itemDef_t *item, int key, qboolean down) { void AdjustFrom640(float *x, float *y, float *w, float *h) { - //*x = *x * DC->scale + DC->bias; - *x *= DC->xscale; - *y *= DC->yscale; - *w *= DC->xscale; - *h *= DC->yscale; + + if (uiVR == NULL || uiVR->virtual_screen) { + // expect valid pointers + *x *= DC->xscale; + *y *= DC->yscale; + *w *= DC->xscale; + *h *= DC->yscale; + } else { + float screenXScale = DC->xscale / 2.75f; + float screenYScale = DC->yscale / 2.75f; + + *x *= screenXScale; + *y *= screenYScale; + *w *= screenXScale; + *h *= screenYScale; + + *x += (DC->glconfig.vidWidth - (640 * screenXScale)) / 2.0f; + *y += (DC->glconfig.vidHeight - (480 * screenYScale)) / 2.0f; + } } void Item_Model_Paint(itemDef_t *item) { diff --git a/code/vr/vr_base.c b/code/vr/vr_base.c index 3571189f..141ba59c 100644 --- a/code/vr/vr_base.c +++ b/code/vr/vr_base.c @@ -93,13 +93,13 @@ engine_t* VR_GetEngine( void ) { bool VR_useScreenLayer( void ) { //intermission is never full screen -/* if ( cl.snap.ps.pm_type == PM_INTERMISSION ) + if ( cl.snap.ps.pm_type == PM_INTERMISSION ) { return qfalse; } -*/ + int keyCatcher = Key_GetCatcher( ); - return (bool)( clc.state != CA_ACTIVE || + return (bool)( clc.state == CA_CINEMATIC || ( keyCatcher & (KEYCATCH_UI | KEYCATCH_CONSOLE) )); } //#endif diff --git a/code/vr/vr_input.c b/code/vr/vr_input.c index 800a309d..e2bcd8b6 100644 --- a/code/vr/vr_input.c +++ b/code/vr/vr_input.c @@ -5,6 +5,7 @@ #include "../qcommon/q_shared.h" #include "../qcommon/qcommon.h" #include "../client/keycodes.h" +#include "../client/client.h" #include "vr_base.h" #include "../VrApi/Include/VrApi_Input.h" #include "../VrApi/Include/VrApi_Helpers.h" @@ -253,7 +254,8 @@ static void IN_VRJoystick( qboolean isRightController, float joystickX, float jo { vrController_t* controller = isRightController == qtrue ? &rightController : &leftController; - if (vr.virtual_screen) + if (vr.virtual_screen || + cl.snap.ps.pm_type == PM_INTERMISSION) { const float x = joystickX * 5.0; const float y = joystickY * -5.0; @@ -342,7 +344,7 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons ) { vrController_t* controller = isRightController == qtrue ? &rightController : &leftController; - if (isRightController == qfalse) { + { if ((buttons & ovrButton_Enter) && !(controller->buttons & ovrButton_Enter)) { Com_QueueEvent(in_vrEventTime, SE_KEY, K_ESCAPE, qtrue, 0, NULL); } else if (!(buttons & ovrButton_Enter) && (controller->buttons & ovrButton_Enter)) { @@ -372,9 +374,7 @@ static void IN_VRButtonsChanged( qboolean isRightController, uint32_t buttons ) } if ((buttons & ovrButton_X) && !(controller->buttons & ovrButton_X)) { -#ifdef DEBUG sendButtonActionSimple("fraglimit 1"); -#endif Com_QueueEvent(in_vrEventTime, SE_KEY, K_PAD0_X, qtrue, 0, NULL); } else if (!(buttons & ovrButton_X) && (controller->buttons & ovrButton_X)) { Com_QueueEvent(in_vrEventTime, SE_KEY, K_PAD0_X, qfalse, 0, NULL);