From 891ad34d886a73d990bf4dc2401fe25c8533809c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 26 Jun 2016 15:33:14 +0900 Subject: [PATCH] mobile: UpdateTouchesOnIOS should take int64 ptrs --- mobile/mobile.go | 2 +- mobile/touches_android.go | 2 +- mobile/touches_empty.go | 2 +- mobile/touches_ios.go | 26 +++++++++++++++++++++++--- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/mobile/mobile.go b/mobile/mobile.go index dc02b37c9..1451b091d 100644 --- a/mobile/mobile.go +++ b/mobile/mobile.go @@ -54,6 +54,6 @@ func UpdateTouchesOnAndroid(action int, id int, x, y int) { updateTouchesOnAndroid(action, id, x, y) } -func UpdateTouchesOnIOS(phase int, ptr int, x, y int) { +func UpdateTouchesOnIOS(phase int, ptr int64, x, y int) { updateTouchesOnIOSImpl(phase, ptr, x, y) } diff --git a/mobile/touches_android.go b/mobile/touches_android.go index 68081d20c..e1a13f88b 100644 --- a/mobile/touches_android.go +++ b/mobile/touches_android.go @@ -25,6 +25,6 @@ func updateTouchesOnAndroid(action int, id int, x, y int) { } } -func updateTouchesOnIOSImpl(phase int, ptr int, x, y int) { +func updateTouchesOnIOSImpl(phase int, ptr int64, x, y int) { panic("not reach") } diff --git a/mobile/touches_empty.go b/mobile/touches_empty.go index f2af52c78..4b023c2f2 100644 --- a/mobile/touches_empty.go +++ b/mobile/touches_empty.go @@ -21,5 +21,5 @@ package mobile func updateTouchesOnAndroid(action int, id int, x, y int) { } -func updateTouchesOnIOSImpl(phase int, ptr int, x, y int) { +func updateTouchesOnIOSImpl(phase int, ptr int64, x, y int) { } diff --git a/mobile/touches_ios.go b/mobile/touches_ios.go index 17d50c0a7..d536ed516 100644 --- a/mobile/touches_ios.go +++ b/mobile/touches_ios.go @@ -22,17 +22,37 @@ package mobile // #import import "C" +var ptrToID = map[int64]int{} + +func getIDFromPtr(ptr int64) int { + if id, ok := ptrToID[ptr]; ok { + return id + } + maxID := 0 + for _, id := range ptrToID { + if maxID > id { + maxID = id + } + } + id := maxID + 1 + ptrToID[ptr] = id + return id +} + func updateTouchesOnAndroid(action int, id int, x, y int) { panic("not reach") } -func updateTouchesOnIOSImpl(phase int, ptr int, x, y int) { +func updateTouchesOnIOSImpl(phase int, ptr int64, x, y int) { switch phase { case C.UITouchPhaseBegan, C.UITouchPhaseMoved, C.UITouchPhaseStationary: - touches[ptr] = position{x, y} + id := getIDFromPtr(ptr) + touches[id] = position{x, y} updateTouches() case C.UITouchPhaseEnded, C.UITouchPhaseCancelled: - delete(touches, ptr) + id := getIDFromPtr(ptr) + delete(ptrToID, ptr) + delete(touches, id) updateTouches() default: panic("not reach")