feat: updated engine version to 4.4-rc1

This commit is contained in:
Sara 2025-02-23 14:38:14 +01:00
parent ee00efde1f
commit 21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *
Import("env")

View file

@ -35,7 +35,6 @@
#include "scene/main/canvas_layer.h"
#include "scene/main/window.h"
#include "scene/resources/atlas_texture.h"
#include "scene/resources/canvas_item_material.h"
#include "scene/resources/font.h"
#include "scene/resources/multimesh.h"
#include "scene/resources/style_box.h"
@ -44,7 +43,7 @@
#define ERR_DRAW_GUARD \
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside this node's `_draw()`, functions connected to its `draw` signal, or when it receives NOTIFICATION_DRAW.")
#ifdef TOOLS_ENABLED
#ifdef DEBUG_ENABLED
bool CanvasItem::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
if (_edit_use_rect()) {
return _edit_get_rect().has_point(p_point);
@ -52,11 +51,13 @@ bool CanvasItem::_edit_is_selected_on_click(const Point2 &p_point, double p_tole
return p_point.length() < p_tolerance;
}
}
#endif // DEBUG_ENABLED
#ifdef TOOLS_ENABLED
Transform2D CanvasItem::_edit_get_transform() const {
return Transform2D(_edit_get_rotation(), _edit_get_position() + _edit_get_pivot());
}
#endif
#endif //TOOLS_ENABLED
bool CanvasItem::is_visible_in_tree() const {
ERR_READ_THREAD_GUARD_V(false);
@ -187,6 +188,20 @@ Transform2D CanvasItem::get_global_transform() const {
return global_transform;
}
// Same as get_global_transform() but no reset for `global_invalid`.
Transform2D CanvasItem::get_global_transform_const() const {
if (_is_global_invalid()) {
const CanvasItem *pi = get_parent_item();
if (pi) {
global_transform = pi->get_global_transform_const() * get_transform();
} else {
global_transform = get_transform();
}
}
return global_transform;
}
void CanvasItem::_set_global_invalid(bool p_invalid) const {
if (is_group_processing()) {
if (p_invalid) {
@ -550,6 +565,60 @@ int CanvasItem::get_light_mask() const {
return light_mask;
}
const StringName *CanvasItem::_instance_shader_parameter_get_remap(const StringName &p_name) const {
StringName *r = instance_shader_parameter_property_remap.getptr(p_name);
if (!r) {
String s = p_name;
if (s.begins_with("instance_shader_parameters/")) {
StringName name = s.trim_prefix("instance_shader_parameters/");
instance_shader_parameter_property_remap[p_name] = name;
return instance_shader_parameter_property_remap.getptr(p_name);
}
return nullptr;
}
return r;
}
bool CanvasItem::_set(const StringName &p_name, const Variant &p_value) {
const StringName *r = _instance_shader_parameter_get_remap(p_name);
if (r) {
set_instance_shader_parameter(*r, p_value);
return true;
}
return false;
}
bool CanvasItem::_get(const StringName &p_name, Variant &r_ret) const {
const StringName *r = _instance_shader_parameter_get_remap(p_name);
if (r) {
r_ret = get_instance_shader_parameter(*r);
return true;
}
return false;
}
void CanvasItem::_get_property_list(List<PropertyInfo> *p_list) const {
List<PropertyInfo> pinfo;
RS::get_singleton()->canvas_item_get_instance_shader_parameter_list(get_canvas_item(), &pinfo);
for (PropertyInfo &pi : pinfo) {
bool has_def_value = false;
Variant def_value = RS::get_singleton()->canvas_item_get_instance_shader_parameter_default_value(get_canvas_item(), pi.name);
if (def_value.get_type() != Variant::NIL) {
has_def_value = true;
}
if (instance_shader_parameters.has(pi.name)) {
pi.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE | (has_def_value ? (PROPERTY_USAGE_CHECKABLE | PROPERTY_USAGE_CHECKED) : PROPERTY_USAGE_NONE);
} else {
pi.usage = PROPERTY_USAGE_EDITOR | (has_def_value ? PROPERTY_USAGE_CHECKABLE : PROPERTY_USAGE_NONE); // Do not save if not changed.
}
pi.name = "instance_shader_parameters/" + pi.name;
p_list->push_back(pi);
}
}
void CanvasItem::item_rect_changed(bool p_size_changed) {
ERR_MAIN_THREAD_GUARD;
if (p_size_changed) {
@ -984,6 +1053,24 @@ void CanvasItem::_physics_interpolated_changed() {
RenderingServer::get_singleton()->canvas_item_set_interpolated(canvas_item, is_physics_interpolated());
}
void CanvasItem::set_canvas_item_use_identity_transform(bool p_enable) {
// Prevent sending item transforms to RenderingServer when using global coords.
_set_use_identity_transform(p_enable);
// Let RenderingServer know not to concatenate the parent transform during the render.
RenderingServer::get_singleton()->canvas_item_set_use_identity_transform(get_canvas_item(), p_enable);
if (is_inside_tree()) {
if (p_enable) {
// Make sure item is using identity transform in server.
RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), Transform2D());
} else {
// Make sure item transform is up to date in server if switching identity transform off.
RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), get_transform());
}
}
}
Rect2 CanvasItem::get_viewport_rect() const {
ERR_READ_THREAD_GUARD_V(Rect2());
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
@ -1080,6 +1167,26 @@ void CanvasItem::set_use_parent_material(bool p_use_parent_material) {
RS::get_singleton()->canvas_item_set_use_parent_material(canvas_item, p_use_parent_material);
}
void CanvasItem::set_instance_shader_parameter(const StringName &p_name, const Variant &p_value) {
if (p_value.get_type() == Variant::NIL) {
Variant def_value = RS::get_singleton()->canvas_item_get_instance_shader_parameter_default_value(get_canvas_item(), p_name);
RS::get_singleton()->canvas_item_set_instance_shader_parameter(get_canvas_item(), p_name, def_value);
instance_shader_parameters.erase(p_value);
} else {
instance_shader_parameters[p_name] = p_value;
if (p_value.get_type() == Variant::OBJECT) {
RID tex_id = p_value;
RS::get_singleton()->canvas_item_set_instance_shader_parameter(get_canvas_item(), p_name, tex_id);
} else {
RS::get_singleton()->canvas_item_set_instance_shader_parameter(get_canvas_item(), p_name, p_value);
}
}
}
Variant CanvasItem::get_instance_shader_parameter(const StringName &p_name) const {
return RS::get_singleton()->canvas_item_get_instance_shader_parameter(get_canvas_item(), p_name);
}
bool CanvasItem::get_use_parent_material() const {
ERR_READ_THREAD_GUARD_V(false);
return use_parent_material;
@ -1158,7 +1265,7 @@ void CanvasItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("_edit_get_pivot"), &CanvasItem::_edit_get_pivot);
ClassDB::bind_method(D_METHOD("_edit_use_pivot"), &CanvasItem::_edit_use_pivot);
ClassDB::bind_method(D_METHOD("_edit_get_transform"), &CanvasItem::_edit_get_transform);
#endif
#endif //TOOLS_ENABLED
ClassDB::bind_method(D_METHOD("get_canvas_item"), &CanvasItem::get_canvas_item);
@ -1242,6 +1349,9 @@ void CanvasItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_material", "material"), &CanvasItem::set_material);
ClassDB::bind_method(D_METHOD("get_material"), &CanvasItem::get_material);
ClassDB::bind_method(D_METHOD("set_instance_shader_parameter", "name", "value"), &CanvasItem::set_instance_shader_parameter);
ClassDB::bind_method(D_METHOD("get_instance_shader_parameter", "name"), &CanvasItem::get_instance_shader_parameter);
ClassDB::bind_method(D_METHOD("set_use_parent_material", "enable"), &CanvasItem::set_use_parent_material);
ClassDB::bind_method(D_METHOD("get_use_parent_material"), &CanvasItem::get_use_parent_material);
@ -1253,7 +1363,7 @@ void CanvasItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("force_update_transform"), &CanvasItem::force_update_transform);
ClassDB::bind_method(D_METHOD("make_canvas_position_local", "screen_point"), &CanvasItem::make_canvas_position_local);
ClassDB::bind_method(D_METHOD("make_canvas_position_local", "viewport_point"), &CanvasItem::make_canvas_position_local);
ClassDB::bind_method(D_METHOD("make_input_local", "event"), &CanvasItem::make_input_local);
ClassDB::bind_method(D_METHOD("set_visibility_layer", "layer"), &CanvasItem::set_visibility_layer);

View file

@ -32,7 +32,6 @@
#define CANVAS_ITEM_H
#include "scene/main/node.h"
#include "scene/resources/canvas_item_material.h"
#include "scene/resources/font.h"
class CanvasLayer;
@ -116,6 +115,8 @@ private:
TextureRepeat texture_repeat = TEXTURE_REPEAT_PARENT_NODE;
Ref<Material> material;
mutable HashMap<StringName, Variant> instance_shader_parameters;
mutable HashMap<StringName, StringName> instance_shader_parameter_property_remap;
mutable Transform2D global_transform;
mutable MTFlag global_invalid;
@ -150,8 +151,13 @@ private:
void _update_texture_filter_changed(bool p_propagate);
void _notify_transform_deferred();
const StringName *_instance_shader_parameter_get_remap(const StringName &p_name) const;
protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
virtual void _update_self_texture_repeat(RS::CanvasItemTextureRepeat p_texture_repeat);
virtual void _update_self_texture_filter(RS::CanvasItemTextureFilter p_texture_filter);
@ -164,6 +170,8 @@ protected:
void item_rect_changed(bool p_size_changed = true);
void set_canvas_item_use_identity_transform(bool p_enable);
void _notification(int p_what);
static void _bind_methods();
@ -174,7 +182,7 @@ protected:
void _draw_multiline_bind_compat_84523(const Vector<Point2> &p_points, const Color &p_color, real_t p_width);
void _draw_multiline_colors_bind_compat_84523(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width);
static void _bind_compatibility_methods();
#endif
#endif // DISABLE_DEPRECATED
void _validate_property(PropertyInfo &p_property) const;
@ -193,11 +201,9 @@ public:
NOTIFICATION_WORLD_2D_CHANGED = 36,
};
/* EDITOR */
#ifdef TOOLS_ENABLED
// Select the node
virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
/* EDITOR AND DEBUGGING */
#ifdef TOOLS_ENABLED
// Save and restore a CanvasItem state
virtual void _edit_set_state(const Dictionary &p_state) {}
virtual Dictionary _edit_get_state() const { return Dictionary(); }
@ -211,23 +217,32 @@ public:
virtual Size2 _edit_get_scale() const = 0;
// Used to rotate the node
virtual bool _edit_use_rotation() const { return false; };
virtual bool _edit_use_rotation() const { return false; }
virtual void _edit_set_rotation(real_t p_rotation) {}
virtual real_t _edit_get_rotation() const { return 0.0; };
virtual real_t _edit_get_rotation() const { return 0.0; }
// Used to resize/move the node
virtual bool _edit_use_rect() const { return false; }; // MAYBE REPLACE BY A _edit_get_editmode()
virtual void _edit_set_rect(const Rect2 &p_rect) {}
virtual Rect2 _edit_get_rect() const { return Rect2(0, 0, 0, 0); };
virtual Size2 _edit_get_minimum_size() const { return Size2(-1, -1); }; // LOOKS WEIRD
virtual Size2 _edit_get_minimum_size() const { return Size2(-1, -1); } // LOOKS WEIRD
// Used to set a pivot
virtual bool _edit_use_pivot() const { return false; };
virtual bool _edit_use_pivot() const { return false; }
virtual void _edit_set_pivot(const Point2 &p_pivot) {}
virtual Point2 _edit_get_pivot() const { return Point2(); };
virtual Point2 _edit_get_pivot() const { return Point2(); }
virtual Transform2D _edit_get_transform() const;
#endif
#endif // TOOLS_ENABLED
#ifdef DEBUG_ENABLED
// Those need to be available in debug runtime, to allow for node selection.
// Select the node.
virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
// Used to resize/move the node.
virtual bool _edit_use_rect() const { return false; } // Maybe replace with _edit_get_editmode().
virtual Rect2 _edit_get_rect() const { return Rect2(0, 0, 0, 0); }
#endif // DEBUG_ENABLED
void update_draw_order();
@ -326,6 +341,7 @@ public:
virtual Transform2D get_transform() const = 0;
virtual Transform2D get_global_transform() const;
virtual Transform2D get_global_transform_const() const;
virtual Transform2D get_global_transform_with_canvas() const;
virtual Transform2D get_screen_transform() const;
@ -348,6 +364,9 @@ public:
virtual void set_material(const Ref<Material> &p_material);
Ref<Material> get_material() const;
void set_instance_shader_parameter(const StringName &p_name, const Variant &p_value);
Variant get_instance_shader_parameter(const StringName &p_name) const;
virtual void set_use_parent_material(bool p_use_parent_material);
bool get_use_parent_material() const;
@ -375,7 +394,7 @@ public:
TextureRepeat get_texture_repeat_in_tree() const;
// Used by control nodes to retrieve the parent's anchorable area
virtual Rect2 get_anchorable_rect() const { return Rect2(0, 0, 0, 0); };
virtual Rect2 get_anchorable_rect() const { return Rect2(0, 0, 0, 0); }
int get_canvas_layer() const;
CanvasLayer *get_canvas_layer_node() const;

View file

@ -108,7 +108,7 @@ void CanvasLayer::_update_xform() {
}
}
void CanvasLayer::_update_locrotscale() {
void CanvasLayer::_update_locrotscale() const {
ofs = transform.columns[2];
rot = transform.get_rotation();
scale = transform.get_scale();
@ -126,7 +126,7 @@ void CanvasLayer::set_offset(const Vector2 &p_offset) {
Vector2 CanvasLayer::get_offset() const {
if (locrotscale_dirty) {
const_cast<CanvasLayer *>(this)->_update_locrotscale();
_update_locrotscale();
}
return ofs;
@ -143,7 +143,7 @@ void CanvasLayer::set_rotation(real_t p_radians) {
real_t CanvasLayer::get_rotation() const {
if (locrotscale_dirty) {
const_cast<CanvasLayer *>(this)->_update_locrotscale();
_update_locrotscale();
}
return rot;
@ -160,7 +160,7 @@ void CanvasLayer::set_scale(const Vector2 &p_scale) {
Vector2 CanvasLayer::get_scale() const {
if (locrotscale_dirty) {
const_cast<CanvasLayer *>(this)->_update_locrotscale();
_update_locrotscale();
}
return scale;

View file

@ -37,10 +37,10 @@ class Viewport;
class CanvasLayer : public Node {
GDCLASS(CanvasLayer, Node);
bool locrotscale_dirty = false;
Vector2 ofs;
Size2 scale = Vector2(1, 1);
real_t rot = 0.0;
mutable bool locrotscale_dirty = false;
mutable Vector2 ofs;
mutable Size2 scale = Vector2(1, 1);
mutable real_t rot = 0.0;
int layer = 1;
Transform2D transform;
RID canvas;
@ -58,7 +58,7 @@ class CanvasLayer : public Node {
float follow_viewport_scale = 1.0;
void _update_xform();
void _update_locrotscale();
void _update_locrotscale() const;
void _update_follow_viewport(bool p_force_exit = false);
protected:

View file

@ -29,7 +29,7 @@
/**************************************************************************/
#include "http_request.h"
#include "core/io/compression.h"
#include "scene/main/timer.h"
Error HTTPRequest::_request() {
@ -49,7 +49,8 @@ Error HTTPRequest::_parse_url(const String &p_url) {
redirections = 0;
String scheme;
Error err = p_url.parse_url(scheme, url, port, request_string);
String fragment;
Error err = p_url.parse_url(scheme, url, port, request_string, fragment);
ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Error parsing URL: '%s'.", p_url));
if (scheme == "https://") {
@ -86,7 +87,7 @@ String HTTPRequest::get_header_value(const PackedStringArray &p_headers, const S
String lowwer_case_header_name = p_header_name.to_lower();
for (int i = 0; i < p_headers.size(); i++) {
if (p_headers[i].find(":") > 0) {
if (p_headers[i].find_char(':') > 0) {
Vector<String> parts = p_headers[i].split(":", false, 1);
if (parts.size() > 1 && parts[0].strip_edges().to_lower() == lowwer_case_header_name) {
value = parts[1].strip_edges();

View file

@ -85,7 +85,7 @@ Node *InstancePlaceholder::create_instance(bool p_replace, const Ref<PackedScene
ps = ResourceLoader::load(path, "PackedScene");
}
if (!ps.is_valid()) {
if (ps.is_null()) {
return nullptr;
}
Node *instance = ps->instantiate();
@ -163,7 +163,7 @@ void InstancePlaceholder::set_value_on_instance(InstancePlaceholder *p_placehold
switch (current_type) {
case Variant::Type::NIL: {
Ref<Resource> resource = p_set.value;
if (placeholder_type != Variant::Type::NODE_PATH && !resource.is_valid()) {
if (placeholder_type != Variant::Type::NODE_PATH && resource.is_null()) {
break;
}
// If it's nil but we have a NodePath or a Resource, we guess what works.
@ -245,7 +245,7 @@ Dictionary InstancePlaceholder::get_stored_values(bool p_with_order) {
}
return ret;
};
}
void InstancePlaceholder::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_stored_values", "with_order"), &InstancePlaceholder::get_stored_values, DEFVAL(false));

View file

@ -84,17 +84,17 @@ bool MissingNode::is_recording_properties() const {
PackedStringArray MissingNode::get_configuration_warnings() const {
// The mere existence of this node is warning.
PackedStringArray ret;
PackedStringArray warnings = Node::get_configuration_warnings();
if (!original_scene.is_empty()) {
ret.push_back(vformat(RTR("This node was an instance of scene '%s', which was no longer available when this scene was loaded."), original_scene));
ret.push_back(vformat(RTR("Saving current scene will discard instance and all its properties, including editable children edits (if existing).")));
warnings.push_back(vformat(RTR("This node was an instance of scene '%s', which was no longer available when this scene was loaded."), original_scene));
warnings.push_back(vformat(RTR("Saving current scene will discard instance and all its properties, including editable children edits (if existing).")));
} else if (!original_class.is_empty()) {
ret.push_back(vformat(RTR("This node was saved as class type '%s', which was no longer available when this scene was loaded."), original_class));
ret.push_back(RTR("Data from the original node is kept as a placeholder until this type of node is available again. It can hence be safely re-saved without risk of data loss."));
warnings.push_back(vformat(RTR("This node was saved as class type '%s', which was no longer available when this scene was loaded."), original_class));
warnings.push_back(RTR("Data from the original node is kept as a placeholder until this type of node is available again. It can hence be safely re-saved without risk of data loss."));
} else {
ret.push_back(RTR("Unrecognized missing node. Check scene dependency errors for details."));
warnings.push_back(RTR("Unrecognized missing node. Check scene dependency errors for details."));
}
return ret;
return warnings;
}
void MissingNode::_bind_methods() {

View file

@ -31,7 +31,6 @@
#ifndef MISSING_NODE_H
#define MISSING_NODE_H
#include "core/io/missing_resource.h"
#include "scene/main/node.h"
class MissingNode : public Node {

View file

@ -30,15 +30,7 @@
#include "multiplayer_api.h"
#include "core/debugger/engine_debugger.h"
#include "core/io/marshalls.h"
#include <stdint.h>
#ifdef DEBUG_ENABLED
#include "core/os/os.h"
#endif
StringName MultiplayerAPI::default_interface;
void MultiplayerAPI::set_default_interface(const StringName &p_interface) {

View file

@ -111,6 +111,7 @@ void Node::_notification(int p_notification) {
data.auto_translate_mode = AUTO_TRANSLATE_MODE_ALWAYS;
}
data.is_auto_translate_dirty = true;
data.is_translation_domain_dirty = true;
#ifdef TOOLS_ENABLED
// Don't translate UI elements when they're being edited.
@ -119,10 +120,6 @@ void Node::_notification(int p_notification) {
}
#endif
if (data.auto_translate_mode != AUTO_TRANSLATE_MODE_DISABLED) {
notification(NOTIFICATION_TRANSLATION_CHANGED);
}
if (data.input) {
add_to_group("_vp_input" + itos(get_viewport()->get_instance_id()));
}
@ -138,6 +135,18 @@ void Node::_notification(int p_notification) {
get_tree()->nodes_in_tree_count++;
orphan_node_count--;
// Allow physics interpolated nodes to automatically reset when added to the tree
// (this is to save the user from doing this manually each time).
if (get_tree()->is_physics_interpolation_enabled()) {
_set_physics_interpolation_reset_requested(true);
}
} break;
case NOTIFICATION_POST_ENTER_TREE: {
if (data.auto_translate_mode != AUTO_TRANSLATE_MODE_DISABLED) {
notification(NOTIFICATION_TRANSLATION_CHANGED);
}
} break;
case NOTIFICATION_EXIT_TREE: {
@ -177,6 +186,7 @@ void Node::_notification(int p_notification) {
}
} break;
case NOTIFICATION_SUSPENDED:
case NOTIFICATION_PAUSED: {
if (is_physics_interpolated_and_enabled() && is_inside_tree()) {
reset_physics_interpolation();
@ -437,6 +447,18 @@ void Node::_propagate_physics_interpolated(bool p_interpolated) {
data.blocked--;
}
void Node::_propagate_physics_interpolation_reset_requested(bool p_requested) {
if (is_physics_interpolated()) {
data.physics_interpolation_reset_requested = p_requested;
}
data.blocked++;
for (KeyValue<StringName, Node *> &K : data.children) {
K.value->_propagate_physics_interpolation_reset_requested(p_requested);
}
data.blocked--;
}
void Node::move_child(Node *p_child, int p_index) {
ERR_FAIL_COND_MSG(data.inside_tree && !Thread::is_main_thread(), "Moving child node positions inside the SceneTree is only allowed from the main thread. Use call_deferred(\"move_child\",child,index).");
ERR_FAIL_NULL(p_child);
@ -656,6 +678,8 @@ void Node::set_process_mode(ProcessMode p_mode) {
if (Engine::get_singleton()->is_editor_hint()) {
get_tree()->emit_signal(SNAME("tree_process_mode_changed"));
}
_emit_editor_state_changed();
#endif
}
@ -676,6 +700,16 @@ void Node::_propagate_pause_notification(bool p_enable) {
data.blocked--;
}
void Node::_propagate_suspend_notification(bool p_enable) {
notification(p_enable ? NOTIFICATION_SUSPENDED : NOTIFICATION_UNSUSPENDED);
data.blocked++;
for (KeyValue<StringName, Node *> &KV : data.children) {
KV.value->_propagate_suspend_notification(p_enable);
}
data.blocked--;
}
Node::ProcessMode Node::get_process_mode() const {
return data.process_mode;
}
@ -739,7 +773,7 @@ void Node::rpc_config(const StringName &p_method, const Variant &p_config) {
}
}
const Variant Node::get_node_rpc_config() const {
Variant Node::get_rpc_config() const {
return data.rpc_config;
}
@ -752,8 +786,7 @@ Error Node::_rpc_bind(const Variant **p_args, int p_argcount, Callable::CallErro
return ERR_INVALID_PARAMETER;
}
Variant::Type type = p_args[0]->get_type();
if (type != Variant::STRING_NAME && type != Variant::STRING) {
if (!p_args[0]->is_string()) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::STRING_NAME;
@ -781,8 +814,7 @@ Error Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Callable::CallE
return ERR_INVALID_PARAMETER;
}
Variant::Type type = p_args[1]->get_type();
if (type != Variant::STRING_NAME && type != Variant::STRING) {
if (!p_args[1]->is_string()) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 1;
r_error.expected = Variant::STRING_NAME;
@ -833,7 +865,7 @@ bool Node::can_process_notification(int p_what) const {
bool Node::can_process() const {
ERR_FAIL_COND_V(!is_inside_tree(), false);
return _can_process(get_tree()->is_paused());
return !get_tree()->is_suspended() && _can_process(get_tree()->is_paused());
}
bool Node::_can_process(bool p_paused) const {
@ -889,16 +921,24 @@ void Node::set_physics_interpolation_mode(PhysicsInterpolationMode p_mode) {
} break;
}
// If swapping from interpolated to non-interpolated, use this as an extra means to cause a reset.
if (is_physics_interpolated() && !interpolate) {
reset_physics_interpolation();
}
_propagate_physics_interpolated(interpolate);
// Auto-reset on changing interpolation mode.
if (is_physics_interpolated() && is_inside_tree()) {
propagate_notification(NOTIFICATION_RESET_PHYSICS_INTERPOLATION);
}
}
void Node::reset_physics_interpolation() {
propagate_notification(NOTIFICATION_RESET_PHYSICS_INTERPOLATION);
if (is_inside_tree()) {
propagate_notification(NOTIFICATION_RESET_PHYSICS_INTERPOLATION);
// If `reset_physics_interpolation()` is called explicitly by the user
// (e.g. from scripts) then we prevent deferred auto-resets taking place.
// The user is trusted to call reset in the right order, and auto-reset
// will interfere with their control of prev / curr, so should be turned off.
_propagate_physics_interpolation_reset_requested(false);
}
}
bool Node::_is_enabled() const {
@ -1296,6 +1336,51 @@ bool Node::can_auto_translate() const {
return data.is_auto_translating;
}
StringName Node::get_translation_domain() const {
ERR_READ_THREAD_GUARD_V(StringName());
if (data.is_translation_domain_inherited && data.is_translation_domain_dirty) {
const_cast<Node *>(this)->_translation_domain = data.parent ? data.parent->get_translation_domain() : StringName();
data.is_translation_domain_dirty = false;
}
return _translation_domain;
}
void Node::set_translation_domain(const StringName &p_domain) {
ERR_THREAD_GUARD
if (!data.is_translation_domain_inherited && _translation_domain == p_domain) {
return;
}
_translation_domain = p_domain;
data.is_translation_domain_inherited = false;
data.is_translation_domain_dirty = false;
_propagate_translation_domain_dirty();
}
void Node::set_translation_domain_inherited() {
ERR_THREAD_GUARD
if (data.is_translation_domain_inherited) {
return;
}
data.is_translation_domain_inherited = true;
data.is_translation_domain_dirty = true;
_propagate_translation_domain_dirty();
}
void Node::_propagate_translation_domain_dirty() {
for (KeyValue<StringName, Node *> &K : data.children) {
Node *child = K.value;
if (child->data.is_translation_domain_inherited) {
child->data.is_translation_domain_dirty = true;
child->_propagate_translation_domain_dirty();
}
}
notification(NOTIFICATION_TRANSLATION_CHANGED);
}
StringName Node::get_name() const {
return data.name;
}
@ -2080,6 +2165,7 @@ void Node::set_unique_name_in_owner(bool p_enabled) {
}
update_configuration_warnings();
_emit_editor_state_changed();
}
bool Node::is_unique_name_in_owner() const {
@ -2117,6 +2203,8 @@ void Node::set_owner(Node *p_owner) {
if (data.unique_name_in_owner) {
_acquire_unique_name_in_owner();
}
_emit_editor_state_changed();
}
Node *Node::get_owner() const {
@ -2300,6 +2388,9 @@ void Node::add_to_group(const StringName &p_identifier, bool p_persistent) {
gd.persistent = p_persistent;
data.grouped[p_identifier] = gd;
if (p_persistent) {
_emit_editor_state_changed();
}
}
void Node::remove_from_group(const StringName &p_identifier) {
@ -2310,11 +2401,21 @@ void Node::remove_from_group(const StringName &p_identifier) {
return;
}
#ifdef TOOLS_ENABLED
bool persistent = E->value.persistent;
#endif
if (data.tree) {
data.tree->remove_from_group(E->key, this);
}
data.grouped.remove(E);
#ifdef TOOLS_ENABLED
if (persistent) {
_emit_editor_state_changed();
}
#endif
}
TypedArray<StringName> Node::_get_groups() const {
@ -2477,6 +2578,7 @@ Ref<Tween> Node::create_tween() {
void Node::set_scene_file_path(const String &p_scene_file_path) {
ERR_THREAD_GUARD
data.scene_file_path = p_scene_file_path;
_emit_editor_state_changed();
}
String Node::get_scene_file_path() const {
@ -2509,6 +2611,8 @@ void Node::set_editable_instance(Node *p_node, bool p_editable) {
} else {
p_node->data.editable_instance = true;
}
p_node->_emit_editor_state_changed();
}
bool Node::is_editable_instance(const Node *p_node) const {
@ -2619,6 +2723,7 @@ Ref<SceneState> Node::get_scene_instance_state() const {
void Node::set_scene_inherited_state(const Ref<SceneState> &p_state) {
ERR_THREAD_GUARD
data.inherited_state = p_state;
_emit_editor_state_changed();
}
Ref<SceneState> Node::get_scene_inherited_state() const {
@ -2783,9 +2888,11 @@ Node *Node::duplicate(int p_flags) const {
ERR_THREAD_GUARD_V(nullptr);
Node *dupe = _duplicate(p_flags);
ERR_FAIL_NULL_V_MSG(dupe, nullptr, "Failed to duplicate node.");
_duplicate_properties(this, this, dupe, p_flags);
if (dupe && (p_flags & DUPLICATE_SIGNALS)) {
if (p_flags & DUPLICATE_SIGNALS) {
_duplicate_signals(this, dupe);
}
@ -2801,6 +2908,8 @@ Node *Node::duplicate_from_editor(HashMap<const Node *, Node *> &r_duplimap, con
int flags = DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS | DUPLICATE_USE_INSTANTIATION | DUPLICATE_FROM_EDITOR;
Node *dupe = _duplicate(flags, &r_duplimap);
ERR_FAIL_NULL_V_MSG(dupe, nullptr, "Failed to duplicate node.");
_duplicate_properties(this, this, dupe, flags);
// This is used by SceneTreeDock's paste functionality. When pasting to foreign scene, resources are duplicated.
@ -2863,6 +2972,14 @@ void Node::remap_nested_resources(Ref<Resource> p_resource, const HashMap<Ref<Re
}
}
}
void Node::_emit_editor_state_changed() {
// This is required for the SceneTreeEditor to properly keep track of when an update is needed.
// This signal might be expensive and not needed for anything outside of the editor.
if (Engine::get_singleton()->is_editor_hint()) {
emit_signal(SNAME("editor_state_changed"));
}
}
#endif
// Duplicate node's properties.
@ -2970,11 +3087,12 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const {
if (copy && copytarget && E.callable.get_method() != StringName()) {
Callable copy_callable = Callable(copytarget, E.callable.get_method());
if (!copy->is_connected(E.signal.get_name(), copy_callable)) {
int arg_count = E.callable.get_bound_arguments_count();
if (arg_count > 0) {
int unbound_arg_count = E.callable.get_unbound_arguments_count();
if (unbound_arg_count > 0) {
copy_callable = copy_callable.unbind(unbound_arg_count);
}
if (E.callable.get_bound_arguments_count() > 0) {
copy_callable = copy_callable.bindv(E.callable.get_bound_arguments());
} else if (arg_count < 0) {
copy_callable = copy_callable.unbind(-arg_count);
}
copy->connect(E.signal.get_name(), copy_callable, E.flags);
}
@ -3406,7 +3524,7 @@ Variant Node::_call_deferred_thread_group_bind(const Variant **p_args, int p_arg
return Variant();
}
if (p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING) {
if (!p_args[0]->is_string()) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::STRING_NAME;
@ -3429,7 +3547,7 @@ Variant Node::_call_thread_safe_bind(const Variant **p_args, int p_argcount, Cal
return Variant();
}
if (p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING) {
if (!p_args[0]->is_string()) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::STRING_NAME;
@ -3582,6 +3700,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_auto_translate_mode", "mode"), &Node::set_auto_translate_mode);
ClassDB::bind_method(D_METHOD("get_auto_translate_mode"), &Node::get_auto_translate_mode);
ClassDB::bind_method(D_METHOD("set_translation_domain_inherited"), &Node::set_translation_domain_inherited);
ClassDB::bind_method(D_METHOD("get_window"), &Node::get_window);
ClassDB::bind_method(D_METHOD("get_last_exclusive_window"), &Node::get_last_exclusive_window);
@ -3610,6 +3729,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_multiplayer"), &Node::get_multiplayer);
ClassDB::bind_method(D_METHOD("rpc_config", "method", "config"), &Node::rpc_config);
ClassDB::bind_method(D_METHOD("get_rpc_config"), &Node::get_rpc_config);
ClassDB::bind_method(D_METHOD("set_editor_description", "editor_description"), &Node::set_editor_description);
ClassDB::bind_method(D_METHOD("get_editor_description"), &Node::get_editor_description);
@ -3753,6 +3873,7 @@ void Node::_bind_methods() {
ADD_SIGNAL(MethodInfo("child_order_changed"));
ADD_SIGNAL(MethodInfo("replacing_by", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT, "Node")));
ADD_SIGNAL(MethodInfo("editor_description_changed", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT, "Node")));
ADD_SIGNAL(MethodInfo("editor_state_changed"));
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_name", "get_name");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "unique_name_in_owner", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_unique_name_in_owner", "is_unique_name_in_owner");
@ -3825,6 +3946,9 @@ Node::Node() {
data.unhandled_key_input = false;
data.physics_interpolated = true;
data.physics_interpolation_reset_requested = false;
data.physics_interpolated_client_side = false;
data.use_identity_transform = false;
data.parent_owned = false;
data.in_constructor = true;
@ -3873,11 +3997,13 @@ bool Node::has_meta(const StringName &p_name) const {
void Node::set_meta(const StringName &p_name, const Variant &p_value) {
ERR_THREAD_GUARD;
Object::set_meta(p_name, p_value);
_emit_editor_state_changed();
}
void Node::remove_meta(const StringName &p_name) {
ERR_THREAD_GUARD;
Object::remove_meta(p_name);
_emit_editor_state_changed();
}
Variant Node::get_meta(const StringName &p_name, const Variant &p_default) const {
@ -3927,12 +4053,33 @@ void Node::get_signals_connected_to_this(List<Connection> *p_connections) const
Error Node::connect(const StringName &p_signal, const Callable &p_callable, uint32_t p_flags) {
ERR_THREAD_GUARD_V(ERR_INVALID_PARAMETER);
return Object::connect(p_signal, p_callable, p_flags);
Error retval = Object::connect(p_signal, p_callable, p_flags);
#ifdef TOOLS_ENABLED
if (p_flags & CONNECT_PERSIST) {
_emit_editor_state_changed();
}
#endif
return retval;
}
void Node::disconnect(const StringName &p_signal, const Callable &p_callable) {
ERR_THREAD_GUARD;
#ifdef TOOLS_ENABLED
// Already under thread guard, don't check again.
int old_connection_count = Object::get_persistent_signal_connection_count();
#endif
Object::disconnect(p_signal, p_callable);
#ifdef TOOLS_ENABLED
int new_connection_count = Object::get_persistent_signal_connection_count();
if (old_connection_count != new_connection_count) {
_emit_editor_state_changed();
}
#endif
}
bool Node::is_connected(const StringName &p_signal, const Callable &p_callable) const {
@ -3940,4 +4087,9 @@ bool Node::is_connected(const StringName &p_signal, const Callable &p_callable)
return Object::is_connected(p_signal, p_callable);
}
bool Node::has_connections(const StringName &p_signal) const {
ERR_THREAD_GUARD_V(false);
return Object::has_connections(p_signal);
}
#endif

View file

@ -32,7 +32,6 @@
#define NODE_H
#include "core/string/node_path.h"
#include "core/templates/rb_map.h"
#include "core/variant/typed_array.h"
#include "scene/main/scene_tree.h"
#include "scene/scene_string_names.h"
@ -199,7 +198,7 @@ private:
void *process_group = nullptr; // to avoid cyclic dependency
int multiplayer_authority = 1; // Server by default.
Variant rpc_config;
Variant rpc_config = Dictionary();
// Variables used to properly sort the node when processing, ignored otherwise.
int process_priority = 0;
@ -225,6 +224,21 @@ private:
// is switched on.
bool physics_interpolated : 1;
// We can auto-reset physics interpolation when e.g. adding a node for the first time.
bool physics_interpolation_reset_requested : 1;
// Most nodes need not be interpolated in the scene tree, physics interpolation
// is normally only needed in the RenderingServer. However if we need to read the
// interpolated transform of a node in the SceneTree, it is necessary to duplicate
// the interpolation logic client side, in order to prevent stalling the RenderingServer
// by reading back.
bool physics_interpolated_client_side : 1;
// For certain nodes (e.g. CPU particles in global mode)
// it can be useful to not send the instance transform to the
// RenderingServer, and specify the mesh in world space.
bool use_identity_transform : 1;
bool parent_owned : 1;
bool in_constructor : 1;
bool use_placeholder : 1;
@ -240,6 +254,9 @@ private:
mutable bool is_auto_translating = true;
mutable bool is_auto_translate_dirty = true;
mutable bool is_translation_domain_inherited = true;
mutable bool is_translation_domain_dirty = true;
mutable NodePath *path_cache = nullptr;
} data;
@ -263,8 +280,10 @@ private:
void _propagate_exit_tree();
void _propagate_after_exit_tree();
void _propagate_physics_interpolated(bool p_interpolated);
void _propagate_physics_interpolation_reset_requested(bool p_requested);
void _propagate_process_owner(Node *p_owner, int p_pause_notification, int p_enabled_notification);
void _propagate_groups_dirty();
void _propagate_translation_domain_dirty();
Array _get_node_and_resource(const NodePath &p_path);
void _duplicate_properties(const Node *p_root, const Node *p_original, Node *p_copy, int p_flags) const;
@ -280,6 +299,7 @@ private:
void _set_tree(SceneTree *p_tree);
void _propagate_pause_notification(bool p_enable);
void _propagate_suspend_notification(bool p_enable);
_FORCE_INLINE_ bool _can_process(bool p_paused) const;
_FORCE_INLINE_ bool _is_enabled() const;
@ -310,6 +330,13 @@ private:
Variant _call_deferred_thread_group_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
Variant _call_thread_safe_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
// Editor only signal to keep the SceneTreeEditor in sync.
#ifdef TOOLS_ENABLED
void _emit_editor_state_changed();
#else
void _emit_editor_state_changed() {}
#endif
protected:
void _block() { data.blocked++; }
void _unblock() { data.blocked--; }
@ -334,6 +361,15 @@ protected:
void _set_owner_nocheck(Node *p_owner);
void _set_name_nocheck(const StringName &p_name);
void _set_physics_interpolated_client_side(bool p_enable) { data.physics_interpolated_client_side = p_enable; }
bool _is_physics_interpolated_client_side() const { return data.physics_interpolated_client_side; }
void _set_physics_interpolation_reset_requested(bool p_enable) { data.physics_interpolation_reset_requested = p_enable; }
bool _is_physics_interpolation_reset_requested() const { return data.physics_interpolation_reset_requested; }
void _set_use_identity_transform(bool p_enable) { data.use_identity_transform = p_enable; }
bool _is_using_identity_transform() const { return data.use_identity_transform; }
//call from SceneTree
void _call_input(const Ref<InputEvent> &p_event);
void _call_shortcut_input(const Ref<InputEvent> &p_event);
@ -395,6 +431,7 @@ public:
NOTIFICATION_WM_DPI_CHANGE = 1009,
NOTIFICATION_VP_MOUSE_ENTER = 1010,
NOTIFICATION_VP_MOUSE_EXIT = 1011,
NOTIFICATION_WM_POSITION_CHANGED = 1012,
NOTIFICATION_OS_MEMORY_WARNING = MainLoop::NOTIFICATION_OS_MEMORY_WARNING,
NOTIFICATION_TRANSLATION_CHANGED = MainLoop::NOTIFICATION_TRANSLATION_CHANGED,
@ -410,6 +447,8 @@ public:
// Editor specific node notifications
NOTIFICATION_EDITOR_PRE_SAVE = 9001,
NOTIFICATION_EDITOR_POST_SAVE = 9002,
NOTIFICATION_SUSPENDED = 9003,
NOTIFICATION_UNSUSPENDED = 9004
};
/* NODE/TREE */
@ -632,7 +671,7 @@ public:
return binds;
}
void replace_by(Node *p_node, bool p_keep_data = false);
void replace_by(Node *p_node, bool p_keep_groups = false);
void set_process_mode(ProcessMode p_mode);
ProcessMode get_process_mode() const;
@ -692,7 +731,7 @@ public:
bool is_multiplayer_authority() const;
void rpc_config(const StringName &p_method, const Variant &p_config); // config a local method for RPC
const Variant get_node_rpc_config() const;
Variant get_rpc_config() const;
template <typename... VarArgs>
Error rpc(const StringName &p_method, VarArgs... p_args);
@ -710,8 +749,17 @@ public:
AutoTranslateMode get_auto_translate_mode() const;
bool can_auto_translate() const;
_FORCE_INLINE_ String atr(const String p_message, const StringName p_context = "") const { return can_auto_translate() ? tr(p_message, p_context) : p_message; }
_FORCE_INLINE_ String atr_n(const String p_message, const StringName &p_message_plural, int p_n, const StringName p_context = "") const { return can_auto_translate() ? tr_n(p_message, p_message_plural, p_n, p_context) : p_message; }
virtual StringName get_translation_domain() const override;
virtual void set_translation_domain(const StringName &p_domain) override;
void set_translation_domain_inherited();
_FORCE_INLINE_ String atr(const String &p_message, const StringName &p_context = "") const { return can_auto_translate() ? tr(p_message, p_context) : p_message; }
_FORCE_INLINE_ String atr_n(const String &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context = "") const {
if (can_auto_translate()) {
return tr_n(p_message, p_message_plural, p_n, p_context);
}
return p_n == 1 ? p_message : String(p_message_plural);
}
/* THREADING */
@ -764,6 +812,7 @@ public:
virtual Error connect(const StringName &p_signal, const Callable &p_callable, uint32_t p_flags = 0) override;
virtual void disconnect(const StringName &p_signal, const Callable &p_callable) override;
virtual bool is_connected(const StringName &p_signal, const Callable &p_callable) const override;
virtual bool has_connections(const StringName &p_signal) const override;
#endif
Node();
~Node();

View file

@ -41,7 +41,7 @@ void ResourcePreloader::_set_resources(const Array &p_data) {
for (int i = 0; i < resdata.size(); i++) {
Ref<Resource> resource = resdata[i];
ERR_CONTINUE(!resource.is_valid());
ERR_CONTINUE(resource.is_null());
resources[names[i]] = resource;
//add_resource(names[i],resource);

View file

@ -31,17 +31,12 @@
#include "scene_tree.h"
#include "core/config/project_settings.h"
#include "core/debugger/engine_debugger.h"
#include "core/input/input.h"
#include "core/io/dir_access.h"
#include "core/io/image_loader.h"
#include "core/io/marshalls.h"
#include "core/io/resource_loader.h"
#include "core/object/message_queue.h"
#include "core/object/worker_thread_pool.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "core/string/print_string.h"
#include "node.h"
#include "scene/animation/tween.h"
#include "scene/debugger/scene_debugger.h"
@ -49,22 +44,18 @@
#include "scene/main/multiplayer_api.h"
#include "scene/main/viewport.h"
#include "scene/resources/environment.h"
#include "scene/resources/font.h"
#include "scene/resources/image_texture.h"
#include "scene/resources/material.h"
#include "scene/resources/mesh.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/world_2d.h"
#include "servers/display_server.h"
#include "servers/navigation_server_3d.h"
#include "servers/physics_server_2d.h"
#ifndef _3D_DISABLED
#include "scene/3d/node_3d.h"
#include "scene/resources/3d/world_3d.h"
#include "servers/physics_server_3d.h"
#endif // _3D_DISABLED
#include "window.h"
#include <stdio.h>
#include <stdlib.h>
void SceneTreeTimer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_time_left", "time"), &SceneTreeTimer::set_time_left);
@ -103,7 +94,7 @@ void SceneTreeTimer::set_ignore_time_scale(bool p_ignore) {
ignore_time_scale = p_ignore;
}
bool SceneTreeTimer::is_ignore_time_scale() {
bool SceneTreeTimer::is_ignoring_time_scale() {
return ignore_time_scale;
}
@ -118,6 +109,29 @@ void SceneTreeTimer::release_connections() {
SceneTreeTimer::SceneTreeTimer() {}
#ifndef _3D_DISABLED
// This should be called once per physics tick, to make sure the transform previous and current
// is kept up to date on the few Node3Ds that are using client side physics interpolation.
void SceneTree::ClientPhysicsInterpolation::physics_process() {
for (SelfList<Node3D> *E = _node_3d_list.first(); E;) {
Node3D *node_3d = E->self();
SelfList<Node3D> *current = E;
// Get the next element here BEFORE we potentially delete one.
E = E->next();
// This will return false if the Node3D has timed out ..
// i.e. if get_global_transform_interpolated() has not been called
// for a few seconds, we can delete from the list to keep processing
// to a minimum.
if (!node_3d->update_client_physics_interpolation_data()) {
_node_3d_list.remove(current);
}
}
}
#endif
void SceneTree::tree_changed() {
emit_signal(tree_changed_name);
}
@ -278,11 +292,15 @@ void SceneTree::call_group_flagsp(uint32_t p_call_flags, const StringName &p_gro
continue;
}
Node *node = gr_nodes[i];
if (!(p_call_flags & GROUP_CALL_DEFERRED)) {
Callable::CallError ce;
gr_nodes[i]->callp(p_function, p_args, p_argcount, ce);
node->callp(p_function, p_args, p_argcount, ce);
if (unlikely(ce.error != Callable::CallError::CALL_OK && ce.error != Callable::CallError::CALL_ERROR_INVALID_METHOD)) {
ERR_PRINT(vformat("Error calling group method on node \"%s\": %s.", node->get_name(), Variant::get_callable_error_text(Callable(node, p_function), p_args, p_argcount, ce)));
}
} else {
MessageQueue::get_singleton()->push_callp(gr_nodes[i], p_function, p_args, p_argcount);
MessageQueue::get_singleton()->push_callp(node, p_function, p_args, p_argcount);
}
}
@ -292,11 +310,15 @@ void SceneTree::call_group_flagsp(uint32_t p_call_flags, const StringName &p_gro
continue;
}
Node *node = gr_nodes[i];
if (!(p_call_flags & GROUP_CALL_DEFERRED)) {
Callable::CallError ce;
gr_nodes[i]->callp(p_function, p_args, p_argcount, ce);
node->callp(p_function, p_args, p_argcount, ce);
if (unlikely(ce.error != Callable::CallError::CALL_OK && ce.error != Callable::CallError::CALL_ERROR_INVALID_METHOD)) {
ERR_PRINT(vformat("Error calling group method on node \"%s\": %s.", node->get_name(), Variant::get_callable_error_text(Callable(node, p_function), p_args, p_argcount, ce)));
}
} else {
MessageQueue::get_singleton()->push_callp(gr_nodes[i], p_function, p_args, p_argcount);
MessageQueue::get_singleton()->push_callp(node, p_function, p_args, p_argcount);
}
}
}
@ -460,14 +482,34 @@ void SceneTree::set_physics_interpolation_enabled(bool p_enabled) {
_physics_interpolation_enabled = p_enabled;
RenderingServer::get_singleton()->set_physics_interpolation_enabled(p_enabled);
// Perform an auto reset on the root node for convenience for the user.
if (root) {
root->reset_physics_interpolation();
}
}
bool SceneTree::is_physics_interpolation_enabled() const {
return _physics_interpolation_enabled;
}
#ifndef _3D_DISABLED
void SceneTree::client_physics_interpolation_add_node_3d(SelfList<Node3D> *p_elem) {
// This ensures that _update_physics_interpolation_data() will be called at least once every
// physics tick, to ensure the previous and current transforms are kept up to date.
_client_physics_interpolation._node_3d_list.add(p_elem);
}
void SceneTree::client_physics_interpolation_remove_node_3d(SelfList<Node3D> *p_elem) {
_client_physics_interpolation._node_3d_list.remove(p_elem);
}
#endif
void SceneTree::iteration_prepare() {
if (_physics_interpolation_enabled) {
// Make sure any pending transforms from the last tick / frame
// are flushed before pumping the interpolation prev and currents.
flush_transform_notifications();
RenderingServer::get_singleton()->tick();
}
}
@ -492,17 +534,32 @@ bool SceneTree::physics_process(double p_time) {
MessageQueue::get_singleton()->flush(); //small little hack
process_timers(p_time, true); //go through timers
process_tweens(p_time, true);
flush_transform_notifications();
// This should happen last because any processing that deletes something beforehand might expect the object to be removed in the same frame.
_flush_delete_queue();
_call_idle_callbacks();
return _quit;
}
void SceneTree::iteration_end() {
// When physics interpolation is active, we want all pending transforms
// to be flushed to the RenderingServer before finishing a physics tick.
if (_physics_interpolation_enabled) {
flush_transform_notifications();
#ifndef _3D_DISABLED
// Any objects performing client physics interpolation
// should be given an opportunity to keep their previous transforms
// up to date.
_client_physics_interpolation.physics_process();
#endif
}
}
bool SceneTree::process(double p_time) {
if (MainLoop::process(p_time)) {
_quit = true;
@ -529,78 +586,94 @@ bool SceneTree::process(double p_time) {
MessageQueue::get_singleton()->flush(); //small little hack
flush_transform_notifications(); //transforms after world update, to avoid unnecessary enter/exit notifications
_flush_delete_queue();
if (unlikely(pending_new_scene)) {
_flush_scene_change();
}
process_timers(p_time, false); //go through timers
process_tweens(p_time, false);
flush_transform_notifications(); //additional transforms after timers update
flush_transform_notifications(); // Additional transforms after timers update.
// This should happen last because any processing that deletes something beforehand might expect the object to be removed in the same frame.
_flush_delete_queue();
_call_idle_callbacks();
#ifdef TOOLS_ENABLED
#ifndef _3D_DISABLED
if (Engine::get_singleton()->is_editor_hint()) {
//simple hack to reload fallback environment if it changed from editor
String env_path = GLOBAL_GET(SNAME("rendering/environment/defaults/default_environment"));
env_path = env_path.strip_edges(); //user may have added a space or two
String cpath;
Ref<Environment> fallback = get_root()->get_world_3d()->get_fallback_environment();
if (fallback.is_valid()) {
cpath = fallback->get_path();
}
if (cpath != env_path) {
if (!env_path.is_empty()) {
fallback = ResourceLoader::load(env_path);
if (fallback.is_null()) {
//could not load fallback, set as empty
ProjectSettings::get_singleton()->set("rendering/environment/defaults/default_environment", "");
}
} else {
fallback.unref();
env_path = env_path.strip_edges(); // User may have added a space or two.
bool can_load = true;
if (env_path.begins_with("uid://")) {
// If an uid path, ensure it is mapped to a resource which could not be
// the case if the editor is still scanning the filesystem.
ResourceUID::ID id = ResourceUID::get_singleton()->text_to_id(env_path);
can_load = ResourceUID::get_singleton()->has_id(id);
if (can_load) {
env_path = ResourceUID::get_singleton()->get_id_path(id);
}
}
if (can_load) {
String cpath;
Ref<Environment> fallback = get_root()->get_world_3d()->get_fallback_environment();
if (fallback.is_valid()) {
cpath = fallback->get_path();
}
if (cpath != env_path) {
if (!env_path.is_empty()) {
fallback = ResourceLoader::load(env_path);
if (fallback.is_null()) {
//could not load fallback, set as empty
ProjectSettings::get_singleton()->set("rendering/environment/defaults/default_environment", "");
}
} else {
fallback.unref();
}
get_root()->get_world_3d()->set_fallback_environment(fallback);
}
get_root()->get_world_3d()->set_fallback_environment(fallback);
}
}
#endif // _3D_DISABLED
#endif // TOOLS_ENABLED
if (_physics_interpolation_enabled) {
RenderingServer::get_singleton()->pre_draw(true);
}
return _quit;
}
void SceneTree::process_timers(double p_delta, bool p_physics_frame) {
_THREAD_SAFE_METHOD_
List<Ref<SceneTreeTimer>>::Element *L = timers.back(); //last element
const List<Ref<SceneTreeTimer>>::Element *L = timers.back(); // Last element.
const double unscaled_delta = Engine::get_singleton()->get_process_step();
for (List<Ref<SceneTreeTimer>>::Element *E = timers.front(); E;) {
List<Ref<SceneTreeTimer>>::Element *N = E->next();
if ((paused && !E->get()->is_process_always()) || (E->get()->is_process_in_physics() != p_physics_frame)) {
Ref<SceneTreeTimer> timer = E->get();
if ((paused && !timer->is_process_always()) || (timer->is_process_in_physics() != p_physics_frame)) {
if (E == L) {
break; //break on last, so if new timers were added during list traversal, ignore them.
break; // Break on last, so if new timers were added during list traversal, ignore them.
}
E = N;
continue;
}
double time_left = E->get()->get_time_left();
if (E->get()->is_ignore_time_scale()) {
time_left -= Engine::get_singleton()->get_process_step();
} else {
time_left -= p_delta;
}
E->get()->set_time_left(time_left);
double time_left = timer->get_time_left();
time_left -= timer->is_ignoring_time_scale() ? unscaled_delta : p_delta;
timer->set_time_left(time_left);
if (time_left <= 0) {
E->get()->emit_signal(SNAME("timeout"));
timers.erase(E);
}
if (E == L) {
break; //break on last, so if new timers were added during list traversal, ignore them.
break; // Break on last, so if new timers were added during list traversal, ignore them.
}
E = N;
}
@ -609,12 +682,15 @@ void SceneTree::process_timers(double p_delta, bool p_physics_frame) {
void SceneTree::process_tweens(double p_delta, bool p_physics) {
_THREAD_SAFE_METHOD_
// This methods works similarly to how SceneTreeTimers are handled.
List<Ref<Tween>>::Element *L = tweens.back();
const List<Ref<Tween>>::Element *L = tweens.back();
const double unscaled_delta = Engine::get_singleton()->get_process_step();
for (List<Ref<Tween>>::Element *E = tweens.front(); E;) {
List<Ref<Tween>>::Element *N = E->next();
Ref<Tween> &tween = E->get();
// Don't process if paused or process mode doesn't match.
if (!E->get()->can_process(paused) || (p_physics == (E->get()->get_process_mode() == Tween::TWEEN_PROCESS_IDLE))) {
if (!tween->can_process(paused) || (p_physics == (tween->get_process_mode() == Tween::TWEEN_PROCESS_IDLE))) {
if (E == L) {
break;
}
@ -622,8 +698,8 @@ void SceneTree::process_tweens(double p_delta, bool p_physics) {
continue;
}
if (!E->get()->step(p_delta)) {
E->get()->clear();
if (!tween->step(tween->is_ignoring_time_scale() ? unscaled_delta : p_delta)) {
tween->clear();
tweens.erase(E);
}
if (E == L) {
@ -833,7 +909,7 @@ Ref<ArrayMesh> SceneTree::get_debug_contact_mesh() {
return debug_contact_mesh;
}
debug_contact_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
debug_contact_mesh.instantiate();
Ref<StandardMaterial3D> mat = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
@ -888,11 +964,14 @@ Ref<ArrayMesh> SceneTree::get_debug_contact_mesh() {
void SceneTree::set_pause(bool p_enabled) {
ERR_FAIL_COND_MSG(!Thread::is_main_thread(), "Pause can only be set from the main thread.");
ERR_FAIL_COND_MSG(suspended, "Pause state cannot be modified while suspended.");
if (p_enabled == paused) {
return;
}
paused = p_enabled;
#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->set_active(!p_enabled);
#endif // _3D_DISABLED
@ -906,6 +985,30 @@ bool SceneTree::is_paused() const {
return paused;
}
void SceneTree::set_suspend(bool p_enabled) {
ERR_FAIL_COND_MSG(!Thread::is_main_thread(), "Suspend can only be set from the main thread.");
if (p_enabled == suspended) {
return;
}
suspended = p_enabled;
Engine::get_singleton()->set_freeze_time_scale(p_enabled);
#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->set_active(!p_enabled && !paused);
#endif // _3D_DISABLED
PhysicsServer2D::get_singleton()->set_active(!p_enabled && !paused);
if (get_root()) {
get_root()->_propagate_suspend_notification(p_enabled);
}
}
bool SceneTree::is_suspended() const {
return suspended;
}
void SceneTree::_process_group(ProcessGroup *p_group, bool p_physics) {
// When reading this function, keep in mind that this code must work in a way where
// if any node is removed, this needs to continue working.
@ -1257,8 +1360,8 @@ void SceneTree::_call_group_flags(const Variant **p_args, int p_argcount, Callab
ERR_FAIL_COND(p_argcount < 3);
ERR_FAIL_COND(!p_args[0]->is_num());
ERR_FAIL_COND(p_args[1]->get_type() != Variant::STRING_NAME && p_args[1]->get_type() != Variant::STRING);
ERR_FAIL_COND(p_args[2]->get_type() != Variant::STRING_NAME && p_args[2]->get_type() != Variant::STRING);
ERR_FAIL_COND(!p_args[1]->is_string());
ERR_FAIL_COND(!p_args[2]->is_string());
int flags = *p_args[0];
StringName group = *p_args[1];
@ -1271,8 +1374,8 @@ void SceneTree::_call_group(const Variant **p_args, int p_argcount, Callable::Ca
r_error.error = Callable::CallError::CALL_OK;
ERR_FAIL_COND(p_argcount < 2);
ERR_FAIL_COND(p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING);
ERR_FAIL_COND(p_args[1]->get_type() != Variant::STRING_NAME && p_args[1]->get_type() != Variant::STRING);
ERR_FAIL_COND(!p_args[0]->is_string());
ERR_FAIL_COND(!p_args[1]->is_string());
StringName group = *p_args[0];
StringName method = *p_args[1];
@ -1486,11 +1589,22 @@ Ref<SceneTreeTimer> SceneTree::create_timer(double p_delay_sec, bool p_process_a
Ref<Tween> SceneTree::create_tween() {
_THREAD_SAFE_METHOD_
Ref<Tween> tween = memnew(Tween(true));
Ref<Tween> tween;
tween.instantiate(this);
tweens.push_back(tween);
return tween;
}
void SceneTree::remove_tween(const Ref<Tween> &p_tween) {
_THREAD_SAFE_METHOD_
for (List<Ref<Tween>>::Element *E = tweens.back(); E; E = E->prev()) {
if (E->get() == p_tween) {
E->erase();
break;
}
}
}
TypedArray<Tween> SceneTree::get_processed_tweens() {
_THREAD_SAFE_METHOD_
TypedArray<Tween> ret;
@ -1537,7 +1651,7 @@ Ref<MultiplayerAPI> SceneTree::get_multiplayer(const NodePath &p_for_path) const
void SceneTree::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer, const NodePath &p_root_path) {
ERR_FAIL_COND_MSG(!Thread::is_main_thread(), "Multiplayer can only be manipulated from the main thread.");
if (p_root_path.is_empty()) {
ERR_FAIL_COND(!p_multiplayer.is_valid());
ERR_FAIL_COND(p_multiplayer.is_null());
if (multiplayer.is_valid()) {
multiplayer->object_configuration_remove(nullptr, NodePath("/" + root->get_name()));
}
@ -1731,7 +1845,7 @@ SceneTree::SceneTree() {
debug_collisions_color = GLOBAL_DEF("debug/shapes/collision/shape_color", Color(0.0, 0.6, 0.7, 0.42));
debug_collision_contact_color = GLOBAL_DEF("debug/shapes/collision/contact_color", Color(1.0, 0.2, 0.1, 0.8));
debug_paths_color = GLOBAL_DEF("debug/shapes/paths/geometry_color", Color(0.1, 1.0, 0.7, 0.4));
debug_paths_width = GLOBAL_DEF("debug/shapes/paths/geometry_width", 2.0);
debug_paths_width = GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "debug/shapes/paths/geometry_width", PROPERTY_HINT_RANGE, "0.01,10,0.001,or_greater"), 2.0);
collision_debug_contacts = GLOBAL_DEF(PropertyInfo(Variant::INT, "debug/shapes/collision/max_contacts_displayed", PROPERTY_HINT_RANGE, "0,20000,1"), 10000);
GLOBAL_DEF("debug/shapes/collision/draw_2d_outlines", true);
@ -1753,7 +1867,7 @@ SceneTree::SceneTree() {
}
#ifndef _3D_DISABLED
if (!root->get_world_3d().is_valid()) {
if (root->get_world_3d().is_null()) {
root->set_world_3d(Ref<World3D>(memnew(World3D)));
}
root->set_as_audio_listener_3d(true);
@ -1761,22 +1875,29 @@ SceneTree::SceneTree() {
set_physics_interpolation_enabled(GLOBAL_DEF("physics/common/physics_interpolation", false));
// Always disable jitter fix if physics interpolation is enabled -
// Jitter fix will interfere with interpolation, and is not necessary
// when interpolation is active.
if (is_physics_interpolation_enabled()) {
Engine::get_singleton()->set_physics_jitter_fix(0);
}
// Initialize network state.
set_multiplayer(MultiplayerAPI::create_default_interface());
root->set_as_audio_listener_2d(true);
current_scene = nullptr;
const int msaa_mode_2d = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/anti_aliasing/quality/msaa_2d", PROPERTY_HINT_ENUM, String::utf8("Disabled (Fastest),2× (Average),4× (Slow),8× (Slowest)")), 0);
const int msaa_mode_2d = GLOBAL_GET("rendering/anti_aliasing/quality/msaa_2d");
root->set_msaa_2d(Viewport::MSAA(msaa_mode_2d));
const int msaa_mode_3d = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/anti_aliasing/quality/msaa_3d", PROPERTY_HINT_ENUM, String::utf8("Disabled (Fastest),2× (Average),4× (Slow),8× (Slowest)")), 0);
const int msaa_mode_3d = GLOBAL_GET("rendering/anti_aliasing/quality/msaa_3d");
root->set_msaa_3d(Viewport::MSAA(msaa_mode_3d));
const bool transparent_background = GLOBAL_DEF("rendering/viewport/transparent_background", false);
root->set_transparent_background(transparent_background);
const bool use_hdr_2d = GLOBAL_DEF_RST_BASIC("rendering/viewport/hdr_2d", false);
const bool use_hdr_2d = GLOBAL_GET("rendering/viewport/hdr_2d");
root->set_use_hdr_2d(use_hdr_2d);
const int ssaa_mode = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/anti_aliasing/quality/screen_space_aa", PROPERTY_HINT_ENUM, "Disabled (Fastest),FXAA (Fast)"), 0);
@ -1820,7 +1941,7 @@ SceneTree::SceneTree() {
int shadowmap_size = GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/lights_and_shadows/positional_shadow/atlas_size", PROPERTY_HINT_RANGE, "256,16384"), 4096);
GLOBAL_DEF("rendering/lights_and_shadows/positional_shadow/atlas_size.mobile", 2048);
bool shadowmap_16_bits = GLOBAL_DEF("rendering/lights_and_shadows/positional_shadow/atlas_16_bits", true);
bool shadowmap_16_bits = GLOBAL_GET("rendering/lights_and_shadows/positional_shadow/atlas_16_bits");
int atlas_q0 = GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/lights_and_shadows/positional_shadow/atlas_quadrant_0_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), 2);
int atlas_q1 = GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/lights_and_shadows/positional_shadow/atlas_quadrant_1_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), 2);
int atlas_q2 = GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/lights_and_shadows/positional_shadow/atlas_quadrant_2_subdiv", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), 3);

View file

@ -41,6 +41,9 @@
class PackedScene;
class Node;
#ifndef _3D_DISABLED
class Node3D;
#endif
class Window;
class Material;
class Mesh;
@ -71,7 +74,7 @@ public:
bool is_process_in_physics();
void set_ignore_time_scale(bool p_ignore);
bool is_ignore_time_scale();
bool is_ignoring_time_scale();
void release_connections();
@ -120,6 +123,13 @@ private:
bool changed = false;
};
#ifndef _3D_DISABLED
struct ClientPhysicsInterpolation {
SelfList<Node3D>::List _node_3d_list;
void physics_process();
} _client_physics_interpolation;
#endif
Window *root = nullptr;
double physics_process_time = 0.0;
@ -133,6 +143,7 @@ private:
bool debug_navigation_hint = false;
#endif
bool paused = false;
bool suspended = false;
HashMap<StringName, Group> group_map;
bool _quit = false;
@ -315,6 +326,7 @@ public:
virtual void iteration_prepare() override;
virtual bool physics_process(double p_time) override;
virtual void iteration_end() override;
virtual bool process(double p_time) override;
virtual void finalize() override;
@ -332,6 +344,8 @@ public:
void set_pause(bool p_enabled);
bool is_paused() const;
void set_suspend(bool p_enabled);
bool is_suspended() const;
#ifdef DEBUG_ENABLED
void set_debug_collisions_hint(bool p_enabled);
@ -397,6 +411,7 @@ public:
Ref<SceneTreeTimer> create_timer(double p_delay_sec, bool p_process_always = true, bool p_process_in_physics = false, bool p_ignore_time_scale = false);
Ref<Tween> create_tween();
void remove_tween(const Ref<Tween> &p_tween);
TypedArray<Tween> get_processed_tweens();
//used by Main::start, don't use otherwise
@ -423,6 +438,11 @@ public:
void set_physics_interpolation_enabled(bool p_enabled);
bool is_physics_interpolation_enabled() const;
#ifndef _3D_DISABLED
void client_physics_interpolation_add_node_3d(SelfList<Node3D> *p_elem);
void client_physics_interpolation_remove_node_3d(SelfList<Node3D> *p_elem);
#endif
SceneTree();
~SceneTree();
};

View file

@ -197,6 +197,11 @@ void ShaderGlobalsOverride::_get_property_list(List<PropertyInfo> *p_list) const
pinfo.hint = PROPERTY_HINT_RESOURCE_TYPE;
pinfo.hint_string = "Cubemap";
} break;
case RS::GLOBAL_VAR_TYPE_SAMPLEREXT: {
pinfo.type = Variant::OBJECT;
pinfo.hint = PROPERTY_HINT_RESOURCE_TYPE;
pinfo.hint_string = "ExternalTexture";
} break;
default: {
} break;
}

View file

@ -48,7 +48,11 @@ void Timer::_notification(int p_what) {
if (!processing || timer_process_callback == TIMER_PROCESS_PHYSICS || !is_processing_internal()) {
return;
}
time_left -= get_process_delta_time();
if (ignore_time_scale) {
time_left -= Engine::get_singleton()->get_process_step();
} else {
time_left -= get_process_delta_time();
}
if (time_left < 0) {
if (!one_shot) {
@ -65,7 +69,11 @@ void Timer::_notification(int p_what) {
if (!processing || timer_process_callback == TIMER_PROCESS_IDLE || !is_physics_processing_internal()) {
return;
}
time_left -= get_physics_process_delta_time();
if (ignore_time_scale) {
time_left -= Engine::get_singleton()->get_process_step();
} else {
time_left -= get_physics_process_delta_time();
}
if (time_left < 0) {
if (!one_shot) {
@ -134,6 +142,14 @@ bool Timer::is_paused() const {
return paused;
}
void Timer::set_ignore_time_scale(bool p_ignore) {
ignore_time_scale = p_ignore;
}
bool Timer::is_ignoring_time_scale() {
return ignore_time_scale;
}
bool Timer::is_stopped() const {
return get_time_left() <= 0;
}
@ -206,6 +222,9 @@ void Timer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_paused", "paused"), &Timer::set_paused);
ClassDB::bind_method(D_METHOD("is_paused"), &Timer::is_paused);
ClassDB::bind_method(D_METHOD("set_ignore_time_scale", "ignore"), &Timer::set_ignore_time_scale);
ClassDB::bind_method(D_METHOD("is_ignoring_time_scale"), &Timer::is_ignoring_time_scale);
ClassDB::bind_method(D_METHOD("is_stopped"), &Timer::is_stopped);
ClassDB::bind_method(D_METHOD("get_time_left"), &Timer::get_time_left);
@ -220,6 +239,7 @@ void Timer::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "is_one_shot");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autostart"), "set_autostart", "has_autostart");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "paused", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_paused", "is_paused");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_time_scale"), "set_ignore_time_scale", "is_ignoring_time_scale");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_left", PROPERTY_HINT_NONE, "suffix:s", PROPERTY_USAGE_NONE), "", "get_time_left");
BIND_ENUM_CONSTANT(TIMER_PROCESS_PHYSICS);

View file

@ -41,6 +41,7 @@ class Timer : public Node {
bool autostart = false;
bool processing = false;
bool paused = false;
bool ignore_time_scale = false;
double time_left = -1.0;
@ -69,6 +70,9 @@ public:
void set_paused(bool p_paused);
bool is_paused() const;
void set_ignore_time_scale(bool p_ignore);
bool is_ignoring_time_scale();
bool is_stopped() const;
double get_time_left() const;

File diff suppressed because it is too large Load diff

View file

@ -63,6 +63,7 @@ class ViewportTexture : public Texture2D {
bool vp_changed = false;
void _setup_local_to_scene(const Node *p_loc_scene);
void _err_print_viewport_not_set() const;
mutable RID proxy_ph;
mutable RID proxy;
@ -99,6 +100,8 @@ public:
SCALING_3D_MODE_BILINEAR,
SCALING_3D_MODE_FSR,
SCALING_3D_MODE_FSR2,
SCALING_3D_MODE_METALFX_SPATIAL,
SCALING_3D_MODE_METALFX_TEMPORAL,
SCALING_3D_MODE_MAX
};
@ -122,6 +125,15 @@ public:
MSAA_MAX
};
enum AnisotropicFiltering {
ANISOTROPY_DISABLED,
ANISOTROPY_2X,
ANISOTROPY_4X,
ANISOTROPY_8X,
ANISOTROPY_16X,
ANISOTROPY_MAX
};
enum ScreenSpaceAA {
SCREEN_SPACE_AA_DISABLED,
SCREEN_SPACE_AA_FXAA,
@ -281,7 +293,7 @@ private:
bool disable_3d = false;
void _propagate_viewport_notification(Node *p_node, int p_what);
static void _propagate_drag_notification(Node *p_node, int p_what);
void _update_global_transform();
@ -302,6 +314,7 @@ private:
float scaling_3d_scale = 1.0;
float fsr_sharpness = 0.2f;
float texture_mipmap_bias = 0.0f;
AnisotropicFiltering anisotropic_filtering_level = ANISOTROPY_4X;
bool use_debanding = false;
float mesh_lod_threshold = 1.0;
bool use_occlusion_culling = false;
@ -349,9 +362,7 @@ private:
Ref<Texture2D> vrs_texture;
struct GUI {
bool forced_mouse_focus = false; //used for menu buttons
bool mouse_in_viewport = false;
bool key_event_accepted = false;
HashMap<int, ObjectID> touch_focus;
Control *mouse_focus = nullptr;
Control *mouse_click_grabber = nullptr;
@ -363,7 +374,6 @@ private:
Window *subwindow_over = nullptr; // mouse_over and subwindow_over are mutually exclusive. At all times at least one of them is nullptr.
Window *windowmanager_window_over = nullptr; // Only used in root Viewport.
Control *drag_mouse_over = nullptr;
Vector2 drag_mouse_over_pos;
Control *tooltip_control = nullptr;
Window *tooltip_popup = nullptr;
Label *tooltip_label = nullptr;
@ -372,7 +382,7 @@ private:
Point2 last_mouse_pos;
Point2 drag_accum;
bool drag_attempted = false;
Variant drag_data;
Variant drag_data; // Only used in root-Viewport and SubViewports, that are not children of a SubViewportContainer.
ObjectID drag_preview_id;
Ref<SceneTreeTimer> tooltip_timer;
double tooltip_delay = 0.0;
@ -380,8 +390,10 @@ private:
List<Control *> roots;
HashSet<ObjectID> canvas_parents_with_dirty_order;
int canvas_sort_index = 0; //for sorting items with canvas as root
bool dragging = false;
bool dragging = false; // Is true in the viewport in which dragging started while dragging is active.
bool global_dragging = false; // Is true while dragging is active. Only used in root-Viewport and SubViewports that are not children of a SubViewportContainer.
bool drag_successful = false;
Control *target_control = nullptr; // Control that the mouse is over in the innermost nested Viewport. Only used in root-Viewport and SubViewports, that are not children of a SubViewportContainer.
bool embed_subwindows_hint = false;
Window *subwindow_focused = nullptr;
@ -401,15 +413,16 @@ private:
DefaultCanvasItemTextureRepeat default_canvas_item_texture_repeat = DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_DISABLED;
bool disable_input = false;
bool disable_input_override = false;
bool _gui_call_input(Control *p_control, const Ref<InputEvent> &p_input);
void _gui_call_input(Control *p_control, const Ref<InputEvent> &p_input);
void _gui_call_notification(Control *p_control, int p_what);
void _gui_sort_roots();
Control *_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform);
void _gui_input_event(Ref<InputEvent> p_event);
void _perform_drop(Control *p_control = nullptr, Point2 p_pos = Point2());
void _perform_drop(Control *p_control = nullptr);
void _gui_cleanup_internal_state(Ref<InputEvent> p_event);
void _push_unhandled_input_internal(const Ref<InputEvent> &p_event);
@ -475,6 +488,9 @@ private:
void _process_dirty_canvas_parent_orders();
void _propagate_world_2d_changed(Node *p_node);
void _window_start_drag(Window *p_window);
void _window_start_resize(SubWindowResize p_edge, Window *p_window);
protected:
bool _set_size(const Size2i &p_size, const Size2i &p_size_2d_override, bool p_allocated);
@ -514,6 +530,7 @@ public:
void set_global_canvas_transform(const Transform2D &p_transform);
Transform2D get_global_canvas_transform() const;
Transform2D get_stretch_transform() const;
virtual Transform2D get_final_transform() const;
void gui_set_root_order_dirty();
@ -559,6 +576,9 @@ public:
void set_texture_mipmap_bias(float p_texture_mipmap_bias);
float get_texture_mipmap_bias() const;
void set_anisotropic_filtering_level(AnisotropicFiltering p_anisotropic_filtering_level);
AnisotropicFiltering get_anisotropic_filtering_level() const;
void set_use_debanding(bool p_use_debanding);
bool is_using_debanding() const;
@ -576,12 +596,17 @@ public:
#ifndef DISABLE_DEPRECATED
void push_unhandled_input(const Ref<InputEvent> &p_event, bool p_local_coords = false);
#endif // DISABLE_DEPRECATED
void notify_mouse_entered();
void notify_mouse_exited();
void set_disable_input(bool p_disable);
bool is_input_disabled() const;
void set_disable_input_override(bool p_disable);
Vector2 get_mouse_position() const;
void warp_mouse(const Vector2 &p_position);
Point2 wrap_mouse_in_rect(const Vector2 &p_relative, const Rect2 &p_rect);
virtual void update_mouse_cursor_state();
void set_physics_object_picking(bool p_enable);
@ -660,9 +685,7 @@ public:
Rect2i subwindow_get_popup_safe_rect(Window *p_window) const;
Viewport *get_parent_viewport() const;
Window *get_base_window() const;
void pass_mouse_focus_to(Viewport *p_viewport, Control *p_control);
Window *get_base_window();
void set_canvas_cull_mask(uint32_t p_layers);
uint32_t get_canvas_cull_mask() const;
@ -670,14 +693,18 @@ public:
void set_canvas_cull_mask_bit(uint32_t p_layer, bool p_enable);
bool get_canvas_cull_mask_bit(uint32_t p_layer) const;
#ifdef TOOLS_ENABLED
bool is_visible_subviewport() const;
#endif // TOOLS_ENABLED
virtual bool is_size_2d_override_stretch_enabled() const { return true; }
Transform2D get_screen_transform() const;
virtual Transform2D get_screen_transform_internal(bool p_absolute_position = false) const;
virtual Transform2D get_popup_base_transform() const { return Transform2D(); }
virtual bool is_directly_attached_to_screen() const { return false; };
virtual bool is_attached_in_viewport() const { return false; };
virtual bool is_sub_viewport() const { return false; };
virtual Viewport *get_section_root_viewport() const { return nullptr; }
virtual bool is_attached_in_viewport() const { return false; }
virtual bool is_sub_viewport() const { return false; }
private:
// 2D audio, camera, and physics. (don't put World2D here because World2D is needed for Control nodes).
@ -772,6 +799,11 @@ public:
void set_camera_3d_override_perspective(real_t p_fovy_degrees, real_t p_z_near, real_t p_z_far);
void set_camera_3d_override_orthogonal(real_t p_size, real_t p_z_near, real_t p_z_far);
HashMap<StringName, real_t> get_camera_3d_override_properties() const;
Vector3 camera_3d_override_project_ray_normal(const Point2 &p_pos) const;
Vector3 camera_3d_override_project_ray_origin(const Point2 &p_pos) const;
Vector3 camera_3d_override_project_local_ray_normal(const Point2 &p_pos) const;
void set_disable_3d(bool p_disable);
bool is_3d_disabled() const;
@ -839,9 +871,9 @@ public:
virtual Transform2D get_screen_transform_internal(bool p_absolute_position = false) const override;
virtual Transform2D get_popup_base_transform() const override;
virtual bool is_directly_attached_to_screen() const override;
virtual Viewport *get_section_root_viewport() const override;
virtual bool is_attached_in_viewport() const override;
virtual bool is_sub_viewport() const override { return true; };
virtual bool is_sub_viewport() const override { return true; }
void _validate_property(PropertyInfo &p_property) const;
SubViewport();
@ -851,6 +883,7 @@ VARIANT_ENUM_CAST(Viewport::Scaling3DMode);
VARIANT_ENUM_CAST(SubViewport::UpdateMode);
VARIANT_ENUM_CAST(Viewport::PositionalShadowAtlasQuadrantSubdiv);
VARIANT_ENUM_CAST(Viewport::MSAA);
VARIANT_ENUM_CAST(Viewport::AnisotropicFiltering);
VARIANT_ENUM_CAST(Viewport::ScreenSpaceAA);
VARIANT_ENUM_CAST(Viewport::DebugDraw);
VARIANT_ENUM_CAST(Viewport::SDFScale);

View file

@ -1,48 +0,0 @@
/**************************************************************************/
/* window.compat.inc */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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 DISABLE_DEPRECATED
void Window::_bind_compatibility_methods() {
ClassDB::bind_compatibility_method(D_METHOD("get_theme_icon", "name", "theme_type"), &Window::get_theme_icon, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("get_theme_stylebox", "name", "theme_type"), &Window::get_theme_stylebox, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("get_theme_font", "name", "theme_type"), &Window::get_theme_font, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("get_theme_font_size", "name", "theme_type"), &Window::get_theme_font_size, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("get_theme_color", "name", "theme_type"), &Window::get_theme_color, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("get_theme_constant", "name", "theme_type"), &Window::get_theme_constant, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("has_theme_icon", "name", "theme_type"), &Window::has_theme_icon, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("has_theme_stylebox", "name", "theme_type"), &Window::has_theme_stylebox, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("has_theme_font", "name", "theme_type"), &Window::has_theme_font, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("has_theme_font_size", "name", "theme_type"), &Window::has_theme_font_size, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("has_theme_color", "name", "theme_type"), &Window::has_theme_color, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("has_theme_constant", "name", "theme_type"), &Window::has_theme_constant, DEFVAL(""));
}
#endif

View file

@ -29,13 +29,11 @@
/**************************************************************************/
#include "window.h"
#include "window.compat.inc"
#include "core/config/project_settings.h"
#include "core/debugger/engine_debugger.h"
#include "core/input/shortcut.h"
#include "core/string/translation.h"
#include "core/variant/variant_parser.h"
#include "core/string/translation_server.h"
#include "scene/gui/control.h"
#include "scene/theme/theme_db.h"
#include "scene/theme/theme_owner.h"
@ -273,16 +271,25 @@ void Window::_validate_property(PropertyInfo &p_property) const {
//
Window *Window::get_from_id(DisplayServer::WindowID p_window_id) {
if (p_window_id == DisplayServer::INVALID_WINDOW_ID) {
return nullptr;
}
return Object::cast_to<Window>(ObjectDB::get_instance(DisplayServer::get_singleton()->window_get_attached_instance_id(p_window_id)));
}
void Window::set_title(const String &p_title) {
ERR_MAIN_THREAD_GUARD;
title = p_title;
tr_title = atr(p_title);
#ifdef DEBUG_ENABLED
if (window_id == DisplayServer::MAIN_WINDOW_ID) {
if (window_id == DisplayServer::MAIN_WINDOW_ID && !Engine::get_singleton()->is_project_manager_hint()) {
// Append a suffix to the window title to denote that the project is running
// from a debug build (including the editor). Since this results in lower performance,
// this should be clearly presented to the user.
// from a debug build (including the editor, excluding the project manager).
// Since this results in lower performance, this should be clearly presented
// to the user.
tr_title = vformat("%s (DEBUG)", tr_title);
}
#endif
@ -299,6 +306,15 @@ void Window::set_title(const String &p_title) {
}
}
}
emit_signal("title_changed");
#ifdef DEBUG_ENABLED
if (EngineDebugger::get_singleton() && window_id == DisplayServer::MAIN_WINDOW_ID && !Engine::get_singleton()->is_project_manager_hint()) {
Array arr;
arr.push_back(tr_title);
EngineDebugger::get_singleton()->send_message("window:title", arr);
}
#endif
}
String Window::get_title() const {
@ -306,6 +322,11 @@ String Window::get_title() const {
return title;
}
String Window::get_translated_title() const {
ERR_READ_THREAD_GUARD_V(String());
return tr_title;
}
void Window::_settings_changed() {
if (visible && initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE && is_in_edited_scene_root()) {
Size2 screen_size = Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
@ -388,6 +409,12 @@ void Window::move_to_center() {
void Window::set_size(const Size2i &p_size) {
ERR_MAIN_THREAD_GUARD;
#if defined(ANDROID_ENABLED)
if (!get_parent() && is_inside_tree()) {
// Can't set root window size on Android.
return;
}
#endif
size = p_size;
_update_window_size();
@ -458,6 +485,12 @@ void Window::_validate_limit_size() {
void Window::set_max_size(const Size2i &p_max_size) {
ERR_MAIN_THREAD_GUARD;
#if defined(ANDROID_ENABLED)
if (!get_parent() && is_inside_tree()) {
// Can't set root window size on Android.
return;
}
#endif
Size2i max_size_clamped = _clamp_limit_size(p_max_size);
if (max_size == max_size_clamped) {
return;
@ -475,6 +508,12 @@ Size2i Window::get_max_size() const {
void Window::set_min_size(const Size2i &p_min_size) {
ERR_MAIN_THREAD_GUARD;
#if defined(ANDROID_ENABLED)
if (!get_parent() && is_inside_tree()) {
// Can't set root window size on Android.
return;
}
#endif
Size2i min_size_clamped = _clamp_limit_size(p_min_size);
if (min_size == min_size_clamped) {
return;
@ -701,7 +740,11 @@ void Window::_rect_changed_callback(const Rect2i &p_callback) {
if (size == p_callback.size && position == p_callback.position) {
return;
}
position = p_callback.position;
if (position != p_callback.position) {
position = p_callback.position;
_propagate_window_notification(this, NOTIFICATION_WM_POSITION_CHANGED);
}
if (size != p_callback.size) {
size = p_callback.size;
@ -910,7 +953,7 @@ void Window::_make_transient() {
if (!is_embedded() && transient_to_focused) {
DisplayServer::WindowID focused_window_id = DisplayServer::get_singleton()->get_focused_window();
if (focused_window_id != DisplayServer::INVALID_WINDOW_ID) {
window = Object::cast_to<Window>(ObjectDB::get_instance(DisplayServer::get_singleton()->window_get_attached_instance_id(focused_window_id)));
window = Window::get_from_id(focused_window_id);
}
}
@ -1069,14 +1112,17 @@ void Window::_update_window_size() {
embedder->_sub_window_update(this);
} else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
if (reset_min_first && wrap_controls) {
// Avoid an error if setting max_size to a value between min_size and the previous size_limit.
DisplayServer::get_singleton()->window_set_min_size(Size2i(), window_id);
}
// When main window embedded in the editor, we can't resize the main window.
if (window_id != DisplayServer::MAIN_WINDOW_ID || !Engine::get_singleton()->is_embedded_in_editor()) {
if (reset_min_first && wrap_controls) {
// Avoid an error if setting max_size to a value between min_size and the previous size_limit.
DisplayServer::get_singleton()->window_set_min_size(Size2i(), window_id);
}
DisplayServer::get_singleton()->window_set_max_size(max_size_used, window_id);
DisplayServer::get_singleton()->window_set_min_size(size_limit, window_id);
DisplayServer::get_singleton()->window_set_size(size, window_id);
DisplayServer::get_singleton()->window_set_max_size(max_size_used, window_id);
DisplayServer::get_singleton()->window_set_min_size(size_limit, window_id);
DisplayServer::get_singleton()->window_set_size(size, window_id);
}
}
//update the viewport
@ -1212,7 +1258,7 @@ void Window::_update_viewport_size() {
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
RenderingServer::get_singleton()->viewport_attach_to_screen(get_viewport_rid(), attach_to_screen_rect, window_id);
} else {
} else if (!is_embedded()) {
RenderingServer::get_singleton()->viewport_attach_to_screen(get_viewport_rid(), Rect2i(), DisplayServer::INVALID_WINDOW_ID);
}
@ -1224,6 +1270,7 @@ void Window::_update_viewport_size() {
TS->font_set_global_oversampling(font_oversampling);
if (!ci_updated) {
update_canvas_items();
emit_signal(SNAME("size_changed"));
}
}
}
@ -1231,6 +1278,10 @@ void Window::_update_viewport_size() {
notification(NOTIFICATION_WM_SIZE_CHANGED);
if (embedder) {
float scale = MIN(embedder->stretch_transform.get_scale().width, embedder->stretch_transform.get_scale().height);
Size2 s = Size2(final_size.width * scale, final_size.height * scale).ceil();
RS::get_singleton()->viewport_set_global_canvas_transform(get_viewport_rid(), global_canvas_transform * scale * content_scale_factor);
RS::get_singleton()->viewport_set_size(get_viewport_rid(), s.width, s.height);
embedder->_sub_window_update(this);
}
}
@ -1395,10 +1446,11 @@ void Window::_notification(int p_what) {
tr_title = atr(title);
#ifdef DEBUG_ENABLED
if (window_id == DisplayServer::MAIN_WINDOW_ID) {
if (window_id == DisplayServer::MAIN_WINDOW_ID && !Engine::get_singleton()->is_project_manager_hint()) {
// Append a suffix to the window title to denote that the project is running
// from a debug build (including the editor). Since this results in lower performance,
// this should be clearly presented to the user.
// from a debug build (including the editor, excluding the project manager).
// Since this results in lower performance, this should be clearly presented
// to the user.
tr_title = vformat("%s (DEBUG)", tr_title);
}
#endif
@ -1602,7 +1654,7 @@ Size2 Window::_get_contents_minimum_size() const {
}
}
return max;
return max * content_scale_factor;
}
void Window::child_controls_changed() {
@ -1631,35 +1683,6 @@ bool Window::_can_consume_input_events() const {
void Window::_window_input(const Ref<InputEvent> &p_ev) {
ERR_MAIN_THREAD_GUARD;
if (EngineDebugger::is_active()) {
// Quit from game window using the stop shortcut (F8 by default).
// The custom shortcut is provided via environment variable when running from the editor.
if (debugger_stop_shortcut.is_null()) {
String shortcut_str = OS::get_singleton()->get_environment("__GODOT_EDITOR_STOP_SHORTCUT__");
if (!shortcut_str.is_empty()) {
Variant shortcut_var;
VariantParser::StreamString ss;
ss.s = shortcut_str;
String errs;
int line;
VariantParser::parse(&ss, shortcut_var, errs, line);
debugger_stop_shortcut = shortcut_var;
}
if (debugger_stop_shortcut.is_null()) {
// Define a default shortcut if it wasn't provided or is invalid.
debugger_stop_shortcut.instantiate();
debugger_stop_shortcut->set_events({ (Variant)InputEventKey::create_reference(Key::F8) });
}
}
Ref<InputEventKey> k = p_ev;
if (k.is_valid() && k->is_pressed() && !k->is_echo() && debugger_stop_shortcut->matches_event(k)) {
EngineDebugger::get_singleton()->send_message("request_quit", Array());
}
}
if (exclusive_child != nullptr) {
if (!is_embedding_subwindows()) { // Not embedding, no need for event.
@ -1984,6 +2007,54 @@ bool Window::has_focus() const {
return focused;
}
void Window::start_drag() {
ERR_MAIN_THREAD_GUARD;
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
DisplayServer::get_singleton()->window_start_drag(window_id);
} else if (embedder) {
embedder->_window_start_drag(this);
}
}
void Window::start_resize(DisplayServer::WindowResizeEdge p_edge) {
ERR_MAIN_THREAD_GUARD;
if (get_flag(FLAG_RESIZE_DISABLED)) {
return;
}
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
DisplayServer::get_singleton()->window_start_resize(p_edge, window_id);
} else if (embedder) {
switch (p_edge) {
case DisplayServer::WINDOW_EDGE_TOP_LEFT: {
embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_TOP_LEFT, this);
} break;
case DisplayServer::WINDOW_EDGE_TOP: {
embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_TOP, this);
} break;
case DisplayServer::WINDOW_EDGE_TOP_RIGHT: {
embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_TOP_RIGHT, this);
} break;
case DisplayServer::WINDOW_EDGE_LEFT: {
embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_LEFT, this);
} break;
case DisplayServer::WINDOW_EDGE_RIGHT: {
embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_RIGHT, this);
} break;
case DisplayServer::WINDOW_EDGE_BOTTOM_LEFT: {
embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_BOTTOM_LEFT, this);
} break;
case DisplayServer::WINDOW_EDGE_BOTTOM: {
embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_BOTTOM, this);
} break;
case DisplayServer::WINDOW_EDGE_BOTTOM_RIGHT: {
embedder->_window_start_resize(Viewport::SUB_WINDOW_RESIZE_BOTTOM_RIGHT, this);
} break;
default:
break;
}
}
}
Rect2i Window::get_usable_parent_rect() const {
ERR_READ_THREAD_GUARD_V(Rect2i());
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
@ -2149,8 +2220,8 @@ Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName
return theme_icon_cache[p_theme_type][p_name];
}
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
Vector<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
Ref<Texture2D> icon = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types);
theme_icon_cache[p_theme_type][p_name] = icon;
return icon;
@ -2173,8 +2244,8 @@ Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringN
return theme_style_cache[p_theme_type][p_name];
}
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
Vector<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
Ref<StyleBox> style = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types);
theme_style_cache[p_theme_type][p_name] = style;
return style;
@ -2197,8 +2268,8 @@ Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_t
return theme_font_cache[p_theme_type][p_name];
}
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
Vector<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
Ref<Font> font = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types);
theme_font_cache[p_theme_type][p_name] = font;
return font;
@ -2221,8 +2292,8 @@ int Window::get_theme_font_size(const StringName &p_name, const StringName &p_th
return theme_font_size_cache[p_theme_type][p_name];
}
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
Vector<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
int font_size = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types);
theme_font_size_cache[p_theme_type][p_name] = font_size;
return font_size;
@ -2245,8 +2316,8 @@ Color Window::get_theme_color(const StringName &p_name, const StringName &p_them
return theme_color_cache[p_theme_type][p_name];
}
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
Vector<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
Color color = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types);
theme_color_cache[p_theme_type][p_name] = color;
return color;
@ -2269,8 +2340,8 @@ int Window::get_theme_constant(const StringName &p_name, const StringName &p_the
return theme_constant_cache[p_theme_type][p_name];
}
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
Vector<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
int constant = theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types);
theme_constant_cache[p_theme_type][p_name] = constant;
return constant;
@ -2315,8 +2386,8 @@ bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_
}
}
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
Vector<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types);
}
@ -2332,8 +2403,8 @@ bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_th
}
}
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
Vector<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types);
}
@ -2349,8 +2420,8 @@ bool Window::has_theme_font(const StringName &p_name, const StringName &p_theme_
}
}
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
Vector<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types);
}
@ -2366,8 +2437,8 @@ bool Window::has_theme_font_size(const StringName &p_name, const StringName &p_t
}
}
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
Vector<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types);
}
@ -2383,8 +2454,8 @@ bool Window::has_theme_color(const StringName &p_name, const StringName &p_theme
}
}
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
Vector<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types);
}
@ -2400,8 +2471,8 @@ bool Window::has_theme_constant(const StringName &p_name, const StringName &p_th
}
}
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
Vector<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types);
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types);
}
@ -2409,7 +2480,7 @@ bool Window::has_theme_constant(const StringName &p_name, const StringName &p_th
void Window::add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) {
ERR_MAIN_THREAD_GUARD;
ERR_FAIL_COND(!p_icon.is_valid());
ERR_FAIL_COND(p_icon.is_null());
if (theme_icon_override.has(p_name)) {
theme_icon_override[p_name]->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
@ -2422,7 +2493,7 @@ void Window::add_theme_icon_override(const StringName &p_name, const Ref<Texture
void Window::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) {
ERR_MAIN_THREAD_GUARD;
ERR_FAIL_COND(!p_style.is_valid());
ERR_FAIL_COND(p_style.is_null());
if (theme_style_override.has(p_name)) {
theme_style_override[p_name]->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
@ -2435,7 +2506,7 @@ void Window::add_theme_style_override(const StringName &p_name, const Ref<StyleB
void Window::add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font) {
ERR_MAIN_THREAD_GUARD;
ERR_FAIL_COND(!p_font.is_valid());
ERR_FAIL_COND(p_font.is_null());
if (theme_font_override.has(p_name)) {
theme_font_override[p_name]->disconnect_changed(callable_mp(this, &Window::_notify_theme_override_changed));
@ -2635,7 +2706,7 @@ void Window::set_unparent_when_invisible(bool p_unparent) {
void Window::set_layout_direction(Window::LayoutDirection p_direction) {
ERR_MAIN_THREAD_GUARD;
ERR_FAIL_INDEX((int)p_direction, 4);
ERR_FAIL_INDEX(p_direction, LAYOUT_DIRECTION_MAX);
layout_dir = p_direction;
propagate_notification(Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED);
@ -2700,13 +2771,20 @@ bool Window::is_layout_rtl() const {
String locale = TranslationServer::get_singleton()->get_tool_locale();
return TS->is_locale_right_to_left(locale);
}
} else if (layout_dir == LAYOUT_DIRECTION_LOCALE) {
} else if (layout_dir == LAYOUT_DIRECTION_APPLICATION_LOCALE) {
if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
return true;
} else {
String locale = TranslationServer::get_singleton()->get_tool_locale();
return TS->is_locale_right_to_left(locale);
}
} else if (layout_dir == LAYOUT_DIRECTION_SYSTEM_LOCALE) {
if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
return true;
} else {
String locale = OS::get_singleton()->get_locale();
return TS->is_locale_right_to_left(locale);
}
} else {
return (layout_dir == LAYOUT_DIRECTION_RTL);
}
@ -2755,12 +2833,16 @@ Transform2D Window::get_popup_base_transform() const {
return popup_base_transform;
}
bool Window::is_directly_attached_to_screen() const {
Viewport *Window::get_section_root_viewport() const {
if (get_embedder()) {
return get_embedder()->is_directly_attached_to_screen();
return get_embedder()->get_section_root_viewport();
}
// Distinguish between the case that this is a native Window and not inside the tree.
return is_inside_tree();
if (is_inside_tree()) {
// Native window.
return SceneTree::get_singleton()->get_root();
}
Window *vp = const_cast<Window *>(this);
return vp;
}
bool Window::is_attached_in_viewport() const {
@ -2863,6 +2945,9 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_focus"), &Window::has_focus);
ClassDB::bind_method(D_METHOD("grab_focus"), &Window::grab_focus);
ClassDB::bind_method(D_METHOD("start_drag"), &Window::start_drag);
ClassDB::bind_method(D_METHOD("start_resize", "edge"), &Window::start_resize);
ClassDB::bind_method(D_METHOD("set_ime_active", "active"), &Window::set_ime_active);
ClassDB::bind_method(D_METHOD("set_ime_position", "position"), &Window::set_ime_position);
@ -2997,6 +3082,8 @@ void Window::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "popup_window"), "set_flag", "get_flag", FLAG_POPUP);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "extend_to_title"), "set_flag", "get_flag", FLAG_EXTEND_TO_TITLE);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "mouse_passthrough"), "set_flag", "get_flag", FLAG_MOUSE_PASSTHROUGH);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "sharp_corners"), "set_flag", "get_flag", FLAG_SHARP_CORNERS);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "exclude_from_capture"), "set_flag", "get_flag", FLAG_EXCLUDE_FROM_CAPTURE);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "force_native"), "set_force_native", "get_force_native");
ADD_GROUP("Limits", "");
@ -3032,6 +3119,7 @@ void Window::_bind_methods() {
ADD_SIGNAL(MethodInfo("theme_changed"));
ADD_SIGNAL(MethodInfo("dpi_changed"));
ADD_SIGNAL(MethodInfo("titlebar_changed"));
ADD_SIGNAL(MethodInfo("title_changed"));
BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
BIND_CONSTANT(NOTIFICATION_THEME_CHANGED);
@ -3050,6 +3138,8 @@ void Window::_bind_methods() {
BIND_ENUM_CONSTANT(FLAG_POPUP);
BIND_ENUM_CONSTANT(FLAG_EXTEND_TO_TITLE);
BIND_ENUM_CONSTANT(FLAG_MOUSE_PASSTHROUGH);
BIND_ENUM_CONSTANT(FLAG_SHARP_CORNERS);
BIND_ENUM_CONSTANT(FLAG_EXCLUDE_FROM_CAPTURE);
BIND_ENUM_CONSTANT(FLAG_MAX);
BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_DISABLED);
@ -3066,9 +3156,14 @@ void Window::_bind_methods() {
BIND_ENUM_CONSTANT(CONTENT_SCALE_STRETCH_INTEGER);
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_INHERITED);
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LOCALE);
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_APPLICATION_LOCALE);
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LTR);
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_RTL);
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_SYSTEM_LOCALE);
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_MAX);
#ifndef DISABLE_DEPRECATED
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LOCALE);
#endif // DISABLE_DEPRECATED
BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_ABSOLUTE);
BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_PRIMARY_SCREEN);

View file

@ -33,6 +33,7 @@
#include "scene/main/viewport.h"
#include "scene/resources/theme.h"
#include "servers/display_server.h"
class Font;
class Shortcut;
@ -62,6 +63,8 @@ public:
FLAG_POPUP = DisplayServer::WINDOW_FLAG_POPUP,
FLAG_EXTEND_TO_TITLE = DisplayServer::WINDOW_FLAG_EXTEND_TO_TITLE,
FLAG_MOUSE_PASSTHROUGH = DisplayServer::WINDOW_FLAG_MOUSE_PASSTHROUGH,
FLAG_SHARP_CORNERS = DisplayServer::WINDOW_FLAG_SHARP_CORNERS,
FLAG_EXCLUDE_FROM_CAPTURE = DisplayServer::WINDOW_FLAG_EXCLUDE_FROM_CAPTURE,
FLAG_MAX = DisplayServer::WINDOW_FLAG_MAX,
};
@ -86,9 +89,14 @@ public:
enum LayoutDirection {
LAYOUT_DIRECTION_INHERITED,
LAYOUT_DIRECTION_LOCALE,
LAYOUT_DIRECTION_APPLICATION_LOCALE,
LAYOUT_DIRECTION_LTR,
LAYOUT_DIRECTION_RTL
LAYOUT_DIRECTION_RTL,
LAYOUT_DIRECTION_SYSTEM_LOCALE,
LAYOUT_DIRECTION_MAX,
#ifndef DISABLE_DEPRECATED
LAYOUT_DIRECTION_LOCALE = LAYOUT_DIRECTION_APPLICATION_LOCALE,
#endif // DISABLE_DEPRECATED
};
enum {
@ -112,7 +120,7 @@ private:
String title;
String tr_title;
mutable int current_screen = 0;
mutable Vector2i position;
mutable Point2i position;
mutable Size2i size = Size2i(DEFAULT_WINDOW_SIZE, DEFAULT_WINDOW_SIZE);
mutable Size2i min_size;
mutable Size2i max_size;
@ -247,10 +255,6 @@ protected:
void _notification(int p_what);
static void _bind_methods();
#ifndef DISABLE_DEPRECATED
static void _bind_compatibility_methods();
#endif
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
@ -269,9 +273,11 @@ public:
};
static void set_root_layout_direction(int p_root_dir);
static Window *get_from_id(DisplayServer::WindowID p_window_id);
void set_title(const String &p_title);
String get_title() const;
String get_translated_title() const;
void set_initial_position(WindowInitialPosition p_initial_position);
WindowInitialPosition get_initial_position() const;
@ -372,7 +378,7 @@ public:
bool is_wrapping_controls() const;
void child_controls_changed();
Window *get_exclusive_child() const { return exclusive_child; };
Window *get_exclusive_child() const { return exclusive_child; }
Window *get_parent_visible_window() const;
Viewport *get_parent_viewport() const;
@ -395,6 +401,9 @@ public:
void grab_focus();
bool has_focus() const;
void start_drag();
void start_resize(DisplayServer::WindowResizeEdge p_edge);
Rect2i get_usable_parent_rect() const;
// Internationalization.
@ -473,7 +482,7 @@ public:
virtual Transform2D get_final_transform() const override;
virtual Transform2D get_screen_transform_internal(bool p_absolute_position = false) const override;
virtual Transform2D get_popup_base_transform() const override;
virtual bool is_directly_attached_to_screen() const override;
virtual Viewport *get_section_root_viewport() const override;
virtual bool is_attached_in_viewport() const override;
Rect2i get_parent_rect() const;