Răsfoiți Sursa

Make CountSetBits() signed (#2953)

1vanK 3 ani în urmă
părinte
comite
c238f55e8e

+ 1 - 1
Docs/AngelScriptAPI.h

@@ -37940,7 +37940,7 @@ VectorBuffer CompressVectorBuffer(VectorBuffer&);
 float ConvertGammaToLinear(float);
 float ConvertLinearToGamma(float);
 float Cos(float);
-uint CountSetBits(uint);
+int CountSetBits(uint);
 Object CreateObject(const String&);
 bool DecompressStream(Serializer&, Deserializer&);
 VectorBuffer DecompressVectorBuffer(VectorBuffer&);

+ 1 - 1
Docs/ScriptAPI.dox

@@ -38285,7 +38285,7 @@ Properties:
 - float ConvertGammaToLinear(float)
 - float ConvertLinearToGamma(float)
 - float Cos(float)
-- uint CountSetBits(uint)
+- int CountSetBits(uint)
 - Object@ CreateObject(const String&)
 - bool DecompressStream(Serializer&, Deserializer&)
 - VectorBuffer DecompressVectorBuffer(VectorBuffer&)

+ 2 - 2
Source/Urho3D/AngelScript/Generated_GlobalFunctions.cpp

@@ -90,8 +90,8 @@ void ASRegisterGeneratedGlobalFunctions(asIScriptEngine* engine)
     // template <class T> T Cos(T angle) | File: ../Math/MathDefs.h
     engine->RegisterGlobalFunction("float Cos(float)", AS_FUNCTIONPR(Cos, (float), float), AS_CALL_CDECL);
 
-    // unsigned CountSetBits(unsigned value) | File: ../Math/MathDefs.h
-    engine->RegisterGlobalFunction("uint CountSetBits(uint)", AS_FUNCTIONPR(CountSetBits, (unsigned), unsigned), AS_CALL_CDECL);
+    // i32 CountSetBits(u32 value) | File: ../Math/MathDefs.h
+    engine->RegisterGlobalFunction("int CountSetBits(uint)", AS_FUNCTIONPR(CountSetBits, (u32), i32), AS_CALL_CDECL);
 
     // PODVector<unsigned char> DecodeBase64(String encodedString) | File: ../Core/StringUtils.h
     // Error: type "PODVector<unsigned char>" can not automatically bind

+ 2 - 2
Source/Urho3D/Math/MathDefs.h

@@ -276,10 +276,10 @@ inline unsigned LogBaseTwo(unsigned value)
 }
 
 /// Count the number of set bits in a mask.
-inline unsigned CountSetBits(unsigned value)
+inline i32 CountSetBits(u32 value)
 {
     // Brian Kernighan's method
-    unsigned count = 0;
+    i32 count = 0;
     for (count = 0; value; count++)
         value &= value - 1;
     return count;

+ 2 - 2
Source/Urho3D/UI/UI.cpp

@@ -1464,7 +1464,7 @@ void UI::ProcessClickBegin(const IntVector2& windowCursorPos, MouseButton button
                 dragData->dragBeginSumPos = cursorPos;
                 dragData->dragBeginTimer.Reset();
                 dragData->dragButtons = button;
-                dragData->numDragButtons = CountSetBits((unsigned)dragData->dragButtons);
+                dragData->numDragButtons = CountSetBits((u32)dragData->dragButtons);
                 dragElementsCount_++;
 
                 dragElementsContain = dragElements_.Contains(element);
@@ -1475,7 +1475,7 @@ void UI::ProcessClickBegin(const IntVector2& windowCursorPos, MouseButton button
                 dragData->sumPos += cursorPos;
                 dragData->dragBeginSumPos += cursorPos;
                 dragData->dragButtons |= button;
-                dragData->numDragButtons = CountSetBits((unsigned)dragData->dragButtons);
+                dragData->numDragButtons = CountSetBits((u32)dragData->dragButtons);
             }
         }
         else

+ 1 - 1
Source/Urho3D/UI/UI.h

@@ -254,7 +254,7 @@ public:
         /// Which button combo initiated the drag.
         MouseButtonFlags dragButtons;
         /// How many buttons initiated the drag.
-        int numDragButtons;
+        i32 numDragButtons;
         /// Sum of all touch locations.
         IntVector2 sumPos;
         /// Flag for a drag start event pending.

+ 1 - 1
Source/Urho3D/UI/UIElement.cpp

@@ -408,7 +408,7 @@ void UIElement::OnDragBegin(const IntVector2& position, const IntVector2& screen
     Cursor* cursor)
 {
     dragButtonCombo_ = buttons;
-    dragButtonCount_ = CountSetBits((unsigned)dragButtonCombo_);
+    dragButtonCount_ = CountSetBits((u32)dragButtonCombo_);
 }
 
 void UIElement::OnDragMove(const IntVector2& position, const IntVector2& screenPosition, const IntVector2& deltaPos, MouseButtonFlags buttons,

+ 1 - 1
Source/Urho3D/UI/UIElement.h

@@ -836,7 +836,7 @@ protected:
     /// Drag button combo.
     MouseButtonFlags dragButtonCombo_{};
     /// Drag button count.
-    unsigned dragButtonCount_{};
+    i32 dragButtonCount_{};
 
 private:
     /// Return child elements recursively.