NetHack minor release checklist items - savefiles

Make some progress on a couple of next minor release checklist
items, hopefully without introducing too many new bugs. This
is just the initial commit, and work continues.

Checklist items:

Savefiles compatible between Windows versions, whether 64-bit
or 32-bit in little-endian field format.

Selection of file formats:
 historical (structlevel saves),
 lendian (little-endian, fieldlevel saves),
 and just for proof-of-concept, ascii fieldlevel saves
 (the ascii is huge! 10x bigger than little-endian).

For the fieldlevel save, all complex data structures recursively
get broken down until until it is one of the simple types that
can't be broken down any further, and that gets when it gets
written to the output file.

New files needed for this build:

hand-coded:
include/sfprocs.h
src/sfbase.c      - really a dispatcher to one of the
                    output/input format routines.
src/sflendian.c   - little-endian output writer/reader.
src/sfascii.c     - ascii text output writer/reader.

auto-coded (generated):
include/sfproto.h
src/sfdata.c

This is just one approach. I'm sure there are countless others
and they have different pros and cons.

For producing the auto-coded files a utility called
universal-ctags, that is actively maintained and evolving,
was used to do all the heavy-lifting of parsing the
NetHack C sources to tabulate the data fields, and store
them in an intermediate file called util/nethack.tags
(not required for building NetHack if you already have a
generated include/sfproto.h and src/sfdata.c)

util/readtags (also not required for building NetHack
itself) will decipher the nethack.tags file and produce
the functions that can deal with the NetHack struct data
fields.

You can obtain the source for universal-ctags by cloning it
from here:
https://github.com/universal-ctags/ctags.git

The combination universal-ctags + util/readtags has been
tried and tested under both Windows and Linux, so it is
not tied to a particular platform.

Note: util/readtags will work only with universal-ctags
output, so other ctags are unlikely to work as-is.
Universal-ctags can be build from source very easily
under Linux, or under Windows using visual studio.
This commit is contained in:
nhmall
2019-06-23 00:11:46 -04:00
parent c9e8ae6323
commit 7054e06e42
45 changed files with 14114 additions and 1280 deletions

View File

