[Freeciv-Dev] (PR#12418) better tracking of timeout
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12418 >
Currently the timeout calculations are only accurate to 1 second. With
a large timeout this is no big deal but with a timeout of 8 (for
instance) one turn may be 7.1 seconds long while another is 8.9.
This patch fixes that, with basically no added complexity. In place of
the time_t value game.phase_start there is a struct timer
game.phase_timer. Thus the calculations are as accurate as the timing
code allows (at least 1/100 second).
Client code is basically unaffected since it was already prepared to
deal with non-integer timeouts. There is one small fix in packhand.c
however.
-jason
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.473
diff -u -r1.473 packhand.c
--- client/packhand.c 23 Feb 2005 03:34:05 -0000 1.473
+++ client/packhand.c 3 Mar 2005 01:57:26 -0000
@@ -1379,7 +1379,7 @@
boot_help = (can_client_change_view()
&& game.spacerace != pinfo->spacerace);
game.spacerace=pinfo->spacerace;
- if (game.timeout != 0 && pinfo->seconds_to_phasedone != 0) {
+ if (game.timeout != 0 && pinfo->seconds_to_phasedone >= 0) {
set_seconds_to_turndone(pinfo->seconds_to_phasedone);
}
if (boot_help) {
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.173
diff -u -r1.173 game.h
--- common/game.h 23 Feb 2005 03:34:05 -0000 1.173
+++ common/game.h 3 Mar 2005 01:57:27 -0000
@@ -20,6 +20,7 @@
#endif
#include "shared.h"
+#include "timing.h"
#include "connection.h" /* struct conn_list */
#include "fc_types.h"
@@ -75,7 +76,7 @@
time_t last_ping;
int pingtimeout;
int pingtime;
- time_t phase_start;
+ struct timer *phase_timer;
int end_year;
int year;
int turn;
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.95
diff -u -r1.95 packets.def
--- common/packets.def 23 Feb 2005 03:34:05 -0000 1.95
+++ common/packets.def 3 Mar 2005 01:57:27 -0000
@@ -339,7 +339,7 @@
UINT8 researchcost;
UINT32 skill_level;
- UINT32 seconds_to_phasedone;
+ FLOAT seconds_to_phasedone;
UINT32 timeout;
TURN turn;
PHASE phase;
Index: server/gamehand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gamehand.c,v
retrieving revision 1.152
diff -u -r1.152 gamehand.c
--- server/gamehand.c 23 Feb 2005 03:34:06 -0000 1.152
+++ server/gamehand.c 3 Mar 2005 01:57:27 -0000
@@ -346,11 +346,11 @@
/* the following values are computed every
time a packet_game_info packet is created */
if (game.timeout != 0) {
- ginfo.seconds_to_phasedone =
- game.phase_start + game.timeout - time(NULL);
+ ginfo.seconds_to_phasedone
+ = (double)game.timeout - read_timer_seconds(game.phase_timer);
} else {
/* unused but at least initialized */
- ginfo.seconds_to_phasedone = -1;
+ ginfo.seconds_to_phasedone = -1.0;
}
conn_list_iterate(dest, pconn) {
Index: server/sernet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v
retrieving revision 1.134
diff -u -r1.134 sernet.c
--- server/sernet.c 23 Feb 2005 03:34:06 -0000 1.134
+++ server/sernet.c 3 Mar 2005 01:57:27 -0000
@@ -500,8 +500,8 @@
if(select(max_desc+1, &readfs, &writefs, &exceptfs, &tv)==0) { /* timeout
*/
(void) send_server_info_to_metaserver(META_REFRESH);
if (game.timeout != 0
- && time(NULL) > game.phase_start + game.timeout
- && server_state == RUN_GAME_STATE) {
+ && read_timer_seconds(game.phase_timer) > (double)game.timeout
+ && server_state == RUN_GAME_STATE) {
con_prompt_off();
return 0;
}
@@ -670,7 +670,8 @@
}
con_prompt_off();
- if (game.timeout != 0 && time(NULL) > game.phase_start + game.timeout) {
+ if (game.timeout != 0
+ && read_timer_seconds(game.phase_timer) > (double)game.timeout) {
return 0;
}
return 1;
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.230
diff -u -r1.230 srv_main.c
--- server/srv_main.c 25 Feb 2005 08:52:20 -0000 1.230
+++ server/srv_main.c 3 Mar 2005 01:57:28 -0000
@@ -566,7 +566,8 @@
sanity_check();
- game.phase_start = time(NULL);
+ game.phase_timer = renew_timer_start(game.phase_timer,
+ TIMER_USER, TIMER_ACTIVE);
send_game_info(NULL);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12418) better tracking of timeout,
Jason Short <=
|
|