godot_view_renderer.mm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**************************************************************************/
  2. /* godot_view_renderer.mm */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #import "godot_view_renderer.h"
  31. #import "display_server_ios.h"
  32. #import "os_ios.h"
  33. #include "core/config/project_settings.h"
  34. #include "core/os/keyboard.h"
  35. #include "main/main.h"
  36. #include "servers/audio_server.h"
  37. #import <AudioToolbox/AudioServices.h>
  38. #import <CoreMotion/CoreMotion.h>
  39. #import <GameController/GameController.h>
  40. #import <QuartzCore/QuartzCore.h>
  41. #import <UIKit/UIKit.h>
  42. @interface GodotViewRenderer ()
  43. @property(assign, nonatomic) BOOL hasFinishedProjectDataSetup;
  44. @property(assign, nonatomic) BOOL hasStartedMain;
  45. @property(assign, nonatomic) BOOL hasFinishedSetup;
  46. @end
  47. @implementation GodotViewRenderer
  48. - (BOOL)setupView:(UIView *)view {
  49. if (self.hasFinishedSetup) {
  50. return NO;
  51. }
  52. if (!OS::get_singleton()) {
  53. exit(0);
  54. }
  55. if (!self.hasFinishedProjectDataSetup) {
  56. [self setupProjectData];
  57. return YES;
  58. }
  59. if (!self.hasStartedMain) {
  60. self.hasStartedMain = YES;
  61. OS_IOS::get_singleton()->start();
  62. return YES;
  63. }
  64. self.hasFinishedSetup = YES;
  65. return NO;
  66. }
  67. - (void)setupProjectData {
  68. self.hasFinishedProjectDataSetup = YES;
  69. Main::setup2();
  70. // this might be necessary before here
  71. NSDictionary *dict = [[NSBundle mainBundle] infoDictionary];
  72. for (NSString *key in dict) {
  73. NSObject *value = [dict objectForKey:key];
  74. String ukey = String::utf8([key UTF8String]);
  75. // we need a NSObject to Variant conversor
  76. if ([value isKindOfClass:[NSString class]]) {
  77. NSString *str = (NSString *)value;
  78. String uval = String::utf8([str UTF8String]);
  79. ProjectSettings::get_singleton()->set("Info.plist/" + ukey, uval);
  80. } else if ([value isKindOfClass:[NSNumber class]]) {
  81. NSNumber *n = (NSNumber *)value;
  82. double dval = [n doubleValue];
  83. ProjectSettings::get_singleton()->set("Info.plist/" + ukey, dval);
  84. }
  85. // do stuff
  86. }
  87. }
  88. - (void)renderOnView:(UIView *)view {
  89. if (!OS_IOS::get_singleton()) {
  90. return;
  91. }
  92. OS_IOS::get_singleton()->iterate();
  93. }
  94. @end