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.
This commit is contained in:
PatR
2015-12-15 17:59:42 -08:00
parent d17fcf3e13
commit 8f96d4b9ef
7 changed files with 29 additions and 33 deletions

View File

@@ -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

View File

@@ -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 --

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -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 */

View File

@@ -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