-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement new SQLite-based save format. New worlds can be configured to use V2. Existing worlds can be converted from the main menu. Existing V1 worlds should load exactly the same as before until converted. Signed-off-by: David Li <[email protected]>
- Loading branch information
Showing
13 changed files
with
618 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "compress.h" | ||
|
||
#include <zlib.h> | ||
#include <vector> | ||
#include <string> | ||
#include <stdexcept> | ||
#include <cstddef> | ||
|
||
void zlib_compress( const std::string &input, std::vector<std::byte> &output ) | ||
{ | ||
uLongf compressedSize = compressBound( input.size() ); | ||
output.resize( compressedSize ); | ||
|
||
int result = compress2( | ||
reinterpret_cast<Bytef *>( output.data() ), | ||
&compressedSize, | ||
reinterpret_cast<const Bytef *>( input.data() ), | ||
input.size(), | ||
Z_BEST_SPEED | ||
); | ||
|
||
if( result != Z_OK ) { | ||
throw std::runtime_error( "Zlib compression error" ); | ||
} | ||
|
||
output.resize( compressedSize ); | ||
} | ||
|
||
void zlib_decompress( const void *compressed_data, int compressed_size, std::string &output ) | ||
{ | ||
// We need to guess at the decompressed size - we expect things to compress fairly well. | ||
uLongf decompressedSize = compressed_size * 8; | ||
output.resize( decompressedSize ); | ||
|
||
int result; | ||
do { | ||
result = uncompress( | ||
reinterpret_cast<Bytef *>( &output[0] ), | ||
&decompressedSize, | ||
reinterpret_cast<const Bytef *>( compressed_data ), | ||
compressed_size | ||
); | ||
|
||
if( result == Z_BUF_ERROR ) { | ||
decompressedSize *= 2; // Double the buffer size and retry | ||
output.resize( decompressedSize ); | ||
} else if( result != Z_OK ) { | ||
throw std::runtime_error( "Zlib decompression failed" ); | ||
} | ||
} while( result == Z_BUF_ERROR ); | ||
|
||
output.resize( decompressedSize ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
#ifndef CATA_SRC_COMPRESS_H | ||
#define CATA_SRC_COMPRESS_H | ||
|
||
#include <string> | ||
|
||
#include "fstream_utils.h" | ||
|
||
void zlib_compress( const std::string &input, std::vector<std::byte> &output ); | ||
void zlib_decompress( const void *compressed_data, int compressed_size, std::string &output ); | ||
|
||
#endif // CATA_SRC_COMPRESS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.