From 157ee95f64380215c3e6b1fed53be99607479582 Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Wed, 29 Nov 2017 00:04:18 -0600 Subject: COMMON: Add support for array serialization to Serializer SCUMM engine does quite a bit of direct array serialization. --- common/serializer.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/common/serializer.h b/common/serializer.h index 2def17cfbd..09f36d064b 100644 --- a/common/serializer.h +++ b/common/serializer.h @@ -43,6 +43,11 @@ namespace Common { _bytesSynced += SIZE; \ } +#define SYNC_PRIMITIVE(suffix) \ + template \ + static inline void suffix(Serializer &s, T &value) { \ + s.syncAs##suffix(value); \ + } /** * This class allows syncing / serializing data (primarily game savestates) @@ -67,6 +72,17 @@ public: typedef uint32 Version; static const Version kLastVersion = 0xFFFFFFFF; + SYNC_PRIMITIVE(Uint32LE) + SYNC_PRIMITIVE(Uint32BE) + SYNC_PRIMITIVE(Sint32LE) + SYNC_PRIMITIVE(Sint32BE) + SYNC_PRIMITIVE(Uint16LE) + SYNC_PRIMITIVE(Uint16BE) + SYNC_PRIMITIVE(Sint16LE) + SYNC_PRIMITIVE(Sint16BE) + SYNC_PRIMITIVE(Byte) + SYNC_PRIMITIVE(SByte) + protected: SeekableReadStream *_loadStream; WriteStream *_saveStream; @@ -94,6 +110,7 @@ public: // in the line "syncAsUint32LE(_version);" of // "bool syncVersion(Version currentVersion)". SYNC_AS(Byte, byte, 1) + SYNC_AS(SByte, int8, 1) SYNC_AS(Uint16LE, uint16, 2) SYNC_AS(Uint16BE, uint16, 2) @@ -237,8 +254,18 @@ public: } } + template + void syncArray(T *arr, size_t entries, void (*serializer)(Serializer &, T &), Version minVersion = 0, Version maxVersion = kLastVersion) { + if (_version < minVersion || _version > maxVersion) + return; + + for (size_t i = 0; i < entries; ++i) { + serializer(*this, arr[i]); + } + } }; +#undef SYNC_PRIMITIVE #undef SYNC_AS -- cgit v1.2.3