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

View File

@ -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);

View File

@ -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));
}

View File

@ -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));
}

View File

@ -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);

View File

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

View File

@ -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);

View File

@ -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);
}

View File

@ -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) )

View File

@ -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));