Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS port fixes and Xcode project improvements #2259

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Common/core/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
#define AGS_SEARCH_FOR_GAME_ON_LAUNCH (AGS_PLATFORM_OS_WINDOWS || \
AGS_PLATFORM_OS_LINUX || \
AGS_PLATFORM_OS_MACOS || \
AGS_PLATFORM_OS_IOS || \
AGS_PLATFORM_OS_EMSCRIPTEN || \
AGS_PLATFORM_OS_FREEBSD )

Expand Down
8 changes: 6 additions & 2 deletions Engine/gfx/ali3dogl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,15 @@ bool OGLGraphicsDriver::CreateWindowAndGlContext(const DisplayMode &mode)
if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1) != 0)
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Error occured setting attribute SDL_GL_CONTEXT_MINOR_VERSION: %s", SDL_GetError());
#endif
#if AGS_PLATFORM_OS_IOS
// minimum number of bits for the depth buffer
if (SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0) != 0)
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Error occured setting attribute SDL_GL_DEPTH_SIZE: %s", SDL_GetError());
#endif
if (SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8) != 0 ||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8) != 0 ||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8) != 0)
{
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Error occured setting one of the attributes SDL_GL_(RED|GREEN| BLUE)_SIZE: %s", SDL_GetError());
}
if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) != 0)
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Error occured setting attribute SDL_GL_DOUBLEBUFFER: %s", SDL_GetError());

