From 8615da91352475a27f345c94eadcc09da125f277 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 06:17:33 +0000 Subject: [PATCH 1/3] Initial plan From e23e98bb20e07a7786091dc1cf9050e0996e29be Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 06:28:39 +0000 Subject: [PATCH 2/3] Fix deprecated code patterns and modernize C++ usage Co-authored-by: pirx42 <2143008+pirx42@users.noreply.github.com> --- ARSTD/ARSTD/Command/CommandProcessorContext.h | 2 +- ARSTD/ARSTD/Structures/Element.cpp | 4 ++-- CodeSubWars/Source/CSWActiveSonar.cpp | 2 +- CodeSubWars/Source/CSWActiveSonarVisualizer.cpp | 2 +- CodeSubWars/Source/CSWCollideable.cpp | 4 ++-- CodeSubWars/Source/CSWEngine.cpp | 2 +- CodeSubWars/Source/CSWEquipment.cpp | 2 +- CodeSubWars/Source/CSWLog.cpp | 4 ++-- CodeSubWars/Source/CSWMap.cpp | 2 +- CodeSubWars/Source/CSWMapVisualizer.cpp | 2 +- CodeSubWars/Source/CSWMessageCollisionObjects.cpp | 2 +- CodeSubWars/Source/CSWPassiveSonar.cpp | 2 +- CodeSubWars/Source/CSWPassiveSonarVisualizer.cpp | 2 +- CodeSubWars/Source/CSWPythonable.cpp | 2 +- CodeSubWars/Source/CSWSilentApplication.cpp | 5 +++++ CodeSubWars/Source/CSWSubmarine.cpp | 2 +- CodeSubWars/Source/CSWWeapon.cpp | 2 +- CodeSubWars/Source/CSWWeaponBattery.cpp | 2 +- CodeSubWars/Source/CSWWorld.cpp | 2 +- CodeSubWars/Source/CodeSubwarsMainWindow.cpp | 14 +++++++------- CodeSubWars/Source/IO/CSWBRImporter.cpp | 7 +++---- CodeSubWars/Source/InformationView.cpp | 2 +- CodeSubWars/Source/InformationView.h | 2 +- CodeSubWars/Source/NewBattleDialog.h | 2 +- CodeSubWars/Source/PrecompiledHeader.h | 3 ++- CodeSubWars/Source/ReplayDialog.cpp | 2 +- CodeSubWars/Source/ReplayDialog.h | 2 +- CodeSubWars/Source/SceneView.cpp | 2 +- 28 files changed, 44 insertions(+), 39 deletions(-) diff --git a/ARSTD/ARSTD/Command/CommandProcessorContext.h b/ARSTD/ARSTD/Command/CommandProcessorContext.h index 236feb5..3fb4c81 100644 --- a/ARSTD/ARSTD/Command/CommandProcessorContext.h +++ b/ARSTD/ARSTD/Command/CommandProcessorContext.h @@ -31,7 +31,7 @@ namespace ARSTD //adds a command to the end bool addCommand(std::shared_ptr pCommand); - //returns the command the is currently executing. returns NULL if no command is currently executing. + //returns the command the is currently executing. returns nullptr if no command is currently executing. std::shared_ptr getCurrentExecutingCommand() const; //empties the whole context diff --git a/ARSTD/ARSTD/Structures/Element.cpp b/ARSTD/ARSTD/Structures/Element.cpp index f56c385..352570b 100644 --- a/ARSTD/ARSTD/Structures/Element.cpp +++ b/ARSTD/ARSTD/Structures/Element.cpp @@ -13,7 +13,7 @@ namespace ARSTD Element::Element(const std::string& strName) : m_strName(strName), - m_pParent(NULL) + m_pParent(nullptr) { } @@ -68,7 +68,7 @@ namespace ARSTD void Element::resetParent() { - m_pParent = NULL; + m_pParent = nullptr; } diff --git a/CodeSubWars/Source/CSWActiveSonar.cpp b/CodeSubWars/Source/CSWActiveSonar.cpp index cc799dc..3b04a38 100644 --- a/CodeSubWars/Source/CSWActiveSonar.cpp +++ b/CodeSubWars/Source/CSWActiveSonar.cpp @@ -269,7 +269,7 @@ namespace CodeSubWars m_bTargetDetected(false), m_vecTargetPosition(0, 0, 0), m_LastScans(50), - m_pVisualizer(NULL), + m_pVisualizer(nullptr), m_pScanRay(CSWScanRay::create(strName + ".ScanRay", Matrix44D(Vector3D(0, 0, 60)), MAX_DISTANCE - 60)) { attach(m_pScanRay); diff --git a/CodeSubWars/Source/CSWActiveSonarVisualizer.cpp b/CodeSubWars/Source/CSWActiveSonarVisualizer.cpp index 956e9f1..f488df2 100644 --- a/CodeSubWars/Source/CSWActiveSonarVisualizer.cpp +++ b/CodeSubWars/Source/CSWActiveSonarVisualizer.cpp @@ -156,7 +156,7 @@ namespace CodeSubWars CSWActiveSonarVisualizer::CSWActiveSonarVisualizer(QWidget* pParent, CSWActiveSonar::PtrType pActiveSonar) - : QWidget(pParent, NULL) + : QWidget(pParent, nullptr) { QHBoxLayout* pLayout = new QHBoxLayout(this); pLayout->setMargin(1); diff --git a/CodeSubWars/Source/CSWCollideable.cpp b/CodeSubWars/Source/CSWCollideable.cpp index 72de240..6949709 100644 --- a/CodeSubWars/Source/CSWCollideable.cpp +++ b/CodeSubWars/Source/CSWCollideable.cpp @@ -139,7 +139,7 @@ namespace CodeSubWars DT_RemoveObject(CSWWorld::getInstance()->getScene(), m_hDTObject); DT_DestroyObject(m_hDTObject); DT_DeleteShape(m_hDTShape); - m_hDTShape = NULL; + m_hDTShape = nullptr; m_bInitialized = false; return true; @@ -150,7 +150,7 @@ namespace CodeSubWars : m_pCollisionMesh(pCollisionMesh), m_BoundingBox(pCollisionMesh->getAxisAlignedBoundingBox()), m_bInitialized(false), - m_hDTShape(NULL), + m_hDTShape(nullptr), m_bHit(false), m_matObjectTCollisionShape(Matrix44D::IDENTITY) { diff --git a/CodeSubWars/Source/CSWEngine.cpp b/CodeSubWars/Source/CSWEngine.cpp index b5dcc31..d380685 100644 --- a/CodeSubWars/Source/CSWEngine.cpp +++ b/CodeSubWars/Source/CSWEngine.cpp @@ -114,7 +114,7 @@ namespace CodeSubWars m_fMaxForce(size.getVolume()*1e+6), m_fIntensity(0), m_bAllowDirectionChanges(bAllowDirectionChanges), - m_pVisualizer(NULL) + m_pVisualizer(nullptr) { } diff --git a/CodeSubWars/Source/CSWEquipment.cpp b/CodeSubWars/Source/CSWEquipment.cpp index f1205c0..c585eb4 100644 --- a/CodeSubWars/Source/CSWEquipment.cpp +++ b/CodeSubWars/Source/CSWEquipment.cpp @@ -105,7 +105,7 @@ namespace CodeSubWars QWidget* CSWEquipment::getInformationWidget(QWidget* pParent) { - return NULL; + return nullptr; } diff --git a/CodeSubWars/Source/CSWLog.cpp b/CodeSubWars/Source/CSWLog.cpp index 3903eb2..e577435 100644 --- a/CodeSubWars/Source/CSWLog.cpp +++ b/CodeSubWars/Source/CSWLog.cpp @@ -32,7 +32,7 @@ namespace CodeSubWars void CSWLog::resetLogOutput() { - m_pTextEdit = NULL; + m_pTextEdit = nullptr; } @@ -50,7 +50,7 @@ namespace CodeSubWars CSWLog::CSWLog() - : m_pTextEdit(NULL) + : m_pTextEdit(nullptr) { QDir().mkdir("log"); m_LogFile.open("log/events.log", std::ios::out | std::ios::app); diff --git a/CodeSubWars/Source/CSWMap.cpp b/CodeSubWars/Source/CSWMap.cpp index b38d7e0..260ced8 100644 --- a/CodeSubWars/Source/CSWMap.cpp +++ b/CodeSubWars/Source/CSWMap.cpp @@ -243,7 +243,7 @@ namespace CodeSubWars CSWMap::CSWMap(const std::string& strName) : CSWEquipment(strName, Matrix44D(), 0, 0), - m_pVisualizer(NULL) + m_pVisualizer(nullptr) { } diff --git a/CodeSubWars/Source/CSWMapVisualizer.cpp b/CodeSubWars/Source/CSWMapVisualizer.cpp index d8cf057..ce09990 100644 --- a/CodeSubWars/Source/CSWMapVisualizer.cpp +++ b/CodeSubWars/Source/CSWMapVisualizer.cpp @@ -193,7 +193,7 @@ namespace CodeSubWars CSWMapVisualizer::CSWMapVisualizer(QWidget* pParent, CSWMap::PtrType pMap) - : QWidget(pParent, NULL) + : QWidget(pParent, nullptr) { QHBoxLayout* pLayout = new QHBoxLayout(this); pLayout->setMargin(1); diff --git a/CodeSubWars/Source/CSWMessageCollisionObjects.cpp b/CodeSubWars/Source/CSWMessageCollisionObjects.cpp index 430d725..541e4ae 100644 --- a/CodeSubWars/Source/CSWMessageCollisionObjects.cpp +++ b/CodeSubWars/Source/CSWMessageCollisionObjects.cpp @@ -82,7 +82,7 @@ namespace CodeSubWars DT_AddDefaultResponse(CSWWorld::getInstance()->getResponseTable(), &(CSWMessageInitializeCollisionObjects::collide), - DT_DEPTH_RESPONSE, NULL); + DT_DEPTH_RESPONSE, nullptr); } diff --git a/CodeSubWars/Source/CSWPassiveSonar.cpp b/CodeSubWars/Source/CSWPassiveSonar.cpp index 0a75cf5..a6de9bd 100644 --- a/CodeSubWars/Source/CSWPassiveSonar.cpp +++ b/CodeSubWars/Source/CSWPassiveSonar.cpp @@ -204,7 +204,7 @@ namespace CodeSubWars : CSWSonar(strName, matBaseTObject), m_pSoundReceiver(CSWSoundReceiver::create()), m_LastScanValues(50), - m_pVisualizer(NULL), + m_pVisualizer(nullptr), m_fAdjustingEndTime(0), m_bFoundMaximum(false), m_bFindingMaximum(false) diff --git a/CodeSubWars/Source/CSWPassiveSonarVisualizer.cpp b/CodeSubWars/Source/CSWPassiveSonarVisualizer.cpp index e566aeb..3da36b4 100644 --- a/CodeSubWars/Source/CSWPassiveSonarVisualizer.cpp +++ b/CodeSubWars/Source/CSWPassiveSonarVisualizer.cpp @@ -151,7 +151,7 @@ namespace CodeSubWars CSWPassiveSonarVisualizer::CSWPassiveSonarVisualizer(QWidget* pParent, CSWPassiveSonar::PtrType pPassiveSonar) - : QWidget(pParent, NULL) + : QWidget(pParent, nullptr) { QHBoxLayout* pLayout = new QHBoxLayout(this); pLayout->setMargin(1); diff --git a/CodeSubWars/Source/CSWPythonable.cpp b/CodeSubWars/Source/CSWPythonable.cpp index 8e02f10..12fd699 100644 --- a/CodeSubWars/Source/CSWPythonable.cpp +++ b/CodeSubWars/Source/CSWPythonable.cpp @@ -56,7 +56,7 @@ namespace CodeSubWars CSWPythonable::CSWPythonable() - : m_pThreadState(NULL) + : m_pThreadState(nullptr) { } diff --git a/CodeSubWars/Source/CSWSilentApplication.cpp b/CodeSubWars/Source/CSWSilentApplication.cpp index 8d634eb..bbfdc3f 100644 --- a/CodeSubWars/Source/CSWSilentApplication.cpp +++ b/CodeSubWars/Source/CSWSilentApplication.cpp @@ -134,7 +134,12 @@ namespace CodeSubWars CSWLog::getInstance()->log("running ... (press ESC to stop)"); std::cout << "\n"; +#ifdef _WIN32 while (!_kbhit() && CSWWorld::getInstance()->isBattleRunning()) +#else + // On non-Windows systems, just run until battle ends + while (CSWWorld::getInstance()->isBattleRunning()) +#endif { //recalculate the world CSWWorld::getInstance()->recalculate(); diff --git a/CodeSubWars/Source/CSWSubmarine.cpp b/CodeSubWars/Source/CSWSubmarine.cpp index ca6c2e6..354508b 100644 --- a/CodeSubWars/Source/CSWSubmarine.cpp +++ b/CodeSubWars/Source/CSWSubmarine.cpp @@ -356,7 +356,7 @@ namespace CodeSubWars CSWSubmarine::CSWSubmarine(const std::string& strName, const Matrix44D& matBaseTObject, double fLength) : CSWDamDynSolCol(strName, matBaseTObject, - Mesh::readSTL(std::istrstream(reinterpret_cast(SUBMARINE_MESH), sizeof(SUBMARINE_MESH)))->transformed(Matrix44D(Vector4D(fLength, 0, 0, 0), + Mesh::readSTL(std::istringstream(std::string(reinterpret_cast(SUBMARINE_MESH), sizeof(SUBMARINE_MESH))))->transformed(Matrix44D(Vector4D(fLength, 0, 0, 0), Vector4D(0, fLength, 0, 0), Vector4D(0, 0, fLength, 0), Vector4D(0, 0, 0, 1))), diff --git a/CodeSubWars/Source/CSWWeapon.cpp b/CodeSubWars/Source/CSWWeapon.cpp index 643969a..5f7b8e5 100644 --- a/CodeSubWars/Source/CSWWeapon.cpp +++ b/CodeSubWars/Source/CSWWeapon.cpp @@ -183,7 +183,7 @@ namespace CodeSubWars Vector3D vecStart = aabb.getMin() + Vector3D(aabb.getWidth()*0.5, aabb.getHeight()*0.5, fRadius); Vector3D vecEnd = aabb.getMax() - Vector3D(aabb.getWidth()*0.5, aabb.getHeight()*0.5, fRadius); - DT_ShapeHandle hDTShape = NULL; + DT_ShapeHandle hDTShape = nullptr; Mesh::PtrType pCollisionMesh; if (vecStart.getDistance(vecEnd) < EPSILON) { diff --git a/CodeSubWars/Source/CSWWeaponBattery.cpp b/CodeSubWars/Source/CSWWeaponBattery.cpp index 0a7944f..af710c3 100644 --- a/CodeSubWars/Source/CSWWeaponBattery.cpp +++ b/CodeSubWars/Source/CSWWeaponBattery.cpp @@ -268,7 +268,7 @@ namespace CodeSubWars m_fLeastWeaponLaunchDelay(1.0), m_fLastRechargeTime(0), m_Cnt(0), - m_pVisualizer(NULL) + m_pVisualizer(nullptr) { } diff --git a/CodeSubWars/Source/CSWWorld.cpp b/CodeSubWars/Source/CSWWorld.cpp index 5fa1b7c..9365645 100644 --- a/CodeSubWars/Source/CSWWorld.cpp +++ b/CodeSubWars/Source/CSWWorld.cpp @@ -516,7 +516,7 @@ namespace CodeSubWars m_bBattleInitialized(false), m_mtxRecalc(QMutex::Recursive), m_mtxDraw(QMutex::Recursive), - m_pyMainState(NULL), + m_pyMainState(nullptr), m_CalculateTimes(200), m_TransformCalculateTimes(200), m_RecalcTimes(200), diff --git a/CodeSubWars/Source/CodeSubwarsMainWindow.cpp b/CodeSubWars/Source/CodeSubwarsMainWindow.cpp index 734f7cc..05e225a 100644 --- a/CodeSubWars/Source/CodeSubwarsMainWindow.cpp +++ b/CodeSubWars/Source/CodeSubwarsMainWindow.cpp @@ -48,7 +48,7 @@ namespace CodeSubWars CodeSubwarsMainWindow::~CodeSubwarsMainWindow() { CSWWorld::getInstance()->finalizeWorld(); - CSWLog::getInstance()->setLogOutput(NULL); + CSWLog::getInstance()->setLogOutput(nullptr); } @@ -245,19 +245,19 @@ namespace CodeSubWars void CodeSubwarsMainWindow::help() { - ShellExecuteA(NULL, NULL, (LPCSTR)(qApp->applicationDirPath() + "/doc/html/index.html").toStdString().c_str(), NULL, NULL, SW_SHOWNORMAL); + ShellExecuteA(nullptr, nullptr, (LPCSTR)(qApp->applicationDirPath() + "/doc/html/index.html").toStdString().c_str(), nullptr, nullptr, SW_SHOWNORMAL); } void CodeSubwarsMainWindow::manual() { - ShellExecuteA(NULL, NULL, (LPCSTR)(qApp->applicationDirPath() + "/doc/Manual.pdf").toStdString().c_str(), NULL, NULL, SW_SHOWNORMAL); + ShellExecuteA(nullptr, nullptr, (LPCSTR)(qApp->applicationDirPath() + "/doc/Manual.pdf").toStdString().c_str(), nullptr, nullptr, SW_SHOWNORMAL); } void CodeSubwarsMainWindow::website() { - ShellExecuteA(NULL, NULL, (LPCSTR)Constants::WEBSITE.toStdString().c_str(), NULL, NULL, SW_SHOWNORMAL); + ShellExecuteA(nullptr, nullptr, (LPCSTR)Constants::WEBSITE.toStdString().c_str(), nullptr, nullptr, SW_SHOWNORMAL); } @@ -324,13 +324,13 @@ namespace CodeSubWars QSplitter* pHorizontalSplitter = new QSplitter(Qt::Horizontal); pVerticalSplitter->addWidget(pHorizontalSplitter); - m_pMainSceneView = new SceneView(NULL, true); + m_pMainSceneView = new SceneView(nullptr, true); pHorizontalSplitter->addWidget(m_pMainSceneView); QSplitter* pDetailVerticalSplitter = new QSplitter(Qt::Vertical); pHorizontalSplitter->addWidget(pDetailVerticalSplitter); - m_pDetailUpperSceneView = new SceneView(NULL, false); + m_pDetailUpperSceneView = new SceneView(nullptr, false); pDetailVerticalSplitter->addWidget(m_pDetailUpperSceneView); m_pDetailLowerInformationView = new InformationView; pDetailVerticalSplitter->addWidget(m_pDetailLowerInformationView); @@ -382,7 +382,7 @@ namespace CodeSubWars m_pTimeSlider->setTickPosition(QSlider::TicksBelow); pHBoxLayout->addWidget(m_pTimeSlider); - m_pSystemView = new SystemView(NULL); + m_pSystemView = new SystemView(nullptr); statusBar()->addPermanentWidget(m_pSystemView); connect(m_pTimeSlider, SIGNAL(valueChanged(int)), this, SLOT(setTimeRatio(int))); diff --git a/CodeSubWars/Source/IO/CSWBRImporter.cpp b/CodeSubWars/Source/IO/CSWBRImporter.cpp index ca1e814..674b843 100644 --- a/CodeSubWars/Source/IO/CSWBRImporter.cpp +++ b/CodeSubWars/Source/IO/CSWBRImporter.cpp @@ -101,10 +101,9 @@ namespace CodeSubWars is.read(reinterpret_cast(&nNameSize), 2); if (is.eof() || is.fail()) return true; - char* buff = new char[nNameSize]; - is.read(buff, nNameSize); - objData.strName = std::string(buff, nNameSize); - delete [] buff; + std::vector buff(nNameSize); + is.read(buff.data(), nNameSize); + objData.strName = std::string(buff.data(), nNameSize); if (is.eof() || is.fail()) return true; diff --git a/CodeSubWars/Source/InformationView.cpp b/CodeSubWars/Source/InformationView.cpp index 63fbf14..6513db9 100644 --- a/CodeSubWars/Source/InformationView.cpp +++ b/CodeSubWars/Source/InformationView.cpp @@ -537,7 +537,7 @@ namespace CodeSubWars { QList widgets; - infoField.pEquipmentInformationWidget = pObj->getInformationWidget(NULL); + infoField.pEquipmentInformationWidget = pObj->getInformationWidget(nullptr); if (!infoField.pEquipmentInformationWidget) infoField.pEquipmentInformationWidget = new QLabel("n.a."); widgets.push_back(infoField.pEquipmentInformationWidget); diff --git a/CodeSubWars/Source/InformationView.h b/CodeSubWars/Source/InformationView.h index 94ae5ee..aebaff8 100644 --- a/CodeSubWars/Source/InformationView.h +++ b/CodeSubWars/Source/InformationView.h @@ -19,7 +19,7 @@ namespace CodeSubWars Q_OBJECT public: - InformationView(QWidget* pParent = NULL); + InformationView(QWidget* pParent = nullptr); virtual ~InformationView(); diff --git a/CodeSubWars/Source/NewBattleDialog.h b/CodeSubWars/Source/NewBattleDialog.h index 311a559..b14b9e6 100644 --- a/CodeSubWars/Source/NewBattleDialog.h +++ b/CodeSubWars/Source/NewBattleDialog.h @@ -14,7 +14,7 @@ namespace CodeSubWars Q_OBJECT public: - NewBattleDialog(QString strPath, QWidget* pParent = NULL); + NewBattleDialog(QString strPath, QWidget* pParent = nullptr); virtual ~NewBattleDialog(); CSWUtilities::SubmarineFileContainer getSubmarines() const; diff --git a/CodeSubWars/Source/PrecompiledHeader.h b/CodeSubWars/Source/PrecompiledHeader.h index 73088de..1e61151 100644 --- a/CodeSubWars/Source/PrecompiledHeader.h +++ b/CodeSubWars/Source/PrecompiledHeader.h @@ -6,7 +6,9 @@ #pragma warning (disable: 4267) // c++ and c standard lib +#ifdef _WIN32 #include +#endif #include #include #include @@ -16,7 +18,6 @@ #include #include #include -#include #include #include #include diff --git a/CodeSubWars/Source/ReplayDialog.cpp b/CodeSubWars/Source/ReplayDialog.cpp index 7ce8f4a..717d904 100644 --- a/CodeSubWars/Source/ReplayDialog.cpp +++ b/CodeSubWars/Source/ReplayDialog.cpp @@ -102,7 +102,7 @@ namespace CodeSubWars } else { - QMessageBox::information(NULL, "Error", "CSW battle record file could not read successfully."); + QMessageBox::information(nullptr, "Error", "CSW battle record file could not read successfully."); m_fMinTime = 0; m_fMaxTime = 0; } diff --git a/CodeSubWars/Source/ReplayDialog.h b/CodeSubWars/Source/ReplayDialog.h index b882166..bae183d 100644 --- a/CodeSubWars/Source/ReplayDialog.h +++ b/CodeSubWars/Source/ReplayDialog.h @@ -16,7 +16,7 @@ namespace CodeSubWars Q_OBJECT public: - ReplayDialog(QString strFileName, QWidget* pParent = NULL); + ReplayDialog(QString strFileName, QWidget* pParent = nullptr); virtual ~ReplayDialog(); const CSWBRImporter::TimeSliceData& getData() const; diff --git a/CodeSubWars/Source/SceneView.cpp b/CodeSubWars/Source/SceneView.cpp index 7fb15c6..cf50522 100644 --- a/CodeSubWars/Source/SceneView.cpp +++ b/CodeSubWars/Source/SceneView.cpp @@ -107,7 +107,7 @@ namespace CodeSubWars //handle mouse pressing float fIntersection = 0; Vector3F vecNormal; - void* pCastResult = DT_RayCast(CSWWorld::getInstance()->getScene(), NULL, + void* pCastResult = DT_RayCast(CSWWorld::getInstance()->getScene(), nullptr, static_cast(resultRay.second.getPos()).pData, static_cast(resultRay.second.getPos() + resultRay.second.getDir()*100000.0).pData, 1.0, &fIntersection, vecNormal.pData); From ca8baca97cc85037bdeba01ec450dcfb5f04de0d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 06:32:55 +0000 Subject: [PATCH 3/3] Improve string parsing safety and modern C++ usage Co-authored-by: pirx42 <2143008+pirx42@users.noreply.github.com> --- CodeSubWars/Source/CSWSilentApplication.cpp | 42 +++++++++++++-------- CodeSubWars/Source/CSWUtilities.cpp | 4 +- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/CodeSubWars/Source/CSWSilentApplication.cpp b/CodeSubWars/Source/CSWSilentApplication.cpp index bbfdc3f..696b182 100644 --- a/CodeSubWars/Source/CSWSilentApplication.cpp +++ b/CodeSubWars/Source/CSWSilentApplication.cpp @@ -41,11 +41,15 @@ namespace CodeSubWars } case WORLD_TYPE: { - int t = atoi(result.second.c_str()); - if (t >= 1 && t <= 5) - m_WorldType = static_cast(t); - else - m_bParametersValid = false; + try { + int t = std::stoi(result.second); + if (t >= 1 && t <= 5) + m_WorldType = static_cast(t); + else + m_bParametersValid = false; + } catch (...) { + m_bParametersValid = false; + } break; } case BATTLE_TYPE: @@ -60,20 +64,28 @@ namespace CodeSubWars } case TEAMSIZE_TYPE: { - int t = atoi(result.second.c_str()); - if (t == 3 || t == 5 || t == 10) - m_nTeamSize = t; - else - m_bParametersValid = false; + try { + int t = std::stoi(result.second); + if (t == 3 || t == 5 || t == 10) + m_nTeamSize = t; + else + m_bParametersValid = false; + } catch (...) { + m_bParametersValid = false; + } break; } case TIMESTEP_TYPE: { - double t = atof(result.second.c_str()); - if (t >= 0.01 && t <= 0.1) - m_fTimeStep = t; - else - m_bParametersValid = false; + try { + double t = std::stod(result.second); + if (t >= 0.01 && t <= 0.1) + m_fTimeStep = t; + else + m_bParametersValid = false; + } catch (...) { + m_bParametersValid = false; + } break; } } diff --git a/CodeSubWars/Source/CSWUtilities.cpp b/CodeSubWars/Source/CSWUtilities.cpp index 3ae47b7..5e4a5fe 100644 --- a/CodeSubWars/Source/CSWUtilities.cpp +++ b/CodeSubWars/Source/CSWUtilities.cpp @@ -255,9 +255,9 @@ namespace CodeSubWars return CSWUtilities::SubmarineFileContainer(); // scan given directory - for (int i = 0; i < list.size(); ++i) + for (const auto& fileInfo : list) { - QFileInfo fi = list.at(i); + QFileInfo fi = fileInfo; if (fi.isFile() && fi.suffix() == "py") {