iphone_delegate.mm 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. Copyright (C) 2009-2011 id Software LLC, a ZeniMax Media company.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #import "iphone_delegate.h"
  16. #import <AudioToolbox/AudioServices.h>
  17. #include "doomiphone.h"
  18. #include "iphone_common.h"
  19. #include "ios/InAppStore.h"
  20. #include "ios/GameCenter.h"
  21. @implementation iphoneApp
  22. @synthesize window;
  23. iphoneApp * gAppDelegate = NULL;
  24. bool inBackgroundProcess = false;
  25. touch_t sysTouches[MAX_TOUCHES];
  26. touch_t gameTouches[MAX_TOUCHES];
  27. #define FRAME_HERTZ 30.0f
  28. const static float ACCELEROMETER_UPDATE_INTERVAL = 1.0f / FRAME_HERTZ;
  29. /*
  30. ========================
  31. applicationDidFinishLaunching
  32. ========================
  33. */
  34. - (void)applicationDidFinishLaunching:(UIApplication *)application {
  35. gAppDelegate = self;
  36. inBackgroundProcess = false;
  37. hasPushedGLView = NO;
  38. // Create the window programmatically instead of loading from a nib file.
  39. self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
  40. // Disable Screen Dimming.
  41. [[ UIApplication sharedApplication] setIdleTimerDisabled: YES ];
  42. // Initial Application Style config.
  43. [ application setStatusBarHidden: YES ];
  44. // start the flow of accelerometer events
  45. UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];
  46. [ accelerometer setDelegate: self ];
  47. [ accelerometer setUpdateInterval: ACCELEROMETER_UPDATE_INTERVAL ];
  48. [self InitializeInterfaceBuilder ];
  49. CommonSystemSetup( [navigationController topViewController] );
  50. // do all the game startup work
  51. iphoneStartup();
  52. UIView * view = navigationController.view;
  53. [window addSubview: view];
  54. [window setRootViewController:navigationController];
  55. [window setBackgroundColor: [UIColor blackColor] ];
  56. [window makeKeyAndVisible];
  57. }
  58. /*
  59. ========================
  60. applicationWillResignActive
  61. ========================
  62. */
  63. - (void)applicationWillResignActive:(UIApplication *)application {
  64. inBackgroundProcess = YES;
  65. idGameCenter::HandleMoveToBackground();
  66. // If we're in a multiplater game, and showing the OpenGL view,
  67. // go back to the main menu since the multiplayer game is hosed.
  68. if ( netgame && navigationController.topViewController == gAppDelegate->openGLViewController ) {
  69. iphoneMainMenu();
  70. }
  71. iphonePauseMusic();
  72. iphoneShutdown();
  73. }
  74. /*
  75. ========================
  76. applicationDidBecomeActive
  77. ========================
  78. */
  79. - (void)applicationDidBecomeActive:(UIApplication *)application {
  80. inBackgroundProcess = NO;
  81. }
  82. /*
  83. ========================
  84. applicationWillTerminate
  85. ========================
  86. */
  87. - (void)applicationWillTerminate:(UIApplication *)application {
  88. iphoneStopMusic();
  89. iphoneShutdown();
  90. }
  91. /*
  92. ========================
  93. applicationDidReceiveMemoryWarning
  94. ========================
  95. */
  96. - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
  97. Com_Printf( "applicationDidReceiveMemoryWarning\n" );
  98. }
  99. /*
  100. ========================
  101. dealloc
  102. ========================
  103. */
  104. - (void)dealloc {
  105. [window release];
  106. [super dealloc];
  107. }
  108. /*
  109. ========================
  110. accelerometer
  111. ========================
  112. */
  113. - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
  114. {
  115. float acc[4];
  116. acc[0] = acceleration.x;
  117. acc[1] = acceleration.y;
  118. acc[2] = acceleration.z;
  119. acc[3] = acceleration.timestamp;
  120. iphoneTiltEvent( acc );
  121. }
  122. /*
  123. ========================
  124. HACK_PushController - Removes Flicker from Loading Wads.
  125. God forgive me.
  126. ========================
  127. */
  128. - (void) HACK_PushController {
  129. [navigationController pushViewController:openGLViewController animated:NO];
  130. }
  131. /*
  132. ========================
  133. ShowGLView
  134. ========================
  135. */
  136. - (void)ShowGLView {
  137. if( hasPushedGLView == NO ) {
  138. hasPushedGLView = YES;
  139. // Hack city.
  140. [NSTimer scheduledTimerWithTimeInterval:0.2f target:self selector:@selector(HACK_PushController) userInfo:nil repeats:NO];
  141. [ openGLViewController StartDisplay ];
  142. }
  143. }
  144. /*
  145. ========================
  146. HideGLView
  147. ========================
  148. */
  149. - (void) HideGLView {
  150. [ navigationController popToRootViewControllerAnimated:NO ];
  151. hasPushedGLView = NO;
  152. }
  153. /*
  154. ========================
  155. PopGLView
  156. ========================
  157. */
  158. - (void) PopGLView {
  159. [ navigationController popViewControllerAnimated:NO];
  160. hasPushedGLView = NO;
  161. }
  162. /*
  163. ========================
  164. InitializeInterfaceBuilder
  165. ========================
  166. */
  167. - (void) InitializeInterfaceBuilder {
  168. }
  169. @end
  170. void ShowGLView( void ) {
  171. [ gAppDelegate ShowGLView ];
  172. }