Lag

From The Elite Wiki
Revision as of 15:52, 16 July 2021 by en>Whiteted (→‎Lag and speed: cut summary from short section which didn't say anything)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Lag is wherever the game frame rate drops, and that's quite often in Goldeneye.

Its main effects are slower forward movement and warps. It directly determines the fire rate of automatic weapons, which is a bottleneck for areas of many levels such as Dam SA and Train. A large part of OCB is coping with lag, particularly avoiding stucks in heavy lag, and experienced players are very sensitive to it.

Causes

Lag is caused by anything which makes more work for Goldeneye to do before it completes a game tick, so the causes are much more than just "what's on screen". However, levels are divided into rooms, objects are marked as being 'on-screen' and generally what is on screen has a much bigger effect on lag than just how long the rendering takes.

Beyond broad ideas, not a great deal is known about the relative size of various causes. But that's not to say that the player base hasn't becoming pretty skilled at reducing lag, including through some rather subtle strats.

Some particular causes:

  • Weapon switching / pausing - this creates a lag spike as the new object is spawned in, and the size of the lag spike is specific to the weapon. The exact cause is unknown but could relate to fetching the files from the ROM and decompressing them. This seems insufficient to explain the size of the lag spike though.
  • Bringing things on screen for the first time (new rooms / guards who have been off-screen)
  • Smoke, particularly if it's very close to the camera i.e. from shooting at a wall right in front of you
  • Guards, particularly when loaded and active (moving or shooting)
  • Having lots of rooms loaded

Lag and speed

One of the big early discoveries was that of 'lookdown'. More precisely, this was the idea that a higher frame rate increases your forward speed.

Exactly what causes this is not well understood. Your forward movement seems to be actually driven by the animation of Bond moving side to side, and so perhaps the root cause is in how lag effects this process.

Backwards movement is affected by lag in the exact same way as forward movement.[1]

Certainly exactly when lag spikes land affects the loss of speed: TASers will nudge weapon switches about by a few frames to find a spot that causes the smallest loss of forward speed, and the variation is dramatic.

Strafing speed is added to your velocity much later in the movement calculation process, and is confirmed as being entirely unaffected by lag.

Technical Details

Lag and lookdown

First of all, what does lookdown actually do?[2] Well, it makes it so that less things are rendered on screen, thus increasing the framerate. However, if we dig a bit deeper, and look at how this affects in-game values in memory, we'll see that it mainly affects the value that tells the game how many 1/60th ticks (i.e. "frames") that passed since the last update.

To figure out how many frames have passed, the game checks the value of the N64 CPU cycle counter. According to the official documentation[3], the CPU runs at 45.6375 MHz (or perhaps 46.875 MHz[4]). If we wish to convert this to 1/60ths of a second:

                  cpu_cycles           cpu_cycles
    frames = ------------------  = ---------------
                (46875000 / 60)        781250

Interestingly, the game doesn't divide by 781250, but rather 775875. I haven't been able to figure out where that number comes from. This number comes from the PAL version [5], credit to MW for figuring it out. Anyway, to get the number of frames passed since last update, we just use the number of CPU cycles passed, divided by 775875, and rounded to nearest integer. This number will be added to the mission timer and will be used in gameplay calculations. To understand lookdown, we'll want to look at the way Bond's position is updated. This is straightforward:

position += (velocity * time)

Time in this case is the value we calculated in the previous step. So if we assume a constant velocity, the distance we move will be proportional to the number of frames passed since the last update. In this scenario, we should be moving just as fast no matter how much the game lags, meaning in-game time should remain unaffected. In reality however, velocity is not constant.

The calculation of velocity in Goldeneye is very complicated, and beyond my patience to figure out. What we can say is that in order to lose in-game time, the average speed of Bond must decrease when lag increases. In order to test this, I modified a ROM to force the number of frames passed to a constant value, essentially emulating constant lag. The result can be seen in this video (the lower right corner shows the value of the constant).

When running forwards, the amount of lag has a huge effect on the amount of time it takes to run down the runway (~1600 frames at 1x, ~13000 frames at 64x). Bond's speed clearly decreases at higher amounts of lag, almost to the point of Bond stopping sporadically at 64x. It looks strange to say the least.

Sideways movement is a different story however, as it remains smooth even at very high lag. Indeed, the time taken stays relatively constant at ~2000 frames throughout the test.

In conclusion, the complex nature of Bond's forward movement (likely programmed that way to create more interesting gameplay and make the movement feel less artifical) causes a decrease in speed when lag increases and is the reason why lookdown saves time. Normally, the game runs at around 1x-4x, where you can't really see the effect. However, it is there, and over longer distances it will have a big effect on you in-game time.

References

  1. "the-elite facts topic post on lag and lookdown response on backwards movement". Retrieved July 16, 2021.
  2. "the-elite facts topic post on lag and lookdown". Retrieved July 16, 2021.
  3. "N64 official documentation osSetTime". Retrieved July 16, 2021.
  4. "N64 official documentation OS_CYCLES_TO_NSEC". Retrieved July 16, 2021.
  5. "N64 official documentation osGetTime". Retrieved July 16, 2021.