cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m
changeset 2691 c0da3a98c01c
parent 2689 dfda97c153a4
child 2692 ce9992075118
equal deleted inserted replaced
2690:8e83c7e31720 2691:c0da3a98c01c
    18  
    18  
    19  Sam Lantinga, mods for Hedgewars by Vittorio Giovara
    19  Sam Lantinga, mods for Hedgewars by Vittorio Giovara
    20  slouken@libsdl.org, vittorio.giovara@gmail.com
    20  slouken@libsdl.org, vittorio.giovara@gmail.com
    21 */
    21 */
    22 
    22 
       
    23 #import <pthread.h>
    23 #import "SDL_uikitappdelegate.h"
    24 #import "SDL_uikitappdelegate.h"
    24 #import "SDL_uikitopenglview.h"
    25 #import "SDL_uikitopenglview.h"
    25 #import "SDL_events_c.h"
    26 #import "SDL_events_c.h"
    26 #import "jumphack.h"
    27 #import "jumphack.h"
    27 #import "SDL_video.h"
    28 #import "SDL_video.h"
       
    29 #import "gameSetup.h"
    28 
    30 
    29 #ifdef main
    31 #ifdef main
    30 #undef main
    32 #undef main
    31 #endif
    33 #endif
    32 
    34 
    33 extern int SDL_main(int argc, char *argv[]);
    35 extern int SDL_main(int argc, char *argv[]);
    34 static int forward_argc;
       
    35 static char **forward_argv;
       
    36 
    36 
    37 int main (int argc, char **argv) {
    37 int main (int argc, char **argv) {
    38 	int i;
    38 	int i;
    39 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    39 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    40 	
    40 	
    60 +(SDLUIKitDelegate *)sharedAppDelegate {
    60 +(SDLUIKitDelegate *)sharedAppDelegate {
    61 	/* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */
    61 	/* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */
    62 	return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate];
    62 	return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate];
    63 }
    63 }
    64 
    64 
       
    65 
    65 - (void) startSDLgame {
    66 - (void) startSDLgame {
       
    67 	pthread_t threadID;
    66 
    68 
       
    69 	pthread_create (&threadID, NULL, (void *) (*engineProtocolThread), NULL);
       
    70 	pthread_detach (threadID);
       
    71 
       
    72 	setupArgsForLocalPlay();
       
    73 	
    67 	/* run the user's application, passing argc and argv */
    74 	/* run the user's application, passing argc and argv */
    68 	NSLog(@"Game is launching");
    75 	NSLog(@"Game is launching...");
    69 	SDL_main(forward_argc, forward_argv);
    76 	SDL_main(forward_argc, forward_argv);
    70 	// can't reach here yet
    77 	// can't reach here yet
    71 	NSLog(@"Game exited");
    78 	NSLog(@"Game exited");
    72 
    79 
    73 	//[self performSelector:@selector(makeNewView) withObject:nil afterDelay:0.0];
    80 	//[self performSelector:@selector(makeNewView) withObject:nil afterDelay:0.0];
    85 //	SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]];
    92 //	SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]];
    86 //	SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]];
    93 //	SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]];
    87 	
    94 	
    88 	[window addSubview:controller.view];
    95 	[window addSubview:controller.view];
    89 	[window makeKeyAndVisible];
    96 	[window makeKeyAndVisible];
       
    97 	
       
    98 	// REMOVE ME when you're done with reverse engineering the protocol
       
    99 	[self performSelector:@selector(startSDLgame)];
    90 }
   100 }
    91 
   101 
    92 -(void) applicationWillTerminate:(UIApplication *)application {
   102 -(void) applicationWillTerminate:(UIApplication *)application {
    93 	/* free the memory we used to hold copies of argc and argv */
   103 	/* free the memory we used to hold copies of argc and argv */
    94 	int i;
   104 	int i;