Merge pull request #108507 from dementive/optimize-scene-tree-groups

Optimize scene tree groups
This commit is contained in:
Thaddeus Crews
2025-11-14 14:22:57 -06:00
8 changed files with 35 additions and 43 deletions

View File

@ -117,8 +117,7 @@ PackedStringArray CanvasModulate::get_configuration_warnings() const {
PackedStringArray warnings = Node2D::get_configuration_warnings();
if (is_in_canvas && is_visible_in_tree()) {
List<Node *> nodes;
get_tree()->get_nodes_in_group("_canvas_modulate_" + itos(get_canvas().get_id()), &nodes);
Vector<Node *> nodes = get_tree()->get_nodes_in_group("_canvas_modulate_" + itos(get_canvas().get_id()));
if (nodes.size() > 1) {
warnings.push_back(RTR("Only one visible CanvasModulate is allowed per canvas.\nWhen there are more than one, only one of them will be active. Which one is undefined."));

View File

@ -1581,22 +1581,20 @@ Node *SceneTree::get_first_node_in_group(const StringName &p_group) {
return E->value.nodes[0];
}
void SceneTree::get_nodes_in_group(const StringName &p_group, List<Node *> *p_list) {
Vector<Node *> SceneTree::get_nodes_in_group(const StringName &p_group) {
_THREAD_SAFE_METHOD_
HashMap<StringName, Group>::Iterator E = group_map.find(p_group);
if (!E) {
return;
return {};
}
_update_group_order(E->value); //update order just in case
int nc = E->value.nodes.size();
if (nc == 0) {
return;
}
Node **ptr = E->value.nodes.ptrw();
for (int i = 0; i < nc; i++) {
p_list->push_back(ptr[i]);
return {};
}
return E->value.nodes;
}
void SceneTree::_flush_delete_queue() {

View File

@ -409,7 +409,7 @@ public:
void queue_delete(Object *p_object);
void get_nodes_in_group(const StringName &p_group, List<Node *> *p_list);
Vector<Node *> get_nodes_in_group(const StringName &p_group);
Node *get_first_node_in_group(const StringName &p_group);
bool has_group(const StringName &p_identifier) const;
int get_node_count_in_group(const StringName &p_group) const;

View File

@ -227,8 +227,7 @@ void ShaderGlobalsOverride::_get_property_list(List<PropertyInfo> *p_list) const
void ShaderGlobalsOverride::_activate() {
ERR_FAIL_NULL(get_tree());
List<Node *> nodes;
get_tree()->get_nodes_in_group(SceneStringName(shader_overrides_group_active), &nodes);
Vector<Node *> nodes = get_tree()->get_nodes_in_group(SceneStringName(shader_overrides_group_active));
if (nodes.is_empty()) {
//good we are the only override, enable all
active = true;

View File

@ -4375,8 +4375,7 @@ Camera2D *Viewport::get_camera_2d() const {
void Viewport::assign_next_enabled_camera_2d(const StringName &p_camera_group) {
ERR_MAIN_THREAD_GUARD;
List<Node *> camera_list;
get_tree()->get_nodes_in_group(p_camera_group, &camera_list);
Vector<Node *> camera_list = get_tree()->get_nodes_in_group(p_camera_group);
Camera2D *new_camera = nullptr;
for (Node *E : camera_list) {