Savestream update
This commit is contained in:
@@ -118,10 +118,6 @@ errorret_t saveStreamWriteVersionImpl(
|
|||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Bool
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
errorret_t saveStreamReadBoolImpl(savestream_t *stream, bool_t *out) {
|
errorret_t saveStreamReadBoolImpl(savestream_t *stream, bool_t *out) {
|
||||||
uint8_t raw;
|
uint8_t raw;
|
||||||
errorChain(saveStreamReadBytesImpl(stream, &raw, sizeof(uint8_t)));
|
errorChain(saveStreamReadBytesImpl(stream, &raw, sizeof(uint8_t)));
|
||||||
@@ -135,10 +131,6 @@ errorret_t saveStreamWriteBoolImpl(savestream_t *stream, const bool_t *input) {
|
|||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Integers
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
errorret_t saveStreamReadInt8Impl(savestream_t *stream, int8_t *out) {
|
errorret_t saveStreamReadInt8Impl(savestream_t *stream, int8_t *out) {
|
||||||
errorChain(saveStreamReadBytesImpl(stream, out, sizeof(int8_t)));
|
errorChain(saveStreamReadBytesImpl(stream, out, sizeof(int8_t)));
|
||||||
errorOk();
|
errorOk();
|
||||||
@@ -252,10 +244,6 @@ errorret_t saveStreamWriteUInt64Impl(
|
|||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Float
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
errorret_t saveStreamReadFloatImpl(savestream_t *stream, float_t *out) {
|
errorret_t saveStreamReadFloatImpl(savestream_t *stream, float_t *out) {
|
||||||
float_t raw;
|
float_t raw;
|
||||||
errorChain(saveStreamReadBytesImpl(stream, &raw, sizeof(float_t)));
|
errorChain(saveStreamReadBytesImpl(stream, &raw, sizeof(float_t)));
|
||||||
@@ -269,10 +257,6 @@ errorret_t saveStreamWriteFloatImpl(savestream_t *stream, const float_t *input)
|
|||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// String
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
errorret_t saveStreamReadStringImpl(
|
errorret_t saveStreamReadStringImpl(
|
||||||
savestream_t *stream, char_t *out, const size_t maxLen
|
savestream_t *stream, char_t *out, const size_t maxLen
|
||||||
) {
|
) {
|
||||||
@@ -293,10 +277,6 @@ errorret_t saveStreamWriteStringImpl(
|
|||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Date (dusktimeepoch_t — stored as three little-endian 64-bit bit patterns)
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
errorret_t saveStreamReadDateImpl(savestream_t *stream, dusktimeepoch_t *out) {
|
errorret_t saveStreamReadDateImpl(savestream_t *stream, dusktimeepoch_t *out) {
|
||||||
uint64_t raw;
|
uint64_t raw;
|
||||||
|
|
||||||
|
|||||||
+19
-43
@@ -11,28 +11,13 @@
|
|||||||
#include "save/saveplatform.h"
|
#include "save/saveplatform.h"
|
||||||
#include "time/timeepoch.h"
|
#include "time/timeepoch.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* Active I/O context for a single save slot read or write pass.
|
|
||||||
*
|
|
||||||
* Platform code fills/drains `platform`. The stream layer maintains the
|
|
||||||
* running CRC32 accumulator so header/checksum bytes are excluded
|
|
||||||
* automatically from the digest.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/** Set true by the platform open-read function if the file exists. */
|
|
||||||
bool_t found;
|
bool_t found;
|
||||||
/** Running CRC32 accumulator, updated by each CRC-covered read/write. */
|
|
||||||
uint32_t checksum;
|
uint32_t checksum;
|
||||||
/** CRC32 value read from the file header; verified after loading. */
|
|
||||||
uint32_t expectedChecksum;
|
uint32_t expectedChecksum;
|
||||||
/** Platform-specific stream state (file handle, buffer, etc.). */
|
|
||||||
saveplatformstream_t platform;
|
saveplatformstream_t platform;
|
||||||
} savestream_t;
|
} savestream_t;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Internal functions — do not call directly; use the macros below.
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads bytes from the platform stream without updating the CRC.
|
* Reads bytes from the platform stream without updating the CRC.
|
||||||
*
|
*
|
||||||
@@ -391,10 +376,25 @@ errorret_t saveStreamWriteDateImpl(
|
|||||||
savestream_t *stream, const dusktimeepoch_t *input
|
savestream_t *stream, const dusktimeepoch_t *input
|
||||||
);
|
);
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
/**
|
||||||
// User-facing macros — these embed errorChain so errors propagate
|
* Reads the contents of a save slot from the stream into the save file
|
||||||
// automatically from saveFileLoad / saveFileWrite.
|
* struct. Use saveFileRead* macros to deserialize fields one at a time.
|
||||||
// ---------------------------------------------------------------------------
|
*
|
||||||
|
* @param stream Active read stream for this slot.
|
||||||
|
* @param file Save file struct to populate.
|
||||||
|
* @return An error code if loading fails.
|
||||||
|
*/
|
||||||
|
errorret_t saveFileLoad(savestream_t *stream, savefile_t *file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the contents of the save file struct into the stream.
|
||||||
|
* Use saveFileWrite* macros to serialize fields one at a time.
|
||||||
|
*
|
||||||
|
* @param stream Active write stream for this slot.
|
||||||
|
* @param file Save file struct to serialize.
|
||||||
|
* @return An error code if writing fails.
|
||||||
|
*/
|
||||||
|
errorret_t saveFileWrite(savestream_t *stream, savefile_t *file);
|
||||||
|
|
||||||
#define saveFileReadHeader(stream, header) \
|
#define saveFileReadHeader(stream, header) \
|
||||||
errorChain(saveStreamReadHeaderImpl(stream, header))
|
errorChain(saveStreamReadHeaderImpl(stream, header))
|
||||||
@@ -465,27 +465,3 @@ errorret_t saveStreamWriteDateImpl(
|
|||||||
errorChain(saveStreamReadDateImpl(stream, out))
|
errorChain(saveStreamReadDateImpl(stream, out))
|
||||||
#define saveFileWriteDate(stream, input) \
|
#define saveFileWriteDate(stream, input) \
|
||||||
errorChain(saveStreamWriteDateImpl(stream, input))
|
errorChain(saveStreamWriteDateImpl(stream, input))
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Game code must implement these two functions.
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the contents of a save slot from the stream into the save file
|
|
||||||
* struct. Use saveFileRead* macros to deserialize fields one at a time.
|
|
||||||
*
|
|
||||||
* @param stream Active read stream for this slot.
|
|
||||||
* @param file Save file struct to populate.
|
|
||||||
* @return An error code if loading fails.
|
|
||||||
*/
|
|
||||||
extern errorret_t saveFileLoad(savestream_t *stream, savefile_t *file);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes the contents of the save file struct into the stream.
|
|
||||||
* Use saveFileWrite* macros to serialize fields one at a time.
|
|
||||||
*
|
|
||||||
* @param stream Active write stream for this slot.
|
|
||||||
* @param file Save file struct to serialize.
|
|
||||||
* @return An error code if writing fails.
|
|
||||||
*/
|
|
||||||
extern errorret_t saveFileWrite(savestream_t *stream, savefile_t *file);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user