diff options
Diffstat (limited to 'scene/2d')
65 files changed, 0 insertions, 1303 deletions
diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp index fc34f967ce..842740aa5e 100644 --- a/scene/2d/animated_sprite_2d.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -103,7 +103,6 @@ Rect2 AnimatedSprite2D::_get_rect() const { } void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture2D> &p_frame, int p_at_pos) { - Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); @@ -123,7 +122,6 @@ int SpriteFrames::get_frame_count(const StringName &p_anim) const { } void SpriteFrames::remove_frame(const StringName &p_anim, int p_idx) { - Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); @@ -131,7 +129,6 @@ void SpriteFrames::remove_frame(const StringName &p_anim, int p_idx) { emit_changed(); } void SpriteFrames::clear(const StringName &p_anim) { - Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); @@ -140,13 +137,11 @@ void SpriteFrames::clear(const StringName &p_anim) { } void SpriteFrames::clear_all() { - animations.clear(); add_animation("default"); } void SpriteFrames::add_animation(const StringName &p_anim) { - ERR_FAIL_COND_MSG(animations.has(p_anim), "SpriteFrames already has animation '" + p_anim + "'."); animations[p_anim] = Anim(); @@ -155,16 +150,13 @@ void SpriteFrames::add_animation(const StringName &p_anim) { } bool SpriteFrames::has_animation(const StringName &p_anim) const { - return animations.has(p_anim); } void SpriteFrames::remove_animation(const StringName &p_anim) { - animations.erase(p_anim); } void SpriteFrames::rename_animation(const StringName &p_prev, const StringName &p_next) { - ERR_FAIL_COND_MSG(!animations.has(p_prev), "SpriteFrames doesn't have animation '" + String(p_prev) + "'."); ERR_FAIL_COND_MSG(animations.has(p_next), "Animation '" + String(p_next) + "' already exists."); @@ -176,12 +168,10 @@ void SpriteFrames::rename_animation(const StringName &p_prev, const StringName & } Vector<String> SpriteFrames::_get_animation_list() const { - Vector<String> ret; List<StringName> al; get_animation_list(&al); for (List<StringName>::Element *E = al.front(); E; E = E->next()) { - ret.push_back(E->get()); } @@ -189,14 +179,12 @@ Vector<String> SpriteFrames::_get_animation_list() const { } void SpriteFrames::get_animation_list(List<StringName> *r_animations) const { - for (const Map<StringName, Anim>::Element *E = animations.front(); E; E = E->next()) { r_animations->push_back(E->key()); } } Vector<String> SpriteFrames::get_animation_names() const { - Vector<String> names; for (const Map<StringName, Anim>::Element *E = animations.front(); E; E = E->next()) { names.push_back(E->key()); @@ -206,14 +194,12 @@ Vector<String> SpriteFrames::get_animation_names() const { } void SpriteFrames::set_animation_speed(const StringName &p_anim, float p_fps) { - ERR_FAIL_COND_MSG(p_fps < 0, "Animation speed cannot be negative (" + itos(p_fps) + ")."); Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); E->get().speed = p_fps; } float SpriteFrames::get_animation_speed(const StringName &p_anim) const { - const Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_V_MSG(!E, 0, "Animation '" + String(p_anim) + "' doesn't exist."); return E->get().speed; @@ -231,7 +217,6 @@ bool SpriteFrames::get_animation_loop(const StringName &p_anim) const { } void SpriteFrames::_set_frames(const Array &p_frames) { - clear_all(); Map<StringName, Anim>::Element *E = animations.find(SceneStringNames::get_singleton()->_default); ERR_FAIL_COND(!E); @@ -241,12 +226,10 @@ void SpriteFrames::_set_frames(const Array &p_frames) { E->get().frames.write[i] = p_frames[i]; } Array SpriteFrames::_get_frames() const { - return Array(); } Array SpriteFrames::_get_animations() const { - Array anims; for (Map<StringName, Anim>::Element *E = animations.front(); E; E = E->next()) { Dictionary d; @@ -264,10 +247,8 @@ Array SpriteFrames::_get_animations() const { return anims; } void SpriteFrames::_set_animations(const Array &p_animations) { - animations.clear(); for (int i = 0; i < p_animations.size(); i++) { - Dictionary d = p_animations[i]; ERR_CONTINUE(!d.has("name")); @@ -280,7 +261,6 @@ void SpriteFrames::_set_animations(const Array &p_animations) { anim.loop = d["loop"]; Array frames = d["frames"]; for (int j = 0; j < frames.size(); j++) { - RES res = frames[j]; anim.frames.push_back(res); } @@ -290,7 +270,6 @@ void SpriteFrames::_set_animations(const Array &p_animations) { } void SpriteFrames::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_animation", "anim"), &SpriteFrames::add_animation); ClassDB::bind_method(D_METHOD("has_animation", "anim"), &SpriteFrames::has_animation); ClassDB::bind_method(D_METHOD("remove_animation", "anim"), &SpriteFrames::remove_animation); @@ -324,16 +303,13 @@ void SpriteFrames::_bind_methods() { } SpriteFrames::SpriteFrames() { - add_animation(SceneStringNames::get_singleton()->_default); } void AnimatedSprite2D::_validate_property(PropertyInfo &property) const { - if (!frames.is_valid()) return; if (property.name == "animation") { - property.hint = PROPERTY_HINT_ENUM; List<StringName> names; frames->get_animation_list(&names); @@ -371,10 +347,8 @@ void AnimatedSprite2D::_validate_property(PropertyInfo &property) const { } void AnimatedSprite2D::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_INTERNAL_PROCESS: { - if (frames.is_null()) return; if (!frames->has_animation(animation)) @@ -389,9 +363,7 @@ void AnimatedSprite2D::_notification(int p_what) { float remaining = get_process_delta_time(); while (remaining) { - if (timeout <= 0) { - timeout = _get_frame_duration(); int fc = frames->get_frame_count(animation); @@ -433,7 +405,6 @@ void AnimatedSprite2D::_notification(int p_what) { } break; case NOTIFICATION_DRAW: { - if (frames.is_null()) return; if (frame < 0) @@ -473,7 +444,6 @@ void AnimatedSprite2D::_notification(int p_what) { } void AnimatedSprite2D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) { - if (frames.is_valid()) frames->disconnect("changed", callable_mp(this, &AnimatedSprite2D::_res_changed)); frames = p_frames; @@ -493,12 +463,10 @@ void AnimatedSprite2D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) { } Ref<SpriteFrames> AnimatedSprite2D::get_sprite_frames() const { - return frames; } void AnimatedSprite2D::set_frame(int p_frame) { - if (!frames.is_valid()) { return; } @@ -522,12 +490,10 @@ void AnimatedSprite2D::set_frame(int p_frame) { emit_signal(SceneStringNames::get_singleton()->frame_changed); } int AnimatedSprite2D::get_frame() const { - return frame; } void AnimatedSprite2D::set_speed_scale(float p_speed_scale) { - float elapsed = _get_frame_duration() - timeout; speed_scale = MAX(p_speed_scale, 0.0f); @@ -538,56 +504,46 @@ void AnimatedSprite2D::set_speed_scale(float p_speed_scale) { } float AnimatedSprite2D::get_speed_scale() const { - return speed_scale; } void AnimatedSprite2D::set_centered(bool p_center) { - centered = p_center; update(); item_rect_changed(); } bool AnimatedSprite2D::is_centered() const { - return centered; } void AnimatedSprite2D::set_offset(const Point2 &p_offset) { - offset = p_offset; update(); item_rect_changed(); _change_notify("offset"); } Point2 AnimatedSprite2D::get_offset() const { - return offset; } void AnimatedSprite2D::set_flip_h(bool p_flip) { - hflip = p_flip; update(); } bool AnimatedSprite2D::is_flipped_h() const { - return hflip; } void AnimatedSprite2D::set_flip_v(bool p_flip) { - vflip = p_flip; update(); } bool AnimatedSprite2D::is_flipped_v() const { - return vflip; } void AnimatedSprite2D::_res_changed() { - set_frame(frame); _change_notify("frame"); _change_notify("animation"); @@ -595,7 +551,6 @@ void AnimatedSprite2D::_res_changed() { } void AnimatedSprite2D::_set_playing(bool p_playing) { - if (playing == p_playing) return; playing = p_playing; @@ -604,12 +559,10 @@ void AnimatedSprite2D::_set_playing(bool p_playing) { } bool AnimatedSprite2D::_is_playing() const { - return playing; } void AnimatedSprite2D::play(const StringName &p_animation, const bool p_backwards) { - backwards = p_backwards; if (p_animation) { @@ -622,12 +575,10 @@ void AnimatedSprite2D::play(const StringName &p_animation, const bool p_backward } void AnimatedSprite2D::stop() { - _set_playing(false); } bool AnimatedSprite2D::is_playing() const { - return playing; } @@ -642,7 +593,6 @@ float AnimatedSprite2D::_get_frame_duration() { } void AnimatedSprite2D::_reset_timeout() { - if (!playing) return; @@ -651,7 +601,6 @@ void AnimatedSprite2D::_reset_timeout() { } void AnimatedSprite2D::set_animation(const StringName &p_animation) { - ERR_FAIL_COND_MSG(frames == nullptr, 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)); @@ -665,12 +614,10 @@ void AnimatedSprite2D::set_animation(const StringName &p_animation) { update(); } StringName AnimatedSprite2D::get_animation() const { - return animation; } String AnimatedSprite2D::get_configuration_warning() const { - if (frames.is_null()) { return TTR("A SpriteFrames resource must be created or set in the \"Frames\" property in order for AnimatedSprite to display frames."); } @@ -697,7 +644,6 @@ float AnimatedSprite2D::get_shininess() const { } void AnimatedSprite2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_sprite_frames", "sprite_frames"), &AnimatedSprite2D::set_sprite_frames); ClassDB::bind_method(D_METHOD("get_sprite_frames"), &AnimatedSprite2D::get_sprite_frames); @@ -755,7 +701,6 @@ void AnimatedSprite2D::_bind_methods() { } AnimatedSprite2D::AnimatedSprite2D() { - centered = true; hflip = false; vflip = false; diff --git a/scene/2d/animated_sprite_2d.h b/scene/2d/animated_sprite_2d.h index 726ecefd32..fae334498d 100644 --- a/scene/2d/animated_sprite_2d.h +++ b/scene/2d/animated_sprite_2d.h @@ -35,11 +35,9 @@ #include "scene/resources/texture.h" class SpriteFrames : public Resource { - GDCLASS(SpriteFrames, Resource); struct Anim { - float speed; bool loop; Vector<Ref<Texture2D>> frames; @@ -87,7 +85,6 @@ public: void add_frame(const StringName &p_anim, const Ref<Texture2D> &p_frame, int p_at_pos = -1); int get_frame_count(const StringName &p_anim) const; _FORCE_INLINE_ Ref<Texture2D> get_frame(const StringName &p_anim, int p_idx) const { - const Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_V_MSG(!E, Ref<Texture2D>(), "Animation '" + String(p_anim) + "' doesn't exist."); ERR_FAIL_COND_V(p_idx < 0, Ref<Texture2D>()); @@ -98,7 +95,6 @@ public: } _FORCE_INLINE_ Ref<Texture2D> get_normal_frame(const StringName &p_anim, int p_idx) const { - const Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_V_MSG(!E, Ref<Texture2D>(), "Animation '" + String(p_anim) + "' doesn't exist."); ERR_FAIL_COND_V(p_idx < 0, Ref<Texture2D>()); @@ -112,7 +108,6 @@ public: } _FORCE_INLINE_ Ref<Texture2D> get_specular_frame(const StringName &p_anim, int p_idx) const { - const Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_V(!E, Ref<Texture2D>()); ERR_FAIL_COND_V(p_idx < 0, Ref<Texture2D>()); @@ -141,7 +136,6 @@ public: }; class AnimatedSprite2D : public Node2D { - GDCLASS(AnimatedSprite2D, Node2D); Ref<SpriteFrames> frames; diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 8ba334bc67..90af1ff274 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -35,27 +35,22 @@ #include "servers/physics_server_2d.h" void Area2D::set_space_override_mode(SpaceOverride p_mode) { - space_override = p_mode; PhysicsServer2D::get_singleton()->area_set_space_override_mode(get_rid(), PhysicsServer2D::AreaSpaceOverrideMode(p_mode)); } Area2D::SpaceOverride Area2D::get_space_override_mode() const { - return space_override; } void Area2D::set_gravity_is_point(bool p_enabled) { - gravity_is_point = p_enabled; PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_IS_POINT, p_enabled); } bool Area2D::is_gravity_a_point() const { - return gravity_is_point; } void Area2D::set_gravity_distance_scale(real_t p_scale) { - gravity_distance_scale = p_scale; PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale); } @@ -65,58 +60,47 @@ real_t Area2D::get_gravity_distance_scale() const { } void Area2D::set_gravity_vector(const Vector2 &p_vec) { - gravity_vec = p_vec; PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_VECTOR, p_vec); } Vector2 Area2D::get_gravity_vector() const { - return gravity_vec; } void Area2D::set_gravity(real_t p_gravity) { - gravity = p_gravity; PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY, p_gravity); } real_t Area2D::get_gravity() const { - return gravity; } void Area2D::set_linear_damp(real_t p_linear_damp) { - linear_damp = p_linear_damp; PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_LINEAR_DAMP, p_linear_damp); } real_t Area2D::get_linear_damp() const { - return linear_damp; } void Area2D::set_angular_damp(real_t p_angular_damp) { - angular_damp = p_angular_damp; PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_ANGULAR_DAMP, p_angular_damp); } real_t Area2D::get_angular_damp() const { - return angular_damp; } void Area2D::set_priority(real_t p_priority) { - priority = p_priority; PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_PRIORITY, p_priority); } real_t Area2D::get_priority() const { - return priority; } void Area2D::_body_enter_tree(ObjectID p_id) { - Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); @@ -128,13 +112,11 @@ void Area2D::_body_enter_tree(ObjectID p_id) { E->get().in_tree = true; emit_signal(SceneStringNames::get_singleton()->body_entered, node); for (int i = 0; i < E->get().shapes.size(); i++) { - emit_signal(SceneStringNames::get_singleton()->body_shape_entered, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape); } } void Area2D::_body_exit_tree(ObjectID p_id) { - Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); @@ -144,13 +126,11 @@ void Area2D::_body_exit_tree(ObjectID p_id) { E->get().in_tree = false; emit_signal(SceneStringNames::get_singleton()->body_exited, node); for (int i = 0; i < E->get().shapes.size(); i++) { - emit_signal(SceneStringNames::get_singleton()->body_shape_exited, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape); } } void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_area_shape) { - bool body_in = p_status == PhysicsServer2D::AREA_BODY_ADDED; ObjectID objid = p_instance; @@ -167,7 +147,6 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i if (body_in) { if (!E) { - E = body_map.insert(objid, BodyState()); E->get().rc = 0; E->get().in_tree = node && node->is_inside_tree(); @@ -188,7 +167,6 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i } } else { - E->get().rc--; if (node) @@ -197,7 +175,6 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i bool eraseit = false; if (E->get().rc == 0) { - if (node) { node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area2D::_body_enter_tree)); node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area2D::_body_exit_tree)); @@ -219,7 +196,6 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i } void Area2D::_area_enter_tree(ObjectID p_id) { - Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); @@ -231,13 +207,11 @@ void Area2D::_area_enter_tree(ObjectID p_id) { E->get().in_tree = true; emit_signal(SceneStringNames::get_singleton()->area_entered, node); for (int i = 0; i < E->get().shapes.size(); i++) { - emit_signal(SceneStringNames::get_singleton()->area_shape_entered, p_id, node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape); } } void Area2D::_area_exit_tree(ObjectID p_id) { - Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); @@ -247,13 +221,11 @@ void Area2D::_area_exit_tree(ObjectID p_id) { E->get().in_tree = false; emit_signal(SceneStringNames::get_singleton()->area_exited, node); for (int i = 0; i < E->get().shapes.size(); i++) { - emit_signal(SceneStringNames::get_singleton()->area_shape_exited, p_id, node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape); } } void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, int p_area_shape, int p_self_shape) { - bool area_in = p_status == PhysicsServer2D::AREA_BODY_ADDED; ObjectID objid = p_instance; @@ -269,7 +241,6 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i if (area_in) { if (!E) { - E = area_map.insert(objid, AreaState()); E->get().rc = 0; E->get().in_tree = node && node->is_inside_tree(); @@ -290,7 +261,6 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i } } else { - E->get().rc--; if (node) @@ -299,7 +269,6 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i bool eraseit = false; if (E->get().rc == 0) { - if (node) { node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area2D::_area_enter_tree)); node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area2D::_area_exit_tree)); @@ -321,7 +290,6 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i } void Area2D::_clear_monitoring() { - ERR_FAIL_COND_MSG(locked, "This function can't be used during the in/out signal."); { @@ -330,7 +298,6 @@ void Area2D::_clear_monitoring() { //disconnect all monitored stuff for (Map<ObjectID, BodyState>::Element *E = bmcopy.front(); E; E = E->next()) { - Object *obj = ObjectDB::get_instance(E->key()); Node *node = Object::cast_to<Node>(obj); @@ -344,7 +311,6 @@ void Area2D::_clear_monitoring() { continue; for (int i = 0; i < E->get().shapes.size(); i++) { - emit_signal(SceneStringNames::get_singleton()->body_shape_exited, E->key(), node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape); } @@ -353,13 +319,11 @@ void Area2D::_clear_monitoring() { } { - Map<ObjectID, AreaState> bmcopy = area_map; area_map.clear(); //disconnect all monitored stuff for (Map<ObjectID, AreaState>::Element *E = bmcopy.front(); E; E = E->next()) { - Object *obj = ObjectDB::get_instance(E->key()); Node *node = Object::cast_to<Node>(obj); @@ -373,7 +337,6 @@ void Area2D::_clear_monitoring() { continue; for (int i = 0; i < E->get().shapes.size(); i++) { - emit_signal(SceneStringNames::get_singleton()->area_shape_exited, E->key(), node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape); } @@ -383,18 +346,14 @@ void Area2D::_clear_monitoring() { } void Area2D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_EXIT_TREE: { - _clear_monitoring(); } break; } } void Area2D::set_monitoring(bool p_enable) { - if (p_enable == monitoring) return; ERR_FAIL_COND_MSG(locked, "Function blocked during in/out signal. Use set_deferred(\"monitoring\", true/false)."); @@ -402,7 +361,6 @@ void Area2D::set_monitoring(bool p_enable) { monitoring = p_enable; if (monitoring) { - PhysicsServer2D::get_singleton()->area_set_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_body_inout); PhysicsServer2D::get_singleton()->area_set_area_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_area_inout); @@ -414,12 +372,10 @@ void Area2D::set_monitoring(bool p_enable) { } bool Area2D::is_monitoring() const { - return monitoring; } void Area2D::set_monitorable(bool p_enable) { - ERR_FAIL_COND_MSG(locked || (is_inside_tree() && PhysicsServer2D::get_singleton()->is_flushing_queries()), "Function blocked during in/out signal. Use set_deferred(\"monitorable\", true/false)."); if (p_enable == monitorable) @@ -431,12 +387,10 @@ void Area2D::set_monitorable(bool p_enable) { } bool Area2D::is_monitorable() const { - return monitorable; } TypedArray<Node2D> Area2D::get_overlapping_bodies() const { - ERR_FAIL_COND_V_MSG(!monitoring, Array(), "Can't find overlapping bodies when monitoring is off."); TypedArray<Node2D> ret; ret.resize(body_map.size()); @@ -454,7 +408,6 @@ TypedArray<Node2D> Area2D::get_overlapping_bodies() const { } TypedArray<Area2D> Area2D::get_overlapping_areas() const { - ERR_FAIL_COND_V_MSG(!monitoring, Array(), "Can't find overlapping bodies when monitoring is off."); TypedArray<Area2D> ret; ret.resize(area_map.size()); @@ -472,7 +425,6 @@ TypedArray<Area2D> Area2D::get_overlapping_areas() const { } bool Area2D::overlaps_area(Node *p_area) const { - ERR_FAIL_NULL_V(p_area, false); const Map<ObjectID, AreaState>::Element *E = area_map.find(p_area->get_instance_id()); if (!E) @@ -481,7 +433,6 @@ bool Area2D::overlaps_area(Node *p_area) const { } bool Area2D::overlaps_body(Node *p_body) const { - ERR_FAIL_NULL_V(p_body, false); const Map<ObjectID, BodyState>::Element *E = body_map.find(p_body->get_instance_id()); if (!E) @@ -490,29 +441,24 @@ bool Area2D::overlaps_body(Node *p_body) const { } void Area2D::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; PhysicsServer2D::get_singleton()->area_set_collision_mask(get_rid(), p_mask); } uint32_t Area2D::get_collision_mask() const { - return collision_mask; } void Area2D::set_collision_layer(uint32_t p_layer) { - collision_layer = p_layer; PhysicsServer2D::get_singleton()->area_set_collision_layer(get_rid(), p_layer); } uint32_t Area2D::get_collision_layer() const { - return collision_layer; } void Area2D::set_collision_mask_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_mask(); if (p_value) mask |= 1 << p_bit; @@ -522,12 +468,10 @@ void Area2D::set_collision_mask_bit(int p_bit, bool p_value) { } bool Area2D::get_collision_mask_bit(int p_bit) const { - return get_collision_mask() & (1 << p_bit); } void Area2D::set_collision_layer_bit(int p_bit, bool p_value) { - uint32_t layer = get_collision_layer(); if (p_value) layer |= 1 << p_bit; @@ -537,27 +481,22 @@ void Area2D::set_collision_layer_bit(int p_bit, bool p_value) { } bool Area2D::get_collision_layer_bit(int p_bit) const { - return get_collision_layer() & (1 << p_bit); } void Area2D::set_audio_bus_override(bool p_override) { - audio_bus_override = p_override; } bool Area2D::is_overriding_audio_bus() const { - return audio_bus_override; } void Area2D::set_audio_bus_name(const StringName &p_audio_bus) { - audio_bus = p_audio_bus; } StringName Area2D::get_audio_bus_name() const { - for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { if (AudioServer::get_singleton()->get_bus_name(i) == audio_bus) { return audio_bus; @@ -567,9 +506,7 @@ StringName Area2D::get_audio_bus_name() const { } void Area2D::_validate_property(PropertyInfo &property) const { - if (property.name == "audio_bus_name") { - String options; for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { if (i > 0) @@ -677,7 +614,6 @@ void Area2D::_bind_methods() { Area2D::Area2D() : CollisionObject2D(PhysicsServer2D::get_singleton()->area_create(), true) { - space_override = SPACE_OVERRIDE_DISABLED; set_gravity(98); set_gravity_vector(Vector2(0, 1)); diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h index 0e2c0ac672..3b9b57cab4 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -35,7 +35,6 @@ #include "scene/2d/collision_object_2d.h" class Area2D : public CollisionObject2D { - GDCLASS(Area2D, CollisionObject2D); public: @@ -68,7 +67,6 @@ private: void _body_exit_tree(ObjectID p_id); struct ShapePair { - int body_shape; int area_shape; bool operator<(const ShapePair &p_sp) const { @@ -86,7 +84,6 @@ private: }; struct BodyState { - int rc; bool in_tree; VSet<ShapePair> shapes; @@ -100,7 +97,6 @@ private: void _area_exit_tree(ObjectID p_id); struct AreaShapePair { - int area_shape; int self_shape; bool operator<(const AreaShapePair &p_sp) const { @@ -118,7 +114,6 @@ private: }; struct AreaState { - int rc; bool in_tree; VSet<AreaShapePair> shapes; diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index 55d111439a..b1ca2912e9 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -35,7 +35,6 @@ #include "scene/main/window.h" void AudioStreamPlayer2D::_mix_audio() { - if (!stream_playback.is_valid() || !active || (stream_paused && !stream_paused_fade_out)) { return; @@ -59,7 +58,6 @@ void AudioStreamPlayer2D::_mix_audio() { //write all outputs for (int i = 0; i < output_count; i++) { - Output current = outputs[i]; //see if current output exists, to keep volume ramp @@ -98,7 +96,6 @@ void AudioStreamPlayer2D::_mix_audio() { AudioFrame *target = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.bus_index, 0); for (int j = 0; j < buffer_size; j++) { - target[j] += buffer[j] * vol; vol += vol_inc; } @@ -120,7 +117,6 @@ void AudioStreamPlayer2D::_mix_audio() { continue; for (int j = 0; j < buffer_size; j++) { - AudioFrame frame = buffer[j] * vol; for (int k = 0; k < cc; k++) { targets[k][j] += frame; @@ -145,9 +141,7 @@ void AudioStreamPlayer2D::_mix_audio() { } void AudioStreamPlayer2D::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - AudioServer::get_singleton()->add_callback(_mix_audios, this); if (autoplay && !Engine::get_singleton()->is_editor_hint()) { play(); @@ -155,7 +149,6 @@ void AudioStreamPlayer2D::_notification(int p_what) { } if (p_what == NOTIFICATION_EXIT_TREE) { - AudioServer::get_singleton()->remove_callback(_mix_audios, this); } @@ -171,7 +164,6 @@ void AudioStreamPlayer2D::_notification(int p_what) { } if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) { - //update anything related to position first, if possible of course if (!output_ready) { @@ -194,7 +186,6 @@ void AudioStreamPlayer2D::_notification(int p_what) { int areas = space_state->intersect_point(global_pos, sr, MAX_INTERSECT_AREAS, Set<RID>(), area_mask, false, true); for (int i = 0; i < areas; i++) { - Area2D *area2d = Object::cast_to<Area2D>(sr[i].collider); if (!area2d) continue; @@ -209,10 +200,8 @@ void AudioStreamPlayer2D::_notification(int p_what) { world_2d->get_viewport_list(&viewports); for (List<Viewport *>::Element *E = viewports.front(); E; E = E->next()) { - Viewport *vp = E->get(); if (vp->is_audio_listener_2d()) { - //compute matrix to convert to screen Transform2D to_screen = vp->get_global_canvas_transform() * vp->get_canvas_transform(); Vector2 screen_size = vp->get_visible_rect().size; @@ -269,7 +258,6 @@ void AudioStreamPlayer2D::_notification(int p_what) { } void AudioStreamPlayer2D::set_stream(Ref<AudioStream> p_stream) { - AudioServer::get_singleton()->lock(); mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size()); @@ -294,16 +282,13 @@ void AudioStreamPlayer2D::set_stream(Ref<AudioStream> p_stream) { } Ref<AudioStream> AudioStreamPlayer2D::get_stream() const { - return stream; } void AudioStreamPlayer2D::set_volume_db(float p_volume) { - volume_db = p_volume; } float AudioStreamPlayer2D::get_volume_db() const { - return volume_db; } @@ -316,7 +301,6 @@ float AudioStreamPlayer2D::get_pitch_scale() const { } void AudioStreamPlayer2D::play(float p_from_pos) { - if (!is_playing()) { // Reset the prev_output_count if the stream is stopped prev_output_count = 0; @@ -331,14 +315,12 @@ void AudioStreamPlayer2D::play(float p_from_pos) { } void AudioStreamPlayer2D::seek(float p_seconds) { - if (stream_playback.is_valid()) { setseek = p_seconds; } } void AudioStreamPlayer2D::stop() { - if (stream_playback.is_valid()) { active = false; set_physics_process_internal(false); @@ -347,7 +329,6 @@ void AudioStreamPlayer2D::stop() { } bool AudioStreamPlayer2D::is_playing() const { - if (stream_playback.is_valid()) { return active; // && stream_playback->is_playing(); } @@ -356,7 +337,6 @@ bool AudioStreamPlayer2D::is_playing() const { } float AudioStreamPlayer2D::get_playback_position() { - if (stream_playback.is_valid()) { return stream_playback->get_playback_position(); } @@ -365,14 +345,12 @@ float AudioStreamPlayer2D::get_playback_position() { } void AudioStreamPlayer2D::set_bus(const StringName &p_bus) { - //if audio is active, must lock this AudioServer::get_singleton()->lock(); bus = p_bus; AudioServer::get_singleton()->unlock(); } StringName AudioStreamPlayer2D::get_bus() const { - for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { if (AudioServer::get_singleton()->get_bus_name(i) == bus) { return bus; @@ -382,30 +360,24 @@ StringName AudioStreamPlayer2D::get_bus() const { } void AudioStreamPlayer2D::set_autoplay(bool p_enable) { - autoplay = p_enable; } bool AudioStreamPlayer2D::is_autoplay_enabled() { - return autoplay; } void AudioStreamPlayer2D::_set_playing(bool p_enable) { - if (p_enable) play(); else stop(); } bool AudioStreamPlayer2D::_is_active() const { - return active; } void AudioStreamPlayer2D::_validate_property(PropertyInfo &property) const { - if (property.name == "bus") { - String options; for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { if (i > 0) @@ -419,42 +391,34 @@ void AudioStreamPlayer2D::_validate_property(PropertyInfo &property) const { } void AudioStreamPlayer2D::_bus_layout_changed() { - _change_notify(); } void AudioStreamPlayer2D::set_max_distance(float p_pixels) { - ERR_FAIL_COND(p_pixels <= 0.0); max_distance = p_pixels; } float AudioStreamPlayer2D::get_max_distance() const { - return max_distance; } void AudioStreamPlayer2D::set_attenuation(float p_curve) { - attenuation = p_curve; } float AudioStreamPlayer2D::get_attenuation() const { - return attenuation; } void AudioStreamPlayer2D::set_area_mask(uint32_t p_mask) { - area_mask = p_mask; } uint32_t AudioStreamPlayer2D::get_area_mask() const { - return area_mask; } void AudioStreamPlayer2D::set_stream_paused(bool p_pause) { - if (p_pause != stream_paused) { stream_paused = p_pause; stream_paused_fade_in = !p_pause; @@ -463,7 +427,6 @@ void AudioStreamPlayer2D::set_stream_paused(bool p_pause) { } bool AudioStreamPlayer2D::get_stream_paused() const { - return stream_paused; } @@ -472,7 +435,6 @@ Ref<AudioStreamPlayback> AudioStreamPlayer2D::get_stream_playback() { } void AudioStreamPlayer2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_stream", "stream"), &AudioStreamPlayer2D::set_stream); ClassDB::bind_method(D_METHOD("get_stream"), &AudioStreamPlayer2D::get_stream); @@ -527,7 +489,6 @@ void AudioStreamPlayer2D::_bind_methods() { } AudioStreamPlayer2D::AudioStreamPlayer2D() { - volume_db = 0; pitch_scale = 1.0; autoplay = false; diff --git a/scene/2d/audio_stream_player_2d.h b/scene/2d/audio_stream_player_2d.h index 86e931b3c6..7f0b6f5897 100644 --- a/scene/2d/audio_stream_player_2d.h +++ b/scene/2d/audio_stream_player_2d.h @@ -36,7 +36,6 @@ #include "servers/audio_server.h" class AudioStreamPlayer2D : public Node2D { - GDCLASS(AudioStreamPlayer2D, Node2D); private: @@ -47,7 +46,6 @@ private: }; struct Output { - AudioFrame vol; int bus_index; Viewport *viewport; //pointer only used for reference to previous mix diff --git a/scene/2d/back_buffer_copy.cpp b/scene/2d/back_buffer_copy.cpp index 4c952b7ca6..0bcb42e563 100644 --- a/scene/2d/back_buffer_copy.cpp +++ b/scene/2d/back_buffer_copy.cpp @@ -31,19 +31,14 @@ #include "back_buffer_copy.h" void BackBufferCopy::_update_copy_mode() { - switch (copy_mode) { - case COPY_MODE_DISABLED: { - RS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), false, Rect2()); } break; case COPY_MODE_RECT: { - RS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, rect); } break; case COPY_MODE_VIEWPORT: { - RS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, Rect2()); } break; @@ -52,7 +47,6 @@ void BackBufferCopy::_update_copy_mode() { #ifdef TOOLS_ENABLED Rect2 BackBufferCopy::_edit_get_rect() const { - return rect; } @@ -62,12 +56,10 @@ bool BackBufferCopy::_edit_use_rect() const { #endif Rect2 BackBufferCopy::get_anchorable_rect() const { - return rect; } void BackBufferCopy::set_rect(const Rect2 &p_rect) { - rect = p_rect; _update_copy_mode(); } @@ -77,17 +69,14 @@ Rect2 BackBufferCopy::get_rect() const { } void BackBufferCopy::set_copy_mode(CopyMode p_mode) { - copy_mode = p_mode; _update_copy_mode(); } BackBufferCopy::CopyMode BackBufferCopy::get_copy_mode() const { - return copy_mode; } void BackBufferCopy::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_rect", "rect"), &BackBufferCopy::set_rect); ClassDB::bind_method(D_METHOD("get_rect"), &BackBufferCopy::get_rect); @@ -103,7 +92,6 @@ void BackBufferCopy::_bind_methods() { } BackBufferCopy::BackBufferCopy() { - rect = Rect2(-100, -100, 200, 200); copy_mode = COPY_MODE_RECT; _update_copy_mode(); diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index d8af14a3fb..eeb87a7396 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -36,7 +36,6 @@ #include "servers/rendering_server.h" void Camera2D::_update_scroll() { - if (!is_inside_tree()) return; @@ -49,7 +48,6 @@ void Camera2D::_update_scroll() { return; if (current) { - ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id)); Transform2D xform = get_camera_transform(); @@ -64,7 +62,6 @@ void Camera2D::_update_scroll() { } void Camera2D::_update_process_mode() { - if (Engine::get_singleton()->is_editor_hint()) { set_process_internal(false); set_physics_process_internal(false); @@ -78,7 +75,6 @@ void Camera2D::_update_process_mode() { } void Camera2D::set_zoom(const Vector2 &p_zoom) { - zoom = p_zoom; Point2 old_smoothed_camera_pos = smoothed_camera_pos; _update_scroll(); @@ -86,12 +82,10 @@ void Camera2D::set_zoom(const Vector2 &p_zoom) { }; Vector2 Camera2D::get_zoom() const { - return zoom; }; Transform2D Camera2D::get_camera_transform() { - if (!get_tree()) return Transform2D(); @@ -103,14 +97,11 @@ Transform2D Camera2D::get_camera_transform() { Point2 ret_camera_pos; if (!first) { - if (anchor_mode == ANCHOR_MODE_DRAG_CENTER) { - if (h_drag_enabled && !Engine::get_singleton()->is_editor_hint() && !h_offset_changed) { camera_pos.x = MIN(camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * zoom.x * drag_margin[MARGIN_LEFT])); camera_pos.x = MAX(camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * zoom.x * drag_margin[MARGIN_RIGHT])); } else { - if (h_ofs < 0) { camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs; } else { @@ -121,12 +112,10 @@ Transform2D Camera2D::get_camera_transform() { } if (v_drag_enabled && !Engine::get_singleton()->is_editor_hint() && !v_offset_changed) { - camera_pos.y = MIN(camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * zoom.y * drag_margin[MARGIN_TOP])); camera_pos.y = MAX(camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * zoom.y * drag_margin[MARGIN_BOTTOM])); } else { - if (v_ofs < 0) { camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs; } else { @@ -137,7 +126,6 @@ Transform2D Camera2D::get_camera_transform() { } } else if (anchor_mode == ANCHOR_MODE_FIXED_TOP_LEFT) { - camera_pos = new_camera_pos; } @@ -159,13 +147,11 @@ Transform2D Camera2D::get_camera_transform() { } if (smoothing_enabled && !Engine::get_singleton()->is_editor_hint()) { - float c = smoothing * (process_mode == CAMERA2D_PROCESS_PHYSICS ? get_physics_process_delta_time() : get_process_delta_time()); smoothed_camera_pos = ((camera_pos - smoothed_camera_pos) * c) + smoothed_camera_pos; ret_camera_pos = smoothed_camera_pos; //camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing; } else { - ret_camera_pos = smoothed_camera_pos = camera_pos; } @@ -218,23 +204,18 @@ Transform2D Camera2D::get_camera_transform() { } void Camera2D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_INTERNAL_PROCESS: case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { - _update_scroll(); } break; case NOTIFICATION_TRANSFORM_CHANGED: { - if (!is_processing_internal() && !is_physics_processing_internal()) _update_scroll(); } break; case NOTIFICATION_ENTER_TREE: { - if (custom_viewport && ObjectDB::get_instance(custom_viewport_id)) { viewport = custom_viewport; } else { @@ -256,7 +237,6 @@ void Camera2D::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { - if (is_current()) { if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) { viewport->set_canvas_transform(Transform2D()); @@ -268,7 +248,6 @@ void Camera2D::_notification(int p_what) { } break; case NOTIFICATION_DRAW: { - if (!is_inside_tree() || !Engine::get_singleton()->is_editor_hint()) break; @@ -349,40 +328,33 @@ void Camera2D::_notification(int p_what) { } void Camera2D::set_offset(const Vector2 &p_offset) { - offset = p_offset; _update_scroll(); } Vector2 Camera2D::get_offset() const { - return offset; } void Camera2D::set_anchor_mode(AnchorMode p_anchor_mode) { - anchor_mode = p_anchor_mode; _update_scroll(); } Camera2D::AnchorMode Camera2D::get_anchor_mode() const { - return anchor_mode; } void Camera2D::set_rotating(bool p_rotating) { - rotating = p_rotating; _update_scroll(); } bool Camera2D::is_rotating() const { - return rotating; } void Camera2D::set_process_mode(Camera2DProcessMode p_mode) { - if (process_mode == p_mode) return; @@ -391,14 +363,11 @@ void Camera2D::set_process_mode(Camera2DProcessMode p_mode) { } Camera2D::Camera2DProcessMode Camera2D::get_process_mode() const { - return process_mode; } void Camera2D::_make_current(Object *p_which) { - if (p_which == this) { - current = true; } else { current = false; @@ -406,7 +375,6 @@ void Camera2D::_make_current(Object *p_which) { } void Camera2D::_set_current(bool p_current) { - if (p_current) make_current(); @@ -415,12 +383,10 @@ void Camera2D::_set_current(bool p_current) { } bool Camera2D::is_current() const { - return current; } void Camera2D::make_current() { - if (!is_inside_tree()) { current = true; } else { @@ -430,7 +396,6 @@ void Camera2D::make_current() { } void Camera2D::clear_current() { - current = false; if (is_inside_tree()) { get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, group_name, "_make_current", (Object *)nullptr); @@ -438,60 +403,50 @@ void Camera2D::clear_current() { } void Camera2D::set_limit(Margin p_margin, int p_limit) { - ERR_FAIL_INDEX((int)p_margin, 4); limit[p_margin] = p_limit; update(); } int Camera2D::get_limit(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, 0); return limit[p_margin]; } void Camera2D::set_limit_smoothing_enabled(bool enable) { - limit_smoothing_enabled = enable; _update_scroll(); } bool Camera2D::is_limit_smoothing_enabled() const { - return limit_smoothing_enabled; } void Camera2D::set_drag_margin(Margin p_margin, float p_drag_margin) { - ERR_FAIL_INDEX((int)p_margin, 4); drag_margin[p_margin] = p_drag_margin; update(); } float Camera2D::get_drag_margin(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, 0); return drag_margin[p_margin]; } Vector2 Camera2D::get_camera_position() const { - return camera_pos; } void Camera2D::force_update_scroll() { - _update_scroll(); } void Camera2D::reset_smoothing() { - smoothed_camera_pos = camera_pos; _update_scroll(); } void Camera2D::align() { - ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id)); Size2 screen_size = viewport->get_visible_rect().size; @@ -509,7 +464,6 @@ void Camera2D::align() { camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs; } } else if (anchor_mode == ANCHOR_MODE_FIXED_TOP_LEFT) { - camera_pos = current_camera_pos; } @@ -517,7 +471,6 @@ void Camera2D::align() { } void Camera2D::set_follow_smoothing(float p_speed) { - smoothing = p_speed; if (smoothing > 0 && !(is_inside_tree() && Engine::get_singleton()->is_editor_hint())) set_process_internal(true); @@ -526,55 +479,45 @@ void Camera2D::set_follow_smoothing(float p_speed) { } float Camera2D::get_follow_smoothing() const { - return smoothing; } Point2 Camera2D::get_camera_screen_center() const { - return camera_screen_center; } void Camera2D::set_h_drag_enabled(bool p_enabled) { - h_drag_enabled = p_enabled; } bool Camera2D::is_h_drag_enabled() const { - return h_drag_enabled; } void Camera2D::set_v_drag_enabled(bool p_enabled) { - v_drag_enabled = p_enabled; } bool Camera2D::is_v_drag_enabled() const { - return v_drag_enabled; } void Camera2D::set_v_offset(float p_offset) { - v_ofs = p_offset; v_offset_changed = true; _update_scroll(); } float Camera2D::get_v_offset() const { - return v_ofs; } void Camera2D::set_h_offset(float p_offset) { - h_ofs = p_offset; h_offset_changed = true; _update_scroll(); } float Camera2D::get_h_offset() const { - return h_ofs; } @@ -587,12 +530,10 @@ void Camera2D::_set_old_smoothing(float p_enable) { } void Camera2D::set_enable_follow_smoothing(bool p_enabled) { - smoothing_enabled = p_enabled; } bool Camera2D::is_follow_smoothing_enabled() const { - return smoothing_enabled; } @@ -612,7 +553,6 @@ void Camera2D::set_custom_viewport(Node *p_viewport) { } if (is_inside_tree()) { - if (custom_viewport) viewport = custom_viewport; else @@ -627,7 +567,6 @@ void Camera2D::set_custom_viewport(Node *p_viewport) { } Node *Camera2D::get_custom_viewport() const { - return custom_viewport; } @@ -659,7 +598,6 @@ bool Camera2D::is_margin_drawing_enabled() const { } void Camera2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Camera2D::set_offset); ClassDB::bind_method(D_METHOD("get_offset"), &Camera2D::get_offset); @@ -777,7 +715,6 @@ void Camera2D::_bind_methods() { } Camera2D::Camera2D() { - anchor_mode = ANCHOR_MODE_DRAG_CENTER; rotating = false; current = false; diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index 7a106ef79a..0a4e269c40 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -35,7 +35,6 @@ #include "scene/main/window.h" class Camera2D : public Node2D { - GDCLASS(Camera2D, Node2D); public: diff --git a/scene/2d/canvas_modulate.cpp b/scene/2d/canvas_modulate.cpp index 05f8804e2a..2ed2eaef42 100644 --- a/scene/2d/canvas_modulate.cpp +++ b/scene/2d/canvas_modulate.cpp @@ -31,22 +31,18 @@ #include "canvas_modulate.h" void CanvasModulate::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_CANVAS) { - if (is_visible_in_tree()) { RS::get_singleton()->canvas_set_modulate(get_canvas(), color); add_to_group("_canvas_modulate_" + itos(get_canvas().get_id())); } } else if (p_what == NOTIFICATION_EXIT_CANVAS) { - if (is_visible_in_tree()) { RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1)); remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id())); } } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - if (is_visible_in_tree()) { RS::get_singleton()->canvas_set_modulate(get_canvas(), color); add_to_group("_canvas_modulate_" + itos(get_canvas().get_id())); @@ -60,7 +56,6 @@ void CanvasModulate::_notification(int p_what) { } void CanvasModulate::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_color", "color"), &CanvasModulate::set_color); ClassDB::bind_method(D_METHOD("get_color"), &CanvasModulate::get_color); @@ -68,19 +63,16 @@ void CanvasModulate::_bind_methods() { } void CanvasModulate::set_color(const Color &p_color) { - color = p_color; if (is_visible_in_tree()) { RS::get_singleton()->canvas_set_modulate(get_canvas(), color); } } Color CanvasModulate::get_color() const { - return color; } String CanvasModulate::get_configuration_warning() const { - if (!is_visible_in_tree() || !is_inside_tree()) return String(); diff --git a/scene/2d/canvas_modulate.h b/scene/2d/canvas_modulate.h index ada6e27760..a0b61f43ba 100644 --- a/scene/2d/canvas_modulate.h +++ b/scene/2d/canvas_modulate.h @@ -34,7 +34,6 @@ #include "scene/2d/node_2d.h" class CanvasModulate : public Node2D { - GDCLASS(CanvasModulate, Node2D); Color color; diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index d82f4a2f2b..2f20a48139 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -34,11 +34,8 @@ #include "servers/physics_server_2d.h" void CollisionObject2D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - Transform2D global_transform = get_global_transform(); if (area) @@ -58,7 +55,6 @@ void CollisionObject2D::_notification(int p_what) { } break; case NOTIFICATION_ENTER_CANVAS: { - if (area) PhysicsServer2D::get_singleton()->area_attach_canvas_instance_id(rid, get_canvas_layer_instance_id()); else @@ -66,11 +62,9 @@ void CollisionObject2D::_notification(int p_what) { } break; case NOTIFICATION_VISIBILITY_CHANGED: { - _update_pickable(); } break; case NOTIFICATION_TRANSFORM_CHANGED: { - if (only_update_transform_changes) { return; } @@ -84,7 +78,6 @@ void CollisionObject2D::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { - if (area) { PhysicsServer2D::get_singleton()->area_set_space(rid, RID()); } else @@ -93,7 +86,6 @@ void CollisionObject2D::_notification(int p_what) { } break; case NOTIFICATION_EXIT_CANVAS: { - if (area) PhysicsServer2D::get_singleton()->area_attach_canvas_instance_id(rid, ObjectID()); else @@ -103,7 +95,6 @@ void CollisionObject2D::_notification(int p_what) { } uint32_t CollisionObject2D::create_shape_owner(Object *p_owner) { - ShapeData sd; uint32_t id; @@ -121,7 +112,6 @@ uint32_t CollisionObject2D::create_shape_owner(Object *p_owner) { } void CollisionObject2D::remove_shape_owner(uint32_t owner) { - ERR_FAIL_COND(!shapes.has(owner)); shape_owner_clear_shapes(owner); @@ -144,14 +134,12 @@ void CollisionObject2D::shape_owner_set_disabled(uint32_t p_owner, bool p_disabl } bool CollisionObject2D::is_shape_owner_disabled(uint32_t p_owner) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), false); return shapes[p_owner].disabled; } void CollisionObject2D::shape_owner_set_one_way_collision(uint32_t p_owner, bool p_enable) { - if (area) return; //not for areas @@ -165,14 +153,12 @@ void CollisionObject2D::shape_owner_set_one_way_collision(uint32_t p_owner, bool } bool CollisionObject2D::is_shape_owner_one_way_collision_enabled(uint32_t p_owner) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), false); return shapes[p_owner].one_way_collision; } void CollisionObject2D::shape_owner_set_one_way_collision_margin(uint32_t p_owner, float p_margin) { - if (area) return; //not for areas @@ -186,21 +172,18 @@ void CollisionObject2D::shape_owner_set_one_way_collision_margin(uint32_t p_owne } float CollisionObject2D::get_shape_owner_one_way_collision_margin(uint32_t p_owner) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), 0); return shapes[p_owner].one_way_collision_margin; } void CollisionObject2D::get_shape_owners(List<uint32_t> *r_owners) { - for (Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) { r_owners->push_back(E->key()); } } Array CollisionObject2D::_get_shape_owners() { - Array ret; for (Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) { ret.push_back(E->key()); @@ -210,7 +193,6 @@ Array CollisionObject2D::_get_shape_owners() { } void CollisionObject2D::shape_owner_set_transform(uint32_t p_owner, const Transform2D &p_transform) { - ERR_FAIL_COND(!shapes.has(p_owner)); ShapeData &sd = shapes[p_owner]; @@ -225,21 +207,18 @@ void CollisionObject2D::shape_owner_set_transform(uint32_t p_owner, const Transf } } Transform2D CollisionObject2D::shape_owner_get_transform(uint32_t p_owner) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), Transform2D()); return shapes[p_owner].xform; } Object *CollisionObject2D::shape_owner_get_owner(uint32_t p_owner) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), nullptr); return shapes[p_owner].owner; } void CollisionObject2D::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape2D> &p_shape) { - ERR_FAIL_COND(!shapes.has(p_owner)); ERR_FAIL_COND(p_shape.is_null()); @@ -257,20 +236,17 @@ void CollisionObject2D::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape2 total_subshapes++; } int CollisionObject2D::shape_owner_get_shape_count(uint32_t p_owner) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), 0); return shapes[p_owner].shapes.size(); } Ref<Shape2D> CollisionObject2D::shape_owner_get_shape(uint32_t p_owner, int p_shape) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), Ref<Shape2D>()); ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), Ref<Shape2D>()); return shapes[p_owner].shapes[p_shape].shape; } int CollisionObject2D::shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), -1); ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), -1); @@ -278,7 +254,6 @@ int CollisionObject2D::shape_owner_get_shape_index(uint32_t p_owner, int p_shape } void CollisionObject2D::shape_owner_remove_shape(uint32_t p_owner, int p_shape) { - ERR_FAIL_COND(!shapes.has(p_owner)); ERR_FAIL_INDEX(p_shape, shapes[p_owner].shapes.size()); @@ -303,7 +278,6 @@ void CollisionObject2D::shape_owner_remove_shape(uint32_t p_owner, int p_shape) } void CollisionObject2D::shape_owner_clear_shapes(uint32_t p_owner) { - ERR_FAIL_COND(!shapes.has(p_owner)); while (shape_owner_get_shape_count(p_owner) > 0) { @@ -312,7 +286,6 @@ void CollisionObject2D::shape_owner_clear_shapes(uint32_t p_owner) { } uint32_t CollisionObject2D::shape_find_owner(int p_shape_index) const { - ERR_FAIL_INDEX_V(p_shape_index, total_subshapes, 0); for (const Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) { @@ -328,7 +301,6 @@ uint32_t CollisionObject2D::shape_find_owner(int p_shape_index) const { } void CollisionObject2D::set_pickable(bool p_enabled) { - if (pickable == p_enabled) return; @@ -337,12 +309,10 @@ void CollisionObject2D::set_pickable(bool p_enabled) { } bool CollisionObject2D::is_pickable() const { - return pickable; } void CollisionObject2D::_input_event(Node *p_viewport, const Ref<InputEvent> &p_input_event, int p_shape) { - if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_input_event, p_viewport, p_input_event, p_shape); } @@ -350,7 +320,6 @@ void CollisionObject2D::_input_event(Node *p_viewport, const Ref<InputEvent> &p_ } void CollisionObject2D::_mouse_enter() { - if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_enter); } @@ -358,7 +327,6 @@ void CollisionObject2D::_mouse_enter() { } void CollisionObject2D::_mouse_exit() { - if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_exit); } @@ -381,7 +349,6 @@ void CollisionObject2D::_update_pickable() { } String CollisionObject2D::get_configuration_warning() const { - String warning = Node2D::get_configuration_warning(); if (shapes.empty()) { @@ -395,7 +362,6 @@ String CollisionObject2D::get_configuration_warning() const { } void CollisionObject2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_rid"), &CollisionObject2D::get_rid); ClassDB::bind_method(D_METHOD("set_pickable", "enabled"), &CollisionObject2D::set_pickable); @@ -432,7 +398,6 @@ void CollisionObject2D::_bind_methods() { } CollisionObject2D::CollisionObject2D(RID p_rid, bool p_area) { - rid = p_rid; area = p_area; pickable = true; @@ -441,7 +406,6 @@ CollisionObject2D::CollisionObject2D(RID p_rid, bool p_area) { only_update_transform_changes = false; if (p_area) { - PhysicsServer2D::get_singleton()->area_attach_object_instance_id(rid, get_instance_id()); } else { PhysicsServer2D::get_singleton()->body_attach_object_instance_id(rid, get_instance_id()); @@ -449,13 +413,11 @@ CollisionObject2D::CollisionObject2D(RID p_rid, bool p_area) { } CollisionObject2D::CollisionObject2D() { - //owner= set_notify_transform(true); } CollisionObject2D::~CollisionObject2D() { - PhysicsServer2D::get_singleton()->free(rid); } diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h index e931f20f40..d7af2f3a2a 100644 --- a/scene/2d/collision_object_2d.h +++ b/scene/2d/collision_object_2d.h @@ -35,7 +35,6 @@ #include "scene/resources/shape_2d.h" class CollisionObject2D : public Node2D { - GDCLASS(CollisionObject2D, Node2D); bool area; @@ -43,7 +42,6 @@ class CollisionObject2D : public Node2D { bool pickable; struct ShapeData { - Object *owner; Transform2D xform; struct Shape { diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index 1e48b2d67f..e5acfafa21 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -38,7 +38,6 @@ #include "thirdparty/misc/triangulator.h" void CollisionPolygon2D::_build_polygon() { - parent->shape_owner_clear_shapes(owner_id); if (polygon.size() == 0) @@ -47,7 +46,6 @@ void CollisionPolygon2D::_build_polygon() { bool solids = build_mode == BUILD_SOLIDS; if (solids) { - //here comes the sun, lalalala //decompose concave into multiple convex polygons and add them Vector<Vector<Vector2>> decomp = _decompose_in_convex(); @@ -58,7 +56,6 @@ void CollisionPolygon2D::_build_polygon() { } } else { - Ref<ConcavePolygonShape2D> concave = memnew(ConcavePolygonShape2D); Vector<Vector2> segments; @@ -82,7 +79,6 @@ Vector<Vector<Vector2>> CollisionPolygon2D::_decompose_in_convex() { } void CollisionPolygon2D::_update_in_shape_owner(bool p_xform_only) { - parent->shape_owner_set_transform(owner_id, get_transform()); if (p_xform_only) return; @@ -92,10 +88,8 @@ void CollisionPolygon2D::_update_in_shape_owner(bool p_xform_only) { } void CollisionPolygon2D::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_PARENTED: { - parent = Object::cast_to<CollisionObject2D>(get_parent()); if (parent) { owner_id = parent->create_shape_owner(this); @@ -111,14 +105,12 @@ void CollisionPolygon2D::_notification(int p_what) { } break; case NOTIFICATION_ENTER_TREE: { - if (parent) { _update_in_shape_owner(); } } break; case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { - if (parent) { _update_in_shape_owner(true); } @@ -133,13 +125,11 @@ void CollisionPolygon2D::_notification(int p_what) { } break; case NOTIFICATION_DRAW: { - if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { break; } for (int i = 0; i < polygon.size(); i++) { - Vector2 p = polygon[i]; Vector2 n = polygon[(i + 1) % polygon.size()]; // draw line with width <= 1, so it does not scale with zoom and break pixel exact editing @@ -152,7 +142,6 @@ void CollisionPolygon2D::_notification(int p_what) { Color c(0.4, 0.9, 0.1); for (int i = 0; i < decomp.size(); i++) { - c.set_hsv(Math::fmod(c.get_h() + 0.738, 1), c.get_s(), c.get_v(), 0.5); draw_colored_polygon(decomp[i], c); } @@ -181,7 +170,6 @@ void CollisionPolygon2D::_notification(int p_what) { } void CollisionPolygon2D::set_polygon(const Vector<Point2> &p_polygon) { - polygon = p_polygon; { @@ -192,7 +180,6 @@ void CollisionPolygon2D::set_polygon(const Vector<Point2> &p_polygon) { aabb.expand_to(polygon[i]); } if (aabb == Rect2()) { - aabb = Rect2(-10, -10, 20, 20); } else { aabb.position -= aabb.size * 0.3; @@ -208,12 +195,10 @@ void CollisionPolygon2D::set_polygon(const Vector<Point2> &p_polygon) { } Vector<Point2> CollisionPolygon2D::get_polygon() const { - return polygon; } void CollisionPolygon2D::set_build_mode(BuildMode p_mode) { - ERR_FAIL_INDEX((int)p_mode, 2); build_mode = p_mode; if (parent) { @@ -222,13 +207,11 @@ void CollisionPolygon2D::set_build_mode(BuildMode p_mode) { } CollisionPolygon2D::BuildMode CollisionPolygon2D::get_build_mode() const { - return build_mode; } #ifdef TOOLS_ENABLED Rect2 CollisionPolygon2D::_edit_get_rect() const { - return aabb; } @@ -237,13 +220,11 @@ bool CollisionPolygon2D::_edit_use_rect() const { } bool CollisionPolygon2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - return Geometry::is_point_in_polygon(p_point, Variant(polygon)); } #endif String CollisionPolygon2D::get_configuration_warning() const { - if (!Object::cast_to<CollisionObject2D>(get_parent())) { return TTR("CollisionPolygon2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape."); } @@ -276,7 +257,6 @@ void CollisionPolygon2D::set_one_way_collision(bool p_enable) { } bool CollisionPolygon2D::is_one_way_collision_enabled() const { - return one_way_collision; } @@ -291,7 +271,6 @@ float CollisionPolygon2D::get_one_way_collision_margin() const { return one_way_collision_margin; } void CollisionPolygon2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &CollisionPolygon2D::set_polygon); ClassDB::bind_method(D_METHOD("get_polygon"), &CollisionPolygon2D::get_polygon); @@ -315,7 +294,6 @@ void CollisionPolygon2D::_bind_methods() { } CollisionPolygon2D::CollisionPolygon2D() { - aabb = Rect2(-10, -10, 20, 20); build_mode = BUILD_SOLIDS; set_notify_local_transform(true); diff --git a/scene/2d/collision_polygon_2d.h b/scene/2d/collision_polygon_2d.h index 92a2758813..bf3e560a93 100644 --- a/scene/2d/collision_polygon_2d.h +++ b/scene/2d/collision_polygon_2d.h @@ -37,7 +37,6 @@ class CollisionObject2D; class CollisionPolygon2D : public Node2D { - GDCLASS(CollisionPolygon2D, Node2D); public: diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index b1dbc57c94..43c8db18be 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -41,12 +41,10 @@ #include "scene/resources/segment_shape_2d.h" void CollisionShape2D::_shape_changed() { - update(); } void CollisionShape2D::_update_in_shape_owner(bool p_xform_only) { - parent->shape_owner_set_transform(owner_id, get_transform()); if (p_xform_only) return; @@ -56,11 +54,8 @@ void CollisionShape2D::_update_in_shape_owner(bool p_xform_only) { } void CollisionShape2D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_PARENTED: { - parent = Object::cast_to<CollisionObject2D>(get_parent()); if (parent) { owner_id = parent->create_shape_owner(this); @@ -78,14 +73,12 @@ void CollisionShape2D::_notification(int p_what) { } break; case NOTIFICATION_ENTER_TREE: { - if (parent) { _update_in_shape_owner(); } } break; case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { - if (parent) { _update_in_shape_owner(true); } @@ -100,7 +93,6 @@ void CollisionShape2D::_notification(int p_what) { } break; case NOTIFICATION_DRAW: { - if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { break; } @@ -147,7 +139,6 @@ void CollisionShape2D::_notification(int p_what) { } void CollisionShape2D::set_shape(const Ref<Shape2D> &p_shape) { - if (shape.is_valid()) shape->disconnect("changed", callable_mp(this, &CollisionShape2D::_shape_changed)); shape = p_shape; @@ -166,12 +157,10 @@ void CollisionShape2D::set_shape(const Ref<Shape2D> &p_shape) { } Ref<Shape2D> CollisionShape2D::get_shape() const { - return shape; } bool CollisionShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - if (!shape.is_valid()) return false; @@ -179,7 +168,6 @@ bool CollisionShape2D::_edit_is_selected_on_click(const Point2 &p_point, double } String CollisionShape2D::get_configuration_warning() const { - if (!Object::cast_to<CollisionObject2D>(get_parent())) { return TTR("CollisionShape2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape."); } @@ -212,7 +200,6 @@ void CollisionShape2D::set_one_way_collision(bool p_enable) { } bool CollisionShape2D::is_one_way_collision_enabled() const { - return one_way_collision; } @@ -228,7 +215,6 @@ float CollisionShape2D::get_one_way_collision_margin() const { } void CollisionShape2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_shape", "shape"), &CollisionShape2D::set_shape); ClassDB::bind_method(D_METHOD("get_shape"), &CollisionShape2D::get_shape); ClassDB::bind_method(D_METHOD("set_disabled", "disabled"), &CollisionShape2D::set_disabled); @@ -245,7 +231,6 @@ void CollisionShape2D::_bind_methods() { } CollisionShape2D::CollisionShape2D() { - rect = Rect2(-Point2(10, 10), Point2(20, 20)); set_notify_local_transform(true); owner_id = 0; diff --git a/scene/2d/collision_shape_2d.h b/scene/2d/collision_shape_2d.h index 80bea0a979..ec7808ee7c 100644 --- a/scene/2d/collision_shape_2d.h +++ b/scene/2d/collision_shape_2d.h @@ -37,7 +37,6 @@ class CollisionObject2D; class CollisionShape2D : public Node2D { - GDCLASS(CollisionShape2D, Node2D); Ref<Shape2D> shape; Rect2 rect; diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index c37cd398c4..ecc78809e7 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -37,7 +37,6 @@ #include "servers/rendering_server.h" void CPUParticles2D::set_emitting(bool p_emitting) { - if (emitting == p_emitting) return; @@ -47,7 +46,6 @@ void CPUParticles2D::set_emitting(bool p_emitting) { } void CPUParticles2D::set_amount(int p_amount) { - ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles must be greater than 0."); particles.resize(p_amount); @@ -65,99 +63,78 @@ void CPUParticles2D::set_amount(int p_amount) { particle_order.resize(p_amount); } void CPUParticles2D::set_lifetime(float p_lifetime) { - ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0."); lifetime = p_lifetime; } void CPUParticles2D::set_one_shot(bool p_one_shot) { - one_shot = p_one_shot; } void CPUParticles2D::set_pre_process_time(float p_time) { - pre_process_time = p_time; } void CPUParticles2D::set_explosiveness_ratio(float p_ratio) { - explosiveness_ratio = p_ratio; } void CPUParticles2D::set_randomness_ratio(float p_ratio) { - randomness_ratio = p_ratio; } void CPUParticles2D::set_lifetime_randomness(float p_random) { - lifetime_randomness = p_random; } void CPUParticles2D::set_use_local_coordinates(bool p_enable) { - local_coords = p_enable; set_notify_transform(!p_enable); } void CPUParticles2D::set_speed_scale(float p_scale) { - speed_scale = p_scale; } bool CPUParticles2D::is_emitting() const { - return emitting; } int CPUParticles2D::get_amount() const { - return particles.size(); } float CPUParticles2D::get_lifetime() const { - return lifetime; } bool CPUParticles2D::get_one_shot() const { - return one_shot; } float CPUParticles2D::get_pre_process_time() const { - return pre_process_time; } float CPUParticles2D::get_explosiveness_ratio() const { - return explosiveness_ratio; } float CPUParticles2D::get_randomness_ratio() const { - return randomness_ratio; } float CPUParticles2D::get_lifetime_randomness() const { - return lifetime_randomness; } bool CPUParticles2D::get_use_local_coordinates() const { - return local_coords; } float CPUParticles2D::get_speed_scale() const { - return speed_scale; } void CPUParticles2D::set_draw_order(DrawOrder p_order) { - draw_order = p_order; } CPUParticles2D::DrawOrder CPUParticles2D::get_draw_order() const { - return draw_order; } void CPUParticles2D::_update_mesh_texture() { - Size2 tex_size; if (texture.is_valid()) { tex_size = texture->get_size(); @@ -225,7 +202,6 @@ void CPUParticles2D::set_texture(const Ref<Texture2D> &p_texture) { } void CPUParticles2D::_texture_changed() { - if (texture.is_valid()) { update(); _update_mesh_texture(); @@ -233,18 +209,15 @@ void CPUParticles2D::_texture_changed() { } Ref<Texture2D> CPUParticles2D::get_texture() const { - return texture; } void CPUParticles2D::set_normalmap(const Ref<Texture2D> &p_normalmap) { - normalmap = p_normalmap; update(); } Ref<Texture2D> CPUParticles2D::get_normalmap() const { - return normalmap; } @@ -265,7 +238,6 @@ bool CPUParticles2D::get_fractional_delta() const { } String CPUParticles2D::get_configuration_warning() const { - String warnings; CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr()); @@ -283,7 +255,6 @@ String CPUParticles2D::get_configuration_warning() const { } void CPUParticles2D::restart() { - time = 0; inactive_time = 0; frame_remainder = 0; @@ -303,53 +274,44 @@ void CPUParticles2D::restart() { } void CPUParticles2D::set_direction(Vector2 p_direction) { - direction = p_direction; } Vector2 CPUParticles2D::get_direction() const { - return direction; } void CPUParticles2D::set_spread(float p_spread) { - spread = p_spread; } float CPUParticles2D::get_spread() const { - return spread; } void CPUParticles2D::set_param(Parameter p_param, float p_value) { - ERR_FAIL_INDEX(p_param, PARAM_MAX); parameters[p_param] = p_value; } float CPUParticles2D::get_param(Parameter p_param) const { - ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return parameters[p_param]; } void CPUParticles2D::set_param_randomness(Parameter p_param, float p_value) { - ERR_FAIL_INDEX(p_param, PARAM_MAX); randomness[p_param] = p_value; } float CPUParticles2D::get_param_randomness(Parameter p_param) const { - ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return randomness[p_param]; } static void _adjust_curve_range(const Ref<Curve> &p_curve, float p_min, float p_max) { - Ref<Curve> curve = p_curve; if (!curve.is_valid()) return; @@ -358,7 +320,6 @@ static void _adjust_curve_range(const Ref<Curve> &p_curve, float p_min, float p_ } void CPUParticles2D::set_param_curve(Parameter p_param, const Ref<Curve> &p_curve) { - ERR_FAIL_INDEX(p_param, PARAM_MAX); curve_parameters[p_param] = p_curve; @@ -389,7 +350,6 @@ void CPUParticles2D::set_param_curve(Parameter p_param, const Ref<Curve> &p_curv _adjust_curve_range(p_curve, -360, 360); } break; case PARAM_SCALE: { - } break; case PARAM_HUE_VARIATION: { _adjust_curve_range(p_curve, -1, 1); @@ -404,29 +364,24 @@ void CPUParticles2D::set_param_curve(Parameter p_param, const Ref<Curve> &p_curv } } Ref<Curve> CPUParticles2D::get_param_curve(Parameter p_param) const { - ERR_FAIL_INDEX_V(p_param, PARAM_MAX, Ref<Curve>()); return curve_parameters[p_param]; } void CPUParticles2D::set_color(const Color &p_color) { - color = p_color; } Color CPUParticles2D::get_color() const { - return color; } void CPUParticles2D::set_color_ramp(const Ref<Gradient> &p_ramp) { - color_ramp = p_ramp; } Ref<Gradient> CPUParticles2D::get_color_ramp() const { - return color_ramp; } @@ -447,49 +402,39 @@ void CPUParticles2D::set_emission_shape(EmissionShape p_shape) { } void CPUParticles2D::set_emission_sphere_radius(float p_radius) { - emission_sphere_radius = p_radius; } void CPUParticles2D::set_emission_rect_extents(Vector2 p_extents) { - emission_rect_extents = p_extents; } void CPUParticles2D::set_emission_points(const Vector<Vector2> &p_points) { - emission_points = p_points; } void CPUParticles2D::set_emission_normals(const Vector<Vector2> &p_normals) { - emission_normals = p_normals; } void CPUParticles2D::set_emission_colors(const Vector<Color> &p_colors) { - emission_colors = p_colors; } float CPUParticles2D::get_emission_sphere_radius() const { - return emission_sphere_radius; } Vector2 CPUParticles2D::get_emission_rect_extents() const { - return emission_rect_extents; } Vector<Vector2> CPUParticles2D::get_emission_points() const { - return emission_points; } Vector<Vector2> CPUParticles2D::get_emission_normals() const { - return emission_normals; } Vector<Color> CPUParticles2D::get_emission_colors() const { - return emission_colors; } @@ -497,17 +442,14 @@ CPUParticles2D::EmissionShape CPUParticles2D::get_emission_shape() const { return emission_shape; } void CPUParticles2D::set_gravity(const Vector2 &p_gravity) { - gravity = p_gravity; } Vector2 CPUParticles2D::get_gravity() const { - return gravity; } void CPUParticles2D::_validate_property(PropertyInfo &property) const { - if (property.name == "color" && color_ramp.is_valid()) { property.usage = 0; } @@ -538,7 +480,6 @@ void CPUParticles2D::_validate_property(PropertyInfo &property) const { } static uint32_t idhash(uint32_t x) { - x = ((x >> uint32_t(16)) ^ x) * uint32_t(0x45d9f3b); x = ((x >> uint32_t(16)) ^ x) * uint32_t(0x45d9f3b); x = (x >> uint32_t(16)) ^ x; @@ -559,7 +500,6 @@ static float rand_from_seed(uint32_t &seed) { } void CPUParticles2D::_update_internal() { - if (particles.size() == 0 || !is_visible_in_tree()) { _set_redraw(false); return; @@ -585,7 +525,6 @@ void CPUParticles2D::_update_internal() { _set_redraw(true); if (time == 0 && pre_process_time > 0.0) { - float frame_time; if (fixed_fps > 0) frame_time = 1.0 / fixed_fps; @@ -627,7 +566,6 @@ void CPUParticles2D::_update_internal() { } void CPUParticles2D::_particles_process(float p_delta) { - p_delta *= speed_scale; int pcount = particles.size(); @@ -657,7 +595,6 @@ void CPUParticles2D::_particles_process(float p_delta) { float system_phase = time / lifetime; for (int i = 0; i < pcount; i++) { - Particle &p = parray[i]; if (!emitting && !p.active) @@ -715,7 +652,6 @@ void CPUParticles2D::_particles_process(float p_delta) { } if (restart) { - if (!emitting) { p.active = false; continue; @@ -774,7 +710,6 @@ void CPUParticles2D::_particles_process(float p_delta) { } break; case EMISSION_SHAPE_POINTS: case EMISSION_SHAPE_DIRECTED_POINTS: { - int pc = emission_points.size(); if (pc == 0) break; @@ -806,7 +741,6 @@ void CPUParticles2D::_particles_process(float p_delta) { } else if (p.time > p.lifetime) { p.active = false; } else { - uint32_t alt_seed = p.seed; p.time += local_delta; @@ -890,7 +824,6 @@ void CPUParticles2D::_particles_process(float p_delta) { } if (parameters[PARAM_DAMPING] + tex_damping > 0.0) { - float v = p.velocity.length(); float damp = (parameters[PARAM_DAMPING] + tex_damping) * Math::lerp(1.0f, rand_from_seed(alt_seed), randomness[PARAM_DAMPING]); v -= damp * local_delta; @@ -949,7 +882,6 @@ void CPUParticles2D::_particles_process(float p_delta) { if (flags[FLAG_ALIGN_Y_TO_VELOCITY]) { if (p.velocity.length() > 0.0) { - p.transform.elements[1] = p.velocity.normalized(); p.transform.elements[0] = p.transform.elements[1].tangent(); } @@ -998,7 +930,6 @@ void CPUParticles2D::_update_particle_data_buffer() { } for (int i = 0; i < pc; i++) { - int idx = order ? order[i] : i; Transform2D t = r[idx].transform; @@ -1008,7 +939,6 @@ void CPUParticles2D::_update_particle_data_buffer() { } if (r[idx].active) { - ptr[0] = t.elements[0][0]; ptr[1] = t.elements[1][0]; ptr[2] = 0; @@ -1065,14 +995,12 @@ void CPUParticles2D::_set_redraw(bool p_redraw) { } void CPUParticles2D::_update_render_thread() { - MutexLock lock(update_mutex); RS::get_singleton()->multimesh_set_buffer(multimesh, particle_data); } void CPUParticles2D::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { set_process_internal(emitting); } @@ -1107,11 +1035,9 @@ void CPUParticles2D::_notification(int p_what) { } if (p_what == NOTIFICATION_TRANSFORM_CHANGED) { - inv_emission_transform = get_global_transform().affine_inverse(); if (!local_coords) { - int pc = particles.size(); float *w = particle_data.ptrw(); @@ -1119,11 +1045,9 @@ void CPUParticles2D::_notification(int p_what) { float *ptr = w; for (int i = 0; i < pc; i++) { - Transform2D t = inv_emission_transform * r[i].transform; if (r[i].active) { - ptr[0] = t.elements[0][0]; ptr[1] = t.elements[1][0]; ptr[2] = 0; @@ -1144,7 +1068,6 @@ void CPUParticles2D::_notification(int p_what) { } void CPUParticles2D::convert_from_particles(Node *p_particles) { - GPUParticles2D *particles = Object::cast_to<GPUParticles2D>(p_particles); ERR_FAIL_COND_MSG(!particles, "Only GPUParticles2D nodes can be converted to CPUParticles2D."); @@ -1219,7 +1142,6 @@ void CPUParticles2D::convert_from_particles(Node *p_particles) { } void CPUParticles2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &CPUParticles2D::set_emitting); ClassDB::bind_method(D_METHOD("set_amount", "amount"), &CPUParticles2D::set_amount); ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &CPUParticles2D::set_lifetime); @@ -1422,7 +1344,6 @@ void CPUParticles2D::_bind_methods() { } CPUParticles2D::CPUParticles2D() { - time = 0; inactive_time = 0; frame_remainder = 0; diff --git a/scene/2d/cpu_particles_2d.h b/scene/2d/cpu_particles_2d.h index 18d0caceed..747f06b90d 100644 --- a/scene/2d/cpu_particles_2d.h +++ b/scene/2d/cpu_particles_2d.h @@ -124,7 +124,6 @@ private: const Particle *particles; Vector2 axis; bool operator()(int p_a, int p_b) const { - return axis.dot(particles[p_a].transform[2]) < axis.dot(particles[p_b].transform[2]); } }; diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp index de3f8fa09e..a76114a6c3 100644 --- a/scene/2d/gpu_particles_2d.cpp +++ b/scene/2d/gpu_particles_2d.cpp @@ -39,7 +39,6 @@ #endif void GPUParticles2D::set_emitting(bool p_emitting) { - RS::get_singleton()->particles_set_emitting(particles, p_emitting); if (p_emitting && one_shot) { @@ -50,25 +49,21 @@ void GPUParticles2D::set_emitting(bool p_emitting) { } void GPUParticles2D::set_amount(int p_amount) { - ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles cannot be smaller than 1."); amount = p_amount; RS::get_singleton()->particles_set_amount(particles, amount); } void GPUParticles2D::set_lifetime(float p_lifetime) { - ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0."); lifetime = p_lifetime; RS::get_singleton()->particles_set_lifetime(particles, lifetime); } void GPUParticles2D::set_one_shot(bool p_enable) { - one_shot = p_enable; RS::get_singleton()->particles_set_one_shot(particles, one_shot); if (is_emitting()) { - set_process_internal(true); if (!one_shot) RenderingServer::get_singleton()->particles_restart(particles); @@ -78,22 +73,18 @@ void GPUParticles2D::set_one_shot(bool p_enable) { set_process_internal(false); } void GPUParticles2D::set_pre_process_time(float p_time) { - pre_process_time = p_time; RS::get_singleton()->particles_set_pre_process_time(particles, pre_process_time); } void GPUParticles2D::set_explosiveness_ratio(float p_ratio) { - explosiveness_ratio = p_ratio; RS::get_singleton()->particles_set_explosiveness_ratio(particles, explosiveness_ratio); } void GPUParticles2D::set_randomness_ratio(float p_ratio) { - randomness_ratio = p_ratio; RS::get_singleton()->particles_set_randomness_ratio(particles, randomness_ratio); } void GPUParticles2D::set_visibility_rect(const Rect2 &p_visibility_rect) { - visibility_rect = p_visibility_rect; AABB aabb; aabb.position.x = p_visibility_rect.position.x; @@ -107,7 +98,6 @@ void GPUParticles2D::set_visibility_rect(const Rect2 &p_visibility_rect) { update(); } void GPUParticles2D::set_use_local_coordinates(bool p_enable) { - local_coords = p_enable; RS::get_singleton()->particles_set_use_local_coordinates(particles, local_coords); set_notify_transform(!p_enable); @@ -117,7 +107,6 @@ void GPUParticles2D::set_use_local_coordinates(bool p_enable) { } void GPUParticles2D::_update_particle_emission_transform() { - Transform2D xf2d = get_global_transform(); Transform xf; xf.basis.set_axis(0, Vector3(xf2d.get_axis(0).x, xf2d.get_axis(0).y, 0)); @@ -128,7 +117,6 @@ void GPUParticles2D::_update_particle_emission_transform() { } void GPUParticles2D::set_process_material(const Ref<Material> &p_material) { - process_material = p_material; Ref<ParticlesMaterial> pm = p_material; if (pm.is_valid() && !pm->get_flag(ParticlesMaterial::FLAG_DISABLE_Z) && pm->get_gravity() == Vector3(0, -9.8, 0)) { @@ -145,66 +133,52 @@ void GPUParticles2D::set_process_material(const Ref<Material> &p_material) { } void GPUParticles2D::set_speed_scale(float p_scale) { - speed_scale = p_scale; RS::get_singleton()->particles_set_speed_scale(particles, p_scale); } bool GPUParticles2D::is_emitting() const { - return RS::get_singleton()->particles_get_emitting(particles); } int GPUParticles2D::get_amount() const { - return amount; } float GPUParticles2D::get_lifetime() const { - return lifetime; } bool GPUParticles2D::get_one_shot() const { - return one_shot; } float GPUParticles2D::get_pre_process_time() const { - return pre_process_time; } float GPUParticles2D::get_explosiveness_ratio() const { - return explosiveness_ratio; } float GPUParticles2D::get_randomness_ratio() const { - return randomness_ratio; } Rect2 GPUParticles2D::get_visibility_rect() const { - return visibility_rect; } bool GPUParticles2D::get_use_local_coordinates() const { - return local_coords; } Ref<Material> GPUParticles2D::get_process_material() const { - return process_material; } float GPUParticles2D::get_speed_scale() const { - return speed_scale; } void GPUParticles2D::set_draw_order(DrawOrder p_order) { - draw_order = p_order; RS::get_singleton()->particles_set_draw_order(particles, RS::ParticlesDrawOrder(p_order)); } GPUParticles2D::DrawOrder GPUParticles2D::get_draw_order() const { - return draw_order; } @@ -227,7 +201,6 @@ bool GPUParticles2D::get_fractional_delta() const { } String GPUParticles2D::get_configuration_warning() const { - if (RenderingServer::get_singleton()->is_low_end()) { return TTR("GPU-based particles are not supported by the GLES2 video driver.\nUse the CPUParticles2D node instead. You can use the \"Convert to CPUParticles2D\" option for this purpose."); } @@ -239,7 +212,6 @@ String GPUParticles2D::get_configuration_warning() const { warnings += "\n"; warnings += "- " + TTR("A material to process the particles is not assigned, so no behavior is imprinted."); } else { - CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr()); if (get_material().is_null() || (mat && !mat->get_particles_animation())) { @@ -258,7 +230,6 @@ String GPUParticles2D::get_configuration_warning() const { } Rect2 GPUParticles2D::capture_rect() const { - AABB aabb = RS::get_singleton()->particles_get_current_aabb(particles); Rect2 r; r.position.x = aabb.position.x; @@ -278,7 +249,6 @@ Ref<Texture2D> GPUParticles2D::get_texture() const { } void GPUParticles2D::set_normal_map(const Ref<Texture2D> &p_normal_map) { - normal_map = p_normal_map; update(); } @@ -296,9 +266,7 @@ void GPUParticles2D::restart() { } void GPUParticles2D::_notification(int p_what) { - if (p_what == NOTIFICATION_DRAW) { - RID texture_rid; if (texture.is_valid()) texture_rid = texture->get_rid(); @@ -310,7 +278,6 @@ void GPUParticles2D::_notification(int p_what) { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint() && (this == get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->is_a_parent_of(this))) { - draw_rect(visibility_rect, Color(0, 0.7, 0.9, 0.4), false); } #endif @@ -320,7 +287,6 @@ void GPUParticles2D::_notification(int p_what) { if (can_process()) { RS::get_singleton()->particles_set_speed_scale(particles, speed_scale); } else { - RS::get_singleton()->particles_set_speed_scale(particles, 0); } } @@ -330,7 +296,6 @@ void GPUParticles2D::_notification(int p_what) { } if (p_what == NOTIFICATION_INTERNAL_PROCESS) { - if (one_shot && !is_emitting()) { _change_notify(); set_process_internal(false); @@ -339,7 +304,6 @@ void GPUParticles2D::_notification(int p_what) { } void GPUParticles2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &GPUParticles2D::set_emitting); ClassDB::bind_method(D_METHOD("set_amount", "amount"), &GPUParticles2D::set_amount); ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &GPUParticles2D::set_lifetime); @@ -407,7 +371,6 @@ void GPUParticles2D::_bind_methods() { } GPUParticles2D::GPUParticles2D() { - particles = RS::get_singleton()->particles_create(); one_shot = false; // Needed so that set_emitting doesn't access uninitialized values @@ -427,6 +390,5 @@ GPUParticles2D::GPUParticles2D() { } GPUParticles2D::~GPUParticles2D() { - RS::get_singleton()->free(particles); } diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp index 4d49f4762f..07a6926d4f 100644 --- a/scene/2d/joints_2d.cpp +++ b/scene/2d/joints_2d.cpp @@ -35,7 +35,6 @@ #include "servers/physics_server_2d.h" void Joint2D::_update_joint(bool p_only_free) { - if (joint.is_valid()) { if (ba.is_valid() && bb.is_valid() && exclude_from_collision) PhysicsServer2D::get_singleton()->joint_disable_collisions_between_bodies(joint, false); @@ -75,7 +74,6 @@ void Joint2D::_update_joint(bool p_only_free) { } void Joint2D::set_node_a(const NodePath &p_node_a) { - if (a == p_node_a) return; @@ -84,26 +82,21 @@ void Joint2D::set_node_a(const NodePath &p_node_a) { } NodePath Joint2D::get_node_a() const { - return a; } void Joint2D::set_node_b(const NodePath &p_node_b) { - if (b == p_node_b) return; b = p_node_b; _update_joint(); } NodePath Joint2D::get_node_b() const { - return b; } void Joint2D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_READY: { _update_joint(); } break; @@ -116,19 +109,16 @@ void Joint2D::_notification(int p_what) { } void Joint2D::set_bias(real_t p_bias) { - bias = p_bias; if (joint.is_valid()) PhysicsServer2D::get_singleton()->get_singleton()->joint_set_param(joint, PhysicsServer2D::JOINT_PARAM_BIAS, bias); } real_t Joint2D::get_bias() const { - return bias; } void Joint2D::set_exclude_nodes_from_collision(bool p_enable) { - if (exclude_from_collision == p_enable) return; @@ -138,12 +128,10 @@ void Joint2D::set_exclude_nodes_from_collision(bool p_enable) { } bool Joint2D::get_exclude_nodes_from_collision() const { - return exclude_from_collision; } void Joint2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint2D::set_node_a); ClassDB::bind_method(D_METHOD("get_node_a"), &Joint2D::get_node_a); @@ -163,7 +151,6 @@ void Joint2D::_bind_methods() { } Joint2D::Joint2D() { - bias = 0; exclude_from_collision = true; } @@ -173,10 +160,8 @@ Joint2D::Joint2D() { /////////////////////////////////////////////////////////////////////////////// void PinJoint2D::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_DRAW: { - if (!is_inside_tree()) break; @@ -191,14 +176,12 @@ void PinJoint2D::_notification(int p_what) { } RID PinJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) { - RID pj = PhysicsServer2D::get_singleton()->pin_joint_create(get_global_transform().get_origin(), body_a->get_rid(), body_b ? body_b->get_rid() : RID()); PhysicsServer2D::get_singleton()->pin_joint_set_param(pj, PhysicsServer2D::PIN_JOINT_SOFTNESS, softness); return pj; } void PinJoint2D::set_softness(real_t p_softness) { - softness = p_softness; update(); if (get_joint().is_valid()) @@ -206,12 +189,10 @@ void PinJoint2D::set_softness(real_t p_softness) { } real_t PinJoint2D::get_softness() const { - return softness; } void PinJoint2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_softness", "softness"), &PinJoint2D::set_softness); ClassDB::bind_method(D_METHOD("get_softness"), &PinJoint2D::get_softness); @@ -219,7 +200,6 @@ void PinJoint2D::_bind_methods() { } PinJoint2D::PinJoint2D() { - softness = 0; } @@ -228,7 +208,6 @@ PinJoint2D::PinJoint2D() { /////////////////////////////////////////////////////////////////////////////// void GrooveJoint2D::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_DRAW: { if (!is_inside_tree()) @@ -247,7 +226,6 @@ void GrooveJoint2D::_notification(int p_what) { } RID GrooveJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) { - Transform2D gt = get_global_transform(); Vector2 groove_A1 = gt.get_origin(); Vector2 groove_A2 = gt.xform(Vector2(0, length)); @@ -257,29 +235,24 @@ RID GrooveJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b } void GrooveJoint2D::set_length(real_t p_length) { - length = p_length; update(); } real_t GrooveJoint2D::get_length() const { - return length; } void GrooveJoint2D::set_initial_offset(real_t p_initial_offset) { - initial_offset = p_initial_offset; update(); } real_t GrooveJoint2D::get_initial_offset() const { - return initial_offset; } void GrooveJoint2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_length", "length"), &GrooveJoint2D::set_length); ClassDB::bind_method(D_METHOD("get_length"), &GrooveJoint2D::get_length); ClassDB::bind_method(D_METHOD("set_initial_offset", "offset"), &GrooveJoint2D::set_initial_offset); @@ -290,7 +263,6 @@ void GrooveJoint2D::_bind_methods() { } GrooveJoint2D::GrooveJoint2D() { - length = 50; initial_offset = 25; } @@ -300,10 +272,8 @@ GrooveJoint2D::GrooveJoint2D() { /////////////////////////////////////////////////////////////////////////////// void DampedSpringJoint2D::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_DRAW: { - if (!is_inside_tree()) break; @@ -319,7 +289,6 @@ void DampedSpringJoint2D::_notification(int p_what) { } RID DampedSpringJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) { - Transform2D gt = get_global_transform(); Vector2 anchor_A = gt.get_origin(); Vector2 anchor_B = gt.xform(Vector2(0, length)); @@ -334,18 +303,15 @@ RID DampedSpringJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D * } void DampedSpringJoint2D::set_length(real_t p_length) { - length = p_length; update(); } real_t DampedSpringJoint2D::get_length() const { - return length; } void DampedSpringJoint2D::set_rest_length(real_t p_rest_length) { - rest_length = p_rest_length; update(); if (get_joint().is_valid()) @@ -353,12 +319,10 @@ void DampedSpringJoint2D::set_rest_length(real_t p_rest_length) { } real_t DampedSpringJoint2D::get_rest_length() const { - return rest_length; } void DampedSpringJoint2D::set_stiffness(real_t p_stiffness) { - stiffness = p_stiffness; update(); if (get_joint().is_valid()) @@ -366,12 +330,10 @@ void DampedSpringJoint2D::set_stiffness(real_t p_stiffness) { } real_t DampedSpringJoint2D::get_stiffness() const { - return stiffness; } void DampedSpringJoint2D::set_damping(real_t p_damping) { - damping = p_damping; update(); if (get_joint().is_valid()) @@ -379,12 +341,10 @@ void DampedSpringJoint2D::set_damping(real_t p_damping) { } real_t DampedSpringJoint2D::get_damping() const { - return damping; } void DampedSpringJoint2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_length", "length"), &DampedSpringJoint2D::set_length); ClassDB::bind_method(D_METHOD("get_length"), &DampedSpringJoint2D::get_length); ClassDB::bind_method(D_METHOD("set_rest_length", "rest_length"), &DampedSpringJoint2D::set_rest_length); @@ -401,7 +361,6 @@ void DampedSpringJoint2D::_bind_methods() { } DampedSpringJoint2D::DampedSpringJoint2D() { - length = 50; rest_length = 0; stiffness = 20; diff --git a/scene/2d/joints_2d.h b/scene/2d/joints_2d.h index f1750e56b6..9a3bea4407 100644 --- a/scene/2d/joints_2d.h +++ b/scene/2d/joints_2d.h @@ -36,7 +36,6 @@ class PhysicsBody2D; class Joint2D : public Node2D { - GDCLASS(Joint2D, Node2D); RID joint; @@ -74,7 +73,6 @@ public: }; class PinJoint2D : public Joint2D { - GDCLASS(PinJoint2D, Joint2D); real_t softness; @@ -92,7 +90,6 @@ public: }; class GrooveJoint2D : public Joint2D { - GDCLASS(GrooveJoint2D, Joint2D); real_t length; @@ -114,7 +111,6 @@ public: }; class DampedSpringJoint2D : public Joint2D { - GDCLASS(DampedSpringJoint2D, Joint2D); real_t stiffness; diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index b3d54b81f8..ed69a4544e 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -80,7 +80,6 @@ Rect2 Light2D::get_anchorable_rect() const { } void Light2D::_update_light_visibility() { - if (!is_inside_tree()) return; @@ -104,29 +103,24 @@ void Light2D::_update_light_visibility() { } void Light2D::set_enabled(bool p_enabled) { - enabled = p_enabled; _update_light_visibility(); } bool Light2D::is_enabled() const { - return enabled; } void Light2D::set_editor_only(bool p_editor_only) { - editor_only = p_editor_only; _update_light_visibility(); } bool Light2D::is_editor_only() const { - return editor_only; } void Light2D::set_texture(const Ref<Texture2D> &p_texture) { - texture = p_texture; if (texture.is_valid()) RS::get_singleton()->canvas_light_set_texture(canvas_light, texture->get_rid()); @@ -137,12 +131,10 @@ void Light2D::set_texture(const Ref<Texture2D> &p_texture) { } Ref<Texture2D> Light2D::get_texture() const { - return texture; } void Light2D::set_texture_offset(const Vector2 &p_offset) { - texture_offset = p_offset; RS::get_singleton()->canvas_light_set_texture_offset(canvas_light, texture_offset); item_rect_changed(); @@ -150,44 +142,36 @@ void Light2D::set_texture_offset(const Vector2 &p_offset) { } Vector2 Light2D::get_texture_offset() const { - return texture_offset; } void Light2D::set_color(const Color &p_color) { - color = p_color; RS::get_singleton()->canvas_light_set_color(canvas_light, color); } Color Light2D::get_color() const { - return color; } void Light2D::set_height(float p_height) { - height = p_height; RS::get_singleton()->canvas_light_set_height(canvas_light, height); } float Light2D::get_height() const { - return height; } void Light2D::set_energy(float p_energy) { - energy = p_energy; RS::get_singleton()->canvas_light_set_energy(canvas_light, energy); } float Light2D::get_energy() const { - return energy; } void Light2D::set_texture_scale(float p_scale) { - _scale = p_scale; // Avoid having 0 scale values, can lead to errors in physics and rendering. if (_scale == 0) { @@ -198,101 +182,82 @@ void Light2D::set_texture_scale(float p_scale) { } float Light2D::get_texture_scale() const { - return _scale; } void Light2D::set_z_range_min(int p_min_z) { - z_min = p_min_z; RS::get_singleton()->canvas_light_set_z_range(canvas_light, z_min, z_max); } int Light2D::get_z_range_min() const { - return z_min; } void Light2D::set_z_range_max(int p_max_z) { - z_max = p_max_z; RS::get_singleton()->canvas_light_set_z_range(canvas_light, z_min, z_max); } int Light2D::get_z_range_max() const { - return z_max; } void Light2D::set_layer_range_min(int p_min_layer) { - layer_min = p_min_layer; RS::get_singleton()->canvas_light_set_layer_range(canvas_light, layer_min, layer_max); } int Light2D::get_layer_range_min() const { - return layer_min; } void Light2D::set_layer_range_max(int p_max_layer) { - layer_max = p_max_layer; RS::get_singleton()->canvas_light_set_layer_range(canvas_light, layer_min, layer_max); } int Light2D::get_layer_range_max() const { - return layer_max; } void Light2D::set_item_cull_mask(int p_mask) { - item_mask = p_mask; RS::get_singleton()->canvas_light_set_item_cull_mask(canvas_light, item_mask); } int Light2D::get_item_cull_mask() const { - return item_mask; } void Light2D::set_item_shadow_cull_mask(int p_mask) { - item_shadow_mask = p_mask; RS::get_singleton()->canvas_light_set_item_shadow_cull_mask(canvas_light, item_shadow_mask); } int Light2D::get_item_shadow_cull_mask() const { - return item_shadow_mask; } void Light2D::set_mode(Mode p_mode) { - mode = p_mode; RS::get_singleton()->canvas_light_set_mode(canvas_light, RS::CanvasLightMode(p_mode)); } Light2D::Mode Light2D::get_mode() const { - return mode; } void Light2D::set_shadow_enabled(bool p_enabled) { - shadow = p_enabled; RS::get_singleton()->canvas_light_set_shadow_enabled(canvas_light, shadow); } bool Light2D::is_shadow_enabled() const { - return shadow; } void Light2D::set_shadow_buffer_size(int p_size) { - shadow_buffer_size = p_size; RS::get_singleton()->canvas_light_set_shadow_buffer_size(canvas_light, shadow_buffer_size); } int Light2D::get_shadow_buffer_size() const { - return shadow_buffer_size; } @@ -303,7 +268,6 @@ void Light2D::set_shadow_filter(ShadowFilter p_filter) { } Light2D::ShadowFilter Light2D::get_shadow_filter() const { - return shadow_filter; } @@ -317,31 +281,25 @@ Color Light2D::get_shadow_color() const { } void Light2D::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, get_canvas()); _update_light_visibility(); } if (p_what == NOTIFICATION_TRANSFORM_CHANGED) { - RS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform()); } if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - _update_light_visibility(); } if (p_what == NOTIFICATION_EXIT_TREE) { - RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, RID()); _update_light_visibility(); } } String Light2D::get_configuration_warning() const { - if (!texture.is_valid()) { return TTR("A texture with the shape of the light must be supplied to the \"Texture\" property."); } @@ -350,18 +308,15 @@ String Light2D::get_configuration_warning() const { } void Light2D::set_shadow_smooth(float p_amount) { - shadow_smooth = p_amount; RS::get_singleton()->canvas_light_set_shadow_smooth(canvas_light, shadow_smooth); } float Light2D::get_shadow_smooth() const { - return shadow_smooth; } void Light2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &Light2D::set_enabled); ClassDB::bind_method(D_METHOD("is_enabled"), &Light2D::is_enabled); @@ -457,7 +412,6 @@ void Light2D::_bind_methods() { } Light2D::Light2D() { - canvas_light = RenderingServer::get_singleton()->canvas_light_create(); enabled = true; editor_only = false; @@ -482,6 +436,5 @@ Light2D::Light2D() { } Light2D::~Light2D() { - RenderingServer::get_singleton()->free(canvas_light); } diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h index 7134029441..0d5e8d674a 100644 --- a/scene/2d/light_2d.h +++ b/scene/2d/light_2d.h @@ -34,7 +34,6 @@ #include "scene/2d/node_2d.h" class Light2D : public Node2D { - GDCLASS(Light2D, Node2D); public: diff --git a/scene/2d/light_occluder_2d.cpp b/scene/2d/light_occluder_2d.cpp index bd1a820aec..80a0c0c40a 100644 --- a/scene/2d/light_occluder_2d.cpp +++ b/scene/2d/light_occluder_2d.cpp @@ -36,7 +36,6 @@ #ifdef TOOLS_ENABLED Rect2 OccluderPolygon2D::_edit_get_rect() const { - if (rect_cache_dirty) { if (closed) { const Vector2 *r = polygon.ptr(); @@ -67,7 +66,6 @@ Rect2 OccluderPolygon2D::_edit_get_rect() const { } bool OccluderPolygon2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - if (closed) { return Geometry::is_point_in_polygon(p_point, Variant(polygon)); } else { @@ -85,7 +83,6 @@ bool OccluderPolygon2D::_edit_is_selected_on_click(const Point2 &p_point, double #endif void OccluderPolygon2D::set_polygon(const Vector<Vector2> &p_polygon) { - polygon = p_polygon; rect_cache_dirty = true; RS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon, p_polygon, closed); @@ -93,12 +90,10 @@ void OccluderPolygon2D::set_polygon(const Vector<Vector2> &p_polygon) { } Vector<Vector2> OccluderPolygon2D::get_polygon() const { - return polygon; } void OccluderPolygon2D::set_closed(bool p_closed) { - if (closed == p_closed) return; closed = p_closed; @@ -108,28 +103,23 @@ void OccluderPolygon2D::set_closed(bool p_closed) { } bool OccluderPolygon2D::is_closed() const { - return closed; } void OccluderPolygon2D::set_cull_mode(CullMode p_mode) { - cull = p_mode; RS::get_singleton()->canvas_occluder_polygon_set_cull_mode(occ_polygon, RS::CanvasOccluderPolygonCullMode(p_mode)); } OccluderPolygon2D::CullMode OccluderPolygon2D::get_cull_mode() const { - return cull; } RID OccluderPolygon2D::get_rid() const { - return occ_polygon; } void OccluderPolygon2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_closed", "closed"), &OccluderPolygon2D::set_closed); ClassDB::bind_method(D_METHOD("is_closed"), &OccluderPolygon2D::is_closed); @@ -149,7 +139,6 @@ void OccluderPolygon2D::_bind_methods() { } OccluderPolygon2D::OccluderPolygon2D() { - occ_polygon = RS::get_singleton()->canvas_occluder_polygon_create(); closed = true; cull = CULL_DISABLED; @@ -157,40 +146,31 @@ OccluderPolygon2D::OccluderPolygon2D() { } OccluderPolygon2D::~OccluderPolygon2D() { - RS::get_singleton()->free(occ_polygon); } void LightOccluder2D::_poly_changed() { - #ifdef DEBUG_ENABLED update(); #endif } void LightOccluder2D::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_CANVAS) { - RS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, get_canvas()); RS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform()); RS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree()); } if (p_what == NOTIFICATION_TRANSFORM_CHANGED) { - RS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform()); } if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - RS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree()); } if (p_what == NOTIFICATION_DRAW) { - if (Engine::get_singleton()->is_editor_hint()) { - if (occluder_polygon.is_valid()) { - Vector<Vector2> poly = occluder_polygon->get_polygon(); if (poly.size()) { @@ -199,11 +179,9 @@ void LightOccluder2D::_notification(int p_what) { color.push_back(Color(0, 0, 0, 0.6)); draw_polygon(Variant(poly), color); } else { - int ps = poly.size(); const Vector2 *r = poly.ptr(); for (int i = 0; i < ps - 1; i++) { - draw_line(r[i], r[i + 1], Color(0, 0, 0, 0.6), 3); } } @@ -213,25 +191,21 @@ void LightOccluder2D::_notification(int p_what) { } if (p_what == NOTIFICATION_EXIT_CANVAS) { - RS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, RID()); } } #ifdef TOOLS_ENABLED Rect2 LightOccluder2D::_edit_get_rect() const { - return occluder_polygon.is_valid() ? occluder_polygon->_edit_get_rect() : Rect2(); } bool LightOccluder2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - return occluder_polygon.is_valid() ? occluder_polygon->_edit_is_selected_on_click(p_point, p_tolerance) : false; } #endif void LightOccluder2D::set_occluder_polygon(const Ref<OccluderPolygon2D> &p_polygon) { - #ifdef DEBUG_ENABLED if (occluder_polygon.is_valid()) occluder_polygon->disconnect("changed", callable_mp(this, &LightOccluder2D::_poly_changed)); @@ -251,23 +225,19 @@ void LightOccluder2D::set_occluder_polygon(const Ref<OccluderPolygon2D> &p_polyg } Ref<OccluderPolygon2D> LightOccluder2D::get_occluder_polygon() const { - return occluder_polygon; } void LightOccluder2D::set_occluder_light_mask(int p_mask) { - mask = p_mask; RS::get_singleton()->canvas_light_occluder_set_light_mask(occluder, mask); } int LightOccluder2D::get_occluder_light_mask() const { - return mask; } String LightOccluder2D::get_configuration_warning() const { - if (!occluder_polygon.is_valid()) { return TTR("An occluder polygon must be set (or drawn) for this occluder to take effect."); } @@ -280,7 +250,6 @@ String LightOccluder2D::get_configuration_warning() const { } void LightOccluder2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_occluder_polygon", "polygon"), &LightOccluder2D::set_occluder_polygon); ClassDB::bind_method(D_METHOD("get_occluder_polygon"), &LightOccluder2D::get_occluder_polygon); @@ -292,13 +261,11 @@ void LightOccluder2D::_bind_methods() { } LightOccluder2D::LightOccluder2D() { - occluder = RS::get_singleton()->canvas_light_occluder_create(); mask = 1; set_notify_transform(true); } LightOccluder2D::~LightOccluder2D() { - RS::get_singleton()->free(occluder); } diff --git a/scene/2d/light_occluder_2d.h b/scene/2d/light_occluder_2d.h index 83702f2875..eba67edfe4 100644 --- a/scene/2d/light_occluder_2d.h +++ b/scene/2d/light_occluder_2d.h @@ -34,7 +34,6 @@ #include "scene/2d/node_2d.h" class OccluderPolygon2D : public Resource { - GDCLASS(OccluderPolygon2D, Resource); public: diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp index 43c54ffd17..0ec58ec176 100644 --- a/scene/2d/line_2d.cpp +++ b/scene/2d/line_2d.cpp @@ -52,7 +52,6 @@ Line2D::Line2D() { #ifdef TOOLS_ENABLED Rect2 Line2D::_edit_get_rect() const { - if (_points.size() == 0) return Rect2(0, 0, 0, 0); Vector2 d = Vector2(_width, _width); @@ -69,7 +68,6 @@ bool Line2D::_edit_use_rect() const { } bool Line2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - const real_t d = _width / 2 + p_tolerance; const Vector2 *points = _points.ptr(); for (int i = 0; i < _points.size() - 1; i++) { @@ -168,7 +166,6 @@ Color Line2D::get_default_color() const { } void Line2D::set_gradient(const Ref<Gradient> &p_gradient) { - // Cleanup previous connection if any if (_gradient.is_valid()) { _gradient->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Line2D::_gradient_changed)); @@ -350,7 +347,6 @@ void Line2D::_curve_changed() { // static void Line2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_points", "points"), &Line2D::set_points); ClassDB::bind_method(D_METHOD("get_points"), &Line2D::get_points); diff --git a/scene/2d/line_2d.h b/scene/2d/line_2d.h index 51706befdb..bccbcbdcb9 100644 --- a/scene/2d/line_2d.h +++ b/scene/2d/line_2d.h @@ -34,7 +34,6 @@ #include "node_2d.h" class Line2D : public Node2D { - GDCLASS(Line2D, Node2D); public: diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp index 6b06f2227a..56293a7b8d 100644 --- a/scene/2d/line_builder.cpp +++ b/scene/2d/line_builder.cpp @@ -117,7 +117,6 @@ void LineBuilder::clear_output() { } void LineBuilder::build() { - // Need at least 2 points to draw a line if (points.size() < 2) { clear_output(); @@ -220,7 +219,6 @@ void LineBuilder::build() { // For each additional segment for (int i = 1; i < len - 1; ++i) { - pos1 = points[i]; Vector2 pos2 = points[i + 1]; @@ -359,7 +357,6 @@ void LineBuilder::build() { // Add joint geometry if (current_joint_mode != Line2D::LINE_JOINT_SHARP) { - /* ________________ cbegin * / \ * / \ @@ -541,7 +538,6 @@ void LineBuilder::strip_add_tri(Vector2 up, Orientation orientation) { } void LineBuilder::strip_add_arc(Vector2 center, float angle_delta, Orientation orientation) { - // Take the two last vertices and extrude an arc made of triangles // that all share one of the initial vertices @@ -570,7 +566,6 @@ void LineBuilder::strip_add_arc(Vector2 center, float angle_delta, Orientation o } void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Color color, Rect2 uv_rect) { - // Make a standalone arc that doesn't use existing vertices, // with undistorted UVs from within a square section diff --git a/scene/2d/mesh_instance_2d.cpp b/scene/2d/mesh_instance_2d.cpp index 5e258be700..b4dd09c513 100644 --- a/scene/2d/mesh_instance_2d.cpp +++ b/scene/2d/mesh_instance_2d.cpp @@ -31,7 +31,6 @@ #include "mesh_instance_2d.h" void MeshInstance2D::_notification(int p_what) { - if (p_what == NOTIFICATION_DRAW) { if (mesh.is_valid()) { draw_mesh(mesh, texture, normal_map); @@ -40,7 +39,6 @@ void MeshInstance2D::_notification(int p_what) { } void MeshInstance2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &MeshInstance2D::set_mesh); ClassDB::bind_method(D_METHOD("get_mesh"), &MeshInstance2D::get_mesh); @@ -58,18 +56,15 @@ void MeshInstance2D::_bind_methods() { } void MeshInstance2D::set_mesh(const Ref<Mesh> &p_mesh) { - mesh = p_mesh; update(); } Ref<Mesh> MeshInstance2D::get_mesh() const { - return mesh; } void MeshInstance2D::set_texture(const Ref<Texture2D> &p_texture) { - if (p_texture == texture) return; texture = p_texture; @@ -79,24 +74,20 @@ void MeshInstance2D::set_texture(const Ref<Texture2D> &p_texture) { } void MeshInstance2D::set_normal_map(const Ref<Texture2D> &p_texture) { - normal_map = p_texture; update(); } Ref<Texture2D> MeshInstance2D::get_normal_map() const { - return normal_map; } Ref<Texture2D> MeshInstance2D::get_texture() const { - return texture; } #ifdef TOOLS_ENABLED Rect2 MeshInstance2D::_edit_get_rect() const { - if (mesh.is_valid()) { AABB aabb = mesh->get_aabb(); return Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y); diff --git a/scene/2d/multimesh_instance_2d.cpp b/scene/2d/multimesh_instance_2d.cpp index 6620027020..d99d5b9b30 100644 --- a/scene/2d/multimesh_instance_2d.cpp +++ b/scene/2d/multimesh_instance_2d.cpp @@ -31,7 +31,6 @@ #include "multimesh_instance_2d.h" void MultiMeshInstance2D::_notification(int p_what) { - if (p_what == NOTIFICATION_DRAW) { if (multimesh.is_valid()) { draw_multimesh(multimesh, texture, normal_map); @@ -40,7 +39,6 @@ void MultiMeshInstance2D::_notification(int p_what) { } void MultiMeshInstance2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_multimesh", "multimesh"), &MultiMeshInstance2D::set_multimesh); ClassDB::bind_method(D_METHOD("get_multimesh"), &MultiMeshInstance2D::get_multimesh); @@ -58,18 +56,15 @@ void MultiMeshInstance2D::_bind_methods() { } void MultiMeshInstance2D::set_multimesh(const Ref<MultiMesh> &p_multimesh) { - multimesh = p_multimesh; update(); } Ref<MultiMesh> MultiMeshInstance2D::get_multimesh() const { - return multimesh; } void MultiMeshInstance2D::set_texture(const Ref<Texture2D> &p_texture) { - if (p_texture == texture) return; texture = p_texture; @@ -79,24 +74,20 @@ void MultiMeshInstance2D::set_texture(const Ref<Texture2D> &p_texture) { } Ref<Texture2D> MultiMeshInstance2D::get_texture() const { - return texture; } void MultiMeshInstance2D::set_normal_map(const Ref<Texture2D> &p_texture) { - normal_map = p_texture; update(); } Ref<Texture2D> MultiMeshInstance2D::get_normal_map() const { - return normal_map; } #ifdef TOOLS_ENABLED Rect2 MultiMeshInstance2D::_edit_get_rect() const { - if (multimesh.is_valid()) { AABB aabb = multimesh->get_aabb(); return Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y); diff --git a/scene/2d/navigation_2d.cpp b/scene/2d/navigation_2d.cpp index ae9fc0f32c..039c6f2e53 100644 --- a/scene/2d/navigation_2d.cpp +++ b/scene/2d/navigation_2d.cpp @@ -54,7 +54,6 @@ void Navigation2D::_notification(int p_what) { NavigationServer2D::get_singleton()->map_set_active(map, true); } break; case NOTIFICATION_EXIT_TREE: { - NavigationServer2D::get_singleton()->map_set_active(map, false); } break; } @@ -83,7 +82,6 @@ RID Navigation2D::get_closest_point_owner(const Vector2 &p_point) const { } Navigation2D::Navigation2D() { - map = NavigationServer2D::get_singleton()->map_create(); set_cell_size(10); // Ten pixels set_edge_connection_margin(100); diff --git a/scene/2d/navigation_2d.h b/scene/2d/navigation_2d.h index 1da13fc78a..6046bddb32 100644 --- a/scene/2d/navigation_2d.h +++ b/scene/2d/navigation_2d.h @@ -35,7 +35,6 @@ #include "scene/2d/node_2d.h" class Navigation2D : public Node2D { - GDCLASS(Navigation2D, Node2D); RID map; diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index dfeb5eea45..42dabeb488 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -35,7 +35,6 @@ #include "servers/navigation_server_2d.h" void NavigationAgent2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_target_desired_distance", "desired_distance"), &NavigationAgent2D::set_target_desired_distance); ClassDB::bind_method(D_METHOD("get_target_desired_distance"), &NavigationAgent2D::get_target_desired_distance); @@ -91,7 +90,6 @@ void NavigationAgent2D::_bind_methods() { void NavigationAgent2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { - agent_parent = Object::cast_to<Node2D>(get_parent()); NavigationServer2D::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); @@ -120,7 +118,6 @@ void NavigationAgent2D::_notification(int p_what) { } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { if (agent_parent) { - NavigationServer2D::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().get_origin()); if (!target_reached) { if (distance_to_target() < target_desired_distance) { @@ -279,7 +276,6 @@ String NavigationAgent2D::get_configuration_warning() const { } void NavigationAgent2D::update_navigation() { - if (agent_parent == nullptr) return; if (navigation == nullptr) diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp index 3eb3ef332f..2352064ae6 100644 --- a/scene/2d/navigation_obstacle_2d.cpp +++ b/scene/2d/navigation_obstacle_2d.cpp @@ -36,7 +36,6 @@ #include "servers/navigation_server_2d.h" void NavigationObstacle2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_navigation", "navigation"), &NavigationObstacle2D::set_navigation_node); ClassDB::bind_method(D_METHOD("get_navigation"), &NavigationObstacle2D::get_navigation_node); } @@ -44,7 +43,6 @@ void NavigationObstacle2D::_bind_methods() { void NavigationObstacle2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { - update_agent_shape(); // Search the navigation node and set it diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp index f3f335e66a..29f23050da 100644 --- a/scene/2d/navigation_region_2d.cpp +++ b/scene/2d/navigation_region_2d.cpp @@ -40,7 +40,6 @@ #ifdef TOOLS_ENABLED Rect2 NavigationPolygon::_edit_get_rect() const { - if (rect_cache_dirty) { item_rect = Rect2(); bool first = true; @@ -67,7 +66,6 @@ Rect2 NavigationPolygon::_edit_get_rect() const { } bool NavigationPolygon::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - for (int i = 0; i < outlines.size(); i++) { const Vector<Vector2> &outline = outlines[i]; const int outline_size = outline.size(); @@ -81,7 +79,6 @@ bool NavigationPolygon::_edit_is_selected_on_click(const Point2 &p_point, double #endif void NavigationPolygon::set_vertices(const Vector<Vector2> &p_vertices) { - { MutexLock lock(navmesh_generation); navmesh.unref(); @@ -91,12 +88,10 @@ void NavigationPolygon::set_vertices(const Vector<Vector2> &p_vertices) { } Vector<Vector2> NavigationPolygon::get_vertices() const { - return vertices; } void NavigationPolygon::_set_polygons(const TypedArray<Vector<int32_t>> &p_array) { - { MutexLock lock(navmesh_generation); navmesh.unref(); @@ -108,7 +103,6 @@ void NavigationPolygon::_set_polygons(const TypedArray<Vector<int32_t>> &p_array } Array NavigationPolygon::_get_polygons() const { - Array ret; ret.resize(polygons.size()); for (int i = 0; i < ret.size(); i++) { @@ -119,7 +113,6 @@ Array NavigationPolygon::_get_polygons() const { } void NavigationPolygon::_set_outlines(const TypedArray<Vector<Vector2>> &p_array) { - outlines.resize(p_array.size()); for (int i = 0; i < p_array.size(); i++) { outlines.write[i] = p_array[i]; @@ -128,7 +121,6 @@ void NavigationPolygon::_set_outlines(const TypedArray<Vector<Vector2>> &p_array } Array NavigationPolygon::_get_outlines() const { - Array ret; ret.resize(outlines.size()); for (int i = 0; i < ret.size(); i++) { @@ -139,7 +131,6 @@ Array NavigationPolygon::_get_outlines() const { } void NavigationPolygon::add_polygon(const Vector<int> &p_polygon) { - Polygon polygon; polygon.indices = p_polygon; polygons.push_back(polygon); @@ -150,22 +141,18 @@ void NavigationPolygon::add_polygon(const Vector<int> &p_polygon) { } void NavigationPolygon::add_outline_at_index(const Vector<Vector2> &p_outline, int p_index) { - outlines.insert(p_index, p_outline); rect_cache_dirty = true; } int NavigationPolygon::get_polygon_count() const { - return polygons.size(); } Vector<int> NavigationPolygon::get_polygon(int p_idx) { - ERR_FAIL_INDEX_V(p_idx, polygons.size(), Vector<int>()); return polygons[p_idx].indices; } void NavigationPolygon::clear_polygons() { - polygons.clear(); { MutexLock lock(navmesh_generation); @@ -200,13 +187,11 @@ Ref<NavigationMesh> NavigationPolygon::get_mesh() { } void NavigationPolygon::add_outline(const Vector<Vector2> &p_outline) { - outlines.push_back(p_outline); rect_cache_dirty = true; } int NavigationPolygon::get_outline_count() const { - return outlines.size(); } @@ -217,7 +202,6 @@ void NavigationPolygon::set_outline(int p_idx, const Vector<Vector2> &p_outline) } void NavigationPolygon::remove_outline(int p_idx) { - ERR_FAIL_INDEX(p_idx, outlines.size()); outlines.remove(p_idx); rect_cache_dirty = true; @@ -229,12 +213,10 @@ Vector<Vector2> NavigationPolygon::get_outline(int p_idx) const { } void NavigationPolygon::clear_outlines() { - outlines.clear(); rect_cache_dirty = true; } void NavigationPolygon::make_polygons_from_outlines() { - { MutexLock lock(navmesh_generation); navmesh.unref(); @@ -244,7 +226,6 @@ void NavigationPolygon::make_polygons_from_outlines() { Vector2 outside_point(-1e10, -1e10); for (int i = 0; i < outlines.size(); i++) { - Vector<Vector2> ol = outlines[i]; int olsize = ol.size(); if (olsize < 3) @@ -259,7 +240,6 @@ void NavigationPolygon::make_polygons_from_outlines() { outside_point += Vector2(0.7239784, 0.819238); //avoid precision issues for (int i = 0; i < outlines.size(); i++) { - Vector<Vector2> ol = outlines[i]; int olsize = ol.size(); if (olsize < 3) @@ -269,7 +249,6 @@ void NavigationPolygon::make_polygons_from_outlines() { int interscount = 0; //test if this is an outer outline for (int k = 0; k < outlines.size(); k++) { - if (i == k) continue; //no self intersect @@ -280,7 +259,6 @@ void NavigationPolygon::make_polygons_from_outlines() { const Vector2 *r2 = ol2.ptr(); for (int l = 0; l < olsize2; l++) { - if (Geometry::segment_intersects_segment_2d(r[0], outside_point, r2[l], r2[(l + 1) % olsize2], nullptr)) { interscount++; } @@ -316,13 +294,11 @@ void NavigationPolygon::make_polygons_from_outlines() { Map<Vector2, int> points; for (List<TriangulatorPoly>::Element *I = out_poly.front(); I; I = I->next()) { - TriangulatorPoly &tp = I->get(); struct Polygon p; for (int64_t i = 0; i < tp.GetNumPoints(); i++) { - Map<Vector2, int>::Element *E = points.find(tp[i]); if (!E) { E = points.insert(tp[i], vertices.size()); @@ -338,7 +314,6 @@ void NavigationPolygon::make_polygons_from_outlines() { } void NavigationPolygon::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_vertices", "vertices"), &NavigationPolygon::set_vertices); ClassDB::bind_method(D_METHOD("get_vertices"), &NavigationPolygon::get_vertices); @@ -368,7 +343,6 @@ void NavigationPolygon::_bind_methods() { } void NavigationRegion2D::set_enabled(bool p_enabled) { - if (enabled == p_enabled) return; enabled = p_enabled; @@ -377,12 +351,9 @@ void NavigationRegion2D::set_enabled(bool p_enabled) { return; if (!enabled) { - NavigationServer2D::get_singleton()->region_set_map(region, RID()); } else { - if (navigation) { - NavigationServer2D::get_singleton()->region_set_map(region, navigation->get_rid()); } } @@ -392,36 +363,28 @@ void NavigationRegion2D::set_enabled(bool p_enabled) { } bool NavigationRegion2D::is_enabled() const { - return enabled; } ///////////////////////////// #ifdef TOOLS_ENABLED Rect2 NavigationRegion2D::_edit_get_rect() const { - return navpoly.is_valid() ? navpoly->_edit_get_rect() : Rect2(); } bool NavigationRegion2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - return navpoly.is_valid() ? navpoly->_edit_is_selected_on_click(p_point, p_tolerance) : false; } #endif void NavigationRegion2D::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_ENTER_TREE: { - Node2D *c = this; while (c) { - navigation = Object::cast_to<Navigation2D>(c); if (navigation) { - if (enabled) { - NavigationServer2D::get_singleton()->region_set_map(region, navigation->get_rid()); } break; @@ -432,22 +395,17 @@ void NavigationRegion2D::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { - NavigationServer2D::get_singleton()->region_set_transform(region, get_global_transform()); } break; case NOTIFICATION_EXIT_TREE: { - if (navigation) { - NavigationServer2D::get_singleton()->region_set_map(region, RID()); } navigation = nullptr; } break; case NOTIFICATION_DRAW: { - if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) && navpoly.is_valid()) { - Vector<Vector2> verts = navpoly->get_vertices(); int vsize = verts.size(); if (vsize < 3) @@ -477,10 +435,8 @@ void NavigationRegion2D::_notification(int p_what) { Vector<int> polygon = navpoly->get_polygon(i); for (int j = 2; j < polygon.size(); j++) { - int kofs[3] = { 0, j - 1, j }; for (int k = 0; k < 3; k++) { - int idx = polygon[kofs[k]]; ERR_FAIL_INDEX(idx, vsize); indices.push_back(idx); @@ -494,7 +450,6 @@ void NavigationRegion2D::_notification(int p_what) { } void NavigationRegion2D::set_navigation_polygon(const Ref<NavigationPolygon> &p_navpoly) { - if (p_navpoly == navpoly) { return; } @@ -516,18 +471,15 @@ void NavigationRegion2D::set_navigation_polygon(const Ref<NavigationPolygon> &p_ } Ref<NavigationPolygon> NavigationRegion2D::get_navigation_polygon() const { - return navpoly; } void NavigationRegion2D::_navpoly_changed() { - if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint())) update(); } String NavigationRegion2D::get_configuration_warning() const { - if (!is_visible_in_tree() || !is_inside_tree()) return String(); @@ -536,7 +488,6 @@ String NavigationRegion2D::get_configuration_warning() const { } const Node2D *c = this; while (c) { - if (Object::cast_to<Navigation2D>(c)) { return String(); } @@ -548,7 +499,6 @@ String NavigationRegion2D::get_configuration_warning() const { } void NavigationRegion2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_navigation_polygon", "navpoly"), &NavigationRegion2D::set_navigation_polygon); ClassDB::bind_method(D_METHOD("get_navigation_polygon"), &NavigationRegion2D::get_navigation_polygon); diff --git a/scene/2d/navigation_region_2d.h b/scene/2d/navigation_region_2d.h index 54d2ac11f8..07cf4d6668 100644 --- a/scene/2d/navigation_region_2d.h +++ b/scene/2d/navigation_region_2d.h @@ -35,7 +35,6 @@ #include "scene/resources/navigation_mesh.h" class NavigationPolygon : public Resource { - GDCLASS(NavigationPolygon, Resource); Vector<Vector2> vertices; @@ -95,7 +94,6 @@ public: class Navigation2D; class NavigationRegion2D : public Node2D { - GDCLASS(NavigationRegion2D, Node2D); bool enabled = true; diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 1ea51be148..b500266620 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -37,7 +37,6 @@ #ifdef TOOLS_ENABLED Dictionary Node2D::_edit_get_state() const { - Dictionary state; state["position"] = get_position(); state["rotation"] = get_rotation(); @@ -48,7 +47,6 @@ Dictionary Node2D::_edit_get_state() const { } void Node2D::_edit_set_state(const Dictionary &p_state) { - pos = p_state["position"]; angle = p_state["rotation"]; _scale = p_state["scale"]; @@ -128,7 +126,6 @@ void Node2D::_edit_set_rect(const Rect2 &p_edit_rect) { #endif void Node2D::_update_xform_values() { - pos = _mat.elements[2]; angle = _mat.get_rotation(); _scale = _mat.get_scale(); @@ -137,7 +134,6 @@ void Node2D::_update_xform_values() { } void Node2D::_update_transform() { - _mat.set_rotation_scale_and_skew(angle, _scale, skew); _mat.elements[2] = pos; @@ -150,7 +146,6 @@ void Node2D::_update_transform() { } void Node2D::set_position(const Point2 &p_pos) { - if (_xform_dirty) ((Node2D *)this)->_update_xform_values(); pos = p_pos; @@ -159,7 +154,6 @@ void Node2D::set_position(const Point2 &p_pos) { } void Node2D::set_rotation(float p_radians) { - if (_xform_dirty) ((Node2D *)this)->_update_xform_values(); angle = p_radians; @@ -169,7 +163,6 @@ void Node2D::set_rotation(float p_radians) { } void Node2D::set_skew(float p_radians) { - if (_xform_dirty) ((Node2D *)this)->_update_xform_values(); skew = p_radians; @@ -179,17 +172,14 @@ void Node2D::set_skew(float p_radians) { } void Node2D::set_rotation_degrees(float p_degrees) { - set_rotation(Math::deg2rad(p_degrees)); } void Node2D::set_skew_degrees(float p_degrees) { - set_skew(Math::deg2rad(p_degrees)); } void Node2D::set_scale(const Size2 &p_scale) { - if (_xform_dirty) ((Node2D *)this)->_update_xform_values(); _scale = p_scale; @@ -203,7 +193,6 @@ void Node2D::set_scale(const Size2 &p_scale) { } Point2 Node2D::get_position() const { - if (_xform_dirty) ((Node2D *)this)->_update_xform_values(); return pos; @@ -224,12 +213,10 @@ float Node2D::get_skew() const { } float Node2D::get_rotation_degrees() const { - return Math::rad2deg(get_rotation()); } float Node2D::get_skew_degrees() const { - return Math::rad2deg(get_skew()); } Size2 Node2D::get_scale() const { @@ -240,32 +227,26 @@ Size2 Node2D::get_scale() const { } Transform2D Node2D::get_transform() const { - return _mat; } void Node2D::rotate(float p_radians) { - set_rotation(get_rotation() + p_radians); } void Node2D::translate(const Vector2 &p_amount) { - set_position(get_position() + p_amount); } void Node2D::global_translate(const Vector2 &p_amount) { - set_global_position(get_global_position() + p_amount); } void Node2D::apply_scale(const Size2 &p_amount) { - set_scale(get_scale() * p_amount); } void Node2D::move_x(float p_delta, bool p_scaled) { - Transform2D t = get_transform(); Vector2 m = t[0]; if (!p_scaled) @@ -274,7 +255,6 @@ void Node2D::move_x(float p_delta, bool p_scaled) { } void Node2D::move_y(float p_delta, bool p_scaled) { - Transform2D t = get_transform(); Vector2 m = t[1]; if (!p_scaled) @@ -283,12 +263,10 @@ void Node2D::move_y(float p_delta, bool p_scaled) { } Point2 Node2D::get_global_position() const { - return get_global_transform().get_origin(); } void Node2D::set_global_position(const Point2 &p_pos) { - Transform2D inv; CanvasItem *pi = get_parent_item(); if (pi) { @@ -300,12 +278,10 @@ void Node2D::set_global_position(const Point2 &p_pos) { } float Node2D::get_global_rotation() const { - return get_global_transform().get_rotation(); } void Node2D::set_global_rotation(float p_radians) { - CanvasItem *pi = get_parent_item(); if (pi) { const float parent_global_rot = pi->get_global_transform().get_rotation(); @@ -316,22 +292,18 @@ void Node2D::set_global_rotation(float p_radians) { } float Node2D::get_global_rotation_degrees() const { - return Math::rad2deg(get_global_rotation()); } void Node2D::set_global_rotation_degrees(float p_degrees) { - set_global_rotation(Math::deg2rad(p_degrees)); } Size2 Node2D::get_global_scale() const { - return get_global_transform().get_scale(); } void Node2D::set_global_scale(const Size2 &p_scale) { - CanvasItem *pi = get_parent_item(); if (pi) { const Size2 parent_global_scale = pi->get_global_transform().get_scale(); @@ -342,7 +314,6 @@ void Node2D::set_global_scale(const Size2 &p_scale) { } void Node2D::set_transform(const Transform2D &p_transform) { - _mat = p_transform; _xform_dirty = true; @@ -355,7 +326,6 @@ void Node2D::set_transform(const Transform2D &p_transform) { } void Node2D::set_global_transform(const Transform2D &p_transform) { - CanvasItem *pi = get_parent_item(); if (pi) set_transform(pi->get_global_transform().affine_inverse() * p_transform); @@ -364,7 +334,6 @@ void Node2D::set_global_transform(const Transform2D &p_transform) { } void Node2D::set_z_index(int p_z) { - ERR_FAIL_COND(p_z < RS::CANVAS_ITEM_Z_MIN); ERR_FAIL_COND(p_z > RS::CANVAS_ITEM_Z_MAX); z_index = p_z; @@ -373,7 +342,6 @@ void Node2D::set_z_index(int p_z) { } void Node2D::set_z_as_relative(bool p_enabled) { - if (z_relative == p_enabled) return; z_relative = p_enabled; @@ -381,17 +349,14 @@ void Node2D::set_z_as_relative(bool p_enabled) { } bool Node2D::is_z_relative() const { - return z_relative; } int Node2D::get_z_index() const { - return z_index; } Transform2D Node2D::get_relative_transform_to_parent(const Node *p_parent) const { - if (p_parent == this) return Transform2D(); @@ -405,27 +370,22 @@ Transform2D Node2D::get_relative_transform_to_parent(const Node *p_parent) const } void Node2D::look_at(const Vector2 &p_pos) { - rotate(get_angle_to(p_pos)); } float Node2D::get_angle_to(const Vector2 &p_pos) const { - return (to_local(p_pos) * get_scale()).angle(); } Point2 Node2D::to_local(Point2 p_global) const { - return get_global_transform().affine_inverse().xform(p_global); } Point2 Node2D::to_global(Point2 p_local) const { - return get_global_transform().xform(p_local); } void Node2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_position", "position"), &Node2D::set_position); ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Node2D::set_rotation); ClassDB::bind_method(D_METHOD("set_rotation_degrees", "degrees"), &Node2D::set_rotation_degrees); @@ -494,7 +454,6 @@ void Node2D::_bind_methods() { } Node2D::Node2D() { - angle = 0; _scale = Vector2(1, 1); skew = 0; diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index 0afec36254..827c192585 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -34,7 +34,6 @@ #include "scene/main/canvas_item.h" class Node2D : public CanvasItem { - GDCLASS(Node2D, CanvasItem); Point2 pos; diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp index 0d5f74a265..6930307840 100644 --- a/scene/2d/parallax_background.cpp +++ b/scene/2d/parallax_background.cpp @@ -32,24 +32,19 @@ #include "parallax_layer.h" void ParallaxBackground::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - group_name = "__cameras_" + itos(get_viewport().get_id()); add_to_group(group_name); } break; case NOTIFICATION_EXIT_TREE: { - remove_from_group(group_name); } break; } } void ParallaxBackground::_camera_moved(const Transform2D &p_transform, const Point2 &p_screen_offset) { - screen_offset = p_screen_offset; set_scroll_scale(p_transform.get_scale().dot(Vector2(0.5, 0.5))); @@ -57,24 +52,20 @@ void ParallaxBackground::_camera_moved(const Transform2D &p_transform, const Poi } void ParallaxBackground::set_scroll_scale(float p_scale) { - scale = p_scale; } float ParallaxBackground::get_scroll_scale() const { - return scale; } void ParallaxBackground::set_scroll_offset(const Point2 &p_ofs) { - offset = p_ofs; _update_scroll(); } void ParallaxBackground::_update_scroll() { - if (!is_inside_tree()) return; @@ -84,7 +75,6 @@ void ParallaxBackground::_update_scroll() { ofs = -ofs; if (limit_begin.x < limit_end.x) { - if (ofs.x < limit_begin.x) ofs.x = limit_begin.x; else if (ofs.x + vps.x > limit_end.x) @@ -92,7 +82,6 @@ void ParallaxBackground::_update_scroll() { } if (limit_begin.y < limit_end.y) { - if (ofs.y < limit_begin.y) ofs.y = limit_begin.y; else if (ofs.y + vps.y > limit_end.y) @@ -103,7 +92,6 @@ void ParallaxBackground::_update_scroll() { final_offset = ofs; for (int i = 0; i < get_child_count(); i++) { - ParallaxLayer *l = Object::cast_to<ParallaxLayer>(get_child(i)); if (!l) continue; @@ -116,71 +104,58 @@ void ParallaxBackground::_update_scroll() { } Point2 ParallaxBackground::get_scroll_offset() const { - return offset; } void ParallaxBackground::set_scroll_base_offset(const Point2 &p_ofs) { - base_offset = p_ofs; _update_scroll(); } Point2 ParallaxBackground::get_scroll_base_offset() const { - return base_offset; } void ParallaxBackground::set_scroll_base_scale(const Point2 &p_ofs) { - base_scale = p_ofs; _update_scroll(); } Point2 ParallaxBackground::get_scroll_base_scale() const { - return base_scale; } void ParallaxBackground::set_limit_begin(const Point2 &p_ofs) { - limit_begin = p_ofs; _update_scroll(); } Point2 ParallaxBackground::get_limit_begin() const { - return limit_begin; } void ParallaxBackground::set_limit_end(const Point2 &p_ofs) { - limit_end = p_ofs; _update_scroll(); } Point2 ParallaxBackground::get_limit_end() const { - return limit_end; } void ParallaxBackground::set_ignore_camera_zoom(bool ignore) { - ignore_camera_zoom = ignore; } bool ParallaxBackground::is_ignore_camera_zoom() { - return ignore_camera_zoom; } Vector2 ParallaxBackground::get_final_offset() const { - return final_offset; } void ParallaxBackground::_bind_methods() { - ClassDB::bind_method(D_METHOD("_camera_moved"), &ParallaxBackground::_camera_moved); ClassDB::bind_method(D_METHOD("set_scroll_offset", "ofs"), &ParallaxBackground::set_scroll_offset); ClassDB::bind_method(D_METHOD("get_scroll_offset"), &ParallaxBackground::get_scroll_offset); @@ -205,7 +180,6 @@ void ParallaxBackground::_bind_methods() { } ParallaxBackground::ParallaxBackground() { - scale = 1.0; set_layer(-100); //behind all by default diff --git a/scene/2d/parallax_background.h b/scene/2d/parallax_background.h index 25ccd910d1..1667880ddb 100644 --- a/scene/2d/parallax_background.h +++ b/scene/2d/parallax_background.h @@ -36,7 +36,6 @@ #include "scene/main/canvas_layer.h" class ParallaxBackground : public CanvasLayer { - GDCLASS(ParallaxBackground, CanvasLayer); Point2 offset; diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index 181f0f158c..ffc6e50da2 100644 --- a/scene/2d/parallax_layer.cpp +++ b/scene/2d/parallax_layer.cpp @@ -34,7 +34,6 @@ #include "parallax_background.h" void ParallaxLayer::set_motion_scale(const Size2 &p_scale) { - motion_scale = p_scale; ParallaxBackground *pb = Object::cast_to<ParallaxBackground>(get_parent()); @@ -46,12 +45,10 @@ void ParallaxLayer::set_motion_scale(const Size2 &p_scale) { } Size2 ParallaxLayer::get_motion_scale() const { - return motion_scale; } void ParallaxLayer::set_motion_offset(const Size2 &p_offset) { - motion_offset = p_offset; ParallaxBackground *pb = Object::cast_to<ParallaxBackground>(get_parent()); @@ -63,18 +60,15 @@ void ParallaxLayer::set_motion_offset(const Size2 &p_offset) { } Size2 ParallaxLayer::get_motion_offset() const { - return motion_offset; } void ParallaxLayer::_update_mirroring() { - if (!is_inside_tree()) return; ParallaxBackground *pb = Object::cast_to<ParallaxBackground>(get_parent()); if (pb) { - RID c = pb->get_canvas(); RID ci = get_canvas_item(); Point2 mirrorScale = mirroring * get_scale(); @@ -83,7 +77,6 @@ void ParallaxLayer::_update_mirroring() { } void ParallaxLayer::set_mirroring(const Size2 &p_mirroring) { - mirroring = p_mirroring; if (mirroring.x < 0) mirroring.x = 0; @@ -94,22 +87,17 @@ void ParallaxLayer::set_mirroring(const Size2 &p_mirroring) { } Size2 ParallaxLayer::get_mirroring() const { - return mirroring; } void ParallaxLayer::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - orig_offset = get_position(); orig_scale = get_scale(); _update_mirroring(); } break; case NOTIFICATION_EXIT_TREE: { - set_position(orig_offset); set_scale(orig_scale); } break; @@ -143,7 +131,6 @@ void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, float p_sc } String ParallaxLayer::get_configuration_warning() const { - if (!Object::cast_to<ParallaxBackground>(get_parent())) { return TTR("ParallaxLayer node only works when set as child of a ParallaxBackground node."); } @@ -152,7 +139,6 @@ String ParallaxLayer::get_configuration_warning() const { } void ParallaxLayer::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_motion_scale", "scale"), &ParallaxLayer::set_motion_scale); ClassDB::bind_method(D_METHOD("get_motion_scale"), &ParallaxLayer::get_motion_scale); ClassDB::bind_method(D_METHOD("set_motion_offset", "offset"), &ParallaxLayer::set_motion_offset); diff --git a/scene/2d/parallax_layer.h b/scene/2d/parallax_layer.h index ba59184649..1f001943b5 100644 --- a/scene/2d/parallax_layer.h +++ b/scene/2d/parallax_layer.h @@ -34,7 +34,6 @@ #include "scene/2d/node_2d.h" class ParallaxLayer : public Node2D { - GDCLASS(ParallaxLayer, Node2D); Point2 orig_offset; diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index 149d5c6b0d..a914da8fe0 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -39,16 +39,13 @@ #ifdef TOOLS_ENABLED Rect2 Path2D::_edit_get_rect() const { - if (!curve.is_valid() || curve->get_point_count() == 0) return Rect2(0, 0, 0, 0); Rect2 aabb = Rect2(curve->get_point_position(0), Vector2(0, 0)); for (int i = 0; i < curve->get_point_count(); i++) { - for (int j = 0; j <= 8; j++) { - real_t frac = j / 8.0; Vector2 p = curve->interpolate(i, frac); aabb.expand_to(p); @@ -63,7 +60,6 @@ bool Path2D::_edit_use_rect() const { } bool Path2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - if (curve.is_null()) { return false; } @@ -89,7 +85,6 @@ bool Path2D::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc #endif void Path2D::_notification(int p_what) { - if (p_what == NOTIFICATION_DRAW && curve.is_valid()) { //draw the curve!! @@ -105,11 +100,9 @@ void Path2D::_notification(int p_what) { const Color color = Color(0.5, 0.6, 1.0, 0.7); for (int i = 0; i < curve->get_point_count(); i++) { - Vector2 prev_p = curve->get_point_position(i); for (int j = 1; j <= 8; j++) { - real_t frac = j / 8.0; Vector2 p = curve->interpolate(i, frac); draw_line(prev_p, p, color, line_width); @@ -132,7 +125,6 @@ void Path2D::_curve_changed() { } void Path2D::set_curve(const Ref<Curve2D> &p_curve) { - if (curve.is_valid()) { curve->disconnect("changed", callable_mp(this, &Path2D::_curve_changed)); } @@ -147,12 +139,10 @@ void Path2D::set_curve(const Ref<Curve2D> &p_curve) { } Ref<Curve2D> Path2D::get_curve() const { - return curve; } void Path2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_curve", "curve"), &Path2D::set_curve); ClassDB::bind_method(D_METHOD("get_curve"), &Path2D::get_curve); @@ -160,14 +150,12 @@ void Path2D::_bind_methods() { } Path2D::Path2D() { - set_curve(Ref<Curve2D>(memnew(Curve2D))); //create one by default } ///////////////////////////////////////////////////////////////////////////////// void PathFollow2D::_update_transform() { - if (!path) return; @@ -219,7 +207,6 @@ void PathFollow2D::_update_transform() { set_rotation(tangent_to_curve.angle()); } else { - pos.x += h_offset; pos.y += v_offset; } @@ -228,11 +215,8 @@ void PathFollow2D::_update_transform() { } void PathFollow2D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - path = Object::cast_to<Path2D>(get_parent()); if (path) { _update_transform(); @@ -240,26 +224,21 @@ void PathFollow2D::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { - path = nullptr; } break; } } void PathFollow2D::set_cubic_interpolation(bool p_enable) { - cubic = p_enable; } bool PathFollow2D::get_cubic_interpolation() const { - return cubic; } void PathFollow2D::_validate_property(PropertyInfo &property) const { - if (property.name == "offset") { - float max = 10000; if (path && path->get_curve().is_valid()) max = path->get_curve()->get_baked_length(); @@ -269,7 +248,6 @@ void PathFollow2D::_validate_property(PropertyInfo &property) const { } String PathFollow2D::get_configuration_warning() const { - if (!is_visible_in_tree() || !is_inside_tree()) return String(); @@ -281,7 +259,6 @@ String PathFollow2D::get_configuration_warning() const { } void PathFollow2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_offset", "offset"), &PathFollow2D::set_offset); ClassDB::bind_method(D_METHOD("get_offset"), &PathFollow2D::get_offset); @@ -317,7 +294,6 @@ void PathFollow2D::_bind_methods() { } void PathFollow2D::set_offset(float p_offset) { - offset = p_offset; if (path) { if (path->get_curve().is_valid()) { @@ -340,42 +316,35 @@ void PathFollow2D::set_offset(float p_offset) { } void PathFollow2D::set_h_offset(float p_h_offset) { - h_offset = p_h_offset; if (path) _update_transform(); } float PathFollow2D::get_h_offset() const { - return h_offset; } void PathFollow2D::set_v_offset(float p_v_offset) { - v_offset = p_v_offset; if (path) _update_transform(); } float PathFollow2D::get_v_offset() const { - return v_offset; } float PathFollow2D::get_offset() const { - return offset; } void PathFollow2D::set_unit_offset(float p_unit_offset) { - if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) set_offset(p_unit_offset * path->get_curve()->get_baked_length()); } float PathFollow2D::get_unit_offset() const { - if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) return get_offset() / path->get_curve()->get_baked_length(); else @@ -383,38 +352,31 @@ float PathFollow2D::get_unit_offset() const { } void PathFollow2D::set_lookahead(float p_lookahead) { - lookahead = p_lookahead; } float PathFollow2D::get_lookahead() const { - return lookahead; } void PathFollow2D::set_rotate(bool p_rotate) { - rotate = p_rotate; _update_transform(); } bool PathFollow2D::is_rotating() const { - return rotate; } void PathFollow2D::set_loop(bool p_loop) { - loop = p_loop; } bool PathFollow2D::has_loop() const { - return loop; } PathFollow2D::PathFollow2D() { - offset = 0; h_offset = 0; v_offset = 0; diff --git a/scene/2d/path_2d.h b/scene/2d/path_2d.h index 35cf8211f4..288ef698e7 100644 --- a/scene/2d/path_2d.h +++ b/scene/2d/path_2d.h @@ -35,7 +35,6 @@ #include "scene/resources/curve.h" class Path2D : public Node2D { - GDCLASS(Path2D, Node2D); Ref<Curve2D> curve; @@ -60,7 +59,6 @@ public: }; class PathFollow2D : public Node2D { - GDCLASS(PathFollow2D, Node2D); public: diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 4198eb6c06..23da6ced5b 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -43,18 +43,15 @@ void PhysicsBody2D::_notification(int p_what) { } void PhysicsBody2D::_set_layers(uint32_t p_mask) { - set_collision_layer(p_mask); set_collision_mask(p_mask); } uint32_t PhysicsBody2D::_get_layers() const { - return get_collision_layer(); } void PhysicsBody2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &PhysicsBody2D::set_collision_layer); ClassDB::bind_method(D_METHOD("get_collision_layer"), &PhysicsBody2D::get_collision_layer); ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &PhysicsBody2D::set_collision_mask); @@ -80,29 +77,24 @@ void PhysicsBody2D::_bind_methods() { } void PhysicsBody2D::set_collision_layer(uint32_t p_layer) { - collision_layer = p_layer; PhysicsServer2D::get_singleton()->body_set_collision_layer(get_rid(), p_layer); } uint32_t PhysicsBody2D::get_collision_layer() const { - return collision_layer; } void PhysicsBody2D::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; PhysicsServer2D::get_singleton()->body_set_collision_mask(get_rid(), p_mask); } uint32_t PhysicsBody2D::get_collision_mask() const { - return collision_mask; } void PhysicsBody2D::set_collision_mask_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_mask(); if (p_value) mask |= 1 << p_bit; @@ -111,12 +103,10 @@ void PhysicsBody2D::set_collision_mask_bit(int p_bit, bool p_value) { set_collision_mask(mask); } bool PhysicsBody2D::get_collision_mask_bit(int p_bit) const { - return get_collision_mask() & (1 << p_bit); } void PhysicsBody2D::set_collision_layer_bit(int p_bit, bool p_value) { - uint32_t collision_layer = get_collision_layer(); if (p_value) collision_layer |= 1 << p_bit; @@ -126,13 +116,11 @@ void PhysicsBody2D::set_collision_layer_bit(int p_bit, bool p_value) { } bool PhysicsBody2D::get_collision_layer_bit(int p_bit) const { - return get_collision_layer() & (1 << p_bit); } PhysicsBody2D::PhysicsBody2D(PhysicsServer2D::BodyMode p_mode) : CollisionObject2D(PhysicsServer2D::get_singleton()->body_create(), false) { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), p_mode); collision_layer = 1; collision_mask = 1; @@ -154,7 +142,6 @@ TypedArray<PhysicsBody2D> PhysicsBody2D::get_collision_exceptions() { } void PhysicsBody2D::add_collision_exception_with(Node *p_node) { - ERR_FAIL_NULL(p_node); PhysicsBody2D *physics_body = Object::cast_to<PhysicsBody2D>(p_node); ERR_FAIL_COND_MSG(!physics_body, "Collision exception only works between two objects of PhysicsBody2D type."); @@ -162,7 +149,6 @@ void PhysicsBody2D::add_collision_exception_with(Node *p_node) { } void PhysicsBody2D::remove_collision_exception_with(Node *p_node) { - ERR_FAIL_NULL(p_node); PhysicsBody2D *physics_body = Object::cast_to<PhysicsBody2D>(p_node); ERR_FAIL_COND_MSG(!physics_body, "Collision exception only works between two objects of PhysicsBody2D type."); @@ -170,23 +156,19 @@ void PhysicsBody2D::remove_collision_exception_with(Node *p_node) { } void StaticBody2D::set_constant_linear_velocity(const Vector2 &p_vel) { - constant_linear_velocity = p_vel; PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_LINEAR_VELOCITY, constant_linear_velocity); } void StaticBody2D::set_constant_angular_velocity(real_t p_vel) { - constant_angular_velocity = p_vel; PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_ANGULAR_VELOCITY, constant_angular_velocity); } Vector2 StaticBody2D::get_constant_linear_velocity() const { - return constant_linear_velocity; } real_t StaticBody2D::get_constant_angular_velocity() const { - return constant_angular_velocity; } @@ -210,7 +192,6 @@ Ref<PhysicsMaterial> StaticBody2D::get_physics_material_override() const { } void StaticBody2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constant_linear_velocity", "vel"), &StaticBody2D::set_constant_linear_velocity); ClassDB::bind_method(D_METHOD("set_constant_angular_velocity", "vel"), &StaticBody2D::set_constant_angular_velocity); ClassDB::bind_method(D_METHOD("get_constant_linear_velocity"), &StaticBody2D::get_constant_linear_velocity); @@ -226,7 +207,6 @@ void StaticBody2D::_bind_methods() { StaticBody2D::StaticBody2D() : PhysicsBody2D(PhysicsServer2D::BODY_MODE_STATIC) { - constant_angular_velocity = 0; } @@ -244,7 +224,6 @@ void StaticBody2D::_reload_physics_characteristics() { } void RigidBody2D::_body_enter_tree(ObjectID p_id) { - Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); @@ -260,7 +239,6 @@ void RigidBody2D::_body_enter_tree(ObjectID p_id) { emit_signal(SceneStringNames::get_singleton()->body_entered, node); for (int i = 0; i < E->get().shapes.size(); i++) { - emit_signal(SceneStringNames::get_singleton()->body_shape_entered, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].local_shape); } @@ -268,7 +246,6 @@ void RigidBody2D::_body_enter_tree(ObjectID p_id) { } void RigidBody2D::_body_exit_tree(ObjectID p_id) { - Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); @@ -283,7 +260,6 @@ void RigidBody2D::_body_exit_tree(ObjectID p_id) { emit_signal(SceneStringNames::get_singleton()->body_exited, node); for (int i = 0; i < E->get().shapes.size(); i++) { - emit_signal(SceneStringNames::get_singleton()->body_shape_exited, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].local_shape); } @@ -291,7 +267,6 @@ void RigidBody2D::_body_exit_tree(ObjectID p_id) { } void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, int p_local_shape) { - bool body_in = p_status == 1; ObjectID objid = p_instance; @@ -305,7 +280,6 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap if (body_in) { if (!E) { - E = contact_monitor->body_map.insert(objid, BodyState()); //E->get().rc=0; E->get().in_scene = node && node->is_inside_tree(); @@ -328,7 +302,6 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap } } else { - //E->get().rc--; if (node) @@ -337,7 +310,6 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap bool in_scene = E->get().in_scene; if (E->get().shapes.empty()) { - if (node) { node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody2D::_body_enter_tree)); node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody2D::_body_exit_tree)); @@ -354,14 +326,12 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap } struct _RigidBody2DInOut { - ObjectID id; int shape; int local_shape; }; bool RigidBody2D::_test_motion(const Vector2 &p_motion, bool p_infinite_inertia, float p_margin, const Ref<PhysicsTestMotionResult2D> &p_result) { - PhysicsServer2D::MotionResult *r = nullptr; if (p_result.is_valid()) r = p_result->get_result_ptr(); @@ -369,7 +339,6 @@ bool RigidBody2D::_test_motion(const Vector2 &p_motion, bool p_infinite_inertia, } void RigidBody2D::_direct_state_changed(Object *p_state) { - #ifdef DEBUG_ENABLED state = Object::cast_to<PhysicsDirectBodyState2D>(p_state); #else @@ -390,15 +359,12 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { set_block_transform_notify(false); // want it back if (contact_monitor) { - contact_monitor->locked = true; //untag all int rc = 0; for (Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) { - for (int i = 0; i < E->get().shapes.size(); i++) { - E->get().shapes[i].tagged = false; rc++; } @@ -412,7 +378,6 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { //put the ones to add for (int i = 0; i < state->get_contact_count(); i++) { - ObjectID obj = state->get_contact_collider_id(i); int local_shape = state->get_contact_local_shape(i); int shape = state->get_contact_collider_shape(i); @@ -431,7 +396,6 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { ShapePair sp(shape, local_shape); int idx = E->get().shapes.find(sp); if (idx == -1) { - toadd[toadd_count].local_shape = local_shape; toadd[toadd_count].id = obj; toadd[toadd_count].shape = shape; @@ -445,11 +409,8 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { //put the ones to remove for (Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) { - for (int i = 0; i < E->get().shapes.size(); i++) { - if (!E->get().shapes[i].tagged) { - toremove[toremove_count].body_id = E->key(); toremove[toremove_count].pair = E->get().shapes[i]; toremove_count++; @@ -460,14 +421,12 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { //process remotions for (int i = 0; i < toremove_count; i++) { - _body_inout(0, toremove[i].body_id, toremove[i].pair.body_shape, toremove[i].pair.local_shape); } //process aditions for (int i = 0; i < toadd_count; i++) { - _body_inout(1, toadd[i].id, toadd[i].shape, toadd[i].local_shape); } @@ -478,21 +437,16 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { } void RigidBody2D::set_mode(Mode p_mode) { - mode = p_mode; switch (p_mode) { - case MODE_RIGID: { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BODY_MODE_RIGID); } break; case MODE_STATIC: { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BODY_MODE_STATIC); } break; case MODE_KINEMATIC: { - PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BODY_MODE_KINEMATIC); } break; @@ -504,12 +458,10 @@ void RigidBody2D::set_mode(Mode p_mode) { } RigidBody2D::Mode RigidBody2D::get_mode() const { - return mode; } void RigidBody2D::set_mass(real_t p_mass) { - ERR_FAIL_COND(p_mass <= 0); mass = p_mass; _change_notify("mass"); @@ -517,28 +469,23 @@ void RigidBody2D::set_mass(real_t p_mass) { PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_MASS, mass); } real_t RigidBody2D::get_mass() const { - return mass; } void RigidBody2D::set_inertia(real_t p_inertia) { - ERR_FAIL_COND(p_inertia < 0); PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_INERTIA, p_inertia); } real_t RigidBody2D::get_inertia() const { - return PhysicsServer2D::get_singleton()->body_get_param(get_rid(), PhysicsServer2D::BODY_PARAM_INERTIA); } void RigidBody2D::set_weight(real_t p_weight) { - set_mass(p_weight / (real_t(GLOBAL_DEF("physics/2d/default_gravity", 98)) / 10)); } real_t RigidBody2D::get_weight() const { - return mass * (real_t(GLOBAL_DEF("physics/2d/default_gravity", 98)) / 10); } @@ -562,39 +509,32 @@ Ref<PhysicsMaterial> RigidBody2D::get_physics_material_override() const { } void RigidBody2D::set_gravity_scale(real_t p_gravity_scale) { - gravity_scale = p_gravity_scale; PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_GRAVITY_SCALE, gravity_scale); } real_t RigidBody2D::get_gravity_scale() const { - return gravity_scale; } void RigidBody2D::set_linear_damp(real_t p_linear_damp) { - ERR_FAIL_COND(p_linear_damp < -1); linear_damp = p_linear_damp; PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_LINEAR_DAMP, linear_damp); } real_t RigidBody2D::get_linear_damp() const { - return linear_damp; } void RigidBody2D::set_angular_damp(real_t p_angular_damp) { - ERR_FAIL_COND(p_angular_damp < -1); angular_damp = p_angular_damp; PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_ANGULAR_DAMP, angular_damp); } real_t RigidBody2D::get_angular_damp() const { - return angular_damp; } void RigidBody2D::set_axis_velocity(const Vector2 &p_axis) { - Vector2 v = state ? state->get_linear_velocity() : linear_velocity; Vector2 axis = p_axis.normalized(); v -= axis * axis.dot(v); @@ -608,23 +548,19 @@ void RigidBody2D::set_axis_velocity(const Vector2 &p_axis) { } void RigidBody2D::set_linear_velocity(const Vector2 &p_velocity) { - linear_velocity = p_velocity; if (state) state->set_linear_velocity(linear_velocity); else { - PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_LINEAR_VELOCITY, linear_velocity); } } Vector2 RigidBody2D::get_linear_velocity() const { - return linear_velocity; } void RigidBody2D::set_angular_velocity(real_t p_velocity) { - angular_velocity = p_velocity; if (state) state->set_angular_velocity(angular_velocity); @@ -632,12 +568,10 @@ void RigidBody2D::set_angular_velocity(real_t p_velocity) { PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_ANGULAR_VELOCITY, angular_velocity); } real_t RigidBody2D::get_angular_velocity() const { - return angular_velocity; } void RigidBody2D::set_use_custom_integrator(bool p_enable) { - if (custom_integrator == p_enable) return; @@ -645,40 +579,33 @@ void RigidBody2D::set_use_custom_integrator(bool p_enable) { PhysicsServer2D::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable); } bool RigidBody2D::is_using_custom_integrator() { - return custom_integrator; } void RigidBody2D::set_sleeping(bool p_sleeping) { - sleeping = p_sleeping; PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_SLEEPING, sleeping); } void RigidBody2D::set_can_sleep(bool p_active) { - can_sleep = p_active; PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_CAN_SLEEP, p_active); } bool RigidBody2D::is_able_to_sleep() const { - return can_sleep; } bool RigidBody2D::is_sleeping() const { - return sleeping; } void RigidBody2D::set_max_contacts_reported(int p_amount) { - max_contacts_reported = p_amount; PhysicsServer2D::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount); } int RigidBody2D::get_max_contacts_reported() const { - return max_contacts_reported; } @@ -687,7 +614,6 @@ void RigidBody2D::apply_central_impulse(const Vector2 &p_impulse) { } void RigidBody2D::apply_impulse(const Vector2 &p_offset, const Vector2 &p_impulse) { - PhysicsServer2D::get_singleton()->body_apply_impulse(get_rid(), p_offset, p_impulse); } @@ -696,22 +622,18 @@ void RigidBody2D::apply_torque_impulse(float p_torque) { } void RigidBody2D::set_applied_force(const Vector2 &p_force) { - PhysicsServer2D::get_singleton()->body_set_applied_force(get_rid(), p_force); }; Vector2 RigidBody2D::get_applied_force() const { - return PhysicsServer2D::get_singleton()->body_get_applied_force(get_rid()); }; void RigidBody2D::set_applied_torque(const float p_torque) { - PhysicsServer2D::get_singleton()->body_set_applied_torque(get_rid(), p_torque); }; float RigidBody2D::get_applied_torque() const { - return PhysicsServer2D::get_singleton()->body_get_applied_torque(get_rid()); }; @@ -720,7 +642,6 @@ void RigidBody2D::add_central_force(const Vector2 &p_force) { } void RigidBody2D::add_force(const Vector2 &p_offset, const Vector2 &p_force) { - PhysicsServer2D::get_singleton()->body_add_force(get_rid(), p_offset, p_force); } @@ -729,18 +650,15 @@ void RigidBody2D::add_torque(const float p_torque) { } void RigidBody2D::set_continuous_collision_detection_mode(CCDMode p_mode) { - ccd_mode = p_mode; PhysicsServer2D::get_singleton()->body_set_continuous_collision_detection_mode(get_rid(), PhysicsServer2D::CCDMode(p_mode)); } RigidBody2D::CCDMode RigidBody2D::get_continuous_collision_detection_mode() const { - return ccd_mode; } TypedArray<Node2D> RigidBody2D::get_colliding_bodies() const { - ERR_FAIL_COND_V(!contact_monitor, Array()); TypedArray<Node2D> ret; @@ -759,16 +677,13 @@ TypedArray<Node2D> RigidBody2D::get_colliding_bodies() const { } void RigidBody2D::set_contact_monitor(bool p_enabled) { - if (p_enabled == is_contact_monitor_enabled()) return; if (!p_enabled) { - 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()) { - //clean up mess Object *obj = ObjectDB::get_instance(E->key()); Node *node = Object::cast_to<Node>(obj); @@ -782,19 +697,16 @@ void RigidBody2D::set_contact_monitor(bool p_enabled) { memdelete(contact_monitor); contact_monitor = nullptr; } else { - contact_monitor = memnew(ContactMonitor); contact_monitor->locked = false; } } bool RigidBody2D::is_contact_monitor_enabled() const { - return contact_monitor != nullptr; } void RigidBody2D::_notification(int p_what) { - #ifdef TOOLS_ENABLED if (p_what == NOTIFICATION_ENTER_TREE) { if (Engine::get_singleton()->is_editor_hint()) { @@ -812,7 +724,6 @@ void RigidBody2D::_notification(int p_what) { } String RigidBody2D::get_configuration_warning() const { - Transform2D t = get_transform(); String warning = CollisionObject2D::get_configuration_warning(); @@ -828,7 +739,6 @@ String RigidBody2D::get_configuration_warning() const { } void RigidBody2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mode", "mode"), &RigidBody2D::set_mode); ClassDB::bind_method(D_METHOD("get_mode"), &RigidBody2D::get_mode); @@ -940,7 +850,6 @@ void RigidBody2D::_bind_methods() { RigidBody2D::RigidBody2D() : PhysicsBody2D(PhysicsServer2D::BODY_MODE_RIGID) { - mode = MODE_RIGID; mass = 1; @@ -964,7 +873,6 @@ RigidBody2D::RigidBody2D() : } RigidBody2D::~RigidBody2D() { - if (contact_monitor) memdelete(contact_monitor); } @@ -982,7 +890,6 @@ void RigidBody2D::_reload_physics_characteristics() { ////////////////////////// Ref<KinematicCollision2D> KinematicBody2D::_move(const Vector2 &p_motion, bool p_infinite_inertia, bool p_exclude_raycast_shapes, bool p_test_only) { - Collision col; if (move_and_collide(p_motion, p_infinite_inertia, col, p_exclude_raycast_shapes, p_test_only)) { @@ -1000,7 +907,6 @@ Ref<KinematicCollision2D> KinematicBody2D::_move(const Vector2 &p_motion, bool p } bool KinematicBody2D::separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision) { - PhysicsServer2D::SeparationResult sep_res[8]; //max 8 rays Transform2D gt = get_global_transform(); @@ -1037,7 +943,6 @@ bool KinematicBody2D::separate_raycast_shapes(bool p_infinite_inertia, Collision } bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, Collision &r_collision, bool p_exclude_raycast_shapes, bool p_test_only) { - if (sync_to_physics) { ERR_PRINT("Functions move_and_slide and move_and_collide do not work together with 'sync to physics' option. Please read the documentation."); } @@ -1070,7 +975,6 @@ bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_ #define FLOOR_ANGLE_THRESHOLD 0.01 Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_up_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { - Vector2 body_velocity = p_linear_velocity; Vector2 body_velocity_normal = body_velocity.normalized(); @@ -1095,7 +999,6 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const floor_velocity = Vector2(); while (p_max_slides) { - Collision collision; bool found_collision = false; @@ -1161,7 +1064,6 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const } Vector2 KinematicBody2D::move_and_slide_with_snap(const Vector2 &p_linear_velocity, const Vector2 &p_snap, const Vector2 &p_up_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { - bool was_on_floor = on_floor; Vector2 ret = move_and_slide(p_linear_velocity, p_up_direction, p_stop_on_slope, p_max_slides, p_floor_max_angle, p_infinite_inertia); @@ -1201,47 +1103,38 @@ Vector2 KinematicBody2D::move_and_slide_with_snap(const Vector2 &p_linear_veloci } bool KinematicBody2D::is_on_floor() const { - return on_floor; } bool KinematicBody2D::is_on_wall() const { - return on_wall; } bool KinematicBody2D::is_on_ceiling() const { - return on_ceiling; } Vector2 KinematicBody2D::get_floor_normal() const { - return floor_normal; } Vector2 KinematicBody2D::get_floor_velocity() const { - return floor_velocity; } bool KinematicBody2D::test_move(const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia) { - ERR_FAIL_COND_V(!is_inside_tree(), false); return PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), p_from, p_motion, p_infinite_inertia, margin); } void KinematicBody2D::set_safe_margin(float p_margin) { - margin = p_margin; } float KinematicBody2D::get_safe_margin() const { - return margin; } int KinematicBody2D::get_slide_count() const { - return colliders.size(); } @@ -1251,7 +1144,6 @@ KinematicBody2D::Collision KinematicBody2D::get_slide_collision(int p_bounce) co } Ref<KinematicCollision2D> KinematicBody2D::_get_slide_collision(int p_bounce) { - ERR_FAIL_INDEX_V(p_bounce, colliders.size(), Ref<KinematicCollision2D>()); if (p_bounce >= slide_colliders.size()) { slide_colliders.resize(p_bounce + 1); @@ -1267,7 +1159,6 @@ Ref<KinematicCollision2D> KinematicBody2D::_get_slide_collision(int p_bounce) { } void KinematicBody2D::set_sync_to_physics(bool p_enable) { - if (sync_to_physics == p_enable) { return; } @@ -1292,7 +1183,6 @@ bool KinematicBody2D::is_sync_to_physics_enabled() const { } void KinematicBody2D::_direct_state_changed(Object *p_state) { - if (!sync_to_physics) return; @@ -1328,7 +1218,6 @@ void KinematicBody2D::_notification(int p_what) { } } void KinematicBody2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("move_and_collide", "rel_vec", "infinite_inertia", "exclude_raycast_shapes", "test_only"), &KinematicBody2D::_move, DEFVAL(true), DEFVAL(true), DEFVAL(false)); ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "up_direction", "stop_on_slope", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody2D::move_and_slide, DEFVAL(Vector2(0, 0)), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); ClassDB::bind_method(D_METHOD("move_and_slide_with_snap", "linear_velocity", "snap", "up_direction", "stop_on_slope", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody2D::move_and_slide_with_snap, DEFVAL(Vector2(0, 0)), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); @@ -1358,7 +1247,6 @@ void KinematicBody2D::_bind_methods() { KinematicBody2D::KinematicBody2D() : PhysicsBody2D(PhysicsServer2D::BODY_MODE_KINEMATIC) { - margin = 0.08; on_floor = false; @@ -1381,7 +1269,6 @@ KinematicBody2D::~KinematicBody2D() { //////////////////////// Vector2 KinematicCollision2D::get_position() const { - return collision.collision; } Vector2 KinematicCollision2D::get_normal() const { @@ -1401,7 +1288,6 @@ Object *KinematicCollision2D::get_local_shape() const { } Object *KinematicCollision2D::get_collider() const { - if (collision.collider.is_valid()) { return ObjectDB::get_instance(collision.collider); } @@ -1409,11 +1295,9 @@ Object *KinematicCollision2D::get_collider() const { return nullptr; } ObjectID KinematicCollision2D::get_collider_id() const { - return collision.collider; } Object *KinematicCollision2D::get_collider_shape() const { - Object *collider = get_collider(); if (collider) { CollisionObject2D *obj2d = Object::cast_to<CollisionObject2D>(collider); @@ -1426,20 +1310,16 @@ Object *KinematicCollision2D::get_collider_shape() const { return nullptr; } int KinematicCollision2D::get_collider_shape_index() const { - return collision.collider_shape; } Vector2 KinematicCollision2D::get_collider_velocity() const { - return collision.collider_vel; } Variant KinematicCollision2D::get_collider_metadata() const { - return Variant(); } void KinematicCollision2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_position"), &KinematicCollision2D::get_position); ClassDB::bind_method(D_METHOD("get_normal"), &KinematicCollision2D::get_normal); ClassDB::bind_method(D_METHOD("get_travel"), &KinematicCollision2D::get_travel); @@ -1466,7 +1346,6 @@ void KinematicCollision2D::_bind_methods() { } KinematicCollision2D::KinematicCollision2D() { - collision.collider_shape = 0; collision.local_shape = 0; owner = nullptr; diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 75f4f778bf..f3bdeb4528 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -39,7 +39,6 @@ class KinematicCollision2D; class PhysicsBody2D : public CollisionObject2D { - GDCLASS(PhysicsBody2D, CollisionObject2D); uint32_t collision_layer; @@ -75,7 +74,6 @@ public: }; class StaticBody2D : public PhysicsBody2D { - GDCLASS(StaticBody2D, PhysicsBody2D); Vector2 constant_linear_velocity; @@ -104,7 +102,6 @@ private: }; class RigidBody2D : public PhysicsBody2D { - GDCLASS(RigidBody2D, PhysicsBody2D); public: @@ -143,7 +140,6 @@ private: CCDMode ccd_mode; struct ShapePair { - int body_shape; int local_shape; bool tagged; @@ -161,19 +157,16 @@ private: } }; struct RigidBody2D_RemoveAction { - ObjectID body_id; ShapePair pair; }; struct BodyState { - //int rc; bool in_scene; VSet<ShapePair> shapes; }; struct ContactMonitor { - bool locked; Map<ObjectID, BodyState> body_map; }; @@ -271,7 +264,6 @@ VARIANT_ENUM_CAST(RigidBody2D::Mode); VARIANT_ENUM_CAST(RigidBody2D::CCDMode); class KinematicBody2D : public PhysicsBody2D { - GDCLASS(KinematicBody2D, PhysicsBody2D); public: @@ -344,7 +336,6 @@ public: }; class KinematicCollision2D : public Reference { - GDCLASS(KinematicCollision2D, Reference); KinematicBody2D *owner; diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp index cec598774e..c05bbb3cd4 100644 --- a/scene/2d/polygon_2d.cpp +++ b/scene/2d/polygon_2d.cpp @@ -81,7 +81,6 @@ bool Polygon2D::_edit_use_rect() const { } bool Polygon2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - Vector<Vector2> polygon2d = Variant(polygon); if (internal_vertices > 0) { polygon2d.resize(polygon2d.size() - internal_vertices); @@ -95,11 +94,8 @@ void Polygon2D::_skeleton_bone_setup_changed() { } void Polygon2D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_DRAW: { - if (polygon.size() < 3) return; @@ -147,7 +143,6 @@ void Polygon2D::_notification(int p_what) { points.resize(len); { - const Vector2 *polyr = polygon.ptr(); for (int i = 0; i < len; i++) { points.write[i] = polyr[i] + offset; @@ -155,7 +150,6 @@ void Polygon2D::_notification(int p_what) { } if (invert) { - Rect2 bounds; int highest_idx = -1; float highest_y = -1e20; @@ -195,12 +189,10 @@ void Polygon2D::_notification(int p_what) { points.resize(points.size() + 7); for (int i = points.size() - 1; i >= highest_idx + 7; i--) { - points.write[i] = points[i - 7]; } for (int i = 0; i < 7; i++) { - points.write[highest_idx + i + 1] = ep[i]; } @@ -208,7 +200,6 @@ void Polygon2D::_notification(int p_what) { } if (texture.is_valid()) { - Transform2D texmat(tex_rot, tex_ofs); texmat.scale(tex_scale); Size2 tex_size = texture->get_size(); @@ -216,7 +207,6 @@ void Polygon2D::_notification(int p_what) { uvs.resize(len); if (points.size() == uv.size()) { - const Vector2 *uvr = uv.ptr(); for (int i = 0; i < len; i++) { @@ -356,12 +346,10 @@ void Polygon2D::set_polygon(const Vector<Vector2> &p_polygon) { } Vector<Vector2> Polygon2D::get_polygon() const { - return polygon; } void Polygon2D::set_internal_vertex_count(int p_count) { - internal_vertices = p_count; } @@ -370,49 +358,40 @@ int Polygon2D::get_internal_vertex_count() const { } void Polygon2D::set_uv(const Vector<Vector2> &p_uv) { - uv = p_uv; update(); } Vector<Vector2> Polygon2D::get_uv() const { - return uv; } void Polygon2D::set_polygons(const Array &p_polygons) { - polygons = p_polygons; update(); } Array Polygon2D::get_polygons() const { - return polygons; } void Polygon2D::set_color(const Color &p_color) { - color = p_color; update(); } Color Polygon2D::get_color() const { - return color; } void Polygon2D::set_vertex_colors(const Vector<Color> &p_colors) { - vertex_colors = p_colors; update(); } Vector<Color> Polygon2D::get_vertex_colors() const { - return vertex_colors; } void Polygon2D::set_texture(const Ref<Texture2D> &p_texture) { - texture = p_texture; /*if (texture.is_valid()) { @@ -426,7 +405,6 @@ void Polygon2D::set_texture(const Ref<Texture2D> &p_texture) { update(); } Ref<Texture2D> Polygon2D::get_texture() const { - return texture; } @@ -467,76 +445,61 @@ float Polygon2D::get_shininess() const { } void Polygon2D::set_texture_offset(const Vector2 &p_offset) { - tex_ofs = p_offset; update(); } Vector2 Polygon2D::get_texture_offset() const { - return tex_ofs; } void Polygon2D::set_texture_rotation(float p_rot) { - tex_rot = p_rot; update(); } float Polygon2D::get_texture_rotation() const { - return tex_rot; } void Polygon2D::set_texture_rotation_degrees(float p_rot) { - set_texture_rotation(Math::deg2rad(p_rot)); } float Polygon2D::get_texture_rotation_degrees() const { - return Math::rad2deg(get_texture_rotation()); } void Polygon2D::set_texture_scale(const Size2 &p_scale) { - tex_scale = p_scale; update(); } Size2 Polygon2D::get_texture_scale() const { - return tex_scale; } void Polygon2D::set_invert(bool p_invert) { - invert = p_invert; update(); } bool Polygon2D::get_invert() const { - return invert; } void Polygon2D::set_antialiased(bool p_antialiased) { - antialiased = p_antialiased; update(); } bool Polygon2D::get_antialiased() const { - return antialiased; } void Polygon2D::set_invert_border(float p_invert_border) { - invert_border = p_invert_border; update(); } float Polygon2D::get_invert_border() const { - return invert_border; } void Polygon2D::set_offset(const Vector2 &p_offset) { - offset = p_offset; rect_cache_dirty = true; update(); @@ -544,12 +507,10 @@ void Polygon2D::set_offset(const Vector2 &p_offset) { } Vector2 Polygon2D::get_offset() const { - return offset; } void Polygon2D::add_bone(const NodePath &p_path, const Vector<float> &p_weights) { - Bone bone; bone.path = p_path; bone.weights = p_weights; @@ -563,12 +524,10 @@ NodePath Polygon2D::get_bone_path(int p_index) const { return bone_weights[p_index].path; } Vector<float> Polygon2D::get_bone_weights(int p_index) const { - ERR_FAIL_INDEX_V(p_index, bone_weights.size(), Vector<float>()); return bone_weights[p_index].weights; } void Polygon2D::erase_bone(int p_idx) { - ERR_FAIL_INDEX(p_idx, bone_weights.size()); bone_weights.remove(p_idx); } @@ -597,7 +556,6 @@ Array Polygon2D::_get_bones() const { return bones; } void Polygon2D::_set_bones(const Array &p_bones) { - ERR_FAIL_COND(p_bones.size() & 1); clear_bones(); for (int i = 0; i < p_bones.size(); i += 2) { @@ -617,7 +575,6 @@ NodePath Polygon2D::get_skeleton() const { } void Polygon2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &Polygon2D::set_polygon); ClassDB::bind_method(D_METHOD("get_polygon"), &Polygon2D::get_polygon); @@ -722,7 +679,6 @@ void Polygon2D::_bind_methods() { } Polygon2D::Polygon2D() { - invert = false; invert_border = 100; antialiased = false; diff --git a/scene/2d/polygon_2d.h b/scene/2d/polygon_2d.h index 777c1f82f3..dafec1c343 100644 --- a/scene/2d/polygon_2d.h +++ b/scene/2d/polygon_2d.h @@ -34,7 +34,6 @@ #include "scene/2d/node_2d.h" class Polygon2D : public Node2D { - GDCLASS(Polygon2D, Node2D); Vector<Vector2> polygon; diff --git a/scene/2d/position_2d.cpp b/scene/2d/position_2d.cpp index 9e95a55d9f..4cd46171c6 100644 --- a/scene/2d/position_2d.cpp +++ b/scene/2d/position_2d.cpp @@ -36,7 +36,6 @@ const float DEFAULT_GIZMO_EXTENTS = 10.0; void Position2D::_draw_cross() { - float extents = get_gizmo_extents(); // Colors taken from `axis_x_color` and `axis_y_color` (defined in `editor/editor_themes.cpp`) draw_line(Point2(-extents, 0), Point2(+extents, 0), Color(0.96, 0.20, 0.32)); @@ -45,7 +44,6 @@ void Position2D::_draw_cross() { #ifdef TOOLS_ENABLED Rect2 Position2D::_edit_get_rect() const { - float extents = get_gizmo_extents(); return Rect2(Point2(-extents, -extents), Size2(extents * 2, extents * 2)); } @@ -56,11 +54,8 @@ bool Position2D::_edit_use_rect() const { #endif void Position2D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - update(); } break; case NOTIFICATION_DRAW: { @@ -92,7 +87,6 @@ float Position2D::get_gizmo_extents() const { } void Position2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("_set_gizmo_extents", "extents"), &Position2D::set_gizmo_extents); ClassDB::bind_method(D_METHOD("_get_gizmo_extents"), &Position2D::get_gizmo_extents); diff --git a/scene/2d/position_2d.h b/scene/2d/position_2d.h index 3ea636171d..b53fa4c0e2 100644 --- a/scene/2d/position_2d.h +++ b/scene/2d/position_2d.h @@ -34,7 +34,6 @@ #include "scene/2d/node_2d.h" class Position2D : public Node2D { - GDCLASS(Position2D, Node2D); void _draw_cross(); diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index 9d6c7304ce..707b6da67d 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -36,29 +36,24 @@ #include "servers/physics_server_2d.h" void RayCast2D::set_cast_to(const Vector2 &p_point) { - cast_to = p_point; if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) update(); } Vector2 RayCast2D::get_cast_to() const { - return cast_to; } void RayCast2D::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; } uint32_t RayCast2D::get_collision_mask() const { - return collision_mask; } void RayCast2D::set_collision_mask_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_mask(); if (p_value) mask |= 1 << p_bit; @@ -68,16 +63,13 @@ void RayCast2D::set_collision_mask_bit(int p_bit, bool p_value) { } bool RayCast2D::get_collision_mask_bit(int p_bit) const { - return get_collision_mask() & (1 << p_bit); } bool RayCast2D::is_colliding() const { - return collided; } Object *RayCast2D::get_collider() const { - if (against.is_null()) return nullptr; @@ -85,20 +77,16 @@ Object *RayCast2D::get_collider() const { } int RayCast2D::get_collider_shape() const { - return against_shape; } Vector2 RayCast2D::get_collision_point() const { - return collision_point; } Vector2 RayCast2D::get_collision_normal() const { - return collision_normal; } void RayCast2D::set_enabled(bool p_enabled) { - enabled = p_enabled; update(); if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) @@ -108,12 +96,10 @@ void RayCast2D::set_enabled(bool p_enabled) { } bool RayCast2D::is_enabled() const { - return enabled; } void RayCast2D::set_exclude_parent_body(bool p_exclude_parent_body) { - if (exclude_parent_body == p_exclude_parent_body) return; @@ -131,16 +117,12 @@ void RayCast2D::set_exclude_parent_body(bool p_exclude_parent_body) { } bool RayCast2D::get_exclude_parent_body() const { - return exclude_parent_body; } void RayCast2D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - if (enabled && !Engine::get_singleton()->is_editor_hint()) set_physics_process_internal(true); else @@ -154,14 +136,12 @@ void RayCast2D::_notification(int p_what) { } } break; case NOTIFICATION_EXIT_TREE: { - if (enabled) set_physics_process_internal(false); } break; case NOTIFICATION_DRAW: { - if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) break; Transform2D xf; @@ -191,7 +171,6 @@ void RayCast2D::_notification(int p_what) { } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { - if (!enabled) break; @@ -217,7 +196,6 @@ void RayCast2D::_update_raycast_state() { PhysicsDirectSpaceState2D::RayResult rr; if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask, collide_with_bodies, collide_with_areas)) { - collided = true; against = rr.collider_id; collision_point = rr.position; @@ -235,12 +213,10 @@ void RayCast2D::force_raycast_update() { } void RayCast2D::add_exception_rid(const RID &p_rid) { - exclude.insert(p_rid); } void RayCast2D::add_exception(const Object *p_object) { - ERR_FAIL_NULL(p_object); const CollisionObject2D *co = Object::cast_to<CollisionObject2D>(p_object); if (!co) @@ -249,12 +225,10 @@ void RayCast2D::add_exception(const Object *p_object) { } void RayCast2D::remove_exception_rid(const RID &p_rid) { - exclude.erase(p_rid); } void RayCast2D::remove_exception(const Object *p_object) { - ERR_FAIL_NULL(p_object); const CollisionObject2D *co = Object::cast_to<CollisionObject2D>(p_object); if (!co) @@ -263,32 +237,26 @@ void RayCast2D::remove_exception(const Object *p_object) { } void RayCast2D::clear_exceptions() { - exclude.clear(); } void RayCast2D::set_collide_with_areas(bool p_clip) { - collide_with_areas = p_clip; } bool RayCast2D::is_collide_with_areas_enabled() const { - return collide_with_areas; } void RayCast2D::set_collide_with_bodies(bool p_clip) { - collide_with_bodies = p_clip; } bool RayCast2D::is_collide_with_bodies_enabled() const { - return collide_with_bodies; } void RayCast2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &RayCast2D::set_enabled); ClassDB::bind_method(D_METHOD("is_enabled"), &RayCast2D::is_enabled); @@ -337,7 +305,6 @@ void RayCast2D::_bind_methods() { } RayCast2D::RayCast2D() { - enabled = false; collided = false; diff --git a/scene/2d/ray_cast_2d.h b/scene/2d/ray_cast_2d.h index 20f05e7525..6accc264a0 100644 --- a/scene/2d/ray_cast_2d.h +++ b/scene/2d/ray_cast_2d.h @@ -34,7 +34,6 @@ #include "scene/2d/node_2d.h" class RayCast2D : public Node2D { - GDCLASS(RayCast2D, Node2D); bool enabled; diff --git a/scene/2d/remote_transform_2d.cpp b/scene/2d/remote_transform_2d.cpp index ec50f5f922..d9b73a5e6e 100644 --- a/scene/2d/remote_transform_2d.cpp +++ b/scene/2d/remote_transform_2d.cpp @@ -32,7 +32,6 @@ #include "scene/scene_string_names.h" void RemoteTransform2D::_update_cache() { - cache = ObjectID(); if (has_node(remote_node)) { Node *node = get_node(remote_node); @@ -45,7 +44,6 @@ void RemoteTransform2D::_update_cache() { } void RemoteTransform2D::_update_remote() { - if (!is_inside_tree()) return; @@ -61,7 +59,6 @@ void RemoteTransform2D::_update_remote() { //todo make faster if (use_global_coordinates) { - if (update_remote_position && update_remote_rotation && update_remote_scale) { n->set_global_transform(get_global_transform()); } else { @@ -83,7 +80,6 @@ void RemoteTransform2D::_update_remote() { } } else { - if (update_remote_position && update_remote_rotation && update_remote_scale) { n->set_transform(get_transform()); } else { @@ -107,11 +103,8 @@ void RemoteTransform2D::_update_remote() { } void RemoteTransform2D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - _update_cache(); } break; @@ -120,7 +113,6 @@ void RemoteTransform2D::_notification(int p_what) { break; if (cache.is_valid()) { - _update_remote(); } @@ -129,7 +121,6 @@ void RemoteTransform2D::_notification(int p_what) { } void RemoteTransform2D::set_remote_node(const NodePath &p_remote_node) { - remote_node = p_remote_node; if (is_inside_tree()) { _update_cache(); @@ -140,7 +131,6 @@ void RemoteTransform2D::set_remote_node(const NodePath &p_remote_node) { } NodePath RemoteTransform2D::get_remote_node() const { - return remote_node; } @@ -185,7 +175,6 @@ void RemoteTransform2D::force_update_cache() { } String RemoteTransform2D::get_configuration_warning() const { - if (!has_node(remote_node) || !Object::cast_to<Node2D>(get_node(remote_node))) { return TTR("Path property must point to a valid Node2D node to work."); } @@ -194,7 +183,6 @@ String RemoteTransform2D::get_configuration_warning() const { } void RemoteTransform2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_remote_node", "path"), &RemoteTransform2D::set_remote_node); ClassDB::bind_method(D_METHOD("get_remote_node"), &RemoteTransform2D::get_remote_node); ClassDB::bind_method(D_METHOD("force_update_cache"), &RemoteTransform2D::force_update_cache); @@ -219,7 +207,6 @@ void RemoteTransform2D::_bind_methods() { } RemoteTransform2D::RemoteTransform2D() { - use_global_coordinates = true; update_remote_position = true; update_remote_rotation = true; diff --git a/scene/2d/remote_transform_2d.h b/scene/2d/remote_transform_2d.h index f5b949d10b..caaa0394f2 100644 --- a/scene/2d/remote_transform_2d.h +++ b/scene/2d/remote_transform_2d.h @@ -34,7 +34,6 @@ #include "scene/2d/node_2d.h" class RemoteTransform2D : public Node2D { - GDCLASS(RemoteTransform2D, Node2D); NodePath remote_node; diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp index 86c9ff6076..e21f7ff836 100644 --- a/scene/2d/skeleton_2d.cpp +++ b/scene/2d/skeleton_2d.cpp @@ -31,7 +31,6 @@ #include "skeleton_2d.h" void Bone2D::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { Node *parent = get_parent(); parent_bone = Object::cast_to<Bone2D>(parent); @@ -79,7 +78,6 @@ void Bone2D::_notification(int p_what) { } } void Bone2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_rest", "rest"), &Bone2D::set_rest); ClassDB::bind_method(D_METHOD("get_rest"), &Bone2D::get_rest); ClassDB::bind_method(D_METHOD("apply_rest"), &Bone2D::apply_rest); @@ -106,7 +104,6 @@ Transform2D Bone2D::get_rest() const { } Transform2D Bone2D::get_skeleton_rest() const { - if (parent_bone) { return parent_bone->get_skeleton_rest() * rest; } else { @@ -119,7 +116,6 @@ void Bone2D::apply_rest() { } void Bone2D::set_default_length(float p_length) { - default_length = p_length; } @@ -133,7 +129,6 @@ int Bone2D::get_index_in_skeleton() const { return skeleton_index; } String Bone2D::get_configuration_warning() const { - String warning = Node2D::get_configuration_warning(); if (!skeleton) { if (warning != String()) { @@ -171,7 +166,6 @@ Bone2D::Bone2D() { ////////////////////////////////////// void Skeleton2D::_make_bone_setup_dirty() { - if (bone_setup_dirty) return; bone_setup_dirty = true; @@ -181,7 +175,6 @@ void Skeleton2D::_make_bone_setup_dirty() { } void Skeleton2D::_update_bone_setup() { - if (!bone_setup_dirty) return; @@ -207,7 +200,6 @@ void Skeleton2D::_update_bone_setup() { } void Skeleton2D::_make_transform_dirty() { - if (transform_dirty) return; transform_dirty = true; @@ -217,7 +209,6 @@ void Skeleton2D::_make_transform_dirty() { } void Skeleton2D::_update_transform() { - if (bone_setup_dirty) { _update_bone_setup(); return; //above will update transform anyway @@ -228,7 +219,6 @@ void Skeleton2D::_update_transform() { transform_dirty = false; for (int i = 0; i < bones.size(); i++) { - ERR_CONTINUE(bones[i].parent_index >= i); if (bones[i].parent_index >= 0) { bones.write[i].accum_transform = bones[bones[i].parent_index].accum_transform * bones[i].bone->get_transform(); @@ -238,14 +228,12 @@ void Skeleton2D::_update_transform() { } for (int i = 0; i < bones.size(); i++) { - Transform2D final_xform = bones[i].accum_transform * bones[i].rest_inverse; RS::get_singleton()->skeleton_bone_set_transform_2d(skeleton, i, final_xform); } } int Skeleton2D::get_bone_count() const { - ERR_FAIL_COND_V(!is_inside_tree(), 0); if (bone_setup_dirty) { @@ -256,7 +244,6 @@ int Skeleton2D::get_bone_count() const { } Bone2D *Skeleton2D::get_bone(int p_idx) { - ERR_FAIL_COND_V(!is_inside_tree(), nullptr); ERR_FAIL_INDEX_V(p_idx, bones.size(), nullptr); @@ -264,9 +251,7 @@ Bone2D *Skeleton2D::get_bone(int p_idx) { } void Skeleton2D::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - if (bone_setup_dirty) _update_bone_setup(); if (transform_dirty) @@ -284,7 +269,6 @@ RID Skeleton2D::get_skeleton() const { return skeleton; } void Skeleton2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("_update_bone_setup"), &Skeleton2D::_update_bone_setup); ClassDB::bind_method(D_METHOD("_update_transform"), &Skeleton2D::_update_transform); @@ -305,6 +289,5 @@ Skeleton2D::Skeleton2D() { } Skeleton2D::~Skeleton2D() { - RS::get_singleton()->free(skeleton); } diff --git a/scene/2d/sprite_2d.cpp b/scene/2d/sprite_2d.cpp index df8859bd9a..4df66057f0 100644 --- a/scene/2d/sprite_2d.cpp +++ b/scene/2d/sprite_2d.cpp @@ -61,7 +61,6 @@ bool Sprite2D::_edit_use_pivot() const { } bool Sprite2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - return is_pixel_opaque(p_point); } @@ -79,7 +78,6 @@ Rect2 Sprite2D::get_anchorable_rect() const { } void Sprite2D::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_clip) const { - Rect2 base_rect; if (region) { @@ -113,11 +111,8 @@ void Sprite2D::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_c } void Sprite2D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_DRAW: { - if (texture.is_null()) return; @@ -138,7 +133,6 @@ void Sprite2D::_notification(int p_what) { } void Sprite2D::set_texture(const Ref<Texture2D> &p_texture) { - if (p_texture == texture) return; @@ -157,24 +151,20 @@ void Sprite2D::set_texture(const Ref<Texture2D> &p_texture) { } void Sprite2D::set_normal_map(const Ref<Texture2D> &p_texture) { - normal_map = p_texture; update(); } Ref<Texture2D> Sprite2D::get_normal_map() const { - return normal_map; } void Sprite2D::set_specular_map(const Ref<Texture2D> &p_texture) { - specular = p_texture; update(); } Ref<Texture2D> Sprite2D::get_specular_map() const { - return specular; } @@ -197,56 +187,46 @@ float Sprite2D::get_shininess() const { } Ref<Texture2D> Sprite2D::get_texture() const { - return texture; } void Sprite2D::set_centered(bool p_center) { - centered = p_center; update(); item_rect_changed(); } bool Sprite2D::is_centered() const { - return centered; } void Sprite2D::set_offset(const Point2 &p_offset) { - offset = p_offset; update(); item_rect_changed(); _change_notify("offset"); } Point2 Sprite2D::get_offset() const { - return offset; } void Sprite2D::set_flip_h(bool p_flip) { - hflip = p_flip; update(); } bool Sprite2D::is_flipped_h() const { - return hflip; } void Sprite2D::set_flip_v(bool p_flip) { - vflip = p_flip; update(); } bool Sprite2D::is_flipped_v() const { - return vflip; } void Sprite2D::set_region(bool p_region) { - if (p_region == region) return; @@ -255,12 +235,10 @@ void Sprite2D::set_region(bool p_region) { } bool Sprite2D::is_region() const { - return region; } void Sprite2D::set_region_rect(const Rect2 &p_region_rect) { - if (region_rect == p_region_rect) return; @@ -273,7 +251,6 @@ void Sprite2D::set_region_rect(const Rect2 &p_region_rect) { } Rect2 Sprite2D::get_region_rect() const { - return region_rect; } @@ -287,7 +264,6 @@ bool Sprite2D::is_region_filter_clip_enabled() const { } void Sprite2D::set_frame(int p_frame) { - ERR_FAIL_INDEX(p_frame, vframes * hframes); if (frame != p_frame) @@ -301,7 +277,6 @@ void Sprite2D::set_frame(int p_frame) { } int Sprite2D::get_frame() const { - return frame; } @@ -317,7 +292,6 @@ Vector2 Sprite2D::get_frame_coords() const { } void Sprite2D::set_vframes(int p_amount) { - ERR_FAIL_COND_MSG(p_amount < 1, "Amount of vframes cannot be smaller than 1."); vframes = p_amount; update(); @@ -325,12 +299,10 @@ void Sprite2D::set_vframes(int p_amount) { _change_notify(); } int Sprite2D::get_vframes() const { - return vframes; } void Sprite2D::set_hframes(int p_amount) { - ERR_FAIL_COND_MSG(p_amount < 1, "Amount of hframes cannot be smaller than 1."); hframes = p_amount; update(); @@ -338,12 +310,10 @@ void Sprite2D::set_hframes(int p_amount) { _change_notify(); } int Sprite2D::get_hframes() const { - return hframes; } bool Sprite2D::is_pixel_opaque(const Point2 &p_point) const { - if (texture.is_null()) return false; @@ -393,7 +363,6 @@ bool Sprite2D::is_pixel_opaque(const Point2 &p_point) const { } Rect2 Sprite2D::get_rect() const { - if (texture.is_null()) return Rect2(0, 0, 1, 1); @@ -418,7 +387,6 @@ Rect2 Sprite2D::get_rect() const { } void Sprite2D::_validate_property(PropertyInfo &property) const { - if (property.name == "frame") { property.hint = PROPERTY_HINT_RANGE; property.hint_string = "0," + itos(vframes * hframes - 1) + ",1"; @@ -431,7 +399,6 @@ void Sprite2D::_validate_property(PropertyInfo &property) const { } void Sprite2D::_texture_changed() { - // Changes to the texture need to trigger an update to make // the editor redraw the sprite with the updated texture. if (texture.is_valid()) { @@ -440,7 +407,6 @@ void Sprite2D::_texture_changed() { } void Sprite2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_texture", "texture"), &Sprite2D::set_texture); ClassDB::bind_method(D_METHOD("get_texture"), &Sprite2D::get_texture); @@ -520,7 +486,6 @@ void Sprite2D::_bind_methods() { } Sprite2D::Sprite2D() { - centered = true; hflip = false; vflip = false; diff --git a/scene/2d/sprite_2d.h b/scene/2d/sprite_2d.h index 599a9e937e..c72e956307 100644 --- a/scene/2d/sprite_2d.h +++ b/scene/2d/sprite_2d.h @@ -35,7 +35,6 @@ #include "scene/resources/texture.h" class Sprite2D : public Node2D { - GDCLASS(Sprite2D, Node2D); Ref<Texture2D> texture; diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 869f290f97..fa66a2af22 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -39,7 +39,6 @@ #include "servers/physics_server_2d.h" int TileMap::_get_quadrant_size() const { - if (use_y_sort) return 1; else @@ -47,14 +46,10 @@ int TileMap::_get_quadrant_size() const { } void TileMap::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - Node2D *c = this; while (c) { - navigation = Object::cast_to<Navigation2D>(c); if (navigation) { break; @@ -79,14 +74,11 @@ void TileMap::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { - _update_quadrant_space(RID()); for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); if (navigation) { for (Map<PosKey, Quadrant::NavPoly>::Element *F = q.navpoly_ids.front(); F; F = F->next()) { - NavigationServer2D::get_singleton()->region_set_map(F->get().region, RID()); } q.navpoly_ids.clear(); @@ -109,13 +101,11 @@ void TileMap::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { - //move stuff _update_quadrant_transform(); } break; case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { - if (use_parent) { _recreate_quadrants(); } @@ -125,10 +115,8 @@ void TileMap::_notification(int p_what) { } void TileMap::_update_quadrant_space(const RID &p_space) { - if (!use_parent) { for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); PhysicsServer2D::get_singleton()->body_set_space(q.body, p_space); } @@ -136,7 +124,6 @@ void TileMap::_update_quadrant_space(const RID &p_space) { } void TileMap::_update_quadrant_transform() { - if (!is_inside_tree()) return; @@ -151,7 +138,6 @@ void TileMap::_update_quadrant_transform() { nav_rel = get_relative_transform_to_parent(navigation); for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); Transform2D xform; xform.set_origin(q.pos); @@ -163,7 +149,6 @@ void TileMap::_update_quadrant_transform() { if (navigation) { for (Map<PosKey, Quadrant::NavPoly>::Element *F = q.navpoly_ids.front(); F; F = F->next()) { - NavigationServer2D::get_singleton()->region_set_transform(F->get().region, nav_rel * F->get().xform); } } @@ -175,7 +160,6 @@ void TileMap::_update_quadrant_transform() { } void TileMap::set_tileset(const Ref<TileSet> &p_tileset) { - if (tile_set.is_valid()) { tile_set->disconnect("changed", callable_mp(this, &TileMap::_recreate_quadrants)); tile_set->remove_change_receptor(this); @@ -196,12 +180,10 @@ void TileMap::set_tileset(const Ref<TileSet> &p_tileset) { } Ref<TileSet> TileMap::get_tileset() const { - return tile_set; } void TileMap::set_cell_size(Size2 p_size) { - ERR_FAIL_COND(p_size.x < 1 || p_size.y < 1); _clear_quadrants(); @@ -211,12 +193,10 @@ void TileMap::set_cell_size(Size2 p_size) { } Size2 TileMap::get_cell_size() const { - return cell_size; } void TileMap::set_quadrant_size(int p_size) { - ERR_FAIL_COND_MSG(p_size < 1, "Quadrant size cannot be smaller than 1."); _clear_quadrants(); @@ -226,17 +206,14 @@ void TileMap::set_quadrant_size(int p_size) { } int TileMap::get_quadrant_size() const { - return quadrant_size; } void TileMap::_fix_cell_transform(Transform2D &xform, const Cell &p_cell, const Vector2 &p_offset, const Size2 &p_sc) { - Size2 s = p_sc; Vector2 offset = p_offset; if (compatibility_mode && !centered_textures) { - if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) { offset.y += cell_size.y; } else if (tile_origin == TILE_ORIGIN_CENTER) { @@ -326,7 +303,6 @@ void TileMap::_add_shape(int &shape_idx, const Quadrant &p_q, const Ref<Shape2D> } void TileMap::update_dirty_quadrants() { - if (!pending_update) return; if (!is_inside_tree() || !tile_set.is_valid()) { @@ -358,11 +334,9 @@ void TileMap::update_dirty_quadrants() { } while (dirty_quadrant_list.first()) { - Quadrant &q = *dirty_quadrant_list.first()->self(); for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) { - vs->free(E->get()); } @@ -377,7 +351,6 @@ void TileMap::update_dirty_quadrants() { if (navigation) { for (Map<PosKey, Quadrant::NavPoly>::Element *E = q.navpoly_ids.front(); E; E = E->next()) { - NavigationServer2D::get_singleton()->region_set_map(E->get().region, RID()); } q.navpoly_ids.clear(); @@ -393,7 +366,6 @@ void TileMap::update_dirty_quadrants() { RID prev_debug_canvas_item; for (int i = 0; i < q.cells.size(); i++) { - Map<PosKey, Cell>::Element *E = tile_map.find(q.cells[i]); Cell &c = E->get(); //moment of truth @@ -420,7 +392,6 @@ void TileMap::update_dirty_quadrants() { RID debug_canvas_item; if (prev_canvas_item == RID() || prev_material != mat || prev_z_index != z_index) { - canvas_item = vs->canvas_item_create(); if (mat.is_valid()) vs->canvas_item_set_material(canvas_item, mat->get_rid()); @@ -435,7 +406,6 @@ void TileMap::update_dirty_quadrants() { q.canvas_items.push_back(canvas_item); if (debug_shapes) { - debug_canvas_item = vs->canvas_item_create(); vs->canvas_item_set_parent(debug_canvas_item, canvas_item); vs->canvas_item_set_z_as_relative_to_parent(debug_canvas_item, false); @@ -509,7 +479,6 @@ void TileMap::update_dirty_quadrants() { rect.position += tile_ofs; } else if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) { - rect.position += tile_ofs; if (c.transpose) { @@ -525,7 +494,6 @@ void TileMap::update_dirty_quadrants() { } } else if (tile_origin == TILE_ORIGIN_CENTER) { - rect.position += tile_ofs; if (c.flip_h) @@ -651,10 +619,8 @@ void TileMap::update_dirty_quadrants() { Vector<int> polygon = navpoly->get_polygon(j); for (int k = 2; k < polygon.size(); k++) { - int kofs[3] = { 0, k - 1, k }; for (int l = 0; l < 3; l++) { - int idx = polygon[kofs[l]]; ERR_FAIL_INDEX(idx, vsize); indices.push_back(idx); @@ -704,13 +670,10 @@ void TileMap::update_dirty_quadrants() { pending_update = false; if (quadrant_order_dirty) { - int index = -(int64_t)0x80000000; //always must be drawn below children for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); for (List<RID>::Element *F = q.canvas_items.front(); F; F = F->next()) { - RS::get_singleton()->canvas_item_set_draw_index(F->get(), index++); } } @@ -722,7 +685,6 @@ void TileMap::update_dirty_quadrants() { } void TileMap::_recompute_rect_cache() { - #ifdef DEBUG_ENABLED if (!rect_cache_dirty) @@ -730,7 +692,6 @@ void TileMap::_recompute_rect_cache() { Rect2 r_total; for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Rect2 r; r.position = _map_to_world(E->key().x * _get_quadrant_size(), E->key().y * _get_quadrant_size()); r.expand_to(_map_to_world(E->key().x * _get_quadrant_size() + _get_quadrant_size(), E->key().y * _get_quadrant_size())); @@ -751,7 +712,6 @@ void TileMap::_recompute_rect_cache() { } Map<TileMap::PosKey, TileMap::Quadrant>::Element *TileMap::_create_quadrant(const PosKey &p_qk) { - Transform2D xform; //xform.set_origin(Point2(p_qk.x,p_qk.y)*cell_size*quadrant_size); Quadrant q; @@ -794,7 +754,6 @@ Map<TileMap::PosKey, TileMap::Quadrant>::Element *TileMap::_create_quadrant(cons } void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) { - Quadrant &q = Q->get(); if (!use_parent) { PhysicsServer2D::get_singleton()->free(q.body); @@ -803,7 +762,6 @@ void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) { } for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) { - RenderingServer::get_singleton()->free(E->get()); } q.canvas_items.clear(); @@ -812,7 +770,6 @@ void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) { if (navigation) { for (Map<PosKey, Quadrant::NavPoly>::Element *E = q.navpoly_ids.front(); E; E = E->next()) { - NavigationServer2D::get_singleton()->region_set_map(E->get().region, RID()); } q.navpoly_ids.clear(); @@ -828,7 +785,6 @@ void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) { } void TileMap::_make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q, bool update) { - Quadrant &q = Q->get(); if (!q.dirty_list.in_list()) dirty_quadrant_list.add(&q.dirty_list); @@ -845,12 +801,10 @@ void TileMap::_make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q, bool updat } void TileMap::set_cellv(const Vector2 &p_pos, int p_tile, bool p_flip_x, bool p_flip_y, bool p_transpose) { - set_cell(p_pos.x, p_pos.y, p_tile, p_flip_x, p_flip_y, p_transpose); } void TileMap::_set_celld(const Vector2 &p_pos, const Dictionary &p_data) { - Variant v_pos_x = p_pos.x, v_pos_y = p_pos.y, v_tile = p_data["id"], v_flip_h = p_data["flip_h"], v_flip_v = p_data["flip_y"], v_transpose = p_data["transpose"], v_autotile_coord = p_data["auto_coord"]; const Variant *args[7] = { &v_pos_x, &v_pos_y, &v_tile, &v_flip_h, &v_flip_v, &v_transpose, &v_autotile_coord }; Callable::CallError ce; @@ -858,7 +812,6 @@ void TileMap::_set_celld(const Vector2 &p_pos, const Dictionary &p_data) { } void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_y, bool p_transpose, Vector2 p_autotile_coord) { - PosKey pk(p_x, p_y); Map<PosKey, Cell>::Element *E = tile_map.find(pk); @@ -912,12 +865,10 @@ void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_ } int TileMap::get_cellv(const Vector2 &p_pos) const { - return get_cell(p_pos.x, p_pos.y); } void TileMap::make_bitmask_area_dirty(const Vector2 &p_pos) { - for (int x = p_pos.x - 1; x <= p_pos.x + 1; x++) { for (int y = p_pos.y - 1; y <= p_pos.y + 1; y++) { PosKey p(x, y); @@ -929,7 +880,6 @@ void TileMap::make_bitmask_area_dirty(const Vector2 &p_pos) { } void TileMap::update_bitmask_area(const Vector2 &p_pos) { - for (int x = p_pos.x - 1; x <= p_pos.x + 1; x++) { for (int y = p_pos.y - 1; y <= p_pos.y + 1; y++) { update_cell_bitmask(x, y); @@ -938,7 +888,6 @@ void TileMap::update_bitmask_area(const Vector2 &p_pos) { } void TileMap::update_bitmask_region(const Vector2 &p_start, const Vector2 &p_end) { - if ((p_end.x < p_start.x || p_end.y < p_start.y) || (p_end.x == p_start.x && p_end.y == p_start.y)) { Array a = get_used_cells(); for (int i = 0; i < a.size(); i++) { @@ -955,7 +904,6 @@ void TileMap::update_bitmask_region(const Vector2 &p_start, const Vector2 &p_end } void TileMap::update_cell_bitmask(int p_x, int p_y) { - ERR_FAIL_COND_MSG(tile_set.is_null(), "Cannot update cell bitmask if Tileset is not open."); PosKey p(p_x, p_y); Map<PosKey, Cell>::Element *E = tile_map.find(p); @@ -1027,11 +975,9 @@ void TileMap::update_cell_bitmask(int p_x, int p_y) { _make_quadrant_dirty(Q); } else if (tile_set->tile_get_tile_mode(id) == TileSet::SINGLE_TILE) { - E->get().autotile_coord_x = 0; E->get().autotile_coord_y = 0; } else if (tile_set->tile_get_tile_mode(id) == TileSet::ATLAS_TILE) { - if (tile_set->autotile_get_bitmask(id, Vector2(p_x, p_y)) == TileSet::BIND_CENTER) { Vector2 coord = tile_set->atlastile_get_subtile_by_priority(id, this, Vector2(p_x, p_y)); @@ -1043,7 +989,6 @@ void TileMap::update_cell_bitmask(int p_x, int p_y) { } void TileMap::update_dirty_bitmask() { - while (dirty_bitmask.size() > 0) { update_cell_bitmask(dirty_bitmask[0].x, dirty_bitmask[0].y); dirty_bitmask.pop_front(); @@ -1051,10 +996,8 @@ void TileMap::update_dirty_bitmask() { } void TileMap::fix_invalid_tiles() { - ERR_FAIL_COND_MSG(tile_set.is_null(), "Cannot fix invalid tiles if Tileset is not open."); for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) { - if (!tile_set->has_tile(get_cell(E->key().x, E->key().y))) { set_cell(E->key().x, E->key().y, INVALID_CELL); } @@ -1062,7 +1005,6 @@ void TileMap::fix_invalid_tiles() { } int TileMap::get_cell(int p_x, int p_y) const { - PosKey pk(p_x, p_y); const Map<PosKey, Cell>::Element *E = tile_map.find(pk); @@ -1073,7 +1015,6 @@ int TileMap::get_cell(int p_x, int p_y) const { return E->get().id; } bool TileMap::is_cell_x_flipped(int p_x, int p_y) const { - PosKey pk(p_x, p_y); const Map<PosKey, Cell>::Element *E = tile_map.find(pk); @@ -1084,7 +1025,6 @@ bool TileMap::is_cell_x_flipped(int p_x, int p_y) const { return E->get().flip_h; } bool TileMap::is_cell_y_flipped(int p_x, int p_y) const { - PosKey pk(p_x, p_y); const Map<PosKey, Cell>::Element *E = tile_map.find(pk); @@ -1095,7 +1035,6 @@ bool TileMap::is_cell_y_flipped(int p_x, int p_y) const { return E->get().flip_v; } bool TileMap::is_cell_transposed(int p_x, int p_y) const { - PosKey pk(p_x, p_y); const Map<PosKey, Cell>::Element *E = tile_map.find(pk); @@ -1107,7 +1046,6 @@ bool TileMap::is_cell_transposed(int p_x, int p_y) const { } void TileMap::set_cell_autotile_coord(int p_x, int p_y, const Vector2 &p_coord) { - PosKey pk(p_x, p_y); const Map<PosKey, Cell>::Element *E = tile_map.find(pk); @@ -1130,7 +1068,6 @@ void TileMap::set_cell_autotile_coord(int p_x, int p_y, const Vector2 &p_coord) } Vector2 TileMap::get_cell_autotile_coord(int p_x, int p_y) const { - PosKey pk(p_x, p_y); const Map<PosKey, Cell>::Element *E = tile_map.find(pk); @@ -1142,11 +1079,9 @@ Vector2 TileMap::get_cell_autotile_coord(int p_x, int p_y) const { } void TileMap::_recreate_quadrants() { - _clear_quadrants(); for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) { - PosKey qk = PosKey(E->key().x, E->key().y).to_quadrant(_get_quadrant_size()); Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk); @@ -1162,50 +1097,41 @@ void TileMap::_recreate_quadrants() { } void TileMap::_clear_quadrants() { - while (quadrant_map.size()) { _erase_quadrant(quadrant_map.front()); } } void TileMap::set_material(const Ref<Material> &p_material) { - CanvasItem::set_material(p_material); _update_all_items_material_state(); } void TileMap::set_use_parent_material(bool p_use_parent_material) { - CanvasItem::set_use_parent_material(p_use_parent_material); _update_all_items_material_state(); } void TileMap::_update_all_items_material_state() { - for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); for (List<RID>::Element *F = q.canvas_items.front(); F; F = F->next()) { - _update_item_material_state(F->get()); } } } void TileMap::_update_item_material_state(const RID &p_canvas_item) { - RS::get_singleton()->canvas_item_set_use_parent_material(p_canvas_item, get_use_parent_material() || get_material().is_valid()); } void TileMap::clear() { - _clear_quadrants(); tile_map.clear(); used_size_cache_dirty = true; } void TileMap::_set_tile_data(const Vector<int> &p_data) { - ERR_FAIL_COND(format > FORMAT_2); int c = p_data.size(); @@ -1215,7 +1141,6 @@ void TileMap::_set_tile_data(const Vector<int> &p_data) { clear(); for (int i = 0; i < c; i += offset) { - const uint8_t *ptr = (const uint8_t *)&r[i]; uint8_t local[12]; for (int j = 0; j < ((format == FORMAT_2) ? 12 : 8); j++) @@ -1253,7 +1178,6 @@ void TileMap::_set_tile_data(const Vector<int> &p_data) { } Vector<int> TileMap::_get_tile_data() const { - Vector<int> data; data.resize(tile_map.size() * 3); int *w = data.ptrw(); @@ -1293,11 +1217,9 @@ Rect2 TileMap::_edit_get_rect() const { #endif void TileMap::set_collision_layer(uint32_t p_layer) { - collision_layer = p_layer; if (!use_parent) { for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); PhysicsServer2D::get_singleton()->body_set_collision_layer(q.body, collision_layer); } @@ -1305,11 +1227,9 @@ void TileMap::set_collision_layer(uint32_t p_layer) { } void TileMap::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; if (!use_parent) { for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); PhysicsServer2D::get_singleton()->body_set_collision_mask(q.body, collision_mask); } @@ -1317,7 +1237,6 @@ void TileMap::set_collision_mask(uint32_t p_mask) { } void TileMap::set_collision_layer_bit(int p_bit, bool p_value) { - uint32_t layer = get_collision_layer(); if (p_value) layer |= 1 << p_bit; @@ -1327,7 +1246,6 @@ void TileMap::set_collision_layer_bit(int p_bit, bool p_value) { } void TileMap::set_collision_mask_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_mask(); if (p_value) mask |= 1 << p_bit; @@ -1337,24 +1255,20 @@ void TileMap::set_collision_mask_bit(int p_bit, bool p_value) { } bool TileMap::get_collision_use_kinematic() const { - return use_kinematic; } void TileMap::set_collision_use_kinematic(bool p_use_kinematic) { - _clear_quadrants(); use_kinematic = p_use_kinematic; _recreate_quadrants(); } bool TileMap::get_collision_use_parent() const { - return use_parent; } void TileMap::set_collision_use_parent(bool p_use_parent) { - if (use_parent == p_use_parent) return; @@ -1375,11 +1289,9 @@ void TileMap::set_collision_use_parent(bool p_use_parent) { } void TileMap::set_collision_friction(float p_friction) { - friction = p_friction; if (!use_parent) { for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); PhysicsServer2D::get_singleton()->body_set_param(q.body, PhysicsServer2D::BODY_PARAM_FRICTION, p_friction); } @@ -1387,48 +1299,39 @@ void TileMap::set_collision_friction(float p_friction) { } float TileMap::get_collision_friction() const { - return friction; } void TileMap::set_collision_bounce(float p_bounce) { - bounce = p_bounce; if (!use_parent) { for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); PhysicsServer2D::get_singleton()->body_set_param(q.body, PhysicsServer2D::BODY_PARAM_BOUNCE, p_bounce); } } } float TileMap::get_collision_bounce() const { - return bounce; } uint32_t TileMap::get_collision_layer() const { - return collision_layer; } uint32_t TileMap::get_collision_mask() const { - return collision_mask; } bool TileMap::get_collision_layer_bit(int p_bit) const { - return get_collision_layer() & (1 << p_bit); } bool TileMap::get_collision_mask_bit(int p_bit) const { - return get_collision_mask() & (1 << p_bit); } void TileMap::set_mode(Mode p_mode) { - _clear_quadrants(); mode = p_mode; _recreate_quadrants(); @@ -1440,7 +1343,6 @@ TileMap::Mode TileMap::get_mode() const { } void TileMap::set_half_offset(HalfOffset p_half_offset) { - _clear_quadrants(); half_offset = p_half_offset; _recreate_quadrants(); @@ -1448,7 +1350,6 @@ void TileMap::set_half_offset(HalfOffset p_half_offset) { } void TileMap::set_tile_origin(TileOrigin p_tile_origin) { - _clear_quadrants(); tile_origin = p_tile_origin; _recreate_quadrants(); @@ -1456,25 +1357,19 @@ void TileMap::set_tile_origin(TileOrigin p_tile_origin) { } TileMap::TileOrigin TileMap::get_tile_origin() const { - return tile_origin; } Vector2 TileMap::get_cell_draw_offset() const { - switch (mode) { - case MODE_SQUARE: { - return Vector2(); } break; case MODE_ISOMETRIC: { - return Vector2(-cell_size.x * 0.5, 0); } break; case MODE_CUSTOM: { - Vector2 min; min.x = MIN(custom_transform[0].x, min.x); min.y = MIN(custom_transform[0].y, min.y); @@ -1492,18 +1387,14 @@ TileMap::HalfOffset TileMap::get_half_offset() const { } Transform2D TileMap::get_cell_transform() const { - switch (mode) { - case MODE_SQUARE: { - Transform2D m; m[0] *= cell_size.x; m[1] *= cell_size.y; return m; } break; case MODE_ISOMETRIC: { - //isometric only makes sense when y is positive in both x and y vectors, otherwise //the drawing of tiles will overlap Transform2D m; @@ -1513,7 +1404,6 @@ Transform2D TileMap::get_cell_transform() const { } break; case MODE_CUSTOM: { - return custom_transform; } break; } @@ -1522,7 +1412,6 @@ Transform2D TileMap::get_cell_transform() const { } void TileMap::set_custom_transform(const Transform2D &p_xform) { - _clear_quadrants(); custom_transform = p_xform; _recreate_quadrants(); @@ -1530,20 +1419,16 @@ void TileMap::set_custom_transform(const Transform2D &p_xform) { } Transform2D TileMap::get_custom_transform() const { - return custom_transform; } Vector2 TileMap::_map_to_world(int p_x, int p_y, bool p_ignore_ofs) const { - Vector2 ret = get_cell_transform().xform(Vector2(p_x, p_y)); if (!p_ignore_ofs) { switch (half_offset) { - case HALF_OFFSET_X: case HALF_OFFSET_NEGATIVE_X: { if (ABS(p_y) & 1) { - ret += get_cell_transform()[0] * (half_offset == HALF_OFFSET_X ? 0.5 : -0.5); } } break; @@ -1562,7 +1447,6 @@ Vector2 TileMap::_map_to_world(int p_x, int p_y, bool p_ignore_ofs) const { } bool TileMap::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == "format") { if (p_value.get_type() == Variant::INT) { format = (DataFormat)(p_value.operator int64_t()); // Set format used for loading @@ -1579,7 +1463,6 @@ bool TileMap::_set(const StringName &p_name, const Variant &p_value) { } bool TileMap::_get(const StringName &p_name, Variant &r_ret) const { - if (p_name == "format") { r_ret = FORMAT_2; // When saving, always save highest format return true; @@ -1591,7 +1474,6 @@ bool TileMap::_get(const StringName &p_name, Variant &r_ret) const { } void TileMap::_get_property_list(List<PropertyInfo> *p_list) const { - PropertyInfo p(Variant::INT, "format", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL); p_list->push_back(p); @@ -1606,16 +1488,13 @@ void TileMap::_validate_property(PropertyInfo &property) const { } Vector2 TileMap::map_to_world(const Vector2 &p_pos, bool p_ignore_ofs) const { - return _map_to_world(p_pos.x, p_pos.y, p_ignore_ofs); } Vector2 TileMap::world_to_map(const Vector2 &p_pos) const { - Vector2 ret = get_cell_transform().affine_inverse().xform(p_pos); switch (half_offset) { - case HALF_OFFSET_X: { if (int(floor(ret.y)) & 1) { ret.x -= 0.5; @@ -1650,7 +1529,6 @@ Vector2 TileMap::world_to_map(const Vector2 &p_pos) const { } void TileMap::set_y_sort_enabled(bool p_enable) { - _clear_quadrants(); use_y_sort = p_enable; RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), use_y_sort); @@ -1659,12 +1537,10 @@ void TileMap::set_y_sort_enabled(bool p_enable) { } bool TileMap::is_y_sort_enabled() const { - return use_y_sort; } void TileMap::set_compatibility_mode(bool p_enable) { - _clear_quadrants(); compatibility_mode = p_enable; _recreate_quadrants(); @@ -1672,12 +1548,10 @@ void TileMap::set_compatibility_mode(bool p_enable) { } bool TileMap::is_compatibility_mode_enabled() const { - return compatibility_mode; } void TileMap::set_centered_textures(bool p_enable) { - _clear_quadrants(); centered_textures = p_enable; _recreate_quadrants(); @@ -1685,17 +1559,14 @@ void TileMap::set_centered_textures(bool p_enable) { } bool TileMap::is_centered_textures_enabled() const { - return centered_textures; } TypedArray<Vector2i> TileMap::get_used_cells() const { - TypedArray<Vector2i> a; a.resize(tile_map.size()); int i = 0; for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) { - Vector2i p(E->key().x, E->key().y); a[i++] = p; } @@ -1704,10 +1575,8 @@ TypedArray<Vector2i> TileMap::get_used_cells() const { } TypedArray<Vector2i> TileMap::get_used_cells_by_index(int p_id) const { - TypedArray<Vector2i> a; for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) { - if (E->value().id == p_id) { Vector2i p(E->key().x, E->key().y); a.push_back(p); @@ -1739,10 +1608,8 @@ Rect2 TileMap::get_used_rect() { // Not const because of cache } void TileMap::set_occluder_light_mask(int p_mask) { - occluder_light_mask = p_mask; for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - for (Map<PosKey, Quadrant::Occluder>::Element *F = E->get().occluder_instances.front(); F; F = F->next()) { RenderingServer::get_singleton()->canvas_light_occluder_set_light_mask(F->get().id, occluder_light_mask); } @@ -1750,15 +1617,12 @@ void TileMap::set_occluder_light_mask(int p_mask) { } int TileMap::get_occluder_light_mask() const { - return occluder_light_mask; } void TileMap::set_light_mask(int p_light_mask) { - CanvasItem::set_light_mask(p_light_mask); for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - for (List<RID>::Element *F = E->get().canvas_items.front(); F; F = F->next()) { RenderingServer::get_singleton()->canvas_item_set_light_mask(F->get(), get_light_mask()); } @@ -1766,7 +1630,6 @@ void TileMap::set_light_mask(int p_light_mask) { } void TileMap::set_clip_uv(bool p_enable) { - if (clip_uv == p_enable) return; @@ -1776,12 +1639,10 @@ void TileMap::set_clip_uv(bool p_enable) { } bool TileMap::get_clip_uv() const { - return clip_uv; } String TileMap::get_configuration_warning() const { - String warning = Node2D::get_configuration_warning(); if (use_parent && !collision_parent) { @@ -1795,7 +1656,6 @@ String TileMap::get_configuration_warning() const { } void TileMap::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_tileset", "tileset"), &TileMap::set_tileset); ClassDB::bind_method(D_METHOD("get_tileset"), &TileMap::get_tileset); @@ -1942,7 +1802,6 @@ void TileMap::_changed_callback(Object *p_changed, const char *p_prop) { } TileMap::TileMap() { - rect_cache_dirty = true; used_size_cache_dirty = true; pending_update = false; @@ -1974,7 +1833,6 @@ TileMap::TileMap() { } TileMap::~TileMap() { - if (tile_set.is_valid()) tile_set->remove_change_receptor(this); diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index 16784571bf..24d4dc09db 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -40,7 +40,6 @@ class CollisionObject2D; class TileMap : public Node2D { - GDCLASS(TileMap, Node2D); public: @@ -82,7 +81,6 @@ private: Navigation2D *navigation; union PosKey { - struct { int16_t x; int16_t y; @@ -112,7 +110,6 @@ private: }; union Cell { - struct { int32_t id : 24; bool flip_h : 1; @@ -130,7 +127,6 @@ private: List<PosKey> dirty_bitmask; struct Quadrant { - Vector2 pos; List<RID> canvas_items; RID body; diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp index 590cc1e6c4..2d8a47ee98 100644 --- a/scene/2d/touch_screen_button.cpp +++ b/scene/2d/touch_screen_button.cpp @@ -36,39 +36,32 @@ #include "scene/main/window.h" # void TouchScreenButton::set_texture(const Ref<Texture2D> &p_texture) { - texture = p_texture; update(); } Ref<Texture2D> TouchScreenButton::get_texture() const { - return texture; } void TouchScreenButton::set_texture_pressed(const Ref<Texture2D> &p_texture_pressed) { - texture_pressed = p_texture_pressed; update(); } Ref<Texture2D> TouchScreenButton::get_texture_pressed() const { - return texture_pressed; } void TouchScreenButton::set_bitmask(const Ref<BitMap> &p_bitmask) { - bitmask = p_bitmask; } Ref<BitMap> TouchScreenButton::get_bitmask() const { - return bitmask; } void TouchScreenButton::set_shape(const Ref<Shape2D> &p_shape) { - if (shape.is_valid()) shape->disconnect("changed", callable_mp((CanvasItem *)this, &CanvasItem::update)); @@ -81,45 +74,36 @@ void TouchScreenButton::set_shape(const Ref<Shape2D> &p_shape) { } Ref<Shape2D> TouchScreenButton::get_shape() const { - return shape; } void TouchScreenButton::set_shape_centered(bool p_shape_centered) { - shape_centered = p_shape_centered; update(); } bool TouchScreenButton::is_shape_visible() const { - return shape_visible; } void TouchScreenButton::set_shape_visible(bool p_shape_visible) { - shape_visible = p_shape_visible; update(); } bool TouchScreenButton::is_shape_centered() const { - return shape_centered; } void TouchScreenButton::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_DRAW: { - if (!is_inside_tree()) return; if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) return; if (finger_pressed != -1) { - if (texture_pressed.is_valid()) draw_texture(texture_pressed, Point2()); else if (texture.is_valid()) @@ -145,7 +129,6 @@ void TouchScreenButton::_notification(int p_what) { } break; case NOTIFICATION_ENTER_TREE: { - if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) return; update(); @@ -177,22 +160,18 @@ void TouchScreenButton::_notification(int p_what) { } bool TouchScreenButton::is_pressed() const { - return finger_pressed != -1; } void TouchScreenButton::set_action(const String &p_action) { - action = p_action; } String TouchScreenButton::get_action() const { - return action; } void TouchScreenButton::_input(const Ref<InputEvent> &p_event) { - if (!get_tree()) return; @@ -204,21 +183,17 @@ void TouchScreenButton::_input(const Ref<InputEvent> &p_event) { const InputEventScreenTouch *st = Object::cast_to<InputEventScreenTouch>(*p_event); if (passby_press) { - const InputEventScreenDrag *sd = Object::cast_to<InputEventScreenDrag>(*p_event); if (st && !st->is_pressed() && finger_pressed == st->get_index()) { - _release(); } if ((st && st->is_pressed()) || sd) { - int index = st ? st->get_index() : sd->get_index(); Point2 coord = st ? st->get_position() : sd->get_position(); if (finger_pressed == -1 || index == finger_pressed) { - if (_is_point_inside(coord)) { if (finger_pressed == -1) { _press(index); @@ -232,11 +207,8 @@ void TouchScreenButton::_input(const Ref<InputEvent> &p_event) { } } else { - if (st) { - if (st->is_pressed()) { - const bool can_press = finger_pressed == -1; if (!can_press) return; //already fingering @@ -268,10 +240,8 @@ bool TouchScreenButton::_is_point_inside(const Point2 &p_point) { } if (bitmask.is_valid()) { - check_rect = false; if (!touched && Rect2(Point2(), bitmask->get_size()).has_point(coord)) { - if (bitmask->get_bit(coord)) touched = true; } @@ -286,11 +256,9 @@ bool TouchScreenButton::_is_point_inside(const Point2 &p_point) { } void TouchScreenButton::_press(int p_finger_pressed) { - finger_pressed = p_finger_pressed; if (action != StringName()) { - Input::get_singleton()->action_press(action); Ref<InputEventAction> iea; iea.instance(); @@ -304,14 +272,11 @@ void TouchScreenButton::_press(int p_finger_pressed) { } void TouchScreenButton::_release(bool p_exiting_tree) { - finger_pressed = -1; if (action != StringName()) { - Input::get_singleton()->action_release(action); if (!p_exiting_tree) { - Ref<InputEventAction> iea; iea.instance(); iea->set_action(action); @@ -352,22 +317,18 @@ void TouchScreenButton::set_visibility_mode(VisibilityMode p_mode) { } TouchScreenButton::VisibilityMode TouchScreenButton::get_visibility_mode() const { - return visibility; } void TouchScreenButton::set_passby_press(bool p_enable) { - passby_press = p_enable; } bool TouchScreenButton::is_passby_press_enabled() const { - return passby_press; } void TouchScreenButton::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_texture", "texture"), &TouchScreenButton::set_texture); ClassDB::bind_method(D_METHOD("get_texture"), &TouchScreenButton::get_texture); @@ -417,7 +378,6 @@ void TouchScreenButton::_bind_methods() { } TouchScreenButton::TouchScreenButton() { - finger_pressed = -1; passby_press = false; visibility = VISIBILITY_ALWAYS; diff --git a/scene/2d/touch_screen_button.h b/scene/2d/touch_screen_button.h index 42e93f7048..d9c7ef7034 100644 --- a/scene/2d/touch_screen_button.h +++ b/scene/2d/touch_screen_button.h @@ -37,7 +37,6 @@ #include "scene/resources/texture.h" class TouchScreenButton : public Node2D { - GDCLASS(TouchScreenButton, Node2D); public: diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index 780d08693d..6b03d86e8b 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -49,7 +49,6 @@ bool VisibilityNotifier2D::_edit_use_rect() const { #endif void VisibilityNotifier2D::_enter_viewport(Viewport *p_viewport) { - ERR_FAIL_COND(viewports.has(p_viewport)); viewports.insert(p_viewport); @@ -65,7 +64,6 @@ void VisibilityNotifier2D::_enter_viewport(Viewport *p_viewport) { } void VisibilityNotifier2D::_exit_viewport(Viewport *p_viewport) { - ERR_FAIL_COND(!viewports.has(p_viewport)); viewports.erase(p_viewport); @@ -81,7 +79,6 @@ void VisibilityNotifier2D::_exit_viewport(Viewport *p_viewport) { } void VisibilityNotifier2D::set_rect(const Rect2 &p_rect) { - rect = p_rect; if (is_inside_tree()) { get_world_2d()->_update_notifier(this, get_global_transform().xform(rect)); @@ -95,44 +92,35 @@ void VisibilityNotifier2D::set_rect(const Rect2 &p_rect) { } Rect2 VisibilityNotifier2D::get_rect() const { - return rect; } void VisibilityNotifier2D::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_ENTER_TREE: { - //get_world_2d()-> get_world_2d()->_register_notifier(this, get_global_transform().xform(rect)); } break; case NOTIFICATION_TRANSFORM_CHANGED: { - //get_world_2d()-> get_world_2d()->_update_notifier(this, get_global_transform().xform(rect)); } break; case NOTIFICATION_DRAW: { - if (Engine::get_singleton()->is_editor_hint()) { - draw_rect(rect, Color(1, 0.5, 1, 0.2)); } } break; case NOTIFICATION_EXIT_TREE: { - get_world_2d()->_remove_notifier(this); } break; } } bool VisibilityNotifier2D::is_on_screen() const { - return viewports.size() > 0; } void VisibilityNotifier2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_rect", "rect"), &VisibilityNotifier2D::set_rect); ClassDB::bind_method(D_METHOD("get_rect"), &VisibilityNotifier2D::get_rect); ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibilityNotifier2D::is_on_screen); @@ -146,7 +134,6 @@ void VisibilityNotifier2D::_bind_methods() { } VisibilityNotifier2D::VisibilityNotifier2D() { - rect = Rect2(-10, -10, 20, 20); set_notify_transform(true); } @@ -154,9 +141,7 @@ VisibilityNotifier2D::VisibilityNotifier2D() { ////////////////////////////////////// void VisibilityEnabler2D::_screen_enter() { - for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) { - _change_node_state(E->key(), true); } @@ -169,9 +154,7 @@ void VisibilityEnabler2D::_screen_enter() { } void VisibilityEnabler2D::_screen_exit() { - for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) { - _change_node_state(E->key(), false); } @@ -184,14 +167,12 @@ void VisibilityEnabler2D::_screen_exit() { } void VisibilityEnabler2D::_find_nodes(Node *p_node) { - bool add = false; Variant meta; { RigidBody2D *rb2d = Object::cast_to<RigidBody2D>(p_node); if (rb2d && ((rb2d->get_mode() == RigidBody2D::MODE_CHARACTER || rb2d->get_mode() == RigidBody2D::MODE_RIGID))) { - add = true; meta = rb2d->get_mode(); } @@ -219,7 +200,6 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) { } if (add) { - p_node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler2D::_node_removed), varray(p_node), CONNECT_ONESHOT); nodes[p_node] = meta; _change_node_state(p_node, false); @@ -235,9 +215,7 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) { } void VisibilityEnabler2D::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - if (Engine::get_singleton()->is_editor_hint()) return; @@ -264,12 +242,10 @@ void VisibilityEnabler2D::_notification(int p_what) { } if (p_what == NOTIFICATION_EXIT_TREE) { - if (Engine::get_singleton()->is_editor_hint()) return; for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) { - if (!visible) _change_node_state(E->key(), true); E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler2D::_node_removed)); @@ -280,13 +256,11 @@ void VisibilityEnabler2D::_notification(int p_what) { } void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { - ERR_FAIL_COND(!nodes.has(p_node)); if (enabler[ENABLER_FREEZE_BODIES]) { RigidBody2D *rb = Object::cast_to<RigidBody2D>(p_node); if (rb) { - rb->set_sleeping(!p_enabled); } } @@ -295,7 +269,6 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node); if (ap) { - ap->set_active(p_enabled); } } @@ -304,7 +277,6 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { AnimatedSprite2D *as = Object::cast_to<AnimatedSprite2D>(p_node); if (as) { - if (p_enabled) as->play(); else @@ -316,14 +288,12 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { GPUParticles2D *ps = Object::cast_to<GPUParticles2D>(p_node); if (ps) { - ps->set_emitting(p_enabled); } } } void VisibilityEnabler2D::_node_removed(Node *p_node) { - if (!visible) _change_node_state(p_node, true); nodes.erase(p_node); @@ -339,7 +309,6 @@ String VisibilityEnabler2D::get_configuration_warning() const { } void VisibilityEnabler2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_enabler", "enabler", "enabled"), &VisibilityEnabler2D::set_enabler); ClassDB::bind_method(D_METHOD("is_enabler_enabled", "enabler"), &VisibilityEnabler2D::is_enabler_enabled); ClassDB::bind_method(D_METHOD("_node_removed"), &VisibilityEnabler2D::_node_removed); @@ -361,18 +330,15 @@ void VisibilityEnabler2D::_bind_methods() { } void VisibilityEnabler2D::set_enabler(Enabler p_enabler, bool p_enable) { - ERR_FAIL_INDEX(p_enabler, ENABLER_MAX); enabler[p_enabler] = p_enable; } bool VisibilityEnabler2D::is_enabler_enabled(Enabler p_enabler) const { - ERR_FAIL_INDEX_V(p_enabler, ENABLER_MAX, false); return enabler[p_enabler]; } VisibilityEnabler2D::VisibilityEnabler2D() { - for (int i = 0; i < ENABLER_MAX; i++) enabler[i] = true; enabler[ENABLER_PARENT_PROCESS] = false; diff --git a/scene/2d/visibility_notifier_2d.h b/scene/2d/visibility_notifier_2d.h index a3b79d29e9..fb6e48f5e8 100644 --- a/scene/2d/visibility_notifier_2d.h +++ b/scene/2d/visibility_notifier_2d.h @@ -35,7 +35,6 @@ class Viewport; class VisibilityNotifier2D : public Node2D { - GDCLASS(VisibilityNotifier2D, Node2D); Set<Viewport *> viewports; @@ -69,7 +68,6 @@ public: }; class VisibilityEnabler2D : public VisibilityNotifier2D { - GDCLASS(VisibilityEnabler2D, VisibilityNotifier2D); public: diff --git a/scene/2d/y_sort.cpp b/scene/2d/y_sort.cpp index 15d97eeaa0..7c2b41db70 100644 --- a/scene/2d/y_sort.cpp +++ b/scene/2d/y_sort.cpp @@ -31,18 +31,15 @@ #include "y_sort.h" void YSort::set_sort_enabled(bool p_enabled) { - sort_enabled = p_enabled; RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), sort_enabled); } bool YSort::is_sort_enabled() const { - return sort_enabled; } void YSort::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_sort_enabled", "enabled"), &YSort::set_sort_enabled); ClassDB::bind_method(D_METHOD("is_sort_enabled"), &YSort::is_sort_enabled); @@ -51,7 +48,6 @@ void YSort::_bind_methods() { } YSort::YSort() { - sort_enabled = true; RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), true); } |