CitiesSkylinesMods / TMPE

Cities: Skylines Traffic Manager: President Edition
https://steamcommunity.com/sharedfiles/filedetails/?id=1637663252
MIT License
569 stars 85 forks source link

New persistence strategy #1559

Open Elesbaan70 opened 2 years ago

Elesbaan70 commented 2 years ago

Resolves #1502

This PR provides a new way to save data so that changes can be made to the model without breaking old savegames.

The complete task list for this project is at #1502.

Also see this wiki page: https://github.com/CitiesSkylinesMods/TMPE/wiki/Loading-and-Saving-Data

kvakvs commented 2 years ago

Can add tests to your checklist (at least run manual test once):

Elesbaan70 commented 2 years ago

Can add tests to your checklist (at least run manual test once):

Here's what I tested:

  1. Transition from binary to XML:
    1. Reading old data:
      1. Load old data in new version. No XML found, so it reads the binary data.
    2. Saving new data with backward compatibility:
      1. Save new (XML) and old (binary) data to same file (default behavior until we decide we don't need to write the binary data anymore).
      2. Load in old version. It completely ignores the XML data.
      3. Load in new version. It sees the XML data and ignores the binary data.
  2. Versioning in XML (currently only tested in #1392 code):
    1. Reading old data:
      1. Load old data into new version. It detects the absence of the new feature, and reads the old way.
    2. Saving new data with backward compatibility:
      1. Save XML elements with and without the new feature.
      2. Load in old version. It skips elements with the new feature and reads elements without.
      3. Load in new version. It reads elements with the new feature and skips elements without.
Elesbaan70 commented 2 years ago

@kvakvs If you weren't already aware, the original issue that prompted this was, as indicated in #1502, the inability to revise the save format without breaking older builds. While we don't support old versions, this still creates a problem for anyone (including ourselves) who wants to run test builds.

But since we don't support old versions, the intention is that once a feature is released to stable, the legacy code that writes data the old way gets removed. (The code to read the old way has to stay pretty much forever, though I imagine we'll identify exceptions on a case-by-case basis.)

Elesbaan70 commented 2 years ago

I am converting this to draft, since TrafficManager.Util.Record was not addressed.