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>
|
||||
)
|
||||
|
||||
if(WIN32 AND BUILD_SHARED_LIBS)
|
||||
# Link to Multimedia API and Winsocks during a shared build.
|
||||
target_link_libraries(GGPO PUBLIC winmm.lib ws2_32.lib)
|
||||
add_definitions(-DGGPO_SHARED_LIB)
|
||||
add_definitions(-DGGPO_SDK_EXPORT)
|
||||
if(WIN32)
|
||||
target_compile_options(GGPO PRIVATE "/W4" "/WX")
|
||||
if(BUILD_SHARED_LIBS)
|
||||
# Link to Multimedia API and Winsocks during a shared build.
|
||||
target_link_libraries(GGPO PUBLIC winmm.lib ws2_32.lib)
|
||||
add_definitions(-DGGPO_SHARED_LIB)
|
||||
add_definitions(-DGGPO_SDK_EXPORT)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set_target_properties(GGPO PROPERTIES VERSION ${PROJECT_VERSION})
|
||||
|
||||
@@ -30,6 +30,13 @@ if(UNIX)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
set(GGPO_LIB_SRC_NOFILTER
|
||||
${GGPO_LIB_SRC_NOFILTER}
|
||||
"lib/ggpo/platform_windows.cpp"
|
||||
)
|
||||
endif()
|
||||
|
||||
set(GGPO_LIB_INC_NETWORK
|
||||
"lib/ggpo/network/udp.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).
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ draw_fairness_graph_control(LPDRAWITEMSTRUCT di)
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -114,7 +114,7 @@ ggpo_perfmon_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
char pid[64];
|
||||
sprintf(pid, "%d", GetCurrentProcessId());
|
||||
snprintf(pid, ARRAYSIZE(pid), "%d", GetCurrentProcessId());
|
||||
SetWindowTextA(GetDlgItem(hwndDlg, IDC_PID), pid);
|
||||
return TRUE;
|
||||
}
|
||||
@@ -219,11 +219,11 @@ ggpoutil_perfmon_update(GGPOSession *ggpo, GGPOPlayerHandle players[], int num_p
|
||||
char fLocal[128], fRemote[128], fBandwidth[128];
|
||||
char msLag[128], frameLag[128];
|
||||
|
||||
sprintf(msLag, "%d ms", stats.network.ping);
|
||||
sprintf(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(fLocal, "%d frames", stats.timesync.local_frames_behind);
|
||||
sprintf(fRemote, "%d frames", stats.timesync.remote_frames_behind);
|
||||
sprintf_s(msLag, ARRAYSIZE(msLag), "%d ms", stats.network.ping);
|
||||
sprintf_s(frameLag, ARRAYSIZE(frameLag), "%.1f frames", stats.network.ping ? stats.network.ping * 60.0 / 1000 : 0);
|
||||
sprintf_s(fBandwidth, ARRAYSIZE(fBandwidth), "%.2f kilobytes/sec", stats.network.kbps_sent / 8.0);
|
||||
sprintf_s(fLocal, ARRAYSIZE(fLocal), "%d frames", stats.timesync.local_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_FRAME_LAG), frameLag);
|
||||
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++) {
|
||||
if (players[i].handle == handle) {
|
||||
players[i].disconnect_start = now;
|
||||
players[i].disconnect_start = when;
|
||||
players[i].disconnect_timeout = timeout;
|
||||
players[i].state = Disconnecting;
|
||||
break;
|
||||
|
||||
@@ -78,8 +78,8 @@ typedef struct GGPOPlayer {
|
||||
struct {
|
||||
} local;
|
||||
struct {
|
||||
char ip_address[32];
|
||||
short port;
|
||||
char ip_address[32];
|
||||
unsigned short port;
|
||||
} remote;
|
||||
} u;
|
||||
} GGPOPlayer;
|
||||
@@ -324,7 +324,7 @@ GGPO_API GGPOErrorCode __cdecl ggpo_start_session(GGPOSession **session,
|
||||
const char *game,
|
||||
int num_players,
|
||||
int input_size,
|
||||
int localport);
|
||||
unsigned short localport);
|
||||
|
||||
|
||||
/*
|
||||
@@ -404,9 +404,9 @@ GGPO_API GGPOErrorCode __cdecl ggpo_start_spectating(GGPOSession **session,
|
||||
const char *game,
|
||||
int num_players,
|
||||
int input_size,
|
||||
int local_port,
|
||||
unsigned int local_port,
|
||||
char *host_ip,
|
||||
int host_port);
|
||||
unsigned int host_port);
|
||||
|
||||
/*
|
||||
* ggpo_close_session --
|
||||
|
||||
@@ -13,7 +13,7 @@ static const int DEFAULT_DISCONNECT_NOTIFY_START = 750;
|
||||
|
||||
Peer2PeerBackend::Peer2PeerBackend(GGPOSessionCallbacks *cb,
|
||||
const char *gamename,
|
||||
int localport,
|
||||
uint16 localport,
|
||||
int num_players,
|
||||
int input_size) :
|
||||
_num_players(num_players),
|
||||
@@ -62,7 +62,7 @@ Peer2PeerBackend::~Peer2PeerBackend()
|
||||
|
||||
void
|
||||
Peer2PeerBackend::AddRemotePlayer(char *ip,
|
||||
int port,
|
||||
uint16 port,
|
||||
int queue)
|
||||
{
|
||||
/*
|
||||
@@ -77,7 +77,7 @@ Peer2PeerBackend::AddRemotePlayer(char *ip,
|
||||
}
|
||||
|
||||
GGPOErrorCode Peer2PeerBackend::AddSpectator(char *ip,
|
||||
int port)
|
||||
uint16 port)
|
||||
{
|
||||
if (_num_spectators == GGPO_MAX_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",
|
||||
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;
|
||||
|
||||
if (syncto < framecount) {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
class Peer2PeerBackend : public IQuarkBackend, IPollSink, Udp::Callbacks {
|
||||
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();
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ protected:
|
||||
void CheckInitialSync(void);
|
||||
int Poll2Players(int current_frame);
|
||||
int PollNPlayers(int current_frame);
|
||||
void AddRemotePlayer(char *remoteip, int reportport, int queue);
|
||||
GGPOErrorCode AddSpectator(char *remoteip, int reportport);
|
||||
void AddRemotePlayer(char *remoteip, uint16 reportport, int queue);
|
||||
GGPOErrorCode AddSpectator(char *remoteip, uint16 reportport);
|
||||
virtual void OnSyncEvent(Sync::Event &e) { }
|
||||
virtual void OnUdpProtocolEvent(UdpProtocol::Event &e, GGPOPlayerHandle handle);
|
||||
virtual void OnUdpProtocolPeerEvent(UdpProtocol::Event &e, int queue);
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
SpectatorBackend::SpectatorBackend(GGPOSessionCallbacks *cb,
|
||||
const char* gamename,
|
||||
int localport,
|
||||
uint16 localport,
|
||||
int num_players,
|
||||
int input_size,
|
||||
char *hostip,
|
||||
int hostport) :
|
||||
u_short hostport) :
|
||||
_num_players(num_players),
|
||||
_input_size(input_size),
|
||||
_next_input_to_send(0)
|
||||
@@ -149,8 +149,6 @@ SpectatorBackend::OnUdpProtocolEvent(UdpProtocol::Event &evt)
|
||||
break;
|
||||
|
||||
case UdpProtocol::Event::Disconnected:
|
||||
GGPOEvent info;
|
||||
|
||||
info.code = GGPO_EVENTCODE_DISCONNECTED_FROM_PEER;
|
||||
info.u.disconnected.player = 0;
|
||||
_callbacks.on_event(&info);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
class SpectatorBackend : public IQuarkBackend, IPollSink, Udp::Callbacks {
|
||||
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();
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ SyncTestBackend::SyncTestBackend(GGPOSessionCallbacks *cb,
|
||||
_running = false;
|
||||
_logfp = NULL;
|
||||
_current_input.erase();
|
||||
strcpy(_game, gamename);
|
||||
strcpy_s(_game, gamename);
|
||||
|
||||
/*
|
||||
* 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
|
||||
// list.
|
||||
SavedInfo info = _saved_frames.front();
|
||||
info = _saved_frames.front();
|
||||
_saved_frames.pop();
|
||||
|
||||
if (info.frame != _sync.GetFrameCount()) {
|
||||
@@ -163,7 +163,7 @@ SyncTestBackend::RaiseSyncError(const char *fmt, ...)
|
||||
char buf[1024];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsprintf(buf, fmt, args);
|
||||
vsprintf_s(buf, ARRAY_SIZE(buf), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
puts(buf);
|
||||
@@ -188,12 +188,12 @@ SyncTestBackend::BeginLog(int saving)
|
||||
|
||||
char filename[MAX_PATH];
|
||||
CreateDirectoryA("synclogs", NULL);
|
||||
sprintf(filename, "synclogs\\%s-%04d-%s.log",
|
||||
sprintf_s(filename, ARRAY_SIZE(filename), "synclogs\\%s-%04d-%s.log",
|
||||
saving ? "state" : "log",
|
||||
_sync.GetFrameCount(),
|
||||
_rollingback ? "replay" : "original");
|
||||
|
||||
_logfp = fopen(filename, "w");
|
||||
fopen_s(&_logfp, filename, "w");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -209,9 +209,9 @@ void
|
||||
SyncTestBackend::LogSaveStates(SavedInfo &info)
|
||||
{
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -36,32 +36,35 @@ GameInput::init(int iframe, char *ibits, int isize)
|
||||
}
|
||||
|
||||
void
|
||||
GameInput::desc(char *buf, bool show_frame) const
|
||||
GameInput::desc(char *buf, size_t buf_size, bool show_frame) const
|
||||
{
|
||||
ASSERT(size);
|
||||
int offset = 0;
|
||||
size_t remaining = buf_size;
|
||||
if (show_frame) {
|
||||
sprintf(buf, "(frame:%d size:%d ", frame, size);
|
||||
remaining -= sprintf_s(buf, buf_size, "(frame:%d size:%d ", frame, size);
|
||||
} else {
|
||||
sprintf(buf, "(size:%d ", size);
|
||||
remaining -= sprintf_s(buf, buf_size, "(size:%d ", size);
|
||||
}
|
||||
|
||||
for (int i = 0; i < size * 8; i++) {
|
||||
char buf2[16];
|
||||
if (value(i)) {
|
||||
sprintf(buf2, "%2d ", i);
|
||||
strcat(buf, buf2);
|
||||
int c = sprintf_s(buf2, ARRAY_SIZE(buf2), "%2d ", i);
|
||||
strncat_s(buf, remaining, buf2, ARRAY_SIZE(buf2));
|
||||
remaining -= c;
|
||||
}
|
||||
}
|
||||
strcat(buf, ")");
|
||||
strncat_s(buf, remaining, ")", 1);
|
||||
}
|
||||
|
||||
void
|
||||
GameInput::log(char *prefix, bool show_frame) const
|
||||
{
|
||||
char buf[1024];
|
||||
strcpy(buf, prefix);
|
||||
desc(buf + strlen(prefix), show_frame);
|
||||
strcat(buf, "\n");
|
||||
size_t c = strlen(prefix);
|
||||
strcpy_s(buf, prefix);
|
||||
desc(buf + c, ARRAY_SIZE(buf) - c, show_frame);
|
||||
strncat_s(buf, ARRAY_SIZE(buf) - strlen(buf), "\n", 1);
|
||||
Log(buf);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ struct GameInput {
|
||||
void set(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 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;
|
||||
bool equal(GameInput &input, bool bitsonly = false);
|
||||
};
|
||||
|
||||
@@ -311,8 +311,7 @@ InputQueue::Log(const char *fmt, ...)
|
||||
size_t offset;
|
||||
va_list args;
|
||||
|
||||
sprintf(buf, "input q%d | ", _id);
|
||||
offset = strlen(buf);
|
||||
offset = sprintf_s(buf, ARRAY_SIZE(buf), "input q%d | ", _id);
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buf + offset, ARRAY_SIZE(buf) - offset - 1, fmt, args);
|
||||
buf[ARRAY_SIZE(buf)-1] = '\0';
|
||||
|
||||
@@ -28,19 +28,19 @@ void Log(const char *fmt, ...)
|
||||
|
||||
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;
|
||||
}
|
||||
if (!logfile) {
|
||||
sprintf(logbuf, "log-%d.log", Platform::GetProcessID());
|
||||
logfile = fopen(logbuf, "w");
|
||||
sprintf_s(logbuf, ARRAY_SIZE(logbuf), "log-%d.log", Platform::GetProcessID());
|
||||
fopen_s(&logfile, logbuf, "w");
|
||||
}
|
||||
Logv(logfile, fmt, 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;
|
||||
int t = 0;
|
||||
if (!start) {
|
||||
@@ -54,7 +54,6 @@ void Logv(FILE *fp, const char *fmt, va_list args)
|
||||
vfprintf(fp, fmt, args);
|
||||
fflush(fp);
|
||||
|
||||
vsprintf(logbuf, fmt, args);
|
||||
//OutputDebugStringA(logbuf);
|
||||
vsprintf_s(logbuf, ARRAY_SIZE(logbuf), fmt, args);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ ggpo_start_session(GGPOSession **session,
|
||||
const char *game,
|
||||
int num_players,
|
||||
int input_size,
|
||||
int localport)
|
||||
unsigned short localport)
|
||||
{
|
||||
*session= (GGPOSession *)new Peer2PeerBackend(cb,
|
||||
game,
|
||||
@@ -192,9 +192,9 @@ GGPOErrorCode ggpo_start_spectating(GGPOSession **session,
|
||||
const char *game,
|
||||
int num_players,
|
||||
int input_size,
|
||||
int local_port,
|
||||
unsigned short local_port,
|
||||
char *host_ip,
|
||||
int host_port)
|
||||
unsigned short host_port)
|
||||
{
|
||||
*session= (GGPOSession *)new SpectatorBackend(cb,
|
||||
game,
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
#include "udp.h"
|
||||
|
||||
SOCKET
|
||||
CreateSocket(int bind_port, int retries)
|
||||
CreateSocket(uint16 bind_port, int retries)
|
||||
{
|
||||
SOCKET s;
|
||||
sockaddr_in sin;
|
||||
int port;
|
||||
uint16 port;
|
||||
int optval = 1;
|
||||
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
@@ -52,7 +52,7 @@ Udp::~Udp(void)
|
||||
}
|
||||
|
||||
void
|
||||
Udp::Init(int port, Poll *poll, Callbacks *callbacks)
|
||||
Udp::Init(uint16 port, Poll *poll, 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);
|
||||
if (res == SOCKET_ERROR) {
|
||||
DWORD err = WSAGetLastError();
|
||||
DWORD e2 = WSAENOTSOCK;
|
||||
Log("unknown error in sendto (erro: %d wsaerr: %d).\n", res, err);
|
||||
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
|
||||
@@ -98,7 +98,8 @@ Udp::OnLoopPoll(void *cookie)
|
||||
}
|
||||
break;
|
||||
} 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;
|
||||
_callbacks->OnMsg(recv_addr, msg, len);
|
||||
}
|
||||
@@ -114,7 +115,7 @@ Udp::Log(const char *fmt, ...)
|
||||
size_t offset;
|
||||
va_list args;
|
||||
|
||||
strcpy(buf, "udp | ");
|
||||
strcpy_s(buf, "udp | ");
|
||||
offset = strlen(buf);
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buf + offset, ARRAY_SIZE(buf) - offset - 1, fmt, args);
|
||||
|
||||
@@ -38,7 +38,7 @@ protected:
|
||||
public:
|
||||
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);
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ struct UdpMsg
|
||||
};
|
||||
|
||||
struct connect_status {
|
||||
int disconnected:1;
|
||||
int last_frame:31;
|
||||
unsigned int disconnected:1;
|
||||
int last_frame:31;
|
||||
};
|
||||
|
||||
struct {
|
||||
@@ -99,7 +99,7 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
UdpMsg(MsgType t) { hdr.type = t; }
|
||||
UdpMsg(MsgType t) { hdr.type = (uint8)t; }
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
@@ -52,10 +52,8 @@ UdpProtocol::UdpProtocol() :
|
||||
memset(&_peer_addr, 0, sizeof _peer_addr);
|
||||
_oo_packet.msg = NULL;
|
||||
|
||||
char *delay = getenv("ggpo.network.delay");
|
||||
char *oop_pct = getenv("ggpo.oop.percent");
|
||||
_send_latency = delay ? atoi(delay) : 0;
|
||||
_oop_percent = oop_pct ? atoi(oop_pct) : 0;
|
||||
_send_latency = Platform::GetConfigInt("ggpo.network.delay");
|
||||
_oop_percent = Platform::GetConfigInt("ggpo.oop.percent");
|
||||
}
|
||||
|
||||
UdpProtocol::~UdpProtocol()
|
||||
@@ -68,7 +66,7 @@ UdpProtocol::Init(Udp *udp,
|
||||
Poll &poll,
|
||||
int queue,
|
||||
char *ip,
|
||||
int port,
|
||||
u_short port,
|
||||
UdpMsg::connect_status *status)
|
||||
{
|
||||
_udp = udp;
|
||||
@@ -76,11 +74,11 @@ UdpProtocol::Init(Udp *udp,
|
||||
_local_connect_status = status;
|
||||
|
||||
_peer_addr.sin_family = AF_INET;
|
||||
_peer_addr.sin_addr.s_addr = inet_addr(ip);
|
||||
_peer_addr.sin_port = htons(port);
|
||||
|
||||
inet_pton(AF_INET, ip, &_peer_addr.sin_addr.s_addr);
|
||||
|
||||
do {
|
||||
_magic_number = rand();
|
||||
_magic_number = (uint16)rand();
|
||||
} while (_magic_number == 0);
|
||||
poll.RegisterLoop(this);
|
||||
}
|
||||
@@ -122,7 +120,7 @@ UdpProtocol::SendPendingOutput()
|
||||
bits = msg->u.input.bits;
|
||||
|
||||
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);
|
||||
for (j = 0; j < _pending_output.size(); j++) {
|
||||
@@ -146,7 +144,7 @@ UdpProtocol::SendPendingOutput()
|
||||
msg->u.input.input_size = 0;
|
||||
}
|
||||
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;
|
||||
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) {
|
||||
UdpMsg *msg = new UdpMsg(UdpMsg::QualityReport);
|
||||
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);
|
||||
_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
|
||||
int seq = msg->hdr.sequence_number;
|
||||
uint16 seq = msg->hdr.sequence_number;
|
||||
if (msg->hdr.type != UdpMsg::SyncRequest &&
|
||||
msg->hdr.type != UdpMsg::SyncReply) {
|
||||
if (msg->hdr.magic != _remote_magic_number) {
|
||||
@@ -326,7 +324,7 @@ UdpProtocol::OnMsg(UdpMsg *msg, int len)
|
||||
}
|
||||
|
||||
// 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);
|
||||
if (skipped > MAX_SEQ_DISTANCE) {
|
||||
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;
|
||||
va_list args;
|
||||
|
||||
sprintf(buf, "udpproto%d | ", _queue);
|
||||
sprintf_s(buf, ARRAY_SIZE(buf), "udpproto%d | ", _queue);
|
||||
offset = strlen(buf);
|
||||
va_start(args, fmt);
|
||||
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);
|
||||
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();
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
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();
|
||||
bool GetPeerConnectStatus(int id, int *frame);
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
#define _GGPO_WINDOWS_H_
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include "types.h"
|
||||
|
||||
class Platform {
|
||||
public: // types
|
||||
@@ -20,6 +22,8 @@ public: // functions
|
||||
static ProcessID GetProcessID() { return GetCurrentProcessId(); }
|
||||
static void AssertFailed(char *msg) { MessageBoxA(NULL, msg, "GGPO Assertion Failed", MB_OK | MB_ICONEXCLAMATION); }
|
||||
static uint32 GetCurrentTimeMS() { return timeGetTime(); }
|
||||
static int GetConfigInt(const char* name);
|
||||
static bool GetConfigBool(const char* name);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,8 +21,6 @@ TimeSync::~TimeSync()
|
||||
void
|
||||
TimeSync::advance_frame(GameInput &input, int advantage, int radvantage)
|
||||
{
|
||||
int sleep_time = 0;
|
||||
|
||||
// Remember the last frame and frame advantage
|
||||
_last_inputs[input.frame % ARRAY_SIZE(_last_inputs)] = input;
|
||||
_local[input.frame % ARRAY_SIZE(_local)] = advantage;
|
||||
|
||||
@@ -54,13 +54,13 @@ typedef int int32;
|
||||
#define ASSERT(x) \
|
||||
do { \
|
||||
if (!(x)) { \
|
||||
char buf[1024]; \
|
||||
snprintf(buf, sizeof(buf) - 1, "Assertion: %s @ %s:%d (pid:%d)", #x, __FILE__, __LINE__, Platform::GetProcessID()); \
|
||||
Log("%s\n", buf); \
|
||||
char assert_buf[1024]; \
|
||||
snprintf(assert_buf, sizeof(assert_buf) - 1, "Assertion: %s @ %s:%d (pid:%d)", #x, __FILE__, __LINE__, Platform::GetProcessID()); \
|
||||
Log("%s\n", assert_buf); \
|
||||
Log("\n"); \
|
||||
Log("\n"); \
|
||||
Log("\n"); \
|
||||
Platform::AssertFailed(buf); \
|
||||
Platform::AssertFailed(assert_buf); \
|
||||
exit(0); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
Reference in New Issue
Block a user