Merge pull request #40 from pond3r/dev/compile_warnings
Clean up compilation
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -x
|
||||
|
||||
WORKSPACE="workspace-${RANDOM}"
|
||||
AGENT_IP="$(gcloud compute instances describe ggpo-ci-build-win-01 --zone=us-central1-a --format='get(networkInterfaces[0].accessConfigs.natIP)')"
|
||||
SSH="ssh -o StrictHostKeyChecking=no"
|
||||
tar -cvf ggpo.tar . &> /dev/null
|
||||
|
||||
${SSH} ponder@${AGENT_IP} "mkdir C:\\workspace\\${WORKSPACE}"
|
||||
scp ggpo.tar "ponder@${AGENT_IP}:/workspace/${WORKSPACE}"
|
||||
${SSH} ponder@${AGENT_IP} "cd C:\\workspace\\${WORKSPACE} && tar -xvf ggpo.tar && ci\\build_windows_agent.cmd"
|
||||
${SSH} ponder@${AGENT_IP} "rmdir /q/s C:\\workspace\\${WORKSPACE}"
|
||||
|
||||
rm ggpo.tar
|
||||
@@ -1,11 +0,0 @@
|
||||
cmake -G "Visual Studio 16 2019" -A x64 -B build -DBUILD_SHARED_LIBS=off
|
||||
|
||||
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"
|
||||
echo on
|
||||
|
||||
devenv.exe "build\GGPO.sln" /build Release /out release.log
|
||||
type release.log
|
||||
|
||||
devenv.exe "build\GGPO.sln" /build Debug /out debug.log
|
||||
type debug.log
|
||||
|
||||
BIN
ci/id_rsa.enc
BIN
ci/id_rsa.enc
Binary file not shown.
@@ -1,30 +0,0 @@
|
||||
# Decrypt the file containing the key
|
||||
steps:
|
||||
- name: 'gcr.io/cloud-builders/gcloud'
|
||||
args:
|
||||
- kms
|
||||
- decrypt
|
||||
- --ciphertext-file=./ci/id_rsa.enc
|
||||
- --plaintext-file=/root/.ssh/id_rsa
|
||||
- --location=global
|
||||
- --keyring=ggpo-ci-keyring
|
||||
- --key=buildagent-key
|
||||
volumes:
|
||||
- name: 'ssh'
|
||||
path: /root/.ssh
|
||||
- name: 'gcr.io/cloud-builders/git'
|
||||
entrypoint: bash
|
||||
args:
|
||||
- '-c'
|
||||
- |
|
||||
chmod 600 /root/.ssh/id_rsa
|
||||
volumes:
|
||||
- name: 'ssh'
|
||||
path: /root/.ssh
|
||||
- name: 'gcr.io/cloud-builders/git'
|
||||
entrypoint: bash
|
||||
args:
|
||||
- ./ci/build_windows.sh
|
||||
volumes:
|
||||
- name: 'ssh'
|
||||
path: /root/.ssh
|
||||
@@ -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,13 +89,13 @@ 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);
|
||||
|
||||
ship->heading = heading;
|
||||
ship->heading = (int)heading;
|
||||
|
||||
if (ship->cooldown == 0) {
|
||||
if (fire) {
|
||||
|
||||
@@ -52,11 +52,11 @@ GDIRenderer::Draw(GameState &gs, NonGameState &ngs)
|
||||
SetTextColor(hdc, _shipColors[i]);
|
||||
SelectObject(hdc, _shipPens[i]);
|
||||
DrawShip(hdc, i, gs);
|
||||
DrawConnectState(hdc, gs._ships[i], ngs.players[i], _shipColors[i]);
|
||||
DrawConnectState(hdc, gs._ships[i], ngs.players[i]);
|
||||
}
|
||||
|
||||
SetTextAlign(hdc, TA_BOTTOM | TA_CENTER);
|
||||
TextOutA(hdc, (_rc.left + _rc.right) / 2, _rc.bottom - 32, _status, strlen(_status));
|
||||
TextOutA(hdc, (_rc.left + _rc.right) / 2, _rc.bottom - 32, _status, (int)strlen(_status));
|
||||
|
||||
SetTextColor(hdc, RGB(192, 192, 192));
|
||||
RenderChecksum(hdc, 40, ngs.periodic);
|
||||
@@ -71,15 +71,15 @@ void
|
||||
GDIRenderer::RenderChecksum(HDC hdc, int y, NonGameState::ChecksumInfo &info)
|
||||
{
|
||||
char checksum[128];
|
||||
sprintf(checksum, "Frame: %04d Checksum: %08x", info.framenumber, info.checksum);
|
||||
TextOutA(hdc, (_rc.left + _rc.right) / 2, _rc.top + y, checksum, strlen(checksum));
|
||||
sprintf_s(checksum, ARRAYSIZE(checksum), "Frame: %04d Checksum: %08x", info.framenumber, info.checksum);
|
||||
TextOutA(hdc, (_rc.left + _rc.right) / 2, _rc.top + y, checksum, (int)strlen(checksum));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GDIRenderer::SetStatusText(const char *text)
|
||||
{
|
||||
strcpy(_status, text);
|
||||
strcpy_s(_status, text);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -110,7 +110,7 @@ GDIRenderer::DrawShip(HDC hdc, int which, GameState &gs)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(shape); i++) {
|
||||
int newx, newy;
|
||||
double newx, newy;
|
||||
double cost, sint, theta;
|
||||
|
||||
theta = (double)ship->heading * PI / 180;
|
||||
@@ -120,27 +120,27 @@ GDIRenderer::DrawShip(HDC hdc, int which, GameState &gs)
|
||||
newx = shape[i].x * cost - shape[i].y * sint;
|
||||
newy = shape[i].x * sint + shape[i].y * cost;
|
||||
|
||||
shape[i].x = newx + ship->position.x;
|
||||
shape[i].y = newy + ship->position.y;
|
||||
shape[i].x = (LONG)(newx + ship->position.x);
|
||||
shape[i].y = (LONG)(newy + ship->position.y);
|
||||
}
|
||||
Polyline(hdc, shape, ARRAY_SIZE(shape));
|
||||
|
||||
for (int i = 0; i < MAX_BULLETS; i++) {
|
||||
for (i = 0; i < MAX_BULLETS; i++) {
|
||||
if (ship->bullets[i].active) {
|
||||
bullet.left = ship->bullets[i].position.x - 1;
|
||||
bullet.right = ship->bullets[i].position.x + 1;
|
||||
bullet.top = ship->bullets[i].position.y - 1;
|
||||
bullet.bottom = ship->bullets[i].position.y + 1;
|
||||
bullet.left = (LONG)ship->bullets[i].position.x - 1;
|
||||
bullet.right = (LONG)ship->bullets[i].position.x + 1;
|
||||
bullet.top = (LONG)ship->bullets[i].position.y - 1;
|
||||
bullet.bottom = (LONG)ship->bullets[i].position.y + 1;
|
||||
FillRect(hdc, &bullet, _bulletBrush);
|
||||
}
|
||||
}
|
||||
SetTextAlign(hdc, alignments[which]);
|
||||
sprintf(buf, "Hits: %d", ship->score);
|
||||
TextOutA(hdc, text_offsets[which].x, text_offsets[which].y, buf, strlen(buf));
|
||||
sprintf_s(buf, ARRAYSIZE(buf), "Hits: %d", ship->score);
|
||||
TextOutA(hdc, text_offsets[which].x, text_offsets[which].y, buf, (int)strlen(buf));
|
||||
}
|
||||
|
||||
void
|
||||
GDIRenderer::DrawConnectState(HDC hdc, Ship &ship, PlayerConnectionInfo &info, COLORREF color)
|
||||
GDIRenderer::DrawConnectState(HDC hdc, Ship &ship, PlayerConnectionInfo &info)
|
||||
{
|
||||
char status[64];
|
||||
static const char *statusStrings[] = {
|
||||
@@ -154,34 +154,34 @@ GDIRenderer::DrawConnectState(HDC hdc, Ship &ship, PlayerConnectionInfo &info, C
|
||||
*status = '\0';
|
||||
switch (info.state) {
|
||||
case Connecting:
|
||||
sprintf(status, (info.type == GGPO_PLAYERTYPE_LOCAL) ? "Local Player" : "Connecting...");
|
||||
sprintf_s(status, ARRAYSIZE(status), (info.type == GGPO_PLAYERTYPE_LOCAL) ? "Local Player" : "Connecting...");
|
||||
break;
|
||||
|
||||
case Synchronizing:
|
||||
progress = info.connect_progress;
|
||||
sprintf(status, (info.type == GGPO_PLAYERTYPE_LOCAL) ? "Local Player" : "Synchronizing...");
|
||||
sprintf_s(status, ARRAYSIZE(status), (info.type == GGPO_PLAYERTYPE_LOCAL) ? "Local Player" : "Synchronizing...");
|
||||
break;
|
||||
|
||||
case Disconnected:
|
||||
sprintf(status, "Disconnected");
|
||||
sprintf_s(status, ARRAYSIZE(status), "Disconnected");
|
||||
break;
|
||||
|
||||
case Disconnecting:
|
||||
sprintf(status, "Waiting for player...");
|
||||
sprintf_s(status, ARRAYSIZE(status), "Waiting for player...");
|
||||
progress = (timeGetTime() - info.disconnect_start) * 100 / info.disconnect_timeout;
|
||||
break;
|
||||
}
|
||||
|
||||
if (*status) {
|
||||
SetTextAlign(hdc, TA_TOP | TA_CENTER);
|
||||
TextOutA(hdc, ship.position.x, ship.position.y + PROGRESS_TEXT_OFFSET, status, strlen(status));
|
||||
TextOutA(hdc, (int)ship.position.x, (int)ship.position.y + PROGRESS_TEXT_OFFSET, status, (int)strlen(status));
|
||||
}
|
||||
if (progress >= 0) {
|
||||
HBRUSH bar = (HBRUSH)(info.state == Synchronizing ? GetStockObject(WHITE_BRUSH) : _redBrush);
|
||||
RECT rc = { ship.position.x - (PROGRESS_BAR_WIDTH / 2),
|
||||
ship.position.y + PROGRESS_BAR_TOP_OFFSET,
|
||||
ship.position.x + (PROGRESS_BAR_WIDTH / 2),
|
||||
ship.position.y + PROGRESS_BAR_TOP_OFFSET + PROGRESS_BAR_HEIGHT };
|
||||
RECT rc = { (LONG)(ship.position.x - (PROGRESS_BAR_WIDTH / 2)),
|
||||
(LONG)(ship.position.y + PROGRESS_BAR_TOP_OFFSET),
|
||||
(LONG)(ship.position.x + (PROGRESS_BAR_WIDTH / 2)),
|
||||
(LONG)(ship.position.y + PROGRESS_BAR_TOP_OFFSET + PROGRESS_BAR_HEIGHT) };
|
||||
|
||||
FrameRect(hdc, &rc, (HBRUSH)GetStockObject(GRAY_BRUSH));
|
||||
rc.right = rc.left + min(100, progress) * PROGRESS_BAR_WIDTH / 100;
|
||||
@@ -192,7 +192,7 @@ GDIRenderer::DrawConnectState(HDC hdc, Ship &ship, PlayerConnectionInfo &info, C
|
||||
|
||||
|
||||
void
|
||||
GDIRenderer::CreateGDIFont(HDC hdc)
|
||||
GDIRenderer::CreateGDIFont(HDC)
|
||||
{
|
||||
_font = CreateFont(-12,
|
||||
0, // Width Of Font
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
protected:
|
||||
void RenderChecksum(HDC hdc, int y, NonGameState::ChecksumInfo &info);
|
||||
void DrawShip(HDC hdc, int which, GameState &gamestate);
|
||||
void DrawConnectState(HDC hdc, Ship &ship, PlayerConnectionInfo &info, COLORREF color);
|
||||
void DrawConnectState(HDC hdc, Ship &ship, PlayerConnectionInfo &info);
|
||||
void CreateGDIFont(HDC hdc);
|
||||
|
||||
HFONT _font;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -159,7 +159,7 @@ ggpoutil_perfmon_toggle()
|
||||
void
|
||||
ggpoutil_perfmon_update(GGPOSession *ggpo, GGPOPlayerHandle players[], int num_players)
|
||||
{
|
||||
GGPONetworkStats stats;
|
||||
GGPONetworkStats stats = { 0 };
|
||||
int i;
|
||||
|
||||
_num_players = num_players;
|
||||
@@ -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);
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#include "vectorwar.h"
|
||||
#include "ggpo_perfmon.h"
|
||||
|
||||
int local_port, num_players, num_spectators;
|
||||
|
||||
LRESULT CALLBACK
|
||||
MainWindowProc(HWND hwnd,
|
||||
UINT uMsg,
|
||||
@@ -94,18 +92,18 @@ Syntax()
|
||||
MessageBox(NULL,
|
||||
L"Syntax: vectorwar.exe <local port> <num players> ('local' | <remote ip>:<remote port>)*\n",
|
||||
L"Could not start", MB_OK);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
_In_opt_ HINSTANCE hPrevInstance,
|
||||
_In_ LPWSTR lpCmdLine,
|
||||
_In_ int nCmdShow)
|
||||
_In_opt_ HINSTANCE,
|
||||
_In_ LPWSTR,
|
||||
_In_ int)
|
||||
{
|
||||
HWND hwnd = CreateMainWindow(hInstance);
|
||||
int offset = 1, local_player = 0;
|
||||
WSADATA wd = { 0 };
|
||||
wchar_t wide_ip_buffer[128];
|
||||
unsigned int wide_ip_buffer_size = (unsigned int)ARRAYSIZE(wide_ip_buffer);
|
||||
|
||||
WSAStartup(MAKEWORD(2, 2), &wd);
|
||||
POINT window_offsets[] = {
|
||||
@@ -123,18 +121,20 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
Syntax();
|
||||
return 1;
|
||||
}
|
||||
local_port = _wtoi(__wargv[offset++]);
|
||||
num_players = _wtoi(__wargv[offset++]);
|
||||
unsigned short local_port = (unsigned short)_wtoi(__wargv[offset++]);
|
||||
int num_players = _wtoi(__wargv[offset++]);
|
||||
if (num_players < 0 || __argc < offset + num_players) {
|
||||
Syntax();
|
||||
return 1;
|
||||
}
|
||||
if (wcscmp(__wargv[offset], L"spectate") == 0) {
|
||||
char host_ip[128];
|
||||
int host_port;
|
||||
if (swscanf(__wargv[offset+1], L"%[^:]:%d", wide_ip_buffer, &host_port) != 2) {
|
||||
unsigned short host_port;
|
||||
if (swscanf_s(__wargv[offset+1], L"%[^:]:%hu", wide_ip_buffer, wide_ip_buffer_size, &host_port) != 2) {
|
||||
Syntax();
|
||||
return 1;
|
||||
}
|
||||
wcstombs(host_ip, wide_ip_buffer, sizeof(host_ip));
|
||||
wcstombs_s(nullptr, host_ip, ARRAYSIZE(host_ip), wide_ip_buffer, _TRUNCATE);
|
||||
VectorWar_InitSpectator(hwnd, local_port, num_players, host_ip, host_port);
|
||||
} else {
|
||||
GGPOPlayer players[GGPO_MAX_SPECTATORS + GGPO_MAX_PLAYERS];
|
||||
@@ -152,21 +152,21 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
}
|
||||
|
||||
players[i].type = GGPO_PLAYERTYPE_REMOTE;
|
||||
if (swscanf(arg, L"%[^:]:%hd", wide_ip_buffer, &players[i].u.remote.port) != 2) {
|
||||
if (swscanf_s(arg, L"%[^:]:%hd", wide_ip_buffer, wide_ip_buffer_size, &players[i].u.remote.port) != 2) {
|
||||
Syntax();
|
||||
return 1;
|
||||
}
|
||||
wcstombs(players[i].u.remote.ip_address, wide_ip_buffer, sizeof(players[i].u.remote.ip_address));
|
||||
wcstombs_s(nullptr, players[i].u.remote.ip_address, ARRAYSIZE(players[i].u.remote.ip_address), wide_ip_buffer, _TRUNCATE);
|
||||
}
|
||||
// these are spectators...
|
||||
num_spectators = 0;
|
||||
int num_spectators = 0;
|
||||
while (offset < __argc) {
|
||||
players[i].type = GGPO_PLAYERTYPE_SPECTATOR;
|
||||
if (swscanf(__wargv[offset++], L"%[^:]:%hd", wide_ip_buffer, &players[i].u.remote.port) != 2) {
|
||||
if (swscanf_s(__wargv[offset++], L"%[^:]:%hd", wide_ip_buffer, wide_ip_buffer_size, &players[i].u.remote.port) != 2) {
|
||||
Syntax();
|
||||
return 1;
|
||||
}
|
||||
wcstombs(players[i].u.remote.ip_address, wide_ip_buffer, sizeof(players[i].u.remote.ip_address));
|
||||
wcstombs_s(nullptr, players[i].u.remote.ip_address, ARRAYSIZE(players[i].u.remote.ip_address), wide_ip_buffer, _TRUNCATE);
|
||||
i++;
|
||||
num_spectators++;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -27,7 +27,7 @@ fletcher32_checksum(short *data, size_t len)
|
||||
int sum1 = 0xffff, sum2 = 0xffff;
|
||||
|
||||
while (len) {
|
||||
unsigned tlen = len > 360 ? 360 : len;
|
||||
size_t tlen = len > 360 ? 360 : len;
|
||||
len -= tlen;
|
||||
do {
|
||||
sum1 += *data++;
|
||||
@@ -50,7 +50,7 @@ fletcher32_checksum(short *data, size_t len)
|
||||
* so just return true.
|
||||
*/
|
||||
bool __cdecl
|
||||
vw_begin_game_callback(const char *name)
|
||||
vw_begin_game_callback(const char *)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ vw_on_event_callback(GGPOEvent *info)
|
||||
* during a rollback.
|
||||
*/
|
||||
bool __cdecl
|
||||
vw_advance_frame_callback(int flags)
|
||||
vw_advance_frame_callback(int)
|
||||
{
|
||||
int inputs[MAX_SHIPS] = { 0 };
|
||||
int disconnect_flags;
|
||||
@@ -137,7 +137,7 @@ vw_load_game_state_callback(unsigned char *buffer, int len)
|
||||
* buffer and len parameters.
|
||||
*/
|
||||
bool __cdecl
|
||||
vw_save_game_state_callback(unsigned char **buffer, int *len, int *checksum, int frame)
|
||||
vw_save_game_state_callback(unsigned char **buffer, int *len, int *checksum, int)
|
||||
{
|
||||
*len = sizeof(gs);
|
||||
*buffer = (unsigned char *)malloc(*len);
|
||||
@@ -155,9 +155,10 @@ vw_save_game_state_callback(unsigned char **buffer, int *len, int *checksum, int
|
||||
* Log the gamestate. Used by the synctest debugging tool.
|
||||
*/
|
||||
bool __cdecl
|
||||
vw_log_game_state(char *filename, unsigned char *buffer, int len)
|
||||
vw_log_game_state(char *filename, unsigned char *buffer, int)
|
||||
{
|
||||
FILE *fp = fopen(filename, "w");
|
||||
FILE* fp = nullptr;
|
||||
fopen_s(&fp, filename, "w");
|
||||
if (fp) {
|
||||
GameState *gamestate = (GameState *)buffer;
|
||||
fprintf(fp, "GameState object.\n");
|
||||
@@ -205,7 +206,7 @@ vw_free_buffer(void *buffer)
|
||||
* the video renderer and creates a new network session.
|
||||
*/
|
||||
void
|
||||
VectorWar_Init(HWND hwnd, int localport, int num_players, GGPOPlayer *players, int num_spectators)
|
||||
VectorWar_Init(HWND hwnd, unsigned short localport, int num_players, GGPOPlayer *players, int num_spectators)
|
||||
{
|
||||
GGPOErrorCode result;
|
||||
renderer = new GDIRenderer(hwnd);
|
||||
@@ -262,7 +263,7 @@ VectorWar_Init(HWND hwnd, int localport, int num_players, GGPOPlayer *players, i
|
||||
* Create a new spectator session
|
||||
*/
|
||||
void
|
||||
VectorWar_InitSpectator(HWND hwnd, int localport, int num_players, char *host_ip, int host_port)
|
||||
VectorWar_InitSpectator(HWND hwnd, unsigned short localport, int num_players, char *host_ip, unsigned short host_port)
|
||||
{
|
||||
GGPOErrorCode result;
|
||||
renderer = new GDIRenderer(hwnd);
|
||||
@@ -302,9 +303,9 @@ VectorWar_DisconnectPlayer(int player)
|
||||
char logbuf[128];
|
||||
GGPOErrorCode result = ggpo_disconnect_player(ggpo, ngs.players[player].handle);
|
||||
if (GGPO_SUCCEEDED(result)) {
|
||||
sprintf(logbuf, "Disconnected player %d.\n", player);
|
||||
sprintf_s(logbuf, ARRAYSIZE(logbuf), "Disconnected player %d.\n", player);
|
||||
} else {
|
||||
sprintf(logbuf, "Error while disconnecting player (err:%d).\n", result);
|
||||
sprintf_s(logbuf, ARRAYSIZE(logbuf), "Error while disconnecting player (err:%d).\n", result);
|
||||
}
|
||||
renderer->SetStatusText(logbuf);
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ enum VectorWarInputs {
|
||||
INPUT_BOMB = (1 << 5),
|
||||
};
|
||||
|
||||
void VectorWar_Init(HWND hwnd, int localport, int num_players, GGPOPlayer *players, int num_spectators);
|
||||
void VectorWar_InitSpectator(HWND hwnd, int localport, int num_players, char *host_ip, int host_port);
|
||||
void VectorWar_Init(HWND hwnd, unsigned short localport, int num_players, GGPOPlayer *players, int num_spectators);
|
||||
void VectorWar_InitSpectator(HWND hwnd, unsigned short localport, int num_players, char *host_ip, unsigned short host_port);
|
||||
void VectorWar_DrawCurrentFrame();
|
||||
void VectorWar_AdvanceFrame(int inputs[], int disconnect_flags);
|
||||
void VectorWar_RunFrame(HWND hwnd);
|
||||
|
||||
@@ -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 short local_port,
|
||||
char *host_ip,
|
||||
int host_port);
|
||||
unsigned short 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);
|
||||
|
||||
27
src/lib/ggpo/platform_windows.cpp
Normal file
27
src/lib/ggpo/platform_windows.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/* -----------------------------------------------------------------------
|
||||
* GGPO.net (http://ggpo.net) - Copyright 2009 GroundStorm Studios, LLC.
|
||||
*
|
||||
* Use of this software is governed by the MIT license that can be found
|
||||
* in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "platform_windows.h"
|
||||
|
||||
int
|
||||
Platform::GetConfigInt(const char* name)
|
||||
{
|
||||
char buf[1024];
|
||||
if (GetEnvironmentVariable(name, buf, ARRAY_SIZE(buf)) == 0) {
|
||||
return 0;
|
||||
}
|
||||
return atoi(buf);
|
||||
}
|
||||
|
||||
bool Platform::GetConfigBool(const char* name)
|
||||
{
|
||||
char buf[1024];
|
||||
if (GetEnvironmentVariable(name, buf, ARRAY_SIZE(buf)) == 0) {
|
||||
return false;
|
||||
}
|
||||
return atoi(buf) != 0 || _stricmp(buf, "true") == 0;
|
||||
}
|
||||
@@ -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