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

[Web] Frame Rate and UI fix #699

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

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).

@CLAassistant
Copy link

CLAassistant commented Apr 30, 2024

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants