Skip to content

Commit 872810e

Browse files
committed
improve rogomatic game log use, set good game level, set screen delay
Renamed the game log file "roguelog" to "gamelog". Moved `ROGUELOG` define from out of `install.h`, and into `types.h` and renamed it `GAMELOG_FILENAME`. Added `gamelog_path[]` to `config.c` to hold the game log path. Changed `set_rgmdir()` in `config.c` to also set `gamelog_path`. Changed uses of `ROGUELOG` define into using `gamelog_path`. Changed meaning of the `-e` command line Improved `set_rgmdir()` in `config.c` to use the `form_prefix_path()` function where applicable. When renaming the gamelog file at the end, save it under the rogomatic directory. Improved `rogue_log_open()` in `getroguetoken.c` to avoid reopening the rogue log twice. Improved `rogue_log_close()` in `getroguetoken.c` to avoid using a NULL `fecho`. Improved `rogue_log_write_command()` in `getroguetoken.c` to avoid using a NULL `fecho`. Improved `rogue_log_write_token()` in `getroguetoken.c` to avoid using a NULL `fecho`. Removed `GOODGAME` from `install.h`. Added `${GOODGAME}` make variable to `Makefile`. Set (kept initial value) the default `${GOODGAME}` in `Makefile` to 18. Added `goodgame` variable to `config.c`. Added `-G goodlvl` to command line to change the good game level value. Added `-G goodlvl` to `run_rogo.sh` to support change the good game level value. Improved the format of the usage message for `run_rogo.sh`. Changed `VERSION` in `run_rogo.sh` to "1.3.1 2026-07-11" Added `-G goodlvl` to `rerun_rogo.sh` to support change the good game level value. Improved `rerun_rogo.sh` to search for executables `run_rogo`, `rogomatic`, `player`, and `rogue` on each run cycles. Added `-Z` to prevent `rerun_rogo.sh` search for executables anywhere other than the `$PATH`. Improved the format of the usage message for `rerun_rogo.sh`. Added detection of SIGHUP of `run_rogo` to `rerun_rogo.sh`. Changed `VERSION` in `rerun_rogo.sh` to "1.2.1 2026-07-11" Don't **NOT** slow down in `sendcnow()` in `io.c` even more when reaching dungeon levels lower than 12, instead keep the same microsecond sleep schedule while in the dungeon. Removed `USLEEP` from `types.h`. Added `${USLEEP}` make variable to `Makefile`. Set (kept initial value) the default `${USLEEP}` in `Makefile` to 14000. Added `usleep_usec` variable to `config.c`. Added `-U usec` to command line to change the microsecond sleep value. A `-U 0` will disable the microsecond sleep. Pause 2.5 seconds in `main()` in `main.c` when a termination message is displayed. I.e., pause 2.5 seconds on rogue death. Removed to `NEWROGUE` from `install.h`. Removed code in `setup.c` code that used `NEWROGUE`. Removed `ROGUE` from `install.h`: only '${ROGUE} in `Makefile` is needed. Simplify compile lines by only defining `ROGUE` in for `setup.o`. Removed to `LOCKFILE` from `install.h`. Improved how `unstuck_player.sh` finds the rogue process, and finds the player process to SIGHUP if the player process appears to be stuck. Improved `unstuck_player.sh` to no longer use `killall(1)`, but rather the args gathered by a `ps(1)` command. By default, `unstuck_player.sh` will ignore processes using `/var/tmp/rogomatic`. Added `-A` to allow `unstuck_player.sh` to unstuck processes using `/var/tmp/rogomatic`. Changed `unstuck_player.sh` to wait 0.5 seconds between delivering a SIGHUP to a rogue process before trying to deliver a SIGHUP to the player process. Added `-z loop_sec` to set the length of time to detect a CPU bound player loop. By default, `loop_sec` is 256 seconds based on a 28 hour `rerun-rogo` run where the longest level was slightly less than 50.5 seconds. Improved `levellog_append()` in `debuglog.c` to avoid writing successive log entries into `lvllog` for the same dungeon level. The exception is when the player is exiting because rogue exited. Improved `unstuck_player.sh` to detect a CPU bound player loop when the `lvllog` file has not been updated for 32 seconds. Changed `VERSION` in `unstuck_player.sh` to "1.1.0 2026-07-12" Simplified most object file builds by removing unneeded defines in the compile line. Change `-a secs` recommendation in `rogomatic(6)` and `README.md` to 4.5 seconds. Updated `rogomatic(6)` man page according to the above. Changed `VERSION` in `setup.c` to "14.2.8 2026-07-13"
1 parent 51dca22 commit 872810e

7 files changed

Lines changed: 816 additions & 176 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ An easy way to "gently kill" a running rogomatic session is to run:
2222
To have rogomatic continuously start another rogue game after the explorer dies:
2323

