Skip to content

Partial reloads 03: Resume a ZR68C reload after the magazine is unloaded - #2285

Closed
sunzenshen wants to merge 2 commits into
NeotokyoRebuild:masterfrom
sunzenshen:reload-zr68c-resume
Closed

sunzenshen wants to merge 2 commits into
NeotokyoRebuild:masterfrom
sunzenshen:reload-zr68c-resume

Conversation

@sunzenshen

@sunzenshen sunzenshen commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Superseded by #2293 (same commits, opened from the upstream stack branch so GitHub links the stack). Review there; this draft stays open until the author closes it.

Description

Depends on NeotokyoRebuild/neoAssets#172 (the ZR68C resume animation, its phases file and three reload sounds).

Partial reloads 03: this PR pairs with neoAssets layer 03 (NeotokyoRebuild/neoAssets#172). The neoAssets stack under it, 01 (NeotokyoRebuild/neoAssets#176, the
Blender layout and tools) and 02 (NeotokyoRebuild/neoAssets#177, the ZR68C sources), carries no game change and has no neo PR. Next: 04
(resume after the load) and 05 (the bolt cycle, a chambered round).

Today a weapon switch during a reload cancels it, even after the old magazine has visibly dropped
out. With sv_neo_reload_experimental 1, a ZR68C reload that is interrupted after the unload step
continues when the ZR68C is drawn again: the draw brings up the fresh magazine, seats it, pulls the
bolt, and ends with a full magazine. The resume cannot be skipped; the gun can fire when it ends.

  • The flag defaults to 1 while the partial-reload stack is reviewed, so the resume works without setting it.
    The last PR of the stack sets the default back to 0. The flag is read once when the map starts (into the game
    rules), so a change applies from the next map.
  • Third person: a resumed reload shows the reload gesture to other players and in the owner's third-person
    view. The one shared-file change is in hl2mp_playeranimstate (+8 lines). The resume starts in Deploy, after the
    weapon switch, so NEO's weapon-switch reset in multiplayer_animstate.cpp cleared the gesture after one frame. The
    resume's reload event carries a RELOAD_EVENT_RESUMED marker, and only that event adopts the new weapon after the
    gesture starts. A plain reload event runs master's code.
  • Other weapons are unchanged at either flag value. Only a weapon whose script has a
    ReloadPhases block uses the new code, and only the ZR68C has one.
  • An uninterrupted reload keeps its animation, sound and fire time. Its magazine counts at the
    seat (1.333 s) instead of at 2.217 s, so a switch after the seat keeps the full magazine and plays
    a normal draw. A switch before the unload cancels the reload as it does today.

How it works

  • Weapon script: ReloadPhases lists, per viewmodel sequence, when each reload step (1_unload,
    2_load, 3_cycle) counts its ammo and when each of its sounds plays. A resume after step N lists
    only the later steps, so it never replays an earlier step's sound. A row's resume key names the
    sequence that resumes a reload interrupted after that step. The table is the one of the sequence the
    reload plays, so reload and reloadempty can time and resume differently. The ZR68C rows come from neoAssets
    (#base "weapon_zr68c_reload_phases.txt"), whose export sets every time from markers in the
    .blend, so the timing follows the animation. If that file is missing, the parser warns and the
    weapon plays the normal reload.
  • End of the resume: the reload finishes and fire is allowed when the resume clip ends; the clip
    ends with both hands at rest. The resume uses no ReloadReadyBeforeEnd-style time; an uninterrupted
    reload keeps today's code, ReloadReadyBeforeEnd included.
  • Switch: when the last finished step's row names a resume, the weapon keeps that step and its
    table (both networked). Nothing else outlasts the switch.
  • Draw: such a weapon empties its clip (the old magazine is gone) and plays the resume
    (drawunloaded_reload, 2.767 s) instead of draw. A second switch during the resume, before its
    load, plays the resume again. The load step loads the magazine through the normal
    reload finish. The load, its tap and the cycle sounds play as separate pieces, because the single reload sound
    cannot start part way. A switch or a drop stops them.
  • Drop: a dropped weapon, also one dropped on death, cancels its reload, so the next owner does
    not resume it.
  • Code layout: master's Reload, FinishReload, Deploy, Holster and ItemBusyFrame each gain one
    ReloadPhasesOn* call. Every hook holds the flag gate, so master's functions only gain one-line calls.
  • Sound names: weapon_zr68.reload_load, reload_load_part2 and reload_cycle, as
    reload_<step>[_part<N>]. In drawunloaded_reload they start at 1.367 s, 1.800 s and 2.100 s; the load counts
    at 1.400 s and the cycle at 2.333 s (times from the neoAssets phases file). The waves keep the ) prefix of weapon_zr68.npc_reload, the entry NEO plays for a
    reload (RELOAD_NPC).
  • Prediction: the four phase fields are networked on the weapon and the flag on the game rules, so the client
    predicts the resume with the server's values.

Why one glued resume sequence, not a runtime join

A runtime join (a transition clip, then reload started at the resume frame) hitched for about 85 ms at the join,
because of how the engine updates a predicted viewmodel's sequence, and saved only about 3.9 KB per model. The model
duplicates the reload frames in the glued clip instead.

Cost with the flag off

  • Network: the weapon's phase fields and the flag never change, so they send nothing per tick (4 constant weapon
    props, 1 rules bit). Prediction fields are constant.
  • Memory: every weapon info carries an empty phase vector (about 32 B). Tables are filled only for weapons whose
    script has them (the ZR68C). The sound pieces are precached with the weapons soundscript at either flag value.
  • CPU: the hooks return at the flag check. The animstate early return and the script parse run ungated; both are
    cheap.
  • neo_predicted_viewmodel.cpp now reads the weapon data by reference instead of copying it every frame.

