Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Integrate Ref instantiate where possible #92986

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/io/tcp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Ref<StreamPeerTCP> TCPServer::take_connection() {
return conn;
}

conn = Ref<StreamPeerTCP>(memnew(StreamPeerTCP));
conn.instantiate();
conn->accept_socket(ns, ip, port);
return conn;
}
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_help_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void EditorHelpSearch::_update_results() {
search_flags |= SEARCH_SHOW_HIERARCHY;
}

search = Ref<Runner>(memnew(Runner(results_tree, results_tree, &tree_cache, term, search_flags)));
search.instantiate(results_tree, results_tree, &tree_cache, term, search_flags);
set_process(true);
}

Expand Down
2 changes: 1 addition & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ void EditorNode::_dialog_action(String p_file) {
}

if (ml.is_null()) {
ml = Ref<MeshLibrary>(memnew(MeshLibrary));
ml.instantiate();
}

MeshLibraryEditor::update_library_file(editor_data.get_edited_scene_root(), ml, merge_with_existing_library, apply_mesh_instance_transforms);
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ void EditorSettings::create() {
extra_config->set_value("init_projects", "list", list);
}

singleton = Ref<EditorSettings>(memnew(EditorSettings));
singleton.instantiate();
singleton->set_path(config_file_path, true);
singleton->save_changed_setting = true;
singleton->_load_defaults(extra_config);
Expand Down
2 changes: 1 addition & 1 deletion editor/import/3d/editor_import_collada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres
//bleh, must ignore invalid

