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

Convert SDL (mostly) to plStrings

This commit is contained in:
2012-11-18 16:49:39 -08:00
parent 188171235e
commit 49dfb4e546
45 changed files with 456 additions and 488 deletions

View File

@ -107,10 +107,10 @@ namespace plSDL
class plStateVarNotificationInfo
{
private:
std::string fHintString;
plString fHintString;
public:
void SetHintString(const char* c) { fHintString=c; }
const char* GetHintString() const { return fHintString.c_str(); }
void SetHintString(const plString& c) { fHintString=c; }
plString GetHintString() const { return fHintString; }
void Read(hsStream* s, uint32_t readOptions);
void Write(hsStream* s, uint32_t writeOptions) const;
@ -137,8 +137,8 @@ public:
plStateVariable() : fFlags(0) {}
virtual ~plStateVariable() {}
const char* GetName() const { return GetVarDescriptor()->GetName(); }
bool IsNamed(const char* n) const { return (n && !stricmp(GetName(), n)); }
plString GetName() const { return GetVarDescriptor()->GetName(); }
bool IsNamed(const char* n) const { return (n && !GetName().CompareI(n)); }
virtual int GetCount() const = 0;
// conversion ops
@ -193,7 +193,7 @@ public:
int RemoveNotificationKey(plKey k); // returns number of keys left after removal
int RemoveNotificationKeys(KeyList keys); // returns number of keys left after removal
void SendNotificationMsg(const plSimpleStateVariable* srcVar, const plSimpleStateVariable* dstVar, const char* sdlName);
void SendNotificationMsg(const plSimpleStateVariable* srcVar, const plSimpleStateVariable* dstVar, const plString& sdlName);
bool GetValue(float* i) const;
bool SetValue(float i);
@ -266,10 +266,10 @@ public:
void TimeStamp( const plUnifiedTime & ut=plUnifiedTime::GetCurrentTime() );
void CopyFrom(plVarDescriptor* v);
void CopyData(const plSimpleStateVariable* other, uint32_t writeOptions=0);
bool SetFromString(const char* value, int idx, bool timeStampNow); // set value from string, type. return false on err
char* GetAsString(int idx) const;
bool SetFromString(const plString& value, int idx, bool timeStampNow); // set value from string, type. return false on err
plString GetAsString(int idx) const;
bool ConvertTo(plSimpleVarDescriptor* toVar, bool force=false); // return false on err
void Alloc(int cnt=-1 /* -1 means don't change count */); // alloc memory after setting type
void Alloc(int cnt=-1 /* -1 means don't change count */); // alloc memory after setting type
void Reset();
// setters
@ -293,7 +293,7 @@ public:
// getters
bool Get(int* value, int idx=0) const;
bool Get(short* value, int idx=0) const;
bool Get(uint8_t* value, int idx=0) const; // returns uint8_t or uint8_tVector
bool Get(uint8_t* value, int idx=0) const; // returns uint8_t or uint8_tVector
bool Get(float* value, int idx=0) const; // returns float or floatVector
bool Get(double* value, int idx=0) const; // returns double or doubleVector
bool Get(bool* value, int idx=0) const;
@ -315,7 +315,7 @@ public:
void AddStateChangeNotification(plStateChangeNotifier& n);
void RemoveStateChangeNotification(plKey notificationObj); // remove all with this key
void RemoveStateChangeNotification(plStateChangeNotifier n); // remove ones which match
void NotifyStateChange(const plSimpleStateVariable* other, const char* sdlName); // send notification msg if necessary, internal use
void NotifyStateChange(const plSimpleStateVariable* other, const plString& sdlName); // send notification msg if necessary, internal use
void DumpToObjectDebugger(bool dirtyOnly, int level) const;
void DumpToStream(hsStream* stream, bool dirtyOnly, int level) const;
@ -407,18 +407,18 @@ protected:
plUoid fAssocObject; // optional
VarsList fVarsList; // list of variables
VarsList fSDVarsList; // list of nested data records
uint32_t fFlags;
uint32_t fFlags;
static const uint8_t kIOVersion; // I/O Version
void IDeleteVarsList(VarsList& vars);
void IInitDescriptor(const char* name, int version); // or plSDL::kLatestVersion
void IInitDescriptor(const plString& name, int version); // or plSDL::kLatestVersion
void IInitDescriptor(const plStateDescriptor* sd);
void IReadHeader(hsStream* s);
void IWriteHeader(hsStream* s) const;
bool IConvertVar(plSimpleStateVariable* fromVar, plSimpleStateVariable* toVar, bool force);
plStateVariable* IFindVar(const VarsList& vars, const char* name) const;
plStateVariable* IFindVar(const VarsList& vars, const plString& name) const;
int IGetNumUsedVars(const VarsList& vars) const;
int IGetUsedVars(const VarsList& varsOut, VarsList *varsIn) const; // build a list of vars that have data
bool IHasUsedVars(const VarsList& vars) const;
@ -430,7 +430,7 @@ public:
CLASSNAME_REGISTER( plStateDataRecord );
GETINTERFACE_ANY( plStateDataRecord, plCreatable);
plStateDataRecord(const char* sdName, int version=plSDL::kLatestVersion);
plStateDataRecord(const plString& sdName, int version=plSDL::kLatestVersion);
plStateDataRecord(plStateDescriptor* sd);
plStateDataRecord(const plStateDataRecord &other, uint32_t writeOptions=0 ):fFlags(0) { CopyFrom(other, writeOptions); }
plStateDataRecord():fFlags(0) {}
@ -442,8 +442,8 @@ public:
uint32_t GetFlags() const { return fFlags; }
void SetFlags(uint32_t f) { fFlags =f; }
plSimpleStateVariable* FindVar(const char* name) const { return (plSimpleStateVariable*)IFindVar(fVarsList, name); }
plSDStateVariable* FindSDVar(const char* name) const { return (plSDStateVariable*)IFindVar(fSDVarsList, name); }
plSimpleStateVariable* FindVar(const plString& name) const { return (plSimpleStateVariable*)IFindVar(fVarsList, name); }
plSDStateVariable* FindSDVar(const plString& name) const { return (plSDStateVariable*)IFindVar(fSDVarsList, name); }
plStateDataRecord& operator=(const plStateDataRecord& other) { CopyFrom(other); return *this; }
void CopyFrom(const plStateDataRecord& other, uint32_t writeOptions=0);
@ -479,7 +479,7 @@ public:
bool HasDirtySDVars() const { return IHasDirtyVars(fSDVarsList); }
const plStateDescriptor* GetDescriptor() const { return fDescriptor; }
void SetDescriptor(const char* sdName, int version);
void SetDescriptor(const plString& sdName, int version);
plNetMsgSDLState* PrepNetMsg(float timeConvert, uint32_t writeOptions) const; // create/prep a net msg with this data
@ -498,7 +498,7 @@ public:
bool Read(hsStream* s, float timeConvert, uint32_t readOptions=0);
void Write(hsStream* s, float timeConvert, uint32_t writeOptions=0) const;
static bool ReadStreamHeader(hsStream* s, char** name, int* version, plUoid* objUoid=nil);
static bool ReadStreamHeader(hsStream* s, plString* name, int* version, plUoid* objUoid=nil);
void WriteStreamHeader(hsStream* s, plUoid* objUoid=nil) const;
};
@ -543,7 +543,7 @@ public:
~plSDLMgr();
static plSDLMgr* GetInstance();
plStateDescriptor* FindDescriptor(const char* name, int version, const plSDL::DescriptorList * dl=nil) const; // version or kLatestVersion
plStateDescriptor* FindDescriptor(const plString& name, int version, const plSDL::DescriptorList * dl=nil) const; // version or kLatestVersion
const plSDL::DescriptorList * GetDescriptors( void ) const { return &fDescriptors;}

