diff --git a/src/graphics/engine/pyro.h b/src/graphics/engine/pyro.h index 1250537a..06f09e3d 100644 --- a/src/graphics/engine/pyro.h +++ b/src/graphics/engine/pyro.h @@ -27,7 +27,6 @@ #include "common/event.h" #include "common/global.h" -#include "common/make_unique.h" #include "graphics/core/color.h" #include "graphics/engine/pyro_type.h" diff --git a/src/object/auto/auto.cpp b/src/object/auto/auto.cpp index dc8025bb..764938a9 100644 --- a/src/object/auto/auto.cpp +++ b/src/object/auto/auto.cpp @@ -23,6 +23,7 @@ #include "app/app.h" #include "common/event.h" +#include "common/make_unique.h" #include "object/level/parserline.h" #include "object/level/parserparam.h" @@ -419,11 +420,11 @@ void CAuto::SetMotor(bool bMotor) bool CAuto::Write(CLevelParserLine* line) { - line->AddParam("aType", CLevelParserParamUPtr{new CLevelParserParam(m_type)}); - line->AddParam("aBusy", CLevelParserParamUPtr{new CLevelParserParam(m_bBusy)}); - line->AddParam("aTime", CLevelParserParamUPtr{new CLevelParserParam(m_time)}); - line->AddParam("aProgressTime", CLevelParserParamUPtr{new CLevelParserParam(m_progressTime)}); - line->AddParam("aProgressTotal", CLevelParserParamUPtr{new CLevelParserParam(m_progressTotal)}); + line->AddParam("aType", MakeUnique(m_type)); + line->AddParam("aBusy", MakeUnique(m_bBusy)); + line->AddParam("aTime", MakeUnique(m_time)); + line->AddParam("aProgressTime", MakeUnique(m_progressTime)); + line->AddParam("aProgressTotal", MakeUnique(m_progressTotal)); return false; } diff --git a/src/object/auto/autoconvert.cpp b/src/object/auto/autoconvert.cpp index db188dab..37047a2f 100644 --- a/src/object/auto/autoconvert.cpp +++ b/src/object/auto/autoconvert.cpp @@ -20,6 +20,8 @@ #include "object/auto/autoconvert.h" +#include "common/make_unique.h" + #include "math/geometry.h" #include "object/object_manager.h" @@ -359,11 +361,11 @@ bool CAutoConvert::Write(CLevelParserLine* line) if ( m_phase == ACP_STOP || m_phase == ACP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); return true; } diff --git a/src/object/auto/autoderrick.cpp b/src/object/auto/autoderrick.cpp index af1062f1..a9d4f3a7 100644 --- a/src/object/auto/autoderrick.cpp +++ b/src/object/auto/autoderrick.cpp @@ -20,6 +20,8 @@ #include "object/auto/autoderrick.h" +#include "common/make_unique.h" + #include "graphics/engine/terrain.h" #include "math/geometry.h" @@ -428,11 +430,11 @@ bool CAutoDerrick::Write(CLevelParserLine* line) { if ( m_phase == ADP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); return true; } diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp index c29af5d1..ed299072 100644 --- a/src/object/auto/autodestroyer.cpp +++ b/src/object/auto/autodestroyer.cpp @@ -20,6 +20,8 @@ #include "object/auto/autodestroyer.h" +#include "common/make_unique.h" + #include "graphics/engine/pyro_manager.h" #include "object/object_manager.h" @@ -352,11 +354,11 @@ bool CAutoDestroyer::Write(CLevelParserLine* line) { if ( m_phase == ADEP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); return true; } diff --git a/src/object/auto/autoegg.cpp b/src/object/auto/autoegg.cpp index 1e95ff9e..7f51a76b 100644 --- a/src/object/auto/autoegg.cpp +++ b/src/object/auto/autoegg.cpp @@ -20,6 +20,8 @@ #include "object/auto/autoegg.h" +#include "common/make_unique.h" + #include "graphics/engine/pyro_manager.h" #include "math/geometry.h" @@ -300,14 +302,14 @@ bool CAutoEgg::Write(CLevelParserLine* line) { if ( m_phase == AEP_NULL ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); - line->AddParam("aParamType", CLevelParserParamUPtr{new CLevelParserParam(m_type)}); - line->AddParam("aParamValue1", CLevelParserParamUPtr{new CLevelParserParam(m_value)}); - line->AddParam("aParamString", CLevelParserParamUPtr{new CLevelParserParam(m_alienProgramName)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); + line->AddParam("aParamType", MakeUnique(m_type)); + line->AddParam("aParamValue1", MakeUnique(m_value)); + line->AddParam("aParamString", MakeUnique(m_alienProgramName)); return true; } diff --git a/src/object/auto/autofactory.cpp b/src/object/auto/autofactory.cpp index b8006d38..37e4a4af 100644 --- a/src/object/auto/autofactory.cpp +++ b/src/object/auto/autofactory.cpp @@ -21,6 +21,7 @@ #include "object/auto/autofactory.h" #include "common/global.h" +#include "common/make_unique.h" #include "math/geometry.h" @@ -521,11 +522,11 @@ bool CAutoFactory::Write(CLevelParserLine* line) { if ( m_phase == AFP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); return true; } diff --git a/src/object/auto/autolabo.cpp b/src/object/auto/autolabo.cpp index b73814c9..48312c09 100644 --- a/src/object/auto/autolabo.cpp +++ b/src/object/auto/autolabo.cpp @@ -21,6 +21,7 @@ #include "object/auto/autolabo.h" #include "common/global.h" +#include "common/make_unique.h" #include "common/misc.h" #include "math/geometry.h" @@ -563,12 +564,12 @@ bool CAutoLabo::Write(CLevelParserLine* line) { if ( m_phase == ALAP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); - line->AddParam("aResearch", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_research))}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); + line->AddParam("aResearch", MakeUnique(static_cast(m_research))); return true; } diff --git a/src/object/auto/automush.cpp b/src/object/auto/automush.cpp index 479d0d4d..6ed8237e 100644 --- a/src/object/auto/automush.cpp +++ b/src/object/auto/automush.cpp @@ -20,6 +20,8 @@ #include "object/auto/automush.h" +#include "common/make_unique.h" + #include "object/object_manager.h" #include "object/old_object.h" #include "object/level/parserline.h" @@ -294,11 +296,11 @@ bool CAutoMush::Write(CLevelParserLine* line) { if ( m_phase == AMP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); return true; } diff --git a/src/object/auto/autonest.cpp b/src/object/auto/autonest.cpp index 03e3f144..918e1bf2 100644 --- a/src/object/auto/autonest.cpp +++ b/src/object/auto/autonest.cpp @@ -20,6 +20,8 @@ #include "object/auto/autonest.h" +#include "common/make_unique.h" + #include "graphics/engine/terrain.h" #include "object/object_manager.h" @@ -209,11 +211,11 @@ bool CAutoNest::Write(CLevelParserLine* line) { if ( m_phase == ANP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); return true; } diff --git a/src/object/auto/autonuclearplant.cpp b/src/object/auto/autonuclearplant.cpp index 298ae6a9..1f636a87 100644 --- a/src/object/auto/autonuclearplant.cpp +++ b/src/object/auto/autonuclearplant.cpp @@ -20,6 +20,8 @@ #include "object/auto/autonuclearplant.h" +#include "common/make_unique.h" + #include "math/geometry.h" #include "object/object_manager.h" @@ -426,11 +428,11 @@ bool CAutoNuclearPlant::Write(CLevelParserLine* line) if ( m_phase == ANUP_STOP || m_phase == ANUP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); return true; } diff --git a/src/object/auto/autopowercaptor.cpp b/src/object/auto/autopowercaptor.cpp index fd32662f..4faeba11 100644 --- a/src/object/auto/autopowercaptor.cpp +++ b/src/object/auto/autopowercaptor.cpp @@ -20,6 +20,7 @@ #include "object/auto/autopowercaptor.h" +#include "common/make_unique.h" #include "math/geometry.h" @@ -291,11 +292,11 @@ bool CAutoPowerCaptor::Write(CLevelParserLine* line) { if ( m_phase == APAP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); return true; } diff --git a/src/object/auto/autopowerplant.cpp b/src/object/auto/autopowerplant.cpp index cee7bee4..8f11d248 100644 --- a/src/object/auto/autopowerplant.cpp +++ b/src/object/auto/autopowerplant.cpp @@ -20,6 +20,8 @@ #include "object/auto/autopowerplant.h" +#include "common/make_unique.h" + #include "graphics/engine/terrain.h" #include "math/geometry.h" @@ -580,11 +582,11 @@ bool CAutoPowerPlant::Write(CLevelParserLine* line) if ( m_phase == AENP_STOP || m_phase == AENP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); return true; } diff --git a/src/object/auto/autorepair.cpp b/src/object/auto/autorepair.cpp index 7d8091a6..f1dd3ec8 100644 --- a/src/object/auto/autorepair.cpp +++ b/src/object/auto/autorepair.cpp @@ -20,6 +20,8 @@ #include "object/auto/autorepair.h" +#include "common/make_unique.h" + #include "object/object_manager.h" #include "object/old_object.h" #include "object/level/parserline.h" @@ -296,11 +298,11 @@ bool CAutoRepair::Write(CLevelParserLine* line) { if ( m_phase == ARP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); return true; } diff --git a/src/object/auto/autoresearch.cpp b/src/object/auto/autoresearch.cpp index 0e403124..b1e12234 100644 --- a/src/object/auto/autoresearch.cpp +++ b/src/object/auto/autoresearch.cpp @@ -21,6 +21,7 @@ #include "object/auto/autoresearch.h" #include "common/global.h" +#include "common/make_unique.h" #include "math/geometry.h" @@ -548,12 +549,12 @@ bool CAutoResearch::Write(CLevelParserLine* line) { if ( m_phase == ALP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); - line->AddParam("aResearch", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_research))}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); + line->AddParam("aResearch", MakeUnique(static_cast(m_research))); return true; } diff --git a/src/object/auto/autotower.cpp b/src/object/auto/autotower.cpp index 15dc82ce..3a36e4fe 100644 --- a/src/object/auto/autotower.cpp +++ b/src/object/auto/autotower.cpp @@ -20,6 +20,8 @@ #include "object/auto/autotower.h" +#include "common/make_unique.h" + #include "math/geometry.h" #include "object/object_manager.h" @@ -468,16 +470,16 @@ bool CAutoTower::Write(CLevelParserLine* line) { if ( m_phase == ATP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); - line->AddParam("aTargetPos", CLevelParserParamUPtr{new CLevelParserParam(m_targetPos)}); - line->AddParam("aAngleYactual", CLevelParserParamUPtr{new CLevelParserParam(m_angleYactual)}); - line->AddParam("aAngleZactual", CLevelParserParamUPtr{new CLevelParserParam(m_angleZactual)}); - line->AddParam("aAngleYfinal", CLevelParserParamUPtr{new CLevelParserParam(m_angleYfinal)}); - line->AddParam("aAngleZfinal", CLevelParserParamUPtr{new CLevelParserParam(m_angleZfinal)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); + line->AddParam("aTargetPos", MakeUnique(m_targetPos)); + line->AddParam("aAngleYactual", MakeUnique(m_angleYactual)); + line->AddParam("aAngleZactual", MakeUnique(m_angleZactual)); + line->AddParam("aAngleYfinal", MakeUnique(m_angleYfinal)); + line->AddParam("aAngleZfinal", MakeUnique(m_angleZfinal)); return true; } diff --git a/src/object/auto/autovault.cpp b/src/object/auto/autovault.cpp index 32984328..c5dfde60 100644 --- a/src/object/auto/autovault.cpp +++ b/src/object/auto/autovault.cpp @@ -20,6 +20,8 @@ #include "object/auto/autovault.h" +#include "common/make_unique.h" + #include "math/geometry.h" #include "object/object_manager.h" @@ -350,11 +352,11 @@ bool CAutoVault::Write(CLevelParserLine* line) { if ( m_phase == ASAP_WAIT ) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); return true; } diff --git a/src/object/brain.cpp b/src/object/brain.cpp index fe8e6b36..cfcd0acc 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -167,11 +167,11 @@ void CBrain::SetMotion(CMotion* motion) bool CBrain::Write(CLevelParserLine* line) { - line->AddParam("bVirusActive", CLevelParserParamUPtr{new CLevelParserParam(m_bActiveVirus)}); + line->AddParam("bVirusActive", MakeUnique(m_bActiveVirus)); if ( m_object->GetType() == OBJECT_MOBILErs ) { - line->AddParam("bShieldActive", CLevelParserParamUPtr{new CLevelParserParam(m_secondaryTask != nullptr)}); + line->AddParam("bShieldActive", MakeUnique(m_secondaryTask != nullptr)); } return true; diff --git a/src/object/level/parser.cpp b/src/object/level/parser.cpp index 0a663903..5a38e71d 100644 --- a/src/object/level/parser.cpp +++ b/src/object/level/parser.cpp @@ -22,6 +22,7 @@ #include "app/app.h" +#include "common/make_unique.h" #include "common/resources/resourcemanager.h" #include "common/resources/inputstream.h" #include "common/resources/outputstream.h" @@ -168,7 +169,7 @@ void CLevelParser::Load() if (command.empty()) continue; - CLevelParserLineUPtr parserLine{new CLevelParserLine(lineNumber, command)}; + auto parserLine = MakeUnique(lineNumber, command); if (command.length() > 2 && command[command.length() - 2] == '.') { @@ -239,7 +240,7 @@ void CLevelParser::Load() std::string paramValue = line.substr(0, pos + 1); boost::algorithm::trim(paramValue); - parserLine->AddParam(paramName, CLevelParserParamUPtr{new CLevelParserParam(paramName, paramValue)}); + parserLine->AddParam(paramName, MakeUnique(paramName, paramValue)); if (pos == std::string::npos) break; diff --git a/src/object/level/parserline.cpp b/src/object/level/parserline.cpp index aa34b95d..cdf11cea 100644 --- a/src/object/level/parserline.cpp +++ b/src/object/level/parserline.cpp @@ -19,8 +19,10 @@ #include "object/level/parserline.h" -#include "object/level/parser.h" #include "common/logger.h" +#include "common/make_unique.h" + +#include "object/level/parser.h" CLevelParserLine::CLevelParserLine(std::string command) { @@ -67,7 +69,7 @@ CLevelParserParam* CLevelParserLine::GetParam(std::string name) return it->second.get(); } - CLevelParserParamUPtr paramUPtr(new CLevelParserParam(name, true)); + auto paramUPtr = MakeUnique(name, true); paramUPtr->SetLine(this); CLevelParserParam* paramPtr = paramUPtr.get(); m_params.insert(std::make_pair(name, std::move(paramUPtr))); diff --git a/src/object/level/parserparam.cpp b/src/object/level/parserparam.cpp index 97298cc9..06463e5d 100644 --- a/src/object/level/parserparam.cpp +++ b/src/object/level/parserparam.cpp @@ -22,6 +22,7 @@ #include "app/app.h" #include "common/logger.h" +#include "common/make_unique.h" #include "common/pathman.h" #include "common/resources/resourcemanager.h" @@ -61,27 +62,27 @@ CLevelParserParam::CLevelParserParam(bool value) CLevelParserParam::CLevelParserParam(Gfx::Color value) { - m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.r)}); - m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.g)}); - m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.b)}); - m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.a)}); + m_array.push_back(MakeUnique(value.r)); + m_array.push_back(MakeUnique(value.g)); + m_array.push_back(MakeUnique(value.b)); + m_array.push_back(MakeUnique(value.a)); LoadArray(); } CLevelParserParam::CLevelParserParam(Math::Point value) { - m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.x)}); - m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.y)}); + m_array.push_back(MakeUnique(value.x)); + m_array.push_back(MakeUnique(value.y)); LoadArray(); } CLevelParserParam::CLevelParserParam(Math::Vector value) { - m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.x)}); - m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.y)}); - m_array.push_back(CLevelParserParamUPtr{new CLevelParserParam(value.z)}); + m_array.push_back(MakeUnique(value.x)); + m_array.push_back(MakeUnique(value.y)); + m_array.push_back(MakeUnique(value.z)); LoadArray(); } @@ -905,7 +906,7 @@ void CLevelParserParam::ParseArray() { boost::algorithm::trim(value); if (value.empty()) continue; - CLevelParserParamUPtr param{new CLevelParserParam(m_name + "[" + boost::lexical_cast(i) + "]", value)}; + auto param = MakeUnique(m_name + "[" + boost::lexical_cast(i) + "]", value); param->SetLine(m_line); m_array.push_back(std::move(param)); i++; diff --git a/src/object/motion/motion.cpp b/src/object/motion/motion.cpp index 1d801ffe..2c483103 100644 --- a/src/object/motion/motion.cpp +++ b/src/object/motion/motion.cpp @@ -22,6 +22,8 @@ #include "app/app.h" +#include "common/make_unique.h" + #include "object/robotmain.h" #include "object/old_object.h" #include "object/level/parserline.h" @@ -162,9 +164,9 @@ bool CMotion::Write(CLevelParserLine* line) { if ( m_actionType == -1 ) return false; - line->AddParam("mType", CLevelParserParamUPtr{new CLevelParserParam(m_actionType)}); - line->AddParam("mTime", CLevelParserParamUPtr{new CLevelParserParam(m_actionTime)}); - line->AddParam("mProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); + line->AddParam("mType", MakeUnique(m_actionType)); + line->AddParam("mTime", MakeUnique(m_actionTime)); + line->AddParam("mProgress", MakeUnique(m_progress)); return false; } diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index 3ff19275..d1e55ed0 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -886,78 +886,78 @@ void COldObject::Write(CLevelParserLine* line) { Math::Vector pos; - line->AddParam("camera", CLevelParserParamUPtr{new CLevelParserParam(GetCameraType())}); + line->AddParam("camera", MakeUnique(GetCameraType())); if ( GetCameraLock() ) - line->AddParam("cameraLock", CLevelParserParamUPtr{new CLevelParserParam(GetCameraLock())}); + line->AddParam("cameraLock", MakeUnique(GetCameraLock())); if ( GetEnergy() != 0.0f ) - line->AddParam("energy", CLevelParserParamUPtr{new CLevelParserParam(GetEnergy())}); + line->AddParam("energy", MakeUnique(GetEnergy())); if ( GetCapacity() != 1.0f ) - line->AddParam("capacity", CLevelParserParamUPtr{new CLevelParserParam(GetCapacity())}); + line->AddParam("capacity", MakeUnique(GetCapacity())); if ( GetShield() != 1.0f ) - line->AddParam("shield", CLevelParserParamUPtr{new CLevelParserParam(GetShield())}); + line->AddParam("shield", MakeUnique(GetShield())); if ( GetRange() != 1.0f ) - line->AddParam("range", CLevelParserParamUPtr{new CLevelParserParam(GetRange())}); + line->AddParam("range", MakeUnique(GetRange())); if ( !GetSelectable() ) - line->AddParam("selectable", CLevelParserParamUPtr{new CLevelParserParam(GetSelectable())}); + line->AddParam("selectable", MakeUnique(GetSelectable())); if ( !GetEnable() ) - line->AddParam("enable", CLevelParserParamUPtr{new CLevelParserParam(GetEnable())}); + line->AddParam("enable", MakeUnique(GetEnable())); // TODO: doesn't seem to be used if ( GetFixed() ) - line->AddParam("fixed", CLevelParserParamUPtr{new CLevelParserParam(GetFixed())}); + line->AddParam("fixed", MakeUnique(GetFixed())); if ( !GetClip() ) - line->AddParam("clip", CLevelParserParamUPtr{new CLevelParserParam(GetClip())}); + line->AddParam("clip", MakeUnique(GetClip())); if ( GetLock() ) - line->AddParam("lock", CLevelParserParamUPtr{new CLevelParserParam(GetLock())}); + line->AddParam("lock", MakeUnique(GetLock())); if ( GetProxyActivate() ) { - line->AddParam("proxyActivate", CLevelParserParamUPtr{new CLevelParserParam(GetProxyActivate())}); - line->AddParam("proxyDistance", CLevelParserParamUPtr{new CLevelParserParam(GetProxyDistance()/g_unit)}); + line->AddParam("proxyActivate", MakeUnique(GetProxyActivate())); + line->AddParam("proxyDistance", MakeUnique(GetProxyDistance()/g_unit)); } if ( GetMagnifyDamage() != 1.0f ) - line->AddParam("magnifyDamage", CLevelParserParamUPtr{new CLevelParserParam(GetMagnifyDamage())}); + line->AddParam("magnifyDamage", MakeUnique(GetMagnifyDamage())); if ( GetTeam() != 0 ) - line->AddParam("team", CLevelParserParamUPtr{new CLevelParserParam(GetTeam())}); + line->AddParam("team", MakeUnique(GetTeam())); if ( GetGunGoalV() != 0.0f ) - line->AddParam("aimV", CLevelParserParamUPtr{new CLevelParserParam(GetGunGoalV())}); + line->AddParam("aimV", MakeUnique(GetGunGoalV())); if ( GetGunGoalH() != 0.0f ) - line->AddParam("aimH", CLevelParserParamUPtr{new CLevelParserParam(GetGunGoalH())}); + line->AddParam("aimH", MakeUnique(GetGunGoalH())); if ( GetAnimateOnReset() ) { - line->AddParam("resetCap", CLevelParserParamUPtr{new CLevelParserParam(GetAnimateOnReset())}); + line->AddParam("resetCap", MakeUnique(GetAnimateOnReset())); } if ( m_bVirusMode ) - line->AddParam("virusMode", CLevelParserParamUPtr{new CLevelParserParam(m_bVirusMode)}); + line->AddParam("virusMode", MakeUnique(m_bVirusMode)); if ( m_virusTime != 0.0f ) - line->AddParam("virusTime", CLevelParserParamUPtr{new CLevelParserParam(m_virusTime)}); + line->AddParam("virusTime", MakeUnique(m_virusTime)); - line->AddParam("ignoreBuildCheck", CLevelParserParamUPtr{new CLevelParserParam(GetIgnoreBuildCheck())}); + line->AddParam("ignoreBuildCheck", MakeUnique(GetIgnoreBuildCheck())); // Sets the parameters of the command line. CLevelParserParamVec cmdline; for(float value : m_cmdLine) { - cmdline.push_back(CLevelParserParamUPtr{new CLevelParserParam(value)}); + cmdline.push_back(MakeUnique(value)); } if (cmdline.size() > 0) - line->AddParam("cmdline", CLevelParserParamUPtr{new CLevelParserParam(std::move(cmdline))}); + line->AddParam("cmdline", MakeUnique(std::move(cmdline))); if ( m_motion != nullptr ) { diff --git a/src/object/old_object.h b/src/object/old_object.h index 41834d0d..a8164b94 100644 --- a/src/object/old_object.h +++ b/src/object/old_object.h @@ -26,8 +26,6 @@ #include "object/object.h" -#include "common/make_unique.h" - #include "object/interface/carrier_object.h" #include "object/interface/interactive_object.h" #include "object/interface/jostleable_object.h" diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 5cd6b40d..3f25680c 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -914,9 +914,9 @@ bool CRobotMain::ProcessEvent(Event &event) if (obj != nullptr) { CLevelParserLine line("CreateObject"); - line.AddParam("type", CLevelParserParamUPtr{new CLevelParserParam(obj->GetType())}); - line.AddParam("pos", CLevelParserParamUPtr{new CLevelParserParam(obj->GetPosition())}); - line.AddParam("dir", CLevelParserParamUPtr{new CLevelParserParam(obj->GetRotationZ()/(Math::PI/180.0f))}); + line.AddParam("type", MakeUnique(obj->GetType())); + line.AddParam("pos", MakeUnique(obj->GetPosition())); + line.AddParam("dir", MakeUnique(obj->GetRotationZ()/(Math::PI/180.0f))); std::stringstream ss; ss << line; @@ -4824,11 +4824,11 @@ void CRobotMain::IOWriteObject(CLevelParserLine* line, CObject* obj) { if (obj->GetType() == OBJECT_FIX) return; - line->AddParam("type", CLevelParserParamUPtr{new CLevelParserParam(obj->GetType())}); - line->AddParam("id", CLevelParserParamUPtr{new CLevelParserParam(obj->GetID())}); - line->AddParam("pos", CLevelParserParamUPtr{new CLevelParserParam(obj->GetPosition()/g_unit)}); - line->AddParam("angle", CLevelParserParamUPtr{new CLevelParserParam(obj->GetRotation() * Math::RAD_TO_DEG)}); - line->AddParam("zoom", CLevelParserParamUPtr{new CLevelParserParam(obj->GetScale())}); + line->AddParam("type", MakeUnique(obj->GetType())); + line->AddParam("id", MakeUnique(obj->GetID())); + line->AddParam("pos", MakeUnique(obj->GetPosition()/g_unit)); + line->AddParam("angle", MakeUnique(obj->GetRotation() * Math::RAD_TO_DEG)); + line->AddParam("zoom", MakeUnique(obj->GetScale())); if (obj->Implements(ObjectInterfaceType::Old)) { @@ -4842,34 +4842,34 @@ void CRobotMain::IOWriteObject(CLevelParserLine* line, CObject* obj) if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f) { pos /= g_unit; - line->AddParam("p" + boost::lexical_cast(i), CLevelParserParamUPtr{new CLevelParserParam(pos)}); + line->AddParam("p" + boost::lexical_cast(i), MakeUnique(pos)); } Math::Vector rot = oldObj->GetPartRotation(i); if (rot.x != 0.0f || rot.y != 0.0f || rot.z != 0.0f) { rot /= (Math::PI/180.0f); - line->AddParam("a" + boost::lexical_cast(i), CLevelParserParamUPtr{new CLevelParserParam(rot)}); + line->AddParam("a" + boost::lexical_cast(i), MakeUnique(rot)); } Math::Vector scale = oldObj->GetPartScale(i); if (scale.x != 1.0f || scale.y != 1.0f || scale.z != 1.0f) { - line->AddParam("z" + boost::lexical_cast(i), CLevelParserParamUPtr{new CLevelParserParam(scale)}); + line->AddParam("z" + boost::lexical_cast(i), MakeUnique(scale)); } } - line->AddParam("trainer", CLevelParserParamUPtr{new CLevelParserParam(obj->GetTrainer())}); - line->AddParam("option", CLevelParserParamUPtr{new CLevelParserParam(obj->GetOption())}); + line->AddParam("trainer", MakeUnique(obj->GetTrainer())); + line->AddParam("option", MakeUnique(obj->GetOption())); } if (obj == m_infoObject) - line->AddParam("select", CLevelParserParamUPtr{new CLevelParserParam(1)}); + line->AddParam("select", MakeUnique(1)); obj->Write(line); if (obj->GetType() == OBJECT_BASE) - line->AddParam("run", CLevelParserParamUPtr{new CLevelParserParam(3)}); // stops and open (PARAM_FIXSCENE) + line->AddParam("run", MakeUnique(3)); // stops and open (PARAM_FIXSCENE) if (obj->Implements(ObjectInterfaceType::Programmable)) { @@ -4878,7 +4878,7 @@ void CRobotMain::IOWriteObject(CLevelParserLine* line, CObject* obj) int run = brain->GetProgram(); if (run != -1) { - line->AddParam("run", CLevelParserParamUPtr{new CLevelParserParam(run+1)}); + line->AddParam("run", MakeUnique(run+1)); } auto& programs = brain->GetPrograms(); @@ -4886,7 +4886,7 @@ void CRobotMain::IOWriteObject(CLevelParserLine* line, CObject* obj) { if (programs[i]->readOnly) { - line->AddParam("scriptReadOnly" + boost::lexical_cast(i+1), CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("scriptReadOnly" + boost::lexical_cast(i+1), MakeUnique(true)); } } } @@ -4898,48 +4898,48 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char * CLevelParser levelParser(filename); CLevelParserLineUPtr line; - line.reset(new CLevelParserLine("Title")); - line->AddParam("text", CLevelParserParamUPtr{new CLevelParserParam(std::string(info))}); + line = MakeUnique("Title"); + line->AddParam("text", MakeUnique(std::string(info))); levelParser.AddLine(std::move(line)); //TODO: Do we need that? It's not used anyway - line.reset(new CLevelParserLine("Version")); - line->AddParam("maj", CLevelParserParamUPtr{new CLevelParserParam(0)}); - line->AddParam("min", CLevelParserParamUPtr{new CLevelParserParam(1)}); + line = MakeUnique("Version"); + line->AddParam("maj", MakeUnique(0)); + line->AddParam("min", MakeUnique(1)); levelParser.AddLine(std::move(line)); - line.reset(new CLevelParserLine("Created")); - line->AddParam("date", CLevelParserParamUPtr{new CLevelParserParam(GetCurrentTimestamp())}); + line = MakeUnique("Created"); + line->AddParam("date", MakeUnique(GetCurrentTimestamp())); levelParser.AddLine(std::move(line)); char* name = m_dialog->GetSceneName(); - line.reset(new CLevelParserLine("Mission")); - line->AddParam("base", CLevelParserParamUPtr{new CLevelParserParam(std::string(name))}); - line->AddParam("rank", CLevelParserParamUPtr{new CLevelParserParam(m_dialog->GetSceneRank())}); + line = MakeUnique("Mission"); + line->AddParam("base", MakeUnique(std::string(name))); + line->AddParam("rank", MakeUnique(m_dialog->GetSceneRank())); if (std::string(name) == "custom") { - line->AddParam("dir", CLevelParserParamUPtr{new CLevelParserParam(std::string(m_dialog->GetSceneDir()))}); + line->AddParam("dir", MakeUnique(std::string(m_dialog->GetSceneDir()))); } levelParser.AddLine(std::move(line)); - line.reset(new CLevelParserLine("Map")); - line->AddParam("zoom", CLevelParserParamUPtr{new CLevelParserParam(m_map->GetZoomMap())}); + line = MakeUnique("Map"); + line->AddParam("zoom", MakeUnique(m_map->GetZoomMap())); levelParser.AddLine(std::move(line)); - line.reset(new CLevelParserLine("DoneResearch")); - line->AddParam("bits", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_researchDone[0]))}); + line = MakeUnique("DoneResearch"); + line->AddParam("bits", MakeUnique(static_cast(m_researchDone[0]))); levelParser.AddLine(std::move(line)); float sleep, delay, magnetic, progress; if (m_lightning->GetStatus(sleep, delay, magnetic, progress)) { - line.reset(new CLevelParserLine("BlitzMode")); - line->AddParam("sleep", CLevelParserParamUPtr{new CLevelParserParam(sleep)}); - line->AddParam("delay", CLevelParserParamUPtr{new CLevelParserParam(delay)}); - line->AddParam("magnetic", CLevelParserParamUPtr{new CLevelParserParam(magnetic/g_unit)}); - line->AddParam("progress", CLevelParserParamUPtr{new CLevelParserParam(progress)}); + line = MakeUnique("BlitzMode"); + line->AddParam("sleep", MakeUnique(sleep)); + line->AddParam("delay", MakeUnique(delay)); + line->AddParam("magnetic", MakeUnique(magnetic/g_unit)); + line->AddParam("progress", MakeUnique(progress)); levelParser.AddLine(std::move(line)); } @@ -4959,7 +4959,7 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char * CObject* cargo = dynamic_cast(obj)->GetCargo(); if (cargo != nullptr) // object transported? { - line.reset(new CLevelParserLine("CreateFret")); + line = MakeUnique("CreateFret"); IOWriteObject(line.get(), cargo); levelParser.AddLine(std::move(line)); } @@ -4970,14 +4970,14 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char * CObject* power = dynamic_cast(obj)->GetPower(); if (power != nullptr) // battery transported? { - line.reset(new CLevelParserLine("CreatePower")); + line = MakeUnique("CreatePower"); IOWriteObject(line.get(), power); levelParser.AddLine(std::move(line)); } } - line.reset(new CLevelParserLine("CreateObject")); + line = MakeUnique("CreateObject"); IOWriteObject(line.get(), obj); levelParser.AddLine(std::move(line)); diff --git a/src/object/subclass/exchange_post.cpp b/src/object/subclass/exchange_post.cpp index 5ed2fb64..e7d37928 100644 --- a/src/object/subclass/exchange_post.cpp +++ b/src/object/subclass/exchange_post.cpp @@ -197,7 +197,7 @@ void CExchangePost::Write(CLevelParserLine* line) { auto key = "info" + boost::lexical_cast(i); auto paramValue = info.name + "=" + boost::lexical_cast(info.value); - line->AddParam(key, CLevelParserParamUPtr{new CLevelParserParam(paramValue)}); + line->AddParam(key, MakeUnique(paramValue)); } } } @@ -656,11 +656,11 @@ bool CAutoInfo::Write(CLevelParserLine* line) if (m_phase == Phase::Wait) return false; - line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)}); + line->AddParam("aExist", MakeUnique(true)); CAuto::Write(line); - line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast(m_phase))}); - line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)}); - line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)}); + line->AddParam("aPhase", MakeUnique(static_cast(m_phase))); + line->AddParam("aProgress", MakeUnique(m_progress)); + line->AddParam("aSpeed", MakeUnique(m_speed)); return true; } diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index bb615600..0e732abb 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -24,6 +24,7 @@ #include "common/event.h" #include "common/global.h" +#include "common/make_unique.h" #include "graphics/engine/camera.h" #include "graphics/engine/engine.h" @@ -173,12 +174,12 @@ PhysicsType CPhysics::GetType() bool CPhysics::Write(CLevelParserLine* line) { - line->AddParam("motor", CLevelParserParamUPtr{new CLevelParserParam(m_motorSpeed)}); + line->AddParam("motor", MakeUnique(m_motorSpeed)); if ( m_type == TYPE_FLYING ) { - line->AddParam("reactorRange", CLevelParserParamUPtr{new CLevelParserParam(GetReactorRange())}); - line->AddParam("land", CLevelParserParamUPtr{new CLevelParserParam(GetLand())}); + line->AddParam("reactorRange", MakeUnique(GetReactorRange())); + line->AddParam("land", MakeUnique(GetLand())); } return true; diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index 0c379a62..70af304f 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -28,6 +28,7 @@ #include "common/global.h" #include "common/event.h" #include "common/logger.h" +#include "common/make_unique.h" #include "common/misc.h" #include "common/profile.h" #include "common/restext.h" @@ -6018,15 +6019,15 @@ void CMainDialog::WriteGamerPerso(char *gamer) CLevelParser persoParser(GetSavegameDir()+"/"+gamer+"/face.gam"); CLevelParserLineUPtr line; - line.reset(new CLevelParserLine("Head")); - line->AddParam("face", CLevelParserParamUPtr{new CLevelParserParam(m_perso.face)}); - line->AddParam("glasses", CLevelParserParamUPtr{new CLevelParserParam(m_perso.glasses)}); - line->AddParam("hair", CLevelParserParamUPtr{new CLevelParserParam(m_perso.colorHair)}); + line = MakeUnique("Head"); + line->AddParam("face", MakeUnique(m_perso.face)); + line->AddParam("glasses", MakeUnique(m_perso.glasses)); + line->AddParam("hair", MakeUnique(m_perso.colorHair)); persoParser.AddLine(std::move(line)); - line.reset(new CLevelParserLine("Body")); - line->AddParam("combi", CLevelParserParamUPtr{new CLevelParserParam(m_perso.colorCombi)}); - line->AddParam("band", CLevelParserParamUPtr{new CLevelParserParam(m_perso.colorBand)}); + line = MakeUnique("Body"); + line->AddParam("combi", MakeUnique(m_perso.colorCombi)); + line->AddParam("band", MakeUnique(m_perso.colorBand)); persoParser.AddLine(std::move(line)); persoParser.Save();