Skip to content

Commit

Permalink
Port plPlates to ST::string
Browse files Browse the repository at this point in the history
  • Loading branch information
dgelessus committed Sep 24, 2023
1 parent 0e08d60 commit 27744db
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 64 deletions.
16 changes: 5 additions & 11 deletions Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9812,9 +9812,8 @@ void plDXPlateManager::IDrawToDevice( plPipeline *pipe )
{
dxPipe->IDrawPlate( plate );

const char *title = plate->GetTitle();
if( plDebugText::Instance().IsEnabled() && title[ 0 ] != 0 )
{
ST::string title = plate->GetTitle();
if (plDebugText::Instance().IsEnabled() && !title.empty()) {
hsPoint3 pt;
pt.Set( 0, -0.5, 0 );
pt = plate->GetTransform() * pt;
Expand All @@ -9830,26 +9829,21 @@ void plDXPlateManager::IDrawToDevice( plPipeline *pipe )
hsPoint3 pt, pt2;
int i;

if( graph->GetLabelText( 0 )[ 0 ] != 0 )
{
uint32_t numLabels = graph->GetNumLabels();
if (numLabels > 0) {
/// Draw key
const char *str;

pt.Set( -0.5, -0.5, 0 );
pt = plate->GetTransform() * pt;
pt.fX = pt.fX * scrnWidthDiv2 + scrnWidthDiv2;
pt.fY = pt.fY * scrnHeightDiv2 + scrnHeightDiv2;
pt.fY += plDebugText::Instance().GetFontHeight();

uint32_t numLabels = graph->GetNumLabels();
if (numLabels > graph->GetNumColors())
numLabels = graph->GetNumColors();

for( i = 0; i < numLabels; i++ )
{
str = graph->GetLabelText( i );
if( str[ 0 ] == 0 )
break;
ST::string str = graph->GetLabelText(i);

pt2 = pt;
pt2.fX -= plDebugText::Instance().CalcStringWidth( str );
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/PubUtilLib/plAudio/plSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ void plSound::IUpdateDebugPlate()
fDebugPlate->SetPosition( -0.5, 0 );
fDebugPlate->SetDataRange( 0, 100, 100 );
fDebugPlate->SetColors( 0x80202000 );
fDebugPlate->SetLabelText( "Desired", "Curr", "Soft", "Dist" );
fDebugPlate->SetLabelText({ST_LITERAL("Desired"), ST_LITERAL("Curr"), ST_LITERAL("Soft"), ST_LITERAL("Dist")});
}

fDebugPlate->SetTitle(GetKeyName().c_str()); // Bleah
fDebugPlate->SetTitle(GetKeyName()); // Bleah
fDebugPlate->SetVisible( true );
fDebugPlate->AddData( (int32_t)( fDesiredVol * 100.f ),
(int32_t)( fCurrVolume * 100.f ),
Expand Down
11 changes: 6 additions & 5 deletions Sources/Plasma/PubUtilLib/plAudio/plVoiceChat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ void plVoiceRecorder::ShowGraph(bool b)
if (!fGraph) {
plPlateManager::Instance().CreateGraphPlate(&fGraph);
fGraph->SetDataRange(0, 100, 100);
fGraph->SetLabelText("Voice Send Rate");
fGraph->SetTitle("Voice Recorder");
fGraph->SetLabelText({ST_LITERAL("Voice Send Rate")});
fGraph->SetTitle(ST_LITERAL("Voice Recorder"));
}

fGraph->SetSize(.4f, .25f);
Expand Down Expand Up @@ -205,8 +205,9 @@ void plVoiceRecorder::SetMicOpen(bool b)
fCaptureOpenSecs = hsTimer::GetSeconds<float>();
} else {
plgAudioSys::EndCapture();
if (fGraph)
fGraph->SetTitle("Voice Recorder");
if (fGraph) {
fGraph->SetTitle(ST_LITERAL("Voice Recorder"));
}
}
DrawTalkIcon(b);
fMicOpen = b;
Expand Down Expand Up @@ -317,7 +318,7 @@ void plVoiceRecorder::Update(double time)
float sendRate = ((float)bytesSent / (now - fCaptureOpenSecs)) / 1024.f;
// Scale the graph such that 8 KiB/s is the max
fGraph->AddData((int32_t)((100.f * sendRate) / 8.f));
fGraph->SetTitle(ST::format("{.2f} KiB/s", sendRate).c_str());
fGraph->SetTitle(ST::format("{.2f} KiB/s", sendRate));
}
fCaptureOpenSecs = now;
}
Expand Down
29 changes: 0 additions & 29 deletions Sources/Plasma/PubUtilLib/plPipeline/plPlates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ plPlate::plPlate( plPlate **owningHandle )
fPrevPtr = nullptr;
fOwningHandle = owningHandle;
fMipmap = nullptr;
memset( fTitle, 0, sizeof( fTitle ) );
}

plPlate::~plPlate()
Expand Down Expand Up @@ -300,7 +299,6 @@ bool plPlate::IsVisible()
plGraphPlate::plGraphPlate( plPlate **owningHandle ) : plPlate( owningHandle )
{
fFlags |= kFlagIsAGraph;
SetLabelText(nullptr);
}

plGraphPlate::~plGraphPlate()
Expand Down Expand Up @@ -533,33 +531,6 @@ void plGraphPlate::SetDataColors( const std::vector<uint32_t> & hexColors )
fDataHexColors = hexColors;
}

//// SetLabelText ////////////////////////////////////////////////////////////

void plGraphPlate::SetLabelText(const char *text1, const char *text2, const char *text3, const char *text4 )
{
std::vector<std::string> strings;
if (text1 != nullptr)
strings.push_back(text1);
else
strings.push_back("");

if (text2 != nullptr)
strings.push_back(text2);
else
strings.push_back("");

if (text3 != nullptr)
strings.push_back(text3);
else
strings.push_back("");

if (text4 != nullptr)
strings.push_back(text4);
else
strings.push_back("");
SetLabelText(strings);
}

//// IDrawNumber /////////////////////////////////////////////////////////////

void plGraphPlate::IDrawNumber( uint32_t number, uint32_t *dataPtr, uint32_t stride, uint32_t color )
Expand Down
15 changes: 7 additions & 8 deletions Sources/Plasma/PubUtilLib/plPipeline/plPlates.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include "HeadSpin.h"

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

#include "hsColorRGBA.h"
Expand Down Expand Up @@ -81,7 +81,7 @@ class plPlate
plMipmap *fMipmap;
float fDepth, fOpacity;
uint32_t fFlags;
char fTitle[ 64 ];
ST::string fTitle;

plPlate *fNext;
plPlate **fPrevPtr;
Expand Down Expand Up @@ -122,11 +122,11 @@ class plPlate
void SetTransform( hsMatrix44 &matrix, bool reSort = true );
void SetMaterial( hsGMaterial *material );
void SetTexture(plBitmap *texture); // Creates a new single layer material to use the texture.
void SetTitle(const char *title) { if (title != nullptr) strncpy(fTitle, title, sizeof(fTitle)); else fTitle[0] = 0; }
void SetTitle(ST::string title) { fTitle = std::move(title); }

hsGMaterial *GetMaterial() { return fMaterial; }
hsMatrix44 &GetTransform() { return fXformMatrix; }
const char *GetTitle() { return fTitle; }
ST::string GetTitle() { return fTitle; }
uint32_t GetFlags() { return fFlags; }
const plMipmap *GetMipmap() { return fMipmap; }

Expand Down Expand Up @@ -160,7 +160,7 @@ class plGraphPlate : public plPlate
std::vector<uint32_t> fDataHexColors;
uint32_t fMin, fMax, fLabelMin, fLabelMax;
std::vector<int32_t> fLastValues;
std::vector<std::string> fLabelText;
std::vector<ST::string> fLabelText;

uint32_t IMakePow2( uint32_t value );
void IDrawNumber( uint32_t number, uint32_t *dataPtr, uint32_t stride, uint32_t color );
Expand All @@ -172,8 +172,7 @@ class plGraphPlate : public plPlate

void SetDataRange( uint32_t min, uint32_t max, uint32_t width );
void SetDataLabels( uint32_t min, uint32_t max );
void SetLabelText(const char *text1, const char *text2 = nullptr, const char *text3 = nullptr, const char *text4 = nullptr);
void SetLabelText(std::vector<std::string> text) { fLabelText = std::move(text); }
void SetLabelText(std::vector<ST::string> text) { fLabelText = std::move(text); }
void ClearData();

void AddData( int32_t value, int32_t value2 = -1, int32_t value3 = -1, int32_t value4 = -1 );
Expand All @@ -183,7 +182,7 @@ class plGraphPlate : public plPlate
void SetDataColors( uint32_t hexColor1 = 0xff00ff00, uint32_t hexColor2 = 0xff0000ff, uint32_t hexColor3 = 0xffffff00, uint32_t hexColor4 = 0xffff00ff );
void SetDataColors( const std::vector<uint32_t> & hexColors );

const char *GetLabelText( int i ) { return fLabelText[ i ].c_str(); }
ST::string GetLabelText(int i) { return fLabelText[i]; }
uint32_t GetDataColor( int i ) { return fDataHexColors[ i ]; }
uint32_t GetNumLabels() { return (uint32_t)fLabelText.size(); }
uint32_t GetNumColors() { return (uint32_t)fDataHexColors.size(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ void CreateStandardGraphs(const char* groupName, bool create)
{
if (ICreateStdPlate(&fFPSPlate))
{
fFPSPlate->SetTitle("mSecs");
fFPSPlate->SetLabelText("Tot", "Draw", "Upd");
fFPSPlate->SetTitle(ST_LITERAL("mSecs"));
fFPSPlate->SetLabelText({ST_LITERAL("Tot"), ST_LITERAL("Draw"), ST_LITERAL("Upd")});
}
}
else
Expand Down
12 changes: 6 additions & 6 deletions Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ void plProfileManagerFull::ShowNextGroup()
}
}

plProfileVar* plProfileManagerFull::IFindTimer(const char *name)
plProfileVar* plProfileManagerFull::IFindTimer(const ST::string& name)
{
for (int i = 0; i < fVars.size(); i++)
{
if (stricmp(fVars[i]->GetName(), name) == 0)
if (name.compare_i(fVars[i]->GetName()) == 0) {
return fVars[i];
}
}

return nullptr;
Expand Down Expand Up @@ -532,8 +533,7 @@ void plProfileManagerFull::CreateGraph(const char* varName, uint32_t min, uint32
// If the graph is already created, destroy it
for (int i = 0; i < fGraphs.size(); i++)
{
if (strcmp(fGraphs[i]->GetTitle(), varName) == 0)
{
if (fGraphs[i]->GetTitle() == varName) {
plPlateManager::Instance().DestroyPlate(fGraphs[i]);
fGraphs.erase(fGraphs.begin()+i);
return;
Expand Down Expand Up @@ -580,7 +580,7 @@ void plProfileManagerFull::ShowDetailGraph()
fDetailGraph->SetSize(0.9f, 0.9f);
fDetailGraph->SetDataRange(0,500,500);
fDetailGraph->SetDataLabels(0,100); // should be relatively simple to cast everything to a 0-100 range
fDetailGraph->SetTitle("Detail");
fDetailGraph->SetTitle(ST_LITERAL("Detail"));
UpdateDetailLabels();
}

Expand Down Expand Up @@ -635,7 +635,7 @@ void plProfileManagerFull::UpdateDetailLabels()
if (fDetailGraph)
{
int i;
std::vector<std::string> labels;
std::vector<ST::string> labels;
for (i=0; i<fDetailVars.size(); i++)
labels.push_back(fDetailVars[i].var->GetName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class plProfileManagerFull
void IPrintGroup(hsStream* s, const char* groupName, bool printTitle=false);
void ILogStats();

plProfileVar* IFindTimer(const char* name);
plProfileVar* IFindTimer(const ST::string& name);

void ISetActive(const char* groupName, bool active);

Expand Down

0 comments on commit 27744db

Please sign in to comment.