Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use perfect fixed interval ticks/physics frames or, by default, integer multiples #149

Closed
wants to merge 6 commits into from
106 changes: 54 additions & 52 deletions trunk/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ cvar_t cl_gibfilter = {"cl_gibfilter", "0"};
cvar_t cl_maxfps = {"cl_maxfps", "72", CVAR_SERVER};
cvar_t cl_advancedcompletion = {"cl_advancedcompletion", "1"};
cvar_t cl_independentphysics = {"cl_independentphysics", "1", CVAR_INIT};
cvar_t cl_mergeticks = {"cl_mergeticks", "1"};
cvar_t cl_viewweapons = {"cl_viewweapons", "0"};
cvar_t cl_autodemo = { "cl_autodemo", "0" };
cvar_t cl_autodemo_name = { "cl_autodemo_name", "" };
cvar_t cl_demoui = {"cl_demoui", "1", CVAR_ARCHIVE};
cvar_t cl_demouitimeout = {"cl_demouitimeout", "2.5", CVAR_ARCHIVE};
cvar_t cl_demouihidespeed = {"cl_demouihidespeed", "2", CVAR_ARCHIVE};
cvar_t cl_demoui = {"cl_demoui", "1", CVAR_ARCHIVE};
cvar_t cl_demouitimeout = {"cl_demouitimeout", "2.5", CVAR_ARCHIVE};
cvar_t cl_demouihidespeed = {"cl_demouihidespeed", "2", CVAR_ARCHIVE};

client_static_t cls;
client_state_t cl;
Expand All @@ -75,7 +76,7 @@ entity_t cl_static_entities[MAX_STATIC_ENTITIES];
lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
dlight_t cl_dlights[MAX_DLIGHTS];

entity_t *cl_entities; //johnfitz -- was a static array, now on hunk
entity_t *cl_entities; //johnfitz -- was a static array, now on hunk
int cl_max_edicts; //johnfitz -- only changes when new map loads

int cl_numvisedicts;
Expand All @@ -89,7 +90,7 @@ qboolean r_loadq3player = false;

extern qboolean physframe;
extern double physframetime;
extern char *skill_modes[];
extern char *skill_modes[];

unsigned CheckModel (char *mdl);

Expand Down Expand Up @@ -128,9 +129,9 @@ void CL_ClearState (void)
memset (cl_lightstyle, 0, sizeof(cl_lightstyle));
memset (cl_temp_entities, 0, sizeof(cl_temp_entities));

//johnfitz -- cl_entities is now dynamically allocated
cl_max_edicts = bound(MIN_EDICTS, (int)max_edicts.value, MAX_EDICTS);
cl_entities = (entity_t *)Hunk_AllocName(cl_max_edicts*sizeof(entity_t), "cl_entities");
//johnfitz -- cl_entities is now dynamically allocated
cl_max_edicts = bound(MIN_EDICTS, (int)max_edicts.value, MAX_EDICTS);
cl_entities = (entity_t *)Hunk_AllocName(cl_max_edicts*sizeof(entity_t), "cl_entities");
//johnfitz

// allocate the efrags and chain together into a free list
Expand Down Expand Up @@ -180,8 +181,8 @@ This is also called on Host_Error, so it shouldn't cause any errors
*/
void CL_Disconnect (void)
{
qboolean was_loopback;

qboolean was_loopback;
// stop sounds (especially looping!)
S_StopAllSounds (true);

Expand All @@ -207,27 +208,27 @@ void CL_Disconnect (void)
MSG_WriteByte (&cls.message, clc_disconnect);
NET_SendUnreliableMessage (cls.netcon, &cls.message);
SZ_Clear (&cls.message);
was_loopback = (cls.netcon && !cls.netcon->disconnected && cls.netcon->driver == 0);
was_loopback = (cls.netcon && !cls.netcon->disconnected && cls.netcon->driver == 0);
NET_Close (cls.netcon);

cls.state = ca_disconnected;
if (sv.active)
{
if (was_loopback
&& svs.clients->active
&& svs.clients->netconnection
&& svs.clients->netconnection->driver == 0)
{
// If this is a loopback connection and there is data ready to
// be sent to the client, then the data will never be sent since
// we just closed the socket (`NET_Close` above), and therefore
// `Host_ShutdownServer` will always hang for three seconds.
//
// Avoid this by just discarding the pending message.
SZ_Clear (&svs.clients->message);
}
{
if (was_loopback
&& svs.clients->active
&& svs.clients->netconnection
&& svs.clients->netconnection->driver == 0)
{
// If this is a loopback connection and there is data ready to
// be sent to the client, then the data will never be sent since
// we just closed the socket (`NET_Close` above), and therefore
// `Host_ShutdownServer` will always hang for three seconds.
//
// Avoid this by just discarding the pending message.
SZ_Clear (&svs.clients->message);
}
Host_ShutdownServer (false);
}
}
}

