Cleanup pass

This commit is contained in:
Lynix
2017-04-22 15:08:05 +02:00
parent ec310b9577
commit 06038a4d81
25 changed files with 124 additions and 206 deletions

View File

@@ -101,7 +101,7 @@ namespace Nz
{
struct HashMD5_state
{
UInt32 count[2]; /* message length in bits, lsw first */
std::size_t count[2]; /* message length in bits, lsw first */
UInt32 abcd[4]; /* digest buffer */
UInt8 buf[64]; /* accumulate block */
};
@@ -280,9 +280,9 @@ namespace Nz
void HashMD5::Append(const UInt8* data, std::size_t len)
{
const UInt8 *p = data;
int left = len;
std::size_t left = len;
int offset = (m_state->count[0] >> 3) & 63;
UInt32 nbits = len << 3;
std::size_t nbits = len << 3;
if (len <= 0)
return;
@@ -296,7 +296,7 @@ namespace Nz
/* Process an initial partial block. */
if (offset)
{
int copy = (offset + len > 64 ? 64 - offset : len);
std::size_t copy = (offset + len > 64 ? 64 - offset : len);
std::memcpy(m_state->buf + offset, p, copy);
if (offset + copy < 64)

View File

@@ -75,8 +75,8 @@ namespace Nz
{
struct HashWhirlpool_state
{
int bufferBits; // current number of bits on the buffer */
int bufferPos; // current (possibly incomplete) byte slot on the buffer */
std::size_t bufferBits; // current number of bits on the buffer */
std::size_t bufferPos; // current (possibly incomplete) byte slot on the buffer */
UInt8 bitLength[32]; // global number of hashed bits (256-bit counter) */
UInt8 buffer[64]; // buffer of data to hash */
UInt64 hash[8]; // the hashing state */
@@ -877,8 +877,8 @@ namespace Nz
UInt32 b;
UInt8* buffer = m_state->buffer;
UInt8* bitLength = m_state->bitLength;
int bufferBits = m_state->bufferBits;
int bufferPos = m_state->bufferPos;
std::size_t bufferBits = m_state->bufferBits;
std::size_t bufferPos = m_state->bufferPos;
// tally the length of the added data
UInt64 value = len;
@@ -968,8 +968,8 @@ namespace Nz
UInt8 *buffer = m_state->buffer;
UInt8 *bitLength = m_state->bitLength;
int bufferBits = m_state->bufferBits;
int bufferPos = m_state->bufferPos;
std::size_t bufferBits = m_state->bufferBits;
std::size_t bufferPos = m_state->bufferPos;
UInt8 *digest = result;
// append a '1'-bit

View File

@@ -2115,7 +2115,7 @@ namespace Nz
return ptr - m_sharedString->string.get();
}
catch (utf8::not_enough_room& e)
catch (utf8::not_enough_room& /*e*/)
{
// Returns npos
}

View File

@@ -33,8 +33,8 @@ namespace Nz
Vector2f uv;
};
std::size_t s_maxQuads = std::numeric_limits<UInt16>::max() / 6;
std::size_t s_vertexBufferSize = 4 * 1024 * 1024; // 4 MiB
UInt32 s_maxQuads = std::numeric_limits<UInt16>::max() / 6;
UInt32 s_vertexBufferSize = 4 * 1024 * 1024; // 4 MiB
}
/*!

View File

@@ -62,9 +62,9 @@ namespace Nz
if (cpShape* shape = cpSpacePointQueryNearest(m_handle, { from.x, from.y }, maxDistance, filter, &queryInfo))
{
result->closestPoint.Set(queryInfo.point.x, queryInfo.point.y);
result->distance = queryInfo.distance;
result->fraction.Set(queryInfo.gradient.x, queryInfo.gradient.y);
result->closestPoint.Set(Nz::Vector2<cpFloat>(queryInfo.point.x, queryInfo.point.y));
result->distance = float(queryInfo.distance);
result->fraction.Set(Nz::Vector2<cpFloat>(queryInfo.gradient.x, queryInfo.gradient.y));
result->nearestBody = static_cast<Nz::RigidBody2D*>(cpShapeGetUserData(shape));
return true;
@@ -90,9 +90,9 @@ namespace Nz
ResultType results = static_cast<ResultType>(data);
RaycastHit hitInfo;
hitInfo.fraction = alpha;
hitInfo.hitNormal.Set(normal.x, normal.y);
hitInfo.hitPos.Set(point.x, point.y);
hitInfo.fraction = float(alpha);
hitInfo.hitNormal.Set(Nz::Vector2<cpFloat>(normal.x, normal.y));
hitInfo.hitPos.Set(Nz::Vector2<cpFloat>(point.x, point.y));
hitInfo.nearestBody = static_cast<Nz::RigidBody2D*>(cpShapeGetUserData(shape));
results->emplace_back(std::move(hitInfo));
@@ -116,9 +116,9 @@ namespace Nz
if (cpShape* shape = cpSpaceSegmentQueryFirst(m_handle, { from.x, from.y }, { to.x, to.y }, radius, filter, &queryInfo))
{
hitInfo->fraction = queryInfo.alpha;
hitInfo->hitNormal.Set(queryInfo.normal.x, queryInfo.normal.y);
hitInfo->hitPos.Set(queryInfo.point.x, queryInfo.point.y);
hitInfo->fraction = float(queryInfo.alpha);
hitInfo->hitNormal.Set(Nz::Vector2<cpFloat>(queryInfo.normal.x, queryInfo.normal.y));
hitInfo->hitPos.Set(Nz::Vector2<cpFloat>(queryInfo.point.x, queryInfo.point.y));
hitInfo->nearestBody = static_cast<Nz::RigidBody2D*>(cpShapeGetUserData(queryInfo.shape));
return true;

View File

@@ -215,7 +215,7 @@ namespace Nz
cpVect vel = cpBodyGetVelocity(m_handle);
Destroy();
Create(mass, moment);
Create(float(mass), float(moment));
cpBodySetAngle(m_handle, rot);
cpBodySetPosition(m_handle, pos);

View File

@@ -91,8 +91,8 @@ namespace Nz
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
IndexBufferRef indexBuffer = IndexBuffer::New(largeIndices, indexCount, parameters.storage, 0);
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent_Skinning), vertexCount, parameters.storage, 0);
IndexBufferRef indexBuffer = IndexBuffer::New(largeIndices, UInt32(indexCount), parameters.storage, 0);
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent_Skinning), UInt32(vertexCount), parameters.storage, 0);
// Index buffer
IndexMapper indexMapper(indexBuffer, BufferAccess_DiscardAndWrite);
@@ -236,7 +236,7 @@ namespace Nz
// Index buffer
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
IndexBufferRef indexBuffer = IndexBuffer::New(largeIndices, indexCount, parameters.storage, 0);
IndexBufferRef indexBuffer = IndexBuffer::New(largeIndices, UInt32(indexCount), parameters.storage, 0);
IndexMapper indexMapper(indexBuffer, BufferAccess_DiscardAndWrite);
IndexIterator index = indexMapper.begin();
@@ -251,7 +251,7 @@ namespace Nz
indexMapper.Unmap();
// Vertex buffer
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.storage, 0);
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), UInt32(vertexCount), parameters.storage, 0);
BufferMapper<VertexBuffer> vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
MeshVertex* vertices = static_cast<MeshVertex*>(vertexMapper.GetPointer());

View File

@@ -233,8 +233,8 @@ namespace Nz
}
// Création des buffers
IndexBufferRef indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indices.size(), parameters.storage, 0);
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.storage, 0);
IndexBufferRef indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), UInt32(indices.size()), parameters.storage, 0);
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), UInt32(vertexCount), parameters.storage, 0);
// Remplissage des indices
IndexMapper indexMapper(indexBuffer, BufferAccess_WriteOnly);

View File

@@ -228,7 +228,7 @@ namespace Nz
if (p < 0)
{
p += m_positions.size() - 1;
p += static_cast<int>(m_positions.size() - 1);
if (p < 0)
{
Error("Vertex index out of range (" + String::Number(p) + " < 0");
@@ -239,7 +239,7 @@ namespace Nz
if (n < 0)
{
n += m_normals.size() - 1;
n += static_cast<int>(m_normals.size() - 1);
if (n < 0)
{
Error("Normal index out of range (" + String::Number(n) + " < 0");
@@ -250,7 +250,7 @@ namespace Nz
if (t < 0)
{
t += m_texCoords.size() - 1;
t += static_cast<int>(m_texCoords.size() - 1);
if (t < 0)
{
Error("Texture coordinates index out of range (" + String::Number(t) + " < 0");

View File

@@ -12,38 +12,38 @@ namespace Nz
{
namespace
{
UInt32 GetterSequential(const void* buffer, unsigned int i)
UInt32 GetterSequential(const void* buffer, std::size_t i)
{
NazaraUnused(buffer);
return i;
return static_cast<UInt32>(i);
}
UInt32 Getter16(const void* buffer, unsigned int i)
UInt32 Getter16(const void* buffer, std::size_t i)
{
const UInt16* ptr = static_cast<const UInt16*>(buffer);
return ptr[i];
}
UInt32 Getter32(const void* buffer, unsigned int i)
UInt32 Getter32(const void* buffer, std::size_t i)
{
const UInt32* ptr = static_cast<const UInt32*>(buffer);
return ptr[i];
}
void Setter16(void* buffer, unsigned int i, UInt32 value)
void Setter16(void* buffer, std::size_t i, UInt32 value)
{
UInt16* ptr = static_cast<UInt16*>(buffer);
ptr[i] = static_cast<UInt16>(value);
}
void Setter32(void* buffer, unsigned int i, UInt32 value)
void Setter32(void* buffer, std::size_t i, UInt32 value)
{
UInt32* ptr = static_cast<UInt32*>(buffer);
ptr[i] = value;
}
void SetterError(void*, unsigned int, UInt32)
void SetterError(void*, std::size_t, UInt32)
{
NazaraError("Index buffer opened with read-only access");
}
@@ -113,15 +113,9 @@ namespace Nz
{
}
UInt32 IndexMapper::Get(unsigned int i) const
UInt32 IndexMapper::Get(std::size_t i) const
{
#if NAZARA_UTILITY_SAFE
if (i >= m_indexCount)
{
NazaraError("Index out of range (" + String::Number(i) + " >= " + String::Number(m_indexCount) + ')');
return 0;
}
#endif
NazaraAssert(i < m_indexCount, "Index out of range");
return m_getter(m_mapper.GetPointer(), i);
}
@@ -131,20 +125,14 @@ namespace Nz
return m_mapper.GetBuffer();
}
unsigned int IndexMapper::GetIndexCount() const
std::size_t IndexMapper::GetIndexCount() const
{
return m_indexCount;
}
void IndexMapper::Set(unsigned int i, UInt32 value)
void IndexMapper::Set(std::size_t i, UInt32 value)
{
#if NAZARA_UTILITY_SAFE
if (i >= m_indexCount)
{
NazaraError("Index out of range (" + String::Number(i) + " >= " + String::Number(m_indexCount) + ')');
return;
}
#endif
NazaraAssert(i < m_indexCount, "Index out of range");
m_setter(m_mapper.GetPointer(), i, value);
}

View File

@@ -79,7 +79,7 @@ namespace Nz
NazaraAssert(subMesh, "Invalid submesh");
NazaraAssert(subMesh->GetAnimationType() == m_impl->animationType, "Submesh animation type doesn't match mesh animation type");
m_impl->subMeshes.push_back(subMesh);
m_impl->subMeshes.emplace_back(subMesh);
InvalidateAABB();
}
@@ -92,10 +92,10 @@ namespace Nz
NazaraAssert(subMesh, "Invalid submesh");
NazaraAssert(subMesh->GetAnimationType() == m_impl->animationType, "Submesh animation type doesn't match mesh animation type");
UInt32 index = m_impl->subMeshes.size();
std::size_t index = m_impl->subMeshes.size();
m_impl->subMeshes.push_back(subMesh);
m_impl->subMeshMap[identifier] = index;
m_impl->subMeshes.emplace_back(subMesh);
m_impl->subMeshMap[identifier] = static_cast<UInt32>(index);
InvalidateAABB();
}
@@ -349,11 +349,11 @@ namespace Nz
if (!m_impl->aabbUpdated)
{
UInt32 subMeshCount = m_impl->subMeshes.size();
std::size_t subMeshCount = m_impl->subMeshes.size();
if (subMeshCount > 0)
{
m_impl->aabb.Set(m_impl->subMeshes[0]->GetAABB());
for (UInt32 i = 1; i < subMeshCount; ++i)
for (std::size_t i = 1; i < subMeshCount; ++i)
m_impl->aabb.ExtendTo(m_impl->subMeshes[i]->GetAABB());
}
else
@@ -407,7 +407,7 @@ namespace Nz
{
NazaraAssert(m_impl, "Mesh should be created first");
return m_impl->materialData.size();
return static_cast<UInt32>(m_impl->materialData.size());
}
Skeleton* Mesh::GetSkeleton()
@@ -466,7 +466,7 @@ namespace Nz
{
NazaraAssert(m_impl, "Mesh should be created first");
return m_impl->subMeshes.size();
return static_cast<UInt32>(m_impl->subMeshes.size());
}
UInt32 Mesh::GetSubMeshIndex(const String& identifier) const

View File

@@ -243,7 +243,7 @@ namespace Nz
m_workingBounds.MakeZero(); //< Compute bounds as float to speedup bounds computation (as casting between floats and integers is costly)
if (m_font)
m_lines.emplace_back(Line{Rectf(0.f, 0.f, 0.f, m_font->GetSizeInfo(m_characterSize).lineHeight), 0});
m_lines.emplace_back(Line{Rectf(0.f, 0.f, 0.f, float(m_font->GetSizeInfo(m_characterSize).lineHeight)), 0});
else
m_lines.emplace_back(Line{Rectf::Zero(), 0});
}
@@ -354,7 +354,7 @@ namespace Nz
{
glyph.atlas = nullptr;
glyph.bounds.Set(m_drawPos.x, m_drawPos.y, float(advance), sizeInfo.lineHeight);
glyph.bounds.Set(m_drawPos.x, m_drawPos.y, float(advance), float(sizeInfo.lineHeight));
glyph.corners[0].Set(glyph.bounds.GetCorner(RectCorner_LeftTop));
glyph.corners[1].Set(glyph.bounds.GetCorner(RectCorner_RightTop));
@@ -377,7 +377,7 @@ namespace Nz
m_drawPos.x = 0;
m_drawPos.y += sizeInfo.lineHeight;
m_lines.emplace_back(Line{Rectf(0.f, sizeInfo.lineHeight * m_lines.size(), 0.f, sizeInfo.lineHeight), m_glyphs.size() + 1});
m_lines.emplace_back(Line{Rectf(0.f, float(sizeInfo.lineHeight * m_lines.size()), 0.f, float(sizeInfo.lineHeight)), m_glyphs.size() + 1});
break;
}
}

View File

@@ -72,12 +72,12 @@ namespace Nz
if (!m_impl->aabbUpdated)
{
UInt32 jointCount = m_impl->joints.size();
std::size_t jointCount = m_impl->joints.size();
if (jointCount > 0)
{
Vector3f pos = m_impl->joints[0].GetPosition();
m_impl->aabb.Set(pos.x, pos.y, pos.z, 0.f, 0.f, 0.f);
for (UInt32 i = 1; i < jointCount; ++i)
for (std::size_t i = 1; i < jointCount; ++i)
m_impl->aabb.ExtendTo(m_impl->joints[i].GetPosition());
}
else
@@ -219,7 +219,7 @@ namespace Nz
}
#endif
return m_impl->joints.size();
return static_cast<UInt32>(m_impl->joints.size());
}
int Skeleton::GetJointIndex(const String& jointName) const
@@ -411,16 +411,9 @@ namespace Nz
String name = m_impl->joints[i].GetName();
if (!name.IsEmpty())
{
#if NAZARA_UTILITY_SAFE
auto it = m_impl->jointMap.find(name);
if (it != m_impl->jointMap.end())
{
NazaraWarning("Joint name \"" + name + "\" is already present in joint map for joint #" + String::Number(it->second));
continue;
}
#endif
NazaraAssert(m_impl->jointMap.find(name) == m_impl->jointMap.end(), "Joint name \"" + name + "\" is already present in joint map");
m_impl->jointMap[name] = i;
m_impl->jointMap[name] = static_cast<UInt32>(i);
}
}

View File

@@ -66,18 +66,9 @@ namespace Nz
return true;
}
UInt32 TriangleIterator::operator[](unsigned int i) const
UInt32 TriangleIterator::operator[](std::size_t i) const
{
#if NAZARA_UTILITY_SAFE
if (i >= 3)
{
StringStream ss;
ss << "Index out of range: (" << i << " >= 3)";
NazaraError(ss);
throw std::domain_error(ss.ToString());
}
#endif
NazaraAssert(i < 3, "Index out of range");
return m_triangleIndices[i];
}