diff options
author | withmorten <morten.with@gmail.com> | 2021-06-26 19:14:46 +0200 |
---|---|---|
committer | withmorten <morten.with@gmail.com> | 2021-06-26 19:14:46 +0200 |
commit | f3a931e1c99372ae4bc224ef482d4052a09580cb (patch) | |
tree | 13992380234e68b8f1a32030b4df6aa3d6ebbaca /src/save | |
parent | Merge pull request #1155 from leanndroguedes/master (diff) | |
download | re3-f3a931e1c99372ae4bc224ef482d4052a09580cb.tar re3-f3a931e1c99372ae4bc224ef482d4052a09580cb.tar.gz re3-f3a931e1c99372ae4bc224ef482d4052a09580cb.tar.bz2 re3-f3a931e1c99372ae4bc224ef482d4052a09580cb.tar.lz re3-f3a931e1c99372ae4bc224ef482d4052a09580cb.tar.xz re3-f3a931e1c99372ae4bc224ef482d4052a09580cb.tar.zst re3-f3a931e1c99372ae4bc224ef482d4052a09580cb.zip |
Diffstat (limited to 'src/save')
-rw-r--r-- | src/save/SaveBuf.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/save/SaveBuf.h b/src/save/SaveBuf.h new file mode 100644 index 00000000..ed48a650 --- /dev/null +++ b/src/save/SaveBuf.h @@ -0,0 +1,64 @@ +#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; +} + +#define SAVE_HEADER_SIZE (4 * sizeof(char) + sizeof(uint32)) + +#define WriteSaveHeader(buf, a, b, c, d, size) \ + WriteSaveBuf(buf, a); \ + WriteSaveBuf(buf, b); \ + WriteSaveBuf(buf, c); \ + WriteSaveBuf(buf, d); \ + WriteSaveBuf(buf, (uint32)size); + +#ifdef VALIDATE_SAVE_SIZE +#define CheckSaveHeader(buf, a, b, c, d, size) { \ + 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);\ + ReadSaveBuf(&_size, buf);\ + assert(_size == size);\ + } +#else +#define CheckSaveHeader(buf, a, b, c, d, size) SkipSaveBuf(buf, 8); +#endif
\ No newline at end of file |