Utility: First code cleaning pass

Former-commit-id: a73d38ce2db2e780ad5b02cdae1c590606081650 [formerly 3d21c0fa44481bf91418a15012fa187a210fc9ad] [formerly b80263df8e91b85f3fd091724c54dec7f05bc535 [formerly 7dcaabaabf74fbdf840289bfc435fdd8e88969d7]]
Former-commit-id: a669a933edd2364d9ee487c7d1bb38e28ad87a2d [formerly b8c5c09df10ce2f831635f460393216799d44056]
Former-commit-id: 6bbd5af22e30cc7fd4b4478162ae89e69b3d274e
This commit is contained in:
Lynix
2016-09-04 20:39:34 +02:00
parent 560825fa8e
commit 68d67cc9da
22 changed files with 276 additions and 489 deletions

View File

@@ -37,10 +37,10 @@ namespace Nz
}
const MD5AnimParser::Frame* frames = parser.GetFrames();
std::size_t frameCount = parser.GetFrameCount();
std::size_t frameRate = parser.GetFrameRate();
UInt32 frameCount = parser.GetFrameCount();
UInt32 frameRate = parser.GetFrameRate();
const MD5AnimParser::Joint* joints = parser.GetJoints();
std::size_t jointCount = parser.GetJointCount();
UInt32 jointCount = parser.GetJointCount();
// À ce stade, nous sommes censés avoir assez d'informations pour créer l'animation
animation->CreateSkeletal(frameCount, jointCount);
@@ -57,12 +57,12 @@ namespace Nz
// Pour que le squelette soit correctement aligné, il faut appliquer un quaternion "de correction" aux joints à la base du squelette
Quaternionf rotationQuat = Quaternionf::RotationBetween(Vector3f::UnitX(), Vector3f::Forward()) *
Quaternionf::RotationBetween(Vector3f::UnitZ(), Vector3f::Up());
Quaternionf::RotationBetween(Vector3f::UnitZ(), Vector3f::Up());
for (std::size_t i = 0; i < jointCount; ++i)
for (UInt32 i = 0; i < jointCount; ++i)
{
int parent = joints[i].parent;
for (std::size_t j = 0; j < frameCount; ++j)
for (UInt32 j = 0; j < frameCount; ++j)
{
SequenceJoint& sequenceJoint = sequenceJoints[j*jointCount + i];

View File

@@ -48,9 +48,9 @@ namespace Nz
return Ternary_False;
}
std::size_t MD5AnimParser::GetAnimatedComponentCount() const
UInt32 MD5AnimParser::GetAnimatedComponentCount() const
{
return m_animatedComponents.size();
return static_cast<UInt32>(m_animatedComponents.size());
}
const MD5AnimParser::Frame* MD5AnimParser::GetFrames() const
@@ -58,12 +58,12 @@ namespace Nz
return m_frames.data();
}
std::size_t MD5AnimParser::GetFrameCount() const
UInt32 MD5AnimParser::GetFrameCount() const
{
return m_frames.size();
return static_cast<UInt32>(m_frames.size());
}
std::size_t MD5AnimParser::GetFrameRate() const
UInt32 MD5AnimParser::GetFrameRate() const
{
return m_frameRate;
}
@@ -73,9 +73,9 @@ namespace Nz
return m_joints.data();
}
std::size_t MD5AnimParser::GetJointCount() const
UInt32 MD5AnimParser::GetJointCount() const
{
return m_joints.size();
return static_cast<UInt32>(m_joints.size());
}
bool MD5AnimParser::Parse()
@@ -209,14 +209,14 @@ namespace Nz
}
}
unsigned int frameCount = m_frames.size();
std::size_t frameCount = m_frames.size();
if (frameCount == 0)
{
NazaraError("Frame count is invalid or missing");
return false;
}
unsigned int jointCount = m_joints.size();
std::size_t jointCount = m_joints.size();
if (jointCount == 0)
{
NazaraError("Joint count is invalid or missing");
@@ -273,21 +273,21 @@ namespace Nz
bool MD5AnimParser::ParseBaseframe()
{
unsigned int jointCount = m_joints.size();
std::size_t jointCount = m_joints.size();
if (jointCount == 0)
{
Error("Joint count is invalid or missing");
return false;
}
for (unsigned int i = 0; i < jointCount; ++i)
for (std::size_t i = 0; i < jointCount; ++i)
{
if (!Advance())
return false;
// Space is important for the buffer of \n
if (std::sscanf(&m_currentLine[0], " ( %f %f %f ) ( %f %f %f )", &m_joints[i].bindPos.x, &m_joints[i].bindPos.y, &m_joints[i].bindPos.z,
&m_joints[i].bindOrient.x, &m_joints[i].bindOrient.y, &m_joints[i].bindOrient.z) != 6)
&m_joints[i].bindOrient.x, &m_joints[i].bindOrient.y, &m_joints[i].bindOrient.z) != 6)
{
UnrecognizedLine(true);
return false;
@@ -312,14 +312,14 @@ namespace Nz
bool MD5AnimParser::ParseBounds()
{
unsigned int frameCount = m_frames.size();
std::size_t frameCount = m_frames.size();
if (frameCount == 0)
{
Error("Frame count is invalid or missing");
return false;
}
for (unsigned int i = 0; i < frameCount; ++i)
for (std::size_t i = 0; i < frameCount; ++i)
{
if (!Advance())
return false;
@@ -353,14 +353,14 @@ namespace Nz
bool MD5AnimParser::ParseFrame()
{
unsigned int animatedComponentsCount = m_animatedComponents.size();
std::size_t animatedComponentsCount = m_animatedComponents.size();
if (animatedComponentsCount == 0)
{
Error("Animated components count is missing or invalid");
return false;
}
unsigned int jointCount = m_joints.size();
std::size_t jointCount = m_joints.size();
if (jointCount == 0)
{
Error("Joint count is invalid or missing");
@@ -369,14 +369,14 @@ namespace Nz
String line;
unsigned int count = 0;
std::size_t count = 0;
do
{
if (!Advance())
return false;
unsigned int index = 0;
unsigned int size = m_currentLine.GetSize();
std::size_t index = 0;
std::size_t size = m_currentLine.GetSize();
do
{
float f;
@@ -399,11 +399,11 @@ namespace Nz
m_frames[m_frameIndex].joints.resize(jointCount);
for (unsigned int i = 0; i < jointCount; ++i)
for (std::size_t i = 0; i < jointCount; ++i)
{
Quaternionf jointOrient = m_joints[i].bindOrient;
Vector3f jointPos = m_joints[i].bindPos;
unsigned int j = 0;
UInt32 j = 0;
if (m_joints[i].flags & 1) // Px
jointPos.x = m_animatedComponents[m_joints[i].index + j++];
@@ -447,19 +447,19 @@ namespace Nz
bool MD5AnimParser::ParseHierarchy()
{
unsigned int jointCount = m_joints.size();
std::size_t jointCount = m_joints.size();
if (jointCount == 0)
{
Error("Joint count is invalid or missing");
return false;
}
for (unsigned int i = 0; i < jointCount; ++i)
for (std::size_t i = 0; i < jointCount; ++i)
{
if (!Advance())
return false;
unsigned int pos = m_currentLine.Find(' ');
std::size_t pos = m_currentLine.Find(' ');
if (pos == String::npos)
{
UnrecognizedLine(true);
@@ -482,10 +482,10 @@ namespace Nz
m_joints[i].name = name;
m_joints[i].name.Trim('"');
int parent = m_joints[i].parent;
Int32 parent = m_joints[i].parent;
if (parent >= 0)
{
if (static_cast<unsigned int>(parent) >= jointCount)
if (static_cast<UInt32>(parent) >= jointCount)
{
Error("Joint's parent is out of bounds (" + String::Number(parent) + " >= " + String::Number(jointCount) + ')');
return false;

View File

@@ -53,15 +53,15 @@ namespace Nz
const MD5MeshParser::Joint* joints = parser.GetJoints();
const MD5MeshParser::Mesh* meshes = parser.GetMeshes();
std::size_t jointCount = parser.GetJointCount();
std::size_t meshCount = parser.GetMeshCount();
UInt32 jointCount = parser.GetJointCount();
UInt32 meshCount = parser.GetMeshCount();
if (parameters.animated)
{
mesh->CreateSkeletal(jointCount);
Skeleton* skeleton = mesh->GetSkeleton();
for (std::size_t i = 0; i < jointCount; ++i)
for (UInt32 i = 0; i < jointCount; ++i)
{
Joint* joint = skeleton->GetJoint(i);
@@ -82,7 +82,7 @@ namespace Nz
}
mesh->SetMaterialCount(meshCount);
for (std::size_t i = 0; i < meshCount; ++i)
for (UInt32 i = 0; i < meshCount; ++i)
{
const MD5MeshParser::Mesh& md5Mesh = meshes[i];
@@ -100,7 +100,7 @@ namespace Nz
// Le format définit un set de triangles nous permettant de retrouver facilement les indices
// Cependant les sommets des triangles ne sont pas spécifiés dans le même ordre que ceux du moteur
// (On parle ici de winding)
unsigned int index = 0;
UInt32 index = 0;
for (const MD5MeshParser::Triangle& triangle : md5Mesh.triangles)
{
// On les respécifie dans le bon ordre (inversion du winding)
@@ -227,7 +227,7 @@ namespace Nz
}
mesh->SetMaterialCount(meshCount);
for (std::size_t i = 0; i < meshCount; ++i)
for (UInt32 i = 0; i < meshCount; ++i)
{
const MD5MeshParser::Mesh& md5Mesh = meshes[i];
std::size_t indexCount = md5Mesh.triangles.size()*3;

View File

@@ -58,9 +58,9 @@ namespace Nz
return m_joints.data();
}
std::size_t MD5MeshParser::GetJointCount() const
UInt32 MD5MeshParser::GetJointCount() const
{
return m_joints.size();
return static_cast<UInt32>(m_joints.size());
}
const MD5MeshParser::Mesh* MD5MeshParser::GetMeshes() const
@@ -68,9 +68,9 @@ namespace Nz
return m_meshes.data();
}
std::size_t MD5MeshParser::GetMeshCount() const
UInt32 MD5MeshParser::GetMeshCount() const
{
return m_meshes.size();
return static_cast<UInt32>(m_meshes.size());
}
bool MD5MeshParser::Parse()
@@ -211,19 +211,19 @@ namespace Nz
bool MD5MeshParser::ParseJoints()
{
unsigned int jointCount = m_joints.size();
std::size_t jointCount = m_joints.size();
if (jointCount == 0)
{
Error("Joint count is invalid or missing");
return false;
}
for (unsigned int i = 0; i < jointCount; ++i)
for (std::size_t i = 0; i < jointCount; ++i)
{
if (!Advance())
return false;
unsigned int pos = m_currentLine.Find(' ');
std::size_t pos = m_currentLine.Find(' ');
if (pos == String::npos)
{
UnrecognizedLine(true);
@@ -248,10 +248,10 @@ namespace Nz
m_joints[i].name = name;
m_joints[i].name.Trim('"');
int parent = m_joints[i].parent;
Int32 parent = m_joints[i].parent;
if (parent >= 0)
{
if (static_cast<unsigned int>(parent) >= jointCount)
if (static_cast<std::size_t>(parent) >= jointCount)
{
Error("Joint's parent is out of bounds (" + String::Number(parent) + " >= " + String::Number(jointCount) + ')');
return false;

View File

@@ -160,7 +160,7 @@ namespace Nz
}
else if (keyword == "map_ka")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -172,7 +172,7 @@ namespace Nz
}
else if (keyword == "map_kd")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -184,7 +184,7 @@ namespace Nz
}
else if (keyword == "map_ks")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -196,7 +196,7 @@ namespace Nz
}
else if (keyword == "map_bump" || keyword == "bump")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -208,7 +208,7 @@ namespace Nz
}
else if (keyword == "map_d")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -220,7 +220,7 @@ namespace Nz
}
else if (keyword == "map_decal" || keyword == "decal")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -232,7 +232,7 @@ namespace Nz
}
else if (keyword == "map_disp" || keyword == "disp")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -244,7 +244,7 @@ namespace Nz
}
else if (keyword == "map_refl" || keyword == "refl")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);

View File

@@ -40,7 +40,7 @@ namespace Nz
return Ternary_Unknown;
}
bool ParseMTL(Mesh* mesh, const String& filePath, const String* materials, const OBJParser::Mesh* meshes, unsigned int meshCount)
bool ParseMTL(Mesh* mesh, const String& filePath, const String* materials, const OBJParser::Mesh* meshes, UInt32 meshCount)
{
File file(filePath);
if (!file.Open(OpenMode_ReadOnly | OpenMode_Text))
@@ -58,7 +58,7 @@ namespace Nz
std::unordered_map<String, ParameterList> materialCache;
String baseDir = file.GetDirectory();
for (unsigned int i = 0; i < meshCount; ++i)
for (UInt32 i = 0; i < meshCount; ++i)
{
const String& matName = materials[meshes[i].material];
const MTLParser::Material* mtlMat = materialParser.GetMaterial(matName);
@@ -154,21 +154,21 @@ namespace Nz
const Vector3f* texCoords = parser.GetTexCoords();
const OBJParser::Mesh* meshes = parser.GetMeshes();
unsigned int meshCount = parser.GetMeshCount();
UInt32 meshCount = parser.GetMeshCount();
NazaraAssert(materials != nullptr && positions != nullptr && normals != nullptr &&
texCoords != nullptr && meshes != nullptr && meshCount > 0,
"Invalid OBJParser output");
// Un conteneur temporaire pour contenir les indices de face avant triangulation
std::vector<unsigned int> faceIndices(3); // Comme il y aura au moins trois sommets
for (unsigned int i = 0; i < meshCount; ++i)
std::vector<UInt32> faceIndices(3); // Comme il y aura au moins trois sommets
for (UInt32 i = 0; i < meshCount; ++i)
{
unsigned int faceCount = meshes[i].faces.size();
std::size_t faceCount = meshes[i].faces.size();
if (faceCount == 0)
continue;
std::vector<unsigned int> indices;
std::vector<UInt32> indices;
indices.reserve(faceCount*3); // Pire cas si les faces sont des triangles
// Afin d'utiliser OBJParser::FaceVertex comme clé dans un unordered_map,
@@ -205,10 +205,10 @@ namespace Nz
unsigned int vertexCount = 0;
for (unsigned int j = 0; j < faceCount; ++j)
{
unsigned int faceVertexCount = meshes[i].faces[j].vertexCount;
UInt32 faceVertexCount = meshes[i].faces[j].vertexCount;
faceIndices.resize(faceVertexCount);
for (unsigned int k = 0; k < faceVertexCount; ++k)
for (UInt32 k = 0; k < faceVertexCount; ++k)
{
const OBJParser::FaceVertex& vertex = meshes[i].vertices[meshes[i].faces[j].firstVertex + k];
@@ -220,7 +220,7 @@ namespace Nz
}
// Triangulation
for (unsigned int k = 1; k < faceVertexCount-1; ++k)
for (UInt32 k = 1; k < faceVertexCount-1; ++k)
{
indices.push_back(faceIndices[0]);
indices.push_back(faceIndices[k]);
@@ -234,7 +234,7 @@ namespace Nz
// Remplissage des indices
IndexMapper indexMapper(indexBuffer, BufferAccess_WriteOnly);
for (unsigned int j = 0; j < indices.size(); ++j)
for (std::size_t j = 0; j < indices.size(); ++j)
indexMapper.Set(j, indices[j]);
indexMapper.Unmap(); // Pour laisser les autres tâches affecter l'index buffer

View File

@@ -13,7 +13,7 @@
namespace Nz
{
bool OBJParser::Parse(Nz::Stream& stream, std::size_t reservedVertexCount)
bool OBJParser::Parse(Nz::Stream& stream, UInt32 reservedVertexCount)
{
m_currentStream = &stream;
@@ -50,8 +50,8 @@ namespace Nz
using MatPair = std::pair<Mesh, unsigned int>;
std::unordered_map<String, std::unordered_map<String, MatPair>> meshesByName;
std::size_t faceReserve = 0;
std::size_t vertexReserve = 0;
UInt32 faceReserve = 0;
UInt32 vertexReserve = 0;
unsigned int matCount = 0;
auto GetMaterial = [&] (const String& meshName, const String& matName) -> Mesh*
{
@@ -79,16 +79,16 @@ namespace Nz
{
case '#': //< Comment
// Some softwares write comments to gives the number of vertex/faces an importer can expect
std::size_t data;
if (std::sscanf(m_currentLine.GetConstBuffer(), "# position count: %zu", &data) == 1)
unsigned int data;
if (std::sscanf(m_currentLine.GetConstBuffer(), "# position count: %u", &data) == 1)
m_positions.reserve(data);
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# normal count: %zu", &data) == 1)
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# normal count: %u", &data) == 1)
m_normals.reserve(data);
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# texcoords count: %zu", &data) == 1)
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# texcoords count: %u", &data) == 1)
m_texCoords.reserve(data);
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# face count: %zu", &data) == 1)
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# face count: %u", &data) == 1)
faceReserve = data;
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# vertex count: %zu", &data) == 1)
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# vertex count: %u", &data) == 1)
vertexReserve = data;
break;
@@ -118,8 +118,8 @@ namespace Nz
currentMesh = GetMaterial(meshName, matName);
Face face;
face.firstVertex = currentMesh->vertices.size();
face.vertexCount = vertexCount;
face.firstVertex = static_cast<UInt32>(currentMesh->vertices.size());
face.vertexCount = static_cast<UInt32>(vertexCount);
currentMesh->vertices.resize(face.firstVertex + vertexCount, FaceVertex{0, 0, 0});
@@ -203,9 +203,9 @@ namespace Nz
break;
}
currentMesh->vertices[face.firstVertex + i].normal = static_cast<std::size_t>(n);
currentMesh->vertices[face.firstVertex + i].position = static_cast<std::size_t>(p);
currentMesh->vertices[face.firstVertex + i].texCoord = static_cast<std::size_t>(t);
currentMesh->vertices[face.firstVertex + i].normal = static_cast<UInt32>(n);
currentMesh->vertices[face.firstVertex + i].position = static_cast<UInt32>(p);
currentMesh->vertices[face.firstVertex + i].texCoord = static_cast<UInt32>(t);
pos += offset;
}

View File

@@ -78,7 +78,7 @@ namespace Nz
return false;
}
std::size_t worstCacheVertexCount = mesh.GetVertexCount();
UInt32 worstCacheVertexCount = mesh.GetVertexCount();
OBJParser objFormat;
objFormat.SetNormalCount(worstCacheVertexCount);
objFormat.SetPositionCount(worstCacheVertexCount);
@@ -101,9 +101,9 @@ namespace Nz
MTLParser mtlFormat;
std::unordered_set<String> registredMaterials;
std::size_t matCount = mesh.GetMaterialCount();
UInt32 matCount = mesh.GetMaterialCount();
String* materialNames = objFormat.SetMaterialCount(matCount);
for (std::size_t i = 0; i < matCount; ++i)
for (UInt32 i = 0; i < matCount; ++i)
{
const ParameterList& matData = mesh.GetMaterialData(i);
@@ -152,13 +152,13 @@ namespace Nz
}
// Meshes
std::size_t meshCount = mesh.GetSubMeshCount();
UInt32 meshCount = mesh.GetSubMeshCount();
OBJParser::Mesh* meshes = objFormat.SetMeshCount(meshCount);
for (std::size_t i = 0; i < meshCount; ++i)
for (UInt32 i = 0; i < meshCount; ++i)
{
const StaticMesh* staticMesh = static_cast<const StaticMesh*>(mesh.GetSubMesh(i));
std::size_t triangleCount = staticMesh->GetTriangleCount();
UInt32 triangleCount = staticMesh->GetTriangleCount();
meshes[i].faces.resize(triangleCount);
meshes[i].material = staticMesh->GetMaterialIndex();
@@ -180,7 +180,7 @@ namespace Nz
face.firstVertex = faceIndex * 3;
face.vertexCount = 3;
for (std::size_t j = 0; j < 3; ++j)
for (unsigned int j = 0; j < 3; ++j)
{
OBJParser::FaceVertex& vertexIndices = meshes[i].vertices[face.firstVertex + j];