ERR_FAIL_COND_V(!collada.state.mesh_data_map.has(meshid), ERR_INVALID_DATA);
mesh = Ref<ImporterMesh>(memnew(ImporterMesh));
mesh.instantiate();
const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid];
String name = meshdata.name;
if (name.is_empty()) {
Expand Down
2 changes: 1 addition & 1 deletion editor/import/3d/resource_importer_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3029,7 +3029,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
if (!scr.is_valid()) {
EditorNode::add_io_error(TTR("Couldn't load post-import script:") + " " + post_import_script_path);
} else {
post_import_script = Ref<EditorScenePostImport>(memnew(EditorScenePostImport));
post_import_script.instantiate();
post_import_script->set_script(scr);
if (!post_import_script->get_script_instance()) {
EditorNode::add_io_error(TTR("Invalid/broken script for post-import (check console):") + " " + post_import_script_path);
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5612,7 +5612,7 @@ CanvasItemEditor::CanvasItemEditor() {
snap_dialog->connect("confirmed", callable_mp(this, &CanvasItemEditor::_snap_changed));
add_child(snap_dialog);

select_sb = Ref<StyleBoxTexture>(memnew(StyleBoxTexture));
select_sb.instantiate();

selection_menu = memnew(PopupMenu);
add_child(selection_menu);
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/gizmos/marker_3d_gizmo_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "scene/3d/marker_3d.h"

Marker3DGizmoPlugin::Marker3DGizmoPlugin() {
pos3d_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
pos3d_mesh.instantiate();

Vector<Vector3> cursor_points;
Vector<Color> cursor_colors;
Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/light_occluder_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

Ref<OccluderPolygon2D> LightOccluder2DEditor::_ensure_occluder() const {
Ref<OccluderPolygon2D> occluder = node->get_occluder_polygon();
if (!occluder.is_valid()) {
occluder = Ref<OccluderPolygon2D>(memnew(OccluderPolygon2D));
if (occluder.is_null()) {
occluder.instantiate();
node->set_occluder_polygon(occluder);
}
return occluder;
Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/navigation_obstacle_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,15 @@ NavigationObstacle3DEditor::NavigationObstacle3DEditor() {
point_lines_meshinstance->set_mesh(point_lines_mesh);
point_lines_meshinstance->set_transform(Transform3D(Basis(), Vector3(0, 0, 0.00001)));

line_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
line_material.instantiate();
line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
line_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
line_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
line_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
line_material->set_albedo(Color(1, 1, 1));

handle_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
handle_material.instantiate();
handle_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
handle_material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true);
handle_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/navigation_polygon_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

Ref<NavigationPolygon> NavigationPolygonEditor::_ensure_navpoly() const {
Ref<NavigationPolygon> navpoly = node->get_navigation_polygon();
if (!navpoly.is_valid()) {
navpoly = Ref<NavigationPolygon>(memnew(NavigationPolygon));
if (navpoly.is_null()) {
navpoly.instantiate();
node->set_navigation_polygon(navpoly);
}
return navpoly;
Expand Down
16 changes: 8 additions & 8 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6845,12 +6845,12 @@ void fragment() {

col.a = EDITOR_GET("editors/3d/manipulator_gizmo_opacity");

move_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
move_plane_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
rotate_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
scale_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
scale_plane_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
axis_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
move_gizmo[i].instantiate();
move_plane_gizmo[i].instantiate();
rotate_gizmo[i].instantiate();
scale_gizmo[i].instantiate();
scale_plane_gizmo[i].instantiate();
axis_gizmo[i].instantiate();

Ref<StandardMaterial3D> mat = memnew(StandardMaterial3D);
mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
Expand Down Expand Up @@ -7081,7 +7081,7 @@ void fragment() {
border_mat->set_shader(border_shader);
border_mat->set_shader_parameter("albedo", Color(0.75, 0.75, 0.75, col.a / 3.0));

rotate_gizmo[3] = Ref<ArrayMesh>(memnew(ArrayMesh));
rotate_gizmo[3].instantiate();
rotate_gizmo[3]->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arrays);
rotate_gizmo[3]->surface_set_material(0, border_mat);
}
Expand Down Expand Up @@ -8431,7 +8431,7 @@ Node3DEditor::Node3DEditor() {
gizmo.visible = true;
gizmo.scale = 1.0;

viewport_environment = Ref<Environment>(memnew(Environment));
viewport_environment.instantiate();
VBoxContainer *vbc = this;

custom_camera = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/path_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ Ref<EditorNode3DGizmo> Path3DGizmoPlugin::create_gizmo(Node3D *p_spatial) {

Path3D *path = Object::cast_to<Path3D>(p_spatial);
if (path) {
ref = Ref<Path3DGizmo>(memnew(Path3DGizmo(path, disk_size)));
ref.instantiate(path, disk_size);
}

return ref;
Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/polygon_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,15 +554,15 @@ Polygon3DEditor::Polygon3DEditor() {
imgeom->set_mesh(imesh);
imgeom->set_transform(Transform3D(Basis(), Vector3(0, 0, 0.00001)));

line_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
line_material.instantiate();
line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
line_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
line_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
line_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
line_material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
line_material->set_albedo(Color(1, 1, 1));

handle_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
handle_material.instantiate();
handle_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
handle_material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true);
handle_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
Expand Down
10 changes: 5 additions & 5 deletions editor/plugins/skeleton_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,8 +904,8 @@ Skeleton3DEditor::Skeleton3DEditor(EditorInspectorPluginSkeleton *e_plugin, Skel
singleton = this;

// Handle.
handle_material = Ref<ShaderMaterial>(memnew(ShaderMaterial));
handle_shader = Ref<Shader>(memnew(Shader));
handle_material.instantiate();
handle_shader.instantiate();
handle_shader->set_code(R"(
// Skeleton 3D gizmo handle shader.

Expand Down Expand Up @@ -1181,15 +1181,15 @@ int Skeleton3DEditor::get_selected_bone() const {
}

Skeleton3DGizmoPlugin::Skeleton3DGizmoPlugin() {
unselected_mat = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
unselected_mat.instantiate();
unselected_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
unselected_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
unselected_mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
unselected_mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
unselected_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);

selected_mat = Ref<ShaderMaterial>(memnew(ShaderMaterial));
selected_sh = Ref<Shader>(memnew(Shader));
selected_mat.instantiate();
selected_sh.instantiate();
selected_sh->set_code(R"(
// Skeleton 3D gizmo bones shader.

Expand Down
2 changes: 1 addition & 1 deletion modules/enet/enet_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Ref<ENetPacketPeer> ENetConnection::connect_to_host(const String &p_address, int
if (peer == nullptr) {
return nullptr;
}
out = Ref<ENetPacketPeer>(memnew(ENetPacketPeer(peer)));
out.instantiate(peer);
peers.push_back(out);
return out;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/gltf/gltf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static Ref<ImporterMesh> _mesh_to_importer_mesh(Ref<Mesh> p_mesh) {
mat_name = mat->get_name();
} else {
// Assign default material when no material is assigned.
mat = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
mat.instantiate();
}
importer_mesh->add_surface(p_mesh->surface_get_primitive_type(surface_i),
array, p_mesh->surface_get_blend_shape_arrays(surface_i), p_mesh->surface_get_lods(surface_i), mat,
Expand Down Expand Up @@ -5323,7 +5323,7 @@ void GLTFDocument::_convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeInd
mat_name = mat->get_name();
} else {
// Assign default material when no material is assigned.
mat = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
mat.instantiate();
}

mesh->add_surface(csg_mesh->surface_get_primitive_type(surface_i),
Expand Down
8 changes: 4 additions & 4 deletions modules/gridmap/grid_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,8 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) {
if (!g.navigation_debug_edge_connections_instance.is_valid()) {
g.navigation_debug_edge_connections_instance = RenderingServer::get_singleton()->instance_create();
}
if (!g.navigation_debug_edge_connections_mesh.is_valid()) {
g.navigation_debug_edge_connections_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
if (g.navigation_debug_edge_connections_mesh.is_null()) {
g.navigation_debug_edge_connections_mesh.instantiate();
}

_update_octant_navigation_debug_edge_connections_mesh(p_key);
Expand Down Expand Up @@ -1386,8 +1386,8 @@ void GridMap::_update_octant_navigation_debug_edge_connections_mesh(const Octant
g.navigation_debug_edge_connections_instance = RenderingServer::get_singleton()->instance_create();
}

if (!g.navigation_debug_edge_connections_mesh.is_valid()) {
g.navigation_debug_edge_connections_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
if (g.navigation_debug_edge_connections_mesh.is_null()) {
g.navigation_debug_edge_connections_mesh.instantiate();
}

g.navigation_debug_edge_connections_mesh->clear_surfaces();
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/csharp_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,7 @@ Ref<Resource> ResourceFormatLoaderCSharpScript::load(const String &p_path, const
GDMonoCache::managed_callbacks.ScriptManagerBridge_GetOrCreateScriptBridgeForPath(&p_path, &scr);
ERR_FAIL_NULL_V_MSG(scr, Ref<Resource>(), "Could not create C# script '" + real_path + "'.");
} else {
scr = Ref<CSharpScript>(memnew(CSharpScript));
scr.instantiate();
}

#if defined(DEBUG_ENABLED) || defined(TOOLS_ENABLED)
Expand Down
6 changes: 3 additions & 3 deletions modules/multiplayer/scene_multiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,9 @@ void SceneMultiplayer::_bind_methods() {

SceneMultiplayer::SceneMultiplayer() {
relay_buffer.instantiate();
cache = Ref<SceneCacheInterface>(memnew(SceneCacheInterface(this)));
replicator = Ref<SceneReplicationInterface>(memnew(SceneReplicationInterface(this, cache.ptr())));
rpc = Ref<SceneRPCInterface>(memnew(SceneRPCInterface(this, cache.ptr(), replicator.ptr())));
cache.instantiate(this);
replicator.instantiate(this, cache.ptr());
rpc.instantiate(this, cache.ptr(), replicator.ptr());
set_multiplayer_peer(Ref<OfflineMultiplayerPeer>(memnew(OfflineMultiplayerPeer)));
}

Expand Down
2 changes: 1 addition & 1 deletion modules/theora/video_stream_theora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ void VideoStreamPlaybackTheora::_streaming_thread(void *ud) {
#endif

VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() {
texture = Ref<ImageTexture>(memnew(ImageTexture));
texture.instantiate();

#ifdef THEORA_USE_THREAD_STREAMING
int rb_power = nearest_shift(RB_SIZE_KB * 1024);
Expand Down
2 changes: 1 addition & 1 deletion platform/ios/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref<EditorExpor
}

if (splash.is_null()) {
splash = Ref<Image>(memnew(Image(boot_splash_png)));
splash.instantiate(boot_splash_png);
}

// Using same image for both @2x and @3x
Expand Down
8 changes: 4 additions & 4 deletions platform/macos/export/codesign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1381,14 +1381,14 @@ Error CodeSign::_codesign_file(bool p_use_hardened_runtime, bool p_force, const
r_error_msg = TTR("Invalid entitlements file.");
ERR_FAIL_V_MSG(FAILED, "CodeSign: Invalid entitlements file.");
}
cet = Ref<CodeSignEntitlementsText>(memnew(CodeSignEntitlementsText(entitlements)));
ceb = Ref<CodeSignEntitlementsBinary>(memnew(CodeSignEntitlementsBinary(entitlements)));
cet.instantiate(entitlements);
ceb.instantiate(entitlements);
}

print_verbose("CodeSign: Generating requirements...");
Ref<CodeSignRequirements> rq;
String team_id = "";
rq = Ref<CodeSignRequirements>(memnew(CodeSignRequirements()));
rq.instantiate();

// Sign executables.
for (int i = 0; i < files_to_sign.size(); i++) {
Expand Down Expand Up @@ -1487,7 +1487,7 @@ Error CodeSign::_codesign_file(bool p_use_hardened_runtime, bool p_force, const

print_verbose("CodeSign: Generating signature...");
Ref<CodeSignSignature> cs;
cs = Ref<CodeSignSignature>(memnew(CodeSignSignature()));
cs.instantiate();

print_verbose("CodeSign: Writing signature superblob...");
// Write signature data to the executable.
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/touch_screen_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,6 @@ void TouchScreenButton::_bind_methods() {
}

TouchScreenButton::TouchScreenButton() {
unit_rect = Ref<RectangleShape2D>(memnew(RectangleShape2D));
unit_rect.instantiate();
unit_rect->set_size(Vector2(1, 1));
}
2 changes: 1 addition & 1 deletion scene/3d/label_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ Ref<TriangleMesh> Label3D::generate_triangle_mesh() const {
facesw[j] = vtx;
}

triangle_mesh = Ref<TriangleMesh>(memnew(TriangleMesh));
triangle_mesh.instantiate();
triangle_mesh->create(faces);

return triangle_mesh;
Expand Down
4 changes: 2 additions & 2 deletions scene/3d/navigation_agent_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,8 @@ void NavigationAgent3D::_update_debug_path() {
debug_path_instance = RenderingServer::get_singleton()->instance_create();
}

if (!debug_path_mesh.is_valid()) {
debug_path_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
if (debug_path_mesh.is_null()) {
debug_path_mesh.instantiate();
}

debug_path_mesh->clear_surfaces();
Expand Down
4 changes: 2 additions & 2 deletions scene/3d/navigation_link_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ void NavigationLink3D::_update_debug_mesh() {
debug_instance = RenderingServer::get_singleton()->instance_create();
}

if (!debug_mesh.is_valid()) {
debug_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
if (debug_mesh.is_null()) {
debug_mesh.instantiate();
}

RID nav_map = get_world_3d()->get_navigation_map();
Expand Down
8 changes: 4 additions & 4 deletions scene/3d/navigation_obstacle_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ void NavigationObstacle3D::_update_fake_agent_radius_debug() {
if (!fake_agent_radius_debug_instance.is_valid()) {
fake_agent_radius_debug_instance = RenderingServer::get_singleton()->instance_create();
}
if (!fake_agent_radius_debug_mesh.is_valid()) {
fake_agent_radius_debug_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
if (fake_agent_radius_debug_mesh.is_null()) {
fake_agent_radius_debug_mesh.instantiate();
}
fake_agent_radius_debug_mesh->clear_surfaces();

Expand Down Expand Up @@ -479,8 +479,8 @@ void NavigationObstacle3D::_update_static_obstacle_debug() {
if (!static_obstacle_debug_instance.is_valid()) {
static_obstacle_debug_instance = RenderingServer::get_singleton()->instance_create();
}
if (!static_obstacle_debug_mesh.is_valid()) {
static_obstacle_debug_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
if (static_obstacle_debug_mesh.is_null()) {
static_obstacle_debug_mesh.instantiate();
}
static_obstacle_debug_mesh->clear_surfaces();

Expand Down
Loading
Loading