2021-06-26 17:14:46 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifdef VALIDATE_SAVE_SIZE
|
|
|
|
extern int32 _saveBufCount;
|
|
|
|
#define INITSAVEBUF _saveBufCount = 0;
|
|
|
|
#define VALIDATESAVEBUF(b) assert(_saveBufCount == b);
|
|
|
|
#else
|
|
|
|
#define INITSAVEBUF
|
|
|
|
#define VALIDATESAVEBUF(b)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
inline void
|
|
|
|
SkipSaveBuf(uint8 *&buf, int32 skip)
|
|
|
|
{
|
|
|
|
buf += skip;
|
|
|
|
#ifdef VALIDATE_SAVE_SIZE
|
|
|
|
_saveBufCount += skip;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void
|
|
|
|
ReadSaveBuf(T* out, uint8 *&buf)
|
|
|
|
{
|
|
|
|
*out = *(T *)buf;
|
|
|
|
SkipSaveBuf(buf, sizeof(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline T *
|
|
|
|
WriteSaveBuf(uint8 *&buf, const T &value)
|
|
|
|
{
|
|
|
|
T *p = (T *)buf;
|
|
|
|
*p = value;
|
|
|
|
SkipSaveBuf(buf, sizeof(T));
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2021-07-05 16:07:26 +00:00
|
|
|
#ifdef COMPATIBLE_SAVES
|
|
|
|
inline void
|
|
|
|
ZeroSaveBuf(uint8 *&buf, uint32 length)
|
|
|
|
{
|
|
|
|
memset(buf, 0, length);
|
|
|
|
SkipSaveBuf(buf, length);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-06-26 17:14:46 +00:00
|
|
|
#define SAVE_HEADER_SIZE (4 * sizeof(char) + sizeof(uint32))
|
|
|
|
|
2021-06-26 17:19:45 +00:00
|
|
|
#define WriteSaveHeader(buf, a, b, c, d, size) \
|
|
|
|
WriteSaveBuf(buf, a); \
|
|
|
|
WriteSaveBuf(buf, b); \
|
|
|
|
WriteSaveBuf(buf, c); \
|
|
|
|
WriteSaveBuf(buf, d); \
|
|
|
|
WriteSaveBuf(buf, (uint32)(size));
|
2021-06-26 17:14:46 +00:00
|
|
|
|
|
|
|
#ifdef VALIDATE_SAVE_SIZE
|
2021-06-26 17:19:45 +00:00
|
|
|
#define CheckSaveHeader(buf, a, b, c, d, size) do { \
|
2021-07-01 19:49:01 +00:00
|
|
|
char _c; uint32 _size;\
|
|
|
|
ReadSaveBuf(&_c, buf);\
|
|
|
|
assert(_c == a);\
|
|
|
|
ReadSaveBuf(&_c, buf);\
|
|
|
|
assert(_c == b);\
|
|
|
|
ReadSaveBuf(&_c, buf);\
|
|
|
|
assert(_c == c);\
|
|
|
|
ReadSaveBuf(&_c, buf);\
|
|
|
|
assert(_c == d);\
|
2021-06-26 17:14:46 +00:00
|
|
|
ReadSaveBuf(&_size, buf);\
|
|
|
|
assert(_size == size);\
|
2021-06-26 17:19:45 +00:00
|
|
|
} while(0)
|
2021-06-26 17:14:46 +00:00
|
|
|
#else
|
|
|
|
#define CheckSaveHeader(buf, a, b, c, d, size) SkipSaveBuf(buf, 8);
|
|
|
|
#endif
|