From 68d67cc9da443bf64a301e2fda9e0dfaf592f431 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 4 Sep 2016 20:39:34 +0200 Subject: [PATCH] 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 --- include/Nazara/Utility/Animation.hpp | 29 +- .../Nazara/Utility/Formats/MD5AnimParser.hpp | 14 +- .../Nazara/Utility/Formats/MD5MeshParser.hpp | 6 +- include/Nazara/Utility/Formats/OBJParser.hpp | 34 +- include/Nazara/Utility/Formats/OBJParser.inl | 30 +- include/Nazara/Utility/Mesh.hpp | 30 +- include/Nazara/Utility/Sequence.hpp | 6 +- include/Nazara/Utility/Skeleton.hpp | 10 +- include/Nazara/Utility/SubMesh.hpp | 10 +- include/Nazara/Utility/VertexMapper.inl | 2 +- src/Nazara/Utility/Animation.cpp | 326 +++--------------- src/Nazara/Utility/Formats/MD5AnimLoader.cpp | 12 +- src/Nazara/Utility/Formats/MD5AnimParser.cpp | 52 +-- src/Nazara/Utility/Formats/MD5MeshLoader.cpp | 12 +- src/Nazara/Utility/Formats/MD5MeshParser.cpp | 18 +- src/Nazara/Utility/Formats/MTLParser.cpp | 16 +- src/Nazara/Utility/Formats/OBJLoader.cpp | 22 +- src/Nazara/Utility/Formats/OBJParser.cpp | 28 +- src/Nazara/Utility/Formats/OBJSaver.cpp | 14 +- src/Nazara/Utility/Mesh.cpp | 58 ++-- src/Nazara/Utility/Skeleton.cpp | 32 +- src/Nazara/Utility/SubMesh.cpp | 4 +- 22 files changed, 276 insertions(+), 489 deletions(-) diff --git a/include/Nazara/Utility/Animation.hpp b/include/Nazara/Utility/Animation.hpp index e196a0f77..2ab1f2baa 100644 --- a/include/Nazara/Utility/Animation.hpp +++ b/include/Nazara/Utility/Animation.hpp @@ -20,16 +20,15 @@ #include #include #include -#include namespace Nz { struct NAZARA_UTILITY_API AnimationParams : ResourceParameters { // La frame de fin à charger - unsigned int endFrame = std::numeric_limits::max(); + UInt32 endFrame = 0xFFFFFFFF; // La frame de début à charger - unsigned int startFrame = 0; + UInt32 startFrame = 0; bool IsValid() const; }; @@ -57,27 +56,27 @@ namespace Nz ~Animation(); bool AddSequence(const Sequence& sequence); - void AnimateSkeleton(Skeleton* targetSkeleton, unsigned int frameA, unsigned int frameB, float interpolation) const; + void AnimateSkeleton(Skeleton* targetSkeleton, UInt32 frameA, UInt32 frameB, float interpolation) const; - bool CreateSkeletal(unsigned int frameCount, unsigned int jointCount); + bool CreateSkeletal(UInt32 frameCount, UInt32 jointCount); void Destroy(); void EnableLoopPointInterpolation(bool loopPointInterpolation); - unsigned int GetFrameCount() const; - unsigned int GetJointCount() const; + UInt32 GetFrameCount() const; + UInt32 GetJointCount() const; Sequence* GetSequence(const String& sequenceName); - Sequence* GetSequence(unsigned int index); + Sequence* GetSequence(UInt32 index); const Sequence* GetSequence(const String& sequenceName) const; - const Sequence* GetSequence(unsigned int index) const; - unsigned int GetSequenceCount() const; - int GetSequenceIndex(const String& sequenceName) const; - SequenceJoint* GetSequenceJoints(unsigned int frameIndex = 0); - const SequenceJoint* GetSequenceJoints(unsigned int frameIndex = 0) const; + const Sequence* GetSequence(UInt32 index) const; + UInt32 GetSequenceCount() const; + UInt32 GetSequenceIndex(const String& sequenceName) const; + SequenceJoint* GetSequenceJoints(UInt32 frameIndex = 0); + const SequenceJoint* GetSequenceJoints(UInt32 frameIndex = 0) const; AnimationType GetType() const; bool HasSequence(const String& sequenceName) const; - bool HasSequence(unsigned int index = 0) const; + bool HasSequence(UInt32 index = 0) const; bool IsLoopPointInterpolationEnabled() const; bool IsValid() const; @@ -87,7 +86,7 @@ namespace Nz bool LoadFromStream(Stream& stream, const AnimationParams& params = AnimationParams()); void RemoveSequence(const String& sequenceName); - void RemoveSequence(unsigned int index); + void RemoveSequence(UInt32 index); template static AnimationRef New(Args&&... args); diff --git a/include/Nazara/Utility/Formats/MD5AnimParser.hpp b/include/Nazara/Utility/Formats/MD5AnimParser.hpp index 558608142..3a9e2163d 100644 --- a/include/Nazara/Utility/Formats/MD5AnimParser.hpp +++ b/include/Nazara/Utility/Formats/MD5AnimParser.hpp @@ -34,12 +34,12 @@ namespace Nz struct Joint { + Int32 parent; Quaternionf bindOrient; String name; Vector3f bindPos; - int parent; - unsigned int flags; - unsigned int index; + UInt32 flags; + UInt32 index; }; MD5AnimParser(Stream& stream); @@ -47,12 +47,12 @@ namespace Nz Ternary Check(); - std::size_t GetAnimatedComponentCount() const; + UInt32 GetAnimatedComponentCount() const; const Frame* GetFrames() const; - std::size_t GetFrameCount() const; - std::size_t GetFrameRate() const; + UInt32 GetFrameCount() const; + UInt32 GetFrameRate() const; const Joint* GetJoints() const; - std::size_t GetJointCount() const; + UInt32 GetJointCount() const; bool Parse(); diff --git a/include/Nazara/Utility/Formats/MD5MeshParser.hpp b/include/Nazara/Utility/Formats/MD5MeshParser.hpp index cd2d19309..b515c1226 100644 --- a/include/Nazara/Utility/Formats/MD5MeshParser.hpp +++ b/include/Nazara/Utility/Formats/MD5MeshParser.hpp @@ -22,10 +22,10 @@ namespace Nz public: struct Joint { + Int32 parent; Quaternionf bindOrient; String name; Vector3f bindPos; - int parent; }; typedef Vector3ui Triangle; @@ -58,9 +58,9 @@ namespace Nz Ternary Check(); const Joint* GetJoints() const; - std::size_t GetJointCount() const; + UInt32 GetJointCount() const; const Mesh* GetMeshes() const; - std::size_t GetMeshCount() const; + UInt32 GetMeshCount() const; bool Parse(); diff --git a/include/Nazara/Utility/Formats/OBJParser.hpp b/include/Nazara/Utility/Formats/OBJParser.hpp index 114f72635..6c0c35af4 100644 --- a/include/Nazara/Utility/Formats/OBJParser.hpp +++ b/include/Nazara/Utility/Formats/OBJParser.hpp @@ -31,43 +31,43 @@ namespace Nz inline String* GetMaterials(); inline const String* GetMaterials() const; - inline unsigned int GetMaterialCount() const; + inline UInt32 GetMaterialCount() const; inline Mesh* GetMeshes(); inline const Mesh* GetMeshes() const; - inline unsigned int GetMeshCount() const; + inline UInt32 GetMeshCount() const; inline const String& GetMtlLib() const; inline Vector3f* GetNormals(); inline const Vector3f* GetNormals() const; - inline unsigned int GetNormalCount() const; + inline UInt32 GetNormalCount() const; inline Vector4f* GetPositions(); inline const Vector4f* GetPositions() const; - inline unsigned int GetPositionCount() const; + inline UInt32 GetPositionCount() const; inline Vector3f* GetTexCoords(); inline const Vector3f* GetTexCoords() const; - inline unsigned int GetTexCoordCount() const; + inline UInt32 GetTexCoordCount() const; - bool Parse(Stream& stream, std::size_t reservedVertexCount = 100); + bool Parse(Stream& stream, UInt32 reservedVertexCount = 100); bool Save(Stream& stream) const; - inline String* SetMaterialCount(std::size_t materialCount); - inline Mesh* SetMeshCount(std::size_t meshCount); + inline String* SetMaterialCount(UInt32 materialCount); + inline Mesh* SetMeshCount(UInt32 meshCount); inline void SetMtlLib(const String& mtlLib); - inline Vector3f* SetNormalCount(std::size_t normalCount); - inline Vector4f* SetPositionCount(std::size_t positionCount); - inline Vector3f* SetTexCoordCount(std::size_t texCoordCount); + inline Vector3f* SetNormalCount(UInt32 normalCount); + inline Vector4f* SetPositionCount(UInt32 positionCount); + inline Vector3f* SetTexCoordCount(UInt32 texCoordCount); struct Face { - std::size_t firstVertex; - std::size_t vertexCount; + UInt32 firstVertex; + UInt32 vertexCount; }; struct FaceVertex { - std::size_t normal; - std::size_t position; - std::size_t texCoord; + UInt32 normal; + UInt32 position; + UInt32 texCoord; }; struct Mesh @@ -75,7 +75,7 @@ namespace Nz std::vector faces; std::vector vertices; String name; - std::size_t material; + UInt32 material; }; private: diff --git a/include/Nazara/Utility/Formats/OBJParser.inl b/include/Nazara/Utility/Formats/OBJParser.inl index b04506fdf..41e794f82 100644 --- a/include/Nazara/Utility/Formats/OBJParser.inl +++ b/include/Nazara/Utility/Formats/OBJParser.inl @@ -27,9 +27,9 @@ namespace Nz return m_materials.data(); } - inline unsigned int OBJParser::GetMaterialCount() const + inline UInt32 OBJParser::GetMaterialCount() const { - return m_materials.size(); + return static_cast(m_materials.size()); } inline OBJParser::Mesh* OBJParser::GetMeshes() @@ -42,9 +42,9 @@ namespace Nz return m_meshes.data(); } - inline unsigned int OBJParser::GetMeshCount() const + inline UInt32 OBJParser::GetMeshCount() const { - return m_meshes.size(); + return static_cast(m_meshes.size()); } inline const String& OBJParser::GetMtlLib() const @@ -62,9 +62,9 @@ namespace Nz return m_normals.data(); } - inline unsigned int OBJParser::GetNormalCount() const + inline UInt32 OBJParser::GetNormalCount() const { - return m_normals.size(); + return static_cast(m_normals.size()); } inline Vector4f* OBJParser::GetPositions() @@ -77,9 +77,9 @@ namespace Nz return m_positions.data(); } - inline unsigned int OBJParser::GetPositionCount() const + inline UInt32 OBJParser::GetPositionCount() const { - return m_positions.size(); + return static_cast(m_positions.size()); } inline Vector3f* OBJParser::GetTexCoords() @@ -92,18 +92,18 @@ namespace Nz return m_texCoords.data(); } - inline unsigned int OBJParser::GetTexCoordCount() const + inline UInt32 OBJParser::GetTexCoordCount() const { - return m_texCoords.size(); + return static_cast(m_texCoords.size()); } - inline String* OBJParser::SetMaterialCount(std::size_t materialCount) + inline String* OBJParser::SetMaterialCount(UInt32 materialCount) { m_materials.resize(materialCount); return m_materials.data(); } - inline OBJParser::Mesh* OBJParser::SetMeshCount(std::size_t meshCount) + inline OBJParser::Mesh* OBJParser::SetMeshCount(UInt32 meshCount) { m_meshes.resize(meshCount); return m_meshes.data(); @@ -114,19 +114,19 @@ namespace Nz m_mtlLib = mtlLib; } - inline Vector3f* OBJParser::SetNormalCount(std::size_t normalCount) + inline Vector3f* OBJParser::SetNormalCount(UInt32 normalCount) { m_normals.resize(normalCount); return m_normals.data(); } - inline Vector4f* OBJParser::SetPositionCount(std::size_t positionCount) + inline Vector4f* OBJParser::SetPositionCount(UInt32 positionCount) { m_positions.resize(positionCount); return m_positions.data(); } - inline Vector3f* OBJParser::SetTexCoordCount(std::size_t texCoordCount) + inline Vector3f* OBJParser::SetTexCoordCount(UInt32 texCoordCount) { m_texCoords.resize(texCoordCount); return m_texCoords.data(); diff --git a/include/Nazara/Utility/Mesh.hpp b/include/Nazara/Utility/Mesh.hpp index 62a372384..60ccb98b1 100644 --- a/include/Nazara/Utility/Mesh.hpp +++ b/include/Nazara/Utility/Mesh.hpp @@ -84,7 +84,7 @@ namespace Nz SubMesh* BuildSubMesh(const Primitive& primitive, const MeshParams& params = MeshParams()); void BuildSubMeshes(const PrimitiveList& list, const MeshParams& params = MeshParams()); - bool CreateSkeletal(unsigned int jointCount); + bool CreateSkeletal(UInt32 jointCount); bool CreateStatic(); void Destroy(); @@ -95,23 +95,23 @@ namespace Nz const Boxf& GetAABB() const; String GetAnimation() const; AnimationType GetAnimationType() const; - unsigned int GetJointCount() const; - ParameterList& GetMaterialData(unsigned int index); - const ParameterList& GetMaterialData(unsigned int index) const; - unsigned int GetMaterialCount() const; + UInt32 GetJointCount() const; + ParameterList& GetMaterialData(UInt32 index); + const ParameterList& GetMaterialData(UInt32 index) const; + UInt32 GetMaterialCount() const; Skeleton* GetSkeleton(); const Skeleton* GetSkeleton() const; SubMesh* GetSubMesh(const String& identifier); - SubMesh* GetSubMesh(unsigned int index); + SubMesh* GetSubMesh(UInt32 index); const SubMesh* GetSubMesh(const String& identifier) const; - const SubMesh* GetSubMesh(unsigned int index) const; - unsigned int GetSubMeshCount() const; - int GetSubMeshIndex(const String& identifier) const; - unsigned int GetTriangleCount() const; - unsigned int GetVertexCount() const; + const SubMesh* GetSubMesh(UInt32 index) const; + UInt32 GetSubMeshCount() const; + UInt32 GetSubMeshIndex(const String& identifier) const; + UInt32 GetTriangleCount() const; + UInt32 GetVertexCount() const; bool HasSubMesh(const String& identifier) const; - bool HasSubMesh(unsigned int index = 0) const; + bool HasSubMesh(UInt32 index = 0) const; void InvalidateAABB() const; @@ -125,14 +125,14 @@ namespace Nz void Recenter(); void RemoveSubMesh(const String& identifier); - void RemoveSubMesh(unsigned int index); + void RemoveSubMesh(UInt32 index); bool SaveToFile(const String& filePath, const MeshParams& params = MeshParams()); bool SaveToStream(Stream& stream, const String& format, const MeshParams& params = MeshParams()); void SetAnimation(const String& animationPath); - void SetMaterialCount(unsigned int matCount); - void SetMaterialData(unsigned int matIndex, ParameterList data); + void SetMaterialCount(UInt32 matCount); + void SetMaterialData(UInt32 matIndex, ParameterList data); void Transform(const Matrix4f& matrix); diff --git a/include/Nazara/Utility/Sequence.hpp b/include/Nazara/Utility/Sequence.hpp index 1c6812eb7..b8549a4bf 100644 --- a/include/Nazara/Utility/Sequence.hpp +++ b/include/Nazara/Utility/Sequence.hpp @@ -16,9 +16,9 @@ namespace Nz struct Sequence { String name; - unsigned int firstFrame; - unsigned int frameCount; - unsigned int frameRate; + UInt32 firstFrame; + UInt32 frameCount; + UInt32 frameRate; }; struct SequenceJoint diff --git a/include/Nazara/Utility/Skeleton.hpp b/include/Nazara/Utility/Skeleton.hpp index fa217e6d4..8312f967f 100644 --- a/include/Nazara/Utility/Skeleton.hpp +++ b/include/Nazara/Utility/Skeleton.hpp @@ -37,21 +37,21 @@ namespace Nz Skeleton(const Skeleton& skeleton); ~Skeleton(); - bool Create(unsigned int jointCount); + bool Create(UInt32 jointCount); void Destroy(); const Boxf& GetAABB() const; Joint* GetJoint(const String& jointName); - Joint* GetJoint(unsigned int index); + Joint* GetJoint(UInt32 index); const Joint* GetJoint(const String& jointName) const; - const Joint* GetJoint(unsigned int index) const; + const Joint* GetJoint(UInt32 index) const; Joint* GetJoints(); const Joint* GetJoints() const; - unsigned int GetJointCount() const; + UInt32 GetJointCount() const; int GetJointIndex(const String& jointName) const; void Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation); - void Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation, unsigned int* indices, unsigned int indiceCount); + void Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation, UInt32* indices, UInt32 indiceCount); bool IsValid() const; diff --git a/include/Nazara/Utility/SubMesh.hpp b/include/Nazara/Utility/SubMesh.hpp index 6eee3a152..525930e0b 100644 --- a/include/Nazara/Utility/SubMesh.hpp +++ b/include/Nazara/Utility/SubMesh.hpp @@ -39,15 +39,15 @@ namespace Nz virtual const Boxf& GetAABB() const = 0; virtual AnimationType GetAnimationType() const = 0; virtual const IndexBuffer* GetIndexBuffer() const = 0; - unsigned int GetMaterialIndex() const; + UInt32 GetMaterialIndex() const; const Mesh* GetParent() const; PrimitiveMode GetPrimitiveMode() const; - unsigned int GetTriangleCount() const; - virtual unsigned int GetVertexCount() const = 0; + UInt32 GetTriangleCount() const; + virtual UInt32 GetVertexCount() const = 0; virtual bool IsAnimated() const = 0; - void SetMaterialIndex(unsigned int matIndex); + void SetMaterialIndex(UInt32 matIndex); void SetPrimitiveMode(PrimitiveMode mode); // Signals: @@ -56,7 +56,7 @@ namespace Nz protected: PrimitiveMode m_primitiveMode; const Mesh* m_parent; - unsigned int m_matIndex; + UInt32 m_matIndex; }; } diff --git a/include/Nazara/Utility/VertexMapper.inl b/include/Nazara/Utility/VertexMapper.inl index 7b36743eb..4a155bfbd 100644 --- a/include/Nazara/Utility/VertexMapper.inl +++ b/include/Nazara/Utility/VertexMapper.inl @@ -28,8 +28,8 @@ namespace Nz { NazaraError("Attribute 0x" + String::Number(component, 16) + " is not enabled"); return SparsePtr(); + } } } -} #include diff --git a/src/Nazara/Utility/Animation.cpp b/src/Nazara/Utility/Animation.cpp index 62591344b..a996f85a5 100644 --- a/src/Nazara/Utility/Animation.cpp +++ b/src/Nazara/Utility/Animation.cpp @@ -14,13 +14,13 @@ namespace Nz { struct AnimationImpl { - std::unordered_map sequenceMap; + std::unordered_map sequenceMap; std::vector sequences; std::vector sequenceJoints; // Uniquement pour les animations squelettiques AnimationType type; bool loopPointInterpolation = false; - unsigned int frameCount; - unsigned int jointCount; // Uniquement pour les animations squelettiques + UInt32 frameCount; + UInt32 jointCount; // Uniquement pour les animations squelettiques }; bool AnimationParams::IsValid() const @@ -43,40 +43,18 @@ namespace Nz bool Animation::AddSequence(const Sequence& sequence) { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return false; - } - - if (sequence.frameCount == 0) - { - NazaraError("Sequence frame count must be over zero"); - return false; - } - #endif + NazaraAssert(m_impl, "Animation not created"); + NazaraAssert(sequence.frameCount > 0, "Sequence frame count must be over zero"); if (m_impl->type == AnimationType_Skeletal) { - unsigned int endFrame = sequence.firstFrame + sequence.frameCount - 1; + UInt32 endFrame = sequence.firstFrame + sequence.frameCount - 1; if (endFrame >= m_impl->frameCount) { m_impl->frameCount = endFrame+1; m_impl->sequenceJoints.resize(m_impl->frameCount*m_impl->jointCount); } } - #if NAZARA_UTILITY_SAFE - else - { - unsigned int endFrame = sequence.firstFrame + sequence.frameCount - 1; - if (endFrame >= m_impl->frameCount) - { - NazaraError("Sequence end frame is over animation end frame"); - return false; - } - } - #endif if (!sequence.name.IsEmpty()) { @@ -84,12 +62,12 @@ namespace Nz auto it = m_impl->sequenceMap.find(sequence.name); if (it != m_impl->sequenceMap.end()) { - NazaraError("Sequence name \"" + sequence.name + "\" is already used"); + NazaraError("Sequence name \"" + sequence.name + "\" is already in use"); return false; } #endif - m_impl->sequenceMap[sequence.name] = m_impl->sequences.size(); + m_impl->sequenceMap[sequence.name] = static_cast(m_impl->sequences.size()); } m_impl->sequences.push_back(sequence); @@ -97,55 +75,16 @@ namespace Nz return true; } - void Animation::AnimateSkeleton(Skeleton* targetSkeleton, unsigned int frameA, unsigned int frameB, float interpolation) const + void Animation::AnimateSkeleton(Skeleton* targetSkeleton, UInt32 frameA, UInt32 frameB, float interpolation) const { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return; - } + NazaraAssert(m_impl, "Animation not created"); + NazaraAssert(m_impl->type == AnimationType_Skeletal, "Animation is not skeletal"); + NazaraAssert(targetSkeleton && targetSkeleton->IsValid(), "Invalid skeleton"); + NazaraAssert(targetSkeleton->GetJointCount() == m_impl->jointCount, "Skeleton joint does not match animation joint count"); + NazaraAssert(frameA < m_impl->frameCount, "FrameA is out of range"); + NazaraAssert(frameB < m_impl->frameCount, "FrameB is out of range"); - if (m_impl->type != AnimationType_Skeletal) - { - NazaraError("Animation is not skeletal"); - return; - } - - if (!targetSkeleton || !targetSkeleton->IsValid()) - { - NazaraError("Target skeleton is invalid"); - return; - } - - if (targetSkeleton->GetJointCount() != m_impl->jointCount) - { - NazaraError("Target skeleton joint count must match animation joint count"); - return; - } - - if (frameA >= m_impl->frameCount) - { - NazaraError("Frame A is out of range (" + String::Number(frameA) + " >= " + String::Number(m_impl->frameCount) + ')'); - return; - } - - if (frameB >= m_impl->frameCount) - { - NazaraError("Frame B is out of range (" + String::Number(frameB) + " >= " + String::Number(m_impl->frameCount) + ')'); - return; - } - #endif - - #ifdef NAZARA_DEBUG - if (interpolation < 0.f || interpolation > 1.f) - { - NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')'); - return; - } - #endif - - for (unsigned int i = 0; i < m_impl->jointCount; ++i) + for (UInt32 i = 0; i < m_impl->jointCount; ++i) { Joint* joint = targetSkeleton->GetJoint(i); @@ -158,17 +97,12 @@ namespace Nz } } - bool Animation::CreateSkeletal(unsigned int frameCount, unsigned int jointCount) + bool Animation::CreateSkeletal(UInt32 frameCount, UInt32 jointCount) { - Destroy(); + NazaraAssert(frameCount > 0, "Frame count must be over zero"); + NazaraAssert(jointCount > 0, "Frame count must be over zero"); - #if NAZARA_UTILITY_SAFE - if (frameCount == 0) - { - NazaraError("Frame count must be over zero"); - return false; - } - #endif + Destroy(); m_impl = new AnimationImpl; m_impl->frameCount = frameCount; @@ -192,255 +126,130 @@ namespace Nz void Animation::EnableLoopPointInterpolation(bool loopPointInterpolation) { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return; - } - #endif + NazaraAssert(m_impl, "Animation not created"); m_impl->loopPointInterpolation = loopPointInterpolation; } - unsigned int Animation::GetFrameCount() const + UInt32 Animation::GetFrameCount() const { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return false; - } - #endif + NazaraAssert(m_impl, "Animation not created"); return m_impl->frameCount; } - unsigned int Animation::GetJointCount() const + UInt32 Animation::GetJointCount() const { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return 0; - } - - if (m_impl->type != AnimationType_Skeletal) - { - NazaraError("Animation is not skeletal"); - return 0; - } - #endif + NazaraAssert(m_impl, "Animation not created"); return m_impl->jointCount; } Sequence* Animation::GetSequence(const String& sequenceName) { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - #endif + NazaraAssert(m_impl, "Animation not created"); auto it = m_impl->sequenceMap.find(sequenceName); - - #if NAZARA_UTILITY_SAFE if (it == m_impl->sequenceMap.end()) { NazaraError("Sequence not found"); return nullptr; } - #endif return &m_impl->sequences[it->second]; } - Sequence* Animation::GetSequence(unsigned int index) + Sequence* Animation::GetSequence(UInt32 index) { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - - if (index >= m_impl->sequences.size()) - { - NazaraError("Sequence index out of range (" + String::Number(index) + " >= " + String::Number(m_impl->sequences.size()) + ')'); - return nullptr; - } - #endif + NazaraAssert(m_impl, "Animation not created"); + NazaraAssert(index < m_impl->sequences.size(), "Sequence index out of range"); return &m_impl->sequences[index]; } const Sequence* Animation::GetSequence(const String& sequenceName) const { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - #endif + NazaraAssert(m_impl, "Animation not created"); auto it = m_impl->sequenceMap.find(sequenceName); - - #if NAZARA_UTILITY_SAFE if (it == m_impl->sequenceMap.end()) { NazaraError("Sequence not found"); return nullptr; } - #endif return &m_impl->sequences[it->second]; } - const Sequence* Animation::GetSequence(unsigned int index) const + const Sequence* Animation::GetSequence(UInt32 index) const { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - - if (index >= m_impl->sequences.size()) - { - NazaraError("Sequence index out of range (" + String::Number(index) + " >= " + String::Number(m_impl->sequences.size()) + ')'); - return nullptr; - } - #endif + NazaraAssert(m_impl, "Animation not created"); + NazaraAssert(index < m_impl->sequences.size(), "Sequence index out of range"); return &m_impl->sequences[index]; } - unsigned int Animation::GetSequenceCount() const + UInt32 Animation::GetSequenceCount() const { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return 0; - } - #endif + NazaraAssert(m_impl, "Animation not created"); - return m_impl->sequences.size(); + return static_cast(m_impl->sequences.size()); } - int Animation::GetSequenceIndex(const String& sequenceName) const + UInt32 Animation::GetSequenceIndex(const String& sequenceName) const { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return -1; - } - #endif + NazaraAssert(m_impl, "Animation not created"); auto it = m_impl->sequenceMap.find(sequenceName); - - #if NAZARA_UTILITY_SAFE if (it == m_impl->sequenceMap.end()) { NazaraError("Sequence not found"); - return -1; + return 0xFFFFFFFF; } - #endif return it->second; } - SequenceJoint* Animation::GetSequenceJoints(unsigned int frameIndex) + SequenceJoint* Animation::GetSequenceJoints(UInt32 frameIndex) { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - - if (m_impl->type != AnimationType_Skeletal) - { - NazaraError("Animation is not skeletal"); - return nullptr; - } - #endif + NazaraAssert(m_impl, "Animation not created"); + NazaraAssert(m_impl->type == AnimationType_Skeletal, "Animation is not skeletal"); return &m_impl->sequenceJoints[frameIndex*m_impl->jointCount]; } - const SequenceJoint* Animation::GetSequenceJoints(unsigned int frameIndex) const + const SequenceJoint* Animation::GetSequenceJoints(UInt32 frameIndex) const { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return nullptr; - } - - if (m_impl->type != AnimationType_Skeletal) - { - NazaraError("Animation is not skeletal"); - return nullptr; - } - #endif + NazaraAssert(m_impl, "Animation not created"); + NazaraAssert(m_impl->type == AnimationType_Skeletal, "Animation is not skeletal"); return &m_impl->sequenceJoints[frameIndex*m_impl->jointCount]; } AnimationType Animation::GetType() const { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return AnimationType_Static; // Ce qui est une valeur invalide pour Animation - } - #endif + NazaraAssert(m_impl, "Animation not created"); return m_impl->type; } bool Animation::HasSequence(const String& sequenceName) const { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return false; - } - #endif + NazaraAssert(m_impl, "Animation not created"); return m_impl->sequenceMap.find(sequenceName) != m_impl->sequenceMap.end(); } - bool Animation::HasSequence(unsigned int index) const + bool Animation::HasSequence(UInt32 index) const { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return false; - } - #endif + NazaraAssert(m_impl, "Animation not created"); return index >= m_impl->sequences.size(); } bool Animation::IsLoopPointInterpolationEnabled() const { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return false; - } - #endif + NazaraAssert(m_impl, "Animation not created"); return m_impl->loopPointInterpolation; } @@ -467,12 +276,7 @@ namespace Nz void Animation::RemoveSequence(const String& identifier) { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return; - } + NazaraAssert(m_impl, "Animation not created"); auto it = m_impl->sequenceMap.find(identifier); if (it == m_impl->sequenceMap.end()) @@ -481,32 +285,16 @@ namespace Nz return; } - int index = it->second; - #else - int index = m_impl->sequenceMap[identifier]; - #endif + auto sequenceIt = m_impl->sequences.begin(); + std::advance(sequenceIt, it->second); - auto it2 = m_impl->sequences.begin(); - std::advance(it2, index); - - m_impl->sequences.erase(it2); + m_impl->sequences.erase(sequenceIt); } - void Animation::RemoveSequence(unsigned int index) + void Animation::RemoveSequence(UInt32 index) { - #if NAZARA_UTILITY_SAFE - if (!m_impl) - { - NazaraError("Animation not created"); - return; - } - - if (index >= m_impl->sequences.size()) - { - NazaraError("Sequence index out of range (" + String::Number(index) + " >= " + String::Number(m_impl->sequences.size()) + ')'); - return; - } - #endif + NazaraAssert(m_impl, "Animation not created"); + NazaraAssert(index < m_impl->sequences.size(), "Sequence index out of range"); auto it = m_impl->sequences.begin(); std::advance(it, index); diff --git a/src/Nazara/Utility/Formats/MD5AnimLoader.cpp b/src/Nazara/Utility/Formats/MD5AnimLoader.cpp index e61f6dda2..942b54f8e 100644 --- a/src/Nazara/Utility/Formats/MD5AnimLoader.cpp +++ b/src/Nazara/Utility/Formats/MD5AnimLoader.cpp @@ -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]; diff --git a/src/Nazara/Utility/Formats/MD5AnimParser.cpp b/src/Nazara/Utility/Formats/MD5AnimParser.cpp index 105944858..a1b02153b 100644 --- a/src/Nazara/Utility/Formats/MD5AnimParser.cpp +++ b/src/Nazara/Utility/Formats/MD5AnimParser.cpp @@ -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(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(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(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(parent) >= jointCount) + if (static_cast(parent) >= jointCount) { Error("Joint's parent is out of bounds (" + String::Number(parent) + " >= " + String::Number(jointCount) + ')'); return false; diff --git a/src/Nazara/Utility/Formats/MD5MeshLoader.cpp b/src/Nazara/Utility/Formats/MD5MeshLoader.cpp index cd8a6813a..59988405a 100644 --- a/src/Nazara/Utility/Formats/MD5MeshLoader.cpp +++ b/src/Nazara/Utility/Formats/MD5MeshLoader.cpp @@ -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; diff --git a/src/Nazara/Utility/Formats/MD5MeshParser.cpp b/src/Nazara/Utility/Formats/MD5MeshParser.cpp index b4fd04a33..ce5264d01 100644 --- a/src/Nazara/Utility/Formats/MD5MeshParser.cpp +++ b/src/Nazara/Utility/Formats/MD5MeshParser.cpp @@ -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(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(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(parent) >= jointCount) + if (static_cast(parent) >= jointCount) { Error("Joint's parent is out of bounds (" + String::Number(parent) + " >= " + String::Number(jointCount) + ')'); return false; diff --git a/src/Nazara/Utility/Formats/MTLParser.cpp b/src/Nazara/Utility/Formats/MTLParser.cpp index 6685bcd04..b31ee24a9 100644 --- a/src/Nazara/Utility/Formats/MTLParser.cpp +++ b/src/Nazara/Utility/Formats/MTLParser.cpp @@ -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); diff --git a/src/Nazara/Utility/Formats/OBJLoader.cpp b/src/Nazara/Utility/Formats/OBJLoader.cpp index 405c845ea..11029bada 100644 --- a/src/Nazara/Utility/Formats/OBJLoader.cpp +++ b/src/Nazara/Utility/Formats/OBJLoader.cpp @@ -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 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 faceIndices(3); // Comme il y aura au moins trois sommets - for (unsigned int i = 0; i < meshCount; ++i) + std::vector 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 indices; + std::vector 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 diff --git a/src/Nazara/Utility/Formats/OBJParser.cpp b/src/Nazara/Utility/Formats/OBJParser.cpp index e2b63b467..a520d6be1 100644 --- a/src/Nazara/Utility/Formats/OBJParser.cpp +++ b/src/Nazara/Utility/Formats/OBJParser.cpp @@ -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; std::unordered_map> 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(currentMesh->vertices.size()); + face.vertexCount = static_cast(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(n); - currentMesh->vertices[face.firstVertex + i].position = static_cast(p); - currentMesh->vertices[face.firstVertex + i].texCoord = static_cast(t); + currentMesh->vertices[face.firstVertex + i].normal = static_cast(n); + currentMesh->vertices[face.firstVertex + i].position = static_cast(p); + currentMesh->vertices[face.firstVertex + i].texCoord = static_cast(t); pos += offset; } diff --git a/src/Nazara/Utility/Formats/OBJSaver.cpp b/src/Nazara/Utility/Formats/OBJSaver.cpp index a7a2cda0b..534eb1952 100644 --- a/src/Nazara/Utility/Formats/OBJSaver.cpp +++ b/src/Nazara/Utility/Formats/OBJSaver.cpp @@ -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 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(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]; diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index 84559abda..363be074d 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -55,7 +55,7 @@ namespace Nz materialData.resize(1); // Un matériau par défaut } - std::unordered_map subMeshMap; + std::unordered_map subMeshMap; std::vector materialData; std::vector subMeshes; AnimationType animationType; @@ -63,7 +63,7 @@ namespace Nz Skeleton skeleton; // Uniquement pour les meshs squelettiques String animationPath; bool aabbUpdated = false; - unsigned int jointCount; // Uniquement pour les meshs squelettiques + UInt32 jointCount; // Uniquement pour les meshs squelettiques }; Mesh::~Mesh() @@ -92,7 +92,7 @@ namespace Nz NazaraAssert(subMesh, "Invalid submesh"); NazaraAssert(subMesh->GetAnimationType() == m_impl->animationType, "Submesh animation type doesn't match mesh animation type"); - int index = m_impl->subMeshes.size(); + UInt32 index = m_impl->subMeshes.size(); m_impl->subMeshes.push_back(subMesh); m_impl->subMeshMap[identifier] = index; @@ -276,11 +276,11 @@ namespace Nz void Mesh::BuildSubMeshes(const PrimitiveList& list, const MeshParams& params) { - for (unsigned int i = 0; i < list.GetSize(); ++i) + for (UInt32 i = 0; i < list.GetSize(); ++i) BuildSubMesh(list.GetPrimitive(i), params); } - bool Mesh::CreateSkeletal(unsigned int jointCount) + bool Mesh::CreateSkeletal(UInt32 jointCount) { Destroy(); @@ -349,11 +349,11 @@ namespace Nz if (!m_impl->aabbUpdated) { - unsigned int subMeshCount = m_impl->subMeshes.size(); + UInt32 subMeshCount = m_impl->subMeshes.size(); if (subMeshCount > 0) { m_impl->aabb.Set(m_impl->subMeshes[0]->GetAABB()); - for (unsigned int i = 1; i < subMeshCount; ++i) + for (UInt32 i = 1; i < subMeshCount; ++i) m_impl->aabb.ExtendTo(m_impl->subMeshes[i]->GetAABB()); } else @@ -379,7 +379,7 @@ namespace Nz return m_impl->animationType; } - unsigned int Mesh::GetJointCount() const + UInt32 Mesh::GetJointCount() const { NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(m_impl->animationType == AnimationType_Skeletal, "Mesh is not skeletal"); @@ -387,7 +387,7 @@ namespace Nz return m_impl->jointCount; } - ParameterList& Mesh::GetMaterialData(unsigned int index) + ParameterList& Mesh::GetMaterialData(UInt32 index) { NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(index < m_impl->materialData.size(), "Material index out of range"); @@ -395,7 +395,7 @@ namespace Nz return m_impl->materialData[index]; } - const ParameterList& Mesh::GetMaterialData(unsigned int index) const + const ParameterList& Mesh::GetMaterialData(UInt32 index) const { NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(index < m_impl->materialData.size(), "Material index out of range"); @@ -403,7 +403,7 @@ namespace Nz return m_impl->materialData[index]; } - unsigned int Mesh::GetMaterialCount() const + UInt32 Mesh::GetMaterialCount() const { NazaraAssert(m_impl, "Mesh should be created first"); @@ -436,7 +436,7 @@ namespace Nz return m_impl->subMeshes[it->second]; } - SubMesh* Mesh::GetSubMesh(unsigned int index) + SubMesh* Mesh::GetSubMesh(UInt32 index) { NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(index < m_impl->subMeshes.size(), "Submesh index out of range"); @@ -454,7 +454,7 @@ namespace Nz return m_impl->subMeshes[it->second]; } - const SubMesh* Mesh::GetSubMesh(unsigned int index) const + const SubMesh* Mesh::GetSubMesh(UInt32 index) const { NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(index < m_impl->subMeshes.size(), "Submesh index out of range"); @@ -462,14 +462,14 @@ namespace Nz return m_impl->subMeshes[index]; } - unsigned int Mesh::GetSubMeshCount() const + UInt32 Mesh::GetSubMeshCount() const { NazaraAssert(m_impl, "Mesh should be created first"); return m_impl->subMeshes.size(); } - int Mesh::GetSubMeshIndex(const String& identifier) const + UInt32 Mesh::GetSubMeshIndex(const String& identifier) const { NazaraAssert(m_impl, "Mesh should be created first"); @@ -479,22 +479,22 @@ namespace Nz return it->second; } - unsigned int Mesh::GetTriangleCount() const + UInt32 Mesh::GetTriangleCount() const { NazaraAssert(m_impl, "Mesh should be created first"); - unsigned int triangleCount = 0; + UInt32 triangleCount = 0; for (SubMesh* subMesh : m_impl->subMeshes) triangleCount += subMesh->GetTriangleCount(); return triangleCount; } - unsigned int Mesh::GetVertexCount() const + UInt32 Mesh::GetVertexCount() const { NazaraAssert(m_impl, "Mesh should be created first"); - unsigned int vertexCount = 0; + UInt32 vertexCount = 0; for (SubMesh* subMesh : m_impl->subMeshes) vertexCount += subMesh->GetVertexCount(); @@ -515,7 +515,7 @@ namespace Nz return m_impl->subMeshMap.find(identifier) != m_impl->subMeshMap.end(); } - bool Mesh::HasSubMesh(unsigned int index) const + bool Mesh::HasSubMesh(UInt32 index) const { NazaraAssert(m_impl, "Mesh should be created first"); @@ -564,8 +564,8 @@ namespace Nz BufferMapper mapper(staticMesh->GetVertexBuffer(), BufferAccess_ReadWrite); MeshVertex* vertices = static_cast(mapper.GetPointer()); - unsigned int vertexCount = staticMesh->GetVertexCount(); - for (unsigned int i = 0; i < vertexCount; ++i) + UInt32 vertexCount = staticMesh->GetVertexCount(); + for (UInt32 i = 0; i < vertexCount; ++i) { vertices->position -= center; vertices++; @@ -583,7 +583,7 @@ namespace Nz void Mesh::RemoveSubMesh(const String& identifier) { - unsigned int index = GetSubMeshIndex(identifier); + UInt32 index = GetSubMeshIndex(identifier); // On déplace l'itérateur du début d'une distance de x auto it2 = m_impl->subMeshes.begin(); @@ -593,7 +593,7 @@ namespace Nz InvalidateAABB(); } - void Mesh::RemoveSubMesh(unsigned int index) + void Mesh::RemoveSubMesh(UInt32 index) { NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(index < m_impl->subMeshes.size(), "Submesh index out of range"); @@ -623,7 +623,7 @@ namespace Nz m_impl->animationPath = animationPath; } - void Mesh::SetMaterialData(unsigned int matIndex, ParameterList data) + void Mesh::SetMaterialData(UInt32 matIndex, ParameterList data) { NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(matIndex < m_impl->materialData.size(), "Material index out of range"); @@ -631,7 +631,7 @@ namespace Nz m_impl->materialData[matIndex] = std::move(data); } - void Mesh::SetMaterialCount(unsigned int matCount) + void Mesh::SetMaterialCount(UInt32 matCount) { NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(matCount > 0, "A mesh should have at least a material"); @@ -641,7 +641,7 @@ namespace Nz #ifdef NAZARA_DEBUG for (SubMesh* subMesh : m_impl->subMeshes) { - unsigned int matIndex = subMesh->GetMaterialIndex(); + UInt32 matIndex = subMesh->GetMaterialIndex(); if (matIndex >= matCount) { subMesh->SetMaterialIndex(0); // To prevent a crash @@ -665,8 +665,8 @@ namespace Nz Boxf aabb(vertices->position.x, vertices->position.y, vertices->position.z, 0.f, 0.f, 0.f); - unsigned int vertexCount = staticMesh->GetVertexCount(); - for (unsigned int i = 0; i < vertexCount; ++i) + UInt32 vertexCount = staticMesh->GetVertexCount(); + for (UInt32 i = 0; i < vertexCount; ++i) { vertices->position = matrix.Transform(vertices->position); aabb.ExtendTo(vertices->position); diff --git a/src/Nazara/Utility/Skeleton.cpp b/src/Nazara/Utility/Skeleton.cpp index ad5632b90..70f7adb07 100644 --- a/src/Nazara/Utility/Skeleton.cpp +++ b/src/Nazara/Utility/Skeleton.cpp @@ -10,7 +10,7 @@ namespace Nz { struct SkeletonImpl { - std::unordered_map jointMap; + std::unordered_map jointMap; std::vector joints; Boxf aabb; bool aabbUpdated = false; @@ -31,7 +31,7 @@ namespace Nz Destroy(); } - bool Skeleton::Create(unsigned int jointCount) + bool Skeleton::Create(UInt32 jointCount) { #if NAZARA_UTILITY_SAFE if (jointCount == 0) @@ -72,12 +72,12 @@ namespace Nz if (!m_impl->aabbUpdated) { - unsigned int jointCount = m_impl->joints.size(); + UInt32 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 (unsigned int i = 1; i < jointCount; ++i) + for (UInt32 i = 1; i < jointCount; ++i) m_impl->aabb.ExtendTo(m_impl->joints[i].GetPosition()); } else @@ -117,7 +117,7 @@ namespace Nz return &m_impl->joints[it->second]; } - Joint* Skeleton::GetJoint(unsigned int index) + Joint* Skeleton::GetJoint(UInt32 index) { #if NAZARA_UTILITY_SAFE if (!m_impl) @@ -164,7 +164,7 @@ namespace Nz return &m_impl->joints[it->second]; } - const Joint* Skeleton::GetJoint(unsigned int index) const + const Joint* Skeleton::GetJoint(UInt32 index) const { #if NAZARA_UTILITY_SAFE if (!m_impl) @@ -209,7 +209,7 @@ namespace Nz return &m_impl->joints[0]; } - unsigned int Skeleton::GetJointCount() const + UInt32 Skeleton::GetJointCount() const { #if NAZARA_UTILITY_SAFE if (!m_impl) @@ -278,13 +278,13 @@ namespace Nz Joint* jointsA = &skeletonA.m_impl->joints[0]; Joint* jointsB = &skeletonB.m_impl->joints[0]; - for (unsigned int i = 0; i < m_impl->joints.size(); ++i) + for (std::size_t i = 0; i < m_impl->joints.size(); ++i) m_impl->joints[i].Interpolate(jointsA[i], jointsB[i], interpolation, CoordSys_Local); InvalidateJoints(); } - void Skeleton::Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation, unsigned int* indices, unsigned int indiceCount) + void Skeleton::Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation, UInt32* indices, UInt32 indiceCount) { #if NAZARA_UTILITY_SAFE if (!m_impl) @@ -314,9 +314,9 @@ namespace Nz const Joint* jointsA = &skeletonA.m_impl->joints[0]; const Joint* jointsB = &skeletonB.m_impl->joints[0]; - for (unsigned int i = 0; i < indiceCount; ++i) + for (UInt32 i = 0; i < indiceCount; ++i) { - unsigned int index = indices[i]; + UInt32 index = indices[i]; #if NAZARA_UTILITY_SAFE if (index >= m_impl->joints.size()) @@ -351,16 +351,16 @@ namespace Nz m_impl->jointMapUpdated = skeleton.m_impl->jointMapUpdated; m_impl->joints = skeleton.m_impl->joints; - // Code crade mais son optimisation demanderait de stocker jointCount*sizeof(unsigned int) en plus + // Code crade mais son optimisation demanderait de stocker jointCount*sizeof(UInt32) en plus // Ce qui, pour juste une copie qui ne se fera que rarement, ne vaut pas le coup // L'éternel trade-off mémoire/calculs .. - unsigned int jointCount = skeleton.m_impl->joints.size(); - for (unsigned int i = 0; i < jointCount; ++i) + std::size_t jointCount = skeleton.m_impl->joints.size(); + for (std::size_t i = 0; i < jointCount; ++i) { const Node* parent = skeleton.m_impl->joints[i].GetParent(); if (parent) { - for (unsigned int j = 0; j < i; ++j) // Le parent se trouve forcément avant nous + for (std::size_t j = 0; j < i; ++j) // Le parent se trouve forcément avant nous { if (parent == &skeleton.m_impl->joints[j]) // A-t-on trouvé le parent ? { @@ -406,7 +406,7 @@ namespace Nz #endif m_impl->jointMap.clear(); - for (unsigned int i = 0; i < m_impl->joints.size(); ++i) + for (std::size_t i = 0; i < m_impl->joints.size(); ++i) { String name = m_impl->joints[i].GetName(); if (!name.IsEmpty()) diff --git a/src/Nazara/Utility/SubMesh.cpp b/src/Nazara/Utility/SubMesh.cpp index 8b0589808..c8da223f0 100644 --- a/src/Nazara/Utility/SubMesh.cpp +++ b/src/Nazara/Utility/SubMesh.cpp @@ -196,7 +196,7 @@ namespace Nz return 0; } - unsigned int SubMesh::GetMaterialIndex() const + UInt32 SubMesh::GetMaterialIndex() const { return m_matIndex; } @@ -206,7 +206,7 @@ namespace Nz m_primitiveMode = mode; } - void SubMesh::SetMaterialIndex(unsigned int matIndex) + void SubMesh::SetMaterialIndex(UInt32 matIndex) { m_matIndex = matIndex; }