mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 03:09:13 +00:00
Merge pull request #382 from zrax/ReadSafeString_plString
Get rid of hsStream::ReadSafe(W)String(Long)_TEMP
This commit is contained in:
@ -169,7 +169,7 @@ void plUoid::Read(hsStream* s)
|
||||
s->LogReadLE(&fClassType, "ClassType");
|
||||
s->LogReadLE(&fObjectID, "ObjectID");
|
||||
s->LogSubStreamPushDesc("ObjectName");
|
||||
fObjectName = s->LogReadSafeString_TEMP();
|
||||
fObjectName = s->LogReadSafeString();
|
||||
|
||||
// conditional cloneIDs read
|
||||
if (contents & kHasCloneIDs)
|
||||
|
@ -1351,7 +1351,7 @@ void proVariableEventData::IWriteNumber(hsStream * stream) {
|
||||
|
||||
void proVariableEventData::IRead(hsStream* stream, hsResMgr* mgr)
|
||||
{
|
||||
fName = stream->ReadSafeString_TEMP();
|
||||
fName = stream->ReadSafeString();
|
||||
fDataType = stream->ReadLE32();
|
||||
IReadNumber(stream);
|
||||
fKey = mgr->ReadKey(stream);
|
||||
@ -1379,7 +1379,7 @@ void proVariableEventData::IReadVersion(hsStream* s, hsResMgr* mgr)
|
||||
contentFlags.Read(s);
|
||||
|
||||
if (contentFlags.IsBitSet(kProVariableName))
|
||||
fName = s->ReadSafeString_TEMP();
|
||||
fName = s->ReadSafeString();
|
||||
if (contentFlags.IsBitSet(kProVariableDataType))
|
||||
fDataType = s->ReadLE32();
|
||||
if (contentFlags.IsBitSet(kProVariableNumber))
|
||||
|
@ -41,7 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
*==LICENSE==*/
|
||||
#include "hsStream.h"
|
||||
#include "plGenericVar.h"
|
||||
#include "hsMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// plGenericType
|
||||
@ -55,116 +54,93 @@ void plGenericType::Reset()
|
||||
|
||||
void plGenericType::CopyFrom(const plGenericType& c)
|
||||
{
|
||||
IDeallocString();
|
||||
fType = c.fType;
|
||||
if (fType==kString || fType==kAny)
|
||||
{
|
||||
fS=hsStrcpy(c.fS);
|
||||
fS = c.fS;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSMemory::BlockMove((void*)&c.fI, (void*)&fI, 4);
|
||||
memmove(&fD, &c.fD, sizeof(double));
|
||||
}
|
||||
}
|
||||
|
||||
//// Conversion Functions ////////////////////////////////////////////////////
|
||||
|
||||
const int32_t & plGenericType::IToInt( void ) const
|
||||
int32_t plGenericType::IToInt( void ) const
|
||||
{
|
||||
hsAssert( fType == kInt || fType == kAny, "Trying to use a non-int parameter as an int!" );
|
||||
|
||||
static int32_t i;
|
||||
if( fType == kAny )
|
||||
{
|
||||
hsAssert( fS != nil, "Weird parameter during conversion" );
|
||||
i = atoi( fS );
|
||||
return i;
|
||||
return fS.ToInt();
|
||||
}
|
||||
|
||||
return fI;
|
||||
}
|
||||
|
||||
const uint32_t & plGenericType::IToUInt( void ) const
|
||||
uint32_t plGenericType::IToUInt( void ) const
|
||||
{
|
||||
hsAssert( fType == kUInt || fType == kAny, "Trying to use a non-int parameter as an int!" );
|
||||
|
||||
static uint32_t i;
|
||||
if( fType == kAny )
|
||||
{
|
||||
hsAssert( fS != nil, "Weird parameter during conversion" );
|
||||
i = atoi( fS );
|
||||
return i;
|
||||
return fS.ToUInt();
|
||||
}
|
||||
|
||||
return fU;
|
||||
}
|
||||
|
||||
const double & plGenericType::IToDouble( void ) const
|
||||
double plGenericType::IToDouble( void ) const
|
||||
{
|
||||
hsAssert( fType == kDouble || fType == kAny, "Trying to use a non-float parameter as a Double!" );
|
||||
|
||||
static double d;
|
||||
if( fType == kAny )
|
||||
{
|
||||
hsAssert( fS != nil, "Weird parameter during conversion" );
|
||||
d = atof( fS );
|
||||
return d;
|
||||
return fS.ToDouble();
|
||||
}
|
||||
|
||||
return fD;
|
||||
}
|
||||
|
||||
const float & plGenericType::IToFloat( void ) const
|
||||
float plGenericType::IToFloat( void ) const
|
||||
{
|
||||
hsAssert( fType == kFloat || fType == kAny, "Trying to use a non-float parameter as a float!" );
|
||||
|
||||
static float f;
|
||||
if( fType == kAny )
|
||||
{
|
||||
hsAssert( fS != nil, "Weird parameter during conversion" );
|
||||
f = (float)atof( fS );
|
||||
return f;
|
||||
return fS.ToFloat();
|
||||
}
|
||||
|
||||
return fF;
|
||||
}
|
||||
|
||||
const bool & plGenericType::IToBool( void ) const
|
||||
bool plGenericType::IToBool( void ) const
|
||||
{
|
||||
hsAssert( fType == kBool || fType == kAny, "Trying to use a non-bool parameter as a bool!" );
|
||||
|
||||
static bool b;
|
||||
if( fType == kAny )
|
||||
{
|
||||
hsAssert( fS != nil, "Weird parameter during conversion" );
|
||||
if( atoi( fS ) > 0 || stricmp( fS, "true" ) == 0 )
|
||||
b = true;
|
||||
else
|
||||
b = false;
|
||||
|
||||
return b;
|
||||
return (fS.ToInt() > 0 || fS.CompareI("true") == 0);
|
||||
}
|
||||
|
||||
return fB;
|
||||
}
|
||||
|
||||
const plGenericType::CharPtr & plGenericType::IToString( void ) const
|
||||
plString plGenericType::IToString( void ) const
|
||||
{
|
||||
hsAssert( fType == kString || fType == kAny, "Trying to use a non-string parameter as a string!" );
|
||||
|
||||
return fS;
|
||||
}
|
||||
|
||||
const char & plGenericType::IToChar( void ) const
|
||||
char plGenericType::IToChar( void ) const
|
||||
{
|
||||
hsAssert( fType == kChar || fType == kAny, "Trying to use a non-char parameter as a char!" );
|
||||
|
||||
static char c;
|
||||
if( fType == kAny )
|
||||
{
|
||||
hsAssert( fS != nil, "Weird parameter during conversion" );
|
||||
c = fS[ 0 ];
|
||||
return c;
|
||||
return fS.CharAt(0);
|
||||
}
|
||||
|
||||
return fC;
|
||||
@ -172,7 +148,6 @@ const char & plGenericType::IToChar( void ) const
|
||||
|
||||
void plGenericType::Read(hsStream* s)
|
||||
{
|
||||
IDeallocString();
|
||||
s->ReadLE(&fType);
|
||||
|
||||
switch ( fType )
|
||||
@ -244,7 +219,6 @@ void plGenericType::Write(hsStream* s)
|
||||
///////////////////////////////////////////////////
|
||||
void plGenericVar::Read(hsStream* s)
|
||||
{
|
||||
delete [] fName;
|
||||
fName = s->ReadSafeString();
|
||||
fValue.Read(s);
|
||||
}
|
||||
@ -258,64 +232,6 @@ void plGenericVar::Write(hsStream* s)
|
||||
|
||||
//////////////////////////////////
|
||||
|
||||
void plGenericType::SetVar(Types t, unsigned int size, void* val)
|
||||
{
|
||||
fType = t;
|
||||
|
||||
switch (t)
|
||||
{
|
||||
case kInt :
|
||||
{
|
||||
hsAssert(size <= sizeof(fI), "plGenericType::SetVar size too large for int");
|
||||
memcpy(&fI, val, size);
|
||||
break;
|
||||
}
|
||||
case kUInt :
|
||||
{
|
||||
hsAssert(size <= sizeof(fU), "plGenericType::SetVar size too large for unsigned int");
|
||||
memcpy(&fU, val, size);
|
||||
break;
|
||||
}
|
||||
case kFloat :
|
||||
{
|
||||
hsAssert(size <= sizeof(fF), "plGenericType::SetVar size too large for float");
|
||||
memcpy(&fF, val, size);
|
||||
break;
|
||||
}
|
||||
case kDouble :
|
||||
{
|
||||
hsAssert(size <= sizeof(fD), "plGenericType::SetVar size too large for double");
|
||||
memcpy(&fD, val, size);
|
||||
break;
|
||||
}
|
||||
case kBool :
|
||||
{
|
||||
hsAssert(size <= sizeof(fB), "plGenericType::SetVar size too large for bool");
|
||||
memcpy(&fB, val, size);
|
||||
break;
|
||||
}
|
||||
case kChar :
|
||||
{
|
||||
hsAssert(size <= sizeof(fC), "plGenericType::SetVar size too large for char");
|
||||
memcpy(&fC, val, size);
|
||||
break;
|
||||
}
|
||||
case kString :
|
||||
{
|
||||
delete [] fS;
|
||||
fS = new char[size+1];
|
||||
memcpy(fS,val,size);
|
||||
fS[size] = 0;
|
||||
break;
|
||||
}
|
||||
case kNone :
|
||||
break;
|
||||
default:
|
||||
hsAssert(false,"plGenericType::SetVar unknown type");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
plString plGenericType::GetAsString() const
|
||||
{
|
||||
switch (fType)
|
||||
|
@ -53,21 +53,18 @@ class hsStream;
|
||||
//
|
||||
class plGenericType
|
||||
{
|
||||
public:
|
||||
typedef char* CharPtr;
|
||||
|
||||
protected:
|
||||
union
|
||||
{
|
||||
int32_t fI;
|
||||
uint32_t fU;
|
||||
int32_t fI;
|
||||
uint32_t fU;
|
||||
float fF;
|
||||
double fD;
|
||||
bool fB;
|
||||
CharPtr fS;
|
||||
char fC;
|
||||
};
|
||||
|
||||
plString fS;
|
||||
|
||||
public:
|
||||
|
||||
enum Types
|
||||
@ -86,20 +83,19 @@ public:
|
||||
protected:
|
||||
uint8_t fType;
|
||||
|
||||
const int32_t &IToInt( void ) const;
|
||||
const uint32_t &IToUInt( void ) const;
|
||||
const float &IToFloat( void ) const;
|
||||
const double &IToDouble( void ) const;
|
||||
const bool &IToBool( void ) const;
|
||||
const CharPtr &IToString( void ) const;
|
||||
const char &IToChar( void ) const;
|
||||
int32_t IToInt( void ) const;
|
||||
uint32_t IToUInt( void ) const;
|
||||
float IToFloat( void ) const;
|
||||
double IToDouble( void ) const;
|
||||
bool IToBool( void ) const;
|
||||
plString IToString( void ) const;
|
||||
char IToChar( void ) const;
|
||||
|
||||
void IDeallocString() { if (fType==kString || fType==kAny) {delete [] fS; fS=nil;} }
|
||||
public:
|
||||
|
||||
plGenericType() : fType(kNone) { Reset(); }
|
||||
plGenericType(const plGenericType& c) { CopyFrom(c); }
|
||||
virtual ~plGenericType() { IDeallocString(); }
|
||||
virtual ~plGenericType() { }
|
||||
|
||||
plGenericType& operator=(const plGenericType& c) { CopyFrom(c); return *this; }
|
||||
|
||||
@ -110,34 +106,33 @@ public:
|
||||
operator double() const { return IToDouble(); }
|
||||
operator float() const { return IToFloat(); }
|
||||
operator bool() const { return IToBool(); }
|
||||
operator const CharPtr() const { return IToString(); }
|
||||
operator plString() const { return IToString(); }
|
||||
operator char() const { return IToChar(); }
|
||||
|
||||
void SetType(Types t) { fType=t; }
|
||||
uint8_t GetType( void ) const { return fType; }
|
||||
uint8_t GetType( void ) const { return fType; }
|
||||
|
||||
plString GetAsString() const;
|
||||
|
||||
// implicit set
|
||||
void Set( int32_t i ) { fI = i; fType = kInt; }
|
||||
void Set( uint32_t i ) { fU = i; fType = kUInt; }
|
||||
void Set( int32_t i ) { fI = i; fType = kInt; }
|
||||
void Set( uint32_t i ) { fU = i; fType = kUInt; }
|
||||
void Set( float f ) { fF = f; fType = kFloat; }
|
||||
void Set( double d ) { fD = d; fType = kDouble; }
|
||||
void Set( bool b ) { fB = b; fType = kBool; }
|
||||
void Set( CharPtr s ) { IDeallocString(); fS = hsStrcpy(s); fType = kString; }
|
||||
void Set( const plString& s ) { fS = s; fType = kString; }
|
||||
void Set( char c ) { fC = c; fType = kChar; }
|
||||
|
||||
// explicit set
|
||||
void SetInt( int32_t i ) { fI = i; fType = kInt; }
|
||||
void SetUInt( uint32_t i ) { fU = i; fType = kUInt; }
|
||||
void SetInt( int32_t i ) { fI = i; fType = kInt; }
|
||||
void SetUInt( uint32_t i ) { fU = i; fType = kUInt; }
|
||||
void SetFloat( float f ) { fF = f; fType = kFloat; }
|
||||
void SetDouble( double d ) { fD = d; fType = kDouble; }
|
||||
void SetBool( bool b ) { fB = b; fType = kBool; }
|
||||
void SetString( CharPtr s ) { IDeallocString(); fS = hsStrcpy(s); fType = kString; }
|
||||
void SetString( const plString& s ) { fS = s; fType = kString; }
|
||||
void SetChar( char c ) { fC = c; fType = kChar; }
|
||||
void SetAny( CharPtr s ) { IDeallocString(); fS = hsStrcpy(s); fType = kAny; }
|
||||
void SetAny( const plString& s ) { fS = s; fType = kAny; }
|
||||
void SetNone( void ) { fType = kNone; }
|
||||
void SetVar(Types t, unsigned int size, void* val);
|
||||
|
||||
virtual void Read(hsStream* s);
|
||||
virtual void Write(hsStream* s);
|
||||
@ -150,17 +145,17 @@ class plGenericVar
|
||||
{
|
||||
protected:
|
||||
plGenericType fValue;
|
||||
char* fName;
|
||||
plString fName;
|
||||
public:
|
||||
plGenericVar(const plGenericVar &c) : fName(nil) { CopyFrom(c); }
|
||||
plGenericVar(const char* name=nil) : fName(nil) { SetName(name); }
|
||||
virtual ~plGenericVar() { delete [] fName; }
|
||||
plGenericVar(const plGenericVar &c) { CopyFrom(c); }
|
||||
plGenericVar(const plString& name="") : fName(name) { }
|
||||
virtual ~plGenericVar() { }
|
||||
|
||||
virtual void Reset() { Value().Reset(); } // reset runtime state, not inherent state
|
||||
plGenericVar& operator=(const plGenericVar &c) { CopyFrom(c); return *this; }
|
||||
void CopyFrom(const plGenericVar &c) { delete [] fName; fName=hsStrcpy(c.GetName()); fValue=c.Value(); }
|
||||
const char* GetName() const { return fName; }
|
||||
void SetName(const char* n) { delete [] fName; fName = hsStrcpy(n); }
|
||||
void CopyFrom(const plGenericVar &c) { fName=c.GetName(); fValue=c.Value(); }
|
||||
plString GetName() const { return fName; }
|
||||
void SetName(const plString& n) { fName = n; }
|
||||
plGenericType& Value() { return fValue; }
|
||||
const plGenericType& Value() const { return fValue; }
|
||||
|
||||
@ -186,7 +181,7 @@ public:
|
||||
operator float() const { return (float)fValue; }
|
||||
operator double() const { return (double)fValue; }
|
||||
operator bool() const { return (bool)fValue; }
|
||||
operator const char *() const { return (const char *)fValue; }
|
||||
operator plString() const { return (plString)fValue; }
|
||||
operator char() const { return (char)fValue; }
|
||||
};
|
||||
|
||||
|
@ -190,7 +190,7 @@ void plSynchedObject::RegisterSynchedValueFriend(plSynchedValueBase* v)
|
||||
//
|
||||
// send sdl state msg immediately
|
||||
//
|
||||
void plSynchedObject::SendSDLStateMsg(const char* SDLStateName, uint32_t synchFlags /*SendSDLStateFlags*/)
|
||||
void plSynchedObject::SendSDLStateMsg(const plString& SDLStateName, uint32_t synchFlags /*SendSDLStateFlags*/)
|
||||
{
|
||||
plSDLModifierMsg* sdlMsg = new plSDLModifierMsg(SDLStateName,
|
||||
(synchFlags & kBCastToClients) ? plSDLModifierMsg::kSendToServerAndClients : plSDLModifierMsg::kSendToServer /* action */);
|
||||
@ -203,14 +203,14 @@ void plSynchedObject::SendSDLStateMsg(const char* SDLStateName, uint32_t synchFl
|
||||
// Tell an object to send an sdl state update.
|
||||
// The request will get queued (returns true)
|
||||
//
|
||||
bool plSynchedObject::DirtySynchState(const char* SDLStateName, uint32_t synchFlags /*SendSDLStateFlags*/)
|
||||
bool plSynchedObject::DirtySynchState(const plString& SDLStateName, uint32_t synchFlags /*SendSDLStateFlags*/)
|
||||
{
|
||||
if (!IOKToDirty(SDLStateName))
|
||||
{
|
||||
#if 0
|
||||
if (plNetClientApp::GetInstance())
|
||||
plNetClientApp::GetInstance()->DebugMsg("NotOKToDirty - Not queueing SDL state, obj %s, sdl %s",
|
||||
GetKeyName(), SDLStateName);
|
||||
GetKeyName().c_str(), SDLStateName.c_str());
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@ -220,7 +220,7 @@ bool plSynchedObject::DirtySynchState(const char* SDLStateName, uint32_t synchFl
|
||||
#if 0
|
||||
if (plNetClientApp::GetInstance())
|
||||
plNetClientApp::GetInstance()->DebugMsg("LocalOnly Object - Not queueing SDL msg, obj %s, sdl %s",
|
||||
GetKeyName(), SDLStateName);
|
||||
GetKeyName().c_str(), SDLStateName.c_str());
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@ -236,7 +236,7 @@ bool plSynchedObject::DirtySynchState(const char* SDLStateName, uint32_t synchFl
|
||||
{
|
||||
if (plNetClientApp::GetInstance())
|
||||
plNetClientApp::GetInstance()->DebugMsg("Queueing SDL state with 'maybe' ownership, obj %s, sdl %s",
|
||||
GetKeyName().c_str(), SDLStateName);
|
||||
GetKeyName().c_str(), SDLStateName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,13 +256,13 @@ bool plSynchedObject::DirtySynchState(const char* SDLStateName, uint32_t synchFl
|
||||
// add state defn if not already there.
|
||||
// if there adjust flags if necessary
|
||||
//
|
||||
void plSynchedObject::IAddDirtyState(plKey objKey, const char* sdlName, uint32_t sendFlags)
|
||||
void plSynchedObject::IAddDirtyState(plKey objKey, const plString& sdlName, uint32_t sendFlags)
|
||||
{
|
||||
bool found=false;
|
||||
std::vector<StateDefn>::iterator it=fDirtyStates.begin();
|
||||
for( ; it != fDirtyStates.end(); it++)
|
||||
{
|
||||
if ((*it).fObjKey==objKey && !stricmp((*it).fSDLName.c_str(), sdlName))
|
||||
if (it->fObjKey == objKey && it->fSDLName.CompareI(sdlName) == 0)
|
||||
{
|
||||
if (sendFlags & kForceFullSend)
|
||||
(*it).fSendFlags |= kForceFullSend;
|
||||
@ -282,7 +282,7 @@ void plSynchedObject::IAddDirtyState(plKey objKey, const char* sdlName, uint32_t
|
||||
{
|
||||
#if 0
|
||||
plNetClientApp::GetInstance()->DebugMsg("Not queueing diplicate request for SDL state, obj %s, sdl %s",
|
||||
objKey->GetName(), sdlName);
|
||||
objKey->GetName().c_str(), sdlName.c_str());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -290,12 +290,12 @@ void plSynchedObject::IAddDirtyState(plKey objKey, const char* sdlName, uint32_t
|
||||
//
|
||||
// STATIC
|
||||
//
|
||||
void plSynchedObject::IRemoveDirtyState(plKey objKey, const char* sdlName)
|
||||
void plSynchedObject::IRemoveDirtyState(plKey objKey, const plString& sdlName)
|
||||
{
|
||||
std::vector<StateDefn>::iterator it=fDirtyStates.begin();
|
||||
for( ; it != fDirtyStates.end(); it++)
|
||||
{
|
||||
if ((*it).fObjKey==objKey && !stricmp((*it).fSDLName.c_str(), sdlName))
|
||||
if (it->fObjKey == objKey && it->fSDLName.CompareI(sdlName) == 0)
|
||||
{
|
||||
fDirtyStates.erase(it);
|
||||
break;
|
||||
@ -342,7 +342,7 @@ void plSynchedObject::Read(hsStream* stream, hsResMgr* mgr)
|
||||
int i;
|
||||
for(i=0;i<num;i++)
|
||||
{
|
||||
std::string s;
|
||||
plString s;
|
||||
plMsgStdStringHelper::Peek(s, stream);
|
||||
fSDLExcludeList.push_back(s);
|
||||
}
|
||||
@ -356,7 +356,7 @@ void plSynchedObject::Read(hsStream* stream, hsResMgr* mgr)
|
||||
int i;
|
||||
for(i=0;i<num;i++)
|
||||
{
|
||||
std::string s;
|
||||
plString s;
|
||||
plMsgStdStringHelper::Peek(s, stream);
|
||||
fSDLVolatileList.push_back(s);
|
||||
}
|
||||
@ -449,7 +449,7 @@ void plSynchedObject::CallDirtyNotifiers() {}
|
||||
//
|
||||
// return true if it's ok to dirty this object
|
||||
//
|
||||
bool plSynchedObject::IOKToDirty(const char* SDLStateName) const
|
||||
bool plSynchedObject::IOKToDirty(const plString& SDLStateName) const
|
||||
{
|
||||
// is synching disabled?
|
||||
bool synchDisabled = (GetSynchDisabled()!=0);
|
||||
@ -471,7 +471,7 @@ bool plSynchedObject::IOKToDirty(const char* SDLStateName) const
|
||||
//
|
||||
// return true if this object should send his SDL msg (for persistence or synch) over the net
|
||||
//
|
||||
bool plSynchedObject::IOKToNetwork(const char* sdlName, uint32_t* synchFlags) const
|
||||
bool plSynchedObject::IOKToNetwork(const plString& sdlName, uint32_t* synchFlags) const
|
||||
{
|
||||
// determine destination
|
||||
bool dstServerOnly=false, dstClientsOnly=false, dstClientsAndServer=false;
|
||||
@ -523,14 +523,14 @@ bool plSynchedObject::IOKToNetwork(const char* sdlName, uint32_t* synchFlags) co
|
||||
return false;
|
||||
}
|
||||
|
||||
plSynchedObject::SDLStateList::const_iterator plSynchedObject::IFindInSDLStateList(const SDLStateList& list, const char* sdlName) const
|
||||
plSynchedObject::SDLStateList::const_iterator plSynchedObject::IFindInSDLStateList(const SDLStateList& list, const plString& sdlName) const
|
||||
{
|
||||
if (!sdlName)
|
||||
if (sdlName.IsEmpty())
|
||||
return list.end(); // false
|
||||
|
||||
SDLStateList::const_iterator it = list.begin();
|
||||
for(; it != list.end(); it++)
|
||||
if (!stricmp((*it).c_str(), sdlName))
|
||||
if (it->CompareI(sdlName) == 0)
|
||||
return it;
|
||||
|
||||
return it; // .end(), false
|
||||
@ -540,19 +540,19 @@ plSynchedObject::SDLStateList::const_iterator plSynchedObject::IFindInSDLStateLi
|
||||
// EXCLUDE LIST
|
||||
///////////////////////////
|
||||
|
||||
void plSynchedObject::AddToSDLExcludeList(const char* sdlName)
|
||||
void plSynchedObject::AddToSDLExcludeList(const plString& sdlName)
|
||||
{
|
||||
if (sdlName)
|
||||
if (!sdlName.IsEmpty())
|
||||
{
|
||||
if (IFindInSDLStateList(fSDLExcludeList, sdlName)==fSDLExcludeList.end())
|
||||
{
|
||||
fSDLExcludeList.push_back(sdlName); // Don't dupe sdlName, std::string will copy
|
||||
fSDLExcludeList.push_back(sdlName);
|
||||
fSynchFlags |= kExcludePersistentState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void plSynchedObject::RemoveFromSDLExcludeList(const char* sdlName)
|
||||
void plSynchedObject::RemoveFromSDLExcludeList(const plString& sdlName)
|
||||
{
|
||||
SDLStateList::const_iterator it=IFindInSDLStateList(fSDLExcludeList, sdlName);
|
||||
if (it != fSDLExcludeList.end())
|
||||
@ -563,7 +563,7 @@ void plSynchedObject::RemoveFromSDLExcludeList(const char* sdlName)
|
||||
}
|
||||
}
|
||||
|
||||
bool plSynchedObject::IsInSDLExcludeList(const char* sdlName) const
|
||||
bool plSynchedObject::IsInSDLExcludeList(const plString& sdlName) const
|
||||
{
|
||||
if ((fSynchFlags & kExcludeAllPersistentState) != 0)
|
||||
return true;
|
||||
@ -579,9 +579,9 @@ bool plSynchedObject::IsInSDLExcludeList(const char* sdlName) const
|
||||
// VOLATILE LIST
|
||||
///////////////////////////
|
||||
|
||||
void plSynchedObject::AddToSDLVolatileList(const char* sdlName)
|
||||
void plSynchedObject::AddToSDLVolatileList(const plString& sdlName)
|
||||
{
|
||||
if (sdlName)
|
||||
if (!sdlName.IsEmpty())
|
||||
{
|
||||
if (IFindInSDLStateList(fSDLVolatileList,sdlName)==fSDLVolatileList.end())
|
||||
{
|
||||
@ -591,7 +591,7 @@ void plSynchedObject::AddToSDLVolatileList(const char* sdlName)
|
||||
}
|
||||
}
|
||||
|
||||
void plSynchedObject::RemoveFromSDLVolatileList(const char* sdlName)
|
||||
void plSynchedObject::RemoveFromSDLVolatileList(const plString& sdlName)
|
||||
{
|
||||
SDLStateList::const_iterator it=IFindInSDLStateList(fSDLVolatileList,sdlName);
|
||||
if (it != fSDLVolatileList.end())
|
||||
@ -602,7 +602,7 @@ void plSynchedObject::RemoveFromSDLVolatileList(const char* sdlName)
|
||||
}
|
||||
}
|
||||
|
||||
bool plSynchedObject::IsInSDLVolatileList(const char* sdlName) const
|
||||
bool plSynchedObject::IsInSDLVolatileList(const plString& sdlName) const
|
||||
{
|
||||
if ((fSynchFlags & kAllStateIsVolatile) != 0)
|
||||
return true;
|
||||
|
@ -89,17 +89,18 @@ public:
|
||||
|
||||
struct StateDefn
|
||||
{
|
||||
plKey fObjKey;
|
||||
plKey fObjKey;
|
||||
uint32_t fSendFlags;
|
||||
std::string fSDLName;
|
||||
plString fSDLName;
|
||||
|
||||
plSynchedObject* GetObject() const { return plSynchedObject::ConvertNoRef(fObjKey->ObjectIsLoaded()); }
|
||||
StateDefn() : fObjKey(nil),fSendFlags(0) {}
|
||||
StateDefn(plKey k, uint32_t f, const char* sdlName) : fObjKey(k),fSendFlags(f) { fSDLName=sdlName; }
|
||||
StateDefn(plKey k, uint32_t f, const plString& sdlName)
|
||||
: fObjKey(k), fSendFlags(f), fSDLName(sdlName) { }
|
||||
};
|
||||
|
||||
private:
|
||||
typedef std::vector<std::string> SDLStateList;
|
||||
typedef std::vector<plString> SDLStateList;
|
||||
SDLStateList fSDLExcludeList;
|
||||
SDLStateList fSDLVolatileList;
|
||||
uint32_t fSynchFlags;
|
||||
@ -110,12 +111,12 @@ private:
|
||||
static plSynchedObject* fStaticSynchedObj; // static which temporarily holds address of each object's synchMgr
|
||||
static std::vector<StateDefn> fDirtyStates;
|
||||
|
||||
static void IRemoveDirtyState(plKey o, const char* sdlName);
|
||||
static void IAddDirtyState(plKey o, const char* sdlName, uint32_t sendFlags);
|
||||
bool IOKToDirty(const char* SDLStateName) const;
|
||||
SDLStateList::const_iterator IFindInSDLStateList(const SDLStateList& list, const char* sdlName) const;
|
||||
static void IRemoveDirtyState(plKey o, const plString& sdlName);
|
||||
static void IAddDirtyState(plKey o, const plString& sdlName, uint32_t sendFlags);
|
||||
bool IOKToDirty(const plString& SDLStateName) const;
|
||||
SDLStateList::const_iterator IFindInSDLStateList(const SDLStateList& list, const plString& sdlName) const;
|
||||
protected:
|
||||
bool IOKToNetwork(const char* sdlName, uint32_t* synchFlags) const;
|
||||
bool IOKToNetwork(const plString& sdlName, uint32_t* synchFlags) const;
|
||||
public:
|
||||
plSynchedObject();
|
||||
virtual ~plSynchedObject();
|
||||
@ -136,8 +137,8 @@ public:
|
||||
virtual void SetNetGroup(plNetGroupId netGroup) { fNetGroup = netGroup; }
|
||||
plNetGroupId SelectNetGroup(plKey groupKey);
|
||||
|
||||
virtual bool DirtySynchState(const char* sdlName, uint32_t sendFlags);
|
||||
void SendSDLStateMsg(const char* SDLStateName, uint32_t synchFlags); // don't use, only for net code
|
||||
virtual bool DirtySynchState(const plString& sdlName, uint32_t sendFlags);
|
||||
void SendSDLStateMsg(const plString& SDLStateName, uint32_t synchFlags); // don't use, only for net code
|
||||
|
||||
void ClearSynchFlagsBit(uint32_t f) { fSynchFlags &= ~f; }
|
||||
|
||||
@ -168,14 +169,14 @@ public:
|
||||
void SetLocalOnly(bool b) { if (b) fSynchFlags |= kLocalOnly; else fSynchFlags &= ~kLocalOnly; }
|
||||
|
||||
// disable particular types of persistence
|
||||
void AddToSDLExcludeList(const char*);
|
||||
void RemoveFromSDLExcludeList(const char*);
|
||||
bool IsInSDLExcludeList(const char*) const;
|
||||
void AddToSDLExcludeList(const plString&);
|
||||
void RemoveFromSDLExcludeList(const plString&);
|
||||
bool IsInSDLExcludeList(const plString&) const;
|
||||
|
||||
// make volatile particular types of state
|
||||
void AddToSDLVolatileList(const char*);
|
||||
void RemoveFromSDLVolatileList(const char*);
|
||||
bool IsInSDLVolatileList(const char*) const;
|
||||
void AddToSDLVolatileList(const plString&);
|
||||
void RemoveFromSDLVolatileList(const plString&);
|
||||
bool IsInSDLVolatileList(const plString&) const;
|
||||
|
||||
//
|
||||
// synched value stuff, currently unused
|
||||
|
@ -144,7 +144,7 @@ public:
|
||||
{
|
||||
MakeDirty(); // dirty value
|
||||
if (GetSynchedObject())
|
||||
GetSynchedObject()->DirtySynchState(nil, 0); // dirty owner
|
||||
GetSynchedObject()->DirtySynchState(plString::Null, 0); // dirty owner
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,6 +118,12 @@ unsigned StrToAnsi (char * dest, const wchar_t source[], unsigned destChars, uns
|
||||
unsigned StrToUnicode (wchar_t * dest, const char source[], unsigned destChars);
|
||||
unsigned StrToUnicode (wchar_t * dest, const char source[], unsigned destChars, unsigned codePage);
|
||||
|
||||
// FIXME: Get rid of these
|
||||
inline unsigned StrToUnicode(wchar_t * dest, const plString & source, unsigned destChars)
|
||||
{ return StrToUnicode(dest, source.c_str(), destChars); }
|
||||
inline unsigned StrToUnicode(wchar_t * dest, const plString & source, unsigned destChars, unsigned codePage)
|
||||
{ return StrToUnicode(dest, source.c_str(), destChars, codePage); }
|
||||
|
||||
float StrToFloat (const char source[], const char ** endptr);
|
||||
float StrToFloat (const wchar_t source[], const wchar_t ** endptr);
|
||||
|
||||
|
Reference in New Issue
Block a user