save/restore changes - part 3

This is the third of a series of savefile-related changes.

    This adds early-days experimental support for a completely optional
    'sfctool' utility (savefile conversion tool), to be able to export
    a savefile's contents into a more portable format. There are likely
    to be bugs at this stage. In this initial first-attempt, the export
    format is a very simple ascii output.

    NetHack can be built entirely, without also building this tool.
    NetHack has no dependencies on the tool.

    Attempts were made to minimize duplication of existing NetHack code.
    To achieve that, unfortunately, #ifdef SFCTOOL and #ifndef SFCTOOL
    had to be sprinkled around through some of the existing NetHack
    source code, so that it could be re-used for building the utility.

    The process for building the sfctool typically recompiles the source
    files with #define SFCTOOL and a distinct object file with SF- is
    produced.

sfctool notes:

    Universal ctags is used and required to produce the sfctool utility.

    Some targets were added to the Unix and Windows Makefiles to
    facilitate the build process.

         make sfctool

    That should build a copy in util.

    Note: At present, the Unix Makefiles do not copy sfctool over to the
          NetHack playground during 'make install' or 'make update'.
          Until that gets resolved by someone, The tool will
          have to be manually copied there by the builder/admin if
          desired.
          cp util/sfctool ~/nh/install/games/lib/nethackdir/sfctool

    Also, a separate Visual Studio sfctool.sln solution was written and
    placed in sys/windows/vs. That has has only very limited testing.

    Usage:

      i)  To convert an existing savefile to an exportascii format
          that co-resides with the savefile:

          sfctool -c savefile

          That *must* be executed on the same platform / architecture /
          data model that produced the save file in the first place.

     ii)  To unconvert an existing exportascii format export file to a
          historical format savefile that can then be used by NetHack:

          sfctool -u savefile

          That must be executed on the same target platform / architecture /
          data model that was used to build the NetHack that will
          utilize the save file that results.

     A Windows example:

          sfctool -c Fred.NetHack-saved-game

          That should result in creation of Fred.NetHack-saved-game.exportascii
          from existing savefile:
              %USERPROFILE%\AppData\Local\NetHack\3.7\Fred.NetHack-saved-game

     A Unix example:

          sfctool -c 1000wizard

          That should result in creation of 1000wizard.exportascii.gz
          from existing savefile in the playground save directory:
              1000wizard.gz

  Current Mechanics:
     1. Makefile recipe, or script uses universal ctags to produce
        util/sf.tags.

     2. util/sftags is built and executed to read util/sf.tags and
        generate: include/sfproto.h and src/sfdata.c.

     3. util/sfctool is built from the following:
        generated file compiled with -DSFCTOOL:
                    src/sfdata.c       -> sfdata.o
        existing files compiled with -DSFCTOOL:
                    util/sfctool.c     -> sfctool.o
                    util/sfexpasc.c    -> sfexpasc.o
                    src/alloc.c        -> sf-alloc.o
                    src/monst.c        -> sf-monst.o
                    src/objects.c      -> sf-objects.o
                    src/sfbase.c       -> sfbase.o
                    src/sfstruct.c     -> sfstruct.o
                    src/nhlua.c        -> sf-nhlua.o
                    util/panic.c       -> panic.o
                    src/date.c         -> sf-date.o
                    src/decl.c         -> sf-decl.o
                    src/artifact.c     -> sf-artifact.o
                    src/dungeon.c      -> sf-dungeon.o
                    src/end.c          -> sf-end.o
                    src/engrave.c      -> sf-engrave.o
                    src/cfgfiles.c     -> sf-cfgfiles.o
                    src/files.c        -> sf-files.o
                    src/light.c        -> sf-light.o
                    src/mdlib.c        -> sf-mdlib.o
                    src/mkmaze.c       -> sf-mkmaze.o
                    src/mkroom.c       -> sf-mkroom.o
                    src/o_init.c       -> sf-o_init.o
                    src/region.c       -> sf-region.o
                    src/restore.c      -> sf-restore.o
                    src/rumors.c       -> sf-rumors.o
                    src/sys.c          -> sf-sys.o
                    src/timeout.c      -> sf-timeout.o
                    src/track.c        -> sf-track.o
                    src/version.c      -> sf-version.o
                    src/worm.c         -> sf-worm.o
                    src/strutil.c      -> strutil.o
This commit is contained in:
nhmall
2025-05-25 20:38:17 -04:00
parent 82fd29c429
commit a654d08c3b
49 changed files with 7578 additions and 257 deletions

View File

@@ -13,6 +13,7 @@
#define NO_CALLBACK (-1)
void free_region(NhRegion *);
#ifndef SFCTOOL
boolean inside_gas_cloud(genericptr, genericptr);
boolean expire_gas_cloud(genericptr, genericptr);
boolean inside_rect(NhRect *, int, int);
@@ -253,6 +254,7 @@ clone_region(NhRegion *reg)
}
#endif /*0*/
#endif /* !SFCTOOL */
/*
* Free mem from region.
@@ -273,6 +275,7 @@ free_region(NhRegion *reg)
}
}
#ifndef SFCTOOL
/*
* Add a region to the list.
* This actually activates the region.
@@ -381,6 +384,7 @@ remove_region(NhRegion *reg)
}
free_region(reg);
}
#endif /* !SFCTOOL */
/*
* Remove all regions and clear all related data. This must be done
@@ -400,6 +404,7 @@ clear_regions(void)
gr.regions = (NhRegion **) 0;
}
#ifndef SFCTOOL
/*
* This function is called every turn.
* It makes the regions age, if necessary and calls the appropriate
@@ -788,6 +793,7 @@ save_regions(NHFILE *nhfp)
if (release_data(nhfp))
clear_regions();
}
#endif /* !SFCTOOL */
void
rest_regions(NHFILE *nhfp)
@@ -872,6 +878,7 @@ rest_regions(NHFILE *nhfp)
Sfi_int(nhfp, &r->glyph, "region-glyph");
Sfi_any(nhfp, &r->arg, "region-arg");
}
#ifndef SFCTOOL
/* remove expired regions, do not trigger the expire_f callback (yet!);
also update monster lists if this data is coming from a bones file */
for (i = svn.n_regions - 1; i >= 0; i--) {
@@ -881,8 +888,10 @@ rest_regions(NHFILE *nhfp)
else if (ghostly && r->n_monst > 0)
reset_region_mids(r);
}
#endif /* !SFCTOOL */
}
#ifndef SFCTOOL
DISABLE_WARNING_FORMAT_NONLITERAL
/* to support '#stats' wizard-mode command */
@@ -1394,5 +1403,6 @@ region_safety(void)
if (BlindedTimeout == 1L)
make_blinded(0L, TRUE);
}
#endif /* !SFCTOOL */
/*region.c*/