Browse Source

iOS8 support (idea & code courtesy of palxex, not tested).

Wei Mingzhi 9 years ago
parent
commit
14297c4052
6 changed files with 91 additions and 21 deletions
  1. 6 3
      common.h
  2. 4 0
      ios/SDLPal/SDLPal.xcodeproj/project.pbxproj
  3. 46 0
      ios/SDLPal/SDLPal/util.m
  4. 20 17
      sound.c
  5. 14 0
      util.h
  6. 1 1
      video.c

+ 6 - 3
common.h

@@ -104,8 +104,8 @@ extern "C"
 
 #elif defined (__IOS__)
 
-#define PAL_PREFIX            "../Documents/"
-#define PAL_SAVE_PREFIX       "../Documents/"
+#define PAL_PREFIX            UTIL_IOS_BasePath()
+#define PAL_SAVE_PREFIX       UTIL_IOS_SavePath()
 #define PAL_HAS_TOUCH         1
 
 #elif defined (__ANDROID__)
@@ -202,7 +202,10 @@ typedef unsigned char       UCHAR, *PUCHAR;
 
 typedef unsigned short      WORD, *LPWORD;
 typedef unsigned int        DWORD, *LPDWORD;
-typedef int                 INT, *LPINT, BOOL, *LPBOOL;
+typedef int                 INT, *LPINT;
+#ifndef __OBJC__
+typedef int                 BOOL, *LPBOOL;
+#endif
 typedef unsigned int        UINT, *PUINT, UINT32, *PUINT32;
 typedef unsigned char       BYTE, *LPBYTE;
 typedef CONST BYTE         *LPCBYTE;

+ 4 - 0
ios/SDLPal/SDLPal.xcodeproj/project.pbxproj

@@ -161,6 +161,7 @@
 		716552AA195BBE1B006E1227 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 716552A9195BBE1B006E1227 /* CoreAudio.framework */; };
 		716552AE195BBE7D006E1227 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 716552AD195BBE7D006E1227 /* AudioToolbox.framework */; };
 		716552B0195BBECE006E1227 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 716552AF195BBECE006E1227 /* QuartzCore.framework */; };