@@ -4,6 +4,8 @@
#include "hack.h"
#include "lev.h" /* for checking save modes */
#include "sfproto.h"
/*
* Mobile light sources.
@@ -42,25 +44,27 @@
#define LSF_SHOW 0x1 /* display the light source */
#define LSF_NEEDS_FIXUP 0x2 /* need oid fixup */
STATIC_DCL void FDECL(write_ls, (int, light_source *));
STATIC_DCL int FDECL(maybe_write_ls, (int, int, BOOLEAN_P));
/* SAVE2018 */
STATIC_DCL void FDECL(write_ls, (NHFILE *, light_source *));
STATIC_DCL int FDECL(maybe_write_ls, (NHFILE *, int, BOOLEAN_P));
/* imported from vision.c, for small circles */
extern char circle_data[];
extern char circle_start[];
/* Create a new light source. */
void
new_light_source(x, y, range, type, id)
xchar x, y;
int range, type;
anything *id;
xchar x, y;
int range, type;
anything *id;
{
light_source *ls;
if (range > MAX_RADIUS || range < 1) {
impossible("new_light_source: illegal range %d", range);
return;
impossible("new_light_source: illegal range %d", range);
return;
}
ls = (light_source *) alloc(sizeof *ls);
@@ -311,22 +315,28 @@ unsigned fmflags;
/* Save all light sources of the given range. */
void
save_light_sources(fd, mode, range)
int fd, mode, range;
save_light_sources(nhfp, range)
NHFILE *nhfp;
int range;
{
int count, actual, is_global;
light_source **prev, *curr;
if (perform_bwrite(mode)) {
count = maybe_write_ls(fd, range, FALSE);
bwrite(fd, (genericptr_t) &count, sizeof count);
actual = maybe_write_ls(fd, range, TRUE);
if (perform_bwrite(nhfp)) {
count = maybe_write_ls(nhfp, range, FALSE);
if (nhfp->structlevel) {
bwrite(nhfp->fd, (genericptr_t) &count, sizeof count);
}
if (nhfp->fieldlevel) {
sfo_int(nhfp, &count, "lightsources", "lightsource_count", 1);
}
actual = maybe_write_ls(nhfp, range, TRUE);
if (actual != count)
panic("counted %d light sources, wrote %d! [range=%d]", count,
actual, range);
}
if (release_data(mode)) {
if (release_data(nhfp)) {
for (prev = &g.light_base; (curr = *prev) != 0;) {
if (!curr->id.a_monst) {
impossible("save_light_sources: no id! [range=%d]", range);
@@ -361,18 +371,24 @@ int fd, mode, range;
* pointers.
*/
void
restore_light_sources(fd)
int fd;
restore_light_sources(nhfp)
NHFILE *nhfp;
{
int count;
light_source *ls;
/* restore elements */
mread(fd, (genericptr_t) &count, sizeof count);
if (nhfp->structlevel)
mread(nhfp->fd, (genericptr_t) &count, sizeof count);
if (nhfp->fieldlevel)
sfi_int(nhfp, &count, "lightsources", "lightsource_count", 1);
while (count-- > 0) {
ls = (light_source *) alloc(sizeof(light_source));
mread(fd, (genericptr_t) ls, sizeof(light_source));
if (nhfp->structlevel)
mread(nhfp->fd, (genericptr_t) ls, sizeof(light_source));
if (nhfp->fieldlevel)
sfi_ls_t(nhfp, ls, "lightsources", "lightsource", 1);
ls->next = g.light_base;
g.light_base = ls;
}
@@ -430,14 +446,17 @@ boolean ghostly;
}
}
/* SAVE2018 */
/*
* Part of the light source save routine. Count up the number of light
* sources that would be written. If write_it is true, actually write
* the light source out.
*/
STATIC_OVL int
maybe_write_ls(fd, range, write_it)
int fd, range;
maybe_write_ls(nhfp, range, write_it)
NHFILE *nhfp;
int range;
boolean write_it;
{
int count = 0, is_global;
@@ -465,7 +484,7 @@ boolean write_it;
if (is_global ^ (range == RANGE_LEVEL)) {
count++;
if (write_it)
write_ls(fd, ls);
write_ls(nhfp, ls);
}
}
@@ -499,11 +518,19 @@ light_sources_sanity_check()
}
}
/* Write a light source structure to disk. */
/* SAVE2018 */
#if 0
STATIC_OVL void
write_ls(fd, ls)
int fd;
light_source *ls;
#endif /* 0 */
/* Write a light source structure to disk. */
STATIC_OVL void
write_ls(nhfp, ls)
NHFILE *nhfp;
light_source *ls;
{
anything arg_save;
struct obj *otmp;
@@ -511,7 +538,10 @@ light_source *ls;
if (ls->type == LS_OBJECT || ls->type == LS_MONSTER) {
if (ls->flags & LSF_NEEDS_FIXUP) {
bwrite(fd, (genericptr_t) ls, sizeof(light_source));
if (nhfp->structlevel)
bwrite(nhfp->fd, (genericptr_t) ls, sizeof(light_source));
if (nhfp->fieldlevel)
sfo_ls_t(nhfp, ls, "lightsources", "lightsource", 1);
} else {
/* replace object pointer with id for write, then put back */
arg_save = ls->id;
@@ -531,7 +561,10 @@ light_source *ls;
ls->id.a_uint);
}
ls->flags |= LSF_NEEDS_FIXUP;
bwrite(fd, (genericptr_t) ls, sizeof(light_source));
if (nhfp->structlevel)
bwrite(nhfp->fd, (genericptr_t) ls, sizeof(light_source));
if (nhfp->fieldlevel)
sfo_ls_t(nhfp, ls, "lightsources", "lightsource", 1);
ls->id = arg_save;
ls->flags &= ~LSF_NEEDS_FIXUP;
}