From 75881f832250caec21c35403b5b622244d9b9ce2 Mon Sep 17 00:00:00 2001 From: kobewi Date: Fri, 22 Mar 2024 22:53:26 +0100 Subject: [PATCH] Use initializer list in Arrays --- core/debugger/debugger_marshalls.cpp | 32 ++-- core/debugger/engine_debugger.cpp | 3 +- core/debugger/remote_debugger.cpp | 23 +-- core/io/json.cpp | 153 +++-------------- core/variant/array.cpp | 4 + core/variant/typed_array.h | 2 + core/variant/variant_op.h | 10 +- core/variant/variant_setget.cpp | 6 +- editor/code_editor.cpp | 10 +- .../debug_adapter/debug_adapter_parser.cpp | 9 +- .../debug_adapter/debug_adapter_protocol.cpp | 82 +++------- .../debug_adapter/debug_adapter_types.h | 4 +- .../debugger/editor_expression_evaluator.cpp | 3 +- editor/debugger/script_editor_debugger.cpp | 154 +++++------------- editor/editor_resource_picker.cpp | 3 +- editor/filesystem_dock.cpp | 8 +- editor/gui/scene_tree_editor.cpp | 3 +- editor/import/editor_import_plugin.cpp | 4 +- editor/plugins/theme_editor_plugin.cpp | 25 +-- editor/plugins/tiles/tile_data_editors.cpp | 33 ++-- .../plugins/tiles/tile_map_layer_editor.cpp | 5 +- .../tiles/tile_set_atlas_source_editor.cpp | 21 +-- editor/themes/editor_fonts.cpp | 36 ++-- modules/enet/enet_connection.cpp | 6 +- modules/fbx/fbx_document.cpp | 6 +- modules/gdscript/gdscript.cpp | 3 +- modules/gdscript/gdscript_cache.cpp | 4 +- modules/gdscript/gdscript_vm.cpp | 7 +- modules/gltf/gltf_document.cpp | 11 +- modules/multiplayer/multiplayer_debugger.cpp | 10 +- modules/multiplayer/scene_multiplayer.cpp | 9 +- .../scene_replication_interface.cpp | 5 +- modules/multiplayer/scene_rpc_interface.cpp | 5 +- modules/openxr/openxr_api.cpp | 3 +- platform/web/export/export_plugin.cpp | 16 +- scene/2d/tile_map_layer.cpp | 13 +- scene/3d/lightmap_gi.cpp | 3 +- scene/debugger/scene_debugger.cpp | 5 +- scene/gui/control.cpp | 12 +- scene/gui/view_panner.cpp | 4 +- scene/main/resource_preloader.cpp | 4 +- scene/main/viewport.cpp | 4 +- scene/main/window.cpp | 3 +- scene/resources/2d/tile_set.cpp | 117 +++---------- .../resources/2d/world_boundary_shape_2d.cpp | 4 +- servers/debugger/servers_debugger.cpp | 26 +-- .../renderer_rd/renderer_scene_render_rd.cpp | 6 +- .../storage_rd/render_scene_buffers_rd.cpp | 33 ++-- servers/xr/xr_interface.cpp | 3 +- tests/core/input/test_input_event.h | 4 +- tests/core/input/test_shortcut.h | 28 +--- tests/core/io/test_http_client.h | 5 +- tests/core/io/test_json.h | 10 +- tests/core/io/test_json_native.h | 22 +-- tests/core/math/test_expression.h | 30 +--- tests/core/object/test_object.h | 3 +- tests/core/variant/test_array.h | 40 +---- tests/core/variant/test_callable.h | 6 +- tests/core/variant/test_dictionary.h | 6 +- tests/core/variant/test_variant_utility.h | 11 +- tests/scene/test_arraymesh.h | 8 +- tests/scene/test_code_edit.h | 23 +-- tests/scene/test_control.h | 3 +- tests/scene/test_instance_placeholder.h | 9 +- tests/scene/test_split_container.h | 4 +- tests/scene/test_text_edit.h | 12 +- tests/scene/test_timer.h | 16 +- tests/scene/test_viewport.h | 37 ++--- tests/servers/test_navigation_server_3d.h | 16 +- tests/servers/test_text_server.h | 30 +--- tests/test_macros.h | 12 +- tests/test_validate_testing.h | 4 +- 72 files changed, 347 insertions(+), 947 deletions(-) diff --git a/core/debugger/debugger_marshalls.cpp b/core/debugger/debugger_marshalls.cpp index cc36ca4816a..55b61f1cc8e 100644 --- a/core/debugger/debugger_marshalls.cpp +++ b/core/debugger/debugger_marshalls.cpp @@ -36,8 +36,7 @@ #define CHECK_END(arr, expected, what) ERR_FAIL_COND_V_MSG((uint32_t)arr.size() > (uint32_t)expected, false, String("Malformed ") + what + " message from script debugger, message too long. Expected size: " + itos(expected) + ", actual size: " + itos(arr.size())) Array DebuggerMarshalls::ScriptStackDump::serialize() { - Array arr; - arr.push_back(frames.size() * 3); + Array arr = { frames.size() * 3 }; for (const ScriptLanguage::StackInfo &frame : frames) { arr.push_back(frame.file); arr.push_back(frame.line); @@ -64,10 +63,7 @@ bool DebuggerMarshalls::ScriptStackDump::deserialize(const Array &p_arr) { } Array DebuggerMarshalls::ScriptStackVariable::serialize(int max_size) { - Array arr; - arr.push_back(name); - arr.push_back(type); - arr.push_back(value.get_type()); + Array arr = { name, type, value.get_type() }; Variant var = value; if (value.get_type() == Variant::OBJECT && value.get_validated_object() == nullptr) { @@ -99,20 +95,20 @@ bool DebuggerMarshalls::ScriptStackVariable::deserialize(const Array &p_arr) { } Array DebuggerMarshalls::OutputError::serialize() { - Array arr; - arr.push_back(hr); - arr.push_back(min); - arr.push_back(sec); - arr.push_back(msec); - arr.push_back(source_file); - arr.push_back(source_func); - arr.push_back(source_line); - arr.push_back(error); - arr.push_back(error_descr); - arr.push_back(warning); unsigned int size = callstack.size(); + Array arr = { + hr, + min, + sec, msec, + source_file, + source_func, + source_line, + error, + error_descr, + warning, + size * 3 + }; const ScriptLanguage::StackInfo *r = callstack.ptr(); - arr.push_back(size * 3); for (int i = 0; i < callstack.size(); i++) { arr.push_back(r[i].file); arr.push_back(r[i].func); diff --git a/core/debugger/engine_debugger.cpp b/core/debugger/engine_debugger.cpp index 00e6d959b33..8d0f526130e 100644 --- a/core/debugger/engine_debugger.cpp +++ b/core/debugger/engine_debugger.cpp @@ -149,8 +149,7 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, bo singleton = memnew(RemoteDebugger(Ref(peer))); script_debugger = memnew(ScriptDebugger); // Notify editor of our pid (to allow focus stealing). - Array msg; - msg.push_back(OS::get_singleton()->get_process_id()); + Array msg = { OS::get_singleton()->get_process_id() }; singleton->send_message("set_pid", msg); } if (!singleton) { diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index 0cc79e744a4..cd9cd084005 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -95,10 +95,7 @@ public: }; Error RemoteDebugger::_put_msg(const String &p_message, const Array &p_data) { - Array msg; - msg.push_back(p_message); - msg.push_back(Thread::get_caller_id()); - msg.push_back(p_data); + Array msg = { p_message, Thread::get_caller_id(), p_data }; Error err = peer->put_message(msg); if (err != OK) { n_messages_dropped++; @@ -235,9 +232,7 @@ void RemoteDebugger::flush_output() { types.push_back(MESSAGE_TYPE_LOG); } - Array arr; - arr.push_back(strings); - arr.push_back(types); + Array arr = { strings, types }; _put_msg("output", arr); output_strings.clear(); } @@ -418,11 +413,12 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { const String error_str = script_lang ? script_lang->debug_get_error() : ""; if (can_break) { - Array msg; - msg.push_back(p_can_continue); - msg.push_back(error_str); - msg.push_back(script_lang->debug_get_stack_level_count() > 0); - msg.push_back(Thread::get_caller_id()); + Array msg = { + p_can_continue, + error_str, + script_lang->debug_get_stack_level_count() > 0, + Thread::get_caller_id() + }; if (allow_focus_steal_fn) { allow_focus_steal_fn(); } @@ -514,8 +510,7 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { script_lang->debug_get_globals(&globals, &globals_vals); ERR_FAIL_COND(globals.size() != globals_vals.size()); - Array var_size; - var_size.push_back(local_vals.size() + member_vals.size() + globals_vals.size()); + Array var_size = { local_vals.size() + member_vals.size() + globals_vals.size() }; send_message("stack_frame_vars", var_size); _send_stack_vars(locals, local_vals, 0); _send_stack_vars(members, member_vals, 1); diff --git a/core/io/json.cpp b/core/io/json.cpp index 41ec634ba08..408e455ab03 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -664,201 +664,96 @@ Variant JSON::_from_native(const Variant &p_variant, bool p_full_objects, int p_ case Variant::VECTOR2: { const Vector2 v = p_variant; - - Array args; - args.push_back(v.x); - args.push_back(v.y); - + Array args = { v.x, v.y }; RETURN_ARGS; } break; case Variant::VECTOR2I: { const Vector2i v = p_variant; - - Array args; - args.push_back(v.x); - args.push_back(v.y); - + Array args = { v.x, v.y }; RETURN_ARGS; } break; case Variant::RECT2: { const Rect2 r = p_variant; - - Array args; - args.push_back(r.position.x); - args.push_back(r.position.y); - args.push_back(r.size.width); - args.push_back(r.size.height); - + Array args = { r.position.x, r.position.y, r.size.width, r.size.height }; RETURN_ARGS; } break; case Variant::RECT2I: { const Rect2i r = p_variant; - - Array args; - args.push_back(r.position.x); - args.push_back(r.position.y); - args.push_back(r.size.width); - args.push_back(r.size.height); - + Array args = { r.position.x, r.position.y, r.size.width, r.size.height }; RETURN_ARGS; } break; case Variant::VECTOR3: { const Vector3 v = p_variant; - - Array args; - args.push_back(v.x); - args.push_back(v.y); - args.push_back(v.z); - + Array args = { v.x, v.y, v.z }; RETURN_ARGS; } break; case Variant::VECTOR3I: { const Vector3i v = p_variant; - - Array args; - args.push_back(v.x); - args.push_back(v.y); - args.push_back(v.z); - + Array args = { v.x, v.y, v.z }; RETURN_ARGS; } break; case Variant::TRANSFORM2D: { const Transform2D t = p_variant; - - Array args; - args.push_back(t[0].x); - args.push_back(t[0].y); - args.push_back(t[1].x); - args.push_back(t[1].y); - args.push_back(t[2].x); - args.push_back(t[2].y); - + Array args = { t[0].x, t[0].y, t[1].x, t[1].y, t[2].x, t[2].y }; RETURN_ARGS; } break; case Variant::VECTOR4: { const Vector4 v = p_variant; - - Array args; - args.push_back(v.x); - args.push_back(v.y); - args.push_back(v.z); - args.push_back(v.w); - + Array args = { v.x, v.y, v.z, v.w }; RETURN_ARGS; } break; case Variant::VECTOR4I: { const Vector4i v = p_variant; - - Array args; - args.push_back(v.x); - args.push_back(v.y); - args.push_back(v.z); - args.push_back(v.w); - + Array args = { v.x, v.y, v.z, v.w }; RETURN_ARGS; } break; case Variant::PLANE: { const Plane p = p_variant; - - Array args; - args.push_back(p.normal.x); - args.push_back(p.normal.y); - args.push_back(p.normal.z); - args.push_back(p.d); - + Array args = { p.normal.x, p.normal.y, p.normal.z, p.d }; RETURN_ARGS; } break; case Variant::QUATERNION: { const Quaternion q = p_variant; - - Array args; - args.push_back(q.x); - args.push_back(q.y); - args.push_back(q.z); - args.push_back(q.w); - + Array args = { q.x, q.y, q.z, q.w }; RETURN_ARGS; } break; case Variant::AABB: { const AABB aabb = p_variant; - - Array args; - args.push_back(aabb.position.x); - args.push_back(aabb.position.y); - args.push_back(aabb.position.z); - args.push_back(aabb.size.x); - args.push_back(aabb.size.y); - args.push_back(aabb.size.z); - + Array args = { aabb.position.x, aabb.position.y, aabb.position.z, aabb.size.x, aabb.size.y, aabb.size.z }; RETURN_ARGS; } break; case Variant::BASIS: { const Basis b = p_variant; - Array args; - args.push_back(b.get_column(0).x); - args.push_back(b.get_column(0).y); - args.push_back(b.get_column(0).z); - args.push_back(b.get_column(1).x); - args.push_back(b.get_column(1).y); - args.push_back(b.get_column(1).z); - args.push_back(b.get_column(2).x); - args.push_back(b.get_column(2).y); - args.push_back(b.get_column(2).z); + Array args = { b.get_column(0).x, b.get_column(0).y, b.get_column(0).z, + b.get_column(1).x, b.get_column(1).y, b.get_column(1).z, + b.get_column(2).x, b.get_column(2).y, b.get_column(2).z }; RETURN_ARGS; } break; case Variant::TRANSFORM3D: { const Transform3D t = p_variant; - Array args; - args.push_back(t.basis.get_column(0).x); - args.push_back(t.basis.get_column(0).y); - args.push_back(t.basis.get_column(0).z); - args.push_back(t.basis.get_column(1).x); - args.push_back(t.basis.get_column(1).y); - args.push_back(t.basis.get_column(1).z); - args.push_back(t.basis.get_column(2).x); - args.push_back(t.basis.get_column(2).y); - args.push_back(t.basis.get_column(2).z); - args.push_back(t.origin.x); - args.push_back(t.origin.y); - args.push_back(t.origin.z); + Array args = { t.basis.get_column(0).x, t.basis.get_column(0).y, t.basis.get_column(0).z, + t.basis.get_column(1).x, t.basis.get_column(1).y, t.basis.get_column(1).z, + t.basis.get_column(2).x, t.basis.get_column(2).y, t.basis.get_column(2).z, + t.origin.x, t.origin.y, t.origin.z }; RETURN_ARGS; } break; case Variant::PROJECTION: { const Projection p = p_variant; - Array args; - args.push_back(p[0].x); - args.push_back(p[0].y); - args.push_back(p[0].z); - args.push_back(p[0].w); - args.push_back(p[1].x); - args.push_back(p[1].y); - args.push_back(p[1].z); - args.push_back(p[1].w); - args.push_back(p[2].x); - args.push_back(p[2].y); - args.push_back(p[2].z); - args.push_back(p[2].w); - args.push_back(p[3].x); - args.push_back(p[3].y); - args.push_back(p[3].z); - args.push_back(p[3].w); + Array args = { p[0].x, p[0].y, p[0].z, p[0].w, + p[1].x, p[1].y, p[1].z, p[1].w, + p[2].x, p[2].y, p[2].z, p[2].w, + p[3].x, p[3].y, p[3].z, p[3].w }; RETURN_ARGS; } break; case Variant::COLOR: { const Color c = p_variant; - - Array args; - args.push_back(c.r); - args.push_back(c.g); - args.push_back(c.b); - args.push_back(c.a); - + Array args = { c.r, c.g, c.b, c.a }; RETURN_ARGS; } break; diff --git a/core/variant/array.cpp b/core/variant/array.cpp index e2f08abcaef..1f203e94e6c 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -45,6 +45,10 @@ struct ArrayPrivate { Vector array; Variant *read_only = nullptr; // If enabled, a pointer is used to a temporary value that is used to return read-only values. ContainerTypeValidate typed; + + ArrayPrivate() {} + ArrayPrivate(std::initializer_list p_init) : + array(p_init) {} }; void Array::_ref(const Array &p_from) const { diff --git a/core/variant/typed_array.h b/core/variant/typed_array.h index 27067756d54..639b5f703d5 100644 --- a/core/variant/typed_array.h +++ b/core/variant/typed_array.h @@ -55,6 +55,8 @@ public: assign(p_array); } } + _FORCE_INLINE_ TypedArray(std::initializer_list p_init) : + TypedArray(Array(p_init)) {} _FORCE_INLINE_ TypedArray() { set_typed(Variant::OBJECT, T::get_class_static(), Variant()); } diff --git a/core/variant/variant_op.h b/core/variant/variant_op.h index 65d3bb01bb4..424ebd937d7 100644 --- a/core/variant/variant_op.h +++ b/core/variant/variant_op.h @@ -907,9 +907,7 @@ template class OperatorEvaluatorStringFormat { public: _FORCE_INLINE_ static String do_mod(const String &s, bool *r_valid) { - Array values; - values.push_back(Variant()); - + Array values = { Variant() }; String a = s.sprintf(values, r_valid); if (r_valid) { *r_valid = !*r_valid; @@ -966,8 +964,7 @@ template class OperatorEvaluatorStringFormat { public: _FORCE_INLINE_ static String do_mod(const String &s, const Object *p_object, bool *r_valid) { - Array values; - values.push_back(p_object); + Array values = { p_object }; String a = s.sprintf(values, r_valid); if (r_valid) { *r_valid = !*r_valid; @@ -997,8 +994,7 @@ template class OperatorEvaluatorStringFormat { public: _FORCE_INLINE_ static String do_mod(const String &s, const T &p_value, bool *r_valid) { - Array values; - values.push_back(p_value); + Array values = { p_value }; String a = s.sprintf(values, r_valid); if (r_valid) { *r_valid = !*r_valid; diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index ba14062a385..8175c904878 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -1379,8 +1379,7 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { #endif Callable::CallError ce; ce.error = Callable::CallError::CALL_OK; - Array ref; - ref.push_back(r_iter); + Array ref = { r_iter }; Variant vref = ref; const Variant *refp[] = { &vref }; Variant ret = _get_obj().obj->callp(CoreStringName(_iter_init), refp, 1, ce); @@ -1614,8 +1613,7 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { #endif Callable::CallError ce; ce.error = Callable::CallError::CALL_OK; - Array ref; - ref.push_back(r_iter); + Array ref = { r_iter }; Variant vref = ref; const Variant *refp[] = { &vref }; Variant ret = _get_obj().obj->callp(CoreStringName(_iter_next), refp, 1, ce); diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index bc678b5ba1b..8e876d94a98 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1940,15 +1940,7 @@ CodeTextEditor::CodeTextEditor() { text_editor->connect("caret_changed", callable_mp(this, &CodeTextEditor::_line_col_changed)); text_editor->connect(SceneStringName(text_changed), callable_mp(this, &CodeTextEditor::_text_changed)); text_editor->connect("code_completion_requested", callable_mp(this, &CodeTextEditor::_complete_request)); - TypedArray cs; - cs.push_back("."); - cs.push_back(","); - cs.push_back("("); - cs.push_back("="); - cs.push_back("$"); - cs.push_back("@"); - cs.push_back("\""); - cs.push_back("\'"); + TypedArray cs = { ".", ",", "(", "=", "$", "@", "\"", "\'" }; text_editor->set_code_completion_prefixes(cs); idle->connect("timeout", callable_mp(this, &CodeTextEditor::_text_changed_idle_timeout)); diff --git a/editor/debugger/debug_adapter/debug_adapter_parser.cpp b/editor/debugger/debug_adapter/debug_adapter_parser.cpp index 30abbbce8eb..00b9e372b0e 100644 --- a/editor/debugger/debug_adapter/debug_adapter_parser.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_parser.cpp @@ -301,12 +301,11 @@ Dictionary DebugAdapterParser::req_threads(const Dictionary &p_params) const { Dictionary response = prepare_success_response(p_params), body; response["body"] = body; - Array arr; DAP::Thread thread; thread.id = 1; // Hardcoded because Godot only supports debugging one thread at the moment thread.name = "Main"; - arr.push_back(thread.to_json()); + Array arr = { thread.to_json() }; body["threads"] = arr; return response; @@ -383,13 +382,12 @@ Dictionary DebugAdapterParser::req_breakpointLocations(const Dictionary &p_param response["body"] = body; Dictionary args = p_params["arguments"]; - Array locations; DAP::BreakpointLocation location; location.line = args["line"]; if (args.has("endLine")) { location.endLine = args["endLine"]; } - locations.push_back(location.to_json()); + Array locations = { location.to_json() }; body["breakpoints"] = locations; return response; @@ -595,8 +593,7 @@ Dictionary DebugAdapterParser::ev_stopped_breakpoint(const int &p_id) const { body["reason"] = "breakpoint"; body["description"] = "Breakpoint"; - Array breakpoints; - breakpoints.push_back(p_id); + Array breakpoints = { p_id }; body["hitBreakpointIds"] = breakpoints; return event; diff --git a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp index 4d64d0d75dd..09728456640 100644 --- a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp @@ -205,9 +205,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { x.value = rtos(vec.x); y.value = rtos(vec.y); - Array arr; - arr.push_back(x.to_json()); - arr.push_back(y.to_json()); + Array arr = { x.to_json(), y.to_json() }; variable_list.insert(id, arr); return id; } @@ -230,11 +228,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { w.value = rtos(rect.size.x); h.value = rtos(rect.size.y); - Array arr; - arr.push_back(x.to_json()); - arr.push_back(y.to_json()); - arr.push_back(w.to_json()); - arr.push_back(h.to_json()); + Array arr = { x.to_json(), y.to_json(), w.to_json(), h.to_json() }; variable_list.insert(id, arr); return id; } @@ -254,10 +248,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { y.value = rtos(vec.y); z.value = rtos(vec.z); - Array arr; - arr.push_back(x.to_json()); - arr.push_back(y.to_json()); - arr.push_back(z.to_json()); + Array arr = { x.to_json(), y.to_json(), z.to_json() }; variable_list.insert(id, arr); return id; } @@ -279,10 +270,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { y.variablesReference = parse_variant(transform.columns[1]); origin.variablesReference = parse_variant(transform.columns[2]); - Array arr; - arr.push_back(x.to_json()); - arr.push_back(y.to_json()); - arr.push_back(origin.to_json()); + Array arr = { x.to_json(), y.to_json(), origin.to_json() }; variable_list.insert(id, arr); return id; } @@ -298,9 +286,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { normal.value = plane.normal; normal.variablesReference = parse_variant(plane.normal); - Array arr; - arr.push_back(d.to_json()); - arr.push_back(normal.to_json()); + Array arr = { d.to_json(), normal.to_json() }; variable_list.insert(id, arr); return id; } @@ -322,11 +308,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { z.value = rtos(quat.z); w.value = rtos(quat.w); - Array arr; - arr.push_back(x.to_json()); - arr.push_back(y.to_json()); - arr.push_back(z.to_json()); - arr.push_back(w.to_json()); + Array arr = { x.to_json(), y.to_json(), z.to_json(), w.to_json() }; variable_list.insert(id, arr); return id; } @@ -344,9 +326,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { position.variablesReference = parse_variant(aabb.position); size.variablesReference = parse_variant(aabb.size); - Array arr; - arr.push_back(position.to_json()); - arr.push_back(size.to_json()); + Array arr = { position.to_json(), size.to_json() }; variable_list.insert(id, arr); return id; } @@ -368,10 +348,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { y.variablesReference = parse_variant(basis.rows[1]); z.variablesReference = parse_variant(basis.rows[2]); - Array arr; - arr.push_back(x.to_json()); - arr.push_back(y.to_json()); - arr.push_back(z.to_json()); + Array arr = { x.to_json(), y.to_json(), z.to_json() }; variable_list.insert(id, arr); return id; } @@ -388,9 +365,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { basis.variablesReference = parse_variant(transform.basis); origin.variablesReference = parse_variant(transform.origin); - Array arr; - arr.push_back(basis.to_json()); - arr.push_back(origin.to_json()); + Array arr = { basis.to_json(), origin.to_json() }; variable_list.insert(id, arr); return id; } @@ -412,11 +387,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { b.value = rtos(color.b); a.value = rtos(color.a); - Array arr; - arr.push_back(r.to_json()); - arr.push_back(g.to_json()); - arr.push_back(b.to_json()); - arr.push_back(a.to_json()); + Array arr = { r.to_json(), g.to_json(), b.to_json(), a.to_json() }; variable_list.insert(id, arr); return id; } @@ -428,8 +399,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { size.type = Variant::get_type_name(Variant::INT); size.value = itos(array.size()); - Array arr; - arr.push_back(size.to_json()); + Array arr = { size.to_json() }; for (int i = 0; i < array.size(); i++) { DAP::Variable var; @@ -467,8 +437,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { size.type = Variant::get_type_name(Variant::INT); size.value = itos(array.size()); - Array arr; - arr.push_back(size.to_json()); + Array arr = { size.to_json() }; for (int i = 0; i < array.size(); i++) { DAP::Variable var; @@ -488,8 +457,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { size.type = Variant::get_type_name(Variant::INT); size.value = itos(array.size()); - Array arr; - arr.push_back(size.to_json()); + Array arr = { size.to_json() }; for (int i = 0; i < array.size(); i++) { DAP::Variable var; @@ -509,8 +477,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { size.type = Variant::get_type_name(Variant::INT); size.value = itos(array.size()); - Array arr; - arr.push_back(size.to_json()); + Array arr = { size.to_json() }; for (int i = 0; i < array.size(); i++) { DAP::Variable var; @@ -530,8 +497,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { size.type = Variant::get_type_name(Variant::INT); size.value = itos(array.size()); - Array arr; - arr.push_back(size.to_json()); + Array arr = { size.to_json() }; for (int i = 0; i < array.size(); i++) { DAP::Variable var; @@ -551,8 +517,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { size.type = Variant::get_type_name(Variant::INT); size.value = itos(array.size()); - Array arr; - arr.push_back(size.to_json()); + Array arr = { size.to_json() }; for (int i = 0; i < array.size(); i++) { DAP::Variable var; @@ -572,8 +537,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { size.type = Variant::get_type_name(Variant::INT); size.value = itos(array.size()); - Array arr; - arr.push_back(size.to_json()); + Array arr = { size.to_json() }; for (int i = 0; i < array.size(); i++) { DAP::Variable var; @@ -593,8 +557,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { size.type = Variant::get_type_name(Variant::INT); size.value = itos(array.size()); - Array arr; - arr.push_back(size.to_json()); + Array arr = { size.to_json() }; for (int i = 0; i < array.size(); i++) { DAP::Variable var; @@ -615,8 +578,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { size.type = Variant::get_type_name(Variant::INT); size.value = itos(array.size()); - Array arr; - arr.push_back(size.to_json()); + Array arr = { size.to_json() }; for (int i = 0; i < array.size(); i++) { DAP::Variable var; @@ -637,8 +599,7 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { size.type = Variant::get_type_name(Variant::INT); size.value = itos(array.size()); - Array arr; - arr.push_back(size.to_json()); + Array arr = { size.to_json() }; for (int i = 0; i < array.size(); i++) { DAP::Variable var; @@ -880,8 +841,7 @@ bool DebugAdapterProtocol::process_message(const String &p_text) { if (parser->has_method(command)) { _current_request = params["command"]; - Array args; - args.push_back(params); + Array args = { params }; Dictionary response = parser->callv(command, args); if (!response.is_empty()) { _current_peer->res_queue.push_front(response); diff --git a/editor/debugger/debug_adapter/debug_adapter_types.h b/editor/debugger/debug_adapter/debug_adapter_types.h index 6682e8081f7..cc2d3d5241e 100644 --- a/editor/debugger/debug_adapter/debug_adapter_types.h +++ b/editor/debugger/debug_adapter/debug_adapter_types.h @@ -158,9 +158,7 @@ struct Capabilities { dict["supportsTerminateRequest"] = supportsTerminateRequest; dict["supportsBreakpointLocationsRequest"] = supportsBreakpointLocationsRequest; - Array arr; - arr.push_back(supportedChecksumAlgorithms[0]); - arr.push_back(supportedChecksumAlgorithms[1]); + Array arr = { supportedChecksumAlgorithms[0], supportedChecksumAlgorithms[1] }; dict["supportedChecksumAlgorithms"] = arr; return dict; diff --git a/editor/debugger/editor_expression_evaluator.cpp b/editor/debugger/editor_expression_evaluator.cpp index 20bfbdd1caa..950dd0b868f 100644 --- a/editor/debugger/editor_expression_evaluator.cpp +++ b/editor/debugger/editor_expression_evaluator.cpp @@ -74,8 +74,7 @@ void EditorExpressionEvaluator::_clear() { } void EditorExpressionEvaluator::_remote_object_selected(ObjectID p_id) { - Array arr; - arr.append(p_id); + Array arr = { p_id }; editor_debugger->emit_signal(SNAME("remote_objects_requested"), arr); } diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 5a10ada6149..0c60d16a46a 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -73,10 +73,7 @@ using CameraOverride = EditorDebuggerNode::CameraOverride; void ScriptEditorDebugger::_put_msg(const String &p_message, const Array &p_data, uint64_t p_thread_id) { ERR_FAIL_COND(p_thread_id == Thread::UNASSIGNED_ID); if (is_session_active()) { - Array msg; - msg.push_back(p_message); - msg.push_back(p_thread_id); - msg.push_back(p_data); + Array msg = { p_message, p_thread_id, p_data }; Error err = peer->put_message(msg); ERR_FAIL_COND_MSG(err != OK, vformat("Failed to send message %d", err)); } @@ -98,8 +95,7 @@ void ScriptEditorDebugger::debug_skip_breakpoints() { skip_breakpoints->set_button_icon(get_editor_theme_icon(SNAME("DebugSkipBreakpointsOff"))); } - Array msg; - msg.push_back(skip_breakpoints_value); + Array msg = { skip_breakpoints_value }; _put_msg("set_skip_breakpoints", msg, debugging_thread_id != Thread::UNASSIGNED_ID ? debugging_thread_id : Thread::MAIN_ID); } @@ -111,8 +107,7 @@ void ScriptEditorDebugger::debug_ignore_error_breaks() { ignore_error_breaks->set_button_icon(get_theme_icon(SNAME("Notification"), SNAME("EditorIcons"))); } - Array msg; - msg.push_back(ignore_error_breaks_value); + Array msg = { ignore_error_breaks_value }; _put_msg("set_ignore_error_breaks", msg); } @@ -170,9 +165,7 @@ void ScriptEditorDebugger::clear_style() { } void ScriptEditorDebugger::save_node(ObjectID p_id, const String &p_file) { - Array msg; - msg.push_back(p_id); - msg.push_back(p_file); + Array msg = { p_id, p_file }; _put_msg("scene:save_node", msg); } @@ -265,17 +258,12 @@ const SceneDebuggerTree *ScriptEditorDebugger::get_remote_tree() { } void ScriptEditorDebugger::request_remote_evaluate(const String &p_expression, int p_stack_frame) { - Array msg; - msg.push_back(p_expression); - msg.push_back(p_stack_frame); + Array msg = { p_expression, p_stack_frame }; _put_msg("evaluate", msg); } void ScriptEditorDebugger::update_remote_object(ObjectID p_obj_id, const String &p_prop, const Variant &p_value, const String &p_field) { - Array msg; - msg.push_back(p_obj_id); - msg.push_back(p_prop); - msg.push_back(p_value); + Array msg = { p_obj_id, p_prop, p_value }; if (p_field.is_empty()) { _put_msg("scene:set_object_property", msg); } else { @@ -286,9 +274,7 @@ void ScriptEditorDebugger::update_remote_object(ObjectID p_obj_id, const String void ScriptEditorDebugger::request_remote_objects(const TypedArray &p_obj_ids, bool p_update_selection) { ERR_FAIL_COND(p_obj_ids.is_empty()); - Array msg; - msg.push_back(p_obj_ids.duplicate()); - msg.push_back(p_update_selection); + Array msg = { p_obj_ids.duplicate(), p_update_selection }; _put_msg("scene:inspect_objects", msg); } @@ -300,8 +286,7 @@ void ScriptEditorDebugger::clear_inspector(bool p_send_msg) { } void ScriptEditorDebugger::_remote_object_selected(ObjectID p_id) { - Array arr; - arr.append(p_id); + Array arr = { p_id }; emit_signal(SNAME("remote_objects_requested"), arr); } @@ -596,11 +581,7 @@ void ScriptEditorDebugger::_msg_error(uint64_t p_thread_id, const Array &p_data) ERR_FAIL_COND_MSG(oe.deserialize(p_data) == false, "Failed to deserialize error message"); // Format time. - Array time_vals; - time_vals.push_back(oe.hr); - time_vals.push_back(oe.min); - time_vals.push_back(oe.sec); - time_vals.push_back(oe.msec); + Array time_vals = { oe.hr, oe.min, oe.sec, oe.msec }; bool e; String time = String("%d:%02d:%02d:%03d").sprintf(time_vals, &e); @@ -608,9 +589,7 @@ void ScriptEditorDebugger::_msg_error(uint64_t p_thread_id, const Array &p_data) bool source_is_project_file = oe.source_file.begins_with("res://"); // Metadata to highlight error line in scripts. - Array source_meta; - source_meta.push_back(oe.source_file); - source_meta.push_back(oe.source_line); + Array source_meta = { oe.source_file, oe.source_line }; // Create error tree to display above error or warning details. TreeItem *r = error_tree->get_root(); @@ -710,9 +689,7 @@ void ScriptEditorDebugger::_msg_error(uint64_t p_thread_id, const Array &p_data) for (unsigned int i = 0; i < (unsigned int)oe.callstack.size(); i++) { TreeItem *stack_trace = error_tree->create_item(error); - Array meta; - meta.push_back(infos[i].file); - meta.push_back(infos[i].line); + Array meta = { infos[i].file, infos[i].line }; stack_trace->set_metadata(0, meta); if (i == 0) { @@ -1068,8 +1045,7 @@ void ScriptEditorDebugger::_notification(int p_what) { transform.scale_basis(Size2(zoom, zoom)); transform.columns[2] = -offset * zoom; - Array msg; - msg.push_back(transform); + Array msg = { transform }; _put_msg("scene:transform_camera_2d", msg); } @@ -1078,8 +1054,7 @@ void ScriptEditorDebugger::_notification(int p_what) { Node3DEditorViewport *viewport = Node3DEditor::get_singleton()->get_last_used_viewport(); const Camera3D *cam = viewport->get_camera_3d(); - Array msg; - msg.push_back(cam->get_camera_transform()); + Array msg = { cam->get_camera_transform() }; if (cam->get_projection() == Camera3D::PROJECTION_ORTHOGONAL) { msg.push_back(false); msg.push_back(cam->get_size()); @@ -1266,8 +1241,7 @@ void ScriptEditorDebugger::stop() { } void ScriptEditorDebugger::_profiler_activate(bool p_enable, int p_type) { - Array msg_data; - msg_data.push_back(p_enable); + Array msg_data = { p_enable }; switch (p_type) { case PROFILER_VISUAL: _put_msg("profiler:visual", msg_data); @@ -1277,11 +1251,9 @@ void ScriptEditorDebugger::_profiler_activate(bool p_enable, int p_type) { // Clear old script signatures. (should we move all this into the profiler?) profiler_signature.clear(); // Add max funcs options to request. - Array opts; int max_funcs = EDITOR_GET("debugger/profiler_frame_max_functions"); bool include_native = EDITOR_GET("debugger/profile_native_calls"); - opts.push_back(CLAMP(max_funcs, 16, 512)); - opts.push_back(include_native); + Array opts = { CLAMP(max_funcs, 16, 512), include_native }; msg_data.push_back(opts); } _put_msg("profiler:servers", msg_data); @@ -1323,8 +1295,7 @@ String ScriptEditorDebugger::get_var_value(const String &p_var) const { } void ScriptEditorDebugger::_resources_reimported(const PackedStringArray &p_resources) { - Array msg; - msg.push_back(p_resources); + Array msg = { p_resources }; _put_msg("scene:reload_cached_files", msg); } @@ -1337,9 +1308,7 @@ int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) { last_path_id++; node_path_cache[p_path] = last_path_id; - Array msg; - msg.push_back(p_path); - msg.push_back(last_path_id); + Array msg = { p_path, last_path_id }; _put_msg("scene:live_node_path", msg); return last_path_id; @@ -1355,9 +1324,7 @@ int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) { last_path_id++; res_path_cache[p_path] = last_path_id; - Array msg; - msg.push_back(p_path); - msg.push_back(last_path_id); + Array msg = { p_path, last_path_id }; _put_msg("scene:live_res_path", msg); return last_path_id; @@ -1381,9 +1348,7 @@ void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_n NodePath path = EditorNode::get_singleton()->get_edited_scene()->get_path_to(node); int pathid = _get_node_path_cache(path); - Array msg; - msg.push_back(pathid); - msg.push_back(p_name); + Array msg = { pathid, p_name }; for (int i = 0; i < p_argcount; i++) { //no pointers, sorry msg.push_back(*p_args[i]); @@ -1399,9 +1364,7 @@ void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_n String respath = res->get_path(); int pathid = _get_res_path_cache(respath); - Array msg; - msg.push_back(pathid); - msg.push_back(p_name); + Array msg = { pathid, p_name }; for (int i = 0; i < p_argcount; i++) { //no pointers, sorry msg.push_back(*p_args[i]); @@ -1426,17 +1389,11 @@ void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p if (p_value.is_ref_counted()) { Ref res = p_value; if (res.is_valid() && !res->get_path().is_empty()) { - Array msg; - msg.push_back(pathid); - msg.push_back(p_property); - msg.push_back(res->get_path()); + Array msg = { pathid, p_property, res->get_path() }; _put_msg("scene:live_node_prop_res", msg); } } else { - Array msg; - msg.push_back(pathid); - msg.push_back(p_property); - msg.push_back(p_value); + Array msg = { pathid, p_property, p_value }; _put_msg("scene:live_node_prop", msg); } @@ -1452,17 +1409,11 @@ void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p if (p_value.is_ref_counted()) { Ref res2 = p_value; if (res2.is_valid() && !res2->get_path().is_empty()) { - Array msg; - msg.push_back(pathid); - msg.push_back(p_property); - msg.push_back(res2->get_path()); + Array msg = { pathid, p_property, res2->get_path() }; _put_msg("scene:live_res_prop_res", msg); } } else { - Array msg; - msg.push_back(pathid); - msg.push_back(p_property); - msg.push_back(p_value); + Array msg = { pathid, p_property, p_value }; _put_msg("scene:live_res_prop", msg); } @@ -1508,8 +1459,7 @@ int ScriptEditorDebugger::get_stack_script_frame() const { bool ScriptEditorDebugger::request_stack_dump(const int &p_frame) { ERR_FAIL_COND_V(!is_session_active() || p_frame < 0, false); - Array msg; - msg.push_back(p_frame); + Array msg = { p_frame }; _put_msg("get_stack_frame_vars", msg, debugging_thread_id); return true; } @@ -1553,8 +1503,7 @@ void ScriptEditorDebugger::_live_edit_clear() { void ScriptEditorDebugger::update_live_edit_root() { NodePath np = EditorNode::get_editor_data().get_edited_scene_live_edit_root(); - Array msg; - msg.push_back(np); + Array msg = { np }; if (EditorNode::get_singleton()->get_edited_scene()) { msg.push_back(EditorNode::get_singleton()->get_edited_scene()->get_scene_file_path()); } else { @@ -1566,67 +1515,49 @@ void ScriptEditorDebugger::update_live_edit_root() { void ScriptEditorDebugger::live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name) { if (live_debug) { - Array msg; - msg.push_back(p_parent); - msg.push_back(p_type); - msg.push_back(p_name); + Array msg = { p_parent, p_type, p_name }; _put_msg("scene:live_create_node", msg); } } void ScriptEditorDebugger::live_debug_instantiate_node(const NodePath &p_parent, const String &p_path, const String &p_name) { if (live_debug) { - Array msg; - msg.push_back(p_parent); - msg.push_back(p_path); - msg.push_back(p_name); + Array msg = { p_parent, p_path, p_name }; _put_msg("scene:live_instantiate_node", msg); } } void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) { if (live_debug) { - Array msg; - msg.push_back(p_at); + Array msg = { p_at }; _put_msg("scene:live_remove_node", msg); } } void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) { if (live_debug) { - Array msg; - msg.push_back(p_at); - msg.push_back(p_keep_id); + Array msg = { p_at, p_keep_id }; _put_msg("scene:live_remove_and_keep_node", msg); } } void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) { if (live_debug) { - Array msg; - msg.push_back(p_id); - msg.push_back(p_at); - msg.push_back(p_at_pos); + Array msg = { p_id, p_at, p_at_pos }; _put_msg("scene:live_restore_node", msg); } } void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) { if (live_debug) { - Array msg; - msg.push_back(p_at); - msg.push_back(p_new_name); + Array msg = { p_at, p_new_name }; _put_msg("scene:live_duplicate_node", msg); } } void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) { if (live_debug) { - Array msg; - msg.push_back(p_at); - msg.push_back(p_new_place); - msg.push_back(p_new_name); - msg.push_back(p_at_pos); + Array msg = { p_at, p_new_place, p_new_name, p_at_pos }; _put_msg("scene:live_reparent_node", msg); } } @@ -1636,8 +1567,7 @@ bool ScriptEditorDebugger::get_debug_mute_audio() const { } void ScriptEditorDebugger::set_debug_mute_audio(bool p_mute) { - Array msg; - msg.push_back(p_mute); + Array msg = { p_mute }; _put_msg("scene:debug_mute_audio", msg); debug_mute_audio = p_mute; } @@ -1647,19 +1577,17 @@ CameraOverride ScriptEditorDebugger::get_camera_override() const { } void ScriptEditorDebugger::set_camera_override(CameraOverride p_override) { - Array msg; - msg.push_back(p_override != CameraOverride::OVERRIDE_NONE); - msg.push_back(p_override == CameraOverride::OVERRIDE_EDITORS); + Array msg = { + p_override != CameraOverride::OVERRIDE_NONE, + p_override == CameraOverride::OVERRIDE_EDITORS + }; _put_msg("scene:override_cameras", msg); camera_override = p_override; } void ScriptEditorDebugger::set_breakpoint(const String &p_path, int p_line, bool p_enabled) { - Array msg; - msg.push_back(p_path); - msg.push_back(p_line); - msg.push_back(p_enabled); + Array msg = { p_path, p_line, p_enabled }; _put_msg("breakpoint", msg, debugging_thread_id != Thread::UNASSIGNED_ID ? debugging_thread_id : Thread::MAIN_ID); TreeItem *path_item = breakpoints_tree->search_item_text(p_path); @@ -1992,9 +1920,7 @@ void ScriptEditorDebugger::send_message(const String &p_message, const Array &p_ } void ScriptEditorDebugger::toggle_profiler(const String &p_profiler, bool p_enable, const Array &p_data) { - Array msg_data; - msg_data.push_back(p_enable); - msg_data.append_array(p_data); + Array msg_data = { p_enable, p_data }; _put_msg("profiler:" + p_profiler, msg_data); } diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index 79d033bf033..d14141c952a 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -1031,8 +1031,7 @@ void EditorResourcePicker::_gather_resources_to_duplicate(const Ref p_ p_item->set_icon(0, EditorNode::get_singleton()->get_object_icon(p_resource.ptr())); p_item->set_editable(0, true); - Array meta; - meta.append(p_resource); + Array meta = { p_resource }; p_item->set_metadata(0, meta); if (!p_property_name.is_empty()) { diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 0f364a47e2e..1ceb11f4615 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -321,9 +321,7 @@ void FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory if (main_scene == file_metadata) { file_item->set_custom_color(0, get_theme_color(SNAME("accent_color"), EditorStringName(Editor))); } - Array udata; - udata.push_back(tree_update_id); - udata.push_back(file_item); + Array udata = { tree_update_id, file_item }; EditorResourcePreview::get_singleton()->queue_resource_preview(file_metadata, this, "_tree_thumbnail_done", udata); } } else { @@ -437,9 +435,7 @@ void FileSystemDock::_update_tree(const Vector &p_uncollapsed_paths, boo ti->set_metadata(0, favorite); if (!favorite.ends_with("/")) { - Array udata; - udata.push_back(tree_update_id); - udata.push_back(ti); + Array udata = { tree_update_id, ti }; EditorResourcePreview::get_singleton()->queue_resource_preview(favorite, this, "_tree_thumbnail_done", udata); } } diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index ffc432896a7..0744c49c067 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -512,8 +512,7 @@ void SceneTreeEditor::_update_node(Node *p_node, TreeItem *p_item, bool p_part_o String msg_temp; if (num_connections >= 1) { - Array arr; - arr.push_back(num_connections); + Array arr = { num_connections }; msg_temp += TTRN("Node has one connection.", "Node has {num} connections.", num_connections).format(arr, "{num}"); if (num_groups >= 1) { msg_temp += "\n"; diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp index 2e3399b0813..789c79a6257 100644 --- a/editor/import/editor_import_plugin.cpp +++ b/editor/import/editor_import_plugin.cpp @@ -118,9 +118,7 @@ int EditorImportPlugin::get_format_version() const { } void EditorImportPlugin::get_import_options(const String &p_path, List *r_options, int p_preset) const { - Array needed; - needed.push_back("name"); - needed.push_back("default_value"); + Array needed = { "name", "default_value" }; TypedArray options; if (GDVIRTUAL_CALL(_get_import_options, p_path, p_preset, options)) { for (int i = 0; i < options.size(); i++) { diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 8913039c679..9afe95f5315 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -240,8 +240,7 @@ void ThemeItemImportTree::_update_items_tree() { } if (color_amount > 0) { - Array arr; - arr.push_back(color_amount); + Array arr = { color_amount }; select_colors_label->set_text(TTRN("1 color", "{num} colors", color_amount).format(arr, "{num}")); select_all_colors_button->set_visible(true); select_full_colors_button->set_visible(true); @@ -254,8 +253,7 @@ void ThemeItemImportTree::_update_items_tree() { } if (constant_amount > 0) { - Array arr; - arr.push_back(constant_amount); + Array arr = { constant_amount }; select_constants_label->set_text(TTRN("1 constant", "{num} constants", constant_amount).format(arr, "{num}")); select_all_constants_button->set_visible(true); select_full_constants_button->set_visible(true); @@ -268,8 +266,7 @@ void ThemeItemImportTree::_update_items_tree() { } if (font_amount > 0) { - Array arr; - arr.push_back(font_amount); + Array arr = { font_amount }; select_fonts_label->set_text(TTRN("1 font", "{num} fonts", font_amount).format(arr, "{num}")); select_all_fonts_button->set_visible(true); select_full_fonts_button->set_visible(true); @@ -282,8 +279,7 @@ void ThemeItemImportTree::_update_items_tree() { } if (font_size_amount > 0) { - Array arr; - arr.push_back(font_size_amount); + Array arr = { font_size_amount }; select_font_sizes_label->set_text(TTRN("1 font size", "{num} font sizes", font_size_amount).format(arr, "{num}")); select_all_font_sizes_button->set_visible(true); select_full_font_sizes_button->set_visible(true); @@ -296,8 +292,7 @@ void ThemeItemImportTree::_update_items_tree() { } if (icon_amount > 0) { - Array arr; - arr.push_back(icon_amount); + Array arr = { icon_amount }; select_icons_label->set_text(TTRN("1 icon", "{num} icons", icon_amount).format(arr, "{num}")); select_all_icons_button->set_visible(true); select_full_icons_button->set_visible(true); @@ -312,8 +307,7 @@ void ThemeItemImportTree::_update_items_tree() { } if (stylebox_amount > 0) { - Array arr; - arr.push_back(stylebox_amount); + Array arr = { stylebox_amount }; select_styleboxes_label->set_text(TTRN("1 stylebox", "{num} styleboxes", stylebox_amount).format(arr, "{num}")); select_all_styleboxes_button->set_visible(true); select_full_styleboxes_button->set_visible(true); @@ -460,8 +454,7 @@ void ThemeItemImportTree::_update_total_selected(Theme::DataType p_data_type) { if (count == 0) { total_selected_items_label->hide(); } else { - Array arr; - arr.push_back(count); + Array arr = { count }; total_selected_items_label->set_text(TTRN("{num} currently selected", "{num} currently selected", count).format(arr, "{num}")); total_selected_items_label->show(); } @@ -756,9 +749,7 @@ void ThemeItemImportTree::_import_selected() { // Arbitrary number of items to skip from reporting. // Reduces the number of UI updates that this causes when copying large themes. if (idx % 10 == 0) { - Array arr; - arr.push_back(idx + 1); - arr.push_back(selected_items.size()); + Array arr = { idx + 1, selected_items.size() }; ProgressDialog::get_singleton()->task_step("import_theme_items", TTR("Importing items {n}/{n}").format(arr, "{n}"), idx); } diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp index ffc525b242d..3a20db5620b 100644 --- a/editor/plugins/tiles/tile_data_editors.cpp +++ b/editor/plugins/tiles/tile_data_editors.cpp @@ -220,8 +220,7 @@ void GenericTilePolygonEditor::_base_control_draw() { color = color.darkened(0.3); } color.a = 0.5; - Vector v_color; - v_color.push_back(color); + Vector v_color = { color }; base_control->draw_polygon(polygon, v_color); color.a = 0.7; @@ -1483,8 +1482,7 @@ void TileDataOcclusionShapeEditor::draw_over_tile(CanvasItem *p_canvas_item, Tra } color.a *= 0.5; - Vector debug_occlusion_color; - debug_occlusion_color.push_back(color); + Vector debug_occlusion_color = { color }; RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), p_transform); for (int i = 0; i < tile_data->get_occluder_polygons_count(occlusion_layer); i++) { @@ -2065,14 +2063,12 @@ void TileDataTerrainsEditor::forward_draw_over_atlas(TileAtlasView *p_tile_atlas } Vector2 end = p_transform.affine_inverse().xform(p_canvas_item->get_local_mouse_position()); - Vector mouse_pos_rect_polygon; - mouse_pos_rect_polygon.push_back(drag_start_pos); - mouse_pos_rect_polygon.push_back(Vector2(end.x, drag_start_pos.y)); - mouse_pos_rect_polygon.push_back(end); - mouse_pos_rect_polygon.push_back(Vector2(drag_start_pos.x, end.y)); + Vector mouse_pos_rect_polygon = { + drag_start_pos, Vector2(end.x, drag_start_pos.y), + end, Vector2(drag_start_pos.x, end.y) + }; - Vector color; - color.push_back(Color(1.0, 1.0, 1.0, 0.5)); + Vector color = { Color(1.0, 1.0, 1.0, 0.5) }; p_canvas_item->draw_set_transform_matrix(p_transform); @@ -2132,8 +2128,7 @@ void TileDataTerrainsEditor::forward_draw_over_alternatives(TileAtlasView *p_til Transform2D xform; xform.set_origin(position); - Vector color; - color.push_back(Color(1.0, 1.0, 1.0, 0.5)); + Vector color = { Color(1.0, 1.0, 1.0, 0.5) }; Vector polygon = tile_set->get_terrain_polygon(terrain_set); if (Geometry2D::is_point_in_polygon(xform.affine_inverse().xform(mouse_pos), polygon)) { @@ -2548,11 +2543,10 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(TileAtlasView *p_t } } - Vector mouse_pos_rect_polygon; - mouse_pos_rect_polygon.push_back(drag_start_pos); - mouse_pos_rect_polygon.push_back(Vector2(mb->get_position().x, drag_start_pos.y)); - mouse_pos_rect_polygon.push_back(mb->get_position()); - mouse_pos_rect_polygon.push_back(Vector2(drag_start_pos.x, mb->get_position().y)); + Vector mouse_pos_rect_polygon = { + drag_start_pos, Vector2(mb->get_position().x, drag_start_pos.y), + mb->get_position(), Vector2(drag_start_pos.x, mb->get_position().y) + }; undo_redo->create_action(TTR("Painting Terrain")); for (const TileMapCell &E : edited) { @@ -3031,8 +3025,7 @@ void TileDataNavigationEditor::draw_over_tile(CanvasItem *p_canvas_item, Transfo Color random_variation_color; random_variation_color.set_hsv(color.get_h() + rand.random(-1.0, 1.0) * 0.05, color.get_s(), color.get_v() + rand.random(-1.0, 1.0) * 0.1); random_variation_color.a = color.a; - Vector colors; - colors.push_back(random_variation_color); + Vector colors = { random_variation_color }; RenderingServer::get_singleton()->canvas_item_add_polygon(p_canvas_item->get_canvas_item(), vertices, colors); } diff --git a/editor/plugins/tiles/tile_map_layer_editor.cpp b/editor/plugins/tiles/tile_map_layer_editor.cpp index c94ef4ea508..2c491a144d9 100644 --- a/editor/plugins/tiles/tile_map_layer_editor.cpp +++ b/editor/plugins/tiles/tile_map_layer_editor.cpp @@ -4285,10 +4285,7 @@ void TileMapLayerEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { if (!source || !source->has_tile(tile_atlas_coords) || !source->has_alternative_tile(tile_atlas_coords, tile_alternative_tile)) { // Generate a random color from the hashed identifier of the tiles. - Array to_hash; - to_hash.push_back(tile_source_id); - to_hash.push_back(tile_atlas_coords); - to_hash.push_back(tile_alternative_tile); + Array to_hash = { tile_source_id, tile_atlas_coords, tile_alternative_tile }; uint32_t hash = RandomPCG(to_hash.hash()).rand(); Color color; diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp index e10d6383e56..093dcf5a683 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp @@ -1473,9 +1473,7 @@ void TileSetAtlasSourceEditor::_end_dragging() { undo_redo->add_do_method(tile_set_atlas_source, "move_tile_in_atlas", drag_start_tile_shape.position, drag_current_tile, tile_set_atlas_source->get_tile_size_in_atlas(drag_current_tile)); undo_redo->add_do_method(this, "_set_selection_from_array", _get_selection_as_array()); undo_redo->add_undo_method(tile_set_atlas_source, "move_tile_in_atlas", drag_current_tile, drag_start_tile_shape.position, drag_start_tile_shape.size); - Array array; - array.push_back(drag_start_tile_shape.position); - array.push_back(0); + Array array = { drag_start_tile_shape.position, 0 }; undo_redo->add_undo_method(this, "_set_selection_from_array", array); undo_redo->commit_action(false); } @@ -1573,9 +1571,7 @@ void TileSetAtlasSourceEditor::_end_dragging() { undo_redo->add_do_method(tile_set_atlas_source, "move_tile_in_atlas", drag_start_tile_shape.position, drag_current_tile, tile_set_atlas_source->get_tile_size_in_atlas(drag_current_tile)); undo_redo->add_do_method(this, "_set_selection_from_array", _get_selection_as_array()); undo_redo->add_undo_method(tile_set_atlas_source, "move_tile_in_atlas", drag_current_tile, drag_start_tile_shape.position, drag_start_tile_shape.size); - Array array; - array.push_back(drag_start_tile_shape.position); - array.push_back(0); + Array array = { drag_start_tile_shape.position, 0 }; undo_redo->add_undo_method(this, "_set_selection_from_array", array); undo_redo->commit_action(false); } @@ -1664,9 +1660,7 @@ void TileSetAtlasSourceEditor::_menu_option(int p_option) { case TILE_CREATE: { undo_redo->create_action(TTR("Create a tile")); undo_redo->add_do_method(tile_set_atlas_source, "create_tile", menu_option_coords); - Array array; - array.push_back(menu_option_coords); - array.push_back(0); + Array array = { menu_option_coords, 0 }; undo_redo->add_do_method(this, "_set_selection_from_array", array); undo_redo->add_undo_method(tile_set_atlas_source, "remove_tile", menu_option_coords); undo_redo->add_undo_method(this, "_set_selection_from_array", _get_selection_as_array()); @@ -2803,11 +2797,9 @@ void EditorPropertyTilePolygon::_polygons_changed() { } } else { // Multiple array of vertices or OccluderPolygon2D. - Vector changed_properties; - Array values; + Vector changed_properties = { count_property }; int count = generic_tile_polygon_editor->get_polygon_count(); - changed_properties.push_back(count_property); - values.push_back(count); + Array values = { count }; for (int i = 0; i < count; i++) { changed_properties.push_back(vformat(element_pattern, i)); if (base_type.is_empty()) { @@ -2941,8 +2933,7 @@ bool EditorInspectorPluginTileData::parse_property(Object *p_object, const Varia if (components[1] == "polygons_count") { EditorPropertyTilePolygon *ep = memnew(EditorPropertyTilePolygon); ep->setup_multiple_mode(vformat("physics_layer_%d/polygons", layer_index), vformat("physics_layer_%d/polygons_count", layer_index), vformat("physics_layer_%d/polygon_%%d/points", layer_index), ""); - Vector properties; - properties.push_back(p_path); + Vector properties = { p_path }; int count = p_object->get(vformat("physics_layer_%d/polygons_count", layer_index)); for (int i = 0; i < count; i++) { properties.push_back(vformat(vformat("physics_layer_%d/polygon_%d/points", layer_index, i))); diff --git a/editor/themes/editor_fonts.cpp b/editor/themes/editor_fonts.cpp index 2768615f183..e283f0342ac 100644 --- a/editor/themes/editor_fonts.cpp +++ b/editor/themes/editor_fonts.cpp @@ -210,13 +210,14 @@ void editor_register_fonts(const Ref &p_theme) { Ref japanese_font_bold = make_bold_font(japanese_font, embolden_strength, &fallbacks_bold); if (OS::get_singleton()->has_feature("system_fonts")) { - PackedStringArray emoji_font_names; - emoji_font_names.push_back("Apple Color Emoji"); - emoji_font_names.push_back("Segoe UI Emoji"); - emoji_font_names.push_back("Noto Color Emoji"); - emoji_font_names.push_back("Twitter Color Emoji"); - emoji_font_names.push_back("OpenMoji"); - emoji_font_names.push_back("EmojiOne Color"); + PackedStringArray emoji_font_names = { + "Apple Color Emoji", + "Segoe UI Emoji", + "Noto Color Emoji", + "Twitter Color Emoji", + "OpenMoji", + "EmojiOne Color" + }; Ref emoji_font = load_system_font(emoji_font_names, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false); fallbacks.push_back(emoji_font); fallbacks_bold.push_back(emoji_font); @@ -238,8 +239,7 @@ void editor_register_fonts(const Ref &p_theme) { if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) { Ref custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps); { - TypedArray fallback_custom; - fallback_custom.push_back(default_font); + TypedArray fallback_custom = { default_font }; custom_font->set_fallbacks(fallback_custom); } default_fc->set_base_font(custom_font); @@ -255,8 +255,7 @@ void editor_register_fonts(const Ref &p_theme) { if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) { Ref custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, font_allow_msdf); { - TypedArray fallback_custom; - fallback_custom.push_back(default_font_msdf); + TypedArray fallback_custom = { default_font_msdf }; custom_font->set_fallbacks(fallback_custom); } default_fc_msdf->set_base_font(custom_font); @@ -272,16 +271,14 @@ void editor_register_fonts(const Ref &p_theme) { if (custom_font_path_bold.length() > 0 && dir->file_exists(custom_font_path_bold)) { Ref custom_font = load_external_font(custom_font_path_bold, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps); { - TypedArray fallback_custom; - fallback_custom.push_back(default_font_bold); + TypedArray fallback_custom = { default_font_bold }; custom_font->set_fallbacks(fallback_custom); } bold_fc->set_base_font(custom_font); } else if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) { Ref custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps); { - TypedArray fallback_custom; - fallback_custom.push_back(default_font_bold); + TypedArray fallback_custom = { default_font_bold }; custom_font->set_fallbacks(fallback_custom); } bold_fc->set_base_font(custom_font); @@ -298,16 +295,14 @@ void editor_register_fonts(const Ref &p_theme) { if (custom_font_path_bold.length() > 0 && dir->file_exists(custom_font_path_bold)) { Ref custom_font = load_external_font(custom_font_path_bold, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, font_allow_msdf); { - TypedArray fallback_custom; - fallback_custom.push_back(default_font_bold_msdf); + TypedArray fallback_custom = { default_font_bold_msdf }; custom_font->set_fallbacks(fallback_custom); } bold_fc_msdf->set_base_font(custom_font); } else if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) { Ref custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, font_allow_msdf); { - TypedArray fallback_custom; - fallback_custom.push_back(default_font_bold_msdf); + TypedArray fallback_custom = { default_font_bold_msdf }; custom_font->set_fallbacks(fallback_custom); } bold_fc_msdf->set_base_font(custom_font); @@ -324,8 +319,7 @@ void editor_register_fonts(const Ref &p_theme) { if (custom_font_path_source.length() > 0 && dir->file_exists(custom_font_path_source)) { Ref custom_font = load_external_font(custom_font_path_source, font_mono_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps); { - TypedArray fallback_custom; - fallback_custom.push_back(default_font_mono); + TypedArray fallback_custom = { default_font_mono }; custom_font->set_fallbacks(fallback_custom); } mono_fc->set_base_font(custom_font); diff --git a/modules/enet/enet_connection.cpp b/modules/enet/enet_connection.cpp index f66f5867368..a48ec015db7 100644 --- a/modules/enet/enet_connection.cpp +++ b/modules/enet/enet_connection.cpp @@ -320,14 +320,10 @@ Error ENetConnection::_create(ENetAddress *p_address, int p_max_peers, int p_max } Array ENetConnection::_service(int p_timeout) { - Array out; Event event; Ref peer; EventType ret = service(p_timeout, event); - out.push_back(ret); - out.push_back(event.peer); - out.push_back(event.data); - out.push_back(event.channel_id); + Array out = { ret, event.peer, event.data, event.channel_id }; if (event.packet && event.peer.is_valid()) { event.peer->_queue_packet(event.packet); } diff --git a/modules/fbx/fbx_document.cpp b/modules/fbx/fbx_document.cpp index e62639ee58b..d6e6b16f4b1 100644 --- a/modules/fbx/fbx_document.cpp +++ b/modules/fbx/fbx_document.cpp @@ -1656,8 +1656,7 @@ void FBXDocument::_generate_scene_node(Ref p_state, const GLTFNodeInde // Add the node we generated and set the owner to the scene root. p_scene_parent->add_child(current_node, true); if (current_node != p_scene_root) { - Array args; - args.append(p_scene_root); + Array args = { p_scene_root }; current_node->propagate_call(StringName("set_owner"), args); } current_node->set_transform(fbx_node->transform); @@ -1744,8 +1743,7 @@ void FBXDocument::_generate_skeleton_bone_node(Ref p_state, const GLTF // Add the node we generated and set the owner to the scene root. p_scene_parent->add_child(current_node, true); if (current_node != p_scene_root) { - Array args; - args.append(p_scene_root); + Array args = { p_scene_root }; current_node->propagate_call(StringName("set_owner"), args); } // Do not set transform here. Transform is already applied to our bone. diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index f611331b0d4..37e159baef4 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -2697,8 +2697,7 @@ void GDScriptLanguage::reload_scripts(const Array &p_scripts, bool p_soft_reload } void GDScriptLanguage::reload_tool_script(const Ref