Просмотр исходного кода

Fix multitouch degrading to single touch behavior over time

Andrey Fidrya 9 лет назад
Родитель
Сommit
a5fdeddfc6
3 измененных файлов с 20 добавлено и 10 удалено
  1. 15 5
      oxygine/src/Input.cpp
  2. 3 3
      oxygine/src/Input.h
  3. 2 2
      oxygine/src/core/oxygine.cpp

+ 15 - 5
oxygine/src/Input.cpp

@@ -37,7 +37,17 @@ 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;
+				++i;
+			}
+			if (i == MAX_TOUCHES - 1)
+	            _ids[i] = 0;
         }
     }
 
@@ -92,12 +102,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 +122,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*);

+ 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,