From eb02e3b5edf9601cf43e2001f963b2e984f18bf4 Mon Sep 17 00:00:00 2001 From: Shpoike Date: Tue, 19 Jul 2022 22:36:57 +0100 Subject: [PATCH] Fixes https://github.com/Shpoike/Quakespasm/issues/107 --- Quake/gl_screen.c | 2 +- Quake/host.c | 8 ++++---- Quake/progs.h | 1 + Quake/sbar.c | 4 ++-- Quake/server.h | 2 +- Quake/sv_main.c | 4 ++-- Quake/sv_phys.c | 39 +++++++++++++++++++++------------------ 7 files changed, 32 insertions(+), 28 deletions(-) diff --git a/Quake/gl_screen.c b/Quake/gl_screen.c index d38c306f..4be999a4 100644 --- a/Quake/gl_screen.c +++ b/Quake/gl_screen.c @@ -1184,7 +1184,7 @@ void SCR_UpdateScreen (void) // Sbar_SortFrags (); pr_global_struct->time = qcvm->time; - pr_global_struct->frametime = host_frametime; + pr_global_struct->frametime = qcvm->frametime; G_FLOAT(OFS_PARM0) = glwidth/s; G_FLOAT(OFS_PARM1) = glheight/s; G_FLOAT(OFS_PARM2) = true; diff --git a/Quake/host.c b/Quake/host.c index cc8b63e0..5d82242a 100644 --- a/Quake/host.c +++ b/Quake/host.c @@ -714,7 +714,7 @@ void Host_ServerFrame (void) // move things around and think // always pause in single player if in console or menus if (!sv.paused && (svs.maxclients > 1 || key_dest == key_game) ) - SV_Physics (); + SV_Physics (host_frametime); //johnfitz -- devstats if (cls.signon == SIGNONS) @@ -803,7 +803,7 @@ static void CL_LoadCSProgs(void) //set a few globals, if they exist if (qcvm->extglobals.maxclients) *qcvm->extglobals.maxclients = cl.maxclients; - pr_global_struct->time = cl.time; + pr_global_struct->time = qcvm->time = cl.time; pr_global_struct->mapname = PR_SetEngineString(cl.mapname); pr_global_struct->total_monsters = cl.statsf[STAT_TOTALMONSTERS]; pr_global_struct->total_secrets = cl.statsf[STAT_TOTALSECRETS]; @@ -934,8 +934,8 @@ void _Host_Frame (double time) if (cl.qcvm.progs) { PR_SwitchQCVM(&cl.qcvm); - pr_global_struct->frametime = host_frametime; - SV_Physics(); + SV_Physics(cl.time - qcvm->time); + pr_global_struct->time = cl.time; PR_SwitchQCVM(NULL); } diff --git a/Quake/progs.h b/Quake/progs.h index f64a86d0..b5192153 100644 --- a/Quake/progs.h +++ b/Quake/progs.h @@ -403,6 +403,7 @@ struct qcvm_s //originally part of the sv_state_t struct //FIXME: put worldmodel in here too. double time; + double frametime; int num_edicts; int reserved_edicts; int max_edicts; diff --git a/Quake/sbar.c b/Quake/sbar.c index 32831824..23f51314 100644 --- a/Quake/sbar.c +++ b/Quake/sbar.c @@ -976,14 +976,14 @@ void Sbar_Draw (void) glDisable (GL_ALPHA_TEST); //in the finest tradition of glquake, we litter gl state calls all over the place. yay state trackers. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); PR_SwitchQCVM(&cl.qcvm); - pr_global_struct->frametime = host_frametime; + pr_global_struct->time = qcvm->time; + pr_global_struct->frametime = qcvm->frametime; if (qcvm->extglobals.cltime) *qcvm->extglobals.cltime = realtime; if (qcvm->extglobals.clframetime) *qcvm->extglobals.clframetime = host_frametime; if (qcvm->extglobals.player_localentnum) *qcvm->extglobals.player_localentnum = cl.viewentity; - pr_global_struct->time = cl.time; Sbar_SortFrags (); G_VECTORSET(OFS_PARM0, vid.width/s, vid.height/s, 0); G_FLOAT(OFS_PARM1) = sb_showscores; diff --git a/Quake/server.h b/Quake/server.h index be5666d1..f9d475c8 100644 --- a/Quake/server.h +++ b/Quake/server.h @@ -333,7 +333,7 @@ void SV_AddClientToServer (struct qsocket_s *ret); void SV_ClientPrintf (const char *fmt, ...) FUNC_PRINTF(1,2); void SV_BroadcastPrintf (const char *fmt, ...) FUNC_PRINTF(1,2); -void SV_Physics (void); +void SV_Physics (double frametime); qboolean SV_CheckBottom (edict_t *ent); qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink); diff --git a/Quake/sv_main.c b/Quake/sv_main.c index 5bc46154..20551cd9 100644 --- a/Quake/sv_main.c +++ b/Quake/sv_main.c @@ -3666,8 +3666,8 @@ void SV_SpawnServer (const char *server) // run two frames to allow everything to settle host_frametime = 0.1; - SV_Physics (); - SV_Physics (); + SV_Physics (host_frametime); + SV_Physics (host_frametime); // create a baseline for more efficient communications SV_CreateBaseline (); diff --git a/Quake/sv_phys.c b/Quake/sv_phys.c index e1867ad6..7a4309e4 100644 --- a/Quake/sv_phys.c +++ b/Quake/sv_phys.c @@ -150,7 +150,7 @@ qboolean SV_RunThink (edict_t *ent) int i; //johnfitz thinktime = ent->v.nextthink; - if (thinktime <= 0 || thinktime > qcvm->time + host_frametime) + if (thinktime <= 0 || thinktime > qcvm->time + qcvm->frametime) return true; if (thinktime < qcvm->time) @@ -417,7 +417,7 @@ void SV_AddGravity (edict_t *ent) else ent_gravity = 1.0; - ent->v.velocity[2] -= ent_gravity * sv_gravity.value * host_frametime; + ent->v.velocity[2] -= ent_gravity * sv_gravity.value * qcvm->frametime; } @@ -847,14 +847,14 @@ void SV_Physics_Pusher (edict_t *ent) oldltime = ent->v.ltime; thinktime = ent->v.nextthink; - if (thinktime < ent->v.ltime + host_frametime) + if (thinktime < ent->v.ltime + qcvm->frametime) { movetime = thinktime - ent->v.ltime; if (movetime < 0) movetime = 0; } else - movetime = host_frametime; + movetime = qcvm->frametime; if (movetime) { @@ -1104,7 +1104,7 @@ void SV_WalkMove (edict_t *ent) VectorCopy (ent->v.origin, oldorg); VectorCopy (ent->v.velocity, oldvel); - clip = SV_FlyMove (ent, host_frametime, &steptrace); + clip = SV_FlyMove (ent, qcvm->frametime, &steptrace); if ( !(clip & 2) ) return; // move didn't block on a step @@ -1132,7 +1132,7 @@ void SV_WalkMove (edict_t *ent) VectorCopy (vec3_origin, upmove); VectorCopy (vec3_origin, downmove); upmove[2] = STEPSIZE; - downmove[2] = -STEPSIZE + oldvel[2]*host_frametime; + downmove[2] = -STEPSIZE + oldvel[2]*qcvm->frametime; // move up SV_PushEntity (ent, upmove); // FIXME: don't link? @@ -1141,7 +1141,7 @@ void SV_WalkMove (edict_t *ent) ent->v.velocity[0] = oldvel[0]; ent->v. velocity[1] = oldvel[1]; ent->v. velocity[2] = 0; - clip = SV_FlyMove (ent, host_frametime, &steptrace); + clip = SV_FlyMove (ent, qcvm->frametime, &steptrace); // check for stuckness, possibly due to the limited precision of floats // in the clipping hulls @@ -1246,13 +1246,13 @@ void SV_Physics_Client (edict_t *ent, int num) case MOVETYPE_FLY: if (!SV_RunThink (ent)) return; - SV_FlyMove (ent, host_frametime, NULL); + SV_FlyMove (ent, qcvm->frametime, NULL); break; case MOVETYPE_NOCLIP: if (!SV_RunThink (ent)) return; - VectorMA (ent->v.origin, host_frametime, ent->v.velocity, ent->v.origin); + VectorMA (ent->v.origin, qcvm->frametime, ent->v.velocity, ent->v.origin); break; default: @@ -1297,8 +1297,8 @@ void SV_Physics_Noclip (edict_t *ent) if (!SV_RunThink (ent)) return; - VectorMA (ent->v.angles, host_frametime, ent->v.avelocity, ent->v.angles); - VectorMA (ent->v.origin, host_frametime, ent->v.velocity, ent->v.origin); + VectorMA (ent->v.angles, qcvm->frametime, ent->v.avelocity, ent->v.angles); + VectorMA (ent->v.origin, qcvm->frametime, ent->v.velocity, ent->v.origin); SV_LinkEdict (ent, false); } @@ -1381,10 +1381,10 @@ void SV_Physics_Toss (edict_t *ent) SV_AddGravity (ent); // move angles - VectorMA (ent->v.angles, host_frametime, ent->v.avelocity, ent->v.angles); + VectorMA (ent->v.angles, qcvm->frametime, ent->v.avelocity, ent->v.angles); // move origin - VectorScale (ent->v.velocity, host_frametime, move); + VectorScale (ent->v.velocity, qcvm->frametime, move); trace = SV_PushEntity (ent, move); if (trace.fraction == 1) return; @@ -1499,7 +1499,7 @@ void SV_Physics_Step (edict_t *ent) SV_AddGravity (ent); SV_CheckVelocity (ent); - SV_FlyMove (ent, host_frametime, NULL); + SV_FlyMove (ent, qcvm->frametime, NULL); SV_LinkEdict (ent, true); if ( (int)ent->v.flags & FL_ONGROUND ) // just hit ground @@ -1524,7 +1524,7 @@ SV_Physics ================ */ -void SV_Physics (void) +void SV_Physics (double frametime) { int i; int entity_cap; // For sv_freezenonclients @@ -1537,9 +1537,12 @@ void SV_Physics (void) else physics_mode = (qcvm==&cl.qcvm)?0:2; //csqc doesn't run thinks by default. it was meant to simplify implementations, but we just force fields to match ssqc so its not that large a burden. + pr_global_struct->time = qcvm->time; + pr_global_struct->frametime = qcvm->frametime = frametime; + if (!physics_mode) { - qcvm->time += host_frametime; + qcvm->time += frametime; return; } else if (physics_mode==1) @@ -1550,7 +1553,7 @@ void SV_Physics (void) continue; SV_RunThink(ent); } - qcvm->time += host_frametime; + qcvm->time += frametime; return; } // else if (physics_mode==2) standard quake physics @@ -1638,5 +1641,5 @@ void SV_Physics (void) } if (!(sv_freezenonclients.value && qcvm == &sv.qcvm)) - qcvm->time += host_frametime; + qcvm->time += frametime; }