Переглянути джерело

Skeleton: use signed type

1vanK 3 роки тому
батько
коміт
ee9f425c74

+ 16 - 16
Source/Urho3D/AngelScript/Generated_Members.h

@@ -621,8 +621,8 @@ template <class T> void RegisterMembers_Bone(asIScriptEngine* engine, const char
     // StringHash Bone::nameHash_
     engine->RegisterObjectProperty(className, "StringHash nameHash", offsetof(T, nameHash_));
 
-    // unsigned Bone::parentIndex_
-    engine->RegisterObjectProperty(className, "uint parentIndex", offsetof(T, parentIndex_));
+    // i32 Bone::parentIndex_
+    engine->RegisterObjectProperty(className, "int parentIndex", offsetof(T, parentIndex_));
 
     // Vector3 Bone::initialPosition_
     engine->RegisterObjectProperty(className, "Vector3 initialPosition", offsetof(T, initialPosition_));
@@ -4590,9 +4590,9 @@ template <class T> void RegisterMembers_Skeleton(asIScriptEngine* engine, const
     // void Skeleton::Define(const Skeleton& src)
     engine->RegisterObjectMethod(className, "void Define(const Skeleton&in)", AS_METHODPR(T, Define, (const Skeleton&), void), AS_CALL_THISCALL);
 
-    // Bone* Skeleton::GetBone(unsigned index)
-    engine->RegisterObjectMethod(className, "Bone@ GetBone(uint)", AS_METHODPR(T, GetBone, (unsigned), Bone*), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "Bone@ get_bones(uint)", AS_METHODPR(T, GetBone, (unsigned), Bone*), AS_CALL_THISCALL);
+    // Bone* Skeleton::GetBone(i32 index)
+    engine->RegisterObjectMethod(className, "Bone@ GetBone(int)", AS_METHODPR(T, GetBone, (i32), Bone*), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "Bone@ get_bones(int)", AS_METHODPR(T, GetBone, (i32), Bone*), AS_CALL_THISCALL);
 
     // Bone* Skeleton::GetBone(const String& name)
     engine->RegisterObjectMethod(className, "Bone@ GetBone(const String&in)", AS_METHODPR(T, GetBone, (const String&), Bone*), AS_CALL_THISCALL);
@@ -4600,21 +4600,21 @@ template <class T> void RegisterMembers_Skeleton(asIScriptEngine* engine, const
     // Bone* Skeleton::GetBone(const StringHash& boneNameHash)
     engine->RegisterObjectMethod(className, "Bone@ GetBone(const StringHash&in)", AS_METHODPR(T, GetBone, (const StringHash&), Bone*), AS_CALL_THISCALL);
 
-    // unsigned Skeleton::GetBoneIndex(const String& boneName) const
-    engine->RegisterObjectMethod(className, "uint GetBoneIndex(const String&in) const", AS_METHODPR(T, GetBoneIndex, (const String&) const, unsigned), AS_CALL_THISCALL);
+    // i32 Skeleton::GetBoneIndex(const String& boneName) const
+    engine->RegisterObjectMethod(className, "int GetBoneIndex(const String&in) const", AS_METHODPR(T, GetBoneIndex, (const String&) const, i32), AS_CALL_THISCALL);
 
-    // unsigned Skeleton::GetBoneIndex(const StringHash& boneNameHash) const
-    engine->RegisterObjectMethod(className, "uint GetBoneIndex(const StringHash&in) const", AS_METHODPR(T, GetBoneIndex, (const StringHash&) const, unsigned), AS_CALL_THISCALL);
+    // i32 Skeleton::GetBoneIndex(const StringHash& boneNameHash) const
+    engine->RegisterObjectMethod(className, "int GetBoneIndex(const StringHash&in) const", AS_METHODPR(T, GetBoneIndex, (const StringHash&) const, i32), AS_CALL_THISCALL);
 
-    // unsigned Skeleton::GetBoneIndex(const Bone* bone) const
-    engine->RegisterObjectMethod(className, "uint GetBoneIndex(Bone@) const", AS_METHODPR(T, GetBoneIndex, (const Bone*) const, unsigned), AS_CALL_THISCALL);
+    // i32 Skeleton::GetBoneIndex(const Bone* bone) const
+    engine->RegisterObjectMethod(className, "int GetBoneIndex(Bone@) const", AS_METHODPR(T, GetBoneIndex, (const Bone*) const, i32), AS_CALL_THISCALL);
 
     // Bone* Skeleton::GetBoneParent(const Bone* bone)
     engine->RegisterObjectMethod(className, "Bone@ GetBoneParent(Bone@)", AS_METHODPR(T, GetBoneParent, (const Bone*), Bone*), AS_CALL_THISCALL);
 
-    // unsigned Skeleton::GetNumBones() const
-    engine->RegisterObjectMethod(className, "uint GetNumBones() const", AS_METHODPR(T, GetNumBones, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_numBones() const", AS_METHODPR(T, GetNumBones, () const, unsigned), AS_CALL_THISCALL);
+    // i32 Skeleton::GetNumBones() const
+    engine->RegisterObjectMethod(className, "int GetNumBones() const", AS_METHODPR(T, GetNumBones, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_numBones() const", AS_METHODPR(T, GetNumBones, () const, i32), AS_CALL_THISCALL);
 
     // Bone* Skeleton::GetRootBone()
     engine->RegisterObjectMethod(className, "Bone@ GetRootBone()", AS_METHODPR(T, GetRootBone, (), Bone*), AS_CALL_THISCALL);
@@ -4632,8 +4632,8 @@ template <class T> void RegisterMembers_Skeleton(asIScriptEngine* engine, const
     // bool Skeleton::Save(Serializer& dest) const
     engine->RegisterObjectMethod(className, "bool Save(Serializer&) const", AS_METHODPR(T, Save, (Serializer&) const, bool), AS_CALL_THISCALL);
 
-    // void Skeleton::SetRootBoneIndex(unsigned index)
-    engine->RegisterObjectMethod(className, "void SetRootBoneIndex(uint)", AS_METHODPR(T, SetRootBoneIndex, (unsigned), void), AS_CALL_THISCALL);
+    // void Skeleton::SetRootBoneIndex(i32 index)
+    engine->RegisterObjectMethod(className, "void SetRootBoneIndex(int)", AS_METHODPR(T, SetRootBoneIndex, (i32), void), AS_CALL_THISCALL);
 
     #ifdef REGISTER_MEMBERS_MANUAL_PART_Skeleton
         REGISTER_MEMBERS_MANUAL_PART_Skeleton();

+ 25 - 22
Source/Urho3D/Graphics/Skeleton.cpp

@@ -12,7 +12,7 @@ namespace Urho3D
 {
 
 Skeleton::Skeleton() :
-    rootBoneIndex_(M_MAX_UNSIGNED)
+    rootBoneIndex_(NINDEX)
 {
 }
 
@@ -25,15 +25,15 @@ bool Skeleton::Load(Deserializer& source)
     if (source.IsEof())
         return false;
 
-    unsigned bones = source.ReadUInt();
+    i32 bones = source.ReadInt();
     bones_.Reserve(bones);
 
-    for (unsigned i = 0; i < bones; ++i)
+    for (i32 i = 0; i < bones; ++i)
     {
         Bone newBone;
         newBone.name_ = source.ReadString();
         newBone.nameHash_ = newBone.name_;
-        newBone.parentIndex_ = source.ReadUInt();
+        newBone.parentIndex_ = source.ReadInt();
         newBone.initialPosition_ = source.ReadVector3();
         newBone.initialRotation_ = source.ReadQuaternion();
         newBone.initialScale_ = source.ReadVector3();
@@ -57,14 +57,14 @@ bool Skeleton::Load(Deserializer& source)
 
 bool Skeleton::Save(Serializer& dest) const
 {
-    if (!dest.WriteUInt(bones_.Size()))
+    if (!dest.WriteInt(bones_.Size()))
         return false;
 
-    for (unsigned i = 0; i < bones_.Size(); ++i)
+    for (i32 i = 0; i < bones_.Size(); ++i)
     {
         const Bone& bone = bones_[i];
         dest.WriteString(bone.name_);
-        dest.WriteUInt(bone.parentIndex_);
+        dest.WriteInt(bone.parentIndex_);
         dest.WriteVector3(bone.initialPosition_);
         dest.WriteQuaternion(bone.initialRotation_);
         dest.WriteVector3(bone.initialScale_);
@@ -93,9 +93,11 @@ void Skeleton::Define(const Skeleton& src)
     rootBoneIndex_ = src.rootBoneIndex_;
 }
 
-void Skeleton::SetRootBoneIndex(unsigned index)
+void Skeleton::SetRootBoneIndex(i32 index)
 {
-    if (index < bones_.Size())
+    assert(index >= 0);
+
+    if (index >= 0 && index < bones_.Size())
         rootBoneIndex_ = index;
     else
         URHO3D_LOGERROR("Root bone index out of bounds");
@@ -104,7 +106,7 @@ void Skeleton::SetRootBoneIndex(unsigned index)
 void Skeleton::ClearBones()
 {
     bones_.Clear();
-    rootBoneIndex_ = M_MAX_UNSIGNED;
+    rootBoneIndex_ = NINDEX;
 }
 
 void Skeleton::Reset()
@@ -131,27 +133,27 @@ Bone* Skeleton::GetRootBone()
     return GetBone(rootBoneIndex_);
 }
 
-unsigned Skeleton::GetBoneIndex(const StringHash& boneNameHash) const
+i32 Skeleton::GetBoneIndex(const StringHash& boneNameHash) const
 {
-    const unsigned numBones = bones_.Size();
-    for (unsigned i = 0; i < numBones; ++i)
+    const i32 numBones = bones_.Size();
+    for (i32 i = 0; i < bones_.Size(); ++i)
     {
         if (bones_[i].nameHash_ == boneNameHash)
             return i;
     }
 
-    return M_MAX_UNSIGNED;
+    return NINDEX;
 }
 
-unsigned Skeleton::GetBoneIndex(const Bone* bone) const
+i32 Skeleton::GetBoneIndex(const Bone* bone) const
 {
     if (bones_.Empty() || bone < &bones_.Front() || bone > &bones_.Back())
-        return M_MAX_UNSIGNED;
+        return NINDEX;
 
-    return static_cast<unsigned>(bone - &bones_.Front());
+    return static_cast<i32>(bone - &bones_.Front());
 }
 
-unsigned Skeleton::GetBoneIndex(const String& boneName) const
+i32 Skeleton::GetBoneIndex(const String& boneName) const
 {
     return GetBoneIndex(StringHash(boneName));
 }
@@ -164,9 +166,10 @@ Bone* Skeleton::GetBoneParent(const Bone* bone)
         return GetBone(bone->parentIndex_);
 }
 
-Bone* Skeleton::GetBone(unsigned index)
+Bone* Skeleton::GetBone(i32 index)
 {
-    return index < bones_.Size() ? &bones_[index] : nullptr;
+    assert(index >= 0 || index == NINDEX);
+    return (index >= 0 && index < bones_.Size()) ? &bones_[index] : nullptr;
 }
 
 Bone* Skeleton::GetBone(const String& name)
@@ -181,8 +184,8 @@ Bone* Skeleton::GetBone(const char* name)
 
 Bone* Skeleton::GetBone(const StringHash& boneNameHash)
 {
-    const unsigned index = GetBoneIndex(boneNameHash);
-    return index < bones_.Size() ? &bones_[index] : nullptr;
+    const i32 index = GetBoneIndex(boneNameHash);
+    return (index >= 0 && index < bones_.Size()) ? &bones_[index] : nullptr;
 }
 
 }

+ 11 - 11
Source/Urho3D/Graphics/Skeleton.h

@@ -43,7 +43,7 @@ struct Bone
     /// Bone name hash.
     StringHash nameHash_;
     /// Parent bone index.
-    unsigned parentIndex_;
+    i32 parentIndex_;
     /// Reset position.
     Vector3 initialPosition_;
     /// Reset rotation.
@@ -81,7 +81,7 @@ public:
     /// Define from another skeleton.
     void Define(const Skeleton& src);
     /// Set root bone's index.
-    void SetRootBoneIndex(unsigned index);
+    void SetRootBoneIndex(i32 index);
     /// Clear bones.
     void ClearBones();
     /// Reset all animating bones to initial positions.
@@ -96,22 +96,22 @@ public:
 
     /// Return number of bones.
     /// @property
-    unsigned GetNumBones() const { return bones_.Size(); }
+    i32 GetNumBones() const { return bones_.Size(); }
 
     /// Return root bone.
     /// @property
     Bone* GetRootBone();
-    /// Return index of the bone by name. Return M_MAX_UNSIGNED if not found.
-    unsigned GetBoneIndex(const String& boneName) const;
-    /// Return index of the bone by name hash. Return M_MAX_UNSIGNED if not found.
-    unsigned GetBoneIndex(const StringHash& boneNameHash) const;
-    /// Return index of the bone by the bone pointer. Return M_MAX_UNSIGNED if not found.
-    unsigned GetBoneIndex(const Bone* bone) const;
+    /// Return index of the bone by name. Return NINDEX if not found.
+    i32 GetBoneIndex(const String& boneName) const;
+    /// Return index of the bone by name hash. Return NINDEX if not found.
+    i32 GetBoneIndex(const StringHash& boneNameHash) const;
+    /// Return index of the bone by the bone pointer. Return NINDEX if not found.
+    i32 GetBoneIndex(const Bone* bone) const;
     /// Return parent of the given bone. Return null for root bones.
     Bone* GetBoneParent(const Bone* bone);
     /// Return bone by index.
     /// @property{get_bones}
-    Bone* GetBone(unsigned index);
+    Bone* GetBone(i32 index);
     /// Return bone by name.
     Bone* GetBone(const String& name);
     /// Return bone by name.
@@ -126,7 +126,7 @@ private:
     /// Bones.
     Vector<Bone> bones_;
     /// Root bone index.
-    unsigned rootBoneIndex_;
+    i32 rootBoneIndex_;
 };
 
 }