I HAVE MADE A DISCOVERY!
So, I have finally tested this:
and also answered this manic question I had a long time ago:
If I have a property in a
PreinitObject
—and this property is markedtransient
—then will it not be saved to cache after compile, and instead be represented with anil
value on game load?
What Happened?
I noticed that my game’s save files were 7 MB in size!!
What?! Ew!!! No!
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.