hrydgard / ppsspp

A PSP emulator for Android, Windows, Mac and Linux, written in C++. Want to contribute? Join us on Discord at https://discord.gg/5NJB6dD or just send pull requests / issues. For discussion use the forums at forums.ppsspp.org.
https://www.ppsspp.org
Other
10.8k stars 2.12k forks source link

Framerate timing issue with hcount (Blade Dancer)? #4040

Closed unknownbrackets closed 10 years ago

unknownbrackets commented 10 years ago

I think there are other games with timing issues, but I don't know which of them / if any of them time the way Blade Dancer does.

On a real PSP, Blade Dancer gets the following timings:

Currently in PPSSPP, Blade Dancer gets 45 / 22 respectively.

The timing code does something like the following (maybe it skips saving hcount in some cases.

static u32 last = 0;
while (true)
{
    sceDisplayWaitVblankStart();

    u32 hcount = sceDisplayGetAccumulatedHcount();
    float v = ((hcount - last) / 286.0f) * sceDisplayGetFramePerSec();

    // Draw based on v and the desired fps.
    last = hcount;
}

Anyway, I thought the 286.0f was interesting. I tried running this in psplink, logging v, and I got a loop with 59.940060 from the PSP. From PPSSPP, I got 59.730476 for every fourth value.

So, I tried 286.0f for hCountPerVblank. The result was 60 / 30. That'd be great, but I'm aiming for 45 / 30 (well, that said, the game's "target" FPS is 60.0f in the menu, so maybe that is correct..) I tried values in between 285.72f and 286.0f, and it just scaled both FPS values.

Anyway, the test seems more correct with 286.0f, but I'm not really sure. Maybe it's my fault and it's drift. Or maybe 286.0f is correct.... just not sure.

Does anyone know of other games with bad timing affected by this value?

-[Unknown]

raven02 commented 10 years ago

Just wonder where to test this code ? sceDisplay ?

unknownbrackets commented 10 years ago

Yeah, this line:

const float hCountPerVblank = 285.72f; // insprired by jpcsp

It will probably only matter for games which call sceDisplayGetAccumulatedHcount().

-[Unknown]

raven02 commented 10 years ago

I see. Tried few games like BOF3 ,Silient Hill and Black Rock Shooter , seems to be not helping.

unknownbrackets commented 10 years ago

Dragoneer's Aria is affected by this too.

It uses the same basic formula. Here's it expressed a different way: hcountPerFrame = (286.0 * 59.9400599) / 60.0;

That suggests it should be, more accurately, 285.714285523333, per vblank.

Or, I wonder if vblanks should occur 59.9400599 times per second? Doing that and 286 does make the game show 30 fps.

const double frameMs = 1000.0 / 59.9400599;

Guess I should try to test that...

-[Unknown]

unknownbrackets commented 10 years ago

My tests seem to indicate that 1000.0 / 59.9400599 is more correct. I timed 240 frames (239 after the starting frame) with both values and on the PSP.

PSP (expected): 3987346us 59.9401 value: 3987326us (20us different) master value: 3983342us (4004us different)

Hmm.

-[Unknown]

hrydgard commented 10 years ago

59.94 is the NTSC field rate, so it would certainly not be unusual.