Hm... Still borked. Seems hard to fix.

This commit is contained in:
Themaister 2011-02-18 03:14:32 +01:00
parent 056a590671
commit aa648c1a49
2 changed files with 10 additions and 11 deletions

View File

@ -21,6 +21,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
#include <assert.h>
#ifdef _WIN32 #ifdef _WIN32
#define _WIN32_WINNT 0x0501 #define _WIN32_WINNT 0x0501
@ -59,7 +60,7 @@ struct delta_frame
bool used_real; bool used_real;
}; };
#define UDP_FRAME_PACKETS 16 #define UDP_FRAME_PACKETS 32
struct netplay struct netplay
{ {
@ -462,6 +463,7 @@ static void simulate_input(netplay_t *handle)
handle->buffer[ptr].simulated_input_state = handle->buffer[prev].real_input_state; handle->buffer[ptr].simulated_input_state = handle->buffer[prev].real_input_state;
handle->buffer[ptr].is_simulated = true; handle->buffer[ptr].is_simulated = true;
handle->buffer[ptr].used_real = false;
} }
static void parse_packet(netplay_t *handle, uint32_t *buffer, unsigned size) static void parse_packet(netplay_t *handle, uint32_t *buffer, unsigned size)
@ -476,7 +478,7 @@ static void parse_packet(netplay_t *handle, uint32_t *buffer, unsigned size)
fprintf(stderr, "Got frame %u, state 0x%x\n", frame, state); fprintf(stderr, "Got frame %u, state 0x%x\n", frame, state);
if (frame < handle->frame_count && frame >= handle->read_frame_count) if (frame <= handle->frame_count && frame >= handle->read_frame_count)
{ {
size_t ptr = (handle->read_ptr + frame - handle->read_frame_count) % handle->buffer_size; size_t ptr = (handle->read_ptr + frame - handle->read_frame_count) % handle->buffer_size;
handle->buffer[ptr].is_simulated = false; handle->buffer[ptr].is_simulated = false;
@ -529,8 +531,11 @@ bool netplay_poll(netplay_t *handle)
return false; return false;
} }
fprintf(stderr, "Other %lu, Read: %lu, Self: %lu, Buffer_size: %lu\n", handle->other_ptr, handle->read_ptr, handle->self_ptr, handle->buffer_size);
if (res == 1) if (res == 1)
{ {
size_t first_read = handle->read_ptr;
do do
{ {
uint32_t buffer[UDP_FRAME_PACKETS * 2]; uint32_t buffer[UDP_FRAME_PACKETS * 2];
@ -542,12 +547,12 @@ bool netplay_poll(netplay_t *handle)
} }
parse_packet(handle, buffer, UDP_FRAME_PACKETS); parse_packet(handle, buffer, UDP_FRAME_PACKETS);
} while ((handle->read_ptr != handle->self_ptr) && poll_input(handle, false) == 1); } while ((handle->read_ptr != handle->self_ptr) && poll_input(handle, handle->other_ptr == NEXT_PTR(handle->self_ptr) && first_read == handle->read_ptr) == 1);
} }
else else
{ {
// Cannot allow this. Should not happen though. // Cannot allow this. Should not happen though.
if (handle->self_ptr == handle->read_ptr) if (NEXT_PTR(handle->self_ptr) == handle->other_ptr)
{ {
SSNES_WARN("Netplay connection hung up. Will continue without netplay.\n"); SSNES_WARN("Netplay connection hung up. Will continue without netplay.\n");
return false; return false;
@ -555,15 +560,9 @@ bool netplay_poll(netplay_t *handle)
} }
if (handle->read_ptr != handle->self_ptr) if (handle->read_ptr != handle->self_ptr)
{
simulate_input(handle); simulate_input(handle);
handle->buffer[PREV_PTR(handle->self_ptr)].used_real = false;
}
else else
{
handle->buffer[PREV_PTR(handle->self_ptr)].is_simulated = false;
handle->buffer[PREV_PTR(handle->self_ptr)].used_real = true; handle->buffer[PREV_PTR(handle->self_ptr)].used_real = true;
}
return true; return true;
} }

View File

@ -525,7 +525,7 @@ static void parse_input(int argc, char *argv[])
case 'F': case 'F':
g_extern.netplay_sync_frames = strtol(optarg, NULL, 0); g_extern.netplay_sync_frames = strtol(optarg, NULL, 0);
if (g_extern.netplay_sync_frames < 32) if (g_extern.netplay_sync_frames > 32)
g_extern.netplay_sync_frames = 32; g_extern.netplay_sync_frames = 32;
break; break;