summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/ustring.cpp5
-rw-r--r--doc/classes/CanvasItem.xml2
-rw-r--r--doc/classes/Node3D.xml2
-rw-r--r--editor/animation_track_editor.cpp2
-rw-r--r--editor/editor_audio_buses.cpp2
-rw-r--r--editor/editor_inspector.cpp10
-rw-r--r--editor/editor_spin_slider.cpp2
-rw-r--r--editor/import/editor_scene_importer_gltf.cpp18
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp10
-rw-r--r--misc/dist/ios_xcode/godot_ios.xcodeproj/project.pbxproj4
-rw-r--r--modules/arkit/arkit_interface.h13
-rw-r--r--modules/arkit/arkit_interface.mm12
-rw-r--r--modules/bullet/bullet_types_converter.cpp14
-rw-r--r--modules/camera/camera_ios.mm24
-rw-r--r--modules/gdscript/doc_classes/@GDScript.xml2
-rw-r--r--modules/mono/mono_gd/support/ios_support.mm3
-rw-r--r--platform/iphone/SCsub2
-rw-r--r--platform/iphone/app_delegate.mm3
-rw-r--r--platform/iphone/detect.py4
-rw-r--r--platform/iphone/device_metrics.h37
-rw-r--r--platform/iphone/device_metrics.m152
-rw-r--r--platform/iphone/display_layer.mm3
-rw-r--r--platform/iphone/display_server_iphone.mm185
-rw-r--r--platform/iphone/game_center.mm17
-rw-r--r--platform/iphone/godot_iphone.mm4
-rw-r--r--platform/iphone/godot_view.mm18
-rw-r--r--platform/iphone/godot_view_gesture_recognizer.mm7
-rw-r--r--platform/iphone/icloud.mm14
-rw-r--r--platform/iphone/in_app_store.mm41
-rw-r--r--platform/iphone/ios.mm19
-rw-r--r--platform/iphone/joypad_iphone.mm101
-rw-r--r--platform/iphone/native_video_view.h41
-rw-r--r--platform/iphone/native_video_view.m260
-rw-r--r--platform/iphone/os_iphone.mm5
-rw-r--r--platform/iphone/platform_config.h7
-rw-r--r--platform/iphone/view_controller.h8
-rw-r--r--platform/iphone/view_controller.mm209
-rw-r--r--platform/iphone/vulkan_context_iphone.mm6
-rw-r--r--platform/javascript/SCsub1
-rw-r--r--platform/javascript/audio_driver_javascript.cpp248
-rw-r--r--platform/javascript/audio_driver_javascript.h19
-rw-r--r--platform/javascript/detect.py1
-rw-r--r--platform/javascript/export/export.cpp3
-rw-r--r--platform/javascript/godot_audio.h58
-rw-r--r--platform/javascript/native/library_godot_audio.js173
-rw-r--r--scene/2d/light_2d.cpp3
-rw-r--r--scene/3d/collision_shape_3d.cpp15
-rw-r--r--scene/3d/navigation_region_3d.cpp4
-rw-r--r--scene/3d/node_3d.cpp34
-rw-r--r--scene/3d/node_3d.h8
-rw-r--r--scene/3d/physics_body_3d.cpp4
-rw-r--r--scene/3d/soft_body_3d.cpp2
-rw-r--r--scene/gui/box_container.cpp8
-rw-r--r--scene/gui/center_container.cpp4
-rw-r--r--scene/gui/color_picker.cpp2
-rw-r--r--scene/gui/control.cpp22
-rw-r--r--scene/gui/dialogs.cpp4
-rw-r--r--scene/gui/graph_edit.cpp2
-rw-r--r--scene/gui/graph_node.cpp10
-rw-r--r--scene/gui/margin_container.cpp4
-rw-r--r--scene/gui/panel_container.cpp4
-rw-r--r--scene/gui/popup.cpp4
-rw-r--r--scene/gui/scroll_container.cpp6
-rw-r--r--scene/gui/split_container.cpp2
-rw-r--r--scene/gui/tab_container.cpp4
-rw-r--r--scene/main/canvas_item.cpp36
-rw-r--r--scene/main/canvas_item.h8
-rw-r--r--scene/main/viewport.cpp22
68 files changed, 1111 insertions, 872 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp
index d5afbc2b47..0033c31e20 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -4484,11 +4484,12 @@ String String::sprintf(const Array &values, bool *error) const {
int number_len = str.length();
// Padding.
+ int pad_chars_count = (value < 0 || show_sign) ? min_chars - 1 : min_chars;
String pad_char = pad_with_zeroes ? String("0") : String(" ");
if (left_justified) {
- str = str.rpad(min_chars, pad_char);
+ str = str.rpad(pad_chars_count, pad_char);
} else {
- str = str.lpad(min_chars, pad_char);
+ str = str.lpad(pad_chars_count, pad_char);
}
// Sign.
diff --git a/doc/classes/CanvasItem.xml b/doc/classes/CanvasItem.xml
index 2440a0e648..d36a997330 100644
--- a/doc/classes/CanvasItem.xml
+++ b/doc/classes/CanvasItem.xml
@@ -607,7 +607,7 @@
<member name="show_behind_parent" type="bool" setter="set_draw_behind_parent" getter="is_draw_behind_parent_enabled" default="false">
If [code]true[/code], the object draws behind its parent.
</member>
- <member name="toplevel" type="bool" setter="set_as_toplevel" getter="is_set_as_toplevel">
+ <member name="top_level" type="bool" setter="set_as_top_level" getter="is_set_as_top_level">
If [code]true[/code], the node will not inherit its transform from parent [CanvasItem]s.
</member>
<member name="show_on_top" type="bool" setter="_set_on_top" getter="_is_on_top">
diff --git a/doc/classes/Node3D.xml b/doc/classes/Node3D.xml
index 86451b5573..af4f18c5f7 100644
--- a/doc/classes/Node3D.xml
+++ b/doc/classes/Node3D.xml
@@ -301,7 +301,7 @@
<member name="scale" type="Vector3" setter="set_scale" getter="get_scale" default="Vector3( 1, 1, 1 )">
Scale part of the local transformation.
</member>
- <member name="toplevel" type="bool" setter="set_as_toplevel" getter="is_set_as_toplevel">
+ <member name="top_level" type="bool" setter="set_as_top_level" getter="is_set_as_top_level">
If [code]true[/code], the node will not inherit its transformations from its parent. Node transformations are only in global space.
</member>
<member name="transform" type="Transform" setter="set_transform" getter="get_transform" default="Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )">
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp
index 39e863ae0f..52c984cbc0 100644
--- a/editor/animation_track_editor.cpp
+++ b/editor/animation_track_editor.cpp
@@ -5758,7 +5758,7 @@ AnimationTrackEditor::AnimationTrackEditor() {
box_selection = memnew(Control);
add_child(box_selection);
- box_selection->set_as_toplevel(true);
+ box_selection->set_as_top_level(true);
box_selection->set_mouse_filter(MOUSE_FILTER_IGNORE);
box_selection->hide();
box_selection->connect("draw", callable_mp(this, &AnimationTrackEditor::_box_selection_draw));
diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp
index adb09532eb..a3deb95130 100644
--- a/editor/editor_audio_buses.cpp
+++ b/editor/editor_audio_buses.cpp
@@ -846,7 +846,7 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
audioprev_hbc->add_child(audio_value_preview_label);
slider->add_child(audio_value_preview_box);
- audio_value_preview_box->set_as_toplevel(true);
+ audio_value_preview_box->set_as_top_level(true);
Ref<StyleBoxFlat> panel_style = memnew(StyleBoxFlat);
panel_style->set_bg_color(Color(0.0f, 0.0f, 0.0f, 0.8f));
audio_value_preview_box->add_theme_style_override("panel", panel_style);
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 2e716a636e..9900e8184d 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -48,7 +48,7 @@ Size2 EditorProperty::get_minimum_size() const {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
if (!c->is_visible()) {
@@ -117,7 +117,7 @@ void EditorProperty::_notification(int p_what) {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
if (c == bottom_editor) {
@@ -179,7 +179,7 @@ void EditorProperty::_notification(int p_what) {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
if (c == bottom_editor) {
@@ -1133,7 +1133,7 @@ void EditorInspectorSection::_notification(int p_what) {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
if (!c->is_visible_in_tree()) {
@@ -1225,7 +1225,7 @@ Size2 EditorInspectorSection::get_minimum_size() const {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
if (!c->is_visible()) {
diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp
index ac61a75a6c..efc966c6c4 100644
--- a/editor/editor_spin_slider.cpp
+++ b/editor/editor_spin_slider.cpp
@@ -483,7 +483,7 @@ EditorSpinSlider::EditorSpinSlider() {
grabber = memnew(TextureRect);
add_child(grabber);
grabber->hide();
- grabber->set_as_toplevel(true);
+ grabber->set_as_top_level(true);
grabber->set_mouse_filter(MOUSE_FILTER_STOP);
grabber->connect("mouse_entered", callable_mp(this, &EditorSpinSlider::_grabber_mouse_entered));
grabber->connect("mouse_exited", callable_mp(this, &EditorSpinSlider::_grabber_mouse_exited));
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp
index 8caa4aeeaf..f4171eda32 100644
--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -379,13 +379,21 @@ Error EditorSceneImporterGLTF::_parse_buffers(GLTFState &state, const String &p_
Vector<uint8_t> buffer_data;
String uri = buffer["uri"];
- if (uri.findn("data:application/octet-stream;base64") == 0) {
- //embedded data
+ if (uri.begins_with("data:")) { // Embedded data using base64.
+ // Validate data MIME types and throw an error if it's one we don't know/support.
+ // Could be an importer bug on our side or a broken glTF file.
+ // Ref: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#file-extensions-and-mime-types
+ if (!uri.begins_with("data:application/octet-stream;base64") &&
+ !uri.begins_with("data:application/gltf-buffer;base64") &&
+ !uri.begins_with("data:image/jpeg;base64") &&
+ !uri.begins_with("data:image/png;base64")) {
+ ERR_PRINT("glTF file contains buffer with an unknown URI data type: " + uri);
+ }
buffer_data = _parse_base64_uri(uri);
- } else {
- uri = p_base_path.plus_file(uri).replace("\\", "/"); //fix for windows
+ } else { // Should be a relative file path.
+ uri = p_base_path.plus_file(uri).replace("\\", "/"); // Fix for Windows.
buffer_data = FileAccess::get_file_as_array(uri);
- ERR_FAIL_COND_V(buffer.size() == 0, ERR_PARSE_ERROR);
+ ERR_FAIL_COND_V_MSG(buffer.size() == 0, ERR_PARSE_ERROR, "Couldn't load binary file as an array: " + uri);
}
ERR_FAIL_COND_V(!buffer.has("byteLength"), ERR_PARSE_ERROR);
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 470d19e65a..c06580df26 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -548,7 +548,7 @@ void CanvasItemEditor::_expand_encompassing_rect_using_children(Rect2 &r_rect, c
const CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
- if (canvas_item && !canvas_item->is_set_as_toplevel()) {
+ if (canvas_item && !canvas_item->is_set_as_top_level()) {
_expand_encompassing_rect_using_children(r_rect, p_node->get_child(i), r_first, p_parent_xform * canvas_item->get_transform(), p_canvas_xform);
} else {
const CanvasLayer *canvas_layer = Object::cast_to<CanvasLayer>(p_node);
@@ -591,7 +591,7 @@ void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_no
for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
if (canvas_item) {
- if (!canvas_item->is_set_as_toplevel()) {
+ if (!canvas_item->is_set_as_top_level()) {
_find_canvas_items_at_pos(p_pos, p_node->get_child(i), r_items, p_parent_xform * canvas_item->get_transform(), p_canvas_xform);
} else {
_find_canvas_items_at_pos(p_pos, p_node->get_child(i), r_items, canvas_item->get_transform(), p_canvas_xform);
@@ -767,7 +767,7 @@ void CanvasItemEditor::_find_canvas_items_in_rect(const Rect2 &p_rect, Node *p_n
if (!lock_children || !editable) {
for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
if (canvas_item) {
- if (!canvas_item->is_set_as_toplevel()) {
+ if (!canvas_item->is_set_as_top_level()) {
_find_canvas_items_in_rect(p_rect, p_node->get_child(i), r_items, p_parent_xform * canvas_item->get_transform(), p_canvas_xform);
} else {
_find_canvas_items_in_rect(p_rect, p_node->get_child(i), r_items, canvas_item->get_transform(), p_canvas_xform);
@@ -3626,7 +3626,7 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans
Transform2D parent_xform = p_parent_xform;
Transform2D canvas_xform = p_canvas_xform;
- if (canvas_item && !canvas_item->is_set_as_toplevel()) {
+ if (canvas_item && !canvas_item->is_set_as_top_level()) {
parent_xform = parent_xform * canvas_item->get_transform();
} else {
CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node);
@@ -3695,7 +3695,7 @@ void CanvasItemEditor::_draw_locks_and_groups(Node *p_node, const Transform2D &p
Transform2D parent_xform = p_parent_xform;
Transform2D canvas_xform = p_canvas_xform;
- if (canvas_item && !canvas_item->is_set_as_toplevel()) {
+ if (canvas_item && !canvas_item->is_set_as_top_level()) {
parent_xform = parent_xform * canvas_item->get_transform();
} else {
CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node);
diff --git a/misc/dist/ios_xcode/godot_ios.xcodeproj/project.pbxproj b/misc/dist/ios_xcode/godot_ios.xcodeproj/project.pbxproj
index 9a1143a21a..d8da520ed7 100644
--- a/misc/dist/ios_xcode/godot_ios.xcodeproj/project.pbxproj
+++ b/misc/dist/ios_xcode/godot_ios.xcodeproj/project.pbxproj
@@ -386,7 +386,7 @@
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
DEVELOPMENT_TEAM = $team_id;
INFOPLIST_FILE = "$binary/$binary-Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 9.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
@@ -416,7 +416,7 @@
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
DEVELOPMENT_TEAM = $team_id;
INFOPLIST_FILE = "$binary/$binary-Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 9.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
diff --git a/modules/arkit/arkit_interface.h b/modules/arkit/arkit_interface.h
index 5a2c50e213..29e09411ff 100644
--- a/modules/arkit/arkit_interface.h
+++ b/modules/arkit/arkit_interface.h
@@ -44,6 +44,15 @@
// forward declaration for some needed objects
class ARKitShader;
+#ifdef __OBJC__
+
+typedef ARAnchor GodotARAnchor;
+
+#else
+
+typedef void GodotARAnchor;
+#endif
+
class ARKitInterface : public XRInterface {
GDCLASS(ARKitInterface, XRInterface);
@@ -115,8 +124,8 @@ public:
virtual void process() override;
// called by delegate (void * because C++ and Obj-C don't always mix, should really change all platform/iphone/*.cpp files to .mm)
- void _add_or_update_anchor(void *p_anchor);
- void _remove_anchor(void *p_anchor);
+ void _add_or_update_anchor(GodotARAnchor *p_anchor);
+ void _remove_anchor(GodotARAnchor *p_anchor);
ARKitInterface();
~ARKitInterface();
diff --git a/modules/arkit/arkit_interface.mm b/modules/arkit/arkit_interface.mm
index 3fb2cc933d..e8fa023ac7 100644
--- a/modules/arkit/arkit_interface.mm
+++ b/modules/arkit/arkit_interface.mm
@@ -306,12 +306,10 @@ void ARKitInterface::uninitialize() {
remove_all_anchors();
if (@available(iOS 11.0, *)) {
- [ar_session release];
- ar_session = NULL;
+ ar_session = nil;
}
- [ar_delegate release];
- ar_delegate = NULL;
+ ar_delegate = nil;
initialized = false;
session_was_started = false;
}
@@ -687,7 +685,7 @@ void ARKitInterface::process() {
}
}
-void ARKitInterface::_add_or_update_anchor(void *p_anchor) {
+void ARKitInterface::_add_or_update_anchor(GodotARAnchor *p_anchor) {
// _THREAD_SAFE_METHOD_
if (@available(iOS 11.0, *)) {
@@ -749,7 +747,7 @@ void ARKitInterface::_add_or_update_anchor(void *p_anchor) {
}
}
-void ARKitInterface::_remove_anchor(void *p_anchor) {
+void ARKitInterface::_remove_anchor(GodotARAnchor *p_anchor) {
// _THREAD_SAFE_METHOD_
if (@available(iOS 11.0, *)) {
@@ -768,7 +766,7 @@ ARKitInterface::ARKitInterface() {
plane_detection_is_enabled = false;
light_estimation_is_enabled = false;
if (@available(iOS 11.0, *)) {
- ar_session = NULL;
+ ar_session = nil;
}
z_near = 0.01;
z_far = 1000.0;
diff --git a/modules/bullet/bullet_types_converter.cpp b/modules/bullet/bullet_types_converter.cpp
index 7ecad9b78a..09b90fe09e 100644
--- a/modules/bullet/bullet_types_converter.cpp
+++ b/modules/bullet/bullet_types_converter.cpp
@@ -101,9 +101,9 @@ void UNSCALE_BT_BASIS(btTransform &scaledBasis) {
btVector3 column2 = basis.getColumn(2);
// Check for zero scaling.
- if (btFuzzyZero(column0[0])) {
- if (btFuzzyZero(column1[1])) {
- if (btFuzzyZero(column2[2])) {
+ if (column0.fuzzyZero()) {
+ if (column1.fuzzyZero()) {
+ if (column2.fuzzyZero()) {
// All dimensions are fuzzy zero. Create a default basis.
column0 = btVector3(1, 0, 0);
column1 = btVector3(0, 1, 0);
@@ -115,7 +115,7 @@ void UNSCALE_BT_BASIS(btTransform &scaledBasis) {
column0 = column1.cross(column2);
}
} else { // Column 1 scale not fuzzy zero.
- if (btFuzzyZero(column2[2])) {
+ if (column2.fuzzyZero()) {
// Create two vectors othogonal to column 1.
// Ensure that a default basis is created if column 1 = <0, 1, 0>
column0 = btVector3(column1[1], -column1[0], 0);
@@ -126,8 +126,8 @@ void UNSCALE_BT_BASIS(btTransform &scaledBasis) {
}
}
} else { // Column 0 scale not fuzzy zero.
- if (btFuzzyZero(column1[1])) {
- if (btFuzzyZero(column2[2])) {
+ if (column1.fuzzyZero()) {
+ if (column2.fuzzyZero()) {
// Create two vectors orthogonal to column 0.
// Ensure that a default basis is created if column 0 = <1, 0, 0>
column2 = btVector3(-column0[2], 0, column0[0]);
@@ -137,7 +137,7 @@ void UNSCALE_BT_BASIS(btTransform &scaledBasis) {
column1 = column2.cross(column0);
}
} else { // Column 0 and column 1 scales not fuzzy zero.
- if (btFuzzyZero(column2[2])) {
+ if (column2.fuzzyZero()) {
// Create column 2 orthogonal to column 0 and column 1.
column2 = column0.cross(column1);
}
diff --git a/modules/camera/camera_ios.mm b/modules/camera/camera_ios.mm
index c10b13b2af..e4cb928805 100644
--- a/modules/camera/camera_ios.mm
+++ b/modules/camera/camera_ios.mm
@@ -124,18 +124,12 @@
if (output) {
[self removeOutput:output];
[output setSampleBufferDelegate:nil queue:NULL];
- [output release];
output = nil;
}
[self commitConfiguration];
}
-- (void)dealloc {
- // bye bye
- [super dealloc];
-}
-
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
// This gets called every time our camera has a new image for us to process.
// May need to investigate in a way to throttle this if we get more images then we're rendering frames..
@@ -272,7 +266,6 @@ CameraFeedIOS::CameraFeedIOS() {
void CameraFeedIOS::set_device(AVCaptureDevice *p_device) {
device = p_device;
- [device retain];
// get some info
NSString *device_name = p_device.localizedName;
@@ -286,14 +279,12 @@ void CameraFeedIOS::set_device(AVCaptureDevice *p_device) {
};
CameraFeedIOS::~CameraFeedIOS() {
- if (capture_session != NULL) {
- [capture_session release];
- capture_session = NULL;
+ if (capture_session) {
+ capture_session = nil;
};
- if (device != NULL) {
- [device release];
- device = NULL;
+ if (device) {
+ device = nil;
};
};
@@ -312,8 +303,7 @@ void CameraFeedIOS::deactivate_feed() {
// end camera capture if we have one
if (capture_session) {
[capture_session cleanup];
- [capture_session release];
- capture_session = NULL;
+ capture_session = nil;
};
};
@@ -347,8 +337,6 @@ void CameraFeedIOS::deactivate_feed() {
// remove notifications
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureDeviceWasConnectedNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureDeviceWasDisconnectedNotification object:nil];
-
- [super dealloc];
}
@end
@@ -453,5 +441,5 @@ CameraIOS::CameraIOS() {
};
CameraIOS::~CameraIOS() {
- [device_notifications release];
+ device_notifications = nil;
};
diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml
index 613039754f..512452a8df 100644
--- a/modules/gdscript/doc_classes/@GDScript.xml
+++ b/modules/gdscript/doc_classes/@GDScript.xml
@@ -767,7 +767,7 @@
Returns the integer modulus of [code]a/b[/code] that wraps equally in positive and negative.
[codeblock]
for i in range(-3, 4):
- print("%2.0f %2.0f %2.0f" % [i, i % 3, posmod(i, 3)])
+ print("%2d %2d %2d" % [i, i % 3, posmod(i, 3)])
[/codeblock]
Produces:
[codeblock]
diff --git a/modules/mono/mono_gd/support/ios_support.mm b/modules/mono/mono_gd/support/ios_support.mm
index e3d1a647fd..dc23c06eba 100644
--- a/modules/mono/mono_gd/support/ios_support.mm
+++ b/modules/mono/mono_gd/support/ios_support.mm
@@ -131,8 +131,7 @@ GD_PINVOKE_EXPORT void *xamarin_timezone_get_data(const char *p_name, uint32_t *
NSTimeZone *tz = nil;
if (p_name) {
NSString *n = [[NSString alloc] initWithUTF8String:p_name];
- tz = [[[NSTimeZone alloc] initWithName:n] autorelease];
- [n release];
+ tz = [[NSTimeZone alloc] initWithName:n];
} else {
tz = [NSTimeZone localTimeZone];
}
diff --git a/platform/iphone/SCsub b/platform/iphone/SCsub
index 848fd9713a..1dd37dabe5 100644
--- a/platform/iphone/SCsub
+++ b/platform/iphone/SCsub
@@ -19,6 +19,8 @@ iphone_lib = [
"display_layer.mm",
"godot_view_renderer.mm",
"godot_view_gesture_recognizer.mm",
+ "device_metrics.m",
+ "native_video_view.m",
]
env_ios = env.Clone()
diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm
index 7edbcc4667..40a63d7ad2 100644
--- a/platform/iphone/app_delegate.mm
+++ b/platform/iphone/app_delegate.mm
@@ -62,7 +62,7 @@ static ViewController *mainViewController = nil;
CGRect windowBounds = [[UIScreen mainScreen] bounds];
// Create a full-screen window
- self.window = [[[UIWindow alloc] initWithFrame:windowBounds] autorelease];
+ self.window = [[UIWindow alloc] initWithFrame:windowBounds];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
@@ -140,7 +140,6 @@ static ViewController *mainViewController = nil;
- (void)dealloc {
self.window = nil;
- [super dealloc];
}
@end
diff --git a/platform/iphone/detect.py b/platform/iphone/detect.py
index 66579c1ad7..5ebabdd3dc 100644
--- a/platform/iphone/detect.py
+++ b/platform/iphone/detect.py
@@ -129,7 +129,7 @@ def configure(env):
detect_darwin_sdk_path("iphone", env)
env.Append(
CCFLAGS=(
- "-fno-objc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing"
+ "-fobjc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing"
" -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits"
" -fpascal-strings -fblocks -isysroot $IPHONESDK -fvisibility=hidden -mthumb"
' "-DIBOutlet=__attribute__((iboutlet))"'
@@ -141,7 +141,7 @@ def configure(env):
detect_darwin_sdk_path("iphone", env)
env.Append(
CCFLAGS=(
- "-fno-objc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing"
+ "-fobjc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing"
" -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits"
" -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies -miphoneos-version-min=11.0"
" -isysroot $IPHONESDK".split()
diff --git a/platform/iphone/device_metrics.h b/platform/iphone/device_metrics.h
new file mode 100644
index 0000000000..6d0ff49077
--- /dev/null
+++ b/platform/iphone/device_metrics.h
@@ -0,0 +1,37 @@
+/*************************************************************************/
+/* device_metrics.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#import <Foundation/Foundation.h>
+
+@interface GodotDeviceMetrics : NSObject
+
+@property(nonatomic, class, readonly, strong) NSDictionary<NSArray *, NSNumber *> *dpiList;
+
+@end
diff --git a/platform/iphone/device_metrics.m b/platform/iphone/device_metrics.m
new file mode 100644
index 0000000000..747872bc49
--- /dev/null
+++ b/platform/iphone/device_metrics.m
@@ -0,0 +1,152 @@
+/*************************************************************************/
+/* device_metrics.m */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#import "device_metrics.h"
+
+@implementation GodotDeviceMetrics
+
++ (NSDictionary *)dpiList {
+ return @{
+ @[
+ @"iPad1,1",
+ @"iPad2,1",
+ @"iPad2,2",
+ @"iPad2,3",
+ @"iPad2,4",
+ ] : @132,
+ @[
+ @"iPhone1,1",
+ @"iPhone1,2",
+ @"iPhone2,1",
+ @"iPad2,5",
+ @"iPad2,6",
+ @"iPad2,7",
+ @"iPod1,1",
+ @"iPod2,1",
+ @"iPod3,1",
+ ] : @163,
+ @[
+ @"iPad3,1",
+ @"iPad3,2",
+ @"iPad3,3",
+ @"iPad3,4",
+ @"iPad3,5",
+ @"iPad3,6",
+ @"iPad4,1",
+ @"iPad4,2",
+ @"iPad4,3",
+ @"iPad5,3",
+ @"iPad5,4",
+ @"iPad6,3",
+ @"iPad6,4",
+ @"iPad6,7",
+ @"iPad6,8",
+ @"iPad6,11",
+ @"iPad6,12",
+ @"iPad7,1",
+ @"iPad7,2",
+ @"iPad7,3",
+ @"iPad7,4",
+ @"iPad7,5",
+ @"iPad7,6",
+ @"iPad7,11",
+ @"iPad7,12",
+ @"iPad8,1",
+ @"iPad8,2",
+ @"iPad8,3",
+ @"iPad8,4",
+ @"iPad8,5",
+ @"iPad8,6",
+ @"iPad8,7",
+ @"iPad8,8",
+ @"iPad8,9",
+ @"iPad8,10",
+ @"iPad8,11",
+ @"iPad8,12",
+ @"iPad11,3",
+ @"iPad11,4",
+ ] : @264,
+ @[
+ @"iPhone3,1",
+ @"iPhone3,2",
+ @"iPhone3,3",
+ @"iPhone4,1",
+ @"iPhone5,1",
+ @"iPhone5,2",
+ @"iPhone5,3",
+ @"iPhone5,4",
+ @"iPhone6,1",
+ @"iPhone6,2",
+ @"iPhone7,2",
+ @"iPhone8,1",
+ @"iPhone8,4",
+ @"iPhone9,1",
+ @"iPhone9,3",
+ @"iPhone10,1",
+ @"iPhone10,4",
+ @"iPhone11,8",
+ @"iPhone12,1",
+ @"iPhone12,8",
+ @"iPad4,4",
+ @"iPad4,5",
+ @"iPad4,6",
+ @"iPad4,7",
+ @"iPad4,8",
+ @"iPad4,9",
+ @"iPad5,1",
+ @"iPad5,2",
+ @"iPad11,1",
+ @"iPad11,2",
+ @"iPod4,1",
+ @"iPod5,1",
+ @"iPod7,1",
+ @"iPod9,1",
+ ] : @326,
+ @[
+ @"iPhone7,1",
+ @"iPhone8,2",
+ @"iPhone9,2",
+ @"iPhone9,4",
+ @"iPhone10,2",
+ @"iPhone10,5",
+ ] : @401,
+ @[
+ @"iPhone10,3",
+ @"iPhone10,6",
+ @"iPhone11,2",
+ @"iPhone11,4",
+ @"iPhone11,6",
+ @"iPhone12,3",
+ @"iPhone12,5",
+ ] : @458,
+ };
+}
+
+@end
diff --git a/platform/iphone/display_layer.mm b/platform/iphone/display_layer.mm
index 5ec94fb471..2716538b89 100644
--- a/platform/iphone/display_layer.mm
+++ b/platform/iphone/display_layer.mm
@@ -124,11 +124,8 @@
}
if (context) {
- [context release];
context = nil;
}
-
- [super dealloc];
}
- (BOOL)createFramebuffer {
diff --git a/platform/iphone/display_server_iphone.mm b/platform/iphone/display_server_iphone.mm
index eea87cecc9..d456f9cbf6 100644
--- a/platform/iphone/display_server_iphone.mm
+++ b/platform/iphone/display_server_iphone.mm
@@ -32,8 +32,10 @@
#import "app_delegate.h"
#include "core/io/file_access_pack.h"
#include "core/project_settings.h"
+#import "device_metrics.h"
#import "godot_view.h"
#include "ios.h"
+#import "native_video_view.h"
#include "os_iphone.h"
#import "view_controller.h"
@@ -41,120 +43,6 @@
#import <sys/utsname.h>
static const float kDisplayServerIPhoneAcceleration = 1;
-static NSDictionary *iOSModelToDPI = @{
- @[
- @"iPad1,1",
- @"iPad2,1",
- @"iPad2,2",
- @"iPad2,3",
- @"iPad2,4",
- ] : @132,
- @[
- @"iPhone1,1",
- @"iPhone1,2",
- @"iPhone2,1",
- @"iPad2,5",
- @"iPad2,6",
- @"iPad2,7",
- @"iPod1,1",
- @"iPod2,1",
- @"iPod3,1",
- ] : @163,
- @[
- @"iPad3,1",
- @"iPad3,2",
- @"iPad3,3",
- @"iPad3,4",
- @"iPad3,5",
- @"iPad3,6",
- @"iPad4,1",
- @"iPad4,2",
- @"iPad4,3",
- @"iPad5,3",
- @"iPad5,4",
- @"iPad6,3",
- @"iPad6,4",
- @"iPad6,7",
- @"iPad6,8",
- @"iPad6,11",
- @"iPad6,12",
- @"iPad7,1",
- @"iPad7,2",
- @"iPad7,3",
- @"iPad7,4",
- @"iPad7,5",
- @"iPad7,6",
- @"iPad7,11",
- @"iPad7,12",
- @"iPad8,1",
- @"iPad8,2",
- @"iPad8,3",
- @"iPad8,4",
- @"iPad8,5",
- @"iPad8,6",
- @"iPad8,7",
- @"iPad8,8",
- @"iPad8,9",
- @"iPad8,10",
- @"iPad8,11",
- @"iPad8,12",
- @"iPad11,3",
- @"iPad11,4",
- ] : @264,
- @[
- @"iPhone3,1",
- @"iPhone3,2",
- @"iPhone3,3",
- @"iPhone4,1",
- @"iPhone5,1",
- @"iPhone5,2",
- @"iPhone5,3",
- @"iPhone5,4",
- @"iPhone6,1",
- @"iPhone6,2",
- @"iPhone7,2",
- @"iPhone8,1",
- @"iPhone8,4",
- @"iPhone9,1",
- @"iPhone9,3",
- @"iPhone10,1",
- @"iPhone10,4",
- @"iPhone11,8",
- @"iPhone12,1",
- @"iPhone12,8",
- @"iPad4,4",
- @"iPad4,5",
- @"iPad4,6",
- @"iPad4,7",
- @"iPad4,8",
- @"iPad4,9",
- @"iPad5,1",
- @"iPad5,2",
- @"iPad11,1",
- @"iPad11,2",
- @"iPod4,1",
- @"iPod5,1",
- @"iPod7,1",
- @"iPod9,1",
- ] : @326,
- @[
- @"iPhone7,1",
- @"iPhone8,2",
- @"iPhone9,2",
- @"iPhone9,4",
- @"iPhone10,2",
- @"iPhone10,5",
- ] : @401,
- @[
- @"iPhone10,3",
- @"iPhone10,6",
- @"iPhone11,2",
- @"iPhone11,4",
- @"iPhone11,6",
- @"iPhone12,3",
- @"iPhone12,5",
- ] : @458,
-};
DisplayServerIPhone *DisplayServerIPhone::get_singleton() {
return (DisplayServerIPhone *)DisplayServer::get_singleton();
@@ -383,8 +271,7 @@ void DisplayServerIPhone::update_gravity(float p_x, float p_y, float p_z) {
Input::get_singleton()->set_gravity(Vector3(p_x, p_y, p_z));
};
-void DisplayServerIPhone::update_accelerometer(float p_x, float p_y,
- float p_z) {
+void DisplayServerIPhone::update_accelerometer(float p_x, float p_y, float p_z) {
// Found out the Z should not be negated! Pass as is!
Vector3 v_accelerometer = Vector3(
p_x / kDisplayServerIPhoneAcceleration,
@@ -392,39 +279,6 @@ void DisplayServerIPhone::update_accelerometer(float p_x, float p_y,
p_z / kDisplayServerIPhoneAcceleration);
Input::get_singleton()->set_accelerometer(v_accelerometer);
-
- /*
- if (p_x != last_accel.x) {
- //printf("updating accel x %f\n", p_x);
- InputEvent ev;
- ev.type = InputEvent::JOYPAD_MOTION;
- ev.device = 0;
- ev.joy_motion.axis = JOY_ANALOG_0;
- ev.joy_motion.axis_value = (p_x / (float)ACCEL_RANGE);
- last_accel.x = p_x;
- queue_event(ev);
- };
- if (p_y != last_accel.y) {
- //printf("updating accel y %f\n", p_y);
- InputEvent ev;
- ev.type = InputEvent::JOYPAD_MOTION;
- ev.device = 0;
- ev.joy_motion.axis = JOY_ANALOG_1;
- ev.joy_motion.axis_value = (p_y / (float)ACCEL_RANGE);
- last_accel.y = p_y;
- queue_event(ev);
- };
- if (p_z != last_accel.z) {
- //printf("updating accel z %f\n", p_z);
- InputEvent ev;
- ev.type = InputEvent::JOYPAD_MOTION;
- ev.device = 0;
- ev.joy_motion.axis = JOY_ANALOG_2;
- ev.joy_motion.axis_value = ( (1.0 - p_z) / (float)ACCEL_RANGE);
- last_accel.z = p_z;
- queue_event(ev);
- };
- */
};
void DisplayServerIPhone::update_magnetometer(float p_x, float p_y, float p_z) {
@@ -516,6 +370,8 @@ int DisplayServerIPhone::screen_get_dpi(int p_screen) const {
NSString *string = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
+ NSDictionary *iOSModelToDPI = [GodotDeviceMetrics dpiList];
+
for (NSArray *keyArray in iOSModelToDPI) {
if ([keyArray containsObject:string]) {
NSNumber *value = iOSModelToDPI[keyArray];
@@ -523,7 +379,26 @@ int DisplayServerIPhone::screen_get_dpi(int p_screen) const {
}
}
- return 163;
+ // If device wasn't found in dictionary
+ // make a best guess from device metrics.
+ CGFloat scale = [UIScreen mainScreen].scale;
+
+ UIUserInterfaceIdiom idiom = [UIDevice currentDevice].userInterfaceIdiom;
+
+ switch (idiom) {
+ case UIUserInterfaceIdiomPad:
+ return scale == 2 ? 264 : 132;
+ case UIUserInterfaceIdiomPhone: {
+ if (scale == 3) {
+ CGFloat nativeScale = [UIScreen mainScreen].nativeScale;
+ return nativeScale == 3 ? 458 : 401;
+ }
+
+ return 326;
+ }
+ default:
+ return 72;
+ }
}
float DisplayServerIPhone::screen_get_scale(int p_screen) const {
@@ -716,7 +591,7 @@ Error DisplayServerIPhone::native_video_play(String p_path, float p_volume, Stri
String file_path = ProjectSettings::get_singleton()->globalize_path(p_path);
- NSString *filePath = [[[NSString alloc] initWithUTF8String:file_path.utf8().get_data()] autorelease];
+ NSString *filePath = [[NSString alloc] initWithUTF8String:file_path.utf8().get_data()];
NSString *audioTrack = [NSString stringWithUTF8String:p_audio_track.utf8()];
NSString *subtitleTrack = [NSString stringWithUTF8String:p_subtitle_track.utf8()];
@@ -731,22 +606,22 @@ Error DisplayServerIPhone::native_video_play(String p_path, float p_volume, Stri
}
bool DisplayServerIPhone::native_video_is_playing() const {
- return [AppDelegate.viewController isVideoPlaying];
+ return [AppDelegate.viewController.videoView isVideoPlaying];
}
void DisplayServerIPhone::native_video_pause() {
if (native_video_is_playing()) {
- [AppDelegate.viewController pauseVideo];
+ [AppDelegate.viewController.videoView pauseVideo];
}
}
void DisplayServerIPhone::native_video_unpause() {
- [AppDelegate.viewController unpauseVideo];
+ [AppDelegate.viewController.videoView unpauseVideo];
};
void DisplayServerIPhone::native_video_stop() {
if (native_video_is_playing()) {
- [AppDelegate.viewController stopVideo];
+ [AppDelegate.viewController.videoView stopVideo];
}
}
diff --git a/platform/iphone/game_center.mm b/platform/iphone/game_center.mm
index b237ba6bb6..0f8c0100c3 100644
--- a/platform/iphone/game_center.mm
+++ b/platform/iphone/game_center.mm
@@ -83,7 +83,12 @@ Error GameCenter::authenticate() {
// after the view is cancelled or the user logs in. Or if the user's already logged in, it's
// called just once to confirm they're authenticated. This is why no result needs to be specified
// in the presentViewController phase. In this case, more calls to this function will follow.
+ _weakify(root_controller);
+ _weakify(player);
player.authenticateHandler = (^(UIViewController *controller, NSError *error) {
+ _strongify(root_controller);
+ _strongify(player);
+
if (controller) {
[root_controller presentViewController:controller animated:YES completion:nil];
} else {
@@ -123,8 +128,8 @@ Error GameCenter::post_score(Dictionary p_score) {
float score = p_score["score"];
String category = p_score["category"];
- NSString *cat_str = [[[NSString alloc] initWithUTF8String:category.utf8().get_data()] autorelease];
- GKScore *reporter = [[[GKScore alloc] initWithLeaderboardIdentifier:cat_str] autorelease];
+ NSString *cat_str = [[NSString alloc] initWithUTF8String:category.utf8().get_data()];
+ GKScore *reporter = [[GKScore alloc] initWithLeaderboardIdentifier:cat_str];
reporter.value = score;
ERR_FAIL_COND_V([GKScore respondsToSelector:@selector(reportScores)], ERR_UNAVAILABLE);
@@ -152,8 +157,8 @@ Error GameCenter::award_achievement(Dictionary p_params) {
String name = p_params["name"];
float progress = p_params["progress"];
- NSString *name_str = [[[NSString alloc] initWithUTF8String:name.utf8().get_data()] autorelease];
- GKAchievement *achievement = [[[GKAchievement alloc] initWithIdentifier:name_str] autorelease];
+ NSString *name_str = [[NSString alloc] initWithUTF8String:name.utf8().get_data()];
+ GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier:name_str];
ERR_FAIL_COND_V(!achievement, FAILED);
ERR_FAIL_COND_V([GKAchievement respondsToSelector:@selector(reportAchievements)], ERR_UNAVAILABLE);
@@ -297,7 +302,7 @@ Error GameCenter::show_game_center(Dictionary p_params) {
}
}
- GKGameCenterViewController *controller = [[[GKGameCenterViewController alloc] init] autorelease];
+ GKGameCenterViewController *controller = [[GKGameCenterViewController alloc] init];
ERR_FAIL_COND_V(!controller, FAILED);
ViewController *root_controller = (ViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
@@ -309,7 +314,7 @@ Error GameCenter::show_game_center(Dictionary p_params) {
controller.leaderboardIdentifier = nil;
if (p_params.has("leaderboard_name")) {
String name = p_params["leaderboard_name"];
- NSString *name_str = [[[NSString alloc] initWithUTF8String:name.utf8().get_data()] autorelease];
+ NSString *name_str = [[NSString alloc] initWithUTF8String:name.utf8().get_data()];
controller.leaderboardIdentifier = name_str;
}
}
diff --git a/platform/iphone/godot_iphone.mm b/platform/iphone/godot_iphone.mm
index 090b772947..6d95276f37 100644
--- a/platform/iphone/godot_iphone.mm
+++ b/platform/iphone/godot_iphone.mm
@@ -49,10 +49,8 @@ int add_path(int p_argc, char **p_args) {
}
p_args[p_argc++] = (char *)"--path";
- [str retain]; // memory leak lol (maybe make it static here and delete it in ViewController destructor? @todo
p_args[p_argc++] = (char *)[str cStringUsingEncoding:NSUTF8StringEncoding];
p_args[p_argc] = NULL;
- [str release];
return p_argc;
};
@@ -68,9 +66,7 @@ int add_cmdline(int p_argc, char **p_args) {
if (!str) {
continue;
}
- [str retain]; // @todo delete these at some point
p_args[p_argc++] = (char *)[str cStringUsingEncoding:NSUTF8StringEncoding];
- [str release];
};
p_args[p_argc] = NULL;
diff --git a/platform/iphone/godot_view.mm b/platform/iphone/godot_view.mm
index c0a31549c4..3b4344c46d 100644
--- a/platform/iphone/godot_view.mm
+++ b/platform/iphone/godot_view.mm
@@ -145,8 +145,6 @@ static const int max_touches = 8;
if (self.delayGestureRecognizer) {
self.delayGestureRecognizer = nil;
}
-
- [super dealloc];
}
- (void)godot_commonInit {
@@ -156,7 +154,7 @@ static const int max_touches = 8;
// Configure and start accelerometer
if (!self.motionManager) {
- self.motionManager = [[[CMMotionManager alloc] init] autorelease];
+ self.motionManager = [[CMMotionManager alloc] init];
if (self.motionManager.deviceMotionAvailable) {
self.motionManager.deviceMotionUpdateInterval = 1.0 / 70.0;
[self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXMagneticNorthZVertical];
@@ -169,7 +167,6 @@ static const int max_touches = 8;
GodotViewGestureRecognizer *gestureRecognizer = [[GodotViewGestureRecognizer alloc] init];
self.delayGestureRecognizer = gestureRecognizer;
[self addGestureRecognizer:self.delayGestureRecognizer];
- [gestureRecognizer release];
}
- (void)stopRendering {
@@ -204,14 +201,11 @@ static const int max_touches = 8;
if (self.useCADisplayLink) {
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView)];
- // if (@available(iOS 10, *)) {
- self.displayLink.preferredFramesPerSecond = (NSInteger)(1.0 / self.renderingInterval);
- // } else {
- // // Approximate frame rate
- // // assumes device refreshes at 60 fps
- // int frameInterval = (int)floor(self.renderingInterval * 60.0f);
- // [self.displayLink setFrameInterval:frameInterval];
- // }
+ // Approximate frame rate
+ // assumes device refreshes at 60 fps
+ int displayFPS = (NSInteger)(1.0 / self.renderingInterval);
+
+ self.displayLink.preferredFramesPerSecond = displayFPS;
// Setup DisplayLink in main thread
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
diff --git a/platform/iphone/godot_view_gesture_recognizer.mm b/platform/iphone/godot_view_gesture_recognizer.mm
index 99ee42ecb3..71367a629c 100644
--- a/platform/iphone/godot_view_gesture_recognizer.mm
+++ b/platform/iphone/godot_view_gesture_recognizer.mm
@@ -83,8 +83,6 @@ const CGFloat kGLGestureMovementDistance = 0.5;
if (self.delayedEvent) {
self.delayedEvent = nil;
}
-
- [super dealloc];
}
- (void)delayTouches:(NSSet *)touches andEvent:(UIEvent *)event {
@@ -116,7 +114,6 @@ const CGFloat kGLGestureMovementDistance = 0.5;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *cleared = [self copyClearedTouches:touches phase:UITouchPhaseBegan];
[self delayTouches:cleared andEvent:event];
- [cleared release];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
@@ -137,17 +134,14 @@ const CGFloat kGLGestureMovementDistance = 0.5;
if (distance > kGLGestureMovementDistance) {
[self.delayTimer fire];
[self.view touchesMoved:cleared withEvent:event];
- [cleared release];
return;
}
}
- [cleared release];
return;
}
[self.view touchesMoved:cleared withEvent:event];
- [cleared release];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
@@ -155,7 +149,6 @@ const CGFloat kGLGestureMovementDistance = 0.5;
NSSet *cleared = [self copyClearedTouches:touches phase:UITouchPhaseEnded];
[self.view touchesEnded:cleared withEvent:event];
- [cleared release];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
diff --git a/platform/iphone/icloud.mm b/platform/iphone/icloud.mm
index d3086e6cea..3d81349883 100644
--- a/platform/iphone/icloud.mm
+++ b/platform/iphone/icloud.mm
@@ -150,7 +150,7 @@ Variant nsobject_to_variant(NSObject *object) {
NSObject *variant_to_nsobject(Variant v) {
if (v.get_type() == Variant::STRING) {
- return [[[NSString alloc] initWithUTF8String:((String)v).utf8().get_data()] autorelease];
+ return [[NSString alloc] initWithUTF8String:((String)v).utf8().get_data()];
} else if (v.get_type() == Variant::FLOAT) {
return [NSNumber numberWithDouble:(double)v];
} else if (v.get_type() == Variant::INT) {
@@ -158,11 +158,11 @@ NSObject *variant_to_nsobject(Variant v) {
} else if (v.get_type() == Variant::BOOL) {
return [NSNumber numberWithBool:BOOL((bool)v)];
} else if (v.get_type() == Variant::DICTIONARY) {
- NSMutableDictionary *result = [[[NSMutableDictionary alloc] init] autorelease];
+ NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
Dictionary dic = v;
Array keys = dic.keys();
for (int i = 0; i < keys.size(); ++i) {
- NSString *key = [[[NSString alloc] initWithUTF8String:((String)(keys[i])).utf8().get_data()] autorelease];
+ NSString *key = [[NSString alloc] initWithUTF8String:((String)(keys[i])).utf8().get_data()];
NSObject *value = variant_to_nsobject(dic[keys[i]]);
if (key == NULL || value == NULL) {
@@ -173,7 +173,7 @@ NSObject *variant_to_nsobject(Variant v) {
}
return result;
} else if (v.get_type() == Variant::ARRAY) {
- NSMutableArray *result = [[[NSMutableArray alloc] init] autorelease];
+ NSMutableArray *result = [[NSMutableArray alloc] init];
Array arr = v;
for (int i = 0; i < arr.size(); ++i) {
NSObject *value = variant_to_nsobject(arr[i]);
@@ -195,7 +195,7 @@ NSObject *variant_to_nsobject(Variant v) {
}
Error ICloud::remove_key(String p_param) {
- NSString *key = [[[NSString alloc] initWithUTF8String:p_param.utf8().get_data()] autorelease];
+ NSString *key = [[NSString alloc] initWithUTF8String:p_param.utf8().get_data()];
NSUbiquitousKeyValueStore *store = [NSUbiquitousKeyValueStore defaultStore];
@@ -217,7 +217,7 @@ Array ICloud::set_key_values(Dictionary p_params) {
String variant_key = keys[i];
Variant variant_value = p_params[variant_key];
- NSString *key = [[[NSString alloc] initWithUTF8String:variant_key.utf8().get_data()] autorelease];
+ NSString *key = [[NSString alloc] initWithUTF8String:variant_key.utf8().get_data()];
if (key == NULL) {
error_keys.push_back(variant_key);
continue;
@@ -238,7 +238,7 @@ Array ICloud::set_key_values(Dictionary p_params) {
}
Variant ICloud::get_key_value(String p_param) {
- NSString *key = [[[NSString alloc] initWithUTF8String:p_param.utf8().get_data()] autorelease];
+ NSString *key = [[NSString alloc] initWithUTF8String:p_param.utf8().get_data()];
NSUbiquitousKeyValueStore *store = [NSUbiquitousKeyValueStore defaultStore];
if (![[store dictionaryRepresentation] objectForKey:key]) {
diff --git a/platform/iphone/in_app_store.mm b/platform/iphone/in_app_store.mm
index 1477f92200..2b973dfbcf 100644
--- a/platform/iphone/in_app_store.mm
+++ b/platform/iphone/in_app_store.mm
@@ -56,7 +56,6 @@ static NSArray *latestProducts;
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:self.priceLocale];
NSString *formattedString = [numberFormatter stringFromNumber:self.price];
- [numberFormatter release];
return formattedString;
}
@@ -124,8 +123,6 @@ void InAppStore::_bind_methods() {
ret["invalid_ids"] = invalid_ids;
InAppStore::get_singleton()->_post_event(ret);
-
- [request release];
};
@end
@@ -136,14 +133,14 @@ Error InAppStore::request_product_info(Dictionary p_params) {
PackedStringArray pids = p_params["product_ids"];
printf("************ request product info! %i\n", pids.size());
- NSMutableArray *array = [[[NSMutableArray alloc] initWithCapacity:pids.size()] autorelease];
+ NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:pids.size()];
for (int i = 0; i < pids.size(); i++) {
printf("******** adding %s to product list\n", pids[i].utf8().get_data());
- NSString *pid = [[[NSString alloc] initWithUTF8String:pids[i].utf8().get_data()] autorelease];
+ NSString *pid = [[NSString alloc] initWithUTF8String:pids[i].utf8().get_data()];
[array addObject:pid];
};
- NSSet *products = [[[NSSet alloc] initWithArray:array] autorelease];
+ NSSet *products = [[NSSet alloc] initWithArray:array];
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:products];
ProductsDelegate *delegate = [[ProductsDelegate alloc] init];
@@ -183,30 +180,14 @@ Error InAppStore::restore_purchases() {
ret["transaction_id"] = transactionId;
NSData *receipt = nil;
- int sdk_version = 6;
-
- if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
- NSURL *receiptFileURL = nil;
- NSBundle *bundle = [NSBundle mainBundle];
- if ([bundle respondsToSelector:@selector(appStoreReceiptURL)]) {
- // Get the transaction receipt file path location in the app bundle.
- receiptFileURL = [bundle appStoreReceiptURL];
-
- // Read in the contents of the transaction file.
- receipt = [NSData dataWithContentsOfURL:receiptFileURL];
- sdk_version = 7;
+ int sdk_version = [[[UIDevice currentDevice] systemVersion] intValue];
- } else {
- // Fall back to deprecated transaction receipt,
- // which is still available in iOS 7.
+ NSBundle *bundle = [NSBundle mainBundle];
+ // Get the transaction receipt file path location in the app bundle.
+ NSURL *receiptFileURL = [bundle appStoreReceiptURL];
- // Use SKPaymentTransaction's transactionReceipt.
- receipt = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
- }
-
- } else {
- receipt = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
- }
+ // Read in the contents of the transaction file.
+ receipt = [NSData dataWithContentsOfURL:receiptFileURL];
NSString *receipt_to_send = nil;
if (receipt != nil) {
@@ -265,7 +246,7 @@ Error InAppStore::purchase(Dictionary p_params) {
printf("purchasing!\n");
ERR_FAIL_COND_V(!p_params.has("product_id"), ERR_INVALID_PARAMETER);
- NSString *pid = [[[NSString alloc] initWithUTF8String:String(p_params["product_id"]).utf8().get_data()] autorelease];
+ NSString *pid = [[NSString alloc] initWithUTF8String:String(p_params["product_id"]).utf8().get_data()];
SKProduct *product = nil;
@@ -307,7 +288,7 @@ void InAppStore::_post_event(Variant p_event) {
void InAppStore::_record_purchase(String product_id) {
String skey = "purchased/" + product_id;
- NSString *key = [[[NSString alloc] initWithUTF8String:skey.utf8().get_data()] autorelease];
+ NSString *key = [[NSString alloc] initWithUTF8String:skey.utf8().get_data()];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:key];
[[NSUserDefaults standardUserDefaults] synchronize];
};
diff --git a/platform/iphone/ios.mm b/platform/iphone/ios.mm
index 6d7699c0c9..d4e099063f 100644
--- a/platform/iphone/ios.mm
+++ b/platform/iphone/ios.mm
@@ -30,6 +30,7 @@
#include "ios.h"
#import "app_delegate.h"
+#import "view_controller.h"
#import <UIKit/UIKit.h>
#include <sys/sysctl.h>
@@ -68,23 +69,9 @@ String iOS::get_model() const {
}
String iOS::get_rate_url(int p_app_id) const {
- String templ = "itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=APP_ID";
- String templ_iOS7 = "itms-apps://itunes.apple.com/app/idAPP_ID";
- String templ_iOS8 = "itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=APP_ID&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software";
+ String app_url_path = "itms-apps://itunes.apple.com/app/idAPP_ID";
- //ios7 before
- String ret = templ;
-
- if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 7.1) {
- // iOS 7 needs a different templateReviewURL @see https://github.com/arashpayan/appirater/issues/131
- ret = templ_iOS7;
- } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
- // iOS 8 needs a different templateReviewURL also @see https://github.com/arashpayan/appirater/issues/182
- ret = templ_iOS8;
- }
-
- // ios7 for everything?
- ret = templ_iOS7.replace("APP_ID", String::num(p_app_id));
+ String ret = app_url_path.replace("APP_ID", String::num(p_app_id));
printf("returning rate url %s\n", ret.utf8().get_data());
return ret;
diff --git a/platform/iphone/joypad_iphone.mm b/platform/iphone/joypad_iphone.mm
index 6088f1c25c..b0a8076b56 100644
--- a/platform/iphone/joypad_iphone.mm
+++ b/platform/iphone/joypad_iphone.mm
@@ -131,8 +131,6 @@ void JoypadIPhone::start_processing() {
- (void)dealloc {
[self finishObserving];
-
- [super dealloc];
}
- (int)getJoyIdForController:(GCController *)controller {
@@ -251,8 +249,13 @@ void JoypadIPhone::start_processing() {
// The extended gamepad profile has all the input you could possibly find on
// a gamepad but will only be active if your gamepad actually has all of
// these...
- controller.extendedGamepad.valueChangedHandler = ^(
- GCExtendedGamepad *gamepad, GCControllerElement *element) {
+ _weakify(self);
+ _weakify(controller);
+
+ controller.extendedGamepad.valueChangedHandler = ^(GCExtendedGamepad *gamepad, GCControllerElement *element) {
+ _strongify(self);
+ _strongify(controller);
+
int joy_id = [self getJoyIdForController:controller];
if (element == gamepad.buttonA) {
@@ -304,71 +307,33 @@ void JoypadIPhone::start_processing() {
Input::get_singleton()->joy_axis(joy_id, JOY_AXIS_TRIGGER_RIGHT, jx);
};
};
+ } else if (controller.microGamepad != nil) {
+ // micro gamepads were added in OS 9 and feature just 2 buttons and a d-pad
+ _weakify(self);
+ _weakify(controller);
+
+ controller.microGamepad.valueChangedHandler = ^(GCMicroGamepad *gamepad, GCControllerElement *element) {
+ _strongify(self);
+ _strongify(controller);
+
+ int joy_id = [self getJoyIdForController:controller];
+
+ if (element == gamepad.buttonA) {
+ Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_A,
+ gamepad.buttonA.isPressed);
+ } else if (element == gamepad.buttonX) {
+ Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_X,
+ gamepad.buttonX.isPressed);
+ } else if (element == gamepad.dpad) {
+ Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_DPAD_UP,
+ gamepad.dpad.up.isPressed);
+ Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_DPAD_DOWN,
+ gamepad.dpad.down.isPressed);
+ Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_DPAD_LEFT, gamepad.dpad.left.isPressed);
+ Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_DPAD_RIGHT, gamepad.dpad.right.isPressed);
+ };
+ };
}
- // else if (controller.gamepad != nil) {
- // // gamepad is the standard profile with 4 buttons, shoulder buttons and a
- // // D-pad
- // controller.gamepad.valueChangedHandler = ^(GCGamepad *gamepad,
- // GCControllerElement *element) {
- // int joy_id = [self getJoyIdForController:controller];
- //
- // if (element == gamepad.buttonA) {
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_A,
- // gamepad.buttonA.isPressed);
- // } else if (element == gamepad.buttonB) {
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_B,
- // gamepad.buttonB.isPressed);
- // } else if (element == gamepad.buttonX) {
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_X,
- // gamepad.buttonX.isPressed);
- // } else if (element == gamepad.buttonY) {
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_Y,
- // gamepad.buttonY.isPressed);
- // } else if (element == gamepad.leftShoulder) {
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_LEFT_SHOULDER,
- // gamepad.leftShoulder.isPressed);
- // } else if (element == gamepad.rightShoulder) {
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_RIGHT_SHOULDER,
- // gamepad.rightShoulder.isPressed);
- // } else if (element == gamepad.dpad) {
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_DPAD_UP,
- // gamepad.dpad.up.isPressed);
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_DPAD_DOWN,
- // gamepad.dpad.down.isPressed);
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_DPAD_LEFT,
- // gamepad.dpad.left.isPressed);
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_DPAD_RIGHT,
- // gamepad.dpad.right.isPressed);
- // };
- // };
- //#ifdef ADD_MICRO_GAMEPAD // disabling this for now, only available on iOS 9+,
- // // while we are setting that as the minimum, seems our
- // // build environment doesn't like it
- // } else if (controller.microGamepad != nil) {
- // // micro gamepads were added in OS 9 and feature just 2 buttons and a d-pad
- // controller.microGamepad.valueChangedHandler =
- // ^(GCMicroGamepad *gamepad, GCControllerElement *element) {
- // int joy_id = [self getJoyIdForController:controller];
- //
- // if (element == gamepad.buttonA) {
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_A,
- // gamepad.buttonA.isPressed);
- // } else if (element == gamepad.buttonX) {
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_X,
- // gamepad.buttonX.isPressed);
- // } else if (element == gamepad.dpad) {
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_DPAD_UP,
- // gamepad.dpad.up.isPressed);
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_DPAD_DOWN,
- // gamepad.dpad.down.isPressed);
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_DPAD_LEFT,
- // gamepad.dpad.left.isPressed);
- // Input::get_singleton()->joy_button(joy_id, JOY_BUTTON_DPAD_RIGHT,
- // gamepad.dpad.right.isPressed);
- // };
- // };
- //#endif
- // };
///@TODO need to add support for controller.motion which gives us access to
/// the orientation of the device (if supported)
diff --git a/platform/iphone/native_video_view.h b/platform/iphone/native_video_view.h
new file mode 100644
index 0000000000..d8687b3538
--- /dev/null
+++ b/platform/iphone/native_video_view.h
@@ -0,0 +1,41 @@
+/*************************************************************************/
+/* native_video_view.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#import <UIKit/UIKit.h>
+
+@interface GodotNativeVideoView : UIView
+
+- (BOOL)playVideoAtPath:(NSString *)filePath volume:(float)videoVolume audio:(NSString *)audioTrack subtitle:(NSString *)subtitleTrack;
+- (BOOL)isVideoPlaying;
+- (void)pauseVideo;
+- (void)unpauseVideo;
+- (void)stopVideo;
+
+@end
diff --git a/platform/iphone/native_video_view.m b/platform/iphone/native_video_view.m
new file mode 100644
index 0000000000..a4e9f209f0
--- /dev/null
+++ b/platform/iphone/native_video_view.m
@@ -0,0 +1,260 @@
+/*************************************************************************/
+/* native_video_view.m */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#import "native_video_view.h"
+#import <AVFoundation/AVFoundation.h>
+
+@interface GodotNativeVideoView ()
+
+@property(strong, nonatomic) AVAsset *avAsset;
+@property(strong, nonatomic) AVPlayerItem *avPlayerItem;
+@property(strong, nonatomic) AVPlayer *avPlayer;
+@property(strong, nonatomic) AVPlayerLayer *avPlayerLayer;
+@property(assign, nonatomic) CMTime videoCurrentTime;
+@property(assign, nonatomic) BOOL isVideoCurrentlyPlaying;
+
+@end
+
+@implementation GodotNativeVideoView
+
+- (instancetype)initWithFrame:(CGRect)frame {
+ self = [super initWithFrame:frame];
+
+ if (self) {
+ [self godot_commonInit];
+ }
+
+ return self;
+}
+
+- (instancetype)initWithCoder:(NSCoder *)coder {
+ self = [super initWithCoder:coder];
+
+ if (self) {
+ [self godot_commonInit];
+ }
+
+ return self;
+}
+
+- (void)godot_commonInit {
+ self.isVideoCurrentlyPlaying = NO;
+ self.videoCurrentTime = kCMTimeZero;
+
+ [self observeVideoAudio];
+}
+
+- (void)observeVideoAudio {
+ printf("******** adding observer for sound routing changes\n");
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(audioRouteChangeListenerCallback:)
+ name:AVAudioSessionRouteChangeNotification
+ object:nil];
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
+ if (object == self.avPlayerItem && [keyPath isEqualToString:@"status"]) {
+ [self handleVideoOrPlayerStatus];
+ }
+
+ if (object == self.avPlayer && [keyPath isEqualToString:@"rate"]) {
+ [self handleVideoPlayRate];
+ }
+}
+
+// MARK: Video Audio
+
+- (void)audioRouteChangeListenerCallback:(NSNotification *)notification {
+ printf("*********** route changed!\n");
+ NSDictionary *interuptionDict = notification.userInfo;
+
+ NSInteger routeChangeReason = [[interuptionDict valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];
+
+ switch (routeChangeReason) {
+ case AVAudioSessionRouteChangeReasonNewDeviceAvailable: {
+ NSLog(@"AVAudioSessionRouteChangeReasonNewDeviceAvailable");
+ NSLog(@"Headphone/Line plugged in");
+ } break;
+ case AVAudioSessionRouteChangeReasonOldDeviceUnavailable: {
+ NSLog(@"AVAudioSessionRouteChangeReasonOldDeviceUnavailable");
+ NSLog(@"Headphone/Line was pulled. Resuming video play....");
+ if ([self isVideoPlaying]) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+ [self.avPlayer play]; // NOTE: change this line according your current player implementation
+ NSLog(@"resumed play");
+ });
+ }
+ } break;
+ case AVAudioSessionRouteChangeReasonCategoryChange: {
+ // called at start - also when other audio wants to play
+ NSLog(@"AVAudioSessionRouteChangeReasonCategoryChange");
+ } break;
+ }
+}
+
+// MARK: Native Video Player
+
+- (void)handleVideoOrPlayerStatus {
+ if (self.avPlayerItem.status == AVPlayerItemStatusFailed || self.avPlayer.status == AVPlayerStatusFailed) {
+ [self stopVideo];
+ }
+
+ if (self.avPlayer.status == AVPlayerStatusReadyToPlay && self.avPlayerItem.status == AVPlayerItemStatusReadyToPlay && CMTimeCompare(self.videoCurrentTime, kCMTimeZero) == 0) {
+ // NSLog(@"time: %@", self.video_current_time);
+ [self.avPlayer seekToTime:self.videoCurrentTime];
+ self.videoCurrentTime = kCMTimeZero;
+ }
+}
+
+- (void)handleVideoPlayRate {
+ NSLog(@"Player playback rate changed: %.5f", self.avPlayer.rate);
+ if ([self isVideoPlaying] && self.avPlayer.rate == 0.0 && !self.avPlayer.error) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+ [self.avPlayer play]; // NOTE: change this line according your current player implementation
+ NSLog(@"resumed play");
+ });
+
+ NSLog(@" . . . PAUSED (or just started)");
+ }
+}
+
+- (BOOL)playVideoAtPath:(NSString *)filePath volume:(float)videoVolume audio:(NSString *)audioTrack subtitle:(NSString *)subtitleTrack {
+ self.avAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:filePath]];
+
+ self.avPlayerItem = [AVPlayerItem playerItemWithAsset:self.avAsset];
+ [self.avPlayerItem addObserver:self forKeyPath:@"status" options:0 context:nil];
+
+ self.avPlayer = [AVPlayer playerWithPlayerItem:self.avPlayerItem];
+ self.avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
+
+ [self.avPlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(playerItemDidReachEnd:)
+ name:AVPlayerItemDidPlayToEndTimeNotification
+ object:[self.avPlayer currentItem]];
+
+ [self.avPlayer addObserver:self forKeyPath:@"rate" options:NSKeyValueObservingOptionNew context:0];
+
+ [self.avPlayerLayer setFrame:self.bounds];
+ [self.layer addSublayer:self.avPlayerLayer];
+ [self.avPlayer play];
+
+ AVMediaSelectionGroup *audioGroup = [self.avAsset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicAudible];
+
+ NSMutableArray *allAudioParams = [NSMutableArray array];
+ for (id track in audioGroup.options) {
+ NSString *language = [[track locale] localeIdentifier];
+ NSLog(@"subtitle lang: %@", language);
+
+ if ([language isEqualToString:audioTrack]) {
+ AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters];
+ [audioInputParams setVolume:videoVolume atTime:kCMTimeZero];
+ [audioInputParams setTrackID:[track trackID]];
+ [allAudioParams addObject:audioInputParams];
+
+ AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
+ [audioMix setInputParameters:allAudioParams];
+
+ [self.avPlayer.currentItem selectMediaOption:track inMediaSelectionGroup:audioGroup];
+ [self.avPlayer.currentItem setAudioMix:audioMix];
+
+ break;
+ }
+ }
+
+ AVMediaSelectionGroup *subtitlesGroup = [self.avAsset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
+ NSArray *useableTracks = [AVMediaSelectionGroup mediaSelectionOptionsFromArray:subtitlesGroup.options withoutMediaCharacteristics:[NSArray arrayWithObject:AVMediaCharacteristicContainsOnlyForcedSubtitles]];
+
+ for (id track in useableTracks) {
+ NSString *language = [[track locale] localeIdentifier];
+ NSLog(@"subtitle lang: %@", language);
+
+ if ([language isEqualToString:subtitleTrack]) {
+ [self.avPlayer.currentItem selectMediaOption:track inMediaSelectionGroup:subtitlesGroup];
+ break;
+ }
+ }
+
+ self.isVideoCurrentlyPlaying = YES;
+
+ return true;
+}
+
+- (BOOL)isVideoPlaying {
+ if (self.avPlayer.error) {
+ printf("Error during playback\n");
+ }
+ return (self.avPlayer.rate > 0 && !self.avPlayer.error);
+}
+
+- (void)pauseVideo {
+ self.videoCurrentTime = self.avPlayer.currentTime;
+ [self.avPlayer pause];
+ self.isVideoCurrentlyPlaying = NO;
+}
+
+- (void)unpauseVideo {
+ [self.avPlayer play];
+ self.isVideoCurrentlyPlaying = YES;
+}
+
+- (void)playerItemDidReachEnd:(NSNotification *)notification {
+ [self stopVideo];
+}
+
+- (void)finishPlayingVideo {
+ [self.avPlayer pause];
+ [self.avPlayerLayer removeFromSuperlayer];
+ self.avPlayerLayer = nil;
+
+ if (self.avPlayerItem) {
+ [self.avPlayerItem removeObserver:self forKeyPath:@"status"];
+ self.avPlayerItem = nil;
+ }
+
+ if (self.avPlayer) {
+ [self.avPlayer removeObserver:self forKeyPath:@"status"];
+ self.avPlayer = nil;
+ }
+
+ self.avAsset = nil;
+
+ self.isVideoCurrentlyPlaying = NO;
+}
+
+- (void)stopVideo {
+ [self finishPlayingVideo];
+
+ [self removeFromSuperview];
+}
+
+@end
diff --git a/platform/iphone/os_iphone.mm b/platform/iphone/os_iphone.mm
index 5baa5b66fc..e007276b4b 100644
--- a/platform/iphone/os_iphone.mm
+++ b/platform/iphone/os_iphone.mm
@@ -271,7 +271,6 @@ String OSIPhone::get_model_name() const {
Error OSIPhone::shell_open(String p_uri) {
NSString *urlPath = [[NSString alloc] initWithUTF8String:p_uri.utf8().get_data()];
NSURL *url = [NSURL URLWithString:urlPath];
- [urlPath release];
if (![[UIApplication sharedApplication] canOpenURL:url]) {
return ERR_CANT_OPEN;
@@ -279,11 +278,7 @@ Error OSIPhone::shell_open(String p_uri) {
printf("opening url %s\n", p_uri.utf8().get_data());
- // if (@available(iOS 10, *)) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
- // } else {
- // [[UIApplication sharedApplication] openURL:url];
- // }
return OK;
};
diff --git a/platform/iphone/platform_config.h b/platform/iphone/platform_config.h
index 2bbbe47c0d..ec39ad0ba4 100644
--- a/platform/iphone/platform_config.h
+++ b/platform/iphone/platform_config.h
@@ -33,3 +33,10 @@
#define PLATFORM_REFCOUNT
#define PTHREAD_RENAME_SELF
+
+#define _weakify(var) __weak typeof(var) GDWeak_##var = var;
+#define _strongify(var) \
+ _Pragma("clang diagnostic push") \
+ _Pragma("clang diagnostic ignored \"-Wshadow\"") \
+ __strong typeof(var) var = GDWeak_##var; \
+ _Pragma("clang diagnostic pop")
diff --git a/platform/iphone/view_controller.h b/platform/iphone/view_controller.h
index dffdc01d4a..b0b31ae377 100644
--- a/platform/iphone/view_controller.h
+++ b/platform/iphone/view_controller.h
@@ -32,17 +32,15 @@
#import <UIKit/UIKit.h>
@class GodotView;
+@class GodotNativeVideoView;
@interface ViewController : UIViewController <GKGameCenterControllerDelegate>
-- (GodotView *)godotView;
+@property(nonatomic, readonly, strong) GodotView *godotView;
+@property(nonatomic, readonly, strong) GodotNativeVideoView *videoView;
// MARK: Native Video Player
- (BOOL)playVideoAtPath:(NSString *)filePath volume:(float)videoVolume audio:(NSString *)audioTrack subtitle:(NSString *)subtitleTrack;
-- (BOOL)isVideoPlaying;
-- (void)pauseVideo;
-- (void)unpauseVideo;
-- (void)stopVideo;
@end
diff --git a/platform/iphone/view_controller.mm b/platform/iphone/view_controller.mm
index 31597f7856..fb25041779 100644
--- a/platform/iphone/view_controller.mm
+++ b/platform/iphone/view_controller.mm
@@ -33,6 +33,7 @@
#include "display_server_iphone.h"
#import "godot_view.h"
#import "godot_view_renderer.h"
+#import "native_video_view.h"
#include "os_iphone.h"
#import <GameController/GameController.h>
@@ -40,16 +41,7 @@
@interface ViewController ()
@property(strong, nonatomic) GodotViewRenderer *renderer;
-
-// TODO: separate view to handle video
-// AVPlayer-related properties
-@property(strong, nonatomic) AVAsset *avAsset;
-@property(strong, nonatomic) AVPlayerItem *avPlayerItem;
-@property(strong, nonatomic) AVPlayer *avPlayer;
-@property(strong, nonatomic) AVPlayerLayer *avPlayerLayer;
-@property(assign, nonatomic) CMTime videoCurrentTime;
-@property(assign, nonatomic) BOOL isVideoCurrentlyPlaying;
-@property(assign, nonatomic) BOOL videoHasFoundError;
+@property(strong, nonatomic) GodotNativeVideoView *videoView;
@end
@@ -67,9 +59,6 @@
self.view = view;
view.renderer = self.renderer;
-
- [renderer release];
- [view release];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
@@ -93,9 +82,7 @@
}
- (void)godot_commonInit {
- self.isVideoCurrentlyPlaying = NO;
- self.videoCurrentTime = kCMTimeZero;
- self.videoHasFoundError = false;
+ // Initialize view controller values.
}
- (void)didReceiveMemoryWarning {
@@ -107,7 +94,6 @@
[super viewDidLoad];
[self observeKeyboard];
- [self observeAudio];
if (@available(iOS 11.0, *)) {
[self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
@@ -128,33 +114,13 @@
object:nil];
}
-- (void)observeAudio {
- printf("******** adding observer for sound routing changes\n");
- [[NSNotificationCenter defaultCenter]
- addObserver:self
- selector:@selector(audioRouteChangeListenerCallback:)
- name:AVAudioSessionRouteChangeNotification
- object:nil];
-}
-
-- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
- if (object == self.avPlayerItem && [keyPath isEqualToString:@"status"]) {
- [self handleVideoOrPlayerStatus];
- }
-
- if (object == self.avPlayer && [keyPath isEqualToString:@"rate"]) {
- [self handleVideoPlayRate];
- }
-}
-
- (void)dealloc {
- [self stopVideo];
+ [self.videoView stopVideo];
+ self.videoView = nil;
self.renderer = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
-
- [super dealloc];
}
// MARK: Orientation
@@ -233,166 +199,19 @@
}
}
-// MARK: Audio
-
-- (void)audioRouteChangeListenerCallback:(NSNotification *)notification {
- printf("*********** route changed!\n");
- NSDictionary *interuptionDict = notification.userInfo;
-
- NSInteger routeChangeReason = [[interuptionDict valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];
-
- switch (routeChangeReason) {
- case AVAudioSessionRouteChangeReasonNewDeviceAvailable: {
- NSLog(@"AVAudioSessionRouteChangeReasonNewDeviceAvailable");
- NSLog(@"Headphone/Line plugged in");
- } break;
- case AVAudioSessionRouteChangeReasonOldDeviceUnavailable: {
- NSLog(@"AVAudioSessionRouteChangeReasonOldDeviceUnavailable");
- NSLog(@"Headphone/Line was pulled. Resuming video play....");
- if ([self isVideoPlaying]) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- [self.avPlayer play]; // NOTE: change this line according your current player implementation
- NSLog(@"resumed play");
- });
- }
- } break;
- case AVAudioSessionRouteChangeReasonCategoryChange: {
- // called at start - also when other audio wants to play
- NSLog(@"AVAudioSessionRouteChangeReasonCategoryChange");
- } break;
- }
-}
-
// MARK: Native Video Player
-- (void)handleVideoOrPlayerStatus {
- if (self.avPlayerItem.status == AVPlayerItemStatusFailed || self.avPlayer.status == AVPlayerStatusFailed) {
- [self stopVideo];
- self.videoHasFoundError = true;
- }
-
- if (self.avPlayer.status == AVPlayerStatusReadyToPlay && self.avPlayerItem.status == AVPlayerItemStatusReadyToPlay && CMTimeCompare(self.videoCurrentTime, kCMTimeZero) == 0) {
- // NSLog(@"time: %@", self.video_current_time);
- [self.avPlayer seekToTime:self.videoCurrentTime];
- self.videoCurrentTime = kCMTimeZero;
- }
-}
-
-- (void)handleVideoPlayRate {
- NSLog(@"Player playback rate changed: %.5f", self.avPlayer.rate);
- if ([self isVideoPlaying] && self.avPlayer.rate == 0.0 && !self.avPlayer.error) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- [self.avPlayer play]; // NOTE: change this line according your current player implementation
- NSLog(@"resumed play");
- });
-
- NSLog(@" . . . PAUSED (or just started)");
- }
-}
-
- (BOOL)playVideoAtPath:(NSString *)filePath volume:(float)videoVolume audio:(NSString *)audioTrack subtitle:(NSString *)subtitleTrack {
- self.avAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:filePath]];
-
- self.avPlayerItem = [AVPlayerItem playerItemWithAsset:self.avAsset];
- [self.avPlayerItem addObserver:self forKeyPath:@"status" options:0 context:nil];
-
- self.avPlayer = [AVPlayer playerWithPlayerItem:self.avPlayerItem];
- self.avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
-
- [self.avPlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
- [[NSNotificationCenter defaultCenter]
- addObserver:self
- selector:@selector(playerItemDidReachEnd:)
- name:AVPlayerItemDidPlayToEndTimeNotification
- object:[self.avPlayer currentItem]];
-
- [self.avPlayer addObserver:self forKeyPath:@"rate" options:NSKeyValueObservingOptionNew context:0];
-
- [self.avPlayerLayer setFrame:self.view.bounds];
- [self.view.layer addSublayer:self.avPlayerLayer];
- [self.avPlayer play];
-
- AVMediaSelectionGroup *audioGroup = [self.avAsset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicAudible];
-
- NSMutableArray *allAudioParams = [NSMutableArray array];
- for (id track in audioGroup.options) {
- NSString *language = [[track locale] localeIdentifier];
- NSLog(@"subtitle lang: %@", language);
-
- if ([language isEqualToString:audioTrack]) {
- AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters];
- [audioInputParams setVolume:videoVolume atTime:kCMTimeZero];
- [audioInputParams setTrackID:[track trackID]];
- [allAudioParams addObject:audioInputParams];
-
- AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
- [audioMix setInputParameters:allAudioParams];
-
- [self.avPlayer.currentItem selectMediaOption:track inMediaSelectionGroup:audioGroup];
- [self.avPlayer.currentItem setAudioMix:audioMix];
-
- break;
- }
- }
-
- AVMediaSelectionGroup *subtitlesGroup = [self.avAsset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
- NSArray *useableTracks = [AVMediaSelectionGroup mediaSelectionOptionsFromArray:subtitlesGroup.options withoutMediaCharacteristics:[NSArray arrayWithObject:AVMediaCharacteristicContainsOnlyForcedSubtitles]];
-
- for (id track in useableTracks) {
- NSString *language = [[track locale] localeIdentifier];
- NSLog(@"subtitle lang: %@", language);
-
- if ([language isEqualToString:subtitleTrack]) {
- [self.avPlayer.currentItem selectMediaOption:track inMediaSelectionGroup:subtitlesGroup];
- break;
- }
- }
-
- self.isVideoCurrentlyPlaying = YES;
-
- return true;
-}
-
-- (BOOL)isVideoPlaying {
- if (self.avPlayer.error) {
- printf("Error during playback\n");
- }
- return (self.avPlayer.rate > 0 && !self.avPlayer.error);
-}
-
-- (void)pauseVideo {
- self.videoCurrentTime = self.avPlayer.currentTime;
- [self.avPlayer pause];
- self.isVideoCurrentlyPlaying = NO;
-}
-
-- (void)unpauseVideo {
- [self.avPlayer play];
- self.isVideoCurrentlyPlaying = YES;
-}
-
-- (void)playerItemDidReachEnd:(NSNotification *)notification {
- [self stopVideo];
-}
-
-- (void)stopVideo {
- [self.avPlayer pause];
- [self.avPlayerLayer removeFromSuperlayer];
- self.avPlayerLayer = nil;
-
- if (self.avPlayerItem) {
- [self.avPlayerItem removeObserver:self forKeyPath:@"status"];
- self.avPlayerItem = nil;
- }
-
- if (self.avPlayer) {
- [self.avPlayer removeObserver:self forKeyPath:@"status"];
- self.avPlayer = nil;
+ // If we are showing some video already, reuse existing view for new video.
+ if (self.videoView) {
+ return [self.videoView playVideoAtPath:filePath volume:videoVolume audio:audioTrack subtitle:subtitleTrack];
+ } else {
+ // Create autoresizing view for video playback.
+ GodotNativeVideoView *videoView = [[GodotNativeVideoView alloc] initWithFrame:self.view.bounds];
+ videoView.autoresizingMask = UIViewAutoresizingFlexibleWidth & UIViewAutoresizingFlexibleHeight;
+ [self.view addSubview:videoView];
+ return [self.videoView playVideoAtPath:filePath volume:videoVolume audio:audioTrack subtitle:subtitleTrack];
}
-
- self.avAsset = nil;
-
- self.isVideoCurrentlyPlaying = NO;
}
// MARK: Delegates
diff --git a/platform/iphone/vulkan_context_iphone.mm b/platform/iphone/vulkan_context_iphone.mm
index cb4dbe7f85..d62e826957 100644
--- a/platform/iphone/vulkan_context_iphone.mm
+++ b/platform/iphone/vulkan_context_iphone.mm
@@ -35,14 +35,12 @@ const char *VulkanContextIPhone::_get_platform_surface_extension() const {
return VK_MVK_IOS_SURFACE_EXTENSION_NAME;
}
-Error VulkanContextIPhone::window_create(DisplayServer::WindowID p_window_id,
- CALayer *p_metal_layer, int p_width,
- int p_height) {
+Error VulkanContextIPhone::window_create(DisplayServer::WindowID p_window_id, CALayer *p_metal_layer, int p_width, int p_height) {
VkIOSSurfaceCreateInfoMVK createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK;
createInfo.pNext = NULL;
createInfo.flags = 0;
- createInfo.pView = p_metal_layer;
+ createInfo.pView = (__bridge const void *)p_metal_layer;
VkSurfaceKHR surface;
VkResult err =
diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub
index 21456efde5..a8861124b9 100644
--- a/platform/javascript/SCsub
+++ b/platform/javascript/SCsub
@@ -19,6 +19,7 @@ build = env.add_program(build_targets, javascript_files)
js_libraries = [
"native/http_request.js",
+ "native/library_godot_audio.js",
]
for lib in js_libraries:
env.Append(LINKFLAGS=["--js-library", env.File(lib).path])
diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp
index 9604914b2c..6ea948004e 100644
--- a/platform/javascript/audio_driver_javascript.cpp
+++ b/platform/javascript/audio_driver_javascript.cpp
@@ -31,34 +31,57 @@
#include "audio_driver_javascript.h"
#include "core/project_settings.h"
+#include "godot_audio.h"
#include <emscripten.h>
AudioDriverJavaScript *AudioDriverJavaScript::singleton = nullptr;
bool AudioDriverJavaScript::is_available() {
- return EM_ASM_INT({
- if (!(window.AudioContext || window.webkitAudioContext)) {
- return 0;
- }
- return 1;
- }) != 0;
+ return godot_audio_is_available() != 0;
}
const char *AudioDriverJavaScript::get_name() const {
return "JavaScript";
}
-extern "C" EMSCRIPTEN_KEEPALIVE void audio_driver_js_mix() {
- AudioDriverJavaScript::singleton->mix_to_js();
+#ifndef NO_THREADS
+void AudioDriverJavaScript::_audio_thread_func(void *p_data) {
+ AudioDriverJavaScript *obj = static_cast<AudioDriverJavaScript *>(p_data);
+ while (!obj->quit) {
+ obj->lock();
+ if (!obj->needs_process) {
+ obj->unlock();
+ OS::get_singleton()->delay_usec(1000); // Give the browser some slack.
+ continue;
+ }
+ obj->_js_driver_process();
+ obj->needs_process = false;
+ obj->unlock();
+ }
+}
+#endif
+
+extern "C" EMSCRIPTEN_KEEPALIVE void audio_driver_process_start() {
+#ifndef NO_THREADS
+ AudioDriverJavaScript::singleton->lock();
+#else
+ AudioDriverJavaScript::singleton->_js_driver_process();
+#endif
+}
+
+extern "C" EMSCRIPTEN_KEEPALIVE void audio_driver_process_end() {
+#ifndef NO_THREADS
+ AudioDriverJavaScript::singleton->needs_process = true;
+ AudioDriverJavaScript::singleton->unlock();
+#endif
}
extern "C" EMSCRIPTEN_KEEPALIVE void audio_driver_process_capture(float sample) {
AudioDriverJavaScript::singleton->process_capture(sample);
}
-void AudioDriverJavaScript::mix_to_js() {
- int channel_count = get_total_channels_by_speaker_mode(get_speaker_mode());
+void AudioDriverJavaScript::_js_driver_process() {
int sample_count = memarr_len(internal_buffer) / channel_count;
int32_t *stream_buffer = reinterpret_cast<int32_t *>(internal_buffer);
audio_server_process(sample_count, stream_buffer);
@@ -73,37 +96,12 @@ void AudioDriverJavaScript::process_capture(float sample) {
}
Error AudioDriverJavaScript::init() {
- int mix_rate = GLOBAL_GET("audio/mix_rate");
+ mix_rate = GLOBAL_GET("audio/mix_rate");
int latency = GLOBAL_GET("audio/output_latency");
- /* clang-format off */
- _driver_id = EM_ASM_INT({
- const MIX_RATE = $0;
- const LATENCY = $1 / 1000;
- return Module.IDHandler.add({
- 'context': new (window.AudioContext || window.webkitAudioContext)({ sampleRate: MIX_RATE, latencyHint: LATENCY}),
- 'input': null,
- 'stream': null,
- 'script': null
- });
- }, mix_rate, latency);
- /* clang-format on */
-
- int channel_count = get_total_channels_by_speaker_mode(get_speaker_mode());
+ channel_count = godot_audio_init(mix_rate, latency);
buffer_length = closest_power_of_2((latency * mix_rate / 1000) * channel_count);
- /* clang-format off */
- buffer_length = EM_ASM_INT({
- var ref = Module.IDHandler.get($0);
- const ctx = ref['context'];
- const BUFFER_LENGTH = $1;
- const CHANNEL_COUNT = $2;
-
- var script = ctx.createScriptProcessor(BUFFER_LENGTH, 2, CHANNEL_COUNT);
- script.connect(ctx.destination);
- ref['script'] = script;
- return script.bufferSize;
- }, _driver_id, buffer_length, channel_count);
- /* clang-format on */
+ buffer_length = godot_audio_create_processor(buffer_length, channel_count);
if (!buffer_length) {
return FAILED;
}
@@ -114,134 +112,60 @@ Error AudioDriverJavaScript::init() {
internal_buffer = memnew_arr(float, buffer_length *channel_count);
}
- return internal_buffer ? OK : ERR_OUT_OF_MEMORY;
+ if (!internal_buffer) {
+ return ERR_OUT_OF_MEMORY;
+ }
+ return OK;
}
void AudioDriverJavaScript::start() {
- /* clang-format off */
- EM_ASM({
- const ref = Module.IDHandler.get($0);
- var INTERNAL_BUFFER_PTR = $1;
-
- var audioDriverMixFunction = cwrap('audio_driver_js_mix');
- var audioDriverProcessCapture = cwrap('audio_driver_process_capture', null, ['number']);
- ref['script'].onaudioprocess = function(audioProcessingEvent) {
- audioDriverMixFunction();
-
- var input = audioProcessingEvent.inputBuffer;
- var output = audioProcessingEvent.outputBuffer;
- var internalBuffer = HEAPF32.subarray(
- INTERNAL_BUFFER_PTR / HEAPF32.BYTES_PER_ELEMENT,
- INTERNAL_BUFFER_PTR / HEAPF32.BYTES_PER_ELEMENT + output.length * output.numberOfChannels);
-
- for (var channel = 0; channel < output.numberOfChannels; channel++) {
- var outputData = output.getChannelData(channel);
- // Loop through samples.
- for (var sample = 0; sample < outputData.length; sample++) {
- outputData[sample] = internalBuffer[sample * output.numberOfChannels + channel];
- }
- }
-
- if (ref['input']) {
- var inputDataL = input.getChannelData(0);
- var inputDataR = input.getChannelData(1);
- for (var i = 0; i < inputDataL.length; i++) {
- audioDriverProcessCapture(inputDataL[i]);
- audioDriverProcessCapture(inputDataR[i]);
- }
- }
- };
- }, _driver_id, internal_buffer);
- /* clang-format on */
+#ifndef NO_THREADS
+ thread = Thread::create(_audio_thread_func, this);
+#endif
+ godot_audio_start(internal_buffer);
}
void AudioDriverJavaScript::resume() {
- /* clang-format off */
- EM_ASM({
- const ref = Module.IDHandler.get($0);
- if (ref && ref['context'] && ref['context'].resume)
- ref['context'].resume();
- }, _driver_id);
- /* clang-format on */
+ godot_audio_resume();
}
float AudioDriverJavaScript::get_latency() {
- /* clang-format off */
- return EM_ASM_DOUBLE({
- const ref = Module.IDHandler.get($0);
- var latency = 0;
- if (ref && ref['context']) {
- const ctx = ref['context'];
- if (ctx.baseLatency) {
- latency += ctx.baseLatency;
- }
- if (ctx.outputLatency) {
- latency += ctx.outputLatency;
- }
- }
- return latency;
- }, _driver_id);
- /* clang-format on */
+ return godot_audio_get_latency();
}
int AudioDriverJavaScript::get_mix_rate() const {
- /* clang-format off */
- return EM_ASM_INT({
- const ref = Module.IDHandler.get($0);
- return ref && ref['context'] ? ref['context'].sampleRate : 0;
- }, _driver_id);
- /* clang-format on */
+ return mix_rate;
}
AudioDriver::SpeakerMode AudioDriverJavaScript::get_speaker_mode() const {
- /* clang-format off */
- return get_speaker_mode_by_total_channels(EM_ASM_INT({
- const ref = Module.IDHandler.get($0);
- return ref && ref['context'] ? ref['context'].destination.channelCount : 0;
- }, _driver_id));
- /* clang-format on */
+ return get_speaker_mode_by_total_channels(channel_count);
}
-// No locking, as threads are not supported.
void AudioDriverJavaScript::lock() {
+#ifndef NO_THREADS
+ mutex.lock();
+#endif
}
void AudioDriverJavaScript::unlock() {
+#ifndef NO_THREADS
+ mutex.unlock();
+#endif
}
void AudioDriverJavaScript::finish_async() {
- // Close the context, add the operation to the async_finish list in module.
- int id = _driver_id;
- _driver_id = 0;
-
- /* clang-format off */
- EM_ASM({
- const id = $0;
- var ref = Module.IDHandler.get(id);
- Module.async_finish.push(new Promise(function(accept, reject) {
- if (!ref) {
- console.log("Ref not found!", id, Module.IDHandler);
- setTimeout(accept, 0);
- } else {
- Module.IDHandler.remove(id);
- const context = ref['context'];
- // Disconnect script and input.
- ref['script'].disconnect();
- if (ref['input'])
- ref['input'].disconnect();
- ref = null;
- context.close().then(function() {
- accept();
- }).catch(function(e) {
- accept();
- });
- }
- }));
- }, id);
- /* clang-format on */
+#ifndef NO_THREADS
+ quit = true; // Ask thread to quit.
+#endif
+ godot_audio_finish_async();
}
void AudioDriverJavaScript::finish() {
+#ifndef NO_THREADS
+ Thread::wait_to_finish(thread);
+ memdelete(thread);
+ thread = NULL;
+#endif
if (internal_buffer) {
memdelete_arr(internal_buffer);
internal_buffer = nullptr;
@@ -249,56 +173,14 @@ void AudioDriverJavaScript::finish() {
}
Error AudioDriverJavaScript::capture_start() {
+ godot_audio_capture_stop();
input_buffer_init(buffer_length);
-
- /* clang-format off */
- EM_ASM({
- function gotMediaInput(stream) {
- var ref = Module.IDHandler.get($0);
- ref['stream'] = stream;
- ref['input'] = ref['context'].createMediaStreamSource(stream);
- ref['input'].connect(ref['script']);
- }
-
- function gotMediaInputError(e) {
- out(e);
- }
-
- if (navigator.mediaDevices.getUserMedia) {
- navigator.mediaDevices.getUserMedia({"audio": true}).then(gotMediaInput, gotMediaInputError);
- } else {
- if (!navigator.getUserMedia)
- navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
- navigator.getUserMedia({"audio": true}, gotMediaInput, gotMediaInputError);
- }
- }, _driver_id);
- /* clang-format on */
-
+ godot_audio_capture_start();
return OK;
}
Error AudioDriverJavaScript::capture_stop() {
- /* clang-format off */
- EM_ASM({
- var ref = Module.IDHandler.get($0);
- if (ref['stream']) {
- const tracks = ref['stream'].getTracks();
- for (var i = 0; i < tracks.length; i++) {
- tracks[i].stop();
- }
- ref['stream'] = null;
- }
-
- if (ref['input']) {
- ref['input'].disconnect();
- ref['input'] = null;
- }
-
- }, _driver_id);
- /* clang-format on */
-
input_buffer.clear();
-
return OK;
}
diff --git a/platform/javascript/audio_driver_javascript.h b/platform/javascript/audio_driver_javascript.h
index c1607301d7..56a7da0307 100644
--- a/platform/javascript/audio_driver_javascript.h
+++ b/platform/javascript/audio_driver_javascript.h
@@ -33,15 +33,30 @@
#include "servers/audio_server.h"
+#include "core/os/mutex.h"
+#include "core/os/thread.h"
+
class AudioDriverJavaScript : public AudioDriver {
+private:
float *internal_buffer = nullptr;
- int _driver_id = 0;
int buffer_length = 0;
+ int mix_rate = 0;
+ int channel_count = 0;
public:
+#ifndef NO_THREADS
+ Mutex mutex;
+ Thread *thread = nullptr;
+ bool quit = false;
+ bool needs_process = true;
+
+ static void _audio_thread_func(void *p_data);
+#endif
+
+ void _js_driver_process();
+
static bool is_available();
- void mix_to_js();
void process_capture(float sample);
static AudioDriverJavaScript *singleton;
diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py
index 81287cead8..91dd2b4499 100644
--- a/platform/javascript/detect.py
+++ b/platform/javascript/detect.py
@@ -139,6 +139,7 @@ def configure(env):
env.Append(LINKFLAGS=["-s", "USE_PTHREADS=1"])
env.Append(LINKFLAGS=["-s", "PTHREAD_POOL_SIZE=4"])
env.Append(LINKFLAGS=["-s", "WASM_MEM_MAX=2048MB"])
+ env.extra_suffix = ".threads" + env.extra_suffix
else:
env.Append(CPPDEFINES=["NO_THREADS"])
diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp
index 230575abce..a83ff44d20 100644
--- a/platform/javascript/export/export.cpp
+++ b/platform/javascript/export/export.cpp
@@ -124,6 +124,9 @@ public:
String s = "HTTP/1.1 200 OK\r\n";
s += "Connection: Close\r\n";
s += "Content-Type: " + ctype + "\r\n";
+ s += "Access-Control-Allow-Origin: *\r\n";
+ s += "Cross-Origin-Opener-Policy: same-origin\r\n";
+ s += "Cross-Origin-Embedder-Policy: require-corp\r\n";
s += "\r\n";
CharString cs = s.utf8();
Error err = connection->put_data((const uint8_t *)cs.get_data(), cs.size() - 1);
diff --git a/platform/javascript/godot_audio.h b/platform/javascript/godot_audio.h
new file mode 100644
index 0000000000..f7f26e5262
--- /dev/null
+++ b/platform/javascript/godot_audio.h
@@ -0,0 +1,58 @@
+/*************************************************************************/
+/* godot_audio.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef GODOT_AUDIO_H
+#define GODOT_AUDIO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "stddef.h"
+
+extern int godot_audio_is_available();
+
+extern int godot_audio_init(int p_mix_rate, int p_latency);
+extern int godot_audio_create_processor(int p_buffer_length, int p_channel_count);
+
+extern void godot_audio_start(float *r_buffer_ptr);
+extern void godot_audio_resume();
+extern void godot_audio_finish_async();
+
+extern float godot_audio_get_latency();
+
+extern void godot_audio_capture_start();
+extern void godot_audio_capture_stop();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GODOT_AUDIO_H */
diff --git a/platform/javascript/native/library_godot_audio.js b/platform/javascript/native/library_godot_audio.js
new file mode 100644
index 0000000000..d300280ccd
--- /dev/null
+++ b/platform/javascript/native/library_godot_audio.js
@@ -0,0 +1,173 @@
+/*************************************************************************/
+/* library_godot_audio.js */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+var GodotAudio = {
+
+ $GodotAudio: {
+
+ ctx: null,
+ input: null,
+ script: null,
+ },
+
+ godot_audio_is_available__proxy: 'sync',
+ godot_audio_is_available: function () {
+ if (!(window.AudioContext || window.webkitAudioContext)) {
+ return 0;
+ }
+ return 1;
+ },
+
+ godot_audio_init: function(mix_rate, latency) {
+ GodotAudio.ctx = new (window.AudioContext || window.webkitAudioContext)({
+ sampleRate: mix_rate,
+ latencyHint: latency
+ });
+ return GodotAudio.ctx.destination.channelCount;
+ },
+
+ godot_audio_create_processor: function(buffer_length, channel_count) {
+ GodotAudio.script = GodotAudio.ctx.createScriptProcessor(buffer_length, 2, channel_count);
+ GodotAudio.script.connect(GodotAudio.ctx.destination);
+ return GodotAudio.script.bufferSize;
+ },
+
+ godot_audio_start: function(buffer_ptr) {
+ var audioDriverProcessStart = cwrap('audio_driver_process_start');
+ var audioDriverProcessEnd = cwrap('audio_driver_process_end');
+ var audioDriverProcessCapture = cwrap('audio_driver_process_capture', null, ['number']);
+ GodotAudio.script.onaudioprocess = function(audioProcessingEvent) {
+ audioDriverProcessStart();
+
+ var input = audioProcessingEvent.inputBuffer;
+ var output = audioProcessingEvent.outputBuffer;
+ var internalBuffer = HEAPF32.subarray(
+ buffer_ptr / HEAPF32.BYTES_PER_ELEMENT,
+ buffer_ptr / HEAPF32.BYTES_PER_ELEMENT + output.length * output.numberOfChannels);
+ for (var channel = 0; channel < output.numberOfChannels; channel++) {
+ var outputData = output.getChannelData(channel);
+ // Loop through samples.
+ for (var sample = 0; sample < outputData.length; sample++) {
+ outputData[sample] = internalBuffer[sample * output.numberOfChannels + channel];
+ }
+ }
+
+ if (GodotAudio.input) {
+ var inputDataL = input.getChannelData(0);
+ var inputDataR = input.getChannelData(1);
+ for (var i = 0; i < inputDataL.length; i++) {
+ audioDriverProcessCapture(inputDataL[i]);
+ audioDriverProcessCapture(inputDataR[i]);
+ }
+ }
+ audioDriverProcessEnd();
+ };
+ },
+
+ godot_audio_resume: function() {
+ if (GodotAudio.ctx && GodotAudio.ctx.state != 'running') {
+ GodotAudio.ctx.resume();
+ }
+ },
+
+ godot_audio_finish_async: function() {
+ Module.async_finish.push(new Promise(function(accept, reject) {
+ if (!GodotAudio.ctx) {
+ setTimeout(accept, 0);
+ } else {
+ if (GodotAudio.script) {
+ GodotAudio.script.disconnect();
+ GodotAudio.script = null;
+ }
+ if (GodotAudio.input) {
+ GodotAudio.input.disconnect();
+ GodotAudio.input = null;
+ }
+ GodotAudio.ctx.close().then(function() {
+ accept();
+ }).catch(function(e) {
+ accept();
+ });
+ GodotAudio.ctx = null;
+ }
+ }));
+ },
+
+ godot_audio_get_latency__proxy: 'sync',
+ godot_audio_get_latency: function() {
+ var latency = 0;
+ if (GodotAudio.ctx) {
+ if (GodotAudio.ctx.baseLatency) {
+ latency += GodotAudio.ctx.baseLatency;
+ }
+ if (GodotAudio.ctx.outputLatency) {
+ latency += GodotAudio.ctx.outputLatency;
+ }
+ }
+ return latency;
+ },
+
+ godot_audio_capture_start__proxy: 'sync',
+ godot_audio_capture_start: function() {
+ if (GodotAudio.input) {
+ return; // Already started.
+ }
+ function gotMediaInput(stream) {
+ GodotAudio.input = GodotAudio.ctx.createMediaStreamSource(stream);
+ GodotAudio.input.connect(GodotAudio.script);
+ }
+
+ function gotMediaInputError(e) {
+ out(e);
+ }
+
+ if (navigator.mediaDevices.getUserMedia) {
+ navigator.mediaDevices.getUserMedia({"audio": true}).then(gotMediaInput, gotMediaInputError);
+ } else {
+ if (!navigator.getUserMedia)
+ navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
+ navigator.getUserMedia({"audio": true}, gotMediaInput, gotMediaInputError);
+ }
+ },
+
+ godot_audio_capture_stop__proxy: 'sync',
+ godot_audio_capture_stop: function() {
+ if (GodotAudio.input) {
+ const tracks = GodotAudio.input.mediaStream.getTracks();
+ for (var i = 0; i < tracks.length; i++) {
+ tracks[i].stop();
+ }
+ GodotAudio.input.disconnect();
+ GodotAudio.input = null;
+ }
+ },
+};
+
+autoAddDeps(GodotAudio, "$GodotAudio");
+mergeInto(LibraryManager.library, GodotAudio);
diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp
index 52bf122789..217a210342 100644
--- a/scene/2d/light_2d.cpp
+++ b/scene/2d/light_2d.cpp
@@ -313,8 +313,9 @@ String Light2D::get_configuration_warning() const {
String warning = Node2D::get_configuration_warning();
if (!texture.is_valid()) {
- if (!warning.empty())
+ if (!warning.empty()) {
warning += "\n\n";
+ }
warning += TTR("A texture with the shape of the light must be supplied to the \"Texture\" property.");
}
diff --git a/scene/3d/collision_shape_3d.cpp b/scene/3d/collision_shape_3d.cpp
index 6ff0ce6032..e1c691b89a 100644
--- a/scene/3d/collision_shape_3d.cpp
+++ b/scene/3d/collision_shape_3d.cpp
@@ -140,15 +140,14 @@ String CollisionShape3D::get_configuration_warning() const {
warning += TTR("A shape must be provided for CollisionShape3D to function. Please create a shape resource for it.");
}
- if (Object::cast_to<RigidBody3D>(get_parent())) {
- if (Object::cast_to<ConcavePolygonShape3D>(*shape)) {
- if (Object::cast_to<RigidBody3D>(get_parent())->get_mode() != RigidBody3D::MODE_STATIC) {
- if (!warning.empty()) {
- warning += "\n\n";
- }
- warning += TTR("ConcavePolygonShape3D doesn't support RigidBody3D in another mode than static.");
- }
+ if (shape.is_valid() &&
+ Object::cast_to<RigidBody3D>(get_parent()) &&
+ Object::cast_to<ConcavePolygonShape3D>(*shape) &&
+ Object::cast_to<RigidBody3D>(get_parent())->get_mode() != RigidBody3D::MODE_STATIC) {
+ if (!warning.empty()) {
+ warning += "\n\n";
}
+ warning += TTR("ConcavePolygonShape3D doesn't support RigidBody3D in another mode than static.");
}
return warning;
diff --git a/scene/3d/navigation_region_3d.cpp b/scene/3d/navigation_region_3d.cpp
index 71bc74f433..3d3467583d 100644
--- a/scene/3d/navigation_region_3d.cpp
+++ b/scene/3d/navigation_region_3d.cpp
@@ -197,10 +197,12 @@ String NavigationRegion3D::get_configuration_warning() const {
}
warning += TTR("A NavigationMesh resource must be set or created for this node to work.");
}
+
const Node3D *c = this;
while (c) {
- if (Object::cast_to<Navigation3D>(c))
+ if (Object::cast_to<Navigation3D>(c)) {
return warning;
+ }
c = Object::cast_to<Node3D>(c->get_parent());
}
diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp
index bf1445edf2..35c4b9d08d 100644
--- a/scene/3d/node_3d.cpp
+++ b/scene/3d/node_3d.cpp
@@ -103,7 +103,7 @@ void Node3D::_propagate_transform_changed(Node3D *p_origin) {
data.children_lock++;
for (List<Node3D *>::Element *E = data.children.front(); E; E = E->next()) {
- if (E->get()->data.toplevel_active) {
+ if (E->get()->data.top_level_active) {
continue; //don't propagate to a toplevel
}
E->get()->_propagate_transform_changed(p_origin);
@@ -136,12 +136,12 @@ void Node3D::_notification(int p_what) {
data.C = nullptr;
}
- if (data.toplevel && !Engine::get_singleton()->is_editor_hint()) {
+ if (data.top_level && !Engine::get_singleton()->is_editor_hint()) {
if (data.parent) {
data.local_transform = data.parent->get_global_transform() * get_transform();
data.dirty = DIRTY_VECTORS; //global is always dirty upon entering a scene
}
- data.toplevel_active = true;
+ data.top_level_active = true;
}
data.dirty |= DIRTY_GLOBAL; //global is always dirty upon entering a scene
@@ -160,7 +160,7 @@ void Node3D::_notification(int p_what) {
}
data.parent = nullptr;
data.C = nullptr;
- data.toplevel_active = false;
+ data.top_level_active = false;
} break;
case NOTIFICATION_ENTER_WORLD: {
data.inside_world = true;
@@ -238,7 +238,7 @@ void Node3D::set_transform(const Transform &p_transform) {
void Node3D::set_global_transform(const Transform &p_transform) {
Transform xform =
- (data.parent && !data.toplevel_active) ?
+ (data.parent && !data.top_level_active) ?
data.parent->get_global_transform().affine_inverse() * p_transform :
p_transform;
@@ -261,7 +261,7 @@ Transform Node3D::get_global_transform() const {
_update_local_transform();
}
- if (data.parent && !data.toplevel_active) {
+ if (data.parent && !data.top_level_active) {
data.global_transform = data.parent->get_global_transform() * data.local_transform;
} else {
data.global_transform = data.local_transform;
@@ -462,8 +462,8 @@ bool Node3D::is_scale_disabled() const {
return data.disable_scale;
}
-void Node3D::set_as_toplevel(bool p_enabled) {
- if (data.toplevel == p_enabled) {
+void Node3D::set_as_top_level(bool p_enabled) {
+ if (data.top_level == p_enabled) {
return;
}
if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
@@ -473,16 +473,16 @@ void Node3D::set_as_toplevel(bool p_enabled) {
set_transform(data.parent->get_global_transform().affine_inverse() * get_global_transform());
}
- data.toplevel = p_enabled;
- data.toplevel_active = p_enabled;
+ data.top_level = p_enabled;
+ data.top_level_active = p_enabled;
} else {
- data.toplevel = p_enabled;
+ data.top_level = p_enabled;
}
}
-bool Node3D::is_set_as_toplevel() const {
- return data.toplevel;
+bool Node3D::is_set_as_top_level() const {
+ return data.top_level;
}
Ref<World3D> Node3D::get_world_3d() const {
@@ -715,8 +715,8 @@ void Node3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_global_transform"), &Node3D::get_global_transform);
ClassDB::bind_method(D_METHOD("get_parent_spatial"), &Node3D::get_parent_spatial);
ClassDB::bind_method(D_METHOD("set_ignore_transform_notification", "enabled"), &Node3D::set_ignore_transform_notification);
- ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &Node3D::set_as_toplevel);
- ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &Node3D::is_set_as_toplevel);
+ ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &Node3D::set_as_top_level);
+ ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &Node3D::is_set_as_top_level);
ClassDB::bind_method(D_METHOD("set_disable_scale", "disable"), &Node3D::set_disable_scale);
ClassDB::bind_method(D_METHOD("is_scale_disabled"), &Node3D::is_scale_disabled);
ClassDB::bind_method(D_METHOD("get_world_3d"), &Node3D::get_world_3d);
@@ -789,8 +789,8 @@ Node3D::Node3D() :
data.children_lock = 0;
data.ignore_notification = false;
- data.toplevel = false;
- data.toplevel_active = false;
+ data.top_level = false;
+ data.top_level_active = false;
data.scale = Vector3(1, 1, 1);
data.viewport = nullptr;
data.inside_world = false;
diff --git a/scene/3d/node_3d.h b/scene/3d/node_3d.h
index 327d4671e9..229e0f2c8c 100644
--- a/scene/3d/node_3d.h
+++ b/scene/3d/node_3d.h
@@ -71,8 +71,8 @@ class Node3D : public Node {
Viewport *viewport;
- bool toplevel_active;
- bool toplevel;
+ bool top_level_active;
+ bool top_level;
bool inside_world;
int children_lock;
@@ -144,8 +144,8 @@ public:
virtual Transform get_local_gizmo_transform() const;
#endif
- void set_as_toplevel(bool p_enabled);
- bool is_set_as_toplevel() const;
+ void set_as_top_level(bool p_enabled);
+ bool is_set_as_top_level() const;
void set_disable_scale(bool p_enabled);
bool is_scale_disabled() const;
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp
index 9a127c5425..193d016010 100644
--- a/scene/3d/physics_body_3d.cpp
+++ b/scene/3d/physics_body_3d.cpp
@@ -2606,7 +2606,7 @@ void PhysicalBone3D::_start_physics_simulation() {
PhysicsServer3D::get_singleton()->body_set_collision_layer(get_rid(), get_collision_layer());
PhysicsServer3D::get_singleton()->body_set_collision_mask(get_rid(), get_collision_mask());
PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed");
- set_as_toplevel(true);
+ set_as_top_level(true);
_internal_simulate_physics = true;
}
@@ -2626,7 +2626,7 @@ void PhysicalBone3D::_stop_physics_simulation() {
if (_internal_simulate_physics) {
PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), nullptr, "");
parent_skeleton->set_bone_global_pose_override(bone_id, Transform(), 0.0, false);
- set_as_toplevel(false);
+ set_as_top_level(false);
_internal_simulate_physics = false;
}
}
diff --git a/scene/3d/soft_body_3d.cpp b/scene/3d/soft_body_3d.cpp
index d3d7cdc1ce..94e9555a1a 100644
--- a/scene/3d/soft_body_3d.cpp
+++ b/scene/3d/soft_body_3d.cpp
@@ -282,7 +282,7 @@ void SoftBody3D::_notification(int p_what) {
set_notify_transform(false);
// Required to be top level with Transform at center of world in order to modify RenderingServer only to support custom Transform
- set_as_toplevel(true);
+ set_as_top_level(true);
set_transform(Transform());
set_notify_transform(true);
diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp
index f130726837..33e030a573 100644
--- a/scene/gui/box_container.cpp
+++ b/scene/gui/box_container.cpp
@@ -57,7 +57,7 @@ void BoxContainer::_resort() {
if (!c || !c->is_visible_in_tree()) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
@@ -111,7 +111,7 @@ void BoxContainer::_resort() {
if (!c || !c->is_visible_in_tree()) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
@@ -172,7 +172,7 @@ void BoxContainer::_resort() {
if (!c || !c->is_visible_in_tree()) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
@@ -224,7 +224,7 @@ Size2 BoxContainer::get_minimum_size() const {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
diff --git a/scene/gui/center_container.cpp b/scene/gui/center_container.cpp
index f8f9bec3d7..1a72f3ca4d 100644
--- a/scene/gui/center_container.cpp
+++ b/scene/gui/center_container.cpp
@@ -40,7 +40,7 @@ Size2 CenterContainer::get_minimum_size() const {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
if (!c->is_visible()) {
@@ -77,7 +77,7 @@ void CenterContainer::_notification(int p_what) {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index cbe0367c7b..f8a67d154b 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -610,7 +610,7 @@ void ColorPicker::_screen_pick_pressed() {
if (!screen) {
screen = memnew(Control);
r->add_child(screen);
- screen->set_as_toplevel(true);
+ screen->set_as_top_level(true);
screen->set_anchors_and_margins_preset(Control::PRESET_WIDE);
screen->set_default_cursor_shape(CURSOR_POINTING_HAND);
screen->connect("gui_input", callable_mp(this, &ColorPicker::_screen_input));
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 8d1dd5afeb..17febc8d66 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -493,7 +493,7 @@ void Control::_notification(int p_notification) {
}
CanvasItem *ci = Object::cast_to<CanvasItem>(parent);
- if (ci && ci->is_set_as_toplevel()) {
+ if (ci && ci->is_set_as_top_level()) {
subwindow = true;
break;
}
@@ -532,7 +532,7 @@ void Control::_notification(int p_notification) {
if (data.parent_canvas_item) {
data.parent_canvas_item->disconnect("item_rect_changed", callable_mp(this, &Control::_size_changed));
data.parent_canvas_item = nullptr;
- } else if (!is_set_as_toplevel()) {
+ } else if (!is_set_as_top_level()) {
//disconnect viewport
get_viewport()->disconnect("size_changed", callable_mp(this, &Control::_size_changed));
}
@@ -1816,7 +1816,7 @@ void Control::set_focus_mode(FocusMode p_focus_mode) {
}
static Control *_next_control(Control *p_from) {
- if (p_from->is_set_as_toplevel()) {
+ if (p_from->is_set_as_top_level()) {
return nullptr; // can't go above
}
@@ -1830,7 +1830,7 @@ static Control *_next_control(Control *p_from) {
ERR_FAIL_INDEX_V(next, parent->get_child_count(), nullptr);
for (int i = (next + 1); i < parent->get_child_count(); i++) {
Control *c = Object::cast_to<Control>(parent->get_child(i));
- if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
+ if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
continue;
}
@@ -1867,7 +1867,7 @@ Control *Control::find_next_valid_focus() const {
for (int i = 0; i < from->get_child_count(); i++) {
Control *c = Object::cast_to<Control>(from->get_child(i));
- if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
+ if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
continue;
}
@@ -1879,7 +1879,7 @@ Control *Control::find_next_valid_focus() const {
next_child = _next_control(from);
if (!next_child) { //nothing else.. go up and find either window or subwindow
next_child = const_cast<Control *>(this);
- while (next_child && !next_child->is_set_as_toplevel()) {
+ while (next_child && !next_child->is_set_as_top_level()) {
next_child = cast_to<Control>(next_child->get_parent());
}
@@ -1915,7 +1915,7 @@ static Control *_prev_control(Control *p_from) {
Control *child = nullptr;
for (int i = p_from->get_child_count() - 1; i >= 0; i--) {
Control *c = Object::cast_to<Control>(p_from->get_child(i));
- if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
+ if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
continue;
}
@@ -1955,7 +1955,7 @@ Control *Control::find_prev_valid_focus() const {
Control *prev_child = nullptr;
- if (from->is_set_as_toplevel() || !Object::cast_to<Control>(from->get_parent())) {
+ if (from->is_set_as_top_level() || !Object::cast_to<Control>(from->get_parent())) {
//find last of the children
prev_child = _prev_control(from);
@@ -1964,7 +1964,7 @@ Control *Control::find_prev_valid_focus() const {
for (int i = (from->get_index() - 1); i >= 0; i--) {
Control *c = Object::cast_to<Control>(from->get_parent()->get_child(i));
- if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
+ if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
continue;
}
@@ -2024,7 +2024,7 @@ void Control::release_focus() {
}
bool Control::is_toplevel_control() const {
- return is_inside_tree() && (!data.parent_canvas_item && !data.RI && is_set_as_toplevel());
+ return is_inside_tree() && (!data.parent_canvas_item && !data.RI && is_set_as_top_level());
}
void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_owner_window, bool p_assign) {
@@ -2374,7 +2374,7 @@ void Control::minimum_size_changed() {
//invalidate cache upwards
while (invalidate && invalidate->data.minimum_size_valid) {
invalidate->data.minimum_size_valid = false;
- if (invalidate->is_set_as_toplevel()) {
+ if (invalidate->is_set_as_top_level()) {
break; // do not go further up
}
if (!invalidate->data.parent && get_parent()) {
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index 9077bfa4ba..430e98d50e 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -181,7 +181,7 @@ void AcceptDialog::_update_child_rects() {
continue;
}
- if (c == hbc || c == label || c == bg || c->is_set_as_toplevel()) {
+ if (c == hbc || c == label || c == bg || c->is_set_as_top_level()) {
continue;
}
@@ -209,7 +209,7 @@ Size2 AcceptDialog::_get_contents_minimum_size() const {
continue;
}
- if (c == hbc || c == label || c->is_set_as_toplevel()) {
+ if (c == hbc || c == label || c->is_set_as_top_level()) {
continue;
}
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 467d252c81..a7c15e7027 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -547,7 +547,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
}
bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &pos) {
- if (p_control->is_set_as_toplevel() || !p_control->is_visible()) {
+ if (p_control->is_set_as_top_level() || !p_control->is_visible()) {
return false;
}
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index 01b54ddaa8..38bf31830f 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -102,7 +102,7 @@ void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
int idx = 0;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || c->is_set_as_toplevel()) {
+ if (!c || c->is_set_as_top_level()) {
continue;
}
@@ -131,7 +131,7 @@ void GraphNode::_resort() {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
@@ -156,7 +156,7 @@ void GraphNode::_resort() {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
@@ -388,7 +388,7 @@ Size2 GraphNode::get_minimum_size() const {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
@@ -477,7 +477,7 @@ void GraphNode::_connpos_update() {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp
index 0299065f77..b674b492d8 100644
--- a/scene/gui/margin_container.cpp
+++ b/scene/gui/margin_container.cpp
@@ -43,7 +43,7 @@ Size2 MarginContainer::get_minimum_size() const {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
if (!c->is_visible()) {
@@ -80,7 +80,7 @@ void MarginContainer::_notification(int p_what) {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp
index 9abdfac009..051b4de825 100644
--- a/scene/gui/panel_container.cpp
+++ b/scene/gui/panel_container.cpp
@@ -45,7 +45,7 @@ Size2 PanelContainer::get_minimum_size() const {
if (!c || !c->is_visible()) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
@@ -95,7 +95,7 @@ void PanelContainer::_notification(int p_what) {
if (!c || !c->is_visible_in_tree()) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index 8a65aa5032..de866fa956 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -191,7 +191,7 @@ Size2 PopupPanel::_get_contents_minimum_size() const {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
@@ -215,7 +215,7 @@ void PopupPanel::_update_child_rects() {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index 5a3b94b198..f4e31c45d2 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -45,7 +45,7 @@ Size2 ScrollContainer::get_minimum_size() const {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
if (c == h_scroll || c == v_scroll) {
@@ -285,7 +285,7 @@ void ScrollContainer::_notification(int p_what) {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
if (c == h_scroll || c == v_scroll) {
@@ -529,7 +529,7 @@ String ScrollContainer::get_configuration_warning() const {
if (!c) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
if (c == h_scroll || c == v_scroll) {
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index 5c60153d91..6508be1e43 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -41,7 +41,7 @@ Control *SplitContainer::_getch(int p_idx) const {
if (!c || !c->is_visible_in_tree()) {
continue;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
continue;
}
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 41b8fad49d..14a10ea627 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -478,7 +478,7 @@ void TabContainer::_on_mouse_exited() {
int TabContainer::_get_tab_width(int p_index) const {
ERR_FAIL_INDEX_V(p_index, get_tab_count(), 0);
Control *control = Object::cast_to<Control>(_get_tabs()[p_index]);
- if (!control || control->is_set_as_toplevel() || get_tab_hidden(p_index)) {
+ if (!control || control->is_set_as_top_level() || get_tab_hidden(p_index)) {
return 0;
}
@@ -537,7 +537,7 @@ void TabContainer::add_child_notify(Node *p_child) {
if (!c) {
return;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
return;
}
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index 564de31dca..2b83e4f532 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -499,7 +499,7 @@ void CanvasItem::_toplevel_raise_self() {
}
void CanvasItem::_enter_canvas() {
- if ((!Object::cast_to<CanvasItem>(get_parent())) || toplevel) {
+ if ((!Object::cast_to<CanvasItem>(get_parent())) || top_level) {
Node *n = this;
canvas_layer = nullptr;
@@ -674,27 +674,27 @@ Color CanvasItem::get_modulate() const {
return modulate;
}
-void CanvasItem::set_as_toplevel(bool p_toplevel) {
- if (toplevel == p_toplevel) {
+void CanvasItem::set_as_top_level(bool p_toplevel) {
+ if (top_level == p_toplevel) {
return;
}
if (!is_inside_tree()) {
- toplevel = p_toplevel;
+ top_level = p_toplevel;
return;
}
_exit_canvas();
- toplevel = p_toplevel;
+ top_level = p_toplevel;
_enter_canvas();
}
-bool CanvasItem::is_set_as_toplevel() const {
- return toplevel;
+bool CanvasItem::is_set_as_top_level() const {
+ return top_level;
}
CanvasItem *CanvasItem::get_parent_item() const {
- if (toplevel) {
+ if (top_level) {
return nullptr;
}
@@ -967,7 +967,7 @@ void CanvasItem::_notify_transform(CanvasItem *p_node) {
for (List<CanvasItem *>::Element *E = p_node->children_items.front(); E; E = E->next()) {
CanvasItem *ci = E->get();
- if (ci->toplevel) {
+ if (ci->top_level) {
continue;
}
_notify_transform(ci);
@@ -997,9 +997,9 @@ ObjectID CanvasItem::get_canvas_layer_instance_id() const {
}
}
-CanvasItem *CanvasItem::get_toplevel() const {
+CanvasItem *CanvasItem::get_top_level() const {
CanvasItem *ci = const_cast<CanvasItem *>(this);
- while (!ci->toplevel && Object::cast_to<CanvasItem>(ci->get_parent())) {
+ while (!ci->top_level && Object::cast_to<CanvasItem>(ci->get_parent())) {
ci = Object::cast_to<CanvasItem>(ci->get_parent());
}
@@ -1009,7 +1009,7 @@ CanvasItem *CanvasItem::get_toplevel() const {
Ref<World2D> CanvasItem::get_world_2d() const {
ERR_FAIL_COND_V(!is_inside_tree(), Ref<World2D>());
- CanvasItem *tl = get_toplevel();
+ CanvasItem *tl = get_top_level();
if (tl->get_viewport()) {
return tl->get_viewport()->find_world_2d();
@@ -1136,8 +1136,8 @@ void CanvasItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("update"), &CanvasItem::update);
- ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &CanvasItem::set_as_toplevel);
- ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &CanvasItem::is_set_as_toplevel);
+ ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &CanvasItem::set_as_top_level);
+ ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &CanvasItem::is_set_as_top_level);
ClassDB::bind_method(D_METHOD("set_light_mask", "light_mask"), &CanvasItem::set_light_mask);
ClassDB::bind_method(D_METHOD("get_light_mask"), &CanvasItem::get_light_mask);
@@ -1218,7 +1218,7 @@ void CanvasItem::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "self_modulate"), "set_self_modulate", "get_self_modulate");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_behind_parent"), "set_draw_behind_parent", "is_draw_behind_parent_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "toplevel"), "set_as_toplevel", "is_set_as_toplevel");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "top_level"), "set_as_top_level", "is_set_as_top_level");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_on_top", PROPERTY_HINT_NONE, "", 0), "_set_on_top", "_is_on_top"); //compatibility
ADD_PROPERTY(PropertyInfo(Variant::INT, "light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_light_mask", "get_light_mask");
@@ -1354,7 +1354,7 @@ void CanvasItem::_update_texture_filter_changed(bool p_propagate) {
if (p_propagate) {
for (List<CanvasItem *>::Element *E = children_items.front(); E; E = E->next()) {
- if (!E->get()->toplevel && E->get()->texture_filter == TEXTURE_FILTER_PARENT_NODE) {
+ if (!E->get()->top_level && E->get()->texture_filter == TEXTURE_FILTER_PARENT_NODE) {
E->get()->_update_texture_filter_changed(true);
}
}
@@ -1407,7 +1407,7 @@ void CanvasItem::_update_texture_repeat_changed(bool p_propagate) {
update();
if (p_propagate) {
for (List<CanvasItem *>::Element *E = children_items.front(); E; E = E->next()) {
- if (!E->get()->toplevel && E->get()->texture_repeat == TEXTURE_REPEAT_PARENT_NODE) {
+ if (!E->get()->top_level && E->get()->texture_repeat == TEXTURE_REPEAT_PARENT_NODE) {
E->get()->_update_texture_repeat_changed(true);
}
}
@@ -1436,7 +1436,7 @@ CanvasItem::CanvasItem() :
pending_update = false;
modulate = Color(1, 1, 1, 1);
self_modulate = Color(1, 1, 1, 1);
- toplevel = false;
+ top_level = false;
first_draw = false;
drawing = false;
behind = false;
diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h
index 3f32df87a7..457ec2feef 100644
--- a/scene/main/canvas_item.h
+++ b/scene/main/canvas_item.h
@@ -201,7 +201,7 @@ private:
bool first_draw;
bool visible;
bool pending_update;
- bool toplevel;
+ bool top_level;
bool drawing;
bool block_transform_notify;
bool behind;
@@ -355,8 +355,8 @@ public:
/* RECT / TRANSFORM */
- void set_as_toplevel(bool p_toplevel);
- bool is_set_as_toplevel() const;
+ void set_as_top_level(bool p_toplevel);
+ bool is_set_as_top_level() const;
void set_draw_behind_parent(bool p_enable);
bool is_draw_behind_parent_enabled() const;
@@ -369,7 +369,7 @@ public:
virtual Transform2D get_global_transform_with_canvas() const;
virtual Transform2D get_screen_transform() const;
- CanvasItem *get_toplevel() const;
+ CanvasItem *get_top_level() const;
_FORCE_INLINE_ RID get_canvas_item() const {
return canvas_item;
}
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 5e91e4fe42..3c7475a150 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1493,7 +1493,7 @@ String Viewport::_gui_get_tooltip(Control *p_control, const Vector2 &p_pos, Cont
if (p_control->data.mouse_filter == Control::MOUSE_FILTER_STOP) {
break;
}
- if (p_control->is_set_as_toplevel()) {
+ if (p_control->is_set_as_top_level()) {
break;
}
@@ -1620,7 +1620,7 @@ void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu
}
}
- if (!control->is_inside_tree() || control->is_set_as_toplevel()) {
+ if (!control->is_inside_tree() || control->is_set_as_top_level()) {
break;
}
if (gui.key_event_accepted) {
@@ -1631,7 +1631,7 @@ void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu
}
}
- if (ci->is_set_as_toplevel()) {
+ if (ci->is_set_as_top_level()) {
break;
}
@@ -1655,7 +1655,7 @@ void Viewport::_gui_call_notification(Control *p_control, int p_what) {
break;
}
- if (!control->is_inside_tree() || control->is_set_as_toplevel()) {
+ if (!control->is_inside_tree() || control->is_set_as_top_level()) {
break;
}
if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP) {
@@ -1663,7 +1663,7 @@ void Viewport::_gui_call_notification(Control *p_control, int p_what) {
}
}
- if (ci->is_set_as_toplevel()) {
+ if (ci->is_set_as_top_level()) {
break;
}
@@ -1721,7 +1721,7 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_
if (!c || !c->clips_input() || c->has_point(matrix.affine_inverse().xform(p_global))) {
for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
CanvasItem *ci = Object::cast_to<CanvasItem>(p_node->get_child(i));
- if (!ci || ci->is_set_as_toplevel()) {
+ if (!ci || ci->is_set_as_top_level()) {
continue;
}
@@ -1768,7 +1768,7 @@ bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_che
p_at_pos = ci->get_transform().xform(p_at_pos);
- if (ci->is_set_as_toplevel()) {
+ if (ci->is_set_as_top_level()) {
break;
}
@@ -1865,7 +1865,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
}
}
- if (ci->is_set_as_toplevel()) {
+ if (ci->is_set_as_top_level()) {
break;
}
@@ -1993,7 +1993,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
}
}
- if (ci->is_set_as_toplevel()) {
+ if (ci->is_set_as_top_level()) {
break;
}
@@ -2105,7 +2105,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
if (c->data.mouse_filter == Control::MOUSE_FILTER_STOP) {
break;
}
- if (c->is_set_as_toplevel()) {
+ if (c->is_set_as_top_level()) {
break;
}
c = c->get_parent_control();
@@ -2404,7 +2404,7 @@ void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) {
if (gui.drag_preview) {
memdelete(gui.drag_preview);
}
- p_control->set_as_toplevel(true);
+ p_control->set_as_top_level(true);
p_control->set_position(gui.last_mouse_pos);
p_base->get_root_parent_control()->add_child(p_control); //add as child of viewport
p_control->raise();