Skip to content

Type the VQA IO commands and name the seek origin - #5

Merged
mischa85 merged 2 commits into
nativefrom
vqa-seek
Sep 9, 2026
Merged

Type the VQA IO commands and name the seek origin#5
mischa85 merged 2 commits into
nativefrom
vqa-seek

Conversation

@mischa85

@mischa85 mischa85 commented Sep 9, 2026

Copy link
Copy Markdown
Owner

The seek origin used to ride in the Buffer parameter as an integer cast to a pointer,
so every handler decoded it with (int)(intptr_t)buffer and compared it against bare
0, 1 and 2. It was never data: it says which operation is wanted, and action
already dispatches, so it belongs in the command.

VQACMD_SEEK_SET 7    from the start
VQACMD_SEEKPEEK 8    as SEEK_SET, then read one byte
VQACMD_SEEK_CUR 10   signed offset from the current position
VQACMD_SEEK_END 11   back from the end

Buffer now means nothing for a seek, which is what the original comment always said.
The set becomes enum VQACommandType : int32_t, matching VQAErrorType.

  • 0 casts added, 23 removed, and two nested switches collapse into the command switch.
  • VQACMD_SEEK is deleted rather than redefined, so the compiler had to find all 15 call
    sites and 5 handlers.

Verification

Behaviour checked differentially, not by inspection: the loop cache seek modelled under
both protocols over 84 combinations of origin, offset and cache position, comparing error
code and resulting offset. All 84 match.

No harness reaches these sources, so dstream.cpp, loader.cpp, task.cpp and
buffer_.cpp were compiled here against a stubbed io.h: no errors, warning counts
unchanged from baseline. vqa.cpp and audiomovie.cpp rest on Windows CI. The seek path
has no runtime coverage, since that needs a real VQA file.

One guard worth naming: the loop cache handler gets an explicit VQACMD_SEEK_END error
case, because its outer default: falls through with error = 0 and would otherwise have
started reporting success for a seek it cannot do.

Not done here

action stays long. The audio handler shares VQA_H_FUNC with the stream handlers but
carries the VQAAUDIO_ set through the same slot, and those values overlap VQACMD_
one for one, so typing the parameter needs the typedef split per role first.

Known, pre-existing and left alone

VQACMD_SEEK_END is implemented inconsistently and no caller uses it. For nbytes = 10,
VQAClass::CacheHandler lands at file_size - 11 (counting back from the end) while the
disk and file handlers land at file_size + 10 (a POSIX signed offset, past the end), and
the loop cache handler errors. That divergence predates this PR; naming the command at
least makes it visible instead of hiding behind a decoded 2.

@mischa85 mischa85 added the no change record Mechanical change with no player- or modder-visible effect label Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Development builds of 2f4e4d8:

The links work without a GitHub account. Artifacts expire after 90 days, and this comment follows the latest successful build.

@mischa85 mischa85 changed the title Name the seek origin the VQA protocol carries Make the seek origin part of the seek command Sep 9, 2026
@mischa85 mischa85 changed the title Make the seek origin part of the seek command Type the VQA IO commands and name the seek origin Sep 9, 2026
@mischa85
mischa85 merged commit 48c7159 into native Sep 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no change record Mechanical change with no player- or modder-visible effect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant