Browse Source

Input: unsigned to signed

1vanK 3 years ago
parent
commit
23f9950d7e

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

@@ -10768,9 +10768,9 @@ template <class T> void RegisterMembers_Input(asIScriptEngine* engine, const cha
     engine->RegisterObjectMethod(className, "JoystickState@ GetJoystick(SDL_JoystickID)", AS_METHODPR(T, GetJoystick, (SDL_JoystickID), JoystickState*), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "JoystickState@ get_joysticks(SDL_JoystickID)", AS_METHODPR(T, GetJoystick, (SDL_JoystickID), JoystickState*), AS_CALL_THISCALL);
 
-    // JoystickState* Input::GetJoystickByIndex(unsigned index)
-    engine->RegisterObjectMethod(className, "JoystickState@ GetJoystickByIndex(uint)", AS_METHODPR(T, GetJoystickByIndex, (unsigned), JoystickState*), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "JoystickState@ get_joysticksByIndex(uint)", AS_METHODPR(T, GetJoystickByIndex, (unsigned), JoystickState*), AS_CALL_THISCALL);
+    // JoystickState* Input::GetJoystickByIndex(i32 index)
+    engine->RegisterObjectMethod(className, "JoystickState@ GetJoystickByIndex(int)", AS_METHODPR(T, GetJoystickByIndex, (i32), JoystickState*), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "JoystickState@ get_joysticksByIndex(int)", AS_METHODPR(T, GetJoystickByIndex, (i32), JoystickState*), AS_CALL_THISCALL);
 
     // JoystickState* Input::GetJoystickByName(const String& name)
     engine->RegisterObjectMethod(className, "JoystickState@ GetJoystickByName(const String&in)", AS_METHODPR(T, GetJoystickByName, (const String&), JoystickState*), AS_CALL_THISCALL);
@@ -10825,13 +10825,13 @@ template <class T> void RegisterMembers_Input(asIScriptEngine* engine, const cha
     engine->RegisterObjectMethod(className, "IntVector2 GetMousePosition() const", AS_METHODPR(T, GetMousePosition, () const, IntVector2), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "IntVector2 get_mousePosition() const", AS_METHODPR(T, GetMousePosition, () const, IntVector2), AS_CALL_THISCALL);
 
-    // unsigned Input::GetNumJoysticks() const
-    engine->RegisterObjectMethod(className, "uint GetNumJoysticks() const", AS_METHODPR(T, GetNumJoysticks, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_numJoysticks() const", AS_METHODPR(T, GetNumJoysticks, () const, unsigned), AS_CALL_THISCALL);
+    // i32 Input::GetNumJoysticks() const
+    engine->RegisterObjectMethod(className, "int GetNumJoysticks() const", AS_METHODPR(T, GetNumJoysticks, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_numJoysticks() const", AS_METHODPR(T, GetNumJoysticks, () const, i32), AS_CALL_THISCALL);
 
-    // unsigned Input::GetNumTouches() const
-    engine->RegisterObjectMethod(className, "uint GetNumTouches() const", AS_METHODPR(T, GetNumTouches, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_numTouches() const", AS_METHODPR(T, GetNumTouches, () const, unsigned), AS_CALL_THISCALL);
+    // i32 Input::GetNumTouches() const
+    engine->RegisterObjectMethod(className, "int GetNumTouches() const", AS_METHODPR(T, GetNumTouches, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_numTouches() const", AS_METHODPR(T, GetNumTouches, () const, i32), AS_CALL_THISCALL);
 
     // bool Input::GetQualifierDown(Qualifier qualifier) const
     engine->RegisterObjectMethod(className, "bool GetQualifierDown(Qualifier) const", AS_METHODPR(T, GetQualifierDown, (Qualifier) const, bool), AS_CALL_THISCALL);
@@ -10870,9 +10870,9 @@ template <class T> void RegisterMembers_Input(asIScriptEngine* engine, const cha
     engine->RegisterObjectMethod(className, "bool GetToggleFullscreen() const", AS_METHODPR(T, GetToggleFullscreen, () const, bool), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool get_toggleFullscreen() const", AS_METHODPR(T, GetToggleFullscreen, () const, bool), AS_CALL_THISCALL);
 
-    // TouchState* Input::GetTouch(unsigned index) const
-    engine->RegisterObjectMethod(className, "TouchState@ GetTouch(uint) const", AS_METHODPR(T, GetTouch, (unsigned) const, TouchState*), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "TouchState@ get_touches(uint) const", AS_METHODPR(T, GetTouch, (unsigned) const, TouchState*), AS_CALL_THISCALL);
+    // TouchState* Input::GetTouch(i32 index) const
+    engine->RegisterObjectMethod(className, "TouchState@ GetTouch(int) const", AS_METHODPR(T, GetTouch, (i32) const, TouchState*), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "TouchState@ get_touches(int) const", AS_METHODPR(T, GetTouch, (i32) const, TouchState*), AS_CALL_THISCALL);
 
     // bool Input::GetTouchEmulation() const
     engine->RegisterObjectMethod(className, "bool GetTouchEmulation() const", AS_METHODPR(T, GetTouchEmulation, () const, bool), AS_CALL_THISCALL);
@@ -10906,8 +10906,8 @@ template <class T> void RegisterMembers_Input(asIScriptEngine* engine, const cha
     engine->RegisterObjectMethod(className, "bool IsScreenKeyboardVisible() const", AS_METHODPR(T, IsScreenKeyboardVisible, () const, bool), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool get_screenKeyboardVisible() const", AS_METHODPR(T, IsScreenKeyboardVisible, () const, bool), AS_CALL_THISCALL);
 
-    // unsigned Input::LoadGestures(Deserializer& source)
-    engine->RegisterObjectMethod(className, "uint LoadGestures(Deserializer&)", AS_METHODPR(T, LoadGestures, (Deserializer&), unsigned), AS_CALL_THISCALL);
+    // i32 Input::LoadGestures(Deserializer& source)
+    engine->RegisterObjectMethod(className, "int LoadGestures(Deserializer&)", AS_METHODPR(T, LoadGestures, (Deserializer&), i32), AS_CALL_THISCALL);
 
     // bool Input::RecordGesture()
     engine->RegisterObjectMethod(className, "bool RecordGesture()", AS_METHODPR(T, RecordGesture, (), bool), AS_CALL_THISCALL);

+ 30 - 24
Source/Urho3D/Input/Input.cpp

@@ -50,7 +50,7 @@ const StringHash VAR_BUTTON_MOUSE_BUTTON_BINDING("VAR_BUTTON_MOUSE_BUTTON_BINDIN
 const StringHash VAR_LAST_KEYSYM("VAR_LAST_KEYSYM");
 const StringHash VAR_SCREEN_JOYSTICK_ID("VAR_SCREEN_JOYSTICK_ID");
 
-const unsigned TOUCHID_MAX = 32;
+static constexpr i32 TOUCHID_MAX = 32;
 
 /// Convert SDL keycode if necessary.
 Key ConvertSDLKeyCode(int keySym, int scanCode)
@@ -1005,9 +1005,9 @@ SDL_JoystickID Input::AddScreenJoystick(XMLFile* layoutFile, XMLFile* styleFile)
     state.name_ = screenJoystick->GetName();
     state.screenJoystick_ = screenJoystick;
 
-    unsigned numButtons = 0;
-    unsigned numAxes = 0;
-    unsigned numHats = 0;
+    i32 numButtons = 0;
+    i32 numAxes = 0;
+    i32 numHats = 0;
     const Vector<SharedPtr<UIElement>>& children = state.screenJoystick_->GetChildren();
     for (Vector<SharedPtr<UIElement>>::ConstIterator iter = children.Begin(); iter != children.End(); ++iter)
     {
@@ -1082,14 +1082,14 @@ SDL_JoystickID Input::AddScreenJoystick(XMLFile* layoutFile, XMLFile* styleFile)
                 else if (keyBinding.Length() == 4)
                 {
                     keyBindings.Resize(4);      // e.g.: "WSAD"
-                    for (unsigned i = 0; i < 4; ++i)
+                    for (i32 i = 0; i < 4; ++i)
                         keyBindings[i] = keyBinding.Substring(i, 1);
                 }
                 if (keyBindings.Size() == 4)
                 {
                     PopulateKeyBindingMap(keyBindingMap);
 
-                    for (unsigned j = 0; j < 4; ++j)
+                    for (i32 j = 0; j < 4; ++j)
                     {
                         if (keyBindings[j].Length() == 1)
                             mappedKeyBinding[j] = keyBindings[j][0];
@@ -1220,7 +1220,7 @@ bool Input::SaveGesture(Serializer& dest, unsigned gestureID)
     return SDL_SaveDollarTemplate(gestureID, wrapper.GetRWOps()) != 0;
 }
 
-unsigned Input::LoadGestures(Deserializer& source)
+i32 Input::LoadGestures(Deserializer& source)
 {
     // If have no touch devices, fail
     if (!SDL_GetNumTouchDevices())
@@ -1230,7 +1230,7 @@ unsigned Input::LoadGestures(Deserializer& source)
     }
 
     RWOpsWrapper<Deserializer> wrapper(source);
-    return (unsigned)SDL_LoadDollarTemplates(-1, wrapper.GetRWOps());
+    return SDL_LoadDollarTemplates(-1, wrapper.GetRWOps());
 }
 
 
@@ -1250,8 +1250,10 @@ void Input::RemoveAllGestures()
 #endif
 }
 
-SDL_JoystickID Input::OpenJoystick(unsigned index)
+SDL_JoystickID Input::OpenJoystick(i32 index)
 {
+    assert(index >= 0);
+
     SDL_Joystick* joystick = SDL_JoystickOpen(index);
     if (!joystick)
     {
@@ -1268,9 +1270,9 @@ SDL_JoystickID Input::OpenJoystick(unsigned index)
     if (SDL_IsGameController(index))
         state.controller_ = SDL_GameControllerOpen(index);
 
-    auto numButtons = (unsigned)SDL_JoystickNumButtons(joystick);
-    auto numAxes = (unsigned)SDL_JoystickNumAxes(joystick);
-    auto numHats = (unsigned)SDL_JoystickNumHats(joystick);
+    i32 numButtons = SDL_JoystickNumButtons(joystick);
+    i32 numAxes = SDL_JoystickNumAxes(joystick);
+    i32 numHats = SDL_JoystickNumHats(joystick);
 
     // When the joystick is a controller, make sure there's enough axes & buttons for the standard controller mappings
     if (state.controller_)
@@ -1421,8 +1423,10 @@ int Input::GetMouseMoveY() const
         return 0;
 }
 
-TouchState* Input::GetTouch(unsigned index) const
+TouchState* Input::GetTouch(i32 index) const
 {
+    assert(index >= 0);
+
     if (index >= touches_.Size())
         return nullptr;
 
@@ -1433,9 +1437,11 @@ TouchState* Input::GetTouch(unsigned index) const
     return const_cast<TouchState*>(&i->second_);
 }
 
-JoystickState* Input::GetJoystickByIndex(unsigned index)
+JoystickState* Input::GetJoystickByIndex(i32 index)
 {
-    unsigned compare = 0;
+    assert(index >= 0);
+
+    i32 compare = 0;
     for (HashMap<SDL_JoystickID, JoystickState>::Iterator i = joysticks_.Begin(); i != joysticks_.End(); ++i)
     {
         if (compare++ == index)
@@ -1545,8 +1551,8 @@ void Input::ResetJoysticks()
     joysticks_.Clear();
 
     // Open each detected joystick automatically on startup
-    auto size = static_cast<unsigned>(SDL_NumJoysticks());
-    for (unsigned i = 0; i < size; ++i)
+    i32 size = SDL_NumJoysticks();
+    for (i32 i = 0; i < size; ++i)
         OpenJoystick(i);
 }
 
@@ -1560,7 +1566,7 @@ void Input::ResetInputAccumulation()
     mouseMoveWheel_ = 0;
     for (HashMap<SDL_JoystickID, JoystickState>::Iterator i = joysticks_.Begin(); i != joysticks_.End(); ++i)
     {
-        for (unsigned j = 0; j < i->second_.buttonPress_.Size(); ++j)
+        for (i32 j = 0; j < i->second_.buttonPress_.Size(); ++j)
             i->second_.buttonPress_[j] = false;
     }
 
@@ -1663,25 +1669,25 @@ void Input::ResetTouches()
 
 }
 
-unsigned Input::GetTouchIndexFromID(int touchID)
+i32 Input::GetTouchIndexFromID(int touchID)
 {
     HashMap<int, int>::ConstIterator i = touchIDMap_.Find(touchID);
     if (i != touchIDMap_.End())
     {
-        return (unsigned)i->second_;
+        return i->second_;
     }
 
-    unsigned index = PopTouchIndex();
+    i32 index = PopTouchIndex();
     touchIDMap_[touchID] = index;
     return index;
 }
 
-unsigned Input::PopTouchIndex()
+i32 Input::PopTouchIndex()
 {
     if (availableTouchIDs_.Empty())
         return 0;
 
-    auto index = (unsigned)availableTouchIDs_.Front();
+    i32 index = availableTouchIDs_.Front();
     availableTouchIDs_.PopFront();
     return index;
 }
@@ -2151,7 +2157,7 @@ void Input::HandleSDLEvent(void* sdlEvent)
         {
             using namespace JoystickConnected;
 
-            SDL_JoystickID joystickID = OpenJoystick((unsigned)evt.jdevice.which);
+            SDL_JoystickID joystickID = OpenJoystick(evt.jdevice.which);
 
             VariantMap& eventData = GetEventDataMap();
             eventData[P_JOYSTICKID] = joystickID;

+ 8 - 8
Source/Urho3D/Input/Input.h

@@ -217,7 +217,7 @@ public:
     /// Save a specific in-memory touch gesture to a file. Return true if successful.
     bool SaveGesture(Serializer& dest, unsigned gestureID);
     /// Load touch gestures from a file. Return number of loaded gestures, or 0 on failure.
-    unsigned LoadGestures(Deserializer& source);
+    i32 LoadGestures(Deserializer& source);
     /// Remove an in-memory gesture by ID. Return true if was found.
     bool RemoveGesture(unsigned gestureID);
     /// Remove all in-memory gestures.
@@ -288,20 +288,20 @@ public:
 
     /// Return number of active finger touches.
     /// @property
-    unsigned GetNumTouches() const { return touches_.Size(); }
+    i32 GetNumTouches() const { return touches_.Size(); }
     /// Return active finger touch by index.
     /// @property{get_touches}
-    TouchState* GetTouch(unsigned index) const;
+    TouchState* GetTouch(i32 index) const;
 
     /// Return number of connected joysticks.
     /// @property
-    unsigned GetNumJoysticks() const { return joysticks_.Size(); }
+    i32 GetNumJoysticks() const { return joysticks_.Size(); }
     /// Return joystick state by ID, or null if does not exist.
     /// @property{get_joysticks}
     JoystickState* GetJoystick(SDL_JoystickID id);
     /// Return joystick state by index, or null if does not exist. 0 = first connected joystick.
     /// @property{get_joysticksByIndex}
-    JoystickState* GetJoystickByIndex(unsigned index);
+    JoystickState* GetJoystickByIndex(i32 index);
     /// Return joystick state by name, or null if does not exist.
     /// @property{get_joysticksByName}
     JoystickState* GetJoystickByName(const String& name);
@@ -350,7 +350,7 @@ private:
     /// Initialize when screen mode initially set.
     void Initialize();
     /// Open a joystick and return its ID. Return -1 if no joystick.
-    SDL_JoystickID OpenJoystick(unsigned index);
+    SDL_JoystickID OpenJoystick(i32 index);
     /// Setup internal joystick structures.
     void ResetJoysticks();
     /// Prepare input state for application gaining input focus.
@@ -364,9 +364,9 @@ private:
     /// Reset input accumulation.
     void ResetInputAccumulation();
     /// Get the index of a touch based on the touch ID.
-    unsigned GetTouchIndexFromID(int touchID);
+    i32 GetTouchIndexFromID(int touchID);
     /// Used internally to return and remove the next available touch index.
-    unsigned PopTouchIndex();
+    i32 PopTouchIndex();
     /// Push a touch index back into the list of available when finished with it.
     void PushTouchIndex(int touchID);
     /// Send an input focus or window minimization change event.