work in progress to remove compile errors
This commit is contained in:
@@ -11,11 +11,14 @@ target_include_directories(GGPO PUBLIC
|
|||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/ggpo>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/ggpo>
|
||||||
)
|
)
|
||||||
|
|
||||||
if(WIN32 AND BUILD_SHARED_LIBS)
|
if(WIN32)
|
||||||
# Link to Multimedia API and Winsocks during a shared build.
|
target_compile_options(GGPO PRIVATE "/W4" "/WX")
|
||||||
target_link_libraries(GGPO PUBLIC winmm.lib ws2_32.lib)
|
if(BUILD_SHARED_LIBS)
|
||||||
add_definitions(-DGGPO_SHARED_LIB)
|
# Link to Multimedia API and Winsocks during a shared build.
|
||||||
add_definitions(-DGGPO_SDK_EXPORT)
|
target_link_libraries(GGPO PUBLIC winmm.lib ws2_32.lib)
|
||||||
|
add_definitions(-DGGPO_SHARED_LIB)
|
||||||
|
add_definitions(-DGGPO_SDK_EXPORT)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set_target_properties(GGPO PROPERTIES VERSION ${PROJECT_VERSION})
|
set_target_properties(GGPO PROPERTIES VERSION ${PROJECT_VERSION})
|
||||||
|
|||||||
@@ -30,6 +30,13 @@ if(UNIX)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
set(GGPO_LIB_SRC_NOFILTER
|
||||||
|
${GGPO_LIB_SRC_NOFILTER}
|
||||||
|
"lib/ggpo/platform_windows.cpp"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(GGPO_LIB_INC_NETWORK
|
set(GGPO_LIB_INC_NETWORK
|
||||||
"lib/ggpo/network/udp.h"
|
"lib/ggpo/network/udp.h"
|
||||||
"lib/ggpo/network/udp_msg.h"
|
"lib/ggpo/network/udp_msg.h"
|
||||||
|
|||||||
@@ -14,3 +14,4 @@ add_definitions(-D_UNICODE -DUNICODE)
|
|||||||
|
|
||||||
# Link against GGPO, winmm (Windows Multimedia API), and ws2_32 (Winsock).
|
# Link against GGPO, winmm (Windows Multimedia API), and ws2_32 (Winsock).
|
||||||
target_link_libraries(VectorWar LINK_PUBLIC GGPO winmm.lib ws2_32.lib)
|
target_link_libraries(VectorWar LINK_PUBLIC GGPO winmm.lib ws2_32.lib)
|
||||||
|
target_compile_options(VectorWar PRIVATE "/W4" "/WX")
|
||||||
|
|||||||
@@ -89,9 +89,9 @@ void GameState::ParseShipInputs(int inputs, int i, double *heading, double *thru
|
|||||||
*fire = inputs & INPUT_FIRE;
|
*fire = inputs & INPUT_FIRE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameState::MoveShip(int i, double heading, double thrust, int fire)
|
void GameState::MoveShip(int which, double heading, double thrust, int fire)
|
||||||
{
|
{
|
||||||
Ship *ship = _ships + i;
|
Ship *ship = _ships + which;
|
||||||
|
|
||||||
ggpo_log(ggpo, "calculation of new ship coordinates: (thrust:%.4f heading:%.4f).\n", thrust, heading);
|
ggpo_log(ggpo, "calculation of new ship coordinates: (thrust:%.4f heading:%.4f).\n", thrust, heading);
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ draw_fairness_graph_control(LPDRAWITEMSTRUCT di)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static INT_PTR CALLBACK
|
static INT_PTR CALLBACK
|
||||||
ggpo_perfmon_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
ggpo_perfmon_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM, LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
@@ -114,7 +114,7 @@ ggpo_perfmon_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
{
|
{
|
||||||
char pid[64];
|
char pid[64];
|
||||||
sprintf(pid, "%d", GetCurrentProcessId());
|
snprintf(pid, ARRAYSIZE(pid), "%d", GetCurrentProcessId());
|
||||||
SetWindowTextA(GetDlgItem(hwndDlg, IDC_PID), pid);
|
SetWindowTextA(GetDlgItem(hwndDlg, IDC_PID), pid);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -219,11 +219,11 @@ ggpoutil_perfmon_update(GGPOSession *ggpo, GGPOPlayerHandle players[], int num_p
|
|||||||
char fLocal[128], fRemote[128], fBandwidth[128];
|
char fLocal[128], fRemote[128], fBandwidth[128];
|
||||||
char msLag[128], frameLag[128];
|
char msLag[128], frameLag[128];
|
||||||
|
|
||||||
sprintf(msLag, "%d ms", stats.network.ping);
|
sprintf_s(msLag, ARRAYSIZE(msLag), "%d ms", stats.network.ping);
|
||||||
sprintf(frameLag, "%.1f frames", stats.network.ping ? stats.network.ping * 60.0 / 1000 : 0);
|
sprintf_s(frameLag, ARRAYSIZE(frameLag), "%.1f frames", stats.network.ping ? stats.network.ping * 60.0 / 1000 : 0);
|
||||||
sprintf(fBandwidth, "%.2f kilobytes/sec", stats.network.kbps_sent / 8.0);
|
sprintf_s(fBandwidth, ARRAYSIZE(fBandwidth), "%.2f kilobytes/sec", stats.network.kbps_sent / 8.0);
|
||||||
sprintf(fLocal, "%d frames", stats.timesync.local_frames_behind);
|
sprintf_s(fLocal, ARRAYSIZE(fLocal), "%d frames", stats.timesync.local_frames_behind);
|
||||||
sprintf(fRemote, "%d frames", stats.timesync.remote_frames_behind);
|
sprintf_s(fRemote, ARRAYSIZE(fRemote), "%d frames", stats.timesync.remote_frames_behind);
|
||||||
SetWindowTextA(GetDlgItem(_dialog, IDC_NETWORK_LAG), msLag);
|
SetWindowTextA(GetDlgItem(_dialog, IDC_NETWORK_LAG), msLag);
|
||||||
SetWindowTextA(GetDlgItem(_dialog, IDC_FRAME_LAG), frameLag);
|
SetWindowTextA(GetDlgItem(_dialog, IDC_FRAME_LAG), frameLag);
|
||||||
SetWindowTextA(GetDlgItem(_dialog, IDC_BANDWIDTH), fBandwidth);
|
SetWindowTextA(GetDlgItem(_dialog, IDC_BANDWIDTH), fBandwidth);
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ struct NonGameState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDisconnectTimeout(GGPOPlayerHandle handle, int now, int timeout) {
|
void SetDisconnectTimeout(GGPOPlayerHandle handle, int when, int timeout) {
|
||||||
for (int i = 0; i < num_players; i++) {
|
for (int i = 0; i < num_players; i++) {
|
||||||
if (players[i].handle == handle) {
|
if (players[i].handle == handle) {
|
||||||
players[i].disconnect_start = now;
|
players[i].disconnect_start = when;
|
||||||
players[i].disconnect_timeout = timeout;
|
players[i].disconnect_timeout = timeout;
|
||||||
players[i].state = Disconnecting;
|
players[i].state = Disconnecting;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ typedef struct GGPOPlayer {
|
|||||||
struct {
|
struct {
|
||||||
} local;
|
} local;
|
||||||
struct {
|
struct {
|
||||||
char ip_address[32];
|
char ip_address[32];
|
||||||
short port;
|
unsigned short port;
|
||||||
} remote;
|
} remote;
|
||||||
} u;
|
} u;
|
||||||
} GGPOPlayer;
|
} GGPOPlayer;
|
||||||
@@ -324,7 +324,7 @@ GGPO_API GGPOErrorCode __cdecl ggpo_start_session(GGPOSession **session,
|
|||||||
const char *game,
|
const char *game,
|
||||||
int num_players,
|
int num_players,
|
||||||
int input_size,
|
int input_size,
|
||||||
int localport);
|
unsigned short localport);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -404,9 +404,9 @@ GGPO_API GGPOErrorCode __cdecl ggpo_start_spectating(GGPOSession **session,
|
|||||||
const char *game,
|
const char *game,
|
||||||
int num_players,
|
int num_players,
|
||||||
int input_size,
|
int input_size,
|
||||||
int local_port,
|
unsigned int local_port,
|
||||||
char *host_ip,
|
char *host_ip,
|
||||||
int host_port);
|
unsigned int host_port);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ggpo_close_session --
|
* ggpo_close_session --
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ static const int DEFAULT_DISCONNECT_NOTIFY_START = 750;
|
|||||||
|
|
||||||
Peer2PeerBackend::Peer2PeerBackend(GGPOSessionCallbacks *cb,
|
Peer2PeerBackend::Peer2PeerBackend(GGPOSessionCallbacks *cb,
|
||||||
const char *gamename,
|
const char *gamename,
|
||||||
int localport,
|
uint16 localport,
|
||||||
int num_players,
|
int num_players,
|
||||||
int input_size) :
|
int input_size) :
|
||||||
_num_players(num_players),
|
_num_players(num_players),
|
||||||
@@ -62,7 +62,7 @@ Peer2PeerBackend::~Peer2PeerBackend()
|
|||||||
|
|
||||||
void
|
void
|
||||||
Peer2PeerBackend::AddRemotePlayer(char *ip,
|
Peer2PeerBackend::AddRemotePlayer(char *ip,
|
||||||
int port,
|
uint16 port,
|
||||||
int queue)
|
int queue)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -77,7 +77,7 @@ Peer2PeerBackend::AddRemotePlayer(char *ip,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GGPOErrorCode Peer2PeerBackend::AddSpectator(char *ip,
|
GGPOErrorCode Peer2PeerBackend::AddSpectator(char *ip,
|
||||||
int port)
|
uint16 port)
|
||||||
{
|
{
|
||||||
if (_num_spectators == GGPO_MAX_SPECTATORS) {
|
if (_num_spectators == GGPO_MAX_SPECTATORS) {
|
||||||
return GGPO_ERRORCODE_TOO_MANY_SPECTATORS;
|
return GGPO_ERRORCODE_TOO_MANY_SPECTATORS;
|
||||||
@@ -498,7 +498,7 @@ Peer2PeerBackend::DisconnectPlayerQueue(int queue, int syncto)
|
|||||||
Log("Changing queue %d local connect status for last frame from %d to %d on disconnect request (current: %d).\n",
|
Log("Changing queue %d local connect status for last frame from %d to %d on disconnect request (current: %d).\n",
|
||||||
queue, _local_connect_status[queue].last_frame, syncto, framecount);
|
queue, _local_connect_status[queue].last_frame, syncto, framecount);
|
||||||
|
|
||||||
_local_connect_status[queue].disconnected = true;
|
_local_connect_status[queue].disconnected = 1;
|
||||||
_local_connect_status[queue].last_frame = syncto;
|
_local_connect_status[queue].last_frame = syncto;
|
||||||
|
|
||||||
if (syncto < framecount) {
|
if (syncto < framecount) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
class Peer2PeerBackend : public IQuarkBackend, IPollSink, Udp::Callbacks {
|
class Peer2PeerBackend : public IQuarkBackend, IPollSink, Udp::Callbacks {
|
||||||
public:
|
public:
|
||||||
Peer2PeerBackend(GGPOSessionCallbacks *cb, const char *gamename, int localport, int num_players, int input_size);
|
Peer2PeerBackend(GGPOSessionCallbacks *cb, const char *gamename, uint16 localport, int num_players, int input_size);
|
||||||
virtual ~Peer2PeerBackend();
|
virtual ~Peer2PeerBackend();
|
||||||
|
|
||||||
|
|
||||||
@@ -46,8 +46,8 @@ protected:
|
|||||||
void CheckInitialSync(void);
|
void CheckInitialSync(void);
|
||||||
int Poll2Players(int current_frame);
|
int Poll2Players(int current_frame);
|
||||||
int PollNPlayers(int current_frame);
|
int PollNPlayers(int current_frame);
|
||||||
void AddRemotePlayer(char *remoteip, int reportport, int queue);
|
void AddRemotePlayer(char *remoteip, uint16 reportport, int queue);
|
||||||
GGPOErrorCode AddSpectator(char *remoteip, int reportport);
|
GGPOErrorCode AddSpectator(char *remoteip, uint16 reportport);
|
||||||
virtual void OnSyncEvent(Sync::Event &e) { }
|
virtual void OnSyncEvent(Sync::Event &e) { }
|
||||||
virtual void OnUdpProtocolEvent(UdpProtocol::Event &e, GGPOPlayerHandle handle);
|
virtual void OnUdpProtocolEvent(UdpProtocol::Event &e, GGPOPlayerHandle handle);
|
||||||
virtual void OnUdpProtocolPeerEvent(UdpProtocol::Event &e, int queue);
|
virtual void OnUdpProtocolPeerEvent(UdpProtocol::Event &e, int queue);
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
|
|
||||||
SpectatorBackend::SpectatorBackend(GGPOSessionCallbacks *cb,
|
SpectatorBackend::SpectatorBackend(GGPOSessionCallbacks *cb,
|
||||||
const char* gamename,
|
const char* gamename,
|
||||||
int localport,
|
uint16 localport,
|
||||||
int num_players,
|
int num_players,
|
||||||
int input_size,
|
int input_size,
|
||||||
char *hostip,
|
char *hostip,
|
||||||
int hostport) :
|
u_short hostport) :
|
||||||
_num_players(num_players),
|
_num_players(num_players),
|
||||||
_input_size(input_size),
|
_input_size(input_size),
|
||||||
_next_input_to_send(0)
|
_next_input_to_send(0)
|
||||||
@@ -149,8 +149,6 @@ SpectatorBackend::OnUdpProtocolEvent(UdpProtocol::Event &evt)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case UdpProtocol::Event::Disconnected:
|
case UdpProtocol::Event::Disconnected:
|
||||||
GGPOEvent info;
|
|
||||||
|
|
||||||
info.code = GGPO_EVENTCODE_DISCONNECTED_FROM_PEER;
|
info.code = GGPO_EVENTCODE_DISCONNECTED_FROM_PEER;
|
||||||
info.u.disconnected.player = 0;
|
info.u.disconnected.player = 0;
|
||||||
_callbacks.on_event(&info);
|
_callbacks.on_event(&info);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
class SpectatorBackend : public IQuarkBackend, IPollSink, Udp::Callbacks {
|
class SpectatorBackend : public IQuarkBackend, IPollSink, Udp::Callbacks {
|
||||||
public:
|
public:
|
||||||
SpectatorBackend(GGPOSessionCallbacks *cb, const char *gamename, int localport, int num_players, int input_size, char *hostip, int hostport);
|
SpectatorBackend(GGPOSessionCallbacks *cb, const char *gamename, uint16 localport, int num_players, int input_size, char *hostip, u_short hostport);
|
||||||
virtual ~SpectatorBackend();
|
virtual ~SpectatorBackend();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ SyncTestBackend::SyncTestBackend(GGPOSessionCallbacks *cb,
|
|||||||
_running = false;
|
_running = false;
|
||||||
_logfp = NULL;
|
_logfp = NULL;
|
||||||
_current_input.erase();
|
_current_input.erase();
|
||||||
strcpy(_game, gamename);
|
strcpy_s(_game, gamename);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the synchronziation layer
|
* Initialize the synchronziation layer
|
||||||
@@ -136,7 +136,7 @@ SyncTestBackend::IncrementFrame(void)
|
|||||||
|
|
||||||
// Verify that the checksumn of this frame is the same as the one in our
|
// Verify that the checksumn of this frame is the same as the one in our
|
||||||
// list.
|
// list.
|
||||||
SavedInfo info = _saved_frames.front();
|
info = _saved_frames.front();
|
||||||
_saved_frames.pop();
|
_saved_frames.pop();
|
||||||
|
|
||||||
if (info.frame != _sync.GetFrameCount()) {
|
if (info.frame != _sync.GetFrameCount()) {
|
||||||
@@ -163,7 +163,7 @@ SyncTestBackend::RaiseSyncError(const char *fmt, ...)
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
vsprintf(buf, fmt, args);
|
vsprintf_s(buf, ARRAY_SIZE(buf), fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
puts(buf);
|
puts(buf);
|
||||||
@@ -188,12 +188,12 @@ SyncTestBackend::BeginLog(int saving)
|
|||||||
|
|
||||||
char filename[MAX_PATH];
|
char filename[MAX_PATH];
|
||||||
CreateDirectoryA("synclogs", NULL);
|
CreateDirectoryA("synclogs", NULL);
|
||||||
sprintf(filename, "synclogs\\%s-%04d-%s.log",
|
sprintf_s(filename, ARRAY_SIZE(filename), "synclogs\\%s-%04d-%s.log",
|
||||||
saving ? "state" : "log",
|
saving ? "state" : "log",
|
||||||
_sync.GetFrameCount(),
|
_sync.GetFrameCount(),
|
||||||
_rollingback ? "replay" : "original");
|
_rollingback ? "replay" : "original");
|
||||||
|
|
||||||
_logfp = fopen(filename, "w");
|
fopen_s(&_logfp, filename, "w");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -209,9 +209,9 @@ void
|
|||||||
SyncTestBackend::LogSaveStates(SavedInfo &info)
|
SyncTestBackend::LogSaveStates(SavedInfo &info)
|
||||||
{
|
{
|
||||||
char filename[MAX_PATH];
|
char filename[MAX_PATH];
|
||||||
sprintf(filename, "synclogs\\state-%04d-original.log", _sync.GetFrameCount());
|
sprintf_s(filename, ARRAY_SIZE(filename), "synclogs\\state-%04d-original.log", _sync.GetFrameCount());
|
||||||
_callbacks.log_game_state(filename, (unsigned char *)info.buf, info.cbuf);
|
_callbacks.log_game_state(filename, (unsigned char *)info.buf, info.cbuf);
|
||||||
|
|
||||||
sprintf(filename, "synclogs\\state-%04d-replay.log", _sync.GetFrameCount());
|
sprintf_s(filename, ARRAY_SIZE(filename), "synclogs\\state-%04d-replay.log", _sync.GetFrameCount());
|
||||||
_callbacks.log_game_state(filename, _sync.GetLastSavedFrame().buf, _sync.GetLastSavedFrame().cbuf);
|
_callbacks.log_game_state(filename, _sync.GetLastSavedFrame().buf, _sync.GetLastSavedFrame().cbuf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,32 +36,35 @@ GameInput::init(int iframe, char *ibits, int isize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
GameInput::desc(char *buf, bool show_frame) const
|
GameInput::desc(char *buf, size_t buf_size, bool show_frame) const
|
||||||
{
|
{
|
||||||
ASSERT(size);
|
ASSERT(size);
|
||||||
int offset = 0;
|
size_t remaining = buf_size;
|
||||||
if (show_frame) {
|
if (show_frame) {
|
||||||
sprintf(buf, "(frame:%d size:%d ", frame, size);
|
remaining -= sprintf_s(buf, buf_size, "(frame:%d size:%d ", frame, size);
|
||||||
} else {
|
} else {
|
||||||
sprintf(buf, "(size:%d ", size);
|
remaining -= sprintf_s(buf, buf_size, "(size:%d ", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < size * 8; i++) {
|
for (int i = 0; i < size * 8; i++) {
|
||||||
char buf2[16];
|
char buf2[16];
|
||||||
if (value(i)) {
|
if (value(i)) {
|
||||||
sprintf(buf2, "%2d ", i);
|
int c = sprintf_s(buf2, ARRAY_SIZE(buf2), "%2d ", i);
|
||||||
strcat(buf, buf2);
|
strncat_s(buf, remaining, buf2, ARRAY_SIZE(buf2));
|
||||||
|
remaining -= c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strcat(buf, ")");
|
strncat_s(buf, remaining, ")", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
GameInput::log(char *prefix, bool show_frame) const
|
GameInput::log(char *prefix, bool show_frame) const
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
strcpy(buf, prefix);
|
size_t c = strlen(prefix);
|
||||||
desc(buf + strlen(prefix), show_frame);
|
strcpy_s(buf, prefix);
|
||||||
strcat(buf, "\n");
|
desc(buf + c, ARRAY_SIZE(buf) - c, show_frame);
|
||||||
|
strncat_s(buf, ARRAY_SIZE(buf) - strlen(buf), "\n", 1);
|
||||||
Log(buf);
|
Log(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ struct GameInput {
|
|||||||
void set(int i) { bits[i/8] |= (1 << (i%8)); }
|
void set(int i) { bits[i/8] |= (1 << (i%8)); }
|
||||||
void clear(int i) { bits[i/8] &= ~(1 << (i%8)); }
|
void clear(int i) { bits[i/8] &= ~(1 << (i%8)); }
|
||||||
void erase() { memset(bits, 0, sizeof(bits)); }
|
void erase() { memset(bits, 0, sizeof(bits)); }
|
||||||
void desc(char *buf, bool show_frame = true) const;
|
void desc(char *buf, size_t buf_size, bool show_frame = true) const;
|
||||||
void log(char *prefix, bool show_frame = true) const;
|
void log(char *prefix, bool show_frame = true) const;
|
||||||
bool equal(GameInput &input, bool bitsonly = false);
|
bool equal(GameInput &input, bool bitsonly = false);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -311,8 +311,7 @@ InputQueue::Log(const char *fmt, ...)
|
|||||||
size_t offset;
|
size_t offset;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
sprintf(buf, "input q%d | ", _id);
|
offset = sprintf_s(buf, ARRAY_SIZE(buf), "input q%d | ", _id);
|
||||||
offset = strlen(buf);
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
vsnprintf(buf + offset, ARRAY_SIZE(buf) - offset - 1, fmt, args);
|
vsnprintf(buf + offset, ARRAY_SIZE(buf) - offset - 1, fmt, args);
|
||||||
buf[ARRAY_SIZE(buf)-1] = '\0';
|
buf[ARRAY_SIZE(buf)-1] = '\0';
|
||||||
|
|||||||
@@ -28,19 +28,19 @@ void Log(const char *fmt, ...)
|
|||||||
|
|
||||||
void Logv(const char *fmt, va_list args)
|
void Logv(const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
if (!getenv("ggpo.log") || getenv("ggpo.log.ignore")) {
|
if (!Platform::GetConfigBool("ggpo.log") || Platform::GetConfigBool("ggpo.log.ignore")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!logfile) {
|
if (!logfile) {
|
||||||
sprintf(logbuf, "log-%d.log", Platform::GetProcessID());
|
sprintf_s(logbuf, ARRAY_SIZE(logbuf), "log-%d.log", Platform::GetProcessID());
|
||||||
logfile = fopen(logbuf, "w");
|
fopen_s(&logfile, logbuf, "w");
|
||||||
}
|
}
|
||||||
Logv(logfile, fmt, args);
|
Logv(logfile, fmt, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logv(FILE *fp, const char *fmt, va_list args)
|
void Logv(FILE *fp, const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
if (getenv("ggpo.log.timestamps")) {
|
if (Platform::GetConfigBool("ggpo.log.timestamps")) {
|
||||||
static int start = 0;
|
static int start = 0;
|
||||||
int t = 0;
|
int t = 0;
|
||||||
if (!start) {
|
if (!start) {
|
||||||
@@ -54,7 +54,6 @@ void Logv(FILE *fp, const char *fmt, va_list args)
|
|||||||
vfprintf(fp, fmt, args);
|
vfprintf(fp, fmt, args);
|
||||||
fflush(fp);
|
fflush(fp);
|
||||||
|
|
||||||
vsprintf(logbuf, fmt, args);
|
vsprintf_s(logbuf, ARRAY_SIZE(logbuf), fmt, args);
|
||||||
//OutputDebugStringA(logbuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ ggpo_start_session(GGPOSession **session,
|
|||||||
const char *game,
|
const char *game,
|
||||||
int num_players,
|
int num_players,
|
||||||
int input_size,
|
int input_size,
|
||||||
int localport)
|
unsigned short localport)
|
||||||
{
|
{
|
||||||
*session= (GGPOSession *)new Peer2PeerBackend(cb,
|
*session= (GGPOSession *)new Peer2PeerBackend(cb,
|
||||||
game,
|
game,
|
||||||
@@ -192,9 +192,9 @@ GGPOErrorCode ggpo_start_spectating(GGPOSession **session,
|
|||||||
const char *game,
|
const char *game,
|
||||||
int num_players,
|
int num_players,
|
||||||
int input_size,
|
int input_size,
|
||||||
int local_port,
|
unsigned short local_port,
|
||||||
char *host_ip,
|
char *host_ip,
|
||||||
int host_port)
|
unsigned short host_port)
|
||||||
{
|
{
|
||||||
*session= (GGPOSession *)new SpectatorBackend(cb,
|
*session= (GGPOSession *)new SpectatorBackend(cb,
|
||||||
game,
|
game,
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
#include "udp.h"
|
#include "udp.h"
|
||||||
|
|
||||||
SOCKET
|
SOCKET
|
||||||
CreateSocket(int bind_port, int retries)
|
CreateSocket(uint16 bind_port, int retries)
|
||||||
{
|
{
|
||||||
SOCKET s;
|
SOCKET s;
|
||||||
sockaddr_in sin;
|
sockaddr_in sin;
|
||||||
int port;
|
uint16 port;
|
||||||
int optval = 1;
|
int optval = 1;
|
||||||
|
|
||||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
@@ -52,7 +52,7 @@ Udp::~Udp(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Udp::Init(int port, Poll *poll, Callbacks *callbacks)
|
Udp::Init(uint16 port, Poll *poll, Callbacks *callbacks)
|
||||||
{
|
{
|
||||||
_callbacks = callbacks;
|
_callbacks = callbacks;
|
||||||
|
|
||||||
@@ -71,11 +71,11 @@ Udp::SendTo(char *buffer, int len, int flags, struct sockaddr *dst, int destlen)
|
|||||||
int res = sendto(_socket, buffer, len, flags, dst, destlen);
|
int res = sendto(_socket, buffer, len, flags, dst, destlen);
|
||||||
if (res == SOCKET_ERROR) {
|
if (res == SOCKET_ERROR) {
|
||||||
DWORD err = WSAGetLastError();
|
DWORD err = WSAGetLastError();
|
||||||
DWORD e2 = WSAENOTSOCK;
|
|
||||||
Log("unknown error in sendto (erro: %d wsaerr: %d).\n", res, err);
|
Log("unknown error in sendto (erro: %d wsaerr: %d).\n", res, err);
|
||||||
ASSERT(FALSE && "Unknown error in sendto");
|
ASSERT(FALSE && "Unknown error in sendto");
|
||||||
}
|
}
|
||||||
Log("sent packet length %d to %s:%d (ret:%d).\n", len, inet_ntoa(to->sin_addr), ntohs(to->sin_port), res);
|
char dst_ip[1024];
|
||||||
|
Log("sent packet length %d to %s:%d (ret:%d).\n", len, inet_ntop(AF_INET, (void *)&to->sin_addr, dst_ip, ARRAY_SIZE(dst_ip)), ntohs(to->sin_port), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -98,7 +98,8 @@ Udp::OnLoopPoll(void *cookie)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (len > 0) {
|
} else if (len > 0) {
|
||||||
Log("recvfrom returned (len:%d from:%s:%d).\n", len,inet_ntoa(recv_addr.sin_addr), ntohs(recv_addr.sin_port) );
|
char src_ip[1024];
|
||||||
|
Log("recvfrom returned (len:%d from:%s:%d).\n", len, inet_ntop(AF_INET, (void*)&recv_addr.sin_addr, src_ip, ARRAY_SIZE(src_ip)), ntohs(recv_addr.sin_port) );
|
||||||
UdpMsg *msg = (UdpMsg *)recv_buf;
|
UdpMsg *msg = (UdpMsg *)recv_buf;
|
||||||
_callbacks->OnMsg(recv_addr, msg, len);
|
_callbacks->OnMsg(recv_addr, msg, len);
|
||||||
}
|
}
|
||||||
@@ -114,7 +115,7 @@ Udp::Log(const char *fmt, ...)
|
|||||||
size_t offset;
|
size_t offset;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
strcpy(buf, "udp | ");
|
strcpy_s(buf, "udp | ");
|
||||||
offset = strlen(buf);
|
offset = strlen(buf);
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
vsnprintf(buf + offset, ARRAY_SIZE(buf) - offset - 1, fmt, args);
|
vsnprintf(buf + offset, ARRAY_SIZE(buf) - offset - 1, fmt, args);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
Udp();
|
Udp();
|
||||||
|
|
||||||
void Init(int port, Poll *p, Callbacks *callbacks);
|
void Init(uint16 port, Poll *p, Callbacks *callbacks);
|
||||||
|
|
||||||
void SendTo(char *buffer, int len, int flags, struct sockaddr *dst, int destlen);
|
void SendTo(char *buffer, int len, int flags, struct sockaddr *dst, int destlen);
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ struct UdpMsg
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct connect_status {
|
struct connect_status {
|
||||||
int disconnected:1;
|
unsigned int disconnected:1;
|
||||||
int last_frame:31;
|
int last_frame:31;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@@ -99,7 +99,7 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UdpMsg(MsgType t) { hdr.type = t; }
|
UdpMsg(MsgType t) { hdr.type = (uint8)t; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|||||||
@@ -52,10 +52,8 @@ UdpProtocol::UdpProtocol() :
|
|||||||
memset(&_peer_addr, 0, sizeof _peer_addr);
|
memset(&_peer_addr, 0, sizeof _peer_addr);
|
||||||
_oo_packet.msg = NULL;
|
_oo_packet.msg = NULL;
|
||||||
|
|
||||||
char *delay = getenv("ggpo.network.delay");
|
_send_latency = Platform::GetConfigInt("ggpo.network.delay");
|
||||||
char *oop_pct = getenv("ggpo.oop.percent");
|
_oop_percent = Platform::GetConfigInt("ggpo.oop.percent");
|
||||||
_send_latency = delay ? atoi(delay) : 0;
|
|
||||||
_oop_percent = oop_pct ? atoi(oop_pct) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UdpProtocol::~UdpProtocol()
|
UdpProtocol::~UdpProtocol()
|
||||||
@@ -68,7 +66,7 @@ UdpProtocol::Init(Udp *udp,
|
|||||||
Poll &poll,
|
Poll &poll,
|
||||||
int queue,
|
int queue,
|
||||||
char *ip,
|
char *ip,
|
||||||
int port,
|
u_short port,
|
||||||
UdpMsg::connect_status *status)
|
UdpMsg::connect_status *status)
|
||||||
{
|
{
|
||||||
_udp = udp;
|
_udp = udp;
|
||||||
@@ -76,11 +74,11 @@ UdpProtocol::Init(Udp *udp,
|
|||||||
_local_connect_status = status;
|
_local_connect_status = status;
|
||||||
|
|
||||||
_peer_addr.sin_family = AF_INET;
|
_peer_addr.sin_family = AF_INET;
|
||||||
_peer_addr.sin_addr.s_addr = inet_addr(ip);
|
|
||||||
_peer_addr.sin_port = htons(port);
|
_peer_addr.sin_port = htons(port);
|
||||||
|
inet_pton(AF_INET, ip, &_peer_addr.sin_addr.s_addr);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
_magic_number = rand();
|
_magic_number = (uint16)rand();
|
||||||
} while (_magic_number == 0);
|
} while (_magic_number == 0);
|
||||||
poll.RegisterLoop(this);
|
poll.RegisterLoop(this);
|
||||||
}
|
}
|
||||||
@@ -122,7 +120,7 @@ UdpProtocol::SendPendingOutput()
|
|||||||
bits = msg->u.input.bits;
|
bits = msg->u.input.bits;
|
||||||
|
|
||||||
msg->u.input.start_frame = _pending_output.front().frame;
|
msg->u.input.start_frame = _pending_output.front().frame;
|
||||||
msg->u.input.input_size = _pending_output.front().size;
|
msg->u.input.input_size = (uint8)_pending_output.front().size;
|
||||||
|
|
||||||
ASSERT(last.frame == -1 || last.frame + 1 == msg->u.input.start_frame);
|
ASSERT(last.frame == -1 || last.frame + 1 == msg->u.input.start_frame);
|
||||||
for (j = 0; j < _pending_output.size(); j++) {
|
for (j = 0; j < _pending_output.size(); j++) {
|
||||||
@@ -146,7 +144,7 @@ UdpProtocol::SendPendingOutput()
|
|||||||
msg->u.input.input_size = 0;
|
msg->u.input.input_size = 0;
|
||||||
}
|
}
|
||||||
msg->u.input.ack_frame = _last_received_input.frame;
|
msg->u.input.ack_frame = _last_received_input.frame;
|
||||||
msg->u.input.num_bits = offset;
|
msg->u.input.num_bits = (uint16)offset;
|
||||||
|
|
||||||
msg->u.input.disconnect_requested = _current_state == Disconnected;
|
msg->u.input.disconnect_requested = _current_state == Disconnected;
|
||||||
if (_local_connect_status) {
|
if (_local_connect_status) {
|
||||||
@@ -211,7 +209,7 @@ UdpProtocol::OnLoopPoll(void *cookie)
|
|||||||
if (!_state.running.last_quality_report_time || _state.running.last_quality_report_time + QUALITY_REPORT_INTERVAL < now) {
|
if (!_state.running.last_quality_report_time || _state.running.last_quality_report_time + QUALITY_REPORT_INTERVAL < now) {
|
||||||
UdpMsg *msg = new UdpMsg(UdpMsg::QualityReport);
|
UdpMsg *msg = new UdpMsg(UdpMsg::QualityReport);
|
||||||
msg->u.quality_report.ping = Platform::GetCurrentTimeMS();
|
msg->u.quality_report.ping = Platform::GetCurrentTimeMS();
|
||||||
msg->u.quality_report.frame_advantage = _local_frame_advantage;
|
msg->u.quality_report.frame_advantage = (uint8)_local_frame_advantage;
|
||||||
SendMsg(msg);
|
SendMsg(msg);
|
||||||
_state.running.last_quality_report_time = now;
|
_state.running.last_quality_report_time = now;
|
||||||
}
|
}
|
||||||
@@ -317,7 +315,7 @@ UdpProtocol::OnMsg(UdpMsg *msg, int len)
|
|||||||
};
|
};
|
||||||
|
|
||||||
// filter out messages that don't match what we expect
|
// filter out messages that don't match what we expect
|
||||||
int seq = msg->hdr.sequence_number;
|
uint16 seq = msg->hdr.sequence_number;
|
||||||
if (msg->hdr.type != UdpMsg::SyncRequest &&
|
if (msg->hdr.type != UdpMsg::SyncRequest &&
|
||||||
msg->hdr.type != UdpMsg::SyncReply) {
|
msg->hdr.type != UdpMsg::SyncReply) {
|
||||||
if (msg->hdr.magic != _remote_magic_number) {
|
if (msg->hdr.magic != _remote_magic_number) {
|
||||||
@@ -326,7 +324,7 @@ UdpProtocol::OnMsg(UdpMsg *msg, int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// filter out out-of-order packets
|
// filter out out-of-order packets
|
||||||
uint16 skipped = seq - _next_recv_seq;
|
uint16 skipped = (uint16)((int)seq - (int)_next_recv_seq);
|
||||||
// Log("checking sequence number -> next - seq : %d - %d = %d\n", seq, _next_recv_seq, skipped);
|
// Log("checking sequence number -> next - seq : %d - %d = %d\n", seq, _next_recv_seq, skipped);
|
||||||
if (skipped > MAX_SEQ_DISTANCE) {
|
if (skipped > MAX_SEQ_DISTANCE) {
|
||||||
Log("dropping out of order packet (seq: %d, last seq:%d)\n", seq, _next_recv_seq);
|
Log("dropping out of order packet (seq: %d, last seq:%d)\n", seq, _next_recv_seq);
|
||||||
@@ -407,7 +405,7 @@ UdpProtocol::Log(const char *fmt, ...)
|
|||||||
size_t offset;
|
size_t offset;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
sprintf(buf, "udpproto%d | ", _queue);
|
sprintf_s(buf, ARRAY_SIZE(buf), "udpproto%d | ", _queue);
|
||||||
offset = strlen(buf);
|
offset = strlen(buf);
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
vsnprintf(buf + offset, ARRAY_SIZE(buf) - offset - 1, fmt, args);
|
vsnprintf(buf + offset, ARRAY_SIZE(buf) - offset - 1, fmt, args);
|
||||||
@@ -594,7 +592,7 @@ UdpProtocol::OnInput(UdpMsg *msg, int len)
|
|||||||
UdpProtocol::Event evt(UdpProtocol::Event::Input);
|
UdpProtocol::Event evt(UdpProtocol::Event::Input);
|
||||||
evt.u.input.input = _last_received_input;
|
evt.u.input.input = _last_received_input;
|
||||||
|
|
||||||
_last_received_input.desc(desc);
|
_last_received_input.desc(desc, ARRAY_SIZE(desc));
|
||||||
|
|
||||||
_state.running.last_input_packet_recv_time = Platform::GetCurrentTimeMS();
|
_state.running.last_input_packet_recv_time = Platform::GetCurrentTimeMS();
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public:
|
|||||||
UdpProtocol();
|
UdpProtocol();
|
||||||
virtual ~UdpProtocol();
|
virtual ~UdpProtocol();
|
||||||
|
|
||||||
void Init(Udp *udp, Poll &p, int queue, char *ip, int port, UdpMsg::connect_status *status);
|
void Init(Udp *udp, Poll &p, int queue, char *ip, u_short port, UdpMsg::connect_status *status);
|
||||||
|
|
||||||
void Synchronize();
|
void Synchronize();
|
||||||
bool GetPeerConnectStatus(int id, int *frame);
|
bool GetPeerConnectStatus(int id, int *frame);
|
||||||
|
|||||||
@@ -9,8 +9,10 @@
|
|||||||
#define _GGPO_WINDOWS_H_
|
#define _GGPO_WINDOWS_H_
|
||||||
|
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
#include <ws2tcpip.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
class Platform {
|
class Platform {
|
||||||
public: // types
|
public: // types
|
||||||
@@ -20,6 +22,8 @@ public: // functions
|
|||||||
static ProcessID GetProcessID() { return GetCurrentProcessId(); }
|
static ProcessID GetProcessID() { return GetCurrentProcessId(); }
|
||||||
static void AssertFailed(char *msg) { MessageBoxA(NULL, msg, "GGPO Assertion Failed", MB_OK | MB_ICONEXCLAMATION); }
|
static void AssertFailed(char *msg) { MessageBoxA(NULL, msg, "GGPO Assertion Failed", MB_OK | MB_ICONEXCLAMATION); }
|
||||||
static uint32 GetCurrentTimeMS() { return timeGetTime(); }
|
static uint32 GetCurrentTimeMS() { return timeGetTime(); }
|
||||||
|
static int GetConfigInt(const char* name);
|
||||||
|
static bool GetConfigBool(const char* name);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ TimeSync::~TimeSync()
|
|||||||
void
|
void
|
||||||
TimeSync::advance_frame(GameInput &input, int advantage, int radvantage)
|
TimeSync::advance_frame(GameInput &input, int advantage, int radvantage)
|
||||||
{
|
{
|
||||||
int sleep_time = 0;
|
|
||||||
|
|
||||||
// Remember the last frame and frame advantage
|
// Remember the last frame and frame advantage
|
||||||
_last_inputs[input.frame % ARRAY_SIZE(_last_inputs)] = input;
|
_last_inputs[input.frame % ARRAY_SIZE(_last_inputs)] = input;
|
||||||
_local[input.frame % ARRAY_SIZE(_local)] = advantage;
|
_local[input.frame % ARRAY_SIZE(_local)] = advantage;
|
||||||
|
|||||||
@@ -54,13 +54,13 @@ typedef int int32;
|
|||||||
#define ASSERT(x) \
|
#define ASSERT(x) \
|
||||||
do { \
|
do { \
|
||||||
if (!(x)) { \
|
if (!(x)) { \
|
||||||
char buf[1024]; \
|
char assert_buf[1024]; \
|
||||||
snprintf(buf, sizeof(buf) - 1, "Assertion: %s @ %s:%d (pid:%d)", #x, __FILE__, __LINE__, Platform::GetProcessID()); \
|
snprintf(assert_buf, sizeof(assert_buf) - 1, "Assertion: %s @ %s:%d (pid:%d)", #x, __FILE__, __LINE__, Platform::GetProcessID()); \
|
||||||
Log("%s\n", buf); \
|
Log("%s\n", assert_buf); \
|
||||||
Log("\n"); \
|
Log("\n"); \
|
||||||
Log("\n"); \
|
Log("\n"); \
|
||||||
Log("\n"); \
|
Log("\n"); \
|
||||||
Platform::AssertFailed(buf); \
|
Platform::AssertFailed(assert_buf); \
|
||||||
exit(0); \
|
exit(0); \
|
||||||
} \
|
} \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|||||||
Reference in New Issue
Block a user