I have been trying to modify this SDL2 game source code to make it playable on android devices.
I had a problem and it was that when I run the game as a host all players are frozen in place and doesn't move
I tracked the problem down until I got to this function
this thread loop is supposed to run forever but it runs only once or twice when I run the app
void *client_loop(void *arg) {
int socket = *((int *) arg);
int16_t tab[BUF_MAX];
int length;
int id, bullets_in_array;
while (1) {
length = client_listen(socket, tab);
id = tab[0];
if (id == -1) {
receive_new_id(tab[1]);
}
SDL_Log("I'm called %i", id);
if (id >= 0) {
check_if_its_new_player(id);
players[id].position.x = tab[1];
players[id].position.y = tab[2];
players[id].kills = tab[3];
players[id].deaths = tab[4];
}
if (id == -2) {
bullets_in_array = (length - sizeof(int16_t)) / (sizeof(int16_t) * 2);
memcpy(bullets_client, tab + 1, sizeof(int16_t) * 2 * bullets_in_array);
bullets_number = bullets_in_array;
}
usleep(50);
}
}
this causes the game to not update players positions.
I think that the client_listen(socket, tab) might be suspicious here it is
int client_listen(int sock, int16_t *tab){
int length = recvfrom(sock, tab, sizeof(int16_t) * BUF_MAX, 0, NULL, 0);
return length;
}
I think this logcat might be related to the problem it appears after few seconds when run the app
the same code works on desktop as you can see the client_loop runs forever on DESKTOP
.
I use <uses-permission android:name="android.permission.INTERNET"/> in the manifest file
