diff --git a/Sources/Plasma/CoreLib/plString.cpp b/Sources/Plasma/CoreLib/plString.cpp index 9b179949..08bab171 100644 --- a/Sources/Plasma/CoreLib/plString.cpp +++ b/Sources/Plasma/CoreLib/plString.cpp @@ -924,14 +924,28 @@ plStringStream &plStringStream::operator<<(const char *text) plStringStream &plStringStream::operator<<(int num) { char buffer[12]; - snprintf(buffer, 12, "%d", num); + snprintf(buffer, arrsize(buffer), "%d", num); return operator<<(buffer); } plStringStream &plStringStream::operator<<(unsigned int num) { char buffer[12]; - snprintf(buffer, 12, "%u", num); + snprintf(buffer, arrsize(buffer), "%u", num); + return operator<<(buffer); +} + +plStringStream &plStringStream::operator<<(int64_t num) +{ + char buffer[24]; + snprintf(buffer, arrsize(buffer), "%lld", num); + return operator<<(buffer); +} + +plStringStream &plStringStream::operator<<(uint64_t num) +{ + char buffer[24]; + snprintf(buffer, arrsize(buffer), "%llu", num); return operator<<(buffer); } diff --git a/Sources/Plasma/CoreLib/plString.h b/Sources/Plasma/CoreLib/plString.h index 536031ea..3304ffac 100644 --- a/Sources/Plasma/CoreLib/plString.h +++ b/Sources/Plasma/CoreLib/plString.h @@ -753,6 +753,12 @@ public: /** Append a base-10 formatted unsigned integer to the stream. */ plStringStream &operator<<(unsigned int num); + /** Append a base-10 formatted signed 64-bit integer to the stream. */ + plStringStream &operator<<(int64_t num); + + /** Append a base-10 formatted unsigned 64-bit integer to the stream. */ + plStringStream &operator<<(uint64_t num); + /** Append a base-10 formatted float to the stream. */ plStringStream &operator<<(float num) { return operator<<(static_cast(num)); } diff --git a/Sources/Plasma/NucleusLib/pnEncryption/plRandom.h b/Sources/Plasma/NucleusLib/pnEncryption/plRandom.h index 177ce4c5..ba2172a1 100644 --- a/Sources/Plasma/NucleusLib/pnEncryption/plRandom.h +++ b/Sources/Plasma/NucleusLib/pnEncryption/plRandom.h @@ -83,7 +83,7 @@ inline float plRandom::RandNorm() const inline int plRandom::Rand() const { #ifndef FAST_Q - register int temp; + int temp; fSeed = fSeed * 1103515245 + 12345; temp = (int)((fSeed/65536)&32767); return (temp); diff --git a/Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp b/Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp index e4742937..242a0fd5 100644 --- a/Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp +++ b/Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp @@ -74,8 +74,12 @@ bool IsTrackedKey(const plKeyImp* key) } #endif +hsKeyedObject* plKeyImp::SafeGetObject(const plKeyImp* key) { + return key ? key->fObjectPtr : nullptr; +} + plKeyImp::plKeyImp() : - fObjectPtr(nil), + fObjectPtr(nil), fStartPos(-1), fDataLen(-1), fNumActiveRefs(0), @@ -89,7 +93,7 @@ plKeyImp::plKeyImp() : plKeyImp::plKeyImp(plUoid u, uint32_t pos,uint32_t len): fUoid(u), - fObjectPtr(nil), + fObjectPtr(nil), fStartPos(pos), fDataLen(len), fNumActiveRefs(0), @@ -104,7 +108,7 @@ plKeyImp::plKeyImp(plUoid u, uint32_t pos,uint32_t len): #endif } -plKeyImp::~plKeyImp() +plKeyImp::~plKeyImp() { plProfile_DelMem(KeyMem, CalcKeySize(this)); @@ -137,7 +141,7 @@ plKeyImp::~plKeyImp() void plKeyImp::SetUoid(const plUoid& uoid) { - fUoid = uoid; + fUoid = uoid; #ifdef HS_DEBUGGING fIDName = fUoid.GetObjectName(); fClassType = plFactory::GetNameOfClass(fUoid.GetClassType()); @@ -145,18 +149,18 @@ void plKeyImp::SetUoid(const plUoid& uoid) } const plString& plKeyImp::GetName() const -{ - return fUoid.GetObjectName(); +{ + return fUoid.GetObjectName(); } hsKeyedObject* plKeyImp::GetObjectPtr() -{ +{ return ObjectIsLoaded(); } hsKeyedObject* plKeyImp::ObjectIsLoaded() const { - return this ? fObjectPtr : nil; + return plKeyImp::SafeGetObject(this); } // Copy the contents of p for cloning process @@ -170,8 +174,8 @@ void plKeyImp::CopyForClone(const plKeyImp *p, uint32_t playerID, uint32_t clone fClassType = plFactory::GetNameOfClass( fUoid.GetClassType() ); #endif - fStartPos = p->GetStartPos(); - fDataLen = p->GetDataLen(); + fStartPos = p->GetStartPos(); + fDataLen = p->GetDataLen(); fUoid.SetClone(playerID, cloneID); } @@ -269,9 +273,9 @@ hsKeyedObject* plKeyImp::RefObject(plRefFlags::Type flags) return VerifyLoaded(); // load object on demand } -void plKeyImp::UnRefObject(plRefFlags::Type flags) +void plKeyImp::UnRefObject(plRefFlags::Type flags) { - // Rather than using hsRefCnt's, make Ref and + // Rather than using hsRefCnt's, make Ref and // UnRef work with ActiveRef system if ( (flags == plRefFlags::kPassiveRef) && !ObjectIsLoaded()) return; @@ -288,7 +292,7 @@ void plKeyImp::UnRefObject(plRefFlags::Type flags) IClearRefs(); ClearNotifyCreated(); - + plKey key=plKey::Make( this ); // for linux build plSelfDestructMsg* nuke = new plSelfDestructMsg( key ); plgDispatch::Dispatch()->MsgSend(nuke); @@ -296,7 +300,7 @@ void plKeyImp::UnRefObject(plRefFlags::Type flags) } hsKeyedObject* plKeyImp::SetObjectPtr(hsKeyedObject* p) -{ +{ hsKeyedObject* retVal = nil; // If our object is the only one with a ref to us, this function will crash, so we @@ -317,7 +321,7 @@ hsKeyedObject* plKeyImp::SetObjectPtr(hsKeyedObject* p) #endif hsAssert(!fObjectPtr, "Setting an ObjectPtr thats already Set!"); - + retVal = fObjectPtr = p; } else @@ -329,20 +333,20 @@ hsKeyedObject* plKeyImp::SetObjectPtr(hsKeyedObject* p) retVal = nil; } - return retVal; + return retVal; } -void plKeyImp::ClearNotifyCreated() -{ +void plKeyImp::ClearNotifyCreated() +{ for (int i = 0; i < fNotifyCreated.GetCount(); i++) hsRefCnt_SafeUnRef(fNotifyCreated[i]); - fNotifyCreated.Reset(); + fNotifyCreated.Reset(); fNotified.Reset(); fActiveRefs.Reset(); } -void plKeyImp::AddNotifyCreated(plRefMsg* msg, plRefFlags::Type flags) -{ +void plKeyImp::AddNotifyCreated(plRefMsg* msg, plRefFlags::Type flags) +{ if (!(flags == plRefFlags::kPassiveRef)) { #ifdef LOG_ACTIVE_REFS @@ -358,13 +362,13 @@ void plKeyImp::AddNotifyCreated(plRefMsg* msg, plRefFlags::Type flags) } hsRefCnt_SafeRef(msg); - fNotifyCreated.Append(msg); + fNotifyCreated.Append(msg); } -void plKeyImp::RemoveNotifyCreated(int i) -{ +void plKeyImp::RemoveNotifyCreated(int i) +{ hsRefCnt_SafeUnRef(fNotifyCreated[i]); - fNotifyCreated.Remove(i); + fNotifyCreated.Remove(i); fNotified.RemoveBit(i); fActiveRefs.RemoveBit(i); @@ -536,9 +540,9 @@ void plKeyImp::NotifyCreated() hsKeyedObject* ko = GetObjectPtr(); hsRefCnt_SafeRef(ko); hsAssert(ko, "Notifying of created before on nil object"); - + INotifySelf(ko); - + for (int i = 0; i < GetNumNotifyCreated(); i++) { if (!IsNotified(i) && GetNotifyCreated(i)->GetReceiver(0)->GetObjectPtr()) @@ -552,7 +556,7 @@ void plKeyImp::NotifyCreated() SetNotified(i); SatisfyPending(msg); - plgDispatch::MsgSend(msg); + plgDispatch::MsgSend(msg); } } hsRefCnt_SafeUnRef(ko); @@ -645,7 +649,7 @@ void plKeyImp::IRelease(plKeyImp* iTargetKey) iTargetKey->IClearRefs(); iTargetKey->ClearNotifyCreated(); - + plKey key = plKey::Make(iTargetKey); plSelfDestructMsg* nuke = new plSelfDestructMsg(key); plgDispatch::Dispatch()->MsgSend(nuke); diff --git a/Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.h b/Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.h index 5b0d070e..e1f8c80a 100644 --- a/Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.h +++ b/Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.h @@ -53,6 +53,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com //------------------------------------ class plKeyImp : public plKeyData { +private: + static hsKeyedObject* SafeGetObject(const plKeyImp* key); + public: plKeyImp(); plKeyImp(plUoid, uint32_t pos,uint32_t len); diff --git a/Sources/Plasma/NucleusLib/pnUUID/pnUUID_Unix.cpp b/Sources/Plasma/NucleusLib/pnUUID/pnUUID_Unix.cpp index 565fbc51..4860c50d 100644 --- a/Sources/Plasma/NucleusLib/pnUUID/pnUUID_Unix.cpp +++ b/Sources/Plasma/NucleusLib/pnUUID/pnUUID_Unix.cpp @@ -78,9 +78,14 @@ bool plUUID::IsNull() const return ( uuid_is_null( g )!=0 ); } -void plUUID::CopyFrom( const plUUID * v ) +void plUUID::CopyFrom(const plUUID* v) { - memcpy( (void*)fData, (const void*)v->fData, sizeof(fData) ); + memcpy((void*)fData, (const void*)v->fData, sizeof(fData)); +} + +void plUUID::CopyFrom(const plUUID& v) +{ + memcpy((void*)fData, (const void*)v.fData, sizeof(fData)); } int plUUID::CompareTo( const plUUID * v ) const diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp index 1922461e..10643fec 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp @@ -84,19 +84,6 @@ namespace Crypt { * ***/ -//============================================================================ -static void Rc4Codec ( - CryptKey * key, - bool encrypt, - ARRAY(uint8_t) * dest, - unsigned sourceBytes, - const void * sourceData -) { - // RC4 uses the same algorithm to both encrypt and decrypt - dest->SetCount(sourceBytes); - RC4((RC4_KEY *)key->handle, sourceBytes, (const unsigned char *)sourceData, dest->Ptr()); -} - //============================================================================ static void Rc4Codec ( CryptKey * key, @@ -158,52 +145,12 @@ void CryptKeyClose ( delete key; } -//============================================================================ -unsigned CryptKeyGetBlockSize ( - CryptKey * key -) { - switch (key->algorithm) { - case kCryptRc4: { - return 1; - } - break; - - case kCryptRsa: // Not implemented; fall-thru to FATAL -// return RsaGetBlockSize(key); - - DEFAULT_FATAL(algorithm); - } -} - -//============================================================================ -void CryptEncrypt ( - CryptKey * key, - ARRAY(uint8_t) * dest, - unsigned sourceBytes, - const void * sourceData -) { - switch (key->algorithm) { - case kCryptRc4: { - Rc4Codec(key, true, dest, sourceBytes, sourceData); - } - break; - - case kCryptRsa: // Not implemented; fall-thru to FATAL -// RsaCodec(key, true, dest, sourceBytes, sourceData); -// break; - - DEFAULT_FATAL(key->algorithm); - } -} - //============================================================================ void CryptEncrypt ( CryptKey * key, unsigned bytes, void * data ) { - ASSERT(1 == CryptKeyGetBlockSize(key)); - switch (key->algorithm) { case kCryptRc4: { Rc4Codec(key, true, bytes, data); @@ -218,35 +165,12 @@ void CryptEncrypt ( } } -//============================================================================ -void CryptDecrypt ( - CryptKey * key, - ARRAY(uint8_t) * dest, - unsigned sourceBytes, - const void * sourceData -) { - switch (key->algorithm) { - case kCryptRc4: { - Rc4Codec(key, false, dest, sourceBytes, sourceData); - } - break; - - case kCryptRsa: // Not implemented; fall-thru to FATAL -// RsaCodec(key, false, dest, sourceBytes, sourceData); -// break; - - DEFAULT_FATAL(key->algorithm); - } -} - //============================================================================ void CryptDecrypt ( CryptKey * key, unsigned bytes, void * data ) { - ASSERT(1 == CryptKeyGetBlockSize(key)); - switch (key->algorithm) { case kCryptRc4: { Rc4Codec(key, false, bytes, data); diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h index 4b5ed241..bbf0ea6b 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h @@ -83,45 +83,18 @@ void CryptKeyClose ( CryptKey * key ); -void CryptKeyGenerate ( - ECryptAlgorithm algorithm, - unsigned keyBits, // used for algorithms with variable key strength - unsigned randomBytes, - const void * randomData, - ARRAY(uint8_t) * privateData, - ARRAY(uint8_t) * publicData // only for public key cryptography -); - -unsigned CryptKeyGetBlockSize ( - CryptKey * key -); - /***************************************************************************** * * Encryption and Decryption * ***/ -void CryptEncrypt ( - CryptKey * key, - ARRAY(uint8_t) * dest, - unsigned sourceBytes, - const void * sourceData -); - void CryptEncrypt ( CryptKey * key, unsigned bytes, void * data ); -void CryptDecrypt ( - CryptKey * key, - ARRAY(uint8_t) * dest, // padded out to the algorithm's block size - unsigned sourceBytes, - const void * sourceData -); - void CryptDecrypt ( CryptKey * key, unsigned bytes, diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtList.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtList.h index 0594f0c6..27a9e9bc 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtList.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtList.h @@ -74,7 +74,6 @@ enum ELinkType { #define LINK(class) TLink< class > #define LIST(class) TList< class > #define LISTDECL(class,field) TListDecl< class, offsetof(class,field) > -#define LISTDYN(class) TListDyn< class > /**************************************************************************** @@ -618,25 +617,4 @@ template TListDecl::TListDecl () { this->SetLinkOffset(linkOffset); } - - -/**************************************************************************** -* -* TListDyn -* -***/ - -template -class TListDyn : public TList { - -public: - void Initialize (int linkOffset); - -}; - -//=========================================================================== -template -void TListDyn::Initialize (int linkOffset) { - this->SetLinkOffset(linkOffset); -} #endif diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtPriQ.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtPriQ.h index 3ca71606..bf86661f 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtPriQ.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtPriQ.h @@ -58,7 +58,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define PRIORITY_TIME(class) TPriorityTime< class > -#define PRIQ(class,priority) TPriorityQueue< class,priority > #define PRIQDECL(class,priority,field) TPriorityQueueDecl< class,priority,offsetof(class,field) > diff --git a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp index b3ba4a99..f6452d53 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp @@ -88,7 +88,7 @@ plEncryptedStream::~plEncryptedStream() // void plEncryptedStream::IEncipher(uint32_t* const v) { - register uint32_t y=v[0], z=v[1], sum=0, delta=0x9E3779B9, n=32; + uint32_t y=v[0], z=v[1], sum=0, delta=0x9E3779B9, n=32; while (n-- > 0) { @@ -102,7 +102,7 @@ void plEncryptedStream::IEncipher(uint32_t* const v) void plEncryptedStream::IDecipher(uint32_t* const v) { - register uint32_t y=v[0], z=v[1], sum=0xC6EF3720, delta=0x9E3779B9, n=32; + uint32_t y=v[0], z=v[1], sum=0xC6EF3720, delta=0x9E3779B9, n=32; // sum = delta<<5, in general sum = delta * n diff --git a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp index 25d47a8c..40350191 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp @@ -111,8 +111,8 @@ plSecureStream::~plSecureStream() void plSecureStream::IEncipher(uint32_t* const v, uint32_t n) { - register unsigned long y=v[0], z=v[n-1], e, delta=0x9E3779B9; - register unsigned long q = 6 + 52/n, p, sum = 0; + unsigned long y=v[0], z=v[n-1], e, delta=0x9E3779B9; + unsigned long q = 6 + 52/n, p, sum = 0; while (q-- > 0) { @@ -132,8 +132,8 @@ void plSecureStream::IEncipher(uint32_t* const v, uint32_t n) void plSecureStream::IDecipher(uint32_t* const v, uint32_t n) { - register unsigned long y=v[0], z=v[n-1], e, delta=0x9E3779B9; - register unsigned long q = 6 + 52/n, p, sum = q * delta; + unsigned long y=v[0], z=v[n-1], e, delta=0x9E3779B9; + unsigned long q = 6 + 52/n, p, sum = q * delta; while (sum > 0) { diff --git a/Sources/Plasma/PubUtilLib/plMath/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plMath/CMakeLists.txt index 5be16a99..fc7800f3 100644 --- a/Sources/Plasma/PubUtilLib/plMath/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plMath/CMakeLists.txt @@ -3,17 +3,12 @@ include_directories("../../NucleusLib") include_directories("../../PubUtilLib") set(plMath_SOURCES - hsNoiseFunc.cpp hsRadixSort.cpp - plAvg.cpp plTriUtils.cpp ) set(plMath_HEADERS - hsNoiseFunc.h hsRadixSort.h - hsSearchVersion.h - plAvg.h plTriUtils.h ) diff --git a/Sources/Plasma/PubUtilLib/plMath/hsNoiseFunc.cpp b/Sources/Plasma/PubUtilLib/plMath/hsNoiseFunc.cpp deleted file mode 100644 index 7e3a43dc..00000000 --- a/Sources/Plasma/PubUtilLib/plMath/hsNoiseFunc.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#include "hsNoiseFunc.h" -#include "HeadSpin.h" - -#include "hsGeometry3.h" - -hsNoiseFunc::hsNoiseFunc() -{ -} - -hsNoiseFunc::~hsNoiseFunc() -{ -} - -void hsNoiseFunc::Seed(uint32_t s) -{ - srand(s); -} - -hsTableNoise::hsTableNoise() -: fTable(nil), fTableLen(0) -{ -} - -hsTableNoise::~hsTableNoise() -{ - delete [] fTable; -} - -void hsTableNoise::SetTable(int len, float* arr) -{ - fTableLen = len; - - delete [] fTable; - if( !len ) - { - fTable = nil; - return; - } - - fTable = new float[len+2]; - - int i; - for( i = 0; i < len; i++ ) - fTable[i] = arr[i]; - fTable[i++] = fTable[i-1]; - fTable[i++] = fTable[i-1]; - -} - -float hsTableNoise::Noise(float lo, float hi, float t) -{ - hsAssert(fTableLen, "Badly initialized table noise function"); - - float r = float(rand()) / float(RAND_MAX); - r = lo + (hi - lo) * r; - - if( t < 0 ) - t = 0; - else if( t > 1.f ) - t = 1.f; - - float tIdx = t * fTableLen; - uint32_t idx = uint32_t(tIdx); - float frac = tIdx - float(idx); - hsAssert((idx >= 0)&&(idx <= fTableLen), "Noise parm t out of range [0..1]"); - - float scale = fTable[idx] + (fTable[idx+1] - fTable[idx]) * frac; - - r *= scale; - - return r; -} - -float hsTableNoise::NoisePoint(const hsPoint3& p, float lo, float hi, float t) -{ - hsAssert(fTableLen, "Badly initialized table noise function"); - - uint32_t sX = *((uint32_t*)&p.fX); - uint32_t sY = *((uint32_t*)&p.fY); - uint32_t sZ = *((uint32_t*)&p.fZ); - - uint32_t sAll = ((((sX & 0x07800000) >> 16) | ((sX & 0x007fffff) >> 17)) << 20) - | ((((sY & 0x07800000) >> 16) | ((sY & 0x007fffff) >> 17)) << 10) - | ((((sZ & 0x07800000) >> 16) | ((sZ & 0x007fffff) >> 17)) ); - - const uint32_t kExp = 0x3f800000; - const uint32_t kMsk = 0x007fffff; - - const uint32_t kA = 1665636L; - const uint32_t kC = 1013904223L; - - uint32_t iR = kA * sAll + kC; - iR &= kMsk; - iR |= kExp; - - float r = (*(float*)&iR) - 1.f; - - r = lo + (hi - lo) * r; - - if( t < 0 ) - t = 0; - else if( t > 1.f ) - t = 1.f; - - float tIdx = t * fTableLen; - uint32_t idx = uint32_t(tIdx); - float frac = tIdx - float(idx); - hsAssert((idx >= 0)&&(idx <= fTableLen), "Noise parm t out of range [0..1]"); - - float scale = fTable[idx] + (fTable[idx+1] - fTable[idx]) * frac; - - r *= scale; - - return r; -} diff --git a/Sources/Plasma/PubUtilLib/plMath/hsNoiseFunc.h b/Sources/Plasma/PubUtilLib/plMath/hsNoiseFunc.h deleted file mode 100644 index 69ff288b..00000000 --- a/Sources/Plasma/PubUtilLib/plMath/hsNoiseFunc.h +++ /dev/null @@ -1,82 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ - -#ifndef hsNoiseFunc_inc -#define hsNoiseFunc_inc - -#include "HeadSpin.h" -#include "hsRefCnt.h" - -struct hsPoint3; - -class hsNoiseFunc : public hsRefCnt // should inherit from keyed object -{ -public: - hsNoiseFunc(); - virtual ~hsNoiseFunc(); - - virtual void Seed(uint32_t s); - virtual float Noise(float lo=0, float hi=1.f, float t=0) = 0; // t = [0..1] - returns random num [lo..hi] scaled by fTable[t] - - virtual float NoisePoint(const hsPoint3& p, float lo=0, float hi=1.f, float t=0) = 0; // t = [0..1] - returns random num [lo..hi] scaled by fTable[t] -}; - -class hsTableNoise : public hsNoiseFunc // should inherit from keyed object -{ -protected: - float* fTable; - uint32_t fTableLen; - - -public: - hsTableNoise(); - virtual ~hsTableNoise(); - - void SetTable(int len, float* arr); // copies. arr should be hsScalars in range [0..1] - float* GetTable(int& len) { len = fTableLen; return fTable; } // should be debug only, access through noise func - - virtual float Noise(float lo=0, float hi=1.f, float t=0); // t = [0..1] - returns random num [lo..hi] scaled by fTable[t] - - virtual float NoisePoint(const hsPoint3& p, float lo=0, float hi=1.f, float t=0); // t = [0..1] - returns random num [lo..hi] scaled by fTable[t] -}; - -#endif // hsNoiseFunc_inc diff --git a/Sources/Plasma/PubUtilLib/plMath/hsSearchVersion.h b/Sources/Plasma/PubUtilLib/plMath/hsSearchVersion.h deleted file mode 100644 index ec608cc0..00000000 --- a/Sources/Plasma/PubUtilLib/plMath/hsSearchVersion.h +++ /dev/null @@ -1,181 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ - -#ifndef hsSearchVersion_inc -#define hsSearchVersion_inc - -#include "HeadSpin.h" - -/* -do a template of lists to search for a matching entry. basic idea is that -you start off with an array of buckets and you know that you will get at -least one, possibly several, in each bucket. when you go to search, you already -know which bucket it will be in if it's there. even as the array is being filled, -each filled entry in each bucket has a valid forever index, as well as it's key -value. so array is fixed length, index into array has no bearing on forever index, -elements of array can grow, and at all times the used forever indices form a contiguous -set from 0 to max forever index. -*/ - -template class hsVersionNode { -protected: - T fData; - int32_t fIndex; - hsVersionNode* fNext; -public: - hsVersionNode(const uint32_t idx, const T &data) : fIndex(idx), fNext(nil) { fData = data; } - ~hsVersionNode() { delete fNext; } - - hsVersionNode* Next() const { return fNext; } - - int32_t Index() const { return fIndex; } - - inline void Append(hsVersionNode* next); - inline int operator==(const T& o) const; - - int operator!=(const T& o) const { return !(this->operator==(o)); } - - T& GetData() { return fData; } -}; - -template int hsVersionNode::operator==(const T& data) const -{ - return fData == data; -} - -template void hsVersionNode::Append(hsVersionNode* next) -{ - if( fNext ) - fNext->Append(next); - else - fNext = next; -} - -template class hsSearchVersion { -protected: - uint32_t fLength; - hsVersionNode** fArray; - uint32_t fNextIndex; - uint32_t fNumIndex; - uint32_t fIncIndex; - T** fBackArray; - - void ICheckBackArray(); -public: - hsSearchVersion(uint32_t len, uint32_t inc = 0); - ~hsSearchVersion(); - - T& operator[]( int32_t index ); - - int32_t Find(int where, const T& what, bool forceUnique=false); - - uint32_t GetCount() const { return fNextIndex; } -}; - -template T& hsSearchVersion::operator[]( int32_t index ) -{ - hsDebugCode(hsThrowIfBadParam((uint32_t)index >= (uint32_t)fNextIndex);) - - return *fBackArray[index]; -} - -template hsSearchVersion::hsSearchVersion(uint32_t len, uint32_t inc) - : fNextIndex(0) -{ - fIncIndex = inc ? inc : len; - fLength = len; - fArray = new hsVersionNode*[fLength]; - HSMemory::Clear(fArray, fLength*sizeof(*fArray)); - fBackArray = new T*[fNumIndex = fLength]; -} - -template hsSearchVersion::~hsSearchVersion() -{ - int i; - for( i = 0; i < fLength; i++ ) - delete fArray[i]; - delete [] fArray; - delete [] fBackArray; -} - -template void hsSearchVersion::ICheckBackArray() -{ - if( fNextIndex >= fNumIndex ) - { - T** newBackArray = new T*[fNumIndex + fIncIndex]; - HSMemory::BlockMove(fBackArray, newBackArray, fNextIndex*sizeof(T*)); - delete [] fBackArray; - fBackArray = newBackArray; - fNumIndex += fIncIndex; - } -} - -template int32_t hsSearchVersion::Find(int where, const T&what, bool forceUnique) -{ - hsVersionNode* curr = fArray[where]; - - ICheckBackArray(); - - if( !curr ) - { - hsVersionNode* next = new hsVersionNode(fNextIndex, what); - fArray[where] = next; - fBackArray[fNextIndex] = &next->GetData(); - return fNextIndex++; - } - if( *curr == what ) - return curr->Index(); - - while( curr->Next() - && (forceUnique || (*curr->Next() != what)) ) - curr = curr->Next(); - - if( curr->Next() ) - return curr->Next()->Index(); - - hsVersionNode* next = new hsVersionNode(fNextIndex, what); - curr->Append(next); - fBackArray[fNextIndex] = &next->GetData(); - return fNextIndex++; -} - -#endif // hsSearchVersion_inc diff --git a/Sources/Plasma/PubUtilLib/plMath/plAvg.cpp b/Sources/Plasma/PubUtilLib/plMath/plAvg.cpp deleted file mode 100644 index 579a5812..00000000 --- a/Sources/Plasma/PubUtilLib/plMath/plAvg.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ - -#include "HeadSpin.h" -#include "plAvg.h" -#include -#include - -template class TimeBasedAvgRing; -template class TimeBasedAvgRing; - -#define PercisionRoundUp(x) (ceil(x / kPercision) * kPercision) - -template -const float TimeBasedAvgRing::kPercision = 0.001; - -template -void TimeBasedAvgRing::AddItem(T value, double time) -{ - std::lock_guard lock(fLock); - - if ( fList.empty() ) - { - // initialize with the first time and zero the first value - fList.insert(fList.end(),Item(0.0,time)); - fRingStart = fRingEnd = fList.begin(); - fAvg = (float)value; - } - else - { - // if we're within the percision amount subtract the RingEnd value from total - // and update the RingEnd value by adding the current value to it - if (time - (*fRingEnd).GetTime() <= kPercision) - { - fTotal -= PercisionRoundUp((*fRingEnd).GetValue()); - (*fRingEnd).SetValue((*fRingEnd).GetValue() + value); - } - else - { - // clean up the begining of the ring - //// there can be some precision loss in the loop time calc - //// check to see if the difference is within 1 milli - while (time - (*fRingStart).GetTime() > fLen + kPercision - && fRingStart != fRingEnd) - { - // remove RingStart from the avg part of the average calc - fTotal -= (*fRingStart).GetValue(); - - typename TimeList::iterator prev = fRingStart++; - - // loop the ring if needed - if (fRingStart == fList.end()) - fRingStart = fList.begin(); - - - // if the new ring start is in the range, interpolate - // and reuse prev - if (time - (*fRingStart).GetTime() < fLen) - { - // remove RingStart from the avg part of the average calc - fTotal -= PercisionRoundUp((*fRingStart).GetValue()); - - // Set up the interp - double remainder = fLen - (time - (*fRingStart).GetTime()); - double timedelta = (*fRingStart).GetTime() - (*prev).GetTime(); - (*prev).SetTime((*fRingStart).GetTime() - remainder); - (*prev).SetValue(0); - // rounding loss occurs here if T is not floting point - double scale = remainder/timedelta; - hsAssert(scale < 1.0 && scale > 0.0,"Interp Scale Out of Bounds"); - (*fRingStart).SetValue((float)((*fRingStart).GetValue() * scale)); - - // add the new value in - fTotal += (*fRingStart).GetValue(); - - // put prev back as ring start - fRingStart = prev; - } - - } - - // zero total & fAvg if we looped or neg - if (fRingStart == fRingEnd || fTotal < 0.0) - { - fTotal = 0.0; - fAvg = 0.0; - } - - // put the new value in the ring by expanding the ring if needed - // or replacing an empty value - fRingEnd++; - if (fRingEnd == fList.end()) - fRingEnd = fList.begin(); - // Do we have free space? - if (fRingEnd == fRingStart) - { - // no free space - fList.insert(fRingEnd,Item(value,time)); - fRingEnd--; - } - else - { - // yes free space @ fRingEnd - (*fRingEnd) = Item(value,time); - } - } - - //update the avg - fTotal += (*fRingEnd).GetValue(); - double currentLen = (*fRingEnd).GetTime() - (*fRingStart).GetTime(); - if (currentLen < 1.0) - fAvg = (float)fTotal; - else - fAvg = (float)(fTotal / currentLen); - } - - // update the max avg - fMaxAvg = std::max(fMaxAvg, fAvg); - -} - diff --git a/Sources/Plasma/PubUtilLib/plMath/plAvg.h b/Sources/Plasma/PubUtilLib/plMath/plAvg.h deleted file mode 100644 index e4994cf1..00000000 --- a/Sources/Plasma/PubUtilLib/plMath/plAvg.h +++ /dev/null @@ -1,108 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#ifndef PL_AVG_H -#define PL_AVG_H - -#include "HeadSpin.h" -#include -#include - -// A Time based Value Averaging class -// implemented in a ring buffer -// Values are averaged over the RingLen -// independant of frame time -// The ring buffer will grow to accomadate -// as many samples as added during the Len -// Only Accurate to kPercision (0.001) of whatever units -// of time are used - -template class TimeBasedAvgRing -{ -/* T must be a simple type - - If T is not a floating point type then rounding - loss may occur when samples are interpolated - at window boundries -*/ -private: - static const float kPercision; - - template class Item - { - private: - T fValue; - double fTime; - public: - Item() { Reset(); } - Item(const T val, const double time) : fValue(val), fTime(time) { } - void Reset() { fValue = 0; fTime = 0; } - void SetValue(const T val) { fValue = val; } - void SetTime(const double time) { fTime = time; } - T GetValue() const { return fValue; } - double GetTime() const { return fTime; } - }; - typedef std::list< Item > TimeList; - typedef typename TimeList::iterator TimeListIterator; // .NET added typename to be C++ ISO compliant - JL - - TimeList fList; - float fLen; // in time - float fAvg; - float fMaxAvg; - double fTotal; - TimeListIterator fRingStart, fRingEnd; - std::mutex fLock; -public: - TimeBasedAvgRing():fLen(0.f),fAvg(0.f),fMaxAvg(0.f),fTotal(0.0) {} - - void SetRingLen(const float len) { fLen = len; } - float GetRingLen() const { return fLen; } - void AddItem(T value, double time); - float GetAvg() const { return fAvg; } - double GetTotal() const { return fTotal; } - float GetMaxAvg() const { return fMaxAvg; } - void ResetMaxAvg() { fMaxAvg=fAvg; } - void Reset() { fRingStart=fRingEnd; ResetMaxAvg(); } -}; - - -#endif // PL_AVG_H - diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsWinRef.h b/Sources/Plasma/PubUtilLib/plPipeline/hsWinRef.h index db465218..572e1930 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsWinRef.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsWinRef.h @@ -43,16 +43,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #ifndef hsWinRef_inc #define hsWinRef_inc +#include "HeadSpin.h" -#ifdef HS_BUILD_FOR_WIN32 - - -typedef HWND hsWinRef; - -#else // Whatever - -typedef void* hsWinRef; - -#endif +typedef hsWindowHndl hsWinRef; #endif // hsWinRef_inc diff --git a/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp b/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp index 8d7ddeea..81beeb02 100644 --- a/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp @@ -356,7 +356,7 @@ bool plPageTreeMgr::IRenderSortingSpans(plPipeline* pipe, hsTArrayfDrawable; listTrav = &scratchList[iSort++]; - listTrav->fBody = (void*)*(uint32_t*)&pairs[i]; + listTrav->fBody = (void*)&pairs[i]; listTrav->fNext = listTrav + 1; if( drawable->GetNativeProperty(plDrawable::kPropSortAsOne) ) @@ -404,7 +404,7 @@ bool plPageTreeMgr::IRenderSortingSpans(plPipeline* pipe, hsTArrayfBody; + plDrawSpanPair& curPair = *(plDrawSpanPair*)listTrav->fBody; drawList[curPair.fDrawable]->fVisList.Append(curPair.fSpan); listTrav = listTrav->fNext; } @@ -423,14 +423,14 @@ bool plPageTreeMgr::IRenderSortingSpans(plPipeline* pipe, hsTArrayfBody; + plDrawSpanPair& curPair = *(plDrawSpanPair*)listTrav->fBody; int curDraw = curPair.fDrawable; visList.Append(curPair.fSpan); listTrav = listTrav->fNext; while( listTrav ) { - curPair = *(plDrawSpanPair*)&listTrav->fBody; + curPair = *(plDrawSpanPair*)listTrav->fBody; if( curPair.fDrawable != curDraw ) { pipe->Render(drawList[curDraw]->fDrawable, visList); @@ -447,7 +447,7 @@ bool plPageTreeMgr::IRenderSortingSpans(plPipeline* pipe, hsTArrayRender(drawList[curDraw]->fDrawable, visList); #else listTrav = sortedList; - plDrawSpanPair& curPair = *(plDrawSpanPair*)&listTrav->fBody; + plDrawSpanPair& curPair = *(plDrawSpanPair*)listTrav->fBody; int curDraw = curPair.fDrawable; listTrav = listTrav->fNext; @@ -458,7 +458,7 @@ bool plPageTreeMgr::IRenderSortingSpans(plPipeline* pipe, hsTArrayfBody; + curPair = *(plDrawSpanPair*)listTrav->fBody; if( curPair.fDrawable != curDraw ) { pipe->Render(drawList[curDraw]->fDrawable, visList); @@ -704,4 +704,4 @@ void plPageTreeMgr::IResetOcclusion(plPipeline* pipe) { fCullPolys.SetCount(0); fSortedCullPolys.SetCount(0); -} \ No newline at end of file +} diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp index 92abff83..d9502411 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp @@ -60,15 +60,13 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsThread.h" #include "hsTemplates.h" #include "hsTimer.h" +#include "hsWindows.h" #include "plStatusLog.h" #include "plUnifiedTime/plUnifiedTime.h" #include "plProduct.h" #include "plEncryptLogLine.h" -#if HS_BUILD_FOR_WIN32 - #include -#endif ////////////////////////////////////////////////////////////////////////////// //// plStatusLogMgr Stuff //////////////////////////////////////////////////// diff --git a/Sources/Plasma/PubUtilLib/plTransform/mat_decomp.cpp b/Sources/Plasma/PubUtilLib/plTransform/mat_decomp.cpp index 73c275e2..d7257071 100644 --- a/Sources/Plasma/PubUtilLib/plTransform/mat_decomp.cpp +++ b/Sources/Plasma/PubUtilLib/plTransform/mat_decomp.cpp @@ -145,7 +145,7 @@ gemQuat Qt_FromMatrix(HMatrix mat) * Otherwise, the largest diagonal entry corresponds to the largest of |x|, * |y|, or |z|, one of which must be larger than |w|, and at least 1/2. */ gemQuat qu; - register double tr, s; + double tr, s; tr = mat[X][X] + mat[Y][Y]+ mat[Z][Z]; if (tr >= 0.0) {