Skip to content

Commit

Permalink
Revert "Fix source of netplay desyncs (#84)"
Browse files Browse the repository at this point in the history
This reverts commit 1ae59e3.
  • Loading branch information
carmiker committed Feb 13, 2024
1 parent 1ae59e3 commit 407df99
Showing 1 changed file with 10 additions and 36 deletions.
46 changes: 10 additions & 36 deletions libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,7 @@ static int overscan_v_top, overscan_v_bottom;
static int overscan_h_left, overscan_h_right;
static bool libretro_supports_option_categories = false;
static unsigned aspect_ratio_mode;
static unsigned tpulse; // A/B Button turbo pulse width in frames

static unsigned char tstate = 2; // A/B Button turbo pulse width counter 0 => lo, !0 => hi, in range [0, tpulse]
static int cur_x = 0; // Absolute x coordinate of zapper/arkanoid in pixels
static int cur_y = 0; // Absolute y coordinate of zapper in pixels
static unsigned char prevL = false; // => L Button is held; controls famicon disc drive
static unsigned char prevR = false; // => R Button is held; controls famicon disc drive
static const int tracked_input_state_size_bytes = 5; // Send the 5 previous fields as unsigned char
static unsigned tpulse;

static enum {
SHOW_CROSSHAIR_DISABLED,
Expand Down Expand Up @@ -601,7 +594,7 @@ static bool NST_CALLBACK gamepad_callback(Api::Base::UserData data, Core::Input:
{
input_poll_cb();

tstate = 2;
static unsigned tstate = 2;
bool pressed_l3 = false;

uint buttons = 0;
Expand Down Expand Up @@ -647,7 +640,7 @@ static bool NST_CALLBACK arkanoid_callback(Api::Base::UserData data, Core::Input
int min_x = overscan_h_left;
int max_x = 255 - overscan_h_right;

cur_x = min_x;
static int cur_x = min_x;
unsigned int button = 0;

switch (arkanoid_device)
Expand Down Expand Up @@ -708,8 +701,8 @@ static bool NST_CALLBACK zapper_callback(Api::Base::UserData data, Core::Input::
int min_y = overscan_v_top;
int max_y = 239 - overscan_v_bottom;

cur_x = min_x;
cur_y = min_y;
static int cur_x = min_x;
static int cur_y = min_y;
zapper.fire = 0;

if (show_crosshair)
Expand Down Expand Up @@ -816,7 +809,7 @@ static void poll_fds_buttons()
}

bool curL = pressed_l;
bool prevL = false;
static bool prevL = false;

if (curL && !prevL)
{
Expand All @@ -828,7 +821,7 @@ static void poll_fds_buttons()
prevL = curL;

bool curR = pressed_r;
bool prevR = false;
static bool prevR = false;

if (curR && !prevR && (fds->GetNumDisks() > 1))
{
Expand Down Expand Up @@ -1708,7 +1701,7 @@ size_t retro_serialize_size(void)
std::stringstream ss;
if (machine->SaveState(ss, Api::Machine::NO_COMPRESSION))
return 0;
return ss.str().size() + tracked_input_state_size_bytes;
return ss.str().size();
}

bool retro_serialize(void *data, size_t size)
Expand All @@ -1718,36 +1711,17 @@ bool retro_serialize(void *data, size_t size)
return false;

std::string state = ss.str();
if (state.size() + tracked_input_state_size_bytes > size)
if (state.size() > size)
return false;

std::copy(state.begin(), state.end(), reinterpret_cast<char*>(data));

unsigned char *tracked_input_state_ptr = reinterpret_cast<unsigned char*>(data) + state.size();

*tracked_input_state_ptr++ = tstate;
*tracked_input_state_ptr++ = (unsigned char) cur_x;
*tracked_input_state_ptr++ = (unsigned char) cur_y;
*tracked_input_state_ptr++ = prevL;
*tracked_input_state_ptr++ = prevR;

return true;
}

bool retro_unserialize(const void *data, size_t size)
{
size_t nestopia_savestate_size = size - tracked_input_state_size_bytes;
std::stringstream ss(std::string(reinterpret_cast<const char*>(data),
reinterpret_cast<const char*>(data) + nestopia_savestate_size));

unsigned char const *tracked_input_state_ptr = reinterpret_cast<unsigned char const*>(data) + nestopia_savestate_size;

tstate = *tracked_input_state_ptr++;
cur_x = (int) *tracked_input_state_ptr++;
cur_y = (int) *tracked_input_state_ptr++;
prevL = *tracked_input_state_ptr++;
prevR = *tracked_input_state_ptr++;

reinterpret_cast<const char*>(data) + size));
return !machine->LoadState(ss);
}

Expand Down

0 comments on commit 407df99

Please sign in to comment.