diff options
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/canvas_item.cpp | 25 | ||||
-rw-r--r-- | scene/main/canvas_layer.cpp | 12 | ||||
-rw-r--r-- | scene/main/http_request.cpp | 8 | ||||
-rw-r--r-- | scene/main/instance_placeholder.cpp | 10 | ||||
-rw-r--r-- | scene/main/node.cpp | 137 | ||||
-rw-r--r-- | scene/main/node.h | 6 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 34 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 248 | ||||
-rw-r--r-- | scene/main/viewport.h | 37 | ||||
-rw-r--r-- | scene/main/window.cpp | 6 |
10 files changed, 300 insertions, 223 deletions
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index 4a415415f1..2eacad68c3 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -43,9 +43,9 @@ #include "servers/rendering_server.h" Mutex CanvasItemMaterial::material_mutex; -SelfList<CanvasItemMaterial>::List *CanvasItemMaterial::dirty_materials = NULL; +SelfList<CanvasItemMaterial>::List *CanvasItemMaterial::dirty_materials = nullptr; Map<CanvasItemMaterial::MaterialKey, CanvasItemMaterial::ShaderData> CanvasItemMaterial::shader_map; -CanvasItemMaterial::ShaderNames *CanvasItemMaterial::shader_names = NULL; +CanvasItemMaterial::ShaderNames *CanvasItemMaterial::shader_names = nullptr; void CanvasItemMaterial::init_shaders() { @@ -62,7 +62,7 @@ void CanvasItemMaterial::finish_shaders() { memdelete(dirty_materials); memdelete(shader_names); - dirty_materials = NULL; + dirty_materials = nullptr; } void CanvasItemMaterial::_update_shader() { @@ -411,7 +411,7 @@ void CanvasItem::hide() { _change_notify("visible"); } -CanvasItem *CanvasItem::current_item_drawn = NULL; +CanvasItem *CanvasItem::current_item_drawn = nullptr; CanvasItem *CanvasItem::get_current_item_drawn() { return current_item_drawn; } @@ -435,9 +435,9 @@ void CanvasItem::_update_callback() { notification(NOTIFICATION_DRAW); emit_signal(SceneStringNames::get_singleton()->draw); if (get_script_instance()) { - get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_draw, NULL, 0); + get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_draw, nullptr, 0); } - current_item_drawn = NULL; + current_item_drawn = nullptr; drawing = false; } //todo updating = false @@ -504,7 +504,7 @@ void CanvasItem::_enter_canvas() { Node *n = this; - canvas_layer = NULL; + canvas_layer = nullptr; while (n) { @@ -554,7 +554,7 @@ void CanvasItem::_exit_canvas() { notification(NOTIFICATION_EXIT_CANVAS, true); //reverse the notification RenderingServer::get_singleton()->canvas_item_set_parent(canvas_item, RID()); - canvas_layer = NULL; + canvas_layer = nullptr; group = ""; } @@ -617,7 +617,7 @@ void CanvasItem::_notification(int p_what) { _exit_canvas(); if (C) { Object::cast_to<CanvasItem>(get_parent())->children_items.erase(C); - C = NULL; + C = nullptr; } if (window) { window->disconnect(SceneStringNames::get_singleton()->visibility_changed, callable_mp(this, &CanvasItem::_window_visibility_changed)); @@ -703,7 +703,7 @@ bool CanvasItem::is_set_as_toplevel() const { CanvasItem *CanvasItem::get_parent_item() const { if (toplevel) - return NULL; + return nullptr; return Object::cast_to<CanvasItem>(get_parent()); } @@ -1469,8 +1469,7 @@ CanvasItem::CanvasItem() : drawing = false; behind = false; block_transform_notify = false; - //viewport=NULL; - canvas_layer = NULL; + canvas_layer = nullptr; use_parent_material = false; global_invalid = true; notify_local_transform = false; @@ -1481,7 +1480,7 @@ CanvasItem::CanvasItem() : texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR; texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED; - C = NULL; + C = nullptr; } CanvasItem::~CanvasItem() { diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp index e6a665d035..c1caa943e3 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -35,7 +35,7 @@ void CanvasLayer::set_layer(int p_xform) { layer = p_xform; if (viewport.is_valid()) - RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); } int CanvasLayer::get_layer() const { @@ -151,7 +151,7 @@ void CanvasLayer::_notification(int p_what) { viewport = vp->get_viewport_rid(); RenderingServer::get_singleton()->viewport_attach_canvas(viewport, canvas); - RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); _update_follow_viewport(); @@ -167,7 +167,7 @@ void CanvasLayer::_notification(int p_what) { case NOTIFICATION_MOVED_IN_PARENT: { if (is_inside_tree()) - RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); } break; } @@ -214,7 +214,7 @@ void CanvasLayer::set_custom_viewport(Node *p_viewport) { viewport = vp->get_viewport_rid(); RenderingServer::get_singleton()->viewport_attach_canvas(viewport, canvas); - RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); } } @@ -320,13 +320,13 @@ void CanvasLayer::_bind_methods() { CanvasLayer::CanvasLayer() { - vp = NULL; + vp = nullptr; scale = Vector2(1, 1); rot = 0; locrotscale_dirty = false; layer = 1; canvas = RS::get_singleton()->canvas_create(); - custom_viewport = NULL; + custom_viewport = nullptr; sort_index = 0; follow_viewport = false; diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index fee2ada76d..dc0da015ac 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -162,12 +162,12 @@ void HTTPRequest::cancel_request() { thread_request_quit = true; Thread::wait_to_finish(thread); memdelete(thread); - thread = NULL; + thread = nullptr; } if (file) { memdelete(file); - file = NULL; + file = nullptr; } client->close(); body.resize(0); @@ -566,7 +566,7 @@ void HTTPRequest::_bind_methods() { HTTPRequest::HTTPRequest() { - thread = NULL; + thread = nullptr; port = 80; redirections = 0; @@ -583,7 +583,7 @@ HTTPRequest::HTTPRequest() { thread_done = false; downloaded = 0; body_size_limit = -1; - file = NULL; + file = nullptr; timer = memnew(Timer); timer->set_one_shot(true); diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp index fe238af1c4..062b221c84 100644 --- a/scene/main/instance_placeholder.cpp +++ b/scene/main/instance_placeholder.cpp @@ -77,11 +77,11 @@ String InstancePlaceholder::get_instance_path() const { Node *InstancePlaceholder::create_instance(bool p_replace, const Ref<PackedScene> &p_custom_scene) { - ERR_FAIL_COND_V(!is_inside_tree(), NULL); + ERR_FAIL_COND_V(!is_inside_tree(), nullptr); Node *base = get_parent(); if (!base) - return NULL; + return nullptr; Ref<PackedScene> ps; if (p_custom_scene.is_valid()) @@ -90,12 +90,12 @@ Node *InstancePlaceholder::create_instance(bool p_replace, const Ref<PackedScene ps = ResourceLoader::load(path, "PackedScene"); if (!ps.is_valid()) - return NULL; + return nullptr; Node *scene = ps->instance(); if (!scene) - return NULL; + return nullptr; scene->set_name(get_name()); - int pos = get_position_in_parent(); + int pos = get_index(); for (List<PropSet>::Element *E = stored_values.front(); E; E = E->next()) { scene->set(E->get().name, E->get().value); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index b882b9ead6..50f3bf834f 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -82,7 +82,7 @@ void Node::_notification(int p_notification) { if (data.parent) data.pause_owner = data.parent->data.pause_owner; else - data.pause_owner = NULL; + data.pause_owner = nullptr; } else { data.pause_owner = this; } @@ -112,17 +112,17 @@ void Node::_notification(int p_notification) { if (data.unhandled_key_input) remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id())); - data.pause_owner = NULL; + data.pause_owner = nullptr; if (data.path_cache) { memdelete(data.path_cache); - data.path_cache = NULL; + data.path_cache = nullptr; } } break; case NOTIFICATION_PATH_CHANGED: { if (data.path_cache) { memdelete(data.path_cache); - data.path_cache = NULL; + data.path_cache = nullptr; } } break; case NOTIFICATION_READY: { @@ -149,7 +149,7 @@ void Node::_notification(int p_notification) { set_physics_process(true); } - get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_ready, NULL, 0); + get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_ready, nullptr, 0); } } break; @@ -158,11 +158,11 @@ void Node::_notification(int p_notification) { } break; case NOTIFICATION_PREDELETE: { - set_owner(NULL); + set_owner(nullptr); while (data.owned.size()) { - data.owned.front()->get()->set_owner(NULL); + data.owned.front()->get()->set_owner(nullptr); } if (data.parent) { @@ -226,7 +226,7 @@ void Node::_propagate_enter_tree() { if (get_script_instance()) { - get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_enter_tree, NULL, 0); + get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_enter_tree, nullptr, 0); } emit_signal(SceneStringNames::get_singleton()->tree_entered); @@ -278,7 +278,7 @@ void Node::_propagate_exit_tree() { if (get_script_instance()) { - get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_tree, NULL, 0); + get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_tree, nullptr, 0); } emit_signal(SceneStringNames::get_singleton()->tree_exiting); @@ -290,17 +290,17 @@ void Node::_propagate_exit_tree() { for (Map<StringName, GroupData>::Element *E = data.grouped.front(); E; E = E->next()) { data.tree->remove_from_group(E->key(), this); - E->get().group = NULL; + E->get().group = nullptr; } - data.viewport = NULL; + data.viewport = nullptr; if (data.tree) data.tree->tree_changed(); data.inside_tree = false; data.ready_notified = false; - data.tree = NULL; + data.tree = nullptr; data.depth = -1; } @@ -423,7 +423,7 @@ void Node::set_pause_mode(PauseMode p_mode) { if ((data.pause_mode == PAUSE_MODE_INHERIT) == prev_inherits) return; ///nothing changed - Node *owner = NULL; + Node *owner = nullptr; if (data.pause_mode == PAUSE_MODE_INHERIT) { @@ -914,7 +914,7 @@ void Node::set_process_priority(int p_priority) { data.process_priority = p_priority; // Make sure we are in SceneTree. - if (data.tree == NULL) { + if (data.tree == nullptr) { return; } @@ -1268,7 +1268,7 @@ void Node::add_child_below_node(Node *p_node, Node *p_child, bool p_legible_uniq add_child(p_child, p_legible_unique_name); if (is_a_parent_of(p_node)) { - move_child(p_child, p_node->get_position_in_parent() + 1); + move_child(p_child, p_node->get_index() + 1); } else { WARN_PRINT("Cannot move under node " + p_node->get_name() + " as " + p_child->get_name() + " does not share a parent."); } @@ -1295,7 +1295,7 @@ void Node::_propagate_validate_owner() { if (!found) { data.owner->data.owned.erase(data.OW); - data.owner = NULL; + data.owner = nullptr; } } @@ -1336,7 +1336,7 @@ void Node::remove_child(Node *p_child) { //if (data.scene) { does not matter - p_child->_set_tree(NULL); + p_child->_set_tree(nullptr); //} remove_child_notify(p_child); @@ -1354,7 +1354,7 @@ void Node::remove_child(Node *p_child) { children[i]->notification(NOTIFICATION_MOVED_IN_PARENT); } - p_child->data.parent = NULL; + p_child->data.parent = nullptr; p_child->data.pos = -1; // validate owner @@ -1371,7 +1371,7 @@ int Node::get_child_count() const { } Node *Node::get_child(int p_index) const { - ERR_FAIL_INDEX_V(p_index, data.children.size(), NULL); + ERR_FAIL_INDEX_V(p_index, data.children.size(), nullptr); return data.children[p_index]; } @@ -1386,19 +1386,19 @@ Node *Node::_get_child_by_name(const StringName &p_name) const { return cd[i]; } - return NULL; + return nullptr; } Node *Node::get_node_or_null(const NodePath &p_path) const { if (p_path.is_empty()) { - return NULL; + return nullptr; } - ERR_FAIL_COND_V_MSG(!data.inside_tree && p_path.is_absolute(), NULL, "Can't use get_node() with absolute paths from outside the active scene tree."); + ERR_FAIL_COND_V_MSG(!data.inside_tree && p_path.is_absolute(), nullptr, "Can't use get_node() with absolute paths from outside the active scene tree."); - Node *current = NULL; - Node *root = NULL; + Node *current = nullptr; + Node *root = nullptr; if (!p_path.is_absolute()) { current = const_cast<Node *>(this); //start from this @@ -1412,7 +1412,7 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { for (int i = 0; i < p_path.get_name_count(); i++) { StringName name = p_path.get_name(i); - Node *next = NULL; + Node *next = nullptr; if (name == SceneStringNames::get_singleton()->dot) { // . @@ -1420,18 +1420,18 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { } else if (name == SceneStringNames::get_singleton()->doubledot) { // .. - if (current == NULL || !current->data.parent) - return NULL; + if (current == nullptr || !current->data.parent) + return nullptr; next = current->data.parent; - } else if (current == NULL) { + } else if (current == nullptr) { if (name == root->get_name()) next = root; } else { - next = NULL; + next = nullptr; for (int j = 0; j < current->data.children.size(); j++) { @@ -1443,8 +1443,8 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { break; } } - if (next == NULL) { - return NULL; + if (next == nullptr) { + return nullptr; }; } current = next; @@ -1456,13 +1456,13 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { Node *Node::get_node(const NodePath &p_path) const { Node *node = get_node_or_null(p_path); - ERR_FAIL_COND_V_MSG(!node, NULL, "Node not found: " + p_path + "."); + ERR_FAIL_COND_V_MSG(!node, nullptr, "Node not found: " + p_path + "."); return node; } bool Node::has_node(const NodePath &p_path) const { - return get_node_or_null(p_path) != NULL; + return get_node_or_null(p_path) != nullptr; } Node *Node::find_node(const String &p_mask, bool p_recursive, bool p_owned) const { @@ -1482,7 +1482,7 @@ Node *Node::find_node(const String &p_mask, bool p_recursive, bool p_owned) cons if (ret) return ret; } - return NULL; + return nullptr; } Node *Node::get_parent() const { @@ -1500,7 +1500,7 @@ Node *Node::find_parent(const String &p_mask) const { p = p->data.parent; } - return NULL; + return nullptr; } bool Node::is_a_parent_of(const Node *p_node) const { @@ -1607,8 +1607,8 @@ void Node::set_owner(Node *p_owner) { if (data.owner) { data.owner->data.owned.erase(data.OW); - data.OW = NULL; - data.owner = NULL; + data.OW = nullptr; + data.owner = nullptr; } ERR_FAIL_COND(p_owner == this); @@ -1663,7 +1663,7 @@ Node *Node::find_common_parent_with(const Node *p_node) const { } if (!common_parent) - return NULL; + return nullptr; return const_cast<Node *>(common_parent); } @@ -1762,7 +1762,7 @@ void Node::add_to_group(const StringName &p_identifier, bool p_persistent) { if (data.tree) { gd.group = data.tree->add_to_group(p_identifier, this); } else { - gd.group = NULL; + gd.group = nullptr; } gd.persistent = p_persistent; @@ -1918,6 +1918,7 @@ int Node::get_index() const { return data.pos; } + void Node::remove_and_skip() { ERR_FAIL_COND(!data.parent); @@ -1935,7 +1936,7 @@ void Node::remove_and_skip() { continue; remove_child(c_node); - c_node->_propagate_replace_owner(this, NULL); + c_node->_propagate_replace_owner(this, nullptr); children.push_back(c_node); clear = false; break; @@ -1949,7 +1950,7 @@ void Node::remove_and_skip() { Node *c_node = children.front()->get(); data.parent->add_child(c_node); - c_node->_propagate_replace_owner(NULL, new_owner); + c_node->_propagate_replace_owner(nullptr, new_owner); children.pop_front(); } @@ -2042,14 +2043,9 @@ bool Node::get_scene_instance_load_placeholder() const { return data.use_placeholder; } -int Node::get_position_in_parent() const { - - return data.pos; -} - Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const { - Node *node = NULL; + Node *node = nullptr; bool instanced = false; @@ -2063,25 +2059,25 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const } else if ((p_flags & DUPLICATE_USE_INSTANCING) && get_filename() != String()) { Ref<PackedScene> res = ResourceLoader::load(get_filename()); - ERR_FAIL_COND_V(res.is_null(), NULL); + ERR_FAIL_COND_V(res.is_null(), nullptr); PackedScene::GenEditState ges = PackedScene::GEN_EDIT_STATE_DISABLED; #ifdef TOOLS_ENABLED if (p_flags & DUPLICATE_FROM_EDITOR) ges = PackedScene::GEN_EDIT_STATE_INSTANCE; #endif node = res->instance(ges); - ERR_FAIL_COND_V(!node, NULL); + ERR_FAIL_COND_V(!node, nullptr); instanced = true; } else { Object *obj = ClassDB::instance(get_class()); - ERR_FAIL_COND_V(!obj, NULL); + ERR_FAIL_COND_V(!obj, nullptr); node = Object::cast_to<Node>(obj); if (!node) memdelete(obj); - ERR_FAIL_COND_V(!node, NULL); + ERR_FAIL_COND_V(!node, nullptr); } if (get_filename() != "") { //an instance @@ -2189,7 +2185,7 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const if (!dup) { memdelete(node); - return NULL; + return nullptr; } node->add_child(dup); @@ -2204,18 +2200,18 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const if (!parent) { memdelete(node); - return NULL; + return nullptr; } Node *dup = E->get()->_duplicate(p_flags, r_duplimap); if (!dup) { memdelete(node); - return NULL; + return nullptr; } parent->add_child(dup); - int pos = E->get()->get_position_in_parent(); + int pos = E->get()->get_index(); if (pos < parent->get_child_count() - 1) { @@ -2256,7 +2252,7 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p if (get_owner() != get_parent()->get_owner()) return; - Node *node = NULL; + Node *node = nullptr; if (get_filename() != "") { @@ -2369,15 +2365,15 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const { Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const { - ERR_FAIL_COND_V(get_filename() != "", NULL); + ERR_FAIL_COND_V(get_filename() != "", nullptr); Object *obj = ClassDB::instance(get_class()); - ERR_FAIL_COND_V_MSG(!obj, NULL, "Node: Could not duplicate: " + String(get_class()) + "."); + ERR_FAIL_COND_V_MSG(!obj, nullptr, "Node: Could not duplicate: " + String(get_class()) + "."); Node *node = Object::cast_to<Node>(obj); if (!node) { memdelete(obj); - ERR_FAIL_V_MSG(NULL, "Node: Could not duplicate: " + String(get_class()) + "."); + ERR_FAIL_V_MSG(nullptr, "Node: Could not duplicate: " + String(get_class()) + "."); } node->set_name(get_name()); @@ -2591,7 +2587,7 @@ Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<Str r_res = RES(); r_leftover_subpath = Vector<StringName>(); if (!node) - return NULL; + return nullptr; if (p_path.get_subname_count()) { @@ -2601,7 +2597,7 @@ Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<Str Variant new_res_v = j == 0 ? node->get(p_path.get_subname(j)) : r_res->get(p_path.get_subname(j)); if (new_res_v.get_type() == Variant::NIL) { // Found nothing on that path - return NULL; + return nullptr; } RES new_res = new_res_v; @@ -2623,8 +2619,8 @@ Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<Str void Node::_set_tree(SceneTree *p_tree) { - SceneTree *tree_changed_a = NULL; - SceneTree *tree_changed_b = NULL; + SceneTree *tree_changed_a = nullptr; + SceneTree *tree_changed_b = nullptr; //ERR_FAIL_COND(p_scene && data.parent && !data.parent->data.scene); //nobug if both are null @@ -2860,7 +2856,6 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("get_pause_mode"), &Node::get_pause_mode); ClassDB::bind_method(D_METHOD("can_process"), &Node::can_process); ClassDB::bind_method(D_METHOD("print_stray_nodes"), &Node::_print_stray_nodes); - ClassDB::bind_method(D_METHOD("get_position_in_parent"), &Node::get_position_in_parent); ClassDB::bind_method(D_METHOD("set_display_folded", "fold"), &Node::set_display_folded); ClassDB::bind_method(D_METHOD("is_displayed_folded"), &Node::is_displayed_folded); @@ -3012,8 +3007,8 @@ Node::Node() { data.pos = -1; data.depth = -1; data.blocked = 0; - data.parent = NULL; - data.tree = NULL; + data.parent = nullptr; + data.tree = nullptr; data.physics_process = false; data.idle_process = false; data.process_priority = 0; @@ -3022,18 +3017,18 @@ Node::Node() { data.inside_tree = false; data.ready_notified = false; - data.owner = NULL; - data.OW = NULL; + data.owner = nullptr; + data.OW = nullptr; data.input = false; data.unhandled_input = false; data.unhandled_key_input = false; data.pause_mode = PAUSE_MODE_INHERIT; - data.pause_owner = NULL; + data.pause_owner = nullptr; data.network_master = 1; //server by default - data.path_cache = NULL; + data.path_cache = nullptr; data.parent_owned = false; data.in_constructor = true; - data.viewport = NULL; + data.viewport = nullptr; data.use_placeholder = false; data.display_folded = false; data.ready_first = true; diff --git a/scene/main/node.h b/scene/main/node.h index cf25a92be6..5de07d506e 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -180,7 +180,7 @@ private: void _duplicate_signals(const Node *p_original, Node *p_copy) const; void _duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p_reown_map) const; - Node *_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap = NULL) const; + Node *_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap = nullptr) const; Array _get_children() const; Array _get_groups() const; @@ -286,7 +286,7 @@ public: Node *find_parent(const String &p_mask) const; _FORCE_INLINE_ SceneTree *get_tree() const { - ERR_FAIL_COND_V(!data.tree, NULL); + ERR_FAIL_COND_V(!data.tree, nullptr); return data.tree; } @@ -369,8 +369,6 @@ public: void set_process_unhandled_key_input(bool p_enable); bool is_processing_unhandled_key_input() const; - int get_position_in_parent() const; - Node *duplicate(int p_flags = DUPLICATE_GROUPS | DUPLICATE_SIGNALS | DUPLICATE_SCRIPTS) const; Node *duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const; #ifdef TOOLS_ENABLED diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 15c0a7666e..0418b20e9c 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -112,7 +112,7 @@ void SceneTree::node_added(Node *p_node) { void SceneTree::node_removed(Node *p_node) { if (current_scene == p_node) { - current_scene = NULL; + current_scene = nullptr; } emit_signal(node_removed_name, p_node); if (call_lock > 0) @@ -539,10 +539,10 @@ void SceneTree::finish() { MainLoop::finish(); if (root) { - root->_set_tree(NULL); + root->_set_tree(nullptr); root->_propagate_after_exit_tree(); memdelete(root); //delete root - root = NULL; + root = nullptr; } // cleanup timers @@ -1037,7 +1037,7 @@ Node *SceneTree::get_edited_scene_root() const { #ifdef TOOLS_ENABLED return edited_scene_root; #else - return NULL; + return nullptr; #endif } @@ -1056,7 +1056,7 @@ void SceneTree::_change_scene(Node *p_to) { if (current_scene) { memdelete(current_scene); - current_scene = NULL; + current_scene = nullptr; } // If we're quitting, abort. @@ -1082,7 +1082,7 @@ Error SceneTree::change_scene(const String &p_path) { } Error SceneTree::change_scene_to(const Ref<PackedScene> &p_scene) { - Node *new_scene = NULL; + Node *new_scene = nullptr; if (p_scene.is_valid()) { new_scene = p_scene->instance(); ERR_FAIL_COND_V(!new_scene, ERR_CANT_CREATE); @@ -1321,7 +1321,7 @@ void SceneTree::_bind_methods() { BIND_ENUM_CONSTANT(GROUP_CALL_UNIQUE); } -SceneTree *SceneTree::singleton = NULL; +SceneTree *SceneTree::singleton = nullptr; SceneTree::IdleCallback SceneTree::idle_callbacks[SceneTree::MAX_IDLE_CALLBACKS]; int SceneTree::idle_callback_count = 0; @@ -1372,7 +1372,7 @@ void SceneTree::get_argument_options(const StringName &p_function, int p_idx, Li SceneTree::SceneTree() { - if (singleton == NULL) singleton = this; + if (singleton == nullptr) singleton = this; _quit = false; accept_quit = true; quit_on_go_back = true; @@ -1392,7 +1392,7 @@ SceneTree::SceneTree() { physics_process_time = 1; idle_process_time = 1; - root = NULL; + root = nullptr; pause = false; current_frame = 0; current_event = 0; @@ -1419,12 +1419,16 @@ SceneTree::SceneTree() { //root->set_world_2d( Ref<World2D>( memnew( World2D ))); root->set_as_audio_listener(true); root->set_as_audio_listener_2d(true); - current_scene = NULL; + current_scene = nullptr; - int msaa_mode = GLOBAL_DEF("rendering/quality/filters/msaa", 0); - ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/filters/msaa", PropertyInfo(Variant::INT, "rendering/quality/filters/msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x")); + int msaa_mode = GLOBAL_DEF("rendering/quality/screen_filters/msaa", 0); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/screen_filters/msaa", PropertyInfo(Variant::INT, "rendering/quality/screen_filters/msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x")); root->set_msaa(Viewport::MSAA(msaa_mode)); + int ssaa_mode = GLOBAL_DEF("rendering/quality/screen_filters/screen_space_aa", 0); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/screen_filters/screen_space_aa", PropertyInfo(Variant::INT, "rendering/quality/screen_filters/screen_space_aa", PROPERTY_HINT_ENUM, "Disabled,FXAA")); + root->set_screen_space_aa(Viewport::ScreenSpaceAA(ssaa_mode)); + { //load default fallback environment //get possible extensions List<String> exts; @@ -1463,16 +1467,16 @@ SceneTree::SceneTree() { root->connect("focus_entered", callable_mp(this, &SceneTree::_main_window_focus_in)); #ifdef TOOLS_ENABLED - edited_scene_root = NULL; + edited_scene_root = nullptr; #endif } SceneTree::~SceneTree() { if (root) { - root->_set_tree(NULL); + root->_set_tree(nullptr); root->_propagate_after_exit_tree(); memdelete(root); } - if (singleton == this) singleton = NULL; + if (singleton == this) singleton = nullptr; } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index b95e81a702..72b1a877c1 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -61,7 +61,7 @@ void ViewportTexture::setup_local_to_scene() { vp->viewport_textures.erase(this); } - vp = NULL; + vp = nullptr; Node *local_scene = get_local_scene(); if (!local_scene) { @@ -148,7 +148,7 @@ void ViewportTexture::_bind_methods() { ViewportTexture::ViewportTexture() { - vp = NULL; + vp = nullptr; set_local_to_scene(true); } @@ -190,17 +190,17 @@ Viewport::GUI::GUI() { embedding_subwindows = false; dragging = false; - mouse_focus = NULL; + mouse_focus = nullptr; forced_mouse_focus = false; - mouse_click_grabber = NULL; + mouse_click_grabber = nullptr; mouse_focus_mask = 0; - key_focus = NULL; - mouse_over = NULL; - drag_mouse_over = NULL; + key_focus = nullptr; + mouse_over = nullptr; + drag_mouse_over = nullptr; - tooltip = NULL; - tooltip_popup = NULL; - tooltip_label = NULL; + tooltip = nullptr; + tooltip_popup = nullptr; + tooltip_label = nullptr; } ///////////////////////////////////// @@ -455,7 +455,7 @@ void Viewport::_notification(int p_what) { parent = get_parent()->get_viewport(); RenderingServer::get_singleton()->viewport_set_parent_viewport(viewport, parent->get_viewport_rid()); } else { - parent = NULL; + parent = nullptr; } current_canvas = find_world_2d()->get_canvas(); @@ -489,10 +489,10 @@ void Viewport::_notification(int p_what) { case NOTIFICATION_READY: { #ifndef _3D_DISABLED if (listeners.size() && !listener) { - Listener3D *first = NULL; + Listener3D *first = nullptr; for (Set<Listener3D *>::Element *E = listeners.front(); E; E = E->next()) { - if (first == NULL || first->is_greater_than(E->get())) { + if (first == nullptr || first->is_greater_than(E->get())) { first = E->get(); } } @@ -503,10 +503,10 @@ void Viewport::_notification(int p_what) { if (cameras.size() && !camera) { //there are cameras but no current camera, pick first in tree and make it current - Camera3D *first = NULL; + Camera3D *first = nullptr; for (Set<Camera3D *>::Element *E = cameras.front(); E; E = E->next()) { - if (first == NULL || first->is_greater_than(E->get())) { + if (first == nullptr || first->is_greater_than(E->get())) { first = E->get(); } } @@ -586,7 +586,7 @@ void Viewport::_notification(int p_what) { #ifndef _3D_DISABLED Vector2 last_pos(1e20, 1e20); - CollisionObject3D *last_object = NULL; + CollisionObject3D *last_object = nullptr; ObjectID last_id; #endif PhysicsDirectSpaceState3D::RayResult result; @@ -879,13 +879,14 @@ void Viewport::update_canvas_items() { _update_canvas_items(this); } -void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_override, const Rect2i &p_to_screen_rect, const Transform2D &p_stretch_transform, bool p_allocated) { +void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, const Transform2D &p_stretch_transform, bool p_allocated) { - if (size == p_size && size_allocated == p_allocated && stretch_transform == p_stretch_transform && p_size_override == size_override && to_screen_rect != p_to_screen_rect) + if (size == p_size && size_allocated == p_allocated && stretch_transform == p_stretch_transform && p_size_2d_override == size_2d_override && to_screen_rect != p_to_screen_rect) return; + size = p_size; size_allocated = p_allocated; - size_override = p_size_override; + size_2d_override = p_size_2d_override; stretch_transform = p_stretch_transform; to_screen_rect = p_to_screen_rect; @@ -904,6 +905,9 @@ void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_override, co Size2i Viewport::_get_size() const { return size; } +Size2i Viewport::_get_size_2d_override() const { + return size_2d_override; +} bool Viewport::_is_size_allocated() const { return size_allocated; } @@ -918,8 +922,8 @@ Rect2 Viewport::get_visible_rect() const { r = Rect2(Point2(), size); } - if (size_override != Size2i()) { - r.size = size_override; + if (size_2d_override != Size2i()) { + r.size = size_2d_override; } return r; @@ -1059,7 +1063,7 @@ void Viewport::_listener_remove(Listener3D *p_listener) { listeners.erase(p_listener); if (listener == p_listener) { - listener = NULL; + listener = nullptr; } } @@ -1073,14 +1077,14 @@ void Viewport::_listener_make_next_current(Listener3D *p_exclude) { continue; if (!E->get()->is_inside_tree()) continue; - if (listener != NULL) + if (listener != nullptr) return; E->get()->make_current(); } } else { // Attempt to reset listener to the camera position - if (camera != NULL) { + if (camera != nullptr) { _update_listener(); _camera_transform_changed_notify(); } @@ -1134,7 +1138,7 @@ void Viewport::_camera_remove(Camera3D *p_camera) { cameras.erase(p_camera); if (camera == p_camera) { camera->notification(Camera3D::NOTIFICATION_LOST_CURRENT); - camera = NULL; + camera = nullptr; } } @@ -1147,7 +1151,7 @@ void Viewport::_camera_make_next_current(Camera3D *p_exclude) { continue; if (!E->get()->is_inside_tree()) continue; - if (camera != NULL) + if (camera != nullptr) return; E->get()->make_current(); @@ -1528,12 +1532,12 @@ void Viewport::_gui_sort_roots() { void Viewport::_gui_cancel_tooltip() { - gui.tooltip = NULL; + gui.tooltip = nullptr; gui.tooltip_timer = -1; if (gui.tooltip_popup) { gui.tooltip_popup->queue_delete(); - gui.tooltip_popup = NULL; - gui.tooltip_label = NULL; + gui.tooltip_popup = nullptr; + gui.tooltip_label = nullptr; } } @@ -1571,7 +1575,7 @@ void Viewport::_gui_show_tooltip() { return; } - Control *which = NULL; + Control *which = nullptr; String tooltip = _gui_get_tooltip(gui.tooltip, gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos), &which); tooltip = tooltip.strip_edges(); if (tooltip.length() == 0) @@ -1579,8 +1583,8 @@ void Viewport::_gui_show_tooltip() { if (gui.tooltip_popup) { memdelete(gui.tooltip_popup); - gui.tooltip_popup = NULL; - gui.tooltip_label = NULL; + gui.tooltip_popup = nullptr; + gui.tooltip_label = nullptr; } if (!which) { @@ -1651,7 +1655,7 @@ void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu Ref<InputEventPanGesture> pn = p_input; cant_stop_me_now = pn.is_valid() || cant_stop_me_now; - bool ismouse = ev.is_valid() || Object::cast_to<InputEventMouseMotion>(*p_input) != NULL; + bool ismouse = ev.is_valid() || Object::cast_to<InputEventMouseMotion>(*p_input) != nullptr; CanvasItem *ci = p_control; while (ci) { @@ -1741,23 +1745,23 @@ Control *Viewport::_gui_find_control(const Point2 &p_global) { return ret; } - return NULL; + return nullptr; } Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform) { if (Object::cast_to<Viewport>(p_node)) - return NULL; + return nullptr; if (!p_node->is_visible()) { //return _find_next_visible_control_at_pos(p_node,p_global,r_inv_xform); - return NULL; //canvas item hidden, discard + return nullptr; //canvas item hidden, discard } Transform2D matrix = p_xform * p_node->get_transform(); // matrix.basis_determinant() == 0.0f implies that node does not exist on scene if (matrix.basis_determinant() == 0.0f) - return NULL; + return nullptr; Control *c = Object::cast_to<Control>(p_node); @@ -1776,7 +1780,7 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_ } if (!c) - return NULL; + return nullptr; matrix.affine_invert(); @@ -1785,7 +1789,7 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_ r_inv_xform = matrix; return c; } else - return NULL; + return nullptr; } bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_check) { @@ -1938,7 +1942,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (gui.drag_preview) { memdelete(gui.drag_preview); - gui.drag_preview = NULL; + gui.drag_preview = nullptr; } _propagate_viewport_notification(this, NOTIFICATION_DRAG_END); //change mouse accordingly @@ -1957,7 +1961,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (gui.drag_preview && mb->get_button_index() == BUTTON_LEFT) { memdelete(gui.drag_preview); - gui.drag_preview = NULL; + gui.drag_preview = nullptr; } gui.drag_data = Variant(); @@ -1985,7 +1989,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { //disable mouse focus if needed before calling input, this makes popups on mouse press event work better, as the release will never be received otherwise if (gui.mouse_focus_mask == 0) { - gui.mouse_focus = NULL; + gui.mouse_focus = nullptr; gui.forced_mouse_focus = false; } @@ -2011,7 +2015,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { gui.last_mouse_pos = mpos; - Control *over = NULL; + Control *over = nullptr; // D&D if (!gui.drag_attempted && gui.mouse_focus && mm->get_button_mask() & BUTTON_MASK_LEFT) { @@ -2031,15 +2035,15 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos) - gui.drag_accum); if (gui.drag_data.get_type() != Variant::NIL) { - gui.mouse_focus = NULL; + gui.mouse_focus = nullptr; gui.forced_mouse_focus = false; gui.mouse_focus_mask = 0; break; } else { - if (gui.drag_preview != NULL) { + if (gui.drag_preview != nullptr) { ERR_PRINT("Don't set a drag preview and return null data. Preview was deleted and drag request ignored."); memdelete(gui.drag_preview); - gui.drag_preview = NULL; + gui.drag_preview = nullptr; } gui.dragging = false; } @@ -2395,7 +2399,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { } } - Control *from = gui.key_focus ? gui.key_focus : NULL; //hmm + Control *from = gui.key_focus ? gui.key_focus : nullptr; //hmm //keyboard focus //if (from && p_event->is_pressed() && !p_event->get_alt() && !p_event->get_metakey() && !p_event->key->get_command()) { @@ -2405,7 +2409,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { bool mods = k.is_valid() && (k->get_control() || k->get_alt() || k->get_shift() || k->get_metakey()); if (from && p_event->is_pressed()) { - Control *next = NULL; + Control *next = nullptr; InputFilter *input = InputFilter::get_singleton(); @@ -2463,7 +2467,7 @@ void Viewport::_gui_force_drag(Control *p_base, const Variant &p_data, Control * gui.dragging = true; gui.drag_data = p_data; - gui.mouse_focus = NULL; + gui.mouse_focus = nullptr; if (p_control) { _gui_set_drag_preview(p_base, p_control); @@ -2475,7 +2479,7 @@ void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) { ERR_FAIL_NULL(p_control); ERR_FAIL_COND(!Object::cast_to<Control>((Object *)p_control)); ERR_FAIL_COND(p_control->is_inside_tree()); - ERR_FAIL_COND(p_control->get_parent() != NULL); + ERR_FAIL_COND(p_control->get_parent() != nullptr); if (gui.drag_preview) { memdelete(gui.drag_preview); @@ -2506,22 +2510,12 @@ void Viewport::_gui_hid_control(Control *p_control) { _drop_mouse_focus(); } - /* ??? - if (data.window==p_control) { - window->drag_data=Variant(); - if (window->drag_preview) { - memdelete( window->drag_preview); - window->drag_preview=NULL; - } - } - */ - if (gui.key_focus == p_control) _gui_remove_focus(); if (gui.mouse_over == p_control) - gui.mouse_over = NULL; + gui.mouse_over = nullptr; if (gui.drag_mouse_over == p_control) - gui.drag_mouse_over = NULL; + gui.drag_mouse_over = nullptr; if (gui.tooltip == p_control) _gui_cancel_tooltip(); } @@ -2529,28 +2523,28 @@ void Viewport::_gui_hid_control(Control *p_control) { void Viewport::_gui_remove_control(Control *p_control) { if (gui.mouse_focus == p_control) { - gui.mouse_focus = NULL; + gui.mouse_focus = nullptr; gui.forced_mouse_focus = false; gui.mouse_focus_mask = 0; } if (gui.last_mouse_focus == p_control) { - gui.last_mouse_focus = NULL; + gui.last_mouse_focus = nullptr; } if (gui.key_focus == p_control) - gui.key_focus = NULL; + gui.key_focus = nullptr; if (gui.mouse_over == p_control) - gui.mouse_over = NULL; + gui.mouse_over = nullptr; if (gui.drag_mouse_over == p_control) - gui.drag_mouse_over = NULL; + gui.drag_mouse_over = nullptr; if (gui.tooltip == p_control) - gui.tooltip = NULL; + gui.tooltip = nullptr; } void Viewport::_gui_remove_focus() { if (gui.key_focus) { Node *f = gui.key_focus; - gui.key_focus = NULL; + gui.key_focus = nullptr; f->notification(Control::NOTIFICATION_FOCUS_EXIT, true); } } @@ -2583,7 +2577,7 @@ void Viewport::_drop_mouse_focus() { Control *c = gui.mouse_focus; int mask = gui.mouse_focus_mask; - gui.mouse_focus = NULL; + gui.mouse_focus = nullptr; gui.forced_mouse_focus = false; gui.mouse_focus_mask = 0; @@ -2645,7 +2639,7 @@ void Viewport::_post_gui_grab_click_focus() { // Redundant grab requests were made return; } - gui.mouse_click_grabber = NULL; + gui.mouse_click_grabber = nullptr; if (gui.mouse_focus) { @@ -3063,7 +3057,7 @@ void Viewport::unhandled_input(const Ref<InputEvent> &p_event, bool p_local_coor get_tree()->_call_input_pause(unhandled_input_group, "_unhandled_input", ev, this); //call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_input","_unhandled_input",ev); - if (!is_input_handled() && Object::cast_to<InputEventKey>(*ev) != NULL) { + if (!is_input_handled() && Object::cast_to<InputEventKey>(*ev) != nullptr) { get_tree()->_call_input_pause(unhandled_key_input_group, "_unhandled_key_input", ev, this); //call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_key_input","_unhandled_key_input",ev); } @@ -3179,7 +3173,7 @@ int Viewport::gui_get_canvas_sort_index() { void Viewport::set_msaa(MSAA p_msaa) { - ERR_FAIL_INDEX(p_msaa, 7); + ERR_FAIL_INDEX(p_msaa, MSAA_MAX); if (msaa == p_msaa) return; msaa = p_msaa; @@ -3191,6 +3185,19 @@ Viewport::MSAA Viewport::get_msaa() const { return msaa; } +void Viewport::set_screen_space_aa(ScreenSpaceAA p_screen_space_aa) { + + ERR_FAIL_INDEX(p_screen_space_aa, SCREEN_SPACE_AA_MAX); + if (screen_space_aa == p_screen_space_aa) + return; + screen_space_aa = p_screen_space_aa; + RS::get_singleton()->viewport_set_screen_space_aa(viewport, RS::ViewportScreenSpaceAA(p_screen_space_aa)); +} + +Viewport::ScreenSpaceAA Viewport::get_screen_space_aa() const { + + return screen_space_aa; +} void Viewport::set_debug_draw(DebugDraw p_debug_draw) { debug_draw = p_debug_draw; @@ -3377,6 +3384,9 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_msaa", "msaa"), &Viewport::set_msaa); ClassDB::bind_method(D_METHOD("get_msaa"), &Viewport::get_msaa); + ClassDB::bind_method(D_METHOD("set_screen_space_aa", "screen_space_aa"), &Viewport::set_screen_space_aa); + ClassDB::bind_method(D_METHOD("get_screen_space_aa"), &Viewport::get_screen_space_aa); + ClassDB::bind_method(D_METHOD("set_debug_draw", "debug_draw"), &Viewport::set_debug_draw); ClassDB::bind_method(D_METHOD("get_debug_draw"), &Viewport::get_debug_draw); @@ -3450,6 +3460,7 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "handle_input_locally"), "set_handle_input_locally", "is_handling_input_locally"); ADD_GROUP("Rendering", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x"), "set_msaa", "get_msaa"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_space_aa", PROPERTY_HINT_ENUM, "Disabled,FXAA"), "set_screen_space_aa", "get_screen_space_aa"); ADD_PROPERTY(PropertyInfo(Variant::INT, "debug_draw", PROPERTY_HINT_ENUM, "Disabled,Unshaded,Overdraw,Wireframe"), "set_debug_draw", "get_debug_draw"); ADD_GROUP("Canvas Items", "canvas_item_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "canvas_item_default_texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,MipmapLinear,MipmapNearest"), "set_default_canvas_item_texture_filter", "get_default_canvas_item_texture_filter"); @@ -3504,6 +3515,9 @@ void Viewport::_bind_methods() { BIND_ENUM_CONSTANT(DEBUG_DRAW_DIRECTIONAL_SHADOW_ATLAS); BIND_ENUM_CONSTANT(DEBUG_DRAW_SCENE_LUMINANCE); BIND_ENUM_CONSTANT(DEBUG_DRAW_SSAO); + BIND_ENUM_CONSTANT(DEBUG_DRAW_ROUGHNESS_LIMITER); + BIND_ENUM_CONSTANT(DEBUG_DRAW_PSSM_SPLITS); + BIND_ENUM_CONSTANT(DEBUG_DRAW_DECAL_ATLAS); BIND_ENUM_CONSTANT(MSAA_DISABLED); BIND_ENUM_CONSTANT(MSAA_2X); @@ -3539,11 +3553,11 @@ Viewport::Viewport() { //internal_listener_2d = SpatialSound2DServer::get_singleton()->listener_create(); audio_listener_2d = false; transparent_bg = false; - parent = NULL; - listener = NULL; - camera = NULL; + parent = nullptr; + listener = nullptr; + camera = nullptr; override_canvas_transform = false; - canvas_layers.insert(NULL); // This eases picking code (interpreted as the canvas of the Viewport) + canvas_layers.insert(nullptr); // This eases picking code (interpreted as the canvas of the Viewport) gen_mipmaps = false; @@ -3577,20 +3591,20 @@ Viewport::Viewport() { gui.tooltip_delay = GLOBAL_DEF("gui/timers/tooltip_delay_sec", 0.5); ProjectSettings::get_singleton()->set_custom_property_info("gui/timers/tooltip_delay_sec", PropertyInfo(Variant::FLOAT, "gui/timers/tooltip_delay_sec", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater")); // No negative numbers - gui.tooltip = NULL; - gui.tooltip_label = NULL; - gui.drag_preview = NULL; + gui.tooltip = nullptr; + gui.tooltip_label = nullptr; + gui.drag_preview = nullptr; gui.drag_attempted = false; gui.canvas_sort_index = 0; gui.roots_order_dirty = false; - gui.mouse_focus = NULL; + gui.mouse_focus = nullptr; gui.forced_mouse_focus = false; - gui.last_mouse_focus = NULL; + gui.last_mouse_focus = nullptr; gui.subwindow_focused = nullptr; gui.subwindow_drag = SUB_WINDOW_DRAG_DISABLED; msaa = MSAA_DISABLED; - + screen_space_aa = SCREEN_SPACE_AA_DISABLED; debug_draw = DEBUG_DRAW_DISABLED; snap_controls_to_pixels = true; @@ -3612,30 +3626,53 @@ Viewport::~Viewport() { //erase itself from viewport textures for (Set<ViewportTexture *>::Element *E = viewport_textures.front(); E; E = E->next()) { - E->get()->vp = NULL; + E->get()->vp = nullptr; } RenderingServer::get_singleton()->free(viewport); } ///////////////////////////////// -void SubViewport::set_use_arvr(bool p_use_arvr) { - arvr = p_use_arvr; +void SubViewport::set_use_xr(bool p_use_xr) { + xr = p_use_xr; - RS::get_singleton()->viewport_set_use_arvr(get_viewport_rid(), arvr); + RS::get_singleton()->viewport_set_use_xr(get_viewport_rid(), xr); } -bool SubViewport::is_using_arvr() { - return arvr; +bool SubViewport::is_using_xr() { + return xr; } void SubViewport::set_size(const Size2i &p_size) { - _set_size(p_size, Size2i(), Rect2i(), Transform2D(), true); + _set_size(p_size, _get_size_2d_override(), Rect2i(), _stretch_transform(), true); } Size2i SubViewport::get_size() const { return _get_size(); } +void SubViewport::set_size_2d_override(const Size2i &p_size) { + + _set_size(_get_size(), p_size, Rect2i(), _stretch_transform(), true); +} +Size2i SubViewport::get_size_2d_override() const { + + return _get_size_2d_override(); +} + +void SubViewport::set_size_2d_override_stretch(bool p_enable) { + + if (p_enable == size_2d_override_stretch) { + return; + } + + size_2d_override_stretch = p_enable; + _set_size(_get_size(), _get_size_2d_override(), Rect2i(), _stretch_transform(), true); +} +bool SubViewport::is_size_2d_override_stretch_enabled() const { + + return size_2d_override_stretch; +} + void SubViewport::set_update_mode(UpdateMode p_mode) { update_mode = p_mode; @@ -3651,7 +3688,6 @@ void SubViewport::set_clear_mode(ClearMode p_mode) { clear_mode = p_mode; RS::get_singleton()->viewport_set_clear_mode(get_viewport_rid(), RS::ViewportClearMode(p_mode)); } - SubViewport::ClearMode SubViewport::get_clear_mode() const { return clear_mode; @@ -3661,6 +3697,18 @@ DisplayServer::WindowID SubViewport::get_window_id() const { return DisplayServer::INVALID_WINDOW_ID; } +Transform2D SubViewport::_stretch_transform() { + + Transform2D transform = Transform2D(); + Size2i view_size_2d_override = _get_size_2d_override(); + if (size_2d_override_stretch && view_size_2d_override.width > 0 && view_size_2d_override.height > 0) { + Size2 scale = _get_size() / view_size_2d_override; + transform.scale(scale); + } + + return transform; +} + void SubViewport::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { @@ -3672,19 +3720,28 @@ void SubViewport::_notification(int p_what) { } void SubViewport::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_use_arvr", "use"), &SubViewport::set_use_arvr); - ClassDB::bind_method(D_METHOD("is_using_arvr"), &SubViewport::is_using_arvr); + ClassDB::bind_method(D_METHOD("set_use_xr", "use"), &SubViewport::set_use_xr); + ClassDB::bind_method(D_METHOD("is_using_xr"), &SubViewport::is_using_xr); ClassDB::bind_method(D_METHOD("set_size", "size"), &SubViewport::set_size); ClassDB::bind_method(D_METHOD("get_size"), &SubViewport::get_size); + ClassDB::bind_method(D_METHOD("set_size_2d_override", "size"), &SubViewport::set_size_2d_override); + ClassDB::bind_method(D_METHOD("get_size_2d_override"), &SubViewport::get_size_2d_override); + + ClassDB::bind_method(D_METHOD("set_size_2d_override_stretch", "enable"), &SubViewport::set_size_2d_override_stretch); + ClassDB::bind_method(D_METHOD("is_size_2d_override_stretch_enabled"), &SubViewport::is_size_2d_override_stretch_enabled); + ClassDB::bind_method(D_METHOD("set_update_mode", "mode"), &SubViewport::set_update_mode); ClassDB::bind_method(D_METHOD("get_update_mode"), &SubViewport::get_update_mode); ClassDB::bind_method(D_METHOD("set_clear_mode", "mode"), &SubViewport::set_clear_mode); ClassDB::bind_method(D_METHOD("get_clear_mode"), &SubViewport::get_clear_mode); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "arvr"), "set_use_arvr", "is_using_arvr"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "xr"), "set_use_xr", "is_using_xr"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size_2d_override"), "set_size_2d_override", "get_size_2d_override"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "size_2d_override_stretch"), "set_size_2d_override_stretch", "is_size_2d_override_stretch_enabled"); ADD_GROUP("Render Target", "render_target_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target_clear_mode", PROPERTY_HINT_ENUM, "Always,Never,Next Frame"), "set_clear_mode", "get_clear_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target_update_mode", PROPERTY_HINT_ENUM, "Disabled,Once,When Visible,Always"), "set_update_mode", "get_update_mode"); @@ -3701,7 +3758,8 @@ void SubViewport::_bind_methods() { } SubViewport::SubViewport() { - arvr = false; + xr = false; + size_2d_override_stretch = false; update_mode = UPDATE_WHEN_VISIBLE; clear_mode = CLEAR_MODE_ALWAYS; } diff --git a/scene/main/viewport.h b/scene/main/viewport.h index d0b22b5553..0cbc957307 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -106,6 +106,13 @@ public: MSAA_4X, MSAA_8X, MSAA_16X, + MSAA_MAX + }; + + enum ScreenSpaceAA { + SCREEN_SPACE_AA_DISABLED, + SCREEN_SPACE_AA_FXAA, + SCREEN_SPACE_AA_MAX }; enum RenderInfo { @@ -133,7 +140,9 @@ public: DEBUG_DRAW_DIRECTIONAL_SHADOW_ATLAS, DEBUG_DRAW_SCENE_LUMINANCE, DEBUG_DRAW_SSAO, - DEBUG_DRAW_ROUGHNESS_LIMITER + DEBUG_DRAW_ROUGHNESS_LIMITER, + DEBUG_DRAW_PSSM_SPLITS, + DEBUG_DRAW_DECAL_ATLAS }; enum DefaultCanvasItemTextureFilter { @@ -203,7 +212,7 @@ private: Transform2D stretch_transform; Size2i size; - Size2i size_override; + Size2i size_2d_override; bool size_allocated; RID contact_2d_debug; @@ -271,6 +280,7 @@ private: ShadowAtlasQuadrantSubdiv shadow_atlas_quadrant_subdiv[4]; MSAA msaa; + ScreenSpaceAA screen_space_aa; Ref<ViewportTexture> default_texture; Set<ViewportTexture *> viewport_textures; @@ -374,7 +384,7 @@ private: void _gui_remove_root_control(List<Control *>::Element *RI); - String _gui_get_tooltip(Control *p_control, const Vector2 &p_pos, Control **r_which = NULL); + String _gui_get_tooltip(Control *p_control, const Vector2 &p_pos, Control **r_which = nullptr); void _gui_cancel_tooltip(); void _gui_show_tooltip(); @@ -434,9 +444,10 @@ private: SubWindowResize _sub_window_get_resize_margin(Window *p_subwindow, const Point2 &p_point); protected: - void _set_size(const Size2i &p_size, const Size2i &p_size_override, const Rect2i &p_to_screen_rect, const Transform2D &p_stretch_transform, bool p_allocated); + void _set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, const Transform2D &p_stretch_transform, bool p_allocated); Size2i _get_size() const; + Size2i _get_size_2d_override() const; bool _is_size_allocated() const; void _notification(int p_what); @@ -503,6 +514,9 @@ public: void set_msaa(MSAA p_msaa); MSAA get_msaa() const; + void set_screen_space_aa(ScreenSpaceAA p_screen_space_aa); + ScreenSpaceAA get_screen_space_aa() const; + Vector2 get_camera_coords(const Vector2 &p_viewport_coords) const; Vector2 get_camera_rect_size() const; @@ -588,19 +602,27 @@ public: private: UpdateMode update_mode; ClearMode clear_mode; - bool arvr; + bool xr; + bool size_2d_override_stretch; protected: static void _bind_methods(); virtual DisplayServer::WindowID get_window_id() const; + Transform2D _stretch_transform(); void _notification(int p_what); public: void set_size(const Size2i &p_size); Size2i get_size() const; - void set_use_arvr(bool p_use_arvr); - bool is_using_arvr(); + void set_size_2d_override(const Size2i &p_size); + Size2i get_size_2d_override() const; + + void set_use_xr(bool p_use_xr); + bool is_using_xr(); + + void set_size_2d_override_stretch(bool p_enable); + bool is_size_2d_override_stretch_enabled() const; void set_update_mode(UpdateMode p_mode); UpdateMode get_update_mode() const; @@ -614,6 +636,7 @@ public: VARIANT_ENUM_CAST(SubViewport::UpdateMode); VARIANT_ENUM_CAST(Viewport::ShadowAtlasQuadrantSubdiv); VARIANT_ENUM_CAST(Viewport::MSAA); +VARIANT_ENUM_CAST(Viewport::ScreenSpaceAA); VARIANT_ENUM_CAST(Viewport::DebugDraw); VARIANT_ENUM_CAST(SubViewport::ClearMode); VARIANT_ENUM_CAST(Viewport::RenderInfo); diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 406f130b71..19954299de 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -909,7 +909,7 @@ void Window::_window_input_text(const String &p_text) { input_text(p_text); } void Window::_window_drop_files(const Vector<String> &p_files) { - emit_signal("files_dropped", p_files); + emit_signal("files_dropped", p_files, current_screen); } Viewport *Window::get_parent_viewport() const { @@ -1108,13 +1108,13 @@ void Window::remove_child_notify(Node *p_child) { Control *child_c = Object::cast_to<Control>(p_child); if (child_c && (child_c->data.theme_owner || child_c->data.theme_owner_window) && child_c->data.theme.is_null()) { - Control::_propagate_theme_changed(child_c, NULL, NULL); + Control::_propagate_theme_changed(child_c, nullptr, nullptr); } Window *child_w = Object::cast_to<Window>(p_child); if (child_w && (child_w->theme_owner || child_w->theme_owner_window) && child_w->theme.is_null()) { - Control::_propagate_theme_changed(child_w, NULL, NULL); + Control::_propagate_theme_changed(child_w, nullptr, nullptr); } if (is_inside_tree() && wrap_controls) { |