Skip to content

Commit

Permalink
Allow headset to dictate refresh rate for game
Browse files Browse the repository at this point in the history
  • Loading branch information
DrBeef committed Oct 16, 2020
1 parent 01b67f3 commit 70c4e81
Show file tree
Hide file tree
Showing 25 changed files with 127 additions and 99 deletions.
16 changes: 11 additions & 5 deletions Projects/Android/jni/Doom3Quest/Doom3Quest_SurfaceView.c
Expand Up @@ -1051,13 +1051,16 @@ static bool destroyed = false;

float Doom3Quest_GetFOV()
{
if (vrFOV == 0.0f) {
vrFOV = vrapi_GetSystemPropertyInt(&gAppState.Java, VRAPI_SYS_PROP_SUGGESTED_EYE_FOV_DEGREES_X);
}
vrFOV = vrapi_GetSystemPropertyInt(&gAppState.Java, VRAPI_SYS_PROP_SUGGESTED_EYE_FOV_DEGREES_X);

return vrFOV;
}

int Doom3Quest_GetRefresh()
{
return Doom3Quest_initialised ? vrapi_GetSystemPropertyInt(&gAppState.Java, VRAPI_SYS_PROP_DISPLAY_REFRESH_RATE) : 60;
}

static void ovrApp_HandleVrModeChanges( ovrApp * app )
{
if ( app->Resumed != false && app->NativeWindow != NULL )
Expand Down Expand Up @@ -1585,8 +1588,11 @@ void * AppThreadFunction(void * parm ) {
// Create the scene if not yet created.
ovrScene_Create( m_width, m_height, &gAppState.Scene, &java );

//Set the screen refresh
vrapi_SetDisplayRefreshRate(gAppState.Ovr, DISPLAY_REFRESH);
//Set the screen refresh - only for Quest 1
bool quest1 = false;
if (quest1) {
vrapi_SetDisplayRefreshRate(gAppState.Ovr, DISPLAY_REFRESH);
}

//Run loading loop until we are ready to start QzDoom
while (!destroyed && !Doom3Quest_initialised) {
Expand Down
2 changes: 2 additions & 0 deletions Projects/Android/jni/Doom3Quest/VrCommon.h
Expand Up @@ -66,6 +66,8 @@ void controlMouse(ovrInputStateTrackedRemote *newState, ovrInputStateTrackedRemo


//Called from engine code
int Doom3Quest_GetRefresh();

bool Doom3Quest_useScreenLayer();

void Doom3Quest_GetScreenRes(int *width, int *height);
Expand Down
3 changes: 1 addition & 2 deletions Projects/Android/jni/Doom3Quest/VrInputDefault.c
Expand Up @@ -59,7 +59,6 @@ extern bool inMenu;
extern bool inGameGuiActive;
extern bool objectiveSystemActive;
extern bool inCinematic;
const int USERCMD_HZ = 60;


void HandleInput_Default( int controlscheme, ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking,
Expand Down Expand Up @@ -379,7 +378,7 @@ void HandleInput_Default( int controlscheme, ovrInputStateTrackedRemote *pDomina
//approximately even out the positional movement on a per frame basis (especially when fps is much lower than 60)
static float lastSampleTime = 0;
float sampleTime = Sys_Milliseconds();
float vr_positional_factor = 2400.0f * ((1000.0f / USERCMD_HZ) / (sampleTime-lastSampleTime));
float vr_positional_factor = 2400.0f * ((1000.0f / (float)Doom3Quest_GetRefresh()) / (sampleTime-lastSampleTime));
lastSampleTime = sampleTime;

//This section corrects for the fact that the controller actually controls direction of movement, but we want to move relative to the direction the
Expand Down
Expand Up @@ -35,6 +35,8 @@ If you have questions concerning this license or the applicable additional terms

#include "framework/UsercmdGen.h"

#include "renderer/RenderSystem.h"

/*
================
usercmd_t::ByteSwap
Expand Down
Expand Up @@ -37,8 +37,10 @@ If you have questions concerning this license or the applicable additional terms
===============================================================================
*/

const int USERCMD_HZ = 60;
const int USERCMD_MSEC = 1000 / USERCMD_HZ;
//const int USERCMD_HZ = 60;
//const int USERCMD_MSEC = 1000 / USERCMD_HZ;

#define USERCMD_MSEC (1000 / (renderSystem ? renderSystem->GetRefresh() : 60))

// usercmd_t->button bits
const int BUTTON_ATTACK = BIT(0);
Expand Down
Expand Up @@ -1860,7 +1860,7 @@ void idAFEntity_VehicleSimple::Think( void ) {

origin = suspension[i]->GetWheelOrigin();
velocity = body->GetPointVelocity( origin ) * body->GetWorldAxis()[0];
wheelAngles[i] += velocity * MS2SEC( gameLocal.msec ) / wheelRadius;
wheelAngles[i] += velocity * MS2SEC( USERCMD_MSEC ) / wheelRadius;

// additional rotation about the wheel axis
wheelRotation.SetAngle( RAD2DEG( wheelAngles[i] ) );
Expand Down Expand Up @@ -2052,7 +2052,7 @@ void idAFEntity_VehicleFourWheels::Think( void ) {
if ( force == 0.0f ) {
velocity = wheels[i]->GetLinearVelocity() * wheels[i]->GetWorldAxis()[0];
}
wheelAngles[i] += velocity * MS2SEC( gameLocal.msec ) / wheelRadius;
wheelAngles[i] += velocity * MS2SEC( USERCMD_MSEC ) / wheelRadius;
// give the wheel joint an additional rotation about the wheel axis
rotation.SetAngle( RAD2DEG( wheelAngles[i] ) );
axis = af.GetPhysics()->GetAxis( 0 );
Expand Down Expand Up @@ -2242,7 +2242,7 @@ void idAFEntity_VehicleSixWheels::Think( void ) {
if ( force == 0.0f ) {
velocity = wheels[i]->GetLinearVelocity() * wheels[i]->GetWorldAxis()[0];
}
wheelAngles[i] += velocity * MS2SEC( gameLocal.msec ) / wheelRadius;
wheelAngles[i] += velocity * MS2SEC( USERCMD_MSEC ) / wheelRadius;
// give the wheel joint an additional rotation about the wheel axis
rotation.SetAngle( RAD2DEG( wheelAngles[i] ) );
axis = af.GetPhysics()->GetAxis( 0 );
Expand Down
12 changes: 6 additions & 6 deletions Projects/Android/jni/d3es-multithread-master/neo/game/Camera.cpp
Expand Up @@ -514,9 +514,9 @@ void idCameraAnim::Think( void ) {
return;
}

if ( frameRate == USERCMD_HZ ) {
if ( frameRate == renderSystem->GetRefresh() ) {
frameTime = gameLocal.time - starttime;
frame = frameTime / gameLocal.msec;
frame = frameTime / USERCMD_MSEC;
} else {
frameTime = ( gameLocal.time - starttime ) * frameRate;
frame = frameTime / 1000;
Expand Down Expand Up @@ -564,9 +564,9 @@ void idCameraAnim::GetViewParms( renderView_t *view ) {
return;
}

if ( frameRate == USERCMD_HZ ) {
if ( frameRate == renderSystem->GetRefresh() ) {
frameTime = gameLocal.time - starttime;
frame = frameTime / gameLocal.msec;
frame = frameTime / USERCMD_MSEC;
lerp = 0.0f;
} else {
frameTime = ( gameLocal.time - starttime ) * frameRate;
Expand All @@ -586,7 +586,7 @@ void idCameraAnim::GetViewParms( renderView_t *view ) {
}

if ( g_debugCinematic.GetBool() ) {
int prevFrameTime = ( gameLocal.time - starttime - gameLocal.msec ) * frameRate;
int prevFrameTime = ( gameLocal.time - starttime - USERCMD_MSEC ) * frameRate;
int prevFrame = prevFrameTime / 1000;
int prevCut;

Expand Down Expand Up @@ -659,7 +659,7 @@ void idCameraAnim::GetViewParms( renderView_t *view ) {
static int lastFrame = 0;
static idVec3 lastFrameVec( 0.0f, 0.0f, 0.0f );
if ( gameLocal.time != lastFrame ) {
gameRenderWorld->DebugBounds( colorCyan, idBounds( view->vieworg ).Expand( 16.0f ), vec3_origin, gameLocal.msec );
gameRenderWorld->DebugBounds( colorCyan, idBounds( view->vieworg ).Expand( 16.0f ), vec3_origin, USERCMD_MSEC );
gameRenderWorld->DebugLine( colorRed, view->vieworg, view->vieworg + idVec3( 0.0f, 0.0f, 2.0f ), 10000, false );
gameRenderWorld->DebugLine( colorCyan, lastFrameVec, view->vieworg, 10000, false );
gameRenderWorld->DebugLine( colorYellow, view->vieworg + view->viewaxis[ 0 ] * 64.0f, view->vieworg + view->viewaxis[ 0 ] * 66.0f, 10000, false );
Expand Down
Expand Up @@ -481,7 +481,7 @@ void idEntity::Spawn( void ) {
renderEntity.entityNum = entityNumber;

// go dormant within 5 frames so that when the map starts most monsters are dormant
dormantStart = gameLocal.time - DELAY_DORMANT_TIME + gameLocal.msec * 5;
dormantStart = gameLocal.time - DELAY_DORMANT_TIME + USERCMD_MSEC * 5;

origin = renderEntity.origin;
axis = renderEntity.axis;
Expand Down
Expand Up @@ -2218,7 +2218,7 @@ gameReturn_t idGameLocal::RunFrame( const usercmd_t *clientCmds ) {
// update the game time
framenum++;
previousTime = time;
time += msec;
time += USERCMD_MSEC;
realClientTime = time;

#ifdef GAME_DLL
Expand Down Expand Up @@ -3553,7 +3553,7 @@ idGameLocal::AlertAI
void idGameLocal::AlertAI( idEntity *ent ) {
if ( ent && ent->IsType( idActor::Type ) ) {
// alert them for the next frame
lastAIAlertTime = time + msec;
lastAIAlertTime = time + USERCMD_MSEC;
lastAIAlertEntity = static_cast<idActor *>( ent );
}
}
Expand Down Expand Up @@ -3958,7 +3958,7 @@ void idGameLocal::SetCamera( idCamera *cam ) {

} else {
inCinematic = false;
cinematicStopTime = time + msec;
cinematicStopTime = time + USERCMD_MSEC;

// restore r_znear
cvarSystem->SetCVarFloat( "r_znear", 3.0f );
Expand Down
Expand Up @@ -274,7 +274,7 @@ class idGameLocal : public idGame {
int framenum;
int previousTime; // time in msec of last frame
int time; // in msec
static const int msec = USERCMD_MSEC; // time since last update in milliseconds
// static const int msec = USERCMD_MSEC; // time since last update in milliseconds

int vacuumAreaNum; // -1 if level doesn't have any outside areas

Expand Down Expand Up @@ -426,7 +426,7 @@ class idGameLocal : public idGame {
// added the following to assist licensees with merge issues
int GetFrameNum() const { return framenum; };
int GetTime() const { return time; };
int GetMSec() const { return msec; };
int GetMSec() const { return USERCMD_MSEC; };

int GetNextClientNum( int current ) const;
idPlayer * GetClientByNum( int current ) const;
Expand Down
Expand Up @@ -994,7 +994,7 @@ void idGameLocal::ClientReadSnapshot( int clientNum, int sequence, const int gam
// update the game time
framenum = gameFrame;
time = gameTime;
previousTime = time - msec;
previousTime = time - USERCMD_MSEC;

// so that StartSound/StopSound doesn't risk skipping
isNewFrame = true;
Expand Down Expand Up @@ -1492,7 +1492,7 @@ gameReturn_t idGameLocal::ClientPrediction( int clientNum, const usercmd_t *clie
// update the game time
framenum++;
previousTime = time;
time += msec;
time += USERCMD_MSEC;

// update the real client time and the new frame flag
if ( time > realClientTime ) {
Expand Down
Expand Up @@ -392,14 +392,14 @@ bool idMoveable::FollowInitialSplinePath( void ) {
if ( initialSpline != NULL ) {
if ( gameLocal.time < initialSpline->GetTime( initialSpline->GetNumValues() - 1 ) ) {
idVec3 splinePos = initialSpline->GetCurrentValue( gameLocal.time );
idVec3 linearVelocity = ( splinePos - physicsObj.GetOrigin() ) * USERCMD_HZ;
idVec3 linearVelocity = ( splinePos - physicsObj.GetOrigin() ) * renderSystem->GetRefresh();
physicsObj.SetLinearVelocity( linearVelocity );

idVec3 splineDir = initialSpline->GetCurrentFirstDerivative( gameLocal.time );
idVec3 dir = initialSplineDir * physicsObj.GetAxis();
idVec3 angularVelocity = dir.Cross( splineDir );
angularVelocity.Normalize();
angularVelocity *= idMath::ACos16( dir * splineDir / splineDir.Length() ) * USERCMD_HZ;
angularVelocity *= idMath::ACos16( dir * splineDir / splineDir.Length() ) * renderSystem->GetRefresh();
physicsObj.SetAngularVelocity( angularVelocity );
return true;
} else {
Expand Down
Expand Up @@ -4930,7 +4930,7 @@ void idPlayer::BobCycle( const idVec3 &pushVelocity ) {
// check for footstep / splash sounds
old = bobCycle;
bobCycle = (int)( old + bobmove * gameLocal.msec ) & 255;
bobCycle = (int)( old + bobmove * USERCMD_MSEC ) & 255;
bobFoot = ( bobCycle & 128 ) >> 7;
bobfracsin = idMath::Fabs( sin( ( bobCycle & 127 ) / 127.0 * idMath::PI ) );
}*/
Expand Down Expand Up @@ -5883,7 +5883,7 @@ void idPlayer::AdjustSpeed( void ) {
bobFrac = 0.0f;
} else if ( !physicsObj.OnLadder() && ( usercmd.buttons & BUTTON_RUN ) && ( usercmd.forwardmove || usercmd.rightmove ) && ( usercmd.upmove >= 0 ) ) {
if ( !gameLocal.isMultiplayer && !physicsObj.IsCrouching() && !PowerUpActive( ADRENALINE ) ) {
stamina -= MS2SEC( gameLocal.msec );
stamina -= MS2SEC( USERCMD_MSEC );
}
if ( stamina < 0 ) {
stamina = 0;
Expand All @@ -5904,7 +5904,7 @@ void idPlayer::AdjustSpeed( void ) {
rate *= 1.25f;
}

stamina += rate * MS2SEC( gameLocal.msec );
stamina += rate * MS2SEC( USERCMD_MSEC );
if ( stamina > pm_stamina.GetFloat() ) {
stamina = pm_stamina.GetFloat();
}
Expand Down
Expand Up @@ -1430,7 +1430,7 @@ void idGuidedProjectile::Launch( const idVec3 &start, const idVec3 &dir, const i
angles = vel.ToAngles();
speed = vel.Length();
rndScale = spawnArgs.GetAngles( "random", "15 15 0" );
turn_max = spawnArgs.GetFloat( "turn_max", "180" ) / ( float )USERCMD_HZ;
turn_max = spawnArgs.GetFloat( "turn_max", "180" ) / ( float )(renderSystem->GetRefresh());
clamp_dist = spawnArgs.GetFloat( "clamp_dist", "256" );
burstMode = spawnArgs.GetBool( "burstMode" );
unGuided = false;
Expand Down
Expand Up @@ -1330,7 +1330,7 @@ void idTarget_SetFov::Event_Activate( idEntity *activator ) {
cinematic = true;

idPlayer *player = gameLocal.GetLocalPlayer();
fovSetting.Init( gameLocal.time, SEC2MS( spawnArgs.GetFloat( "time" ) ), player ? player->DefaultFov() : g_fov.GetFloat(), spawnArgs.GetFloat( "fov" ) );
fovSetting.Init( gameLocal.time, SEC2MS( spawnArgs.GetFloat( "time" ) ), player ? player->DefaultFov() : renderSystem->GetFOV(), spawnArgs.GetFloat( "fov" ) );
BecomeActive( TH_THINK );
}

Expand Down

0 comments on commit 70c4e81

Please sign in to comment.