Skip to content

Commit

Permalink
Updated to the latest version of SDL
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Sep 18, 2024
1 parent 6021c0e commit cad9d77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions examples/voipchat.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,24 @@ static void SendClientAudioToServer(void)

static void mainloop(void)
{
const SDL_bool is_client = (server_addr != NULL) ? SDL_TRUE : SDL_FALSE;
SDL_bool done = SDL_FALSE;
const bool is_client = (server_addr != NULL) ? true : false;
bool done = false;
Uint64 last_send_ticks = 0;

if (is_client) {
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); /* red by default (green when recording) */
}

while (!done) {
SDL_bool activity = SDL_FALSE;
bool activity = false;
const Uint64 now = SDL_GetTicks();
SDL_Event event;
SDLNet_Datagram *dgram = NULL;
int rc;

while (((rc = SDLNet_ReceiveDatagram(sock, &dgram)) == 0) && (dgram != NULL)) {
SDL_Log("%s: got %d-byte datagram from %s:%d", is_client ? "CLIENT" : "SERVER", (int) dgram->buflen, SDLNet_GetAddressString(dgram->addr), (int) dgram->port);
activity = SDL_TRUE;
activity = true;
if (!is_client) { /* we're the server? */
Voice *voice = FindVoiceByAddr(dgram->addr, dgram->port);
Voice *i;
Expand Down Expand Up @@ -187,7 +187,7 @@ static void mainloop(void)
}

while (SDL_PollEvent(&event)) {
activity = SDL_TRUE;
activity = true;
switch (event.type) {
case SDL_EVENT_QUIT:
done = 1;
Expand Down Expand Up @@ -220,7 +220,7 @@ static void mainloop(void)
while (SDL_GetAudioStreamAvailable(capture_stream) > max_datagram) {
SendClientAudioToServer();
last_send_ticks = now;
activity = SDL_TRUE;
activity = true;
}
}

Expand All @@ -247,14 +247,14 @@ static void mainloop(void)
static void run_voipchat(int argc, char **argv)
{
const char *hostname = NULL;
SDL_bool is_server = SDL_FALSE;
bool is_server = false;
int simulate_failure = 0;
int i;

for (i = 1; i < argc; i++) {
const char *arg = argv[i];
if (SDL_strcmp(arg, "--server") == 0) {
is_server = SDL_TRUE;
is_server = true;
} else if ((SDL_strcmp(arg, "--port") == 0) && (i < (argc-1))) {
server_port = (Uint16) SDL_atoi(argv[++i]);
} else if ((SDL_strcmp(arg, "--simulate-failure") == 0) && (i < (argc-1))) {
Expand Down
16 changes: 8 additions & 8 deletions src/SDL_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,12 @@ static int MakeSocketNonblocking(Socket handle)
#endif
}

static SDL_bool WouldBlock(const int err)
static bool WouldBlock(const int err)
{
#ifdef _WIN32
return (err == WSAEWOULDBLOCK) ? SDL_TRUE : SDL_FALSE;
return (err == WSAEWOULDBLOCK) ? true : false;
#else
return ((err == EWOULDBLOCK) || (err == EAGAIN) || (err == EINPROGRESS)) ? SDL_TRUE : SDL_FALSE;
return ((err == EWOULDBLOCK) || (err == EAGAIN) || (err == EINPROGRESS)) ? true : false;
#endif
}

Expand Down Expand Up @@ -1490,7 +1490,7 @@ int SDLNet_ReceiveDatagram(SDLNet_DatagramSocket *sock, SDLNet_Datagram **dgram)
}
}

const SDL_bool create_fromaddr = (!fromaddr) ? SDL_TRUE : SDL_FALSE;
const bool create_fromaddr = (!fromaddr) ? true : false;
if (create_fromaddr) {
fromaddr = CreateSDLNetAddrFromSockAddr((struct sockaddr *) &from, fromlen);
if (!fromaddr) {
Expand Down Expand Up @@ -1598,7 +1598,7 @@ int SDLNet_WaitUntilInputAvailable(void **vsockets, int numsockets, int timeoutm
int retval = 0;
const Uint64 endtime = (timeoutms > 0) ? (SDL_GetTicks() + timeoutms) : 0;

while (SDL_TRUE) {
while (true) {
SDL_memset(pfds, '\0', sizeof (*pfds) * numsockets);

for (int i = 0; i < numsockets; i++) {
Expand Down Expand Up @@ -1643,9 +1643,9 @@ int SDLNet_WaitUntilInputAvailable(void **vsockets, int numsockets, int timeoutm
for (int i = 0; i < numsockets; i++) {
SDLNet_GenericSocket *sock = sockets[i];
const struct pollfd *pfd = &pfds[i];
const SDL_bool failed = ((pfd->revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) ? SDL_TRUE : SDL_FALSE;
const SDL_bool writable = (pfd->revents & POLLOUT) ? SDL_TRUE : SDL_FALSE;
const SDL_bool readable = (pfd->revents & POLLIN) ? SDL_TRUE : SDL_FALSE;
const bool failed = ((pfd->revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) ? true : false;
const bool writable = (pfd->revents & POLLOUT) ? true : false;
const bool readable = (pfd->revents & POLLIN) ? true : false;

if (readable || failed) {
retval++;
Expand Down

0 comments on commit cad9d77

Please sign in to comment.