T2DAppDelegate.mm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #import "platformiOS/T2DAppDelegate.h"
  23. #include "platform/platformInput.h"
  24. #include "platformiOS/iOSUtil.h"
  25. #include "console/console.h"
  26. extern void _iOSGameInnerLoop();
  27. extern void _iOSGameResignActive();
  28. extern void _iOSGameBecomeActive();
  29. extern void _iOSGameWillTerminate();
  30. // Store current orientation for easy access
  31. extern void _iOSGameChangeOrientation(S32 newOrientation);
  32. UIDeviceOrientation currentOrientation;
  33. bool _iOSTorqueFatalError = false;
  34. @implementation T2DAppDelegate
  35. @synthesize window = _window;
  36. - (void)applicationDidFinishLaunching:(UIApplication *)application {
  37. [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
  38. //Also we set the currentRotation up so its not invalid
  39. currentOrientation = [UIDevice currentDevice].orientation;
  40. //So we make a selector to handle that, called didRotate (lower down in the code)
  41. [[NSNotificationCenter defaultCenter] addObserver:self
  42. selector:@selector(didRotate:)
  43. name:UIDeviceOrientationDidChangeNotification
  44. object:nil];
  45. }
  46. - (void)applicationWillResignActive:(UIApplication *)application
  47. {
  48. _iOSGameResignActive();
  49. }
  50. - (void)applicationDidEnterBackground:(UIApplication *)application
  51. {
  52. /*
  53. Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  54. If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  55. */
  56. }
  57. - (void)applicationWillEnterForeground:(UIApplication *)application
  58. {
  59. /*
  60. Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
  61. */
  62. }
  63. - (void)applicationDidBecomeActive:(UIApplication *)application
  64. {
  65. if(!_iOSTorqueFatalError)
  66. _iOSGameBecomeActive();
  67. }
  68. - (void)applicationWillTerminate:(UIApplication *)application
  69. {
  70. _iOSGameWillTerminate();
  71. [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
  72. }
  73. - (void)didRotate:(NSNotification *)notification
  74. {
  75. //Default to landscape left
  76. UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
  77. if(currentOrientation != orientation)
  78. {
  79. //Change the orientation
  80. currentOrientation = orientation;
  81. //Tell the rest of the engine
  82. _iOSGameChangeOrientation(currentOrientation);
  83. }
  84. }
  85. - (void) runMainLoop
  86. {
  87. _iOSGameInnerLoop();
  88. }
  89. @end