Explorar o código

Merge pull request #58 from zmeyc/pr_multitouch_bugfix

Fix multitouch degrading to single touch over time
Denis Muratshin %!s(int64=9) %!d(string=hai) anos
pai
achega
6fdf0ab8e7
Modificáronse 4 ficheiros con 32 adicións e 16 borrados
  1. 19 5
      oxygine/src/Input.cpp
  2. 3 3
      oxygine/src/Input.h
  3. 8 6
      oxygine/src/PointerState.cpp
  4. 2 2
      oxygine/src/core/oxygine.cpp

+ 19 - 5
oxygine/src/Input.cpp

@@ -37,7 +37,21 @@ namespace oxygine
 
         if (type == TouchEvent::TOUCH_UP)
         {
-            _ids[ps->getIndex() - 1] = 0;
+			// Remove id and compact the array:
+			//  - stop on first copied zero id
+			//  - if end is reached, zero the last element
+			int i = ps->getIndex() - 1;
+			while (i < MAX_TOUCHES - 1) {
+				if ((_ids[i] = _ids[i + 1]) == 0)
+					break;
+				_pointers[i] = _pointers[i + 1];
+				_pointers[i]._index = i + 1;
+				++i;
+			}
+			if (i == MAX_TOUCHES - 1) {
+	            _ids[i] = 0;
+				_pointers[i].init(i + 1);
+			}
         }
     }
 
@@ -92,12 +106,12 @@ namespace oxygine
     }
 
 #ifndef __S3E__
-    int Input::touchID2index(int id)
+    int Input::touchID2index(int64_t id)
     {
         id += 1;//id could be = 0 ?
         for (int i = 0; i < MAX_TOUCHES; ++i)
         {
-            int& d = _ids[i];
+            int64_t& d = _ids[i];
             int index = i + 1;
             if (d == 0)
             {
@@ -112,9 +126,9 @@ namespace oxygine
         return -1;
     }
 
-    PointerState* Input::getTouchByID(int id)
+    PointerState* Input::getTouchByID(int64_t id)
     {
-        int i = touchID2index(id);
+        int64_t i = touchID2index(id);
         if (i == -1)
             return 0;
         return getTouchByIndex(i);

+ 3 - 3
oxygine/src/Input.h

@@ -26,8 +26,8 @@ namespace oxygine
         PointerState* getTouchByIndex(int index);
 
 #ifndef __S3E__
-        int touchID2index(int id);
-        PointerState* getTouchByID(int id);
+        int touchID2index(int64_t id);
+        PointerState* getTouchByID(int64_t id);
 #endif
 
 
@@ -35,7 +35,7 @@ namespace oxygine
         PointerState _pointers[MAX_TOUCHES];
         PointerState _pointerMouse;
 
-        int _ids[MAX_TOUCHES + 1];
+        int64_t _ids[MAX_TOUCHES + 1];
 
 
         void sendPointerButtonEvent(spStage, MouseButton button, float x, float y, float pressure, int type, PointerState*);

+ 8 - 6
oxygine/src/PointerState.cpp

@@ -4,14 +4,16 @@ namespace oxygine
 {
     PointerState::PointerState(): _index(0)
     {
-        for (int i = 0; i < MouseButton_Count; ++i)
-            _isPressed[i] = false;
+		init(_index);
     }
 
-    void PointerState::init(int ID)
-    {
-        _index = ID;
-    }
+	void PointerState::init(int pointerIndex)
+	{
+		_index = pointerIndex;
+		for (int i = 0; i < MouseButton_Count; ++i)
+			_isPressed[i] = false;
+		_position.setZero();
+	}
 
     bool isFriend22(Actor* actor, Actor* max_parent, Actor* checkParent)
     {

+ 2 - 2
oxygine/src/core/oxygine.cpp

@@ -691,7 +691,7 @@ namespace oxygine
                         {
                             //log::messageln("SDL_FINGERMOTION");
                             Vector2 pos = convertTouch(event);
-                            PointerState* ps = input->getTouchByID((int)event.tfinger.fingerId);
+                            PointerState* ps = input->getTouchByID((int64_t)event.tfinger.fingerId);
                             if (ps)
                                 input->sendPointerMotionEvent(stage,
                                                               pos.x, pos.y, event.tfinger.pressure, ps);
@@ -706,7 +706,7 @@ namespace oxygine
                         {
                             //log::messageln("SDL_FINGER");
                             Vector2 pos = convertTouch(event);
-                            PointerState* ps = input->getTouchByID((int)event.tfinger.fingerId);
+                            PointerState* ps = input->getTouchByID((int64_t)event.tfinger.fingerId);
                             if (ps)
                                 input->sendPointerButtonEvent(stage,
                                                               MouseButton_Touch,