From 939f6c3d41fa47bc453680a39168d1a08fbfa5f2 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sat, 11 Jan 2014 00:18:23 -0800 Subject: [PATCH 01/15] Accept plStrings in plDynamicTextMap for rendering and font names --- .../pfJournalBook/pfJournalBook.cpp | 12 ++-- .../FeatureLib/pfJournalBook/pfJournalBook.h | 2 +- .../plGImage/plDynSurfaceWriter.cpp | 31 ++++----- .../PubUtilLib/plGImage/plDynSurfaceWriter.h | 20 +++--- .../PubUtilLib/plGImage/plDynamicTextMap.cpp | 69 +++++++------------ .../PubUtilLib/plGImage/plDynamicTextMap.h | 23 +++---- Sources/Plasma/PubUtilLib/plGImage/plFont.cpp | 44 +++++------- Sources/Plasma/PubUtilLib/plGImage/plFont.h | 26 +++---- .../PubUtilLib/plGImage/plFontCache.cpp | 28 +++----- .../Plasma/PubUtilLib/plGImage/plFontCache.h | 2 +- .../PubUtilLib/plGImage/plWinFontCache.cpp | 23 +++---- .../PubUtilLib/plGImage/plWinFontCache.h | 10 +-- .../plFontConverter/plFontConverterProc.cpp | 6 +- 13 files changed, 129 insertions(+), 167 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp b/Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp index aaa2c9ad..13b45121 100644 --- a/Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp +++ b/Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp @@ -2608,10 +2608,10 @@ void pfJournalBook::IRenderPage( uint32_t page, uint32_t whichDTMap, bool sup uint32_t idx; uint16_t width, height, y, x, ascent, lastX, lastY; - uint8_t fontFlags, fontSize; - const wchar_t *fontFace; + uint8_t fontFlags, fontSize; + plString fontFace; hsColorRGBA fontColor; - int16_t fontSpacing; + int16_t fontSpacing; bool needSFX = false; // Find and set initial font properties @@ -3339,7 +3339,7 @@ void pfJournalBook::ISetDecalLayers(hsGMaterial *material,hsTArrayfText != L"" ) { - face = chunk->fText.c_str(); + face = plString::FromWchar(chunk->fText.c_str()); found |= kFace; } if( !( found & kSize ) && chunk->fFontSize > 0 ) @@ -3403,7 +3403,7 @@ void pfJournalBook::IFindFontProps( uint32_t chunkIdx, const wchar_t *&face, // Set any un-found defaults if( !( found & kFace ) ) - face = L"Arial"; + face = "Arial"; if( !( found & kSize ) ) size = 24; if( !( found & kFlags ) ) diff --git a/Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.h b/Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.h index 4fdf7d61..d30030c7 100644 --- a/Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.h +++ b/Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.h @@ -535,7 +535,7 @@ class pfJournalBook : public hsKeyedObject // Starting at the given chunk, works backwards to determine the full set of current // font properties at that point, or assigns defaults if none were specified - void IFindFontProps( uint32_t chunkIdx, const wchar_t *&face, uint8_t &size, uint8_t &flags, hsColorRGBA &color, int16_t &spacing ); + void IFindFontProps( uint32_t chunkIdx, plString &face, uint8_t &size, uint8_t &flags, hsColorRGBA &color, int16_t &spacing ); // Find the last paragraph chunk and thus the last par alignment settings uint8_t IFindLastAlignment( void ) const; diff --git a/Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.cpp b/Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.cpp index 1fb22f83..cde40ce4 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.cpp @@ -86,7 +86,6 @@ plDynSurfaceWriter::plWinSurface::plWinSurface() fWidth = fHeight = 0; fSaveNum = 0; - fFontFace = nil; fFontSize = 0; fFontFlags = 0; fFontAntiAliasRGB = false; @@ -207,8 +206,7 @@ void plDynSurfaceWriter::plWinSurface::Release( void ) fBits = nil; fWidth = fHeight = 0; - delete [] fFontFace; - fFontFace = nil; + fFontFace = plString::Null; fFontSize = 0; fFontFlags = 0; fFontAntiAliasRGB = false; @@ -231,19 +229,18 @@ static int SafeStrCmp( const char *str1, const char *str2 ) return -1; } -bool plDynSurfaceWriter::plWinSurface::FontMatches( const char *face, uint16_t size, uint8_t flags, bool aaRGB ) +bool plDynSurfaceWriter::plWinSurface::FontMatches( const plString &face, uint16_t size, uint8_t flags, bool aaRGB ) { - if( SafeStrCmp( face, fFontFace ) == 0 && fFontSize == size && + if( face == fFontFace && fFontSize == size && fFontFlags == flags && fFontAntiAliasRGB == aaRGB ) return true; return false; } -void plDynSurfaceWriter::plWinSurface::SetFont( const char *face, uint16_t size, uint8_t flags, bool aaRGB ) +void plDynSurfaceWriter::plWinSurface::SetFont( const plString &face, uint16_t size, uint8_t flags, bool aaRGB ) { - delete [] fFontFace; - fFontFace = ( face != nil ) ? hsStrcpy( face ) : nil; + fFontFace = face; fFontSize = size; fFontFlags = flags; fFontAntiAliasRGB = aaRGB; @@ -256,7 +253,7 @@ void plDynSurfaceWriter::plWinSurface::SetFont( const char *face, uint16_t si fFont = nil; } - if( face == nil ) + if (face.IsEmpty()) return; bool bold = ( fFontFlags & plDynSurfaceWriter::kFontBold ) ? true : false; @@ -283,10 +280,10 @@ void plDynSurfaceWriter::plWinSurface::SetFont( const char *face, uint16_t si if( fFont == nil ) { hsAssert( false, "Cannot create Windows font for plDynSurfaceWriter" ); - plStatusLog::AddLineS( "pipeline.log", "ERROR: Cannot allocate font for RGB surface! (face: %s, size: %d %s %s)", face, nHeight, bold ? "bold" : "", italic ? "italic" : "" ); + plStatusLog::AddLineS( "pipeline.log", "ERROR: Cannot allocate font for RGB surface! (face: %s, size: %d %s %s)", + face.c_str(), nHeight, bold ? "bold" : "", italic ? "italic" : "" ); - delete [] fFontFace; - fFontFace = nil; + fFontFace = plString::Null; fFontSize = 0; return; } @@ -385,7 +382,7 @@ void plDynSurfaceWriter::IInit( void ) fJustify = kLeftJustify; fFlags = 0; fFlushed = true; - fFontFace = nil; + fFontFace = plString::Null; fFontSize = 0; fFontBlockedRGB = false; } @@ -401,8 +398,7 @@ void plDynSurfaceWriter::Reset( void ) fCurrTarget = nil; fFlushed = true; - delete [] fFontFace; - fFontFace = nil; + fFontFace = plString::Null; fFontSize = 0; } @@ -514,8 +510,7 @@ void plDynSurfaceWriter::SwitchTarget( plDynamicTextMap *target ) if( hadToAllocate ) { - delete [] fFontFace; - fFontFace = nil; + fFontFace = plString::Null; fFontSize = 0; fFontFlags = 0; } @@ -701,7 +696,7 @@ void plDynSurfaceWriter::SetFont( const char *face, uint16_t size, uint8_t fo //// ISetFont ///////////////////////////////////////////////////////////////// -void plDynSurfaceWriter::ISetFont( const char *face, uint16_t size, uint8_t fontFlags, bool antiAliasRGB ) +void plDynSurfaceWriter::ISetFont( const plString &face, uint16_t size, uint8_t fontFlags, bool antiAliasRGB ) { fFlags = ( fFlags & ~kFontShadowed ) | ( fontFlags & kFontShadowed ); diff --git a/Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.h b/Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.h index cf35388e..b94c69a2 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.h +++ b/Sources/Plasma/PubUtilLib/plGImage/plDynSurfaceWriter.h @@ -148,16 +148,16 @@ class plDynSurfaceWriter void IRefreshOSJustify( void ); void ISetTextColor( hsColorRGBA &color, bool blockRGB ); - void ISetFont( const char *face, uint16_t size, uint8_t fontFlags = 0, bool antiAliasRGB = true ); + void ISetFont( const plString &face, uint16_t size, uint8_t fontFlags = 0, bool antiAliasRGB = true ); plDynamicTextMap *fCurrTarget; uint32_t fFlags; Justify fJustify; bool fFlushed; - char *fFontFace; - uint16_t fFontSize; - uint8_t fFontFlags; + plString fFontFace; + uint16_t fFontSize; + uint8_t fFontFlags; bool fFontAntiAliasRGB; bool fFontBlockedRGB; @@ -180,11 +180,11 @@ class plDynSurfaceWriter COLORREF fTextColor; int fSaveNum; - uint16_t fWidth, fHeight; + uint16_t fWidth, fHeight; - char *fFontFace; - uint16_t fFontSize; - uint8_t fFontFlags; + plString fFontFace; + uint16_t fFontSize; + uint8_t fFontFlags; bool fFontAntiAliasRGB, fFontBlockedRGB; plWinSurface(); @@ -194,8 +194,8 @@ class plDynSurfaceWriter void Release( void ); bool WillFit( uint16_t w, uint16_t h ); - bool FontMatches( const char *face, uint16_t size, uint8_t flags, bool aaRGB ); - void SetFont( const char *face, uint16_t size, uint8_t flags, bool aaRGB ); + bool FontMatches( const plString &face, uint16_t size, uint8_t flags, bool aaRGB ); + void SetFont( const plString &face, uint16_t size, uint8_t flags, bool aaRGB ); }; class plWinRGBSurface : public plWinSurface diff --git a/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp b/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp index e862c6cf..96be7b57 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp @@ -77,7 +77,7 @@ plProfile_Extern(MemMipmaps); plDynamicTextMap::plDynamicTextMap() : fVisWidth(0), fVisHeight(0), fHasAlpha(false), fJustify(kLeftJustify), - fInitBuffer(nullptr), fFontFace(nullptr), fFontSize(0), fFontFlags(0), + fInitBuffer(nullptr), fFontSize(0), fFontFlags(0), fFontAntiAliasRGB(false), fFontBlockRGB(false), fHasCreateBeenCalled(false) { fFontColor.Set(0, 0, 0, 1); @@ -89,7 +89,7 @@ plDynamicTextMap::~plDynamicTextMap() } plDynamicTextMap::plDynamicTextMap( uint32_t width, uint32_t height, bool hasAlpha, uint32_t extraWidth, uint32_t extraHeight ) - : fInitBuffer(nullptr), fFontFace(nullptr) + : fInitBuffer(nullptr) { Create( width, height, hasAlpha, extraWidth, extraHeight ); } @@ -163,8 +163,7 @@ void plDynamicTextMap::Reset( void ) delete [] fInitBuffer; fInitBuffer = nil; - delete [] fFontFace; - fFontFace = nil; + fFontFace = plString::Null; // Destroy the old texture ref, since we're no longer using it SetDeviceRef( nil ); @@ -413,22 +412,21 @@ void plDynamicTextMap::SetJustify( Justify j ) //// SetFont ////////////////////////////////////////////////////////////////// -void plDynamicTextMap::SetFont( const char *face, uint16_t size, uint8_t fontFlags, bool antiAliasRGB ) +void plDynamicTextMap::SetFont( const plString &face, uint16_t size, uint8_t fontFlags, bool antiAliasRGB ) { // ===> Don't need to validate creation // if( !IIsValid() ) // return; - delete [] fFontFace; if (plLocalization::UsingUnicode()) { // unicode has a bunch of chars that most fonts don't have, so we override the font choice with one // that will work with the desired language - hsStatusMessageF("We are using a unicode language, overriding font choice of %s", face ? face : "nil"); - fFontFace = hsStrcpy( "Unicode" ); + hsStatusMessageF("We are using a unicode language, overriding font choice of %s", face.c_str("nil")); + fFontFace = "Unicode"; } else - fFontFace = ( face != nil ) ? hsStrcpy( face ) : nil; + fFontFace = face; fFontSize = size; fFontFlags = fontFlags; fFontAntiAliasRGB = antiAliasRGB; @@ -439,11 +437,9 @@ void plDynamicTextMap::SetFont( const char *face, uint16_t size, uint8_t font if ( fCurrFont == nil ) { if (!fCurrFont) - hsStatusMessageF("Font missing - %s. Using Arial", fFontFace ? fFontFace : "nil"); + hsStatusMessageF("Font missing - %s. Using Arial", fFontFace.c_str("nil")); - if ( fFontFace ) - delete [] fFontFace; - fFontFace = hsStrcpy( "Arial" ); + fFontFace = "Arial"; // lets try again with Arial fCurrFont = plFontCache::GetInstance().GetFont( fFontFace, (uint8_t)fFontSize, ( ( fFontFlags & kFontBold ) ? plFont::kFlagBold : 0 ) | @@ -458,13 +454,6 @@ void plDynamicTextMap::SetFont( const char *face, uint16_t size, uint8_t font } } -void plDynamicTextMap::SetFont( const wchar_t *face, uint16_t size, uint8_t fontFlags , bool antiAliasRGB ) -{ - char *sFace = hsWStringToString(face); - SetFont(sFace,size,fontFlags,antiAliasRGB); - delete [] sFace; -} - //// SetLineSpacing /////////////////////////////////////////////////////////// void plDynamicTextMap::SetLineSpacing( int16_t spacing ) @@ -515,11 +504,10 @@ void plDynamicTextMap::DrawString( uint16_t x, uint16_t y, const wchar_t *tex //// DrawClippedString //////////////////////////////////////////////////////// -void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const char *text, uint16_t width, uint16_t height ) +void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const plString &text, uint16_t width, uint16_t height ) { - wchar_t *wText = hsStringToWString(text); - DrawClippedString(x,y,wText,width,height); - delete [] wText; + // TEMP + DrawClippedString(x, y, text.ToWchar().GetData(), width, height); } void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const wchar_t *text, uint16_t width, uint16_t height ) @@ -536,11 +524,10 @@ void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const wchar_t //// DrawClippedString //////////////////////////////////////////////////////// -void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const char *text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height ) +void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const plString &text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height ) { - wchar_t *wText = hsStringToWString(text); - DrawClippedString(x,y,wText,clipX,clipY,width,height); - delete [] wText; + // TEMP + DrawClippedString(x, y, text.ToWchar().GetData(), width, height); } void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const wchar_t *text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height ) @@ -556,11 +543,10 @@ void plDynamicTextMap::DrawClippedString( int16_t x, int16_t y, const wchar_t //// DrawWrappedString //////////////////////////////////////////////////////// -void plDynamicTextMap::DrawWrappedString( uint16_t x, uint16_t y, const char *text, uint16_t width, uint16_t height, uint16_t *lastX, uint16_t *lastY ) +void plDynamicTextMap::DrawWrappedString( uint16_t x, uint16_t y, const plString &text, uint16_t width, uint16_t height, uint16_t *lastX, uint16_t *lastY ) { - wchar_t *wText = hsStringToWString(text); - DrawWrappedString(x,y,wText,width,height,lastX,lastY); - delete [] wText; + // TEMP + DrawWrappedString(x, y, text.ToWchar().GetData(), width, height, lastX, lastY); } void plDynamicTextMap::DrawWrappedString( uint16_t x, uint16_t y, const wchar_t *text, uint16_t width, uint16_t height, uint16_t *lastX, uint16_t *lastY ) @@ -577,12 +563,10 @@ void plDynamicTextMap::DrawWrappedString( uint16_t x, uint16_t y, const wchar //// CalcStringWidth ////////////////////////////////////////////////////////// -uint16_t plDynamicTextMap::CalcStringWidth( const char *text, uint16_t *height ) +uint16_t plDynamicTextMap::CalcStringWidth( const plString &text, uint16_t *height ) { - wchar_t *wText = hsStringToWString(text); - uint16_t w = CalcStringWidth(wText,height); - delete [] wText; - return w; + // TEMP + return CalcStringWidth(text.ToWchar().GetData(), height); } uint16_t plDynamicTextMap::CalcStringWidth( const wchar_t *text, uint16_t *height ) @@ -614,11 +598,10 @@ void plDynamicTextMap::SetFirstLineIndent( int16_t indent ) //// CalcWrappedStringSize //////////////////////////////////////////////////// -void plDynamicTextMap::CalcWrappedStringSize( const char *text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar, uint16_t *maxAscent, uint16_t *lastX, uint16_t *lastY ) +void plDynamicTextMap::CalcWrappedStringSize( const plString &text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar, uint16_t *maxAscent, uint16_t *lastX, uint16_t *lastY ) { - wchar_t *wText = hsStringToWString(text); - CalcWrappedStringSize(wText,width,height,firstClippedChar,maxAscent,lastX,lastY); - delete [] wText; + // TEMP + CalcWrappedStringSize(text.ToWchar().GetData(), width, height, firstClippedChar, maxAscent, lastX, lastY); } void plDynamicTextMap::CalcWrappedStringSize( const wchar_t *text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar, uint16_t *maxAscent, uint16_t *lastX, uint16_t *lastY ) @@ -816,7 +799,7 @@ bool plDynamicTextMap::MsgReceive( plMessage *msg ) SetTextColor( textMsg->fColor, textMsg->fBlockRGB ); if( (textMsg->fCmd & plDynamicTextMsg::kSetFont ) && !textMsg->fString.IsNull()) - SetFont( textMsg->fString.ToWchar(), textMsg->fX, (uint8_t)(textMsg->fFlags) ); + SetFont( textMsg->fString, textMsg->fX, (uint8_t)(textMsg->fFlags) ); if( textMsg->fCmd & plDynamicTextMsg::kSetLineSpacing ) SetLineSpacing( textMsg->fLineSpacing ); @@ -902,7 +885,7 @@ void plDynamicTextMap::Swap( plDynamicTextMap *other ) SWAP_ME( bool, fShadowed, other->fShadowed ); SWAP_ME( Justify, fJustify, other->fJustify ); - SWAP_ME( char *, fFontFace, other->fFontFace ); + SWAP_ME( plString, fFontFace, other->fFontFace ); SWAP_ME( uint16_t, fFontSize, other->fFontSize ); SWAP_ME( uint8_t, fFontFlags, other->fFontFlags ); SWAP_ME( bool, fFontAntiAliasRGB, other->fFontAntiAliasRGB ); diff --git a/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h b/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h index 3083aae1..eddf8c11 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h +++ b/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h @@ -152,23 +152,22 @@ class plDynamicTextMap : public plMipmap kFontShadowed = 0x04 }; - void SetFont( const char *face, uint16_t size, uint8_t fontFlags = 0, bool antiAliasRGB = true ); - void SetFont( const wchar_t *face, uint16_t size, uint8_t fontFlags = 0, bool antiAliasRGB = true ); + void SetFont( const plString &face, uint16_t size, uint8_t fontFlags = 0, bool antiAliasRGB = true ); void SetLineSpacing( int16_t spacing ); void SetTextColor( hsColorRGBA &color, bool blockRGB = false ); void SetJustify( Justify j ); void DrawString( uint16_t x, uint16_t y, const char *text ); void DrawString( uint16_t x, uint16_t y, const wchar_t *text ); - void DrawClippedString( int16_t x, int16_t y, const char *text, uint16_t width, uint16_t height ); + void DrawClippedString( int16_t x, int16_t y, const plString &text, uint16_t width, uint16_t height ); void DrawClippedString( int16_t x, int16_t y, const wchar_t *text, uint16_t width, uint16_t height ); - void DrawClippedString( int16_t x, int16_t y, const char *text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height ); + void DrawClippedString( int16_t x, int16_t y, const plString &text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height ); void DrawClippedString( int16_t x, int16_t y, const wchar_t *text, uint16_t clipX, uint16_t clipY, uint16_t width, uint16_t height ); - void DrawWrappedString( uint16_t x, uint16_t y, const char *text, uint16_t width, uint16_t height, uint16_t *lastX = nil, uint16_t *lastY = nil ); + void DrawWrappedString( uint16_t x, uint16_t y, const plString &text, uint16_t width, uint16_t height, uint16_t *lastX = nil, uint16_t *lastY = nil ); void DrawWrappedString( uint16_t x, uint16_t y, const wchar_t *text, uint16_t width, uint16_t height, uint16_t *lastX = nil, uint16_t *lastY = nil ); - uint16_t CalcStringWidth( const char *text, uint16_t *height = nil ); + uint16_t CalcStringWidth( const plString &text, uint16_t *height = nil ); uint16_t CalcStringWidth( const wchar_t *text, uint16_t *height = nil ); - void CalcWrappedStringSize( const char *text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar = nil, uint16_t *maxAscent = nil, uint16_t *lastX = nil, uint16_t *lastY = nil ); + void CalcWrappedStringSize( const plString &text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar = nil, uint16_t *maxAscent = nil, uint16_t *lastX = nil, uint16_t *lastY = nil ); void CalcWrappedStringSize( const wchar_t *text, uint16_t *width, uint16_t *height, uint32_t *firstClippedChar = nil, uint16_t *maxAscent = nil, uint16_t *lastX = nil, uint16_t *lastY = nil ); void FillRect( uint16_t x, uint16_t y, uint16_t width, uint16_t height, hsColorRGBA &color ); void FrameRect( uint16_t x, uint16_t y, uint16_t width, uint16_t height, hsColorRGBA &color ); @@ -201,8 +200,8 @@ class plDynamicTextMap : public plMipmap // Gets for font values Justify GetFontJustify( void ) const { return fJustify; } - const char *GetFontFace( void ) const { return fFontFace; } - uint16_t GetFontSize( void ) const { return fFontSize; } + plString GetFontFace( void ) const { return fFontFace; } + uint16_t GetFontSize( void ) const { return fFontSize; } bool GetFontAARGB( void ) const { return fFontAntiAliasRGB; } hsColorRGBA GetFontColor( void ) const { return fFontColor; } bool GetFontBlockRGB( void ) const { return fFontBlockRGB; } @@ -225,9 +224,9 @@ class plDynamicTextMap : public plMipmap bool fHasAlpha, fShadowed; Justify fJustify; - char *fFontFace; - uint16_t fFontSize; - uint8_t fFontFlags; + plString fFontFace; + uint16_t fFontSize; + uint8_t fFontFlags; bool fFontAntiAliasRGB; hsColorRGBA fFontColor; bool fFontBlockRGB; diff --git a/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp b/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp index 0491dacb..219a7da1 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp @@ -117,7 +117,7 @@ void plFont::IClear( bool onConstruct ) if( !onConstruct ) delete [] fBMapData; - memset( fFace, 0, sizeof( fFace ) ); + fFace = plString::Null; fSize = 0; fFlags = 0; @@ -141,16 +141,6 @@ void plFont::IClear( bool onConstruct ) fRenderInfo.fLineSpacing = 0; } -void plFont::SetFace( const char *face ) -{ - strncpy( fFace, face, sizeof( fFace ) ); -} - -void plFont::SetSize( uint8_t size ) -{ - fSize = size; -} - void plFont::Read( hsStream *s, hsResMgr *mgr ) { hsKeyedObject::Read( s, mgr ); @@ -232,12 +222,10 @@ static inline bool IIsDrawableWordBreak( const char c ) // The base render function. Additional options are specified externally, // so that their effects can be cached for optimization -void plFont::RenderString( plMipmap *mip, uint16_t x, uint16_t y, const char *string, uint16_t *lastX, uint16_t *lastY ) +void plFont::RenderString( plMipmap *mip, uint16_t x, uint16_t y, const plString &string, uint16_t *lastX, uint16_t *lastY ) { - // convert the char string to a wchar_t string - wchar_t *wideString = hsStringToWString(string); - RenderString(mip,x,y,wideString,lastX,lastY); - delete [] wideString; + // TEMP + RenderString(mip, x, y, string.ToWchar().GetData(), lastX, lastY); } @@ -990,7 +978,7 @@ void plFont::IRenderCharNull( const plCharacter &c ) //// CalcString Variations //////////////////////////////////////////////////// -uint16_t plFont::CalcStringWidth( const char *string ) +uint16_t plFont::CalcStringWidth( const plString &string ) { uint16_t w, h, a, lX, lY; uint32_t s; @@ -1006,12 +994,10 @@ uint16_t plFont::CalcStringWidth( const wchar_t *string ) return w; } -void plFont::CalcStringExtents( const char *string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY ) +void plFont::CalcStringExtents( const plString &string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY ) { // convert the char string to a wchar_t string - wchar_t *wideString = hsStringToWString(string); - CalcStringExtents(wideString,width,height,ascent,firstClippedChar,lastX,lastY); - delete [] wideString; + CalcStringExtents(string.ToWchar().GetData(), width, height, ascent, firstClippedChar, lastX, lastY); } void plFont::CalcStringExtents( const wchar_t *string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY ) @@ -1197,7 +1183,7 @@ bool plFont::LoadFromFNTStream( hsStream *stream ) charEntries[ i ].offset = stream->ReadLE32(); } - char faceName[ 256 ], deviceName[ 256 ]; + char faceName[ 257 ], deviceName[ 256 ]; if( fntInfo.face != 0 ) { stream->SetPosition( fntInfo.face ); @@ -1207,7 +1193,8 @@ bool plFont::LoadFromFNTStream( hsStream *stream ) if( faceName[ i ] == 0 ) break; } - strncpy( fFace, faceName, sizeof( fFace ) ); + faceName[256] = 0; + fFace = faceName; } if( fntInfo.device != 0 ) { @@ -1926,7 +1913,11 @@ bool plFont::LoadFromBDF( const char *path, plBDFConvertCallback *callback ) bool plFont::ReadRaw( hsStream *s ) { - s->Read( sizeof( fFace ), fFace ); + char face_buf[257]; + s->Read(256, face_buf); + face_buf[256] = 0; + fFace = face_buf; + fSize = s->ReadByte(); s->ReadLE( &fFlags ); @@ -1959,7 +1950,10 @@ bool plFont::ReadRaw( hsStream *s ) bool plFont::WriteRaw( hsStream *s ) { - s->Write( sizeof( fFace ), fFace ); + char face_buf[256] = { 0 }; + memcpy(face_buf, fFace.c_str(), fFace.GetSize() * sizeof(char)); + s->Write(sizeof(face_buf), face_buf); + s->WriteByte( fSize ); s->WriteLE( fFlags ); diff --git a/Sources/Plasma/PubUtilLib/plGImage/plFont.h b/Sources/Plasma/PubUtilLib/plGImage/plFont.h index 9a121ef1..7c971325 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plFont.h +++ b/Sources/Plasma/PubUtilLib/plGImage/plFont.h @@ -131,7 +131,7 @@ class plFont : public hsKeyedObject friend class plBDFCharsParser; // Font face and size. This is just used for IDing purposes, not for rendering - char fFace[ 256 ]; + plString fFace; uint8_t fSize; uint32_t fFlags; @@ -244,20 +244,20 @@ class plFont : public hsKeyedObject virtual void Read( hsStream *s, hsResMgr *mgr ); virtual void Write( hsStream *s, hsResMgr *mgr ); - const char *GetFace( void ) const { return fFace; } - uint8_t GetSize( void ) const { return fSize; } - uint16_t GetFirstChar( void ) const { return fFirstChar; } - uint16_t GetNumChars( void ) const { return fCharacters.GetCount(); } - uint32_t GetFlags( void ) const { return fFlags; } - float GetDescent( void ) const { return (float)fFontDescent; } - float GetAscent( void ) const { return (float)fFontAscent; } + plString GetFace( void ) const { return fFace; } + uint8_t GetSize( void ) const { return fSize; } + uint16_t GetFirstChar( void ) const { return fFirstChar; } + uint16_t GetNumChars( void ) const { return fCharacters.GetCount(); } + uint32_t GetFlags( void ) const { return fFlags; } + float GetDescent( void ) const { return (float)fFontDescent; } + float GetAscent( void ) const { return (float)fFontAscent; } uint32_t GetBitmapWidth( void ) const { return fWidth; } uint32_t GetBitmapHeight( void ) const { return fHeight; } uint8_t GetBitmapBPP( void ) const { return fBPP; } - void SetFace( const char *face ); - void SetSize( uint8_t size ); + void SetFace( const plString &face ) { fFace = face; } + void SetSize( uint8_t size ) { fSize = size; } void SetFlags( uint32_t flags ) { fFlags = flags; } void SetFlag( uint32_t flag, bool on ) { if( on ) fFlags |= flag; else fFlags &= ~flag; } bool IsFlagSet( uint32_t flag ) { if( fFlags & flag ) return true; return false; } @@ -275,12 +275,12 @@ class plFont : public hsKeyedObject void SetRenderClipping( int16_t x, int16_t y, int16_t width, int16_t height ); void SetRenderWrapping( int16_t x, int16_t y, int16_t width, int16_t height ); - void RenderString( plMipmap *mip, uint16_t x, uint16_t y, const char *string, uint16_t *lastX = nil, uint16_t *lastY = nil ); + void RenderString( plMipmap *mip, uint16_t x, uint16_t y, const plString &string, uint16_t *lastX = nil, uint16_t *lastY = nil ); void RenderString( plMipmap *mip, uint16_t x, uint16_t y, const wchar_t *string, uint16_t *lastX = nil, uint16_t *lastY = nil ); - uint16_t CalcStringWidth( const char *string ); + uint16_t CalcStringWidth( const plString &string ); uint16_t CalcStringWidth( const wchar_t *string ); - void CalcStringExtents( const char *string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY ); + void CalcStringExtents( const plString &string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY ); void CalcStringExtents( const wchar_t *string, uint16_t &width, uint16_t &height, uint16_t &ascent, uint32_t &firstClippedChar, uint16_t &lastX, uint16_t &lastY ); bool LoadFromFNT( const char *path ); diff --git a/Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp b/Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp index dcaa3801..124fc406 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plFontCache.cpp @@ -89,23 +89,16 @@ void plFontCache::Clear( void ) { } -plFont *plFontCache::GetFont( const char *face, uint8_t size, uint32_t fontFlags ) +plFont *plFontCache::GetFont( const plString &face, uint8_t size, uint32_t fontFlags ) { uint32_t i, currIdx = (uint32_t)-1; int currDeltaSize = 100000; - char toFind[ 256 ]; - strcpy( toFind, face ); - strlwr( toFind ); for( i = 0; i < fCache.GetCount(); i++ ) { - char thisOne[ 256 ]; - strcpy( thisOne, fCache[ i ]->GetFace() ); - strlwr( thisOne ); - - if( strncmp( thisOne, toFind, strlen( toFind ) ) == 0 && - ( fCache[ i ]->GetFlags() == fontFlags ) ) + if (fCache[i]->GetFace().CompareNI(face, face.GetSize()) == 0 && + (fCache[i]->GetFlags() == fontFlags)) { int delta = fCache[ i ]->GetSize() - size; if( delta < 0 ) @@ -125,18 +118,17 @@ plFont *plFontCache::GetFont( const char *face, uint8_t size, uint32_t fontFlag return fCache[ currIdx ]; } - // If we failed, it's possible we have a face saved as "Times", for example, and someone's - // asking for "Times New Roman", so strip all but the first uint16_t from our font and try the search again - char *c = strchr( toFind, ' ' ); - if( c != nil ) + // If we failed, it's possible we have a face saved as "Times", for example, and someone's + // asking for "Times New Roman", so strip all but the first word from our font and try the search again + ssize_t sp = face.Find(' '); + if (sp >= 0) { - *c = 0; - return GetFont( toFind, size, fontFlags ); + return GetFont(face.Left(sp), size, fontFlags); } else if( fontFlags != 0 ) { // Hmm, well ok, just to be nice, try without our flags - plFont *f = GetFont( toFind, size, 0 ); + plFont *f = GetFont( face, size, 0 ); if( f != nil ) { //plStatusLog::AddLineS( "pipeline.log", "Warning: plFontCache is substituting %s %d regular (flags 0x%x could not be matched)", f->GetFace(), f->GetSize(), fontFlags ); @@ -171,7 +163,7 @@ void plFontCache::ILoadCustomFonts( void ) plString keyName; if (font->GetKey() == nil) { - keyName = plString::Format( "%s-%d", font->GetFace(), font->GetSize() ); + keyName = plString::Format( "%s-%d", font->GetFace().c_str(), font->GetSize() ); hsgResMgr::ResMgr()->NewKey( keyName, font, plLocation::kGlobalFixedLoc ); } diff --git a/Sources/Plasma/PubUtilLib/plGImage/plFontCache.h b/Sources/Plasma/PubUtilLib/plGImage/plFontCache.h index 528e4c8c..17b2ae40 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plFontCache.h +++ b/Sources/Plasma/PubUtilLib/plGImage/plFontCache.h @@ -91,7 +91,7 @@ class plFontCache : public hsKeyedObject static plFontCache &GetInstance( void ); - plFont *GetFont( const char *face, uint8_t size, uint32_t fontFlags ); + plFont *GetFont( const plString &face, uint8_t size, uint32_t fontFlags ); // HFONT GetMeAFont( const char *face, int height, int weight, bool italic, uint32_t quality ); // void FreeFont( HFONT font ); diff --git a/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp b/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp index c4a57b15..421121f3 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.cpp @@ -92,7 +92,7 @@ plWinFontCache &plWinFontCache::GetInstance( void ) return cache; } -HFONT plWinFontCache::IFindFont( const char *face, int height, int weight, bool italic, uint32_t quality ) +HFONT plWinFontCache::IFindFont( const plString &face, int height, int weight, bool italic, uint32_t quality ) { int i; @@ -105,7 +105,7 @@ HFONT plWinFontCache::IFindFont( const char *face, int height, int weight, boo fFontCache[ i ].fItalic == italic && fFontCache[ i ].fQuality == quality ) { - if( strcmp( fFontCache[ i ].fFace, face ) == 0 ) + if (fFontCache[i].fFace == face) return fFontCache[ i ].fFont; } } @@ -113,7 +113,7 @@ HFONT plWinFontCache::IFindFont( const char *face, int height, int weight, boo return nil; } -HFONT plWinFontCache::IMakeFont( const char *face, int height, int weight, bool italic, uint32_t quality ) +HFONT plWinFontCache::IMakeFont( const plString &face, int height, int weight, bool italic, uint32_t quality ) { plFontRecord myRec; int i; @@ -122,12 +122,12 @@ HFONT plWinFontCache::IMakeFont( const char *face, int height, int weight, boo // Find a cached name for us for( i = 0; i < fFontNameCache.GetCount(); i++ ) { - if( strcmp( face, fFontNameCache[ i ] ) == 0 ) + if (face == fFontNameCache[i]) break; } if( i == fFontNameCache.GetCount() ) - fFontNameCache.Append( hsStrcpy( face ) ); + fFontNameCache.Append(face); myRec.fFace = fFontNameCache[ i ]; myRec.fHeight = height; @@ -135,8 +135,8 @@ HFONT plWinFontCache::IMakeFont( const char *face, int height, int weight, boo myRec.fItalic = italic; myRec.fQuality = quality; - myRec.fFont = CreateFont( height, 0, 0, 0, weight, italic ? TRUE : FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, face ); + myRec.fFont = CreateFontW( height, 0, 0, 0, weight, italic ? TRUE : FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, face.ToWchar().GetData() ); if( myRec.fFont != nil ) { @@ -156,7 +156,7 @@ HFONT plWinFontCache::IMakeFont( const char *face, int height, int weight, boo err = "Weight of created font does not match"; if( static_cast(fontInfo.lfItalic) != italic ) err = "Italic-ness of created font does not match"; - if( stricmp( fontInfo.lfFaceName, face ) != 0 ) + if( face.CompareI(fontInfo.lfFaceName) != 0 ) err = "Face of created font does not match"; if( err != nil ) @@ -199,13 +199,14 @@ HFONT plWinFontCache::IMakeFont( const char *face, int height, int weight, boo } else { - plStatusLog::AddLineS( "pipeline.log", "ERROR: CreateFont() call FAILED (face: %s, size: %d %s %s)", face, -height, weight == FW_BOLD ? "bold" : "", italic ? "italic" : "" ); + plStatusLog::AddLineS( "pipeline.log", "ERROR: CreateFont() call FAILED (face: %s, size: %d %s %s)", + face.c_str(), -height, weight == FW_BOLD ? "bold" : "", italic ? "italic" : "" ); } return myRec.fFont; } -HFONT plWinFontCache::GetMeAFont( const char *face, int height, int weight, bool italic, uint32_t quality ) +HFONT plWinFontCache::GetMeAFont( const plString &face, int height, int weight, bool italic, uint32_t quality ) { HFONT font = IFindFont( face, height, weight, italic, quality ); if( font == nil ) @@ -226,8 +227,6 @@ void plWinFontCache::Clear( void ) DeleteObject( fFontCache[ i ].fFont ); fFontCache.Reset(); - for( i = 0; i < fFontNameCache.GetCount(); i++ ) - delete [] fFontNameCache[ i ]; fFontNameCache.Reset(); for( i = 0; i < fCustFonts.GetCount(); i++ ) diff --git a/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.h b/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.h index 1ede70bb..b990e07a 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.h +++ b/Sources/Plasma/PubUtilLib/plGImage/plWinFontCache.h @@ -80,7 +80,7 @@ class plWinFontCache public: HFONT fFont; - char *fFace; // Pointer is owned by fFontNameCache + plString fFace; int fHeight; int fWeight; bool fItalic; @@ -98,15 +98,15 @@ class plWinFontCache bool fInShutdown; hsTArray fFontCache; - hsTArray fFontNameCache; + hsTArray fFontNameCache; char *fCustFontDir; hsTArray fCustFonts; plWinFontCache(); - HFONT IFindFont( const char *face, int height, int weight, bool italic, uint32_t quality ); - HFONT IMakeFont( const char *face, int height, int weight, bool italic, uint32_t quality ); + HFONT IFindFont( const plString &face, int height, int weight, bool italic, uint32_t quality ); + HFONT IMakeFont( const plString &face, int height, int weight, bool italic, uint32_t quality ); void ILoadCustomFonts( void ); @@ -115,7 +115,7 @@ class plWinFontCache virtual ~plWinFontCache(); static plWinFontCache &GetInstance( void ); - HFONT GetMeAFont( const char *face, int height, int weight, bool italic, uint32_t quality ); + HFONT GetMeAFont( const plString &face, int height, int weight, bool italic, uint32_t quality ); void FreeFont( HFONT font ); void Clear( void ); diff --git a/Sources/Tools/plFontConverter/plFontConverterProc.cpp b/Sources/Tools/plFontConverter/plFontConverterProc.cpp index 5fb5a6ca..ed58b2ff 100644 --- a/Sources/Tools/plFontConverter/plFontConverterProc.cpp +++ b/Sources/Tools/plFontConverter/plFontConverterProc.cpp @@ -135,7 +135,7 @@ void IUpdateInfo( HWND hDlg ) return; } - SetDlgItemText( hDlg, IDC_FACE, gFont->GetFace() ); + SetDlgItemText( hDlg, IDC_FACE, gFont->GetFace().c_str() ); SetDlgItemInt( hDlg, IDC_FSIZE, gFont->GetSize(), false ); SetDlgItemInt( hDlg, IDC_STARTG, gFont->GetFirstChar(), false ); SetDlgItemInt( hDlg, IDC_GCOUNT, gFont->GetNumChars(), false ); @@ -598,7 +598,7 @@ void IBatchFreeType( HWND hWnd, const char *path ) gFont->SetFace(sFontName); char fileName[ MAX_PATH ]; - sprintf( fileName, "%s\\%s-%d.p2f", destPath, gFont->GetFace(), gFont->GetSize() ); + sprintf( fileName, "%s\\%s-%d.p2f", destPath, gFont->GetFace().c_str(), gFont->GetSize() ); hsUNIXStream stream; if( !stream.Open( fileName, "wb" ) ) MessageBox( hWnd, "Can't open file for writing", "Error", MB_OK | MB_ICONEXCLAMATION ); @@ -688,7 +688,7 @@ BOOL CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) gFont->SetFlag( plFont::kFlagItalic, IsDlgButtonChecked( hWnd, IDC_ITALIC ) == BST_CHECKED ); // Write out - sprintf( fileName, "%s-%d.p2f", gFont->GetFace(), gFont->GetSize() ); + sprintf( fileName, "%s-%d.p2f", gFont->GetFace().c_str(), gFont->GetSize() ); if( PromptForFile( hWnd, "Specify a file to export to", "Plasma 2 font files\0*.p2f\0", fileName, sizeof( fileName ), true ) ) { hsUNIXStream stream; From 262cc65f574e44287d05c88bd5d52734cc7624dc Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sat, 11 Jan 2014 00:43:03 -0800 Subject: [PATCH 02/15] pfGUIControlMod's font face => plString --- .../pfGameGUIMgr/pfGUIControlMod.cpp | 20 ++++--------------- .../FeatureLib/pfGameGUIMgr/pfGUIControlMod.h | 17 ++++++++-------- .../pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp | 12 +++++------ .../pfGameGUIMgr/pfGUIMultiLineEditCtrl.h | 8 ++++---- 4 files changed, 22 insertions(+), 35 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp index eb7e6f71..ca6cb413 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp @@ -85,7 +85,7 @@ void pfGUIColorScheme::IReset( void ) fSelForeColor.Set( 1, 1, 1, 1 ); fSelBackColor.Set( 0, 0, 1, 1 ); fTransparent = false; - fFontFace = hsStrcpy( "Times New Roman" ); + fFontFace = "Times New Roman"; fFontSize = 10; fFontFlags = 0; } @@ -95,11 +95,6 @@ pfGUIColorScheme::pfGUIColorScheme() IReset(); } -pfGUIColorScheme::~pfGUIColorScheme() -{ - delete [] fFontFace; -} - pfGUIColorScheme::pfGUIColorScheme( hsColorRGBA &foreColor, hsColorRGBA &backColor ) { IReset(); @@ -107,20 +102,14 @@ pfGUIColorScheme::pfGUIColorScheme( hsColorRGBA &foreColor, hsColorRGBA &backCol fBackColor = backColor; } -pfGUIColorScheme::pfGUIColorScheme( const char *face, uint8_t size, uint8_t fontFlags ) +pfGUIColorScheme::pfGUIColorScheme( const plString &face, uint8_t size, uint8_t fontFlags ) { IReset(); - fFontFace = hsStrcpy( face ); + fFontFace = face; fFontSize = size; fFontFlags = fontFlags; } -void pfGUIColorScheme::SetFontFace( const char *face ) -{ - delete [] fFontFace; - fFontFace = hsStrcpy( face ); -} - void pfGUIColorScheme::Read( hsStream *s ) { fForeColor.Read( s ); @@ -129,8 +118,7 @@ void pfGUIColorScheme::Read( hsStream *s ) fSelBackColor.Read( s ); fTransparent = s->ReadBOOL(); - delete [] fFontFace; - fFontFace = s->ReadSafeString(); + fFontFace = s->ReadSafeString_TEMP(); s->ReadLE( &fFontSize ); s->ReadLE( &fFontFlags ); } diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h index 7cf70571..96f8de7c 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h @@ -74,9 +74,9 @@ class pfGUIColorScheme : public hsRefCnt hsColorRGBA fSelForeColor, fSelBackColor; bool fTransparent; - char *fFontFace; - uint8_t fFontSize; - uint8_t fFontFlags; + plString fFontFace; + uint8_t fFontSize; + uint8_t fFontFlags; enum FontFlags { @@ -86,18 +86,17 @@ class pfGUIColorScheme : public hsRefCnt }; pfGUIColorScheme(); - ~pfGUIColorScheme(); pfGUIColorScheme( hsColorRGBA &foreColor, hsColorRGBA &backColor ); - pfGUIColorScheme( const char *face, uint8_t size, uint8_t fontFlags ); + pfGUIColorScheme( const plString &face, uint8_t size, uint8_t fontFlags ); - void SetFontFace( const char *face ); + void SetFontFace(const plString &face) { fFontFace = face; } void Read( hsStream *s ); void Write( hsStream *s ); - bool IsBold( void ) { return ( fFontFlags & kFontBold ) ? true : false; } - bool IsItalic( void ) { return ( fFontFlags & kFontItalic ) ? true : false; } - bool IsShadowed( void ) { return ( fFontFlags & kFontShadowed ) ? true : false; } + bool IsBold() const { return ( fFontFlags & kFontBold ) ? true : false; } + bool IsItalic() const { return ( fFontFlags & kFontItalic ) ? true : false; } + bool IsShadowed() const { return ( fFontFlags & kFontShadowed ) ? true : false; } protected: diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp index 3acf1518..aa6b8c6b 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp @@ -349,7 +349,7 @@ void pfGUIMultiLineEditCtrl::IPostSetUpDynTextMap( void ) fFontFlagsSet |= kFontStyleSet; } - fDynTextMap->SetFont( fFontFace.c_str(), fFontSize, fFontStyle, + fDynTextMap->SetFont( fFontFace, fFontSize, fFontStyle, HasFlag( kXparentBgnd ) ? false : true ); // Calculate a height for each line @@ -572,7 +572,7 @@ uint32_t pfGUIMultiLineEditCtrl::IRenderLine( uint16_t x, uint16_t y, int32_t s IFindLastStyleCode( start, currStyle ); fDynTextMap->SetTextColor( currColor, HasFlag( kXparentBgnd ) ? true : false ); - fDynTextMap->SetFont( fFontFace.c_str(), fFontSize, GetColorScheme()->fFontFlags | currStyle, + fDynTextMap->SetFont( fFontFace, fFontSize, GetColorScheme()->fFontFlags | currStyle, HasFlag( kXparentBgnd ) ? false : true ); // Now, start from our start and go to the end and keep eating up as many chunks @@ -609,7 +609,7 @@ uint32_t pfGUIMultiLineEditCtrl::IRenderLine( uint16_t x, uint16_t y, int32_t s // Read style and switch to that one IReadStyleCode( pos, currStyle ); if( !dontRender ) - fDynTextMap->SetFont( fFontFace.c_str(), fFontSize , GetColorScheme()->fFontFlags | currStyle, + fDynTextMap->SetFont( fFontFace, fFontSize , GetColorScheme()->fFontFlags | currStyle, HasFlag( kXparentBgnd ) ? false : true ); } else if( buffer[ pos ] == L'\n' ) @@ -1836,11 +1836,11 @@ void pfGUIMultiLineEditCtrl::IHitBeginningOfControlList(int32_t cursorPos) } } -void pfGUIMultiLineEditCtrl::SetFontFace(std::string fontFace) +void pfGUIMultiLineEditCtrl::SetFontFace(const plString &fontFace) { fFontFace = fontFace; fFontFlagsSet |= kFontFaceSet; - fDynTextMap->SetFont( fFontFace.c_str(), fFontSize, fFontStyle, + fDynTextMap->SetFont( fFontFace, fFontSize, fFontStyle, HasFlag( kXparentBgnd ) ? false : true ); fDynTextMap->CalcStringWidth( "The quick brown fox jumped over the lazy dog.", &fLineHeight ); } @@ -1850,7 +1850,7 @@ void pfGUIMultiLineEditCtrl::SetFontSize(uint8_t fontSize) fFontSize = fontSize; fFontFlagsSet |= kFontSizeSet; fCalcedFontSize = fontSize; - fDynTextMap->SetFont( fFontFace.c_str(), fFontSize, fFontStyle, + fDynTextMap->SetFont( fFontFace, fFontSize, fFontStyle, HasFlag( kXparentBgnd ) ? false : true ); fDynTextMap->CalcStringWidth( "The quick brown fox jumped over the lazy dog.", &fLineHeight ); } diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h index fab1bbe0..e9de267b 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h @@ -129,10 +129,10 @@ class pfGUIMultiLineEditCtrl : public pfGUIControlMod pfGUIMultiLineEditProc *fEventProc; // where we send events to - std::string fFontFace; + plString fFontFace; hsColorRGBA fFontColor; - uint8_t fFontSize; - uint8_t fFontStyle; + uint8_t fFontSize; + uint8_t fFontStyle; enum flagsSet { kFontFaceSet = 1, @@ -271,7 +271,7 @@ class pfGUIMultiLineEditCtrl : public pfGUIControlMod uint8_t GetFontSize() {return fFontSize;} // because we're too cool to use the color scheme crap - void SetFontFace(std::string fontFace); + void SetFontFace(const plString &fontFace); void SetFontColor(hsColorRGBA fontColor) {fFontColor = fontColor; fFontFlagsSet |= kFontColorSet;} void SetFontSize(uint8_t fontSize); void SetFontStyle(uint8_t fontStyle) {fFontStyle = fontStyle; fFontFlagsSet |= kFontStyleSet;} From f370c65ad30000b8541b62d0d471282ef8712bd4 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sat, 11 Jan 2014 01:06:59 -0800 Subject: [PATCH 03/15] GUI List Box items => plString --- .../pfGameGUIMgr/pfGUIListBoxMod.cpp | 15 +-- .../FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h | 6 +- .../pfGameGUIMgr/pfGUIListElement.cpp | 100 +++--------------- .../pfGameGUIMgr/pfGUIListElement.h | 26 ++--- .../pfPython/pyGUIControlListBox.cpp | 97 +++-------------- .../FeatureLib/pfPython/pyGUIControlListBox.h | 18 ++-- .../pfPython/pyGUIControlListBoxGlue.cpp | 13 ++- 7 files changed, 57 insertions(+), 218 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp index 515d4b47..b984ce80 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp @@ -1152,23 +1152,12 @@ void pfGUIListBoxMod::ClearAllElements( void ) HandleExtendedEvent( pfGUIListBoxMod::kListCleared ); } -uint16_t pfGUIListBoxMod::AddString( const char *string ) +uint16_t pfGUIListBoxMod::AddString( const plString &string ) { return AddElement( new pfGUIListText( string ) ); } -uint16_t pfGUIListBoxMod::AddString( const wchar_t *string ) -{ - return AddElement( new pfGUIListText( string ) ); -} - -int16_t pfGUIListBoxMod::FindString( const char *toCompareTo ) -{ - pfGUIListText text( toCompareTo ); - return FindElement( &text ); -} - -int16_t pfGUIListBoxMod::FindString( const wchar_t *toCompareTo ) +int16_t pfGUIListBoxMod::FindString( const plString &toCompareTo ) { pfGUIListText text( toCompareTo ); return FindElement( &text ); diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h index d87c1354..4189d866 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h @@ -186,10 +186,8 @@ class pfGUIListBoxMod : public pfGUIControlMod uint16_t GetNumElements( void ); pfGUIListElement *GetElement( uint16_t idx ); - uint16_t AddString( const char *string ); - uint16_t AddString( const wchar_t *string ); - int16_t FindString( const char *toCompareTo ); - int16_t FindString( const wchar_t *toCompareTo ); + uint16_t AddString( const plString &string ); + int16_t FindString( const plString &toCompareTo ); // Export only void SetScrollCtrl( pfGUIValueCtrl *ctrl ) { fScrollControl = ctrl; } diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.cpp index 534d7822..669ff146 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.cpp @@ -77,28 +77,14 @@ void pfGUIListElement::Write( hsStream *s, hsResMgr *mgr ) //// Constructor/Destructor ////////////////////////////////////////////////// -pfGUIListText::pfGUIListText() : pfGUIListElement( kText ) +pfGUIListText::pfGUIListText() + : pfGUIListElement(kText), fJustify(kLeftJustify) { - fText = nil; - fJustify = kLeftJustify; } -pfGUIListText::pfGUIListText( const char *text ) : pfGUIListElement( kText ) +pfGUIListText::pfGUIListText( const plString &text ) + : pfGUIListElement(kText), fText(text), fJustify(kLeftJustify) { - fText = hsStringToWString(text); - fJustify = kLeftJustify; -} - -pfGUIListText::pfGUIListText( const wchar_t *text ) : pfGUIListElement( kText ) -{ - fText = new wchar_t[ wcslen( text ) + 1 ]; - wcscpy( fText, text ); - fJustify = kLeftJustify; -} - -pfGUIListText::~pfGUIListText() -{ - delete [] fText; } //// Virtuals //////////////////////////////////////////////////////////////// @@ -107,18 +93,14 @@ void pfGUIListText::Read( hsStream *s, hsResMgr *mgr ) { pfGUIListElement::Read( s, mgr ); - char *text = s->ReadSafeString(); - fText = hsStringToWString(text); - delete [] text; + fText = s->ReadSafeString_TEMP(); } void pfGUIListText::Write( hsStream *s, hsResMgr *mgr ) { pfGUIListElement::Write( s, mgr ); - char *text = hsWStringToString(fText); - s->WriteSafeString(text); - delete [] text; + s->WriteSafeString(fText); } bool pfGUIListText::Draw( plDynamicTextMap *textGen, uint16_t x, uint16_t y, uint16_t maxWidth, uint16_t maxHeight ) @@ -158,26 +140,7 @@ int pfGUIListText::CompareTo( pfGUIListElement *rightSide ) if( text->fType != kText ) return -2; - return wcscmp( GetText(), text->GetText() ); -} - -void pfGUIListText::SetText( const char *text ) -{ - wchar_t *wText = hsStringToWString(text); - SetText(wText); - delete [] wText; -} - -void pfGUIListText::SetText( const wchar_t *text ) -{ - delete [] fText; - if( text != nil ) - { - fText = new wchar_t[ wcslen( text ) + 1 ]; - wcscpy( fText, text ); - } - else - fText = nil; + return GetText().Compare(text->GetText()); } void pfGUIListText::SetJustify( JustifyTypes justify ) @@ -295,26 +258,14 @@ int pfGUIListPicture::CompareTo( pfGUIListElement *rightSide ) //// Constructor/Destructor ////////////////////////////////////////////////// -pfGUIListTreeRoot::pfGUIListTreeRoot() : pfGUIListElement( kTreeRoot ) +pfGUIListTreeRoot::pfGUIListTreeRoot() + : pfGUIListElement(kTreeRoot), fShowChildren(true) { - fText = nil; - fShowChildren = true; } -pfGUIListTreeRoot::pfGUIListTreeRoot( const char *text ) : pfGUIListElement( kTreeRoot ) +pfGUIListTreeRoot::pfGUIListTreeRoot( const plString &text ) + : pfGUIListElement(kTreeRoot), fText(text) { - fText = hsStringToWString(text); -} - -pfGUIListTreeRoot::pfGUIListTreeRoot( const wchar_t *text ) : pfGUIListElement( kTreeRoot ) -{ - fText = new wchar_t[ wcslen( text ) + 1 ]; - wcscpy( fText, text ); -} - -pfGUIListTreeRoot::~pfGUIListTreeRoot() -{ - delete [] fText; } //// Virtuals //////////////////////////////////////////////////////////////// @@ -323,18 +274,14 @@ void pfGUIListTreeRoot::Read( hsStream *s, hsResMgr *mgr ) { pfGUIListElement::Read( s, mgr ); - char *temp = s->ReadSafeString(); - fText = hsStringToWString(temp); - delete [] temp; + fText = s->ReadSafeString_TEMP(); } void pfGUIListTreeRoot::Write( hsStream *s, hsResMgr *mgr ) { pfGUIListElement::Write( s, mgr ); - char *temp = hsWStringToString(fText); - s->WriteSafeString( temp ); - delete [] temp; + s->WriteSafeString(fText); } bool pfGUIListTreeRoot::Draw( plDynamicTextMap *textGen, uint16_t x, uint16_t y, uint16_t maxWidth, uint16_t maxHeight ) @@ -416,26 +363,7 @@ int pfGUIListTreeRoot::CompareTo( pfGUIListElement *rightSide ) if( text->fType != kTreeRoot ) return -2; - return wcscmp( GetTitle(), text->GetTitle() ); -} - -void pfGUIListTreeRoot::SetTitle( const char *text ) -{ - wchar_t *wText = hsStringToWString(text); - SetTitle(wText); - delete [] wText; -} - -void pfGUIListTreeRoot::SetTitle( const wchar_t *text ) -{ - delete [] fText; - if( text != nil ) - { - fText = new wchar_t[ wcslen( text ) + 1 ]; - wcscpy( fText, text ); - } - else - fText = nil; + return GetTitle().Compare(text->GetTitle()); } void pfGUIListTreeRoot::AddChild( pfGUIListElement *el ) diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.h b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.h index 60d7c104..50df5494 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.h +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.h @@ -118,15 +118,13 @@ class pfGUIListText : public pfGUIListElement protected: - wchar_t *fText; - uint8_t fJustify; // This is not our JustifyTypes, but from plDynamicTextMap + plString fText; + uint8_t fJustify; // This is not our JustifyTypes, but from plDynamicTextMap public: pfGUIListText(); - pfGUIListText( const char *text ); - pfGUIListText( const wchar_t *text ); - virtual ~pfGUIListText(); + pfGUIListText( const plString &text ); virtual void Read( hsStream *s, hsResMgr *mgr ); virtual void Write( hsStream *s, hsResMgr *mgr ); @@ -139,9 +137,8 @@ class pfGUIListText : public pfGUIListElement virtual void SetJustify( JustifyTypes justify ); // These two are virtual so we can derive and override them - virtual const wchar_t *GetText( void ) { return fText; } - virtual void SetText( const char *text ); - virtual void SetText( const wchar_t *text ); + virtual plString GetText() const { return fText; } + virtual void SetText(const plString &text) { fText = text; } }; class pfGUIListPicture : public pfGUIListElement @@ -176,7 +173,7 @@ class pfGUIListTreeRoot : public pfGUIListElement { protected: - wchar_t *fText; + plString fText; bool fShowChildren; hsTArray fChildren; @@ -184,9 +181,7 @@ class pfGUIListTreeRoot : public pfGUIListElement public: pfGUIListTreeRoot(); - pfGUIListTreeRoot( const char *text ); - pfGUIListTreeRoot( const wchar_t *text ); - virtual ~pfGUIListTreeRoot(); + pfGUIListTreeRoot( const plString &text ); virtual void Read( hsStream *s, hsResMgr *mgr ); virtual void Write( hsStream *s, hsResMgr *mgr ); @@ -197,11 +192,10 @@ class pfGUIListTreeRoot : public pfGUIListElement virtual bool MouseClicked( uint16_t localX, uint16_t localY ); - const wchar_t *GetTitle( void ) { return fText; } - void SetTitle( const char *text ); - void SetTitle( const wchar_t *text ); + const plString GetTitle() const { return fText; } + void SetTitle(const plString &text) { fText = text; } - uint32_t GetNumChildren( void ) const { return fChildren.GetCount(); } + uint32_t GetNumChildren() const { return fChildren.GetCount(); } pfGUIListElement *GetChild( uint32_t i ) const { return fChildren[ i ]; } void AddChild( pfGUIListElement *el ); diff --git a/Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBox.cpp b/Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBox.cpp index 80436e04..7f78c8f1 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBox.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBox.cpp @@ -81,12 +81,12 @@ class pfColorListElement : public pfGUIListText if ( string1 ) { fString1 = hsStringToWString(string1); - fText = nil; + fText = plString::Null; } else { fString1 = nil; - fText = L""; + fText = ""; } fTextColor1 = color1; if (string2) @@ -105,12 +105,12 @@ class pfColorListElement : public pfGUIListText { fString1 = new wchar_t[wcslen(string1)+1]; wcscpy(fString1,string1); - fText = nil; + fText = plString::Null; } else { fString1 = nil; - fText = L""; + fText = ""; } fTextColor1 = color1; if (string2) @@ -132,7 +132,7 @@ class pfColorListElement : public pfGUIListText { delete [] fString1; fString1 = nil; - fText = nil; + fText = plString::Null; } if ( fString2 ) delete [] fString2; @@ -287,14 +287,7 @@ class pfListTextInBox : public pfGUIListText uint32_t fMinHeight; public: - pfListTextInBox( const char *text, uint32_t min_width=0, uint32_t min_height=0 ) : pfGUIListText( text ) - { - fMinWidth = min_width; - fMinHeight = min_height; - fJustify = pfGUIListText::kCenter; - } - - pfListTextInBox( const wchar_t *text, uint32_t min_width=0, uint32_t min_height=0 ) : pfGUIListText( text ) + pfListTextInBox( const plString &text, uint32_t min_width=0, uint32_t min_height=0 ) : pfGUIListText( text ) { fMinWidth = min_width; fMinHeight = min_height; @@ -510,14 +503,7 @@ uint16_t pyGUIControlListBox::GetNumElements( void ) return 0; } -void pyGUIControlListBox::SetElement( uint16_t idx, const char* text ) -{ - wchar_t *wText = hsStringToWString(text); - SetElementW(idx,wText); - delete [] wText; -} - -void pyGUIControlListBox::SetElementW( uint16_t idx, std::wstring text ) +void pyGUIControlListBox::SetElement( uint16_t idx, const plString& text ) { if ( fGCkey ) { @@ -532,7 +518,7 @@ void pyGUIControlListBox::SetElementW( uint16_t idx, std::wstring text ) { // if its a text element type then it should be safe to cast it to a pfGUIListText pfGUIListText* letext = (pfGUIListText*)le; - letext->SetText(text.c_str()); + letext->SetText(text); } } } @@ -562,16 +548,7 @@ void pyGUIControlListBox::SetStringJustify( uint16_t idx, uint32_t justify) } -std::string pyGUIControlListBox::GetElement( uint16_t idx ) -{ - std::wstring wRetVal = GetElementW(idx); - char *temp = hsWStringToString(wRetVal.c_str()); - std::string retVal = temp; - delete [] temp; - return retVal; -} - -std::wstring pyGUIControlListBox::GetElementW( uint16_t idx ) +plString pyGUIControlListBox::GetElement( uint16_t idx ) { if ( fGCkey ) { @@ -596,18 +573,10 @@ std::wstring pyGUIControlListBox::GetElementW( uint16_t idx ) } } } - return L""; -} - -int16_t pyGUIControlListBox::AddString( const char *string ) -{ - wchar_t *wString = hsStringToWString(string); - int16_t retVal = AddStringW(wString); - delete [] wString; - return retVal; + return ""; } -int16_t pyGUIControlListBox::AddStringW( std::wstring string ) +int16_t pyGUIControlListBox::AddString( const plString &string ) { if ( fGCkey ) { @@ -615,7 +584,7 @@ int16_t pyGUIControlListBox::AddStringW( std::wstring string ) pfGUIListBoxMod* plbmod = pfGUIListBoxMod::ConvertNoRef(fGCkey->ObjectIsLoaded()); if ( plbmod ) { - pfGUIListText *element = new pfGUIListText( string.c_str() ); + pfGUIListText *element = new pfGUIListText(string); if( fBuildRoots.GetCount() > 0 ) fBuildRoots[ fBuildRoots.GetCount() - 1 ]->AddChild( element ); return plbmod->AddElement( element ); @@ -642,22 +611,14 @@ int16_t pyGUIControlListBox::AddImage( pyImage& image, bool respectAlpha ) } -int16_t pyGUIControlListBox::FindString( const char *toCompareTo ) -{ - wchar_t *wToCompareTo = hsStringToWString(toCompareTo); - int16_t retVal = FindStringW(wToCompareTo); - delete [] wToCompareTo; - return retVal; -} - -int16_t pyGUIControlListBox::FindStringW( std::wstring toCompareTo ) +int16_t pyGUIControlListBox::FindString( const plString &toCompareTo ) { if ( fGCkey ) { // get the pointer to the modifier pfGUIListBoxMod* plbmod = pfGUIListBoxMod::ConvertNoRef(fGCkey->ObjectIsLoaded()); if ( plbmod ) - return plbmod->FindString(toCompareTo.c_str()); + return plbmod->FindString(toCompareTo); } return -1; } @@ -737,7 +698,7 @@ void pyGUIControlListBox::Add2TextWColorW( std::wstring str1, pyColor& textcolor } } -int16_t pyGUIControlListBox::AddStringInBox( const char *string, uint32_t min_width, uint32_t min_height ) +int16_t pyGUIControlListBox::AddStringInBox( const plString &string, uint32_t min_width, uint32_t min_height ) { if ( fGCkey ) { @@ -754,23 +715,6 @@ int16_t pyGUIControlListBox::AddStringInBox( const char *string, uint32_t min_wi return -1; } -int16_t pyGUIControlListBox::AddStringInBoxW( std::wstring string, uint32_t min_width, uint32_t min_height ) -{ - if ( fGCkey ) - { - // get the pointer to the modifier - pfGUIListBoxMod* plbmod = pfGUIListBoxMod::ConvertNoRef(fGCkey->ObjectIsLoaded()); - if ( plbmod ) - { - pfListTextInBox *element = new pfListTextInBox( string.c_str(), min_width, min_height ); - if( fBuildRoots.GetCount() > 0 ) - fBuildRoots[ fBuildRoots.GetCount() - 1 ]->AddChild( element ); - return plbmod->AddElement( element ); - } - } - return -1; -} - int16_t pyGUIControlListBox::AddImageInBox( pyImage& image, uint32_t x, uint32_t y, uint32_t width, uint32_t height, bool respectAlpha ) { if ( fGCkey ) @@ -927,14 +871,7 @@ void pyGUIControlListBox::Unclickable( void ) } } -void pyGUIControlListBox::AddBranch( const char *name, bool initiallyOpen ) -{ - wchar_t *wName = hsStringToWString(name); - AddBranchW(wName,initiallyOpen); - delete [] wName; -} - -void pyGUIControlListBox::AddBranchW( std::wstring name, bool initiallyOpen ) +void pyGUIControlListBox::AddBranch( const plString &name, bool initiallyOpen ) { if ( fGCkey ) { @@ -942,7 +879,7 @@ void pyGUIControlListBox::AddBranchW( std::wstring name, bool initiallyOpen ) pfGUIListBoxMod* plbmod = pfGUIListBoxMod::ConvertNoRef(fGCkey->ObjectIsLoaded()); if ( plbmod ) { - pfGUIListTreeRoot *root = new pfGUIListTreeRoot( name.c_str() ); + pfGUIListTreeRoot *root = new pfGUIListTreeRoot(name); root->ShowChildren( initiallyOpen ); if( fBuildRoots.GetCount() > 0 ) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBox.h b/Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBox.h index 28964149..84016a04 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBox.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBox.h @@ -88,15 +88,12 @@ public: virtual int32_t GetSelection( void ); virtual void SetSelection( int32_t item ); virtual void Refresh( void ); - virtual void SetElement( uint16_t idx, const char* text ); - virtual void SetElementW( uint16_t idx, std::wstring text ); + virtual void SetElement( uint16_t idx, const plString& text ); virtual void RemoveElement( uint16_t index ); virtual void ClearAllElements( void ); virtual uint16_t GetNumElements( void ); - virtual std::string GetElement( uint16_t idx ); - virtual std::wstring GetElementW( uint16_t idx ); - virtual int16_t AddString( const char *string ); - virtual int16_t AddStringW( std::wstring string ); + virtual plString GetElement( uint16_t idx ); + virtual int16_t AddString( const plString &string ); virtual int16_t AddImage( pyImage& image, bool respectAlpha ); virtual int16_t AddImageInBox( pyImage& image, uint32_t x, uint32_t y, uint32_t width, uint32_t height, bool respectAlpha ); virtual int16_t AddImageAndSwatchesInBox( pyImage& image, uint32_t x, uint32_t y, uint32_t width, uint32_t height, bool respectAlpha, @@ -104,16 +101,14 @@ public: virtual void SetSwatchSize( uint32_t size ); virtual void SetSwatchEdgeOffset( uint32_t size ); virtual void SetStringJustify( uint16_t idx, uint32_t justify); - virtual int16_t FindString( const char *toCompareTo ); - virtual int16_t FindStringW( std::wstring toCompareTo ); + virtual int16_t FindString( const plString &toCompareTo ); virtual int16_t AddTextWColor( const char *str, pyColor& textcolor, uint32_t inheritalpha); virtual int16_t AddTextWColorW( std::wstring str, pyColor& textcolor, uint32_t inheritalpha); virtual int16_t AddTextWColorWSize( const char *str, pyColor& textcolor, uint32_t inheritalpha, int32_t fontsize); virtual int16_t AddTextWColorWSizeW( std::wstring str, pyColor& textcolor, uint32_t inheritalpha, int32_t fontsize); virtual void Add2TextWColor( const char *str1, pyColor& textcolor1,const char *str2, pyColor& textcolor2, uint32_t inheritalpha); virtual void Add2TextWColorW( std::wstring str1, pyColor& textcolor1, std::wstring str2, pyColor& textcolor2, uint32_t inheritalpha); - virtual int16_t AddStringInBox( const char *string, uint32_t min_width, uint32_t min_height ); - virtual int16_t AddStringInBoxW( std::wstring string, uint32_t min_width, uint32_t min_height ); + virtual int16_t AddStringInBox( const plString &string, uint32_t min_width, uint32_t min_height ); virtual void ScrollToBegin( void ); virtual void ScrollToEnd( void ); virtual void SetScrollPos( int32_t pos ); @@ -125,8 +120,7 @@ public: // To create tree branches, call AddBranch() with a name, then add elements as usual, including new sub-branches // via additional AddBranch() calls. Call CloseBranch() to stop writing elements to that branch. - void AddBranch( const char *name, bool initiallyOpen ); - void AddBranchW( std::wstring name, bool initiallyOpen ); + void AddBranch( const plString &name, bool initiallyOpen ); void CloseBranch( void ); void RemoveSelection( int32_t item ); diff --git a/Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBoxGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBoxGlue.cpp index ccaa7cdb..e61b8b6b 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBoxGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBoxGlue.cpp @@ -136,7 +136,7 @@ PYTHON_METHOD_DEFINITION(ptGUIControlListBox, setElementW, args) PyErr_SetString(PyExc_TypeError, "setElementW expects an unsigned short and a unicode string"); PYTHON_RETURN_ERROR; } - self->fThis->SetElementW(index, text); + self->fThis->SetElement(index, plString::FromWchar(text)); PYTHON_RETURN_NONE; } @@ -148,7 +148,7 @@ PYTHON_METHOD_DEFINITION(ptGUIControlListBox, getElement, args) PyErr_SetString(PyExc_TypeError, "getElement expects an unsigned short"); PYTHON_RETURN_ERROR; } - return PyString_FromString(self->fThis->GetElement(index).c_str()); + return PyString_FromPlString(self->fThis->GetElement(index)); } PYTHON_METHOD_DEFINITION(ptGUIControlListBox, getElementW, args) @@ -159,8 +159,7 @@ PYTHON_METHOD_DEFINITION(ptGUIControlListBox, getElementW, args) PyErr_SetString(PyExc_TypeError, "getElementW expects an unsigned short"); PYTHON_RETURN_ERROR; } - std::wstring retVal = self->fThis->GetElementW(index); - return PyUnicode_FromWideChar(retVal.c_str(), retVal.length()); + return PyUnicode_FromStringEx(self->fThis->GetElement(index)); } PYTHON_METHOD_DEFINITION(ptGUIControlListBox, setStringJustify, args) @@ -195,7 +194,7 @@ PYTHON_METHOD_DEFINITION(ptGUIControlListBox, addStringW, args) PyErr_SetString(PyExc_TypeError, "addStringW expects a unicode string"); PYTHON_RETURN_ERROR; } - return PyInt_FromLong(self->fThis->AddStringW(text)); + return PyInt_FromLong(self->fThis->AddString(plString::FromWchar(text))); } PYTHON_METHOD_DEFINITION(ptGUIControlListBox, findString, args) @@ -217,7 +216,7 @@ PYTHON_METHOD_DEFINITION(ptGUIControlListBox, findStringW, args) PyErr_SetString(PyExc_TypeError, "findStringW expects a unicode string"); PYTHON_RETURN_ERROR; } - return PyInt_FromLong(self->fThis->FindStringW(text)); + return PyInt_FromLong(self->fThis->FindString(plString::FromWchar(text))); } PYTHON_METHOD_DEFINITION(ptGUIControlListBox, addImage, args) @@ -387,7 +386,7 @@ PYTHON_METHOD_DEFINITION(ptGUIControlListBox, addBranchW, args) wchar_t* name = new wchar_t[strLen + 1]; PyUnicode_AsWideChar((PyUnicodeObject*)textObj, name, strLen); name[strLen] = L'\0'; - self->fThis->AddBranchW(name, initiallyOpen != 0); + self->fThis->AddBranch(plString::FromWchar(name), initiallyOpen != 0); delete [] name; PYTHON_RETURN_NONE; } From a783642515a74793122b8a9b5af7a0a82a2c2c42 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sat, 11 Jan 2014 11:33:45 -0800 Subject: [PATCH 04/15] Python file names and SynchedObj SDL state names => plString --- Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp | 4 +- Sources/Plasma/FeatureLib/pfPython/cyMisc.h | 4 +- .../FeatureLib/pfPython/plPythonFileMod.cpp | 36 ++++--------- .../FeatureLib/pfPython/plPythonFileMod.h | 4 +- .../FeatureLib/pfPython/plPythonPack.cpp | 26 ++++------ .../Plasma/FeatureLib/pfPython/plPythonPack.h | 5 +- .../pfPython/plPythonSDLModifier.cpp | 6 ++- .../FeatureLib/pfPython/plPythonSDLModifier.h | 2 +- Sources/Plasma/FeatureLib/pfPython/pyKey.cpp | 2 +- Sources/Plasma/FeatureLib/pfPython/pyKey.h | 2 +- .../pnNetCommon/plSynchedObject.cpp | 52 +++++++++---------- .../NucleusLib/pnNetCommon/plSynchedObject.h | 35 +++++++------ .../NucleusLib/pnNetCommon/plSynchedValue.h | 2 +- Sources/Plasma/PubUtilLib/plAudio/plSound.cpp | 2 +- Sources/Plasma/PubUtilLib/plAudio/plSound.h | 2 +- .../PubUtilLib/plAvatar/plAGMasterMod.cpp | 2 +- .../PubUtilLib/plAvatar/plAGMasterMod.h | 2 +- .../PubUtilLib/plAvatar/plArmatureMod.cpp | 4 +- .../PubUtilLib/plAvatar/plArmatureMod.h | 2 +- .../PubUtilLib/plAvatar/plAvatarClothing.cpp | 2 +- .../PubUtilLib/plAvatar/plAvatarClothing.h | 2 +- .../PubUtilLib/plPhysX/plPXPhysical.cpp | 2 +- .../Plasma/PubUtilLib/plPhysX/plPXPhysical.h | 2 +- .../PubUtilLib/plSurface/plLayerAnimation.h | 2 +- Sources/Tools/MaxMain/plMaxNode.cpp | 4 +- 25 files changed, 97 insertions(+), 111 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp index ef01a509..d3c06252 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp @@ -443,7 +443,7 @@ void cyMisc::DetachObjectSO(pySceneObject& cobj, pySceneObject& pobj, bool netFo // // PURPOSE : set the Python modifier to be dirty and asked to be saved out // -void cyMisc::SetDirtySyncState(pyKey &selfkey, const char* SDLStateName, uint32_t sendFlags) +void cyMisc::SetDirtySyncState(pyKey &selfkey, const plString& SDLStateName, uint32_t sendFlags) { selfkey.DirtySynchState(SDLStateName, sendFlags); } @@ -455,7 +455,7 @@ void cyMisc::SetDirtySyncState(pyKey &selfkey, const char* SDLStateName, uint32_ // // PURPOSE : set the Python modifier to be dirty and asked to be saved out // -void cyMisc::SetDirtySyncStateWithClients(pyKey &selfkey, const char* SDLStateName, uint32_t sendFlags) +void cyMisc::SetDirtySyncStateWithClients(pyKey &selfkey, const plString& SDLStateName, uint32_t sendFlags) { selfkey.DirtySynchState(SDLStateName, sendFlags|plSynchedObject::kBCastToClients); } diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h index a6befc1f..6dfa30ce 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h @@ -217,7 +217,7 @@ public: // // PURPOSE : set the Python modifier to be dirty and asked to be saved out // - static void SetDirtySyncState(pyKey &selfkey, const char* SDLStateName, uint32_t sendFlags); + static void SetDirtySyncState(pyKey &selfkey, const plString& SDLStateName, uint32_t sendFlags); ///////////////////////////////////////////////////////////////////////////// // @@ -227,7 +227,7 @@ public: // PURPOSE : set the Python modifier to be dirty and asked to be saved out // specifies that state should be sent to other clients as well as server // - static void SetDirtySyncStateWithClients(pyKey &selfkey, const char* SDLStateName, uint32_t sendFlags); + static void SetDirtySyncStateWithClients(pyKey &selfkey, const plString& SDLStateName, uint32_t sendFlags); ///////////////////////////////////////////////////////////////////////////// // diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp index defd5d5d..8d220a22 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp @@ -336,7 +336,6 @@ bool plPythonFileMod::fAtConvertTime = false; // plPythonFileMod::plPythonFileMod() { - fPythonFile = nil; fModule = nil; fLocalNotify= true; fIsFirstTimeEval = true; @@ -401,12 +400,6 @@ plPythonFileMod::~plPythonFileMod() fSelfKey = nil; } - // get rid of the python code - if ( fPythonFile ) - { - delete [] fPythonFile; - fPythonFile = nil; - } // then get rid of this module // NOTE: fModule shouldn't be made in the plugin, only at runtime if ( !fModuleName.IsNull() && fModule ) @@ -438,14 +431,14 @@ bool plPythonFileMod::ILoadPythonCode() #ifndef PLASMA_EXTERNAL_RELEASE // get code from file and execute in module // see if the file exists first before trying to import it - plFileName pyfile = plFileName::Join(".", "python", plString::Format("%s.py", fPythonFile)); + plFileName pyfile = plFileName::Join(".", "python", plString::Format("%s.py", fPythonFile.c_str())); if (plFileInfo(pyfile).Exists()) { char fromLoad[256]; - //sprintf(fromLoad,"from %s import *", fPythonFile); + //sprintf(fromLoad,"from %s import *", fPythonFile.c_str()); // ok... we can't really use import because Python remembers too much where global variables came from // ...and using execfile make it sure that globals are defined in this module and not in the imported module - sprintf(fromLoad,"execfile('.\\\\python\\\\%s.py')", fPythonFile); + sprintf(fromLoad,"execfile('.\\\\python\\\\%s.py')", fPythonFile.c_str()); if ( PythonInterface::RunString( fromLoad, fModule) ) { // we've loaded the code into our module @@ -461,7 +454,7 @@ bool plPythonFileMod::ILoadPythonCode() } DisplayPythonOutput(); char errMsg[256]; - sprintf(errMsg,"Python file %s.py had errors!!! Could not load.",fPythonFile); + snprintf(errMsg, arrsize(errMsg), "Python file %s.py had errors!!! Could not load.", fPythonFile.c_str()); PythonInterface::WriteToLog(errMsg); hsAssert(0,errMsg); return false; @@ -476,7 +469,7 @@ bool plPythonFileMod::ILoadPythonCode() DisplayPythonOutput(); char errMsg[256]; - sprintf(errMsg,"Python file %s.py was not found.",fPythonFile); + snprintf(errMsg, arrsize(errMsg), "Python file %s.py was not found.", fPythonFile.c_str()); PythonInterface::WriteToLog(errMsg); hsAssert(0,errMsg); return false; @@ -503,7 +496,7 @@ void plPythonFileMod::AddTarget(plSceneObject* sobj) if ( !fAtConvertTime ) // if this is just an Add that's during a convert, then don't do anymore { // was there a python file module with this? - if ( fPythonFile ) + if ( !fPythonFile.IsEmpty() ) { // has the module not been initialized yet if ( !fModule ) @@ -523,7 +516,7 @@ void plPythonFileMod::AddTarget(plSceneObject* sobj) // set the name of the file (in the global dictionary of the module) PyObject* dict = PyModule_GetDict(fModule); - PyObject* pfilename = PyString_FromString(fPythonFile); + PyObject* pfilename = PyString_FromPlString(fPythonFile); PyDict_SetItemString(dict, "glue_name", pfilename); // next we need to: // - create instance of class @@ -542,7 +535,7 @@ void plPythonFileMod::AddTarget(plSceneObject* sobj) { // display any output (NOTE: this would be disabled in production) char errMsg[256]; - sprintf(errMsg,"Python file %s.py, instance not found.",fPythonFile); + snprintf(errMsg, arrsize(errMsg), "Python file %s.py, instance not found.", fPythonFile.c_str()); PythonInterface::WriteToLog(errMsg); hsAssert(0, errMsg); return; // if we can't create the instance then there is nothing to do here @@ -2933,10 +2926,9 @@ void plPythonFileMod::DisplayPythonOutput() // : Compile it into a Python code object // : (This is usually called by the component) // -void plPythonFileMod::SetSourceFile(const char* filename) +void plPythonFileMod::SetSourceFile(const plString& filename) { - delete [] fPythonFile; - fPythonFile = hsStrcpy(filename); + fPythonFile = filename; } ///////////////////////////////////////////////////////////////////////////// @@ -2996,13 +2988,7 @@ void plPythonFileMod::Read(hsStream* stream, hsResMgr* mgr) plMultiModifier::Read(stream, mgr); // read in the compile python code (pyc) - if ( fPythonFile ) - { - // if we already have some code, get rid of it! - delete [] fPythonFile; - fPythonFile = nil; - } - fPythonFile = stream->ReadSafeString(); + fPythonFile = stream->ReadSafeString_TEMP(); // then read in the list of receivers that want to be notified int nRcvs = stream->ReadLE32(); diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.h b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.h index 57fed231..65208b48 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.h +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.h @@ -73,7 +73,7 @@ protected: plString IMakeModuleName(plSceneObject* sobj); - char* fPythonFile; + plString fPythonFile; plString fModuleName; // the list of receivers that want to be notified @@ -131,7 +131,7 @@ public: plPythonSDLModifier* GetSDLMod() { return fSDLMod; } bool WasLocalNotify() { return fLocalNotify; } plPipeline* GetPipeline() { return fPipe; } - virtual void SetSourceFile(const char* filename); + virtual void SetSourceFile(const plString& filename); virtual int getPythonOutput(std::string* line); virtual void ReportError(); virtual void DisplayPythonOutput(); diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp b/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp index ae697f0c..8242c75f 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp @@ -68,7 +68,7 @@ protected: std::vector fPackStreams; bool fPackNotFound; // No pack file, don't keep trying - typedef std::map FileOffset; + typedef std::map FileOffset; FileOffset fFileOffsets; plPythonPack(); @@ -81,16 +81,16 @@ public: bool Open(); void Close(); - PyObject* OpenPacked(const char *fileName); - bool IsPackedFile(const char* fileName); + PyObject* OpenPacked(const plString& sfileName); + bool IsPackedFile(const plString& fileName); }; -PyObject* PythonPack::OpenPythonPacked(const char* fileName) +PyObject* PythonPack::OpenPythonPacked(const plString& fileName) { return plPythonPack::Instance().OpenPacked(fileName); } -bool PythonPack::IsItPythonPacked(const char* fileName) +bool PythonPack::IsItPythonPacked(const plString& fileName) { return plPythonPack::Instance().IsPackedFile(fileName); } @@ -148,9 +148,7 @@ bool plPythonPack::Open() for (int i = 0; i < numFiles; i++) { // and pack the index into our own data structure - char* buf = fPackStream->ReadSafeString(); - std::string pythonName = buf; // reading a "string" from a hsStream directly into a stl string causes memory loss - delete [] buf; + plString pythonName = fPackStream->ReadSafeString_TEMP(); uint32_t offset = fPackStream->ReadLE32(); plPackOffsetInfo offsetInfo; @@ -191,13 +189,12 @@ void plPythonPack::Close() fFileOffsets.clear(); } -PyObject* plPythonPack::OpenPacked(const char* fileName) +PyObject* plPythonPack::OpenPacked(const plString& fileName) { if (!Open()) return nil; - std::string pythonName = fileName; - pythonName += ".py"; + plString pythonName = fileName + ".py"; FileOffset::iterator it = fFileOffsets.find(pythonName); if (it != fFileOffsets.end()) @@ -213,7 +210,7 @@ PyObject* plPythonPack::OpenPacked(const char* fileName) char *buf = new char[size]; uint32_t readSize = fPackStream->Read(size, buf); hsAssert(readSize <= size, plString::Format("Python PackFile %s: Incorrect amount of data, read %d instead of %d", - fileName, readSize, size).c_str()); + fileName.c_str(), readSize, size).c_str()); // let the python marshal make it back into a code object PyObject *pythonCode = PyMarshal_ReadObjectFromString(buf, size); @@ -227,13 +224,12 @@ PyObject* plPythonPack::OpenPacked(const char* fileName) return nil; } -bool plPythonPack::IsPackedFile(const char* fileName) +bool plPythonPack::IsPackedFile(const plString& fileName) { if (!Open()) return nil; - std::string pythonName = fileName; - pythonName += ".py"; + plString pythonName = fileName + ".py"; FileOffset:: iterator it = fFileOffsets.find(pythonName); if (it != fFileOffsets.end()) diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonPack.h b/Sources/Plasma/FeatureLib/pfPython/plPythonPack.h index d671f281..9114d362 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonPack.h +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonPack.h @@ -43,11 +43,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define plPythonPack_h_inc typedef struct _object PyObject; +class plString; namespace PythonPack { - PyObject* OpenPythonPacked(const char* fileName); - bool IsItPythonPacked(const char* fileName); + PyObject* OpenPythonPacked(const plString& fileName); + bool IsItPythonPacked(const plString& fileName); } #endif // plPythonPack_h_inc diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.cpp b/Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.cpp index 0b1bf3fe..17b8e002 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.cpp @@ -265,7 +265,9 @@ void plPythonSDLModifier::SetItemIdx(const plString& key, int idx, PyObject* val const char* plPythonSDLModifier::GetSDLName() const { - return fOwner->fPythonFile; + // NOTE: Not changing GetSDLName since most implementations of this + // virtual function just return a stored string literal. + return fOwner->fPythonFile.c_str(); } void plPythonSDLModifier::SetFlags(const plString& name, bool sendImmediate, bool skipOwnershipCheck) @@ -566,7 +568,7 @@ PyObject* plPythonSDLModifier::ISDLVarToPython(plSimpleStateVariable* var) return pyTuple; } -bool plPythonSDLModifier::HasSDL(const char* pythonFile) +bool plPythonSDLModifier::HasSDL(const plString& pythonFile) { return (plSDLMgr::GetInstance()->FindDescriptor(pythonFile, plSDL::kLatestVersion) != nil); } diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.h b/Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.h index 2632ae62..0031d28f 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.h +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.h @@ -101,7 +101,7 @@ public: virtual const char* GetSDLName() const; virtual void SetItemFromSDLVar(plSimpleStateVariable* var); - static bool HasSDL(const char* pythonFile); + static bool HasSDL(const plString& pythonFile); // find the Age global SDL guy... if there is one static const plPythonSDLModifier* FindAgeSDL(); static plKey FindAgeSDLTarget(); diff --git a/Sources/Plasma/FeatureLib/pfPython/pyKey.cpp b/Sources/Plasma/FeatureLib/pfPython/pyKey.cpp index 3779eaff..94db30b1 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyKey.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyKey.cpp @@ -206,7 +206,7 @@ plKey pyKey::GetNotifyListItem(int32_t i) // Set the dirty state on the PythonModifier -void pyKey::DirtySynchState(const char* SDLStateName, uint32_t sendFlags) +void pyKey::DirtySynchState(const plString& SDLStateName, uint32_t sendFlags) { // see if we have a PythonFileModifier pointer if ( fPyFileMod ) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyKey.h b/Sources/Plasma/FeatureLib/pfPython/pyKey.h index b0795382..c0f23525 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyKey.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyKey.h @@ -123,7 +123,7 @@ public: // get a notify list item virtual plKey GetNotifyListItem(int32_t i); // Set the dirty state on the PythonModifier - virtual void DirtySynchState(const char* SDLStateName, uint32_t sendFlags); + virtual void DirtySynchState(const plString& SDLStateName, uint32_t sendFlags); // register and unregister for control key envents virtual void EnableControlKeyEvents(); diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.cpp b/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.cpp index d677138b..e11123a5 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.cpp @@ -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::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::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;iCompareI(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; diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.h b/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.h index 0fa8995f..9e51458b 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.h +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.h @@ -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 SDLStateList; + typedef std::vector 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 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 diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedValue.h b/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedValue.h index e723c43e..079c5800 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedValue.h +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedValue.h @@ -144,7 +144,7 @@ public: { MakeDirty(); // dirty value if (GetSynchedObject()) - GetSynchedObject()->DirtySynchState(nil, 0); // dirty owner + GetSynchedObject()->DirtySynchState(plString::Null, 0); // dirty owner } } diff --git a/Sources/Plasma/PubUtilLib/plAudio/plSound.cpp b/Sources/Plasma/PubUtilLib/plAudio/plSound.cpp index 48dbc57a..018775d0 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plSound.cpp +++ b/Sources/Plasma/PubUtilLib/plAudio/plSound.cpp @@ -1480,7 +1480,7 @@ plDrawableSpans* plSound::CreateProxy(const hsMatrix44& l2w, hsGMaterial* mat, h // call when state has changed -bool plSound::DirtySynchState(const char* sdlName /* kSDLSound */, uint32_t sendFlags) +bool plSound::DirtySynchState(const plString& sdlName /* kSDLSound */, uint32_t sendFlags) { /* if( sdlName == nil ) diff --git a/Sources/Plasma/PubUtilLib/plAudio/plSound.h b/Sources/Plasma/PubUtilLib/plAudio/plSound.h index 55a4a57e..d5e241fc 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plSound.h +++ b/Sources/Plasma/PubUtilLib/plAudio/plSound.h @@ -239,7 +239,7 @@ public: virtual void UpdateSoftVolume( bool enable, bool firstTime = false ); virtual bool MsgReceive( plMessage* pMsg ); - virtual bool DirtySynchState( const char *sdlName = nil, uint32_t sendFlags = 0 ); // call when state has changed + virtual bool DirtySynchState( const plString &sdlName = "", uint32_t sendFlags = 0 ); // call when state has changed // Tests whether this sound is within range of the given position, not counting soft regions bool IsWithinRange( const hsPoint3 &listenerPos, float *distSquared ); diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAGMasterMod.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAGMasterMod.cpp index 7fb747d9..7c8159f5 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAGMasterMod.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAGMasterMod.cpp @@ -799,7 +799,7 @@ bool plAGMasterMod::HasRunningAnims() // // Send SDL sendState msg to object's plAGMasterSDLModifier // -bool plAGMasterMod::DirtySynchState(const char* SDLStateName, uint32_t synchFlags) +bool plAGMasterMod::DirtySynchState(const plString& SDLStateName, uint32_t synchFlags) { if(GetNumTargets() > 0 && (!fIsGrouped || fIsGroupMaster)) { diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAGMasterMod.h b/Sources/Plasma/PubUtilLib/plAvatar/plAGMasterMod.h index 815e72b7..d79fc294 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAGMasterMod.h +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAGMasterMod.h @@ -206,7 +206,7 @@ public: virtual void Read(hsStream * stream, hsResMgr *mgr); bool HasRunningAnims(); - bool DirtySynchState(const char* SDLStateName, uint32_t synchFlags); + bool DirtySynchState(const plString& SDLStateName, uint32_t synchFlags); CLASSNAME_REGISTER( plAGMasterMod ); GETINTERFACE_ANY( plAGMasterMod, plModifier ); diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp index 8a8e0353..607532d1 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp @@ -1836,10 +1836,10 @@ void plArmatureMod::Read(hsStream * stream, hsResMgr *mgr) plgDispatch::Dispatch()->RegisterForExactType(plAvatarStealthModeMsg::Index(), GetKey()); } -bool plArmatureMod::DirtySynchState(const char* SDLStateName, uint32_t synchFlags) +bool plArmatureMod::DirtySynchState(const plString& SDLStateName, uint32_t synchFlags) { // skip requests to synch non-avatar state - if (SDLStateName && stricmp(SDLStateName, kSDLAvatar)) + if (SDLStateName.CompareI(kSDLAvatar) != 0) { return false; } diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h index c5924ae3..c9ed070d 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h +++ b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h @@ -283,7 +283,7 @@ public: void SynchIfLocal(double timeNow, int force); // Just physical state void SynchInputState(uint32_t rcvID = kInvalidPlayerID); - bool DirtySynchState(const char* SDLStateName, uint32_t synchFlags ); + bool DirtySynchState(const plString& SDLStateName, uint32_t synchFlags ); bool DirtyPhysicalSynchState(uint32_t synchFlags); plClothingOutfit *GetClothingOutfit() const { return fClothingOutfit; } plClothingSDLModifier *GetClothingSDLMod() const { return fClothingSDLMod; } diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp index 033e8426..c962bdc2 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp @@ -1405,7 +1405,7 @@ bool plClothingOutfit::MsgReceive(plMessage* msg) // TESTING SDL // Send clothing sendState msg to object's plClothingSDLModifier // -bool plClothingOutfit::DirtySynchState(const char* SDLStateName, uint32_t synchFlags) +bool plClothingOutfit::DirtySynchState(const plString& SDLStateName, uint32_t synchFlags) { plSynchEnabler ps(true); // make sure synching is enabled, since this happens during load synchFlags |= plSynchedObject::kForceFullSend; // TEMP diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.h b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.h index 09e7f4b0..7278ac25 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.h +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.h @@ -195,7 +195,7 @@ public: virtual void Read(hsStream* s, hsResMgr* mgr); virtual void Write(hsStream* s, hsResMgr* mgr); - bool DirtySynchState(const char* SDLStateName, uint32_t synchFlags); + bool DirtySynchState(const plString& SDLStateName, uint32_t synchFlags); void StripAccessories(); void WearDefaultClothing(); diff --git a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp index 9acfab82..7576be53 100644 --- a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp +++ b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.cpp @@ -1010,7 +1010,7 @@ void plPXPhysical::Write(hsStream* stream, hsResMgr* mgr) // TESTING SDL // Send phys sendState msg to object's plPhysicalSDLModifier // -bool plPXPhysical::DirtySynchState(const char* SDLStateName, uint32_t synchFlags ) +bool plPXPhysical::DirtySynchState(const plString& SDLStateName, uint32_t synchFlags ) { if (GetObjectKey()) { diff --git a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.h b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.h index 61920b14..1ed1b077 100644 --- a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.h +++ b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.h @@ -210,7 +210,7 @@ protected: ///////////////////////////////////////////////////////////// /** Remember that we need to do a synch soon. */ - bool DirtySynchState(const char* SDLStateName, uint32_t synchFlags ); + bool DirtySynchState(const plString& SDLStateName, uint32_t synchFlags); double GetLastSyncTime() { return fLastSyncTime; } diff --git a/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.h b/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.h index 28040ba1..55172273 100644 --- a/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.h +++ b/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.h @@ -173,7 +173,7 @@ public: // NEVER! // If you think it should... talk to Bob. He will explain why it can't be, and beat you up. // If he can't remember, beat him up until he does (or ask Moose). - virtual bool DirtySynchState(const char* sdlName, uint32_t sendFlags) { return false; } // don't send link state + virtual bool DirtySynchState(const plString& sdlName, uint32_t sendFlags) { return false; } // don't send link state virtual void Read(hsStream* s, hsResMgr* mgr); virtual void Write(hsStream* s, hsResMgr* mgr); diff --git a/Sources/Tools/MaxMain/plMaxNode.cpp b/Sources/Tools/MaxMain/plMaxNode.cpp index ea88e983..e6983855 100644 --- a/Sources/Tools/MaxMain/plMaxNode.cpp +++ b/Sources/Tools/MaxMain/plMaxNode.cpp @@ -455,7 +455,7 @@ void plMaxNode::CheckSynchOptions(plSynchedObject* so) if (gUserPropMgr.GetUserPropStringList(this, "DontPersist", num, sdataList)) { for(i=0;iAddToSDLExcludeList(sdataList[i]); // disable a type of persistence + so->AddToSDLExcludeList((const char *)sdataList[i]); // disable a type of persistence } } @@ -469,7 +469,7 @@ void plMaxNode::CheckSynchOptions(plSynchedObject* so) if (gUserPropMgr.GetUserPropStringList(this, "Volatile", num, sdataList)) { for(i=0;iAddToSDLVolatileList(sdataList[i]); // make volatile a type of persistence + so->AddToSDLVolatileList((const char *)sdataList[i]); // make volatile a type of persistence } } From 0c1783b2f35d45f7fac2273137c678418216dbaf Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sat, 11 Jan 2014 12:10:07 -0800 Subject: [PATCH 05/15] plGenericVar => plString - Also fixes a bug in plGenericType::CopyFrom, where doubles would get only half copied (and therefore become corrupt) --- .../FeatureLib/pfPython/plPythonFileMod.cpp | 5 +- .../NucleusLib/pnNetCommon/plGenericVar.cpp | 118 +++--------------- .../NucleusLib/pnNetCommon/plGenericVar.h | 65 +++++----- .../plNetCommon/plNetCommonHelpers.cpp | 6 +- .../plNetCommon/plNetCommonHelpers.h | 2 +- 5 files changed, 54 insertions(+), 142 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp index 8d220a22..e3ebe2d6 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp @@ -2089,10 +2089,11 @@ bool plPythonFileMod::MsgReceive(plMessage* msg) case plVaultNotifyMsg::kPublicAgeCreated: case plVaultNotifyMsg::kPublicAgeRemoved: { - if (const char * ageName = vaultNotifyMsg->GetArgs()->GetString(plNetCommon::VaultTaskArgs::kAgeFilename)) { + plString ageName = vaultNotifyMsg->GetArgs()->GetString(plNetCommon::VaultTaskArgs::kAgeFilename); + if (!ageName.IsEmpty()) { Py_DECREF(ptuple); ptuple = PyTuple_New(1); - PyTuple_SetItem(ptuple, 0, PyString_FromString(ageName)); + PyTuple_SetItem(ptuple, 0, PyString_FromPlString(ageName)); } } break; diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.cpp b/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.cpp index 0d71e07c..08a79082 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.cpp @@ -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,14 +148,13 @@ const char & plGenericType::IToChar( void ) const void plGenericType::Read(hsStream* s) { - IDeallocString(); s->ReadLE(&fType); switch ( fType ) { case kString: case kAny: - fS=s->ReadSafeString(); + fS=s->ReadSafeString_TEMP(); break; case kBool: {int8_t b; @@ -244,8 +219,7 @@ void plGenericType::Write(hsStream* s) /////////////////////////////////////////////////// void plGenericVar::Read(hsStream* s) { - delete [] fName; - fName = s->ReadSafeString(); + fName = s->ReadSafeString_TEMP(); 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) diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.h b/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.h index b3ff533b..14723b89 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.h +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.h @@ -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; - - void IDeallocString() { if (fType==kString || fType==kAny) {delete [] fS; fS=nil;} } + 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; + 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; } }; diff --git a/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.cpp b/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.cpp index e59d2ccc..64f75e2c 100644 --- a/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.cpp +++ b/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.cpp @@ -198,11 +198,11 @@ void plCreatableListHelper::AddDouble( uint16_t id, double value ) AddItem( id, V, true ); } -const char * plCreatableListHelper::GetString( uint16_t id ) +plString plCreatableListHelper::GetString( uint16_t id ) { plCreatableGenericValue * V = plCreatableGenericValue::ConvertNoRef( GetItem( id ) ); - if ( !V ) return nil; - return (const char *)V->Value(); + if ( !V ) return plString::Null; + return (plString)V->Value(); } int32_t plCreatableListHelper::GetInt( uint16_t id ) diff --git a/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.h b/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.h index 47413798..99b25a42 100644 --- a/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.h +++ b/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.h @@ -125,7 +125,7 @@ public: // helpers for typed arguments void AddString( uint16_t id, const char * value ); void AddString( uint16_t id, std::string & value ); - const char * GetString( uint16_t id ); + plString GetString( uint16_t id ); void AddInt( uint16_t id, int32_t value ); int32_t GetInt( uint16_t id ); void AddDouble( uint16_t id, double value ); From ff30c77ddd45d4588f98309a719e394ab61ca190 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sun, 12 Jan 2014 13:22:42 -0800 Subject: [PATCH 06/15] plArmatureMod => plString --- Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp | 2 +- .../PubUtilLib/plAvatar/plArmatureMod.cpp | 22 ++++++------------- .../PubUtilLib/plAvatar/plArmatureMod.h | 14 ++++++------ .../Plasma/PubUtilLib/plMessage/plAIMsg.cpp | 7 ++---- Sources/Plasma/PubUtilLib/plMessage/plAIMsg.h | 6 ++--- 5 files changed, 20 insertions(+), 31 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp index d3c06252..72a674b0 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp @@ -2919,7 +2919,7 @@ PyObject* cyMisc::GetAIAvatarsByModelName(const char* name) { PyObject* tuple = PyTuple_New(2); PyTuple_SetItem(tuple, 0, pyCritterBrain::New(critterBrain)); - PyTuple_SetItem(tuple, 1, PyString_FromString(armMod->GetUserStr())); + PyTuple_SetItem(tuple, 1, PyString_FromPlString(armMod->GetUserStr())); PyList_Append(avList, tuple); Py_DECREF(tuple); diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp index 607532d1..3921d58f 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp @@ -1743,8 +1743,8 @@ void plArmatureMod::Write(hsStream *stream, hsResMgr *mgr) stream->WriteLEFloat(fPhysWidth); stream->WriteSafeString(fAnimationPrefix); - stream->WriteSafeString(fBodyAgeName.c_str()); - stream->WriteSafeString(fBodyFootstepSoundPage.c_str()); + stream->WriteSafeString(fBodyAgeName); + stream->WriteSafeString(fBodyFootstepSoundPage); } void plArmatureMod::Read(hsStream * stream, hsResMgr *mgr) @@ -1780,9 +1780,7 @@ void plArmatureMod::Read(hsStream * stream, hsResMgr *mgr) // Attach the Footstep emitter scene object hsResMgr *mgr = hsgResMgr::ResMgr(); - const char *age = fBodyAgeName.c_str(); - const char *page = fBodyFootstepSoundPage.c_str(); - const plLocation &gLoc = plKeyFinder::Instance().FindLocation(age, page); + const plLocation &gLoc = plKeyFinder::Instance().FindLocation(fBodyAgeName, fBodyFootstepSoundPage); if (gLoc.IsValid()) { @@ -1824,15 +1822,9 @@ void plArmatureMod::Read(hsStream * stream, hsResMgr *mgr) fPhysWidth = stream->ReadLEFloat(); fAnimationPrefix = stream->ReadSafeString_TEMP(); + fBodyAgeName = stream->ReadSafeString_TEMP(); + fBodyFootstepSoundPage = stream->ReadSafeString_TEMP(); - char *temp = stream->ReadSafeString(); - fBodyAgeName = temp; - delete [] temp; - - temp = stream->ReadSafeString(); - fBodyFootstepSoundPage = temp; - delete [] temp; - plgDispatch::Dispatch()->RegisterForExactType(plAvatarStealthModeMsg::Index(), GetKey()); } @@ -2561,9 +2553,9 @@ int plArmatureMod::GetKILevel() return VaultGetKILevel(); } -void plArmatureMod::SetLinkInAnim(const char *animName) +void plArmatureMod::SetLinkInAnim(const plString &animName) { - if (animName) + if (!animName.IsNull()) { plAGAnim *anim = FindCustomAnim(animName); fLinkInAnimKey = (anim ? anim->GetKey() : nil); diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h index c9ed070d..9b9e9bc0 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h +++ b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h @@ -340,7 +340,7 @@ public: bool IsKILowestLevel(); int GetKILevel(); - void SetLinkInAnim(const char *animName); + void SetLinkInAnim(const plString &animName); plKey GetLinkInAnimKey() const; enum @@ -369,11 +369,11 @@ public: void SetPhysicalDims(float height, float width) { fPhysHeight = height; fPhysWidth = width; } - void SetBodyAgeName(const char* ageName) {if (ageName) fBodyAgeName = ageName; else fBodyAgeName = "";} - void SetBodyFootstepSoundPage(const char* pageName) {if (pageName) fBodyFootstepSoundPage = pageName; else fBodyFootstepSoundPage = "";} + void SetBodyAgeName(const plString& ageName) { fBodyAgeName = ageName; } + void SetBodyFootstepSoundPage(const plString& pageName) { fBodyFootstepSoundPage = pageName; } void SetAnimationPrefix(const plString& prefix) { fAnimationPrefix = prefix; } - const char* GetUserStr() {return fUserStr.c_str();} + plString GetUserStr() const { return fUserStr; } protected: void IInitDefaults(); @@ -443,12 +443,12 @@ protected: bool fDontPanicLink; // strings for animations, age names, footstep sounds, etc - std::string fBodyAgeName; - std::string fBodyFootstepSoundPage; + plString fBodyAgeName; + plString fBodyFootstepSoundPage; plString fAnimationPrefix; // user-defined string assigned to this avatar - std::string fUserStr; + plString fUserStr; }; // PLARMATURELOD diff --git a/Sources/Plasma/PubUtilLib/plMessage/plAIMsg.cpp b/Sources/Plasma/PubUtilLib/plMessage/plAIMsg.cpp index e71be044..54caa80f 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plAIMsg.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plAIMsg.cpp @@ -68,17 +68,14 @@ void plAIMsg::Read(hsStream* stream, hsResMgr* mgr) { plMessage::IMsgRead(stream, mgr); - char* temp = stream->ReadSafeString(); - if (temp) - fBrainUserStr = temp; - delete [] temp; + fBrainUserStr = stream->ReadSafeString_TEMP(); } void plAIMsg::Write(hsStream* stream, hsResMgr* mgr) { plMessage::IMsgWrite(stream, mgr); - stream->WriteSafeString(fBrainUserStr.c_str()); + stream->WriteSafeString(fBrainUserStr); } /////////////////////////////////////////////////////////////////////////////// diff --git a/Sources/Plasma/PubUtilLib/plMessage/plAIMsg.h b/Sources/Plasma/PubUtilLib/plMessage/plAIMsg.h index 96af1fba..16689301 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plAIMsg.h +++ b/Sources/Plasma/PubUtilLib/plMessage/plAIMsg.h @@ -63,8 +63,8 @@ public: virtual void Read(hsStream* stream, hsResMgr* mgr); virtual void Write(hsStream* stream, hsResMgr* mgr); - void BrainUserString(const std::string& userStr) {fBrainUserStr = userStr;} - std::string BrainUserString() const {return fBrainUserStr;} + void BrainUserString(const plString& userStr) {fBrainUserStr = userStr;} + plString BrainUserString() const {return fBrainUserStr;} // enum for all messages to make things easier for people that use us enum @@ -75,7 +75,7 @@ public: }; private: - std::string fBrainUserStr; + plString fBrainUserStr; }; // message spammed to anyone listening so they can grab the brain's key and talk to it From ef04cfcf84a1a0a8bcc64ef8241830c14a5a0524 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sun, 12 Jan 2014 15:13:04 -0800 Subject: [PATCH 07/15] Age Link info names => plString --- .../pfConsole/pfConsoleCommandsNet.cpp | 26 ++++----- Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp | 4 +- Sources/Plasma/FeatureLib/pfPython/cyMisc.h | 2 +- .../Plasma/FeatureLib/pfPython/cyMiscGlue.cpp | 2 +- .../FeatureLib/pfPython/pyAgeInfoStruct.cpp | 54 ++++++++--------- .../FeatureLib/pfPython/pyAgeInfoStruct.h | 28 ++++----- .../pfPython/pyAgeInfoStructGlue.cpp | 14 ++--- .../pfPython/pyNetServerSessionInfo.h | 16 ++--- .../pfPython/pyNetServerSessionInfoGlue.cpp | 8 +-- .../Plasma/FeatureLib/pfPython/pyVault.cpp | 8 +-- Sources/Plasma/NucleusLib/pnUtils/pnUtStr.h | 6 ++ .../plInputCore/plSceneInputInterface.cpp | 11 ++-- .../plInputCore/plSceneInputInterface.h | 8 +-- .../PubUtilLib/plMessage/plInputIfaceMgrMsg.h | 40 ++++++------- .../plNetClient/plLinkEffectsMgr.cpp | 14 ++--- .../PubUtilLib/plNetClient/plNetClientMgr.cpp | 2 +- .../PubUtilLib/plNetClient/plNetClientMgr.h | 2 +- .../plNetClient/plNetClientMsgScreener.cpp | 2 +- .../plNetClient/plNetClientMsgScreener.h | 2 +- .../plNetClient/plNetLinkingMgr.cpp | 24 ++++---- .../plNetCommon/plNetMsgScreener.cpp | 4 +- .../PubUtilLib/plNetCommon/plNetMsgScreener.h | 2 +- .../plNetCommon/plNetServerSessionInfo.cpp | 58 +++++++++---------- .../plNetCommon/plNetServerSessionInfo.h | 49 ++++++++-------- .../PubUtilLib/plVault/plVaultClientApi.cpp | 3 +- 25 files changed, 195 insertions(+), 194 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp index 16d38969..99784a84 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp @@ -336,7 +336,7 @@ PF_CONSOLE_CMD( Net, // groupName "Link to an age." ) // helpString { plAgeLinkStruct link; - link.GetAgeInfo()->SetAgeFilename( params[0] ); + link.GetAgeInfo()->SetAgeFilename( (const char *)params[0] ); link.SetLinkingRules( plNetCommon::LinkingRules::kBasicLink ); plNetLinkingMgr::GetInstance()->LinkToAge( &link ); PrintString("Linking to age..."); @@ -350,7 +350,7 @@ PF_CONSOLE_CMD( Net, // groupName "Link to a specific age by guid." ) // helpString { plAgeLinkStruct link; - link.GetAgeInfo()->SetAgeFilename( params[0] ); + link.GetAgeInfo()->SetAgeFilename( (const char *)params[0] ); //link.GetAgeInfo()->SetAgeInstanceName( params[0] ); //link.GetAgeInfo()->SetAgeUserDefinedName( params[0] ); plUUID guid( (const char *)params[1] ); @@ -375,7 +375,7 @@ PF_CONSOLE_CMD( Net, "Link to specified age using Original Age Linking Book rules" ) { plAgeLinkStruct link; - link.GetAgeInfo()->SetAgeFilename( params[0] ); + link.GetAgeInfo()->SetAgeFilename( (const char *)params[0] ); link.SpawnPoint() = plSpawnPointInfo( (const char *)params[1], (const char *)params[1] ); link.SetLinkingRules( plNetCommon::LinkingRules::kOriginalBook ); plNetLinkingMgr::GetInstance()->LinkToAge( &link ); @@ -388,7 +388,7 @@ PF_CONSOLE_CMD( Net, "Link to specified age using Personal Age Linking Book rules" ) { plAgeLinkStruct link; - link.GetAgeInfo()->SetAgeFilename( params[0] ); + link.GetAgeInfo()->SetAgeFilename( (const char *)params[0] ); link.SetLinkingRules( plNetCommon::LinkingRules::kOwnedBook ); plNetLinkingMgr::GetInstance()->LinkToAge( &link ); PrintString("Linking to age I own..."); @@ -400,7 +400,7 @@ PF_CONSOLE_CMD( Net, "Link to specified age using Personal Age Linking Book rules" ) { plAgeLinkStruct link; - link.GetAgeInfo()->SetAgeFilename( params[0] ); + link.GetAgeInfo()->SetAgeFilename( (const char *)params[0] ); link.SetLinkingRules( plNetCommon::LinkingRules::kVisitBook ); plNetLinkingMgr::GetInstance()->LinkToAge( &link ); PrintString("Linking to age I can visit..."); @@ -412,7 +412,7 @@ PF_CONSOLE_CMD( Net, "Link to a sub-age of the current age" ) { plAgeLinkStruct link; - link.GetAgeInfo()->SetAgeFilename( params[0] ); + link.GetAgeInfo()->SetAgeFilename( (const char *)params[0] ); link.SetLinkingRules( plNetCommon::LinkingRules::kSubAgeBook ); plNetLinkingMgr::GetInstance()->LinkToAge( &link ); PrintString("Linking to a sub-age..."); @@ -481,7 +481,7 @@ PF_CONSOLE_CMD( Net, plNetLinkingMgr * lm = plNetLinkingMgr::GetInstance(); plAgeInfoStruct info; - info.SetAgeFilename( params[0] ); + info.SetAgeFilename( (const char *)params[0] ); plAgeLinkStruct link; if (!VaultGetOwnedAgeLink(&info, &link)) { @@ -806,8 +806,8 @@ PF_CONSOLE_CMD( Net_Vault, "Add an instance of the specified age to your bookshelf" ) { plAgeLinkStruct link; - link.GetAgeInfo()->SetAgeFilename( params[0] ); - link.GetAgeInfo()->SetAgeInstanceName( params[0] ); + link.GetAgeInfo()->SetAgeFilename( (const char *)params[0] ); + link.GetAgeInfo()->SetAgeInstanceName( (const char *)params[0] ); plUUID guid = plUUID::Generate(); link.GetAgeInfo()->SetAgeInstanceGuid( &guid); link.SetSpawnPoint( kDefaultSpawnPoint ); @@ -822,7 +822,7 @@ PF_CONSOLE_CMD( Net_Vault, "Remove the specified age from your bookshelf" ) { plAgeInfoStruct info; - info.SetAgeFilename( params[0] ); + info.SetAgeFilename( (const char *)params[0] ); bool success = VaultUnregisterOwnedAgeAndWait(&info); PrintStringF(PrintString, "Operation %s.", success ? "Successful" : "Failed"); } @@ -834,8 +834,8 @@ PF_CONSOLE_CMD( Net_Vault, "Add an instance of the specified age to your private links" ) { plAgeLinkStruct link; - link.GetAgeInfo()->SetAgeFilename( params[0] ); - link.GetAgeInfo()->SetAgeInstanceName( params[0] ); + link.GetAgeInfo()->SetAgeFilename( (const char *)params[0] ); + link.GetAgeInfo()->SetAgeInstanceName( (const char *)params[0] ); plUUID guid = plUUID::Generate(); link.GetAgeInfo()->SetAgeInstanceGuid( &guid); link.SetSpawnPoint( kDefaultSpawnPoint ); @@ -850,7 +850,7 @@ PF_CONSOLE_CMD( Net_Vault, "Remove all instances of the specified age from your private links" ) { plAgeInfoStruct info; - info.SetAgeFilename( params[0] ); + info.SetAgeFilename( (const char *)params[0] ); unsigned count = 0; while (VaultUnregisterVisitAgeAndWait(&info)) diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp index 72a674b0..ef6abde0 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp @@ -632,7 +632,7 @@ PyObject* cyMisc::GetAgeInfo() } -const char* cyMisc::GetPrevAgeName() +plString cyMisc::GetPrevAgeName() { plNetLinkingMgr* nmgr = plNetLinkingMgr::GetInstance(); if (nmgr) @@ -641,7 +641,7 @@ const char* cyMisc::GetPrevAgeName() if (als) return als->GetAgeInfo()->GetAgeFilename(); } - return nil; + return plString::Null; } PyObject* cyMisc::GetPrevAgeInfo() diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h index 6dfa30ce..12180ec3 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h @@ -300,7 +300,7 @@ public: // static const char* GetAgeName(); static PyObject* GetAgeInfo(); // returns pyAgeInfoStruct - static const char* GetPrevAgeName(); + static plString GetPrevAgeName(); static PyObject* GetPrevAgeInfo(); // current time in current age static uint32_t GetAgeTime( void ); diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp index 852c8c31..fa252671 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp @@ -68,7 +68,7 @@ PYTHON_GLOBAL_METHOD_DEFINITION_NOARGS(PtGetAgeTime, "DEPRECIATED - use ptDniInf PYTHON_GLOBAL_METHOD_DEFINITION_NOARGS(PtGetPrevAgeName, "Returns filename of previous age visited") { - return PyString_FromString(cyMisc::GetPrevAgeName()); + return PyString_FromPlString(cyMisc::GetPrevAgeName()); } PYTHON_GLOBAL_METHOD_DEFINITION_NOARGS(PtGetPrevAgeInfo, "Returns ptAgeInfoStruct of previous age visited") diff --git a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp index 4cdfa0b7..5d9f1440 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp @@ -81,42 +81,42 @@ void pyAgeInfoStruct::CopyFromRef( const pyAgeInfoStructRef & other ) fAgeInfo.CopyFrom( other.GetAgeInfo() ); } -const char * pyAgeInfoStruct::GetAgeFilename() const +plString pyAgeInfoStruct::GetAgeFilename() const { return fAgeInfo.GetAgeFilename(); } -void pyAgeInfoStruct::SetAgeFilename( const char * v ) +void pyAgeInfoStruct::SetAgeFilename( const plString & v ) { fAgeInfo.SetAgeFilename( v ); } -const char * pyAgeInfoStruct::GetAgeInstanceName() const +plString pyAgeInfoStruct::GetAgeInstanceName() const { return fAgeInfo.GetAgeInstanceName(); } -void pyAgeInfoStruct::SetAgeInstanceName( const char * v ) +void pyAgeInfoStruct::SetAgeInstanceName( const plString & v ) { fAgeInfo.SetAgeInstanceName( v ); } -const char * pyAgeInfoStruct::GetAgeUserDefinedName() const +plString pyAgeInfoStruct::GetAgeUserDefinedName() const { return fAgeInfo.GetAgeUserDefinedName(); } -void pyAgeInfoStruct::SetAgeUserDefinedName( const char * v ) +void pyAgeInfoStruct::SetAgeUserDefinedName( const plString & v ) { fAgeInfo.SetAgeUserDefinedName( v ); } -const char * pyAgeInfoStruct::GetAgeDescription() const +plString pyAgeInfoStruct::GetAgeDescription() const { return fAgeInfo.GetAgeDescription(); } -void pyAgeInfoStruct::SetAgeDescription( const char * v ) +void pyAgeInfoStruct::SetAgeDescription( const plString & v ) { fAgeInfo.SetAgeDescription( v ); } @@ -132,12 +132,12 @@ void pyAgeInfoStruct::SetAgeInstanceGuid( const char * guid ) if ( guid[0] == '@' ) { // if it starts with an @ then do a meta kind of GUID - std::string curInst = fAgeInfo.GetAgeInstanceName(); - std::string y = curInst + guid; + plString curInst = fAgeInfo.GetAgeInstanceName(); + plString y = curInst + guid; plMD5Checksum hash; hash.Start(); - hash.AddTo(y.length(), (uint8_t*)y.c_str()); + hash.AddTo(y.GetSize(), (uint8_t*)y.c_str()); hash.Finish(); const char* md5sum = hash.GetAsHexString(); @@ -180,9 +180,9 @@ void pyAgeInfoStruct::SetAgeLanguage( int32_t v ) plString pyAgeInfoStruct::GetDisplayName() const { - const char* instance = GetAgeInstanceName(); - const char* user = GetAgeUserDefinedName(); - bool namesEqual = (stricmp(user, instance) == 0); // Ae'gura Ae'gura + plString instance = GetAgeInstanceName(); + plString user = GetAgeUserDefinedName(); + bool namesEqual = (user.CompareI(instance) == 0); // Ae'gura Ae'gura if (namesEqual) return instance; @@ -190,9 +190,9 @@ plString pyAgeInfoStruct::GetDisplayName() const { int32_t seq = GetAgeSequenceNumber(); if (seq > 0) - return plString::Format("%s (%d) %s", user, seq, instance); + return plString::Format("%s (%d) %s", user.c_str(), seq, instance.c_str()); else - return plString::Format("%s %s", user, instance); + return plString::Format("%s %s", user.c_str(), instance.c_str()); } } @@ -211,32 +211,32 @@ void pyAgeInfoStructRef::CopyFromRef( const pyAgeInfoStructRef & other ) fAgeInfo.CopyFrom( other.GetAgeInfo() ); } -const char * pyAgeInfoStructRef::GetAgeFilename() const +plString pyAgeInfoStructRef::GetAgeFilename() const { return fAgeInfo.GetAgeFilename(); } -void pyAgeInfoStructRef::SetAgeFilename( const char * v ) +void pyAgeInfoStructRef::SetAgeFilename( const plString & v ) { fAgeInfo.SetAgeFilename( v ); } -const char * pyAgeInfoStructRef::GetAgeInstanceName() const +plString pyAgeInfoStructRef::GetAgeInstanceName() const { return fAgeInfo.GetAgeInstanceName(); } -void pyAgeInfoStructRef::SetAgeInstanceName( const char * v ) +void pyAgeInfoStructRef::SetAgeInstanceName( const plString & v ) { fAgeInfo.SetAgeInstanceName( v ); } -const char * pyAgeInfoStructRef::GetAgeUserDefinedName() const +plString pyAgeInfoStructRef::GetAgeUserDefinedName() const { return fAgeInfo.GetAgeUserDefinedName(); } -void pyAgeInfoStructRef::SetAgeUserDefinedName( const char * v ) +void pyAgeInfoStructRef::SetAgeUserDefinedName( const plString & v ) { fAgeInfo.SetAgeUserDefinedName( v ); } @@ -265,9 +265,9 @@ void pyAgeInfoStructRef::SetAgeSequenceNumber( int32_t v ) plString pyAgeInfoStructRef::GetDisplayName() const { - const char* instance = GetAgeInstanceName(); - const char* user = GetAgeUserDefinedName(); - bool namesEqual = (stricmp(user, instance) == 0); // Ae'gura Ae'gura + plString instance = GetAgeInstanceName(); + plString user = GetAgeUserDefinedName(); + bool namesEqual = (user.CompareI(instance) == 0); // Ae'gura Ae'gura if (namesEqual) return instance; @@ -275,8 +275,8 @@ plString pyAgeInfoStructRef::GetDisplayName() const { int32_t seq = GetAgeSequenceNumber(); if (seq > 0) - return plString::Format("%s (%d) %s", user, seq, instance); + return plString::Format("%s (%d) %s", user.c_str(), seq, instance.c_str()); else - return plString::Format("%s %s", user, instance); + return plString::Format("%s %s", user.c_str(), instance.c_str()); } } diff --git a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.h b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.h index 89a7d302..5eb5f815 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.h @@ -87,14 +87,14 @@ public: static void PythonModDef(); void CopyFrom( const pyAgeInfoStruct & other ); void CopyFromRef( const pyAgeInfoStructRef & other ); - const char * GetAgeFilename() const; - void SetAgeFilename( const char * v ); - const char * GetAgeInstanceName() const; - void SetAgeInstanceName( const char * v ); - const char * GetAgeUserDefinedName() const; - void SetAgeUserDefinedName( const char * v ); - const char * GetAgeDescription() const; - void SetAgeDescription( const char * v ); + plString GetAgeFilename() const; + void SetAgeFilename( const plString & v ); + plString GetAgeInstanceName() const; + void SetAgeInstanceName( const plString & v ); + plString GetAgeUserDefinedName() const; + void SetAgeUserDefinedName( const plString & v ); + plString GetAgeDescription() const; + void SetAgeDescription( const plString & v ); const char * GetAgeInstanceGuid() const; void SetAgeInstanceGuid( const char * guid ); int32_t GetAgeSequenceNumber() const; @@ -132,12 +132,12 @@ public: const plAgeInfoStruct * GetAgeInfo() const { return &fAgeInfo; } void CopyFrom( const pyAgeInfoStruct & other ); void CopyFromRef( const pyAgeInfoStructRef & other ); - const char * GetAgeFilename() const; - void SetAgeFilename( const char * v ); - const char * GetAgeInstanceName() const; - void SetAgeInstanceName( const char * v ); - const char * GetAgeUserDefinedName() const; - void SetAgeUserDefinedName( const char * v ); + plString GetAgeFilename() const; + void SetAgeFilename( const plString & v ); + plString GetAgeInstanceName() const; + void SetAgeInstanceName( const plString & v ); + plString GetAgeUserDefinedName() const; + void SetAgeUserDefinedName( const plString & v ); const char * GetAgeInstanceGuid() const; void SetAgeInstanceGuid( const char * guid ); int32_t GetAgeSequenceNumber() const; diff --git a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStructGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStructGlue.cpp index fad2a201..75855e1c 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStructGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStructGlue.cpp @@ -115,7 +115,7 @@ PYTHON_METHOD_DEFINITION(ptAgeInfoStruct, copyFrom, args) PYTHON_METHOD_DEFINITION_NOARGS(ptAgeInfoStruct, getAgeFilename) { - return PyString_FromString(self->fThis->GetAgeFilename()); + return PyString_FromPlString(self->fThis->GetAgeFilename()); } PYTHON_METHOD_DEFINITION(ptAgeInfoStruct, setAgeFilename, args) @@ -132,7 +132,7 @@ PYTHON_METHOD_DEFINITION(ptAgeInfoStruct, setAgeFilename, args) PYTHON_METHOD_DEFINITION_NOARGS(ptAgeInfoStruct, getAgeInstanceName) { - return PyString_FromString(self->fThis->GetAgeInstanceName()); + return PyString_FromPlString(self->fThis->GetAgeInstanceName()); } PYTHON_METHOD_DEFINITION(ptAgeInfoStruct, setAgeInstanceName, args) @@ -149,7 +149,7 @@ PYTHON_METHOD_DEFINITION(ptAgeInfoStruct, setAgeInstanceName, args) PYTHON_METHOD_DEFINITION_NOARGS(ptAgeInfoStruct, getAgeUserDefinedName) { - return PyString_FromString(self->fThis->GetAgeUserDefinedName()); + return PyString_FromPlString(self->fThis->GetAgeUserDefinedName()); } PYTHON_METHOD_DEFINITION(ptAgeInfoStruct, setAgeUserDefinedName, args) @@ -166,7 +166,7 @@ PYTHON_METHOD_DEFINITION(ptAgeInfoStruct, setAgeUserDefinedName, args) PYTHON_METHOD_DEFINITION_NOARGS(ptAgeInfoStruct, getAgeDescription) { - return PyString_FromString(self->fThis->GetAgeDescription()); + return PyString_FromPlString(self->fThis->GetAgeDescription()); } PYTHON_METHOD_DEFINITION(ptAgeInfoStruct, setAgeDescription, args) @@ -325,7 +325,7 @@ PYTHON_METHOD_DEFINITION(ptAgeInfoStructRef, copyFrom, args) PYTHON_METHOD_DEFINITION_NOARGS(ptAgeInfoStructRef, getAgeFilename) { - return PyString_FromString(self->fThis->GetAgeFilename()); + return PyString_FromPlString(self->fThis->GetAgeFilename()); } PYTHON_METHOD_DEFINITION(ptAgeInfoStructRef, setAgeFilename, args) @@ -342,7 +342,7 @@ PYTHON_METHOD_DEFINITION(ptAgeInfoStructRef, setAgeFilename, args) PYTHON_METHOD_DEFINITION_NOARGS(ptAgeInfoStructRef, getAgeInstanceName) { - return PyString_FromString(self->fThis->GetAgeInstanceName()); + return PyString_FromPlString(self->fThis->GetAgeInstanceName()); } PYTHON_METHOD_DEFINITION(ptAgeInfoStructRef, setAgeInstanceName, args) @@ -359,7 +359,7 @@ PYTHON_METHOD_DEFINITION(ptAgeInfoStructRef, setAgeInstanceName, args) PYTHON_METHOD_DEFINITION_NOARGS(ptAgeInfoStructRef, getAgeUserDefinedName) { - return PyString_FromString(self->fThis->GetAgeUserDefinedName()); + return PyString_FromPlString(self->fThis->GetAgeUserDefinedName()); } PYTHON_METHOD_DEFINITION(ptAgeInfoStructRef, setAgeUserDefinedName, args) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyNetServerSessionInfo.h b/Sources/Plasma/FeatureLib/pfPython/pyNetServerSessionInfo.h index 2af30bf1..32688019 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyNetServerSessionInfo.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyNetServerSessionInfo.h @@ -76,9 +76,9 @@ public: plNetServerSessionInfo & ServerInfo() { return fInfo; } - void SetServerName(const char * val) { fInfo.SetServerName( val ); } + void SetServerName(const plString & val) { fInfo.SetServerName( val ); } void SetServerType(uint8_t val) { fInfo.SetServerType( val ); } - void SetServerAddr(const char * val) { fInfo.SetServerAddr( val ); } + void SetServerAddr(const plString & val) { fInfo.SetServerAddr( val ); } void SetServerPort(uint16_t val) { fInfo.SetServerPort( val ); } void SetServerGuid(const char * val) { fServerGuid.FromString( val ); fInfo.SetServerGuid( &fServerGuid ); } bool HasServerName() const { return fInfo.HasServerName(); } @@ -86,9 +86,9 @@ public: bool HasServerAddr() const { return fInfo.HasServerAddr(); } bool HasServerPort() const { return fInfo.HasServerPort(); } bool HasServerGuid() const { return fInfo.HasServerGuid(); } - const char * GetServerName() const { return fInfo.GetServerName(); } + plString GetServerName() const { return fInfo.GetServerName(); } uint8_t GetServerType() const { return fInfo.GetServerType(); } - const char * GetServerAddr() const { return fInfo.GetServerAddr(); } + plString GetServerAddr() const { return fInfo.GetServerAddr(); } uint16_t GetServerPort() const { return fInfo.GetServerPort(); } const char * GetServerGuid() const { fServerGuid.CopyFrom( fInfo.GetServerGuid() ); return fServerGuid.AsString().c_str(); } }; @@ -116,9 +116,9 @@ public: static void AddPlasmaClasses(PyObject *m); - void SetServerName(const char * val) { fInfo.SetServerName( val ); } + void SetServerName(const plString & val) { fInfo.SetServerName( val ); } void SetServerType(uint8_t val) { fInfo.SetServerType( val ); } - void SetServerAddr(const char * val) { fInfo.SetServerAddr( val ); } + void SetServerAddr(const plString & val) { fInfo.SetServerAddr( val ); } void SetServerPort(uint16_t val) { fInfo.SetServerPort( val ); } void SetServerGuid(const char * val) { fServerGuid.FromString( val ); fInfo.SetServerGuid( &fServerGuid ); } bool HasServerName() const { return fInfo.HasServerName(); } @@ -126,9 +126,9 @@ public: bool HasServerAddr() const { return fInfo.HasServerAddr(); } bool HasServerPort() const { return fInfo.HasServerPort(); } bool HasServerGuid() const { return fInfo.HasServerGuid(); } - const char * GetServerName() const { return fInfo.GetServerName(); } + plString GetServerName() const { return fInfo.GetServerName(); } uint8_t GetServerType() const { return fInfo.GetServerType(); } - const char * GetServerAddr() const { return fInfo.GetServerAddr(); } + plString GetServerAddr() const { return fInfo.GetServerAddr(); } uint16_t GetServerPort() const { return fInfo.GetServerPort(); } const char * GetServerGuid() const { fServerGuid.CopyFrom( fInfo.GetServerGuid() ); return fServerGuid.AsString().c_str(); } }; diff --git a/Sources/Plasma/FeatureLib/pfPython/pyNetServerSessionInfoGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/pyNetServerSessionInfoGlue.cpp index 824e7bc7..b212fecf 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyNetServerSessionInfoGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyNetServerSessionInfoGlue.cpp @@ -143,7 +143,7 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptNetServerSessionInfo, hasServerGuid) PYTHON_METHOD_DEFINITION_NOARGS(ptNetServerSessionInfo, getServerName) { - return PyString_FromString(self->fThis->GetServerName()); + return PyString_FromPlString(self->fThis->GetServerName()); } PYTHON_METHOD_DEFINITION_NOARGS(ptNetServerSessionInfo, getServerType) @@ -153,7 +153,7 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptNetServerSessionInfo, getServerType) PYTHON_METHOD_DEFINITION_NOARGS(ptNetServerSessionInfo, getServerAddr) { - return PyString_FromString(self->fThis->GetServerAddr()); + return PyString_FromPlString(self->fThis->GetServerAddr()); } PYTHON_METHOD_DEFINITION_NOARGS(ptNetServerSessionInfo, getServerPort) @@ -306,7 +306,7 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptNetServerSessionInfoRef, hasServerGuid) PYTHON_METHOD_DEFINITION_NOARGS(ptNetServerSessionInfoRef, getServerName) { - return PyString_FromString(self->fThis->GetServerName()); + return PyString_FromPlString(self->fThis->GetServerName()); } PYTHON_METHOD_DEFINITION_NOARGS(ptNetServerSessionInfoRef, getServerType) @@ -316,7 +316,7 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptNetServerSessionInfoRef, getServerType) PYTHON_METHOD_DEFINITION_NOARGS(ptNetServerSessionInfoRef, getServerAddr) { - return PyString_FromString(self->fThis->GetServerAddr()); + return PyString_FromPlString(self->fThis->GetServerAddr()); } PYTHON_METHOD_DEFINITION_NOARGS(ptNetServerSessionInfoRef, getServerPort) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyVault.cpp b/Sources/Plasma/FeatureLib/pfPython/pyVault.cpp index 61b43f39..0beff194 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyVault.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyVault.cpp @@ -671,18 +671,18 @@ void pyVault::CreateNeighborhood() if (nc->GetPlayerName().CharAt(nameLen - 1) == 's' || nc->GetPlayerName().CharAt(nameLen - 1) == 'S') { title = plString::Format( "%s'", nc->GetPlayerName().c_str() ); - desc = plString::Format( "%s' %s", nc->GetPlayerName().c_str(), link.GetAgeInfo()->GetAgeInstanceName() ); + desc = plString::Format( "%s' %s", nc->GetPlayerName().c_str(), link.GetAgeInfo()->GetAgeInstanceName().c_str() ); } else { title = plString::Format( "%s's", nc->GetPlayerName().c_str() ); - desc = plString::Format( "%s's %s", nc->GetPlayerName().c_str(), link.GetAgeInfo()->GetAgeInstanceName() ); + desc = plString::Format( "%s's %s", nc->GetPlayerName().c_str(), link.GetAgeInfo()->GetAgeInstanceName().c_str() ); } plUUID guid = plUUID::Generate(); link.GetAgeInfo()->SetAgeInstanceGuid(&guid); - link.GetAgeInfo()->SetAgeUserDefinedName( title.c_str() ); - link.GetAgeInfo()->SetAgeDescription( desc.c_str() ); + link.GetAgeInfo()->SetAgeUserDefinedName(title); + link.GetAgeInfo()->SetAgeDescription(desc); VaultRegisterOwnedAge(&link); } diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtStr.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtStr.h index a7d265ca..abfacd85 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtStr.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtStr.h @@ -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); diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.cpp index 3cc50879..37f4e8f9 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.cpp @@ -108,7 +108,6 @@ bool plSceneInputInterface::fShowLOS = false; plSceneInputInterface::plSceneInputInterface() { fPipe = nil; - fSpawnPoint = nil; fAgeInstanceGuid.Clear(); fInstance = this; SetEnabled( true ); // Always enabled @@ -840,11 +839,11 @@ void plSceneInputInterface::ILinkOffereeToAge() unsigned nameLen = plNetClientMgr::GetInstance()->GetPlayerName().GetSize(); if (plNetClientMgr::GetInstance()->GetPlayerName().CharAt(nameLen - 1) == 's' || plNetClientMgr::GetInstance()->GetPlayerName().CharAt(nameLen - 1) == 'S') { title = plString::Format( "%s'", plNetClientMgr::GetInstance()->GetPlayerName().c_str() ); - desc = plString::Format( "%s' %s", plNetClientMgr::GetInstance()->GetPlayerName().c_str(), link.GetAgeInfo()->GetAgeInstanceName() ); + desc = plString::Format( "%s' %s", plNetClientMgr::GetInstance()->GetPlayerName().c_str(), link.GetAgeInfo()->GetAgeInstanceName().c_str() ); } else { title = plString::Format( "%s's", plNetClientMgr::GetInstance()->GetPlayerName().c_str() ); - desc = plString::Format( "%s's %s", plNetClientMgr::GetInstance()->GetPlayerName().c_str(), link.GetAgeInfo()->GetAgeInstanceName() ); + desc = plString::Format( "%s's %s", plNetClientMgr::GetInstance()->GetPlayerName().c_str(), link.GetAgeInfo()->GetAgeInstanceName().c_str() ); } info.SetAgeUserDefinedName( title.c_str() ); @@ -869,7 +868,7 @@ void plSceneInputInterface::ILinkOffereeToAge() linkNode->DecRef(); } - if (fSpawnPoint) { + if (!fSpawnPoint.IsEmpty()) { plSpawnPointInfo spawnPoint; spawnPoint.SetName(fSpawnPoint); link.SetSpawnPoint(spawnPoint); @@ -878,12 +877,12 @@ void plSceneInputInterface::ILinkOffereeToAge() // We now own the age, offer it - if (0 == stricmp(fOfferedAgeFile, kPersonalAgeFilename)) + if (fOfferedAgeFile.CompareI(kPersonalAgeFilename) == 0) plNetLinkingMgr::GetInstance()->OfferLinkToPlayer(&link, fOffereeID, fManager->GetKey()); else plNetLinkingMgr::GetInstance()->LinkPlayerToAge(&link, fOffereeID); - if (!fPendingLink && stricmp(fOfferedAgeFile, kPersonalAgeFilename)) + if (!fPendingLink && fOfferedAgeFile.CompareI(kPersonalAgeFilename) != 0) { // tell our local dialog to pop up again... plKey avKey = plNetClientMgr::GetInstance()->GetLocalPlayerKey(); diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.h b/Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.h index fc2fcfd8..72d88ecf 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.h +++ b/Sources/Plasma/PubUtilLib/plInputCore/plSceneInputInterface.h @@ -82,10 +82,10 @@ class plSceneInputInterface : public plInputInterface int fBookMode; // are we in offer book mode? plKey fBookKey; // key for the python file modifier for the book we are offering plKey fOffereeKey; - uint32_t fOffereeID; // ID for the guy who's accepted our link offer - const char* fOfferedAgeFile; - const char* fOfferedAgeInstance; - const char* fSpawnPoint; + uint32_t fOffereeID; // ID for the guy who's accepted our link offer + plString fOfferedAgeFile; + plString fOfferedAgeInstance; + plString fSpawnPoint; plUUID fAgeInstanceGuid; struct clickableTest { diff --git a/Sources/Plasma/PubUtilLib/plMessage/plInputIfaceMgrMsg.h b/Sources/Plasma/PubUtilLib/plMessage/plInputIfaceMgrMsg.h index 16a29ece..90cec7ca 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plInputIfaceMgrMsg.h +++ b/Sources/Plasma/PubUtilLib/plMessage/plInputIfaceMgrMsg.h @@ -62,9 +62,9 @@ class plInputIfaceMgrMsg : public plMessage uint8_t fCommand; plInputInterface *fInterface; uint32_t fPageID; - const char* ageName; - const char* ageFileName; - const char* spawnPoint; + plString ageName; + plString ageFileName; + plString spawnPoint; plUUID ageInstanceGuid; plKey fAvKey; public: @@ -88,10 +88,10 @@ class plInputIfaceMgrMsg : public plMessage kSetShareAgeInstanceGuid, }; - plInputIfaceMgrMsg() : plMessage( nil, nil, nil ) { SetBCastFlag( kBCastByExactType ); fInterface = nil; ageName = ageFileName = spawnPoint = 0; fAvKey = nil; } - plInputIfaceMgrMsg( plKey &receiver, uint8_t command ) : plMessage( nil, nil, nil ) { AddReceiver( receiver ); fCommand = command; fInterface = nil; fAvKey = nil; ageName = ageFileName = spawnPoint = 0;} - plInputIfaceMgrMsg( uint8_t command ) : plMessage( nil, nil, nil ) { SetBCastFlag( kBCastByExactType ); fCommand = command; fInterface = nil; fAvKey = nil; ageName = ageFileName = spawnPoint = 0;} - plInputIfaceMgrMsg( uint8_t command, uint32_t pageID ) : plMessage( nil, nil, nil ) { SetBCastFlag( kBCastByExactType ); fCommand = command; fPageID = pageID; fInterface = nil; fAvKey = nil; ageName = ageFileName = spawnPoint = 0;} + plInputIfaceMgrMsg() : plMessage( nil, nil, nil ) { SetBCastFlag( kBCastByExactType ); fInterface = nil; fAvKey = nil; } + plInputIfaceMgrMsg( plKey &receiver, uint8_t command ) : plMessage( nil, nil, nil ) { AddReceiver( receiver ); fCommand = command; fInterface = nil; fAvKey = nil; } + plInputIfaceMgrMsg( uint8_t command ) : plMessage( nil, nil, nil ) { SetBCastFlag( kBCastByExactType ); fCommand = command; fInterface = nil; fAvKey = nil; } + plInputIfaceMgrMsg( uint8_t command, uint32_t pageID ) : plMessage( nil, nil, nil ) { SetBCastFlag( kBCastByExactType ); fCommand = command; fPageID = pageID; fInterface = nil; fAvKey = nil; } ~plInputIfaceMgrMsg(); CLASSNAME_REGISTER( plInputIfaceMgrMsg ); @@ -102,9 +102,9 @@ class plInputIfaceMgrMsg : public plMessage plMessage::IMsgRead( s, mgr ); s->ReadLE( &fCommand ); s->ReadLE( &fPageID ); - ageName = s->ReadSafeString(); - ageFileName = s->ReadSafeString(); - spawnPoint = s->ReadSafeString(); + ageName = s->ReadSafeString_TEMP(); + ageFileName = s->ReadSafeString_TEMP(); + spawnPoint = s->ReadSafeString_TEMP(); fAvKey = mgr->ReadKey(s); } @@ -119,18 +119,18 @@ class plInputIfaceMgrMsg : public plMessage mgr->WriteKey(s,fAvKey); } - void SetAgeName(const char* s) { ageName = s; } - const char* GetAgeName() { return ageName; } - void SetAgeFileName(const char* s) { ageFileName = s; } - const char* GetAgeFileName() { return ageFileName; } - void SetSpawnPoint(const char* s) { spawnPoint = s; } - const char* GetSpawnPoint() { return spawnPoint; } + void SetAgeName(const plString& s) { ageName = s; } + plString GetAgeName() const { return ageName; } + void SetAgeFileName(const plString& s) { ageFileName = s; } + plString GetAgeFileName() const { return ageFileName; } + void SetSpawnPoint(const plString& s) { spawnPoint = s; } + plString GetSpawnPoint() const { return spawnPoint; } void SetAgeInstanceGuid(const plUUID& guid) { ageInstanceGuid = guid; } - const plUUID& GetAgeInstanceGuid() { return ageInstanceGuid; } - uint8_t GetCommand( void ) { return fCommand; } - uint32_t GetPageID( void ) { return fPageID; } + const plUUID& GetAgeInstanceGuid() const { return ageInstanceGuid; } + uint8_t GetCommand() const { return fCommand; } + uint32_t GetPageID() const { return fPageID; } void SetIFace( plInputInterface *iface ); - plInputInterface *GetIFace( void ) const { return fInterface; } + plInputInterface *GetIFace() const { return fInterface; } plKey& GetAvKey( void ) { return fAvKey; } const plKey& GetAvKey( void ) const { return fAvKey; } void SetAvKey( plKey& k ) { fAvKey = k; } diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plLinkEffectsMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plLinkEffectsMgr.cpp index 6cab6095..e5528a6f 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plLinkEffectsMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plLinkEffectsMgr.cpp @@ -374,16 +374,16 @@ bool plLinkEffectsMgr::MsgReceive(plMessage *msg) if (linkKey == nc->GetLocalPlayerKey()) { if(lm) { - const char *ageName = lm->GetAgeLink()->GetAgeInfo()->GetAgeFilename(); - const char *prevAgeName = lm->GetPrevAgeLink()->GetAgeInfo()->GetAgeFilename(); + plString ageName = lm->GetAgeLink()->GetAgeInfo()->GetAgeFilename(); + plString prevAgeName = lm->GetPrevAgeLink()->GetAgeInfo()->GetAgeFilename(); - bool linkToStartup = ageName && !stricmp(ageName, kStartUpAgeFilename ); // To Startup - bool linkFromStartup = prevAgeName && !stricmp(prevAgeName, kStartUpAgeFilename); // Leaving Startup + bool linkToStartup = ageName.CompareI(kStartUpAgeFilename) == 0; // To Startup + bool linkFromStartup = prevAgeName.CompareI(kStartUpAgeFilename) == 0; // Leaving Startup bool cleftSolved = VaultHasChronicleEntry( kCleftSolved ); - bool linkToACA = ageName && !stricmp(ageName, kAvCustomizationFilename); - bool linkFromACA = prevAgeName && !stricmp(prevAgeName, kAvCustomizationFilename); + bool linkToACA = ageName.CompareI(kAvCustomizationFilename) == 0; + bool linkFromACA = prevAgeName.CompareI(kAvCustomizationFilename) == 0; bool linkToFissureDrop = lm && lm->GetAgeLink()->HasSpawnPt() && @@ -606,4 +606,4 @@ void plLinkEffectsMgr::IRemovePseudo(plKey avatarKey) } } -} \ No newline at end of file +} diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp index 1dd07572..6e93f451 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp @@ -1144,7 +1144,7 @@ bool plNetClientMgr::ObjectInLocalAge(const plSynchedObject* obj) const // // the next age we are going to // -const char* plNetClientMgr::GetNextAgeFilename() +plString plNetClientMgr::GetNextAgeFilename() const { // set when we start linking to an age. plNetLinkingMgr * lm = plNetLinkingMgr::GetInstance(); diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h index 4cac0c0f..d7ab4207 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h @@ -358,7 +358,7 @@ public: const plKey& GetAgeSDLObjectKey() const { return fAgeSDLObjectKey; } plUoid GetAgeSDLObjectUoid(const char* ageName) const; plNetClientComm& GetNetClientComm() { return fNetClientComm; } - const char* GetNextAgeFilename(); + plString GetNextAgeFilename() const; void SetOverrideAgeTimeOfDayPercent(float f) { fOverrideAgeTimeOfDayPercent=f; } void AddPendingPagingRoomMsg( plNetMsgPagingRoom * msg ); diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.cpp index af34573d..0379cbb4 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.cpp @@ -72,7 +72,7 @@ void plNetClientMsgScreener::ICreateStatusLog() const // // return cur age name // -const char* plNetClientMsgScreener::IGetAgeName() const +plString plNetClientMsgScreener::IGetAgeName() const { plNetLinkingMgr *lm = plNetLinkingMgr::GetInstance(); return lm && lm->GetAgeLink()->GetAgeInfo() ? lm->GetAgeLink()->GetAgeInfo()->GetAgeFilename() : "?"; diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.h b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.h index c449fc2a..cf0044ca 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.h +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.h @@ -52,7 +52,7 @@ class plNetClientMsgScreener : public plNetMsgScreener protected: void ICreateStatusLog() const; const char* IGetSenderName(const plNetGameMember* gm) const { return "local"; } - const char* IGetAgeName() const; + plString IGetAgeName() const; bool IIsLocalAvatarKey(plKey key, const plNetGameMember* gm) const; bool IIsLocalArmatureModKey(plKey key, const plNetGameMember* gm) const; bool IIsSenderCCR(const plNetGameMember* gm=nil) const; diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp index bd5651ff..ff38afa6 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp @@ -436,7 +436,7 @@ void plNetLinkingMgr::IDoLink(plLinkToAgeMsg* msg) joinAgeOp->muteSfx = !msg->PlayLinkInSfx(); StrCopy( joinAgeOp->age.ageDatasetName, - GetAgeLink()->GetAgeInfo()->GetAgeFilename(), + GetAgeLink()->GetAgeInfo()->GetAgeFilename().c_str(), arrsize(joinAgeOp->age.ageDatasetName) ); StrCopy( @@ -775,9 +775,9 @@ void plNetLinkingMgr::IPostProcessLink( void ) plAgeLinkStruct* link = GetAgeLink(); plAgeInfoStruct* info = link->GetAgeInfo(); - bool city = (stricmp(info->GetAgeFilename(), kCityAgeFilename) == 0); - bool hood = (stricmp(info->GetAgeFilename(), kNeighborhoodAgeFilename) == 0); - bool psnl = (stricmp(info->GetAgeFilename(), kPersonalAgeFilename) == 0); + bool city = (info->GetAgeFilename().CompareI(kCityAgeFilename) == 0); + bool hood = (info->GetAgeFilename().CompareI(kNeighborhoodAgeFilename) == 0); + bool psnl = (info->GetAgeFilename().CompareI(kPersonalAgeFilename) == 0); // Update our online status if (RelVaultNode* rvnInfo = VaultGetPlayerInfoNodeIncRef()) { @@ -913,17 +913,17 @@ uint8_t plNetLinkingMgr::IPreProcessLink(void) //------------------------------------------------------------------------ // SPECIAL CASE: StartUp: force basic link - if (stricmp(info->GetAgeFilename(), kStartUpAgeFilename) == 0) + if (info->GetAgeFilename().CompareI(kStartUpAgeFilename) == 0) link->SetLinkingRules( plNetCommon::LinkingRules::kBasicLink ); //------------------------------------------------------------------------ // SPECIAL CASE: Nexus: force original link - if (stricmp(info->GetAgeFilename(), kNexusAgeFilename) == 0) + if (info->GetAgeFilename().CompareI(kNexusAgeFilename) == 0) link->SetLinkingRules(plNetCommon::LinkingRules::kOriginalBook); //------------------------------------------------------------------------ // SPECIAL CASE: ACA: force original link - if (stricmp(info->GetAgeFilename(), kAvCustomizationFilename ) == 0) + if (info->GetAgeFilename().CompareI(kAvCustomizationFilename) == 0) link->SetLinkingRules(plNetCommon::LinkingRules::kOriginalBook); hsLogEntry(nc->DebugMsg("plNetLinkingMgr: Process: Linking with %s rules...", @@ -970,9 +970,9 @@ uint8_t plNetLinkingMgr::IPreProcessLink(void) plString desc; unsigned nameLen = nc->GetPlayerName().GetSize(); if (nc->GetPlayerName().ToLower().CharAt(nameLen - 1) == 's') - desc = plString::Format("%s' %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName()); + desc = plString::Format("%s' %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName().c_str()); else - desc = plString::Format("%s's %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName()); + desc = plString::Format("%s's %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName().c_str()); info->SetAgeDescription(desc.c_str()); } if (!info->HasAgeInstanceGuid()) { @@ -1010,9 +1010,9 @@ uint8_t plNetLinkingMgr::IPreProcessLink(void) plString desc; unsigned nameLen = nc->GetPlayerName().GetSize(); if (nc->GetPlayerName().ToLower().CharAt(nameLen - 1) == 's') - desc = plString::Format("%s' %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName()); + desc = plString::Format("%s' %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName().c_str()); else - desc = plString::Format("%s's %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName()); + desc = plString::Format("%s's %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName().c_str()); info->SetAgeDescription( desc.c_str() ); } @@ -1029,7 +1029,7 @@ uint8_t plNetLinkingMgr::IPreProcessLink(void) } } else { - if (stricmp(info->GetAgeFilename(), kNeighborhoodAgeFilename) == 0) { + if (info->GetAgeFilename().CompareI(kNeighborhoodAgeFilename) == 0) { // if we get here then it's because we're linking to a neighborhood that we don't belong to // and our own neighborhood book is not volatile, so really we want to basic link link->SetLinkingRules(plNetCommon::LinkingRules::kBasicLink); diff --git a/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.cpp b/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.cpp index a5e575a8..af107476 100644 --- a/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.cpp +++ b/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.cpp @@ -68,7 +68,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com void plNetMsgScreener::IRejectLogMsg(int16_t classIndex, const char* desc, const plNetGameMember* gm) const { DebugMsg("Message %s was rejected, reason:%s, age:%s, client:%s", - plFactory::GetNameOfClass(classIndex), desc, IGetAgeName(), IGetSenderName(gm)); + plFactory::GetNameOfClass(classIndex), desc, IGetAgeName().c_str(), IGetSenderName(gm)); } // @@ -80,7 +80,7 @@ void plNetMsgScreener::IRejectLogMsg(const plMessage* msg, const char* desc, con const char* rcvrName = msg->GetNumReceivers() && msg->GetReceiver(0) ? msg->GetReceiver(0)->GetUoid().GetObjectName().c_str() : "?"; DebugMsg("Message %s was rejected, reason:%s, age:%s, client:%s, msgSndr:%s, msgRcvr:%s", - msg->ClassName(), desc, IGetAgeName(), IGetSenderName(gm), + msg->ClassName(), desc, IGetAgeName().c_str(), IGetSenderName(gm), senderName, rcvrName); } diff --git a/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.h b/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.h index cee32efa..14ee203c 100644 --- a/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.h +++ b/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.h @@ -63,7 +63,7 @@ protected: kYes }; virtual const char* IGetSenderName(const plNetGameMember* gm) const = 0; - virtual const char* IGetAgeName() const = 0; + virtual plString IGetAgeName() const = 0; virtual bool IIsSenderCCR(const plNetGameMember* gm=nil) const = 0; virtual bool IIsLocalAvatarKey(plKey key, const plNetGameMember* gm) const = 0; virtual bool IIsLocalArmatureModKey(plKey key, const plNetGameMember* gm) const { return true; } diff --git a/Sources/Plasma/PubUtilLib/plNetCommon/plNetServerSessionInfo.cpp b/Sources/Plasma/PubUtilLib/plNetCommon/plNetServerSessionInfo.cpp index 79c9f8bb..6c89a5cf 100644 --- a/Sources/Plasma/PubUtilLib/plNetCommon/plNetServerSessionInfo.cpp +++ b/Sources/Plasma/PubUtilLib/plNetCommon/plNetServerSessionInfo.cpp @@ -46,7 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plNetCommon.h" #include "plVault/plVault.h" -#define SAFE(s) ((s)?(s):"(nil)") +#define SAFE(s) ((s).IsEmpty() ? "(nil)" : (s)) #define kComma "," #define kEmpty "" #define kSemicolon ";" @@ -119,11 +119,11 @@ bool plAgeInfoStruct::IsEqualTo( const plAgeInfoStruct * other ) const // otherwise compare everything. bool match = true; if (match && HasAgeFilename() && other->HasAgeFilename()) - match = match && ( stricmp( GetAgeFilename(), other->GetAgeFilename() )==0 ); + match = match && ( GetAgeFilename().CompareI( other->GetAgeFilename() )==0 ); if (match && HasAgeInstanceName() && other->HasAgeInstanceName()) - match = match && ( stricmp( GetAgeInstanceName(), other->GetAgeInstanceName() )==0 ); + match = match && ( GetAgeInstanceName().CompareI( other->GetAgeInstanceName() )==0 ); if (match && HasAgeUserDefinedName() && other->HasAgeUserDefinedName()) - match = match && ( stricmp( GetAgeUserDefinedName(), other->GetAgeUserDefinedName() )==0 ); + match = match && ( GetAgeUserDefinedName().CompareI( other->GetAgeUserDefinedName() )==0 ); if (match && HasAgeSequenceNumber() && other->HasAgeSequenceNumber()) match = match && fAgeSequenceNumber==other->GetAgeSequenceNumber(); if (match && HasAgeLanguage() && other->HasAgeLanguage()) @@ -238,9 +238,9 @@ plString plAgeInfoStruct::AsString() const } -void plAgeInfoStruct::SetAgeFilename( const char * v ) +void plAgeInfoStruct::SetAgeFilename( const plString & v ) { - if ( v && v[0]) + if (!v.IsEmpty()) { SetFlag( kHasAgeFilename ); fAgeFilename=v; @@ -251,9 +251,9 @@ void plAgeInfoStruct::SetAgeFilename( const char * v ) } } -void plAgeInfoStruct::SetAgeInstanceName( const char * v ) +void plAgeInfoStruct::SetAgeInstanceName( const plString & v ) { - if ( v && v[0]) + if (!v.IsEmpty()) { SetFlag( kHasAgeInstanceName ); fAgeInstanceName=v; @@ -278,9 +278,9 @@ void plAgeInfoStruct::SetAgeInstanceGuid( const plUUID * v ) } } -void plAgeInfoStruct::SetAgeUserDefinedName( const char * v ) +void plAgeInfoStruct::SetAgeUserDefinedName( const plString & v ) { - if ( v && v[0]) + if (!v.IsEmpty()) { SetFlag( kHasAgeUserDefinedName ); fAgeUserDefinedName=v; @@ -304,9 +304,9 @@ void plAgeInfoStruct::SetAgeSequenceNumber( uint32_t v ) } } -void plAgeInfoStruct::SetAgeDescription( const char * v ) +void plAgeInfoStruct::SetAgeDescription( const plString & v ) { - if ( v && v[0]) + if (!v.IsEmpty()) { SetFlag( kHasAgeDescription ); fAgeDescription=v; @@ -332,12 +332,12 @@ void plAgeInfoStruct::SetAgeLanguage( uint32_t v ) void plAgeInfoStruct::UpdateFlags() const { - SetFlag( kHasAgeFilename, fAgeFilename.size()!=0 ); - SetFlag( kHasAgeInstanceName, fAgeInstanceName.size()!=0 ); - SetFlag( kHasAgeUserDefinedName, fAgeUserDefinedName.size()!=0 ); + SetFlag( kHasAgeFilename, !fAgeFilename.IsEmpty() ); + SetFlag( kHasAgeInstanceName, !fAgeInstanceName.IsEmpty() ); + SetFlag( kHasAgeUserDefinedName, !fAgeUserDefinedName.IsEmpty() ); SetFlag( kHasAgeInstanceGuid, fAgeInstanceGuid.IsSet() ); SetFlag( kHasAgeSequenceNumber, fAgeSequenceNumber!=0 ); - SetFlag( kHasAgeDescription, fAgeDescription.size()!=0 ); + SetFlag( kHasAgeDescription, !fAgeDescription.IsEmpty() ); SetFlag( kHasAgeLanguage, fAgeLanguage>=0 ); } @@ -622,7 +622,7 @@ plString plNetServerSessionInfo::AsString() const { ss << spacer << "N:" - << SAFE(fServerName.c_str()); + << SAFE(fServerName); spacer = kComma; } if (HasServerGuid()) @@ -636,7 +636,7 @@ plString plNetServerSessionInfo::AsString() const { ss << spacer << "A:[" - << SAFE(fServerAddr.c_str()) + << SAFE(fServerAddr) << ":" << fServerPort << "]"; @@ -662,14 +662,14 @@ plString plNetServerSessionInfo::AsLogString() const if (HasServerName()) { ss << typeName << "Name" << "="; - ss << fServerName.c_str(); + ss << fServerName; ss << spacer; } if (HasServerAddr()) { ss << typeName << "Addr" << "="; - ss << fServerAddr.c_str(); + ss << fServerAddr; ss << spacer; } @@ -696,27 +696,26 @@ bool plNetServerSessionInfo::IsEqualTo(const plNetServerSessionInfo * other) con if (match && IsFlagSet(kHasServerGuid) && other->IsFlagSet(kHasServerGuid)) match = match && fServerGuid.IsEqualTo(other->GetServerGuid()); if (match && IsFlagSet(kHasServerName) && other->IsFlagSet(kHasServerName)) - match = match && (stricmp(fServerName.c_str(),other->fServerName.c_str())==0); + match = match && (fServerName.CompareI(other->fServerName)==0); if (match && IsFlagSet(kHasServerType) && other->IsFlagSet(kHasServerType)) match = match && fServerType==other->fServerType; if (match && IsFlagSet(kHasServerAddr) && other->IsFlagSet(kHasServerAddr)) - match = match && (stricmp(fServerAddr.c_str(),other->fServerAddr.c_str())==0); + match = match && (fServerAddr.CompareI(other->fServerAddr)==0); if (match && IsFlagSet(kHasServerPort) && other->IsFlagSet(kHasServerPort)) match = match && fServerPort==other->fServerPort; return match; } -void plNetServerSessionInfo::SetServerName(const char * val) +void plNetServerSessionInfo::SetServerName(const plString & val) { - if (val) + fServerName = val; + if (!val.IsEmpty()) { - fServerName=val; SetFlag(kHasServerName); } else { - fServerName=""; ClearFlag(kHasServerName); } } @@ -735,16 +734,15 @@ void plNetServerSessionInfo::SetServerType(uint8_t val) } } -void plNetServerSessionInfo::SetServerAddr(const char * val) +void plNetServerSessionInfo::SetServerAddr(const plString & val) { - if (val) + fServerAddr = val; + if (!val.IsEmpty()) { - fServerAddr = val; SetFlag(kHasServerAddr); } else { - fServerAddr = ""; ClearFlag(kHasServerAddr); } } diff --git a/Sources/Plasma/PubUtilLib/plNetCommon/plNetServerSessionInfo.h b/Sources/Plasma/PubUtilLib/plNetCommon/plNetServerSessionInfo.h index 43a68608..7812b1c7 100644 --- a/Sources/Plasma/PubUtilLib/plNetCommon/plNetServerSessionInfo.h +++ b/Sources/Plasma/PubUtilLib/plNetCommon/plNetServerSessionInfo.h @@ -43,7 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define plNetServerSessionInfo_h_inc #include "HeadSpin.h" -#include #include "pnFactory/plCreatable.h" #include "pnNetCommon/plNetServers.h" @@ -64,19 +63,19 @@ class plAgeInfoStruct : public plCreatable mutable uint8_t fFlags; // Age dataset name "Neighborhood" - std::string fAgeFilename; + plString fAgeFilename; // Age string ID "Bevin" - std::string fAgeInstanceName; + plString fAgeInstanceName; // Age guid. Same as game server guid. plUUID fAgeInstanceGuid; // User-defined age name: "My Teledahn" - std::string fAgeUserDefinedName; + plString fAgeUserDefinedName; // User-defined age description "This is Joe's Neighborhood" - std::string fAgeDescription; + plString fAgeDescription; // A modifier to user-defined name to make it unique in gui lists. // Assigned by vault server. @@ -117,19 +116,19 @@ public: void CopyFrom(const struct NetAgeInfo & info); bool IsEqualTo( const plAgeInfoStruct * other ) const; - const char * GetAgeFilename() const { return fAgeFilename.c_str(); } - const char * GetAgeInstanceName() const { return fAgeInstanceName.c_str(); } + plString GetAgeFilename() const { return fAgeFilename; } + plString GetAgeInstanceName() const { return fAgeInstanceName; } const plUUID * GetAgeInstanceGuid() const { return &fAgeInstanceGuid; } - const char * GetAgeUserDefinedName() const { return fAgeUserDefinedName.c_str(); } - const char * GetAgeDescription() const { return fAgeDescription.c_str(); } + plString GetAgeUserDefinedName() const { return fAgeUserDefinedName; } + plString GetAgeDescription() const { return fAgeDescription; } uint32_t GetAgeSequenceNumber() const { return fAgeSequenceNumber; } uint32_t GetAgeLanguage() const { return fAgeLanguage; } - void SetAgeFilename( const char * v ); - void SetAgeInstanceName( const char * v ); + void SetAgeFilename( const plString & v ); + void SetAgeInstanceName( const plString & v ); void SetAgeInstanceGuid( const plUUID * v ); - void SetAgeUserDefinedName( const char * v ); - void SetAgeDescription( const char * v ); + void SetAgeUserDefinedName( const plString & v ); + void SetAgeDescription( const plString & v ); void SetAgeSequenceNumber( uint32_t v ); void SetAgeLanguage( uint32_t v ); @@ -227,12 +226,12 @@ public: class plNetServerSessionInfo : public plCreatable { - uint8_t fFlags; - std::string fServerName; - uint8_t fServerType; - std::string fServerAddr; - uint16_t fServerPort; - plUUID fServerGuid; + uint8_t fFlags; + plString fServerName; + uint8_t fServerType; + plString fServerAddr; + uint16_t fServerPort; + plUUID fServerGuid; enum { @@ -256,17 +255,17 @@ public: CLASSNAME_REGISTER( plNetServerSessionInfo ); GETINTERFACE_ANY( plNetServerSessionInfo, plCreatable ); - void SetServerName(const char * val); + void SetServerName(const plString & val); void SetServerType(uint8_t val); - void SetServerAddr(const char * val); + void SetServerAddr(const plString & val); void SetServerPort(uint16_t val); void SetServerGuid(const plUUID * val); void CopyServerGuid(const plUUID & val); - const char * GetServerName() const { return fServerName.c_str();} - uint8_t GetServerType() const { return fServerType;} - const char * GetServerAddr() const { return fServerAddr.c_str(); } - uint16_t GetServerPort() const { return fServerPort; } + plString GetServerName() const { return fServerName; } + uint8_t GetServerType() const { return fServerType; } + plString GetServerAddr() const { return fServerAddr; } + uint16_t GetServerPort() const { return fServerPort; } const plUUID *GetServerGuid() const { return &fServerGuid; } plUUID * GetServerGuid() { return &fServerGuid; } diff --git a/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp b/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp index 35f8c5a1..e3ab47ac 100644 --- a/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp +++ b/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp @@ -5001,9 +5001,8 @@ uint8_t VaultAgeFindOrCreateChildAgeLink( // Still here? Try to find the Child Ages folder uint8_t retval = hsFail; if (RelVaultNode* rvnChildAges = rvnParentInfo->GetChildAgeInfoListNodeIncRef(plVault::kChildAgesFolder, 1)) { - const char* ageName = info->GetAgeFilename(); wchar_t hack[MAX_PATH]; - StrToUnicode(hack, ageName, arrsize(hack)); + StrToUnicode(hack, info->GetAgeFilename(), arrsize(hack)); // Search for our age NetVaultNode* temp = new NetVaultNode; From ae1bbdc1d609aaa996ab467474983d7fa5ca0406 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sun, 12 Jan 2014 17:45:53 -0800 Subject: [PATCH 08/15] Animation SDL variable names => plString --- .../Plasma/PubUtilLib/plAvatar/plAGAnim.cpp | 19 ++----------------- Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.h | 10 ++++------ .../PubUtilLib/plSurface/plLayerAnimation.cpp | 17 +++-------------- .../PubUtilLib/plSurface/plLayerAnimation.h | 7 +++---- 4 files changed, 12 insertions(+), 41 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.cpp index ba1987a6..2182347d 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.cpp @@ -665,30 +665,15 @@ float plEmoteAnim::GetFadeOut() const plAgeGlobalAnim::plAgeGlobalAnim() : plAGAnim() { - fGlobalVarName = nil; } // ctor -------------------------------------------------------------------- // ----- plAgeGlobalAnim::plAgeGlobalAnim(const plString &name, double start, double end) -: plAGAnim(name, start, end), - fGlobalVarName(nil) +: plAGAnim(name, start, end) { } -// dtor --------------------------- -// ----- -plAgeGlobalAnim::~plAgeGlobalAnim() -{ - delete [] fGlobalVarName; -} - -void plAgeGlobalAnim::SetGlobalVarName(char *name) -{ - delete [] fGlobalVarName; - fGlobalVarName = hsStrcpy(name); -} - // Read --------------------------------------------------- // ----- @@ -696,7 +681,7 @@ void plAgeGlobalAnim::Read(hsStream *stream, hsResMgr *mgr) { plAGAnim::Read(stream, mgr); - fGlobalVarName = stream->ReadSafeString(); + fGlobalVarName = stream->ReadSafeString_TEMP(); } // Write --------------------------------------------------- diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.h b/Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.h index 70e9b172..2e22e1cb 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.h +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.h @@ -417,11 +417,9 @@ public: /** Construct with name, start time, and end time (within the max note track) */ plAgeGlobalAnim(const plString &name, double begin, double end); - /** Destruct, freeing the underlying animation data. */ - virtual ~plAgeGlobalAnim(); - - const char * GetGlobalVarName() const { return fGlobalVarName; } - void SetGlobalVarName(char *name); + + plString GetGlobalVarName() const { return fGlobalVarName; } + void SetGlobalVarName(const plString &name) { fGlobalVarName = name; } // PLASMA PROTOCOL // rtti @@ -433,7 +431,7 @@ public: virtual void Write(hsStream* stream, hsResMgr* mgr); protected: - char *fGlobalVarName; // Name of the SDL variable we animate on. + plString fGlobalVarName; // Name of the SDL variable we animate on. }; // USEFUL HELPER FUNCTIONS diff --git a/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.cpp b/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.cpp index dff15914..64222131 100644 --- a/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.cpp +++ b/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.cpp @@ -674,12 +674,7 @@ bool plLayerLinkAnimation::MsgReceive( plMessage* pMsg ) /////////////////////////////////////////////////////////////////////////////////////////////// -plLayerSDLAnimation::plLayerSDLAnimation() : plLayerAnimationBase(), fVar(nil), fVarName(nil) {} - -plLayerSDLAnimation::~plLayerSDLAnimation() -{ - delete [] fVarName; -} +plLayerSDLAnimation::plLayerSDLAnimation() : plLayerAnimationBase(), fVar(nil) {} uint32_t plLayerSDLAnimation::Eval(double wSecs, uint32_t frame, uint32_t ignore) { @@ -691,7 +686,7 @@ uint32_t plLayerSDLAnimation::Eval(double wSecs, uint32_t frame, uint32_t ignore if (fEvalTime < 0) { - if (fVarName != nil) + if (!fVarName.IsEmpty()) { extern const plSDLModifier *ExternFindAgeSDL(); const plSDLModifier *sdlMod = ExternFindAgeSDL(); @@ -741,7 +736,7 @@ void plLayerSDLAnimation::Read(hsStream* s, hsResMgr* mgr) { plLayerAnimationBase::Read(s, mgr); - fVarName = s->ReadSafeString(); + fVarName = s->ReadSafeString_TEMP(); } void plLayerSDLAnimation::Write(hsStream* s, hsResMgr* mgr) @@ -750,9 +745,3 @@ void plLayerSDLAnimation::Write(hsStream* s, hsResMgr* mgr) s->WriteSafeString(fVarName); } - -void plLayerSDLAnimation::SetVarName(char *name) -{ - delete [] fVarName; - fVarName = hsStrcpy(name); -} diff --git a/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.h b/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.h index 55172273..28a0371a 100644 --- a/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.h +++ b/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.h @@ -189,11 +189,10 @@ class plLayerSDLAnimation : public plLayerAnimationBase { protected: plSimpleStateVariable *fVar; - char *fVarName; + plString fVarName; public: plLayerSDLAnimation(); - virtual ~plLayerSDLAnimation(); CLASSNAME_REGISTER( plLayerSDLAnimation ); GETINTERFACE_ANY( plLayerSDLAnimation, plLayerAnimationBase ); @@ -205,8 +204,8 @@ public: virtual void Read(hsStream* s, hsResMgr* mgr); virtual void Write(hsStream* s, hsResMgr* mgr); - char *GetVarName() { return fVarName; } - void SetVarName(char *name); + plString GetVarName() const { return fVarName; } + void SetVarName(const plString &name) { fVarName = name; } }; #endif // plLayerAnimation_inc From f1131bbb257ef69c968947b7210a2ffa311d57b6 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sun, 12 Jan 2014 17:59:20 -0800 Subject: [PATCH 09/15] Fix winmain use and a couple of remaining SafeStrings => plString --- Sources/Plasma/Apps/plClient/winmain.cpp | 9 ++++----- Sources/Plasma/PubUtilLib/plMessage/plAvatarMsg.cpp | 2 +- .../Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.cpp | 13 ++++--------- .../Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.h | 7 +++---- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index cb179d5b..4d26acf8 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -872,7 +872,7 @@ static void LoadUserPass (LoginDialogParam *pLoginParam) ZeroMemory(cryptKey, sizeof(cryptKey)); GetCryptKey(cryptKey, arrsize(cryptKey)); - char* temp; + plString temp; pLoginParam->remember = false; pLoginParam->username[0] = '\0'; @@ -891,12 +891,11 @@ static void LoadUserPass (LoginDialogParam *pLoginParam) if (memcmp(cryptKey, savedKey, sizeof(savedKey)) == 0) { - temp = stream->ReadSafeString(); + temp = stream->ReadSafeString_TEMP(); - if (temp) + if (!temp.IsEmpty()) { - StrCopy(pLoginParam->username, temp, kMaxAccountNameLength); - delete[] temp; + StrCopy(pLoginParam->username, temp.c_str(), kMaxAccountNameLength); } pLoginParam->remember = stream->ReadBool(); diff --git a/Sources/Plasma/PubUtilLib/plMessage/plAvatarMsg.cpp b/Sources/Plasma/PubUtilLib/plMessage/plAvatarMsg.cpp index a6ba9134..0939486b 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plAvatarMsg.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plAvatarMsg.cpp @@ -236,7 +236,7 @@ void plAvSeekMsg::Read(hsStream *stream, hsResMgr *mgr) fDuration = stream->ReadLEScalar(); fSmartSeek = stream->ReadBool(); - fAnimName = stream->ReadSafeString(); + fAnimName = stream->ReadSafeString_TEMP(); fAlignType = static_cast(stream->ReadLE16()); fNoSeek = stream->ReadBool(); fFlags = stream->ReadByte(); diff --git a/Sources/Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.cpp b/Sources/Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.cpp index 13fecb4b..ad40cd69 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.cpp @@ -53,20 +53,15 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // // plLinkToAgeMsg -plLinkToAgeMsg::plLinkToAgeMsg() : fLinkInAnimName(nil), fFlags(0) +plLinkToAgeMsg::plLinkToAgeMsg() : fFlags(0) { } -plLinkToAgeMsg::plLinkToAgeMsg( const plAgeLinkStruct * link ) : fLinkInAnimName(nil), fFlags(0) +plLinkToAgeMsg::plLinkToAgeMsg( const plAgeLinkStruct * link ) : fFlags(0) { fAgeLink.CopyFrom( link ); } -plLinkToAgeMsg::~plLinkToAgeMsg() -{ - delete [] fLinkInAnimName; -} - void plLinkToAgeMsg::PlayLinkSfx(bool linkIn, bool linkOut) { if (linkIn) @@ -84,7 +79,7 @@ void plLinkToAgeMsg::Read(hsStream* stream, hsResMgr* mgr) plMessage::IMsgRead( stream, mgr ); fFlags = stream->ReadByte(); fAgeLink.Read( stream, mgr ); - fLinkInAnimName = stream->ReadSafeString(); + fLinkInAnimName = stream->ReadSafeString_TEMP(); } void plLinkToAgeMsg::Write(hsStream* stream, hsResMgr* mgr) @@ -111,7 +106,7 @@ void plLinkToAgeMsg::ReadVersion(hsStream* s, hsResMgr* mgr) if ( contentFlags.IsBitSet( kLinkToAgeAgeLinkStruct ) ) fAgeLink.Read( s, mgr ); if ( contentFlags.IsBitSet( kLinkToAgeLinkAnimName ) ) - fLinkInAnimName = s->ReadSafeString(); + fLinkInAnimName = s->ReadSafeString_TEMP(); } void plLinkToAgeMsg::WriteVersion(hsStream* s, hsResMgr* mgr) diff --git a/Sources/Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.h b/Sources/Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.h index 13592be6..625f5ca5 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.h +++ b/Sources/Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.h @@ -66,12 +66,11 @@ class plLinkToAgeMsg : public plMessage uint8_t fFlags; plAgeLinkStruct fAgeLink; - char* fLinkInAnimName; + plString fLinkInAnimName; public: plLinkToAgeMsg(); plLinkToAgeMsg( const plAgeLinkStruct * link ); - virtual ~plLinkToAgeMsg(); CLASSNAME_REGISTER( plLinkToAgeMsg ); GETINTERFACE_ANY( plLinkToAgeMsg, plMessage ); @@ -83,8 +82,8 @@ public: bool PlayLinkInSfx() const { return (fFlags & kMuteLinkInSfx) == 0; } bool PlayLinkOutSfx() const { return (fFlags & kMuteLinkOutSfx) == 0; } - const char * GetLinkInAnimName() { return fLinkInAnimName; } - void SetLinkInAnimName(const char* name) { delete [] fLinkInAnimName; fLinkInAnimName = hsStrcpy(name); } + plString GetLinkInAnimName() { return fLinkInAnimName; } + void SetLinkInAnimName(const plString& name) { fLinkInAnimName = name; } void Read(hsStream* stream, hsResMgr* mgr); void Write(hsStream* stream, hsResMgr* mgr); From dceb911f2538fa7b7299d5f589c2a474bf71bfb9 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sun, 12 Jan 2014 18:12:43 -0800 Subject: [PATCH 10/15] Clean up some crazy in plClientResMgr --- .../plClientResMgr/plClientResMgr.cpp | 37 +++++++------------ .../plClientResMgr/plClientResMgr.h | 11 +++--- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp index 5e544a48..d85cde24 100644 --- a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp @@ -59,28 +59,19 @@ plClientResMgr& plClientResMgr::Instance(void) return theInstance; } -plClientResMgr::plClientResMgr() -{ - this->ClientResources = new std::map; -} - plClientResMgr::~plClientResMgr() { - if (this->ClientResources) { - std::map::iterator it; - - for (it = this->ClientResources->begin(); it != this->ClientResources->end(); ++it) { - if (it->second) - it->second->UnRef(); - } + std::map::iterator it; - delete this->ClientResources; + for (it = ClientResources.begin(); it != ClientResources.end(); ++it) { + if (it->second) + it->second->UnRef(); } } -void plClientResMgr::ILoadResources(const char* resfile) +void plClientResMgr::ILoadResources(const plFileName& resfile) { - if (!resfile) { + if (!resfile.IsValid()) { return; } @@ -98,10 +89,8 @@ void plClientResMgr::ILoadResources(const char* resfile) for (int i = 0; i < num_resources; i++) { plMipmap* res_data = NULL; uint32_t res_size = 0; - char* tmp_name = in.ReadSafeStringLong(); - std::string res_name = std::string(tmp_name); - std::string res_type = res_name.substr(res_name.length() - 4, 4); - delete[] tmp_name; + plString res_name = in.ReadSafeStringLong_TEMP(); + plString res_type = res_name.Substr(res_name.GetSize() - 4, 4); // Version 1 doesn't encode format, so we'll try some simple // extension sniffing @@ -122,7 +111,7 @@ void plClientResMgr::ILoadResources(const char* resfile) in.Skip(res_size); } - (*this->ClientResources)[res_name] = res_data; + ClientResources[res_name] = res_data; } break; @@ -134,12 +123,12 @@ void plClientResMgr::ILoadResources(const char* resfile) } } -plMipmap* plClientResMgr::getResource(const char* resname) +plMipmap* plClientResMgr::getResource(const plString& resname) { - plMipmap* resmipmap = NULL; - std::map::iterator it = this->ClientResources->find(resname); + plMipmap* resmipmap = nullptr; + std::map::iterator it = ClientResources.find(resname); - if (it != this->ClientResources->end()) { + if (it != ClientResources.end()) { resmipmap = it->second; } else { hsAssert(resmipmap, "Unknown client resource requested."); diff --git a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h index f3c16b73..1dc2e241 100644 --- a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h +++ b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h @@ -44,21 +44,22 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define _plClientResMgr_h #include -#include class plMipmap; +class plString; +class plFileName; class plClientResMgr { protected: - std::map* ClientResources; + std::map ClientResources; public: - plClientResMgr(); + plClientResMgr() { } ~plClientResMgr(); - void ILoadResources(const char* resfile); + void ILoadResources(const plFileName& resfile); - plMipmap* getResource(const char* resname); + plMipmap* getResource(const plString& resname); static plClientResMgr& Instance(void); }; From d7fdf10455d748d6b15708a6dc544ff8307e1e6e Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sun, 12 Jan 2014 18:39:33 -0800 Subject: [PATCH 11/15] Convert ReadSafe(W)String* to the plString variants, and remove the now unneeded _TEMP variants. All safe strings read from hsStreams are now plStringified :) --- Sources/Plasma/Apps/plClient/winmain.cpp | 2 +- Sources/Plasma/CoreLib/hsStream.cpp | 46 ++----------------- Sources/Plasma/CoreLib/hsStream.h | 14 ++---- Sources/Plasma/CoreLib/plGeneric.cpp | 2 +- .../pfGameGUIMgr/pfGUIButtonMod.cpp | 4 +- .../pfGameGUIMgr/pfGUICheckBoxCtrl.cpp | 2 +- .../pfGameGUIMgr/pfGUIControlMod.cpp | 2 +- .../FeatureLib/pfGameGUIMgr/pfGUIKnobCtrl.cpp | 2 +- .../pfGameGUIMgr/pfGUIListElement.cpp | 4 +- .../pfGameGUIMgr/pfGUIProgressCtrl.cpp | 2 +- .../pfGameGUIMgr/pfGUITextBoxMod.cpp | 2 +- .../FeatureLib/pfMessage/pfBackdoorMsg.h | 4 +- .../FeatureLib/pfMessage/pfGameGUIMsg.h | 2 +- Sources/Plasma/FeatureLib/pfMessage/pfKIMsg.h | 4 +- .../FeatureLib/pfMessage/pfMovieEventMsg.cpp | 2 +- .../FeatureLib/pfPython/plPythonFileMod.cpp | 2 +- .../FeatureLib/pfPython/plPythonPack.cpp | 2 +- .../NucleusLib/pnKeyedObject/plUoid.cpp | 2 +- .../NucleusLib/pnMessage/plNotifyMsg.cpp | 4 +- .../NucleusLib/pnNetCommon/plGenericVar.cpp | 4 +- .../PubUtilLib/plAudioCore/plSoundBuffer.cpp | 2 +- .../Plasma/PubUtilLib/plAvatar/plAGAnim.cpp | 8 ++-- .../PubUtilLib/plAvatar/plAGApplicator.cpp | 2 +- .../PubUtilLib/plAvatar/plAGChannel.cpp | 2 +- .../PubUtilLib/plAvatar/plAGModifier.cpp | 2 +- .../PubUtilLib/plAvatar/plAnimStage.cpp | 2 +- .../PubUtilLib/plAvatar/plArmatureMod.cpp | 8 ++-- .../PubUtilLib/plAvatar/plAvatarClothing.cpp | 12 ++--- .../PubUtilLib/plAvatar/plAvatarTasks.cpp | 6 +-- .../PubUtilLib/plAvatar/plCoopCoordinator.cpp | 2 +- .../PubUtilLib/plAvatar/plNPCSpawnMod.cpp | 4 +- .../PubUtilLib/plAvatar/plOneShotMod.cpp | 2 +- .../plClientResMgr/plClientResMgr.cpp | 2 +- .../Plasma/PubUtilLib/plMessage/plAIMsg.cpp | 2 +- .../PubUtilLib/plMessage/plAnimCmdMsg.cpp | 6 +-- .../PubUtilLib/plMessage/plAvatarMsg.cpp | 4 +- .../PubUtilLib/plMessage/plDynamicTextMsg.cpp | 4 +- .../PubUtilLib/plMessage/plInputIfaceMgrMsg.h | 6 +-- .../PubUtilLib/plMessage/plLinkToAgeMsg.cpp | 4 +- .../PubUtilLib/plMessage/plLoadAgeMsg.cpp | 2 +- .../PubUtilLib/plMessage/plLoadAvatarMsg.cpp | 4 +- .../plMessage/plOneShotCallbacks.cpp | 2 +- .../plModifier/plCloneSpawnModifier.cpp | 2 +- .../PubUtilLib/plPipeline/plDynamicEnvMap.cpp | 4 +- .../Plasma/PubUtilLib/plResMgr/plPageInfo.cpp | 6 +-- .../PubUtilLib/plSDL/plStateDataRecord.cpp | 2 +- .../PubUtilLib/plSDL/plStateDescriptor.cpp | 2 +- .../PubUtilLib/plSDL/plStateVariable.cpp | 2 +- .../PubUtilLib/plSDL/plVarDescriptor.cpp | 6 +-- .../PubUtilLib/plSurface/plLayerAnimation.cpp | 2 +- .../Tools/MaxComponent/plMultistageStage.cpp | 4 +- 51 files changed, 91 insertions(+), 135 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index 4d26acf8..44d3bf3c 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -891,7 +891,7 @@ static void LoadUserPass (LoginDialogParam *pLoginParam) if (memcmp(cryptKey, savedKey, sizeof(savedKey)) == 0) { - temp = stream->ReadSafeString_TEMP(); + temp = stream->ReadSafeString(); if (!temp.IsEmpty()) { diff --git a/Sources/Plasma/CoreLib/hsStream.cpp b/Sources/Plasma/CoreLib/hsStream.cpp index 84d0efe6..45e0d00f 100644 --- a/Sources/Plasma/CoreLib/hsStream.cpp +++ b/Sources/Plasma/CoreLib/hsStream.cpp @@ -158,7 +158,7 @@ uint32_t hsStream::WriteSafeWStringLong(const plString &string) return 0; } -plString hsStream::ReadSafeStringLong_TEMP() +plString hsStream::ReadSafeStringLong() { plStringBuffer name; uint32_t numChars = ReadLE32(); @@ -179,15 +179,7 @@ plString hsStream::ReadSafeStringLong_TEMP() return name; } -char *hsStream::ReadSafeStringLong() -{ - plString name = ReadSafeStringLong_TEMP(); - char *buff = new char[name.GetSize() + 1]; - memcpy(buff, name.c_str(), name.GetSize() + 1); - return buff; -} - -plString hsStream::ReadSafeWStringLong_TEMP() +plString hsStream::ReadSafeWStringLong() { plStringBuffer retVal; uint32_t numChars = ReadLE32(); @@ -209,17 +201,6 @@ plString hsStream::ReadSafeWStringLong_TEMP() return plString::FromUtf16(retVal); } -wchar_t *hsStream::ReadSafeWStringLong() -{ - // Horribly inefficient (convert to UTF-8 and then back to UTF-16), which - // is why this should go away completely after plString has taken over - // the world^H^H^H^H^HPlasma - plStringBuffer retVal = ReadSafeWStringLong_TEMP().ToWchar(); - wchar_t *buff = new wchar_t[retVal.GetSize() + 1]; - memcpy(buff, retVal.GetData(), retVal.GetSize() + 1); - return buff; -} - uint32_t hsStream::WriteSafeString(const plString &string) { int len = string.GetSize(); @@ -261,7 +242,7 @@ uint32_t hsStream::WriteSafeWString(const plString &string) return 0; } -plString hsStream::ReadSafeString_TEMP() +plString hsStream::ReadSafeString() { plStringBuffer name; uint16_t numChars = ReadLE16(); @@ -293,15 +274,7 @@ plString hsStream::ReadSafeString_TEMP() return name; } -char *hsStream::ReadSafeString() -{ - plString name = ReadSafeString_TEMP(); - char *buff = new char[name.GetSize() + 1]; - memcpy(buff, name.c_str(), name.GetSize() + 1); - return buff; -} - -plString hsStream::ReadSafeWString_TEMP() +plString hsStream::ReadSafeWString() { plStringBuffer retVal; uint32_t numChars = ReadLE16(); @@ -326,17 +299,6 @@ plString hsStream::ReadSafeWString_TEMP() return plString::FromUtf16(retVal); } -wchar_t *hsStream::ReadSafeWString() -{ - // Horribly inefficient (convert to UTF-8 and then back to UTF-16), which - // is why this should go away completely after plString has taken over - // the world^H^H^H^H^HPlasma - plStringBuffer retVal = ReadSafeWString_TEMP().ToWchar(); - wchar_t *buff = new wchar_t[retVal.GetSize() + 1]; - memcpy(buff, retVal.GetData(), retVal.GetSize() + 1); - return buff; -} - bool hsStream::Read4Bytes(void *pv) // Virtual, faster version in sub classes { int knt = this->Read(sizeof(uint32_t), pv); diff --git a/Sources/Plasma/CoreLib/hsStream.h b/Sources/Plasma/CoreLib/hsStream.h index c80787cf..9153c51d 100644 --- a/Sources/Plasma/CoreLib/hsStream.h +++ b/Sources/Plasma/CoreLib/hsStream.h @@ -55,7 +55,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define hsReadOnlyLoggingStream hsReadOnlyStream #define LogRead(byteCount, buffer, desc) Read(byteCount, buffer) #define LogReadSafeString() ReadSafeString() -#define LogReadSafeString_TEMP() ReadSafeString_TEMP() #define LogReadSafeStringLong() ReadSafeStringLong(); #define LogSkip(deltaByteCount, desc) Skip(deltaByteCount) #define LogReadLE(value, desc) ReadLE(value) @@ -126,18 +125,13 @@ public: uint32_t WriteSafeStringLong(const plString &string); // uses 4 bytes for length uint32_t WriteSafeWStringLong(const plString &string); - char * ReadSafeStringLong(); - wchar_t * ReadSafeWStringLong(); + plString ReadSafeStringLong(); + plString ReadSafeWStringLong(); uint32_t WriteSafeString(const plString &string); // uses 2 bytes for length uint32_t WriteSafeWString(const plString &string); - char * ReadSafeString(); - wchar_t * ReadSafeWString(); - - plString ReadSafeStringLong_TEMP(); - plString ReadSafeWStringLong_TEMP(); - plString ReadSafeString_TEMP(); - plString ReadSafeWString_TEMP(); + plString ReadSafeString(); + plString ReadSafeWString(); bool GetToken(char *s, uint32_t maxLen=uint32_t(-1), const char beginComment=kComment, const char endComment=kEolnCode); bool ReadLn(char* s, uint32_t maxLen=uint32_t(-1), const char beginComment=kComment, const char endComment=kEolnCode); diff --git a/Sources/Plasma/CoreLib/plGeneric.cpp b/Sources/Plasma/CoreLib/plGeneric.cpp index 1b60a671..2cf2cb2c 100644 --- a/Sources/Plasma/CoreLib/plGeneric.cpp +++ b/Sources/Plasma/CoreLib/plGeneric.cpp @@ -144,7 +144,7 @@ int plGeneric::Read(hsStream* stream) break; case kString: - fStringVal = stream->ReadSafeWString_TEMP(); + fStringVal = stream->ReadSafeWString(); break; } return stream->GetPosition(); diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIButtonMod.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIButtonMod.cpp index af6daade..36b4f430 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIButtonMod.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIButtonMod.cpp @@ -196,13 +196,13 @@ void pfGUIButtonMod::Read( hsStream *s, hsResMgr *mgr ) uint32_t i, count = s->ReadLE32(); for( i = 0; i < count; i++ ) fAnimationKeys.Append( mgr->ReadKey( s ) ); - fAnimName = s->ReadSafeString_TEMP(); + fAnimName = s->ReadSafeString(); fMouseOverAnimKeys.Reset(); count = s->ReadLE32(); for( i = 0; i < count; i++ ) fMouseOverAnimKeys.Append( mgr->ReadKey( s ) ); - fMouseOverAnimName = s->ReadSafeString_TEMP(); + fMouseOverAnimName = s->ReadSafeString(); fNotifyType = s->ReadLE32(); mgr->ReadKeyNotifyMe( s, new plGenRefMsg( GetKey(), plRefMsg::kOnCreate, -1, kRefDraggable ), plRefFlags::kActiveRef ); diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUICheckBoxCtrl.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUICheckBoxCtrl.cpp index a0144aab..6c302ce8 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUICheckBoxCtrl.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUICheckBoxCtrl.cpp @@ -96,7 +96,7 @@ void pfGUICheckBoxCtrl::Read( hsStream *s, hsResMgr *mgr ) for( i = 0; i < count; i++ ) fAnimationKeys.Append( mgr->ReadKey( s ) ); - fAnimName = s->ReadSafeString_TEMP(); + fAnimName = s->ReadSafeString(); fChecked = s->ReadBool(); } diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp index ca6cb413..865bf184 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp @@ -118,7 +118,7 @@ void pfGUIColorScheme::Read( hsStream *s ) fSelBackColor.Read( s ); fTransparent = s->ReadBOOL(); - fFontFace = s->ReadSafeString_TEMP(); + fFontFace = s->ReadSafeString(); s->ReadLE( &fFontSize ); s->ReadLE( &fFontFlags ); } diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIKnobCtrl.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIKnobCtrl.cpp index 81e04908..24bca699 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIKnobCtrl.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIKnobCtrl.cpp @@ -106,7 +106,7 @@ void pfGUIKnobCtrl::Read( hsStream *s, hsResMgr *mgr ) uint32_t i, count = s->ReadLE32(); for( i = 0; i < count; i++ ) fAnimationKeys.Append( mgr->ReadKey( s ) ); - fAnimName = s->ReadSafeString_TEMP(); + fAnimName = s->ReadSafeString(); fAnimTimesCalced = false; diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.cpp index 669ff146..f229e227 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.cpp @@ -93,7 +93,7 @@ void pfGUIListText::Read( hsStream *s, hsResMgr *mgr ) { pfGUIListElement::Read( s, mgr ); - fText = s->ReadSafeString_TEMP(); + fText = s->ReadSafeString(); } void pfGUIListText::Write( hsStream *s, hsResMgr *mgr ) @@ -274,7 +274,7 @@ void pfGUIListTreeRoot::Read( hsStream *s, hsResMgr *mgr ) { pfGUIListElement::Read( s, mgr ); - fText = s->ReadSafeString_TEMP(); + fText = s->ReadSafeString(); } void pfGUIListTreeRoot::Write( hsStream *s, hsResMgr *mgr ) diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIProgressCtrl.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIProgressCtrl.cpp index 123fcd09..027f36cf 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIProgressCtrl.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIProgressCtrl.cpp @@ -108,7 +108,7 @@ void pfGUIProgressCtrl::Read( hsStream *s, hsResMgr *mgr ) uint32_t i, count = s->ReadLE32(); for( i = 0; i < count; i++ ) fAnimationKeys.Append( mgr->ReadKey( s ) ); - fAnimName = s->ReadSafeString_TEMP(); + fAnimName = s->ReadSafeString(); fAnimTimesCalced = false; } diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.cpp index 9aaa02dc..1b5c5347 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.cpp @@ -169,7 +169,7 @@ void pfGUITextBoxMod::Read( hsStream *s, hsResMgr *mgr ) fUseLocalizationPath = s->ReadBool(); if (fUseLocalizationPath) { - fLocalizationPath = s->ReadSafeWString_TEMP(); + fLocalizationPath = s->ReadSafeWString(); } } diff --git a/Sources/Plasma/FeatureLib/pfMessage/pfBackdoorMsg.h b/Sources/Plasma/FeatureLib/pfMessage/pfBackdoorMsg.h index fea3d661..dfad50dd 100644 --- a/Sources/Plasma/FeatureLib/pfMessage/pfBackdoorMsg.h +++ b/Sources/Plasma/FeatureLib/pfMessage/pfBackdoorMsg.h @@ -74,8 +74,8 @@ class pfBackdoorMsg : public plMessage virtual void Read(hsStream* s, hsResMgr* mgr) { plMessage::IMsgRead( s, mgr ); - fTarget = s->ReadSafeString_TEMP(); - fString = s->ReadSafeString_TEMP(); + fTarget = s->ReadSafeString(); + fString = s->ReadSafeString(); } virtual void Write(hsStream* s, hsResMgr* mgr) diff --git a/Sources/Plasma/FeatureLib/pfMessage/pfGameGUIMsg.h b/Sources/Plasma/FeatureLib/pfMessage/pfGameGUIMsg.h index 217456ce..05cece5b 100644 --- a/Sources/Plasma/FeatureLib/pfMessage/pfGameGUIMsg.h +++ b/Sources/Plasma/FeatureLib/pfMessage/pfGameGUIMsg.h @@ -84,7 +84,7 @@ class pfGameGUIMsg : public plMessage s->Read(sizeof(buffer), buffer); buffer[GAME_GUI_MSG_STRING_SIZE - 1] = 0; fString = buffer; - fAge = s->ReadSafeString_TEMP(); + fAge = s->ReadSafeString(); } virtual void Write(hsStream* s, hsResMgr* mgr) diff --git a/Sources/Plasma/FeatureLib/pfMessage/pfKIMsg.h b/Sources/Plasma/FeatureLib/pfMessage/pfKIMsg.h index 0bffa243..cbeff2f2 100644 --- a/Sources/Plasma/FeatureLib/pfMessage/pfKIMsg.h +++ b/Sources/Plasma/FeatureLib/pfMessage/pfKIMsg.h @@ -188,9 +188,9 @@ class pfKIMsg : public plMessage { plMessage::IMsgRead( s, mgr ); s->ReadLE( &fCommand ); - fUser = s->ReadSafeString_TEMP(); + fUser = s->ReadSafeString(); fPlayerID = s->ReadLE32(); - fString = s->ReadSafeWString_TEMP(); + fString = s->ReadSafeWString(); fFlags = s->ReadLE32(); fDelay = s->ReadLEScalar(); fValue = s->ReadLE32(); diff --git a/Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.cpp b/Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.cpp index 10a5848c..309a0a5d 100644 --- a/Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.cpp +++ b/Sources/Plasma/FeatureLib/pfMessage/pfMovieEventMsg.cpp @@ -49,7 +49,7 @@ void pfMovieEventMsg::Read(hsStream* stream, hsResMgr* mgr) fReason = (Reason)stream->ReadByte(); - fMovieName = stream->ReadSafeString_TEMP(); + fMovieName = stream->ReadSafeString(); } void pfMovieEventMsg::Write(hsStream* stream, hsResMgr* mgr) diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp index e3ebe2d6..feb52b3b 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp @@ -2989,7 +2989,7 @@ void plPythonFileMod::Read(hsStream* stream, hsResMgr* mgr) plMultiModifier::Read(stream, mgr); // read in the compile python code (pyc) - fPythonFile = stream->ReadSafeString_TEMP(); + fPythonFile = stream->ReadSafeString(); // then read in the list of receivers that want to be notified int nRcvs = stream->ReadLE32(); diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp b/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp index 8242c75f..4b3fdf53 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp @@ -148,7 +148,7 @@ bool plPythonPack::Open() for (int i = 0; i < numFiles; i++) { // and pack the index into our own data structure - plString pythonName = fPackStream->ReadSafeString_TEMP(); + plString pythonName = fPackStream->ReadSafeString(); uint32_t offset = fPackStream->ReadLE32(); plPackOffsetInfo offsetInfo; diff --git a/Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.cpp b/Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.cpp index 9e070e18..872f70a8 100644 --- a/Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.cpp +++ b/Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.cpp @@ -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) diff --git a/Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.cpp b/Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.cpp index c3ea0f4a..b959ccb4 100644 --- a/Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.cpp +++ b/Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.cpp @@ -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)) diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.cpp b/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.cpp index 08a79082..fd7e16ff 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.cpp @@ -154,7 +154,7 @@ void plGenericType::Read(hsStream* s) { case kString: case kAny: - fS=s->ReadSafeString_TEMP(); + fS=s->ReadSafeString(); break; case kBool: {int8_t b; @@ -219,7 +219,7 @@ void plGenericType::Write(hsStream* s) /////////////////////////////////////////////////// void plGenericVar::Read(hsStream* s) { - fName = s->ReadSafeString_TEMP(); + fName = s->ReadSafeString(); fValue.Read(s); } diff --git a/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp b/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp index 0b8ca2cc..4a6c24cb 100644 --- a/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp +++ b/Sources/Plasma/PubUtilLib/plAudioCore/plSoundBuffer.cpp @@ -219,7 +219,7 @@ void plSoundBuffer::Read( hsStream *s, hsResMgr *mgr ) s->ReadLE( &fFlags ); s->ReadLE( &fDataLength ); - fFileName = s->ReadSafeString_TEMP(); + fFileName = s->ReadSafeString(); s->ReadLE( &fHeader.fFormatTag ); s->ReadLE( &fHeader.fNumChannels ); diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.cpp index 2182347d..02ae07e9 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.cpp @@ -217,7 +217,7 @@ void plAGAnim::Read(hsStream *stream, hsResMgr *mgr) plSynchedObject::Read(stream, mgr); // read in the name of the animation itself - fName = stream->ReadSafeString_TEMP(); + fName = stream->ReadSafeString(); fStart = stream->ReadLEScalar(); fEnd = stream->ReadLEScalar(); @@ -412,7 +412,7 @@ void plATCAnim::Read(hsStream *stream, hsResMgr *mgr) int numMarkers = stream->ReadLE32(); for (i = 0; i < numMarkers; i++) { - plString name = stream->ReadSafeString_TEMP(); + plString name = stream->ReadSafeString(); float time = stream->ReadLEFloat(); fMarkers[name] = time; } @@ -420,7 +420,7 @@ void plATCAnim::Read(hsStream *stream, hsResMgr *mgr) int numLoops = stream->ReadLE32(); for (i = 0; i < numLoops; i++) { - plString name = stream->ReadSafeString_TEMP(); + plString name = stream->ReadSafeString(); float begin = stream->ReadLEScalar(); float end = stream->ReadLEScalar(); fLoops[name] = std::pair(begin,end); @@ -681,7 +681,7 @@ void plAgeGlobalAnim::Read(hsStream *stream, hsResMgr *mgr) { plAGAnim::Read(stream, mgr); - fGlobalVarName = stream->ReadSafeString_TEMP(); + fGlobalVarName = stream->ReadSafeString(); } // Write --------------------------------------------------- diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAGApplicator.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAGApplicator.cpp index 742a64d3..59079874 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAGApplicator.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAGApplicator.cpp @@ -138,7 +138,7 @@ void plAGApplicator::Read(hsStream *stream, hsResMgr *mgr) fEnabled = stream->ReadBool(); fChannel = nil; // Whatever is reading this applicator in should know what channel to assign it - fChannelName = stream->ReadSafeString_TEMP(); + fChannelName = stream->ReadSafeString(); } // IGETxI diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAGChannel.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAGChannel.cpp index f31602ed..9c088bf8 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAGChannel.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAGChannel.cpp @@ -119,7 +119,7 @@ void plAGChannel::Read(hsStream *stream, hsResMgr *mgr) { plCreatable::Read(stream, mgr); - fName = stream->ReadSafeString_TEMP(); + fName = stream->ReadSafeString(); } //////////////////////////////////////////////////////////////////////////////////// diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAGModifier.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAGModifier.cpp index 56754037..3cbe480e 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAGModifier.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAGModifier.cpp @@ -269,7 +269,7 @@ void plAGModifier::Read(hsStream *stream, hsResMgr *mgr) plSingleModifier::Read(stream, mgr); // read in the name of the modifier - fChannelName = stream->ReadSafeString_TEMP(); + fChannelName = stream->ReadSafeString(); } // WRITE diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAnimStage.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAnimStage.cpp index b3ee36a2..90a15a94 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAnimStage.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAnimStage.cpp @@ -741,7 +741,7 @@ void plAnimStage::DumpDebug(bool active, int &x, int &y, int lineHeight, plDebug // READ void plAnimStage::Read(hsStream *stream, hsResMgr *mgr) { - fAnimName = stream->ReadSafeString_TEMP(); + fAnimName = stream->ReadSafeString(); fNotify = stream->ReadByte(); fForwardType = (ForwardType)stream->ReadLE32(); fBackType = (BackType)stream->ReadLE32(); diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp index 3921d58f..cb1a607f 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp @@ -1756,7 +1756,7 @@ void plArmatureMod::Read(hsStream * stream, hsResMgr *mgr) fMeshKeys.push_back(mgr->ReadKey(stream)); // read the root name string - fRootName = stream->ReadSafeString_TEMP(); + fRootName = stream->ReadSafeString(); // read in the brains int nBrains = stream->ReadLE32(); @@ -1821,9 +1821,9 @@ void plArmatureMod::Read(hsStream * stream, hsResMgr *mgr) fPhysHeight = stream->ReadLEFloat(); fPhysWidth = stream->ReadLEFloat(); - fAnimationPrefix = stream->ReadSafeString_TEMP(); - fBodyAgeName = stream->ReadSafeString_TEMP(); - fBodyFootstepSoundPage = stream->ReadSafeString_TEMP(); + fAnimationPrefix = stream->ReadSafeString(); + fBodyAgeName = stream->ReadSafeString(); + fBodyFootstepSoundPage = stream->ReadSafeString(); plgDispatch::Dispatch()->RegisterForExactType(plAvatarStealthModeMsg::Index(), GetKey()); } diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp index c962bdc2..8bd97bdd 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp @@ -160,14 +160,14 @@ void plClothingItem::Read(hsStream *s, hsResMgr *mgr) { hsKeyedObject::Read(s, mgr); - fName = s->ReadSafeString_TEMP(); + fName = s->ReadSafeString(); fGroup = s->ReadByte(); fType = s->ReadByte(); fTileset = s->ReadByte(); fSortOrder = s->ReadByte(); - fCustomText = s->ReadSafeString_TEMP(); - fDescription = s->ReadSafeString_TEMP(); + fCustomText = s->ReadSafeString(); + fDescription = s->ReadSafeString(); if (s->ReadBool()) mgr->ReadKeyNotifyMe(s, new plGenRefMsg(GetKey(), plRefMsg::kOnCreate, -1, -1), plRefFlags::kActiveRef); // thumbnail @@ -175,7 +175,7 @@ void plClothingItem::Read(hsStream *s, hsResMgr *mgr) int i, j; for (i = 0; i < tileCount; i++) { - fElementNames.Append(s->ReadSafeString_TEMP()); + fElementNames.Append(s->ReadSafeString()); int layerCount = s->ReadByte(); for (j = 0; j < layerCount; j++) @@ -375,10 +375,10 @@ void plClothingBase::Read(hsStream* s, hsResMgr* mgr) { hsKeyedObject::Read(s, mgr); - fName = s->ReadSafeString_TEMP(); + fName = s->ReadSafeString(); if (s->ReadBool()) mgr->ReadKeyNotifyMe(s, new plGenRefMsg(GetKey(), plRefMsg::kOnCreate, -1, -1), plRefFlags::kActiveRef); - fLayoutName = s->ReadSafeString_TEMP(); + fLayoutName = s->ReadSafeString(); } void plClothingBase::Write(hsStream* s, hsResMgr* mgr) diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarTasks.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarTasks.cpp index 1b62485b..bca53acb 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarTasks.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarTasks.cpp @@ -465,7 +465,7 @@ void plAvAnimTask::LeaveAge(plArmatureMod *avatar) // READ void plAvAnimTask::Read(hsStream *stream, hsResMgr *mgr) { - fAnimName = stream->ReadSafeString_TEMP(); + fAnimName = stream->ReadSafeString(); fInitialBlend = stream->ReadLEScalar(); fTargetBlend = stream->ReadLEScalar(); fFadeSpeed = stream->ReadLEScalar(); @@ -802,8 +802,8 @@ void plAvOneShotLinkTask::Write(hsStream *stream, hsResMgr *mgr) void plAvOneShotLinkTask::Read(hsStream *stream, hsResMgr *mgr) { plAvOneShotTask::Read(stream, mgr); - fAnimName = stream->ReadSafeString_TEMP(); - fMarkerName = stream->ReadSafeString_TEMP(); + fAnimName = stream->ReadSafeString(); + fMarkerName = stream->ReadSafeString(); } void plAvOneShotLinkTask::SetMarkerName(const plString &name) diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plCoopCoordinator.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plCoopCoordinator.cpp index a1671e36..1eb04215 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plCoopCoordinator.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plCoopCoordinator.cpp @@ -398,7 +398,7 @@ void plCoopCoordinator::Read(hsStream *stream, hsResMgr *mgr) else fGuestAcceptMsg = nil; - fSynchBone = stream->ReadSafeString_TEMP(); + fSynchBone = stream->ReadSafeString(); fAutoStartGuest = stream->ReadBool(); fInitiatorID = fHostBrain->GetInitiatorID(); diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plNPCSpawnMod.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plNPCSpawnMod.cpp index d020a7d2..af32fe4c 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plNPCSpawnMod.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plNPCSpawnMod.cpp @@ -128,8 +128,8 @@ void plNPCSpawnMod::Read(hsStream *stream, hsResMgr *mgr) { plSingleModifier::Read(stream, mgr); - fModelName = stream->ReadSafeString_TEMP(); - fAccountName = stream->ReadSafeString_TEMP(); + fModelName = stream->ReadSafeString(); + fAccountName = stream->ReadSafeString(); fAutoSpawn = stream->ReadBool(); if(stream->ReadBool()) fNotify = plNotifyMsg::ConvertNoRef(mgr->ReadCreatable(stream)); diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plOneShotMod.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plOneShotMod.cpp index b06c2071..73267fa2 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plOneShotMod.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plOneShotMod.cpp @@ -154,7 +154,7 @@ void plOneShotMod::Read(hsStream *stream, hsResMgr *mgr) plMultiModifier::Read(stream, mgr); // read in the name of the animation itself - fAnimName = stream->ReadSafeString_TEMP(); + fAnimName = stream->ReadSafeString(); fSeekDuration = stream->ReadLEScalar(); fDrivable = stream->ReadBool(); fReversable = stream->ReadBool(); diff --git a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp index d85cde24..ca9bc63f 100644 --- a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp @@ -89,7 +89,7 @@ void plClientResMgr::ILoadResources(const plFileName& resfile) for (int i = 0; i < num_resources; i++) { plMipmap* res_data = NULL; uint32_t res_size = 0; - plString res_name = in.ReadSafeStringLong_TEMP(); + plString res_name = in.ReadSafeStringLong(); plString res_type = res_name.Substr(res_name.GetSize() - 4, 4); // Version 1 doesn't encode format, so we'll try some simple diff --git a/Sources/Plasma/PubUtilLib/plMessage/plAIMsg.cpp b/Sources/Plasma/PubUtilLib/plMessage/plAIMsg.cpp index 54caa80f..d131b40f 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plAIMsg.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plAIMsg.cpp @@ -68,7 +68,7 @@ void plAIMsg::Read(hsStream* stream, hsResMgr* mgr) { plMessage::IMsgRead(stream, mgr); - fBrainUserStr = stream->ReadSafeString_TEMP(); + fBrainUserStr = stream->ReadSafeString(); } void plAIMsg::Write(hsStream* stream, hsResMgr* mgr) diff --git a/Sources/Plasma/PubUtilLib/plMessage/plAnimCmdMsg.cpp b/Sources/Plasma/PubUtilLib/plMessage/plAnimCmdMsg.cpp index 00f26a4c..be79b06a 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plAnimCmdMsg.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plAnimCmdMsg.cpp @@ -86,8 +86,8 @@ void plAnimCmdMsg::Read(hsStream* stream, hsResMgr* mgr) stream->ReadLE(&fSpeedChangeRate); stream->ReadLE(&fTime); - fAnimName = stream->ReadSafeString_TEMP(); - fLoopName = stream->ReadSafeString_TEMP(); + fAnimName = stream->ReadSafeString(); + fLoopName = stream->ReadSafeString(); } void plAnimCmdMsg::Write(hsStream* stream, hsResMgr* mgr) @@ -134,7 +134,7 @@ void plAGCmdMsg::Read(hsStream* stream, hsResMgr* mgr) stream->ReadLE(&fAmp); stream->ReadLE(&fAmpRate); - fAnimName = stream->ReadSafeString_TEMP(); + fAnimName = stream->ReadSafeString(); } void plAGCmdMsg::Write(hsStream* stream, hsResMgr* mgr) diff --git a/Sources/Plasma/PubUtilLib/plMessage/plAvatarMsg.cpp b/Sources/Plasma/PubUtilLib/plMessage/plAvatarMsg.cpp index 0939486b..66c10785 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plAvatarMsg.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plAvatarMsg.cpp @@ -236,7 +236,7 @@ void plAvSeekMsg::Read(hsStream *stream, hsResMgr *mgr) fDuration = stream->ReadLEScalar(); fSmartSeek = stream->ReadBool(); - fAnimName = stream->ReadSafeString_TEMP(); + fAnimName = stream->ReadSafeString(); fAlignType = static_cast(stream->ReadLE16()); fNoSeek = stream->ReadBool(); fFlags = stream->ReadByte(); @@ -313,7 +313,7 @@ void plAvOneShotMsg::Read(hsStream *stream, hsResMgr *mgr) { plAvSeekMsg::Read(stream, mgr); - fAnimName = stream->ReadSafeString_TEMP(); + fAnimName = stream->ReadSafeString(); fDrivable = stream->ReadBool(); fReversible = stream->ReadBool(); } diff --git a/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.cpp b/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.cpp index ceebb8b4..aeef41aa 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.cpp @@ -216,7 +216,7 @@ void plDynamicTextMsg::Read( hsStream *s, hsResMgr *mgr ) fClearColor.Read( s ); fColor.Read( s ); - fString = s->ReadSafeWString_TEMP(); + fString = s->ReadSafeWString(); fImageKey = mgr->ReadKey( s ); s->ReadLE( &fFlags ); @@ -301,7 +301,7 @@ void plDynamicTextMsg::ReadVersion(hsStream* s, hsResMgr* mgr) if (contentFlags.IsBitSet(kDynTextMsgColor)) fColor.Read( s ); if (contentFlags.IsBitSet(kDynTextMsgString)) - fString = s->ReadSafeWString_TEMP(); + fString = s->ReadSafeWString(); if (contentFlags.IsBitSet(kDynTextMsgImageKey)) fImageKey = mgr->ReadKey( s ); if (contentFlags.IsBitSet(kDynTextMsgFlags)) diff --git a/Sources/Plasma/PubUtilLib/plMessage/plInputIfaceMgrMsg.h b/Sources/Plasma/PubUtilLib/plMessage/plInputIfaceMgrMsg.h index 90cec7ca..9499da28 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plInputIfaceMgrMsg.h +++ b/Sources/Plasma/PubUtilLib/plMessage/plInputIfaceMgrMsg.h @@ -102,9 +102,9 @@ class plInputIfaceMgrMsg : public plMessage plMessage::IMsgRead( s, mgr ); s->ReadLE( &fCommand ); s->ReadLE( &fPageID ); - ageName = s->ReadSafeString_TEMP(); - ageFileName = s->ReadSafeString_TEMP(); - spawnPoint = s->ReadSafeString_TEMP(); + ageName = s->ReadSafeString(); + ageFileName = s->ReadSafeString(); + spawnPoint = s->ReadSafeString(); fAvKey = mgr->ReadKey(s); } diff --git a/Sources/Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.cpp b/Sources/Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.cpp index ad40cd69..f01a4100 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plLinkToAgeMsg.cpp @@ -79,7 +79,7 @@ void plLinkToAgeMsg::Read(hsStream* stream, hsResMgr* mgr) plMessage::IMsgRead( stream, mgr ); fFlags = stream->ReadByte(); fAgeLink.Read( stream, mgr ); - fLinkInAnimName = stream->ReadSafeString_TEMP(); + fLinkInAnimName = stream->ReadSafeString(); } void plLinkToAgeMsg::Write(hsStream* stream, hsResMgr* mgr) @@ -106,7 +106,7 @@ void plLinkToAgeMsg::ReadVersion(hsStream* s, hsResMgr* mgr) if ( contentFlags.IsBitSet( kLinkToAgeAgeLinkStruct ) ) fAgeLink.Read( s, mgr ); if ( contentFlags.IsBitSet( kLinkToAgeLinkAnimName ) ) - fLinkInAnimName = s->ReadSafeString_TEMP(); + fLinkInAnimName = s->ReadSafeString(); } void plLinkToAgeMsg::WriteVersion(hsStream* s, hsResMgr* mgr) diff --git a/Sources/Plasma/PubUtilLib/plMessage/plLoadAgeMsg.cpp b/Sources/Plasma/PubUtilLib/plMessage/plLoadAgeMsg.cpp index 59142bf3..0c607028 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plLoadAgeMsg.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plLoadAgeMsg.cpp @@ -99,7 +99,7 @@ void plLoadAgeMsg::ReadVersion(hsStream* s, hsResMgr* mgr) if (contentFlags.IsBitSet(kLoadAgeAgeName)) { // read agename - fAgeFilename = s->ReadSafeString_TEMP(); + fAgeFilename = s->ReadSafeString(); } if (contentFlags.IsBitSet(kLoadAgeUnload)) diff --git a/Sources/Plasma/PubUtilLib/plMessage/plLoadAvatarMsg.cpp b/Sources/Plasma/PubUtilLib/plMessage/plLoadAvatarMsg.cpp index 3c31673d..d9c82a0c 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plLoadAvatarMsg.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plLoadAvatarMsg.cpp @@ -93,7 +93,7 @@ void plLoadAvatarMsg::Read(hsStream* stream, hsResMgr* mgr) { fInitialTask = plAvTask::ConvertNoRef(mgr->ReadCreatable(stream)); } - fUserStr = stream->ReadSafeString_TEMP(); + fUserStr = stream->ReadSafeString(); } void plLoadAvatarMsg::Write(hsStream *stream, hsResMgr *mgr) @@ -132,7 +132,7 @@ void plLoadAvatarMsg::ReadVersion(hsStream* stream, hsResMgr* mgr) fSpawnPoint = mgr->ReadKey(stream); if (contentFlags.IsBitSet(kLoadAvatarMsgUserStr)) - fUserStr = stream->ReadSafeString_TEMP(); + fUserStr = stream->ReadSafeString(); } void plLoadAvatarMsg::WriteVersion(hsStream* stream, hsResMgr* mgr) diff --git a/Sources/Plasma/PubUtilLib/plMessage/plOneShotCallbacks.cpp b/Sources/Plasma/PubUtilLib/plMessage/plOneShotCallbacks.cpp index 93b27de8..2136648d 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plOneShotCallbacks.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plOneShotCallbacks.cpp @@ -74,7 +74,7 @@ void plOneShotCallbacks::Read(hsStream* stream, hsResMgr* mgr) fCallbacks.reserve(size); for (int i = 0; i < size; i++) { - plString marker = stream->ReadSafeString_TEMP(); + plString marker = stream->ReadSafeString(); plKey receiver = mgr->ReadKey(stream); int16_t user = stream->ReadLE16(); diff --git a/Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.cpp b/Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.cpp index 540b391b..c2141d6a 100644 --- a/Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.cpp +++ b/Sources/Plasma/PubUtilLib/plModifier/plCloneSpawnModifier.cpp @@ -59,7 +59,7 @@ plCloneSpawnModifier::plCloneSpawnModifier() : fExportTime(false) void plCloneSpawnModifier::Read(hsStream *s, hsResMgr *mgr) { - fTemplateName = s->ReadSafeString_TEMP(); + fTemplateName = s->ReadSafeString(); plSingleModifier::Read(s, mgr); } diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plDynamicEnvMap.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plDynamicEnvMap.cpp index facec419..600cb446 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plDynamicEnvMap.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plDynamicEnvMap.cpp @@ -439,7 +439,7 @@ void plDynamicEnvMap::Read(hsStream* s, hsResMgr* mgr) nVis = s->ReadLE32(); for( i = 0; i < nVis; i++) { - plKey key = plKeyFinder::Instance().StupidSearch("", "", plVisRegion::Index(), s->ReadSafeString_TEMP()); + plKey key = plKeyFinder::Instance().StupidSearch("", "", plVisRegion::Index(), s->ReadSafeString()); if (key) hsgResMgr::ResMgr()->AddViaNotify(key, new plGenRefMsg(GetKey(), plRefMsg::kOnCreate, -1, kRefVisSet), plRefFlags::kActiveRef); } @@ -928,7 +928,7 @@ void plDynamicCamMap::Read(hsStream* s, hsResMgr* mgr) nVis = s->ReadLE32(); for( i = 0; i < nVis; i++) { - plKey key = plKeyFinder::Instance().StupidSearch("", "", plVisRegion::Index(), s->ReadSafeString_TEMP()); + plKey key = plKeyFinder::Instance().StupidSearch("", "", plVisRegion::Index(), s->ReadSafeString()); if (key) hsgResMgr::ResMgr()->AddViaNotify(key, new plGenRefMsg(GetKey(), plRefMsg::kOnCreate, -1, kRefVisSet), plRefFlags::kActiveRef); } diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plPageInfo.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plPageInfo.cpp index bcef4faf..62de2b4f 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plPageInfo.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plPageInfo.cpp @@ -133,10 +133,10 @@ void plPageInfo::Read( hsStream *s ) if (version >= 5) { fLocation.Read( s ); - fAge = s->ReadSafeString_TEMP(); + fAge = s->ReadSafeString(); if (version < 6) - s->ReadSafeString_TEMP(); // fChapter was never used, and always "District". - fPage = s->ReadSafeString_TEMP(); + s->ReadSafeString(); // fChapter was never used, and always "District". + fPage = s->ReadSafeString(); s->ReadLE( &fMajorVersion ); diff --git a/Sources/Plasma/PubUtilLib/plSDL/plStateDataRecord.cpp b/Sources/Plasma/PubUtilLib/plSDL/plStateDataRecord.cpp index 894e77d9..d42bc664 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plStateDataRecord.cpp +++ b/Sources/Plasma/PubUtilLib/plSDL/plStateDataRecord.cpp @@ -403,7 +403,7 @@ bool plStateDataRecord::ReadStreamHeader(hsStream* s, plString* name, int* versi return false; // bad version } - *name = s->ReadSafeString_TEMP(); + *name = s->ReadSafeString(); *version = s->ReadLE16(); if (objUoid) diff --git a/Sources/Plasma/PubUtilLib/plSDL/plStateDescriptor.cpp b/Sources/Plasma/PubUtilLib/plSDL/plStateDescriptor.cpp index 7adcadbd..2c614e75 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plStateDescriptor.cpp +++ b/Sources/Plasma/PubUtilLib/plSDL/plStateDescriptor.cpp @@ -94,7 +94,7 @@ bool plStateDescriptor::Read(hsStream* s) IDeInit(); - fName = s->ReadSafeString_TEMP(); + fName = s->ReadSafeString(); uint16_t version=s->ReadLE16(); fVersion=version; diff --git a/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp b/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp index 8d53532c..e4796954 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp +++ b/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp @@ -107,7 +107,7 @@ public: void plStateVarNotificationInfo::Read(hsStream* s, uint32_t readOptions) { uint8_t saveFlags=s->ReadByte(); // unused - plString hint=s->ReadSafeString_TEMP(); + plString hint=s->ReadSafeString(); if (!hint.IsNull() && !(readOptions & plSDL::kSkipNotificationInfo)) fHintString = hint; } diff --git a/Sources/Plasma/PubUtilLib/plSDL/plVarDescriptor.cpp b/Sources/Plasma/PubUtilLib/plSDL/plVarDescriptor.cpp index 16a61076..659da039 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plVarDescriptor.cpp +++ b/Sources/Plasma/PubUtilLib/plSDL/plVarDescriptor.cpp @@ -157,7 +157,7 @@ bool plVarDescriptor::Read(hsStream* s) return false; } - fName=s->ReadSafeString_TEMP(); + fName=s->ReadSafeString(); plMsgStdStringHelper::Peek(fDisplayOptions, s); @@ -165,7 +165,7 @@ bool plVarDescriptor::Read(hsStream* s) fType=(Type)s->ReadByte(); - fDefault = s->ReadSafeString_TEMP(); + fDefault = s->ReadSafeString(); fFlags = s->ReadLE32(); return true; @@ -372,7 +372,7 @@ bool plSDVarDescriptor::Read(hsStream* s) if (!plVarDescriptor::Read(s)) return false; - plString sdName=s->ReadSafeString_TEMP(); + plString sdName=s->ReadSafeString(); uint16_t version = s->ReadLE16(); plStateDescriptor* sd=plSDLMgr::GetInstance()->FindDescriptor(sdName, version); hsAssert( sd, plString::Format("Failed to find sdl descriptor: %s,%d. Missing legacy descriptor?", sdName.c_str(), version ).c_str() ); diff --git a/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.cpp b/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.cpp index 64222131..5ce7d649 100644 --- a/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.cpp +++ b/Sources/Plasma/PubUtilLib/plSurface/plLayerAnimation.cpp @@ -736,7 +736,7 @@ void plLayerSDLAnimation::Read(hsStream* s, hsResMgr* mgr) { plLayerAnimationBase::Read(s, mgr); - fVarName = s->ReadSafeString_TEMP(); + fVarName = s->ReadSafeString(); } void plLayerSDLAnimation::Write(hsStream* s, hsResMgr* mgr) diff --git a/Sources/Tools/MaxComponent/plMultistageStage.cpp b/Sources/Tools/MaxComponent/plMultistageStage.cpp index 871a259d..847c6a00 100644 --- a/Sources/Tools/MaxComponent/plMultistageStage.cpp +++ b/Sources/Tools/MaxComponent/plMultistageStage.cpp @@ -96,7 +96,7 @@ plString plBaseStage::GetName() void plBaseStage::Read(hsStream *stream) { stream->ReadLE16(); - fName = stream->ReadSafeString_TEMP(); + fName = stream->ReadSafeString(); } void plBaseStage::Write(hsStream *stream) @@ -137,7 +137,7 @@ void plStandardStage::Read(hsStream *stream) uint16_t version = stream->ReadLE16(); - fAnimName = stream->ReadSafeString_TEMP(); + fAnimName = stream->ReadSafeString(); fNumLoops = stream->ReadLE32(); fLoopForever = stream->ReadBool(); fForward = stream->ReadByte(); From 249f26c53ff454ea7cafb751b18d7f6fea1de592 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 29 Dec 2013 22:48:47 -0500 Subject: [PATCH 12/15] plString Hash for unordered containers --- Sources/Plasma/CoreLib/plString.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Sources/Plasma/CoreLib/plString.h b/Sources/Plasma/CoreLib/plString.h index 33fd8bbc..b054b679 100644 --- a/Sources/Plasma/CoreLib/plString.h +++ b/Sources/Plasma/CoreLib/plString.h @@ -598,6 +598,35 @@ public: static plString Fill(size_t count, char c); public: + /** Functor that hashes a string for unordered containers. + * \note The hash is case sensitive. + */ + struct hash + { + size_t operator()(const plString& str) const + { + uint32_t hash = 0; + for (size_t i = 0; i < str.GetSize(); ++i) { + hash += str.CharAt(i); + hash += (hash << 10); + hash ^= (hash >> 6); + } + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + return hash; + } + }; + + /** Functor that hashes a string for unordered containers. + * \remarks This returns the hash of the lower-case variant of the string. + */ + struct hash_i : hash + { + size_t operator()(const plString& str) const + { return hash::operator()(str.ToLower()); } + }; + /** Functor which compares two strings case-insensitively for sorting. */ struct less_i { From b10795b9cb9f56f2efd78efb2b412d9501a4073a Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 7 Jan 2014 23:17:00 -0500 Subject: [PATCH 13/15] Convert plClientResMgr to plString DIE std::string DIE!!! --- .../plClientResMgr/plClientResMgr.cpp | 18 ++++++++---------- .../PubUtilLib/plClientResMgr/plClientResMgr.h | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp index ca9bc63f..bfa3795b 100644 --- a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp @@ -41,6 +41,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "HeadSpin.h" +#include #include "hsStream.h" #include "hsResMgr.h" @@ -61,9 +62,7 @@ plClientResMgr& plClientResMgr::Instance(void) plClientResMgr::~plClientResMgr() { - std::map::iterator it; - - for (it = ClientResources.begin(); it != ClientResources.end(); ++it) { + for (auto it = ClientResources.begin(); it != ClientResources.end(); ++it) { if (it->second) it->second->UnRef(); } @@ -71,9 +70,8 @@ plClientResMgr::~plClientResMgr() void plClientResMgr::ILoadResources(const plFileName& resfile) { - if (!resfile.IsValid()) { + if (!resfile.IsValid()) return; - } hsUNIXStream in; @@ -87,19 +85,19 @@ void plClientResMgr::ILoadResources(const plFileName& resfile) num_resources = in.ReadLE32(); for (int i = 0; i < num_resources; i++) { - plMipmap* res_data = NULL; + plMipmap* res_data = nullptr; uint32_t res_size = 0; plString res_name = in.ReadSafeStringLong(); - plString res_type = res_name.Substr(res_name.GetSize() - 4, 4); + plString extension = plFileName(res_name).GetFileExt(); // Version 1 doesn't encode format, so we'll try some simple // extension sniffing - if (res_type == ".png") { + if (extension == "png") { // Read resource stream size, but the PNG has that info in the header // so it's not needed res_size = in.ReadLE32(); res_data = plPNG::Instance().ReadFromStream(&in); - } else if (res_type == ".jpg") { + } else if (extension == "jpg") { // Don't read resource stream size, as plJPEG's reader will need it res_data = plJPEG::Instance().ReadFromStream(&in); } else { @@ -126,7 +124,7 @@ void plClientResMgr::ILoadResources(const plFileName& resfile) plMipmap* plClientResMgr::getResource(const plString& resname) { plMipmap* resmipmap = nullptr; - std::map::iterator it = ClientResources.find(resname); + auto it = ClientResources.find(resname); if (it != ClientResources.end()) { resmipmap = it->second; diff --git a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h index 1dc2e241..5738f393 100644 --- a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h +++ b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h @@ -43,7 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #ifndef _plClientResMgr_h #define _plClientResMgr_h -#include +#include class plMipmap; class plString; @@ -51,7 +51,7 @@ class plFileName; class plClientResMgr { protected: - std::map ClientResources; + std::unordered_map ClientResources; public: plClientResMgr() { } From 9e0330feeaf4dd9542de30f268e5530c468b4278 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 11 Jan 2014 19:53:32 -0500 Subject: [PATCH 14/15] Plate resource plString --- .../Plasma/PubUtilLib/plPipeline/plPlates.cpp | 8 ++--- .../Plasma/PubUtilLib/plPipeline/plPlates.h | 4 +-- .../plProgressMgr/plProgressMgr.cpp | 29 +++++++------------ .../PubUtilLib/plProgressMgr/plProgressMgr.h | 10 +++---- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plPlates.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plPlates.cpp index 63f0009c..83fae06d 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plPlates.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plPlates.cpp @@ -238,9 +238,9 @@ plMipmap *plPlate::CreateMaterial( uint32_t width, uint32_t height, bool with //// CreateFromResource ////////////////////////////////////////////////////// // Creates a plate's material from a resource of the given name. -void plPlate::CreateFromResource(const char *resName) +void plPlate::CreateFromResource(const plString& resName) { - if (resName) + if (!resName.IsEmpty()) { plMipmap* resTexture = new plMipmap; resTexture->CopyFrom(plClientResMgr::Instance().getResource(resName)); @@ -256,9 +256,9 @@ void plPlate::CreateFromResource(const char *resName) } } -void plPlate::ReloadFromResource(const char *resName) +void plPlate::ReloadFromResource(const plString& resName) { - if (resName) + if (!resName.IsEmpty()) { fMipmap->CopyFrom(plClientResMgr::Instance().getResource(resName)); } diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plPlates.h b/Sources/Plasma/PubUtilLib/plPipeline/plPlates.h index 8513f0e7..dc993a4d 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plPlates.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/plPlates.h @@ -144,8 +144,8 @@ class plPlate void SetSize( float width, float height, bool adjustByAspectRatio = false ); plMipmap *CreateMaterial( uint32_t width, uint32_t height, bool withAlpha, plMipmap* texture = NULL ); - void CreateFromResource( const char *resName ); - void ReloadFromResource( const char *resName ); + void CreateFromResource(const plString& resName); + void ReloadFromResource(const plString& resName); }; //// plGraphPlate Class Definition /////////////////////////////////////////// diff --git a/Sources/Plasma/PubUtilLib/plProgressMgr/plProgressMgr.cpp b/Sources/Plasma/PubUtilLib/plProgressMgr/plProgressMgr.cpp index a0af9574..beea394d 100644 --- a/Sources/Plasma/PubUtilLib/plProgressMgr/plProgressMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plProgressMgr/plProgressMgr.cpp @@ -60,14 +60,14 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com //// plProgressMgr Functions ///////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -plProgressMgr *plProgressMgr::fManager = nil; +plProgressMgr* plProgressMgr::fManager = nullptr; #define LOADING_RES "xLoading_Linking.%02d.png" #define LOADING_RES_COUNT 18 -char* plProgressMgr::fImageRotation[LOADING_RES_COUNT]; +plString plProgressMgr::fImageRotation[LOADING_RES_COUNT]; -const char* plProgressMgr::fStaticTextIDs[] = { +const plString plProgressMgr::fStaticTextIDs[] = { "xLoading_Linking_Text.png", "xLoading_Updating_Text.png" }; @@ -76,30 +76,21 @@ const char* plProgressMgr::fStaticTextIDs[] = { plProgressMgr::plProgressMgr() { - fOperations = nil; + fOperations = nullptr; fManager = this; - fCallbackProc = nil; + fCallbackProc = nullptr; fCurrentStaticText = kNone; // Fill array with pre-computed loading frame IDs for (int i=0; i < LOADING_RES_COUNT; i++) - { - char* frameID = new char[128]; - sprintf(frameID, LOADING_RES, i); - fImageRotation[i] = frameID; - } + fImageRotation[i] = plString::Format(LOADING_RES, i); } plProgressMgr::~plProgressMgr() { - for (int i=0; i < LOADING_RES_COUNT; i++) - { - delete[] fImageRotation[i]; - } - - while( fOperations != nil ) + while (fOperations) delete fOperations; - fManager = nil; + fManager = nullptr; } //// RegisterOperation /////////////////////////////////////////////////////// @@ -238,7 +229,7 @@ void plProgressMgr::CancelAllOps( void ) fCurrentStaticText = kNone; } -char* plProgressMgr::GetLoadingFrameID(int index) +const plString plProgressMgr::GetLoadingFrameID(int index) { if (index < LOADING_RES_COUNT) return fImageRotation[index]; @@ -251,7 +242,7 @@ uint32_t plProgressMgr::NumLoadingFrames() const return LOADING_RES_COUNT; } -const char* plProgressMgr::GetStaticTextID(StaticText staticTextType) +const plString plProgressMgr::GetStaticTextID(StaticText staticTextType) { return fStaticTextIDs[staticTextType]; } diff --git a/Sources/Plasma/PubUtilLib/plProgressMgr/plProgressMgr.h b/Sources/Plasma/PubUtilLib/plProgressMgr/plProgressMgr.h index 7e3cfeac..903d07fb 100644 --- a/Sources/Plasma/PubUtilLib/plProgressMgr/plProgressMgr.h +++ b/Sources/Plasma/PubUtilLib/plProgressMgr/plProgressMgr.h @@ -201,9 +201,9 @@ class plProgressMgr private: - static plProgressMgr *fManager; - static char* fImageRotation[]; - static const char* fStaticTextIDs[]; + static plProgressMgr* fManager; + static plString fImageRotation[]; + static const plString fStaticTextIDs[]; protected: @@ -235,9 +235,9 @@ class plProgressMgr virtual ~plProgressMgr(); static plProgressMgr* GetInstance() { return fManager; } - static char* GetLoadingFrameID(int index); + static const plString GetLoadingFrameID(int index); uint32_t plProgressMgr::NumLoadingFrames() const; - static const char* GetStaticTextID(StaticText staticTextType); + static const plString GetStaticTextID(StaticText staticTextType); virtual void Draw( plPipeline *p ) { } From 387e23061a616d165cbee69fda94f6183fb94737 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Thu, 16 Jan 2014 18:25:10 -0800 Subject: [PATCH 15/15] Minor changes to hash and hash_i to avoid making a copy of the string data --- Sources/Plasma/CoreLib/plString.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Sources/Plasma/CoreLib/plString.h b/Sources/Plasma/CoreLib/plString.h index b054b679..89a41ad6 100644 --- a/Sources/Plasma/CoreLib/plString.h +++ b/Sources/Plasma/CoreLib/plString.h @@ -48,6 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include #include +#include #include /** Single Unicode character code unit */ @@ -603,11 +604,13 @@ public: */ struct hash { + // TODO: This doesn't really use enough bits to be useful when + // size_t is 64-bits. size_t operator()(const plString& str) const { - uint32_t hash = 0; + size_t hash = 0; for (size_t i = 0; i < str.GetSize(); ++i) { - hash += str.CharAt(i); + hash += fetch_char(str, i); hash += (hash << 10); hash ^= (hash >> 6); } @@ -616,15 +619,20 @@ public: hash += (hash << 15); return hash; } + + protected: + virtual char fetch_char(const plString& str, size_t index) const + { return str.CharAt(index); } }; /** Functor that hashes a string for unordered containers. * \remarks This returns the hash of the lower-case variant of the string. */ - struct hash_i : hash + struct hash_i : public hash { - size_t operator()(const plString& str) const - { return hash::operator()(str.ToLower()); } + protected: + virtual char fetch_char(const plString& str, size_t index) const + { return tolower(str.CharAt(index)); } }; /** Functor which compares two strings case-insensitively for sorting. */