X Tutup
Skip to content

AUDIO: Mark more AdLib symbols as const#6266

Merged
bluegr merged 2 commits intoscummvm:masterfrom
ccawley2011:adlib-ms-const
Jan 28, 2025
Merged

AUDIO: Mark more AdLib symbols as const#6266
bluegr merged 2 commits intoscummvm:masterfrom
ccawley2011:adlib-ms-const

Conversation

@ccawley2011
Copy link
Member

No description provided.

Comment on lines -1228 to +1230
OplInstrumentDefinition *_instrumentBank;
const OplInstrumentDefinition *_instrumentBank;
// Pointer to the rhythm instrument definitions.
OplInstrumentDefinition *_rhythmBank;
const OplInstrumentDefinition *_rhythmBank;
Copy link
Member

@bluegr bluegr Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we want to make these two const?
They are accessed and updated by engine code, and making them const makes the engine code ugly with no real gain

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, the purpose of this PR is to make every statically define OplInstrumentDefinition objects constant (to have them located in .rodata instead of having them copied in .data at load time).
But this means that these pointers must be declared as pointing to const data.
This prevents some engines needing to it to update the tables.

@lephilousophe
Copy link
Member

Following a chat with @bluegr here is a proposal (as a commit to squash) that removes the writable pointer.
All const_cast needed to write to the const pointer are justified in a comment.

const_cast is valid in these cases because the pointed data is
dynamically allocated.
@bluegr
Copy link
Member

bluegr commented Jan 28, 2025

Thanks for your work @ccawley2011 and @lephilousophe!

The implementation is much cleaner now. I've tested the changes with Simon the Sorcerer 1 and Elvira 2, and both work great.

Nice work! Merging

@bluegr bluegr merged commit c7e3415 into scummvm:master Jan 28, 2025
8 checks passed
@ccawley2011 ccawley2011 deleted the adlib-ms-const branch January 28, 2025 21:51
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.

3 participants

X Tutup