From c66c9e9ffda0c037d9d1a9142f6fcc754fb27578 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 24 Mar 2024 14:27:07 +0800 Subject: [PATCH] some fix --- .../Xcode15/raylib.xcodeproj/project.pbxproj | 4 +- src/platforms/rcore_ios.c | 41 ++++++++++--------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/projects/Xcode15/raylib.xcodeproj/project.pbxproj b/projects/Xcode15/raylib.xcodeproj/project.pbxproj index c11484b85..94f31373b 100644 --- a/projects/Xcode15/raylib.xcodeproj/project.pbxproj +++ b/projects/Xcode15/raylib.xcodeproj/project.pbxproj @@ -346,7 +346,7 @@ GRAPHICS_API_OPENGL_ES2, PLATFORM_IOS, ); - GCC_WARN_64_TO_32_BIT_CONVERSION = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GENERATE_INFOPLIST_FILE = YES; HEADER_SEARCH_PATHS = ""; @@ -388,7 +388,7 @@ GRAPHICS_API_OPENGL_ES2, PLATFORM_IOS, ); - GCC_WARN_64_TO_32_BIT_CONVERSION = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GENERATE_INFOPLIST_FILE = YES; HEADER_SEARCH_PATHS = ""; diff --git a/src/platforms/rcore_ios.c b/src/platforms/rcore_ios.c index cd95530c2..206d6bc5c 100644 --- a/src/platforms/rcore_ios.c +++ b/src/platforms/rcore_ios.c @@ -458,7 +458,7 @@ int InitPlatform(void) CORE.Window.screen.height = platform.viewController.view.frame.size.height; } - int orientation = [[UIApplication sharedApplication] statusBarOrientation]; + long long orientation = [[UIApplication sharedApplication] statusBarOrientation]; if(orientation == UIInterfaceOrientationPortrait){ TRACELOG(LOG_INFO, "IOS: Window orientation set as Portrait"); }else if(orientation == UIInterfaceOrientationPortraitUpsideDown){ @@ -665,19 +665,25 @@ void ClosePlatform(void) static void sync_all_touches(UIEvent* event) { - CORE.Input.Touch.pointCount = event.allTouches.count; + CORE.Input.Touch.pointCount = (int)event.allTouches.count; int i = 0; for (UITouch *touch in event.allTouches) { CGPoint location = [touch locationInView:platform.viewController.view]; CORE.Input.Touch.position[i] = (Vector2){ location.x, location.y }; - CORE.Input.Touch.pointId[i] = (int)touch; + CORE.Input.Touch.pointId[i] = (long long)touch; i++; if(i >= MAX_TOUCH_POINTS) break; } // TODO: Normalize CORE.Input.Touch.position[i] for CORE.Window.screen.width and CORE.Window.screen.height } +static int array_index_of(long long needle, long long *haystack, int size) +{ + for (int i = 0; i < size; i++) if(haystack[i] == needle) return i; + return -1; +} + static void send_gesture_event(NSSet * touches, int action) { #if defined(SUPPORT_GESTURES_SYSTEM) @@ -704,26 +710,21 @@ static void send_gesture_event(NSSet * touches, int action) // One of the touchpoints is released, remove it from touch point arrays for (UITouch *touch in touches) { - for (int i = 0; i < MAX_TOUCH_POINTS; i++) - { - if(CORE.Input.Touch.pointId[i] == (int)touch){ - CORE.Input.Touch.pointId[i] = 0; - CORE.Input.Touch.position[i] = (Vector2){ 0.0f, 0.0f }; - break; + int size = CORE.Input.Touch.pointCount; + if(size > MAX_TOUCH_POINTS) size = MAX_TOUCH_POINTS; + int i = array_index_of((long long)touch, CORE.Input.Touch.pointId, size); + if(i >= 0){ + // remove i-th touch point + for (int j = i; j < size - 1; j++) + { + CORE.Input.Touch.pointId[j] = CORE.Input.Touch.pointId[j + 1]; + CORE.Input.Touch.position[j] = CORE.Input.Touch.position[j + 1]; } + CORE.Input.Touch.pointCount--; + }else{ + TRACELOG(LOG_WARNING, "Touch point not found. This may be a bug!"); } } - // re-arrange the touch points - int j = 0; - for (int i = 0; i < MAX_TOUCH_POINTS; i++) - { - if(CORE.Input.Touch.pointId[i] != 0){ - CORE.Input.Touch.pointId[j] = CORE.Input.Touch.pointId[i]; - CORE.Input.Touch.position[j] = CORE.Input.Touch.position[i]; - j++; - } - } - CORE.Input.Touch.pointCount -= touches.count; } if(action == TOUCH_ACTION_MOVE){