diff options
author | Colin Snover | 2017-11-29 00:04:18 -0600 |
---|---|---|
committer | Eugene Sandulenko | 2018-01-31 17:58:01 +0100 |
commit | 157ee95f64380215c3e6b1fed53be99607479582 (patch) | |
tree | 8f3f4a3a7607619a5a2d0590c4f4b52c6751dfee | |
parent | 9d10a998ae83f37eafef524cf1b750923f48cfad (diff) | |
download | scummvm-rg350-157ee95f64380215c3e6b1fed53be99607479582.tar.gz scummvm-rg350-157ee95f64380215c3e6b1fed53be99607479582.tar.bz2 scummvm-rg350-157ee95f64380215c3e6b1fed53be99607479582.zip |
COMMON: Add support for array serialization to Serializer
SCUMM engine does quite a bit of direct array serialization.
-rw-r--r-- | common/serializer.h | 27 |
1 files changed, 27 insertions, 0 deletions
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 <typename T> \ + 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 <typename T> + 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 |