diff --git a/Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp b/Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp index 0604e448c5..13dfb10983 100644 --- a/Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp +++ b/Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp @@ -150,9 +150,9 @@ void plClient::InitDLLs() { hsStatusMessage("Init dlls client\n"); std::vector dlls = plFileSystem::ListDir("ModDLL", "*.dll"); - for (auto iter = dlls.begin(); iter != dlls.end(); ++iter) + for (const auto& dll : dlls) { - HMODULE hMod = LoadLibraryW(iter->WideString().data()); + HMODULE hMod = LoadLibraryW(dll.WideString().data()); if (hMod) { pInitGlobalsFunc initGlobals = (pInitGlobalsFunc)GetProcAddress(hMod, "InitGlobals"); diff --git a/Sources/Plasma/Apps/plPythonPack/main.cpp b/Sources/Plasma/Apps/plPythonPack/main.cpp index 125a0ec863..6c643dde77 100644 --- a/Sources/Plasma/Apps/plPythonPack/main.cpp +++ b/Sources/Plasma/Apps/plPythonPack/main.cpp @@ -213,9 +213,9 @@ void FindFiles(std::vector &filenames, std::vector &path // Get the names of all the python files std::vector pys = plFileSystem::ListDir(path, "*.py"); - for (auto iter = pys.begin(); iter != pys.end(); ++iter) + for (const auto& py : pys) { - filenames.push_back(iter->GetFileName()); + filenames.emplace_back(py.GetFileName()); pathnames.push_back(path); } } @@ -223,8 +223,9 @@ void FindFiles(std::vector &filenames, std::vector &path void FindSubDirs(std::vector &dirnames, const plFileName &path) { std::vector subdirs = plFileSystem::ListSubdirs(path); - for (auto iter = subdirs.begin(); iter != subdirs.end(); ++iter) { - ST::string name = iter->GetFileName(); + for (const auto& subdir : subdirs) + { + const ST::string& name = subdir.GetFileName(); if (s_ignoreSubdirs.find(name) == s_ignoreSubdirs.end()) dirnames.push_back(name); } @@ -234,15 +235,15 @@ void FindPackages(std::vector& fileNames, std::vector& p { std::vector packages; FindSubDirs(packages, path); - for (int i = 0; i < packages.size(); i++) + for (const auto& package : packages) { ST::string packageName; if (!parent_package.empty()) packageName = parent_package + "."; - packageName += packages[i].AsString(); + packageName += package.AsString(); std::vector packageFileNames; std::vector packagePathNames; - plFileName packagePath = plFileName::Join(path, packages[i]); + plFileName packagePath = plFileName::Join(path, package); FindFiles(packageFileNames, packagePathNames, packagePath); // Check for the magic file to make sure this is really a package... diff --git a/Sources/Plasma/CoreLib/hsMatrix33.cpp b/Sources/Plasma/CoreLib/hsMatrix33.cpp index c5f83f4f9a..1c06025976 100644 --- a/Sources/Plasma/CoreLib/hsMatrix33.cpp +++ b/Sources/Plasma/CoreLib/hsMatrix33.cpp @@ -91,16 +91,16 @@ hsMatrix33 operator*(const hsMatrix33& a, const hsMatrix33& b) void hsMatrix33::Read(hsStream* s) { - for (int i = 0; i < 3; i++) + for (auto& i : fMap) { - s->ReadLEFloat(3, fMap[i]); + s->ReadLEFloat(3, i); } } void hsMatrix33::Write(hsStream* s) { - for (int i = 0; i < 3; i++) + for (const auto& i : fMap) { - s->WriteLEFloat(3, fMap[i]); + s->WriteLEFloat(3, i); } } diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.cpp index 7d795c863a..ecb738c59c 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.cpp @@ -63,7 +63,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define WEAK_ERROR_CHECK( cond ) cond #endif -static D3DMATRIX d3dIdentityMatrix{ +static constexpr D3DMATRIX d3dIdentityMatrix{ 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDeviceRefs.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDeviceRefs.cpp index 9a2922bf01..d3e90d4f73 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDeviceRefs.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDeviceRefs.cpp @@ -189,8 +189,8 @@ plDXTextureRef& plDXTextureRef::Set( D3DFORMAT ft, uint32_t ml, uint32_t mw, uin fMaxHeight = mh; fNumPix = np; fDataSize = manSize; - if (fLevelSizes != nullptr) - delete [] fLevelSizes; + + delete [] fLevelSizes; if( lSz ) fLevelSizes = lSz; else diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.cpp index 13babbef9f..a7fc56f780 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.cpp @@ -50,16 +50,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com typedef LPDIRECT3D9 (WINAPI * Direct3DCreateProc)( UINT sdkVersion ); -const uint8_t hsGDirect3DTnLEnumerate::kNumDisplayFormats = 6; -const D3DFORMAT hsGDirect3DTnLEnumerate::kDisplayFormats[] = -{ - D3DFMT_A1R5G5B5, - D3DFMT_A2B10G10R10, - D3DFMT_A8R8G8B8, - D3DFMT_R5G6B5, - D3DFMT_X1R5G5B5, - D3DFMT_X8R8G8B8, -}; bool hsGDirect3DTnLEnumerate::SelectFromDevMode(const hsG3DDeviceRecord* devRec, const hsG3DDeviceMode* devMode) { diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.h b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.h index 7f22a838fb..40e2d7922c 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.h +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.h @@ -151,9 +151,16 @@ class hsGDirect3DTnLEnumerate bool ICheckCubicRenderTargets( IDirect3D9 *pD3D, UINT iAdapter, D3DDEVTYPE deviceType, D3DEnum_ModeInfo *modeInfo ); HRESULT IConfirmDevice( D3DCAPS9* pCaps, DWORD dwBehavior, D3DFORMAT format ); - static const uint8_t kNumDisplayFormats; - static const D3DFORMAT kDisplayFormats[]; - + static constexpr D3DFORMAT kDisplayFormats[] = + { + D3DFMT_A1R5G5B5, + D3DFMT_A2B10G10R10, + D3DFMT_A8R8G8B8, + D3DFMT_R5G6B5, + D3DFMT_X1R5G5B5, + D3DFMT_X8R8G8B8, + }; + static constexpr uint8_t kNumDisplayFormats = std::size(kDisplayFormats); public: hsGDirect3DTnLEnumerate(); virtual ~hsGDirect3DTnLEnumerate(); diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp index a9ed50f25f..3dadc0fcc7 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp @@ -242,7 +242,7 @@ inline DWORD F2DW( FLOAT f ) #define WEAK_ERROR_CHECK( cond ) cond #endif -static D3DMATRIX d3dIdentityMatrix{ 1.0f, 0.0f, 0.0f, 0.0f, +static constexpr D3DMATRIX d3dIdentityMatrix{ 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXTextFont.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXTextFont.cpp index 80a390aa9c..6b5a9e64b1 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXTextFont.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXTextFont.cpp @@ -63,10 +63,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com //// Local Stuff ////////////////////////////////////////////////////////////// -static const long PLD3D_FONTFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE +static constexpr long PLD3D_FONTFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0); -static D3DMATRIX d3dIdentityMatrix{ 1.0f, 0.0f, 0.0f, 0.0f, +static const D3DMATRIX d3dIdentityMatrix{ 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; @@ -78,9 +78,6 @@ static D3DMATRIX d3dIdentityMatrix{ 1.0f, 0.0f, 0.0f, 0.0f, //const uint32_t kNumVertsInBuffer(32768); const uint32_t kNumVertsInBuffer(4608); -// See the declaration for plFontVertex in plTextFont.h for info -const DWORD plDXTextFont::kFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0); - IDirect3DVertexBuffer9* plDXTextFont::fBuffer = nullptr; uint32_t plDXTextFont::fBufferCursor = 0; diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXTextFont.h b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXTextFont.h index 53f326c73d..ae88da371b 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXTextFont.h +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXTextFont.h @@ -84,7 +84,8 @@ class plDXTextFont : public plTextFont void RestoreStates() override; void DestroyObjects() override; - static const DWORD kFVF; + // See the declaration for plFontVertex in plTextFont.h for info + static constexpr DWORD kFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0); }; diff --git a/Sources/Plasma/PubUtilLib/plMath/plTriUtils.cpp b/Sources/Plasma/PubUtilLib/plMath/plTriUtils.cpp index e9d3aadb35..10f2ac7946 100644 --- a/Sources/Plasma/PubUtilLib/plMath/plTriUtils.cpp +++ b/Sources/Plasma/PubUtilLib/plMath/plTriUtils.cpp @@ -45,17 +45,18 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include "plTriUtils.h" -static const float kAlmostZero = 1.e-5f; -static const float kPastZero = -kAlmostZero; -static const float kPastOne = 1.f + kAlmostZero; -static const float kAlmostOne = 1.f - kAlmostZero; -static const float kAlmostZeroSquared = kAlmostZero*kAlmostZero; +static constexpr float kAlmostZero = 1.e-5f; +static constexpr float kPastZero = -kAlmostZero; +static constexpr float kPastOne = 1.f + kAlmostZero; +static constexpr float kAlmostOne = 1.f - kAlmostZero; +static constexpr float kAlmostZeroSquared = kAlmostZero*kAlmostZero; static inline hsVector3 Cross(const hsScalarTriple& p0, const hsScalarTriple& p1) { - return hsVector3(p0.fY * p1.fZ - p0.fZ * p1.fY, - p0.fZ * p1.fX - p0.fX * p1.fZ, - p0.fX * p1.fY - p0.fY * p1.fX); + return {p0.fY * p1.fZ - p0.fZ * p1.fY, + p0.fZ * p1.fX - p0.fX * p1.fZ, + p0.fX * p1.fY - p0.fY * p1.fX + }; } diff --git a/Sources/Tools/plFilePatcher/main.cpp b/Sources/Tools/plFilePatcher/main.cpp index beeffceb98..02b944bbab 100644 --- a/Sources/Tools/plFilePatcher/main.cpp +++ b/Sources/Tools/plFilePatcher/main.cpp @@ -55,7 +55,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #if HS_BUILD_FOR_WIN32 # include "hsWindows.h" # include -# define isatty _isatty + +#ifndef __MINGW32__ +# define ttycheck(fileinfo) (GetFileType(fileinfo) == FILE_TYPE_CHAR) +#endif void GetConsoleWidth(size_t& width) { @@ -67,7 +70,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com # include # include # include - +# define ttycheck(fileinfo) isatty(fileno(fileinfo)) void GetConsoleWidth(size_t& width) { struct winsize w; @@ -174,7 +177,7 @@ int main(int argc, char* argv[]) patcher.SetPatcherFlags(flags); - if (!cmdParser.GetBool(kArgQuiet) && isatty(fileno(stdout))) { + if (!cmdParser.GetBool(kArgQuiet) && ttycheck(stdout)) { patcher.SetDownloadBeginCallback(&FileDownloadBegin); patcher.SetProgressCallback(&FileDownloadProgress); } @@ -185,7 +188,7 @@ int main(int argc, char* argv[]) return 1; } - if (!cmdParser.GetBool(kArgQuiet) && isatty(fileno(stdout))) { + if (!cmdParser.GetBool(kArgQuiet) && ttycheck(stdout)) { ST::printf("\r{}\r", ST::string::fill(consoleWidth, ' ')); fflush(stdout); }