Savestream update

This commit is contained in:
2026-05-16 17:51:00 -05:00
parent a8fd55cb38
commit 782fd07a8d
2 changed files with 20 additions and 64 deletions
-20
View File
@@ -118,10 +118,6 @@ errorret_t saveStreamWriteVersionImpl(
errorOk();
}
// ---------------------------------------------------------------------------
// Bool
// ---------------------------------------------------------------------------
errorret_t saveStreamReadBoolImpl(savestream_t *stream, bool_t *out) {
uint8_t raw;
errorChain(saveStreamReadBytesImpl(stream, &raw, sizeof(uint8_t)));
@@ -135,10 +131,6 @@ errorret_t saveStreamWriteBoolImpl(savestream_t *stream, const bool_t *input) {
errorOk();
}
// ---------------------------------------------------------------------------
// Integers
// ---------------------------------------------------------------------------
errorret_t saveStreamReadInt8Impl(savestream_t *stream, int8_t *out) {
errorChain(saveStreamReadBytesImpl(stream, out, sizeof(int8_t)));
errorOk();
@@ -252,10 +244,6 @@ errorret_t saveStreamWriteUInt64Impl(
errorOk();
}
// ---------------------------------------------------------------------------
// Float
// ---------------------------------------------------------------------------
errorret_t saveStreamReadFloatImpl(savestream_t *stream, float_t *out) {
float_t raw;
errorChain(saveStreamReadBytesImpl(stream, &raw, sizeof(float_t)));
@@ -269,10 +257,6 @@ errorret_t saveStreamWriteFloatImpl(savestream_t *stream, const float_t *input)
errorOk();
}
// ---------------------------------------------------------------------------
// String
// ---------------------------------------------------------------------------
errorret_t saveStreamReadStringImpl(
savestream_t *stream, char_t *out, const size_t maxLen
) {
@@ -293,10 +277,6 @@ errorret_t saveStreamWriteStringImpl(
errorOk();
}
// ---------------------------------------------------------------------------
// Date (dusktimeepoch_t — stored as three little-endian 64-bit bit patterns)
// ---------------------------------------------------------------------------
errorret_t saveStreamReadDateImpl(savestream_t *stream, dusktimeepoch_t *out) {
uint64_t raw;
+20 -44
View File
@@ -11,28 +11,13 @@
#include "save/saveplatform.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 {
/** Set true by the platform open-read function if the file exists. */
bool_t found;
/** Running CRC32 accumulator, updated by each CRC-covered read/write. */
uint32_t checksum;
/** CRC32 value read from the file header; verified after loading. */
uint32_t expectedChecksum;
/** Platform-specific stream state (file handle, buffer, etc.). */
saveplatformstream_t platform;
} savestream_t;
// ---------------------------------------------------------------------------
// Internal functions — do not call directly; use the macros below.
// ---------------------------------------------------------------------------
/**
* Reads bytes from the platform stream without updating the CRC.
*
@@ -391,10 +376,25 @@ errorret_t saveStreamWriteDateImpl(
savestream_t *stream, const dusktimeepoch_t *input
);
// ---------------------------------------------------------------------------
// User-facing macros — these embed errorChain so errors propagate
// automatically from saveFileLoad / saveFileWrite.
// ---------------------------------------------------------------------------
/**
* 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.
*/
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) \
errorChain(saveStreamReadHeaderImpl(stream, header))
@@ -464,28 +464,4 @@ errorret_t saveStreamWriteDateImpl(
#define saveFileReadDate(stream, out) \
errorChain(saveStreamReadDateImpl(stream, out))
#define saveFileWriteDate(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);
errorChain(saveStreamWriteDateImpl(stream, input))