godot_view_renderer.mm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #include "core/os/keyboard.h"
  32. #include "core/project_settings.h"
  33. #include "main/main.h"
  34. #include "os_iphone.h"
  35. #include "servers/audio_server.h"
  36. #import <AudioToolbox/AudioServices.h>
  37. #import <CoreMotion/CoreMotion.h>
  38. #import <GameController/GameController.h>
  39. #import <QuartzCore/QuartzCore.h>
  40. #import <UIKit/UIKit.h>
  41. @interface GodotViewRenderer ()
  42. @property(assign, nonatomic) BOOL hasFinishedProjectDataSetup;
  43. @property(assign, nonatomic) BOOL hasStartedMain;
  44. @property(assign, nonatomic) BOOL hasFinishedSetup;
  45. @end
  46. @implementation GodotViewRenderer
  47. - (BOOL)setupView:(UIView *)view {
  48. if (self.hasFinishedSetup) {
  49. return NO;
  50. }
  51. if (!OS::get_singleton()) {
  52. exit(0);
  53. }
  54. if (!self.hasFinishedProjectDataSetup) {
  55. [self setupProjectData];
  56. return YES;
  57. }
  58. if (!self.hasStartedMain) {
  59. self.hasStartedMain = YES;
  60. OSIPhone::get_singleton()->start();
  61. return YES;
  62. }
  63. self.hasFinishedSetup = YES;
  64. return NO;
  65. }
  66. - (void)setupProjectData {
  67. self.hasFinishedProjectDataSetup = YES;
  68. Main::setup2();
  69. // this might be necessary before here
  70. NSDictionary *dict = [[NSBundle mainBundle] infoDictionary];
  71. for (NSString *key in dict) {
  72. NSObject *value = [dict objectForKey:key];
  73. String ukey = String::utf8([key UTF8String]);
  74. // we need a NSObject to Variant conversor
  75. if ([value isKindOfClass:[NSString class]]) {
  76. NSString *str = (NSString *)value;
  77. String uval = String::utf8([str UTF8String]);
  78. ProjectSettings::get_singleton()->set("Info.plist/" + ukey, uval);
  79. } else if ([value isKindOfClass:[NSNumber class]]) {
  80. NSNumber *n = (NSNumber *)value;
  81. double dval = [n doubleValue];
  82. ProjectSettings::get_singleton()->set("Info.plist/" + ukey, dval);
  83. };
  84. // do stuff
  85. }
  86. }
  87. - (void)renderOnView:(UIView *)view {
  88. if (!OSIPhone::get_singleton()) {
  89. return;
  90. }
  91. OSIPhone::get_singleton()->iterate();
  92. }
  93. @end