summaryrefslogtreecommitdiffstats
path: root/src/save/SaveBuf.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/save/SaveBuf.h')
-rw-r--r--src/save/SaveBuf.h74
1 files changed, 62 insertions, 12 deletions
diff --git a/src/save/SaveBuf.h b/src/save/SaveBuf.h
index aad2e1a8..d0817e9a 100644
--- a/src/save/SaveBuf.h
+++ b/src/save/SaveBuf.h
@@ -18,24 +18,52 @@ SkipSaveBuf(uint8 *&buf, int32 skip)
#endif
}
-template <typename T>
inline void
-ReadSaveBuf(T* out, uint8 *&buf)
+SkipSaveBuf(uint8*& buf, uint32 &length, int32 skip)
+{
+ buf += skip;
+ length += 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>
+template<typename T>
+inline void
+ReadSaveBuf(T *out, uint8 *&buf, uint32 &length)
+{
+ *out = *(T *)buf;
+ SkipSaveBuf(buf, length, sizeof(T));
+}
+
+template<typename T>
inline T *
WriteSaveBuf(uint8 *&buf, const T &value)
{
- T *p = (T *)buf;
+ T *p = (T*)buf;
*p = value;
SkipSaveBuf(buf, sizeof(T));
return p;
}
+template<typename T>
+inline T *
+WriteSaveBuf(uint8 *&buf, uint32 &length, const T &value)
+{
+ T *p = (T*)buf;
+ *p = value;
+ SkipSaveBuf(buf, length, sizeof(T));
+ return p;
+}
+
#ifdef COMPATIBLE_SAVES
inline void
ZeroSaveBuf(uint8 *&buf, uint32 length)
@@ -45,14 +73,21 @@ ZeroSaveBuf(uint8 *&buf, uint32 length)
}
#endif
-#define SAVE_HEADER_SIZE (4 * sizeof(char) + sizeof(uint32))
+#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));
+#define WriteSaveHeader(buf,a,b,c,d,size) \
+ WriteSaveBuf(buf, a);\
+ WriteSaveBuf(buf, b);\
+ WriteSaveBuf(buf, c);\
+ WriteSaveBuf(buf, d);\
+ WriteSaveBuf<uint32>(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, (uint32)(size));
#ifdef VALIDATE_SAVE_SIZE
#define CheckSaveHeader(buf, a, b, c, d, size) do { \
@@ -68,6 +103,21 @@ ZeroSaveBuf(uint8 *&buf, uint32 length)
ReadSaveBuf(&_size, buf);\
assert(_size == size);\
} while(0)
+
+#define CheckSaveHeaderWithLength(buf,len,a,b,c,d,size) do { \
+ char _c; uint32 _size;\
+ ReadSaveBuf(&_c, buf, len);\
+ assert(_c == a);\
+ ReadSaveBuf(&_c, buf, len);\
+ assert(_c == b);\
+ ReadSaveBuf(&_c, buf, len);\
+ assert(_c == c);\
+ ReadSaveBuf(&_c, buf, len);\
+ assert(_c == d);\
+ ReadSaveBuf(&_size, buf, len);\
+ assert(_size == size);\
+ } while(0)
#else
#define CheckSaveHeader(buf, a, b, c, d, size) SkipSaveBuf(buf, 8);
-#endif \ No newline at end of file
+#define CheckSaveHeaderWithLength(buf, len, a, b, c, d, size) SkipSaveBuf(buf, 8);
+#endif