Expand Down
3 changes: 3 additions & 0 deletions Engine/platform/base/sys_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ SDL_Window *sys_window_create(const char *window_title, int w, int h, WindowMode
#if (AGS_PLATFORM_MOBILE)
// Resizable flag is necessary for fullscreen app rotation
flags |= SDL_WINDOW_RESIZABLE;
#endif
#if (AGS_PLATFORM_OS_IOS)
flags |= SDL_WINDOW_ALLOW_HIGHDPI;
#endif
window = SDL_CreateWindow(
window_title,
Expand Down
15 changes: 5 additions & 10 deletions Engine/platform/ios/acplios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void setStringConfigValue(int id, const char* value)
int getAvailableTranslations(char* translations)
{
int i = 0;
int length;
size_t length;
DIR* dir;
struct dirent* entry;
char buffer[200];
Expand Down Expand Up @@ -267,9 +267,6 @@ int getAvailableTranslations(char* translations)
return i;
}

//extern void ios_show_message_box(char* buffer);
volatile int ios_wait_for_ui = 0;


void startEngine(char* filename, char* directory, int loadLastSave)
{
Expand All @@ -288,7 +285,7 @@ void startEngine(char* filename, char* directory, int loadLastSave)
// Get the games path.
char path[256];
strcpy(path, setup.game_file_name.GetCStr());
int lastindex = strlen(path) - 1;
size_t lastindex = strlen(path) - 1;
while (path[lastindex] != '/')
{
path[lastindex] = 0;
Expand Down Expand Up @@ -359,15 +356,13 @@ void AGSIOS::DisplayAlert(const char *text, ...) {
va_start(ap, text);
vsnprintf(displbuf, 2000, text, ap);
va_end(ap);
printf("%s", displbuf);
// ios_show_message_box(displbuf);

//while (ios_wait_for_ui)
// usleep(200);
Debug::Printf(kDbgMsg_Warn, "%s", displbuf);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, nullptr, displbuf, nullptr);
}

void AGSIOS::Delay(int millis) {
usleep(millis);
Copy link
Contributor Author

@edmundito edmundito Dec 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this was incorrect the whole time because usleep accepts seconds and not milliseconds, so a conversion was needed. The SDL Implementation uses the best option for the platform and takes milliseconds as the input.

SDL_Delay(millis);
}

unsigned long AGSIOS::GetDiskFreeSpaceMB() {
Expand Down
22 changes: 6 additions & 16 deletions Plugins/agstouch/agstouch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,15 @@ Helper functions for touch devices

#include "plugin/agsplugin.h"

#include <SDL.h>

#if defined(BUILTIN_PLUGINS)
namespace agstouch {
#endif

IAGSEngine* engine;


#if defined(IOS_VERSION)

extern "C"
{
void ios_show_keyboard();
void ios_hide_keyboard();
int ios_is_keyboard_visible();
}

#endif



// ********************************************
// ************ AGS Interface ***************
Expand All @@ -46,23 +36,23 @@ extern "C"
void TouchShowKeyboard()
{
#if defined(IOS_VERSION)
ios_show_keyboard();
SDL_StartTextInput();
#endif
}


void TouchHideKeyboard()
{
#if defined(IOS_VERSION)
ios_hide_keyboard();
SDL_StopTextInput();
#endif
}


bool TouchIsKeyboardVisible()
{
#if defined(IOS_VERSION)
return (ios_is_keyboard_visible() != 0);
return SDL_IsTextInputActive();
#else
return false;
#endif
Expand Down Expand Up @@ -164,5 +154,5 @@ void AGS_EditorLoadGame(char* buffer, int bufsize)


#if defined(BUILTIN_PLUGINS)
}
} // namespace agstouch
#endif
2 changes: 1 addition & 1 deletion Plugins/agstouch/agstouch.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ namespace agstouch
void AGS_EngineInitGfx(const char *driverID, void *data);
}

#endif
#endif
69 changes: 66 additions & 3 deletions iOS/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# AGS for iOS

This port was initally done by JJS, when the backend was Allegro4. Currently, it uses SDL2.

iOS thread on the AGS forum: https://www.adventuregamestudio.co.uk/forums/index.php?topic=46040.0

## Building
Expand All @@ -13,6 +11,71 @@ To do this, navigate to it and run the `./download.sh` script there.

After the script is ran, open Xcode and load the project in `<SOURCE>/iOS/xcode/ags/ags.xcodeproj`.

The iOS AGS app is all contained in a single Xcode project.
The iOS AGS app is all contained in a single Xcode project. It currently embeds SDL as a subproject
downloaded by `./download.sh` and located in the in the `/libsrc` folder.

## Preparing game

1. Copy the game files to `iOS/Resources`: `game.ags`, `speech.vox`, `audio.vox`, and any other files related to the game (e.g. Lip Sync)
2. Add additional files to `AGS/Resources`` in the Xcode project
3. Select the target "AGS Game" in the AGS project
4. Edit the Identity section (Category, Display Name, bundle identifier, and version)
5. Under Build Phases -> Copy Bundle Resources, add additional game resources that need to be embedded with the game, the ones that were added to `AGS/Resources` (e.g. Lip Sync files)
4. Build and run the AGS Game target on the simulator or device!
5. Modify the `AGS/Resources/ios.cfg` file to make game setup changes (see below)

You may also need to manually assign a launch screen and game icons the way you normally would for an iOS app.

## Game setup config file

The configuration file is similar, but unique to mobile and iOS devices and may differ from the configuration for Windows/Linux builds. Here's an explanation of all the settings:

```ini
[misc]
config_enabled = 1 ; Enable or disable config. If disabled, only translation config is read, default 0
rotation = 1 ; Set game rotation (0 = unlocked, 1 = force portrait, 2 = force landscape), default 0
translation = default ; (string) Translation to use, default "default"
[controls]
mouse_emulation = 1 ; 0 = off, 1 = one finger (hold, drag), 2 = two fingers (tap), default 1
mouse_method = 0 ; Mouse emulation method (0 = absolute, 1 = relative), default 0
mouse_speed = 1.0 ; Mouse speed in relative mode, default 10
[compatibility]
clear_cache_on_room_change = 0 ; For low-end devices, clear the cache when changing rooms (1 = enabled), default 0
[sound]
enabled = 1 ; Enable sound, default 0,
cache_size = 64 ; Sound cache size in bytes, default 32 * 1024
[video]
framedrop = 0 ; Video framedrop, default 0
[graphics]
renderer = 1 ; Renderer type (0 = Software, 1 = Render to screen, 2 = Render to texture), default 0
smoothing = 0 ; Scale smoothing (0 = nearest-neighbor, linear) enabled, default 0,
scaling = 1 ; Scaling style (0 = none, 1 = stretch and preserve aspect ratio, 2 stretch to whole screen), default 0
super_sampling = 0 ; Super sampling (only if renderer = 1 or 2) (0 = x1, 1 = x2), default 0,
smooth_sprites = 0 ; Sprite anti-aliasing, default 0
[debug]
show_fps = 0 ; Show FPS overlay while running the game, default 0
logging = 0 ; Write logging to logcat, default 0
```

## Embedded plugins

The AGS iOS build will provide ports for existing AGS plugins built right into the library:

* Snow/Rain
* Parallax
* Flashlight
* Touch

The Touch plugin is specific to the iOS build and allows the option to pull
the virtual keyboard with the following calls in a game script:

```agsscript
// Shows the virtual keyboard
import void TouchShowKeyboard();

// Hides the virtual keyboard
import void TouchHideKeyboard();

// Returns true or false if the virtual keyboard is visible
import bool TouchIsKeyboardVisible();
```
Loading