Skip to content

Draw the view's bob and the gun's sway between ticks - #38

Open
wizzan1 wants to merge 1 commit into
ReactionQuake3:masterfrom
wizzan1:view-bob
Open

wizzan1 wants to merge 1 commit into
ReactionQuake3:masterfrom
wizzan1:view-bob

Conversation

@wizzan1

@wizzan1 wizzan1 commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

What was wrong

The view is drawn between the last two movement ticks, so it turns and moves on every frame. The bob cycle and the
velocity were still read from the newest tick alone. The view's bob, its lean and the sway of the gun in the hand follow
those two, so they stood still on the frames between two ticks and jumped on the next. At com_maxfps 125 on a 165 Hz
screen every fourth picture showed the gun where it was while the eye had moved on.

What changed

Only code/cgame (cg_local.h, cg_predict.c, cg_view.c). No game, server or network code.

  • Each tick keeps its bob cycle and velocity beside its origin, and the view takes all three at the frame's moment
    between the two ticks. CG_SetViewBob holds the one copy of the bob's formula.
  • A landing or a stop starts the cycle again, and the same tick may advance it, so a landing at a run ends at 3, not 0.
    A cycle runs forward at most 0.5 a msec, so a longer step is a restart (CG_BobStep) and is shown as it is, as before.
  • The cycle advances only on the ground. Sliding across a tilted street the player is off it for a tick or two at a
    time, and the sway ran on about one tick in three. The drawn cycle carries on at the rate it last ran through an
    airborne moment of up to 32 msec (CG_CarryViewBob). A jump is longer and holds the bob, as before.

Views that are not predicted (a demo, a followed player, an engine without the call) are unchanged, and so are the
player state, its footsteps and movement.

Cost

A few operations a tick and one more sin and sqrt a frame.

Proof

  • A scripted circle on urban without vsync, 330 pictures a second, measured as how far each frame's rate of change is
    from its neighbours': the eye's height 199 % before and 17 % after, the gun's yaw against the view 187 % before and
    18 % after, over the same 13 degrees of sway.
  • Recorded play on urban's tilted streets: before, the sway moved 0.19, 0.01, 0.01, 0.19 degrees a tick; after, it moves
    on every tick. Through strafe jumps the gun shows the landing's restart once and no longer flips after it.
  • Built as QVM and DLL, with GCC and Visual Studio 2022.

🤖 Generated with Claude Code

The view is drawn between the last two movement ticks, but the bob cycle and the
velocity were still read from the newest tick alone. The view's bob, its lean and
the sway of the gun in the hand follow those, so they stood still on the frames
between two ticks and jumped on the next: at com_maxfps 125 on a 165 Hz screen
every fourth picture showed the gun where it was while the eye moved on.

Each tick now keeps its bob cycle and velocity beside its origin, and the view
takes all three at the frame's moment between the ticks. CG_SetViewBob holds the
one copy of the bob's formula, for a player state and for that moment.

Two rules of movement show in a drawn cycle and are handled here, in drawing only:

- A landing and a stop start the cycle again, and the same tick may advance it,
  so a landing at a run ends at 3, not 0. A cycle runs forward at most 0.5 a
  msec, so a longer step is a restart (CG_BobStep) and is shown as it is, as
  before. Read as a step it would sweep the gun through half a cycle.
- The cycle advances only on the ground. Sliding across a tilted street the
  player is off it for a tick or two at a time, and the sway ran on one tick in
  three. The drawn cycle carries on at the rate it last ran through an airborne
  moment of up to 32 msec (CG_CarryViewBob). A jump is longer and holds the bob.

Views that are not predicted (a demo, a followed player, an engine without the
call) are unchanged, and so are the player state, its footsteps and movement.

Cost: a few operations a tick and one more sin and sqrt a frame.

Measured on a circle run without vsync, 330 pictures a second, as how far each
frame's rate of change is from its neighbours': the eye's height 199 % before
and 17 % after, the gun's yaw against the view 187 % before and 18 % after, over
the same 13 degrees of sway. In recorded play on urban's tilted streets and
through strafe jumps the gun no longer moves in bursts or flips after a landing.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant