| 
Complete.Org:
Mailing Lists:
Archives:
freeciv-dev:
February 2003: [Freeciv-Dev] Re: (PR#3391) SDL client polls the network  | 
  
   | 
[Freeciv-Dev] Re: (PR#3391) SDL client polls the network[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index] 
 
 HiAs I say before SDL is Simple DirectMedia Layer that was design to work on many enviroment. Event code was create also for work on no-threaded system ( Windows ???? ) and with single thread program. In this role work great but it doesn't mean its good solution :( Some time before Bob Pendelton fight with this problem and he creatae thread based event code (see: http://gameprogrammer.com/game.html ) we can use his code ( is small see attach ) and write somthing like : /* Secoudary thread */ static int socket_thread(void *socket) { struct timeval tv; fd_set civfdset; SDL_Event ev; ev.type = SDL_USEREVENT; ev.user.code = 0; ev.user.data1 = 0; ev.user.data2 = 0; while (net_socket >= 0) { FD_ZERO(&civfdset); FD_SET(net_socket, &civfdset); tv.tv_sec = 0; tv.tv_usec = 0; if (select(FD_SETSIZE, &civfdset, NULL, NULL, &tv)) { if (FD_ISSET(net_socket, &civfdset)) { FE_PushEvent(&ev); } } } /* while */ return 0; } /* Primary Thread */ void add_net_input(int sock) { freelog(LOG_DEBUG, "Connection UP (%d)", sock); net_socket = sock; pThread = SDL_CreateThread(socket_thread, NULL); } void remove_net_input(void) { net_socket = (-1); freelog(LOG_DEBUG, "Connection DOWN... "); SDL_WaitThread(pThread, NULL);} and in main event loop : 
    FE_WaitEvent(&Main.event);
    switch (Main.event.type) {
    case SDL_QUIT:
      return;
    case SDL_USEREVENT:
      input_from_server(net_socket);
    break;
...
But when I use it I can't make debug with gdb :(
Rafal
----------------------------------------------------------------------
KOBIETA > Uroda >>> http://link.interia.pl/f16cd
 
 
 
 
  |