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

@ -20,16 +20,15 @@
#include <Nazara/Utility/Config.hpp> #include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp> #include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Sequence.hpp> #include <Nazara/Utility/Sequence.hpp>
#include <limits>
namespace Nz namespace Nz
{ {
struct NAZARA_UTILITY_API AnimationParams : ResourceParameters struct NAZARA_UTILITY_API AnimationParams : ResourceParameters
{ {
// La frame de fin à charger // La frame de fin à charger
unsigned int endFrame = std::numeric_limits<unsigned int>::max(); UInt32 endFrame = 0xFFFFFFFF;
// La frame de début à charger // La frame de début à charger
unsigned int startFrame = 0; UInt32 startFrame = 0;
bool IsValid() const; bool IsValid() const;
}; };
@ -57,27 +56,27 @@ namespace Nz
~Animation(); ~Animation();
bool AddSequence(const Sequence& sequence); 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 Destroy();
void EnableLoopPointInterpolation(bool loopPointInterpolation); void EnableLoopPointInterpolation(bool loopPointInterpolation);
unsigned int GetFrameCount() const; UInt32 GetFrameCount() const;
unsigned int GetJointCount() const; UInt32 GetJointCount() const;
Sequence* GetSequence(const String& sequenceName); Sequence* GetSequence(const String& sequenceName);
Sequence* GetSequence(unsigned int index); Sequence* GetSequence(UInt32 index);
const Sequence* GetSequence(const String& sequenceName) const; const Sequence* GetSequence(const String& sequenceName) const;
const Sequence* GetSequence(unsigned int index) const; const Sequence* GetSequence(UInt32 index) const;
unsigned int GetSequenceCount() const; UInt32 GetSequenceCount() const;
int GetSequenceIndex(const String& sequenceName) const; UInt32 GetSequenceIndex(const String& sequenceName) const;
SequenceJoint* GetSequenceJoints(unsigned int frameIndex = 0); SequenceJoint* GetSequenceJoints(UInt32 frameIndex = 0);
const SequenceJoint* GetSequenceJoints(unsigned int frameIndex = 0) const; const SequenceJoint* GetSequenceJoints(UInt32 frameIndex = 0) const;
AnimationType GetType() const; AnimationType GetType() const;
bool HasSequence(const String& sequenceName) const; bool HasSequence(const String& sequenceName) const;
bool HasSequence(unsigned int index = 0) const; bool HasSequence(UInt32 index = 0) const;
bool IsLoopPointInterpolationEnabled() const; bool IsLoopPointInterpolationEnabled() const;
bool IsValid() const; bool IsValid() const;
@ -87,7 +86,7 @@ namespace Nz
bool LoadFromStream(Stream& stream, const AnimationParams& params = AnimationParams()); bool LoadFromStream(Stream& stream, const AnimationParams& params = AnimationParams());
void RemoveSequence(const String& sequenceName); void RemoveSequence(const String& sequenceName);
void RemoveSequence(unsigned int index); void RemoveSequence(UInt32 index);
template<typename... Args> static AnimationRef New(Args&&... args); template<typename... Args> static AnimationRef New(Args&&... args);

View File

@ -34,12 +34,12 @@ namespace Nz
struct Joint struct Joint
{ {
Int32 parent;
Quaternionf bindOrient; Quaternionf bindOrient;
String name; String name;
Vector3f bindPos; Vector3f bindPos;
int parent; UInt32 flags;
unsigned int flags; UInt32 index;
unsigned int index;
}; };
MD5AnimParser(Stream& stream); MD5AnimParser(Stream& stream);
@ -47,12 +47,12 @@ namespace Nz
Ternary Check(); Ternary Check();
std::size_t GetAnimatedComponentCount() const; UInt32 GetAnimatedComponentCount() const;
const Frame* GetFrames() const; const Frame* GetFrames() const;
std::size_t GetFrameCount() const; UInt32 GetFrameCount() const;
std::size_t GetFrameRate() const; UInt32 GetFrameRate() const;
const Joint* GetJoints() const; const Joint* GetJoints() const;
std::size_t GetJointCount() const; UInt32 GetJointCount() const;
bool Parse(); bool Parse();

View File

@ -22,10 +22,10 @@ namespace Nz
public: public:
struct Joint struct Joint
{ {
Int32 parent;
Quaternionf bindOrient; Quaternionf bindOrient;
String name; String name;
Vector3f bindPos; Vector3f bindPos;
int parent;
}; };
typedef Vector3ui Triangle; typedef Vector3ui Triangle;
@ -58,9 +58,9 @@ namespace Nz
Ternary Check(); Ternary Check();
const Joint* GetJoints() const; const Joint* GetJoints() const;
std::size_t GetJointCount() const; UInt32 GetJointCount() const;
const Mesh* GetMeshes() const; const Mesh* GetMeshes() const;
std::size_t GetMeshCount() const; UInt32 GetMeshCount() const;
bool Parse(); bool Parse();

View File

@ -31,43 +31,43 @@ namespace Nz
inline String* GetMaterials(); inline String* GetMaterials();
inline const String* GetMaterials() const; inline const String* GetMaterials() const;
inline unsigned int GetMaterialCount() const; inline UInt32 GetMaterialCount() const;
inline Mesh* GetMeshes(); inline Mesh* GetMeshes();
inline const Mesh* GetMeshes() const; inline const Mesh* GetMeshes() const;
inline unsigned int GetMeshCount() const; inline UInt32 GetMeshCount() const;
inline const String& GetMtlLib() const; inline const String& GetMtlLib() const;
inline Vector3f* GetNormals(); inline Vector3f* GetNormals();
inline const Vector3f* GetNormals() const; inline const Vector3f* GetNormals() const;
inline unsigned int GetNormalCount() const; inline UInt32 GetNormalCount() const;
inline Vector4f* GetPositions(); inline Vector4f* GetPositions();
inline const Vector4f* GetPositions() const; inline const Vector4f* GetPositions() const;
inline unsigned int GetPositionCount() const; inline UInt32 GetPositionCount() const;
inline Vector3f* GetTexCoords(); inline Vector3f* GetTexCoords();
inline const Vector3f* GetTexCoords() const; 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; bool Save(Stream& stream) const;
inline String* SetMaterialCount(std::size_t materialCount); inline String* SetMaterialCount(UInt32 materialCount);
inline Mesh* SetMeshCount(std::size_t meshCount); inline Mesh* SetMeshCount(UInt32 meshCount);
inline void SetMtlLib(const String& mtlLib); inline void SetMtlLib(const String& mtlLib);
inline Vector3f* SetNormalCount(std::size_t normalCount); inline Vector3f* SetNormalCount(UInt32 normalCount);
inline Vector4f* SetPositionCount(std::size_t positionCount); inline Vector4f* SetPositionCount(UInt32 positionCount);
inline Vector3f* SetTexCoordCount(std::size_t texCoordCount); inline Vector3f* SetTexCoordCount(UInt32 texCoordCount);
struct Face struct Face
{ {
std::size_t firstVertex; UInt32 firstVertex;
std::size_t vertexCount; UInt32 vertexCount;
}; };
struct FaceVertex struct FaceVertex
{ {
std::size_t normal; UInt32 normal;
std::size_t position; UInt32 position;
std::size_t texCoord; UInt32 texCoord;
}; };
struct Mesh struct Mesh
@ -75,7 +75,7 @@ namespace Nz
std::vector<Face> faces; std::vector<Face> faces;
std::vector<FaceVertex> vertices; std::vector<FaceVertex> vertices;
String name; String name;
std::size_t material; UInt32 material;
}; };
private: private:

