Skip to content

Commit

Permalink
Fix const-correctness issues with hsTArray's operator[]
Browse files Browse the repository at this point in the history
  • Loading branch information
zrax committed Jan 20, 2021
1 parent 7e9bb1c commit 8870649
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Sources/Plasma/Apps/plClient/plClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ bool plClient::InitPipeline()
// find our resolution if we're not in windowed mode
for ( int i = 0; i < rec->GetModes().GetCount(); i++ )
{
hsG3DDeviceMode *mode = rec->GetMode(i);
const hsG3DDeviceMode *mode = rec->GetMode(i);
if ((mode->GetWidth() == plPipeline::fInitialPipeParams.Width) &&
(mode->GetHeight() == plPipeline::fInitialPipeParams.Height) &&
(mode->GetColorDepth() == plPipeline::fInitialPipeParams.ColorDepth))
Expand Down
3 changes: 2 additions & 1 deletion Sources/Plasma/CoreLib/hsTemplates.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ template <class T> class hsTArray : public hsTArrayBase

void Set(int index, const T& item) { hsTArray_ValidateIndex(index); fArray[index]=item; }
const T& Get(int index) const { hsTArray_ValidateIndex(index); return fArray[index]; }
T& operator[](int index) const { hsTArray_ValidateIndex(index); return fArray[index]; }
T& operator[](int index) { hsTArray_ValidateIndex(index); return fArray[index]; }
const T& operator[](int index) const { hsTArray_ValidateIndex(index); return fArray[index]; }

int Count() const { return fUseCount; }
int GetCount() const { return fUseCount; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const char *pfConsoleContext::GetVarName( uint32_t idx ) const
return fVarNames[ idx ];
}

pfConsoleCmdParam &pfConsoleContext::GetVarValue( uint32_t idx ) const
const pfConsoleCmdParam &pfConsoleContext::GetVarValue(uint32_t idx) const
{
hsAssert( fVarValues.GetCount() == fVarNames.GetCount(), "Mismatch in console var context arrays" );
hsAssert( idx < fVarValues.GetCount(), "GetVarValue() index out of range for console context" );
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class pfConsoleContext

uint32_t GetNumVars() const;
const char *GetVarName( uint32_t idx ) const;
pfConsoleCmdParam &GetVarValue( uint32_t idx ) const;
const pfConsoleCmdParam &GetVarValue(uint32_t idx) const;

int32_t FindVar( const char *name ) const;
void RemoveVar( uint32_t idx );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void plAgeDescription::RemovePage( const ST::string &page )
}
}

