diff --git a/Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp b/Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp index 0604e448c5..e01bbde091 100644 --- a/Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp +++ b/Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp @@ -99,14 +99,12 @@ void plClient::IChangeResolution(int width, int height) HMONITOR monitor = MonitorFromWindow(fWindowHndl, MONITOR_DEFAULTTONULL); if (!monitor) return; - MONITORINFOEXW moninfo; - memset(&moninfo, 0, sizeof(moninfo)); + MONITORINFOEXW moninfo{}; moninfo.cbSize = sizeof(moninfo); GetMonitorInfoW(monitor, &moninfo); // Fetch a base display settings - DEVMODEW devmode; - memset(&devmode, 0, sizeof(devmode)); + DEVMODEW devmode{}; devmode.dmSize = sizeof(devmode); EnumDisplaySettingsW(moninfo.szDevice, ENUM_REGISTRY_SETTINGS, &devmode); diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp index d833caef05..8251766ee9 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp @@ -61,19 +61,18 @@ bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const char* mask /* hsAssert(fEngine != nullptr, "Cannot do a dir execute without an engine!"); std::vector files = plFileSystem::ListDir(path, mask); - for (auto iter = files.begin(); iter != files.end(); ++iter) + for (const auto& file : files) { - plFileName name = iter->GetFileName(); - if (AlreadyProcessedFile(path, name)) + if (AlreadyProcessedFile(path, file)) continue; - AddProcessedFile(path, name); - if (!fEngine->ExecuteFile(*iter)) + AddProcessedFile(path, file); + if (!fEngine->ExecuteFile(file)) { // Change the following line once we have a better way of reporting // errors in the parsing ST::string_stream error, caption; - caption << "Error parsing " << name.AsString(); + caption << "Error parsing " << file.AsString(); error << fEngine->GetErrorMsg() << ":\n\nCommand: '" << fEngine->GetLastErrorLine() << "'\n\nPress OK to continue parsing files."; @@ -90,9 +89,8 @@ bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const char* mask /* void pfConsoleDirSrc::ResetProcessedFiles() { - int i; - for(i=0;ifFile && path == fProcessedFiles[i]->fPath) + for (const auto& fProcessedFile : fProcessedFiles) + { + if (file == fProcessedFile->fFile && path == fProcessedFile->fPath) return true; } } diff --git a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleParser.cpp b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleParser.cpp index 8c1a0957ea..19e3fe4e65 100644 --- a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleParser.cpp +++ b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleParser.cpp @@ -46,8 +46,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pfConsoleCmd.h" -static const char kTokenSeparators[] = " =\r\n\t,"; -static const char kTokenGrpSeps[] = " =\r\n._\t,"; +static constexpr char kTokenSeparators[] = " =\r\n\t,"; +static constexpr char kTokenGrpSeps[] = " =\r\n._\t,"; std::optional pfConsoleTokenizer::NextNamePart() { diff --git a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp index 42b2fa1bf9..ca1f0f8bac 100644 --- a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp @@ -491,11 +491,8 @@ void plAgeDescription::CopyFrom(const plAgeDescription& other) bool plAgeDescription::FindLocation(const plLocation& loc) const { - for (const plAgePage& page : fPages) + return std::any_of(fPages.begin(), fPages.end(), [this, &loc](const plAgePage& page) { - plLocation pageLoc = CalcPageLocation(page.GetName()); - if (pageLoc == loc) - return true; - } - return false; + return CalcPageLocation(page.GetName()) == loc; + }); } diff --git a/Sources/Plasma/PubUtilLib/plAnimation/plAGAnim.cpp b/Sources/Plasma/PubUtilLib/plAnimation/plAGAnim.cpp index c338ec1ea6..d32dcc3df9 100644 --- a/Sources/Plasma/PubUtilLib/plAnimation/plAGAnim.cpp +++ b/Sources/Plasma/PubUtilLib/plAnimation/plAGAnim.cpp @@ -438,17 +438,17 @@ void plATCAnim::Write(hsStream *stream, hsResMgr *mgr) stream->WriteLEFloat(fEaseOutLength); stream->WriteLE32((uint32_t)fMarkers.size()); - for (MarkerMap::iterator it = fMarkers.begin(); it != fMarkers.end(); it++) + for (const auto& fMarker : fMarkers) { - stream->WriteSafeString(it->first); - stream->WriteLEFloat(it->second); + stream->WriteSafeString(fMarker.first); + stream->WriteLEFloat(fMarker.second); } stream->WriteLE32((uint32_t)fLoops.size()); - for (LoopMap::iterator loopIt = fLoops.begin(); loopIt != fLoops.end(); loopIt++) + for (const auto& loop : fLoops) { - stream->WriteSafeString(loopIt->first); - std::pair& loop = loopIt->second; + stream->WriteSafeString(loop.first); + std::pair& loop = loop.second; stream->WriteLEFloat(loop.first); stream->WriteLEFloat(loop.second); } diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp index 26c35d92ca..e28a26d7ca 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp @@ -133,7 +133,7 @@ plArmatureModBase::~plArmatureModBase() { delete fController; - while (fUnusedBones.size() > 0) + while (!fUnusedBones.empty()) { delete fUnusedBones.back(); fUnusedBones.pop_back(); @@ -143,7 +143,7 @@ plArmatureModBase::~plArmatureModBase() bool plArmatureModBase::MsgReceive(plMessage* msg) { plArmatureBrain *curBrain = nullptr; - if (fBrains.size() > 0) + if (!fBrains.empty()) { curBrain = fBrains.back(); if(curBrain->MsgReceive(msg)) @@ -179,7 +179,7 @@ bool plArmatureModBase::IEval(double time, float elapsed, uint32_t dirty) { if (IsFinal()) { - if (fBrains.size()) + if (!fBrains.empty()) { plArmatureBrain *curBrain = fBrains.back(); if (curBrain) @@ -345,7 +345,7 @@ void plArmatureModBase::PushBrain(plArmatureBrain *brain) void plArmatureModBase::PopBrain() { plArmatureBrain *oldBrain = nullptr; - if (fBrains.size() > 0) + if (!fBrains.empty()) { oldBrain = fBrains.back(); oldBrain->Deactivate(); @@ -362,7 +362,7 @@ void plArmatureModBase::PopBrain() plArmatureBrain *plArmatureModBase::GetCurrentBrain() const { plArmatureBrain *result = nullptr; - if (fBrains.size() > 0) + if (!fBrains.empty()) result = fBrains.back(); return result; diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp index 12fee0554b..c9840e71de 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp @@ -206,12 +206,7 @@ void plAvBrainHuman::Activate(plArmatureModBase *avMod) void plAvBrainHuman::IInitBoneMap() { - struct tuple { - HumanBoneID fID; - const char * fName; - }; - - tuple tupleMap[] = + static constexpr std::tuple BoneMap[] = { { Pelvis, "Bone_Root" }, // left leg @@ -304,20 +299,16 @@ void plAvBrainHuman::IInitBoneMap() { RThumb3, "Bone_RThumb3" }, }; - int numTuples = sizeof(tupleMap) / sizeof(tuple); - - for(int i = 0; i < numTuples; i++) + for (const auto& [BoneID, BoneName] : BoneMap) { - HumanBoneID id = tupleMap[i].fID; - ST::string name = tupleMap[i].fName; - - const plSceneObject * bone = this->fAvMod->FindBone(name); - if( bone ) + if (const plSceneObject * bone = fAvMod->FindBone(BoneName)) { - fAvMod->AddBoneMapping(id, bone); + fAvMod->AddBoneMapping(BoneID, bone); } else - hsStatusMessageF("Couldn't find standard bone %s.", name.c_str()); + { + hsStatusMessageF("Couldn't find standard bone %s.", BoneName.data()); + } } }