From: PatR Date: Wed, 16 Dec 2015 01:59:42 +0000 (-0800) Subject: fix bz157, #H4075 - 'realtime' had strange units X-Git-Tag: NetHack-3.6.1_RC01~1173 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f96d4b9efd7d536a84590d674f08eb5747a1bd1;p=nethack fix bz157, #H4075 - 'realtime' had strange units A couple of reports asked what weird unit of measure was used for the 'realtime' value in xlogfile. It was just seconds, but was accumulating incorrectly whenever game-state got saved for the checkpoint option. Now it really is seconds, or rather whatever unit you get for the delta of two time_t values; usually seconds but not guaranteed to be that. --- diff --git a/doc/fixes36.1 b/doc/fixes36.1 index f4088b147..8b475665a 100644 --- a/doc/fixes36.1 +++ b/doc/fixes36.1 @@ -31,6 +31,7 @@ fix typo in passage 1 of The Colour of Magic falling asleep when reading dull spellbook ignored sleep resistance getpos() complaint about invalid movement keystroke didn't describe meta-chars accurately +'realtime' value in xlogfile was incorrect if 'checkpoint' option was active Platform- and/or Interface-Specific Fixes diff --git a/include/you.h b/include/you.h index ef45eef46..78a3a1334 100644 --- a/include/you.h +++ b/include/you.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 you.h $NHDT-Date: 1432512782 2015/05/25 00:13:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.29 $ */ +/* NetHack 3.6 you.h $NHDT-Date: 1450231172 2015/12/16 01:59:32 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.30 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -68,10 +68,11 @@ struct u_achieve { }; struct u_realtime { - long - realtime; /* actual playing time up until the last restore, seconds */ - time_t restored; /* time the game was started or restored */ - time_t endtime; + long realtime; /* accumulated playing time in seconds */ + time_t start_timing; /* time game was started or restored or 'realtime' + was last updated (savegamestate for checkpoint) */ + time_t finish_time; /* end of 'realtime' interval: time of save or + end of game; used for topten/logfile/xlogfile */ }; /* KMH, conduct -- diff --git a/src/allmain.c b/src/allmain.c index 962df4c68..02fa6480f 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 allmain.c $NHDT-Date: 1446975459 2015/11/08 09:37:39 $ $NHDT-Branch: master $:$NHDT-Revision: 1.66 $ */ +/* NetHack 3.6 allmain.c $NHDT-Date: 1450231173 2015/12/16 01:59:33 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.67 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -587,18 +587,13 @@ newgame() com_pager(1); } + urealtime.realtime = 0L; + urealtime.start_timing = getnow(); #ifdef INSURANCE save_currentstate(); #endif program_state.something_worth_saving++; /* useful data now exists */ - urealtime.realtime = 0L; -#if defined(BSD) && !defined(POSIX_TYPES) - (void) time((long *) &urealtime.restored); -#else - (void) time(&urealtime.restored); -#endif - /* Success! */ welcome(TRUE); return; diff --git a/src/end.c b/src/end.c index e245e30e4..20ca00d09 100644 --- a/src/end.c +++ b/src/end.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 end.c $NHDT-Date: 1448241780 2015/11/23 01:23:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.108 $ */ +/* NetHack 3.6 end.c $NHDT-Date: 1450231174 2015/12/16 01:59:34 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.110 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -951,8 +951,8 @@ int how; /* remember time of death here instead of having bones, rip, and topten figure it out separately and possibly getting different time or even day if player is slow responding to --More-- */ - endtime = getnow(); - urealtime.realtime += (long) (endtime - urealtime.restored); + urealtime.finish_time = endtime = getnow(); + urealtime.realtime += (long) (endtime - urealtime.start_timing); /* Sometimes you die on the first move. Life's not fair. * On those rare occasions you get hosed immediately, go out diff --git a/src/restore.c b/src/restore.c index 99c5ad61f..d56af4ea6 100644 --- a/src/restore.c +++ b/src/restore.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 restore.c $NHDT-Date: 1446892455 2015/11/07 10:34:15 $ $NHDT-Branch: master $:$NHDT-Revision: 1.101 $ */ +/* NetHack 3.6 restore.c $NHDT-Date: 1450231174 2015/12/16 01:59:34 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.102 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -568,13 +568,10 @@ unsigned int *stuckid, *steedid; foo = time_from_yyyymmddhhmmss(timebuf); ReadTimebuf(ubirthday); - mread(fd, &urealtime.realtime, sizeof(urealtime.realtime)); - ReadTimebuf(urealtime.restored); -#if defined(BSD) && !defined(POSIX_TYPES) - (void) time((long *) &urealtime.restored); -#else - (void) time(&urealtime.restored); -#endif + mread(fd, &urealtime.realtime, sizeof urealtime.realtime); + ReadTimebuf(urealtime.start_timing); /** [not used] **/ + /* current time is the time to use for next urealtime.realtime update */ + urealtime.start_timing = getnow(); set_uasmon(); #ifdef CLIPPING diff --git a/src/save.c b/src/save.c index 2fc087209..f1e4ecf7b 100644 --- a/src/save.c +++ b/src/save.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 save.c $NHDT-Date: 1448241784 2015/11/23 01:23:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.95 $ */ +/* NetHack 3.6 save.c $NHDT-Date: 1450231175 2015/12/16 01:59:35 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.98 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -289,12 +289,15 @@ register int fd, mode; #ifdef SYSFLAGS bwrite(fd, (genericptr_t) &sysflags, sizeof(struct sysflag)); #endif - urealtime.realtime += (long) (getnow() - urealtime.restored); + urealtime.finish_time = getnow(); + urealtime.realtime += (long) (urealtime.finish_time + - urealtime.start_timing); bwrite(fd, (genericptr_t) &u, sizeof(struct you)); bwrite(fd, yyyymmddhhmmss(ubirthday), 14); - bwrite(fd, (genericptr_t) &urealtime.realtime, - sizeof(urealtime.realtime)); - bwrite(fd, yyyymmddhhmmss(urealtime.restored), 14); + bwrite(fd, (genericptr_t) &urealtime.realtime, sizeof urealtime.realtime); + bwrite(fd, yyyymmddhhmmss(urealtime.start_timing), 14); /** Why? **/ + /* this is the value to use for the next update of urealtime.realtime */ + urealtime.start_timing = urealtime.finish_time; save_killers(fd, mode); /* must come before migrating_objs and migrating_mons are freed */ diff --git a/src/topten.c b/src/topten.c index 7ea996da3..375eb1d23 100644 --- a/src/topten.c +++ b/src/topten.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 topten.c $NHDT-Date: 1448117546 2015/11/21 14:52:26 $ $NHDT-Branch: master $:$NHDT-Revision: 1.40 $ */ +/* NetHack 3.6 topten.c $NHDT-Date: 1450231176 2015/12/16 01:59:36 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.41 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -330,8 +330,8 @@ struct toptenentry *tt; Fprintf(rfile, "%cconduct=0x%lx%cturns=%ld%cachieve=0x%lx", XLOG_SEP, encodeconduct(), XLOG_SEP, moves, XLOG_SEP, encodeachieve()); Fprintf(rfile, "%crealtime=%ld%cstarttime=%ld%cendtime=%ld", XLOG_SEP, - (long) urealtime.realtime, XLOG_SEP, (long) ubirthday, XLOG_SEP, - (long) urealtime.endtime); + (long) urealtime.realtime, XLOG_SEP, + (long) ubirthday, XLOG_SEP, (long) urealtime.finish_time); Fprintf(rfile, "%cgender0=%s%calign0=%s", XLOG_SEP, genders[flags.initgend].filecode, XLOG_SEP, aligns[1 - u.ualignbase[A_ORIGINAL]].filecode); @@ -516,7 +516,6 @@ time_t when; t0->birthdate = yyyymmdd(ubirthday); t0->deathdate = yyyymmdd(when); t0->tt_next = 0; - urealtime.endtime = when; #ifdef UPDATE_RECORD_IN_PLACE t0->fpos = -1L; #endif