Compression [ADDED]

Vote for new features, or make your own requests here.
Post Reply
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Compression [ADDED]

Post by Joel »

Status

Added in 3.3.1

Complexity

7/10

Description

This would allow you to compress data using Easy Save.

LZF compression is available under the BSD license (https://forum.unity.com/threads/lzf-com ... ty.152579/), and might be worth considering if .NET's built-in compression is not compatible with the platforms supported by Easy Save.
EduardK
Posts: 1
Joined: Tue Dec 20, 2016 9:20 am

Re: Compression

Post by EduardK »

Hi, tell, please, what probability that you realize it in the next 2 months?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Compression

Post by Joel »

Hi there,

Unfortunately as there has been very few requests for this feature it is not likely that it will be included in the next two months. Easy Save's format is already so compact that there are very few cases where it's required.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
viveleroi
Posts: 17
Joined: Fri Feb 03, 2017 1:40 am

Re: Compression

Post by viveleroi »

This would be a big feature for me but I can see how my use-case isn't common.

I have a procedurally-generated 2d terrain system so I save every chunk of 3x3 tiles to its own file. This includes a Vector2 for the chunk coord, and some tile data (primarily an enum for the tile type and any world object placed on it).

Each file ranges from 200-400k (some will be a bit larger once I implement saving containers). It doesn't take a long time before we've generated 600 chunks and the save game file is already 3MB. Running the entire "terrain" folder through the default Mac OS X "Compress Folder" zip tool yields a total file size of 173k.

Is there anything I can do in the meantime to add some compression?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Compression

Post by Joel »

Hi there,

At the moment you might be able to save your data to memory rather than disk using an ES2Writer, and then compress the bytes and use ES2.SaveRaw to store them to file. Then you can use ES2.LoadRaw to load the compressed bytes as a byte array, decompress them and then use an ES2Reader to read from them.

Here's the code for writing and reading to and from a byte array:
var settings = new ES2Settings();
settings.saveLocation = ES2Settings.SaveLocation.Memory;
byte[] bytes;
 
using(var writer = ES2Writer.Create(settings))
{
    writer.Write(123, "tag1");
    writer.Write("myString", "tag2");
    bytes = writer.stream.ReadAllBytes();
}
 
using(var reader = new ES2Reader(bytes, settings))
{
    var es2Data = reader.ReadAll();
}
And some information on compressing bytes in C# can be found here: https://www.dotnetperls.com/compress

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
fur
Posts: 9
Joined: Fri Jul 28, 2017 6:12 am

Re: Compression

Post by fur »

Although it seems not very hard to make the compression solution by our own, it will still be great to see it in ES3.

(we have some map files to save which is simply binary but can be 10M+)
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Compression

Post by Joel »

Compression will be included in 3.3.1, which will be available in mid-May 2020.
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply