Test Results of Transient Preinit Data After Restoring Save

I HAVE MADE A DISCOVERY!

So, I have finally tested this:

and also answered this manic question I had a long time ago:

What Happened?

I noticed that my game’s save files were 7 MB in size!! :scream:

What?! Ew!!! No! :angry:

I had suspected that the preinit cached data were being dumped into the game save file, which is completely unnecessary, because again: They never change, and come packaged with the game file.

The Experiment

So, I have some data that get precached during preinit. These data will never get modified during the course of the game. It’s only ever used in references.

Here’s an excerpt of code:

// Object for storing test data for this experiment
routeStorageTestBed: object {
    storedRouteTable = nil
    storedRouteRef = nil

    checkStatus() {
        "Table: <<(storedRouteTable == nil)
            ? 'nil' : 'stored'>>\n
        Route: <<(storedRouteRef == nil)
            ? 'nil' : 'stored'>>";
    }
}

// Experimental action for storing references to these data
VerbRule(TestStoreRouteRef)
    'store' 'route' 'ref'
    : VerbProduction
    action = TestStoreRouteRef
    verbPhrase = 'store/storing route ref'
;

DefineSystemAction(TestStoreRouteRef)
    includeInUndo = true
    execAction(cmd) {
        // All this does is store a route table and route from the table
        local mapModeRoom = gPlayerChar.getOutermostRoom().mapModeVersion;
        routeStorageTestBed.storedRouteTable = mapModeRoom.playerRouteTable;
        // Get the next route to the hangar
        routeStorageTestBed.storedRouteRef =
            mapModeRoom.playerRouteTable.findBestDirectionTo(
                hangar.mapModeVersion
            );
        // Visually confirm we've stored something
        routeStorageTestBed.checkStatus();
    }
;

// Experimental action for checking references to these data
VerbRule(TestCheckRouteRef)
    'check' 'route' 'ref'
    : VerbProduction
    action = TestCheckRouteRef
    verbPhrase = 'check/checking route ref'
;

DefineSystemAction(TestCheckRouteRef)
    includeInUndo = true
    execAction(cmd) {
        // Again, confirm we've stored something
        routeStorageTestBed.checkStatus();
    }
;

class MapModeRoom: Room {
    construct(_actual) {
        ...
        // This will get populated during preinit
        // This used to be non-transient before this experiment
        playerRouteTable = new transient RouteTable(self, nil);
        ...
    }
    ...
}

So! I start a new game, fire off the TestStoreRouteRef, and confirm that references to the transient preinit data have been stored.

Then, I save the game, close QTADS, start a new game, restore my save, and then fire off TestCheckRouteRef.

And there they are! The references are still there!
Also: The save file is now just over 200 kB!

Am I seeing things??
Is this something that only works in QTADS?
Have I made an original discovery?
Is this useful to anyone?
Am I doing something dangerous?

I can also confirm that I am NOT using a debug version of the game. I am using a release version, which is saves preinit data with the game file.

What Happens In A Debug Version?

When I run this same test in a debug build, the references fail to load, probably because the preinit data are calculated during runtime for a debug build, and are not saved in the game file.

Therefore, you will need to use preprocessor code to make sure these data are declared as NON-TRANSIENT during debug builds, if you want this is to work.

2 Likes

If anyone is interested, I could probably make a small test game file for others to verify this discovery with.

1 Like

It should work everywhere.

2 Likes

Interesting stuff. I haven’t had the need for that kind of complex pre caching yet…

1 Like

Awesome! I come from the Doom modding scene, and sometimes different interpreters over there have varied implementations that surprise people. I was tentatively assuming that interpreters in the IF scene were a lot more standardized, but just wanted to confirm. Thanks! :grin:

Yee, I’m mostly just neurotic about not leaving megabytes of redundant data on a save file if I can help it, lol. A drop in the ocean for modern computers, but some of my friends are a bit stressed on storage space for various reasons, so it’s still something I think about.

1 Like

I wouldn’t want 7 meg save files either… mine are already 2-3 meg!

1 Like