2015-12-23 20:25:28 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2016-01-10 03:06:50 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2016-09-13 21:06:23 +00:00
|
|
|
* Copyright (C) 2016 - Gregor Richards
|
2015-12-23 20:25:28 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-09-05 22:56:00 +00:00
|
|
|
#include <compat/strl.h>
|
2016-09-13 01:18:00 +00:00
|
|
|
#include <stdio.h>
|
2016-09-05 22:56:00 +00:00
|
|
|
|
2015-12-23 20:25:28 +00:00
|
|
|
#include "netplay_private.h"
|
2016-09-03 05:48:25 +00:00
|
|
|
|
2016-09-13 01:18:00 +00:00
|
|
|
#include "retro_assert.h"
|
|
|
|
|
2016-09-03 05:48:25 +00:00
|
|
|
#include "../../autosave.h"
|
|
|
|
|
2015-12-23 20:25:28 +00:00
|
|
|
/**
|
|
|
|
* pre_frame:
|
|
|
|
* @netplay : pointer to netplay object
|
|
|
|
*
|
|
|
|
* Pre-frame for Netplay (normal version).
|
|
|
|
**/
|
2015-12-24 18:23:46 +00:00
|
|
|
static void netplay_net_pre_frame(netplay_t *netplay)
|
2015-12-23 20:25:28 +00:00
|
|
|
{
|
2016-01-27 06:28:03 +00:00
|
|
|
retro_ctx_serialize_info_t serial_info;
|
|
|
|
|
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-12 02:01:47 +00:00
|
|
|
if (netplay_delta_frame_ready(netplay, &netplay->buffer[netplay->self_ptr], netplay->self_frame_count))
|
|
|
|
{
|
2016-09-13 21:05:28 +00:00
|
|
|
serial_info.data_const = NULL;
|
|
|
|
serial_info.data = netplay->buffer[netplay->self_ptr].state;
|
|
|
|
serial_info.size = netplay->state_size;
|
|
|
|
|
|
|
|
if (!core_serialize(&serial_info))
|
|
|
|
{
|
|
|
|
/* If the core can't serialize properly, we must stall for the
|
|
|
|
* remote input on EVERY frame, because we can't recover */
|
|
|
|
netplay->stall_frames = 0;
|
|
|
|
}
|
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-12 02:01:47 +00:00
|
|
|
}
|
2016-01-27 06:28:03 +00:00
|
|
|
|
2015-12-23 20:25:28 +00:00
|
|
|
netplay->can_poll = true;
|
|
|
|
|
|
|
|
input_poll_net();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* post_frame:
|
|
|
|
* @netplay : pointer to netplay object
|
|
|
|
*
|
|
|
|
* Post-frame for Netplay (normal version).
|
|
|
|
* We check if we have new input and replay from recorded input.
|
|
|
|
**/
|
2015-12-24 18:23:46 +00:00
|
|
|
static void netplay_net_post_frame(netplay_t *netplay)
|
2015-12-23 20:25:28 +00:00
|
|
|
{
|
2016-09-14 00:37:53 +00:00
|
|
|
netplay->self_ptr = NEXT_PTR(netplay->self_ptr);
|
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-12 02:01:47 +00:00
|
|
|
netplay->self_frame_count++;
|
2015-12-23 20:25:28 +00:00
|
|
|
|
2016-09-13 21:33:26 +00:00
|
|
|
/* Only relevant if we're connected */
|
|
|
|
if (!netplay->has_connection)
|
|
|
|
return;
|
|
|
|
|
2015-12-23 20:25:28 +00:00
|
|
|
/* Skip ahead if we predicted correctly.
|
|
|
|
* Skip until our simulation failed. */
|
2016-09-14 00:35:10 +00:00
|
|
|
while (netplay->other_frame_count < netplay->read_frame_count &&
|
|
|
|
netplay->other_frame_count < netplay->self_frame_count)
|
2015-12-23 20:25:28 +00:00
|
|
|
{
|
|
|
|
const struct delta_frame *ptr = &netplay->buffer[netplay->other_ptr];
|
|
|
|
|
2016-02-03 15:58:30 +00:00
|
|
|
if (memcmp(ptr->simulated_input_state, ptr->real_input_state,
|
|
|
|
sizeof(ptr->real_input_state)) != 0
|
2015-12-23 20:25:28 +00:00
|
|
|
&& !ptr->used_real)
|
|
|
|
break;
|
|
|
|
netplay->other_ptr = NEXT_PTR(netplay->other_ptr);
|
|
|
|
netplay->other_frame_count++;
|
|
|
|
}
|
|
|
|
|
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-12 02:01:47 +00:00
|
|
|
/* Now replay the real input if we've gotten ahead of it */
|
2016-09-14 00:35:10 +00:00
|
|
|
if (netplay->other_frame_count < netplay->read_frame_count &&
|
|
|
|
netplay->other_frame_count < netplay->self_frame_count)
|
2015-12-23 20:25:28 +00:00
|
|
|
{
|
2016-01-27 06:28:03 +00:00
|
|
|
retro_ctx_serialize_info_t serial_info;
|
2015-12-23 20:25:28 +00:00
|
|
|
|
|
|
|
/* Replay frames. */
|
|
|
|
netplay->is_replay = true;
|
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-12 21:50:38 +00:00
|
|
|
netplay->replay_ptr = netplay->other_ptr;
|
|
|
|
netplay->replay_frame_count = netplay->other_frame_count;
|
2015-12-23 20:25:28 +00:00
|
|
|
|
2016-09-12 11:42:35 +00:00
|
|
|
if (netplay->replay_frame_count < netplay->self_frame_count)
|
|
|
|
{
|
|
|
|
serial_info.data = NULL;
|
|
|
|
serial_info.data_const = netplay->buffer[netplay->replay_ptr].state;
|
|
|
|
serial_info.size = netplay->state_size;
|
2016-09-13 01:18:00 +00:00
|
|
|
|
2016-09-12 11:42:35 +00:00
|
|
|
core_unserialize(&serial_info);
|
|
|
|
}
|
2015-12-23 20:25:28 +00:00
|
|
|
|
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-12 02:01:47 +00:00
|
|
|
while (netplay->replay_frame_count < netplay->self_frame_count)
|
2015-12-23 20:25:28 +00:00
|
|
|
{
|
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-12 02:01:47 +00:00
|
|
|
serial_info.data = netplay->buffer[netplay->replay_ptr].state;
|
2016-01-27 06:28:03 +00:00
|
|
|
serial_info.size = netplay->state_size;
|
2016-04-10 14:35:25 +00:00
|
|
|
serial_info.data_const = NULL;
|
2016-01-27 06:28:03 +00:00
|
|
|
|
2016-05-07 23:33:57 +00:00
|
|
|
core_serialize(&serial_info);
|
2016-01-27 06:28:03 +00:00
|
|
|
|
2016-05-01 23:35:28 +00:00
|
|
|
#if defined(HAVE_THREADS)
|
2016-05-09 06:17:35 +00:00
|
|
|
autosave_lock();
|
2015-12-23 20:25:28 +00:00
|
|
|
#endif
|
2016-05-07 23:33:57 +00:00
|
|
|
core_run();
|
2016-05-01 23:35:28 +00:00
|
|
|
#if defined(HAVE_THREADS)
|
2016-05-09 06:17:35 +00:00
|
|
|
autosave_unlock();
|
2015-12-23 20:25:28 +00:00
|
|
|
#endif
|
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-12 02:01:47 +00:00
|
|
|
netplay->replay_ptr = NEXT_PTR(netplay->replay_ptr);
|
|
|
|
netplay->replay_frame_count++;
|
2015-12-23 20:25:28 +00:00
|
|
|
}
|
|
|
|
|
2016-09-14 00:35:10 +00:00
|
|
|
if (netplay->read_frame_count < netplay->self_frame_count)
|
2016-09-12 11:42:35 +00:00
|
|
|
{
|
2016-09-14 00:35:10 +00:00
|
|
|
netplay->other_ptr = netplay->read_ptr;
|
|
|
|
netplay->other_frame_count = netplay->read_frame_count;
|
2016-09-14 14:06:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-14 00:35:10 +00:00
|
|
|
netplay->other_ptr = netplay->self_ptr;
|
|
|
|
netplay->other_frame_count = netplay->self_frame_count;
|
2016-09-12 11:42:35 +00:00
|
|
|
}
|
2015-12-23 20:25:28 +00:00
|
|
|
netplay->is_replay = false;
|
|
|
|
}
|
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-12 02:01:47 +00:00
|
|
|
|
2016-09-12 13:13:26 +00:00
|
|
|
/* If we're supposed to stall, rewind */
|
|
|
|
if (netplay->stall)
|
|
|
|
{
|
|
|
|
retro_ctx_serialize_info_t serial_info;
|
|
|
|
|
|
|
|
netplay->self_ptr = PREV_PTR(netplay->self_ptr);
|
|
|
|
netplay->self_frame_count--;
|
|
|
|
|
|
|
|
serial_info.data = NULL;
|
|
|
|
serial_info.data_const = netplay->buffer[netplay->self_ptr].state;
|
|
|
|
serial_info.size = netplay->state_size;
|
|
|
|
|
|
|
|
core_unserialize(&serial_info);
|
|
|
|
}
|
2015-12-23 20:25:28 +00:00
|
|
|
}
|
2015-12-24 18:23:46 +00:00
|
|
|
static bool netplay_net_init_buffers(netplay_t *netplay)
|
2015-12-23 20:25:28 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
2016-01-27 06:09:30 +00:00
|
|
|
retro_ctx_size_info_t info;
|
2015-12-23 20:25:28 +00:00
|
|
|
|
|
|
|
if (!netplay)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
netplay->buffer = (struct delta_frame*)calloc(netplay->buffer_size,
|
|
|
|
sizeof(*netplay->buffer));
|
2016-09-13 21:05:28 +00:00
|
|
|
|
2015-12-23 20:25:28 +00:00
|
|
|
if (!netplay->buffer)
|
|
|
|
return false;
|
|
|
|
|
2016-05-07 23:33:57 +00:00
|
|
|
core_serialize_size(&info);
|
2016-01-27 06:09:30 +00:00
|
|
|
|
|
|
|
netplay->state_size = info.size;
|
2015-12-23 20:25:28 +00:00
|
|
|
|
|
|
|
for (i = 0; i < netplay->buffer_size; i++)
|
|
|
|
{
|
|
|
|
netplay->buffer[i].state = malloc(netplay->state_size);
|
|
|
|
|
|
|
|
if (!netplay->buffer[i].state)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-24 18:23:46 +00:00
|
|
|
static bool netplay_net_info_cb(netplay_t* netplay, unsigned frames)
|
2015-12-23 20:25:28 +00:00
|
|
|
{
|
2016-05-12 08:20:14 +00:00
|
|
|
if (netplay_is_server(netplay))
|
2015-12-23 20:25:28 +00:00
|
|
|
{
|
2016-05-12 10:03:43 +00:00
|
|
|
if (!netplay_send_info(netplay))
|
2015-12-23 20:25:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-12 10:03:43 +00:00
|
|
|
if (!netplay_get_info(netplay))
|
2015-12-23 20:25:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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-12 21:50:38 +00:00
|
|
|
/* * 2 + 1 because:
|
|
|
|
* Self sits in the middle,
|
|
|
|
* Other is allowed to drift as much as 'frames' frames behind
|
|
|
|
* Read is allowed to drift as much as 'frames' frames ahead */
|
|
|
|
netplay->buffer_size = frames * 2 + 1;
|
2015-12-23 20:25:28 +00:00
|
|
|
|
2015-12-24 18:23:46 +00:00
|
|
|
if (!netplay_net_init_buffers(netplay))
|
2015-12-23 20:25:28 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
netplay->has_connection = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct netplay_callbacks* netplay_get_cbs_net(void)
|
|
|
|
{
|
|
|
|
static struct netplay_callbacks cbs = {
|
2015-12-24 18:23:46 +00:00
|
|
|
&netplay_net_pre_frame,
|
|
|
|
&netplay_net_post_frame,
|
|
|
|
&netplay_net_info_cb
|
2015-12-23 20:25:28 +00:00
|
|
|
};
|
|
|
|
return &cbs;
|
2016-01-10 03:06:50 +00:00
|
|
|
}
|