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
11.32k stars 2.18k forks source link

Lock FF button & frameskip [ad-hoc netplay enhancement] #14686

Open samosaphile opened 3 years ago

samosaphile commented 3 years ago

What should happen

During ad-hoc PPSSPP netplay:

1) fast forward button should be completedly disabled. (Either when you press it, it does nothing or it should be removed from GUI / no longer in view there).

2) Also frame skip should either be disabled (or there should be some kind of ppsspp check, like it'll only allow frameskip if both devices are using the exact same frame skip number maybe?)

The reason I suggest above is so many times either me or my friend has pressed fast forward (by accident) during ad-hoc netplay and it's caused the game to disconnect. And just yesterday, I was playing with a friend and noticed he wasn't in sync and skipping across the screen. We then realized it was because he had frame skip 1 on and I was playing with frame skip disabled... :P (after he disabled frameskip the sync problems completely disappeared)

Who would this benefit

The entire multiplayer community would benefit?

Platform (if relevant)

No response

Games this would be useful in

Applies to all games capable of online play.

Other emulators or software with a similar feature

No response

Checklist

anr2me commented 3 years ago

I agreed for number 1, because if one player is running at a different speed it may cause a desync, although some games will try to balance the performance by running at the speed of the slowest device (this will make the faster device to feels like a slow motion similar to the slower device even when the FPS looked full speed 60/60 on the faster device) but not all games do this, thus speed could affects stability.

However, for number 2, not sure whether disabling frame skip is a good idea or not, because if one of the player is using a low-end device, it may be struggling to keep up the pace with other [faster] players, thus will runs at a different speed that others (which may have similar effect to number 1)

ghost commented 3 years ago

I agree for both. Maybe if you got lower fps then needed just display a message that is not optimal for online play. This is also useful for the future to be infrastructure support

unknownbrackets commented 3 years ago

Does it help to enable real time clock sync instead of disabling frameskip? That is, to enable frame skip at the same time?

The danger of frame skip without real time clock sync is that it'll sync network stuff even less frequently in real time.

-[Unknown]

anr2me commented 3 years ago

I also have worries that frame skipping could skipped some of the network sync too, but i don't know how PSP frame skipping worked, it wasn't as simple as ignoring the display list submission?

unknownbrackets commented 3 years ago

PPSSPP frameskip simply ignores drawing commands. It still technically submits the display list. The only way the game can "tell" is that graphics it asked to be drawn are not drawn in VRAM (but copies it requests in a display list DO happen.) It still takes as many emulated cycles (game time, not real time), and no CPU operations are skipped. So it only skips actual device GPU work.

The reason it could effect network, though, is because of timing. The entire timing engine of the emulator is based on graphics.

If I draw a frame 60 times per 1.001 seconds (NTSC), then it means that every 16.683ms the emulator does all the work it needs to for a frame.

On a PSP with its 333 Mhz CPU and 166 Mhz GPU, this might take 16ms to complete. But on a lot of more modern devices (even phones), it's quicker. So instead, maybe it takes 10ms. After that, we just sit and wait for 6ms until it's time to do something again.

Let me explain with ASCII art:

           / these are frames
|==========1==========2==========3==========4==========|
                           ^ this represents PSP time

So here we have a normal game situation, it running all the time and drawing 4 frames. But now let's see what happens on a 4.3 Ghz PC:

  / the PC is so fast, it's already done in 1/10th the time
|=---------1==--------2=---------3=---------4==--------|
     ^ the emulated world is "paused" during this time

As you can see, most of the time the emulated PSP is not actually running. It runs just for a few milliseconds, and then it's already blazed through everything a real PSP would've done in a fraction of the time. There's nothing else to do, so PPSSPP waits for the next frame before resuming emulation.

But now let's see what happens if I enabled frameskip 1 (with auto disabled):

                      / now the frame is skipped
|=---------1===------------------3==-------------------|
             ^ PPSSPP gets both frames of work done

Because of frameskipping, there's less checkpoints. So PPSSPP plows through two frames of work at a time, before pausing. Now, some 5ms after the frame started, the emulated PSP already thinks an entire 30ms have gone by. PPSSPP then pauses until the next frame, and continues.

This is the whole point of frameskip, it's exactly what it's supposed to do. By doing all the work for the next frame, we maximize the chances of rendering that second frame in time on slow devices. If the first half of the frame went a bit faster and we waited, we'd lose precious time and might fall behind in the second half. So this is 100% intentional behavior.

However, netplay wants to be in sync. This is why the "force real clock sync" option exists. Again, it's worse for performance (read my paragraph just above, it doesn't do that), but it changes the timing model of PPSSPP:

   / checkpoints are now every 2ms
|=-*==*==*=1*==*=-*=-*2=*==*=-*==3*=-*=-*==*4=*=-*==*=-|
                      ^ frames still happen too

In "force real clock sync" mode, it checkpoints every 2ms instead, and tries to keep the real clock and game clock mostly aligned. Doing it more often than that is likely to make it fall behind a bunch.

Note that if you're on a laptop in Windows, we no longer sleep because Windows is actually not capable of delaying a thread with such fine resolution (Linux can handle it fine.) "Force real clock sync" will probably burn your battery faster and make your fan spin up more. Android is not as affected because Linux/Android is better in this regard.

Really, you want all involved devices using "force real clock sync" for netplay. Otherwise, weaker and more powerful devices could easily see time move at very different paces within these 16ms or 33ms bubbles.

-[Unknown]

samosaphile commented 3 years ago

Does it help to enable real time clock sync instead of disabling frameskip? That is, to enable frame skip at the same time?

The danger of frame skip without real time clock sync is that it'll sync network stuff even less frequently in real time.

-[Unknown]

Didn't test real time clock sync with frame skip yet. I don't think real time clock sync alone helps much anymore after more testing (without frame skip).

I don't think my friend needs frame skip any longer. As the main game where we were having issues was Colin McRae Rally 2005. But we figured out how to do cheats and it turns out there's a cheat which fixes the sun flare lag on this game.