From cd18cdb1d650013194c4a9ffd7adcd2d5a908d8f Mon Sep 17 00:00:00 2001 From: Alcaro Date: Tue, 15 Oct 2019 20:29:04 +0200 Subject: [PATCH] Optimize serialization stuff a bit --- bsnes/sfc/ppu-fast/serialization.cpp | 3 ++- nall/serializer.hpp | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/bsnes/sfc/ppu-fast/serialization.cpp b/bsnes/sfc/ppu-fast/serialization.cpp index 38ac36ef..119eea61 100644 --- a/bsnes/sfc/ppu-fast/serialization.cpp +++ b/bsnes/sfc/ppu-fast/serialization.cpp @@ -8,7 +8,8 @@ auto PPU::serialize(serializer& s) -> void { s.array(cgram); for(auto& object : objects) object.serialize(s); - for(auto address : range(32768)) updateTiledata(address); + if (s.mode() == s.Load) + for(auto address : range(32768)) updateTiledata(address); Line::start = 0; Line::count = 0; } diff --git a/nall/serializer.hpp b/nall/serializer.hpp index 1e8eeb2c..0fd086ca 100755 --- a/nall/serializer.hpp +++ b/nall/serializer.hpp @@ -110,6 +110,30 @@ struct serializer { return *this; } + template auto array(uint8_t (&array_)[N]) -> serializer& { + array(array_, N); + return *this; + } + auto array(uint8_t* array, uint size) -> serializer& { + if(_mode == Save) { + memcpy(_data+_size, array, size); + } else if(_mode == Load) { + memcpy(array, _data+_size, size); + } + _size += size; + return *this; + } +#ifdef ENDIAN_LSB + template auto array(uint16_t (&array_)[N]) -> serializer& { + array(array_, N); + return *this; + } + auto array(uint16_t* array_, uint size) -> serializer& { + array((uint8_t*)array_, size*2); + return *this; + } +#endif + template auto array(nall::array& array) -> serializer& { for(auto& value : array) operator()(value); return *this;