2424
```sh
25-
./rerun_rogo -U 0 -a 2.5
25+
./rerun_rogo -U 0 -a 4.5
2626
```
2727

2828
It is recommended that while `./rerun_rogo` is running, in another window run:

debuglog.c

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ append_pidlog (const char *dir, const char *file)
247247
void
248248
levellog_create (void)
249249
{
250-
int levellog_fd; /* level log open file descriptor, or <0 ==> not open */
250+
int levellog_fd; /* level log open file descriptor, or <0 ==> not open */
251251

252252
/*
253253
* be sure that the pid log exists, writable at the beginning of file, and mode 0644 under umask
@@ -280,9 +280,11 @@ levellog_create (void)
280280
void
281281
levellog_append (char *reason)
282282
{
283-
struct timeval tp; /* now */
284-
struct tm *now; /* now broken out into segments */
285-
char timebuf[MU_BUF + 1]; /* now as a string */
283+
struct timeval tp; /* now */
284+
struct tm *now; /* now broken out into segments */
285+
char timebuf[MU_BUF + 1]; /* now as a string */
286+
static int prev_lvl_no_reason = -1; /* if >= 0, previously logged level in lvllog, "with no reason" */
287+
static int prev_lvl_a_reason = -1; /* if >= 0, previously logged level in lvllog, "with a reason" */
286288

287289
/*
288290
* firewall - level_log_stream must be open
@@ -314,20 +316,82 @@ levellog_append (char *reason)
314316
exit (1);
315317
}
316318

319+
/*
320+
* prevent too many successive logs for the same dungeon level
321+
*
322+
* If this function is called more than once for the same dungeon level,
323+
* we skip logging the same level. The unstuck_player script watches the lvllog file
324+
* in an effort to try and detect a CPU bound loop. In rare(?) cases, a CPU loop
325+
* might cause this function to be called multiple times for the same dungeon level.
326+
* So we prevent writing to the level log in succession for the same dungeon level.
327+
*
328+
* However .. there is an allowed case for a successive logs for the same dungeon level:
329+
* normally when exiting, the reason goes from NULL or an empty string ("with no reason")
330+
* to having a reason string ("with a reason").
331+
*
332+
* Therefore:
333+
*
334+
* we prevent logging successive logs for the same dungeon level "with no reason",
335+
* AND
336+
* we prevent logging successive logs for the same dungeon level "with a reason".
337+
*/
338+
if (reason == NULL || reason[0] == '\0') {
339+
if (prev_lvl_no_reason < 0) {
340+
341+
/* first call to this function "with no reason" */
342+
prev_lvl_no_reason = Level;
343+
344+
} else if (prev_lvl_no_reason == Level) {
345+
346+
/* don't log a successive call with same level "with no reason" */
347+
return;
348+
349+
}
350+
} else {
351+
if (prev_lvl_a_reason < 0) {
352+
353+
/* first call to this function "with a reason" */
354+
prev_lvl_a_reason = Level;
355+
356+
} else if (prev_lvl_a_reason == Level) {
357+
358+
/* don't log a successive call with same level "with a reason" */
359+
return;
360+
361+
}
362+
}
363+
317364
/*
318365
* append line to level log
319366
*/
320367
if (reason == NULL || reason[0] == '\0') {
368+
/* level log "with no reason" */
321369
fprintf (level_log_stream, "%ld.%06ld %s Level: %d Gold: %d Hp: %d(%d) Str: %d(%d) Ac: %d Exp: %d/%d Am: %c ...\n",
322370
(long) tp.tv_sec, (long) tp.tv_usec, timebuf,
323371
Level, Gold, Hp, Hpmax, Str/100, Strmax/100, Ac, Explev, Exp,
324372
((have (amulet) != NONE) ? ',' : '-'));
325373
} else {
374+
/* level log "with a reason" */
326375
fprintf (level_log_stream, "%ld.%06ld %s Level: %d Gold: %d Hp: %d(%d) Str: %d(%d) Ac: %d Exp: %d/%d Am: %c %s\n",
327376
(long) tp.tv_sec, (long) tp.tv_usec, timebuf,
328377
Level, Gold, Hp, Hpmax, Str/100, Strmax/100, Ac, Explev, Exp,
329378
((have (amulet) != NONE) ? ',' : '-'), reason);
330379
}
331380
fflush(level_log_stream);
381+
382+
/*
383+
* prep for the next log level call
384+
*/
385+
if (reason == NULL || reason[0] == '\0') {
386+
387+
/* remember this level, "with no reason", for the next call */
388+
prev_lvl_no_reason = Level;
389+
390+
} else {
391+
392+
/* remember this level, "with a reason", for the next call */
393+
prev_lvl_a_reason = Level;
394+
395+
}
332396
return;
333397
}

0 commit comments

Comments
 (0)