Skip to content

Commit

Permalink
Merge pull request #31213 from KoBeWi/explain_scenes
Browse files Browse the repository at this point in the history
Replace ERR_EXPLAIN in scene/* code
  • Loading branch information
akien-mga authored Aug 9, 2019
2 parents 7bc984c + af5e0ff commit 7bb2215
Show file tree
Hide file tree
Showing 36 changed files with 157 additions and 473 deletions.
5 changes: 2 additions & 3 deletions scene/2d/animated_sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,8 @@ void AnimatedSprite::_reset_timeout() {

void AnimatedSprite::set_animation(const StringName &p_animation) {

ERR_EXPLAIN(vformat("There is no animation with name '%s'.", p_animation));
ERR_FAIL_COND(frames == NULL);
ERR_FAIL_COND(frames->get_animation_names().find(p_animation) == -1);
ERR_FAIL_COND_MSG(frames == NULL, vformat("There is no animation with name '%s'.", p_animation));
ERR_FAIL_COND_MSG(frames->get_animation_names().find(p_animation) == -1, vformat("There is no animation with name '%s'.", p_animation));

if (animation == p_animation)
return;
Expand Down
15 changes: 3 additions & 12 deletions scene/2d/area_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,7 @@ void Area2D::_area_inout(int p_status, const RID &p_area, int p_instance, int p_

void Area2D::_clear_monitoring() {

if (locked) {
ERR_EXPLAIN("This function can't be used during the in/out signal.");
}
ERR_FAIL_COND(locked);
ERR_FAIL_COND_MSG(locked, "This function can't be used during the in/out signal.");

{
Map<ObjectID, BodyState> bmcopy = body_map;
Expand Down Expand Up @@ -401,10 +398,7 @@ void Area2D::set_monitoring(bool p_enable) {

if (p_enable == monitoring)
return;
if (locked) {
ERR_EXPLAIN("Function blocked during in/out signal. Use set_deferred(\"monitoring\",true/false)");
}
ERR_FAIL_COND(locked);
ERR_FAIL_COND_MSG(locked, "Function blocked during in/out signal. Use set_deferred(\"monitoring\", true/false).");

monitoring = p_enable;

Expand All @@ -427,10 +421,7 @@ bool Area2D::is_monitoring() const {

void Area2D::set_monitorable(bool p_enable) {

if (locked || (is_inside_tree() && Physics2DServer::get_singleton()->is_flushing_queries())) {
ERR_EXPLAIN("Function blocked during in/out signal. Use set_deferred(\"monitorable\",true/false)");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(locked || (is_inside_tree() && Physics2DServer::get_singleton()->is_flushing_queries()), "Function blocked during in/out signal. Use set_deferred(\"monitorable\", true/false).");

if (p_enable == monitorable)
return;
Expand Down
90 changes: 18 additions & 72 deletions scene/2d/canvas_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,20 +707,14 @@ void CanvasItem::item_rect_changed(bool p_size_changed) {

void CanvasItem::draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width, bool p_antialiased) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

VisualServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width, p_antialiased);
}

void CanvasItem::draw_polyline(const Vector<Point2> &p_points, const Color &p_color, float p_width, bool p_antialiased) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

Vector<Color> colors;
colors.push_back(p_color);
Expand All @@ -729,20 +723,14 @@ void CanvasItem::draw_polyline(const Vector<Point2> &p_points, const Color &p_co

void CanvasItem::draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width, bool p_antialiased) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

VisualServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, p_colors, p_width, p_antialiased);
}

void CanvasItem::draw_multiline(const Vector<Point2> &p_points, const Color &p_color, float p_width, bool p_antialiased) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

Vector<Color> colors;
colors.push_back(p_color);
Expand All @@ -751,20 +739,14 @@ void CanvasItem::draw_multiline(const Vector<Point2> &p_points, const Color &p_c

void CanvasItem::draw_multiline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width, bool p_antialiased) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

VisualServer::get_singleton()->canvas_item_add_multiline(canvas_item, p_points, p_colors, p_width, p_antialiased);
}

void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled, float p_width, bool p_antialiased) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

if (p_filled) {
if (p_width != 1.0) {
Expand Down Expand Up @@ -819,20 +801,14 @@ void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_fil

void CanvasItem::draw_circle(const Point2 &p_pos, float p_radius, const Color &p_color) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

VisualServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius, p_color);
}

void CanvasItem::draw_texture(const Ref<Texture> &p_texture, const Point2 &p_pos, const Color &p_modulate, const Ref<Texture> &p_normal_map) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

ERR_FAIL_COND(p_texture.is_null());

Expand All @@ -841,40 +817,28 @@ void CanvasItem::draw_texture(const Ref<Texture> &p_texture, const Point2 &p_pos

void CanvasItem::draw_texture_rect(const Ref<Texture> &p_texture, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

ERR_FAIL_COND(p_texture.is_null());
p_texture->draw_rect(canvas_item, p_rect, p_tile, p_modulate, p_transpose, p_normal_map);
}
void CanvasItem::draw_texture_rect_region(const Ref<Texture> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map, bool p_clip_uv) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL_COND(p_texture.is_null());
p_texture->draw_rect_region(canvas_item, p_rect, p_src_rect, p_modulate, p_transpose, p_normal_map, p_clip_uv);
}

void CanvasItem::draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

ERR_FAIL_COND(p_style_box.is_null());

p_style_box->draw(canvas_item, p_rect);
}
void CanvasItem::draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture> p_texture, float p_width, const Ref<Texture> &p_normal_map) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
RID rid_normal = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
Expand All @@ -883,10 +847,7 @@ void CanvasItem::draw_primitive(const Vector<Point2> &p_points, const Vector<Col
}
void CanvasItem::draw_set_transform(const Point2 &p_offset, float p_rot, const Size2 &p_scale) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

Transform2D xform(p_rot, p_offset);
xform.scale_basis(p_scale);
Expand All @@ -895,20 +856,14 @@ void CanvasItem::draw_set_transform(const Point2 &p_offset, float p_rot, const S

void CanvasItem::draw_set_transform_matrix(const Transform2D &p_matrix) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item, p_matrix);
}

void CanvasItem::draw_polygon(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture> p_texture, const Ref<Texture> &p_normal_map, bool p_antialiased) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
RID rid_normal = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
Expand All @@ -918,10 +873,7 @@ void CanvasItem::draw_polygon(const Vector<Point2> &p_points, const Vector<Color

void CanvasItem::draw_colored_polygon(const Vector<Point2> &p_points, const Color &p_color, const Vector<Point2> &p_uvs, Ref<Texture> p_texture, const Ref<Texture> &p_normal_map, bool p_antialiased) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

Vector<Color> colors;
colors.push_back(p_color);
Expand Down Expand Up @@ -949,21 +901,15 @@ void CanvasItem::draw_multimesh(const Ref<MultiMesh> &p_multimesh, const Ref<Tex

void CanvasItem::draw_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, const Color &p_modulate, int p_clip_w) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

ERR_FAIL_COND(p_font.is_null());
p_font->draw(canvas_item, p_pos, p_text, p_modulate, p_clip_w);
}

float CanvasItem::draw_char(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, const String &p_next, const Color &p_modulate) {

if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL_V(0);
}
ERR_FAIL_COND_V_MSG(!drawing, 0, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");

ERR_FAIL_COND_V(p_char.length() != 1, 0);
ERR_FAIL_COND_V(p_font.is_null(), 0);
Expand Down
39 changes: 11 additions & 28 deletions scene/2d/physics_body_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,15 @@ void PhysicsBody2D::add_collision_exception_with(Node *p_node) {

ERR_FAIL_NULL(p_node);
PhysicsBody2D *physics_body = Object::cast_to<PhysicsBody2D>(p_node);
if (!physics_body) {
ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type");
}
ERR_FAIL_COND(!physics_body);
ERR_FAIL_COND_MSG(!physics_body, "Collision exception only works between two objects of PhysicsBody type.");
Physics2DServer::get_singleton()->body_add_collision_exception(get_rid(), physics_body->get_rid());
}

void PhysicsBody2D::remove_collision_exception_with(Node *p_node) {

ERR_FAIL_NULL(p_node);
PhysicsBody2D *physics_body = Object::cast_to<PhysicsBody2D>(p_node);
if (!physics_body) {
ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type");
}
ERR_FAIL_COND(!physics_body);
ERR_FAIL_COND_MSG(!physics_body, "Collision exception only works between two objects of PhysicsBody type.");
Physics2DServer::get_singleton()->body_remove_collision_exception(get_rid(), physics_body->get_rid());
}

Expand Down Expand Up @@ -203,8 +197,7 @@ void StaticBody2D::set_friction(real_t p_friction) {
return;
}

ERR_EXPLAIN("The method set_friction has been deprecated and will be removed in the future, use physics material instead.");
WARN_DEPRECATED;
WARN_DEPRECATED_MSG("The method set_friction has been deprecated and will be removed in the future, use physics material instead.");

ERR_FAIL_COND(p_friction < 0 || p_friction > 1);

Expand All @@ -217,8 +210,7 @@ void StaticBody2D::set_friction(real_t p_friction) {

real_t StaticBody2D::get_friction() const {

ERR_EXPLAIN("The method get_friction has been deprecated and will be removed in the future, use physics material instead.");
WARN_DEPRECATED;
WARN_DEPRECATED_MSG("The method get_friction has been deprecated and will be removed in the future, use physics material instead.");

if (physics_material_override.is_null()) {
return 1;
Expand All @@ -233,8 +225,7 @@ void StaticBody2D::set_bounce(real_t p_bounce) {
return;
}

ERR_EXPLAIN("The method set_bounce has been deprecated and will be removed in the future, use physics material instead.");
WARN_DEPRECATED;
WARN_DEPRECATED_MSG("The method set_bounce has been deprecated and will be removed in the future, use physics material instead.");

ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1);

Expand All @@ -247,8 +238,7 @@ void StaticBody2D::set_bounce(real_t p_bounce) {

real_t StaticBody2D::get_bounce() const {

ERR_EXPLAIN("The method get_bounce has been deprecated and will be removed in the future, use physics material instead.");
WARN_DEPRECATED;
WARN_DEPRECATED_MSG("The method get_bounce has been deprecated and will be removed in the future, use physics material instead.");

if (physics_material_override.is_null()) {
return 0;
Expand Down Expand Up @@ -630,8 +620,7 @@ void RigidBody2D::set_friction(real_t p_friction) {
return;
}

ERR_EXPLAIN("The method set_friction has been deprecated and will be removed in the future, use physics material instead.");
WARN_DEPRECATED;
WARN_DEPRECATED_MSG("The method set_friction has been deprecated and will be removed in the future, use physics material instead.");

ERR_FAIL_COND(p_friction < 0 || p_friction > 1);

Expand All @@ -643,8 +632,7 @@ void RigidBody2D::set_friction(real_t p_friction) {
}
real_t RigidBody2D::get_friction() const {

ERR_EXPLAIN("The method get_friction has been deprecated and will be removed in the future, use physics material instead.");
WARN_DEPRECATED;
WARN_DEPRECATED_MSG("The method get_friction has been deprecated and will be removed in the future, use physics material instead.");

if (physics_material_override.is_null()) {
return 1;
Expand All @@ -659,8 +647,7 @@ void RigidBody2D::set_bounce(real_t p_bounce) {
return;
}

ERR_EXPLAIN("The method set_bounce has been deprecated and will be removed in the future, use physics material instead.");
WARN_DEPRECATED;
WARN_DEPRECATED_MSG("The method set_bounce has been deprecated and will be removed in the future, use physics material instead.");

ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1);

Expand All @@ -672,8 +659,7 @@ void RigidBody2D::set_bounce(real_t p_bounce) {
}
real_t RigidBody2D::get_bounce() const {

ERR_EXPLAIN("The method get_bounce has been deprecated and will be removed in the future, use physics material instead.");
WARN_DEPRECATED;
WARN_DEPRECATED_MSG("The method get_bounce has been deprecated and will be removed in the future, use physics material instead.");

if (physics_material_override.is_null()) {
return 0;
Expand Down Expand Up @@ -905,10 +891,7 @@ void RigidBody2D::set_contact_monitor(bool p_enabled) {

if (!p_enabled) {

if (contact_monitor->locked) {
ERR_EXPLAIN("Can't disable contact monitoring during in/out callback. Use call_deferred(\"set_contact_monitor\",false) instead");
}
ERR_FAIL_COND(contact_monitor->locked);
ERR_FAIL_COND_MSG(contact_monitor->locked, "Can't disable contact monitoring during in/out callback. Use call_deferred(\"set_contact_monitor\", false) instead.");

for (Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) {

Expand Down
Loading

0 comments on commit 7bb2215

Please sign in to comment.