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

Simplify clock APIs; migrade fade effects to the new API #2232

Merged
merged 21 commits into from
Jan 8, 2025

Conversation

rr-
Copy link
Collaborator

@rr- rr- commented Jan 8, 2025

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
  • I have added a readme entry about my new feature or OG bug fix, or it is a different change

Clock API changes

This pull request simplifies the CLOCK_TIMER APIs. I've removed logical and draw frames, opting to use seconds (as decimals) throughout. Historically, this method was compromised by the turbo cheat, whose capability to alter the game pace made real-time measurements meaningless, but I managed to circumvent this problem with some tricks. CLOCK_TIMER is now split into two types: CLOCK_TIMER_REAL, which uses real-world time for tasks like player input debouncing or calculating rendered FPS, and CLOCK_TIMER_SIM (simulation), which adjusts for the turbo cheat speed multiplier. The APIs include the following functions:

  • ClockTimer_Sync: reset the timer state to now,
  • ClockTimer_PeekElapsed: return elapsed seconds since the last sync,
  • ClockTimer_TakeElapsed: return elapsed seconds since the last sync, and immediately sync again,
  • ClockTimer_CheckElapsed: check if the given time has passed since the last sync,
  • ClockTimer_CheckElapsedAndTake: check if the given time has passed since the last sync, and sync again if so.

Coincidentally, this fixes also #2231.

Fader API changes

The fader module has been updated to operate in seconds rather than logical frames as well. Since it was made to utilize the new timers, there was no need for Fader_Control anymore and it was removed. This means that the current draw value, and whether a fader is active, is determined solely by the elapsed time, making it entirely immutable. In addition, the multiple factory functions have been combined into a single Fader_Init function, which abandons FADER_ARGS in favor of plain arguments with the debuff being determined automatically to cut down on verbosity for API users. The call sites can opt for Fader_InitEx, which still supports the full FADER_ARGS. I've also replaced manual Output_DrawBlackRectangle calls with a dedicated Fader_Draw function, which further reduces complexity in usage.

All TR1 phases have transitioned to the new fader system, resulting in the removal of the old Output_Fade* APIs. This update went smoothly, except for the pause phase, which was a bit peculiar – it depended on the overlay fade effect maintaining its state across different phases. Specifically, a fade-out effect that began on the pause screen would continue into the game after a phase change. To avoid managing global state across phases, I decided to complete the fade within the pause phase itself. The downside is that it prevents player interaction during this short period. An alternative approach that could prevent this regression would be for the game phase to transfer its internal fader to the pause phase using PHASE_PAUSE_ARGS.

Testing

  • All fade effects and their durations
  • Turbo speed
  • 30/60 FPS (I expect it to have zero influence, so it's more of a sanity check)
  • Holding arrows in load/save game dialogs
  • Holding reset/unbind keys in the controls dialog
  • Underwater caustics
  • Health bar blinking
  • Text flashing
  • FPS counter
  • Demo timer (waiting without inputs)
  • Picture durations
  • Inventory ring animation speeds
  • 3D pickups UI speed

@rr- rr- added TRX bug A bug with TRX Internal The invisible stuff TR2 TR1 labels Jan 8, 2025
@rr- rr- self-assigned this Jan 8, 2025
@rr- rr- requested review from a team as code owners January 8, 2025 00:48
@rr- rr- requested review from lahm86, walkawayy and aredfan and removed request for a team January 8, 2025 00:48
@aredfan
Copy link
Collaborator

aredfan commented Jan 8, 2025

TR1X issues:

  • Initiate the demo mode from the main menu, then press action to skip. When you're back on the main menu, initiate the demo mode again and you'll get a black screen.
  • The eidos screen fades out as soon as it fades in.
  • On the main menu, the fade out is starting early when selecting load game, new game, gym, or exit to title. In the latest dev snapshot, the fade out would start when the inventory ring have closed.
  • If you select load game or exit to title while ingame. the fade out is faster. This also happens if you select new game from the gym level. In dev snapshot, you can see the inventory ring close fully during fade out whereas in the PR build, it's a black screen before that point.
  • The credits are showing for about 6.5 seconds between fades instead of 7.5.
  • In demo mode, if you have the FPS counter enabled, it overlaps with the health bar.
  • The fades in the final stats screen are a bit fast compared to the credits.

@rr- rr- force-pushed the fader-improvements branch 2 times, most recently from ab74e45 to 49fd51c Compare January 8, 2025 16:04
@rr-
Copy link
Collaborator Author

rr- commented Jan 8, 2025

@aredfan addressed all

@rr-
Copy link
Collaborator Author

rr- commented Jan 8, 2025

@aredfan I have proposed a different fade setup for TR1 in the latest commit, which makes ingame fades to black work the same as the main menu ones. Fades to transparency are working as they were. LMK how this change feels, if it's yay or nay.

@aredfan
Copy link
Collaborator

aredfan commented Jan 8, 2025

@aredfan I have proposed a different fade setup for TR1 in the latest commit, which makes ingame fades to black work the same as the main menu ones. Fades to transparency are working as they were. LMK how this change feels, if it's yay or nay.

I have to say I do like this change because it's visually neater to allow the ring to close before fading out, albeit a tiny bit slower when loading a savegame or exiting to the title. Regardless, yay is my answer. 😄

  • I found a new TR1X issue, when the main menu is fading out, you can see the backdrop persist but only just.

Screenshot

@rr- rr- force-pushed the fader-improvements branch from 3031ae7 to d9cbc33 Compare January 8, 2025 18:13
@rr-
Copy link
Collaborator Author

rr- commented Jan 8, 2025

@aredfan addressed – I changed the fader to ensure it has drawn the target state before I consider it deactivated.

@Richard-L
Copy link
Collaborator

Does the build here update when you say you've addressed something? #2232 (comment)

I might have an hour for some testing later tonight.

@rr-
Copy link
Collaborator Author

rr- commented Jan 8, 2025

Does the build here update when you say you've addressed something? #2232 (comment)

I might have an hour for some testing later tonight.

No. Edit: I've rebased it (which means I've updated that other PR with the changes from here)

Copy link
Collaborator

@aredfan aredfan left a comment

Choose a reason for hiding this comment

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

@aredfan addressed – I changed the fader to ensure it has drawn the target state before I consider it deactivated.

Thank you. Everything LGTM. 👍

@rr- rr- merged commit e73f1e9 into develop Jan 8, 2025
8 checks passed
@rr- rr- deleted the fader-improvements branch January 8, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internal The invisible stuff TR1 TR2 TRX bug A bug with TRX
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants