1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 11:19:10 +00:00

Complete the previous commit by also removing the inline min and max

functions defined in HeadSpin.h without breaking (3ds)Max compilation
This commit is contained in:
2014-07-22 22:22:22 -07:00
parent e36220cca5
commit 72f18e8ebb
20 changed files with 49 additions and 86 deletions

View File

@ -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);
}

View File

@ -242,51 +242,6 @@ inline void hsSwap(float& a, float& b)
# define NULL_STMT ((void)0)
#endif
//===========================================================================
template<class T>
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<class T>
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

View File

@ -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 <algorithm>
using std::min;
using std::max;
# endif
# define WIN32_LEAN_AND_MEAN

View File

@ -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);
}

View File

@ -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++) {

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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) {

View File

@ -740,25 +740,25 @@ public:
//===========================================================================
template<class T, class C>
TArray<T,C>::TArray () : TFArray<T,C>() {
m_chunkSize = max(1, 256 / sizeof(T));
m_chunkSize = std::max(1u, 256 / sizeof(T));
}
//===========================================================================
template<class T, class C>
TArray<T,C>::TArray (const char file[], int line) : TFArray<T,C>(file, line) {
m_chunkSize = max(1, 256 / sizeof(T));
m_chunkSize = std::max(1u, 256 / sizeof(T));
}
//===========================================================================
template<class T, class C>
TArray<T,C>::TArray (unsigned count) : TFArray<T,C>(count) {
m_chunkSize = max(1, 256 / sizeof(T));
m_chunkSize = std::max(1u, 256 / sizeof(T));
}
//===========================================================================
template<class T, class C>
TArray<T,C>::TArray (const T * source, unsigned count) : TFArray<T,C>(source, count) {
m_chunkSize = max(1, 256 / sizeof(T));
m_chunkSize = std::max(1u, 256 / sizeof(T));
}
//===========================================================================
@ -890,8 +890,8 @@ void TArray<T,C>::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<T,C>::Pop () {
//===========================================================================
template<class T, class C>
void TArray<T,C>::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<T,C>::SetChunkSize (unsigned chunkSize) {
//===========================================================================
template<class T, class C>
void TArray<T,C>::SetCount (unsigned count) {
AdjustSizeChunked(max(this->m_alloc, count), count);
AdjustSizeChunked(std::max(this->m_alloc, count), count);
}
//===========================================================================

View File

@ -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)

View File

@ -432,7 +432,7 @@ void TBaseHashTable<T>::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<unsigned>(kSlotMinCount), v));
}
}
@ -459,7 +459,7 @@ void TBaseHashTable<T>::SetSlotCount (unsigned count) {
template<class T>
void TBaseHashTable<T>::SetSlotMaxCount (unsigned count) {
if (count)
m_slotMaxCount = max(kSlotMinCount, count);
m_slotMaxCount = std::max(static_cast<unsigned>(kSlotMinCount), count);
}
//===========================================================================

View File

@ -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);
}

View File

@ -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<int>(10 * strength), 10);
blendBar[bars] = '\0';
plString details;

View File

@ -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
}

View File

@ -577,7 +577,7 @@ bool plWalkingStrategy::EnableControlledFlight(bool status)
++fControlledFlight;
}
else
fControlledFlight = max(--fControlledFlight, 0);
fControlledFlight = std::max(--fControlledFlight, 0);
return status;
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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;

View File

@ -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?

View File

@ -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)
{