Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Add the filepath of the ttyrec if it exists to the xlogfile. #319

Merged
merged 2 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/nleobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ typedef struct nle_settings {
* https://nethackwiki.com/wiki/Monster_creation#Random_generation
*/
int spawn_monsters;
/*
* Filename for nle's ttyrec*.bz2.
*/
char ttyrecname[4096];
} nle_settings;

#endif /* NLEOBS_H */
6 changes: 6 additions & 0 deletions src/nle.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ nle_done(int how)
nle->observation->how_done = how;
}

char *
nle_ttyrecname()
{
return settings.ttyrecname;
}

int
nle_spawn_monsters()
{
Expand Down
7 changes: 7 additions & 0 deletions src/topten.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ static long final_fpos;
#define DTHSZ 100
#define ROLESZ 3

#define NLE_XLOG_INCLUDE_FILE
extern char * FDECL(nle_ttyrecname, ());

struct toptenentry {
struct toptenentry *tt_next;
#ifdef UPDATE_RECORD_IN_PLACE
Expand Down Expand Up @@ -376,6 +379,10 @@ int how;
genders[flags.initgend].filecode, XLOG_SEP,
aligns[1 - u.ualignbase[A_ORIGINAL]].filecode);
Fprintf(rfile, "%cflags=0x%lx", XLOG_SEP, encodexlogflags());
#ifdef NLE_XLOG_INCLUDE_FILE
if (nle_ttyrecname()[0] != '\0')
Fprintf(rfile, "%cttyrecname=%s", XLOG_SEP, nle_ttyrecname());
#endif
Fprintf(rfile, "\n");
#undef XLOG_SEP
}
Expand Down
13 changes: 13 additions & 0 deletions win/rl/pynethack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class Nethack
}
strncpy(settings_.scoreprefix, scoreprefix.c_str(),
scoreprefix.length());
std::size_t found = ttyrec.rfind("/");
if (found != std::string::npos && found + 1 < ttyrec.length())
strncpy(settings_.ttyrecname, &ttyrec.c_str()[found + 1],
ttyrec.length() - found - 1);
}

Nethack(std::string dlpath, std::string hackdir,
Expand Down Expand Up @@ -181,6 +185,12 @@ class Nethack
PyErr_SetFromErrnoWithFilename(PyExc_OSError, ttyrec.c_str());
throw py::error_already_set();
}

std::size_t found = ttyrec.rfind("/");
if (found != std::string::npos && (found + 1) < ttyrec.length())
strncpy(settings_.ttyrecname, &ttyrec.c_str()[found + 1],
ttyrec.length() - found - 1);

// Reset environment, then close original FILE. Cannot use freopen
// as the game may still need to write to the original file but
// reset() wants to get the new one already.
Expand Down Expand Up @@ -331,6 +341,9 @@ class Nethack
{
py::gil_scoped_release gil;

if (!ttyrec)
strncpy(settings_.ttyrecname, "", sizeof(settings_.ttyrecname));

if (!nle_) {
nle_ =
nle_start(dlpath_.c_str(), &obs_, ttyrec ? ttyrec : ttyrec_,
Expand Down