diff options
Diffstat (limited to 'scene/2d')
47 files changed, 754 insertions, 2772 deletions
diff --git a/scene/2d/SCsub b/scene/2d/SCsub index b01e2fd54d..fc61250247 100644 --- a/scene/2d/SCsub +++ b/scene/2d/SCsub @@ -1,5 +1,5 @@ #!/usr/bin/env python -Import('env') +Import("env") env.add_source_files(env.scene_sources, "*.cpp") diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite_2d.cpp index f3f7ba9ddd..fc34f967ce 100644 --- a/scene/2d/animated_sprite.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* animated_sprite.cpp */ +/* animated_sprite_2d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "animated_sprite.h" +#include "animated_sprite_2d.h" #include "core/os/os.h" #include "scene/scene_string_names.h" @@ -37,35 +37,35 @@ #define SPECULAR_SUFFIX "_specular" #ifdef TOOLS_ENABLED -Dictionary AnimatedSprite::_edit_get_state() const { +Dictionary AnimatedSprite2D::_edit_get_state() const { Dictionary state = Node2D::_edit_get_state(); state["offset"] = offset; return state; } -void AnimatedSprite::_edit_set_state(const Dictionary &p_state) { +void AnimatedSprite2D::_edit_set_state(const Dictionary &p_state) { Node2D::_edit_set_state(p_state); set_offset(p_state["offset"]); } -void AnimatedSprite::_edit_set_pivot(const Point2 &p_pivot) { +void AnimatedSprite2D::_edit_set_pivot(const Point2 &p_pivot) { set_offset(get_offset() - p_pivot); set_position(get_transform().xform(p_pivot)); } -Point2 AnimatedSprite::_edit_get_pivot() const { +Point2 AnimatedSprite2D::_edit_get_pivot() const { return Vector2(); } -bool AnimatedSprite::_edit_use_pivot() const { +bool AnimatedSprite2D::_edit_use_pivot() const { return true; } -Rect2 AnimatedSprite::_edit_get_rect() const { +Rect2 AnimatedSprite2D::_edit_get_rect() const { return _get_rect(); } -bool AnimatedSprite::_edit_use_rect() const { +bool AnimatedSprite2D::_edit_use_rect() const { if (!frames.is_valid() || !frames->has_animation(animation) || frame < 0 || frame >= frames->get_frame_count(animation)) { return false; } @@ -76,11 +76,11 @@ bool AnimatedSprite::_edit_use_rect() const { } #endif -Rect2 AnimatedSprite::get_anchorable_rect() const { +Rect2 AnimatedSprite2D::get_anchorable_rect() const { return _get_rect(); } -Rect2 AnimatedSprite::_get_rect() const { +Rect2 AnimatedSprite2D::_get_rect() const { if (!frames.is_valid() || !frames->has_animation(animation) || frame < 0 || frame >= frames->get_frame_count(animation)) { return Rect2(); } @@ -328,7 +328,7 @@ SpriteFrames::SpriteFrames() { add_animation(SceneStringNames::get_singleton()->_default); } -void AnimatedSprite::_validate_property(PropertyInfo &property) const { +void AnimatedSprite2D::_validate_property(PropertyInfo &property) const { if (!frames.is_valid()) return; @@ -370,7 +370,7 @@ void AnimatedSprite::_validate_property(PropertyInfo &property) const { } } -void AnimatedSprite::_notification(int p_what) { +void AnimatedSprite2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_INTERNAL_PROCESS: { @@ -472,13 +472,13 @@ void AnimatedSprite::_notification(int p_what) { } } -void AnimatedSprite::set_sprite_frames(const Ref<SpriteFrames> &p_frames) { +void AnimatedSprite2D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) { if (frames.is_valid()) - frames->disconnect("changed", callable_mp(this, &AnimatedSprite::_res_changed)); + frames->disconnect("changed", callable_mp(this, &AnimatedSprite2D::_res_changed)); frames = p_frames; if (frames.is_valid()) - frames->connect("changed", callable_mp(this, &AnimatedSprite::_res_changed)); + frames->connect("changed", callable_mp(this, &AnimatedSprite2D::_res_changed)); if (!frames.is_valid()) { frame = 0; @@ -492,12 +492,12 @@ void AnimatedSprite::set_sprite_frames(const Ref<SpriteFrames> &p_frames) { update_configuration_warning(); } -Ref<SpriteFrames> AnimatedSprite::get_sprite_frames() const { +Ref<SpriteFrames> AnimatedSprite2D::get_sprite_frames() const { return frames; } -void AnimatedSprite::set_frame(int p_frame) { +void AnimatedSprite2D::set_frame(int p_frame) { if (!frames.is_valid()) { return; @@ -521,12 +521,12 @@ void AnimatedSprite::set_frame(int p_frame) { _change_notify("frame"); emit_signal(SceneStringNames::get_singleton()->frame_changed); } -int AnimatedSprite::get_frame() const { +int AnimatedSprite2D::get_frame() const { return frame; } -void AnimatedSprite::set_speed_scale(float p_speed_scale) { +void AnimatedSprite2D::set_speed_scale(float p_speed_scale) { float elapsed = _get_frame_duration() - timeout; @@ -537,56 +537,56 @@ void AnimatedSprite::set_speed_scale(float p_speed_scale) { timeout -= elapsed; } -float AnimatedSprite::get_speed_scale() const { +float AnimatedSprite2D::get_speed_scale() const { return speed_scale; } -void AnimatedSprite::set_centered(bool p_center) { +void AnimatedSprite2D::set_centered(bool p_center) { centered = p_center; update(); item_rect_changed(); } -bool AnimatedSprite::is_centered() const { +bool AnimatedSprite2D::is_centered() const { return centered; } -void AnimatedSprite::set_offset(const Point2 &p_offset) { +void AnimatedSprite2D::set_offset(const Point2 &p_offset) { offset = p_offset; update(); item_rect_changed(); _change_notify("offset"); } -Point2 AnimatedSprite::get_offset() const { +Point2 AnimatedSprite2D::get_offset() const { return offset; } -void AnimatedSprite::set_flip_h(bool p_flip) { +void AnimatedSprite2D::set_flip_h(bool p_flip) { hflip = p_flip; update(); } -bool AnimatedSprite::is_flipped_h() const { +bool AnimatedSprite2D::is_flipped_h() const { return hflip; } -void AnimatedSprite::set_flip_v(bool p_flip) { +void AnimatedSprite2D::set_flip_v(bool p_flip) { vflip = p_flip; update(); } -bool AnimatedSprite::is_flipped_v() const { +bool AnimatedSprite2D::is_flipped_v() const { return vflip; } -void AnimatedSprite::_res_changed() { +void AnimatedSprite2D::_res_changed() { set_frame(frame); _change_notify("frame"); @@ -594,7 +594,7 @@ void AnimatedSprite::_res_changed() { update(); } -void AnimatedSprite::_set_playing(bool p_playing) { +void AnimatedSprite2D::_set_playing(bool p_playing) { if (playing == p_playing) return; @@ -603,12 +603,12 @@ void AnimatedSprite::_set_playing(bool p_playing) { set_process_internal(playing); } -bool AnimatedSprite::_is_playing() const { +bool AnimatedSprite2D::_is_playing() const { return playing; } -void AnimatedSprite::play(const StringName &p_animation, const bool p_backwards) { +void AnimatedSprite2D::play(const StringName &p_animation, const bool p_backwards) { backwards = p_backwards; @@ -621,17 +621,17 @@ void AnimatedSprite::play(const StringName &p_animation, const bool p_backwards) _set_playing(true); } -void AnimatedSprite::stop() { +void AnimatedSprite2D::stop() { _set_playing(false); } -bool AnimatedSprite::is_playing() const { +bool AnimatedSprite2D::is_playing() const { return playing; } -float AnimatedSprite::_get_frame_duration() { +float AnimatedSprite2D::_get_frame_duration() { if (frames.is_valid() && frames->has_animation(animation)) { float speed = frames->get_animation_speed(animation) * speed_scale; if (speed > 0) { @@ -641,7 +641,7 @@ float AnimatedSprite::_get_frame_duration() { return 0.0; } -void AnimatedSprite::_reset_timeout() { +void AnimatedSprite2D::_reset_timeout() { if (!playing) return; @@ -650,9 +650,9 @@ void AnimatedSprite::_reset_timeout() { is_over = false; } -void AnimatedSprite::set_animation(const StringName &p_animation) { +void AnimatedSprite2D::set_animation(const StringName &p_animation) { - ERR_FAIL_COND_MSG(frames == NULL, vformat("There is no animation with name '%s'.", 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)); if (animation == p_animation) @@ -664,12 +664,12 @@ void AnimatedSprite::set_animation(const StringName &p_animation) { _change_notify(); update(); } -StringName AnimatedSprite::get_animation() const { +StringName AnimatedSprite2D::get_animation() const { return animation; } -String AnimatedSprite::get_configuration_warning() const { +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."); @@ -678,62 +678,62 @@ String AnimatedSprite::get_configuration_warning() const { return String(); } -void AnimatedSprite::set_specular_color(const Color &p_color) { +void AnimatedSprite2D::set_specular_color(const Color &p_color) { specular_color = p_color; update(); } -Color AnimatedSprite::get_specular_color() const { +Color AnimatedSprite2D::get_specular_color() const { return specular_color; } -void AnimatedSprite::set_shininess(float p_shininess) { +void AnimatedSprite2D::set_shininess(float p_shininess) { shininess = CLAMP(p_shininess, 0.0, 1.0); update(); } -float AnimatedSprite::get_shininess() const { +float AnimatedSprite2D::get_shininess() const { return shininess; } -void AnimatedSprite::_bind_methods() { +void AnimatedSprite2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_sprite_frames", "sprite_frames"), &AnimatedSprite::set_sprite_frames); - ClassDB::bind_method(D_METHOD("get_sprite_frames"), &AnimatedSprite::get_sprite_frames); + 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); - ClassDB::bind_method(D_METHOD("set_animation", "animation"), &AnimatedSprite::set_animation); - ClassDB::bind_method(D_METHOD("get_animation"), &AnimatedSprite::get_animation); + ClassDB::bind_method(D_METHOD("set_animation", "animation"), &AnimatedSprite2D::set_animation); + ClassDB::bind_method(D_METHOD("get_animation"), &AnimatedSprite2D::get_animation); - ClassDB::bind_method(D_METHOD("_set_playing", "playing"), &AnimatedSprite::_set_playing); - ClassDB::bind_method(D_METHOD("_is_playing"), &AnimatedSprite::_is_playing); + ClassDB::bind_method(D_METHOD("_set_playing", "playing"), &AnimatedSprite2D::_set_playing); + ClassDB::bind_method(D_METHOD("_is_playing"), &AnimatedSprite2D::_is_playing); - ClassDB::bind_method(D_METHOD("play", "anim", "backwards"), &AnimatedSprite::play, DEFVAL(StringName()), DEFVAL(false)); - ClassDB::bind_method(D_METHOD("stop"), &AnimatedSprite::stop); - ClassDB::bind_method(D_METHOD("is_playing"), &AnimatedSprite::is_playing); + ClassDB::bind_method(D_METHOD("play", "anim", "backwards"), &AnimatedSprite2D::play, DEFVAL(StringName()), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("stop"), &AnimatedSprite2D::stop); + ClassDB::bind_method(D_METHOD("is_playing"), &AnimatedSprite2D::is_playing); - ClassDB::bind_method(D_METHOD("set_centered", "centered"), &AnimatedSprite::set_centered); - ClassDB::bind_method(D_METHOD("is_centered"), &AnimatedSprite::is_centered); + ClassDB::bind_method(D_METHOD("set_centered", "centered"), &AnimatedSprite2D::set_centered); + ClassDB::bind_method(D_METHOD("is_centered"), &AnimatedSprite2D::is_centered); - ClassDB::bind_method(D_METHOD("set_offset", "offset"), &AnimatedSprite::set_offset); - ClassDB::bind_method(D_METHOD("get_offset"), &AnimatedSprite::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "offset"), &AnimatedSprite2D::set_offset); + ClassDB::bind_method(D_METHOD("get_offset"), &AnimatedSprite2D::get_offset); - ClassDB::bind_method(D_METHOD("set_flip_h", "flip_h"), &AnimatedSprite::set_flip_h); - ClassDB::bind_method(D_METHOD("is_flipped_h"), &AnimatedSprite::is_flipped_h); + ClassDB::bind_method(D_METHOD("set_flip_h", "flip_h"), &AnimatedSprite2D::set_flip_h); + ClassDB::bind_method(D_METHOD("is_flipped_h"), &AnimatedSprite2D::is_flipped_h); - ClassDB::bind_method(D_METHOD("set_flip_v", "flip_v"), &AnimatedSprite::set_flip_v); - ClassDB::bind_method(D_METHOD("is_flipped_v"), &AnimatedSprite::is_flipped_v); + ClassDB::bind_method(D_METHOD("set_flip_v", "flip_v"), &AnimatedSprite2D::set_flip_v); + ClassDB::bind_method(D_METHOD("is_flipped_v"), &AnimatedSprite2D::is_flipped_v); - ClassDB::bind_method(D_METHOD("set_frame", "frame"), &AnimatedSprite::set_frame); - ClassDB::bind_method(D_METHOD("get_frame"), &AnimatedSprite::get_frame); + ClassDB::bind_method(D_METHOD("set_frame", "frame"), &AnimatedSprite2D::set_frame); + ClassDB::bind_method(D_METHOD("get_frame"), &AnimatedSprite2D::get_frame); - ClassDB::bind_method(D_METHOD("set_speed_scale", "speed_scale"), &AnimatedSprite::set_speed_scale); - ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimatedSprite::get_speed_scale); + ClassDB::bind_method(D_METHOD("set_speed_scale", "speed_scale"), &AnimatedSprite2D::set_speed_scale); + ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimatedSprite2D::get_speed_scale); - ClassDB::bind_method(D_METHOD("set_specular_color", "color"), &AnimatedSprite::set_specular_color); - ClassDB::bind_method(D_METHOD("get_specular_color"), &AnimatedSprite::get_specular_color); + ClassDB::bind_method(D_METHOD("set_specular_color", "color"), &AnimatedSprite2D::set_specular_color); + ClassDB::bind_method(D_METHOD("get_specular_color"), &AnimatedSprite2D::get_specular_color); - ClassDB::bind_method(D_METHOD("set_shininess", "shininess"), &AnimatedSprite::set_shininess); - ClassDB::bind_method(D_METHOD("get_shininess"), &AnimatedSprite::get_shininess); + ClassDB::bind_method(D_METHOD("set_shininess", "shininess"), &AnimatedSprite2D::set_shininess); + ClassDB::bind_method(D_METHOD("get_shininess"), &AnimatedSprite2D::get_shininess); ADD_SIGNAL(MethodInfo("frame_changed")); ADD_SIGNAL(MethodInfo("animation_finished")); @@ -754,7 +754,7 @@ void AnimatedSprite::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_v"), "set_flip_v", "is_flipped_v"); } -AnimatedSprite::AnimatedSprite() { +AnimatedSprite2D::AnimatedSprite2D() { centered = true; hflip = false; diff --git a/scene/2d/animated_sprite.h b/scene/2d/animated_sprite_2d.h index 37d093e3d8..726ecefd32 100644 --- a/scene/2d/animated_sprite.h +++ b/scene/2d/animated_sprite_2d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* animated_sprite.h */ +/* animated_sprite_2d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef ANIMATED_SPRITE_H -#define ANIMATED_SPRITE_H +#ifndef ANIMATED_SPRITE_2D_H +#define ANIMATED_SPRITE_2D_H #include "scene/2d/node_2d.h" #include "scene/resources/texture.h" @@ -42,7 +42,7 @@ class SpriteFrames : public Resource { float speed; bool loop; - Vector<Ref<Texture2D> > frames; + Vector<Ref<Texture2D>> frames; Anim() { loop = true; @@ -140,9 +140,9 @@ public: SpriteFrames(); }; -class AnimatedSprite : public Node2D { +class AnimatedSprite2D : public Node2D { - GDCLASS(AnimatedSprite, Node2D); + GDCLASS(AnimatedSprite2D, Node2D); Ref<SpriteFrames> frames; bool playing; @@ -225,7 +225,7 @@ public: float get_shininess() const; virtual String get_configuration_warning() const; - AnimatedSprite(); + AnimatedSprite2D(); }; #endif // ANIMATED_SPRITE_H diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index b99c4c88bf..c46b6eeb5c 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -32,12 +32,12 @@ #include "scene/scene_string_names.h" #include "servers/audio_server.h" -#include "servers/physics_2d_server.h" +#include "servers/physics_server_2d.h" void Area2D::set_space_override_mode(SpaceOverride p_mode) { space_override = p_mode; - Physics2DServer::get_singleton()->area_set_space_override_mode(get_rid(), Physics2DServer::AreaSpaceOverrideMode(p_mode)); + PhysicsServer2D::get_singleton()->area_set_space_override_mode(get_rid(), PhysicsServer2D::AreaSpaceOverrideMode(p_mode)); } Area2D::SpaceOverride Area2D::get_space_override_mode() const { @@ -47,7 +47,7 @@ Area2D::SpaceOverride Area2D::get_space_override_mode() const { void Area2D::set_gravity_is_point(bool p_enabled) { gravity_is_point = p_enabled; - Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_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 { @@ -57,7 +57,7 @@ bool Area2D::is_gravity_a_point() const { void Area2D::set_gravity_distance_scale(real_t p_scale) { gravity_distance_scale = p_scale; - Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale); + PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale); } real_t Area2D::get_gravity_distance_scale() const { @@ -67,7 +67,7 @@ real_t Area2D::get_gravity_distance_scale() const { void Area2D::set_gravity_vector(const Vector2 &p_vec) { gravity_vec = p_vec; - Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_GRAVITY_VECTOR, p_vec); + PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_VECTOR, p_vec); } Vector2 Area2D::get_gravity_vector() const { @@ -77,7 +77,7 @@ Vector2 Area2D::get_gravity_vector() const { void Area2D::set_gravity(real_t p_gravity) { gravity = p_gravity; - Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_GRAVITY, p_gravity); + PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY, p_gravity); } real_t Area2D::get_gravity() const { @@ -87,7 +87,7 @@ real_t Area2D::get_gravity() const { void Area2D::set_linear_damp(real_t p_linear_damp) { linear_damp = p_linear_damp; - Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_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 { @@ -97,7 +97,7 @@ real_t Area2D::get_linear_damp() const { void Area2D::set_angular_damp(real_t p_angular_damp) { angular_damp = p_angular_damp; - Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_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 { @@ -108,7 +108,7 @@ real_t Area2D::get_angular_damp() const { void Area2D::set_priority(real_t p_priority) { priority = p_priority; - Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_PRIORITY, p_priority); + PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_PRIORITY, p_priority); } real_t Area2D::get_priority() const { @@ -151,7 +151,7 @@ void Area2D::_body_exit_tree(ObjectID p_id) { 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 == Physics2DServer::AREA_BODY_ADDED; + bool body_in = p_status == PhysicsServer2D::AREA_BODY_ADDED; ObjectID objid = p_instance; Object *obj = ObjectDB::get_instance(objid); @@ -254,7 +254,7 @@ void Area2D::_area_exit_tree(ObjectID p_id) { 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 == Physics2DServer::AREA_BODY_ADDED; + bool area_in = p_status == PhysicsServer2D::AREA_BODY_ADDED; ObjectID objid = p_instance; Object *obj = ObjectDB::get_instance(objid); @@ -403,12 +403,12 @@ void Area2D::set_monitoring(bool p_enable) { if (monitoring) { - Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_body_inout); - Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_area_inout); + 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); } else { - Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(), NULL, StringName()); - Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(), NULL, StringName()); + PhysicsServer2D::get_singleton()->area_set_monitor_callback(get_rid(), nullptr, StringName()); + PhysicsServer2D::get_singleton()->area_set_area_monitor_callback(get_rid(), nullptr, StringName()); _clear_monitoring(); } } @@ -420,14 +420,14 @@ bool Area2D::is_monitoring() const { void Area2D::set_monitorable(bool p_enable) { - ERR_FAIL_COND_MSG(locked || (is_inside_tree() && Physics2DServer::get_singleton()->is_flushing_queries()), "Function blocked during in/out signal. Use set_deferred(\"monitorable\", true/false)."); + 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) return; monitorable = p_enable; - Physics2DServer::get_singleton()->area_set_monitorable(get_rid(), monitorable); + PhysicsServer2D::get_singleton()->area_set_monitorable(get_rid(), monitorable); } bool Area2D::is_monitorable() const { @@ -492,7 +492,7 @@ bool Area2D::overlaps_body(Node *p_body) const { void Area2D::set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; - Physics2DServer::get_singleton()->area_set_collision_mask(get_rid(), p_mask); + PhysicsServer2D::get_singleton()->area_set_collision_mask(get_rid(), p_mask); } uint32_t Area2D::get_collision_mask() const { @@ -503,7 +503,7 @@ uint32_t Area2D::get_collision_mask() const { void Area2D::set_collision_layer(uint32_t p_layer) { collision_layer = p_layer; - Physics2DServer::get_singleton()->area_set_collision_layer(get_rid(), p_layer); + PhysicsServer2D::get_singleton()->area_set_collision_layer(get_rid(), p_layer); } uint32_t Area2D::get_collision_layer() const { @@ -676,7 +676,7 @@ void Area2D::_bind_methods() { } Area2D::Area2D() : - CollisionObject2D(Physics2DServer::get_singleton()->area_create(), true) { + CollisionObject2D(PhysicsServer2D::get_singleton()->area_create(), true) { space_override = SPACE_OVERRIDE_DISABLED; set_gravity(98); diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index aa4ed233fb..55d111439a 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -32,7 +32,7 @@ #include "core/engine.h" #include "scene/2d/area_2d.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" void AudioStreamPlayer2D::_mix_audio() { @@ -87,7 +87,7 @@ void AudioStreamPlayer2D::_mix_audio() { AudioFrame target_volume = stream_paused_fade_out ? AudioFrame(0.f, 0.f) : current.vol; AudioFrame vol_prev = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : prev_outputs[i].vol; AudioFrame vol_inc = (target_volume - vol_prev) / float(buffer_size); - AudioFrame vol = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : current.vol; + AudioFrame vol = vol_prev; int cc = AudioServer::get_singleton()->get_channel_count(); @@ -187,9 +187,9 @@ void AudioStreamPlayer2D::_notification(int p_what) { //check if any area is diverting sound into a bus - Physics2DDirectSpaceState *space_state = Physics2DServer::get_singleton()->space_get_direct_state(world_2d->get_space()); + PhysicsDirectSpaceState2D *space_state = PhysicsServer2D::get_singleton()->space_get_direct_state(world_2d->get_space()); - Physics2DDirectSpaceState::ShapeResult sr[MAX_INTERSECT_AREAS]; + PhysicsDirectSpaceState2D::ShapeResult sr[MAX_INTERSECT_AREAS]; int areas = space_state->intersect_point(global_pos, sr, MAX_INTERSECT_AREAS, Set<RID>(), area_mask, false, true); diff --git a/scene/2d/back_buffer_copy.cpp b/scene/2d/back_buffer_copy.cpp index faeb6b7169..4c952b7ca6 100644 --- a/scene/2d/back_buffer_copy.cpp +++ b/scene/2d/back_buffer_copy.cpp @@ -36,15 +36,15 @@ void BackBufferCopy::_update_copy_mode() { case COPY_MODE_DISABLED: { - VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), false, Rect2()); + RS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), false, Rect2()); } break; case COPY_MODE_RECT: { - VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, rect); + RS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, rect); } break; case COPY_MODE_VIEWPORT: { - VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, Rect2()); + RS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, Rect2()); } break; } diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index a8860c3d81..d8af14a3fb 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -33,7 +33,7 @@ #include "core/engine.h" #include "core/math/math_funcs.h" #include "scene/scene_string_names.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" void Camera2D::_update_scroll() { @@ -264,7 +264,7 @@ void Camera2D::_notification(int p_what) { } remove_from_group(group_name); remove_from_group(canvas_group_name); - viewport = NULL; + viewport = nullptr; } break; case NOTIFICATION_DRAW: { @@ -433,7 +433,7 @@ void Camera2D::clear_current() { current = false; if (is_inside_tree()) { - get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, group_name, "_make_current", (Object *)(NULL)); + get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, group_name, "_make_current", (Object *)nullptr); } } @@ -794,7 +794,7 @@ Camera2D::Camera2D() { first = true; smoothing_enabled = false; limit_smoothing_enabled = false; - custom_viewport = NULL; + custom_viewport = nullptr; process_mode = CAMERA2D_PROCESS_IDLE; diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index 04b5260444..7a106ef79a 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -32,7 +32,7 @@ #define CAMERA_2D_H #include "scene/2d/node_2d.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" class Camera2D : public Node2D { diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp deleted file mode 100644 index ef7aa9ba01..0000000000 --- a/scene/2d/canvas_item.cpp +++ /dev/null @@ -1,1439 +0,0 @@ -/*************************************************************************/ -/* canvas_item.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "canvas_item.h" -#include "core/message_queue.h" -#include "core/method_bind_ext.gen.inc" -#include "core/os/input.h" -#include "scene/main/canvas_layer.h" -#include "scene/main/viewport.h" -#include "scene/resources/font.h" -#include "scene/resources/style_box.h" -#include "scene/resources/texture.h" -#include "scene/scene_string_names.h" -#include "servers/visual/visual_server_raster.h" -#include "servers/visual_server.h" - -Mutex CanvasItemMaterial::material_mutex; -SelfList<CanvasItemMaterial>::List *CanvasItemMaterial::dirty_materials = NULL; -Map<CanvasItemMaterial::MaterialKey, CanvasItemMaterial::ShaderData> CanvasItemMaterial::shader_map; -CanvasItemMaterial::ShaderNames *CanvasItemMaterial::shader_names = NULL; - -void CanvasItemMaterial::init_shaders() { - - dirty_materials = memnew(SelfList<CanvasItemMaterial>::List); - - shader_names = memnew(ShaderNames); - - shader_names->particles_anim_h_frames = "particles_anim_h_frames"; - shader_names->particles_anim_v_frames = "particles_anim_v_frames"; - shader_names->particles_anim_loop = "particles_anim_loop"; -} - -void CanvasItemMaterial::finish_shaders() { - - memdelete(dirty_materials); - memdelete(shader_names); - dirty_materials = NULL; -} - -void CanvasItemMaterial::_update_shader() { - - dirty_materials->remove(&element); - - MaterialKey mk = _compute_key(); - if (mk.key == current_key.key) - return; //no update required in the end - - if (shader_map.has(current_key)) { - shader_map[current_key].users--; - if (shader_map[current_key].users == 0) { - //deallocate shader, as it's no longer in use - VS::get_singleton()->free(shader_map[current_key].shader); - shader_map.erase(current_key); - } - } - - current_key = mk; - - if (shader_map.has(mk)) { - - VS::get_singleton()->material_set_shader(_get_material(), shader_map[mk].shader); - shader_map[mk].users++; - return; - } - - //must create a shader! - - String code = "shader_type canvas_item;\nrender_mode "; - switch (blend_mode) { - case BLEND_MODE_MIX: code += "blend_mix"; break; - case BLEND_MODE_ADD: code += "blend_add"; break; - case BLEND_MODE_SUB: code += "blend_sub"; break; - case BLEND_MODE_MUL: code += "blend_mul"; break; - case BLEND_MODE_PREMULT_ALPHA: code += "blend_premul_alpha"; break; - case BLEND_MODE_DISABLED: code += "blend_disabled"; break; - } - - switch (light_mode) { - case LIGHT_MODE_NORMAL: break; - case LIGHT_MODE_UNSHADED: code += ",unshaded"; break; - case LIGHT_MODE_LIGHT_ONLY: code += ",light_only"; break; - } - - code += ";\n"; - - if (particles_animation) { - - code += "uniform int particles_anim_h_frames;\n"; - code += "uniform int particles_anim_v_frames;\n"; - code += "uniform bool particles_anim_loop;\n"; - - code += "void vertex() {\n"; - - code += "\tfloat h_frames = float(particles_anim_h_frames);\n"; - code += "\tfloat v_frames = float(particles_anim_v_frames);\n"; - - code += "\tVERTEX.xy /= vec2(h_frames, v_frames);\n"; - - code += "\tfloat particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);\n"; - code += "\tfloat particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));\n"; - code += "\tif (!particles_anim_loop) {\n"; - code += "\t\tparticle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0);\n"; - code += "\t} else {\n"; - code += "\t\tparticle_frame = mod(particle_frame, particle_total_frames);\n"; - code += "\t}"; - code += "\tUV /= vec2(h_frames, v_frames);\n"; - code += "\tUV += vec2(mod(particle_frame, h_frames) / h_frames, floor(particle_frame / h_frames) / v_frames);\n"; - code += "}\n"; - } - - ShaderData shader_data; - shader_data.shader = VS::get_singleton()->shader_create(); - shader_data.users = 1; - - VS::get_singleton()->shader_set_code(shader_data.shader, code); - - shader_map[mk] = shader_data; - - VS::get_singleton()->material_set_shader(_get_material(), shader_data.shader); -} - -void CanvasItemMaterial::flush_changes() { - - MutexLock lock(material_mutex); - - while (dirty_materials->first()) { - - dirty_materials->first()->self()->_update_shader(); - } -} - -void CanvasItemMaterial::_queue_shader_change() { - - MutexLock lock(material_mutex); - - if (!element.in_list()) { - dirty_materials->add(&element); - } -} - -bool CanvasItemMaterial::_is_shader_dirty() const { - - MutexLock lock(material_mutex); - - return element.in_list(); -} -void CanvasItemMaterial::set_blend_mode(BlendMode p_blend_mode) { - - blend_mode = p_blend_mode; - _queue_shader_change(); -} - -CanvasItemMaterial::BlendMode CanvasItemMaterial::get_blend_mode() const { - return blend_mode; -} - -void CanvasItemMaterial::set_light_mode(LightMode p_light_mode) { - - light_mode = p_light_mode; - _queue_shader_change(); -} - -CanvasItemMaterial::LightMode CanvasItemMaterial::get_light_mode() const { - - return light_mode; -} - -void CanvasItemMaterial::set_particles_animation(bool p_particles_anim) { - particles_animation = p_particles_anim; - _queue_shader_change(); - _change_notify(); -} - -bool CanvasItemMaterial::get_particles_animation() const { - return particles_animation; -} - -void CanvasItemMaterial::set_particles_anim_h_frames(int p_frames) { - - particles_anim_h_frames = p_frames; - VS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_h_frames, p_frames); -} - -int CanvasItemMaterial::get_particles_anim_h_frames() const { - - return particles_anim_h_frames; -} -void CanvasItemMaterial::set_particles_anim_v_frames(int p_frames) { - - particles_anim_v_frames = p_frames; - VS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_v_frames, p_frames); -} - -int CanvasItemMaterial::get_particles_anim_v_frames() const { - - return particles_anim_v_frames; -} - -void CanvasItemMaterial::set_particles_anim_loop(bool p_loop) { - - particles_anim_loop = p_loop; - VS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_loop, particles_anim_loop); -} - -bool CanvasItemMaterial::get_particles_anim_loop() const { - - return particles_anim_loop; -} - -void CanvasItemMaterial::_validate_property(PropertyInfo &property) const { - if (property.name.begins_with("particles_anim_") && !particles_animation) { - property.usage = 0; - } -} - -RID CanvasItemMaterial::get_shader_rid() const { - - ERR_FAIL_COND_V(!shader_map.has(current_key), RID()); - return shader_map[current_key].shader; -} - -Shader::Mode CanvasItemMaterial::get_shader_mode() const { - - return Shader::MODE_CANVAS_ITEM; -} - -void CanvasItemMaterial::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_blend_mode", "blend_mode"), &CanvasItemMaterial::set_blend_mode); - ClassDB::bind_method(D_METHOD("get_blend_mode"), &CanvasItemMaterial::get_blend_mode); - - ClassDB::bind_method(D_METHOD("set_light_mode", "light_mode"), &CanvasItemMaterial::set_light_mode); - ClassDB::bind_method(D_METHOD("get_light_mode"), &CanvasItemMaterial::get_light_mode); - - ClassDB::bind_method(D_METHOD("set_particles_animation", "particles_anim"), &CanvasItemMaterial::set_particles_animation); - ClassDB::bind_method(D_METHOD("get_particles_animation"), &CanvasItemMaterial::get_particles_animation); - - ClassDB::bind_method(D_METHOD("set_particles_anim_h_frames", "frames"), &CanvasItemMaterial::set_particles_anim_h_frames); - ClassDB::bind_method(D_METHOD("get_particles_anim_h_frames"), &CanvasItemMaterial::get_particles_anim_h_frames); - - ClassDB::bind_method(D_METHOD("set_particles_anim_v_frames", "frames"), &CanvasItemMaterial::set_particles_anim_v_frames); - ClassDB::bind_method(D_METHOD("get_particles_anim_v_frames"), &CanvasItemMaterial::get_particles_anim_v_frames); - - ClassDB::bind_method(D_METHOD("set_particles_anim_loop", "loop"), &CanvasItemMaterial::set_particles_anim_loop); - ClassDB::bind_method(D_METHOD("get_particles_anim_loop"), &CanvasItemMaterial::get_particles_anim_loop); - - ADD_PROPERTY(PropertyInfo(Variant::INT, "blend_mode", PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul,Premult Alpha"), "set_blend_mode", "get_blend_mode"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "light_mode", PROPERTY_HINT_ENUM, "Normal,Unshaded,Light Only"), "set_light_mode", "get_light_mode"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "particles_animation"), "set_particles_animation", "get_particles_animation"); - - ADD_PROPERTY(PropertyInfo(Variant::INT, "particles_anim_h_frames", PROPERTY_HINT_RANGE, "1,128,1"), "set_particles_anim_h_frames", "get_particles_anim_h_frames"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "particles_anim_v_frames", PROPERTY_HINT_RANGE, "1,128,1"), "set_particles_anim_v_frames", "get_particles_anim_v_frames"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "particles_anim_loop"), "set_particles_anim_loop", "get_particles_anim_loop"); - - BIND_ENUM_CONSTANT(BLEND_MODE_MIX); - BIND_ENUM_CONSTANT(BLEND_MODE_ADD); - BIND_ENUM_CONSTANT(BLEND_MODE_SUB); - BIND_ENUM_CONSTANT(BLEND_MODE_MUL); - BIND_ENUM_CONSTANT(BLEND_MODE_PREMULT_ALPHA); - - BIND_ENUM_CONSTANT(LIGHT_MODE_NORMAL); - BIND_ENUM_CONSTANT(LIGHT_MODE_UNSHADED); - BIND_ENUM_CONSTANT(LIGHT_MODE_LIGHT_ONLY); -} - -CanvasItemMaterial::CanvasItemMaterial() : - element(this) { - - blend_mode = BLEND_MODE_MIX; - light_mode = LIGHT_MODE_NORMAL; - particles_animation = false; - - set_particles_anim_h_frames(1); - set_particles_anim_v_frames(1); - set_particles_anim_loop(false); - - current_key.key = 0; - current_key.invalid_key = 1; - _queue_shader_change(); -} - -CanvasItemMaterial::~CanvasItemMaterial() { - - MutexLock lock(material_mutex); - - if (shader_map.has(current_key)) { - shader_map[current_key].users--; - if (shader_map[current_key].users == 0) { - //deallocate shader, as it's no longer in use - VS::get_singleton()->free(shader_map[current_key].shader); - shader_map.erase(current_key); - } - - VS::get_singleton()->material_set_shader(_get_material(), RID()); - } -} - -/////////////////////////////////////////////////////////////////// -#ifdef TOOLS_ENABLED -bool CanvasItem::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - if (_edit_use_rect()) { - return _edit_get_rect().has_point(p_point); - } else { - return p_point.length() < p_tolerance; - } -} - -Transform2D CanvasItem::_edit_get_transform() const { - return Transform2D(_edit_get_rotation(), _edit_get_position() + _edit_get_pivot()); -} -#endif - -bool CanvasItem::is_visible_in_tree() const { - - if (!is_inside_tree()) - return false; - - const CanvasItem *p = this; - - while (p) { - if (!p->visible) - return false; - p = p->get_parent_item(); - } - - return true; -} - -void CanvasItem::_propagate_visibility_changed(bool p_visible) { - - if (p_visible && first_draw) { //avoid propagating it twice - first_draw = false; - } - notification(NOTIFICATION_VISIBILITY_CHANGED); - - if (p_visible) - update(); //todo optimize - else - emit_signal(SceneStringNames::get_singleton()->hide); - _block(); - - for (int i = 0; i < get_child_count(); i++) { - - CanvasItem *c = Object::cast_to<CanvasItem>(get_child(i)); - - if (c && c->visible) //should the toplevels stop propagation? i think so but.. - c->_propagate_visibility_changed(p_visible); - } - - _unblock(); -} - -void CanvasItem::show() { - - if (visible) - return; - - visible = true; - VisualServer::get_singleton()->canvas_item_set_visible(canvas_item, true); - - if (!is_inside_tree()) - return; - - _propagate_visibility_changed(true); - _change_notify("visible"); -} - -void CanvasItem::hide() { - - if (!visible) - return; - - visible = false; - VisualServer::get_singleton()->canvas_item_set_visible(canvas_item, false); - - if (!is_inside_tree()) - return; - - _propagate_visibility_changed(false); - _change_notify("visible"); -} - -CanvasItem *CanvasItem::current_item_drawn = NULL; -CanvasItem *CanvasItem::get_current_item_drawn() { - return current_item_drawn; -} - -void CanvasItem::_update_callback() { - - if (!is_inside_tree()) { - pending_update = false; - return; - } - - VisualServer::get_singleton()->canvas_item_clear(get_canvas_item()); - //todo updating = true - only allow drawing here - if (is_visible_in_tree()) { //todo optimize this!! - if (first_draw) { - notification(NOTIFICATION_VISIBILITY_CHANGED); - first_draw = false; - } - drawing = true; - current_item_drawn = this; - notification(NOTIFICATION_DRAW); - emit_signal(SceneStringNames::get_singleton()->draw); - if (get_script_instance()) { - get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_draw, NULL, 0); - } - current_item_drawn = NULL; - drawing = false; - } - //todo updating = false - pending_update = false; // don't change to false until finished drawing (avoid recursive update) -} - -Transform2D CanvasItem::get_global_transform_with_canvas() const { - - if (canvas_layer) - return canvas_layer->get_transform() * get_global_transform(); - else if (is_inside_tree()) - return get_viewport()->get_canvas_transform() * get_global_transform(); - else - return get_global_transform(); -} - -Transform2D CanvasItem::get_global_transform() const { -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!is_inside_tree(), get_transform()); -#endif - if (global_invalid) { - - const CanvasItem *pi = get_parent_item(); - if (pi) - global_transform = pi->get_global_transform() * get_transform(); - else - global_transform = get_transform(); - - global_invalid = false; - } - - return global_transform; -} - -void CanvasItem::_toplevel_raise_self() { - - if (!is_inside_tree()) - return; - - if (canvas_layer) - VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, canvas_layer->get_sort_index()); - else - VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_viewport()->gui_get_canvas_sort_index()); -} - -void CanvasItem::_enter_canvas() { - - if ((!Object::cast_to<CanvasItem>(get_parent())) || toplevel) { - - Node *n = this; - - canvas_layer = NULL; - - while (n) { - - canvas_layer = Object::cast_to<CanvasLayer>(n); - if (canvas_layer) { - break; - } - if (Object::cast_to<Viewport>(n)) { - break; - } - n = n->get_parent(); - } - - RID canvas; - if (canvas_layer) - canvas = canvas_layer->get_canvas(); - else - canvas = get_viewport()->find_world_2d()->get_canvas(); - - VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, canvas); - - group = "root_canvas" + itos(canvas.get_id()); - - add_to_group(group); - if (canvas_layer) - canvas_layer->reset_sort_index(); - else - get_viewport()->gui_reset_canvas_sort_index(); - - get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_toplevel_raise_self"); - - } else { - - CanvasItem *parent = get_parent_item(); - canvas_layer = parent->canvas_layer; - VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, parent->get_canvas_item()); - VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index()); - } - - pending_update = false; - update(); - - notification(NOTIFICATION_ENTER_CANVAS); -} - -void CanvasItem::_exit_canvas() { - - notification(NOTIFICATION_EXIT_CANVAS, true); //reverse the notification - VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, RID()); - canvas_layer = NULL; - group = ""; -} - -void CanvasItem::_notification(int p_what) { - - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - - _update_texture_filter_changed(false); - _update_texture_repeat_changed(false); - - first_draw = true; - if (get_parent()) { - CanvasItem *ci = Object::cast_to<CanvasItem>(get_parent()); - if (ci) - C = ci->children_items.push_back(this); - } - _enter_canvas(); - if (!block_transform_notify && !xform_change.in_list()) { - get_tree()->xform_change_list.add(&xform_change); - } - } break; - case NOTIFICATION_MOVED_IN_PARENT: { - - if (!is_inside_tree()) - break; - - if (group != "") { - get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_toplevel_raise_self"); - } else { - CanvasItem *p = get_parent_item(); - ERR_FAIL_COND(!p); - VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index()); - } - - } break; - case NOTIFICATION_EXIT_TREE: { - if (xform_change.in_list()) - get_tree()->xform_change_list.remove(&xform_change); - _exit_canvas(); - if (C) { - Object::cast_to<CanvasItem>(get_parent())->children_items.erase(C); - C = NULL; - } - global_invalid = true; - } break; - case NOTIFICATION_DRAW: - case NOTIFICATION_TRANSFORM_CHANGED: { - - } break; - case NOTIFICATION_VISIBILITY_CHANGED: { - - emit_signal(SceneStringNames::get_singleton()->visibility_changed); - } break; - } -} - -void CanvasItem::set_visible(bool p_visible) { - - if (p_visible) - show(); - else - hide(); -} -bool CanvasItem::is_visible() const { - - return visible; -} - -void CanvasItem::update() { - - if (!is_inside_tree()) - return; - if (pending_update) - return; - - pending_update = true; - - MessageQueue::get_singleton()->push_call(this, "_update_callback"); -} - -void CanvasItem::set_modulate(const Color &p_modulate) { - - if (modulate == p_modulate) - return; - - modulate = p_modulate; - VisualServer::get_singleton()->canvas_item_set_modulate(canvas_item, modulate); -} -Color CanvasItem::get_modulate() const { - - return modulate; -} - -void CanvasItem::set_as_toplevel(bool p_toplevel) { - - if (toplevel == p_toplevel) - return; - - if (!is_inside_tree()) { - toplevel = p_toplevel; - return; - } - - _exit_canvas(); - toplevel = p_toplevel; - _enter_canvas(); -} - -bool CanvasItem::is_set_as_toplevel() const { - - return toplevel; -} - -CanvasItem *CanvasItem::get_parent_item() const { - - if (toplevel) - return NULL; - - return Object::cast_to<CanvasItem>(get_parent()); -} - -void CanvasItem::set_self_modulate(const Color &p_self_modulate) { - - if (self_modulate == p_self_modulate) - return; - - self_modulate = p_self_modulate; - VisualServer::get_singleton()->canvas_item_set_self_modulate(canvas_item, self_modulate); -} -Color CanvasItem::get_self_modulate() const { - - return self_modulate; -} - -void CanvasItem::set_light_mask(int p_light_mask) { - - if (light_mask == p_light_mask) - return; - - light_mask = p_light_mask; - VS::get_singleton()->canvas_item_set_light_mask(canvas_item, p_light_mask); -} - -int CanvasItem::get_light_mask() const { - - return light_mask; -} - -void CanvasItem::item_rect_changed(bool p_size_changed) { - - if (p_size_changed) - update(); - emit_signal(SceneStringNames::get_singleton()->item_rect_changed); -} - -void CanvasItem::draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - VisualServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width); -} - -void CanvasItem::draw_polyline(const Vector<Point2> &p_points, const Color &p_color, float p_width) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - Vector<Color> colors; - colors.push_back(p_color); - VisualServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, colors, p_width); -} - -void CanvasItem::draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - VisualServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, p_colors, p_width); -} - -void CanvasItem::draw_arc(const Vector2 &p_center, float p_radius, float p_start_angle, float p_end_angle, int p_point_count, const Color &p_color, float p_width) { - - Vector<Point2> points; - points.resize(p_point_count); - const float delta_angle = p_end_angle - p_start_angle; - for (int i = 0; i < p_point_count; i++) { - float theta = (i / (p_point_count - 1.0f)) * delta_angle + p_start_angle; - points.set(i, p_center + Vector2(Math::cos(theta), Math::sin(theta)) * p_radius); - } - - draw_polyline(points, p_color, p_width); -} - -void CanvasItem::draw_multiline(const Vector<Point2> &p_points, const Color &p_color, float p_width) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - Vector<Color> colors; - colors.push_back(p_color); - VisualServer::get_singleton()->canvas_item_add_multiline(canvas_item, p_points, colors, p_width); -} - -void CanvasItem::draw_multiline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - VisualServer::get_singleton()->canvas_item_add_multiline(canvas_item, p_points, p_colors, p_width); -} - -void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled, float p_width) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - if (p_filled) { - if (p_width != 1.0) { - WARN_PRINT("The draw_rect() \"width\" argument has no effect when \"filled\" is \"true\"."); - } - - VisualServer::get_singleton()->canvas_item_add_rect(canvas_item, p_rect, p_color); - } else { - // Thick lines are offset depending on their width to avoid partial overlapping. - // Thin lines don't require an offset, so don't apply one in this case - float offset; - if (p_width >= 2) { - offset = p_width / 2.0; - } else { - offset = 0.0; - } - - VisualServer::get_singleton()->canvas_item_add_line( - canvas_item, - p_rect.position + Size2(-offset, 0), - p_rect.position + Size2(p_rect.size.width + offset, 0), - p_color, - p_width); - VisualServer::get_singleton()->canvas_item_add_line( - canvas_item, - p_rect.position + Size2(p_rect.size.width, offset), - p_rect.position + Size2(p_rect.size.width, p_rect.size.height - offset), - p_color, - p_width); - VisualServer::get_singleton()->canvas_item_add_line( - canvas_item, - p_rect.position + Size2(p_rect.size.width + offset, p_rect.size.height), - p_rect.position + Size2(-offset, p_rect.size.height), - p_color, - p_width); - VisualServer::get_singleton()->canvas_item_add_line( - canvas_item, - p_rect.position + Size2(0, p_rect.size.height - offset), - p_rect.position + Size2(0, offset), - p_color, - p_width); - } -} - -void CanvasItem::draw_circle(const Point2 &p_pos, float p_radius, const Color &p_color) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - VisualServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius, p_color); -} - -void CanvasItem::draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, TextureFilter p_texture_filter, TextureRepeat p_texture_repeat) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - ERR_FAIL_COND(p_texture.is_null()); - - p_texture->draw(canvas_item, p_pos, p_modulate, false, p_normal_map, p_specular_map, p_specular_color_shininess, VS::CanvasItemTextureFilter(p_texture_filter), VS::CanvasItemTextureRepeat(p_texture_repeat)); -} - -void CanvasItem::draw_texture_rect(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, TextureFilter p_texture_filter, TextureRepeat p_texture_repeat) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - ERR_FAIL_COND(p_texture.is_null()); - p_texture->draw_rect(canvas_item, p_rect, p_tile, p_modulate, p_transpose, p_normal_map, p_specular_map, p_specular_color_shininess, VS::CanvasItemTextureFilter(p_texture_filter), VS::CanvasItemTextureRepeat(p_texture_repeat)); -} -void CanvasItem::draw_texture_rect_region(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, bool p_clip_uv, TextureFilter p_texture_filter, TextureRepeat p_texture_repeat) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL_COND(p_texture.is_null()); - p_texture->draw_rect_region(canvas_item, p_rect, p_src_rect, p_modulate, p_transpose, p_normal_map, p_specular_map, p_specular_color_shininess, VS::CanvasItemTextureFilter(p_texture_filter), VS::CanvasItemTextureRepeat(p_texture_repeat), p_clip_uv); -} - -void CanvasItem::draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect) { - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - ERR_FAIL_COND(p_style_box.is_null()); - - p_style_box->draw(canvas_item, p_rect); -} -void CanvasItem::draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture2D> p_texture, float p_width, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, TextureFilter p_texture_filter, TextureRepeat p_texture_repeat) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); - RID rid_normal = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); - RID rid_specular = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - - VisualServer::get_singleton()->canvas_item_add_primitive(canvas_item, p_points, p_colors, p_uvs, rid, p_width, rid_normal, rid_specular, p_specular_color_shininess, VS::CanvasItemTextureFilter(p_texture_filter), VS::CanvasItemTextureRepeat(p_texture_repeat)); -} -void CanvasItem::draw_set_transform(const Point2 &p_offset, float p_rot, const Size2 &p_scale) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - Transform2D xform(p_rot, p_offset); - xform.scale_basis(p_scale); - VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item, xform); -} - -void CanvasItem::draw_set_transform_matrix(const Transform2D &p_matrix) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item, p_matrix); -} - -void CanvasItem::draw_polygon(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture2D> p_texture, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, TextureFilter p_texture_filter, TextureRepeat p_texture_repeat) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); - RID rid_normal = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); - RID rid_specular = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - - VisualServer::get_singleton()->canvas_item_add_polygon(canvas_item, p_points, p_colors, p_uvs, rid, rid_normal, rid_specular, p_specular_color_shininess, VS::CanvasItemTextureFilter(p_texture_filter), VS::CanvasItemTextureRepeat(p_texture_repeat)); -} - -void CanvasItem::draw_colored_polygon(const Vector<Point2> &p_points, const Color &p_color, const Vector<Point2> &p_uvs, Ref<Texture2D> p_texture, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, TextureFilter p_texture_filter, TextureRepeat p_texture_repeat) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - Vector<Color> colors; - colors.push_back(p_color); - RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); - RID rid_normal = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); - RID rid_specular = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - - VisualServer::get_singleton()->canvas_item_add_polygon(canvas_item, p_points, colors, p_uvs, rid, rid_normal, rid_specular, p_specular_color_shininess, VS::CanvasItemTextureFilter(p_texture_filter), VS::CanvasItemTextureRepeat(p_texture_repeat)); -} - -void CanvasItem::draw_mesh(const Ref<Mesh> &p_mesh, const Ref<Texture2D> &p_texture, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, const Transform2D &p_transform, const Color &p_modulate, TextureFilter p_texture_filter, TextureRepeat p_texture_repeat) { - - ERR_FAIL_COND(p_mesh.is_null()); - RID texture_rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); - RID normal_map_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); - RID specular_map_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - - VisualServer::get_singleton()->canvas_item_add_mesh(canvas_item, p_mesh->get_rid(), p_transform, p_modulate, texture_rid, normal_map_rid, specular_map_rid, p_specular_color_shininess, VS::CanvasItemTextureFilter(p_texture_filter), VS::CanvasItemTextureRepeat(p_texture_repeat)); -} -void CanvasItem::draw_multimesh(const Ref<MultiMesh> &p_multimesh, const Ref<Texture2D> &p_texture, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, TextureFilter p_texture_filter, TextureRepeat p_texture_repeat) { - - ERR_FAIL_COND(p_multimesh.is_null()); - RID texture_rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); - RID normal_map_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); - RID specular_map_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - - VisualServer::get_singleton()->canvas_item_add_multimesh(canvas_item, p_multimesh->get_rid(), texture_rid, normal_map_rid, specular_map_rid, p_specular_color_shininess, VS::CanvasItemTextureFilter(p_texture_filter), VS::CanvasItemTextureRepeat(p_texture_repeat)); -} - -void CanvasItem::draw_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, const Color &p_modulate, int p_clip_w) { - - ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - ERR_FAIL_COND(p_font.is_null()); - p_font->draw(canvas_item, p_pos, p_text, p_modulate, p_clip_w); -} - -float CanvasItem::draw_char(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, const String &p_next, const Color &p_modulate) { - - ERR_FAIL_COND_V_MSG(!drawing, 0, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - - ERR_FAIL_COND_V(p_char.length() != 1, 0); - ERR_FAIL_COND_V(p_font.is_null(), 0); - - if (p_font->has_outline()) { - p_font->draw_char(canvas_item, p_pos, p_char[0], p_next.c_str()[0], Color(1, 1, 1), true); - } - return p_font->draw_char(canvas_item, p_pos, p_char[0], p_next.c_str()[0], p_modulate); -} - -void CanvasItem::_notify_transform(CanvasItem *p_node) { - - /* This check exists to avoid re-propagating the transform - * notification down the tree on dirty nodes. It provides - * optimization by avoiding redundancy (nodes are dirty, will get the - * notification anyway). - */ - - if (/*p_node->xform_change.in_list() &&*/ p_node->global_invalid) { - return; //nothing to do - } - - p_node->global_invalid = true; - - if (p_node->notify_transform && !p_node->xform_change.in_list()) { - if (!p_node->block_transform_notify) { - if (p_node->is_inside_tree()) - get_tree()->xform_change_list.add(&p_node->xform_change); - } - } - - for (List<CanvasItem *>::Element *E = p_node->children_items.front(); E; E = E->next()) { - - CanvasItem *ci = E->get(); - if (ci->toplevel) - continue; - _notify_transform(ci); - } -} - -Rect2 CanvasItem::get_viewport_rect() const { - - ERR_FAIL_COND_V(!is_inside_tree(), Rect2()); - return get_viewport()->get_visible_rect(); -} - -RID CanvasItem::get_canvas() const { - - ERR_FAIL_COND_V(!is_inside_tree(), RID()); - - if (canvas_layer) - return canvas_layer->get_canvas(); - else - return get_viewport()->find_world_2d()->get_canvas(); -} - -ObjectID CanvasItem::get_canvas_layer_instance_id() const { - - if (canvas_layer) { - return canvas_layer->get_instance_id(); - } else { - return ObjectID(); - } -} - -CanvasItem *CanvasItem::get_toplevel() const { - - CanvasItem *ci = const_cast<CanvasItem *>(this); - while (!ci->toplevel && Object::cast_to<CanvasItem>(ci->get_parent())) { - ci = Object::cast_to<CanvasItem>(ci->get_parent()); - } - - return ci; -} - -Ref<World2D> CanvasItem::get_world_2d() const { - - ERR_FAIL_COND_V(!is_inside_tree(), Ref<World2D>()); - - CanvasItem *tl = get_toplevel(); - - if (tl->get_viewport()) { - return tl->get_viewport()->find_world_2d(); - } else { - return Ref<World2D>(); - } -} - -RID CanvasItem::get_viewport_rid() const { - - ERR_FAIL_COND_V(!is_inside_tree(), RID()); - return get_viewport()->get_viewport_rid(); -} - -void CanvasItem::set_block_transform_notify(bool p_enable) { - block_transform_notify = p_enable; -} - -bool CanvasItem::is_block_transform_notify_enabled() const { - - return block_transform_notify; -} - -void CanvasItem::set_draw_behind_parent(bool p_enable) { - - if (behind == p_enable) - return; - behind = p_enable; - VisualServer::get_singleton()->canvas_item_set_draw_behind_parent(canvas_item, behind); -} - -bool CanvasItem::is_draw_behind_parent_enabled() const { - - return behind; -} - -void CanvasItem::set_material(const Ref<Material> &p_material) { - - material = p_material; - RID rid; - if (material.is_valid()) - rid = material->get_rid(); - VS::get_singleton()->canvas_item_set_material(canvas_item, rid); - _change_notify(); //properties for material exposed -} - -void CanvasItem::set_use_parent_material(bool p_use_parent_material) { - - use_parent_material = p_use_parent_material; - VS::get_singleton()->canvas_item_set_use_parent_material(canvas_item, p_use_parent_material); -} - -bool CanvasItem::get_use_parent_material() const { - - return use_parent_material; -} - -Ref<Material> CanvasItem::get_material() const { - - return material; -} - -Vector2 CanvasItem::make_canvas_position_local(const Vector2 &screen_point) const { - - ERR_FAIL_COND_V(!is_inside_tree(), screen_point); - - Transform2D local_matrix = (get_canvas_transform() * get_global_transform()).affine_inverse(); - - return local_matrix.xform(screen_point); -} - -Ref<InputEvent> CanvasItem::make_input_local(const Ref<InputEvent> &p_event) const { - - ERR_FAIL_COND_V(p_event.is_null(), p_event); - ERR_FAIL_COND_V(!is_inside_tree(), p_event); - - return p_event->xformed_by((get_canvas_transform() * get_global_transform()).affine_inverse()); -} - -Vector2 CanvasItem::get_global_mouse_position() const { - - ERR_FAIL_COND_V(!get_viewport(), Vector2()); - return get_canvas_transform().affine_inverse().xform(get_viewport()->get_mouse_position()); -} - -Vector2 CanvasItem::get_local_mouse_position() const { - - ERR_FAIL_COND_V(!get_viewport(), Vector2()); - - return get_global_transform().affine_inverse().xform(get_global_mouse_position()); -} - -void CanvasItem::force_update_transform() { - ERR_FAIL_COND(!is_inside_tree()); - if (!xform_change.in_list()) { - return; - } - - get_tree()->xform_change_list.remove(&xform_change); - - notification(NOTIFICATION_TRANSFORM_CHANGED); -} - -void CanvasItem::_bind_methods() { - - ClassDB::bind_method(D_METHOD("_toplevel_raise_self"), &CanvasItem::_toplevel_raise_self); - ClassDB::bind_method(D_METHOD("_update_callback"), &CanvasItem::_update_callback); - -#ifdef TOOLS_ENABLED - ClassDB::bind_method(D_METHOD("_edit_set_state", "state"), &CanvasItem::_edit_set_state); - ClassDB::bind_method(D_METHOD("_edit_get_state"), &CanvasItem::_edit_get_state); - ClassDB::bind_method(D_METHOD("_edit_set_position", "position"), &CanvasItem::_edit_set_position); - ClassDB::bind_method(D_METHOD("_edit_get_position"), &CanvasItem::_edit_get_position); - ClassDB::bind_method(D_METHOD("_edit_set_scale", "scale"), &CanvasItem::_edit_set_scale); - ClassDB::bind_method(D_METHOD("_edit_get_scale"), &CanvasItem::_edit_get_scale); - ClassDB::bind_method(D_METHOD("_edit_set_rect", "rect"), &CanvasItem::_edit_set_rect); - ClassDB::bind_method(D_METHOD("_edit_get_rect"), &CanvasItem::_edit_get_rect); - ClassDB::bind_method(D_METHOD("_edit_use_rect"), &CanvasItem::_edit_use_rect); - ClassDB::bind_method(D_METHOD("_edit_set_rotation", "degrees"), &CanvasItem::_edit_set_rotation); - ClassDB::bind_method(D_METHOD("_edit_get_rotation"), &CanvasItem::_edit_get_rotation); - ClassDB::bind_method(D_METHOD("_edit_use_rotation"), &CanvasItem::_edit_use_rotation); - ClassDB::bind_method(D_METHOD("_edit_set_pivot", "pivot"), &CanvasItem::_edit_set_pivot); - ClassDB::bind_method(D_METHOD("_edit_get_pivot"), &CanvasItem::_edit_get_pivot); - ClassDB::bind_method(D_METHOD("_edit_use_pivot"), &CanvasItem::_edit_use_pivot); - ClassDB::bind_method(D_METHOD("_edit_get_transform"), &CanvasItem::_edit_get_transform); -#endif - - ClassDB::bind_method(D_METHOD("get_canvas_item"), &CanvasItem::get_canvas_item); - - ClassDB::bind_method(D_METHOD("set_visible", "visible"), &CanvasItem::set_visible); - ClassDB::bind_method(D_METHOD("is_visible"), &CanvasItem::is_visible); - ClassDB::bind_method(D_METHOD("is_visible_in_tree"), &CanvasItem::is_visible_in_tree); - ClassDB::bind_method(D_METHOD("show"), &CanvasItem::show); - ClassDB::bind_method(D_METHOD("hide"), &CanvasItem::hide); - - ClassDB::bind_method(D_METHOD("update"), &CanvasItem::update); - - ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &CanvasItem::set_as_toplevel); - ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &CanvasItem::is_set_as_toplevel); - - ClassDB::bind_method(D_METHOD("set_light_mask", "light_mask"), &CanvasItem::set_light_mask); - ClassDB::bind_method(D_METHOD("get_light_mask"), &CanvasItem::get_light_mask); - - ClassDB::bind_method(D_METHOD("set_modulate", "modulate"), &CanvasItem::set_modulate); - ClassDB::bind_method(D_METHOD("get_modulate"), &CanvasItem::get_modulate); - ClassDB::bind_method(D_METHOD("set_self_modulate", "self_modulate"), &CanvasItem::set_self_modulate); - ClassDB::bind_method(D_METHOD("get_self_modulate"), &CanvasItem::get_self_modulate); - - ClassDB::bind_method(D_METHOD("set_draw_behind_parent", "enable"), &CanvasItem::set_draw_behind_parent); - ClassDB::bind_method(D_METHOD("is_draw_behind_parent_enabled"), &CanvasItem::is_draw_behind_parent_enabled); - - ClassDB::bind_method(D_METHOD("_set_on_top", "on_top"), &CanvasItem::_set_on_top); - ClassDB::bind_method(D_METHOD("_is_on_top"), &CanvasItem::_is_on_top); - //ClassDB::bind_method(D_METHOD("get_transform"),&CanvasItem::get_transform); - - ClassDB::bind_method(D_METHOD("draw_line", "from", "to", "color", "width"), &CanvasItem::draw_line, DEFVAL(1.0)); - ClassDB::bind_method(D_METHOD("draw_polyline", "points", "color", "width"), &CanvasItem::draw_polyline, DEFVAL(1.0)); - ClassDB::bind_method(D_METHOD("draw_polyline_colors", "points", "colors", "width"), &CanvasItem::draw_polyline_colors, DEFVAL(1.0)); - ClassDB::bind_method(D_METHOD("draw_arc", "center", "radius", "start_angle", "end_angle", "point_count", "color", "width"), &CanvasItem::draw_arc, DEFVAL(1.0)); - ClassDB::bind_method(D_METHOD("draw_multiline", "points", "color", "width"), &CanvasItem::draw_multiline, DEFVAL(1.0)); - ClassDB::bind_method(D_METHOD("draw_multiline_colors", "points", "colors", "width"), &CanvasItem::draw_multiline_colors, DEFVAL(1.0)); - ClassDB::bind_method(D_METHOD("draw_rect", "rect", "color", "filled", "width"), &CanvasItem::draw_rect, DEFVAL(true), DEFVAL(1.0)); - ClassDB::bind_method(D_METHOD("draw_circle", "position", "radius", "color"), &CanvasItem::draw_circle); - ClassDB::bind_method(D_METHOD("draw_texture", "texture", "position", "modulate", "normal_map", "specular_map", "specular_shininess", "texture_filter", "texture_repeat"), &CanvasItem::draw_texture, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(TEXTURE_FILTER_PARENT_NODE), DEFVAL(TEXTURE_REPEAT_PARENT_NODE)); - ClassDB::bind_method(D_METHOD("draw_texture_rect", "texture", "rect", "tile", "modulate", "transpose", "normal_map", "specular_map", "specular_shininess", "texture_filter", "texture_repeat"), &CanvasItem::draw_texture_rect, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(false), DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(TEXTURE_FILTER_PARENT_NODE), DEFVAL(TEXTURE_REPEAT_PARENT_NODE)); - ClassDB::bind_method(D_METHOD("draw_texture_rect_region", "texture", "rect", "src_rect", "modulate", "transpose", "normal_map", "specular_map", "specular_shininess", "clip_uv", "texture_filter", "texture_repeat"), &CanvasItem::draw_texture_rect_region, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(false), DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(true), DEFVAL(TEXTURE_FILTER_PARENT_NODE), DEFVAL(TEXTURE_REPEAT_PARENT_NODE)); - ClassDB::bind_method(D_METHOD("draw_style_box", "style_box", "rect"), &CanvasItem::draw_style_box); - ClassDB::bind_method(D_METHOD("draw_primitive", "points", "colors", "uvs", "texture", "width", "normal_map", "specular_map", "specular_shininess", "texture_filter", "texture_repeat"), &CanvasItem::draw_primitive, DEFVAL(Ref<Texture2D>()), DEFVAL(1.0), DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(TEXTURE_FILTER_PARENT_NODE), DEFVAL(TEXTURE_REPEAT_PARENT_NODE)); - ClassDB::bind_method(D_METHOD("draw_polygon", "points", "colors", "uvs", "texture", "normal_map", "specular_map", "specular_shininess", "texture_filter", "texture_repeat"), &CanvasItem::draw_polygon, DEFVAL(PackedVector2Array()), DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(TEXTURE_FILTER_PARENT_NODE), DEFVAL(TEXTURE_REPEAT_PARENT_NODE)); - ClassDB::bind_method(D_METHOD("draw_colored_polygon", "points", "color", "uvs", "texture", "normal_map", "specular_map", "specular_shininess", "texture_filter", "texture_repeat"), &CanvasItem::draw_colored_polygon, DEFVAL(PackedVector2Array()), DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(TEXTURE_FILTER_PARENT_NODE), DEFVAL(TEXTURE_REPEAT_PARENT_NODE)); - ClassDB::bind_method(D_METHOD("draw_string", "font", "position", "text", "modulate", "clip_w"), &CanvasItem::draw_string, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(-1)); - ClassDB::bind_method(D_METHOD("draw_char", "font", "position", "char", "next", "modulate"), &CanvasItem::draw_char, DEFVAL(Color(1, 1, 1, 1))); - ClassDB::bind_method(D_METHOD("draw_mesh", "mesh", "texture", "normal_map", "specular_map", "specular_shininess", "transform", "modulate", "texture_filter", "texture_repeat"), &CanvasItem::draw_mesh, DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(Transform2D()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(TEXTURE_FILTER_PARENT_NODE), DEFVAL(TEXTURE_REPEAT_PARENT_NODE)); - ClassDB::bind_method(D_METHOD("draw_multimesh", "multimesh", "texture", "normal_map", "specular_map", "specular_shininess", "texture_filter", "texture_repeat"), &CanvasItem::draw_multimesh, DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(TEXTURE_FILTER_PARENT_NODE), DEFVAL(TEXTURE_REPEAT_PARENT_NODE)); - - ClassDB::bind_method(D_METHOD("draw_set_transform", "position", "rotation", "scale"), &CanvasItem::draw_set_transform); - ClassDB::bind_method(D_METHOD("draw_set_transform_matrix", "xform"), &CanvasItem::draw_set_transform_matrix); - ClassDB::bind_method(D_METHOD("get_transform"), &CanvasItem::get_transform); - ClassDB::bind_method(D_METHOD("get_global_transform"), &CanvasItem::get_global_transform); - ClassDB::bind_method(D_METHOD("get_global_transform_with_canvas"), &CanvasItem::get_global_transform_with_canvas); - ClassDB::bind_method(D_METHOD("get_viewport_transform"), &CanvasItem::get_viewport_transform); - ClassDB::bind_method(D_METHOD("get_viewport_rect"), &CanvasItem::get_viewport_rect); - ClassDB::bind_method(D_METHOD("get_canvas_transform"), &CanvasItem::get_canvas_transform); - ClassDB::bind_method(D_METHOD("get_local_mouse_position"), &CanvasItem::get_local_mouse_position); - ClassDB::bind_method(D_METHOD("get_global_mouse_position"), &CanvasItem::get_global_mouse_position); - ClassDB::bind_method(D_METHOD("get_canvas"), &CanvasItem::get_canvas); - ClassDB::bind_method(D_METHOD("get_world_2d"), &CanvasItem::get_world_2d); - //ClassDB::bind_method(D_METHOD("get_viewport"),&CanvasItem::get_viewport); - - ClassDB::bind_method(D_METHOD("set_material", "material"), &CanvasItem::set_material); - ClassDB::bind_method(D_METHOD("get_material"), &CanvasItem::get_material); - - ClassDB::bind_method(D_METHOD("set_use_parent_material", "enable"), &CanvasItem::set_use_parent_material); - ClassDB::bind_method(D_METHOD("get_use_parent_material"), &CanvasItem::get_use_parent_material); - - ClassDB::bind_method(D_METHOD("set_notify_local_transform", "enable"), &CanvasItem::set_notify_local_transform); - ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"), &CanvasItem::is_local_transform_notification_enabled); - - ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &CanvasItem::set_notify_transform); - ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &CanvasItem::is_transform_notification_enabled); - - ClassDB::bind_method(D_METHOD("force_update_transform"), &CanvasItem::force_update_transform); - - ClassDB::bind_method(D_METHOD("make_canvas_position_local", "screen_point"), &CanvasItem::make_canvas_position_local); - ClassDB::bind_method(D_METHOD("make_input_local", "event"), &CanvasItem::make_input_local); - - ClassDB::bind_method(D_METHOD("set_texture_filter", "mode"), &CanvasItem::set_texture_filter); - ClassDB::bind_method(D_METHOD("get_texture_filter"), &CanvasItem::get_texture_filter); - - ClassDB::bind_method(D_METHOD("set_texture_repeat", "mode"), &CanvasItem::set_texture_repeat); - ClassDB::bind_method(D_METHOD("get_texture_repeat"), &CanvasItem::get_texture_repeat); - - BIND_VMETHOD(MethodInfo("_draw")); - - ADD_GROUP("Visibility", ""); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible"); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate"); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "self_modulate"), "set_self_modulate", "get_self_modulate"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_behind_parent"), "set_draw_behind_parent", "is_draw_behind_parent_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_on_top", PROPERTY_HINT_NONE, "", 0), "_set_on_top", "_is_on_top"); //compatibility - ADD_PROPERTY(PropertyInfo(Variant::INT, "light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_light_mask", "get_light_mask"); - - ADD_GROUP("Texture", "texture_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_filter", PROPERTY_HINT_ENUM, "ParentNode,Nearest,Linear,MipmapNearest,MipmapLinear,MipmapNearestAniso,MipmapLinearAniso"), "set_texture_filter", "get_texture_filter"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_repeat", PROPERTY_HINT_ENUM, "ParentNode,Disabled,Enabled,Mirror"), "set_texture_repeat", "get_texture_repeat"); - - ADD_GROUP("Material", ""); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,CanvasItemMaterial"), "set_material", "get_material"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_parent_material"), "set_use_parent_material", "get_use_parent_material"); - //exporting these things doesn't really make much sense i think - // ADD_PROPERTY(PropertyInfo(Variant::BOOL, "toplevel", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_as_toplevel", "is_set_as_toplevel"); - // ADD_PROPERTY(PropertyInfo(Variant::BOOL,"transform/notify"),"set_transform_notify","is_transform_notify_enabled"); - - ADD_SIGNAL(MethodInfo("draw")); - ADD_SIGNAL(MethodInfo("visibility_changed")); - ADD_SIGNAL(MethodInfo("hide")); - ADD_SIGNAL(MethodInfo("item_rect_changed")); - - BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED); - BIND_CONSTANT(NOTIFICATION_DRAW); - BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED); - BIND_CONSTANT(NOTIFICATION_ENTER_CANVAS); - BIND_CONSTANT(NOTIFICATION_EXIT_CANVAS); - - BIND_ENUM_CONSTANT(TEXTURE_FILTER_PARENT_NODE); - BIND_ENUM_CONSTANT(TEXTURE_FILTER_NEAREST); - BIND_ENUM_CONSTANT(TEXTURE_FILTER_LINEAR); - BIND_ENUM_CONSTANT(TEXTURE_FILTER_NEAREST_WITH_MIPMAPS); - BIND_ENUM_CONSTANT(TEXTURE_FILTER_LINEAR_WITH_MIPMAPS); - BIND_ENUM_CONSTANT(TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC); - BIND_ENUM_CONSTANT(TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC); - BIND_ENUM_CONSTANT(TEXTURE_FILTER_MAX); - - BIND_ENUM_CONSTANT(TEXTURE_REPEAT_PARENT_NODE); - BIND_ENUM_CONSTANT(TEXTURE_REPEAT_DISABLED); - BIND_ENUM_CONSTANT(TEXTURE_REPEAT_ENABLED); - BIND_ENUM_CONSTANT(TEXTURE_REPEAT_MIRROR); - BIND_ENUM_CONSTANT(TEXTURE_REPEAT_MAX); -} - -Transform2D CanvasItem::get_canvas_transform() const { - - ERR_FAIL_COND_V(!is_inside_tree(), Transform2D()); - - if (canvas_layer) - return canvas_layer->get_transform(); - else if (Object::cast_to<CanvasItem>(get_parent())) - return Object::cast_to<CanvasItem>(get_parent())->get_canvas_transform(); - else - return get_viewport()->get_canvas_transform(); -} - -Transform2D CanvasItem::get_viewport_transform() const { - - ERR_FAIL_COND_V(!is_inside_tree(), Transform2D()); - - if (canvas_layer) { - - if (get_viewport()) { - return get_viewport()->get_final_transform() * canvas_layer->get_transform(); - } else { - return canvas_layer->get_transform(); - } - - } else { - return get_viewport()->get_final_transform() * get_viewport()->get_canvas_transform(); - } -} - -void CanvasItem::set_notify_local_transform(bool p_enable) { - notify_local_transform = p_enable; -} - -bool CanvasItem::is_local_transform_notification_enabled() const { - return notify_local_transform; -} - -void CanvasItem::set_notify_transform(bool p_enable) { - if (notify_transform == p_enable) - return; - - notify_transform = p_enable; - - if (notify_transform && is_inside_tree()) { - //this ensures that invalid globals get resolved, so notifications can be received - get_global_transform(); - } -} - -bool CanvasItem::is_transform_notification_enabled() const { - return notify_transform; -} - -int CanvasItem::get_canvas_layer() const { - - if (canvas_layer) - return canvas_layer->get_layer(); - else - return 0; -} - -void CanvasItem::_update_texture_filter_changed(bool p_propagate) { - - if (!is_inside_tree()) { - return; - } - - if (texture_filter == TEXTURE_FILTER_PARENT_NODE) { - CanvasItem *parent_item = get_parent_item(); - if (parent_item) { - texture_filter_cache = parent_item->texture_filter_cache; - } else { - //from viewport - switch (get_viewport()->get_default_canvas_item_texture_filter()) { - case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST: texture_filter_cache = VS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST; break; - case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR: texture_filter_cache = VS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR; break; - case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS: texture_filter_cache = VS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS; break; - case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS: texture_filter_cache = VS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS; break; - default: { - } - } - } - } else { - texture_filter_cache = VS::CanvasItemTextureFilter(texture_filter); - } - VS::get_singleton()->canvas_item_set_default_texture_filter(get_canvas_item(), texture_filter_cache); - update(); - - if (p_propagate) { - for (List<CanvasItem *>::Element *E = children_items.front(); E; E = E->next()) { - if (!E->get()->toplevel && E->get()->texture_filter == TEXTURE_FILTER_PARENT_NODE) { - E->get()->_update_texture_filter_changed(true); - } - } - } -} - -void CanvasItem::set_texture_filter(TextureFilter p_texture_filter) { - ERR_FAIL_INDEX(p_texture_filter, TEXTURE_FILTER_MAX); - if (texture_filter == p_texture_filter) { - return; - } - texture_filter = p_texture_filter; - _update_texture_filter_changed(true); -} - -CanvasItem::TextureFilter CanvasItem::get_texture_filter() const { - return texture_filter; -} - -void CanvasItem::_update_texture_repeat_changed(bool p_propagate) { - - if (!is_inside_tree()) { - return; - } - - if (texture_repeat == TEXTURE_REPEAT_PARENT_NODE) { - CanvasItem *parent_item = get_parent_item(); - if (parent_item) { - texture_repeat_cache = parent_item->texture_repeat_cache; - } else { - //from viewport - switch (get_viewport()->get_default_canvas_item_texture_repeat()) { - case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_DISABLED: texture_repeat_cache = VS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED; break; - case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_ENABLED: texture_repeat_cache = VS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED; break; - case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_MIRROR: texture_repeat_cache = VS::CANVAS_ITEM_TEXTURE_REPEAT_MIRROR; break; - default: { - } - } - } - } else { - texture_repeat_cache = VS::CanvasItemTextureRepeat(texture_repeat); - } - VS::get_singleton()->canvas_item_set_default_texture_repeat(get_canvas_item(), texture_repeat_cache); - update(); - if (p_propagate) { - for (List<CanvasItem *>::Element *E = children_items.front(); E; E = E->next()) { - if (!E->get()->toplevel && E->get()->texture_repeat == TEXTURE_REPEAT_PARENT_NODE) { - E->get()->_update_texture_repeat_changed(true); - } - } - } -} - -void CanvasItem::set_texture_repeat(TextureRepeat p_texture_repeat) { - ERR_FAIL_INDEX(p_texture_repeat, TEXTURE_REPEAT_MAX); - if (texture_repeat == p_texture_repeat) { - return; - } - texture_repeat = p_texture_repeat; - _update_texture_repeat_changed(true); -} - -CanvasItem::TextureRepeat CanvasItem::get_texture_repeat() const { - return texture_repeat; -} - -CanvasItem::CanvasItem() : - xform_change(this) { - - canvas_item = VisualServer::get_singleton()->canvas_item_create(); - visible = true; - pending_update = false; - modulate = Color(1, 1, 1, 1); - self_modulate = Color(1, 1, 1, 1); - toplevel = false; - first_draw = false; - drawing = false; - behind = false; - block_transform_notify = false; - //viewport=NULL; - canvas_layer = NULL; - use_parent_material = false; - global_invalid = true; - notify_local_transform = false; - notify_transform = false; - light_mask = 1; - texture_repeat = TEXTURE_REPEAT_PARENT_NODE; - texture_filter = TEXTURE_FILTER_PARENT_NODE; - texture_filter_cache = VS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR; - texture_repeat_cache = VS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED; - - C = NULL; -} - -CanvasItem::~CanvasItem() { - - VisualServer::get_singleton()->free(canvas_item); -} diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h deleted file mode 100644 index c7f9500ea1..0000000000 --- a/scene/2d/canvas_item.h +++ /dev/null @@ -1,422 +0,0 @@ -/*************************************************************************/ -/* canvas_item.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CANVAS_ITEM_H -#define CANVAS_ITEM_H - -#include "scene/main/node.h" -#include "scene/main/scene_tree.h" -#include "scene/resources/material.h" -#include "scene/resources/multimesh.h" -#include "scene/resources/shader.h" -#include "scene/resources/texture.h" - -class CanvasLayer; -class Viewport; -class Font; - -class StyleBox; - -class CanvasItemMaterial : public Material { - - GDCLASS(CanvasItemMaterial, Material); - -public: - enum BlendMode { - BLEND_MODE_MIX, - BLEND_MODE_ADD, - BLEND_MODE_SUB, - BLEND_MODE_MUL, - BLEND_MODE_PREMULT_ALPHA, - BLEND_MODE_DISABLED - }; - - enum LightMode { - LIGHT_MODE_NORMAL, - LIGHT_MODE_UNSHADED, - LIGHT_MODE_LIGHT_ONLY - }; - -private: - union MaterialKey { - - struct { - uint32_t blend_mode : 4; - uint32_t light_mode : 4; - uint32_t particles_animation : 1; - uint32_t invalid_key : 1; - }; - - uint32_t key; - - bool operator<(const MaterialKey &p_key) const { - return key < p_key.key; - } - }; - - struct ShaderNames { - StringName particles_anim_h_frames; - StringName particles_anim_v_frames; - StringName particles_anim_loop; - }; - - static ShaderNames *shader_names; - - struct ShaderData { - RID shader; - int users; - }; - - static Map<MaterialKey, ShaderData> shader_map; - - MaterialKey current_key; - - _FORCE_INLINE_ MaterialKey _compute_key() const { - - MaterialKey mk; - mk.key = 0; - mk.blend_mode = blend_mode; - mk.light_mode = light_mode; - mk.particles_animation = particles_animation; - return mk; - } - - static Mutex material_mutex; - static SelfList<CanvasItemMaterial>::List *dirty_materials; - SelfList<CanvasItemMaterial> element; - - void _update_shader(); - _FORCE_INLINE_ void _queue_shader_change(); - _FORCE_INLINE_ bool _is_shader_dirty() const; - - BlendMode blend_mode; - LightMode light_mode; - bool particles_animation; - - int particles_anim_h_frames; - int particles_anim_v_frames; - bool particles_anim_loop; - -protected: - static void _bind_methods(); - void _validate_property(PropertyInfo &property) const; - -public: - void set_blend_mode(BlendMode p_blend_mode); - BlendMode get_blend_mode() const; - - void set_light_mode(LightMode p_light_mode); - LightMode get_light_mode() const; - - void set_particles_animation(bool p_particles_anim); - bool get_particles_animation() const; - - void set_particles_anim_h_frames(int p_frames); - int get_particles_anim_h_frames() const; - void set_particles_anim_v_frames(int p_frames); - int get_particles_anim_v_frames() const; - - void set_particles_anim_loop(bool p_loop); - bool get_particles_anim_loop() const; - - static void init_shaders(); - static void finish_shaders(); - static void flush_changes(); - - RID get_shader_rid() const; - - virtual Shader::Mode get_shader_mode() const; - - CanvasItemMaterial(); - virtual ~CanvasItemMaterial(); -}; - -VARIANT_ENUM_CAST(CanvasItemMaterial::BlendMode) -VARIANT_ENUM_CAST(CanvasItemMaterial::LightMode) - -class CanvasItem : public Node { - - GDCLASS(CanvasItem, Node); - -public: - enum TextureFilter { - TEXTURE_FILTER_PARENT_NODE, - TEXTURE_FILTER_NEAREST, - TEXTURE_FILTER_LINEAR, - TEXTURE_FILTER_NEAREST_WITH_MIPMAPS, - TEXTURE_FILTER_LINEAR_WITH_MIPMAPS, - TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC, - TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC, - TEXTURE_FILTER_MAX - }; - - enum TextureRepeat { - TEXTURE_REPEAT_PARENT_NODE, - TEXTURE_REPEAT_DISABLED, - TEXTURE_REPEAT_ENABLED, - TEXTURE_REPEAT_MIRROR, - TEXTURE_REPEAT_MAX, - }; - -private: - mutable SelfList<Node> xform_change; - - RID canvas_item; - String group; - - CanvasLayer *canvas_layer; - - Color modulate; - Color self_modulate; - - List<CanvasItem *> children_items; - List<CanvasItem *>::Element *C; - - int light_mask; - - bool first_draw; - bool visible; - bool pending_update; - bool toplevel; - bool drawing; - bool block_transform_notify; - bool behind; - bool use_parent_material; - bool notify_local_transform; - bool notify_transform; - - VS::CanvasItemTextureFilter texture_filter_cache; - VS::CanvasItemTextureRepeat texture_repeat_cache; - - TextureFilter texture_filter; - TextureRepeat texture_repeat; - - Ref<Material> material; - - mutable Transform2D global_transform; - mutable bool global_invalid; - - void _toplevel_raise_self(); - - void _propagate_visibility_changed(bool p_visible); - - void _update_callback(); - - void _enter_canvas(); - void _exit_canvas(); - - void _notify_transform(CanvasItem *p_node); - - void _set_on_top(bool p_on_top) { set_draw_behind_parent(!p_on_top); } - bool _is_on_top() const { return !is_draw_behind_parent_enabled(); } - - static CanvasItem *current_item_drawn; - friend class Viewport; - void _update_texture_repeat_changed(bool p_propagate); - void _update_texture_filter_changed(bool p_propagate); - -protected: - _FORCE_INLINE_ void _notify_transform() { - if (!is_inside_tree()) return; - _notify_transform(this); - if (!block_transform_notify && notify_local_transform) notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED); - } - - void item_rect_changed(bool p_size_changed = true); - - void _notification(int p_what); - static void _bind_methods(); - -public: - enum { - NOTIFICATION_TRANSFORM_CHANGED = SceneTree::NOTIFICATION_TRANSFORM_CHANGED, //unique - NOTIFICATION_DRAW = 30, - NOTIFICATION_VISIBILITY_CHANGED = 31, - NOTIFICATION_ENTER_CANVAS = 32, - NOTIFICATION_EXIT_CANVAS = 33, - NOTIFICATION_LOCAL_TRANSFORM_CHANGED = 35, - NOTIFICATION_WORLD_2D_CHANGED = 36, - - }; - - /* EDITOR */ -#ifdef TOOLS_ENABLED - // Select the node - virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; - - // Save and restore a CanvasItem state - virtual void _edit_set_state(const Dictionary &p_state){}; - virtual Dictionary _edit_get_state() const { return Dictionary(); }; - - // Used to move the node - virtual void _edit_set_position(const Point2 &p_position) = 0; - virtual Point2 _edit_get_position() const = 0; - - // Used to scale the node - virtual void _edit_set_scale(const Size2 &p_scale) = 0; - virtual Size2 _edit_get_scale() const = 0; - - // Used to rotate the node - virtual bool _edit_use_rotation() const { return false; }; - virtual void _edit_set_rotation(float p_rotation){}; - virtual float _edit_get_rotation() const { return 0.0; }; - - // Used to resize/move the node - virtual bool _edit_use_rect() const { return false; }; // MAYBE REPLACE BY A _edit_get_editmode() - virtual void _edit_set_rect(const Rect2 &p_rect){}; - virtual Rect2 _edit_get_rect() const { return Rect2(0, 0, 0, 0); }; - virtual Size2 _edit_get_minimum_size() const { return Size2(-1, -1); }; // LOOKS WEIRD - - // Used to set a pivot - virtual bool _edit_use_pivot() const { return false; }; - virtual void _edit_set_pivot(const Point2 &p_pivot){}; - virtual Point2 _edit_get_pivot() const { return Point2(); }; - - virtual Transform2D _edit_get_transform() const; -#endif - - /* VISIBILITY */ - - void set_visible(bool p_visible); - bool is_visible() const; - bool is_visible_in_tree() const; - void show(); - void hide(); - - void update(); - - virtual void set_light_mask(int p_light_mask); - int get_light_mask() const; - - void set_modulate(const Color &p_modulate); - Color get_modulate() const; - - void set_self_modulate(const Color &p_self_modulate); - Color get_self_modulate() const; - - /* DRAWING API */ - - void draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width = 1.0); - void draw_polyline(const Vector<Point2> &p_points, const Color &p_color, float p_width = 1.0); - void draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width = 1.0); - void draw_arc(const Vector2 &p_center, float p_radius, float p_start_angle, float p_end_angle, int p_point_count, const Color &p_color, float p_width = 1.0); - void draw_multiline(const Vector<Point2> &p_points, const Color &p_color, float p_width = 1.0); - void draw_multiline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width = 1.0); - void draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled = true, float p_width = 1.0); - void draw_circle(const Point2 &p_pos, float p_radius, const Color &p_color); - void draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1, 1), const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE); - void draw_texture_rect(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE); - void draw_texture_rect_region(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), bool p_clip_uv = false, TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE); - void draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect); - void draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture2D> p_texture = Ref<Texture2D>(), float p_width = 1, const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE); - void draw_polygon(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), Ref<Texture2D> p_texture = Ref<Texture2D>(), const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE); - void draw_colored_polygon(const Vector<Point2> &p_points, const Color &p_color, const Vector<Point2> &p_uvs = Vector<Point2>(), Ref<Texture2D> p_texture = Ref<Texture2D>(), const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE); - - void draw_mesh(const Ref<Mesh> &p_mesh, const Ref<Texture2D> &p_texture, const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), const Transform2D &p_transform = Transform2D(), const Color &p_modulate = Color(1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE); - void draw_multimesh(const Ref<MultiMesh> &p_multimesh, const Ref<Texture2D> &p_texture, const Ref<Texture2D> &p_normal_map = Ref<Texture2D>(), const Ref<Texture2D> &p_specular_map = Ref<Texture2D>(), const Color &p_specular_color_shininess = Color(1, 1, 1, 1), TextureFilter p_texture_filter = TEXTURE_FILTER_PARENT_NODE, TextureRepeat p_texture_repeat = TEXTURE_REPEAT_PARENT_NODE); - - void draw_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, const Color &p_modulate = Color(1, 1, 1), int p_clip_w = -1); - float draw_char(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, const String &p_next = "", const Color &p_modulate = Color(1, 1, 1)); - - void draw_set_transform(const Point2 &p_offset, float p_rot, const Size2 &p_scale); - void draw_set_transform_matrix(const Transform2D &p_matrix); - - static CanvasItem *get_current_item_drawn(); - - /* RECT / TRANSFORM */ - - void set_as_toplevel(bool p_toplevel); - bool is_set_as_toplevel() const; - - void set_draw_behind_parent(bool p_enable); - bool is_draw_behind_parent_enabled() const; - - CanvasItem *get_parent_item() const; - - virtual Transform2D get_transform() const = 0; - - virtual Transform2D get_global_transform() const; - virtual Transform2D get_global_transform_with_canvas() const; - - CanvasItem *get_toplevel() const; - _FORCE_INLINE_ RID get_canvas_item() const { - return canvas_item; - } - - void set_block_transform_notify(bool p_enable); - bool is_block_transform_notify_enabled() const; - - Transform2D get_canvas_transform() const; - Transform2D get_viewport_transform() const; - Rect2 get_viewport_rect() const; - RID get_viewport_rid() const; - RID get_canvas() const; - ObjectID get_canvas_layer_instance_id() const; - Ref<World2D> get_world_2d() const; - - virtual void set_material(const Ref<Material> &p_material); - Ref<Material> get_material() const; - - virtual void set_use_parent_material(bool p_use_parent_material); - bool get_use_parent_material() const; - - Ref<InputEvent> make_input_local(const Ref<InputEvent> &p_event) const; - Vector2 make_canvas_position_local(const Vector2 &screen_point) const; - - Vector2 get_global_mouse_position() const; - Vector2 get_local_mouse_position() const; - - void set_notify_local_transform(bool p_enable); - bool is_local_transform_notification_enabled() const; - - void set_notify_transform(bool p_enable); - bool is_transform_notification_enabled() const; - - void force_update_transform(); - - void set_texture_filter(TextureFilter p_texture_filter); - TextureFilter get_texture_filter() const; - - void set_texture_repeat(TextureRepeat p_texture_repeat); - TextureRepeat get_texture_repeat() const; - - // Used by control nodes to retrieve the parent's anchorable area - virtual Rect2 get_anchorable_rect() const { return Rect2(0, 0, 0, 0); }; - - int get_canvas_layer() const; - - CanvasItem(); - ~CanvasItem(); -}; - -VARIANT_ENUM_CAST(CanvasItem::TextureFilter) -VARIANT_ENUM_CAST(CanvasItem::TextureRepeat) - -#endif // CANVAS_ITEM_H diff --git a/scene/2d/canvas_modulate.cpp b/scene/2d/canvas_modulate.cpp index 25db434918..05f8804e2a 100644 --- a/scene/2d/canvas_modulate.cpp +++ b/scene/2d/canvas_modulate.cpp @@ -35,23 +35,23 @@ void CanvasModulate::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_CANVAS) { if (is_visible_in_tree()) { - VS::get_singleton()->canvas_set_modulate(get_canvas(), color); + 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()) { - VS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1)); + 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()) { - VS::get_singleton()->canvas_set_modulate(get_canvas(), color); + RS::get_singleton()->canvas_set_modulate(get_canvas(), color); add_to_group("_canvas_modulate_" + itos(get_canvas().get_id())); } else { - VS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1)); + RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1)); remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id())); } @@ -71,7 +71,7 @@ void CanvasModulate::set_color(const Color &p_color) { color = p_color; if (is_visible_in_tree()) { - VS::get_singleton()->canvas_set_modulate(get_canvas(), color); + RS::get_singleton()->canvas_set_modulate(get_canvas(), color); } } Color CanvasModulate::get_color() const { diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index 4af2e846f7..d82f4a2f2b 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -31,7 +31,7 @@ #include "collision_object_2d.h" #include "scene/scene_string_names.h" -#include "servers/physics_2d_server.h" +#include "servers/physics_server_2d.h" void CollisionObject2D::_notification(int p_what) { @@ -42,15 +42,15 @@ void CollisionObject2D::_notification(int p_what) { Transform2D global_transform = get_global_transform(); if (area) - Physics2DServer::get_singleton()->area_set_transform(rid, global_transform); + PhysicsServer2D::get_singleton()->area_set_transform(rid, global_transform); else - Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform); + PhysicsServer2D::get_singleton()->body_set_state(rid, PhysicsServer2D::BODY_STATE_TRANSFORM, global_transform); RID space = get_world_2d()->get_space(); if (area) { - Physics2DServer::get_singleton()->area_set_space(rid, space); + PhysicsServer2D::get_singleton()->area_set_space(rid, space); } else - Physics2DServer::get_singleton()->body_set_space(rid, space); + PhysicsServer2D::get_singleton()->body_set_space(rid, space); _update_pickable(); @@ -60,9 +60,9 @@ void CollisionObject2D::_notification(int p_what) { case NOTIFICATION_ENTER_CANVAS: { if (area) - Physics2DServer::get_singleton()->area_attach_canvas_instance_id(rid, get_canvas_layer_instance_id()); + PhysicsServer2D::get_singleton()->area_attach_canvas_instance_id(rid, get_canvas_layer_instance_id()); else - Physics2DServer::get_singleton()->body_attach_canvas_instance_id(rid, get_canvas_layer_instance_id()); + PhysicsServer2D::get_singleton()->body_attach_canvas_instance_id(rid, get_canvas_layer_instance_id()); } break; case NOTIFICATION_VISIBILITY_CHANGED: { @@ -78,26 +78,26 @@ void CollisionObject2D::_notification(int p_what) { Transform2D global_transform = get_global_transform(); if (area) - Physics2DServer::get_singleton()->area_set_transform(rid, global_transform); + PhysicsServer2D::get_singleton()->area_set_transform(rid, global_transform); else - Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform); + PhysicsServer2D::get_singleton()->body_set_state(rid, PhysicsServer2D::BODY_STATE_TRANSFORM, global_transform); } break; case NOTIFICATION_EXIT_TREE: { if (area) { - Physics2DServer::get_singleton()->area_set_space(rid, RID()); + PhysicsServer2D::get_singleton()->area_set_space(rid, RID()); } else - Physics2DServer::get_singleton()->body_set_space(rid, RID()); + PhysicsServer2D::get_singleton()->body_set_space(rid, RID()); } break; case NOTIFICATION_EXIT_CANVAS: { if (area) - Physics2DServer::get_singleton()->area_attach_canvas_instance_id(rid, ObjectID()); + PhysicsServer2D::get_singleton()->area_attach_canvas_instance_id(rid, ObjectID()); else - Physics2DServer::get_singleton()->body_attach_canvas_instance_id(rid, ObjectID()); + PhysicsServer2D::get_singleton()->body_attach_canvas_instance_id(rid, ObjectID()); } break; } } @@ -136,9 +136,9 @@ void CollisionObject2D::shape_owner_set_disabled(uint32_t p_owner, bool p_disabl sd.disabled = p_disabled; for (int i = 0; i < sd.shapes.size(); i++) { if (area) { - Physics2DServer::get_singleton()->area_set_shape_disabled(rid, sd.shapes[i].index, p_disabled); + PhysicsServer2D::get_singleton()->area_set_shape_disabled(rid, sd.shapes[i].index, p_disabled); } else { - Physics2DServer::get_singleton()->body_set_shape_disabled(rid, sd.shapes[i].index, p_disabled); + PhysicsServer2D::get_singleton()->body_set_shape_disabled(rid, sd.shapes[i].index, p_disabled); } } } @@ -160,7 +160,7 @@ void CollisionObject2D::shape_owner_set_one_way_collision(uint32_t p_owner, bool ShapeData &sd = shapes[p_owner]; sd.one_way_collision = p_enable; for (int i = 0; i < sd.shapes.size(); i++) { - Physics2DServer::get_singleton()->body_set_shape_as_one_way_collision(rid, sd.shapes[i].index, sd.one_way_collision, sd.one_way_collision_margin); + PhysicsServer2D::get_singleton()->body_set_shape_as_one_way_collision(rid, sd.shapes[i].index, sd.one_way_collision, sd.one_way_collision_margin); } } @@ -181,7 +181,7 @@ void CollisionObject2D::shape_owner_set_one_way_collision_margin(uint32_t p_owne ShapeData &sd = shapes[p_owner]; sd.one_way_collision_margin = p_margin; for (int i = 0; i < sd.shapes.size(); i++) { - Physics2DServer::get_singleton()->body_set_shape_as_one_way_collision(rid, sd.shapes[i].index, sd.one_way_collision, sd.one_way_collision_margin); + PhysicsServer2D::get_singleton()->body_set_shape_as_one_way_collision(rid, sd.shapes[i].index, sd.one_way_collision, sd.one_way_collision_margin); } } @@ -218,9 +218,9 @@ void CollisionObject2D::shape_owner_set_transform(uint32_t p_owner, const Transf sd.xform = p_transform; for (int i = 0; i < sd.shapes.size(); i++) { if (area) { - Physics2DServer::get_singleton()->area_set_shape_transform(rid, sd.shapes[i].index, sd.xform); + PhysicsServer2D::get_singleton()->area_set_shape_transform(rid, sd.shapes[i].index, sd.xform); } else { - Physics2DServer::get_singleton()->body_set_shape_transform(rid, sd.shapes[i].index, sd.xform); + PhysicsServer2D::get_singleton()->body_set_shape_transform(rid, sd.shapes[i].index, sd.xform); } } } @@ -233,7 +233,7 @@ Transform2D CollisionObject2D::shape_owner_get_transform(uint32_t p_owner) const Object *CollisionObject2D::shape_owner_get_owner(uint32_t p_owner) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), NULL); + ERR_FAIL_COND_V(!shapes.has(p_owner), nullptr); return shapes[p_owner].owner; } @@ -248,9 +248,9 @@ void CollisionObject2D::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape2 s.index = total_subshapes; s.shape = p_shape; if (area) { - Physics2DServer::get_singleton()->area_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled); + PhysicsServer2D::get_singleton()->area_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled); } else { - Physics2DServer::get_singleton()->body_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled); + PhysicsServer2D::get_singleton()->body_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled); } sd.shapes.push_back(s); @@ -284,9 +284,9 @@ void CollisionObject2D::shape_owner_remove_shape(uint32_t p_owner, int p_shape) int index_to_remove = shapes[p_owner].shapes[p_shape].index; if (area) { - Physics2DServer::get_singleton()->area_remove_shape(rid, index_to_remove); + PhysicsServer2D::get_singleton()->area_remove_shape(rid, index_to_remove); } else { - Physics2DServer::get_singleton()->body_remove_shape(rid, index_to_remove); + PhysicsServer2D::get_singleton()->body_remove_shape(rid, index_to_remove); } shapes[p_owner].shapes.remove(p_shape); @@ -375,9 +375,9 @@ void CollisionObject2D::_update_pickable() { bool is_pickable = pickable && is_visible_in_tree(); if (area) - Physics2DServer::get_singleton()->area_set_pickable(rid, is_pickable); + PhysicsServer2D::get_singleton()->area_set_pickable(rid, is_pickable); else - Physics2DServer::get_singleton()->body_set_pickable(rid, is_pickable); + PhysicsServer2D::get_singleton()->body_set_pickable(rid, is_pickable); } String CollisionObject2D::get_configuration_warning() const { @@ -442,9 +442,9 @@ CollisionObject2D::CollisionObject2D(RID p_rid, bool p_area) { if (p_area) { - Physics2DServer::get_singleton()->area_attach_object_instance_id(rid, get_instance_id()); + PhysicsServer2D::get_singleton()->area_attach_object_instance_id(rid, get_instance_id()); } else { - Physics2DServer::get_singleton()->body_attach_object_instance_id(rid, get_instance_id()); + PhysicsServer2D::get_singleton()->body_attach_object_instance_id(rid, get_instance_id()); } } @@ -457,5 +457,5 @@ CollisionObject2D::CollisionObject2D() { CollisionObject2D::~CollisionObject2D() { - Physics2DServer::get_singleton()->free(rid); + PhysicsServer2D::get_singleton()->free(rid); } diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h index 8874f61bb7..e931f20f40 100644 --- a/scene/2d/collision_object_2d.h +++ b/scene/2d/collision_object_2d.h @@ -60,7 +60,7 @@ class CollisionObject2D : public Node2D { disabled = false; one_way_collision = false; one_way_collision_margin = 0; - owner = NULL; + owner = nullptr; } }; diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index 4edf92197e..1e48b2d67f 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -50,7 +50,7 @@ void CollisionPolygon2D::_build_polygon() { //here comes the sun, lalalala //decompose concave into multiple convex polygons and add them - Vector<Vector<Vector2> > decomp = _decompose_in_convex(); + Vector<Vector<Vector2>> decomp = _decompose_in_convex(); for (int i = 0; i < decomp.size(); i++) { Ref<ConvexPolygonShape2D> convex = memnew(ConvexPolygonShape2D); convex->set_points(decomp[i]); @@ -76,8 +76,8 @@ void CollisionPolygon2D::_build_polygon() { } } -Vector<Vector<Vector2> > CollisionPolygon2D::_decompose_in_convex() { - Vector<Vector<Vector2> > decomp = Geometry::decompose_polygon_in_convex(polygon); +Vector<Vector<Vector2>> CollisionPolygon2D::_decompose_in_convex() { + Vector<Vector<Vector2>> decomp = Geometry::decompose_polygon_in_convex(polygon); return decomp; } @@ -106,7 +106,7 @@ void CollisionPolygon2D::_notification(int p_what) { /*if (Engine::get_singleton()->is_editor_hint()) { //display above all else set_z_as_relative(false); - set_z_index(VS::CANVAS_ITEM_Z_MAX - 1); + set_z_index(RS::CANVAS_ITEM_Z_MAX - 1); }*/ } break; @@ -129,7 +129,7 @@ void CollisionPolygon2D::_notification(int p_what) { parent->remove_shape_owner(owner_id); } owner_id = 0; - parent = NULL; + parent = nullptr; } break; case NOTIFICATION_DRAW: { @@ -148,7 +148,7 @@ void CollisionPolygon2D::_notification(int p_what) { #define DEBUG_DECOMPOSE #if defined(TOOLS_ENABLED) && defined(DEBUG_DECOMPOSE) - Vector<Vector<Vector2> > decomp = _decompose_in_convex(); + Vector<Vector<Vector2>> decomp = _decompose_in_convex(); Color c(0.4, 0.9, 0.1); for (int i = 0; i < decomp.size(); i++) { @@ -319,7 +319,7 @@ CollisionPolygon2D::CollisionPolygon2D() { aabb = Rect2(-10, -10, 20, 20); build_mode = BUILD_SOLIDS; set_notify_local_transform(true); - parent = NULL; + parent = nullptr; owner_id = 0; disabled = false; one_way_collision = false; diff --git a/scene/2d/collision_polygon_2d.h b/scene/2d/collision_polygon_2d.h index d8dfec8fd2..92a2758813 100644 --- a/scene/2d/collision_polygon_2d.h +++ b/scene/2d/collision_polygon_2d.h @@ -56,7 +56,7 @@ protected: bool one_way_collision; float one_way_collision_margin; - Vector<Vector<Vector2> > _decompose_in_convex(); + Vector<Vector<Vector2>> _decompose_in_convex(); void _build_polygon(); diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index b2ad040654..b1dbc57c94 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -73,7 +73,7 @@ void CollisionShape2D::_notification(int p_what) { /*if (Engine::get_singleton()->is_editor_hint()) { //display above all else set_z_as_relative(false); - set_z_index(VS::CANVAS_ITEM_Z_MAX - 1); + set_z_index(RS::CANVAS_ITEM_Z_MAX - 1); }*/ } break; @@ -96,7 +96,7 @@ void CollisionShape2D::_notification(int p_what) { parent->remove_shape_owner(owner_id); } owner_id = 0; - parent = NULL; + parent = nullptr; } break; case NOTIFICATION_DRAW: { @@ -249,7 +249,7 @@ CollisionShape2D::CollisionShape2D() { rect = Rect2(-Point2(10, 10), Point2(20, 20)); set_notify_local_transform(true); owner_id = 0; - parent = NULL; + parent = nullptr; disabled = false; one_way_collision = false; one_way_collision_margin = 1.0; diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index 3b8a81d2ca..0a6b091a51 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -31,10 +31,10 @@ #include "cpu_particles_2d.h" #include "core/core_string_names.h" -#include "scene/2d/canvas_item.h" -#include "scene/2d/particles_2d.h" +#include "scene/2d/gpu_particles_2d.h" +#include "scene/main/canvas_item.h" #include "scene/resources/particles_material.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" void CPUParticles2D::set_emitting(bool p_emitting) { @@ -60,7 +60,7 @@ void CPUParticles2D::set_amount(int p_amount) { } particle_data.resize((8 + 4 + 4) * p_amount); - VS::get_singleton()->multimesh_allocate(multimesh, p_amount, VS::MULTIMESH_TRANSFORM_2D, true, true); + RS::get_singleton()->multimesh_allocate(multimesh, p_amount, RS::MULTIMESH_TRANSFORM_2D, true, true); particle_order.resize(p_amount); } @@ -198,14 +198,14 @@ void CPUParticles2D::_update_mesh_texture() { indices.push_back(0); Array arr; - arr.resize(VS::ARRAY_MAX); - arr[VS::ARRAY_VERTEX] = vertices; - arr[VS::ARRAY_TEX_UV] = uvs; - arr[VS::ARRAY_COLOR] = colors; - arr[VS::ARRAY_INDEX] = indices; + arr.resize(RS::ARRAY_MAX); + arr[RS::ARRAY_VERTEX] = vertices; + arr[RS::ARRAY_TEX_UV] = uvs; + arr[RS::ARRAY_COLOR] = colors; + arr[RS::ARRAY_INDEX] = indices; - VS::get_singleton()->mesh_clear(mesh); - VS::get_singleton()->mesh_add_surface_from_arrays(mesh, VS::PRIMITIVE_TRIANGLES, arr); + RS::get_singleton()->mesh_clear(mesh); + RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr); } void CPUParticles2D::set_texture(const Ref<Texture2D> &p_texture) { @@ -976,7 +976,7 @@ void CPUParticles2D::_update_particle_data_buffer() { int pc = particles.size(); int *ow; - int *order = NULL; + int *order = nullptr; float *w = particle_data.ptrw(); const Particle *r = particles.ptr(); @@ -1046,17 +1046,17 @@ void CPUParticles2D::_set_redraw(bool p_redraw) { MutexLock lock(update_mutex); if (redraw) { - VS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &CPUParticles2D::_update_render_thread)); - VS::get_singleton()->canvas_item_set_update_when_visible(get_canvas_item(), true); + RS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &CPUParticles2D::_update_render_thread)); + RS::get_singleton()->canvas_item_set_update_when_visible(get_canvas_item(), true); - VS::get_singleton()->multimesh_set_visible_instances(multimesh, -1); + RS::get_singleton()->multimesh_set_visible_instances(multimesh, -1); } else { - if (VS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &CPUParticles2D::_update_render_thread))) { - VS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &CPUParticles2D::_update_render_thread)); + if (RS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &CPUParticles2D::_update_render_thread))) { + RS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &CPUParticles2D::_update_render_thread)); } - VS::get_singleton()->canvas_item_set_update_when_visible(get_canvas_item(), false); + RS::get_singleton()->canvas_item_set_update_when_visible(get_canvas_item(), false); - VS::get_singleton()->multimesh_set_visible_instances(multimesh, 0); + RS::get_singleton()->multimesh_set_visible_instances(multimesh, 0); } } @@ -1067,7 +1067,7 @@ void CPUParticles2D::_update_render_thread() { MutexLock lock(update_mutex); - VS::get_singleton()->multimesh_set_buffer(multimesh, particle_data); + RS::get_singleton()->multimesh_set_buffer(multimesh, particle_data); } void CPUParticles2D::_notification(int p_what) { @@ -1098,7 +1098,7 @@ void CPUParticles2D::_notification(int p_what) { normrid = normalmap->get_rid(); } - VS::get_singleton()->canvas_item_add_multimesh(get_canvas_item(), multimesh, texrid, normrid); + RS::get_singleton()->canvas_item_add_multimesh(get_canvas_item(), multimesh, texrid, normrid); } if (p_what == NOTIFICATION_INTERNAL_PROCESS) { @@ -1144,8 +1144,8 @@ void CPUParticles2D::_notification(int p_what) { void CPUParticles2D::convert_from_particles(Node *p_particles) { - Particles2D *particles = Object::cast_to<Particles2D>(p_particles); - ERR_FAIL_COND_MSG(!particles, "Only Particles2D nodes can be converted to CPUParticles2D."); + GPUParticles2D *particles = Object::cast_to<GPUParticles2D>(p_particles); + ERR_FAIL_COND_MSG(!particles, "Only GPUParticles2D nodes can be converted to CPUParticles2D."); set_emitting(particles->is_emitting()); set_amount(particles->get_amount()); @@ -1428,9 +1428,9 @@ CPUParticles2D::CPUParticles2D() { redraw = false; emitting = false; - mesh = VisualServer::get_singleton()->mesh_create(); - multimesh = VisualServer::get_singleton()->multimesh_create(); - VisualServer::get_singleton()->multimesh_set_mesh(multimesh, mesh); + mesh = RenderingServer::get_singleton()->mesh_create(); + multimesh = RenderingServer::get_singleton()->multimesh_create(); + RenderingServer::get_singleton()->multimesh_set_mesh(multimesh, mesh); set_emitting(true); set_one_shot(false); @@ -1481,6 +1481,6 @@ CPUParticles2D::CPUParticles2D() { } CPUParticles2D::~CPUParticles2D() { - VS::get_singleton()->free(multimesh); - VS::get_singleton()->free(mesh); + RS::get_singleton()->free(multimesh); + RS::get_singleton()->free(mesh); } diff --git a/scene/2d/particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp index 2ba2fd8f79..de3f8fa09e 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/gpu_particles_2d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* particles_2d.cpp */ +/* gpu_particles_2d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "particles_2d.h" +#include "gpu_particles_2d.h" #include "core/os/os.h" #include "scene/resources/particles_material.h" @@ -38,9 +38,9 @@ #include "core/engine.h" #endif -void Particles2D::set_emitting(bool p_emitting) { +void GPUParticles2D::set_emitting(bool p_emitting) { - VS::get_singleton()->particles_set_emitting(particles, p_emitting); + RS::get_singleton()->particles_set_emitting(particles, p_emitting); if (p_emitting && one_shot) { set_process_internal(true); @@ -49,50 +49,50 @@ void Particles2D::set_emitting(bool p_emitting) { } } -void Particles2D::set_amount(int p_amount) { +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; - VS::get_singleton()->particles_set_amount(particles, amount); + RS::get_singleton()->particles_set_amount(particles, amount); } -void Particles2D::set_lifetime(float p_lifetime) { +void GPUParticles2D::set_lifetime(float p_lifetime) { ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0."); lifetime = p_lifetime; - VS::get_singleton()->particles_set_lifetime(particles, lifetime); + RS::get_singleton()->particles_set_lifetime(particles, lifetime); } -void Particles2D::set_one_shot(bool p_enable) { +void GPUParticles2D::set_one_shot(bool p_enable) { one_shot = p_enable; - VS::get_singleton()->particles_set_one_shot(particles, one_shot); + RS::get_singleton()->particles_set_one_shot(particles, one_shot); if (is_emitting()) { set_process_internal(true); if (!one_shot) - VisualServer::get_singleton()->particles_restart(particles); + RenderingServer::get_singleton()->particles_restart(particles); } if (!one_shot) set_process_internal(false); } -void Particles2D::set_pre_process_time(float p_time) { +void GPUParticles2D::set_pre_process_time(float p_time) { pre_process_time = p_time; - VS::get_singleton()->particles_set_pre_process_time(particles, pre_process_time); + RS::get_singleton()->particles_set_pre_process_time(particles, pre_process_time); } -void Particles2D::set_explosiveness_ratio(float p_ratio) { +void GPUParticles2D::set_explosiveness_ratio(float p_ratio) { explosiveness_ratio = p_ratio; - VS::get_singleton()->particles_set_explosiveness_ratio(particles, explosiveness_ratio); + RS::get_singleton()->particles_set_explosiveness_ratio(particles, explosiveness_ratio); } -void Particles2D::set_randomness_ratio(float p_ratio) { +void GPUParticles2D::set_randomness_ratio(float p_ratio) { randomness_ratio = p_ratio; - VS::get_singleton()->particles_set_randomness_ratio(particles, randomness_ratio); + RS::get_singleton()->particles_set_randomness_ratio(particles, randomness_ratio); } -void Particles2D::set_visibility_rect(const Rect2 &p_visibility_rect) { +void GPUParticles2D::set_visibility_rect(const Rect2 &p_visibility_rect) { visibility_rect = p_visibility_rect; AABB aabb; @@ -101,22 +101,22 @@ void Particles2D::set_visibility_rect(const Rect2 &p_visibility_rect) { aabb.size.x = p_visibility_rect.size.x; aabb.size.y = p_visibility_rect.size.y; - VS::get_singleton()->particles_set_custom_aabb(particles, aabb); + RS::get_singleton()->particles_set_custom_aabb(particles, aabb); _change_notify("visibility_rect"); update(); } -void Particles2D::set_use_local_coordinates(bool p_enable) { +void GPUParticles2D::set_use_local_coordinates(bool p_enable) { local_coords = p_enable; - VS::get_singleton()->particles_set_use_local_coordinates(particles, local_coords); + RS::get_singleton()->particles_set_use_local_coordinates(particles, local_coords); set_notify_transform(!p_enable); if (!p_enable && is_inside_tree()) { _update_particle_emission_transform(); } } -void Particles2D::_update_particle_emission_transform() { +void GPUParticles2D::_update_particle_emission_transform() { Transform2D xf2d = get_global_transform(); Transform xf; @@ -124,10 +124,10 @@ void Particles2D::_update_particle_emission_transform() { xf.basis.set_axis(1, Vector3(xf2d.get_axis(1).x, xf2d.get_axis(1).y, 0)); xf.set_origin(Vector3(xf2d.get_origin().x, xf2d.get_origin().y, 0)); - VS::get_singleton()->particles_set_emission_transform(particles, xf); + RS::get_singleton()->particles_set_emission_transform(particles, xf); } -void Particles2D::set_process_material(const Ref<Material> &p_material) { +void GPUParticles2D::set_process_material(const Ref<Material> &p_material) { process_material = p_material; Ref<ParticlesMaterial> pm = p_material; @@ -139,97 +139,97 @@ void Particles2D::set_process_material(const Ref<Material> &p_material) { RID material_rid; if (process_material.is_valid()) material_rid = process_material->get_rid(); - VS::get_singleton()->particles_set_process_material(particles, material_rid); + RS::get_singleton()->particles_set_process_material(particles, material_rid); update_configuration_warning(); } -void Particles2D::set_speed_scale(float p_scale) { +void GPUParticles2D::set_speed_scale(float p_scale) { speed_scale = p_scale; - VS::get_singleton()->particles_set_speed_scale(particles, p_scale); + RS::get_singleton()->particles_set_speed_scale(particles, p_scale); } -bool Particles2D::is_emitting() const { +bool GPUParticles2D::is_emitting() const { - return VS::get_singleton()->particles_get_emitting(particles); + return RS::get_singleton()->particles_get_emitting(particles); } -int Particles2D::get_amount() const { +int GPUParticles2D::get_amount() const { return amount; } -float Particles2D::get_lifetime() const { +float GPUParticles2D::get_lifetime() const { return lifetime; } -bool Particles2D::get_one_shot() const { +bool GPUParticles2D::get_one_shot() const { return one_shot; } -float Particles2D::get_pre_process_time() const { +float GPUParticles2D::get_pre_process_time() const { return pre_process_time; } -float Particles2D::get_explosiveness_ratio() const { +float GPUParticles2D::get_explosiveness_ratio() const { return explosiveness_ratio; } -float Particles2D::get_randomness_ratio() const { +float GPUParticles2D::get_randomness_ratio() const { return randomness_ratio; } -Rect2 Particles2D::get_visibility_rect() const { +Rect2 GPUParticles2D::get_visibility_rect() const { return visibility_rect; } -bool Particles2D::get_use_local_coordinates() const { +bool GPUParticles2D::get_use_local_coordinates() const { return local_coords; } -Ref<Material> Particles2D::get_process_material() const { +Ref<Material> GPUParticles2D::get_process_material() const { return process_material; } -float Particles2D::get_speed_scale() const { +float GPUParticles2D::get_speed_scale() const { return speed_scale; } -void Particles2D::set_draw_order(DrawOrder p_order) { +void GPUParticles2D::set_draw_order(DrawOrder p_order) { draw_order = p_order; - VS::get_singleton()->particles_set_draw_order(particles, VS::ParticlesDrawOrder(p_order)); + RS::get_singleton()->particles_set_draw_order(particles, RS::ParticlesDrawOrder(p_order)); } -Particles2D::DrawOrder Particles2D::get_draw_order() const { +GPUParticles2D::DrawOrder GPUParticles2D::get_draw_order() const { return draw_order; } -void Particles2D::set_fixed_fps(int p_count) { +void GPUParticles2D::set_fixed_fps(int p_count) { fixed_fps = p_count; - VS::get_singleton()->particles_set_fixed_fps(particles, p_count); + RS::get_singleton()->particles_set_fixed_fps(particles, p_count); } -int Particles2D::get_fixed_fps() const { +int GPUParticles2D::get_fixed_fps() const { return fixed_fps; } -void Particles2D::set_fractional_delta(bool p_enable) { +void GPUParticles2D::set_fractional_delta(bool p_enable) { fractional_delta = p_enable; - VS::get_singleton()->particles_set_fractional_delta(particles, p_enable); + RS::get_singleton()->particles_set_fractional_delta(particles, p_enable); } -bool Particles2D::get_fractional_delta() const { +bool GPUParticles2D::get_fractional_delta() const { return fractional_delta; } -String Particles2D::get_configuration_warning() const { +String GPUParticles2D::get_configuration_warning() const { - if (OS::get_singleton()->get_current_video_driver() == OS::VIDEO_DRIVER_GLES2) { - return TTR("GPU-based particles are not supported by the GLES2 video driver.\nUse the CPUParticles2D node instead. You can use the \"Convert to CPUParticles\" option for this purpose."); + 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."); } String warnings; @@ -257,9 +257,9 @@ String Particles2D::get_configuration_warning() const { return warnings; } -Rect2 Particles2D::capture_rect() const { +Rect2 GPUParticles2D::capture_rect() const { - AABB aabb = VS::get_singleton()->particles_get_current_aabb(particles); + AABB aabb = RS::get_singleton()->particles_get_current_aabb(particles); Rect2 r; r.position.x = aabb.position.x; r.position.y = aabb.position.y; @@ -268,34 +268,34 @@ Rect2 Particles2D::capture_rect() const { return r; } -void Particles2D::set_texture(const Ref<Texture2D> &p_texture) { +void GPUParticles2D::set_texture(const Ref<Texture2D> &p_texture) { texture = p_texture; update(); } -Ref<Texture2D> Particles2D::get_texture() const { +Ref<Texture2D> GPUParticles2D::get_texture() const { return texture; } -void Particles2D::set_normal_map(const Ref<Texture2D> &p_normal_map) { +void GPUParticles2D::set_normal_map(const Ref<Texture2D> &p_normal_map) { normal_map = p_normal_map; update(); } -Ref<Texture2D> Particles2D::get_normal_map() const { +Ref<Texture2D> GPUParticles2D::get_normal_map() const { return normal_map; } -void Particles2D::_validate_property(PropertyInfo &property) const { +void GPUParticles2D::_validate_property(PropertyInfo &property) const { } -void Particles2D::restart() { - VS::get_singleton()->particles_restart(particles); - VS::get_singleton()->particles_set_emitting(particles, true); +void GPUParticles2D::restart() { + RS::get_singleton()->particles_restart(particles); + RS::get_singleton()->particles_set_emitting(particles, true); } -void Particles2D::_notification(int p_what) { +void GPUParticles2D::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { @@ -306,7 +306,7 @@ void Particles2D::_notification(int p_what) { if (normal_map.is_valid()) normal_rid = normal_map->get_rid(); - VS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid, normal_rid); + RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid, normal_rid); #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))) { @@ -318,10 +318,10 @@ void Particles2D::_notification(int p_what) { if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) { if (can_process()) { - VS::get_singleton()->particles_set_speed_scale(particles, speed_scale); + RS::get_singleton()->particles_set_speed_scale(particles, speed_scale); } else { - VS::get_singleton()->particles_set_speed_scale(particles, 0); + RS::get_singleton()->particles_set_speed_scale(particles, 0); } } @@ -338,48 +338,48 @@ void Particles2D::_notification(int p_what) { } } -void Particles2D::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &Particles2D::set_emitting); - ClassDB::bind_method(D_METHOD("set_amount", "amount"), &Particles2D::set_amount); - ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &Particles2D::set_lifetime); - ClassDB::bind_method(D_METHOD("set_one_shot", "secs"), &Particles2D::set_one_shot); - ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &Particles2D::set_pre_process_time); - ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &Particles2D::set_explosiveness_ratio); - ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &Particles2D::set_randomness_ratio); - ClassDB::bind_method(D_METHOD("set_visibility_rect", "visibility_rect"), &Particles2D::set_visibility_rect); - ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &Particles2D::set_use_local_coordinates); - ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &Particles2D::set_fixed_fps); - ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &Particles2D::set_fractional_delta); - ClassDB::bind_method(D_METHOD("set_process_material", "material"), &Particles2D::set_process_material); - ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &Particles2D::set_speed_scale); - - ClassDB::bind_method(D_METHOD("is_emitting"), &Particles2D::is_emitting); - ClassDB::bind_method(D_METHOD("get_amount"), &Particles2D::get_amount); - ClassDB::bind_method(D_METHOD("get_lifetime"), &Particles2D::get_lifetime); - ClassDB::bind_method(D_METHOD("get_one_shot"), &Particles2D::get_one_shot); - ClassDB::bind_method(D_METHOD("get_pre_process_time"), &Particles2D::get_pre_process_time); - ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &Particles2D::get_explosiveness_ratio); - ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &Particles2D::get_randomness_ratio); - ClassDB::bind_method(D_METHOD("get_visibility_rect"), &Particles2D::get_visibility_rect); - ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &Particles2D::get_use_local_coordinates); - ClassDB::bind_method(D_METHOD("get_fixed_fps"), &Particles2D::get_fixed_fps); - ClassDB::bind_method(D_METHOD("get_fractional_delta"), &Particles2D::get_fractional_delta); - ClassDB::bind_method(D_METHOD("get_process_material"), &Particles2D::get_process_material); - ClassDB::bind_method(D_METHOD("get_speed_scale"), &Particles2D::get_speed_scale); - - ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &Particles2D::set_draw_order); - ClassDB::bind_method(D_METHOD("get_draw_order"), &Particles2D::get_draw_order); - - ClassDB::bind_method(D_METHOD("set_texture", "texture"), &Particles2D::set_texture); - ClassDB::bind_method(D_METHOD("get_texture"), &Particles2D::get_texture); - - ClassDB::bind_method(D_METHOD("set_normal_map", "texture"), &Particles2D::set_normal_map); - ClassDB::bind_method(D_METHOD("get_normal_map"), &Particles2D::get_normal_map); - - ClassDB::bind_method(D_METHOD("capture_rect"), &Particles2D::capture_rect); - - ClassDB::bind_method(D_METHOD("restart"), &Particles2D::restart); +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); + ClassDB::bind_method(D_METHOD("set_one_shot", "secs"), &GPUParticles2D::set_one_shot); + ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &GPUParticles2D::set_pre_process_time); + ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &GPUParticles2D::set_explosiveness_ratio); + ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &GPUParticles2D::set_randomness_ratio); + ClassDB::bind_method(D_METHOD("set_visibility_rect", "visibility_rect"), &GPUParticles2D::set_visibility_rect); + ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &GPUParticles2D::set_use_local_coordinates); + ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &GPUParticles2D::set_fixed_fps); + ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &GPUParticles2D::set_fractional_delta); + ClassDB::bind_method(D_METHOD("set_process_material", "material"), &GPUParticles2D::set_process_material); + ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &GPUParticles2D::set_speed_scale); + + ClassDB::bind_method(D_METHOD("is_emitting"), &GPUParticles2D::is_emitting); + ClassDB::bind_method(D_METHOD("get_amount"), &GPUParticles2D::get_amount); + ClassDB::bind_method(D_METHOD("get_lifetime"), &GPUParticles2D::get_lifetime); + ClassDB::bind_method(D_METHOD("get_one_shot"), &GPUParticles2D::get_one_shot); + ClassDB::bind_method(D_METHOD("get_pre_process_time"), &GPUParticles2D::get_pre_process_time); + ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &GPUParticles2D::get_explosiveness_ratio); + ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &GPUParticles2D::get_randomness_ratio); + ClassDB::bind_method(D_METHOD("get_visibility_rect"), &GPUParticles2D::get_visibility_rect); + ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &GPUParticles2D::get_use_local_coordinates); + ClassDB::bind_method(D_METHOD("get_fixed_fps"), &GPUParticles2D::get_fixed_fps); + ClassDB::bind_method(D_METHOD("get_fractional_delta"), &GPUParticles2D::get_fractional_delta); + ClassDB::bind_method(D_METHOD("get_process_material"), &GPUParticles2D::get_process_material); + ClassDB::bind_method(D_METHOD("get_speed_scale"), &GPUParticles2D::get_speed_scale); + + ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &GPUParticles2D::set_draw_order); + ClassDB::bind_method(D_METHOD("get_draw_order"), &GPUParticles2D::get_draw_order); + + ClassDB::bind_method(D_METHOD("set_texture", "texture"), &GPUParticles2D::set_texture); + ClassDB::bind_method(D_METHOD("get_texture"), &GPUParticles2D::get_texture); + + ClassDB::bind_method(D_METHOD("set_normal_map", "texture"), &GPUParticles2D::set_normal_map); + ClassDB::bind_method(D_METHOD("get_normal_map"), &GPUParticles2D::get_normal_map); + + ClassDB::bind_method(D_METHOD("capture_rect"), &GPUParticles2D::capture_rect); + + ClassDB::bind_method(D_METHOD("restart"), &GPUParticles2D::restart); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting"), "set_emitting", "is_emitting"); ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_EXP_RANGE, "1,1000000,1"), "set_amount", "get_amount"); @@ -406,9 +406,9 @@ void Particles2D::_bind_methods() { BIND_ENUM_CONSTANT(DRAW_ORDER_LIFETIME); } -Particles2D::Particles2D() { +GPUParticles2D::GPUParticles2D() { - particles = VS::get_singleton()->particles_create(); + particles = RS::get_singleton()->particles_create(); one_shot = false; // Needed so that set_emitting doesn't access uninitialized values set_emitting(true); @@ -426,7 +426,7 @@ Particles2D::Particles2D() { set_speed_scale(1); } -Particles2D::~Particles2D() { +GPUParticles2D::~GPUParticles2D() { - VS::get_singleton()->free(particles); + RS::get_singleton()->free(particles); } diff --git a/scene/2d/particles_2d.h b/scene/2d/gpu_particles_2d.h index 66281d7950..47951d76dc 100644 --- a/scene/2d/particles_2d.h +++ b/scene/2d/gpu_particles_2d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* particles_2d.h */ +/* gpu_particles_2d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -35,9 +35,9 @@ #include "scene/2d/node_2d.h" #include "scene/resources/texture.h" -class Particles2D : public Node2D { +class GPUParticles2D : public Node2D { private: - GDCLASS(Particles2D, Node2D); + GDCLASS(GPUParticles2D, Node2D); public: enum DrawOrder { @@ -118,10 +118,10 @@ public: void restart(); Rect2 capture_rect() const; - Particles2D(); - ~Particles2D(); + GPUParticles2D(); + ~GPUParticles2D(); }; -VARIANT_ENUM_CAST(Particles2D::DrawOrder) +VARIANT_ENUM_CAST(GPUParticles2D::DrawOrder) #endif // PARTICLES_2D_H diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp index 9cc9ab25ac..4d49f4762f 100644 --- a/scene/2d/joints_2d.cpp +++ b/scene/2d/joints_2d.cpp @@ -32,15 +32,15 @@ #include "core/engine.h" #include "physics_body_2d.h" -#include "servers/physics_2d_server.h" +#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) - Physics2DServer::get_singleton()->joint_disable_collisions_between_bodies(joint, false); + PhysicsServer2D::get_singleton()->joint_disable_collisions_between_bodies(joint, false); - Physics2DServer::get_singleton()->free(joint); + PhysicsServer2D::get_singleton()->free(joint); joint = RID(); ba = RID(); bb = RID(); @@ -49,8 +49,8 @@ void Joint2D::_update_joint(bool p_only_free) { if (p_only_free || !is_inside_tree()) return; - Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL; - Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL; + Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)nullptr; + Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)nullptr; if (!node_a || !node_b) return; @@ -66,12 +66,12 @@ void Joint2D::_update_joint(bool p_only_free) { if (!joint.is_valid()) return; - Physics2DServer::get_singleton()->get_singleton()->joint_set_param(joint, Physics2DServer::JOINT_PARAM_BIAS, bias); + PhysicsServer2D::get_singleton()->get_singleton()->joint_set_param(joint, PhysicsServer2D::JOINT_PARAM_BIAS, bias); ba = body_a->get_rid(); bb = body_b->get_rid(); - Physics2DServer::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision); + PhysicsServer2D::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision); } void Joint2D::set_node_a(const NodePath &p_node_a) { @@ -119,7 +119,7 @@ void Joint2D::set_bias(real_t p_bias) { bias = p_bias; if (joint.is_valid()) - Physics2DServer::get_singleton()->get_singleton()->joint_set_param(joint, Physics2DServer::JOINT_PARAM_BIAS, bias); + PhysicsServer2D::get_singleton()->get_singleton()->joint_set_param(joint, PhysicsServer2D::JOINT_PARAM_BIAS, bias); } real_t Joint2D::get_bias() const { @@ -192,8 +192,8 @@ void PinJoint2D::_notification(int p_what) { RID PinJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) { - RID pj = Physics2DServer::get_singleton()->pin_joint_create(get_global_transform().get_origin(), body_a->get_rid(), body_b ? body_b->get_rid() : RID()); - Physics2DServer::get_singleton()->pin_joint_set_param(pj, Physics2DServer::PIN_JOINT_SOFTNESS, softness); + 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; } @@ -202,7 +202,7 @@ void PinJoint2D::set_softness(real_t p_softness) { softness = p_softness; update(); if (get_joint().is_valid()) - Physics2DServer::get_singleton()->pin_joint_set_param(get_joint(), Physics2DServer::PIN_JOINT_SOFTNESS, p_softness); + PhysicsServer2D::get_singleton()->pin_joint_set_param(get_joint(), PhysicsServer2D::PIN_JOINT_SOFTNESS, p_softness); } real_t PinJoint2D::get_softness() const { @@ -253,7 +253,7 @@ RID GrooveJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b Vector2 groove_A2 = gt.xform(Vector2(0, length)); Vector2 anchor_B = gt.xform(Vector2(0, initial_offset)); - return Physics2DServer::get_singleton()->groove_joint_create(groove_A1, groove_A2, anchor_B, body_a->get_rid(), body_b->get_rid()); + return PhysicsServer2D::get_singleton()->groove_joint_create(groove_A1, groove_A2, anchor_B, body_a->get_rid(), body_b->get_rid()); } void GrooveJoint2D::set_length(real_t p_length) { @@ -324,11 +324,11 @@ RID DampedSpringJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D * Vector2 anchor_A = gt.get_origin(); Vector2 anchor_B = gt.xform(Vector2(0, length)); - RID dsj = Physics2DServer::get_singleton()->damped_spring_joint_create(anchor_A, anchor_B, body_a->get_rid(), body_b->get_rid()); + RID dsj = PhysicsServer2D::get_singleton()->damped_spring_joint_create(anchor_A, anchor_B, body_a->get_rid(), body_b->get_rid()); if (rest_length) - Physics2DServer::get_singleton()->damped_string_joint_set_param(dsj, Physics2DServer::DAMPED_STRING_REST_LENGTH, rest_length); - Physics2DServer::get_singleton()->damped_string_joint_set_param(dsj, Physics2DServer::DAMPED_STRING_STIFFNESS, stiffness); - Physics2DServer::get_singleton()->damped_string_joint_set_param(dsj, Physics2DServer::DAMPED_STRING_DAMPING, damping); + PhysicsServer2D::get_singleton()->damped_string_joint_set_param(dsj, PhysicsServer2D::DAMPED_STRING_REST_LENGTH, rest_length); + PhysicsServer2D::get_singleton()->damped_string_joint_set_param(dsj, PhysicsServer2D::DAMPED_STRING_STIFFNESS, stiffness); + PhysicsServer2D::get_singleton()->damped_string_joint_set_param(dsj, PhysicsServer2D::DAMPED_STRING_DAMPING, damping); return dsj; } @@ -349,7 +349,7 @@ void DampedSpringJoint2D::set_rest_length(real_t p_rest_length) { rest_length = p_rest_length; update(); if (get_joint().is_valid()) - Physics2DServer::get_singleton()->damped_string_joint_set_param(get_joint(), Physics2DServer::DAMPED_STRING_REST_LENGTH, p_rest_length ? p_rest_length : length); + PhysicsServer2D::get_singleton()->damped_string_joint_set_param(get_joint(), PhysicsServer2D::DAMPED_STRING_REST_LENGTH, p_rest_length ? p_rest_length : length); } real_t DampedSpringJoint2D::get_rest_length() const { @@ -362,7 +362,7 @@ void DampedSpringJoint2D::set_stiffness(real_t p_stiffness) { stiffness = p_stiffness; update(); if (get_joint().is_valid()) - Physics2DServer::get_singleton()->damped_string_joint_set_param(get_joint(), Physics2DServer::DAMPED_STRING_STIFFNESS, p_stiffness); + PhysicsServer2D::get_singleton()->damped_string_joint_set_param(get_joint(), PhysicsServer2D::DAMPED_STRING_STIFFNESS, p_stiffness); } real_t DampedSpringJoint2D::get_stiffness() const { @@ -375,7 +375,7 @@ void DampedSpringJoint2D::set_damping(real_t p_damping) { damping = p_damping; update(); if (get_joint().is_valid()) - Physics2DServer::get_singleton()->damped_string_joint_set_param(get_joint(), Physics2DServer::DAMPED_STRING_DAMPING, p_damping); + PhysicsServer2D::get_singleton()->damped_string_joint_set_param(get_joint(), PhysicsServer2D::DAMPED_STRING_DAMPING, p_damping); } real_t DampedSpringJoint2D::get_damping() const { diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index e61b1fa339..b3d54b81f8 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -31,7 +31,7 @@ #include "light_2d.h" #include "core/engine.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" #ifdef TOOLS_ENABLED Dictionary Light2D::_edit_get_state() const { @@ -100,7 +100,7 @@ void Light2D::_update_light_visibility() { } #endif - VS::get_singleton()->canvas_light_set_enabled(canvas_light, enabled && is_visible_in_tree() && editor_ok); + RS::get_singleton()->canvas_light_set_enabled(canvas_light, enabled && is_visible_in_tree() && editor_ok); } void Light2D::set_enabled(bool p_enabled) { @@ -129,9 +129,9 @@ void Light2D::set_texture(const Ref<Texture2D> &p_texture) { texture = p_texture; if (texture.is_valid()) - VS::get_singleton()->canvas_light_set_texture(canvas_light, texture->get_rid()); + RS::get_singleton()->canvas_light_set_texture(canvas_light, texture->get_rid()); else - VS::get_singleton()->canvas_light_set_texture(canvas_light, RID()); + RS::get_singleton()->canvas_light_set_texture(canvas_light, RID()); update_configuration_warning(); } @@ -144,7 +144,7 @@ Ref<Texture2D> Light2D::get_texture() const { void Light2D::set_texture_offset(const Vector2 &p_offset) { texture_offset = p_offset; - VS::get_singleton()->canvas_light_set_texture_offset(canvas_light, texture_offset); + RS::get_singleton()->canvas_light_set_texture_offset(canvas_light, texture_offset); item_rect_changed(); _change_notify("offset"); } @@ -157,7 +157,7 @@ Vector2 Light2D::get_texture_offset() const { void Light2D::set_color(const Color &p_color) { color = p_color; - VS::get_singleton()->canvas_light_set_color(canvas_light, color); + RS::get_singleton()->canvas_light_set_color(canvas_light, color); } Color Light2D::get_color() const { @@ -167,7 +167,7 @@ Color Light2D::get_color() const { void Light2D::set_height(float p_height) { height = p_height; - VS::get_singleton()->canvas_light_set_height(canvas_light, height); + RS::get_singleton()->canvas_light_set_height(canvas_light, height); } float Light2D::get_height() const { @@ -178,7 +178,7 @@ float Light2D::get_height() const { void Light2D::set_energy(float p_energy) { energy = p_energy; - VS::get_singleton()->canvas_light_set_energy(canvas_light, energy); + RS::get_singleton()->canvas_light_set_energy(canvas_light, energy); } float Light2D::get_energy() const { @@ -193,7 +193,7 @@ void Light2D::set_texture_scale(float p_scale) { if (_scale == 0) { _scale = CMP_EPSILON; } - VS::get_singleton()->canvas_light_set_scale(canvas_light, _scale); + RS::get_singleton()->canvas_light_set_scale(canvas_light, _scale); item_rect_changed(); } @@ -205,7 +205,7 @@ float Light2D::get_texture_scale() const { void Light2D::set_z_range_min(int p_min_z) { z_min = p_min_z; - VS::get_singleton()->canvas_light_set_z_range(canvas_light, z_min, z_max); + RS::get_singleton()->canvas_light_set_z_range(canvas_light, z_min, z_max); } int Light2D::get_z_range_min() const { @@ -215,7 +215,7 @@ int Light2D::get_z_range_min() const { void Light2D::set_z_range_max(int p_max_z) { z_max = p_max_z; - VS::get_singleton()->canvas_light_set_z_range(canvas_light, z_min, z_max); + RS::get_singleton()->canvas_light_set_z_range(canvas_light, z_min, z_max); } int Light2D::get_z_range_max() const { @@ -225,7 +225,7 @@ int Light2D::get_z_range_max() const { void Light2D::set_layer_range_min(int p_min_layer) { layer_min = p_min_layer; - VS::get_singleton()->canvas_light_set_layer_range(canvas_light, layer_min, layer_max); + RS::get_singleton()->canvas_light_set_layer_range(canvas_light, layer_min, layer_max); } int Light2D::get_layer_range_min() const { @@ -235,7 +235,7 @@ int Light2D::get_layer_range_min() const { void Light2D::set_layer_range_max(int p_max_layer) { layer_max = p_max_layer; - VS::get_singleton()->canvas_light_set_layer_range(canvas_light, layer_min, layer_max); + RS::get_singleton()->canvas_light_set_layer_range(canvas_light, layer_min, layer_max); } int Light2D::get_layer_range_max() const { @@ -245,7 +245,7 @@ int Light2D::get_layer_range_max() const { void Light2D::set_item_cull_mask(int p_mask) { item_mask = p_mask; - VS::get_singleton()->canvas_light_set_item_cull_mask(canvas_light, item_mask); + RS::get_singleton()->canvas_light_set_item_cull_mask(canvas_light, item_mask); } int Light2D::get_item_cull_mask() const { @@ -256,7 +256,7 @@ int Light2D::get_item_cull_mask() const { void Light2D::set_item_shadow_cull_mask(int p_mask) { item_shadow_mask = p_mask; - VS::get_singleton()->canvas_light_set_item_shadow_cull_mask(canvas_light, item_shadow_mask); + RS::get_singleton()->canvas_light_set_item_shadow_cull_mask(canvas_light, item_shadow_mask); } int Light2D::get_item_shadow_cull_mask() const { @@ -267,7 +267,7 @@ int Light2D::get_item_shadow_cull_mask() const { void Light2D::set_mode(Mode p_mode) { mode = p_mode; - VS::get_singleton()->canvas_light_set_mode(canvas_light, VS::CanvasLightMode(p_mode)); + RS::get_singleton()->canvas_light_set_mode(canvas_light, RS::CanvasLightMode(p_mode)); } Light2D::Mode Light2D::get_mode() const { @@ -278,7 +278,7 @@ Light2D::Mode Light2D::get_mode() const { void Light2D::set_shadow_enabled(bool p_enabled) { shadow = p_enabled; - VS::get_singleton()->canvas_light_set_shadow_enabled(canvas_light, shadow); + RS::get_singleton()->canvas_light_set_shadow_enabled(canvas_light, shadow); } bool Light2D::is_shadow_enabled() const { @@ -288,7 +288,7 @@ bool Light2D::is_shadow_enabled() const { void Light2D::set_shadow_buffer_size(int p_size) { shadow_buffer_size = p_size; - VS::get_singleton()->canvas_light_set_shadow_buffer_size(canvas_light, shadow_buffer_size); + RS::get_singleton()->canvas_light_set_shadow_buffer_size(canvas_light, shadow_buffer_size); } int Light2D::get_shadow_buffer_size() const { @@ -299,7 +299,7 @@ int Light2D::get_shadow_buffer_size() const { void Light2D::set_shadow_filter(ShadowFilter p_filter) { ERR_FAIL_INDEX(p_filter, SHADOW_FILTER_MAX); shadow_filter = p_filter; - VS::get_singleton()->canvas_light_set_shadow_filter(canvas_light, VS::CanvasLightShadowFilter(p_filter)); + RS::get_singleton()->canvas_light_set_shadow_filter(canvas_light, RS::CanvasLightShadowFilter(p_filter)); } Light2D::ShadowFilter Light2D::get_shadow_filter() const { @@ -309,7 +309,7 @@ Light2D::ShadowFilter Light2D::get_shadow_filter() const { void Light2D::set_shadow_color(const Color &p_shadow_color) { shadow_color = p_shadow_color; - VS::get_singleton()->canvas_light_set_shadow_color(canvas_light, shadow_color); + RS::get_singleton()->canvas_light_set_shadow_color(canvas_light, shadow_color); } Color Light2D::get_shadow_color() const { @@ -320,13 +320,13 @@ void Light2D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { - VS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, get_canvas()); + RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, get_canvas()); _update_light_visibility(); } if (p_what == NOTIFICATION_TRANSFORM_CHANGED) { - VS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform()); + RS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform()); } if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { @@ -335,7 +335,7 @@ void Light2D::_notification(int p_what) { if (p_what == NOTIFICATION_EXIT_TREE) { - VS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, RID()); + RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, RID()); _update_light_visibility(); } } @@ -352,7 +352,7 @@ String Light2D::get_configuration_warning() const { void Light2D::set_shadow_smooth(float p_amount) { shadow_smooth = p_amount; - VS::get_singleton()->canvas_light_set_shadow_smooth(canvas_light, shadow_smooth); + RS::get_singleton()->canvas_light_set_shadow_smooth(canvas_light, shadow_smooth); } float Light2D::get_shadow_smooth() const { @@ -432,8 +432,8 @@ void Light2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Add,Sub,Mix,Mask"), "set_mode", "get_mode"); ADD_GROUP("Range", "range_"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "range_height", PROPERTY_HINT_RANGE, "-2048,2048,0.1,or_lesser,or_greater"), "set_height", "get_height"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "range_z_min", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_range_min", "get_z_range_min"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "range_z_max", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_range_max", "get_z_range_max"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "range_z_min", PROPERTY_HINT_RANGE, itos(RS::CANVAS_ITEM_Z_MIN) + "," + itos(RS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_range_min", "get_z_range_min"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "range_z_max", PROPERTY_HINT_RANGE, itos(RS::CANVAS_ITEM_Z_MIN) + "," + itos(RS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_range_max", "get_z_range_max"); ADD_PROPERTY(PropertyInfo(Variant::INT, "range_layer_min", PROPERTY_HINT_RANGE, "-512,512,1"), "set_layer_range_min", "get_layer_range_min"); ADD_PROPERTY(PropertyInfo(Variant::INT, "range_layer_max", PROPERTY_HINT_RANGE, "-512,512,1"), "set_layer_range_max", "get_layer_range_max"); ADD_PROPERTY(PropertyInfo(Variant::INT, "range_item_cull_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_item_cull_mask", "get_item_cull_mask"); @@ -458,7 +458,7 @@ void Light2D::_bind_methods() { Light2D::Light2D() { - canvas_light = VisualServer::get_singleton()->canvas_light_create(); + canvas_light = RenderingServer::get_singleton()->canvas_light_create(); enabled = true; editor_only = false; shadow = false; @@ -483,5 +483,5 @@ Light2D::Light2D() { Light2D::~Light2D() { - VisualServer::get_singleton()->free(canvas_light); + RenderingServer::get_singleton()->free(canvas_light); } diff --git a/scene/2d/light_occluder_2d.cpp b/scene/2d/light_occluder_2d.cpp index d4a5c93823..bd1a820aec 100644 --- a/scene/2d/light_occluder_2d.cpp +++ b/scene/2d/light_occluder_2d.cpp @@ -88,7 +88,7 @@ void OccluderPolygon2D::set_polygon(const Vector<Vector2> &p_polygon) { polygon = p_polygon; rect_cache_dirty = true; - VS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon, p_polygon, closed); + RS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon, p_polygon, closed); emit_changed(); } @@ -103,7 +103,7 @@ void OccluderPolygon2D::set_closed(bool p_closed) { return; closed = p_closed; if (polygon.size()) - VS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon, polygon, closed); + RS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon, polygon, closed); emit_changed(); } @@ -115,7 +115,7 @@ bool OccluderPolygon2D::is_closed() const { void OccluderPolygon2D::set_cull_mode(CullMode p_mode) { cull = p_mode; - VS::get_singleton()->canvas_occluder_polygon_set_cull_mode(occ_polygon, VS::CanvasOccluderPolygonCullMode(p_mode)); + RS::get_singleton()->canvas_occluder_polygon_set_cull_mode(occ_polygon, RS::CanvasOccluderPolygonCullMode(p_mode)); } OccluderPolygon2D::CullMode OccluderPolygon2D::get_cull_mode() const { @@ -150,7 +150,7 @@ void OccluderPolygon2D::_bind_methods() { OccluderPolygon2D::OccluderPolygon2D() { - occ_polygon = VS::get_singleton()->canvas_occluder_polygon_create(); + occ_polygon = RS::get_singleton()->canvas_occluder_polygon_create(); closed = true; cull = CULL_DISABLED; rect_cache_dirty = true; @@ -158,7 +158,7 @@ OccluderPolygon2D::OccluderPolygon2D() { OccluderPolygon2D::~OccluderPolygon2D() { - VS::get_singleton()->free(occ_polygon); + RS::get_singleton()->free(occ_polygon); } void LightOccluder2D::_poly_changed() { @@ -172,17 +172,17 @@ void LightOccluder2D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_CANVAS) { - VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, get_canvas()); - VS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform()); - VS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree()); + 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) { - VS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform()); + RS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform()); } if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - VS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree()); + RS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree()); } if (p_what == NOTIFICATION_DRAW) { @@ -214,7 +214,7 @@ void LightOccluder2D::_notification(int p_what) { if (p_what == NOTIFICATION_EXIT_CANVAS) { - VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, RID()); + RS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, RID()); } } @@ -239,9 +239,9 @@ void LightOccluder2D::set_occluder_polygon(const Ref<OccluderPolygon2D> &p_polyg occluder_polygon = p_polygon; if (occluder_polygon.is_valid()) - VS::get_singleton()->canvas_light_occluder_set_polygon(occluder, occluder_polygon->get_rid()); + RS::get_singleton()->canvas_light_occluder_set_polygon(occluder, occluder_polygon->get_rid()); else - VS::get_singleton()->canvas_light_occluder_set_polygon(occluder, RID()); + RS::get_singleton()->canvas_light_occluder_set_polygon(occluder, RID()); #ifdef DEBUG_ENABLED if (occluder_polygon.is_valid()) @@ -258,7 +258,7 @@ Ref<OccluderPolygon2D> LightOccluder2D::get_occluder_polygon() const { void LightOccluder2D::set_occluder_light_mask(int p_mask) { mask = p_mask; - VS::get_singleton()->canvas_light_occluder_set_light_mask(occluder, mask); + RS::get_singleton()->canvas_light_occluder_set_light_mask(occluder, mask); } int LightOccluder2D::get_occluder_light_mask() const { @@ -293,12 +293,12 @@ void LightOccluder2D::_bind_methods() { LightOccluder2D::LightOccluder2D() { - occluder = VS::get_singleton()->canvas_light_occluder_create(); + occluder = RS::get_singleton()->canvas_light_occluder_create(); mask = 1; set_notify_transform(true); } LightOccluder2D::~LightOccluder2D() { - VS::get_singleton()->free(occluder); + RS::get_singleton()->free(occluder); } diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp index 873c901c0a..c45eab70df 100644 --- a/scene/2d/line_2d.cpp +++ b/scene/2d/line_2d.cpp @@ -311,7 +311,7 @@ void Line2D::_draw() { lb.build(); - VS::get_singleton()->canvas_item_add_triangle_array( + RS::get_singleton()->canvas_item_add_triangle_array( get_canvas_item(), lb.indices, lb.vertices, diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp index 3385f2fbe0..6b06f2227a 100644 --- a/scene/2d/line_builder.cpp +++ b/scene/2d/line_builder.cpp @@ -95,9 +95,9 @@ static inline Vector2 interpolate(const Rect2 &r, const Vector2 &v) { LineBuilder::LineBuilder() { joint_mode = Line2D::LINE_JOINT_SHARP; width = 10; - curve = NULL; + curve = nullptr; default_color = Color(0.4, 0.5, 1); - gradient = NULL; + gradient = nullptr; sharp_limit = 2.f; round_precision = 8; begin_cap_mode = Line2D::LINE_CAP_NONE; @@ -147,8 +147,8 @@ void LineBuilder::build() { float current_distance1 = 0.f; float total_distance = 0.f; float width_factor = 1.f; - _interpolate_color = gradient != NULL; - bool retrieve_curve = curve != NULL; + _interpolate_color = gradient != nullptr; + bool retrieve_curve = curve != nullptr; bool distance_required = _interpolate_color || retrieve_curve || texture_mode == Line2D::LINE_TEXTURE_TILE || diff --git a/scene/2d/navigation_2d.cpp b/scene/2d/navigation_2d.cpp index bbabfa16c7..ae9fc0f32c 100644 --- a/scene/2d/navigation_2d.cpp +++ b/scene/2d/navigation_2d.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "navigation_2d.h" -#include "servers/navigation_2d_server.h" +#include "servers/navigation_server_2d.h" void Navigation2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_rid"), &Navigation2D::get_rid); @@ -51,44 +51,44 @@ void Navigation2D::_bind_methods() { void Navigation2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { - Navigation2DServer::get_singleton()->map_set_active(map, true); + NavigationServer2D::get_singleton()->map_set_active(map, true); } break; case NOTIFICATION_EXIT_TREE: { - Navigation2DServer::get_singleton()->map_set_active(map, false); + NavigationServer2D::get_singleton()->map_set_active(map, false); } break; } } void Navigation2D::set_cell_size(float p_cell_size) { cell_size = p_cell_size; - Navigation2DServer::get_singleton()->map_set_cell_size(map, cell_size); + NavigationServer2D::get_singleton()->map_set_cell_size(map, cell_size); } void Navigation2D::set_edge_connection_margin(float p_edge_connection_margin) { edge_connection_margin = p_edge_connection_margin; - Navigation2DServer::get_singleton()->map_set_edge_connection_margin(map, edge_connection_margin); + NavigationServer2D::get_singleton()->map_set_edge_connection_margin(map, edge_connection_margin); } Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vector2 &p_end, bool p_optimize) const { - return Navigation2DServer::get_singleton()->map_get_path(map, p_start, p_end, p_optimize); + return NavigationServer2D::get_singleton()->map_get_path(map, p_start, p_end, p_optimize); } Vector2 Navigation2D::get_closest_point(const Vector2 &p_point) const { - return Navigation2DServer::get_singleton()->map_get_closest_point(map, p_point); + return NavigationServer2D::get_singleton()->map_get_closest_point(map, p_point); } RID Navigation2D::get_closest_point_owner(const Vector2 &p_point) const { - return Navigation2DServer::get_singleton()->map_get_closest_point_owner(map, p_point); + return NavigationServer2D::get_singleton()->map_get_closest_point_owner(map, p_point); } Navigation2D::Navigation2D() { - map = Navigation2DServer::get_singleton()->map_create(); + map = NavigationServer2D::get_singleton()->map_create(); set_cell_size(10); // Ten pixels set_edge_connection_margin(100); } Navigation2D::~Navigation2D() { - Navigation2DServer::get_singleton()->free(map); + NavigationServer2D::get_singleton()->free(map); } diff --git a/scene/2d/navigation_2d.h b/scene/2d/navigation_2d.h index 5520f5006e..1da13fc78a 100644 --- a/scene/2d/navigation_2d.h +++ b/scene/2d/navigation_2d.h @@ -31,7 +31,7 @@ #ifndef NAVIGATION_2D_H #define NAVIGATION_2D_H -#include "scene/2d/navigation_polygon.h" +#include "scene/2d/navigation_region_2d.h" #include "scene/2d/node_2d.h" class Navigation2D : public Node2D { diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index f5fe113f29..32da46e8a8 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -32,7 +32,7 @@ #include "core/engine.h" #include "scene/2d/navigation_2d.h" -#include "servers/navigation_2d_server.h" +#include "servers/navigation_server_2d.h" void NavigationAgent2D::_bind_methods() { @@ -94,16 +94,16 @@ void NavigationAgent2D::_notification(int p_what) { agent_parent = Object::cast_to<Node2D>(get_parent()); - Navigation2DServer::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); + NavigationServer2D::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); // Search the navigation node and set it { - Navigation2D *nav = NULL; + Navigation2D *nav = nullptr; Node *p = get_parent(); - while (p != NULL) { + while (p != nullptr) { nav = Object::cast_to<Navigation2D>(p); - if (nav != NULL) - p = NULL; + if (nav != nullptr) + p = nullptr; else p = p->get_parent(); } @@ -114,14 +114,14 @@ void NavigationAgent2D::_notification(int p_what) { set_physics_process_internal(true); } break; case NOTIFICATION_EXIT_TREE: { - agent_parent = NULL; - set_navigation(NULL); + agent_parent = nullptr; + set_navigation(nullptr); set_physics_process_internal(false); } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { if (agent_parent) { - Navigation2DServer::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().get_origin()); + NavigationServer2D::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().get_origin()); if (!target_reached) { if (distance_to_target() < target_desired_distance) { emit_signal("target_reached"); @@ -134,15 +134,15 @@ void NavigationAgent2D::_notification(int p_what) { } NavigationAgent2D::NavigationAgent2D() : - agent_parent(NULL), - navigation(NULL), + agent_parent(nullptr), + navigation(nullptr), agent(RID()), target_desired_distance(1.0), path_max_distance(3.0), velocity_submitted(false), target_reached(false), navigation_finished(true) { - agent = Navigation2DServer::get_singleton()->agent_create(); + agent = NavigationServer2D::get_singleton()->agent_create(); set_neighbor_dist(500.0); set_max_neighbors(10); set_time_horizon(20.0); @@ -151,7 +151,7 @@ NavigationAgent2D::NavigationAgent2D() : } NavigationAgent2D::~NavigationAgent2D() { - Navigation2DServer::get_singleton()->free(agent); + NavigationServer2D::get_singleton()->free(agent); agent = RID(); // Pointless } @@ -160,12 +160,12 @@ void NavigationAgent2D::set_navigation(Navigation2D *p_nav) { return; // Pointless navigation = p_nav; - Navigation2DServer::get_singleton()->agent_set_map(agent, navigation == NULL ? RID() : navigation->get_rid()); + NavigationServer2D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid()); } void NavigationAgent2D::set_navigation_node(Node *p_nav) { Navigation2D *nav = Object::cast_to<Navigation2D>(p_nav); - ERR_FAIL_COND(nav == NULL); + ERR_FAIL_COND(nav == nullptr); set_navigation(nav); } @@ -179,27 +179,27 @@ void NavigationAgent2D::set_target_desired_distance(real_t p_dd) { void NavigationAgent2D::set_radius(real_t p_radius) { radius = p_radius; - Navigation2DServer::get_singleton()->agent_set_radius(agent, radius); + NavigationServer2D::get_singleton()->agent_set_radius(agent, radius); } void NavigationAgent2D::set_neighbor_dist(real_t p_dist) { neighbor_dist = p_dist; - Navigation2DServer::get_singleton()->agent_set_neighbor_dist(agent, neighbor_dist); + NavigationServer2D::get_singleton()->agent_set_neighbor_dist(agent, neighbor_dist); } void NavigationAgent2D::set_max_neighbors(int p_count) { max_neighbors = p_count; - Navigation2DServer::get_singleton()->agent_set_max_neighbors(agent, max_neighbors); + NavigationServer2D::get_singleton()->agent_set_max_neighbors(agent, max_neighbors); } void NavigationAgent2D::set_time_horizon(real_t p_time) { time_horizon = p_time; - Navigation2DServer::get_singleton()->agent_set_time_horizon(agent, time_horizon); + NavigationServer2D::get_singleton()->agent_set_time_horizon(agent, time_horizon); } void NavigationAgent2D::set_max_speed(real_t p_max_speed) { max_speed = p_max_speed; - Navigation2DServer::get_singleton()->agent_set_max_speed(agent, max_speed); + NavigationServer2D::get_singleton()->agent_set_max_speed(agent, max_speed); } void NavigationAgent2D::set_path_max_distance(real_t p_pmd) { @@ -215,6 +215,7 @@ void NavigationAgent2D::set_target_location(Vector2 p_location) { navigation_path.clear(); target_reached = false; navigation_finished = false; + update_frame_id = 0; } Vector2 NavigationAgent2D::get_target_location() const { @@ -224,7 +225,7 @@ Vector2 NavigationAgent2D::get_target_location() const { Vector2 NavigationAgent2D::get_next_location() { update_navigation(); if (navigation_path.size() == 0) { - ERR_FAIL_COND_V(agent_parent == NULL, Vector2()); + ERR_FAIL_COND_V(agent_parent == nullptr, Vector2()); return agent_parent->get_global_transform().get_origin(); } else { return navigation_path[nav_path_index]; @@ -232,7 +233,7 @@ Vector2 NavigationAgent2D::get_next_location() { } real_t NavigationAgent2D::distance_to_target() const { - ERR_FAIL_COND_V(agent_parent == NULL, 0.0); + ERR_FAIL_COND_V(agent_parent == nullptr, 0.0); return agent_parent->get_global_transform().get_origin().distance_to(target_location); } @@ -259,8 +260,8 @@ Vector2 NavigationAgent2D::get_final_location() { void NavigationAgent2D::set_velocity(Vector2 p_velocity) { target_velocity = p_velocity; - Navigation2DServer::get_singleton()->agent_set_target_velocity(agent, target_velocity); - Navigation2DServer::get_singleton()->agent_set_velocity(agent, prev_safe_velocity); + NavigationServer2D::get_singleton()->agent_set_target_velocity(agent, target_velocity); + NavigationServer2D::get_singleton()->agent_set_velocity(agent, prev_safe_velocity); velocity_submitted = true; } @@ -287,8 +288,8 @@ String NavigationAgent2D::get_configuration_warning() const { void NavigationAgent2D::update_navigation() { - if (agent_parent == NULL) return; - if (navigation == NULL) return; + if (agent_parent == nullptr) return; + if (navigation == nullptr) return; if (update_frame_id == Engine::get_singleton()->get_physics_frames()) return; update_frame_id = Engine::get_singleton()->get_physics_frames(); @@ -297,7 +298,7 @@ void NavigationAgent2D::update_navigation() { bool reload_path = false; - if (Navigation2DServer::get_singleton()->agent_is_map_changed(agent)) { + if (NavigationServer2D::get_singleton()->agent_is_map_changed(agent)) { reload_path = true; } else if (navigation_path.size() == 0) { reload_path = true; @@ -316,7 +317,7 @@ void NavigationAgent2D::update_navigation() { } if (reload_path) { - navigation_path = Navigation2DServer::get_singleton()->map_get_path(navigation->get_rid(), o, target_location, true); + navigation_path = NavigationServer2D::get_singleton()->map_get_path(navigation->get_rid(), o, target_location, true); navigation_finished = false; nav_path_index = 0; emit_signal("path_changed"); diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp index cc9f5740a9..50d02ca507 100644 --- a/scene/2d/navigation_obstacle_2d.cpp +++ b/scene/2d/navigation_obstacle_2d.cpp @@ -33,7 +33,7 @@ #include "scene/2d/collision_shape_2d.h" #include "scene/2d/navigation_2d.h" #include "scene/2d/physics_body_2d.h" -#include "servers/navigation_2d_server.h" +#include "servers/navigation_server_2d.h" void NavigationObstacle2D::_bind_methods() { @@ -49,12 +49,12 @@ void NavigationObstacle2D::_notification(int p_what) { // Search the navigation node and set it { - Navigation2D *nav = NULL; + Navigation2D *nav = nullptr; Node *p = get_parent(); - while (p != NULL) { + while (p != nullptr) { nav = Object::cast_to<Navigation2D>(p); - if (nav != NULL) - p = NULL; + if (nav != nullptr) + p = nullptr; else p = p->get_parent(); } @@ -65,13 +65,13 @@ void NavigationObstacle2D::_notification(int p_what) { set_physics_process_internal(true); } break; case NOTIFICATION_EXIT_TREE: { - set_navigation(NULL); + set_navigation(nullptr); set_physics_process_internal(false); } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { Node2D *node = Object::cast_to<Node2D>(get_parent()); if (node) { - Navigation2DServer::get_singleton()->agent_set_position(agent, node->get_global_transform().get_origin()); + NavigationServer2D::get_singleton()->agent_set_position(agent, node->get_global_transform().get_origin()); } } break; @@ -79,13 +79,13 @@ void NavigationObstacle2D::_notification(int p_what) { } NavigationObstacle2D::NavigationObstacle2D() : - navigation(NULL), + navigation(nullptr), agent(RID()) { - agent = Navigation2DServer::get_singleton()->agent_create(); + agent = NavigationServer2D::get_singleton()->agent_create(); } NavigationObstacle2D::~NavigationObstacle2D() { - Navigation2DServer::get_singleton()->free(agent); + NavigationServer2D::get_singleton()->free(agent); agent = RID(); // Pointless } @@ -94,12 +94,12 @@ void NavigationObstacle2D::set_navigation(Navigation2D *p_nav) { return; // Pointless navigation = p_nav; - Navigation2DServer::get_singleton()->agent_set_map(agent, navigation == NULL ? RID() : navigation->get_rid()); + NavigationServer2D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid()); } void NavigationObstacle2D::set_navigation_node(Node *p_nav) { Navigation2D *nav = Object::cast_to<Navigation2D>(p_nav); - ERR_FAIL_COND(nav == NULL); + ERR_FAIL_COND(nav == nullptr); set_navigation(nav); } @@ -146,9 +146,9 @@ void NavigationObstacle2D::update_agent_shape() { radius = 1.0; // Never a 0 radius // Initialize the Agent as an object - Navigation2DServer::get_singleton()->agent_set_neighbor_dist(agent, 0.0); - Navigation2DServer::get_singleton()->agent_set_max_neighbors(agent, 0); - Navigation2DServer::get_singleton()->agent_set_time_horizon(agent, 0.0); - Navigation2DServer::get_singleton()->agent_set_radius(agent, radius); - Navigation2DServer::get_singleton()->agent_set_max_speed(agent, 0.0); + NavigationServer2D::get_singleton()->agent_set_neighbor_dist(agent, 0.0); + NavigationServer2D::get_singleton()->agent_set_max_neighbors(agent, 0); + NavigationServer2D::get_singleton()->agent_set_time_horizon(agent, 0.0); + NavigationServer2D::get_singleton()->agent_set_radius(agent, radius); + NavigationServer2D::get_singleton()->agent_set_max_speed(agent, 0.0); } diff --git a/scene/2d/navigation_polygon.cpp b/scene/2d/navigation_region_2d.cpp index 9159ef21c5..d77fd5b097 100644 --- a/scene/2d/navigation_polygon.cpp +++ b/scene/2d/navigation_region_2d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_polygon.cpp */ +/* navigation_region_2d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,13 +28,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "navigation_polygon.h" +#include "navigation_region_2d.h" #include "core/core_string_names.h" #include "core/engine.h" #include "core/os/mutex.h" #include "navigation_2d.h" -#include "servers/navigation_2d_server.h" +#include "servers/navigation_server_2d.h" #include "thirdparty/misc/triangulator.h" @@ -281,7 +281,7 @@ void NavigationPolygon::make_polygons_from_outlines() { for (int l = 0; l < olsize2; l++) { - if (Geometry::segment_intersects_segment_2d(r[0], outside_point, r2[l], r2[(l + 1) % olsize2], NULL)) { + if (Geometry::segment_intersects_segment_2d(r[0], outside_point, r2[l], r2[(l + 1) % olsize2], nullptr)) { interscount++; } } @@ -385,12 +385,12 @@ void NavigationRegion2D::set_enabled(bool p_enabled) { if (!enabled) { - Navigation2DServer::get_singleton()->region_set_map(region, RID()); + NavigationServer2D::get_singleton()->region_set_map(region, RID()); } else { if (navigation) { - Navigation2DServer::get_singleton()->region_set_map(region, navigation->get_rid()); + NavigationServer2D::get_singleton()->region_set_map(region, navigation->get_rid()); } } @@ -429,7 +429,7 @@ void NavigationRegion2D::_notification(int p_what) { if (enabled) { - Navigation2DServer::get_singleton()->region_set_map(region, navigation->get_rid()); + NavigationServer2D::get_singleton()->region_set_map(region, navigation->get_rid()); } break; } @@ -440,16 +440,16 @@ void NavigationRegion2D::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { - Navigation2DServer::get_singleton()->region_set_transform(region, get_global_transform()); + NavigationServer2D::get_singleton()->region_set_transform(region, get_global_transform()); } break; case NOTIFICATION_EXIT_TREE: { if (navigation) { - Navigation2DServer::get_singleton()->region_set_map(region, RID()); + NavigationServer2D::get_singleton()->region_set_map(region, RID()); } - navigation = NULL; + navigation = nullptr; } break; case NOTIFICATION_DRAW: { @@ -494,7 +494,7 @@ void NavigationRegion2D::_notification(int p_what) { } } } - VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, vertices, colors); + RS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, vertices, colors); } } break; } @@ -511,7 +511,7 @@ void NavigationRegion2D::set_navigation_polygon(const Ref<NavigationPolygon> &p_ } navpoly = p_navpoly; - Navigation2DServer::get_singleton()->region_set_navpoly(region, p_navpoly); + NavigationServer2D::get_singleton()->region_set_navpoly(region, p_navpoly); if (navpoly.is_valid()) { navpoly->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &NavigationRegion2D::_navpoly_changed)); @@ -572,11 +572,11 @@ NavigationRegion2D::NavigationRegion2D() { enabled = true; set_notify_transform(true); - region = Navigation2DServer::get_singleton()->region_create(); + region = NavigationServer2D::get_singleton()->region_create(); - navigation = NULL; + navigation = nullptr; } NavigationRegion2D::~NavigationRegion2D() { - Navigation2DServer::get_singleton()->free(region); + NavigationServer2D::get_singleton()->free(region); } diff --git a/scene/2d/navigation_polygon.h b/scene/2d/navigation_region_2d.h index 579d6b0e0e..73e056a353 100644 --- a/scene/2d/navigation_polygon.h +++ b/scene/2d/navigation_region_2d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_polygon.h */ +/* navigation_region_2d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef NAVIGATION_POLYGON_H -#define NAVIGATION_POLYGON_H +#ifndef NAVIGATION_REGION_2D_H +#define NAVIGATION_REGION_2D_H #include "scene/2d/node_2d.h" #include "scene/resources/navigation_mesh.h" @@ -43,7 +43,7 @@ class NavigationPolygon : public Resource { Vector<int> indices; }; Vector<Polygon> polygons; - Vector<Vector<Vector2> > outlines; + Vector<Vector<Vector2>> outlines; mutable Rect2 item_rect; mutable bool rect_cache_dirty; @@ -127,4 +127,4 @@ public: ~NavigationRegion2D(); }; -#endif // NAVIGATIONPOLYGON_H +#endif // NAVIGATION_REGION_2D_H diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index df21538609..ac8a77b6cb 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -32,8 +32,8 @@ #include "core/message_queue.h" #include "scene/gui/control.h" -#include "scene/main/viewport.h" -#include "servers/visual_server.h" +#include "scene/main/window.h" +#include "servers/rendering_server.h" #ifdef TOOLS_ENABLED Dictionary Node2D::_edit_get_state() const { @@ -136,7 +136,7 @@ void Node2D::_update_transform() { _mat.set_rotation_and_scale(angle, _scale); _mat.elements[2] = pos; - VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), _mat); + RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), _mat); if (!is_inside_tree()) return; @@ -315,7 +315,7 @@ void Node2D::set_transform(const Transform2D &p_transform) { _mat = p_transform; _xform_dirty = true; - VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), _mat); + RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), _mat); if (!is_inside_tree()) return; @@ -334,10 +334,10 @@ void Node2D::set_global_transform(const Transform2D &p_transform) { void Node2D::set_z_index(int p_z) { - ERR_FAIL_COND(p_z < VS::CANVAS_ITEM_Z_MIN); - ERR_FAIL_COND(p_z > VS::CANVAS_ITEM_Z_MAX); + ERR_FAIL_COND(p_z < RS::CANVAS_ITEM_Z_MIN); + ERR_FAIL_COND(p_z > RS::CANVAS_ITEM_Z_MAX); z_index = p_z; - VS::get_singleton()->canvas_item_set_z_index(get_canvas_item(), z_index); + RS::get_singleton()->canvas_item_set_z_index(get_canvas_item(), z_index); _change_notify("z_index"); } @@ -346,7 +346,7 @@ void Node2D::set_z_as_relative(bool p_enabled) { if (z_relative == p_enabled) return; z_relative = p_enabled; - VS::get_singleton()->canvas_item_set_z_as_relative_to_parent(get_canvas_item(), p_enabled); + RS::get_singleton()->canvas_item_set_z_as_relative_to_parent(get_canvas_item(), p_enabled); } bool Node2D::is_z_relative() const { @@ -452,7 +452,7 @@ void Node2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "global_transform", PROPERTY_HINT_NONE, "", 0), "set_global_transform", "get_global_transform"); ADD_GROUP("Z Index", ""); - ADD_PROPERTY(PropertyInfo(Variant::INT, "z_index", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_index", "get_z_index"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "z_index", PROPERTY_HINT_RANGE, itos(RS::CANVAS_ITEM_Z_MIN) + "," + itos(RS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_index", "get_z_index"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "z_as_relative"), "set_z_as_relative", "is_z_relative"); } diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index 00202481a6..abed05ed0c 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -31,7 +31,7 @@ #ifndef NODE2D_H #define NODE2D_H -#include "scene/2d/canvas_item.h" +#include "scene/main/canvas_item.h" class Node2D : public CanvasItem { diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index 5aea1025ef..181f0f158c 100644 --- a/scene/2d/parallax_layer.cpp +++ b/scene/2d/parallax_layer.cpp @@ -78,7 +78,7 @@ void ParallaxLayer::_update_mirroring() { RID c = pb->get_canvas(); RID ci = get_canvas_item(); Point2 mirrorScale = mirroring * get_scale(); - VisualServer::get_singleton()->canvas_set_item_mirroring(c, ci, mirrorScale); + RenderingServer::get_singleton()->canvas_set_item_mirroring(c, ci, mirrorScale); } } diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index 3e807f12dc..ed8481db4a 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -242,7 +242,7 @@ void PathFollow2D::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { - path = NULL; + path = nullptr; } break; } } @@ -321,16 +321,14 @@ void PathFollow2D::set_offset(float p_offset) { offset = p_offset; if (path) { - if (path->get_curve().is_valid() && path->get_curve()->get_baked_length()) { + if (path->get_curve().is_valid()) { float path_length = path->get_curve()->get_baked_length(); if (loop) { - while (offset > path_length) - offset -= path_length; - - while (offset < 0) - offset += path_length; - + offset = Math::fposmod(offset, path_length); + if (!Math::is_zero_approx(p_offset) && Math::is_zero_approx(offset)) { + offset = path_length; + } } else { offset = CLAMP(offset, 0, path_length); } @@ -421,7 +419,7 @@ PathFollow2D::PathFollow2D() { offset = 0; h_offset = 0; v_offset = 0; - path = NULL; + path = nullptr; rotate = true; cubic = true; loop = true; diff --git a/scene/2d/path_texture.cpp b/scene/2d/path_texture.cpp deleted file mode 100644 index 590f70a1b2..0000000000 --- a/scene/2d/path_texture.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************************************/ -/* path_texture.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "path_texture.h" - -void PathTexture::set_begin_texture(const Ref<Texture2D> &p_texture) { - - begin = p_texture; - update(); -} - -Ref<Texture2D> PathTexture::get_begin_texture() const { - - return begin; -} - -void PathTexture::set_repeat_texture(const Ref<Texture2D> &p_texture) { - - repeat = p_texture; - update(); -} -Ref<Texture2D> PathTexture::get_repeat_texture() const { - - return repeat; -} - -void PathTexture::set_end_texture(const Ref<Texture2D> &p_texture) { - - end = p_texture; - update(); -} -Ref<Texture2D> PathTexture::get_end_texture() const { - - return end; -} - -void PathTexture::set_subdivisions(int p_amount) { - - ERR_FAIL_INDEX(p_amount, 32); - subdivs = p_amount; - update(); -} - -int PathTexture::get_subdivisions() const { - - return subdivs; -} - -void PathTexture::set_overlap(int p_amount) { - - overlap = p_amount; - update(); -} -int PathTexture::get_overlap() const { - - return overlap; -} - -PathTexture::PathTexture() { - - overlap = 0; - subdivs = 1; -} diff --git a/scene/2d/path_texture.h b/scene/2d/path_texture.h deleted file mode 100644 index 014d0dc959..0000000000 --- a/scene/2d/path_texture.h +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************/ -/* path_texture.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef PATH_TEXTURE_H -#define PATH_TEXTURE_H - -#include "scene/2d/node_2d.h" - -class PathTexture : public Node2D { - GDCLASS(PathTexture, Node2D); - - Ref<Texture2D> begin; - Ref<Texture2D> repeat; - Ref<Texture2D> end; - int subdivs; - bool overlap; - -public: - void set_begin_texture(const Ref<Texture2D> &p_texture); - Ref<Texture2D> get_begin_texture() const; - - void set_repeat_texture(const Ref<Texture2D> &p_texture); - Ref<Texture2D> get_repeat_texture() const; - - void set_end_texture(const Ref<Texture2D> &p_texture); - Ref<Texture2D> get_end_texture() const; - - void set_subdivisions(int p_amount); - int get_subdivisions() const; - - void set_overlap(int p_amount); - int get_overlap() const; - - PathTexture(); -}; - -#endif // PATH_TEXTURE_H diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 9bfeca7e56..21dc9537ec 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -82,7 +82,7 @@ void PhysicsBody2D::_bind_methods() { void PhysicsBody2D::set_collision_layer(uint32_t p_layer) { collision_layer = p_layer; - Physics2DServer::get_singleton()->body_set_collision_layer(get_rid(), p_layer); + PhysicsServer2D::get_singleton()->body_set_collision_layer(get_rid(), p_layer); } uint32_t PhysicsBody2D::get_collision_layer() const { @@ -93,7 +93,7 @@ uint32_t PhysicsBody2D::get_collision_layer() const { void PhysicsBody2D::set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; - Physics2DServer::get_singleton()->body_set_collision_mask(get_rid(), p_mask); + PhysicsServer2D::get_singleton()->body_set_collision_mask(get_rid(), p_mask); } uint32_t PhysicsBody2D::get_collision_mask() const { @@ -130,10 +130,10 @@ bool PhysicsBody2D::get_collision_layer_bit(int p_bit) const { return get_collision_layer() & (1 << p_bit); } -PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : - CollisionObject2D(Physics2DServer::get_singleton()->body_create(), false) { +PhysicsBody2D::PhysicsBody2D(PhysicsServer2D::BodyMode p_mode) : + CollisionObject2D(PhysicsServer2D::get_singleton()->body_create(), false) { - Physics2DServer::get_singleton()->body_set_mode(get_rid(), p_mode); + PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), p_mode); collision_layer = 1; collision_mask = 1; set_pickable(false); @@ -141,11 +141,11 @@ PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : Array PhysicsBody2D::get_collision_exceptions() { List<RID> exceptions; - Physics2DServer::get_singleton()->body_get_collision_exceptions(get_rid(), &exceptions); + PhysicsServer2D::get_singleton()->body_get_collision_exceptions(get_rid(), &exceptions); Array ret; for (List<RID>::Element *E = exceptions.front(); E; E = E->next()) { RID body = E->get(); - ObjectID instance_id = Physics2DServer::get_singleton()->body_get_object_instance_id(body); + ObjectID instance_id = PhysicsServer2D::get_singleton()->body_get_object_instance_id(body); Object *obj = ObjectDB::get_instance(instance_id); PhysicsBody2D *physics_body = Object::cast_to<PhysicsBody2D>(obj); ret.append(physics_body); @@ -157,28 +157,28 @@ 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 PhysicsBody type."); - Physics2DServer::get_singleton()->body_add_collision_exception(get_rid(), physics_body->get_rid()); + ERR_FAIL_COND_MSG(!physics_body, "Collision exception only works between two objects of PhysicsBody2D type."); + PhysicsServer2D::get_singleton()->body_add_collision_exception(get_rid(), physics_body->get_rid()); } void PhysicsBody2D::remove_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); PhysicsBody2D *physics_body = Object::cast_to<PhysicsBody2D>(p_node); - ERR_FAIL_COND_MSG(!physics_body, "Collision exception only works between two objects of PhysicsBody type."); - Physics2DServer::get_singleton()->body_remove_collision_exception(get_rid(), physics_body->get_rid()); + ERR_FAIL_COND_MSG(!physics_body, "Collision exception only works between two objects of PhysicsBody2D type."); + PhysicsServer2D::get_singleton()->body_remove_collision_exception(get_rid(), physics_body->get_rid()); } void StaticBody2D::set_constant_linear_velocity(const Vector2 &p_vel) { constant_linear_velocity = p_vel; - Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_LINEAR_VELOCITY, constant_linear_velocity); + 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; - Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_ANGULAR_VELOCITY, constant_angular_velocity); + PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_ANGULAR_VELOCITY, constant_angular_velocity); } Vector2 StaticBody2D::get_constant_linear_velocity() const { @@ -225,7 +225,7 @@ void StaticBody2D::_bind_methods() { } StaticBody2D::StaticBody2D() : - PhysicsBody2D(Physics2DServer::BODY_MODE_STATIC) { + PhysicsBody2D(PhysicsServer2D::BODY_MODE_STATIC) { constant_angular_velocity = 0; } @@ -235,11 +235,11 @@ StaticBody2D::~StaticBody2D() { void StaticBody2D::_reload_physics_characteristics() { if (physics_material_override.is_null()) { - Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, 0); - Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, 1); + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_BOUNCE, 0); + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_FRICTION, 1); } else { - Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce()); - Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, physics_material_override->computed_friction()); + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce()); + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_FRICTION, physics_material_override->computed_friction()); } } @@ -360,20 +360,20 @@ struct _RigidBody2DInOut { int local_shape; }; -bool RigidBody2D::_test_motion(const Vector2 &p_motion, bool p_infinite_inertia, float p_margin, const Ref<Physics2DTestMotionResult> &p_result) { +bool RigidBody2D::_test_motion(const Vector2 &p_motion, bool p_infinite_inertia, float p_margin, const Ref<PhysicsTestMotionResult2D> &p_result) { - Physics2DServer::MotionResult *r = NULL; + PhysicsServer2D::MotionResult *r = nullptr; if (p_result.is_valid()) r = p_result->get_result_ptr(); - return Physics2DServer::get_singleton()->body_test_motion(get_rid(), get_global_transform(), p_motion, p_infinite_inertia, p_margin, r); + return PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), get_global_transform(), p_motion, p_infinite_inertia, p_margin, r); } void RigidBody2D::_direct_state_changed(Object *p_state) { #ifdef DEBUG_ENABLED - state = Object::cast_to<Physics2DDirectBodyState>(p_state); + state = Object::cast_to<PhysicsDirectBodyState2D>(p_state); #else - state = (Physics2DDirectBodyState *)p_state; //trust it + state = (PhysicsDirectBodyState2D *)p_state; //trust it #endif set_block_transform_notify(true); // don't want notify (would feedback loop) @@ -474,7 +474,7 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { contact_monitor->locked = false; } - state = NULL; + state = nullptr; } void RigidBody2D::set_mode(Mode p_mode) { @@ -484,20 +484,20 @@ void RigidBody2D::set_mode(Mode p_mode) { case MODE_RIGID: { - Physics2DServer::get_singleton()->body_set_mode(get_rid(), Physics2DServer::BODY_MODE_RIGID); + PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BODY_MODE_RIGID); } break; case MODE_STATIC: { - Physics2DServer::get_singleton()->body_set_mode(get_rid(), Physics2DServer::BODY_MODE_STATIC); + PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BODY_MODE_STATIC); } break; case MODE_KINEMATIC: { - Physics2DServer::get_singleton()->body_set_mode(get_rid(), Physics2DServer::BODY_MODE_KINEMATIC); + PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BODY_MODE_KINEMATIC); } break; case MODE_CHARACTER: { - Physics2DServer::get_singleton()->body_set_mode(get_rid(), Physics2DServer::BODY_MODE_CHARACTER); + PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BODY_MODE_CHARACTER); } break; } @@ -514,7 +514,7 @@ void RigidBody2D::set_mass(real_t p_mass) { mass = p_mass; _change_notify("mass"); _change_notify("weight"); - Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_MASS, mass); + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_MASS, mass); } real_t RigidBody2D::get_mass() const { @@ -524,12 +524,12 @@ real_t RigidBody2D::get_mass() const { void RigidBody2D::set_inertia(real_t p_inertia) { ERR_FAIL_COND(p_inertia < 0); - Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_INERTIA, p_inertia); + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_INERTIA, p_inertia); } real_t RigidBody2D::get_inertia() const { - return Physics2DServer::get_singleton()->body_get_param(get_rid(), Physics2DServer::BODY_PARAM_INERTIA); + return PhysicsServer2D::get_singleton()->body_get_param(get_rid(), PhysicsServer2D::BODY_PARAM_INERTIA); } void RigidBody2D::set_weight(real_t p_weight) { @@ -564,7 +564,7 @@ Ref<PhysicsMaterial> RigidBody2D::get_physics_material_override() const { void RigidBody2D::set_gravity_scale(real_t p_gravity_scale) { gravity_scale = p_gravity_scale; - Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_GRAVITY_SCALE, gravity_scale); + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_GRAVITY_SCALE, gravity_scale); } real_t RigidBody2D::get_gravity_scale() const { @@ -575,7 +575,7 @@ void RigidBody2D::set_linear_damp(real_t p_linear_damp) { ERR_FAIL_COND(p_linear_damp < -1); linear_damp = p_linear_damp; - Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_LINEAR_DAMP, linear_damp); + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_LINEAR_DAMP, linear_damp); } real_t RigidBody2D::get_linear_damp() const { @@ -586,7 +586,7 @@ void RigidBody2D::set_angular_damp(real_t p_angular_damp) { ERR_FAIL_COND(p_angular_damp < -1); angular_damp = p_angular_damp; - Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_ANGULAR_DAMP, angular_damp); + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_ANGULAR_DAMP, angular_damp); } real_t RigidBody2D::get_angular_damp() const { @@ -602,7 +602,7 @@ void RigidBody2D::set_axis_velocity(const Vector2 &p_axis) { if (state) { set_linear_velocity(v); } else { - Physics2DServer::get_singleton()->body_set_axis_velocity(get_rid(), p_axis); + PhysicsServer2D::get_singleton()->body_set_axis_velocity(get_rid(), p_axis); linear_velocity = v; } } @@ -614,7 +614,7 @@ void RigidBody2D::set_linear_velocity(const Vector2 &p_velocity) { state->set_linear_velocity(linear_velocity); else { - Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_LINEAR_VELOCITY, linear_velocity); + PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_LINEAR_VELOCITY, linear_velocity); } } @@ -629,7 +629,7 @@ void RigidBody2D::set_angular_velocity(real_t p_velocity) { if (state) state->set_angular_velocity(angular_velocity); else - Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_ANGULAR_VELOCITY, angular_velocity); + PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_ANGULAR_VELOCITY, angular_velocity); } real_t RigidBody2D::get_angular_velocity() const { @@ -642,7 +642,7 @@ void RigidBody2D::set_use_custom_integrator(bool p_enable) { return; custom_integrator = p_enable; - Physics2DServer::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable); + PhysicsServer2D::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable); } bool RigidBody2D::is_using_custom_integrator() { @@ -652,13 +652,13 @@ bool RigidBody2D::is_using_custom_integrator() { void RigidBody2D::set_sleeping(bool p_sleeping) { sleeping = p_sleeping; - Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_SLEEPING, 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; - Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_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 { @@ -674,7 +674,7 @@ bool RigidBody2D::is_sleeping() const { void RigidBody2D::set_max_contacts_reported(int p_amount) { max_contacts_reported = p_amount; - Physics2DServer::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount); + PhysicsServer2D::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount); } int RigidBody2D::get_max_contacts_reported() const { @@ -683,55 +683,55 @@ int RigidBody2D::get_max_contacts_reported() const { } void RigidBody2D::apply_central_impulse(const Vector2 &p_impulse) { - Physics2DServer::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse); + PhysicsServer2D::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse); } void RigidBody2D::apply_impulse(const Vector2 &p_offset, const Vector2 &p_impulse) { - Physics2DServer::get_singleton()->body_apply_impulse(get_rid(), p_offset, p_impulse); + PhysicsServer2D::get_singleton()->body_apply_impulse(get_rid(), p_offset, p_impulse); } void RigidBody2D::apply_torque_impulse(float p_torque) { - Physics2DServer::get_singleton()->body_apply_torque_impulse(get_rid(), p_torque); + PhysicsServer2D::get_singleton()->body_apply_torque_impulse(get_rid(), p_torque); } void RigidBody2D::set_applied_force(const Vector2 &p_force) { - Physics2DServer::get_singleton()->body_set_applied_force(get_rid(), p_force); + PhysicsServer2D::get_singleton()->body_set_applied_force(get_rid(), p_force); }; Vector2 RigidBody2D::get_applied_force() const { - return Physics2DServer::get_singleton()->body_get_applied_force(get_rid()); + return PhysicsServer2D::get_singleton()->body_get_applied_force(get_rid()); }; void RigidBody2D::set_applied_torque(const float p_torque) { - Physics2DServer::get_singleton()->body_set_applied_torque(get_rid(), p_torque); + PhysicsServer2D::get_singleton()->body_set_applied_torque(get_rid(), p_torque); }; float RigidBody2D::get_applied_torque() const { - return Physics2DServer::get_singleton()->body_get_applied_torque(get_rid()); + return PhysicsServer2D::get_singleton()->body_get_applied_torque(get_rid()); }; void RigidBody2D::add_central_force(const Vector2 &p_force) { - Physics2DServer::get_singleton()->body_add_central_force(get_rid(), p_force); + PhysicsServer2D::get_singleton()->body_add_central_force(get_rid(), p_force); } void RigidBody2D::add_force(const Vector2 &p_offset, const Vector2 &p_force) { - Physics2DServer::get_singleton()->body_add_force(get_rid(), p_offset, p_force); + PhysicsServer2D::get_singleton()->body_add_force(get_rid(), p_offset, p_force); } void RigidBody2D::add_torque(const float p_torque) { - Physics2DServer::get_singleton()->body_add_torque(get_rid(), p_torque); + PhysicsServer2D::get_singleton()->body_add_torque(get_rid(), p_torque); } void RigidBody2D::set_continuous_collision_detection_mode(CCDMode p_mode) { ccd_mode = p_mode; - Physics2DServer::get_singleton()->body_set_continuous_collision_detection_mode(get_rid(), Physics2DServer::CCDMode(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 { @@ -780,7 +780,7 @@ void RigidBody2D::set_contact_monitor(bool p_enabled) { } memdelete(contact_monitor); - contact_monitor = NULL; + contact_monitor = nullptr; } else { contact_monitor = memnew(ContactMonitor); @@ -790,7 +790,7 @@ void RigidBody2D::set_contact_monitor(bool p_enabled) { bool RigidBody2D::is_contact_monitor_enabled() const { - return contact_monitor != NULL; + return contact_monitor != nullptr; } void RigidBody2D::_notification(int p_what) { @@ -898,7 +898,7 @@ void RigidBody2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody2D::get_colliding_bodies); - BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "Physics2DDirectBodyState"))); + BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectBodyState2D"))); ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Rigid,Static,Character,Kinematic"), "set_mode", "get_mode"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mass", PROPERTY_HINT_EXP_RANGE, "0.01,65535,0.01"), "set_mass", "get_mass"); @@ -939,7 +939,7 @@ void RigidBody2D::_bind_methods() { } RigidBody2D::RigidBody2D() : - PhysicsBody2D(Physics2DServer::BODY_MODE_RIGID) { + PhysicsBody2D(PhysicsServer2D::BODY_MODE_RIGID) { mode = MODE_RIGID; @@ -950,17 +950,17 @@ RigidBody2D::RigidBody2D() : angular_damp = -1; max_contacts_reported = 0; - state = NULL; + state = nullptr; angular_velocity = 0; sleeping = false; ccd_mode = CCD_MODE_DISABLED; custom_integrator = false; - contact_monitor = NULL; + contact_monitor = nullptr; can_sleep = true; - Physics2DServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); + PhysicsServer2D::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); } RigidBody2D::~RigidBody2D() { @@ -971,11 +971,11 @@ RigidBody2D::~RigidBody2D() { void RigidBody2D::_reload_physics_characteristics() { if (physics_material_override.is_null()) { - Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, 0); - Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, 1); + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_BOUNCE, 0); + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_FRICTION, 1); } else { - Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce()); - Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, physics_material_override->computed_friction()); + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce()); + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_FRICTION, physics_material_override->computed_friction()); } } @@ -1001,12 +1001,12 @@ Ref<KinematicCollision2D> KinematicBody2D::_move(const Vector2 &p_motion, bool p bool KinematicBody2D::separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision) { - Physics2DServer::SeparationResult sep_res[8]; //max 8 rays + PhysicsServer2D::SeparationResult sep_res[8]; //max 8 rays Transform2D gt = get_global_transform(); Vector2 recover; - int hits = Physics2DServer::get_singleton()->body_test_ray_separation(get_rid(), gt, p_infinite_inertia, recover, sep_res, 8, margin); + int hits = PhysicsServer2D::get_singleton()->body_test_ray_separation(get_rid(), gt, p_infinite_inertia, recover, sep_res, 8, margin); int deepest = -1; float deepest_depth; for (int i = 0; i < hits; i++) { @@ -1042,8 +1042,8 @@ bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_ ERR_PRINT("Functions move_and_slide and move_and_collide do not work together with 'sync to physics' option. Please read the documentation."); } Transform2D gt = get_global_transform(); - Physics2DServer::MotionResult result; - bool colliding = Physics2DServer::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, margin, &result, p_exclude_raycast_shapes); + PhysicsServer2D::MotionResult result; + bool colliding = PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, margin, &result, p_exclude_raycast_shapes); if (colliding) { r_collision.collider_metadata = result.collider_metadata; @@ -1077,7 +1077,7 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const Vector2 current_floor_velocity = floor_velocity; if (on_floor && on_floor_body.is_valid()) { //this approach makes sure there is less delay between the actual body velocity and the one we saved - Physics2DDirectBodyState *bs = Physics2DServer::get_singleton()->body_get_direct_state(on_floor_body); + PhysicsDirectBodyState2D *bs = PhysicsServer2D::get_singleton()->body_get_direct_state(on_floor_body); if (bs) { current_floor_velocity = bs->get_linear_velocity(); } @@ -1227,7 +1227,7 @@ bool KinematicBody2D::test_move(const Transform2D &p_from, const Vector2 &p_moti ERR_FAIL_COND_V(!is_inside_tree(), false); - return Physics2DServer::get_singleton()->body_test_motion(get_rid(), p_from, p_motion, p_infinite_inertia, margin); + 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) { @@ -1277,11 +1277,11 @@ void KinematicBody2D::set_sync_to_physics(bool p_enable) { return; if (p_enable) { - Physics2DServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); + PhysicsServer2D::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); set_only_update_transform_changes(true); set_notify_local_transform(true); } else { - Physics2DServer::get_singleton()->body_set_force_integration_callback(get_rid(), NULL, ""); + PhysicsServer2D::get_singleton()->body_set_force_integration_callback(get_rid(), nullptr, ""); set_only_update_transform_changes(false); set_notify_local_transform(false); } @@ -1296,7 +1296,7 @@ void KinematicBody2D::_direct_state_changed(Object *p_state) { if (!sync_to_physics) return; - Physics2DDirectBodyState *state = Object::cast_to<Physics2DDirectBodyState>(p_state); + PhysicsDirectBodyState2D *state = Object::cast_to<PhysicsDirectBodyState2D>(p_state); last_valid_transform = state->get_transform(); set_notify_local_transform(false); @@ -1320,7 +1320,7 @@ void KinematicBody2D::_notification(int p_what) { if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) { //used by sync to physics, send the new transform to the physics Transform2D new_transform = get_global_transform(); - Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_TRANSFORM, new_transform); + PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_TRANSFORM, new_transform); //but then revert changes set_notify_local_transform(false); set_global_transform(last_valid_transform); @@ -1357,7 +1357,7 @@ void KinematicBody2D::_bind_methods() { } KinematicBody2D::KinematicBody2D() : - PhysicsBody2D(Physics2DServer::BODY_MODE_KINEMATIC) { + PhysicsBody2D(PhysicsServer2D::BODY_MODE_KINEMATIC) { margin = 0.08; @@ -1368,12 +1368,12 @@ KinematicBody2D::KinematicBody2D() : } KinematicBody2D::~KinematicBody2D() { if (motion_cache.is_valid()) { - motion_cache->owner = NULL; + motion_cache->owner = nullptr; } for (int i = 0; i < slide_colliders.size(); i++) { if (slide_colliders[i].is_valid()) { - slide_colliders.write[i]->owner = NULL; + slide_colliders.write[i]->owner = nullptr; } } } @@ -1394,7 +1394,7 @@ Vector2 KinematicCollision2D::get_remainder() const { return collision.remainder; } Object *KinematicCollision2D::get_local_shape() const { - if (!owner) return NULL; + if (!owner) return nullptr; uint32_t ownerid = owner->shape_find_owner(collision.local_shape); return owner->shape_owner_get_owner(ownerid); } @@ -1405,7 +1405,7 @@ Object *KinematicCollision2D::get_collider() const { return ObjectDB::get_instance(collision.collider); } - return NULL; + return nullptr; } ObjectID KinematicCollision2D::get_collider_id() const { @@ -1422,7 +1422,7 @@ Object *KinematicCollision2D::get_collider_shape() const { } } - return NULL; + return nullptr; } int KinematicCollision2D::get_collider_shape_index() const { @@ -1468,5 +1468,5 @@ KinematicCollision2D::KinematicCollision2D() { collision.collider_shape = 0; collision.local_shape = 0; - owner = NULL; + owner = nullptr; } diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 20e9f3ffcf..0d92a820e3 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -34,7 +34,7 @@ #include "core/vset.h" #include "scene/2d/collision_object_2d.h" #include "scene/resources/physics_material.h" -#include "servers/physics_2d_server.h" +#include "servers/physics_server_2d.h" class KinematicCollision2D; @@ -50,7 +50,7 @@ class PhysicsBody2D : public CollisionObject2D { protected: void _notification(int p_what); - PhysicsBody2D(Physics2DServer::BodyMode p_mode); + PhysicsBody2D(PhysicsServer2D::BodyMode p_mode); static void _bind_methods(); @@ -123,7 +123,7 @@ public: private: bool can_sleep; - Physics2DDirectBodyState *state; + PhysicsDirectBodyState2D *state; Mode mode; real_t mass; @@ -185,7 +185,7 @@ private: void _body_inout(int p_status, ObjectID p_instance, int p_body_shape, int p_local_shape); void _direct_state_changed(Object *p_state); - bool _test_motion(const Vector2 &p_motion, bool p_infinite_inertia = true, float p_margin = 0.08, const Ref<Physics2DTestMotionResult> &p_result = Ref<Physics2DTestMotionResult>()); + bool _test_motion(const Vector2 &p_motion, bool p_infinite_inertia = true, float p_margin = 0.08, const Ref<PhysicsTestMotionResult2D> &p_result = Ref<PhysicsTestMotionResult2D>()); protected: void _notification(int p_what); @@ -300,10 +300,10 @@ private: bool sync_to_physics; Vector<Collision> colliders; - Vector<Ref<KinematicCollision2D> > slide_colliders; + Vector<Ref<KinematicCollision2D>> slide_colliders; Ref<KinematicCollision2D> motion_cache; - _FORCE_INLINE_ bool _ignores_mode(Physics2DServer::BodyMode) const; + _FORCE_INLINE_ bool _ignores_mode(PhysicsServer2D::BodyMode) const; Ref<KinematicCollision2D> _move(const Vector2 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false); Ref<KinematicCollision2D> _get_slide_collision(int p_bounce); diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp index 95656b9610..84c1828b47 100644 --- a/scene/2d/polygon_2d.cpp +++ b/scene/2d/polygon_2d.cpp @@ -103,7 +103,7 @@ void Polygon2D::_notification(int p_what) { if (polygon.size() < 3) return; - Skeleton2D *skeleton_node = NULL; + Skeleton2D *skeleton_node = nullptr; if (has_node(skeleton)) { skeleton_node = Object::cast_to<Skeleton2D>(get_node(skeleton)); } @@ -111,10 +111,10 @@ void Polygon2D::_notification(int p_what) { ObjectID new_skeleton_id; if (skeleton_node) { - VS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), skeleton_node->get_skeleton()); + RS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), skeleton_node->get_skeleton()); new_skeleton_id = skeleton_node->get_instance_id(); } else { - VS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), RID()); + RS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), RID()); } if (new_skeleton_id != current_skeleton_id) { @@ -307,7 +307,7 @@ void Polygon2D::_notification(int p_what) { if (invert || polygons.size() == 0) { Vector<int> indices = Geometry::triangulate_polygon(points); if (indices.size()) { - VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID(), -1, normal_map.is_valid() ? normal_map->get_rid() : RID(), specular_map.is_valid() ? specular_map->get_rid() : RID(), Color(specular_color.r, specular_color.g, specular_color.b, shininess)); + RS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID(), -1, normal_map.is_valid() ? normal_map->get_rid() : RID(), specular_map.is_valid() ? specular_map->get_rid() : RID(), Color(specular_color.r, specular_color.g, specular_color.b, shininess)); } } else { //draw individual polygons @@ -341,7 +341,7 @@ void Polygon2D::_notification(int p_what) { } if (total_indices.size()) { - VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), total_indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID()); + RS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), total_indices, points, colors, uvs, bones, weights, texture.is_valid() ? texture->get_rid() : RID()); } } diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index fd6e0aebcc..9d6c7304ce 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -33,7 +33,7 @@ #include "collision_object_2d.h" #include "core/engine.h" #include "physics_body_2d.h" -#include "servers/physics_2d_server.h" +#include "servers/physics_server_2d.h" void RayCast2D::set_cast_to(const Vector2 &p_point) { @@ -79,7 +79,7 @@ bool RayCast2D::is_colliding() const { Object *RayCast2D::get_collider() const { if (against.is_null()) - return NULL; + return nullptr; return ObjectDB::get_instance(against); } @@ -205,7 +205,7 @@ void RayCast2D::_update_raycast_state() { Ref<World2D> w2d = get_world_2d(); ERR_FAIL_COND(w2d.is_null()); - Physics2DDirectSpaceState *dss = Physics2DServer::get_singleton()->space_get_direct_state(w2d->get_space()); + PhysicsDirectSpaceState2D *dss = PhysicsServer2D::get_singleton()->space_get_direct_state(w2d->get_space()); ERR_FAIL_COND(!dss); Transform2D gt = get_global_transform(); @@ -214,7 +214,7 @@ void RayCast2D::_update_raycast_state() { if (to == Vector2()) to = Vector2(0, 0.01); - Physics2DDirectSpaceState::RayResult rr; + PhysicsDirectSpaceState2D::RayResult rr; if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask, collide_with_bodies, collide_with_areas)) { diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp index 9ebaf23c3a..86c9ff6076 100644 --- a/scene/2d/skeleton_2d.cpp +++ b/scene/2d/skeleton_2d.cpp @@ -35,7 +35,7 @@ void Bone2D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { Node *parent = get_parent(); parent_bone = Object::cast_to<Bone2D>(parent); - skeleton = NULL; + skeleton = nullptr; while (parent) { skeleton = Object::cast_to<Skeleton2D>(parent); if (skeleton) @@ -73,9 +73,9 @@ void Bone2D::_notification(int p_what) { } } skeleton->_make_bone_setup_dirty(); - skeleton = NULL; + skeleton = nullptr; } - parent_bone = NULL; + parent_bone = nullptr; } } void Bone2D::_bind_methods() { @@ -157,8 +157,8 @@ String Bone2D::get_configuration_warning() const { } Bone2D::Bone2D() { - skeleton = NULL; - parent_bone = NULL; + skeleton = nullptr; + parent_bone = nullptr; skeleton_index = -1; default_length = 16; set_notify_local_transform(true); @@ -186,7 +186,7 @@ void Skeleton2D::_update_bone_setup() { return; bone_setup_dirty = false; - VS::get_singleton()->skeleton_allocate(skeleton, bones.size(), true); + RS::get_singleton()->skeleton_allocate(skeleton, bones.size(), true); bones.sort(); //sorty so they are always in the same order/index @@ -240,7 +240,7 @@ void Skeleton2D::_update_transform() { for (int i = 0; i < bones.size(); i++) { Transform2D final_xform = bones[i].accum_transform * bones[i].rest_inverse; - VS::get_singleton()->skeleton_bone_set_transform_2d(skeleton, i, final_xform); + RS::get_singleton()->skeleton_bone_set_transform_2d(skeleton, i, final_xform); } } @@ -257,8 +257,8 @@ int Skeleton2D::get_bone_count() const { Bone2D *Skeleton2D::get_bone(int p_idx) { - ERR_FAIL_COND_V(!is_inside_tree(), NULL); - ERR_FAIL_INDEX_V(p_idx, bones.size(), NULL); + ERR_FAIL_COND_V(!is_inside_tree(), nullptr); + ERR_FAIL_INDEX_V(p_idx, bones.size(), nullptr); return bones[p_idx].bone; } @@ -276,7 +276,7 @@ void Skeleton2D::_notification(int p_what) { } if (p_what == NOTIFICATION_TRANSFORM_CHANGED) { - VS::get_singleton()->skeleton_set_base_transform_2d(skeleton, get_global_transform()); + RS::get_singleton()->skeleton_set_base_transform_2d(skeleton, get_global_transform()); } } @@ -300,11 +300,11 @@ Skeleton2D::Skeleton2D() { bone_setup_dirty = true; transform_dirty = true; - skeleton = VS::get_singleton()->skeleton_create(); + skeleton = RS::get_singleton()->skeleton_create(); set_notify_transform(true); } Skeleton2D::~Skeleton2D() { - VS::get_singleton()->free(skeleton); + RS::get_singleton()->free(skeleton); } diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite_2d.cpp index 7eaafe5348..df8859bd9a 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite_2d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* sprite.cpp */ +/* sprite_2d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,57 +28,57 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "sprite.h" +#include "sprite_2d.h" #include "core/core_string_names.h" #include "core/os/os.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" #include "scene/scene_string_names.h" #ifdef TOOLS_ENABLED -Dictionary Sprite::_edit_get_state() const { +Dictionary Sprite2D::_edit_get_state() const { Dictionary state = Node2D::_edit_get_state(); state["offset"] = offset; return state; } -void Sprite::_edit_set_state(const Dictionary &p_state) { +void Sprite2D::_edit_set_state(const Dictionary &p_state) { Node2D::_edit_set_state(p_state); set_offset(p_state["offset"]); } -void Sprite::_edit_set_pivot(const Point2 &p_pivot) { +void Sprite2D::_edit_set_pivot(const Point2 &p_pivot) { set_offset(get_offset() - p_pivot); set_position(get_transform().xform(p_pivot)); } -Point2 Sprite::_edit_get_pivot() const { +Point2 Sprite2D::_edit_get_pivot() const { return Vector2(); } -bool Sprite::_edit_use_pivot() const { +bool Sprite2D::_edit_use_pivot() const { return true; } -bool Sprite::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { +bool Sprite2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { return is_pixel_opaque(p_point); } -Rect2 Sprite::_edit_get_rect() const { +Rect2 Sprite2D::_edit_get_rect() const { return get_rect(); } -bool Sprite::_edit_use_rect() const { +bool Sprite2D::_edit_use_rect() const { return texture.is_valid(); } #endif -Rect2 Sprite::get_anchorable_rect() const { +Rect2 Sprite2D::get_anchorable_rect() const { return get_rect(); } -void Sprite::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_clip) const { +void Sprite2D::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_clip) const { Rect2 base_rect; @@ -112,7 +112,7 @@ void Sprite::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_cli r_dst_rect.size.y = -r_dst_rect.size.y; } -void Sprite::_notification(int p_what) { +void Sprite2D::_notification(int p_what) { switch (p_what) { @@ -131,24 +131,24 @@ void Sprite::_notification(int p_what) { Rect2 src_rect, dst_rect; bool filter_clip; _get_rects(src_rect, dst_rect, filter_clip); - texture->draw_rect_region(ci, dst_rect, src_rect, Color(1, 1, 1), false, normal_map, specular, Color(specular_color.r, specular_color.g, specular_color.b, shininess), VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, filter_clip); + texture->draw_rect_region(ci, dst_rect, src_rect, Color(1, 1, 1), false, normal_map, specular, Color(specular_color.r, specular_color.g, specular_color.b, shininess), RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, filter_clip); } break; } } -void Sprite::set_texture(const Ref<Texture2D> &p_texture) { +void Sprite2D::set_texture(const Ref<Texture2D> &p_texture) { if (p_texture == texture) return; if (texture.is_valid()) - texture->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Sprite::_texture_changed)); + texture->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Sprite2D::_texture_changed)); texture = p_texture; if (texture.is_valid()) - texture->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Sprite::_texture_changed)); + texture->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Sprite2D::_texture_changed)); update(); emit_signal("texture_changed"); @@ -156,96 +156,96 @@ void Sprite::set_texture(const Ref<Texture2D> &p_texture) { _change_notify("texture"); } -void Sprite::set_normal_map(const Ref<Texture2D> &p_texture) { +void Sprite2D::set_normal_map(const Ref<Texture2D> &p_texture) { normal_map = p_texture; update(); } -Ref<Texture2D> Sprite::get_normal_map() const { +Ref<Texture2D> Sprite2D::get_normal_map() const { return normal_map; } -void Sprite::set_specular_map(const Ref<Texture2D> &p_texture) { +void Sprite2D::set_specular_map(const Ref<Texture2D> &p_texture) { specular = p_texture; update(); } -Ref<Texture2D> Sprite::get_specular_map() const { +Ref<Texture2D> Sprite2D::get_specular_map() const { return specular; } -void Sprite::set_specular_color(const Color &p_color) { +void Sprite2D::set_specular_color(const Color &p_color) { specular_color = p_color; update(); } -Color Sprite::get_specular_color() const { +Color Sprite2D::get_specular_color() const { return specular_color; } -void Sprite::set_shininess(float p_shininess) { +void Sprite2D::set_shininess(float p_shininess) { shininess = CLAMP(p_shininess, 0.0, 1.0); update(); } -float Sprite::get_shininess() const { +float Sprite2D::get_shininess() const { return shininess; } -Ref<Texture2D> Sprite::get_texture() const { +Ref<Texture2D> Sprite2D::get_texture() const { return texture; } -void Sprite::set_centered(bool p_center) { +void Sprite2D::set_centered(bool p_center) { centered = p_center; update(); item_rect_changed(); } -bool Sprite::is_centered() const { +bool Sprite2D::is_centered() const { return centered; } -void Sprite::set_offset(const Point2 &p_offset) { +void Sprite2D::set_offset(const Point2 &p_offset) { offset = p_offset; update(); item_rect_changed(); _change_notify("offset"); } -Point2 Sprite::get_offset() const { +Point2 Sprite2D::get_offset() const { return offset; } -void Sprite::set_flip_h(bool p_flip) { +void Sprite2D::set_flip_h(bool p_flip) { hflip = p_flip; update(); } -bool Sprite::is_flipped_h() const { +bool Sprite2D::is_flipped_h() const { return hflip; } -void Sprite::set_flip_v(bool p_flip) { +void Sprite2D::set_flip_v(bool p_flip) { vflip = p_flip; update(); } -bool Sprite::is_flipped_v() const { +bool Sprite2D::is_flipped_v() const { return vflip; } -void Sprite::set_region(bool p_region) { +void Sprite2D::set_region(bool p_region) { if (p_region == region) return; @@ -254,12 +254,12 @@ void Sprite::set_region(bool p_region) { update(); } -bool Sprite::is_region() const { +bool Sprite2D::is_region() const { return region; } -void Sprite::set_region_rect(const Rect2 &p_region_rect) { +void Sprite2D::set_region_rect(const Rect2 &p_region_rect) { if (region_rect == p_region_rect) return; @@ -272,21 +272,21 @@ void Sprite::set_region_rect(const Rect2 &p_region_rect) { _change_notify("region_rect"); } -Rect2 Sprite::get_region_rect() const { +Rect2 Sprite2D::get_region_rect() const { return region_rect; } -void Sprite::set_region_filter_clip(bool p_enable) { +void Sprite2D::set_region_filter_clip(bool p_enable) { region_filter_clip = p_enable; update(); } -bool Sprite::is_region_filter_clip_enabled() const { +bool Sprite2D::is_region_filter_clip_enabled() const { return region_filter_clip; } -void Sprite::set_frame(int p_frame) { +void Sprite2D::set_frame(int p_frame) { ERR_FAIL_INDEX(p_frame, vframes * hframes); @@ -300,23 +300,23 @@ void Sprite::set_frame(int p_frame) { emit_signal(SceneStringNames::get_singleton()->frame_changed); } -int Sprite::get_frame() const { +int Sprite2D::get_frame() const { return frame; } -void Sprite::set_frame_coords(const Vector2 &p_coord) { +void Sprite2D::set_frame_coords(const Vector2 &p_coord) { ERR_FAIL_INDEX(int(p_coord.x), hframes); ERR_FAIL_INDEX(int(p_coord.y), vframes); set_frame(int(p_coord.y) * hframes + int(p_coord.x)); } -Vector2 Sprite::get_frame_coords() const { +Vector2 Sprite2D::get_frame_coords() const { return Vector2(frame % hframes, frame / hframes); } -void Sprite::set_vframes(int p_amount) { +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; @@ -324,12 +324,12 @@ void Sprite::set_vframes(int p_amount) { item_rect_changed(); _change_notify(); } -int Sprite::get_vframes() const { +int Sprite2D::get_vframes() const { return vframes; } -void Sprite::set_hframes(int p_amount) { +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; @@ -337,12 +337,12 @@ void Sprite::set_hframes(int p_amount) { item_rect_changed(); _change_notify(); } -int Sprite::get_hframes() const { +int Sprite2D::get_hframes() const { return hframes; } -bool Sprite::is_pixel_opaque(const Point2 &p_point) const { +bool Sprite2D::is_pixel_opaque(const Point2 &p_point) const { if (texture.is_null()) return false; @@ -392,7 +392,7 @@ bool Sprite::is_pixel_opaque(const Point2 &p_point) const { return texture->is_pixel_opaque((int)q.x, (int)q.y); } -Rect2 Sprite::get_rect() const { +Rect2 Sprite2D::get_rect() const { if (texture.is_null()) return Rect2(0, 0, 1, 1); @@ -417,7 +417,7 @@ Rect2 Sprite::get_rect() const { return Rect2(ofs, s); } -void Sprite::_validate_property(PropertyInfo &property) const { +void Sprite2D::_validate_property(PropertyInfo &property) const { if (property.name == "frame") { property.hint = PROPERTY_HINT_RANGE; @@ -430,7 +430,7 @@ void Sprite::_validate_property(PropertyInfo &property) const { } } -void Sprite::_texture_changed() { +void Sprite2D::_texture_changed() { // Changes to the texture need to trigger an update to make // the editor redraw the sprite with the updated texture. @@ -439,59 +439,59 @@ void Sprite::_texture_changed() { } } -void Sprite::_bind_methods() { +void Sprite2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_texture", "texture"), &Sprite::set_texture); - ClassDB::bind_method(D_METHOD("get_texture"), &Sprite::get_texture); + ClassDB::bind_method(D_METHOD("set_texture", "texture"), &Sprite2D::set_texture); + ClassDB::bind_method(D_METHOD("get_texture"), &Sprite2D::get_texture); - ClassDB::bind_method(D_METHOD("set_normal_map", "normal_map"), &Sprite::set_normal_map); - ClassDB::bind_method(D_METHOD("get_normal_map"), &Sprite::get_normal_map); + ClassDB::bind_method(D_METHOD("set_normal_map", "normal_map"), &Sprite2D::set_normal_map); + ClassDB::bind_method(D_METHOD("get_normal_map"), &Sprite2D::get_normal_map); - ClassDB::bind_method(D_METHOD("set_specular_map", "specular_map"), &Sprite::set_specular_map); - ClassDB::bind_method(D_METHOD("get_specular_map"), &Sprite::get_specular_map); + ClassDB::bind_method(D_METHOD("set_specular_map", "specular_map"), &Sprite2D::set_specular_map); + ClassDB::bind_method(D_METHOD("get_specular_map"), &Sprite2D::get_specular_map); - ClassDB::bind_method(D_METHOD("set_specular_color", "specular_color"), &Sprite::set_specular_color); - ClassDB::bind_method(D_METHOD("get_specular_color"), &Sprite::get_specular_color); + ClassDB::bind_method(D_METHOD("set_specular_color", "specular_color"), &Sprite2D::set_specular_color); + ClassDB::bind_method(D_METHOD("get_specular_color"), &Sprite2D::get_specular_color); - ClassDB::bind_method(D_METHOD("set_shininess", "shininess"), &Sprite::set_shininess); - ClassDB::bind_method(D_METHOD("get_shininess"), &Sprite::get_shininess); + ClassDB::bind_method(D_METHOD("set_shininess", "shininess"), &Sprite2D::set_shininess); + ClassDB::bind_method(D_METHOD("get_shininess"), &Sprite2D::get_shininess); - ClassDB::bind_method(D_METHOD("set_centered", "centered"), &Sprite::set_centered); - ClassDB::bind_method(D_METHOD("is_centered"), &Sprite::is_centered); + ClassDB::bind_method(D_METHOD("set_centered", "centered"), &Sprite2D::set_centered); + ClassDB::bind_method(D_METHOD("is_centered"), &Sprite2D::is_centered); - ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Sprite::set_offset); - ClassDB::bind_method(D_METHOD("get_offset"), &Sprite::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Sprite2D::set_offset); + ClassDB::bind_method(D_METHOD("get_offset"), &Sprite2D::get_offset); - ClassDB::bind_method(D_METHOD("set_flip_h", "flip_h"), &Sprite::set_flip_h); - ClassDB::bind_method(D_METHOD("is_flipped_h"), &Sprite::is_flipped_h); + ClassDB::bind_method(D_METHOD("set_flip_h", "flip_h"), &Sprite2D::set_flip_h); + ClassDB::bind_method(D_METHOD("is_flipped_h"), &Sprite2D::is_flipped_h); - ClassDB::bind_method(D_METHOD("set_flip_v", "flip_v"), &Sprite::set_flip_v); - ClassDB::bind_method(D_METHOD("is_flipped_v"), &Sprite::is_flipped_v); + ClassDB::bind_method(D_METHOD("set_flip_v", "flip_v"), &Sprite2D::set_flip_v); + ClassDB::bind_method(D_METHOD("is_flipped_v"), &Sprite2D::is_flipped_v); - ClassDB::bind_method(D_METHOD("set_region", "enabled"), &Sprite::set_region); - ClassDB::bind_method(D_METHOD("is_region"), &Sprite::is_region); + ClassDB::bind_method(D_METHOD("set_region", "enabled"), &Sprite2D::set_region); + ClassDB::bind_method(D_METHOD("is_region"), &Sprite2D::is_region); - ClassDB::bind_method(D_METHOD("is_pixel_opaque", "pos"), &Sprite::is_pixel_opaque); + ClassDB::bind_method(D_METHOD("is_pixel_opaque", "pos"), &Sprite2D::is_pixel_opaque); - ClassDB::bind_method(D_METHOD("set_region_rect", "rect"), &Sprite::set_region_rect); - ClassDB::bind_method(D_METHOD("get_region_rect"), &Sprite::get_region_rect); + ClassDB::bind_method(D_METHOD("set_region_rect", "rect"), &Sprite2D::set_region_rect); + ClassDB::bind_method(D_METHOD("get_region_rect"), &Sprite2D::get_region_rect); - ClassDB::bind_method(D_METHOD("set_region_filter_clip", "enabled"), &Sprite::set_region_filter_clip); - ClassDB::bind_method(D_METHOD("is_region_filter_clip_enabled"), &Sprite::is_region_filter_clip_enabled); + ClassDB::bind_method(D_METHOD("set_region_filter_clip", "enabled"), &Sprite2D::set_region_filter_clip); + ClassDB::bind_method(D_METHOD("is_region_filter_clip_enabled"), &Sprite2D::is_region_filter_clip_enabled); - ClassDB::bind_method(D_METHOD("set_frame", "frame"), &Sprite::set_frame); - ClassDB::bind_method(D_METHOD("get_frame"), &Sprite::get_frame); + ClassDB::bind_method(D_METHOD("set_frame", "frame"), &Sprite2D::set_frame); + ClassDB::bind_method(D_METHOD("get_frame"), &Sprite2D::get_frame); - ClassDB::bind_method(D_METHOD("set_frame_coords", "coords"), &Sprite::set_frame_coords); - ClassDB::bind_method(D_METHOD("get_frame_coords"), &Sprite::get_frame_coords); + ClassDB::bind_method(D_METHOD("set_frame_coords", "coords"), &Sprite2D::set_frame_coords); + ClassDB::bind_method(D_METHOD("get_frame_coords"), &Sprite2D::get_frame_coords); - ClassDB::bind_method(D_METHOD("set_vframes", "vframes"), &Sprite::set_vframes); - ClassDB::bind_method(D_METHOD("get_vframes"), &Sprite::get_vframes); + ClassDB::bind_method(D_METHOD("set_vframes", "vframes"), &Sprite2D::set_vframes); + ClassDB::bind_method(D_METHOD("get_vframes"), &Sprite2D::get_vframes); - ClassDB::bind_method(D_METHOD("set_hframes", "hframes"), &Sprite::set_hframes); - ClassDB::bind_method(D_METHOD("get_hframes"), &Sprite::get_hframes); + ClassDB::bind_method(D_METHOD("set_hframes", "hframes"), &Sprite2D::set_hframes); + ClassDB::bind_method(D_METHOD("get_hframes"), &Sprite2D::get_hframes); - ClassDB::bind_method(D_METHOD("get_rect"), &Sprite::get_rect); + ClassDB::bind_method(D_METHOD("get_rect"), &Sprite2D::get_rect); ADD_SIGNAL(MethodInfo("frame_changed")); ADD_SIGNAL(MethodInfo("texture_changed")); @@ -519,7 +519,7 @@ void Sprite::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "region_filter_clip"), "set_region_filter_clip", "is_region_filter_clip_enabled"); } -Sprite::Sprite() { +Sprite2D::Sprite2D() { centered = true; hflip = false; @@ -535,5 +535,5 @@ Sprite::Sprite() { hframes = 1; } -Sprite::~Sprite() { +Sprite2D::~Sprite2D() { } diff --git a/scene/2d/sprite.h b/scene/2d/sprite_2d.h index a96f023231..599a9e937e 100644 --- a/scene/2d/sprite.h +++ b/scene/2d/sprite_2d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* sprite.h */ +/* sprite_2d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef SPRITE_H -#define SPRITE_H +#ifndef SPRITE_2D_H +#define SPRITE_2D_H #include "scene/2d/node_2d.h" #include "scene/resources/texture.h" -class Sprite : public Node2D { +class Sprite2D : public Node2D { - GDCLASS(Sprite, Node2D); + GDCLASS(Sprite2D, Node2D); Ref<Texture2D> texture; Ref<Texture2D> normal_map; @@ -136,8 +136,8 @@ public: Rect2 get_rect() const; virtual Rect2 get_anchorable_rect() const; - Sprite(); - ~Sprite(); + Sprite2D(); + ~Sprite2D(); }; #endif // SPRITE_H diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 601be17274..1cf12e4421 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -35,8 +35,8 @@ #include "core/method_bind_ext.gen.inc" #include "core/os/os.h" #include "scene/2d/area_2d.h" -#include "servers/navigation_2d_server.h" -#include "servers/physics_2d_server.h" +#include "servers/navigation_server_2d.h" +#include "servers/physics_server_2d.h" int TileMap::_get_quadrant_size() const { @@ -87,7 +87,7 @@ void TileMap::_notification(int p_what) { if (navigation) { for (Map<PosKey, Quadrant::NavPoly>::Element *F = q.navpoly_ids.front(); F; F = F->next()) { - Navigation2DServer::get_singleton()->region_set_map(F->get().region, RID()); + NavigationServer2D::get_singleton()->region_set_map(F->get().region, RID()); } q.navpoly_ids.clear(); } @@ -98,13 +98,13 @@ void TileMap::_notification(int p_what) { } for (Map<PosKey, Quadrant::Occluder>::Element *F = q.occluder_instances.front(); F; F = F->next()) { - VS::get_singleton()->free(F->get().id); + RS::get_singleton()->free(F->get().id); } q.occluder_instances.clear(); } - collision_parent = NULL; - navigation = NULL; + collision_parent = nullptr; + navigation = nullptr; } break; @@ -130,7 +130,7 @@ void TileMap::_update_quadrant_space(const RID &p_space) { for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { Quadrant &q = E->get(); - Physics2DServer::get_singleton()->body_set_space(q.body, p_space); + PhysicsServer2D::get_singleton()->body_set_space(q.body, p_space); } } } @@ -158,18 +158,18 @@ void TileMap::_update_quadrant_transform() { if (!use_parent) { xform = global_transform * xform; - Physics2DServer::get_singleton()->body_set_state(q.body, Physics2DServer::BODY_STATE_TRANSFORM, xform); + PhysicsServer2D::get_singleton()->body_set_state(q.body, PhysicsServer2D::BODY_STATE_TRANSFORM, xform); } if (navigation) { for (Map<PosKey, Quadrant::NavPoly>::Element *F = q.navpoly_ids.front(); F; F = F->next()) { - Navigation2DServer::get_singleton()->region_set_transform(F->get().region, nav_rel * F->get().xform); + NavigationServer2D::get_singleton()->region_set_transform(F->get().region, nav_rel * F->get().xform); } } for (Map<PosKey, Quadrant::Occluder>::Element *F = q.occluder_instances.front(); F; F = F->next()) { - VS::get_singleton()->canvas_light_occluder_set_transform(F->get().id, global_transform * F->get().xform); + RS::get_singleton()->canvas_light_occluder_set_transform(F->get().id, global_transform * F->get().xform); } } } @@ -298,7 +298,7 @@ void TileMap::_fix_cell_transform(Transform2D &xform, const Cell &p_cell, const } void TileMap::_add_shape(int &shape_idx, const Quadrant &p_q, const Ref<Shape2D> &p_shape, const TileSet::ShapeData &p_shape_data, const Transform2D &p_xform, const Vector2 &p_metadata) { - Physics2DServer *ps = Physics2DServer::get_singleton(); + PhysicsServer2D *ps = PhysicsServer2D::get_singleton(); if (!use_parent) { ps->body_add_shape(p_q.body, p_shape->get_rid(), p_xform); @@ -314,7 +314,7 @@ void TileMap::_add_shape(int &shape_idx, const Quadrant &p_q, const Ref<Shape2D> int real_index = collision_parent->shape_owner_get_shape_index(p_q.shape_owner_id, shape_idx); RID rid = collision_parent->get_rid(); - if (Object::cast_to<Area2D>(collision_parent) != NULL) { + if (Object::cast_to<Area2D>(collision_parent) != nullptr) { ps->area_set_shape_transform(rid, real_index, get_transform() * xform); } else { ps->body_set_shape_transform(rid, real_index, get_transform() * xform); @@ -334,8 +334,8 @@ void TileMap::update_dirty_quadrants() { return; } - VisualServer *vs = VisualServer::get_singleton(); - Physics2DServer *ps = Physics2DServer::get_singleton(); + RenderingServer *vs = RenderingServer::get_singleton(); + PhysicsServer2D *ps = PhysicsServer2D::get_singleton(); Vector2 tofs = get_cell_draw_offset(); Transform2D nav_rel; if (navigation) @@ -378,13 +378,13 @@ void TileMap::update_dirty_quadrants() { if (navigation) { for (Map<PosKey, Quadrant::NavPoly>::Element *E = q.navpoly_ids.front(); E; E = E->next()) { - Navigation2DServer::get_singleton()->region_set_map(E->get().region, RID()); + NavigationServer2D::get_singleton()->region_set_map(E->get().region, RID()); } q.navpoly_ids.clear(); } for (Map<PosKey, Quadrant::Occluder>::Element *E = q.occluder_instances.front(); E; E = E->next()) { - VS::get_singleton()->free(E->get().id); + RS::get_singleton()->free(E->get().id); } q.occluder_instances.clear(); Ref<ShaderMaterial> prev_material; @@ -439,7 +439,7 @@ void TileMap::update_dirty_quadrants() { 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); - vs->canvas_item_set_z_index(debug_canvas_item, VS::CANVAS_ITEM_Z_MAX - 1); + vs->canvas_item_set_z_index(debug_canvas_item, RS::CANVAS_ITEM_Z_MAX - 1); q.canvas_items.push_back(debug_canvas_item); prev_debug_canvas_item = debug_canvas_item; } @@ -550,7 +550,7 @@ void TileMap::update_dirty_quadrants() { if (r == Rect2()) { tex->draw_rect(canvas_item, rect, false, modulate, c.transpose, normal_map); } else { - tex->draw_rect_region(canvas_item, rect, r, modulate, c.transpose, normal_map, Ref<Texture2D>(), Color(1, 1, 1, 1), VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, clip_uv); + tex->draw_rect_region(canvas_item, rect, r, modulate, c.transpose, normal_map, Ref<Texture2D>(), Color(1, 1, 1, 1), RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, clip_uv); } Vector<TileSet::ShapeData> shapes = tile_set->tile_get_shapes(c.id); @@ -612,10 +612,10 @@ void TileMap::update_dirty_quadrants() { xform.set_origin(offset.floor() + q.pos); _fix_cell_transform(xform, c, npoly_ofs, s); - RID region = Navigation2DServer::get_singleton()->region_create(); - Navigation2DServer::get_singleton()->region_set_map(region, navigation->get_rid()); - Navigation2DServer::get_singleton()->region_set_transform(region, nav_rel * xform); - Navigation2DServer::get_singleton()->region_set_navpoly(region, navpoly); + RID region = NavigationServer2D::get_singleton()->region_create(); + NavigationServer2D::get_singleton()->region_set_map(region, navigation->get_rid()); + NavigationServer2D::get_singleton()->region_set_transform(region, nav_rel * xform); + NavigationServer2D::get_singleton()->region_set_navpoly(region, navpoly); Quadrant::NavPoly np; np.region = region; @@ -626,7 +626,7 @@ void TileMap::update_dirty_quadrants() { RID debug_navigation_item = vs->canvas_item_create(); vs->canvas_item_set_parent(debug_navigation_item, canvas_item); vs->canvas_item_set_z_as_relative_to_parent(debug_navigation_item, false); - vs->canvas_item_set_z_index(debug_navigation_item, VS::CANVAS_ITEM_Z_MAX - 2); // Display one below collision debug + vs->canvas_item_set_z_index(debug_navigation_item, RS::CANVAS_ITEM_Z_MAX - 2); // Display one below collision debug if (debug_navigation_item.is_valid()) { Vector<Vector2> navigation_polygon_vertices = navpoly->get_vertices(); @@ -685,11 +685,11 @@ void TileMap::update_dirty_quadrants() { xform.set_origin(offset.floor() + q.pos); _fix_cell_transform(xform, c, occluder_ofs, s); - RID orid = VS::get_singleton()->canvas_light_occluder_create(); - VS::get_singleton()->canvas_light_occluder_set_transform(orid, get_global_transform() * xform); - VS::get_singleton()->canvas_light_occluder_set_polygon(orid, occluder->get_rid()); - VS::get_singleton()->canvas_light_occluder_attach_to_canvas(orid, get_canvas()); - VS::get_singleton()->canvas_light_occluder_set_light_mask(orid, occluder_light_mask); + RID orid = RS::get_singleton()->canvas_light_occluder_create(); + RS::get_singleton()->canvas_light_occluder_set_transform(orid, get_global_transform() * xform); + RS::get_singleton()->canvas_light_occluder_set_polygon(orid, occluder->get_rid()); + RS::get_singleton()->canvas_light_occluder_attach_to_canvas(orid, get_canvas()); + RS::get_singleton()->canvas_light_occluder_set_light_mask(orid, occluder_light_mask); Quadrant::Occluder oc; oc.xform = xform; oc.id = orid; @@ -711,7 +711,7 @@ void TileMap::update_dirty_quadrants() { Quadrant &q = E->get(); for (List<RID>::Element *F = q.canvas_items.front(); F; F = F->next()) { - VS::get_singleton()->canvas_item_set_draw_index(F->get(), index++); + RS::get_singleton()->canvas_item_set_draw_index(F->get(), index++); } } @@ -763,24 +763,24 @@ Map<TileMap::PosKey, TileMap::Quadrant>::Element *TileMap::_create_quadrant(cons q.pos.y += cell_size.y; xform.set_origin(q.pos); - //q.canvas_item = VisualServer::get_singleton()->canvas_item_create(); + //q.canvas_item = RenderingServer::get_singleton()->canvas_item_create(); if (!use_parent) { - q.body = Physics2DServer::get_singleton()->body_create(); - Physics2DServer::get_singleton()->body_set_mode(q.body, use_kinematic ? Physics2DServer::BODY_MODE_KINEMATIC : Physics2DServer::BODY_MODE_STATIC); + q.body = PhysicsServer2D::get_singleton()->body_create(); + PhysicsServer2D::get_singleton()->body_set_mode(q.body, use_kinematic ? PhysicsServer2D::BODY_MODE_KINEMATIC : PhysicsServer2D::BODY_MODE_STATIC); - Physics2DServer::get_singleton()->body_attach_object_instance_id(q.body, get_instance_id()); - Physics2DServer::get_singleton()->body_set_collision_layer(q.body, collision_layer); - Physics2DServer::get_singleton()->body_set_collision_mask(q.body, collision_mask); - Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_FRICTION, friction); - Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_BOUNCE, bounce); + PhysicsServer2D::get_singleton()->body_attach_object_instance_id(q.body, get_instance_id()); + PhysicsServer2D::get_singleton()->body_set_collision_layer(q.body, collision_layer); + PhysicsServer2D::get_singleton()->body_set_collision_mask(q.body, collision_mask); + PhysicsServer2D::get_singleton()->body_set_param(q.body, PhysicsServer2D::BODY_PARAM_FRICTION, friction); + PhysicsServer2D::get_singleton()->body_set_param(q.body, PhysicsServer2D::BODY_PARAM_BOUNCE, bounce); if (is_inside_tree()) { xform = get_global_transform() * xform; RID space = get_world_2d()->get_space(); - Physics2DServer::get_singleton()->body_set_space(q.body, space); + PhysicsServer2D::get_singleton()->body_set_space(q.body, space); } - Physics2DServer::get_singleton()->body_set_state(q.body, Physics2DServer::BODY_STATE_TRANSFORM, xform); + PhysicsServer2D::get_singleton()->body_set_state(q.body, PhysicsServer2D::BODY_STATE_TRANSFORM, xform); } else if (collision_parent) { xform = get_transform() * xform; q.shape_owner_id = collision_parent->create_shape_owner(this); @@ -797,14 +797,14 @@ void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) { Quadrant &q = Q->get(); if (!use_parent) { - Physics2DServer::get_singleton()->free(q.body); + PhysicsServer2D::get_singleton()->free(q.body); } else if (collision_parent) { collision_parent->remove_shape_owner(q.shape_owner_id); } for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) { - VisualServer::get_singleton()->free(E->get()); + RenderingServer::get_singleton()->free(E->get()); } q.canvas_items.clear(); if (q.dirty_list.in_list()) @@ -813,13 +813,13 @@ 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()) { - Navigation2DServer::get_singleton()->region_set_map(E->get().region, RID()); + NavigationServer2D::get_singleton()->region_set_map(E->get().region, RID()); } q.navpoly_ids.clear(); } for (Map<PosKey, Quadrant::Occluder>::Element *E = q.occluder_instances.front(); E; E = E->next()) { - VS::get_singleton()->free(E->get().id); + RS::get_singleton()->free(E->get().id); } q.occluder_instances.clear(); @@ -921,7 +921,7 @@ 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); - if (dirty_bitmask.find(p) == NULL) { + if (dirty_bitmask.find(p) == nullptr) { dirty_bitmask.push_back(p); } } @@ -962,7 +962,7 @@ 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); - if (E != NULL) { + if (E != nullptr) { int id = get_cell(p_x, p_y); if (tile_set->tile_get_tile_mode(id) == TileSet::AUTO_TILE) { uint16_t mask = 0; @@ -1197,7 +1197,7 @@ void TileMap::_update_all_items_material_state() { void TileMap::_update_item_material_state(const RID &p_canvas_item) { - VS::get_singleton()->canvas_item_set_use_parent_material(p_canvas_item, get_use_parent_material() || get_material().is_valid()); + RS::get_singleton()->canvas_item_set_use_parent_material(p_canvas_item, get_use_parent_material() || get_material().is_valid()); } void TileMap::clear() { @@ -1302,7 +1302,7 @@ void TileMap::set_collision_layer(uint32_t p_layer) { for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { Quadrant &q = E->get(); - Physics2DServer::get_singleton()->body_set_collision_layer(q.body, collision_layer); + PhysicsServer2D::get_singleton()->body_set_collision_layer(q.body, collision_layer); } } } @@ -1314,7 +1314,7 @@ void TileMap::set_collision_mask(uint32_t p_mask) { for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { Quadrant &q = E->get(); - Physics2DServer::get_singleton()->body_set_collision_mask(q.body, collision_mask); + PhysicsServer2D::get_singleton()->body_set_collision_mask(q.body, collision_mask); } } } @@ -1368,7 +1368,7 @@ void TileMap::set_collision_use_parent(bool p_use_parent) { if (use_parent && is_inside_tree()) { collision_parent = Object::cast_to<CollisionObject2D>(get_parent()); } else { - collision_parent = NULL; + collision_parent = nullptr; } _recreate_quadrants(); @@ -1383,7 +1383,7 @@ void TileMap::set_collision_friction(float p_friction) { for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { Quadrant &q = E->get(); - Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_FRICTION, p_friction); + PhysicsServer2D::get_singleton()->body_set_param(q.body, PhysicsServer2D::BODY_PARAM_FRICTION, p_friction); } } } @@ -1400,7 +1400,7 @@ void TileMap::set_collision_bounce(float p_bounce) { for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { Quadrant &q = E->get(); - Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_BOUNCE, p_bounce); + PhysicsServer2D::get_singleton()->body_set_param(q.body, PhysicsServer2D::BODY_PARAM_BOUNCE, p_bounce); } } } @@ -1655,7 +1655,7 @@ void TileMap::set_y_sort_mode(bool p_enable) { _clear_quadrants(); y_sort_mode = p_enable; - VS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), y_sort_mode); + RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), y_sort_mode); _recreate_quadrants(); emit_signal("settings_changed"); } @@ -1746,7 +1746,7 @@ void TileMap::set_occluder_light_mask(int 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()) { - VisualServer::get_singleton()->canvas_light_occluder_set_light_mask(F->get().id, occluder_light_mask); + RenderingServer::get_singleton()->canvas_light_occluder_set_light_mask(F->get().id, occluder_light_mask); } } } @@ -1762,7 +1762,7 @@ void TileMap::set_light_mask(int 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()) { - VisualServer::get_singleton()->canvas_item_set_light_mask(F->get(), get_light_mask()); + RenderingServer::get_singleton()->canvas_item_set_light_mask(F->get(), get_light_mask()); } } } @@ -1959,9 +1959,9 @@ TileMap::TileMap() { mode = MODE_SQUARE; half_offset = HALF_OFFSET_DISABLED; use_parent = false; - collision_parent = NULL; + collision_parent = nullptr; use_kinematic = false; - navigation = NULL; + navigation = nullptr; y_sort_mode = false; compatibility_mode = false; centered_textures = false; diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp index 1cca45b422..2cb979a0e0 100644 --- a/scene/2d/touch_screen_button.cpp +++ b/scene/2d/touch_screen_button.cpp @@ -30,10 +30,11 @@ #include "touch_screen_button.h" -#include "core/input_map.h" -#include "core/os/input.h" +#include "core/input/input_filter.h" +#include "core/input/input_map.h" #include "core/os/os.h" - +#include "scene/main/window.h" +# void TouchScreenButton::set_texture(const Ref<Texture2D> &p_texture) { texture = p_texture; @@ -114,7 +115,7 @@ void TouchScreenButton::_notification(int p_what) { if (!is_inside_tree()) return; - if (!Engine::get_singleton()->is_editor_hint() && !OS::get_singleton()->has_touchscreen_ui_hint() && visibility == VISIBILITY_TOUCHSCREEN_ONLY) + 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) { @@ -145,7 +146,7 @@ void TouchScreenButton::_notification(int p_what) { } break; case NOTIFICATION_ENTER_TREE: { - if (!Engine::get_singleton()->is_editor_hint() && !OS::get_singleton()->has_touchscreen_ui_hint() && visibility == VISIBILITY_TOUCHSCREEN_ONLY) + 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(); @@ -289,12 +290,12 @@ void TouchScreenButton::_press(int p_finger_pressed) { if (action != StringName()) { - Input::get_singleton()->action_press(action); + InputFilter::get_singleton()->action_press(action); Ref<InputEventAction> iea; iea.instance(); iea->set_action(action); iea->set_pressed(true); - get_tree()->input_event(iea); + get_viewport()->input(iea, true); } emit_signal("pressed"); @@ -307,14 +308,14 @@ void TouchScreenButton::_release(bool p_exiting_tree) { if (action != StringName()) { - Input::get_singleton()->action_release(action); + InputFilter::get_singleton()->action_release(action); if (!p_exiting_tree) { Ref<InputEventAction> iea; iea.instance(); iea->set_action(action); iea->set_pressed(false); - get_tree()->input_event(iea); + get_viewport()->input(iea, true); } } diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index 366de28386..c374dd5faa 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -31,11 +31,11 @@ #include "visibility_notifier_2d.h" #include "core/engine.h" -#include "particles_2d.h" -#include "scene/2d/animated_sprite.h" +#include "gpu_particles_2d.h" +#include "scene/2d/animated_sprite_2d.h" #include "scene/2d/physics_body_2d.h" #include "scene/animation/animation_player.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" #include "scene/scene_string_names.h" #ifdef TOOLS_ENABLED @@ -188,8 +188,7 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) { bool add = false; Variant meta; - if (enabler[ENABLER_FREEZE_BODIES]) { - + { RigidBody2D *rb2d = Object::cast_to<RigidBody2D>(p_node); if (rb2d && ((rb2d->get_mode() == RigidBody2D::MODE_CHARACTER || rb2d->get_mode() == RigidBody2D::MODE_RIGID))) { @@ -198,25 +197,22 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) { } } - if (enabler[ENABLER_PAUSE_ANIMATIONS]) { - + { AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node); if (ap) { add = true; } } - if (enabler[ENABLER_PAUSE_ANIMATED_SPRITES]) { - - AnimatedSprite *as = Object::cast_to<AnimatedSprite>(p_node); + { + AnimatedSprite2D *as = Object::cast_to<AnimatedSprite2D>(p_node); if (as) { add = true; } } - if (enabler[ENABLER_PAUSE_PARTICLES]) { - - Particles2D *ps = Object::cast_to<Particles2D>(p_node); + { + GPUParticles2D *ps = Object::cast_to<GPUParticles2D>(p_node); if (ps) { add = true; } @@ -278,7 +274,7 @@ 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) { @@ -286,7 +282,7 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { } } - { + if (enabler[ENABLER_PAUSE_ANIMATIONS]) { AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node); if (ap) { @@ -294,8 +290,9 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { ap->set_active(p_enabled); } } - { - AnimatedSprite *as = Object::cast_to<AnimatedSprite>(p_node); + + if (enabler[ENABLER_PAUSE_ANIMATED_SPRITES]) { + AnimatedSprite2D *as = Object::cast_to<AnimatedSprite2D>(p_node); if (as) { @@ -306,8 +303,8 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { } } - { - Particles2D *ps = Object::cast_to<Particles2D>(p_node); + if (enabler[ENABLER_PAUSE_PARTICLES]) { + GPUParticles2D *ps = Object::cast_to<GPUParticles2D>(p_node); if (ps) { diff --git a/scene/2d/y_sort.cpp b/scene/2d/y_sort.cpp index 62f10a5c96..15d97eeaa0 100644 --- a/scene/2d/y_sort.cpp +++ b/scene/2d/y_sort.cpp @@ -33,7 +33,7 @@ void YSort::set_sort_enabled(bool p_enabled) { sort_enabled = p_enabled; - VS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), sort_enabled); + RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), sort_enabled); } bool YSort::is_sort_enabled() const { @@ -53,5 +53,5 @@ void YSort::_bind_methods() { YSort::YSort() { sort_enabled = true; - VS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), true); + RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), true); } |