Browse Source

Merge pull request #485 from dpogue/cleanups

Fixes and small cleanups
Michael Hansen 10 years ago
parent
commit
f11cde086d
  1. 18
      Sources/Plasma/CoreLib/plString.cpp
  2. 6
      Sources/Plasma/CoreLib/plString.h
  3. 2
      Sources/Plasma/NucleusLib/pnEncryption/plRandom.h
  4. 62
      Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp
  5. 3
      Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.h
  6. 9
      Sources/Plasma/NucleusLib/pnUUID/pnUUID_Unix.cpp
  7. 76
      Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.cpp
  8. 27
      Sources/Plasma/NucleusLib/pnUtils/pnUtCrypt.h
  9. 22
      Sources/Plasma/NucleusLib/pnUtils/pnUtList.h
  10. 1
      Sources/Plasma/NucleusLib/pnUtils/pnUtPriQ.h
  11. 4
      Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp
  12. 8
      Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp
  13. 5
      Sources/Plasma/PubUtilLib/plMath/CMakeLists.txt
  14. 156
      Sources/Plasma/PubUtilLib/plMath/hsNoiseFunc.cpp
  15. 82
      Sources/Plasma/PubUtilLib/plMath/hsNoiseFunc.h
  16. 181
      Sources/Plasma/PubUtilLib/plMath/hsSearchVersion.h
  17. 160
      Sources/Plasma/PubUtilLib/plMath/plAvg.cpp
  18. 108
      Sources/Plasma/PubUtilLib/plMath/plAvg.h
  19. 12
      Sources/Plasma/PubUtilLib/plPipeline/hsWinRef.h
  20. 14
      Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp
  21. 4
      Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp
  22. 2
      Sources/Plasma/PubUtilLib/plTransform/mat_decomp.cpp

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

6
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<double>(num)); }

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

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

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

9
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

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

27
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,

22
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<class T, int linkOffset>
TListDecl<T,linkOffset>::TListDecl () {
this->SetLinkOffset(linkOffset);
}
/****************************************************************************
*
* TListDyn
*
***/
template<class T>
class TListDyn : public TList<T> {
public:
void Initialize (int linkOffset);
};
//===========================================================================
template<class T>
void TListDyn<T>::Initialize (int linkOffset) {
this->SetLinkOffset(linkOffset);
}
#endif

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

4
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

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

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

156
Sources/Plasma/PubUtilLib/plMath/hsNoiseFunc.cpp

@ -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 <http://www.gnu.org/licenses/>.
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;
}

82
Sources/Plasma/PubUtilLib/plMath/hsNoiseFunc.h

@ -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 <http://www.gnu.org/licenses/>.
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

181
Sources/Plasma/PubUtilLib/plMath/hsSearchVersion.h

