Skip to content

Commit

Permalink
C4Landscape::DrawMap: Use std::optional instead of std::unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
Fulgen301 committed Nov 26, 2024
1 parent 365dc44 commit 9f72c9b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/C4Landscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2659,16 +2659,20 @@ bool C4Landscape::DrawMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, co
FakeLS.MapWdt.Set(iMapWdt, 0, iMapWdt, iMapWdt);
FakeLS.MapHgt.Set(iMapHgt, 0, iMapHgt, iMapHgt);
// create map creator
std::unique_ptr<C4MapCreatorS2> MapCreator;
std::optional<C4MapCreatorS2> mapCreator;
// If KeepMapCreator=1 we copy the existing creator to gain access to the named overlays
if (!pMapCreator)
MapCreator = std::make_unique<C4MapCreatorS2>(&FakeLS, &Game.TextureMap, &Game.Material, Game.Parameters.StartupPlayerCount);
if (pMapCreator)
{
mapCreator.emplace(*pMapCreator, &FakeLS);
}
else
MapCreator = std::make_unique<C4MapCreatorS2>(*pMapCreator, &FakeLS);
{
mapCreator.emplace(&FakeLS, &Game.TextureMap, &Game.Material, Game.Parameters.StartupPlayerCount);
}
// read file
MapCreator->ReadScript(szMapDef);
mapCreator->ReadScript(szMapDef);
// render map
CSurface8 *sfcMap = MapCreator->Render(nullptr);
CSurface8 *sfcMap = mapCreator->Render(nullptr);
if (!sfcMap) return false;
// map it to the landscape
bool fSuccess = MapToLandscape(sfcMap, 0, 0, iMapWdt, iMapHgt, iX, iY);
Expand Down

0 comments on commit 9f72c9b

Please sign in to comment.