mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Savestates: Use LZ4 algorithm for faster decompression
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
@ -17,18 +18,62 @@ namespace State
|
||||
// number of states
|
||||
static const u32 NUM_STATES = 10;
|
||||
|
||||
struct StateHeader
|
||||
struct StateHeaderLegacy
|
||||
{
|
||||
char gameID[6];
|
||||
u16 reserved1;
|
||||
u32 size;
|
||||
u32 reserved2;
|
||||
char game_id[6];
|
||||
char reserved1[2];
|
||||
u32 lzo_size = 0; // Must be zero for new states. Used to support legacy decompression algorithm.
|
||||
char reserved2[4];
|
||||
double time;
|
||||
};
|
||||
constexpr size_t STATE_HEADER_SIZE = sizeof(StateHeader);
|
||||
constexpr size_t STATE_HEADER_SIZE = sizeof(StateHeaderLegacy);
|
||||
static_assert(STATE_HEADER_SIZE == 24);
|
||||
static_assert(offsetof(StateHeader, size) == 8);
|
||||
static_assert(offsetof(StateHeader, time) == 16);
|
||||
static_assert(offsetof(StateHeaderLegacy, lzo_size) == 8);
|
||||
static_assert(offsetof(StateHeaderLegacy, time) == 16);
|
||||
static_assert(std::is_trivially_copyable_v<StateHeaderLegacy>);
|
||||
|
||||
struct StateHeaderVersion
|
||||
{
|
||||
u32 version_cookie;
|
||||
u32 version_string_length;
|
||||
};
|
||||
static_assert(std::is_trivially_copyable_v<StateHeaderVersion>);
|
||||
|
||||
struct StateHeader
|
||||
{
|
||||
StateHeaderLegacy legacy_header;
|
||||
StateHeaderVersion version_header;
|
||||
std::string version_string;
|
||||
};
|
||||
|
||||
enum CompressionType : u16
|
||||
{
|
||||
Uncompressed = 0,
|
||||
LZ4 = 1,
|
||||
// Add new compression types after this, as the compression type
|
||||
// is numerically stored in the state file.
|
||||
};
|
||||
|
||||
struct StateExtendedBaseHeader
|
||||
{
|
||||
u16 header_version;
|
||||
u16 compression_type;
|
||||
u32 payload_offset;
|
||||
u64 uncompressed_size;
|
||||
};
|
||||
constexpr size_t EXTENDED_BASE_HEADER_SIZE = sizeof(StateExtendedBaseHeader);
|
||||
static_assert(EXTENDED_BASE_HEADER_SIZE == 16);
|
||||
static_assert(offsetof(StateExtendedBaseHeader, payload_offset) == 4);
|
||||
static_assert(offsetof(StateExtendedBaseHeader, uncompressed_size) == 8);
|
||||
static_assert(std::is_trivially_copyable_v<StateExtendedBaseHeader>);
|
||||
|
||||
struct StateExtendedHeader
|
||||
{
|
||||
StateExtendedBaseHeader base_header;
|
||||
// Feel free to add new fields here, adjusting COMPRESSED_DATA_OFFSET accordingly, as well as
|
||||
// CreateExtendedHeader(). Add the appropriate IOFile read/write calls within LoadFileStateData()
|
||||
// and WriteHeadersToFile()
|
||||
};
|
||||
|
||||
void Init();
|
||||
|
||||
|
Reference in New Issue
Block a user