From 9be2581e6fa80303a0fda4d903ccc85a541b3dbb Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 14 Aug 2015 21:30:07 -0300 Subject: [PATCH] Implemented love.system.vibrate on iOS. Unfortunately due to API limitations the duration argument is ignored, and it always vibrates for roughly 0.5 seconds. --- src/common/iOS.h | 5 +++++ src/common/iOS.mm | 13 +++++++++++++ src/modules/font/BMFontRasterizer.cpp | 2 +- src/modules/system/System.cpp | 2 ++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/common/iOS.h b/src/common/iOS.h index 84c1e2717..d788e057f 100644 --- a/src/common/iOS.h +++ b/src/common/iOS.h @@ -59,6 +59,11 @@ bool openURL(const std::string &url); **/ std::string getExecutablePath(); +/** + * Causes devices with vibration support to vibrate for about 0.5 seconds. + **/ +void vibrate(); + } // ios } // love diff --git a/src/common/iOS.mm b/src/common/iOS.mm index 297f463b0..fb04631d5 100644 --- a/src/common/iOS.mm +++ b/src/common/iOS.mm @@ -25,6 +25,8 @@ #import #import +#import + #include #include @@ -321,6 +323,17 @@ std::string getExecutablePath() } } +static dispatch_queue_t queue = nil; +static dispatch_source_t timer = nil; + +void vibrate() +{ + @autoreleasepool + { + AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); + } +} + } // ios } // love diff --git a/src/modules/font/BMFontRasterizer.cpp b/src/modules/font/BMFontRasterizer.cpp index b6df24b06..33b6351e1 100644 --- a/src/modules/font/BMFontRasterizer.cpp +++ b/src/modules/font/BMFontRasterizer.cpp @@ -199,7 +199,7 @@ void BMFontRasterizer::parseConfig(const std::string &configtext) throw love::Exception("Image module not loaded!"); // Release these variables right away since StrongRef retains. - StrongRef data = filesystem->read(filename.c_str()); + StrongRef data = filesystem->read(filename.c_str()); data->release(); images[pageindex].set(imagemodule->newImageData(data.get())); diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index 881d5682f..cb3087a89 100755 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -146,6 +146,8 @@ void System::vibrate(double seconds) const { #ifdef LOVE_ANDROID love::android::vibrate(seconds); +#elif defined(LOVE_IOS) + love::ios::vibrate(); #else LOVE_UNUSED(seconds); #endif