Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tr2/music_main: refactor music track handling #1905

Merged
merged 1 commit into from
Nov 16, 2024

Conversation

lahm86
Copy link
Collaborator

@lahm86 lahm86 commented Nov 15, 2024

Resolves #1899.

Checklist

  • I have read the coding conventions
  • I have added a changelog entry about what my pull request accomplishes, or it is an internal change

Description

This refactors the way music is checked when requested to play tracks. We introduce tracking, similar to TR1 - I think prior to 0.2, it was implicitly done by setting (or not setting) g_CD_TrackID before playing the music in various places, so it was difficult to keep track of that. That global is now redundant, although remains in place, along with the original Music_Play function (renamed).

Some tracks require to be enforced such as from flip effects (like completing the assault course) and mounting the skidoo. Tracked trigger tracks will not play in succession, provided the mode is the same when requesting to play them. So standing on a tile doesn't loop a track.

Attached is a test level which should behave the same played in OG as TR2X. So e.g. if you cross the "manual" secret track trigger, then collect a secret, the track will restart (similarly if you collect the secrets quickly before the track finishes each time). And if you cross the skidoo track trigger, then mount the skidoo itself, the music will restart, the same as OG. On the other foot, if you mount the skidoo first, wait for the track to completely finish, then cross the trigger for the same track, it doesn't play.

The assault course is a good place to test everything too, especially the delayed tracks there and ensuring Lara acknowledges beating the best time twice in a row. The test level can also be renamed to boat.tr2 to check a level with no ambience. Renaming it to house.tr2 will allow for example triggering the skidoo music, then ending the level, and ensuring the credits restart the track.

WALL.zip

@lahm86 lahm86 added TRX bug A bug with TRX TR2 labels Nov 15, 2024
@lahm86 lahm86 self-assigned this Nov 15, 2024
@lahm86 lahm86 requested review from a team as code owners November 15, 2024 20:47
@lahm86 lahm86 requested review from rr-, walkawayy and aredfan and removed request for a team November 15, 2024 20:47
Copy link

github-actions bot commented Nov 15, 2024

@@ -12,7 +12,7 @@
#define g_RhwFactor (*(float*)0x0046408C) // = 335544320.0f
#define g_CineTrackID (*(int32_t*)0x004640B0) // = 1
#define g_CineTickRate (*(int32_t*)0x004640B8) // = 0x8000
#define g_CD_TrackID (*(int16_t*)0x004640BC) // = -1
#define g_Legacy_CD_TrackID (*(int16_t*)0x004640BC) // = -1
Copy link
Collaborator

@rr- rr- Nov 16, 2024

Choose a reason for hiding this comment

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

Hi, this file is updated by progress.txt as well. Let's mark this variable with a + flag in progress.txt (without renaming it). This way, it'll be visible as g_CD_TrackID in IDA, while it'll be completely skipped in our codebase.

As for Music_Legacy_Play, we can safely remove its definitions altogether, considering how since 0.2 we're no longer trying to inject it (and thus are free to use our own signatures).

After these changes please make sure to run tools/tr2/generate_funcs to see all is compatible.
Apologies for not documenting this process better, but hopefully it won't be long until we can start freely refactoring the majority of the codebase.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you, and no - my apologies for not getting this bit right.

I've changed the variable back to OG and marked it as decompiled.

The legacy function is still in use though: below is with logging added, it's triggered when Lara completes the assault course (possibly elsewhere, but this one for sure). I'm assuming that flip effect does some comparison with the player's time and decides which track to play (22 is "gosh, that was my best time yet").

game/music/music_main.c 116 Music_Legacy_Play Legacy call for track: 22
game/music/music_main.c 149 Music_Play Playing track 22 (real: 19), mode: 0

image

This refactors the way music is checked when requested to play tracks.
Some tracks require to be enforced such as from flip effects, while
others are tracked, such as from regular triggers. Tracked tracks will
not play in succession, provided the mode is the same when requesting
to play them.

Resolves LostArtefacts#1899.
@lahm86 lahm86 force-pushed the issue-1899-refactor-music-mode branch from 38f8cf6 to cc9e501 Compare November 16, 2024 13:22
@lahm86 lahm86 merged commit 36eec3d into LostArtefacts:develop Nov 16, 2024
6 checks passed
@lahm86 lahm86 deleted the issue-1899-refactor-music-mode branch November 16, 2024 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TR2 TRX bug A bug with TRX
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

TR2X bug: some music triggers loop and others don't repeat
3 participants