@ -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 <http://www.gnu.org/licenses/>.
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 T> class hsVersionNode {
protected:
T fData;
int32_t fIndex;
hsVersionNode<T>* fNext;
public:
hsVersionNode(const uint32_t idx, const T &data) : fIndex(idx), fNext(nil) { fData = data; }
~hsVersionNode() { delete fNext; }
hsVersionNode<T>* Next() const { return fNext; }
int32_t Index() const { return fIndex; }
inline void Append(hsVersionNode<T>* next);
inline int operator==(const T& o) const;
int operator!=(const T& o) const { return !(this->operator==(o)); }
T& GetData() { return fData; }
};
template <class T> int hsVersionNode<T>::operator==(const T& data) const
{
return fData == data;
}
template <class T> void hsVersionNode<T>::Append(hsVersionNode<T>* next)
{
if( fNext )
fNext->Append(next);
else
fNext = next;
}
template <class T> class hsSearchVersion {
protected:
uint32_t fLength;
hsVersionNode<T>** 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 <class T> T& hsSearchVersion<T>::operator[]( int32_t index )
{
hsDebugCode(hsThrowIfBadParam((uint32_t)index >= (uint32_t)fNextIndex);)
return *fBackArray[index];
}
template <class T> hsSearchVersion<T>::hsSearchVersion(uint32_t len, uint32_t inc)
: fNextIndex(0)
{
fIncIndex = inc ? inc : len;
fLength = len;
fArray = new hsVersionNode<T>*[fLength];
HSMemory::Clear(fArray, fLength*sizeof(*fArray));
fBackArray = new T*[fNumIndex = fLength];
}
template <class T> hsSearchVersion<T>::~hsSearchVersion()
{
int i;
for( i = 0; i < fLength; i++ )
delete fArray[i];
delete [] fArray;
delete [] fBackArray;
}
template <class T> void hsSearchVersion<T>::ICheckBackArray()
{
if( fNextIndex >= fNumIndex )
{
T** newBackArray = new T*[fNumIndex + fIncIndex];
HSMemory::BlockMove(fBackArray, newBackArray, fNextIndex*sizeof(T*));
delete [] fBackArray;
fBackArray = newBackArray;
fNumIndex += fIncIndex;
}
}
template <class T> int32_t hsSearchVersion<T>::Find(int where, const T&what, bool forceUnique)
{
hsVersionNode<T>* curr = fArray[where];
ICheckBackArray();
if( !curr )
{
hsVersionNode<T>* next = new hsVersionNode<T>(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<T>* next = new hsVersionNode<T>(fNextIndex, what);
curr->Append(next);
fBackArray[fNextIndex] = &next->GetData();
return fNextIndex++;
}
#endif // hsSearchVersion_inc

160
Sources/Plasma/PubUtilLib/plMath/plAvg.cpp

@ -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 <http://www.gnu.org/licenses/>.
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 <cmath>
#include <algorithm>
template class TimeBasedAvgRing<float>;
template class TimeBasedAvgRing<double>;
#define PercisionRoundUp(x) (ceil(x / kPercision) * kPercision)
template <class T>
const float TimeBasedAvgRing<T>::kPercision = 0.001;
template <class T>
void TimeBasedAvgRing<T>::AddItem(T value, double time)
{
std::lock_guard<std::mutex> lock(fLock);
if ( fList.empty() )
{
// initialize with the first time and zero the first value
fList.insert(fList.end(),Item<T>(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<T>(value,time));
fRingEnd--;
}
else
{
// yes free space @ fRingEnd
(*fRingEnd) = Item<T>(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);
}

108
Sources/Plasma/PubUtilLib/plMath/plAvg.h

@ -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 <http://www.gnu.org/licenses/>.
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 <list>
#include <mutex>
// 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 T> 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 S> 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<T> > 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

12
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

14
Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp

@ -356,7 +356,7 @@ bool plPageTreeMgr::IRenderSortingSpans(plPipeline* pipe, hsTArray<plDrawVisList
plDrawable* drawable = drawList[pairs[i].fDrawable]->fDrawable;
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, hsTArray<plDrawVisList
listTrav = sortedList;
while( listTrav )
{
plDrawSpanPair& curPair = *(plDrawSpanPair*)&listTrav->fBody;
plDrawSpanPair& curPair = *(plDrawSpanPair*)listTrav->fBody;
drawList[curPair.fDrawable]->fVisList.Append(curPair.fSpan);
listTrav = listTrav->fNext;
}
@ -423,14 +423,14 @@ bool plPageTreeMgr::IRenderSortingSpans(plPipeline* pipe, hsTArray<plDrawVisList
#if 0
listTrav = sortedList;
plDrawSpanPair& curPair = *(plDrawSpanPair*)&listTrav->fBody;
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, hsTArray<plDrawVisList
pipe->Render(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, hsTArray<plDrawVisList
while( listTrav )
{
curPair = *(plDrawSpanPair*)&listTrav->fBody;
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);
}
}

4
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 <shlobj.h>
#endif
//////////////////////////////////////////////////////////////////////////////
//// plStatusLogMgr Stuff ////////////////////////////////////////////////////

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

Loading…
Cancel
Save