Debian Codegraph @

drivers/apple_embedded/godot_view_renderer.mm

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