MapLoaderSystem compression support, new commands for saving/loading full game state - #6956
MapLoaderSystem compression support, new commands for saving/loading full game state#6956Roudenn wants to merge 38 commits into
Conversation
… into replay-saves
metalgearsloth
left a comment
There was a problem hiding this comment.
Needs tests please.
Also not really sure why compression isn't rolled into existing maploader instead of a bespoke system.
This comment was marked as outdated.
This comment was marked as outdated.
Roudenn
left a comment
There was a problem hiding this comment.
Technically the full entity serialization should be incompatable with adminbus prototype loading, so I wonder if having adminbus should be controlled by a CVar that if enabled disallows full entity serialization
| /// <param name="data">Mapping data node to compress into the specified path.</param> | ||
| private void WriteCompressedZstd(ResPath path, MappingDataNode data) | ||
| { | ||
| using var uncompressedStream = new MemoryStream(Encoding.UTF8.GetBytes(data.ToString())); |
There was a problem hiding this comment.
I've tried to do that with a IRobustSerializer, but it seems to return a prefix with an arbitrary byte length depending on how large the file is, so I've resorted to using Encoding.UTF8.GetBytes instead
| if (!uncompressedStream.TryGetBuffer(out var uncompressed)) | ||
| { | ||
| uncompressed = new ArraySegment<byte>(uncompressedStream.ToArray()); | ||
| } |
There was a problem hiding this comment.
When I debugged this it looks like this never fails, is this fail-safe redundant here?
| if (path.Extension == SaveExtension) | ||
| { | ||
| WriteCompressedZstd(path, data); | ||
| } | ||
| else | ||
| { | ||
| using var writer = _resourceManager.UserData.OpenWriteText(path); | ||
| WriteYaml(writer, data); | ||
| } |
There was a problem hiding this comment.
Is it okay to run compression when a special file format is specified? Maybe it should be a boolean passed as a parameter everywhere instead
|
Reworked the PR entirely to work around maploader, now uses safe methods for file reading and writing, and also included a test to confirm that the new file format works as intended |
Overview
Added support for ZStd compression for files saved and loaded by MapLoaderSystem, using the new file extension:
.rtsave.Added
savegameandloadgamecommands that can save and load all entities to a save file, by calling an already existing method in the maploader system, andconvertsavefilethat converts YAML files into RTSAVE and backwards, which is useful for debugging.Why
Fixes #2406 since now save files are very cheap memory-wise and have official support, starting from here content can eventually implement full persistence
ZStd compression can provide up to 97% file size reduction, which can be used for packaged server builds on Content, or even in the repository itself if you're crazy and don't care about readability.
Also it's useful for servers that support persistent rounds since SS14's serializers are sometimes not efficient for post map-init entities, so file compression saves a lot of disk space and makes them practically free.
Test plan
New file format support should be covered by MapLoaderTest
New commands can be easily tested in-game by just running them on a devmap
Media
Convert command works correctly in both ways, and the file is compressed correctly:
Demonstration of the new commands:
2026-08-11.19-02-17.mp4