Minor code cleanup

Mostly const fixes in headers to make it easier for users to have more warnings enabled in static code analysis
Also updating our own rules a bit (kicking some out we won't need yet).

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6583 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2024-01-01 15:29:28 +00:00
parent 2fdb1fc156
commit bff1a50c34
14 changed files with 53 additions and 59 deletions

@ -280,7 +280,7 @@ protected:
void IProfiler::start(s32 id)
{
s32 idx = ProfileDatas.binary_search(SProfileData(id));
const s32 idx = ProfileDatas.binary_search(SProfileData(id));
if ( idx >= 0 && Timer )
{
++ProfileDatas[idx].StartStopCounter;
@ -352,7 +352,7 @@ void IProfiler::add(s32 id, const core::stringw &name, const core::stringw &grou
}
SProfileData data(id);
s32 idx = ProfileDatas.binary_search(data);
const s32 idx = ProfileDatas.binary_search(data);
if ( idx < 0 )
{
data.reset();
@ -422,7 +422,7 @@ bool IProfiler::findGroupIndex(u32 & result, const core::stringw &name) const
void IProfiler::resetDataById(s32 id)
{
s32 idx = ProfileDatas.binary_search(SProfileData(id));
const s32 idx = ProfileDatas.binary_search(SProfileData(id));
if ( idx >= 0 )
{
resetDataByIndex((u32)idx);

@ -207,7 +207,7 @@ class aabbox3d
\return Interpolated box. */
aabbox3d<T> getInterpolated(const aabbox3d<T>& other, f32 d) const
{
f32 inv = 1.0f - d;
const f32 inv = 1.0f - d;
return aabbox3d<T>((other.MinEdge*inv) + (MinEdge*d),
(other.MaxEdge*inv) + (MaxEdge*d));
}

@ -195,7 +195,7 @@ namespace core
\return Interpolated dimension. */
dimension2d<T> getInterpolated(const dimension2d<T>& other, f32 d) const
{
f32 inv = (1.0f - d);
const f32 inv = (1.0f - d);
return dimension2d<T>( (T)(other.Width*inv + Width*d), (T)(other.Height*inv + Height*d));
}

@ -45,18 +45,17 @@ inline void heapsort(T* array_, s32 size)
// the maximum always +2 and the element always +1
T* virtualArray = array_ - 1;
s32 virtualSize = size + 2;
s32 i;
const s32 virtualSize = size + 2;
// build heap
for (i=((size-1)/2); i>=0; --i)
for (s32 i=((size-1)/2); i>=0; --i)
heapsink(virtualArray, i+1, virtualSize-1);
// sort array, leave out the last element (0)
for (i=size-1; i>0; --i)
for (s32 i=size-1; i>0; --i)
{
T t = array_[0];
const T t = array_[0];
array_[0] = array_[i];
array_[i] = t;
heapsink(virtualArray, 1, i + 1);

@ -915,7 +915,7 @@ class map
//! Returns a Constiterator
ConstIterator getConstIterator() const
{
Iterator it(getRoot());
const Iterator it(getRoot());
return it;
}

@ -710,7 +710,7 @@ namespace core
}
return *this;
#else
CMatrix4<T> temp ( *this );
const CMatrix4<T> temp ( *this );
return setbyproduct_nocheck( temp, other );
#endif
}
@ -1186,7 +1186,7 @@ namespace core
template <class T>
inline void CMatrix4<T>::rotateVect( vector3df& vect ) const
{
vector3d<T> tmp(static_cast<T>(vect.X), static_cast<T>(vect.Y), static_cast<T>(vect.Z));
const vector3d<T> tmp(static_cast<T>(vect.X), static_cast<T>(vect.Y), static_cast<T>(vect.Z));
vect.X = static_cast<f32>(tmp.X*M[0] + tmp.Y*M[4] + tmp.Z*M[8]);
vect.Y = static_cast<f32>(tmp.X*M[1] + tmp.Y*M[5] + tmp.Z*M[9]);
vect.Z = static_cast<f32>(tmp.X*M[2] + tmp.Y*M[6] + tmp.Z*M[10]);
@ -1213,7 +1213,7 @@ namespace core
template <class T>
inline void CMatrix4<T>::inverseRotateVect( vector3df& vect ) const
{
vector3d<T> tmp(static_cast<T>(vect.X), static_cast<T>(vect.Y), static_cast<T>(vect.Z));
const vector3d<T> tmp(static_cast<T>(vect.X), static_cast<T>(vect.Y), static_cast<T>(vect.Z));
vect.X = static_cast<f32>(tmp.X*M[0] + tmp.Y*M[1] + tmp.Z*M[2]);
vect.Y = static_cast<f32>(tmp.X*M[4] + tmp.Y*M[5] + tmp.Z*M[6]);
vect.Z = static_cast<f32>(tmp.X*M[8] + tmp.Y*M[9] + tmp.Z*M[10]);
@ -1278,7 +1278,7 @@ namespace core
transformVect(member, plane.getMemberPoint());
// Transform the normal by the transposed inverse of the matrix
CMatrix4<T> transposedInverse(*this, EM4CONST_INVERSE_TRANSPOSED);
const CMatrix4<T> transposedInverse(*this, EM4CONST_INVERSE_TRANSPOSED);
vector3df normal = plane.Normal;
transposedInverse.rotateVect(normal);
plane.setPlane(member, normal.normalize());
@ -2002,7 +2002,7 @@ namespace core
t.normalize();
// axis multiplication by sin
core::vector3df vs(t.crossProduct(f));
const core::vector3df vs(t.crossProduct(f));
// axis of rotation
core::vector3df v(vs);

@ -107,8 +107,8 @@ class plane3d
f32 getKnownIntersectionWithLine(const vector3d<T>& linePoint1,
const vector3d<T>& linePoint2) const
{
vector3d<T> vect = linePoint2 - linePoint1;
T t2 = (f32)Normal.dotProduct(vect);
const vector3d<T> vect = linePoint2 - linePoint1;
const T t2 = (f32)Normal.dotProduct(vect);
return (f32)-((Normal.dotProduct(linePoint1) + D) / t2);
}

@ -88,10 +88,10 @@ namespace core
\return True if the point is inside the triangle, otherwise false. */
bool isPointInside(const vector3d<T>& p) const
{
vector3d<f64> af64((f64)pointA.X, (f64)pointA.Y, (f64)pointA.Z);
vector3d<f64> bf64((f64)pointB.X, (f64)pointB.Y, (f64)pointB.Z);
vector3d<f64> cf64((f64)pointC.X, (f64)pointC.Y, (f64)pointC.Z);
vector3d<f64> pf64((f64)p.X, (f64)p.Y, (f64)p.Z);
const vector3d<f64> af64((f64)pointA.X, (f64)pointA.Y, (f64)pointA.Z);
const vector3d<f64> bf64((f64)pointB.X, (f64)pointB.Y, (f64)pointB.Z);
const vector3d<f64> cf64((f64)pointC.X, (f64)pointC.Y, (f64)pointC.Z);
const vector3d<f64> pf64((f64)p.X, (f64)p.Y, (f64)p.Z);
return (isOnSameSide(pf64, af64, bf64, cf64) &&
isOnSameSide(pf64, bf64, af64, cf64) &&
isOnSameSide(pf64, cf64, af64, bf64));
@ -174,7 +174,7 @@ namespace core
const vector3d<f64> lineVectf64(lineVect.X, lineVect.Y, lineVect.Z);
vector3d<f64> outIntersectionf64;
core::triangle3d<irr::f64> trianglef64(vector3d<f64>((f64)pointA.X, (f64)pointA.Y, (f64)pointA.Z)
const core::triangle3d<irr::f64> trianglef64(vector3d<f64>((f64)pointA.X, (f64)pointA.Y, (f64)pointA.Z)
,vector3d<f64>((f64)pointB.X, (f64)pointB.Y, (f64)pointB.Z)
, vector3d<f64>((f64)pointC.X, (f64)pointC.Y, (f64)pointC.Z));
const vector3d<irr::f64> normalf64 = trianglef64.getNormal().normalize();
@ -183,8 +183,8 @@ namespace core
if ( core::iszero ( t2 = normalf64.dotProduct(lineVectf64) ) )
return false;
f64 d = trianglef64.pointA.dotProduct(normalf64);
f64 t = -(normalf64.dotProduct(linePointf64) - d) / t2;
const f64 d = trianglef64.pointA.dotProduct(normalf64);
const f64 t = -(normalf64.dotProduct(linePointf64) - d) / t2;
outIntersectionf64 = linePointf64 + (lineVectf64 * t);
outIntersection.X = (T)outIntersectionf64.X;
@ -246,14 +246,14 @@ namespace core
const vector3d<f64>& a, const vector3d<f64>& b) const
{
vector3d<f64> bminusa = b - a;
vector3d<f64> cp1 = bminusa.crossProduct(p1 - a);
vector3d<f64> cp2 = bminusa.crossProduct(p2 - a);
const vector3d<f64> cp1 = bminusa.crossProduct(p1 - a);
const vector3d<f64> cp2 = bminusa.crossProduct(p2 - a);
f64 res = cp1.dotProduct(cp2);
if ( res < 0 )
{
// This catches some floating point troubles.
// Unfortunately slightly expensive and we don't really know the best epsilon for iszero.
vector3d<f64> cp1n = bminusa.normalize().crossProduct((p1 - a).normalize());
const vector3d<f64> cp1n = bminusa.normalize().crossProduct((p1 - a).normalize());
if (core::iszero(cp1n.X, (f64)ROUNDING_ERROR_f32)
&& core::iszero(cp1n.Y, (f64)ROUNDING_ERROR_f32)
&& core::iszero(cp1n.Z, (f64)ROUNDING_ERROR_f32) )

@ -243,8 +243,8 @@ namespace core
void rotateXZBy(f64 degrees, const vector3d<T>& center=vector3d<T>())
{
degrees *= DEGTORAD64;
f64 cs = cos(degrees);
f64 sn = sin(degrees);
const f64 cs = cos(degrees);
const f64 sn = sin(degrees);
X -= center.X;
Z -= center.Z;
set((T)(X*cs - Z*sn), Y, (T)(X*sn + Z*cs));
@ -258,8 +258,8 @@ namespace core
void rotateXYBy(f64 degrees, const vector3d<T>& center=vector3d<T>())
{
degrees *= DEGTORAD64;
f64 cs = cos(degrees);
f64 sn = sin(degrees);
const f64 cs = cos(degrees);
const f64 sn = sin(degrees);
X -= center.X;
Y -= center.Y;
set((T)(X*cs - Y*sn), (T)(X*sn + Y*cs), Z);
@ -273,8 +273,8 @@ namespace core
void rotateYZBy(f64 degrees, const vector3d<T>& center=vector3d<T>())
{
degrees *= DEGTORAD64;
f64 cs = cos(degrees);
f64 sn = sin(degrees);
const f64 cs = cos(degrees);
const f64 sn = sin(degrees);
Z -= center.Z;
Y -= center.Y;
set(X, (T)(Y*cs - Z*sn), (T)(Y*sn + Z*cs));

@ -239,10 +239,8 @@ IMesh* CGeometryCreator::createHillPlaneMesh(
vtx.Color.set(255,255,255,255);
// create vertices from left-front to right-back
u32 x;
f32 sx=0.f, tsx=0.f;
for (x=0; x<tileCount.Width; ++x)
for (u32 x=0; x<tileCount.Width; ++x)
{
f32 sy=0.f, tsy=0.f;
for (u32 y=0; y<tileCount.Height; ++y)
@ -265,7 +263,7 @@ IMesh* CGeometryCreator::createHillPlaneMesh(
// create indices
for (x=0; x<tileCount.Width-1; ++x)
for (u32 x=0; x<tileCount.Width-1; ++x)
{
for (u32 y=0; y<tileCount.Height-1; ++y)
{
@ -499,13 +497,13 @@ IMesh* CGeometryCreator::createTerrainMesh(video::IImage* texture,
if (buffer->Vertices.size())
{
c8 textureName[64];
// create texture for this block
video::IImage* img = driver->createImage(texture->getColorFormat(), core::dimension2d<u32>(core::floor32(blockSize.Width*thRel.X), core::floor32(blockSize.Height*thRel.Y)));
texture->copyTo(img, core::position2di(0,0), core::recti(
core::position2d<s32>(core::floor32(processed.X*thRel.X), core::floor32(processed.Y*thRel.Y)),
core::dimension2d<u32>(core::floor32(blockSize.Width*thRel.X), core::floor32(blockSize.Height*thRel.Y))), 0);
c8 textureName[64];
sprintf(textureName, "terrain%u_%u", tm, mesh->getMeshBufferCount());
buffer->Material.setTexture(0, driver->addTexture(textureName, img));
@ -665,7 +663,6 @@ IMesh* CGeometryCreator::createSphereMesh(f32 radius, u32 polyCountX, u32 polyCo
const f64 AngleY = core::PI / polyCountY;
u32 i=0;
f64 axz;
// we don't start at 0.
@ -676,7 +673,7 @@ IMesh* CGeometryCreator::createSphereMesh(f32 radius, u32 polyCountX, u32 polyCo
{
ay += AngleY;
const f64 sinay = sin(ay);
axz = 0;
f64 axz = 0;
// calculate the necessary vertices without the doubled one
for (u32 xz = 0;xz < polyCountX; ++xz)
@ -754,13 +751,12 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
const f32 recTessellation = core::reciprocal((f32)tessellation);
const f32 angleStep = (core::PI * 2.f ) * recTessellation;
u32 i;
video::S3DVertex v;
v.Color = color;
buffer->Vertices.reallocate(tessellation*2+2+(closeTop?2:1));
buffer->Indices.reallocate(tessellation*(closeTop?12:9));
f32 tcx = 0.f;
for ( i = 0; i <= tessellation; ++i )
for (u32 i = 0; i <= tessellation; ++i )
{
const f32 angle = angleStep * i;
v.Pos.X = radius * cosf(angle);
@ -790,7 +786,7 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
}
const u32 nonWrappedSize = tessellation*2;
for (i=0; i != nonWrappedSize; i += 2)
for (u32 i=0; i != nonWrappedSize; i += 2)
{
buffer->Indices.push_back(i + 2);
buffer->Indices.push_back(i + 0);
@ -814,7 +810,7 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
u32 index = buffer->Vertices.size() - 1;
for ( i = 0; i != nonWrappedSize; i += 2 )
for (u32 i = 0; i != nonWrappedSize; i += 2 )
{
buffer->Indices.push_back(index);
buffer->Indices.push_back(i + 0);
@ -836,7 +832,7 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
index = buffer->Vertices.size() - 1;
for ( i = 0; i != nonWrappedSize; i += 2 )
for (u32 i = 0; i != nonWrappedSize; i += 2 )
{
buffer->Indices.push_back(i + 1);
buffer->Indices.push_back(index);
@ -988,8 +984,8 @@ irr::scene::IMesh* CGeometryCreator::createTorusMesh(irr::f32 majorRadius, irr::
core::swap(angleStart, angleEnd);
const f32 radStart = angleStart * core::DEGTORAD;
const f32 radEnd = angleEnd * core::DEGTORAD;
const f32 radMajor = radEnd-radStart;
const f32 radStepMajor = radMajor / majorSegments;
const f32 radMajorLen = radEnd-radStart;
const f32 radStepMajor = radMajorLen / majorSegments;
const f32 TWO_PI = 2.f*core::PI;
const f32 radStepMinor = TWO_PI / minorSegments;

@ -197,7 +197,6 @@ IMeshBuffer* CIrrMeshFileLoader::readMeshBuffer(io::IXMLReader* reader)
if (vertexTypeName1 == vertexType)
{
buffer = new CDynamicMeshBuffer(irr::video::EVT_STANDARD, itype);
}
else
if (vertexTypeName2 == vertexType)
@ -209,8 +208,11 @@ IMeshBuffer* CIrrMeshFileLoader::readMeshBuffer(io::IXMLReader* reader)
{
buffer = new CDynamicMeshBuffer(irr::video::EVT_TANGENTS, itype);
}
buffer->getVertexBuffer().reallocate(vertexCount);
buffer->Material = material;
if ( buffer )
{
buffer->getVertexBuffer().reallocate(vertexCount);
buffer->Material = material;
}
}
else
if (indicesSectionName == nodeName)

@ -247,6 +247,7 @@
<Rule Id="C26432" Action="None" />
<Rule Id="C26435" Action="None" />
<Rule Id="C26438" Action="None" />
<Rule Id="C26439" Action="None" />
<Rule Id="C26440" Action="None" />
<Rule Id="C26443" Action="None" />
<Rule Id="C26444" Action="None" />
@ -257,6 +258,7 @@
<Rule Id="C26449" Action="None" />
<Rule Id="C26451" Action="None" />
<Rule Id="C26455" Action="None" />
<Rule Id="C26458" Action="None" />
<Rule Id="C26459" Action="None" />
<Rule Id="C26461" Action="None" />
<Rule Id="C26466" Action="None" />
@ -274,6 +276,7 @@
<Rule Id="C26496" Action="Warning" />
<Rule Id="C26497" Action="None" />
<Rule Id="C26814" Action="None" />
<Rule Id="C26821" Action="None" />
<Rule Id="C28204" Action="None" />
<Rule Id="C28205" Action="None" />
<Rule Id="C28209" Action="None" />

@ -162,7 +162,7 @@
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='SDL-Debug|Win32'">true</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='SDL-Debug|x64'">true</LinkIncremental>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Irrlicht.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
@ -180,7 +180,7 @@
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='SDL-Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='SDL-Debug|x64'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Static lib - Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Static lib - Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Static lib - Debug|x64'">Irrlicht.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Static lib - Debug|Win32'" />
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Static lib - Debug|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Static lib - Debug|Win32'" />

@ -1438,12 +1438,6 @@
<ClInclude Include="..\..\include\EDeviceTypes.h">
<Filter>include</Filter>
</ClInclude>
<ClInclude Include="..\..\include\EMeshBufferTypes.h">
<Filter>include\scene</Filter>
</ClInclude>
<ClInclude Include="..\..\include\ESceneNodeUpdateAbs.h">
<Filter>include\scene</Filter>
</ClInclude>
<ClInclude Include="CBufferRenderNode.h">
<Filter>Irrlicht\scene\sceneNodes</Filter>
</ClInclude>