-
Notifications
You must be signed in to change notification settings - Fork 151
tweak(credits): Decouple credits scroll timing from render update #2057
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
base: main
Are you sure you want to change the base?
tweak(credits): Decouple credits scroll timing from render update #2057
Conversation
aa81f5a to
7fa2519
Compare
| // TheSuperHackers @tweak Credits scroll timing is now decoupled from the render update. | ||
| const UnsignedInt scrollIntervalMs = static_cast<UnsignedInt>(m_scrollRatePerFrames * MSEC_PER_LOGICFRAME_REAL); | ||
| const UnsignedInt now = timeGetTime(); | ||
| if (now - m_lastScrollTime < scrollIntervalMs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this approach because it is inaccurate. Scrolling should be specified as scroll distance per second and then scale each frame by the render frame rate. Probably better to have a start time, then take new time, calculate position offset, check if position has reached new integer, then continue update, otherwise wait next update and fractional move.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New code looks promising. Does it work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works for me :) Took me a minute to figure out how to use the On Screen Keyboard to get at the numpad keys 😆 and that they don't work while the snipping tool is recording for me. Once I got the FPS up and then started recording it seems as smooth on my machine at either framerate, and it maxed out at 70 something, it's old.
5a98add to
7d49889
Compare
Greptile Overview
|
| Filename | Overview |
|---|---|
| Generals/Code/GameEngine/Source/GameClient/Credits.cpp | Implemented time-based scrolling with catch-up logic for frame drops |
| GeneralsMD/Code/GameEngine/Source/GameClient/Credits.cpp | Implemented time-based scrolling with catch-up logic for frame drops |
Sequence Diagram
sequenceDiagram
participant GameLoop
participant CreditsManager
participant timeGetTime
Note over CreditsManager: init() or reset() called
CreditsManager->>timeGetTime: timeGetTime()
timeGetTime-->>CreditsManager: startTime
Note over CreditsManager: m_scrollStartTime = startTime<br/>m_lastScrollPixels = 0
loop Every frame
GameLoop->>CreditsManager: update()
alt m_isFinished
CreditsManager-->>GameLoop: return early
else not finished
CreditsManager->>timeGetTime: timeGetTime()
timeGetTime-->>CreditsManager: now
Note over CreditsManager: elapsedMs = now - m_scrollStartTime<br/>scrollSpeedPixelsPerMs = m_scrollRate / (m_scrollRatePerFrames * 33.33ms)<br/>expectedScrollPixels = elapsedMs * scrollSpeedPixelsPerMs<br/>pixelsToMove = expectedScrollPixels - m_lastScrollPixels
alt pixelsToMove < 1
CreditsManager-->>GameLoop: return (no scroll needed)
else pixelsToMove >= 1
Note over CreditsManager: m_lastScrollPixels = expectedScrollPixels
loop For each displayed credit line
Note over CreditsManager: Update position:<br/>pos.y += pixelsToMove * directionMultiplier
end
CreditsManager-->>GameLoop: credits scrolled
end
end
end
Summary
Changes
m_framesSinceStartedframe counter withm_lastScrollTimetimestamptimeGetTime()to measure elapsed time between scroll updatesTest plan
30FPS
https://github.com/user-attachments/assets/0215fd82-49f7-4c7c-9903-c8b0f53eb239
60FPS
https://github.com/user-attachments/assets/a45a847b-1f9d-4642-8ab3-23e30de25c04