trigger-segfault / OpenLRR

An open source re-implementation of LEGO Rock Raiders 🪨⛏
65 stars 5 forks source link

Front end RockWipe animation stutters when Main_GetTime is too high #64

Closed trigger-segfault closed 1 year ago

trigger-segfault commented 1 year ago

Describe the issue If your computer is kept on for long enough, the RockWipe (falling rocks) animation that plays when transitioning between front end screens begins to stutter and animate very inconsistently (sometimes it looks like its jumping back frames instead of forwards).

Expected behaviour The RockWipe animation should play smoothly (as fast as the game is ticking).

Steps to reproduce

  1. A) Keep your computer on for a long enough time (for example, when testing this, my computer had been on for over 21 days).
  2. B) Modify Main_GetTime to return the base value + some additional amount (like + 0x70000000) so that the returned value is high enough.
  3. When in the main menu, press Start Game, or any other menu item that brings you to another menu.

Cause The (incorrectly named) field frontGlobs.rockWipeSFXStartTime is a float, and holds the value returned by Main_GetTime after each tick. Single-precision floating point numbers cannot precisely store high integer values, so the value can either jump to be higher than the actual returned time, or lower. Some ticks, the value won't change at all because it is rounded down.

Solution

  1. Create a new global variable to hold frontGlobs.rockWipeSFXStartTime as an unsigned integer.
  2. In Front_RockWipe_Play, store Main_GetTime in the new global variable.
  3. Implement Front_Menu_Update and replace all uses of the old frontGlobs.rockWipeSFXStartTime global variable with the new unsigned one, never cast to a float before getting the delta between the current and last time.

Because of how big the Front_Menu_Update function is, it may be possible to hook into the function where the animation time is updated and only replace functionality around there.


Video

https://github.com/trigger-segfault/OpenLRR/assets/9752430/3653e8de-6e1f-4272-89b0-de1037136b93