Skip to content
New issue

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

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

Already on GitHub? # to your account

[Web] Frame Rate and UI fix #699

Closed
wants to merge 10 commits into from
Closed

Conversation

cemalgnlts
Copy link

@cemalgnlts cemalgnlts commented Apr 30, 2024

Hi,

I think a few frames are omitted because of the floating point numbers in this line.

static U64 s_tick = 0;
void TimerTickShim(void *userdata)
{
CoronaAppContext *context = (CoronaAppContext*) userdata;
float frameDuration = 1000.0f / (float) context->getFPS();
U64 now = Rtt_AbsoluteToMilliseconds(Rtt_GetAbsoluteTime());
if (now - s_tick >= frameDuration) // 60fps ==> 1000/60 = 16.66666 msec
{
s_tick = now;
context->TimerTick();

I can show it with JS (you can paste it into the console in Developer Options and see the result):

function runTest(fps) {
  let last = 0;
  let actualFrame = 0;
  let s2dFrame = 0;
  
  const FPS = fps ?? 60;
  const MS_PER_SEC = 1000 / FPS;
  
  function onFrame(now) {
      actualFrame += 1;
  
      if(now - last >= MS_PER_SEC) {
          last = now;
          s2dFrame += 1;
      }
  
      if(actualFrame % (FPS * 3) === 0) { // run 3 seconds
          completed();
      } else {
          requestAnimationFrame(onFrame);
      }
  }
  
  requestAnimationFrame(onFrame);
  
  function completed() {
      console.log("Frame got: %s, S2D got: %s, Missed Frame: %s", actualFrame, s2dFrame, actualFrame - s2dFrame);
  }
}

The results I get when I run this example:

runTest() // Frame got: 180, S2D got: 92, Missed Frame: 88
runTest(30) // Frame got: 90, S2D got: 31, Missed Frame: 59

If we update it this way and try again:

- const MS_PER_SEC = 1000 / FPS;
+ const MS_PER_SEC = 1 / FPS;
runTest() // Frame got: 180, S2D got: 180, Missed Frame: 0
runTest(30) // Frame got: 90, S2D got: 90, Missed Frame: 0

I also fixed that if the status text is blank on the loading screen, the height is reset and the logo slides down.

The commit history may look a bit dirty because the code is not compiled properly in linux (maybe I couldn't do it).

@cemalgnlts cemalgnlts requested a review from Shchvova as a code owner April 30, 2024 14:48
@CLAassistant
Copy link

CLAassistant commented Apr 30, 2024

CLA assistant check
All committers have signed the CLA.

@Shchvova
Copy link
Contributor

Shchvova commented Nov 1, 2024

Was this fixed by other PR already?

@Shchvova Shchvova closed this Dec 8, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants