Commit Graph

33 Commits

Author SHA1 Message Date
Gregor Richards
f710303a40 Somewhat fixing support for savestateless cores
Without early saves we couldn't properly detect savestateless cores. We
still can't, really, but we can at least EVENTUALLY detect this
condition. netplay_net has been fixed to do so.
2016-09-29 20:48:39 -04:00
Gregor Richards
1470b6672b Fix delay_frames=0 mode to work with the recent late-loading workaround 2016-09-28 15:45:52 -04:00
Gregor Richards
f665881d6d Workarounds for cores that can't be saved early
Netplay now never serializes/unserializes cores before 60 frames have
been emulated. This is a workaround for buggy cores and documented as
such.
2016-09-27 20:49:16 -04:00
Gregor Richards
bd354cd275 Making all Netplay sockets should be cloexec
All Netplay sockets should close-on-exec. There is no reason for
xdg-screensaver to keep Netplay sockets alive.
2016-09-25 23:26:32 -04:00
Gregor Richards
60449e8928 Checks for some netplay syscall errors and NULL deref errors 2016-09-24 18:48:55 -04:00
Gregor Richards
fcd57801bd When we replay, resimulate input so that it doesn't judder between
remote states
2016-09-24 08:12:08 -04:00
Gregor Richards
fa5b75b635 Bugfixes in how we reset state on a late Netplay connection 2016-09-23 22:21:53 -04:00
Gregor Richards
1503b3d42f Don't serialize frame 0 in netplay, as the core may not yet be ready 2016-09-22 17:36:46 -04:00
Twinaphex
34944cac0f remove unused variables 2016-09-22 22:01:35 +02:00
Gregor Richards
4b370cf55e Re-add TCP_NODELAY in host mode. 2016-09-21 17:31:19 -04:00
Gregor Richards
c2d9e7a538 Support for late connection to Netplay host mode
This changes netplay host mode's behavior in net (normal) mode from
immediately blocking to waiting for a connection while allowing the game
to run, like spectator mode.
2016-09-21 17:26:02 -04:00
Gregor Richards
ad336df709 Reimplemented Netplay spectate mode
Spectate mode is now far more similar to net (normal) mode, and, more
importantly, it works. In addition, spectate mode will not fast-forward
to catch up with the server if it lags too far behind.
2016-09-15 23:06:32 -04:00
Gregor Richards
2a0202ccf5 Making Netplay check frequency configurable. 2016-09-15 23:06:32 -04:00
Gregor Richards
7271d1c3fa Support for frame CRCing
Every frame (soon to be configurable), the server does a CRC-32 hash and
sends it to the client. If the client finds that its own hash is
different from the server's, it requests a fresh savestate.

This is a last-ditch effort to sync if all else fails, and it's a
best-effort situation. The size of the buffer should assure that we
always still have the frame around to CRC, but I imagine there are edge
cases where we don't. If you're in an edge case, the CRC is ignored.
2016-09-15 23:06:32 -04:00
Gregor Richards
5f90f072ba Documentation fixup
Fixing up some of the function documentation, and documenting the packet
formats.
2016-09-15 23:06:32 -04:00
Gregor Richards
27188e102d Support for savestate loading over netplay
Assuming the core supports saving/loading states, and (crucially)
assuming the states are portable across the architectures on both sides
of the connection, Netplay now supports the transmission of savestates.
Right now the frontend doesn't actually send any such requests, as it's
not clear exactly where the code for that should be.

This works in either direction, although I'll admit I have no idea what
happens if they both load at the same time.
2016-09-15 23:06:32 -04:00
Gregor Richards
96186438ec Remote pausing
Support for remote pausing, and with it, support for Netplay pausing the
frontend correctly. With this patch alone this doesn't work, since
there's no clean way for the frontend to tell Netplay that it's paused.
2016-09-15 23:06:32 -04:00
Gregor Richards
9bc78d25a0 Minor stylistic fixes for clarity and consistency with the rest of
RetroArch.
2016-09-14 10:06:57 -04:00
Gregor Richards
d4e074dbed Moved the advance of self_ptr to the same place as the advance of
self_frame_count, which is much clearer.
2016-09-13 21:32:57 -04:00
Gregor Richards
99b5ed92ed other should always be <= both real AND self. Before this fix, it was
possible (albeit unlikely) for the remote to get so far ahead of us that
they actually overwrote our own current data :)
2016-09-13 21:32:57 -04:00
Gregor Richards
6829b80c6b Reimplemented disconnection based on stalls. If we stall for 10 seconds,
disconnect.
2016-09-13 21:32:57 -04:00
Gregor Richards
0ccc39769d Adding my copyright lines to files I've touched. 2016-09-13 21:32:57 -04:00
Gregor Richards
ae8e695644 Fixing indentation to align with the rest of RetroArch. 2016-09-13 21:32:57 -04:00
Gregor Richards
f9f4e15d33 Removing commented-out code (mostly old UDP stuff) 2016-09-13 21:32:57 -04:00
Gregor Richards
147d739197 Fixed stall_frames=0 mode to only block if frames are actually needed.
Rather than counting on the complexicon of used_real calculations, set
used_real when... real is used. (Problem: If the core doesn't read input
at all, used_real won't be set; todo: test with handhelds.) Minor
resilience fixes.
2016-09-13 21:32:57 -04:00
Gregor Richards
c7d0bf90f6 Bugfixes to bring Netplay Nouveau from "kinda working" to "stably
working":

(1) Fixups to the stall logic to make sure it always receives frames
while stalling :)

(2) Disused the used_real field. It was misconfigured and would
frequently claim to be using real data when real data hadn't been
used... this means more replays for now, but used_real will be readded.
(TODO)

(3) Stall duration is now related to sync frames, and thus configurable.

(4) Delta frames were having the good ol' initialization problem, as
frame==0 was indistinguishable from unused. Quickfixed by adding a
"used" field, but maybe there's a better way.

(5) If serialization fails, switch immediately to blocking mode
(stall_frames = 0). Blocking mode barely works, but if serialization
fails, no mode will work!

(6) I'm not sure which bug my replaying-from-previous-frame was trying
to fix, but the correct behavior is to replay from the last frame we had
vital information, not the frame prior. Notionally this should just be
an efficiency thing, but unsigned arithmetic at 0 made this a "just
ignore all input from now on" thing.
2016-09-13 21:32:57 -04:00
Gregor Richards
07e869ccae is_simulated was confusing and poorly named. Using have_remote in its
place, which is simply true if we've received remote data. Could also
just use read_frame_crount instead, but this keeps the info frame-local.
2016-09-13 21:32:57 -04:00
Gregor Richards
4f16a19f5e Rather than stalling by blocking and becoming unresponsive, stall by
replaying the same frame. TODO: Maybe mute the audio?
2016-09-13 21:32:57 -04:00
Gregor Richards
5edfbeafb0 Switched Netplay over to TCP. A lot of the stalling logic had to change
for this, and in particular, it now sometimes stalls in a way that makes
it very difficult to actually input anything (whoops :) ). Simply
setting the sync frames higher avoids that. With supported cores, this
is incredibly risilient, but when it fails, it mostly fails to freezing,
which is less than ideal.

TODO: Stall frames should be configurable. All the UDP code is still
there but commented out, should be gutted. The original fast-forward
code is now commented out, but really both fast-forward and stalling
should be options; the only complication is that it needs to send
simulated self-input for fast-forward.
2016-09-13 21:32:57 -04:00
Gregor Richards
69b7dc0d08 Multitudinous fixes and updates to Netplay. Had to be one commit since
they're mostly related:

(1) Renamed frame_count to self_frame_count to be consistent with all
other names.

(2) Previously, it was possible to overwrite data in the ring buffer
that hadn't yet been used. Now that's not possible, but that just
changes one breakage for another: It's now possible to miss the NEW
data. The final resolution for this will probably be requesting stalls.
This is accomplished simply by storing frame numbers in the ring buffer
and checking them against the 'other' head.

(3) In TCP packets, separated cmd_size from cmd. It was beyond pointless
for these to be combined, and restricted cmd_size to 16 bits, which
will probably fail when/if state loading is supported.

(4) Readahead is now allowed. In the past, if the peer got ahead of us,
we would simply ignore their data. Thus, if they got too far ahead of
us, we'd stop reading their data altogether. Fabulous. Now, we're happy
to read future input.

(5) If the peer gets too far ahead of us (currently an unconfigurable 10
frames), fast forward to catch up. This should prevent desync due to
clock drift or stutter.

(6) Used frame_count in a few places where ptr was used. Doing a
comparison of pointers on a ring buffer is a far more dangerous way to
assure we're done with a task than simply using the count, since the
ring buffer is... well, a ring.

(7) Renamed tmp_{ptr,frame_count} to replay_{ptr,frame_count} for
clarity.

(8) Slightly changed the protocol version hash, just to assure that
other clients wouldn't think they were compatible with this one.

(9) There was an off-by-one error which, under some circumstances, could
allow the replay engine to run a complete round through the ring buffer,
replaying stale data. Fixed.
2016-09-13 21:32:57 -04:00
twinaphex
075aea2289 Header include cleanups 2016-09-06 00:56:00 +02:00
twinaphex
23612cb26f Header include cleanups 2016-09-03 07:48:25 +02:00
twinaphex
aabb1e409c Move netplay code to network/netplay dir 2016-05-19 11:46:54 +02:00