Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proper serialization logic for the tile's main object part #9227

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
};
Loading