Silence Clang warnings

This commit is contained in:
twinaphex 2018-04-09 17:35:27 +02:00
parent 9381d27f1f
commit 8e7b1ede7f
4 changed files with 143 additions and 88 deletions

View File

@ -46,7 +46,7 @@ endif
include Makefile.common include Makefile.common
ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang"),1) ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang"),1)
DEFINES += -Wno-invalid-source-encoding DEFINES += -Wno-invalid-source-encoding -Wno-incompatible-ms-struct
endif endif
ifeq ($(shell $(CC) -v 2>&1 | grep -c "tcc"),1) ifeq ($(shell $(CC) -v 2>&1 | grep -c "tcc"),1)

View File

@ -155,7 +155,7 @@ static void frontend_win32_get_os(char *s, size_t len, int *major, int *minor)
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500
/* Windows 2000 and later */ /* Windows 2000 and later */
SYSTEM_INFO si = {0}; SYSTEM_INFO si = {{0}};
OSVERSIONINFOEX vi = {0}; OSVERSIONINFOEX vi = {0};
vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
@ -359,7 +359,7 @@ enum frontend_architecture frontend_win32_get_architecture(void)
{ {
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500
/* Windows 2000 and later */ /* Windows 2000 and later */
SYSTEM_INFO si = {0}; SYSTEM_INFO si = {{0}};
GetSystemInfo(&si); GetSystemInfo(&si);

View File

@ -948,8 +948,9 @@ bool win32_suppress_screensaver(void *data, bool enable)
#ifndef _XBOX #ifndef _XBOX
if(enable) if(enable)
{ {
int major, minor;
char tmp[PATH_MAX_LENGTH]; char tmp[PATH_MAX_LENGTH];
int major = 0;
int minor = 0;
const frontend_ctx_driver_t *frontend = frontend_get_ptr(); const frontend_ctx_driver_t *frontend = frontend_get_ptr();
if (!frontend) if (!frontend)

View File

@ -126,35 +126,51 @@ static void netplay_merge_digital(netplay_t *netplay,
{ {
netplay_input_state_t simstate; netplay_input_state_t simstate;
uint32_t word, bit, client; uint32_t word, bit, client;
uint8_t share_mode = netplay->device_share_modes[device] & NETPLAY_SHARE_DIGITAL_BITS; uint8_t share_mode = netplay->device_share_modes[device]
& NETPLAY_SHARE_DIGITAL_BITS;
/* Make sure all real clients are accounted for */ /* Make sure all real clients are accounted for */
for (simstate = simframe->real_input[device]; simstate; simstate = simstate->next) for (simstate = simframe->real_input[device];
simstate; simstate = simstate->next)
{ {
if (!simstate->used || simstate->size != resstate->size) continue; if (!simstate->used || simstate->size != resstate->size)
continue;
clients |= 1<<simstate->client_num; clients |= 1<<simstate->client_num;
} }
if (share_mode == NETPLAY_SHARE_DIGITAL_VOTE) if (share_mode == NETPLAY_SHARE_DIGITAL_VOTE)
{ {
unsigned i, j;
/* This just assumes we have no more than
* three words, will need to be adjusted for new devices */
struct vote_count votes[3];
/* Vote mode requires counting all the bits */ /* Vote mode requires counting all the bits */
uint32_t client_count = 0; uint32_t client_count = 0;
/* This just assumes we have no more than three words, will need to be adjusted for new devices */ for (i = 0; i < 3; i++)
struct vote_count votes[3] = {0}; for (j = 0; j < 32; j++)
votes[i].votes[j] = 0;
for (client = 0; client < MAX_CLIENTS; client++) for (client = 0; client < MAX_CLIENTS; client++)
{ {
if (!(clients & (1<<client))) continue; if (!(clients & (1<<client)))
simstate = netplay_device_client_state(netplay, simframe, device, client); continue;
if (!simstate) continue;
simstate = netplay_device_client_state(
netplay, simframe, device, client);
if (!simstate)
continue;
client_count++; client_count++;
for (word = 0; word < resstate->size; word++) for (word = 0; word < resstate->size; word++)
{ {
if (!digital[word]) continue; if (!digital[word])
continue;
for (bit = 0; bit < 32; bit++) for (bit = 0; bit < 32; bit++)
{ {
if (!(digital[word] & (1<<bit))) continue; if (!(digital[word] & (1<<bit)))
continue;
if (simstate->data[word] & (1<<bit)) if (simstate->data[word] & (1<<bit))
votes[word].votes[bit]++; votes[word].votes[bit]++;
} }
@ -171,27 +187,35 @@ static void netplay_merge_digital(netplay_t *netplay,
resstate->data[word] |= (1<<bit); resstate->data[word] |= (1<<bit);
} }
} }
} }
else /* !VOTE */ else /* !VOTE */
{ {
for (client = 0; client < MAX_CLIENTS; client++) for (client = 0; client < MAX_CLIENTS; client++)
{ {
if (!(clients & (1<<client))) continue; if (!(clients & (1<<client)))
simstate = netplay_device_client_state(netplay, simframe, device, client); continue;
if (!simstate) continue; simstate = netplay_device_client_state(
netplay, simframe, device, client);
if (!simstate)
continue;
for (word = 0; word < resstate->size; word++) for (word = 0; word < resstate->size; word++)
{ {
uint32_t part; uint32_t part;
if (!digital[word]) continue; if (!digital[word])
continue;
part = simstate->data[word]; part = simstate->data[word];
if (digital[word] == (uint32_t) -1) if (digital[word] == (uint32_t) -1)
{ {
/* Combine the whole word */ /* Combine the whole word */
switch (share_mode) switch (share_mode)
{ {
case NETPLAY_SHARE_DIGITAL_XOR: resstate->data[word] ^= part; break; case NETPLAY_SHARE_DIGITAL_XOR:
default: resstate->data[word] |= part; resstate->data[word] ^= part;
break;
default:
resstate->data[word] |= part;
} }
} }
@ -199,11 +223,15 @@ static void netplay_merge_digital(netplay_t *netplay,
{ {
for (bit = 0; bit < 32; bit++) for (bit = 0; bit < 32; bit++)
{ {
if (!(digital[word] & (1<<bit))) continue; if (!(digital[word] & (1<<bit)))
continue;
switch (share_mode) switch (share_mode)
{ {
case NETPLAY_SHARE_DIGITAL_XOR: resstate->data[word] ^= part & (1<<bit); break; case NETPLAY_SHARE_DIGITAL_XOR:
default: resstate->data[word] |= part & (1<<bit); resstate->data[word] ^= part & (1<<bit);
break;
default:
resstate->data[word] |= part & (1<<bit);
} }
} }
} }
@ -229,21 +257,26 @@ static void merge_analog_part(netplay_t *netplay,
{ {
netplay_input_state_t simstate; netplay_input_state_t simstate;
uint32_t client, client_count = 0; uint32_t client, client_count = 0;
uint8_t share_mode = netplay->device_share_modes[device] & NETPLAY_SHARE_ANALOG_BITS; uint8_t share_mode = netplay->device_share_modes[device]
& NETPLAY_SHARE_ANALOG_BITS;
int32_t value = 0, new_value; int32_t value = 0, new_value;
/* Make sure all real clients are accounted for */ /* Make sure all real clients are accounted for */
for (simstate = simframe->real_input[device]; simstate; simstate = simstate->next) for (simstate = simframe->real_input[device]; simstate; simstate = simstate->next)
{ {
if (!simstate->used || simstate->size != resstate->size) continue; if (!simstate->used || simstate->size != resstate->size)
continue;
clients |= 1<<simstate->client_num; clients |= 1<<simstate->client_num;
} }
for (client = 0; client < MAX_CLIENTS; client++) for (client = 0; client < MAX_CLIENTS; client++)
{ {
if (!(clients & (1<<client))) continue; if (!(clients & (1<<client)))
simstate = netplay_device_client_state(netplay, simframe, device, client); continue;
if (!simstate) continue; simstate = netplay_device_client_state(
netplay, simframe, device, client);
if (!simstate)
continue;
client_count++; client_count++;
new_value = (int16_t) ((simstate->data[word]>>bit) & 0xFFFF); new_value = (int16_t) ((simstate->data[word]>>bit) & 0xFFFF);
switch (share_mode) switch (share_mode)
@ -307,13 +340,13 @@ static void netplay_merge_analog(netplay_t *netplay,
bool netplay_resolve_input(netplay_t *netplay, size_t sim_ptr, bool resim) bool netplay_resolve_input(netplay_t *netplay, size_t sim_ptr, bool resim)
{ {
size_t prev; size_t prev;
struct delta_frame *simframe, *pframe;
netplay_input_state_t simstate, client_state = NULL, resstate, oldresstate, pstate;
uint32_t clients, client, client_count;
uint32_t device; uint32_t device;
uint32_t clients, client, client_count;
netplay_input_state_t simstate, client_state = NULL,
resstate, oldresstate, pstate;
bool ret = false; bool ret = false;
struct delta_frame *pframe = NULL;
simframe = &netplay->buffer[sim_ptr]; struct delta_frame *simframe = &netplay->buffer[sim_ptr];
for (device = 0; device < MAX_INPUT_DEVICES; device++) for (device = 0; device < MAX_INPUT_DEVICES; device++)
{ {
@ -325,19 +358,23 @@ bool netplay_resolve_input(netplay_t *netplay, size_t sim_ptr, bool resim)
/* Make sure all real clients are accounted for */ /* Make sure all real clients are accounted for */
for (simstate = simframe->real_input[device]; simstate; simstate = simstate->next) for (simstate = simframe->real_input[device]; simstate; simstate = simstate->next)
{ {
if (!simstate->used || simstate->size != dsize) continue; if (!simstate->used || simstate->size != dsize)
continue;
clients |= 1<<simstate->client_num; clients |= 1<<simstate->client_num;
} }
for (client = 0; client < MAX_CLIENTS; client++) for (client = 0; client < MAX_CLIENTS; client++)
{ {
if (!(clients & (1<<client))) continue; if (!(clients & (1<<client)))
continue;
/* Resolve this client-device */ /* Resolve this client-device */
simstate = netplay_input_state_for(&simframe->real_input[device], client, dsize, false, true); simstate = netplay_input_state_for(
&simframe->real_input[device], client, dsize, false, true);
if (!simstate) if (!simstate)
{ {
/* Don't already have this input, so must simulate if we're supposed to have it at all */ /* Don't already have this input, so must
* simulate if we're supposed to have it at all */
if (netplay->read_frame_count[client] > simframe->frame) if (netplay->read_frame_count[client] > simframe->frame)
continue; continue;
simstate = netplay_input_state_for(&simframe->simlated_input[device], client, dsize, false, false); simstate = netplay_input_state_for(&simframe->simlated_input[device], client, dsize, false, false);
@ -376,29 +413,31 @@ bool netplay_resolve_input(netplay_t *netplay, size_t sim_ptr, bool resim)
simstate->data[0] |= pstate->data[0] & ~keep; simstate->data[0] |= pstate->data[0] & ~keep;
} }
else else
{
memcpy(simstate->data, pstate->data, memcpy(simstate->data, pstate->data,
dsize * sizeof(uint32_t)); dsize * sizeof(uint32_t));
} }
}
client_state = simstate; client_state = simstate;
client_count++; client_count++;
} }
/* The frontend always uses the first resolved input, so make sure it's right */ /* The frontend always uses the first resolved input,
* so make sure it's right */
while (simframe->resolved_input[device] while (simframe->resolved_input[device]
&& (simframe->resolved_input[device]->size != dsize && (simframe->resolved_input[device]->size != dsize
|| simframe->resolved_input[device]->client_num != 0)) || simframe->resolved_input[device]->client_num != 0))
{ {
/* The default resolved input is of the wrong size! */ /* The default resolved input is of the wrong size! */
netplay_input_state_t nextistate = simframe->resolved_input[device]->next; netplay_input_state_t nextistate =
simframe->resolved_input[device]->next;
free(simframe->resolved_input[device]); free(simframe->resolved_input[device]);
simframe->resolved_input[device] = nextistate; simframe->resolved_input[device] = nextistate;
} }
/* Now we copy the state, whether real or simulated, out into the resolved state */ /* Now we copy the state, whether real or simulated,
resstate = netplay_input_state_for(&simframe->resolved_input[device], 0, * out into the resolved state */
resstate = netplay_input_state_for(
&simframe->resolved_input[device], 0,
dsize, false, false); dsize, false, false);
if (!resstate) if (!resstate)
continue; continue;
@ -406,9 +445,11 @@ bool netplay_resolve_input(netplay_t *netplay, size_t sim_ptr, bool resim)
if (client_count == 1) if (client_count == 1)
{ {
/* Trivial in the common 1-client case */ /* Trivial in the common 1-client case */
if (memcmp(resstate->data, client_state->data, dsize * sizeof(uint32_t))) if (memcmp(resstate->data, client_state->data,
dsize * sizeof(uint32_t)))
ret = true; ret = true;
memcpy(resstate->data, client_state->data, dsize * sizeof(uint32_t)); memcpy(resstate->data, client_state->data,
dsize * sizeof(uint32_t));
} }
else if (client_count == 0) else if (client_count == 0)
@ -433,16 +474,20 @@ bool netplay_resolve_input(netplay_t *netplay, size_t sim_ptr, bool resim)
digital = digital_keyboard; digital = digital_keyboard;
else else
digital = digital_common; digital = digital_common;
oldresstate = netplay_input_state_for(&simframe->resolved_input[device], 1, dsize, false, false); oldresstate = netplay_input_state_for(
&simframe->resolved_input[device], 1, dsize, false, false);
if (!oldresstate) if (!oldresstate)
continue; continue;
memcpy(oldresstate->data, resstate->data, dsize * sizeof(uint32_t)); memcpy(oldresstate->data, resstate->data, dsize * sizeof(uint32_t));
memset(resstate->data, 0, dsize * sizeof(uint32_t)); memset(resstate->data, 0, dsize * sizeof(uint32_t));
netplay_merge_digital(netplay, resstate, simframe, device, clients, digital); netplay_merge_digital(netplay, resstate, simframe,
netplay_merge_analog(netplay, resstate, simframe, device, clients, dtype); device, clients, digital);
netplay_merge_analog(netplay, resstate, simframe,
device, clients, dtype);
if (memcmp(resstate->data, oldresstate->data, dsize * sizeof(uint32_t))) if (memcmp(resstate->data, oldresstate->data,
dsize * sizeof(uint32_t)))
ret = true; ret = true;
} }
@ -451,7 +496,8 @@ bool netplay_resolve_input(netplay_t *netplay, size_t sim_ptr, bool resim)
return ret; return ret;
} }
static void netplay_handle_frame_hash(netplay_t *netplay, struct delta_frame *delta) static void netplay_handle_frame_hash(netplay_t *netplay,
struct delta_frame *delta)
{ {
if (netplay->is_server) if (netplay->is_server)
{ {
@ -468,12 +514,10 @@ static void netplay_handle_frame_hash(netplay_t *netplay, struct delta_frame *de
uint32_t local_crc = netplay_delta_frame_crc(netplay, delta); uint32_t local_crc = netplay_delta_frame_crc(netplay, delta);
if (local_crc != delta->crc) if (local_crc != delta->crc)
{ {
/* If the very first check frame is wrong,
* they probably just don't work */
if (!netplay->crc_validity_checked) if (!netplay->crc_validity_checked)
{
/* If the very first check frame is wrong, they probably just don't
* work */
netplay->crcs_valid = false; netplay->crcs_valid = false;
}
else if (netplay->crcs_valid) else if (netplay->crcs_valid)
{ {
/* Fix this! */ /* Fix this! */
@ -483,16 +527,12 @@ static void netplay_handle_frame_hash(netplay_t *netplay, struct delta_frame *de
RARCH_ERR("Netplay CRCs mismatch!\n"); RARCH_ERR("Netplay CRCs mismatch!\n");
} }
else else
{
netplay_cmd_request_savestate(netplay); netplay_cmd_request_savestate(netplay);
} }
} }
}
else if (!netplay->crc_validity_checked) else if (!netplay->crc_validity_checked)
{
netplay->crc_validity_checked = true; netplay->crc_validity_checked = true;
} }
}
} }
/** /**
@ -505,23 +545,27 @@ bool netplay_sync_pre_frame(netplay_t *netplay)
{ {
retro_ctx_serialize_info_t serial_info; retro_ctx_serialize_info_t serial_info;
if (netplay_delta_frame_ready(netplay, &netplay->buffer[netplay->run_ptr], netplay->run_frame_count)) if (netplay_delta_frame_ready(netplay,
&netplay->buffer[netplay->run_ptr], netplay->run_frame_count))
{ {
serial_info.data_const = NULL; serial_info.data_const = NULL;
serial_info.data = netplay->buffer[netplay->run_ptr].state; serial_info.data = netplay->buffer[netplay->run_ptr].state;
serial_info.size = netplay->state_size; serial_info.size = netplay->state_size;
memset(serial_info.data, 0, serial_info.size); memset(serial_info.data, 0, serial_info.size);
if ((netplay->quirks & NETPLAY_QUIRK_INITIALIZATION) || netplay->run_frame_count == 0) if ((netplay->quirks & NETPLAY_QUIRK_INITIALIZATION)
|| netplay->run_frame_count == 0)
{ {
/* Don't serialize until it's safe */ /* Don't serialize until it's safe */
} }
else if (!(netplay->quirks & NETPLAY_QUIRK_NO_SAVESTATES) && core_serialize(&serial_info)) else if (!(netplay->quirks & NETPLAY_QUIRK_NO_SAVESTATES)
&& core_serialize(&serial_info))
{ {
if (netplay->force_send_savestate && !netplay->stall && !netplay->remote_paused) if (netplay->force_send_savestate && !netplay->stall
&& !netplay->remote_paused)
{ {
/* Bring our running frame and input frames into parity so we don't /* Bring our running frame and input frames into
* send old info */ * parity so we don't send old info. */
if (netplay->run_ptr != netplay->self_ptr) if (netplay->run_ptr != netplay->self_ptr)
{ {
memcpy(netplay->buffer[netplay->self_ptr].state, memcpy(netplay->buffer[netplay->self_ptr].state,
@ -545,7 +589,8 @@ bool netplay_sync_pre_frame(netplay_t *netplay)
netplay->stateless_mode = true; netplay->stateless_mode = true;
} }
/* If we can't transmit savestates, we must stall until the client is ready */ /* If we can't transmit savestates, we must stall
* until the client is ready. */
if (netplay->run_frame_count > 0 && if (netplay->run_frame_count > 0 &&
(netplay->quirks & (NETPLAY_QUIRK_NO_SAVESTATES|NETPLAY_QUIRK_NO_TRANSMISSION)) && (netplay->quirks & (NETPLAY_QUIRK_NO_SAVESTATES|NETPLAY_QUIRK_NO_TRANSMISSION)) &&
(netplay->connections_size == 0 || !netplay->connections[0].active || (netplay->connections_size == 0 || !netplay->connections[0].active ||
@ -566,11 +611,14 @@ bool netplay_sync_pre_frame(netplay_t *netplay)
/* Check for a connection */ /* Check for a connection */
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(netplay->listen_fd, &fds); FD_SET(netplay->listen_fd, &fds);
if (socket_select(netplay->listen_fd + 1, &fds, NULL, NULL, &tmp_tv) > 0 && if (socket_select(netplay->listen_fd + 1,
&fds, NULL, NULL, &tmp_tv) > 0 &&
FD_ISSET(netplay->listen_fd, &fds)) FD_ISSET(netplay->listen_fd, &fds))
{ {
addr_size = sizeof(their_addr); addr_size = sizeof(their_addr);
new_fd = accept(netplay->listen_fd, (struct sockaddr*)&their_addr, &addr_size); new_fd = accept(netplay->listen_fd,
(struct sockaddr*)&their_addr, &addr_size);
if (new_fd < 0) if (new_fd < 0)
{ {
RARCH_ERR("%s\n", msg_hash_to_str(MSG_NETPLAY_FAILED)); RARCH_ERR("%s\n", msg_hash_to_str(MSG_NETPLAY_FAILED));
@ -614,8 +662,10 @@ bool netplay_sync_pre_frame(netplay_t *netplay)
{ {
if (connection_num == 0) if (connection_num == 0)
{ {
netplay->connections = (struct netplay_connection*)malloc(sizeof(struct netplay_connection)); netplay->connections = (struct netplay_connection*)
if (netplay->connections == NULL) malloc(sizeof(struct netplay_connection));
if (!netplay->connections)
{ {
socket_close(new_fd); socket_close(new_fd);
goto process; goto process;
@ -626,10 +676,13 @@ bool netplay_sync_pre_frame(netplay_t *netplay)
else else
{ {
size_t new_connections_size = netplay->connections_size * 2; size_t new_connections_size = netplay->connections_size * 2;
struct netplay_connection *new_connections = (struct netplay_connection*) struct netplay_connection
*new_connections = (struct netplay_connection*)
realloc(netplay->connections, realloc(netplay->connections,
new_connections_size*sizeof(struct netplay_connection)); new_connections_size*sizeof(struct netplay_connection));
if (new_connections == NULL)
if (!new_connections)
{ {
socket_close(new_fd); socket_close(new_fd);
goto process; goto process;
@ -694,7 +747,8 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
/* We've finished an input frame even if we're stalling */ /* We've finished an input frame even if we're stalling */
if ((!stalled || netplay->stall == NETPLAY_STALL_INPUT_LATENCY) && if ((!stalled || netplay->stall == NETPLAY_STALL_INPUT_LATENCY) &&
netplay->self_frame_count < netplay->run_frame_count + netplay->input_latency_frames) netplay->self_frame_count <
netplay->run_frame_count + netplay->input_latency_frames)
{ {
netplay->self_ptr = NEXT_PTR(netplay->self_ptr); netplay->self_ptr = NEXT_PTR(netplay->self_ptr);
netplay->self_frame_count++; netplay->self_frame_count++;