View File

@ -50,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "plString.h"
//
// Describes a variable in a state descriptor.
@ -98,17 +99,17 @@ public:
kVariableLength = 0x4 // Var is defined as int foo[], so it's length is variable, starting at 0
};
protected:
static const uint8_t kVersion; // for Read/Write format
char* fDefault; // set by .sdl
char* fName; // set by .sdl
int fCount; // set by .sdl
Type fType; // set by .sdl
char* fTypeString; // string version of fType
uint32_t fFlags;
std::string fDisplayOptions; // set by .sdl
static const uint8_t kVersion; // for Read/Write format
plString fDefault; // set by .sdl
plString fName; // set by .sdl
int fCount; // set by .sdl
Type fType; // set by .sdl
plString fTypeString; // string version of fType
uint32_t fFlags;
plString fDisplayOptions; // set by .sdl
public:
plVarDescriptor();
virtual ~plVarDescriptor();
plVarDescriptor() : fCount(1), fType(kNone), fFlags(0) { }
virtual ~plVarDescriptor() { }
virtual void CopyFrom(const plVarDescriptor* v);
@ -119,26 +120,26 @@ public:
virtual const plSDVarDescriptor* GetAsSDVarDescriptor() const = 0;
// getters
const char* GetDefault() const { return fDefault; }
const char* GetName() const { return fName; }
Type GetType() const { return fType; }
const char* GetTypeString() const { return fTypeString; }
int GetCount() const { return fCount; }
bool IsInternal() const { return (fFlags & kInternal) != 0; }
bool IsAlwaysNew() const { return (fFlags & kAlwaysNew) != 0; }
bool IsVariableLength() const { return (fFlags & kVariableLength) != 0; }
const char* GetDisplayOptions() const { return fDisplayOptions.c_str(); }
plString GetDefault() const { return fDefault; }
plString GetName() const { return fName; }
Type GetType() const { return fType; }
plString GetTypeString() const { return fTypeString; }
int GetCount() const { return fCount; }
bool IsInternal() const { return (fFlags & kInternal) != 0; }
bool IsAlwaysNew() const { return (fFlags & kAlwaysNew) != 0; }
bool IsVariableLength() const { return (fFlags & kVariableLength) != 0; }
plString GetDisplayOptions() const { return fDisplayOptions; }
// setters
void SetDefault(const char* n) { delete [] fDefault; fDefault= hsStrcpy(n); }
void SetName(const char* n) { delete [] fName; fName = hsStrcpy(n); }
void SetDefault(const plString& n) { fDefault = n; }
void SetName(const plString& n) { fName = n; }
void SetCount(int c) { fCount=c; }
virtual bool SetType(const char* type);
void SetType(Type t) { fType=t; }
virtual bool SetType(const plString& type);
void SetType(Type t) { fType=t; }
void SetInternal(bool d) { if (d) fFlags |= kInternal; else fFlags &= ~kInternal; }
void SetAlwaysNew(bool d) { if (d) fFlags |= kAlwaysNew; else fFlags &= ~kAlwaysNew; }
void SetVariableLength(bool d) { if (d) fFlags |= kVariableLength; else fFlags &= ~kVariableLength; }
void SetDisplayOptions(const char* s) { fDisplayOptions=s; }
void SetDisplayOptions(const plString& s) { fDisplayOptions=s; }
// IO
virtual bool Read(hsStream* s);
@ -173,7 +174,7 @@ public:
int GetAtomicCount() const { return fAtomicCount; }
// setters
bool SetType(const char* type);
bool SetType(const plString& type);
void SetType(Type t) { plVarDescriptor::SetType(t); } // for lame compiler
void SetAtomicType(Type t) { fAtomicType=t; }
@ -225,16 +226,16 @@ private:
typedef std::vector<plVarDescriptor*> VarsList;
VarsList fVarsList;
int fVersion;
char* fName;
plString fName;
std::string fFilename; // the filename this descriptor was read from
void IDeInit();
public:
plStateDescriptor() : fVersion(-1),fName(nil) {}
plStateDescriptor() : fVersion(-1) {}
~plStateDescriptor();
// getters
const char* GetName() const { return fName; }
plString GetName() const { return fName; }
int GetNumVars() const { return fVarsList.size(); }
plVarDescriptor* GetVar(int i) const { return fVarsList[i]; }
int GetVersion() const { return fVersion; }
@ -242,11 +243,11 @@ public:
// setters
void SetVersion(int v) { fVersion=v; }
void SetName(const char* n) { delete [] fName; fName=hsStrcpy(n); }
void SetName(const plString& n) { fName=n; }
void AddVar(plVarDescriptor* v) { fVarsList.push_back(v); }
void SetFilename( const char * n ) { fFilename=n;}
plVarDescriptor* FindVar(const char* name, int* idx=nil) const;
plVarDescriptor* FindVar(const plString& name, int* idx=nil) const;
// IO
bool Read(hsStream* s);

View File