How to review

  1. Flag-off entry points: the five ReloadPhasesOn* calls in Reload, FinishReload, Deploy, Holster,
    ItemBusyFrame. Each hook returns first on the flag.
  2. The shared hunk in hl2mp_playeranimstate.cpp, guarded by RELOAD_EVENT_RESUMED.
  3. The parser: ReloadPhases in neo_weapon_parse.cpp.
  4. The assets: read neoAssets#172 with this PR (script rows, drawunloaded_reload, the three sound pieces).
  5. Test in game: "How to test" below, flag 1 then 0.
  6. Evidence: "Results", including the flag-off trace against master.

How to test

  1. Load a map (sv_neo_reload_experimental is 1 by default in this PR).
  2. Join a team and take the ZR68C.
  3. Fire a few rounds, press reload, and switch to the secondary after the magazine has dropped out
    (about 0.7 s in). Switch back: the draw should bring up a fresh magazine, seat it, pull the bolt,
    and end with 30 rounds. Holding fire during this draw should not fire.
  4. Repeat, but switch before the magazine drops: the reload should cancel and keep the old magazine.
  5. Repeat with sv_neo_reload_experimental 0, and with another rifle at both values: the reload
    should behave as it does today.

Results

Tested with this PR's head and the neoAssets layer 03 assets (NeotokyoRebuild/neoAssets#172), Linux Debug client and dedicated server, no
warnings. The layer 03 resume clip is 2 frames longer than the one first tested here (a slower magazine clasp flip
in drawunloaded): the resume runs 2.767 s instead of 2.70 s, and its load and every sound piece come 0.067 s later
(load 1.400 s instead of 1.333 s). The third-person, remote-view and flag-off rows were measured with the earlier clip; the code
they exercise did not change, and the clip length does not enter the flag-off path.

check result
ZR68C, flag 1, switch after the drop drawunloaded_reload, clip 0 to 30 at 1.41 s after the draw (table 1.400 s), fire allowed at the clip end (2.767 s); fire held through the draw fires no shot
Third person (owner) Reload_ZR68C plays whole (2.51 s) inside the 2.767 s resume; no studio.cpp asserts
ZR68C, flag 0 plain draw, clip 0 kept, fresh reload 0 to 30
Tachi, flag 1, plain reload and switch mid-reload master behavior, no ReloadPhases
Switch before the unload plain draw, then the normal reload; no resume
Headless TDM, 12 bots, 1 round, flag 1 PASS, match_end=True, 0 asserts

