From dd039677a097168b0488482a19f55a3e33e8b3c6 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 10 Oct 2020 23:50:00 +0300 Subject: Zones saving and loading --- src/core/common.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/core/common.h') diff --git a/src/core/common.h b/src/core/common.h index c4c133fa..0e6bd60f 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -412,6 +412,15 @@ inline void SkipSaveBuf(uint8 *&buf, int32 skip) #endif } +inline void SkipSaveBuf(uint8*& buf, uint32 &length, int32 skip) +{ + buf += skip; + length += skip; +#ifdef VALIDATE_SAVE_SIZE + _saveBufCount += skip; +#endif +} + template inline const T ReadSaveBuf(uint8 *&buf) { @@ -420,6 +429,14 @@ inline const T ReadSaveBuf(uint8 *&buf) return value; } +template +inline const T ReadSaveBuf(uint8 *&buf, uint32 &length) +{ + T &value = *(T*)buf; + SkipSaveBuf(buf, length, sizeof(T)); + return value; +} + template inline T *WriteSaveBuf(uint8 *&buf, const T &value) { @@ -429,6 +446,15 @@ inline T *WriteSaveBuf(uint8 *&buf, const T &value) return p; } +template +inline T *WriteSaveBuf(uint8 *&buf, uint32 &length, const T &value) +{ + T *p = (T*)buf; + *p = value; + SkipSaveBuf(buf, length, sizeof(T)); + return p; +} + #define SAVE_HEADER_SIZE (4*sizeof(char)+sizeof(uint32)) @@ -439,6 +465,13 @@ inline T *WriteSaveBuf(uint8 *&buf, const T &value) WriteSaveBuf(buf, d);\ WriteSaveBuf(buf, size); +#define WriteSaveHeaderWithLength(buf,len,a,b,c,d,size) \ + WriteSaveBuf(buf, len, a);\ + WriteSaveBuf(buf, len, b);\ + WriteSaveBuf(buf, len, c);\ + WriteSaveBuf(buf, len, d);\ + WriteSaveBuf(buf, len, size); + #define CheckSaveHeader(buf,a,b,c,d,size)\ assert(ReadSaveBuf(buf) == a);\ assert(ReadSaveBuf(buf) == b);\ @@ -446,5 +479,12 @@ inline T *WriteSaveBuf(uint8 *&buf, const T &value) assert(ReadSaveBuf(buf) == d);\ assert(ReadSaveBuf(buf) == size); +#define CheckSaveHeaderWithLength(buf,len,a,b,c,d,size)\ + assert(ReadSaveBuf(buf,len) == a);\ + assert(ReadSaveBuf(buf,len) == b);\ + assert(ReadSaveBuf(buf,len) == c);\ + assert(ReadSaveBuf(buf,len) == d);\ + assert(ReadSaveBuf(buf,len) == size); + void cprintf(char*, ...); \ No newline at end of file -- cgit v1.2.3