Skip to content

Frame timing

How time reaches the engine

  • ZSysInterfaceSDL::StepTime (sysinterfacesdl.cpp) measures the real time since the previous frame on an EE-rate counter, clamps one step to 0.1 s and scales it by the time multiplier. ZSysInterface::StepFrameTime turns that into FrameTime and DeltaFrameTime, freezing FrameTime while the game is paused. Nothing here assumes a frame length, so at 144 fps the engine simply sees deltas of about 6.9 ms instead of 33.3 ms.
  • The rate itself is set only by the frame limiter, ZRenderSDL::WaitForNextFrame (rendersdl.cpp), which sleeps to the next frame slot. FrameRateSDL() (sysinterfacesdl.h) returns the chosen rate; for display it is the refresh rate of the chosen fullscreen mode, or of the primary display, rounded and clamped to 30 to 240. The limiter and RenderFrameRateSDL() (shown in the debug overlay's performance panel) read it.
  • m_fFramesPerSecond stays 60. It is the display's field rate, not the game's frame rate: ZPS2Setup sets 60 or 50 for NTSC or PAL, and the engine uses it as a unit of time (zcollisionboxold.cpp, humanflow.cpp, the blocking FadeScreen loop).
  • Game time is fixed point at 1/1024 s (TIMETYPE), and DeltaFrameTime is a difference of two such times. At 144 fps a frame is about 7 ticks, so single deltas vary by about ±7% and average out; 240 (4 ticks) is the highest rate the port allows.

The PS2 already runs parts of the game at 60

ZRenderPS2::Flip (renderps2.cpp) waits m_lMaxFrameInterval fields per frame. The interval is 1 (60 fps) by default and after every scene pop (renderbase.cpp), and in the in-game map (CIngameMap::OnWindowOpen, ingamemap.cpp); the level control sets 2 (30 fps) for play (ZHM3LevelControl::Init2, levelcontrolbase.cpp, the hideout included) and the movie player sets 2 while a movie runs (basevideo.cpp). The front end and the map therefore ran at 60 fps on the PS2 and are known to work at that rate. The port's limiter ignores the interval and paces everything at the chosen rate.

Time-based code (unaffected)

Almost all game logic scales with DeltaFrameTime or reads FrameTime: animation (animation.cpp, zmovement.cpp, zlnkobj.cpp, zactor.cpp convert seconds to 25 fps animation frames), cut sequences (cutsequence.cpp, cutsequence2.cpp), particles (zparticlebox.cpp, zparticleemitter.cpp), visibility timers (checkvisible.cpp), the camera spring (hm3cameraspring.cpp), the console camera's pull (hm3cameraconsole.cpp), the turn ease (CEaseInOut::Update, zhitman3movementcontrol.cpp), script Sleep (seconds, scriptc.cpp), the hitman's turn speed (a rate; the mouse controls divide their motion by the frame time) and the mouse turn (relative motion per frame). Some code steps in fixed slices of time from an accumulator, which gives the same result at any rate:

  • ZDynamicsExtend physics advances in fixed 1/60 s steps (dynamicsextend.cpp); at 30 fps it already takes two steps a frame.
  • The blood particles of ZBoneParticle (zboneparticle.cpp) move in whole 1/30 s steps.
  • Cloth (ZCloth::DrawIt, cloth.cpp) takes fixed 1/40 s steps; see the fix below for the one per-frame part.
  • The newspaper's pad pan and zoom (ZStatisticsTest::ControlMoveSmooth, statisticsscreen.cpp) scale with DeltaFrameTime (powf(zoom, DeltaFrameTime * 2)). The PC version uses * 8 (PC 0x65e080), a zoom four times faster per second at any rate; the port uses that speed when PC tuning is enabled.
  • The rigid bodies' rest threshold grows by powf(1.002, dt / 0.05) (CRigidBody::FrameUpdate), the text fade-out by m_fActualTimeDelta * 5 (ZSimpleDisplay::UpdateFades), the heartbeat by the real time delta (ZHM3GameData::UpdateHeartBeat), and the map's icons and zoom by DeltaFrameTime * 2 and m_fActualTimeDelta * 3 (CMapIconDraw::DrawIcons, CIngameMap::PositionUpdate).

Per-frame code

Code that moves, decays or counts by a fixed amount each frame runs that much more often at a higher rate. The port's versions of such functions (docs/development/port/overrides.md) go through the helpers in port/engine/system/_sdl/frameratesdl.h, implemented in sysinterfacesdl.cpp. Each gives exactly the PS2's own value at 30 fps, so at 30 the port runs these functions exactly as the PS2 does:

Helper Value
PS2FrameFraction() the part of a 1/30 s frame the current frame covers: 1 at 30 fps, otherwise the real frame time times 30 (about 0.21 at 144). A step made each frame is multiplied by it.
PS2FieldFraction() the same for a 1/60 s field: 2 at 30 fps. For code the PS2 ran at 60 fps.
PS2FrameDecay(k) k to the power of the frame fraction: a value the PS2 multiplies by k each frame. k itself at 30 fps.
PS2FrameLerp(t) 1 - (1 - t) to the power of the frame fraction: a value the PS2 moves t of the way to its target each frame. t itself at 30 fps.
PS2FrameTick() whether this frame completes another 1/30 s of real time; always at 30 fps, about one frame in 4.8 at 144. A counter the PS2 steps each frame steps on these frames.
PS2FrameRate() whether the port runs at 30 fps.

They use real time, not game time: the PS2 runs this code once per frame whatever the time multiplier is, so in slow motion (M13's ending, the cheat menu's time multiplier, Instinct) the port matches it too.

Fixes

Function (game file → port file) What was per frame Fix
The cameras add the right stick's turn once a frame (ZHM3CameraConsole, Camera1stPerson, CameraScope, CameraBinocular, CameraObservation through ZHitman3::ReadTurnInput) the turn ZHM3MovementControl::SetTurn scales the stored turn by the fraction when the pad drives movement (movementoverridesdl.cpp). The mouse's turn is the motion during the frame already.
ZHM3CameraBinocular::UpdatePerturbation, ZHM3CameraScope::UpdatePerturbation (swayoverridesdl.cpp) scope and binocular sway grows with the turn input and decays by 0.995 the growth follows the scaled turn; the decay is PS2FrameDecay.
ZScheduledUpdate::m_lMaxCyclesToRun (1,000,000 EE cycles, 3.4 ms, a frame; docs/development/port/stability.md) the script scheduler's budget ZSysInterfaceSDL::ParseOptions sets it to 1,000,000 × 30 / frame rate, so scripts get the same time per second.
CRagdoll2::Move, CRagdoll2::Activate (engine/fysix/ragdoll.cpp → port/engine/fysix/_sdl/ragdolloverridesdl.cpp) The PS2 clamps a ragdoll's step to [0.01, 0.1] s and simulates every frame. At 144 fps a frame is 0.007 s, so the floor made ragdolls fall 1.44 times too fast (2.4 times at 240), and the counters that put a ragdoll to rest (251 steps without movement, the water timeout, the speed average) ran once a frame: a body came to rest 1.7 s after landing instead of 8.4 s. The PC version's frame guard (PC 0x571d30, docs/development/pc-differences/engine-core.md): above 30 fps a step is at least 0.025 s, a per-ragdoll counter adds 100 × (0.025 / dt − 1) each simulated frame and skips a frame for every 100, so the ragdoll moves in real time at up to 40 steps a second, and Activate zeroes the counter. The PC keeps the field on the ragdoll (+0x218); the port keeps it in a table of eight entries keyed by the ragdoll, where a new ragdoll (each scene builds its own container) takes the entry used longest ago. Like the PC, a ragdoll with fixed particles (dragged or nailed) or in slow motion simulates every frame; there the PC keeps the 0.01 s floor, which at 144 fps runs it 1.44 times too fast, so the port takes 0.01 × PS2FrameFraction() and steps its rest counters on PS2FrameTick(). Above 40 fps the rest counters step at 40 a second, as on the PC: a body rests 6.3 s after it stops instead of 8.4.
CRigidBody::FrameUpdate, CRigidBody::Move (engine/fysix/rigidbody.cpp → port/engine/fysix/_sdl/rigidbodyoverridesdl.cpp) Thrown and dropped objects, falling chandeliers and shards: the speed average decays by 0.925 a frame, and Move's speed sample is the distance of a step over its length squared, so it grows with the rate; a body stops after 17 frames (0.57 s at 30) with an energy change below 0.05 a frame; Move's timeout counts 1000 frames (33 s). The PC (0x575950, 0x575250) has the same code. The average decays by PS2FrameDecay(0.925) and takes the sample scaled back to a 1/30 s frame (× PS2FrameFraction() × (1 − decay) / 0.075), so it settles where the PS2's does; the energy change allowed per frame is 0.05 × PS2FrameFraction(), and the stop count and the timeout step on PS2FrameTick().
ZCloth::DrawIt (engine/fysix/cloth.cpp → port/engine/fysix/_sdl/clothoverridesdl.cpp) The cloth takes the frame's DeltaFrameTime into its 1/40 s accumulator each time it is drawn, and skips a second call in the same frame only when the first one took a step and marked its buffer with the frame's time. At 30 fps every frame takes a step; above 40 most do not, so a cloth drawn twice a frame (in the main view and a shadow or mirror view) gathered the time twice: 66 steps a second instead of 40, measured in M01 at 144 fps. Above 30 fps the buffer is marked with the frame's time whenever the frame's time is taken, so a second call in the frame is skipped: 39 to 42 steps a second at 144, as 40 at 30.
ZBloodSplatters::ClassFrameUpdate (engine/geomsbase/zprojectmarks.cpp → port/engine/geomsbase/_sdl/bloodoverridesdl.cpp) Blood running down a wall: ZBloodSplatters::CallBack multiplies the slide by m_fRunMarkMultiplier, 0.99, each frame, so above 30 fps a run stopped sooner and shorter. PS2FrameDecay(0.99), the PC version's fix (pow(0.99, DeltaFrameTime × 60), PC 0x4f6090) with the PS2's rate: the PC's 60 makes the slide decay twice as fast per second as the PS2's at any rate. The UV scale the callback applies is the ratio of the slides before and after, so the total run depends only on the decay per second.
CIngameMap::FrameUpdate (hitman3/gui/ingamemap.cpp → port/hitman3/gui/_sdl/ingamemapoverridesdl.cpp) The stick pans and zooms the map by m_fCurrentScale / 30 each frame. The PS2 draws the map at 60 fps (SetMaxFrameInterval(1)), so 2 map scales a second at full deflection; the port at 30 fps did 1, at 144 about 4.8. The step is multiplied by PS2FieldFraction(): 2.0 scales a second at any rate. Measured with OPENBLOOD_TRACE_FRAMERATE in M01: 1.93 at 30 fps (the run held 29 fps; the step at exactly 30 is fixed per frame, as on the PS2) and 2.000 at 144 (126 map frames a second). This makes the pad's map twice as fast at 30 fps as the port was before, as fast as on the PS2. The PC version pans at m_fCurrentScale × (1/60) per frame (PC 0x6677a0), half the PS2's speed at 60.
ZOSD::UpdateTension, UpdateDisguiseBar, UpdateVisibilityBar (hitman3/gui/osd.cpp → port/hitman3/gui/_sdl/osdmetersoverridesdl.cpp) The HUD's suspicion, disguise and visibility meters: their goals decay by 0.998, 0.998 and 0.99 a frame and the bars move 2, 0.5 and 2 a frame towards them. UpdateTension also hands the meter to ZHM3GameData::SetTension, which drives the heartbeat rumble. The decays are PS2FrameDecay, the steps are multiplied by PS2FrameFraction(); the dead bands (0.5 and 2) stay.
ZHM3Actor::ClassFrameUpdate (hitman3/characters/hm3actor.cpp → port/hitman3/characters/_sdl/actorframerateoverridesdl.cpp) An actor's tension decays by 0.9998 a frame (the PC, 0x63da70, the same), so above 30 fps guards calmed down sooner: from 100 to below 30, where they relax their vision range, in 200 s at 30 fps and 42 s at 144. The script priority count of an off-screen actor steps once a frame. PS2FrameDecay(0.9998); the count steps on PS2FrameTick().
ZHitman3::UpdateActorAimOffset (hitman3/characters/zhitman3.cpp → same port file) The point actors aim at follows 47 a fifth of the way each frame. ZHM3Actor's shots add the lag (m_ActorAimOffset, scaled down on harder difficulties) to their target, so above 30 fps the lag shrank and actors hit a moving 47 more often. PS2FrameLerp(0.2).
ZHM3CameraBase::AddPoseOffset, ZHM3Camera1stPerson::AddPoseOffset (hitman3/camera/ → port/hitman3/camera/_sdl/poseoffsetoverridesdl.cpp) The camera eases to its crouch and sneak offsets by 0.025 or 0.04 (third person) and 0.05, 0.1 or 0.4 (first person) of the way each frame. PS2FrameLerp. The two files' offset constants are file-level there and copied into the port file.
ZSimpleDisplay::UpdateFades (hitman3/gui/infodisplay.cpp → port/hitman3/gui/_sdl/infodisplayfadesoverridesdl.cpp) The on-screen texts fade in by m_fActualTimeDelta × 2 plus sin(v × π/2) × 0.1 a frame, so above 30 fps the sine term made them fade in up to three times faster (the PC, 0x66e6b0, the same). The sine term is multiplied by PS2FrameFraction().
ZWaterManager::FrameUpdate (engine/drawing/watermanager.cpp → port/engine/drawing/_sdl/wateroverridesdl.cpp) The ripples 47 makes when he wades (ZHitman3::UpdateObjectVisibleFlags adds one at a time interval, so their number does not depend on the rate) lose fDamping of their amplitude and grow by fRadiusSpeed each frame, so above 30 fps they faded and spread faster. Found by the water check (docs/development/port/pc-data.md, "Water in play"). Both steps are multiplied by PS2FrameFraction(). Measured with OPENBLOOD_PCFIXES_TEST=water in the disc's M05 pool: 3 to 4 ripples alive while 47 wades at 30 fps and at 144. The port's version leaves out the PS2's VIF ripple chain, which only the PS2 renderer reads.
ZHM3LevelControlM13::FrameUpdate (hitman3/levelcontrol/levelcontrolm13.cpp → port/hitman3/levelcontrol/_sdl/levelcontrolm13overridesdl.cpp) The revival on the table in Requiem: 47's health drains by 0.995 and the heartbeat boost by 0.9 each frame, and a change of his move speed by more than 0.5 between two frames gives him 5 back. Above 30 fps the drain was faster per second and the change per frame smaller, so the revival got harder. The PC is the same. The drains are PS2FrameDecay; the speed change is measured between PS2FrameTick() frames and only those give health back.

The PC version's variable-frame-rate code

The PC build was written for variable frame rates; docs/development/pc-differences/engine-core.md and gui-and-input.md record where it differs. What the port does with each:

Difference PS2 per frame? Port
Blood decay, pow(0.99, dt × 60) in ZBloodSplatters::ClassFrameUpdate yes adopted per 1/30 s (above)
Map panning, scale / 60 against scale / 30 yes, at 60 fps fixed per 1/60 s, the PS2's speed (above); PC tuning halves the speed
Newspaper zoom, DeltaFrameTime × 8 against × 2 no, time-based on both PC tuning selects the faster zoom
Cloth step, 1/50 s against 1/40 s no, a fixed-step accumulator the launcher's PC physics (docs/guide/enhancements.md); the double-draw fix above is the port's own
Ragdoll frame guard in CRagdoll2::Move yes adopted above 30 fps (above)
Ragdoll sub-steps, 4 against 2 in MoveRagdoll no; the guard fixes the rate the launcher's PC physics

Left as they are

Code Effect
checkvisible.cpp: work every 10th frame runs more often (CPU only)
draw-cache cleanup by frame count (zolddrawbase.cpp, frame count − 8) entries are dropped sooner (memory only)
ZHashTable's load average (zhash.h:129) per lookup, not per frame
ZWeaponDetails::Update (weapondetails.cpp), the rotating weapon in the hideout's and the planning screen's weapon menus the stick turns, pans and zooms it a fixed amount each frame, so faster above 30. The rate the PS2 ran it at is not known (the hideout's level control sets 30 fps, the front end runs at 60), so it is unchanged.
ZHM3Boid (hm3boid.cpp): a shot bird's fall drag (0.99 a frame, Fall), the banking ease (0.01 a frame, UpdateLocalSpace) and the force smoothing birds bank and slow down faster above 30; their flight itself integrates DeltaFrameTime
ZPlayer's pelvis bob amplitude (zplayer.cpp, an average of 0.9 a frame) reaches the same amplitude, sooner; only with g_PelvisBob above 0
Tension that scene scripts add each time they run (hm3actor.si.cpp) a script that adds tension every update adds it as often as the scheduler runs it

Verification

OPENBLOOD_TRACE_FRAMERATE=1 logs once a second how often the ragdolls, rigid bodies and cloth stepped and the time they took, each rigid body as it is set up, and how fast the pad pans the map (port/engine/fysix/_sdl/physicstracesdl.cpp). The runs below played the PS2 disc with a test mod that, two seconds into a mission, points the camera at the nearest person, throws him as a ragdoll (obm.physics.ragdoll) and logs the body's position every 0.05 s of game time, or lifts a rigid body and activates it (CRigidBody::Command("Activate")).

  • At 30 fps the port is the PS2: with OPENBLOOD_DETERMINISTIC=1, the build without these fixes and the build with them gave byte-identical logs: the ragdoll in A Vintage Year (241 positions over 12 s) and the falling library chandelier in Flatline (201 positions over 10 s).
  • Ragdoll, A Vintage Year: at 30 fps the body lands after about 1 s, slides and rests at 10.0 s. Without the fixes at 144 fps it moved 57 units in the first 0.5 s and rested at 3.0 s; with them it moves 25, lands after about 1 s, slides at 4 to 5 units a second (5.5 at 30), steps 39 to 40 times a second (about 105 frames a second skipped) and rests at 8.1 s.
  • Cloth, A Vintage Year: 40 steps a second at 30 fps, 66 at 144 before the double-draw fix, 39 to 42 after it.
  • Map: 1.93 map scales a second at 30 fps (29 frames held), 2.000 at 144.
  • The HUD meters, the tension and aim lag, the camera offsets, the text fades and M13's revival are exact by construction: at 30 fps the helpers return the PS2's own numbers, and above it a decay per second, a lerp per second or a step per second equals the PS2's. They were not measured in play.

What is still unverified

The engine's per-frame code above was searched for systematically: every PC function that reads the frame time where its PS2 partner does not (build/pc-compare/diffs.tsv, the PC decompilation), the PC's constant changes (1/30 to 1/60, 30 to 60, decay factors), and src/ for decays, eases and counters without a frame time. What remains untested at rates above 30:

  • Scene scripts may count frames in their own loops. That is not visible from the engine; each level would have to be played through at these rates.
  • No level was played through above 30 fps. The fixes for the meters, actors' tension and aim, the camera offsets, the text fades and the Requiem revival are checked by construction, not in play.
  • The weapon details screen and the birds are unchanged (above).

The rates above 30 therefore stay experimental for whole missions, but ragdolls, rigid bodies, cloth, blood, the map, the HUD meters and actors' tension and aim are now frame-rate independent.

Cost

Every frame runs the whole engine update, and the port skins characters on the CPU, crowds included. At 144 fps the update, the skinning and the draw-list submission share 6.9 ms; the debug overlay's performance tab shows whether a scene fits. A frame that misses its slot is simply late, and the next one starts at once. The frame guard makes a ragdoll cost about a third more per second at 144 than at 30 (40 steps instead of 30: 1.3 ms a second against 1.0 for one ragdoll, measured).