Browse Source

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.

Alex Szpakowski 10 years ago
parent
commit
9be2581e6f
4 changed files with 21 additions and 1 deletions
  1. 5 0
      src/common/iOS.h
  2. 13 0
      src/common/iOS.mm
  3. 1 1
      src/modules/font/BMFontRasterizer.cpp
  4. 2 0
      src/modules/system/System.cpp

+ 5 - 0
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
 

+ 13 - 0
src/common/iOS.mm

@@ -25,6 +25,8 @@
 #import <Foundation/Foundation.h>
 #import <UIKit/UIKit.h>
 
+#import <AudioToolbox/AudioServices.h>
+
 #include <vector>
 
 #include <SDL_events.h>
@@ -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
 

+ 1 - 1
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<filesystem::FileData> data = filesystem->read(filename.c_str());
+				StrongRef<FileData> data = filesystem->read(filename.c_str());
 				data->release();
 
 				images[pageindex].set(imagemodule->newImageData(data.get()));

+ 2 - 0
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