mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
[Tweak] Use unique_ptr for map header in pregame
This commit is contained in:
@ -131,10 +131,10 @@ void setPlayer(PlayerSettings &pset, ui8 player, const std::map<ui8, std::string
|
|||||||
playerColor = pset.color;
|
playerColor = pset.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateStartInfo(std::string filename, StartInfo & sInfo, const CMapHeader * mapHeader, const std::map<ui8, std::string> &playerNames)
|
void updateStartInfo(std::string filename, StartInfo & sInfo, const std::unique_ptr<CMapHeader> & mapHeader, const std::map<ui8, std::string> &playerNames)
|
||||||
{
|
{
|
||||||
sInfo.playerInfos.clear();
|
sInfo.playerInfos.clear();
|
||||||
if(!mapHeader)
|
if(!mapHeader.get())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -799,7 +799,12 @@ void CSelectionScreen::changeSelection(const CMapInfo * to)
|
|||||||
SEL->sInfo.difficulty = to->scenarioOpts->difficulty;
|
SEL->sInfo.difficulty = to->scenarioOpts->difficulty;
|
||||||
if(screenType != CMenuScreen::campaignList)
|
if(screenType != CMenuScreen::campaignList)
|
||||||
{
|
{
|
||||||
updateStartInfo(to ? to->fileURI : "", sInfo, to ? to->mapHeader.get() : nullptr);
|
std::unique_ptr<CMapHeader> emptyHeader;
|
||||||
|
if(to)
|
||||||
|
updateStartInfo(to->fileURI, sInfo, to->mapHeader);
|
||||||
|
else
|
||||||
|
updateStartInfo("", sInfo, emptyHeader);
|
||||||
|
|
||||||
if(screenType == CMenuScreen::newGame)
|
if(screenType == CMenuScreen::newGame)
|
||||||
{
|
{
|
||||||
if(to && to->isRandomMap)
|
if(to && to->isRandomMap)
|
||||||
@ -3219,7 +3224,7 @@ void CHotSeatPlayers::enterSelectionScreen()
|
|||||||
void CBonusSelection::init()
|
void CBonusSelection::init()
|
||||||
{
|
{
|
||||||
highlightedRegion = nullptr;
|
highlightedRegion = nullptr;
|
||||||
ourHeader = nullptr;
|
ourHeader.reset();
|
||||||
diffLb = nullptr;
|
diffLb = nullptr;
|
||||||
diffRb = nullptr;
|
diffRb = nullptr;
|
||||||
bonuses = nullptr;
|
bonuses = nullptr;
|
||||||
@ -3342,7 +3347,6 @@ CBonusSelection::CBonusSelection(const std::string & campaignFName)
|
|||||||
CBonusSelection::~CBonusSelection()
|
CBonusSelection::~CBonusSelection()
|
||||||
{
|
{
|
||||||
SDL_FreeSurface(background);
|
SDL_FreeSurface(background);
|
||||||
delete ourHeader;
|
|
||||||
sFlags->unload();
|
sFlags->unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3423,10 +3427,9 @@ void CBonusSelection::selectMap(int mapNr, bool initialSelect)
|
|||||||
scenarioName += ':' + boost::lexical_cast<std::string>(selectedMap);
|
scenarioName += ':' + boost::lexical_cast<std::string>(selectedMap);
|
||||||
|
|
||||||
//get header
|
//get header
|
||||||
delete ourHeader;
|
|
||||||
std::string & headerStr = ourCampaign->camp->mapPieces.find(mapNr)->second;
|
std::string & headerStr = ourCampaign->camp->mapPieces.find(mapNr)->second;
|
||||||
auto buffer = reinterpret_cast<const ui8 *>(headerStr.data());
|
auto buffer = reinterpret_cast<const ui8 *>(headerStr.data());
|
||||||
ourHeader = CMapService::loadMapHeader(buffer, headerStr.size(), scenarioName).release();
|
ourHeader = CMapService::loadMapHeader(buffer, headerStr.size(), scenarioName);
|
||||||
|
|
||||||
std::map<ui8, std::string> names;
|
std::map<ui8, std::string> names;
|
||||||
names[1] = settings["general"]["playerName"].String();
|
names[1] = settings["general"]["playerName"].String();
|
||||||
@ -3922,7 +3925,7 @@ ISelectionScreenInfo::~ISelectionScreenInfo()
|
|||||||
SEL = nullptr;
|
SEL = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ISelectionScreenInfo::updateStartInfo(std::string filename, StartInfo & sInfo, const CMapHeader * mapHeader)
|
void ISelectionScreenInfo::updateStartInfo(std::string filename, StartInfo & sInfo, const std::unique_ptr<CMapHeader> & mapHeader)
|
||||||
{
|
{
|
||||||
::updateStartInfo(filename, sInfo, mapHeader, playerNames);
|
::updateStartInfo(filename, sInfo, mapHeader, playerNames);
|
||||||
}
|
}
|
||||||
|
@ -341,7 +341,7 @@ public:
|
|||||||
virtual void postChatMessage(const std::string &txt){};
|
virtual void postChatMessage(const std::string &txt){};
|
||||||
|
|
||||||
void setPlayer(PlayerSettings &pset, ui8 player);
|
void setPlayer(PlayerSettings &pset, ui8 player);
|
||||||
void updateStartInfo( std::string filename, StartInfo & sInfo, const CMapHeader * mapHeader );
|
void updateStartInfo(std::string filename, StartInfo & sInfo, const std::unique_ptr<CMapHeader> & mapHeader);
|
||||||
|
|
||||||
ui8 getIdOfFirstUnallocatedPlayer(); //returns 0 if none
|
ui8 getIdOfFirstUnallocatedPlayer(); //returns 0 if none
|
||||||
bool isGuest() const;
|
bool isGuest() const;
|
||||||
@ -539,7 +539,7 @@ private:
|
|||||||
int selectedMap;
|
int selectedMap;
|
||||||
boost::optional<int> selectedBonus;
|
boost::optional<int> selectedBonus;
|
||||||
StartInfo startInfo;
|
StartInfo startInfo;
|
||||||
CMapHeader * ourHeader;
|
std::unique_ptr<CMapHeader> ourHeader;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Campaign selection screen
|
/// Campaign selection screen
|
||||||
|
Reference in New Issue
Block a user