Flag-off against master. One script (ZR68C then Tachi: taps, tactical and dry reloads, switches at 0.3 s and 1.0 s)
logged per tick the weapon, clip, in-reload state, viewmodel sequence and next-attack time, on this PR and on master.
The difference between the PR and master is smaller than master's own run-to-run noise: 194 aligned states, one
differing block (a wall-clock race in the script on master), next-attack times equal within one tick at every state
entry. A second pair confirms it; the two PR runs are identical.

Remote view. A bot replayed the owner's inputs (bot_mimic) and the owner's client rendered it as a remote player.
After a switch and the resume draw, the bot's Reload_ZR68C restarts on the draw and plays whole. Its sound pieces
start +0.452 s and +0.753 s after the load piece (table: +0.433 s, +0.733 s; the same spacing in layer 03). cl_showerror shows no prediction error at the switch, the
resume draw, the fill or the end. This used a bot observed by one client, not two human clients.

The only asserts are engine baseline asserts (m_simThinkList at join, one client shadow-leaf assert); none fires
during a reload.

Known limits

  • Only the ZR68C resumes, and only after the unload step.
  • During the resume draw the clip reads 0 until the load, as during an empty reload today. A bot
    with an enemy within 250 units switches to its secondary then (EquipBestWeaponForThreat), as in
    today's empty reload; its next draw resumes again.
  • A switch after the seat skips the bolt pull: the magazine is already in. Today's reload does the
    same after 2.217 s.
  • Changing the flag during a map applies from the next map.

Later PRs

Resuming after the load and after the cycle, keeping a chambered round (31/30), and partial reloads.
The script block and the phase list are shaped so those add rows and cases, not new syntax.

Toolchain

  • Linux GCC Distro Native (Linux Mint 22.3, GCC 13.3.0)

Linked Issues

sunzenshen added a commit to sunzenshen/neo that referenced this pull request Nov 9, 2026
Bring in the NeotokyoRebuild#2285 commits that cut its gesture change, add the
one-line reload-phase hooks and rename the sound pieces. Each
conflict resolves to the slice: it keeps its gesture fit, which
short resumes and reload_skipcycle need. The hook layout and the
sound names follow in their own commits.
sunzenshen added a commit to sunzenshen/neo that referenced this pull request Nov 9, 2026
Master's Reload, FinishReload, Deploy, Holster and ItemBusyFrame
gain one hook call each, as in NeotokyoRebuild#2285, and each hook checks the
reload-phase gate itself. The slice's chamber, dry-chamber and
reload_skipcycle starts move into ReloadPhasesOnRequest, and the
chambered round kept through a magazine change comes back from
ReloadPhasesOnFinish, so master's clip arithmetic keeps
GetMaxClip1.

The header additions move into one commented block. Behavior is
unchanged with the flag on and off.
sunzenshen added a commit to sunzenshen/neo that referenced this pull request Nov 9, 2026
Name each piece reload_<step>, and a step's later pieces _part2, as
in NeotokyoRebuild#2285: reload_unload, reload_load, reload_load_part2,
reload_cycle. The wav files and the phases-file keys are renamed to
match in neoAssets. The ) prefix stays.
@sunzenshen sunzenshen changed the title Resume a ZR68C reload after the magazine is unloaded Partial reloads 03: Resume a ZR68C reload after the magazine is unloaded Nov 9, 2026
Behind sv_neo_reload_experimental, a weapon whose script has a
ReloadPhases block (only the ZR68C here) keeps its reload step across a
weapon switch: switched after the unload, the next draw plays the
resume sequence named in the phases file, loads the magazine and plays
the remaining sound pieces. A switch before the unload still cancels
the reload, and a dropped weapon cancels it.

The parser reads the ReloadPhases block and stores tables only for
weapons that have one. Master's Reload, FinishReload, Deploy, Holster
and ItemBusyFrame each gain one call into a hook that checks the flag.
The flag is read once per map into the game rules. The third-person
reload gesture adopts the new weapon on a resumed reload, so NEO's
weapon-switch reset does not clear it. The viewmodel reads the weapon
data by reference instead of copying it every frame.
Reviewers can test the resume without setting the cvar. The last PR of
the partial-reload stack sets the default back to 0.
@sunzenshen

Copy link
Copy Markdown
Contributor Author

Closing in favor of #2293 because this PR cannot be inserted into the PR stack.

@sunzenshen sunzenshen closed this Nov 9, 2026
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