diff --git a/Sources/Plasma/Apps/plFileSecure/main.cpp b/Sources/Plasma/Apps/plFileSecure/main.cpp index ee69b5aa..e3fecce6 100644 --- a/Sources/Plasma/Apps/plFileSecure/main.cpp +++ b/Sources/Plasma/Apps/plFileSecure/main.cpp @@ -75,7 +75,7 @@ void GenerateKey(bool useDefault) uint32_t key[4]; if (useDefault) { - unsigned memSize = min(arrsize(key), arrsize(plSecureStream::kDefaultKey)); + unsigned memSize = std::min(arrsize(key), arrsize(plSecureStream::kDefaultKey)); memSize *= sizeof(uint32_t); memcpy(key, plSecureStream::kDefaultKey, memSize); } diff --git a/Sources/Plasma/CoreLib/HeadSpin.h b/Sources/Plasma/CoreLib/HeadSpin.h index 471d9efc..201075d8 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.h +++ b/Sources/Plasma/CoreLib/HeadSpin.h @@ -242,51 +242,6 @@ inline void hsSwap(float& a, float& b) # define NULL_STMT ((void)0) #endif -//=========================================================================== -template -inline T max (const T & a, const T & b) { - return (a > b) ? a : b; -} - -//=========================================================================== -inline unsigned max (int a, unsigned b) { - return ((unsigned)a > b) ? a : b; -} - -//=========================================================================== -inline unsigned max (unsigned a, int b) { - return (a > (unsigned)b) ? a : b; -} - -//=========================================================================== -template -inline T min (const T & a, const T & b) { - return (a < b) ? a : b; -} - -//=========================================================================== -inline unsigned min (int a, unsigned b) { - return ((unsigned)a < b) ? a : b; -} - -//=========================================================================== -inline unsigned min (unsigned a, int b) { - return (a < (unsigned)b) ? a : b; -} - - -/**************************************************************************** -* -* MAX/MIN macros -* These are less safe than the inline function versions, since they -* evaluate parameters twice. However, they can be used to produce -* compile-time constants. -* -***/ -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) - - /**************************************************************************** * * SWAP diff --git a/Sources/Plasma/CoreLib/hsWindows.h b/Sources/Plasma/CoreLib/hsWindows.h index 5e8702f3..fb5dddc1 100644 --- a/Sources/Plasma/CoreLib/hsWindows.h +++ b/Sources/Plasma/CoreLib/hsWindows.h @@ -61,8 +61,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com # define _WIN32_IE 0x400 # endif + // HACK: Max headers depend on the min() and max() macros normally pulled + // in by windows.h... However, we usually disable those, since they break + // std::min and std::max. Therefore, we bring the std:: versions down to + // the global namespace so we can still compile max code without breaking + // everything else :/ # ifndef NOMINMAX # define NOMINMAX +# include + using std::min; + using std::max; # endif # define WIN32_LEAN_AND_MEAN diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp index ab4cd404..a0214eca 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp @@ -338,7 +338,7 @@ static NtOpSocketWrite * SocketQueueAsyncWrite ( NtOpSocketWrite * lastQueuedWrite = (NtOpSocketWrite *) opCurr; unsigned bytesLeft = lastQueuedWrite->bytesAlloc - lastQueuedWrite->write.bytes; - bytesLeft = min(bytesLeft, bytes); + bytesLeft = std::min(bytesLeft, bytes); if (bytesLeft) { PerfAddCounter(kAsyncPerfSocketBytesWaitQueued, bytesLeft); memcpy(lastQueuedWrite->write.buffer + lastQueuedWrite->write.bytes, data, bytesLeft); @@ -353,8 +353,8 @@ static NtOpSocketWrite * SocketQueueAsyncWrite ( // allocate a buffer large enough to hold the data, plus // extra space in case more data needs to be queued later - unsigned bytesAlloc = max(bytes, sock->backlogAlloc); - bytesAlloc = max(bytesAlloc, kMinBacklogBytes); + unsigned bytesAlloc = std::max(bytes, sock->backlogAlloc); + bytesAlloc = std::max(bytesAlloc, kMinBacklogBytes); NtOpSocketWrite * op = new(malloc(sizeof(NtOpSocketWrite) + bytesAlloc)) NtOpSocketWrite; // init Operation @@ -883,7 +883,7 @@ static unsigned SocketCloseTimerCallback (void *) { HardCloseSocket(*cur); // Don't run too frequently - return max(sleepMs, 2000); + return std::max(sleepMs, 2000u); } diff --git a/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp index 92e72e59..300f7bcd 100644 --- a/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp +++ b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp @@ -48,8 +48,8 @@ void CryptCreateRandomSeed(size_t length, uint8_t* data) { uint32_t seedIdx = 0; uint32_t dataIdx = 0; - uint32_t cur = 0; - uint32_t end = max(length, sizeof(ShaDigest)); + size_t cur = 0; + size_t end = std::max(length, sizeof(ShaDigest)); // Combine seed with input data for (; cur < end; cur++) { diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp b/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp index 91d5fdf6..e1bc67ae 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp @@ -205,7 +205,7 @@ static unsigned MaxMsgId (const T msgs[], unsigned count) { for (unsigned i = 0; i < count; i++) { ASSERT(msgs[i].msg.count); - maxMsgId = max(msgs[i].msg.messageId, maxMsgId); + maxMsgId = std::max(msgs[i].msg.messageId, maxMsgId); } return maxMsgId; } @@ -248,7 +248,7 @@ static void AddRecvMsgs_CS ( *dst = *src; const uint32_t bytes = ValidateMsg(dst->msg); - channel->m_largestRecv = max(channel->m_largestRecv, bytes); + channel->m_largestRecv = std::max(channel->m_largestRecv, bytes); } } diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp b/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp index 2ecd793a..b1f6fc7b 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp @@ -244,7 +244,7 @@ static void AddToSendBuffer ( // calculate the space left in the output buffer and use it // to determine the maximum number of bytes that will fit unsigned const left = &cli->sendBuffer[arrsize(cli->sendBuffer)] - cli->sendCurr; - unsigned const copy = min(bytes, left); + unsigned const copy = std::min(bytes, left); // copy the data into the buffer for (unsigned i = 0; i < copy; ++i) @@ -678,7 +678,7 @@ static void ClientConnect (NetCli * cli) { memset(&cli->seed, 0, sizeof(cli->seed)); unsigned bytes; unsigned char * data = clientSeed.GetData_LE(&bytes); - memcpy(cli->seed, data, min(bytes, sizeof(cli->seed))); + memcpy(cli->seed, data, std::min(bytes, sizeof(cli->seed))); delete [] data; } @@ -740,7 +740,7 @@ static bool ServerRecvConnect ( memset(&clientSeed, 0, sizeof(clientSeed)); unsigned bytes; unsigned char * data = clientSeedValue.GetData_LE(&bytes); - memcpy(clientSeed, data, min(bytes, sizeof(clientSeed))); + memcpy(clientSeed, data, std::min(bytes, sizeof(clientSeed))); delete [] data; } @@ -964,7 +964,7 @@ static void SetConnSeed ( const uint8_t seedData[] ) { if (seedBytes) - memcpy(cli->seed, seedData, min(sizeof(cli->seed), seedBytes)); + memcpy(cli->seed, seedData, std::min(sizeof(cli->seed), seedBytes)); else CryptCreateRandomSeed(sizeof(cli->seed), cli->seed); } diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtArray.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtArray.cpp index c7450c99..7c4c1aa3 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtArray.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtArray.cpp @@ -60,7 +60,7 @@ unsigned CBaseArray::CalcAllocGrowth (unsigned newAlloc, unsigned oldAlloc, unsi // If this is the initial allocation, or if the new allocation is more // than twice as big as the old allocation and larger than the chunk // size, then allocate exactly the amount of memory requested - if (!oldAlloc || (newAlloc >= max(2 * oldAlloc, *chunkSize))) + if (!oldAlloc || (newAlloc >= std::max(2 * oldAlloc, *chunkSize))) return newAlloc; // Otherwise, allocate memory beyond what was requested in preparation @@ -69,7 +69,7 @@ unsigned CBaseArray::CalcAllocGrowth (unsigned newAlloc, unsigned oldAlloc, unsi // For small allocations, double the size of the buffer each time if (newAlloc < *chunkSize) - return max(newAlloc, 2 * oldAlloc); + return std::max(newAlloc, 2 * oldAlloc); // For larger allocations, grow by the chunk size each time if (oldAlloc + *chunkSize > newAlloc) { diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtArray.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtArray.h index 01346f99..0d4537b4 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtArray.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtArray.h @@ -740,25 +740,25 @@ public: //=========================================================================== template TArray::TArray () : TFArray() { - m_chunkSize = max(1, 256 / sizeof(T)); + m_chunkSize = std::max(1u, 256 / sizeof(T)); } //=========================================================================== template TArray::TArray (const char file[], int line) : TFArray(file, line) { - m_chunkSize = max(1, 256 / sizeof(T)); + m_chunkSize = std::max(1u, 256 / sizeof(T)); } //=========================================================================== template TArray::TArray (unsigned count) : TFArray(count) { - m_chunkSize = max(1, 256 / sizeof(T)); + m_chunkSize = std::max(1u, 256 / sizeof(T)); } //=========================================================================== template TArray::TArray (const T * source, unsigned count) : TFArray(source, count) { - m_chunkSize = max(1, 256 / sizeof(T)); + m_chunkSize = std::max(1u, 256 / sizeof(T)); } //=========================================================================== @@ -890,8 +890,8 @@ void TArray::Move (unsigned destIndex, unsigned sourceIndex, unsigned count // Remove it from the source if (destIndex >= sourceIndex) { - C::Destruct(this->m_data + sourceIndex, min(count, destIndex - sourceIndex)); - C::Construct(this->m_data + sourceIndex, min(count, destIndex - sourceIndex)); + C::Destruct(this->m_data + sourceIndex, std::min(count, destIndex - sourceIndex)); + C::Construct(this->m_data + sourceIndex, std::min(count, destIndex - sourceIndex)); } else { unsigned overlap = (destIndex + count > sourceIndex) ? (destIndex + count - sourceIndex) : 0; @@ -936,7 +936,7 @@ T TArray::Pop () { //=========================================================================== template void TArray::Reserve (unsigned additionalCount) { - AdjustSizeChunked(max(this->m_alloc, this->m_count + additionalCount), this->m_count); + AdjustSizeChunked(std::max(this->m_alloc, this->m_count + additionalCount), this->m_count); } //=========================================================================== @@ -956,7 +956,7 @@ void TArray::SetChunkSize (unsigned chunkSize) { //=========================================================================== template void TArray::SetCount (unsigned count) { - AdjustSizeChunked(max(this->m_alloc, count), count); + AdjustSizeChunked(std::max(this->m_alloc, count), count); } //=========================================================================== diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.cpp index cea8367a..a11dca75 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.cpp @@ -158,7 +158,7 @@ CICmdParser::CICmdParser (const CmdArgDef def[], unsigned defCount) { arg.nameChars = def[loop].name ? StrLen(def[loop].name) : 0; arg.isSpecified = false; SetDefaultValue(arg); - maxId = max(maxId, def[loop].id); + maxId = std::max(maxId, def[loop].id); // Track the number of unflagged arguments if (!flagged) @@ -167,7 +167,7 @@ CICmdParser::CICmdParser (const CmdArgDef def[], unsigned defCount) { } // Build the id lookup table - unsigned idTableSize = min(maxId + 1, defCount * 2); + unsigned idTableSize = std::min(maxId + 1, defCount * 2); m_idLookupArray.SetCount(idTableSize); m_idLookupArray.Zero(); for (loop = 0; loop < defCount; ++loop) diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h index 6c5f34d5..b7313c05 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h @@ -432,7 +432,7 @@ void TBaseHashTable::SetLinkOffset (int linkOffset, unsigned maxSize) { v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; - SetSlotCount(max(kSlotMinCount, v)); + SetSlotCount(std::max(static_cast(kSlotMinCount), v)); } } @@ -459,7 +459,7 @@ void TBaseHashTable::SetSlotCount (unsigned count) { template void TBaseHashTable::SetSlotMaxCount (unsigned count) { if (count) - m_slotMaxCount = max(kSlotMinCount, count); + m_slotMaxCount = std::max(static_cast(kSlotMinCount), count); } //=========================================================================== diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp index 1cfff012..b5956c0c 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp @@ -439,9 +439,9 @@ void plArmatureModBase::AdjustLOD() hsPoint3 delta = ourPos - camPos; float distanceSquared = delta.MagnitudeSquared(); if (distanceSquared < fLODDistance * fLODDistance) - SetLOD(max(0, fMinLOD)); + SetLOD(std::max(0, fMinLOD)); else if (distanceSquared < fLODDistance * fLODDistance * 4.0) - SetLOD(max(1, fMinLOD)); + SetLOD(std::max(1, fMinLOD)); else SetLOD(2); } diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvBehaviors.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvBehaviors.cpp index bb78bf1c..63594843 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvBehaviors.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvBehaviors.cpp @@ -106,7 +106,7 @@ void plArmatureBehavior::DumpDebug(int &x, int &y, int lineHeight, plDebugText & float strength = GetStrength(); const char *onOff = strength > 0 ? "on" : "off"; char blendBar[] = "||||||||||"; - int bars = (int)min(10 * strength, 10); + int bars = std::min(static_cast(10 * strength), 10); blendBar[bars] = '\0'; plString details; diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainSwim.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainSwim.cpp index 94b7b77a..8db5b732 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainSwim.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvBrainSwim.cpp @@ -179,7 +179,7 @@ public: float oldSpeed = fabs(fSwimBrain->fSwimStrategy->GetTurnStrength()); float thisInc = elapsed * incPerSec; - float newSpeed = min(oldSpeed + thisInc, maxTurnSpeed); + float newSpeed = std::min(oldSpeed + thisInc, maxTurnSpeed); fSwimBrain->fSwimStrategy->SetTurnStrength(newSpeed * fAvMod->GetKeyTurnStrength() + fAvMod->GetAnalogTurnStrength()); // the turn is actually applied during PhysicsUpdate } diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plPhysicalControllerCore.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plPhysicalControllerCore.cpp index c515e7f1..8a4a5903 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plPhysicalControllerCore.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plPhysicalControllerCore.cpp @@ -577,7 +577,7 @@ bool plWalkingStrategy::EnableControlledFlight(bool status) ++fControlledFlight; } else - fControlledFlight = max(--fControlledFlight, 0); + fControlledFlight = std::max(--fControlledFlight, 0); return status; } diff --git a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp index c99c4b19..b3dc5622 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp @@ -713,7 +713,7 @@ bool plSecureStream::GetSecureEncryptionKey(const plFileName& filename, uint32_t file.Close(); - unsigned memSize = min(bytesToRead, bytesRead); + unsigned memSize = std::min(bytesToRead, bytesRead); memcpy(key, buffer, memSize); free(buffer); @@ -721,7 +721,7 @@ bool plSecureStream::GetSecureEncryptionKey(const plFileName& filename, uint32_t } // file doesn't exist, use default key - unsigned memSize = min(length, arrsize(plSecureStream::kDefaultKey)); + unsigned memSize = std::min(length, arrsize(plSecureStream::kDefaultKey)); memSize *= sizeof(uint32_t); memcpy(key, plSecureStream::kDefaultKey, memSize); diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index ff0bc694..eb4d37a0 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -2701,7 +2701,7 @@ bool LoginRequestTrans::Recv ( m_accountFlags = reply.accountFlags; m_billingType = reply.billingType; - unsigned memSize = min(arrsize(s_encryptionKey), arrsize(reply.encryptionKey)); + unsigned memSize = std::min(arrsize(s_encryptionKey), arrsize(reply.encryptionKey)); memSize *= sizeof(uint32_t); memcpy(s_encryptionKey, reply.encryptionKey, memSize); } @@ -5130,7 +5130,7 @@ void NetCliAuthStartConnect ( ) { // TEMP: Only connect to one auth server until we fill out this module // to choose the "best" auth connection. - authAddrCount = min(authAddrCount, 1); + authAddrCount = std::min(authAddrCount, 1u); for (unsigned i = 0; i < authAddrCount; ++i) { // Do we need to lookup the address? @@ -5273,7 +5273,7 @@ void NetCliAuthGetEncryptionKey ( uint32_t key[], unsigned size ) { - unsigned memSize = min(arrsize(s_encryptionKey), size); + unsigned memSize = std::min(arrsize(s_encryptionKey), size); memSize *= sizeof(uint32_t); memcpy(key, s_encryptionKey, memSize); } diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp index 8086f4c5..cff25405 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp @@ -1350,7 +1350,7 @@ void NetCliFileStartConnect ( ) { // TEMP: Only connect to one file server until we fill out this module // to choose the "best" file connection. - fileAddrCount = min(fileAddrCount, 1); + fileAddrCount = std::min(fileAddrCount, 1u); s_connectBuildId = isPatcher ? kFileSrvBuildId : plProduct::BuildId(); s_serverType = kSrvTypeNone; @@ -1387,7 +1387,7 @@ void NetCliFileStartConnectAsServer ( ) { // TEMP: Only connect to one file server until we fill out this module // to choose the "best" file connection. - fileAddrCount = min(fileAddrCount, 1); + fileAddrCount = std::min(fileAddrCount, 1u); s_connectBuildId = serverBuildId; s_serverType = serverType; diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp index 4606f883..3d5673c3 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp @@ -1062,7 +1062,7 @@ void NetCliGateKeeperStartConnect ( const char* gateKeeperAddrList[], uint32_t gateKeeperAddrCount ) { - gateKeeperAddrCount = min(gateKeeperAddrCount, 1); + gateKeeperAddrCount = std::min(gateKeeperAddrCount, 1u); for (unsigned i = 0; i < gateKeeperAddrCount; ++i) { // Do we need to lookup the address? diff --git a/Sources/Plasma/PubUtilLib/plSockets/plBufferedSocketWriter.cpp b/Sources/Plasma/PubUtilLib/plSockets/plBufferedSocketWriter.cpp index 609e8902..5468c00b 100644 --- a/Sources/Plasma/PubUtilLib/plSockets/plBufferedSocketWriter.cpp +++ b/Sources/Plasma/PubUtilLib/plSockets/plBufferedSocketWriter.cpp @@ -79,7 +79,7 @@ int plBufferedSocketWriter::Flush(plTcpSocket & sck) // this is where things { int ans = kSuccessNoDataSent; - int writeSize = MIN(FastAmountBuffered(),fBytesPerFlush); + int writeSize = std::min(FastAmountBuffered(), fBytesPerFlush); if(writeSize > 0) {