diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index 2ef6ae8a38..7b253b1e7b 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -495,19 +495,17 @@ bool plClient::InitPipeline(hsWindowHndl display, uint32_t devType) } plPipeline *pipe = ICreatePipeline(display, fWindowHndl, &dmr); - if (pipe->GetErrorString() != nullptr) - { + if (!pipe->GetErrorString().empty()) { ISetGraphicsDefaults(); #ifdef PLASMA_EXTERNAL_RELEASE hsMessageBox(ST_LITERAL("There was an error initializing the video card.\nSetting defaults."), ST_LITERAL("Error"), hsMessageBoxNormal); #else - hsMessageBox(ST::string(pipe->GetErrorString()), ST_LITERAL("Error creating pipeline"), hsMessageBoxNormal); + hsMessageBox(pipe->GetErrorString(), ST_LITERAL("Error creating pipeline"), hsMessageBoxNormal); #endif delete pipe; devSel.GetDefault(&dmr); pipe = ICreatePipeline(display, fWindowHndl, &dmr); - if (pipe->GetErrorString() != nullptr) - { + if (!pipe->GetErrorString().empty()) { // not much else we can do return true; } @@ -1617,7 +1615,7 @@ bool plClient::IUpdate() plgDispatch::MsgSend(eval); plProfile_EndTiming(EvalMsg); - const char *xFormLap1 = "Main"; + const ST::string xFormLap1 = ST_LITERAL("Main"); plProfile_BeginLap(TransformMsg, xFormLap1); plTransformMsg* xform = new plTransformMsg(nullptr, nullptr, nullptr, nullptr); plgDispatch::MsgSend(xform); @@ -1635,7 +1633,7 @@ bool plClient::IUpdate() // At this point, we just register for a plDelayedTransformMsg when dirtied. if (!plCoordinateInterface::GetDelayedTransformsEnabled()) { - const char *xFormLap2 = "Simulation"; + const ST::string xFormLap2 = ST_LITERAL("Simulation"); plProfile_BeginLap(TransformMsg, xFormLap2); xform = new plTransformMsg(nullptr, nullptr, nullptr, nullptr); plgDispatch::MsgSend(xform); @@ -1643,7 +1641,7 @@ bool plClient::IUpdate() } else { - const char *xFormLap3 = "Delayed"; + const ST::string xFormLap3 = ST_LITERAL("Delayed"); plProfile_BeginLap(TransformMsg, xFormLap3); xform = new plDelayedTransformMsg(nullptr, nullptr, nullptr, nullptr); plgDispatch::MsgSend(xform); diff --git a/Sources/Plasma/FeatureLib/pfAnimation/plFollowMod.cpp b/Sources/Plasma/FeatureLib/pfAnimation/plFollowMod.cpp index f2d5835656..ba6b9c4827 100644 --- a/Sources/Plasma/FeatureLib/pfAnimation/plFollowMod.cpp +++ b/Sources/Plasma/FeatureLib/pfAnimation/plFollowMod.cpp @@ -72,11 +72,11 @@ bool plFollowMod::MsgReceive(plMessage* msg) plRenderMsg* rend = plRenderMsg::ConvertNoRef(msg); if( rend ) { - plProfile_BeginLap(FollowMod, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(FollowMod, this->GetKey()->GetUoid().GetObjectName()); fLeaderL2W = rend->Pipeline()->GetCameraToWorld(); fLeaderW2L = rend->Pipeline()->GetWorldToCamera(); fLeaderSet = true; - plProfile_EndLap(FollowMod, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(FollowMod, this->GetKey()->GetUoid().GetObjectName()); return true; } plListenerMsg* list = plListenerMsg::ConvertNoRef(msg); diff --git a/Sources/Plasma/FeatureLib/pfAnimation/plLineFollowMod.cpp b/Sources/Plasma/FeatureLib/pfAnimation/plLineFollowMod.cpp index 4b4b76ea8d..9d66452ad2 100644 --- a/Sources/Plasma/FeatureLib/pfAnimation/plLineFollowMod.cpp +++ b/Sources/Plasma/FeatureLib/pfAnimation/plLineFollowMod.cpp @@ -243,11 +243,11 @@ bool plLineFollowMod::MsgReceive(plMessage* msg) plRenderMsg* rend = plRenderMsg::ConvertNoRef(msg); if( rend ) { - plProfile_BeginLap(LineFollow, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(LineFollow, this->GetKey()->GetUoid().GetObjectName()); hsPoint3 oldPos = fSearchPos; fSearchPos = rend->Pipeline()->GetViewPositionWorld(); ICheckForPop(oldPos, fSearchPos); - plProfile_EndLap(LineFollow, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(LineFollow, this->GetKey()->GetUoid().GetObjectName()); return true; } plListenerMsg* list = plListenerMsg::ConvertNoRef(msg); diff --git a/Sources/Plasma/FeatureLib/pfAnimation/plViewFaceModifier.cpp b/Sources/Plasma/FeatureLib/pfAnimation/plViewFaceModifier.cpp index 9aec6d9eb0..3f892bd773 100644 --- a/Sources/Plasma/FeatureLib/pfAnimation/plViewFaceModifier.cpp +++ b/Sources/Plasma/FeatureLib/pfAnimation/plViewFaceModifier.cpp @@ -274,7 +274,7 @@ bool plViewFaceModifier::MsgReceive(plMessage* msg) if( rend ) { - plProfile_BeginLap(ViewFace, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(ViewFace, this->GetKey()->GetUoid().GetObjectName()); if( HasFlag(kFaceCam) ) { @@ -310,7 +310,7 @@ bool plViewFaceModifier::MsgReceive(plMessage* msg) IFacePoint(rend->Pipeline(), fFacePoint); - plProfile_EndLap(ViewFace, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(ViewFace, this->GetKey()->GetUoid().GetObjectName()); return true; } plArmatureUpdateMsg* armMsg = plArmatureUpdateMsg::ConvertNoRef(msg); diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp index 7f3f96dd34..677f57047b 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp @@ -480,13 +480,12 @@ PF_CONSOLE_CMD( Stats, Show, // Group name, Function name "Shows or hides a given category of statistics.\n" "List the valid categories using Stats.ListGroups") { - const ST::string& group = numParams > 0 ? params[0] : ST::string(); - if (numParams > 1) { - const ST::string& stat = params[1]; - plProfileManagerFull::Instance().ShowLaps(group.c_str(), stat.c_str()); + plProfileManagerFull::Instance().ShowLaps(params[0], params[1]); + } else if (numParams > 0) { + plProfileManagerFull::Instance().ShowGroup(params[0]); } else { - plProfileManagerFull::Instance().ShowGroup(group.c_str()); + plProfileManagerFull::Instance().ShowGroup(ST_LITERAL("General")); } } @@ -506,9 +505,7 @@ PF_CONSOLE_CMD(Stats, ShowLaps, "string group, string stat", "") { - const ST::string& group = params[0]; - const ST::string& stat = params[1]; - plProfileManagerFull::Instance().ShowLaps(group.c_str(), stat.c_str()); + plProfileManagerFull::Instance().ShowLaps(params[0], params[1]); } PF_CONSOLE_CMD(Stats, ListGroups, "", "Prints the names of all the stat groups to the console") @@ -554,8 +551,7 @@ PF_CONSOLE_CMD(Stats, SetAvgTime, "int ms", "Sets the amount of time stats are a PF_CONSOLE_CMD(Stats, Graph, "string stat, int min, int max", "Graphs the specified stat") { - const ST::string& stat = params[0]; - plProfileManagerFull::Instance().CreateGraph(stat.c_str(), (int)params[1], (int)params[2]); + plProfileManagerFull::Instance().CreateGraph(params[0], (int)params[1], (int)params[2]); } PF_CONSOLE_CMD(Stats, ShowDetail, "", "Shows the detail stat graph") @@ -575,36 +571,31 @@ PF_CONSOLE_CMD(Stats, ResetDetailDefaults, "", "Resets the detail graph's defaul PF_CONSOLE_CMD(Stats, AddDetailVar, "string stat", "Adds the specified var to the detail graph with the default range of 0->100") { - const ST::string& stat = params[0]; - plProfileManagerFull::Instance().AddDetailVar(stat.c_str(), 0, 100); + plProfileManagerFull::Instance().AddDetailVar(params[0], 0, 100); } PF_CONSOLE_CMD(Stats, AddDetailVarWithOffset, "string stat, int offset", "Adds the specified var to the detail graph with a offset and default range\n" "of 0->(100-offset)") { - const ST::string& stat = params[0]; int offset = (int)params[1]; - plProfileManagerFull::Instance().AddDetailVar(stat.c_str(), -offset, 100-offset); + plProfileManagerFull::Instance().AddDetailVar(params[0], -offset, 100-offset); } PF_CONSOLE_CMD(Stats, AddDetailVarWithRange, "string stat, int min, int max", "Adds the specified var to the detail graph") { - const ST::string& stat = params[0]; - plProfileManagerFull::Instance().AddDetailVar(stat.c_str(), (int)params[1], (int)params[2]); + plProfileManagerFull::Instance().AddDetailVar(params[0], (int)params[1], (int)params[2]); } PF_CONSOLE_CMD(Stats, AddDetailVarWithOffsetAndRange, "string stat, int offset, int min, int max", "Adds the specified var to the detail graph with an\n" "offset and a range of min->(max-offset)") { - const ST::string& stat = params[0]; int offset = (int)params[1]; - plProfileManagerFull::Instance().AddDetailVar(stat.c_str(), (int)params[2]-offset, (int)params[3]-offset); + plProfileManagerFull::Instance().AddDetailVar(params[0], (int)params[2]-offset, (int)params[3]-offset); } PF_CONSOLE_CMD(Stats, RemoveDetailVar, "string stat", "Removes the specified var from the detail graph") { - const ST::string& stat = params[0]; - plProfileManagerFull::Instance().RemoveDetailVar(stat.c_str()); + plProfileManagerFull::Instance().RemoveDetailVar(params[0]); } diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.cpp index 7d795c863a..0722bfbb4f 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.cpp @@ -52,8 +52,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plDXVertexShader.h" #include "plDXPixelShader.h" +#include + //// Macros for D3D error handling -#define INIT_ERROR_CHECK( cond, errMsg ) if( FAILED( fPipeline->fSettings.fDXError = cond ) ) { return fPipeline->ICreateFail( errMsg ); } +#define INIT_ERROR_CHECK(cond, errMsg) if (FAILED(fSettings.fDXError = cond)) { return ICreateFail(ST_LITERAL(errMsg)); } #if 1 // DEBUG #define STRONG_ERROR_CHECK( cond ) if( FAILED( fPipeline->fSettings.fDXError = cond ) ) { fPipeline->IGetD3DError(); fPipeline->IShowErrorMessage(); } @@ -189,7 +191,7 @@ void plDXDevice::SetLocalToWorldMatrix(const hsMatrix44& src) fD3DDevice->SetTransform(D3DTS_WORLD, &mat); } -const char* plDXDevice::GetErrorString() const +ST::string plDXDevice::GetErrorString() const { return fPipeline->fSettings.fErrorStr; } diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.h b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.h index ed62c19808..f34354760b 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.h +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.h @@ -54,6 +54,7 @@ class plDXPipeline; class plRenderTarget; struct IDirect3DDevice9; struct IDirect3DSurface9; +namespace ST { class string; } class plDXDevice { @@ -98,7 +99,7 @@ class plDXDevice void SetWorldToCameraMatrix(const hsMatrix44& src); void SetLocalToWorldMatrix(const hsMatrix44& src); - const char* GetErrorString() const; + ST::string GetErrorString() const; }; #endif diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDeviceRefs.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDeviceRefs.cpp index 9a2922bf01..a0b7606ba7 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDeviceRefs.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXDeviceRefs.cpp @@ -144,7 +144,7 @@ void plDXVertexBufferRef::Release() if (!Volatile()) { plProfile_DelMem(MemVertex, fCount * fVertexSize); - PROFILE_POOL_MEM(D3DPOOL_MANAGED, fCount * fVertexSize, false, "VtxBuff"); + PROFILE_POOL_MEM(D3DPOOL_MANAGED, fCount * fVertexSize, false, ST_LITERAL("VtxBuff")); plDXPipeline::FreeManagedVertex(fCount * fVertexSize); } } @@ -159,7 +159,7 @@ void plDXIndexBufferRef::Release() if (fD3DBuffer != nullptr) { plProfile_DelMem(MemIndex, fCount * sizeof(uint16_t)); - PROFILE_POOL_MEM(fPoolType, fCount * sizeof(uint16_t), false, "IndexBuff"); + PROFILE_POOL_MEM(fPoolType, fCount * sizeof(uint16_t), false, ST_LITERAL("IndexBuff")); ReleaseObject( fD3DBuffer ); } @@ -221,7 +221,7 @@ void plDXTextureRef::Release() { plProfile_DelMem(MemTexture, fDataSize + sizeof(plDXTextureRef)); plProfile_Extern(ManagedMem); - PROFILE_POOL_MEM(D3DPOOL_MANAGED, fDataSize, false, (fOwner ? fOwner->GetKey() ? fOwner->GetKey()->GetUoid().GetObjectName().c_str() : "(UnknownTexture)" : "(UnknownTexture)")); + PROFILE_POOL_MEM(D3DPOOL_MANAGED, fDataSize, false, fOwner && fOwner->GetKey() ? fOwner->GetKey()->GetUoid().GetObjectName() : ST_LITERAL("(UnknownTexture)")); plDXPipeline::FreeManagedTexture(fDataSize); fDataSize = 0; diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.cpp index 23b9525667..ca5f504f0a 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.cpp @@ -110,15 +110,17 @@ bool hsGDirect3DTnLEnumerate::SelectFromDevMode(const hsG3DDeviceRecord* devRec, D3DEnum_SelectDefaultDisplay(0); if( !GetCurrentDisplay() || !GetCurrentRenderer() ) { - if( !*GetEnumeErrorStr() ) - SetEnumeErrorStr("Error finding device"); + if (GetEnumeErrorStr().empty()) { + fEnumeErrorStr = ST_LITERAL("Error finding device"); + } return true; } D3DEnum_SelectDefaultMode(width, height, colorDepth); if( !GetCurrentMode() ) { - if( !*GetEnumeErrorStr() ) - SetEnumeErrorStr("Error finding mode"); + if (GetEnumeErrorStr().empty()) { + fEnumeErrorStr = ST_LITERAL("Error finding mode"); + } return true; } @@ -260,8 +262,6 @@ HRESULT hsGDirect3DTnLEnumerate::D3DEnum_SelectDefaultDisplay( DWORD dwFlags ) hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate() { - memset( &fEnumeErrorStr[0], 0x00, sizeof(fEnumeErrorStr) ); - fCurrentDisplay = nullptr; // The selected DD driver fDisplays.clear(); // List of DD drivers @@ -269,7 +269,7 @@ hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate() IDirect3D9* pD3D = hsGDirect3D::GetDirect3D(); if (!pD3D) { - strcpy( fEnumeErrorStr, "Cannot load DirectX!" ); + fEnumeErrorStr = ST_LITERAL("Cannot load DirectX!"); return; } @@ -285,8 +285,8 @@ hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate() pD3D->GetAdapterDisplayMode(iAdapter, &newDriver.fDesktopMode); newDriver.fAdapterInfo = adapterInfo; - strncpy(newDriver.fStrName, adapterInfo.Driver, 39); - strncpy(newDriver.fStrDesc, adapterInfo.Description, 39); + newDriver.fStrName = ST::string::from_latin_1(adapterInfo.Driver); + newDriver.fStrDesc = ST::string::from_latin_1(adapterInfo.Description); newDriver.fGuid = adapterInfo.DeviceIdentifier; newDriver.fMemory = 16 * 1024 * 1024; /// Simulate 16 MB @@ -307,7 +307,7 @@ void hsGDirect3DTnLEnumerate::IEnumAdapterDevices( IDirect3D9 *pD3D, UINT iAd // Then we can enum through the modes for each format. const DWORD numDeviceTypes = 2; - const TCHAR* strDeviceDescs[] = { "HAL", "REF" }; + const ST::string strDeviceDescs[] = {ST_LITERAL("HAL"), ST_LITERAL("REF")}; const D3DDEVTYPE deviceTypes[] = { D3DDEVTYPE_HAL, D3DDEVTYPE_REF }; BOOL *formatWorks = new BOOL[kNumDisplayFormats + 1]; // One for each format @@ -318,7 +318,7 @@ void hsGDirect3DTnLEnumerate::IEnumAdapterDevices( IDirect3D9 *pD3D, UINT iAd D3DEnum_RendererInfo& deviceInfo = drivInfo->fRenderers.emplace_back(); pD3D->GetDeviceCaps(iAdapter, deviceTypes[iDevice], &deviceInfo.fDDCaps); - strncpy(deviceInfo.fStrName, strDeviceDescs[iDevice], 39); + deviceInfo.fStrName = strDeviceDescs[iDevice]; deviceInfo.fDDType = deviceTypes[iDevice]; deviceInfo.fIsHardware = deviceInfo.fDDCaps.DevCaps & D3DDEVCAPS_HWRASTERIZATION; @@ -408,7 +408,7 @@ void hsGDirect3DTnLEnumerate::IEnumAdapterDevices( IDirect3D9 *pD3D, UINT iAd /// Add it to our driver's global mode list D3DEnum_ModeInfo& modeInfo = drivInfo->fModes.emplace_back(); modeInfo.fDDmode = dispMode; - sprintf(modeInfo.fStrDesc, TEXT("%ld x %ld x %ld"), dispMode.Width, dispMode.Height, bitDepth); + modeInfo.fStrDesc = ST::format("{} x {} x {}", dispMode.Width, dispMode.Height, bitDepth); modeInfo.fBitDepth = bitDepth; // Add it to the device @@ -434,7 +434,7 @@ void hsGDirect3DTnLEnumerate::IEnumAdapterDevices( IDirect3D9 *pD3D, UINT iAd pModeInfo.fDDmode = dispMode; pModeInfo.fDDBehavior = behavior[iFormat]; pModeInfo.fBitDepth = bitDepth; - sprintf(pModeInfo.fStrDesc, TEXT("Windowed")); + pModeInfo.fStrDesc = ST_LITERAL("Windowed"); pModeInfo.fWindowed = true; IFindDepthFormats(pD3D, iAdapter, deviceInfo.fDDType, &pModeInfo); @@ -556,15 +556,6 @@ VOID hsGDirect3DTnLEnumerate::D3DEnum_FreeResources() { } -//----------------------------------------------------------------------------- -// Name: SetEnumeErrorStr() -// Desc: -//----------------------------------------------------------------------------- -void hsGDirect3DTnLEnumerate::SetEnumeErrorStr(const char* s) -{ - hsStrncpy(fEnumeErrorStr, s, 128); -} - //// IGetDXBitDepth ////////////////////////////////////////////////////////// // // From a D3DFORMAT enumeration, return the bit depth associated with it. @@ -602,7 +593,7 @@ bool hsG3DDeviceSelector::IGetD3DCardInfo( hsG3DDeviceRecord &record, void *driverInfo, void *deviceInfo, uint32_t *vendorID, uint32_t *deviceID, // Out - char **driverString, char **descString ) + ST::string& driverString, ST::string& descString) { D3DEnum_DisplayInfo *driverD3DInfo = (D3DEnum_DisplayInfo *)driverInfo; D3DEnum_RendererInfo *deviceD3DInfo = (D3DEnum_RendererInfo *)deviceInfo; @@ -613,8 +604,8 @@ bool hsG3DDeviceSelector::IGetD3DCardInfo( hsG3DDeviceRecord &record, *vendorID = adapterInfo->VendorId; *deviceID = adapterInfo->DeviceId; - *driverString = adapterInfo->Driver; - *descString = adapterInfo->Description; + driverString = ST::string::from_latin_1(adapterInfo->Driver); + descString = ST::string::from_latin_1(adapterInfo->Description); return true; } @@ -644,15 +635,11 @@ void hsG3DDeviceSelector::ITryDirect3DTnLDriver(D3DEnum_DisplayInfo* drivInfo) devRec.SetDriverName( drivInfo->fAdapterInfo.Driver ); devRec.SetDriverDesc( drivInfo->fAdapterInfo.Description ); - char buff[ 256 ]; - sprintf( buff, "%d.%02d.%02d.%04d", - HIWORD( drivInfo->fAdapterInfo.DriverVersion.u.HighPart ), - LOWORD( drivInfo->fAdapterInfo.DriverVersion.u.HighPart ), - HIWORD( drivInfo->fAdapterInfo.DriverVersion.u.LowPart ), - LOWORD( drivInfo->fAdapterInfo.DriverVersion.u.LowPart ) ); - - - devRec.SetDriverVersion(buff); + devRec.SetDriverVersion(ST::format("{}.{02d}.{02d}.{04d}", + HIWORD(drivInfo->fAdapterInfo.DriverVersion.u.HighPart), + LOWORD(drivInfo->fAdapterInfo.DriverVersion.u.HighPart), + HIWORD(drivInfo->fAdapterInfo.DriverVersion.u.LowPart), + LOWORD(drivInfo->fAdapterInfo.DriverVersion.u.LowPart))); devRec.SetMemoryBytes(drivInfo->fMemory); diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.h b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.h index a372de3bde..3e15d771bf 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.h +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.h @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #ifndef hsGDirect3DTnLEnumerate_h #define hsGDirect3DTnLEnumerate_h +#include #include #include "HeadSpin.h" @@ -60,9 +61,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com struct D3DEnum_ModeInfo { D3DDISPLAYMODE fDDmode; - CHAR fStrDesc[40]; + ST::string fStrDesc; BOOL fWindowed; - char fBitDepth; + uint8_t fBitDepth; DWORD fDDBehavior; std::vector fDepthFormats; std::vector fFSAATypes; @@ -82,7 +83,7 @@ struct D3DEnum_ModeInfo struct D3DEnum_RendererInfo { D3DDEVTYPE fDDType; - CHAR fStrName[40]; + ST::string fStrName; D3DCAPS9 fDDCaps; BOOL fCanWindow; BOOL fCompatibleWithDesktop; @@ -110,8 +111,8 @@ struct D3DEnum_DisplayInfo { GUID fGuid; - CHAR fStrDesc[40]; - CHAR fStrName[40]; + ST::string fStrDesc; + ST::string fStrName; unsigned int fMemory; @@ -136,7 +137,7 @@ class hsG3DDeviceMode; class hsGDirect3DTnLEnumerate { protected: - char fEnumeErrorStr[128]; // Driver & device enumeration error message buffer + ST::string fEnumeErrorStr; // Driver & device enumeration error message buffer std::vector fDisplays; @@ -160,8 +161,6 @@ class hsGDirect3DTnLEnumerate VOID D3DEnum_FreeResources(); - char* GetErrorString() { return (fEnumeErrorStr[0] ? fEnumeErrorStr : nullptr); } - bool SelectFromDevMode(const hsG3DDeviceRecord* devRec, const hsG3DDeviceMode* devMode); HRESULT D3DEnum_SelectDefaultMode(int width, int height, int depth); HRESULT D3DEnum_SelectDefaultDisplay( DWORD dwFlags ); @@ -177,8 +176,7 @@ class hsGDirect3DTnLEnumerate void SetCurrentRenderer(D3DEnum_RendererInfo* d) { hsAssert(GetCurrentDisplay(), "Set Display first"); GetCurrentDisplay()->fCurrentRenderer = d; } void SetCurrentMode(D3DEnum_ModeInfo* m) { hsAssert(GetCurrentDisplay(), "Set Display first"); GetCurrentDisplay()->fCurrentMode = m; } - char* GetEnumeErrorStr() { return fEnumeErrorStr; } - void SetEnumeErrorStr(const char* s); + ST::string GetEnumeErrorStr() const { return fEnumeErrorStr; } }; diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp index 787b82f9d8..ded0d4ffa9 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp @@ -232,7 +232,7 @@ inline DWORD F2DW( FLOAT f ) } //// Macros for D3D error handling -#define INIT_ERROR_CHECK( cond, errMsg ) if( FAILED( fSettings.fDXError = cond ) ) { return ICreateFail( errMsg ); } +#define INIT_ERROR_CHECK(cond, errMsg) if (FAILED(fSettings.fDXError = cond)) { return ICreateFail(ST_LITERAL(errMsg)); } #if 1 // DEBUG #define STRONG_ERROR_CHECK( cond ) if( FAILED( fSettings.fDXError = cond ) ) { IGetD3DError(); IShowErrorMessage(); } @@ -337,7 +337,7 @@ void D3DSURF_MEMNEW(IDirect3DSurface9* surf) { D3DSURFACE_DESC info; surf->GetDesc( &info ); - PROFILE_POOL_MEM(D3DPOOL_DEFAULT, info.Width * info.Height * plDXPipeline::GetDXBitDepth(info.Format) / 8 + sizeof(IDirect3DSurface9), true, "D3DSurface"); + PROFILE_POOL_MEM(D3DPOOL_DEFAULT, info.Width * info.Height * plDXPipeline::GetDXBitDepth(info.Format) / 8 + sizeof(IDirect3DSurface9), true, ST_LITERAL("D3DSurface")); plProfile_NewMem(MemPipelineSurfaces, info.Width * info.Height * plDXPipeline::GetDXBitDepth(info.Format) / 8 + sizeof(IDirect3DSurface9)); } } @@ -381,7 +381,7 @@ void D3DSURF_MEMDEL(IDirect3DSurface9* surf) { D3DSURFACE_DESC info; surf->GetDesc( &info ); - PROFILE_POOL_MEM(D3DPOOL_DEFAULT, info.Width * info.Height * plDXPipeline::GetDXBitDepth(info.Format) / 8 + sizeof(IDirect3DSurface9), false, "D3DSurface"); + PROFILE_POOL_MEM(D3DPOOL_DEFAULT, info.Width * info.Height * plDXPipeline::GetDXBitDepth(info.Format) / 8 + sizeof(IDirect3DSurface9), false, ST_LITERAL("D3DSurface")); plProfile_DelMem(MemPipelineSurfaces, info.Width * info.Height * plDXPipeline::GetDXBitDepth(info.Format) / 8 + sizeof(IDirect3DSurface9)); } } @@ -428,7 +428,7 @@ void D3DSURF_MEMDEL(IDirect3DCubeTexture9* cTex) {} #endif // PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE -void plDXPipeline::ProfilePoolMem(D3DPOOL poolType, uint32_t size, bool add, const char *id) +void plDXPipeline::ProfilePoolMem(D3DPOOL poolType, uint32_t size, bool add, const ST::string& id) { switch( poolType ) { @@ -550,15 +550,14 @@ plDXPipeline::plDXPipeline( hsWinRef hWnd, const hsG3DDeviceModeRecord *devModeR fSettings.fNumAASamples = devMode->GetFSAAType( devRec->GetAASetting() - 1 ); hsGDirect3DTnLEnumerate& d3dEnum = hsGDirect3D::EnumerateTnL(); - if( d3dEnum.GetEnumeErrorStr()[ 0 ] ) - { - IShowErrorMessage( (char *)d3dEnum.GetEnumeErrorStr() ); + if (!d3dEnum.GetEnumeErrorStr().empty()) { + IShowErrorMessage(d3dEnum.GetEnumeErrorStr()); return; } if( d3dEnum.SelectFromDevMode(devRec, devMode) ) { - IShowErrorMessage( (char *)d3dEnum.GetEnumeErrorStr() ); + IShowErrorMessage(d3dEnum.GetEnumeErrorStr()); return; } @@ -591,7 +590,7 @@ plDXPipeline::plDXPipeline( hsWinRef hWnd, const hsG3DDeviceModeRecord *devModeR // Go create surfaces and DX-dependent objects if( ICreateDeviceObjects() ) { - IShowErrorMessage( "Cannot create Direct3D device" ); + IShowErrorMessage(ST_LITERAL("Cannot create Direct3D device")); return; } @@ -715,7 +714,7 @@ void plDXGeneralSettings::Reset() fIsIntel = false; fDXError = D3D_OK; - memset( fErrorStr, 0, sizeof( fErrorStr ) ); + fErrorStr.clear(); fCurrFVFFormat = 0; fCurrVertexShader = nullptr; @@ -1151,8 +1150,8 @@ void plDXPipeline::ISetCurrentDisplay( D3DEnum_DisplayInfo *driv ) fCurrentDisplay = new D3DEnum_DisplayInfo; fCurrentDisplay->fGuid = driv->fGuid; - hsStrncpy( fCurrentDisplay->fStrDesc, driv->fStrDesc, 40 ); - hsStrncpy( fCurrentDisplay->fStrName, driv->fStrName, 40 ); + fCurrentDisplay->fStrDesc = driv->fStrDesc; + fCurrentDisplay->fStrName = driv->fStrName; fCurrentDisplay->fDesktopMode = driv->fDesktopMode; fCurrentDisplay->fAdapterInfo = driv->fAdapterInfo; @@ -1185,7 +1184,7 @@ void plDXPipeline::ISetCurrentRenderer( D3DEnum_RendererInfo *dev ) delete fCurrentRenderer; fCurrentRenderer = new D3DEnum_RendererInfo; - hsStrncpy( fCurrentRenderer->fStrName, dev->fStrName, 40 ); + fCurrentRenderer->fStrName = dev->fStrName; fCurrentRenderer->fDDCaps = dev->fDDCaps; fCurrentRenderer->fDDType = dev->fDDType; @@ -1209,7 +1208,7 @@ void plDXPipeline::ISetCurrentRenderer( D3DEnum_RendererInfo *dev ) currMode.fDepthFormats = mode.fDepthFormats; currMode.fFSAATypes = mode.fFSAATypes; memcpy(&currMode.fDDmode, &mode.fDDmode, sizeof(D3DDISPLAYMODE)); - strcpy(currMode.fStrDesc, mode.fStrDesc); + currMode.fStrDesc = mode.fStrDesc; currMode.fWindowed = mode.fWindowed; fCurrentRenderer->fModes.emplace_back(currMode); @@ -1305,13 +1304,10 @@ bool plDXPipeline::ICreateDevice(bool windowed) /// First, create the D3D Device object D3DPRESENT_PARAMETERS params; D3DDISPLAYMODE dispMode; -#ifdef DBG_WRITE_FORMATS - char msg[ 256 ]; -#endif // DBG_WRITE_FORMATS IDirect3D9* d3d = hsGDirect3D::GetDirect3D(); if (!d3d) - return ICreateFail("Failed to get Direct3D Object"); + return ICreateFail(ST_LITERAL("Failed to get Direct3D Object")); INIT_ERROR_CHECK( d3d->GetAdapterDisplayMode( fCurrentAdapter, &dispMode ), "Cannot get desktop display mode" ); @@ -1351,8 +1347,7 @@ bool plDXPipeline::ICreateDevice(bool windowed) #ifdef DBG_WRITE_FORMATS for (D3DFORMAT fmt : fCurrentMode->fDepthFormats) { - sprintf(msg, "-- Valid depth buffer format: %s", IGetDXFormatName(fmt)); - hsDebugMessage( msg, 0 ); + hsDebugMessage(ST::format("-- Valid depth buffer format: {}", IGetDXFormatName(fmt)).c_str(), 0); } #endif @@ -1375,7 +1370,7 @@ bool plDXPipeline::ICreateDevice(bool windowed) params.MultiSampleType = D3DMULTISAMPLE_NONE; if( !IFindDepthFormat(params) ) // Okay, we're screwed here, we might as well bail. - return ICreateFail( "Can't find a Depth Buffer format" ); + return ICreateFail(ST_LITERAL("Can't find a Depth Buffer format")); } /// TEMP HACK--if we're running 16-bit z-buffer or below, use our z-bias (go figure, it works better @@ -1386,15 +1381,13 @@ bool plDXPipeline::ICreateDevice(bool windowed) fSettings.fD3DCaps &= ~kCapsZBias; #ifdef DBG_WRITE_FORMATS - sprintf( msg, "-- Requesting depth buffer format: %s", IGetDXFormatName( params.AutoDepthStencilFormat ) ); - hsDebugMessage( msg, 0 ); + hsDebugMessage(ST::format("-- Requesting depth buffer format: {}", IGetDXFormatName(params.AutoDepthStencilFormat)).c_str(), 0); #endif params.BackBufferFormat = dispMode.Format; #ifdef DBG_WRITE_FORMATS - sprintf( msg, "-- Requesting back buffer format: %s", IGetDXFormatName( params.BackBufferFormat ) ); - hsDebugMessage( msg, 0 ); + hsDebugMessage(ST::format("-- Requesting back buffer format: {}", IGetDXFormatName(params.BackBufferFormat)).c_str(), 0); #endif params.hDeviceWindow = fDevice.fHWnd; @@ -1768,7 +1761,7 @@ void plDXPipeline::IReleaseDynamicBuffers() // Actually, if it's volatile, it's sharing the global dynamic vertex buff, so we're already // accounting for the memory when we clear the global buffer. - //PROFILE_POOL_MEM(D3DPOOL_DEFAULT, vbRef->fCount * vbRef->fVertexSize, false, "VtxBuff"); + //PROFILE_POOL_MEM(D3DPOOL_DEFAULT, vbRef->fCount * vbRef->fVertexSize, false, ST_LITERAL("VtxBuff")); } // 9600 THRASH else if( fSettings.fBadManaged ) @@ -1787,14 +1780,14 @@ void plDXPipeline::IReleaseDynamicBuffers() { iRef->fD3DBuffer->Release(); iRef->fD3DBuffer = nullptr; - PROFILE_POOL_MEM(iRef->fPoolType, iRef->fCount * sizeof(uint16_t), false, "IndexBuff"); + PROFILE_POOL_MEM(iRef->fPoolType, iRef->fCount * sizeof(uint16_t), false, ST_LITERAL("IndexBuff")); } iRef = iRef->GetNext(); } if (fDynVtxBuff) { ReleaseObject(fDynVtxBuff); - PROFILE_POOL_MEM(D3DPOOL_DEFAULT, fDynVtxSize, false, "DynVtxBuff"); + PROFILE_POOL_MEM(D3DPOOL_DEFAULT, fDynVtxSize, false, ST_LITERAL("DynVtxBuff")); fDynVtxBuff = nullptr; } @@ -1837,7 +1830,7 @@ void plDXPipeline::ICreateDynamicBuffers() D3DPOOL poolType = D3DPOOL_DEFAULT; if( fDynVtxSize ) { - PROFILE_POOL_MEM(poolType, fDynVtxSize, true, "DynVtxBuff"); + PROFILE_POOL_MEM(poolType, fDynVtxSize, true, ST_LITERAL("DynVtxBuff")); if( FAILED( fD3DDevice->CreateVertexBuffer( fDynVtxSize, usage, 0, @@ -2253,14 +2246,14 @@ void plDXPipeline::Resize( uint32_t width, uint32_t height ) // Recreate if( hsGDirect3D::GetDirect3D(true) ) { - IShowErrorMessage( "Cannot create D3D master object" ); + IShowErrorMessage(ST_LITERAL("Cannot create D3D master object")); return; } // Go recreate surfaces and DX-dependent objects if( ICreateDeviceObjects() ) { - IShowErrorMessage( "Cannot create Direct3D device" ); + IShowErrorMessage(ST_LITERAL("Cannot create Direct3D device")); return; } @@ -7290,7 +7283,7 @@ IDirect3DTexture9 *plDXPipeline::IMakeD3DTexture( plDXTextureRef *ref, D3DFORM ref->fMaxWidth, ref->fMaxHeight, ref->fMMLvs, ref->GetFlags() ); return nullptr; } - PROFILE_POOL_MEM(poolType, ref->fDataSize, true, (ref->fOwner ? ref->fOwner->GetKey() ? ref->fOwner->GetKey()->GetUoid().GetObjectName().c_str() : "(UnknownTexture)" : "(UnknownTexture)")); + PROFILE_POOL_MEM(poolType, ref->fDataSize, true, ref->fOwner && ref->fOwner->GetKey() ? ref->fOwner->GetKey()->GetUoid().GetObjectName() : ST_LITERAL("(UnknownTexture)")); fTexManaged += ref->fDataSize; return texPtr; @@ -7329,7 +7322,7 @@ void plDXPipeline::IFillD3DTexture( plDXTextureRef *ref ) return; } - memcpy( (char *)lockInfo.pBits, pTexDat, ref->fLevelSizes[ i ] ); + memcpy(lockInfo.pBits, pTexDat, ref->fLevelSizes[i]); pTexDat += ref->fLevelSizes[ i ]; lpDst->UnlockRect( i ); } @@ -7344,7 +7337,7 @@ IDirect3DCubeTexture9 *plDXPipeline::IMakeD3DCubeTexture( plDXTextureRef *ref, IDirect3DCubeTexture9 *texPtr = nullptr; fManagedAlloced = true; WEAK_ERROR_CHECK(fD3DDevice->CreateCubeTexture( ref->fMaxWidth, ref->fMMLvs, 0, formatType, poolType, &texPtr, nullptr)); - PROFILE_POOL_MEM(poolType, ref->fDataSize, true, (ref->fOwner ? ref->fOwner->GetKey() ? ref->fOwner->GetKey()->GetUoid().GetObjectName().c_str() : "(UnknownTexture)" : "(UnknownTexture)")); + PROFILE_POOL_MEM(poolType, ref->fDataSize, true, ref->fOwner && ref->fOwner->GetKey() ? ref->fOwner->GetKey()->GetUoid().GetObjectName() : ST_LITERAL("(UnknownTexture)")); fTexManaged += ref->fDataSize; return texPtr; } @@ -7371,7 +7364,7 @@ void plDXPipeline::IFillD3DCubeTexture( plDXCubeTextureRef *ref ) D3DLOCKED_RECT lockInfo; lpDst->LockRect(faces[f], i, &lockInfo, nullptr, 0); - memcpy( (char *)lockInfo.pBits, pTexDat, ref->fLevelSizes[ i ] ); + memcpy(lockInfo.pBits, pTexDat, ref->fLevelSizes[i]); pTexDat += ref->fLevelSizes[ i ]; lpDst->UnlockRect( faces[ f ], i ); } @@ -8144,7 +8137,7 @@ void plDXPipeline::ICheckStaticVertexBuffer(plDXVertexBufferRef* vRef, plGBuffer vRef->fD3DBuffer = nullptr; return; } - PROFILE_POOL_MEM(poolType, numVerts * vertSize, true, "VtxBuff"); + PROFILE_POOL_MEM(poolType, numVerts * vertSize, true, ST_LITERAL("VtxBuff")); // Record that we've allocated this into managed memory, in case we're // fighting that NVidia driver bug. Search for OSVERSION for mor info. @@ -8495,7 +8488,7 @@ void plDXPipeline::ICheckIndexBuffer(plDXIndexBufferRef* iRef) iRef->fD3DBuffer = nullptr; return; } - PROFILE_POOL_MEM(poolType, sizeof(uint16_t) * iRef->fCount, true, "IndexBuff"); + PROFILE_POOL_MEM(poolType, sizeof(uint16_t) * iRef->fCount, true, ST_LITERAL("IndexBuff")); iRef->fPoolType = poolType; iRef->SetDirty(true); @@ -9719,7 +9712,7 @@ void plDXPlateManager::ICreateGeometry(plDXPipeline* pipe) fCreatedSucessfully = false; return; } - PROFILE_POOL_MEM(poolType, 4 * sizeof(plPlateVertex), true, "PlateMgrVtxBuff"); + PROFILE_POOL_MEM(poolType, 4 * sizeof(plPlateVertex), true, ST_LITERAL("PlateMgrVtxBuff")); /// Lock the buffer plPlateVertex *ptr; @@ -9760,7 +9753,7 @@ void plDXPlateManager::IReleaseGeometry() if (fVertBuffer) { ReleaseObject(fVertBuffer); - PROFILE_POOL_MEM(D3DPOOL_DEFAULT, 4 * sizeof(plPlateVertex), false, "PlateMgrVtxBuff"); + PROFILE_POOL_MEM(D3DPOOL_DEFAULT, 4 * sizeof(plPlateVertex), false, ST_LITERAL("PlateMgrVtxBuff")); fVertBuffer = nullptr; } } @@ -9911,43 +9904,38 @@ void plDXPipeline::IDrawPlate( plPlate *plate ) // IAddErrorMessage //////////////////////////////////////////////////// // Append the error string to the current error string. -void plDXPipeline::IAddErrorMessage(const char* errStr) +void plDXPipeline::IAddErrorMessage(const ST::string& errStr) { - static char str[ 512 ]; - if( errStr && strlen( errStr ) + strlen( fSettings.fErrorStr ) < sizeof( fSettings.fErrorStr ) - 4 ) - { - strcpy( str, fSettings.fErrorStr ); - sprintf( fSettings.fErrorStr, "%s\n(%s)", errStr, str ); + if (!errStr.empty()) { + fSettings.fErrorStr = ST::format("{}\n({})", errStr, fSettings.fErrorStr); plStatusLog::AddLineS("pipeline.log", fSettings.fErrorStr); } } // ISetErrorMessage ////////////////////////////////////////////////////////// // Clear the current error string to the input string. -void plDXPipeline::ISetErrorMessage(const char* errStr) +void plDXPipeline::ISetErrorMessage(ST::string errStr) { - if( errStr ) - { - strcpy( fSettings.fErrorStr, errStr ); + fSettings.fErrorStr = std::move(errStr); + if (!fSettings.fErrorStr.empty()) { plStatusLog::AddLineS("pipeline.log", fSettings.fErrorStr); } - else - fSettings.fErrorStr[ 0 ] = 0; } // IGetD3DError ///////////////////////////////////////////////////////////////// // Convert the last D3D error code to a string (probably "Conflicting Render State"). void plDXPipeline::IGetD3DError() { - sprintf( fSettings.fErrorStr, "D3DError : %s", fSettings.fDXError.ToString().c_str() ); + fSettings.fErrorStr = ST::format("D3DError : {}", fSettings.fDXError.ToString()); } // IShowErrorMessage ///////////////////////////////////////////////////////////// // Append the string to the running error string. -void plDXPipeline::IShowErrorMessage(const char* errStr) +void plDXPipeline::IShowErrorMessage(const ST::string& errStr) { - if (errStr != nullptr) - IAddErrorMessage( errStr ); + if (!errStr.empty()) { + IAddErrorMessage(errStr); + } // hsAssert( false, fSettings.fErrorStr ); } @@ -9955,18 +9943,18 @@ void plDXPipeline::IShowErrorMessage(const char* errStr) // ICreateFail //////////////////////////////////////////////////////////////////// // Called on unrecoverable error during device creation. Frees up anything // allocated so far, sets the error string, and returns true. -bool plDXPipeline::ICreateFail(const char* errStr) +bool plDXPipeline::ICreateFail(const ST::string& errStr) { // Don't overwrite any error string we already had - if( fSettings.fErrorStr[ 0 ] == 0 ) + if (fSettings.fErrorStr.empty()) { IGetD3DError(); + } - if( errStr && *errStr ) - { - IAddErrorMessage( errStr ); + if (!errStr.empty()) { + IAddErrorMessage(errStr); + } else if (fSettings.fErrorStr.empty()) { + IAddErrorMessage(ST_LITERAL("unknown")); } - else if( !*fSettings.fErrorStr ) - IAddErrorMessage( "unknown" ); IReleaseDeviceObjects(); return true; @@ -9974,11 +9962,8 @@ bool plDXPipeline::ICreateFail(const char* errStr) // GetErrorString /////////////////////////////////////////////////////////////////////////// // Return the current error string. -const char* plDXPipeline::GetErrorString() +ST::string plDXPipeline::GetErrorString() { - if( fSettings.fErrorStr[ 0 ] == 0 ) - return nullptr; - return fSettings.fErrorStr; } @@ -10076,51 +10061,50 @@ short plDXPipeline::GetDXBitDepth( D3DFORMAT format ) // // From a D3DFORMAT enumeration, return the string for it. -const char *plDXPipeline::IGetDXFormatName( D3DFORMAT format ) -{ - switch( format ) - { - case D3DFMT_UNKNOWN: return "D3DFMT_UNKNOWN"; - case D3DFMT_R8G8B8: return "D3DFMT_R8G8B8"; - case D3DFMT_A8R8G8B8: return "D3DFMT_A8R8G8B8"; - case D3DFMT_X8R8G8B8: return "D3DFMT_X8R8G8B8"; - case D3DFMT_R5G6B5: return "D3DFMT_R5G6B5"; - case D3DFMT_X1R5G5B5: return "D3DFMT_X1R5G5B5"; - case D3DFMT_A1R5G5B5: return "D3DFMT_A1R5G5B5"; - case D3DFMT_A4R4G4B4: return "D3DFMT_A4R4G4B4"; - case D3DFMT_R3G3B2: return "D3DFMT_R3G3B2"; - case D3DFMT_A8: return "D3DFMT_A8"; - case D3DFMT_A8R3G3B2: return "D3DFMT_A8R3G3B2"; - case D3DFMT_X4R4G4B4: return "D3DFMT_X4R4G4B4"; - case D3DFMT_A8P8: return "D3DFMT_A8P8"; - case D3DFMT_P8: return "D3DFMT_P8"; - case D3DFMT_L8: return "D3DFMT_L8"; - case D3DFMT_A8L8: return "D3DFMT_A8L8"; - case D3DFMT_A4L4: return "D3DFMT_A4L4"; - case D3DFMT_V8U8: return "D3DFMT_V8U8"; - case D3DFMT_L6V5U5: return "D3DFMT_L6V5U5"; - case D3DFMT_X8L8V8U8: return "D3DFMT_X8L8V8U8"; - case D3DFMT_Q8W8V8U8: return "D3DFMT_Q8W8V8U8"; - case D3DFMT_V16U16: return "D3DFMT_V16U16"; - //case D3DFMT_W11V11U10: return "D3DFMT_W11V11U10"; - case D3DFMT_UYVY: return "D3DFMT_UYVY"; - case D3DFMT_YUY2: return "D3DFMT_YUY2"; - case D3DFMT_DXT1: return "D3DFMT_DXT1"; -// case D3DFMT_DXT2: return "D3DFMT_DXT2"; -// case D3DFMT_DXT3: return "D3DFMT_DXT3"; -// case D3DFMT_DXT4: return "D3DFMT_DXT4"; - case D3DFMT_DXT5: return "D3DFMT_DXT5"; - case D3DFMT_VERTEXDATA: return "D3DFMT_VERTEXDATA"; - case D3DFMT_D16_LOCKABLE: return "D3DFMT_D16_LOCKABLE"; - case D3DFMT_D32: return "D3DFMT_D32"; - case D3DFMT_D15S1: return "D3DFMT_D15S1"; - case D3DFMT_D24S8: return "D3DFMT_D24S8"; - case D3DFMT_D16: return "D3DFMT_D16"; - case D3DFMT_D24X8: return "D3DFMT_D24X8"; - case D3DFMT_D24X4S4: return "D3DFMT_D24X4S4"; - case D3DFMT_INDEX16: return "D3DFMT_INDEX16"; - case D3DFMT_INDEX32: return "D3DFMT_INDEX32"; - default: return "Bad format"; +ST::string plDXPipeline::IGetDXFormatName(D3DFORMAT format) +{ + switch (format) { + case D3DFMT_UNKNOWN: return ST_LITERAL("D3DFMT_UNKNOWN"); + case D3DFMT_R8G8B8: return ST_LITERAL("D3DFMT_R8G8B8"); + case D3DFMT_A8R8G8B8: return ST_LITERAL("D3DFMT_A8R8G8B8"); + case D3DFMT_X8R8G8B8: return ST_LITERAL("D3DFMT_X8R8G8B8"); + case D3DFMT_R5G6B5: return ST_LITERAL("D3DFMT_R5G6B5"); + case D3DFMT_X1R5G5B5: return ST_LITERAL("D3DFMT_X1R5G5B5"); + case D3DFMT_A1R5G5B5: return ST_LITERAL("D3DFMT_A1R5G5B5"); + case D3DFMT_A4R4G4B4: return ST_LITERAL("D3DFMT_A4R4G4B4"); + case D3DFMT_R3G3B2: return ST_LITERAL("D3DFMT_R3G3B2"); + case D3DFMT_A8: return ST_LITERAL("D3DFMT_A8"); + case D3DFMT_A8R3G3B2: return ST_LITERAL("D3DFMT_A8R3G3B2"); + case D3DFMT_X4R4G4B4: return ST_LITERAL("D3DFMT_X4R4G4B4"); + case D3DFMT_A8P8: return ST_LITERAL("D3DFMT_A8P8"); + case D3DFMT_P8: return ST_LITERAL("D3DFMT_P8"); + case D3DFMT_L8: return ST_LITERAL("D3DFMT_L8"); + case D3DFMT_A8L8: return ST_LITERAL("D3DFMT_A8L8"); + case D3DFMT_A4L4: return ST_LITERAL("D3DFMT_A4L4"); + case D3DFMT_V8U8: return ST_LITERAL("D3DFMT_V8U8"); + case D3DFMT_L6V5U5: return ST_LITERAL("D3DFMT_L6V5U5"); + case D3DFMT_X8L8V8U8: return ST_LITERAL("D3DFMT_X8L8V8U8"); + case D3DFMT_Q8W8V8U8: return ST_LITERAL("D3DFMT_Q8W8V8U8"); + case D3DFMT_V16U16: return ST_LITERAL("D3DFMT_V16U16"); + //case D3DFMT_W11V11U10: return ST_LITERAL("D3DFMT_W11V11U10"); + case D3DFMT_UYVY: return ST_LITERAL("D3DFMT_UYVY"); + case D3DFMT_YUY2: return ST_LITERAL("D3DFMT_YUY2"); + case D3DFMT_DXT1: return ST_LITERAL("D3DFMT_DXT1"); + //case D3DFMT_DXT2: return ST_LITERAL("D3DFMT_DXT2"); + //case D3DFMT_DXT3: return ST_LITERAL("D3DFMT_DXT3"); + //case D3DFMT_DXT4: return ST_LITERAL("D3DFMT_DXT4"); + case D3DFMT_DXT5: return ST_LITERAL("D3DFMT_DXT5"); + case D3DFMT_VERTEXDATA: return ST_LITERAL("D3DFMT_VERTEXDATA"); + case D3DFMT_D16_LOCKABLE: return ST_LITERAL("D3DFMT_D16_LOCKABLE"); + case D3DFMT_D32: return ST_LITERAL("D3DFMT_D32"); + case D3DFMT_D15S1: return ST_LITERAL("D3DFMT_D15S1"); + case D3DFMT_D24S8: return ST_LITERAL("D3DFMT_D24S8"); + case D3DFMT_D16: return ST_LITERAL("D3DFMT_D16"); + case D3DFMT_D24X8: return ST_LITERAL("D3DFMT_D24X8"); + case D3DFMT_D24X4S4: return ST_LITERAL("D3DFMT_D24X4S4"); + case D3DFMT_INDEX16: return ST_LITERAL("D3DFMT_INDEX16"); + case D3DFMT_INDEX32: return ST_LITERAL("D3DFMT_INDEX32"); + default: return ST_LITERAL("Bad format"); } } @@ -10590,7 +10574,7 @@ void plDXPipeline::IReleaseBlurVBuffers() if (fBlurVBuffers[i]) { ReleaseObject(fBlurVBuffers[i]); - PROFILE_POOL_MEM(D3DPOOL_DEFAULT, 4 * kVSize, false, "BlurVtxBuff"); + PROFILE_POOL_MEM(D3DPOOL_DEFAULT, 4 * kVSize, false, ST_LITERAL("BlurVtxBuff")); fBlurVBuffers[i] = nullptr; } } @@ -10673,7 +10657,7 @@ bool plDXPipeline::ICreateBlurVBuffers() vBuffer->Release(); return false; } - PROFILE_POOL_MEM(D3DPOOL_DEFAULT, 4 * kVSize, true, "BlurVtxBuff"); + PROFILE_POOL_MEM(D3DPOOL_DEFAULT, 4 * kVSize, true, ST_LITERAL("BlurVtxBuff")); plShadowVertStruct vert; vert.fPos[0] = -1.f; diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.h b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.h index bb0b86f839..3b33cdcb44 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.h +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.h @@ -417,11 +417,11 @@ class plDXPipeline : public pl3DPipeline inline D3DCOLORVALUE inlPlToD3DColor(const hsColorRGBA& c, float a) const; // Error handling - void IAddErrorMessage(const char* errStr); - void ISetErrorMessage(const char* errStr = nullptr); - void IGetD3DError(); - void IShowErrorMessage(const char* errStr = nullptr); - bool ICreateFail(const char* errStr); + void IAddErrorMessage(const ST::string& errStr); + void ISetErrorMessage(ST::string errStr); + void IGetD3DError(); + void IShowErrorMessage(const ST::string& errStr = {}); + bool ICreateFail(const ST::string& errStr); // Device initialization void IInvalidateState(); @@ -476,7 +476,7 @@ class plDXPipeline : public pl3DPipeline bool IFindRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &surfFormat, D3DRESOURCETYPE &resType ); // From a D3DFORMAT enumeration, return the string literal for it - static const char *IGetDXFormatName( D3DFORMAT format ); + static ST::string IGetDXFormatName(D3DFORMAT format); /////// Shadow internals // Generation @@ -573,7 +573,7 @@ class plDXPipeline : public pl3DPipeline static void AllocManagedVertex(uint32_t sz) { fVtxManaged += sz; } #ifndef PLASMA_EXTERNAL_RELEASE - static void ProfilePoolMem(D3DPOOL poolType, uint32_t size, bool add, const char *id); + static void ProfilePoolMem(D3DPOOL poolType, uint32_t size, bool add, const ST::string& id); #endif // PLASMA_EXTERNAL_RELEASE // From a D3DFORMAT enumeration, return the bit depth associated with it. @@ -595,7 +595,7 @@ class plDXPipeline : public pl3DPipeline plMipmap* ExtractMipMap(plRenderTarget* targ) override; /// Error handling - const char *GetErrorString() override; + ST::string GetErrorString() override; bool ManagedAlloced() const { return fManagedAlloced; } diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPixelShader.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPixelShader.cpp index b020713f8c..1ad2a76119 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPixelShader.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPixelShader.cpp @@ -66,8 +66,7 @@ void plDXPixelShader::Release() ReleaseObject(fHandle); fHandle = nullptr; fPipe = nullptr; - - ISetError(nullptr); + fErrorString.clear(); } bool plDXPixelShader::VerifyFormat(uint8_t format) const @@ -94,17 +93,17 @@ HRESULT plDXPixelShader::ICreate(plDXPipeline* pipe) { fHandle = nullptr; // in case something goes wrong. fPipe = nullptr; - ISetError(nullptr); + fErrorString.clear(); DWORD* shaderCodes = (DWORD*)(fOwner->GetDecl()->GetCodes()); if( !shaderCodes ) - return IOnError(-1, "Shaders must be compiled into the engine."); + return IOnError(-1, ST_LITERAL("Shaders must be compiled into the engine.")); HRESULT hr = pipe->GetD3DDevice()->CreatePixelShader(shaderCodes, &fHandle); if( FAILED(hr) ) { - return IOnError(hr, "Error on CreatePixelShader"); + return IOnError(hr, ST_LITERAL("Error on CreatePixelShader")); } hsAssert(fHandle, "No error, but no pixel shader handle. Grrrr."); @@ -123,7 +122,7 @@ HRESULT plDXPixelShader::ISetConstants(plDXPipeline* pipe) (const float*)fOwner->GetConstBasePtr(), fOwner->GetNumConsts()); if( FAILED(hr) ) - return IOnError(hr, "Error setting constants"); + return IOnError(hr, ST_LITERAL("Error setting constants")); } return S_OK; diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXSettings.h b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXSettings.h index 10ca790927..014448a8ce 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXSettings.h +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXSettings.h @@ -56,6 +56,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsWindows.h" #include +#include #include #include "hsBitVector.h" @@ -73,6 +74,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com //// General Settings ///////////////////////////////////////////////////////// +class plLightInfo; class plRenderRequest; class plRenderTarget; struct IDirect3DSurface9; @@ -109,7 +111,7 @@ class plDXGeneralSettings DWORD fCurrFVFFormat; hsCOMError fDXError; - char fErrorStr[ 256 ]; + ST::string fErrorStr; void Reset(); }; diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXShader.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXShader.cpp index b68f3bccaf..03db98dccc 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXShader.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXShader.cpp @@ -60,8 +60,7 @@ plDXShader::plDXShader(plShader* owner) plDXShader::~plDXShader() { fPipe = nullptr; - - ISetError(nullptr); + fErrorString.clear(); } void plDXShader::SetOwner(plShader* owner) @@ -74,13 +73,13 @@ void plDXShader::SetOwner(plShader* owner) } } -HRESULT plDXShader::IOnError(HRESULT hr, const char* errStr) +HRESULT plDXShader::IOnError(HRESULT hr, ST::string errStr) { - ISetError(errStr); + fErrorString = std::move(errStr); fOwner->Invalidate(); - hsStatusMessage(errStr); + hsStatusMessage(fErrorString.c_str()); return hr; } diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXShader.h b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXShader.h index f4035127b1..daedc9e1b0 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXShader.h +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXShader.h @@ -56,8 +56,7 @@ class plDXShader : public plDXDeviceRef ST::string fErrorString; plDXPipeline* fPipe; - HRESULT IOnError(HRESULT hr, const char* errStr); - void ISetError(const char* errStr) { fErrorString = errStr; } + HRESULT IOnError(HRESULT hr, ST::string errStr); virtual HRESULT ICreate(plDXPipeline* pipe) = 0; virtual HRESULT ISetConstants(plDXPipeline* pipe) = 0; // On error, sets error string. diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXVertexShader.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXVertexShader.cpp index 1ba4fe6999..c9f1b87450 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXVertexShader.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXVertexShader.cpp @@ -66,8 +66,7 @@ void plDXVertexShader::Release() ReleaseObject(fHandle); fHandle = nullptr; fPipe = nullptr; - - ISetError(nullptr); + fErrorString.clear(); } bool plDXVertexShader::VerifyFormat(uint8_t format) const @@ -94,7 +93,7 @@ HRESULT plDXVertexShader::ICreate(plDXPipeline* pipe) { fHandle = nullptr; // in case something goes wrong. fPipe = nullptr; - ISetError(nullptr); + fErrorString.clear(); // We could store the compiled buffer and skip the assembly step // if we need to recreate the shader (e.g. on device lost). @@ -102,12 +101,12 @@ HRESULT plDXVertexShader::ICreate(plDXPipeline* pipe) DWORD* shaderCodes = (DWORD*)(fOwner->GetDecl()->GetCodes()); if( !shaderCodes ) - return IOnError(-1, "Shaders must be compiled into the engine."); + return IOnError(-1, ST_LITERAL("Shaders must be compiled into the engine.")); HRESULT hr = pipe->GetD3DDevice()->CreateVertexShader(shaderCodes, &fHandle); if( FAILED(hr) ) - return IOnError(hr, "Error on CreateVertexShader"); + return IOnError(hr, ST_LITERAL("Error on CreateVertexShader")); hsAssert(fHandle, "No error, but no vertex shader handle. Grrrr."); @@ -125,7 +124,7 @@ HRESULT plDXVertexShader::ISetConstants(plDXPipeline* pipe) (const float*)fOwner->GetConstBasePtr(), fOwner->GetNumConsts()); if( FAILED(hr) ) - return IOnError(hr, "Failure setting vertex shader constants"); + return IOnError(hr, ST_LITERAL("Failure setting vertex shader constants")); } return S_OK; diff --git a/Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.h b/Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.h index 49c4110fa1..2de62f4cfd 100644 --- a/Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.h +++ b/Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.h @@ -44,13 +44,15 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsMatrix44.h" +#include + class plGLPipeline; class plRenderTarget; class plGLDevice { protected: - const char* fErrorMsg; + ST::string fErrorMsg; plGLPipeline* fPipeline; public: @@ -76,7 +78,7 @@ class plGLDevice struct IndexBufferRef; struct TextureRef; - const char* GetErrorString() const { return fErrorMsg; } + ST::string GetErrorString() const { return fErrorMsg; } }; #endif diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp index 1f8e5c16d8..c9ba51efa8 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp @@ -549,9 +549,9 @@ bool pfGUIControlMod::MsgReceive( plMessage *msg ) if (rend || device) { plPipeline* pipe = rend ? rend->Pipeline() : device->Pipeline(); - plProfile_BeginLap(GUITime, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(GUITime, this->GetKey()->GetUoid().GetObjectName()); ISetUpDynTextMap(pipe); - plProfile_EndLap(GUITime, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(GUITime, this->GetKey()->GetUoid().GetObjectName()); if (rend) plgDispatch::Dispatch()->UnRegisterForExactType(plRenderMsg::Index(), GetKey()); diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.h b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.h index c5f3cfd89a..9fbff73299 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.h +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.h @@ -47,6 +47,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include #include +#include #include #include "HeadSpin.h" @@ -85,7 +86,7 @@ class plMetalDevice hsWindowHndl fDevice; hsWindowHndl fWindow; - const char* fErrorMsg; + ST::string fErrorMsg; MTL::RenderCommandEncoder* CurrentRenderCommandEncoder(); MTL::Device* fMetalDevice; @@ -140,7 +141,7 @@ class plMetalDevice void MakeTextureRef(TextureRef* tRef, plMipmap* img); void MakeCubicTextureRef(TextureRef* tRef, plCubicEnvironmap* img); - const char* GetErrorString() const { return fErrorMsg; } + ST::string GetErrorString() const { return fErrorMsg; } void SetProjectionMatrix(const hsMatrix44& src); void SetWorldToCameraMatrix(const hsMatrix44& src); diff --git a/Sources/Plasma/NucleusLib/inc/plPipeline.h b/Sources/Plasma/NucleusLib/inc/plPipeline.h index 6b6f463ee5..12f8924ad1 100644 --- a/Sources/Plasma/NucleusLib/inc/plPipeline.h +++ b/Sources/Plasma/NucleusLib/inc/plPipeline.h @@ -337,7 +337,7 @@ class plPipeline : public plCreatable virtual plMipmap* ExtractMipMap(plRenderTarget* targ) = 0; /// Error handling - virtual const char *GetErrorString() = 0; + virtual ST::string GetErrorString() = 0; // info about current rendering device virtual void GetSupportedDisplayModes(std::vector *res, int ColorDepth = 32 ) = 0; diff --git a/Sources/Plasma/NucleusLib/inc/plProfile.h b/Sources/Plasma/NucleusLib/inc/plProfile.h index 6ccba04cdf..5dfdfe51f3 100644 --- a/Sources/Plasma/NucleusLib/inc/plProfile.h +++ b/Sources/Plasma/NucleusLib/inc/plProfile.h @@ -44,6 +44,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" +#include + #ifndef PLASMA_EXTERNAL_RELEASE #define PL_PROFILE_ENABLED #endif @@ -79,23 +81,23 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #ifdef PL_PROFILE_ENABLED -#define plProfile_CreateTimerNoReset(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayTime | plProfileVar::kDisplayNoReset) -#define plProfile_CreateTimer(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayTime) -#define plProfile_CreateAsynchTimer(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayTime | plProfileVar::kDisplayResetEveryBegin | plProfileVar::kDisplayNoReset) +#define plProfile_CreateTimerNoReset(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayTime | plProfileVar::kDisplayNoReset) +#define plProfile_CreateTimer(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayTime) +#define plProfile_CreateAsynchTimer(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayTime | plProfileVar::kDisplayResetEveryBegin | plProfileVar::kDisplayNoReset) #define plProfile_BeginTiming(varName) gProfileVar##varName.BeginTiming() #define plProfile_EndTiming(varName) gProfileVar##varName.EndTiming() #define plProfile_BeginLap(varName, lapName) gProfileVar##varName.BeginLap(lapName) #define plProfile_EndLap(varName, lapName) gProfileVar##varName.EndLap(lapName) -#define plProfile_CreateCounter(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayCount) -#define plProfile_CreateCounterNoReset(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayCount | plProfileVar::kDisplayNoReset) +#define plProfile_CreateCounter(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayCount) +#define plProfile_CreateCounterNoReset(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayCount | plProfileVar::kDisplayNoReset) #define plProfile_Inc(varName) gProfileVar##varName.Inc() #define plProfile_IncCount(varName, count) gProfileVar##varName.Inc(count) #define plProfile_Dec(varName) gProfileVar##varName.Dec() #define plProfile_Set(varName, value) gProfileVar##varName.Set(value) -#define plProfile_CreateMemCounter(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayMem | plProfileVar::kDisplayNoReset) -#define plProfile_CreateMemCounterReset(name, group, varName) plProfileVar gProfileVar##varName(name, group, plProfileVar::kDisplayMem) +#define plProfile_CreateMemCounter(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayMem | plProfileVar::kDisplayNoReset) +#define plProfile_CreateMemCounterReset(name, group, varName) plProfileVar gProfileVar##varName(ST_LITERAL(name), ST_LITERAL(group), plProfileVar::kDisplayMem) #define plProfile_NewMem(varName, memAmount) gProfileVar##varName.NewMem(memAmount) #define plProfile_DelMem(varName, memAmount) gProfileVar##varName.DelMem(memAmount) @@ -151,7 +153,7 @@ class plProfileBase }; protected: - const char* fName; // Name of timer + ST::string fName; // Name of timer uint64_t fValue; @@ -168,7 +170,7 @@ class plProfileBase void IAddAvg(); - void IPrintValue(uint64_t value, char* buf, bool printType); + ST::string IPrintValue(uint64_t value, bool printType); public: plProfileBase(); @@ -181,13 +183,13 @@ class plProfileBase uint64_t GetValue(); - void PrintValue(char* buf, bool printType=true); - void PrintAvg(char* buf, bool printType=true); - void PrintMax(char* buf, bool printType=true); + ST::string PrintValue(bool printType = true); + ST::string PrintAvg(bool printType = true); + ST::string PrintMax(bool printType = true); uint32_t GetTimerSamples() const { return fTimerSamples; } - const char* GetName() { return fName; } + ST::string GetName() const { return fName; } void SetActive(bool s) { fActive = s; } @@ -202,7 +204,7 @@ class plProfileBase class plProfileVar : public plProfileBase { protected: - const char* fGroup; + ST::string fGroup; plProfileLaps* fLaps; bool fLapsActive; @@ -210,13 +212,13 @@ class plProfileVar : public plProfileBase void IBeginTiming(); void IEndTiming(); - - void IBeginLap(const char* lapName); - void IEndLap(const char* lapName); + + void IBeginLap(const ST::string& lapName); + void IEndLap(const ST::string& lapName); public: // Name is the timer name. Each timer group gets its own plStatusLog - plProfileVar(const char *name, const char* group, uint8_t flags); + plProfileVar(ST::string name, ST::string group, uint8_t flags); ~plProfileVar(); // For timing @@ -238,10 +240,10 @@ class plProfileVar : public plProfileBase // Will output to log like // Timername : lapCnt: (lapName) : 3.22 msec // - void BeginLap(const char* lapName) { if(fActive && fRunning) IBeginLap(lapName); } - void EndLap(const char* lapName) { if(fActive && fRunning) IEndLap(lapName); } - - const char* GetGroup() { return fGroup; } + void BeginLap(const ST::string& lapName) { if (fActive && fRunning) IBeginLap(lapName); } + void EndLap(const ST::string& lapName) { if (fActive && fRunning) IEndLap(lapName); } + + ST::string GetGroup() const { return fGroup; } plProfileLaps* GetLaps() { return fLaps; } diff --git a/Sources/Plasma/NucleusLib/inc/plProfileManager.cpp b/Sources/Plasma/NucleusLib/inc/plProfileManager.cpp index f69d9b39c8..9c12570f61 100644 --- a/Sources/Plasma/NucleusLib/inc/plProfileManager.cpp +++ b/Sources/Plasma/NucleusLib/inc/plProfileManager.cpp @@ -42,7 +42,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plProfileManager.h" #include "plProfile.h" #include "hsTimer.h" -#include + +#include +#include plProfileManager::plProfileManager() : fLastAvgTime(0), fProcessorSpeed(0) { @@ -70,7 +72,7 @@ void plProfileManager::SetAvgTime(uint32_t avgMS) kAvgMilliseconds = avgMS; } -static plProfileVar gVarEFPS("EFPS", "General", plProfileVar::kDisplayTime | plProfileVar::kDisplayFPS); +static plProfileVar gVarEFPS(ST_LITERAL("EFPS"), ST_LITERAL("General"), plProfileVar::kDisplayTime | plProfileVar::kDisplayFPS); void plProfileManager::BeginFrame() { @@ -182,89 +184,65 @@ uint64_t plProfileBase::GetValue() return fValue; } -// Stolen from plMemTracker.cpp -static const char *insertCommas(unsigned long long value) +static ST::string insertCommas(unsigned long long value) { - static char str[30]; - memset(str, 0, sizeof(str)); - - snprintf(str, std::size(str), "%llu", value); - if (strlen(str) > 3) - { - memmove(&str[strlen(str)-3], &str[strlen(str)-4], 4); - str[strlen(str) - 4] = ','; - } - if (strlen(str) > 7) - { - memmove(&str[strlen(str)-7], &str[strlen(str)-8], 8); - str[strlen(str) - 8] = ','; + ST::string str; + while (value >= 1000) { + str = ST::format(",{>03}{}", value % 1000, str); + value /= 1000; } - if (strlen(str) > 11) - { - memmove(&str[strlen(str)-11], &str[strlen(str)-12], 12); - str[strlen(str) - 12] = ','; - } - - return str; + return ST::format("{}{}", value, str); } -void plProfileBase::IPrintValue(uint64_t value, char* buf, bool printType) +ST::string plProfileBase::IPrintValue(uint64_t value, bool printType) { - if (hsCheckBits(fDisplayFlags, kDisplayCount)) - { - if (printType) - { - const char* valueStr = insertCommas(value); - strcpy(buf, valueStr); + if (hsCheckBits(fDisplayFlags, kDisplayCount)) { + if (printType) { + return insertCommas(value); + } else { + return ST::string::from_uint(value); } - else - sprintf(buf, "%llu", static_cast(value)); - } - else if (hsCheckBits(fDisplayFlags, kDisplayFPS)) - { - sprintf(buf, "%.2f", 1000.0f / hsTimer::GetMilliSeconds(value)); - } - else if (hsCheckBits(fDisplayFlags, kDisplayTime)) - { - sprintf(buf, "%.2f", hsTimer::GetMilliSeconds(value)); - if (printType) - strcat(buf, " ms"); - } - else if (hsCheckBits(fDisplayFlags, kDisplayMem)) - { - if (printType) - { - if (value > (1024*1000)) - sprintf(buf, "%.2f MB", float(value) / (1024.f * 1024.f)); - else if (value > 1024) - sprintf(buf, "%llu KB", static_cast(value / 1024)); - else - sprintf(buf, "%llu b", static_cast(value)); + } else if (hsCheckBits(fDisplayFlags, kDisplayFPS)) { + return ST::format("{.2f}", 1000.0f / hsTimer::GetMilliSeconds(value)); + } else if (hsCheckBits(fDisplayFlags, kDisplayTime)) { + return ST::format("{.2f}{}", hsTimer::GetMilliSeconds(value), printType ? ST_LITERAL(" ms") : ST::string()); + } else if (hsCheckBits(fDisplayFlags, kDisplayMem)) { + if (printType) { + if (value > (1024*1000)) { + return ST::format("{.2f} MB", value / (1024.f * 1024.f)); + } else if (value > 1024) { + return ST::format("{} KB", value / 1024); + } else { + return ST::format("{} b", value); + } + } else { + return ST::string::from_uint(value); } - else - sprintf(buf, "%llu", static_cast(value)); + } else { + FATAL("Unhandled stat value type"); + return {}; } } -void plProfileBase::PrintValue(char* buf, bool printType) +ST::string plProfileBase::PrintValue(bool printType) { - IPrintValue(fValue, buf, printType); + return IPrintValue(fValue, printType); } -void plProfileBase::PrintAvg(char* buf, bool printType) +ST::string plProfileBase::PrintAvg(bool printType) { - IPrintValue(fLastAvg, buf, printType); + return IPrintValue(fLastAvg, printType); } -void plProfileBase::PrintMax(char* buf, bool printType) +ST::string plProfileBase::PrintMax(bool printType) { - IPrintValue(fMax, buf, printType); + return IPrintValue(fMax, printType); } //////////////////////////////////////////////////////////////////////////////// -plProfileLaps::LapInfo* plProfileLaps::IFindLap(const char* lapName) +plProfileLaps::LapInfo* plProfileLaps::IFindLap(const ST::string& lapName) { static int lastSearch = 0; @@ -290,13 +268,10 @@ plProfileLaps::LapInfo* plProfileLaps::IFindLap(const char* lapName) return nullptr; } -void plProfileLaps::BeginLap(uint64_t curValue, const char* name) +void plProfileLaps::BeginLap(uint64_t curValue, const ST::string& name) { LapInfo* lap = IFindLap(name); - if (!lap) - { - // Technically we shouldn't hold on to this pointer. However, I think - // it will be ok in all cases, so I'll wait until this blows up + if (!lap) { LapInfo info(name); fLapTimes.push_back(info); lap = &(*(fLapTimes.end()-1)); @@ -306,7 +281,7 @@ void plProfileLaps::BeginLap(uint64_t curValue, const char* name) lap->BeginTiming(curValue); } -void plProfileLaps::EndLap(uint64_t curValue, const char* name) +void plProfileLaps::EndLap(uint64_t curValue, const ST::string& name) { LapInfo* lap = IFindLap(name); @@ -333,9 +308,7 @@ void plProfileLaps::EndFrame() fLapTimes[i].EndFrame(); if (!fLapTimes[i].fUsedThisFrame) { - char buf[200]; - sprintf(buf, "Dropping unused lap %s", fLapTimes[i].GetName()); - hsStatusMessage(buf); + hsStatusMessage(ST::format("Dropping unused lap {}", fLapTimes[i].GetName()).c_str()); fLapTimes.erase(fLapTimes.begin()+i); i--; } @@ -363,11 +336,11 @@ plProfileBase* plProfileLaps::GetLap(int i) /////////////////////////////////////////////////////////////////////////////// -plProfileVar::plProfileVar(const char *name, const char* group, uint8_t flags) : - fGroup(group), +plProfileVar::plProfileVar(ST::string name, ST::string group, uint8_t flags) : + fGroup(std::move(group)), fLaps() { - fName = name; + fName = std::move(name); fDisplayFlags = flags; plProfileManager::Instance().AddTimer(this); fLapsActive = 0; @@ -378,7 +351,7 @@ plProfileVar::~plProfileVar() delete fLaps; } -void plProfileVar::IBeginLap(const char* lapName) +void plProfileVar::IBeginLap(const ST::string& lapName) { if (!fLaps) fLaps = new plProfileLaps; @@ -388,7 +361,7 @@ void plProfileVar::IBeginLap(const char* lapName) BeginTiming(); } -void plProfileVar::IEndLap(const char* lapName) +void plProfileVar::IEndLap(const ST::string& lapName) { EndTiming(); if(fLapsActive) diff --git a/Sources/Plasma/NucleusLib/inc/plProfileManager.h b/Sources/Plasma/NucleusLib/inc/plProfileManager.h index 344fc640f3..476dab7dec 100644 --- a/Sources/Plasma/NucleusLib/inc/plProfileManager.h +++ b/Sources/Plasma/NucleusLib/inc/plProfileManager.h @@ -43,6 +43,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define plProfileManager_h_inc #include "HeadSpin.h" + +#include +#include #include #include "plProfile.h" @@ -88,7 +91,7 @@ class plProfileLaps public: bool fUsedThisFrame; - LapInfo(const char* name) : fUsedThisFrame() { fName = name; fDisplayFlags = kDisplayTime; } + LapInfo(ST::string name) : fUsedThisFrame() { fName = std::move(name); fDisplayFlags = kDisplayTime; } bool operator<(const LapInfo& rhs) const { return fLastAvg < rhs.fLastAvg; } void BeginTiming(uint64_t value) { fValue -= value; } @@ -96,11 +99,11 @@ class plProfileLaps }; std::vector fLapTimes; - LapInfo* IFindLap(const char* lapName); + LapInfo* IFindLap(const ST::string& lapName); public: - void BeginLap(uint64_t curValue, const char* name); - void EndLap(uint64_t curValue, const char* name); + void BeginLap(uint64_t curValue, const ST::string& name); + void EndLap(uint64_t curValue, const ST::string& name); void BeginFrame(); void EndFrame(); diff --git a/Sources/Plasma/PubUtilLib/plAnimation/plAGMasterMod.cpp b/Sources/Plasma/PubUtilLib/plAnimation/plAGMasterMod.cpp index 6a9e596bcb..ccbd51e943 100644 --- a/Sources/Plasma/PubUtilLib/plAnimation/plAGMasterMod.cpp +++ b/Sources/Plasma/PubUtilLib/plAnimation/plAGMasterMod.cpp @@ -242,7 +242,7 @@ bool plAGMasterMod::IEval(double secs, float del, uint32_t dirty) // APPLYANIMATIONS void plAGMasterMod::ApplyAnimations(double time, float elapsed) { - plProfile_BeginLap(ApplyAnimation, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(ApplyAnimation, this->GetKey()->GetUoid().GetObjectName()); // update any fades for (int i = 0; i < fAnimInstances.size(); i++) @@ -252,7 +252,7 @@ void plAGMasterMod::ApplyAnimations(double time, float elapsed) AdvanceAnimsToTime(time); - plProfile_EndLap(ApplyAnimation,this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(ApplyAnimation,this->GetKey()->GetUoid().GetObjectName()); } void plAGMasterMod::AdvanceAnimsToTime(double time) diff --git a/Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.cpp b/Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.cpp index 612716f878..d19b8fb64d 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.cpp +++ b/Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.cpp @@ -817,7 +817,7 @@ bool plAudioSystem::MsgReceive(plMessage* msg) if (plRenderMsg* pRMsg = plRenderMsg::ConvertNoRef( msg )) { //if (fListener) { - plProfile_BeginLap(AudioUpdate, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(AudioUpdate, this->GetKey()->GetUoid().GetObjectName()); if (hsTimer::GetMilliSeconds() - fLastUpdateTimeMs > UPDATE_TIME_MS) { IUpdateSoftSounds(fCurrListenerPos); @@ -827,7 +827,7 @@ bool plAudioSystem::MsgReceive(plMessage* msg) plProfile_EndTiming(SoundEAXUpdate); } } - plProfile_EndLap(AudioUpdate, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(AudioUpdate, this->GetKey()->GetUoid().GetObjectName()); } return true; } diff --git a/Sources/Plasma/PubUtilLib/plDrawable/plDrawableSpans.cpp b/Sources/Plasma/PubUtilLib/plDrawable/plDrawableSpans.cpp index 61a34819c5..2fa789cb9f 100644 --- a/Sources/Plasma/PubUtilLib/plDrawable/plDrawableSpans.cpp +++ b/Sources/Plasma/PubUtilLib/plDrawable/plDrawableSpans.cpp @@ -1222,7 +1222,7 @@ bool plDrawableSpans::MsgReceive( plMessage* msg ) } else if( plRenderMsg::ConvertNoRef( msg ) ) { - plProfile_BeginLap(PalletteHack, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(PalletteHack, this->GetKey()->GetUoid().GetObjectName()); IUpdateMatrixPaletteBoundsHack(); @@ -1233,7 +1233,7 @@ bool plDrawableSpans::MsgReceive( plMessage* msg ) // The pipeline will then clear out those bits as it blends them, and then we simply // re-set them here, since plRenderMsg is sent once before all the rendering is done :) fFakeBlendingSpanVector = fBlendingSpanVector; - plProfile_EndLap(PalletteHack, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(PalletteHack, this->GetKey()->GetUoid().GetObjectName()); return true; } @@ -1433,7 +1433,7 @@ void plDrawableSpans::SortSpan( uint32_t index, plPipeline *pipe ) { plProfile_Inc(FaceSortCalls); - plProfile_BeginLap(FaceSort, "0"); + plProfile_BeginLap(FaceSort, ST_LITERAL("0")); plIcicle *span = (plIcicle *)fSpans[ index ]; plGBufferTriangle *list, temp; @@ -1462,8 +1462,8 @@ void plDrawableSpans::SortSpan( uint32_t index, plPipeline *pipe ) tempTriList.resize(numTris * 3); elem = sortList.data(); - plProfile_EndLap(FaceSort, "0"); - plProfile_BeginLap(FaceSort, "1"); + plProfile_EndLap(FaceSort, ST_LITERAL("0")); + plProfile_BeginLap(FaceSort, ST_LITERAL("1")); hsVector3 vec(w2cMatrix.fMap[2][0], w2cMatrix.fMap[2][1], w2cMatrix.fMap[2][2]); float trans = w2cMatrix.fMap[2][3]; @@ -1478,15 +1478,15 @@ void plDrawableSpans::SortSpan( uint32_t index, plPipeline *pipe ) } elem[i - 1].fNext = nullptr; - plProfile_EndLap(FaceSort, "1"); - plProfile_BeginLap(FaceSort, "2"); + plProfile_EndLap(FaceSort, ST_LITERAL("1")); + plProfile_BeginLap(FaceSort, ST_LITERAL("2")); // Do da sort thingy hsRadixSort rad; hsRadixSort::Elem *sortedList = rad.Sort( elem, 0 ); - plProfile_EndLap(FaceSort, "2"); - plProfile_BeginLap(FaceSort, "3"); + plProfile_EndLap(FaceSort, ST_LITERAL("2")); + plProfile_BeginLap(FaceSort, ST_LITERAL("3")); uint16_t* indices = tempTriList.data(); // Stuff into the temp array @@ -1498,8 +1498,8 @@ void plDrawableSpans::SortSpan( uint32_t index, plPipeline *pipe ) elem = elem->fNext; } - plProfile_EndLap(FaceSort, "3"); - plProfile_BeginLap(FaceSort, "4"); + plProfile_EndLap(FaceSort, ST_LITERAL("3")); + plProfile_BeginLap(FaceSort, ST_LITERAL("4")); /// Now send them on to the buffer group fGroups[ span->fGroupIdx ]->StuffFromTriList( span->fIBufferIdx, span->fIStartIdx, @@ -1515,7 +1515,7 @@ void plDrawableSpans::SortSpan( uint32_t index, plPipeline *pipe ) /// All done! (force buffer groups to refresh during next render call) fReadyToRender = false; - plProfile_EndLap(FaceSort, "4"); + plProfile_EndLap(FaceSort, ST_LITERAL("4")); } //// SortVisibleSpans //////////////////////////////////////////////////////// @@ -1757,7 +1757,7 @@ void plDrawableSpans::SortVisibleSpans(const std::vector& visList, plPi plProfile_EndTiming(FaceSort); - plProfile_BeginLap(FaceSort, "0"); + plProfile_BeginLap(FaceSort, ST_LITERAL("0")); startIndex.resize(fSpans.size()); @@ -1777,7 +1777,7 @@ void plDrawableSpans::SortVisibleSpans(const std::vector& visList, plPi } if( totTris == 0 ) { - plProfile_EndLap(FaceSort, "0"); + plProfile_EndLap(FaceSort, ST_LITERAL("0")); return; } @@ -1788,12 +1788,12 @@ void plDrawableSpans::SortVisibleSpans(const std::vector& visList, plPi hsRadixSort::Elem* elem = sortScratch.data(); - plProfile_EndLap(FaceSort, "0"); + plProfile_EndLap(FaceSort, ST_LITERAL("0")); size_t iVis = 0; while (iVis < visList.size()) { - plProfile_BeginLap(FaceSort, "1"); + plProfile_BeginLap(FaceSort, ST_LITERAL("1")); // Pack them into the sort structure. We probably want to make the // plGBufferTriangle look like plTriSortData (just add span index) @@ -1824,15 +1824,15 @@ void plDrawableSpans::SortVisibleSpans(const std::vector& visList, plPi } elem[cnt-1].fNext = nullptr; - plProfile_EndLap(FaceSort, "1"); - plProfile_BeginLap(FaceSort, "2"); + plProfile_EndLap(FaceSort, ST_LITERAL("1")); + plProfile_BeginLap(FaceSort, ST_LITERAL("2")); // Actual sort hsRadixSort rad; hsRadixSort::Elem* sortedList = rad.Sort( elem, 0 ); - plProfile_EndLap(FaceSort, "2"); - plProfile_BeginLap(FaceSort, "3"); + plProfile_EndLap(FaceSort, ST_LITERAL("2")); + plProfile_BeginLap(FaceSort, ST_LITERAL("3")); counters.assign(fSpans.size(), 0); @@ -1853,10 +1853,10 @@ void plDrawableSpans::SortVisibleSpans(const std::vector& visList, plPi sortedList = sortedList->fNext; } - plProfile_EndLap(FaceSort, "3"); + plProfile_EndLap(FaceSort, ST_LITERAL("3")); } - plProfile_BeginLap(FaceSort, "4"); + plProfile_BeginLap(FaceSort, ST_LITERAL("4")); constexpr size_t kMaxBufferGroups = 20; constexpr size_t kMaxIndexBuffers = 20; @@ -1882,7 +1882,7 @@ void plDrawableSpans::SortVisibleSpans(const std::vector& visList, plPi span->fILength / 3, triList.data() + startIndex[idx]); } - plProfile_EndLap(FaceSort, "4"); + plProfile_EndLap(FaceSort, ST_LITERAL("4")); fReadyToRender = false; diff --git a/Sources/Plasma/PubUtilLib/plGLight/plLightInfo.cpp b/Sources/Plasma/PubUtilLib/plGLight/plLightInfo.cpp index e815fcc3d3..08e49601bb 100644 --- a/Sources/Plasma/PubUtilLib/plGLight/plLightInfo.cpp +++ b/Sources/Plasma/PubUtilLib/plGLight/plLightInfo.cpp @@ -370,7 +370,7 @@ bool plLightInfo::MsgReceive(plMessage* msg) plRenderMsg* rendMsg = plRenderMsg::ConvertNoRef(msg); if( rendMsg ) { - plProfile_BeginLap(LightInfo, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(LightInfo, this->GetKey()->GetUoid().GetObjectName()); if( !fDeviceRef && !GetProperty(kLPShadowOnly) ) { @@ -379,7 +379,7 @@ bool plLightInfo::MsgReceive(plMessage* msg) ICheckMaxStrength(); - plProfile_EndLap(LightInfo, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(LightInfo, this->GetKey()->GetUoid().GetObjectName()); return true; } plGenRefMsg* refMsg = plGenRefMsg::ConvertNoRef(msg); diff --git a/Sources/Plasma/PubUtilLib/plGLight/plShadowCaster.cpp b/Sources/Plasma/PubUtilLib/plGLight/plShadowCaster.cpp index 64429eba8d..fadeb30ed4 100644 --- a/Sources/Plasma/PubUtilLib/plGLight/plShadowCaster.cpp +++ b/Sources/Plasma/PubUtilLib/plGLight/plShadowCaster.cpp @@ -210,9 +210,9 @@ bool plShadowCaster::MsgReceive(plMessage* msg) plRenderMsg* rendMsg = plRenderMsg::ConvertNoRef(msg); if( rendMsg ) { - plProfile_BeginLap(ShadowCaster, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(ShadowCaster, this->GetKey()->GetUoid().GetObjectName()); IOnRenderMsg(rendMsg); - plProfile_EndLap(ShadowCaster, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(ShadowCaster, this->GetKey()->GetUoid().GetObjectName()); return true; } diff --git a/Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp b/Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp index 42d428c28f..b56d58c8f5 100644 --- a/Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp +++ b/Sources/Plasma/PubUtilLib/plGLight/plShadowMaster.cpp @@ -177,9 +177,9 @@ bool plShadowMaster::MsgReceive(plMessage* msg) plRenderMsg* rendMsg = plRenderMsg::ConvertNoRef(msg); if( rendMsg ) { - plProfile_BeginLap(ShadowMaster, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(ShadowMaster, this->GetKey()->GetUoid().GetObjectName()); IBeginRender(); - plProfile_EndLap(ShadowMaster, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(ShadowMaster, this->GetKey()->GetUoid().GetObjectName()); return true; } diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plInputInterfaceMgr.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plInputInterfaceMgr.cpp index b8af1f3916..a875f853ed 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plInputInterfaceMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plInputInterfaceMgr.cpp @@ -290,7 +290,7 @@ void plInputInterfaceMgr::IUpdateCursor( int32_t newCursor ) bool plInputInterfaceMgr::IEval( double secs, float del, uint32_t dirty ) { - const char *inputEval = "Eval"; + const ST::string inputEval = ST_LITERAL("Eval"); plProfile_BeginLap(Input, inputEval); @@ -420,7 +420,7 @@ bool plInputInterfaceMgr::MsgReceive( plMessage *msg ) plInputEventMsg *ieMsg = plInputEventMsg::ConvertNoRef( msg ); if (ieMsg != nullptr) { - const char *inputIEM = "InputEventMsg"; + const ST::string inputIEM = ST_LITERAL("InputEventMsg"); plProfile_BeginLap(Input, inputIEM); bool handled = false; size_t missedInputStartIdx = 0; diff --git a/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleEmitter.cpp b/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleEmitter.cpp index cd6ff83bd3..af59ad77b1 100644 --- a/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleEmitter.cpp +++ b/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleEmitter.cpp @@ -325,7 +325,7 @@ void plParticleEmitter::IUpdateParticles(float delta) if ((fGenerator != nullptr) && (fTimeToLive >= 0)) { - plProfile_BeginLap(ParticleGenerate, fSystem->GetKeyName().c_str()); + plProfile_BeginLap(ParticleGenerate, fSystem->GetKeyName()); if (!fGenerator->AddAutoParticles(this, delta)) { delete fGenerator; @@ -333,7 +333,7 @@ void plParticleEmitter::IUpdateParticles(float delta) } if( (fTimeToLive > 0) && ((fTimeToLive -= delta) <= 0) ) fTimeToLive = -1.f; - plProfile_EndLap(ParticleGenerate, fSystem->GetKeyName().c_str()); + plProfile_EndLap(ParticleGenerate, fSystem->GetKeyName()); } fTargetInfo.fContext = fSystem->fContext; diff --git a/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleSystem.cpp b/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleSystem.cpp index 4e0fb8841e..31178cba6d 100644 --- a/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleSystem.cpp +++ b/Sources/Plasma/PubUtilLib/plParticleSystem/plParticleSystem.cpp @@ -485,9 +485,9 @@ bool plParticleSystem::MsgReceive(plMessage* msg) if ((rend = plRenderMsg::ConvertNoRef(msg))) { - plProfile_BeginLap(ParticleSys, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(ParticleSys, this->GetKey()->GetUoid().GetObjectName()); IHandleRenderMsg(rend->Pipeline()); - plProfile_EndLap(ParticleSys, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(ParticleSys, this->GetKey()->GetUoid().GetObjectName()); return true; } else if ((refMsg = plGenRefMsg::ConvertNoRef(msg))) diff --git a/Sources/Plasma/PubUtilLib/plPhysX/plGenericPhysical.cpp b/Sources/Plasma/PubUtilLib/plPhysX/plGenericPhysical.cpp index a244f8e1c6..f3b1ed0573 100644 --- a/Sources/Plasma/PubUtilLib/plPhysX/plGenericPhysical.cpp +++ b/Sources/Plasma/PubUtilLib/plPhysX/plGenericPhysical.cpp @@ -500,7 +500,7 @@ void plPXPhysical::SendNewLocation(bool synchTransform, bool isSynchUpdate) if (!curl2w.Compare(fCachedLocal2World, .0001f)) { plProfile_Inc(LocationsSent); - plProfile_BeginLap(PhysicsUpdates, GetKeyName().c_str()); + plProfile_BeginLap(PhysicsUpdates, GetKeyName()); if (fCachedLocal2World.GetTranslate().fZ < kMaxNegativeZPos) { @@ -517,7 +517,7 @@ void plPXPhysical::SendNewLocation(bool synchTransform, bool isSynchUpdate) pCorrMsg->Send(); if (fProxyGen) fProxyGen->SetTransform(fCachedLocal2World, w2l); - plProfile_EndLap(PhysicsUpdates, GetKeyName().c_str()); + plProfile_EndLap(PhysicsUpdates, GetKeyName()); } } } diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp index 61a3afda97..8049ef9c44 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp @@ -156,12 +156,12 @@ hsG3DDeviceRecord& hsG3DDeviceRecord::operator=(const hsG3DDeviceRecord& src) return *this; } -const char* hsG3DDeviceRecord::GetG3DDeviceTypeName() const +ST::string hsG3DDeviceRecord::GetG3DDeviceTypeName() const { - static const char* deviceNames[hsG3DDeviceSelector::kNumDevTypes] = { - "Unknown", - "Direct3D", - "OpenGL" + static const ST::string deviceNames[hsG3DDeviceSelector::kNumDevTypes] = { + ST_LITERAL("Unknown"), + ST_LITERAL("Direct3D"), + ST_LITERAL("OpenGL"), }; uint32_t devType = GetG3DDeviceType(); @@ -562,15 +562,13 @@ void hsG3DDeviceSelector::IFudgeDirectXDevice( hsG3DDeviceRecord &record, D3DEnum_RendererInfo *deviceInfo ) { uint32_t vendorID, deviceID; - char *szDriver, *szDesc; - + ST::string driverString; + ST::string descString; /// Send it off to each D3D device, respectively if( record.GetG3DDeviceType() == kDevTypeDirect3D ) { - if( !IGetD3DCardInfo( record, driverInfo, deviceInfo, &vendorID, &deviceID, &szDriver, &szDesc ) ) - { - // {} to make VC6 happy in release build + if (!IGetD3DCardInfo(record, driverInfo, deviceInfo, &vendorID, &deviceID, driverString, descString)) { hsAssert( false, "Trying to fudge D3D device but D3D support isn't in this EXE!" ); } } @@ -580,20 +578,20 @@ void hsG3DDeviceSelector::IFudgeDirectXDevice( hsG3DDeviceRecord &record, } /// So capitalization won't matter in our tests - ST::string desc = ST::string::from_latin_1(szDesc).to_lower(); + descString = descString.to_lower(); /// Detect ATI Radeon chipset // We will probably need to differentiate between different Radeons at some point in // the future, but not now. - ST_ssize_t radeon = desc.find("radeon"); - if (stricmp(szDriver, "ati2dvag.dll") == 0 || radeon >= 0) - { + ST_ssize_t radeon = descString.find("radeon"); + if (driverString.compare_i("ati2dvag.dll") == 0 || radeon >= 0) { int series = 0; if (radeon >= 0) { - const char* str = desc.c_str() + radeon + strlen("radeon"); - if( 1 == sscanf(str, "%d", &series) ) - { + ST::string str = descString.substr(radeon + strlen("radeon")).trim_left(); + ST::conversion_result res; + series = str.to_int(res, 10); + if (res.ok()) { if( (series >= 8000) && (series < 9000) ) { hsStatusMessage( "== Using fudge factors for ATI Radeon 8X00 chipset ==\n" ); @@ -620,15 +618,13 @@ void hsG3DDeviceSelector::IFudgeDirectXDevice( hsG3DDeviceRecord &record, //// Other Cards ////////////////////////////////////////////////////////// /// Detect Intel i810 chipset else if( deviceID == 0x00007125 && - ( stricmp( szDriver, "i81xdd.dll" ) == 0 - || ( desc.find("intel") >= 0 && desc.find("810") >= 0 ) ) ) - { + (driverString.compare_i("i81xdd.dll") == 0 + || (descString.find("intel") >= 0 && descString.find("810") >= 0))) { hsStatusMessage( "== Using fudge factors for an Intel i810 chipset ==\n" ); ISetFudgeFactors( kIntelI810Chipset, record ); } /// Detect for a GeForc FX card. We only need to nerf the really low end one. - else if( desc.find("nvidia") >= 0 && desc.find("geforce fx 5200") >= 0 ) - { + else if (descString.find("nvidia") >= 0 && descString.find("geforce fx 5200") >= 0) { hsStatusMessage( "== Using fudge factors for an NVidia GeForceFX-based chipset ==\n" ); ISetFudgeFactors( kNVidiaGeForceFXChipset, record ); } diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h index 4fef83f979..3dfc1582fd 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h @@ -185,7 +185,7 @@ class hsG3DDeviceRecord hsG3DDeviceRecord& operator=(const hsG3DDeviceRecord& src); uint32_t GetG3DDeviceType() const { return fG3DDeviceType; } - const char* GetG3DDeviceTypeName() const; + ST::string GetG3DDeviceTypeName() const; uint32_t GetG3DHALorHEL() const { return fG3DHALorHEL; } uint32_t GetMemoryBytes() const { return fMemoryBytes; } @@ -326,7 +326,6 @@ class hsG3DDeviceSelector : public hsRefCnt static std::list sEnumerators; std::vector fRecords; - char fErrorString[ 128 ]; void IClear(); void IRemoveDiscarded(); @@ -340,7 +339,7 @@ class hsG3DDeviceSelector : public hsRefCnt uint32_t IAdjustDirectXMemory( uint32_t cardMem ); bool IGetD3DCardInfo( hsG3DDeviceRecord &record, void *driverInfo, void *deviceInfo, - uint32_t *vendorID, uint32_t *deviceID, char **driverString, char **descString ); + uint32_t *vendorID, uint32_t *deviceID, ST::string& driverString, ST::string& descString); void ISetFudgeFactors( uint8_t chipsetID, hsG3DDeviceRecord &record ); diff --git a/Sources/Plasma/PubUtilLib/plPipeline/pl3DPipeline.h b/Sources/Plasma/PubUtilLib/plPipeline/pl3DPipeline.h index 4ff9486fdb..5827a1feb9 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/pl3DPipeline.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/pl3DPipeline.h @@ -43,6 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define _pl3DPipeline_inc_ #include +#include #include #include "plPipeline.h" @@ -683,7 +684,8 @@ class pl3DPipeline : public plPipeline //virtual plMipmap* ExtractMipMap(plRenderTarget* targ) = 0; /** Return the current error string. */ - const char* GetErrorString() override { + ST::string GetErrorString() override + { return fDevice.GetErrorString(); } diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plNullPipeline.h b/Sources/Plasma/PubUtilLib/plPipeline/plNullPipeline.h index 25e23108b8..72c29391c0 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plNullPipeline.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/plNullPipeline.h @@ -59,7 +59,7 @@ class plNullPipelineDevice void SetProjectionMatrix(const hsMatrix44& src) { } void SetWorldToCameraMatrix(const hsMatrix44& src) { } void SetLocalToWorldMatrix(const hsMatrix44& src) { } - const char* GetErrorString() const { return nullptr; } + ST::string GetErrorString() const { return {}; } }; class plNullPipeline : public pl3DPipeline diff --git a/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp b/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp index 6bc73baf7d..331df41f2b 100644 --- a/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plScene/plPageTreeMgr.cpp @@ -212,7 +212,7 @@ size_t plPageTreeMgr::IRenderVisList(plPipeline* pipe, std::vectorGetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(DrawableTime, p->GetKey()->GetUoid().GetObjectName()); if( sortedDrawList[i].fDrawable->GetNativeProperty(plDrawable::kPropSortSpans) ) { @@ -230,7 +230,7 @@ size_t plPageTreeMgr::IRenderVisList(plPipeline* pipe, std::vectorGetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(DrawableTime, p->GetKey()->GetUoid().GetObjectName()); } return numDrawn; diff --git a/Sources/Plasma/PubUtilLib/plScene/plPostEffectMod.cpp b/Sources/Plasma/PubUtilLib/plScene/plPostEffectMod.cpp index c43a317204..6a25afec3d 100644 --- a/Sources/Plasma/PubUtilLib/plScene/plPostEffectMod.cpp +++ b/Sources/Plasma/PubUtilLib/plScene/plPostEffectMod.cpp @@ -232,9 +232,9 @@ bool plPostEffectMod::MsgReceive(plMessage* msg) plRenderMsg* rend = plRenderMsg::ConvertNoRef(msg); if( rend && IIsEnabled() ) { - plProfile_BeginLap(PostEffect, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_BeginLap(PostEffect, this->GetKey()->GetUoid().GetObjectName()); ISubmitRequest(); - plProfile_EndLap(PostEffect, this->GetKey()->GetUoid().GetObjectName().c_str()); + plProfile_EndLap(PostEffect, this->GetKey()->GetUoid().GetObjectName()); return true; } diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp index 4d63a5a30e..14fc37923b 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp @@ -73,7 +73,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plGImage/plMipmap.h" #include -#include +#include +#include class plAutoProfileImp : public plAutoProfile { @@ -83,7 +84,7 @@ class plAutoProfileImp : public plAutoProfile int fNextSpawnPoint; ST::string fLastSpawnPointName; // For profiling a single age - std::string fAgeName; + ST::string fAgeName; bool fLinkedToSingleAge; bool fJustLinkToAges; @@ -103,7 +104,7 @@ class plAutoProfileImp : public plAutoProfile : fNextAge(), fNextSpawnPoint(), fLinkedToSingleAge(), fJustLinkToAges(), fLinkTime() { } - void StartProfile(const char* ageName) override; + void StartProfile(ST::string ageName) override; void LinkToAllAges() override; bool MsgReceive(plMessage* msg) override; @@ -117,12 +118,9 @@ plAutoProfile* plAutoProfile::Instance() //////////////////////////////////////////////////////////////////////////////// -void plAutoProfileImp::StartProfile(const char* ageName) +void plAutoProfileImp::StartProfile(ST::string ageName) { - if (ageName) - fAgeName = ageName; - else - fAgeName = ""; + fAgeName = std::move(ageName); IInit(); @@ -241,22 +239,19 @@ void plAutoProfileImp::INextProfile() bool plAutoProfileImp::INextAge() { - const char* ageName = nullptr; + ST::string ageName; - if (fAgeName.length() > 0) - { + if (!fAgeName.empty()) { if (fLinkedToSingleAge) return false; fLinkedToSingleAge = true; - ageName = fAgeName.c_str(); - } - else - { + ageName = fAgeName; + } else { if (fNextAge >= fAges.size()) return false; - ageName = fAges[fNextAge].c_str(); + ageName = fAges[fNextAge]; } fNextAge++; diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.h b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.h index fa5f6e4a73..9393c0bf2d 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.h +++ b/Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.h @@ -44,6 +44,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnKeyedObject/hsKeyedObject.h" +namespace ST { class string; } + class plAutoProfile : public hsKeyedObject { public: @@ -52,8 +54,8 @@ class plAutoProfile : public hsKeyedObject static plAutoProfile* Instance(); - // If ageName is nil, do all ages - virtual void StartProfile(const char* ageName = nullptr) = 0; + // If ageName is empty, do all ages + virtual void StartProfile(ST::string ageName) = 0; // For when we just want to link to each age, for other reasons (profiling load times) virtual void LinkToAllAges()=0; diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.cpp index 4862cac597..fba2bfc78b 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.cpp @@ -53,7 +53,7 @@ plProfile_CreateMemCounter("Allocated", "Memory", MemAllocated); plProfile_CreateMemCounter("Peak Alloc", "Memory", MemPeakAlloc); #endif -static plProfileVar gVarRFPS("RFPS", "General", plProfileVar::kDisplayTime | plProfileVar::kDisplayFPS); +static plProfileVar gVarRFPS(ST_LITERAL("RFPS"), ST_LITERAL("General"), plProfileVar::kDisplayTime | plProfileVar::kDisplayFPS); plProfile_Extern(DrawTriangles); plProfile_Extern(MatChange); @@ -99,10 +99,9 @@ static bool ICreateStdPlate(plGraphPlate** graph) return false; } -void CreateStandardGraphs(const char* groupName, bool create) +void CreateStandardGraphs(const ST::string& groupName, bool create) { - if (strcmp(groupName, "General") == 0) - { + if (groupName == "General") { if (create) { if (ICreateStdPlate(&fFPSPlate)) diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.h b/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.h index dc843c1fb0..1b058112af 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.h +++ b/Sources/Plasma/PubUtilLib/plStatGather/plCalculatedProfiles.h @@ -40,6 +40,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ +namespace ST { class string; } + void CalculateProfiles(); -void CreateStandardGraphs(const char* groupName, bool create); +void CreateStandardGraphs(const ST::string& groupName, bool create); void UpdateStandardGraphs(float xPos, float yPos); diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp index 0a6cc0d280..357563c33c 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp @@ -73,11 +73,8 @@ void plProfileManagerFull::GetGroups(GroupSet& groups) groups.insert(fVars[i]->GetGroup()); } -void plProfileManagerFull::ShowGroup(const char* groupName) +void plProfileManagerFull::ShowGroup(const ST::string& groupName) { - if (!groupName) - groupName = "General"; - // If we're already showing this group, stop if (fShowGroups.find(groupName) != fShowGroups.end()) { @@ -87,10 +84,10 @@ void plProfileManagerFull::ShowGroup(const char* groupName) } else { - const char* shareGroupName = nullptr; + ST::string shareGroupName; for (int i = 0; i < fVars.size(); i++) { - if (stricmp(fVars[i]->GetGroup(), groupName) == 0) + if (fVars[i]->GetGroup().compare_i(groupName) == 0) { shareGroupName = fVars[i]->GetGroup(); } @@ -98,7 +95,7 @@ void plProfileManagerFull::ShowGroup(const char* groupName) // We do have a group with this name, so insert one of the variable's // pointers to the name into our list (we can hang on to those pointers) - if (shareGroupName) + if (!shareGroupName.empty()) { ISetActive(shareGroupName, true); CreateStandardGraphs(shareGroupName, true); @@ -119,7 +116,7 @@ void plProfileManagerFull::ShowNextGroup() ST::string nextGroup; if (!curGroup.empty()) { - CreateStandardGraphs(curGroup.c_str(), false); + CreateStandardGraphs(curGroup, false); GroupSet::iterator it = groups.find(curGroup); it++; @@ -127,7 +124,7 @@ void plProfileManagerFull::ShowNextGroup() { nextGroup = *it; } - ISetActive(curGroup.c_str(), false); + ISetActive(curGroup, false); } else { @@ -137,8 +134,8 @@ void plProfileManagerFull::ShowNextGroup() fShowGroups.clear(); if (!nextGroup.empty()) { - ISetActive(nextGroup.c_str(), true); - CreateStandardGraphs(nextGroup.c_str(), true); + ISetActive(nextGroup, true); + CreateStandardGraphs(nextGroup, true); fShowGroups.insert(nextGroup); } } @@ -198,7 +195,6 @@ static void PrintColumn(ProfileGroup& group, const ST::string& groupName, int co for (int i = 0; i < group.size(); i++) { - char buf[1024]; ST::string str; switch (column) @@ -220,16 +216,13 @@ static void PrintColumn(ProfileGroup& group, const ST::string& groupName, int co } break; case kColValue: - group[i]->PrintValue(buf); - str = buf; + str = group[i]->PrintValue(); break; case kColAvg: - group[i]->PrintAvg(buf); - str = buf; + str = group[i]->PrintAvg(); break; case kColMax: - group[i]->PrintMax(buf); - str = buf; + str = group[i]->PrintMax(); break; case kColIndex: str = ST::format("[{3d}]", i + off); @@ -304,16 +297,14 @@ void plProfileManagerFull::Update() int maxX = 0; int y = 10; - GroupSet::iterator it; - for (it = fShowGroups.begin(); it != fShowGroups.end(); it++) - { - ST::string groupName = *it; - + for (const ST::string& groupName : fShowGroups) { std::vector group; - for (int i = 0; i < fVars.size(); i++) - if (groupName.compare(fVars[i]->GetGroup()) == 0) + for (int i = 0; i < fVars.size(); i++) { + if (groupName == fVars[i]->GetGroup()) { group.push_back(fVars[i]); + } + } int x = 10; PrintGroup(group, groupName, x, y); @@ -398,21 +389,19 @@ void plProfileManagerFull::ActivateAllStats() } } -void plProfileManagerFull::IPrintGroup(hsStream* s, const char* groupName, bool printTitle) +void plProfileManagerFull::IPrintGroup(hsStream* s, const ST::string& groupName, bool printTitle) { - char buf[256]; - - for (int i = 0; i < fVars.size(); i++) - { + for (int i = 0; i < fVars.size(); i++) { plProfileVar* var = fVars[i]; - if (strcmp(var->GetGroup(), groupName) == 0) - { - if (printTitle) - sprintf(buf, "%s:%s", var->GetGroup(), var->GetName()); - else - var->PrintAvg(buf, false); + if (var->GetGroup() == groupName) { + ST::string str; + if (printTitle) { + str = ST::format("{}:{}", var->GetGroup(), var->GetName()); + } else { + str = var->PrintAvg(false); + } - s->Write(strlen(buf), buf); + s->WriteString(str); s->WriteByte((uint8_t)','); } } @@ -457,30 +446,22 @@ void plProfileManagerFull::ILogStats() GroupSet groups; GetGroups(groups); - GroupSet::iterator it; - if (!exists) { - static const char kSpawn[] = "Spawn"; - s.Write(strlen(kSpawn), kSpawn); - s.WriteByte((uint8_t)','); + s.WriteString(ST_LITERAL("Spawn,")); - for (it = groups.begin(); it != groups.end(); it++) - { - ST::string groupName = *it; - IPrintGroup(&s, groupName.c_str(), true); + for (const ST::string& groupName : groups) { + IPrintGroup(&s, groupName, true); } s.WriteByte((uint8_t)'\r'); s.WriteByte((uint8_t)'\n'); } - s.Write(fLogSpawnName.size(), fLogSpawnName.c_str()); + s.WriteString(fLogSpawnName); s.WriteByte((uint8_t)','); - for (it = groups.begin(); it != groups.end(); it++) - { - ST::string groupName = *it; - IPrintGroup(&s, groupName.c_str()); + for (const ST::string& groupName : groups) { + IPrintGroup(&s, groupName); } s.WriteByte((uint8_t)'\r'); s.WriteByte((uint8_t)'\n'); @@ -492,7 +473,7 @@ void plProfileManagerFull::ILogStats() } -void plProfileManagerFull::ShowLaps(const char* groupName, const char* varName) +void plProfileManagerFull::ShowLaps(const ST::string& groupName, const ST::string& varName) { plProfileVar* var = nullptr; @@ -502,11 +483,9 @@ void plProfileManagerFull::ShowLaps(const char* groupName, const char* varName) for (int i = 0; i < fVars.size(); i++) { - int j = 0; - while(fVars[i]->GetName()[j++] == ' ') {} - if (stricmp(&(fVars[i]->GetName()[j-1]), varName) == 0 && - stricmp(fVars[i]->GetGroup(), groupName) == 0) - { + if (fVars[i]->GetName().trim_left(" ").compare_i(varName) == 0 && + fVars[i]->GetGroup().compare_i(groupName) == 0 + ) { var = fVars[i]; break; } @@ -528,7 +507,7 @@ void plProfileManagerFull::ShowLaps(const char* groupName, const char* varName) fShowLaps->SetLapsActive(true); } -void plProfileManagerFull::CreateGraph(const char* varName, uint32_t min, uint32_t max) +void plProfileManagerFull::CreateGraph(const ST::string& varName, uint32_t min, uint32_t max) { // If the graph is already created, destroy it for (int i = 0; i < fGraphs.size(); i++) @@ -556,16 +535,16 @@ void plProfileManagerFull::CreateGraph(const char* varName, uint32_t min, uint32 void plProfileManagerFull::ResetDefaultDetailVars() { fDetailVars.clear(); - AddDetailVar("ApplyAnimation",0,50); - AddDetailVar("AnimatingPhysicals",0,50); - AddDetailVar("StoppedAnimPhysicals",0,50); - AddDetailVar("DrawableTime",0,50); - AddDetailVar("Polys",0,150000); - AddDetailVar("Step",0,50); - AddDetailVar("LineOfSight",0,50); - AddDetailVar(" PhysicsUpdates",0,50); - AddDetailVar("Stream Shove Time",0,50); - AddDetailVar("RenderSetup",0,50); + AddDetailVar(ST_LITERAL("ApplyAnimation"), 0, 50); + AddDetailVar(ST_LITERAL("AnimatingPhysicals"), 0, 50); + AddDetailVar(ST_LITERAL("StoppedAnimPhysicals"), 0, 50); + AddDetailVar(ST_LITERAL("DrawableTime"), 0, 50); + AddDetailVar(ST_LITERAL("Polys"), 0, 150000); + AddDetailVar(ST_LITERAL("Step"), 0, 50); + AddDetailVar(ST_LITERAL("LineOfSight"), 0, 50); + AddDetailVar(ST_LITERAL(" PhysicsUpdates"), 0, 50); + AddDetailVar(ST_LITERAL("Stream Shove Time"), 0, 50); + AddDetailVar(ST_LITERAL("RenderSetup"), 0, 50); } void plProfileManagerFull::ShowDetailGraph() @@ -593,13 +572,14 @@ void plProfileManagerFull::HideDetailGraph() } } -void plProfileManagerFull::AddDetailVar(const char* varName, uint32_t min, uint32_t max) +void plProfileManagerFull::AddDetailVar(const ST::string& varName, uint32_t min, uint32_t max) { int i=0; for (i=0; iGetName(), varName) == 0) + if (fDetailVars[i].var->GetName().compare_i(varName) == 0) { return; // don't add it again + } } plProfileVar* var = IFindTimer(varName); @@ -617,12 +597,12 @@ void plProfileManagerFull::AddDetailVar(const char* varName, uint32_t min, uint3 UpdateDetailLabels(); } -void plProfileManagerFull::RemoveDetailVar(const char* varName) +void plProfileManagerFull::RemoveDetailVar(const ST::string& varName) { int i=0; for (i=0; iGetName(), varName) == 0) + if (fDetailVars[i].var->GetName().compare_i(varName) == 0) { fDetailVars.erase(fDetailVars.begin()+i); } @@ -664,12 +644,11 @@ void plProfileManagerFull::ResetMax() fVars[i]->ResetMax(); } -void plProfileManagerFull::ISetActive(const char* groupName, bool active) +void plProfileManagerFull::ISetActive(const ST::string& groupName, bool active) { for (int i = 0; i < fVars.size(); i++) { - if (stricmp(fVars[i]->GetGroup(), groupName) == 0) - { + if (fVars[i]->GetGroup().compare_i(groupName) == 0) { fVars[i]->SetActive(active); } } diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h index 1f8bf0dc68..025e01c000 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h +++ b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.h @@ -83,12 +83,12 @@ class plProfileManagerFull plProfileVar* fShowLaps; uint32_t fMinLap; // For Display - void IPrintGroup(hsStream* s, const char* groupName, bool printTitle=false); + void IPrintGroup(hsStream* s, const ST::string& groupName, bool printTitle = false); void ILogStats(); plProfileVar* IFindTimer(const ST::string& name); - void ISetActive(const char* groupName, bool active); + void ISetActive(const ST::string& groupName, bool active); plProfileManagerFull(); @@ -99,24 +99,24 @@ class plProfileManagerFull void Update(); void GetGroups(GroupSet& groups); - void ShowGroup(const char* groupName); + void ShowGroup(const ST::string& groupName); void ShowNextGroup(); - struct LapPair { const char* group; const char* varName; }; + struct LapPair { ST::string group; ST::string varName; }; typedef std::vector LapNames; void GetLaps(LapNames& lapNames); - void ShowLaps(const char* groupName, const char* varName); + void ShowLaps(const ST::string& groupName, const ST::string& varName); void SetMinLap(int m) { fMinLap = m; }; void PageDownLaps() { fMinLap += 40; } void PageUpLaps() { fMinLap = (fMinLap < 40) ? 0 : fMinLap - 40;} - void CreateGraph(const char* varName, uint32_t min, uint32_t max); + void CreateGraph(const ST::string& varName, uint32_t min, uint32_t max); void ResetDefaultDetailVars(); void ShowDetailGraph(); void HideDetailGraph(); - void AddDetailVar(const char* varName, uint32_t min, uint32_t max); - void RemoveDetailVar(const char* varName); + void AddDetailVar(const ST::string& varName, uint32_t min, uint32_t max); + void RemoveDetailVar(const ST::string& varName); void UpdateDetailLabels(); void ResetMax(); diff --git a/Sources/Plasma/PubUtilLib/plSurface/hsGMaterial.cpp b/Sources/Plasma/PubUtilLib/plSurface/hsGMaterial.cpp index 120b1115b4..e344d3e19d 100644 --- a/Sources/Plasma/PubUtilLib/plSurface/hsGMaterial.cpp +++ b/Sources/Plasma/PubUtilLib/plSurface/hsGMaterial.cpp @@ -263,7 +263,7 @@ void hsGMaterial::Read(hsStream *stream, hsResMgr *group) void hsGMaterial::Eval(double secs, uint32_t frame) { - plProfile_BeginLap(MaterialAnims, GetKeyName().c_str()); + plProfile_BeginLap(MaterialAnims, GetKeyName()); for (size_t i = 0; i < GetNumLayers(); i++) { @@ -276,7 +276,7 @@ void hsGMaterial::Eval(double secs, uint32_t frame) fPiggyBacks[i]->Eval(secs, frame, 0); } - plProfile_EndLap(MaterialAnims, GetKeyName().c_str()); + plProfile_EndLap(MaterialAnims, GetKeyName()); } void hsGMaterial::Reset()