From 6a8a6ed56c240f70c18e18801aea68f5d173f070 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Tue, 3 Oct 2023 13:03:47 +0200 Subject: [PATCH] Migrate pipelines to ST::string --- Sources/Plasma/Apps/plClient/plClient.cpp | 8 +- .../FeatureLib/pfDXPipeline/plDXDevice.cpp | 6 +- .../FeatureLib/pfDXPipeline/plDXDevice.h | 3 +- .../pfDXPipeline/plDXDeviceRefs.cpp | 6 +- .../FeatureLib/pfDXPipeline/plDXEnumerate.cpp | 55 ++--- .../FeatureLib/pfDXPipeline/plDXEnumerate.h | 18 +- .../FeatureLib/pfDXPipeline/plDXPipeline.cpp | 210 ++++++++---------- .../FeatureLib/pfDXPipeline/plDXPipeline.h | 16 +- .../pfDXPipeline/plDXPixelShader.cpp | 11 +- .../FeatureLib/pfDXPipeline/plDXSettings.h | 3 +- .../FeatureLib/pfDXPipeline/plDXShader.cpp | 9 +- .../FeatureLib/pfDXPipeline/plDXShader.h | 3 +- .../pfDXPipeline/plDXVertexShader.cpp | 11 +- .../FeatureLib/pfGLPipeline/plGLDevice.h | 6 +- Sources/Plasma/NucleusLib/inc/plPipeline.h | 2 +- .../plPipeline/hsG3DDeviceSelector.cpp | 40 ++-- .../plPipeline/hsG3DDeviceSelector.h | 5 +- .../PubUtilLib/plPipeline/pl3DPipeline.h | 4 +- .../PubUtilLib/plPipeline/plNullPipeline.h | 2 +- 19 files changed, 192 insertions(+), 226 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index a7a7d347e4..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; } 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 13babbef9f..18c746a0a1 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_SelectDefaultDriver(0); if( !GetCurrentDriver() || !GetCurrentDevice() ) { - 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_SelectDefaultDriver( DWORD dwFlags ) hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate() { - memset( &fEnumeErrorStr[0], 0x00, sizeof(fEnumeErrorStr) ); - fCurrentDriver = nullptr; // The selected DD driver fDrivers.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_DeviceInfo& deviceInfo = drivInfo->fDevices.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_DriverInfo *driverD3DInfo = (D3DEnum_DriverInfo *)driverInfo; D3DEnum_DeviceInfo *deviceD3DInfo = (D3DEnum_DeviceInfo *)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_DriverInfo* 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 7f22a838fb..9021ca01bd 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_DeviceInfo { D3DDEVTYPE fDDType; - CHAR fStrName[40]; + ST::string fStrName; D3DCAPS9 fDDCaps; BOOL fCanWindow; BOOL fCompatibleWithDesktop; @@ -110,8 +111,8 @@ struct D3DEnum_DriverInfo { 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 fDrivers; @@ -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_SelectDefaultDriver( DWORD dwFlags ); @@ -177,8 +176,7 @@ class hsGDirect3DTnLEnumerate void SetCurrentDevice(D3DEnum_DeviceInfo* d) { hsAssert(GetCurrentDriver(), "Set Driver first"); GetCurrentDriver()->fCurrentDevice = d; } void SetCurrentMode(D3DEnum_ModeInfo* m) { hsAssert(GetCurrentDriver(), "Set Driver first"); GetCurrentDriver()->fCurrentMode = m; } - char* GetEnumeErrorStr() { return fEnumeErrorStr; } - void SetEnumeErrorStr(const char* s); + ST::string GetEnumeErrorStr() { return fEnumeErrorStr; } }; diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp index a9ed50f25f..84f67347bc 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::ISetCurrentDriver( D3DEnum_DriverInfo *driv ) fCurrentDriver = new D3DEnum_DriverInfo; fCurrentDriver->fGuid = driv->fGuid; - hsStrncpy( fCurrentDriver->fStrDesc, driv->fStrDesc, 40 ); - hsStrncpy( fCurrentDriver->fStrName, driv->fStrName, 40 ); + fCurrentDriver->fStrDesc = driv->fStrDesc; + fCurrentDriver->fStrName = driv->fStrName; fCurrentDriver->fDesktopMode = driv->fDesktopMode; fCurrentDriver->fAdapterInfo = driv->fAdapterInfo; @@ -1185,7 +1184,7 @@ void plDXPipeline::ISetCurrentDevice( D3DEnum_DeviceInfo *dev ) delete fCurrentDevice; fCurrentDevice = new D3DEnum_DeviceInfo; - hsStrncpy( fCurrentDevice->fStrName, dev->fStrName, 40 ); + fCurrentDevice->fStrName = dev->fStrName; fCurrentDevice->fDDCaps = dev->fDDCaps; fCurrentDevice->fDDType = dev->fDDType; @@ -1209,7 +1208,7 @@ void plDXPipeline::ISetCurrentDevice( D3DEnum_DeviceInfo *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; fCurrentDevice->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 cb0c1361e1..4b5c6a8f19 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 174658b278..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" @@ -110,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/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/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp index 402f2cea42..9e1d0784b0 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_DeviceInfo *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 e0760deca5..5916128d94 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