Author Topic: Building for iOS?  (Read 1452 times)

Building for iOS?
« on: 19 Nov 2019, 03:50 »
Has anyone successfully built the engine and a game for iOS recently?

I've read the two old threads, and pulled down the source from Janet Gilberg/Wadjet, but that was built for a really old version of AGS, and I created my game with 3.5. So, it seems if I want to release for iOS, I have to get 3.5 to build -- or recreate my game in 3.4.0 (a version of AGS that's going on 3 years old)?

I've updated the Xcode project in the iOS folder with the current engine/common files, and have corrected a couple of build issues, and got the libraries to build, but ultimately it fails to compile due to errors in the GLAD code. Unfortunately, I'm not familiar enough with OpenGL and C++ to fix it.

The errors I'm getting are around GLAD_GL_VERSION_2_0:

Code: Adventure Game Studio
  1. Expected unqualified-id glad.h in file ali3dogl.cpp
  2. Expanded from macro 'GLAD_GL_VERSION_2_0'
  4. Expected ')' in file ali3dogl.cpp
  5. Expanded from macro 'GLAD_GL_VERSION_2_0'
  6. To match this '('

I think it's related to ogl_headers.h, where it defines GLAD_GL_VERSION_2_0
Code: Adventure Game Studio
  1. #ifndef GLAPI
  2. #define GLAD_GL_VERSION_2_0 (0)
  3. #endif

If I comment those lines, then I get a ton of undefined GL errors.

Any pointers in the right direction would be appreciated!


Re: Building for iOS?
« Reply #1 on: 21 Nov 2019, 01:57 »
I guess no one's interested in iOS  :P

Anyway, I added this line to ogl_headers.h at line 70 (inside the AGS_PLATFORM_OS_IOS section) to work around the GLAD errors...
Code: C++
  1. #define GLAPI extern

That got me a little further., and on to the next error... Now I have an issue with a missing pack_fopen method I'm trying to work on...

Crimson Wizard

  • Local Moderator
    • Lifetime Achievement Award Winner
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    • Crimson Wizard worked on one or more games that won an AGS Award!
    • Crimson Wizard worked on one or more games that was nominated for an AGS Award!
Re: Building for iOS?
« Reply #2 on: 21 Nov 2019, 07:21 »
AFAIK only few people/companies were building for iOS in the past, and none used 3.5.0 yet.

I asked a person who touched the iOS port to look into this when he has time, so maybe he will respond later.
« Last Edit: 21 Nov 2019, 07:23 by Crimson Wizard »

Re: Building for iOS?
« Reply #3 on: 21 Nov 2019, 16:49 »
I was able to get it to build and run successfully.

To fix the pack_fopen error, I added code to Engine/ac/file.cpp to define it as it was in the previous versions of the file for AGS_PLATFORM_OS_IOS.

Code: C++
  2. // override packfile functions to allow it to load from our
  3. // custom CLIB datafiles
  4. extern "C" {
  5.     PACKFILE*_my_temppack;
  6. #if ALLEGRO_DATE > 19991010
  7. #define PFO_PARAM const char *
  8. #else
  9. #define PFO_PARAM char *
  10. #endif
  11. #if !defined(AGS_RUNTIME_PATCH_ALLEGRO)
  12.     extern PACKFILE *__old_pack_fopen(PFO_PARAM,PFO_PARAM);
  13. #endif
  14. }
  16. PACKFILE *pack_fopen(const char *filename, const char *mode)
  17. {
  18.     return __old_pack_fopen(filename, mode);
  19. }
  20. #endif

After that, I had to tweak startThread in agsViewController.m to look for my game.ags instead of searching in /ags/game, based on the code from Janet.

Code: C++
  1.     #if defined (IOS_VERSION)
  2.         //JG
  3.         NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Rogue"
  4.                                                              ofType:@"ags"];
  5.         const char * resourceChars = [filePath UTF8String];
  6.         strcpy(filename, resourceChars);
  7.     #else
  8.         strcpy(filename, path);
  9.         strcat(filename, "ac2game.dat");
  10.     #endif

After that, I was receiving an error that it couldn't write to the save folder, because it was trying to use an invalid location. I had to fix it so that it was saving games in the correct place by changing MakeSaveGameDir in Engine/ac/game.cpp.

Code: C++
  1. bool MakeSaveGameDir(const String &newFolder, ResolvedPath &rp)
  2. {
  3. ...
  5.   base_dir = PathOrCurDir(platform->GetUserSavedgamesDirectory());
  6.   newSaveGameDir.Format("%s/%s", base_dir.GetCStr(), game.saveGameFolderName);
  7. #else
  8.     if (newSaveGameDir.CompareLeft(UserSavedgamesRootToken, UserSavedgamesRootToken.GetLength()) == 0)
  9. ...

After that, I updated platform/iOS/acplios.cpp to add the virtual overrides for all of the Get*Directory methods and have them return ios_document_directory.

Anyway, it's all working now. I just to make some tweaks, like hiding the Quit button if the OS is iOS. I'm also going to disable the keyboard handling since I don't need it, and I'm going to change long press to right-click instead.

Re: Building for iOS?
« Reply #4 on: 21 Nov 2019, 17:00 »
I should also mention, I had to make some tweaks to get the libraries to build native/fat libraries. (The fat libraries in the Janet repository give errors about missing architectures or bitcode errors when trying to build and run with Xcode 11.)

To get the libraries to build, I had to update all of the iOS/buildlib/{architecture}/ scripts to set the IOS_TARGET to "10.0"

For some reason, freetype doesn't download and then it tries to build it, so I had to manually download the correct version and drop it into the libsrc folder.

The version of Lua used no longer builds on IOS because of system, so I added this to the end of liblua.patch...

Code: Adventure Game Studio
  1.   --- src/luaconf.h     2008-02-11 11:25:08.000000000 -0500
  2.   +++ src/luaconf.h     2019-11-12 22:42:55.000000000 -0500
  3.   @@ -757,7 +757,11 @@
  4.    ** without modifying the main part of the file.
  5.    */
  7.   -
  8.   -
  9.   +#if defined(__APPLE__)
  10.   +     #include "TargetConditionals.h"
  12.   +         #define system(s) ((s)==NULL ? 0 : -1)
  13.   +     #endif // end iOS
  14.    #endif
  16.   +#endif

After that, I could run the and correctly, and am able to run the game on the simulators or devices without library architecture errors.