From 52b6370103efe81e720b20324ccaae04fb6ee6cc Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 26 Sep 2020 11:30:46 +0100 Subject: [PATCH] Draw PDA to HUD Looks cool --- Projects/Android/AndroidManifest.xml | 4 +- .../jni/Doom3Quest/Doom3Quest_SurfaceView.c | 19 +++++++- .../neo/game/Player.cpp | 44 +++++++++++-------- .../neo/game/PlayerView.cpp | 28 +++++------- .../neo/game/Weapon.cpp | 4 +- .../neo/game/gamesys/SysCvar.cpp | 1 + .../neo/game/gamesys/SysCvar.h | 1 + 7 files changed, 59 insertions(+), 42 deletions(-) diff --git a/Projects/Android/AndroidManifest.xml b/Projects/Android/AndroidManifest.xml index eb1d0b9..484542f 100644 --- a/Projects/Android/AndroidManifest.xml +++ b/Projects/Android/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="12" + android:versionName="0.0.18" android:installLocation="auto" > diff --git a/Projects/Android/jni/Doom3Quest/Doom3Quest_SurfaceView.c b/Projects/Android/jni/Doom3Quest/Doom3Quest_SurfaceView.c index f64d089..1845187 100644 --- a/Projects/Android/jni/Doom3Quest/Doom3Quest_SurfaceView.c +++ b/Projects/Android/jni/Doom3Quest/Doom3Quest_SurfaceView.c @@ -152,7 +152,7 @@ void Doom3Quest_setUseScreenLayer(int screen) bool Doom3Quest_useScreenLayer() { - return inMenu || objectiveSystemActive || inCinematic || forceVirtualScreen; + return inMenu || inCinematic || forceVirtualScreen; } static void UnEscapeQuotes( char *arg ) @@ -999,7 +999,10 @@ static void ovrApp_HandleVrModeChanges( ovrApp * app ) vrapi_SetPerfThread( app->Ovr, VRAPI_PERF_THREAD_TYPE_RENDERER, app->RenderThreadTid ); ALOGV( " vrapi_SetPerfThread( RENDERER, %d )", app->RenderThreadTid ); + + vrapi_SetExtraLatencyMode(app->Ovr, VRAPI_EXTRA_LATENCY_MODE_ON); } + } } else @@ -1263,8 +1266,12 @@ void VR_Init() shutdown = false; } +long renderThreadCPUTime[2] = {0, 0}; + void Doom3Quest_prepareEyeBuffer(int eye ) { + renderThreadCPUTime[eye] = GetTimeInMilliSeconds(); + ovrRenderer *renderer = Doom3Quest_useScreenLayer() ? &gAppState.Scene.CylinderRenderer : &gAppState.Renderer; ovrFramebuffer *frameBuffer = &(renderer->FrameBuffer[eye]); @@ -1286,6 +1293,16 @@ void Doom3Quest_prepareEyeBuffer(int eye ) void Doom3Quest_finishEyeBuffer(int eye ) { + renderThreadCPUTime[eye] = GetTimeInMilliSeconds() - renderThreadCPUTime[eye]; + + if (eye == 1) + { + int totalTime = renderThreadCPUTime[0] + renderThreadCPUTime[1]; + //__android_log_print(ANDROID_LOG_INFO, "Doom3Quest", "RENDER THREAD LEFT EYE CPU TIME: %i", renderThreadCPUTime[0]); + //__android_log_print(ANDROID_LOG_INFO, "Doom3Quest", "RENDER THREAD RIGHT EYE CPU TIME: %i", renderThreadCPUTime[1]); + __android_log_print(ANDROID_LOG_INFO, "Doom3Quest", "RENDER THREAD TOTAL CPU TIME: %i", totalTime); + } + GLCheckErrors( __LINE__ ); ovrRenderer *renderer = Doom3Quest_useScreenLayer() ? &gAppState.Scene.CylinderRenderer : &gAppState.Renderer; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/game/Player.cpp b/Projects/Android/jni/d3es-multithread-master/neo/game/Player.cpp index a817ad2..f6d66e3 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/game/Player.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/game/Player.cpp @@ -2703,8 +2703,6 @@ void idPlayer::DrawHUD( idUserInterface *_hud ) { //cursor->Redraw( gameLocal.realClientTime ); } } - - renderSystem->CaptureRenderToImage( "_hudImage" ); } @@ -2718,7 +2716,6 @@ void idPlayer::UpdateVrHud() { static idVec3 hudOrigin; static idMat3 hudAxis; - float hudPitch; if (pVRClientInfo != nullptr) @@ -2733,9 +2730,8 @@ void idPlayer::UpdateVrHud() hudEntity.allowSurfaceInViewID = entityNumber + 1; { - hudPitch = 10.0f; - float yaw; + if (vr_hudmode.GetInteger() == 0) { // CalculateRenderView must have been called first const idVec3 &viewOrigin = firstPersonViewOrigin; @@ -2743,8 +2739,9 @@ void idPlayer::UpdateVrHud() if (pVRClientInfo) { + float yaw; idAngles angles; - float *pAngles = pVRClientInfo->offhandangles; + angles.pitch = pVRClientInfo->offhandangles[PITCH]; angles.yaw = viewAngles.yaw + (pVRClientInfo->offhandangles[YAW] - pVRClientInfo->hmdorientation[YAW]); @@ -2758,25 +2755,31 @@ void idPlayer::UpdateVrHud() idAngles a(0, viewAngles.yaw - pVRClientInfo->hmdorientation[YAW], 0); offpos *= a.ToMat3(); - offpos *= cvarSystem->GetCVarFloat( "vr_worldscale" ); + offpos *= vr_worldscale.GetFloat(); { hudOrigin = viewOrigin + offpos; } } - -// GetViewPos( hudOrigin, hudAxis ); -// yaw = viewAngles.yaw; + hudOrigin += hudAxis[2] * 16.0f; + hudOrigin += hudAxis[1] * -8.5f; + hudAxis *= 0.7; // scale } - //hudAxis = idAngles( hudPitch, yaw, 0.0f ).ToMat3(); + else { + //Fixed HUD, but make it take a short time to catch up with the player's yaw + static float yaw_x = 0.0f; + static float yaw_y = 1.0f; + yaw_x = 0.97f * yaw_x + 0.03f * cosf(DEG2RAD(viewAngles.yaw)); + yaw_y = 0.97f * yaw_y + 0.03f * sinf(DEG2RAD(viewAngles.yaw)); - //hudOrigin += hudAxis[0] * 24.0f;//vr_hudPosDis.GetFloat(); - hudOrigin += hudAxis[1] * -8.0f; - hudOrigin += hudAxis[2] * 16.0f; + GetViewPos( hudOrigin, hudAxis ); + hudAxis = idAngles( 10.0f, RAD2DEG(atan2(yaw_y, yaw_x)), 0.0f ).ToMat3(); + hudOrigin += hudAxis[0] * 24.0f; + hudOrigin.z += 4.0f; + hudOrigin += hudAxis[1] * -8.5f; + } } - hudAxis *= 0.7; - hudEntity.axis = hudAxis; hudEntity.origin = hudOrigin; hudEntity.weaponDepthHack = true; @@ -5046,7 +5049,7 @@ void idPlayer::UpdateViewAngles( void ) { int i; idAngles delta; - if ( !noclip && ( gameLocal.inCinematic || privateCameraView || gameLocal.GetCamera() || influenceActive == INFLUENCE_LEVEL2 || objectiveSystemOpen ) ) { + if ( !noclip && ( gameLocal.inCinematic || privateCameraView || gameLocal.GetCamera() || influenceActive == INFLUENCE_LEVEL2 /*|| objectiveSystemOpen*/ ) ) { // no view changes at all, but we still want to update the deltas or else when // we get out of this mode, our view will snap to a kind of random angle UpdateDeltaViewAngles( viewAngles ); @@ -7515,7 +7518,10 @@ void idPlayer::CalculateViewWeaponPos( bool pointer, idVec3 &origin, idMat3 &axi ///HACK if (currentWeapon == weapon_pda) { - idVec3 pdaOffs( 30, -7, -14 ); + //idVec3 pdaOffs( 30, -7, -14 ); + + //Put it behind us + idVec3 pdaOffs( -30, -7, -14 ); origin += pdaOffs * viewAxis; } @@ -7648,7 +7654,7 @@ idVec3 idPlayer::GetEyePosition( void ) const { if (pVRClientInfo) { float eyeHeight = 0; - float vrEyeHeight = (-(pVRClientInfo->hmdposition[1] + cvarSystem->GetCVarFloat( "vr_heightoffset" )) * cvarSystem->GetCVarFloat( "vr_worldscale" )); + float vrEyeHeight = (-(pVRClientInfo->hmdposition[1] + vr_heightoffset.GetFloat()) * vr_worldscale.GetFloat()); //Add special handling for physical crouching at some point /* if (physicsObj.IsCrouching() && PHYSICAL_CROUCH) { diff --git a/Projects/Android/jni/d3es-multithread-master/neo/game/PlayerView.cpp b/Projects/Android/jni/d3es-multithread-master/neo/game/PlayerView.cpp index 5b07172..0b18836 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/game/PlayerView.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/game/PlayerView.cpp @@ -462,16 +462,16 @@ void idPlayerView::SingleView( idUserInterface *hud, const renderView_t *view ) return; } - player->DrawHUD(hud); + if ( player->objectiveSystemOpen ) { + player->objectiveSystem->Redraw( gameLocal.time ); + } else { + player->DrawHUD(hud); + } - // place the sound origin for the player - gameSoundWorld->PlaceListener( view->vieworg, view->viewaxis, player->entityNumber + 1, gameLocal.time, hud ? hud->State().GetString( "location" ) : "Undefined" ); + renderSystem->CaptureRenderToImage( "_hudImage" ); - // if the objective system is up, don't do normal drawing - if ( player->objectiveSystemOpen ) { - player->objectiveSystem->Redraw( gameLocal.time ); - return; - } + // place the sound origin for the player + gameSoundWorld->PlaceListener( view->vieworg, view->viewaxis, player->entityNumber + 1, gameLocal.time, hud ? hud->State().GetString( "location" ) : "Undefined" ); // hack the shake in at the very last moment, so it can't cause any consistency problems renderView_t hackedView = *view; @@ -733,16 +733,8 @@ void idPlayerView::RenderPlayerView( idUserInterface *hud ) { if (eyeView && !game->InCinematic()) { - int eye = cvarSystem->GetCVarInteger("vr_eye"); - if (eye == 0) // left eye - { - eyeView->vieworg += eyeView->viewaxis[1] * - (cvarSystem->GetCVarFloat( "vr_ipd" ) / 2.0f) * cvarSystem->GetCVarFloat( "vr_worldscale" ); - } else if (eye == 1) // right eye - { - eyeView->vieworg -= eyeView->viewaxis[1] * - (cvarSystem->GetCVarFloat( "vr_ipd" ) / 2.0f) * cvarSystem->GetCVarFloat( "vr_worldscale" ); - } + eyeView->vieworg += (vr_eye.GetInteger() == 0 ? 1.0f : -1.0f) * eyeView->viewaxis[1] * + (vr_ipd.GetFloat() / 2.0f) * vr_worldscale.GetFloat(); } if (g_skipViewEffects.GetBool()) { diff --git a/Projects/Android/jni/d3es-multithread-master/neo/game/Weapon.cpp b/Projects/Android/jni/d3es-multithread-master/neo/game/Weapon.cpp index 099b568..9549f01 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/game/Weapon.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/game/Weapon.cpp @@ -2950,7 +2950,7 @@ void idWeapon::Event_LaunchProjectiles( int num_projectiles, float spread, float vrClientInfo *pVRClientInfo = owner->GetVRClientInfo(); if (owner->GetCurrentWeapon() == WEAPON_GREANDE && pVRClientInfo != nullptr && - cvarSystem->GetCVarBool("vr_throwables")) + vr_throwables.GetBool()) { idVec3 releaseOffset( -pVRClientInfo->throw_origin[2], -pVRClientInfo->throw_origin[0], @@ -3000,7 +3000,7 @@ void idWeapon::Event_LaunchProjectiles( int num_projectiles, float spread, float projBounds = proj->GetPhysics()->GetBounds().Rotate( proj->GetPhysics()->GetAxis() ); if (owner->GetCurrentWeapon() != WEAPON_GREANDE || - !cvarSystem->GetCVarBool("vr_throwables")) { + !vr_throwables.GetBool()) { // make sure the projectile starts inside the bounding box of the owner if (i == 0) { //muzzle_pos = muzzleOrigin + playerViewAxis[ 0 ] * 2.0f; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.cpp b/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.cpp index 50d7832..06d1c74 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.cpp @@ -349,4 +349,5 @@ idCVar vr_weaponsight( "vr_weaponsight", "0", CVAR_BOOL | CVAR_ARCHIVE, "We idCVar vr_throwables( "vr_throwables", "1", CVAR_BOOL | CVAR_ARCHIVE, "Throwable Grenades.\n 0 = Disable\n 1 = Throw and release with trigger" ); idCVar vr_turnmode( "vr_turnmode", "0", CVAR_BOOL | CVAR_ARCHIVE, "Turn Mode.\n 0 = Snap Turn\n 1 = Smooth Turn" ); idCVar vr_turnangle( "vr_turnangle", "45", CVAR_INTEGER | CVAR_ARCHIVE, "Turn Angle. angle for snap, or velocity for smooth" ); +idCVar vr_hudmode( "vr_hudmode", "0", CVAR_BOOL | CVAR_ARCHIVE, "HUD Mode.\n 1 = Attached to off-hand controller\n 0 = Fixed" ); diff --git a/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.h b/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.h index 02d9e53..1dde8cb 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.h +++ b/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.h @@ -263,6 +263,7 @@ extern idCVar vr_weaponsight; extern idCVar vr_throwables; extern idCVar vr_turnmode; extern idCVar vr_turnangle; +extern idCVar vr_hudmode; extern const char *si_gameTypeArgs[];