Skip to content

Commit

Permalink
Use proper serialization logic for the tile's main object part (#9227)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihhub authored Oct 25, 2024
1 parent a605b44 commit fb4790a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
30 changes: 21 additions & 9 deletions src/fheroes2/maps/maps_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1862,25 +1862,32 @@ IStreamBase & Maps::operator>>( IStreamBase & stream, ObjectPart & ta )

OStreamBase & Maps::operator<<( OStreamBase & stream, const Tiles & tile )
{
// TODO: use operator<<() for _mainObjectPart.
return stream << tile._index << tile._terrainImageIndex << tile._terrainFlags << tile._tilePassabilityDirections << tile._mainObjectPart._uid
<< tile._mainObjectPart._objectIcnType << tile._mainObjectPart._imageIndex << tile._mainObjectType << tile._fogColors << tile._metadata
<< tile._occupantHeroId << tile._isTileMarkedAsRoad << tile._groundObjectPart << tile._topObjectPart << tile._mainObjectPart._layerType
return stream << tile._index << tile._terrainImageIndex << tile._terrainFlags << tile._tilePassabilityDirections << tile._mainObjectPart << tile._mainObjectType
<< tile._fogColors << tile._metadata << tile._occupantHeroId << tile._isTileMarkedAsRoad << tile._groundObjectPart << tile._topObjectPart
<< tile._boatOwnerColor;
}

IStreamBase & Maps::operator>>( IStreamBase & stream, Tiles & tile )
{
stream >> tile._index >> tile._terrainImageIndex >> tile._terrainFlags >> tile._tilePassabilityDirections >> tile._mainObjectPart._uid
>> tile._mainObjectPart._objectIcnType;
stream >> tile._index >> tile._terrainImageIndex >> tile._terrainFlags >> tile._tilePassabilityDirections;

static_assert( LAST_SUPPORTED_FORMAT_VERSION < FORMAT_VERSION_1104_RELEASE, "Remove the logic below." );
if ( Game::GetVersionOfCurrentSaveFile() < FORMAT_VERSION_1104_RELEASE ) {
stream >> tile._mainObjectPart._uid >> tile._mainObjectPart._objectIcnType;
}
else {
stream >> tile._mainObjectPart;
}

static_assert( LAST_SUPPORTED_FORMAT_VERSION < FORMAT_VERSION_PRE2_1009_RELEASE, "Remove the logic below." );
if ( Game::GetVersionOfCurrentSaveFile() < FORMAT_VERSION_PRE2_1009_RELEASE ) {
bool temp;
stream >> temp >> temp;
}

stream >> tile._mainObjectPart._imageIndex;
if ( Game::GetVersionOfCurrentSaveFile() < FORMAT_VERSION_1104_RELEASE ) {
stream >> tile._mainObjectPart._imageIndex;
}

static_assert( LAST_SUPPORTED_FORMAT_VERSION < FORMAT_VERSION_PRE3_1100_RELEASE, "Remove the logic below." );
if ( Game::GetVersionOfCurrentSaveFile() < FORMAT_VERSION_PRE3_1100_RELEASE ) {
Expand All @@ -1893,6 +1900,11 @@ IStreamBase & Maps::operator>>( IStreamBase & stream, Tiles & tile )
stream >> tile._mainObjectType;
}

return stream >> tile._fogColors >> tile._metadata >> tile._occupantHeroId >> tile._isTileMarkedAsRoad >> tile._groundObjectPart >> tile._topObjectPart
>> tile._mainObjectPart._layerType >> tile._boatOwnerColor;
stream >> tile._fogColors >> tile._metadata >> tile._occupantHeroId >> tile._isTileMarkedAsRoad >> tile._groundObjectPart >> tile._topObjectPart;

if ( Game::GetVersionOfCurrentSaveFile() < FORMAT_VERSION_1104_RELEASE ) {
stream >> tile._mainObjectPart._layerType;
}

return stream >> tile._boatOwnerColor;
}
3 changes: 2 additions & 1 deletion src/fheroes2/system/save_format_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum SaveFileFormat : uint16_t
// !!! IMPORTANT !!!
// If you're adding a new version you must assign it to CURRENT_FORMAT_VERSION located at the bottom.
// If you're removing an old version you must assign the oldest available to LAST_SUPPORTED_FORMAT_VERSION located at the bottom.
FORMAT_VERSION_1104_RELEASE = 10025,
FORMAT_VERSION_1103_RELEASE = 10024,
FORMAT_VERSION_PRE2_1103_RELEASE = 10023,
FORMAT_VERSION_PRE1_1103_RELEASE = 10022,
Expand All @@ -45,5 +46,5 @@ enum SaveFileFormat : uint16_t

LAST_SUPPORTED_FORMAT_VERSION = FORMAT_VERSION_1005_RELEASE,

CURRENT_FORMAT_VERSION = FORMAT_VERSION_1103_RELEASE
CURRENT_FORMAT_VERSION = FORMAT_VERSION_1104_RELEASE
};

0 comments on commit fb4790a

Please sign in to comment.