Index: client/civclient.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v retrieving revision 1.138 diff -u -r1.138 civclient.c --- client/civclient.c 2002/06/27 01:11:37 1.138 +++ client/civclient.c 2002/07/16 14:23:34 @@ -672,3 +672,49 @@ { return aconnection.established && find_conn_by_id(game.conn_id)->observer; } + +/************************************************************************** + This function should be called every 500ms. It lets the unit blink + and update the timeout. +**************************************************************************/ +void real_timer_callback(void) +{ + static bool flip = FALSE; + + assert(TIMER_INTERVAL == 500); + + if (get_client_state() == CLIENT_GAME_RUNNING_STATE) { + if (game.player_ptr->is_connected && game.player_ptr->is_alive && + !game.player_ptr->turn_done) { + int is_waiting = 0, is_moving = 0; + + players_iterate(pplayer) { + if (pplayer->is_alive && pplayer->is_connected) { + if (pplayer->turn_done) { + is_waiting++; + } else { + is_moving++; + } + } + } + players_iterate_end; + + if (is_moving == 1 && is_waiting > 0) { + update_turn_done_button(0); /* stress the slow player! */ + } + } + + blink_active_unit(); + + if (flip) { + update_timeout_label(); + if (seconds_to_turndone > 0) { + seconds_to_turndone--; + } else { + seconds_to_turndone = 0; + } + } + + flip = !flip; + } +} Index: client/civclient.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/civclient.h,v retrieving revision 1.18 diff -u -r1.18 civclient.h --- client/civclient.h 2002/06/23 16:06:22 1.18 +++ client/civclient.h 2002/07/16 14:23:34 @@ -16,6 +16,8 @@ #include "packets.h" /* enum report_type */ #include "game.h" /* enum client_states */ +#define TIMER_INTERVAL 500 /* milliseconds */ + void handle_packet_input(void *packet, int type); void send_unit_info(struct unit *punit); @@ -44,5 +46,6 @@ void wait_till_request_got_processed(int request_id); bool client_is_observer(void); +void real_timer_callback(void); #endif /* FC__CIVCLIENT_H */ Index: client/gui-gtk/gui_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v retrieving revision 1.111 diff -u -r1.111 gui_main.c --- client/gui-gtk/gui_main.c 2002/07/10 14:13:36 1.111 +++ client/gui-gtk/gui_main.c 2002/07/16 14:23:35 @@ -66,8 +66,6 @@ #include "freeciv.ico" -#define TIMER_INTERVAL 500 /* milliseconds */ - const char *client_string = "gui-gtk"; GtkWidget *map_canvas; /* GtkDrawingArea */ @@ -980,38 +978,7 @@ **************************************************************************/ static gint timer_callback(gpointer data) { - static int flip; - - if(get_client_state() == CLIENT_GAME_RUNNING_STATE) { - - if(game.player_ptr->is_connected && game.player_ptr->is_alive - && !game.player_ptr->turn_done) { - int i, is_waiting, is_moving; - - for(i = 0, is_waiting = 0, is_moving = 0; i < game.nplayers; i++) - if(game.players[i].is_alive && game.players[i].is_connected) { - if(game.players[i].turn_done) - is_waiting++; - else - is_moving++; - } - - if(is_moving == 1 && is_waiting) - update_turn_done_button(0); /* stress the slow player! */ - } - - blink_active_unit(); - - if(flip) { - update_timeout_label(); - if(seconds_to_turndone > 0) - seconds_to_turndone--; - else - seconds_to_turndone = 0; - } - - flip = !flip; - } + real_timer_callback(); return TRUE; } Index: client/gui-gtk-2.0/gui_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v retrieving revision 1.21 diff -u -r1.21 gui_main.c --- client/gui-gtk-2.0/gui_main.c 2002/07/10 14:13:37 1.21 +++ client/gui-gtk-2.0/gui_main.c 2002/07/16 14:23:35 @@ -65,8 +65,6 @@ #include "freeciv.ico" -#define TIMER_INTERVAL 500 /* milliseconds */ - const char *client_string = "gui-gtk-2.0"; GtkWidget *map_canvas; /* GtkDrawingArea */ @@ -1086,38 +1084,7 @@ **************************************************************************/ static gint timer_callback(gpointer data) { - static int flip; - - if(get_client_state() == CLIENT_GAME_RUNNING_STATE) { - - if(game.player_ptr->is_connected && game.player_ptr->is_alive - && !game.player_ptr->turn_done) { - int i, is_waiting, is_moving; - - for(i = 0, is_waiting = 0, is_moving = 0; i < game.nplayers; i++) - if(game.players[i].is_alive && game.players[i].is_connected) { - if(game.players[i].turn_done) - is_waiting++; - else - is_moving++; - } - - if(is_moving == 1 && is_waiting) - update_turn_done_button(0); /* stress the slow player! */ - } - - blink_active_unit(); - - if(flip) { - update_timeout_label(); - if(seconds_to_turndone > 0) - seconds_to_turndone--; - else - seconds_to_turndone = 0; - } - - flip = !flip; - } + real_timer_callback(); return TRUE; } Index: client/gui-mui/gui_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/gui_main.c,v retrieving revision 1.63 diff -u -r1.63 gui_main.c --- client/gui-mui/gui_main.c 2002/07/05 10:37:42 1.63 +++ client/gui-mui/gui_main.c 2002/07/16 14:23:36 @@ -122,49 +122,13 @@ } /************************************************************************** - This function should be called every 500ms - it lets the unit blink and update the timeout - belongs maybe to civclient.c + ... **************************************************************************/ static void handle_timer(void) { - static int flip; - - if (get_client_state() == CLIENT_GAME_RUNNING_STATE) - { - - if (game.player_ptr->is_connected && game.player_ptr->is_alive && - !game.player_ptr->turn_done) - { - int i, is_waiting, is_moving; - - for (i = 0, is_waiting = 0, is_moving = 0; i < game.nplayers; i++) - if (game.players[i].is_alive && game.players[i].is_connected) - { - if (game.players[i].turn_done) - is_waiting++; - else - is_moving++; - } - - if (is_moving == 1 && is_waiting) - update_turn_done_button(0); /* stress the slow player! */ - } - - blink_active_unit(); - - if (flip) - { - update_timeout_label(); - if (seconds_to_turndone) - seconds_to_turndone--; - } - - flip = !flip; - } + real_timer_callback(); } - static BOOL connected; /* TRUE, if connected to the server */ static int connected_sock; @@ -1141,7 +1105,7 @@ timer_outstanding--; } - if (!timer_outstanding) send_timer(0, 500000); + if (!timer_outstanding) send_timer(0, TIMER_INTERVAL * 1000); CurrentTime(&secs, &mics); handle_timer(); @@ -1463,7 +1427,7 @@ if (xget(main_wnd, MUIA_Window_Open)) { set_client_state(CLIENT_PRE_GAME_STATE); - send_timer(0, 500000); + send_timer(0, TIMER_INTERVAL * 1000); loop(); } else Index: client/gui-win32/gui_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/gui_main.c,v retrieving revision 1.14 diff -u -r1.14 gui_main.c --- client/gui-win32/gui_main.c 2002/07/13 13:33:06 1.14 +++ client/gui-win32/gui_main.c 2002/07/16 14:23:37 @@ -455,41 +455,15 @@ /************************************************************************** **************************************************************************/ -static VOID CALLBACK blink_timer(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime) +static VOID CALLBACK blink_timer(HWND hwnd, UINT uMsg, UINT idEvent, + DWORD dwTime) { - static int flip; - - if(get_client_state()==CLIENT_GAME_RUNNING_STATE) { - - if(game.player_ptr->is_connected && game.player_ptr->is_alive && - !game.player_ptr->turn_done) { - int i, is_waiting, is_moving; - - for(i=0, is_waiting=0, is_moving=0; i 0) - seconds_to_turndone--; - else - seconds_to_turndone = 0; - } - - flip=!flip; } -} + + real_timer_callback(); +} /************************************************************************** @@ -591,7 +565,7 @@ set_client_state(CLIENT_PRE_GAME_STATE); SetTimer(root_window,1,100,socket_timer); - SetTimer(root_window,2,500,blink_timer); + SetTimer(root_window, 2, TIMER_INTERVAL, blink_timer); while (GetMessage(&msg,NULL,0,0)) { if (!((msg.hwnd==root_window)&&(TranslateAccelerator(root_window, Index: client/gui-xaw/gui_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.c,v retrieving revision 1.67 diff -u -r1.67 gui_main.c --- client/gui-xaw/gui_main.c 2002/07/10 14:13:37 1.67 +++ client/gui-xaw/gui_main.c 2002/07/16 14:23:38 @@ -431,7 +431,7 @@ XtRealizeWidget(toplevel); - x_interval_id=XtAppAddTimeOut(app_context, 500, + x_interval_id=XtAppAddTimeOut(app_context, TIMER_INTERVAL, (XtTimerCallbackProc)timer_callback, NULL); map_canvas_resize(); @@ -817,43 +817,12 @@ /************************************************************************** ... **************************************************************************/ -void timer_callback(XtPointer client_data, XtIntervalId *id) +void timer_callback(XtPointer client_data, XtIntervalId * id) { - static int flip; - - x_interval_id=XtAppAddTimeOut(app_context, 500, - (XtTimerCallbackProc)timer_callback, NULL); - - if(get_client_state()==CLIENT_GAME_RUNNING_STATE) { - - if(game.player_ptr->is_connected && game.player_ptr->is_alive && - !game.player_ptr->turn_done) { - int i, is_waiting, is_moving; - - for(i=0, is_waiting=0, is_moving=0; i 0) - seconds_to_turndone--; - else - seconds_to_turndone = 0; - } - - flip=!flip; - } + x_interval_id = XtAppAddTimeOut(app_context, TIMER_INTERVAL, + (XtTimerCallbackProc) timer_callback, + NULL); + real_timer_callback(); } /**************************************************************************