cls.demoplayback = cls.timedemo = false;
Expand All @@ -248,7 +249,7 @@ void CL_Disconnect_f (void)
if (sv.active)
Host_ShutdownServer (false);
}


/*
=====================
Expand Down Expand Up @@ -758,8 +759,8 @@ void CL_RelinkEntities (void)
{
if (!ent->model)
{ // empty slot
// ericw -- efrags are only used for static entities in GLQuake
// ent can't be static, so this is a no-op.
// ericw -- efrags are only used for static entities in GLQuake
// ent can't be static, so this is a no-op.
//if (ent->forcelink)
// R_RemoveEfrags (ent); // just became empty
continue;
Expand All @@ -770,7 +771,7 @@ void CL_RelinkEntities (void)
{
ent->model = NULL;
#ifdef GLQUAKE
ent->lerpflags |= LERP_RESETMOVE | LERP_RESETANIM; //johnfitz -- next time this entity slot is reused, the lerp will need to be reset
ent->lerpflags |= LERP_RESETMOVE | LERP_RESETANIM; //johnfitz -- next time this entity slot is reused, the lerp will need to be reset
#endif
continue;
}
Expand All @@ -791,15 +792,15 @@ void CL_RelinkEntities (void)
if (delta[j] > 100 || delta[j] < -100)
{
f = 1; // assume a teleportation, not a motion
ent->lerpflags |= LERP_RESETMOVE; //johnfitz -- don't lerp teleports
ent->lerpflags |= LERP_RESETMOVE; //johnfitz -- don't lerp teleports
}
}

#ifdef GLQUAKE
//johnfitz -- don't cl_lerp entities that will be r_lerped
if (gl_interpolate_moves.value && (ent->lerpflags & LERP_MOVESTEP))
f = 1;
//johnfitz
//johnfitz -- don't cl_lerp entities that will be r_lerped
if (gl_interpolate_moves.value && (ent->lerpflags & LERP_MOVESTEP))
f = 1;
//johnfitz
#endif

// interpolate the origin and angles
Expand Down Expand Up @@ -869,15 +870,15 @@ void CL_RelinkEntities (void)

if (ent->effects & EF_MUZZLEFLASH)
{
//johnfitz -- assume muzzle flash accompanied by muzzle flare, which looks bad when lerped
if (gl_interpolate_anims.value == 1)
{
if (ent == &cl_entities[cl.viewentity])
cl.viewent.lerpflags |= LERP_RESETANIM | LERP_RESETANIM2; //no lerping for two frames
else
ent->lerpflags |= LERP_RESETANIM | LERP_RESETANIM2; //no lerping for two frames
}
//johnfitz
//johnfitz -- assume muzzle flash accompanied by muzzle flare, which looks bad when lerped
if (gl_interpolate_anims.value == 1)
{
if (ent == &cl_entities[cl.viewentity])
cl.viewent.lerpflags |= LERP_RESETANIM | LERP_RESETANIM2; //no lerping for two frames
else
ent->lerpflags |= LERP_RESETANIM | LERP_RESETANIM2; //no lerping for two frames
}
//johnfitz

if (cl_muzzleflash.value)
{
Expand Down Expand Up @@ -1396,7 +1397,7 @@ char *CL_MapName (void)
return cl_mapname.string;
}


/*
=================
CL_Init
Expand All @@ -1410,8 +1411,8 @@ void CL_Init (void)
CL_InitModelnames ();
CL_InitTEnts ();
Ghost_Init ();
CL_InitDemo ();
FreeFly_Init ();
CL_InitDemo ();
FreeFly_Init ();

// register our commands
Cvar_Register (&cl_name);
Expand Down Expand Up @@ -1448,16 +1449,17 @@ void CL_Init (void)
Cvar_Register (&cl_maxfps);
Cvar_Register (&cl_advancedcompletion);
Cvar_Register (&cl_independentphysics);
Cvar_Register (&cl_mergeticks);
Cvar_Register (&cl_viewweapons);
Cvar_Register(&cl_autodemo);
Cvar_Register(&cl_autodemo_name);
Cvar_Register(&cl_demoui);
Cvar_Register(&cl_demouitimeout);
Cvar_Register(&cl_demouihidespeed);

if (COM_CheckParm("-noindphys"))
{
Cvar_SetValue(&cl_independentphysics, 0);
if (COM_CheckParm("-noindphys"))
{
Cvar_SetValue(&cl_independentphysics, 0);
}

Cmd_AddCommand ("entities", CL_PrintEntities_f);
Expand All @@ -1469,8 +1471,8 @@ void CL_Init (void)
Cmd_AddCommand ("demoseek", CL_DemoSeek_f);
Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
Cmd_AddCommand("keepdemo", CL_KeepDemo_f);


}


Expand Down
37 changes: 17 additions & 20 deletions trunk/gl_rpart.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void R_DrawQ3Model (entity_t *ent);
void QMB_Q3Gunshot (vec3_t org, int skinnum, float alpha);
void QMB_Q3Teleport (vec3_t org, float alpha);

extern qboolean physframe;
extern int physframecount;

#define TruePointContents(p) SV_HullPointContents(&cl.worldmodel->hulls[0], 0, p)

Expand Down Expand Up @@ -1837,16 +1837,13 @@ void QMB_TeleportSplash (vec3_t org)

void QMB_StaticBubble (entity_t *ent)
{
if (fabs(cl.ctime - cl.oldtime))
AddParticle (p_staticbubble, ent->origin, 1, ent->frame == 1 ? 1.85 : 2.9, ONE_FRAME_ONLY, NULL, zerodir);
AddParticle (p_staticbubble, ent->origin, 1, ent->frame == 1 ? 1.85 : 2.9, ONE_FRAME_ONLY, NULL, zerodir);
}

void QMB_TorchFlame (vec3_t org, float size, float time)
{
if (!physframe)
return;

if (fabs(cl.ctime - cl.oldtime))
// emit once per tick
for (int i = 0; i < physframecount; i++)
AddParticle (p_flame, org, 1, size, time, NULL, zerodir);
}

Expand All @@ -1859,14 +1856,12 @@ void QMB_Q3TorchFlame (vec3_t org, float size)
else
return;

if (fabs(cl.ctime - cl.oldtime))
AddParticle (p_q3flame, org, 1, size, 0.25, NULL, zerodir);
AddParticle (p_q3flame, org, 1, size, 0.25, NULL, zerodir);
}

void QMB_MissileFire (vec3_t org)
{
if (fabs(cl.ctime - cl.oldtime))
AddParticle (p_missilefire, org, 1, 20, ONE_FRAME_ONLY, NULL, zerodir);
AddParticle (p_missilefire, org, 1, 20, ONE_FRAME_ONLY, NULL, zerodir);
}

void QMB_ShamblerCharge (vec3_t org)
Expand Down Expand Up @@ -1952,15 +1947,19 @@ void QMB_LightningSplash (vec3_t org)
void QMB_LightningBeam (vec3_t start, vec3_t end)
{
vec3_t neworg;
double frametime;

if (!physframe)
// only update LG beam on tick
if (!physframecount)
return;

if (fabs(cl.ctime - cl.oldtime))
{
AddParticle (p_lightningbeam, start, 1, 80, physframetime * 2, NULL, end);
frametime = max(physframetime, host_frametime);
AddParticle (p_lightningbeam, start, 1, 80, frametime * 2, NULL, end);

if (TraceLineN(start, end, neworg, NULL))
if (TraceLineN(start, end, neworg, NULL))
{
// always create an impact for each tick
for (int i = 0; i < physframecount; i++)
{
QMB_LightningSplash (neworg);
if (gl_decal_sparks.value)
Expand Down Expand Up @@ -2026,10 +2025,8 @@ void QMB_MuzzleFlash (vec3_t org, qboolean weapon)
{
if (weapon)
{
float frametime = fabs(cl.ctime - cl.oldtime);

if (frametime)
AddParticle (p_muzzleflash, org, 1, 8, frametime * 2, NULL, zerodir);
float frametime = fabs(cl.ctime - cl.oldtime);
AddParticle (p_muzzleflash, org, 1, 8, frametime * 2, NULL, zerodir);
}
else
{
Expand Down
Loading