@ -101,9 +101,9 @@ plSDLMgr* plSDLMgr::GetInstance()
// search latest and legacy descriptors for one that matches.
// if version is -1, search for latest descriptor with matching name
//
plStateDescriptor* plSDLMgr::FindDescriptor(const char* name, int version, const plSDL::DescriptorList * dl) const
plStateDescriptor* plSDLMgr::FindDescriptor(const plString& name, int version, const plSDL::DescriptorList * dl) const
{
if (!name)
if (name.IsNull())
return nil;
if ( !dl )
@ -116,7 +116,7 @@ plStateDescriptor* plSDLMgr::FindDescriptor(const char* name, int version, const
int highestFound = -1;
for(it=(*dl).begin(); it!= (*dl).end(); it++)
{
if (!stricmp((*it)->GetName(), name) )
if (!(*it)->GetName().CompareI(name) )
{
if ( (*it)->GetVersion()==version )
{

View File

@ -162,12 +162,12 @@ bool plSDLParser::IParseStateDesc(const char* fileName, hsStream* stream, char t
bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char token[], plStateDescriptor*& curDesc,
plVarDescriptor*& curVar) const
{
hsAssert(curDesc, xtl::format("Syntax problem with .sdl file, fileName=%s", fileName).c_str());
hsAssert(curDesc, plString::Format("Syntax problem with .sdl file, fileName=%s", fileName).c_str());
if ( !curDesc )
return false;
bool skipNext=false;
std::string dbgStr;
plString dbgStr;
static char seps[] = "( ,)[]";
// read type, name, cnt, [default]
@ -180,7 +180,7 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
// nested sdls
char* sdlName = token+1;
plStateDescriptor* stateDesc = plSDLMgr::GetInstance()->FindDescriptor(sdlName, plSDL::kLatestVersion);
hsAssert(stateDesc, xtl::format("can't find nested state desc reference %s, fileName=%s",
hsAssert(stateDesc, plString::Format("can't find nested state desc reference %s, fileName=%s",
sdlName, fileName).c_str());
curVar = new plSDVarDescriptor(stateDesc);
}
@ -189,19 +189,19 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
curDesc->AddVar(curVar);
bool ok=curVar->SetType(token);
hsAssert(ok, xtl::format("Variable 'type' syntax problem with .sdl file, type=%s, fileName=%s", token, fileName).c_str());
dbgStr = xtl::format("\tVAR Type=%s ", token).c_str();
hsAssert(ok, plString::Format("Variable 'type' syntax problem with .sdl file, type=%s, fileName=%s", token, fileName).c_str());
dbgStr = plString::Format("\tVAR Type=%s ", token);
//
// NAME (foo[1])
//
if (stream->GetToken(token, kTokenLen))
{
hsAssert(strstr(token, "[") && strstr(token, "]"), xtl::format("invalid var syntax, missing [x], fileName=%s",
hsAssert(strstr(token, "[") && strstr(token, "]"), plString::Format("invalid var syntax, missing [x], fileName=%s",
fileName).c_str());
char* ptr = strtok( token, seps ); // skip [
hsAssert(curVar, xtl::format("Missing current var. Syntax problem with .sdl file, fileName=%s", fileName).c_str());
hsAssert(curVar, plString::Format("Missing current var. Syntax problem with .sdl file, fileName=%s", fileName).c_str());
curVar->SetName(token);
//
// COUNT
@ -211,7 +211,7 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
curVar->SetCount(cnt);
if (cnt==0)
curVar->SetVariableLength(true);
dbgStr += xtl::format("Name=%s[%d]", curVar->GetName(), cnt).c_str();
dbgStr += plString::Format("Name=%s[%d]", curVar->GetName().c_str(), cnt);
}
//
@ -221,10 +221,10 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
{
if (!strcmp(token, "DEFAULT"))
{
hsAssert(curVar, xtl::format("Syntax problem with .sdl file, fileName=%s", fileName).c_str());
hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", fileName).c_str());
// read state var type
std::string defaultStr;
plString defaultStr;
plSimpleVarDescriptor* sVar=(plSimpleVarDescriptor*)curVar;
if (sVar)
{
@ -239,51 +239,51 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
}
}
}
if (defaultStr.size())
if (!defaultStr.IsEmpty())
{
curVar->SetDefault(defaultStr.c_str());
dbgStr += std::string(" DEFAULT=") + defaultStr;
curVar->SetDefault(defaultStr);
dbgStr += " DEFAULT=" + defaultStr;
}
}
else
if (!strcmp(token, "DISPLAYOPTION"))
{
hsAssert(curVar, xtl::format("Syntax problem with .sdl file, fileName=%s", fileName).c_str());
dbgStr += std::string(" ") + token;
hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", fileName).c_str());
dbgStr += plString(" ") + token;
bool read=stream->GetToken(token, kTokenLen);
if (read)
{
std::string oldOptions=curVar->GetDisplayOptions();
if (oldOptions.size())
oldOptions += std::string(",");
plString oldOptions=curVar->GetDisplayOptions();
if (!oldOptions.IsEmpty())
oldOptions += ",";
oldOptions += token;
curVar->SetDisplayOptions(oldOptions.c_str());
dbgStr += std::string("=") + token;
curVar->SetDisplayOptions(oldOptions);
dbgStr += plString("=") + token;
if (!stricmp(token, "hidden"))
curVar->SetInternal(true);
}
else
{
hsAssert(false, xtl::format("missing displayOption string, fileName=%s", fileName).c_str());
hsAssert(false, plString::Format("missing displayOption string, fileName=%s", fileName).c_str());
}
}
else
if (!strcmp(token, "DEFAULTOPTION"))
{
hsAssert(curVar, xtl::format("Syntax problem with .sdl file, fileName=%s", fileName).c_str());
dbgStr += std::string(" ") + token;
hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", fileName).c_str());
dbgStr += plString(" ") + token;
bool read=stream->GetToken(token, kTokenLen);
if (read)
{
dbgStr += std::string("=") + token;
dbgStr += plString("=") + token;
if (!stricmp(token, "vault"))
curVar->SetAlwaysNew(true);
}
else
{
hsAssert(false, xtl::format("missing defaultOption string, fileName=%s", fileName).c_str());
hsAssert(false, plString::Format("missing defaultOption string, fileName=%s", fileName).c_str());
}
}
@ -291,16 +291,16 @@ bool plSDLParser::IParseVarDesc(const char* fileName, hsStream* stream, char tok
else
if (!strcmp(token, "INTERNAL"))
{
hsAssert(curVar, xtl::format("Syntax problem with .sdl file, fileName=%s", fileName).c_str());
hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", fileName).c_str());
curVar->SetInternal(true);
dbgStr += std::string(" ") + token;
dbgStr += plString(" ") + token;
}
else
if (!strcmp(token, "PHASED"))
{
hsAssert(curVar, xtl::format("Syntax problem with .sdl file, fileName=%s", fileName).c_str());
hsAssert(curVar, plString::Format("Syntax problem with .sdl file, fileName=%s", fileName).c_str());
curVar->SetAlwaysNew(true);
dbgStr += std::string(" ") + token;
dbgStr += plString(" ") + token;
}
#endif
else

View File

@ -121,7 +121,7 @@ bool plStateChangeNotifier::operator==(const plStateChangeNotifier &other) const
// send notification msg to all registered recipients
//
void plStateChangeNotifier::SendNotificationMsg(const plSimpleStateVariable* srcVar, const plSimpleStateVariable* dstVar,
const char* sdlName)
const plString& sdlName)
{
plSDLNotificationMsg* m = new plSDLNotificationMsg;

View File

@ -95,7 +95,7 @@ void plSDL::VariableLengthWrite(hsStream* s, int size, int val)
/////////////////////////////////////////////////////////////////////////////////
// State Data
/////////////////////////////////////////////////////////////////////////////////
plStateDataRecord::plStateDataRecord(const char* name, int version) : fFlags(0)
plStateDataRecord::plStateDataRecord(const plString& name, int version) : fFlags(0)
, fDescriptor( nil )
{
SetDescriptor(name, version);
@ -113,7 +113,7 @@ plStateDataRecord::~plStateDataRecord()
IDeleteVarsList(fSDVarsList);
}
void plStateDataRecord::SetDescriptor(const char* name, int version)
void plStateDataRecord::SetDescriptor(const plString& name, int version)
{
IInitDescriptor(name, version);
}
@ -125,10 +125,10 @@ void plStateDataRecord::IDeleteVarsList(VarsList& vars)
vars.clear();
}
void plStateDataRecord::IInitDescriptor(const char* name, int version)
void plStateDataRecord::IInitDescriptor(const plString& name, int version)
{
plStateDescriptor* sd = plSDLMgr::GetInstance()->FindDescriptor(name, version);
//hsAssert( sd, xtl::format("Failed to find sdl descriptor: %s,%d. Missing legacy descriptor?", name, version ).c_str() );
//hsAssert( sd, plString::Format("Failed to find sdl descriptor: %s,%d. Missing legacy descriptor?", name.c_str(), version ).c_str() );
if (sd)
IInitDescriptor(sd);
}
@ -268,7 +268,7 @@ bool plStateDataRecord::Read(hsStream* s, float timeConvert, uint32_t readOption
{
if (plSDLMgr::GetInstance()->GetNetApp())
plSDLMgr::GetInstance()->GetNetApp()->ErrorMsg("Failed reading SDL, desc %s",
fDescriptor && fDescriptor->GetName() ? fDescriptor->GetName() : "?");
fDescriptor ? fDescriptor->GetName().c_str("?") : "?");
return false;
}
}
@ -276,8 +276,8 @@ bool plStateDataRecord::Read(hsStream* s, float timeConvert, uint32_t readOption
catch(...)
{
hsAssert( false,
xtl::format("Something bad happened while reading simple var data, desc:%s",
fDescriptor && fDescriptor->GetName() ? fDescriptor->GetName() : "?").c_str());
plString::Format("Something bad happened while reading simple var data, desc:%s",
fDescriptor ? fDescriptor->GetName().c_str("?") : "?").c_str());
return false;
}
@ -302,7 +302,7 @@ bool plStateDataRecord::Read(hsStream* s, float timeConvert, uint32_t readOption
{
if (plSDLMgr::GetInstance()->GetNetApp())
plSDLMgr::GetInstance()->GetNetApp()->ErrorMsg("Failed reading nested SDL, desc %s",
fDescriptor && fDescriptor->GetName() ? fDescriptor->GetName() : "?");
fDescriptor ? fDescriptor->GetName().c_str("?") : "?");
return false;
}
}
@ -310,15 +310,15 @@ bool plStateDataRecord::Read(hsStream* s, float timeConvert, uint32_t readOption
catch(...)
{
hsAssert( false,
xtl::format("Something bad happened while reading nested var data, desc:%s",
fDescriptor && fDescriptor->GetName() ? fDescriptor->GetName() : "?").c_str());
plString::Format("Something bad happened while reading nested var data, desc:%s",
fDescriptor ? fDescriptor->GetName().c_str("?") : "?").c_str());
return false;
}
// convert to latest descriptor
// Only really need to do this the first time this descriptor is read...
plStateDescriptor* latestDesc=plSDLMgr::GetInstance()->FindDescriptor(fDescriptor->GetName(), plSDL::kLatestVersion);
hsAssert( latestDesc, xtl::format("Failed to find latest sdl descriptor for: %s", fDescriptor->GetName() ).c_str() );
hsAssert( latestDesc, plString::Format("Failed to find latest sdl descriptor for: %s", fDescriptor->GetName().c_str() ).c_str() );
bool forceConvert = (readOptions&plSDL::kForceConvert)!=0;
if ( latestDesc && ( forceConvert || ( fDescriptor->GetVersion()!=latestDesc->GetVersion() ) ) )
{
@ -392,17 +392,17 @@ void plStateDataRecord::Write(hsStream* s, float timeConvert, uint32_t writeOpti
//
// STATIC - read prefix header. returns true on success
//
bool plStateDataRecord::ReadStreamHeader(hsStream* s, char** name, int* version, plUoid* objUoid)
bool plStateDataRecord::ReadStreamHeader(hsStream* s, plString* name, int* version, plUoid* objUoid)
{
uint16_t savFlags;
s->ReadLE(&savFlags);
if (!(savFlags & plSDL::kAddedVarLengthIO)) // using to establish a new version in the header, can delete in 8/03
{
*name = nil;
*name = "";
return false; // bad version
}
*name = s->ReadSafeString();
*name = s->ReadSafeString_TEMP();
*version = s->ReadLE16();
if (objUoid)
@ -492,13 +492,14 @@ void plStateDataRecord::UpdateFrom(const plStateDataRecord& other, uint32_t writ
if ( GetDescriptor()->GetVersion()!=other.GetDescriptor()->GetVersion() )
{
plStateDescriptor* sd=plSDLMgr::GetInstance()->FindDescriptor( other.GetDescriptor()->GetName(), other.GetDescriptor()->GetVersion() );
hsAssert( sd, xtl::format( "Failed to find sdl descriptor %s,%d. Missing legacy descriptor?", other.GetDescriptor()->GetName(), other.GetDescriptor()->GetVersion() ).c_str() );
hsAssert( sd, plString::Format( "Failed to find sdl descriptor %s,%d. Missing legacy descriptor?",
other.GetDescriptor()->GetName().c_str(), other.GetDescriptor()->GetVersion() ).c_str() );
ConvertTo( sd );
}
hsAssert(other.GetDescriptor()==fDescriptor,
xtl::format("descriptor mismatch in UpdateFromDirty, SDL=%s,%s version %d %d",
GetDescriptor()->GetName(), other.GetDescriptor()->GetName(),
plString::Format("descriptor mismatch in UpdateFromDirty, SDL=%s,%s version %d %d",
GetDescriptor()->GetName().c_str(), other.GetDescriptor()->GetName().c_str(),
GetDescriptor()->GetVersion(), other.GetDescriptor()->GetVersion()).c_str());
bool dirtyOnly = (writeOptions & plSDL::kDirtyOnly);
@ -543,9 +544,9 @@ void plStateDataRecord::FlagDifferentState(const plStateDataRecord& other)
}
else
{
hsAssert(false, xtl::format("descriptor mismatch in FlagDifferentState, mine %s %d, other %s %d",
fDescriptor->GetName(), fDescriptor->GetVersion(),
other.GetDescriptor()->GetName(), other.GetDescriptor()->GetVersion()).c_str());
hsAssert(false, plString::Format("descriptor mismatch in FlagDifferentState, mine %s %d, other %s %d",
fDescriptor->GetName().c_str(), fDescriptor->GetVersion(),
other.GetDescriptor()->GetName().c_str(), other.GetDescriptor()->GetVersion()).c_str());
}
}
@ -597,9 +598,9 @@ void plStateDataRecord::FlagNewerState(const plStateDataRecord& other, bool resp
}
else
{
hsAssert(false, xtl::format("descriptor mismatch in FlagNewerState, mine %s %d, other %s %d",
fDescriptor->GetName(), fDescriptor->GetVersion(),
other.GetDescriptor()->GetName(), other.GetDescriptor()->GetVersion()).c_str());
hsAssert(false, plString::Format("descriptor mismatch in FlagNewerState, mine %s %d, other %s %d",
fDescriptor->GetName().c_str(), fDescriptor->GetVersion(),
other.GetDescriptor()->GetName().c_str(), other.GetDescriptor()->GetVersion()).c_str());
}
}
@ -651,16 +652,16 @@ bool plStateDataRecord::IConvertVar(plSimpleStateVariable* fromVar, plSimpleStat
return true; // ok
}
plStateVariable* plStateDataRecord::IFindVar(const VarsList& vars, const char* name) const
plStateVariable* plStateDataRecord::IFindVar(const VarsList& vars, const plString& name) const
{
for (int i = 0; i < vars.size(); i++)
{
if (!stricmp(vars[i]->GetVarDescriptor()->GetName(), name))
if (!vars[i]->GetVarDescriptor()->GetName().CompareI(name))
return vars[i];
}
if (plSDLMgr::GetInstance()->GetNetApp())
plSDLMgr::GetInstance()->GetNetApp()->ErrorMsg("Failed to find SDL var %s", name);
plSDLMgr::GetInstance()->GetNetApp()->ErrorMsg("Failed to find SDL var %s", name.c_str());
return nil;
}
@ -674,7 +675,7 @@ bool plStateDataRecord::ConvertTo( plStateDescriptor* other, bool force )
if (!other && !force)
return false; // err
hsAssert(!stricmp(fDescriptor->GetName(), other->GetName()), "descriptor mismatch");
hsAssert(!fDescriptor->GetName().CompareI(other->GetName()), "descriptor mismatch");
if ( !force && (other == fDescriptor || other->GetVersion()==fDescriptor->GetVersion()))
return true; // ok, nothing to do
@ -682,7 +683,7 @@ bool plStateDataRecord::ConvertTo( plStateDescriptor* other, bool force )
hsAssert(other->GetVersion()>=fDescriptor->GetVersion(), "converting to an older state descriptor version?");
hsLogEntry( plNetApp::StaticDebugMsg( "SDR(%p) converting sdl record %s from version %d to %d (force:%d)",
this, fDescriptor->GetName(), fDescriptor->GetVersion(), other->GetVersion(), force ) );
this, fDescriptor->GetName().c_str(), fDescriptor->GetVersion(), other->GetVersion(), force ) );
// make other StateData to represent other descriptor,
// this will be the destination for the convert operation
@ -696,7 +697,7 @@ bool plStateDataRecord::ConvertTo( plStateDescriptor* other, bool force )
{
// get other var info
plSimpleStateVariable* otherVar = otherStateData.GetVar(i);
const char* otherVarName = otherVar->GetVarDescriptor()->GetName();
plString otherVarName = otherVar->GetVarDescriptor()->GetName();
// find corresponding var in my data
plSimpleStateVariable* myVar=FindVar(otherVarName);
@ -708,7 +709,7 @@ bool plStateDataRecord::ConvertTo( plStateDescriptor* other, bool force )
for(i=0;i<otherStateData.GetNumSDVars(); i++)
{
plSDStateVariable* otherSDVar = otherStateData.GetSDVar(i);
const char* otherSDVarName = otherSDVar->GetVarDescriptor()->GetName();
plString otherSDVarName = otherSDVar->GetVarDescriptor()->GetName();
// find corresponding var in my data
plSDStateVariable* mySDVar=FindSDVar(otherSDVarName);
@ -747,7 +748,7 @@ void plStateDataRecord::DumpToObjectDebugger(const char* msg, bool dirtyOnly, in
dbg->LogMsg(plString::Format("%s%s", pad.c_str(),msg).c_str());
dbg->LogMsg(plString::Format("%sSDR(%p), desc=%s, showDirty=%d, numVars=%d, vol=%d",
pad.c_str(), this, fDescriptor->GetName(), dirtyOnly, numVars+numSDVars, fFlags&kVolatile).c_str());
pad.c_str(), this, fDescriptor->GetName().c_str(), dirtyOnly, numVars+numSDVars, fFlags&kVolatile).c_str());
// dump simple vars
for(i=0;i<fVarsList.size(); i++)
@ -787,7 +788,8 @@ void plStateDataRecord::DumpToStream(hsStream* stream, const char* msg, bool dir
stream->Write(logStr.GetSize(), logStr.c_str());
}
logStr = plString::Format("%sSDR(%p), desc=%s, showDirty=%d, numVars=%d, vol=%d", pad.c_str(), this, fDescriptor->GetName(), dirtyOnly, numVars+numSDVars, fFlags&kVolatile);
logStr = plString::Format("%sSDR(%p), desc=%s, showDirty=%d, numVars=%d, vol=%d",
pad.c_str(), this, fDescriptor->GetName().c_str(), dirtyOnly, numVars+numSDVars, fFlags&kVolatile);
stream->Write(logStr.GetSize(), logStr.c_str());
// dump simple vars

View File

@ -56,19 +56,18 @@ plStateDescriptor::~plStateDescriptor()
void plStateDescriptor::IDeInit()
{
delete [] fName;
int i;
for(i=0;i<fVarsList.size();i++)
delete fVarsList[i];
fVarsList.clear();
}
plVarDescriptor* plStateDescriptor::FindVar(const char* name, int* idx) const
plVarDescriptor* plStateDescriptor::FindVar(const plString& name, int* idx) const
{
VarsList::const_iterator it;
for(it=fVarsList.begin(); it != fVarsList.end(); it++)
{
if (!stricmp((*it)->GetName(), name))
if (!(*it)->GetName().CompareI(name))
{
if (idx)
*idx = it-fVarsList.begin();
@ -94,9 +93,8 @@ bool plStateDescriptor::Read(hsStream* s)
}
IDeInit();
delete [] fName;
fName = s->ReadSafeString();
fName = s->ReadSafeString_TEMP();
uint16_t version=s->ReadLE16();
fVersion=version;

View File

@ -108,11 +108,9 @@ public:
void plStateVarNotificationInfo::Read(hsStream* s, uint32_t readOptions)
{
uint8_t saveFlags=s->ReadByte(); // unused
char* hint=s->ReadSafeString();
if (hint && !(readOptions & plSDL::kSkipNotificationInfo))
fHintString = (const char*)hint;
// we're done with it...
delete[] hint;
plString hint=s->ReadSafeString_TEMP();
if (!hint.IsNull() && !(readOptions & plSDL::kSkipNotificationInfo))
fHintString = hint;
}
void plStateVarNotificationInfo::Write(hsStream* s, uint32_t writeOptions) const
@ -212,8 +210,8 @@ void plSimpleStateVariable::IDeAlloc()
}
break;
default:
hsAssert(false, xtl::format("undefined atomic type:%d var:%s cnt:%d",
type, GetName() ? GetName() : "?", GetCount()).c_str());
hsAssert(false, plString::Format("undefined atomic type:%d var:%s cnt:%d",
type, GetName().c_str("?"), GetCount()).c_str());
break;
};
@ -328,12 +326,11 @@ void plSimpleStateVariable::TimeStamp( const plUnifiedTime & ut/*=plUnifiedTime:
//
// Set value from string. Used to set default values which are specified as strings.
//
bool plSimpleStateVariable::SetFromString(const char* valueConst, int idx, bool timeStampNow)
bool plSimpleStateVariable::SetFromString(const plString& value, int idx, bool timeStampNow)
{
if (!valueConst)
if (value.IsNull())
return false;
std::string value = valueConst;
plVarDescriptor::Type type=fVar.GetAtomicType();
switch(type)
{
@ -346,54 +343,47 @@ bool plSimpleStateVariable::SetFromString(const char* valueConst, int idx, bool
case plVarDescriptor::kByte:
{
// handles value in the form "(i,j,k)" for vectors
static char seps[] = "( ,)";
char* ptr = strtok( (char*)value.c_str(), seps );
std::vector<plString> bits = value.Tokenize("( ,)");
int i=idx*fVar.GetAtomicCount();
while (ptr)
for (std::vector<plString>::iterator ptr = bits.begin(); ptr != bits.end(); ++ptr)
{
if ((type==plVarDescriptor::kInt) && fI)
fI[i++] = atoi(ptr);
fI[i++] = ptr->ToInt();
else if (type==plVarDescriptor::kShort && fS)
fS[i++] = (short)atoi(ptr);
fS[i++] = static_cast<short>(ptr->ToInt());
else if (type==plVarDescriptor::kByte && fBy)
fBy[i++] = (uint8_t)atoi(ptr);
fBy[i++] = static_cast<uint8_t>(ptr->ToInt());
else if ( (type==plVarDescriptor::kFloat || type==plVarDescriptor::kAgeTimeOfDay) && fF)
fF[i++] = (float)atof(ptr);
fF[i++] = static_cast<float>(ptr->ToFloat());
else if ( (type==plVarDescriptor::kDouble || type==plVarDescriptor::kTime) && fD)
fD[i++] = atof(ptr);
ptr = strtok(nil, seps);
fD[i++] = ptr->ToDouble();
}
}
break;
case plVarDescriptor::kBool:
{
// handles value in the form "(i,j,k)" for things like vectors
static char seps[] = "( ,)";
char* ptr = strtok( (char*)value.c_str(), seps );
std::vector<plString> bits = value.Tokenize("( ,)");
int i=idx*fVar.GetAtomicCount();
while (ptr)
for (std::vector<plString>::iterator ptr = bits.begin(); ptr != bits.end(); ++ptr)
{
if (!stricmp(ptr, "true"))
if (!ptr->CompareI("true"))
fB[i++]=true;
else
if (!stricmp(ptr, "false"))
else if (!ptr->CompareI("false"))
fB[i++]=false;
else
fB[i++] = (atoi(ptr) != 0);
ptr = strtok(nil, seps);
fB[i++] = (ptr->ToInt() != 0);
}
}
break;
case plVarDescriptor::kString32:
{
// handles value in the form "(i,j,k)" for things like vectors
static char seps[] = "( ,)";
char* ptr = strtok( (char*)value.c_str(), seps );
std::vector<plString> bits = value.Tokenize("( ,)");
int i=idx*fVar.GetAtomicCount();
while (ptr)
for (std::vector<plString>::iterator ptr = bits.begin(); ptr != bits.end(); ++ptr)
{
hsStrncpy(fS32[i++], ptr, 32);
ptr = strtok(nil, seps);
hsStrncpy(fS32[i++], ptr->c_str(), 32);
}
}
break;
@ -419,12 +409,12 @@ void plSimpleStateVariable::IVarSet(bool timeStampNow/*=true*/)
//
// Get value as string.
//
char* plSimpleStateVariable::GetAsString(int idx) const
plString plSimpleStateVariable::GetAsString(int idx) const
{
int j;
std::string str;
plString str;
if (fVar.GetAtomicCount()>1)
str = str + "(";
str += "(";
plVarDescriptor::Type type=fVar.GetAtomicType();
switch(type)
@ -442,20 +432,20 @@ char* plSimpleStateVariable::GetAsString(int idx) const
for(j=0;j<fVar.GetAtomicCount();j++)
{
if (type==plVarDescriptor::kInt)
str.append( xtl::format( "%d", fI[i++]) );
str += plString::Format( "%d", fI[i++]);
else if (type==plVarDescriptor::kShort)
str.append( xtl::format( "%d", fS[i++]) );
str += plString::Format( "%d", fS[i++]);
else if (type==plVarDescriptor::kByte)
str.append( xtl::format( "%d", fBy[i++]) );
str += plString::Format( "%d", fBy[i++]);
else if (type==plVarDescriptor::kFloat || type==plVarDescriptor::kAgeTimeOfDay)
str.append( xtl::format( "%.3f", fF[i++]) );
str += plString::Format( "%.3f", fF[i++]);
else if (type==plVarDescriptor::kDouble)
str.append( xtl::format( "%.3f", fD[i++]) );
str += plString::Format( "%.3f", fD[i++]);
else if (type==plVarDescriptor::kTime)
{
double tmp;
Get(&tmp, i++);
str.append( xtl::format( "%.3f", tmp) );
str += plString::Format( "%.3f", tmp);
}
if (j==fVar.GetAtomicCount()-1)
@ -474,7 +464,7 @@ char* plSimpleStateVariable::GetAsString(int idx) const
int i=idx*fVar.GetAtomicCount();
for(j=0;j<fVar.GetAtomicCount();j++)
{
str.append( xtl::format( "%s", fB[i++] ? "true" : "false") );
str += plString::Format( "%s", fB[i++] ? "true" : "false");
if (j==fVar.GetAtomicCount()-1)
{
@ -492,7 +482,7 @@ char* plSimpleStateVariable::GetAsString(int idx) const
int i=idx*fVar.GetAtomicCount();
for(j=0;j<fVar.GetAtomicCount();j++)
{
str.append( xtl::format( "%s", fS32[i++]) );
str += plString::Format( "%s", fS32[i++]);
if (j==fVar.GetAtomicCount()-1)
{
@ -510,7 +500,7 @@ char* plSimpleStateVariable::GetAsString(int idx) const
int i=idx*fVar.GetAtomicCount();
for(j=0;j<fVar.GetAtomicCount();j++)
{
str.append( xtl::format( "%s", "other") );
str += "other";
if (j==fVar.GetAtomicCount()-1)
{
@ -524,7 +514,7 @@ char* plSimpleStateVariable::GetAsString(int idx) const
break;
}
return hsStrcpy(str.c_str());
return str;
}
//
@ -2131,7 +2121,7 @@ case type: \
} \
break;
void plSimpleStateVariable::NotifyStateChange(const plSimpleStateVariable* other, const char* sdlName)
void plSimpleStateVariable::NotifyStateChange(const plSimpleStateVariable* other, const plString& sdlName)
{
if (fChangeNotifiers.size()==0)
return;
@ -2174,8 +2164,8 @@ void plSimpleStateVariable::NotifyStateChange(const plSimpleStateVariable* other
if (plNetObjectDebuggerBase::GetInstance() && plNetObjectDebuggerBase::GetInstance()->GetDebugging())
{
plNetObjectDebuggerBase::GetInstance()->LogMsg(
xtl::format("Var %s did %s send notification difference. Has %d notifiers with %d recipients.",
GetName(), !notify ? "NOT" : "", fChangeNotifiers.size(), numNotifiers).c_str());
plString::Format("Var %s did %s send notification difference. Has %d notifiers with %d recipients.",
GetName().c_str(), !notify ? "NOT" : "", fChangeNotifiers.size(), numNotifiers).c_str());
}
}
@ -2290,12 +2280,12 @@ void plSimpleStateVariable::DumpToObjectDebugger(bool dirtyOnly, int level) cons
if (!dbg)
return;
std::string pad;
plString pad;
int i;
for(i=0;i<level; i++)
pad += " ";
std::string logMsg = xtl::format( "%sSimpleVar, name:%s[%d]", pad.c_str(), GetName(), GetCount());
plString logMsg = plString::Format( "%sSimpleVar, name:%s[%d]", pad.c_str(), GetName().c_str(), GetCount());
if (GetCount()>1)
{
dbg->LogMsg(logMsg.c_str()); // it's going to be a long msg, so print it on its own line
@ -2305,22 +2295,21 @@ void plSimpleStateVariable::DumpToObjectDebugger(bool dirtyOnly, int level) cons
pad += "\t";
for(i=0;i<GetCount(); i++)
{
char* s=GetAsString(i);
plString s=GetAsString(i);
if (fVar.GetAtomicType() == plVarDescriptor::kTime)
{
const char* p=fT[i].PrintWMillis();
logMsg += xtl::format( "%sVar:%d gameTime:%s pst:%s ts:%s",
pad.c_str(), i, s ? s : "?", p, fTimeStamp.Format("%c").c_str() );
logMsg += plString::Format( "%sVar:%d gameTime:%s pst:%s ts:%s",
pad.c_str(), i, s.c_str("?"), p, fTimeStamp.Format("%c").c_str() );
}
else
{
logMsg +=xtl::format( "%sVar:%d value:%s ts:%s",
pad.c_str(), i, s ? s : "?", fTimeStamp.AtEpoch() ? "0" : fTimeStamp.Format("%c").c_str() );
logMsg += plString::Format( "%sVar:%d value:%s ts:%s",
pad.c_str(), i, s.c_str("?"), fTimeStamp.AtEpoch() ? "0" : fTimeStamp.Format("%c").c_str() );
}
delete [] s;
if ( !dirtyOnly )
logMsg += xtl::format( " dirty:%d", IsDirty() );
logMsg += plString::Format( " dirty:%d", IsDirty() );
dbg->LogMsg(logMsg.c_str());
logMsg = "";
@ -2329,12 +2318,12 @@ void plSimpleStateVariable::DumpToObjectDebugger(bool dirtyOnly, int level) cons
void plSimpleStateVariable::DumpToStream(hsStream* stream, bool dirtyOnly, int level) const
{
std::string pad;
plString pad;
int i;
for(i=0;i<level; i++)
pad += " ";
std::string logMsg = xtl::format( "%sSimpleVar, name:%s[%d]", pad.c_str(), GetName(), GetCount());
plString logMsg = plString::Format( "%sSimpleVar, name:%s[%d]", pad.c_str(), GetName().c_str(), GetCount());
if (GetCount()>1)
{
stream->WriteString(logMsg.c_str()); // it's going to be a long msg, so print it on its own line
@ -2344,22 +2333,21 @@ void plSimpleStateVariable::DumpToStream(hsStream* stream, bool dirtyOnly, int l
pad += "\t";
for(i=0;i<GetCount(); i++)
{
char* s=GetAsString(i);
plString s=GetAsString(i);
if (fVar.GetAtomicType() == plVarDescriptor::kTime)
{
const char* p=fT[i].PrintWMillis();
logMsg += xtl::format( "%sVar:%d gameTime:%s pst:%s ts:%s",
pad.c_str(), i, s ? s : "?", p, fTimeStamp.Format("%c").c_str() );
logMsg += plString::Format( "%sVar:%d gameTime:%s pst:%s ts:%s",
pad.c_str(), i, s.c_str("?"), p, fTimeStamp.Format("%c").c_str() );
}
else
{
logMsg +=xtl::format( "%sVar:%d value:%s ts:%s",
pad.c_str(), i, s ? s : "?", fTimeStamp.AtEpoch() ? "0" : fTimeStamp.Format("%c").c_str() );
logMsg += plString::Format( "%sVar:%d value:%s ts:%s",
pad.c_str(), i, s.c_str("?"), fTimeStamp.AtEpoch() ? "0" : fTimeStamp.Format("%c").c_str() );
}
delete [] s;
if ( !dirtyOnly )
logMsg += xtl::format( " dirty:%d", IsDirty() );
logMsg += plString::Format( " dirty:%d", IsDirty() );
stream->WriteString(logMsg.c_str());
logMsg = "";
@ -2497,9 +2485,9 @@ void plSDStateVariable::CopyFrom(plSDStateVariable* other, uint32_t writeOptions
//
void plSDStateVariable::UpdateFrom(plSDStateVariable* other, uint32_t writeOptions/*=0*/)
{
hsAssert(!stricmp(other->GetSDVarDescriptor()->GetName(), fVarDescriptor->GetName()),
xtl::format("var descriptor mismatch in UpdateFrom, name %s,%s ver %d,%d",
GetName(), other->GetName()).c_str());
hsAssert(!other->GetSDVarDescriptor()->GetName().CompareI(fVarDescriptor->GetName()),
plString::Format("var descriptor mismatch in UpdateFrom, name %s,%s ver %d,%d",
GetName().c_str(), other->GetName().c_str()).c_str());
Resize(other->GetCount()); // make sure sizes match
bool dirtyOnly = (writeOptions & plSDL::kDirtyOnly);
@ -2521,8 +2509,8 @@ void plSDStateVariable::ConvertTo(plSDStateVariable* otherSDVar, bool force )
plStateDescriptor* otherSD=otherSDVar->GetSDVarDescriptor()->GetStateDescriptor();
hsLogEntry( plNetApp::StaticDebugMsg( "SDSV(%p) converting %s from %s to %s (force:%d)",
this, fVarDescriptor->GetName(), fVarDescriptor->GetTypeString(),
otherSDVar->GetSDVarDescriptor()->GetTypeString(), force ) );
this, fVarDescriptor->GetName().c_str(), fVarDescriptor->GetTypeString().c_str(),
otherSDVar->GetSDVarDescriptor()->GetTypeString().c_str(), force ) );
int j;
for(j=0;j<GetCount(); j++)

View File

@ -55,96 +55,77 @@ const uint8_t plVarDescriptor::kVersion=3; // for Read/Write format
// State Var
/////////////////////////////////////////////////////////////////////////////////
plVarDescriptor::plVarDescriptor() :
fName(nil),
fCount(1),
fType(kNone),
fTypeString(nil),
fDefault(nil),
fFlags(0)
{
}
plVarDescriptor::~plVarDescriptor()
{
delete [] fName;
delete [] fDefault;
delete [] fTypeString;
}
//
// Set type from a string. Return false on err.
//
bool plVarDescriptor::SetType(const char* type)
bool plVarDescriptor::SetType(const plString& type)
{
if (!type)
if (type.IsNull())
return false;
if (!stricmp(type, "vector3"))
if (!type.CompareI("vector3"))
fType=kVector3;
else
if (!stricmp(type, "point3"))
if (!type.CompareI("point3"))
fType=kPoint3;
else
if (!stricmp(type, "rgb"))
if (!type.CompareI("rgb"))
fType=kRGB;
else
if (!stricmp(type, "rgba"))
if (!type.CompareI("rgba"))
fType=kRGBA;
else
if (!stricmp(type, "rgb8"))
if (!type.CompareI("rgb8"))
fType=kRGB8;
else
if (!stricmp(type, "rgba8"))
if (!type.CompareI("rgba8"))
fType=kRGBA8;
else
if (!strnicmp(type, "quat",4))
if (!type.CompareNI("quat", 4))
fType=kQuaternion;
else
if (!stricmp(type, "rgba"))
if (!type.CompareI("rgba"))
fType=kRGBA;
else
if (!stricmp(type, "int"))
if (!type.CompareI("int"))
fType=kInt;
else
if (!stricmp(type, "byte"))
if (!type.CompareI("byte"))
fType=kByte;
else
if (!stricmp(type, "short"))
if (!type.CompareI("short"))
fType=kShort;
else
if (!stricmp(type, "float"))
if (!type.CompareI("float"))
fType=kFloat;
else
if (!stricmp(type, "double"))
if (!type.CompareI("double"))
fType=kDouble;
else
if (!stricmp(type, "time"))
if (!type.CompareI("time"))
fType=kTime;
else
if (!stricmp(type, "ageTimeOfDay"))
if (!type.CompareI("ageTimeOfDay"))
fType=kAgeTimeOfDay;
else
if (!stricmp(type, "bool"))
if (!type.CompareI("bool"))
fType=kBool;
else
if (!stricmp(type, "string32"))
if (!type.CompareI("string32"))
fType=kString32;
else
if (!stricmp(type, "plKey"))
if (!type.CompareI("plKey"))
fType=kKey;
else
if (!stricmp(type, "message") || !stricmp(type, "creatable") )
if (!type.CompareI("message") || !type.CompareI("creatable") )
fType=kCreatable;
else
if (*type=='$')
if (type.CharAt(0)=='$')
fType=kStateDescriptor;
else
return false; // err
delete [] fTypeString;
fTypeString = hsStrcpy(type);
fTypeString = type;
return true; // ok
}
@ -156,8 +137,7 @@ void plVarDescriptor::CopyFrom(const plVarDescriptor* other)
SetCount(other->GetCount());
SetDisplayOptions(other->GetDisplayOptions());
delete [] fTypeString;
fTypeString=hsStrcpy(other->GetTypeString());
fTypeString=other->GetTypeString();
fType = other->GetType();
fFlags = other->fFlags;
@ -178,8 +158,7 @@ bool plVarDescriptor::Read(hsStream* s)
return false;
}
delete [] fName;
fName=s->ReadSafeString();
fName=s->ReadSafeString_TEMP();
plMsgStdStringHelper::Peek(fDisplayOptions, s);
@ -187,8 +166,7 @@ bool plVarDescriptor::Read(hsStream* s)
fType=(Type)s->ReadByte();
delete [] fDefault;
fDefault = s->ReadSafeString();
fDefault = s->ReadSafeString_TEMP();
fFlags = s->ReadLE32();
return true;
@ -259,87 +237,84 @@ int plSimpleVarDescriptor::GetSize() const
// Set type from a string. Return false on err.
// Sets atomicCount and atomicType
//
bool plSimpleVarDescriptor::SetType(const char* type)
bool plSimpleVarDescriptor::SetType(const plString& type)
{
if (!type)
return false;
if (!plVarDescriptor::SetType(type))
return false;
if (!stricmp(type, "vector3"))
if (!type.CompareI("vector3"))
{
fAtomicCount = 3;
fAtomicType=kFloat;
}
else
if (!stricmp(type, "point3"))
if (!type.CompareI("point3"))
{
fAtomicCount = 3;
fAtomicType=kFloat;
}
else
if (!stricmp(type, "rgb"))
if (!type.CompareI("rgb"))
{
fAtomicCount = 3;
fAtomicType=kFloat;
}
else
if (!stricmp(type, "rgba"))
if (!type.CompareI("rgba"))
{
fAtomicCount = 4;
fAtomicType=kFloat;
}
else
if (!stricmp(type, "rgb8"))
if (!type.CompareI("rgb8"))
{
fAtomicCount = 3;
fAtomicType=kByte;
}
else
if (!stricmp(type, "rgba8"))
if (!type.CompareI("rgba8"))
{
fAtomicCount = 4;
fAtomicType=kByte;
}
else
if (!strnicmp(type, "quat",4))
if (!type.CompareNI("quat", 4))
{
fAtomicCount = 4;
fAtomicType=kFloat;
}
else
if (!stricmp(type, "int"))
if (!type.CompareI("int"))
fAtomicType=kInt;
else
if (!stricmp(type, "byte"))
if (!type.CompareI("byte"))
fAtomicType=kByte;
else
if (!stricmp(type, "short"))
if (!type.CompareI("short"))
fAtomicType=kShort;
else
if (!stricmp(type, "float"))
if (!type.CompareI("float"))
fAtomicType=kFloat;
else
if (!stricmp(type, "double"))
if (!type.CompareI("double"))
fAtomicType=kDouble;
else
if (!stricmp(type, "time"))
if (!type.CompareI("time"))
fAtomicType=kTime;
else
if (!stricmp(type, "ageTimeOfDay"))
if (!type.CompareI("ageTimeOfDay"))
fAtomicType=kAgeTimeOfDay;
else
if (!stricmp(type, "bool"))
if (!type.CompareI("bool"))
fAtomicType=kBool;
else
if (!stricmp(type, "string32"))
if (!type.CompareI("string32"))
fAtomicType=kString32;
else
if (!stricmp(type, "plKey"))
if (!type.CompareI("plKey"))
fAtomicType=kKey;
else
if (!stricmp(type, "message") || !stricmp(type, "creatable"))
if (!type.CompareI("message") || !type.CompareI("creatable"))
fAtomicType=kCreatable;
else
return false; // err
@ -398,12 +373,11 @@ bool plSDVarDescriptor::Read(hsStream* s)
if (!plVarDescriptor::Read(s))
return false;
char* sdName=s->ReadSafeString();
plString sdName=s->ReadSafeString_TEMP();
uint16_t version = s->ReadLE16();
plStateDescriptor* sd=plSDLMgr::GetInstance()->FindDescriptor(sdName, version);
hsAssert( sd, xtl::format("Failed to find sdl descriptor: %s,%d. Missing legacy descriptor?", sdName, version ).c_str() );
hsAssert( sd, plString::Format("Failed to find sdl descriptor: %s,%d. Missing legacy descriptor?", sdName.c_str(), version ).c_str() );
SetStateDesc(sd);
delete [] sdName;
return true;
}