Save System Fixes

Hey Folks! A lot of save system work today, as I discovered a pretty big bug while testing character gen and crew hiring.

Basically, it looks like there was a bug in the ship data saving code that caused ship templates to be overwritten by ships that were based on those templates. E.g. the K-Leg station layout template was overwritten by the current game's instance of K-Leg.

And to make matters worse, this applied to ships that were only partially loaded, such as stations not currently docked to the player ship. In other words, it replaced a lot of the templates with empty shells, causing the game to degrade into empty ship layouts everywhere over time.

I hadn't noticed it yet because I haven't saved and loaded the same game more than once. It works the first time, but subsequent times start showing errors.

Fixing the issue has turned out to be pretty involved, as there are a bunch of places that needed special handling. A ship can be "shallow" loaded, meaning only basic "radar" type info is loaded (name, position, velocity, etc.), or it can be "fully" loaded (visible on-screen, with crew and equipment simulating). Most ships are "shallow" loaded until docked with the player ship.

There's also "template" vs. "savegame" loading. The latter loads the ship as it was saved, complete with existing crew and all their current activities. The former loads a copy of the ship, but spawns new crew and starts the new ship "from scratch."

As you can imagine, the ship loading code is fraught with pitfalls. And it appears I fell into a few when I set it up.

As of now, I have separated the template data and save game data for ships, so that is no longer in danger of overwrites. And for the most part, things are saving and loading as they should, whether in a new game or a saved game.

The one issue I can see remaining is that loading a saved game duplicates docked ships and their crew in the game. At first, I thought this was just a simple true vs. false "template" flag error when loading ships, but it turns out changing that fixes save games, but prevents crew from loading in new games. It looks like there's one extra condition I'll have to test for in the ship loading, and we should be back on track.

Unfortunately, it derailed progress today. I was hoping to start a new game, go through chargen, spawn into my first ship, fly to a nearby station, hire crew, and then head to a nearby derelict for salvage. And in the process, finally test my first long haul trapped on a ship with other crew for days.

However, I guess the good news is that this was a major bug that could cause a lot more damage down the road, as saves and templates get more complex and time consuming to make. Hopefully, we're back on track tomorrow, and can resume testing crew drama!

Tags: Ostranauts