| 1 |
#import <UIKit/UIKit.h> |
| 2 |
#import "allegroAppDelegate.h" |
| 3 |
#include <allegro5/allegro.h> |
| 4 |
#include <allegro5/internal/aintern_iphone.h> |
| 5 |
#include <pthread.h> |
| 6 |
|
| 7 |
ALLEGRO_DEBUG_CHANNEL("iphone") |
| 8 |
|
| 9 |
/* Not that there could ever be any arguments on iphone... */ |
| 10 |
static int global_argc; |
| 11 |
static char **global_argv; |
| 12 |
extern int _al_mangled_main(int, char **); |
| 13 |
|
| 14 |
/* We run the user's "main" in its own thread. */ |
| 15 |
static void *user_main(ALLEGRO_THREAD *thread, void *arg) |
| 16 |
{ |
| 17 |
(void)thread; |
| 18 |
ALLEGRO_INFO("Starting user main.\n"); |
| 19 |
_al_mangled_main(global_argc, global_argv); |
| 20 |
ALLEGRO_INFO("User main has returned.\n"); |
| 21 |
ALLEGRO_SYSTEM_IPHONE *iphone = (void *)al_get_system_driver(); |
| 22 |
al_lock_mutex(iphone->mutex); |
| 23 |
iphone->has_shutdown = true; |
| 24 |
al_signal_cond(iphone->cond); |
| 25 |
al_unlock_mutex(iphone->mutex); |
| 26 |
/* Apple does not allow iphone applications to shutdown and provides |
| 27 |
* no API for it: |
| 28 |
* http://developer.apple.com/iphone/library/qa/qa2008/qa1561.html |
| 29 |
* |
| 30 |
* Therefore we only call exit here if the user actually returned from |
| 31 |
* there main - in that case crashing the app is better then freezing it. |
| 32 |
*/ |
| 33 |
if (!iphone->wants_shutdown) |
| 34 |
exit(0); /* "crash grazefully" */ |
| 35 |
return arg; |
| 36 |
} |
| 37 |
|
| 38 |
/* There really is no point running the user main before the application |
| 39 |
* has finished launching, so this function is called back when we receive |
| 40 |
* the applicationDidFinishLaunching message. |
| 41 |
*/ |
| 42 |
void _al_iphone_run_user_main(void) |
| 43 |
{ |
| 44 |
ALLEGRO_THREAD *thread = al_create_thread(user_main, NULL); |
| 45 |
al_start_thread(thread); |
| 46 |
} |
| 47 |
|
| 48 |
void _al_iphone_init_path(void) |
| 49 |
{ |
| 50 |
/* On iphone, data always can only be in the resource bundle. So we set |
| 51 |
* the initial path to that. As each app is sandboxed, there is not much |
| 52 |
* else to access anyway. |
| 53 |
*/ |
| 54 |
NSFileManager *fm = [NSFileManager defaultManager]; |
| 55 |
NSBundle *mainBundle = [NSBundle mainBundle]; |
| 56 |
NSString *string = [mainBundle resourcePath]; |
| 57 |
[fm changeCurrentDirectoryPath:string]; |
| 58 |
} |
| 59 |
|
| 60 |
int main(int argc, char **argv) { |
| 61 |
global_argc = argc; |
| 62 |
global_argv = argv; |
| 63 |
[allegroAppDelegate run:argc:argv]; |
| 64 |
ASSERT(false); /* can never reach */ |
| 65 |
return 0; |
| 66 |
} |