Skip to content

Commit

Permalink
Migrate pipelines to ST::string
Browse files Browse the repository at this point in the history
  • Loading branch information
dgelessus committed Mar 29, 2024
1 parent f490ba0 commit 2fd5dd9
Show file tree
Hide file tree
Showing 20 changed files with 195 additions and 228 deletions.
8 changes: 3 additions & 5 deletions Sources/Plasma/Apps/plClient/plClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "plDXVertexShader.h"
#include "plDXPixelShader.h"

#include <string_theory/string>

//// 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(); }
Expand Down Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion Sources/Plasma/FeatureLib/pfDXPipeline/plDXDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class plDXPipeline;
class plRenderTarget;
struct IDirect3DDevice9;
struct IDirect3DSurface9;
namespace ST { class string; }

class plDXDevice
{
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions Sources/Plasma/FeatureLib/pfDXPipeline/plDXDeviceRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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 );
}

Expand Down Expand Up @@ -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;

Expand Down
55 changes: 21 additions & 34 deletions Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -260,16 +262,14 @@ 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

// Create a D3D object to use
IDirect3D9* pD3D = hsGDirect3D::GetDirect3D();
if (!pD3D)
{
strcpy( fEnumeErrorStr, "Cannot load DirectX!" );
fEnumeErrorStr = ST_LITERAL("Cannot load DirectX!");
return;
}

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down
18 changes: 8 additions & 10 deletions Sources/Plasma/FeatureLib/pfDXPipeline/plDXEnumerate.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#ifndef hsGDirect3DTnLEnumerate_h
#define hsGDirect3DTnLEnumerate_h

#include <string_theory/string>
#include <vector>

#include "HeadSpin.h"
Expand All @@ -60,9 +61,9 @@ You can contact Cyan Worlds, Inc. by email [email protected]
struct D3DEnum_ModeInfo
{
D3DDISPLAYMODE fDDmode;
CHAR fStrDesc[40];
ST::string fStrDesc;
BOOL fWindowed;
char fBitDepth;
uint8_t fBitDepth;
DWORD fDDBehavior;
std::vector<D3DFORMAT> fDepthFormats;
std::vector<D3DMULTISAMPLE_TYPE> fFSAATypes;
Expand All @@ -82,7 +83,7 @@ struct D3DEnum_ModeInfo
struct D3DEnum_RendererInfo
{
D3DDEVTYPE fDDType;
CHAR fStrName[40];
ST::string fStrName;
D3DCAPS9 fDDCaps;
BOOL fCanWindow;
BOOL fCompatibleWithDesktop;
Expand Down Expand Up @@ -110,8 +111,8 @@ struct D3DEnum_DisplayInfo
{
GUID fGuid;

CHAR fStrDesc[40];
CHAR fStrName[40];
ST::string fStrDesc;
ST::string fStrName;

unsigned int fMemory;

Expand All @@ -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<D3DEnum_DisplayInfo> fDisplays;

Expand All @@ -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 );
Expand All @@ -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() { return fEnumeErrorStr; }
};


Expand Down
Loading

0 comments on commit 2fd5dd9

Please sign in to comment.