+		71AA35801A0BCA4E00793FFF /* util.m in Sources */ = {isa = PBXBuildFile; fileRef = 71AA357F1A0BCA4E00793FFF /* util.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
@@ -505,6 +506,7 @@
 		716552AB195BBE4C006E1227 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; };
 		716552AD195BBE7D006E1227 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
 		716552AF195BBECE006E1227 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
+		71AA357F1A0BCA4E00793FFF /* util.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = util.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -630,6 +632,7 @@
 		71655067195BB372006E1227 /* Supporting Files */ = {
 			isa = PBXGroup;
 			children = (
+				71AA357F1A0BCA4E00793FFF /* util.m */,
 				7165507D195BB3D8006E1227 /* Icon.png */,
 				71655068195BB372006E1227 /* SDLPal-Info.plist */,
 				71655072195BB372006E1227 /* Default.png */,
@@ -1283,6 +1286,7 @@
 				716552A6195BBDFF006E1227 /* SDL_audiotypecvt.c in Sources */,
 				716552A7195BBDFF006E1227 /* SDL_mixer.c in Sources */,
 				716552A8195BBDFF006E1227 /* SDL_wave.c in Sources */,
+				71AA35801A0BCA4E00793FFF /* util.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 46 - 0
ios/SDLPal/SDLPal/util.m

@@ -0,0 +1,46 @@
+#include <Foundation/Foundation.h>
+#include "common.h"
+#include "SDL_filesystem.h"
+
+LPCSTR
+UTIL_IOS_BasePath(
+   VOID
+)
+{
+   static char buf[4096] = "";
+
+   if (buf[0] == '\0')
+   {
+#ifdef CYDIA
+      char *p = SDL_GetBasePath();
+      if (p != NULL)
+      {
+         strcpy(buf, p);
+         free(p);
+      }
+#else
+      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+      NSString *documentsDirectory = [[paths objectAtIndex:0] stringByAppendingString:@"/"];
+      strcpy(buf, [documentsDirectory UTF8String]);
+#endif
+   }
+
+   return buf;
+}
+
+LPCSTR
+UTIL_IOS_SavePath(
+   VOID
+)
+{
+   static char buf[4096] = "";
+
+   if (buf[0] == '\0')
+   {
+      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+      NSString *documentsDirectory = [[paths objectAtIndex:0] stringByAppendingString:@"/"];
+      strcpy(buf, [documentsDirectory UTF8String]);
+   }
+
+   return buf;
+}

+ 20 - 17
sound.c

@@ -222,8 +222,8 @@ SOUND_FillAudio(
    if (!g_fNoMusic)
    {
 #ifdef PAL_HAS_MP3
-      SDL_mutexP(gSndPlayer.lock);
-
+      SDL_mutexP(gSndPlayer.lock);
+
       if (gSndPlayer.pMP3 != NULL)
       {
          mad_getSamples(gSndPlayer.pMP3, stream, len);
@@ -235,9 +235,9 @@ SOUND_FillAudio(
 
             mad_getSamples(gSndPlayer.pMP3, stream, len);
          }
-      }
+      }
 
-      SDL_mutexV(gSndPlayer.lock);
+      SDL_mutexV(gSndPlayer.lock);
 #endif
       RIX_FillBuffer(stream, len);
    }
@@ -369,7 +369,10 @@ SOUND_OpenAudio(
    //
    // Initialize the music subsystem.
    //
-   RIX_Init(va("%s%s", PAL_PREFIX, "mus.mkf"));
+   if (RIX_Init(va("%s%s", PAL_PREFIX, "mus.mkf")) < 0)
+   {
+      RIX_Init(va("%s%s", PAL_PREFIX, "MUS.MKF"));
+   }
 
 #ifdef PAL_HAS_CD
    //
@@ -631,14 +634,14 @@ SOUND_PlayChannel(
       free(bufdec);
       return;
    }
-   memcpy(wavecvt.buf, bufdec, wavespec.size);
-   if (g_fUseWav)
-   {
-      SDL_FreeWAV(bufdec);
-   }
-   else
+   memcpy(wavecvt.buf, bufdec, wavespec.size);
+   if (g_fUseWav)
    {
-      free(bufdec);
+      SDL_FreeWAV(bufdec);
+   }
+   else
+   {
+      free(bufdec);
    }
 
    //
@@ -678,13 +681,13 @@ PAL_PlayMUS(
 #endif
 
 #ifdef PAL_HAS_MP3
-   SDL_mutexP(gSndPlayer.lock);
-
+   SDL_mutexP(gSndPlayer.lock);
+
    if (gSndPlayer.pMP3 != NULL)
    {
       if (iNumRIX == gSndPlayer.iCurrentMP3 && !g_fNoMusic)
       {
-         SDL_mutexV(gSndPlayer.lock);
+         SDL_mutexV(gSndPlayer.lock);
          return;
       }
 
@@ -692,9 +695,9 @@ PAL_PlayMUS(
       mad_closeFile(gSndPlayer.pMP3);
 
       gSndPlayer.pMP3 = NULL;
-   }
+   }
 
-   SDL_mutexV(gSndPlayer.lock);
+   SDL_mutexV(gSndPlayer.lock);
 
    gSndPlayer.iCurrentMP3 = -1;
 

+ 14 - 0
util.h

@@ -90,6 +90,20 @@ VOID
 UTIL_CloseFile(
    FILE                *fp
 );
+    
+#ifdef __IOS__
+
+LPCSTR
+UTIL_IOS_BasePath(
+   VOID
+);
+
+LPCSTR
+UTIL_IOS_SavePath(
+   VOID
+);
+    
+#endif
 
 #define _PATH_LOG           PAL_PREFIX "log.txt"
 #define LOG_EMERG           0 /* system is unusable */

+ 1 - 1
video.c

@@ -183,7 +183,7 @@ VIDEO_Init(
    //
    // Create texture for overlay.
    //
-   overlay = SDL_LoadBMP(PAL_PREFIX "overlay.bmp");
+   overlay = SDL_LoadBMP(va("%s%s", PAL_PREFIX, "overlay.bmp"));
    if (overlay != NULL)
    {
       SDL_SetColorKey(overlay, SDL_RLEACCEL, SDL_MapRGB(overlay->format, 255, 0, 255));