View File

@ -27,9 +27,9 @@ namespace Nz
return m_materials.data(); return m_materials.data();
} }
inline unsigned int OBJParser::GetMaterialCount() const inline UInt32 OBJParser::GetMaterialCount() const
{ {
return m_materials.size(); return static_cast<UInt32>(m_materials.size());
} }
inline OBJParser::Mesh* OBJParser::GetMeshes() inline OBJParser::Mesh* OBJParser::GetMeshes()
@ -42,9 +42,9 @@ namespace Nz
return m_meshes.data(); return m_meshes.data();
} }
inline unsigned int OBJParser::GetMeshCount() const inline UInt32 OBJParser::GetMeshCount() const
{ {
return m_meshes.size(); return static_cast<UInt32>(m_meshes.size());
} }
inline const String& OBJParser::GetMtlLib() const inline const String& OBJParser::GetMtlLib() const
@ -62,9 +62,9 @@ namespace Nz
return m_normals.data(); return m_normals.data();
} }
inline unsigned int OBJParser::GetNormalCount() const inline UInt32 OBJParser::GetNormalCount() const
{ {
return m_normals.size(); return static_cast<UInt32>(m_normals.size());
} }
inline Vector4f* OBJParser::GetPositions() inline Vector4f* OBJParser::GetPositions()
@ -77,9 +77,9 @@ namespace Nz
return m_positions.data(); return m_positions.data();
} }
inline unsigned int OBJParser::GetPositionCount() const inline UInt32 OBJParser::GetPositionCount() const
{ {
return m_positions.size(); return static_cast<UInt32>(m_positions.size());
} }
inline Vector3f* OBJParser::GetTexCoords() inline Vector3f* OBJParser::GetTexCoords()
@ -92,18 +92,18 @@ namespace Nz
return m_texCoords.data(); return m_texCoords.data();
} }
inline unsigned int OBJParser::GetTexCoordCount() const inline UInt32 OBJParser::GetTexCoordCount() const
{ {
return m_texCoords.size(); return static_cast<UInt32>(m_texCoords.size());
} }
inline String* OBJParser::SetMaterialCount(std::size_t materialCount) inline String* OBJParser::SetMaterialCount(UInt32 materialCount)
{ {
m_materials.resize(materialCount); m_materials.resize(materialCount);
return m_materials.data(); return m_materials.data();
} }
inline OBJParser::Mesh* OBJParser::SetMeshCount(std::size_t meshCount) inline OBJParser::Mesh* OBJParser::SetMeshCount(UInt32 meshCount)
{ {
m_meshes.resize(meshCount); m_meshes.resize(meshCount);
return m_meshes.data(); return m_meshes.data();
@ -114,19 +114,19 @@ namespace Nz
m_mtlLib = mtlLib; m_mtlLib = mtlLib;
} }
inline Vector3f* OBJParser::SetNormalCount(std::size_t normalCount) inline Vector3f* OBJParser::SetNormalCount(UInt32 normalCount)
{ {
m_normals.resize(normalCount); m_normals.resize(normalCount);
return m_normals.data(); return m_normals.data();
} }
inline Vector4f* OBJParser::SetPositionCount(std::size_t positionCount) inline Vector4f* OBJParser::SetPositionCount(UInt32 positionCount)
{ {
m_positions.resize(positionCount); m_positions.resize(positionCount);
return m_positions.data(); return m_positions.data();
} }
inline Vector3f* OBJParser::SetTexCoordCount(std::size_t texCoordCount) inline Vector3f* OBJParser::SetTexCoordCount(UInt32 texCoordCount)
{ {
m_texCoords.resize(texCoordCount); m_texCoords.resize(texCoordCount);
return m_texCoords.data(); return m_texCoords.data();

View File

@ -84,7 +84,7 @@ namespace Nz
SubMesh* BuildSubMesh(const Primitive& primitive, const MeshParams& params = MeshParams()); SubMesh* BuildSubMesh(const Primitive& primitive, const MeshParams& params = MeshParams());
void BuildSubMeshes(const PrimitiveList& list, const MeshParams& params = MeshParams()); void BuildSubMeshes(const PrimitiveList& list, const MeshParams& params = MeshParams());
bool CreateSkeletal(unsigned int jointCount); bool CreateSkeletal(UInt32 jointCount);
bool CreateStatic(); bool CreateStatic();
void Destroy(); void Destroy();
@ -95,23 +95,23 @@ namespace Nz
const Boxf& GetAABB() const; const Boxf& GetAABB() const;
String GetAnimation() const; String GetAnimation() const;
AnimationType GetAnimationType() const; AnimationType GetAnimationType() const;
unsigned int GetJointCount() const; UInt32 GetJointCount() const;
ParameterList& GetMaterialData(unsigned int index); ParameterList& GetMaterialData(UInt32 index);
const ParameterList& GetMaterialData(unsigned int index) const; const ParameterList& GetMaterialData(UInt32 index) const;
unsigned int GetMaterialCount() const; UInt32 GetMaterialCount() const;
Skeleton* GetSkeleton(); Skeleton* GetSkeleton();
const Skeleton* GetSkeleton() const; const Skeleton* GetSkeleton() const;
SubMesh* GetSubMesh(const String& identifier); SubMesh* GetSubMesh(const String& identifier);
SubMesh* GetSubMesh(unsigned int index); SubMesh* GetSubMesh(UInt32 index);
const SubMesh* GetSubMesh(const String& identifier) const; const SubMesh* GetSubMesh(const String& identifier) const;
const SubMesh* GetSubMesh(unsigned int index) const; const SubMesh* GetSubMesh(UInt32 index) const;
unsigned int GetSubMeshCount() const; UInt32 GetSubMeshCount() const;
int GetSubMeshIndex(const String& identifier) const; UInt32 GetSubMeshIndex(const String& identifier) const;
unsigned int GetTriangleCount() const; UInt32 GetTriangleCount() const;
unsigned int GetVertexCount() const; UInt32 GetVertexCount() const;
bool HasSubMesh(const String& identifier) const; bool HasSubMesh(const String& identifier) const;
bool HasSubMesh(unsigned int index = 0) const; bool HasSubMesh(UInt32 index = 0) const;
void InvalidateAABB() const; void InvalidateAABB() const;
@ -125,14 +125,14 @@ namespace Nz
void Recenter(); void Recenter();
void RemoveSubMesh(const String& identifier); void RemoveSubMesh(const String& identifier);
void RemoveSubMesh(unsigned int index); void RemoveSubMesh(UInt32 index);
bool SaveToFile(const String& filePath, const MeshParams& params = MeshParams()); bool SaveToFile(const String& filePath, const MeshParams& params = MeshParams());
bool SaveToStream(Stream& stream, const String& format, const MeshParams& params = MeshParams()); bool SaveToStream(Stream& stream, const String& format, const MeshParams& params = MeshParams());
void SetAnimation(const String& animationPath); void SetAnimation(const String& animationPath);
void SetMaterialCount(unsigned int matCount); void SetMaterialCount(UInt32 matCount);
void SetMaterialData(unsigned int matIndex, ParameterList data); void SetMaterialData(UInt32 matIndex, ParameterList data);
void Transform(const Matrix4f& matrix); void Transform(const Matrix4f& matrix);

View File

@ -16,9 +16,9 @@ namespace Nz
struct Sequence struct Sequence
{ {
String name; String name;
unsigned int firstFrame; UInt32 firstFrame;
unsigned int frameCount; UInt32 frameCount;
unsigned int frameRate; UInt32 frameRate;
}; };
struct SequenceJoint struct SequenceJoint

View File

@ -37,21 +37,21 @@ namespace Nz
Skeleton(const Skeleton& skeleton); Skeleton(const Skeleton& skeleton);
~Skeleton(); ~Skeleton();
bool Create(unsigned int jointCount); bool Create(UInt32 jointCount);
void Destroy(); void Destroy();
const Boxf& GetAABB() const; const Boxf& GetAABB() const;
Joint* GetJoint(const String& jointName); Joint* GetJoint(const String& jointName);
Joint* GetJoint(unsigned int index); Joint* GetJoint(UInt32 index);
const Joint* GetJoint(const String& jointName) const; const Joint* GetJoint(const String& jointName) const;
const Joint* GetJoint(unsigned int index) const; const Joint* GetJoint(UInt32 index) const;
Joint* GetJoints(); Joint* GetJoints();
const Joint* GetJoints() const; const Joint* GetJoints() const;
unsigned int GetJointCount() const; UInt32 GetJointCount() const;
int GetJointIndex(const String& jointName) 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);
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; bool IsValid() const;

View File

@ -39,15 +39,15 @@ namespace Nz
virtual const Boxf& GetAABB() const = 0; virtual const Boxf& GetAABB() const = 0;
virtual AnimationType GetAnimationType() const = 0; virtual AnimationType GetAnimationType() const = 0;
virtual const IndexBuffer* GetIndexBuffer() const = 0; virtual const IndexBuffer* GetIndexBuffer() const = 0;
unsigned int GetMaterialIndex() const; UInt32 GetMaterialIndex() const;
const Mesh* GetParent() const; const Mesh* GetParent() const;
PrimitiveMode GetPrimitiveMode() const; PrimitiveMode GetPrimitiveMode() const;
unsigned int GetTriangleCount() const; UInt32 GetTriangleCount() const;
virtual unsigned int GetVertexCount() const = 0; virtual UInt32 GetVertexCount() const = 0;
virtual bool IsAnimated() const = 0; virtual bool IsAnimated() const = 0;
void SetMaterialIndex(unsigned int matIndex); void SetMaterialIndex(UInt32 matIndex);
void SetPrimitiveMode(PrimitiveMode mode); void SetPrimitiveMode(PrimitiveMode mode);
// Signals: // Signals:
@ -56,7 +56,7 @@ namespace Nz
protected: protected:
PrimitiveMode m_primitiveMode; PrimitiveMode m_primitiveMode;
const Mesh* m_parent; const Mesh* m_parent;
unsigned int m_matIndex; UInt32 m_matIndex;
}; };
} }

