Forum

Fixing gravity/acceleration

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

Fixing gravity/acceleration

Postby mankrip » Tue Apr 13, 2010 12:01 am

This article seems to describe a bug in the way Quake calculates gravity and acceleration in general.

After looking into SV_AddGravity, it seems Quake really has this problem:
Code: Select all
ent->v.velocity[2] -= ent_gravity * sv_gravity.value * host_frametime;


Has anyone already implemented a solution for this?
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Postby leileilol » Tue Apr 13, 2010 12:28 am

It's not a bug, it's a "feature"! "Fix" this and you will recieve essays of whining on how you suck, brought to you by the Picmip 256 Fov 150 Fullbright Association of Europe.

Wazat's probably said enough what i'd want to say in another thread somewhere, i'm just giving the most abridged version I can.

I do wonder what mods this could break with. Quake Rally?
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Postby mankrip » Tue Apr 13, 2010 1:40 am

The only mods that could have problems when fixing this are the ones that doesn't behave correctly in high framerates, and I never found any mod like this.

On the other hand, fixing this would probably improve the gameplay of several mods that behaves incorrectly at low framerates.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Postby r00k » Tue Apr 13, 2010 3:56 am

This would be a unique algorithm for Quake, changing this would change the way the game feels, thus breaking gameplay-compatibility.
If your would mod benefits more by 'fixing' this, then just create a switch.
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby Lardarse » Tue Apr 13, 2010 7:03 am

...why is it wrong? What "should" it be?
Roaming status: Testing and documentation
User avatar
Lardarse
 
Posts: 266
Joined: Sat Nov 05, 2005 1:58 pm
Location: Bristol, UK

Postby mankrip » Tue Apr 13, 2010 7:16 am

r00k wrote:This would be a unique algorithm for Quake, changing this would change the way the game feels

It wouldn't. All this change would do is make the gameplay in slow computers behave like the gameplay in fast ones. All engines already works like this when running at 60 fps:
Image
People with fast computers would see no difference:
Image

I'll try to implement this and do some tests.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Postby mh » Tue Apr 13, 2010 9:04 am

It's server-side anyway, so it wouldn't affect multiplayer games. I see no problem in fixing it - the very worst you can do is allow people who have low framerates to make jumps that they could have previously only made if they hadn't.

Incidentally - and slightly less important but good to know nonetheless - this also explains why particle velocities are framerate-dependent, as they go through a similar equation.

I'm going to implement this later on today and see how things turn out.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby Urre » Tue Apr 13, 2010 11:54 am

Twig fixed this :)
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby mh » Tue Apr 13, 2010 1:10 pm

This seems to work:
Code: Select all
void SV_AddGravity (edict_t *ent)
{
   float   ent_gravity;
   eval_t   *val;

   val = GetEdictFieldValue (ent, "gravity");

   if (val && val->_float)
      ent_gravity = val->_float;
   else ent_gravity = 1.0;

   // in case SV_AddGravity gets called on an entity more than once per frame
   // (can this ever happen???)
   if (ent->grav_frame != host_framecount)
   {
      // update from last frame's gravity
      ent->v.velocity[2] -= ent->last_grav;
      ent->grav_frame = host_framecount;
   }

   // evaluate this frame's gravity
   ent->last_grav = (ent_gravity * sv_gravity.value * host_frametime) / 2.0f;

   // update from this frame's gravity
   ent->v.velocity[2] -= ent->last_grav;
}

There are there obvious new fields there that need to be added to edict_t, and there is probably a bit of work required elsewhere (setting last_grav to 0 in ED_Alloc for example), but overall yes, it does let you jump much the same distance when you're running at 3 FPS.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby Sajt » Tue Apr 13, 2010 5:44 pm

Darkplaces fixed this a long time ago. I don't remember if it was made into a sv_gameplayfix cvar, but it should be.
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby mh » Tue Apr 13, 2010 9:23 pm

I'd vote for always on. To be honest I'm having a really difficult time thinking of any advatages to not doing it. A listen server running a complex map on a slow machine is the only situation where somebody may not want it.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby Spike » Tue Apr 13, 2010 9:40 pm

tbh, prediction is the only reason I can think of.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby metlslime » Tue Apr 13, 2010 10:53 pm

the alternative is a fixed server FPS independent of client framerate. If client is running slow, do multiple server frames in a row. If client is running fast, skip server frame. Of course i've never done this so i'm sure there are details to work out.

The fix in the original post seems reasonable though, but i haven't looked at it closely.
metlslime
 
Posts: 316
Joined: Tue Feb 05, 2008 11:03 pm

Postby mh » Tue Apr 13, 2010 11:16 pm

Running the server in it's own thread would be the correct solution IMO, but there are data sharing issues to be resolved (the server would need to load it's own copy of the models for starters, as these are shared by a client and a server on the same machine) and thread sync issues during network communications (even if it's just using the net_loop driver).

I've just run through most of e1 using the code I posted and it seems solid enough there. No idea what it would be like in The Real World though...
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby metlslime » Tue Apr 13, 2010 11:27 pm

the client and server only need readonly access to the shared model data once it's loaded, right? So they probably don't need their own copies of it.
metlslime
 
Posts: 316
Joined: Tue Feb 05, 2008 11:03 pm

Next

Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest