Merge pull request #174 from Alcaro/master

Optimize serialization stuff a bit
This commit is contained in:
byuu 2019-10-16 09:26:50 +09:00 committed by GitHub
commit 53f8de6ac3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -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;
}

View File

@ -110,6 +110,30 @@ struct serializer {
return *this;
}
template<int N> 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<int N> 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<typename T, uint Size> auto array(nall::array<T[Size]>& array) -> serializer& {
for(auto& value : array) operator()(value);
return *this;