mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-05 05:20:31 +00:00
Issue found with PVS-Studio:
Many instances of a function or expression being used repeatedly, which can lower performance. Fixed it in these cases by creating on local var, reference or pointer that's used instead.
This commit is contained in:
parent
ec63398042
commit
2002d74b78
38 changed files with 465 additions and 371 deletions
|
|
@ -113,9 +113,11 @@ void GuiClockHud::initPersistFields()
|
|||
|
||||
void GuiClockHud::onRender(Point2I offset, const RectI &updateRect)
|
||||
{
|
||||
GFXDrawUtil* drawUtil = GFX->getDrawUtil();
|
||||
|
||||
// Background first
|
||||
if (mShowFill)
|
||||
GFX->getDrawUtil()->drawRectFill(updateRect, mFillColor);
|
||||
drawUtil->drawRectFill(updateRect, mFillColor);
|
||||
|
||||
// Convert ms time into hours, minutes and seconds.
|
||||
S32 time = S32(getTime());
|
||||
|
|
@ -129,13 +131,13 @@ void GuiClockHud::onRender(Point2I offset, const RectI &updateRect)
|
|||
// Center the text
|
||||
offset.x += (getWidth() - mProfile->mFont->getStrWidth((const UTF8 *)buf)) / 2;
|
||||
offset.y += (getHeight() - mProfile->mFont->getHeight()) / 2;
|
||||
GFX->getDrawUtil()->setBitmapModulation(mTextColor);
|
||||
GFX->getDrawUtil()->drawText(mProfile->mFont, offset, buf);
|
||||
GFX->getDrawUtil()->clearBitmapModulation();
|
||||
drawUtil->setBitmapModulation(mTextColor);
|
||||
drawUtil->drawText(mProfile->mFont, offset, buf);
|
||||
drawUtil->clearBitmapModulation();
|
||||
|
||||
// Border last
|
||||
if (mShowFrame)
|
||||
GFX->getDrawUtil()->drawRect(updateRect, mFrameColor);
|
||||
drawUtil->drawRect(updateRect, mFrameColor);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -162,10 +162,12 @@ void GuiHealthTextHud::onRender(Point2I offset, const RectI &updateRect)
|
|||
else
|
||||
mValue = 100 - (100 * control->getDamageValue());
|
||||
}
|
||||
|
||||
GFXDrawUtil* drawUtil = GFX->getDrawUtil();
|
||||
|
||||
// If enabled draw background first
|
||||
if (mShowFill)
|
||||
GFX->getDrawUtil()->drawRectFill(updateRect, mFillColor);
|
||||
drawUtil->drawRectFill(updateRect, mFillColor);
|
||||
|
||||
// Prepare text and center it
|
||||
S32 val = (S32)mValue;
|
||||
|
|
@ -190,11 +192,11 @@ void GuiHealthTextHud::onRender(Point2I offset, const RectI &updateRect)
|
|||
}
|
||||
}
|
||||
|
||||
GFX->getDrawUtil()->setBitmapModulation(tColor);
|
||||
GFX->getDrawUtil()->drawText(mProfile->mFont, offset, buf);
|
||||
GFX->getDrawUtil()->clearBitmapModulation();
|
||||
drawUtil->setBitmapModulation(tColor);
|
||||
drawUtil->drawText(mProfile->mFont, offset, buf);
|
||||
drawUtil->clearBitmapModulation();
|
||||
|
||||
// If enabled draw the border last
|
||||
if (mShowFrame)
|
||||
GFX->getDrawUtil()->drawRect(updateRect, mFrameColor);
|
||||
drawUtil->drawRect(updateRect, mFrameColor);
|
||||
}
|
||||
|
|
@ -301,18 +301,20 @@ void GuiShapeNameHud::drawName(Point2I offset, const char *name, F32 opacity)
|
|||
offset.x -= width / 2;
|
||||
offset.y -= height / 2;
|
||||
|
||||
GFXDrawUtil* drawUtil = GFX->getDrawUtil();
|
||||
|
||||
// Background fill first
|
||||
if (mShowLabelFill)
|
||||
GFX->getDrawUtil()->drawRectFill(RectI(offset, extent), mLabelFillColor);
|
||||
drawUtil->drawRectFill(RectI(offset, extent), mLabelFillColor);
|
||||
|
||||
// Deal with opacity and draw.
|
||||
mTextColor.alpha = opacity;
|
||||
GFX->getDrawUtil()->setBitmapModulation(mTextColor);
|
||||
GFX->getDrawUtil()->drawText(mProfile->mFont, offset + mLabelPadding, name);
|
||||
GFX->getDrawUtil()->clearBitmapModulation();
|
||||
drawUtil->setBitmapModulation(mTextColor);
|
||||
drawUtil->drawText(mProfile->mFont, offset + mLabelPadding, name);
|
||||
drawUtil->clearBitmapModulation();
|
||||
|
||||
// Border last
|
||||
if (mShowLabelFrame)
|
||||
GFX->getDrawUtil()->drawRect(RectI(offset, extent), mLabelFrameColor);
|
||||
drawUtil->drawRect(RectI(offset, extent), mLabelFrameColor);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1171,8 +1171,10 @@ DefineEngineMethod( TSStatic, changeMaterial, void, ( const char* mapTo, Materia
|
|||
return;
|
||||
}
|
||||
|
||||
TSMaterialList* shapeMaterialList = object->getShape()->materialList;
|
||||
|
||||
// Check the mapTo name exists for this shape
|
||||
S32 matIndex = object->getShape()->materialList->getMaterialNameList().find_next(String(mapTo));
|
||||
S32 matIndex = shapeMaterialList->getMaterialNameList().find_next(String(mapTo));
|
||||
if (matIndex < 0)
|
||||
{
|
||||
Con::errorf("TSShape::changeMaterial failed: Invalid mapTo name '%s'", mapTo);
|
||||
|
|
@ -1190,13 +1192,13 @@ DefineEngineMethod( TSStatic, changeMaterial, void, ( const char* mapTo, Materia
|
|||
|
||||
// Replace instances with the new material being traded in. Lets make sure that we only
|
||||
// target the specific targets per inst, this is actually doing more than we thought
|
||||
delete object->getShape()->materialList->mMatInstList[matIndex];
|
||||
object->getShape()->materialList->mMatInstList[matIndex] = newMat->createMatInstance();
|
||||
delete shapeMaterialList->mMatInstList[matIndex];
|
||||
shapeMaterialList->mMatInstList[matIndex] = newMat->createMatInstance();
|
||||
|
||||
// Finish up preparing the material instances for rendering
|
||||
const GFXVertexFormat *flags = getGFXVertexFormat<GFXVertexPNTTB>();
|
||||
FeatureSet features = MATMGR->getDefaultFeatures();
|
||||
object->getShape()->materialList->getMaterialInst(matIndex)->init( features, flags );
|
||||
shapeMaterialList->getMaterialInst(matIndex)->init(features, flags);
|
||||
}
|
||||
|
||||
DefineEngineMethod( TSStatic, getModelFile, const char *, (),,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue