Skip to content

Commit

Permalink
player move refactoring and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Chomenor committed Apr 1, 2022
1 parent 2543b2f commit 81d8e39
Show file tree
Hide file tree
Showing 17 changed files with 393 additions and 225 deletions.
1 change: 1 addition & 0 deletions build/qvm_build/build_game.bat
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ set src=game&set name=g_weapon&call :compile
set src=game\mods&set name=g_mod_main&call :compile
set src=game\mods&set name=g_mod_stubs&call :compile
set src=game\mods&set name=g_mod_utils&call :compile
set src=game\mods\features&set name=feature_player_move&call :compile
set src=common&set name=logging&call :compile
set src=common&set name=vm_extensions&call :compile

Expand Down
1 change: 1 addition & 0 deletions code/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@ typedef struct {
typedef struct {
// player movement
int pMoveFixed;
int pMoveTriggerMode;
qboolean noJumpKeySlowdown;
qboolean bounceFix;
int snapVectorGravLimit;
Expand Down
46 changes: 34 additions & 12 deletions code/cgame/cg_predict.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ void CG_FilterPredictableEvent( entity_event_t event, int eventParm, playerState

debounceTable[i].lastCommandTime = ps->commandTime;
debounceTable[i].lastClientTime = cg.time;

// Make sure predicted playerstate is up to date in case any event handling code accesses it
if ( !serverEvent ) {
cg.predictedPlayerState = *ps;
}

CG_ExecutePredictableEvent( event, eventParm );
return;
}
Expand Down Expand Up @@ -943,7 +949,7 @@ static void CG_FinalPredict( playerState_t *ps, usercmd_t *cmd ) {
temp.eventSequence = 0;

CG_InitPmove( &temp, cmd );
Pmove( &cg_pmove, 0 );
Pmove( &cg_pmove, 0, NULL, NULL );

ps->origin[0] = temp.origin[0];
ps->origin[1] = temp.origin[1];
Expand All @@ -955,6 +961,31 @@ static void CG_FinalPredict( playerState_t *ps, usercmd_t *cmd ) {
ps->bobCycle = temp.bobCycle;
}

/*
=================
CG_PostPmove
=================
*/
static void CG_PostPmove( pmove_t *pmove, qboolean finalFragment, void *context) {
predictionFrame_t *frame = (predictionFrame_t *)context;
if ( finalFragment || cgs.modConfig.pMoveTriggerMode ) {
int i;

CG_TouchTriggerPrediction( &frame->ps, &frame->predictedTeleport );

// Note that running events here means that CG_FilterPredictableEvent won't be called for cached
// frames. This should be fine since cached frames should only contain duplicate events that would
// filtered anyway, but it might have implications for testing/debug purposes.
for ( i = frame->ps.eventSequence - MAX_PS_EVENTS; i < frame->ps.eventSequence; ++i ) {
if ( i >= 0 ) {
CG_FilterPredictableEvent( frame->ps.events[ i & (MAX_PS_EVENTS-1) ],
frame->ps.eventParms[ i & (MAX_PS_EVENTS-1) ], &frame->ps, qfalse );
}
}
frame->ps.eventSequence = 0;
}
}

/*
=================
CG_PredictPlayerState
Expand All @@ -978,7 +1009,6 @@ to ease the jerk.
=================
*/
void CG_PredictPlayerState( void ) {
int i;
snapshot_t *snap = PREDICTION_SNAPSHOT;
playerState_t oldPlayerState;
usercmd_t *latestCmd;
Expand Down Expand Up @@ -1125,24 +1155,16 @@ void CG_PredictPlayerState( void ) {

// perform the move
CG_InitPmove( &frame->ps, cmd );
Pmove( &cg_pmove, cgs.modConfig.pMoveFixed );
CG_TouchTriggerPrediction( &frame->ps, &frame->predictedTeleport );
Pmove( &cg_pmove, cgs.modConfig.pMoveFixed, CG_PostPmove, frame );
CG_PatchWeaponAutoswitch( &frame->ps );

predictCache.latest = frameNum;
}

// check for predicted events...
// check for predicted teleport...
if ( frame->predictedTeleport ) {
cg.hyperspace = qtrue;
}

for ( i = frame->ps.eventSequence - MAX_PS_EVENTS; i < frame->ps.eventSequence; ++i ) {
if ( i >= 0 ) {
CG_FilterPredictableEvent( frame->ps.events[ i & (MAX_PS_EVENTS-1) ],
frame->ps.eventParms[ i & (MAX_PS_EVENTS-1) ], &frame->ps, qfalse );
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions code/cgame/cg_servercmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ void CG_ParseModConfig( void ) {
break;
if ( !Q_stricmp( key, "pMoveFixed" ) )
cgs.modConfig.pMoveFixed = atoi( value );
if ( !Q_stricmp( key, "pMoveTriggerMode" ) )
cgs.modConfig.pMoveTriggerMode = atoi( value );
if ( !Q_stricmp( key, "noJumpKeySlowdown" ) )
cgs.modConfig.noJumpKeySlowdown = atoi( value ) ? qtrue : qfalse;
if ( !Q_stricmp( key, "bounceFix" ) )
Expand Down
8 changes: 7 additions & 1 deletion code/common/bg_pmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,8 @@ Pmove
Can be called by either the server or the client
================
*/
void Pmove( pmove_t *pmove, int pMoveFixed ) {
void Pmove( pmove_t *pmove, int pMoveFixed,
void ( *postMove )( pmove_t *pmove, qboolean finalFragment, void *context ), void *postMoveContext ) {
usercmd_t inputCmd = pmove->cmd;

if ( inputCmd.serverTime > pmove->ps->commandTime + 1000 ) {
Expand All @@ -2350,5 +2351,10 @@ void Pmove( pmove_t *pmove, int pMoveFixed ) {

// reset any changes to command during move
pmove->cmd = inputCmd;

if ( postMove ) {
qboolean finalFragment = !PM_IsMoveNeeded( pmove->ps->commandTime,inputCmd.serverTime, pMoveFixed );
postMove( pmove, finalFragment, postMoveContext );
}
}
}
3 changes: 2 additions & 1 deletion code/common/bg_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ typedef struct {
void PM_UpdateViewAngles( playerState_t *ps, const usercmd_t *cmd );
int PM_NextMoveTime( int currentTime, int targetTime, int pMoveFixed );
qboolean PM_IsMoveNeeded( int currentTime, int targetTime, int pMoveFixed );
void Pmove( pmove_t *pmove, int pMoveFixed );
void Pmove( pmove_t *pmove, int pMoveFixed,
void ( *postMove )( pmove_t *pmove, qboolean finalFragment, void *context ), void *postMoveContext );

//===================================================================================

Expand Down
Loading

0 comments on commit 81d8e39

Please sign in to comment.