-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: SQLite+Compressed save format (Phase 2 of v2 save format) #5777
Merged
RoyalFox2140
merged 7 commits into
cataclysmbnteam:main
from
randombk:sqlite-saves-phase2
Jan 19, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fd2b198
fix: clang-tidy should ignore changes to non-source files
randombk aa7365d
feat: V2 save format
randombk b61ff6f
fix: Compiler warnings, OSX+Android Build
randombk 3eedcc0
docs: Update docs with build instructions for v2 saves
randombk 76aaee2
Merge branch 'main' into pr/5777
chaosvolt 6ef7fc4
Avoid ever-growing world names from the V2 conversion
randombk 8aa2596
Merge branch 'main' into sqlite-saves-phase2
scarf005 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,49 @@ | ||
# Reference: https://developer.android.com/ndk/guides/android_mk.html | ||
|
||
# Based on https://sqlite.org/android/file?name=sqlite3/src/main/jni/sqlite/Android.mk&ci=tip | ||
|
||
LOCAL_PATH:= $(call my-dir) | ||
include $(CLEAR_VARS) | ||
|
||
# If using SEE, uncomment the following: | ||
# LOCAL_CFLAGS += -DSQLITE_HAS_CODEC | ||
|
||
#Define HAVE_USLEEP, otherwise ALL sleep() calls take at least 1000ms | ||
LOCAL_CFLAGS += -DHAVE_USLEEP=1 | ||
|
||
# Enable SQLite extensions. | ||
LOCAL_CFLAGS += -DSQLITE_ENABLE_FTS5 | ||
LOCAL_CFLAGS += -DSQLITE_ENABLE_RTREE | ||
LOCAL_CFLAGS += -DSQLITE_ENABLE_FTS3 | ||
LOCAL_CFLAGS += -DSQLITE_ENABLE_BATCH_ATOMIC_WRITE | ||
|
||
# This is important - it causes SQLite to use memory for temp files. Since | ||
# Android has no globally writable temp directory, if this is not defined the | ||
# application throws an exception when it tries to create a temp file. | ||
# | ||
LOCAL_CFLAGS += -DSQLITE_TEMP_STORE=3 | ||
|
||
LOCAL_CFLAGS += -DHAVE_CONFIG_H -DKHTML_NO_EXCEPTIONS -DGKWQ_NO_JAVA | ||
LOCAL_CFLAGS += -DNO_SUPPORT_JS_BINDING -DQT_NO_WHEELEVENT -DKHTML_NO_XBL | ||
LOCAL_CFLAGS += -U__APPLE__ | ||
LOCAL_CFLAGS += -DHAVE_STRCHRNUL=0 | ||
LOCAL_CFLAGS += -DSQLITE_USE_URI=1 | ||
LOCAL_CFLAGS += -Wno-unused-parameter -Wno-int-to-pointer-cast | ||
LOCAL_CFLAGS += -Wno-uninitialized -Wno-parentheses | ||
LOCAL_CPPFLAGS += -Wno-conversion-null | ||
|
||
ifeq ($(TARGET_ARCH), arm) | ||
LOCAL_CFLAGS += -DPACKED="__attribute__ ((packed))" | ||
else | ||
LOCAL_CFLAGS += -DPACKED="" | ||
endif | ||
|
||
LOCAL_SRC_FILES := sqlite3.c | ||
|
||
LOCAL_C_INCLUDES += $(LOCAL_PATH) | ||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) | ||
|
||
LOCAL_MODULE := libsqlite3 | ||
LOCAL_LDLIBS += -ldl -llog | ||
|
||
include $(BUILD_SHARED_LIBRARY) |
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
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 = static_cast<uLongf>( compressed_size ) * 8; | ||
output.resize( decompressedSize ); | ||
|
||
int result; | ||
do { | ||
result = uncompress( | ||
reinterpret_cast<Bytef *>( output.data() ), | ||
&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 ); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed here, but it might be a good idea to extract it to an option later.