Building for iOS?

Started by robcolton, Tue 19/11/2019 03:50:44

Previous topic - Next topic

robcolton

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: ags
Expected unqualified-id glad.h in file ali3dogl.cpp
Expanded from macro 'GLAD_GL_VERSION_2_0'

Expected ')' in file ali3dogl.cpp
Expanded from macro 'GLAD_GL_VERSION_2_0'
To match this '('


I think it's related to ogl_headers.h, where it defines GLAD_GL_VERSION_2_0
Code: ags
#ifndef GLAPI
#define GLAD_GL_VERSION_2_0 (0)
#endif


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

Any pointers in the right direction would be appreciated!

Rob

robcolton

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: cpp
#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

#2
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.

robcolton

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: cpp

#if AGS_PLATFORM_OS_IOS
// override packfile functions to allow it to load from our
// custom CLIB datafiles
extern "C" {
    PACKFILE*_my_temppack;
#if ALLEGRO_DATE > 19991010
#define PFO_PARAM const char *
#else
#define PFO_PARAM char *
#endif
#if !defined(AGS_RUNTIME_PATCH_ALLEGRO)
    extern PACKFILE *__old_pack_fopen(PFO_PARAM,PFO_PARAM);
#endif
}

PACKFILE *pack_fopen(const char *filename, const char *mode)
{
    return __old_pack_fopen(filename, mode);
}
#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: cpp

    #if defined (IOS_VERSION)
        //JG
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Rogue"
                                                             ofType:@"ags"];
        const char * resourceChars = [filePath UTF8String];
        strcpy(filename, resourceChars);
    #else
        strcpy(filename, path);
        strcat(filename, "ac2game.dat");
    #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: cpp

bool MakeSaveGameDir(const String &newFolder, ResolvedPath &rp)
{
...
#if AGS_PLATFORM_OS_IOS
  base_dir = PathOrCurDir(platform->GetUserSavedgamesDirectory());
  newSaveGameDir.Format("%s/%s", base_dir.GetCStr(), game.saveGameFolderName);
#else
    if (newSaveGameDir.CompareLeft(UserSavedgamesRootToken, UserSavedgamesRootToken.GetLength()) == 0)
...


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.


robcolton

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}/setenv.sh 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: ags

  --- src/luaconf.h	2008-02-11 11:25:08.000000000 -0500
  +++ src/luaconf.h	2019-11-12 22:42:55.000000000 -0500
  @@ -757,7 +757,11 @@
   ** without modifying the main part of the file.
   */

  -
  -
  +#if defined(__APPLE__)
  +     #include "TargetConditionals.h"
  +     #if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV
  +         #define system(s) ((s)==NULL ? 0 : -1)
  +     #endif // end iOS
   #endif

  +#endif


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

SMF spam blocked by CleanTalk