View File

@ -28,8 +28,8 @@ namespace Nz
{ {
NazaraError("Attribute 0x" + String::Number(component, 16) + " is not enabled"); NazaraError("Attribute 0x" + String::Number(component, 16) + " is not enabled");
return SparsePtr<T>(); return SparsePtr<T>();
}
} }
} }
}
#include <Nazara/Utility/DebugOff.hpp> #include <Nazara/Utility/DebugOff.hpp>

View File

@ -14,13 +14,13 @@ namespace Nz
{ {
struct AnimationImpl struct AnimationImpl
{ {
std::unordered_map<String, unsigned int> sequenceMap; std::unordered_map<String, UInt32> sequenceMap;
std::vector<Sequence> sequences; std::vector<Sequence> sequences;
std::vector<SequenceJoint> sequenceJoints; // Uniquement pour les animations squelettiques std::vector<SequenceJoint> sequenceJoints; // Uniquement pour les animations squelettiques
AnimationType type; AnimationType type;
bool loopPointInterpolation = false; bool loopPointInterpolation = false;
unsigned int frameCount; UInt32 frameCount;
unsigned int jointCount; // Uniquement pour les animations squelettiques UInt32 jointCount; // Uniquement pour les animations squelettiques
}; };
bool AnimationParams::IsValid() const bool AnimationParams::IsValid() const
@ -43,40 +43,18 @@ namespace Nz
bool Animation::AddSequence(const Sequence& sequence) bool Animation::AddSequence(const Sequence& sequence)
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl) NazaraAssert(sequence.frameCount > 0, "Sequence frame count must be over zero");
{
NazaraError("Animation not created");
return false;
}
if (sequence.frameCount == 0)
{
NazaraError("Sequence frame count must be over zero");
return false;
}
#endif
if (m_impl->type == AnimationType_Skeletal) 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) if (endFrame >= m_impl->frameCount)
{ {
m_impl->frameCount = endFrame+1; m_impl->frameCount = endFrame+1;
m_impl->sequenceJoints.resize(m_impl->frameCount*m_impl->jointCount); 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()) if (!sequence.name.IsEmpty())
{ {
@ -84,12 +62,12 @@ namespace Nz
auto it = m_impl->sequenceMap.find(sequence.name); auto it = m_impl->sequenceMap.find(sequence.name);
if (it != m_impl->sequenceMap.end()) 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; return false;
} }
#endif #endif
m_impl->sequenceMap[sequence.name] = m_impl->sequences.size(); m_impl->sequenceMap[sequence.name] = static_cast<UInt32>(m_impl->sequences.size());
} }
m_impl->sequences.push_back(sequence); m_impl->sequences.push_back(sequence);
@ -97,55 +75,16 @@ namespace Nz
return true; 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 NazaraAssert(m_impl, "Animation not created");
if (!m_impl) NazaraAssert(m_impl->type == AnimationType_Skeletal, "Animation is not skeletal");
{ NazaraAssert(targetSkeleton && targetSkeleton->IsValid(), "Invalid skeleton");
NazaraError("Animation not created"); NazaraAssert(targetSkeleton->GetJointCount() == m_impl->jointCount, "Skeleton joint does not match animation joint count");
return; 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) for (UInt32 i = 0; i < m_impl->jointCount; ++i)
{
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)
{ {
Joint* joint = targetSkeleton->GetJoint(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 Destroy();
if (frameCount == 0)
{
NazaraError("Frame count must be over zero");
return false;
}
#endif
m_impl = new AnimationImpl; m_impl = new AnimationImpl;
m_impl->frameCount = frameCount; m_impl->frameCount = frameCount;
@ -192,255 +126,130 @@ namespace Nz
void Animation::EnableLoopPointInterpolation(bool loopPointInterpolation) void Animation::EnableLoopPointInterpolation(bool loopPointInterpolation)
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl)
{
NazaraError("Animation not created");
return;
}
#endif
m_impl->loopPointInterpolation = loopPointInterpolation; m_impl->loopPointInterpolation = loopPointInterpolation;
} }
unsigned int Animation::GetFrameCount() const UInt32 Animation::GetFrameCount() const
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
return m_impl->frameCount; return m_impl->frameCount;
} }
unsigned int Animation::GetJointCount() const UInt32 Animation::GetJointCount() const
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl)
{
NazaraError("Animation not created");
return 0;
}
if (m_impl->type != AnimationType_Skeletal)
{
NazaraError("Animation is not skeletal");
return 0;
}
#endif
return m_impl->jointCount; return m_impl->jointCount;
} }
Sequence* Animation::GetSequence(const String& sequenceName) Sequence* Animation::GetSequence(const String& sequenceName)
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
#endif
auto it = m_impl->sequenceMap.find(sequenceName); auto it = m_impl->sequenceMap.find(sequenceName);
#if NAZARA_UTILITY_SAFE
if (it == m_impl->sequenceMap.end()) if (it == m_impl->sequenceMap.end())
{ {
NazaraError("Sequence not found"); NazaraError("Sequence not found");
return nullptr; return nullptr;
} }
#endif
return &m_impl->sequences[it->second]; return &m_impl->sequences[it->second];
} }
Sequence* Animation::GetSequence(unsigned int index) Sequence* Animation::GetSequence(UInt32 index)
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl) NazaraAssert(index < m_impl->sequences.size(), "Sequence index out of range");
{
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
return &m_impl->sequences[index]; return &m_impl->sequences[index];
} }
const Sequence* Animation::GetSequence(const String& sequenceName) const const Sequence* Animation::GetSequence(const String& sequenceName) const
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
#endif
auto it = m_impl->sequenceMap.find(sequenceName); auto it = m_impl->sequenceMap.find(sequenceName);
#if NAZARA_UTILITY_SAFE
if (it == m_impl->sequenceMap.end()) if (it == m_impl->sequenceMap.end())
{ {
NazaraError("Sequence not found"); NazaraError("Sequence not found");
return nullptr; return nullptr;
} }
#endif
return &m_impl->sequences[it->second]; 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 NazaraAssert(m_impl, "Animation not created");
if (!m_impl) NazaraAssert(index < m_impl->sequences.size(), "Sequence index out of range");
{
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
return &m_impl->sequences[index]; return &m_impl->sequences[index];
} }
unsigned int Animation::GetSequenceCount() const UInt32 Animation::GetSequenceCount() const
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl)
{
NazaraError("Animation not created");
return 0;
}
#endif
return m_impl->sequences.size(); return static_cast<UInt32>(m_impl->sequences.size());
} }
int Animation::GetSequenceIndex(const String& sequenceName) const UInt32 Animation::GetSequenceIndex(const String& sequenceName) const
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl)
{
NazaraError("Animation not created");
return -1;
}
#endif
auto it = m_impl->sequenceMap.find(sequenceName); auto it = m_impl->sequenceMap.find(sequenceName);
#if NAZARA_UTILITY_SAFE
if (it == m_impl->sequenceMap.end()) if (it == m_impl->sequenceMap.end())
{ {
NazaraError("Sequence not found"); NazaraError("Sequence not found");
return -1; return 0xFFFFFFFF;
} }
#endif
return it->second; return it->second;
} }
SequenceJoint* Animation::GetSequenceJoints(unsigned int frameIndex) SequenceJoint* Animation::GetSequenceJoints(UInt32 frameIndex)
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl) NazaraAssert(m_impl->type == AnimationType_Skeletal, "Animation is not skeletal");
{
NazaraError("Animation not created");
return nullptr;
}
if (m_impl->type != AnimationType_Skeletal)
{
NazaraError("Animation is not skeletal");
return nullptr;
}
#endif
return &m_impl->sequenceJoints[frameIndex*m_impl->jointCount]; 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 NazaraAssert(m_impl, "Animation not created");
if (!m_impl) NazaraAssert(m_impl->type == AnimationType_Skeletal, "Animation is not skeletal");
{
NazaraError("Animation not created");
return nullptr;
}
if (m_impl->type != AnimationType_Skeletal)
{
NazaraError("Animation is not skeletal");
return nullptr;
}
#endif
return &m_impl->sequenceJoints[frameIndex*m_impl->jointCount]; return &m_impl->sequenceJoints[frameIndex*m_impl->jointCount];
} }
AnimationType Animation::GetType() const AnimationType Animation::GetType() const
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl)
{
NazaraError("Animation not created");
return AnimationType_Static; // Ce qui est une valeur invalide pour Animation
}
#endif
return m_impl->type; return m_impl->type;
} }
bool Animation::HasSequence(const String& sequenceName) const bool Animation::HasSequence(const String& sequenceName) const
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
return m_impl->sequenceMap.find(sequenceName) != m_impl->sequenceMap.end(); 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 NazaraAssert(m_impl, "Animation not created");
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
return index >= m_impl->sequences.size(); return index >= m_impl->sequences.size();
} }
bool Animation::IsLoopPointInterpolationEnabled() const bool Animation::IsLoopPointInterpolationEnabled() const
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
return m_impl->loopPointInterpolation; return m_impl->loopPointInterpolation;
} }
@ -467,12 +276,7 @@ namespace Nz
void Animation::RemoveSequence(const String& identifier) void Animation::RemoveSequence(const String& identifier)
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl)
{
NazaraError("Animation not created");
return;
}
auto it = m_impl->sequenceMap.find(identifier); auto it = m_impl->sequenceMap.find(identifier);
if (it == m_impl->sequenceMap.end()) if (it == m_impl->sequenceMap.end())
@ -481,32 +285,16 @@ namespace Nz
return; return;
} }
int index = it->second; auto sequenceIt = m_impl->sequences.begin();
#else std::advance(sequenceIt, it->second);
int index = m_impl->sequenceMap[identifier];
#endif
auto it2 = m_impl->sequences.begin(); m_impl->sequences.erase(sequenceIt);
std::advance(it2, index);
m_impl->sequences.erase(it2);
} }
void Animation::RemoveSequence(unsigned int index) void Animation::RemoveSequence(UInt32 index)
{ {
#if NAZARA_UTILITY_SAFE NazaraAssert(m_impl, "Animation not created");
if (!m_impl) NazaraAssert(index < m_impl->sequences.size(), "Sequence index out of range");
{
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
auto it = m_impl->sequences.begin(); auto it = m_impl->sequences.begin();
std::advance(it, index); std::advance(it, index);

View File

@ -37,10 +37,10 @@ namespace Nz
} }
const MD5AnimParser::Frame* frames = parser.GetFrames(); const MD5AnimParser::Frame* frames = parser.GetFrames();
std::size_t frameCount = parser.GetFrameCount(); UInt32 frameCount = parser.GetFrameCount();
std::size_t frameRate = parser.GetFrameRate(); UInt32 frameRate = parser.GetFrameRate();
const MD5AnimParser::Joint* joints = parser.GetJoints(); 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 // À ce stade, nous sommes censés avoir assez d'informations pour créer l'animation
animation->CreateSkeletal(frameCount, jointCount); 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 // 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 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; 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]; SequenceJoint& sequenceJoint = sequenceJoints[j*jointCount + i];

View File

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

View File

@ -53,15 +53,15 @@ namespace Nz
const MD5MeshParser::Joint* joints = parser.GetJoints(); const MD5MeshParser::Joint* joints = parser.GetJoints();
const MD5MeshParser::Mesh* meshes = parser.GetMeshes(); const MD5MeshParser::Mesh* meshes = parser.GetMeshes();
std::size_t jointCount = parser.GetJointCount(); UInt32 jointCount = parser.GetJointCount();
std::size_t meshCount = parser.GetMeshCount(); UInt32 meshCount = parser.GetMeshCount();
if (parameters.animated) if (parameters.animated)
{ {
mesh->CreateSkeletal(jointCount); mesh->CreateSkeletal(jointCount);
Skeleton* skeleton = mesh->GetSkeleton(); 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); Joint* joint = skeleton->GetJoint(i);
@ -82,7 +82,7 @@ namespace Nz
} }
mesh->SetMaterialCount(meshCount); 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]; 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 // 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 // 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) // (On parle ici de winding)
unsigned int index = 0; UInt32 index = 0;
for (const MD5MeshParser::Triangle& triangle : md5Mesh.triangles) for (const MD5MeshParser::Triangle& triangle : md5Mesh.triangles)
{ {
// On les respécifie dans le bon ordre (inversion du winding) // On les respécifie dans le bon ordre (inversion du winding)
@ -227,7 +227,7 @@ namespace Nz
} }
mesh->SetMaterialCount(meshCount); 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]; const MD5MeshParser::Mesh& md5Mesh = meshes[i];
std::size_t indexCount = md5Mesh.triangles.size()*3; std::size_t indexCount = md5Mesh.triangles.size()*3;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -55,7 +55,7 @@ namespace Nz
materialData.resize(1); // Un matériau par défaut materialData.resize(1); // Un matériau par défaut
} }
std::unordered_map<String, unsigned int> subMeshMap; std::unordered_map<String, UInt32> subMeshMap;
std::vector<ParameterList> materialData; std::vector<ParameterList> materialData;
std::vector<SubMeshRef> subMeshes; std::vector<SubMeshRef> subMeshes;
AnimationType animationType; AnimationType animationType;
@ -63,7 +63,7 @@ namespace Nz
Skeleton skeleton; // Uniquement pour les meshs squelettiques Skeleton skeleton; // Uniquement pour les meshs squelettiques
String animationPath; String animationPath;
bool aabbUpdated = false; bool aabbUpdated = false;
unsigned int jointCount; // Uniquement pour les meshs squelettiques UInt32 jointCount; // Uniquement pour les meshs squelettiques
}; };
Mesh::~Mesh() Mesh::~Mesh()
@ -92,7 +92,7 @@ namespace Nz
NazaraAssert(subMesh, "Invalid submesh"); NazaraAssert(subMesh, "Invalid submesh");
NazaraAssert(subMesh->GetAnimationType() == m_impl->animationType, "Submesh animation type doesn't match mesh animation type"); 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->subMeshes.push_back(subMesh);
m_impl->subMeshMap[identifier] = index; m_impl->subMeshMap[identifier] = index;
@ -276,11 +276,11 @@ namespace Nz
void Mesh::BuildSubMeshes(const PrimitiveList& list, const MeshParams& params) 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); BuildSubMesh(list.GetPrimitive(i), params);
} }
bool Mesh::CreateSkeletal(unsigned int jointCount) bool Mesh::CreateSkeletal(UInt32 jointCount)
{ {
Destroy(); Destroy();
@ -349,11 +349,11 @@ namespace Nz
if (!m_impl->aabbUpdated) if (!m_impl->aabbUpdated)
{ {
unsigned int subMeshCount = m_impl->subMeshes.size(); UInt32 subMeshCount = m_impl->subMeshes.size();
if (subMeshCount > 0) if (subMeshCount > 0)
{ {
m_impl->aabb.Set(m_impl->subMeshes[0]->GetAABB()); 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()); m_impl->aabb.ExtendTo(m_impl->subMeshes[i]->GetAABB());
} }
else else
@ -379,7 +379,7 @@ namespace Nz
return m_impl->animationType; return m_impl->animationType;
} }
unsigned int Mesh::GetJointCount() const UInt32 Mesh::GetJointCount() const
{ {
NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(m_impl, "Mesh should be created first");
NazaraAssert(m_impl->animationType == AnimationType_Skeletal, "Mesh is not skeletal"); NazaraAssert(m_impl->animationType == AnimationType_Skeletal, "Mesh is not skeletal");
@ -387,7 +387,7 @@ namespace Nz
return m_impl->jointCount; return m_impl->jointCount;
} }
ParameterList& Mesh::GetMaterialData(unsigned int index) ParameterList& Mesh::GetMaterialData(UInt32 index)
{ {
NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(m_impl, "Mesh should be created first");
NazaraAssert(index < m_impl->materialData.size(), "Material index out of range"); NazaraAssert(index < m_impl->materialData.size(), "Material index out of range");
@ -395,7 +395,7 @@ namespace Nz
return m_impl->materialData[index]; 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(m_impl, "Mesh should be created first");
NazaraAssert(index < m_impl->materialData.size(), "Material index out of range"); NazaraAssert(index < m_impl->materialData.size(), "Material index out of range");
@ -403,7 +403,7 @@ namespace Nz
return m_impl->materialData[index]; return m_impl->materialData[index];
} }
unsigned int Mesh::GetMaterialCount() const UInt32 Mesh::GetMaterialCount() const
{ {
NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(m_impl, "Mesh should be created first");
@ -436,7 +436,7 @@ namespace Nz
return m_impl->subMeshes[it->second]; 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(m_impl, "Mesh should be created first");
NazaraAssert(index < m_impl->subMeshes.size(), "Submesh index out of range"); NazaraAssert(index < m_impl->subMeshes.size(), "Submesh index out of range");
@ -454,7 +454,7 @@ namespace Nz
return m_impl->subMeshes[it->second]; 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(m_impl, "Mesh should be created first");
NazaraAssert(index < m_impl->subMeshes.size(), "Submesh index out of range"); NazaraAssert(index < m_impl->subMeshes.size(), "Submesh index out of range");
@ -462,14 +462,14 @@ namespace Nz
return m_impl->subMeshes[index]; return m_impl->subMeshes[index];
} }
unsigned int Mesh::GetSubMeshCount() const UInt32 Mesh::GetSubMeshCount() const
{ {
NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(m_impl, "Mesh should be created first");
return m_impl->subMeshes.size(); 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"); NazaraAssert(m_impl, "Mesh should be created first");
@ -479,22 +479,22 @@ namespace Nz
return it->second; return it->second;
} }
unsigned int Mesh::GetTriangleCount() const UInt32 Mesh::GetTriangleCount() const
{ {
NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(m_impl, "Mesh should be created first");
unsigned int triangleCount = 0; UInt32 triangleCount = 0;
for (SubMesh* subMesh : m_impl->subMeshes) for (SubMesh* subMesh : m_impl->subMeshes)
triangleCount += subMesh->GetTriangleCount(); triangleCount += subMesh->GetTriangleCount();
return triangleCount; return triangleCount;
} }
unsigned int Mesh::GetVertexCount() const UInt32 Mesh::GetVertexCount() const
{ {
NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(m_impl, "Mesh should be created first");
unsigned int vertexCount = 0; UInt32 vertexCount = 0;
for (SubMesh* subMesh : m_impl->subMeshes) for (SubMesh* subMesh : m_impl->subMeshes)
vertexCount += subMesh->GetVertexCount(); vertexCount += subMesh->GetVertexCount();
@ -515,7 +515,7 @@ namespace Nz
return m_impl->subMeshMap.find(identifier) != m_impl->subMeshMap.end(); 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"); NazaraAssert(m_impl, "Mesh should be created first");
@ -564,8 +564,8 @@ namespace Nz
BufferMapper<VertexBuffer> mapper(staticMesh->GetVertexBuffer(), BufferAccess_ReadWrite); BufferMapper<VertexBuffer> mapper(staticMesh->GetVertexBuffer(), BufferAccess_ReadWrite);
MeshVertex* vertices = static_cast<MeshVertex*>(mapper.GetPointer()); MeshVertex* vertices = static_cast<MeshVertex*>(mapper.GetPointer());
unsigned int vertexCount = staticMesh->GetVertexCount(); UInt32 vertexCount = staticMesh->GetVertexCount();
for (unsigned int i = 0; i < vertexCount; ++i) for (UInt32 i = 0; i < vertexCount; ++i)
{ {
vertices->position -= center; vertices->position -= center;
vertices++; vertices++;
@ -583,7 +583,7 @@ namespace Nz
void Mesh::RemoveSubMesh(const String& identifier) 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 // On déplace l'itérateur du début d'une distance de x
auto it2 = m_impl->subMeshes.begin(); auto it2 = m_impl->subMeshes.begin();
@ -593,7 +593,7 @@ namespace Nz
InvalidateAABB(); InvalidateAABB();
} }
void Mesh::RemoveSubMesh(unsigned int index) void Mesh::RemoveSubMesh(UInt32 index)
{ {
NazaraAssert(m_impl, "Mesh should be created first"); NazaraAssert(m_impl, "Mesh should be created first");
NazaraAssert(index < m_impl->subMeshes.size(), "Submesh index out of range"); NazaraAssert(index < m_impl->subMeshes.size(), "Submesh index out of range");
@ -623,7 +623,7 @@ namespace Nz
m_impl->animationPath = animationPath; 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(m_impl, "Mesh should be created first");
NazaraAssert(matIndex < m_impl->materialData.size(), "Material index out of range"); NazaraAssert(matIndex < m_impl->materialData.size(), "Material index out of range");
@ -631,7 +631,7 @@ namespace Nz
m_impl->materialData[matIndex] = std::move(data); 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(m_impl, "Mesh should be created first");
NazaraAssert(matCount > 0, "A mesh should have at least a material"); NazaraAssert(matCount > 0, "A mesh should have at least a material");
@ -641,7 +641,7 @@ namespace Nz
#ifdef NAZARA_DEBUG #ifdef NAZARA_DEBUG
for (SubMesh* subMesh : m_impl->subMeshes) for (SubMesh* subMesh : m_impl->subMeshes)
{ {
unsigned int matIndex = subMesh->GetMaterialIndex(); UInt32 matIndex = subMesh->GetMaterialIndex();
if (matIndex >= matCount) if (matIndex >= matCount)
{ {
subMesh->SetMaterialIndex(0); // To prevent a crash 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); Boxf aabb(vertices->position.x, vertices->position.y, vertices->position.z, 0.f, 0.f, 0.f);
unsigned int vertexCount = staticMesh->GetVertexCount(); UInt32 vertexCount = staticMesh->GetVertexCount();
for (unsigned int i = 0; i < vertexCount; ++i) for (UInt32 i = 0; i < vertexCount; ++i)
{ {
vertices->position = matrix.Transform(vertices->position); vertices->position = matrix.Transform(vertices->position);
aabb.ExtendTo(vertices->position); aabb.ExtendTo(vertices->position);

View File

@ -10,7 +10,7 @@ namespace Nz
{ {
struct SkeletonImpl struct SkeletonImpl
{ {
std::unordered_map<String, unsigned int> jointMap; std::unordered_map<String, UInt32> jointMap;
std::vector<Joint> joints; std::vector<Joint> joints;
Boxf aabb; Boxf aabb;
bool aabbUpdated = false; bool aabbUpdated = false;
@ -31,7 +31,7 @@ namespace Nz
Destroy(); Destroy();
} }
bool Skeleton::Create(unsigned int jointCount) bool Skeleton::Create(UInt32 jointCount)
{ {
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
if (jointCount == 0) if (jointCount == 0)
@ -72,12 +72,12 @@ namespace Nz
if (!m_impl->aabbUpdated) if (!m_impl->aabbUpdated)
{ {
unsigned int jointCount = m_impl->joints.size(); UInt32 jointCount = m_impl->joints.size();
if (jointCount > 0) if (jointCount > 0)
{ {
Vector3f pos = m_impl->joints[0].GetPosition(); Vector3f pos = m_impl->joints[0].GetPosition();
m_impl->aabb.Set(pos.x, pos.y, pos.z, 0.f, 0.f, 0.f); 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()); m_impl->aabb.ExtendTo(m_impl->joints[i].GetPosition());
} }
else else
@ -117,7 +117,7 @@ namespace Nz
return &m_impl->joints[it->second]; return &m_impl->joints[it->second];
} }
Joint* Skeleton::GetJoint(unsigned int index) Joint* Skeleton::GetJoint(UInt32 index)
{ {
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
if (!m_impl) if (!m_impl)
@ -164,7 +164,7 @@ namespace Nz
return &m_impl->joints[it->second]; 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 NAZARA_UTILITY_SAFE
if (!m_impl) if (!m_impl)
@ -209,7 +209,7 @@ namespace Nz
return &m_impl->joints[0]; return &m_impl->joints[0];
} }
unsigned int Skeleton::GetJointCount() const UInt32 Skeleton::GetJointCount() const
{ {
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
if (!m_impl) if (!m_impl)
@ -278,13 +278,13 @@ namespace Nz
Joint* jointsA = &skeletonA.m_impl->joints[0]; Joint* jointsA = &skeletonA.m_impl->joints[0];
Joint* jointsB = &skeletonB.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); m_impl->joints[i].Interpolate(jointsA[i], jointsB[i], interpolation, CoordSys_Local);
InvalidateJoints(); 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 NAZARA_UTILITY_SAFE
if (!m_impl) if (!m_impl)
@ -314,9 +314,9 @@ namespace Nz
const Joint* jointsA = &skeletonA.m_impl->joints[0]; const Joint* jointsA = &skeletonA.m_impl->joints[0];
const Joint* jointsB = &skeletonB.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 NAZARA_UTILITY_SAFE
if (index >= m_impl->joints.size()) if (index >= m_impl->joints.size())
@ -351,16 +351,16 @@ namespace Nz
m_impl->jointMapUpdated = skeleton.m_impl->jointMapUpdated; m_impl->jointMapUpdated = skeleton.m_impl->jointMapUpdated;
m_impl->joints = skeleton.m_impl->joints; 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 // Ce qui, pour juste une copie qui ne se fera que rarement, ne vaut pas le coup
// L'éternel trade-off mémoire/calculs .. // L'éternel trade-off mémoire/calculs ..
unsigned int jointCount = skeleton.m_impl->joints.size(); std::size_t jointCount = skeleton.m_impl->joints.size();
for (unsigned int i = 0; i < jointCount; ++i) for (std::size_t i = 0; i < jointCount; ++i)
{ {
const Node* parent = skeleton.m_impl->joints[i].GetParent(); const Node* parent = skeleton.m_impl->joints[i].GetParent();
if (parent) 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 ? if (parent == &skeleton.m_impl->joints[j]) // A-t-on trouvé le parent ?
{ {
@ -406,7 +406,7 @@ namespace Nz
#endif #endif
m_impl->jointMap.clear(); 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(); String name = m_impl->joints[i].GetName();
if (!name.IsEmpty()) if (!name.IsEmpty())

View File

@ -196,7 +196,7 @@ namespace Nz
return 0; return 0;
} }
unsigned int SubMesh::GetMaterialIndex() const UInt32 SubMesh::GetMaterialIndex() const
{ {
return m_matIndex; return m_matIndex;
} }
@ -206,7 +206,7 @@ namespace Nz
m_primitiveMode = mode; m_primitiveMode = mode;
} }
void SubMesh::SetMaterialIndex(unsigned int matIndex) void SubMesh::SetMaterialIndex(UInt32 matIndex)
{ {
m_matIndex = matIndex; m_matIndex = matIndex;
} }