Skip to content

Commit

Permalink
[Scene] Improve use of Ref.is_null/valid
Browse files Browse the repository at this point in the history
Use `is_null` over `!is_valid` and vice versa.
  • Loading branch information
AThousandShips committed Aug 25, 2024
1 parent bc2d0e9 commit 5058ae8
Show file tree
Hide file tree
Showing 73 changed files with 162 additions and 162 deletions.
4 changes: 2 additions & 2 deletions scene/2d/animated_sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Rect2 AnimatedSprite2D::_get_rect() const {
}

void AnimatedSprite2D::_validate_property(PropertyInfo &p_property) const {
if (!frames.is_valid()) {
if (frames.is_null()) {
return;
}

Expand Down Expand Up @@ -166,7 +166,7 @@ void AnimatedSprite2D::_validate_property(PropertyInfo &p_property) const {
void AnimatedSprite2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY: {
if (!Engine::get_singleton()->is_editor_hint() && !frames.is_null() && frames->has_animation(autoplay)) {
if (!Engine::get_singleton()->is_editor_hint() && frames.is_valid() && frames->has_animation(autoplay)) {
play(autoplay);
}
} break;
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/cpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ real_t CPUParticles2D::get_param_max(Parameter p_param) const {

static void _adjust_curve_range(const Ref<Curve> &p_curve, real_t p_min, real_t p_max) {
Ref<Curve> curve = p_curve;
if (!curve.is_valid()) {
if (curve.is_null()) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions scene/2d/light_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ Rect2 PointLight2D::_edit_get_rect() const {
}

bool PointLight2D::_edit_use_rect() const {
return !texture.is_null();
return texture.is_valid();
}
#endif

Expand Down Expand Up @@ -419,7 +419,7 @@ Vector2 PointLight2D::get_texture_offset() const {
PackedStringArray PointLight2D::get_configuration_warnings() const {
PackedStringArray warnings = Node::get_configuration_warnings();

if (!texture.is_valid()) {
if (texture.is_null()) {
warnings.push_back(RTR("A texture with the shape of the light must be supplied to the \"Texture\" property."));
}

Expand Down
2 changes: 1 addition & 1 deletion scene/2d/light_occluder_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ int LightOccluder2D::get_occluder_light_mask() const {
PackedStringArray LightOccluder2D::get_configuration_warnings() const {
PackedStringArray warnings = Node::get_configuration_warnings();

if (!occluder_polygon.is_valid()) {
if (occluder_polygon.is_null()) {
warnings.push_back(RTR("An occluder polygon must be set (or drawn) for this occluder to take effect."));
}

Expand Down
4 changes: 2 additions & 2 deletions scene/2d/navigation_region_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ RID NavigationRegion2D::get_navigation_map() const {

void NavigationRegion2D::bake_navigation_polygon(bool p_on_thread) {
ERR_FAIL_COND_MSG(!Thread::is_main_thread(), "The SceneTree can only be parsed on the main thread. Call this function from the main thread or use call_deferred().");
ERR_FAIL_COND_MSG(!navigation_polygon.is_valid(), "Baking the navigation polygon requires a valid `NavigationPolygon` resource.");
ERR_FAIL_COND_MSG(navigation_polygon.is_null(), "Baking the navigation polygon requires a valid `NavigationPolygon` resource.");

Ref<NavigationMeshSourceGeometryData2D> source_geometry_data;
source_geometry_data.instantiate();
Expand Down Expand Up @@ -295,7 +295,7 @@ PackedStringArray NavigationRegion2D::get_configuration_warnings() const {
PackedStringArray warnings = Node2D::get_configuration_warnings();

if (is_visible_in_tree() && is_inside_tree()) {
if (!navigation_polygon.is_valid()) {
if (navigation_polygon.is_null()) {
warnings.push_back(RTR("A NavigationMesh resource must be set or created for this node to work. Please set a property or draw a polygon."));
}
}
Expand Down
6 changes: 3 additions & 3 deletions scene/2d/path_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#ifdef TOOLS_ENABLED
Rect2 Path2D::_edit_get_rect() const {
if (!curve.is_valid() || curve->get_point_count() == 0) {
if (curve.is_null() || curve->get_point_count() == 0) {
return Rect2(0, 0, 0, 0);
}

Expand Down Expand Up @@ -90,7 +90,7 @@ void Path2D::_notification(int p_what) {
switch (p_what) {
// Draw the curve if path debugging is enabled.
case NOTIFICATION_DRAW: {
if (!curve.is_valid()) {
if (curve.is_null()) {
break;
}

Expand Down Expand Up @@ -221,7 +221,7 @@ void PathFollow2D::_update_transform() {
}

Ref<Curve2D> c = path->get_curve();
if (!c.is_valid()) {
if (c.is_null()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion scene/2d/physics/collision_object_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void CollisionObject2D::_notification(int p_what) {

if (!disabled || (disable_mode != DISABLE_MODE_REMOVE)) {
Ref<World2D> world_ref = get_world_2d();
ERR_FAIL_COND(!world_ref.is_valid());
ERR_FAIL_COND(world_ref.is_null());
RID space = world_ref->get_space();
if (area) {
PhysicsServer2D::get_singleton()->area_set_space(rid, space);
Expand Down
6 changes: 3 additions & 3 deletions scene/2d/physics/collision_shape_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void CollisionShape2D::_notification(int p_what) {
break;
}

if (!shape.is_valid()) {
if (shape.is_null()) {
break;
}

Expand Down Expand Up @@ -166,7 +166,7 @@ Ref<Shape2D> CollisionShape2D::get_shape() const {
}

bool CollisionShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
if (!shape.is_valid()) {
if (shape.is_null()) {
return false;
}

Expand All @@ -180,7 +180,7 @@ PackedStringArray CollisionShape2D::get_configuration_warnings() const {
if (col_object == nullptr) {
warnings.push_back(RTR("CollisionShape2D only serves to provide a collision shape to a CollisionObject2D derived node.\nPlease only use it as a child of Area2D, StaticBody2D, RigidBody2D, CharacterBody2D, etc. to give them a shape."));
}
if (!shape.is_valid()) {
if (shape.is_null()) {
warnings.push_back(RTR("A shape must be provided for CollisionShape2D to function. Please create a shape resource for it!"));
}
if (one_way_collision && Object::cast_to<Area2D>(col_object)) {
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/skeleton_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ Ref<SkeletonModificationStack2D> Skeleton2D::get_modification_stack() const {
}

void Skeleton2D::execute_modifications(real_t p_delta, int p_execution_mode) {
if (!modification_stack.is_valid()) {
if (modification_stack.is_null()) {
return;
}

Expand Down
12 changes: 6 additions & 6 deletions scene/2d/tile_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ Ref<TileMapPattern> TileMap::get_pattern(int p_layer, TypedArray<Vector2i> p_coo
}

Vector2i TileMap::map_pattern(const Vector2i &p_position_in_tilemap, const Vector2i &p_coords_in_pattern, Ref<TileMapPattern> p_pattern) {
ERR_FAIL_COND_V(!tile_set.is_valid(), Vector2i());
ERR_FAIL_COND_V(tile_set.is_null(), Vector2i());
return tile_set->map_pattern(p_position_in_tilemap, p_coords_in_pattern, p_pattern);
}

Expand Down Expand Up @@ -738,22 +738,22 @@ void TileMap::_get_property_list(List<PropertyInfo> *p_list) const {
}

Vector2 TileMap::map_to_local(const Vector2i &p_pos) const {
ERR_FAIL_COND_V(!tile_set.is_valid(), Vector2());
ERR_FAIL_COND_V(tile_set.is_null(), Vector2());
return tile_set->map_to_local(p_pos);
}

Vector2i TileMap::local_to_map(const Vector2 &p_pos) const {
ERR_FAIL_COND_V(!tile_set.is_valid(), Vector2i());
ERR_FAIL_COND_V(tile_set.is_null(), Vector2i());
return tile_set->local_to_map(p_pos);
}

bool TileMap::is_existing_neighbor(TileSet::CellNeighbor p_cell_neighbor) const {
ERR_FAIL_COND_V(!tile_set.is_valid(), false);
ERR_FAIL_COND_V(tile_set.is_null(), false);
return tile_set->is_existing_neighbor(p_cell_neighbor);
}

Vector2i TileMap::get_neighbor_cell(const Vector2i &p_coords, TileSet::CellNeighbor p_cell_neighbor) const {
ERR_FAIL_COND_V(!tile_set.is_valid(), Vector2i());
ERR_FAIL_COND_V(tile_set.is_null(), Vector2i());
return tile_set->get_neighbor_cell(p_coords, p_cell_neighbor);
}

Expand Down Expand Up @@ -819,7 +819,7 @@ void TileMap::set_texture_repeat(CanvasItem::TextureRepeat p_texture_repeat) {
}

TypedArray<Vector2i> TileMap::get_surrounding_cells(const Vector2i &p_coords) {
if (!tile_set.is_valid()) {
if (tile_set.is_null()) {
return TypedArray<Vector2i>();
}

Expand Down
14 changes: 7 additions & 7 deletions scene/2d/tile_map_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void TileMapLayer::_rendering_update(bool p_force_cleanup) {
rs->canvas_item_set_material(ci, mat->get_rid());
}
rs->canvas_item_set_parent(ci, get_canvas_item());
rs->canvas_item_set_use_parent_material(ci, !mat.is_valid());
rs->canvas_item_set_use_parent_material(ci, mat.is_null());

Transform2D xform(0, rendering_quadrant->canvas_items_position);
rs->canvas_item_set_transform(ci, xform);
Expand Down Expand Up @@ -655,7 +655,7 @@ void TileMapLayer::_rendering_draw_cell_debug(const RID &p_canvas_item, const Ve
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
if (atlas_source) {
Vector2i grid_size = atlas_source->get_atlas_grid_size();
if (!atlas_source->get_runtime_texture().is_valid() || c.get_atlas_coords().x >= grid_size.x || c.get_atlas_coords().y >= grid_size.y) {
if (atlas_source->get_runtime_texture().is_null() || c.get_atlas_coords().x >= grid_size.x || c.get_atlas_coords().y >= grid_size.y) {
// Generate a random color from the hashed values of the tiles.
Array to_hash;
to_hash.push_back(c.source_id);
Expand Down Expand Up @@ -836,7 +836,7 @@ void TileMapLayer::_physics_update_cell(CellData &r_cell_data) {
ps->body_set_state(body, PhysicsServer2D::BODY_STATE_LINEAR_VELOCITY, tile_data->get_constant_linear_velocity(tile_set_physics_layer));
ps->body_set_state(body, PhysicsServer2D::BODY_STATE_ANGULAR_VELOCITY, tile_data->get_constant_angular_velocity(tile_set_physics_layer));

if (!physics_material.is_valid()) {
if (physics_material.is_null()) {
ps->body_set_param(body, PhysicsServer2D::BODY_PARAM_BOUNCE, 0);
ps->body_set_param(body, PhysicsServer2D::BODY_PARAM_FRICTION, 1);
} else {
Expand Down Expand Up @@ -1313,7 +1313,7 @@ void TileMapLayer::_scenes_draw_cell_debug(const RID &p_canvas_item, const Vecto

TileSetScenesCollectionSource *scenes_collection_source = Object::cast_to<TileSetScenesCollectionSource>(source);
if (scenes_collection_source) {
if (!scenes_collection_source->get_scene_tile_scene(c.alternative_tile).is_valid() || scenes_collection_source->get_scene_tile_display_placeholder(c.alternative_tile)) {
if (scenes_collection_source->get_scene_tile_scene(c.alternative_tile).is_null() || scenes_collection_source->get_scene_tile_display_placeholder(c.alternative_tile)) {
// Generate a random color from the hashed values of the tiles.
Array to_hash;
to_hash.push_back(c.source_id);
Expand Down Expand Up @@ -3020,7 +3020,7 @@ HashMap<Vector2i, TileSet::CellNeighbor> TerrainConstraint::get_overlapping_coor
HashMap<Vector2i, TileSet::CellNeighbor> output;

ERR_FAIL_COND_V(is_center_bit(), output);
ERR_FAIL_COND_V(!tile_set.is_valid(), output);
ERR_FAIL_COND_V(tile_set.is_null(), output);

TileSet::TileShape shape = tile_set->get_tile_shape();
if (shape == TileSet::TILE_SHAPE_SQUARE) {
Expand Down Expand Up @@ -3124,7 +3124,7 @@ HashMap<Vector2i, TileSet::CellNeighbor> TerrainConstraint::get_overlapping_coor
}

TerrainConstraint::TerrainConstraint(Ref<TileSet> p_tile_set, const Vector2i &p_position, int p_terrain) {
ERR_FAIL_COND(!p_tile_set.is_valid());
ERR_FAIL_COND(p_tile_set.is_null());
tile_set = p_tile_set;
bit = 0;
base_cell_coords = p_position;
Expand All @@ -3133,7 +3133,7 @@ TerrainConstraint::TerrainConstraint(Ref<TileSet> p_tile_set, const Vector2i &p_

TerrainConstraint::TerrainConstraint(Ref<TileSet> p_tile_set, const Vector2i &p_position, const TileSet::CellNeighbor &p_bit, int p_terrain) {
// The way we build the constraint make it easy to detect conflicting constraints.
ERR_FAIL_COND(!p_tile_set.is_valid());
ERR_FAIL_COND(p_tile_set.is_null());
tile_set = p_tile_set;

TileSet::TileShape shape = tile_set->get_tile_shape();
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 @@ -339,7 +339,7 @@ Rect2 TouchScreenButton::_edit_get_rect() const {
}

bool TouchScreenButton::_edit_use_rect() const {
return !texture_normal.is_null();
return texture_normal.is_valid();
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion scene/3d/cpu_particles_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ real_t CPUParticles3D::get_param_max(Parameter p_param) const {

static void _adjust_curve_range(const Ref<Curve> &p_curve, real_t p_min, real_t p_max) {
Ref<Curve> curve = p_curve;
if (!curve.is_valid()) {
if (curve.is_null()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion scene/3d/gpu_particles_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ PackedStringArray GPUParticles3D::get_configuration_warnings() const {
warnings.push_back(RTR("Only one Trail mesh is supported. If you want to use more than a single mesh, a Skin is needed (see documentation)."));
}

if ((dp_count || !skin.is_null()) && (missing_trails || no_materials)) {
if ((dp_count || skin.is_valid()) && (missing_trails || no_materials)) {
warnings.push_back(RTR("Trails enabled, but one or more mesh materials are either missing or not set for trails rendering."));
}
if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
Expand Down
2 changes: 1 addition & 1 deletion scene/3d/gpu_particles_collision_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void GPUParticlesCollisionSDF3D::_find_meshes(const AABB &p_aabb, Node *p_at_nod
for (int i = 0; i < meshes.size(); i += 2) {
Transform3D mxf = meshes[i];
Ref<Mesh> mesh = meshes[i + 1];
if (!mesh.is_valid()) {
if (mesh.is_null()) {
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions scene/3d/lightmap_gi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void LightmapGI::_find_meshes_and_lights(Node *p_at_node, Vector<MeshesFound> &m
Transform3D xf = get_global_transform().affine_inverse() * s->get_global_transform();
for (int i = 0; i < bmeshes.size(); i += 2) {
Ref<Mesh> mesh = bmeshes[i];
if (!mesh.is_valid()) {
if (mesh.is_null()) {
continue;
}

Expand Down Expand Up @@ -1365,7 +1365,7 @@ void LightmapGI::_notification(int p_what) {
}

void LightmapGI::_assign_lightmaps() {
ERR_FAIL_COND(!light_data.is_valid());
ERR_FAIL_COND(light_data.is_null());

for (int i = 0; i < light_data->get_user_count(); i++) {
Node *node = get_node(light_data->get_user_path(i));
Expand All @@ -1384,7 +1384,7 @@ void LightmapGI::_assign_lightmaps() {
}

void LightmapGI::_clear_lightmaps() {
ERR_FAIL_COND(!light_data.is_valid());
ERR_FAIL_COND(light_data.is_null());
for (int i = 0; i < light_data->get_user_count(); i++) {
Node *node = get_node(light_data->get_user_path(i));
int instance_idx = light_data->get_user_sub_instance(i);
Expand Down
4 changes: 2 additions & 2 deletions scene/3d/mesh_instance_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ NodePath MeshInstance3D::get_skeleton_path() {
}

AABB MeshInstance3D::get_aabb() const {
if (!mesh.is_null()) {
if (mesh.is_valid()) {
return mesh->get_aabb();
}

Expand Down Expand Up @@ -415,7 +415,7 @@ MeshInstance3D *MeshInstance3D::create_debug_tangents_node() {
Vector<Color> colors;

Ref<Mesh> m = get_mesh();
if (!m.is_valid()) {
if (m.is_null()) {
return nullptr;
}

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

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

Expand Down Expand Up @@ -1108,7 +1108,7 @@ void NavigationAgent3D::_update_debug_path() {

Ref<StandardMaterial3D> debug_agent_path_line_material = NavigationServer3D::get_singleton()->get_debug_navigation_agent_path_line_material();
if (debug_use_custom) {
if (!debug_agent_path_line_custom_material.is_valid()) {
if (debug_agent_path_line_custom_material.is_null()) {
debug_agent_path_line_custom_material = debug_agent_path_line_material->duplicate();
}
debug_agent_path_line_custom_material->set_albedo(debug_path_custom_color);
Expand All @@ -1132,7 +1132,7 @@ void NavigationAgent3D::_update_debug_path() {

Ref<StandardMaterial3D> debug_agent_path_point_material = NavigationServer3D::get_singleton()->get_debug_navigation_agent_path_point_material();
if (debug_use_custom) {
if (!debug_agent_path_point_custom_material.is_valid()) {
if (debug_agent_path_point_custom_material.is_null()) {
debug_agent_path_point_custom_material = debug_agent_path_point_material->duplicate();
}
debug_agent_path_point_custom_material->set_albedo(debug_path_custom_color);
Expand Down
2 changes: 1 addition & 1 deletion scene/3d/navigation_link_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void NavigationLink3D::_update_debug_mesh() {
debug_instance = RenderingServer::get_singleton()->instance_create();
}

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

Expand Down
4 changes: 2 additions & 2 deletions scene/3d/navigation_obstacle_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ 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()) {
if (fake_agent_radius_debug_mesh.is_null()) {
fake_agent_radius_debug_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
}
fake_agent_radius_debug_mesh->clear_surfaces();
Expand Down Expand Up @@ -479,7 +479,7 @@ 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()) {
if (static_obstacle_debug_mesh.is_null()) {
static_obstacle_debug_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
}
static_obstacle_debug_mesh->clear_surfaces();
Expand Down
Loading

0 comments on commit 5058ae8

Please sign in to comment.