plAgePage *plAgeDescription::FindPage( const ST::string &name ) const
const plAgePage *plAgeDescription::FindPage(const ST::string &name) const
{
for (int i = 0; i < fPages.GetCount(); i++)
{
Expand All @@ -256,7 +256,7 @@ plAgePage *plAgeDescription::FindPage( const ST::string &name ) const

plLocation plAgeDescription::CalcPageLocation( const ST::string &page ) const
{
plAgePage *ap = FindPage( page );
const plAgePage *ap = FindPage(page);
if( ap != nil )
{
// Combine our sequence # together
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class plAgeDescription : public plInitSectionTokenReader
void SeekFirstPage();
plAgePage *GetNextPage();
int GetNumPages() const { return fPages.GetCount(); }
plAgePage *FindPage( const ST::string &name ) const;
const plAgePage *FindPage(const ST::string &name) const;
bool FindLocation(const plLocation& loc) const;
plLocation CalcPageLocation( const ST::string &page ) const;

Expand Down
3 changes: 2 additions & 1 deletion Sources/Plasma/PubUtilLib/plDrawable/plDrawableSpans.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class plDISpanIndex
void Reset() { fFlags = kNone; fIndices.Reset(); }
void SetCountAndZero(int c) { fIndices.SetCountAndZero(c); }
uint32_t GetCount() const { return fIndices.GetCount(); }
uint32_t& operator[](int i) const { return fIndices[i]; }
uint32_t& operator[](int i) { return fIndices[i]; }
uint32_t operator[](int i) const { return fIndices[i]; }
};

struct hsColorRGBA;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/PubUtilLib/plDrawable/plMorphArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class plMorphArray
void AddDelta(const plMorphDelta& delta);

int GetNumDeltas() const { return fDeltas.GetCount(); }
float GetWeight(int iDel) { return fDeltas[iDel].GetWeight(); }
float GetWeight(int iDel) const { return fDeltas[iDel].GetWeight(); }
void SetWeight(int iDel, float w) { if( iDel < fDeltas.GetCount() )fDeltas[iDel].SetWeight(w); }
};

Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/PubUtilLib/plDrawable/plMorphDelta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void plMorphDelta::Apply(hsTArray<plAccessSpan>& dst, float weight /* = -1.f */)
{
plAccessVtxSpan& vtxDst = dst[iSpan].AccessVtx();

plMorphSpan& span = fSpans[iSpan];
const plMorphSpan& span = fSpans[iSpan];

// For each vertDelta
const hsPoint3* uvwDel = span.fUVWs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ HRESULT plDXPixelShader::ISetConstants(plDXPipeline* pipe)
if( fOwner->GetNumConsts() )
{
HRESULT hr = pipe->GetD3DDevice()->SetPixelShaderConstantF(0,
(float*)fOwner->GetConstBasePtr(),
(const float*)fOwner->GetConstBasePtr(),
fOwner->GetNumConsts());
if( FAILED(hr) )
return IOnError(hr, "Error setting constants");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ HRESULT plDXVertexShader::ISetConstants(plDXPipeline* pipe)
if( fOwner->GetNumConsts() )
{
HRESULT hr = pipe->GetD3DDevice()->SetVertexShaderConstantF(0,
(float*)fOwner->GetConstBasePtr(),
(const float*)fOwner->GetConstBasePtr(),
fOwner->GetNumConsts());
if( FAILED(hr) )
return IOnError(hr, "Failure setting vertex shader constants");
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class hsG3DDeviceRecord

hsTArray<hsG3DDeviceMode>& GetModes() { return fModes; }

hsG3DDeviceMode* GetMode(int i) const { return &fModes[i]; }
const hsG3DDeviceMode* GetMode(int i) const { return &fModes[i]; }

void ClearModes();
void Clear();
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/PubUtilLib/plScene/plOccluder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void plOccluder::Write(hsStream* s, hsResMgr* mgr)
fWorldBounds.Write(s);
s->WriteLEScalar(fPriority);

const hsTArray<plCullPoly>& localPolys = IGetLocalPolyList();
hsTArray<plCullPoly>& localPolys = IGetLocalPolyList();
s->WriteLE16(localPolys.GetCount());
int i;
for( i = 0; i < localPolys.GetCount(); i++ )
Expand Down
3 changes: 2 additions & 1 deletion Sources/Plasma/PubUtilLib/plSurface/plShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class plShaderConst
};

float& operator[](int i) { return fArray[i]; }
float operator[](int i) const { return fArray[i]; }

void Read(hsStream* s);
void Write(hsStream* s);
Expand Down Expand Up @@ -257,7 +258,7 @@ class plShader : public hsKeyedObject
hsGDeviceRef* GetDeviceRef() const { return fDeviceRef; }
void SetDeviceRef(hsGDeviceRef* ref) const;

void* GetConstBasePtr() const { return fConsts.GetCount() ? &fConsts[0] : nil; }
const void* GetConstBasePtr() const { return fConsts.GetCount() ? &fConsts[0] : nil; }

void CopyConsts(const plShader* src) { fConsts = src->fConsts; }

Expand Down
4 changes: 2 additions & 2 deletions Sources/Tools/MaxMain/plPluginResManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ plLocation plPluginResManager::ICreateLocation(const ST::string& age, const ST::

// If we have an age description file for the age we're creating a location
// for, grab some extra flags from it
plAgeDescription* ageDesc = plPageInfoUtils::GetAgeDesc(age.c_str());
plAgePage* agePage = ageDesc ? ageDesc->FindPage(page.c_str()) : nil;
plAgeDescription* ageDesc = plPageInfoUtils::GetAgeDesc(age);
const plAgePage* agePage = ageDesc ? ageDesc->FindPage(page) : nullptr;
if (agePage)
{
if (agePage->GetFlags() & plAgePage::kIsLocalOnly)
Expand Down

0 comments on commit 8870649

Please sign in to comment.