diff options
Diffstat (limited to 'scene')
303 files changed, 14148 insertions, 11906 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 e5d015b07c..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" @@ -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..8ba334bc67 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 { @@ -435,10 +435,10 @@ bool Area2D::is_monitorable() const { return monitorable; } -Array Area2D::get_overlapping_bodies() const { +TypedArray<Node2D> Area2D::get_overlapping_bodies() const { ERR_FAIL_COND_V_MSG(!monitoring, Array(), "Can't find overlapping bodies when monitoring is off."); - Array ret; + TypedArray<Node2D> ret; ret.resize(body_map.size()); int idx = 0; for (const Map<ObjectID, BodyState>::Element *E = body_map.front(); E; E = E->next()) { @@ -453,10 +453,10 @@ Array Area2D::get_overlapping_bodies() const { return ret; } -Array Area2D::get_overlapping_areas() const { +TypedArray<Area2D> Area2D::get_overlapping_areas() const { ERR_FAIL_COND_V_MSG(!monitoring, Array(), "Can't find overlapping bodies when monitoring is off."); - Array ret; + TypedArray<Area2D> ret; ret.resize(area_map.size()); int idx = 0; for (const Map<ObjectID, AreaState>::Element *E = area_map.front(); E; E = E->next()) { @@ -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/area_2d.h b/scene/2d/area_2d.h index c5e6635412..0e2c0ac672 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -178,8 +178,8 @@ public: void set_collision_layer_bit(int p_bit, bool p_value); bool get_collision_layer_bit(int p_bit) const; - Array get_overlapping_bodies() const; //function for script - Array get_overlapping_areas() const; //function for script + TypedArray<Node2D> get_overlapping_bodies() const; //function for script + TypedArray<Area2D> get_overlapping_areas() const; //function for script bool overlaps_area(Node *p_area) const; bool overlaps_body(Node *p_body) const; 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_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 e9dfb94cb2..1e48b2d67f 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -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: { @@ -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_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 e345a076ae..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) { @@ -225,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]; @@ -233,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); } @@ -260,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; } @@ -288,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(); @@ -298,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; @@ -317,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..19484442b1 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" @@ -95,7 +95,7 @@ Vector<Vector2> NavigationPolygon::get_vertices() const { return vertices; } -void NavigationPolygon::_set_polygons(const Array &p_array) { +void NavigationPolygon::_set_polygons(const TypedArray<Vector<int32_t>> &p_array) { { MutexLock lock(navmesh_generation); @@ -118,7 +118,7 @@ Array NavigationPolygon::_get_polygons() const { return ret; } -void NavigationPolygon::_set_outlines(const Array &p_array) { +void NavigationPolygon::_set_outlines(const TypedArray<Vector<int32_t>> &p_array) { outlines.resize(p_array.size()); for (int i = 0; i < p_array.size(); i++) { @@ -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 3d096ec91b..cbfe4299fb 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" @@ -55,10 +55,10 @@ class NavigationPolygon : public Resource { protected: static void _bind_methods(); - void _set_polygons(const Array &p_array); + void _set_polygons(const TypedArray<Vector<int32_t>> &p_array); Array _get_polygons() const; - void _set_outlines(const Array &p_array); + void _set_outlines(const TypedArray<Vector<int32_t>> &p_array); Array _get_outlines() const; public: @@ -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..de15f0efc2 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,22 +130,22 @@ 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); } -Array PhysicsBody2D::get_collision_exceptions() { +TypedArray<PhysicsBody2D> 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 { @@ -739,11 +739,11 @@ RigidBody2D::CCDMode RigidBody2D::get_continuous_collision_detection_mode() cons return ccd_mode; } -Array RigidBody2D::get_colliding_bodies() const { +TypedArray<Node2D> RigidBody2D::get_colliding_bodies() const { ERR_FAIL_COND_V(!contact_monitor, Array()); - Array ret; + TypedArray<Node2D> ret; ret.resize(contact_monitor->body_map.size()); int idx = 0; for (const Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) { @@ -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 eb7aefb495..75f4f778bf 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(); @@ -67,7 +67,7 @@ public: void set_collision_layer_bit(int p_bit, bool p_value); bool get_collision_layer_bit(int p_bit) const; - Array get_collision_exceptions(); + TypedArray<PhysicsBody2D> get_collision_exceptions(); void add_collision_exception_with(Node *p_node); //must be physicsbody void remove_collision_exception_with(Node *p_node); @@ -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); @@ -256,7 +256,7 @@ public: void add_force(const Vector2 &p_offset, const Vector2 &p_force); void add_torque(float p_torque); - Array get_colliding_bodies() const; //function for script + TypedArray<Node2D> get_colliding_bodies() const; //function for script virtual String get_configuration_warning() const; @@ -303,7 +303,7 @@ private: 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..9628c01718 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"); } @@ -1691,27 +1691,27 @@ bool TileMap::is_centered_textures_enabled() const { return centered_textures; } -Array TileMap::get_used_cells() const { +TypedArray<Vector2i> TileMap::get_used_cells() const { - Array a; + TypedArray<Vector2i> a; a.resize(tile_map.size()); int i = 0; for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) { - Vector2 p(E->key().x, E->key().y); + Vector2i p(E->key().x, E->key().y); a[i++] = p; } return a; } -Array TileMap::get_used_cells_by_id(int p_id) const { +TypedArray<Vector2i> TileMap::get_used_cells_by_id(int p_id) const { - Array a; + TypedArray<Vector2i> a; for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) { if (E->value().id == p_id) { - Vector2 p(E->key().x, E->key().y); + Vector2i p(E->key().x, E->key().y); a.push_back(p); } } @@ -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/tile_map.h b/scene/2d/tile_map.h index d9490aae13..cc1537f583 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -328,8 +328,8 @@ public: void set_centered_textures(bool p_enable); bool is_centered_textures_enabled() const; - Array get_used_cells() const; - Array get_used_cells_by_id(int p_id) const; + TypedArray<Vector2i> get_used_cells() const; + TypedArray<Vector2i> get_used_cells_by_id(int p_id) const; Rect2 get_used_rect(); // Not const because of cache void set_occluder_light_mask(int p_mask); 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 54511bbe1b..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 @@ -205,14 +205,14 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) { } { - AnimatedSprite *as = Object::cast_to<AnimatedSprite>(p_node); + AnimatedSprite2D *as = Object::cast_to<AnimatedSprite2D>(p_node); if (as) { add = true; } } { - Particles2D *ps = Object::cast_to<Particles2D>(p_node); + GPUParticles2D *ps = Object::cast_to<GPUParticles2D>(p_node); if (ps) { add = true; } @@ -292,7 +292,7 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { } if (enabler[ENABLER_PAUSE_ANIMATED_SPRITES]) { - AnimatedSprite *as = Object::cast_to<AnimatedSprite>(p_node); + AnimatedSprite2D *as = Object::cast_to<AnimatedSprite2D>(p_node); if (as) { @@ -304,7 +304,7 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) { } if (enabler[ENABLER_PAUSE_PARTICLES]) { - Particles2D *ps = Object::cast_to<Particles2D>(p_node); + 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); } diff --git a/scene/3d/SCsub b/scene/3d/SCsub index 31a443bad1..ce69e8aa19 100644 --- a/scene/3d/SCsub +++ b/scene/3d/SCsub @@ -1,12 +1,9 @@ #!/usr/bin/env python -Import('env') +Import("env") -if env['disable_3d']: - env.add_source_files(env.scene_sources, "spatial.cpp") - env.add_source_files(env.scene_sources, "skeleton.cpp") - env.add_source_files(env.scene_sources, "particles.cpp") - env.add_source_files(env.scene_sources, "visual_instance.cpp") - env.add_source_files(env.scene_sources, "world_environment.cpp") +if env["disable_3d"]: + env.add_source_files(env.scene_sources, "node_3d.cpp") + env.add_source_files(env.scene_sources, "skeleton_3d.cpp") else: env.add_source_files(env.scene_sources, "*.cpp") diff --git a/scene/3d/area.cpp b/scene/3d/area_3d.cpp index 321926d841..b72483d71b 100644 --- a/scene/3d/area.cpp +++ b/scene/3d/area_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* area.cpp */ +/* area_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,93 +28,93 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "area.h" +#include "area_3d.h" #include "scene/scene_string_names.h" #include "servers/audio_server.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" -void Area::set_space_override_mode(SpaceOverride p_mode) { +void Area3D::set_space_override_mode(SpaceOverride p_mode) { space_override = p_mode; - PhysicsServer::get_singleton()->area_set_space_override_mode(get_rid(), PhysicsServer::AreaSpaceOverrideMode(p_mode)); + PhysicsServer3D::get_singleton()->area_set_space_override_mode(get_rid(), PhysicsServer3D::AreaSpaceOverrideMode(p_mode)); } -Area::SpaceOverride Area::get_space_override_mode() const { +Area3D::SpaceOverride Area3D::get_space_override_mode() const { return space_override; } -void Area::set_gravity_is_point(bool p_enabled) { +void Area3D::set_gravity_is_point(bool p_enabled) { gravity_is_point = p_enabled; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT, p_enabled); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_IS_POINT, p_enabled); } -bool Area::is_gravity_a_point() const { +bool Area3D::is_gravity_a_point() const { return gravity_is_point; } -void Area::set_gravity_distance_scale(real_t p_scale) { +void Area3D::set_gravity_distance_scale(real_t p_scale) { gravity_distance_scale = p_scale; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale); } -real_t Area::get_gravity_distance_scale() const { +real_t Area3D::get_gravity_distance_scale() const { return gravity_distance_scale; } -void Area::set_gravity_vector(const Vector3 &p_vec) { +void Area3D::set_gravity_vector(const Vector3 &p_vec) { gravity_vec = p_vec; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY_VECTOR, p_vec); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR, p_vec); } -Vector3 Area::get_gravity_vector() const { +Vector3 Area3D::get_gravity_vector() const { return gravity_vec; } -void Area::set_gravity(real_t p_gravity) { +void Area3D::set_gravity(real_t p_gravity) { gravity = p_gravity; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY, p_gravity); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY, p_gravity); } -real_t Area::get_gravity() const { +real_t Area3D::get_gravity() const { return gravity; } -void Area::set_linear_damp(real_t p_linear_damp) { +void Area3D::set_linear_damp(real_t p_linear_damp) { linear_damp = p_linear_damp; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_LINEAR_DAMP, p_linear_damp); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_LINEAR_DAMP, p_linear_damp); } -real_t Area::get_linear_damp() const { +real_t Area3D::get_linear_damp() const { return linear_damp; } -void Area::set_angular_damp(real_t p_angular_damp) { +void Area3D::set_angular_damp(real_t p_angular_damp) { angular_damp = p_angular_damp; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_ANGULAR_DAMP, p_angular_damp); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP, p_angular_damp); } -real_t Area::get_angular_damp() const { +real_t Area3D::get_angular_damp() const { return angular_damp; } -void Area::set_priority(real_t p_priority) { +void Area3D::set_priority(real_t p_priority) { priority = p_priority; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_PRIORITY, p_priority); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_PRIORITY, p_priority); } -real_t Area::get_priority() const { +real_t Area3D::get_priority() const { return priority; } -void Area::_body_enter_tree(ObjectID p_id) { +void Area3D::_body_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); @@ -132,7 +132,7 @@ void Area::_body_enter_tree(ObjectID p_id) { } } -void Area::_body_exit_tree(ObjectID p_id) { +void Area3D::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); @@ -148,9 +148,9 @@ void Area::_body_exit_tree(ObjectID p_id) { } } -void Area::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_area_shape) { +void Area3D::_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 == PhysicsServer::AREA_BODY_ADDED; + bool body_in = p_status == PhysicsServer3D::AREA_BODY_ADDED; ObjectID objid = p_instance; Object *obj = ObjectDB::get_instance(objid); @@ -171,8 +171,8 @@ void Area::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int E->get().rc = 0; E->get().in_tree = node && node->is_inside_tree(); if (node) { - node->connect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area::_body_enter_tree), make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area::_body_exit_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area3D::_body_enter_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area3D::_body_exit_tree), make_binds(objid)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->body_entered, node); } @@ -198,8 +198,8 @@ void Area::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int if (E->get().rc == 0) { if (node) { - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area::_body_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area::_body_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area3D::_body_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area3D::_body_exit_tree)); if (E->get().in_tree) emit_signal(SceneStringNames::get_singleton()->body_exited, obj); } @@ -217,7 +217,7 @@ void Area::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int locked = false; } -void Area::_clear_monitoring() { +void Area3D::_clear_monitoring() { ERR_FAIL_COND_MSG(locked, "This function can't be used during the in/out signal."); @@ -245,8 +245,8 @@ void Area::_clear_monitoring() { emit_signal(SceneStringNames::get_singleton()->body_exited, node); - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area::_body_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area::_body_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area3D::_body_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area3D::_body_exit_tree)); } } @@ -275,19 +275,19 @@ void Area::_clear_monitoring() { emit_signal(SceneStringNames::get_singleton()->area_exited, obj); - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area::_area_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area::_area_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area3D::_area_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area3D::_area_exit_tree)); } } } -void Area::_notification(int p_what) { +void Area3D::_notification(int p_what) { if (p_what == NOTIFICATION_EXIT_TREE) { _clear_monitoring(); } } -void Area::set_monitoring(bool p_enable) { +void Area3D::set_monitoring(bool p_enable) { ERR_FAIL_COND_MSG(locked, "Function blocked during in/out signal. Use set_deferred(\"monitoring\", true/false)."); @@ -298,16 +298,16 @@ void Area::set_monitoring(bool p_enable) { if (monitoring) { - PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_body_inout); - PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_area_inout); + PhysicsServer3D::get_singleton()->area_set_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_body_inout); + PhysicsServer3D::get_singleton()->area_set_area_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_area_inout); } else { - PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(), NULL, StringName()); - PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(), NULL, StringName()); + PhysicsServer3D::get_singleton()->area_set_monitor_callback(get_rid(), nullptr, StringName()); + PhysicsServer3D::get_singleton()->area_set_area_monitor_callback(get_rid(), nullptr, StringName()); _clear_monitoring(); } } -void Area::_area_enter_tree(ObjectID p_id) { +void Area3D::_area_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); @@ -325,7 +325,7 @@ void Area::_area_enter_tree(ObjectID p_id) { } } -void Area::_area_exit_tree(ObjectID p_id) { +void Area3D::_area_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); @@ -341,9 +341,9 @@ void Area::_area_exit_tree(ObjectID p_id) { } } -void Area::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, int p_area_shape, int p_self_shape) { +void Area3D::_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 == PhysicsServer::AREA_BODY_ADDED; + bool area_in = p_status == PhysicsServer3D::AREA_BODY_ADDED; ObjectID objid = p_instance; Object *obj = ObjectDB::get_instance(objid); @@ -364,8 +364,8 @@ void Area::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, int E->get().rc = 0; E->get().in_tree = node && node->is_inside_tree(); if (node) { - node->connect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area::_area_enter_tree), make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area::_area_exit_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area3D::_area_enter_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area3D::_area_exit_tree), make_binds(objid)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->area_entered, node); } @@ -391,8 +391,8 @@ void Area::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, int if (E->get().rc == 0) { if (node) { - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area::_area_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area::_area_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area3D::_area_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area3D::_area_exit_tree)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->area_exited, obj); } @@ -411,12 +411,12 @@ void Area::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, int locked = false; } -bool Area::is_monitoring() const { +bool Area3D::is_monitoring() const { return monitoring; } -Array Area::get_overlapping_bodies() const { +TypedArray<Node3D> Area3D::get_overlapping_bodies() const { ERR_FAIL_COND_V(!monitoring, Array()); Array ret; @@ -434,24 +434,24 @@ Array Area::get_overlapping_bodies() const { return ret; } -void Area::set_monitorable(bool p_enable) { +void Area3D::set_monitorable(bool p_enable) { - ERR_FAIL_COND_MSG(locked || (is_inside_tree() && PhysicsServer::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() && PhysicsServer3D::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; - PhysicsServer::get_singleton()->area_set_monitorable(get_rid(), monitorable); + PhysicsServer3D::get_singleton()->area_set_monitorable(get_rid(), monitorable); } -bool Area::is_monitorable() const { +bool Area3D::is_monitorable() const { return monitorable; } -Array Area::get_overlapping_areas() const { +TypedArray<Area3D> Area3D::get_overlapping_areas() const { ERR_FAIL_COND_V(!monitoring, Array()); Array ret; @@ -469,7 +469,7 @@ Array Area::get_overlapping_areas() const { return ret; } -bool Area::overlaps_area(Node *p_area) const { +bool Area3D::overlaps_area(Node *p_area) const { ERR_FAIL_NULL_V(p_area, false); const Map<ObjectID, AreaState>::Element *E = area_map.find(p_area->get_instance_id()); @@ -478,7 +478,7 @@ bool Area::overlaps_area(Node *p_area) const { return E->get().in_tree; } -bool Area::overlaps_body(Node *p_body) const { +bool Area3D::overlaps_body(Node *p_body) const { ERR_FAIL_NULL_V(p_body, false); const Map<ObjectID, BodyState>::Element *E = body_map.find(p_body->get_instance_id()); @@ -486,28 +486,28 @@ bool Area::overlaps_body(Node *p_body) const { return false; return E->get().in_tree; } -void Area::set_collision_mask(uint32_t p_mask) { +void Area3D::set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; - PhysicsServer::get_singleton()->area_set_collision_mask(get_rid(), p_mask); + PhysicsServer3D::get_singleton()->area_set_collision_mask(get_rid(), p_mask); } -uint32_t Area::get_collision_mask() const { +uint32_t Area3D::get_collision_mask() const { return collision_mask; } -void Area::set_collision_layer(uint32_t p_layer) { +void Area3D::set_collision_layer(uint32_t p_layer) { collision_layer = p_layer; - PhysicsServer::get_singleton()->area_set_collision_layer(get_rid(), p_layer); + PhysicsServer3D::get_singleton()->area_set_collision_layer(get_rid(), p_layer); } -uint32_t Area::get_collision_layer() const { +uint32_t Area3D::get_collision_layer() const { return collision_layer; } -void Area::set_collision_mask_bit(int p_bit, bool p_value) { +void Area3D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); if (p_value) @@ -517,12 +517,12 @@ void Area::set_collision_mask_bit(int p_bit, bool p_value) { set_collision_mask(mask); } -bool Area::get_collision_mask_bit(int p_bit) const { +bool Area3D::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } -void Area::set_collision_layer_bit(int p_bit, bool p_value) { +void Area3D::set_collision_layer_bit(int p_bit, bool p_value) { uint32_t layer = get_collision_layer(); if (p_value) @@ -532,26 +532,26 @@ void Area::set_collision_layer_bit(int p_bit, bool p_value) { set_collision_layer(layer); } -bool Area::get_collision_layer_bit(int p_bit) const { +bool Area3D::get_collision_layer_bit(int p_bit) const { return get_collision_layer() & (1 << p_bit); } -void Area::set_audio_bus_override(bool p_override) { +void Area3D::set_audio_bus_override(bool p_override) { audio_bus_override = p_override; } -bool Area::is_overriding_audio_bus() const { +bool Area3D::is_overriding_audio_bus() const { return audio_bus_override; } -void Area::set_audio_bus(const StringName &p_audio_bus) { +void Area3D::set_audio_bus(const StringName &p_audio_bus) { audio_bus = p_audio_bus; } -StringName Area::get_audio_bus() const { +StringName Area3D::get_audio_bus() const { for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { if (AudioServer::get_singleton()->get_bus_name(i) == audio_bus) { @@ -561,20 +561,20 @@ StringName Area::get_audio_bus() const { return "Master"; } -void Area::set_use_reverb_bus(bool p_enable) { +void Area3D::set_use_reverb_bus(bool p_enable) { use_reverb_bus = p_enable; } -bool Area::is_using_reverb_bus() const { +bool Area3D::is_using_reverb_bus() const { return use_reverb_bus; } -void Area::set_reverb_bus(const StringName &p_audio_bus) { +void Area3D::set_reverb_bus(const StringName &p_audio_bus) { reverb_bus = p_audio_bus; } -StringName Area::get_reverb_bus() const { +StringName Area3D::get_reverb_bus() const { for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { if (AudioServer::get_singleton()->get_bus_name(i) == reverb_bus) { @@ -584,25 +584,25 @@ StringName Area::get_reverb_bus() const { return "Master"; } -void Area::set_reverb_amount(float p_amount) { +void Area3D::set_reverb_amount(float p_amount) { reverb_amount = p_amount; } -float Area::get_reverb_amount() const { +float Area3D::get_reverb_amount() const { return reverb_amount; } -void Area::set_reverb_uniformity(float p_uniformity) { +void Area3D::set_reverb_uniformity(float p_uniformity) { reverb_uniformity = p_uniformity; } -float Area::get_reverb_uniformity() const { +float Area3D::get_reverb_uniformity() const { return reverb_uniformity; } -void Area::_validate_property(PropertyInfo &property) const { +void Area3D::_validate_property(PropertyInfo &property) const { if (property.name == "audio_bus_name" || property.name == "reverb_bus_name") { @@ -618,85 +618,85 @@ void Area::_validate_property(PropertyInfo &property) const { } } -void Area::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_space_override_mode", "enable"), &Area::set_space_override_mode); - ClassDB::bind_method(D_METHOD("get_space_override_mode"), &Area::get_space_override_mode); +void Area3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_space_override_mode", "enable"), &Area3D::set_space_override_mode); + ClassDB::bind_method(D_METHOD("get_space_override_mode"), &Area3D::get_space_override_mode); - ClassDB::bind_method(D_METHOD("set_gravity_is_point", "enable"), &Area::set_gravity_is_point); - ClassDB::bind_method(D_METHOD("is_gravity_a_point"), &Area::is_gravity_a_point); + ClassDB::bind_method(D_METHOD("set_gravity_is_point", "enable"), &Area3D::set_gravity_is_point); + ClassDB::bind_method(D_METHOD("is_gravity_a_point"), &Area3D::is_gravity_a_point); - ClassDB::bind_method(D_METHOD("set_gravity_distance_scale", "distance_scale"), &Area::set_gravity_distance_scale); - ClassDB::bind_method(D_METHOD("get_gravity_distance_scale"), &Area::get_gravity_distance_scale); + ClassDB::bind_method(D_METHOD("set_gravity_distance_scale", "distance_scale"), &Area3D::set_gravity_distance_scale); + ClassDB::bind_method(D_METHOD("get_gravity_distance_scale"), &Area3D::get_gravity_distance_scale); - ClassDB::bind_method(D_METHOD("set_gravity_vector", "vector"), &Area::set_gravity_vector); - ClassDB::bind_method(D_METHOD("get_gravity_vector"), &Area::get_gravity_vector); + ClassDB::bind_method(D_METHOD("set_gravity_vector", "vector"), &Area3D::set_gravity_vector); + ClassDB::bind_method(D_METHOD("get_gravity_vector"), &Area3D::get_gravity_vector); - ClassDB::bind_method(D_METHOD("set_gravity", "gravity"), &Area::set_gravity); - ClassDB::bind_method(D_METHOD("get_gravity"), &Area::get_gravity); + ClassDB::bind_method(D_METHOD("set_gravity", "gravity"), &Area3D::set_gravity); + ClassDB::bind_method(D_METHOD("get_gravity"), &Area3D::get_gravity); - ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &Area::set_angular_damp); - ClassDB::bind_method(D_METHOD("get_angular_damp"), &Area::get_angular_damp); + ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &Area3D::set_angular_damp); + ClassDB::bind_method(D_METHOD("get_angular_damp"), &Area3D::get_angular_damp); - ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &Area::set_linear_damp); - ClassDB::bind_method(D_METHOD("get_linear_damp"), &Area::get_linear_damp); + ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &Area3D::set_linear_damp); + ClassDB::bind_method(D_METHOD("get_linear_damp"), &Area3D::get_linear_damp); - ClassDB::bind_method(D_METHOD("set_priority", "priority"), &Area::set_priority); - ClassDB::bind_method(D_METHOD("get_priority"), &Area::get_priority); + ClassDB::bind_method(D_METHOD("set_priority", "priority"), &Area3D::set_priority); + ClassDB::bind_method(D_METHOD("get_priority"), &Area3D::get_priority); - ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &Area::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &Area::get_collision_mask); + ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &Area3D::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &Area3D::get_collision_mask); - ClassDB::bind_method(D_METHOD("set_collision_layer", "collision_layer"), &Area::set_collision_layer); - ClassDB::bind_method(D_METHOD("get_collision_layer"), &Area::get_collision_layer); + ClassDB::bind_method(D_METHOD("set_collision_layer", "collision_layer"), &Area3D::set_collision_layer); + ClassDB::bind_method(D_METHOD("get_collision_layer"), &Area3D::get_collision_layer); - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &Area::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &Area::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &Area3D::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &Area3D::get_collision_mask_bit); - ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &Area::set_collision_layer_bit); - ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &Area::get_collision_layer_bit); + ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &Area3D::set_collision_layer_bit); + ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &Area3D::get_collision_layer_bit); - ClassDB::bind_method(D_METHOD("set_monitorable", "enable"), &Area::set_monitorable); - ClassDB::bind_method(D_METHOD("is_monitorable"), &Area::is_monitorable); + ClassDB::bind_method(D_METHOD("set_monitorable", "enable"), &Area3D::set_monitorable); + ClassDB::bind_method(D_METHOD("is_monitorable"), &Area3D::is_monitorable); - ClassDB::bind_method(D_METHOD("set_monitoring", "enable"), &Area::set_monitoring); - ClassDB::bind_method(D_METHOD("is_monitoring"), &Area::is_monitoring); + ClassDB::bind_method(D_METHOD("set_monitoring", "enable"), &Area3D::set_monitoring); + ClassDB::bind_method(D_METHOD("is_monitoring"), &Area3D::is_monitoring); - ClassDB::bind_method(D_METHOD("get_overlapping_bodies"), &Area::get_overlapping_bodies); - ClassDB::bind_method(D_METHOD("get_overlapping_areas"), &Area::get_overlapping_areas); + ClassDB::bind_method(D_METHOD("get_overlapping_bodies"), &Area3D::get_overlapping_bodies); + ClassDB::bind_method(D_METHOD("get_overlapping_areas"), &Area3D::get_overlapping_areas); - ClassDB::bind_method(D_METHOD("overlaps_body", "body"), &Area::overlaps_body); - ClassDB::bind_method(D_METHOD("overlaps_area", "area"), &Area::overlaps_area); + ClassDB::bind_method(D_METHOD("overlaps_body", "body"), &Area3D::overlaps_body); + ClassDB::bind_method(D_METHOD("overlaps_area", "area"), &Area3D::overlaps_area); - ClassDB::bind_method(D_METHOD("_body_inout"), &Area::_body_inout); - ClassDB::bind_method(D_METHOD("_area_inout"), &Area::_area_inout); + ClassDB::bind_method(D_METHOD("_body_inout"), &Area3D::_body_inout); + ClassDB::bind_method(D_METHOD("_area_inout"), &Area3D::_area_inout); - ClassDB::bind_method(D_METHOD("set_audio_bus_override", "enable"), &Area::set_audio_bus_override); - ClassDB::bind_method(D_METHOD("is_overriding_audio_bus"), &Area::is_overriding_audio_bus); + ClassDB::bind_method(D_METHOD("set_audio_bus_override", "enable"), &Area3D::set_audio_bus_override); + ClassDB::bind_method(D_METHOD("is_overriding_audio_bus"), &Area3D::is_overriding_audio_bus); - ClassDB::bind_method(D_METHOD("set_audio_bus", "name"), &Area::set_audio_bus); - ClassDB::bind_method(D_METHOD("get_audio_bus"), &Area::get_audio_bus); + ClassDB::bind_method(D_METHOD("set_audio_bus", "name"), &Area3D::set_audio_bus); + ClassDB::bind_method(D_METHOD("get_audio_bus"), &Area3D::get_audio_bus); - ClassDB::bind_method(D_METHOD("set_use_reverb_bus", "enable"), &Area::set_use_reverb_bus); - ClassDB::bind_method(D_METHOD("is_using_reverb_bus"), &Area::is_using_reverb_bus); + ClassDB::bind_method(D_METHOD("set_use_reverb_bus", "enable"), &Area3D::set_use_reverb_bus); + ClassDB::bind_method(D_METHOD("is_using_reverb_bus"), &Area3D::is_using_reverb_bus); - ClassDB::bind_method(D_METHOD("set_reverb_bus", "name"), &Area::set_reverb_bus); - ClassDB::bind_method(D_METHOD("get_reverb_bus"), &Area::get_reverb_bus); + ClassDB::bind_method(D_METHOD("set_reverb_bus", "name"), &Area3D::set_reverb_bus); + ClassDB::bind_method(D_METHOD("get_reverb_bus"), &Area3D::get_reverb_bus); - ClassDB::bind_method(D_METHOD("set_reverb_amount", "amount"), &Area::set_reverb_amount); - ClassDB::bind_method(D_METHOD("get_reverb_amount"), &Area::get_reverb_amount); + ClassDB::bind_method(D_METHOD("set_reverb_amount", "amount"), &Area3D::set_reverb_amount); + ClassDB::bind_method(D_METHOD("get_reverb_amount"), &Area3D::get_reverb_amount); - ClassDB::bind_method(D_METHOD("set_reverb_uniformity", "amount"), &Area::set_reverb_uniformity); - ClassDB::bind_method(D_METHOD("get_reverb_uniformity"), &Area::get_reverb_uniformity); + ClassDB::bind_method(D_METHOD("set_reverb_uniformity", "amount"), &Area3D::set_reverb_uniformity); + ClassDB::bind_method(D_METHOD("get_reverb_uniformity"), &Area3D::get_reverb_uniformity); ADD_SIGNAL(MethodInfo("body_shape_entered", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "area_shape"))); ADD_SIGNAL(MethodInfo("body_shape_exited", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "area_shape"))); ADD_SIGNAL(MethodInfo("body_entered", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("body_exited", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); - ADD_SIGNAL(MethodInfo("area_shape_entered", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape"))); - ADD_SIGNAL(MethodInfo("area_shape_exited", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape"))); - ADD_SIGNAL(MethodInfo("area_entered", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"))); - ADD_SIGNAL(MethodInfo("area_exited", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"))); + ADD_SIGNAL(MethodInfo("area_shape_entered", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area3D"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape"))); + ADD_SIGNAL(MethodInfo("area_shape_exited", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area3D"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape"))); + ADD_SIGNAL(MethodInfo("area_entered", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area3D"))); + ADD_SIGNAL(MethodInfo("area_exited", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area3D"))); ADD_PROPERTY(PropertyInfo(Variant::INT, "space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine"), "set_space_override_mode", "get_space_override_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gravity_point"), "set_gravity_is_point", "is_gravity_a_point"); @@ -727,8 +727,8 @@ void Area::_bind_methods() { BIND_ENUM_CONSTANT(SPACE_OVERRIDE_REPLACE_COMBINE); } -Area::Area() : - CollisionObject(PhysicsServer::get_singleton()->area_create(), true) { +Area3D::Area3D() : + CollisionObject3D(PhysicsServer3D::get_singleton()->area_create(), true) { space_override = SPACE_OVERRIDE_DISABLED; set_gravity(9.8); @@ -755,5 +755,5 @@ Area::Area() : reverb_uniformity = 0.0; } -Area::~Area() { +Area3D::~Area3D() { } diff --git a/scene/3d/area.h b/scene/3d/area_3d.h index 7fe61430fa..f6503c6d2d 100644 --- a/scene/3d/area.h +++ b/scene/3d/area_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* area.h */ +/* area_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef AREA_H -#define AREA_H +#ifndef AREA_3D_H +#define AREA_3D_H #include "core/vset.h" -#include "scene/3d/collision_object.h" +#include "scene/3d/collision_object_3d.h" -class Area : public CollisionObject { +class Area3D : public CollisionObject3D { - GDCLASS(Area, CollisionObject); + GDCLASS(Area3D, CollisionObject3D); public: enum SpaceOverride { @@ -184,8 +184,8 @@ public: void set_collision_layer_bit(int p_bit, bool p_value); bool get_collision_layer_bit(int p_bit) const; - Array get_overlapping_bodies() const; - Array get_overlapping_areas() const; //function for script + TypedArray<Node3D> get_overlapping_bodies() const; + TypedArray<Area3D> get_overlapping_areas() const; //function for script bool overlaps_area(Node *p_area) const; bool overlaps_body(Node *p_body) const; @@ -208,10 +208,10 @@ public: void set_reverb_uniformity(float p_uniformity); float get_reverb_uniformity() const; - Area(); - ~Area(); + Area3D(); + ~Area3D(); }; -VARIANT_ENUM_CAST(Area::SpaceOverride); +VARIANT_ENUM_CAST(Area3D::SpaceOverride); #endif // AREA__H diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 855d254bd6..097368853e 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -29,11 +29,12 @@ /*************************************************************************/ #include "audio_stream_player_3d.h" + #include "core/engine.h" -#include "scene/3d/area.h" -#include "scene/3d/camera.h" -#include "scene/3d/listener.h" -#include "scene/main/viewport.h" +#include "scene/3d/area_3d.h" +#include "scene/3d/camera_3d.h" +#include "scene/3d/listener_3d.h" +#include "scene/main/window.h" // Based on "A Novel Multichannel Panning Method for Standard and Arbitrary Loudspeaker Configurations" by Ramy Sadek and Chris Kyriakakis (2004) // Speaker-Placement Correction Amplitude Panning (SPCAP) @@ -96,7 +97,7 @@ static const Vector3 speaker_directions[7] = { }; void AudioStreamPlayer3D::_calc_output_vol(const Vector3 &source_dir, real_t tightness, AudioStreamPlayer3D::Output &output) { - unsigned int speaker_count; // only main speakers (no LFE) + unsigned int speaker_count = 0; // only main speakers (no LFE) switch (AudioServer::get_singleton()->get_speaker_mode()) { case AudioServer::SPEAKER_MODE_STEREO: speaker_count = 2; @@ -213,7 +214,7 @@ void AudioStreamPlayer3D::_mix_audio() { AudioFrame target_volume = stream_paused_fade_out ? AudioFrame(0.f, 0.f) : current.vol[k]; AudioFrame vol_prev = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : prev_outputs[i].vol[k]; AudioFrame vol_inc = (target_volume - vol_prev) / float(buffer_size); - AudioFrame vol = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : current.vol[k]; + AudioFrame vol = vol_prev; if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, k)) continue; //may have been deleted, will be updated on process @@ -384,7 +385,7 @@ void AudioStreamPlayer3D::_notification(int p_what) { linear_velocity = velocity_tracker->get_tracked_linear_velocity(); } - Ref<World> world = get_world(); + Ref<World3D> world = get_world(); ERR_FAIL_COND(world.is_null()); int new_output_count = 0; @@ -395,18 +396,18 @@ void AudioStreamPlayer3D::_notification(int p_what) { //check if any area is diverting sound into a bus - PhysicsDirectSpaceState *space_state = PhysicsServer::get_singleton()->space_get_direct_state(world->get_space()); + PhysicsDirectSpaceState3D *space_state = PhysicsServer3D::get_singleton()->space_get_direct_state(world->get_space()); - PhysicsDirectSpaceState::ShapeResult sr[MAX_INTERSECT_AREAS]; + PhysicsDirectSpaceState3D::ShapeResult sr[MAX_INTERSECT_AREAS]; int areas = space_state->intersect_point(global_pos, sr, MAX_INTERSECT_AREAS, Set<RID>(), area_mask, false, true); - Area *area = NULL; + Area3D *area = nullptr; for (int i = 0; i < areas; i++) { if (!sr[i].collider) continue; - Area *tarea = Object::cast_to<Area>(sr[i].collider); + Area3D *tarea = Object::cast_to<Area3D>(sr[i].collider); if (!tarea) continue; @@ -417,20 +418,20 @@ void AudioStreamPlayer3D::_notification(int p_what) { break; } - List<Camera *> cameras; + List<Camera3D *> cameras; world->get_camera_list(&cameras); - for (List<Camera *>::Element *E = cameras.front(); E; E = E->next()) { + for (List<Camera3D *>::Element *E = cameras.front(); E; E = E->next()) { - Camera *camera = E->get(); + Camera3D *camera = E->get(); Viewport *vp = camera->get_viewport(); if (!vp->is_audio_listener()) continue; bool listener_is_camera = true; - Spatial *listener_node = camera; + Node3D *listener_node = camera; - Listener *listener = vp->get_listener(); + Listener3D *listener = vp->get_listener(); if (listener) { listener_node = listener; listener_is_camera = false; diff --git a/scene/3d/audio_stream_player_3d.h b/scene/3d/audio_stream_player_3d.h index 5b4c865475..13e08339e2 100644 --- a/scene/3d/audio_stream_player_3d.h +++ b/scene/3d/audio_stream_player_3d.h @@ -31,16 +31,16 @@ #ifndef AUDIO_STREAM_PLAYER_3D_H #define AUDIO_STREAM_PLAYER_3D_H -#include "scene/3d/spatial.h" -#include "scene/3d/spatial_velocity_tracker.h" +#include "scene/3d/node_3d.h" +#include "scene/3d/velocity_tracker_3d.h" #include "servers/audio/audio_filter_sw.h" #include "servers/audio/audio_stream.h" #include "servers/audio_server.h" -class Camera; -class AudioStreamPlayer3D : public Spatial { +class Camera3D; +class AudioStreamPlayer3D : public Node3D { - GDCLASS(AudioStreamPlayer3D, Spatial); + GDCLASS(AudioStreamPlayer3D, Node3D); public: enum AttenuationModel { @@ -82,7 +82,7 @@ private: Output() { filter_gain = 0; - viewport = NULL; + viewport = nullptr; reverb_bus_index = -1; bus_index = -1; } @@ -134,7 +134,7 @@ private: float max_distance; - Ref<SpatialVelocityTracker> velocity_tracker; + Ref<VelocityTracker3D> velocity_tracker; DopplerTracking doppler_tracking; diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp index 73b1d450f0..6bde56104e 100644 --- a/scene/3d/baked_lightmap.cpp +++ b/scene/3d/baked_lightmap.cpp @@ -39,7 +39,7 @@ void BakedLightmapData::set_bounds(const AABB &p_bounds) { bounds = p_bounds; - VS::get_singleton()->lightmap_capture_set_bounds(baked_light, p_bounds); + RS::get_singleton()->lightmap_capture_set_bounds(baked_light, p_bounds); } AABB BakedLightmapData::get_bounds() const { @@ -49,18 +49,18 @@ AABB BakedLightmapData::get_bounds() const { void BakedLightmapData::set_octree(const Vector<uint8_t> &p_octree) { - VS::get_singleton()->lightmap_capture_set_octree(baked_light, p_octree); + RS::get_singleton()->lightmap_capture_set_octree(baked_light, p_octree); } Vector<uint8_t> BakedLightmapData::get_octree() const { - return VS::get_singleton()->lightmap_capture_get_octree(baked_light); + return RS::get_singleton()->lightmap_capture_get_octree(baked_light); } void BakedLightmapData::set_cell_space_transform(const Transform &p_xform) { cell_space_xform = p_xform; - VS::get_singleton()->lightmap_capture_set_octree_cell_transform(baked_light, p_xform); + RS::get_singleton()->lightmap_capture_set_octree_cell_transform(baked_light, p_xform); } Transform BakedLightmapData::get_cell_space_transform() const { @@ -69,7 +69,7 @@ Transform BakedLightmapData::get_cell_space_transform() const { void BakedLightmapData::set_cell_subdiv(int p_cell_subdiv) { cell_subdiv = p_cell_subdiv; - VS::get_singleton()->lightmap_capture_set_octree_cell_subdiv(baked_light, p_cell_subdiv); + RS::get_singleton()->lightmap_capture_set_octree_cell_subdiv(baked_light, p_cell_subdiv); } int BakedLightmapData::get_cell_subdiv() const { @@ -79,7 +79,7 @@ int BakedLightmapData::get_cell_subdiv() const { void BakedLightmapData::set_energy(float p_energy) { energy = p_energy; - VS::get_singleton()->lightmap_capture_set_energy(baked_light, energy); + RS::get_singleton()->lightmap_capture_set_energy(baked_light, energy); } float BakedLightmapData::get_energy() const { @@ -181,21 +181,21 @@ void BakedLightmapData::_bind_methods() { BakedLightmapData::BakedLightmapData() { - baked_light = VS::get_singleton()->lightmap_capture_create(); + baked_light = RS::get_singleton()->lightmap_capture_create(); energy = 1; cell_subdiv = 1; } BakedLightmapData::~BakedLightmapData() { - VS::get_singleton()->free(baked_light); + RS::get_singleton()->free(baked_light); } /////////////////////////// -BakedLightmap::BakeBeginFunc BakedLightmap::bake_begin_function = NULL; -BakedLightmap::BakeStepFunc BakedLightmap::bake_step_function = NULL; -BakedLightmap::BakeEndFunc BakedLightmap::bake_end_function = NULL; +BakedLightmap::BakeBeginFunc BakedLightmap::bake_begin_function = nullptr; +BakedLightmap::BakeStepFunc BakedLightmap::bake_step_function = nullptr; +BakedLightmap::BakeEndFunc BakedLightmap::bake_end_function = nullptr; void BakedLightmap::set_bake_cell_size(float p_cell_size) { bake_cell_size = p_cell_size; @@ -425,13 +425,13 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, bool p_create_vi pmc++; PlotLight pl = E->get(); switch (pl.light->get_light_type()) { - case VS::LIGHT_DIRECTIONAL: { + case RS::LIGHT_DIRECTIONAL: { baker.plot_light_directional(-pl.local_xform.basis.get_axis(2), pl.light->get_color(), pl.light->get_param(Light::PARAM_ENERGY), pl.light->get_param(Light::PARAM_INDIRECT_ENERGY), pl.light->get_bake_mode() == Light::BAKE_ALL); } break; - case VS::LIGHT_OMNI: { + case RS::LIGHT_OMNI: { baker.plot_light_omni(pl.local_xform.origin, pl.light->get_color(), pl.light->get_param(Light::PARAM_ENERGY), pl.light->get_param(Light::PARAM_INDIRECT_ENERGY), pl.light->get_param(Light::PARAM_RANGE), pl.light->get_param(Light::PARAM_ATTENUATION), pl.light->get_bake_mode() == Light::BAKE_ALL); } break; - case VS::LIGHT_SPOT: { + case RS::LIGHT_SPOT: { baker.plot_light_spot(pl.local_xform.origin, pl.local_xform.basis.get_axis(2), pl.light->get_color(), pl.light->get_param(Light::PARAM_ENERGY), pl.light->get_param(Light::PARAM_INDIRECT_ENERGY), pl.light->get_param(Light::PARAM_RANGE), pl.light->get_param(Light::PARAM_ATTENUATION), pl.light->get_param(Light::PARAM_SPOT_ANGLE), pl.light->get_param(Light::PARAM_SPOT_ATTENUATION), pl.light->get_bake_mode() == Light::BAKE_ALL); } break; @@ -675,12 +675,12 @@ void BakedLightmap::_assign_lightmaps() { if (instance_idx >= 0) { RID instance = node->call("get_bake_mesh_instance", instance_idx); if (instance.is_valid()) { - VS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), lightmap->get_rid()); + RS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), lightmap->get_rid()); } } else { VisualInstance *vi = Object::cast_to<VisualInstance>(node); ERR_CONTINUE(!vi); - VS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), lightmap->get_rid()); + RS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), lightmap->get_rid()); } } } @@ -693,12 +693,12 @@ void BakedLightmap::_clear_lightmaps() { if (instance_idx >= 0) { RID instance = node->call("get_bake_mesh_instance", instance_idx); if (instance.is_valid()) { - VS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), RID()); + RS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), RID()); } } else { VisualInstance *vi = Object::cast_to<VisualInstance>(node); ERR_CONTINUE(!vi); - VS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), RID()); + RS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), RID()); } } } diff --git a/scene/3d/bone_attachment.cpp b/scene/3d/bone_attachment_3d.cpp index b1cd9bfe8b..825cb39e2d 100644 --- a/scene/3d/bone_attachment.cpp +++ b/scene/3d/bone_attachment_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* bone_attachment.cpp */ +/* bone_attachment_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,12 +28,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "bone_attachment.h" +#include "bone_attachment_3d.h" -void BoneAttachment::_validate_property(PropertyInfo &property) const { +void BoneAttachment3D::_validate_property(PropertyInfo &property) const { if (property.name == "bone_name") { - Skeleton *parent = Object::cast_to<Skeleton>(get_parent()); + Skeleton3D *parent = Object::cast_to<Skeleton3D>(get_parent()); if (parent) { @@ -54,9 +54,9 @@ void BoneAttachment::_validate_property(PropertyInfo &property) const { } } -void BoneAttachment::_check_bind() { +void BoneAttachment3D::_check_bind() { - Skeleton *sk = Object::cast_to<Skeleton>(get_parent()); + Skeleton3D *sk = Object::cast_to<Skeleton3D>(get_parent()); if (sk) { int idx = sk->find_bone(bone_name); @@ -68,11 +68,11 @@ void BoneAttachment::_check_bind() { } } -void BoneAttachment::_check_unbind() { +void BoneAttachment3D::_check_unbind() { if (bound) { - Skeleton *sk = Object::cast_to<Skeleton>(get_parent()); + Skeleton3D *sk = Object::cast_to<Skeleton3D>(get_parent()); if (sk) { int idx = sk->find_bone(bone_name); @@ -84,7 +84,7 @@ void BoneAttachment::_check_unbind() { } } -void BoneAttachment::set_bone_name(const String &p_name) { +void BoneAttachment3D::set_bone_name(const String &p_name) { if (is_inside_tree()) _check_unbind(); @@ -95,12 +95,12 @@ void BoneAttachment::set_bone_name(const String &p_name) { _check_bind(); } -String BoneAttachment::get_bone_name() const { +String BoneAttachment3D::get_bone_name() const { return bone_name; } -void BoneAttachment::_notification(int p_what) { +void BoneAttachment3D::_notification(int p_what) { switch (p_what) { @@ -115,13 +115,13 @@ void BoneAttachment::_notification(int p_what) { } } -BoneAttachment::BoneAttachment() { +BoneAttachment3D::BoneAttachment3D() { bound = false; } -void BoneAttachment::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_bone_name", "bone_name"), &BoneAttachment::set_bone_name); - ClassDB::bind_method(D_METHOD("get_bone_name"), &BoneAttachment::get_bone_name); +void BoneAttachment3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_bone_name", "bone_name"), &BoneAttachment3D::set_bone_name); + ClassDB::bind_method(D_METHOD("get_bone_name"), &BoneAttachment3D::get_bone_name); ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "bone_name"), "set_bone_name", "get_bone_name"); } diff --git a/scene/3d/bone_attachment.h b/scene/3d/bone_attachment_3d.h index 43c46dd759..d2a3ffec90 100644 --- a/scene/3d/bone_attachment.h +++ b/scene/3d/bone_attachment_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* bone_attachment.h */ +/* bone_attachment_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,11 +31,11 @@ #ifndef BONE_ATTACHMENT_H #define BONE_ATTACHMENT_H -#include "scene/3d/skeleton.h" +#include "scene/3d/skeleton_3d.h" -class BoneAttachment : public Spatial { +class BoneAttachment3D : public Node3D { - GDCLASS(BoneAttachment, Spatial); + GDCLASS(BoneAttachment3D, Node3D); bool bound; String bone_name; @@ -53,7 +53,7 @@ public: void set_bone_name(const String &p_name); String get_bone_name() const; - BoneAttachment(); + BoneAttachment3D(); }; #endif // BONE_ATTACHMENT_H diff --git a/scene/3d/camera.cpp b/scene/3d/camera_3d.cpp index 741712025c..706c49b43b 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* camera.cpp */ +/* camera_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,22 +28,22 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "camera.h" +#include "camera_3d.h" -#include "collision_object.h" +#include "collision_object_3d.h" #include "core/engine.h" #include "core/math/camera_matrix.h" #include "scene/resources/material.h" #include "scene/resources/surface_tool.h" -void Camera::_update_audio_listener_state() { +void Camera3D::_update_audio_listener_state() { } -void Camera::_request_camera_update() { +void Camera3D::_request_camera_update() { _update_camera(); } -void Camera::_update_camera_mode() { +void Camera3D::_update_camera_mode() { force_change = true; switch (mode) { @@ -61,7 +61,7 @@ void Camera::_update_camera_mode() { } } -void Camera::_validate_property(PropertyInfo &p_property) const { +void Camera3D::_validate_property(PropertyInfo &p_property) const { if (p_property.name == "fov") { if (mode != PROJECTION_PERSPECTIVE) { p_property.usage = PROPERTY_USAGE_NOEDITOR; @@ -77,12 +77,12 @@ void Camera::_validate_property(PropertyInfo &p_property) const { } } -void Camera::_update_camera() { +void Camera3D::_update_camera() { if (!is_inside_tree()) return; - VisualServer::get_singleton()->camera_set_transform(camera, get_camera_transform()); + RenderingServer::get_singleton()->camera_set_transform(camera, get_camera_transform()); // here goes listener stuff /* @@ -100,7 +100,7 @@ void Camera::_update_camera() { } } -void Camera::_notification(int p_what) { +void Camera3D::_notification(int p_what) { switch (p_what) { @@ -138,7 +138,7 @@ void Camera::_notification(int p_what) { if (viewport) { viewport->_camera_remove(this); - viewport = NULL; + viewport = nullptr; } } break; @@ -155,7 +155,7 @@ void Camera::_notification(int p_what) { } } -Transform Camera::get_camera_transform() const { +Transform Camera3D::get_camera_transform() const { Transform tr = get_global_transform().orthonormalized(); tr.origin += tr.basis.get_axis(1) * v_offset; @@ -163,7 +163,7 @@ Transform Camera::get_camera_transform() const { return tr; } -void Camera::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far) { +void Camera3D::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far) { if (!force_change && fov == p_fovy_degrees && p_z_near == near && p_z_far == far && mode == PROJECTION_PERSPECTIVE) return; @@ -173,11 +173,11 @@ void Camera::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far far = p_z_far; mode = PROJECTION_PERSPECTIVE; - VisualServer::get_singleton()->camera_set_perspective(camera, fov, near, far); + RenderingServer::get_singleton()->camera_set_perspective(camera, fov, near, far); update_gizmo(); force_change = false; } -void Camera::set_orthogonal(float p_size, float p_z_near, float p_z_far) { +void Camera3D::set_orthogonal(float p_size, float p_z_near, float p_z_far) { if (!force_change && size == p_size && p_z_near == near && p_z_far == far && mode == PROJECTION_ORTHOGONAL) return; @@ -189,11 +189,11 @@ void Camera::set_orthogonal(float p_size, float p_z_near, float p_z_far) { mode = PROJECTION_ORTHOGONAL; force_change = false; - VisualServer::get_singleton()->camera_set_orthogonal(camera, size, near, far); + RenderingServer::get_singleton()->camera_set_orthogonal(camera, size, near, far); update_gizmo(); } -void Camera::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p_z_far) { +void Camera3D::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p_z_far) { if (!force_change && size == p_size && frustum_offset == p_offset && p_z_near == near && p_z_far == far && mode == PROJECTION_FRUSTUM) return; @@ -205,11 +205,11 @@ void Camera::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p mode = PROJECTION_FRUSTUM; force_change = false; - VisualServer::get_singleton()->camera_set_frustum(camera, size, frustum_offset, near, far); + RenderingServer::get_singleton()->camera_set_frustum(camera, size, frustum_offset, near, far); update_gizmo(); } -void Camera::set_projection(Camera::Projection p_mode) { +void Camera3D::set_projection(Camera3D::Projection p_mode) { if (p_mode == PROJECTION_PERSPECTIVE || p_mode == PROJECTION_ORTHOGONAL || p_mode == PROJECTION_FRUSTUM) { mode = p_mode; _update_camera_mode(); @@ -217,12 +217,12 @@ void Camera::set_projection(Camera::Projection p_mode) { } } -RID Camera::get_camera() const { +RID Camera3D::get_camera() const { return camera; }; -void Camera::make_current() { +void Camera3D::make_current() { current = true; @@ -234,14 +234,14 @@ void Camera::make_current() { //get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,camera_group,"_camera_make_current",this); } -void Camera::clear_current(bool p_enable_next) { +void Camera3D::clear_current(bool p_enable_next) { current = false; if (!is_inside_tree()) return; if (get_viewport()->get_camera() == this) { - get_viewport()->_camera_set(NULL); + get_viewport()->_camera_set(nullptr); if (p_enable_next) { get_viewport()->_camera_make_next_current(this); @@ -249,7 +249,7 @@ void Camera::clear_current(bool p_enable_next) { } } -void Camera::set_current(bool p_current) { +void Camera3D::set_current(bool p_current) { if (p_current) { make_current(); } else { @@ -257,7 +257,7 @@ void Camera::set_current(bool p_current) { } } -bool Camera::is_current() const { +bool Camera3D::is_current() const { if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { @@ -266,18 +266,18 @@ bool Camera::is_current() const { return current; } -bool Camera::_can_gizmo_scale() const { +bool Camera3D::_can_gizmo_scale() const { return false; } -Vector3 Camera::project_ray_normal(const Point2 &p_pos) const { +Vector3 Camera3D::project_ray_normal(const Point2 &p_pos) const { Vector3 ray = project_local_ray_normal(p_pos); return get_camera_transform().basis.xform(ray).normalized(); }; -Vector3 Camera::project_local_ray_normal(const Point2 &p_pos) const { +Vector3 Camera3D::project_local_ray_normal(const Point2 &p_pos) const { ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); @@ -298,7 +298,7 @@ Vector3 Camera::project_local_ray_normal(const Point2 &p_pos) const { return ray; }; -Vector3 Camera::project_ray_origin(const Point2 &p_pos) const { +Vector3 Camera3D::project_ray_origin(const Point2 &p_pos) const { ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); @@ -330,14 +330,14 @@ Vector3 Camera::project_ray_origin(const Point2 &p_pos) const { }; }; -bool Camera::is_position_behind(const Vector3 &p_pos) const { +bool Camera3D::is_position_behind(const Vector3 &p_pos) const { Transform t = get_global_transform(); Vector3 eyedir = -get_global_transform().basis.get_axis(2).normalized(); return eyedir.dot(p_pos) < (eyedir.dot(t.origin) + near); } -Vector<Vector3> Camera::get_near_plane_points() const { +Vector<Vector3> Camera3D::get_near_plane_points() const { ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector<Vector3>(), "Camera is not inside scene."); Size2 viewport_size = get_viewport()->get_visible_rect().size; @@ -360,7 +360,7 @@ Vector<Vector3> Camera::get_near_plane_points() const { return points; } -Point2 Camera::unproject_position(const Vector3 &p_pos) const { +Point2 Camera3D::unproject_position(const Vector3 &p_pos) const { ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector2(), "Camera is not inside scene."); @@ -385,7 +385,7 @@ Point2 Camera::unproject_position(const Vector3 &p_pos) const { return res; } -Vector3 Camera::project_position(const Point2 &p_point, float p_z_depth) const { +Vector3 Camera3D::project_position(const Point2 &p_point, float p_z_depth) const { ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); @@ -413,66 +413,49 @@ Vector3 Camera::project_position(const Point2 &p_point, float p_z_depth) const { return get_camera_transform().xform(p); } -/* -void Camera::_camera_make_current(Node *p_camera) { - - - if (p_camera==this) { - VisualServer::get_singleton()->viewport_attach_camera(viewport_id,camera); - active=true; - } else { - if (active && p_camera==NULL) { - //detech camera because no one else will claim it - VisualServer::get_singleton()->viewport_attach_camera(viewport_id,RID()); - } - active=false; - } -} -*/ - -void Camera::set_environment(const Ref<Environment> &p_environment) { +void Camera3D::set_environment(const Ref<Environment> &p_environment) { environment = p_environment; if (environment.is_valid()) - VS::get_singleton()->camera_set_environment(camera, environment->get_rid()); + RS::get_singleton()->camera_set_environment(camera, environment->get_rid()); else - VS::get_singleton()->camera_set_environment(camera, RID()); + RS::get_singleton()->camera_set_environment(camera, RID()); _update_camera_mode(); } -Ref<Environment> Camera::get_environment() const { +Ref<Environment> Camera3D::get_environment() const { return environment; } -void Camera::set_effects(const Ref<CameraEffects> &p_effects) { +void Camera3D::set_effects(const Ref<CameraEffects> &p_effects) { effects = p_effects; if (effects.is_valid()) - VS::get_singleton()->camera_set_camera_effects(camera, effects->get_rid()); + RS::get_singleton()->camera_set_camera_effects(camera, effects->get_rid()); else - VS::get_singleton()->camera_set_camera_effects(camera, RID()); + RS::get_singleton()->camera_set_camera_effects(camera, RID()); _update_camera_mode(); } -Ref<CameraEffects> Camera::get_effects() const { +Ref<CameraEffects> Camera3D::get_effects() const { return effects; } -void Camera::set_keep_aspect_mode(KeepAspect p_aspect) { +void Camera3D::set_keep_aspect_mode(KeepAspect p_aspect) { keep_aspect = p_aspect; - VisualServer::get_singleton()->camera_set_use_vertical_aspect(camera, p_aspect == KEEP_WIDTH); + RenderingServer::get_singleton()->camera_set_use_vertical_aspect(camera, p_aspect == KEEP_WIDTH); _update_camera_mode(); _change_notify(); } -Camera::KeepAspect Camera::get_keep_aspect_mode() const { +Camera3D::KeepAspect Camera3D::get_keep_aspect_mode() const { return keep_aspect; } -void Camera::set_doppler_tracking(DopplerTracking p_tracking) { +void Camera3D::set_doppler_tracking(DopplerTracking p_tracking) { if (doppler_tracking == p_tracking) return; @@ -487,57 +470,57 @@ void Camera::set_doppler_tracking(DopplerTracking p_tracking) { _update_camera_mode(); } -Camera::DopplerTracking Camera::get_doppler_tracking() const { +Camera3D::DopplerTracking Camera3D::get_doppler_tracking() const { return doppler_tracking; } -void Camera::_bind_methods() { - - ClassDB::bind_method(D_METHOD("project_ray_normal", "screen_point"), &Camera::project_ray_normal); - ClassDB::bind_method(D_METHOD("project_local_ray_normal", "screen_point"), &Camera::project_local_ray_normal); - ClassDB::bind_method(D_METHOD("project_ray_origin", "screen_point"), &Camera::project_ray_origin); - ClassDB::bind_method(D_METHOD("unproject_position", "world_point"), &Camera::unproject_position); - ClassDB::bind_method(D_METHOD("is_position_behind", "world_point"), &Camera::is_position_behind); - ClassDB::bind_method(D_METHOD("project_position", "screen_point", "z_depth"), &Camera::project_position); - ClassDB::bind_method(D_METHOD("set_perspective", "fov", "z_near", "z_far"), &Camera::set_perspective); - ClassDB::bind_method(D_METHOD("set_orthogonal", "size", "z_near", "z_far"), &Camera::set_orthogonal); - ClassDB::bind_method(D_METHOD("set_frustum", "size", "offset", "z_near", "z_far"), &Camera::set_frustum); - ClassDB::bind_method(D_METHOD("make_current"), &Camera::make_current); - ClassDB::bind_method(D_METHOD("clear_current", "enable_next"), &Camera::clear_current, DEFVAL(true)); - ClassDB::bind_method(D_METHOD("set_current"), &Camera::set_current); - ClassDB::bind_method(D_METHOD("is_current"), &Camera::is_current); - ClassDB::bind_method(D_METHOD("get_camera_transform"), &Camera::get_camera_transform); - ClassDB::bind_method(D_METHOD("get_fov"), &Camera::get_fov); - ClassDB::bind_method(D_METHOD("get_frustum_offset"), &Camera::get_frustum_offset); - ClassDB::bind_method(D_METHOD("get_size"), &Camera::get_size); - ClassDB::bind_method(D_METHOD("get_zfar"), &Camera::get_zfar); - ClassDB::bind_method(D_METHOD("get_znear"), &Camera::get_znear); - ClassDB::bind_method(D_METHOD("set_fov"), &Camera::set_fov); - ClassDB::bind_method(D_METHOD("set_frustum_offset"), &Camera::set_frustum_offset); - ClassDB::bind_method(D_METHOD("set_size"), &Camera::set_size); - ClassDB::bind_method(D_METHOD("set_zfar"), &Camera::set_zfar); - ClassDB::bind_method(D_METHOD("set_znear"), &Camera::set_znear); - ClassDB::bind_method(D_METHOD("get_projection"), &Camera::get_projection); - ClassDB::bind_method(D_METHOD("set_projection"), &Camera::set_projection); - ClassDB::bind_method(D_METHOD("set_h_offset", "ofs"), &Camera::set_h_offset); - ClassDB::bind_method(D_METHOD("get_h_offset"), &Camera::get_h_offset); - ClassDB::bind_method(D_METHOD("set_v_offset", "ofs"), &Camera::set_v_offset); - ClassDB::bind_method(D_METHOD("get_v_offset"), &Camera::get_v_offset); - ClassDB::bind_method(D_METHOD("set_cull_mask", "mask"), &Camera::set_cull_mask); - ClassDB::bind_method(D_METHOD("get_cull_mask"), &Camera::get_cull_mask); - ClassDB::bind_method(D_METHOD("set_environment", "env"), &Camera::set_environment); - ClassDB::bind_method(D_METHOD("get_environment"), &Camera::get_environment); - ClassDB::bind_method(D_METHOD("set_effects", "env"), &Camera::set_effects); - ClassDB::bind_method(D_METHOD("get_effects"), &Camera::get_effects); - ClassDB::bind_method(D_METHOD("set_keep_aspect_mode", "mode"), &Camera::set_keep_aspect_mode); - ClassDB::bind_method(D_METHOD("get_keep_aspect_mode"), &Camera::get_keep_aspect_mode); - ClassDB::bind_method(D_METHOD("set_doppler_tracking", "mode"), &Camera::set_doppler_tracking); - ClassDB::bind_method(D_METHOD("get_doppler_tracking"), &Camera::get_doppler_tracking); - ClassDB::bind_method(D_METHOD("get_frustum"), &Camera::get_frustum); - ClassDB::bind_method(D_METHOD("get_camera_rid"), &Camera::get_camera); - - ClassDB::bind_method(D_METHOD("set_cull_mask_bit", "layer", "enable"), &Camera::set_cull_mask_bit); - ClassDB::bind_method(D_METHOD("get_cull_mask_bit", "layer"), &Camera::get_cull_mask_bit); +void Camera3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("project_ray_normal", "screen_point"), &Camera3D::project_ray_normal); + ClassDB::bind_method(D_METHOD("project_local_ray_normal", "screen_point"), &Camera3D::project_local_ray_normal); + ClassDB::bind_method(D_METHOD("project_ray_origin", "screen_point"), &Camera3D::project_ray_origin); + ClassDB::bind_method(D_METHOD("unproject_position", "world_point"), &Camera3D::unproject_position); + ClassDB::bind_method(D_METHOD("is_position_behind", "world_point"), &Camera3D::is_position_behind); + ClassDB::bind_method(D_METHOD("project_position", "screen_point", "z_depth"), &Camera3D::project_position); + ClassDB::bind_method(D_METHOD("set_perspective", "fov", "z_near", "z_far"), &Camera3D::set_perspective); + ClassDB::bind_method(D_METHOD("set_orthogonal", "size", "z_near", "z_far"), &Camera3D::set_orthogonal); + ClassDB::bind_method(D_METHOD("set_frustum", "size", "offset", "z_near", "z_far"), &Camera3D::set_frustum); + ClassDB::bind_method(D_METHOD("make_current"), &Camera3D::make_current); + ClassDB::bind_method(D_METHOD("clear_current", "enable_next"), &Camera3D::clear_current, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("set_current"), &Camera3D::set_current); + ClassDB::bind_method(D_METHOD("is_current"), &Camera3D::is_current); + ClassDB::bind_method(D_METHOD("get_camera_transform"), &Camera3D::get_camera_transform); + ClassDB::bind_method(D_METHOD("get_fov"), &Camera3D::get_fov); + ClassDB::bind_method(D_METHOD("get_frustum_offset"), &Camera3D::get_frustum_offset); + ClassDB::bind_method(D_METHOD("get_size"), &Camera3D::get_size); + ClassDB::bind_method(D_METHOD("get_zfar"), &Camera3D::get_zfar); + ClassDB::bind_method(D_METHOD("get_znear"), &Camera3D::get_znear); + ClassDB::bind_method(D_METHOD("set_fov"), &Camera3D::set_fov); + ClassDB::bind_method(D_METHOD("set_frustum_offset"), &Camera3D::set_frustum_offset); + ClassDB::bind_method(D_METHOD("set_size"), &Camera3D::set_size); + ClassDB::bind_method(D_METHOD("set_zfar"), &Camera3D::set_zfar); + ClassDB::bind_method(D_METHOD("set_znear"), &Camera3D::set_znear); + ClassDB::bind_method(D_METHOD("get_projection"), &Camera3D::get_projection); + ClassDB::bind_method(D_METHOD("set_projection"), &Camera3D::set_projection); + ClassDB::bind_method(D_METHOD("set_h_offset", "ofs"), &Camera3D::set_h_offset); + ClassDB::bind_method(D_METHOD("get_h_offset"), &Camera3D::get_h_offset); + ClassDB::bind_method(D_METHOD("set_v_offset", "ofs"), &Camera3D::set_v_offset); + ClassDB::bind_method(D_METHOD("get_v_offset"), &Camera3D::get_v_offset); + ClassDB::bind_method(D_METHOD("set_cull_mask", "mask"), &Camera3D::set_cull_mask); + ClassDB::bind_method(D_METHOD("get_cull_mask"), &Camera3D::get_cull_mask); + ClassDB::bind_method(D_METHOD("set_environment", "env"), &Camera3D::set_environment); + ClassDB::bind_method(D_METHOD("get_environment"), &Camera3D::get_environment); + ClassDB::bind_method(D_METHOD("set_effects", "env"), &Camera3D::set_effects); + ClassDB::bind_method(D_METHOD("get_effects"), &Camera3D::get_effects); + ClassDB::bind_method(D_METHOD("set_keep_aspect_mode", "mode"), &Camera3D::set_keep_aspect_mode); + ClassDB::bind_method(D_METHOD("get_keep_aspect_mode"), &Camera3D::get_keep_aspect_mode); + ClassDB::bind_method(D_METHOD("set_doppler_tracking", "mode"), &Camera3D::set_doppler_tracking); + ClassDB::bind_method(D_METHOD("get_doppler_tracking"), &Camera3D::get_doppler_tracking); + ClassDB::bind_method(D_METHOD("get_frustum"), &Camera3D::get_frustum); + ClassDB::bind_method(D_METHOD("get_camera_rid"), &Camera3D::get_camera); + + ClassDB::bind_method(D_METHOD("set_cull_mask_bit", "layer", "enable"), &Camera3D::set_cull_mask_bit); + ClassDB::bind_method(D_METHOD("get_cull_mask_bit", "layer"), &Camera3D::get_cull_mask_bit); //ClassDB::bind_method(D_METHOD("_camera_make_current"),&Camera::_camera_make_current ); @@ -568,76 +551,76 @@ void Camera::_bind_methods() { BIND_ENUM_CONSTANT(DOPPLER_TRACKING_PHYSICS_STEP); } -float Camera::get_fov() const { +float Camera3D::get_fov() const { return fov; } -float Camera::get_size() const { +float Camera3D::get_size() const { return size; } -float Camera::get_znear() const { +float Camera3D::get_znear() const { return near; } -Vector2 Camera::get_frustum_offset() const { +Vector2 Camera3D::get_frustum_offset() const { return frustum_offset; } -float Camera::get_zfar() const { +float Camera3D::get_zfar() const { return far; } -Camera::Projection Camera::get_projection() const { +Camera3D::Projection Camera3D::get_projection() const { return mode; } -void Camera::set_fov(float p_fov) { +void Camera3D::set_fov(float p_fov) { ERR_FAIL_COND(p_fov < 1 || p_fov > 179); fov = p_fov; _update_camera_mode(); _change_notify("fov"); } -void Camera::set_size(float p_size) { +void Camera3D::set_size(float p_size) { ERR_FAIL_COND(p_size < 0.1 || p_size > 16384); size = p_size; _update_camera_mode(); _change_notify("size"); } -void Camera::set_znear(float p_znear) { +void Camera3D::set_znear(float p_znear) { near = p_znear; _update_camera_mode(); } -void Camera::set_frustum_offset(Vector2 p_offset) { +void Camera3D::set_frustum_offset(Vector2 p_offset) { frustum_offset = p_offset; _update_camera_mode(); } -void Camera::set_zfar(float p_zfar) { +void Camera3D::set_zfar(float p_zfar) { far = p_zfar; _update_camera_mode(); } -void Camera::set_cull_mask(uint32_t p_layers) { +void Camera3D::set_cull_mask(uint32_t p_layers) { layers = p_layers; - VisualServer::get_singleton()->camera_set_cull_mask(camera, layers); + RenderingServer::get_singleton()->camera_set_cull_mask(camera, layers); _update_camera_mode(); } -uint32_t Camera::get_cull_mask() const { +uint32_t Camera3D::get_cull_mask() const { return layers; } -void Camera::set_cull_mask_bit(int p_layer, bool p_enable) { +void Camera3D::set_cull_mask_bit(int p_layer, bool p_enable) { ERR_FAIL_INDEX(p_layer, 32); if (p_enable) { set_cull_mask(layers | (1 << p_layer)); @@ -646,12 +629,12 @@ void Camera::set_cull_mask_bit(int p_layer, bool p_enable) { } } -bool Camera::get_cull_mask_bit(int p_layer) const { +bool Camera3D::get_cull_mask_bit(int p_layer) const { ERR_FAIL_INDEX_V(p_layer, 32, false); return (layers & (1 << p_layer)); } -Vector<Plane> Camera::get_frustum() const { +Vector<Plane> Camera3D::get_frustum() const { ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>()); @@ -665,28 +648,28 @@ Vector<Plane> Camera::get_frustum() const { return cm.get_projection_planes(get_camera_transform()); } -void Camera::set_v_offset(float p_offset) { +void Camera3D::set_v_offset(float p_offset) { v_offset = p_offset; _update_camera(); } -float Camera::get_v_offset() const { +float Camera3D::get_v_offset() const { return v_offset; } -void Camera::set_h_offset(float p_offset) { +void Camera3D::set_h_offset(float p_offset) { h_offset = p_offset; _update_camera(); } -float Camera::get_h_offset() const { +float Camera3D::get_h_offset() const { return h_offset; } -Vector3 Camera::get_doppler_tracked_velocity() const { +Vector3 Camera3D::get_doppler_tracked_velocity() const { if (doppler_tracking != DOPPLER_TRACKING_DISABLED) { return velocity_tracker->get_tracked_linear_velocity(); @@ -694,16 +677,16 @@ Vector3 Camera::get_doppler_tracked_velocity() const { return Vector3(); } } -Camera::Camera() { +Camera3D::Camera3D() { - camera = VisualServer::get_singleton()->camera_create(); + camera = RenderingServer::get_singleton()->camera_create(); size = 1; fov = 0; frustum_offset = Vector2(); near = 0; far = 0; current = false; - viewport = NULL; + viewport = nullptr; force_change = false; mode = PROJECTION_PERSPECTIVE; set_perspective(70.0, 0.05, 100.0); @@ -711,7 +694,7 @@ Camera::Camera() { layers = 0xfffff; v_offset = 0; h_offset = 0; - VisualServer::get_singleton()->camera_set_cull_mask(camera, layers); + RenderingServer::get_singleton()->camera_set_cull_mask(camera, layers); //active=false; velocity_tracker.instance(); doppler_tracking = DOPPLER_TRACKING_DISABLED; @@ -719,20 +702,20 @@ Camera::Camera() { set_disable_scale(true); } -Camera::~Camera() { +Camera3D::~Camera3D() { - VisualServer::get_singleton()->free(camera); + RenderingServer::get_singleton()->free(camera); } //////////////////////////////////////// -void ClippedCamera::set_margin(float p_margin) { +void ClippedCamera3D::set_margin(float p_margin) { margin = p_margin; } -float ClippedCamera::get_margin() const { +float ClippedCamera3D::get_margin() const { return margin; } -void ClippedCamera::set_process_mode(ProcessMode p_mode) { +void ClippedCamera3D::set_process_mode(ProcessMode p_mode) { if (process_mode == p_mode) { return; @@ -741,26 +724,26 @@ void ClippedCamera::set_process_mode(ProcessMode p_mode) { set_process_internal(process_mode == CLIP_PROCESS_IDLE); set_physics_process_internal(process_mode == CLIP_PROCESS_PHYSICS); } -ClippedCamera::ProcessMode ClippedCamera::get_process_mode() const { +ClippedCamera3D::ProcessMode ClippedCamera3D::get_process_mode() const { return process_mode; } -Transform ClippedCamera::get_camera_transform() const { +Transform ClippedCamera3D::get_camera_transform() const { - Transform t = Camera::get_camera_transform(); + Transform t = Camera3D::get_camera_transform(); t.origin += -t.basis.get_axis(Vector3::AXIS_Z).normalized() * clip_offset; return t; } -void ClippedCamera::_notification(int p_what) { +void ClippedCamera3D::_notification(int p_what) { if (p_what == NOTIFICATION_INTERNAL_PROCESS || p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) { - Spatial *parent = Object::cast_to<Spatial>(get_parent()); + Node3D *parent = Object::cast_to<Node3D>(get_parent()); if (!parent) { return; } - PhysicsDirectSpaceState *dspace = get_world()->get_direct_space_state(); + PhysicsDirectSpaceState3D *dspace = get_world()->get_direct_space_state(); ERR_FAIL_COND(!dspace); // most likely physics set to threads Vector3 cam_fw = -get_global_transform().basis.get_axis(Vector3::AXIS_Z).normalized(); @@ -791,7 +774,7 @@ void ClippedCamera::_notification(int p_what) { } if (!all_equal) { - PhysicsServer::get_singleton()->shape_set_data(pyramid_shape, local_points); + PhysicsServer3D::get_singleton()->shape_set_data(pyramid_shape, local_points); points = local_points; } } @@ -813,17 +796,17 @@ void ClippedCamera::_notification(int p_what) { } } -void ClippedCamera::set_collision_mask(uint32_t p_mask) { +void ClippedCamera3D::set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; } -uint32_t ClippedCamera::get_collision_mask() const { +uint32_t ClippedCamera3D::get_collision_mask() const { return collision_mask; } -void ClippedCamera::set_collision_mask_bit(int p_bit, bool p_value) { +void ClippedCamera3D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); if (p_value) @@ -833,98 +816,98 @@ void ClippedCamera::set_collision_mask_bit(int p_bit, bool p_value) { set_collision_mask(mask); } -bool ClippedCamera::get_collision_mask_bit(int p_bit) const { +bool ClippedCamera3D::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } -void ClippedCamera::add_exception_rid(const RID &p_rid) { +void ClippedCamera3D::add_exception_rid(const RID &p_rid) { exclude.insert(p_rid); } -void ClippedCamera::add_exception(const Object *p_object) { +void ClippedCamera3D::add_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); - const CollisionObject *co = Object::cast_to<CollisionObject>(p_object); + const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object); if (!co) return; add_exception_rid(co->get_rid()); } -void ClippedCamera::remove_exception_rid(const RID &p_rid) { +void ClippedCamera3D::remove_exception_rid(const RID &p_rid) { exclude.erase(p_rid); } -void ClippedCamera::remove_exception(const Object *p_object) { +void ClippedCamera3D::remove_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); - const CollisionObject *co = Object::cast_to<CollisionObject>(p_object); + const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object); if (!co) return; remove_exception_rid(co->get_rid()); } -void ClippedCamera::clear_exceptions() { +void ClippedCamera3D::clear_exceptions() { exclude.clear(); } -float ClippedCamera::get_clip_offset() const { +float ClippedCamera3D::get_clip_offset() const { return clip_offset; } -void ClippedCamera::set_clip_to_areas(bool p_clip) { +void ClippedCamera3D::set_clip_to_areas(bool p_clip) { clip_to_areas = p_clip; } -bool ClippedCamera::is_clip_to_areas_enabled() const { +bool ClippedCamera3D::is_clip_to_areas_enabled() const { return clip_to_areas; } -void ClippedCamera::set_clip_to_bodies(bool p_clip) { +void ClippedCamera3D::set_clip_to_bodies(bool p_clip) { clip_to_bodies = p_clip; } -bool ClippedCamera::is_clip_to_bodies_enabled() const { +bool ClippedCamera3D::is_clip_to_bodies_enabled() const { return clip_to_bodies; } -void ClippedCamera::_bind_methods() { +void ClippedCamera3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_margin", "margin"), &ClippedCamera::set_margin); - ClassDB::bind_method(D_METHOD("get_margin"), &ClippedCamera::get_margin); + ClassDB::bind_method(D_METHOD("set_margin", "margin"), &ClippedCamera3D::set_margin); + ClassDB::bind_method(D_METHOD("get_margin"), &ClippedCamera3D::get_margin); - ClassDB::bind_method(D_METHOD("set_process_mode", "process_mode"), &ClippedCamera::set_process_mode); - ClassDB::bind_method(D_METHOD("get_process_mode"), &ClippedCamera::get_process_mode); + ClassDB::bind_method(D_METHOD("set_process_mode", "process_mode"), &ClippedCamera3D::set_process_mode); + ClassDB::bind_method(D_METHOD("get_process_mode"), &ClippedCamera3D::get_process_mode); - ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &ClippedCamera::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &ClippedCamera::get_collision_mask); + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &ClippedCamera3D::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &ClippedCamera3D::get_collision_mask); - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &ClippedCamera::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &ClippedCamera::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &ClippedCamera3D::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &ClippedCamera3D::get_collision_mask_bit); - ClassDB::bind_method(D_METHOD("add_exception_rid", "rid"), &ClippedCamera::add_exception_rid); - ClassDB::bind_method(D_METHOD("add_exception", "node"), &ClippedCamera::add_exception); + ClassDB::bind_method(D_METHOD("add_exception_rid", "rid"), &ClippedCamera3D::add_exception_rid); + ClassDB::bind_method(D_METHOD("add_exception", "node"), &ClippedCamera3D::add_exception); - ClassDB::bind_method(D_METHOD("remove_exception_rid", "rid"), &ClippedCamera::remove_exception_rid); - ClassDB::bind_method(D_METHOD("remove_exception", "node"), &ClippedCamera::remove_exception); + ClassDB::bind_method(D_METHOD("remove_exception_rid", "rid"), &ClippedCamera3D::remove_exception_rid); + ClassDB::bind_method(D_METHOD("remove_exception", "node"), &ClippedCamera3D::remove_exception); - ClassDB::bind_method(D_METHOD("set_clip_to_areas", "enable"), &ClippedCamera::set_clip_to_areas); - ClassDB::bind_method(D_METHOD("is_clip_to_areas_enabled"), &ClippedCamera::is_clip_to_areas_enabled); + ClassDB::bind_method(D_METHOD("set_clip_to_areas", "enable"), &ClippedCamera3D::set_clip_to_areas); + ClassDB::bind_method(D_METHOD("is_clip_to_areas_enabled"), &ClippedCamera3D::is_clip_to_areas_enabled); - ClassDB::bind_method(D_METHOD("get_clip_offset"), &ClippedCamera::get_clip_offset); + ClassDB::bind_method(D_METHOD("get_clip_offset"), &ClippedCamera3D::get_clip_offset); - ClassDB::bind_method(D_METHOD("set_clip_to_bodies", "enable"), &ClippedCamera::set_clip_to_bodies); - ClassDB::bind_method(D_METHOD("is_clip_to_bodies_enabled"), &ClippedCamera::is_clip_to_bodies_enabled); + ClassDB::bind_method(D_METHOD("set_clip_to_bodies", "enable"), &ClippedCamera3D::set_clip_to_bodies); + ClassDB::bind_method(D_METHOD("is_clip_to_bodies_enabled"), &ClippedCamera3D::is_clip_to_bodies_enabled); - ClassDB::bind_method(D_METHOD("clear_exceptions"), &ClippedCamera::clear_exceptions); + ClassDB::bind_method(D_METHOD("clear_exceptions"), &ClippedCamera3D::clear_exceptions); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin", PROPERTY_HINT_RANGE, "0,32,0.01"), "set_margin", "get_margin"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_mode", "get_process_mode"); @@ -937,7 +920,7 @@ void ClippedCamera::_bind_methods() { BIND_ENUM_CONSTANT(CLIP_PROCESS_PHYSICS); BIND_ENUM_CONSTANT(CLIP_PROCESS_IDLE); } -ClippedCamera::ClippedCamera() { +ClippedCamera3D::ClippedCamera3D() { margin = 0; clip_offset = 0; process_mode = CLIP_PROCESS_PHYSICS; @@ -945,10 +928,10 @@ ClippedCamera::ClippedCamera() { collision_mask = 1; set_notify_local_transform(Engine::get_singleton()->is_editor_hint()); points.resize(5); - pyramid_shape = PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_CONVEX_POLYGON); + pyramid_shape = PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_CONVEX_POLYGON); clip_to_areas = false; clip_to_bodies = true; } -ClippedCamera::~ClippedCamera() { - PhysicsServer::get_singleton()->free(pyramid_shape); +ClippedCamera3D::~ClippedCamera3D() { + PhysicsServer3D::get_singleton()->free(pyramid_shape); } diff --git a/scene/3d/camera.h b/scene/3d/camera_3d.h index 6ac3ece798..9a005226cb 100644 --- a/scene/3d/camera.h +++ b/scene/3d/camera_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* camera.h */ +/* camera_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,17 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef CAMERA_H -#define CAMERA_H +#ifndef CAMERA_3D_H +#define CAMERA_3D_H -#include "scene/3d/spatial.h" -#include "scene/3d/spatial_velocity_tracker.h" -#include "scene/main/viewport.h" +#include "scene/3d/node_3d.h" +#include "scene/3d/velocity_tracker_3d.h" +#include "scene/main/window.h" #include "scene/resources/environment.h" -class Camera : public Spatial { +class Camera3D : public Node3D { - GDCLASS(Camera, Spatial); + GDCLASS(Camera3D, Node3D); public: enum Projection { @@ -48,10 +48,8 @@ public: PROJECTION_FRUSTUM }; - enum KeepAspect { - KEEP_WIDTH, - KEEP_HEIGHT - }; + enum KeepAspect { KEEP_WIDTH, + KEEP_HEIGHT }; enum DopplerTracking { DOPPLER_TRACKING_DISABLED, @@ -77,7 +75,7 @@ private: RID camera; RID scenario_id; - //String camera_group; + // String camera_group; uint32_t layers; @@ -86,12 +84,12 @@ private: virtual bool _can_gizmo_scale() const; - //void _camera_make_current(Node *p_camera); + // void _camera_make_current(Node *p_camera); friend class Viewport; void _update_audio_listener_state(); DopplerTracking doppler_tracking; - Ref<SpatialVelocityTracker> velocity_tracker; + Ref<VelocityTracker3D> velocity_tracker; protected: void _update_camera(); @@ -112,8 +110,9 @@ public: void set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far); void set_orthogonal(float p_size, float p_z_near, float p_z_far); - void set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p_z_far); - void set_projection(Camera::Projection p_mode); + void set_frustum(float p_size, Vector2 p_offset, float p_z_near, + float p_z_far); + void set_projection(Camera3D::Projection p_mode); void make_current(); void clear_current(bool p_enable_next = true); @@ -143,7 +142,8 @@ public: virtual Vector3 project_local_ray_normal(const Point2 &p_pos) const; virtual Point2 unproject_position(const Vector3 &p_pos) const; bool is_position_behind(const Vector3 &p_pos) const; - virtual Vector3 project_position(const Point2 &p_point, float p_z_depth) const; + virtual Vector3 project_position(const Point2 &p_point, + float p_z_depth) const; Vector<Vector3> get_near_plane_points() const; @@ -175,17 +175,17 @@ public: Vector3 get_doppler_tracked_velocity() const; - Camera(); - ~Camera(); + Camera3D(); + ~Camera3D(); }; -VARIANT_ENUM_CAST(Camera::Projection); -VARIANT_ENUM_CAST(Camera::KeepAspect); -VARIANT_ENUM_CAST(Camera::DopplerTracking); +VARIANT_ENUM_CAST(Camera3D::Projection); +VARIANT_ENUM_CAST(Camera3D::KeepAspect); +VARIANT_ENUM_CAST(Camera3D::DopplerTracking); -class ClippedCamera : public Camera { +class ClippedCamera3D : public Camera3D { - GDCLASS(ClippedCamera, Camera); + GDCLASS(ClippedCamera3D, Camera3D); public: enum ProcessMode { @@ -238,9 +238,9 @@ public: float get_clip_offset() const; - ClippedCamera(); - ~ClippedCamera(); + ClippedCamera3D(); + ~ClippedCamera3D(); }; -VARIANT_ENUM_CAST(ClippedCamera::ProcessMode); +VARIANT_ENUM_CAST(ClippedCamera3D::ProcessMode); #endif diff --git a/scene/3d/collision_object.cpp b/scene/3d/collision_object_3d.cpp index c067ef34a6..e6cd7bfe7e 100644 --- a/scene/3d/collision_object.cpp +++ b/scene/3d/collision_object_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* collision_object.cpp */ +/* collision_object_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,27 +28,27 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "collision_object.h" +#include "collision_object_3d.h" #include "scene/scene_string_names.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" -void CollisionObject::_notification(int p_what) { +void CollisionObject3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_WORLD: { if (area) - PhysicsServer::get_singleton()->area_set_transform(rid, get_global_transform()); + PhysicsServer3D::get_singleton()->area_set_transform(rid, get_global_transform()); else - PhysicsServer::get_singleton()->body_set_state(rid, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform()); + PhysicsServer3D::get_singleton()->body_set_state(rid, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); RID space = get_world()->get_space(); if (area) { - PhysicsServer::get_singleton()->area_set_space(rid, space); + PhysicsServer3D::get_singleton()->area_set_space(rid, space); } else - PhysicsServer::get_singleton()->body_set_space(rid, space); + PhysicsServer3D::get_singleton()->body_set_space(rid, space); _update_pickable(); //get space @@ -57,9 +57,9 @@ void CollisionObject::_notification(int p_what) { case NOTIFICATION_TRANSFORM_CHANGED: { if (area) - PhysicsServer::get_singleton()->area_set_transform(rid, get_global_transform()); + PhysicsServer3D::get_singleton()->area_set_transform(rid, get_global_transform()); else - PhysicsServer::get_singleton()->body_set_state(rid, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform()); + PhysicsServer3D::get_singleton()->body_set_state(rid, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); } break; case NOTIFICATION_VISIBILITY_CHANGED: { @@ -70,15 +70,15 @@ void CollisionObject::_notification(int p_what) { case NOTIFICATION_EXIT_WORLD: { if (area) { - PhysicsServer::get_singleton()->area_set_space(rid, RID()); + PhysicsServer3D::get_singleton()->area_set_space(rid, RID()); } else - PhysicsServer::get_singleton()->body_set_space(rid, RID()); + PhysicsServer3D::get_singleton()->body_set_space(rid, RID()); } break; } } -void CollisionObject::_input_event(Node *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) { +void CollisionObject3D::_input_event(Node *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) { if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_input_event, p_camera, p_input_event, p_pos, p_normal, p_shape); @@ -86,7 +86,7 @@ void CollisionObject::_input_event(Node *p_camera, const Ref<InputEvent> &p_inpu emit_signal(SceneStringNames::get_singleton()->input_event, p_camera, p_input_event, p_pos, p_normal, p_shape); } -void CollisionObject::_mouse_enter() { +void CollisionObject3D::_mouse_enter() { if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_enter); @@ -94,7 +94,7 @@ void CollisionObject::_mouse_enter() { emit_signal(SceneStringNames::get_singleton()->mouse_entered); } -void CollisionObject::_mouse_exit() { +void CollisionObject3D::_mouse_exit() { if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_exit); @@ -102,50 +102,50 @@ void CollisionObject::_mouse_exit() { emit_signal(SceneStringNames::get_singleton()->mouse_exited); } -void CollisionObject::_update_pickable() { +void CollisionObject3D::_update_pickable() { if (!is_inside_tree()) return; bool pickable = ray_pickable && is_visible_in_tree(); if (area) - PhysicsServer::get_singleton()->area_set_ray_pickable(rid, pickable); + PhysicsServer3D::get_singleton()->area_set_ray_pickable(rid, pickable); else - PhysicsServer::get_singleton()->body_set_ray_pickable(rid, pickable); + PhysicsServer3D::get_singleton()->body_set_ray_pickable(rid, pickable); } -void CollisionObject::set_ray_pickable(bool p_ray_pickable) { +void CollisionObject3D::set_ray_pickable(bool p_ray_pickable) { ray_pickable = p_ray_pickable; _update_pickable(); } -bool CollisionObject::is_ray_pickable() const { +bool CollisionObject3D::is_ray_pickable() const { return ray_pickable; } -void CollisionObject::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &CollisionObject::set_ray_pickable); - ClassDB::bind_method(D_METHOD("is_ray_pickable"), &CollisionObject::is_ray_pickable); - ClassDB::bind_method(D_METHOD("set_capture_input_on_drag", "enable"), &CollisionObject::set_capture_input_on_drag); - ClassDB::bind_method(D_METHOD("get_capture_input_on_drag"), &CollisionObject::get_capture_input_on_drag); - ClassDB::bind_method(D_METHOD("get_rid"), &CollisionObject::get_rid); - ClassDB::bind_method(D_METHOD("create_shape_owner", "owner"), &CollisionObject::create_shape_owner); - ClassDB::bind_method(D_METHOD("remove_shape_owner", "owner_id"), &CollisionObject::remove_shape_owner); - ClassDB::bind_method(D_METHOD("get_shape_owners"), &CollisionObject::_get_shape_owners); - ClassDB::bind_method(D_METHOD("shape_owner_set_transform", "owner_id", "transform"), &CollisionObject::shape_owner_set_transform); - ClassDB::bind_method(D_METHOD("shape_owner_get_transform", "owner_id"), &CollisionObject::shape_owner_get_transform); - ClassDB::bind_method(D_METHOD("shape_owner_get_owner", "owner_id"), &CollisionObject::shape_owner_get_owner); - ClassDB::bind_method(D_METHOD("shape_owner_set_disabled", "owner_id", "disabled"), &CollisionObject::shape_owner_set_disabled); - ClassDB::bind_method(D_METHOD("is_shape_owner_disabled", "owner_id"), &CollisionObject::is_shape_owner_disabled); - ClassDB::bind_method(D_METHOD("shape_owner_add_shape", "owner_id", "shape"), &CollisionObject::shape_owner_add_shape); - ClassDB::bind_method(D_METHOD("shape_owner_get_shape_count", "owner_id"), &CollisionObject::shape_owner_get_shape_count); - ClassDB::bind_method(D_METHOD("shape_owner_get_shape", "owner_id", "shape_id"), &CollisionObject::shape_owner_get_shape); - ClassDB::bind_method(D_METHOD("shape_owner_get_shape_index", "owner_id", "shape_id"), &CollisionObject::shape_owner_get_shape_index); - ClassDB::bind_method(D_METHOD("shape_owner_remove_shape", "owner_id", "shape_id"), &CollisionObject::shape_owner_remove_shape); - ClassDB::bind_method(D_METHOD("shape_owner_clear_shapes", "owner_id"), &CollisionObject::shape_owner_clear_shapes); - ClassDB::bind_method(D_METHOD("shape_find_owner", "shape_index"), &CollisionObject::shape_find_owner); +void CollisionObject3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &CollisionObject3D::set_ray_pickable); + ClassDB::bind_method(D_METHOD("is_ray_pickable"), &CollisionObject3D::is_ray_pickable); + ClassDB::bind_method(D_METHOD("set_capture_input_on_drag", "enable"), &CollisionObject3D::set_capture_input_on_drag); + ClassDB::bind_method(D_METHOD("get_capture_input_on_drag"), &CollisionObject3D::get_capture_input_on_drag); + ClassDB::bind_method(D_METHOD("get_rid"), &CollisionObject3D::get_rid); + ClassDB::bind_method(D_METHOD("create_shape_owner", "owner"), &CollisionObject3D::create_shape_owner); + ClassDB::bind_method(D_METHOD("remove_shape_owner", "owner_id"), &CollisionObject3D::remove_shape_owner); + ClassDB::bind_method(D_METHOD("get_shape_owners"), &CollisionObject3D::_get_shape_owners); + ClassDB::bind_method(D_METHOD("shape_owner_set_transform", "owner_id", "transform"), &CollisionObject3D::shape_owner_set_transform); + ClassDB::bind_method(D_METHOD("shape_owner_get_transform", "owner_id"), &CollisionObject3D::shape_owner_get_transform); + ClassDB::bind_method(D_METHOD("shape_owner_get_owner", "owner_id"), &CollisionObject3D::shape_owner_get_owner); + ClassDB::bind_method(D_METHOD("shape_owner_set_disabled", "owner_id", "disabled"), &CollisionObject3D::shape_owner_set_disabled); + ClassDB::bind_method(D_METHOD("is_shape_owner_disabled", "owner_id"), &CollisionObject3D::is_shape_owner_disabled); + ClassDB::bind_method(D_METHOD("shape_owner_add_shape", "owner_id", "shape"), &CollisionObject3D::shape_owner_add_shape); + ClassDB::bind_method(D_METHOD("shape_owner_get_shape_count", "owner_id"), &CollisionObject3D::shape_owner_get_shape_count); + ClassDB::bind_method(D_METHOD("shape_owner_get_shape", "owner_id", "shape_id"), &CollisionObject3D::shape_owner_get_shape); + ClassDB::bind_method(D_METHOD("shape_owner_get_shape_index", "owner_id", "shape_id"), &CollisionObject3D::shape_owner_get_shape_index); + ClassDB::bind_method(D_METHOD("shape_owner_remove_shape", "owner_id", "shape_id"), &CollisionObject3D::shape_owner_remove_shape); + ClassDB::bind_method(D_METHOD("shape_owner_clear_shapes", "owner_id"), &CollisionObject3D::shape_owner_clear_shapes); + ClassDB::bind_method(D_METHOD("shape_find_owner", "shape_index"), &CollisionObject3D::shape_find_owner); BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "camera"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), PropertyInfo(Variant::VECTOR3, "click_position"), PropertyInfo(Variant::VECTOR3, "click_normal"), PropertyInfo(Variant::INT, "shape_idx"))); @@ -157,7 +157,7 @@ void CollisionObject::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_capture_on_drag"), "set_capture_input_on_drag", "get_capture_input_on_drag"); } -uint32_t CollisionObject::create_shape_owner(Object *p_owner) { +uint32_t CollisionObject3D::create_shape_owner(Object *p_owner) { ShapeData sd; uint32_t id; @@ -175,7 +175,7 @@ uint32_t CollisionObject::create_shape_owner(Object *p_owner) { return id; } -void CollisionObject::remove_shape_owner(uint32_t owner) { +void CollisionObject3D::remove_shape_owner(uint32_t owner) { ERR_FAIL_COND(!shapes.has(owner)); @@ -184,35 +184,35 @@ void CollisionObject::remove_shape_owner(uint32_t owner) { shapes.erase(owner); } -void CollisionObject::shape_owner_set_disabled(uint32_t p_owner, bool p_disabled) { +void CollisionObject3D::shape_owner_set_disabled(uint32_t p_owner, bool p_disabled) { ERR_FAIL_COND(!shapes.has(p_owner)); ShapeData &sd = shapes[p_owner]; sd.disabled = p_disabled; for (int i = 0; i < sd.shapes.size(); i++) { if (area) { - PhysicsServer::get_singleton()->area_set_shape_disabled(rid, sd.shapes[i].index, p_disabled); + PhysicsServer3D::get_singleton()->area_set_shape_disabled(rid, sd.shapes[i].index, p_disabled); } else { - PhysicsServer::get_singleton()->body_set_shape_disabled(rid, sd.shapes[i].index, p_disabled); + PhysicsServer3D::get_singleton()->body_set_shape_disabled(rid, sd.shapes[i].index, p_disabled); } } } -bool CollisionObject::is_shape_owner_disabled(uint32_t p_owner) const { +bool CollisionObject3D::is_shape_owner_disabled(uint32_t p_owner) const { ERR_FAIL_COND_V(!shapes.has(p_owner), false); return shapes[p_owner].disabled; } -void CollisionObject::get_shape_owners(List<uint32_t> *r_owners) { +void CollisionObject3D::get_shape_owners(List<uint32_t> *r_owners) { for (Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) { r_owners->push_back(E->key()); } } -Array CollisionObject::_get_shape_owners() { +Array CollisionObject3D::_get_shape_owners() { Array ret; for (Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) { @@ -222,7 +222,7 @@ Array CollisionObject::_get_shape_owners() { return ret; } -void CollisionObject::shape_owner_set_transform(uint32_t p_owner, const Transform &p_transform) { +void CollisionObject3D::shape_owner_set_transform(uint32_t p_owner, const Transform &p_transform) { ERR_FAIL_COND(!shapes.has(p_owner)); @@ -230,27 +230,27 @@ void CollisionObject::shape_owner_set_transform(uint32_t p_owner, const Transfor sd.xform = p_transform; for (int i = 0; i < sd.shapes.size(); i++) { if (area) { - PhysicsServer::get_singleton()->area_set_shape_transform(rid, sd.shapes[i].index, p_transform); + PhysicsServer3D::get_singleton()->area_set_shape_transform(rid, sd.shapes[i].index, p_transform); } else { - PhysicsServer::get_singleton()->body_set_shape_transform(rid, sd.shapes[i].index, p_transform); + PhysicsServer3D::get_singleton()->body_set_shape_transform(rid, sd.shapes[i].index, p_transform); } } } -Transform CollisionObject::shape_owner_get_transform(uint32_t p_owner) const { +Transform CollisionObject3D::shape_owner_get_transform(uint32_t p_owner) const { ERR_FAIL_COND_V(!shapes.has(p_owner), Transform()); return shapes[p_owner].xform; } -Object *CollisionObject::shape_owner_get_owner(uint32_t p_owner) const { +Object *CollisionObject3D::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; } -void CollisionObject::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape> &p_shape) { +void CollisionObject3D::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape3D> &p_shape) { ERR_FAIL_COND(!shapes.has(p_owner)); ERR_FAIL_COND(p_shape.is_null()); @@ -260,28 +260,28 @@ void CollisionObject::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape> & s.index = total_subshapes; s.shape = p_shape; if (area) { - PhysicsServer::get_singleton()->area_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled); + PhysicsServer3D::get_singleton()->area_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled); } else { - PhysicsServer::get_singleton()->body_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled); + PhysicsServer3D::get_singleton()->body_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled); } sd.shapes.push_back(s); total_subshapes++; } -int CollisionObject::shape_owner_get_shape_count(uint32_t p_owner) const { +int CollisionObject3D::shape_owner_get_shape_count(uint32_t p_owner) const { ERR_FAIL_COND_V(!shapes.has(p_owner), 0); return shapes[p_owner].shapes.size(); } -Ref<Shape> CollisionObject::shape_owner_get_shape(uint32_t p_owner, int p_shape) const { +Ref<Shape3D> CollisionObject3D::shape_owner_get_shape(uint32_t p_owner, int p_shape) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), Ref<Shape>()); - ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), Ref<Shape>()); + ERR_FAIL_COND_V(!shapes.has(p_owner), Ref<Shape3D>()); + ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), Ref<Shape3D>()); return shapes[p_owner].shapes[p_shape].shape; } -int CollisionObject::shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const { +int CollisionObject3D::shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const { ERR_FAIL_COND_V(!shapes.has(p_owner), -1); ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), -1); @@ -289,16 +289,16 @@ int CollisionObject::shape_owner_get_shape_index(uint32_t p_owner, int p_shape) return shapes[p_owner].shapes[p_shape].index; } -void CollisionObject::shape_owner_remove_shape(uint32_t p_owner, int p_shape) { +void CollisionObject3D::shape_owner_remove_shape(uint32_t p_owner, int p_shape) { ERR_FAIL_COND(!shapes.has(p_owner)); ERR_FAIL_INDEX(p_shape, shapes[p_owner].shapes.size()); int index_to_remove = shapes[p_owner].shapes[p_shape].index; if (area) { - PhysicsServer::get_singleton()->area_remove_shape(rid, index_to_remove); + PhysicsServer3D::get_singleton()->area_remove_shape(rid, index_to_remove); } else { - PhysicsServer::get_singleton()->body_remove_shape(rid, index_to_remove); + PhysicsServer3D::get_singleton()->body_remove_shape(rid, index_to_remove); } shapes[p_owner].shapes.remove(p_shape); @@ -314,7 +314,7 @@ void CollisionObject::shape_owner_remove_shape(uint32_t p_owner, int p_shape) { total_subshapes--; } -void CollisionObject::shape_owner_clear_shapes(uint32_t p_owner) { +void CollisionObject3D::shape_owner_clear_shapes(uint32_t p_owner) { ERR_FAIL_COND(!shapes.has(p_owner)); @@ -323,7 +323,7 @@ void CollisionObject::shape_owner_clear_shapes(uint32_t p_owner) { } } -uint32_t CollisionObject::shape_find_owner(int p_shape_index) const { +uint32_t CollisionObject3D::shape_find_owner(int p_shape_index) const { ERR_FAIL_INDEX_V(p_shape_index, total_subshapes, 0); @@ -339,7 +339,7 @@ uint32_t CollisionObject::shape_find_owner(int p_shape_index) const { return 0; } -CollisionObject::CollisionObject(RID p_rid, bool p_area) { +CollisionObject3D::CollisionObject3D(RID p_rid, bool p_area) { rid = p_rid; area = p_area; @@ -349,38 +349,38 @@ CollisionObject::CollisionObject(RID p_rid, bool p_area) { total_subshapes = 0; if (p_area) { - PhysicsServer::get_singleton()->area_attach_object_instance_id(rid, get_instance_id()); + PhysicsServer3D::get_singleton()->area_attach_object_instance_id(rid, get_instance_id()); } else { - PhysicsServer::get_singleton()->body_attach_object_instance_id(rid, get_instance_id()); + PhysicsServer3D::get_singleton()->body_attach_object_instance_id(rid, get_instance_id()); } //set_transform_notify(true); } -void CollisionObject::set_capture_input_on_drag(bool p_capture) { +void CollisionObject3D::set_capture_input_on_drag(bool p_capture) { capture_input_on_drag = p_capture; } -bool CollisionObject::get_capture_input_on_drag() const { +bool CollisionObject3D::get_capture_input_on_drag() const { return capture_input_on_drag; } -String CollisionObject::get_configuration_warning() const { +String CollisionObject3D::get_configuration_warning() const { - String warning = Spatial::get_configuration_warning(); + String warning = Node3D::get_configuration_warning(); if (shapes.empty()) { if (!warning.empty()) { warning += "\n\n"; } - warning += TTR("This node has no shape, so it can't collide or interact with other objects.\nConsider adding a CollisionShape or CollisionPolygon as a child to define its shape."); + warning += TTR("This node has no shape, so it can't collide or interact with other objects.\nConsider adding a CollisionShape3D or CollisionPolygon3D as a child to define its shape."); } return warning; } -CollisionObject::CollisionObject() { +CollisionObject3D::CollisionObject3D() { capture_input_on_drag = false; ray_pickable = true; @@ -390,7 +390,7 @@ CollisionObject::CollisionObject() { //set_transform_notify(true); } -CollisionObject::~CollisionObject() { +CollisionObject3D::~CollisionObject3D() { - PhysicsServer::get_singleton()->free(rid); + PhysicsServer3D::get_singleton()->free(rid); } diff --git a/scene/3d/collision_object.h b/scene/3d/collision_object_3d.h index 572e73d51b..67d3aed3c8 100644 --- a/scene/3d/collision_object.h +++ b/scene/3d/collision_object_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* collision_object.h */ +/* collision_object_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef COLLISION_OBJECT_H -#define COLLISION_OBJECT_H +#ifndef COLLISION_OBJECT_3D_H +#define COLLISION_OBJECT_3D_H -#include "scene/3d/spatial.h" -#include "scene/resources/shape.h" +#include "scene/3d/node_3d.h" +#include "scene/resources/shape_3d.h" -class CollisionObject : public Spatial { +class CollisionObject3D : public Node3D { - GDCLASS(CollisionObject, Spatial); + GDCLASS(CollisionObject3D, Node3D); bool area; @@ -47,7 +47,7 @@ class CollisionObject : public Spatial { Object *owner; Transform xform; struct ShapeBase { - Ref<Shape> shape; + Ref<Shape3D> shape; int index; }; @@ -56,7 +56,7 @@ class CollisionObject : public Spatial { ShapeData() { disabled = false; - owner = NULL; + owner = nullptr; } }; @@ -70,7 +70,7 @@ class CollisionObject : public Spatial { void _update_pickable(); protected: - CollisionObject(RID p_rid, bool p_area); + CollisionObject3D(RID p_rid, bool p_area); void _notification(int p_what); static void _bind_methods(); @@ -92,9 +92,9 @@ public: void shape_owner_set_disabled(uint32_t p_owner, bool p_disabled); bool is_shape_owner_disabled(uint32_t p_owner) const; - void shape_owner_add_shape(uint32_t p_owner, const Ref<Shape> &p_shape); + void shape_owner_add_shape(uint32_t p_owner, const Ref<Shape3D> &p_shape); int shape_owner_get_shape_count(uint32_t p_owner) const; - Ref<Shape> shape_owner_get_shape(uint32_t p_owner, int p_shape) const; + Ref<Shape3D> shape_owner_get_shape(uint32_t p_owner, int p_shape) const; int shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const; void shape_owner_remove_shape(uint32_t p_owner, int p_shape); @@ -112,8 +112,8 @@ public: virtual String get_configuration_warning() const; - CollisionObject(); - ~CollisionObject(); + CollisionObject3D(); + ~CollisionObject3D(); }; #endif // COLLISION_OBJECT__H diff --git a/scene/3d/collision_polygon.cpp b/scene/3d/collision_polygon_3d.cpp index 24c3a9eb41..66bd903eeb 100644 --- a/scene/3d/collision_polygon.cpp +++ b/scene/3d/collision_polygon_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* collision_polygon.cpp */ +/* collision_polygon_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,13 +28,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "collision_polygon.h" +#include "collision_polygon_3d.h" -#include "collision_object.h" -#include "scene/resources/concave_polygon_shape.h" -#include "scene/resources/convex_polygon_shape.h" +#include "collision_object_3d.h" +#include "scene/resources/concave_polygon_shape_3d.h" +#include "scene/resources/convex_polygon_shape_3d.h" -void CollisionPolygon::_build_polygon() { +void CollisionPolygon3D::_build_polygon() { if (!parent) return; @@ -52,7 +52,7 @@ void CollisionPolygon::_build_polygon() { //decompose concave into multiple convex polygons and add them for (int i = 0; i < decomp.size(); i++) { - Ref<ConvexPolygonShape> convex = memnew(ConvexPolygonShape); + Ref<ConvexPolygonShape3D> convex = memnew(ConvexPolygonShape3D); Vector<Vector3> cp; int cs = decomp[i].size(); cp.resize(cs * 2); @@ -73,7 +73,7 @@ void CollisionPolygon::_build_polygon() { } } -void CollisionPolygon::_update_in_shape_owner(bool p_xform_only) { +void CollisionPolygon3D::_update_in_shape_owner(bool p_xform_only) { parent->shape_owner_set_transform(owner_id, get_transform()); if (p_xform_only) @@ -81,12 +81,12 @@ void CollisionPolygon::_update_in_shape_owner(bool p_xform_only) { parent->shape_owner_set_disabled(owner_id, disabled); } -void CollisionPolygon::_notification(int p_what) { +void CollisionPolygon3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_PARENTED: { - parent = Object::cast_to<CollisionObject>(get_parent()); + parent = Object::cast_to<CollisionObject3D>(get_parent()); if (parent) { owner_id = parent->create_shape_owner(this); _build_polygon(); @@ -112,12 +112,12 @@ void CollisionPolygon::_notification(int p_what) { parent->remove_shape_owner(owner_id); } owner_id = 0; - parent = NULL; + parent = nullptr; } break; } } -void CollisionPolygon::set_polygon(const Vector<Point2> &p_polygon) { +void CollisionPolygon3D::set_polygon(const Vector<Point2> &p_polygon) { polygon = p_polygon; if (parent) { @@ -127,29 +127,29 @@ void CollisionPolygon::set_polygon(const Vector<Point2> &p_polygon) { update_gizmo(); } -Vector<Point2> CollisionPolygon::get_polygon() const { +Vector<Point2> CollisionPolygon3D::get_polygon() const { return polygon; } -AABB CollisionPolygon::get_item_rect() const { +AABB CollisionPolygon3D::get_item_rect() const { return aabb; } -void CollisionPolygon::set_depth(float p_depth) { +void CollisionPolygon3D::set_depth(float p_depth) { depth = p_depth; _build_polygon(); update_gizmo(); } -float CollisionPolygon::get_depth() const { +float CollisionPolygon3D::get_depth() const { return depth; } -void CollisionPolygon::set_disabled(bool p_disabled) { +void CollisionPolygon3D::set_disabled(bool p_disabled) { disabled = p_disabled; update_gizmo(); @@ -158,50 +158,50 @@ void CollisionPolygon::set_disabled(bool p_disabled) { } } -bool CollisionPolygon::is_disabled() const { +bool CollisionPolygon3D::is_disabled() const { return disabled; } -String CollisionPolygon::get_configuration_warning() const { +String CollisionPolygon3D::get_configuration_warning() const { - if (!Object::cast_to<CollisionObject>(get_parent())) { - return TTR("CollisionPolygon only serves to provide a collision shape to a CollisionObject derived node. Please only use it as a child of Area, StaticBody, RigidBody, KinematicBody, etc. to give them a shape."); + if (!Object::cast_to<CollisionObject3D>(get_parent())) { + return TTR("CollisionPolygon3D only serves to provide a collision shape to a CollisionObject3D derived node. Please only use it as a child of Area3D, StaticBody3D, RigidBody3D, KinematicBody3D, etc. to give them a shape."); } if (polygon.empty()) { - return TTR("An empty CollisionPolygon has no effect on collision."); + return TTR("An empty CollisionPolygon3D has no effect on collision."); } return String(); } -bool CollisionPolygon::_is_editable_3d_polygon() const { +bool CollisionPolygon3D::_is_editable_3d_polygon() const { return true; } -void CollisionPolygon::_bind_methods() { +void CollisionPolygon3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_depth", "depth"), &CollisionPolygon::set_depth); - ClassDB::bind_method(D_METHOD("get_depth"), &CollisionPolygon::get_depth); + ClassDB::bind_method(D_METHOD("set_depth", "depth"), &CollisionPolygon3D::set_depth); + ClassDB::bind_method(D_METHOD("get_depth"), &CollisionPolygon3D::get_depth); - ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &CollisionPolygon::set_polygon); - ClassDB::bind_method(D_METHOD("get_polygon"), &CollisionPolygon::get_polygon); + ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &CollisionPolygon3D::set_polygon); + ClassDB::bind_method(D_METHOD("get_polygon"), &CollisionPolygon3D::get_polygon); - ClassDB::bind_method(D_METHOD("set_disabled", "disabled"), &CollisionPolygon::set_disabled); - ClassDB::bind_method(D_METHOD("is_disabled"), &CollisionPolygon::is_disabled); + ClassDB::bind_method(D_METHOD("set_disabled", "disabled"), &CollisionPolygon3D::set_disabled); + ClassDB::bind_method(D_METHOD("is_disabled"), &CollisionPolygon3D::is_disabled); - ClassDB::bind_method(D_METHOD("_is_editable_3d_polygon"), &CollisionPolygon::_is_editable_3d_polygon); + ClassDB::bind_method(D_METHOD("_is_editable_3d_polygon"), &CollisionPolygon3D::_is_editable_3d_polygon); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth"), "set_depth", "get_depth"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "is_disabled"); ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon"); } -CollisionPolygon::CollisionPolygon() { +CollisionPolygon3D::CollisionPolygon3D() { aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2)); depth = 1.0; set_notify_local_transform(true); - parent = NULL; + parent = nullptr; owner_id = 0; disabled = false; } diff --git a/scene/3d/collision_polygon.h b/scene/3d/collision_polygon_3d.h index 9ecdc02697..256aee3d7e 100644 --- a/scene/3d/collision_polygon.h +++ b/scene/3d/collision_polygon_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* collision_polygon.h */ +/* collision_polygon_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,16 +28,16 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef COLLISION_POLYGON_H -#define COLLISION_POLYGON_H +#ifndef COLLISION_POLYGON_3D_H +#define COLLISION_POLYGON_3D_H -#include "scene/3d/spatial.h" -#include "scene/resources/shape.h" +#include "scene/3d/node_3d.h" +#include "scene/resources/shape_3d.h" -class CollisionObject; -class CollisionPolygon : public Spatial { +class CollisionObject3D; +class CollisionPolygon3D : public Node3D { - GDCLASS(CollisionPolygon, Spatial); + GDCLASS(CollisionPolygon3D, Node3D); protected: float depth; @@ -45,7 +45,7 @@ protected: Vector<Point2> polygon; uint32_t owner_id; - CollisionObject *parent; + CollisionObject3D *parent; bool disabled; @@ -73,7 +73,7 @@ public: String get_configuration_warning() const; - CollisionPolygon(); + CollisionPolygon3D(); }; #endif // COLLISION_POLYGON_H diff --git a/scene/3d/collision_shape.cpp b/scene/3d/collision_shape_3d.cpp index d825c8daf7..a66e84ac3c 100644 --- a/scene/3d/collision_shape.cpp +++ b/scene/3d/collision_shape_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* collision_shape.cpp */ +/* collision_shape_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,21 +28,23 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "collision_shape.h" -#include "scene/resources/box_shape.h" -#include "scene/resources/capsule_shape.h" -#include "scene/resources/concave_polygon_shape.h" -#include "scene/resources/convex_polygon_shape.h" -#include "scene/resources/ray_shape.h" -#include "scene/resources/sphere_shape.h" -#include "scene/resources/world_margin_shape.h" -#include "servers/visual_server.h" -//TODO: Implement CylinderShape and HeightMapShape? +#include "collision_shape_3d.h" + #include "core/math/quick_hull.h" -#include "mesh_instance.h" -#include "physics_body.h" +#include "mesh_instance_3d.h" +#include "physics_body_3d.h" +#include "scene/resources/box_shape_3d.h" +#include "scene/resources/capsule_shape_3d.h" +#include "scene/resources/concave_polygon_shape_3d.h" +#include "scene/resources/convex_polygon_shape_3d.h" +#include "scene/resources/ray_shape_3d.h" +#include "scene/resources/sphere_shape_3d.h" +#include "scene/resources/world_margin_shape_3d.h" +#include "servers/rendering_server.h" + +//TODO: Implement CylinderShape and HeightMapShape? -void CollisionShape::make_convex_from_brothers() { +void CollisionShape3D::make_convex_from_brothers() { Node *p = get_parent(); if (!p) @@ -51,32 +53,32 @@ void CollisionShape::make_convex_from_brothers() { for (int i = 0; i < p->get_child_count(); i++) { Node *n = p->get_child(i); - MeshInstance *mi = Object::cast_to<MeshInstance>(n); + MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(n); if (mi) { Ref<Mesh> m = mi->get_mesh(); if (m.is_valid()) { - Ref<Shape> s = m->create_convex_shape(); + Ref<Shape3D> s = m->create_convex_shape(); set_shape(s); } } } } -void CollisionShape::_update_in_shape_owner(bool p_xform_only) { +void CollisionShape3D::_update_in_shape_owner(bool p_xform_only) { parent->shape_owner_set_transform(owner_id, get_transform()); if (p_xform_only) return; parent->shape_owner_set_disabled(owner_id, disabled); } -void CollisionShape::_notification(int p_what) { +void CollisionShape3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_PARENTED: { - parent = Object::cast_to<CollisionObject>(get_parent()); + parent = Object::cast_to<CollisionObject3D>(get_parent()); if (parent) { owner_id = parent->create_shape_owner(this); if (shape.is_valid()) { @@ -103,30 +105,30 @@ void CollisionShape::_notification(int p_what) { parent->remove_shape_owner(owner_id); } owner_id = 0; - parent = NULL; + parent = nullptr; } break; } } -void CollisionShape::resource_changed(RES res) { +void CollisionShape3D::resource_changed(RES res) { update_gizmo(); } -String CollisionShape::get_configuration_warning() const { +String CollisionShape3D::get_configuration_warning() const { - if (!Object::cast_to<CollisionObject>(get_parent())) { - return TTR("CollisionShape only serves to provide a collision shape to a CollisionObject derived node. Please only use it as a child of Area, StaticBody, RigidBody, KinematicBody, etc. to give them a shape."); + if (!Object::cast_to<CollisionObject3D>(get_parent())) { + return TTR("CollisionShape3D only serves to provide a collision shape to a CollisionObject3D derived node. Please only use it as a child of Area3D, StaticBody3D, RigidBody3D, KinematicBody3D, etc. to give them a shape."); } if (!shape.is_valid()) { - return TTR("A shape must be provided for CollisionShape to function. Please create a shape resource for it."); + return TTR("A shape must be provided for CollisionShape3D to function. Please create a shape resource for it."); } - if (Object::cast_to<RigidBody>(get_parent())) { - if (Object::cast_to<ConcavePolygonShape>(*shape)) { - if (Object::cast_to<RigidBody>(get_parent())->get_mode() != RigidBody::MODE_STATIC) { - return TTR("ConcavePolygonShape doesn't support RigidBody in another mode than static."); + if (Object::cast_to<RigidBody3D>(get_parent())) { + if (Object::cast_to<ConcavePolygonShape3D>(*shape)) { + if (Object::cast_to<RigidBody3D>(get_parent())->get_mode() != RigidBody3D::MODE_STATIC) { + return TTR("ConcavePolygonShape3D doesn't support RigidBody3D in another mode than static."); } } } @@ -134,33 +136,33 @@ String CollisionShape::get_configuration_warning() const { return String(); } -void CollisionShape::_bind_methods() { +void CollisionShape3D::_bind_methods() { //not sure if this should do anything - ClassDB::bind_method(D_METHOD("resource_changed", "resource"), &CollisionShape::resource_changed); - ClassDB::bind_method(D_METHOD("set_shape", "shape"), &CollisionShape::set_shape); - ClassDB::bind_method(D_METHOD("get_shape"), &CollisionShape::get_shape); - ClassDB::bind_method(D_METHOD("set_disabled", "enable"), &CollisionShape::set_disabled); - ClassDB::bind_method(D_METHOD("is_disabled"), &CollisionShape::is_disabled); - ClassDB::bind_method(D_METHOD("make_convex_from_brothers"), &CollisionShape::make_convex_from_brothers); - ClassDB::set_method_flags("CollisionShape", "make_convex_from_brothers", METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); + ClassDB::bind_method(D_METHOD("resource_changed", "resource"), &CollisionShape3D::resource_changed); + ClassDB::bind_method(D_METHOD("set_shape", "shape"), &CollisionShape3D::set_shape); + ClassDB::bind_method(D_METHOD("get_shape"), &CollisionShape3D::get_shape); + ClassDB::bind_method(D_METHOD("set_disabled", "enable"), &CollisionShape3D::set_disabled); + ClassDB::bind_method(D_METHOD("is_disabled"), &CollisionShape3D::is_disabled); + ClassDB::bind_method(D_METHOD("make_convex_from_brothers"), &CollisionShape3D::make_convex_from_brothers); + ClassDB::set_method_flags("CollisionShape3D", "make_convex_from_brothers", METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); - ClassDB::bind_method(D_METHOD("_update_debug_shape"), &CollisionShape::_update_debug_shape); + ClassDB::bind_method(D_METHOD("_update_debug_shape"), &CollisionShape3D::_update_debug_shape); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape"), "set_shape", "get_shape"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape3D"), "set_shape", "get_shape"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "is_disabled"); } -void CollisionShape::set_shape(const Ref<Shape> &p_shape) { +void CollisionShape3D::set_shape(const Ref<Shape3D> &p_shape) { if (!shape.is_null()) { shape->unregister_owner(this); - shape->disconnect("changed", callable_mp(this, &CollisionShape::_shape_changed)); + shape->disconnect("changed", callable_mp(this, &CollisionShape3D::_shape_changed)); } shape = p_shape; if (!shape.is_null()) { shape->register_owner(this); - shape->connect("changed", callable_mp(this, &CollisionShape::_shape_changed)); + shape->connect("changed", callable_mp(this, &CollisionShape3D::_shape_changed)); } update_gizmo(); if (parent) { @@ -175,12 +177,12 @@ void CollisionShape::set_shape(const Ref<Shape> &p_shape) { update_configuration_warning(); } -Ref<Shape> CollisionShape::get_shape() const { +Ref<Shape3D> CollisionShape3D::get_shape() const { return shape; } -void CollisionShape::set_disabled(bool p_disabled) { +void CollisionShape3D::set_disabled(bool p_disabled) { disabled = p_disabled; update_gizmo(); @@ -189,47 +191,47 @@ void CollisionShape::set_disabled(bool p_disabled) { } } -bool CollisionShape::is_disabled() const { +bool CollisionShape3D::is_disabled() const { return disabled; } -CollisionShape::CollisionShape() { +CollisionShape3D::CollisionShape3D() { - //indicator = VisualServer::get_singleton()->mesh_create(); + //indicator = RenderingServer::get_singleton()->mesh_create(); disabled = false; - debug_shape = NULL; - parent = NULL; + debug_shape = nullptr; + parent = nullptr; owner_id = 0; set_notify_local_transform(true); } -CollisionShape::~CollisionShape() { +CollisionShape3D::~CollisionShape3D() { if (!shape.is_null()) shape->unregister_owner(this); - //VisualServer::get_singleton()->free(indicator); + //RenderingServer::get_singleton()->free(indicator); } -void CollisionShape::_update_debug_shape() { +void CollisionShape3D::_update_debug_shape() { debug_shape_dirty = false; if (debug_shape) { debug_shape->queue_delete(); - debug_shape = NULL; + debug_shape = nullptr; } - Ref<Shape> s = get_shape(); + Ref<Shape3D> s = get_shape(); if (s.is_null()) return; Ref<Mesh> mesh = s->get_debug_mesh(); - MeshInstance *mi = memnew(MeshInstance); + MeshInstance3D *mi = memnew(MeshInstance3D); mi->set_mesh(mesh); add_child(mi); debug_shape = mi; } -void CollisionShape::_shape_changed() { +void CollisionShape3D::_shape_changed() { // If this is a heightfield shape our center may have changed if (parent) { _update_in_shape_owner(true); diff --git a/scene/3d/collision_shape.h b/scene/3d/collision_shape_3d.h index 3150a41ebf..8515d292af 100644 --- a/scene/3d/collision_shape.h +++ b/scene/3d/collision_shape_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* collision_shape.h */ +/* collision_shape_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,18 +31,18 @@ #ifndef COLLISION_SHAPE_H #define COLLISION_SHAPE_H -#include "scene/3d/spatial.h" -#include "scene/resources/shape.h" -class CollisionObject; -class CollisionShape : public Spatial { +#include "scene/3d/node_3d.h" +#include "scene/resources/shape_3d.h" +class CollisionObject3D; +class CollisionShape3D : public Node3D { - GDCLASS(CollisionShape, Spatial); + GDCLASS(CollisionShape3D, Node3D); OBJ_CATEGORY("3D Physics Nodes"); - Ref<Shape> shape; + Ref<Shape3D> shape; uint32_t owner_id; - CollisionObject *parent; + CollisionObject3D *parent; Node *debug_shape; bool debug_shape_dirty; @@ -63,16 +63,16 @@ protected: public: void make_convex_from_brothers(); - void set_shape(const Ref<Shape> &p_shape); - Ref<Shape> get_shape() const; + void set_shape(const Ref<Shape3D> &p_shape); + Ref<Shape3D> get_shape() const; void set_disabled(bool p_disabled); bool is_disabled() const; String get_configuration_warning() const; - CollisionShape(); - ~CollisionShape(); + CollisionShape3D(); + ~CollisionShape3D(); }; #endif // BODY_VOLUME_H diff --git a/scene/3d/cpu_particles.cpp b/scene/3d/cpu_particles_3d.cpp index bde578d0af..12c105b0f4 100644 --- a/scene/3d/cpu_particles.cpp +++ b/scene/3d/cpu_particles_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* cpu_particles.cpp */ +/* cpu_particles_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,23 +28,23 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "cpu_particles.h" +#include "cpu_particles_3d.h" -#include "scene/3d/camera.h" -#include "scene/3d/particles.h" +#include "scene/3d/camera_3d.h" +#include "scene/3d/gpu_particles_3d.h" #include "scene/resources/particles_material.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" -AABB CPUParticles::get_aabb() const { +AABB CPUParticles3D::get_aabb() const { return AABB(); } -Vector<Face3> CPUParticles::get_faces(uint32_t p_usage_flags) const { +Vector<Face3> CPUParticles3D::get_faces(uint32_t p_usage_flags) const { return Vector<Face3>(); } -void CPUParticles::set_emitting(bool p_emitting) { +void CPUParticles3D::set_emitting(bool p_emitting) { if (emitting == p_emitting) return; @@ -59,7 +59,7 @@ void CPUParticles::set_emitting(bool p_emitting) { } } -void CPUParticles::set_amount(int p_amount) { +void CPUParticles3D::set_amount(int p_amount) { ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles must be greater than 0."); @@ -73,132 +73,132 @@ void CPUParticles::set_amount(int p_amount) { } particle_data.resize((12 + 4 + 4) * p_amount); - VS::get_singleton()->multimesh_allocate(multimesh, p_amount, VS::MULTIMESH_TRANSFORM_3D, true, true); + RS::get_singleton()->multimesh_allocate(multimesh, p_amount, RS::MULTIMESH_TRANSFORM_3D, true, true); particle_order.resize(p_amount); } -void CPUParticles::set_lifetime(float p_lifetime) { +void CPUParticles3D::set_lifetime(float p_lifetime) { ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0."); lifetime = p_lifetime; } -void CPUParticles::set_one_shot(bool p_one_shot) { +void CPUParticles3D::set_one_shot(bool p_one_shot) { one_shot = p_one_shot; } -void CPUParticles::set_pre_process_time(float p_time) { +void CPUParticles3D::set_pre_process_time(float p_time) { pre_process_time = p_time; } -void CPUParticles::set_explosiveness_ratio(float p_ratio) { +void CPUParticles3D::set_explosiveness_ratio(float p_ratio) { explosiveness_ratio = p_ratio; } -void CPUParticles::set_randomness_ratio(float p_ratio) { +void CPUParticles3D::set_randomness_ratio(float p_ratio) { randomness_ratio = p_ratio; } -void CPUParticles::set_lifetime_randomness(float p_random) { +void CPUParticles3D::set_lifetime_randomness(float p_random) { lifetime_randomness = p_random; } -void CPUParticles::set_use_local_coordinates(bool p_enable) { +void CPUParticles3D::set_use_local_coordinates(bool p_enable) { local_coords = p_enable; } -void CPUParticles::set_speed_scale(float p_scale) { +void CPUParticles3D::set_speed_scale(float p_scale) { speed_scale = p_scale; } -bool CPUParticles::is_emitting() const { +bool CPUParticles3D::is_emitting() const { return emitting; } -int CPUParticles::get_amount() const { +int CPUParticles3D::get_amount() const { return particles.size(); } -float CPUParticles::get_lifetime() const { +float CPUParticles3D::get_lifetime() const { return lifetime; } -bool CPUParticles::get_one_shot() const { +bool CPUParticles3D::get_one_shot() const { return one_shot; } -float CPUParticles::get_pre_process_time() const { +float CPUParticles3D::get_pre_process_time() const { return pre_process_time; } -float CPUParticles::get_explosiveness_ratio() const { +float CPUParticles3D::get_explosiveness_ratio() const { return explosiveness_ratio; } -float CPUParticles::get_randomness_ratio() const { +float CPUParticles3D::get_randomness_ratio() const { return randomness_ratio; } -float CPUParticles::get_lifetime_randomness() const { +float CPUParticles3D::get_lifetime_randomness() const { return lifetime_randomness; } -bool CPUParticles::get_use_local_coordinates() const { +bool CPUParticles3D::get_use_local_coordinates() const { return local_coords; } -float CPUParticles::get_speed_scale() const { +float CPUParticles3D::get_speed_scale() const { return speed_scale; } -void CPUParticles::set_draw_order(DrawOrder p_order) { +void CPUParticles3D::set_draw_order(DrawOrder p_order) { draw_order = p_order; } -CPUParticles::DrawOrder CPUParticles::get_draw_order() const { +CPUParticles3D::DrawOrder CPUParticles3D::get_draw_order() const { return draw_order; } -void CPUParticles::set_mesh(const Ref<Mesh> &p_mesh) { +void CPUParticles3D::set_mesh(const Ref<Mesh> &p_mesh) { mesh = p_mesh; if (mesh.is_valid()) { - VS::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid()); + RS::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid()); } else { - VS::get_singleton()->multimesh_set_mesh(multimesh, RID()); + RS::get_singleton()->multimesh_set_mesh(multimesh, RID()); } } -Ref<Mesh> CPUParticles::get_mesh() const { +Ref<Mesh> CPUParticles3D::get_mesh() const { return mesh; } -void CPUParticles::set_fixed_fps(int p_count) { +void CPUParticles3D::set_fixed_fps(int p_count) { fixed_fps = p_count; } -int CPUParticles::get_fixed_fps() const { +int CPUParticles3D::get_fixed_fps() const { return fixed_fps; } -void CPUParticles::set_fractional_delta(bool p_enable) { +void CPUParticles3D::set_fractional_delta(bool p_enable) { fractional_delta = p_enable; } -bool CPUParticles::get_fractional_delta() const { +bool CPUParticles3D::get_fractional_delta() const { return fractional_delta; } -String CPUParticles::get_configuration_warning() const { +String CPUParticles3D::get_configuration_warning() const { String warnings; @@ -208,13 +208,13 @@ String CPUParticles::get_configuration_warning() const { if (get_mesh().is_valid()) { mesh_found = true; for (int j = 0; j < get_mesh()->get_surface_count(); j++) { - anim_material_found = Object::cast_to<ShaderMaterial>(get_mesh()->surface_get_material(j).ptr()) != NULL; + anim_material_found = Object::cast_to<ShaderMaterial>(get_mesh()->surface_get_material(j).ptr()) != nullptr; StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(get_mesh()->surface_get_material(j).ptr()); anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES); } } - anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != NULL; + anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != nullptr; StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(get_material_override().ptr()); anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES); @@ -228,13 +228,13 @@ String CPUParticles::get_configuration_warning() const { get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid())) { if (warnings != String()) warnings += "\n"; - warnings += "- " + TTR("CPUParticles animation requires the usage of a StandardMaterial3D whose Billboard Mode is set to \"Particle Billboard\"."); + warnings += "- " + TTR("CPUParticles3D animation requires the usage of a StandardMaterial3D whose Billboard Mode is set to \"Particle Billboard\"."); } return warnings; } -void CPUParticles::restart() { +void CPUParticles3D::restart() { time = 0; inactive_time = 0; @@ -254,55 +254,55 @@ void CPUParticles::restart() { set_emitting(true); } -void CPUParticles::set_direction(Vector3 p_direction) { +void CPUParticles3D::set_direction(Vector3 p_direction) { direction = p_direction; } -Vector3 CPUParticles::get_direction() const { +Vector3 CPUParticles3D::get_direction() const { return direction; } -void CPUParticles::set_spread(float p_spread) { +void CPUParticles3D::set_spread(float p_spread) { spread = p_spread; } -float CPUParticles::get_spread() const { +float CPUParticles3D::get_spread() const { return spread; } -void CPUParticles::set_flatness(float p_flatness) { +void CPUParticles3D::set_flatness(float p_flatness) { flatness = p_flatness; } -float CPUParticles::get_flatness() const { +float CPUParticles3D::get_flatness() const { return flatness; } -void CPUParticles::set_param(Parameter p_param, float p_value) { +void CPUParticles3D::set_param(Parameter p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); parameters[p_param] = p_value; } -float CPUParticles::get_param(Parameter p_param) const { +float CPUParticles3D::get_param(Parameter p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return parameters[p_param]; } -void CPUParticles::set_param_randomness(Parameter p_param, float p_value) { +void CPUParticles3D::set_param_randomness(Parameter p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); randomness[p_param] = p_value; } -float CPUParticles::get_param_randomness(Parameter p_param) const { +float CPUParticles3D::get_param_randomness(Parameter p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); @@ -318,7 +318,7 @@ static void _adjust_curve_range(const Ref<Curve> &p_curve, float p_min, float p_ curve->ensure_default_setup(p_min, p_max); } -void CPUParticles::set_param_curve(Parameter p_param, const Ref<Curve> &p_curve) { +void CPUParticles3D::set_param_curve(Parameter p_param, const Ref<Curve> &p_curve) { ERR_FAIL_INDEX(p_param, PARAM_MAX); @@ -364,34 +364,34 @@ void CPUParticles::set_param_curve(Parameter p_param, const Ref<Curve> &p_curve) } } } -Ref<Curve> CPUParticles::get_param_curve(Parameter p_param) const { +Ref<Curve> CPUParticles3D::get_param_curve(Parameter p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, Ref<Curve>()); return curve_parameters[p_param]; } -void CPUParticles::set_color(const Color &p_color) { +void CPUParticles3D::set_color(const Color &p_color) { color = p_color; } -Color CPUParticles::get_color() const { +Color CPUParticles3D::get_color() const { return color; } -void CPUParticles::set_color_ramp(const Ref<Gradient> &p_ramp) { +void CPUParticles3D::set_color_ramp(const Ref<Gradient> &p_ramp) { color_ramp = p_ramp; } -Ref<Gradient> CPUParticles::get_color_ramp() const { +Ref<Gradient> CPUParticles3D::get_color_ramp() const { return color_ramp; } -void CPUParticles::set_particle_flag(Flags p_flag, bool p_enable) { +void CPUParticles3D::set_particle_flag(Flags p_flag, bool p_enable) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); flags[p_flag] = p_enable; if (p_flag == FLAG_DISABLE_Z) { @@ -399,77 +399,77 @@ void CPUParticles::set_particle_flag(Flags p_flag, bool p_enable) { } } -bool CPUParticles::get_particle_flag(Flags p_flag) const { +bool CPUParticles3D::get_particle_flag(Flags p_flag) const { ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); return flags[p_flag]; } -void CPUParticles::set_emission_shape(EmissionShape p_shape) { +void CPUParticles3D::set_emission_shape(EmissionShape p_shape) { ERR_FAIL_INDEX(p_shape, EMISSION_SHAPE_MAX); emission_shape = p_shape; } -void CPUParticles::set_emission_sphere_radius(float p_radius) { +void CPUParticles3D::set_emission_sphere_radius(float p_radius) { emission_sphere_radius = p_radius; } -void CPUParticles::set_emission_box_extents(Vector3 p_extents) { +void CPUParticles3D::set_emission_box_extents(Vector3 p_extents) { emission_box_extents = p_extents; } -void CPUParticles::set_emission_points(const Vector<Vector3> &p_points) { +void CPUParticles3D::set_emission_points(const Vector<Vector3> &p_points) { emission_points = p_points; } -void CPUParticles::set_emission_normals(const Vector<Vector3> &p_normals) { +void CPUParticles3D::set_emission_normals(const Vector<Vector3> &p_normals) { emission_normals = p_normals; } -void CPUParticles::set_emission_colors(const Vector<Color> &p_colors) { +void CPUParticles3D::set_emission_colors(const Vector<Color> &p_colors) { emission_colors = p_colors; } -float CPUParticles::get_emission_sphere_radius() const { +float CPUParticles3D::get_emission_sphere_radius() const { return emission_sphere_radius; } -Vector3 CPUParticles::get_emission_box_extents() const { +Vector3 CPUParticles3D::get_emission_box_extents() const { return emission_box_extents; } -Vector<Vector3> CPUParticles::get_emission_points() const { +Vector<Vector3> CPUParticles3D::get_emission_points() const { return emission_points; } -Vector<Vector3> CPUParticles::get_emission_normals() const { +Vector<Vector3> CPUParticles3D::get_emission_normals() const { return emission_normals; } -Vector<Color> CPUParticles::get_emission_colors() const { +Vector<Color> CPUParticles3D::get_emission_colors() const { return emission_colors; } -CPUParticles::EmissionShape CPUParticles::get_emission_shape() const { +CPUParticles3D::EmissionShape CPUParticles3D::get_emission_shape() const { return emission_shape; } -void CPUParticles::set_gravity(const Vector3 &p_gravity) { +void CPUParticles3D::set_gravity(const Vector3 &p_gravity) { gravity = p_gravity; } -Vector3 CPUParticles::get_gravity() const { +Vector3 CPUParticles3D::get_gravity() const { return gravity; } -void CPUParticles::_validate_property(PropertyInfo &property) const { +void CPUParticles3D::_validate_property(PropertyInfo &property) const { if (property.name == "color" && color_ramp.is_valid()) { property.usage = 0; @@ -517,7 +517,7 @@ static float rand_from_seed(uint32_t &seed) { return float(seed % uint32_t(65536)) / 65535.0; } -void CPUParticles::_update_internal() { +void CPUParticles3D::_update_internal() { if (particles.size() == 0 || !is_visible_in_tree()) { _set_redraw(false); @@ -592,7 +592,7 @@ void CPUParticles::_update_internal() { } } -void CPUParticles::_particles_process(float p_delta) { +void CPUParticles3D::_particles_process(float p_delta) { p_delta *= speed_scale; @@ -1016,13 +1016,13 @@ void CPUParticles::_particles_process(float p_delta) { } } -void CPUParticles::_update_particle_data_buffer() { +void CPUParticles3D::_update_particle_data_buffer() { MutexLock lock(update_mutex); int pc = particles.size(); int *ow; - int *order = NULL; + int *order = nullptr; float *w = particle_data.ptrw(); const Particle *r = particles.ptr(); @@ -1040,7 +1040,7 @@ void CPUParticles::_update_particle_data_buffer() { sorter.compare.particles = r; sorter.sort(order, pc); } else if (draw_order == DRAW_ORDER_VIEW_DEPTH) { - Camera *c = get_viewport()->get_camera(); + Camera3D *c = get_viewport()->get_camera(); if (c) { Vector3 dir = c->get_global_transform().basis.get_axis(2); //far away to close @@ -1106,7 +1106,7 @@ void CPUParticles::_update_particle_data_buffer() { can_update = true; } -void CPUParticles::_set_redraw(bool p_redraw) { +void CPUParticles3D::_set_redraw(bool p_redraw) { if (redraw == p_redraw) return; redraw = p_redraw; @@ -1115,30 +1115,30 @@ void CPUParticles::_set_redraw(bool p_redraw) { MutexLock lock(update_mutex); if (redraw) { - VS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &CPUParticles::_update_render_thread)); - VS::get_singleton()->instance_geometry_set_flag(get_instance(), VS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, true); - VS::get_singleton()->multimesh_set_visible_instances(multimesh, -1); + RS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &CPUParticles3D::_update_render_thread)); + RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, true); + RS::get_singleton()->multimesh_set_visible_instances(multimesh, -1); } else { - if (VS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &CPUParticles::_update_render_thread))) { - VS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &CPUParticles::_update_render_thread)); + if (RS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &CPUParticles3D::_update_render_thread))) { + RS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &CPUParticles3D::_update_render_thread)); } - VS::get_singleton()->instance_geometry_set_flag(get_instance(), VS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, false); - VS::get_singleton()->multimesh_set_visible_instances(multimesh, 0); + RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, false); + RS::get_singleton()->multimesh_set_visible_instances(multimesh, 0); } } } -void CPUParticles::_update_render_thread() { +void CPUParticles3D::_update_render_thread() { MutexLock lock(update_mutex); if (can_update) { - VS::get_singleton()->multimesh_set_buffer(multimesh, particle_data); + RS::get_singleton()->multimesh_set_buffer(multimesh, particle_data); can_update = false; //wait for next time } } -void CPUParticles::_notification(int p_what) { +void CPUParticles3D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { set_process_internal(emitting); @@ -1203,10 +1203,10 @@ void CPUParticles::_notification(int p_what) { } } -void CPUParticles::convert_from_particles(Node *p_particles) { +void CPUParticles3D::convert_from_particles(Node *p_particles) { - Particles *particles = Object::cast_to<Particles>(p_particles); - ERR_FAIL_COND_MSG(!particles, "Only Particles nodes can be converted to CPUParticles."); + GPUParticles3D *particles = Object::cast_to<GPUParticles3D>(p_particles); + ERR_FAIL_COND_MSG(!particles, "Only GPUParticles3D nodes can be converted to CPUParticles3D."); set_emitting(particles->is_emitting()); set_amount(particles->get_amount()); @@ -1272,42 +1272,42 @@ void CPUParticles::convert_from_particles(Node *p_particles) { #undef CONVERT_PARAM } -void CPUParticles::_bind_methods() { +void CPUParticles3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &CPUParticles::set_emitting); - ClassDB::bind_method(D_METHOD("set_amount", "amount"), &CPUParticles::set_amount); - ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &CPUParticles::set_lifetime); - ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &CPUParticles::set_one_shot); - ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &CPUParticles::set_pre_process_time); - ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &CPUParticles::set_explosiveness_ratio); - ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &CPUParticles::set_randomness_ratio); - ClassDB::bind_method(D_METHOD("set_lifetime_randomness", "random"), &CPUParticles::set_lifetime_randomness); - ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &CPUParticles::set_use_local_coordinates); - ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &CPUParticles::set_fixed_fps); - ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &CPUParticles::set_fractional_delta); - ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &CPUParticles::set_speed_scale); + ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &CPUParticles3D::set_emitting); + ClassDB::bind_method(D_METHOD("set_amount", "amount"), &CPUParticles3D::set_amount); + ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &CPUParticles3D::set_lifetime); + ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &CPUParticles3D::set_one_shot); + ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &CPUParticles3D::set_pre_process_time); + ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &CPUParticles3D::set_explosiveness_ratio); + ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &CPUParticles3D::set_randomness_ratio); + ClassDB::bind_method(D_METHOD("set_lifetime_randomness", "random"), &CPUParticles3D::set_lifetime_randomness); + ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &CPUParticles3D::set_use_local_coordinates); + ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &CPUParticles3D::set_fixed_fps); + ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &CPUParticles3D::set_fractional_delta); + ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &CPUParticles3D::set_speed_scale); - ClassDB::bind_method(D_METHOD("is_emitting"), &CPUParticles::is_emitting); - ClassDB::bind_method(D_METHOD("get_amount"), &CPUParticles::get_amount); - ClassDB::bind_method(D_METHOD("get_lifetime"), &CPUParticles::get_lifetime); - ClassDB::bind_method(D_METHOD("get_one_shot"), &CPUParticles::get_one_shot); - ClassDB::bind_method(D_METHOD("get_pre_process_time"), &CPUParticles::get_pre_process_time); - ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &CPUParticles::get_explosiveness_ratio); - ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &CPUParticles::get_randomness_ratio); - ClassDB::bind_method(D_METHOD("get_lifetime_randomness"), &CPUParticles::get_lifetime_randomness); - ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &CPUParticles::get_use_local_coordinates); - ClassDB::bind_method(D_METHOD("get_fixed_fps"), &CPUParticles::get_fixed_fps); - ClassDB::bind_method(D_METHOD("get_fractional_delta"), &CPUParticles::get_fractional_delta); - ClassDB::bind_method(D_METHOD("get_speed_scale"), &CPUParticles::get_speed_scale); + ClassDB::bind_method(D_METHOD("is_emitting"), &CPUParticles3D::is_emitting); + ClassDB::bind_method(D_METHOD("get_amount"), &CPUParticles3D::get_amount); + ClassDB::bind_method(D_METHOD("get_lifetime"), &CPUParticles3D::get_lifetime); + ClassDB::bind_method(D_METHOD("get_one_shot"), &CPUParticles3D::get_one_shot); + ClassDB::bind_method(D_METHOD("get_pre_process_time"), &CPUParticles3D::get_pre_process_time); + ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &CPUParticles3D::get_explosiveness_ratio); + ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &CPUParticles3D::get_randomness_ratio); + ClassDB::bind_method(D_METHOD("get_lifetime_randomness"), &CPUParticles3D::get_lifetime_randomness); + ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &CPUParticles3D::get_use_local_coordinates); + ClassDB::bind_method(D_METHOD("get_fixed_fps"), &CPUParticles3D::get_fixed_fps); + ClassDB::bind_method(D_METHOD("get_fractional_delta"), &CPUParticles3D::get_fractional_delta); + ClassDB::bind_method(D_METHOD("get_speed_scale"), &CPUParticles3D::get_speed_scale); - ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &CPUParticles::set_draw_order); + ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &CPUParticles3D::set_draw_order); - ClassDB::bind_method(D_METHOD("get_draw_order"), &CPUParticles::get_draw_order); + ClassDB::bind_method(D_METHOD("get_draw_order"), &CPUParticles3D::get_draw_order); - ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &CPUParticles::set_mesh); - ClassDB::bind_method(D_METHOD("get_mesh"), &CPUParticles::get_mesh); + ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &CPUParticles3D::set_mesh); + ClassDB::bind_method(D_METHOD("get_mesh"), &CPUParticles3D::get_mesh); - ClassDB::bind_method(D_METHOD("restart"), &CPUParticles::restart); + ClassDB::bind_method(D_METHOD("restart"), &CPUParticles3D::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"); @@ -1332,55 +1332,55 @@ void CPUParticles::_bind_methods() { //////////////////////////////// - ClassDB::bind_method(D_METHOD("set_direction", "direction"), &CPUParticles::set_direction); - ClassDB::bind_method(D_METHOD("get_direction"), &CPUParticles::get_direction); + ClassDB::bind_method(D_METHOD("set_direction", "direction"), &CPUParticles3D::set_direction); + ClassDB::bind_method(D_METHOD("get_direction"), &CPUParticles3D::get_direction); - ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &CPUParticles::set_spread); - ClassDB::bind_method(D_METHOD("get_spread"), &CPUParticles::get_spread); + ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &CPUParticles3D::set_spread); + ClassDB::bind_method(D_METHOD("get_spread"), &CPUParticles3D::get_spread); - ClassDB::bind_method(D_METHOD("set_flatness", "amount"), &CPUParticles::set_flatness); - ClassDB::bind_method(D_METHOD("get_flatness"), &CPUParticles::get_flatness); + ClassDB::bind_method(D_METHOD("set_flatness", "amount"), &CPUParticles3D::set_flatness); + ClassDB::bind_method(D_METHOD("get_flatness"), &CPUParticles3D::get_flatness); - ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &CPUParticles::set_param); - ClassDB::bind_method(D_METHOD("get_param", "param"), &CPUParticles::get_param); + ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &CPUParticles3D::set_param); + ClassDB::bind_method(D_METHOD("get_param", "param"), &CPUParticles3D::get_param); - ClassDB::bind_method(D_METHOD("set_param_randomness", "param", "randomness"), &CPUParticles::set_param_randomness); - ClassDB::bind_method(D_METHOD("get_param_randomness", "param"), &CPUParticles::get_param_randomness); + ClassDB::bind_method(D_METHOD("set_param_randomness", "param", "randomness"), &CPUParticles3D::set_param_randomness); + ClassDB::bind_method(D_METHOD("get_param_randomness", "param"), &CPUParticles3D::get_param_randomness); - ClassDB::bind_method(D_METHOD("set_param_curve", "param", "curve"), &CPUParticles::set_param_curve); - ClassDB::bind_method(D_METHOD("get_param_curve", "param"), &CPUParticles::get_param_curve); + ClassDB::bind_method(D_METHOD("set_param_curve", "param", "curve"), &CPUParticles3D::set_param_curve); + ClassDB::bind_method(D_METHOD("get_param_curve", "param"), &CPUParticles3D::get_param_curve); - ClassDB::bind_method(D_METHOD("set_color", "color"), &CPUParticles::set_color); - ClassDB::bind_method(D_METHOD("get_color"), &CPUParticles::get_color); + ClassDB::bind_method(D_METHOD("set_color", "color"), &CPUParticles3D::set_color); + ClassDB::bind_method(D_METHOD("get_color"), &CPUParticles3D::get_color); - ClassDB::bind_method(D_METHOD("set_color_ramp", "ramp"), &CPUParticles::set_color_ramp); - ClassDB::bind_method(D_METHOD("get_color_ramp"), &CPUParticles::get_color_ramp); + ClassDB::bind_method(D_METHOD("set_color_ramp", "ramp"), &CPUParticles3D::set_color_ramp); + ClassDB::bind_method(D_METHOD("get_color_ramp"), &CPUParticles3D::get_color_ramp); - ClassDB::bind_method(D_METHOD("set_particle_flag", "flag", "enable"), &CPUParticles::set_particle_flag); - ClassDB::bind_method(D_METHOD("get_particle_flag", "flag"), &CPUParticles::get_particle_flag); + ClassDB::bind_method(D_METHOD("set_particle_flag", "flag", "enable"), &CPUParticles3D::set_particle_flag); + ClassDB::bind_method(D_METHOD("get_particle_flag", "flag"), &CPUParticles3D::get_particle_flag); - ClassDB::bind_method(D_METHOD("set_emission_shape", "shape"), &CPUParticles::set_emission_shape); - ClassDB::bind_method(D_METHOD("get_emission_shape"), &CPUParticles::get_emission_shape); + ClassDB::bind_method(D_METHOD("set_emission_shape", "shape"), &CPUParticles3D::set_emission_shape); + ClassDB::bind_method(D_METHOD("get_emission_shape"), &CPUParticles3D::get_emission_shape); - ClassDB::bind_method(D_METHOD("set_emission_sphere_radius", "radius"), &CPUParticles::set_emission_sphere_radius); - ClassDB::bind_method(D_METHOD("get_emission_sphere_radius"), &CPUParticles::get_emission_sphere_radius); + ClassDB::bind_method(D_METHOD("set_emission_sphere_radius", "radius"), &CPUParticles3D::set_emission_sphere_radius); + ClassDB::bind_method(D_METHOD("get_emission_sphere_radius"), &CPUParticles3D::get_emission_sphere_radius); - ClassDB::bind_method(D_METHOD("set_emission_box_extents", "extents"), &CPUParticles::set_emission_box_extents); - ClassDB::bind_method(D_METHOD("get_emission_box_extents"), &CPUParticles::get_emission_box_extents); + ClassDB::bind_method(D_METHOD("set_emission_box_extents", "extents"), &CPUParticles3D::set_emission_box_extents); + ClassDB::bind_method(D_METHOD("get_emission_box_extents"), &CPUParticles3D::get_emission_box_extents); - ClassDB::bind_method(D_METHOD("set_emission_points", "array"), &CPUParticles::set_emission_points); - ClassDB::bind_method(D_METHOD("get_emission_points"), &CPUParticles::get_emission_points); + ClassDB::bind_method(D_METHOD("set_emission_points", "array"), &CPUParticles3D::set_emission_points); + ClassDB::bind_method(D_METHOD("get_emission_points"), &CPUParticles3D::get_emission_points); - ClassDB::bind_method(D_METHOD("set_emission_normals", "array"), &CPUParticles::set_emission_normals); - ClassDB::bind_method(D_METHOD("get_emission_normals"), &CPUParticles::get_emission_normals); + ClassDB::bind_method(D_METHOD("set_emission_normals", "array"), &CPUParticles3D::set_emission_normals); + ClassDB::bind_method(D_METHOD("get_emission_normals"), &CPUParticles3D::get_emission_normals); - ClassDB::bind_method(D_METHOD("set_emission_colors", "array"), &CPUParticles::set_emission_colors); - ClassDB::bind_method(D_METHOD("get_emission_colors"), &CPUParticles::get_emission_colors); + ClassDB::bind_method(D_METHOD("set_emission_colors", "array"), &CPUParticles3D::set_emission_colors); + ClassDB::bind_method(D_METHOD("get_emission_colors"), &CPUParticles3D::get_emission_colors); - ClassDB::bind_method(D_METHOD("get_gravity"), &CPUParticles::get_gravity); - ClassDB::bind_method(D_METHOD("set_gravity", "accel_vec"), &CPUParticles::set_gravity); + ClassDB::bind_method(D_METHOD("get_gravity"), &CPUParticles3D::get_gravity); + ClassDB::bind_method(D_METHOD("set_gravity", "accel_vec"), &CPUParticles3D::set_gravity); - ClassDB::bind_method(D_METHOD("convert_from_particles", "particles"), &CPUParticles::convert_from_particles); + ClassDB::bind_method(D_METHOD("convert_from_particles", "particles"), &CPUParticles3D::convert_from_particles); ADD_GROUP("Emission Shape", "emission_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_shape", PROPERTY_HINT_ENUM, "Point,Sphere,Box,Points,Directed Points"), "set_emission_shape", "get_emission_shape"); @@ -1477,7 +1477,7 @@ void CPUParticles::_bind_methods() { BIND_ENUM_CONSTANT(EMISSION_SHAPE_MAX); } -CPUParticles::CPUParticles() { +CPUParticles3D::CPUParticles3D() { time = 0; inactive_time = 0; @@ -1488,8 +1488,8 @@ CPUParticles::CPUParticles() { set_notify_transform(true); - multimesh = VisualServer::get_singleton()->multimesh_create(); - VisualServer::get_singleton()->multimesh_set_visible_instances(multimesh, 0); + multimesh = RenderingServer::get_singleton()->multimesh_create(); + RenderingServer::get_singleton()->multimesh_set_visible_instances(multimesh, 0); set_base(multimesh); set_emitting(true); @@ -1541,6 +1541,6 @@ CPUParticles::CPUParticles() { set_color(Color(1, 1, 1, 1)); } -CPUParticles::~CPUParticles() { - VS::get_singleton()->free(multimesh); +CPUParticles3D::~CPUParticles3D() { + RS::get_singleton()->free(multimesh); } diff --git a/scene/3d/cpu_particles.h b/scene/3d/cpu_particles_3d.h index 231e1f1ad9..ffe0ecc9a9 100644 --- a/scene/3d/cpu_particles.h +++ b/scene/3d/cpu_particles_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* cpu_particles.h */ +/* cpu_particles_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -32,11 +32,11 @@ #define CPU_PARTICLES_H #include "core/rid.h" -#include "scene/3d/visual_instance.h" +#include "scene/3d/visual_instance_3d.h" -class CPUParticles : public GeometryInstance { +class CPUParticles3D : public GeometryInstance3D { private: - GDCLASS(CPUParticles, GeometryInstance); + GDCLASS(CPUParticles3D, GeometryInstance3D); public: enum DrawOrder { @@ -286,13 +286,13 @@ public: void convert_from_particles(Node *p_particles); - CPUParticles(); - ~CPUParticles(); + CPUParticles3D(); + ~CPUParticles3D(); }; -VARIANT_ENUM_CAST(CPUParticles::DrawOrder) -VARIANT_ENUM_CAST(CPUParticles::Parameter) -VARIANT_ENUM_CAST(CPUParticles::Flags) -VARIANT_ENUM_CAST(CPUParticles::EmissionShape) +VARIANT_ENUM_CAST(CPUParticles3D::DrawOrder) +VARIANT_ENUM_CAST(CPUParticles3D::Parameter) +VARIANT_ENUM_CAST(CPUParticles3D::Flags) +VARIANT_ENUM_CAST(CPUParticles3D::EmissionShape) #endif // CPU_PARTICLES_H diff --git a/scene/3d/decal.cpp b/scene/3d/decal.cpp new file mode 100644 index 0000000000..4c824aedc4 --- /dev/null +++ b/scene/3d/decal.cpp @@ -0,0 +1,235 @@ +/*************************************************************************/ +/* decal.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 "decal.h" + +void Decal::set_extents(const Vector3 &p_extents) { + extents = p_extents; + RS::get_singleton()->decal_set_extents(decal, p_extents); + update_gizmo(); + _change_notify("extents"); +} + +Vector3 Decal::get_extents() const { + return extents; +} + +void Decal::set_texture(DecalTexture p_type, const Ref<Texture2D> &p_texture) { + ERR_FAIL_INDEX(p_type, TEXTURE_MAX); + textures[p_type] = p_texture; + RID texture_rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); + RS::get_singleton()->decal_set_texture(decal, RS::DecalTexture(p_type), texture_rid); +} +Ref<Texture2D> Decal::get_texture(DecalTexture p_type) const { + ERR_FAIL_INDEX_V(p_type, TEXTURE_MAX, Ref<Texture2D>()); + return textures[p_type]; +} + +void Decal::set_emission_energy(float p_energy) { + emission_energy = p_energy; + RS::get_singleton()->decal_set_emission_energy(decal, emission_energy); +} +float Decal::get_emission_energy() const { + return emission_energy; +} + +void Decal::set_albedo_mix(float p_mix) { + albedo_mix = p_mix; + RS::get_singleton()->decal_set_albedo_mix(decal, albedo_mix); +} +float Decal::get_albedo_mix() const { + return albedo_mix; +} + +void Decal::set_upper_fade(float p_fade) { + upper_fade = p_fade; + RS::get_singleton()->decal_set_fade(decal, upper_fade, lower_fade); +} +float Decal::get_upper_fade() const { + return upper_fade; +} + +void Decal::set_lower_fade(float p_fade) { + lower_fade = p_fade; + RS::get_singleton()->decal_set_fade(decal, upper_fade, lower_fade); +} +float Decal::get_lower_fade() const { + return lower_fade; +} + +void Decal::set_normal_fade(float p_fade) { + normal_fade = p_fade; + RS::get_singleton()->decal_set_normal_fade(decal, normal_fade); +} +float Decal::get_normal_fade() const { + return normal_fade; +} + +void Decal::set_modulate(Color p_modulate) { + modulate = p_modulate; + RS::get_singleton()->decal_set_modulate(decal, p_modulate); +} + +Color Decal::get_modulate() const { + return modulate; +} + +void Decal::set_enable_distance_fade(bool p_enable) { + distance_fade_enabled = p_enable; + RS::get_singleton()->decal_set_distance_fade(decal, distance_fade_enabled, distance_fade_begin, distance_fade_length); +} +bool Decal::is_distance_fade_enabled() const { + return distance_fade_enabled; +} + +void Decal::set_distance_fade_begin(float p_distance) { + distance_fade_begin = p_distance; + RS::get_singleton()->decal_set_distance_fade(decal, distance_fade_enabled, distance_fade_begin, distance_fade_length); +} +float Decal::get_distance_fade_begin() const { + return distance_fade_begin; +} + +void Decal::set_distance_fade_length(float p_length) { + distance_fade_length = p_length; + RS::get_singleton()->decal_set_distance_fade(decal, distance_fade_enabled, distance_fade_begin, distance_fade_length); +} +float Decal::get_distance_fade_length() const { + return distance_fade_length; +} + +void Decal::set_cull_mask(uint32_t p_layers) { + cull_mask = p_layers; + RS::get_singleton()->decal_set_cull_mask(decal, cull_mask); +} +uint32_t Decal::get_cull_mask() const { + return cull_mask; +} + +AABB Decal::get_aabb() const { + + AABB aabb; + aabb.position = -extents; + aabb.size = extents * 2.0; + return aabb; +} +Vector<Face3> Decal::get_faces(uint32_t p_usage_flags) const { + + return Vector<Face3>(); +} + +void Decal::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_extents", "extents"), &Decal::set_extents); + ClassDB::bind_method(D_METHOD("get_extents"), &Decal::get_extents); + + ClassDB::bind_method(D_METHOD("set_texture", "type", "texture"), &Decal::set_texture); + ClassDB::bind_method(D_METHOD("get_texture", "type"), &Decal::get_texture); + + ClassDB::bind_method(D_METHOD("set_emission_energy", "energy"), &Decal::set_emission_energy); + ClassDB::bind_method(D_METHOD("get_emission_energy"), &Decal::get_emission_energy); + + ClassDB::bind_method(D_METHOD("set_albedo_mix", "energy"), &Decal::set_albedo_mix); + ClassDB::bind_method(D_METHOD("get_albedo_mix"), &Decal::get_albedo_mix); + + ClassDB::bind_method(D_METHOD("set_modulate", "color"), &Decal::set_modulate); + ClassDB::bind_method(D_METHOD("get_modulate"), &Decal::get_modulate); + + ClassDB::bind_method(D_METHOD("set_upper_fade", "fade"), &Decal::set_upper_fade); + ClassDB::bind_method(D_METHOD("get_upper_fade"), &Decal::get_upper_fade); + + ClassDB::bind_method(D_METHOD("set_lower_fade", "fade"), &Decal::set_lower_fade); + ClassDB::bind_method(D_METHOD("get_lower_fade"), &Decal::get_lower_fade); + + ClassDB::bind_method(D_METHOD("set_normal_fade", "fade"), &Decal::set_normal_fade); + ClassDB::bind_method(D_METHOD("get_normal_fade"), &Decal::get_normal_fade); + + ClassDB::bind_method(D_METHOD("set_enable_distance_fade", "enable"), &Decal::set_enable_distance_fade); + ClassDB::bind_method(D_METHOD("is_distance_fade_enabled"), &Decal::is_distance_fade_enabled); + + ClassDB::bind_method(D_METHOD("set_distance_fade_begin", "distance"), &Decal::set_distance_fade_begin); + ClassDB::bind_method(D_METHOD("get_distance_fade_begin"), &Decal::get_distance_fade_begin); + + ClassDB::bind_method(D_METHOD("set_distance_fade_length", "distance"), &Decal::set_distance_fade_length); + ClassDB::bind_method(D_METHOD("get_distance_fade_length"), &Decal::get_distance_fade_length); + + ClassDB::bind_method(D_METHOD("set_cull_mask", "mask"), &Decal::set_cull_mask); + ClassDB::bind_method(D_METHOD("get_cull_mask"), &Decal::get_cull_mask); + + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents", PROPERTY_HINT_RANGE, "0,1024,0.001,or_greater"), "set_extents", "get_extents"); + ADD_GROUP("Textures", "texture_"); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "texture_albedo", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_ALBEDO); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "texture_normal", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_NORMAL); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "texture_orm", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_ORM); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "texture_emission", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_EMISSION); + ADD_GROUP("Parameters", ""); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_energy", PROPERTY_HINT_RANGE, "0,128,0.01"), "set_emission_energy", "get_emission_energy"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "albedo_mix", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_albedo_mix", "get_albedo_mix"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "normal_fade", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_normal_fade", "get_normal_fade"); + ADD_GROUP("Vertical Fade", ""); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "upper_fade", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_upper_fade", "get_upper_fade"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lower_fade", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_lower_fade", "get_lower_fade"); + ADD_GROUP("Distance Fade", "distance_fade_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "distance_fade_enabled"), "set_enable_distance_fade", "is_distance_fade_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "distance_fade_begin"), "set_distance_fade_begin", "get_distance_fade_begin"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "distance_fade_length"), "set_distance_fade_length", "get_distance_fade_length"); + ADD_GROUP("Cull Mask", ""); + ADD_PROPERTY(PropertyInfo(Variant::INT, "cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask"); + + BIND_ENUM_CONSTANT(TEXTURE_ALBEDO); + BIND_ENUM_CONSTANT(TEXTURE_NORMAL); + BIND_ENUM_CONSTANT(TEXTURE_ORM); + BIND_ENUM_CONSTANT(TEXTURE_EMISSION); + BIND_ENUM_CONSTANT(TEXTURE_MAX); +} + +Decal::Decal() { + + extents = Vector3(1, 1, 1); + emission_energy = 1.0; + modulate = Color(1, 1, 1, 1); + albedo_mix = 1.0; + cull_mask = (1 << 20) - 1; + upper_fade = 0.3; + lower_fade = 0.3; + normal_fade = 0; + distance_fade_enabled = false; + distance_fade_begin = 10; + distance_fade_length = 1; + + decal = RenderingServer::get_singleton()->decal_create(); + RS::get_singleton()->instance_set_base(get_instance(), decal); +} + +Decal::~Decal() { + + RS::get_singleton()->free(decal); +} diff --git a/scene/3d/decal.h b/scene/3d/decal.h new file mode 100644 index 0000000000..665444829d --- /dev/null +++ b/scene/3d/decal.h @@ -0,0 +1,114 @@ +/*************************************************************************/ +/* decal.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 DECAL_H +#define DECAL_H + +#include "scene/3d/visual_instance_3d.h" +#include "scene/resources/texture.h" +#include "servers/rendering_server.h" + +class Decal : public VisualInstance3D { + GDCLASS(Decal, VisualInstance3D); + +public: + enum DecalTexture { + TEXTURE_ALBEDO, + TEXTURE_NORMAL, + TEXTURE_ORM, + TEXTURE_EMISSION, + TEXTURE_MAX + }; + +private: + RID decal; + Vector3 extents; + Ref<Texture2D> textures[TEXTURE_MAX]; + float emission_energy; + float albedo_mix; + Color modulate; + uint32_t cull_mask; + float normal_fade; + float upper_fade; + float lower_fade; + bool distance_fade_enabled; + float distance_fade_begin; + float distance_fade_length; + +protected: + static void _bind_methods(); + +public: + void set_extents(const Vector3 &p_extents); + Vector3 get_extents() const; + + void set_texture(DecalTexture p_type, const Ref<Texture2D> &p_texture); + Ref<Texture2D> get_texture(DecalTexture p_type) const; + + void set_emission_energy(float p_energy); + float get_emission_energy() const; + + void set_albedo_mix(float p_mix); + float get_albedo_mix() const; + + void set_modulate(Color p_modulate); + Color get_modulate() const; + + void set_upper_fade(float p_energy); + float get_upper_fade() const; + + void set_lower_fade(float p_fade); + float get_lower_fade() const; + + void set_normal_fade(float p_fade); + float get_normal_fade() const; + + void set_enable_distance_fade(bool p_enable); + bool is_distance_fade_enabled() const; + + void set_distance_fade_begin(float p_distance); + float get_distance_fade_begin() const; + + void set_distance_fade_length(float p_length); + float get_distance_fade_length() const; + + void set_cull_mask(uint32_t p_layers); + uint32_t get_cull_mask() const; + + virtual AABB get_aabb() const; + virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const; + + Decal(); + ~Decal(); +}; + +VARIANT_ENUM_CAST(Decal::DecalTexture); + +#endif // DECAL_H diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp index c3f039ae85..6d571ee4f2 100644 --- a/scene/3d/gi_probe.cpp +++ b/scene/3d/gi_probe.cpp @@ -33,7 +33,7 @@ #include "core/os/os.h" #include "core/method_bind_ext.gen.inc" -#include "mesh_instance.h" +#include "mesh_instance_3d.h" #include "voxelizer.h" void GIProbeData::_set_data(const Dictionary &p_data) { @@ -92,7 +92,7 @@ Dictionary GIProbeData::_get_data() const { } void GIProbeData::allocate(const Transform &p_to_cell_xform, const AABB &p_aabb, const Vector3 &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) { - VS::get_singleton()->gi_probe_allocate(probe, p_to_cell_xform, p_aabb, p_octree_size, p_octree_cells, p_data_cells, p_distance_field, p_level_counts); + RS::get_singleton()->gi_probe_allocate(probe, p_to_cell_xform, p_aabb, p_octree_size, p_octree_cells, p_data_cells, p_distance_field, p_level_counts); bounds = p_aabb; to_cell_xform = p_to_cell_xform; octree_size = p_octree_size; @@ -105,24 +105,24 @@ Vector3 GIProbeData::get_octree_size() const { return octree_size; } Vector<uint8_t> GIProbeData::get_octree_cells() const { - return VS::get_singleton()->gi_probe_get_octree_cells(probe); + return RS::get_singleton()->gi_probe_get_octree_cells(probe); } Vector<uint8_t> GIProbeData::get_data_cells() const { - return VS::get_singleton()->gi_probe_get_data_cells(probe); + return RS::get_singleton()->gi_probe_get_data_cells(probe); } Vector<uint8_t> GIProbeData::get_distance_field() const { - return VS::get_singleton()->gi_probe_get_distance_field(probe); + return RS::get_singleton()->gi_probe_get_distance_field(probe); } Vector<int> GIProbeData::get_level_counts() const { - return VS::get_singleton()->gi_probe_get_level_counts(probe); + return RS::get_singleton()->gi_probe_get_level_counts(probe); } Transform GIProbeData::get_to_cell_xform() const { return to_cell_xform; } void GIProbeData::set_dynamic_range(float p_range) { - VS::get_singleton()->gi_probe_set_dynamic_range(probe, p_range); + RS::get_singleton()->gi_probe_set_dynamic_range(probe, p_range); dynamic_range = p_range; } @@ -131,7 +131,7 @@ float GIProbeData::get_dynamic_range() const { } void GIProbeData::set_propagation(float p_propagation) { - VS::get_singleton()->gi_probe_set_propagation(probe, p_propagation); + RS::get_singleton()->gi_probe_set_propagation(probe, p_propagation); propagation = p_propagation; } @@ -140,7 +140,7 @@ float GIProbeData::get_propagation() const { } void GIProbeData::set_anisotropy_strength(float p_anisotropy_strength) { - VS::get_singleton()->gi_probe_set_anisotropy_strength(probe, p_anisotropy_strength); + RS::get_singleton()->gi_probe_set_anisotropy_strength(probe, p_anisotropy_strength); anisotropy_strength = p_anisotropy_strength; } @@ -149,7 +149,7 @@ float GIProbeData::get_anisotropy_strength() const { } void GIProbeData::set_energy(float p_energy) { - VS::get_singleton()->gi_probe_set_energy(probe, p_energy); + RS::get_singleton()->gi_probe_set_energy(probe, p_energy); energy = p_energy; } @@ -158,7 +158,7 @@ float GIProbeData::get_energy() const { } void GIProbeData::set_ao(float p_ao) { - VS::get_singleton()->gi_probe_set_ao(probe, p_ao); + RS::get_singleton()->gi_probe_set_ao(probe, p_ao); ao = p_ao; } @@ -167,7 +167,7 @@ float GIProbeData::get_ao() const { } void GIProbeData::set_ao_size(float p_ao_size) { - VS::get_singleton()->gi_probe_set_ao_size(probe, p_ao_size); + RS::get_singleton()->gi_probe_set_ao_size(probe, p_ao_size); ao_size = p_ao_size; } @@ -176,7 +176,7 @@ float GIProbeData::get_ao_size() const { } void GIProbeData::set_bias(float p_bias) { - VS::get_singleton()->gi_probe_set_bias(probe, p_bias); + RS::get_singleton()->gi_probe_set_bias(probe, p_bias); bias = p_bias; } @@ -185,7 +185,7 @@ float GIProbeData::get_bias() const { } void GIProbeData::set_normal_bias(float p_normal_bias) { - VS::get_singleton()->gi_probe_set_normal_bias(probe, p_normal_bias); + RS::get_singleton()->gi_probe_set_normal_bias(probe, p_normal_bias); normal_bias = p_normal_bias; } @@ -194,7 +194,7 @@ float GIProbeData::get_normal_bias() const { } void GIProbeData::set_interior(bool p_enable) { - VS::get_singleton()->gi_probe_set_interior(probe, p_enable); + RS::get_singleton()->gi_probe_set_interior(probe, p_enable); interior = p_enable; } @@ -203,7 +203,7 @@ bool GIProbeData::is_interior() const { } void GIProbeData::set_use_two_bounces(bool p_enable) { - VS::get_singleton()->gi_probe_set_use_two_bounces(probe, p_enable); + RS::get_singleton()->gi_probe_set_use_two_bounces(probe, p_enable); use_two_bounces = p_enable; } @@ -293,13 +293,14 @@ GIProbeData::GIProbeData() { propagation = 0.7; anisotropy_strength = 0.5; interior = false; + use_two_bounces = false; - probe = VS::get_singleton()->gi_probe_create(); + probe = RS::get_singleton()->gi_probe_create(); } GIProbeData::~GIProbeData() { - VS::get_singleton()->free(probe); + RS::get_singleton()->free(probe); } ////////////////////// @@ -308,9 +309,9 @@ GIProbeData::~GIProbeData() { void GIProbe::set_probe_data(const Ref<GIProbeData> &p_data) { if (p_data.is_valid()) { - VS::get_singleton()->instance_set_base(get_instance(), p_data->get_rid()); + RS::get_singleton()->instance_set_base(get_instance(), p_data->get_rid()); } else { - VS::get_singleton()->instance_set_base(get_instance(), RID()); + RS::get_singleton()->instance_set_base(get_instance(), RID()); } probe_data = p_data; @@ -347,8 +348,8 @@ Vector3 GIProbe::get_extents() const { void GIProbe::_find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes) { - MeshInstance *mi = Object::cast_to<MeshInstance>(p_at_node); - if (mi && mi->get_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT) && mi->is_visible_in_tree()) { + MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_at_node); + if (mi && mi->get_flag(GeometryInstance3D::FLAG_USE_BAKED_LIGHT) && mi->is_visible_in_tree()) { Ref<Mesh> mesh = mi->get_mesh(); if (mesh.is_valid()) { @@ -369,7 +370,7 @@ void GIProbe::_find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes) { } } - Spatial *s = Object::cast_to<Spatial>(p_at_node); + Node3D *s = Object::cast_to<Node3D>(p_at_node); if (s) { if (s->is_visible_in_tree()) { @@ -402,9 +403,9 @@ void GIProbe::_find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes) { } } -GIProbe::BakeBeginFunc GIProbe::bake_begin_function = NULL; -GIProbe::BakeStepFunc GIProbe::bake_step_function = NULL; -GIProbe::BakeEndFunc GIProbe::bake_end_function = NULL; +GIProbe::BakeBeginFunc GIProbe::bake_begin_function = nullptr; +GIProbe::BakeStepFunc GIProbe::bake_step_function = nullptr; +GIProbe::BakeEndFunc GIProbe::bake_end_function = nullptr; Vector3i GIProbe::get_estimated_cell_size() const { static const int subdiv_value[SUBDIV_MAX] = { 6, 7, 8, 9 }; @@ -468,7 +469,7 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug) { //create the data for visual server if (p_create_visual_debug) { - MultiMeshInstance *mmi = memnew(MultiMeshInstance); + MultiMeshInstance3D *mmi = memnew(MultiMeshInstance3D); mmi->set_multimesh(baker.create_debug_multimesh()); add_child(mmi); #ifdef TOOLS_ENABLED @@ -511,7 +512,7 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug) { void GIProbe::_debug_bake() { - bake(NULL, true); + bake(nullptr, true); } AABB GIProbe::get_aabb() const { @@ -526,7 +527,7 @@ Vector<Face3> GIProbe::get_faces(uint32_t p_usage_flags) const { String GIProbe::get_configuration_warning() const { - if (OS::get_singleton()->get_current_video_driver() == OS::VIDEO_DRIVER_GLES2) { + if (RenderingServer::get_singleton()->is_low_end()) { return TTR("GIProbes are not supported by the GLES2 video driver.\nUse a BakedLightmap instead."); } return String(); @@ -563,10 +564,10 @@ GIProbe::GIProbe() { subdiv = SUBDIV_128; extents = Vector3(10, 10, 10); - gi_probe = VS::get_singleton()->gi_probe_create(); + gi_probe = RS::get_singleton()->gi_probe_create(); set_disable_scale(true); } GIProbe::~GIProbe() { - VS::get_singleton()->free(gi_probe); + RS::get_singleton()->free(gi_probe); } diff --git a/scene/3d/gi_probe.h b/scene/3d/gi_probe.h index f991843883..28b533e82d 100644 --- a/scene/3d/gi_probe.h +++ b/scene/3d/gi_probe.h @@ -31,8 +31,8 @@ #ifndef GIPROBE_H #define GIPROBE_H -#include "multimesh_instance.h" -#include "scene/3d/visual_instance.h" +#include "multimesh_instance_3d.h" +#include "scene/3d/visual_instance_3d.h" class GIProbeData : public Resource { @@ -108,8 +108,8 @@ public: ~GIProbeData(); }; -class GIProbe : public VisualInstance { - GDCLASS(GIProbe, VisualInstance); +class GIProbe : public VisualInstance3D { + GDCLASS(GIProbe, VisualInstance3D); public: enum Subdiv { @@ -161,7 +161,7 @@ public: Vector3 get_extents() const; Vector3i get_estimated_cell_size() const; - void bake(Node *p_from_node = NULL, bool p_create_visual_debug = false); + void bake(Node *p_from_node = nullptr, bool p_create_visual_debug = false); virtual AABB get_aabb() const; virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const; diff --git a/scene/3d/particles.cpp b/scene/3d/gpu_particles_3d.cpp index e502b0c037..7744c477cb 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/gpu_particles_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* particles.cpp */ +/* gpu_particles_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,25 +28,25 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "particles.h" +#include "gpu_particles_3d.h" #include "core/os/os.h" #include "scene/resources/particles_material.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" -AABB Particles::get_aabb() const { +AABB GPUParticles3D::get_aabb() const { return AABB(); } -Vector<Face3> Particles::get_faces(uint32_t p_usage_flags) const { +Vector<Face3> GPUParticles3D::get_faces(uint32_t p_usage_flags) const { return Vector<Face3>(); } -void Particles::set_emitting(bool p_emitting) { +void GPUParticles3D::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); @@ -55,150 +55,150 @@ void Particles::set_emitting(bool p_emitting) { } } -void Particles::set_amount(int p_amount) { +void GPUParticles3D::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 Particles::set_lifetime(float p_lifetime) { +void GPUParticles3D::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 Particles::set_one_shot(bool p_one_shot) { +void GPUParticles3D::set_one_shot(bool p_one_shot) { one_shot = p_one_shot; - 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 Particles::set_pre_process_time(float p_time) { +void GPUParticles3D::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 Particles::set_explosiveness_ratio(float p_ratio) { +void GPUParticles3D::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 Particles::set_randomness_ratio(float p_ratio) { +void GPUParticles3D::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 Particles::set_visibility_aabb(const AABB &p_aabb) { +void GPUParticles3D::set_visibility_aabb(const AABB &p_aabb) { visibility_aabb = p_aabb; - VS::get_singleton()->particles_set_custom_aabb(particles, visibility_aabb); + RS::get_singleton()->particles_set_custom_aabb(particles, visibility_aabb); update_gizmo(); _change_notify("visibility_aabb"); } -void Particles::set_use_local_coordinates(bool p_enable) { +void GPUParticles3D::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); } -void Particles::set_process_material(const Ref<Material> &p_material) { +void GPUParticles3D::set_process_material(const Ref<Material> &p_material) { process_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 Particles::set_speed_scale(float p_scale) { +void GPUParticles3D::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 Particles::is_emitting() const { +bool GPUParticles3D::is_emitting() const { - return VS::get_singleton()->particles_get_emitting(particles); + return RS::get_singleton()->particles_get_emitting(particles); } -int Particles::get_amount() const { +int GPUParticles3D::get_amount() const { return amount; } -float Particles::get_lifetime() const { +float GPUParticles3D::get_lifetime() const { return lifetime; } -bool Particles::get_one_shot() const { +bool GPUParticles3D::get_one_shot() const { return one_shot; } -float Particles::get_pre_process_time() const { +float GPUParticles3D::get_pre_process_time() const { return pre_process_time; } -float Particles::get_explosiveness_ratio() const { +float GPUParticles3D::get_explosiveness_ratio() const { return explosiveness_ratio; } -float Particles::get_randomness_ratio() const { +float GPUParticles3D::get_randomness_ratio() const { return randomness_ratio; } -AABB Particles::get_visibility_aabb() const { +AABB GPUParticles3D::get_visibility_aabb() const { return visibility_aabb; } -bool Particles::get_use_local_coordinates() const { +bool GPUParticles3D::get_use_local_coordinates() const { return local_coords; } -Ref<Material> Particles::get_process_material() const { +Ref<Material> GPUParticles3D::get_process_material() const { return process_material; } -float Particles::get_speed_scale() const { +float GPUParticles3D::get_speed_scale() const { return speed_scale; } -void Particles::set_draw_order(DrawOrder p_order) { +void GPUParticles3D::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)); } -Particles::DrawOrder Particles::get_draw_order() const { +GPUParticles3D::DrawOrder GPUParticles3D::get_draw_order() const { return draw_order; } -void Particles::set_draw_passes(int p_count) { +void GPUParticles3D::set_draw_passes(int p_count) { ERR_FAIL_COND(p_count < 1); draw_passes.resize(p_count); - VS::get_singleton()->particles_set_draw_passes(particles, p_count); + RS::get_singleton()->particles_set_draw_passes(particles, p_count); _change_notify(); } -int Particles::get_draw_passes() const { +int GPUParticles3D::get_draw_passes() const { return draw_passes.size(); } -void Particles::set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh) { +void GPUParticles3D::set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh) { ERR_FAIL_INDEX(p_pass, draw_passes.size()); @@ -208,40 +208,40 @@ void Particles::set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh) { if (p_mesh.is_valid()) mesh_rid = p_mesh->get_rid(); - VS::get_singleton()->particles_set_draw_pass_mesh(particles, p_pass, mesh_rid); + RS::get_singleton()->particles_set_draw_pass_mesh(particles, p_pass, mesh_rid); update_configuration_warning(); } -Ref<Mesh> Particles::get_draw_pass_mesh(int p_pass) const { +Ref<Mesh> GPUParticles3D::get_draw_pass_mesh(int p_pass) const { ERR_FAIL_INDEX_V(p_pass, draw_passes.size(), Ref<Mesh>()); return draw_passes[p_pass]; } -void Particles::set_fixed_fps(int p_count) { +void GPUParticles3D::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 Particles::get_fixed_fps() const { +int GPUParticles3D::get_fixed_fps() const { return fixed_fps; } -void Particles::set_fractional_delta(bool p_enable) { +void GPUParticles3D::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 Particles::get_fractional_delta() const { +bool GPUParticles3D::get_fractional_delta() const { return fractional_delta; } -String Particles::get_configuration_warning() const { +String GPUParticles3D::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 CPUParticles 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 CPUParticles3D node instead. You can use the \"Convert to CPUParticles3D\" option for this purpose."); } String warnings; @@ -253,7 +253,7 @@ String Particles::get_configuration_warning() const { if (draw_passes[i].is_valid()) { meshes_found = true; for (int j = 0; j < draw_passes[i]->get_surface_count(); j++) { - anim_material_found = Object::cast_to<ShaderMaterial>(draw_passes[i]->surface_get_material(j).ptr()) != NULL; + anim_material_found = Object::cast_to<ShaderMaterial>(draw_passes[i]->surface_get_material(j).ptr()) != nullptr; StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(draw_passes[i]->surface_get_material(j).ptr()); anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES); } @@ -261,7 +261,7 @@ String Particles::get_configuration_warning() const { } } - anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != NULL; + anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != nullptr; StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(get_material_override().ptr()); anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES); @@ -289,18 +289,18 @@ String Particles::get_configuration_warning() const { return warnings; } -void Particles::restart() { +void GPUParticles3D::restart() { - VisualServer::get_singleton()->particles_restart(particles); - VisualServer::get_singleton()->particles_set_emitting(particles, true); + RenderingServer::get_singleton()->particles_restart(particles); + RenderingServer::get_singleton()->particles_set_emitting(particles, true); } -AABB Particles::capture_aabb() const { +AABB GPUParticles3D::capture_aabb() const { - return VS::get_singleton()->particles_get_current_aabb(particles); + return RS::get_singleton()->particles_get_current_aabb(particles); } -void Particles::_validate_property(PropertyInfo &property) const { +void GPUParticles3D::_validate_property(PropertyInfo &property) const { if (property.name.begins_with("draw_pass_")) { int index = property.name.get_slicec('_', 2).to_int() - 1; @@ -311,14 +311,14 @@ void Particles::_validate_property(PropertyInfo &property) const { } } -void Particles::_notification(int p_what) { +void GPUParticles3D::_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); } } @@ -334,54 +334,54 @@ void Particles::_notification(int p_what) { if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { // make sure particles are updated before rendering occurs if they were active before - if (is_visible_in_tree() && !VS::get_singleton()->particles_is_inactive(particles)) { - VS::get_singleton()->particles_request_process(particles); + if (is_visible_in_tree() && !RS::get_singleton()->particles_is_inactive(particles)) { + RS::get_singleton()->particles_request_process(particles); } } } -void Particles::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &Particles::set_emitting); - ClassDB::bind_method(D_METHOD("set_amount", "amount"), &Particles::set_amount); - ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &Particles::set_lifetime); - ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &Particles::set_one_shot); - ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &Particles::set_pre_process_time); - ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &Particles::set_explosiveness_ratio); - ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &Particles::set_randomness_ratio); - ClassDB::bind_method(D_METHOD("set_visibility_aabb", "aabb"), &Particles::set_visibility_aabb); - ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &Particles::set_use_local_coordinates); - ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &Particles::set_fixed_fps); - ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &Particles::set_fractional_delta); - ClassDB::bind_method(D_METHOD("set_process_material", "material"), &Particles::set_process_material); - ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &Particles::set_speed_scale); - - ClassDB::bind_method(D_METHOD("is_emitting"), &Particles::is_emitting); - ClassDB::bind_method(D_METHOD("get_amount"), &Particles::get_amount); - ClassDB::bind_method(D_METHOD("get_lifetime"), &Particles::get_lifetime); - ClassDB::bind_method(D_METHOD("get_one_shot"), &Particles::get_one_shot); - ClassDB::bind_method(D_METHOD("get_pre_process_time"), &Particles::get_pre_process_time); - ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &Particles::get_explosiveness_ratio); - ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &Particles::get_randomness_ratio); - ClassDB::bind_method(D_METHOD("get_visibility_aabb"), &Particles::get_visibility_aabb); - ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &Particles::get_use_local_coordinates); - ClassDB::bind_method(D_METHOD("get_fixed_fps"), &Particles::get_fixed_fps); - ClassDB::bind_method(D_METHOD("get_fractional_delta"), &Particles::get_fractional_delta); - ClassDB::bind_method(D_METHOD("get_process_material"), &Particles::get_process_material); - ClassDB::bind_method(D_METHOD("get_speed_scale"), &Particles::get_speed_scale); - - ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &Particles::set_draw_order); - - ClassDB::bind_method(D_METHOD("get_draw_order"), &Particles::get_draw_order); - - ClassDB::bind_method(D_METHOD("set_draw_passes", "passes"), &Particles::set_draw_passes); - ClassDB::bind_method(D_METHOD("set_draw_pass_mesh", "pass", "mesh"), &Particles::set_draw_pass_mesh); - - ClassDB::bind_method(D_METHOD("get_draw_passes"), &Particles::get_draw_passes); - ClassDB::bind_method(D_METHOD("get_draw_pass_mesh", "pass"), &Particles::get_draw_pass_mesh); - - ClassDB::bind_method(D_METHOD("restart"), &Particles::restart); - ClassDB::bind_method(D_METHOD("capture_aabb"), &Particles::capture_aabb); +void GPUParticles3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &GPUParticles3D::set_emitting); + ClassDB::bind_method(D_METHOD("set_amount", "amount"), &GPUParticles3D::set_amount); + ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &GPUParticles3D::set_lifetime); + ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &GPUParticles3D::set_one_shot); + ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &GPUParticles3D::set_pre_process_time); + ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &GPUParticles3D::set_explosiveness_ratio); + ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &GPUParticles3D::set_randomness_ratio); + ClassDB::bind_method(D_METHOD("set_visibility_aabb", "aabb"), &GPUParticles3D::set_visibility_aabb); + ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &GPUParticles3D::set_use_local_coordinates); + ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &GPUParticles3D::set_fixed_fps); + ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &GPUParticles3D::set_fractional_delta); + ClassDB::bind_method(D_METHOD("set_process_material", "material"), &GPUParticles3D::set_process_material); + ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &GPUParticles3D::set_speed_scale); + + ClassDB::bind_method(D_METHOD("is_emitting"), &GPUParticles3D::is_emitting); + ClassDB::bind_method(D_METHOD("get_amount"), &GPUParticles3D::get_amount); + ClassDB::bind_method(D_METHOD("get_lifetime"), &GPUParticles3D::get_lifetime); + ClassDB::bind_method(D_METHOD("get_one_shot"), &GPUParticles3D::get_one_shot); + ClassDB::bind_method(D_METHOD("get_pre_process_time"), &GPUParticles3D::get_pre_process_time); + ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &GPUParticles3D::get_explosiveness_ratio); + ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &GPUParticles3D::get_randomness_ratio); + ClassDB::bind_method(D_METHOD("get_visibility_aabb"), &GPUParticles3D::get_visibility_aabb); + ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &GPUParticles3D::get_use_local_coordinates); + ClassDB::bind_method(D_METHOD("get_fixed_fps"), &GPUParticles3D::get_fixed_fps); + ClassDB::bind_method(D_METHOD("get_fractional_delta"), &GPUParticles3D::get_fractional_delta); + ClassDB::bind_method(D_METHOD("get_process_material"), &GPUParticles3D::get_process_material); + ClassDB::bind_method(D_METHOD("get_speed_scale"), &GPUParticles3D::get_speed_scale); + + ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &GPUParticles3D::set_draw_order); + + ClassDB::bind_method(D_METHOD("get_draw_order"), &GPUParticles3D::get_draw_order); + + ClassDB::bind_method(D_METHOD("set_draw_passes", "passes"), &GPUParticles3D::set_draw_passes); + ClassDB::bind_method(D_METHOD("set_draw_pass_mesh", "pass", "mesh"), &GPUParticles3D::set_draw_pass_mesh); + + ClassDB::bind_method(D_METHOD("get_draw_passes"), &GPUParticles3D::get_draw_passes); + ClassDB::bind_method(D_METHOD("get_draw_pass_mesh", "pass"), &GPUParticles3D::get_draw_pass_mesh); + + ClassDB::bind_method(D_METHOD("restart"), &GPUParticles3D::restart); + ClassDB::bind_method(D_METHOD("capture_aabb"), &GPUParticles3D::capture_aabb); 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"); @@ -414,9 +414,9 @@ void Particles::_bind_methods() { BIND_CONSTANT(MAX_DRAW_PASSES); } -Particles::Particles() { +GPUParticles3D::GPUParticles3D() { - particles = VS::get_singleton()->particles_create(); + particles = RS::get_singleton()->particles_create(); set_base(particles); one_shot = false; // Needed so that set_emitting doesn't access uninitialized values set_emitting(true); @@ -435,7 +435,7 @@ Particles::Particles() { set_speed_scale(1); } -Particles::~Particles() { +GPUParticles3D::~GPUParticles3D() { - VS::get_singleton()->free(particles); + RS::get_singleton()->free(particles); } diff --git a/scene/3d/particles.h b/scene/3d/gpu_particles_3d.h index cf461f25e9..0c6653294b 100644 --- a/scene/3d/particles.h +++ b/scene/3d/gpu_particles_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* particles.h */ +/* gpu_particles_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -32,12 +32,12 @@ #define PARTICLES_H #include "core/rid.h" -#include "scene/3d/visual_instance.h" +#include "scene/3d/visual_instance_3d.h" #include "scene/resources/material.h" -class Particles : public GeometryInstance { +class GPUParticles3D : public GeometryInstance3D { private: - GDCLASS(Particles, GeometryInstance); + GDCLASS(GPUParticles3D, GeometryInstance3D); public: enum DrawOrder { @@ -124,10 +124,10 @@ public: void restart(); AABB capture_aabb() const; - Particles(); - ~Particles(); + GPUParticles3D(); + ~GPUParticles3D(); }; -VARIANT_ENUM_CAST(Particles::DrawOrder) +VARIANT_ENUM_CAST(GPUParticles3D::DrawOrder) #endif // PARTICLES_H diff --git a/scene/3d/immediate_geometry.cpp b/scene/3d/immediate_geometry_3d.cpp index f5b08b86e1..63d4b1ac84 100644 --- a/scene/3d/immediate_geometry.cpp +++ b/scene/3d/immediate_geometry_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* immediate_geometry.cpp */ +/* immediate_geometry_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,43 +28,43 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "immediate_geometry.h" +#include "immediate_geometry_3d.h" -void ImmediateGeometry::begin(Mesh::PrimitiveType p_primitive, const Ref<Texture2D> &p_texture) { +void ImmediateGeometry3D::begin(Mesh::PrimitiveType p_primitive, const Ref<Texture2D> &p_texture) { - VS::get_singleton()->immediate_begin(im, (VS::PrimitiveType)p_primitive, p_texture.is_valid() ? p_texture->get_rid() : RID()); + RS::get_singleton()->immediate_begin(im, (RS::PrimitiveType)p_primitive, p_texture.is_valid() ? p_texture->get_rid() : RID()); if (p_texture.is_valid()) cached_textures.push_back(p_texture); } -void ImmediateGeometry::set_normal(const Vector3 &p_normal) { +void ImmediateGeometry3D::set_normal(const Vector3 &p_normal) { - VS::get_singleton()->immediate_normal(im, p_normal); + RS::get_singleton()->immediate_normal(im, p_normal); } -void ImmediateGeometry::set_tangent(const Plane &p_tangent) { +void ImmediateGeometry3D::set_tangent(const Plane &p_tangent) { - VS::get_singleton()->immediate_tangent(im, p_tangent); + RS::get_singleton()->immediate_tangent(im, p_tangent); } -void ImmediateGeometry::set_color(const Color &p_color) { +void ImmediateGeometry3D::set_color(const Color &p_color) { - VS::get_singleton()->immediate_color(im, p_color); + RS::get_singleton()->immediate_color(im, p_color); } -void ImmediateGeometry::set_uv(const Vector2 &p_uv) { +void ImmediateGeometry3D::set_uv(const Vector2 &p_uv) { - VS::get_singleton()->immediate_uv(im, p_uv); + RS::get_singleton()->immediate_uv(im, p_uv); } -void ImmediateGeometry::set_uv2(const Vector2 &p_uv2) { +void ImmediateGeometry3D::set_uv2(const Vector2 &p_uv2) { - VS::get_singleton()->immediate_uv2(im, p_uv2); + RS::get_singleton()->immediate_uv2(im, p_uv2); } -void ImmediateGeometry::add_vertex(const Vector3 &p_vertex) { +void ImmediateGeometry3D::add_vertex(const Vector3 &p_vertex) { - VS::get_singleton()->immediate_vertex(im, p_vertex); + RS::get_singleton()->immediate_vertex(im, p_vertex); if (empty) { aabb.position = p_vertex; aabb.size = Vector3(); @@ -74,28 +74,28 @@ void ImmediateGeometry::add_vertex(const Vector3 &p_vertex) { } } -void ImmediateGeometry::end() { +void ImmediateGeometry3D::end() { - VS::get_singleton()->immediate_end(im); + RS::get_singleton()->immediate_end(im); } -void ImmediateGeometry::clear() { +void ImmediateGeometry3D::clear() { - VS::get_singleton()->immediate_clear(im); + RS::get_singleton()->immediate_clear(im); empty = true; cached_textures.clear(); } -AABB ImmediateGeometry::get_aabb() const { +AABB ImmediateGeometry3D::get_aabb() const { return aabb; } -Vector<Face3> ImmediateGeometry::get_faces(uint32_t p_usage_flags) const { +Vector<Face3> ImmediateGeometry3D::get_faces(uint32_t p_usage_flags) const { return Vector<Face3>(); } -void ImmediateGeometry::add_sphere(int p_lats, int p_lons, float p_radius, bool p_add_uv) { +void ImmediateGeometry3D::add_sphere(int p_lats, int p_lons, float p_radius, bool p_add_uv) { for (int i = 1; i <= p_lats; i++) { double lat0 = Math_PI * (-0.5 + (double)(i - 1) / p_lats); @@ -142,28 +142,28 @@ void ImmediateGeometry::add_sphere(int p_lats, int p_lons, float p_radius, bool } } -void ImmediateGeometry::_bind_methods() { - - ClassDB::bind_method(D_METHOD("begin", "primitive", "texture"), &ImmediateGeometry::begin, DEFVAL(Ref<Texture2D>())); - ClassDB::bind_method(D_METHOD("set_normal", "normal"), &ImmediateGeometry::set_normal); - ClassDB::bind_method(D_METHOD("set_tangent", "tangent"), &ImmediateGeometry::set_tangent); - ClassDB::bind_method(D_METHOD("set_color", "color"), &ImmediateGeometry::set_color); - ClassDB::bind_method(D_METHOD("set_uv", "uv"), &ImmediateGeometry::set_uv); - ClassDB::bind_method(D_METHOD("set_uv2", "uv"), &ImmediateGeometry::set_uv2); - ClassDB::bind_method(D_METHOD("add_vertex", "position"), &ImmediateGeometry::add_vertex); - ClassDB::bind_method(D_METHOD("add_sphere", "lats", "lons", "radius", "add_uv"), &ImmediateGeometry::add_sphere, DEFVAL(true)); - ClassDB::bind_method(D_METHOD("end"), &ImmediateGeometry::end); - ClassDB::bind_method(D_METHOD("clear"), &ImmediateGeometry::clear); +void ImmediateGeometry3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("begin", "primitive", "texture"), &ImmediateGeometry3D::begin, DEFVAL(Ref<Texture2D>())); + ClassDB::bind_method(D_METHOD("set_normal", "normal"), &ImmediateGeometry3D::set_normal); + ClassDB::bind_method(D_METHOD("set_tangent", "tangent"), &ImmediateGeometry3D::set_tangent); + ClassDB::bind_method(D_METHOD("set_color", "color"), &ImmediateGeometry3D::set_color); + ClassDB::bind_method(D_METHOD("set_uv", "uv"), &ImmediateGeometry3D::set_uv); + ClassDB::bind_method(D_METHOD("set_uv2", "uv"), &ImmediateGeometry3D::set_uv2); + ClassDB::bind_method(D_METHOD("add_vertex", "position"), &ImmediateGeometry3D::add_vertex); + ClassDB::bind_method(D_METHOD("add_sphere", "lats", "lons", "radius", "add_uv"), &ImmediateGeometry3D::add_sphere, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("end"), &ImmediateGeometry3D::end); + ClassDB::bind_method(D_METHOD("clear"), &ImmediateGeometry3D::clear); } -ImmediateGeometry::ImmediateGeometry() { +ImmediateGeometry3D::ImmediateGeometry3D() { - im = VisualServer::get_singleton()->immediate_create(); + im = RenderingServer::get_singleton()->immediate_create(); set_base(im); empty = true; } -ImmediateGeometry::~ImmediateGeometry() { +ImmediateGeometry3D::~ImmediateGeometry3D() { - VisualServer::get_singleton()->free(im); + RenderingServer::get_singleton()->free(im); } diff --git a/scene/3d/immediate_geometry.h b/scene/3d/immediate_geometry_3d.h index f9222c75fa..6e15450a5b 100644 --- a/scene/3d/immediate_geometry.h +++ b/scene/3d/immediate_geometry_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* immediate_geometry.h */ +/* immediate_geometry_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,19 +28,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef IMMEDIATE_GEOMETRY_H -#define IMMEDIATE_GEOMETRY_H +#ifndef IMMEDIATE_GEOMETRY_3D_H +#define IMMEDIATE_GEOMETRY_3D_H -#include "scene/3d/visual_instance.h" +#include "scene/3d/visual_instance_3d.h" #include "scene/resources/mesh.h" -class ImmediateGeometry : public GeometryInstance { +class ImmediateGeometry3D : public GeometryInstance3D { - GDCLASS(ImmediateGeometry, GeometryInstance); + GDCLASS(ImmediateGeometry3D, GeometryInstance3D); RID im; //a list of textures drawn need to be kept, to avoid references - // in VisualServer from becoming invalid if the texture is no longer used + // in RenderingServer from becoming invalid if the texture is no longer used List<Ref<Texture2D>> cached_textures; bool empty; AABB aabb; @@ -66,8 +66,8 @@ public: virtual AABB get_aabb() const; virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const; - ImmediateGeometry(); - ~ImmediateGeometry(); + ImmediateGeometry3D(); + ~ImmediateGeometry3D(); }; #endif // IMMEDIATE_GEOMETRY_H diff --git a/scene/3d/interpolated_camera.cpp b/scene/3d/interpolated_camera.cpp deleted file mode 100644 index 592d592a38..0000000000 --- a/scene/3d/interpolated_camera.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/*************************************************************************/ -/* interpolated_camera.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 "interpolated_camera.h" - -#include "core/engine.h" - -void InterpolatedCamera::_notification(int p_what) { - - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - - if (Engine::get_singleton()->is_editor_hint() && enabled) - set_process_internal(false); - - } break; - case NOTIFICATION_INTERNAL_PROCESS: { - - if (!enabled) - break; - if (has_node(target)) { - - Spatial *node = Object::cast_to<Spatial>(get_node(target)); - if (!node) - break; - - float delta = speed * get_process_delta_time(); - Transform target_xform = node->get_global_transform(); - Transform local_transform = get_global_transform(); - local_transform = local_transform.interpolate_with(target_xform, delta); - set_global_transform(local_transform); - Camera *cam = Object::cast_to<Camera>(node); - if (cam) { - - if (cam->get_projection() == get_projection()) { - - float new_near = Math::lerp(get_znear(), cam->get_znear(), delta); - float new_far = Math::lerp(get_zfar(), cam->get_zfar(), delta); - - if (cam->get_projection() == PROJECTION_ORTHOGONAL) { - - float size = Math::lerp(get_size(), cam->get_size(), delta); - set_orthogonal(size, new_near, new_far); - } else { - - float fov = Math::lerp(get_fov(), cam->get_fov(), delta); - set_perspective(fov, new_near, new_far); - } - } - } - } - - } break; - } -} - -void InterpolatedCamera::_set_target(const Object *p_target) { - - ERR_FAIL_NULL(p_target); - set_target(Object::cast_to<Spatial>(p_target)); -} - -void InterpolatedCamera::set_target(const Spatial *p_target) { - - ERR_FAIL_NULL(p_target); - target = get_path_to(p_target); -} - -void InterpolatedCamera::set_target_path(const NodePath &p_path) { - - target = p_path; -} - -NodePath InterpolatedCamera::get_target_path() const { - - return target; -} - -void InterpolatedCamera::set_interpolation_enabled(bool p_enable) { - - if (enabled == p_enable) - return; - enabled = p_enable; - if (p_enable) { - if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) - return; - set_process_internal(true); - } else - set_process_internal(false); -} - -bool InterpolatedCamera::is_interpolation_enabled() const { - - return enabled; -} - -void InterpolatedCamera::set_speed(real_t p_speed) { - - speed = p_speed; -} - -real_t InterpolatedCamera::get_speed() const { - - return speed; -} - -void InterpolatedCamera::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_target_path", "target_path"), &InterpolatedCamera::set_target_path); - ClassDB::bind_method(D_METHOD("get_target_path"), &InterpolatedCamera::get_target_path); - ClassDB::bind_method(D_METHOD("set_target", "target"), &InterpolatedCamera::_set_target); - - ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InterpolatedCamera::set_speed); - ClassDB::bind_method(D_METHOD("get_speed"), &InterpolatedCamera::get_speed); - - ClassDB::bind_method(D_METHOD("set_interpolation_enabled", "target_path"), &InterpolatedCamera::set_interpolation_enabled); - ClassDB::bind_method(D_METHOD("is_interpolation_enabled"), &InterpolatedCamera::is_interpolation_enabled); - - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "target"), "set_target_path", "get_target_path"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed"), "set_speed", "get_speed"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_interpolation_enabled", "is_interpolation_enabled"); -} - -InterpolatedCamera::InterpolatedCamera() { - - enabled = false; - speed = 1; -} diff --git a/scene/3d/interpolated_camera.h b/scene/3d/interpolated_camera.h deleted file mode 100644 index 7b160c66fa..0000000000 --- a/scene/3d/interpolated_camera.h +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************/ -/* interpolated_camera.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 INTERPOLATED_CAMERA_H -#define INTERPOLATED_CAMERA_H - -#include "scene/3d/camera.h" - -class InterpolatedCamera : public Camera { - - GDCLASS(InterpolatedCamera, Camera); - - bool enabled; - real_t speed; - NodePath target; - -protected: - void _notification(int p_what); - static void _bind_methods(); - void _set_target(const Object *p_target); - -public: - void set_target(const Spatial *p_target); - void set_target_path(const NodePath &p_path); - NodePath get_target_path() const; - - void set_speed(real_t p_speed); - real_t get_speed() const; - - void set_interpolation_enabled(bool p_enable); - bool is_interpolation_enabled() const; - - InterpolatedCamera(); -}; - -#endif // INTERPOLATED_CAMERA_H diff --git a/scene/3d/light.cpp b/scene/3d/light_3d.cpp index 7c922ce1cd..c048f60ebd 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* light.cpp */ +/* light_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,23 +28,23 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "light.h" +#include "light_3d.h" #include "core/engine.h" #include "core/project_settings.h" #include "scene/resources/surface_tool.h" -bool Light::_can_gizmo_scale() const { +bool Light3D::_can_gizmo_scale() const { return false; } -void Light::set_param(Param p_param, float p_value) { +void Light3D::set_param(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); param[p_param] = p_value; - VS::get_singleton()->light_set_param(light, VS::LightParam(p_param), p_value); + RS::get_singleton()->light_set_param(light, RS::LightParam(p_param), p_value); if (p_param == PARAM_SPOT_ANGLE || p_param == PARAM_RANGE) { update_gizmo(); @@ -59,90 +59,90 @@ void Light::set_param(Param p_param, float p_value) { } } -float Light::get_param(Param p_param) const { +float Light3D::get_param(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return param[p_param]; } -void Light::set_shadow(bool p_enable) { +void Light3D::set_shadow(bool p_enable) { shadow = p_enable; - VS::get_singleton()->light_set_shadow(light, p_enable); + RS::get_singleton()->light_set_shadow(light, p_enable); - if (type == VisualServer::LIGHT_SPOT) { + if (type == RenderingServer::LIGHT_SPOT || type == RenderingServer::LIGHT_OMNI) { update_configuration_warning(); } } -bool Light::has_shadow() const { +bool Light3D::has_shadow() const { return shadow; } -void Light::set_negative(bool p_enable) { +void Light3D::set_negative(bool p_enable) { negative = p_enable; - VS::get_singleton()->light_set_negative(light, p_enable); + RS::get_singleton()->light_set_negative(light, p_enable); } -bool Light::is_negative() const { +bool Light3D::is_negative() const { return negative; } -void Light::set_cull_mask(uint32_t p_cull_mask) { +void Light3D::set_cull_mask(uint32_t p_cull_mask) { cull_mask = p_cull_mask; - VS::get_singleton()->light_set_cull_mask(light, p_cull_mask); + RS::get_singleton()->light_set_cull_mask(light, p_cull_mask); } -uint32_t Light::get_cull_mask() const { +uint32_t Light3D::get_cull_mask() const { return cull_mask; } -void Light::set_color(const Color &p_color) { +void Light3D::set_color(const Color &p_color) { color = p_color; - VS::get_singleton()->light_set_color(light, p_color); + RS::get_singleton()->light_set_color(light, p_color); // The gizmo color depends on the light color, so update it. update_gizmo(); } -Color Light::get_color() const { +Color Light3D::get_color() const { return color; } -void Light::set_shadow_color(const Color &p_shadow_color) { +void Light3D::set_shadow_color(const Color &p_shadow_color) { shadow_color = p_shadow_color; - VS::get_singleton()->light_set_shadow_color(light, p_shadow_color); + RS::get_singleton()->light_set_shadow_color(light, p_shadow_color); } -Color Light::get_shadow_color() const { +Color Light3D::get_shadow_color() const { return shadow_color; } -void Light::set_shadow_reverse_cull_face(bool p_enable) { +void Light3D::set_shadow_reverse_cull_face(bool p_enable) { reverse_cull = p_enable; - VS::get_singleton()->light_set_reverse_cull_face_mode(light, reverse_cull); + RS::get_singleton()->light_set_reverse_cull_face_mode(light, reverse_cull); } -bool Light::get_shadow_reverse_cull_face() const { +bool Light3D::get_shadow_reverse_cull_face() const { return reverse_cull; } -AABB Light::get_aabb() const { +AABB Light3D::get_aabb() const { - if (type == VisualServer::LIGHT_DIRECTIONAL) { + if (type == RenderingServer::LIGHT_DIRECTIONAL) { return AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2)); - } else if (type == VisualServer::LIGHT_OMNI) { + } else if (type == RenderingServer::LIGHT_OMNI) { return AABB(Vector3(-1, -1, -1) * param[PARAM_RANGE], Vector3(2, 2, 2) * param[PARAM_RANGE]); - } else if (type == VisualServer::LIGHT_SPOT) { + } else if (type == RenderingServer::LIGHT_SPOT) { float len = param[PARAM_RANGE]; float size = Math::tan(Math::deg2rad(param[PARAM_SPOT_ANGLE])) * len; @@ -152,21 +152,33 @@ AABB Light::get_aabb() const { return AABB(); } -Vector<Face3> Light::get_faces(uint32_t p_usage_flags) const { +Vector<Face3> Light3D::get_faces(uint32_t p_usage_flags) const { return Vector<Face3>(); } -void Light::set_bake_mode(BakeMode p_mode) { +void Light3D::set_bake_mode(BakeMode p_mode) { bake_mode = p_mode; - VS::get_singleton()->light_set_use_gi(light, p_mode != BAKE_DISABLED); + RS::get_singleton()->light_set_use_gi(light, p_mode != BAKE_DISABLED); } -Light::BakeMode Light::get_bake_mode() const { +Light3D::BakeMode Light3D::get_bake_mode() const { return bake_mode; } -void Light::_update_visibility() { +void Light3D::set_projector(const Ref<Texture2D> &p_texture) { + + projector = p_texture; + RID tex_id = projector.is_valid() ? projector->get_rid() : RID(); + RS::get_singleton()->light_set_projector(light, tex_id); + update_configuration_warning(); +} + +Ref<Texture2D> Light3D::get_projector() const { + return projector; +} + +void Light3D::_update_visibility() { if (!is_inside_tree()) return; @@ -187,12 +199,12 @@ void Light::_update_visibility() { } #endif - VS::get_singleton()->instance_set_visible(get_instance(), is_visible_in_tree() && editor_ok); + RS::get_singleton()->instance_set_visible(get_instance(), is_visible_in_tree() && editor_ok); _change_notify("geometry/visible"); } -void Light::_notification(int p_what) { +void Light3D::_notification(int p_what) { if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { @@ -204,57 +216,71 @@ void Light::_notification(int p_what) { } } -void Light::set_editor_only(bool p_editor_only) { +void Light3D::set_editor_only(bool p_editor_only) { editor_only = p_editor_only; _update_visibility(); } -bool Light::is_editor_only() const { +bool Light3D::is_editor_only() const { return editor_only; } -void Light::_validate_property(PropertyInfo &property) const { +void Light3D::_validate_property(PropertyInfo &property) const { + + if (get_light_type() == RS::LIGHT_DIRECTIONAL && property.name == "light_size") { + property.usage = 0; + } + + if (get_light_type() == RS::LIGHT_DIRECTIONAL && property.name == "light_projector") { + property.usage = 0; + } - if (VisualServer::get_singleton()->is_low_end() && property.name == "shadow_contact") { - property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; + if (get_light_type() != RS::LIGHT_DIRECTIONAL && property.name == "light_angular_distance") { + property.usage = 0; } } -void Light::_bind_methods() { +void Light3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light::set_editor_only); - ClassDB::bind_method(D_METHOD("is_editor_only"), &Light::is_editor_only); + ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light3D::set_editor_only); + ClassDB::bind_method(D_METHOD("is_editor_only"), &Light3D::is_editor_only); - ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &Light::set_param); - ClassDB::bind_method(D_METHOD("get_param", "param"), &Light::get_param); + ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &Light3D::set_param); + ClassDB::bind_method(D_METHOD("get_param", "param"), &Light3D::get_param); - ClassDB::bind_method(D_METHOD("set_shadow", "enabled"), &Light::set_shadow); - ClassDB::bind_method(D_METHOD("has_shadow"), &Light::has_shadow); + ClassDB::bind_method(D_METHOD("set_shadow", "enabled"), &Light3D::set_shadow); + ClassDB::bind_method(D_METHOD("has_shadow"), &Light3D::has_shadow); - ClassDB::bind_method(D_METHOD("set_negative", "enabled"), &Light::set_negative); - ClassDB::bind_method(D_METHOD("is_negative"), &Light::is_negative); + ClassDB::bind_method(D_METHOD("set_negative", "enabled"), &Light3D::set_negative); + ClassDB::bind_method(D_METHOD("is_negative"), &Light3D::is_negative); - ClassDB::bind_method(D_METHOD("set_cull_mask", "cull_mask"), &Light::set_cull_mask); - ClassDB::bind_method(D_METHOD("get_cull_mask"), &Light::get_cull_mask); + ClassDB::bind_method(D_METHOD("set_cull_mask", "cull_mask"), &Light3D::set_cull_mask); + ClassDB::bind_method(D_METHOD("get_cull_mask"), &Light3D::get_cull_mask); - ClassDB::bind_method(D_METHOD("set_color", "color"), &Light::set_color); - ClassDB::bind_method(D_METHOD("get_color"), &Light::get_color); + ClassDB::bind_method(D_METHOD("set_color", "color"), &Light3D::set_color); + ClassDB::bind_method(D_METHOD("get_color"), &Light3D::get_color); - ClassDB::bind_method(D_METHOD("set_shadow_reverse_cull_face", "enable"), &Light::set_shadow_reverse_cull_face); - ClassDB::bind_method(D_METHOD("get_shadow_reverse_cull_face"), &Light::get_shadow_reverse_cull_face); + ClassDB::bind_method(D_METHOD("set_shadow_reverse_cull_face", "enable"), &Light3D::set_shadow_reverse_cull_face); + ClassDB::bind_method(D_METHOD("get_shadow_reverse_cull_face"), &Light3D::get_shadow_reverse_cull_face); - ClassDB::bind_method(D_METHOD("set_shadow_color", "shadow_color"), &Light::set_shadow_color); - ClassDB::bind_method(D_METHOD("get_shadow_color"), &Light::get_shadow_color); + ClassDB::bind_method(D_METHOD("set_shadow_color", "shadow_color"), &Light3D::set_shadow_color); + ClassDB::bind_method(D_METHOD("get_shadow_color"), &Light3D::get_shadow_color); - ClassDB::bind_method(D_METHOD("set_bake_mode", "bake_mode"), &Light::set_bake_mode); - ClassDB::bind_method(D_METHOD("get_bake_mode"), &Light::get_bake_mode); + ClassDB::bind_method(D_METHOD("set_bake_mode", "bake_mode"), &Light3D::set_bake_mode); + ClassDB::bind_method(D_METHOD("get_bake_mode"), &Light3D::get_bake_mode); + + ClassDB::bind_method(D_METHOD("set_projector", "projector"), &Light3D::set_projector); + ClassDB::bind_method(D_METHOD("get_projector"), &Light3D::get_projector); ADD_GROUP("Light", "light_"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_color", "get_color"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_param", "get_param", PARAM_ENERGY); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_indirect_energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_param", "get_param", PARAM_INDIRECT_ENERGY); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "light_projector", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_projector", "get_projector"); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_size", PROPERTY_HINT_RANGE, "0,64,0.01,or_greater"), "set_param", "get_param", PARAM_SIZE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_angular_distance", PROPERTY_HINT_RANGE, "0,90,0.01"), "set_param", "get_param", PARAM_SIZE); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_negative"), "set_negative", "is_negative"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_specular", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SPECULAR); ADD_PROPERTY(PropertyInfo(Variant::INT, "light_bake_mode", PROPERTY_HINT_ENUM, "Disable,Indirect,All"), "set_bake_mode", "get_bake_mode"); @@ -262,9 +288,11 @@ void Light::_bind_methods() { ADD_GROUP("Shadow", "shadow_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_enabled"), "set_shadow", "has_shadow"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "shadow_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_shadow_color", "get_shadow_color"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_bias", PROPERTY_HINT_RANGE, "-16,16,0.01"), "set_param", "get_param", PARAM_SHADOW_BIAS); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_contact", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_param", "get_param", PARAM_CONTACT_SHADOW_SIZE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_bias", PROPERTY_HINT_RANGE, "0,10,0.001"), "set_param", "get_param", PARAM_SHADOW_BIAS); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_normal_bias", PROPERTY_HINT_RANGE, "0,10,0.001"), "set_param", "get_param", PARAM_SHADOW_NORMAL_BIAS); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_reverse_cull_face"), "set_shadow_reverse_cull_face", "get_shadow_reverse_cull_face"); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_transmittance_bias", PROPERTY_HINT_RANGE, "-16,16,0.01"), "set_param", "get_param", PARAM_TRANSMITTANCE_BIAS); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_blur", PROPERTY_HINT_RANGE, "0.1,8,0.01"), "set_param", "get_param", PARAM_SHADOW_BLUR); ADD_GROUP("Editor", ""); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "is_editor_only"); ADD_GROUP("", ""); @@ -273,10 +301,10 @@ void Light::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_INDIRECT_ENERGY); BIND_ENUM_CONSTANT(PARAM_SPECULAR); BIND_ENUM_CONSTANT(PARAM_RANGE); + BIND_ENUM_CONSTANT(PARAM_SIZE); BIND_ENUM_CONSTANT(PARAM_ATTENUATION); BIND_ENUM_CONSTANT(PARAM_SPOT_ANGLE); BIND_ENUM_CONSTANT(PARAM_SPOT_ATTENUATION); - BIND_ENUM_CONSTANT(PARAM_CONTACT_SHADOW_SIZE); BIND_ENUM_CONSTANT(PARAM_SHADOW_MAX_DISTANCE); BIND_ENUM_CONSTANT(PARAM_SHADOW_SPLIT_1_OFFSET); BIND_ENUM_CONSTANT(PARAM_SHADOW_SPLIT_2_OFFSET); @@ -284,7 +312,9 @@ void Light::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_SHADOW_FADE_START); BIND_ENUM_CONSTANT(PARAM_SHADOW_NORMAL_BIAS); BIND_ENUM_CONSTANT(PARAM_SHADOW_BIAS); - BIND_ENUM_CONSTANT(PARAM_SHADOW_BIAS_SPLIT_SCALE); + BIND_ENUM_CONSTANT(PARAM_SHADOW_PANCAKE_SIZE); + BIND_ENUM_CONSTANT(PARAM_SHADOW_BLUR); + BIND_ENUM_CONSTANT(PARAM_TRANSMITTANCE_BIAS); BIND_ENUM_CONSTANT(PARAM_MAX); BIND_ENUM_CONSTANT(BAKE_DISABLED); @@ -292,18 +322,18 @@ void Light::_bind_methods() { BIND_ENUM_CONSTANT(BAKE_ALL); } -Light::Light(VisualServer::LightType p_type) { +Light3D::Light3D(RenderingServer::LightType p_type) { type = p_type; switch (p_type) { - case VS::LIGHT_DIRECTIONAL: light = VisualServer::get_singleton()->directional_light_create(); break; - case VS::LIGHT_OMNI: light = VisualServer::get_singleton()->omni_light_create(); break; - case VS::LIGHT_SPOT: light = VisualServer::get_singleton()->spot_light_create(); break; + case RS::LIGHT_DIRECTIONAL: light = RenderingServer::get_singleton()->directional_light_create(); break; + case RS::LIGHT_OMNI: light = RenderingServer::get_singleton()->omni_light_create(); break; + case RS::LIGHT_SPOT: light = RenderingServer::get_singleton()->spot_light_create(); break; default: { }; } - VS::get_singleton()->instance_set_base(get_instance(), light); + RS::get_singleton()->instance_set_base(get_instance(), light); reverse_cull = false; bake_mode = BAKE_INDIRECT; @@ -318,78 +348,81 @@ Light::Light(VisualServer::LightType p_type) { set_param(PARAM_INDIRECT_ENERGY, 1); set_param(PARAM_SPECULAR, 0.5); set_param(PARAM_RANGE, 5); + set_param(PARAM_SIZE, 0); set_param(PARAM_ATTENUATION, 1); set_param(PARAM_SPOT_ANGLE, 45); set_param(PARAM_SPOT_ATTENUATION, 1); - set_param(PARAM_CONTACT_SHADOW_SIZE, 0); set_param(PARAM_SHADOW_MAX_DISTANCE, 0); set_param(PARAM_SHADOW_SPLIT_1_OFFSET, 0.1); set_param(PARAM_SHADOW_SPLIT_2_OFFSET, 0.2); set_param(PARAM_SHADOW_SPLIT_3_OFFSET, 0.5); set_param(PARAM_SHADOW_FADE_START, 0.8); - set_param(PARAM_SHADOW_NORMAL_BIAS, 0.0); - set_param(PARAM_SHADOW_BIAS, 0.15); + set_param(PARAM_SHADOW_PANCAKE_SIZE, 20.0); + set_param(PARAM_SHADOW_BLUR, 1.0); + set_param(PARAM_SHADOW_BIAS, 0.02); + set_param(PARAM_SHADOW_NORMAL_BIAS, 1.0); + set_param(PARAM_TRANSMITTANCE_BIAS, 0.05); set_param(PARAM_SHADOW_FADE_START, 1); set_disable_scale(true); } -Light::Light() { +Light3D::Light3D() { - type = VisualServer::LIGHT_DIRECTIONAL; - ERR_PRINT("Light should not be instanced directly; use the DirectionalLight, OmniLight or SpotLight subtypes instead."); + type = RenderingServer::LIGHT_DIRECTIONAL; + ERR_PRINT("Light3D should not be instanced directly; use the DirectionalLight3D, OmniLight3D or SpotLight3D subtypes instead."); } -Light::~Light() { +Light3D::~Light3D() { - VS::get_singleton()->instance_set_base(get_instance(), RID()); + RS::get_singleton()->instance_set_base(get_instance(), RID()); if (light.is_valid()) - VisualServer::get_singleton()->free(light); + RenderingServer::get_singleton()->free(light); } ///////////////////////////////////////// -void DirectionalLight::set_shadow_mode(ShadowMode p_mode) { +void DirectionalLight3D::set_shadow_mode(ShadowMode p_mode) { shadow_mode = p_mode; - VS::get_singleton()->light_directional_set_shadow_mode(light, VS::LightDirectionalShadowMode(p_mode)); + RS::get_singleton()->light_directional_set_shadow_mode(light, RS::LightDirectionalShadowMode(p_mode)); } -DirectionalLight::ShadowMode DirectionalLight::get_shadow_mode() const { +DirectionalLight3D::ShadowMode DirectionalLight3D::get_shadow_mode() const { return shadow_mode; } -void DirectionalLight::set_shadow_depth_range(ShadowDepthRange p_range) { +void DirectionalLight3D::set_shadow_depth_range(ShadowDepthRange p_range) { shadow_depth_range = p_range; - VS::get_singleton()->light_directional_set_shadow_depth_range_mode(light, VS::LightDirectionalShadowDepthRangeMode(p_range)); + RS::get_singleton()->light_directional_set_shadow_depth_range_mode(light, RS::LightDirectionalShadowDepthRangeMode(p_range)); } -DirectionalLight::ShadowDepthRange DirectionalLight::get_shadow_depth_range() const { +DirectionalLight3D::ShadowDepthRange DirectionalLight3D::get_shadow_depth_range() const { return shadow_depth_range; } -void DirectionalLight::set_blend_splits(bool p_enable) { +void DirectionalLight3D::set_blend_splits(bool p_enable) { blend_splits = p_enable; - VS::get_singleton()->light_directional_set_blend_splits(light, p_enable); + RS::get_singleton()->light_directional_set_blend_splits(light, p_enable); } -bool DirectionalLight::is_blend_splits_enabled() const { +bool DirectionalLight3D::is_blend_splits_enabled() const { return blend_splits; } -void DirectionalLight::_bind_methods() { +void DirectionalLight3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &DirectionalLight::set_shadow_mode); - ClassDB::bind_method(D_METHOD("get_shadow_mode"), &DirectionalLight::get_shadow_mode); + ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &DirectionalLight3D::set_shadow_mode); + ClassDB::bind_method(D_METHOD("get_shadow_mode"), &DirectionalLight3D::get_shadow_mode); - ClassDB::bind_method(D_METHOD("set_shadow_depth_range", "mode"), &DirectionalLight::set_shadow_depth_range); - ClassDB::bind_method(D_METHOD("get_shadow_depth_range"), &DirectionalLight::get_shadow_depth_range); + ClassDB::bind_method(D_METHOD("set_shadow_depth_range", "mode"), &DirectionalLight3D::set_shadow_depth_range); + ClassDB::bind_method(D_METHOD("get_shadow_depth_range"), &DirectionalLight3D::get_shadow_depth_range); - ClassDB::bind_method(D_METHOD("set_blend_splits", "enabled"), &DirectionalLight::set_blend_splits); - ClassDB::bind_method(D_METHOD("is_blend_splits_enabled"), &DirectionalLight::is_blend_splits_enabled); + ClassDB::bind_method(D_METHOD("set_blend_splits", "enabled"), &DirectionalLight3D::set_blend_splits); + ClassDB::bind_method(D_METHOD("is_blend_splits_enabled"), &DirectionalLight3D::is_blend_splits_enabled); ADD_GROUP("Directional Shadow", "directional_shadow_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "directional_shadow_mode", PROPERTY_HINT_ENUM, "Orthogonal,PSSM 2 Splits,PSSM 4 Splits"), "set_shadow_mode", "get_shadow_mode"); @@ -398,10 +431,9 @@ void DirectionalLight::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_split_3", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_3_OFFSET); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_fade_start", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SHADOW_FADE_START); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "directional_shadow_blend_splits"), "set_blend_splits", "is_blend_splits_enabled"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_normal_bias", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_param", "get_param", PARAM_SHADOW_NORMAL_BIAS); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_bias_split_scale", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SHADOW_BIAS_SPLIT_SCALE); ADD_PROPERTY(PropertyInfo(Variant::INT, "directional_shadow_depth_range", PROPERTY_HINT_ENUM, "Stable,Optimized"), "set_shadow_depth_range", "get_shadow_depth_range"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_max_distance", PROPERTY_HINT_EXP_RANGE, "0,8192,0.1,or_greater"), "set_param", "get_param", PARAM_SHADOW_MAX_DISTANCE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_pancake_size", PROPERTY_HINT_EXP_RANGE, "0,1024,0.1,or_greater"), "set_param", "get_param", PARAM_SHADOW_PANCAKE_SIZE); BIND_ENUM_CONSTANT(SHADOW_ORTHOGONAL); BIND_ENUM_CONSTANT(SHADOW_PARALLEL_2_SPLITS); @@ -411,35 +443,45 @@ void DirectionalLight::_bind_methods() { BIND_ENUM_CONSTANT(SHADOW_DEPTH_RANGE_OPTIMIZED); } -DirectionalLight::DirectionalLight() : - Light(VisualServer::LIGHT_DIRECTIONAL) { +DirectionalLight3D::DirectionalLight3D() : + Light3D(RenderingServer::LIGHT_DIRECTIONAL) { - set_param(PARAM_SHADOW_NORMAL_BIAS, 0.8); - set_param(PARAM_SHADOW_BIAS, 0.1); set_param(PARAM_SHADOW_MAX_DISTANCE, 100); set_param(PARAM_SHADOW_FADE_START, 0.8); - set_param(PARAM_SHADOW_BIAS_SPLIT_SCALE, 0.25); set_shadow_mode(SHADOW_PARALLEL_4_SPLITS); set_shadow_depth_range(SHADOW_DEPTH_RANGE_STABLE); blend_splits = false; } -void OmniLight::set_shadow_mode(ShadowMode p_mode) { +void OmniLight3D::set_shadow_mode(ShadowMode p_mode) { shadow_mode = p_mode; - VS::get_singleton()->light_omni_set_shadow_mode(light, VS::LightOmniShadowMode(p_mode)); + RS::get_singleton()->light_omni_set_shadow_mode(light, RS::LightOmniShadowMode(p_mode)); } -OmniLight::ShadowMode OmniLight::get_shadow_mode() const { +OmniLight3D::ShadowMode OmniLight3D::get_shadow_mode() const { return shadow_mode; } -void OmniLight::_bind_methods() { +String OmniLight3D::get_configuration_warning() const { + String warning = Light3D::get_configuration_warning(); + + if (!has_shadow() && get_projector().is_valid()) { + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("Projector texture only works with shadows active."); + } + + return warning; +} + +void OmniLight3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &OmniLight::set_shadow_mode); - ClassDB::bind_method(D_METHOD("get_shadow_mode"), &OmniLight::get_shadow_mode); + ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &OmniLight3D::set_shadow_mode); + ClassDB::bind_method(D_METHOD("get_shadow_mode"), &OmniLight3D::get_shadow_mode); ADD_GROUP("Omni", "omni_"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "omni_range", PROPERTY_HINT_EXP_RANGE, "0,4096,0.1,or_greater"), "set_param", "get_param", PARAM_RANGE); @@ -450,27 +492,34 @@ void OmniLight::_bind_methods() { BIND_ENUM_CONSTANT(SHADOW_CUBE); } -OmniLight::OmniLight() : - Light(VisualServer::LIGHT_OMNI) { +OmniLight3D::OmniLight3D() : + Light3D(RenderingServer::LIGHT_OMNI) { set_shadow_mode(SHADOW_CUBE); } -String SpotLight::get_configuration_warning() const { - String warning = Light::get_configuration_warning(); +String SpotLight3D::get_configuration_warning() const { + String warning = Light3D::get_configuration_warning(); if (has_shadow() && get_param(PARAM_SPOT_ANGLE) >= 90.0) { if (warning != String()) { warning += "\n\n"; } - warning += TTR("A SpotLight with an angle wider than 90 degrees cannot cast shadows."); + warning += TTR("A SpotLight3D with an angle wider than 90 degrees cannot cast shadows."); + } + + if (!has_shadow() && get_projector().is_valid()) { + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("Projector texture only works with shadows active."); } return warning; } -void SpotLight::_bind_methods() { +void SpotLight3D::_bind_methods() { ADD_GROUP("Spot", "spot_"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "spot_range", PROPERTY_HINT_EXP_RANGE, "0,4096,0.1,or_greater"), "set_param", "get_param", PARAM_RANGE); diff --git a/scene/3d/light.h b/scene/3d/light_3d.h index 16e0c47083..6e78217342 100644 --- a/scene/3d/light.h +++ b/scene/3d/light_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* light.h */ +/* light_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,34 +31,36 @@ #ifndef LIGHT_H #define LIGHT_H -#include "scene/3d/visual_instance.h" +#include "scene/3d/visual_instance_3d.h" #include "scene/resources/texture.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" -class Light : public VisualInstance { +class Light3D : public VisualInstance3D { - GDCLASS(Light, VisualInstance); + GDCLASS(Light3D, VisualInstance3D); OBJ_CATEGORY("3D Light Nodes"); public: enum Param { - PARAM_ENERGY = VS::LIGHT_PARAM_ENERGY, - PARAM_INDIRECT_ENERGY = VS::LIGHT_PARAM_INDIRECT_ENERGY, - PARAM_SPECULAR = VS::LIGHT_PARAM_SPECULAR, - PARAM_RANGE = VS::LIGHT_PARAM_RANGE, - PARAM_ATTENUATION = VS::LIGHT_PARAM_ATTENUATION, - PARAM_SPOT_ANGLE = VS::LIGHT_PARAM_SPOT_ANGLE, - PARAM_SPOT_ATTENUATION = VS::LIGHT_PARAM_SPOT_ATTENUATION, - PARAM_CONTACT_SHADOW_SIZE = VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE, - PARAM_SHADOW_MAX_DISTANCE = VS::LIGHT_PARAM_SHADOW_MAX_DISTANCE, - PARAM_SHADOW_SPLIT_1_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET, - PARAM_SHADOW_SPLIT_2_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET, - PARAM_SHADOW_SPLIT_3_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET, - PARAM_SHADOW_FADE_START = VS::LIGHT_PARAM_SHADOW_FADE_START, - PARAM_SHADOW_NORMAL_BIAS = VS::LIGHT_PARAM_SHADOW_NORMAL_BIAS, - PARAM_SHADOW_BIAS = VS::LIGHT_PARAM_SHADOW_BIAS, - PARAM_SHADOW_BIAS_SPLIT_SCALE = VS::LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE, - PARAM_MAX = VS::LIGHT_PARAM_MAX + PARAM_ENERGY = RS::LIGHT_PARAM_ENERGY, + PARAM_INDIRECT_ENERGY = RS::LIGHT_PARAM_INDIRECT_ENERGY, + PARAM_SPECULAR = RS::LIGHT_PARAM_SPECULAR, + PARAM_RANGE = RS::LIGHT_PARAM_RANGE, + PARAM_SIZE = RS::LIGHT_PARAM_SIZE, + PARAM_ATTENUATION = RS::LIGHT_PARAM_ATTENUATION, + PARAM_SPOT_ANGLE = RS::LIGHT_PARAM_SPOT_ANGLE, + PARAM_SPOT_ATTENUATION = RS::LIGHT_PARAM_SPOT_ATTENUATION, + PARAM_SHADOW_MAX_DISTANCE = RS::LIGHT_PARAM_SHADOW_MAX_DISTANCE, + PARAM_SHADOW_SPLIT_1_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET, + PARAM_SHADOW_SPLIT_2_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET, + PARAM_SHADOW_SPLIT_3_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET, + PARAM_SHADOW_FADE_START = RS::LIGHT_PARAM_SHADOW_FADE_START, + PARAM_SHADOW_NORMAL_BIAS = RS::LIGHT_PARAM_SHADOW_NORMAL_BIAS, + PARAM_SHADOW_BIAS = RS::LIGHT_PARAM_SHADOW_BIAS, + PARAM_SHADOW_PANCAKE_SIZE = RS::LIGHT_PARAM_SHADOW_PANCAKE_SIZE, + PARAM_SHADOW_BLUR = RS::LIGHT_PARAM_SHADOW_BLUR, + PARAM_TRANSMITTANCE_BIAS = RS::LIGHT_PARAM_TRANSMITTANCE_BIAS, + PARAM_MAX = RS::LIGHT_PARAM_MAX }; enum BakeMode { @@ -75,10 +77,11 @@ private: bool negative; bool reverse_cull; uint32_t cull_mask; - VS::LightType type; + RS::LightType type; bool editor_only; void _update_visibility(); BakeMode bake_mode; + Ref<Texture2D> projector; // bind helpers @@ -91,10 +94,10 @@ protected: void _notification(int p_what); virtual void _validate_property(PropertyInfo &property) const; - Light(VisualServer::LightType p_type); + Light3D(RenderingServer::LightType p_type); public: - VS::LightType get_light_type() const { return type; } + RS::LightType get_light_type() const { return type; } void set_editor_only(bool p_editor_only); bool is_editor_only() const; @@ -123,19 +126,22 @@ public: void set_bake_mode(BakeMode p_mode); BakeMode get_bake_mode() const; + void set_projector(const Ref<Texture2D> &p_texture); + Ref<Texture2D> get_projector() const; + virtual AABB get_aabb() const; virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const; - Light(); - ~Light(); + Light3D(); + ~Light3D(); }; -VARIANT_ENUM_CAST(Light::Param); -VARIANT_ENUM_CAST(Light::BakeMode); +VARIANT_ENUM_CAST(Light3D::Param); +VARIANT_ENUM_CAST(Light3D::BakeMode); -class DirectionalLight : public Light { +class DirectionalLight3D : public Light3D { - GDCLASS(DirectionalLight, Light); + GDCLASS(DirectionalLight3D, Light3D); public: enum ShadowMode { @@ -145,8 +151,8 @@ public: }; enum ShadowDepthRange { - SHADOW_DEPTH_RANGE_STABLE = VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE, - SHADOW_DEPTH_RANGE_OPTIMIZED = VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED, + SHADOW_DEPTH_RANGE_STABLE = RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE, + SHADOW_DEPTH_RANGE_OPTIMIZED = RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED, }; private: @@ -167,15 +173,15 @@ public: void set_blend_splits(bool p_enable); bool is_blend_splits_enabled() const; - DirectionalLight(); + DirectionalLight3D(); }; -VARIANT_ENUM_CAST(DirectionalLight::ShadowMode) -VARIANT_ENUM_CAST(DirectionalLight::ShadowDepthRange) +VARIANT_ENUM_CAST(DirectionalLight3D::ShadowMode) +VARIANT_ENUM_CAST(DirectionalLight3D::ShadowDepthRange) -class OmniLight : public Light { +class OmniLight3D : public Light3D { - GDCLASS(OmniLight, Light); + GDCLASS(OmniLight3D, Light3D); public: // omni light @@ -194,14 +200,16 @@ public: void set_shadow_mode(ShadowMode p_mode); ShadowMode get_shadow_mode() const; - OmniLight(); + virtual String get_configuration_warning() const; + + OmniLight3D(); }; -VARIANT_ENUM_CAST(OmniLight::ShadowMode) +VARIANT_ENUM_CAST(OmniLight3D::ShadowMode) -class SpotLight : public Light { +class SpotLight3D : public Light3D { - GDCLASS(SpotLight, Light); + GDCLASS(SpotLight3D, Light3D); protected: static void _bind_methods(); @@ -209,8 +217,8 @@ protected: public: virtual String get_configuration_warning() const; - SpotLight() : - Light(VisualServer::LIGHT_SPOT) {} + SpotLight3D() : + Light3D(RenderingServer::LIGHT_SPOT) {} }; #endif diff --git a/scene/3d/listener.cpp b/scene/3d/listener_3d.cpp index 2779d14b57..426e34ea80 100644 --- a/scene/3d/listener.cpp +++ b/scene/3d/listener_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* listener.cpp */ +/* listener_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,19 +28,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "listener.h" +#include "listener_3d.h" #include "scene/resources/mesh.h" -void Listener::_update_audio_listener_state() { +void Listener3D::_update_audio_listener_state() { } -void Listener::_request_listener_update() { +void Listener3D::_request_listener_update() { _update_listener(); } -bool Listener::_set(const StringName &p_name, const Variant &p_value) { +bool Listener3D::_set(const StringName &p_name, const Variant &p_value) { if (p_name == "current") { if (p_value.operator bool()) { @@ -53,7 +53,7 @@ bool Listener::_set(const StringName &p_name, const Variant &p_value) { return true; } -bool Listener::_get(const StringName &p_name, Variant &r_ret) const { +bool Listener3D::_get(const StringName &p_name, Variant &r_ret) const { if (p_name == "current") { if (is_inside_tree() && get_tree()->is_node_being_edited(this)) { @@ -67,19 +67,19 @@ bool Listener::_get(const StringName &p_name, Variant &r_ret) const { return true; } -void Listener::_get_property_list(List<PropertyInfo> *p_list) const { +void Listener3D::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::BOOL, "current")); } -void Listener::_update_listener() { +void Listener3D::_update_listener() { if (is_inside_tree() && is_current()) { get_viewport()->_listener_transform_changed_notify(); } } -void Listener::_notification(int p_what) { +void Listener3D::_notification(int p_what) { switch (p_what) { @@ -109,12 +109,12 @@ void Listener::_notification(int p_what) { } } -Transform Listener::get_listener_transform() const { +Transform Listener3D::get_listener_transform() const { return get_global_transform().orthonormalized(); } -void Listener::make_current() { +void Listener3D::make_current() { current = true; @@ -124,19 +124,19 @@ void Listener::make_current() { get_viewport()->_listener_set(this); } -void Listener::clear_current() { +void Listener3D::clear_current() { current = false; if (!is_inside_tree()) return; if (get_viewport()->get_listener() == this) { - get_viewport()->_listener_set(NULL); + get_viewport()->_listener_set(nullptr); get_viewport()->_listener_make_next_current(this); } } -bool Listener::is_current() const { +bool Listener3D::is_current() const { if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { @@ -147,26 +147,26 @@ bool Listener::is_current() const { return false; } -bool Listener::_can_gizmo_scale() const { +bool Listener3D::_can_gizmo_scale() const { return false; } -RES Listener::_get_gizmo_geometry() const { +RES Listener3D::_get_gizmo_geometry() const { Ref<ArrayMesh> mesh = memnew(ArrayMesh); return mesh; } -void Listener::_bind_methods() { +void Listener3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("make_current"), &Listener::make_current); - ClassDB::bind_method(D_METHOD("clear_current"), &Listener::clear_current); - ClassDB::bind_method(D_METHOD("is_current"), &Listener::is_current); - ClassDB::bind_method(D_METHOD("get_listener_transform"), &Listener::get_listener_transform); + ClassDB::bind_method(D_METHOD("make_current"), &Listener3D::make_current); + ClassDB::bind_method(D_METHOD("clear_current"), &Listener3D::clear_current); + ClassDB::bind_method(D_METHOD("is_current"), &Listener3D::is_current); + ClassDB::bind_method(D_METHOD("get_listener_transform"), &Listener3D::get_listener_transform); } -Listener::Listener() { +Listener3D::Listener3D() { current = false; force_change = false; @@ -174,5 +174,5 @@ Listener::Listener() { //active=false; } -Listener::~Listener() { +Listener3D::~Listener3D() { } diff --git a/scene/3d/listener.h b/scene/3d/listener_3d.h index 287e67f31e..3383d6725e 100644 --- a/scene/3d/listener.h +++ b/scene/3d/listener_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* listener.h */ +/* listener_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef LISTENER_H -#define LISTENER_H +#ifndef LISTENER_3D_H +#define LISTENER_3D_H -#include "scene/3d/spatial.h" -#include "scene/main/viewport.h" +#include "scene/3d/node_3d.h" +#include "scene/main/window.h" -class Listener : public Spatial { +class Listener3D : public Node3D { - GDCLASS(Listener, Spatial); + GDCLASS(Listener3D, Node3D); private: bool force_change; @@ -71,8 +71,8 @@ public: void set_visible_layers(uint32_t p_layers); uint32_t get_visible_layers() const; - Listener(); - ~Listener(); + Listener3D(); + ~Listener3D(); }; #endif diff --git a/scene/3d/mesh_instance.cpp b/scene/3d/mesh_instance_3d.cpp index 4ca139ebbc..cdc8db8aea 100644 --- a/scene/3d/mesh_instance.cpp +++ b/scene/3d/mesh_instance_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* mesh_instance.cpp */ +/* mesh_instance_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "mesh_instance.h" +#include "mesh_instance_3d.h" -#include "collision_shape.h" +#include "collision_shape_3d.h" #include "core/core_string_names.h" -#include "physics_body.h" +#include "physics_body_3d.h" #include "scene/resources/material.h" -#include "skeleton.h" +#include "skeleton_3d.h" -bool MeshInstance::_set(const StringName &p_name, const Variant &p_value) { +bool MeshInstance3D::_set(const StringName &p_name, const Variant &p_value) { //this is not _too_ bad performance wise, really. it only arrives here if the property was not set anywhere else. //add to it that it's probably found on first call to _set anyway. @@ -47,7 +47,7 @@ bool MeshInstance::_set(const StringName &p_name, const Variant &p_value) { Map<StringName, BlendShapeTrack>::Element *E = blend_shape_tracks.find(p_name); if (E) { E->get().value = p_value; - VisualServer::get_singleton()->instance_set_blend_shape_weight(get_instance(), E->get().idx, E->get().value); + RenderingServer::get_singleton()->instance_set_blend_shape_weight(get_instance(), E->get().idx, E->get().value); return true; } @@ -63,7 +63,7 @@ bool MeshInstance::_set(const StringName &p_name, const Variant &p_value) { return false; } -bool MeshInstance::_get(const StringName &p_name, Variant &r_ret) const { +bool MeshInstance3D::_get(const StringName &p_name, Variant &r_ret) const { if (!get_instance().is_valid()) return false; @@ -84,7 +84,7 @@ bool MeshInstance::_get(const StringName &p_name, Variant &r_ret) const { return false; } -void MeshInstance::_get_property_list(List<PropertyInfo> *p_list) const { +void MeshInstance3D::_get_property_list(List<PropertyInfo> *p_list) const { List<String> ls; for (const Map<StringName, BlendShapeTrack>::Element *E = blend_shape_tracks.front(); E; E = E->next()) { @@ -105,13 +105,13 @@ void MeshInstance::_get_property_list(List<PropertyInfo> *p_list) const { } } -void MeshInstance::set_mesh(const Ref<Mesh> &p_mesh) { +void MeshInstance3D::set_mesh(const Ref<Mesh> &p_mesh) { if (mesh == p_mesh) return; if (mesh.is_valid()) { - mesh->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &MeshInstance::_mesh_changed)); + mesh->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &MeshInstance3D::_mesh_changed)); materials.clear(); } @@ -128,7 +128,7 @@ void MeshInstance::set_mesh(const Ref<Mesh> &p_mesh) { blend_shape_tracks["blend_shapes/" + String(mesh->get_blend_shape_name(i))] = mt; } - mesh->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &MeshInstance::_mesh_changed)); + mesh->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &MeshInstance3D::_mesh_changed)); materials.resize(mesh->get_surface_count()); set_base(mesh->get_rid()); @@ -141,17 +141,17 @@ void MeshInstance::set_mesh(const Ref<Mesh> &p_mesh) { _change_notify(); } -Ref<Mesh> MeshInstance::get_mesh() const { +Ref<Mesh> MeshInstance3D::get_mesh() const { return mesh; } -void MeshInstance::_resolve_skeleton_path() { +void MeshInstance3D::_resolve_skeleton_path() { Ref<SkinReference> new_skin_reference; if (!skeleton_path.is_empty()) { - Skeleton *skeleton = Object::cast_to<Skeleton>(get_node(skeleton_path)); + Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(get_node(skeleton_path)); if (skeleton) { new_skin_reference = skeleton->register_skin(skin_internal); if (skin_internal.is_null()) { @@ -165,13 +165,13 @@ void MeshInstance::_resolve_skeleton_path() { skin_ref = new_skin_reference; if (skin_ref.is_valid()) { - VisualServer::get_singleton()->instance_attach_skeleton(get_instance(), skin_ref->get_skeleton()); + RenderingServer::get_singleton()->instance_attach_skeleton(get_instance(), skin_ref->get_skeleton()); } else { - VisualServer::get_singleton()->instance_attach_skeleton(get_instance(), RID()); + RenderingServer::get_singleton()->instance_attach_skeleton(get_instance(), RID()); } } -void MeshInstance::set_skin(const Ref<Skin> &p_skin) { +void MeshInstance3D::set_skin(const Ref<Skin> &p_skin) { skin_internal = p_skin; skin = p_skin; if (!is_inside_tree()) @@ -179,11 +179,11 @@ void MeshInstance::set_skin(const Ref<Skin> &p_skin) { _resolve_skeleton_path(); } -Ref<Skin> MeshInstance::get_skin() const { +Ref<Skin> MeshInstance3D::get_skin() const { return skin; } -void MeshInstance::set_skeleton_path(const NodePath &p_skeleton) { +void MeshInstance3D::set_skeleton_path(const NodePath &p_skeleton) { skeleton_path = p_skeleton; if (!is_inside_tree()) @@ -191,11 +191,11 @@ void MeshInstance::set_skeleton_path(const NodePath &p_skeleton) { _resolve_skeleton_path(); } -NodePath MeshInstance::get_skeleton_path() { +NodePath MeshInstance3D::get_skeleton_path() { return skeleton_path; } -AABB MeshInstance::get_aabb() const { +AABB MeshInstance3D::get_aabb() const { if (!mesh.is_null()) return mesh->get_aabb(); @@ -203,7 +203,7 @@ AABB MeshInstance::get_aabb() const { return AABB(); } -Vector<Face3> MeshInstance::get_faces(uint32_t p_usage_flags) const { +Vector<Face3> MeshInstance3D::get_faces(uint32_t p_usage_flags) const { if (!(p_usage_flags & (FACES_SOLID | FACES_ENCLOSING))) return Vector<Face3>(); @@ -214,103 +214,123 @@ Vector<Face3> MeshInstance::get_faces(uint32_t p_usage_flags) const { return mesh->get_faces(); } -Node *MeshInstance::create_trimesh_collision_node() { +Node *MeshInstance3D::create_trimesh_collision_node() { if (mesh.is_null()) - return NULL; + return nullptr; - Ref<Shape> shape = mesh->create_trimesh_shape(); + Ref<Shape3D> shape = mesh->create_trimesh_shape(); if (shape.is_null()) - return NULL; + return nullptr; - StaticBody *static_body = memnew(StaticBody); - CollisionShape *cshape = memnew(CollisionShape); + StaticBody3D *static_body = memnew(StaticBody3D); + CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(shape); static_body->add_child(cshape); return static_body; } -void MeshInstance::create_trimesh_collision() { +void MeshInstance3D::create_trimesh_collision() { - StaticBody *static_body = Object::cast_to<StaticBody>(create_trimesh_collision_node()); + StaticBody3D *static_body = Object::cast_to<StaticBody3D>(create_trimesh_collision_node()); ERR_FAIL_COND(!static_body); static_body->set_name(String(get_name()) + "_col"); add_child(static_body); if (get_owner()) { - CollisionShape *cshape = Object::cast_to<CollisionShape>(static_body->get_child(0)); + CollisionShape3D *cshape = Object::cast_to<CollisionShape3D>(static_body->get_child(0)); static_body->set_owner(get_owner()); cshape->set_owner(get_owner()); } } -Node *MeshInstance::create_convex_collision_node() { +Node *MeshInstance3D::create_convex_collision_node() { if (mesh.is_null()) - return NULL; + return nullptr; - Ref<Shape> shape = mesh->create_convex_shape(); + Ref<Shape3D> shape = mesh->create_convex_shape(); if (shape.is_null()) - return NULL; + return nullptr; - StaticBody *static_body = memnew(StaticBody); - CollisionShape *cshape = memnew(CollisionShape); + StaticBody3D *static_body = memnew(StaticBody3D); + CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(shape); static_body->add_child(cshape); return static_body; } -void MeshInstance::create_convex_collision() { +void MeshInstance3D::create_convex_collision() { - StaticBody *static_body = Object::cast_to<StaticBody>(create_convex_collision_node()); + StaticBody3D *static_body = Object::cast_to<StaticBody3D>(create_convex_collision_node()); ERR_FAIL_COND(!static_body); static_body->set_name(String(get_name()) + "_col"); add_child(static_body); if (get_owner()) { - CollisionShape *cshape = Object::cast_to<CollisionShape>(static_body->get_child(0)); + CollisionShape3D *cshape = Object::cast_to<CollisionShape3D>(static_body->get_child(0)); static_body->set_owner(get_owner()); cshape->set_owner(get_owner()); } } -void MeshInstance::_notification(int p_what) { +void MeshInstance3D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { _resolve_skeleton_path(); } } -int MeshInstance::get_surface_material_count() const { +int MeshInstance3D::get_surface_material_count() const { return materials.size(); } -void MeshInstance::set_surface_material(int p_surface, const Ref<Material> &p_material) { +void MeshInstance3D::set_surface_material(int p_surface, const Ref<Material> &p_material) { ERR_FAIL_INDEX(p_surface, materials.size()); materials.write[p_surface] = p_material; if (materials[p_surface].is_valid()) - VS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, materials[p_surface]->get_rid()); + RS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, materials[p_surface]->get_rid()); else - VS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, RID()); + RS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, RID()); } -Ref<Material> MeshInstance::get_surface_material(int p_surface) const { +Ref<Material> MeshInstance3D::get_surface_material(int p_surface) const { ERR_FAIL_INDEX_V(p_surface, materials.size(), Ref<Material>()); return materials[p_surface]; } -void MeshInstance::_mesh_changed() { +Ref<Material> MeshInstance3D::get_active_material(int p_surface) const { + + Ref<Material> material_override = get_material_override(); + if (material_override.is_valid()) { + return material_override; + } + + Ref<Material> surface_material = get_surface_material(p_surface); + if (surface_material.is_valid()) { + return surface_material; + } + + Ref<Mesh> mesh = get_mesh(); + if (mesh.is_valid()) { + return mesh->surface_get_material(p_surface); + } + + return Ref<Material>(); +} + +void MeshInstance3D::_mesh_changed() { materials.resize(mesh->get_surface_count()); } -void MeshInstance::create_debug_tangents() { +void MeshInstance3D::create_debug_tangents() { Vector<Vector3> lines; Vector<Color> colors; @@ -371,7 +391,7 @@ void MeshInstance::create_debug_tangents() { am->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, a); am->surface_set_material(0, sm); - MeshInstance *mi = memnew(MeshInstance); + MeshInstance3D *mi = memnew(MeshInstance3D); mi->set_mesh(am); mi->set_name("DebugTangents"); add_child(mi); @@ -385,37 +405,38 @@ void MeshInstance::create_debug_tangents() { } } -void MeshInstance::_bind_methods() { +void MeshInstance3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &MeshInstance::set_mesh); - ClassDB::bind_method(D_METHOD("get_mesh"), &MeshInstance::get_mesh); - ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path"), &MeshInstance::set_skeleton_path); - ClassDB::bind_method(D_METHOD("get_skeleton_path"), &MeshInstance::get_skeleton_path); - ClassDB::bind_method(D_METHOD("set_skin", "skin"), &MeshInstance::set_skin); - ClassDB::bind_method(D_METHOD("get_skin"), &MeshInstance::get_skin); + ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &MeshInstance3D::set_mesh); + ClassDB::bind_method(D_METHOD("get_mesh"), &MeshInstance3D::get_mesh); + ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path"), &MeshInstance3D::set_skeleton_path); + ClassDB::bind_method(D_METHOD("get_skeleton_path"), &MeshInstance3D::get_skeleton_path); + ClassDB::bind_method(D_METHOD("set_skin", "skin"), &MeshInstance3D::set_skin); + ClassDB::bind_method(D_METHOD("get_skin"), &MeshInstance3D::get_skin); - ClassDB::bind_method(D_METHOD("get_surface_material_count"), &MeshInstance::get_surface_material_count); - ClassDB::bind_method(D_METHOD("set_surface_material", "surface", "material"), &MeshInstance::set_surface_material); - ClassDB::bind_method(D_METHOD("get_surface_material", "surface"), &MeshInstance::get_surface_material); + ClassDB::bind_method(D_METHOD("get_surface_material_count"), &MeshInstance3D::get_surface_material_count); + ClassDB::bind_method(D_METHOD("set_surface_material", "surface", "material"), &MeshInstance3D::set_surface_material); + ClassDB::bind_method(D_METHOD("get_surface_material", "surface"), &MeshInstance3D::get_surface_material); + ClassDB::bind_method(D_METHOD("get_active_material", "surface"), &MeshInstance3D::get_active_material); - ClassDB::bind_method(D_METHOD("create_trimesh_collision"), &MeshInstance::create_trimesh_collision); - ClassDB::set_method_flags("MeshInstance", "create_trimesh_collision", METHOD_FLAGS_DEFAULT); - ClassDB::bind_method(D_METHOD("create_convex_collision"), &MeshInstance::create_convex_collision); - ClassDB::set_method_flags("MeshInstance", "create_convex_collision", METHOD_FLAGS_DEFAULT); + ClassDB::bind_method(D_METHOD("create_trimesh_collision"), &MeshInstance3D::create_trimesh_collision); + ClassDB::set_method_flags("MeshInstance3D", "create_trimesh_collision", METHOD_FLAGS_DEFAULT); + ClassDB::bind_method(D_METHOD("create_convex_collision"), &MeshInstance3D::create_convex_collision); + ClassDB::set_method_flags("MeshInstance3D", "create_convex_collision", METHOD_FLAGS_DEFAULT); - ClassDB::bind_method(D_METHOD("create_debug_tangents"), &MeshInstance::create_debug_tangents); - ClassDB::set_method_flags("MeshInstance", "create_debug_tangents", METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); + ClassDB::bind_method(D_METHOD("create_debug_tangents"), &MeshInstance3D::create_debug_tangents); + ClassDB::set_method_flags("MeshInstance3D", "create_debug_tangents", METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh"); ADD_GROUP("Skeleton", ""); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skin", PROPERTY_HINT_RESOURCE_TYPE, "Skin"), "set_skin", "get_skin"); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton"), "set_skeleton_path", "get_skeleton_path"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton3D"), "set_skeleton_path", "get_skeleton_path"); ADD_GROUP("", ""); } -MeshInstance::MeshInstance() { +MeshInstance3D::MeshInstance3D() { skeleton_path = NodePath(".."); } -MeshInstance::~MeshInstance() { +MeshInstance3D::~MeshInstance3D() { } diff --git a/scene/3d/mesh_instance.h b/scene/3d/mesh_instance_3d.h index a6190e7660..914148f427 100644 --- a/scene/3d/mesh_instance.h +++ b/scene/3d/mesh_instance_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* mesh_instance.h */ +/* mesh_instance_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,14 +31,14 @@ #ifndef MESH_INSTANCE_H #define MESH_INSTANCE_H -#include "scene/3d/skeleton.h" -#include "scene/3d/visual_instance.h" +#include "scene/3d/skeleton_3d.h" +#include "scene/3d/visual_instance_3d.h" #include "scene/resources/mesh.h" #include "scene/resources/skin.h" -class MeshInstance : public GeometryInstance { +class MeshInstance3D : public GeometryInstance3D { - GDCLASS(MeshInstance, GeometryInstance); + GDCLASS(MeshInstance3D, GeometryInstance3D); protected: Ref<Mesh> mesh; @@ -84,6 +84,7 @@ public: int get_surface_material_count() const; void set_surface_material(int p_surface, const Ref<Material> &p_material); Ref<Material> get_surface_material(int p_surface) const; + Ref<Material> get_active_material(int p_surface) const; Node *create_trimesh_collision_node(); void create_trimesh_collision(); @@ -96,8 +97,8 @@ public: virtual AABB get_aabb() const; virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const; - MeshInstance(); - ~MeshInstance(); + MeshInstance3D(); + ~MeshInstance3D(); }; #endif diff --git a/scene/3d/multimesh_instance.cpp b/scene/3d/multimesh_instance_3d.cpp index 075eb0a1ec..a625a34283 100644 --- a/scene/3d/multimesh_instance.cpp +++ b/scene/3d/multimesh_instance_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* multimesh_instance.cpp */ +/* multimesh_instance_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,16 +28,16 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "multimesh_instance.h" +#include "multimesh_instance_3d.h" -void MultiMeshInstance::_bind_methods() { +void MultiMeshInstance3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_multimesh", "multimesh"), &MultiMeshInstance::set_multimesh); - ClassDB::bind_method(D_METHOD("get_multimesh"), &MultiMeshInstance::get_multimesh); + ClassDB::bind_method(D_METHOD("set_multimesh", "multimesh"), &MultiMeshInstance3D::set_multimesh); + ClassDB::bind_method(D_METHOD("get_multimesh"), &MultiMeshInstance3D::get_multimesh); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "multimesh", PROPERTY_HINT_RESOURCE_TYPE, "MultiMesh"), "set_multimesh", "get_multimesh"); } -void MultiMeshInstance::set_multimesh(const Ref<MultiMesh> &p_multimesh) { +void MultiMeshInstance3D::set_multimesh(const Ref<MultiMesh> &p_multimesh) { multimesh = p_multimesh; if (multimesh.is_valid()) @@ -46,17 +46,17 @@ void MultiMeshInstance::set_multimesh(const Ref<MultiMesh> &p_multimesh) { set_base(RID()); } -Ref<MultiMesh> MultiMeshInstance::get_multimesh() const { +Ref<MultiMesh> MultiMeshInstance3D::get_multimesh() const { return multimesh; } -Vector<Face3> MultiMeshInstance::get_faces(uint32_t p_usage_flags) const { +Vector<Face3> MultiMeshInstance3D::get_faces(uint32_t p_usage_flags) const { return Vector<Face3>(); } -AABB MultiMeshInstance::get_aabb() const { +AABB MultiMeshInstance3D::get_aabb() const { if (multimesh.is_null()) return AABB(); @@ -64,8 +64,8 @@ AABB MultiMeshInstance::get_aabb() const { return multimesh->get_aabb(); } -MultiMeshInstance::MultiMeshInstance() { +MultiMeshInstance3D::MultiMeshInstance3D() { } -MultiMeshInstance::~MultiMeshInstance() { +MultiMeshInstance3D::~MultiMeshInstance3D() { } diff --git a/scene/3d/multimesh_instance.h b/scene/3d/multimesh_instance_3d.h index 2b59c3b96c..87ec9e120e 100644 --- a/scene/3d/multimesh_instance.h +++ b/scene/3d/multimesh_instance_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* multimesh_instance.h */ +/* multimesh_instance_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef MULTIMESH_INSTANCE_H -#define MULTIMESH_INSTANCE_H +#ifndef MULTIMESH_INSTANCE_3D_H +#define MULTIMESH_INSTANCE_3D_H -#include "scene/3d/visual_instance.h" +#include "scene/3d/visual_instance_3d.h" #include "scene/resources/multimesh.h" -class MultiMeshInstance : public GeometryInstance { - GDCLASS(MultiMeshInstance, GeometryInstance); +class MultiMeshInstance3D : public GeometryInstance3D { + GDCLASS(MultiMeshInstance3D, GeometryInstance3D); Ref<MultiMesh> multimesh; @@ -51,8 +51,8 @@ public: virtual AABB get_aabb() const; - MultiMeshInstance(); - ~MultiMeshInstance(); + MultiMeshInstance3D(); + ~MultiMeshInstance3D(); }; #endif // MULTIMESH_INSTANCE_H diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation_3d.cpp index 8c543bc97f..f880f65d37 100644 --- a/scene/3d/navigation.cpp +++ b/scene/3d/navigation_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation.cpp */ +/* navigation_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,91 +28,91 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "navigation.h" +#include "navigation_3d.h" -#include "servers/navigation_server.h" +#include "servers/navigation_server_3d.h" -Vector<Vector3> Navigation::get_simple_path(const Vector3 &p_start, const Vector3 &p_end, bool p_optimize) const { +Vector<Vector3> Navigation3D::get_simple_path(const Vector3 &p_start, const Vector3 &p_end, bool p_optimize) const { - return NavigationServer::get_singleton()->map_get_path(map, p_start, p_end, p_optimize); + return NavigationServer3D::get_singleton()->map_get_path(map, p_start, p_end, p_optimize); } -Vector3 Navigation::get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, bool p_use_collision) const { - return NavigationServer::get_singleton()->map_get_closest_point_to_segment(map, p_from, p_to, p_use_collision); +Vector3 Navigation3D::get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, bool p_use_collision) const { + return NavigationServer3D::get_singleton()->map_get_closest_point_to_segment(map, p_from, p_to, p_use_collision); } -Vector3 Navigation::get_closest_point(const Vector3 &p_point) const { - return NavigationServer::get_singleton()->map_get_closest_point(map, p_point); +Vector3 Navigation3D::get_closest_point(const Vector3 &p_point) const { + return NavigationServer3D::get_singleton()->map_get_closest_point(map, p_point); } -Vector3 Navigation::get_closest_point_normal(const Vector3 &p_point) const { - return NavigationServer::get_singleton()->map_get_closest_point_normal(map, p_point); +Vector3 Navigation3D::get_closest_point_normal(const Vector3 &p_point) const { + return NavigationServer3D::get_singleton()->map_get_closest_point_normal(map, p_point); } -RID Navigation::get_closest_point_owner(const Vector3 &p_point) const { - return NavigationServer::get_singleton()->map_get_closest_point_owner(map, p_point); +RID Navigation3D::get_closest_point_owner(const Vector3 &p_point) const { + return NavigationServer3D::get_singleton()->map_get_closest_point_owner(map, p_point); } -void Navigation::set_up_vector(const Vector3 &p_up) { +void Navigation3D::set_up_vector(const Vector3 &p_up) { up = p_up; - NavigationServer::get_singleton()->map_set_up(map, up); + NavigationServer3D::get_singleton()->map_set_up(map, up); } -Vector3 Navigation::get_up_vector() const { +Vector3 Navigation3D::get_up_vector() const { return up; } -void Navigation::set_cell_size(float p_cell_size) { +void Navigation3D::set_cell_size(float p_cell_size) { cell_size = p_cell_size; - NavigationServer::get_singleton()->map_set_cell_size(map, cell_size); + NavigationServer3D::get_singleton()->map_set_cell_size(map, cell_size); } -void Navigation::set_edge_connection_margin(float p_edge_connection_margin) { +void Navigation3D::set_edge_connection_margin(float p_edge_connection_margin) { edge_connection_margin = p_edge_connection_margin; - NavigationServer::get_singleton()->map_set_edge_connection_margin(map, edge_connection_margin); + NavigationServer3D::get_singleton()->map_set_edge_connection_margin(map, edge_connection_margin); } -void Navigation::_bind_methods() { +void Navigation3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_rid"), &Navigation::get_rid); + ClassDB::bind_method(D_METHOD("get_rid"), &Navigation3D::get_rid); - ClassDB::bind_method(D_METHOD("get_simple_path", "start", "end", "optimize"), &Navigation::get_simple_path, DEFVAL(true)); - ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "start", "end", "use_collision"), &Navigation::get_closest_point_to_segment, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("get_closest_point", "to_point"), &Navigation::get_closest_point); - ClassDB::bind_method(D_METHOD("get_closest_point_normal", "to_point"), &Navigation::get_closest_point_normal); - ClassDB::bind_method(D_METHOD("get_closest_point_owner", "to_point"), &Navigation::get_closest_point_owner); + ClassDB::bind_method(D_METHOD("get_simple_path", "start", "end", "optimize"), &Navigation3D::get_simple_path, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "start", "end", "use_collision"), &Navigation3D::get_closest_point_to_segment, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("get_closest_point", "to_point"), &Navigation3D::get_closest_point); + ClassDB::bind_method(D_METHOD("get_closest_point_normal", "to_point"), &Navigation3D::get_closest_point_normal); + ClassDB::bind_method(D_METHOD("get_closest_point_owner", "to_point"), &Navigation3D::get_closest_point_owner); - ClassDB::bind_method(D_METHOD("set_up_vector", "up"), &Navigation::set_up_vector); - ClassDB::bind_method(D_METHOD("get_up_vector"), &Navigation::get_up_vector); + ClassDB::bind_method(D_METHOD("set_up_vector", "up"), &Navigation3D::set_up_vector); + ClassDB::bind_method(D_METHOD("get_up_vector"), &Navigation3D::get_up_vector); - ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &Navigation::set_cell_size); - ClassDB::bind_method(D_METHOD("get_cell_size"), &Navigation::get_cell_size); + ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &Navigation3D::set_cell_size); + ClassDB::bind_method(D_METHOD("get_cell_size"), &Navigation3D::get_cell_size); - ClassDB::bind_method(D_METHOD("set_edge_connection_margin", "margin"), &Navigation::set_edge_connection_margin); - ClassDB::bind_method(D_METHOD("get_edge_connection_margin"), &Navigation::get_edge_connection_margin); + ClassDB::bind_method(D_METHOD("set_edge_connection_margin", "margin"), &Navigation3D::set_edge_connection_margin); + ClassDB::bind_method(D_METHOD("get_edge_connection_margin"), &Navigation3D::get_edge_connection_margin); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "up_vector"), "set_up_vector", "get_up_vector"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cell_size"), "set_cell_size", "get_cell_size"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "edge_connection_margin"), "set_edge_connection_margin", "get_edge_connection_margin"); } -void Navigation::_notification(int p_what) { +void Navigation3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { - NavigationServer::get_singleton()->map_set_active(map, true); + NavigationServer3D::get_singleton()->map_set_active(map, true); } break; case NOTIFICATION_EXIT_TREE: { - NavigationServer::get_singleton()->map_set_active(map, false); + NavigationServer3D::get_singleton()->map_set_active(map, false); } break; } } -Navigation::Navigation() { +Navigation3D::Navigation3D() { - map = NavigationServer::get_singleton()->map_create(); + map = NavigationServer3D::get_singleton()->map_create(); set_cell_size(0.3); set_edge_connection_margin(5.0); // Five meters, depends alot on the agents radius @@ -120,6 +120,6 @@ Navigation::Navigation() { up = Vector3(0, 1, 0); } -Navigation::~Navigation() { - NavigationServer::get_singleton()->free(map); +Navigation3D::~Navigation3D() { + NavigationServer3D::get_singleton()->free(map); } diff --git a/scene/3d/navigation.h b/scene/3d/navigation_3d.h index 08f306611f..daa9558125 100644 --- a/scene/3d/navigation.h +++ b/scene/3d/navigation_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation.h */ +/* navigation_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef NAVIGATION_H -#define NAVIGATION_H +#ifndef NAVIGATION_3D_H +#define NAVIGATION_3D_H -#include "scene/3d/navigation_region.h" -#include "scene/3d/spatial.h" +#include "scene/3d/navigation_region_3d.h" +#include "scene/3d/node_3d.h" -class Navigation : public Spatial { +class Navigation3D : public Node3D { - GDCLASS(Navigation, Spatial); + GDCLASS(Navigation3D, Node3D); RID map; @@ -72,8 +72,8 @@ public: Vector3 get_closest_point_normal(const Vector3 &p_point) const; RID get_closest_point_owner(const Vector3 &p_point) const; - Navigation(); - ~Navigation(); + Navigation3D(); + ~Navigation3D(); }; #endif // NAVIGATION_H diff --git a/scene/3d/navigation_agent.cpp b/scene/3d/navigation_agent_3d.cpp index 3da1ea66d6..0449ab15b7 100644 --- a/scene/3d/navigation_agent.cpp +++ b/scene/3d/navigation_agent_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_agent.cpp */ +/* navigation_agent_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,57 +28,57 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "navigation_agent.h" +#include "navigation_agent_3d.h" #include "core/engine.h" -#include "scene/3d/navigation.h" -#include "servers/navigation_server.h" +#include "scene/3d/navigation_3d.h" +#include "servers/navigation_server_3d.h" -void NavigationAgent::_bind_methods() { +void NavigationAgent3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_target_desired_distance", "desired_distance"), &NavigationAgent::set_target_desired_distance); - ClassDB::bind_method(D_METHOD("get_target_desired_distance"), &NavigationAgent::get_target_desired_distance); + ClassDB::bind_method(D_METHOD("set_target_desired_distance", "desired_distance"), &NavigationAgent3D::set_target_desired_distance); + ClassDB::bind_method(D_METHOD("get_target_desired_distance"), &NavigationAgent3D::get_target_desired_distance); - ClassDB::bind_method(D_METHOD("set_radius", "radius"), &NavigationAgent::set_radius); - ClassDB::bind_method(D_METHOD("get_radius"), &NavigationAgent::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "radius"), &NavigationAgent3D::set_radius); + ClassDB::bind_method(D_METHOD("get_radius"), &NavigationAgent3D::get_radius); - ClassDB::bind_method(D_METHOD("set_agent_height_offset", "agent_height_offset"), &NavigationAgent::set_agent_height_offset); - ClassDB::bind_method(D_METHOD("get_agent_height_offset"), &NavigationAgent::get_agent_height_offset); + ClassDB::bind_method(D_METHOD("set_agent_height_offset", "agent_height_offset"), &NavigationAgent3D::set_agent_height_offset); + ClassDB::bind_method(D_METHOD("get_agent_height_offset"), &NavigationAgent3D::get_agent_height_offset); - ClassDB::bind_method(D_METHOD("set_ignore_y", "ignore"), &NavigationAgent::set_ignore_y); - ClassDB::bind_method(D_METHOD("get_ignore_y"), &NavigationAgent::get_ignore_y); + ClassDB::bind_method(D_METHOD("set_ignore_y", "ignore"), &NavigationAgent3D::set_ignore_y); + ClassDB::bind_method(D_METHOD("get_ignore_y"), &NavigationAgent3D::get_ignore_y); - ClassDB::bind_method(D_METHOD("set_navigation", "navigation"), &NavigationAgent::set_navigation_node); - ClassDB::bind_method(D_METHOD("get_navigation"), &NavigationAgent::get_navigation_node); + ClassDB::bind_method(D_METHOD("set_navigation", "navigation"), &NavigationAgent3D::set_navigation_node); + ClassDB::bind_method(D_METHOD("get_navigation"), &NavigationAgent3D::get_navigation_node); - ClassDB::bind_method(D_METHOD("set_neighbor_dist", "neighbor_dist"), &NavigationAgent::set_neighbor_dist); - ClassDB::bind_method(D_METHOD("get_neighbor_dist"), &NavigationAgent::get_neighbor_dist); + ClassDB::bind_method(D_METHOD("set_neighbor_dist", "neighbor_dist"), &NavigationAgent3D::set_neighbor_dist); + ClassDB::bind_method(D_METHOD("get_neighbor_dist"), &NavigationAgent3D::get_neighbor_dist); - ClassDB::bind_method(D_METHOD("set_max_neighbors", "max_neighbors"), &NavigationAgent::set_max_neighbors); - ClassDB::bind_method(D_METHOD("get_max_neighbors"), &NavigationAgent::get_max_neighbors); + ClassDB::bind_method(D_METHOD("set_max_neighbors", "max_neighbors"), &NavigationAgent3D::set_max_neighbors); + ClassDB::bind_method(D_METHOD("get_max_neighbors"), &NavigationAgent3D::get_max_neighbors); - ClassDB::bind_method(D_METHOD("set_time_horizon", "time_horizon"), &NavigationAgent::set_time_horizon); - ClassDB::bind_method(D_METHOD("get_time_horizon"), &NavigationAgent::get_time_horizon); + ClassDB::bind_method(D_METHOD("set_time_horizon", "time_horizon"), &NavigationAgent3D::set_time_horizon); + ClassDB::bind_method(D_METHOD("get_time_horizon"), &NavigationAgent3D::get_time_horizon); - ClassDB::bind_method(D_METHOD("set_max_speed", "max_speed"), &NavigationAgent::set_max_speed); - ClassDB::bind_method(D_METHOD("get_max_speed"), &NavigationAgent::get_max_speed); + ClassDB::bind_method(D_METHOD("set_max_speed", "max_speed"), &NavigationAgent3D::set_max_speed); + ClassDB::bind_method(D_METHOD("get_max_speed"), &NavigationAgent3D::get_max_speed); - ClassDB::bind_method(D_METHOD("set_path_max_distance", "max_speed"), &NavigationAgent::set_path_max_distance); - ClassDB::bind_method(D_METHOD("get_path_max_distance"), &NavigationAgent::get_path_max_distance); + ClassDB::bind_method(D_METHOD("set_path_max_distance", "max_speed"), &NavigationAgent3D::set_path_max_distance); + ClassDB::bind_method(D_METHOD("get_path_max_distance"), &NavigationAgent3D::get_path_max_distance); - ClassDB::bind_method(D_METHOD("set_target_location", "location"), &NavigationAgent::set_target_location); - ClassDB::bind_method(D_METHOD("get_target_location"), &NavigationAgent::get_target_location); - ClassDB::bind_method(D_METHOD("get_next_location"), &NavigationAgent::get_next_location); - ClassDB::bind_method(D_METHOD("distance_to_target"), &NavigationAgent::distance_to_target); - ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &NavigationAgent::set_velocity); - ClassDB::bind_method(D_METHOD("get_nav_path"), &NavigationAgent::get_nav_path); - ClassDB::bind_method(D_METHOD("get_nav_path_index"), &NavigationAgent::get_nav_path_index); - ClassDB::bind_method(D_METHOD("is_target_reached"), &NavigationAgent::is_target_reached); - ClassDB::bind_method(D_METHOD("is_target_reachable"), &NavigationAgent::is_target_reachable); - ClassDB::bind_method(D_METHOD("is_navigation_finished"), &NavigationAgent::is_navigation_finished); - ClassDB::bind_method(D_METHOD("get_final_location"), &NavigationAgent::get_final_location); + ClassDB::bind_method(D_METHOD("set_target_location", "location"), &NavigationAgent3D::set_target_location); + ClassDB::bind_method(D_METHOD("get_target_location"), &NavigationAgent3D::get_target_location); + ClassDB::bind_method(D_METHOD("get_next_location"), &NavigationAgent3D::get_next_location); + ClassDB::bind_method(D_METHOD("distance_to_target"), &NavigationAgent3D::distance_to_target); + ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &NavigationAgent3D::set_velocity); + ClassDB::bind_method(D_METHOD("get_nav_path"), &NavigationAgent3D::get_nav_path); + ClassDB::bind_method(D_METHOD("get_nav_path_index"), &NavigationAgent3D::get_nav_path_index); + ClassDB::bind_method(D_METHOD("is_target_reached"), &NavigationAgent3D::is_target_reached); + ClassDB::bind_method(D_METHOD("is_target_reachable"), &NavigationAgent3D::is_target_reachable); + ClassDB::bind_method(D_METHOD("is_navigation_finished"), &NavigationAgent3D::is_navigation_finished); + ClassDB::bind_method(D_METHOD("get_final_location"), &NavigationAgent3D::get_final_location); - ClassDB::bind_method(D_METHOD("_avoidance_done", "new_velocity"), &NavigationAgent::_avoidance_done); + ClassDB::bind_method(D_METHOD("_avoidance_done", "new_velocity"), &NavigationAgent3D::_avoidance_done); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "target_desired_distance", PROPERTY_HINT_RANGE, "0.1,100,0.01"), "set_target_desired_distance", "get_target_desired_distance"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.1,100,0.01"), "set_radius", "get_radius"); @@ -96,22 +96,22 @@ void NavigationAgent::_bind_methods() { ADD_SIGNAL(MethodInfo("velocity_computed", PropertyInfo(Variant::VECTOR3, "safe_velocity"))); } -void NavigationAgent::_notification(int p_what) { +void NavigationAgent3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { - agent_parent = Object::cast_to<Spatial>(get_parent()); + agent_parent = Object::cast_to<Node3D>(get_parent()); - NavigationServer::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); + NavigationServer3D::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); // Search the navigation node and set it { - Navigation *nav = NULL; + Navigation3D *nav = nullptr; Node *p = get_parent(); - while (p != NULL) { - nav = Object::cast_to<Navigation>(p); - if (nav != NULL) - p = NULL; + while (p != nullptr) { + nav = Object::cast_to<Navigation3D>(p); + if (nav != nullptr) + p = nullptr; else p = p->get_parent(); } @@ -122,14 +122,14 @@ void NavigationAgent::_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) { - NavigationServer::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().origin); + NavigationServer3D::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().origin); if (!target_reached) { if (distance_to_target() < target_desired_distance) { emit_signal("target_reached"); @@ -141,9 +141,9 @@ void NavigationAgent::_notification(int p_what) { } } -NavigationAgent::NavigationAgent() : - agent_parent(NULL), - navigation(NULL), +NavigationAgent3D::NavigationAgent3D() : + agent_parent(nullptr), + navigation(nullptr), agent(RID()), target_desired_distance(1.0), navigation_height_offset(0.0), @@ -151,7 +151,7 @@ NavigationAgent::NavigationAgent() : velocity_submitted(false), target_reached(false), navigation_finished(true) { - agent = NavigationServer::get_singleton()->agent_create(); + agent = NavigationServer3D::get_singleton()->agent_create(); set_neighbor_dist(50.0); set_max_neighbors(10); set_time_horizon(5.0); @@ -160,76 +160,76 @@ NavigationAgent::NavigationAgent() : set_ignore_y(true); } -NavigationAgent::~NavigationAgent() { - NavigationServer::get_singleton()->free(agent); +NavigationAgent3D::~NavigationAgent3D() { + NavigationServer3D::get_singleton()->free(agent); agent = RID(); // Pointless } -void NavigationAgent::set_navigation(Navigation *p_nav) { +void NavigationAgent3D::set_navigation(Navigation3D *p_nav) { if (navigation == p_nav) return; // Pointless navigation = p_nav; - NavigationServer::get_singleton()->agent_set_map(agent, navigation == NULL ? RID() : navigation->get_rid()); + NavigationServer3D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid()); } -void NavigationAgent::set_navigation_node(Node *p_nav) { - Navigation *nav = Object::cast_to<Navigation>(p_nav); - ERR_FAIL_COND(nav == NULL); +void NavigationAgent3D::set_navigation_node(Node *p_nav) { + Navigation3D *nav = Object::cast_to<Navigation3D>(p_nav); + ERR_FAIL_COND(nav == nullptr); set_navigation(nav); } -Node *NavigationAgent::get_navigation_node() const { +Node *NavigationAgent3D::get_navigation_node() const { return Object::cast_to<Node>(navigation); } -void NavigationAgent::set_target_desired_distance(real_t p_dd) { +void NavigationAgent3D::set_target_desired_distance(real_t p_dd) { target_desired_distance = p_dd; } -void NavigationAgent::set_radius(real_t p_radius) { +void NavigationAgent3D::set_radius(real_t p_radius) { radius = p_radius; - NavigationServer::get_singleton()->agent_set_radius(agent, radius); + NavigationServer3D::get_singleton()->agent_set_radius(agent, radius); } -void NavigationAgent::set_agent_height_offset(real_t p_hh) { +void NavigationAgent3D::set_agent_height_offset(real_t p_hh) { navigation_height_offset = p_hh; } -void NavigationAgent::set_ignore_y(bool p_ignore_y) { +void NavigationAgent3D::set_ignore_y(bool p_ignore_y) { ignore_y = p_ignore_y; - NavigationServer::get_singleton()->agent_set_ignore_y(agent, ignore_y); + NavigationServer3D::get_singleton()->agent_set_ignore_y(agent, ignore_y); } -void NavigationAgent::set_neighbor_dist(real_t p_dist) { +void NavigationAgent3D::set_neighbor_dist(real_t p_dist) { neighbor_dist = p_dist; - NavigationServer::get_singleton()->agent_set_neighbor_dist(agent, neighbor_dist); + NavigationServer3D::get_singleton()->agent_set_neighbor_dist(agent, neighbor_dist); } -void NavigationAgent::set_max_neighbors(int p_count) { +void NavigationAgent3D::set_max_neighbors(int p_count) { max_neighbors = p_count; - NavigationServer::get_singleton()->agent_set_max_neighbors(agent, max_neighbors); + NavigationServer3D::get_singleton()->agent_set_max_neighbors(agent, max_neighbors); } -void NavigationAgent::set_time_horizon(real_t p_time) { +void NavigationAgent3D::set_time_horizon(real_t p_time) { time_horizon = p_time; - NavigationServer::get_singleton()->agent_set_time_horizon(agent, time_horizon); + NavigationServer3D::get_singleton()->agent_set_time_horizon(agent, time_horizon); } -void NavigationAgent::set_max_speed(real_t p_max_speed) { +void NavigationAgent3D::set_max_speed(real_t p_max_speed) { max_speed = p_max_speed; - NavigationServer::get_singleton()->agent_set_max_speed(agent, max_speed); + NavigationServer3D::get_singleton()->agent_set_max_speed(agent, max_speed); } -void NavigationAgent::set_path_max_distance(real_t p_pmd) { +void NavigationAgent3D::set_path_max_distance(real_t p_pmd) { path_max_distance = p_pmd; } -real_t NavigationAgent::get_path_max_distance() { +real_t NavigationAgent3D::get_path_max_distance() { return path_max_distance; } -void NavigationAgent::set_target_location(Vector3 p_location) { +void NavigationAgent3D::set_target_location(Vector3 p_location) { target_location = p_location; navigation_path.clear(); target_reached = false; @@ -237,39 +237,39 @@ void NavigationAgent::set_target_location(Vector3 p_location) { update_frame_id = 0; } -Vector3 NavigationAgent::get_target_location() const { +Vector3 NavigationAgent3D::get_target_location() const { return target_location; } -Vector3 NavigationAgent::get_next_location() { +Vector3 NavigationAgent3D::get_next_location() { update_navigation(); if (navigation_path.size() == 0) { - ERR_FAIL_COND_V(agent_parent == NULL, Vector3()); + ERR_FAIL_COND_V(agent_parent == nullptr, Vector3()); return agent_parent->get_global_transform().origin; } else { return navigation_path[nav_path_index] - Vector3(0, navigation_height_offset, 0); } } -real_t NavigationAgent::distance_to_target() const { - ERR_FAIL_COND_V(agent_parent == NULL, 0.0); +real_t NavigationAgent3D::distance_to_target() const { + ERR_FAIL_COND_V(agent_parent == nullptr, 0.0); return agent_parent->get_global_transform().origin.distance_to(target_location); } -bool NavigationAgent::is_target_reached() const { +bool NavigationAgent3D::is_target_reached() const { return target_reached; } -bool NavigationAgent::is_target_reachable() { +bool NavigationAgent3D::is_target_reachable() { return target_desired_distance >= get_final_location().distance_to(target_location); } -bool NavigationAgent::is_navigation_finished() { +bool NavigationAgent3D::is_navigation_finished() { update_navigation(); return navigation_finished; } -Vector3 NavigationAgent::get_final_location() { +Vector3 NavigationAgent3D::get_final_location() { update_navigation(); if (navigation_path.size() == 0) { return Vector3(); @@ -277,14 +277,14 @@ Vector3 NavigationAgent::get_final_location() { return navigation_path[navigation_path.size() - 1]; } -void NavigationAgent::set_velocity(Vector3 p_velocity) { +void NavigationAgent3D::set_velocity(Vector3 p_velocity) { target_velocity = p_velocity; - NavigationServer::get_singleton()->agent_set_target_velocity(agent, target_velocity); - NavigationServer::get_singleton()->agent_set_velocity(agent, prev_safe_velocity); + NavigationServer3D::get_singleton()->agent_set_target_velocity(agent, target_velocity); + NavigationServer3D::get_singleton()->agent_set_velocity(agent, prev_safe_velocity); velocity_submitted = true; } -void NavigationAgent::_avoidance_done(Vector3 p_new_velocity) { +void NavigationAgent3D::_avoidance_done(Vector3 p_new_velocity) { prev_safe_velocity = p_new_velocity; if (!velocity_submitted) { @@ -296,18 +296,18 @@ void NavigationAgent::_avoidance_done(Vector3 p_new_velocity) { emit_signal("velocity_computed", p_new_velocity); } -String NavigationAgent::get_configuration_warning() const { - if (!Object::cast_to<Spatial>(get_parent())) { - return TTR("The NavigationAgent can be used only under a spatial node."); +String NavigationAgent3D::get_configuration_warning() const { + if (!Object::cast_to<Node3D>(get_parent())) { + return TTR("The NavigationAgent3D can be used only under a spatial node."); } return String(); } -void NavigationAgent::update_navigation() { +void NavigationAgent3D::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(); @@ -316,7 +316,7 @@ void NavigationAgent::update_navigation() { bool reload_path = false; - if (NavigationServer::get_singleton()->agent_is_map_changed(agent)) { + if (NavigationServer3D::get_singleton()->agent_is_map_changed(agent)) { reload_path = true; } else if (navigation_path.size() == 0) { reload_path = true; @@ -337,7 +337,7 @@ void NavigationAgent::update_navigation() { } if (reload_path) { - navigation_path = NavigationServer::get_singleton()->map_get_path(navigation->get_rid(), o, target_location, true); + navigation_path = NavigationServer3D::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/3d/navigation_agent.h b/scene/3d/navigation_agent_3d.h index 200d5db475..3558b4e51b 100644 --- a/scene/3d/navigation_agent.h +++ b/scene/3d/navigation_agent_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_agent.h */ +/* navigation_agent_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -34,14 +34,14 @@ #include "core/vector.h" #include "scene/main/node.h" -class Spatial; -class Navigation; +class Node3D; +class Navigation3D; -class NavigationAgent : public Node { - GDCLASS(NavigationAgent, Node); +class NavigationAgent3D : public Node { + GDCLASS(NavigationAgent3D, Node); - Spatial *agent_parent; - Navigation *navigation; + Node3D *agent_parent; + Navigation3D *navigation; RID agent; @@ -73,11 +73,11 @@ protected: void _notification(int p_what); public: - NavigationAgent(); - virtual ~NavigationAgent(); + NavigationAgent3D(); + virtual ~NavigationAgent3D(); - void set_navigation(Navigation *p_nav); - const Navigation *get_navigation() const { + void set_navigation(Navigation3D *p_nav); + const Navigation3D *get_navigation() const { return navigation; } diff --git a/scene/3d/navigation_obstacle.cpp b/scene/3d/navigation_obstacle_3d.cpp index befc41eee5..2ee2008799 100644 --- a/scene/3d/navigation_obstacle.cpp +++ b/scene/3d/navigation_obstacle_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_obstacle.cpp */ +/* navigation_obstacle_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,20 +28,20 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "navigation_obstacle.h" +#include "navigation_obstacle_3d.h" -#include "scene/3d/collision_shape.h" -#include "scene/3d/navigation.h" -#include "scene/3d/physics_body.h" -#include "servers/navigation_server.h" +#include "scene/3d/collision_shape_3d.h" +#include "scene/3d/navigation_3d.h" +#include "scene/3d/physics_body_3d.h" +#include "servers/navigation_server_3d.h" -void NavigationObstacle::_bind_methods() { +void NavigationObstacle3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_navigation", "navigation"), &NavigationObstacle::set_navigation_node); - ClassDB::bind_method(D_METHOD("get_navigation"), &NavigationObstacle::get_navigation_node); + ClassDB::bind_method(D_METHOD("set_navigation", "navigation"), &NavigationObstacle3D::set_navigation_node); + ClassDB::bind_method(D_METHOD("get_navigation"), &NavigationObstacle3D::get_navigation_node); } -void NavigationObstacle::_notification(int p_what) { +void NavigationObstacle3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { @@ -49,12 +49,12 @@ void NavigationObstacle::_notification(int p_what) { // Search the navigation node and set it { - Navigation *nav = NULL; + Navigation3D *nav = nullptr; Node *p = get_parent(); - while (p != NULL) { - nav = Object::cast_to<Navigation>(p); - if (nav != NULL) - p = NULL; + while (p != nullptr) { + nav = Object::cast_to<Navigation3D>(p); + if (nav != nullptr) + p = nullptr; else p = p->get_parent(); } @@ -65,73 +65,73 @@ void NavigationObstacle::_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: { - Spatial *spatial = Object::cast_to<Spatial>(get_parent()); + Node3D *spatial = Object::cast_to<Node3D>(get_parent()); if (spatial) { - NavigationServer::get_singleton()->agent_set_position(agent, spatial->get_global_transform().origin); + NavigationServer3D::get_singleton()->agent_set_position(agent, spatial->get_global_transform().origin); } - PhysicsBody *rigid = Object::cast_to<PhysicsBody>(get_parent()); + PhysicsBody3D *rigid = Object::cast_to<PhysicsBody3D>(get_parent()); if (rigid) { Vector3 v = rigid->get_linear_velocity(); - NavigationServer::get_singleton()->agent_set_velocity(agent, v); - NavigationServer::get_singleton()->agent_set_target_velocity(agent, v); + NavigationServer3D::get_singleton()->agent_set_velocity(agent, v); + NavigationServer3D::get_singleton()->agent_set_target_velocity(agent, v); } } break; } } -NavigationObstacle::NavigationObstacle() : - navigation(NULL), +NavigationObstacle3D::NavigationObstacle3D() : + navigation(nullptr), agent(RID()) { - agent = NavigationServer::get_singleton()->agent_create(); + agent = NavigationServer3D::get_singleton()->agent_create(); } -NavigationObstacle::~NavigationObstacle() { - NavigationServer::get_singleton()->free(agent); +NavigationObstacle3D::~NavigationObstacle3D() { + NavigationServer3D::get_singleton()->free(agent); agent = RID(); // Pointless } -void NavigationObstacle::set_navigation(Navigation *p_nav) { +void NavigationObstacle3D::set_navigation(Navigation3D *p_nav) { if (navigation == p_nav) return; // Pointless navigation = p_nav; - NavigationServer::get_singleton()->agent_set_map(agent, navigation == NULL ? RID() : navigation->get_rid()); + NavigationServer3D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid()); } -void NavigationObstacle::set_navigation_node(Node *p_nav) { - Navigation *nav = Object::cast_to<Navigation>(p_nav); - ERR_FAIL_COND(nav == NULL); +void NavigationObstacle3D::set_navigation_node(Node *p_nav) { + Navigation3D *nav = Object::cast_to<Navigation3D>(p_nav); + ERR_FAIL_COND(nav == nullptr); set_navigation(nav); } -Node *NavigationObstacle::get_navigation_node() const { +Node *NavigationObstacle3D::get_navigation_node() const { return Object::cast_to<Node>(navigation); } -String NavigationObstacle::get_configuration_warning() const { - if (!Object::cast_to<Spatial>(get_parent())) { +String NavigationObstacle3D::get_configuration_warning() const { + if (!Object::cast_to<Node3D>(get_parent())) { - return TTR("The NavigationObstacle only serves to provide collision avoidance to a spatial object."); + return TTR("The NavigationObstacle3D only serves to provide collision avoidance to a spatial object."); } return String(); } -void NavigationObstacle::update_agent_shape() { +void NavigationObstacle3D::update_agent_shape() { Node *node = get_parent(); // Estimate the radius of this physics body real_t radius = 0.0; for (int i(0); i < node->get_child_count(); i++) { // For each collision shape - CollisionShape *cs = Object::cast_to<CollisionShape>(node->get_child(i)); + CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(node->get_child(i)); if (cs) { // Take the distance between the Body center to the shape center real_t r = cs->get_transform().origin.length(); @@ -145,7 +145,7 @@ void NavigationObstacle::update_agent_shape() { radius = MAX(radius, r); } } - Spatial *spa = Object::cast_to<Spatial>(node); + Node3D *spa = Object::cast_to<Node3D>(node); if (spa) { Vector3 s = spa->get_global_transform().basis.get_scale(); radius *= MAX(s.x, MAX(s.y, s.z)); @@ -155,9 +155,9 @@ void NavigationObstacle::update_agent_shape() { radius = 1.0; // Never a 0 radius // Initialize the Agent as an object - NavigationServer::get_singleton()->agent_set_neighbor_dist(agent, 0.0); - NavigationServer::get_singleton()->agent_set_max_neighbors(agent, 0); - NavigationServer::get_singleton()->agent_set_time_horizon(agent, 0.0); - NavigationServer::get_singleton()->agent_set_radius(agent, radius); - NavigationServer::get_singleton()->agent_set_max_speed(agent, 0.0); + NavigationServer3D::get_singleton()->agent_set_neighbor_dist(agent, 0.0); + NavigationServer3D::get_singleton()->agent_set_max_neighbors(agent, 0); + NavigationServer3D::get_singleton()->agent_set_time_horizon(agent, 0.0); + NavigationServer3D::get_singleton()->agent_set_radius(agent, radius); + NavigationServer3D::get_singleton()->agent_set_max_speed(agent, 0.0); } diff --git a/scene/3d/navigation_obstacle.h b/scene/3d/navigation_obstacle_3d.h index 7257a43150..b58d7c4991 100644 --- a/scene/3d/navigation_obstacle.h +++ b/scene/3d/navigation_obstacle_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_obstacle.h */ +/* navigation_obstacle_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -33,12 +33,12 @@ #include "scene/main/node.h" -class Navigation; +class Navigation3D; -class NavigationObstacle : public Node { - GDCLASS(NavigationObstacle, Node); +class NavigationObstacle3D : public Node { + GDCLASS(NavigationObstacle3D, Node); - Navigation *navigation; + Navigation3D *navigation; RID agent; @@ -47,11 +47,11 @@ protected: void _notification(int p_what); public: - NavigationObstacle(); - virtual ~NavigationObstacle(); + NavigationObstacle3D(); + virtual ~NavigationObstacle3D(); - void set_navigation(Navigation *p_nav); - const Navigation *get_navigation() const { + void set_navigation(Navigation3D *p_nav); + const Navigation3D *get_navigation() const { return navigation; } diff --git a/scene/3d/navigation_region.cpp b/scene/3d/navigation_region_3d.cpp index 53b707a29a..043b816033 100644 --- a/scene/3d/navigation_region.cpp +++ b/scene/3d/navigation_region_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_region.cpp */ +/* navigation_region_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,13 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "navigation_region.h" +#include "navigation_region_3d.h" + #include "core/os/thread.h" -#include "mesh_instance.h" -#include "navigation.h" -#include "servers/navigation_server.h" +#include "mesh_instance_3d.h" +#include "navigation_3d.h" +#include "servers/navigation_server_3d.h" -void NavigationRegion::set_enabled(bool p_enabled) { +void NavigationRegion3D::set_enabled(bool p_enabled) { if (enabled == p_enabled) return; @@ -45,17 +46,17 @@ void NavigationRegion::set_enabled(bool p_enabled) { if (!enabled) { - NavigationServer::get_singleton()->region_set_map(region, RID()); + NavigationServer3D::get_singleton()->region_set_map(region, RID()); } else { if (navigation) { - NavigationServer::get_singleton()->region_set_map(region, navigation->get_rid()); + NavigationServer3D::get_singleton()->region_set_map(region, navigation->get_rid()); } } if (debug_view) { - MeshInstance *dm = Object::cast_to<MeshInstance>(debug_view); + MeshInstance3D *dm = Object::cast_to<MeshInstance3D>(debug_view); if (is_enabled()) { dm->set_material_override(get_tree()->get_debug_navigation_material()); } else { @@ -66,27 +67,27 @@ void NavigationRegion::set_enabled(bool p_enabled) { update_gizmo(); } -bool NavigationRegion::is_enabled() const { +bool NavigationRegion3D::is_enabled() const { return enabled; } ///////////////////////////// -void NavigationRegion::_notification(int p_what) { +void NavigationRegion3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - Spatial *c = this; + Node3D *c = this; while (c) { - navigation = Object::cast_to<Navigation>(c); + navigation = Object::cast_to<Navigation3D>(c); if (navigation) { if (enabled) { - NavigationServer::get_singleton()->region_set_map(region, navigation->get_rid()); + NavigationServer3D::get_singleton()->region_set_map(region, navigation->get_rid()); } break; } @@ -96,7 +97,7 @@ void NavigationRegion::_notification(int p_what) { if (navmesh.is_valid() && get_tree()->is_debugging_navigation_hint()) { - MeshInstance *dm = memnew(MeshInstance); + MeshInstance3D *dm = memnew(MeshInstance3D); dm->set_mesh(navmesh->get_debug_mesh()); if (is_enabled()) { dm->set_material_override(get_tree()->get_debug_navigation_material()); @@ -110,26 +111,26 @@ void NavigationRegion::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { - NavigationServer::get_singleton()->region_set_transform(region, get_global_transform()); + NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform()); } break; case NOTIFICATION_EXIT_TREE: { if (navigation) { - NavigationServer::get_singleton()->region_set_map(region, RID()); + NavigationServer3D::get_singleton()->region_set_map(region, RID()); } if (debug_view) { debug_view->queue_delete(); - debug_view = NULL; + debug_view = nullptr; } - navigation = NULL; + navigation = nullptr; } break; } } -void NavigationRegion::set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh) { +void NavigationRegion3D::set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh) { if (p_navmesh == navmesh) return; @@ -144,10 +145,10 @@ void NavigationRegion::set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh) navmesh->add_change_receptor(this); } - NavigationServer::get_singleton()->region_set_navmesh(region, p_navmesh); + NavigationServer3D::get_singleton()->region_set_navmesh(region, p_navmesh); if (debug_view && navmesh.is_valid()) { - Object::cast_to<MeshInstance>(debug_view)->set_mesh(navmesh->get_debug_mesh()); + Object::cast_to<MeshInstance3D>(debug_view)->set_mesh(navmesh->get_debug_mesh()); } emit_signal("navigation_mesh_changed"); @@ -156,13 +157,13 @@ void NavigationRegion::set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh) update_configuration_warning(); } -Ref<NavigationMesh> NavigationRegion::get_navigation_mesh() const { +Ref<NavigationMesh> NavigationRegion3D::get_navigation_mesh() const { return navmesh; } struct BakeThreadsArgs { - NavigationRegion *nav_region; + NavigationRegion3D *nav_region; }; void _bake_navigation_mesh(void *p_user_data) { @@ -171,7 +172,7 @@ void _bake_navigation_mesh(void *p_user_data) { if (args->nav_region->get_navigation_mesh().is_valid()) { Ref<NavigationMesh> nav_mesh = args->nav_region->get_navigation_mesh()->duplicate(); - NavigationServer::get_singleton()->region_bake_navmesh(nav_mesh, args->nav_region); + NavigationServer3D::get_singleton()->region_bake_navmesh(nav_mesh, args->nav_region); args->nav_region->call_deferred("_bake_finished", nav_mesh); memdelete(args); } else { @@ -182,22 +183,22 @@ void _bake_navigation_mesh(void *p_user_data) { } } -void NavigationRegion::bake_navigation_mesh() { - ERR_FAIL_COND(bake_thread != NULL); +void NavigationRegion3D::bake_navigation_mesh() { + ERR_FAIL_COND(bake_thread != nullptr); BakeThreadsArgs *args = memnew(BakeThreadsArgs); args->nav_region = this; bake_thread = Thread::create(_bake_navigation_mesh, args); - ERR_FAIL_COND(bake_thread == NULL); + ERR_FAIL_COND(bake_thread == nullptr); } -void NavigationRegion::_bake_finished(Ref<NavigationMesh> p_nav_mesh) { +void NavigationRegion3D::_bake_finished(Ref<NavigationMesh> p_nav_mesh) { set_navigation_mesh(p_nav_mesh); - bake_thread = NULL; + bake_thread = nullptr; } -String NavigationRegion::get_configuration_warning() const { +String NavigationRegion3D::get_configuration_warning() const { if (!is_visible_in_tree() || !is_inside_tree()) return String(); @@ -205,28 +206,28 @@ String NavigationRegion::get_configuration_warning() const { if (!navmesh.is_valid()) { return TTR("A NavigationMesh resource must be set or created for this node to work."); } - const Spatial *c = this; + const Node3D *c = this; while (c) { - if (Object::cast_to<Navigation>(c)) + if (Object::cast_to<Navigation3D>(c)) return String(); - c = Object::cast_to<Spatial>(c->get_parent()); + c = Object::cast_to<Node3D>(c->get_parent()); } - return TTR("NavigationRegion must be a child or grandchild to a Navigation node. It only provides navigation data."); + return TTR("NavigationRegion3D must be a child or grandchild to a Navigation3D node. It only provides navigation data."); } -void NavigationRegion::_bind_methods() { +void NavigationRegion3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_navigation_mesh", "navmesh"), &NavigationRegion::set_navigation_mesh); - ClassDB::bind_method(D_METHOD("get_navigation_mesh"), &NavigationRegion::get_navigation_mesh); + ClassDB::bind_method(D_METHOD("set_navigation_mesh", "navmesh"), &NavigationRegion3D::set_navigation_mesh); + ClassDB::bind_method(D_METHOD("get_navigation_mesh"), &NavigationRegion3D::get_navigation_mesh); - ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationRegion::set_enabled); - ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationRegion::is_enabled); + ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationRegion3D::set_enabled); + ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationRegion3D::is_enabled); - ClassDB::bind_method(D_METHOD("bake_navigation_mesh"), &NavigationRegion::bake_navigation_mesh); - ClassDB::bind_method(D_METHOD("_bake_finished", "nav_mesh"), &NavigationRegion::_bake_finished); + ClassDB::bind_method(D_METHOD("bake_navigation_mesh"), &NavigationRegion3D::bake_navigation_mesh); + ClassDB::bind_method(D_METHOD("_bake_finished", "nav_mesh"), &NavigationRegion3D::_bake_finished); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "navmesh", PROPERTY_HINT_RESOURCE_TYPE, "NavigationMesh"), "set_navigation_mesh", "get_navigation_mesh"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); @@ -235,24 +236,24 @@ void NavigationRegion::_bind_methods() { ADD_SIGNAL(MethodInfo("bake_finished")); } -void NavigationRegion::_changed_callback(Object *p_changed, const char *p_prop) { +void NavigationRegion3D::_changed_callback(Object *p_changed, const char *p_prop) { update_gizmo(); update_configuration_warning(); } -NavigationRegion::NavigationRegion() { +NavigationRegion3D::NavigationRegion3D() { enabled = true; set_notify_transform(true); - region = NavigationServer::get_singleton()->region_create(); + region = NavigationServer3D::get_singleton()->region_create(); - navigation = NULL; - debug_view = NULL; - bake_thread = NULL; + navigation = nullptr; + debug_view = nullptr; + bake_thread = nullptr; } -NavigationRegion::~NavigationRegion() { +NavigationRegion3D::~NavigationRegion3D() { if (navmesh.is_valid()) navmesh->remove_change_receptor(this); - NavigationServer::get_singleton()->free(region); + NavigationServer3D::get_singleton()->free(region); } diff --git a/scene/3d/navigation_region.h b/scene/3d/navigation_region_3d.h index f215e92c97..ae071e6b7a 100644 --- a/scene/3d/navigation_region.h +++ b/scene/3d/navigation_region_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_region.h */ +/* navigation_region_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,21 +31,21 @@ #ifndef NAVIGATION_REGION_H #define NAVIGATION_REGION_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" #include "scene/resources/mesh.h" #include "scene/resources/navigation_mesh.h" -class Navigation; +class Navigation3D; -class NavigationRegion : public Spatial { +class NavigationRegion3D : public Node3D { - GDCLASS(NavigationRegion, Spatial); + GDCLASS(NavigationRegion3D, Node3D); bool enabled; RID region; Ref<NavigationMesh> navmesh; - Navigation *navigation; + Navigation3D *navigation; Node *debug_view; Thread *bake_thread; @@ -68,8 +68,8 @@ public: String get_configuration_warning() const; - NavigationRegion(); - ~NavigationRegion(); + NavigationRegion3D(); + ~NavigationRegion3D(); }; #endif // NAVIGATION_REGION_H diff --git a/scene/3d/spatial.cpp b/scene/3d/node_3d.cpp index f1911348ce..0b7407e049 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/node_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* spatial.cpp */ +/* node_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,12 +28,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "spatial.h" +#include "node_3d.h" #include "core/engine.h" #include "core/message_queue.h" #include "scene/main/scene_tree.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" #include "scene/scene_string_names.h" /* @@ -70,10 +70,10 @@ future: no idea */ -SpatialGizmo::SpatialGizmo() { +Node3DGizmo::Node3DGizmo() { } -void Spatial::_notify_dirty() { +void Node3D::_notify_dirty() { #ifdef TOOLS_ENABLED if ((data.gizmo.is_valid() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) { @@ -85,12 +85,12 @@ void Spatial::_notify_dirty() { } } -void Spatial::_update_local_transform() const { +void Node3D::_update_local_transform() const { data.local_transform.basis.set_euler_scale(data.rotation, data.scale); data.dirty &= ~DIRTY_LOCAL; } -void Spatial::_propagate_transform_changed(Spatial *p_origin) { +void Node3D::_propagate_transform_changed(Node3D *p_origin) { if (!is_inside_tree()) { return; @@ -103,7 +103,7 @@ void Spatial::_propagate_transform_changed(Spatial *p_origin) { data.children_lock++; - for (List<Spatial *>::Element *E = data.children.front(); E; E = E->next()) { + for (List<Node3D *>::Element *E = data.children.front(); E; E = E->next()) { if (E->get()->data.toplevel_active) continue; //don't propagate to a toplevel @@ -121,7 +121,7 @@ void Spatial::_propagate_transform_changed(Spatial *p_origin) { data.children_lock--; } -void Spatial::_notification(int p_what) { +void Node3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { @@ -129,12 +129,12 @@ void Spatial::_notification(int p_what) { Node *p = get_parent(); if (p) - data.parent = Object::cast_to<Spatial>(p); + data.parent = Object::cast_to<Node3D>(p); if (data.parent) data.C = data.parent->data.children.push_back(this); else - data.C = NULL; + data.C = nullptr; if (data.toplevel && !Engine::get_singleton()->is_editor_hint()) { @@ -158,14 +158,14 @@ void Spatial::_notification(int p_what) { get_tree()->xform_change_list.remove(&xform_change); if (data.C) data.parent->data.children.erase(data.C); - data.parent = NULL; - data.C = NULL; + data.parent = nullptr; + data.C = nullptr; data.toplevel_active = false; } break; case NOTIFICATION_ENTER_WORLD: { data.inside_world = true; - data.viewport = NULL; + data.viewport = nullptr; Node *parent = get_parent(); while (parent && !data.viewport) { data.viewport = Object::cast_to<Viewport>(parent); @@ -176,7 +176,7 @@ void Spatial::_notification(int p_what) { if (get_script_instance()) { - get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_enter_world, NULL, 0); + get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_enter_world, nullptr, 0); } #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) { @@ -208,10 +208,10 @@ void Spatial::_notification(int p_what) { if (get_script_instance()) { - get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_world, NULL, 0); + get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_world, nullptr, 0); } - data.viewport = NULL; + data.viewport = nullptr; data.inside_world = false; } break; @@ -230,7 +230,7 @@ void Spatial::_notification(int p_what) { } } -void Spatial::set_transform(const Transform &p_transform) { +void Node3D::set_transform(const Transform &p_transform) { data.local_transform = p_transform; data.dirty |= DIRTY_VECTORS; @@ -244,7 +244,7 @@ void Spatial::set_transform(const Transform &p_transform) { } } -void Spatial::set_global_transform(const Transform &p_transform) { +void Node3D::set_global_transform(const Transform &p_transform) { Transform xform = (data.parent && !data.toplevel_active) ? @@ -254,7 +254,7 @@ void Spatial::set_global_transform(const Transform &p_transform) { set_transform(xform); } -Transform Spatial::get_transform() const { +Transform Node3D::get_transform() const { if (data.dirty & DIRTY_LOCAL) { @@ -263,7 +263,7 @@ Transform Spatial::get_transform() const { return data.local_transform; } -Transform Spatial::get_global_transform() const { +Transform Node3D::get_global_transform() const { ERR_FAIL_COND_V(!is_inside_tree(), Transform()); @@ -293,21 +293,21 @@ Transform Spatial::get_global_transform() const { } #ifdef TOOLS_ENABLED -Transform Spatial::get_global_gizmo_transform() const { +Transform Node3D::get_global_gizmo_transform() const { return get_global_transform(); } -Transform Spatial::get_local_gizmo_transform() const { +Transform Node3D::get_local_gizmo_transform() const { return get_transform(); } #endif -Spatial *Spatial::get_parent_spatial() const { +Node3D *Node3D::get_parent_spatial() const { return data.parent; } -Transform Spatial::get_relative_transform(const Node *p_parent) const { +Transform Node3D::get_relative_transform(const Node *p_parent) const { if (p_parent == this) return Transform(); @@ -320,7 +320,7 @@ Transform Spatial::get_relative_transform(const Node *p_parent) const { return data.parent->get_relative_transform(p_parent) * get_transform(); } -void Spatial::set_translation(const Vector3 &p_translation) { +void Node3D::set_translation(const Vector3 &p_translation) { data.local_transform.origin = p_translation; _change_notify("transform"); @@ -330,7 +330,7 @@ void Spatial::set_translation(const Vector3 &p_translation) { } } -void Spatial::set_rotation(const Vector3 &p_euler_rad) { +void Node3D::set_rotation(const Vector3 &p_euler_rad) { if (data.dirty & DIRTY_VECTORS) { data.scale = data.local_transform.basis.get_scale(); @@ -346,12 +346,12 @@ void Spatial::set_rotation(const Vector3 &p_euler_rad) { } } -void Spatial::set_rotation_degrees(const Vector3 &p_euler_deg) { +void Node3D::set_rotation_degrees(const Vector3 &p_euler_deg) { set_rotation(p_euler_deg * Math_PI / 180.0); } -void Spatial::set_scale(const Vector3 &p_scale) { +void Node3D::set_scale(const Vector3 &p_scale) { if (data.dirty & DIRTY_VECTORS) { data.rotation = data.local_transform.basis.get_rotation(); @@ -367,12 +367,12 @@ void Spatial::set_scale(const Vector3 &p_scale) { } } -Vector3 Spatial::get_translation() const { +Vector3 Node3D::get_translation() const { return data.local_transform.origin; } -Vector3 Spatial::get_rotation() const { +Vector3 Node3D::get_rotation() const { if (data.dirty & DIRTY_VECTORS) { data.scale = data.local_transform.basis.get_scale(); @@ -384,12 +384,12 @@ Vector3 Spatial::get_rotation() const { return data.rotation; } -Vector3 Spatial::get_rotation_degrees() const { +Vector3 Node3D::get_rotation_degrees() const { return get_rotation() * 180.0 / Math_PI; } -Vector3 Spatial::get_scale() const { +Vector3 Node3D::get_scale() const { if (data.dirty & DIRTY_VECTORS) { data.scale = data.local_transform.basis.get_scale(); @@ -401,7 +401,7 @@ Vector3 Spatial::get_scale() const { return data.scale; } -void Spatial::update_gizmo() { +void Node3D::update_gizmo() { #ifdef TOOLS_ENABLED if (!is_inside_world()) @@ -417,7 +417,7 @@ void Spatial::update_gizmo() { #endif } -void Spatial::set_gizmo(const Ref<SpatialGizmo> &p_gizmo) { +void Node3D::set_gizmo(const Ref<Node3DGizmo> &p_gizmo) { #ifdef TOOLS_ENABLED @@ -438,18 +438,18 @@ void Spatial::set_gizmo(const Ref<SpatialGizmo> &p_gizmo) { #endif } -Ref<SpatialGizmo> Spatial::get_gizmo() const { +Ref<Node3DGizmo> Node3D::get_gizmo() const { #ifdef TOOLS_ENABLED return data.gizmo; #else - return Ref<SpatialGizmo>(); + return Ref<Node3DGizmo>(); #endif } -void Spatial::_update_gizmo() { +void Node3D::_update_gizmo() { #ifdef TOOLS_ENABLED if (!is_inside_world()) @@ -465,25 +465,25 @@ void Spatial::_update_gizmo() { } #ifdef TOOLS_ENABLED -void Spatial::set_disable_gizmo(bool p_enabled) { +void Node3D::set_disable_gizmo(bool p_enabled) { data.gizmo_disabled = p_enabled; if (!p_enabled && data.gizmo.is_valid()) - data.gizmo = Ref<SpatialGizmo>(); + data.gizmo = Ref<Node3DGizmo>(); } #endif -void Spatial::set_disable_scale(bool p_enabled) { +void Node3D::set_disable_scale(bool p_enabled) { data.disable_scale = p_enabled; } -bool Spatial::is_scale_disabled() const { +bool Node3D::is_scale_disabled() const { return data.disable_scale; } -void Spatial::set_as_toplevel(bool p_enabled) { +void Node3D::set_as_toplevel(bool p_enabled) { if (data.toplevel == p_enabled) return; @@ -502,20 +502,20 @@ void Spatial::set_as_toplevel(bool p_enabled) { } } -bool Spatial::is_set_as_toplevel() const { +bool Node3D::is_set_as_toplevel() const { return data.toplevel; } -Ref<World> Spatial::get_world() const { +Ref<World3D> Node3D::get_world() const { - ERR_FAIL_COND_V(!is_inside_world(), Ref<World>()); - ERR_FAIL_COND_V(!data.viewport, Ref<World>()); + ERR_FAIL_COND_V(!is_inside_world(), Ref<World3D>()); + ERR_FAIL_COND_V(!data.viewport, Ref<World3D>()); return data.viewport->find_world(); } -void Spatial::_propagate_visibility_changed() { +void Node3D::_propagate_visibility_changed() { notification(NOTIFICATION_VISIBILITY_CHANGED); emit_signal(SceneStringNames::get_singleton()->visibility_changed); @@ -525,16 +525,16 @@ void Spatial::_propagate_visibility_changed() { _update_gizmo(); #endif - for (List<Spatial *>::Element *E = data.children.front(); E; E = E->next()) { + for (List<Node3D *>::Element *E = data.children.front(); E; E = E->next()) { - Spatial *c = E->get(); + Node3D *c = E->get(); if (!c || !c->data.visible) continue; c->_propagate_visibility_changed(); } } -void Spatial::show() { +void Node3D::show() { if (data.visible) return; @@ -547,7 +547,7 @@ void Spatial::show() { _propagate_visibility_changed(); } -void Spatial::hide() { +void Node3D::hide() { if (!data.visible) return; @@ -560,9 +560,9 @@ void Spatial::hide() { _propagate_visibility_changed(); } -bool Spatial::is_visible_in_tree() const { +bool Node3D::is_visible_in_tree() const { - const Spatial *s = this; + const Node3D *s = this; while (s) { if (!s->data.visible) { @@ -574,7 +574,7 @@ bool Spatial::is_visible_in_tree() const { return true; } -void Spatial::set_visible(bool p_visible) { +void Node3D::set_visible(bool p_visible) { if (p_visible) show(); @@ -582,52 +582,52 @@ void Spatial::set_visible(bool p_visible) { hide(); } -bool Spatial::is_visible() const { +bool Node3D::is_visible() const { return data.visible; } -void Spatial::rotate_object_local(const Vector3 &p_axis, float p_angle) { +void Node3D::rotate_object_local(const Vector3 &p_axis, float p_angle) { Transform t = get_transform(); t.basis.rotate_local(p_axis, p_angle); set_transform(t); } -void Spatial::rotate(const Vector3 &p_axis, float p_angle) { +void Node3D::rotate(const Vector3 &p_axis, float p_angle) { Transform t = get_transform(); t.basis.rotate(p_axis, p_angle); set_transform(t); } -void Spatial::rotate_x(float p_angle) { +void Node3D::rotate_x(float p_angle) { Transform t = get_transform(); t.basis.rotate(Vector3(1, 0, 0), p_angle); set_transform(t); } -void Spatial::rotate_y(float p_angle) { +void Node3D::rotate_y(float p_angle) { Transform t = get_transform(); t.basis.rotate(Vector3(0, 1, 0), p_angle); set_transform(t); } -void Spatial::rotate_z(float p_angle) { +void Node3D::rotate_z(float p_angle) { Transform t = get_transform(); t.basis.rotate(Vector3(0, 0, 1), p_angle); set_transform(t); } -void Spatial::translate(const Vector3 &p_offset) { +void Node3D::translate(const Vector3 &p_offset) { Transform t = get_transform(); t.translate(p_offset); set_transform(t); } -void Spatial::translate_object_local(const Vector3 &p_offset) { +void Node3D::translate_object_local(const Vector3 &p_offset) { Transform t = get_transform(); Transform s; @@ -635,58 +635,58 @@ void Spatial::translate_object_local(const Vector3 &p_offset) { set_transform(t * s); } -void Spatial::scale(const Vector3 &p_ratio) { +void Node3D::scale(const Vector3 &p_ratio) { Transform t = get_transform(); t.basis.scale(p_ratio); set_transform(t); } -void Spatial::scale_object_local(const Vector3 &p_scale) { +void Node3D::scale_object_local(const Vector3 &p_scale) { Transform t = get_transform(); t.basis.scale_local(p_scale); set_transform(t); } -void Spatial::global_rotate(const Vector3 &p_axis, float p_angle) { +void Node3D::global_rotate(const Vector3 &p_axis, float p_angle) { Transform t = get_global_transform(); t.basis.rotate(p_axis, p_angle); set_global_transform(t); } -void Spatial::global_scale(const Vector3 &p_scale) { +void Node3D::global_scale(const Vector3 &p_scale) { Transform t = get_global_transform(); t.basis.scale(p_scale); set_global_transform(t); } -void Spatial::global_translate(const Vector3 &p_offset) { +void Node3D::global_translate(const Vector3 &p_offset) { Transform t = get_global_transform(); t.origin += p_offset; set_global_transform(t); } -void Spatial::orthonormalize() { +void Node3D::orthonormalize() { Transform t = get_transform(); t.orthonormalize(); set_transform(t); } -void Spatial::set_identity() { +void Node3D::set_identity() { set_transform(Transform()); } -void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up) { +void Node3D::look_at(const Vector3 &p_target, const Vector3 &p_up) { Vector3 origin(get_global_transform().origin); look_at_from_position(origin, p_target, p_up); } -void Spatial::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up) { +void Node3D::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up) { ERR_FAIL_COND_MSG(p_pos == p_target, "Node origin and target are in the same position, look_at() failed."); ERR_FAIL_COND_MSG(p_up.cross(p_target - p_pos) == Vector3(), "Up vector and direction between node origin and target are aligned, look_at() failed."); @@ -700,33 +700,33 @@ void Spatial::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_targe set_scale(original_scale); } -Vector3 Spatial::to_local(Vector3 p_global) const { +Vector3 Node3D::to_local(Vector3 p_global) const { return get_global_transform().affine_inverse().xform(p_global); } -Vector3 Spatial::to_global(Vector3 p_local) const { +Vector3 Node3D::to_global(Vector3 p_local) const { return get_global_transform().xform(p_local); } -void Spatial::set_notify_transform(bool p_enable) { +void Node3D::set_notify_transform(bool p_enable) { data.notify_transform = p_enable; } -bool Spatial::is_transform_notification_enabled() const { +bool Node3D::is_transform_notification_enabled() const { return data.notify_transform; } -void Spatial::set_notify_local_transform(bool p_enable) { +void Node3D::set_notify_local_transform(bool p_enable) { data.notify_local_transform = p_enable; } -bool Spatial::is_local_transform_notification_enabled() const { +bool Node3D::is_local_transform_notification_enabled() const { return data.notify_local_transform; } -void Spatial::force_update_transform() { +void Node3D::force_update_transform() { ERR_FAIL_COND(!is_inside_tree()); if (!xform_change.in_list()) { return; //nothing to update @@ -736,67 +736,67 @@ void Spatial::force_update_transform() { notification(NOTIFICATION_TRANSFORM_CHANGED); } -void Spatial::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_transform", "local"), &Spatial::set_transform); - ClassDB::bind_method(D_METHOD("get_transform"), &Spatial::get_transform); - ClassDB::bind_method(D_METHOD("set_translation", "translation"), &Spatial::set_translation); - ClassDB::bind_method(D_METHOD("get_translation"), &Spatial::get_translation); - ClassDB::bind_method(D_METHOD("set_rotation", "euler"), &Spatial::set_rotation); - ClassDB::bind_method(D_METHOD("get_rotation"), &Spatial::get_rotation); - ClassDB::bind_method(D_METHOD("set_rotation_degrees", "euler_degrees"), &Spatial::set_rotation_degrees); - ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Spatial::get_rotation_degrees); - ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Spatial::set_scale); - ClassDB::bind_method(D_METHOD("get_scale"), &Spatial::get_scale); - ClassDB::bind_method(D_METHOD("set_global_transform", "global"), &Spatial::set_global_transform); - ClassDB::bind_method(D_METHOD("get_global_transform"), &Spatial::get_global_transform); - ClassDB::bind_method(D_METHOD("get_parent_spatial"), &Spatial::get_parent_spatial); - ClassDB::bind_method(D_METHOD("set_ignore_transform_notification", "enabled"), &Spatial::set_ignore_transform_notification); - ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &Spatial::set_as_toplevel); - ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &Spatial::is_set_as_toplevel); - ClassDB::bind_method(D_METHOD("set_disable_scale", "disable"), &Spatial::set_disable_scale); - ClassDB::bind_method(D_METHOD("is_scale_disabled"), &Spatial::is_scale_disabled); - ClassDB::bind_method(D_METHOD("get_world"), &Spatial::get_world); - - ClassDB::bind_method(D_METHOD("force_update_transform"), &Spatial::force_update_transform); - - ClassDB::bind_method(D_METHOD("_update_gizmo"), &Spatial::_update_gizmo); - - ClassDB::bind_method(D_METHOD("update_gizmo"), &Spatial::update_gizmo); - ClassDB::bind_method(D_METHOD("set_gizmo", "gizmo"), &Spatial::set_gizmo); - ClassDB::bind_method(D_METHOD("get_gizmo"), &Spatial::get_gizmo); - - ClassDB::bind_method(D_METHOD("set_visible", "visible"), &Spatial::set_visible); - ClassDB::bind_method(D_METHOD("is_visible"), &Spatial::is_visible); - ClassDB::bind_method(D_METHOD("is_visible_in_tree"), &Spatial::is_visible_in_tree); - ClassDB::bind_method(D_METHOD("show"), &Spatial::show); - ClassDB::bind_method(D_METHOD("hide"), &Spatial::hide); - - ClassDB::bind_method(D_METHOD("set_notify_local_transform", "enable"), &Spatial::set_notify_local_transform); - ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"), &Spatial::is_local_transform_notification_enabled); - - ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &Spatial::set_notify_transform); - ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &Spatial::is_transform_notification_enabled); - - ClassDB::bind_method(D_METHOD("rotate", "axis", "angle"), &Spatial::rotate); - ClassDB::bind_method(D_METHOD("global_rotate", "axis", "angle"), &Spatial::global_rotate); - ClassDB::bind_method(D_METHOD("global_scale", "scale"), &Spatial::global_scale); - ClassDB::bind_method(D_METHOD("global_translate", "offset"), &Spatial::global_translate); - ClassDB::bind_method(D_METHOD("rotate_object_local", "axis", "angle"), &Spatial::rotate_object_local); - ClassDB::bind_method(D_METHOD("scale_object_local", "scale"), &Spatial::scale_object_local); - ClassDB::bind_method(D_METHOD("translate_object_local", "offset"), &Spatial::translate_object_local); - ClassDB::bind_method(D_METHOD("rotate_x", "angle"), &Spatial::rotate_x); - ClassDB::bind_method(D_METHOD("rotate_y", "angle"), &Spatial::rotate_y); - ClassDB::bind_method(D_METHOD("rotate_z", "angle"), &Spatial::rotate_z); - ClassDB::bind_method(D_METHOD("translate", "offset"), &Spatial::translate); - ClassDB::bind_method(D_METHOD("orthonormalize"), &Spatial::orthonormalize); - ClassDB::bind_method(D_METHOD("set_identity"), &Spatial::set_identity); - - ClassDB::bind_method(D_METHOD("look_at", "target", "up"), &Spatial::look_at); - ClassDB::bind_method(D_METHOD("look_at_from_position", "position", "target", "up"), &Spatial::look_at_from_position); - - ClassDB::bind_method(D_METHOD("to_local", "global_point"), &Spatial::to_local); - ClassDB::bind_method(D_METHOD("to_global", "local_point"), &Spatial::to_global); +void Node3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_transform", "local"), &Node3D::set_transform); + ClassDB::bind_method(D_METHOD("get_transform"), &Node3D::get_transform); + ClassDB::bind_method(D_METHOD("set_translation", "translation"), &Node3D::set_translation); + ClassDB::bind_method(D_METHOD("get_translation"), &Node3D::get_translation); + ClassDB::bind_method(D_METHOD("set_rotation", "euler"), &Node3D::set_rotation); + ClassDB::bind_method(D_METHOD("get_rotation"), &Node3D::get_rotation); + ClassDB::bind_method(D_METHOD("set_rotation_degrees", "euler_degrees"), &Node3D::set_rotation_degrees); + ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Node3D::get_rotation_degrees); + ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Node3D::set_scale); + ClassDB::bind_method(D_METHOD("get_scale"), &Node3D::get_scale); + ClassDB::bind_method(D_METHOD("set_global_transform", "global"), &Node3D::set_global_transform); + ClassDB::bind_method(D_METHOD("get_global_transform"), &Node3D::get_global_transform); + ClassDB::bind_method(D_METHOD("get_parent_spatial"), &Node3D::get_parent_spatial); + ClassDB::bind_method(D_METHOD("set_ignore_transform_notification", "enabled"), &Node3D::set_ignore_transform_notification); + ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &Node3D::set_as_toplevel); + ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &Node3D::is_set_as_toplevel); + ClassDB::bind_method(D_METHOD("set_disable_scale", "disable"), &Node3D::set_disable_scale); + ClassDB::bind_method(D_METHOD("is_scale_disabled"), &Node3D::is_scale_disabled); + ClassDB::bind_method(D_METHOD("get_world"), &Node3D::get_world); + + ClassDB::bind_method(D_METHOD("force_update_transform"), &Node3D::force_update_transform); + + ClassDB::bind_method(D_METHOD("_update_gizmo"), &Node3D::_update_gizmo); + + ClassDB::bind_method(D_METHOD("update_gizmo"), &Node3D::update_gizmo); + ClassDB::bind_method(D_METHOD("set_gizmo", "gizmo"), &Node3D::set_gizmo); + ClassDB::bind_method(D_METHOD("get_gizmo"), &Node3D::get_gizmo); + + ClassDB::bind_method(D_METHOD("set_visible", "visible"), &Node3D::set_visible); + ClassDB::bind_method(D_METHOD("is_visible"), &Node3D::is_visible); + ClassDB::bind_method(D_METHOD("is_visible_in_tree"), &Node3D::is_visible_in_tree); + ClassDB::bind_method(D_METHOD("show"), &Node3D::show); + ClassDB::bind_method(D_METHOD("hide"), &Node3D::hide); + + ClassDB::bind_method(D_METHOD("set_notify_local_transform", "enable"), &Node3D::set_notify_local_transform); + ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"), &Node3D::is_local_transform_notification_enabled); + + ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &Node3D::set_notify_transform); + ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &Node3D::is_transform_notification_enabled); + + ClassDB::bind_method(D_METHOD("rotate", "axis", "angle"), &Node3D::rotate); + ClassDB::bind_method(D_METHOD("global_rotate", "axis", "angle"), &Node3D::global_rotate); + ClassDB::bind_method(D_METHOD("global_scale", "scale"), &Node3D::global_scale); + ClassDB::bind_method(D_METHOD("global_translate", "offset"), &Node3D::global_translate); + ClassDB::bind_method(D_METHOD("rotate_object_local", "axis", "angle"), &Node3D::rotate_object_local); + ClassDB::bind_method(D_METHOD("scale_object_local", "scale"), &Node3D::scale_object_local); + ClassDB::bind_method(D_METHOD("translate_object_local", "offset"), &Node3D::translate_object_local); + ClassDB::bind_method(D_METHOD("rotate_x", "angle"), &Node3D::rotate_x); + ClassDB::bind_method(D_METHOD("rotate_y", "angle"), &Node3D::rotate_y); + ClassDB::bind_method(D_METHOD("rotate_z", "angle"), &Node3D::rotate_z); + ClassDB::bind_method(D_METHOD("translate", "offset"), &Node3D::translate); + ClassDB::bind_method(D_METHOD("orthonormalize"), &Node3D::orthonormalize); + ClassDB::bind_method(D_METHOD("set_identity"), &Node3D::set_identity); + + ClassDB::bind_method(D_METHOD("look_at", "target", "up"), &Node3D::look_at); + ClassDB::bind_method(D_METHOD("look_at_from_position", "position", "target", "up"), &Node3D::look_at_from_position); + + ClassDB::bind_method(D_METHOD("to_local", "global_point"), &Node3D::to_local); + ClassDB::bind_method(D_METHOD("to_global", "local_point"), &Node3D::to_global); BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED); BIND_CONSTANT(NOTIFICATION_ENTER_WORLD); @@ -814,12 +814,12 @@ void Spatial::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform", PROPERTY_HINT_NONE, ""), "set_transform", "get_transform"); ADD_GROUP("Visibility", ""); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "SpatialGizmo", 0), "set_gizmo", "get_gizmo"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "Node3DGizmo", 0), "set_gizmo", "get_gizmo"); ADD_SIGNAL(MethodInfo("visibility_changed")); } -Spatial::Spatial() : +Node3D::Node3D() : xform_change(this) { data.dirty = DIRTY_NONE; @@ -829,7 +829,7 @@ Spatial::Spatial() : data.toplevel = false; data.toplevel_active = false; data.scale = Vector3(1, 1, 1); - data.viewport = NULL; + data.viewport = nullptr; data.inside_world = false; data.visible = true; data.disable_scale = false; @@ -840,9 +840,9 @@ Spatial::Spatial() : #endif data.notify_local_transform = false; data.notify_transform = false; - data.parent = NULL; - data.C = NULL; + data.parent = nullptr; + data.C = nullptr; } -Spatial::~Spatial() { +Node3D::~Node3D() { } diff --git a/scene/3d/spatial.h b/scene/3d/node_3d.h index 9d4705700b..f97a8a97dc 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/node_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* spatial.h */ +/* node_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef SPATIAL_H -#define SPATIAL_H +#ifndef NODE_3D_H +#define NODE_3D_H #include "scene/main/node.h" #include "scene/main/scene_tree.h" -class SpatialGizmo : public Reference { +class Node3DGizmo : public Reference { - GDCLASS(SpatialGizmo, Reference); + GDCLASS(Node3DGizmo, Reference); public: virtual void create() = 0; @@ -45,13 +45,13 @@ public: virtual void redraw() = 0; virtual void free() = 0; - SpatialGizmo(); - virtual ~SpatialGizmo() {} + Node3DGizmo(); + virtual ~Node3DGizmo() {} }; -class Spatial : public Node { +class Node3D : public Node { - GDCLASS(Spatial, Node); + GDCLASS(Node3D, Node); OBJ_CATEGORY("3D"); enum TransformDirty { @@ -79,9 +79,9 @@ class Spatial : public Node { bool inside_world; int children_lock; - Spatial *parent; - List<Spatial *> children; - List<Spatial *>::Element *C; + Node3D *parent; + List<Node3D *> children; + List<Node3D *>::Element *C; bool ignore_notification; bool notify_local_transform; @@ -91,7 +91,7 @@ class Spatial : public Node { bool disable_scale; #ifdef TOOLS_ENABLED - Ref<SpatialGizmo> gizmo; + Ref<Node3DGizmo> gizmo; bool gizmo_disabled; bool gizmo_dirty; #endif @@ -100,7 +100,7 @@ class Spatial : public Node { void _update_gizmo(); void _notify_dirty(); - void _propagate_transform_changed(Spatial *p_origin); + void _propagate_transform_changed(Node3D *p_origin); void _propagate_visibility_changed(); @@ -122,9 +122,9 @@ public: NOTIFICATION_LOCAL_TRANSFORM_CHANGED = 44, }; - Spatial *get_parent_spatial() const; + Node3D *get_parent_spatial() const; - Ref<World> get_world() const; + Ref<World3D> get_world() const; void set_translation(const Vector3 &p_translation); void set_rotation(const Vector3 &p_euler_rad); @@ -155,8 +155,8 @@ public: void set_disable_gizmo(bool p_enabled); void update_gizmo(); - void set_gizmo(const Ref<SpatialGizmo> &p_gizmo); - Ref<SpatialGizmo> get_gizmo() const; + void set_gizmo(const Ref<Node3DGizmo> &p_gizmo); + Ref<Node3DGizmo> get_gizmo() const; _FORCE_INLINE_ bool is_inside_world() const { return data.inside_world; } @@ -200,8 +200,8 @@ public: void force_update_transform(); - Spatial(); - ~Spatial(); + Node3D(); + ~Node3D(); }; -#endif +#endif // NODE_3D_H diff --git a/scene/3d/path.cpp b/scene/3d/path_3d.cpp index f93485d79f..4a425d1e0e 100644 --- a/scene/3d/path.cpp +++ b/scene/3d/path_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* path.cpp */ +/* path_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "path.h" +#include "path_3d.h" #include "core/engine.h" #include "scene/scene_string_names.h" -void Path::_notification(int p_what) { +void Path3D::_notification(int p_what) { } -void Path::_curve_changed() { +void Path3D::_curve_changed() { if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) update_gizmo(); @@ -48,7 +48,7 @@ void Path::_curve_changed() { // previously used for PathFollowOriented (now enforced orientation is done in PathFollow) if (is_inside_tree()) { for (int i = 0; i < get_child_count(); i++) { - PathFollow *child = Object::cast_to<PathFollow>(get_child(i)); + PathFollow3D *child = Object::cast_to<PathFollow3D>(get_child(i)); if (child) { child->update_configuration_warning(); } @@ -56,43 +56,43 @@ void Path::_curve_changed() { } } -void Path::set_curve(const Ref<Curve3D> &p_curve) { +void Path3D::set_curve(const Ref<Curve3D> &p_curve) { if (curve.is_valid()) { - curve->disconnect("changed", callable_mp(this, &Path::_curve_changed)); + curve->disconnect("changed", callable_mp(this, &Path3D::_curve_changed)); } curve = p_curve; if (curve.is_valid()) { - curve->connect("changed", callable_mp(this, &Path::_curve_changed)); + curve->connect("changed", callable_mp(this, &Path3D::_curve_changed)); } _curve_changed(); } -Ref<Curve3D> Path::get_curve() const { +Ref<Curve3D> Path3D::get_curve() const { return curve; } -void Path::_bind_methods() { +void Path3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_curve", "curve"), &Path::set_curve); - ClassDB::bind_method(D_METHOD("get_curve"), &Path::get_curve); + ClassDB::bind_method(D_METHOD("set_curve", "curve"), &Path3D::set_curve); + ClassDB::bind_method(D_METHOD("get_curve"), &Path3D::get_curve); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve3D"), "set_curve", "get_curve"); ADD_SIGNAL(MethodInfo("curve_changed")); } -Path::Path() { +Path3D::Path3D() { set_curve(Ref<Curve3D>(memnew(Curve3D))); //create one by default } ////////////// -void PathFollow::_update_transform() { +void PathFollow3D::_update_transform() { if (!path) return; @@ -212,7 +212,7 @@ void PathFollow::_update_transform() { set_transform(t); } -void PathFollow::_notification(int p_what) { +void PathFollow3D::_notification(int p_what) { switch (p_what) { @@ -220,7 +220,7 @@ void PathFollow::_notification(int p_what) { Node *parent = get_parent(); if (parent) { - path = Object::cast_to<Path>(parent); + path = Object::cast_to<Path3D>(parent); if (path) { _update_transform(); } @@ -229,22 +229,22 @@ void PathFollow::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { - path = NULL; + path = nullptr; } break; } } -void PathFollow::set_cubic_interpolation(bool p_enable) { +void PathFollow3D::set_cubic_interpolation(bool p_enable) { cubic = p_enable; } -bool PathFollow::get_cubic_interpolation() const { +bool PathFollow3D::get_cubic_interpolation() const { return cubic; } -void PathFollow::_validate_property(PropertyInfo &property) const { +void PathFollow3D::_validate_property(PropertyInfo &property) const { if (property.name == "offset") { @@ -256,45 +256,45 @@ void PathFollow::_validate_property(PropertyInfo &property) const { } } -String PathFollow::get_configuration_warning() const { +String PathFollow3D::get_configuration_warning() const { if (!is_visible_in_tree() || !is_inside_tree()) return String(); - if (!Object::cast_to<Path>(get_parent())) { - return TTR("PathFollow only works when set as a child of a Path node."); + if (!Object::cast_to<Path3D>(get_parent())) { + return TTR("PathFollow3D only works when set as a child of a Path3D node."); } else { - Path *path = Object::cast_to<Path>(get_parent()); + Path3D *path = Object::cast_to<Path3D>(get_parent()); if (path->get_curve().is_valid() && !path->get_curve()->is_up_vector_enabled() && rotation_mode == ROTATION_ORIENTED) { - return TTR("PathFollow's ROTATION_ORIENTED requires \"Up Vector\" to be enabled in its parent Path's Curve resource."); + return TTR("PathFollow3D's ROTATION_ORIENTED requires \"Up Vector\" to be enabled in its parent Path3D's Curve resource."); } } return String(); } -void PathFollow::_bind_methods() { +void PathFollow3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_offset", "offset"), &PathFollow::set_offset); - ClassDB::bind_method(D_METHOD("get_offset"), &PathFollow::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "offset"), &PathFollow3D::set_offset); + ClassDB::bind_method(D_METHOD("get_offset"), &PathFollow3D::get_offset); - ClassDB::bind_method(D_METHOD("set_h_offset", "h_offset"), &PathFollow::set_h_offset); - ClassDB::bind_method(D_METHOD("get_h_offset"), &PathFollow::get_h_offset); + ClassDB::bind_method(D_METHOD("set_h_offset", "h_offset"), &PathFollow3D::set_h_offset); + ClassDB::bind_method(D_METHOD("get_h_offset"), &PathFollow3D::get_h_offset); - ClassDB::bind_method(D_METHOD("set_v_offset", "v_offset"), &PathFollow::set_v_offset); - ClassDB::bind_method(D_METHOD("get_v_offset"), &PathFollow::get_v_offset); + ClassDB::bind_method(D_METHOD("set_v_offset", "v_offset"), &PathFollow3D::set_v_offset); + ClassDB::bind_method(D_METHOD("get_v_offset"), &PathFollow3D::get_v_offset); - ClassDB::bind_method(D_METHOD("set_unit_offset", "unit_offset"), &PathFollow::set_unit_offset); - ClassDB::bind_method(D_METHOD("get_unit_offset"), &PathFollow::get_unit_offset); + ClassDB::bind_method(D_METHOD("set_unit_offset", "unit_offset"), &PathFollow3D::set_unit_offset); + ClassDB::bind_method(D_METHOD("get_unit_offset"), &PathFollow3D::get_unit_offset); - ClassDB::bind_method(D_METHOD("set_rotation_mode", "rotation_mode"), &PathFollow::set_rotation_mode); - ClassDB::bind_method(D_METHOD("get_rotation_mode"), &PathFollow::get_rotation_mode); + ClassDB::bind_method(D_METHOD("set_rotation_mode", "rotation_mode"), &PathFollow3D::set_rotation_mode); + ClassDB::bind_method(D_METHOD("get_rotation_mode"), &PathFollow3D::get_rotation_mode); - ClassDB::bind_method(D_METHOD("set_cubic_interpolation", "enable"), &PathFollow::set_cubic_interpolation); - ClassDB::bind_method(D_METHOD("get_cubic_interpolation"), &PathFollow::get_cubic_interpolation); + ClassDB::bind_method(D_METHOD("set_cubic_interpolation", "enable"), &PathFollow3D::set_cubic_interpolation); + ClassDB::bind_method(D_METHOD("get_cubic_interpolation"), &PathFollow3D::get_cubic_interpolation); - ClassDB::bind_method(D_METHOD("set_loop", "loop"), &PathFollow::set_loop); - ClassDB::bind_method(D_METHOD("has_loop"), &PathFollow::has_loop); + ClassDB::bind_method(D_METHOD("set_loop", "loop"), &PathFollow3D::set_loop); + ClassDB::bind_method(D_METHOD("has_loop"), &PathFollow3D::has_loop); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "offset", PROPERTY_HINT_RANGE, "0,10000,0.01,or_lesser,or_greater"), "set_offset", "get_offset"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "unit_offset", PROPERTY_HINT_RANGE, "0,1,0.0001,or_lesser,or_greater", PROPERTY_USAGE_EDITOR), "set_unit_offset", "get_unit_offset"); @@ -311,21 +311,19 @@ void PathFollow::_bind_methods() { BIND_ENUM_CONSTANT(ROTATION_ORIENTED); } -void PathFollow::set_offset(float p_offset) { +void PathFollow3D::set_offset(float p_offset) { delta_offset = p_offset - 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); } @@ -337,42 +335,42 @@ void PathFollow::set_offset(float p_offset) { _change_notify("unit_offset"); } -void PathFollow::set_h_offset(float p_h_offset) { +void PathFollow3D::set_h_offset(float p_h_offset) { h_offset = p_h_offset; if (path) _update_transform(); } -float PathFollow::get_h_offset() const { +float PathFollow3D::get_h_offset() const { return h_offset; } -void PathFollow::set_v_offset(float p_v_offset) { +void PathFollow3D::set_v_offset(float p_v_offset) { v_offset = p_v_offset; if (path) _update_transform(); } -float PathFollow::get_v_offset() const { +float PathFollow3D::get_v_offset() const { return v_offset; } -float PathFollow::get_offset() const { +float PathFollow3D::get_offset() const { return offset; } -void PathFollow::set_unit_offset(float p_unit_offset) { +void PathFollow3D::set_unit_offset(float p_unit_offset) { if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) set_offset(p_unit_offset * path->get_curve()->get_baked_length()); } -float PathFollow::get_unit_offset() const { +float PathFollow3D::get_unit_offset() const { if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) return get_offset() / path->get_curve()->get_baked_length(); @@ -380,7 +378,7 @@ float PathFollow::get_unit_offset() const { return 0; } -void PathFollow::set_rotation_mode(RotationMode p_rotation_mode) { +void PathFollow3D::set_rotation_mode(RotationMode p_rotation_mode) { rotation_mode = p_rotation_mode; @@ -388,28 +386,28 @@ void PathFollow::set_rotation_mode(RotationMode p_rotation_mode) { _update_transform(); } -PathFollow::RotationMode PathFollow::get_rotation_mode() const { +PathFollow3D::RotationMode PathFollow3D::get_rotation_mode() const { return rotation_mode; } -void PathFollow::set_loop(bool p_loop) { +void PathFollow3D::set_loop(bool p_loop) { loop = p_loop; } -bool PathFollow::has_loop() const { +bool PathFollow3D::has_loop() const { return loop; } -PathFollow::PathFollow() { +PathFollow3D::PathFollow3D() { offset = 0; delta_offset = 0; h_offset = 0; v_offset = 0; - path = NULL; + path = nullptr; rotation_mode = ROTATION_XYZ; cubic = true; loop = true; diff --git a/scene/3d/path.h b/scene/3d/path_3d.h index 497913b925..6f0db8c5c2 100644 --- a/scene/3d/path.h +++ b/scene/3d/path_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* path.h */ +/* path_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,12 +31,12 @@ #ifndef PATH_H #define PATH_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" #include "scene/resources/curve.h" -class Path : public Spatial { +class Path3D : public Node3D { - GDCLASS(Path, Spatial); + GDCLASS(Path3D, Node3D); Ref<Curve3D> curve; @@ -50,12 +50,12 @@ public: void set_curve(const Ref<Curve3D> &p_curve); Ref<Curve3D> get_curve() const; - Path(); + Path3D(); }; -class PathFollow : public Spatial { +class PathFollow3D : public Node3D { - GDCLASS(PathFollow, Spatial); + GDCLASS(PathFollow3D, Node3D); public: enum RotationMode { @@ -68,7 +68,7 @@ public: }; private: - Path *path; + Path3D *path; real_t delta_offset; // change in offset since last _update_transform real_t offset; real_t h_offset; @@ -109,9 +109,9 @@ public: String get_configuration_warning() const; - PathFollow(); + PathFollow3D(); }; -VARIANT_ENUM_CAST(PathFollow::RotationMode); +VARIANT_ENUM_CAST(PathFollow3D::RotationMode); #endif // PATH_H diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body_3d.cpp index 2f8dc31cb6..3991efc7c0 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* physics_body.cpp */ +/* physics_body_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "physics_body.h" +#include "physics_body_3d.h" #include "core/core_string_names.h" #include "core/engine.h" @@ -36,51 +36,51 @@ #include "core/method_bind_ext.gen.inc" #include "core/object.h" #include "core/rid.h" -#include "scene/3d/collision_shape.h" +#include "scene/3d/collision_shape_3d.h" #include "scene/scene_string_names.h" -#include "servers/navigation_server.h" +#include "servers/navigation_server_3d.h" #ifdef TOOLS_ENABLED -#include "editor/plugins/spatial_editor_plugin.h" +#include "editor/plugins/node_3d_editor_plugin.h" #endif -Vector3 PhysicsBody::get_linear_velocity() const { +Vector3 PhysicsBody3D::get_linear_velocity() const { return Vector3(); } -Vector3 PhysicsBody::get_angular_velocity() const { +Vector3 PhysicsBody3D::get_angular_velocity() const { return Vector3(); } -float PhysicsBody::get_inverse_mass() const { +float PhysicsBody3D::get_inverse_mass() const { return 0; } -void PhysicsBody::set_collision_layer(uint32_t p_layer) { +void PhysicsBody3D::set_collision_layer(uint32_t p_layer) { collision_layer = p_layer; - PhysicsServer::get_singleton()->body_set_collision_layer(get_rid(), p_layer); + PhysicsServer3D::get_singleton()->body_set_collision_layer(get_rid(), p_layer); } -uint32_t PhysicsBody::get_collision_layer() const { +uint32_t PhysicsBody3D::get_collision_layer() const { return collision_layer; } -void PhysicsBody::set_collision_mask(uint32_t p_mask) { +void PhysicsBody3D::set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; - PhysicsServer::get_singleton()->body_set_collision_mask(get_rid(), p_mask); + PhysicsServer3D::get_singleton()->body_set_collision_mask(get_rid(), p_mask); } -uint32_t PhysicsBody::get_collision_mask() const { +uint32_t PhysicsBody3D::get_collision_mask() const { return collision_mask; } -void PhysicsBody::set_collision_mask_bit(int p_bit, bool p_value) { +void PhysicsBody3D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); if (p_value) @@ -90,12 +90,12 @@ void PhysicsBody::set_collision_mask_bit(int p_bit, bool p_value) { set_collision_mask(mask); } -bool PhysicsBody::get_collision_mask_bit(int p_bit) const { +bool PhysicsBody3D::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } -void PhysicsBody::set_collision_layer_bit(int p_bit, bool p_value) { +void PhysicsBody3D::set_collision_layer_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_layer(); if (p_value) @@ -105,155 +105,155 @@ void PhysicsBody::set_collision_layer_bit(int p_bit, bool p_value) { set_collision_layer(mask); } -bool PhysicsBody::get_collision_layer_bit(int p_bit) const { +bool PhysicsBody3D::get_collision_layer_bit(int p_bit) const { return get_collision_layer() & (1 << p_bit); } -Array PhysicsBody::get_collision_exceptions() { +TypedArray<PhysicsBody3D> PhysicsBody3D::get_collision_exceptions() { List<RID> exceptions; - PhysicsServer::get_singleton()->body_get_collision_exceptions(get_rid(), &exceptions); + PhysicsServer3D::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 = PhysicsServer::get_singleton()->body_get_object_instance_id(body); + ObjectID instance_id = PhysicsServer3D::get_singleton()->body_get_object_instance_id(body); Object *obj = ObjectDB::get_instance(instance_id); - PhysicsBody *physics_body = Object::cast_to<PhysicsBody>(obj); + PhysicsBody3D *physics_body = Object::cast_to<PhysicsBody3D>(obj); ret.append(physics_body); } return ret; } -void PhysicsBody::add_collision_exception_with(Node *p_node) { +void PhysicsBody3D::add_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); - CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject."); - PhysicsServer::get_singleton()->body_add_collision_exception(get_rid(), collision_object->get_rid()); + CollisionObject3D *collision_object = Object::cast_to<CollisionObject3D>(p_node); + ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject3Ds."); + PhysicsServer3D::get_singleton()->body_add_collision_exception(get_rid(), collision_object->get_rid()); } -void PhysicsBody::remove_collision_exception_with(Node *p_node) { +void PhysicsBody3D::remove_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); - CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject."); - PhysicsServer::get_singleton()->body_remove_collision_exception(get_rid(), collision_object->get_rid()); + CollisionObject3D *collision_object = Object::cast_to<CollisionObject3D>(p_node); + ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject3Ds."); + PhysicsServer3D::get_singleton()->body_remove_collision_exception(get_rid(), collision_object->get_rid()); } -void PhysicsBody::_set_layers(uint32_t p_mask) { +void PhysicsBody3D::_set_layers(uint32_t p_mask) { set_collision_layer(p_mask); set_collision_mask(p_mask); } -uint32_t PhysicsBody::_get_layers() const { +uint32_t PhysicsBody3D::_get_layers() const { return get_collision_layer(); } -void PhysicsBody::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &PhysicsBody::set_collision_layer); - ClassDB::bind_method(D_METHOD("get_collision_layer"), &PhysicsBody::get_collision_layer); +void PhysicsBody3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &PhysicsBody3D::set_collision_layer); + ClassDB::bind_method(D_METHOD("get_collision_layer"), &PhysicsBody3D::get_collision_layer); - ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &PhysicsBody::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsBody::get_collision_mask); + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &PhysicsBody3D::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsBody3D::get_collision_mask); - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &PhysicsBody::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &PhysicsBody::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &PhysicsBody3D::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &PhysicsBody3D::get_collision_mask_bit); - ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &PhysicsBody::set_collision_layer_bit); - ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &PhysicsBody::get_collision_layer_bit); + ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &PhysicsBody3D::set_collision_layer_bit); + ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &PhysicsBody3D::get_collision_layer_bit); - ClassDB::bind_method(D_METHOD("_set_layers", "mask"), &PhysicsBody::_set_layers); - ClassDB::bind_method(D_METHOD("_get_layers"), &PhysicsBody::_get_layers); + ClassDB::bind_method(D_METHOD("_set_layers", "mask"), &PhysicsBody3D::_set_layers); + ClassDB::bind_method(D_METHOD("_get_layers"), &PhysicsBody3D::_get_layers); ADD_GROUP("Collision", "collision_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); } -PhysicsBody::PhysicsBody(PhysicsServer::BodyMode p_mode) : - CollisionObject(PhysicsServer::get_singleton()->body_create(p_mode), false) { +PhysicsBody3D::PhysicsBody3D(PhysicsServer3D::BodyMode p_mode) : + CollisionObject3D(PhysicsServer3D::get_singleton()->body_create(p_mode), false) { collision_layer = 1; collision_mask = 1; } -void StaticBody::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) { +void StaticBody3D::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) { if (physics_material_override.is_valid()) { - if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, callable_mp(this, &StaticBody::_reload_physics_characteristics))) { - physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &StaticBody::_reload_physics_characteristics)); + if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, callable_mp(this, &StaticBody3D::_reload_physics_characteristics))) { + physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &StaticBody3D::_reload_physics_characteristics)); } } physics_material_override = p_physics_material_override; if (physics_material_override.is_valid()) { - physics_material_override->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &StaticBody::_reload_physics_characteristics)); + physics_material_override->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &StaticBody3D::_reload_physics_characteristics)); } _reload_physics_characteristics(); } -Ref<PhysicsMaterial> StaticBody::get_physics_material_override() const { +Ref<PhysicsMaterial> StaticBody3D::get_physics_material_override() const { return physics_material_override; } -void StaticBody::set_constant_linear_velocity(const Vector3 &p_vel) { +void StaticBody3D::set_constant_linear_velocity(const Vector3 &p_vel) { constant_linear_velocity = p_vel; - PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_LINEAR_VELOCITY, constant_linear_velocity); + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_LINEAR_VELOCITY, constant_linear_velocity); } -void StaticBody::set_constant_angular_velocity(const Vector3 &p_vel) { +void StaticBody3D::set_constant_angular_velocity(const Vector3 &p_vel) { constant_angular_velocity = p_vel; - PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_ANGULAR_VELOCITY, constant_angular_velocity); + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_ANGULAR_VELOCITY, constant_angular_velocity); } -Vector3 StaticBody::get_constant_linear_velocity() const { +Vector3 StaticBody3D::get_constant_linear_velocity() const { return constant_linear_velocity; } -Vector3 StaticBody::get_constant_angular_velocity() const { +Vector3 StaticBody3D::get_constant_angular_velocity() const { return constant_angular_velocity; } -void StaticBody::_bind_methods() { +void StaticBody3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constant_linear_velocity", "vel"), &StaticBody::set_constant_linear_velocity); - ClassDB::bind_method(D_METHOD("set_constant_angular_velocity", "vel"), &StaticBody::set_constant_angular_velocity); - ClassDB::bind_method(D_METHOD("get_constant_linear_velocity"), &StaticBody::get_constant_linear_velocity); - ClassDB::bind_method(D_METHOD("get_constant_angular_velocity"), &StaticBody::get_constant_angular_velocity); + ClassDB::bind_method(D_METHOD("set_constant_linear_velocity", "vel"), &StaticBody3D::set_constant_linear_velocity); + ClassDB::bind_method(D_METHOD("set_constant_angular_velocity", "vel"), &StaticBody3D::set_constant_angular_velocity); + ClassDB::bind_method(D_METHOD("get_constant_linear_velocity"), &StaticBody3D::get_constant_linear_velocity); + ClassDB::bind_method(D_METHOD("get_constant_angular_velocity"), &StaticBody3D::get_constant_angular_velocity); - ClassDB::bind_method(D_METHOD("set_physics_material_override", "physics_material_override"), &StaticBody::set_physics_material_override); - ClassDB::bind_method(D_METHOD("get_physics_material_override"), &StaticBody::get_physics_material_override); + ClassDB::bind_method(D_METHOD("set_physics_material_override", "physics_material_override"), &StaticBody3D::set_physics_material_override); + ClassDB::bind_method(D_METHOD("get_physics_material_override"), &StaticBody3D::get_physics_material_override); - ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &PhysicsBody::get_collision_exceptions); - ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &PhysicsBody::add_collision_exception_with); - ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &PhysicsBody::remove_collision_exception_with); + ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &PhysicsBody3D::get_collision_exceptions); + ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &PhysicsBody3D::add_collision_exception_with); + ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &PhysicsBody3D::remove_collision_exception_with); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "physics_material_override", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsMaterial"), "set_physics_material_override", "get_physics_material_override"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "constant_linear_velocity"), "set_constant_linear_velocity", "get_constant_linear_velocity"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "constant_angular_velocity"), "set_constant_angular_velocity", "get_constant_angular_velocity"); } -StaticBody::StaticBody() : - PhysicsBody(PhysicsServer::BODY_MODE_STATIC) { +StaticBody3D::StaticBody3D() : + PhysicsBody3D(PhysicsServer3D::BODY_MODE_STATIC) { } -StaticBody::~StaticBody() {} +StaticBody3D::~StaticBody3D() {} -void StaticBody::_reload_physics_characteristics() { +void StaticBody3D::_reload_physics_characteristics() { if (physics_material_override.is_null()) { - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, 0); - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, 1); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_BOUNCE, 0); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_FRICTION, 1); } else { - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce()); - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, physics_material_override->computed_friction()); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce()); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_FRICTION, physics_material_override->computed_friction()); } } -void RigidBody::_body_enter_tree(ObjectID p_id) { +void RigidBody3D::_body_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); @@ -278,7 +278,7 @@ void RigidBody::_body_enter_tree(ObjectID p_id) { contact_monitor->locked = false; } -void RigidBody::_body_exit_tree(ObjectID p_id) { +void RigidBody3D::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); @@ -301,7 +301,7 @@ void RigidBody::_body_exit_tree(ObjectID p_id) { contact_monitor->locked = false; } -void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, int p_local_shape) { +void RigidBody3D::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, int p_local_shape) { bool body_in = p_status == 1; ObjectID objid = p_instance; @@ -321,8 +321,8 @@ void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, //E->get().rc=0; E->get().in_tree = node && node->is_inside_tree(); if (node) { - node->connect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody::_body_enter_tree), make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody::_body_exit_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody3D::_body_enter_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody3D::_body_exit_tree), make_binds(objid)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->body_entered, node); } @@ -348,8 +348,8 @@ void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, if (E->get().shapes.empty()) { if (node) { - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody::_body_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody::_body_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody3D::_body_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody3D::_body_exit_tree)); if (in_tree) emit_signal(SceneStringNames::get_singleton()->body_exited, node); } @@ -369,12 +369,12 @@ struct _RigidBodyInOut { int local_shape; }; -void RigidBody::_direct_state_changed(Object *p_state) { +void RigidBody3D::_direct_state_changed(Object *p_state) { #ifdef DEBUG_ENABLED - state = Object::cast_to<PhysicsDirectBodyState>(p_state); + state = Object::cast_to<PhysicsDirectBodyState3D>(p_state); #else - state = (PhysicsDirectBodyState *)p_state; //trust it + state = (PhysicsDirectBodyState3D *)p_state; //trust it #endif set_ignore_transform_notification(true); @@ -406,7 +406,7 @@ void RigidBody::_direct_state_changed(Object *p_state) { _RigidBodyInOut *toadd = (_RigidBodyInOut *)alloca(state->get_contact_count() * sizeof(_RigidBodyInOut)); int toadd_count = 0; //state->get_contact_count(); - RigidBody_RemoveAction *toremove = (RigidBody_RemoveAction *)alloca(rc * sizeof(RigidBody_RemoveAction)); + RigidBody3D_RemoveAction *toremove = (RigidBody3D_RemoveAction *)alloca(rc * sizeof(RigidBody3D_RemoveAction)); int toremove_count = 0; //put the ones to add @@ -474,10 +474,10 @@ void RigidBody::_direct_state_changed(Object *p_state) { contact_monitor->locked = false; } - state = NULL; + state = nullptr; } -void RigidBody::_notification(int p_what) { +void RigidBody3D::_notification(int p_what) { #ifdef TOOLS_ENABLED if (p_what == NOTIFICATION_ENTER_TREE) { @@ -495,111 +495,111 @@ void RigidBody::_notification(int p_what) { #endif } -void RigidBody::set_mode(Mode p_mode) { +void RigidBody3D::set_mode(Mode p_mode) { mode = p_mode; switch (p_mode) { case MODE_RIGID: { - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_RIGID); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_RIGID); } break; case MODE_STATIC: { - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_STATIC); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_STATIC); } break; case MODE_CHARACTER: { - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_CHARACTER); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_CHARACTER); } break; case MODE_KINEMATIC: { - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_KINEMATIC); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_KINEMATIC); } break; } update_configuration_warning(); } -RigidBody::Mode RigidBody::get_mode() const { +RigidBody3D::Mode RigidBody3D::get_mode() const { return mode; } -void RigidBody::set_mass(real_t p_mass) { +void RigidBody3D::set_mass(real_t p_mass) { ERR_FAIL_COND(p_mass <= 0); mass = p_mass; _change_notify("mass"); _change_notify("weight"); - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_MASS, mass); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_MASS, mass); } -real_t RigidBody::get_mass() const { +real_t RigidBody3D::get_mass() const { return mass; } -void RigidBody::set_weight(real_t p_weight) { +void RigidBody3D::set_weight(real_t p_weight) { set_mass(p_weight / real_t(GLOBAL_DEF("physics/3d/default_gravity", 9.8))); } -real_t RigidBody::get_weight() const { +real_t RigidBody3D::get_weight() const { return mass * real_t(GLOBAL_DEF("physics/3d/default_gravity", 9.8)); } -void RigidBody::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) { +void RigidBody3D::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) { if (physics_material_override.is_valid()) { - if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody::_reload_physics_characteristics))) { - physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody::_reload_physics_characteristics)); + if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody3D::_reload_physics_characteristics))) { + physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody3D::_reload_physics_characteristics)); } } physics_material_override = p_physics_material_override; if (physics_material_override.is_valid()) { - physics_material_override->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody::_reload_physics_characteristics)); + physics_material_override->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody3D::_reload_physics_characteristics)); } _reload_physics_characteristics(); } -Ref<PhysicsMaterial> RigidBody::get_physics_material_override() const { +Ref<PhysicsMaterial> RigidBody3D::get_physics_material_override() const { return physics_material_override; } -void RigidBody::set_gravity_scale(real_t p_gravity_scale) { +void RigidBody3D::set_gravity_scale(real_t p_gravity_scale) { gravity_scale = p_gravity_scale; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_GRAVITY_SCALE, gravity_scale); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_GRAVITY_SCALE, gravity_scale); } -real_t RigidBody::get_gravity_scale() const { +real_t RigidBody3D::get_gravity_scale() const { return gravity_scale; } -void RigidBody::set_linear_damp(real_t p_linear_damp) { +void RigidBody3D::set_linear_damp(real_t p_linear_damp) { ERR_FAIL_COND(p_linear_damp < -1); linear_damp = p_linear_damp; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_LINEAR_DAMP, linear_damp); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_LINEAR_DAMP, linear_damp); } -real_t RigidBody::get_linear_damp() const { +real_t RigidBody3D::get_linear_damp() const { return linear_damp; } -void RigidBody::set_angular_damp(real_t p_angular_damp) { +void RigidBody3D::set_angular_damp(real_t p_angular_damp) { ERR_FAIL_COND(p_angular_damp < -1); angular_damp = p_angular_damp; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_ANGULAR_DAMP, angular_damp); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP, angular_damp); } -real_t RigidBody::get_angular_damp() const { +real_t RigidBody3D::get_angular_damp() const { return angular_damp; } -void RigidBody::set_axis_velocity(const Vector3 &p_axis) { +void RigidBody3D::set_axis_velocity(const Vector3 &p_axis) { Vector3 v = state ? state->get_linear_velocity() : linear_velocity; Vector3 axis = p_axis.normalized(); @@ -608,121 +608,121 @@ void RigidBody::set_axis_velocity(const Vector3 &p_axis) { if (state) { set_linear_velocity(v); } else { - PhysicsServer::get_singleton()->body_set_axis_velocity(get_rid(), p_axis); + PhysicsServer3D::get_singleton()->body_set_axis_velocity(get_rid(), p_axis); linear_velocity = v; } } -void RigidBody::set_linear_velocity(const Vector3 &p_velocity) { +void RigidBody3D::set_linear_velocity(const Vector3 &p_velocity) { linear_velocity = p_velocity; if (state) state->set_linear_velocity(linear_velocity); else - PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_LINEAR_VELOCITY, linear_velocity); + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_LINEAR_VELOCITY, linear_velocity); } -Vector3 RigidBody::get_linear_velocity() const { +Vector3 RigidBody3D::get_linear_velocity() const { return linear_velocity; } -void RigidBody::set_angular_velocity(const Vector3 &p_velocity) { +void RigidBody3D::set_angular_velocity(const Vector3 &p_velocity) { angular_velocity = p_velocity; if (state) state->set_angular_velocity(angular_velocity); else - PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_ANGULAR_VELOCITY, angular_velocity); + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_ANGULAR_VELOCITY, angular_velocity); } -Vector3 RigidBody::get_angular_velocity() const { +Vector3 RigidBody3D::get_angular_velocity() const { return angular_velocity; } -void RigidBody::set_use_custom_integrator(bool p_enable) { +void RigidBody3D::set_use_custom_integrator(bool p_enable) { if (custom_integrator == p_enable) return; custom_integrator = p_enable; - PhysicsServer::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable); + PhysicsServer3D::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable); } -bool RigidBody::is_using_custom_integrator() { +bool RigidBody3D::is_using_custom_integrator() { return custom_integrator; } -void RigidBody::set_sleeping(bool p_sleeping) { +void RigidBody3D::set_sleeping(bool p_sleeping) { sleeping = p_sleeping; - PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_SLEEPING, sleeping); + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_SLEEPING, sleeping); } -void RigidBody::set_can_sleep(bool p_active) { +void RigidBody3D::set_can_sleep(bool p_active) { can_sleep = p_active; - PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_CAN_SLEEP, p_active); + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_CAN_SLEEP, p_active); } -bool RigidBody::is_able_to_sleep() const { +bool RigidBody3D::is_able_to_sleep() const { return can_sleep; } -bool RigidBody::is_sleeping() const { +bool RigidBody3D::is_sleeping() const { return sleeping; } -void RigidBody::set_max_contacts_reported(int p_amount) { +void RigidBody3D::set_max_contacts_reported(int p_amount) { max_contacts_reported = p_amount; - PhysicsServer::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount); + PhysicsServer3D::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount); } -int RigidBody::get_max_contacts_reported() const { +int RigidBody3D::get_max_contacts_reported() const { return max_contacts_reported; } -void RigidBody::add_central_force(const Vector3 &p_force) { - PhysicsServer::get_singleton()->body_add_central_force(get_rid(), p_force); +void RigidBody3D::add_central_force(const Vector3 &p_force) { + PhysicsServer3D::get_singleton()->body_add_central_force(get_rid(), p_force); } -void RigidBody::add_force(const Vector3 &p_force, const Vector3 &p_pos) { - PhysicsServer::get_singleton()->body_add_force(get_rid(), p_force, p_pos); +void RigidBody3D::add_force(const Vector3 &p_force, const Vector3 &p_pos) { + PhysicsServer3D::get_singleton()->body_add_force(get_rid(), p_force, p_pos); } -void RigidBody::add_torque(const Vector3 &p_torque) { - PhysicsServer::get_singleton()->body_add_torque(get_rid(), p_torque); +void RigidBody3D::add_torque(const Vector3 &p_torque) { + PhysicsServer3D::get_singleton()->body_add_torque(get_rid(), p_torque); } -void RigidBody::apply_central_impulse(const Vector3 &p_impulse) { - PhysicsServer::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse); +void RigidBody3D::apply_central_impulse(const Vector3 &p_impulse) { + PhysicsServer3D::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse); } -void RigidBody::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) { +void RigidBody3D::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) { - PhysicsServer::get_singleton()->body_apply_impulse(get_rid(), p_pos, p_impulse); + PhysicsServer3D::get_singleton()->body_apply_impulse(get_rid(), p_pos, p_impulse); } -void RigidBody::apply_torque_impulse(const Vector3 &p_impulse) { - PhysicsServer::get_singleton()->body_apply_torque_impulse(get_rid(), p_impulse); +void RigidBody3D::apply_torque_impulse(const Vector3 &p_impulse) { + PhysicsServer3D::get_singleton()->body_apply_torque_impulse(get_rid(), p_impulse); } -void RigidBody::set_use_continuous_collision_detection(bool p_enable) { +void RigidBody3D::set_use_continuous_collision_detection(bool p_enable) { ccd = p_enable; - PhysicsServer::get_singleton()->body_set_enable_continuous_collision_detection(get_rid(), p_enable); + PhysicsServer3D::get_singleton()->body_set_enable_continuous_collision_detection(get_rid(), p_enable); } -bool RigidBody::is_using_continuous_collision_detection() const { +bool RigidBody3D::is_using_continuous_collision_detection() const { return ccd; } -void RigidBody::set_contact_monitor(bool p_enabled) { +void RigidBody3D::set_contact_monitor(bool p_enabled) { if (p_enabled == is_contact_monitor_enabled()) return; @@ -738,13 +738,13 @@ void RigidBody::set_contact_monitor(bool p_enabled) { Node *node = Object::cast_to<Node>(obj); if (node) { - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody::_body_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody::_body_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody3D::_body_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody3D::_body_exit_tree)); } } memdelete(contact_monitor); - contact_monitor = NULL; + contact_monitor = nullptr; } else { contact_monitor = memnew(ContactMonitor); @@ -752,20 +752,20 @@ void RigidBody::set_contact_monitor(bool p_enabled) { } } -bool RigidBody::is_contact_monitor_enabled() const { +bool RigidBody3D::is_contact_monitor_enabled() const { - return contact_monitor != NULL; + return contact_monitor != nullptr; } -void RigidBody::set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock) { - PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), p_axis, p_lock); +void RigidBody3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock) { + PhysicsServer3D::get_singleton()->body_set_axis_lock(get_rid(), p_axis, p_lock); } -bool RigidBody::get_axis_lock(PhysicsServer::BodyAxis p_axis) const { - return PhysicsServer::get_singleton()->body_is_axis_locked(get_rid(), p_axis); +bool RigidBody3D::get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const { + return PhysicsServer3D::get_singleton()->body_is_axis_locked(get_rid(), p_axis); } -Array RigidBody::get_colliding_bodies() const { +Array RigidBody3D::get_colliding_bodies() const { ERR_FAIL_COND_V(!contact_monitor, Array()); @@ -784,87 +784,87 @@ Array RigidBody::get_colliding_bodies() const { return ret; } -String RigidBody::get_configuration_warning() const { +String RigidBody3D::get_configuration_warning() const { Transform t = get_transform(); - String warning = CollisionObject::get_configuration_warning(); + String warning = CollisionObject3D::get_configuration_warning(); if ((get_mode() == MODE_RIGID || get_mode() == MODE_CHARACTER) && (ABS(t.basis.get_axis(0).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(1).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(2).length() - 1.0) > 0.05)) { if (warning != String()) { warning += "\n\n"; } - warning += TTR("Size changes to RigidBody (in character or rigid modes) will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."); + warning += TTR("Size changes to RigidBody3D (in character or rigid modes) will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."); } return warning; } -void RigidBody::_bind_methods() { +void RigidBody3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mode", "mode"), &RigidBody::set_mode); - ClassDB::bind_method(D_METHOD("get_mode"), &RigidBody::get_mode); + ClassDB::bind_method(D_METHOD("set_mode", "mode"), &RigidBody3D::set_mode); + ClassDB::bind_method(D_METHOD("get_mode"), &RigidBody3D::get_mode); - ClassDB::bind_method(D_METHOD("set_mass", "mass"), &RigidBody::set_mass); - ClassDB::bind_method(D_METHOD("get_mass"), &RigidBody::get_mass); + ClassDB::bind_method(D_METHOD("set_mass", "mass"), &RigidBody3D::set_mass); + ClassDB::bind_method(D_METHOD("get_mass"), &RigidBody3D::get_mass); - ClassDB::bind_method(D_METHOD("set_weight", "weight"), &RigidBody::set_weight); - ClassDB::bind_method(D_METHOD("get_weight"), &RigidBody::get_weight); + ClassDB::bind_method(D_METHOD("set_weight", "weight"), &RigidBody3D::set_weight); + ClassDB::bind_method(D_METHOD("get_weight"), &RigidBody3D::get_weight); - ClassDB::bind_method(D_METHOD("set_physics_material_override", "physics_material_override"), &RigidBody::set_physics_material_override); - ClassDB::bind_method(D_METHOD("get_physics_material_override"), &RigidBody::get_physics_material_override); + ClassDB::bind_method(D_METHOD("set_physics_material_override", "physics_material_override"), &RigidBody3D::set_physics_material_override); + ClassDB::bind_method(D_METHOD("get_physics_material_override"), &RigidBody3D::get_physics_material_override); - ClassDB::bind_method(D_METHOD("set_linear_velocity", "linear_velocity"), &RigidBody::set_linear_velocity); - ClassDB::bind_method(D_METHOD("get_linear_velocity"), &RigidBody::get_linear_velocity); + ClassDB::bind_method(D_METHOD("set_linear_velocity", "linear_velocity"), &RigidBody3D::set_linear_velocity); + ClassDB::bind_method(D_METHOD("get_linear_velocity"), &RigidBody3D::get_linear_velocity); - ClassDB::bind_method(D_METHOD("set_angular_velocity", "angular_velocity"), &RigidBody::set_angular_velocity); - ClassDB::bind_method(D_METHOD("get_angular_velocity"), &RigidBody::get_angular_velocity); + ClassDB::bind_method(D_METHOD("set_angular_velocity", "angular_velocity"), &RigidBody3D::set_angular_velocity); + ClassDB::bind_method(D_METHOD("get_angular_velocity"), &RigidBody3D::get_angular_velocity); - ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &RigidBody::set_gravity_scale); - ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidBody::get_gravity_scale); + ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &RigidBody3D::set_gravity_scale); + ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidBody3D::get_gravity_scale); - ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &RigidBody::set_linear_damp); - ClassDB::bind_method(D_METHOD("get_linear_damp"), &RigidBody::get_linear_damp); + ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &RigidBody3D::set_linear_damp); + ClassDB::bind_method(D_METHOD("get_linear_damp"), &RigidBody3D::get_linear_damp); - ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &RigidBody::set_angular_damp); - ClassDB::bind_method(D_METHOD("get_angular_damp"), &RigidBody::get_angular_damp); + ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &RigidBody3D::set_angular_damp); + ClassDB::bind_method(D_METHOD("get_angular_damp"), &RigidBody3D::get_angular_damp); - ClassDB::bind_method(D_METHOD("set_max_contacts_reported", "amount"), &RigidBody::set_max_contacts_reported); - ClassDB::bind_method(D_METHOD("get_max_contacts_reported"), &RigidBody::get_max_contacts_reported); + ClassDB::bind_method(D_METHOD("set_max_contacts_reported", "amount"), &RigidBody3D::set_max_contacts_reported); + ClassDB::bind_method(D_METHOD("get_max_contacts_reported"), &RigidBody3D::get_max_contacts_reported); - ClassDB::bind_method(D_METHOD("set_use_custom_integrator", "enable"), &RigidBody::set_use_custom_integrator); - ClassDB::bind_method(D_METHOD("is_using_custom_integrator"), &RigidBody::is_using_custom_integrator); + ClassDB::bind_method(D_METHOD("set_use_custom_integrator", "enable"), &RigidBody3D::set_use_custom_integrator); + ClassDB::bind_method(D_METHOD("is_using_custom_integrator"), &RigidBody3D::is_using_custom_integrator); - ClassDB::bind_method(D_METHOD("set_contact_monitor", "enabled"), &RigidBody::set_contact_monitor); - ClassDB::bind_method(D_METHOD("is_contact_monitor_enabled"), &RigidBody::is_contact_monitor_enabled); + ClassDB::bind_method(D_METHOD("set_contact_monitor", "enabled"), &RigidBody3D::set_contact_monitor); + ClassDB::bind_method(D_METHOD("is_contact_monitor_enabled"), &RigidBody3D::is_contact_monitor_enabled); - ClassDB::bind_method(D_METHOD("set_use_continuous_collision_detection", "enable"), &RigidBody::set_use_continuous_collision_detection); - ClassDB::bind_method(D_METHOD("is_using_continuous_collision_detection"), &RigidBody::is_using_continuous_collision_detection); + ClassDB::bind_method(D_METHOD("set_use_continuous_collision_detection", "enable"), &RigidBody3D::set_use_continuous_collision_detection); + ClassDB::bind_method(D_METHOD("is_using_continuous_collision_detection"), &RigidBody3D::is_using_continuous_collision_detection); - ClassDB::bind_method(D_METHOD("set_axis_velocity", "axis_velocity"), &RigidBody::set_axis_velocity); + ClassDB::bind_method(D_METHOD("set_axis_velocity", "axis_velocity"), &RigidBody3D::set_axis_velocity); - ClassDB::bind_method(D_METHOD("add_central_force", "force"), &RigidBody::add_central_force); - ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &RigidBody::add_force); - ClassDB::bind_method(D_METHOD("add_torque", "torque"), &RigidBody::add_torque); + ClassDB::bind_method(D_METHOD("add_central_force", "force"), &RigidBody3D::add_central_force); + ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &RigidBody3D::add_force); + ClassDB::bind_method(D_METHOD("add_torque", "torque"), &RigidBody3D::add_torque); - ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &RigidBody::apply_central_impulse); - ClassDB::bind_method(D_METHOD("apply_impulse", "position", "impulse"), &RigidBody::apply_impulse); - ClassDB::bind_method(D_METHOD("apply_torque_impulse", "impulse"), &RigidBody::apply_torque_impulse); + ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &RigidBody3D::apply_central_impulse); + ClassDB::bind_method(D_METHOD("apply_impulse", "position", "impulse"), &RigidBody3D::apply_impulse); + ClassDB::bind_method(D_METHOD("apply_torque_impulse", "impulse"), &RigidBody3D::apply_torque_impulse); - ClassDB::bind_method(D_METHOD("set_sleeping", "sleeping"), &RigidBody::set_sleeping); - ClassDB::bind_method(D_METHOD("is_sleeping"), &RigidBody::is_sleeping); + ClassDB::bind_method(D_METHOD("set_sleeping", "sleeping"), &RigidBody3D::set_sleeping); + ClassDB::bind_method(D_METHOD("is_sleeping"), &RigidBody3D::is_sleeping); - ClassDB::bind_method(D_METHOD("set_can_sleep", "able_to_sleep"), &RigidBody::set_can_sleep); - ClassDB::bind_method(D_METHOD("is_able_to_sleep"), &RigidBody::is_able_to_sleep); + ClassDB::bind_method(D_METHOD("set_can_sleep", "able_to_sleep"), &RigidBody3D::set_can_sleep); + ClassDB::bind_method(D_METHOD("is_able_to_sleep"), &RigidBody3D::is_able_to_sleep); - ClassDB::bind_method(D_METHOD("_direct_state_changed"), &RigidBody::_direct_state_changed); + ClassDB::bind_method(D_METHOD("_direct_state_changed"), &RigidBody3D::_direct_state_changed); - ClassDB::bind_method(D_METHOD("set_axis_lock", "axis", "lock"), &RigidBody::set_axis_lock); - ClassDB::bind_method(D_METHOD("get_axis_lock", "axis"), &RigidBody::get_axis_lock); + ClassDB::bind_method(D_METHOD("set_axis_lock", "axis", "lock"), &RigidBody3D::set_axis_lock); + ClassDB::bind_method(D_METHOD("get_axis_lock", "axis"), &RigidBody3D::get_axis_lock); - ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody::get_colliding_bodies); + ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody3D::get_colliding_bodies); - BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectBodyState"))); + BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectBodyState3D"))); 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"); @@ -878,12 +878,12 @@ void RigidBody::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sleeping"), "set_sleeping", "is_sleeping"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "can_sleep"), "set_can_sleep", "is_able_to_sleep"); ADD_GROUP("Axis Lock", "axis_lock_"); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_x"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_X); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_y"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Y); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_z"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Z); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_x"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_ANGULAR_X); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_y"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_ANGULAR_Y); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_z"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_ANGULAR_Z); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_x"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_X); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_y"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_Y); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_z"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_Z); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_x"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_ANGULAR_X); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_y"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_ANGULAR_Y); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_z"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_ANGULAR_Z); ADD_GROUP("Linear", "linear_"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "linear_velocity"), "set_linear_velocity", "get_linear_velocity"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp"); @@ -903,14 +903,14 @@ void RigidBody::_bind_methods() { BIND_ENUM_CONSTANT(MODE_KINEMATIC); } -RigidBody::RigidBody() : - PhysicsBody(PhysicsServer::BODY_MODE_RIGID) { +RigidBody3D::RigidBody3D() : + PhysicsBody3D(PhysicsServer3D::BODY_MODE_RIGID) { mode = MODE_RIGID; mass = 1; max_contacts_reported = 0; - state = NULL; + state = nullptr; gravity_scale = 1; linear_damp = -1; @@ -921,32 +921,32 @@ RigidBody::RigidBody() : ccd = false; custom_integrator = false; - contact_monitor = NULL; + contact_monitor = nullptr; can_sleep = true; - PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); + PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); } -RigidBody::~RigidBody() { +RigidBody3D::~RigidBody3D() { if (contact_monitor) memdelete(contact_monitor); } -void RigidBody::_reload_physics_characteristics() { +void RigidBody3D::_reload_physics_characteristics() { if (physics_material_override.is_null()) { - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, 0); - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, 1); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_BOUNCE, 0); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_FRICTION, 1); } else { - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce()); - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, physics_material_override->computed_friction()); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce()); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_FRICTION, physics_material_override->computed_friction()); } } ////////////////////////////////////////////////////// ////////////////////////// -Ref<KinematicCollision> KinematicBody::_move(const Vector3 &p_motion, bool p_infinite_inertia, bool p_exclude_raycast_shapes, bool p_test_only) { +Ref<KinematicCollision3D> KinematicBody3D::_move(const Vector3 &p_motion, bool p_infinite_inertia, bool p_exclude_raycast_shapes, bool p_test_only) { Collision col; if (move_and_collide(p_motion, p_infinite_inertia, col, p_exclude_raycast_shapes, p_test_only)) { @@ -960,22 +960,22 @@ Ref<KinematicCollision> KinematicBody::_move(const Vector3 &p_motion, bool p_inf return motion_cache; } - return Ref<KinematicCollision>(); + return Ref<KinematicCollision3D>(); } -Vector3 KinematicBody::get_linear_velocity() const { +Vector3 KinematicBody3D::get_linear_velocity() const { return linear_velocity; } -Vector3 KinematicBody::get_angular_velocity() const { +Vector3 KinematicBody3D::get_angular_velocity() const { return angular_velocity; } -bool KinematicBody::move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, Collision &r_collision, bool p_exclude_raycast_shapes, bool p_test_only) { +bool KinematicBody3D::move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, Collision &r_collision, bool p_exclude_raycast_shapes, bool p_test_only) { Transform gt = get_global_transform(); - PhysicsServer::MotionResult result; - bool colliding = PhysicsServer::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, &result, p_exclude_raycast_shapes); + PhysicsServer3D::MotionResult result; + bool colliding = PhysicsServer3D::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, &result, p_exclude_raycast_shapes); if (colliding) { r_collision.collider_metadata = result.collider_metadata; @@ -1007,7 +1007,7 @@ bool KinematicBody::move_and_collide(const Vector3 &p_motion, bool p_infinite_in //so, if you pass 45 as limit, avoid numerical precision errors when angle is 45. #define FLOOR_ANGLE_THRESHOLD 0.01 -Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_up_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { +Vector3 KinematicBody3D::move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_up_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { Vector3 body_velocity = p_linear_velocity; Vector3 body_velocity_normal = body_velocity.normalized(); @@ -1101,7 +1101,7 @@ Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Ve return body_velocity; } -Vector3 KinematicBody::move_and_slide_with_snap(const Vector3 &p_linear_velocity, const Vector3 &p_snap, const Vector3 &p_up_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { +Vector3 KinematicBody3D::move_and_slide_with_snap(const Vector3 &p_linear_velocity, const Vector3 &p_snap, const Vector3 &p_up_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { bool was_on_floor = on_floor; @@ -1140,45 +1140,45 @@ Vector3 KinematicBody::move_and_slide_with_snap(const Vector3 &p_linear_velocity return ret; } -bool KinematicBody::is_on_floor() const { +bool KinematicBody3D::is_on_floor() const { return on_floor; } -bool KinematicBody::is_on_wall() const { +bool KinematicBody3D::is_on_wall() const { return on_wall; } -bool KinematicBody::is_on_ceiling() const { +bool KinematicBody3D::is_on_ceiling() const { return on_ceiling; } -Vector3 KinematicBody::get_floor_normal() const { +Vector3 KinematicBody3D::get_floor_normal() const { return floor_normal; } -Vector3 KinematicBody::get_floor_velocity() const { +Vector3 KinematicBody3D::get_floor_velocity() const { return floor_velocity; } -bool KinematicBody::test_move(const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia) { +bool KinematicBody3D::test_move(const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia) { ERR_FAIL_COND_V(!is_inside_tree(), false); - return PhysicsServer::get_singleton()->body_test_motion(get_rid(), p_from, p_motion, p_infinite_inertia); + return PhysicsServer3D::get_singleton()->body_test_motion(get_rid(), p_from, p_motion, p_infinite_inertia); } -bool KinematicBody::separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision) { +bool KinematicBody3D::separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision) { - PhysicsServer::SeparationResult sep_res[8]; //max 8 rays + PhysicsServer3D::SeparationResult sep_res[8]; //max 8 rays Transform gt = get_global_transform(); Vector3 recover; - int hits = PhysicsServer::get_singleton()->body_test_ray_separation(get_rid(), gt, p_infinite_inertia, recover, sep_res, 8, margin); + int hits = PhysicsServer3D::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++) { @@ -1208,37 +1208,37 @@ bool KinematicBody::separate_raycast_shapes(bool p_infinite_inertia, Collision & } } -void KinematicBody::set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock) { - PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), p_axis, p_lock); +void KinematicBody3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock) { + PhysicsServer3D::get_singleton()->body_set_axis_lock(get_rid(), p_axis, p_lock); } -bool KinematicBody::get_axis_lock(PhysicsServer::BodyAxis p_axis) const { - return PhysicsServer::get_singleton()->body_is_axis_locked(get_rid(), p_axis); +bool KinematicBody3D::get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const { + return PhysicsServer3D::get_singleton()->body_is_axis_locked(get_rid(), p_axis); } -void KinematicBody::set_safe_margin(float p_margin) { +void KinematicBody3D::set_safe_margin(float p_margin) { margin = p_margin; - PhysicsServer::get_singleton()->body_set_kinematic_safe_margin(get_rid(), margin); + PhysicsServer3D::get_singleton()->body_set_kinematic_safe_margin(get_rid(), margin); } -float KinematicBody::get_safe_margin() const { +float KinematicBody3D::get_safe_margin() const { return margin; } -int KinematicBody::get_slide_count() const { +int KinematicBody3D::get_slide_count() const { return colliders.size(); } -KinematicBody::Collision KinematicBody::get_slide_collision(int p_bounce) const { +KinematicBody3D::Collision KinematicBody3D::get_slide_collision(int p_bounce) const { ERR_FAIL_INDEX_V(p_bounce, colliders.size(), Collision()); return colliders[p_bounce]; } -Ref<KinematicCollision> KinematicBody::_get_slide_collision(int p_bounce) { +Ref<KinematicCollision3D> KinematicBody3D::_get_slide_collision(int p_bounce) { - ERR_FAIL_INDEX_V(p_bounce, colliders.size(), Ref<KinematicCollision>()); + ERR_FAIL_INDEX_V(p_bounce, colliders.size(), Ref<KinematicCollision3D>()); if (p_bounce >= slide_colliders.size()) { slide_colliders.resize(p_bounce + 1); } @@ -1252,7 +1252,7 @@ Ref<KinematicCollision> KinematicBody::_get_slide_collision(int p_bounce) { return slide_colliders[p_bounce]; } -void KinematicBody::_notification(int p_what) { +void KinematicBody3D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { // Reset move_and_slide() data. on_floor = false; @@ -1264,51 +1264,51 @@ void KinematicBody::_notification(int p_what) { } } -void KinematicBody::_bind_methods() { +void KinematicBody3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("_direct_state_changed"), &KinematicBody::_direct_state_changed); + ClassDB::bind_method(D_METHOD("_direct_state_changed"), &KinematicBody3D::_direct_state_changed); - ClassDB::bind_method(D_METHOD("move_and_collide", "rel_vec", "infinite_inertia", "exclude_raycast_shapes", "test_only"), &KinematicBody::_move, DEFVAL(true), DEFVAL(true), DEFVAL(false)); - ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "up_direction", "stop_on_slope", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody::move_and_slide, DEFVAL(Vector3(0, 0, 0)), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); - ClassDB::bind_method(D_METHOD("move_and_slide_with_snap", "linear_velocity", "snap", "up_direction", "stop_on_slope", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody::move_and_slide_with_snap, DEFVAL(Vector3(0, 0, 0)), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("move_and_collide", "rel_vec", "infinite_inertia", "exclude_raycast_shapes", "test_only"), &KinematicBody3D::_move, DEFVAL(true), DEFVAL(true), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "up_direction", "stop_on_slope", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody3D::move_and_slide, DEFVAL(Vector3(0, 0, 0)), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("move_and_slide_with_snap", "linear_velocity", "snap", "up_direction", "stop_on_slope", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody3D::move_and_slide_with_snap, DEFVAL(Vector3(0, 0, 0)), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); - ClassDB::bind_method(D_METHOD("test_move", "from", "rel_vec", "infinite_inertia"), &KinematicBody::test_move, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("test_move", "from", "rel_vec", "infinite_inertia"), &KinematicBody3D::test_move, DEFVAL(true)); - ClassDB::bind_method(D_METHOD("is_on_floor"), &KinematicBody::is_on_floor); - ClassDB::bind_method(D_METHOD("is_on_ceiling"), &KinematicBody::is_on_ceiling); - ClassDB::bind_method(D_METHOD("is_on_wall"), &KinematicBody::is_on_wall); - ClassDB::bind_method(D_METHOD("get_floor_normal"), &KinematicBody::get_floor_normal); - ClassDB::bind_method(D_METHOD("get_floor_velocity"), &KinematicBody::get_floor_velocity); + ClassDB::bind_method(D_METHOD("is_on_floor"), &KinematicBody3D::is_on_floor); + ClassDB::bind_method(D_METHOD("is_on_ceiling"), &KinematicBody3D::is_on_ceiling); + ClassDB::bind_method(D_METHOD("is_on_wall"), &KinematicBody3D::is_on_wall); + ClassDB::bind_method(D_METHOD("get_floor_normal"), &KinematicBody3D::get_floor_normal); + ClassDB::bind_method(D_METHOD("get_floor_velocity"), &KinematicBody3D::get_floor_velocity); - ClassDB::bind_method(D_METHOD("set_axis_lock", "axis", "lock"), &KinematicBody::set_axis_lock); - ClassDB::bind_method(D_METHOD("get_axis_lock", "axis"), &KinematicBody::get_axis_lock); + ClassDB::bind_method(D_METHOD("set_axis_lock", "axis", "lock"), &KinematicBody3D::set_axis_lock); + ClassDB::bind_method(D_METHOD("get_axis_lock", "axis"), &KinematicBody3D::get_axis_lock); - ClassDB::bind_method(D_METHOD("set_safe_margin", "pixels"), &KinematicBody::set_safe_margin); - ClassDB::bind_method(D_METHOD("get_safe_margin"), &KinematicBody::get_safe_margin); + ClassDB::bind_method(D_METHOD("set_safe_margin", "pixels"), &KinematicBody3D::set_safe_margin); + ClassDB::bind_method(D_METHOD("get_safe_margin"), &KinematicBody3D::get_safe_margin); - ClassDB::bind_method(D_METHOD("get_slide_count"), &KinematicBody::get_slide_count); - ClassDB::bind_method(D_METHOD("get_slide_collision", "slide_idx"), &KinematicBody::_get_slide_collision); + ClassDB::bind_method(D_METHOD("get_slide_count"), &KinematicBody3D::get_slide_count); + ClassDB::bind_method(D_METHOD("get_slide_collision", "slide_idx"), &KinematicBody3D::_get_slide_collision); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_x", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_X); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_y", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Y); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_z", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Z); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_x", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_X); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_y", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_Y); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_z", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_Z); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision/safe_margin", PROPERTY_HINT_RANGE, "0.001,256,0.001"), "set_safe_margin", "get_safe_margin"); } -void KinematicBody::_direct_state_changed(Object *p_state) { +void KinematicBody3D::_direct_state_changed(Object *p_state) { #ifdef DEBUG_ENABLED - PhysicsDirectBodyState *state = Object::cast_to<PhysicsDirectBodyState>(p_state); + PhysicsDirectBodyState3D *state = Object::cast_to<PhysicsDirectBodyState3D>(p_state); #else - PhysicsDirectBodyState *state = (PhysicsDirectBodyState *)p_state; //trust it + PhysicsDirectBodyState3D *state = (PhysicsDirectBodyState3D *)p_state; //trust it #endif linear_velocity = state->get_linear_velocity(); angular_velocity = state->get_angular_velocity(); } -KinematicBody::KinematicBody() : - PhysicsBody(PhysicsServer::BODY_MODE_KINEMATIC) { +KinematicBody3D::KinematicBody3D() : + PhysicsBody3D(PhysicsServer3D::BODY_MODE_KINEMATIC) { margin = 0.001; locked_axis = 0; @@ -1316,92 +1316,92 @@ KinematicBody::KinematicBody() : on_ceiling = false; on_wall = false; - PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); + PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); } -KinematicBody::~KinematicBody() { +KinematicBody3D::~KinematicBody3D() { 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; } } } /////////////////////////////////////// -Vector3 KinematicCollision::get_position() const { +Vector3 KinematicCollision3D::get_position() const { return collision.collision; } -Vector3 KinematicCollision::get_normal() const { +Vector3 KinematicCollision3D::get_normal() const { return collision.normal; } -Vector3 KinematicCollision::get_travel() const { +Vector3 KinematicCollision3D::get_travel() const { return collision.travel; } -Vector3 KinematicCollision::get_remainder() const { +Vector3 KinematicCollision3D::get_remainder() const { return collision.remainder; } -Object *KinematicCollision::get_local_shape() const { - if (!owner) return NULL; +Object *KinematicCollision3D::get_local_shape() const { + if (!owner) return nullptr; uint32_t ownerid = owner->shape_find_owner(collision.local_shape); return owner->shape_owner_get_owner(ownerid); } -Object *KinematicCollision::get_collider() const { +Object *KinematicCollision3D::get_collider() const { if (collision.collider.is_valid()) { return ObjectDB::get_instance(collision.collider); } - return NULL; + return nullptr; } -ObjectID KinematicCollision::get_collider_id() const { +ObjectID KinematicCollision3D::get_collider_id() const { return collision.collider; } -Object *KinematicCollision::get_collider_shape() const { +Object *KinematicCollision3D::get_collider_shape() const { Object *collider = get_collider(); if (collider) { - CollisionObject *obj2d = Object::cast_to<CollisionObject>(collider); + CollisionObject3D *obj2d = Object::cast_to<CollisionObject3D>(collider); if (obj2d) { uint32_t ownerid = obj2d->shape_find_owner(collision.collider_shape); return obj2d->shape_owner_get_owner(ownerid); } } - return NULL; + return nullptr; } -int KinematicCollision::get_collider_shape_index() const { +int KinematicCollision3D::get_collider_shape_index() const { return collision.collider_shape; } -Vector3 KinematicCollision::get_collider_velocity() const { +Vector3 KinematicCollision3D::get_collider_velocity() const { return collision.collider_vel; } -Variant KinematicCollision::get_collider_metadata() const { +Variant KinematicCollision3D::get_collider_metadata() const { return Variant(); } -void KinematicCollision::_bind_methods() { +void KinematicCollision3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_position"), &KinematicCollision::get_position); - ClassDB::bind_method(D_METHOD("get_normal"), &KinematicCollision::get_normal); - ClassDB::bind_method(D_METHOD("get_travel"), &KinematicCollision::get_travel); - ClassDB::bind_method(D_METHOD("get_remainder"), &KinematicCollision::get_remainder); - ClassDB::bind_method(D_METHOD("get_local_shape"), &KinematicCollision::get_local_shape); - ClassDB::bind_method(D_METHOD("get_collider"), &KinematicCollision::get_collider); - ClassDB::bind_method(D_METHOD("get_collider_id"), &KinematicCollision::get_collider_id); - ClassDB::bind_method(D_METHOD("get_collider_shape"), &KinematicCollision::get_collider_shape); - ClassDB::bind_method(D_METHOD("get_collider_shape_index"), &KinematicCollision::get_collider_shape_index); - ClassDB::bind_method(D_METHOD("get_collider_velocity"), &KinematicCollision::get_collider_velocity); - ClassDB::bind_method(D_METHOD("get_collider_metadata"), &KinematicCollision::get_collider_metadata); + ClassDB::bind_method(D_METHOD("get_position"), &KinematicCollision3D::get_position); + ClassDB::bind_method(D_METHOD("get_normal"), &KinematicCollision3D::get_normal); + ClassDB::bind_method(D_METHOD("get_travel"), &KinematicCollision3D::get_travel); + ClassDB::bind_method(D_METHOD("get_remainder"), &KinematicCollision3D::get_remainder); + ClassDB::bind_method(D_METHOD("get_local_shape"), &KinematicCollision3D::get_local_shape); + ClassDB::bind_method(D_METHOD("get_collider"), &KinematicCollision3D::get_collider); + ClassDB::bind_method(D_METHOD("get_collider_id"), &KinematicCollision3D::get_collider_id); + ClassDB::bind_method(D_METHOD("get_collider_shape"), &KinematicCollision3D::get_collider_shape); + ClassDB::bind_method(D_METHOD("get_collider_shape_index"), &KinematicCollision3D::get_collider_shape_index); + ClassDB::bind_method(D_METHOD("get_collider_velocity"), &KinematicCollision3D::get_collider_velocity); + ClassDB::bind_method(D_METHOD("get_collider_metadata"), &KinematicCollision3D::get_collider_metadata); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position"), "", "get_position"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "normal"), "", "get_normal"); @@ -1416,35 +1416,35 @@ void KinematicCollision::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::NIL, "collider_metadata", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "", "get_collider_metadata"); } -KinematicCollision::KinematicCollision() { +KinematicCollision3D::KinematicCollision3D() { collision.collider_shape = 0; collision.local_shape = 0; - owner = NULL; + owner = nullptr; } /////////////////////////////////////// -bool PhysicalBone::JointData::_set(const StringName &p_name, const Variant &p_value, RID j) { +bool PhysicalBone3D::JointData::_set(const StringName &p_name, const Variant &p_value, RID j) { return false; } -bool PhysicalBone::JointData::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::JointData::_get(const StringName &p_name, Variant &r_ret) const { return false; } -void PhysicalBone::JointData::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::JointData::_get_property_list(List<PropertyInfo> *p_list) const { } -void PhysicalBone::apply_central_impulse(const Vector3 &p_impulse) { - PhysicsServer::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse); +void PhysicalBone3D::apply_central_impulse(const Vector3 &p_impulse) { + PhysicsServer3D::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse); } -void PhysicalBone::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) { - PhysicsServer::get_singleton()->body_apply_impulse(get_rid(), p_pos, p_impulse); +void PhysicalBone3D::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) { + PhysicsServer3D::get_singleton()->body_apply_impulse(get_rid(), p_pos, p_impulse); } -void PhysicalBone::reset_physics_simulation_state() { +void PhysicalBone3D::reset_physics_simulation_state() { if (simulate_physics) { _start_physics_simulation(); } else { @@ -1452,7 +1452,7 @@ void PhysicalBone::reset_physics_simulation_state() { } } -void PhysicalBone::reset_to_rest_position() { +void PhysicalBone3D::reset_to_rest_position() { if (parent_skeleton) { if (-1 == bone_id) { set_global_transform(parent_skeleton->get_global_transform() * body_offset); @@ -1462,7 +1462,7 @@ void PhysicalBone::reset_to_rest_position() { } } -bool PhysicalBone::PinJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { +bool PhysicalBone3D::PinJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { if (JointData::_set(p_name, p_value, j)) { return true; } @@ -1470,17 +1470,17 @@ bool PhysicalBone::PinJointData::_set(const StringName &p_name, const Variant &p if ("joint_constraints/bias" == p_name) { bias = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->pin_joint_set_param(j, PhysicsServer::PIN_JOINT_BIAS, bias); + PhysicsServer3D::get_singleton()->pin_joint_set_param(j, PhysicsServer3D::PIN_JOINT_BIAS, bias); } else if ("joint_constraints/damping" == p_name) { damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->pin_joint_set_param(j, PhysicsServer::PIN_JOINT_DAMPING, damping); + PhysicsServer3D::get_singleton()->pin_joint_set_param(j, PhysicsServer3D::PIN_JOINT_DAMPING, damping); } else if ("joint_constraints/impulse_clamp" == p_name) { impulse_clamp = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->pin_joint_set_param(j, PhysicsServer::PIN_JOINT_IMPULSE_CLAMP, impulse_clamp); + PhysicsServer3D::get_singleton()->pin_joint_set_param(j, PhysicsServer3D::PIN_JOINT_IMPULSE_CLAMP, impulse_clamp); } else { return false; @@ -1489,7 +1489,7 @@ bool PhysicalBone::PinJointData::_set(const StringName &p_name, const Variant &p return true; } -bool PhysicalBone::PinJointData::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::PinJointData::_get(const StringName &p_name, Variant &r_ret) const { if (JointData::_get(p_name, r_ret)) { return true; } @@ -1507,7 +1507,7 @@ bool PhysicalBone::PinJointData::_get(const StringName &p_name, Variant &r_ret) return true; } -void PhysicalBone::PinJointData::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::PinJointData::_get_property_list(List<PropertyInfo> *p_list) const { JointData::_get_property_list(p_list); p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/bias", PROPERTY_HINT_RANGE, "0.01,0.99,0.01")); @@ -1515,7 +1515,7 @@ void PhysicalBone::PinJointData::_get_property_list(List<PropertyInfo> *p_list) p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/impulse_clamp", PROPERTY_HINT_RANGE, "0.0,64.0,0.01")); } -bool PhysicalBone::ConeJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { +bool PhysicalBone3D::ConeJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { if (JointData::_set(p_name, p_value, j)) { return true; } @@ -1523,27 +1523,27 @@ bool PhysicalBone::ConeJointData::_set(const StringName &p_name, const Variant & if ("joint_constraints/swing_span" == p_name) { swing_span = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::CONE_TWIST_JOINT_SWING_SPAN, swing_span); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_SWING_SPAN, swing_span); } else if ("joint_constraints/twist_span" == p_name) { twist_span = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::CONE_TWIST_JOINT_TWIST_SPAN, twist_span); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_TWIST_SPAN, twist_span); } else if ("joint_constraints/bias" == p_name) { bias = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::CONE_TWIST_JOINT_BIAS, bias); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_BIAS, bias); } else if ("joint_constraints/softness" == p_name) { softness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::CONE_TWIST_JOINT_SOFTNESS, softness); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_SOFTNESS, softness); } else if ("joint_constraints/relaxation" == p_name) { relaxation = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::CONE_TWIST_JOINT_RELAXATION, relaxation); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_RELAXATION, relaxation); } else { return false; @@ -1552,7 +1552,7 @@ bool PhysicalBone::ConeJointData::_set(const StringName &p_name, const Variant & return true; } -bool PhysicalBone::ConeJointData::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::ConeJointData::_get(const StringName &p_name, Variant &r_ret) const { if (JointData::_get(p_name, r_ret)) { return true; } @@ -1574,7 +1574,7 @@ bool PhysicalBone::ConeJointData::_get(const StringName &p_name, Variant &r_ret) return true; } -void PhysicalBone::ConeJointData::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::ConeJointData::_get_property_list(List<PropertyInfo> *p_list) const { JointData::_get_property_list(p_list); p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/swing_span", PROPERTY_HINT_RANGE, "-180,180,0.01")); @@ -1584,7 +1584,7 @@ void PhysicalBone::ConeJointData::_get_property_list(List<PropertyInfo> *p_list) p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/relaxation", PROPERTY_HINT_RANGE, "0.01,16.0,0.01")); } -bool PhysicalBone::HingeJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { +bool PhysicalBone3D::HingeJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { if (JointData::_set(p_name, p_value, j)) { return true; } @@ -1592,32 +1592,32 @@ bool PhysicalBone::HingeJointData::_set(const StringName &p_name, const Variant if ("joint_constraints/angular_limit_enabled" == p_name) { angular_limit_enabled = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_flag(j, PhysicsServer::HINGE_JOINT_FLAG_USE_LIMIT, angular_limit_enabled); + PhysicsServer3D::get_singleton()->hinge_joint_set_flag(j, PhysicsServer3D::HINGE_JOINT_FLAG_USE_LIMIT, angular_limit_enabled); } else if ("joint_constraints/angular_limit_upper" == p_name) { angular_limit_upper = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HINGE_JOINT_LIMIT_UPPER, angular_limit_upper); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_UPPER, angular_limit_upper); } else if ("joint_constraints/angular_limit_lower" == p_name) { angular_limit_lower = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HINGE_JOINT_LIMIT_LOWER, angular_limit_lower); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_LOWER, angular_limit_lower); } else if ("joint_constraints/angular_limit_bias" == p_name) { angular_limit_bias = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HINGE_JOINT_LIMIT_BIAS, angular_limit_bias); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_BIAS, angular_limit_bias); } else if ("joint_constraints/angular_limit_softness" == p_name) { angular_limit_softness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HINGE_JOINT_LIMIT_SOFTNESS, angular_limit_softness); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_SOFTNESS, angular_limit_softness); } else if ("joint_constraints/angular_limit_relaxation" == p_name) { angular_limit_relaxation = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HINGE_JOINT_LIMIT_RELAXATION, angular_limit_relaxation); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_RELAXATION, angular_limit_relaxation); } else { return false; @@ -1626,7 +1626,7 @@ bool PhysicalBone::HingeJointData::_set(const StringName &p_name, const Variant return true; } -bool PhysicalBone::HingeJointData::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::HingeJointData::_get(const StringName &p_name, Variant &r_ret) const { if (JointData::_get(p_name, r_ret)) { return true; } @@ -1650,7 +1650,7 @@ bool PhysicalBone::HingeJointData::_get(const StringName &p_name, Variant &r_ret return true; } -void PhysicalBone::HingeJointData::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::HingeJointData::_get_property_list(List<PropertyInfo> *p_list) const { JointData::_get_property_list(p_list); p_list->push_back(PropertyInfo(Variant::BOOL, "joint_constraints/angular_limit_enabled")); @@ -1661,7 +1661,7 @@ void PhysicalBone::HingeJointData::_get_property_list(List<PropertyInfo> *p_list p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/angular_limit_relaxation", PROPERTY_HINT_RANGE, "0.01,16,0.01")); } -bool PhysicalBone::SliderJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { +bool PhysicalBone3D::SliderJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { if (JointData::_set(p_name, p_value, j)) { return true; } @@ -1669,52 +1669,52 @@ bool PhysicalBone::SliderJointData::_set(const StringName &p_name, const Variant if ("joint_constraints/linear_limit_upper" == p_name) { linear_limit_upper = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER, linear_limit_upper); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_UPPER, linear_limit_upper); } else if ("joint_constraints/linear_limit_lower" == p_name) { linear_limit_lower = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_LOWER, linear_limit_lower); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_LOWER, linear_limit_lower); } else if ("joint_constraints/linear_limit_softness" == p_name) { linear_limit_softness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS, linear_limit_softness); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS, linear_limit_softness); } else if ("joint_constraints/linear_limit_restitution" == p_name) { linear_limit_restitution = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION, linear_limit_restitution); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION, linear_limit_restitution); } else if ("joint_constraints/linear_limit_damping" == p_name) { linear_limit_damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_DAMPING, linear_limit_restitution); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_DAMPING, linear_limit_restitution); } else if ("joint_constraints/angular_limit_upper" == p_name) { angular_limit_upper = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_UPPER, angular_limit_upper); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_UPPER, angular_limit_upper); } else if ("joint_constraints/angular_limit_lower" == p_name) { angular_limit_lower = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_LOWER, angular_limit_lower); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_LOWER, angular_limit_lower); } else if ("joint_constraints/angular_limit_softness" == p_name) { angular_limit_softness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, angular_limit_softness); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, angular_limit_softness); } else if ("joint_constraints/angular_limit_restitution" == p_name) { angular_limit_restitution = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, angular_limit_softness); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, angular_limit_softness); } else if ("joint_constraints/angular_limit_damping" == p_name) { angular_limit_damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING, angular_limit_damping); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING, angular_limit_damping); } else { return false; @@ -1723,7 +1723,7 @@ bool PhysicalBone::SliderJointData::_set(const StringName &p_name, const Variant return true; } -bool PhysicalBone::SliderJointData::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::SliderJointData::_get(const StringName &p_name, Variant &r_ret) const { if (JointData::_get(p_name, r_ret)) { return true; } @@ -1755,7 +1755,7 @@ bool PhysicalBone::SliderJointData::_get(const StringName &p_name, Variant &r_re return true; } -void PhysicalBone::SliderJointData::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::SliderJointData::_get_property_list(List<PropertyInfo> *p_list) const { JointData::_get_property_list(p_list); p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/linear_limit_upper")); @@ -1771,7 +1771,7 @@ void PhysicalBone::SliderJointData::_get_property_list(List<PropertyInfo> *p_lis p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/angular_limit_damping", PROPERTY_HINT_RANGE, "0,16.0,0.01")); } -bool PhysicalBone::SixDOFJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { +bool PhysicalBone3D::SixDOFJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { if (JointData::_set(p_name, p_value, j)) { return true; } @@ -1797,107 +1797,107 @@ bool PhysicalBone::SixDOFJointData::_set(const StringName &p_name, const Variant if ("linear_limit_enabled" == var_name) { axis_data[axis].linear_limit_enabled = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, axis_data[axis].linear_limit_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, axis_data[axis].linear_limit_enabled); } else if ("linear_limit_upper" == var_name) { axis_data[axis].linear_limit_upper = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_UPPER_LIMIT, axis_data[axis].linear_limit_upper); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_UPPER_LIMIT, axis_data[axis].linear_limit_upper); } else if ("linear_limit_lower" == var_name) { axis_data[axis].linear_limit_lower = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_LOWER_LIMIT, axis_data[axis].linear_limit_lower); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_LOWER_LIMIT, axis_data[axis].linear_limit_lower); } else if ("linear_limit_softness" == var_name) { axis_data[axis].linear_limit_softness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, axis_data[axis].linear_limit_softness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, axis_data[axis].linear_limit_softness); } else if ("linear_spring_enabled" == var_name) { axis_data[axis].linear_spring_enabled = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING, axis_data[axis].linear_spring_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING, axis_data[axis].linear_spring_enabled); } else if ("linear_spring_stiffness" == var_name) { axis_data[axis].linear_spring_stiffness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS, axis_data[axis].linear_spring_stiffness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS, axis_data[axis].linear_spring_stiffness); } else if ("linear_spring_damping" == var_name) { axis_data[axis].linear_spring_damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_DAMPING, axis_data[axis].linear_spring_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_DAMPING, axis_data[axis].linear_spring_damping); } else if ("linear_equilibrium_point" == var_name) { axis_data[axis].linear_equilibrium_point = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT, axis_data[axis].linear_equilibrium_point); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT, axis_data[axis].linear_equilibrium_point); } else if ("linear_restitution" == var_name) { axis_data[axis].linear_restitution = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_RESTITUTION, axis_data[axis].linear_restitution); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_RESTITUTION, axis_data[axis].linear_restitution); } else if ("linear_damping" == var_name) { axis_data[axis].linear_damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING, axis_data[axis].linear_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_DAMPING, axis_data[axis].linear_damping); } else if ("angular_limit_enabled" == var_name) { axis_data[axis].angular_limit_enabled = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, axis_data[axis].angular_limit_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, axis_data[axis].angular_limit_enabled); } else if ("angular_limit_upper" == var_name) { axis_data[axis].angular_limit_upper = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, axis_data[axis].angular_limit_upper); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, axis_data[axis].angular_limit_upper); } else if ("angular_limit_lower" == var_name) { axis_data[axis].angular_limit_lower = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, axis_data[axis].angular_limit_lower); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, axis_data[axis].angular_limit_lower); } else if ("angular_limit_softness" == var_name) { axis_data[axis].angular_limit_softness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, axis_data[axis].angular_limit_softness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, axis_data[axis].angular_limit_softness); } else if ("angular_restitution" == var_name) { axis_data[axis].angular_restitution = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_RESTITUTION, axis_data[axis].angular_restitution); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_RESTITUTION, axis_data[axis].angular_restitution); } else if ("angular_damping" == var_name) { axis_data[axis].angular_damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_DAMPING, axis_data[axis].angular_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_DAMPING, axis_data[axis].angular_damping); } else if ("erp" == var_name) { axis_data[axis].erp = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_ERP, axis_data[axis].erp); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_ERP, axis_data[axis].erp); } else if ("angular_spring_enabled" == var_name) { axis_data[axis].angular_spring_enabled = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING, axis_data[axis].angular_spring_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING, axis_data[axis].angular_spring_enabled); } else if ("angular_spring_stiffness" == var_name) { axis_data[axis].angular_spring_stiffness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS, axis_data[axis].angular_spring_stiffness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS, axis_data[axis].angular_spring_stiffness); } else if ("angular_spring_damping" == var_name) { axis_data[axis].angular_spring_damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_DAMPING, axis_data[axis].angular_spring_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_DAMPING, axis_data[axis].angular_spring_damping); } else if ("angular_equilibrium_point" == var_name) { axis_data[axis].angular_equilibrium_point = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT, axis_data[axis].angular_equilibrium_point); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT, axis_data[axis].angular_equilibrium_point); } else { return false; @@ -1906,7 +1906,7 @@ bool PhysicalBone::SixDOFJointData::_set(const StringName &p_name, const Variant return true; } -bool PhysicalBone::SixDOFJointData::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::SixDOFJointData::_get(const StringName &p_name, Variant &r_ret) const { if (JointData::_get(p_name, r_ret)) { return true; } @@ -1978,7 +1978,7 @@ bool PhysicalBone::SixDOFJointData::_get(const StringName &p_name, Variant &r_re return true; } -void PhysicalBone::SixDOFJointData::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::SixDOFJointData::_get_property_list(List<PropertyInfo> *p_list) const { const StringName axis_names[] = { "x", "y", "z" }; for (int i = 0; i < 3; ++i) { p_list->push_back(PropertyInfo(Variant::BOOL, "joint_constraints/" + axis_names[i] + "/linear_limit_enabled")); @@ -2005,7 +2005,7 @@ void PhysicalBone::SixDOFJointData::_get_property_list(List<PropertyInfo> *p_lis } } -bool PhysicalBone::_set(const StringName &p_name, const Variant &p_value) { +bool PhysicalBone3D::_set(const StringName &p_name, const Variant &p_value) { if (p_name == "bone_name") { set_bone_name(p_value); return true; @@ -2024,7 +2024,7 @@ bool PhysicalBone::_set(const StringName &p_name, const Variant &p_value) { return false; } -bool PhysicalBone::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::_get(const StringName &p_name, Variant &r_ret) const { if (p_name == "bone_name") { r_ret = get_bone_name(); return true; @@ -2037,9 +2037,9 @@ bool PhysicalBone::_get(const StringName &p_name, Variant &r_ret) const { return false; } -void PhysicalBone::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::_get_property_list(List<PropertyInfo> *p_list) const { - Skeleton *parent = find_skeleton_parent(get_parent()); + Skeleton3D *parent = find_skeleton_parent(get_parent()); if (parent) { @@ -2061,7 +2061,7 @@ void PhysicalBone::_get_property_list(List<PropertyInfo> *p_list) const { } } -void PhysicalBone::_notification(int p_what) { +void PhysicalBone3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: parent_skeleton = find_skeleton_parent(get_parent()); @@ -2078,9 +2078,9 @@ void PhysicalBone::_notification(int p_what) { parent_skeleton->unbind_physical_bone_from_bone(bone_id); } } - parent_skeleton = NULL; + parent_skeleton = nullptr; if (joint.is_valid()) { - PhysicsServer::get_singleton()->free(joint); + PhysicsServer3D::get_singleton()->free(joint); joint = RID(); } break; @@ -2093,7 +2093,7 @@ void PhysicalBone::_notification(int p_what) { } } -void PhysicalBone::_direct_state_changed(Object *p_state) { +void PhysicalBone3D::_direct_state_changed(Object *p_state) { if (!simulate_physics || !_internal_simulate_physics) { return; @@ -2101,12 +2101,12 @@ void PhysicalBone::_direct_state_changed(Object *p_state) { /// Update bone transform - PhysicsDirectBodyState *state; + PhysicsDirectBodyState3D *state; #ifdef DEBUG_ENABLED - state = Object::cast_to<PhysicsDirectBodyState>(p_state); + state = Object::cast_to<PhysicsDirectBodyState3D>(p_state); #else - state = (PhysicsDirectBodyState *)p_state; //trust it + state = (PhysicsDirectBodyState3D *)p_state; //trust it #endif Transform global_transform(state->get_transform()); @@ -2123,45 +2123,63 @@ void PhysicalBone::_direct_state_changed(Object *p_state) { } } -void PhysicalBone::_bind_methods() { - ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &PhysicalBone::apply_central_impulse); - ClassDB::bind_method(D_METHOD("apply_impulse", "position", "impulse"), &PhysicalBone::apply_impulse); +void PhysicalBone3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &PhysicalBone3D::apply_central_impulse); + ClassDB::bind_method(D_METHOD("apply_impulse", "position", "impulse"), &PhysicalBone3D::apply_impulse); - ClassDB::bind_method(D_METHOD("_direct_state_changed"), &PhysicalBone::_direct_state_changed); + ClassDB::bind_method(D_METHOD("_direct_state_changed"), &PhysicalBone3D::_direct_state_changed); - ClassDB::bind_method(D_METHOD("set_joint_type", "joint_type"), &PhysicalBone::set_joint_type); - ClassDB::bind_method(D_METHOD("get_joint_type"), &PhysicalBone::get_joint_type); + ClassDB::bind_method(D_METHOD("set_joint_type", "joint_type"), &PhysicalBone3D::set_joint_type); + ClassDB::bind_method(D_METHOD("get_joint_type"), &PhysicalBone3D::get_joint_type); - ClassDB::bind_method(D_METHOD("set_joint_offset", "offset"), &PhysicalBone::set_joint_offset); - ClassDB::bind_method(D_METHOD("get_joint_offset"), &PhysicalBone::get_joint_offset); + ClassDB::bind_method(D_METHOD("set_joint_offset", "offset"), &PhysicalBone3D::set_joint_offset); + ClassDB::bind_method(D_METHOD("get_joint_offset"), &PhysicalBone3D::get_joint_offset); + ClassDB::bind_method(D_METHOD("set_joint_rotation", "euler"), &PhysicalBone3D::set_joint_rotation); + ClassDB::bind_method(D_METHOD("get_joint_rotation"), &PhysicalBone3D::get_joint_rotation); + ClassDB::bind_method(D_METHOD("set_joint_rotation_degrees", "euler_degrees"), &PhysicalBone3D::set_joint_rotation_degrees); + ClassDB::bind_method(D_METHOD("get_joint_rotation_degrees"), &PhysicalBone3D::get_joint_rotation_degrees); - ClassDB::bind_method(D_METHOD("set_body_offset", "offset"), &PhysicalBone::set_body_offset); - ClassDB::bind_method(D_METHOD("get_body_offset"), &PhysicalBone::get_body_offset); + ClassDB::bind_method(D_METHOD("set_body_offset", "offset"), &PhysicalBone3D::set_body_offset); + ClassDB::bind_method(D_METHOD("get_body_offset"), &PhysicalBone3D::get_body_offset); - ClassDB::bind_method(D_METHOD("get_simulate_physics"), &PhysicalBone::get_simulate_physics); + ClassDB::bind_method(D_METHOD("get_simulate_physics"), &PhysicalBone3D::get_simulate_physics); - ClassDB::bind_method(D_METHOD("is_simulating_physics"), &PhysicalBone::is_simulating_physics); + ClassDB::bind_method(D_METHOD("is_simulating_physics"), &PhysicalBone3D::is_simulating_physics); - ClassDB::bind_method(D_METHOD("get_bone_id"), &PhysicalBone::get_bone_id); + ClassDB::bind_method(D_METHOD("get_bone_id"), &PhysicalBone3D::get_bone_id); - ClassDB::bind_method(D_METHOD("set_mass", "mass"), &PhysicalBone::set_mass); - ClassDB::bind_method(D_METHOD("get_mass"), &PhysicalBone::get_mass); + ClassDB::bind_method(D_METHOD("set_mass", "mass"), &PhysicalBone3D::set_mass); + ClassDB::bind_method(D_METHOD("get_mass"), &PhysicalBone3D::get_mass); - ClassDB::bind_method(D_METHOD("set_weight", "weight"), &PhysicalBone::set_weight); - ClassDB::bind_method(D_METHOD("get_weight"), &PhysicalBone::get_weight); + ClassDB::bind_method(D_METHOD("set_weight", "weight"), &PhysicalBone3D::set_weight); + ClassDB::bind_method(D_METHOD("get_weight"), &PhysicalBone3D::get_weight); - ClassDB::bind_method(D_METHOD("set_friction", "friction"), &PhysicalBone::set_friction); - ClassDB::bind_method(D_METHOD("get_friction"), &PhysicalBone::get_friction); + ClassDB::bind_method(D_METHOD("set_friction", "friction"), &PhysicalBone3D::set_friction); + ClassDB::bind_method(D_METHOD("get_friction"), &PhysicalBone3D::get_friction); - ClassDB::bind_method(D_METHOD("set_bounce", "bounce"), &PhysicalBone::set_bounce); - ClassDB::bind_method(D_METHOD("get_bounce"), &PhysicalBone::get_bounce); + ClassDB::bind_method(D_METHOD("set_bounce", "bounce"), &PhysicalBone3D::set_bounce); + ClassDB::bind_method(D_METHOD("get_bounce"), &PhysicalBone3D::get_bounce); - ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &PhysicalBone::set_gravity_scale); - ClassDB::bind_method(D_METHOD("get_gravity_scale"), &PhysicalBone::get_gravity_scale); + ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &PhysicalBone3D::set_gravity_scale); + ClassDB::bind_method(D_METHOD("get_gravity_scale"), &PhysicalBone3D::get_gravity_scale); + + ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &PhysicalBone3D::set_linear_damp); + ClassDB::bind_method(D_METHOD("get_linear_damp"), &PhysicalBone3D::get_linear_damp); + + ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &PhysicalBone3D::set_angular_damp); + ClassDB::bind_method(D_METHOD("get_angular_damp"), &PhysicalBone3D::get_angular_damp); + + ClassDB::bind_method(D_METHOD("set_can_sleep", "able_to_sleep"), &PhysicalBone3D::set_can_sleep); + ClassDB::bind_method(D_METHOD("is_able_to_sleep"), &PhysicalBone3D::is_able_to_sleep); + + ClassDB::bind_method(D_METHOD("set_axis_lock", "axis", "lock"), &PhysicalBone3D::set_axis_lock); + ClassDB::bind_method(D_METHOD("get_axis_lock", "axis"), &PhysicalBone3D::get_axis_lock); ADD_GROUP("Joint", "joint_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "joint_type", PROPERTY_HINT_ENUM, "None,PinJoint,ConeJoint,HingeJoint,SliderJoint,6DOFJoint"), "set_joint_type", "get_joint_type"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "joint_offset"), "set_joint_offset", "get_joint_offset"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "joint_rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_joint_rotation_degrees", "get_joint_rotation_degrees"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "joint_rotation", PROPERTY_HINT_NONE, "", 0), "set_joint_rotation", "get_joint_rotation"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "body_offset"), "set_body_offset", "get_body_offset"); @@ -2170,6 +2188,17 @@ void PhysicalBone::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "friction", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_friction", "get_friction"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bounce", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_bounce", "get_bounce"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_scale", PROPERTY_HINT_RANGE, "-10,10,0.01"), "set_gravity_scale", "get_gravity_scale"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), "set_angular_damp", "get_angular_damp"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "can_sleep"), "set_can_sleep", "is_able_to_sleep"); + + ADD_GROUP("Axis Lock", "axis_lock_"); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_x"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_X); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_y"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_Y); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_z"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_Z); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_x"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_ANGULAR_X); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_y"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_ANGULAR_Y); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_z"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_ANGULAR_Z); BIND_ENUM_CONSTANT(JOINT_TYPE_NONE); BIND_ENUM_CONSTANT(JOINT_TYPE_PIN); @@ -2179,25 +2208,38 @@ void PhysicalBone::_bind_methods() { BIND_ENUM_CONSTANT(JOINT_TYPE_6DOF); } -Skeleton *PhysicalBone::find_skeleton_parent(Node *p_parent) { +Skeleton3D *PhysicalBone3D::find_skeleton_parent(Node *p_parent) { if (!p_parent) { - return NULL; + return nullptr; } - Skeleton *s = Object::cast_to<Skeleton>(p_parent); + Skeleton3D *s = Object::cast_to<Skeleton3D>(p_parent); return s ? s : find_skeleton_parent(p_parent->get_parent()); } -void PhysicalBone::_fix_joint_offset() { +void PhysicalBone3D::_update_joint_offset() { + _fix_joint_offset(); + + set_ignore_transform_notification(true); + reset_to_rest_position(); + set_ignore_transform_notification(false); + +#ifdef TOOLS_ENABLED + if (get_gizmo().is_valid()) + get_gizmo()->redraw(); +#endif +} + +void PhysicalBone3D::_fix_joint_offset() { // Clamp joint origin to bone origin if (parent_skeleton) { joint_offset.origin = body_offset.affine_inverse().origin; } } -void PhysicalBone::_reload_joint() { +void PhysicalBone3D::_reload_joint() { if (joint.is_valid()) { - PhysicsServer::get_singleton()->free(joint); + PhysicsServer3D::get_singleton()->free(joint); joint = RID(); } @@ -2205,7 +2247,7 @@ void PhysicalBone::_reload_joint() { return; } - PhysicalBone *body_a = parent_skeleton->get_physical_bone_parent(bone_id); + PhysicalBone3D *body_a = parent_skeleton->get_physical_bone_parent(bone_id); if (!body_a) { return; } @@ -2217,78 +2259,78 @@ void PhysicalBone::_reload_joint() { switch (get_joint_type()) { case JOINT_TYPE_PIN: { - joint = PhysicsServer::get_singleton()->joint_create_pin(body_a->get_rid(), local_a.origin, get_rid(), joint_offset.origin); + joint = PhysicsServer3D::get_singleton()->joint_create_pin(body_a->get_rid(), local_a.origin, get_rid(), joint_offset.origin); const PinJointData *pjd(static_cast<const PinJointData *>(joint_data)); - PhysicsServer::get_singleton()->pin_joint_set_param(joint, PhysicsServer::PIN_JOINT_BIAS, pjd->bias); - PhysicsServer::get_singleton()->pin_joint_set_param(joint, PhysicsServer::PIN_JOINT_DAMPING, pjd->damping); - PhysicsServer::get_singleton()->pin_joint_set_param(joint, PhysicsServer::PIN_JOINT_IMPULSE_CLAMP, pjd->impulse_clamp); + PhysicsServer3D::get_singleton()->pin_joint_set_param(joint, PhysicsServer3D::PIN_JOINT_BIAS, pjd->bias); + PhysicsServer3D::get_singleton()->pin_joint_set_param(joint, PhysicsServer3D::PIN_JOINT_DAMPING, pjd->damping); + PhysicsServer3D::get_singleton()->pin_joint_set_param(joint, PhysicsServer3D::PIN_JOINT_IMPULSE_CLAMP, pjd->impulse_clamp); } break; case JOINT_TYPE_CONE: { - joint = PhysicsServer::get_singleton()->joint_create_cone_twist(body_a->get_rid(), local_a, get_rid(), joint_offset); + joint = PhysicsServer3D::get_singleton()->joint_create_cone_twist(body_a->get_rid(), local_a, get_rid(), joint_offset); const ConeJointData *cjd(static_cast<const ConeJointData *>(joint_data)); - PhysicsServer::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer::CONE_TWIST_JOINT_SWING_SPAN, cjd->swing_span); - PhysicsServer::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer::CONE_TWIST_JOINT_TWIST_SPAN, cjd->twist_span); - PhysicsServer::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer::CONE_TWIST_JOINT_BIAS, cjd->bias); - PhysicsServer::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer::CONE_TWIST_JOINT_SOFTNESS, cjd->softness); - PhysicsServer::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer::CONE_TWIST_JOINT_RELAXATION, cjd->relaxation); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer3D::CONE_TWIST_JOINT_SWING_SPAN, cjd->swing_span); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer3D::CONE_TWIST_JOINT_TWIST_SPAN, cjd->twist_span); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer3D::CONE_TWIST_JOINT_BIAS, cjd->bias); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer3D::CONE_TWIST_JOINT_SOFTNESS, cjd->softness); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer3D::CONE_TWIST_JOINT_RELAXATION, cjd->relaxation); } break; case JOINT_TYPE_HINGE: { - joint = PhysicsServer::get_singleton()->joint_create_hinge(body_a->get_rid(), local_a, get_rid(), joint_offset); + joint = PhysicsServer3D::get_singleton()->joint_create_hinge(body_a->get_rid(), local_a, get_rid(), joint_offset); const HingeJointData *hjd(static_cast<const HingeJointData *>(joint_data)); - PhysicsServer::get_singleton()->hinge_joint_set_flag(joint, PhysicsServer::HINGE_JOINT_FLAG_USE_LIMIT, hjd->angular_limit_enabled); - PhysicsServer::get_singleton()->hinge_joint_set_param(joint, PhysicsServer::HINGE_JOINT_LIMIT_UPPER, hjd->angular_limit_upper); - PhysicsServer::get_singleton()->hinge_joint_set_param(joint, PhysicsServer::HINGE_JOINT_LIMIT_LOWER, hjd->angular_limit_lower); - PhysicsServer::get_singleton()->hinge_joint_set_param(joint, PhysicsServer::HINGE_JOINT_LIMIT_BIAS, hjd->angular_limit_bias); - PhysicsServer::get_singleton()->hinge_joint_set_param(joint, PhysicsServer::HINGE_JOINT_LIMIT_SOFTNESS, hjd->angular_limit_softness); - PhysicsServer::get_singleton()->hinge_joint_set_param(joint, PhysicsServer::HINGE_JOINT_LIMIT_RELAXATION, hjd->angular_limit_relaxation); + PhysicsServer3D::get_singleton()->hinge_joint_set_flag(joint, PhysicsServer3D::HINGE_JOINT_FLAG_USE_LIMIT, hjd->angular_limit_enabled); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(joint, PhysicsServer3D::HINGE_JOINT_LIMIT_UPPER, hjd->angular_limit_upper); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(joint, PhysicsServer3D::HINGE_JOINT_LIMIT_LOWER, hjd->angular_limit_lower); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(joint, PhysicsServer3D::HINGE_JOINT_LIMIT_BIAS, hjd->angular_limit_bias); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(joint, PhysicsServer3D::HINGE_JOINT_LIMIT_SOFTNESS, hjd->angular_limit_softness); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(joint, PhysicsServer3D::HINGE_JOINT_LIMIT_RELAXATION, hjd->angular_limit_relaxation); } break; case JOINT_TYPE_SLIDER: { - joint = PhysicsServer::get_singleton()->joint_create_slider(body_a->get_rid(), local_a, get_rid(), joint_offset); + joint = PhysicsServer3D::get_singleton()->joint_create_slider(body_a->get_rid(), local_a, get_rid(), joint_offset); const SliderJointData *sjd(static_cast<const SliderJointData *>(joint_data)); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER, sjd->linear_limit_upper); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_LOWER, sjd->linear_limit_lower); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS, sjd->linear_limit_softness); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION, sjd->linear_limit_restitution); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_DAMPING, sjd->linear_limit_restitution); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_UPPER, sjd->angular_limit_upper); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_LOWER, sjd->angular_limit_lower); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, sjd->angular_limit_softness); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, sjd->angular_limit_softness); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING, sjd->angular_limit_damping); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_UPPER, sjd->linear_limit_upper); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_LOWER, sjd->linear_limit_lower); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS, sjd->linear_limit_softness); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION, sjd->linear_limit_restitution); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_DAMPING, sjd->linear_limit_restitution); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_UPPER, sjd->angular_limit_upper); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_LOWER, sjd->angular_limit_lower); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, sjd->angular_limit_softness); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, sjd->angular_limit_softness); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING, sjd->angular_limit_damping); } break; case JOINT_TYPE_6DOF: { - joint = PhysicsServer::get_singleton()->joint_create_generic_6dof(body_a->get_rid(), local_a, get_rid(), joint_offset); + joint = PhysicsServer3D::get_singleton()->joint_create_generic_6dof(body_a->get_rid(), local_a, get_rid(), joint_offset); const SixDOFJointData *g6dofjd(static_cast<const SixDOFJointData *>(joint_data)); for (int axis = 0; axis < 3; ++axis) { - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, g6dofjd->axis_data[axis].linear_limit_enabled); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_UPPER_LIMIT, g6dofjd->axis_data[axis].linear_limit_upper); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_LOWER_LIMIT, g6dofjd->axis_data[axis].linear_limit_lower); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, g6dofjd->axis_data[axis].linear_limit_softness); - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING, g6dofjd->axis_data[axis].linear_spring_enabled); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS, g6dofjd->axis_data[axis].linear_spring_stiffness); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_DAMPING, g6dofjd->axis_data[axis].linear_spring_damping); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT, g6dofjd->axis_data[axis].linear_equilibrium_point); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_RESTITUTION, g6dofjd->axis_data[axis].linear_restitution); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING, g6dofjd->axis_data[axis].linear_damping); - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, g6dofjd->axis_data[axis].angular_limit_enabled); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, g6dofjd->axis_data[axis].angular_limit_upper); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, g6dofjd->axis_data[axis].angular_limit_lower); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, g6dofjd->axis_data[axis].angular_limit_softness); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_RESTITUTION, g6dofjd->axis_data[axis].angular_restitution); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_DAMPING, g6dofjd->axis_data[axis].angular_damping); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_ERP, g6dofjd->axis_data[axis].erp); - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING, g6dofjd->axis_data[axis].angular_spring_enabled); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS, g6dofjd->axis_data[axis].angular_spring_stiffness); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_DAMPING, g6dofjd->axis_data[axis].angular_spring_damping); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT, g6dofjd->axis_data[axis].angular_equilibrium_point); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, g6dofjd->axis_data[axis].linear_limit_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_UPPER_LIMIT, g6dofjd->axis_data[axis].linear_limit_upper); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_LOWER_LIMIT, g6dofjd->axis_data[axis].linear_limit_lower); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, g6dofjd->axis_data[axis].linear_limit_softness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING, g6dofjd->axis_data[axis].linear_spring_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS, g6dofjd->axis_data[axis].linear_spring_stiffness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_DAMPING, g6dofjd->axis_data[axis].linear_spring_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT, g6dofjd->axis_data[axis].linear_equilibrium_point); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_RESTITUTION, g6dofjd->axis_data[axis].linear_restitution); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_DAMPING, g6dofjd->axis_data[axis].linear_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, g6dofjd->axis_data[axis].angular_limit_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, g6dofjd->axis_data[axis].angular_limit_upper); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, g6dofjd->axis_data[axis].angular_limit_lower); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, g6dofjd->axis_data[axis].angular_limit_softness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_RESTITUTION, g6dofjd->axis_data[axis].angular_restitution); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_DAMPING, g6dofjd->axis_data[axis].angular_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_ERP, g6dofjd->axis_data[axis].erp); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING, g6dofjd->axis_data[axis].angular_spring_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS, g6dofjd->axis_data[axis].angular_spring_stiffness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_DAMPING, g6dofjd->axis_data[axis].angular_spring_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT, g6dofjd->axis_data[axis].angular_equilibrium_point); } } break; @@ -2297,43 +2339,43 @@ void PhysicalBone::_reload_joint() { } } -void PhysicalBone::_on_bone_parent_changed() { +void PhysicalBone3D::_on_bone_parent_changed() { _reload_joint(); } -void PhysicalBone::_set_gizmo_move_joint(bool p_move_joint) { +void PhysicalBone3D::_set_gizmo_move_joint(bool p_move_joint) { #ifdef TOOLS_ENABLED gizmo_move_joint = p_move_joint; - SpatialEditor::get_singleton()->update_transform_gizmo(); + Node3DEditor::get_singleton()->update_transform_gizmo(); #endif } #ifdef TOOLS_ENABLED -Transform PhysicalBone::get_global_gizmo_transform() const { +Transform PhysicalBone3D::get_global_gizmo_transform() const { return gizmo_move_joint ? get_global_transform() * joint_offset : get_global_transform(); } -Transform PhysicalBone::get_local_gizmo_transform() const { +Transform PhysicalBone3D::get_local_gizmo_transform() const { return gizmo_move_joint ? get_transform() * joint_offset : get_transform(); } #endif -const PhysicalBone::JointData *PhysicalBone::get_joint_data() const { +const PhysicalBone3D::JointData *PhysicalBone3D::get_joint_data() const { return joint_data; } -Skeleton *PhysicalBone::find_skeleton_parent() { +Skeleton3D *PhysicalBone3D::find_skeleton_parent() { return find_skeleton_parent(this); } -void PhysicalBone::set_joint_type(JointType p_joint_type) { +void PhysicalBone3D::set_joint_type(JointType p_joint_type) { if (p_joint_type == get_joint_type()) return; if (joint_data) memdelete(joint_data); - joint_data = NULL; + joint_data = nullptr; switch (p_joint_type) { case JOINT_TYPE_PIN: joint_data = memnew(PinJointData); @@ -2363,50 +2405,52 @@ void PhysicalBone::set_joint_type(JointType p_joint_type) { #endif } -PhysicalBone::JointType PhysicalBone::get_joint_type() const { +PhysicalBone3D::JointType PhysicalBone3D::get_joint_type() const { return joint_data ? joint_data->get_joint_type() : JOINT_TYPE_NONE; } -void PhysicalBone::set_joint_offset(const Transform &p_offset) { +void PhysicalBone3D::set_joint_offset(const Transform &p_offset) { joint_offset = p_offset; - _fix_joint_offset(); - - set_ignore_transform_notification(true); - reset_to_rest_position(); - set_ignore_transform_notification(false); + _update_joint_offset(); + _change_notify("joint_rotation_degrees"); +} -#ifdef TOOLS_ENABLED - if (get_gizmo().is_valid()) - get_gizmo()->redraw(); -#endif +const Transform &PhysicalBone3D::get_joint_offset() const { + return joint_offset; } -const Transform &PhysicalBone::get_body_offset() const { - return body_offset; +void PhysicalBone3D::set_joint_rotation(const Vector3 &p_euler_rad) { + joint_offset.basis.set_euler_scale(p_euler_rad, joint_offset.basis.get_scale()); + + _update_joint_offset(); + _change_notify("joint_offset"); } -void PhysicalBone::set_body_offset(const Transform &p_offset) { - body_offset = p_offset; - body_offset_inverse = body_offset.affine_inverse(); +Vector3 PhysicalBone3D::get_joint_rotation() const { + return joint_offset.basis.get_rotation(); +} - _fix_joint_offset(); +void PhysicalBone3D::set_joint_rotation_degrees(const Vector3 &p_euler_deg) { + set_joint_rotation(p_euler_deg * Math_PI / 180.0); +} - set_ignore_transform_notification(true); - reset_to_rest_position(); - set_ignore_transform_notification(false); +Vector3 PhysicalBone3D::get_joint_rotation_degrees() const { + return get_joint_rotation() * 180.0 / Math_PI; +} -#ifdef TOOLS_ENABLED - if (get_gizmo().is_valid()) - get_gizmo()->redraw(); -#endif +const Transform &PhysicalBone3D::get_body_offset() const { + return body_offset; } -const Transform &PhysicalBone::get_joint_offset() const { - return joint_offset; +void PhysicalBone3D::set_body_offset(const Transform &p_offset) { + body_offset = p_offset; + body_offset_inverse = body_offset.affine_inverse(); + + _update_joint_offset(); } -void PhysicalBone::set_simulate_physics(bool p_simulate) { +void PhysicalBone3D::set_simulate_physics(bool p_simulate) { if (simulate_physics == p_simulate) { return; } @@ -2415,15 +2459,15 @@ void PhysicalBone::set_simulate_physics(bool p_simulate) { reset_physics_simulation_state(); } -bool PhysicalBone::get_simulate_physics() { +bool PhysicalBone3D::get_simulate_physics() { return simulate_physics; } -bool PhysicalBone::is_simulating_physics() { +bool PhysicalBone3D::is_simulating_physics() { return _internal_simulate_physics; } -void PhysicalBone::set_bone_name(const String &p_name) { +void PhysicalBone3D::set_bone_name(const String &p_name) { bone_name = p_name; bone_id = -1; @@ -2432,77 +2476,114 @@ void PhysicalBone::set_bone_name(const String &p_name) { reset_to_rest_position(); } -const String &PhysicalBone::get_bone_name() const { +const String &PhysicalBone3D::get_bone_name() const { return bone_name; } -void PhysicalBone::set_mass(real_t p_mass) { +void PhysicalBone3D::set_mass(real_t p_mass) { ERR_FAIL_COND(p_mass <= 0); mass = p_mass; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_MASS, mass); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_MASS, mass); } -real_t PhysicalBone::get_mass() const { +real_t PhysicalBone3D::get_mass() const { return mass; } -void PhysicalBone::set_weight(real_t p_weight) { +void PhysicalBone3D::set_weight(real_t p_weight) { set_mass(p_weight / real_t(GLOBAL_DEF("physics/3d/default_gravity", 9.8))); } -real_t PhysicalBone::get_weight() const { +real_t PhysicalBone3D::get_weight() const { return mass * real_t(GLOBAL_DEF("physics/3d/default_gravity", 9.8)); } -void PhysicalBone::set_friction(real_t p_friction) { +void PhysicalBone3D::set_friction(real_t p_friction) { ERR_FAIL_COND(p_friction < 0 || p_friction > 1); friction = p_friction; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, friction); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_FRICTION, friction); } -real_t PhysicalBone::get_friction() const { +real_t PhysicalBone3D::get_friction() const { return friction; } -void PhysicalBone::set_bounce(real_t p_bounce) { +void PhysicalBone3D::set_bounce(real_t p_bounce) { ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1); bounce = p_bounce; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, bounce); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_BOUNCE, bounce); } -real_t PhysicalBone::get_bounce() const { +real_t PhysicalBone3D::get_bounce() const { return bounce; } -void PhysicalBone::set_gravity_scale(real_t p_gravity_scale) { +void PhysicalBone3D::set_gravity_scale(real_t p_gravity_scale) { gravity_scale = p_gravity_scale; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_GRAVITY_SCALE, gravity_scale); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_GRAVITY_SCALE, gravity_scale); } -real_t PhysicalBone::get_gravity_scale() const { +real_t PhysicalBone3D::get_gravity_scale() const { return gravity_scale; } -PhysicalBone::PhysicalBone() : - PhysicsBody(PhysicsServer::BODY_MODE_STATIC), +void PhysicalBone3D::set_linear_damp(real_t p_linear_damp) { + ERR_FAIL_COND(p_linear_damp < -1); + linear_damp = p_linear_damp; + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_LINEAR_DAMP, linear_damp); +} + +real_t PhysicalBone3D::get_linear_damp() const { + return linear_damp; +} + +void PhysicalBone3D::set_angular_damp(real_t p_angular_damp) { + ERR_FAIL_COND(p_angular_damp < -1); + angular_damp = p_angular_damp; + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP, angular_damp); +} + +real_t PhysicalBone3D::get_angular_damp() const { + return angular_damp; +} + +void PhysicalBone3D::set_can_sleep(bool p_active) { + can_sleep = p_active; + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_CAN_SLEEP, p_active); +} + +bool PhysicalBone3D::is_able_to_sleep() const { + return can_sleep; +} + +void PhysicalBone3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock) { + PhysicsServer3D::get_singleton()->body_set_axis_lock(get_rid(), p_axis, p_lock); +} + +bool PhysicalBone3D::get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const { + return PhysicsServer3D::get_singleton()->body_is_axis_locked(get_rid(), p_axis); +} + +PhysicalBone3D::PhysicalBone3D() : + PhysicsBody3D(PhysicsServer3D::BODY_MODE_STATIC), #ifdef TOOLS_ENABLED gizmo_move_joint(false), #endif - joint_data(NULL), - parent_skeleton(NULL), + joint_data(nullptr), + parent_skeleton(nullptr), simulate_physics(false), _internal_simulate_physics(false), bone_id(-1), @@ -2510,17 +2591,20 @@ PhysicalBone::PhysicalBone() : bounce(0), mass(1), friction(1), - gravity_scale(1) { + gravity_scale(1), + linear_damp(-1), + angular_damp(-1), + can_sleep(true) { reset_physics_simulation_state(); } -PhysicalBone::~PhysicalBone() { +PhysicalBone3D::~PhysicalBone3D() { if (joint_data) memdelete(joint_data); } -void PhysicalBone::update_bone_id() { +void PhysicalBone3D::update_bone_id() { if (!parent_skeleton) { return; } @@ -2543,7 +2627,7 @@ void PhysicalBone::update_bone_id() { } } -void PhysicalBone::update_offset() { +void PhysicalBone3D::update_offset() { #ifdef TOOLS_ENABLED if (parent_skeleton) { @@ -2561,34 +2645,34 @@ void PhysicalBone::update_offset() { #endif } -void PhysicalBone::_start_physics_simulation() { +void PhysicalBone3D::_start_physics_simulation() { if (_internal_simulate_physics || !parent_skeleton) { return; } reset_to_rest_position(); - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_RIGID); - PhysicsServer::get_singleton()->body_set_collision_layer(get_rid(), get_collision_layer()); - PhysicsServer::get_singleton()->body_set_collision_mask(get_rid(), get_collision_mask()); - PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_RIGID); + PhysicsServer3D::get_singleton()->body_set_collision_layer(get_rid(), get_collision_layer()); + PhysicsServer3D::get_singleton()->body_set_collision_mask(get_rid(), get_collision_mask()); + PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); set_as_toplevel(true); _internal_simulate_physics = true; } -void PhysicalBone::_stop_physics_simulation() { +void PhysicalBone3D::_stop_physics_simulation() { if (!parent_skeleton) { return; } if (parent_skeleton->get_animate_physical_bones()) { - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_KINEMATIC); - PhysicsServer::get_singleton()->body_set_collision_layer(get_rid(), get_collision_layer()); - PhysicsServer::get_singleton()->body_set_collision_mask(get_rid(), get_collision_mask()); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_KINEMATIC); + PhysicsServer3D::get_singleton()->body_set_collision_layer(get_rid(), get_collision_layer()); + PhysicsServer3D::get_singleton()->body_set_collision_mask(get_rid(), get_collision_mask()); } else { - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_STATIC); - PhysicsServer::get_singleton()->body_set_collision_layer(get_rid(), 0); - PhysicsServer::get_singleton()->body_set_collision_mask(get_rid(), 0); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_STATIC); + PhysicsServer3D::get_singleton()->body_set_collision_layer(get_rid(), 0); + PhysicsServer3D::get_singleton()->body_set_collision_mask(get_rid(), 0); } if (_internal_simulate_physics) { - PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(), NULL, ""); + PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), nullptr, ""); parent_skeleton->set_bone_global_pose_override(bone_id, Transform(), 0.0, false); set_as_toplevel(false); _internal_simulate_physics = false; diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body_3d.h index 90de1ffce6..0e719f5108 100644 --- a/scene/3d/physics_body.h +++ b/scene/3d/physics_body_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* physics_body.h */ +/* physics_body_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,18 +28,18 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef PHYSICS_BODY__H -#define PHYSICS_BODY__H +#ifndef PHYSICS_BODY_3D_H +#define PHYSICS_BODY_3D_H #include "core/vset.h" -#include "scene/3d/collision_object.h" +#include "scene/3d/collision_object_3d.h" #include "scene/resources/physics_material.h" -#include "servers/physics_server.h" -#include "skeleton.h" +#include "servers/physics_server_3d.h" +#include "skeleton_3d.h" -class PhysicsBody : public CollisionObject { +class PhysicsBody3D : public CollisionObject3D { - GDCLASS(PhysicsBody, CollisionObject); + GDCLASS(PhysicsBody3D, CollisionObject3D); uint32_t collision_layer; uint32_t collision_mask; @@ -49,7 +49,7 @@ class PhysicsBody : public CollisionObject { protected: static void _bind_methods(); - PhysicsBody(PhysicsServer::BodyMode p_mode); + PhysicsBody3D(PhysicsServer3D::BodyMode p_mode); public: virtual Vector3 get_linear_velocity() const; @@ -68,16 +68,16 @@ public: void set_collision_mask_bit(int p_bit, bool p_value); bool get_collision_mask_bit(int p_bit) const; - Array get_collision_exceptions(); + TypedArray<PhysicsBody3D> get_collision_exceptions(); void add_collision_exception_with(Node *p_node); //must be physicsbody void remove_collision_exception_with(Node *p_node); - PhysicsBody(); + PhysicsBody3D(); }; -class StaticBody : public PhysicsBody { +class StaticBody3D : public PhysicsBody3D { - GDCLASS(StaticBody, PhysicsBody); + GDCLASS(StaticBody3D, PhysicsBody3D); Vector3 constant_linear_velocity; Vector3 constant_angular_velocity; @@ -97,16 +97,16 @@ public: Vector3 get_constant_linear_velocity() const; Vector3 get_constant_angular_velocity() const; - StaticBody(); - ~StaticBody(); + StaticBody3D(); + ~StaticBody3D(); private: void _reload_physics_characteristics(); }; -class RigidBody : public PhysicsBody { +class RigidBody3D : public PhysicsBody3D { - GDCLASS(RigidBody, PhysicsBody); + GDCLASS(RigidBody3D, PhysicsBody3D); public: enum Mode { @@ -118,7 +118,7 @@ public: protected: bool can_sleep; - PhysicsDirectBodyState *state; + PhysicsDirectBodyState3D *state; Mode mode; real_t mass; @@ -156,7 +156,7 @@ protected: tagged = false; } }; - struct RigidBody_RemoveAction { + struct RigidBody3D_RemoveAction { ObjectID body_id; ShapePair pair; @@ -234,8 +234,8 @@ public: void set_use_continuous_collision_detection(bool p_enable); bool is_using_continuous_collision_detection() const; - void set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock); - bool get_axis_lock(PhysicsServer::BodyAxis p_axis) const; + void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock); + bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const; Array get_colliding_bodies() const; @@ -249,20 +249,20 @@ public: virtual String get_configuration_warning() const; - RigidBody(); - ~RigidBody(); + RigidBody3D(); + ~RigidBody3D(); private: void _reload_physics_characteristics(); }; -VARIANT_ENUM_CAST(RigidBody::Mode); +VARIANT_ENUM_CAST(RigidBody3D::Mode); -class KinematicCollision; +class KinematicCollision3D; -class KinematicBody : public PhysicsBody { +class KinematicBody3D : public PhysicsBody3D { - GDCLASS(KinematicBody, PhysicsBody); + GDCLASS(KinematicBody3D, PhysicsBody3D); public: struct Collision { @@ -293,13 +293,13 @@ private: bool on_ceiling; bool on_wall; Vector<Collision> colliders; - Vector<Ref<KinematicCollision>> slide_colliders; - Ref<KinematicCollision> motion_cache; + Vector<Ref<KinematicCollision3D>> slide_colliders; + Ref<KinematicCollision3D> motion_cache; - _FORCE_INLINE_ bool _ignores_mode(PhysicsServer::BodyMode) const; + _FORCE_INLINE_ bool _ignores_mode(PhysicsServer3D::BodyMode) const; - Ref<KinematicCollision> _move(const Vector3 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false); - Ref<KinematicCollision> _get_slide_collision(int p_bounce); + Ref<KinematicCollision3D> _move(const Vector3 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false); + Ref<KinematicCollision3D> _get_slide_collision(int p_bounce); protected: void _notification(int p_what); @@ -316,8 +316,8 @@ public: bool separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision); - void set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock); - bool get_axis_lock(PhysicsServer::BodyAxis p_axis) const; + void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock); + bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const; void set_safe_margin(float p_margin); float get_safe_margin() const; @@ -333,17 +333,17 @@ public: int get_slide_count() const; Collision get_slide_collision(int p_bounce) const; - KinematicBody(); - ~KinematicBody(); + KinematicBody3D(); + ~KinematicBody3D(); }; -class KinematicCollision : public Reference { +class KinematicCollision3D : public Reference { - GDCLASS(KinematicCollision, Reference); + GDCLASS(KinematicCollision3D, Reference); - KinematicBody *owner; - friend class KinematicBody; - KinematicBody::Collision collision; + KinematicBody3D *owner; + friend class KinematicBody3D; + KinematicBody3D::Collision collision; protected: static void _bind_methods(); @@ -361,12 +361,12 @@ public: Vector3 get_collider_velocity() const; Variant get_collider_metadata() const; - KinematicCollision(); + KinematicCollision3D(); }; -class PhysicalBone : public PhysicsBody { +class PhysicalBone3D : public PhysicsBody3D { - GDCLASS(PhysicalBone, PhysicsBody); + GDCLASS(PhysicalBone3D, PhysicsBody3D); public: enum JointType { @@ -381,7 +381,7 @@ public: struct JointData { virtual JointType get_joint_type() { return JOINT_TYPE_NONE; } - /// "j" is used to set the parameter inside the PhysicsServer + /// "j" is used to set the parameter inside the PhysicsServer3D virtual bool _set(const StringName &p_name, const Variant &p_value, RID j = RID()); virtual bool _get(const StringName &p_name, Variant &r_ret) const; virtual void _get_property_list(List<PropertyInfo> *p_list) const; @@ -550,7 +550,7 @@ private: Transform joint_offset; RID joint; - Skeleton *parent_skeleton; + Skeleton3D *parent_skeleton; Transform body_offset; Transform body_offset_inverse; bool simulate_physics; @@ -562,6 +562,9 @@ private: real_t mass; real_t friction; real_t gravity_scale; + real_t linear_damp; + real_t angular_damp; + bool can_sleep; protected: bool _set(const StringName &p_name, const Variant &p_value); @@ -573,8 +576,9 @@ protected: static void _bind_methods(); private: - static Skeleton *find_skeleton_parent(Node *p_parent); + static Skeleton3D *find_skeleton_parent(Node *p_parent); + void _update_joint_offset(); void _fix_joint_offset(); void _reload_joint(); @@ -589,7 +593,7 @@ public: #endif const JointData *get_joint_data() const; - Skeleton *find_skeleton_parent(); + Skeleton3D *find_skeleton_parent(); int get_bone_id() const { return bone_id; } @@ -599,6 +603,12 @@ public: void set_joint_offset(const Transform &p_offset); const Transform &get_joint_offset() const; + void set_joint_rotation(const Vector3 &p_euler_rad); + Vector3 get_joint_rotation() const; + + void set_joint_rotation_degrees(const Vector3 &p_euler_deg); + Vector3 get_joint_rotation_degrees() const; + void set_body_offset(const Transform &p_offset); const Transform &get_body_offset() const; @@ -624,14 +634,26 @@ public: void set_gravity_scale(real_t p_gravity_scale); real_t get_gravity_scale() const; + void set_linear_damp(real_t p_linear_damp); + real_t get_linear_damp() const; + + void set_angular_damp(real_t p_angular_damp); + real_t get_angular_damp() const; + + void set_can_sleep(bool p_active); + bool is_able_to_sleep() const; + + void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock); + bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const; + void apply_central_impulse(const Vector3 &p_impulse); void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse); void reset_physics_simulation_state(); void reset_to_rest_position(); - PhysicalBone(); - ~PhysicalBone(); + PhysicalBone3D(); + ~PhysicalBone3D(); private: void update_bone_id(); @@ -641,6 +663,6 @@ private: void _stop_physics_simulation(); }; -VARIANT_ENUM_CAST(PhysicalBone::JointType); +VARIANT_ENUM_CAST(PhysicalBone3D::JointType); #endif // PHYSICS_BODY__H diff --git a/scene/3d/physics_joint.h b/scene/3d/physics_joint.h deleted file mode 100644 index d03dbac392..0000000000 --- a/scene/3d/physics_joint.h +++ /dev/null @@ -1,343 +0,0 @@ -/*************************************************************************/ -/* physics_joint.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 PHYSICS_JOINT_H -#define PHYSICS_JOINT_H - -#include "scene/3d/physics_body.h" -#include "scene/3d/spatial.h" - -class Joint : public Spatial { - - GDCLASS(Joint, Spatial); - - RID ba, bb; - - RID joint; - - NodePath a; - NodePath b; - - int solver_priority; - bool exclude_from_collision; - -protected: - void _update_joint(bool p_only_free = false); - - void _notification(int p_what); - - virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) = 0; - - static void _bind_methods(); - -public: - void set_node_a(const NodePath &p_node_a); - NodePath get_node_a() const; - - void set_node_b(const NodePath &p_node_b); - NodePath get_node_b() const; - - void set_solver_priority(int p_priority); - int get_solver_priority() const; - - void set_exclude_nodes_from_collision(bool p_enable); - bool get_exclude_nodes_from_collision() const; - - RID get_joint() const { return joint; } - Joint(); -}; - -/////////////////////////////////////////// - -class PinJoint : public Joint { - - GDCLASS(PinJoint, Joint); - -public: - enum Param { - PARAM_BIAS = PhysicsServer::PIN_JOINT_BIAS, - PARAM_DAMPING = PhysicsServer::PIN_JOINT_DAMPING, - PARAM_IMPULSE_CLAMP = PhysicsServer::PIN_JOINT_IMPULSE_CLAMP - }; - -protected: - float params[3]; - virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b); - static void _bind_methods(); - -public: - void set_param(Param p_param, float p_value); - float get_param(Param p_param) const; - - PinJoint(); -}; - -VARIANT_ENUM_CAST(PinJoint::Param); - -class HingeJoint : public Joint { - - GDCLASS(HingeJoint, Joint); - -public: - enum Param { - PARAM_BIAS = PhysicsServer::HINGE_JOINT_BIAS, - PARAM_LIMIT_UPPER = PhysicsServer::HINGE_JOINT_LIMIT_UPPER, - PARAM_LIMIT_LOWER = PhysicsServer::HINGE_JOINT_LIMIT_LOWER, - PARAM_LIMIT_BIAS = PhysicsServer::HINGE_JOINT_LIMIT_BIAS, - PARAM_LIMIT_SOFTNESS = PhysicsServer::HINGE_JOINT_LIMIT_SOFTNESS, - PARAM_LIMIT_RELAXATION = PhysicsServer::HINGE_JOINT_LIMIT_RELAXATION, - PARAM_MOTOR_TARGET_VELOCITY = PhysicsServer::HINGE_JOINT_MOTOR_TARGET_VELOCITY, - PARAM_MOTOR_MAX_IMPULSE = PhysicsServer::HINGE_JOINT_MOTOR_MAX_IMPULSE, - PARAM_MAX = PhysicsServer::HINGE_JOINT_MAX - }; - - enum Flag { - FLAG_USE_LIMIT = PhysicsServer::HINGE_JOINT_FLAG_USE_LIMIT, - FLAG_ENABLE_MOTOR = PhysicsServer::HINGE_JOINT_FLAG_ENABLE_MOTOR, - FLAG_MAX = PhysicsServer::HINGE_JOINT_FLAG_MAX - }; - -protected: - float params[PARAM_MAX]; - bool flags[FLAG_MAX]; - virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b); - static void _bind_methods(); - - void _set_upper_limit(float p_limit); - float _get_upper_limit() const; - - void _set_lower_limit(float p_limit); - float _get_lower_limit() const; - -public: - void set_param(Param p_param, float p_value); - float get_param(Param p_param) const; - - void set_flag(Flag p_flag, bool p_value); - bool get_flag(Flag p_flag) const; - - HingeJoint(); -}; - -VARIANT_ENUM_CAST(HingeJoint::Param); -VARIANT_ENUM_CAST(HingeJoint::Flag); - -class SliderJoint : public Joint { - - GDCLASS(SliderJoint, Joint); - -public: - enum Param { - PARAM_LINEAR_LIMIT_UPPER = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER, - PARAM_LINEAR_LIMIT_LOWER = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_LOWER, - PARAM_LINEAR_LIMIT_SOFTNESS = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS, - PARAM_LINEAR_LIMIT_RESTITUTION = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION, - PARAM_LINEAR_LIMIT_DAMPING = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_DAMPING, - PARAM_LINEAR_MOTION_SOFTNESS = PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS, - PARAM_LINEAR_MOTION_RESTITUTION = PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION, - PARAM_LINEAR_MOTION_DAMPING = PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_DAMPING, - PARAM_LINEAR_ORTHOGONAL_SOFTNESS = PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS, - PARAM_LINEAR_ORTHOGONAL_RESTITUTION = PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION, - PARAM_LINEAR_ORTHOGONAL_DAMPING = PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING, - - PARAM_ANGULAR_LIMIT_UPPER = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_UPPER, - PARAM_ANGULAR_LIMIT_LOWER = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_LOWER, - PARAM_ANGULAR_LIMIT_SOFTNESS = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, - PARAM_ANGULAR_LIMIT_RESTITUTION = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION, - PARAM_ANGULAR_LIMIT_DAMPING = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING, - PARAM_ANGULAR_MOTION_SOFTNESS = PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS, - PARAM_ANGULAR_MOTION_RESTITUTION = PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION, - PARAM_ANGULAR_MOTION_DAMPING = PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_DAMPING, - PARAM_ANGULAR_ORTHOGONAL_SOFTNESS = PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS, - PARAM_ANGULAR_ORTHOGONAL_RESTITUTION = PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION, - PARAM_ANGULAR_ORTHOGONAL_DAMPING = PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING, - PARAM_MAX = PhysicsServer::SLIDER_JOINT_MAX - - }; - -protected: - void _set_upper_limit_angular(float p_limit_angular); - float _get_upper_limit_angular() const; - - void _set_lower_limit_angular(float p_limit_angular); - float _get_lower_limit_angular() const; - - float params[PARAM_MAX]; - virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b); - static void _bind_methods(); - -public: - void set_param(Param p_param, float p_value); - float get_param(Param p_param) const; - - SliderJoint(); -}; - -VARIANT_ENUM_CAST(SliderJoint::Param); - -class ConeTwistJoint : public Joint { - - GDCLASS(ConeTwistJoint, Joint); - -public: - enum Param { - - PARAM_SWING_SPAN, - PARAM_TWIST_SPAN, - PARAM_BIAS, - PARAM_SOFTNESS, - PARAM_RELAXATION, - PARAM_MAX - }; - -protected: - void _set_swing_span(float p_limit_angular); - float _get_swing_span() const; - - void _set_twist_span(float p_limit_angular); - float _get_twist_span() const; - - float params[PARAM_MAX]; - virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b); - static void _bind_methods(); - -public: - void set_param(Param p_param, float p_value); - float get_param(Param p_param) const; - - ConeTwistJoint(); -}; - -VARIANT_ENUM_CAST(ConeTwistJoint::Param); - -class Generic6DOFJoint : public Joint { - - GDCLASS(Generic6DOFJoint, Joint); - -public: - enum Param { - - PARAM_LINEAR_LOWER_LIMIT = PhysicsServer::G6DOF_JOINT_LINEAR_LOWER_LIMIT, - PARAM_LINEAR_UPPER_LIMIT = PhysicsServer::G6DOF_JOINT_LINEAR_UPPER_LIMIT, - PARAM_LINEAR_LIMIT_SOFTNESS = PhysicsServer::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, - PARAM_LINEAR_RESTITUTION = PhysicsServer::G6DOF_JOINT_LINEAR_RESTITUTION, - PARAM_LINEAR_DAMPING = PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING, - PARAM_LINEAR_MOTOR_TARGET_VELOCITY = PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY, - PARAM_LINEAR_MOTOR_FORCE_LIMIT = PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT, - PARAM_LINEAR_SPRING_STIFFNESS = PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS, - PARAM_LINEAR_SPRING_DAMPING = PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_DAMPING, - PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT = PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT, - PARAM_ANGULAR_LOWER_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, - PARAM_ANGULAR_UPPER_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, - PARAM_ANGULAR_LIMIT_SOFTNESS = PhysicsServer::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, - PARAM_ANGULAR_DAMPING = PhysicsServer::G6DOF_JOINT_ANGULAR_DAMPING, - PARAM_ANGULAR_RESTITUTION = PhysicsServer::G6DOF_JOINT_ANGULAR_RESTITUTION, - PARAM_ANGULAR_FORCE_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_FORCE_LIMIT, - PARAM_ANGULAR_ERP = PhysicsServer::G6DOF_JOINT_ANGULAR_ERP, - PARAM_ANGULAR_MOTOR_TARGET_VELOCITY = PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY, - PARAM_ANGULAR_MOTOR_FORCE_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT, - PARAM_ANGULAR_SPRING_STIFFNESS = PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS, - PARAM_ANGULAR_SPRING_DAMPING = PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_DAMPING, - PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT = PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT, - PARAM_MAX = PhysicsServer::G6DOF_JOINT_MAX, - }; - - enum Flag { - FLAG_ENABLE_LINEAR_LIMIT = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, - FLAG_ENABLE_ANGULAR_LIMIT = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, - FLAG_ENABLE_LINEAR_SPRING = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING, - FLAG_ENABLE_ANGULAR_SPRING = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING, - FLAG_ENABLE_MOTOR = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_MOTOR, - FLAG_ENABLE_LINEAR_MOTOR = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR, - FLAG_MAX = PhysicsServer::G6DOF_JOINT_FLAG_MAX - }; - -protected: - void _set_angular_hi_limit_x(float p_limit_angular); - float _get_angular_hi_limit_x() const; - - void _set_angular_hi_limit_y(float p_limit_angular); - float _get_angular_hi_limit_y() const; - - void _set_angular_hi_limit_z(float p_limit_angular); - float _get_angular_hi_limit_z() const; - - void _set_angular_lo_limit_x(float p_limit_angular); - float _get_angular_lo_limit_x() const; - - void _set_angular_lo_limit_y(float p_limit_angular); - float _get_angular_lo_limit_y() const; - - void _set_angular_lo_limit_z(float p_limit_angular); - float _get_angular_lo_limit_z() const; - - float params_x[PARAM_MAX]; - bool flags_x[FLAG_MAX]; - float params_y[PARAM_MAX]; - bool flags_y[FLAG_MAX]; - float params_z[PARAM_MAX]; - bool flags_z[FLAG_MAX]; - - int precision; - - virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b); - static void _bind_methods(); - -public: - void set_param_x(Param p_param, float p_value); - float get_param_x(Param p_param) const; - - void set_param_y(Param p_param, float p_value); - float get_param_y(Param p_param) const; - - void set_param_z(Param p_param, float p_value); - float get_param_z(Param p_param) const; - - void set_flag_x(Flag p_flag, bool p_enabled); - bool get_flag_x(Flag p_flag) const; - - void set_flag_y(Flag p_flag, bool p_enabled); - bool get_flag_y(Flag p_flag) const; - - void set_flag_z(Flag p_flag, bool p_enabled); - bool get_flag_z(Flag p_flag) const; - - void set_precision(int p_precision); - int get_precision() const { - return precision; - } - - Generic6DOFJoint(); -}; - -VARIANT_ENUM_CAST(Generic6DOFJoint::Param); -VARIANT_ENUM_CAST(Generic6DOFJoint::Flag); - -#endif // PHYSICS_JOINT_H diff --git a/scene/3d/physics_joint.cpp b/scene/3d/physics_joint_3d.cpp index 0699e366e0..591c17a91e 100644 --- a/scene/3d/physics_joint.cpp +++ b/scene/3d/physics_joint_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* physics_joint.cpp */ +/* physics_joint_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "physics_joint.h" +#include "physics_joint_3d.h" -void Joint::_update_joint(bool p_only_free) { +void Joint3D::_update_joint(bool p_only_free) { if (joint.is_valid()) { if (ba.is_valid() && bb.is_valid()) - PhysicsServer::get_singleton()->body_remove_collision_exception(ba, bb); + PhysicsServer3D::get_singleton()->body_remove_collision_exception(ba, bb); - PhysicsServer::get_singleton()->free(joint); + PhysicsServer3D::get_singleton()->free(joint); joint = RID(); ba = RID(); bb = RID(); @@ -45,11 +45,11 @@ void Joint::_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; - PhysicsBody *body_a = Object::cast_to<PhysicsBody>(node_a); - PhysicsBody *body_b = Object::cast_to<PhysicsBody>(node_b); + PhysicsBody3D *body_a = Object::cast_to<PhysicsBody3D>(node_a); + PhysicsBody3D *body_b = Object::cast_to<PhysicsBody3D>(node_b); if (!body_a && body_b) SWAP(body_a, body_b); @@ -62,16 +62,16 @@ void Joint::_update_joint(bool p_only_free) { if (!joint.is_valid()) return; - PhysicsServer::get_singleton()->joint_set_solver_priority(joint, solver_priority); + PhysicsServer3D::get_singleton()->joint_set_solver_priority(joint, solver_priority); ba = body_a->get_rid(); if (body_b) bb = body_b->get_rid(); - PhysicsServer::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision); + PhysicsServer3D::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision); } -void Joint::set_node_a(const NodePath &p_node_a) { +void Joint3D::set_node_a(const NodePath &p_node_a) { if (a == p_node_a) return; @@ -80,36 +80,36 @@ void Joint::set_node_a(const NodePath &p_node_a) { _update_joint(); } -NodePath Joint::get_node_a() const { +NodePath Joint3D::get_node_a() const { return a; } -void Joint::set_node_b(const NodePath &p_node_b) { +void Joint3D::set_node_b(const NodePath &p_node_b) { if (b == p_node_b) return; b = p_node_b; _update_joint(); } -NodePath Joint::get_node_b() const { +NodePath Joint3D::get_node_b() const { return b; } -void Joint::set_solver_priority(int p_priority) { +void Joint3D::set_solver_priority(int p_priority) { solver_priority = p_priority; if (joint.is_valid()) - PhysicsServer::get_singleton()->joint_set_solver_priority(joint, solver_priority); + PhysicsServer3D::get_singleton()->joint_set_solver_priority(joint, solver_priority); } -int Joint::get_solver_priority() const { +int Joint3D::get_solver_priority() const { return solver_priority; } -void Joint::_notification(int p_what) { +void Joint3D::_notification(int p_what) { switch (p_what) { @@ -124,7 +124,7 @@ void Joint::_notification(int p_what) { } } -void Joint::set_exclude_nodes_from_collision(bool p_enable) { +void Joint3D::set_exclude_nodes_from_collision(bool p_enable) { if (exclude_from_collision == p_enable) return; @@ -132,33 +132,33 @@ void Joint::set_exclude_nodes_from_collision(bool p_enable) { _update_joint(); } -bool Joint::get_exclude_nodes_from_collision() const { +bool Joint3D::get_exclude_nodes_from_collision() const { return exclude_from_collision; } -void Joint::_bind_methods() { +void Joint3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint::set_node_a); - ClassDB::bind_method(D_METHOD("get_node_a"), &Joint::get_node_a); + ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint3D::set_node_a); + ClassDB::bind_method(D_METHOD("get_node_a"), &Joint3D::get_node_a); - ClassDB::bind_method(D_METHOD("set_node_b", "node"), &Joint::set_node_b); - ClassDB::bind_method(D_METHOD("get_node_b"), &Joint::get_node_b); + ClassDB::bind_method(D_METHOD("set_node_b", "node"), &Joint3D::set_node_b); + ClassDB::bind_method(D_METHOD("get_node_b"), &Joint3D::get_node_b); - ClassDB::bind_method(D_METHOD("set_solver_priority", "priority"), &Joint::set_solver_priority); - ClassDB::bind_method(D_METHOD("get_solver_priority"), &Joint::get_solver_priority); + ClassDB::bind_method(D_METHOD("set_solver_priority", "priority"), &Joint3D::set_solver_priority); + ClassDB::bind_method(D_METHOD("get_solver_priority"), &Joint3D::get_solver_priority); - ClassDB::bind_method(D_METHOD("set_exclude_nodes_from_collision", "enable"), &Joint::set_exclude_nodes_from_collision); - ClassDB::bind_method(D_METHOD("get_exclude_nodes_from_collision"), &Joint::get_exclude_nodes_from_collision); + ClassDB::bind_method(D_METHOD("set_exclude_nodes_from_collision", "enable"), &Joint3D::set_exclude_nodes_from_collision); + ClassDB::bind_method(D_METHOD("get_exclude_nodes_from_collision"), &Joint3D::get_exclude_nodes_from_collision); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_a", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "CollisionObject"), "set_node_a", "get_node_a"); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_b", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "CollisionObject"), "set_node_b", "get_node_b"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_a", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "CollisionObject3D"), "set_node_a", "get_node_a"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_b", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "CollisionObject3D"), "set_node_b", "get_node_b"); ADD_PROPERTY(PropertyInfo(Variant::INT, "solver/priority", PROPERTY_HINT_RANGE, "1,8,1"), "set_solver_priority", "get_solver_priority"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision/exclude_nodes"), "set_exclude_nodes_from_collision", "get_exclude_nodes_from_collision"); } -Joint::Joint() { +Joint3D::Joint3D() { exclude_from_collision = true; solver_priority = 1; @@ -167,10 +167,10 @@ Joint::Joint() { /////////////////////////////////// -void PinJoint::_bind_methods() { +void PinJoint3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &PinJoint::set_param); - ClassDB::bind_method(D_METHOD("get_param", "param"), &PinJoint::get_param); + ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &PinJoint3D::set_param); + ClassDB::bind_method(D_METHOD("get_param", "param"), &PinJoint3D::get_param); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "params/bias", PROPERTY_HINT_RANGE, "0.01,0.99,0.01"), "set_param", "get_param", PARAM_BIAS); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "params/damping", PROPERTY_HINT_RANGE, "0.01,8.0,0.01"), "set_param", "get_param", PARAM_DAMPING); @@ -181,20 +181,20 @@ void PinJoint::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_IMPULSE_CLAMP); } -void PinJoint::set_param(Param p_param, float p_value) { +void PinJoint3D::set_param(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, 3); params[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->pin_joint_set_param(get_joint(), PhysicsServer::PinJointParam(p_param), p_value); + PhysicsServer3D::get_singleton()->pin_joint_set_param(get_joint(), PhysicsServer3D::PinJointParam(p_param), p_value); } -float PinJoint::get_param(Param p_param) const { +float PinJoint3D::get_param(Param p_param) const { ERR_FAIL_INDEX_V(p_param, 3, 0); return params[p_param]; } -RID PinJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { +RID PinJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) { Vector3 pinpos = get_global_transform().origin; Vector3 local_a = body_a->get_global_transform().affine_inverse().xform(pinpos); @@ -205,14 +205,14 @@ RID PinJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { else local_b = pinpos; - RID j = PhysicsServer::get_singleton()->joint_create_pin(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); + RID j = PhysicsServer3D::get_singleton()->joint_create_pin(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); for (int i = 0; i < 3; i++) { - PhysicsServer::get_singleton()->pin_joint_set_param(j, PhysicsServer::PinJointParam(i), params[i]); + PhysicsServer3D::get_singleton()->pin_joint_set_param(j, PhysicsServer3D::PinJointParam(i), params[i]); } return j; } -PinJoint::PinJoint() { +PinJoint3D::PinJoint3D() { params[PARAM_BIAS] = 0.3; params[PARAM_DAMPING] = 1; @@ -223,39 +223,39 @@ PinJoint::PinJoint() { /////////////////////////////////// -void HingeJoint::_set_upper_limit(float p_limit) { +void HingeJoint3D::_set_upper_limit(float p_limit) { set_param(PARAM_LIMIT_UPPER, Math::deg2rad(p_limit)); } -float HingeJoint::_get_upper_limit() const { +float HingeJoint3D::_get_upper_limit() const { return Math::rad2deg(get_param(PARAM_LIMIT_UPPER)); } -void HingeJoint::_set_lower_limit(float p_limit) { +void HingeJoint3D::_set_lower_limit(float p_limit) { set_param(PARAM_LIMIT_LOWER, Math::deg2rad(p_limit)); } -float HingeJoint::_get_lower_limit() const { +float HingeJoint3D::_get_lower_limit() const { return Math::rad2deg(get_param(PARAM_LIMIT_LOWER)); } -void HingeJoint::_bind_methods() { +void HingeJoint3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &HingeJoint::set_param); - ClassDB::bind_method(D_METHOD("get_param", "param"), &HingeJoint::get_param); + ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &HingeJoint3D::set_param); + ClassDB::bind_method(D_METHOD("get_param", "param"), &HingeJoint3D::get_param); - ClassDB::bind_method(D_METHOD("set_flag", "flag", "enabled"), &HingeJoint::set_flag); - ClassDB::bind_method(D_METHOD("get_flag", "flag"), &HingeJoint::get_flag); + ClassDB::bind_method(D_METHOD("set_flag", "flag", "enabled"), &HingeJoint3D::set_flag); + ClassDB::bind_method(D_METHOD("get_flag", "flag"), &HingeJoint3D::get_flag); - ClassDB::bind_method(D_METHOD("_set_upper_limit", "upper_limit"), &HingeJoint::_set_upper_limit); - ClassDB::bind_method(D_METHOD("_get_upper_limit"), &HingeJoint::_get_upper_limit); + ClassDB::bind_method(D_METHOD("_set_upper_limit", "upper_limit"), &HingeJoint3D::_set_upper_limit); + ClassDB::bind_method(D_METHOD("_get_upper_limit"), &HingeJoint3D::_get_upper_limit); - ClassDB::bind_method(D_METHOD("_set_lower_limit", "lower_limit"), &HingeJoint::_set_lower_limit); - ClassDB::bind_method(D_METHOD("_get_lower_limit"), &HingeJoint::_get_lower_limit); + ClassDB::bind_method(D_METHOD("_set_lower_limit", "lower_limit"), &HingeJoint3D::_set_lower_limit); + ClassDB::bind_method(D_METHOD("_get_lower_limit"), &HingeJoint3D::_get_lower_limit); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "params/bias", PROPERTY_HINT_RANGE, "0.00,0.99,0.01"), "set_param", "get_param", PARAM_BIAS); @@ -285,37 +285,37 @@ void HingeJoint::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_MAX); } -void HingeJoint::set_param(Param p_param, float p_value) { +void HingeJoint3D::set_param(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); params[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_param(get_joint(), PhysicsServer::HingeJointParam(p_param), p_value); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(get_joint(), PhysicsServer3D::HingeJointParam(p_param), p_value); update_gizmo(); } -float HingeJoint::get_param(Param p_param) const { +float HingeJoint3D::get_param(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return params[p_param]; } -void HingeJoint::set_flag(Flag p_flag, bool p_value) { +void HingeJoint3D::set_flag(Flag p_flag, bool p_value) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); flags[p_flag] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_flag(get_joint(), PhysicsServer::HingeJointFlag(p_flag), p_value); + PhysicsServer3D::get_singleton()->hinge_joint_set_flag(get_joint(), PhysicsServer3D::HingeJointFlag(p_flag), p_value); update_gizmo(); } -bool HingeJoint::get_flag(Flag p_flag) const { +bool HingeJoint3D::get_flag(Flag p_flag) const { ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); return flags[p_flag]; } -RID HingeJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { +RID HingeJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) { Transform gt = get_global_transform(); Transform ainv = body_a->get_global_transform().affine_inverse(); @@ -331,18 +331,18 @@ RID HingeJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { local_b.orthonormalize(); - RID j = PhysicsServer::get_singleton()->joint_create_hinge(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); + RID j = PhysicsServer3D::get_singleton()->joint_create_hinge(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); for (int i = 0; i < PARAM_MAX; i++) { - PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HingeJointParam(i), params[i]); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HingeJointParam(i), params[i]); } for (int i = 0; i < FLAG_MAX; i++) { set_flag(Flag(i), flags[i]); - PhysicsServer::get_singleton()->hinge_joint_set_flag(j, PhysicsServer::HingeJointFlag(i), flags[i]); + PhysicsServer3D::get_singleton()->hinge_joint_set_flag(j, PhysicsServer3D::HingeJointFlag(i), flags[i]); } return j; } -HingeJoint::HingeJoint() { +HingeJoint3D::HingeJoint3D() { params[PARAM_BIAS] = 0.3; params[PARAM_LIMIT_UPPER] = Math_PI * 0.5; @@ -361,36 +361,36 @@ HingeJoint::HingeJoint() { ////////////////////////////////// -void SliderJoint::_set_upper_limit_angular(float p_limit_angular) { +void SliderJoint3D::_set_upper_limit_angular(float p_limit_angular) { set_param(PARAM_ANGULAR_LIMIT_UPPER, Math::deg2rad(p_limit_angular)); } -float SliderJoint::_get_upper_limit_angular() const { +float SliderJoint3D::_get_upper_limit_angular() const { return Math::rad2deg(get_param(PARAM_ANGULAR_LIMIT_UPPER)); } -void SliderJoint::_set_lower_limit_angular(float p_limit_angular) { +void SliderJoint3D::_set_lower_limit_angular(float p_limit_angular) { set_param(PARAM_ANGULAR_LIMIT_LOWER, Math::deg2rad(p_limit_angular)); } -float SliderJoint::_get_lower_limit_angular() const { +float SliderJoint3D::_get_lower_limit_angular() const { return Math::rad2deg(get_param(PARAM_ANGULAR_LIMIT_LOWER)); } -void SliderJoint::_bind_methods() { +void SliderJoint3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &SliderJoint::set_param); - ClassDB::bind_method(D_METHOD("get_param", "param"), &SliderJoint::get_param); + ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &SliderJoint3D::set_param); + ClassDB::bind_method(D_METHOD("get_param", "param"), &SliderJoint3D::get_param); - ClassDB::bind_method(D_METHOD("_set_upper_limit_angular", "upper_limit_angular"), &SliderJoint::_set_upper_limit_angular); - ClassDB::bind_method(D_METHOD("_get_upper_limit_angular"), &SliderJoint::_get_upper_limit_angular); + ClassDB::bind_method(D_METHOD("_set_upper_limit_angular", "upper_limit_angular"), &SliderJoint3D::_set_upper_limit_angular); + ClassDB::bind_method(D_METHOD("_get_upper_limit_angular"), &SliderJoint3D::_get_upper_limit_angular); - ClassDB::bind_method(D_METHOD("_set_lower_limit_angular", "lower_limit_angular"), &SliderJoint::_set_lower_limit_angular); - ClassDB::bind_method(D_METHOD("_get_lower_limit_angular"), &SliderJoint::_get_lower_limit_angular); + ClassDB::bind_method(D_METHOD("_set_lower_limit_angular", "lower_limit_angular"), &SliderJoint3D::_set_lower_limit_angular); + ClassDB::bind_method(D_METHOD("_get_lower_limit_angular"), &SliderJoint3D::_get_lower_limit_angular); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit/upper_distance", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_UPPER); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit/lower_distance", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_LOWER); @@ -443,21 +443,21 @@ void SliderJoint::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_MAX); } -void SliderJoint::set_param(Param p_param, float p_value) { +void SliderJoint3D::set_param(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); params[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(get_joint(), PhysicsServer::SliderJointParam(p_param), p_value); + PhysicsServer3D::get_singleton()->slider_joint_set_param(get_joint(), PhysicsServer3D::SliderJointParam(p_param), p_value); update_gizmo(); } -float SliderJoint::get_param(Param p_param) const { +float SliderJoint3D::get_param(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return params[p_param]; } -RID SliderJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { +RID SliderJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) { Transform gt = get_global_transform(); Transform ainv = body_a->get_global_transform().affine_inverse(); @@ -473,15 +473,15 @@ RID SliderJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { local_b.orthonormalize(); - RID j = PhysicsServer::get_singleton()->joint_create_slider(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); + RID j = PhysicsServer3D::get_singleton()->joint_create_slider(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); for (int i = 0; i < PARAM_MAX; i++) { - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SliderJointParam(i), params[i]); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SliderJointParam(i), params[i]); } return j; } -SliderJoint::SliderJoint() { +SliderJoint3D::SliderJoint3D() { params[PARAM_LINEAR_LIMIT_UPPER] = 1.0; params[PARAM_LINEAR_LIMIT_LOWER] = -1.0; @@ -510,36 +510,36 @@ SliderJoint::SliderJoint() { ////////////////////////////////// -void ConeTwistJoint::_set_swing_span(float p_limit_angular) { +void ConeTwistJoint3D::_set_swing_span(float p_limit_angular) { set_param(PARAM_SWING_SPAN, Math::deg2rad(p_limit_angular)); } -float ConeTwistJoint::_get_swing_span() const { +float ConeTwistJoint3D::_get_swing_span() const { return Math::rad2deg(get_param(PARAM_SWING_SPAN)); } -void ConeTwistJoint::_set_twist_span(float p_limit_angular) { +void ConeTwistJoint3D::_set_twist_span(float p_limit_angular) { set_param(PARAM_TWIST_SPAN, Math::deg2rad(p_limit_angular)); } -float ConeTwistJoint::_get_twist_span() const { +float ConeTwistJoint3D::_get_twist_span() const { return Math::rad2deg(get_param(PARAM_TWIST_SPAN)); } -void ConeTwistJoint::_bind_methods() { +void ConeTwistJoint3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &ConeTwistJoint::set_param); - ClassDB::bind_method(D_METHOD("get_param", "param"), &ConeTwistJoint::get_param); + ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &ConeTwistJoint3D::set_param); + ClassDB::bind_method(D_METHOD("get_param", "param"), &ConeTwistJoint3D::get_param); - ClassDB::bind_method(D_METHOD("_set_swing_span", "swing_span"), &ConeTwistJoint::_set_swing_span); - ClassDB::bind_method(D_METHOD("_get_swing_span"), &ConeTwistJoint::_get_swing_span); + ClassDB::bind_method(D_METHOD("_set_swing_span", "swing_span"), &ConeTwistJoint3D::_set_swing_span); + ClassDB::bind_method(D_METHOD("_get_swing_span"), &ConeTwistJoint3D::_get_swing_span); - ClassDB::bind_method(D_METHOD("_set_twist_span", "twist_span"), &ConeTwistJoint::_set_twist_span); - ClassDB::bind_method(D_METHOD("_get_twist_span"), &ConeTwistJoint::_get_twist_span); + ClassDB::bind_method(D_METHOD("_set_twist_span", "twist_span"), &ConeTwistJoint3D::_set_twist_span); + ClassDB::bind_method(D_METHOD("_get_twist_span"), &ConeTwistJoint3D::_get_twist_span); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "swing_span", PROPERTY_HINT_RANGE, "-180,180,0.1"), "_set_swing_span", "_get_swing_span"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "twist_span", PROPERTY_HINT_RANGE, "-40000,40000,0.1"), "_set_twist_span", "_get_twist_span"); @@ -556,22 +556,22 @@ void ConeTwistJoint::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_MAX); } -void ConeTwistJoint::set_param(Param p_param, float p_value) { +void ConeTwistJoint3D::set_param(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); params[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->cone_twist_joint_set_param(get_joint(), PhysicsServer::ConeTwistJointParam(p_param), p_value); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(get_joint(), PhysicsServer3D::ConeTwistJointParam(p_param), p_value); update_gizmo(); } -float ConeTwistJoint::get_param(Param p_param) const { +float ConeTwistJoint3D::get_param(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return params[p_param]; } -RID ConeTwistJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { +RID ConeTwistJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) { Transform gt = get_global_transform(); //Vector3 cone_twistpos = gt.origin; @@ -590,15 +590,15 @@ RID ConeTwistJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { local_b.orthonormalize(); - RID j = PhysicsServer::get_singleton()->joint_create_cone_twist(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); + RID j = PhysicsServer3D::get_singleton()->joint_create_cone_twist(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); for (int i = 0; i < PARAM_MAX; i++) { - PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::ConeTwistJointParam(i), params[i]); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::ConeTwistJointParam(i), params[i]); } return j; } -ConeTwistJoint::ConeTwistJoint() { +ConeTwistJoint3D::ConeTwistJoint3D() { params[PARAM_SWING_SPAN] = Math_PI * 0.25; params[PARAM_TWIST_SPAN] = Math_PI; @@ -609,106 +609,106 @@ ConeTwistJoint::ConeTwistJoint() { ///////////////////////////////////////////////////////////////////// -void Generic6DOFJoint::_set_angular_hi_limit_x(float p_limit_angular) { +void Generic6DOFJoint3D::_set_angular_hi_limit_x(float p_limit_angular) { set_param_x(PARAM_ANGULAR_UPPER_LIMIT, Math::deg2rad(p_limit_angular)); } -float Generic6DOFJoint::_get_angular_hi_limit_x() const { +float Generic6DOFJoint3D::_get_angular_hi_limit_x() const { return Math::rad2deg(get_param_x(PARAM_ANGULAR_UPPER_LIMIT)); } -void Generic6DOFJoint::_set_angular_lo_limit_x(float p_limit_angular) { +void Generic6DOFJoint3D::_set_angular_lo_limit_x(float p_limit_angular) { set_param_x(PARAM_ANGULAR_LOWER_LIMIT, Math::deg2rad(p_limit_angular)); } -float Generic6DOFJoint::_get_angular_lo_limit_x() const { +float Generic6DOFJoint3D::_get_angular_lo_limit_x() const { return Math::rad2deg(get_param_x(PARAM_ANGULAR_LOWER_LIMIT)); } -void Generic6DOFJoint::_set_angular_hi_limit_y(float p_limit_angular) { +void Generic6DOFJoint3D::_set_angular_hi_limit_y(float p_limit_angular) { set_param_y(PARAM_ANGULAR_UPPER_LIMIT, Math::deg2rad(p_limit_angular)); } -float Generic6DOFJoint::_get_angular_hi_limit_y() const { +float Generic6DOFJoint3D::_get_angular_hi_limit_y() const { return Math::rad2deg(get_param_y(PARAM_ANGULAR_UPPER_LIMIT)); } -void Generic6DOFJoint::_set_angular_lo_limit_y(float p_limit_angular) { +void Generic6DOFJoint3D::_set_angular_lo_limit_y(float p_limit_angular) { set_param_y(PARAM_ANGULAR_LOWER_LIMIT, Math::deg2rad(p_limit_angular)); } -float Generic6DOFJoint::_get_angular_lo_limit_y() const { +float Generic6DOFJoint3D::_get_angular_lo_limit_y() const { return Math::rad2deg(get_param_y(PARAM_ANGULAR_LOWER_LIMIT)); } -void Generic6DOFJoint::_set_angular_hi_limit_z(float p_limit_angular) { +void Generic6DOFJoint3D::_set_angular_hi_limit_z(float p_limit_angular) { set_param_z(PARAM_ANGULAR_UPPER_LIMIT, Math::deg2rad(p_limit_angular)); } -float Generic6DOFJoint::_get_angular_hi_limit_z() const { +float Generic6DOFJoint3D::_get_angular_hi_limit_z() const { return Math::rad2deg(get_param_z(PARAM_ANGULAR_UPPER_LIMIT)); } -void Generic6DOFJoint::_set_angular_lo_limit_z(float p_limit_angular) { +void Generic6DOFJoint3D::_set_angular_lo_limit_z(float p_limit_angular) { set_param_z(PARAM_ANGULAR_LOWER_LIMIT, Math::deg2rad(p_limit_angular)); } -float Generic6DOFJoint::_get_angular_lo_limit_z() const { +float Generic6DOFJoint3D::_get_angular_lo_limit_z() const { return Math::rad2deg(get_param_z(PARAM_ANGULAR_LOWER_LIMIT)); } -void Generic6DOFJoint::_bind_methods() { +void Generic6DOFJoint3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_x", "angle"), &Generic6DOFJoint::_set_angular_hi_limit_x); - ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_x"), &Generic6DOFJoint::_get_angular_hi_limit_x); + ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_x", "angle"), &Generic6DOFJoint3D::_set_angular_hi_limit_x); + ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_x"), &Generic6DOFJoint3D::_get_angular_hi_limit_x); - ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_x", "angle"), &Generic6DOFJoint::_set_angular_lo_limit_x); - ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_x"), &Generic6DOFJoint::_get_angular_lo_limit_x); + ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_x", "angle"), &Generic6DOFJoint3D::_set_angular_lo_limit_x); + ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_x"), &Generic6DOFJoint3D::_get_angular_lo_limit_x); - ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_y", "angle"), &Generic6DOFJoint::_set_angular_hi_limit_y); - ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_y"), &Generic6DOFJoint::_get_angular_hi_limit_y); + ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_y", "angle"), &Generic6DOFJoint3D::_set_angular_hi_limit_y); + ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_y"), &Generic6DOFJoint3D::_get_angular_hi_limit_y); - ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_y", "angle"), &Generic6DOFJoint::_set_angular_lo_limit_y); - ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_y"), &Generic6DOFJoint::_get_angular_lo_limit_y); + ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_y", "angle"), &Generic6DOFJoint3D::_set_angular_lo_limit_y); + ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_y"), &Generic6DOFJoint3D::_get_angular_lo_limit_y); - ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_z", "angle"), &Generic6DOFJoint::_set_angular_hi_limit_z); - ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_z"), &Generic6DOFJoint::_get_angular_hi_limit_z); + ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_z", "angle"), &Generic6DOFJoint3D::_set_angular_hi_limit_z); + ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_z"), &Generic6DOFJoint3D::_get_angular_hi_limit_z); - ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_z", "angle"), &Generic6DOFJoint::_set_angular_lo_limit_z); - ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_z"), &Generic6DOFJoint::_get_angular_lo_limit_z); + ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_z", "angle"), &Generic6DOFJoint3D::_set_angular_lo_limit_z); + ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_z"), &Generic6DOFJoint3D::_get_angular_lo_limit_z); - ClassDB::bind_method(D_METHOD("set_param_x", "param", "value"), &Generic6DOFJoint::set_param_x); - ClassDB::bind_method(D_METHOD("get_param_x", "param"), &Generic6DOFJoint::get_param_x); + ClassDB::bind_method(D_METHOD("set_param_x", "param", "value"), &Generic6DOFJoint3D::set_param_x); + ClassDB::bind_method(D_METHOD("get_param_x", "param"), &Generic6DOFJoint3D::get_param_x); - ClassDB::bind_method(D_METHOD("set_param_y", "param", "value"), &Generic6DOFJoint::set_param_y); - ClassDB::bind_method(D_METHOD("get_param_y", "param"), &Generic6DOFJoint::get_param_y); + ClassDB::bind_method(D_METHOD("set_param_y", "param", "value"), &Generic6DOFJoint3D::set_param_y); + ClassDB::bind_method(D_METHOD("get_param_y", "param"), &Generic6DOFJoint3D::get_param_y); - ClassDB::bind_method(D_METHOD("set_param_z", "param", "value"), &Generic6DOFJoint::set_param_z); - ClassDB::bind_method(D_METHOD("get_param_z", "param"), &Generic6DOFJoint::get_param_z); + ClassDB::bind_method(D_METHOD("set_param_z", "param", "value"), &Generic6DOFJoint3D::set_param_z); + ClassDB::bind_method(D_METHOD("get_param_z", "param"), &Generic6DOFJoint3D::get_param_z); - ClassDB::bind_method(D_METHOD("set_flag_x", "flag", "value"), &Generic6DOFJoint::set_flag_x); - ClassDB::bind_method(D_METHOD("get_flag_x", "flag"), &Generic6DOFJoint::get_flag_x); + ClassDB::bind_method(D_METHOD("set_flag_x", "flag", "value"), &Generic6DOFJoint3D::set_flag_x); + ClassDB::bind_method(D_METHOD("get_flag_x", "flag"), &Generic6DOFJoint3D::get_flag_x); - ClassDB::bind_method(D_METHOD("set_flag_y", "flag", "value"), &Generic6DOFJoint::set_flag_y); - ClassDB::bind_method(D_METHOD("get_flag_y", "flag"), &Generic6DOFJoint::get_flag_y); + ClassDB::bind_method(D_METHOD("set_flag_y", "flag", "value"), &Generic6DOFJoint3D::set_flag_y); + ClassDB::bind_method(D_METHOD("get_flag_y", "flag"), &Generic6DOFJoint3D::get_flag_y); - ClassDB::bind_method(D_METHOD("set_flag_z", "flag", "value"), &Generic6DOFJoint::set_flag_z); - ClassDB::bind_method(D_METHOD("get_flag_z", "flag"), &Generic6DOFJoint::get_flag_z); + ClassDB::bind_method(D_METHOD("set_flag_z", "flag", "value"), &Generic6DOFJoint3D::set_flag_z); + ClassDB::bind_method(D_METHOD("get_flag_z", "flag"), &Generic6DOFJoint3D::get_flag_z); - ClassDB::bind_method(D_METHOD("set_precision", "precision"), &Generic6DOFJoint::set_precision); - ClassDB::bind_method(D_METHOD("get_precision"), &Generic6DOFJoint::get_precision); + ClassDB::bind_method(D_METHOD("set_precision", "precision"), &Generic6DOFJoint3D::set_precision); + ClassDB::bind_method(D_METHOD("get_precision"), &Generic6DOFJoint3D::get_precision); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_limit_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_LINEAR_LIMIT); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_x/upper_distance"), "set_param_x", "get_param_x", PARAM_LINEAR_UPPER_LIMIT); @@ -827,100 +827,100 @@ void Generic6DOFJoint::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_MAX); } -void Generic6DOFJoint::set_param_x(Param p_param, float p_value) { +void Generic6DOFJoint3D::set_param_x(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); params_x[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisParam(p_param), p_value); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value); update_gizmo(); } -float Generic6DOFJoint::get_param_x(Param p_param) const { +float Generic6DOFJoint3D::get_param_x(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return params_x[p_param]; } -void Generic6DOFJoint::set_param_y(Param p_param, float p_value) { +void Generic6DOFJoint3D::set_param_y(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); params_y[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisParam(p_param), p_value); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value); update_gizmo(); } -float Generic6DOFJoint::get_param_y(Param p_param) const { +float Generic6DOFJoint3D::get_param_y(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return params_y[p_param]; } -void Generic6DOFJoint::set_param_z(Param p_param, float p_value) { +void Generic6DOFJoint3D::set_param_z(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); params_z[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisParam(p_param), p_value); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value); update_gizmo(); } -float Generic6DOFJoint::get_param_z(Param p_param) const { +float Generic6DOFJoint3D::get_param_z(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return params_z[p_param]; } -void Generic6DOFJoint::set_flag_x(Flag p_flag, bool p_enabled) { +void Generic6DOFJoint3D::set_flag_x(Flag p_flag, bool p_enabled) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); flags_x[p_flag] = p_enabled; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled); update_gizmo(); } -bool Generic6DOFJoint::get_flag_x(Flag p_flag) const { +bool Generic6DOFJoint3D::get_flag_x(Flag p_flag) const { ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); return flags_x[p_flag]; } -void Generic6DOFJoint::set_flag_y(Flag p_flag, bool p_enabled) { +void Generic6DOFJoint3D::set_flag_y(Flag p_flag, bool p_enabled) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); flags_y[p_flag] = p_enabled; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled); update_gizmo(); } -bool Generic6DOFJoint::get_flag_y(Flag p_flag) const { +bool Generic6DOFJoint3D::get_flag_y(Flag p_flag) const { ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); return flags_y[p_flag]; } -void Generic6DOFJoint::set_flag_z(Flag p_flag, bool p_enabled) { +void Generic6DOFJoint3D::set_flag_z(Flag p_flag, bool p_enabled) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); flags_z[p_flag] = p_enabled; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled); update_gizmo(); } -bool Generic6DOFJoint::get_flag_z(Flag p_flag) const { +bool Generic6DOFJoint3D::get_flag_z(Flag p_flag) const { ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); return flags_z[p_flag]; } -void Generic6DOFJoint::set_precision(int p_precision) { +void Generic6DOFJoint3D::set_precision(int p_precision) { precision = p_precision; - PhysicsServer::get_singleton()->generic_6dof_joint_set_precision( + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_precision( get_joint(), precision); } -RID Generic6DOFJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { +RID Generic6DOFJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) { Transform gt = get_global_transform(); //Vector3 cone_twistpos = gt.origin; @@ -939,22 +939,22 @@ RID Generic6DOFJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) local_b.orthonormalize(); - RID j = PhysicsServer::get_singleton()->joint_create_generic_6dof(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); + RID j = PhysicsServer3D::get_singleton()->joint_create_generic_6dof(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); for (int i = 0; i < PARAM_MAX; i++) { - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisParam(i), params_x[i]); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisParam(i), params_y[i]); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisParam(i), params_z[i]); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisParam(i), params_x[i]); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisParam(i), params_y[i]); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisParam(i), params_z[i]); } for (int i = 0; i < FLAG_MAX; i++) { - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisFlag(i), flags_x[i]); - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisFlag(i), flags_y[i]); - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisFlag(i), flags_z[i]); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisFlag(i), flags_x[i]); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisFlag(i), flags_y[i]); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisFlag(i), flags_z[i]); } return j; } -Generic6DOFJoint::Generic6DOFJoint() : +Generic6DOFJoint3D::Generic6DOFJoint3D() : precision(1) { set_param_x(PARAM_LINEAR_LOWER_LIMIT, 0); diff --git a/scene/3d/physics_joint_3d.h b/scene/3d/physics_joint_3d.h new file mode 100644 index 0000000000..ce0c7af5d1 --- /dev/null +++ b/scene/3d/physics_joint_3d.h @@ -0,0 +1,343 @@ +/*************************************************************************/ +/* physics_joint_3d.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 PHYSICS_JOINT_H +#define PHYSICS_JOINT_H + +#include "scene/3d/node_3d.h" +#include "scene/3d/physics_body_3d.h" + +class Joint3D : public Node3D { + + GDCLASS(Joint3D, Node3D); + + RID ba, bb; + + RID joint; + + NodePath a; + NodePath b; + + int solver_priority; + bool exclude_from_collision; + +protected: + void _update_joint(bool p_only_free = false); + + void _notification(int p_what); + + virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) = 0; + + static void _bind_methods(); + +public: + void set_node_a(const NodePath &p_node_a); + NodePath get_node_a() const; + + void set_node_b(const NodePath &p_node_b); + NodePath get_node_b() const; + + void set_solver_priority(int p_priority); + int get_solver_priority() const; + + void set_exclude_nodes_from_collision(bool p_enable); + bool get_exclude_nodes_from_collision() const; + + RID get_joint() const { return joint; } + Joint3D(); +}; + +/////////////////////////////////////////// + +class PinJoint3D : public Joint3D { + + GDCLASS(PinJoint3D, Joint3D); + +public: + enum Param { + PARAM_BIAS = PhysicsServer3D::PIN_JOINT_BIAS, + PARAM_DAMPING = PhysicsServer3D::PIN_JOINT_DAMPING, + PARAM_IMPULSE_CLAMP = PhysicsServer3D::PIN_JOINT_IMPULSE_CLAMP + }; + +protected: + float params[3]; + virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b); + static void _bind_methods(); + +public: + void set_param(Param p_param, float p_value); + float get_param(Param p_param) const; + + PinJoint3D(); +}; + +VARIANT_ENUM_CAST(PinJoint3D::Param); + +class HingeJoint3D : public Joint3D { + + GDCLASS(HingeJoint3D, Joint3D); + +public: + enum Param { + PARAM_BIAS = PhysicsServer3D::HINGE_JOINT_BIAS, + PARAM_LIMIT_UPPER = PhysicsServer3D::HINGE_JOINT_LIMIT_UPPER, + PARAM_LIMIT_LOWER = PhysicsServer3D::HINGE_JOINT_LIMIT_LOWER, + PARAM_LIMIT_BIAS = PhysicsServer3D::HINGE_JOINT_LIMIT_BIAS, + PARAM_LIMIT_SOFTNESS = PhysicsServer3D::HINGE_JOINT_LIMIT_SOFTNESS, + PARAM_LIMIT_RELAXATION = PhysicsServer3D::HINGE_JOINT_LIMIT_RELAXATION, + PARAM_MOTOR_TARGET_VELOCITY = PhysicsServer3D::HINGE_JOINT_MOTOR_TARGET_VELOCITY, + PARAM_MOTOR_MAX_IMPULSE = PhysicsServer3D::HINGE_JOINT_MOTOR_MAX_IMPULSE, + PARAM_MAX = PhysicsServer3D::HINGE_JOINT_MAX + }; + + enum Flag { + FLAG_USE_LIMIT = PhysicsServer3D::HINGE_JOINT_FLAG_USE_LIMIT, + FLAG_ENABLE_MOTOR = PhysicsServer3D::HINGE_JOINT_FLAG_ENABLE_MOTOR, + FLAG_MAX = PhysicsServer3D::HINGE_JOINT_FLAG_MAX + }; + +protected: + float params[PARAM_MAX]; + bool flags[FLAG_MAX]; + virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b); + static void _bind_methods(); + + void _set_upper_limit(float p_limit); + float _get_upper_limit() const; + + void _set_lower_limit(float p_limit); + float _get_lower_limit() const; + +public: + void set_param(Param p_param, float p_value); + float get_param(Param p_param) const; + + void set_flag(Flag p_flag, bool p_value); + bool get_flag(Flag p_flag) const; + + HingeJoint3D(); +}; + +VARIANT_ENUM_CAST(HingeJoint3D::Param); +VARIANT_ENUM_CAST(HingeJoint3D::Flag); + +class SliderJoint3D : public Joint3D { + + GDCLASS(SliderJoint3D, Joint3D); + +public: + enum Param { + PARAM_LINEAR_LIMIT_UPPER = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_UPPER, + PARAM_LINEAR_LIMIT_LOWER = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_LOWER, + PARAM_LINEAR_LIMIT_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS, + PARAM_LINEAR_LIMIT_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION, + PARAM_LINEAR_LIMIT_DAMPING = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_DAMPING, + PARAM_LINEAR_MOTION_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS, + PARAM_LINEAR_MOTION_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION, + PARAM_LINEAR_MOTION_DAMPING = PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_DAMPING, + PARAM_LINEAR_ORTHOGONAL_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS, + PARAM_LINEAR_ORTHOGONAL_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION, + PARAM_LINEAR_ORTHOGONAL_DAMPING = PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING, + + PARAM_ANGULAR_LIMIT_UPPER = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_UPPER, + PARAM_ANGULAR_LIMIT_LOWER = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_LOWER, + PARAM_ANGULAR_LIMIT_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, + PARAM_ANGULAR_LIMIT_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION, + PARAM_ANGULAR_LIMIT_DAMPING = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING, + PARAM_ANGULAR_MOTION_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS, + PARAM_ANGULAR_MOTION_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION, + PARAM_ANGULAR_MOTION_DAMPING = PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_DAMPING, + PARAM_ANGULAR_ORTHOGONAL_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS, + PARAM_ANGULAR_ORTHOGONAL_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION, + PARAM_ANGULAR_ORTHOGONAL_DAMPING = PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING, + PARAM_MAX = PhysicsServer3D::SLIDER_JOINT_MAX + + }; + +protected: + void _set_upper_limit_angular(float p_limit_angular); + float _get_upper_limit_angular() const; + + void _set_lower_limit_angular(float p_limit_angular); + float _get_lower_limit_angular() const; + + float params[PARAM_MAX]; + virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b); + static void _bind_methods(); + +public: + void set_param(Param p_param, float p_value); + float get_param(Param p_param) const; + + SliderJoint3D(); +}; + +VARIANT_ENUM_CAST(SliderJoint3D::Param); + +class ConeTwistJoint3D : public Joint3D { + + GDCLASS(ConeTwistJoint3D, Joint3D); + +public: + enum Param { + + PARAM_SWING_SPAN, + PARAM_TWIST_SPAN, + PARAM_BIAS, + PARAM_SOFTNESS, + PARAM_RELAXATION, + PARAM_MAX + }; + +protected: + void _set_swing_span(float p_limit_angular); + float _get_swing_span() const; + + void _set_twist_span(float p_limit_angular); + float _get_twist_span() const; + + float params[PARAM_MAX]; + virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b); + static void _bind_methods(); + +public: + void set_param(Param p_param, float p_value); + float get_param(Param p_param) const; + + ConeTwistJoint3D(); +}; + +VARIANT_ENUM_CAST(ConeTwistJoint3D::Param); + +class Generic6DOFJoint3D : public Joint3D { + + GDCLASS(Generic6DOFJoint3D, Joint3D); + +public: + enum Param { + + PARAM_LINEAR_LOWER_LIMIT = PhysicsServer3D::G6DOF_JOINT_LINEAR_LOWER_LIMIT, + PARAM_LINEAR_UPPER_LIMIT = PhysicsServer3D::G6DOF_JOINT_LINEAR_UPPER_LIMIT, + PARAM_LINEAR_LIMIT_SOFTNESS = PhysicsServer3D::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, + PARAM_LINEAR_RESTITUTION = PhysicsServer3D::G6DOF_JOINT_LINEAR_RESTITUTION, + PARAM_LINEAR_DAMPING = PhysicsServer3D::G6DOF_JOINT_LINEAR_DAMPING, + PARAM_LINEAR_MOTOR_TARGET_VELOCITY = PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY, + PARAM_LINEAR_MOTOR_FORCE_LIMIT = PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT, + PARAM_LINEAR_SPRING_STIFFNESS = PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS, + PARAM_LINEAR_SPRING_DAMPING = PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_DAMPING, + PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT = PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT, + PARAM_ANGULAR_LOWER_LIMIT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, + PARAM_ANGULAR_UPPER_LIMIT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, + PARAM_ANGULAR_LIMIT_SOFTNESS = PhysicsServer3D::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, + PARAM_ANGULAR_DAMPING = PhysicsServer3D::G6DOF_JOINT_ANGULAR_DAMPING, + PARAM_ANGULAR_RESTITUTION = PhysicsServer3D::G6DOF_JOINT_ANGULAR_RESTITUTION, + PARAM_ANGULAR_FORCE_LIMIT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_FORCE_LIMIT, + PARAM_ANGULAR_ERP = PhysicsServer3D::G6DOF_JOINT_ANGULAR_ERP, + PARAM_ANGULAR_MOTOR_TARGET_VELOCITY = PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY, + PARAM_ANGULAR_MOTOR_FORCE_LIMIT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT, + PARAM_ANGULAR_SPRING_STIFFNESS = PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS, + PARAM_ANGULAR_SPRING_DAMPING = PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_DAMPING, + PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT, + PARAM_MAX = PhysicsServer3D::G6DOF_JOINT_MAX, + }; + + enum Flag { + FLAG_ENABLE_LINEAR_LIMIT = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, + FLAG_ENABLE_ANGULAR_LIMIT = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, + FLAG_ENABLE_LINEAR_SPRING = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING, + FLAG_ENABLE_ANGULAR_SPRING = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING, + FLAG_ENABLE_MOTOR = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_MOTOR, + FLAG_ENABLE_LINEAR_MOTOR = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR, + FLAG_MAX = PhysicsServer3D::G6DOF_JOINT_FLAG_MAX + }; + +protected: + void _set_angular_hi_limit_x(float p_limit_angular); + float _get_angular_hi_limit_x() const; + + void _set_angular_hi_limit_y(float p_limit_angular); + float _get_angular_hi_limit_y() const; + + void _set_angular_hi_limit_z(float p_limit_angular); + float _get_angular_hi_limit_z() const; + + void _set_angular_lo_limit_x(float p_limit_angular); + float _get_angular_lo_limit_x() const; + + void _set_angular_lo_limit_y(float p_limit_angular); + float _get_angular_lo_limit_y() const; + + void _set_angular_lo_limit_z(float p_limit_angular); + float _get_angular_lo_limit_z() const; + + float params_x[PARAM_MAX]; + bool flags_x[FLAG_MAX]; + float params_y[PARAM_MAX]; + bool flags_y[FLAG_MAX]; + float params_z[PARAM_MAX]; + bool flags_z[FLAG_MAX]; + + int precision; + + virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b); + static void _bind_methods(); + +public: + void set_param_x(Param p_param, float p_value); + float get_param_x(Param p_param) const; + + void set_param_y(Param p_param, float p_value); + float get_param_y(Param p_param) const; + + void set_param_z(Param p_param, float p_value); + float get_param_z(Param p_param) const; + + void set_flag_x(Flag p_flag, bool p_enabled); + bool get_flag_x(Flag p_flag) const; + + void set_flag_y(Flag p_flag, bool p_enabled); + bool get_flag_y(Flag p_flag) const; + + void set_flag_z(Flag p_flag, bool p_enabled); + bool get_flag_z(Flag p_flag) const; + + void set_precision(int p_precision); + int get_precision() const { + return precision; + } + + Generic6DOFJoint3D(); +}; + +VARIANT_ENUM_CAST(Generic6DOFJoint3D::Param); +VARIANT_ENUM_CAST(Generic6DOFJoint3D::Flag); + +#endif // PHYSICS_JOINT_H diff --git a/scene/3d/position_3d.h b/scene/3d/position_3d.h index cd5080c95a..9c806723fb 100644 --- a/scene/3d/position_3d.h +++ b/scene/3d/position_3d.h @@ -31,11 +31,11 @@ #ifndef POSITION_3D_H #define POSITION_3D_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" -class Position3D : public Spatial { +class Position3D : public Node3D { - GDCLASS(Position3D, Spatial); + GDCLASS(Position3D, Node3D); public: Position3D(); diff --git a/scene/3d/proximity_group.cpp b/scene/3d/proximity_group_3d.cpp index 2e1478b1cf..44ffabb655 100644 --- a/scene/3d/proximity_group.cpp +++ b/scene/3d/proximity_group_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* proximity_group.cpp */ +/* proximity_group_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,11 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "proximity_group.h" +#include "proximity_group_3d.h" #include "core/math/math_funcs.h" -void ProximityGroup::clear_groups() { +void ProximityGroup3D::clear_groups() { Map<StringName, uint32_t>::Element *E; @@ -60,7 +60,7 @@ void ProximityGroup::clear_groups() { }; }; -void ProximityGroup::update_groups() { +void ProximityGroup3D::update_groups() { if (grid_radius == Vector3(0, 0, 0)) return; @@ -76,7 +76,7 @@ void ProximityGroup::update_groups() { clear_groups(); }; -void ProximityGroup::add_groups(int *p_cell, String p_base, int p_depth) { +void ProximityGroup3D::add_groups(int *p_cell, String p_base, int p_depth) { p_base = p_base + "|"; if (grid_radius[p_depth] == 0) { @@ -102,7 +102,7 @@ void ProximityGroup::add_groups(int *p_cell, String p_base, int p_depth) { }; }; -void ProximityGroup::_new_group(StringName p_name) { +void ProximityGroup3D::_new_group(StringName p_name) { const Map<StringName, uint32_t>::Element *E = groups.find(p_name); if (!E) { @@ -112,7 +112,7 @@ void ProximityGroup::_new_group(StringName p_name) { groups[p_name] = group_version; }; -void ProximityGroup::_notification(int p_what) { +void ProximityGroup3D::_notification(int p_what) { switch (p_what) { @@ -126,7 +126,7 @@ void ProximityGroup::_notification(int p_what) { }; }; -void ProximityGroup::broadcast(String p_name, Variant p_params) { +void ProximityGroup3D::broadcast(String p_name, Variant p_params) { Map<StringName, uint32_t>::Element *E; E = groups.front(); @@ -137,7 +137,7 @@ void ProximityGroup::broadcast(String p_name, Variant p_params) { }; }; -void ProximityGroup::_proximity_group_broadcast(String p_name, Variant p_params) { +void ProximityGroup3D::_proximity_group_broadcast(String p_name, Variant p_params) { if (dispatch_mode == MODE_PROXY) { @@ -148,46 +148,46 @@ void ProximityGroup::_proximity_group_broadcast(String p_name, Variant p_params) }; }; -void ProximityGroup::set_group_name(const String &p_group_name) { +void ProximityGroup3D::set_group_name(const String &p_group_name) { group_name = p_group_name; }; -String ProximityGroup::get_group_name() const { +String ProximityGroup3D::get_group_name() const { return group_name; }; -void ProximityGroup::set_dispatch_mode(DispatchMode p_mode) { +void ProximityGroup3D::set_dispatch_mode(DispatchMode p_mode) { dispatch_mode = p_mode; }; -ProximityGroup::DispatchMode ProximityGroup::get_dispatch_mode() const { +ProximityGroup3D::DispatchMode ProximityGroup3D::get_dispatch_mode() const { return dispatch_mode; }; -void ProximityGroup::set_grid_radius(const Vector3 &p_radius) { +void ProximityGroup3D::set_grid_radius(const Vector3 &p_radius) { grid_radius = p_radius; }; -Vector3 ProximityGroup::get_grid_radius() const { +Vector3 ProximityGroup3D::get_grid_radius() const { return grid_radius; }; -void ProximityGroup::_bind_methods() { +void ProximityGroup3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_group_name", "name"), &ProximityGroup::set_group_name); - ClassDB::bind_method(D_METHOD("get_group_name"), &ProximityGroup::get_group_name); - ClassDB::bind_method(D_METHOD("set_dispatch_mode", "mode"), &ProximityGroup::set_dispatch_mode); - ClassDB::bind_method(D_METHOD("get_dispatch_mode"), &ProximityGroup::get_dispatch_mode); - ClassDB::bind_method(D_METHOD("set_grid_radius", "radius"), &ProximityGroup::set_grid_radius); - ClassDB::bind_method(D_METHOD("get_grid_radius"), &ProximityGroup::get_grid_radius); - ClassDB::bind_method(D_METHOD("broadcast", "name", "parameters"), &ProximityGroup::broadcast); - ClassDB::bind_method(D_METHOD("_proximity_group_broadcast", "name", "params"), &ProximityGroup::_proximity_group_broadcast); + ClassDB::bind_method(D_METHOD("set_group_name", "name"), &ProximityGroup3D::set_group_name); + ClassDB::bind_method(D_METHOD("get_group_name"), &ProximityGroup3D::get_group_name); + ClassDB::bind_method(D_METHOD("set_dispatch_mode", "mode"), &ProximityGroup3D::set_dispatch_mode); + ClassDB::bind_method(D_METHOD("get_dispatch_mode"), &ProximityGroup3D::get_dispatch_mode); + ClassDB::bind_method(D_METHOD("set_grid_radius", "radius"), &ProximityGroup3D::set_grid_radius); + ClassDB::bind_method(D_METHOD("get_grid_radius"), &ProximityGroup3D::get_grid_radius); + ClassDB::bind_method(D_METHOD("broadcast", "name", "parameters"), &ProximityGroup3D::broadcast); + ClassDB::bind_method(D_METHOD("_proximity_group_broadcast", "name", "params"), &ProximityGroup3D::_proximity_group_broadcast); ADD_PROPERTY(PropertyInfo(Variant::STRING, "group_name"), "set_group_name", "get_group_name"); ADD_PROPERTY(PropertyInfo(Variant::INT, "dispatch_mode", PROPERTY_HINT_ENUM, "Proxy,Signal"), "set_dispatch_mode", "get_dispatch_mode"); @@ -199,7 +199,7 @@ void ProximityGroup::_bind_methods() { BIND_ENUM_CONSTANT(MODE_SIGNAL); }; -ProximityGroup::ProximityGroup() { +ProximityGroup3D::ProximityGroup3D() { group_version = 0; dispatch_mode = MODE_PROXY; @@ -209,6 +209,6 @@ ProximityGroup::ProximityGroup() { set_notify_transform(true); }; -ProximityGroup::~ProximityGroup(){ +ProximityGroup3D::~ProximityGroup3D(){ }; diff --git a/scene/3d/proximity_group.h b/scene/3d/proximity_group_3d.h index 9ff8853178..751bfbdb52 100644 --- a/scene/3d/proximity_group.h +++ b/scene/3d/proximity_group_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* proximity_group.h */ +/* proximity_group_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,11 +31,11 @@ #ifndef PROXIMITY_GROUP_H #define PROXIMITY_GROUP_H -#include "spatial.h" +#include "node_3d.h" -class ProximityGroup : public Spatial { +class ProximityGroup3D : public Node3D { - GDCLASS(ProximityGroup, Spatial); + GDCLASS(ProximityGroup3D, Node3D); OBJ_CATEGORY("3D"); public: @@ -78,10 +78,10 @@ public: void broadcast(String p_name, Variant p_params); - ProximityGroup(); - ~ProximityGroup(); + ProximityGroup3D(); + ~ProximityGroup3D(); }; -VARIANT_ENUM_CAST(ProximityGroup::DispatchMode); +VARIANT_ENUM_CAST(ProximityGroup3D::DispatchMode); #endif diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast_3d.cpp index f6eb3d954a..a18da61656 100644 --- a/scene/3d/ray_cast.cpp +++ b/scene/3d/ray_cast_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* ray_cast.cpp */ +/* ray_cast_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "ray_cast.h" +#include "ray_cast_3d.h" -#include "collision_object.h" +#include "collision_object_3d.h" #include "core/engine.h" -#include "mesh_instance.h" -#include "servers/physics_server.h" +#include "mesh_instance_3d.h" +#include "servers/physics_server_3d.h" -void RayCast::set_cast_to(const Vector3 &p_point) { +void RayCast3D::set_cast_to(const Vector3 &p_point) { cast_to = p_point; if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) @@ -44,22 +44,22 @@ void RayCast::set_cast_to(const Vector3 &p_point) { _update_debug_shape(); } -Vector3 RayCast::get_cast_to() const { +Vector3 RayCast3D::get_cast_to() const { return cast_to; } -void RayCast::set_collision_mask(uint32_t p_mask) { +void RayCast3D::set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; } -uint32_t RayCast::get_collision_mask() const { +uint32_t RayCast3D::get_collision_mask() const { return collision_mask; } -void RayCast::set_collision_mask_bit(int p_bit, bool p_value) { +void RayCast3D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); if (p_value) @@ -69,37 +69,37 @@ void RayCast::set_collision_mask_bit(int p_bit, bool p_value) { set_collision_mask(mask); } -bool RayCast::get_collision_mask_bit(int p_bit) const { +bool RayCast3D::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } -bool RayCast::is_colliding() const { +bool RayCast3D::is_colliding() const { return collided; } -Object *RayCast::get_collider() const { +Object *RayCast3D::get_collider() const { if (against.is_null()) - return NULL; + return nullptr; return ObjectDB::get_instance(against); } -int RayCast::get_collider_shape() const { +int RayCast3D::get_collider_shape() const { return against_shape; } -Vector3 RayCast::get_collision_point() const { +Vector3 RayCast3D::get_collision_point() const { return collision_point; } -Vector3 RayCast::get_collision_normal() const { +Vector3 RayCast3D::get_collision_normal() const { return collision_normal; } -void RayCast::set_enabled(bool p_enabled) { +void RayCast3D::set_enabled(bool p_enabled) { enabled = p_enabled; update_gizmo(); @@ -117,12 +117,12 @@ void RayCast::set_enabled(bool p_enabled) { } } -bool RayCast::is_enabled() const { +bool RayCast3D::is_enabled() const { return enabled; } -void RayCast::set_exclude_parent_body(bool p_exclude_parent_body) { +void RayCast3D::set_exclude_parent_body(bool p_exclude_parent_body) { if (exclude_parent_body == p_exclude_parent_body) return; @@ -132,20 +132,20 @@ void RayCast::set_exclude_parent_body(bool p_exclude_parent_body) { if (!is_inside_tree()) return; - if (Object::cast_to<CollisionObject>(get_parent())) { + if (Object::cast_to<CollisionObject3D>(get_parent())) { if (exclude_parent_body) - exclude.insert(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + exclude.insert(Object::cast_to<CollisionObject3D>(get_parent())->get_rid()); else - exclude.erase(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + exclude.erase(Object::cast_to<CollisionObject3D>(get_parent())->get_rid()); } } -bool RayCast::get_exclude_parent_body() const { +bool RayCast3D::get_exclude_parent_body() const { return exclude_parent_body; } -void RayCast::_notification(int p_what) { +void RayCast3D::_notification(int p_what) { switch (p_what) { @@ -159,11 +159,11 @@ void RayCast::_notification(int p_what) { } else set_physics_process_internal(false); - if (Object::cast_to<CollisionObject>(get_parent())) { + if (Object::cast_to<CollisionObject3D>(get_parent())) { if (exclude_parent_body) - exclude.insert(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + exclude.insert(Object::cast_to<CollisionObject3D>(get_parent())->get_rid()); else - exclude.erase(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + exclude.erase(Object::cast_to<CollisionObject3D>(get_parent())->get_rid()); } } break; @@ -195,11 +195,11 @@ void RayCast::_notification(int p_what) { } } -void RayCast::_update_raycast_state() { - Ref<World> w3d = get_world(); +void RayCast3D::_update_raycast_state() { + Ref<World3D> w3d = get_world(); ERR_FAIL_COND(w3d.is_null()); - PhysicsDirectSpaceState *dss = PhysicsServer::get_singleton()->space_get_direct_state(w3d->get_space()); + PhysicsDirectSpaceState3D *dss = PhysicsServer3D::get_singleton()->space_get_direct_state(w3d->get_space()); ERR_FAIL_COND(!dss); Transform gt = get_global_transform(); @@ -208,7 +208,7 @@ void RayCast::_update_raycast_state() { if (to == Vector3()) to = Vector3(0, 0.01, 0); - PhysicsDirectSpaceState::RayResult rr; + PhysicsDirectSpaceState3D::RayResult rr; if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask, collide_with_bodies, collide_with_areas)) { @@ -224,101 +224,101 @@ void RayCast::_update_raycast_state() { } } -void RayCast::force_raycast_update() { +void RayCast3D::force_raycast_update() { _update_raycast_state(); } -void RayCast::add_exception_rid(const RID &p_rid) { +void RayCast3D::add_exception_rid(const RID &p_rid) { exclude.insert(p_rid); } -void RayCast::add_exception(const Object *p_object) { +void RayCast3D::add_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); - const CollisionObject *co = Object::cast_to<CollisionObject>(p_object); + const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object); if (!co) return; add_exception_rid(co->get_rid()); } -void RayCast::remove_exception_rid(const RID &p_rid) { +void RayCast3D::remove_exception_rid(const RID &p_rid) { exclude.erase(p_rid); } -void RayCast::remove_exception(const Object *p_object) { +void RayCast3D::remove_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); - const CollisionObject *co = Object::cast_to<CollisionObject>(p_object); + const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object); if (!co) return; remove_exception_rid(co->get_rid()); } -void RayCast::clear_exceptions() { +void RayCast3D::clear_exceptions() { exclude.clear(); } -void RayCast::set_collide_with_areas(bool p_clip) { +void RayCast3D::set_collide_with_areas(bool p_clip) { collide_with_areas = p_clip; } -bool RayCast::is_collide_with_areas_enabled() const { +bool RayCast3D::is_collide_with_areas_enabled() const { return collide_with_areas; } -void RayCast::set_collide_with_bodies(bool p_clip) { +void RayCast3D::set_collide_with_bodies(bool p_clip) { collide_with_bodies = p_clip; } -bool RayCast::is_collide_with_bodies_enabled() const { +bool RayCast3D::is_collide_with_bodies_enabled() const { return collide_with_bodies; } -void RayCast::_bind_methods() { +void RayCast3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &RayCast::set_enabled); - ClassDB::bind_method(D_METHOD("is_enabled"), &RayCast::is_enabled); + ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &RayCast3D::set_enabled); + ClassDB::bind_method(D_METHOD("is_enabled"), &RayCast3D::is_enabled); - ClassDB::bind_method(D_METHOD("set_cast_to", "local_point"), &RayCast::set_cast_to); - ClassDB::bind_method(D_METHOD("get_cast_to"), &RayCast::get_cast_to); + ClassDB::bind_method(D_METHOD("set_cast_to", "local_point"), &RayCast3D::set_cast_to); + ClassDB::bind_method(D_METHOD("get_cast_to"), &RayCast3D::get_cast_to); - ClassDB::bind_method(D_METHOD("is_colliding"), &RayCast::is_colliding); - ClassDB::bind_method(D_METHOD("force_raycast_update"), &RayCast::force_raycast_update); + ClassDB::bind_method(D_METHOD("is_colliding"), &RayCast3D::is_colliding); + ClassDB::bind_method(D_METHOD("force_raycast_update"), &RayCast3D::force_raycast_update); - ClassDB::bind_method(D_METHOD("get_collider"), &RayCast::get_collider); - ClassDB::bind_method(D_METHOD("get_collider_shape"), &RayCast::get_collider_shape); - ClassDB::bind_method(D_METHOD("get_collision_point"), &RayCast::get_collision_point); - ClassDB::bind_method(D_METHOD("get_collision_normal"), &RayCast::get_collision_normal); + ClassDB::bind_method(D_METHOD("get_collider"), &RayCast3D::get_collider); + ClassDB::bind_method(D_METHOD("get_collider_shape"), &RayCast3D::get_collider_shape); + ClassDB::bind_method(D_METHOD("get_collision_point"), &RayCast3D::get_collision_point); + ClassDB::bind_method(D_METHOD("get_collision_normal"), &RayCast3D::get_collision_normal); - ClassDB::bind_method(D_METHOD("add_exception_rid", "rid"), &RayCast::add_exception_rid); - ClassDB::bind_method(D_METHOD("add_exception", "node"), &RayCast::add_exception); + ClassDB::bind_method(D_METHOD("add_exception_rid", "rid"), &RayCast3D::add_exception_rid); + ClassDB::bind_method(D_METHOD("add_exception", "node"), &RayCast3D::add_exception); - ClassDB::bind_method(D_METHOD("remove_exception_rid", "rid"), &RayCast::remove_exception_rid); - ClassDB::bind_method(D_METHOD("remove_exception", "node"), &RayCast::remove_exception); + ClassDB::bind_method(D_METHOD("remove_exception_rid", "rid"), &RayCast3D::remove_exception_rid); + ClassDB::bind_method(D_METHOD("remove_exception", "node"), &RayCast3D::remove_exception); - ClassDB::bind_method(D_METHOD("clear_exceptions"), &RayCast::clear_exceptions); + ClassDB::bind_method(D_METHOD("clear_exceptions"), &RayCast3D::clear_exceptions); - ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &RayCast::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &RayCast::get_collision_mask); + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &RayCast3D::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &RayCast3D::get_collision_mask); - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &RayCast::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &RayCast::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &RayCast3D::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &RayCast3D::get_collision_mask_bit); - ClassDB::bind_method(D_METHOD("set_exclude_parent_body", "mask"), &RayCast::set_exclude_parent_body); - ClassDB::bind_method(D_METHOD("get_exclude_parent_body"), &RayCast::get_exclude_parent_body); + ClassDB::bind_method(D_METHOD("set_exclude_parent_body", "mask"), &RayCast3D::set_exclude_parent_body); + ClassDB::bind_method(D_METHOD("get_exclude_parent_body"), &RayCast3D::get_exclude_parent_body); - ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &RayCast::set_collide_with_areas); - ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &RayCast::is_collide_with_areas_enabled); + ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &RayCast3D::set_collide_with_areas); + ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &RayCast3D::is_collide_with_areas_enabled); - ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &RayCast::set_collide_with_bodies); - ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &RayCast::is_collide_with_bodies_enabled); + ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &RayCast3D::set_collide_with_bodies); + ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &RayCast3D::is_collide_with_bodies_enabled); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclude_parent"), "set_exclude_parent_body", "get_exclude_parent_body"); @@ -330,7 +330,7 @@ void RayCast::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collide_with_bodies", "is_collide_with_bodies_enabled"); } -void RayCast::_create_debug_shape() { +void RayCast3D::_create_debug_shape() { if (!debug_material.is_valid()) { debug_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); @@ -342,14 +342,14 @@ void RayCast::_create_debug_shape() { Ref<ArrayMesh> mesh = memnew(ArrayMesh); - MeshInstance *mi = memnew(MeshInstance); + MeshInstance3D *mi = memnew(MeshInstance3D); mi->set_mesh(mesh); add_child(mi); debug_shape = mi; } -void RayCast::_update_debug_shape() { +void RayCast3D::_update_debug_shape() { if (!enabled) return; @@ -357,7 +357,7 @@ void RayCast::_update_debug_shape() { if (!debug_shape) _create_debug_shape(); - MeshInstance *mi = static_cast<MeshInstance *>(debug_shape); + MeshInstance3D *mi = static_cast<MeshInstance3D *>(debug_shape); if (!mi->get_mesh().is_valid()) return; @@ -376,21 +376,21 @@ void RayCast::_update_debug_shape() { mesh->surface_set_material(0, debug_material); } -void RayCast::_clear_debug_shape() { +void RayCast3D::_clear_debug_shape() { if (!debug_shape) return; - MeshInstance *mi = static_cast<MeshInstance *>(debug_shape); + MeshInstance3D *mi = static_cast<MeshInstance3D *>(debug_shape); if (mi->is_inside_tree()) mi->queue_delete(); else memdelete(mi); - debug_shape = NULL; + debug_shape = nullptr; } -RayCast::RayCast() { +RayCast3D::RayCast3D() { enabled = false; @@ -398,7 +398,7 @@ RayCast::RayCast() { against_shape = 0; collision_mask = 1; cast_to = Vector3(0, -1, 0); - debug_shape = NULL; + debug_shape = nullptr; exclude_parent_body = true; collide_with_areas = false; collide_with_bodies = true; diff --git a/scene/3d/ray_cast.h b/scene/3d/ray_cast_3d.h index 5cebfe3ac2..f8bfb7846a 100644 --- a/scene/3d/ray_cast.h +++ b/scene/3d/ray_cast_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* ray_cast.h */ +/* ray_cast_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef RAY_CAST_H -#define RAY_CAST_H +#ifndef RAY_CAST_3D_H +#define RAY_CAST_3D_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" -class RayCast : public Spatial { +class RayCast3D : public Node3D { - GDCLASS(RayCast, Spatial); + GDCLASS(RayCast3D, Node3D); bool enabled; bool collided; @@ -100,7 +100,7 @@ public: void remove_exception(const Object *p_object); void clear_exceptions(); - RayCast(); + RayCast3D(); }; #endif // RAY_CAST_H diff --git a/scene/3d/reflection_probe.cpp b/scene/3d/reflection_probe.cpp index 3cf8e43ec2..24bf8b43d1 100644 --- a/scene/3d/reflection_probe.cpp +++ b/scene/3d/reflection_probe.cpp @@ -33,7 +33,7 @@ void ReflectionProbe::set_intensity(float p_intensity) { intensity = p_intensity; - VS::get_singleton()->reflection_probe_set_intensity(probe, p_intensity); + RS::get_singleton()->reflection_probe_set_intensity(probe, p_intensity); } float ReflectionProbe::get_intensity() const { @@ -44,12 +44,12 @@ float ReflectionProbe::get_intensity() const { void ReflectionProbe::set_interior_ambient(Color p_ambient) { interior_ambient = p_ambient; - VS::get_singleton()->reflection_probe_set_interior_ambient(probe, p_ambient); + RS::get_singleton()->reflection_probe_set_interior_ambient(probe, p_ambient); } void ReflectionProbe::set_interior_ambient_energy(float p_energy) { interior_ambient_energy = p_energy; - VS::get_singleton()->reflection_probe_set_interior_ambient_energy(probe, p_energy); + RS::get_singleton()->reflection_probe_set_interior_ambient_energy(probe, p_energy); } float ReflectionProbe::get_interior_ambient_energy() const { @@ -64,7 +64,7 @@ Color ReflectionProbe::get_interior_ambient() const { void ReflectionProbe::set_interior_ambient_probe_contribution(float p_contribution) { interior_ambient_probe_contribution = p_contribution; - VS::get_singleton()->reflection_probe_set_interior_ambient_probe_contribution(probe, p_contribution); + RS::get_singleton()->reflection_probe_set_interior_ambient_probe_contribution(probe, p_contribution); } float ReflectionProbe::get_interior_ambient_probe_contribution() const { @@ -75,7 +75,7 @@ float ReflectionProbe::get_interior_ambient_probe_contribution() const { void ReflectionProbe::set_max_distance(float p_distance) { max_distance = p_distance; - VS::get_singleton()->reflection_probe_set_max_distance(probe, p_distance); + RS::get_singleton()->reflection_probe_set_max_distance(probe, p_distance); } float ReflectionProbe::get_max_distance() const { @@ -97,8 +97,8 @@ void ReflectionProbe::set_extents(const Vector3 &p_extents) { } } - VS::get_singleton()->reflection_probe_set_extents(probe, extents); - VS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset); + RS::get_singleton()->reflection_probe_set_extents(probe, extents); + RS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset); _change_notify("extents"); update_gizmo(); } @@ -117,8 +117,8 @@ void ReflectionProbe::set_origin_offset(const Vector3 &p_extents) { origin_offset[i] = SGN(origin_offset[i]) * (extents[i] - 0.01); } } - VS::get_singleton()->reflection_probe_set_extents(probe, extents); - VS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset); + RS::get_singleton()->reflection_probe_set_extents(probe, extents); + RS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset); _change_notify("origin_offset"); update_gizmo(); @@ -131,7 +131,7 @@ Vector3 ReflectionProbe::get_origin_offset() const { void ReflectionProbe::set_enable_box_projection(bool p_enable) { box_projection = p_enable; - VS::get_singleton()->reflection_probe_set_enable_box_projection(probe, p_enable); + RS::get_singleton()->reflection_probe_set_enable_box_projection(probe, p_enable); } bool ReflectionProbe::is_box_projection_enabled() const { @@ -141,7 +141,7 @@ bool ReflectionProbe::is_box_projection_enabled() const { void ReflectionProbe::set_as_interior(bool p_enable) { interior = p_enable; - VS::get_singleton()->reflection_probe_set_as_interior(probe, interior); + RS::get_singleton()->reflection_probe_set_as_interior(probe, interior); _change_notify(); } @@ -153,7 +153,7 @@ bool ReflectionProbe::is_set_as_interior() const { void ReflectionProbe::set_enable_shadows(bool p_enable) { enable_shadows = p_enable; - VS::get_singleton()->reflection_probe_set_enable_shadows(probe, p_enable); + RS::get_singleton()->reflection_probe_set_enable_shadows(probe, p_enable); } bool ReflectionProbe::are_shadows_enabled() const { @@ -163,7 +163,7 @@ bool ReflectionProbe::are_shadows_enabled() const { void ReflectionProbe::set_cull_mask(uint32_t p_layers) { cull_mask = p_layers; - VS::get_singleton()->reflection_probe_set_cull_mask(probe, p_layers); + RS::get_singleton()->reflection_probe_set_cull_mask(probe, p_layers); } uint32_t ReflectionProbe::get_cull_mask() const { @@ -172,7 +172,7 @@ uint32_t ReflectionProbe::get_cull_mask() const { void ReflectionProbe::set_update_mode(UpdateMode p_mode) { update_mode = p_mode; - VS::get_singleton()->reflection_probe_set_update_mode(probe, VS::ReflectionProbeUpdateMode(p_mode)); + RS::get_singleton()->reflection_probe_set_update_mode(probe, RS::ReflectionProbeUpdateMode(p_mode)); } ReflectionProbe::UpdateMode ReflectionProbe::get_update_mode() const { @@ -272,12 +272,12 @@ ReflectionProbe::ReflectionProbe() { cull_mask = (1 << 20) - 1; update_mode = UPDATE_ONCE; - probe = VisualServer::get_singleton()->reflection_probe_create(); - VS::get_singleton()->instance_set_base(get_instance(), probe); + probe = RenderingServer::get_singleton()->reflection_probe_create(); + RS::get_singleton()->instance_set_base(get_instance(), probe); set_disable_scale(true); } ReflectionProbe::~ReflectionProbe() { - VS::get_singleton()->free(probe); + RS::get_singleton()->free(probe); } diff --git a/scene/3d/reflection_probe.h b/scene/3d/reflection_probe.h index 57c1b0a320..3867d13435 100644 --- a/scene/3d/reflection_probe.h +++ b/scene/3d/reflection_probe.h @@ -31,13 +31,13 @@ #ifndef REFLECTIONPROBE_H #define REFLECTIONPROBE_H -#include "scene/3d/visual_instance.h" +#include "scene/3d/visual_instance_3d.h" #include "scene/resources/sky.h" #include "scene/resources/texture.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" -class ReflectionProbe : public VisualInstance { - GDCLASS(ReflectionProbe, VisualInstance); +class ReflectionProbe : public VisualInstance3D { + GDCLASS(ReflectionProbe, VisualInstance3D); public: enum UpdateMode { diff --git a/scene/3d/remote_transform.cpp b/scene/3d/remote_transform_3d.cpp index 9ef43647ba..38792bbb58 100644 --- a/scene/3d/remote_transform.cpp +++ b/scene/3d/remote_transform_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* remote_transform.cpp */ +/* remote_transform_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,9 +28,9 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "remote_transform.h" +#include "remote_transform_3d.h" -void RemoteTransform::_update_cache() { +void RemoteTransform3D::_update_cache() { cache = ObjectID(); if (has_node(remote_node)) { Node *node = get_node(remote_node); @@ -42,7 +42,7 @@ void RemoteTransform::_update_cache() { } } -void RemoteTransform::_update_remote() { +void RemoteTransform3D::_update_remote() { if (!is_inside_tree()) return; @@ -50,7 +50,7 @@ void RemoteTransform::_update_remote() { if (cache.is_null()) return; - Spatial *n = Object::cast_to<Spatial>(ObjectDB::get_instance(cache)); + Node3D *n = Object::cast_to<Node3D>(ObjectDB::get_instance(cache)); if (!n) return; @@ -101,7 +101,7 @@ void RemoteTransform::_update_remote() { } } -void RemoteTransform::_notification(int p_what) { +void RemoteTransform3D::_notification(int p_what) { switch (p_what) { @@ -123,7 +123,7 @@ void RemoteTransform::_notification(int p_what) { } } -void RemoteTransform::set_remote_node(const NodePath &p_remote_node) { +void RemoteTransform3D::set_remote_node(const NodePath &p_remote_node) { remote_node = p_remote_node; if (is_inside_tree()) { @@ -134,76 +134,76 @@ void RemoteTransform::set_remote_node(const NodePath &p_remote_node) { update_configuration_warning(); } -NodePath RemoteTransform::get_remote_node() const { +NodePath RemoteTransform3D::get_remote_node() const { return remote_node; } -void RemoteTransform::set_use_global_coordinates(const bool p_enable) { +void RemoteTransform3D::set_use_global_coordinates(const bool p_enable) { use_global_coordinates = p_enable; } -bool RemoteTransform::get_use_global_coordinates() const { +bool RemoteTransform3D::get_use_global_coordinates() const { return use_global_coordinates; } -void RemoteTransform::set_update_position(const bool p_update) { +void RemoteTransform3D::set_update_position(const bool p_update) { update_remote_position = p_update; _update_remote(); } -bool RemoteTransform::get_update_position() const { +bool RemoteTransform3D::get_update_position() const { return update_remote_position; } -void RemoteTransform::set_update_rotation(const bool p_update) { +void RemoteTransform3D::set_update_rotation(const bool p_update) { update_remote_rotation = p_update; _update_remote(); } -bool RemoteTransform::get_update_rotation() const { +bool RemoteTransform3D::get_update_rotation() const { return update_remote_rotation; } -void RemoteTransform::set_update_scale(const bool p_update) { +void RemoteTransform3D::set_update_scale(const bool p_update) { update_remote_scale = p_update; _update_remote(); } -bool RemoteTransform::get_update_scale() const { +bool RemoteTransform3D::get_update_scale() const { return update_remote_scale; } -void RemoteTransform::force_update_cache() { +void RemoteTransform3D::force_update_cache() { _update_cache(); } -String RemoteTransform::get_configuration_warning() const { +String RemoteTransform3D::get_configuration_warning() const { - if (!has_node(remote_node) || !Object::cast_to<Spatial>(get_node(remote_node))) { - return TTR("The \"Remote Path\" property must point to a valid Spatial or Spatial-derived node to work."); + if (!has_node(remote_node) || !Object::cast_to<Node3D>(get_node(remote_node))) { + return TTR("The \"Remote Path\" property must point to a valid Node3D or Node3D-derived node to work."); } return String(); } -void RemoteTransform::_bind_methods() { +void RemoteTransform3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_remote_node", "path"), &RemoteTransform::set_remote_node); - ClassDB::bind_method(D_METHOD("get_remote_node"), &RemoteTransform::get_remote_node); - ClassDB::bind_method(D_METHOD("force_update_cache"), &RemoteTransform::force_update_cache); + ClassDB::bind_method(D_METHOD("set_remote_node", "path"), &RemoteTransform3D::set_remote_node); + ClassDB::bind_method(D_METHOD("get_remote_node"), &RemoteTransform3D::get_remote_node); + ClassDB::bind_method(D_METHOD("force_update_cache"), &RemoteTransform3D::force_update_cache); - ClassDB::bind_method(D_METHOD("set_use_global_coordinates", "use_global_coordinates"), &RemoteTransform::set_use_global_coordinates); - ClassDB::bind_method(D_METHOD("get_use_global_coordinates"), &RemoteTransform::get_use_global_coordinates); + ClassDB::bind_method(D_METHOD("set_use_global_coordinates", "use_global_coordinates"), &RemoteTransform3D::set_use_global_coordinates); + ClassDB::bind_method(D_METHOD("get_use_global_coordinates"), &RemoteTransform3D::get_use_global_coordinates); - ClassDB::bind_method(D_METHOD("set_update_position", "update_remote_position"), &RemoteTransform::set_update_position); - ClassDB::bind_method(D_METHOD("get_update_position"), &RemoteTransform::get_update_position); - ClassDB::bind_method(D_METHOD("set_update_rotation", "update_remote_rotation"), &RemoteTransform::set_update_rotation); - ClassDB::bind_method(D_METHOD("get_update_rotation"), &RemoteTransform::get_update_rotation); - ClassDB::bind_method(D_METHOD("set_update_scale", "update_remote_scale"), &RemoteTransform::set_update_scale); - ClassDB::bind_method(D_METHOD("get_update_scale"), &RemoteTransform::get_update_scale); + ClassDB::bind_method(D_METHOD("set_update_position", "update_remote_position"), &RemoteTransform3D::set_update_position); + ClassDB::bind_method(D_METHOD("get_update_position"), &RemoteTransform3D::get_update_position); + ClassDB::bind_method(D_METHOD("set_update_rotation", "update_remote_rotation"), &RemoteTransform3D::set_update_rotation); + ClassDB::bind_method(D_METHOD("get_update_rotation"), &RemoteTransform3D::get_update_rotation); + ClassDB::bind_method(D_METHOD("set_update_scale", "update_remote_scale"), &RemoteTransform3D::set_update_scale); + ClassDB::bind_method(D_METHOD("get_update_scale"), &RemoteTransform3D::get_update_scale); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "remote_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Spatial"), "set_remote_node", "get_remote_node"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "remote_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Node3D"), "set_remote_node", "get_remote_node"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_global_coordinates"), "set_use_global_coordinates", "get_use_global_coordinates"); ADD_GROUP("Update", "update_"); @@ -212,7 +212,7 @@ void RemoteTransform::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "update_scale"), "set_update_scale", "get_update_scale"); } -RemoteTransform::RemoteTransform() { +RemoteTransform3D::RemoteTransform3D() { use_global_coordinates = true; update_remote_position = true; diff --git a/scene/3d/remote_transform.h b/scene/3d/remote_transform_3d.h index 02e448832f..50d7c5a9b2 100644 --- a/scene/3d/remote_transform.h +++ b/scene/3d/remote_transform_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* remote_transform.h */ +/* remote_transform_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,10 +31,10 @@ #ifndef REMOTETRANSFORM_H #define REMOTETRANSFORM_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" -class RemoteTransform : public Spatial { - GDCLASS(RemoteTransform, Spatial); +class RemoteTransform3D : public Node3D { + GDCLASS(RemoteTransform3D, Node3D); NodePath remote_node; @@ -72,7 +72,7 @@ public: virtual String get_configuration_warning() const; - RemoteTransform(); + RemoteTransform3D(); }; #endif // REMOTETRANSFORM_H diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton_3d.cpp index b2252bcb04..973822653a 100644 --- a/scene/3d/skeleton.cpp +++ b/scene/3d/skeleton_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* skeleton.cpp */ +/* skeleton_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,12 +28,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "skeleton.h" +#include "skeleton_3d.h" #include "core/engine.h" #include "core/message_queue.h" #include "core/project_settings.h" -#include "scene/3d/physics_body.h" +#include "core/type_info.h" +#include "scene/3d/physics_body_3d.h" #include "scene/resources/surface_tool.h" void SkinReference::_skin_changed() { @@ -62,10 +63,10 @@ SkinReference::~SkinReference() { skeleton_node->skin_bindings.erase(this); } - VS::get_singleton()->free(skeleton); + RS::get_singleton()->free(skeleton); } -bool Skeleton::_set(const StringName &p_path, const Variant &p_value) { +bool Skeleton3D::_set(const StringName &p_path, const Variant &p_value) { String path = p_path; @@ -113,7 +114,7 @@ bool Skeleton::_set(const StringName &p_path, const Variant &p_value) { return true; } -bool Skeleton::_get(const StringName &p_path, Variant &r_ret) const { +bool Skeleton3D::_get(const StringName &p_path, Variant &r_ret) const { String path = p_path; @@ -154,7 +155,7 @@ bool Skeleton::_get(const StringName &p_path, Variant &r_ret) const { return true; } -void Skeleton::_get_property_list(List<PropertyInfo> *p_list) const { +void Skeleton3D::_get_property_list(List<PropertyInfo> *p_list) const { for (int i = 0; i < bones.size(); i++) { @@ -168,7 +169,7 @@ void Skeleton::_get_property_list(List<PropertyInfo> *p_list) const { } } -void Skeleton::_update_process_order() { +void Skeleton3D::_update_process_order() { if (!process_order_dirty) return; @@ -221,13 +222,13 @@ void Skeleton::_update_process_order() { process_order_dirty = false; } -void Skeleton::_notification(int p_what) { +void Skeleton3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_UPDATE_SKELETON: { - VisualServer *vs = VisualServer::get_singleton(); + RenderingServer *vs = RenderingServer::get_singleton(); Bone *bonesptr = bones.ptrw(); int len = bones.size(); @@ -306,7 +307,7 @@ void Skeleton::_notification(int p_what) { Object *obj = ObjectDB::get_instance(E->get()); ERR_CONTINUE(!obj); - Spatial *sp = Object::cast_to<Spatial>(obj); + Node3D *sp = Object::cast_to<Node3D>(obj); ERR_CONTINUE(!sp); sp->set_transform(b.pose_global); } @@ -320,7 +321,7 @@ void Skeleton::_notification(int p_what) { uint32_t bind_count = skin->get_bind_count(); if (E->get()->bind_count != bind_count) { - VS::get_singleton()->skeleton_allocate(skeleton, bind_count); + RS::get_singleton()->skeleton_allocate(skeleton, bind_count); E->get()->bind_count = bind_count; E->get()->skin_bone_indices.resize(bind_count); E->get()->skin_bone_indices_ptrs = E->get()->skin_bone_indices.ptrw(); @@ -396,7 +397,14 @@ void Skeleton::_notification(int p_what) { } } -void Skeleton::set_bone_global_pose_override(int p_bone, const Transform &p_pose, float p_amount, bool p_persistent) { +void Skeleton3D::clear_bones_global_pose_override() { + for (int i = 0; i < bones.size(); i += 1) { + bones.write[i].global_pose_override_amount = 0; + } + _make_dirty(); +} + +void Skeleton3D::set_bone_global_pose_override(int p_bone, const Transform &p_pose, float p_amount, bool p_persistent) { ERR_FAIL_INDEX(p_bone, bones.size()); bones.write[p_bone].global_pose_override_amount = p_amount; @@ -405,16 +413,16 @@ void Skeleton::set_bone_global_pose_override(int p_bone, const Transform &p_pose _make_dirty(); } -Transform Skeleton::get_bone_global_pose(int p_bone) const { +Transform Skeleton3D::get_bone_global_pose(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform()); if (dirty) - const_cast<Skeleton *>(this)->notification(NOTIFICATION_UPDATE_SKELETON); + const_cast<Skeleton3D *>(this)->notification(NOTIFICATION_UPDATE_SKELETON); return bones[p_bone].pose_global; } // skeleton creation api -void Skeleton::add_bone(const String &p_name) { +void Skeleton3D::add_bone(const String &p_name) { ERR_FAIL_COND(p_name == "" || p_name.find(":") != -1 || p_name.find("/") != -1); @@ -431,7 +439,7 @@ void Skeleton::add_bone(const String &p_name) { _make_dirty(); update_gizmo(); } -int Skeleton::find_bone(const String &p_name) const { +int Skeleton3D::find_bone(const String &p_name) const { for (int i = 0; i < bones.size(); i++) { @@ -441,14 +449,14 @@ int Skeleton::find_bone(const String &p_name) const { return -1; } -String Skeleton::get_bone_name(int p_bone) const { +String Skeleton3D::get_bone_name(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), ""); return bones[p_bone].name; } -bool Skeleton::is_bone_parent_of(int p_bone, int p_parent_bone_id) const { +bool Skeleton3D::is_bone_parent_of(int p_bone, int p_parent_bone_id) const { int parent_of_bone = get_bone_parent(p_bone); @@ -461,12 +469,12 @@ bool Skeleton::is_bone_parent_of(int p_bone, int p_parent_bone_id) const { return is_bone_parent_of(parent_of_bone, p_parent_bone_id); } -int Skeleton::get_bone_count() const { +int Skeleton3D::get_bone_count() const { return bones.size(); } -void Skeleton::set_bone_parent(int p_bone, int p_parent) { +void Skeleton3D::set_bone_parent(int p_bone, int p_parent) { ERR_FAIL_INDEX(p_bone, bones.size()); ERR_FAIL_COND(p_parent != -1 && (p_parent < 0)); @@ -476,7 +484,7 @@ void Skeleton::set_bone_parent(int p_bone, int p_parent) { _make_dirty(); } -void Skeleton::unparent_bone_and_rest(int p_bone) { +void Skeleton3D::unparent_bone_and_rest(int p_bone) { ERR_FAIL_INDEX(p_bone, bones.size()); @@ -494,53 +502,53 @@ void Skeleton::unparent_bone_and_rest(int p_bone) { _make_dirty(); } -void Skeleton::set_bone_disable_rest(int p_bone, bool p_disable) { +void Skeleton3D::set_bone_disable_rest(int p_bone, bool p_disable) { ERR_FAIL_INDEX(p_bone, bones.size()); bones.write[p_bone].disable_rest = p_disable; } -bool Skeleton::is_bone_rest_disabled(int p_bone) const { +bool Skeleton3D::is_bone_rest_disabled(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), false); return bones[p_bone].disable_rest; } -int Skeleton::get_bone_parent(int p_bone) const { +int Skeleton3D::get_bone_parent(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), -1); return bones[p_bone].parent; } -void Skeleton::set_bone_rest(int p_bone, const Transform &p_rest) { +void Skeleton3D::set_bone_rest(int p_bone, const Transform &p_rest) { ERR_FAIL_INDEX(p_bone, bones.size()); bones.write[p_bone].rest = p_rest; _make_dirty(); } -Transform Skeleton::get_bone_rest(int p_bone) const { +Transform Skeleton3D::get_bone_rest(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform()); return bones[p_bone].rest; } -void Skeleton::set_bone_enabled(int p_bone, bool p_enabled) { +void Skeleton3D::set_bone_enabled(int p_bone, bool p_enabled) { ERR_FAIL_INDEX(p_bone, bones.size()); bones.write[p_bone].enabled = p_enabled; _make_dirty(); } -bool Skeleton::is_bone_enabled(int p_bone) const { +bool Skeleton3D::is_bone_enabled(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), false); return bones[p_bone].enabled; } -void Skeleton::bind_child_node_to_bone(int p_bone, Node *p_node) { +void Skeleton3D::bind_child_node_to_bone(int p_bone, Node *p_node) { ERR_FAIL_NULL(p_node); ERR_FAIL_INDEX(p_bone, bones.size()); @@ -555,7 +563,7 @@ void Skeleton::bind_child_node_to_bone(int p_bone, Node *p_node) { bones.write[p_bone].nodes_bound.push_back(id); } -void Skeleton::unbind_child_node_from_bone(int p_bone, Node *p_node) { +void Skeleton3D::unbind_child_node_from_bone(int p_bone, Node *p_node) { ERR_FAIL_NULL(p_node); ERR_FAIL_INDEX(p_bone, bones.size()); @@ -563,7 +571,7 @@ void Skeleton::unbind_child_node_from_bone(int p_bone, Node *p_node) { ObjectID id = p_node->get_instance_id(); bones.write[p_bone].nodes_bound.erase(id); } -void Skeleton::get_bound_child_nodes_to_bone(int p_bone, List<Node *> *p_bound) const { +void Skeleton3D::get_bound_child_nodes_to_bone(int p_bone, List<Node *> *p_bound) const { ERR_FAIL_INDEX(p_bone, bones.size()); @@ -575,7 +583,7 @@ void Skeleton::get_bound_child_nodes_to_bone(int p_bone, List<Node *> *p_bound) } } -void Skeleton::clear_bones() { +void Skeleton3D::clear_bones() { bones.clear(); process_order_dirty = true; @@ -585,7 +593,7 @@ void Skeleton::clear_bones() { // posing api -void Skeleton::set_bone_pose(int p_bone, const Transform &p_pose) { +void Skeleton3D::set_bone_pose(int p_bone, const Transform &p_pose) { ERR_FAIL_INDEX(p_bone, bones.size()); @@ -594,13 +602,13 @@ void Skeleton::set_bone_pose(int p_bone, const Transform &p_pose) { _make_dirty(); } } -Transform Skeleton::get_bone_pose(int p_bone) const { +Transform Skeleton3D::get_bone_pose(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform()); return bones[p_bone].pose; } -void Skeleton::set_bone_custom_pose(int p_bone, const Transform &p_custom_pose) { +void Skeleton3D::set_bone_custom_pose(int p_bone, const Transform &p_custom_pose) { ERR_FAIL_INDEX(p_bone, bones.size()); //ERR_FAIL_COND( !is_inside_scene() ); @@ -611,13 +619,13 @@ void Skeleton::set_bone_custom_pose(int p_bone, const Transform &p_custom_pose) _make_dirty(); } -Transform Skeleton::get_bone_custom_pose(int p_bone) const { +Transform Skeleton3D::get_bone_custom_pose(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform()); return bones[p_bone].custom_pose; } -void Skeleton::_make_dirty() { +void Skeleton3D::_make_dirty() { if (dirty) return; @@ -626,13 +634,13 @@ void Skeleton::_make_dirty() { dirty = true; } -int Skeleton::get_process_order(int p_idx) { +int Skeleton3D::get_process_order(int p_idx) { ERR_FAIL_INDEX_V(p_idx, bones.size(), -1); _update_process_order(); return process_order[p_idx]; } -void Skeleton::localize_rests() { +void Skeleton3D::localize_rests() { _update_process_order(); @@ -646,7 +654,7 @@ void Skeleton::localize_rests() { #ifndef _3D_DISABLED -void Skeleton::set_animate_physical_bones(bool p_animate) { +void Skeleton3D::set_animate_physical_bones(bool p_animate) { animate_physical_bones = p_animate; if (Engine::get_singleton()->is_editor_hint() == false) { @@ -663,11 +671,11 @@ void Skeleton::set_animate_physical_bones(bool p_animate) { } } -bool Skeleton::get_animate_physical_bones() const { +bool Skeleton3D::get_animate_physical_bones() const { return animate_physical_bones; } -void Skeleton::bind_physical_bone_to_bone(int p_bone, PhysicalBone *p_physical_bone) { +void Skeleton3D::bind_physical_bone_to_bone(int p_bone, PhysicalBone3D *p_physical_bone) { ERR_FAIL_INDEX(p_bone, bones.size()); ERR_FAIL_COND(bones[p_bone].physical_bone); ERR_FAIL_COND(!p_physical_bone); @@ -676,21 +684,21 @@ void Skeleton::bind_physical_bone_to_bone(int p_bone, PhysicalBone *p_physical_b _rebuild_physical_bones_cache(); } -void Skeleton::unbind_physical_bone_from_bone(int p_bone) { +void Skeleton3D::unbind_physical_bone_from_bone(int p_bone) { ERR_FAIL_INDEX(p_bone, bones.size()); - bones.write[p_bone].physical_bone = NULL; + bones.write[p_bone].physical_bone = nullptr; _rebuild_physical_bones_cache(); } -PhysicalBone *Skeleton::get_physical_bone(int p_bone) { - ERR_FAIL_INDEX_V(p_bone, bones.size(), NULL); +PhysicalBone3D *Skeleton3D::get_physical_bone(int p_bone) { + ERR_FAIL_INDEX_V(p_bone, bones.size(), nullptr); return bones[p_bone].physical_bone; } -PhysicalBone *Skeleton::get_physical_bone_parent(int p_bone) { - ERR_FAIL_INDEX_V(p_bone, bones.size(), NULL); +PhysicalBone3D *Skeleton3D::get_physical_bone_parent(int p_bone) { + ERR_FAIL_INDEX_V(p_bone, bones.size(), nullptr); if (bones[p_bone].cache_parent_physical_bone) { return bones[p_bone].cache_parent_physical_bone; @@ -699,15 +707,15 @@ PhysicalBone *Skeleton::get_physical_bone_parent(int p_bone) { return _get_physical_bone_parent(p_bone); } -PhysicalBone *Skeleton::_get_physical_bone_parent(int p_bone) { - ERR_FAIL_INDEX_V(p_bone, bones.size(), NULL); +PhysicalBone3D *Skeleton3D::_get_physical_bone_parent(int p_bone) { + ERR_FAIL_INDEX_V(p_bone, bones.size(), nullptr); const int parent_bone = bones[p_bone].parent; if (0 > parent_bone) { - return NULL; + return nullptr; } - PhysicalBone *pb = bones[parent_bone].physical_bone; + PhysicalBone3D *pb = bones[parent_bone].physical_bone; if (pb) { return pb; } else { @@ -715,10 +723,10 @@ PhysicalBone *Skeleton::_get_physical_bone_parent(int p_bone) { } } -void Skeleton::_rebuild_physical_bones_cache() { +void Skeleton3D::_rebuild_physical_bones_cache() { const int b_size = bones.size(); for (int i = 0; i < b_size; ++i) { - PhysicalBone *parent_pb = _get_physical_bone_parent(i); + PhysicalBone3D *parent_pb = _get_physical_bone_parent(i); if (parent_pb != bones[i].physical_bone) { bones.write[i].cache_parent_physical_bone = parent_pb; if (bones[i].physical_bone) @@ -733,26 +741,26 @@ void _pb_stop_simulation(Node *p_node) { _pb_stop_simulation(p_node->get_child(i)); } - PhysicalBone *pb = Object::cast_to<PhysicalBone>(p_node); + PhysicalBone3D *pb = Object::cast_to<PhysicalBone3D>(p_node); if (pb) { pb->set_simulate_physics(false); } } -void Skeleton::physical_bones_stop_simulation() { +void Skeleton3D::physical_bones_stop_simulation() { _pb_stop_simulation(this); if (Engine::get_singleton()->is_editor_hint() == false && animate_physical_bones) { set_physics_process_internal(true); } } -void _pb_start_simulation(const Skeleton *p_skeleton, Node *p_node, const Vector<int> &p_sim_bones) { +void _pb_start_simulation(const Skeleton3D *p_skeleton, Node *p_node, const Vector<int> &p_sim_bones) { for (int i = p_node->get_child_count() - 1; 0 <= i; --i) { _pb_start_simulation(p_skeleton, p_node->get_child(i), p_sim_bones); } - PhysicalBone *pb = Object::cast_to<PhysicalBone>(p_node); + PhysicalBone3D *pb = Object::cast_to<PhysicalBone3D>(p_node); if (pb) { for (int i = p_sim_bones.size() - 1; 0 <= i; --i) { if (p_sim_bones[i] == pb->get_bone_id() || p_skeleton->is_bone_parent_of(pb->get_bone_id(), p_sim_bones[i])) { @@ -763,7 +771,7 @@ void _pb_start_simulation(const Skeleton *p_skeleton, Node *p_node, const Vector } } -void Skeleton::physical_bones_start_simulation_on(const Array &p_bones) { +void Skeleton3D::physical_bones_start_simulation_on(const TypedArray<StringName> &p_bones) { set_physics_process_internal(false); Vector<int> sim_bones; @@ -773,12 +781,9 @@ void Skeleton::physical_bones_start_simulation_on(const Array &p_bones) { sim_bones.resize(p_bones.size()); int c = 0; for (int i = sim_bones.size() - 1; 0 <= i; --i) { - Variant::Type type = p_bones.get(i).get_type(); - if (Variant::STRING == type || Variant::STRING_NAME == type) { - int bone_id = find_bone(p_bones.get(i)); - if (bone_id != -1) - sim_bones.write[c++] = bone_id; - } + int bone_id = find_bone(p_bones[i]); + if (bone_id != -1) + sim_bones.write[c++] = bone_id; } sim_bones.resize(c); } @@ -792,31 +797,31 @@ void _physical_bones_add_remove_collision_exception(bool p_add, Node *p_node, RI _physical_bones_add_remove_collision_exception(p_add, p_node->get_child(i), p_exception); } - CollisionObject *co = Object::cast_to<CollisionObject>(p_node); + CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_node); if (co) { if (p_add) { - PhysicsServer::get_singleton()->body_add_collision_exception(co->get_rid(), p_exception); + PhysicsServer3D::get_singleton()->body_add_collision_exception(co->get_rid(), p_exception); } else { - PhysicsServer::get_singleton()->body_remove_collision_exception(co->get_rid(), p_exception); + PhysicsServer3D::get_singleton()->body_remove_collision_exception(co->get_rid(), p_exception); } } } -void Skeleton::physical_bones_add_collision_exception(RID p_exception) { +void Skeleton3D::physical_bones_add_collision_exception(RID p_exception) { _physical_bones_add_remove_collision_exception(true, this, p_exception); } -void Skeleton::physical_bones_remove_collision_exception(RID p_exception) { +void Skeleton3D::physical_bones_remove_collision_exception(RID p_exception) { _physical_bones_add_remove_collision_exception(false, this, p_exception); } #endif // _3D_DISABLED -void Skeleton::_skin_changed() { +void Skeleton3D::_skin_changed() { _make_dirty(); } -Ref<SkinReference> Skeleton::register_skin(const Ref<Skin> &p_skin) { +Ref<SkinReference> Skeleton3D::register_skin(const Ref<Skin> &p_skin) { for (Set<SkinReference *>::Element *E = skin_bindings.front(); E; E = E->next()) { if (E->get()->skin == p_skin) { @@ -864,7 +869,7 @@ Ref<SkinReference> Skeleton::register_skin(const Ref<Skin> &p_skin) { skin_ref->skeleton_node = this; skin_ref->bind_count = 0; - skin_ref->skeleton = VisualServer::get_singleton()->skeleton_create(); + skin_ref->skeleton = RenderingServer::get_singleton()->skeleton_create(); skin_ref->skeleton_node = this; skin_ref->skin = skin; @@ -877,53 +882,54 @@ Ref<SkinReference> Skeleton::register_skin(const Ref<Skin> &p_skin) { return skin_ref; } -void Skeleton::_bind_methods() { +void Skeleton3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_bone", "name"), &Skeleton::add_bone); - ClassDB::bind_method(D_METHOD("find_bone", "name"), &Skeleton::find_bone); - ClassDB::bind_method(D_METHOD("get_bone_name", "bone_idx"), &Skeleton::get_bone_name); + ClassDB::bind_method(D_METHOD("add_bone", "name"), &Skeleton3D::add_bone); + ClassDB::bind_method(D_METHOD("find_bone", "name"), &Skeleton3D::find_bone); + ClassDB::bind_method(D_METHOD("get_bone_name", "bone_idx"), &Skeleton3D::get_bone_name); - ClassDB::bind_method(D_METHOD("get_bone_parent", "bone_idx"), &Skeleton::get_bone_parent); - ClassDB::bind_method(D_METHOD("set_bone_parent", "bone_idx", "parent_idx"), &Skeleton::set_bone_parent); + ClassDB::bind_method(D_METHOD("get_bone_parent", "bone_idx"), &Skeleton3D::get_bone_parent); + ClassDB::bind_method(D_METHOD("set_bone_parent", "bone_idx", "parent_idx"), &Skeleton3D::set_bone_parent); - ClassDB::bind_method(D_METHOD("get_bone_count"), &Skeleton::get_bone_count); + ClassDB::bind_method(D_METHOD("get_bone_count"), &Skeleton3D::get_bone_count); - ClassDB::bind_method(D_METHOD("unparent_bone_and_rest", "bone_idx"), &Skeleton::unparent_bone_and_rest); + ClassDB::bind_method(D_METHOD("unparent_bone_and_rest", "bone_idx"), &Skeleton3D::unparent_bone_and_rest); - ClassDB::bind_method(D_METHOD("get_bone_rest", "bone_idx"), &Skeleton::get_bone_rest); - ClassDB::bind_method(D_METHOD("set_bone_rest", "bone_idx", "rest"), &Skeleton::set_bone_rest); + ClassDB::bind_method(D_METHOD("get_bone_rest", "bone_idx"), &Skeleton3D::get_bone_rest); + ClassDB::bind_method(D_METHOD("set_bone_rest", "bone_idx", "rest"), &Skeleton3D::set_bone_rest); - ClassDB::bind_method(D_METHOD("register_skin", "skin"), &Skeleton::register_skin); + ClassDB::bind_method(D_METHOD("register_skin", "skin"), &Skeleton3D::register_skin); - ClassDB::bind_method(D_METHOD("localize_rests"), &Skeleton::localize_rests); + ClassDB::bind_method(D_METHOD("localize_rests"), &Skeleton3D::localize_rests); - ClassDB::bind_method(D_METHOD("set_bone_disable_rest", "bone_idx", "disable"), &Skeleton::set_bone_disable_rest); - ClassDB::bind_method(D_METHOD("is_bone_rest_disabled", "bone_idx"), &Skeleton::is_bone_rest_disabled); + ClassDB::bind_method(D_METHOD("set_bone_disable_rest", "bone_idx", "disable"), &Skeleton3D::set_bone_disable_rest); + ClassDB::bind_method(D_METHOD("is_bone_rest_disabled", "bone_idx"), &Skeleton3D::is_bone_rest_disabled); - ClassDB::bind_method(D_METHOD("bind_child_node_to_bone", "bone_idx", "node"), &Skeleton::bind_child_node_to_bone); - ClassDB::bind_method(D_METHOD("unbind_child_node_from_bone", "bone_idx", "node"), &Skeleton::unbind_child_node_from_bone); - ClassDB::bind_method(D_METHOD("get_bound_child_nodes_to_bone", "bone_idx"), &Skeleton::_get_bound_child_nodes_to_bone); + ClassDB::bind_method(D_METHOD("bind_child_node_to_bone", "bone_idx", "node"), &Skeleton3D::bind_child_node_to_bone); + ClassDB::bind_method(D_METHOD("unbind_child_node_from_bone", "bone_idx", "node"), &Skeleton3D::unbind_child_node_from_bone); + ClassDB::bind_method(D_METHOD("get_bound_child_nodes_to_bone", "bone_idx"), &Skeleton3D::_get_bound_child_nodes_to_bone); - ClassDB::bind_method(D_METHOD("clear_bones"), &Skeleton::clear_bones); + ClassDB::bind_method(D_METHOD("clear_bones"), &Skeleton3D::clear_bones); - ClassDB::bind_method(D_METHOD("get_bone_pose", "bone_idx"), &Skeleton::get_bone_pose); - ClassDB::bind_method(D_METHOD("set_bone_pose", "bone_idx", "pose"), &Skeleton::set_bone_pose); + ClassDB::bind_method(D_METHOD("get_bone_pose", "bone_idx"), &Skeleton3D::get_bone_pose); + ClassDB::bind_method(D_METHOD("set_bone_pose", "bone_idx", "pose"), &Skeleton3D::set_bone_pose); - ClassDB::bind_method(D_METHOD("set_bone_global_pose_override", "bone_idx", "pose", "amount", "persistent"), &Skeleton::set_bone_global_pose_override, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("get_bone_global_pose", "bone_idx"), &Skeleton::get_bone_global_pose); + ClassDB::bind_method(D_METHOD("clear_bones_global_pose_override"), &Skeleton3D::clear_bones_global_pose_override); + ClassDB::bind_method(D_METHOD("set_bone_global_pose_override", "bone_idx", "pose", "amount", "persistent"), &Skeleton3D::set_bone_global_pose_override, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("get_bone_global_pose", "bone_idx"), &Skeleton3D::get_bone_global_pose); - ClassDB::bind_method(D_METHOD("get_bone_custom_pose", "bone_idx"), &Skeleton::get_bone_custom_pose); - ClassDB::bind_method(D_METHOD("set_bone_custom_pose", "bone_idx", "custom_pose"), &Skeleton::set_bone_custom_pose); + ClassDB::bind_method(D_METHOD("get_bone_custom_pose", "bone_idx"), &Skeleton3D::get_bone_custom_pose); + ClassDB::bind_method(D_METHOD("set_bone_custom_pose", "bone_idx", "custom_pose"), &Skeleton3D::set_bone_custom_pose); #ifndef _3D_DISABLED - ClassDB::bind_method(D_METHOD("set_animate_physical_bones"), &Skeleton::set_animate_physical_bones); - ClassDB::bind_method(D_METHOD("get_animate_physical_bones"), &Skeleton::get_animate_physical_bones); + ClassDB::bind_method(D_METHOD("set_animate_physical_bones"), &Skeleton3D::set_animate_physical_bones); + ClassDB::bind_method(D_METHOD("get_animate_physical_bones"), &Skeleton3D::get_animate_physical_bones); - ClassDB::bind_method(D_METHOD("physical_bones_stop_simulation"), &Skeleton::physical_bones_stop_simulation); - ClassDB::bind_method(D_METHOD("physical_bones_start_simulation", "bones"), &Skeleton::physical_bones_start_simulation_on, DEFVAL(Array())); - ClassDB::bind_method(D_METHOD("physical_bones_add_collision_exception", "exception"), &Skeleton::physical_bones_add_collision_exception); - ClassDB::bind_method(D_METHOD("physical_bones_remove_collision_exception", "exception"), &Skeleton::physical_bones_remove_collision_exception); + ClassDB::bind_method(D_METHOD("physical_bones_stop_simulation"), &Skeleton3D::physical_bones_stop_simulation); + ClassDB::bind_method(D_METHOD("physical_bones_start_simulation", "bones"), &Skeleton3D::physical_bones_start_simulation_on, DEFVAL(Array())); + ClassDB::bind_method(D_METHOD("physical_bones_add_collision_exception", "exception"), &Skeleton3D::physical_bones_add_collision_exception); + ClassDB::bind_method(D_METHOD("physical_bones_remove_collision_exception", "exception"), &Skeleton3D::physical_bones_remove_collision_exception); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "animate_physical_bones"), "set_animate_physical_bones", "get_animate_physical_bones"); #endif // _3D_DISABLED @@ -931,7 +937,7 @@ void Skeleton::_bind_methods() { BIND_CONSTANT(NOTIFICATION_UPDATE_SKELETON); } -Skeleton::Skeleton() { +Skeleton3D::Skeleton3D() { animate_physical_bones = true; dirty = false; @@ -939,7 +945,7 @@ Skeleton::Skeleton() { process_order_dirty = true; } -Skeleton::~Skeleton() { +Skeleton3D::~Skeleton3D() { //some skins may remain bound for (Set<SkinReference *>::Element *E = skin_bindings.front(); E; E = E->next()) { diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton_3d.h index 76fd96f30a..0bccd3f8fc 100644 --- a/scene/3d/skeleton.h +++ b/scene/3d/skeleton_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* skeleton.h */ +/* skeleton_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,26 +28,26 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef SKELETON_H -#define SKELETON_H +#ifndef SKELETON_3D_H +#define SKELETON_3D_H #include "core/rid.h" -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" #include "scene/resources/skin.h" #ifndef _3D_DISABLED typedef int BoneId; -class PhysicalBone; +class PhysicalBone3D; #endif // _3D_DISABLED -class Skeleton; +class Skeleton3D; class SkinReference : public Reference { GDCLASS(SkinReference, Reference) - friend class Skeleton; + friend class Skeleton3D; - Skeleton *skeleton_node; + Skeleton3D *skeleton_node; RID skeleton; Ref<Skin> skin; uint32_t bind_count = 0; @@ -65,9 +65,9 @@ public: ~SkinReference(); }; -class Skeleton : public Spatial { +class Skeleton3D : public Node3D { - GDCLASS(Skeleton, Spatial); + GDCLASS(Skeleton3D, Node3D); private: friend class SkinReference; @@ -98,8 +98,8 @@ private: Transform global_pose_override; #ifndef _3D_DISABLED - PhysicalBone *physical_bone; - PhysicalBone *cache_parent_physical_bone; + PhysicalBone3D *physical_bone; + PhysicalBone3D *cache_parent_physical_bone; #endif // _3D_DISABLED List<ObjectID> nodes_bound; @@ -112,8 +112,8 @@ private: global_pose_override_amount = 0; global_pose_override_reset = false; #ifndef _3D_DISABLED - physical_bone = NULL; - cache_parent_physical_bone = NULL; + physical_bone = nullptr; + cache_parent_physical_bone = nullptr; #endif // _3D_DISABLED } }; @@ -178,6 +178,7 @@ public: Transform get_bone_rest(int p_bone) const; Transform get_bone_global_pose(int p_bone) const; + void clear_bones_global_pose_override(); void set_bone_global_pose_override(int p_bone, const Transform &p_pose, float p_amount, bool p_persistent = false); void set_bone_enabled(int p_bone, bool p_enabled); @@ -208,27 +209,27 @@ public: void set_animate_physical_bones(bool p_animate); bool get_animate_physical_bones() const; - void bind_physical_bone_to_bone(int p_bone, PhysicalBone *p_physical_bone); + void bind_physical_bone_to_bone(int p_bone, PhysicalBone3D *p_physical_bone); void unbind_physical_bone_from_bone(int p_bone); - PhysicalBone *get_physical_bone(int p_bone); - PhysicalBone *get_physical_bone_parent(int p_bone); + PhysicalBone3D *get_physical_bone(int p_bone); + PhysicalBone3D *get_physical_bone_parent(int p_bone); private: /// This is a slow API os it's cached - PhysicalBone *_get_physical_bone_parent(int p_bone); + PhysicalBone3D *_get_physical_bone_parent(int p_bone); void _rebuild_physical_bones_cache(); public: void physical_bones_stop_simulation(); - void physical_bones_start_simulation_on(const Array &p_bones); + void physical_bones_start_simulation_on(const TypedArray<StringName> &p_bones); void physical_bones_add_collision_exception(RID p_exception); void physical_bones_remove_collision_exception(RID p_exception); #endif // _3D_DISABLED public: - Skeleton(); - ~Skeleton(); + Skeleton3D(); + ~Skeleton3D(); }; #endif diff --git a/scene/animation/skeleton_ik.cpp b/scene/3d/skeleton_ik_3d.cpp index 5cdb38b5c2..7366290ed3 100644 --- a/scene/animation/skeleton_ik.cpp +++ b/scene/3d/skeleton_ik_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* skeleton_ik.cpp */ +/* skeleton_ik_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -32,7 +32,7 @@ * @author AndreaCatania */ -#include "skeleton_ik.h" +#include "skeleton_ik_3d.h" #ifndef _3D_DISABLED @@ -42,7 +42,7 @@ FabrikInverseKinematic::ChainItem *FabrikInverseKinematic::ChainItem::find_child return &children.write[i]; } } - return NULL; + return nullptr; } FabrikInverseKinematic::ChainItem *FabrikInverseKinematic::ChainItem::add_child(const BoneId p_bone_id) { @@ -65,7 +65,7 @@ bool FabrikInverseKinematic::build_chain(Task *p_task, bool p_force_simple_chain chain.chain_root.initial_transform = p_task->skeleton->get_bone_global_pose(chain.chain_root.bone); chain.chain_root.current_pos = chain.chain_root.initial_transform.origin; chain.chain_root.pb = p_task->skeleton->get_physical_bone(chain.chain_root.bone); - chain.middle_chain_item = NULL; + chain.middle_chain_item = nullptr; // Holds all IDs that are composing a single chain in reverse order Vector<BoneId> chain_ids; @@ -119,7 +119,7 @@ bool FabrikInverseKinematic::build_chain(Task *p_task, bool p_force_simple_chain } if (!middle_chain_item_id) - chain.middle_chain_item = NULL; + chain.middle_chain_item = nullptr; // Initialize current tip chain.tips.write[x].chain_item = sub_chain; @@ -136,7 +136,7 @@ bool FabrikInverseKinematic::build_chain(Task *p_task, bool p_force_simple_chain return true; } -void FabrikInverseKinematic::update_chain(const Skeleton *p_sk, ChainItem *p_chain_item) { +void FabrikInverseKinematic::update_chain(const Skeleton3D *p_sk, ChainItem *p_chain_item) { if (!p_chain_item) return; @@ -144,8 +144,9 @@ void FabrikInverseKinematic::update_chain(const Skeleton *p_sk, ChainItem *p_cha p_chain_item->initial_transform = p_sk->get_bone_global_pose(p_chain_item->bone); p_chain_item->current_pos = p_chain_item->initial_transform.origin; - for (int i = p_chain_item->children.size() - 1; 0 <= i; --i) { - update_chain(p_sk, &p_chain_item->children.write[i]); + ChainItem *items = p_chain_item->children.ptrw(); + for (int i = 0; i < p_chain_item->children.size(); i += 1) { + update_chain(p_sk, items + i); } } @@ -225,19 +226,19 @@ void FabrikInverseKinematic::solve_simple_forwards(Chain &r_chain, bool p_solve_ if (p_solve_magnet && sub_chain_root == r_chain.middle_chain_item) { // In case of magnet solving this is the tip - sub_chain_root = NULL; + sub_chain_root = nullptr; } else { sub_chain_root = &child; } } else { // Is tip - sub_chain_root = NULL; + sub_chain_root = nullptr; } } } -FabrikInverseKinematic::Task *FabrikInverseKinematic::create_simple_task(Skeleton *p_sk, BoneId root_bone, BoneId tip_bone, const Transform &goal_transform) { +FabrikInverseKinematic::Task *FabrikInverseKinematic::create_simple_task(Skeleton3D *p_sk, BoneId root_bone, BoneId tip_bone, const Transform &goal_transform) { FabrikInverseKinematic::EndEffector ee; ee.tip_bone = tip_bone; @@ -250,7 +251,7 @@ FabrikInverseKinematic::Task *FabrikInverseKinematic::create_simple_task(Skeleto if (!build_chain(task)) { free_task(task); - return NULL; + return nullptr; } return task; @@ -286,6 +287,8 @@ void FabrikInverseKinematic::solve(Task *p_task, real_t blending_delta, bool ove return; // Skip solving } + p_task->skeleton->clear_bones_global_pose_override(); + make_goal(p_task, p_task->skeleton->get_global_transform().affine_inverse().scaled(p_task->skeleton->get_global_transform().get_basis().get_scale()), blending_delta); update_chain(p_task->skeleton, &p_task->chain.chain_root); @@ -325,11 +328,11 @@ void FabrikInverseKinematic::solve(Task *p_task, real_t blending_delta, bool ove if (!ci->children.empty()) ci = &ci->children.write[0]; else - ci = NULL; + ci = nullptr; } } -void SkeletonIK::_validate_property(PropertyInfo &property) const { +void SkeletonIK3D::_validate_property(PropertyInfo &property) const { if (property.name == "root_bone" || property.name == "tip_bone") { @@ -352,43 +355,43 @@ void SkeletonIK::_validate_property(PropertyInfo &property) const { } } -void SkeletonIK::_bind_methods() { +void SkeletonIK3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_root_bone", "root_bone"), &SkeletonIK::set_root_bone); - ClassDB::bind_method(D_METHOD("get_root_bone"), &SkeletonIK::get_root_bone); + ClassDB::bind_method(D_METHOD("set_root_bone", "root_bone"), &SkeletonIK3D::set_root_bone); + ClassDB::bind_method(D_METHOD("get_root_bone"), &SkeletonIK3D::get_root_bone); - ClassDB::bind_method(D_METHOD("set_tip_bone", "tip_bone"), &SkeletonIK::set_tip_bone); - ClassDB::bind_method(D_METHOD("get_tip_bone"), &SkeletonIK::get_tip_bone); + ClassDB::bind_method(D_METHOD("set_tip_bone", "tip_bone"), &SkeletonIK3D::set_tip_bone); + ClassDB::bind_method(D_METHOD("get_tip_bone"), &SkeletonIK3D::get_tip_bone); - ClassDB::bind_method(D_METHOD("set_interpolation", "interpolation"), &SkeletonIK::set_interpolation); - ClassDB::bind_method(D_METHOD("get_interpolation"), &SkeletonIK::get_interpolation); + ClassDB::bind_method(D_METHOD("set_interpolation", "interpolation"), &SkeletonIK3D::set_interpolation); + ClassDB::bind_method(D_METHOD("get_interpolation"), &SkeletonIK3D::get_interpolation); - ClassDB::bind_method(D_METHOD("set_target_transform", "target"), &SkeletonIK::set_target_transform); - ClassDB::bind_method(D_METHOD("get_target_transform"), &SkeletonIK::get_target_transform); + ClassDB::bind_method(D_METHOD("set_target_transform", "target"), &SkeletonIK3D::set_target_transform); + ClassDB::bind_method(D_METHOD("get_target_transform"), &SkeletonIK3D::get_target_transform); - ClassDB::bind_method(D_METHOD("set_target_node", "node"), &SkeletonIK::set_target_node); - ClassDB::bind_method(D_METHOD("get_target_node"), &SkeletonIK::get_target_node); + ClassDB::bind_method(D_METHOD("set_target_node", "node"), &SkeletonIK3D::set_target_node); + ClassDB::bind_method(D_METHOD("get_target_node"), &SkeletonIK3D::get_target_node); - ClassDB::bind_method(D_METHOD("set_override_tip_basis", "override"), &SkeletonIK::set_override_tip_basis); - ClassDB::bind_method(D_METHOD("is_override_tip_basis"), &SkeletonIK::is_override_tip_basis); + ClassDB::bind_method(D_METHOD("set_override_tip_basis", "override"), &SkeletonIK3D::set_override_tip_basis); + ClassDB::bind_method(D_METHOD("is_override_tip_basis"), &SkeletonIK3D::is_override_tip_basis); - ClassDB::bind_method(D_METHOD("set_use_magnet", "use"), &SkeletonIK::set_use_magnet); - ClassDB::bind_method(D_METHOD("is_using_magnet"), &SkeletonIK::is_using_magnet); + ClassDB::bind_method(D_METHOD("set_use_magnet", "use"), &SkeletonIK3D::set_use_magnet); + ClassDB::bind_method(D_METHOD("is_using_magnet"), &SkeletonIK3D::is_using_magnet); - ClassDB::bind_method(D_METHOD("set_magnet_position", "local_position"), &SkeletonIK::set_magnet_position); - ClassDB::bind_method(D_METHOD("get_magnet_position"), &SkeletonIK::get_magnet_position); + ClassDB::bind_method(D_METHOD("set_magnet_position", "local_position"), &SkeletonIK3D::set_magnet_position); + ClassDB::bind_method(D_METHOD("get_magnet_position"), &SkeletonIK3D::get_magnet_position); - ClassDB::bind_method(D_METHOD("get_parent_skeleton"), &SkeletonIK::get_parent_skeleton); - ClassDB::bind_method(D_METHOD("is_running"), &SkeletonIK::is_running); + ClassDB::bind_method(D_METHOD("get_parent_skeleton"), &SkeletonIK3D::get_parent_skeleton); + ClassDB::bind_method(D_METHOD("is_running"), &SkeletonIK3D::is_running); - ClassDB::bind_method(D_METHOD("set_min_distance", "min_distance"), &SkeletonIK::set_min_distance); - ClassDB::bind_method(D_METHOD("get_min_distance"), &SkeletonIK::get_min_distance); + ClassDB::bind_method(D_METHOD("set_min_distance", "min_distance"), &SkeletonIK3D::set_min_distance); + ClassDB::bind_method(D_METHOD("get_min_distance"), &SkeletonIK3D::get_min_distance); - ClassDB::bind_method(D_METHOD("set_max_iterations", "iterations"), &SkeletonIK::set_max_iterations); - ClassDB::bind_method(D_METHOD("get_max_iterations"), &SkeletonIK::get_max_iterations); + ClassDB::bind_method(D_METHOD("set_max_iterations", "iterations"), &SkeletonIK3D::set_max_iterations); + ClassDB::bind_method(D_METHOD("get_max_iterations"), &SkeletonIK3D::get_max_iterations); - ClassDB::bind_method(D_METHOD("start", "one_time"), &SkeletonIK::start, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("stop"), &SkeletonIK::stop); + ClassDB::bind_method(D_METHOD("start", "one_time"), &SkeletonIK3D::start, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("stop"), &SkeletonIK3D::stop); ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "root_bone"), "set_root_bone", "get_root_bone"); ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "tip_bone"), "set_tip_bone", "get_tip_bone"); @@ -402,10 +405,10 @@ void SkeletonIK::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "max_iterations"), "set_max_iterations", "get_max_iterations"); } -void SkeletonIK::_notification(int p_what) { +void SkeletonIK3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - skeleton = Object::cast_to<Skeleton>(get_parent()); + skeleton = Object::cast_to<Skeleton3D>(get_parent()); set_process_priority(1); reload_chain(); } break; @@ -423,104 +426,104 @@ void SkeletonIK::_notification(int p_what) { } } -SkeletonIK::SkeletonIK() : +SkeletonIK3D::SkeletonIK3D() : interpolation(1), override_tip_basis(true), use_magnet(false), min_distance(0.01), max_iterations(10), - skeleton(NULL), - target_node_override(NULL), - task(NULL) { + skeleton(nullptr), + target_node_override(nullptr), + task(nullptr) { } -SkeletonIK::~SkeletonIK() { +SkeletonIK3D::~SkeletonIK3D() { FabrikInverseKinematic::free_task(task); - task = NULL; + task = nullptr; } -void SkeletonIK::set_root_bone(const StringName &p_root_bone) { +void SkeletonIK3D::set_root_bone(const StringName &p_root_bone) { root_bone = p_root_bone; reload_chain(); } -StringName SkeletonIK::get_root_bone() const { +StringName SkeletonIK3D::get_root_bone() const { return root_bone; } -void SkeletonIK::set_tip_bone(const StringName &p_tip_bone) { +void SkeletonIK3D::set_tip_bone(const StringName &p_tip_bone) { tip_bone = p_tip_bone; reload_chain(); } -StringName SkeletonIK::get_tip_bone() const { +StringName SkeletonIK3D::get_tip_bone() const { return tip_bone; } -void SkeletonIK::set_interpolation(real_t p_interpolation) { +void SkeletonIK3D::set_interpolation(real_t p_interpolation) { interpolation = p_interpolation; } -real_t SkeletonIK::get_interpolation() const { +real_t SkeletonIK3D::get_interpolation() const { return interpolation; } -void SkeletonIK::set_target_transform(const Transform &p_target) { +void SkeletonIK3D::set_target_transform(const Transform &p_target) { target = p_target; reload_goal(); } -const Transform &SkeletonIK::get_target_transform() const { +const Transform &SkeletonIK3D::get_target_transform() const { return target; } -void SkeletonIK::set_target_node(const NodePath &p_node) { +void SkeletonIK3D::set_target_node(const NodePath &p_node) { target_node_path_override = p_node; - target_node_override = NULL; + target_node_override = nullptr; reload_goal(); } -NodePath SkeletonIK::get_target_node() { +NodePath SkeletonIK3D::get_target_node() { return target_node_path_override; } -void SkeletonIK::set_override_tip_basis(bool p_override) { +void SkeletonIK3D::set_override_tip_basis(bool p_override) { override_tip_basis = p_override; } -bool SkeletonIK::is_override_tip_basis() const { +bool SkeletonIK3D::is_override_tip_basis() const { return override_tip_basis; } -void SkeletonIK::set_use_magnet(bool p_use) { +void SkeletonIK3D::set_use_magnet(bool p_use) { use_magnet = p_use; } -bool SkeletonIK::is_using_magnet() const { +bool SkeletonIK3D::is_using_magnet() const { return use_magnet; } -void SkeletonIK::set_magnet_position(const Vector3 &p_local_position) { +void SkeletonIK3D::set_magnet_position(const Vector3 &p_local_position) { magnet_position = p_local_position; } -const Vector3 &SkeletonIK::get_magnet_position() const { +const Vector3 &SkeletonIK3D::get_magnet_position() const { return magnet_position; } -void SkeletonIK::set_min_distance(real_t p_min_distance) { +void SkeletonIK3D::set_min_distance(real_t p_min_distance) { min_distance = p_min_distance; } -void SkeletonIK::set_max_iterations(int p_iterations) { +void SkeletonIK3D::set_max_iterations(int p_iterations) { max_iterations = p_iterations; } -bool SkeletonIK::is_running() { +bool SkeletonIK3D::is_running() { return is_processing_internal(); } -void SkeletonIK::start(bool p_one_time) { +void SkeletonIK3D::start(bool p_one_time) { if (p_one_time) { set_process_internal(false); _solve_chain(); @@ -529,14 +532,14 @@ void SkeletonIK::start(bool p_one_time) { } } -void SkeletonIK::stop() { +void SkeletonIK3D::stop() { set_process_internal(false); } -Transform SkeletonIK::_get_target_transform() { +Transform SkeletonIK3D::_get_target_transform() { if (!target_node_override && !target_node_path_override.is_empty()) - target_node_override = Object::cast_to<Spatial>(get_node(target_node_path_override)); + target_node_override = Object::cast_to<Node3D>(get_node(target_node_path_override)); if (target_node_override) return target_node_override->get_global_transform(); @@ -544,10 +547,10 @@ Transform SkeletonIK::_get_target_transform() { return target; } -void SkeletonIK::reload_chain() { +void SkeletonIK3D::reload_chain() { FabrikInverseKinematic::free_task(task); - task = NULL; + task = nullptr; if (!skeleton) return; @@ -559,14 +562,14 @@ void SkeletonIK::reload_chain() { } } -void SkeletonIK::reload_goal() { +void SkeletonIK3D::reload_goal() { if (!task) return; FabrikInverseKinematic::set_goal(task, _get_target_transform()); } -void SkeletonIK::_solve_chain() { +void SkeletonIK3D::_solve_chain() { if (!task) return; FabrikInverseKinematic::solve(task, interpolation, override_tip_basis, use_magnet, magnet_position); diff --git a/scene/animation/skeleton_ik.h b/scene/3d/skeleton_ik_3d.h index 02d5aba5ba..5fbbe6e9e7 100644 --- a/scene/animation/skeleton_ik.h +++ b/scene/3d/skeleton_ik_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* skeleton_ik.h */ +/* skeleton_ik_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -38,7 +38,7 @@ */ #include "core/math/transform.h" -#include "scene/3d/skeleton.h" +#include "scene/3d/skeleton_3d.h" class FabrikInverseKinematic { @@ -54,7 +54,7 @@ class FabrikInverseKinematic { // Bone info BoneId bone; - PhysicalBone *pb; + PhysicalBone3D *pb; real_t length; /// Positions relative to root bone @@ -64,9 +64,9 @@ class FabrikInverseKinematic { Vector3 current_ori; ChainItem() : - parent_item(NULL), + parent_item(nullptr), bone(-1), - pb(NULL), + pb(nullptr), length(0) {} ChainItem *find_child(const BoneId p_bone_id); @@ -78,8 +78,8 @@ class FabrikInverseKinematic { const EndEffector *end_effector; ChainTip() : - chain_item(NULL), - end_effector(NULL) {} + chain_item(nullptr), + end_effector(nullptr) {} ChainTip(ChainItem *p_chain_item, const EndEffector *p_end_effector) : chain_item(p_chain_item), @@ -100,7 +100,7 @@ class FabrikInverseKinematic { public: struct Task { RID self; - Skeleton *skeleton; + Skeleton3D *skeleton; Chain chain; @@ -115,7 +115,7 @@ public: Transform goal_global_transform; Task() : - skeleton(NULL), + skeleton(nullptr), min_distance(0.01), max_iterations(10), root_bone(-1) {} @@ -125,7 +125,7 @@ private: /// Init a chain that starts from the root to tip static bool build_chain(Task *p_task, bool p_force_simple_chain = true); - static void update_chain(const Skeleton *p_sk, ChainItem *p_chain_item); + static void update_chain(const Skeleton3D *p_sk, ChainItem *p_chain_item); static void solve_simple(Task *p_task, bool p_solve_magnet); /// Special solvers that solve only chains with one end effector @@ -133,7 +133,7 @@ private: static void solve_simple_forwards(Chain &r_chain, bool p_solve_magnet); public: - static Task *create_simple_task(Skeleton *p_sk, BoneId root_bone, BoneId tip_bone, const Transform &goal_transform); + static Task *create_simple_task(Skeleton3D *p_sk, BoneId root_bone, BoneId tip_bone, const Transform &goal_transform); static void free_task(Task *p_task); // The goal of chain should be always in local space static void set_goal(Task *p_task, const Transform &p_goal); @@ -141,8 +141,8 @@ public: static void solve(Task *p_task, real_t blending_delta, bool override_tip_basis, bool p_use_magnet, const Vector3 &p_magnet_position); }; -class SkeletonIK : public Node { - GDCLASS(SkeletonIK, Node); +class SkeletonIK3D : public Node { + GDCLASS(SkeletonIK3D, Node); StringName root_bone; StringName tip_bone; @@ -156,8 +156,8 @@ class SkeletonIK : public Node { real_t min_distance; int max_iterations; - Skeleton *skeleton; - Spatial *target_node_override; + Skeleton3D *skeleton; + Node3D *target_node_override; FabrikInverseKinematic::Task *task; protected: @@ -168,8 +168,8 @@ protected: virtual void _notification(int p_what); public: - SkeletonIK(); - virtual ~SkeletonIK(); + SkeletonIK3D(); + virtual ~SkeletonIK3D(); void set_root_bone(const StringName &p_root_bone); StringName get_root_bone() const; @@ -201,7 +201,7 @@ public: void set_max_iterations(int p_iterations); int get_max_iterations() const { return max_iterations; } - Skeleton *get_parent_skeleton() const { return skeleton; } + Skeleton3D *get_parent_skeleton() const { return skeleton; } bool is_running(); diff --git a/scene/3d/soft_body.cpp b/scene/3d/soft_body_3d.cpp index 65f868aed4..6092818252 100644 --- a/scene/3d/soft_body.cpp +++ b/scene/3d/soft_body_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* soft_body.cpp */ +/* soft_body_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,19 +28,20 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "soft_body.h" +#include "soft_body_3d.h" + #include "core/list.h" #include "core/object.h" #include "core/os/os.h" #include "core/rid.h" -#include "scene/3d/collision_object.h" -#include "scene/3d/physics_body.h" -#include "scene/3d/skeleton.h" -#include "servers/physics_server.h" +#include "scene/3d/collision_object_3d.h" +#include "scene/3d/physics_body_3d.h" +#include "scene/3d/skeleton_3d.h" +#include "servers/physics_server_3d.h" -SoftBodyVisualServerHandler::SoftBodyVisualServerHandler() {} +SoftBodyRenderingServerHandler::SoftBodyRenderingServerHandler() {} -void SoftBodyVisualServerHandler::prepare(RID p_mesh, int p_surface) { +void SoftBodyRenderingServerHandler::prepare(RID p_mesh, int p_surface) { clear(); ERR_FAIL_COND(!p_mesh.is_valid()); @@ -51,19 +52,19 @@ void SoftBodyVisualServerHandler::prepare(RID p_mesh, int p_surface) { #warning Softbody is not working, needs to be redone considering that these functions no longer exist #endif #if 0 - const uint32_t surface_format = VS::get_singleton()->mesh_surface_get_format(mesh, surface); - const int surface_vertex_len = VS::get_singleton()->mesh_surface_get_array_len(mesh, p_surface); - const int surface_index_len = VS::get_singleton()->mesh_surface_get_array_index_len(mesh, p_surface); - uint32_t surface_offsets[VS::ARRAY_MAX]; - - buffer = VS::get_singleton()->mesh_surface_get_array(mesh, surface); - stride = VS::get_singleton()->mesh_surface_make_offsets_from_format(surface_format, surface_vertex_len, surface_index_len, surface_offsets); - offset_vertices = surface_offsets[VS::ARRAY_VERTEX]; - offset_normal = surface_offsets[VS::ARRAY_NORMAL]; + const uint32_t surface_format = RS::get_singleton()->mesh_surface_get_format(mesh, surface); + const int surface_vertex_len = RS::get_singleton()->mesh_surface_get_array_len(mesh, p_surface); + const int surface_index_len = RS::get_singleton()->mesh_surface_get_array_index_len(mesh, p_surface); + uint32_t surface_offsets[RS::ARRAY_MAX]; + + buffer = RS::get_singleton()->mesh_surface_get_array(mesh, surface); + stride = RS::get_singleton()->mesh_surface_make_offsets_from_format(surface_format, surface_vertex_len, surface_index_len, surface_offsets); + offset_vertices = surface_offsets[RS::ARRAY_VERTEX]; + offset_normal = surface_offsets[RS::ARRAY_NORMAL]; #endif } -void SoftBodyVisualServerHandler::clear() { +void SoftBodyRenderingServerHandler::clear() { if (mesh.is_valid()) { buffer.resize(0); @@ -72,43 +73,43 @@ void SoftBodyVisualServerHandler::clear() { mesh = RID(); } -void SoftBodyVisualServerHandler::open() { +void SoftBodyRenderingServerHandler::open() { write_buffer = buffer.ptrw(); } -void SoftBodyVisualServerHandler::close() { +void SoftBodyRenderingServerHandler::close() { //write_buffer.release(); } -void SoftBodyVisualServerHandler::commit_changes() { - VS::get_singleton()->mesh_surface_update_region(mesh, surface, 0, buffer); +void SoftBodyRenderingServerHandler::commit_changes() { + RS::get_singleton()->mesh_surface_update_region(mesh, surface, 0, buffer); } -void SoftBodyVisualServerHandler::set_vertex(int p_vertex_id, const void *p_vector3) { +void SoftBodyRenderingServerHandler::set_vertex(int p_vertex_id, const void *p_vector3) { copymem(&write_buffer[p_vertex_id * stride + offset_vertices], p_vector3, sizeof(float) * 3); } -void SoftBodyVisualServerHandler::set_normal(int p_vertex_id, const void *p_vector3) { +void SoftBodyRenderingServerHandler::set_normal(int p_vertex_id, const void *p_vector3) { copymem(&write_buffer[p_vertex_id * stride + offset_normal], p_vector3, sizeof(float) * 3); } -void SoftBodyVisualServerHandler::set_aabb(const AABB &p_aabb) { - VS::get_singleton()->mesh_set_custom_aabb(mesh, p_aabb); +void SoftBodyRenderingServerHandler::set_aabb(const AABB &p_aabb) { + RS::get_singleton()->mesh_set_custom_aabb(mesh, p_aabb); } -SoftBody::PinnedPoint::PinnedPoint() : +SoftBody3D::PinnedPoint::PinnedPoint() : point_index(-1), - spatial_attachment(NULL) { + spatial_attachment(nullptr) { } -SoftBody::PinnedPoint::PinnedPoint(const PinnedPoint &obj_tocopy) { +SoftBody3D::PinnedPoint::PinnedPoint(const PinnedPoint &obj_tocopy) { point_index = obj_tocopy.point_index; spatial_attachment_path = obj_tocopy.spatial_attachment_path; spatial_attachment = obj_tocopy.spatial_attachment; offset = obj_tocopy.offset; } -SoftBody::PinnedPoint SoftBody::PinnedPoint::operator=(const PinnedPoint &obj) { +SoftBody3D::PinnedPoint SoftBody3D::PinnedPoint::operator=(const PinnedPoint &obj) { point_index = obj.point_index; spatial_attachment_path = obj.spatial_attachment_path; spatial_attachment = obj.spatial_attachment; @@ -116,14 +117,14 @@ SoftBody::PinnedPoint SoftBody::PinnedPoint::operator=(const PinnedPoint &obj) { return *this; } -void SoftBody::_update_pickable() { +void SoftBody3D::_update_pickable() { if (!is_inside_tree()) return; bool pickable = ray_pickable && is_visible_in_tree(); - PhysicsServer::get_singleton()->soft_body_set_ray_pickable(physics_rid, pickable); + PhysicsServer3D::get_singleton()->soft_body_set_ray_pickable(physics_rid, pickable); } -bool SoftBody::_set(const StringName &p_name, const Variant &p_value) { +bool SoftBody3D::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; String which = name.get_slicec('/', 0); @@ -142,7 +143,7 @@ bool SoftBody::_set(const StringName &p_name, const Variant &p_value) { return false; } -bool SoftBody::_get(const StringName &p_name, Variant &r_ret) const { +bool SoftBody3D::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; String which = name.get_slicec('/', 0); @@ -170,7 +171,7 @@ bool SoftBody::_get(const StringName &p_name, Variant &r_ret) const { return false; } -void SoftBody::_get_property_list(List<PropertyInfo> *p_list) const { +void SoftBody3D::_get_property_list(List<PropertyInfo> *p_list) const { const int pinned_points_indices_size = pinned_points.size(); @@ -183,7 +184,7 @@ void SoftBody::_get_property_list(List<PropertyInfo> *p_list) const { } } -bool SoftBody::_set_property_pinned_points_indices(const Array &p_indices) { +bool SoftBody3D::_set_property_pinned_points_indices(const Array &p_indices) { const int p_indices_size = p_indices.size(); @@ -212,7 +213,7 @@ bool SoftBody::_set_property_pinned_points_indices(const Array &p_indices) { return true; } -bool SoftBody::_set_property_pinned_points_attachment(int p_item, const String &p_what, const Variant &p_value) { +bool SoftBody3D::_set_property_pinned_points_attachment(int p_item, const String &p_what, const Variant &p_value) { if (pinned_points.size() <= p_item) { return false; } @@ -231,7 +232,7 @@ bool SoftBody::_set_property_pinned_points_attachment(int p_item, const String & return true; } -bool SoftBody::_get_property_pinned_points(int p_item, const String &p_what, Variant &r_ret) const { +bool SoftBody3D::_get_property_pinned_points(int p_item, const String &p_what, Variant &r_ret) const { if (pinned_points.size() <= p_item) { return false; } @@ -250,7 +251,7 @@ bool SoftBody::_get_property_pinned_points(int p_item, const String &p_what, Var return true; } -void SoftBody::_changed_callback(Object *p_changed, const char *p_prop) { +void SoftBody3D::_changed_callback(Object *p_changed, const char *p_prop) { prepare_physics_server(); _reset_points_offsets(); #ifdef TOOLS_ENABLED @@ -260,7 +261,7 @@ void SoftBody::_changed_callback(Object *p_changed, const char *p_prop) { #endif } -void SoftBody::_notification(int p_what) { +void SoftBody3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_WORLD: { @@ -270,7 +271,7 @@ void SoftBody::_notification(int p_what) { } RID space = get_world()->get_space(); - PhysicsServer::get_singleton()->soft_body_set_space(physics_rid, space); + PhysicsServer3D::get_singleton()->soft_body_set_space(physics_rid, space); prepare_physics_server(); } break; case NOTIFICATION_READY: { @@ -285,10 +286,10 @@ void SoftBody::_notification(int p_what) { return; } - PhysicsServer::get_singleton()->soft_body_set_transform(physics_rid, get_global_transform()); + PhysicsServer3D::get_singleton()->soft_body_set_transform(physics_rid, get_global_transform()); set_notify_transform(false); - // Required to be top level with Transform at center of world in order to modify VisualServer only to support custom Transform + // Required to be top level with Transform at center of world in order to modify RenderingServer only to support custom Transform set_as_toplevel(true); set_transform(Transform()); set_notify_transform(true); @@ -301,7 +302,7 @@ void SoftBody::_notification(int p_what) { } break; case NOTIFICATION_EXIT_WORLD: { - PhysicsServer::get_singleton()->soft_body_set_space(physics_rid, RID()); + PhysicsServer3D::get_singleton()->soft_body_set_space(physics_rid, RID()); } break; } @@ -317,56 +318,56 @@ void SoftBody::_notification(int p_what) { #endif } -void SoftBody::_bind_methods() { +void SoftBody3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &SoftBody::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &SoftBody::get_collision_mask); + ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &SoftBody3D::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &SoftBody3D::get_collision_mask); - ClassDB::bind_method(D_METHOD("set_collision_layer", "collision_layer"), &SoftBody::set_collision_layer); - ClassDB::bind_method(D_METHOD("get_collision_layer"), &SoftBody::get_collision_layer); + ClassDB::bind_method(D_METHOD("set_collision_layer", "collision_layer"), &SoftBody3D::set_collision_layer); + ClassDB::bind_method(D_METHOD("get_collision_layer"), &SoftBody3D::get_collision_layer); - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &SoftBody::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &SoftBody::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &SoftBody3D::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &SoftBody3D::get_collision_mask_bit); - ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &SoftBody::set_collision_layer_bit); - ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &SoftBody::get_collision_layer_bit); + ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &SoftBody3D::set_collision_layer_bit); + ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &SoftBody3D::get_collision_layer_bit); - ClassDB::bind_method(D_METHOD("set_parent_collision_ignore", "parent_collision_ignore"), &SoftBody::set_parent_collision_ignore); - ClassDB::bind_method(D_METHOD("get_parent_collision_ignore"), &SoftBody::get_parent_collision_ignore); + ClassDB::bind_method(D_METHOD("set_parent_collision_ignore", "parent_collision_ignore"), &SoftBody3D::set_parent_collision_ignore); + ClassDB::bind_method(D_METHOD("get_parent_collision_ignore"), &SoftBody3D::get_parent_collision_ignore); - ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &SoftBody::get_collision_exceptions); - ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &SoftBody::add_collision_exception_with); - ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &SoftBody::remove_collision_exception_with); + ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &SoftBody3D::get_collision_exceptions); + ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &SoftBody3D::add_collision_exception_with); + ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &SoftBody3D::remove_collision_exception_with); - ClassDB::bind_method(D_METHOD("set_simulation_precision", "simulation_precision"), &SoftBody::set_simulation_precision); - ClassDB::bind_method(D_METHOD("get_simulation_precision"), &SoftBody::get_simulation_precision); + ClassDB::bind_method(D_METHOD("set_simulation_precision", "simulation_precision"), &SoftBody3D::set_simulation_precision); + ClassDB::bind_method(D_METHOD("get_simulation_precision"), &SoftBody3D::get_simulation_precision); - ClassDB::bind_method(D_METHOD("set_total_mass", "mass"), &SoftBody::set_total_mass); - ClassDB::bind_method(D_METHOD("get_total_mass"), &SoftBody::get_total_mass); + ClassDB::bind_method(D_METHOD("set_total_mass", "mass"), &SoftBody3D::set_total_mass); + ClassDB::bind_method(D_METHOD("get_total_mass"), &SoftBody3D::get_total_mass); - ClassDB::bind_method(D_METHOD("set_linear_stiffness", "linear_stiffness"), &SoftBody::set_linear_stiffness); - ClassDB::bind_method(D_METHOD("get_linear_stiffness"), &SoftBody::get_linear_stiffness); + ClassDB::bind_method(D_METHOD("set_linear_stiffness", "linear_stiffness"), &SoftBody3D::set_linear_stiffness); + ClassDB::bind_method(D_METHOD("get_linear_stiffness"), &SoftBody3D::get_linear_stiffness); - ClassDB::bind_method(D_METHOD("set_areaAngular_stiffness", "areaAngular_stiffness"), &SoftBody::set_areaAngular_stiffness); - ClassDB::bind_method(D_METHOD("get_areaAngular_stiffness"), &SoftBody::get_areaAngular_stiffness); + ClassDB::bind_method(D_METHOD("set_areaAngular_stiffness", "areaAngular_stiffness"), &SoftBody3D::set_areaAngular_stiffness); + ClassDB::bind_method(D_METHOD("get_areaAngular_stiffness"), &SoftBody3D::get_areaAngular_stiffness); - ClassDB::bind_method(D_METHOD("set_volume_stiffness", "volume_stiffness"), &SoftBody::set_volume_stiffness); - ClassDB::bind_method(D_METHOD("get_volume_stiffness"), &SoftBody::get_volume_stiffness); + ClassDB::bind_method(D_METHOD("set_volume_stiffness", "volume_stiffness"), &SoftBody3D::set_volume_stiffness); + ClassDB::bind_method(D_METHOD("get_volume_stiffness"), &SoftBody3D::get_volume_stiffness); - ClassDB::bind_method(D_METHOD("set_pressure_coefficient", "pressure_coefficient"), &SoftBody::set_pressure_coefficient); - ClassDB::bind_method(D_METHOD("get_pressure_coefficient"), &SoftBody::get_pressure_coefficient); + ClassDB::bind_method(D_METHOD("set_pressure_coefficient", "pressure_coefficient"), &SoftBody3D::set_pressure_coefficient); + ClassDB::bind_method(D_METHOD("get_pressure_coefficient"), &SoftBody3D::get_pressure_coefficient); - ClassDB::bind_method(D_METHOD("set_pose_matching_coefficient", "pose_matching_coefficient"), &SoftBody::set_pose_matching_coefficient); - ClassDB::bind_method(D_METHOD("get_pose_matching_coefficient"), &SoftBody::get_pose_matching_coefficient); + ClassDB::bind_method(D_METHOD("set_pose_matching_coefficient", "pose_matching_coefficient"), &SoftBody3D::set_pose_matching_coefficient); + ClassDB::bind_method(D_METHOD("get_pose_matching_coefficient"), &SoftBody3D::get_pose_matching_coefficient); - ClassDB::bind_method(D_METHOD("set_damping_coefficient", "damping_coefficient"), &SoftBody::set_damping_coefficient); - ClassDB::bind_method(D_METHOD("get_damping_coefficient"), &SoftBody::get_damping_coefficient); + ClassDB::bind_method(D_METHOD("set_damping_coefficient", "damping_coefficient"), &SoftBody3D::set_damping_coefficient); + ClassDB::bind_method(D_METHOD("get_damping_coefficient"), &SoftBody3D::get_damping_coefficient); - ClassDB::bind_method(D_METHOD("set_drag_coefficient", "drag_coefficient"), &SoftBody::set_drag_coefficient); - ClassDB::bind_method(D_METHOD("get_drag_coefficient"), &SoftBody::get_drag_coefficient); + ClassDB::bind_method(D_METHOD("set_drag_coefficient", "drag_coefficient"), &SoftBody3D::set_drag_coefficient); + ClassDB::bind_method(D_METHOD("get_drag_coefficient"), &SoftBody3D::get_drag_coefficient); - ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &SoftBody::set_ray_pickable); - ClassDB::bind_method(D_METHOD("is_ray_pickable"), &SoftBody::is_ray_pickable); + ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &SoftBody3D::set_ray_pickable); + ClassDB::bind_method(D_METHOD("is_ray_pickable"), &SoftBody3D::is_ray_pickable); ADD_GROUP("Collision", "collision_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer"); @@ -386,9 +387,9 @@ void SoftBody::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ray_pickable"), "set_ray_pickable", "is_ray_pickable"); } -String SoftBody::get_configuration_warning() const { +String SoftBody3D::get_configuration_warning() const { - String warning = MeshInstance::get_configuration_warning(); + String warning = MeshInstance3D::get_configuration_warning(); if (get_mesh().is_null()) { if (!warning.empty()) @@ -402,13 +403,13 @@ String SoftBody::get_configuration_warning() const { if (!warning.empty()) warning += "\n\n"; - warning += TTR("Size changes to SoftBody will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."); + warning += TTR("Size changes to SoftBody3D will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."); } return warning; } -void SoftBody::_update_physics_server() { +void SoftBody3D::_update_physics_server() { if (!simulation_started) return; @@ -418,18 +419,18 @@ void SoftBody::_update_physics_server() { const PinnedPoint *r = pinned_points.ptr(); for (int i = 0; i < pinned_points_indices_size; ++i) { if (r[i].spatial_attachment) { - PhysicsServer::get_singleton()->soft_body_move_point(physics_rid, r[i].point_index, r[i].spatial_attachment->get_global_transform().xform(r[i].offset)); + PhysicsServer3D::get_singleton()->soft_body_move_point(physics_rid, r[i].point_index, r[i].spatial_attachment->get_global_transform().xform(r[i].offset)); } } } -void SoftBody::_draw_soft_mesh() { +void SoftBody3D::_draw_soft_mesh() { if (get_mesh().is_null()) return; - if (!visual_server_handler.is_ready()) { + if (!rendering_server_handler.is_ready()) { - visual_server_handler.prepare(get_mesh()->get_rid(), 0); + rendering_server_handler.prepare(get_mesh()->get_rid(), 0); /// Necessary in order to render the mesh correctly (Soft body nodes are in global space) simulation_started = true; @@ -439,21 +440,21 @@ void SoftBody::_draw_soft_mesh() { _update_physics_server(); - visual_server_handler.open(); - PhysicsServer::get_singleton()->soft_body_update_visual_server(physics_rid, &visual_server_handler); - visual_server_handler.close(); + rendering_server_handler.open(); + PhysicsServer3D::get_singleton()->soft_body_update_rendering_server(physics_rid, &rendering_server_handler); + rendering_server_handler.close(); - visual_server_handler.commit_changes(); + rendering_server_handler.commit_changes(); } -void SoftBody::prepare_physics_server() { +void SoftBody3D::prepare_physics_server() { if (Engine::get_singleton()->is_editor_hint()) { if (get_mesh().is_valid()) - PhysicsServer::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); + PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); else - PhysicsServer::get_singleton()->soft_body_set_mesh(physics_rid, NULL); + PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, nullptr); return; } @@ -461,18 +462,18 @@ void SoftBody::prepare_physics_server() { if (get_mesh().is_valid()) { become_mesh_owner(); - PhysicsServer::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); - VS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &SoftBody::_draw_soft_mesh)); + PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); + RS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &SoftBody3D::_draw_soft_mesh)); } else { - PhysicsServer::get_singleton()->soft_body_set_mesh(physics_rid, NULL); - if (VS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &SoftBody::_draw_soft_mesh))) { - VS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &SoftBody::_draw_soft_mesh)); + PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, nullptr); + if (RS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &SoftBody3D::_draw_soft_mesh))) { + RS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &SoftBody3D::_draw_soft_mesh)); } } } -void SoftBody::become_mesh_owner() { +void SoftBody3D::become_mesh_owner() { if (mesh.is_null()) return; @@ -506,24 +507,24 @@ void SoftBody::become_mesh_owner() { } } -void SoftBody::set_collision_mask(uint32_t p_mask) { +void SoftBody3D::set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; - PhysicsServer::get_singleton()->soft_body_set_collision_mask(physics_rid, p_mask); + PhysicsServer3D::get_singleton()->soft_body_set_collision_mask(physics_rid, p_mask); } -uint32_t SoftBody::get_collision_mask() const { +uint32_t SoftBody3D::get_collision_mask() const { return collision_mask; } -void SoftBody::set_collision_layer(uint32_t p_layer) { +void SoftBody3D::set_collision_layer(uint32_t p_layer) { collision_layer = p_layer; - PhysicsServer::get_singleton()->soft_body_set_collision_layer(physics_rid, p_layer); + PhysicsServer3D::get_singleton()->soft_body_set_collision_layer(physics_rid, p_layer); } -uint32_t SoftBody::get_collision_layer() const { +uint32_t SoftBody3D::get_collision_layer() const { return collision_layer; } -void SoftBody::set_collision_mask_bit(int p_bit, bool p_value) { +void SoftBody3D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); if (p_value) mask |= 1 << p_bit; @@ -532,11 +533,11 @@ void SoftBody::set_collision_mask_bit(int p_bit, bool p_value) { set_collision_mask(mask); } -bool SoftBody::get_collision_mask_bit(int p_bit) const { +bool SoftBody3D::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } -void SoftBody::set_collision_layer_bit(int p_bit, bool p_value) { +void SoftBody3D::set_collision_layer_bit(int p_bit, bool p_value) { uint32_t layer = get_collision_layer(); if (p_value) layer |= 1 << p_bit; @@ -545,138 +546,138 @@ void SoftBody::set_collision_layer_bit(int p_bit, bool p_value) { set_collision_layer(layer); } -bool SoftBody::get_collision_layer_bit(int p_bit) const { +bool SoftBody3D::get_collision_layer_bit(int p_bit) const { return get_collision_layer() & (1 << p_bit); } -void SoftBody::set_parent_collision_ignore(const NodePath &p_parent_collision_ignore) { +void SoftBody3D::set_parent_collision_ignore(const NodePath &p_parent_collision_ignore) { parent_collision_ignore = p_parent_collision_ignore; } -const NodePath &SoftBody::get_parent_collision_ignore() const { +const NodePath &SoftBody3D::get_parent_collision_ignore() const { return parent_collision_ignore; } -void SoftBody::set_pinned_points_indices(Vector<SoftBody::PinnedPoint> p_pinned_points_indices) { +void SoftBody3D::set_pinned_points_indices(Vector<SoftBody3D::PinnedPoint> p_pinned_points_indices) { pinned_points = p_pinned_points_indices; for (int i = pinned_points.size() - 1; 0 <= i; --i) { pin_point(p_pinned_points_indices[i].point_index, true); } } -Vector<SoftBody::PinnedPoint> SoftBody::get_pinned_points_indices() { +Vector<SoftBody3D::PinnedPoint> SoftBody3D::get_pinned_points_indices() { return pinned_points; } -Array SoftBody::get_collision_exceptions() { +Array SoftBody3D::get_collision_exceptions() { List<RID> exceptions; - PhysicsServer::get_singleton()->soft_body_get_collision_exceptions(physics_rid, &exceptions); + PhysicsServer3D::get_singleton()->soft_body_get_collision_exceptions(physics_rid, &exceptions); Array ret; for (List<RID>::Element *E = exceptions.front(); E; E = E->next()) { RID body = E->get(); - ObjectID instance_id = PhysicsServer::get_singleton()->body_get_object_instance_id(body); + ObjectID instance_id = PhysicsServer3D::get_singleton()->body_get_object_instance_id(body); Object *obj = ObjectDB::get_instance(instance_id); - PhysicsBody *physics_body = Object::cast_to<PhysicsBody>(obj); + PhysicsBody3D *physics_body = Object::cast_to<PhysicsBody3D>(obj); ret.append(physics_body); } return ret; } -void SoftBody::add_collision_exception_with(Node *p_node) { +void SoftBody3D::add_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); - CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject."); - PhysicsServer::get_singleton()->soft_body_add_collision_exception(physics_rid, collision_object->get_rid()); + CollisionObject3D *collision_object = Object::cast_to<CollisionObject3D>(p_node); + ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject3Ds."); + PhysicsServer3D::get_singleton()->soft_body_add_collision_exception(physics_rid, collision_object->get_rid()); } -void SoftBody::remove_collision_exception_with(Node *p_node) { +void SoftBody3D::remove_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); - CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject."); - PhysicsServer::get_singleton()->soft_body_remove_collision_exception(physics_rid, collision_object->get_rid()); + CollisionObject3D *collision_object = Object::cast_to<CollisionObject3D>(p_node); + ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject3Ds."); + PhysicsServer3D::get_singleton()->soft_body_remove_collision_exception(physics_rid, collision_object->get_rid()); } -int SoftBody::get_simulation_precision() { - return PhysicsServer::get_singleton()->soft_body_get_simulation_precision(physics_rid); +int SoftBody3D::get_simulation_precision() { + return PhysicsServer3D::get_singleton()->soft_body_get_simulation_precision(physics_rid); } -void SoftBody::set_simulation_precision(int p_simulation_precision) { - PhysicsServer::get_singleton()->soft_body_set_simulation_precision(physics_rid, p_simulation_precision); +void SoftBody3D::set_simulation_precision(int p_simulation_precision) { + PhysicsServer3D::get_singleton()->soft_body_set_simulation_precision(physics_rid, p_simulation_precision); } -real_t SoftBody::get_total_mass() { - return PhysicsServer::get_singleton()->soft_body_get_total_mass(physics_rid); +real_t SoftBody3D::get_total_mass() { + return PhysicsServer3D::get_singleton()->soft_body_get_total_mass(physics_rid); } -void SoftBody::set_total_mass(real_t p_total_mass) { - PhysicsServer::get_singleton()->soft_body_set_total_mass(physics_rid, p_total_mass); +void SoftBody3D::set_total_mass(real_t p_total_mass) { + PhysicsServer3D::get_singleton()->soft_body_set_total_mass(physics_rid, p_total_mass); } -void SoftBody::set_linear_stiffness(real_t p_linear_stiffness) { - PhysicsServer::get_singleton()->soft_body_set_linear_stiffness(physics_rid, p_linear_stiffness); +void SoftBody3D::set_linear_stiffness(real_t p_linear_stiffness) { + PhysicsServer3D::get_singleton()->soft_body_set_linear_stiffness(physics_rid, p_linear_stiffness); } -real_t SoftBody::get_linear_stiffness() { - return PhysicsServer::get_singleton()->soft_body_get_linear_stiffness(physics_rid); +real_t SoftBody3D::get_linear_stiffness() { + return PhysicsServer3D::get_singleton()->soft_body_get_linear_stiffness(physics_rid); } -void SoftBody::set_areaAngular_stiffness(real_t p_areaAngular_stiffness) { - PhysicsServer::get_singleton()->soft_body_set_areaAngular_stiffness(physics_rid, p_areaAngular_stiffness); +void SoftBody3D::set_areaAngular_stiffness(real_t p_areaAngular_stiffness) { + PhysicsServer3D::get_singleton()->soft_body_set_areaAngular_stiffness(physics_rid, p_areaAngular_stiffness); } -real_t SoftBody::get_areaAngular_stiffness() { - return PhysicsServer::get_singleton()->soft_body_get_areaAngular_stiffness(physics_rid); +real_t SoftBody3D::get_areaAngular_stiffness() { + return PhysicsServer3D::get_singleton()->soft_body_get_areaAngular_stiffness(physics_rid); } -void SoftBody::set_volume_stiffness(real_t p_volume_stiffness) { - PhysicsServer::get_singleton()->soft_body_set_volume_stiffness(physics_rid, p_volume_stiffness); +void SoftBody3D::set_volume_stiffness(real_t p_volume_stiffness) { + PhysicsServer3D::get_singleton()->soft_body_set_volume_stiffness(physics_rid, p_volume_stiffness); } -real_t SoftBody::get_volume_stiffness() { - return PhysicsServer::get_singleton()->soft_body_get_volume_stiffness(physics_rid); +real_t SoftBody3D::get_volume_stiffness() { + return PhysicsServer3D::get_singleton()->soft_body_get_volume_stiffness(physics_rid); } -real_t SoftBody::get_pressure_coefficient() { - return PhysicsServer::get_singleton()->soft_body_get_pressure_coefficient(physics_rid); +real_t SoftBody3D::get_pressure_coefficient() { + return PhysicsServer3D::get_singleton()->soft_body_get_pressure_coefficient(physics_rid); } -void SoftBody::set_pose_matching_coefficient(real_t p_pose_matching_coefficient) { - PhysicsServer::get_singleton()->soft_body_set_pose_matching_coefficient(physics_rid, p_pose_matching_coefficient); +void SoftBody3D::set_pose_matching_coefficient(real_t p_pose_matching_coefficient) { + PhysicsServer3D::get_singleton()->soft_body_set_pose_matching_coefficient(physics_rid, p_pose_matching_coefficient); } -real_t SoftBody::get_pose_matching_coefficient() { - return PhysicsServer::get_singleton()->soft_body_get_pose_matching_coefficient(physics_rid); +real_t SoftBody3D::get_pose_matching_coefficient() { + return PhysicsServer3D::get_singleton()->soft_body_get_pose_matching_coefficient(physics_rid); } -void SoftBody::set_pressure_coefficient(real_t p_pressure_coefficient) { - PhysicsServer::get_singleton()->soft_body_set_pressure_coefficient(physics_rid, p_pressure_coefficient); +void SoftBody3D::set_pressure_coefficient(real_t p_pressure_coefficient) { + PhysicsServer3D::get_singleton()->soft_body_set_pressure_coefficient(physics_rid, p_pressure_coefficient); } -real_t SoftBody::get_damping_coefficient() { - return PhysicsServer::get_singleton()->soft_body_get_damping_coefficient(physics_rid); +real_t SoftBody3D::get_damping_coefficient() { + return PhysicsServer3D::get_singleton()->soft_body_get_damping_coefficient(physics_rid); } -void SoftBody::set_damping_coefficient(real_t p_damping_coefficient) { - PhysicsServer::get_singleton()->soft_body_set_damping_coefficient(physics_rid, p_damping_coefficient); +void SoftBody3D::set_damping_coefficient(real_t p_damping_coefficient) { + PhysicsServer3D::get_singleton()->soft_body_set_damping_coefficient(physics_rid, p_damping_coefficient); } -real_t SoftBody::get_drag_coefficient() { - return PhysicsServer::get_singleton()->soft_body_get_drag_coefficient(physics_rid); +real_t SoftBody3D::get_drag_coefficient() { + return PhysicsServer3D::get_singleton()->soft_body_get_drag_coefficient(physics_rid); } -void SoftBody::set_drag_coefficient(real_t p_drag_coefficient) { - PhysicsServer::get_singleton()->soft_body_set_drag_coefficient(physics_rid, p_drag_coefficient); +void SoftBody3D::set_drag_coefficient(real_t p_drag_coefficient) { + PhysicsServer3D::get_singleton()->soft_body_set_drag_coefficient(physics_rid, p_drag_coefficient); } -Vector3 SoftBody::get_point_transform(int p_point_index) { - return PhysicsServer::get_singleton()->soft_body_get_point_global_position(physics_rid, p_point_index); +Vector3 SoftBody3D::get_point_transform(int p_point_index) { + return PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, p_point_index); } -void SoftBody::pin_point_toggle(int p_point_index) { +void SoftBody3D::pin_point_toggle(int p_point_index) { pin_point(p_point_index, !(-1 != _has_pinned_point(p_point_index))); } -void SoftBody::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path) { +void SoftBody3D::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path) { _pin_point_on_physics_server(p_point_index, pin); if (pin) { _add_pinned_point(p_point_index, p_spatial_attachment_path); @@ -685,23 +686,23 @@ void SoftBody::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_ } } -bool SoftBody::is_point_pinned(int p_point_index) const { +bool SoftBody3D::is_point_pinned(int p_point_index) const { return -1 != _has_pinned_point(p_point_index); } -void SoftBody::set_ray_pickable(bool p_ray_pickable) { +void SoftBody3D::set_ray_pickable(bool p_ray_pickable) { ray_pickable = p_ray_pickable; _update_pickable(); } -bool SoftBody::is_ray_pickable() const { +bool SoftBody3D::is_ray_pickable() const { return ray_pickable; } -SoftBody::SoftBody() : - physics_rid(PhysicsServer::get_singleton()->soft_body_create()), +SoftBody3D::SoftBody3D() : + physics_rid(PhysicsServer3D::get_singleton()->soft_body_create()), mesh_owner(false), collision_mask(1), collision_layer(1), @@ -709,26 +710,26 @@ SoftBody::SoftBody() : pinned_points_cache_dirty(true), ray_pickable(true) { - PhysicsServer::get_singleton()->body_attach_object_instance_id(physics_rid, get_instance_id()); + PhysicsServer3D::get_singleton()->body_attach_object_instance_id(physics_rid, get_instance_id()); } -SoftBody::~SoftBody() { - PhysicsServer::get_singleton()->free(physics_rid); +SoftBody3D::~SoftBody3D() { + PhysicsServer3D::get_singleton()->free(physics_rid); } -void SoftBody::reset_softbody_pin() { - PhysicsServer::get_singleton()->soft_body_remove_all_pinned_points(physics_rid); +void SoftBody3D::reset_softbody_pin() { + PhysicsServer3D::get_singleton()->soft_body_remove_all_pinned_points(physics_rid); const PinnedPoint *pps = pinned_points.ptr(); for (int i = pinned_points.size() - 1; 0 < i; --i) { - PhysicsServer::get_singleton()->soft_body_pin_point(physics_rid, pps[i].point_index, true); + PhysicsServer3D::get_singleton()->soft_body_pin_point(physics_rid, pps[i].point_index, true); } } -void SoftBody::_make_cache_dirty() { +void SoftBody3D::_make_cache_dirty() { pinned_points_cache_dirty = true; } -void SoftBody::_update_cache_pin_points_datas() { +void SoftBody3D::_update_cache_pin_points_datas() { if (!pinned_points_cache_dirty) return; @@ -738,20 +739,20 @@ void SoftBody::_update_cache_pin_points_datas() { for (int i = pinned_points.size() - 1; 0 <= i; --i) { if (!w[i].spatial_attachment_path.is_empty()) { - w[i].spatial_attachment = Object::cast_to<Spatial>(get_node(w[i].spatial_attachment_path)); + w[i].spatial_attachment = Object::cast_to<Node3D>(get_node(w[i].spatial_attachment_path)); } if (!w[i].spatial_attachment) { - ERR_PRINT("Spatial node not defined in the pinned point, Softbody undefined behaviour!"); + ERR_PRINT("Node3D node not defined in the pinned point, Softbody undefined behaviour!"); } } } -void SoftBody::_pin_point_on_physics_server(int p_point_index, bool pin) { - PhysicsServer::get_singleton()->soft_body_pin_point(physics_rid, p_point_index, pin); +void SoftBody3D::_pin_point_on_physics_server(int p_point_index, bool pin) { + PhysicsServer3D::get_singleton()->soft_body_pin_point(physics_rid, p_point_index, pin); } -void SoftBody::_add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path) { - SoftBody::PinnedPoint *pinned_point; +void SoftBody3D::_add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path) { + SoftBody3D::PinnedPoint *pinned_point; if (-1 == _get_pinned_point(p_point_index, pinned_point)) { // Create new @@ -760,8 +761,8 @@ void SoftBody::_add_pinned_point(int p_point_index, const NodePath &p_spatial_at pp.spatial_attachment_path = p_spatial_attachment_path; if (!p_spatial_attachment_path.is_empty() && has_node(p_spatial_attachment_path)) { - pp.spatial_attachment = Object::cast_to<Spatial>(get_node(p_spatial_attachment_path)); - pp.offset = (pp.spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer::get_singleton()->soft_body_get_point_global_position(physics_rid, pp.point_index)); + pp.spatial_attachment = Object::cast_to<Node3D>(get_node(p_spatial_attachment_path)); + pp.offset = (pp.spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, pp.point_index)); } pinned_points.push_back(pp); @@ -772,13 +773,13 @@ void SoftBody::_add_pinned_point(int p_point_index, const NodePath &p_spatial_at pinned_point->spatial_attachment_path = p_spatial_attachment_path; if (!p_spatial_attachment_path.is_empty() && has_node(p_spatial_attachment_path)) { - pinned_point->spatial_attachment = Object::cast_to<Spatial>(get_node(p_spatial_attachment_path)); - pinned_point->offset = (pinned_point->spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer::get_singleton()->soft_body_get_point_global_position(physics_rid, pinned_point->point_index)); + pinned_point->spatial_attachment = Object::cast_to<Node3D>(get_node(p_spatial_attachment_path)); + pinned_point->offset = (pinned_point->spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, pinned_point->point_index)); } } } -void SoftBody::_reset_points_offsets() { +void SoftBody3D::_reset_points_offsets() { if (!Engine::get_singleton()->is_editor_hint()) return; @@ -788,34 +789,34 @@ void SoftBody::_reset_points_offsets() { for (int i = pinned_points.size() - 1; 0 <= i; --i) { if (!r[i].spatial_attachment) - w[i].spatial_attachment = Object::cast_to<Spatial>(get_node(r[i].spatial_attachment_path)); + w[i].spatial_attachment = Object::cast_to<Node3D>(get_node(r[i].spatial_attachment_path)); if (!r[i].spatial_attachment) continue; - w[i].offset = (r[i].spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer::get_singleton()->soft_body_get_point_global_position(physics_rid, r[i].point_index)); + w[i].offset = (r[i].spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, r[i].point_index)); } } -void SoftBody::_remove_pinned_point(int p_point_index) { +void SoftBody3D::_remove_pinned_point(int p_point_index) { const int id(_has_pinned_point(p_point_index)); if (-1 != id) { pinned_points.remove(id); } } -int SoftBody::_get_pinned_point(int p_point_index, SoftBody::PinnedPoint *&r_point) const { +int SoftBody3D::_get_pinned_point(int p_point_index, SoftBody3D::PinnedPoint *&r_point) const { const int id = _has_pinned_point(p_point_index); if (-1 == id) { - r_point = NULL; + r_point = nullptr; return -1; } else { - r_point = const_cast<SoftBody::PinnedPoint *>(&pinned_points.ptr()[id]); + r_point = const_cast<SoftBody3D::PinnedPoint *>(&pinned_points.ptr()[id]); return id; } } -int SoftBody::_has_pinned_point(int p_point_index) const { +int SoftBody3D::_has_pinned_point(int p_point_index) const { const PinnedPoint *r = pinned_points.ptr(); for (int i = pinned_points.size() - 1; 0 <= i; --i) { if (p_point_index == r[i].point_index) { diff --git a/scene/3d/soft_body.h b/scene/3d/soft_body_3d.h index d6c35a5989..7dd5880985 100644 --- a/scene/3d/soft_body.h +++ b/scene/3d/soft_body_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* soft_body.h */ +/* soft_body_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,13 +31,13 @@ #ifndef SOFT_PHYSICS_BODY_H #define SOFT_PHYSICS_BODY_H -#include "scene/3d/mesh_instance.h" +#include "scene/3d/mesh_instance_3d.h" -class SoftBody; +class SoftBody3D; -class SoftBodyVisualServerHandler { +class SoftBodyRenderingServerHandler { - friend class SoftBody; + friend class SoftBody3D; RID mesh; int surface; @@ -49,7 +49,7 @@ class SoftBodyVisualServerHandler { uint8_t *write_buffer; private: - SoftBodyVisualServerHandler(); + SoftBodyRenderingServerHandler(); bool is_ready() { return mesh.is_valid(); } void prepare(RID p_mesh_rid, int p_surface); void clear(); @@ -63,14 +63,14 @@ public: void set_aabb(const AABB &p_aabb); }; -class SoftBody : public MeshInstance { - GDCLASS(SoftBody, MeshInstance); +class SoftBody3D : public MeshInstance3D { + GDCLASS(SoftBody3D, MeshInstance3D); public: struct PinnedPoint { int point_index; NodePath spatial_attachment_path; - Spatial *spatial_attachment; // Cache + Node3D *spatial_attachment; // Cache Vector3 offset; PinnedPoint(); @@ -79,7 +79,7 @@ public: }; private: - SoftBodyVisualServerHandler visual_server_handler; + SoftBodyRenderingServerHandler rendering_server_handler; RID physics_rid; @@ -92,7 +92,7 @@ private: bool pinned_points_cache_dirty; Ref<ArrayMesh> debug_mesh_cache; - class MeshInstance *debug_mesh; + class MeshInstance3D *debug_mesh; bool capture_input_on_drag; bool ray_pickable; @@ -181,8 +181,8 @@ public: void set_ray_pickable(bool p_ray_pickable); bool is_ray_pickable() const; - SoftBody(); - ~SoftBody(); + SoftBody3D(); + ~SoftBody3D(); private: void reset_softbody_pin(); diff --git a/scene/3d/spring_arm.cpp b/scene/3d/spring_arm_3d.cpp index ce277dae5b..0ffde7aa8f 100644 --- a/scene/3d/spring_arm.cpp +++ b/scene/3d/spring_arm_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* spring_arm.cpp */ +/* spring_arm_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,115 +28,115 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "spring_arm.h" +#include "spring_arm_3d.h" #include "core/engine.h" -#include "scene/3d/collision_object.h" -#include "scene/resources/sphere_shape.h" -#include "servers/physics_server.h" +#include "scene/3d/collision_object_3d.h" +#include "scene/resources/sphere_shape_3d.h" +#include "servers/physics_server_3d.h" -SpringArm::SpringArm() : +SpringArm3D::SpringArm3D() : spring_length(1), current_spring_length(0), keep_child_basis(false), mask(1), margin(0.01) {} -void SpringArm::_notification(int p_what) { +void SpringArm3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: if (!Engine::get_singleton()->is_editor_hint()) { - set_process_internal(true); + set_physics_process_internal(true); } break; case NOTIFICATION_EXIT_TREE: if (!Engine::get_singleton()->is_editor_hint()) { - set_process_internal(false); + set_physics_process_internal(false); } break; - case NOTIFICATION_INTERNAL_PROCESS: + case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: process_spring(); break; } } -void SpringArm::_bind_methods() { +void SpringArm3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_hit_length"), &SpringArm::get_hit_length); + ClassDB::bind_method(D_METHOD("get_hit_length"), &SpringArm3D::get_hit_length); - ClassDB::bind_method(D_METHOD("set_length", "length"), &SpringArm::set_length); - ClassDB::bind_method(D_METHOD("get_length"), &SpringArm::get_length); + ClassDB::bind_method(D_METHOD("set_length", "length"), &SpringArm3D::set_length); + ClassDB::bind_method(D_METHOD("get_length"), &SpringArm3D::get_length); - ClassDB::bind_method(D_METHOD("set_shape", "shape"), &SpringArm::set_shape); - ClassDB::bind_method(D_METHOD("get_shape"), &SpringArm::get_shape); + ClassDB::bind_method(D_METHOD("set_shape", "shape"), &SpringArm3D::set_shape); + ClassDB::bind_method(D_METHOD("get_shape"), &SpringArm3D::get_shape); - ClassDB::bind_method(D_METHOD("add_excluded_object", "RID"), &SpringArm::add_excluded_object); - ClassDB::bind_method(D_METHOD("remove_excluded_object", "RID"), &SpringArm::remove_excluded_object); - ClassDB::bind_method(D_METHOD("clear_excluded_objects"), &SpringArm::clear_excluded_objects); + ClassDB::bind_method(D_METHOD("add_excluded_object", "RID"), &SpringArm3D::add_excluded_object); + ClassDB::bind_method(D_METHOD("remove_excluded_object", "RID"), &SpringArm3D::remove_excluded_object); + ClassDB::bind_method(D_METHOD("clear_excluded_objects"), &SpringArm3D::clear_excluded_objects); - ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &SpringArm::set_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &SpringArm::get_mask); + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &SpringArm3D::set_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &SpringArm3D::get_mask); - ClassDB::bind_method(D_METHOD("set_margin", "margin"), &SpringArm::set_margin); - ClassDB::bind_method(D_METHOD("get_margin"), &SpringArm::get_margin); + ClassDB::bind_method(D_METHOD("set_margin", "margin"), &SpringArm3D::set_margin); + ClassDB::bind_method(D_METHOD("get_margin"), &SpringArm3D::get_margin); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape"), "set_shape", "get_shape"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape3D"), "set_shape", "get_shape"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "spring_length"), "set_length", "get_length"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin"), "set_margin", "get_margin"); } -float SpringArm::get_length() const { +float SpringArm3D::get_length() const { return spring_length; } -void SpringArm::set_length(float p_length) { +void SpringArm3D::set_length(float p_length) { if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) update_gizmo(); spring_length = p_length; } -void SpringArm::set_shape(Ref<Shape> p_shape) { +void SpringArm3D::set_shape(Ref<Shape3D> p_shape) { shape = p_shape; } -Ref<Shape> SpringArm::get_shape() const { +Ref<Shape3D> SpringArm3D::get_shape() const { return shape; } -void SpringArm::set_mask(uint32_t p_mask) { +void SpringArm3D::set_mask(uint32_t p_mask) { mask = p_mask; } -uint32_t SpringArm::get_mask() { +uint32_t SpringArm3D::get_mask() { return mask; } -float SpringArm::get_margin() { +float SpringArm3D::get_margin() { return margin; } -void SpringArm::set_margin(float p_margin) { +void SpringArm3D::set_margin(float p_margin) { margin = p_margin; } -void SpringArm::add_excluded_object(RID p_rid) { +void SpringArm3D::add_excluded_object(RID p_rid) { excluded_objects.insert(p_rid); } -bool SpringArm::remove_excluded_object(RID p_rid) { +bool SpringArm3D::remove_excluded_object(RID p_rid) { return excluded_objects.erase(p_rid); } -void SpringArm::clear_excluded_objects() { +void SpringArm3D::clear_excluded_objects() { excluded_objects.clear(); } -float SpringArm::get_hit_length() { +float SpringArm3D::get_hit_length() { return current_spring_length; } -void SpringArm::process_spring() { +void SpringArm3D::process_spring() { // From real_t motion_delta(1); real_t motion_delta_unsafe(1); @@ -146,7 +146,7 @@ void SpringArm::process_spring() { if (shape.is_null()) { motion = Vector3(cast_direction * (spring_length)); - PhysicsDirectSpaceState::RayResult r; + PhysicsDirectSpaceState3D::RayResult r; bool intersected = get_world()->get_direct_space_state()->intersect_ray(get_global_transform().origin, get_global_transform().origin + motion, r, excluded_objects, mask); if (intersected) { float dist = get_global_transform().origin.distance_to(r.position); @@ -164,7 +164,7 @@ void SpringArm::process_spring() { for (int i = get_child_count() - 1; 0 <= i; --i) { - Spatial *child = Object::cast_to<Spatial>(get_child(i)); + Node3D *child = Object::cast_to<Node3D>(get_child(i)); if (child) { childs_transform.basis = child->get_global_transform().basis; child->set_global_transform(childs_transform); diff --git a/scene/3d/spring_arm.h b/scene/3d/spring_arm_3d.h index 1a12370564..cb8a00ecf9 100644 --- a/scene/3d/spring_arm.h +++ b/scene/3d/spring_arm_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* spring_arm.h */ +/* spring_arm_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,12 +31,12 @@ #ifndef SPRING_ARM_H #define SPRING_ARM_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" -class SpringArm : public Spatial { - GDCLASS(SpringArm, Spatial); +class SpringArm3D : public Node3D { + GDCLASS(SpringArm3D, Node3D); - Ref<Shape> shape; + Ref<Shape3D> shape; Set<RID> excluded_objects; float spring_length; float current_spring_length; @@ -51,8 +51,8 @@ protected: public: void set_length(float p_length); float get_length() const; - void set_shape(Ref<Shape> p_shape); - Ref<Shape> get_shape() const; + void set_shape(Ref<Shape3D> p_shape); + Ref<Shape3D> get_shape() const; void set_mask(uint32_t p_mask); uint32_t get_mask(); void add_excluded_object(RID p_rid); @@ -62,7 +62,7 @@ public: void set_margin(float p_margin); float get_margin(); - SpringArm(); + SpringArm3D(); private: void process_spring(); diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index fd22076091..85e5ebc475 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -83,8 +83,8 @@ void SpriteBase3D::_notification(int p_what) { if (parent_sprite) { parent_sprite->children.erase(pI); - pI = NULL; - parent_sprite = NULL; + pI = nullptr; + parent_sprite = nullptr; } } } @@ -364,8 +364,8 @@ SpriteBase3D::SpriteBase3D() { centered = true; hflip = false; vflip = false; - parent_sprite = NULL; - pI = NULL; + parent_sprite = nullptr; + pI = nullptr; for (int i = 0; i < FLAG_MAX; i++) flags[i] = i == FLAG_TRANSPARENT || i == FLAG_DOUBLE_SIDED; @@ -377,13 +377,13 @@ SpriteBase3D::SpriteBase3D() { modulate = Color(1, 1, 1, 1); pending_update = false; opacity = 1.0; - immediate = VisualServer::get_singleton()->immediate_create(); + immediate = RenderingServer::get_singleton()->immediate_create(); set_base(immediate); } SpriteBase3D::~SpriteBase3D() { - VisualServer::get_singleton()->free(immediate); + RenderingServer::get_singleton()->free(immediate); } /////////////////////////////////////////// @@ -392,7 +392,7 @@ void Sprite3D::_draw() { RID immediate = get_immediate(); - VS::get_singleton()->immediate_clear(immediate); + RS::get_singleton()->immediate_clear(immediate); if (!texture.is_valid()) return; Vector2 tsize = texture->get_size(); @@ -441,7 +441,7 @@ void Sprite3D::_draw() { // Properly setup UVs for impostor textures (AtlasTexture). Ref<AtlasTexture> atlas_tex = texture; - if (atlas_tex != NULL) { + if (atlas_tex != nullptr) { src_tsize[0] = atlas_tex->get_atlas()->get_width(); src_tsize[1] = atlas_tex->get_atlas()->get_height(); } @@ -475,9 +475,9 @@ void Sprite3D::_draw() { } RID mat = StandardMaterial3D::get_material_rid_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS, get_billboard_mode() == StandardMaterial3D::BILLBOARD_ENABLED, get_billboard_mode() == StandardMaterial3D::BILLBOARD_FIXED_Y); - VS::get_singleton()->immediate_set_material(immediate, mat); + RS::get_singleton()->immediate_set_material(immediate, mat); - VS::get_singleton()->immediate_begin(immediate, VS::PRIMITIVE_TRIANGLES, texture->get_rid()); + RS::get_singleton()->immediate_begin(immediate, RS::PRIMITIVE_TRIANGLES, texture->get_rid()); int x_axis = ((axis + 1) % 3); int y_axis = ((axis + 2) % 3); @@ -502,15 +502,15 @@ void Sprite3D::_draw() { static const int index[6] = { 0, 1, 2, 0, 2, 3 }; - VS::get_singleton()->immediate_normal(immediate, normal); - VS::get_singleton()->immediate_tangent(immediate, tangent); - VS::get_singleton()->immediate_color(immediate, color); - VS::get_singleton()->immediate_uv(immediate, uvs[i]); + RS::get_singleton()->immediate_normal(immediate, normal); + RS::get_singleton()->immediate_tangent(immediate, tangent); + RS::get_singleton()->immediate_color(immediate, color); + RS::get_singleton()->immediate_uv(immediate, uvs[i]); Vector3 vtx; vtx[x_axis] = vertices[index[i]][0]; vtx[y_axis] = vertices[index[i]][1]; - VS::get_singleton()->immediate_vertex(immediate, vtx); + RS::get_singleton()->immediate_vertex(immediate, vtx); if (i == 0) { aabb.position = vtx; aabb.size = Vector3(); @@ -519,7 +519,7 @@ void Sprite3D::_draw() { } } set_aabb(aabb); - VS::get_singleton()->immediate_end(immediate); + RS::get_singleton()->immediate_end(immediate); } void Sprite3D::_texture_changed() { @@ -717,7 +717,7 @@ Sprite3D::Sprite3D() { void AnimatedSprite3D::_draw() { RID immediate = get_immediate(); - VS::get_singleton()->immediate_clear(immediate); + RS::get_singleton()->immediate_clear(immediate); if (frames.is_null()) { return; @@ -775,7 +775,7 @@ void AnimatedSprite3D::_draw() { // Properly setup UVs for impostor textures (AtlasTexture). Ref<AtlasTexture> atlas_tex = texture; - if (atlas_tex != NULL) { + if (atlas_tex != nullptr) { src_tsize[0] = atlas_tex->get_atlas()->get_width(); src_tsize[1] = atlas_tex->get_atlas()->get_height(); } @@ -810,9 +810,9 @@ void AnimatedSprite3D::_draw() { RID mat = StandardMaterial3D::get_material_rid_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS, get_billboard_mode() == StandardMaterial3D::BILLBOARD_ENABLED, get_billboard_mode() == StandardMaterial3D::BILLBOARD_FIXED_Y); - VS::get_singleton()->immediate_set_material(immediate, mat); + RS::get_singleton()->immediate_set_material(immediate, mat); - VS::get_singleton()->immediate_begin(immediate, VS::PRIMITIVE_TRIANGLES, texture->get_rid()); + RS::get_singleton()->immediate_begin(immediate, RS::PRIMITIVE_TRIANGLES, texture->get_rid()); int x_axis = ((axis + 1) % 3); int y_axis = ((axis + 2) % 3); @@ -840,15 +840,15 @@ void AnimatedSprite3D::_draw() { 0, 2, 3 }; - VS::get_singleton()->immediate_normal(immediate, normal); - VS::get_singleton()->immediate_tangent(immediate, tangent); - VS::get_singleton()->immediate_color(immediate, color); - VS::get_singleton()->immediate_uv(immediate, uvs[i]); + RS::get_singleton()->immediate_normal(immediate, normal); + RS::get_singleton()->immediate_tangent(immediate, tangent); + RS::get_singleton()->immediate_color(immediate, color); + RS::get_singleton()->immediate_uv(immediate, uvs[i]); Vector3 vtx; vtx[x_axis] = vertices[indices[i]][0]; vtx[y_axis] = vertices[indices[i]][1]; - VS::get_singleton()->immediate_vertex(immediate, vtx); + RS::get_singleton()->immediate_vertex(immediate, vtx); if (i == 0) { aabb.position = vtx; aabb.size = Vector3(); @@ -857,7 +857,7 @@ void AnimatedSprite3D::_draw() { } } set_aabb(aabb); - VS::get_singleton()->immediate_end(immediate); + RS::get_singleton()->immediate_end(immediate); } void AnimatedSprite3D::_validate_property(PropertyInfo &property) const { diff --git a/scene/3d/sprite_3d.h b/scene/3d/sprite_3d.h index 082884c83b..64bef41fd8 100644 --- a/scene/3d/sprite_3d.h +++ b/scene/3d/sprite_3d.h @@ -31,12 +31,12 @@ #ifndef SPRITE_3D_H #define SPRITE_3D_H -#include "scene/2d/animated_sprite.h" -#include "scene/3d/visual_instance.h" +#include "scene/2d/animated_sprite_2d.h" +#include "scene/3d/visual_instance_3d.h" -class SpriteBase3D : public GeometryInstance { +class SpriteBase3D : public GeometryInstance3D { - GDCLASS(SpriteBase3D, GeometryInstance); + GDCLASS(SpriteBase3D, GeometryInstance3D); mutable Ref<TriangleMesh> triangle_mesh; //cached diff --git a/scene/3d/vehicle_body.cpp b/scene/3d/vehicle_body_3d.cpp index c249d844d1..5c2fa59a21 100644 --- a/scene/3d/vehicle_body.cpp +++ b/scene/3d/vehicle_body_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* vehicle_body.cpp */ +/* vehicle_body_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "vehicle_body.h" +#include "vehicle_body_3d.h" #define ROLLING_INFLUENCE_FIX @@ -78,11 +78,11 @@ public: } }; -void VehicleWheel::_notification(int p_what) { +void VehicleWheel3D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { - VehicleBody *cb = Object::cast_to<VehicleBody>(get_parent()); + VehicleBody3D *cb = Object::cast_to<VehicleBody3D>(get_parent()); if (!cb) return; body = cb; @@ -95,23 +95,23 @@ void VehicleWheel::_notification(int p_what) { } if (p_what == NOTIFICATION_EXIT_TREE) { - VehicleBody *cb = Object::cast_to<VehicleBody>(get_parent()); + VehicleBody3D *cb = Object::cast_to<VehicleBody3D>(get_parent()); if (!cb) return; cb->wheels.erase(this); - body = NULL; + body = nullptr; } } -String VehicleWheel::get_configuration_warning() const { - if (!Object::cast_to<VehicleBody>(get_parent())) { - return TTR("VehicleWheel serves to provide a wheel system to a VehicleBody. Please use it as a child of a VehicleBody."); +String VehicleWheel3D::get_configuration_warning() const { + if (!Object::cast_to<VehicleBody3D>(get_parent())) { + return TTR("VehicleWheel3D serves to provide a wheel system to a VehicleBody3D. Please use it as a child of a VehicleBody3D."); } return String(); } -void VehicleWheel::_update(PhysicsDirectBodyState *s) { +void VehicleWheel3D::_update(PhysicsDirectBodyState3D *s) { if (m_raycastInfo.m_isInContact) @@ -144,148 +144,148 @@ void VehicleWheel::_update(PhysicsDirectBodyState *s) { } } -void VehicleWheel::set_radius(float p_radius) { +void VehicleWheel3D::set_radius(float p_radius) { m_wheelRadius = p_radius; update_gizmo(); } -float VehicleWheel::get_radius() const { +float VehicleWheel3D::get_radius() const { return m_wheelRadius; } -void VehicleWheel::set_suspension_rest_length(float p_length) { +void VehicleWheel3D::set_suspension_rest_length(float p_length) { m_suspensionRestLength = p_length; update_gizmo(); } -float VehicleWheel::get_suspension_rest_length() const { +float VehicleWheel3D::get_suspension_rest_length() const { return m_suspensionRestLength; } -void VehicleWheel::set_suspension_travel(float p_length) { +void VehicleWheel3D::set_suspension_travel(float p_length) { m_maxSuspensionTravelCm = p_length / 0.01; } -float VehicleWheel::get_suspension_travel() const { +float VehicleWheel3D::get_suspension_travel() const { return m_maxSuspensionTravelCm * 0.01; } -void VehicleWheel::set_suspension_stiffness(float p_value) { +void VehicleWheel3D::set_suspension_stiffness(float p_value) { m_suspensionStiffness = p_value; } -float VehicleWheel::get_suspension_stiffness() const { +float VehicleWheel3D::get_suspension_stiffness() const { return m_suspensionStiffness; } -void VehicleWheel::set_suspension_max_force(float p_value) { +void VehicleWheel3D::set_suspension_max_force(float p_value) { m_maxSuspensionForce = p_value; } -float VehicleWheel::get_suspension_max_force() const { +float VehicleWheel3D::get_suspension_max_force() const { return m_maxSuspensionForce; } -void VehicleWheel::set_damping_compression(float p_value) { +void VehicleWheel3D::set_damping_compression(float p_value) { m_wheelsDampingCompression = p_value; } -float VehicleWheel::get_damping_compression() const { +float VehicleWheel3D::get_damping_compression() const { return m_wheelsDampingCompression; } -void VehicleWheel::set_damping_relaxation(float p_value) { +void VehicleWheel3D::set_damping_relaxation(float p_value) { m_wheelsDampingRelaxation = p_value; } -float VehicleWheel::get_damping_relaxation() const { +float VehicleWheel3D::get_damping_relaxation() const { return m_wheelsDampingRelaxation; } -void VehicleWheel::set_friction_slip(float p_value) { +void VehicleWheel3D::set_friction_slip(float p_value) { m_frictionSlip = p_value; } -float VehicleWheel::get_friction_slip() const { +float VehicleWheel3D::get_friction_slip() const { return m_frictionSlip; } -void VehicleWheel::set_roll_influence(float p_value) { +void VehicleWheel3D::set_roll_influence(float p_value) { m_rollInfluence = p_value; } -float VehicleWheel::get_roll_influence() const { +float VehicleWheel3D::get_roll_influence() const { return m_rollInfluence; } -bool VehicleWheel::is_in_contact() const { +bool VehicleWheel3D::is_in_contact() const { return m_raycastInfo.m_isInContact; } -void VehicleWheel::_bind_methods() { +void VehicleWheel3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_radius", "length"), &VehicleWheel::set_radius); - ClassDB::bind_method(D_METHOD("get_radius"), &VehicleWheel::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "length"), &VehicleWheel3D::set_radius); + ClassDB::bind_method(D_METHOD("get_radius"), &VehicleWheel3D::get_radius); - ClassDB::bind_method(D_METHOD("set_suspension_rest_length", "length"), &VehicleWheel::set_suspension_rest_length); - ClassDB::bind_method(D_METHOD("get_suspension_rest_length"), &VehicleWheel::get_suspension_rest_length); + ClassDB::bind_method(D_METHOD("set_suspension_rest_length", "length"), &VehicleWheel3D::set_suspension_rest_length); + ClassDB::bind_method(D_METHOD("get_suspension_rest_length"), &VehicleWheel3D::get_suspension_rest_length); - ClassDB::bind_method(D_METHOD("set_suspension_travel", "length"), &VehicleWheel::set_suspension_travel); - ClassDB::bind_method(D_METHOD("get_suspension_travel"), &VehicleWheel::get_suspension_travel); + ClassDB::bind_method(D_METHOD("set_suspension_travel", "length"), &VehicleWheel3D::set_suspension_travel); + ClassDB::bind_method(D_METHOD("get_suspension_travel"), &VehicleWheel3D::get_suspension_travel); - ClassDB::bind_method(D_METHOD("set_suspension_stiffness", "length"), &VehicleWheel::set_suspension_stiffness); - ClassDB::bind_method(D_METHOD("get_suspension_stiffness"), &VehicleWheel::get_suspension_stiffness); + ClassDB::bind_method(D_METHOD("set_suspension_stiffness", "length"), &VehicleWheel3D::set_suspension_stiffness); + ClassDB::bind_method(D_METHOD("get_suspension_stiffness"), &VehicleWheel3D::get_suspension_stiffness); - ClassDB::bind_method(D_METHOD("set_suspension_max_force", "length"), &VehicleWheel::set_suspension_max_force); - ClassDB::bind_method(D_METHOD("get_suspension_max_force"), &VehicleWheel::get_suspension_max_force); + ClassDB::bind_method(D_METHOD("set_suspension_max_force", "length"), &VehicleWheel3D::set_suspension_max_force); + ClassDB::bind_method(D_METHOD("get_suspension_max_force"), &VehicleWheel3D::get_suspension_max_force); - ClassDB::bind_method(D_METHOD("set_damping_compression", "length"), &VehicleWheel::set_damping_compression); - ClassDB::bind_method(D_METHOD("get_damping_compression"), &VehicleWheel::get_damping_compression); + ClassDB::bind_method(D_METHOD("set_damping_compression", "length"), &VehicleWheel3D::set_damping_compression); + ClassDB::bind_method(D_METHOD("get_damping_compression"), &VehicleWheel3D::get_damping_compression); - ClassDB::bind_method(D_METHOD("set_damping_relaxation", "length"), &VehicleWheel::set_damping_relaxation); - ClassDB::bind_method(D_METHOD("get_damping_relaxation"), &VehicleWheel::get_damping_relaxation); + ClassDB::bind_method(D_METHOD("set_damping_relaxation", "length"), &VehicleWheel3D::set_damping_relaxation); + ClassDB::bind_method(D_METHOD("get_damping_relaxation"), &VehicleWheel3D::get_damping_relaxation); - ClassDB::bind_method(D_METHOD("set_use_as_traction", "enable"), &VehicleWheel::set_use_as_traction); - ClassDB::bind_method(D_METHOD("is_used_as_traction"), &VehicleWheel::is_used_as_traction); + ClassDB::bind_method(D_METHOD("set_use_as_traction", "enable"), &VehicleWheel3D::set_use_as_traction); + ClassDB::bind_method(D_METHOD("is_used_as_traction"), &VehicleWheel3D::is_used_as_traction); - ClassDB::bind_method(D_METHOD("set_use_as_steering", "enable"), &VehicleWheel::set_use_as_steering); - ClassDB::bind_method(D_METHOD("is_used_as_steering"), &VehicleWheel::is_used_as_steering); + ClassDB::bind_method(D_METHOD("set_use_as_steering", "enable"), &VehicleWheel3D::set_use_as_steering); + ClassDB::bind_method(D_METHOD("is_used_as_steering"), &VehicleWheel3D::is_used_as_steering); - ClassDB::bind_method(D_METHOD("set_friction_slip", "length"), &VehicleWheel::set_friction_slip); - ClassDB::bind_method(D_METHOD("get_friction_slip"), &VehicleWheel::get_friction_slip); + ClassDB::bind_method(D_METHOD("set_friction_slip", "length"), &VehicleWheel3D::set_friction_slip); + ClassDB::bind_method(D_METHOD("get_friction_slip"), &VehicleWheel3D::get_friction_slip); - ClassDB::bind_method(D_METHOD("is_in_contact"), &VehicleWheel::is_in_contact); + ClassDB::bind_method(D_METHOD("is_in_contact"), &VehicleWheel3D::is_in_contact); - ClassDB::bind_method(D_METHOD("set_roll_influence", "roll_influence"), &VehicleWheel::set_roll_influence); - ClassDB::bind_method(D_METHOD("get_roll_influence"), &VehicleWheel::get_roll_influence); + ClassDB::bind_method(D_METHOD("set_roll_influence", "roll_influence"), &VehicleWheel3D::set_roll_influence); + ClassDB::bind_method(D_METHOD("get_roll_influence"), &VehicleWheel3D::get_roll_influence); - ClassDB::bind_method(D_METHOD("get_skidinfo"), &VehicleWheel::get_skidinfo); + ClassDB::bind_method(D_METHOD("get_skidinfo"), &VehicleWheel3D::get_skidinfo); - ClassDB::bind_method(D_METHOD("get_rpm"), &VehicleWheel::get_rpm); + ClassDB::bind_method(D_METHOD("get_rpm"), &VehicleWheel3D::get_rpm); - ClassDB::bind_method(D_METHOD("set_engine_force", "engine_force"), &VehicleWheel::set_engine_force); - ClassDB::bind_method(D_METHOD("get_engine_force"), &VehicleWheel::get_engine_force); + ClassDB::bind_method(D_METHOD("set_engine_force", "engine_force"), &VehicleWheel3D::set_engine_force); + ClassDB::bind_method(D_METHOD("get_engine_force"), &VehicleWheel3D::get_engine_force); - ClassDB::bind_method(D_METHOD("set_brake", "brake"), &VehicleWheel::set_brake); - ClassDB::bind_method(D_METHOD("get_brake"), &VehicleWheel::get_brake); + ClassDB::bind_method(D_METHOD("set_brake", "brake"), &VehicleWheel3D::set_brake); + ClassDB::bind_method(D_METHOD("get_brake"), &VehicleWheel3D::get_brake); - ClassDB::bind_method(D_METHOD("set_steering", "steering"), &VehicleWheel::set_steering); - ClassDB::bind_method(D_METHOD("get_steering"), &VehicleWheel::get_steering); + ClassDB::bind_method(D_METHOD("set_steering", "steering"), &VehicleWheel3D::set_steering); + ClassDB::bind_method(D_METHOD("get_steering"), &VehicleWheel3D::get_steering); ADD_GROUP("Per-Wheel Motion", ""); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "engine_force", PROPERTY_HINT_RANGE, "0.00,1024.0,0.01,or_greater"), "set_engine_force", "get_engine_force"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "brake", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_brake", "get_brake"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "steering", PROPERTY_HINT_RANGE, "-180,180.0,0.01"), "set_steering", "get_steering"); - ADD_GROUP("VehicleBody Motion", ""); + ADD_GROUP("VehicleBody3D Motion", ""); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_traction"), "set_use_as_traction", "is_used_as_traction"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_steering"), "set_use_as_steering", "is_used_as_steering"); ADD_GROUP("Wheel", "wheel_"); @@ -302,65 +302,65 @@ void VehicleWheel::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "damping_relaxation"), "set_damping_relaxation", "get_damping_relaxation"); } -void VehicleWheel::set_engine_force(float p_engine_force) { +void VehicleWheel3D::set_engine_force(float p_engine_force) { m_engineForce = p_engine_force; } -float VehicleWheel::get_engine_force() const { +float VehicleWheel3D::get_engine_force() const { return m_engineForce; } -void VehicleWheel::set_brake(float p_brake) { +void VehicleWheel3D::set_brake(float p_brake) { m_brake = p_brake; } -float VehicleWheel::get_brake() const { +float VehicleWheel3D::get_brake() const { return m_brake; } -void VehicleWheel::set_steering(float p_steering) { +void VehicleWheel3D::set_steering(float p_steering) { m_steering = p_steering; } -float VehicleWheel::get_steering() const { +float VehicleWheel3D::get_steering() const { return m_steering; } -void VehicleWheel::set_use_as_traction(bool p_enable) { +void VehicleWheel3D::set_use_as_traction(bool p_enable) { engine_traction = p_enable; } -bool VehicleWheel::is_used_as_traction() const { +bool VehicleWheel3D::is_used_as_traction() const { return engine_traction; } -void VehicleWheel::set_use_as_steering(bool p_enabled) { +void VehicleWheel3D::set_use_as_steering(bool p_enabled) { steers = p_enabled; } -bool VehicleWheel::is_used_as_steering() const { +bool VehicleWheel3D::is_used_as_steering() const { return steers; } -float VehicleWheel::get_skidinfo() const { +float VehicleWheel3D::get_skidinfo() const { return m_skidInfo; } -float VehicleWheel::get_rpm() const { +float VehicleWheel3D::get_rpm() const { return m_rpm; } -VehicleWheel::VehicleWheel() { +VehicleWheel3D::VehicleWheel3D() { steers = false; engine_traction = false; @@ -385,10 +385,10 @@ VehicleWheel::VehicleWheel() { m_clippedInvContactDotSuspension = 1.0; m_raycastInfo.m_isInContact = false; - body = NULL; + body = nullptr; } -void VehicleBody::_update_wheel_transform(VehicleWheel &wheel, PhysicsDirectBodyState *s) { +void VehicleBody3D::_update_wheel_transform(VehicleWheel3D &wheel, PhysicsDirectBodyState3D *s) { wheel.m_raycastInfo.m_isInContact = false; @@ -405,9 +405,9 @@ void VehicleBody::_update_wheel_transform(VehicleWheel &wheel, PhysicsDirectBody wheel.m_raycastInfo.m_wheelAxleWS = chassisTrans.get_basis().xform(wheel.m_wheelAxleCS).normalized(); } -void VehicleBody::_update_wheel(int p_idx, PhysicsDirectBodyState *s) { +void VehicleBody3D::_update_wheel(int p_idx, PhysicsDirectBodyState3D *s) { - VehicleWheel &wheel = *wheels[p_idx]; + VehicleWheel3D &wheel = *wheels[p_idx]; _update_wheel_transform(wheel, s); Vector3 up = -wheel.m_raycastInfo.m_wheelDirectionWS; @@ -430,9 +430,9 @@ void VehicleBody::_update_wheel(int p_idx, PhysicsDirectBodyState *s) { wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_raycastInfo.m_suspensionLength); } -real_t VehicleBody::_ray_cast(int p_idx, PhysicsDirectBodyState *s) { +real_t VehicleBody3D::_ray_cast(int p_idx, PhysicsDirectBodyState3D *s) { - VehicleWheel &wheel = *wheels[p_idx]; + VehicleWheel3D &wheel = *wheels[p_idx]; _update_wheel_transform(wheel, s); @@ -448,13 +448,13 @@ real_t VehicleBody::_ray_cast(int p_idx, PhysicsDirectBodyState *s) { real_t param = real_t(0.); - PhysicsDirectSpaceState::RayResult rr; + PhysicsDirectSpaceState3D::RayResult rr; - PhysicsDirectSpaceState *ss = s->get_space_state(); + PhysicsDirectSpaceState3D *ss = s->get_space_state(); bool col = ss->intersect_ray(source, target, rr, exclude); - wheel.m_raycastInfo.m_groundObject = 0; + wheel.m_raycastInfo.m_groundObject = nullptr; if (col) { param = source.distance_to(rr.position) / source.distance_to(target); @@ -463,7 +463,7 @@ real_t VehicleBody::_ray_cast(int p_idx, PhysicsDirectBodyState *s) { wheel.m_raycastInfo.m_isInContact = true; if (rr.collider) - wheel.m_raycastInfo.m_groundObject = Object::cast_to<PhysicsBody>(rr.collider); + wheel.m_raycastInfo.m_groundObject = Object::cast_to<PhysicsBody3D>(rr.collider); real_t hitDistance = param * raylen; wheel.m_raycastInfo.m_suspensionLength = hitDistance - wheel.m_wheelRadius; @@ -513,12 +513,12 @@ real_t VehicleBody::_ray_cast(int p_idx, PhysicsDirectBodyState *s) { return depth; } -void VehicleBody::_update_suspension(PhysicsDirectBodyState *s) { +void VehicleBody3D::_update_suspension(PhysicsDirectBodyState3D *s) { real_t chassisMass = mass; for (int w_it = 0; w_it < wheels.size(); w_it++) { - VehicleWheel &wheel_info = *wheels[w_it]; + VehicleWheel3D &wheel_info = *wheels[w_it]; if (wheel_info.m_raycastInfo.m_isInContact) { real_t force; @@ -558,8 +558,8 @@ void VehicleBody::_update_suspension(PhysicsDirectBodyState *s) { } //bilateral constraint between two dynamic objects -void VehicleBody::_resolve_single_bilateral(PhysicsDirectBodyState *s, const Vector3 &pos1, - PhysicsBody *body2, const Vector3 &pos2, const Vector3 &normal, real_t &impulse, const real_t p_rollInfluence) { +void VehicleBody3D::_resolve_single_bilateral(PhysicsDirectBodyState3D *s, const Vector3 &pos1, + PhysicsBody3D *body2, const Vector3 &pos2, const Vector3 &normal, real_t &impulse, const real_t p_rollInfluence) { real_t normalLenSqr = normal.length_squared(); //ERR_FAIL_COND( normalLenSqr < real_t(1.1)); @@ -636,7 +636,7 @@ void VehicleBody::_resolve_single_bilateral(PhysicsDirectBodyState *s, const Vec #endif } -VehicleBody::btVehicleWheelContactPoint::btVehicleWheelContactPoint(PhysicsDirectBodyState *s, PhysicsBody *body1, const Vector3 &frictionPosWorld, const Vector3 &frictionDirectionWorld, real_t maxImpulse) : +VehicleBody3D::btVehicleWheelContactPoint::btVehicleWheelContactPoint(PhysicsDirectBodyState3D *s, PhysicsBody3D *body1, const Vector3 &frictionPosWorld, const Vector3 &frictionDirectionWorld, real_t maxImpulse) : m_s(s), m_body1(body1), m_frictionPositionWorld(frictionPosWorld), @@ -667,7 +667,7 @@ VehicleBody::btVehicleWheelContactPoint::btVehicleWheelContactPoint(PhysicsDirec m_jacDiagABInv = relaxation / (denom0 + denom1); } -real_t VehicleBody::_calc_rolling_friction(btVehicleWheelContactPoint &contactPoint) { +real_t VehicleBody3D::_calc_rolling_friction(btVehicleWheelContactPoint &contactPoint) { real_t j1 = 0.f; @@ -698,7 +698,7 @@ real_t VehicleBody::_calc_rolling_friction(btVehicleWheelContactPoint &contactPo } static const real_t sideFrictionStiffness2 = real_t(1.0); -void VehicleBody::_update_friction(PhysicsDirectBodyState *s) { +void VehicleBody3D::_update_friction(PhysicsDirectBodyState3D *s) { //calculate the impulse, so that the wheels don't move sidewards int numWheel = wheels.size(); @@ -720,7 +720,7 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) { for (int i = 0; i < wheels.size(); i++) { - VehicleWheel &wheelInfo = *wheels[i]; + VehicleWheel3D &wheelInfo = *wheels[i]; if (wheelInfo.m_raycastInfo.m_isInContact) { @@ -754,7 +754,7 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) { bool sliding = false; { for (int wheel = 0; wheel < wheels.size(); wheel++) { - VehicleWheel &wheelInfo = *wheels[wheel]; + VehicleWheel3D &wheelInfo = *wheels[wheel]; //class btRigidBody* groundObject = (class btRigidBody*) wheelInfo.m_raycastInfo.m_groundObject; @@ -816,7 +816,7 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) { // apply the impulses { for (int wheel = 0; wheel < wheels.size(); wheel++) { - VehicleWheel &wheelInfo = *wheels[wheel]; + VehicleWheel3D &wheelInfo = *wheels[wheel]; Vector3 rel_pos = wheelInfo.m_raycastInfo.m_contactPointWS - s->get_transform().origin; @@ -825,7 +825,7 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) { s->apply_impulse(rel_pos, m_forwardWS[wheel] * (m_forwardImpulse[wheel])); } if (m_sideImpulse[wheel] != real_t(0.)) { - PhysicsBody *groundObject = wheelInfo.m_raycastInfo.m_groundObject; + PhysicsBody3D *groundObject = wheelInfo.m_raycastInfo.m_groundObject; Vector3 rel_pos2; if (groundObject) { @@ -850,11 +850,11 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) { } } -void VehicleBody::_direct_state_changed(Object *p_state) { +void VehicleBody3D::_direct_state_changed(Object *p_state) { - RigidBody::_direct_state_changed(p_state); + RigidBody3D::_direct_state_changed(p_state); - state = Object::cast_to<PhysicsDirectBodyState>(p_state); + state = Object::cast_to<PhysicsDirectBodyState3D>(p_state); float step = state->get_step(); @@ -874,7 +874,7 @@ void VehicleBody::_direct_state_changed(Object *p_state) { for (int i = 0; i < wheels.size(); i++) { //apply suspension force - VehicleWheel &wheel = *wheels[i]; + VehicleWheel3D &wheel = *wheels[i]; real_t suspensionForce = wheel.m_wheelsSuspensionForce; @@ -891,7 +891,7 @@ void VehicleBody::_direct_state_changed(Object *p_state) { _update_friction(state); for (int i = 0; i < wheels.size(); i++) { - VehicleWheel &wheel = *wheels[i]; + VehicleWheel3D &wheel = *wheels[i]; Vector3 relpos = wheel.m_raycastInfo.m_hardPointWS - state->get_transform().origin; Vector3 vel = state->get_linear_velocity() + (state->get_angular_velocity()).cross(relpos); // * mPos); @@ -917,61 +917,61 @@ void VehicleBody::_direct_state_changed(Object *p_state) { wheel.m_deltaRotation *= real_t(0.99); //damping of rotation when not in contact } - state = NULL; + state = nullptr; } -void VehicleBody::set_engine_force(float p_engine_force) { +void VehicleBody3D::set_engine_force(float p_engine_force) { engine_force = p_engine_force; for (int i = 0; i < wheels.size(); i++) { - VehicleWheel &wheelInfo = *wheels[i]; + VehicleWheel3D &wheelInfo = *wheels[i]; if (wheelInfo.engine_traction) wheelInfo.m_engineForce = p_engine_force; } } -float VehicleBody::get_engine_force() const { +float VehicleBody3D::get_engine_force() const { return engine_force; } -void VehicleBody::set_brake(float p_brake) { +void VehicleBody3D::set_brake(float p_brake) { brake = p_brake; for (int i = 0; i < wheels.size(); i++) { - VehicleWheel &wheelInfo = *wheels[i]; + VehicleWheel3D &wheelInfo = *wheels[i]; wheelInfo.m_brake = p_brake; } } -float VehicleBody::get_brake() const { +float VehicleBody3D::get_brake() const { return brake; } -void VehicleBody::set_steering(float p_steering) { +void VehicleBody3D::set_steering(float p_steering) { m_steeringValue = p_steering; for (int i = 0; i < wheels.size(); i++) { - VehicleWheel &wheelInfo = *wheels[i]; + VehicleWheel3D &wheelInfo = *wheels[i]; if (wheelInfo.steers) wheelInfo.m_steering = p_steering; } } -float VehicleBody::get_steering() const { +float VehicleBody3D::get_steering() const { return m_steeringValue; } -void VehicleBody::_bind_methods() { +void VehicleBody3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_engine_force", "engine_force"), &VehicleBody::set_engine_force); - ClassDB::bind_method(D_METHOD("get_engine_force"), &VehicleBody::get_engine_force); + ClassDB::bind_method(D_METHOD("set_engine_force", "engine_force"), &VehicleBody3D::set_engine_force); + ClassDB::bind_method(D_METHOD("get_engine_force"), &VehicleBody3D::get_engine_force); - ClassDB::bind_method(D_METHOD("set_brake", "brake"), &VehicleBody::set_brake); - ClassDB::bind_method(D_METHOD("get_brake"), &VehicleBody::get_brake); + ClassDB::bind_method(D_METHOD("set_brake", "brake"), &VehicleBody3D::set_brake); + ClassDB::bind_method(D_METHOD("get_brake"), &VehicleBody3D::get_brake); - ClassDB::bind_method(D_METHOD("set_steering", "steering"), &VehicleBody::set_steering); - ClassDB::bind_method(D_METHOD("get_steering"), &VehicleBody::get_steering); + ClassDB::bind_method(D_METHOD("set_steering", "steering"), &VehicleBody3D::set_steering); + ClassDB::bind_method(D_METHOD("get_steering"), &VehicleBody3D::get_steering); ADD_GROUP("Motion", ""); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "engine_force", PROPERTY_HINT_RANGE, "0.00,1024.0,0.01,or_greater"), "set_engine_force", "get_engine_force"); @@ -979,7 +979,7 @@ void VehicleBody::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "steering", PROPERTY_HINT_RANGE, "-180,180.0,0.01"), "set_steering", "get_steering"); } -VehicleBody::VehicleBody() { +VehicleBody3D::VehicleBody3D() { m_pitchControl = 0; m_currentVehicleSpeedKmHour = real_t(0.); @@ -988,11 +988,11 @@ VehicleBody::VehicleBody() { engine_force = 0; brake = 0; - state = NULL; + state = nullptr; ccd = false; exclude.insert(get_rid()); - //PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); + //PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); set_mass(40); } diff --git a/scene/3d/vehicle_body.h b/scene/3d/vehicle_body_3d.h index c05ea30f94..d5e896263d 100644 --- a/scene/3d/vehicle_body.h +++ b/scene/3d/vehicle_body_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* vehicle_body.h */ +/* vehicle_body_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,15 +31,15 @@ #ifndef VEHICLE_BODY_H #define VEHICLE_BODY_H -#include "scene/3d/physics_body.h" +#include "scene/3d/physics_body_3d.h" -class VehicleBody; +class VehicleBody3D; -class VehicleWheel : public Spatial { +class VehicleWheel3D : public Node3D { - GDCLASS(VehicleWheel, Spatial); + GDCLASS(VehicleWheel3D, Node3D); - friend class VehicleBody; + friend class VehicleBody3D; Transform m_worldTransform; Transform local_xform; @@ -61,7 +61,7 @@ class VehicleWheel : public Spatial { real_t m_maxSuspensionForce; bool m_bIsFrontWheel; - VehicleBody *body; + VehicleBody3D *body; //btVector3 m_wheelAxleCS; // const or modified by steering ? @@ -88,10 +88,10 @@ class VehicleWheel : public Spatial { Vector3 m_wheelDirectionWS; //direction in worldspace Vector3 m_wheelAxleWS; // axle in worldspace bool m_isInContact; - PhysicsBody *m_groundObject; //could be general void* ptr + PhysicsBody3D *m_groundObject; //could be general void* ptr } m_raycastInfo; - void _update(PhysicsDirectBodyState *s); + void _update(PhysicsDirectBodyState3D *s); protected: void _notification(int p_what); @@ -148,12 +148,12 @@ public: String get_configuration_warning() const; - VehicleWheel(); + VehicleWheel3D(); }; -class VehicleBody : public RigidBody { +class VehicleBody3D : public RigidBody3D { - GDCLASS(VehicleBody, RigidBody); + GDCLASS(VehicleBody3D, RigidBody3D); float engine_force; float brake; @@ -170,27 +170,27 @@ class VehicleBody : public RigidBody { Vector<real_t> m_sideImpulse; struct btVehicleWheelContactPoint { - PhysicsDirectBodyState *m_s; - PhysicsBody *m_body1; + PhysicsDirectBodyState3D *m_s; + PhysicsBody3D *m_body1; Vector3 m_frictionPositionWorld; Vector3 m_frictionDirectionWorld; real_t m_jacDiagABInv; real_t m_maxImpulse; - btVehicleWheelContactPoint(PhysicsDirectBodyState *s, PhysicsBody *body1, const Vector3 &frictionPosWorld, const Vector3 &frictionDirectionWorld, real_t maxImpulse); + btVehicleWheelContactPoint(PhysicsDirectBodyState3D *s, PhysicsBody3D *body1, const Vector3 &frictionPosWorld, const Vector3 &frictionDirectionWorld, real_t maxImpulse); }; - void _resolve_single_bilateral(PhysicsDirectBodyState *s, const Vector3 &pos1, PhysicsBody *body2, const Vector3 &pos2, const Vector3 &normal, real_t &impulse, const real_t p_rollInfluence); + void _resolve_single_bilateral(PhysicsDirectBodyState3D *s, const Vector3 &pos1, PhysicsBody3D *body2, const Vector3 &pos2, const Vector3 &normal, real_t &impulse, const real_t p_rollInfluence); real_t _calc_rolling_friction(btVehicleWheelContactPoint &contactPoint); - void _update_friction(PhysicsDirectBodyState *s); - void _update_suspension(PhysicsDirectBodyState *s); - real_t _ray_cast(int p_idx, PhysicsDirectBodyState *s); - void _update_wheel_transform(VehicleWheel &wheel, PhysicsDirectBodyState *s); - void _update_wheel(int p_idx, PhysicsDirectBodyState *s); + void _update_friction(PhysicsDirectBodyState3D *s); + void _update_suspension(PhysicsDirectBodyState3D *s); + real_t _ray_cast(int p_idx, PhysicsDirectBodyState3D *s); + void _update_wheel_transform(VehicleWheel3D &wheel, PhysicsDirectBodyState3D *s); + void _update_wheel(int p_idx, PhysicsDirectBodyState3D *s); - friend class VehicleWheel; - Vector<VehicleWheel *> wheels; + friend class VehicleWheel3D; + Vector<VehicleWheel3D *> wheels; static void _bind_methods(); @@ -206,7 +206,7 @@ public: void set_steering(float p_steering); float get_steering() const; - VehicleBody(); + VehicleBody3D(); }; #endif // VEHICLE_BODY_H diff --git a/scene/3d/spatial_velocity_tracker.cpp b/scene/3d/velocity_tracker_3d.cpp index ec1bb1f991..c9b95e6397 100644 --- a/scene/3d/spatial_velocity_tracker.cpp +++ b/scene/3d/velocity_tracker_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* spatial_velocity_tracker.cpp */ +/* velocity_tracker_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,19 +28,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "spatial_velocity_tracker.h" +#include "velocity_tracker_3d.h" #include "core/engine.h" -void SpatialVelocityTracker::set_track_physics_step(bool p_track_physics_step) { +void VelocityTracker3D::set_track_physics_step(bool p_track_physics_step) { physics_step = p_track_physics_step; } -bool SpatialVelocityTracker::is_tracking_physics_step() const { +bool VelocityTracker3D::is_tracking_physics_step() const { return physics_step; } -void SpatialVelocityTracker::update_position(const Vector3 &p_position) { +void VelocityTracker3D::update_position(const Vector3 &p_position) { PositionHistory ph; ph.position = p_position; @@ -59,7 +59,7 @@ void SpatialVelocityTracker::update_position(const Vector3 &p_position) { position_history.write[0] = ph; } -Vector3 SpatialVelocityTracker::get_tracked_linear_velocity() const { +Vector3 VelocityTracker3D::get_tracked_linear_velocity() const { Vector3 linear_velocity; @@ -104,7 +104,7 @@ Vector3 SpatialVelocityTracker::get_tracked_linear_velocity() const { return linear_velocity; } -void SpatialVelocityTracker::reset(const Vector3 &p_new_pos) { +void VelocityTracker3D::reset(const Vector3 &p_new_pos) { PositionHistory ph; ph.position = p_new_pos; @@ -118,18 +118,18 @@ void SpatialVelocityTracker::reset(const Vector3 &p_new_pos) { position_history_len = 1; } -void SpatialVelocityTracker::_bind_methods() { +void VelocityTracker3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_track_physics_step", "enable"), &SpatialVelocityTracker::set_track_physics_step); - ClassDB::bind_method(D_METHOD("is_tracking_physics_step"), &SpatialVelocityTracker::is_tracking_physics_step); - ClassDB::bind_method(D_METHOD("update_position", "position"), &SpatialVelocityTracker::update_position); - ClassDB::bind_method(D_METHOD("get_tracked_linear_velocity"), &SpatialVelocityTracker::get_tracked_linear_velocity); - ClassDB::bind_method(D_METHOD("reset", "position"), &SpatialVelocityTracker::reset); + ClassDB::bind_method(D_METHOD("set_track_physics_step", "enable"), &VelocityTracker3D::set_track_physics_step); + ClassDB::bind_method(D_METHOD("is_tracking_physics_step"), &VelocityTracker3D::is_tracking_physics_step); + ClassDB::bind_method(D_METHOD("update_position", "position"), &VelocityTracker3D::update_position); + ClassDB::bind_method(D_METHOD("get_tracked_linear_velocity"), &VelocityTracker3D::get_tracked_linear_velocity); + ClassDB::bind_method(D_METHOD("reset", "position"), &VelocityTracker3D::reset); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "track_physics_step"), "set_track_physics_step", "is_tracking_physics_step"); } -SpatialVelocityTracker::SpatialVelocityTracker() { +VelocityTracker3D::VelocityTracker3D() { position_history.resize(4); // should be configurable position_history_len = 0; physics_step = false; diff --git a/scene/3d/spatial_velocity_tracker.h b/scene/3d/velocity_tracker_3d.h index 92b527b93c..a7ab3dce4d 100644 --- a/scene/3d/spatial_velocity_tracker.h +++ b/scene/3d/velocity_tracker_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* spatial_velocity_tracker.h */ +/* velocity_tracker_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,10 +31,10 @@ #ifndef SPATIAL_VELOCITY_TRACKER_H #define SPATIAL_VELOCITY_TRACKER_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" -class SpatialVelocityTracker : public Reference { - GDCLASS(SpatialVelocityTracker, Reference); +class VelocityTracker3D : public Reference { + GDCLASS(VelocityTracker3D, Reference); struct PositionHistory { uint64_t frame; @@ -55,7 +55,7 @@ public: void update_position(const Vector3 &p_position); Vector3 get_tracked_linear_velocity() const; - SpatialVelocityTracker(); + VelocityTracker3D(); }; #endif // SPATIAL_VELOCITY_TRACKER_H diff --git a/scene/3d/visibility_notifier.cpp b/scene/3d/visibility_notifier_3d.cpp index 5bc568bd5d..2f657fe7b1 100644 --- a/scene/3d/visibility_notifier.cpp +++ b/scene/3d/visibility_notifier_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* visibility_notifier.cpp */ +/* visibility_notifier_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "visibility_notifier.h" +#include "visibility_notifier_3d.h" #include "core/engine.h" -#include "scene/3d/camera.h" -#include "scene/3d/physics_body.h" +#include "scene/3d/camera_3d.h" +#include "scene/3d/physics_body_3d.h" #include "scene/animation/animation_player.h" #include "scene/scene_string_names.h" -void VisibilityNotifier::_enter_camera(Camera *p_camera) { +void VisibilityNotifier3D::_enter_camera(Camera3D *p_camera) { ERR_FAIL_COND(cameras.has(p_camera)); cameras.insert(p_camera); @@ -48,7 +48,7 @@ void VisibilityNotifier::_enter_camera(Camera *p_camera) { emit_signal(SceneStringNames::get_singleton()->camera_entered, p_camera); } -void VisibilityNotifier::_exit_camera(Camera *p_camera) { +void VisibilityNotifier3D::_exit_camera(Camera3D *p_camera) { ERR_FAIL_COND(!cameras.has(p_camera)); cameras.erase(p_camera); @@ -61,7 +61,7 @@ void VisibilityNotifier::_exit_camera(Camera *p_camera) { } } -void VisibilityNotifier::set_aabb(const AABB &p_aabb) { +void VisibilityNotifier3D::set_aabb(const AABB &p_aabb) { if (aabb == p_aabb) return; @@ -75,12 +75,12 @@ void VisibilityNotifier::set_aabb(const AABB &p_aabb) { update_gizmo(); } -AABB VisibilityNotifier::get_aabb() const { +AABB VisibilityNotifier3D::get_aabb() const { return aabb; } -void VisibilityNotifier::_notification(int p_what) { +void VisibilityNotifier3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_WORLD: { @@ -98,26 +98,26 @@ void VisibilityNotifier::_notification(int p_what) { } } -bool VisibilityNotifier::is_on_screen() const { +bool VisibilityNotifier3D::is_on_screen() const { return cameras.size() != 0; } -void VisibilityNotifier::_bind_methods() { +void VisibilityNotifier3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_aabb", "rect"), &VisibilityNotifier::set_aabb); - ClassDB::bind_method(D_METHOD("get_aabb"), &VisibilityNotifier::get_aabb); - ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibilityNotifier::is_on_screen); + ClassDB::bind_method(D_METHOD("set_aabb", "rect"), &VisibilityNotifier3D::set_aabb); + ClassDB::bind_method(D_METHOD("get_aabb"), &VisibilityNotifier3D::get_aabb); + ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibilityNotifier3D::is_on_screen); ADD_PROPERTY(PropertyInfo(Variant::AABB, "aabb"), "set_aabb", "get_aabb"); - ADD_SIGNAL(MethodInfo("camera_entered", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"))); - ADD_SIGNAL(MethodInfo("camera_exited", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"))); + ADD_SIGNAL(MethodInfo("camera_entered", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"))); + ADD_SIGNAL(MethodInfo("camera_exited", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"))); ADD_SIGNAL(MethodInfo("screen_entered")); ADD_SIGNAL(MethodInfo("screen_exited")); } -VisibilityNotifier::VisibilityNotifier() { +VisibilityNotifier3D::VisibilityNotifier3D() { aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2)); set_notify_transform(true); @@ -125,7 +125,7 @@ VisibilityNotifier::VisibilityNotifier() { ////////////////////////////////////// -void VisibilityEnabler::_screen_enter() { +void VisibilityEnabler3D::_screen_enter() { for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) { @@ -135,7 +135,7 @@ void VisibilityEnabler::_screen_enter() { visible = true; } -void VisibilityEnabler::_screen_exit() { +void VisibilityEnabler3D::_screen_exit() { for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) { @@ -145,14 +145,14 @@ void VisibilityEnabler::_screen_exit() { visible = false; } -void VisibilityEnabler::_find_nodes(Node *p_node) { +void VisibilityEnabler3D::_find_nodes(Node *p_node) { bool add = false; Variant meta; { - RigidBody *rb = Object::cast_to<RigidBody>(p_node); - if (rb && ((rb->get_mode() == RigidBody::MODE_CHARACTER || rb->get_mode() == RigidBody::MODE_RIGID))) { + RigidBody3D *rb = Object::cast_to<RigidBody3D>(p_node); + if (rb && ((rb->get_mode() == RigidBody3D::MODE_CHARACTER || rb->get_mode() == RigidBody3D::MODE_RIGID))) { add = true; meta = rb->get_mode(); @@ -168,7 +168,7 @@ void VisibilityEnabler::_find_nodes(Node *p_node) { if (add) { - p_node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler::_node_removed), varray(p_node), CONNECT_ONESHOT); + p_node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler3D::_node_removed), varray(p_node), CONNECT_ONESHOT); nodes[p_node] = meta; _change_node_state(p_node, false); } @@ -182,7 +182,7 @@ void VisibilityEnabler::_find_nodes(Node *p_node) { } } -void VisibilityEnabler::_notification(int p_what) { +void VisibilityEnabler3D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { @@ -206,19 +206,19 @@ void VisibilityEnabler::_notification(int p_what) { if (!visible) _change_node_state(E->key(), true); - E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler::_node_removed)); + E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler3D::_node_removed)); } nodes.clear(); } } -void VisibilityEnabler::_change_node_state(Node *p_node, bool p_enabled) { +void VisibilityEnabler3D::_change_node_state(Node *p_node, bool p_enabled) { ERR_FAIL_COND(!nodes.has(p_node)); if (enabler[ENABLER_FREEZE_BODIES]) { - RigidBody *rb = Object::cast_to<RigidBody>(p_node); + RigidBody3D *rb = Object::cast_to<RigidBody3D>(p_node); if (rb) rb->set_sleeping(!p_enabled); @@ -234,17 +234,17 @@ void VisibilityEnabler::_change_node_state(Node *p_node, bool p_enabled) { } } -void VisibilityEnabler::_node_removed(Node *p_node) { +void VisibilityEnabler3D::_node_removed(Node *p_node) { if (!visible) _change_node_state(p_node, true); nodes.erase(p_node); } -void VisibilityEnabler::_bind_methods() { +void VisibilityEnabler3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_enabler", "enabler", "enabled"), &VisibilityEnabler::set_enabler); - ClassDB::bind_method(D_METHOD("is_enabler_enabled", "enabler"), &VisibilityEnabler::is_enabler_enabled); + ClassDB::bind_method(D_METHOD("set_enabler", "enabler", "enabled"), &VisibilityEnabler3D::set_enabler); + ClassDB::bind_method(D_METHOD("is_enabler_enabled", "enabler"), &VisibilityEnabler3D::is_enabler_enabled); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "pause_animations"), "set_enabler", "is_enabler_enabled", ENABLER_PAUSE_ANIMATIONS); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "freeze_bodies"), "set_enabler", "is_enabler_enabled", ENABLER_FREEZE_BODIES); @@ -254,18 +254,18 @@ void VisibilityEnabler::_bind_methods() { BIND_ENUM_CONSTANT(ENABLER_MAX); } -void VisibilityEnabler::set_enabler(Enabler p_enabler, bool p_enable) { +void VisibilityEnabler3D::set_enabler(Enabler p_enabler, bool p_enable) { ERR_FAIL_INDEX(p_enabler, ENABLER_MAX); enabler[p_enabler] = p_enable; } -bool VisibilityEnabler::is_enabler_enabled(Enabler p_enabler) const { +bool VisibilityEnabler3D::is_enabler_enabled(Enabler p_enabler) const { ERR_FAIL_INDEX_V(p_enabler, ENABLER_MAX, false); return enabler[p_enabler]; } -VisibilityEnabler::VisibilityEnabler() { +VisibilityEnabler3D::VisibilityEnabler3D() { for (int i = 0; i < ENABLER_MAX; i++) enabler[i] = true; diff --git a/scene/3d/visibility_notifier.h b/scene/3d/visibility_notifier_3d.h index 71fdfdb78c..19204a6a4e 100644 --- a/scene/3d/visibility_notifier.h +++ b/scene/3d/visibility_notifier_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* visibility_notifier.h */ +/* visibility_notifier_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,14 +31,14 @@ #ifndef VISIBILITY_NOTIFIER_H #define VISIBILITY_NOTIFIER_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" -class Camera; -class VisibilityNotifier : public Spatial { +class Camera3D; +class VisibilityNotifier3D : public Node3D { - GDCLASS(VisibilityNotifier, Spatial); + GDCLASS(VisibilityNotifier3D, Node3D); - Set<Camera *> cameras; + Set<Camera3D *> cameras; AABB aabb; @@ -50,20 +50,20 @@ protected: static void _bind_methods(); friend struct SpatialIndexer; - void _enter_camera(Camera *p_camera); - void _exit_camera(Camera *p_camera); + void _enter_camera(Camera3D *p_camera); + void _exit_camera(Camera3D *p_camera); public: void set_aabb(const AABB &p_aabb); AABB get_aabb() const; bool is_on_screen() const; - VisibilityNotifier(); + VisibilityNotifier3D(); }; -class VisibilityEnabler : public VisibilityNotifier { +class VisibilityEnabler3D : public VisibilityNotifier3D { - GDCLASS(VisibilityEnabler, VisibilityNotifier); + GDCLASS(VisibilityEnabler3D, VisibilityNotifier3D); public: enum Enabler { @@ -93,9 +93,9 @@ public: void set_enabler(Enabler p_enabler, bool p_enable); bool is_enabler_enabled(Enabler p_enabler) const; - VisibilityEnabler(); + VisibilityEnabler3D(); }; -VARIANT_ENUM_CAST(VisibilityEnabler::Enabler); +VARIANT_ENUM_CAST(VisibilityEnabler3D::Enabler); #endif // VISIBILITY_NOTIFIER_H diff --git a/scene/3d/visual_instance.cpp b/scene/3d/visual_instance_3d.cpp index 105ce9ca74..604bc53422 100644 --- a/scene/3d/visual_instance.cpp +++ b/scene/3d/visual_instance_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* visual_instance.cpp */ +/* visual_instance_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,27 +28,27 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "visual_instance.h" +#include "visual_instance_3d.h" #include "scene/scene_string_names.h" -#include "servers/visual_server.h" -#include "skeleton.h" +#include "servers/rendering_server.h" +#include "skeleton_3d.h" -AABB VisualInstance::get_transformed_aabb() const { +AABB VisualInstance3D::get_transformed_aabb() const { return get_global_transform().xform(get_aabb()); } -void VisualInstance::_update_visibility() { +void VisualInstance3D::_update_visibility() { if (!is_inside_tree()) return; _change_notify("visible"); - VS::get_singleton()->instance_set_visible(get_instance(), is_visible_in_tree()); + RS::get_singleton()->instance_set_visible(get_instance(), is_visible_in_tree()); } -void VisualInstance::_notification(int p_what) { +void VisualInstance3D::_notification(int p_what) { switch (p_what) { @@ -58,23 +58,23 @@ void VisualInstance::_notification(int p_what) { /* Skeleton *skeleton=Object::cast_to<Skeleton>(get_parent()); if (skeleton) - VisualServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() ); + RenderingServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() ); */ ERR_FAIL_COND(get_world().is_null()); - VisualServer::get_singleton()->instance_set_scenario(instance, get_world()->get_scenario()); + RenderingServer::get_singleton()->instance_set_scenario(instance, get_world()->get_scenario()); _update_visibility(); } break; case NOTIFICATION_TRANSFORM_CHANGED: { Transform gt = get_global_transform(); - VisualServer::get_singleton()->instance_set_transform(instance, gt); + RenderingServer::get_singleton()->instance_set_transform(instance, gt); } break; case NOTIFICATION_EXIT_WORLD: { - VisualServer::get_singleton()->instance_set_scenario(instance, RID()); - VisualServer::get_singleton()->instance_attach_skeleton(instance, RID()); - //VS::get_singleton()->instance_geometry_set_baked_light_sampler(instance, RID() ); + RenderingServer::get_singleton()->instance_set_scenario(instance, RID()); + RenderingServer::get_singleton()->instance_attach_skeleton(instance, RID()); + //RS::get_singleton()->instance_geometry_set_baked_light_sampler(instance, RID() ); } break; case NOTIFICATION_VISIBILITY_CHANGED: { @@ -84,28 +84,28 @@ void VisualInstance::_notification(int p_what) { } } -RID VisualInstance::get_instance() const { +RID VisualInstance3D::get_instance() const { return instance; } -RID VisualInstance::_get_visual_instance_rid() const { +RID VisualInstance3D::_get_visual_instance_rid() const { return instance; } -void VisualInstance::set_layer_mask(uint32_t p_mask) { +void VisualInstance3D::set_layer_mask(uint32_t p_mask) { layers = p_mask; - VisualServer::get_singleton()->instance_set_layer_mask(instance, p_mask); + RenderingServer::get_singleton()->instance_set_layer_mask(instance, p_mask); } -uint32_t VisualInstance::get_layer_mask() const { +uint32_t VisualInstance3D::get_layer_mask() const { return layers; } -void VisualInstance::set_layer_mask_bit(int p_layer, bool p_enable) { +void VisualInstance3D::set_layer_mask_bit(int p_layer, bool p_enable) { ERR_FAIL_INDEX(p_layer, 32); if (p_enable) { set_layer_mask(layers | (1 << p_layer)); @@ -114,184 +114,259 @@ void VisualInstance::set_layer_mask_bit(int p_layer, bool p_enable) { } } -bool VisualInstance::get_layer_mask_bit(int p_layer) const { +bool VisualInstance3D::get_layer_mask_bit(int p_layer) const { ERR_FAIL_INDEX_V(p_layer, 32, false); return (layers & (1 << p_layer)); } -void VisualInstance::_bind_methods() { +void VisualInstance3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("_get_visual_instance_rid"), &VisualInstance::_get_visual_instance_rid); - ClassDB::bind_method(D_METHOD("set_base", "base"), &VisualInstance::set_base); - ClassDB::bind_method(D_METHOD("get_base"), &VisualInstance::get_base); - ClassDB::bind_method(D_METHOD("get_instance"), &VisualInstance::get_instance); - ClassDB::bind_method(D_METHOD("set_layer_mask", "mask"), &VisualInstance::set_layer_mask); - ClassDB::bind_method(D_METHOD("get_layer_mask"), &VisualInstance::get_layer_mask); - ClassDB::bind_method(D_METHOD("set_layer_mask_bit", "layer", "enabled"), &VisualInstance::set_layer_mask_bit); - ClassDB::bind_method(D_METHOD("get_layer_mask_bit", "layer"), &VisualInstance::get_layer_mask_bit); + ClassDB::bind_method(D_METHOD("_get_visual_instance_rid"), &VisualInstance3D::_get_visual_instance_rid); + ClassDB::bind_method(D_METHOD("set_base", "base"), &VisualInstance3D::set_base); + ClassDB::bind_method(D_METHOD("get_base"), &VisualInstance3D::get_base); + ClassDB::bind_method(D_METHOD("get_instance"), &VisualInstance3D::get_instance); + ClassDB::bind_method(D_METHOD("set_layer_mask", "mask"), &VisualInstance3D::set_layer_mask); + ClassDB::bind_method(D_METHOD("get_layer_mask"), &VisualInstance3D::get_layer_mask); + ClassDB::bind_method(D_METHOD("set_layer_mask_bit", "layer", "enabled"), &VisualInstance3D::set_layer_mask_bit); + ClassDB::bind_method(D_METHOD("get_layer_mask_bit", "layer"), &VisualInstance3D::get_layer_mask_bit); - ClassDB::bind_method(D_METHOD("get_transformed_aabb"), &VisualInstance::get_transformed_aabb); + ClassDB::bind_method(D_METHOD("get_transformed_aabb"), &VisualInstance3D::get_transformed_aabb); ADD_PROPERTY(PropertyInfo(Variant::INT, "layers", PROPERTY_HINT_LAYERS_3D_RENDER), "set_layer_mask", "get_layer_mask"); } -void VisualInstance::set_base(const RID &p_base) { +void VisualInstance3D::set_base(const RID &p_base) { - VisualServer::get_singleton()->instance_set_base(instance, p_base); + RenderingServer::get_singleton()->instance_set_base(instance, p_base); base = p_base; } -RID VisualInstance::get_base() const { +RID VisualInstance3D::get_base() const { return base; } -VisualInstance::VisualInstance() { +VisualInstance3D::VisualInstance3D() { - instance = VisualServer::get_singleton()->instance_create(); - VisualServer::get_singleton()->instance_attach_object_instance_id(instance, get_instance_id()); + instance = RenderingServer::get_singleton()->instance_create(); + RenderingServer::get_singleton()->instance_attach_object_instance_id(instance, get_instance_id()); layers = 1; set_notify_transform(true); } -VisualInstance::~VisualInstance() { +VisualInstance3D::~VisualInstance3D() { - VisualServer::get_singleton()->free(instance); + RenderingServer::get_singleton()->free(instance); } -void GeometryInstance::set_material_override(const Ref<Material> &p_material) { +void GeometryInstance3D::set_material_override(const Ref<Material> &p_material) { material_override = p_material; - VS::get_singleton()->instance_geometry_set_material_override(get_instance(), p_material.is_valid() ? p_material->get_rid() : RID()); + RS::get_singleton()->instance_geometry_set_material_override(get_instance(), p_material.is_valid() ? p_material->get_rid() : RID()); } -Ref<Material> GeometryInstance::get_material_override() const { +Ref<Material> GeometryInstance3D::get_material_override() const { return material_override; } -void GeometryInstance::set_lod_min_distance(float p_dist) { +void GeometryInstance3D::set_lod_min_distance(float p_dist) { lod_min_distance = p_dist; - VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); + RS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); } -float GeometryInstance::get_lod_min_distance() const { +float GeometryInstance3D::get_lod_min_distance() const { return lod_min_distance; } -void GeometryInstance::set_lod_max_distance(float p_dist) { +void GeometryInstance3D::set_lod_max_distance(float p_dist) { lod_max_distance = p_dist; - VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); + RS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); } -float GeometryInstance::get_lod_max_distance() const { +float GeometryInstance3D::get_lod_max_distance() const { return lod_max_distance; } -void GeometryInstance::set_lod_min_hysteresis(float p_dist) { +void GeometryInstance3D::set_lod_min_hysteresis(float p_dist) { lod_min_hysteresis = p_dist; - VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); + RS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); } -float GeometryInstance::get_lod_min_hysteresis() const { +float GeometryInstance3D::get_lod_min_hysteresis() const { return lod_min_hysteresis; } -void GeometryInstance::set_lod_max_hysteresis(float p_dist) { +void GeometryInstance3D::set_lod_max_hysteresis(float p_dist) { lod_max_hysteresis = p_dist; - VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); + RS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); } -float GeometryInstance::get_lod_max_hysteresis() const { +float GeometryInstance3D::get_lod_max_hysteresis() const { return lod_max_hysteresis; } -void GeometryInstance::_notification(int p_what) { +void GeometryInstance3D::_notification(int p_what) { } -void GeometryInstance::set_flag(Flags p_flag, bool p_value) { +const StringName *GeometryInstance3D::_instance_uniform_get_remap(const StringName p_name) const { + StringName *r = instance_uniform_property_remap.getptr(p_name); + if (!r) { + String s = p_name; + if (s.begins_with("shader_params/")) { + StringName name = s.replace("shader_params/", ""); + instance_uniform_property_remap[p_name] = name; + return instance_uniform_property_remap.getptr(p_name); + } + + return nullptr; + } + + return r; +} + +bool GeometryInstance3D::_set(const StringName &p_name, const Variant &p_value) { + const StringName *r = _instance_uniform_get_remap(p_name); + if (r) { + set_shader_instance_uniform(*r, p_value); + return true; + } + + return false; +} + +bool GeometryInstance3D::_get(const StringName &p_name, Variant &r_ret) const { + const StringName *r = _instance_uniform_get_remap(p_name); + if (r) { + r_ret = get_shader_instance_uniform(*r); + return true; + } + + return false; +} +void GeometryInstance3D::_get_property_list(List<PropertyInfo> *p_list) const { + List<PropertyInfo> pinfo; + RS::get_singleton()->instance_geometry_get_shader_parameter_list(get_instance(), &pinfo); + for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { + PropertyInfo pi = E->get(); + bool has_def_value = false; + Variant def_value = RS::get_singleton()->instance_geometry_get_shader_parameter_default_value(get_instance(), pi.name); + if (def_value.get_type() != Variant::NIL) { + has_def_value = true; + } + if (instance_uniforms.has(pi.name)) { + pi.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE | (has_def_value ? (PROPERTY_USAGE_CHECKABLE | PROPERTY_USAGE_CHECKED) : 0); + } else { + pi.usage = PROPERTY_USAGE_EDITOR | (has_def_value ? PROPERTY_USAGE_CHECKABLE : 0); //do not save if not changed + } + + pi.name = "shader_params/" + pi.name; + p_list->push_back(pi); + } +} + +void GeometryInstance3D::set_flag(Flags p_flag, bool p_value) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); if (flags[p_flag] == p_value) return; flags[p_flag] = p_value; - VS::get_singleton()->instance_geometry_set_flag(get_instance(), (VS::InstanceFlags)p_flag, p_value); + RS::get_singleton()->instance_geometry_set_flag(get_instance(), (RS::InstanceFlags)p_flag, p_value); } -bool GeometryInstance::get_flag(Flags p_flag) const { +bool GeometryInstance3D::get_flag(Flags p_flag) const { ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); return flags[p_flag]; } -void GeometryInstance::set_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting) { +void GeometryInstance3D::set_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting) { shadow_casting_setting = p_shadow_casting_setting; - VS::get_singleton()->instance_geometry_set_cast_shadows_setting(get_instance(), (VS::ShadowCastingSetting)p_shadow_casting_setting); + RS::get_singleton()->instance_geometry_set_cast_shadows_setting(get_instance(), (RS::ShadowCastingSetting)p_shadow_casting_setting); } -GeometryInstance::ShadowCastingSetting GeometryInstance::get_cast_shadows_setting() const { +GeometryInstance3D::ShadowCastingSetting GeometryInstance3D::get_cast_shadows_setting() const { return shadow_casting_setting; } -void GeometryInstance::set_extra_cull_margin(float p_margin) { +void GeometryInstance3D::set_extra_cull_margin(float p_margin) { ERR_FAIL_COND(p_margin < 0); extra_cull_margin = p_margin; - VS::get_singleton()->instance_set_extra_visibility_margin(get_instance(), extra_cull_margin); + RS::get_singleton()->instance_set_extra_visibility_margin(get_instance(), extra_cull_margin); } -float GeometryInstance::get_extra_cull_margin() const { +float GeometryInstance3D::get_extra_cull_margin() const { return extra_cull_margin; } -void GeometryInstance::set_custom_aabb(AABB aabb) { +void GeometryInstance3D::set_shader_instance_uniform(const StringName &p_uniform, const Variant &p_value) { - VS::get_singleton()->instance_set_custom_aabb(get_instance(), aabb); + if (p_value.get_type() == Variant::NIL) { + Variant def_value = RS::get_singleton()->instance_geometry_get_shader_parameter_default_value(get_instance(), p_uniform); + RS::get_singleton()->instance_geometry_set_shader_parameter(get_instance(), p_uniform, def_value); + instance_uniforms.erase(p_value); + } else { + instance_uniforms[p_uniform] = p_value; + RS::get_singleton()->instance_geometry_set_shader_parameter(get_instance(), p_uniform, p_value); + } } -void GeometryInstance::_bind_methods() { +Variant GeometryInstance3D::get_shader_instance_uniform(const StringName &p_uniform) const { + + return RS::get_singleton()->instance_geometry_get_shader_parameter(get_instance(), p_uniform); +} +void GeometryInstance3D::set_custom_aabb(AABB aabb) { + + RS::get_singleton()->instance_set_custom_aabb(get_instance(), aabb); +} + +void GeometryInstance3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_material_override", "material"), &GeometryInstance3D::set_material_override); + ClassDB::bind_method(D_METHOD("get_material_override"), &GeometryInstance3D::get_material_override); - ClassDB::bind_method(D_METHOD("set_material_override", "material"), &GeometryInstance::set_material_override); - ClassDB::bind_method(D_METHOD("get_material_override"), &GeometryInstance::get_material_override); + ClassDB::bind_method(D_METHOD("set_flag", "flag", "value"), &GeometryInstance3D::set_flag); + ClassDB::bind_method(D_METHOD("get_flag", "flag"), &GeometryInstance3D::get_flag); - ClassDB::bind_method(D_METHOD("set_flag", "flag", "value"), &GeometryInstance::set_flag); - ClassDB::bind_method(D_METHOD("get_flag", "flag"), &GeometryInstance::get_flag); + ClassDB::bind_method(D_METHOD("set_cast_shadows_setting", "shadow_casting_setting"), &GeometryInstance3D::set_cast_shadows_setting); + ClassDB::bind_method(D_METHOD("get_cast_shadows_setting"), &GeometryInstance3D::get_cast_shadows_setting); - ClassDB::bind_method(D_METHOD("set_cast_shadows_setting", "shadow_casting_setting"), &GeometryInstance::set_cast_shadows_setting); - ClassDB::bind_method(D_METHOD("get_cast_shadows_setting"), &GeometryInstance::get_cast_shadows_setting); + ClassDB::bind_method(D_METHOD("set_lod_max_hysteresis", "mode"), &GeometryInstance3D::set_lod_max_hysteresis); + ClassDB::bind_method(D_METHOD("get_lod_max_hysteresis"), &GeometryInstance3D::get_lod_max_hysteresis); - ClassDB::bind_method(D_METHOD("set_lod_max_hysteresis", "mode"), &GeometryInstance::set_lod_max_hysteresis); - ClassDB::bind_method(D_METHOD("get_lod_max_hysteresis"), &GeometryInstance::get_lod_max_hysteresis); + ClassDB::bind_method(D_METHOD("set_lod_max_distance", "mode"), &GeometryInstance3D::set_lod_max_distance); + ClassDB::bind_method(D_METHOD("get_lod_max_distance"), &GeometryInstance3D::get_lod_max_distance); - ClassDB::bind_method(D_METHOD("set_lod_max_distance", "mode"), &GeometryInstance::set_lod_max_distance); - ClassDB::bind_method(D_METHOD("get_lod_max_distance"), &GeometryInstance::get_lod_max_distance); + ClassDB::bind_method(D_METHOD("set_shader_instance_uniform", "uniform", "value"), &GeometryInstance3D::set_shader_instance_uniform); + ClassDB::bind_method(D_METHOD("get_shader_instance_uniform", "uniform"), &GeometryInstance3D::get_shader_instance_uniform); - ClassDB::bind_method(D_METHOD("set_lod_min_hysteresis", "mode"), &GeometryInstance::set_lod_min_hysteresis); - ClassDB::bind_method(D_METHOD("get_lod_min_hysteresis"), &GeometryInstance::get_lod_min_hysteresis); + ClassDB::bind_method(D_METHOD("set_lod_min_hysteresis", "mode"), &GeometryInstance3D::set_lod_min_hysteresis); + ClassDB::bind_method(D_METHOD("get_lod_min_hysteresis"), &GeometryInstance3D::get_lod_min_hysteresis); - ClassDB::bind_method(D_METHOD("set_lod_min_distance", "mode"), &GeometryInstance::set_lod_min_distance); - ClassDB::bind_method(D_METHOD("get_lod_min_distance"), &GeometryInstance::get_lod_min_distance); + ClassDB::bind_method(D_METHOD("set_lod_min_distance", "mode"), &GeometryInstance3D::set_lod_min_distance); + ClassDB::bind_method(D_METHOD("get_lod_min_distance"), &GeometryInstance3D::get_lod_min_distance); - ClassDB::bind_method(D_METHOD("set_extra_cull_margin", "margin"), &GeometryInstance::set_extra_cull_margin); - ClassDB::bind_method(D_METHOD("get_extra_cull_margin"), &GeometryInstance::get_extra_cull_margin); + ClassDB::bind_method(D_METHOD("set_extra_cull_margin", "margin"), &GeometryInstance3D::set_extra_cull_margin); + ClassDB::bind_method(D_METHOD("get_extra_cull_margin"), &GeometryInstance3D::get_extra_cull_margin); - ClassDB::bind_method(D_METHOD("set_custom_aabb", "aabb"), &GeometryInstance::set_custom_aabb); + ClassDB::bind_method(D_METHOD("set_custom_aabb", "aabb"), &GeometryInstance3D::set_custom_aabb); - ClassDB::bind_method(D_METHOD("get_aabb"), &GeometryInstance::get_aabb); + ClassDB::bind_method(D_METHOD("get_aabb"), &GeometryInstance3D::get_aabb); ADD_GROUP("Geometry", ""); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material_override", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,StandardMaterial3D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DEFERRED_SET_RESOURCE), "set_material_override", "get_material_override"); @@ -319,7 +394,7 @@ void GeometryInstance::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_MAX); } -GeometryInstance::GeometryInstance() { +GeometryInstance3D::GeometryInstance3D() { lod_min_distance = 0; lod_max_distance = 0; lod_min_hysteresis = 0; @@ -331,5 +406,5 @@ GeometryInstance::GeometryInstance() { shadow_casting_setting = SHADOW_CASTING_SETTING_ON; extra_cull_margin = 0; - //VS::get_singleton()->instance_geometry_set_baked_light_texture_index(get_instance(),0); + //RS::get_singleton()->instance_geometry_set_baked_light_texture_index(get_instance(),0); } diff --git a/scene/3d/visual_instance.h b/scene/3d/visual_instance_3d.h index fee6787c87..cc5f92066f 100644 --- a/scene/3d/visual_instance.h +++ b/scene/3d/visual_instance_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* visual_instance.h */ +/* visual_instance_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -33,12 +33,12 @@ #include "core/math/face3.h" #include "core/rid.h" -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" #include "scene/resources/material.h" -class VisualInstance : public Spatial { +class VisualInstance3D : public Node3D { - GDCLASS(VisualInstance, Spatial); + GDCLASS(VisualInstance3D, Node3D); OBJ_CATEGORY("3D Visual Nodes"); RID base; @@ -76,27 +76,27 @@ public: void set_layer_mask_bit(int p_layer, bool p_enable); bool get_layer_mask_bit(int p_layer) const; - VisualInstance(); - ~VisualInstance(); + VisualInstance3D(); + ~VisualInstance3D(); }; -class GeometryInstance : public VisualInstance { +class GeometryInstance3D : public VisualInstance3D { - GDCLASS(GeometryInstance, VisualInstance); + GDCLASS(GeometryInstance3D, VisualInstance3D); public: enum Flags { - FLAG_USE_BAKED_LIGHT = VS::INSTANCE_FLAG_USE_BAKED_LIGHT, - FLAG_USE_DYNAMIC_GI = VS::INSTANCE_FLAG_USE_DYNAMIC_GI, - FLAG_DRAW_NEXT_FRAME_IF_VISIBLE = VS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, - FLAG_MAX = VS::INSTANCE_FLAG_MAX, + FLAG_USE_BAKED_LIGHT = RS::INSTANCE_FLAG_USE_BAKED_LIGHT, + FLAG_USE_DYNAMIC_GI = RS::INSTANCE_FLAG_USE_DYNAMIC_GI, + FLAG_DRAW_NEXT_FRAME_IF_VISIBLE = RS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, + FLAG_MAX = RS::INSTANCE_FLAG_MAX, }; enum ShadowCastingSetting { - SHADOW_CASTING_SETTING_OFF = VS::SHADOW_CASTING_SETTING_OFF, - SHADOW_CASTING_SETTING_ON = VS::SHADOW_CASTING_SETTING_ON, - SHADOW_CASTING_SETTING_DOUBLE_SIDED = VS::SHADOW_CASTING_SETTING_DOUBLE_SIDED, - SHADOW_CASTING_SETTING_SHADOWS_ONLY = VS::SHADOW_CASTING_SETTING_SHADOWS_ONLY + SHADOW_CASTING_SETTING_OFF = RS::SHADOW_CASTING_SETTING_OFF, + SHADOW_CASTING_SETTING_ON = RS::SHADOW_CASTING_SETTING_ON, + SHADOW_CASTING_SETTING_DOUBLE_SIDED = RS::SHADOW_CASTING_SETTING_DOUBLE_SIDED, + SHADOW_CASTING_SETTING_SHADOWS_ONLY = RS::SHADOW_CASTING_SETTING_SHADOWS_ONLY }; private: @@ -108,9 +108,18 @@ private: float lod_min_hysteresis; float lod_max_hysteresis; + mutable HashMap<StringName, Variant> instance_uniforms; + mutable HashMap<StringName, StringName> instance_uniform_property_remap; + float extra_cull_margin; + const StringName *_instance_uniform_get_remap(const StringName p_name) const; + protected: + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; + void _notification(int p_what); static void _bind_methods(); @@ -139,12 +148,15 @@ public: void set_extra_cull_margin(float p_margin); float get_extra_cull_margin() const; + void set_shader_instance_uniform(const StringName &p_uniform, const Variant &p_value); + Variant get_shader_instance_uniform(const StringName &p_uniform) const; + void set_custom_aabb(AABB aabb); - GeometryInstance(); + GeometryInstance3D(); }; -VARIANT_ENUM_CAST(GeometryInstance::Flags); -VARIANT_ENUM_CAST(GeometryInstance::ShadowCastingSetting); +VARIANT_ENUM_CAST(GeometryInstance3D::Flags); +VARIANT_ENUM_CAST(GeometryInstance3D::ShadowCastingSetting); #endif diff --git a/scene/3d/voxelizer.cpp b/scene/3d/voxelizer.cpp index 203c3cd812..f30c58be55 100644 --- a/scene/3d/voxelizer.cpp +++ b/scene/3d/voxelizer.cpp @@ -592,22 +592,16 @@ void Voxelizer::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, const Vec Vector<Vector3> vertices = a[Mesh::ARRAY_VERTEX]; const Vector3 *vr = vertices.ptr(); Vector<Vector2> uv = a[Mesh::ARRAY_TEX_UV]; - const Vector2 *uvr; + const Vector2 *uvr = nullptr; Vector<Vector3> normals = a[Mesh::ARRAY_NORMAL]; - const Vector3 *nr; + const Vector3 *nr = nullptr; Vector<int> index = a[Mesh::ARRAY_INDEX]; - bool read_uv = false; - bool read_normals = false; - if (uv.size()) { - uvr = uv.ptr(); - read_uv = true; } if (normals.size()) { - read_normals = true; nr = normals.ptr(); } @@ -626,13 +620,13 @@ void Voxelizer::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, const Vec vtxs[k] = p_xform.xform(vr[ir[j * 3 + k]]); } - if (read_uv) { + if (uvr) { for (int k = 0; k < 3; k++) { uvs[k] = uvr[ir[j * 3 + k]]; } } - if (read_normals) { + if (nr) { for (int k = 0; k < 3; k++) { normal[k] = nr[ir[j * 3 + k]]; } @@ -659,13 +653,13 @@ void Voxelizer::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, const Vec vtxs[k] = p_xform.xform(vr[j * 3 + k]); } - if (read_uv) { + if (uvr) { for (int k = 0; k < 3; k++) { uvs[k] = uvr[j * 3 + k]; } } - if (read_normals) { + if (nr) { for (int k = 0; k < 3; k++) { normal[k] = nr[j * 3 + k]; } diff --git a/scene/3d/voxelizer.h b/scene/3d/voxelizer.h index af9237ae7b..1fde6237a2 100644 --- a/scene/3d/voxelizer.h +++ b/scene/3d/voxelizer.h @@ -32,7 +32,7 @@ #define VOXEL_LIGHT_BAKER_H #include "core/math/vector3i.h" -#include "scene/3d/mesh_instance.h" +#include "scene/3d/mesh_instance_3d.h" #include "scene/resources/multimesh.h" class Voxelizer { diff --git a/scene/3d/world_environment.cpp b/scene/3d/world_environment.cpp index 83a7243906..8cf4554653 100644 --- a/scene/3d/world_environment.cpp +++ b/scene/3d/world_environment.cpp @@ -29,11 +29,11 @@ /*************************************************************************/ #include "world_environment.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" void WorldEnvironment::_notification(int p_what) { - if (p_what == Spatial::NOTIFICATION_ENTER_WORLD || p_what == Spatial::NOTIFICATION_ENTER_TREE) { + if (p_what == Node3D::NOTIFICATION_ENTER_WORLD || p_what == Node3D::NOTIFICATION_ENTER_TREE) { if (environment.is_valid()) { if (get_viewport()->find_world()->get_environment().is_valid()) { @@ -51,7 +51,7 @@ void WorldEnvironment::_notification(int p_what) { add_to_group("_world_camera_effects_" + itos(get_viewport()->find_world()->get_scenario().get_id())); } - } else if (p_what == Spatial::NOTIFICATION_EXIT_WORLD || p_what == Spatial::NOTIFICATION_EXIT_TREE) { + } else if (p_what == Node3D::NOTIFICATION_EXIT_WORLD || p_what == Node3D::NOTIFICATION_EXIT_TREE) { if (environment.is_valid() && get_viewport()->find_world()->get_environment() == environment) { get_viewport()->find_world()->set_environment(Ref<Environment>()); diff --git a/scene/3d/world_environment.h b/scene/3d/world_environment.h index 0c590bfc07..e4c9fc071d 100644 --- a/scene/3d/world_environment.h +++ b/scene/3d/world_environment.h @@ -31,7 +31,7 @@ #ifndef SCENARIO_FX_H #define SCENARIO_FX_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" class WorldEnvironment : public Node { diff --git a/scene/3d/arvr_nodes.cpp b/scene/3d/xr_nodes.cpp index d23e5ffa08..0373114e7d 100644 --- a/scene/3d/arvr_nodes.cpp +++ b/scene/3d/xr_nodes.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* arvr_nodes.cpp */ +/* xr_nodes.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,54 +28,54 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "arvr_nodes.h" -#include "core/os/input.h" -#include "servers/arvr/arvr_interface.h" -#include "servers/arvr_server.h" +#include "xr_nodes.h" +#include "core/input/input_filter.h" +#include "servers/xr/xr_interface.h" +#include "servers/xr_server.h" //////////////////////////////////////////////////////////////////////////////////////////////////// -void ARVRCamera::_notification(int p_what) { +void XRCamera3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - // need to find our ARVROrigin parent and let it know we're its camera! - ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent()); - if (origin != NULL) { + // need to find our XROrigin3D parent and let it know we're its camera! + XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent()); + if (origin != nullptr) { origin->set_tracked_camera(this); } }; break; case NOTIFICATION_EXIT_TREE: { - // need to find our ARVROrigin parent and let it know we're no longer its camera! - ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent()); - if (origin != NULL) { + // need to find our XROrigin3D parent and let it know we're no longer its camera! + XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent()); + if (origin != nullptr) { origin->clear_tracked_camera_if(this); } }; break; }; }; -String ARVRCamera::get_configuration_warning() const { +String XRCamera3D::get_configuration_warning() const { if (!is_visible() || !is_inside_tree()) return String(); - // must be child node of ARVROrigin! - ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent()); - if (origin == NULL) { - return TTR("ARVRCamera must have an ARVROrigin node as its parent."); + // must be child node of XROrigin3D! + XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent()); + if (origin == nullptr) { + return TTR("XRCamera3D must have an XROrigin3D node as its parent."); }; return String(); }; -Vector3 ARVRCamera::project_local_ray_normal(const Point2 &p_pos) const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, Vector3()); +Vector3 XRCamera3D::project_local_ray_normal(const Point2 &p_pos) const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, Vector3()); - Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface(); - if (arvr_interface.is_null()) { + Ref<XRInterface> xr_interface = xr_server->get_primary_interface(); + if (xr_interface.is_null()) { // we might be in the editor or have VR turned off, just call superclass - return Camera::project_local_ray_normal(p_pos); + return Camera3D::project_local_ray_normal(p_pos); } ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); @@ -84,29 +84,29 @@ Vector3 ARVRCamera::project_local_ray_normal(const Point2 &p_pos) const { Vector2 cpos = get_viewport()->get_camera_coords(p_pos); Vector3 ray; - CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); + CameraMatrix cm = xr_interface->get_projection_for_eye(XRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); Vector2 screen_he = cm.get_viewport_half_extents(); ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_he.x, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_he.y, -get_znear()).normalized(); return ray; }; -Point2 ARVRCamera::unproject_position(const Vector3 &p_pos) const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, Vector2()); +Point2 XRCamera3D::unproject_position(const Vector3 &p_pos) const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, Vector2()); - Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface(); - if (arvr_interface.is_null()) { + Ref<XRInterface> xr_interface = xr_server->get_primary_interface(); + if (xr_interface.is_null()) { // we might be in the editor or have VR turned off, just call superclass - return Camera::unproject_position(p_pos); + return Camera3D::unproject_position(p_pos); } ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector2(), "Camera is not inside scene."); Size2 viewport_size = get_viewport()->get_visible_rect().size; - CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); + CameraMatrix cm = xr_interface->get_projection_for_eye(XRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); Plane p(get_camera_transform().xform_inv(p_pos), 1.0); @@ -120,22 +120,22 @@ Point2 ARVRCamera::unproject_position(const Vector3 &p_pos) const { return res; }; -Vector3 ARVRCamera::project_position(const Point2 &p_point, float p_z_depth) const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, Vector3()); +Vector3 XRCamera3D::project_position(const Point2 &p_point, float p_z_depth) const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, Vector3()); - Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface(); - if (arvr_interface.is_null()) { + Ref<XRInterface> xr_interface = xr_server->get_primary_interface(); + if (xr_interface.is_null()) { // we might be in the editor or have VR turned off, just call superclass - return Camera::project_position(p_point, p_z_depth); + return Camera3D::project_position(p_point, p_z_depth); } ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); Size2 viewport_size = get_viewport()->get_visible_rect().size; - CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); + CameraMatrix cm = xr_interface->get_projection_for_eye(XRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); Vector2 vp_he = cm.get_viewport_half_extents(); @@ -149,35 +149,35 @@ Vector3 ARVRCamera::project_position(const Point2 &p_point, float p_z_depth) con return get_camera_transform().xform(p); }; -Vector<Plane> ARVRCamera::get_frustum() const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, Vector<Plane>()); +Vector<Plane> XRCamera3D::get_frustum() const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, Vector<Plane>()); - Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface(); - if (arvr_interface.is_null()) { + Ref<XRInterface> xr_interface = xr_server->get_primary_interface(); + if (xr_interface.is_null()) { // we might be in the editor or have VR turned off, just call superclass - return Camera::get_frustum(); + return Camera3D::get_frustum(); } ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>()); Size2 viewport_size = get_viewport()->get_visible_rect().size; - CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); + CameraMatrix cm = xr_interface->get_projection_for_eye(XRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); return cm.get_projection_planes(get_camera_transform()); }; -ARVRCamera::ARVRCamera(){ +XRCamera3D::XRCamera3D(){ // nothing to do here yet for now.. }; -ARVRCamera::~ARVRCamera(){ +XRCamera3D::~XRCamera3D(){ // nothing to do here yet for now.. }; //////////////////////////////////////////////////////////////////////////////////////////////////// -void ARVRController::_notification(int p_what) { +void XRController3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { set_process_internal(true); @@ -186,13 +186,13 @@ void ARVRController::_notification(int p_what) { set_process_internal(false); }; break; case NOTIFICATION_INTERNAL_PROCESS: { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); // find the tracker for our controller - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); - if (tracker == NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, controller_id); + if (tracker == nullptr) { // this controller is currently turned off is_active = false; button_states = 0; @@ -206,7 +206,7 @@ void ARVRController::_notification(int p_what) { // check button states for (int i = 0; i < 16; i++) { bool was_pressed = (button_states & mask) == mask; - bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, i); + bool is_pressed = InputFilter::get_singleton()->is_joy_button_pressed(joy_id, i); if (!was_pressed && is_pressed) { emit_signal("button_pressed", i); @@ -236,63 +236,63 @@ void ARVRController::_notification(int p_what) { }; }; -void ARVRController::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_controller_id", "controller_id"), &ARVRController::set_controller_id); - ClassDB::bind_method(D_METHOD("get_controller_id"), &ARVRController::get_controller_id); +void XRController3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_controller_id", "controller_id"), &XRController3D::set_controller_id); + ClassDB::bind_method(D_METHOD("get_controller_id"), &XRController3D::get_controller_id); ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_id", PROPERTY_HINT_RANGE, "0,32,1"), "set_controller_id", "get_controller_id"); - ClassDB::bind_method(D_METHOD("get_controller_name"), &ARVRController::get_controller_name); + ClassDB::bind_method(D_METHOD("get_controller_name"), &XRController3D::get_controller_name); // passthroughs to information about our related joystick - ClassDB::bind_method(D_METHOD("get_joystick_id"), &ARVRController::get_joystick_id); - ClassDB::bind_method(D_METHOD("is_button_pressed", "button"), &ARVRController::is_button_pressed); - ClassDB::bind_method(D_METHOD("get_joystick_axis", "axis"), &ARVRController::get_joystick_axis); + ClassDB::bind_method(D_METHOD("get_joystick_id"), &XRController3D::get_joystick_id); + ClassDB::bind_method(D_METHOD("is_button_pressed", "button"), &XRController3D::is_button_pressed); + ClassDB::bind_method(D_METHOD("get_joystick_axis", "axis"), &XRController3D::get_joystick_axis); - ClassDB::bind_method(D_METHOD("get_is_active"), &ARVRController::get_is_active); - ClassDB::bind_method(D_METHOD("get_hand"), &ARVRController::get_hand); + ClassDB::bind_method(D_METHOD("get_is_active"), &XRController3D::get_is_active); + ClassDB::bind_method(D_METHOD("get_hand"), &XRController3D::get_hand); - ClassDB::bind_method(D_METHOD("get_rumble"), &ARVRController::get_rumble); - ClassDB::bind_method(D_METHOD("set_rumble", "rumble"), &ARVRController::set_rumble); + ClassDB::bind_method(D_METHOD("get_rumble"), &XRController3D::get_rumble); + ClassDB::bind_method(D_METHOD("set_rumble", "rumble"), &XRController3D::set_rumble); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rumble", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_rumble", "get_rumble"); ADD_PROPERTY_DEFAULT("rumble", 0.0); - ClassDB::bind_method(D_METHOD("get_mesh"), &ARVRController::get_mesh); + ClassDB::bind_method(D_METHOD("get_mesh"), &XRController3D::get_mesh); ADD_SIGNAL(MethodInfo("button_pressed", PropertyInfo(Variant::INT, "button"))); ADD_SIGNAL(MethodInfo("button_release", PropertyInfo(Variant::INT, "button"))); ADD_SIGNAL(MethodInfo("mesh_updated", PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"))); }; -void ARVRController::set_controller_id(int p_controller_id) { +void XRController3D::set_controller_id(int p_controller_id) { // We don't check any bounds here, this controller may not yet be active and just be a place holder until it is. // Note that setting this to 0 means this node is not bound to a controller yet. controller_id = p_controller_id; update_configuration_warning(); }; -int ARVRController::get_controller_id(void) const { +int XRController3D::get_controller_id(void) const { return controller_id; }; -String ARVRController::get_controller_name(void) const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, String()); +String XRController3D::get_controller_name(void) const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, String()); - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); - if (tracker == NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, controller_id); + if (tracker == nullptr) { return String("Not connected"); }; return tracker->get_name(); }; -int ARVRController::get_joystick_id() const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, 0); +int XRController3D::get_joystick_id() const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, 0); - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); - if (tracker == NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, controller_id); + if (tracker == nullptr) { // No tracker? no joystick id... (0 is our first joystick) return -1; }; @@ -300,77 +300,77 @@ int ARVRController::get_joystick_id() const { return tracker->get_joy_id(); }; -bool ARVRController::is_button_pressed(int p_button) const { +bool XRController3D::is_button_pressed(int p_button) const { int joy_id = get_joystick_id(); if (joy_id == -1) { return false; }; - return Input::get_singleton()->is_joy_button_pressed(joy_id, p_button); + return InputFilter::get_singleton()->is_joy_button_pressed(joy_id, p_button); }; -float ARVRController::get_joystick_axis(int p_axis) const { +float XRController3D::get_joystick_axis(int p_axis) const { int joy_id = get_joystick_id(); if (joy_id == -1) { return 0.0; }; - return Input::get_singleton()->get_joy_axis(joy_id, p_axis); + return InputFilter::get_singleton()->get_joy_axis(joy_id, p_axis); }; -real_t ARVRController::get_rumble() const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, 0.0); +real_t XRController3D::get_rumble() const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, 0.0); - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); - if (tracker == NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, controller_id); + if (tracker == nullptr) { return 0.0; }; return tracker->get_rumble(); }; -void ARVRController::set_rumble(real_t p_rumble) { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); +void XRController3D::set_rumble(real_t p_rumble) { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); - if (tracker != NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, controller_id); + if (tracker != nullptr) { tracker->set_rumble(p_rumble); }; }; -Ref<Mesh> ARVRController::get_mesh() const { +Ref<Mesh> XRController3D::get_mesh() const { return mesh; } -bool ARVRController::get_is_active() const { +bool XRController3D::get_is_active() const { return is_active; }; -ARVRPositionalTracker::TrackerHand ARVRController::get_hand() const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, ARVRPositionalTracker::TRACKER_HAND_UNKNOWN); +XRPositionalTracker::TrackerHand XRController3D::get_hand() const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, XRPositionalTracker::TRACKER_HAND_UNKNOWN); - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); - if (tracker == NULL) { - return ARVRPositionalTracker::TRACKER_HAND_UNKNOWN; + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, controller_id); + if (tracker == nullptr) { + return XRPositionalTracker::TRACKER_HAND_UNKNOWN; }; return tracker->get_hand(); }; -String ARVRController::get_configuration_warning() const { +String XRController3D::get_configuration_warning() const { if (!is_visible() || !is_inside_tree()) return String(); - // must be child node of ARVROrigin! - ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent()); - if (origin == NULL) { - return TTR("ARVRController must have an ARVROrigin node as its parent."); + // must be child node of XROrigin! + XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent()); + if (origin == nullptr) { + return TTR("XRController3D must have an XROrigin3D node as its parent."); }; if (controller_id == 0) { @@ -380,19 +380,19 @@ String ARVRController::get_configuration_warning() const { return String(); }; -ARVRController::ARVRController() { +XRController3D::XRController3D() { controller_id = 1; is_active = true; button_states = 0; }; -ARVRController::~ARVRController(){ +XRController3D::~XRController3D(){ // nothing to do here yet for now.. }; //////////////////////////////////////////////////////////////////////////////////////////////////// -void ARVRAnchor::_notification(int p_what) { +void XRAnchor3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { set_process_internal(true); @@ -401,13 +401,13 @@ void ARVRAnchor::_notification(int p_what) { set_process_internal(false); }; break; case NOTIFICATION_INTERNAL_PROCESS: { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); // find the tracker for our anchor - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_ANCHOR, anchor_id); - if (tracker == NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_ANCHOR, anchor_id); + if (tracker == nullptr) { // this anchor is currently not available is_active = false; } else { @@ -415,7 +415,7 @@ void ARVRAnchor::_notification(int p_what) { Transform transform; // we'll need our world_scale - real_t world_scale = arvr_server->get_world_scale(); + real_t world_scale = xr_server->get_world_scale(); // get our info from our tracker transform.basis = tracker->get_orientation(); @@ -427,7 +427,7 @@ void ARVRAnchor::_notification(int p_what) { transform.basis.orthonormalize(); // apply our reference frame and set our transform - set_transform(arvr_server->get_reference_frame() * transform); + set_transform(xr_server->get_reference_frame() * transform); // check for an updated mesh Ref<Mesh> trackerMesh = tracker->get_mesh(); @@ -442,62 +442,62 @@ void ARVRAnchor::_notification(int p_what) { }; }; -void ARVRAnchor::_bind_methods() { +void XRAnchor3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_anchor_id", "anchor_id"), &ARVRAnchor::set_anchor_id); - ClassDB::bind_method(D_METHOD("get_anchor_id"), &ARVRAnchor::get_anchor_id); + ClassDB::bind_method(D_METHOD("set_anchor_id", "anchor_id"), &XRAnchor3D::set_anchor_id); + ClassDB::bind_method(D_METHOD("get_anchor_id"), &XRAnchor3D::get_anchor_id); ADD_PROPERTY(PropertyInfo(Variant::INT, "anchor_id", PROPERTY_HINT_RANGE, "0,32,1"), "set_anchor_id", "get_anchor_id"); - ClassDB::bind_method(D_METHOD("get_anchor_name"), &ARVRAnchor::get_anchor_name); + ClassDB::bind_method(D_METHOD("get_anchor_name"), &XRAnchor3D::get_anchor_name); - ClassDB::bind_method(D_METHOD("get_is_active"), &ARVRAnchor::get_is_active); - ClassDB::bind_method(D_METHOD("get_size"), &ARVRAnchor::get_size); + ClassDB::bind_method(D_METHOD("get_is_active"), &XRAnchor3D::get_is_active); + ClassDB::bind_method(D_METHOD("get_size"), &XRAnchor3D::get_size); - ClassDB::bind_method(D_METHOD("get_plane"), &ARVRAnchor::get_plane); + ClassDB::bind_method(D_METHOD("get_plane"), &XRAnchor3D::get_plane); - ClassDB::bind_method(D_METHOD("get_mesh"), &ARVRAnchor::get_mesh); + ClassDB::bind_method(D_METHOD("get_mesh"), &XRAnchor3D::get_mesh); ADD_SIGNAL(MethodInfo("mesh_updated", PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"))); }; -void ARVRAnchor::set_anchor_id(int p_anchor_id) { +void XRAnchor3D::set_anchor_id(int p_anchor_id) { // We don't check any bounds here, this anchor may not yet be active and just be a place holder until it is. // Note that setting this to 0 means this node is not bound to an anchor yet. anchor_id = p_anchor_id; update_configuration_warning(); }; -int ARVRAnchor::get_anchor_id(void) const { +int XRAnchor3D::get_anchor_id(void) const { return anchor_id; }; -Vector3 ARVRAnchor::get_size() const { +Vector3 XRAnchor3D::get_size() const { return size; }; -String ARVRAnchor::get_anchor_name(void) const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, String()); +String XRAnchor3D::get_anchor_name(void) const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, String()); - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_ANCHOR, anchor_id); - if (tracker == NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_ANCHOR, anchor_id); + if (tracker == nullptr) { return String("Not connected"); }; return tracker->get_name(); }; -bool ARVRAnchor::get_is_active() const { +bool XRAnchor3D::get_is_active() const { return is_active; }; -String ARVRAnchor::get_configuration_warning() const { +String XRAnchor3D::get_configuration_warning() const { if (!is_visible() || !is_inside_tree()) return String(); - // must be child node of ARVROrigin! - ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent()); - if (origin == NULL) { - return TTR("ARVRAnchor must have an ARVROrigin node as its parent."); + // must be child node of XROrigin3D! + XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent()); + if (origin == nullptr) { + return TTR("XRAnchor3D must have an XROrigin3D node as its parent."); }; if (anchor_id == 0) { @@ -507,7 +507,7 @@ String ARVRAnchor::get_configuration_warning() const { return String(); }; -Plane ARVRAnchor::get_plane() const { +Plane XRAnchor3D::get_plane() const { Vector3 location = get_translation(); Basis orientation = get_transform().basis; @@ -516,67 +516,67 @@ Plane ARVRAnchor::get_plane() const { return plane; }; -Ref<Mesh> ARVRAnchor::get_mesh() const { +Ref<Mesh> XRAnchor3D::get_mesh() const { return mesh; } -ARVRAnchor::ARVRAnchor() { +XRAnchor3D::XRAnchor3D() { anchor_id = 1; is_active = true; }; -ARVRAnchor::~ARVRAnchor(){ +XRAnchor3D::~XRAnchor3D(){ // nothing to do here yet for now.. }; //////////////////////////////////////////////////////////////////////////////////////////////////// -String ARVROrigin::get_configuration_warning() const { +String XROrigin3D::get_configuration_warning() const { if (!is_visible() || !is_inside_tree()) return String(); - if (tracked_camera == NULL) - return TTR("ARVROrigin requires an ARVRCamera child node."); + if (tracked_camera == nullptr) + return TTR("XROrigin3D requires an XRCamera3D child node."); return String(); }; -void ARVROrigin::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_world_scale", "world_scale"), &ARVROrigin::set_world_scale); - ClassDB::bind_method(D_METHOD("get_world_scale"), &ARVROrigin::get_world_scale); +void XROrigin3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_world_scale", "world_scale"), &XROrigin3D::set_world_scale); + ClassDB::bind_method(D_METHOD("get_world_scale"), &XROrigin3D::get_world_scale); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "world_scale"), "set_world_scale", "get_world_scale"); }; -void ARVROrigin::set_tracked_camera(ARVRCamera *p_tracked_camera) { +void XROrigin3D::set_tracked_camera(XRCamera3D *p_tracked_camera) { tracked_camera = p_tracked_camera; }; -void ARVROrigin::clear_tracked_camera_if(ARVRCamera *p_tracked_camera) { +void XROrigin3D::clear_tracked_camera_if(XRCamera3D *p_tracked_camera) { if (tracked_camera == p_tracked_camera) { - tracked_camera = NULL; + tracked_camera = nullptr; }; }; -float ARVROrigin::get_world_scale() const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, 1.0); +float XROrigin3D::get_world_scale() const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, 1.0); - return arvr_server->get_world_scale(); + return xr_server->get_world_scale(); }; -void ARVROrigin::set_world_scale(float p_world_scale) { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); +void XROrigin3D::set_world_scale(float p_world_scale) { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); - arvr_server->set_world_scale(p_world_scale); + xr_server->set_world_scale(p_world_scale); }; -void ARVROrigin::_notification(int p_what) { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); +void XROrigin3D::_notification(int p_what) { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); switch (p_what) { case NOTIFICATION_ENTER_TREE: { @@ -587,13 +587,13 @@ void ARVROrigin::_notification(int p_what) { }; break; case NOTIFICATION_INTERNAL_PROCESS: { // set our world origin to our node transform - arvr_server->set_world_origin(get_global_transform()); + xr_server->set_world_origin(get_global_transform()); // check if we have a primary interface - Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface(); - if (arvr_interface.is_valid() && tracked_camera != NULL) { + Ref<XRInterface> xr_interface = xr_server->get_primary_interface(); + if (xr_interface.is_valid() && tracked_camera != nullptr) { // get our positioning transform for our headset - Transform t = arvr_interface->get_transform_for_eye(ARVRInterface::EYE_MONO, Transform()); + Transform t = xr_interface->get_transform_for_eye(XRInterface::EYE_MONO, Transform()); // now apply this to our camera tracked_camera->set_transform(t); @@ -603,19 +603,19 @@ void ARVROrigin::_notification(int p_what) { break; }; - // send our notification to all active ARVR interfaces, they may need to react to it also - for (int i = 0; i < arvr_server->get_interface_count(); i++) { - Ref<ARVRInterface> interface = arvr_server->get_interface(i); + // send our notification to all active XE interfaces, they may need to react to it also + for (int i = 0; i < xr_server->get_interface_count(); i++) { + Ref<XRInterface> interface = xr_server->get_interface(i); if (interface.is_valid() && interface->is_initialized()) { interface->notification(p_what); } } }; -ARVROrigin::ARVROrigin() { - tracked_camera = NULL; +XROrigin3D::XROrigin3D() { + tracked_camera = nullptr; }; -ARVROrigin::~ARVROrigin(){ +XROrigin3D::~XROrigin3D(){ // nothing to do here yet for now.. }; diff --git a/scene/3d/arvr_nodes.h b/scene/3d/xr_nodes.h index e968e33c9d..a2f16545d1 100644 --- a/scene/3d/arvr_nodes.h +++ b/scene/3d/xr_nodes.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* arvr_nodes.h */ +/* xr_nodes.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,24 +28,24 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef ARVR_NODES_H -#define ARVR_NODES_H +#ifndef XR_NODES_H +#define XR_NODES_H -#include "scene/3d/camera.h" -#include "scene/3d/spatial.h" +#include "scene/3d/camera_3d.h" +#include "scene/3d/node_3d.h" #include "scene/resources/mesh.h" -#include "servers/arvr/arvr_positional_tracker.h" +#include "servers/xr/xr_positional_tracker.h" /** @author Bastiaan Olij <mux213@gmail.com> **/ /* - ARVRCamera is a subclass of camera which will register itself with its parent ARVROrigin and as a result is automatically positioned + XRCamera is a subclass of camera which will register itself with its parent XROrigin and as a result is automatically positioned */ -class ARVRCamera : public Camera { +class XRCamera3D : public Camera3D { - GDCLASS(ARVRCamera, Camera); + GDCLASS(XRCamera3D, Camera3D); protected: void _notification(int p_what); @@ -58,19 +58,19 @@ public: virtual Vector3 project_position(const Point2 &p_point, float p_z_depth) const; virtual Vector<Plane> get_frustum() const; - ARVRCamera(); - ~ARVRCamera(); + XRCamera3D(); + ~XRCamera3D(); }; /* - ARVRController is a helper node that automatically updates its position based on tracker data. + XRController3D is a helper node that automatically updates its position based on tracker data. - It must be a child node of our ARVROrigin node + It must be a child node of our XROrigin node */ -class ARVRController : public Spatial { +class XRController3D : public Node3D { - GDCLASS(ARVRController, Spatial); + GDCLASS(XRController3D, Node3D); private: int controller_id; @@ -95,23 +95,23 @@ public: void set_rumble(real_t p_rumble); bool get_is_active() const; - ARVRPositionalTracker::TrackerHand get_hand() const; + XRPositionalTracker::TrackerHand get_hand() const; Ref<Mesh> get_mesh(void) const; String get_configuration_warning() const; - ARVRController(); - ~ARVRController(); + XRController3D(); + ~XRController3D(); }; /* - ARVRAnchor is a helper node that automatically updates its position based on anchor data, it represents a real world location. - It must be a child node of our ARVROrigin node + XRAnchor3D is a helper node that automatically updates its position based on anchor data, it represents a real world location. + It must be a child node of our XROrigin3D node */ -class ARVRAnchor : public Spatial { - GDCLASS(ARVRAnchor, Spatial); +class XRAnchor3D : public Node3D { + GDCLASS(XRAnchor3D, Node3D); private: int anchor_id; @@ -137,24 +137,24 @@ public: String get_configuration_warning() const; - ARVRAnchor(); - ~ARVRAnchor(); + XRAnchor3D(); + ~XRAnchor3D(); }; /* - ARVROrigin is special spatial node that acts as our origin point mapping our real world center of our tracking volume into our virtual world. + XROrigin3D is special spatial node that acts as our origin point mapping our real world center of our tracking volume into our virtual world. It is this point that you will move around the world as the player 'moves while standing still', i.e. the player moves through teleporting or controller inputs as opposed to physically moving. Our camera and controllers will always be child nodes and thus place relative to this origin point. - This node will automatically locate any camera child nodes and update its position while our ARVRController node will handle tracked controllers. + This node will automatically locate any camera child nodes and update its position while our XRController3D node will handle tracked controllers. */ -class ARVROrigin : public Spatial { +class XROrigin3D : public Node3D { - GDCLASS(ARVROrigin, Spatial); + GDCLASS(XROrigin3D, Node3D); private: - ARVRCamera *tracked_camera; + XRCamera3D *tracked_camera; protected: void _notification(int p_what); @@ -163,14 +163,14 @@ protected: public: String get_configuration_warning() const; - void set_tracked_camera(ARVRCamera *p_tracked_camera); - void clear_tracked_camera_if(ARVRCamera *p_tracked_camera); + void set_tracked_camera(XRCamera3D *p_tracked_camera); + void clear_tracked_camera_if(XRCamera3D *p_tracked_camera); float get_world_scale() const; void set_world_scale(float p_world_scale); - ARVROrigin(); - ~ARVROrigin(); + XROrigin3D(); + ~XROrigin3D(); }; -#endif /* ARVR_NODES_H */ +#endif /* XR_NODES_H */ diff --git a/scene/SCsub b/scene/SCsub index 1c5b87b87a..f9fc00f3f2 100644 --- a/scene/SCsub +++ b/scene/SCsub @@ -1,16 +1,16 @@ #!/usr/bin/env python -Import('env') +Import("env") env.scene_sources = [] # Thirdparty code thirdparty_dir = "#thirdparty/misc/" thirdparty_sources = [ - # C++ sources - "easing_equations.cpp", - # C sources - "mikktspace.c", + # C++ sources + "easing_equations.cpp", + # C sources + "mikktspace.c", ] thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] @@ -23,14 +23,14 @@ env.add_source_files(env.scene_sources, "*.cpp") # Chain load SCsubs -SConscript('main/SCsub') -SConscript('gui/SCsub') -SConscript('3d/SCsub') -SConscript('2d/SCsub') -SConscript('animation/SCsub') -SConscript('audio/SCsub') -SConscript('resources/SCsub') -SConscript('debugger/SCsub') +SConscript("main/SCsub") +SConscript("gui/SCsub") +SConscript("3d/SCsub") +SConscript("2d/SCsub") +SConscript("animation/SCsub") +SConscript("audio/SCsub") +SConscript("resources/SCsub") +SConscript("debugger/SCsub") # Build it all as a library diff --git a/scene/animation/SCsub b/scene/animation/SCsub index b01e2fd54d..fc61250247 100644 --- a/scene/animation/SCsub +++ b/scene/animation/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/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index 8ba7a38628..570735ad87 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -41,7 +41,7 @@ StringName AnimationNodeAnimation::get_animation() const { return animation; } -Vector<String> (*AnimationNodeAnimation::get_editable_animation_list)() = NULL; +Vector<String> (*AnimationNodeAnimation::get_editable_animation_list)() = nullptr; void AnimationNodeAnimation::get_parameter_list(List<PropertyInfo> *r_list) const { r_list->push_back(PropertyInfo(Variant::FLOAT, time, PROPERTY_HINT_NONE, "", 0)); diff --git a/scene/animation/animation_cache.cpp b/scene/animation/animation_cache.cpp index 9ed8155bdc..ab8be47b4d 100644 --- a/scene/animation/animation_cache.cpp +++ b/scene/animation/animation_cache.cpp @@ -94,19 +94,19 @@ void AnimationCache::_update_cache() { ERR_CONTINUE_MSG(animation->track_get_type(i) == Animation::TYPE_TRANSFORM, "Transform tracks can't have a subpath '" + np + "'."); } - Spatial *sp = Object::cast_to<Spatial>(node); + Node3D *sp = Object::cast_to<Node3D>(node); if (!sp) { path_cache.push_back(Path()); - ERR_CONTINUE_MSG(!sp, "Transform track not of type Spatial '" + np + "'."); + ERR_CONTINUE_MSG(!sp, "Transform track not of type Node3D '" + np + "'."); } if (np.get_subname_count() == 1) { StringName property = np.get_subname(0); String ps = property; - Skeleton *sk = Object::cast_to<Skeleton>(node); + Skeleton3D *sk = Object::cast_to<Skeleton3D>(node); if (!sk) { path_cache.push_back(Path()); @@ -287,7 +287,7 @@ void AnimationCache::set_all(float p_time, float p_delta) { if (!args.size()) { - call_track(i, name, NULL, 0, err); + call_track(i, name, nullptr, 0, err); } else { Vector<const Variant *> argptrs; @@ -332,7 +332,7 @@ void AnimationCache::set_root(Node *p_root) { AnimationCache::AnimationCache() { - root = NULL; + root = nullptr; cache_dirty = true; cache_valid = false; } diff --git a/scene/animation/animation_cache.h b/scene/animation/animation_cache.h index e73b9e2498..23312ca7ec 100644 --- a/scene/animation/animation_cache.h +++ b/scene/animation/animation_cache.h @@ -31,7 +31,7 @@ #ifndef ANIMATION_CACHE_H #define ANIMATION_CACHE_H -#include "scene/3d/skeleton.h" +#include "scene/3d/skeleton_3d.h" #include "scene/resources/animation.h" class AnimationCache : public Object { @@ -42,20 +42,20 @@ class AnimationCache : public Object { RES resource; Object *object; - Skeleton *skeleton; // haxor + Skeleton3D *skeleton; // haxor Node *node; - Spatial *spatial; + Node3D *spatial; int bone_idx; Vector<StringName> subpath; bool valid; Path() { - object = NULL; - skeleton = NULL; - node = NULL; + object = nullptr; + skeleton = nullptr; + node = nullptr; bone_idx = -1; valid = false; - spatial = NULL; + spatial = nullptr; } }; diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index ce1e75a61d..9f5e06c43d 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -225,7 +225,7 @@ bool AnimationNodeStateMachinePlayback::_travel(AnimationNodeStateMachine *p_sta } //find the last cost transition - List<int>::Element *least_cost_transition = NULL; + List<int>::Element *least_cost_transition = nullptr; float least_cost = 1e20; for (List<int>::Element *E = open_list.front(); E; E = E->next()) { @@ -516,6 +516,11 @@ AnimationNodeStateMachinePlayback::AnimationNodeStateMachinePlayback() { len_current = 0; fading_time = 0; stop_request = false; + len_total = 0.0; + pos_current = 0.0; + loops_current = 0; + fading_pos = 0.0; + start_request_travel = false; } /////////////////////////////////////////////////////// @@ -525,7 +530,7 @@ void AnimationNodeStateMachine::get_parameter_list(List<PropertyInfo> *r_list) c List<StringName> advance_conditions; for (int i = 0; i < transitions.size(); i++) { StringName ac = transitions[i].transition->get_advance_condition_name(); - if (ac != StringName() && advance_conditions.find(ac) == NULL) { + if (ac != StringName() && advance_conditions.find(ac) == nullptr) { advance_conditions.push_back(ac); } } diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 587485669e..946f759610 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -44,7 +44,7 @@ void AnimatedValuesBackup::update_skeletons() { for (int i = 0; i < entries.size(); i++) { if (entries[i].bone_idx != -1) { // 3D bone - Object::cast_to<Skeleton>(entries[i].object)->notification(Skeleton::NOTIFICATION_UPDATE_SKELETON); + Object::cast_to<Skeleton3D>(entries[i].object)->notification(Skeleton3D::NOTIFICATION_UPDATE_SKELETON); } else { Bone2D *bone = Object::cast_to<Bone2D>(entries[i].object); if (bone && bone->skeleton) { @@ -244,7 +244,7 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) { for (int i = 0; i < a->get_track_count(); i++) { - p_anim->node_cache.write[i] = NULL; + p_anim->node_cache.write[i] = nullptr; RES resource; Vector<StringName> leftover_path; Node *child = parent->get_node_and_resource(a->track_get_path(i), resource, leftover_path); @@ -252,9 +252,9 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) { ObjectID id = resource.is_valid() ? resource->get_instance_id() : child->get_instance_id(); int bone_idx = -1; - if (a->track_get_path(i).get_subname_count() == 1 && Object::cast_to<Skeleton>(child)) { + if (a->track_get_path(i).get_subname_count() == 1 && Object::cast_to<Skeleton3D>(child)) { - Skeleton *sk = Object::cast_to<Skeleton>(child); + Skeleton3D *sk = Object::cast_to<Skeleton3D>(child); bone_idx = sk->find_bone(a->track_get_path(i).get_subname(0)); if (bone_idx == -1) { @@ -283,9 +283,9 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) { // special cases and caches for transform tracks // cache spatial - p_anim->node_cache[i]->spatial = Object::cast_to<Spatial>(child); + p_anim->node_cache[i]->spatial = Object::cast_to<Node3D>(child); // cache skeleton - p_anim->node_cache[i]->skeleton = Object::cast_to<Skeleton>(child); + p_anim->node_cache[i]->skeleton = Object::cast_to<Skeleton3D>(child); if (p_anim->node_cache[i]->skeleton) { if (a->track_get_path(i).get_subname_count() == 1) { StringName bone_name = a->track_get_path(i).get_subname(0); @@ -293,13 +293,13 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) { p_anim->node_cache[i]->bone_idx = p_anim->node_cache[i]->skeleton->find_bone(bone_name); if (p_anim->node_cache[i]->bone_idx < 0) { // broken track (nonexistent bone) - p_anim->node_cache[i]->skeleton = NULL; - p_anim->node_cache[i]->spatial = NULL; + p_anim->node_cache[i]->skeleton = nullptr; + p_anim->node_cache[i]->spatial = nullptr; ERR_CONTINUE(p_anim->node_cache[i]->bone_idx < 0); } } else { // no property, just use spatialnode - p_anim->node_cache[i]->skeleton = NULL; + p_anim->node_cache[i]->skeleton = nullptr; } } } @@ -830,7 +830,7 @@ void AnimationPlayer::_animation_process2(float p_delta, bool p_started) { c.seeked = false; } - List<Blend>::Element *prev = NULL; + List<Blend>::Element *prev = nullptr; for (List<Blend>::Element *E = c.blend.back(); E; E = prev) { Blend &b = E->get(); @@ -950,13 +950,13 @@ void AnimationPlayer::_animation_process(float p_delta) { play(queued.front()->get()); String new_name = playback.assigned; queued.pop_front(); - if (end_notify) + if (end_notify || playback.seeked) emit_signal(SceneStringNames::get_singleton()->animation_changed, old, new_name); } else { //stop(); playing = false; _set_process(false); - if (end_notify) + if (end_notify || playback.seeked) emit_signal(SceneStringNames::get_singleton()->animation_finished, playback.assigned); } end_reached = false; @@ -1242,19 +1242,6 @@ void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float bool AnimationPlayer::is_playing() const { return playing; - /* - if (playback.current.from==NULL) - return false; - - float len=playback.current.from->animation->get_length(); - float pos = playback.current.pos; - bool loop=playback.current.from->animation->has_loop(); - if (!loop && pos >= len) { - return false; - }; - - return true; - */ } void AnimationPlayer::set_current_animation(const String &p_anim) { @@ -1296,7 +1283,7 @@ void AnimationPlayer::stop(bool p_reset) { Playback &c = playback; c.blend.clear(); if (p_reset) { - c.current.from = NULL; + c.current.from = nullptr; c.current.speed_scale = 1; c.current.pos = 0; } @@ -1612,7 +1599,7 @@ void AnimationPlayer::restore_animated_values(const AnimatedValuesBackup &p_back if (entry->bone_idx == -1) { entry->object->set_indexed(entry->subpath, entry->value); } else { - Object::cast_to<Skeleton>(entry->object)->set_bone_pose(entry->bone_idx, entry->value); + Object::cast_to<Skeleton3D>(entry->object)->set_bone_pose(entry->bone_idx, entry->value); } } } diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index 24f60363ed..c134aff707 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -32,8 +32,8 @@ #define ANIMATION_PLAYER_H #include "scene/2d/node_2d.h" -#include "scene/3d/skeleton.h" -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" +#include "scene/3d/skeleton_3d.h" #include "scene/resources/animation.h" #ifdef TOOLS_ENABLED @@ -90,9 +90,9 @@ private: uint32_t id; RES resource; Node *node; - Spatial *spatial; + Node3D *spatial; Node2D *node_2d; - Skeleton *skeleton; + Skeleton3D *skeleton; int bone_idx; // accumulated transforms @@ -118,9 +118,9 @@ private: Variant capture; PropertyAnim() : - owner(NULL), + owner(nullptr), special(SP_NONE), - object(NULL), + object(nullptr), accum_pass(0) {} }; @@ -135,9 +135,9 @@ private: uint64_t accum_pass; BezierAnim() : - owner(NULL), + owner(nullptr), bezier_accum(0.0), - object(NULL), + object(nullptr), accum_pass(0) {} }; @@ -145,10 +145,10 @@ private: TrackNodeCache() : id(0), - node(NULL), - spatial(NULL), - node_2d(NULL), - skeleton(NULL), + node(nullptr), + spatial(nullptr), + node_2d(nullptr), + skeleton(nullptr), bone_idx(-1), accum_pass(0), audio_playing(false), @@ -212,7 +212,7 @@ private: pos = 0; speed_scale = 1.0; - from = NULL; + from = nullptr; } }; diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 95afd74ee5..f8b3ca291b 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -128,8 +128,8 @@ float AnimationNode::_pre_process(const StringName &p_base_path, AnimationNode * float t = process(p_time, p_seek); - state = NULL; - parent = NULL; + state = nullptr; + parent = nullptr; base_path = StringName(); connections.clear(); @@ -164,7 +164,7 @@ float AnimationNode::blend_input(int p_input, float p_time, bool p_seek, float p //inputs.write[p_input].last_pass = state->last_pass; float activity = 0; - float ret = _blend_node(node_name, blend_tree->get_node_connection_array(node_name), NULL, node, p_time, p_seek, p_blend, p_filter, p_optimize, &activity); + float ret = _blend_node(node_name, blend_tree->get_node_connection_array(node_name), nullptr, node, p_time, p_seek, p_blend, p_filter, p_optimize, &activity); Vector<AnimationTree::Activity> *activity_ptr = state->tree->input_activity_map.getptr(base_path); @@ -202,7 +202,7 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin blendw[i] = 0.0; //all to zero by default } - const NodePath *K = NULL; + const NodePath *K = nullptr; while ((K = filter.next(K))) { if (!state->track_map.has(*K)) { continue; @@ -316,7 +316,7 @@ String AnimationNode::get_caption() const { void AnimationNode::add_input(const String &p_name) { //root nodes can't add inputs - ERR_FAIL_COND(Object::cast_to<AnimationRootNode>(this) != NULL); + ERR_FAIL_COND(Object::cast_to<AnimationRootNode>(this) != nullptr); Input input; ERR_FAIL_COND(p_name.find(".") != -1 || p_name.find("/") != -1); input.name = p_name; @@ -374,7 +374,7 @@ Array AnimationNode::_get_filters() const { Array paths; - const NodePath *K = NULL; + const NodePath *K = nullptr; while ((K = filter.next(K))) { paths.push_back(String(*K)); //use strings, so sorting is possible } @@ -453,8 +453,8 @@ void AnimationNode::_bind_methods() { AnimationNode::AnimationNode() { - state = NULL; - parent = NULL; + state = nullptr; + parent = nullptr; filter_enabled = false; } @@ -558,17 +558,17 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { NodePath path = anim->track_get_path(i); Animation::TrackType track_type = anim->track_get_type(i); - TrackCache *track = NULL; + TrackCache *track = nullptr; if (track_cache.has(path)) { track = track_cache.get(path); } //if not valid, delete track - if (track && (track->type != track_type || ObjectDB::get_instance(track->object_id) == NULL)) { + if (track && (track->type != track_type || ObjectDB::get_instance(track->object_id) == nullptr)) { playing_caches.erase(track); memdelete(track); track_cache.erase(path); - track = NULL; + track = nullptr; } if (!track) { @@ -605,7 +605,7 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { } break; case Animation::TYPE_TRANSFORM: { - Spatial *spatial = Object::cast_to<Spatial>(child); + Node3D *spatial = Object::cast_to<Node3D>(child); if (!spatial) { ERR_PRINT("AnimationTree: '" + String(E->get()) + "', transform track does not point to spatial: '" + String(path) + "'"); @@ -615,12 +615,12 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { TrackCacheTransform *track_xform = memnew(TrackCacheTransform); track_xform->spatial = spatial; - track_xform->skeleton = NULL; + track_xform->skeleton = nullptr; track_xform->bone_idx = -1; - if (path.get_subname_count() == 1 && Object::cast_to<Skeleton>(spatial)) { + if (path.get_subname_count() == 1 && Object::cast_to<Skeleton3D>(spatial)) { - Skeleton *sk = Object::cast_to<Skeleton>(spatial); + Skeleton3D *sk = Object::cast_to<Skeleton3D>(spatial); int bone_idx = sk->find_bone(path.get_subname(0)); if (bone_idx != -1) { @@ -700,7 +700,7 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { List<NodePath> to_delete; - const NodePath *K = NULL; + const NodePath *K = nullptr; while ((K = track_cache.next(K))) { TrackCache *tc = track_cache[*K]; if (tc->setup_pass != setup_pass) { @@ -717,7 +717,7 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { state.track_map.clear(); - K = NULL; + K = nullptr; int idx = 0; while ((K = track_cache.next(K))) { state.track_map[*K] = idx; @@ -733,7 +733,7 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { void AnimationTree::_clear_caches() { - const NodePath *K = NULL; + const NodePath *K = nullptr; while ((K = track_cache.next(K))) { memdelete(track_cache[*K]); } @@ -829,11 +829,11 @@ void AnimationTree::_process_graph(float p_delta) { if (started) { //if started, seek - root->_pre_process(SceneStringNames::get_singleton()->parameters_base_path, NULL, &state, 0, true, Vector<StringName>()); + root->_pre_process(SceneStringNames::get_singleton()->parameters_base_path, nullptr, &state, 0, true, Vector<StringName>()); started = false; } - root->_pre_process(SceneStringNames::get_singleton()->parameters_base_path, NULL, &state, p_delta, false, Vector<StringName>()); + root->_pre_process(SceneStringNames::get_singleton()->parameters_base_path, nullptr, &state, p_delta, false, Vector<StringName>()); } if (!state.valid) { @@ -1224,7 +1224,7 @@ void AnimationTree::_process_graph(float p_delta) { { // finally, set the tracks - const NodePath *K = NULL; + const NodePath *K = nullptr; while ((K = track_cache.next(K))) { TrackCache *track = track_cache[*K]; if (track->process_pass != process_pass) diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h index 742942fcda..d558170f23 100644 --- a/scene/animation/animation_tree.h +++ b/scene/animation/animation_tree.h @@ -32,8 +32,8 @@ #define ANIMATION_GRAPH_PLAYER_H #include "animation_player.h" -#include "scene/3d/skeleton.h" -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" +#include "scene/3d/skeleton_3d.h" #include "scene/resources/animation.h" class AnimationNodeBlendTree; @@ -101,7 +101,7 @@ public: Array _get_filters() const; void _set_filters(const Array &p_filters); friend class AnimationNodeBlendTree; - float _blend_node(const StringName &p_subpath, const Vector<StringName> &p_connections, AnimationNode *p_new_parent, Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter = FILTER_IGNORE, bool p_optimize = true, float *r_max = NULL); + float _blend_node(const StringName &p_subpath, const Vector<StringName> &p_connections, AnimationNode *p_new_parent, Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter = FILTER_IGNORE, bool p_optimize = true, float *r_max = nullptr); protected: void blend_animation(const StringName &p_animation, float p_time, float p_delta, bool p_seeked, float p_blend); @@ -186,14 +186,14 @@ private: root_motion = false; setup_pass = 0; process_pass = 0; - object = NULL; + object = nullptr; } virtual ~TrackCache() {} }; struct TrackCacheTransform : public TrackCache { - Spatial *spatial; - Skeleton *skeleton; + Node3D *spatial; + Skeleton3D *skeleton; int bone_idx; Vector3 loc; Quat rot; @@ -202,9 +202,9 @@ private: TrackCacheTransform() { type = Animation::TYPE_TRANSFORM; - spatial = NULL; + spatial = nullptr; bone_idx = -1; - skeleton = NULL; + skeleton = nullptr; } }; diff --git a/scene/animation/root_motion_view.cpp b/scene/animation/root_motion_view.cpp index ce9b8bd213..f993127b07 100644 --- a/scene/animation/root_motion_view.cpp +++ b/scene/animation/root_motion_view.cpp @@ -79,7 +79,7 @@ void RootMotionView::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { - VS::get_singleton()->immediate_set_material(immediate, StandardMaterial3D::get_material_rid_for_2d(false, true, false, false, false)); + RS::get_singleton()->immediate_set_material(immediate, StandardMaterial3D::get_material_rid_for_2d(false, true, false, false, false)); first = true; } @@ -122,11 +122,11 @@ void RootMotionView::_notification(int p_what) { } accumulated.origin.z = Math::fposmod(accumulated.origin.z, cell_size); - VS::get_singleton()->immediate_clear(immediate); + RS::get_singleton()->immediate_clear(immediate); int cells_in_radius = int((radius / cell_size) + 1.0); - VS::get_singleton()->immediate_begin(immediate, VS::PRIMITIVE_LINES); + RS::get_singleton()->immediate_begin(immediate, RS::PRIMITIVE_LINES); for (int i = -cells_in_radius; i < cells_in_radius; i++) { for (int j = -cells_in_radius; j < cells_in_radius; j++) { @@ -142,21 +142,21 @@ void RootMotionView::_notification(int p_what) { c_i.a *= MAX(0, 1.0 - from_i.length() / radius); c_j.a *= MAX(0, 1.0 - from_j.length() / radius); - VS::get_singleton()->immediate_color(immediate, c); - VS::get_singleton()->immediate_vertex(immediate, from); + RS::get_singleton()->immediate_color(immediate, c); + RS::get_singleton()->immediate_vertex(immediate, from); - VS::get_singleton()->immediate_color(immediate, c_i); - VS::get_singleton()->immediate_vertex(immediate, from_i); + RS::get_singleton()->immediate_color(immediate, c_i); + RS::get_singleton()->immediate_vertex(immediate, from_i); - VS::get_singleton()->immediate_color(immediate, c); - VS::get_singleton()->immediate_vertex(immediate, from); + RS::get_singleton()->immediate_color(immediate, c); + RS::get_singleton()->immediate_vertex(immediate, from); - VS::get_singleton()->immediate_color(immediate, c_j); - VS::get_singleton()->immediate_vertex(immediate, from_j); + RS::get_singleton()->immediate_color(immediate, c_j); + RS::get_singleton()->immediate_vertex(immediate, from_j); } } - VS::get_singleton()->immediate_end(immediate); + RS::get_singleton()->immediate_end(immediate); } } @@ -197,12 +197,12 @@ RootMotionView::RootMotionView() { radius = 10; cell_size = 1; set_process_internal(true); - immediate = VisualServer::get_singleton()->immediate_create(); + immediate = RenderingServer::get_singleton()->immediate_create(); set_base(immediate); color = Color(0.5, 0.5, 1.0); } RootMotionView::~RootMotionView() { set_base(RID()); - VisualServer::get_singleton()->free(immediate); + RenderingServer::get_singleton()->free(immediate); } diff --git a/scene/animation/root_motion_view.h b/scene/animation/root_motion_view.h index 42950dde42..c8a755a854 100644 --- a/scene/animation/root_motion_view.h +++ b/scene/animation/root_motion_view.h @@ -31,10 +31,10 @@ #ifndef ROOT_MOTION_VIEW_H #define ROOT_MOTION_VIEW_H -#include "scene/3d/visual_instance.h" +#include "scene/3d/visual_instance_3d.h" -class RootMotionView : public VisualInstance { - GDCLASS(RootMotionView, VisualInstance); +class RootMotionView : public VisualInstance3D { + GDCLASS(RootMotionView, VisualInstance3D); public: RID immediate; diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 628568afbb..bc28c38e2c 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -297,7 +297,7 @@ Variant Tween::_get_initial_val(const InterpolateData &p_data) const { case TARGETING_METHOD: { // Get the object that is being targeted Object *object = ObjectDB::get_instance(p_data.target_id); - ERR_FAIL_COND_V(object == NULL, p_data.initial_val); + ERR_FAIL_COND_V(object == nullptr, p_data.initial_val); // Are we targeting a property or a method? Variant initial_val; @@ -309,7 +309,7 @@ Variant Tween::_get_initial_val(const InterpolateData &p_data) const { } else { // Call the method and get the initial value from it Callable::CallError error; - initial_val = object->call(p_data.target_key[0], NULL, 0, error); + initial_val = object->call(p_data.target_key[0], nullptr, 0, error); ERR_FAIL_COND_V(error.error != Callable::CallError::CALL_OK, p_data.initial_val); } return initial_val; @@ -329,7 +329,7 @@ Variant Tween::_get_final_val(const InterpolateData &p_data) const { case FOLLOW_METHOD: { // Get the object that is being followed Object *target = ObjectDB::get_instance(p_data.target_id); - ERR_FAIL_COND_V(target == NULL, p_data.initial_val); + ERR_FAIL_COND_V(target == nullptr, p_data.initial_val); // We want to figure out the final value Variant final_val; @@ -341,7 +341,7 @@ Variant Tween::_get_final_val(const InterpolateData &p_data) const { } else { // We're looking at a method. Call the method on the target object Callable::CallError error; - final_val = target->call(p_data.target_key[0], NULL, 0, error); + final_val = target->call(p_data.target_key[0], nullptr, 0, error); ERR_FAIL_COND_V(error.error != Callable::CallError::CALL_OK, p_data.initial_val); } @@ -371,7 +371,7 @@ Variant &Tween::_get_delta_val(InterpolateData &p_data) { case FOLLOW_METHOD: { // We're following an object, so grab that instance Object *target = ObjectDB::get_instance(p_data.target_id); - ERR_FAIL_COND_V(target == NULL, p_data.initial_val); + ERR_FAIL_COND_V(target == nullptr, p_data.initial_val); // We want to figure out the final value Variant final_val; @@ -383,7 +383,7 @@ Variant &Tween::_get_delta_val(InterpolateData &p_data) { } else { // We're looking at a method. Call the method on the target object Callable::CallError error; - final_val = target->call(p_data.target_key[0], NULL, 0, error); + final_val = target->call(p_data.target_key[0], nullptr, 0, error); ERR_FAIL_COND_V(error.error != Callable::CallError::CALL_OK, p_data.initial_val); } @@ -607,7 +607,7 @@ bool Tween::_apply_tween_value(InterpolateData &p_data, Variant &value) { // Get the object we want to apply the new value to Object *object = ObjectDB::get_instance(p_data.id); - ERR_FAIL_COND_V(object == NULL, false); + ERR_FAIL_COND_V(object == nullptr, false); // What kind of data are we mutating? switch (p_data.type) { @@ -634,7 +634,7 @@ bool Tween::_apply_tween_value(InterpolateData &p_data, Variant &value) { object->call(p_data.key[0], (const Variant **)arg, 1, error); } else { // Don't pass any argument - object->call(p_data.key[0], NULL, 0, error); + object->call(p_data.key[0], nullptr, 0, error); } // Did we get an error from the function call? @@ -700,7 +700,7 @@ void Tween::_tween_process(float p_delta) { // Get the target object for this interpolation Object *object = ObjectDB::get_instance(data.id); - if (object == NULL) + if (object == nullptr) continue; // Are we still delaying this tween? @@ -860,7 +860,7 @@ void Tween::reset(Object *p_object, StringName p_key) { // Get the target object InterpolateData &data = E->get(); Object *object = ObjectDB::get_instance(data.id); - if (object == NULL) + if (object == nullptr) continue; // Do we have the correct object and key? @@ -901,7 +901,7 @@ void Tween::stop(Object *p_object, StringName p_key) { // Get the object the tween is targeting InterpolateData &data = E->get(); Object *object = ObjectDB::get_instance(data.id); - if (object == NULL) + if (object == nullptr) continue; // Is this the correct object and does it have the given key? @@ -937,7 +937,7 @@ void Tween::resume(Object *p_object, StringName p_key) { // Grab the object InterpolateData &data = E->get(); Object *object = ObjectDB::get_instance(data.id); - if (object == NULL) + if (object == nullptr) continue; // If the object and string key match, activate it @@ -975,7 +975,7 @@ void Tween::remove(Object *p_object, StringName p_key) { // Get the target object InterpolateData &data = E->get(); Object *object = ObjectDB::get_instance(data.id); - if (object == NULL) + if (object == nullptr) continue; // If the target object and string key match, queue it for removal @@ -1264,7 +1264,7 @@ void Tween::_build_interpolation(InterpolateType p_interpolation_type, Object *p // Validate and apply interpolation data // Give it the object - ERR_FAIL_COND_MSG(p_object == NULL, "Invalid object provided to Tween."); + ERR_FAIL_COND_MSG(p_object == nullptr, "Invalid object provided to Tween."); data.id = p_object->get_instance_id(); // Validate the initial and final values @@ -1335,7 +1335,7 @@ void Tween::interpolate_property(Object *p_object, NodePath p_property, Variant if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t(); // Build the interpolation data - _build_interpolation(INTER_PROPERTY, p_object, &p_property, NULL, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); + _build_interpolation(INTER_PROPERTY, p_object, &p_property, nullptr, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); } void Tween::interpolate_method(Object *p_object, StringName p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { @@ -1350,7 +1350,7 @@ void Tween::interpolate_method(Object *p_object, StringName p_method, Variant p_ if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t(); // Build the interpolation data - _build_interpolation(INTER_METHOD, p_object, NULL, &p_method, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); + _build_interpolation(INTER_METHOD, p_object, nullptr, &p_method, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); } void Tween::interpolate_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE) { @@ -1361,7 +1361,7 @@ void Tween::interpolate_callback(Object *p_object, real_t p_duration, String p_c } // Check that the target object is valid - ERR_FAIL_COND(p_object == NULL); + ERR_FAIL_COND(p_object == nullptr); // Duration cannot be negative ERR_FAIL_COND(p_duration < 0); @@ -1418,7 +1418,7 @@ void Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, S } // Check that the target object is valid - ERR_FAIL_COND(p_object == NULL); + ERR_FAIL_COND(p_object == nullptr); // No negative durations allowed ERR_FAIL_COND(p_duration < 0); @@ -1486,8 +1486,8 @@ void Tween::follow_property(Object *p_object, NodePath p_property, Variant p_ini if (p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t(); // Confirm the source and target objects are valid - ERR_FAIL_COND(p_object == NULL); - ERR_FAIL_COND(p_target == NULL); + ERR_FAIL_COND(p_object == nullptr); + ERR_FAIL_COND(p_target == nullptr); // No negative durations ERR_FAIL_COND(p_duration < 0); @@ -1547,8 +1547,8 @@ void Tween::follow_method(Object *p_object, StringName p_method, Variant p_initi if (p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t(); // Verify the source and target objects are valid - ERR_FAIL_COND(p_object == NULL); - ERR_FAIL_COND(p_target == NULL); + ERR_FAIL_COND(p_object == nullptr); + ERR_FAIL_COND(p_target == nullptr); // No negative durations ERR_FAIL_COND(p_duration < 0); @@ -1566,7 +1566,7 @@ void Tween::follow_method(Object *p_object, StringName p_method, Variant p_initi // Call the method to get the target value Callable::CallError error; - Variant target_val = p_target->call(p_target_method, NULL, 0, error); + Variant target_val = p_target->call(p_target_method, nullptr, 0, error); ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK); // Convert target INT values to FLOAT as they are better for interpolation @@ -1610,8 +1610,8 @@ void Tween::targeting_property(Object *p_object, NodePath p_property, Object *p_ if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t(); // Verify both objects are valid - ERR_FAIL_COND(p_object == NULL); - ERR_FAIL_COND(p_initial == NULL); + ERR_FAIL_COND(p_object == nullptr); + ERR_FAIL_COND(p_initial == nullptr); // No negative durations ERR_FAIL_COND(p_duration < 0); @@ -1676,8 +1676,8 @@ void Tween::targeting_method(Object *p_object, StringName p_method, Object *p_in if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t(); // Make sure the given objects are valid - ERR_FAIL_COND(p_object == NULL); - ERR_FAIL_COND(p_initial == NULL); + ERR_FAIL_COND(p_object == nullptr); + ERR_FAIL_COND(p_initial == nullptr); // No negative durations ERR_FAIL_COND(p_duration < 0); @@ -1695,7 +1695,7 @@ void Tween::targeting_method(Object *p_object, StringName p_method, Object *p_in // Call the method to get the initial value Callable::CallError error; - Variant initial_val = p_initial->call(p_initial_method, NULL, 0, error); + Variant initial_val = p_initial->call(p_initial_method, nullptr, 0, error); ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK); // Convert initial INT values to FLOAT as they aer better for interpolation diff --git a/scene/audio/SCsub b/scene/audio/SCsub index b01e2fd54d..fc61250247 100644 --- a/scene/audio/SCsub +++ b/scene/audio/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/audio/audio_stream_player.cpp b/scene/audio/audio_stream_player.cpp index 2582bab200..f612944a62 100644 --- a/scene/audio/audio_stream_player.cpp +++ b/scene/audio/audio_stream_player.cpp @@ -36,7 +36,7 @@ void AudioStreamPlayer::_mix_to_bus(const AudioFrame *p_frames, int p_amount) { int bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus); - AudioFrame *targets[4] = { NULL, NULL, NULL, NULL }; + AudioFrame *targets[4] = { nullptr, nullptr, nullptr, nullptr }; if (AudioServer::get_singleton()->get_speaker_mode() == AudioServer::SPEAKER_MODE_STEREO) { targets[0] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 0); diff --git a/scene/debugger/SCsub b/scene/debugger/SCsub index b01e2fd54d..fc61250247 100644 --- a/scene/debugger/SCsub +++ b/scene/debugger/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/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index 7a184adc55..8cb63c4ab5 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -34,13 +34,13 @@ #include "core/io/marshalls.h" #include "core/script_language.h" #include "scene/main/scene_tree.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" #include "scene/resources/packed_scene.h" void SceneDebugger::initialize() { #ifdef DEBUG_ENABLED LiveEditor::singleton = memnew(LiveEditor); - EngineDebugger::register_message_capture("scene", EngineDebugger::Capture(NULL, SceneDebugger::parse_message)); + EngineDebugger::register_message_capture("scene", EngineDebugger::Capture(nullptr, SceneDebugger::parse_message)); #endif } @@ -51,7 +51,7 @@ void SceneDebugger::deinitialize() { if (EngineDebugger::has_capture("scene")) EngineDebugger::unregister_message_capture("scene"); memdelete(LiveEditor::singleton); - LiveEditor::singleton = NULL; + LiveEditor::singleton = nullptr; } #endif } @@ -279,7 +279,7 @@ SceneDebuggerObject::SceneDebuggerObject(ObjectID p_id) { } } else if (Script *s = Object::cast_to<Script>(obj)) { // Add script constants (no instance). - _parse_script_properties(s, NULL); + _parse_script_properties(s, nullptr); } // Add base object properties. @@ -373,7 +373,7 @@ void SceneDebuggerObject::serialize(Array &r_arr, int p_max_size) { var = res->get_path(); } else { //only send information that can be sent.. int len = 0; //test how big is this to encode - encode_variant(var, NULL, len); + encode_variant(var, nullptr, len); if (len > p_max_size) { //limit to max size hint = PROPERTY_HINT_OBJECT_TOO_BIG; hint_string = ""; @@ -478,7 +478,7 @@ void SceneDebuggerTree::deserialize(const Array &p_arr) { } /// LiveEditor -LiveEditor *LiveEditor::singleton = NULL; +LiveEditor *LiveEditor::singleton = nullptr; LiveEditor *LiveEditor::get_singleton() { return singleton; } @@ -515,7 +515,7 @@ void LiveEditor::_node_set_func(int p_id, const StringName &p_prop, const Varian return; NodePath np = live_edit_node_path_cache[p_id]; - Node *base = NULL; + Node *base = nullptr; if (scene_tree->root->has_node(live_edit_root)) base = scene_tree->root->get_node(live_edit_root); @@ -553,7 +553,7 @@ void LiveEditor::_node_call_func(int p_id, const StringName &p_method, VARIANT_A return; NodePath np = live_edit_node_path_cache[p_id]; - Node *base = NULL; + Node *base = nullptr; if (scene_tree->root->has_node(live_edit_root)) base = scene_tree->root->get_node(live_edit_root); @@ -626,7 +626,7 @@ void LiveEditor::_create_node_func(const NodePath &p_parent, const String &p_typ if (!scene_tree) return; - Node *base = NULL; + Node *base = nullptr; if (scene_tree->root->has_node(live_edit_root)) base = scene_tree->root->get_node(live_edit_root); @@ -664,7 +664,7 @@ void LiveEditor::_instance_node_func(const NodePath &p_parent, const String &p_p if (!ps.is_valid()) return; - Node *base = NULL; + Node *base = nullptr; if (scene_tree->root->has_node(live_edit_root)) base = scene_tree->root->get_node(live_edit_root); @@ -697,7 +697,7 @@ void LiveEditor::_remove_node_func(const NodePath &p_at) { if (!scene_tree) return; - Node *base = NULL; + Node *base = nullptr; if (scene_tree->root->has_node(live_edit_root)) base = scene_tree->root->get_node(live_edit_root); @@ -728,7 +728,7 @@ void LiveEditor::_remove_and_keep_node_func(const NodePath &p_at, ObjectID p_kee if (!scene_tree) return; - Node *base = NULL; + Node *base = nullptr; if (scene_tree->root->has_node(live_edit_root)) base = scene_tree->root->get_node(live_edit_root); @@ -762,7 +762,7 @@ void LiveEditor::_restore_node_func(ObjectID p_id, const NodePath &p_at, int p_a if (!scene_tree) return; - Node *base = NULL; + Node *base = nullptr; if (scene_tree->root->has_node(live_edit_root)) base = scene_tree->root->get_node(live_edit_root); @@ -808,7 +808,7 @@ void LiveEditor::_duplicate_node_func(const NodePath &p_at, const String &p_new_ if (!scene_tree) return; - Node *base = NULL; + Node *base = nullptr; if (scene_tree->root->has_node(live_edit_root)) base = scene_tree->root->get_node(live_edit_root); @@ -841,7 +841,7 @@ void LiveEditor::_reparent_node_func(const NodePath &p_at, const NodePath &p_new if (!scene_tree) return; - Node *base = NULL; + Node *base = nullptr; if (scene_tree->root->has_node(live_edit_root)) base = scene_tree->root->get_node(live_edit_root); diff --git a/scene/gui/SCsub b/scene/gui/SCsub index b01e2fd54d..fc61250247 100644 --- a/scene/gui/SCsub +++ b/scene/gui/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/gui/base_button.cpp b/scene/gui/base_button.cpp index b2020d44e8..1cdc6f8057 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -31,7 +31,7 @@ #include "base_button.h" #include "core/os/keyboard.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" #include "scene/scene_string_names.h" void BaseButton::_unpress_group() { @@ -357,9 +357,6 @@ void BaseButton::_unhandled_input(Ref<InputEvent> p_event) { if (!is_disabled() && is_visible_in_tree() && !p_event->is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) { - if (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this)) - return; //ignore because of modal window - on_action_event(p_event); } } @@ -501,7 +498,7 @@ BaseButton *ButtonGroup::get_pressed_button() { return E->get(); } - return NULL; + return nullptr; } void ButtonGroup::_bind_methods() { diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index e0bfeac9f7..0da6e0fdfa 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -45,7 +45,7 @@ void BoxContainer::_resort() { Size2i new_size = get_size(); - int sep = get_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer"); + int sep = get_theme_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer"); bool first = true; int children_count = 0; @@ -206,7 +206,7 @@ Size2 BoxContainer::get_minimum_size() const { /* Calculate MINIMUM SIZE */ Size2i minimum; - int sep = get_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer"); + int sep = get_theme_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer"); bool first = true; @@ -310,7 +310,7 @@ MarginContainer *VBoxContainer::add_margin_child(const String &p_label, Control l->set_text(p_label); add_child(l); MarginContainer *mc = memnew(MarginContainer); - mc->add_constant_override("margin_left", 0); + mc->add_theme_constant_override("margin_left", 0); mc->add_child(p_control); add_child(mc); if (p_expand) diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index 784d298bff..1f8487c173 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -31,18 +31,18 @@ #include "button.h" #include "core/translation.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" Size2 Button::get_minimum_size() const { - Size2 minsize = get_font("font")->get_string_size(xl_text); + Size2 minsize = get_theme_font("font")->get_string_size(xl_text); if (clip_text) minsize.width = 0; if (!expand_icon) { Ref<Texture2D> _icon; - if (icon.is_null() && has_icon("icon")) - _icon = Control::get_icon("icon"); + if (icon.is_null() && has_theme_icon("icon")) + _icon = Control::get_theme_icon("icon"); else _icon = icon; @@ -51,11 +51,11 @@ Size2 Button::get_minimum_size() const { minsize.height = MAX(minsize.height, _icon->get_height()); minsize.width += _icon->get_width(); if (xl_text != "") - minsize.width += get_constant("hseparation"); + minsize.width += get_theme_constant("hseparation"); } } - return get_stylebox("normal")->get_minimum_size() + minsize; + return get_theme_stylebox("normal")->get_minimum_size() + minsize; } void Button::_set_internal_margin(Margin p_margin, float p_value) { @@ -79,30 +79,30 @@ void Button::_notification(int p_what) { Color color; Color color_icon(1, 1, 1, 1); - Ref<StyleBox> style = get_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox("normal"); switch (get_draw_mode()) { case DRAW_NORMAL: { - style = get_stylebox("normal"); + style = get_theme_stylebox("normal"); if (!flat) style->draw(ci, Rect2(Point2(0, 0), size)); - color = get_color("font_color"); - if (has_color("icon_color_normal")) - color_icon = get_color("icon_color_normal"); + color = get_theme_color("font_color"); + if (has_theme_color("icon_color_normal")) + color_icon = get_theme_color("icon_color_normal"); } break; case DRAW_HOVER_PRESSED: { - if (has_stylebox("hover_pressed") && has_stylebox_override("hover_pressed")) { - style = get_stylebox("hover_pressed"); + if (has_theme_stylebox("hover_pressed") && has_theme_stylebox_override("hover_pressed")) { + style = get_theme_stylebox("hover_pressed"); if (!flat) style->draw(ci, Rect2(Point2(0, 0), size)); - if (has_color("font_color_hover_pressed")) - color = get_color("font_color_hover_pressed"); + if (has_theme_color("font_color_hover_pressed")) + color = get_theme_color("font_color_hover_pressed"); else - color = get_color("font_color"); - if (has_color("icon_color_hover_pressed")) - color_icon = get_color("icon_color_hover_pressed"); + color = get_theme_color("font_color"); + if (has_theme_color("icon_color_hover_pressed")) + color_icon = get_theme_color("icon_color_hover_pressed"); break; } @@ -110,49 +110,49 @@ void Button::_notification(int p_what) { } case DRAW_PRESSED: { - style = get_stylebox("pressed"); + style = get_theme_stylebox("pressed"); if (!flat) style->draw(ci, Rect2(Point2(0, 0), size)); - if (has_color("font_color_pressed")) - color = get_color("font_color_pressed"); + if (has_theme_color("font_color_pressed")) + color = get_theme_color("font_color_pressed"); else - color = get_color("font_color"); - if (has_color("icon_color_pressed")) - color_icon = get_color("icon_color_pressed"); + color = get_theme_color("font_color"); + if (has_theme_color("icon_color_pressed")) + color_icon = get_theme_color("icon_color_pressed"); } break; case DRAW_HOVER: { - style = get_stylebox("hover"); + style = get_theme_stylebox("hover"); if (!flat) style->draw(ci, Rect2(Point2(0, 0), size)); - color = get_color("font_color_hover"); - if (has_color("icon_color_hover")) - color_icon = get_color("icon_color_hover"); + color = get_theme_color("font_color_hover"); + if (has_theme_color("icon_color_hover")) + color_icon = get_theme_color("icon_color_hover"); } break; case DRAW_DISABLED: { - style = get_stylebox("disabled"); + style = get_theme_stylebox("disabled"); if (!flat) style->draw(ci, Rect2(Point2(0, 0), size)); - color = get_color("font_color_disabled"); - if (has_color("icon_color_disabled")) - color_icon = get_color("icon_color_disabled"); + color = get_theme_color("font_color_disabled"); + if (has_theme_color("icon_color_disabled")) + color_icon = get_theme_color("icon_color_disabled"); } break; } if (has_focus()) { - Ref<StyleBox> style2 = get_stylebox("focus"); + Ref<StyleBox> style2 = get_theme_stylebox("focus"); style2->draw(ci, Rect2(Point2(), size)); } - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); Ref<Texture2D> _icon; - if (icon.is_null() && has_icon("icon")) - _icon = Control::get_icon("icon"); + if (icon.is_null() && has_theme_icon("icon")) + _icon = Control::get_theme_icon("icon"); else _icon = icon; @@ -166,14 +166,14 @@ void Button::_notification(int p_what) { float icon_ofs_region = 0; if (_internal_margin[MARGIN_LEFT] > 0) { - icon_ofs_region = _internal_margin[MARGIN_LEFT] + get_constant("hseparation"); + icon_ofs_region = _internal_margin[MARGIN_LEFT] + get_theme_constant("hseparation"); } if (expand_icon) { Size2 _size = get_size() - style->get_offset() * 2; - _size.width -= get_constant("hseparation") + icon_ofs_region; + _size.width -= get_theme_constant("hseparation") + icon_ofs_region; if (!clip_text) - _size.width -= get_font("font")->get_string_size(xl_text).width; + _size.width -= get_theme_font("font")->get_string_size(xl_text).width; float icon_width = _icon->get_width() * _size.height / _icon->get_height(); float icon_height = _size.height; @@ -188,13 +188,13 @@ void Button::_notification(int p_what) { } } - Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + get_constant("hseparation"), 0) : Point2(); + Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + get_theme_constant("hseparation"), 0) : Point2(); int text_clip = size.width - style->get_minimum_size().width - icon_ofs.width; if (_internal_margin[MARGIN_LEFT] > 0) { - text_clip -= _internal_margin[MARGIN_LEFT] + get_constant("hseparation"); + text_clip -= _internal_margin[MARGIN_LEFT] + get_theme_constant("hseparation"); } if (_internal_margin[MARGIN_RIGHT] > 0) { - text_clip -= _internal_margin[MARGIN_RIGHT] + get_constant("hseparation"); + text_clip -= _internal_margin[MARGIN_RIGHT] + get_theme_constant("hseparation"); } Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - font->get_string_size(xl_text) - Point2(_internal_margin[MARGIN_RIGHT] - _internal_margin[MARGIN_LEFT], 0)) / 2.0; @@ -202,7 +202,7 @@ void Button::_notification(int p_what) { switch (align) { case ALIGN_LEFT: { if (_internal_margin[MARGIN_LEFT] > 0) { - text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x + _internal_margin[MARGIN_LEFT] + get_constant("hseparation"); + text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x + _internal_margin[MARGIN_LEFT] + get_theme_constant("hseparation"); } else { text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x; } @@ -216,7 +216,7 @@ void Button::_notification(int p_what) { } break; case ALIGN_RIGHT: { if (_internal_margin[MARGIN_RIGHT] > 0) { - text_ofs.x = size.x - style->get_margin(MARGIN_RIGHT) - font->get_string_size(xl_text).x - _internal_margin[MARGIN_RIGHT] - get_constant("hseparation"); + text_ofs.x = size.x - style->get_margin(MARGIN_RIGHT) - font->get_string_size(xl_text).x - _internal_margin[MARGIN_RIGHT] - get_theme_constant("hseparation"); } else { text_ofs.x = size.x - style->get_margin(MARGIN_RIGHT) - font->get_string_size(xl_text).x; } diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp index 89bd8ab0dd..470450e3ed 100644 --- a/scene/gui/check_box.cpp +++ b/scene/gui/check_box.cpp @@ -30,13 +30,13 @@ #include "check_box.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" Size2 CheckBox::get_icon_size() const { - Ref<Texture2D> checked = Control::get_icon("checked"); - Ref<Texture2D> unchecked = Control::get_icon("unchecked"); - Ref<Texture2D> radio_checked = Control::get_icon("radio_checked"); - Ref<Texture2D> radio_unchecked = Control::get_icon("radio_unchecked"); + Ref<Texture2D> checked = Control::get_theme_icon("checked"); + Ref<Texture2D> unchecked = Control::get_theme_icon("unchecked"); + Ref<Texture2D> radio_checked = Control::get_theme_icon("radio_checked"); + Ref<Texture2D> radio_unchecked = Control::get_theme_icon("radio_unchecked"); Size2 tex_size = Size2(0, 0); if (!checked.is_null()) @@ -56,9 +56,9 @@ Size2 CheckBox::get_minimum_size() const { Size2 tex_size = get_icon_size(); minsize.width += tex_size.width; if (get_text().length() > 0) { - minsize.width += get_constant("hseparation"); + minsize.width += get_theme_constant("hseparation"); } - Ref<StyleBox> sb = get_stylebox("normal"); + Ref<StyleBox> sb = get_theme_stylebox("normal"); minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(MARGIN_TOP) + sb->get_margin(MARGIN_BOTTOM)); return minsize; @@ -73,13 +73,13 @@ void CheckBox::_notification(int p_what) { RID ci = get_canvas_item(); - Ref<Texture2D> on = Control::get_icon(is_radio() ? "radio_checked" : "checked"); - Ref<Texture2D> off = Control::get_icon(is_radio() ? "radio_unchecked" : "unchecked"); - Ref<StyleBox> sb = get_stylebox("normal"); + Ref<Texture2D> on = Control::get_theme_icon(is_radio() ? "radio_checked" : "checked"); + Ref<Texture2D> off = Control::get_theme_icon(is_radio() ? "radio_unchecked" : "unchecked"); + Ref<StyleBox> sb = get_theme_stylebox("normal"); Vector2 ofs; ofs.x = sb->get_margin(MARGIN_LEFT); - ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_constant("check_vadjust"); + ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant("check_vadjust"); if (is_pressed()) on->draw(ci, ofs); diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp index 0b093ce850..96484424f8 100644 --- a/scene/gui/check_button.cpp +++ b/scene/gui/check_button.cpp @@ -31,12 +31,12 @@ #include "check_button.h" #include "core/print_string.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" Size2 CheckButton::get_icon_size() const { - Ref<Texture2D> on = Control::get_icon(is_disabled() ? "on_disabled" : "on"); - Ref<Texture2D> off = Control::get_icon(is_disabled() ? "off_disabled" : "off"); + Ref<Texture2D> on = Control::get_theme_icon(is_disabled() ? "on_disabled" : "on"); + Ref<Texture2D> off = Control::get_theme_icon(is_disabled() ? "off_disabled" : "off"); Size2 tex_size = Size2(0, 0); if (!on.is_null()) tex_size = Size2(on->get_width(), on->get_height()); @@ -52,8 +52,8 @@ Size2 CheckButton::get_minimum_size() const { Size2 tex_size = get_icon_size(); minsize.width += tex_size.width; if (get_text().length() > 0) - minsize.width += get_constant("hseparation"); - Ref<StyleBox> sb = get_stylebox("normal"); + minsize.width += get_theme_constant("hseparation"); + Ref<StyleBox> sb = get_theme_stylebox("normal"); minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(MARGIN_TOP) + sb->get_margin(MARGIN_BOTTOM)); return minsize; @@ -68,15 +68,15 @@ void CheckButton::_notification(int p_what) { RID ci = get_canvas_item(); - Ref<Texture2D> on = Control::get_icon(is_disabled() ? "on_disabled" : "on"); - Ref<Texture2D> off = Control::get_icon(is_disabled() ? "off_disabled" : "off"); + Ref<Texture2D> on = Control::get_theme_icon(is_disabled() ? "on_disabled" : "on"); + Ref<Texture2D> off = Control::get_theme_icon(is_disabled() ? "off_disabled" : "off"); - Ref<StyleBox> sb = get_stylebox("normal"); + Ref<StyleBox> sb = get_theme_stylebox("normal"); Vector2 ofs; Size2 tex_size = get_icon_size(); ofs.x = get_size().width - (tex_size.width + sb->get_margin(MARGIN_RIGHT)); - ofs.y = (get_size().height - tex_size.height) / 2 + get_constant("check_vadjust"); + ofs.y = (get_size().height - tex_size.height) / 2 + get_theme_constant("check_vadjust"); if (is_pressed()) on->draw(ci, ofs); diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index cbbad79811..5e0f4c91e8 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -30,7 +30,7 @@ #include "color_picker.h" -#include "core/os/input.h" +#include "core/input/input_filter.h" #include "core/os/keyboard.h" #include "core/os/os.h" @@ -38,22 +38,22 @@ #include "editor/editor_scale.h" #include "editor/editor_settings.h" #endif -#include "scene/main/viewport.h" +#include "scene/main/window.h" void ColorPicker::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: { - btn_pick->set_icon(get_icon("screen_picker", "ColorPicker")); - bt_add_preset->set_icon(get_icon("add_preset")); + btn_pick->set_icon(get_theme_icon("screen_picker", "ColorPicker")); + bt_add_preset->set_icon(get_theme_icon("add_preset")); _update_controls(); } break; case NOTIFICATION_ENTER_TREE: { - btn_pick->set_icon(get_icon("screen_picker", "ColorPicker")); - bt_add_preset->set_icon(get_icon("add_preset")); + btn_pick->set_icon(get_theme_icon("screen_picker", "ColorPicker")); + bt_add_preset->set_icon(get_theme_icon("add_preset")); _update_color(); @@ -70,17 +70,17 @@ void ColorPicker::_notification(int p_what) { case NOTIFICATION_PARENTED: { for (int i = 0; i < 4; i++) - set_margin((Margin)i, get_constant("margin")); + set_margin((Margin)i, get_theme_constant("margin")); } break; case NOTIFICATION_VISIBILITY_CHANGED: { Popup *p = Object::cast_to<Popup>(get_parent()); if (p) - p->set_size(Size2(get_combined_minimum_size().width + get_constant("margin") * 2, get_combined_minimum_size().height + get_constant("margin") * 2)); + p->set_size(Size2(get_combined_minimum_size().width + get_theme_constant("margin") * 2, get_combined_minimum_size().height + get_theme_constant("margin") * 2)); } break; - case MainLoop::NOTIFICATION_WM_QUIT_REQUEST: { + case NOTIFICATION_WM_CLOSE_REQUEST: { - if (screen != NULL && screen->is_visible()) + if (screen != nullptr && screen->is_visible()) screen->hide(); } break; } @@ -247,6 +247,9 @@ void ColorPicker::_update_color(bool p_update_sliders) { } void ColorPicker::_update_presets() { + return; + //presets should be shown using buttons or something else, this method is not a good idea + presets_per_row = 10; Size2 size = bt_add_preset->get_size(); Size2 preset_size = Size2(MIN(size.width * presets.size(), presets_per_row * size.width), size.height * (Math::ceil((float)presets.size() / presets_per_row))); @@ -267,12 +270,12 @@ void ColorPicker::_text_type_toggled() { text_is_constructor = !text_is_constructor; if (text_is_constructor) { text_type->set_text(""); - text_type->set_icon(get_icon("Script", "EditorIcons")); + text_type->set_icon(get_theme_icon("Script", "EditorIcons")); c_text->set_editable(false); } else { text_type->set_text("#"); - text_type->set_icon(NULL); + text_type->set_icon(nullptr); c_text->set_editable(true); } @@ -399,14 +402,14 @@ void ColorPicker::_sample_draw() { const Rect2 r = Rect2(Point2(), Size2(uv_edit->get_size().width, sample->get_size().height * 0.95)); if (color.a < 1.0) { - sample->draw_texture_rect(get_icon("preset_bg", "ColorPicker"), r, true); + sample->draw_texture_rect(get_theme_icon("preset_bg", "ColorPicker"), r, true); } sample->draw_rect(r, color); if (color.r > 1 || color.g > 1 || color.b > 1) { // Draw an indicator to denote that the color is "overbright" and can't be displayed accurately in the preview - sample->draw_texture(get_icon("overbright_indicator", "ColorPicker"), Point2()); + sample->draw_texture(get_theme_icon("overbright_indicator", "ColorPicker"), Point2()); } } @@ -445,7 +448,7 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) { c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted()); c->draw_line(Point2(x, y), Point2(x, y), Color(1, 1, 1), 2); } else if (p_which == 1) { - Ref<Texture2D> hue = get_icon("color_hue", "ColorPicker"); + Ref<Texture2D> hue = get_theme_icon("color_hue", "ColorPicker"); c->draw_texture_rect(hue, Rect2(Point2(), c->get_size())); int y = c->get_size().y - c->get_size().y * (1.0 - h); Color col = Color(); @@ -620,30 +623,40 @@ void ColorPicker::_screen_pick_pressed() { screen->call_deferred("connect", "hide", Callable(btn_pick, "set_pressed"), varray(false)); } screen->raise(); - screen->show_modal(); +#ifndef _MSC_VER +#warning show modal no longer works, needs to be converted to a popup +#endif + //screen->show_modal(); } void ColorPicker::_focus_enter() { - if (c_text->has_focus()) { + bool has_ctext_focus = c_text->has_focus(); + if (has_ctext_focus) { c_text->select_all(); - return; + } else { + c_text->select(0, 0); } + for (int i = 0; i < 4; i++) { - if (values[i]->get_line_edit()->has_focus()) { + if (values[i]->get_line_edit()->has_focus() && !has_ctext_focus) { values[i]->get_line_edit()->select_all(); - break; + } else { + values[i]->get_line_edit()->select(0, 0); } } } void ColorPicker::_focus_exit() { for (int i = 0; i < 4; i++) { - values[i]->get_line_edit()->select(0, 0); + if (!values[i]->get_line_edit()->get_menu()->is_visible()) + values[i]->get_line_edit()->select(0, 0); } c_text->select(0, 0); } void ColorPicker::_html_focus_exit() { + if (c_text->get_menu()->is_visible()) + return; _html_entered(c_text->get_text()); _focus_exit(); } @@ -719,7 +732,7 @@ ColorPicker::ColorPicker() : changing_color = false; presets_enabled = true; presets_visible = true; - screen = NULL; + screen = nullptr; HBoxContainer *hb_edit = memnew(HBoxContainer); add_child(hb_edit); @@ -731,12 +744,12 @@ ColorPicker::ColorPicker() : uv_edit->set_mouse_filter(MOUSE_FILTER_PASS); uv_edit->set_h_size_flags(SIZE_EXPAND_FILL); uv_edit->set_v_size_flags(SIZE_EXPAND_FILL); - uv_edit->set_custom_minimum_size(Size2(get_constant("sv_width"), get_constant("sv_height"))); + uv_edit->set_custom_minimum_size(Size2(get_theme_constant("sv_width"), get_theme_constant("sv_height"))); uv_edit->connect("draw", callable_mp(this, &ColorPicker::_hsv_draw), make_binds(0, uv_edit)); w_edit = memnew(Control); hb_edit->add_child(w_edit); - w_edit->set_custom_minimum_size(Size2(get_constant("h_width"), 0)); + w_edit->set_custom_minimum_size(Size2(get_theme_constant("h_width"), 0)); w_edit->set_h_size_flags(SIZE_FILL); w_edit->set_v_size_flags(SIZE_EXPAND_FILL); w_edit->connect("gui_input", callable_mp(this, &ColorPicker::_w_input)); @@ -770,7 +783,7 @@ ColorPicker::ColorPicker() : HBoxContainer *hbc = memnew(HBoxContainer); labels[i] = memnew(Label()); - labels[i]->set_custom_minimum_size(Size2(get_constant("label_width"), 0)); + labels[i]->set_custom_minimum_size(Size2(get_theme_constant("label_width"), 0)); labels[i]->set_v_size_flags(SIZE_SHRINK_CENTER); hbc->add_child(labels[i]); @@ -874,8 +887,32 @@ void ColorPickerButton::_modal_closed() { void ColorPickerButton::pressed() { _update_picker(); - popup->set_position(get_global_position() - picker->get_combined_minimum_size() * get_global_transform().get_scale()); - popup->set_scale(get_global_transform().get_scale()); + + popup->set_as_minsize(); + + Rect2i usable_rect = popup->get_usable_parent_rect(); + //let's try different positions to see which one we can use + + Rect2i cp_rect(Point2i(), popup->get_size()); + for (int i = 0; i < 4; i++) { + if (i > 1) { + cp_rect.position.y = get_screen_position().y - cp_rect.size.y; + } else { + cp_rect.position.y = get_screen_position().y + get_size().height; + } + + if (i & 1) { + cp_rect.position.x = get_screen_position().x; + } else { + + cp_rect.position.x = get_screen_position().x - MAX(0, (cp_rect.size.x - get_size().x)); + } + + if (usable_rect.encloses(cp_rect)) { + break; + } + } + popup->set_position(cp_rect.position); popup->popup(); picker->set_focus_on_line_edit(); } @@ -885,17 +922,17 @@ void ColorPickerButton::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - const Ref<StyleBox> normal = get_stylebox("normal"); + const Ref<StyleBox> normal = get_theme_stylebox("normal"); const Rect2 r = Rect2(normal->get_offset(), get_size() - normal->get_minimum_size()); - draw_texture_rect(Control::get_icon("bg", "ColorPickerButton"), r, true); + draw_texture_rect(Control::get_theme_icon("bg", "ColorPickerButton"), r, true); draw_rect(r, color); if (color.r > 1 || color.g > 1 || color.b > 1) { // Draw an indicator to denote that the color is "overbright" and can't be displayed accurately in the preview - draw_texture(Control::get_icon("overbright_indicator", "ColorPicker"), normal->get_offset()); + draw_texture(Control::get_theme_icon("overbright_indicator", "ColorPicker"), normal->get_offset()); } } break; - case MainLoop::NOTIFICATION_WM_QUIT_REQUEST: { + case NOTIFICATION_WM_CLOSE_REQUEST: { if (popup) popup->hide(); @@ -951,12 +988,14 @@ PopupPanel *ColorPickerButton::get_popup() { void ColorPickerButton::_update_picker() { if (!picker) { popup = memnew(PopupPanel); + popup->set_wrap_controls(true); picker = memnew(ColorPicker); + picker->set_anchors_and_margins_preset(PRESET_WIDE); popup->add_child(picker); add_child(popup); picker->connect("color_changed", callable_mp(this, &ColorPickerButton::_color_changed)); popup->connect("modal_closed", callable_mp(this, &ColorPickerButton::_modal_closed)); - popup->connect("about_to_show", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(true)); + popup->connect("about_to_popup", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(true)); popup->connect("popup_hide", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(false)); picker->set_pick_color(color); picker->set_edit_alpha(edit_alpha); @@ -985,8 +1024,8 @@ ColorPickerButton::ColorPickerButton() { // Initialization is now done deferred, // this improves performance in the inspector as the color picker // can be expensive to initialize. - picker = NULL; - popup = NULL; + picker = nullptr; + popup = nullptr; edit_alpha = true; set_toggle_mode(true); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 1a231e368b..b4dc37c74f 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -38,9 +38,9 @@ #include "scene/gui/label.h" #include "scene/gui/panel.h" #include "scene/main/canvas_layer.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" #include "scene/scene_string_names.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" #ifdef TOOLS_ENABLED #include "editor/editor_settings.h" @@ -260,22 +260,22 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) { } else { if (name.begins_with("custom_icons/")) { String dname = name.get_slicec('/', 1); - add_icon_override(dname, p_value); + add_theme_icon_override(dname, p_value); } else if (name.begins_with("custom_shaders/")) { String dname = name.get_slicec('/', 1); - add_shader_override(dname, p_value); + add_theme_shader_override(dname, p_value); } else if (name.begins_with("custom_styles/")) { String dname = name.get_slicec('/', 1); - add_style_override(dname, p_value); + add_theme_style_override(dname, p_value); } else if (name.begins_with("custom_fonts/")) { String dname = name.get_slicec('/', 1); - add_font_override(dname, p_value); + add_theme_font_override(dname, p_value); } else if (name.begins_with("custom_colors/")) { String dname = name.get_slicec('/', 1); - add_color_override(dname, p_value); + add_theme_color_override(dname, p_value); } else if (name.begins_with("custom_constants/")) { String dname = name.get_slicec('/', 1); - add_constant_override(dname, p_value); + add_theme_constant_override(dname, p_value); } else return false; } @@ -438,22 +438,30 @@ void Control::_resize(const Size2 &p_size) { void Control::add_child_notify(Node *p_child) { Control *child_c = Object::cast_to<Control>(p_child); - if (!child_c) - return; - if (child_c->data.theme.is_null() && data.theme_owner) { - _propagate_theme_changed(child_c, data.theme_owner); //need to propagate here, since many controls may require setting up stuff + if (child_c && child_c->data.theme.is_null() && (data.theme_owner || data.theme_owner_window)) { + _propagate_theme_changed(child_c, data.theme_owner, data.theme_owner_window); //need to propagate here, since many controls may require setting up stuff + } + + Window *child_w = Object::cast_to<Window>(p_child); + + if (child_w && child_w->theme.is_null() && (data.theme_owner || data.theme_owner_window)) { + _propagate_theme_changed(child_w, data.theme_owner, data.theme_owner_window); //need to propagate here, since many controls may require setting up stuff } } void Control::remove_child_notify(Node *p_child) { Control *child_c = Object::cast_to<Control>(p_child); - if (!child_c) - return; - if (child_c->data.theme_owner && child_c->data.theme.is_null()) { - _propagate_theme_changed(child_c, NULL); + if (child_c && (child_c->data.theme_owner || child_c->data.theme_owner_window) && child_c->data.theme.is_null()) { + _propagate_theme_changed(child_c, nullptr, nullptr); + } + + Window *child_w = Object::cast_to<Window>(p_child); + + if (child_w && (child_w->theme_owner || child_w->theme_owner_window) && child_w->theme.is_null()) { + _propagate_theme_changed(child_w, nullptr, nullptr); } } @@ -462,7 +470,7 @@ void Control::_update_canvas_item_transform() { Transform2D xform = _get_internal_transform(); xform[2] += get_position(); - VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform); + RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform); } void Control::_notification(int p_notification) { @@ -486,111 +494,73 @@ void Control::_notification(int p_notification) { data.parent = Object::cast_to<Control>(get_parent()); - if (is_set_as_toplevel()) { - data.SI = get_viewport()->_gui_add_subwindow_control(this); - - if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) { - data.theme_owner = data.parent->data.theme_owner; - notification(NOTIFICATION_THEME_CHANGED); - } - - } else { - - Node *parent = this; //meh - Control *parent_control = NULL; - bool subwindow = false; + Node *parent = this; //meh + Control *parent_control = nullptr; + bool subwindow = false; - while (parent) { - - parent = parent->get_parent(); - - if (!parent) - break; - - CanvasItem *ci = Object::cast_to<CanvasItem>(parent); - if (ci && ci->is_set_as_toplevel()) { - subwindow = true; - break; - } + while (parent) { - parent_control = Object::cast_to<Control>(parent); + parent = parent->get_parent(); - if (parent_control) { - break; - } else if (ci) { + if (!parent) + break; - } else { - break; - } + CanvasItem *ci = Object::cast_to<CanvasItem>(parent); + if (ci && ci->is_set_as_toplevel()) { + subwindow = true; + break; } - if (parent_control) { - //do nothing, has a parent control - if (data.theme.is_null() && parent_control->data.theme_owner) { - data.theme_owner = parent_control->data.theme_owner; - notification(NOTIFICATION_THEME_CHANGED); - } - } else if (subwindow) { - //is a subwindow (process input before other controls for that canvas) - data.SI = get_viewport()->_gui_add_subwindow_control(this); - } else { - //is a regular root control - data.RI = get_viewport()->_gui_add_root_control(this); - } + parent_control = Object::cast_to<Control>(parent); - data.parent_canvas_item = get_parent_item(); - - if (data.parent_canvas_item) { + if (parent_control) { + break; + } else if (ci) { - data.parent_canvas_item->connect("item_rect_changed", callable_mp(this, &Control::_size_changed)); } else { - //connect viewport - get_viewport()->connect("size_changed", callable_mp(this, &Control::_size_changed)); + break; } } - /* - if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) { - data.theme_owner=data.parent->data.theme_owner; - notification(NOTIFICATION_THEME_CHANGED); + if (parent_control && !subwindow) { + //do nothing, has a parent control and not toplevel + if (data.theme.is_null() && parent_control->data.theme_owner) { + data.theme_owner = parent_control->data.theme_owner; + notification(NOTIFICATION_THEME_CHANGED); + } + } else { + //is a regular root control or toplevel + data.RI = get_viewport()->_gui_add_root_control(this); } - */ + data.parent_canvas_item = get_parent_item(); + + if (data.parent_canvas_item) { + + data.parent_canvas_item->connect("item_rect_changed", callable_mp(this, &Control::_size_changed)); + } else { + //connect viewport + get_viewport()->connect("size_changed", callable_mp(this, &Control::_size_changed)); + } } break; case NOTIFICATION_EXIT_CANVAS: { if (data.parent_canvas_item) { data.parent_canvas_item->disconnect("item_rect_changed", callable_mp(this, &Control::_size_changed)); - data.parent_canvas_item = NULL; + data.parent_canvas_item = nullptr; } else if (!is_set_as_toplevel()) { //disconnect viewport get_viewport()->disconnect("size_changed", callable_mp(this, &Control::_size_changed)); } - if (data.MI) { - get_viewport()->_gui_remove_modal_control(data.MI); - data.MI = NULL; - } - - if (data.SI) { - get_viewport()->_gui_remove_subwindow_control(data.SI); - data.SI = NULL; - } - if (data.RI) { get_viewport()->_gui_remove_root_control(data.RI); - data.RI = NULL; + data.RI = nullptr; } - data.parent = NULL; - data.parent_canvas_item = NULL; - /* - if (data.theme_owner && data.theme.is_null()) { - data.theme_owner=NULL; - notification(NOTIFICATION_THEME_CHANGED); - } - */ + data.parent = nullptr; + data.parent_canvas_item = nullptr; } break; case NOTIFICATION_MOVED_IN_PARENT: { @@ -600,9 +570,6 @@ void Control::_notification(int p_notification) { data.parent->update(); update(); - if (data.SI) { - get_viewport()->_gui_set_subwindow_order_dirty(); - } if (data.RI) { get_viewport()->_gui_set_root_order_dirty(); } @@ -615,8 +582,8 @@ void Control::_notification(int p_notification) { case NOTIFICATION_DRAW: { _update_canvas_item_transform(); - VisualServer::get_singleton()->canvas_item_set_custom_rect(get_canvas_item(), !data.disable_visibility_clip, Rect2(Point2(), get_size())); - VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), data.clip_contents); + RenderingServer::get_singleton()->canvas_item_set_custom_rect(get_canvas_item(), !data.disable_visibility_clip, Rect2(Point2(), get_size())); + RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), data.clip_contents); //emit_signal(SceneStringNames::get_singleton()->draw); } break; @@ -644,34 +611,21 @@ void Control::_notification(int p_notification) { minimum_size_changed(); update(); } break; - case NOTIFICATION_MODAL_CLOSE: { - - emit_signal("modal_closed"); - } break; case NOTIFICATION_VISIBILITY_CHANGED: { if (!is_visible_in_tree()) { - if (get_viewport() != NULL) + if (get_viewport() != nullptr) get_viewport()->_gui_hid_control(this); - if (is_inside_tree()) { - _modal_stack_remove(); - } - //remove key focus - //remove modalness + } else { data.minimum_size_valid = false; _size_changed(); } } break; - case SceneTree::NOTIFICATION_WM_UNFOCUS_REQUEST: { - - get_viewport()->_gui_unfocus_control(this); - - } break; } } @@ -787,76 +741,143 @@ void Control::set_drag_preview(Control *p_control) { get_viewport()->_gui_set_drag_preview(this, p_control); } -bool Control::is_window_modal_on_top() const { - - if (!is_inside_tree()) - return false; - - return get_viewport()->_gui_is_modal_on_top(this); -} - -uint64_t Control::get_modal_frame() const { - - return data.modal_frame; -} - Size2 Control::get_minimum_size() const { ScriptInstance *si = const_cast<Control *>(this)->get_script_instance(); if (si) { Callable::CallError ce; - Variant s = si->call(SceneStringNames::get_singleton()->_get_minimum_size, NULL, 0, ce); + Variant s = si->call(SceneStringNames::get_singleton()->_get_minimum_size, nullptr, 0, ce); if (ce.error == Callable::CallError::CALL_OK) return s; } return Size2(); } -Ref<Texture2D> Control::get_icon(const StringName &p_name, const StringName &p_type) const { +template <class T> +bool Control::_find_theme_item(Control *p_theme_owner, Window *p_theme_owner_window, T &r_ret, T (Theme::*get_func)(const StringName &, const StringName &) const, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type) { - if (p_type == StringName() || p_type == get_class_name()) { + // try with custom themes + Control *theme_owner = p_theme_owner; + Window *theme_owner_window = p_theme_owner_window; - const Ref<Texture2D> *tex = data.icon_override.getptr(p_name); - if (tex) - return *tex; + while (theme_owner || theme_owner_window) { + + StringName class_name = p_type; + + while (class_name != StringName()) { + if (theme_owner && (theme_owner->data.theme.operator->()->*has_func)(p_name, class_name)) { + r_ret = (theme_owner->data.theme.operator->()->*get_func)(p_name, class_name); + return true; + } + + if (theme_owner_window && (theme_owner_window->theme.operator->()->*has_func)(p_name, class_name)) { + r_ret = (theme_owner_window->theme.operator->()->*get_func)(p_name, class_name); + return true; + } + + class_name = ClassDB::get_parent_class_nocheck(class_name); + } + + Node *parent = theme_owner ? theme_owner->get_parent() : theme_owner_window->get_parent(); + + Control *parent_c = Object::cast_to<Control>(parent); + + if (parent_c) { + theme_owner = parent_c->data.theme_owner; + theme_owner_window = parent_c->data.theme_owner_window; + } else { + Window *parent_w = Object::cast_to<Window>(parent); + if (parent_w) { + theme_owner = parent_w->theme_owner; + theme_owner_window = parent_w->theme_owner_window; + } else { + + theme_owner = nullptr; + theme_owner_window = nullptr; + } + } } + return false; +} - StringName type = p_type ? p_type : get_class_name(); +bool Control::_has_theme_item(Control *p_theme_owner, Window *p_theme_owner_window, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type) { // try with custom themes - Control *theme_owner = data.theme_owner; + Control *theme_owner = p_theme_owner; + Window *theme_owner_window = p_theme_owner_window; - while (theme_owner) { + while (theme_owner || theme_owner_window) { - StringName class_name = type; + StringName class_name = p_type; while (class_name != StringName()) { - if (theme_owner->data.theme->has_icon(p_name, class_name)) { - return theme_owner->data.theme->get_icon(p_name, class_name); + if (theme_owner && (theme_owner->data.theme.operator->()->*has_func)(p_name, class_name)) { + return true; + } + + if (theme_owner_window && (theme_owner_window->theme.operator->()->*has_func)(p_name, class_name)) { + return true; } class_name = ClassDB::get_parent_class_nocheck(class_name); } - Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); + Node *parent = theme_owner ? theme_owner->get_parent() : theme_owner_window->get_parent(); + + Control *parent_c = Object::cast_to<Control>(parent); - if (parent) - theme_owner = parent->data.theme_owner; - else - theme_owner = NULL; + if (parent_c) { + theme_owner = parent_c->data.theme_owner; + theme_owner_window = parent_c->data.theme_owner_window; + } else { + Window *parent_w = Object::cast_to<Window>(parent); + if (parent_w) { + theme_owner = parent_w->theme_owner; + theme_owner_window = parent_w->theme_owner_window; + } else { + + theme_owner = nullptr; + theme_owner_window = nullptr; + } + } + } + return false; +} + +Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringName &p_type) const { + + if (p_type == StringName() || p_type == get_class_name()) { + + const Ref<Texture2D> *tex = data.icon_override.getptr(p_name); + if (tex) + return *tex; + } + + StringName type = p_type ? p_type : get_class_name(); + + return get_icons(data.theme_owner, data.theme_owner_window, p_name, type); +} + +Ref<Texture2D> Control::get_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { + + Ref<Texture2D> icon; + + if (_find_theme_item(p_theme_owner, p_theme_owner_window, icon, &Theme::get_icon, &Theme::has_icon, p_name, p_type)) { + return icon; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_icon(p_name, type)) { - return Theme::get_project_default()->get_icon(p_name, type); + if (Theme::get_project_default()->has_icon(p_name, p_type)) { + return Theme::get_project_default()->get_icon(p_name, p_type); } } - return Theme::get_default()->get_icon(p_name, type); + return Theme::get_default()->get_icon(p_name, p_type); } -Ref<Shader> Control::get_shader(const StringName &p_name, const StringName &p_type) const { +Ref<Shader> Control::get_theme_shader(const StringName &p_name, const StringName &p_type) const { + if (p_type == StringName() || p_type == get_class_name()) { const Ref<Shader> *sdr = data.shader_override.getptr(p_name); @@ -866,39 +887,27 @@ Ref<Shader> Control::get_shader(const StringName &p_name, const StringName &p_ty StringName type = p_type ? p_type : get_class_name(); - // try with custom themes - Control *theme_owner = data.theme_owner; - - while (theme_owner) { - - StringName class_name = type; - - while (class_name != StringName()) { - if (theme_owner->data.theme->has_shader(p_name, class_name)) { - return theme_owner->data.theme->get_shader(p_name, class_name); - } + return get_shaders(data.theme_owner, data.theme_owner_window, p_name, type); +} - class_name = ClassDB::get_parent_class_nocheck(class_name); - } +Ref<Shader> Control::get_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); + Ref<Shader> shader; - if (parent) - theme_owner = parent->data.theme_owner; - else - theme_owner = NULL; + if (_find_theme_item(p_theme_owner, p_theme_owner_window, shader, &Theme::get_shader, &Theme::has_shader, p_name, p_type)) { + return shader; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_shader(p_name, type)) { - return Theme::get_project_default()->get_shader(p_name, type); + if (Theme::get_project_default()->has_shader(p_name, p_type)) { + return Theme::get_project_default()->get_shader(p_name, p_type); } } - return Theme::get_default()->get_shader(p_name, type); + return Theme::get_default()->get_shader(p_name, p_type); } -Ref<StyleBox> Control::get_stylebox(const StringName &p_name, const StringName &p_type) const { +Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { const Ref<StyleBox> *style = data.style_override.getptr(p_name); @@ -908,43 +917,27 @@ Ref<StyleBox> Control::get_stylebox(const StringName &p_name, const StringName & StringName type = p_type ? p_type : get_class_name(); - // try with custom themes - Control *theme_owner = data.theme_owner; + return get_styleboxs(data.theme_owner, data.theme_owner_window, p_name, type); +} - StringName class_name = type; +Ref<StyleBox> Control::get_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - while (theme_owner) { + Ref<StyleBox> stylebox; - while (class_name != StringName()) { - if (theme_owner->data.theme->has_stylebox(p_name, class_name)) { - return theme_owner->data.theme->get_stylebox(p_name, class_name); - } + if (_find_theme_item(p_theme_owner, p_theme_owner_window, stylebox, &Theme::get_stylebox, &Theme::has_stylebox, p_name, p_type)) { + return stylebox; + } - class_name = ClassDB::get_parent_class_nocheck(class_name); + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_stylebox(p_name, p_type)) { + return Theme::get_project_default()->get_stylebox(p_name, p_type); } - - class_name = type; - - Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); - - if (parent) - theme_owner = parent->data.theme_owner; - else - theme_owner = NULL; } - while (class_name != StringName()) { - if (Theme::get_project_default().is_valid() && Theme::get_project_default()->has_stylebox(p_name, type)) - return Theme::get_project_default()->get_stylebox(p_name, type); - - if (Theme::get_default()->has_stylebox(p_name, class_name)) - return Theme::get_default()->get_stylebox(p_name, class_name); - - class_name = ClassDB::get_parent_class_nocheck(class_name); - } - return Theme::get_default()->get_stylebox(p_name, type); + return Theme::get_default()->get_stylebox(p_name, p_type); } -Ref<Font> Control::get_font(const StringName &p_name, const StringName &p_type) const { + +Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { const Ref<Font> *font = data.font_override.getptr(p_name); @@ -954,34 +947,27 @@ Ref<Font> Control::get_font(const StringName &p_name, const StringName &p_type) StringName type = p_type ? p_type : get_class_name(); - // try with custom themes - Control *theme_owner = data.theme_owner; + return get_fonts(data.theme_owner, data.theme_owner_window, p_name, type); +} - while (theme_owner) { +Ref<Font> Control::get_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - StringName class_name = type; + Ref<Font> font; - while (class_name != StringName()) { - if (theme_owner->data.theme->has_font(p_name, class_name)) { - return theme_owner->data.theme->get_font(p_name, class_name); - } + if (_find_theme_item(p_theme_owner, p_theme_owner_window, font, &Theme::get_font, &Theme::has_font, p_name, p_type)) { + return font; + } - class_name = ClassDB::get_parent_class_nocheck(class_name); + if (Theme::get_project_default().is_valid()) { + if (Theme::get_project_default()->has_font(p_name, p_type)) { + return Theme::get_project_default()->get_font(p_name, p_type); } - - if (theme_owner->data.theme->get_default_theme_font().is_valid()) - return theme_owner->data.theme->get_default_theme_font(); - Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); - - if (parent) - theme_owner = parent->data.theme_owner; - else - theme_owner = NULL; } - return Theme::get_default()->get_font(p_name, type); + return Theme::get_default()->get_font(p_name, p_type); } -Color Control::get_color(const StringName &p_name, const StringName &p_type) const { + +Color Control::get_theme_color(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { const Color *color = data.color_override.getptr(p_name); @@ -990,38 +976,27 @@ Color Control::get_color(const StringName &p_name, const StringName &p_type) con } StringName type = p_type ? p_type : get_class_name(); - // try with custom themes - Control *theme_owner = data.theme_owner; - - while (theme_owner) { - - StringName class_name = type; - while (class_name != StringName()) { - if (theme_owner->data.theme->has_color(p_name, class_name)) { - return theme_owner->data.theme->get_color(p_name, class_name); - } + return get_colors(data.theme_owner, data.theme_owner_window, p_name, type); +} - class_name = ClassDB::get_parent_class_nocheck(class_name); - } +Color Control::get_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); + Color color; - if (parent) - theme_owner = parent->data.theme_owner; - else - theme_owner = NULL; + if (_find_theme_item(p_theme_owner, p_theme_owner_window, color, &Theme::get_color, &Theme::has_color, p_name, p_type)) { + return color; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_color(p_name, type)) { - return Theme::get_project_default()->get_color(p_name, type); + if (Theme::get_project_default()->has_color(p_name, p_type)) { + return Theme::get_project_default()->get_color(p_name, p_type); } } - return Theme::get_default()->get_color(p_name, type); + return Theme::get_default()->get_color(p_name, p_type); } -int Control::get_constant(const StringName &p_name, const StringName &p_type) const { +int Control::get_theme_constant(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { const int *constant = data.constant_override.getptr(p_name); @@ -1030,303 +1005,213 @@ int Control::get_constant(const StringName &p_name, const StringName &p_type) co } StringName type = p_type ? p_type : get_class_name(); - // try with custom themes - Control *theme_owner = data.theme_owner; - - while (theme_owner) { - StringName class_name = type; - - while (class_name != StringName()) { - if (theme_owner->data.theme->has_constant(p_name, class_name)) { - return theme_owner->data.theme->get_constant(p_name, class_name); - } + return get_constants(data.theme_owner, data.theme_owner_window, p_name, type); +} - class_name = ClassDB::get_parent_class_nocheck(class_name); - } +int Control::get_constants(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); + int constant; - if (parent) - theme_owner = parent->data.theme_owner; - else - theme_owner = NULL; + if (_find_theme_item(p_theme_owner, p_theme_owner_window, constant, &Theme::get_constant, &Theme::has_constant, p_name, p_type)) { + return constant; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_constant(p_name, type)) { - return Theme::get_project_default()->get_constant(p_name, type); + if (Theme::get_project_default()->has_constant(p_name, p_type)) { + return Theme::get_project_default()->get_constant(p_name, p_type); } } - return Theme::get_default()->get_constant(p_name, type); + return Theme::get_default()->get_constant(p_name, p_type); } -bool Control::has_icon_override(const StringName &p_name) const { +bool Control::has_theme_icon_override(const StringName &p_name) const { const Ref<Texture2D> *tex = data.icon_override.getptr(p_name); - return tex != NULL; + return tex != nullptr; } -bool Control::has_shader_override(const StringName &p_name) const { +bool Control::has_theme_shader_override(const StringName &p_name) const { const Ref<Shader> *sdr = data.shader_override.getptr(p_name); - return sdr != NULL; + return sdr != nullptr; } -bool Control::has_stylebox_override(const StringName &p_name) const { +bool Control::has_theme_stylebox_override(const StringName &p_name) const { const Ref<StyleBox> *style = data.style_override.getptr(p_name); - return style != NULL; + return style != nullptr; } -bool Control::has_font_override(const StringName &p_name) const { +bool Control::has_theme_font_override(const StringName &p_name) const { const Ref<Font> *font = data.font_override.getptr(p_name); - return font != NULL; + return font != nullptr; } -bool Control::has_color_override(const StringName &p_name) const { +bool Control::has_theme_color_override(const StringName &p_name) const { const Color *color = data.color_override.getptr(p_name); - return color != NULL; + return color != nullptr; } -bool Control::has_constant_override(const StringName &p_name) const { +bool Control::has_theme_constant_override(const StringName &p_name) const { const int *constant = data.constant_override.getptr(p_name); - return constant != NULL; + return constant != nullptr; } -bool Control::has_icon(const StringName &p_name, const StringName &p_type) const { +bool Control::has_theme_icon(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { - if (has_icon_override(p_name)) + if (has_theme_icon_override(p_name)) return true; } StringName type = p_type ? p_type : get_class_name(); - // try with custom themes - Control *theme_owner = data.theme_owner; - - while (theme_owner) { - - StringName class_name = type; - - while (class_name != StringName()) { - if (theme_owner->data.theme->has_icon(p_name, class_name)) { - return true; - } - class_name = ClassDB::get_parent_class_nocheck(class_name); - } + return has_icons(data.theme_owner, data.theme_owner_window, p_name, type); +} - Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); +bool Control::has_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - if (parent) - theme_owner = parent->data.theme_owner; - else - theme_owner = NULL; + if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_icon, p_name, p_type)) { + return true; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_color(p_name, type)) { + if (Theme::get_project_default()->has_color(p_name, p_type)) { return true; } } - return Theme::get_default()->has_icon(p_name, type); + return Theme::get_default()->has_icon(p_name, p_type); } -bool Control::has_shader(const StringName &p_name, const StringName &p_type) const { +bool Control::has_theme_shader(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { - if (has_shader_override(p_name)) + if (has_theme_shader_override(p_name)) return true; } StringName type = p_type ? p_type : get_class_name(); - // try with custom themes - Control *theme_owner = data.theme_owner; - - while (theme_owner) { - - StringName class_name = type; - - while (class_name != StringName()) { - if (theme_owner->data.theme->has_shader(p_name, class_name)) { - return true; - } - class_name = ClassDB::get_parent_class_nocheck(class_name); - } - - Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); + return has_shaders(data.theme_owner, data.theme_owner_window, p_name, type); +} +bool Control::has_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - if (parent) - theme_owner = parent->data.theme_owner; - else - theme_owner = NULL; + if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_shader, p_name, p_type)) { + return true; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_shader(p_name, type)) { + if (Theme::get_project_default()->has_shader(p_name, p_type)) { return true; } } - return Theme::get_default()->has_shader(p_name, type); + return Theme::get_default()->has_shader(p_name, p_type); } -bool Control::has_stylebox(const StringName &p_name, const StringName &p_type) const { + +bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { - if (has_stylebox_override(p_name)) + if (has_theme_stylebox_override(p_name)) return true; } StringName type = p_type ? p_type : get_class_name(); - // try with custom themes - Control *theme_owner = data.theme_owner; - - while (theme_owner) { - - StringName class_name = type; - - while (class_name != StringName()) { - if (theme_owner->data.theme->has_stylebox(p_name, class_name)) { - return true; - } - class_name = ClassDB::get_parent_class_nocheck(class_name); - } + return has_styleboxs(data.theme_owner, data.theme_owner_window, p_name, type); +} - Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); +bool Control::has_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - if (parent) - theme_owner = parent->data.theme_owner; - else - theme_owner = NULL; + if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_stylebox, p_name, p_type)) { + return true; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_stylebox(p_name, type)) { + if (Theme::get_project_default()->has_stylebox(p_name, p_type)) { return true; } } - return Theme::get_default()->has_stylebox(p_name, type); + return Theme::get_default()->has_stylebox(p_name, p_type); } -bool Control::has_font(const StringName &p_name, const StringName &p_type) const { + +bool Control::has_theme_font(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { - if (has_font_override(p_name)) + if (has_theme_font_override(p_name)) return true; } StringName type = p_type ? p_type : get_class_name(); - // try with custom themes - Control *theme_owner = data.theme_owner; - - while (theme_owner) { - - StringName class_name = type; - - while (class_name != StringName()) { - if (theme_owner->data.theme->has_font(p_name, class_name)) { - return true; - } - class_name = ClassDB::get_parent_class_nocheck(class_name); - } - - Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); + return has_fonts(data.theme_owner, data.theme_owner_window, p_name, type); +} +bool Control::has_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - if (parent) - theme_owner = parent->data.theme_owner; - else - theme_owner = NULL; + if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_font, p_name, p_type)) { + return true; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_font(p_name, type)) { + if (Theme::get_project_default()->has_font(p_name, p_type)) { return true; } } - return Theme::get_default()->has_font(p_name, type); + return Theme::get_default()->has_font(p_name, p_type); } -bool Control::has_color(const StringName &p_name, const StringName &p_type) const { +bool Control::has_theme_color(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { - if (has_color_override(p_name)) + if (has_theme_color_override(p_name)) return true; } StringName type = p_type ? p_type : get_class_name(); - // try with custom themes - Control *theme_owner = data.theme_owner; - - while (theme_owner) { - - StringName class_name = type; - - while (class_name != StringName()) { - if (theme_owner->data.theme->has_color(p_name, class_name)) { - return true; - } - class_name = ClassDB::get_parent_class_nocheck(class_name); - } - - Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); + return has_colors(data.theme_owner, data.theme_owner_window, p_name, type); +} +bool Control::has_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - if (parent) - theme_owner = parent->data.theme_owner; - else - theme_owner = NULL; + if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_color, p_name, p_type)) { + return true; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_color(p_name, type)) { + if (Theme::get_project_default()->has_color(p_name, p_type)) { return true; } } - return Theme::get_default()->has_color(p_name, type); + return Theme::get_default()->has_color(p_name, p_type); } -bool Control::has_constant(const StringName &p_name, const StringName &p_type) const { +bool Control::has_theme_constant(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { - if (has_constant_override(p_name)) + if (has_theme_constant_override(p_name)) return true; } StringName type = p_type ? p_type : get_class_name(); - // try with custom themes - Control *theme_owner = data.theme_owner; - - while (theme_owner) { - - StringName class_name = type; - - while (class_name != StringName()) { - if (theme_owner->data.theme->has_constant(p_name, class_name)) { - return true; - } - class_name = ClassDB::get_parent_class_nocheck(class_name); - } + return has_constants(data.theme_owner, data.theme_owner_window, p_name, p_type); +} - Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); +bool Control::has_constants(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - if (parent) - theme_owner = parent->data.theme_owner; - else - theme_owner = NULL; + if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_constant, p_name, p_type)) { + return true; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_constant(p_name, type)) { + if (Theme::get_project_default()->has_constant(p_name, p_type)) { return true; } } - return Theme::get_default()->has_constant(p_name, type); + return Theme::get_default()->has_constant(p_name, p_type); } Rect2 Control::get_parent_anchorable_rect() const { @@ -1769,6 +1654,17 @@ Point2 Control::get_global_position() const { return get_global_transform().get_origin(); } +Point2 Control::get_screen_position() const { + ERR_FAIL_COND_V(!is_inside_tree(), Point2()); + Point2 global_pos = get_global_position(); + Window *w = Object::cast_to<Window>(get_viewport()); + if (w && !w->is_embedding_subwindows()) { + global_pos += w->get_position(); + } + + return global_pos; +} + void Control::_set_global_position(const Point2 &p_point) { set_global_position(p_point); } @@ -1863,6 +1759,20 @@ Rect2 Control::get_global_rect() const { return Rect2(get_global_position(), get_size()); } +Rect2 Control::get_screen_rect() const { + + ERR_FAIL_COND_V(!is_inside_tree(), Rect2()); + + Rect2 r(get_global_position(), get_size()); + + Window *w = Object::cast_to<Window>(get_viewport()); + if (w && !w->is_embedding_subwindows()) { + r.position += w->get_position(); + } + + return r; +} + Rect2 Control::get_window_rect() const { ERR_FAIL_COND_V(!is_inside_tree(), Rect2()); Rect2 gr = get_global_rect(); @@ -1880,7 +1790,7 @@ Rect2 Control::get_anchorable_rect() const { return Rect2(Point2(), get_size()); } -void Control::add_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) { +void Control::add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) { if (data.icon_override.has(p_name)) { data.icon_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); @@ -1898,7 +1808,7 @@ void Control::add_icon_override(const StringName &p_name, const Ref<Texture2D> & notification(NOTIFICATION_THEME_CHANGED); } -void Control::add_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) { +void Control::add_theme_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) { if (data.shader_override.has(p_name)) { data.shader_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); @@ -1915,7 +1825,7 @@ void Control::add_shader_override(const StringName &p_name, const Ref<Shader> &p } notification(NOTIFICATION_THEME_CHANGED); } -void Control::add_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) { +void Control::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) { if (data.style_override.has(p_name)) { data.style_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); @@ -1933,7 +1843,7 @@ void Control::add_style_override(const StringName &p_name, const Ref<StyleBox> & notification(NOTIFICATION_THEME_CHANGED); } -void Control::add_font_override(const StringName &p_name, const Ref<Font> &p_font) { +void Control::add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font) { if (data.font_override.has(p_name)) { data.font_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); @@ -1950,12 +1860,12 @@ void Control::add_font_override(const StringName &p_name, const Ref<Font> &p_fon } notification(NOTIFICATION_THEME_CHANGED); } -void Control::add_color_override(const StringName &p_name, const Color &p_color) { +void Control::add_theme_color_override(const StringName &p_name, const Color &p_color) { data.color_override[p_name] = p_color; notification(NOTIFICATION_THEME_CHANGED); } -void Control::add_constant_override(const StringName &p_name, int p_constant) { +void Control::add_theme_constant_override(const StringName &p_name, int p_constant) { data.constant_override[p_name] = p_constant; notification(NOTIFICATION_THEME_CHANGED); @@ -1974,17 +1884,17 @@ void Control::set_focus_mode(FocusMode p_focus_mode) { static Control *_next_control(Control *p_from) { if (p_from->is_set_as_toplevel()) - return NULL; // can't go above + return nullptr; // can't go above Control *parent = Object::cast_to<Control>(p_from->get_parent()); if (!parent) { - return NULL; + return nullptr; } - int next = p_from->get_position_in_parent(); - ERR_FAIL_INDEX_V(next, parent->get_child_count(), NULL); + int next = p_from->get_index(); + ERR_FAIL_INDEX_V(next, parent->get_child_count(), nullptr); for (int i = (next + 1); i < parent->get_child_count(); i++) { Control *c = Object::cast_to<Control>(parent->get_child(i)); @@ -2011,9 +1921,9 @@ Control *Control::find_next_valid_focus() const { Control *c; if (n) { c = Object::cast_to<Control>(n); - ERR_FAIL_COND_V_MSG(!c, NULL, "Next focus node is not a control: " + n->get_name() + "."); + ERR_FAIL_COND_V_MSG(!c, nullptr, "Next focus node is not a control: " + n->get_name() + "."); } else { - return NULL; + return nullptr; } if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) return c; @@ -2021,7 +1931,7 @@ Control *Control::find_next_valid_focus() const { // find next child - Control *next_child = NULL; + Control *next_child = nullptr; for (int i = 0; i < from->get_child_count(); i++) { @@ -2049,7 +1959,7 @@ Control *Control::find_next_valid_focus() const { next_child = const_cast<Control *>(this); while (next_child) { - if (next_child->data.SI || next_child->data.RI) + if (next_child->data.RI) break; next_child = next_child->get_parent_control(); } @@ -2058,7 +1968,7 @@ Control *Control::find_next_valid_focus() const { } if (next_child == this) // no next control-> - return (get_focus_mode() == FOCUS_ALL) ? next_child : NULL; + return (get_focus_mode() == FOCUS_ALL) ? next_child : nullptr; if (next_child) { if (next_child->get_focus_mode() == FOCUS_ALL) return next_child; @@ -2067,12 +1977,12 @@ Control *Control::find_next_valid_focus() const { break; } - return NULL; + return nullptr; } static Control *_prev_control(Control *p_from) { - Control *child = NULL; + Control *child = nullptr; for (int i = p_from->get_child_count() - 1; i >= 0; i--) { Control *c = Object::cast_to<Control>(p_from->get_child(i)); @@ -2102,9 +2012,9 @@ Control *Control::find_prev_valid_focus() const { Control *c; if (n) { c = Object::cast_to<Control>(n); - ERR_FAIL_COND_V_MSG(!c, NULL, "Previous focus node is not a control: " + n->get_name() + "."); + ERR_FAIL_COND_V_MSG(!c, nullptr, "Previous focus node is not a control: " + n->get_name() + "."); } else { - return NULL; + return nullptr; } if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) return c; @@ -2112,7 +2022,7 @@ Control *Control::find_prev_valid_focus() const { // find prev child - Control *prev_child = NULL; + Control *prev_child = nullptr; if (from->is_set_as_toplevel() || !Object::cast_to<Control>(from->get_parent())) { @@ -2122,7 +2032,7 @@ Control *Control::find_prev_valid_focus() const { } else { - for (int i = (from->get_position_in_parent() - 1); i >= 0; i--) { + for (int i = (from->get_index() - 1); i >= 0; i--) { Control *c = Object::cast_to<Control>(from->get_parent()->get_child(i)); @@ -2144,7 +2054,7 @@ Control *Control::find_prev_valid_focus() const { } if (prev_child == this) // no prev control-> - return (get_focus_mode() == FOCUS_ALL) ? prev_child : NULL; + return (get_focus_mode() == FOCUS_ALL) ? prev_child : nullptr; if (prev_child->get_focus_mode() == FOCUS_ALL) return prev_child; @@ -2152,7 +2062,7 @@ Control *Control::find_prev_valid_focus() const { from = prev_child; } - return NULL; + return nullptr; } Control::FocusMode Control::get_focus_mode() const { @@ -2192,53 +2102,29 @@ bool Control::is_toplevel_control() const { return is_inside_tree() && (!data.parent_canvas_item && !data.RI && is_set_as_toplevel()); } -void Control::show_modal(bool p_exclusive) { - - ERR_FAIL_COND(!is_inside_tree()); - ERR_FAIL_COND(!data.SI); - - if (is_visible_in_tree()) - hide(); - - ERR_FAIL_COND(data.MI != NULL); - show(); - raise(); - data.modal_exclusive = p_exclusive; - data.MI = get_viewport()->_gui_show_modal(this); - data.modal_frame = Engine::get_singleton()->get_frames_drawn(); -} +void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_owner_window, bool p_assign) { -void Control::_modal_set_prev_focus_owner(ObjectID p_prev) { - data.modal_prev_focus_owner = p_prev; -} - -void Control::_modal_stack_remove() { - - ERR_FAIL_COND(!is_inside_tree()); + Control *c = Object::cast_to<Control>(p_at); - if (!data.MI) + if (c && c != p_owner && c->data.theme.is_valid()) // has a theme, this can't be propagated return; - List<Control *>::Element *element = data.MI; - data.MI = NULL; - - get_viewport()->_gui_remove_from_modal_stack(element, data.modal_prev_focus_owner); - - data.modal_prev_focus_owner = ObjectID(); -} + Window *w = c == nullptr ? Object::cast_to<Window>(p_at) : nullptr; -void Control::_propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool p_assign) { - - Control *c = Object::cast_to<Control>(p_at); - - if (c && c != p_owner && c->data.theme.is_valid()) // has a theme, this can't be propagated + if (w && w != p_owner_window && w->theme.is_valid()) // has a theme, this can't be propagated return; for (int i = 0; i < p_at->get_child_count(); i++) { CanvasItem *child = Object::cast_to<CanvasItem>(p_at->get_child(i)); if (child) { - _propagate_theme_changed(child, p_owner, p_assign); + _propagate_theme_changed(child, p_owner, p_owner_window, p_assign); + } else { + + Window *window = Object::cast_to<Window>(p_at->get_child(i)); + if (window) { + _propagate_theme_changed(window, p_owner, p_owner_window, p_assign); + } } } @@ -2246,14 +2132,26 @@ void Control::_propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool if (p_assign) { c->data.theme_owner = p_owner; + c->data.theme_owner_window = p_owner_window; + } + c->notification(Control::NOTIFICATION_THEME_CHANGED); + c->emit_signal(SceneStringNames::get_singleton()->theme_changed); + } + + if (w) { + + if (p_assign) { + w->theme_owner = p_owner; + w->theme_owner_window = p_owner_window; } - c->notification(NOTIFICATION_THEME_CHANGED); + w->notification(Window::NOTIFICATION_THEME_CHANGED); + w->emit_signal(SceneStringNames::get_singleton()->theme_changed); } } void Control::_theme_changed() { - _propagate_theme_changed(this, this, false); + _propagate_theme_changed(this, this, nullptr, false); } void Control::set_theme(const Ref<Theme> &p_theme) { @@ -2269,15 +2167,21 @@ void Control::set_theme(const Ref<Theme> &p_theme) { if (!p_theme.is_null()) { data.theme_owner = this; - _propagate_theme_changed(this, this); + data.theme_owner_window = nullptr; + _propagate_theme_changed(this, this, nullptr); } else { - Control *parent = cast_to<Control>(get_parent()); - if (parent && parent->data.theme_owner) { - _propagate_theme_changed(this, parent->data.theme_owner); - } else { + Control *parent_c = Object::cast_to<Control>(get_parent()); - _propagate_theme_changed(this, NULL); + if (parent_c && (parent_c->data.theme_owner || parent_c->data.theme_owner_window)) { + Control::_propagate_theme_changed(this, parent_c->data.theme_owner, parent_c->data.theme_owner_window); + } else { + Window *parent_w = cast_to<Window>(get_parent()); + if (parent_w && (parent_w->theme_owner || parent_w->theme_owner_window)) { + Control::_propagate_theme_changed(this, parent_w->theme_owner, parent_w->theme_owner_window); + } else { + Control::_propagate_theme_changed(this, nullptr, nullptr); + } } } @@ -2311,7 +2215,7 @@ Control *Control::make_custom_tooltip(const String &p_text) const { if (get_script_instance()) { return const_cast<Control *>(this)->call("_make_custom_tooltip", p_text); } - return NULL; + return nullptr; } void Control::set_default_cursor_shape(CursorShape p_shape) { @@ -2378,19 +2282,19 @@ NodePath Control::get_focus_previous() const { Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) { - ERR_FAIL_INDEX_V((int)p_margin, 4, NULL); + ERR_FAIL_INDEX_V((int)p_margin, 4, nullptr); if (p_count >= MAX_NEIGHBOUR_SEARCH_COUNT) - return NULL; + return nullptr; if (!data.focus_neighbour[p_margin].is_empty()) { - Control *c = NULL; + Control *c = nullptr; Node *n = get_node(data.focus_neighbour[p_margin]); if (n) { c = Object::cast_to<Control>(n); - ERR_FAIL_COND_V_MSG(!c, NULL, "Neighbor focus node is not a control: " + n->get_name() + "."); + ERR_FAIL_COND_V_MSG(!c, nullptr, "Neighbor focus node is not a control: " + n->get_name() + "."); } else { - return NULL; + return nullptr; } bool valid = true; if (!c->is_visible()) @@ -2405,7 +2309,7 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) { } float dist = 1e7; - Control *result = NULL; + Control *result = nullptr; Point2 points[4]; @@ -2440,8 +2344,6 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) { Control *c = Object::cast_to<Control>(base); if (c) { - if (c->data.SI) - break; if (c->data.RI) break; } @@ -2449,7 +2351,7 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) { } if (!base) - return NULL; + return nullptr; _window_find_focus_neighbour(vdir, base, points, maxd, dist, &result); @@ -2511,7 +2413,7 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con Node *child = p_at->get_child(i); Control *childc = Object::cast_to<Control>(child); - if (childc && childc->data.SI) + if (childc && childc->data.RI) continue; //subwindow, ignore _window_find_focus_neighbour(p_dir, p_at->get_child(i), p_points, p_min, r_closest_dist, r_closest); } @@ -2569,6 +2471,12 @@ void Control::minimum_size_changed() { invalidate->data.minimum_size_valid = false; if (invalidate->is_set_as_toplevel()) break; // do not go further up + if (!invalidate->data.parent && get_parent()) { + Window *parent_window = Object::cast_to<Window>(get_parent()); + if (parent_window && parent_window->is_wrapping_controls()) { + parent_window->child_controls_changed(); + } + } invalidate = invalidate->data.parent; } @@ -2599,19 +2507,9 @@ Control::MouseFilter Control::get_mouse_filter() const { return data.mouse_filter; } -void Control::set_pass_on_modal_close_click(bool p_pass_on) { - - data.pass_on_modal_close_click = p_pass_on; -} - -bool Control::pass_on_modal_close_click() const { - - return data.pass_on_modal_close_click; -} - Control *Control::get_focus_owner() const { - ERR_FAIL_COND_V(!is_inside_tree(), NULL); + ERR_FAIL_COND_V(!is_inside_tree(), nullptr); return get_viewport()->_gui_get_focus_owner(); } @@ -2658,6 +2556,7 @@ float Control::get_rotation_degrees() const { void Control::_override_changed() { notification(NOTIFICATION_THEME_CHANGED); + emit_signal(SceneStringNames::get_singleton()->theme_changed); minimum_size_changed(); // overrides are likely to affect minimum size } @@ -2701,7 +2600,7 @@ Control *Control::get_root_parent_control() const { if (c) { root = c; - if (c->data.RI || c->data.MI || c->is_toplevel_control()) + if (c->data.RI || c->is_toplevel_control()) break; } @@ -2853,7 +2752,6 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("get_global_position"), &Control::get_global_position); ClassDB::bind_method(D_METHOD("get_rect"), &Control::get_rect); ClassDB::bind_method(D_METHOD("get_global_rect"), &Control::get_global_rect); - ClassDB::bind_method(D_METHOD("show_modal", "exclusive"), &Control::show_modal, DEFVAL(false)); ClassDB::bind_method(D_METHOD("set_focus_mode", "mode"), &Control::set_focus_mode); ClassDB::bind_method(D_METHOD("get_focus_mode"), &Control::get_focus_mode); ClassDB::bind_method(D_METHOD("has_focus"), &Control::has_focus); @@ -2873,31 +2771,31 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Control::set_theme); ClassDB::bind_method(D_METHOD("get_theme"), &Control::get_theme); - ClassDB::bind_method(D_METHOD("add_icon_override", "name", "texture"), &Control::add_icon_override); - ClassDB::bind_method(D_METHOD("add_shader_override", "name", "shader"), &Control::add_shader_override); - ClassDB::bind_method(D_METHOD("add_stylebox_override", "name", "stylebox"), &Control::add_style_override); - ClassDB::bind_method(D_METHOD("add_font_override", "name", "font"), &Control::add_font_override); - ClassDB::bind_method(D_METHOD("add_color_override", "name", "color"), &Control::add_color_override); - ClassDB::bind_method(D_METHOD("add_constant_override", "name", "constant"), &Control::add_constant_override); - - ClassDB::bind_method(D_METHOD("get_icon", "name", "type"), &Control::get_icon, DEFVAL("")); - ClassDB::bind_method(D_METHOD("get_stylebox", "name", "type"), &Control::get_stylebox, DEFVAL("")); - ClassDB::bind_method(D_METHOD("get_font", "name", "type"), &Control::get_font, DEFVAL("")); - ClassDB::bind_method(D_METHOD("get_color", "name", "type"), &Control::get_color, DEFVAL("")); - ClassDB::bind_method(D_METHOD("get_constant", "name", "type"), &Control::get_constant, DEFVAL("")); - - ClassDB::bind_method(D_METHOD("has_icon_override", "name"), &Control::has_icon_override); - ClassDB::bind_method(D_METHOD("has_shader_override", "name"), &Control::has_shader_override); - ClassDB::bind_method(D_METHOD("has_stylebox_override", "name"), &Control::has_stylebox_override); - ClassDB::bind_method(D_METHOD("has_font_override", "name"), &Control::has_font_override); - ClassDB::bind_method(D_METHOD("has_color_override", "name"), &Control::has_color_override); - ClassDB::bind_method(D_METHOD("has_constant_override", "name"), &Control::has_constant_override); - - ClassDB::bind_method(D_METHOD("has_icon", "name", "type"), &Control::has_icon, DEFVAL("")); - ClassDB::bind_method(D_METHOD("has_stylebox", "name", "type"), &Control::has_stylebox, DEFVAL("")); - ClassDB::bind_method(D_METHOD("has_font", "name", "type"), &Control::has_font, DEFVAL("")); - ClassDB::bind_method(D_METHOD("has_color", "name", "type"), &Control::has_color, DEFVAL("")); - ClassDB::bind_method(D_METHOD("has_constant", "name", "type"), &Control::has_constant, DEFVAL("")); + ClassDB::bind_method(D_METHOD("add_theme_icon_override", "name", "texture"), &Control::add_theme_icon_override); + ClassDB::bind_method(D_METHOD("add_theme_shader_override", "name", "shader"), &Control::add_theme_shader_override); + ClassDB::bind_method(D_METHOD("add_theme_stylebox_override", "name", "stylebox"), &Control::add_theme_style_override); + ClassDB::bind_method(D_METHOD("add_theme_font_override", "name", "font"), &Control::add_theme_font_override); + ClassDB::bind_method(D_METHOD("add_theme_color_override", "name", "color"), &Control::add_theme_color_override); + ClassDB::bind_method(D_METHOD("add_theme_constant_override", "name", "constant"), &Control::add_theme_constant_override); + + ClassDB::bind_method(D_METHOD("get_theme_icon", "name", "type"), &Control::get_theme_icon, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_stylebox", "name", "type"), &Control::get_theme_stylebox, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_font", "name", "type"), &Control::get_theme_font, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_color", "name", "type"), &Control::get_theme_color, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_constant", "name", "type"), &Control::get_theme_constant, DEFVAL("")); + + ClassDB::bind_method(D_METHOD("has_theme_icon_override", "name"), &Control::has_theme_icon_override); + ClassDB::bind_method(D_METHOD("has_theme_shader_override", "name"), &Control::has_theme_shader_override); + ClassDB::bind_method(D_METHOD("has_theme_stylebox_override", "name"), &Control::has_theme_stylebox_override); + ClassDB::bind_method(D_METHOD("has_theme_font_override", "name"), &Control::has_theme_font_override); + ClassDB::bind_method(D_METHOD("has_theme_color_override", "name"), &Control::has_theme_color_override); + ClassDB::bind_method(D_METHOD("has_theme_constant_override", "name"), &Control::has_theme_constant_override); + + ClassDB::bind_method(D_METHOD("has_theme_icon", "name", "type"), &Control::has_theme_icon, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_stylebox", "name", "type"), &Control::has_theme_stylebox, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_font", "name", "type"), &Control::has_theme_font, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_color", "name", "type"), &Control::has_theme_color, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_constant", "name", "type"), &Control::has_theme_constant, DEFVAL("")); ClassDB::bind_method(D_METHOD("get_parent_control"), &Control::get_parent_control); @@ -3013,7 +2911,6 @@ void Control::_bind_methods() { BIND_CONSTANT(NOTIFICATION_FOCUS_ENTER); BIND_CONSTANT(NOTIFICATION_FOCUS_EXIT); BIND_CONSTANT(NOTIFICATION_THEME_CHANGED); - BIND_CONSTANT(NOTIFICATION_MODAL_CLOSE); BIND_CONSTANT(NOTIFICATION_SCROLL_BEGIN); BIND_CONSTANT(NOTIFICATION_SCROLL_END); @@ -3082,31 +2979,27 @@ void Control::_bind_methods() { ADD_SIGNAL(MethodInfo("focus_exited")); ADD_SIGNAL(MethodInfo("size_flags_changed")); ADD_SIGNAL(MethodInfo("minimum_size_changed")); - ADD_SIGNAL(MethodInfo("modal_closed")); + ADD_SIGNAL(MethodInfo("theme_changed")); BIND_VMETHOD(MethodInfo(Variant::BOOL, "has_point", PropertyInfo(Variant::VECTOR2, "point"))); } Control::Control() { - data.parent = NULL; + data.parent = nullptr; data.mouse_filter = MOUSE_FILTER_STOP; - data.pass_on_modal_close_click = true; - data.SI = NULL; - data.MI = NULL; - data.RI = NULL; - data.theme_owner = NULL; - data.modal_exclusive = false; + data.RI = nullptr; + data.theme_owner = nullptr; + data.theme_owner_window = nullptr; data.default_cursor = CURSOR_ARROW; data.h_size_flags = SIZE_FILL; data.v_size_flags = SIZE_FILL; data.expand = 1; data.rotation = 0; - data.parent_canvas_item = NULL; + data.parent_canvas_item = nullptr; data.scale = Vector2(1, 1); - data.modal_frame = 0; data.block_minimum_size_adjust = false; data.disable_visibility_clip = false; data.h_grow = GROW_DIRECTION_END; diff --git a/scene/gui/control.h b/scene/gui/control.h index 15a32b8f67..d02fea20a6 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -33,8 +33,8 @@ #include "core/math/transform_2d.h" #include "core/rid.h" -#include "scene/2d/canvas_item.h" #include "scene/gui/shortcut.h" +#include "scene/main/canvas_item.h" #include "scene/main/node.h" #include "scene/main/timer.h" #include "scene/resources/theme.h" @@ -168,8 +168,6 @@ private: float expand; Point2 custom_minimum_size; - bool pass_on_modal_close_click; - MouseFilter mouse_filter; bool clip_contents; @@ -179,21 +177,16 @@ private: Control *parent; ObjectID drag_owner; - bool modal_exclusive; - uint64_t modal_frame; //frame used to put something as modal Ref<Theme> theme; Control *theme_owner; + Window *theme_owner_window; String tooltip; CursorShape default_cursor; - List<Control *>::Element *MI; //modal item - List<Control *>::Element *SI; List<Control *>::Element *RI; CanvasItem *parent_canvas_item; - ObjectID modal_prev_focus_owner; - NodePath focus_neighbour[4]; NodePath focus_next; NodePath focus_prev; @@ -218,7 +211,6 @@ private: void _set_global_position(const Point2 &p_point); void _set_size(const Size2 &p_size); - void _propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool p_assign = true); void _theme_changed(); void _change_notify_margins(); @@ -240,10 +232,29 @@ private: Transform2D _get_internal_transform() const; friend class Viewport; - void _modal_stack_remove(); - void _modal_set_prev_focus_owner(ObjectID p_prev); void _update_minimum_size_cache(); + friend class Window; + static void _propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_owner_window, bool p_assign = true); + + template <class T> + _FORCE_INLINE_ static bool _find_theme_item(Control *p_theme_owner, Window *p_theme_owner_window, T &, T (Theme::*get_func)(const StringName &, const StringName &) const, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type); + + _FORCE_INLINE_ static bool _has_theme_item(Control *p_theme_owner, Window *p_theme_owner_window, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type); + + static Ref<Texture2D> get_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static Ref<Shader> get_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static Ref<StyleBox> get_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static Ref<Font> get_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static Color get_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static int get_constants(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + + static bool has_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static bool has_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static bool has_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static bool has_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static bool has_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static bool has_constants(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); protected: virtual void add_child_notify(Node *p_child); @@ -272,7 +283,6 @@ public: NOTIFICATION_FOCUS_ENTER = 43, NOTIFICATION_FOCUS_EXIT = 44, NOTIFICATION_THEME_CHANGED = 45, - NOTIFICATION_MODAL_CLOSE = 46, NOTIFICATION_SCROLL_BEGIN = 47, NOTIFICATION_SCROLL_END = 48, @@ -320,9 +330,6 @@ public: void set_custom_minimum_size(const Size2 &p_custom); Size2 get_custom_minimum_size() const; - bool is_window_modal_on_top() const; - uint64_t get_modal_frame() const; //frame in which this was made modal - Control *get_parent_control() const; /* POSITIONING */ @@ -349,12 +356,14 @@ public: void set_global_position(const Point2 &p_point, bool p_keep_margins = false); Point2 get_position() const; Point2 get_global_position() const; + Point2 get_screen_position() const; void set_size(const Size2 &p_size, bool p_keep_margins = false); Size2 get_size() const; Rect2 get_rect() const; Rect2 get_global_rect() const; + Rect2 get_screen_rect() const; Rect2 get_window_rect() const; ///< use with care, as it blocks waiting for the visual server Rect2 get_anchorable_rect() const; @@ -375,8 +384,6 @@ public: void set_scale(const Vector2 &p_scale); Vector2 get_scale() const; - void show_modal(bool p_exclusive = false); - void set_theme(const Ref<Theme> &p_theme); Ref<Theme> get_theme() const; @@ -415,38 +422,35 @@ public: void set_mouse_filter(MouseFilter p_filter); MouseFilter get_mouse_filter() const; - void set_pass_on_modal_close_click(bool p_pass_on); - bool pass_on_modal_close_click() const; - /* SKINNING */ - void add_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon); - void add_shader_override(const StringName &p_name, const Ref<Shader> &p_shader); - void add_style_override(const StringName &p_name, const Ref<StyleBox> &p_style); - void add_font_override(const StringName &p_name, const Ref<Font> &p_font); - void add_color_override(const StringName &p_name, const Color &p_color); - void add_constant_override(const StringName &p_name, int p_constant); - - Ref<Texture2D> get_icon(const StringName &p_name, const StringName &p_type = StringName()) const; - Ref<Shader> get_shader(const StringName &p_name, const StringName &p_type = StringName()) const; - Ref<StyleBox> get_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const; - Ref<Font> get_font(const StringName &p_name, const StringName &p_type = StringName()) const; - Color get_color(const StringName &p_name, const StringName &p_type = StringName()) const; - int get_constant(const StringName &p_name, const StringName &p_type = StringName()) const; - - bool has_icon_override(const StringName &p_name) const; - bool has_shader_override(const StringName &p_name) const; - bool has_stylebox_override(const StringName &p_name) const; - bool has_font_override(const StringName &p_name) const; - bool has_color_override(const StringName &p_name) const; - bool has_constant_override(const StringName &p_name) const; - - bool has_icon(const StringName &p_name, const StringName &p_type = StringName()) const; - bool has_shader(const StringName &p_name, const StringName &p_type = StringName()) const; - bool has_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const; - bool has_font(const StringName &p_name, const StringName &p_type = StringName()) const; - bool has_color(const StringName &p_name, const StringName &p_type = StringName()) const; - bool has_constant(const StringName &p_name, const StringName &p_type = StringName()) const; + void add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon); + void add_theme_shader_override(const StringName &p_name, const Ref<Shader> &p_shader); + void add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style); + void add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font); + void add_theme_color_override(const StringName &p_name, const Color &p_color); + void add_theme_constant_override(const StringName &p_name, int p_constant); + + Ref<Texture2D> get_theme_icon(const StringName &p_name, const StringName &p_type = StringName()) const; + Ref<Shader> get_theme_shader(const StringName &p_name, const StringName &p_type = StringName()) const; + Ref<StyleBox> get_theme_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const; + Ref<Font> get_theme_font(const StringName &p_name, const StringName &p_type = StringName()) const; + Color get_theme_color(const StringName &p_name, const StringName &p_type = StringName()) const; + int get_theme_constant(const StringName &p_name, const StringName &p_type = StringName()) const; + + bool has_theme_icon_override(const StringName &p_name) const; + bool has_theme_shader_override(const StringName &p_name) const; + bool has_theme_stylebox_override(const StringName &p_name) const; + bool has_theme_font_override(const StringName &p_name) const; + bool has_theme_color_override(const StringName &p_name) const; + bool has_theme_constant_override(const StringName &p_name) const; + + bool has_theme_icon(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_shader(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_font(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_color(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_constant(const StringName &p_name, const StringName &p_type = StringName()) const; /* TOOLTIP */ diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 6cadd0a63e..5654219a3e 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -29,6 +29,8 @@ /*************************************************************************/ #include "dialogs.h" + +#include "core/os/keyboard.h" #include "core/print_string.h" #include "core/translation.h" #include "line_edit.h" @@ -36,362 +38,61 @@ #ifdef TOOLS_ENABLED #include "editor/editor_node.h" #include "editor/editor_scale.h" -#include "scene/main/viewport.h" // Only used to check for more modals when dimming the editor. +#include "scene/main/window.h" // Only used to check for more modals when dimming the editor. #endif -// WindowDialog - -void WindowDialog::_post_popup() { - - drag_type = DRAG_NONE; // just in case -} - -void WindowDialog::_fix_size() { - - // Perhaps this should be called when the viewport resizes as well or windows go out of bounds... - - // Ensure the whole window is visible. - Point2i pos = get_global_position(); - Size2i size = get_size(); - Size2i viewport_size = get_viewport_rect().size; - - // Windows require additional padding to keep the window chrome visible. - Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog"); - float top = 0; - float left = 0; - float bottom = 0; - float right = 0; - // Check validity, because the theme could contain a different type of StyleBox. - if (panel->get_class() == "StyleBoxTexture") { - Ref<StyleBoxTexture> panel_texture = Object::cast_to<StyleBoxTexture>(*panel); - top = panel_texture->get_expand_margin_size(MARGIN_TOP); - left = panel_texture->get_expand_margin_size(MARGIN_LEFT); - bottom = panel_texture->get_expand_margin_size(MARGIN_BOTTOM); - right = panel_texture->get_expand_margin_size(MARGIN_RIGHT); - } else if (panel->get_class() == "StyleBoxFlat") { - Ref<StyleBoxFlat> panel_flat = Object::cast_to<StyleBoxFlat>(*panel); - top = panel_flat->get_expand_margin_size(MARGIN_TOP); - left = panel_flat->get_expand_margin_size(MARGIN_LEFT); - bottom = panel_flat->get_expand_margin_size(MARGIN_BOTTOM); - right = panel_flat->get_expand_margin_size(MARGIN_RIGHT); - } - - pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right)); - pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom)); - set_global_position(pos); +// AcceptDialog - if (resizable) { - size.x = MIN(size.x, viewport_size.x - left - right); - size.y = MIN(size.y, viewport_size.y - top - bottom); - set_size(size); +void AcceptDialog::_input_from_window(const Ref<InputEvent> &p_event) { + Ref<InputEventKey> key = p_event; + if (key.is_valid() && key->is_pressed() && key->get_keycode() == KEY_ESCAPE) { + _cancel_pressed(); } } -bool WindowDialog::has_point(const Point2 &p_point) const { - - Rect2 r(Point2(), get_size()); - - // Enlarge upwards for title bar. - int title_height = get_constant("title_height", "WindowDialog"); - r.position.y -= title_height; - r.size.y += title_height; - - // Inflate by the resizable border thickness. - if (resizable) { - int scaleborder_size = get_constant("scaleborder_size", "WindowDialog"); - r.position.x -= scaleborder_size; - r.size.width += scaleborder_size * 2; - r.position.y -= scaleborder_size; - r.size.height += scaleborder_size * 2; - } - - return r.has_point(p_point); +void AcceptDialog::_parent_focused() { + _cancel_pressed(); } -void WindowDialog::_gui_input(const Ref<InputEvent> &p_event) { - - Ref<InputEventMouseButton> mb = p_event; - - if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT) { - - if (mb->is_pressed()) { - // Begin a possible dragging operation. - drag_type = _drag_hit_test(Point2(mb->get_position().x, mb->get_position().y)); - if (drag_type != DRAG_NONE) - drag_offset = get_global_mouse_position() - get_position(); - drag_offset_far = get_position() + get_size() - get_global_mouse_position(); - } else if (drag_type != DRAG_NONE && !mb->is_pressed()) { - // End a dragging operation. - drag_type = DRAG_NONE; - } - } +void AcceptDialog::_notification(int p_what) { - Ref<InputEventMouseMotion> mm = p_event; - - if (mm.is_valid()) { - - if (drag_type == DRAG_NONE) { - // Update the cursor while moving along the borders. - CursorShape cursor = CURSOR_ARROW; - if (resizable) { - int preview_drag_type = _drag_hit_test(Point2(mm->get_position().x, mm->get_position().y)); - switch (preview_drag_type) { - case DRAG_RESIZE_TOP: - case DRAG_RESIZE_BOTTOM: - cursor = CURSOR_VSIZE; - break; - case DRAG_RESIZE_LEFT: - case DRAG_RESIZE_RIGHT: - cursor = CURSOR_HSIZE; - break; - case DRAG_RESIZE_TOP + DRAG_RESIZE_LEFT: - case DRAG_RESIZE_BOTTOM + DRAG_RESIZE_RIGHT: - cursor = CURSOR_FDIAGSIZE; - break; - case DRAG_RESIZE_TOP + DRAG_RESIZE_RIGHT: - case DRAG_RESIZE_BOTTOM + DRAG_RESIZE_LEFT: - cursor = CURSOR_BDIAGSIZE; - break; + switch (p_what) { + case NOTIFICATION_VISIBILITY_CHANGED: { + if (is_visible()) { + + get_ok()->grab_focus(); + _update_child_rects(); + parent_visible = get_parent_visible_window(); + if (parent_visible) { + parent_visible->connect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); } - } - if (get_cursor_shape() != cursor) - set_default_cursor_shape(cursor); - } else { - // Update while in a dragging operation. - Point2 global_pos = get_global_mouse_position(); - global_pos.y = MAX(global_pos.y, 0); // Ensure title bar stays visible. - - Rect2 rect = get_rect(); - Size2 min_size = get_combined_minimum_size(); - - if (drag_type == DRAG_MOVE) { - rect.position = global_pos - drag_offset; } else { - if (drag_type & DRAG_RESIZE_TOP) { - int bottom = rect.position.y + rect.size.height; - int max_y = bottom - min_size.height; - rect.position.y = MIN(global_pos.y - drag_offset.y, max_y); - rect.size.height = bottom - rect.position.y; - } else if (drag_type & DRAG_RESIZE_BOTTOM) { - rect.size.height = global_pos.y - rect.position.y + drag_offset_far.y; - } - if (drag_type & DRAG_RESIZE_LEFT) { - int right = rect.position.x + rect.size.width; - int max_x = right - min_size.width; - rect.position.x = MIN(global_pos.x - drag_offset.x, max_x); - rect.size.width = right - rect.position.x; - } else if (drag_type & DRAG_RESIZE_RIGHT) { - rect.size.width = global_pos.x - rect.position.x + drag_offset_far.x; + if (parent_visible) { + parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible = nullptr; } } - set_size(rect.size); - set_position(rect.position); - } - } -} - -void WindowDialog::_notification(int p_what) { - - switch (p_what) { - case NOTIFICATION_DRAW: { - RID canvas = get_canvas_item(); - - // Draw the background. - Ref<StyleBox> panel = get_stylebox("panel"); - Size2 size = get_size(); - panel->draw(canvas, Rect2(0, 0, size.x, size.y)); - - // Draw the title bar text. - Ref<Font> title_font = get_font("title_font", "WindowDialog"); - Color title_color = get_color("title_color", "WindowDialog"); - int title_height = get_constant("title_height", "WindowDialog"); - int font_height = title_font->get_height() - title_font->get_descent() * 2; - int x = (size.x - title_font->get_string_size(xl_title).x) / 2; - int y = (-title_height + font_height) / 2; - title_font->draw(canvas, Point2(x, y), xl_title, title_color, size.x - panel->get_minimum_size().x); } break; - case NOTIFICATION_THEME_CHANGED: - case NOTIFICATION_ENTER_TREE: { - close_button->set_normal_texture(get_icon("close", "WindowDialog")); - close_button->set_pressed_texture(get_icon("close", "WindowDialog")); - close_button->set_hover_texture(get_icon("close_highlight", "WindowDialog")); - close_button->set_anchor(MARGIN_LEFT, ANCHOR_END); - close_button->set_begin(Point2(-get_constant("close_h_ofs", "WindowDialog"), -get_constant("close_v_ofs", "WindowDialog"))); - } break; - - case NOTIFICATION_TRANSLATION_CHANGED: { - String new_title = tr(title); - if (new_title != xl_title) { - xl_title = new_title; - minimum_size_changed(); - update(); - } + case NOTIFICATION_THEME_CHANGED: { + bg->add_theme_style_override("panel", bg->get_theme_stylebox("panel", "AcceptDialog")); } break; - case NOTIFICATION_MOUSE_EXIT: { - // Reset the mouse cursor when leaving the resizable window border. - if (resizable && !drag_type) { - if (get_default_cursor_shape() != CURSOR_ARROW) - set_default_cursor_shape(CURSOR_ARROW); + case NOTIFICATION_EXIT_TREE: { + if (parent_visible) { + parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible = nullptr; } } break; - -#ifdef TOOLS_ENABLED - case NOTIFICATION_POST_POPUP: { - if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton()) { - was_editor_dimmed = EditorNode::get_singleton()->is_editor_dimmed(); - EditorNode::get_singleton()->dim_editor(true); + case NOTIFICATION_READY: + case NOTIFICATION_WM_SIZE_CHANGED: { + if (is_visible()) { + _update_child_rects(); } } break; - - case NOTIFICATION_POPUP_HIDE: { - if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton() && !was_editor_dimmed) { - EditorNode::get_singleton()->dim_editor(false); - set_pass_on_modal_close_click(false); - } - } break; -#endif - } -} - -void WindowDialog::_closed() { - - _close_pressed(); - hide(); -} - -int WindowDialog::_drag_hit_test(const Point2 &pos) const { - int drag_type = DRAG_NONE; - - if (resizable) { - int title_height = get_constant("title_height", "WindowDialog"); - int scaleborder_size = get_constant("scaleborder_size", "WindowDialog"); - - Rect2 rect = get_rect(); - - if (pos.y < (-title_height + scaleborder_size)) - drag_type = DRAG_RESIZE_TOP; - else if (pos.y >= (rect.size.height - scaleborder_size)) - drag_type = DRAG_RESIZE_BOTTOM; - if (pos.x < scaleborder_size) - drag_type |= DRAG_RESIZE_LEFT; - else if (pos.x >= (rect.size.width - scaleborder_size)) - drag_type |= DRAG_RESIZE_RIGHT; - } - - if (drag_type == DRAG_NONE && pos.y < 0) - drag_type = DRAG_MOVE; - - return drag_type; -} - -void WindowDialog::set_title(const String &p_title) { - - if (title != p_title) { - title = p_title; - xl_title = tr(p_title); - minimum_size_changed(); - update(); - } -} -String WindowDialog::get_title() const { - - return title; -} - -void WindowDialog::set_resizable(bool p_resizable) { - resizable = p_resizable; -} -bool WindowDialog::get_resizable() const { - return resizable; -} - -Size2 WindowDialog::get_minimum_size() const { - - Ref<Font> font = get_font("title_font", "WindowDialog"); - - const int button_width = close_button->get_combined_minimum_size().x; - const int title_width = font->get_string_size(xl_title).x; - const int padding = button_width / 2; - const int button_area = button_width + padding; - - // As the title gets centered, title_width + close_button_width is not enough. - // We want a width w, such that w / 2 - title_width / 2 >= button_area, i.e. - // w >= 2 * button_area + title_width - - return Size2(2 * button_area + title_width, 1); -} - -TextureButton *WindowDialog::get_close_button() { - - return close_button; -} - -void WindowDialog::_bind_methods() { - - ClassDB::bind_method(D_METHOD("_gui_input"), &WindowDialog::_gui_input); - ClassDB::bind_method(D_METHOD("set_title", "title"), &WindowDialog::set_title); - ClassDB::bind_method(D_METHOD("get_title"), &WindowDialog::get_title); - ClassDB::bind_method(D_METHOD("set_resizable", "resizable"), &WindowDialog::set_resizable); - ClassDB::bind_method(D_METHOD("get_resizable"), &WindowDialog::get_resizable); - ClassDB::bind_method(D_METHOD("get_close_button"), &WindowDialog::get_close_button); - - ADD_PROPERTY(PropertyInfo(Variant::STRING, "window_title", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_title", "get_title"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resizable", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_resizable", "get_resizable"); -} - -WindowDialog::WindowDialog() { - - drag_type = DRAG_NONE; - resizable = false; - close_button = memnew(TextureButton); - add_child(close_button); - close_button->connect("pressed", callable_mp(this, &WindowDialog::_closed)); - -#ifdef TOOLS_ENABLED - was_editor_dimmed = false; -#endif -} - -WindowDialog::~WindowDialog() { -} - -// PopupDialog - -void PopupDialog::_notification(int p_what) { - - if (p_what == NOTIFICATION_DRAW) { - RID ci = get_canvas_item(); - get_stylebox("panel")->draw(ci, Rect2(Point2(), get_size())); - } -} - -PopupDialog::PopupDialog() { -} - -PopupDialog::~PopupDialog() { -} - -// AcceptDialog - -void AcceptDialog::_post_popup() { - - WindowDialog::_post_popup(); - get_ok()->grab_focus(); -} - -void AcceptDialog::_notification(int p_what) { - - switch (p_what) { - case NOTIFICATION_MODAL_CLOSE: { - cancel_pressed(); - } break; - - case NOTIFICATION_READY: - case NOTIFICATION_RESIZED: { - _update_child_rects(); + case NOTIFICATION_WM_CLOSE_REQUEST: { + _cancel_pressed(); } break; } } @@ -404,20 +105,28 @@ void AcceptDialog::_text_entered(const String &p_text) { void AcceptDialog::_ok_pressed() { if (hide_on_ok) - hide(); + set_visible(false); ok_pressed(); emit_signal("confirmed"); } -void AcceptDialog::_close_pressed() { +void AcceptDialog::_cancel_pressed() { + + Window *parent_window = parent_visible; + if (parent_visible) { + parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible = nullptr; + } + + call_deferred("hide"); + + emit_signal("cancelled"); cancel_pressed(); -} -// FIXME: This is redundant with _closed_pressed, but there's a slight behavior -// change (WindowDialog's _closed() also calls hide()) which should be assessed. -void AcceptDialog::_on_close_pressed() { - _closed(); // From WindowDialog. + if (parent_window) { + //parent_window->grab_focus(); + } } String AcceptDialog::get_text() const { @@ -427,8 +136,10 @@ String AcceptDialog::get_text() const { void AcceptDialog::set_text(String p_text) { label->set_text(p_text); - minimum_size_changed(); - _update_child_rects(); + child_controls_changed(); + if (is_visible()) { + _update_child_rects(); + } } void AcceptDialog::set_hide_on_ok(bool p_hide) { @@ -463,7 +174,7 @@ void AcceptDialog::_update_child_rects() { if (label->get_text().empty()) { label_size.height = 0; } - int margin = get_constant("margin", "Dialogs"); + int margin = hbc->get_theme_constant("margin", "Dialogs"); Size2 size = get_size(); Size2 hminsize = hbc->get_combined_minimum_size(); @@ -475,7 +186,7 @@ void AcceptDialog::_update_child_rects() { if (!c) continue; - if (c == hbc || c == label || c == get_close_button() || c->is_set_as_toplevel()) + if (c == hbc || c == label || c == bg || c->is_set_as_toplevel()) continue; c->set_position(cpos); @@ -487,11 +198,14 @@ void AcceptDialog::_update_child_rects() { hbc->set_position(cpos); hbc->set_size(csize); + + bg->set_position(Point2()); + bg->set_size(size); } -Size2 AcceptDialog::get_minimum_size() const { +Size2 AcceptDialog::_get_contents_minimum_size() const { - int margin = get_constant("margin", "Dialogs"); + int margin = hbc->get_theme_constant("margin", "Dialogs"); Size2 minsize = label->get_combined_minimum_size(); for (int i = 0; i < get_child_count(); i++) { @@ -499,7 +213,7 @@ Size2 AcceptDialog::get_minimum_size() const { if (!c) continue; - if (c == hbc || c == label || c == const_cast<AcceptDialog *>(this)->get_close_button() || c->is_set_as_toplevel()) + if (c == hbc || c == label || c->is_set_as_toplevel()) continue; Size2 cminsize = c->get_combined_minimum_size(); @@ -513,7 +227,7 @@ Size2 AcceptDialog::get_minimum_size() const { minsize.x += margin * 2; minsize.y += margin * 3; //one as separation between hbc and child - Size2 wmsize = WindowDialog::get_minimum_size(); + Size2 wmsize = get_min_size(); minsize.x = MAX(wmsize.x, minsize.x); return minsize; } @@ -551,7 +265,7 @@ Button *AcceptDialog::add_cancel(const String &p_cancel) { if (p_cancel == "") c = RTR("Cancel"); Button *b = swap_ok_cancel ? add_button(c, true) : add_button(c); - b->connect("pressed", callable_mp(this, &AcceptDialog::_on_close_pressed)); + b->connect("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed)); return b; } @@ -570,6 +284,7 @@ void AcceptDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("has_autowrap"), &AcceptDialog::has_autowrap); ADD_SIGNAL(MethodInfo("confirmed")); + ADD_SIGNAL(MethodInfo("cancelled")); ADD_SIGNAL(MethodInfo("custom_action", PropertyInfo(Variant::STRING_NAME, "action"))); ADD_GROUP("Dialog", "dialog"); @@ -586,17 +301,27 @@ void AcceptDialog::set_swap_ok_cancel(bool p_swap) { AcceptDialog::AcceptDialog() { - int margin = get_constant("margin", "Dialogs"); - int button_margin = get_constant("button_margin", "Dialogs"); + parent_visible = nullptr; + + set_wrap_controls(true); + set_visible(false); + set_transient(true); + + bg = memnew(Panel); + add_child(bg); + + hbc = memnew(HBoxContainer); + + int margin = hbc->get_theme_constant("margin", "Dialogs"); + int button_margin = hbc->get_theme_constant("button_margin", "Dialogs"); label = memnew(Label); - label->set_anchor(MARGIN_RIGHT, ANCHOR_END); - label->set_anchor(MARGIN_BOTTOM, ANCHOR_END); + label->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END); + label->set_anchor(MARGIN_BOTTOM, Control::ANCHOR_END); label->set_begin(Point2(margin, margin)); label->set_end(Point2(-margin, -button_margin - 10)); add_child(label); - hbc = memnew(HBoxContainer); add_child(hbc); hbc->add_spacer(); @@ -606,10 +331,11 @@ AcceptDialog::AcceptDialog() { hbc->add_spacer(); ok->connect("pressed", callable_mp(this, &AcceptDialog::_ok_pressed)); - set_as_toplevel(true); hide_on_ok = true; set_title(RTR("Alert!")); + + connect("window_input", callable_mp(this, &AcceptDialog::_input_from_window)); } AcceptDialog::~AcceptDialog() { @@ -631,7 +357,7 @@ ConfirmationDialog::ConfirmationDialog() { set_title(RTR("Please Confirm...")); #ifdef TOOLS_ENABLED - set_custom_minimum_size(Size2(200, 70) * EDSCALE); + set_min_size(Size2(200, 70) * EDSCALE); #endif cancel = add_cancel(); } diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h index c474f7849d..b68b4297d7 100644 --- a/scene/gui/dialogs.h +++ b/scene/gui/dialogs.h @@ -37,91 +37,32 @@ #include "scene/gui/panel.h" #include "scene/gui/popup.h" #include "scene/gui/texture_button.h" - -class WindowDialog : public Popup { - - GDCLASS(WindowDialog, Popup); - - enum DRAG_TYPE { - DRAG_NONE = 0, - DRAG_MOVE = 1, - DRAG_RESIZE_TOP = 1 << 1, - DRAG_RESIZE_RIGHT = 1 << 2, - DRAG_RESIZE_BOTTOM = 1 << 3, - DRAG_RESIZE_LEFT = 1 << 4 - }; - - TextureButton *close_button; - String title; - String xl_title; - int drag_type; - Point2 drag_offset; - Point2 drag_offset_far; - bool resizable; - -#ifdef TOOLS_ENABLED - bool was_editor_dimmed; -#endif - - void _gui_input(const Ref<InputEvent> &p_event); - int _drag_hit_test(const Point2 &pos) const; - -protected: - virtual void _post_popup(); - virtual void _fix_size(); - virtual void _close_pressed() {} - virtual bool has_point(const Point2 &p_point) const; - void _notification(int p_what); - static void _bind_methods(); - - // Not private since used by derived classes signal. - void _closed(); - -public: - TextureButton *get_close_button(); - - void set_title(const String &p_title); - String get_title() const; - void set_resizable(bool p_resizable); - bool get_resizable() const; - - Size2 get_minimum_size() const; - - WindowDialog(); - ~WindowDialog(); -}; - -class PopupDialog : public Popup { - - GDCLASS(PopupDialog, Popup); - -protected: - void _notification(int p_what); - -public: - PopupDialog(); - ~PopupDialog(); -}; +#include "scene/main/window.h" class LineEdit; -class AcceptDialog : public WindowDialog { +class AcceptDialog : public Window { - GDCLASS(AcceptDialog, WindowDialog); + GDCLASS(AcceptDialog, Window); + Window *parent_visible; + Panel *bg; HBoxContainer *hbc; Label *label; Button *ok; bool hide_on_ok; void _custom_action(const String &p_action); - void _close_pressed(); void _update_child_rects(); static bool swap_ok_cancel; + void _input_from_window(const Ref<InputEvent> &p_event); + void _parent_focused(); + protected: - virtual void _post_popup(); + virtual Size2 _get_contents_minimum_size() const; + void _notification(int p_what); static void _bind_methods(); virtual void ok_pressed() {} @@ -131,11 +72,9 @@ protected: // Not private since used by derived classes signal. void _text_entered(const String &p_text); void _ok_pressed(); - void _on_close_pressed(); + void _cancel_pressed(); public: - Size2 get_minimum_size() const; - Label *get_label() { return label; } static void set_swap_ok_cancel(bool p_swap); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 3be77ff4b3..89d13ecd7f 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -34,52 +34,56 @@ #include "core/print_string.h" #include "scene/gui/label.h" -FileDialog::GetIconFunc FileDialog::get_icon_func = NULL; -FileDialog::GetIconFunc FileDialog::get_large_icon_func = NULL; +FileDialog::GetIconFunc FileDialog::get_icon_func = nullptr; +FileDialog::GetIconFunc FileDialog::get_large_icon_func = nullptr; -FileDialog::RegisterFunc FileDialog::register_func = NULL; -FileDialog::RegisterFunc FileDialog::unregister_func = NULL; +FileDialog::RegisterFunc FileDialog::register_func = nullptr; +FileDialog::RegisterFunc FileDialog::unregister_func = nullptr; VBoxContainer *FileDialog::get_vbox() { return vbox; } -void FileDialog::_notification(int p_what) { +void FileDialog::_theme_changed() { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + Color font_color = vbox->get_theme_color("font_color", "ToolButton"); + Color font_color_hover = vbox->get_theme_color("font_color_hover", "ToolButton"); + Color font_color_pressed = vbox->get_theme_color("font_color_pressed", "ToolButton"); - if (p_what == NOTIFICATION_ENTER_TREE) { - dir_up->set_icon(get_icon("parent_folder")); - refresh->set_icon(get_icon("reload")); - show_hidden->set_icon(get_icon("toggle_hidden")); - } + dir_up->add_theme_color_override("icon_color_normal", font_color); + dir_up->add_theme_color_override("icon_color_hover", font_color_hover); + dir_up->add_theme_color_override("icon_color_pressed", font_color_pressed); - Color font_color = get_color("font_color", "ToolButton"); - Color font_color_hover = get_color("font_color_hover", "ToolButton"); - Color font_color_pressed = get_color("font_color_pressed", "ToolButton"); + refresh->add_theme_color_override("icon_color_normal", font_color); + refresh->add_theme_color_override("icon_color_hover", font_color_hover); + refresh->add_theme_color_override("icon_color_pressed", font_color_pressed); - dir_up->add_color_override("icon_color_normal", font_color); - dir_up->add_color_override("icon_color_hover", font_color_hover); - dir_up->add_color_override("icon_color_pressed", font_color_pressed); + show_hidden->add_theme_color_override("icon_color_normal", font_color); + show_hidden->add_theme_color_override("icon_color_hover", font_color_hover); + show_hidden->add_theme_color_override("icon_color_pressed", font_color_pressed); +} - refresh->add_color_override("icon_color_normal", font_color); - refresh->add_color_override("icon_color_hover", font_color_hover); - refresh->add_color_override("icon_color_pressed", font_color_pressed); +void FileDialog::_notification(int p_what) { - show_hidden->add_color_override("icon_color_normal", font_color); - show_hidden->add_color_override("icon_color_hover", font_color_hover); - show_hidden->add_color_override("icon_color_pressed", font_color_pressed); + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { + if (!is_visible()) { - } else if (p_what == NOTIFICATION_POPUP_HIDE) { + set_process_unhandled_input(false); + } + } + if (p_what == NOTIFICATION_ENTER_TREE) { - set_process_unhandled_input(false); + dir_up->set_icon(vbox->get_theme_icon("parent_folder", "FileDialog")); + refresh->set_icon(vbox->get_theme_icon("reload", "FileDialog")); + show_hidden->set_icon(vbox->get_theme_icon("toggle_hidden", "FileDialog")); + _theme_changed(); } } void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) { Ref<InputEventKey> k = p_event; - if (k.is_valid() && is_window_modal_on_top()) { + if (k.is_valid() && has_focus()) { if (k->is_pressed()) { @@ -110,7 +114,7 @@ void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) { } if (handled) - accept_event(); + set_input_as_handled(); } } } @@ -171,7 +175,7 @@ void FileDialog::_post_popup() { update_file_list(); invalidated = false; } - if (mode == MODE_SAVE_FILE) + if (mode == FILE_MODE_SAVE_FILE) file->grab_focus(); else tree->grab_focus(); @@ -179,7 +183,7 @@ void FileDialog::_post_popup() { set_process_unhandled_input(true); // For open dir mode, deselect all items on file dialog open. - if (mode == MODE_OPEN_DIR) { + if (mode == FILE_MODE_OPEN_DIR) { deselect_items(); file_box->set_visible(false); } else { @@ -189,9 +193,9 @@ void FileDialog::_post_popup() { void FileDialog::_action_pressed() { - if (mode == MODE_OPEN_FILES) { + if (mode == FILE_MODE_OPEN_FILES) { - TreeItem *ti = tree->get_next_selected(NULL); + TreeItem *ti = tree->get_next_selected(nullptr); String fbase = dir_access->get_current_dir(); Vector<String> files; @@ -211,10 +215,10 @@ void FileDialog::_action_pressed() { String f = dir_access->get_current_dir().plus_file(file->get_text()); - if ((mode == MODE_OPEN_ANY || mode == MODE_OPEN_FILE) && dir_access->file_exists(f)) { + if ((mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_FILE) && dir_access->file_exists(f)) { emit_signal("file_selected", f); hide(); - } else if (mode == MODE_OPEN_ANY || mode == MODE_OPEN_DIR) { + } else if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_DIR) { String path = dir_access->get_current_dir(); @@ -231,7 +235,7 @@ void FileDialog::_action_pressed() { hide(); } - if (mode == MODE_SAVE_FILE) { + if (mode == FILE_MODE_SAVE_FILE) { bool valid = false; @@ -283,7 +287,7 @@ void FileDialog::_action_pressed() { if (!valid) { - exterr->popup_centered_minsize(Size2(250, 80)); + exterr->popup_centered(Size2(250, 80)); return; } @@ -307,7 +311,7 @@ void FileDialog::_cancel_pressed() { bool FileDialog::_is_open_should_be_disabled() { - if (mode == MODE_OPEN_ANY || mode == MODE_SAVE_FILE) + if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE) return false; TreeItem *ti = tree->get_next_selected(tree->get_root()); @@ -319,13 +323,13 @@ bool FileDialog::_is_open_should_be_disabled() { } // We have something that we can't select? if (!ti) - return mode != MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder. + return mode != FILE_MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder. Dictionary d = ti->get_metadata(0); // Opening a file, but selected a folder? Forbidden. - return ((mode == MODE_OPEN_FILE || mode == MODE_OPEN_FILES) && d["dir"]) || // Flipped case, also forbidden. - (mode == MODE_OPEN_DIR && !d["dir"]); + return ((mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES) && d["dir"]) || // Flipped case, also forbidden. + (mode == FILE_MODE_OPEN_DIR && !d["dir"]); } void FileDialog::_go_up() { @@ -346,15 +350,15 @@ void FileDialog::deselect_items() { switch (mode) { - case MODE_OPEN_FILE: - case MODE_OPEN_FILES: + case FILE_MODE_OPEN_FILE: + case FILE_MODE_OPEN_FILES: get_ok()->set_text(RTR("Open")); break; - case MODE_OPEN_DIR: + case FILE_MODE_OPEN_DIR: get_ok()->set_text(RTR("Select Current Folder")); break; - case MODE_OPEN_ANY: - case MODE_SAVE_FILE: + case FILE_MODE_OPEN_ANY: + case FILE_MODE_SAVE_FILE: // FIXME: Implement, or refactor to avoid duplication with set_mode break; } @@ -375,7 +379,7 @@ void FileDialog::_tree_selected() { if (!d["dir"]) { file->set_text(d["name"]); - } else if (mode == MODE_OPEN_DIR) { + } else if (mode == FILE_MODE_OPEN_DIR) { get_ok()->set_text(RTR("Select This Folder")); } @@ -393,7 +397,7 @@ void FileDialog::_tree_item_activated() { if (d["dir"]) { dir_access->change_dir(d["name"]); - if (mode == MODE_OPEN_FILE || mode == MODE_OPEN_FILES || mode == MODE_OPEN_DIR || mode == MODE_OPEN_ANY) + if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES || mode == FILE_MODE_OPEN_DIR || mode == FILE_MODE_OPEN_ANY) file->set_text(""); call_deferred("_update_file_list"); call_deferred("_update_dir"); @@ -425,8 +429,8 @@ void FileDialog::update_file_list() { dir_access->list_dir_begin(); TreeItem *root = tree->create_item(); - Ref<Texture2D> folder = get_icon("folder"); - const Color folder_color = get_color("folder_icon_modulate"); + Ref<Texture2D> folder = vbox->get_theme_icon("folder", "FileDialog"); + const Color folder_color = vbox->get_theme_color("folder_icon_modulate", "FileDialog"); List<String> files; List<String> dirs; @@ -523,8 +527,8 @@ void FileDialog::update_file_list() { ti->set_icon(0, icon); } - if (mode == MODE_OPEN_DIR) { - ti->set_custom_color(0, get_color("files_disabled")); + if (mode == FILE_MODE_OPEN_DIR) { + ti->set_custom_color(0, vbox->get_theme_color("files_disabled", "FileDialog")); ti->set_selectable(0, false); } Dictionary d; @@ -539,7 +543,7 @@ void FileDialog::update_file_list() { files.pop_front(); } - if (tree->get_root() && tree->get_root()->get_children() && tree->get_selected() == NULL) + if (tree->get_root() && tree->get_root()->get_children() && tree->get_selected() == nullptr) tree->get_root()->get_children()->select(0); } @@ -661,38 +665,38 @@ bool FileDialog::is_mode_overriding_title() const { return mode_overrides_title; } -void FileDialog::set_mode(Mode p_mode) { +void FileDialog::set_file_mode(FileMode p_mode) { ERR_FAIL_INDEX((int)p_mode, 5); mode = p_mode; switch (mode) { - case MODE_OPEN_FILE: + case FILE_MODE_OPEN_FILE: get_ok()->set_text(RTR("Open")); if (mode_overrides_title) set_title(RTR("Open a File")); makedir->hide(); break; - case MODE_OPEN_FILES: + case FILE_MODE_OPEN_FILES: get_ok()->set_text(RTR("Open")); if (mode_overrides_title) set_title(RTR("Open File(s)")); makedir->hide(); break; - case MODE_OPEN_DIR: + case FILE_MODE_OPEN_DIR: get_ok()->set_text(RTR("Select Current Folder")); if (mode_overrides_title) set_title(RTR("Open a Directory")); makedir->show(); break; - case MODE_OPEN_ANY: + case FILE_MODE_OPEN_ANY: get_ok()->set_text(RTR("Open")); if (mode_overrides_title) set_title(RTR("Open a File or Directory")); makedir->show(); break; - case MODE_SAVE_FILE: + case FILE_MODE_SAVE_FILE: get_ok()->set_text(RTR("Save")); if (mode_overrides_title) set_title(RTR("Save a File")); @@ -700,14 +704,14 @@ void FileDialog::set_mode(Mode p_mode) { break; } - if (mode == MODE_OPEN_FILES) { + if (mode == FILE_MODE_OPEN_FILES) { tree->set_select_mode(Tree::SELECT_MULTI); } else { tree->set_select_mode(Tree::SELECT_SINGLE); } } -FileDialog::Mode FileDialog::get_mode() const { +FileDialog::FileMode FileDialog::get_file_mode() const { return mode; } @@ -741,7 +745,7 @@ void FileDialog::set_access(Access p_access) { void FileDialog::invalidate() { - if (is_visible_in_tree()) { + if (is_visible()) { update_file_list(); invalidated = false; } else { @@ -763,14 +767,14 @@ void FileDialog::_make_dir_confirm() { update_filters(); update_dir(); } else { - mkdirerr->popup_centered_minsize(Size2(250, 50)); + mkdirerr->popup_centered(Size2(250, 50)); } makedirname->set_text(""); // reset label } void FileDialog::_make_dir() { - makedialog->popup_centered_minsize(Size2(250, 80)); + makedialog->popup_centered(Size2(250, 80)); makedirname->grab_focus(); } @@ -826,8 +830,8 @@ void FileDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("set_current_path", "path"), &FileDialog::set_current_path); ClassDB::bind_method(D_METHOD("set_mode_overrides_title", "override"), &FileDialog::set_mode_overrides_title); ClassDB::bind_method(D_METHOD("is_mode_overriding_title"), &FileDialog::is_mode_overriding_title); - ClassDB::bind_method(D_METHOD("set_mode", "mode"), &FileDialog::set_mode); - ClassDB::bind_method(D_METHOD("get_mode"), &FileDialog::get_mode); + ClassDB::bind_method(D_METHOD("set_file_mode", "mode"), &FileDialog::set_file_mode); + ClassDB::bind_method(D_METHOD("get_file_mode"), &FileDialog::get_file_mode); ClassDB::bind_method(D_METHOD("get_vbox"), &FileDialog::get_vbox); ClassDB::bind_method(D_METHOD("get_line_edit"), &FileDialog::get_line_edit); ClassDB::bind_method(D_METHOD("set_access", "access"), &FileDialog::set_access); @@ -842,7 +846,7 @@ void FileDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("invalidate"), &FileDialog::invalidate); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "mode_overrides_title"), "set_mode_overrides_title", "is_mode_overriding_title"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Open File,Open Files,Open Folder,Open Any,Save"), "set_mode", "get_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "file_mode", PROPERTY_HINT_ENUM, "Open File,Open Files,Open Folder,Open Any,Save"), "set_file_mode", "get_file_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "access", PROPERTY_HINT_ENUM, "Resources,User data,File system"), "set_access", "get_access"); ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "filters"), "set_filters", "get_filters"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_hidden_files"), "set_show_hidden_files", "is_showing_hidden_files"); @@ -854,11 +858,11 @@ void FileDialog::_bind_methods() { ADD_SIGNAL(MethodInfo("files_selected", PropertyInfo(Variant::PACKED_STRING_ARRAY, "paths"))); ADD_SIGNAL(MethodInfo("dir_selected", PropertyInfo(Variant::STRING, "dir"))); - BIND_ENUM_CONSTANT(MODE_OPEN_FILE); - BIND_ENUM_CONSTANT(MODE_OPEN_FILES); - BIND_ENUM_CONSTANT(MODE_OPEN_DIR); - BIND_ENUM_CONSTANT(MODE_OPEN_ANY); - BIND_ENUM_CONSTANT(MODE_SAVE_FILE); + BIND_ENUM_CONSTANT(FILE_MODE_OPEN_FILE); + BIND_ENUM_CONSTANT(FILE_MODE_OPEN_FILES); + BIND_ENUM_CONSTANT(FILE_MODE_OPEN_DIR); + BIND_ENUM_CONSTANT(FILE_MODE_OPEN_ANY); + BIND_ENUM_CONSTANT(FILE_MODE_SAVE_FILE); BIND_ENUM_CONSTANT(ACCESS_RESOURCES); BIND_ENUM_CONSTANT(ACCESS_USERDATA); @@ -884,10 +888,11 @@ FileDialog::FileDialog() { mode_overrides_title = true; - VBoxContainer *vbc = memnew(VBoxContainer); - add_child(vbc); + vbox = memnew(VBoxContainer); + add_child(vbox); + vbox->connect("theme_changed", callable_mp(this, &FileDialog::_theme_changed)); - mode = MODE_SAVE_FILE; + mode = FILE_MODE_SAVE_FILE; set_title(RTR("Save a File")); HBoxContainer *hbc = memnew(HBoxContainer); @@ -904,10 +909,11 @@ FileDialog::FileDialog() { drives = memnew(OptionButton); drives->connect("item_selected", callable_mp(this, &FileDialog::_select_drive)); + hbc->add_child(drives); dir = memnew(LineEdit); hbc->add_child(dir); - dir->set_h_size_flags(SIZE_EXPAND_FILL); + dir->set_h_size_flags(Control::SIZE_EXPAND_FILL); refresh = memnew(ToolButton); refresh->set_tooltip(RTR("Refresh files.")); @@ -928,24 +934,24 @@ FileDialog::FileDialog() { makedir->set_text(RTR("Create Folder")); makedir->connect("pressed", callable_mp(this, &FileDialog::_make_dir)); hbc->add_child(makedir); - vbc->add_child(hbc); + vbox->add_child(hbc); tree = memnew(Tree); tree->set_hide_root(true); - vbc->add_margin_child(RTR("Directories & Files:"), tree, true); + vbox->add_margin_child(RTR("Directories & Files:"), tree, true); file_box = memnew(HBoxContainer); file_box->add_child(memnew(Label(RTR("File:")))); file = memnew(LineEdit); file->set_stretch_ratio(4); - file->set_h_size_flags(SIZE_EXPAND_FILL); + file->set_h_size_flags(Control::SIZE_EXPAND_FILL); file_box->add_child(file); filter = memnew(OptionButton); filter->set_stretch_ratio(3); - filter->set_h_size_flags(SIZE_EXPAND_FILL); + filter->set_h_size_flags(Control::SIZE_EXPAND_FILL); filter->set_clip_text(true); // too many extensions overflows it file_box->add_child(filter); - vbc->add_child(file_box); + vbox->add_child(file_box); dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES); access = ACCESS_RESOURCES; @@ -961,7 +967,7 @@ FileDialog::FileDialog() { filter->connect("item_selected", callable_mp(this, &FileDialog::_filter_selected)); confirm_save = memnew(ConfirmationDialog); - confirm_save->set_as_toplevel(true); + // confirm_save->set_as_toplevel(true); add_child(confirm_save); confirm_save->connect("confirmed", callable_mp(this, &FileDialog::_save_confirm_pressed)); @@ -988,7 +994,6 @@ FileDialog::FileDialog() { update_dir(); set_hide_on_ok(false); - vbox = vbc; invalidated = true; if (register_func) @@ -1001,37 +1006,3 @@ FileDialog::~FileDialog() { unregister_func(this); memdelete(dir_access); } - -void LineEditFileChooser::_bind_methods() { - - ClassDB::bind_method(D_METHOD("get_button"), &LineEditFileChooser::get_button); - ClassDB::bind_method(D_METHOD("get_line_edit"), &LineEditFileChooser::get_line_edit); - ClassDB::bind_method(D_METHOD("get_file_dialog"), &LineEditFileChooser::get_file_dialog); -} - -void LineEditFileChooser::_chosen(const String &p_text) { - - line_edit->set_text(p_text); - line_edit->emit_signal("text_entered", p_text); -} - -void LineEditFileChooser::_browse() { - - dialog->popup_centered_ratio(); -} - -LineEditFileChooser::LineEditFileChooser() { - - line_edit = memnew(LineEdit); - add_child(line_edit); - line_edit->set_h_size_flags(SIZE_EXPAND_FILL); - button = memnew(Button); - button->set_text(" .. "); - add_child(button); - button->connect("pressed", callable_mp(this, &LineEditFileChooser::_browse)); - dialog = memnew(FileDialog); - add_child(dialog); - dialog->connect("file_selected", callable_mp(this, &LineEditFileChooser::_chosen)); - dialog->connect("dir_selected", callable_mp(this, &LineEditFileChooser::_chosen)); - dialog->connect("files_selected", callable_mp(this, &LineEditFileChooser::_chosen)); -} diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index a7dc101d12..ac0e733abc 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -50,12 +50,12 @@ public: ACCESS_FILESYSTEM }; - enum Mode { - MODE_OPEN_FILE, - MODE_OPEN_FILES, - MODE_OPEN_DIR, - MODE_OPEN_ANY, - MODE_SAVE_FILE + enum FileMode { + FILE_MODE_OPEN_FILE, + FILE_MODE_OPEN_FILES, + FILE_MODE_OPEN_DIR, + FILE_MODE_OPEN_ANY, + FILE_MODE_SAVE_FILE }; typedef Ref<Texture2D> (*GetIconFunc)(const String &); @@ -74,7 +74,7 @@ private: Access access; //Button *action; VBoxContainer *vbox; - Mode mode; + FileMode mode; LineEdit *dir; HBoxContainer *drives_container; HBoxContainer *shortcuts_container; @@ -131,6 +131,8 @@ private: virtual void _post_popup(); protected: + void _theme_changed(); + void _notification(int p_what); static void _bind_methods(); //bind helpers @@ -153,8 +155,8 @@ public: void set_mode_overrides_title(bool p_override); bool is_mode_overriding_title() const; - void set_mode(Mode p_mode); - Mode get_mode() const; + void set_file_mode(FileMode p_mode); + FileMode get_file_mode() const; VBoxContainer *get_vbox(); LineEdit *get_line_edit() { return file; } @@ -175,28 +177,7 @@ public: ~FileDialog(); }; -class LineEditFileChooser : public HBoxContainer { - - GDCLASS(LineEditFileChooser, HBoxContainer); - Button *button; - LineEdit *line_edit; - FileDialog *dialog; - - void _chosen(const String &p_text); - void _browse(); - -protected: - static void _bind_methods(); - -public: - Button *get_button() { return button; } - LineEdit *get_line_edit() { return line_edit; } - FileDialog *get_file_dialog() { return dialog; } - - LineEditFileChooser(); -}; - -VARIANT_ENUM_CAST(FileDialog::Mode); +VARIANT_ENUM_CAST(FileDialog::FileMode); VARIANT_ENUM_CAST(FileDialog::Access); #endif diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp index 6345bfe562..88107f754c 100644 --- a/scene/gui/gradient_edit.cpp +++ b/scene/gui/gradient_edit.cpp @@ -76,15 +76,15 @@ void GradientEdit::_show_color_picker() { if (grabbed == -1) return; picker->set_pick_color(points[grabbed].color); - Size2 minsize = popup->get_combined_minimum_size(); + Size2 minsize = popup->get_contents_minimum_size(); bool show_above = false; if (get_global_position().y + get_size().y + minsize.y > get_viewport_rect().size.y) { show_above = true; } if (show_above) { - popup->set_position(get_global_position() - Vector2(0, minsize.y)); + popup->set_position(get_screen_position() - Vector2(0, minsize.y)); } else { - popup->set_position(get_global_position() + Vector2(0, get_size().y)); + popup->set_position(get_screen_position() + Vector2(0, get_size().y)); } popup->popup(); } diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 4bc33b220e..0fe65462e4 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -30,7 +30,7 @@ #include "graph_edit.h" -#include "core/os/input.h" +#include "core/input/input_filter.h" #include "core/os/keyboard.h" #include "scene/gui/box_container.h" @@ -281,13 +281,13 @@ void GraphEdit::remove_child_notify(Node *p_child) { void GraphEdit::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - port_grab_distance_horizontal = get_constant("port_grab_distance_horizontal"); - port_grab_distance_vertical = get_constant("port_grab_distance_vertical"); + port_grab_distance_horizontal = get_theme_constant("port_grab_distance_horizontal"); + port_grab_distance_vertical = get_theme_constant("port_grab_distance_vertical"); - zoom_minus->set_icon(get_icon("minus")); - zoom_reset->set_icon(get_icon("reset")); - zoom_plus->set_icon(get_icon("more")); - snap_button->set_icon(get_icon("snap")); + zoom_minus->set_icon(get_theme_icon("minus")); + zoom_reset->set_icon(get_theme_icon("reset")); + zoom_plus->set_icon(get_theme_icon("more")); + snap_button->set_icon(get_theme_icon("snap")); } if (p_what == NOTIFICATION_READY) { Size2 hmin = h_scroll->get_combined_minimum_size(); @@ -305,7 +305,7 @@ void GraphEdit::_notification(int p_what) { } if (p_what == NOTIFICATION_DRAW) { - draw_style_box(get_stylebox("bg"), Rect2(Point2(), get_size())); + draw_style_box(get_theme_stylebox("bg"), Rect2(Point2(), get_size())); if (is_using_snap()) { //draw grid @@ -318,8 +318,8 @@ void GraphEdit::_notification(int p_what) { Point2i from = (offset / float(snap)).floor(); Point2i len = (size / float(snap)).floor() + Vector2(1, 1); - Color grid_minor = get_color("grid_minor"); - Color grid_major = get_color("grid_major"); + Color grid_minor = get_theme_color("grid_minor"); + Color grid_major = get_theme_color("grid_major"); for (int i = from.x; i < from.x + len.x; i++) { @@ -357,7 +357,7 @@ void GraphEdit::_notification(int p_what) { bool GraphEdit::_filter_input(const Point2 &p_point) { - Ref<Texture2D> port = get_icon("port", "GraphNode"); + Ref<Texture2D> port = get_theme_icon("port", "GraphNode"); for (int i = get_child_count() - 1; i >= 0; i--) { @@ -389,7 +389,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { Ref<InputEventMouseButton> mb = p_ev; if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - Ref<Texture2D> port = get_icon("port", "GraphNode"); + Ref<Texture2D> port = get_theme_icon("port", "GraphNode"); Vector2 mpos(mb->get_position().x, mb->get_position().y); for (int i = get_child_count() - 1; i >= 0; i--) { @@ -501,7 +501,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { connecting_target = false; top_layer->update(); - Ref<Texture2D> port = get_icon("port", "GraphNode"); + Ref<Texture2D> port = get_theme_icon("port", "GraphNode"); Vector2 mpos = mm->get_position(); for (int i = get_child_count() - 1; i >= 0; i--) { @@ -666,8 +666,8 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const //cubic bezier code float diff = p_to.x - p_from.x; float cp_offset; - int cp_len = get_constant("bezier_len_pos"); - int cp_neg_len = get_constant("bezier_len_neg"); + int cp_len = get_theme_constant("bezier_len_pos"); + int cp_neg_len = get_theme_constant("bezier_len_neg"); if (diff > 0) { cp_offset = MIN(cp_len, diff * 0.5); @@ -697,7 +697,7 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const void GraphEdit::_connections_layer_draw() { - Color activity_color = get_color("activity"); + Color activity_color = get_theme_color("activity"); //draw connections List<List<Connection>::Element *> to_erase; for (List<Connection>::Element *E = connections.front(); E; E = E->next()) { @@ -784,8 +784,8 @@ void GraphEdit::_top_layer_draw() { } if (box_selecting) { - top_layer->draw_rect(box_selecting_rect, get_color("selection_fill")); - top_layer->draw_rect(box_selecting_rect, get_color("selection_stroke"), false); + top_layer->draw_rect(box_selecting_rect, get_theme_color("selection_fill")); + top_layer->draw_rect(box_selecting_rect, get_theme_color("selection_stroke"), false); } } @@ -804,7 +804,7 @@ void GraphEdit::set_selected(Node *p_child) { void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { Ref<InputEventMouseMotion> mm = p_ev; - if (mm.is_valid() && (mm->get_button_mask() & BUTTON_MASK_MIDDLE || (mm->get_button_mask() & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) { + if (mm.is_valid() && (mm->get_button_mask() & BUTTON_MASK_MIDDLE || (mm->get_button_mask() & BUTTON_MASK_LEFT && InputFilter::get_singleton()->is_key_pressed(KEY_SPACE)))) { h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x); v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y); } @@ -823,7 +823,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { // Snapping can be toggled temporarily by holding down Ctrl. // This is done here as to not toggle the grid when holding down Ctrl. - if (is_using_snap() ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { + if (is_using_snap() ^ InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) { const int snap = get_snap(); pos = pos.snapped(Vector2(snap, snap)); } @@ -852,9 +852,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { bool in_box = r.intersects(box_selecting_rect); if (in_box) - gn->set_selected(box_selection_mode_aditive); + gn->set_selected(box_selection_mode_additive); else - gn->set_selected(previus_selected.find(gn) != NULL); + gn->set_selected(previus_selected.find(gn) != nullptr); } top_layer->update(); @@ -872,7 +872,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { if (!gn) continue; - gn->set_selected(previus_selected.find(gn) != NULL); + gn->set_selected(previus_selected.find(gn) != nullptr); } top_layer->update(); } else { @@ -886,7 +886,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { } if (b->get_button_index() == BUTTON_LEFT && !b->is_pressed() && dragging) { - if (!just_selected && drag_accum == Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { + if (!just_selected && drag_accum == Vector2() && InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) { //deselect current node for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); @@ -922,7 +922,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { if (b->get_button_index() == BUTTON_LEFT && b->is_pressed()) { - GraphNode *gn = NULL; + GraphNode *gn = nullptr; for (int i = get_child_count() - 1; i >= 0; i--) { @@ -948,11 +948,19 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { drag_accum = Vector2(); drag_origin = get_local_mouse_position(); just_selected = !gn->is_selected(); - if (!gn->is_selected() && !Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { + if (!gn->is_selected() && !InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) { for (int i = 0; i < get_child_count(); i++) { GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i)); - if (o_gn) - o_gn->set_selected(o_gn == gn); + if (o_gn) { + if (o_gn == gn) { + o_gn->set_selected(true); + } else { + if (o_gn->is_selected()) { + emit_signal("node_unselected", o_gn); + } + o_gn->set_selected(false); + } + } } } @@ -968,13 +976,13 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { } else { if (_filter_input(b->get_position())) return; - if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) + if (InputFilter::get_singleton()->is_key_pressed(KEY_SPACE)) return; box_selecting = true; box_selecting_from = get_local_mouse_position(); if (b->get_control()) { - box_selection_mode_aditive = true; + box_selection_mode_additive = true; previus_selected.clear(); for (int i = get_child_count() - 1; i >= 0; i--) { @@ -985,7 +993,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { previus_selected.push_back(gn2); } } else if (b->get_shift()) { - box_selection_mode_aditive = false; + box_selection_mode_additive = false; previus_selected.clear(); for (int i = get_child_count() - 1; i >= 0; i--) { @@ -996,14 +1004,16 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { previus_selected.push_back(gn2); } } else { - box_selection_mode_aditive = true; + box_selection_mode_additive = true; previus_selected.clear(); for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i)); if (!gn2) continue; - + if (gn2->is_selected()) { + emit_signal("node_unselected", gn2); + } gn2->set_selected(false); } } @@ -1025,16 +1035,16 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { //too difficult to get right //set_zoom(zoom/ZOOM_SCALE); } - if (b->get_button_index() == BUTTON_WHEEL_UP && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (b->get_button_index() == BUTTON_WHEEL_UP && !InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * b->get_factor() / 8); } - if (b->get_button_index() == BUTTON_WHEEL_DOWN && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (b->get_button_index() == BUTTON_WHEEL_DOWN && !InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * b->get_factor() / 8); } - if (b->get_button_index() == BUTTON_WHEEL_RIGHT || (b->get_button_index() == BUTTON_WHEEL_DOWN && Input::get_singleton()->is_key_pressed(KEY_SHIFT))) { + if (b->get_button_index() == BUTTON_WHEEL_RIGHT || (b->get_button_index() == BUTTON_WHEEL_DOWN && InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT))) { h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * b->get_factor() / 8); } - if (b->get_button_index() == BUTTON_WHEEL_LEFT || (b->get_button_index() == BUTTON_WHEEL_UP && Input::get_singleton()->is_key_pressed(KEY_SHIFT))) { + if (b->get_button_index() == BUTTON_WHEEL_LEFT || (b->get_button_index() == BUTTON_WHEEL_UP && InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT))) { h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * b->get_factor() / 8); } } @@ -1311,6 +1321,7 @@ void GraphEdit::_bind_methods() { ADD_SIGNAL(MethodInfo("copy_nodes_request")); ADD_SIGNAL(MethodInfo("paste_nodes_request")); ADD_SIGNAL(MethodInfo("node_selected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); + ADD_SIGNAL(MethodInfo("node_unselected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING_NAME, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::VECTOR2, "release_position"))); ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING_NAME, "to"), PropertyInfo(Variant::INT, "to_slot"), PropertyInfo(Variant::VECTOR2, "release_position"))); ADD_SIGNAL(MethodInfo("delete_nodes_request")); @@ -1323,7 +1334,7 @@ GraphEdit::GraphEdit() { set_focus_mode(FOCUS_ALL); awaiting_scroll_offset_update = false; - top_layer = NULL; + top_layer = nullptr; top_layer = memnew(GraphEditFilter(this)); add_child(top_layer); top_layer->set_mouse_filter(MOUSE_FILTER_PASS); diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index 7f1d2699ba..f675f8c7f3 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -104,7 +104,7 @@ private: float zoom; bool box_selecting; - bool box_selection_mode_aditive; + bool box_selection_mode_additive; Point2 box_selecting_from; Point2 box_selecting_to; Rect2 box_selecting_rect; diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 82e890395a..5dbc5bc50d 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -117,8 +117,8 @@ void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const { void GraphNode::_resort() { - int sep = get_constant("separation"); - Ref<StyleBox> sb = get_stylebox("frame"); + int sep = get_theme_constant("separation"); + Ref<StyleBox> sb = get_theme_stylebox("frame"); bool first = true; Size2 minsize; @@ -169,8 +169,8 @@ void GraphNode::_resort() { bool GraphNode::has_point(const Point2 &p_point) const { if (comment) { - Ref<StyleBox> comment = get_stylebox("comment"); - Ref<Texture2D> resizer = get_icon("resizer"); + Ref<StyleBox> comment = get_theme_stylebox("comment"); + Ref<Texture2D> resizer = get_theme_icon("resizer"); if (Rect2(get_size() - resizer->get_size(), resizer->get_size()).has_point(p_point)) { return true; @@ -195,28 +195,28 @@ void GraphNode::_notification(int p_what) { Ref<StyleBox> sb; if (comment) { - sb = get_stylebox(selected ? "commentfocus" : "comment"); + sb = get_theme_stylebox(selected ? "commentfocus" : "comment"); } else { - sb = get_stylebox(selected ? "selectedframe" : "frame"); + sb = get_theme_stylebox(selected ? "selectedframe" : "frame"); } //sb=sb->duplicate(); //sb->call("set_modulate",modulate); - Ref<Texture2D> port = get_icon("port"); - Ref<Texture2D> close = get_icon("close"); - Ref<Texture2D> resizer = get_icon("resizer"); - int close_offset = get_constant("close_offset"); - int close_h_offset = get_constant("close_h_offset"); - Color close_color = get_color("close_color"); - Color resizer_color = get_color("resizer_color"); - Ref<Font> title_font = get_font("title_font"); - int title_offset = get_constant("title_offset"); - int title_h_offset = get_constant("title_h_offset"); - Color title_color = get_color("title_color"); + Ref<Texture2D> port = get_theme_icon("port"); + Ref<Texture2D> close = get_theme_icon("close"); + Ref<Texture2D> resizer = get_theme_icon("resizer"); + int close_offset = get_theme_constant("close_offset"); + int close_h_offset = get_theme_constant("close_h_offset"); + Color close_color = get_theme_color("close_color"); + Color resizer_color = get_theme_color("resizer_color"); + Ref<Font> title_font = get_theme_font("title_font"); + int title_offset = get_theme_constant("title_offset"); + int title_h_offset = get_theme_constant("title_h_offset"); + Color title_color = get_theme_color("title_color"); Point2i icofs = -port->get_size() * 0.5; - int edgeofs = get_constant("port_offset"); + int edgeofs = get_theme_constant("port_offset"); icofs.y += sb->get_margin(MARGIN_TOP); draw_style_box(sb, Rect2(Point2(), get_size())); @@ -227,10 +227,10 @@ void GraphNode::_notification(int p_what) { } break; case OVERLAY_BREAKPOINT: { - draw_style_box(get_stylebox("breakpoint"), Rect2(Point2(), get_size())); + draw_style_box(get_theme_stylebox("breakpoint"), Rect2(Point2(), get_size())); } break; case OVERLAY_POSITION: { - draw_style_box(get_stylebox("position"), Rect2(Point2(), get_size())); + draw_style_box(get_theme_stylebox("position"), Rect2(Point2(), get_size())); } break; } @@ -370,16 +370,16 @@ Color GraphNode::get_slot_color_right(int p_idx) const { Size2 GraphNode::get_minimum_size() const { - Ref<Font> title_font = get_font("title_font"); + Ref<Font> title_font = get_theme_font("title_font"); - int sep = get_constant("separation"); - Ref<StyleBox> sb = get_stylebox("frame"); + int sep = get_theme_constant("separation"); + Ref<StyleBox> sb = get_theme_stylebox("frame"); bool first = true; Size2 minsize; minsize.x = title_font->get_string_size(title).x; if (show_close) { - Ref<Texture2D> close = get_icon("close"); + Ref<Texture2D> close = get_theme_icon("close"); minsize.x += sep + close->get_width(); } @@ -464,10 +464,10 @@ bool GraphNode::is_close_button_visible() const { void GraphNode::_connpos_update() { - int edgeofs = get_constant("port_offset"); - int sep = get_constant("separation"); + int edgeofs = get_theme_constant("port_offset"); + int sep = get_theme_constant("separation"); - Ref<StyleBox> sb = get_stylebox("frame"); + Ref<StyleBox> sb = get_theme_stylebox("frame"); conn_input_cache.clear(); conn_output_cache.clear(); int vofs = 0; @@ -593,7 +593,7 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { Ref<InputEventMouseButton> mb = p_ev; if (mb.is_valid()) { - ERR_FAIL_COND_MSG(get_parent_control() == NULL, "GraphNode must be the child of a GraphEdit node."); + ERR_FAIL_COND_MSG(get_parent_control() == nullptr, "GraphNode must be the child of a GraphEdit node."); if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { @@ -606,7 +606,7 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { return; } - Ref<Texture2D> resizer = get_icon("resizer"); + Ref<Texture2D> resizer = get_theme_icon("resizer"); if (resizable && mpos.x > get_size().x - resizer->get_width() && mpos.y > get_size().y - resizer->get_height()) { diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp index 0028093a95..16f6fd0111 100644 --- a/scene/gui/grid_container.cpp +++ b/scene/gui/grid_container.cpp @@ -41,8 +41,8 @@ void GridContainer::_notification(int p_what) { Set<int> col_expanded; // Columns which have the SIZE_EXPAND flag set. Set<int> row_expanded; // Rows which have the SIZE_EXPAND flag set. - int hsep = get_constant("hseparation"); - int vsep = get_constant("vseparation"); + int hsep = get_theme_constant("hseparation"); + int vsep = get_theme_constant("vseparation"); int max_col = MIN(get_child_count(), columns); int max_row = ceil((float)get_child_count() / (float)columns); @@ -200,8 +200,8 @@ Size2 GridContainer::get_minimum_size() const { Map<int, int> col_minw; Map<int, int> row_minh; - int hsep = get_constant("hseparation"); - int vsep = get_constant("vseparation"); + int hsep = get_theme_constant("hseparation"); + int vsep = get_theme_constant("vseparation"); int max_row = 0; int max_col = 0; diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 5e662b8df0..47a5ac68d2 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -495,7 +495,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { search_string = ""; //any mousepress cancels Vector2 pos = mb->get_position(); - Ref<StyleBox> bg = get_stylebox("bg"); + Ref<StyleBox> bg = get_theme_stylebox("bg"); pos -= bg->get_offset(); pos.y += scroll_bar->get_value(); @@ -820,7 +820,7 @@ void ItemList::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - Ref<StyleBox> bg = get_stylebox("bg"); + Ref<StyleBox> bg = get_theme_stylebox("bg"); int mw = scroll_bar->get_minimum_size().x; scroll_bar->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -mw); @@ -837,18 +837,18 @@ void ItemList::_notification(int p_what) { draw_style_box(bg, Rect2(Point2(), size)); - int hseparation = get_constant("hseparation"); - int vseparation = get_constant("vseparation"); - int icon_margin = get_constant("icon_margin"); - int line_separation = get_constant("line_separation"); + int hseparation = get_theme_constant("hseparation"); + int vseparation = get_theme_constant("vseparation"); + int icon_margin = get_theme_constant("icon_margin"); + int line_separation = get_theme_constant("line_separation"); - Ref<StyleBox> sbsel = has_focus() ? get_stylebox("selected_focus") : get_stylebox("selected"); - Ref<StyleBox> cursor = has_focus() ? get_stylebox("cursor") : get_stylebox("cursor_unfocused"); + Ref<StyleBox> sbsel = has_focus() ? get_theme_stylebox("selected_focus") : get_theme_stylebox("selected"); + Ref<StyleBox> cursor = has_focus() ? get_theme_stylebox("cursor") : get_theme_stylebox("cursor_unfocused"); - Ref<Font> font = get_font("font"); - Color guide_color = get_color("guide_color"); - Color font_color = get_color("font_color"); - Color font_color_selected = get_color("font_color_selected"); + Ref<Font> font = get_theme_font("font"); + Color guide_color = get_theme_color("guide_color"); + Color font_color = get_theme_color("font_color"); + Color font_color_selected = get_theme_color("font_color_selected"); int font_height = font->get_height(); Vector<int> line_size_cache; Vector<int> line_limit_cache; @@ -859,9 +859,9 @@ void ItemList::_notification(int p_what) { } if (has_focus()) { - VisualServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), true); - draw_style_box(get_stylebox("bg_focus"), Rect2(Point2(), size)); - VisualServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), false); + RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), true); + draw_style_box(get_theme_stylebox("bg_focus"), Rect2(Point2(), size)); + RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), false); } if (shape_changed) { @@ -1251,7 +1251,7 @@ void ItemList::_scroll_changed(double) { int ItemList::get_item_at_position(const Point2 &p_pos, bool p_exact) const { Vector2 pos = p_pos; - Ref<StyleBox> bg = get_stylebox("bg"); + Ref<StyleBox> bg = get_theme_stylebox("bg"); pos -= bg->get_offset(); pos.y += scroll_bar->get_value(); @@ -1286,7 +1286,7 @@ bool ItemList::is_pos_at_end_of_items(const Point2 &p_pos) const { return true; Vector2 pos = p_pos; - Ref<StyleBox> bg = get_stylebox("bg"); + Ref<StyleBox> bg = get_theme_stylebox("bg"); pos -= bg->get_offset(); pos.y += scroll_bar->get_value(); diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index c900b35d65..bedcef2df2 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -65,7 +65,7 @@ bool Label::is_uppercase() const { int Label::get_line_height() const { - return get_font("font")->get_height(); + return get_theme_font("font")->get_height(); } void Label::_notification(int p_what) { @@ -84,7 +84,7 @@ void Label::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { if (clip) { - VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true); + RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true); } if (word_cache_dirty) @@ -94,18 +94,18 @@ void Label::_notification(int p_what) { Size2 string_size; Size2 size = get_size(); - Ref<StyleBox> style = get_stylebox("normal"); - Ref<Font> font = get_font("font"); - Color font_color = get_color("font_color"); - Color font_color_shadow = get_color("font_color_shadow"); - bool use_outline = get_constant("shadow_as_outline"); - Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); - int line_spacing = get_constant("line_spacing"); - Color font_outline_modulate = get_color("font_outline_modulate"); + Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<Font> font = get_theme_font("font"); + Color font_color = get_theme_color("font_color"); + Color font_color_shadow = get_theme_color("font_color_shadow"); + bool use_outline = get_theme_constant("shadow_as_outline"); + Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); + int line_spacing = get_theme_constant("line_spacing"); + Color font_outline_modulate = get_theme_color("font_outline_modulate"); style->draw(ci, Rect2(Point2(0, 0), get_size())); - VisualServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(), font.is_valid() && font->is_distance_field_hint()); + RenderingServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(), font.is_valid() && font->is_distance_field_hint()); int font_h = font->get_height() + line_spacing; @@ -282,7 +282,7 @@ void Label::_notification(int p_what) { from = from->next; } - wc = to ? to->next : 0; + wc = to ? to->next : nullptr; line++; } } @@ -300,7 +300,7 @@ void Label::_notification(int p_what) { Size2 Label::get_minimum_size() const { - Size2 min_style = get_stylebox("normal")->get_minimum_size(); + Size2 min_style = get_theme_stylebox("normal")->get_minimum_size(); // don't want to mutable everything if (word_cache_dirty) { @@ -319,7 +319,7 @@ Size2 Label::get_minimum_size() const { int Label::get_longest_line_width() const { - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); real_t max_line_width = 0; real_t line_width = 0; @@ -363,9 +363,9 @@ int Label::get_line_count() const { int Label::get_visible_line_count() const { - int line_spacing = get_constant("line_spacing"); - int font_h = get_font("font")->get_height() + line_spacing; - int lines_visible = (get_size().height - get_stylebox("normal")->get_minimum_size().height + line_spacing) / font_h; + int line_spacing = get_theme_constant("line_spacing"); + int font_h = get_theme_font("font")->get_height() + line_spacing; + int lines_visible = (get_size().height - get_theme_stylebox("normal")->get_minimum_size().height + line_spacing) / font_h; if (lines_visible > line_count) lines_visible = line_count; @@ -387,24 +387,24 @@ void Label::regenerate_word_cache() { int width; if (autowrap) { - Ref<StyleBox> style = get_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox("normal"); width = MAX(get_size().width, get_custom_minimum_size().width) - style->get_minimum_size().width; } else { width = get_longest_line_width(); } - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); real_t current_word_size = 0; int word_pos = 0; real_t line_width = 0; int space_count = 0; real_t space_width = font->get_char_size(' ').width; - int line_spacing = get_constant("line_spacing"); + int line_spacing = get_theme_constant("line_spacing"); line_count = 1; total_char_cache = 0; - WordCache *last = NULL; + WordCache *last = nullptr; for (int i = 0; i <= xl_text.length(); i++) { @@ -447,7 +447,7 @@ void Label::regenerate_word_cache() { } if (i < xl_text.length() && xl_text[i] == ' ') { - if (line_width > 0 || last == NULL || last->char_pos != WordCache::CHAR_WRAPLINE) { + if (line_width > 0 || last == nullptr || last->char_pos != WordCache::CHAR_WRAPLINE) { space_count++; line_width += space_width; } else { @@ -697,7 +697,7 @@ Label::Label(const String &p_text) { align = ALIGN_LEFT; valign = VALIGN_TOP; xl_text = ""; - word_cache = NULL; + word_cache = nullptr; word_cache_dirty = true; autowrap = false; line_count = 0; diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 73380c6b1b..b9b7560f2e 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -36,12 +36,12 @@ #include "core/print_string.h" #include "core/translation.h" #include "label.h" - +#include "servers/display_server.h" #ifdef TOOLS_ENABLED #include "editor/editor_scale.h" #include "editor/editor_settings.h" #endif - +#include "scene/main/window.h" static bool _is_text_char(CharType c) { return !is_symbol(c); @@ -56,7 +56,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { if (b->is_pressed() && b->get_button_index() == BUTTON_RIGHT && context_menu_enabled) { menu->set_position(get_global_transform().xform(get_local_mouse_position())); menu->set_size(Vector2(1, 1)); - menu->set_scale(get_global_transform().get_scale()); + //menu->set_scale(get_global_transform().get_scale()); menu->popup(); grab_focus(); accept_event(); @@ -127,8 +127,8 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { selection.creating = false; selection.doubleclick = false; - if (OS::get_singleton()->has_virtual_keyboard()) - OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), max_length); + if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) + DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), max_length); } update(); @@ -304,10 +304,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { case KEY_ENTER: { emit_signal("text_entered", text); - if (OS::get_singleton()->has_virtual_keyboard()) - OS::get_singleton()->hide_virtual_keyboard(); + if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) + DisplayServer::get_singleton()->virtual_keyboard_hide(); - return; } break; case KEY_BACKSPACE: { @@ -553,10 +552,10 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { } break; case KEY_MENU: { if (context_menu_enabled) { - Point2 pos = Point2(get_cursor_pixel_pos(), (get_size().y + get_font("font")->get_height()) / 2); + Point2 pos = Point2(get_cursor_pixel_pos(), (get_size().y + get_theme_font("font")->get_height()) / 2); menu->set_position(get_global_transform().xform(pos)); menu->set_size(Vector2(1, 1)); - menu->set_scale(get_global_transform().get_scale()); + // menu->set_scale(get_global_transform().get_scale()); menu->popup(); menu->grab_focus(); } @@ -630,10 +629,10 @@ void LineEdit::drop_data(const Point2 &p_point, const Variant &p_data) { set_cursor_at_pixel_pos(p_point.x); int selected = selection.end - selection.begin; - Ref<Font> font = get_font("font"); - if (font != NULL) { + Ref<Font> font = get_theme_font("font"); + if (font != nullptr) { for (int i = selection.begin; i < selection.end; i++) - cached_width -= font->get_char_size(text[i]).width; + cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width; } text.erase(selection.begin, selected); @@ -655,8 +654,8 @@ bool LineEdit::_is_over_clear_button(const Point2 &p_pos) const { if (!clear_button_enabled || !has_point(p_pos)) { return false; } - Ref<Texture2D> icon = Control::get_icon("clear"); - int x_ofs = get_stylebox("normal")->get_offset().x; + Ref<Texture2D> icon = Control::get_theme_icon("clear"); + int x_ofs = get_theme_stylebox("normal")->get_offset().x; return p_pos.x > get_size().width - icon->get_width() - x_ofs; } @@ -686,12 +685,12 @@ void LineEdit::_notification(int p_what) { update_placeholder_width(); update(); } break; - case MainLoop::NOTIFICATION_WM_FOCUS_IN: { + case NOTIFICATION_WM_FOCUS_IN: { window_has_focus = true; draw_caret = true; update(); } break; - case MainLoop::NOTIFICATION_WM_FOCUS_OUT: { + case NOTIFICATION_WM_FOCUS_OUT: { window_has_focus = false; draw_caret = false; update(); @@ -710,19 +709,19 @@ void LineEdit::_notification(int p_what) { RID ci = get_canvas_item(); - Ref<StyleBox> style = get_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox("normal"); if (!is_editable()) { - style = get_stylebox("read_only"); + style = get_theme_stylebox("read_only"); draw_caret = false; } - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); style->draw(ci, Rect2(Point2(), size)); if (has_focus()) { - get_stylebox("focus")->draw(ci, Rect2(Point2(), size)); + get_theme_stylebox("focus")->draw(ci, Rect2(Point2(), size)); } int x_ofs = 0; @@ -757,10 +756,10 @@ void LineEdit::_notification(int p_what) { int font_ascent = font->get_ascent(); - Color selection_color = get_color("selection_color"); - Color font_color = is_editable() ? get_color("font_color") : get_color("font_color_uneditable"); - Color font_color_selected = get_color("font_color_selected"); - Color cursor_color = get_color("cursor_color"); + Color selection_color = get_theme_color("selection_color"); + Color font_color = is_editable() ? get_theme_color("font_color") : get_theme_color("font_color_uneditable"); + Color font_color_selected = get_theme_color("font_color_selected"); + Color cursor_color = get_theme_color("cursor_color"); const String &t = using_placeholder ? placeholder_translated : text; // Draw placeholder color. @@ -769,13 +768,13 @@ void LineEdit::_notification(int p_what) { bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled; if (right_icon.is_valid() || display_clear_icon) { - Ref<Texture2D> r_icon = display_clear_icon ? Control::get_icon("clear") : right_icon; + Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon; Color color_icon(1, 1, 1, !is_editable() ? .5 * .9 : .9); if (display_clear_icon) { if (clear_button_status.press_attempt && clear_button_status.pressing_inside) { - color_icon = get_color("clear_button_color_pressed"); + color_icon = get_theme_color("clear_button_color_pressed"); } else { - color_icon = get_color("clear_button_color"); + color_icon = get_theme_color("clear_button_color"); } } @@ -816,9 +815,9 @@ void LineEdit::_notification(int p_what) { bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y; if (selected) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 3)), font_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 3)), font_color); } else { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 1)), font_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 1)), font_color); } drawer.draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, font_color); @@ -840,7 +839,7 @@ void LineEdit::_notification(int p_what) { bool selected = selection.enabled && char_ofs >= selection.begin && char_ofs < selection.end; if (selected) - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, caret_height)), selection_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, caret_height)), selection_color); int yofs = y_ofs + (caret_height - font->get_height()) / 2; drawer.draw_char(ci, Point2(x_ofs, yofs + font_ascent), cchar, next, selected ? font_color_selected : font_color); @@ -848,9 +847,9 @@ void LineEdit::_notification(int p_what) { if (char_ofs == cursor_pos && draw_caret && !using_placeholder) { if (ime_text.length() == 0) { #ifdef TOOLS_ENABLED - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(Math::round(EDSCALE), caret_height)), cursor_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(Math::round(EDSCALE), caret_height)), cursor_color); #else - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(1, caret_height)), cursor_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(1, caret_height)), cursor_color); #endif } } @@ -875,9 +874,9 @@ void LineEdit::_notification(int p_what) { bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y; if (selected) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 3)), font_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 3)), font_color); } else { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 1)), font_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 1)), font_color); } drawer.draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, font_color); @@ -906,17 +905,18 @@ void LineEdit::_notification(int p_what) { } } #ifdef TOOLS_ENABLED - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(caret_x_ofs, y_ofs), Size2(Math::round(EDSCALE), caret_height)), cursor_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(caret_x_ofs, y_ofs), Size2(Math::round(EDSCALE), caret_height)), cursor_color); #else - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(caret_x_ofs, y_ofs), Size2(1, caret_height)), cursor_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(caret_x_ofs, y_ofs), Size2(1, caret_height)), cursor_color); #endif } } if (has_focus()) { - - OS::get_singleton()->set_ime_active(true); - OS::get_singleton()->set_ime_position(get_global_position() + Point2(using_placeholder ? 0 : x_ofs, y_ofs + caret_height)); + if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id()); + DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + Point2(using_placeholder ? 0 : x_ofs, y_ofs + caret_height), get_viewport()->get_window_id()); + } } } break; case NOTIFICATION_FOCUS_ENTER: { @@ -927,12 +927,14 @@ void LineEdit::_notification(int p_what) { draw_caret = true; } - OS::get_singleton()->set_ime_active(true); - Point2 cursor_pos = Point2(get_cursor_position(), 1) * get_minimum_size().height; - OS::get_singleton()->set_ime_position(get_global_position() + cursor_pos); + if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id()); + Point2 cursor_pos = Point2(get_cursor_position(), 1) * get_minimum_size().height; + DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + cursor_pos, get_viewport()->get_window_id()); + } - if (OS::get_singleton()->has_virtual_keyboard()) - OS::get_singleton()->show_virtual_keyboard(text, get_global_rect(), max_length); + if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) + DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), max_length); } break; case NOTIFICATION_FOCUS_EXIT: { @@ -941,20 +943,22 @@ void LineEdit::_notification(int p_what) { caret_blink_timer->stop(); } - OS::get_singleton()->set_ime_position(Point2()); - OS::get_singleton()->set_ime_active(false); + if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_ime_position(Point2(), get_viewport()->get_window_id()); + DisplayServer::get_singleton()->window_set_ime_active(false, get_viewport()->get_window_id()); + } ime_text = ""; ime_selection = Point2(); - if (OS::get_singleton()->has_virtual_keyboard()) - OS::get_singleton()->hide_virtual_keyboard(); + if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) + DisplayServer::get_singleton()->virtual_keyboard_hide(); } break; case MainLoop::NOTIFICATION_OS_IME_UPDATE: { if (has_focus()) { - ime_text = OS::get_singleton()->get_ime_text(); - ime_selection = OS::get_singleton()->get_ime_selection(); + ime_text = DisplayServer::get_singleton()->ime_get_text(); + ime_selection = DisplayServer::get_singleton()->ime_get_selection(); update(); } } break; @@ -964,14 +968,14 @@ void LineEdit::_notification(int p_what) { void LineEdit::copy_text() { if (selection.enabled && !pass) { - OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin)); + DisplayServer::get_singleton()->clipboard_set(text.substr(selection.begin, selection.end - selection.begin)); } } void LineEdit::cut_text() { if (selection.enabled && !pass) { - OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin)); + DisplayServer::get_singleton()->clipboard_set(text.substr(selection.begin, selection.end - selection.begin)); selection_delete(); } } @@ -979,7 +983,7 @@ void LineEdit::cut_text() { void LineEdit::paste_text() { // Strip escape characters like \n and \t as they can't be displayed on LineEdit. - String paste_buffer = OS::get_singleton()->get_clipboard().strip_escapes(); + String paste_buffer = DisplayServer::get_singleton()->clipboard_get().strip_escapes(); if (paste_buffer != "") { @@ -997,7 +1001,7 @@ void LineEdit::paste_text() { } void LineEdit::undo() { - if (undo_stack_pos == NULL) { + if (undo_stack_pos == nullptr) { if (undo_stack.size() <= 1) { return; } @@ -1019,7 +1023,7 @@ void LineEdit::undo() { } void LineEdit::redo() { - if (undo_stack_pos == NULL) { + if (undo_stack_pos == nullptr) { return; } if (undo_stack_pos == undo_stack.back()) { @@ -1055,13 +1059,13 @@ void LineEdit::shift_selection_check_post(bool p_shift) { void LineEdit::set_cursor_at_pixel_pos(int p_x) { - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); int ofs = window_pos; - Ref<StyleBox> style = get_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox("normal"); int pixel_ofs = 0; Size2 size = get_size(); bool display_clear_icon = !text.empty() && is_editable() && clear_button_enabled; - int r_icon_width = Control::get_icon("clear")->get_width(); + int r_icon_width = Control::get_theme_icon("clear")->get_width(); switch (align) { @@ -1092,12 +1096,8 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) { while (ofs < text.length()) { int char_w = 0; - if (font != NULL) { - if (is_secret()) { - char_w = font->get_char_size(secret_character[0]).width; - } else { - char_w = font->get_char_size(text[ofs]).width; - } + if (font != nullptr) { + char_w = font->get_char_size(pass ? secret_character[0] : text[ofs]).width; } pixel_ofs += char_w; @@ -1113,13 +1113,13 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) { int LineEdit::get_cursor_pixel_pos() { - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); int ofs = window_pos; - Ref<StyleBox> style = get_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox("normal"); int pixel_ofs = 0; Size2 size = get_size(); bool display_clear_icon = !text.empty() && is_editable() && clear_button_enabled; - int r_icon_width = Control::get_icon("clear")->get_width(); + int r_icon_width = Control::get_theme_icon("clear")->get_width(); switch (align) { @@ -1148,8 +1148,8 @@ int LineEdit::get_cursor_pixel_pos() { } while (ofs < cursor_pos) { - if (font != NULL) { - pixel_ofs += font->get_char_size(text[ofs]).width; + if (font != nullptr) { + pixel_ofs += font->get_char_size(pass ? secret_character[0] : text[ofs]).width; } ofs++; } @@ -1206,9 +1206,9 @@ void LineEdit::delete_char() { if ((text.length() <= 0) || (cursor_pos == 0)) return; - Ref<Font> font = get_font("font"); - if (font != NULL) { - cached_width -= font->get_char_size(text[cursor_pos - 1]).width; + Ref<Font> font = get_theme_font("font"); + if (font != nullptr) { + cached_width -= font->get_char_size(pass ? secret_character[0] : text[cursor_pos - 1]).width; } text.erase(cursor_pos - 1, 1); @@ -1225,10 +1225,10 @@ void LineEdit::delete_char() { void LineEdit::delete_text(int p_from_column, int p_to_column) { if (text.size() > 0) { - Ref<Font> font = get_font("font"); - if (font != NULL) { + Ref<Font> font = get_theme_font("font"); + if (font != nullptr) { for (int i = p_from_column; i < p_to_column; i++) - cached_width -= font->get_char_size(text[i]).width; + cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width; } } else { cached_width = 0; @@ -1323,8 +1323,8 @@ void LineEdit::set_cursor_position(int p_pos) { return; } - Ref<StyleBox> style = get_stylebox("normal"); - Ref<Font> font = get_font("font"); + Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<Font> font = get_theme_font("font"); if (cursor_pos <= window_pos) { // Adjust window if cursor goes too much to the left. @@ -1334,7 +1334,7 @@ void LineEdit::set_cursor_position(int p_pos) { int window_width = get_size().width - style->get_minimum_size().width; bool display_clear_icon = !text.empty() && is_editable() && clear_button_enabled; if (right_icon.is_valid() || display_clear_icon) { - Ref<Texture2D> r_icon = display_clear_icon ? Control::get_icon("clear") : right_icon; + Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon; window_width -= r_icon->get_width(); } @@ -1352,7 +1352,11 @@ void LineEdit::set_cursor_position(int p_pos) { // Do not do this, because if the cursor is at the end, its just fine that it takes no space. // accum_width = font->get_char_size(' ').width; } else { - accum_width += font->get_char_size(text[i], i + 1 < text.length() ? text[i + 1] : 0).width; // Anything should do. + if (pass) { + accum_width += font->get_char_size(secret_character[0], i + 1 < text.length() ? secret_character[0] : 0).width; + } else { + accum_width += font->get_char_size(text[i], i + 1 < text.length() ? text[i + 1] : 0).width; // Anything should do. + } } if (accum_width > window_width) break; @@ -1405,14 +1409,14 @@ void LineEdit::clear_internal() { Size2 LineEdit::get_minimum_size() const { - Ref<StyleBox> style = get_stylebox("normal"); - Ref<Font> font = get_font("font"); + Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<Font> font = get_theme_font("font"); Size2 min_size; // Minimum size of text. int space_size = font->get_char_size(' ').x; - min_size.width = get_constant("minimum_spaces") * space_size; + min_size.width = get_theme_constant("minimum_spaces") * space_size; if (expand_to_text_length) { // Add a space because some fonts are too exact, and because cursor needs a bit more when at the end. @@ -1423,8 +1427,8 @@ Size2 LineEdit::get_minimum_size() const { // Take icons into account. if (!text.empty() && is_editable() && clear_button_enabled) { - min_size.width = MAX(min_size.width, Control::get_icon("clear")->get_width()); - min_size.height = MAX(min_size.height, Control::get_icon("clear")->get_height()); + min_size.width = MAX(min_size.width, Control::get_theme_icon("clear")->get_width()); + min_size.height = MAX(min_size.height, Control::get_theme_icon("clear")->get_height()); } if (right_icon.is_valid()) { min_size.width = MAX(min_size.width, right_icon->get_width()); @@ -1703,9 +1707,9 @@ void LineEdit::_emit_text_change() { } void LineEdit::update_cached_width() { - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); cached_width = 0; - if (font != NULL) { + if (font != nullptr) { String text = get_text(); for (int i = 0; i < text.length(); i++) { cached_width += font->get_char_size(pass ? secret_character[0] : text[i]).width; @@ -1714,9 +1718,9 @@ void LineEdit::update_cached_width() { } void LineEdit::update_placeholder_width() { - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); cached_placeholder_width = 0; - if (font != NULL) { + if (font != nullptr) { for (int i = 0; i < placeholder_translated.length(); i++) { cached_placeholder_width += font->get_char_size(placeholder_translated[i]).width; } @@ -1725,7 +1729,7 @@ void LineEdit::update_placeholder_width() { void LineEdit::_clear_redo() { _create_undo_state(); - if (undo_stack_pos == NULL) { + if (undo_stack_pos == nullptr) { return; } @@ -1740,7 +1744,7 @@ void LineEdit::_clear_redo() { void LineEdit::_clear_undo_stack() { undo_stack.clear(); - undo_stack_pos = NULL; + undo_stack_pos = nullptr; _create_undo_state(); } @@ -1861,7 +1865,7 @@ void LineEdit::_bind_methods() { LineEdit::LineEdit() { - undo_stack_pos = NULL; + undo_stack_pos = nullptr; _create_undo_state(); align = ALIGN_LEFT; cached_width = 0; diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp index 4b8054bac6..3dffa06b49 100644 --- a/scene/gui/link_button.cpp +++ b/scene/gui/link_button.cpp @@ -54,7 +54,7 @@ LinkButton::UnderlineMode LinkButton::get_underline_mode() const { Size2 LinkButton::get_minimum_size() const { - return get_font("font")->get_string_size(text); + return get_theme_font("font")->get_string_size(text); } void LinkButton::_notification(int p_what) { @@ -72,29 +72,29 @@ void LinkButton::_notification(int p_what) { case DRAW_NORMAL: { - color = get_color("font_color"); + color = get_theme_color("font_color"); do_underline = underline_mode == UNDERLINE_MODE_ALWAYS; } break; case DRAW_HOVER_PRESSED: case DRAW_PRESSED: { - if (has_color("font_color_pressed")) - color = get_color("font_color_pressed"); + if (has_theme_color("font_color_pressed")) + color = get_theme_color("font_color_pressed"); else - color = get_color("font_color"); + color = get_theme_color("font_color"); do_underline = underline_mode != UNDERLINE_MODE_NEVER; } break; case DRAW_HOVER: { - color = get_color("font_color_hover"); + color = get_theme_color("font_color_hover"); do_underline = underline_mode != UNDERLINE_MODE_NEVER; } break; case DRAW_DISABLED: { - color = get_color("font_color_disabled"); + color = get_theme_color("font_color_disabled"); do_underline = underline_mode == UNDERLINE_MODE_ALWAYS; } break; @@ -102,16 +102,16 @@ void LinkButton::_notification(int p_what) { if (has_focus()) { - Ref<StyleBox> style = get_stylebox("focus"); + Ref<StyleBox> style = get_theme_stylebox("focus"); style->draw(ci, Rect2(Point2(), size)); } - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); draw_string(font, Vector2(0, font->get_ascent()), text, color); if (do_underline) { - int underline_spacing = get_constant("underline_spacing"); + int underline_spacing = get_theme_constant("underline_spacing"); int width = font->get_string_size(text).width; int y = font->get_ascent() + underline_spacing; diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp index 53373fc297..1cd4ff4ff8 100644 --- a/scene/gui/margin_container.cpp +++ b/scene/gui/margin_container.cpp @@ -32,10 +32,10 @@ Size2 MarginContainer::get_minimum_size() const { - int margin_left = get_constant("margin_left"); - int margin_top = get_constant("margin_top"); - int margin_right = get_constant("margin_right"); - int margin_bottom = get_constant("margin_bottom"); + int margin_left = get_theme_constant("margin_left"); + int margin_top = get_theme_constant("margin_top"); + int margin_right = get_theme_constant("margin_right"); + int margin_bottom = get_theme_constant("margin_bottom"); Size2 max; @@ -67,10 +67,10 @@ void MarginContainer::_notification(int p_what) { switch (p_what) { case NOTIFICATION_SORT_CHILDREN: { - int margin_left = get_constant("margin_left"); - int margin_top = get_constant("margin_top"); - int margin_right = get_constant("margin_right"); - int margin_bottom = get_constant("margin_bottom"); + int margin_left = get_theme_constant("margin_left"); + int margin_top = get_theme_constant("margin_top"); + int margin_right = get_theme_constant("margin_right"); + int margin_bottom = get_theme_constant("margin_bottom"); Size2 s = get_size(); diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 2b163187c5..a7d1f64e93 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -31,7 +31,7 @@ #include "menu_button.h" #include "core/os/keyboard.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) { @@ -43,23 +43,34 @@ void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) { if (!get_parent() || !is_visible_in_tree() || is_disabled()) return; - bool global_only = (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this)); - - if (popup->activate_item_by_event(p_event, global_only)) + //bool global_only = (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this)); + //if (popup->activate_item_by_event(p_event, global_only)) + // accept_event(); + if (popup->activate_item_by_event(p_event, false)) accept_event(); } } void MenuButton::pressed() { - emit_signal("about_to_show"); + { + Window *w = Object::cast_to<Window>(get_viewport()); + if (w && !w->is_embedding_subwindows()) { + print_line("windowpos: " + w->get_position()); + } + } Size2 size = get_size(); - Point2 gp = get_global_position(); - popup->set_global_position(gp + Size2(0, size.height * get_global_transform().get_scale().y)); + Point2 gp = get_screen_position(); + + print_line("screenpos: " + gp); + gp.y += get_size().y; + + popup->set_position(gp); + popup->set_size(Size2(size.width, 0)); - popup->set_scale(get_global_transform().get_scale()); - popup->set_parent_rect(Rect2(Point2(gp - popup->get_global_position()), get_size())); + popup->set_parent_rect(Rect2(Point2(gp - popup->get_position()), get_size())); + popup->take_mouse_focus(); popup->popup(); } @@ -116,7 +127,7 @@ void MenuButton::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "switch_on_hover"), "set_switch_on_hover", "is_switch_on_hover"); - ADD_SIGNAL(MethodInfo("about_to_show")); + ADD_SIGNAL(MethodInfo("about_to_popup")); } void MenuButton::set_disable_shortcuts(bool p_disabled) { @@ -137,8 +148,7 @@ MenuButton::MenuButton() { popup = memnew(PopupMenu); popup->hide(); add_child(popup); - popup->set_pass_on_modal_close_click(false); - popup->connect("about_to_show", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(true)); // For when switching from another MenuButton. + popup->connect("about_to_popup", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(true)); // For when switching from another MenuButton. popup->connect("popup_hide", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(false)); } diff --git a/scene/gui/nine_patch_rect.cpp b/scene/gui/nine_patch_rect.cpp index 0ef1f53006..cf10c4cfbd 100644 --- a/scene/gui/nine_patch_rect.cpp +++ b/scene/gui/nine_patch_rect.cpp @@ -30,7 +30,7 @@ #include "nine_patch_rect.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" void NinePatchRect::_notification(int p_what) { @@ -45,7 +45,7 @@ void NinePatchRect::_notification(int p_what) { texture->get_rect_region(rect, src_rect, rect, src_rect); RID ci = get_canvas_item(); - VS::get_singleton()->canvas_item_add_nine_patch(ci, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NinePatchAxisMode(axis_h), VS::NinePatchAxisMode(axis_v), draw_center); + RS::get_singleton()->canvas_item_add_nine_patch(ci, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center); } } diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index c185761beb..a03d6d0cdc 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -36,12 +36,12 @@ Size2 OptionButton::get_minimum_size() const { Size2 minsize = Button::get_minimum_size(); - if (has_icon("arrow")) { - const Size2 padding = get_stylebox("normal")->get_minimum_size(); - const Size2 arrow_size = Control::get_icon("arrow")->get_size(); + if (has_theme_icon("arrow")) { + const Size2 padding = get_theme_stylebox("normal")->get_minimum_size(); + const Size2 arrow_size = Control::get_theme_icon("arrow")->get_size(); Size2 content_size = minsize - padding; - content_size.width += arrow_size.width + get_constant("hseparation"); + content_size.width += arrow_size.width + get_theme_constant("hseparation"); content_size.height = MAX(content_size.height, arrow_size.height); minsize = content_size + padding; @@ -55,37 +55,37 @@ void OptionButton::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - if (!has_icon("arrow")) + if (!has_theme_icon("arrow")) return; RID ci = get_canvas_item(); - Ref<Texture2D> arrow = Control::get_icon("arrow"); + Ref<Texture2D> arrow = Control::get_theme_icon("arrow"); Color clr = Color(1, 1, 1); - if (get_constant("modulate_arrow")) { + if (get_theme_constant("modulate_arrow")) { switch (get_draw_mode()) { case DRAW_PRESSED: - clr = get_color("font_color_pressed"); + clr = get_theme_color("font_color_pressed"); break; case DRAW_HOVER: - clr = get_color("font_color_hover"); + clr = get_theme_color("font_color_hover"); break; case DRAW_DISABLED: - clr = get_color("font_color_disabled"); + clr = get_theme_color("font_color_disabled"); break; default: - clr = get_color("font_color"); + clr = get_theme_color("font_color"); } } Size2 size = get_size(); - Point2 ofs(size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2))); + Point2 ofs(size.width - arrow->get_width() - get_theme_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2))); arrow->draw(ci, ofs, clr); } break; case NOTIFICATION_THEME_CHANGED: { - if (has_icon("arrow")) { - _set_internal_margin(MARGIN_RIGHT, Control::get_icon("arrow")->get_width()); + if (has_theme_icon("arrow")) { + _set_internal_margin(MARGIN_RIGHT, Control::get_theme_icon("arrow")->get_width()); } } break; case NOTIFICATION_VISIBILITY_CHANGED: { @@ -109,9 +109,8 @@ void OptionButton::_selected(int p_which) { void OptionButton::pressed() { Size2 size = get_size(); - popup->set_global_position(get_global_position() + Size2(0, size.height * get_global_transform().get_scale().y)); + popup->set_position(get_screen_position() + Size2(0, size.height * get_global_transform().get_scale().y)); popup->set_size(Size2(size.width, 0)); - popup->set_scale(get_global_transform().get_scale()); popup->popup(); } @@ -341,8 +340,8 @@ void OptionButton::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items"); // "selected" property must come after "items", otherwise GH-10213 occurs. ADD_PROPERTY(PropertyInfo(Variant::INT, "selected"), "_select_int", "get_selected"); - ADD_SIGNAL(MethodInfo("item_selected", PropertyInfo(Variant::INT, "id"))); - ADD_SIGNAL(MethodInfo("item_focused", PropertyInfo(Variant::INT, "id"))); + ADD_SIGNAL(MethodInfo("item_selected", PropertyInfo(Variant::INT, "index"))); + ADD_SIGNAL(MethodInfo("item_focused", PropertyInfo(Variant::INT, "index"))); } OptionButton::OptionButton() { @@ -351,15 +350,15 @@ OptionButton::OptionButton() { set_toggle_mode(true); set_text_align(ALIGN_LEFT); set_action_mode(ACTION_MODE_BUTTON_PRESS); - if (has_icon("arrow")) { - _set_internal_margin(MARGIN_RIGHT, Control::get_icon("arrow")->get_width()); + if (has_theme_icon("arrow")) { + _set_internal_margin(MARGIN_RIGHT, Control::get_theme_icon("arrow")->get_width()); } popup = memnew(PopupMenu); popup->hide(); add_child(popup); - popup->set_pass_on_modal_close_click(false); - popup->set_notify_transform(true); + // popup->set_pass_on_modal_close_click(false); + // popup->set_notify_transform(true); popup->set_allow_search(true); popup->connect("index_pressed", callable_mp(this, &OptionButton::_selected)); popup->connect("id_focused", callable_mp(this, &OptionButton::_focused)); diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp index 0356607071..a17d0eb9c6 100644 --- a/scene/gui/panel.cpp +++ b/scene/gui/panel.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "panel.h" + #include "core/print_string.h" void Panel::_notification(int p_what) { @@ -36,11 +37,29 @@ void Panel::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { RID ci = get_canvas_item(); - Ref<StyleBox> style = get_stylebox("panel"); + Ref<StyleBox> style = mode == MODE_BACKGROUND ? get_theme_stylebox("panel") : get_theme_stylebox("panel_fg"); style->draw(ci, Rect2(Point2(), get_size())); } } +void Panel::set_mode(Mode p_mode) { + mode = p_mode; + update(); +} +Panel::Mode Panel::get_mode() const { + return mode; +} + +void Panel::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_mode", "mode"), &Panel::set_mode); + ClassDB::bind_method(D_METHOD("get_mode"), &Panel::get_mode); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Background,Foreground"), "set_mode", "get_mode"); + + BIND_ENUM_CONSTANT(MODE_BACKGROUND); + BIND_ENUM_CONSTANT(MODE_FOREGROUND); +} + Panel::Panel() { // Has visible stylebox, so stop by default. set_mouse_filter(MOUSE_FILTER_STOP); diff --git a/scene/gui/panel.h b/scene/gui/panel.h index 3538126d22..75e266b6a6 100644 --- a/scene/gui/panel.h +++ b/scene/gui/panel.h @@ -37,12 +37,27 @@ class Panel : public Control { GDCLASS(Panel, Control); +public: + enum Mode { + MODE_BACKGROUND, + MODE_FOREGROUND, + }; + +private: + Mode mode = MODE_BACKGROUND; + protected: void _notification(int p_what); + static void _bind_methods(); public: + void set_mode(Mode p_mode); + Mode get_mode() const; + Panel(); ~Panel(); }; -#endif +VARIANT_ENUM_CAST(Panel::Mode) + +#endif // PANEL_H diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp index 6cf23b8a32..62b9296409 100644 --- a/scene/gui/panel_container.cpp +++ b/scene/gui/panel_container.cpp @@ -34,16 +34,16 @@ Size2 PanelContainer::get_minimum_size() const { Ref<StyleBox> style; - if (has_stylebox("panel")) - style = get_stylebox("panel"); + if (has_theme_stylebox("panel")) + style = get_theme_stylebox("panel"); else - style = get_stylebox("panel", "PanelContainer"); + style = get_theme_stylebox("panel", "PanelContainer"); Size2 ms; for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || !c->is_visible_in_tree()) + if (!c || !c->is_visible()) continue; if (c->is_set_as_toplevel()) continue; @@ -65,10 +65,10 @@ void PanelContainer::_notification(int p_what) { RID ci = get_canvas_item(); Ref<StyleBox> style; - if (has_stylebox("panel")) - style = get_stylebox("panel"); + if (has_theme_stylebox("panel")) + style = get_theme_stylebox("panel"); else - style = get_stylebox("panel", "PanelContainer"); + style = get_theme_stylebox("panel", "PanelContainer"); style->draw(ci, Rect2(Point2(), get_size())); } @@ -77,10 +77,10 @@ void PanelContainer::_notification(int p_what) { Ref<StyleBox> style; - if (has_stylebox("panel")) - style = get_stylebox("panel"); + if (has_theme_stylebox("panel")) + style = get_theme_stylebox("panel"); else - style = get_stylebox("panel", "PanelContainer"); + style = get_theme_stylebox("panel", "PanelContainer"); Size2 size = get_size(); Point2 ofs; diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 64ef4a01f6..6edafc65a0 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -32,227 +32,131 @@ #include "core/engine.h" #include "core/os/keyboard.h" +#include "scene/gui/panel.h" -void Popup::_gui_input(Ref<InputEvent> p_event) { -} - -void Popup::_notification(int p_what) { - - if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - if (popped_up && !is_visible_in_tree()) { - popped_up = false; - notification(NOTIFICATION_POPUP_HIDE); - emit_signal("popup_hide"); - } - - update_configuration_warning(); - } - - if (p_what == NOTIFICATION_EXIT_TREE) { - if (popped_up) { - popped_up = false; - notification(NOTIFICATION_POPUP_HIDE); - emit_signal("popup_hide"); - } - } - - if (p_what == NOTIFICATION_ENTER_TREE) { -//small helper to make editing of these easier in editor -#ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { - //edited on editor - set_as_toplevel(false); - } else -#endif - if (is_visible()) { - hide(); - } +void Popup::_input_from_window(const Ref<InputEvent> &p_event) { + Ref<InputEventKey> key = p_event; + if (key.is_valid() && key->is_pressed() && key->get_keycode() == KEY_ESCAPE) { + _close_pressed(); } } -void Popup::_fix_size() { - - Point2 pos = get_global_position(); - Size2 size = get_size() * get_scale(); - Point2 window_size = get_viewport_rect().size - get_viewport_transform().get_origin(); - - if (pos.x + size.width > window_size.width) - pos.x = window_size.width - size.width; - if (pos.x < 0) - pos.x = 0; +void Popup::_parent_focused() { - if (pos.y + size.height > window_size.height) - pos.y = window_size.height - size.height; - if (pos.y < 0) - pos.y = 0; - if (pos != get_position()) - set_global_position(pos); + _close_pressed(); } +void Popup::_notification(int p_what) { -void Popup::set_as_minsize() { - - Size2 total_minsize; - - for (int i = 0; i < get_child_count(); i++) { - - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) - continue; - if (!c->is_visible()) - continue; - - Size2 minsize = c->get_combined_minimum_size(); - - for (int j = 0; j < 2; j++) { - - Margin m_beg = Margin(0 + j); - Margin m_end = Margin(2 + j); - - float margin_begin = c->get_margin(m_beg); - float margin_end = c->get_margin(m_end); - float anchor_begin = c->get_anchor(m_beg); - float anchor_end = c->get_anchor(m_end); - - minsize[j] += margin_begin * (ANCHOR_END - anchor_begin) + margin_end * anchor_end; - } - - total_minsize.width = MAX(total_minsize.width, minsize.width); - total_minsize.height = MAX(total_minsize.height, minsize.height); + switch (p_what) { + case NOTIFICATION_VISIBILITY_CHANGED: { + if (is_visible()) { + + parent_visible = get_parent_visible_window(); + if (parent_visible) { + parent_visible->connect("focus_entered", callable_mp(this, &Popup::_parent_focused)); + } + } else { + if (parent_visible) { + parent_visible->disconnect("focus_entered", callable_mp(this, &Popup::_parent_focused)); + parent_visible = nullptr; + } + + emit_signal("popup_hide"); + } + + } break; + case NOTIFICATION_EXIT_TREE: { + if (parent_visible) { + parent_visible->disconnect("focus_entered", callable_mp(this, &Popup::_parent_focused)); + parent_visible = nullptr; + } + } break; + case NOTIFICATION_WM_CLOSE_REQUEST: { + _close_pressed(); + + } break; } - - set_size(total_minsize); } -void Popup::popup_centered_clamped(const Size2 &p_size, float p_fallback_ratio) { - - Size2 popup_size = p_size; - Size2 window_size = get_viewport_rect().size; - - // clamp popup size in each dimension if window size is too small (using fallback ratio) - popup_size.x = MIN(window_size.x * p_fallback_ratio, popup_size.x); - popup_size.y = MIN(window_size.y * p_fallback_ratio, popup_size.y); - - popup_centered(popup_size); -} +void Popup::_close_pressed() { -void Popup::popup_centered_minsize(const Size2 &p_minsize) { - - set_custom_minimum_size(p_minsize); - _fix_size(); - popup_centered(); -} + Window *parent_window = parent_visible; + if (parent_visible) { + parent_visible->disconnect("focus_entered", callable_mp(this, &Popup::_parent_focused)); + parent_visible = nullptr; + } -void Popup::popup_centered(const Size2 &p_size) { + call_deferred("hide"); - Rect2 rect; - Size2 window_size = get_viewport_rect().size; - rect.size = p_size == Size2() ? get_size() : p_size; - rect.position = ((window_size - rect.size) / 2.0).floor(); + emit_signal("cancelled"); - _popup(rect, true); + if (parent_window) { + //parent_window->grab_focus(); + } } -void Popup::popup_centered_ratio(float p_screen_ratio) { - - Rect2 rect; - Size2 window_size = get_viewport_rect().size; - rect.size = (window_size * p_screen_ratio).floor(); - rect.position = ((window_size - rect.size) / 2.0).floor(); - - _popup(rect, true); +void Popup::set_as_minsize() { + set_size(get_contents_minimum_size()); } +void Popup::_bind_methods() { -void Popup::popup(const Rect2 &p_bounds) { - - _popup(p_bounds); + ADD_SIGNAL(MethodInfo("popup_hide")); } -void Popup::_popup(const Rect2 &p_bounds, const bool p_centered) { - - emit_signal("about_to_show"); - show_modal(exclusive); - - // Fit the popup into the optionally provided bounds. - if (!p_bounds.has_no_area()) { - set_size(p_bounds.size); +Rect2i Popup::_popup_adjust_rect() const { + ERR_FAIL_COND_V(!is_inside_tree(), Rect2()); + Rect2i parent = get_usable_parent_rect(); - // check if p_bounds.size was using an outdated cached values - if (p_centered && p_bounds.size != get_size()) { - set_position(p_bounds.position - ((get_size() - p_bounds.size) / 2.0).floor()); - } else { - set_position(p_bounds.position); - } + if (parent == Rect2i()) { + return Rect2i(); } - _fix_size(); - - Control *focusable = find_next_valid_focus(); - - if (focusable) - focusable->grab_focus(); - - _post_popup(); - notification(NOTIFICATION_POST_POPUP); - popped_up = true; -} -void Popup::set_exclusive(bool p_exclusive) { + Rect2i current(get_position(), get_size()); - exclusive = p_exclusive; -} - -bool Popup::is_exclusive() const { + if (current.position.x + current.size.x > parent.position.x + parent.size.x) { + current.position.x = parent.position.x + parent.size.x - current.size.x; + } - return exclusive; -} + if (current.position.x < parent.position.x) { + current.position.x = parent.position.x; + } -void Popup::_bind_methods() { + if (current.position.y + current.size.y > parent.position.y + parent.size.y) { + current.position.y = parent.position.y + parent.size.y - current.size.y; + } - ClassDB::bind_method(D_METHOD("set_as_minsize"), &Popup::set_as_minsize); - ClassDB::bind_method(D_METHOD("popup_centered", "size"), &Popup::popup_centered, DEFVAL(Size2())); - ClassDB::bind_method(D_METHOD("popup_centered_ratio", "ratio"), &Popup::popup_centered_ratio, DEFVAL(0.75)); - ClassDB::bind_method(D_METHOD("popup_centered_minsize", "minsize"), &Popup::popup_centered_minsize, DEFVAL(Size2())); - ClassDB::bind_method(D_METHOD("popup_centered_clamped", "size", "fallback_ratio"), &Popup::popup_centered_clamped, DEFVAL(Size2()), DEFVAL(0.75)); - ClassDB::bind_method(D_METHOD("popup", "bounds"), &Popup::popup, DEFVAL(Rect2())); - ClassDB::bind_method(D_METHOD("set_exclusive", "enable"), &Popup::set_exclusive); - ClassDB::bind_method(D_METHOD("is_exclusive"), &Popup::is_exclusive); - ADD_SIGNAL(MethodInfo("about_to_show")); - ADD_SIGNAL(MethodInfo("popup_hide")); - ADD_GROUP("Popup", "popup_"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "popup_exclusive"), "set_exclusive", "is_exclusive"); + if (current.position.y < parent.position.y) { + current.position.y = parent.position.y; + } - BIND_CONSTANT(NOTIFICATION_POST_POPUP); - BIND_CONSTANT(NOTIFICATION_POPUP_HIDE); + return current; } Popup::Popup() { - set_as_toplevel(true); - exclusive = false; - popped_up = false; - hide(); -} - -String Popup::get_configuration_warning() const { + parent_visible = nullptr; - if (is_visible_in_tree()) { - return TTR("Popups will hide by default unless you call popup() or any of the popup*() functions. Making them visible for editing is fine, but they will hide upon running."); - } + set_wrap_controls(true); + set_visible(false); + set_transient(true); + set_flag(FLAG_BORDERLESS, true); + set_flag(FLAG_RESIZE_DISABLED, true); - return String(); + connect("window_input", callable_mp(this, &Popup::_input_from_window)); } Popup::~Popup() { } -Size2 PopupPanel::get_minimum_size() const { +Size2 PopupPanel::_get_contents_minimum_size() const { - Ref<StyleBox> p = get_stylebox("panel"); + Ref<StyleBox> p = get_theme_stylebox("panel", get_class_name()); Size2 ms; for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c || c == panel) continue; if (c->is_set_as_toplevel()) @@ -268,7 +172,7 @@ Size2 PopupPanel::get_minimum_size() const { void PopupPanel::_update_child_rects() { - Ref<StyleBox> p = get_stylebox("panel"); + Ref<StyleBox> p = get_theme_stylebox("panel", get_class_name()); Vector2 cpos(p->get_offset()); Vector2 csize(get_size() - p->get_minimum_size()); @@ -281,24 +185,32 @@ void PopupPanel::_update_child_rects() { if (c->is_set_as_toplevel()) continue; - c->set_position(cpos); - c->set_size(csize); + if (c == panel) { + c->set_position(Vector2()); + c->set_size(get_size()); + } else { + c->set_position(cpos); + c->set_size(csize); + } } } void PopupPanel::_notification(int p_what) { - if (p_what == NOTIFICATION_DRAW) { - - get_stylebox("panel")->draw(get_canvas_item(), Rect2(Point2(), get_size())); - } else if (p_what == NOTIFICATION_READY) { + if (p_what == NOTIFICATION_THEME_CHANGED) { + panel->add_theme_style_override("panel", get_theme_stylebox("panel", get_class_name())); + } else if (p_what == NOTIFICATION_READY || p_what == NOTIFICATION_ENTER_TREE) { + panel->add_theme_style_override("panel", get_theme_stylebox("panel", get_class_name())); _update_child_rects(); - } else if (p_what == NOTIFICATION_RESIZED) { + } else if (p_what == NOTIFICATION_WM_SIZE_CHANGED) { _update_child_rects(); } } PopupPanel::PopupPanel() { + + panel = memnew(Panel); + add_child(panel); } diff --git a/scene/gui/popup.h b/scene/gui/popup.h index ff472170b3..6cd2b4028f 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -31,44 +31,26 @@ #ifndef POPUP_H #define POPUP_H -#include "scene/gui/control.h" +#include "scene/main/window.h" -class Popup : public Control { +class Popup : public Window { - GDCLASS(Popup, Control); + GDCLASS(Popup, Window); - bool exclusive; - bool popped_up; + Window *parent_visible; -private: - void _popup(const Rect2 &p_bounds = Rect2(), const bool p_centered = false); + void _input_from_window(const Ref<InputEvent> &p_event); + void _parent_focused(); protected: - virtual void _post_popup() {} + void _close_pressed(); + virtual Rect2i _popup_adjust_rect() const; - void _gui_input(Ref<InputEvent> p_event); void _notification(int p_what); - virtual void _fix_size(); static void _bind_methods(); public: - enum { - NOTIFICATION_POST_POPUP = 80, - NOTIFICATION_POPUP_HIDE = 81 - }; - - void set_exclusive(bool p_exclusive); - bool is_exclusive() const; - - void popup_centered_ratio(float p_screen_ratio = 0.75); - void popup_centered(const Size2 &p_size = Size2()); - void popup_centered_minsize(const Size2 &p_minsize = Size2()); void set_as_minsize(); - void popup_centered_clamped(const Size2 &p_size = Size2(), float p_fallback_ratio = 0.75); - virtual void popup(const Rect2 &p_bounds = Rect2()); - - virtual String get_configuration_warning() const; - Popup(); ~Popup(); }; @@ -77,13 +59,16 @@ class PopupPanel : public Popup { GDCLASS(PopupPanel, Popup); + Panel *panel; + protected: void _update_child_rects(); void _notification(int p_what); + virtual Size2 _get_contents_minimum_size() const; + public: void set_child_rect(Control *p_child); - virtual Size2 get_minimum_size() const; PopupPanel(); }; diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index e75dadd5e0..1e933c9aa1 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -30,11 +30,12 @@ #include "popup_menu.h" -#include "core/os/input.h" +#include "core/input/input_filter.h" #include "core/os/keyboard.h" #include "core/os/os.h" #include "core/print_string.h" #include "core/translation.h" +#include "scene/gui/control.h" String PopupMenu::_get_accel_text(int p_item) const { @@ -47,18 +48,18 @@ String PopupMenu::_get_accel_text(int p_item) const { return String(); } -Size2 PopupMenu::get_minimum_size() const { +Size2 PopupMenu::_get_contents_minimum_size() const { - int vseparation = get_constant("vseparation"); - int hseparation = get_constant("hseparation"); + int vseparation = get_theme_constant("vseparation"); + int hseparation = get_theme_constant("hseparation"); - Size2 minsize = get_stylebox("panel")->get_minimum_size(); - Ref<Font> font = get_font("font"); + Size2 minsize = get_theme_stylebox("panel")->get_minimum_size(); + Ref<Font> font = get_theme_font("font"); float max_w = 0; float icon_w = 0; int font_h = font->get_height(); - int check_w = MAX(get_icon("checked")->get_width(), get_icon("radio_checked")->get_width()) + hseparation; + int check_w = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation; int accel_max_w = 0; bool has_check = false; @@ -93,7 +94,7 @@ Size2 PopupMenu::get_minimum_size() const { } if (items[i].submenu != "") - size.width += get_icon("submenu")->get_width(); + size.width += get_theme_icon("submenu")->get_width(); max_w = MAX(max_w, size.width); @@ -112,15 +113,15 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const { if (p_over.x < 0 || p_over.x >= get_size().width) return -1; - Ref<StyleBox> style = get_stylebox("panel"); + Ref<StyleBox> style = get_theme_stylebox("panel"); Point2 ofs = style->get_offset(); if (ofs.y > p_over.y) return -1; - Ref<Font> font = get_font("font"); - int vseparation = get_constant("vseparation"); + Ref<Font> font = get_theme_font("font"); + int vseparation = get_theme_constant("vseparation"); float font_h = font->get_height(); for (int i = 0; i < items.size(); i++) { @@ -152,27 +153,27 @@ void PopupMenu::_activate_submenu(int over) { ERR_FAIL_COND_MSG(!n, "Item subnode does not exist: " + items[over].submenu + "."); Popup *pm = Object::cast_to<Popup>(n); ERR_FAIL_COND_MSG(!pm, "Item subnode is not a Popup: " + items[over].submenu + "."); - if (pm->is_visible_in_tree()) + if (pm->is_visible()) return; //already visible! - Point2 p = get_global_position(); + Point2 p = get_position(); Rect2 pr(p, get_size()); - Ref<StyleBox> style = get_stylebox("panel"); + Ref<StyleBox> style = get_theme_stylebox("panel"); - Point2 pos = p + Point2(get_size().width, items[over]._ofs_cache - style->get_offset().y) * get_global_transform().get_scale(); + Point2 pos = p + Point2(get_size().width, items[over]._ofs_cache - style->get_offset().y); Size2 size = pm->get_size(); // fix pos - if (pos.x + size.width > get_viewport_rect().size.width) + if (pos.x + size.width > get_parent_rect().size.width) pos.x = p.x - size.width; pm->set_position(pos); - pm->set_scale(get_global_transform().get_scale()); + // pm->set_scale(get_global_transform().get_scale()); pm->popup(); PopupMenu *pum = Object::cast_to<PopupMenu>(pm); if (pum) { - pr.position -= pum->get_global_position(); + pr.position -= pum->get_position(); pum->clear_autohide_areas(); pum->add_autohide_area(Rect2(pr.position.x, pr.position.y, pr.size.x, items[over]._ofs_cache)); if (over < items.size() - 1) { @@ -184,6 +185,9 @@ void PopupMenu::_activate_submenu(int over) { void PopupMenu::_submenu_timeout() { + //if (!has_focus()) { + // return; //do not activate if not has focus + //} if (mouse_over == submenu_over) _activate_submenu(mouse_over); @@ -192,20 +196,27 @@ void PopupMenu::_submenu_timeout() { void PopupMenu::_scroll(float p_factor, const Point2 &p_over) { - int vseparation = get_constant("vseparation"); - Ref<Font> font = get_font("font"); + int vseparation = get_theme_constant("vseparation"); + Ref<Font> font = get_theme_font("font"); - float dy = (vseparation + font->get_height()) * 3 * p_factor * get_global_transform().get_scale().y; + Rect2 visible_rect = get_usable_parent_rect(); + + int dy = (vseparation + font->get_height()) * 3 * p_factor; if (dy > 0) { - const float global_top = get_global_position().y; - const float limit = global_top < 0 ? -global_top : 0; + const float global_top = get_position().y; + const float limit = global_top < visible_rect.position.y ? visible_rect.position.y - global_top : 0; dy = MIN(dy, limit); } else if (dy < 0) { - const float global_bottom = get_global_position().y + get_size().y * get_global_transform().get_scale().y; - const float viewport_height = get_viewport_rect().size.y; + const float global_bottom = get_position().y + get_size().y; + const float viewport_height = visible_rect.position.y + visible_rect.size.y; const float limit = global_bottom > viewport_height ? global_bottom - viewport_height : 0; dy = -MIN(-dy, limit); } + + if (dy == 0) { + return; + } + set_position(get_position() + Vector2(0, dy)); Ref<InputEventMouseMotion> ie; @@ -231,8 +242,8 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { mouse_over = i; emit_signal("id_focused", i); - update(); - accept_event(); + control->update(); + set_input_as_handled(); break; } } @@ -251,8 +262,8 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { mouse_over = i; emit_signal("id_focused", i); - update(); - accept_event(); + control->update(); + set_input_as_handled(); break; } } @@ -261,13 +272,13 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { Node *n = get_parent(); if (n && Object::cast_to<PopupMenu>(n)) { hide(); - accept_event(); + set_input_as_handled(); } } else if (p_event->is_action("ui_right") && p_event->is_pressed()) { if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator && items[mouse_over].submenu != "" && submenu_over != mouse_over) { _activate_submenu(mouse_over); - accept_event(); + set_input_as_handled(); } } else if (p_event->is_action("ui_accept") && p_event->is_pressed()) { @@ -278,7 +289,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { } else { activate_item(mouse_over); } - accept_event(); + set_input_as_handled(); } } @@ -294,15 +305,11 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { case BUTTON_WHEEL_DOWN: { - if (get_global_position().y + get_size().y * get_global_transform().get_scale().y > get_viewport_rect().size.y) { - _scroll(-b->get_factor(), b->get_position()); - } + _scroll(-b->get_factor(), b->get_position()); } break; case BUTTON_WHEEL_UP: { - if (get_global_position().y < 0) { - _scroll(b->get_factor(), b->get_position()); - } + _scroll(b->get_factor(), b->get_position()); } break; default: { // Allow activating item by releasing the LMB or any that was down when the popup appeared @@ -338,7 +345,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { } } - //update(); + //control->update(); } Ref<InputEventMouseMotion> m = p_event; @@ -354,7 +361,8 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) { if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E->get().has_point(m->get_position())) { - call_deferred("hide"); + + _close_pressed(); return; } } @@ -364,7 +372,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { if (id < 0) { mouse_over = -1; - update(); + control->update(); return; } @@ -375,20 +383,18 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { if (over != mouse_over) { mouse_over = over; - update(); + control->update(); } } Ref<InputEventPanGesture> pan_gesture = p_event; if (pan_gesture.is_valid()) { - if (get_global_position().y + get_size().y > get_viewport_rect().size.y || get_global_position().y < 0) { - _scroll(-pan_gesture->get_delta().y, pan_gesture->get_position()); - } + _scroll(-pan_gesture->get_delta().y, pan_gesture->get_position()); } Ref<InputEventKey> k = p_event; - if (allow_search && k.is_valid() && k->get_unicode()) { + if (allow_search && k.is_valid() && k->get_unicode() && k->is_pressed()) { uint64_t now = OS::get_singleton()->get_ticks_msec(); uint64_t diff = now - search_time_msec; @@ -416,218 +422,227 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { if (items[i].text.findn(search_string) == 0) { mouse_over = i; emit_signal("id_focused", i); - update(); - accept_event(); + control->update(); + set_input_as_handled(); break; } } } } -bool PopupMenu::has_point(const Point2 &p_point) const { +void PopupMenu::_draw() { - if (parent_rect.has_point(p_point)) - return true; - for (const List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) { + RID ci = control->get_canvas_item(); + Size2 size = get_size(); - if (E->get().has_point(p_point)) - return true; - } + Ref<StyleBox> style = get_theme_stylebox("panel"); + Ref<StyleBox> hover = get_theme_stylebox("hover"); + Ref<Font> font = get_theme_font("font"); + // In Item::checkable_type enum order (less the non-checkable member) + Ref<Texture2D> check[] = { get_theme_icon("checked"), get_theme_icon("radio_checked") }; + Ref<Texture2D> uncheck[] = { get_theme_icon("unchecked"), get_theme_icon("radio_unchecked") }; + Ref<Texture2D> submenu = get_theme_icon("submenu"); + Ref<StyleBox> separator = get_theme_stylebox("separator"); + Ref<StyleBox> labeled_separator_left = get_theme_stylebox("labeled_separator_left"); + Ref<StyleBox> labeled_separator_right = get_theme_stylebox("labeled_separator_right"); - return Control::has_point(p_point); -} - -void PopupMenu::_notification(int p_what) { + style->draw(ci, Rect2(Point2(), get_size())); + Point2 ofs = style->get_offset(); + int vseparation = get_theme_constant("vseparation"); + int hseparation = get_theme_constant("hseparation"); + Color font_color = get_theme_color("font_color"); + Color font_color_disabled = get_theme_color("font_color_disabled"); + Color font_color_accel = get_theme_color("font_color_accel"); + Color font_color_hover = get_theme_color("font_color_hover"); + float font_h = font->get_height(); - switch (p_what) { + // Add the check and the wider icon to the offset of all items. + float icon_ofs = 0.0; + bool has_check = false; + for (int i = 0; i < items.size(); i++) { - case NOTIFICATION_ENTER_TREE: { + if (!items[i].icon.is_null()) + icon_ofs = MAX(items[i].icon->get_size().width, icon_ofs); - PopupMenu *pm = Object::cast_to<PopupMenu>(get_parent()); - if (pm) { - // Inherit submenu's popup delay time from parent menu - float pm_delay = pm->get_submenu_popup_delay(); - set_submenu_popup_delay(pm_delay); - } - } break; - case NOTIFICATION_TRANSLATION_CHANGED: { + if (items[i].checkable_type) + has_check = true; + } + if (icon_ofs > 0.0) + icon_ofs += hseparation; - for (int i = 0; i < items.size(); i++) { - items.write[i].xl_text = tr(items[i].text); - } + float check_ofs = 0.0; + if (has_check) + check_ofs = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation; - minimum_size_changed(); - update(); - } break; - case NOTIFICATION_DRAW: { - - RID ci = get_canvas_item(); - Size2 size = get_size(); - - Ref<StyleBox> style = get_stylebox("panel"); - Ref<StyleBox> hover = get_stylebox("hover"); - Ref<Font> font = get_font("font"); - // In Item::checkable_type enum order (less the non-checkable member) - Ref<Texture2D> check[] = { get_icon("checked"), get_icon("radio_checked") }; - Ref<Texture2D> uncheck[] = { get_icon("unchecked"), get_icon("radio_unchecked") }; - Ref<Texture2D> submenu = get_icon("submenu"); - Ref<StyleBox> separator = get_stylebox("separator"); - Ref<StyleBox> labeled_separator_left = get_stylebox("labeled_separator_left"); - Ref<StyleBox> labeled_separator_right = get_stylebox("labeled_separator_right"); - - style->draw(ci, Rect2(Point2(), get_size())); - Point2 ofs = style->get_offset(); - int vseparation = get_constant("vseparation"); - int hseparation = get_constant("hseparation"); - Color font_color = get_color("font_color"); - Color font_color_disabled = get_color("font_color_disabled"); - Color font_color_accel = get_color("font_color_accel"); - Color font_color_hover = get_color("font_color_hover"); - float font_h = font->get_height(); - - // Add the check and the wider icon to the offset of all items. - float icon_ofs = 0.0; - bool has_check = false; - for (int i = 0; i < items.size(); i++) { + for (int i = 0; i < items.size(); i++) { - if (!items[i].icon.is_null()) - icon_ofs = MAX(items[i].icon->get_size().width, icon_ofs); + if (i > 0) + ofs.y += vseparation; + Point2 item_ofs = ofs; + Size2 icon_size; + float h; - if (items[i].checkable_type) - has_check = true; - } - if (icon_ofs > 0.0) - icon_ofs += hseparation; + if (!items[i].icon.is_null()) { - float check_ofs = 0.0; - if (has_check) - check_ofs = MAX(get_icon("checked")->get_width(), get_icon("radio_checked")->get_width()) + hseparation; + icon_size = items[i].icon->get_size(); + h = MAX(icon_size.height, font_h); + } else { - for (int i = 0; i < items.size(); i++) { + h = font_h; + } - if (i > 0) - ofs.y += vseparation; - Point2 item_ofs = ofs; - Size2 icon_size; - float h; + if (i == mouse_over) { - if (!items[i].icon.is_null()) { + hover->draw(ci, Rect2(item_ofs + Point2(-hseparation, -vseparation / 2), Size2(get_size().width - style->get_minimum_size().width + hseparation * 2, h + vseparation))); + } - icon_size = items[i].icon->get_size(); - h = MAX(icon_size.height, font_h); - } else { + String text = items[i].xl_text; - h = font_h; + item_ofs.x += items[i].h_ofs; + if (items[i].separator) { + + int sep_h = separator->get_center_size().height + separator->get_minimum_size().height; + if (text != String()) { + int ss = font->get_string_size(text).width; + int center = (get_size().width) / 2; + int l = center - ss / 2; + int r = center + ss / 2; + if (l > item_ofs.x) { + labeled_separator_left->draw(ci, Rect2(item_ofs + Point2(0, Math::floor((h - sep_h) / 2.0)), Size2(MAX(0, l - item_ofs.x), sep_h))); } - - if (i == mouse_over) { - - hover->draw(ci, Rect2(item_ofs + Point2(-hseparation, -vseparation / 2), Size2(get_size().width - style->get_minimum_size().width + hseparation * 2, h + vseparation))); + if (r < get_size().width - style->get_margin(MARGIN_RIGHT)) { + labeled_separator_right->draw(ci, Rect2(Point2(r, item_ofs.y + Math::floor((h - sep_h) / 2.0)), Size2(MAX(0, get_size().width - style->get_margin(MARGIN_RIGHT) - r), sep_h))); } + } else { + separator->draw(ci, Rect2(item_ofs + Point2(0, Math::floor((h - sep_h) / 2.0)), Size2(get_size().width - style->get_minimum_size().width, sep_h))); + } + } - String text = items[i].xl_text; + Color icon_color(1, 1, 1, items[i].disabled ? 0.5 : 1); - item_ofs.x += items[i].h_ofs; - if (items[i].separator) { + if (items[i].checkable_type) { + Texture2D *icon = (items[i].checked ? check[items[i].checkable_type - 1] : uncheck[items[i].checkable_type - 1]).ptr(); + icon->draw(ci, item_ofs + Point2(0, Math::floor((h - icon->get_height()) / 2.0)), icon_color); + } - int sep_h = separator->get_center_size().height + separator->get_minimum_size().height; - if (text != String()) { - int ss = font->get_string_size(text).width; - int center = (get_size().width) / 2; - int l = center - ss / 2; - int r = center + ss / 2; - if (l > item_ofs.x) { - labeled_separator_left->draw(ci, Rect2(item_ofs + Point2(0, Math::floor((h - sep_h) / 2.0)), Size2(MAX(0, l - item_ofs.x), sep_h))); - } - if (r < get_size().width - style->get_margin(MARGIN_RIGHT)) { - labeled_separator_right->draw(ci, Rect2(Point2(r, item_ofs.y + Math::floor((h - sep_h) / 2.0)), Size2(MAX(0, get_size().width - style->get_margin(MARGIN_RIGHT) - r), sep_h))); - } - } else { - separator->draw(ci, Rect2(item_ofs + Point2(0, Math::floor((h - sep_h) / 2.0)), Size2(get_size().width - style->get_minimum_size().width, sep_h))); - } - } + if (!items[i].icon.is_null()) { + items[i].icon->draw(ci, item_ofs + Size2(check_ofs, 0) + Point2(0, Math::floor((h - icon_size.height) / 2.0)), icon_color); + } - Color icon_color(1, 1, 1, items[i].disabled ? 0.5 : 1); + if (items[i].submenu != "") { + submenu->draw(ci, Point2(size.width - style->get_margin(MARGIN_RIGHT) - submenu->get_width(), item_ofs.y + Math::floor(h - submenu->get_height()) / 2), icon_color); + } - if (items[i].checkable_type) { - Texture2D *icon = (items[i].checked ? check[items[i].checkable_type - 1] : uncheck[items[i].checkable_type - 1]).ptr(); - icon->draw(ci, item_ofs + Point2(0, Math::floor((h - icon->get_height()) / 2.0)), icon_color); - } + item_ofs.y += font->get_ascent(); + if (items[i].separator) { - if (!items[i].icon.is_null()) { - items[i].icon->draw(ci, item_ofs + Size2(check_ofs, 0) + Point2(0, Math::floor((h - icon_size.height) / 2.0)), icon_color); - } + if (text != String()) { + int center = (get_size().width - font->get_string_size(text).width) / 2; + font->draw(ci, Point2(center, item_ofs.y + Math::floor((h - font_h) / 2.0)), text, font_color_disabled); + } + } else { - if (items[i].submenu != "") { - submenu->draw(ci, Point2(size.width - style->get_margin(MARGIN_RIGHT) - submenu->get_width(), item_ofs.y + Math::floor(h - submenu->get_height()) / 2), icon_color); - } + item_ofs.x += icon_ofs + check_ofs; + font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text, items[i].disabled ? font_color_disabled : (i == mouse_over ? font_color_hover : font_color)); + } - item_ofs.y += font->get_ascent(); - if (items[i].separator) { + if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) { + //accelerator + String text2 = _get_accel_text(i); + item_ofs.x = size.width - style->get_margin(MARGIN_RIGHT) - font->get_string_size(text2).width; + font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text2, i == mouse_over ? font_color_hover : font_color_accel); + } - if (text != String()) { - int center = (get_size().width - font->get_string_size(text).width) / 2; - font->draw(ci, Point2(center, item_ofs.y + Math::floor((h - font_h) / 2.0)), text, font_color_disabled); - } - } else { + items.write[i]._ofs_cache = ofs.y; - item_ofs.x += icon_ofs + check_ofs; - font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text, items[i].disabled ? font_color_disabled : (i == mouse_over ? font_color_hover : font_color)); - } + ofs.y += h; + } +} - if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) { - //accelerator - String text2 = _get_accel_text(i); - item_ofs.x = size.width - style->get_margin(MARGIN_RIGHT) - font->get_string_size(text2).width; - font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text2, i == mouse_over ? font_color_hover : font_color_accel); - } +void PopupMenu::_notification(int p_what) { + + switch (p_what) { - items.write[i]._ofs_cache = ofs.y; + case NOTIFICATION_ENTER_TREE: { - ofs.y += h; + PopupMenu *pm = Object::cast_to<PopupMenu>(get_parent()); + if (pm) { + // Inherit submenu's popup delay time from parent menu + float pm_delay = pm->get_submenu_popup_delay(); + set_submenu_popup_delay(pm_delay); } } break; - case MainLoop::NOTIFICATION_WM_FOCUS_OUT: { + case NOTIFICATION_TRANSLATION_CHANGED: { - if (hide_on_window_lose_focus) - hide(); + for (int i = 0; i < items.size(); i++) { + items.write[i].xl_text = tr(items[i].text); + } + + child_controls_changed(); + control->update(); } break; - case NOTIFICATION_MOUSE_ENTER: { + case NOTIFICATION_WM_MOUSE_ENTER: { - grab_focus(); + //grab_focus(); } break; - case NOTIFICATION_MOUSE_EXIT: { + case NOTIFICATION_WM_MOUSE_EXIT: { if (mouse_over >= 0 && (items[mouse_over].submenu == "" || submenu_over != -1)) { mouse_over = -1; - update(); + control->update(); } } break; case NOTIFICATION_POST_POPUP: { - initial_button_mask = Input::get_singleton()->get_mouse_button_mask(); + initial_button_mask = InputFilter::get_singleton()->get_mouse_button_mask(); during_grabbed_click = (bool)initial_button_mask; } break; - case NOTIFICATION_POPUP_HIDE: { + case NOTIFICATION_WM_SIZE_CHANGED: { - if (mouse_over >= 0) { - mouse_over = -1; - update(); + } break; + case NOTIFICATION_INTERNAL_PROCESS: { + //only used when using operating system windows + if (get_window_id() != DisplayServer::INVALID_WINDOW_ID && autohide_areas.size()) { + Point2 mouse_pos = DisplayServer::get_singleton()->mouse_get_position(); + mouse_pos -= get_position(); + + for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) { + + if (!Rect2(Point2(), get_size()).has_point(mouse_pos) && E->get().has_point(mouse_pos)) { + _close_pressed(); + return; + } + } } + } break; + case NOTIFICATION_VISIBILITY_CHANGED: { - for (int i = 0; i < items.size(); i++) { - if (items[i].submenu == "") - continue; + if (!is_visible()) { + if (mouse_over >= 0) { + mouse_over = -1; + control->update(); + } + + for (int i = 0; i < items.size(); i++) { + if (items[i].submenu == "") + continue; - Node *n = get_node(items[i].submenu); - if (!n) - continue; + Node *n = get_node(items[i].submenu); + if (!n) + continue; - PopupMenu *pm = Object::cast_to<PopupMenu>(n); - if (!pm || !pm->is_visible()) - continue; + PopupMenu *pm = Object::cast_to<PopupMenu>(n); + if (!pm || !pm->is_visible()) + continue; - pm->hide(); + pm->hide(); + } + + set_process_internal(false); + } else { + if (get_window_id() != DisplayServer::INVALID_WINDOW_ID) { + set_process_internal(true); + } } } break; } @@ -648,8 +663,8 @@ void PopupMenu::add_item(const String &p_label, int p_id, uint32_t p_accel) { Item item; ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { @@ -658,8 +673,8 @@ void PopupMenu::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_labe ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); item.icon = p_icon; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_check_item(const String &p_label, int p_id, uint32_t p_accel) { @@ -668,8 +683,8 @@ void PopupMenu::add_check_item(const String &p_label, int p_id, uint32_t p_accel ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_icon_check_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { @@ -679,8 +694,8 @@ void PopupMenu::add_icon_check_item(const Ref<Texture2D> &p_icon, const String & item.icon = p_icon; item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_radio_check_item(const String &p_label, int p_id, uint32_t p_accel) { @@ -689,8 +704,8 @@ void PopupMenu::add_radio_check_item(const String &p_label, int p_id, uint32_t p ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_icon_radio_check_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { @@ -700,8 +715,8 @@ void PopupMenu::add_icon_radio_check_item(const Ref<Texture2D> &p_icon, const St item.icon = p_icon; item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_multistate_item(const String &p_label, int p_max_states, int p_default_state, int p_id, uint32_t p_accel) { @@ -711,8 +726,8 @@ void PopupMenu::add_multistate_item(const String &p_label, int p_max_states, int item.max_states = p_max_states; item.state = p_default_state; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } #define ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global) \ @@ -729,8 +744,8 @@ void PopupMenu::add_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_g Item item; ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_icon_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { @@ -739,8 +754,8 @@ void PopupMenu::add_icon_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortC ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); item.icon = p_icon; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { @@ -749,8 +764,8 @@ void PopupMenu::add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bo ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_icon_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { @@ -760,8 +775,8 @@ void PopupMenu::add_icon_check_shortcut(const Ref<Texture2D> &p_icon, const Ref< item.icon = p_icon; item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_radio_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { @@ -770,8 +785,8 @@ void PopupMenu::add_radio_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_ ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { @@ -781,8 +796,8 @@ void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, cons item.icon = p_icon; item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu, int p_id) { @@ -793,8 +808,8 @@ void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu, item.id = p_id == -1 ? items.size() : p_id; item.submenu = p_submenu; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } #undef ITEM_SETUP_WITH_ACCEL @@ -808,16 +823,16 @@ void PopupMenu::set_item_text(int p_idx, const String &p_text) { items.write[p_idx].text = p_text; items.write[p_idx].xl_text = tr(p_text); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].icon = p_icon; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_checked(int p_idx, bool p_checked) { @@ -825,16 +840,16 @@ void PopupMenu::set_item_checked(int p_idx, bool p_checked) { items.write[p_idx].checked = p_checked; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_id(int p_idx, int p_id) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].id = p_id; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_accelerator(int p_idx, uint32_t p_accel) { @@ -842,40 +857,40 @@ void PopupMenu::set_item_accelerator(int p_idx, uint32_t p_accel) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].accel = p_accel; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_metadata(int p_idx, const Variant &p_meta) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].metadata = p_meta; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_disabled(int p_idx, bool p_disabled) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].disabled = p_disabled; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_submenu(int p_idx, const String &p_submenu) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].submenu = p_submenu; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::toggle_item_checked(int p_idx) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].checked = !items[p_idx].checked; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } String PopupMenu::get_item_text(int p_idx) const { @@ -968,7 +983,7 @@ void PopupMenu::set_item_as_separator(int p_idx, bool p_separator) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].separator = p_separator; - update(); + control->update(); } bool PopupMenu::is_item_separator(int p_idx) const { @@ -980,21 +995,21 @@ void PopupMenu::set_item_as_checkable(int p_idx, bool p_checkable) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].checkable_type = p_checkable ? Item::CHECKABLE_TYPE_CHECK_BOX : Item::CHECKABLE_TYPE_NONE; - update(); + control->update(); } void PopupMenu::set_item_as_radio_checkable(int p_idx, bool p_radio_checkable) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].checkable_type = p_radio_checkable ? Item::CHECKABLE_TYPE_RADIO_BUTTON : Item::CHECKABLE_TYPE_NONE; - update(); + control->update(); } void PopupMenu::set_item_tooltip(int p_idx, const String &p_tooltip) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].tooltip = p_tooltip; - update(); + control->update(); } void PopupMenu::set_item_shortcut(int p_idx, const Ref<ShortCut> &p_shortcut, bool p_global) { @@ -1009,29 +1024,29 @@ void PopupMenu::set_item_shortcut(int p_idx, const Ref<ShortCut> &p_shortcut, bo _ref_shortcut(items[p_idx].shortcut); } - update(); + control->update(); } void PopupMenu::set_item_h_offset(int p_idx, int p_offset) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].h_ofs = p_offset; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_multistate(int p_idx, int p_state) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].state = p_state; - update(); + control->update(); } void PopupMenu::set_item_shortcut_disabled(int p_idx, bool p_disabled) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].shortcut_is_disabled = p_disabled; - update(); + control->update(); } void PopupMenu::toggle_item_multistate(int p_idx) { @@ -1045,7 +1060,7 @@ void PopupMenu::toggle_item_multistate(int p_idx) { if (items.write[p_idx].max_states <= items[p_idx].state) items.write[p_idx].state = 0; - update(); + control->update(); } bool PopupMenu::is_item_checkable(int p_idx) const { @@ -1177,8 +1192,8 @@ void PopupMenu::remove_item(int p_idx) { } items.remove(p_idx); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_separator(const String &p_text) { @@ -1191,7 +1206,7 @@ void PopupMenu::add_separator(const String &p_text) { sep.xl_text = tr(p_text); } items.push_back(sep); - update(); + control->update(); } void PopupMenu::clear() { @@ -1203,8 +1218,8 @@ void PopupMenu::clear() { } items.clear(); mouse_over = -1; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } Array PopupMenu::_get_items() const { @@ -1345,16 +1360,6 @@ bool PopupMenu::get_allow_search() const { return allow_search; } -void PopupMenu::set_hide_on_window_lose_focus(bool p_enabled) { - - hide_on_window_lose_focus = p_enabled; -} - -bool PopupMenu::is_hide_on_window_lose_focus() const { - - return hide_on_window_lose_focus; -} - String PopupMenu::get_tooltip(const Point2 &p_pos) const { int over = _get_mouse_over(p_pos); @@ -1387,6 +1392,14 @@ void PopupMenu::clear_autohide_areas() { autohide_areas.clear(); } +void PopupMenu::take_mouse_focus() { + ERR_FAIL_COND(!is_inside_tree()); + + if (get_parent()) { + get_parent()->get_viewport()->pass_mouse_focus_to(this, control); + } +} + void PopupMenu::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &PopupMenu::_gui_input); @@ -1466,9 +1479,6 @@ void PopupMenu::_bind_methods() { ClassDB::bind_method(D_METHOD("set_submenu_popup_delay", "seconds"), &PopupMenu::set_submenu_popup_delay); ClassDB::bind_method(D_METHOD("get_submenu_popup_delay"), &PopupMenu::get_submenu_popup_delay); - ClassDB::bind_method(D_METHOD("set_hide_on_window_lose_focus", "enable"), &PopupMenu::set_hide_on_window_lose_focus); - ClassDB::bind_method(D_METHOD("is_hide_on_window_lose_focus"), &PopupMenu::is_hide_on_window_lose_focus); - ClassDB::bind_method(D_METHOD("set_allow_search", "allow"), &PopupMenu::set_allow_search); ClassDB::bind_method(D_METHOD("get_allow_search"), &PopupMenu::get_allow_search); @@ -1486,7 +1496,6 @@ void PopupMenu::_bind_methods() { void PopupMenu::popup(const Rect2 &p_bounds) { - grab_click_focus(); moved = Vector2(); invalidated_click = true; Popup::popup(p_bounds); @@ -1494,21 +1503,26 @@ void PopupMenu::popup(const Rect2 &p_bounds) { PopupMenu::PopupMenu() { + control = memnew(Control); + add_child(control); + + control->set_anchors_and_margins_preset(Control::PRESET_WIDE); + connect("window_input", callable_mp(this, &PopupMenu::_gui_input)); + control->connect("draw", callable_mp(this, &PopupMenu::_draw)); + mouse_over = -1; submenu_over = -1; initial_button_mask = 0; during_grabbed_click = false; + invalidated_click = false; allow_search = false; search_time_msec = 0; search_string = ""; - set_focus_mode(FOCUS_ALL); - set_as_toplevel(true); set_hide_on_item_selection(true); set_hide_on_checkable_item_selection(true); set_hide_on_multistate_item_selection(false); - set_hide_on_window_lose_focus(true); submenu_timer = memnew(Timer); submenu_timer->set_wait_time(0.3); diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index a3a858cfde..2eef1f009d 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -32,6 +32,7 @@ #define POPUP_MENU_H #include "scene/gui/popup.h" +#include "scene/gui/shortcut.h" class PopupMenu : public Popup { @@ -87,7 +88,7 @@ class PopupMenu : public Popup { Rect2 parent_rect; String _get_accel_text(int p_item) const; int _get_mouse_over(const Point2 &p_over) const; - virtual Size2 get_minimum_size() const; + virtual Size2 _get_contents_minimum_size() const; void _scroll(float p_factor, const Point2 &p_over); void _gui_input(const Ref<InputEvent> &p_event); void _activate_submenu(int over); @@ -97,7 +98,6 @@ class PopupMenu : public Popup { bool hide_on_item_selection; bool hide_on_checkable_item_selection; bool hide_on_multistate_item_selection; - bool hide_on_window_lose_focus; Vector2 moved; Array _get_items() const; @@ -112,9 +112,11 @@ class PopupMenu : public Popup { uint64_t search_time_msec; String search_string; -protected: - virtual bool has_point(const Point2 &p_point) const; + Control *control; + + void _draw(); +protected: friend class MenuButton; void _notification(int p_what); static void _bind_methods(); @@ -213,8 +215,7 @@ public: virtual void popup(const Rect2 &p_bounds = Rect2()); - void set_hide_on_window_lose_focus(bool p_enabled); - bool is_hide_on_window_lose_focus() const; + void take_mouse_focus(); PopupMenu(); ~PopupMenu(); diff --git a/scene/gui/progress_bar.cpp b/scene/gui/progress_bar.cpp index e11295d7e7..362c45453d 100644 --- a/scene/gui/progress_bar.cpp +++ b/scene/gui/progress_bar.cpp @@ -32,9 +32,9 @@ Size2 ProgressBar::get_minimum_size() const { - Ref<StyleBox> bg = get_stylebox("bg"); - Ref<StyleBox> fg = get_stylebox("fg"); - Ref<Font> font = get_font("font"); + Ref<StyleBox> bg = get_theme_stylebox("bg"); + Ref<StyleBox> fg = get_theme_stylebox("fg"); + Ref<Font> font = get_theme_font("font"); Size2 minimum_size = bg->get_minimum_size(); minimum_size.height = MAX(minimum_size.height, fg->get_minimum_size().height); @@ -52,10 +52,10 @@ void ProgressBar::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - Ref<StyleBox> bg = get_stylebox("bg"); - Ref<StyleBox> fg = get_stylebox("fg"); - Ref<Font> font = get_font("font"); - Color font_color = get_color("font_color"); + Ref<StyleBox> bg = get_theme_stylebox("bg"); + Ref<StyleBox> fg = get_theme_stylebox("fg"); + Ref<Font> font = get_theme_font("font"); + Color font_color = get_theme_color("font_color"); draw_style_box(bg, Rect2(Point2(), get_size())); float r = get_as_ratio(); diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index adc5f81465..ab2f64e1b4 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -236,7 +236,7 @@ void Range::_unref_shared() { shared->owners.erase(this); if (shared->owners.size() == 0) { memdelete(shared); - shared = NULL; + shared = nullptr; } } } diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index bc1510d6f6..9fab9005f9 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -34,6 +34,7 @@ #include "core/os/keyboard.h" #include "core/os/os.h" #include "scene/scene_string_names.h" +#include "servers/display_server.h" #include "modules/modules_enabled.gen.h" #ifdef MODULE_REGEX_ENABLED @@ -52,7 +53,7 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) { return p_item->subitems.front()->get(); } else if (!p_item->parent) { - return NULL; + return nullptr; } else if (p_item->E->next()) { return p_item->E->next()->get(); @@ -65,7 +66,7 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) { if (p_item->parent) return p_item->E->next()->get(); else - return NULL; + return nullptr; } } else { @@ -73,7 +74,7 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) { return p_item->subitems.front()->get(); } else if (p_item->type == ITEM_FRAME) { - return NULL; + return nullptr; } else if (p_item->E->next()) { return p_item->E->next()->get(); @@ -86,11 +87,11 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) { if (p_item->type != ITEM_FRAME) return p_item->E->next()->get(); else - return NULL; + return nullptr; } } - return NULL; + return nullptr; } RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) { @@ -100,7 +101,7 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) { return p_item->subitems.back()->get(); } else if (!p_item->parent) { - return NULL; + return nullptr; } else if (p_item->E->prev()) { return p_item->E->prev()->get(); @@ -113,7 +114,7 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) { if (p_item->parent) return p_item->E->prev()->get(); else - return NULL; + return nullptr; } } else { @@ -121,7 +122,7 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) { return p_item->subitems.back()->get(); } else if (p_item->type == ITEM_FRAME) { - return NULL; + return nullptr; } else if (p_item->E->prev()) { return p_item->E->prev()->get(); @@ -134,15 +135,15 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) { if (p_item->type != ITEM_FRAME) return p_item->E->prev()->get(); else - return NULL; + return nullptr; } } - return NULL; + return nullptr; } Rect2 RichTextLabel::_get_text_rect() { - Ref<StyleBox> style = get_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox("normal"); return Rect2(style->get_offset(), get_size() - style->get_minimum_size()); } @@ -157,7 +158,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & ci = get_canvas_item(); if (r_click_item) - *r_click_item = NULL; + *r_click_item = nullptr; } Line &l = p_frame->lines.write[p_line]; Item *it = l.from; @@ -240,7 +241,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & l.space_caches.push_back(spaces); \ } \ line_wrapped = false; \ - y += line_height + get_constant(SceneStringNames::get_singleton()->line_separation); \ + y += line_height + get_theme_constant(SceneStringNames::get_singleton()->line_separation); \ line_height = 0; \ line_ascent = 0; \ line_descent = 0; \ @@ -305,8 +306,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & Color selection_bg; if (p_mode == PROCESS_DRAW) { - selection_fg = get_color("font_color_selected"); - selection_bg = get_color("selection_color"); + selection_fg = get_theme_color("font_color_selected"); + selection_bg = get_theme_color("selection_color"); } int rchar = 0; @@ -355,7 +356,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & Color font_color_shadow; bool underline = false; bool strikethrough = false; - ItemFade *fade = NULL; + ItemFade *fade = nullptr; int it_char_start = p_char_count; Vector<ItemFX *> fx_stack = Vector<ItemFX *>(); @@ -406,17 +407,16 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & cw = tab_size * font->get_char_size(' ').width; } - if (end > 0 && w + cw + begin > p_width) { + if (end > 0 && fw + cw + begin > p_width) { break; //don't allow lines longer than assigned width } - w += cw; fw += cw; end++; } CHECK_HEIGHT(fh); - ENSURE_WIDTH(w); + ENSURE_WIDTH(fw); line_ascent = MAX(line_ascent, ascent); line_descent = MAX(line_descent, descent); @@ -551,8 +551,10 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } } - if (visible) + if (visible) { line_is_blank = false; + w += font->get_char_size(c[i], c[i + 1]).x; + } if (c[i] == '\t') visible = false; @@ -581,13 +583,14 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } else { cw = drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent) + fx_offset, fx_char, c[i + 1], fx_color); } - } else if (previously_visible) { + } else if (previously_visible && c[i] != '\t') { backtrack += font->get_char_size(fx_char, c[i + 1]).x; } p_char_count++; if (c[i] == '\t') { cw = tab_size * font->get_char_size(' ').width; + backtrack = MAX(0, backtrack - cw); } ofs += cw; @@ -602,16 +605,16 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & #ifdef TOOLS_ENABLED underline_width *= EDSCALE; #endif - VS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, underline_width); + RS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, underline_width); } else if (strikethrough) { Color uc = color; uc.a *= 0.5; - int uy = y + lh / 2 - line_descent + 2; + int uy = y + lh - (line_ascent + line_descent) / 2; float strikethrough_width = 1.0; #ifdef TOOLS_ENABLED strikethrough_width *= EDSCALE; #endif - VS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, strikethrough_width); + RS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, strikethrough_width); } } @@ -667,13 +670,13 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & lh = 0; ItemTable *table = static_cast<ItemTable *>(it); - int hseparation = get_constant("table_hseparation"); - int vseparation = get_constant("table_vseparation"); + int hseparation = get_theme_constant("table_hseparation"); + int vseparation = get_theme_constant("table_vseparation"); Color ccolor = _find_color(table, p_base_color); Vector2 draw_ofs = Point2(wofs, y); - Color font_color_shadow = get_color("font_color_shadow"); - bool use_outline = get_constant("shadow_as_outline"); - Point2 shadow_ofs2(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); + Color font_color_shadow = get_theme_color("font_color_shadow"); + bool use_outline = get_theme_constant("shadow_as_outline"); + Point2 shadow_ofs2(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); if (p_mode == PROCESS_CACHE) { @@ -914,7 +917,7 @@ void RichTextLabel::_update_scroll() { void RichTextLabel::_update_fx(RichTextLabel::ItemFrame *p_frame, float p_delta_time) { Item *it = p_frame; while (it) { - ItemFX *ifx = NULL; + ItemFX *ifx = nullptr; if (it->type == ITEM_CUSTOMFX || it->type == ITEM_SHAKE || it->type == ITEM_WAVE || it->type == ITEM_TORNADO || it->type == ITEM_RAINBOW) { ifx = static_cast<ItemFX *>(it); @@ -927,7 +930,7 @@ void RichTextLabel::_update_fx(RichTextLabel::ItemFrame *p_frame, float p_delta_ ifx->elapsed_time += p_delta_time; - ItemShake *shake = NULL; + ItemShake *shake = nullptr; if (it->type == ITEM_SHAKE) { shake = static_cast<ItemShake *>(it); @@ -951,7 +954,7 @@ void RichTextLabel::_notification(int p_what) { case NOTIFICATION_MOUSE_EXIT: { if (meta_hovering) { - meta_hovering = NULL; + meta_hovering = nullptr; emit_signal("meta_hover_ended", current_meta); current_meta = false; update(); @@ -987,12 +990,12 @@ void RichTextLabel::_notification(int p_what) { Size2 size = get_size(); Rect2 text_rect = _get_text_rect(); - draw_style_box(get_stylebox("normal"), Rect2(Point2(), size)); + draw_style_box(get_theme_stylebox("normal"), Rect2(Point2(), size)); if (has_focus()) { - VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci, true); - draw_style_box(get_stylebox("focus"), Rect2(Point2(), size)); - VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci, false); + RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, true); + draw_style_box(get_theme_stylebox("focus"), Rect2(Point2(), size)); + RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, false); } int ofs = vscroll->get_value(); @@ -1012,16 +1015,16 @@ void RichTextLabel::_notification(int p_what) { if (from_line >= main->lines.size()) break; //nothing to draw int y = (main->lines[from_line].height_accum_cache - main->lines[from_line].height_cache) - ofs; - Ref<Font> base_font = get_font("normal_font"); - Color base_color = get_color("default_color"); - Color font_color_shadow = get_color("font_color_shadow"); - bool use_outline = get_constant("shadow_as_outline"); - Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); + Ref<Font> base_font = get_theme_font("normal_font"); + Color base_color = get_theme_color("default_color"); + Color font_color_shadow = get_theme_color("font_color_shadow"); + bool use_outline = get_theme_constant("shadow_as_outline"); + Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); visible_line_count = 0; while (y < size.height && from_line < main->lines.size()) { - visible_line_count += _process_line(main, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_DRAW, base_font, base_color, font_color_shadow, use_outline, shadow_ofs, Point2i(), NULL, NULL, NULL, total_chars); + visible_line_count += _process_line(main, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_DRAW, base_font, base_color, font_color_shadow, use_outline, shadow_ofs, Point2i(), nullptr, nullptr, nullptr, total_chars); total_chars += main->lines[from_line].char_count; from_line++; @@ -1039,13 +1042,13 @@ void RichTextLabel::_notification(int p_what) { void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item, int *r_click_char, bool *r_outside) { if (r_click_item) - *r_click_item = NULL; + *r_click_item = nullptr; Rect2 text_rect = _get_text_rect(); int ofs = vscroll->get_value(); - Color font_color_shadow = get_color("font_color_shadow"); - bool use_outline = get_constant("shadow_as_outline"); - Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); + Color font_color_shadow = get_theme_color("font_color_shadow"); + bool use_outline = get_theme_constant("shadow_as_outline"); + Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); //todo, change to binary search int from_line = 0; @@ -1061,8 +1064,8 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item return; int y = (p_frame->lines[from_line].height_accum_cache - p_frame->lines[from_line].height_cache) - ofs; - Ref<Font> base_font = get_font("normal_font"); - Color base_color = get_color("default_color"); + Ref<Font> base_font = get_theme_font("normal_font"); + Color base_color = get_theme_color("default_color"); while (y < text_rect.get_size().height && from_line < p_frame->lines.size()) { @@ -1085,11 +1088,11 @@ Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const return CURSOR_ARROW; //invalid int line = 0; - Item *item = NULL; + Item *item = nullptr; bool outside; ((RichTextLabel *)(this))->_find_click(main, p_pos, &item, &line, &outside); - if (item && !outside && ((RichTextLabel *)(this))->_find_meta(item, NULL)) + if (item && !outside && ((RichTextLabel *)(this))->_find_meta(item, nullptr)) return CURSOR_POINTING_HAND; return CURSOR_ARROW; @@ -1107,7 +1110,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { if (b->is_pressed() && !b->is_doubleclick()) { scroll_updated = false; int line = 0; - Item *item = NULL; + Item *item = nullptr; bool outside; _find_click(main, b->get_position(), &item, &line, &outside); @@ -1121,9 +1124,9 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { // Erase previous selection. if (selection.active) { - selection.from = NULL; + selection.from = nullptr; selection.from_char = '\0'; - selection.to = NULL; + selection.to = nullptr; selection.to_char = '\0'; selection.active = false; @@ -1135,7 +1138,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { //doubleclick: select word int line = 0; - Item *item = NULL; + Item *item = nullptr; bool outside; _find_click(main, b->get_position(), &item, &line, &outside); @@ -1162,11 +1165,11 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { } } else if (!b->is_pressed()) { - selection.click = NULL; + selection.click = nullptr; if (!b->is_doubleclick() && !scroll_updated) { int line = 0; - Item *item = NULL; + Item *item = nullptr; bool outside; _find_click(main, b->get_position(), &item, &line, &outside); @@ -1227,14 +1230,14 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { case KEY_UP: { if (vscroll->is_visible_in_tree()) { - vscroll->set_value(vscroll->get_value() - get_font("normal_font")->get_height()); + vscroll->set_value(vscroll->get_value() - get_theme_font("normal_font")->get_height()); handled = true; } } break; case KEY_DOWN: { if (vscroll->is_visible_in_tree()) { - vscroll->set_value(vscroll->get_value() + get_font("normal_font")->get_height()); + vscroll->set_value(vscroll->get_value() + get_theme_font("normal_font")->get_height()); handled = true; } } break; @@ -1275,7 +1278,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { return; int line = 0; - Item *item = NULL; + Item *item = nullptr; bool outside; _find_click(main, m->get_position(), &item, &line, &outside); @@ -1324,7 +1327,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { emit_signal("meta_hover_started", meta); } } else if (meta_hovering) { - meta_hovering = NULL; + meta_hovering = nullptr; emit_signal("meta_hover_ended", current_meta); current_meta = false; } @@ -1525,11 +1528,11 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { size.width = fixed_width; } Rect2 text_rect = _get_text_rect(); - Color font_color_shadow = get_color("font_color_shadow"); - bool use_outline = get_constant("shadow_as_outline"); - Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); + Color font_color_shadow = get_theme_color("font_color_shadow"); + bool use_outline = get_theme_constant("shadow_as_outline"); + Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); - Ref<Font> base_font = get_font("normal_font"); + Ref<Font> base_font = get_theme_font("normal_font"); for (int i = p_frame->first_invalid_line; i < p_frame->lines.size(); i++) { @@ -1544,7 +1547,7 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { int total_height = 0; if (p_frame->lines.size()) - total_height = p_frame->lines[p_frame->lines.size() - 1].height_accum_cache + get_stylebox("normal")->get_minimum_size().height; + total_height = p_frame->lines[p_frame->lines.size() - 1].height_accum_cache + get_theme_stylebox("normal")->get_minimum_size().height; main->first_invalid_line = p_frame->lines.size(); @@ -1640,12 +1643,16 @@ void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline) } } - if (current_frame->lines[current_frame->lines.size() - 1].from == NULL) { + if (current_frame->lines[current_frame->lines.size() - 1].from == nullptr) { current_frame->lines.write[current_frame->lines.size() - 1].from = p_item; } p_item->line = current_frame->lines.size() - 1; _invalidate_current_line(current_frame); + + if (fixed_width != -1) { + minimum_size_changed(); + } } void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_subitem_line) { @@ -1758,35 +1765,35 @@ void RichTextLabel::push_font(const Ref<Font> &p_font) { } void RichTextLabel::push_normal() { - Ref<Font> normal_font = get_font("normal_font"); + Ref<Font> normal_font = get_theme_font("normal_font"); ERR_FAIL_COND(normal_font.is_null()); push_font(normal_font); } void RichTextLabel::push_bold() { - Ref<Font> bold_font = get_font("bold_font"); + Ref<Font> bold_font = get_theme_font("bold_font"); ERR_FAIL_COND(bold_font.is_null()); push_font(bold_font); } void RichTextLabel::push_bold_italics() { - Ref<Font> bold_italics_font = get_font("bold_italics_font"); + Ref<Font> bold_italics_font = get_theme_font("bold_italics_font"); ERR_FAIL_COND(bold_italics_font.is_null()); push_font(bold_italics_font); } void RichTextLabel::push_italics() { - Ref<Font> italics_font = get_font("italics_font"); + Ref<Font> italics_font = get_theme_font("italics_font"); ERR_FAIL_COND(italics_font.is_null()); push_font(italics_font); } void RichTextLabel::push_mono() { - Ref<Font> mono_font = get_font("mono_font"); + Ref<Font> mono_font = get_theme_font("mono_font"); ERR_FAIL_COND(mono_font.is_null()); push_font(mono_font); @@ -1933,7 +1940,7 @@ void RichTextLabel::push_cell() { item->cell = true; item->parent_line = item->parent_frame->lines.size() - 1; item->lines.resize(1); - item->lines.write[0].from = NULL; + item->lines.write[0].from = nullptr; item->first_invalid_line = 0; } @@ -1964,9 +1971,13 @@ void RichTextLabel::clear() { main->lines.resize(1); main->first_invalid_line = 0; update(); - selection.click = NULL; + selection.click = nullptr; selection.active = false; current_idx = 1; + + if (fixed_width != -1) { + minimum_size_changed(); + } } void RichTextLabel::set_tab_size(int p_spaces) { @@ -2044,13 +2055,13 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { int pos = 0; List<String> tag_stack; - Ref<Font> normal_font = get_font("normal_font"); - Ref<Font> bold_font = get_font("bold_font"); - Ref<Font> italics_font = get_font("italics_font"); - Ref<Font> bold_italics_font = get_font("bold_italics_font"); - Ref<Font> mono_font = get_font("mono_font"); + Ref<Font> normal_font = get_theme_font("normal_font"); + Ref<Font> bold_font = get_theme_font("bold_font"); + Ref<Font> italics_font = get_theme_font("italics_font"); + Ref<Font> bold_italics_font = get_theme_font("bold_italics_font"); + Ref<Font> mono_font = get_theme_font("mono_font"); - Color base_color = get_color("default_color"); + Color base_color = get_theme_color("default_color"); int indent_level = 0; @@ -2507,7 +2518,7 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p if (it->type == ITEM_TEXT) { ItemText *t = static_cast<ItemText *>(it); - int sp = t->text.find(p_string, charidx); + int sp = t->text.findn(p_string, charidx); if (sp != -1) { selection.from = it; selection.from_char = sp; @@ -2518,7 +2529,7 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p _validate_line_caches(main); - int fh = _find_font(t).is_valid() ? _find_font(t)->get_height() : get_font("normal_font")->get_height(); + int fh = _find_font(t).is_valid() ? _find_font(t)->get_height() : get_theme_font("normal_font")->get_height(); float offset = 0; @@ -2584,7 +2595,7 @@ void RichTextLabel::selection_copy() { } if (text != "") { - OS::get_singleton()->set_clipboard(text); + DisplayServer::get_singleton()->clipboard_set(text); } } @@ -2692,7 +2703,7 @@ void RichTextLabel::install_effect(const Variant effect) { int RichTextLabel::get_content_height() { int total_height = 0; if (main->lines.size()) - total_height = main->lines[main->lines.size() - 1].height_accum_cache + get_stylebox("normal")->get_minimum_size().height; + total_height = main->lines[main->lines.size() - 1].height_accum_cache + get_theme_stylebox("normal")->get_minimum_size().height; return total_height; } @@ -2944,7 +2955,7 @@ RichTextLabel::RichTextLabel() { tab_size = 4; default_align = ALIGN_LEFT; underline_meta = true; - meta_hovering = NULL; + meta_hovering = nullptr; override_selected_font_color = false; scroll_visible = false; @@ -2968,7 +2979,7 @@ RichTextLabel::RichTextLabel() { current_idx = 1; use_bbcode = false; - selection.click = NULL; + selection.click = nullptr; selection.active = false; selection.enabled = false; diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index dd439208af..7f2b5facb9 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -98,7 +98,7 @@ private: int maximum_width; Line() { - from = NULL; + from = nullptr; char_count = 0; } }; @@ -119,9 +119,11 @@ private: } Item() { - parent = NULL; - E = NULL; + parent = nullptr; + E = nullptr; line = 0; + index = 0; + type = ITEM_FRAME; } virtual ~Item() { _clear_children(); } }; @@ -135,7 +137,7 @@ private: ItemFrame() { type = ITEM_FRAME; - parent_frame = NULL; + parent_frame = nullptr; cell = false; parent_line = 0; } @@ -368,8 +370,8 @@ private: int visible_characters; float percent_visible; - int _process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Color &p_font_color_shadow, bool p_shadow_as_outline, const Point2 &shadow_ofs, const Point2i &p_click_pos = Point2i(), Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL, int p_char_count = 0); - void _find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL); + int _process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Color &p_font_color_shadow, bool p_shadow_as_outline, const Point2 &shadow_ofs, const Point2i &p_click_pos = Point2i(), Item **r_click_item = nullptr, int *r_click_char = nullptr, bool *r_outside = nullptr, int p_char_count = 0); + void _find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item = nullptr, int *r_click_char = nullptr, bool *r_outside = nullptr); Ref<Font> _find_font(Item *p_item); int _find_margin(Item *p_item, const Ref<Font> &p_base_font); @@ -377,7 +379,7 @@ private: Color _find_color(Item *p_item, const Color &p_default_color); bool _find_underline(Item *p_item); bool _find_strikethrough(Item *p_item); - bool _find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item = NULL); + bool _find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item = nullptr); bool _find_layout_subitem(Item *from, Item *to); bool _find_by_type(Item *p_item, ItemType p_type); void _fetch_item_fx_stack(Item *p_item, Vector<ItemFX *> &r_stack); diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index fef5e00984..1c63c25e28 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -33,6 +33,7 @@ #include "core/os/keyboard.h" #include "core/os/os.h" #include "core/print_string.h" +#include "scene/main/window.h" bool ScrollBar::focus_by_default = false; @@ -71,8 +72,8 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { if (b->is_pressed()) { double ofs = orientation == VERTICAL ? b->get_position().y : b->get_position().x; - Ref<Texture2D> decr = get_icon("decrement"); - Ref<Texture2D> incr = get_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon("increment"); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width(); @@ -148,7 +149,7 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { if (drag.active) { double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x; - Ref<Texture2D> decr = get_icon("decrement"); + Ref<Texture2D> decr = get_theme_icon("decrement"); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); ofs -= decr_size; @@ -159,8 +160,8 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { } else { double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x; - Ref<Texture2D> decr = get_icon("decrement"); - Ref<Texture2D> incr = get_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon("increment"); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width(); @@ -233,17 +234,17 @@ void ScrollBar::_notification(int p_what) { RID ci = get_canvas_item(); - Ref<Texture2D> decr = highlight == HIGHLIGHT_DECR ? get_icon("decrement_highlight") : get_icon("decrement"); - Ref<Texture2D> incr = highlight == HIGHLIGHT_INCR ? get_icon("increment_highlight") : get_icon("increment"); - Ref<StyleBox> bg = has_focus() ? get_stylebox("scroll_focus") : get_stylebox("scroll"); + Ref<Texture2D> decr = highlight == HIGHLIGHT_DECR ? get_theme_icon("decrement_highlight") : get_theme_icon("decrement"); + Ref<Texture2D> incr = highlight == HIGHLIGHT_INCR ? get_theme_icon("increment_highlight") : get_theme_icon("increment"); + Ref<StyleBox> bg = has_focus() ? get_theme_stylebox("scroll_focus") : get_theme_stylebox("scroll"); Ref<StyleBox> grabber; if (drag.active) - grabber = get_stylebox("grabber_pressed"); + grabber = get_theme_stylebox("grabber_pressed"); else if (highlight == HIGHLIGHT_RANGE) - grabber = get_stylebox("grabber_highlight"); + grabber = get_theme_stylebox("grabber_highlight"); else - grabber = get_stylebox("grabber"); + grabber = get_theme_stylebox("grabber"); Point2 ofs; @@ -307,7 +308,7 @@ void ScrollBar::_notification(int p_what) { drag_node->disconnect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit)); } - drag_node = NULL; + drag_node = nullptr; } if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) { @@ -416,7 +417,7 @@ void ScrollBar::_notification(int p_what) { double ScrollBar::get_grabber_min_size() const { - Ref<StyleBox> grabber = get_stylebox("grabber"); + Ref<StyleBox> grabber = get_theme_stylebox("grabber"); Size2 gminsize = grabber->get_minimum_size() + grabber->get_center_size(); return (orientation == VERTICAL) ? gminsize.height : gminsize.width; } @@ -442,17 +443,17 @@ double ScrollBar::get_area_size() const { switch (orientation) { case VERTICAL: { double area = get_size().height; - area -= get_stylebox("scroll")->get_minimum_size().height; - area -= get_icon("increment")->get_height(); - area -= get_icon("decrement")->get_height(); + area -= get_theme_stylebox("scroll")->get_minimum_size().height; + area -= get_theme_icon("increment")->get_height(); + area -= get_theme_icon("decrement")->get_height(); area -= get_grabber_min_size(); return area; } break; case HORIZONTAL: { double area = get_size().width; - area -= get_stylebox("scroll")->get_minimum_size().width; - area -= get_icon("increment")->get_width(); - area -= get_icon("decrement")->get_width(); + area -= get_theme_stylebox("scroll")->get_minimum_size().width; + area -= get_theme_icon("increment")->get_width(); + area -= get_theme_icon("decrement")->get_width(); area -= get_grabber_min_size(); return area; } break; @@ -468,14 +469,14 @@ double ScrollBar::get_area_offset() const { if (orientation == VERTICAL) { - ofs += get_stylebox("hscroll")->get_margin(MARGIN_TOP); - ofs += get_icon("decrement")->get_height(); + ofs += get_theme_stylebox("hscroll")->get_margin(MARGIN_TOP); + ofs += get_theme_icon("decrement")->get_height(); } if (orientation == HORIZONTAL) { - ofs += get_stylebox("hscroll")->get_margin(MARGIN_LEFT); - ofs += get_icon("decrement")->get_width(); + ofs += get_theme_stylebox("hscroll")->get_margin(MARGIN_LEFT); + ofs += get_theme_icon("decrement")->get_width(); } return ofs; @@ -500,9 +501,9 @@ double ScrollBar::get_grabber_offset() const { Size2 ScrollBar::get_minimum_size() const { - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); - Ref<StyleBox> bg = get_stylebox("scroll"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<StyleBox> bg = get_theme_stylebox("scroll"); Size2 minsize; if (orientation == VERTICAL) { @@ -541,7 +542,7 @@ void ScrollBar::_drag_node_exit() { if (drag_node) { drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input)); } - drag_node = NULL; + drag_node = nullptr; } void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) { @@ -559,8 +560,7 @@ void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) { drag_node_accum = Vector2(); last_drag_node_accum = Vector2(); drag_node_from = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0); - - drag_node_touching = OS::get_singleton()->has_touchscreen_ui_hint(); + drag_node_touching = !DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())); drag_node_touching_deaccel = false; time_since_motion = 0; @@ -616,7 +616,7 @@ void ScrollBar::set_drag_node(const NodePath &p_path) { } } - drag_node = NULL; + drag_node = nullptr; drag_node_path = p_path; if (is_inside_tree()) { @@ -662,7 +662,7 @@ ScrollBar::ScrollBar(Orientation p_orientation) { orientation = p_orientation; highlight = HIGHLIGHT_NONE; custom_step = -1; - drag_node = NULL; + drag_node = nullptr; drag.active = false; diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index c25a6d5a0c..fb17adf96e 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -30,7 +30,7 @@ #include "scroll_container.h" #include "core/os/os.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" bool ScrollContainer::clips_input() const { @@ -39,7 +39,7 @@ bool ScrollContainer::clips_input() const { Size2 ScrollContainer::get_minimum_size() const { - Ref<StyleBox> sb = get_stylebox("bg"); + Ref<StyleBox> sb = get_theme_stylebox("bg"); Size2 min_size; for (int i = 0; i < get_child_count(); i++) { @@ -129,7 +129,7 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) { if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) accept_event(); //accept event if scroll changed - if (!OS::get_singleton()->has_touchscreen_ui_hint()) + if (!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id()))) return; if (mb->get_button_index() != BUTTON_LEFT) @@ -145,7 +145,7 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) { drag_accum = Vector2(); last_drag_accum = Vector2(); drag_from = Vector2(h_scroll->get_value(), v_scroll->get_value()); - drag_touching = OS::get_singleton()->has_touchscreen_ui_hint(); + drag_touching = !DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())); drag_touching_deaccel = false; beyond_deadzone = false; time_since_motion = 0; @@ -276,7 +276,7 @@ void ScrollContainer::_notification(int p_what) { Size2 size = get_size(); Point2 ofs; - Ref<StyleBox> sb = get_stylebox("bg"); + Ref<StyleBox> sb = get_theme_stylebox("bg"); size -= sb->get_minimum_size(); ofs += sb->get_offset(); @@ -323,7 +323,7 @@ void ScrollContainer::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - Ref<StyleBox> sb = get_stylebox("bg"); + Ref<StyleBox> sb = get_theme_stylebox("bg"); draw_style_box(sb, Rect2(Vector2(), get_size())); update_scrollbars(); @@ -404,7 +404,7 @@ void ScrollContainer::_notification(int p_what) { void ScrollContainer::update_scrollbars() { Size2 size = get_size(); - Ref<StyleBox> sb = get_stylebox("bg"); + Ref<StyleBox> sb = get_theme_stylebox("bg"); size -= sb->get_minimum_size(); Size2 hmin; diff --git a/scene/gui/separator.cpp b/scene/gui/separator.cpp index 4635efb233..75c4b7cce9 100644 --- a/scene/gui/separator.cpp +++ b/scene/gui/separator.cpp @@ -34,9 +34,9 @@ Size2 Separator::get_minimum_size() const { Size2 ms(3, 3); if (orientation == VERTICAL) { - ms.x = get_constant("separation"); + ms.x = get_theme_constant("separation"); } else { // HORIZONTAL - ms.y = get_constant("separation"); + ms.y = get_theme_constant("separation"); } return ms; } @@ -48,7 +48,7 @@ void Separator::_notification(int p_what) { case NOTIFICATION_DRAW: { Size2i size = get_size(); - Ref<StyleBox> style = get_stylebox("separator"); + Ref<StyleBox> style = get_theme_stylebox("separator"); Size2i ssize = style->get_minimum_size() + style->get_center_size(); if (orientation == VERTICAL) { diff --git a/scene/gui/shortcut.h b/scene/gui/shortcut.h index 59d3245db5..b22c3441c5 100644 --- a/scene/gui/shortcut.h +++ b/scene/gui/shortcut.h @@ -31,7 +31,7 @@ #ifndef SHORTCUT_H #define SHORTCUT_H -#include "core/os/input_event.h" +#include "core/input/input_event.h" #include "core/resource.h" class ShortCut : public Resource { diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 85887ef7b1..1f135163d4 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -33,10 +33,10 @@ Size2 Slider::get_minimum_size() const { - Ref<StyleBox> style = get_stylebox("slider"); + Ref<StyleBox> style = get_theme_stylebox("slider"); Size2i ss = style->get_minimum_size() + style->get_center_size(); - Ref<Texture2D> grabber = get_icon("grabber"); + Ref<Texture2D> grabber = get_theme_icon("grabber"); Size2i rs = grabber->get_size(); if (orientation == HORIZONTAL) @@ -57,7 +57,7 @@ void Slider::_gui_input(Ref<InputEvent> p_event) { if (mb->get_button_index() == BUTTON_LEFT) { if (mb->is_pressed()) { - Ref<Texture2D> grabber = get_icon(mouse_inside || has_focus() ? "grabber_highlight" : "grabber"); + Ref<Texture2D> grabber = get_theme_icon(mouse_inside || has_focus() ? "grabber_highlight" : "grabber"); grab.pos = orientation == VERTICAL ? mb->get_position().y : mb->get_position().x; double grab_width = (double)grabber->get_size().width; @@ -87,7 +87,7 @@ void Slider::_gui_input(Ref<InputEvent> p_event) { if (grab.active) { Size2i size = get_size(); - Ref<Texture2D> grabber = get_icon("grabber"); + Ref<Texture2D> grabber = get_theme_icon("grabber"); float motion = (orientation == VERTICAL ? mm->get_position().y : mm->get_position().x) - grab.pos; if (orientation == VERTICAL) motion = -motion; @@ -165,10 +165,11 @@ void Slider::_notification(int p_what) { case NOTIFICATION_DRAW: { RID ci = get_canvas_item(); Size2i size = get_size(); - Ref<StyleBox> style = get_stylebox("slider"); - Ref<StyleBox> grabber_area = get_stylebox("grabber_area"); - Ref<Texture2D> grabber = get_icon(editable ? ((mouse_inside || has_focus()) ? "grabber_highlight" : "grabber") : "grabber_disabled"); - Ref<Texture2D> tick = get_icon("tick"); + Ref<StyleBox> style = get_theme_stylebox("slider"); + bool highlighted = mouse_inside || has_focus(); + Ref<StyleBox> grabber_area = get_theme_stylebox(highlighted ? "grabber_area_highlight" : "grabber_area"); + Ref<Texture2D> grabber = get_theme_icon(editable ? (highlighted ? "grabber_highlight" : "grabber") : "grabber_disabled"); + Ref<Texture2D> tick = get_theme_icon("tick"); double ratio = Math::is_nan(get_as_ratio()) ? 0 : get_as_ratio(); if (orientation == VERTICAL) { diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 576de98a4f..8572d570fb 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -29,8 +29,9 @@ /*************************************************************************/ #include "spin_box.h" + +#include "core/input/input_filter.h" #include "core/math/expression.h" -#include "core/os/input.h" Size2 SpinBox::get_minimum_size() const { @@ -59,7 +60,7 @@ void SpinBox::_text_entered(const String &p_string) { return; } - Variant value = expr->execute(Array(), NULL, false); + Variant value = expr->execute(Array(), nullptr, false); if (value.get_type() != Variant::NIL) { set_value(value); _value_changed(0); @@ -76,7 +77,7 @@ void SpinBox::_line_edit_input(const Ref<InputEvent> &p_event) { void SpinBox::_range_click_timeout() { - if (!drag.enabled && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { + if (!drag.enabled && InputFilter::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { bool up = get_local_mouse_position().y < (get_size().height / 2); set_value(get_value() + (up ? get_step() : -get_step())); @@ -148,7 +149,7 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) { if (drag.enabled) { drag.enabled = false; - Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE); warp_mouse(drag.capture_pos); } drag.allowed = false; @@ -165,7 +166,7 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) { set_value(CLAMP(drag.base_val + get_step() * diff_y, get_min(), get_max())); } else if (drag.allowed && drag.capture_pos.distance_to(mm->get_position()) > 2) { - Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED); + InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_CAPTURED); drag.enabled = true; drag.base_val = get_value(); drag.diff_y = 0; @@ -195,7 +196,7 @@ void SpinBox::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - Ref<Texture2D> updown = get_icon("updown"); + Ref<Texture2D> updown = get_theme_icon("updown"); _adjust_width_for_icon(updown); @@ -209,7 +210,7 @@ void SpinBox::_notification(int p_what) { //_value_changed(0); } else if (p_what == NOTIFICATION_ENTER_TREE) { - _adjust_width_for_icon(get_icon("updown")); + _adjust_width_for_icon(get_theme_icon("updown")); _value_changed(0); } else if (p_what == NOTIFICATION_THEME_CHANGED) { diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index 255278be2b..de892a4fb9 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -50,7 +50,7 @@ Control *SplitContainer::_getch(int p_idx) const { idx++; } - return NULL; + return nullptr; } void SplitContainer::_resort() { @@ -74,8 +74,8 @@ void SplitContainer::_resort() { bool second_expanded = (vertical ? second->get_v_size_flags() : second->get_h_size_flags()) & SIZE_EXPAND; // Determine the separation between items - Ref<Texture2D> g = get_icon("grabber"); - int sep = get_constant("separation"); + Ref<Texture2D> g = get_theme_icon("grabber"); + int sep = get_theme_constant("separation"); sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0; // Compute the minimum size @@ -123,8 +123,8 @@ Size2 SplitContainer::get_minimum_size() const { /* Calculate MINIMUM SIZE */ Size2i minimum; - Ref<Texture2D> g = get_icon("grabber"); - int sep = get_constant("separation"); + Ref<Texture2D> g = get_theme_icon("grabber"); + int sep = get_theme_constant("separation"); sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0; for (int i = 0; i < 2; i++) { @@ -167,7 +167,7 @@ void SplitContainer::_notification(int p_what) { case NOTIFICATION_MOUSE_EXIT: { mouse_inside = false; - if (get_constant("autohide")) + if (get_theme_constant("autohide")) update(); } break; case NOTIFICATION_DRAW: { @@ -175,14 +175,14 @@ void SplitContainer::_notification(int p_what) { if (!_getch(0) || !_getch(1)) return; - if (collapsed || (!dragging && !mouse_inside && get_constant("autohide"))) + if (collapsed || (!dragging && !mouse_inside && get_theme_constant("autohide"))) return; if (dragger_visibility != DRAGGER_VISIBLE) return; - int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_constant("separation") : 0; - Ref<Texture2D> tex = get_icon("grabber"); + int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_theme_constant("separation") : 0; + Ref<Texture2D> tex = get_theme_icon("grabber"); Size2 size = get_size(); if (vertical) @@ -210,7 +210,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { if (mb->is_pressed()) { - int sep = get_constant("separation"); + int sep = get_theme_constant("separation"); if (vertical) { @@ -242,14 +242,14 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { bool mouse_inside_state = false; if (vertical) - mouse_inside_state = mm->get_position().y > middle_sep && mm->get_position().y < middle_sep + get_constant("separation"); + mouse_inside_state = mm->get_position().y > middle_sep && mm->get_position().y < middle_sep + get_theme_constant("separation"); else - mouse_inside_state = mm->get_position().x > middle_sep && mm->get_position().x < middle_sep + get_constant("separation"); + mouse_inside_state = mm->get_position().x > middle_sep && mm->get_position().x < middle_sep + get_theme_constant("separation"); if (mouse_inside != mouse_inside_state) { mouse_inside = mouse_inside_state; - if (get_constant("autohide")) + if (get_theme_constant("autohide")) update(); } @@ -270,7 +270,7 @@ Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const if (!collapsed && _getch(0) && _getch(1) && dragger_visibility == DRAGGER_VISIBLE) { - int sep = get_constant("separation"); + int sep = get_theme_constant("separation"); if (vertical) { diff --git a/scene/gui/viewport_container.cpp b/scene/gui/subviewport_container.cpp index a76f2924d3..50f468741d 100644 --- a/scene/gui/viewport_container.cpp +++ b/scene/gui/subviewport_container.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* viewport_container.cpp */ +/* subviewport_container.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,19 +28,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "viewport_container.h" +#include "subviewport_container.h" #include "core/engine.h" #include "scene/main/viewport.h" -Size2 ViewportContainer::get_minimum_size() const { +Size2 SubViewportContainer::get_minimum_size() const { if (stretch) return Size2(); Size2 ms; for (int i = 0; i < get_child_count(); i++) { - Viewport *c = Object::cast_to<Viewport>(get_child(i)); + SubViewport *c = Object::cast_to<SubViewport>(get_child(i)); if (!c) continue; @@ -52,19 +52,19 @@ Size2 ViewportContainer::get_minimum_size() const { return ms; } -void ViewportContainer::set_stretch(bool p_enable) { +void SubViewportContainer::set_stretch(bool p_enable) { stretch = p_enable; queue_sort(); update(); } -bool ViewportContainer::is_stretch_enabled() const { +bool SubViewportContainer::is_stretch_enabled() const { return stretch; } -void ViewportContainer::set_stretch_shrink(int p_shrink) { +void SubViewportContainer::set_stretch_shrink(int p_shrink) { ERR_FAIL_COND(p_shrink < 1); if (shrink == p_shrink) @@ -77,7 +77,7 @@ void ViewportContainer::set_stretch_shrink(int p_shrink) { for (int i = 0; i < get_child_count(); i++) { - Viewport *c = Object::cast_to<Viewport>(get_child(i)); + SubViewport *c = Object::cast_to<SubViewport>(get_child(i)); if (!c) continue; @@ -87,12 +87,12 @@ void ViewportContainer::set_stretch_shrink(int p_shrink) { update(); } -int ViewportContainer::get_stretch_shrink() const { +int SubViewportContainer::get_stretch_shrink() const { return shrink; } -void ViewportContainer::_notification(int p_what) { +void SubViewportContainer::_notification(int p_what) { if (p_what == NOTIFICATION_RESIZED) { @@ -101,7 +101,7 @@ void ViewportContainer::_notification(int p_what) { for (int i = 0; i < get_child_count(); i++) { - Viewport *c = Object::cast_to<Viewport>(get_child(i)); + SubViewport *c = Object::cast_to<SubViewport>(get_child(i)); if (!c) continue; @@ -113,14 +113,14 @@ void ViewportContainer::_notification(int p_what) { for (int i = 0; i < get_child_count(); i++) { - Viewport *c = Object::cast_to<Viewport>(get_child(i)); + SubViewport *c = Object::cast_to<SubViewport>(get_child(i)); if (!c) continue; if (is_visible_in_tree()) - c->set_update_mode(Viewport::UPDATE_ALWAYS); + c->set_update_mode(SubViewport::UPDATE_ALWAYS); else - c->set_update_mode(Viewport::UPDATE_DISABLED); + c->set_update_mode(SubViewport::UPDATE_DISABLED); c->set_handle_input_locally(false); //do not handle input locally here } @@ -130,7 +130,7 @@ void ViewportContainer::_notification(int p_what) { for (int i = 0; i < get_child_count(); i++) { - Viewport *c = Object::cast_to<Viewport>(get_child(i)); + SubViewport *c = Object::cast_to<SubViewport>(get_child(i)); if (!c) continue; @@ -142,7 +142,7 @@ void ViewportContainer::_notification(int p_what) { } } -void ViewportContainer::_input(const Ref<InputEvent> &p_event) { +void SubViewportContainer::_input(const Ref<InputEvent> &p_event) { if (Engine::get_singleton()->is_editor_hint()) return; @@ -159,7 +159,7 @@ void ViewportContainer::_input(const Ref<InputEvent> &p_event) { for (int i = 0; i < get_child_count(); i++) { - Viewport *c = Object::cast_to<Viewport>(get_child(i)); + SubViewport *c = Object::cast_to<SubViewport>(get_child(i)); if (!c || c->is_input_disabled()) continue; @@ -167,7 +167,7 @@ void ViewportContainer::_input(const Ref<InputEvent> &p_event) { } } -void ViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) { +void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) { if (Engine::get_singleton()->is_editor_hint()) return; @@ -184,7 +184,7 @@ void ViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) { for (int i = 0; i < get_child_count(); i++) { - Viewport *c = Object::cast_to<Viewport>(get_child(i)); + SubViewport *c = Object::cast_to<SubViewport>(get_child(i)); if (!c || c->is_input_disabled()) continue; @@ -192,21 +192,21 @@ void ViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) { } } -void ViewportContainer::_bind_methods() { +void SubViewportContainer::_bind_methods() { - ClassDB::bind_method(D_METHOD("_unhandled_input", "event"), &ViewportContainer::_unhandled_input); - ClassDB::bind_method(D_METHOD("_input", "event"), &ViewportContainer::_input); - ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &ViewportContainer::set_stretch); - ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &ViewportContainer::is_stretch_enabled); + ClassDB::bind_method(D_METHOD("_unhandled_input", "event"), &SubViewportContainer::_unhandled_input); + ClassDB::bind_method(D_METHOD("_input", "event"), &SubViewportContainer::_input); + ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &SubViewportContainer::set_stretch); + ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &SubViewportContainer::is_stretch_enabled); - ClassDB::bind_method(D_METHOD("set_stretch_shrink", "amount"), &ViewportContainer::set_stretch_shrink); - ClassDB::bind_method(D_METHOD("get_stretch_shrink"), &ViewportContainer::get_stretch_shrink); + ClassDB::bind_method(D_METHOD("set_stretch_shrink", "amount"), &SubViewportContainer::set_stretch_shrink); + ClassDB::bind_method(D_METHOD("get_stretch_shrink"), &SubViewportContainer::get_stretch_shrink); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stretch"), "set_stretch", "is_stretch_enabled"); ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_shrink"), "set_stretch_shrink", "get_stretch_shrink"); } -ViewportContainer::ViewportContainer() { +SubViewportContainer::SubViewportContainer() { stretch = false; shrink = 1; diff --git a/scene/gui/viewport_container.h b/scene/gui/subviewport_container.h index 8597444426..6ff3d188e2 100644 --- a/scene/gui/viewport_container.h +++ b/scene/gui/subviewport_container.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* viewport_container.h */ +/* subviewport_container.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -33,9 +33,9 @@ #include "scene/gui/container.h" -class ViewportContainer : public Container { +class SubViewportContainer : public Container { - GDCLASS(ViewportContainer, Container); + GDCLASS(SubViewportContainer, Container); bool stretch; int shrink; @@ -55,7 +55,7 @@ public: virtual Size2 get_minimum_size() const; - ViewportContainer(); + SubViewportContainer(); }; #endif // VIEWPORTCONTAINER_H diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 6290d364fc..3a128cf8e6 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -41,14 +41,14 @@ int TabContainer::_get_top_margin() const { return 0; // Respect the minimum tab height. - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); int tab_height = MAX(MAX(tab_bg->get_minimum_size().height, tab_fg->get_minimum_size().height), tab_disabled->get_minimum_size().height); // Font height or higher icon wins. - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); int content_height = font->get_height(); Vector<Control *> tabs = _get_tabs(); @@ -81,15 +81,15 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { return; // Handle menu button. - Ref<Texture2D> menu = get_icon("menu"); + Ref<Texture2D> menu = get_theme_icon("menu"); if (popup && pos.x > size.width - menu->get_width()) { emit_signal("pre_popup_pressed"); - Vector2 popup_pos = get_global_position(); - popup_pos.x += size.width * get_global_transform().get_scale().x - popup->get_size().width * popup->get_global_transform().get_scale().x; - popup_pos.y += menu->get_height() * get_global_transform().get_scale().y; + Vector2 popup_pos = get_screen_position(); + popup_pos.x += size.width - popup->get_size().width; + popup_pos.y += menu->get_height(); - popup->set_global_position(popup_pos); + popup->set_position(popup_pos); popup->popup(); return; } @@ -107,8 +107,8 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { popup_ofs = menu->get_width(); } - Ref<Texture2D> increment = get_icon("increment"); - Ref<Texture2D> decrement = get_icon("decrement"); + Ref<Texture2D> increment = get_theme_icon("increment"); + Ref<Texture2D> decrement = get_theme_icon("decrement"); if (pos.x > size.width - increment->get_width() - popup_ofs) { if (last_tab_cache < tabs.size() - 1) { first_tab_cache += 1; @@ -159,7 +159,7 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { return; } - Ref<Texture2D> menu = get_icon("menu"); + Ref<Texture2D> menu = get_theme_icon("menu"); if (popup) { if (pos.x >= size.width - menu->get_width()) { @@ -191,8 +191,8 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { popup_ofs = menu->get_width(); } - Ref<Texture2D> increment = get_icon("increment"); - Ref<Texture2D> decrement = get_icon("decrement"); + Ref<Texture2D> increment = get_theme_icon("increment"); + Ref<Texture2D> decrement = get_theme_icon("decrement"); if (pos.x >= size.width - increment->get_width() - popup_ofs) { if (highlight_arrow != 1) { @@ -224,10 +224,10 @@ void TabContainer::_notification(int p_what) { case NOTIFICATION_RESIZED: { Vector<Control *> tabs = _get_tabs(); - int side_margin = get_constant("side_margin"); - Ref<Texture2D> menu = get_icon("menu"); - Ref<Texture2D> increment = get_icon("increment"); - Ref<Texture2D> decrement = get_icon("decrement"); + int side_margin = get_theme_constant("side_margin"); + Ref<Texture2D> menu = get_theme_icon("menu"); + Ref<Texture2D> increment = get_theme_icon("increment"); + Ref<Texture2D> decrement = get_theme_icon("decrement"); int header_width = get_size().width - side_margin * 2; // Find the width of the header area. @@ -262,28 +262,28 @@ void TabContainer::_notification(int p_what) { Size2 size = get_size(); // Draw only the tab area if the header is hidden. - Ref<StyleBox> panel = get_stylebox("panel"); + Ref<StyleBox> panel = get_theme_stylebox("panel"); if (!tabs_visible) { panel->draw(canvas, Rect2(0, 0, size.width, size.height)); return; } Vector<Control *> tabs = _get_tabs(); - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); - Ref<Texture2D> increment = get_icon("increment"); - Ref<Texture2D> increment_hl = get_icon("increment_highlight"); - Ref<Texture2D> decrement = get_icon("decrement"); - Ref<Texture2D> decrement_hl = get_icon("decrement_highlight"); - Ref<Texture2D> menu = get_icon("menu"); - Ref<Texture2D> menu_hl = get_icon("menu_highlight"); - Ref<Font> font = get_font("font"); - Color font_color_fg = get_color("font_color_fg"); - Color font_color_bg = get_color("font_color_bg"); - Color font_color_disabled = get_color("font_color_disabled"); - int side_margin = get_constant("side_margin"); - int icon_text_distance = get_constant("hseparation"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<Texture2D> increment = get_theme_icon("increment"); + Ref<Texture2D> increment_hl = get_theme_icon("increment_highlight"); + Ref<Texture2D> decrement = get_theme_icon("decrement"); + Ref<Texture2D> decrement_hl = get_theme_icon("decrement_highlight"); + Ref<Texture2D> menu = get_theme_icon("menu"); + Ref<Texture2D> menu_hl = get_theme_icon("menu_highlight"); + Ref<Font> font = get_theme_font("font"); + Color font_color_fg = get_theme_color("font_color_fg"); + Color font_color_bg = get_theme_color("font_color_bg"); + Color font_color_disabled = get_theme_color("font_color_disabled"); + int side_margin = get_theme_constant("side_margin"); + int icon_text_distance = get_theme_constant("hseparation"); // Find out start and width of the header area. int header_x = side_margin; @@ -458,7 +458,7 @@ int TabContainer::_get_tab_width(int p_index) const { return 0; // Get the width of the text displayed on the tab. - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(control->get_name()); int width = font->get_string_size(text).width; @@ -468,14 +468,14 @@ int TabContainer::_get_tab_width(int p_index) const { if (icon.is_valid()) { width += icon->get_width(); if (text != "") - width += get_constant("hseparation"); + width += get_theme_constant("hseparation"); } } // Respect a minimum size. - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); if (get_tab_disabled(p_index)) { width += tab_disabled->get_minimum_size().width; } else if (p_index == current) { @@ -530,7 +530,7 @@ void TabContainer::add_child_notify(Node *p_child) { c->set_anchors_and_margins_preset(Control::PRESET_WIDE); if (tabs_visible) c->set_margin(MARGIN_TOP, _get_top_margin()); - Ref<StyleBox> sb = get_stylebox("panel"); + Ref<StyleBox> sb = get_theme_stylebox("panel"); c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP))); c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT))); c->set_margin(Margin(MARGIN_RIGHT), c->get_margin(Margin(MARGIN_RIGHT)) - sb->get_margin(Margin(MARGIN_RIGHT))); @@ -554,7 +554,7 @@ void TabContainer::set_current_tab(int p_current) { int pending_previous = current; current = p_current; - Ref<StyleBox> sb = get_stylebox("panel"); + Ref<StyleBox> sb = get_theme_stylebox("panel"); Vector<Control *> tabs = _get_tabs(); for (int i = 0; i < tabs.size(); i++) { @@ -602,7 +602,7 @@ Control *TabContainer::get_tab_control(int p_idx) const { if (p_idx >= 0 && p_idx < tabs.size()) return tabs[p_idx]; else - return NULL; + return nullptr; } Control *TabContainer::get_current_tab_control() const { @@ -611,7 +611,7 @@ Control *TabContainer::get_current_tab_control() const { if (current >= 0 && current < tabs.size()) return tabs[current]; else - return NULL; + return nullptr; } void TabContainer::remove_child_notify(Node *p_child) { @@ -745,12 +745,12 @@ int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const { int right_ofs = 0; if (popup) { - Ref<Texture2D> menu = get_icon("menu"); + Ref<Texture2D> menu = get_theme_icon("menu"); right_ofs += menu->get_width(); } if (buttons_visible_cache) { - Ref<Texture2D> increment = get_icon("increment"); - Ref<Texture2D> decrement = get_icon("decrement"); + Ref<Texture2D> increment = get_theme_icon("increment"); + Ref<Texture2D> decrement = get_theme_icon("decrement"); right_ofs += increment->get_width() + decrement->get_width(); } if (p_point.x > size.width - right_ofs) { @@ -933,17 +933,17 @@ Size2 TabContainer::get_minimum_size() const { ms.y = MAX(ms.y, cms.y); } - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); - Ref<Font> font = get_font("font"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<Font> font = get_theme_font("font"); if (tabs_visible) { ms.y += MAX(MAX(tab_bg->get_minimum_size().y, tab_fg->get_minimum_size().y), tab_disabled->get_minimum_size().y); ms.y += font->get_height(); } - Ref<StyleBox> sb = get_stylebox("panel"); + Ref<StyleBox> sb = get_theme_stylebox("panel"); ms += sb->get_minimum_size(); return ms; @@ -990,7 +990,7 @@ void TabContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_current_tab"), &TabContainer::get_current_tab); ClassDB::bind_method(D_METHOD("get_previous_tab"), &TabContainer::get_previous_tab); ClassDB::bind_method(D_METHOD("get_current_tab_control"), &TabContainer::get_current_tab_control); - ClassDB::bind_method(D_METHOD("get_tab_control", "idx"), &TabContainer::get_tab_control); + ClassDB::bind_method(D_METHOD("get_tab_control", "tab_idx"), &TabContainer::get_tab_control); ClassDB::bind_method(D_METHOD("set_tab_align", "align"), &TabContainer::set_tab_align); ClassDB::bind_method(D_METHOD("get_tab_align"), &TabContainer::get_tab_align); ClassDB::bind_method(D_METHOD("set_tabs_visible", "visible"), &TabContainer::set_tabs_visible); @@ -1041,7 +1041,7 @@ TabContainer::TabContainer() { previous = 0; align = ALIGN_CENTER; tabs_visible = true; - popup = NULL; + popup = nullptr; drag_to_rearrange_enabled = false; tabs_rearrange_group = -1; use_hidden_tabs_for_min_size = false; diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index 901408919a..1a3b53f489 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -37,10 +37,10 @@ Size2 Tabs::get_minimum_size() const { - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); - Ref<Font> font = get_font("font"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<Font> font = get_theme_font("font"); Size2 ms(0, MAX(MAX(tab_bg->get_minimum_size().height, tab_fg->get_minimum_size().height), tab_disabled->get_minimum_size().height) + font->get_height()); @@ -50,7 +50,7 @@ Size2 Tabs::get_minimum_size() const { if (tex.is_valid()) { ms.height = MAX(ms.height, tex->get_size().height); if (tabs[i].text != "") - ms.width += get_constant("hseparation"); + ms.width += get_theme_constant("hseparation"); } ms.width += Math::ceil(font->get_string_size(tabs[i].xl_text).width); @@ -65,15 +65,15 @@ Size2 Tabs::get_minimum_size() const { if (tabs[i].right_button.is_valid()) { Ref<Texture2D> rb = tabs[i].right_button; Size2 bms = rb->get_size(); - bms.width += get_constant("hseparation"); + bms.width += get_theme_constant("hseparation"); ms.width += bms.width; ms.height = MAX(bms.height + tab_bg->get_minimum_size().height, ms.height); } if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) { - Ref<Texture2D> cb = get_icon("close"); + Ref<Texture2D> cb = get_theme_icon("close"); Size2 bms = cb->get_size(); - bms.width += get_constant("hseparation"); + bms.width += get_theme_constant("hseparation"); ms.width += bms.width; ms.height = MAX(bms.height + tab_bg->get_minimum_size().height, ms.height); } @@ -94,8 +94,8 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { highlight_arrow = -1; if (buttons_visible) { - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); @@ -163,8 +163,8 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { if (buttons_visible) { - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); @@ -184,10 +184,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { } int found = -1; - for (int i = 0; i < tabs.size(); i++) { - - if (i < offset) - continue; + for (int i = offset; i < tabs.size(); i++) { if (tabs[i].rb_rect.has_point(pos)) { rb_pressing = true; @@ -238,14 +235,14 @@ void Tabs::_notification(int p_what) { _update_cache(); RID ci = get_canvas_item(); - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); - Ref<Font> font = get_font("font"); - Color color_fg = get_color("font_color_fg"); - Color color_bg = get_color("font_color_bg"); - Color color_disabled = get_color("font_color_disabled"); - Ref<Texture2D> close = get_icon("close"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<Font> font = get_theme_font("font"); + Color color_fg = get_theme_color("font_color_fg"); + Color color_bg = get_theme_color("font_color_bg"); + Color color_disabled = get_theme_color("font_color_disabled"); + Ref<Texture2D> close = get_theme_icon("close"); int h = get_size().height; int w = 0; @@ -267,19 +264,16 @@ void Tabs::_notification(int p_what) { w = 0; } - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); - Ref<Texture2D> incr_hl = get_icon("increment_highlight"); - Ref<Texture2D> decr_hl = get_icon("decrement_highlight"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<Texture2D> incr_hl = get_theme_icon("increment_highlight"); + Ref<Texture2D> decr_hl = get_theme_icon("decrement_highlight"); int limit = get_size().width - incr->get_size().width - decr->get_size().width; missing_right = false; - for (int i = 0; i < tabs.size(); i++) { - - if (i < offset) - continue; + for (int i = offset; i < tabs.size(); i++) { tabs.write[i].ofs_cache = w; @@ -318,7 +312,7 @@ void Tabs::_notification(int p_what) { icon->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2)); if (tabs[i].text != "") - w += icon->get_width() + get_constant("hseparation"); + w += icon->get_width() + get_theme_constant("hseparation"); } font->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - font->get_height()) / 2 + font->get_ascent()), tabs[i].xl_text, col, tabs[i].size_text); @@ -327,10 +321,10 @@ void Tabs::_notification(int p_what) { if (tabs[i].right_button.is_valid()) { - Ref<StyleBox> style = get_stylebox("button"); + Ref<StyleBox> style = get_theme_stylebox("button"); Ref<Texture2D> rb = tabs[i].right_button; - w += get_constant("hseparation"); + w += get_theme_constant("hseparation"); Rect2 rb_rect; rb_rect.size = style->get_minimum_size() + rb->get_size(); @@ -339,7 +333,7 @@ void Tabs::_notification(int p_what) { if (rb_hover == i) { if (rb_pressing) - get_stylebox("button_pressed")->draw(ci, rb_rect); + get_theme_stylebox("button_pressed")->draw(ci, rb_rect); else style->draw(ci, rb_rect); } @@ -351,10 +345,10 @@ void Tabs::_notification(int p_what) { if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) { - Ref<StyleBox> style = get_stylebox("button"); + Ref<StyleBox> style = get_theme_stylebox("button"); Ref<Texture2D> cb = close; - w += get_constant("hseparation"); + w += get_theme_constant("hseparation"); Rect2 cb_rect; cb_rect.size = style->get_minimum_size() + cb->get_size(); @@ -363,7 +357,7 @@ void Tabs::_notification(int p_what) { if (!tabs[i].disabled && cb_hover == i) { if (cb_pressing) - get_stylebox("button_pressed")->draw(ci, cb_rect); + get_theme_stylebox("button_pressed")->draw(ci, cb_rect); else style->draw(ci, cb_rect); } @@ -499,10 +493,7 @@ void Tabs::_update_hover() { // test hovering to display right or close button int hover_now = -1; int hover_buttons = -1; - for (int i = 0; i < tabs.size(); i++) { - - if (i < offset) - continue; + for (int i = offset; i < tabs.size(); i++) { Rect2 rect = get_tab_rect(i); if (rect.has_point(pos)) { @@ -532,12 +523,12 @@ void Tabs::_update_hover() { } void Tabs::_update_cache() { - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<Font> font = get_font("font"); - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<Font> font = get_theme_font("font"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); int w = 0; @@ -559,9 +550,8 @@ void Tabs::_update_cache() { if (count_resize > 0) { m_width = MAX((limit - size_fixed) / count_resize, min_width); } - for (int i = 0; i < tabs.size(); i++) { - if (i < offset) - continue; + for (int i = offset; i < tabs.size(); i++) { + Ref<StyleBox> sb; if (tabs[i].disabled) { sb = tab_disabled; @@ -577,12 +567,12 @@ void Tabs::_update_cache() { slen = m_width - (sb->get_margin(MARGIN_LEFT) + sb->get_margin(MARGIN_RIGHT)); if (tabs[i].icon.is_valid()) { slen -= tabs[i].icon->get_width(); - slen -= get_constant("hseparation"); + slen -= get_theme_constant("hseparation"); } if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) { - Ref<Texture2D> cb = get_icon("close"); + Ref<Texture2D> cb = get_theme_icon("close"); slen -= cb->get_width(); - slen -= get_constant("hseparation"); + slen -= get_theme_constant("hseparation"); } slen = MAX(slen, 1); lsize = m_width; @@ -753,10 +743,7 @@ void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) { int Tabs::get_tab_idx_at_point(const Point2 &p_point) const { int hover_now = -1; - for (int i = 0; i < tabs.size(); i++) { - - if (i < offset) - continue; + for (int i = offset; i < tabs.size(); i++) { Rect2 rect = get_tab_rect(i); if (rect.has_point(p_point)) { @@ -799,10 +786,10 @@ int Tabs::get_tab_width(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, tabs.size(), 0); - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); - Ref<Font> font = get_font("font"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<Font> font = get_theme_font("font"); int x = 0; @@ -810,7 +797,7 @@ int Tabs::get_tab_width(int p_idx) const { if (tex.is_valid()) { x += tex->get_width(); if (tabs[p_idx].text != "") - x += get_constant("hseparation"); + x += get_theme_constant("hseparation"); } x += Math::ceil(font->get_string_size(tabs[p_idx].xl_text).width); @@ -825,13 +812,13 @@ int Tabs::get_tab_width(int p_idx) const { if (tabs[p_idx].right_button.is_valid()) { Ref<Texture2D> rb = tabs[p_idx].right_button; x += rb->get_width(); - x += get_constant("hseparation"); + x += get_theme_constant("hseparation"); } if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && p_idx == current)) { - Ref<Texture2D> cb = get_icon("close"); + Ref<Texture2D> cb = get_theme_icon("close"); x += cb->get_width(); - x += get_constant("hseparation"); + x += get_theme_constant("hseparation"); } return x; @@ -842,18 +829,15 @@ void Tabs::_ensure_no_over_offset() { if (!is_inside_tree()) return; - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); while (offset > 0) { int total_w = 0; - for (int i = 0; i < tabs.size(); i++) { - - if (i < offset - 1) - continue; + for (int i = offset - 1; i < tabs.size(); i++) { total_w += tabs[i].size_cache; } @@ -885,8 +869,8 @@ void Tabs::ensure_tab_visible(int p_idx) { } int prev_offset = offset; - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); for (int i = offset; i <= p_idx; i++) { if (tabs[i].ofs_cache + tabs[i].size_cache > limit) { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index cdc2430eb5..36e35897d1 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -30,13 +30,13 @@ #include "text_edit.h" +#include "core/input/input_filter.h" #include "core/message_queue.h" -#include "core/os/input.h" #include "core/os/keyboard.h" #include "core/os/os.h" #include "core/project_settings.h" #include "core/script_language.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" #ifdef TOOLS_ENABLED #include "editor/editor_scale.h" @@ -446,7 +446,7 @@ void TextEdit::_click_selection_held() { // Warning: is_mouse_button_pressed(BUTTON_LEFT) returns false for double+ clicks, so this doesn't work for MODE_WORD // and MODE_LINE. However, moving the mouse triggers _gui_input, which calls these functions too, so that's not a huge problem. // I'm unsure if there's an actual fix that doesn't have a ton of side effects. - if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && selection.selecting_mode != Selection::MODE_NONE) { + if (InputFilter::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && selection.selecting_mode != Selection::MODE_NONE) { switch (selection.selecting_mode) { case Selection::MODE_POINTER: { _update_selection_mode_pointer(); @@ -639,12 +639,12 @@ void TextEdit::_notification(int p_what) { _update_wrap_at(); syntax_highlighting_cache.clear(); } break; - case MainLoop::NOTIFICATION_WM_FOCUS_IN: { + case NOTIFICATION_WM_FOCUS_IN: { window_has_focus = true; draw_caret = true; update(); } break; - case MainLoop::NOTIFICATION_WM_FOCUS_OUT: { + case NOTIFICATION_WM_FOCUS_OUT: { window_has_focus = false; draw_caret = false; update(); @@ -728,7 +728,7 @@ void TextEdit::_notification(int p_what) { _update_scrollbars(); RID ci = get_canvas_item(); - VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true); + RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true); int xmargin_beg = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width + cache.info_gutter_width; int xmargin_end = size.width - cache.style_normal->get_margin(MARGIN_RIGHT) - cache.minimap_width; @@ -749,14 +749,14 @@ void TextEdit::_notification(int p_what) { if (syntax_coloring) { if (cache.background_color.a > 0.01) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(), get_size()), cache.background_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(), get_size()), cache.background_color); } } if (line_length_guidelines) { const int hard_x = xmargin_beg + (int)cache.font->get_char_size('0').width * line_length_guideline_hard_col - cursor.x_ofs; if (hard_x > xmargin_beg && hard_x < xmargin_end) { - VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(hard_x, 0), Point2(hard_x, size.height), cache.line_length_guideline_color); + RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(hard_x, 0), Point2(hard_x, size.height), cache.line_length_guideline_color); } // Draw a "Soft" line length guideline, less visible than the hard line length guideline. @@ -764,7 +764,7 @@ void TextEdit::_notification(int p_what) { // Only drawn if its column differs from the hard line length guideline. const int soft_x = xmargin_beg + (int)cache.font->get_char_size('0').width * line_length_guideline_soft_col - cursor.x_ofs; if (hard_x != soft_x && soft_x > xmargin_beg && soft_x < xmargin_end) { - VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(soft_x, 0), Point2(soft_x, size.height), cache.line_length_guideline_color * Color(1, 1, 1, 0.5)); + RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(soft_x, 0), Point2(soft_x, size.height), cache.line_length_guideline_color * Color(1, 1, 1, 0.5)); } } @@ -955,7 +955,7 @@ void TextEdit::_notification(int p_what) { // draw the minimap Color viewport_color = (cache.background_color.get_v() < 0.5) ? Color(1, 1, 1, 0.1) : Color(0, 0, 0, 0.1); - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), viewport_offset_y, cache.minimap_width, viewport_height), viewport_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), viewport_offset_y, cache.minimap_width, viewport_height), viewport_color); for (int i = 0; i < minimap_draw_amount; i++) { minimap_line++; @@ -1008,7 +1008,7 @@ void TextEdit::_notification(int p_what) { } if (minimap_line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), i * 3, cache.minimap_width, 2), cache.current_line_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), i * 3, cache.minimap_width, 2), cache.current_line_color); } Color previous_color; @@ -1057,7 +1057,7 @@ void TextEdit::_notification(int p_what) { // take one for zero indexing, and if we hit whitespace / the end of a word. int chars = MAX(0, (j - (characters - 1)) - (is_whitespace ? 1 : 0)) + 1; int char_x_ofs = indent_px + ((xmargin_end + minimap_char_size.x) + (minimap_char_size.x * chars)) + tabs; - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_x_ofs, minimap_line_height * i), Point2(minimap_char_size.x * characters, minimap_char_size.y)), previous_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_x_ofs, minimap_line_height * i), Point2(minimap_char_size.x * characters, minimap_char_size.y)), previous_color); } if (out_of_bounds) { @@ -1164,24 +1164,24 @@ void TextEdit::_notification(int p_what) { } if (text.is_marked(line)) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.mark_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.mark_color); } if (str.length() == 0) { // Draw line background if empty as we won't loop at at all. if (line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(ofs_x, ofs_y, xmargin_end, get_row_height()), cache.current_line_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(ofs_x, ofs_y, xmargin_end, get_row_height()), cache.current_line_color); } // Give visual indication of empty selected line. if (selection.active && line >= selection.from_line && line <= selection.to_line && char_margin >= xmargin_beg) { int char_w = cache.font->get_char_size(' ').width; - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, char_w, get_row_height()), cache.selection_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, char_w, get_row_height()), cache.selection_color); } } else { // If it has text, then draw current line marker in the margin, as line number etc will draw over it, draw the rest of line marker later. if (line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_beg + ofs_x, get_row_height()), cache.current_line_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_beg + ofs_x, get_row_height()), cache.current_line_color); } } @@ -1190,9 +1190,9 @@ void TextEdit::_notification(int p_what) { if (text.is_breakpoint(line) && !draw_breakpoint_gutter) { #ifdef TOOLS_ENABLED - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y + get_row_height() - EDSCALE, xmargin_end - xmargin_beg, EDSCALE), cache.breakpoint_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y + get_row_height() - EDSCALE, xmargin_end - xmargin_beg, EDSCALE), cache.breakpoint_color); #else - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.breakpoint_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.breakpoint_color); #endif } @@ -1202,7 +1202,7 @@ void TextEdit::_notification(int p_what) { int vertical_gap = (get_row_height() * 40) / 100; int horizontal_gap = (cache.breakpoint_gutter_width * 30) / 100; int marker_radius = get_row_height() - (vertical_gap * 2); - VisualServer::get_singleton()->canvas_item_add_circle(ci, Point2(cache.style_normal->get_margin(MARGIN_LEFT) + horizontal_gap - 2 + marker_radius / 2, ofs_y + vertical_gap + marker_radius / 2), marker_radius, Color(cache.bookmark_color.r, cache.bookmark_color.g, cache.bookmark_color.b)); + RenderingServer::get_singleton()->canvas_item_add_circle(ci, Point2(cache.style_normal->get_margin(MARGIN_LEFT) + horizontal_gap - 2 + marker_radius / 2, ofs_y + vertical_gap + marker_radius / 2), marker_radius, Color(cache.bookmark_color.r, cache.bookmark_color.g, cache.bookmark_color.b)); } } @@ -1214,7 +1214,7 @@ void TextEdit::_notification(int p_what) { int marker_height = get_row_height() - (vertical_gap * 2); int marker_width = cache.breakpoint_gutter_width - (horizontal_gap * 2); // No transparency on marker. - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cache.style_normal->get_margin(MARGIN_LEFT) + horizontal_gap - 2, ofs_y + vertical_gap, marker_width, marker_height), Color(cache.breakpoint_color.r, cache.breakpoint_color.g, cache.breakpoint_color.b)); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cache.style_normal->get_margin(MARGIN_LEFT) + horizontal_gap - 2, ofs_y + vertical_gap, marker_width, marker_height), Color(cache.breakpoint_color.r, cache.breakpoint_color.g, cache.breakpoint_color.b)); } } @@ -1254,9 +1254,9 @@ void TextEdit::_notification(int p_what) { cache.executing_icon->draw_rect(ci, Rect2(cache.style_normal->get_margin(MARGIN_LEFT) + horizontal_gap - 2 - icon_extra_size / 2, ofs_y + vertical_gap - icon_extra_size / 2, marker_width, marker_height), false, Color(cache.executing_line_color.r, cache.executing_line_color.g, cache.executing_line_color.b)); } else { #ifdef TOOLS_ENABLED - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y + get_row_height() - EDSCALE, xmargin_end - xmargin_beg, EDSCALE), cache.executing_line_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y + get_row_height() - EDSCALE, xmargin_end - xmargin_beg, EDSCALE), cache.executing_line_color); #else - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.executing_line_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.executing_line_color); #endif } } @@ -1315,10 +1315,10 @@ void TextEdit::_notification(int p_what) { if (j == str.length() - 1) { // End of line when last char is skipped. - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - (char_ofs + char_margin + char_w), get_row_height()), cache.current_line_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - (char_ofs + char_margin + char_w), get_row_height()), cache.current_line_color); } else if ((char_ofs + char_margin) > xmargin_beg) { // Char next to margin is skipped. - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, (char_ofs + char_margin) - (xmargin_beg + ofs_x), get_row_height()), cache.current_line_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, (char_ofs + char_margin) - (xmargin_beg + ofs_x), get_row_height()), cache.current_line_color); } } continue; @@ -1338,7 +1338,7 @@ void TextEdit::_notification(int p_what) { in_search_result = j >= search_text_col && j < search_text_col + search_text.length(); if (in_search_result) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin, ofs_y), Size2i(char_w, get_row_height())), cache.search_result_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin, ofs_y), Size2i(char_w, get_row_height())), cache.search_result_color); } } @@ -1348,32 +1348,32 @@ void TextEdit::_notification(int p_what) { if (line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) { // Draw the wrap indent offset highlight. if (line_wrap_index != 0 && j == 0) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(char_ofs + char_margin + ofs_x - indent_px, ofs_y, indent_px, get_row_height()), cache.current_line_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(char_ofs + char_margin + ofs_x - indent_px, ofs_y, indent_px, get_row_height()), cache.current_line_color); } // If its the last char draw to end of the line. if (j == str.length() - 1) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(char_ofs + char_margin + char_w + ofs_x, ofs_y, xmargin_end - (char_ofs + char_margin + char_w), get_row_height()), cache.current_line_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(char_ofs + char_margin + char_w + ofs_x, ofs_y, xmargin_end - (char_ofs + char_margin + char_w), get_row_height()), cache.current_line_color); } // Actual text. if (!in_selection) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, get_row_height())), cache.current_line_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, get_row_height())), cache.current_line_color); } } if (in_selection) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, get_row_height())), cache.selection_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, get_row_height())), cache.selection_color); } if (in_search_result) { Color border_color = (line == search_result_line && j >= search_result_col && j < search_result_col + search_text.length()) ? cache.font_color : cache.search_result_border_color; - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, 1)), border_color); - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y + get_row_height() - 1), Size2i(char_w, 1)), border_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, 1)), border_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y + get_row_height() - 1), Size2i(char_w, 1)), border_color); if (j == search_text_col) - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(1, get_row_height())), border_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(1, get_row_height())), border_color); if (j == search_text_col + search_text.length() - 1) - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + char_w + ofs_x - 1, ofs_y), Size2i(1, get_row_height())), border_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + char_w + ofs_x - 1, ofs_y), Size2i(1, get_row_height())), border_color); } if (highlight_all_occurrences && !only_whitespaces_highlighted) { @@ -1392,7 +1392,7 @@ void TextEdit::_notification(int p_what) { } if (in_highlighted_word) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, get_row_height())), cache.word_highlighted_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, get_row_height())), cache.word_highlighted_color); } } } @@ -1449,9 +1449,9 @@ void TextEdit::_notification(int p_what) { bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y; if (selected) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 3)), color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 3)), color); } else { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 1)), color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 1)), color); } drawer.draw_char(ci, Point2(char_ofs + char_margin + ofs_x, ofs_y + ascent), cchar, next, color); @@ -1468,7 +1468,7 @@ void TextEdit::_notification(int p_what) { #else int caret_h = (block_caret) ? 4 : 2; #endif - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, caret_h)), cache.caret_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, caret_h)), cache.caret_color); } else { #ifdef TOOLS_ENABLED caret_w = (block_caret) ? caret_w : 2 * EDSCALE; @@ -1476,7 +1476,7 @@ void TextEdit::_notification(int p_what) { caret_w = (block_caret) ? caret_w : 2; #endif - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, cache.font->get_height())), cache.caret_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, cache.font->get_height())), cache.caret_color); } } } @@ -1544,9 +1544,9 @@ void TextEdit::_notification(int p_what) { bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y; if (selected) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 3)), color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 3)), color); } else { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 1)), color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 1)), color); } drawer.draw_char(ci, Point2(char_ofs + char_margin + ofs_x, ofs_y + ascent), cchar, next, color); @@ -1564,7 +1564,7 @@ void TextEdit::_notification(int p_what) { #else int caret_h = (block_caret) ? 4 : 2; #endif - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(char_w, caret_h)), cache.caret_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(char_w, caret_h)), cache.caret_color); } else { int char_w = cache.font->get_char_size(' ').width; #ifdef TOOLS_ENABLED @@ -1573,7 +1573,7 @@ void TextEdit::_notification(int p_what) { int caret_w = (block_caret) ? char_w : 2; #endif - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, cache.font->get_height())), cache.caret_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, cache.font->get_height())), cache.caret_color); } } } @@ -1584,11 +1584,11 @@ void TextEdit::_notification(int p_what) { bool completion_below = false; if (completion_active && completion_options.size() > 0) { // Code completion box. - Ref<StyleBox> csb = get_stylebox("completion"); - int maxlines = get_constant("completion_lines"); - int cmax_width = get_constant("completion_max_width") * cache.font->get_char_size('x').x; - int scrollw = get_constant("completion_scroll_width"); - Color scrollc = get_color("completion_scroll_color"); + Ref<StyleBox> csb = get_theme_stylebox("completion"); + int maxlines = get_theme_constant("completion_lines"); + int cmax_width = get_theme_constant("completion_max_width") * cache.font->get_char_size('x').x; + int scrollw = get_theme_constant("completion_scroll_width"); + Color scrollc = get_theme_color("completion_scroll_color"); const int completion_options_size = completion_options.size(); int lines = MIN(completion_options_size, maxlines); @@ -1607,7 +1607,7 @@ void TextEdit::_notification(int p_what) { } // Add space for completion icons. - const int icon_hsep = get_constant("hseparation", "ItemList"); + const int icon_hsep = get_theme_constant("hseparation", "ItemList"); Size2 icon_area_size(get_row_height(), get_row_height()); w += icon_area_size.width + icon_hsep; @@ -1634,10 +1634,10 @@ void TextEdit::_notification(int p_what) { draw_style_box(csb, Rect2(completion_rect.position - csb->get_offset(), completion_rect.size + csb->get_minimum_size() + Size2(scrollw, 0))); if (cache.completion_background_color.a > 0.01) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(completion_rect.position, completion_rect.size + Size2(scrollw, 0)), cache.completion_background_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(completion_rect.position, completion_rect.size + Size2(scrollw, 0)), cache.completion_background_color); } int line_from = CLAMP(completion_index - lines / 2, 0, completion_options_size - lines); - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(completion_rect.position.x, completion_rect.position.y + (completion_index - line_from) * get_row_height()), Size2(completion_rect.size.width, get_row_height())), cache.completion_selected_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(completion_rect.position.x, completion_rect.position.y + (completion_index - line_from) * get_row_height()), Size2(completion_rect.size.width, get_row_height())), cache.completion_selected_color); draw_rect(Rect2(completion_rect.position + Vector2(icon_area_size.x + icon_hsep, 0), Size2(MIN(nofs, completion_rect.size.width - (icon_area_size.x + icon_hsep)), completion_rect.size.height)), cache.completion_existing_color); for (int i = 0; i < lines; i++) { @@ -1694,9 +1694,9 @@ void TextEdit::_notification(int p_what) { if (show_hint) { - Ref<StyleBox> sb = get_stylebox("panel", "TooltipPanel"); + Ref<StyleBox> sb = get_theme_stylebox("panel", "TooltipPanel"); Ref<Font> font = cache.font; - Color font_color = get_color("font_color", "TooltipLabel"); + Color font_color = get_theme_color("font_color", "TooltipLabel"); int max_w = 0; int sc = completion_hint.get_slice_count("\n"); @@ -1754,8 +1754,10 @@ void TextEdit::_notification(int p_what) { } if (has_focus()) { - OS::get_singleton()->set_ime_active(true); - OS::get_singleton()->set_ime_position(get_global_position() + cursor_pos + Point2(0, get_row_height())); + if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id()); + DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + cursor_pos + Point2(0, get_row_height()), get_viewport()->get_window_id()); + } } } break; case NOTIFICATION_FOCUS_ENTER: { @@ -1766,12 +1768,14 @@ void TextEdit::_notification(int p_what) { draw_caret = true; } - OS::get_singleton()->set_ime_active(true); - Point2 cursor_pos = Point2(cursor_get_column(), cursor_get_line()) * get_row_height(); - OS::get_singleton()->set_ime_position(get_global_position() + cursor_pos); + if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id()); + Point2 cursor_pos = Point2(cursor_get_column(), cursor_get_line()) * get_row_height(); + DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + cursor_pos, get_viewport()->get_window_id()); + } - if (OS::get_singleton()->has_virtual_keyboard()) - OS::get_singleton()->show_virtual_keyboard(get_text(), get_global_rect()); + if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) + DisplayServer::get_singleton()->virtual_keyboard_show(get_text(), get_global_rect()); } break; case NOTIFICATION_FOCUS_EXIT: { @@ -1779,19 +1783,21 @@ void TextEdit::_notification(int p_what) { caret_blink_timer->stop(); } - OS::get_singleton()->set_ime_position(Point2()); - OS::get_singleton()->set_ime_active(false); + if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_ime_position(Point2(), get_viewport()->get_window_id()); + DisplayServer::get_singleton()->window_set_ime_active(false, get_viewport()->get_window_id()); + } ime_text = ""; ime_selection = Point2(); - if (OS::get_singleton()->has_virtual_keyboard()) - OS::get_singleton()->hide_virtual_keyboard(); + if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) + DisplayServer::get_singleton()->virtual_keyboard_hide(); } break; case MainLoop::NOTIFICATION_OS_IME_UPDATE: { if (has_focus()) { - ime_text = OS::get_singleton()->get_ime_text(); - ime_selection = OS::get_singleton()->get_ime_selection(); + ime_text = DisplayServer::get_singleton()->ime_get_text(); + ime_selection = DisplayServer::get_singleton()->ime_get_selection(); update(); } } break; @@ -2180,7 +2186,7 @@ Vector2i TextEdit::_get_cursor_pixel_pos() { int x = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width + cache.info_gutter_width - cursor.x_ofs; int ix = 0; while (ix < rows2[0].size() && ix < cursor.column) { - if (cache.font != NULL) { + if (cache.font != nullptr) { x += cache.font->get_char_size(rows2[0].get(ix)).width; } ix++; @@ -2477,9 +2483,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } } - menu->set_position(get_global_transform().xform(get_local_mouse_position())); + menu->set_position(get_screen_transform().xform(get_local_mouse_position())); menu->set_size(Vector2(1, 1)); - menu->set_scale(get_global_transform().get_scale()); + // menu->set_scale(get_global_transform().get_scale()); menu->popup(); grab_focus(); } @@ -2634,7 +2640,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (k->get_keycode() == KEY_PAGEUP) { - completion_index -= get_constant("completion_lines"); + completion_index -= get_theme_constant("completion_lines"); if (completion_index < 0) completion_index = 0; completion_current = completion_options[completion_index]; @@ -2645,7 +2651,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (k->get_keycode() == KEY_PAGEDOWN) { - completion_index += get_constant("completion_lines"); + completion_index += get_theme_constant("completion_lines"); if (completion_index >= completion_options.size()) completion_index = completion_options.size() - 1; completion_current = completion_options[completion_index]; @@ -3735,7 +3741,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (context_menu_enabled) { menu->set_position(get_global_transform().xform(_get_cursor_pixel_pos())); menu->set_size(Vector2(1, 1)); - menu->set_scale(get_global_transform().get_scale()); + // menu->set_scale(get_global_transform().get_scale()); menu->popup(); menu->grab_focus(); } @@ -3984,7 +3990,7 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i text.set_breakpoint(p_line, false); text.set_hidden(p_line, false); - text.set_info_icon(p_line, NULL, ""); + text.set_info_icon(p_line, nullptr, ""); } text.set_line_wrap_amount(p_line, -1); @@ -5026,51 +5032,51 @@ void TextEdit::_toggle_draw_caret() { void TextEdit::_update_caches() { - cache.style_normal = get_stylebox("normal"); - cache.style_focus = get_stylebox("focus"); - cache.style_readonly = get_stylebox("read_only"); - cache.completion_background_color = get_color("completion_background_color"); - cache.completion_selected_color = get_color("completion_selected_color"); - cache.completion_existing_color = get_color("completion_existing_color"); - cache.completion_font_color = get_color("completion_font_color"); - cache.font = get_font("font"); - cache.caret_color = get_color("caret_color"); - cache.caret_background_color = get_color("caret_background_color"); - cache.line_number_color = get_color("line_number_color"); - cache.safe_line_number_color = get_color("safe_line_number_color"); - cache.font_color = get_color("font_color"); - cache.font_color_selected = get_color("font_color_selected"); - cache.font_color_readonly = get_color("font_color_readonly"); - cache.keyword_color = get_color("keyword_color"); - cache.function_color = get_color("function_color"); - cache.member_variable_color = get_color("member_variable_color"); - cache.number_color = get_color("number_color"); - cache.selection_color = get_color("selection_color"); - cache.mark_color = get_color("mark_color"); - cache.current_line_color = get_color("current_line_color"); - cache.line_length_guideline_color = get_color("line_length_guideline_color"); - cache.bookmark_color = get_color("bookmark_color"); - cache.breakpoint_color = get_color("breakpoint_color"); - cache.executing_line_color = get_color("executing_line_color"); - cache.code_folding_color = get_color("code_folding_color"); - cache.brace_mismatch_color = get_color("brace_mismatch_color"); - cache.word_highlighted_color = get_color("word_highlighted_color"); - cache.search_result_color = get_color("search_result_color"); - cache.search_result_border_color = get_color("search_result_border_color"); - cache.symbol_color = get_color("symbol_color"); - cache.background_color = get_color("background_color"); + cache.style_normal = get_theme_stylebox("normal"); + cache.style_focus = get_theme_stylebox("focus"); + cache.style_readonly = get_theme_stylebox("read_only"); + cache.completion_background_color = get_theme_color("completion_background_color"); + cache.completion_selected_color = get_theme_color("completion_selected_color"); + cache.completion_existing_color = get_theme_color("completion_existing_color"); + cache.completion_font_color = get_theme_color("completion_font_color"); + cache.font = get_theme_font("font"); + cache.caret_color = get_theme_color("caret_color"); + cache.caret_background_color = get_theme_color("caret_background_color"); + cache.line_number_color = get_theme_color("line_number_color"); + cache.safe_line_number_color = get_theme_color("safe_line_number_color"); + cache.font_color = get_theme_color("font_color"); + cache.font_color_selected = get_theme_color("font_color_selected"); + cache.font_color_readonly = get_theme_color("font_color_readonly"); + cache.keyword_color = get_theme_color("keyword_color"); + cache.function_color = get_theme_color("function_color"); + cache.member_variable_color = get_theme_color("member_variable_color"); + cache.number_color = get_theme_color("number_color"); + cache.selection_color = get_theme_color("selection_color"); + cache.mark_color = get_theme_color("mark_color"); + cache.current_line_color = get_theme_color("current_line_color"); + cache.line_length_guideline_color = get_theme_color("line_length_guideline_color"); + cache.bookmark_color = get_theme_color("bookmark_color"); + cache.breakpoint_color = get_theme_color("breakpoint_color"); + cache.executing_line_color = get_theme_color("executing_line_color"); + cache.code_folding_color = get_theme_color("code_folding_color"); + cache.brace_mismatch_color = get_theme_color("brace_mismatch_color"); + cache.word_highlighted_color = get_theme_color("word_highlighted_color"); + cache.search_result_color = get_theme_color("search_result_color"); + cache.search_result_border_color = get_theme_color("search_result_border_color"); + cache.symbol_color = get_theme_color("symbol_color"); + cache.background_color = get_theme_color("background_color"); #ifdef TOOLS_ENABLED - cache.line_spacing = get_constant("line_spacing") * EDSCALE; + cache.line_spacing = get_theme_constant("line_spacing") * EDSCALE; #else - cache.line_spacing = get_constant("line_spacing"); + cache.line_spacing = get_theme_constant("line_spacing"); #endif cache.row_height = cache.font->get_height() + cache.line_spacing; - cache.tab_icon = get_icon("tab"); - cache.space_icon = get_icon("space"); - cache.folded_icon = get_icon("folded"); - cache.can_fold_icon = get_icon("fold"); - cache.folded_eol_icon = get_icon("GuiEllipsis", "EditorIcons"); - cache.executing_icon = get_icon("MainPlay", "EditorIcons"); + cache.tab_icon = get_theme_icon("tab"); + cache.space_icon = get_theme_icon("space"); + cache.folded_icon = get_theme_icon("folded"); + cache.can_fold_icon = get_theme_icon("fold"); + cache.folded_eol_icon = get_theme_icon("GuiEllipsis", "EditorIcons"); + cache.executing_icon = get_theme_icon("MainPlay", "EditorIcons"); text.set_font(cache.font); if (syntax_highlighter) { @@ -5226,7 +5232,7 @@ void TextEdit::cut() { if (!selection.active) { String clipboard = text[cursor.line]; - OS::get_singleton()->set_clipboard(clipboard); + DisplayServer::get_singleton()->clipboard_set(clipboard); cursor_set_line(cursor.line); cursor_set_column(0); @@ -5244,7 +5250,7 @@ void TextEdit::cut() { } else { String clipboard = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column); - OS::get_singleton()->set_clipboard(clipboard); + DisplayServer::get_singleton()->clipboard_set(clipboard); _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column); cursor_set_line(selection.from_line); // Set afterwards else it causes the view to be offset. @@ -5264,19 +5270,19 @@ void TextEdit::copy() { if (text[cursor.line].length() != 0) { String clipboard = _base_get_text(cursor.line, 0, cursor.line, text[cursor.line].length()); - OS::get_singleton()->set_clipboard(clipboard); + DisplayServer::get_singleton()->clipboard_set(clipboard); cut_copy_line = clipboard; } } else { String clipboard = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column); - OS::get_singleton()->set_clipboard(clipboard); + DisplayServer::get_singleton()->clipboard_set(clipboard); cut_copy_line = ""; } } void TextEdit::paste() { - String clipboard = OS::get_singleton()->get_clipboard(); + String clipboard = DisplayServer::get_singleton()->clipboard_get(); begin_complex_operation(); if (selection.active) { @@ -6081,7 +6087,7 @@ void TextEdit::_do_text_op(const TextOperation &p_op, bool p_reverse) { void TextEdit::_clear_redo() { - if (undo_stack_pos == NULL) + if (undo_stack_pos == nullptr) return; // Nothing to clear. _push_current_op(); @@ -6097,7 +6103,7 @@ void TextEdit::undo() { _push_current_op(); - if (undo_stack_pos == NULL) { + if (undo_stack_pos == nullptr) { if (!undo_stack.size()) return; // Nothing to undo. @@ -6146,7 +6152,7 @@ void TextEdit::redo() { _push_current_op(); - if (undo_stack_pos == NULL) + if (undo_stack_pos == nullptr) return; // Nothing to do. deselect(); @@ -6178,7 +6184,7 @@ void TextEdit::clear_undo_history() { saved_version = 0; current_op.type = TextOperation::TYPE_NONE; - undo_stack_pos = NULL; + undo_stack_pos = nullptr; undo_stack.clear(); } @@ -6627,8 +6633,8 @@ void TextEdit::_update_completion_candidates() { const CharType *tgt = &option.display[0]; const CharType *tgt_lower = &display_lower[0]; - const CharType *ssq_last_tgt = NULL; - const CharType *ssq_lower_last_tgt = NULL; + const CharType *ssq_last_tgt = nullptr; + const CharType *ssq_lower_last_tgt = nullptr; for (; *tgt; tgt++, tgt_lower++) { if (*ssq == *tgt) { @@ -6695,7 +6701,7 @@ void TextEdit::query_code_comple() { bool ignored = completion_active && !completion_options.empty(); if (ignored) { ScriptCodeCompletionOption::Kind kind = ScriptCodeCompletionOption::KIND_PLAIN_TEXT; - const ScriptCodeCompletionOption *previous_option = NULL; + const ScriptCodeCompletionOption *previous_option = nullptr; for (int i = 0; i < completion_options.size(); i++) { const ScriptCodeCompletionOption ¤t_option = completion_options[i]; if (!previous_option) { @@ -7253,7 +7259,7 @@ TextEdit::TextEdit() { wrap_at = 0; wrap_right_offset = 10; set_focus_mode(FOCUS_ALL); - syntax_highlighter = NULL; + syntax_highlighter = nullptr; _update_caches(); cache.row_height = 1; cache.line_spacing = 1; @@ -7317,7 +7323,7 @@ TextEdit::TextEdit() { current_op.type = TextOperation::TYPE_NONE; undo_enabled = true; - undo_stack_pos = NULL; + undo_stack_pos = nullptr; setting_text = false; last_dblclk = 0; current_op.version = 0; @@ -7327,7 +7333,7 @@ TextEdit::TextEdit() { completion_enabled = false; completion_active = false; completion_line_ofs = 0; - tooltip_obj = NULL; + tooltip_obj = nullptr; line_numbers = false; line_numbers_zero_padded = false; line_length_guidelines = false; @@ -7388,7 +7394,7 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int return syntax_highlighting_cache[p_line]; } - if (syntax_highlighter != NULL) { + if (syntax_highlighter != nullptr) { Map<int, HighlighterInfo> color_map = syntax_highlighter->_get_line_syntax_highlighting(p_line); syntax_highlighting_cache[p_line] = color_map; return color_map; @@ -7502,7 +7508,7 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int if (col) { for (int k = j - 1; k >= 0; k--) { if (str[k] == '.') { - col = NULL; // Member indexing not allowed. + col = nullptr; // Member indexing not allowed. break; } else if (str[k] > 32) { break; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 7d096f7897..ef8c39d32f 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -530,7 +530,7 @@ private: protected: virtual String get_tooltip(const Point2 &p_pos) const; - void _insert_text(int p_line, int p_char, const String &p_text, int *r_end_line = NULL, int *r_end_char = NULL); + void _insert_text(int p_line, int p_char, const String &p_text, int *r_end_line = nullptr, int *r_end_char = nullptr); void _remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column); void _insert_text_at_cursor(const String &p_text); void _gui_input(const Ref<InputEvent> &p_gui_input); diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp index abf6b2ed49..0dd43e4a35 100644 --- a/scene/gui/texture_progress.cpp +++ b/scene/gui/texture_progress.cpp @@ -300,7 +300,7 @@ void TextureProgress::draw_nine_patch_stretched(const Ref<Texture2D> &p_texture, p_texture->get_rect_region(dst_rect, src_rect, dst_rect, src_rect); RID ci = get_canvas_item(); - VS::get_singleton()->canvas_item_add_nine_patch(ci, dst_rect, src_rect, p_texture->get_rid(), topleft, bottomright, VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, true, p_modulate); + RS::get_singleton()->canvas_item_add_nine_patch(ci, dst_rect, src_rect, p_texture->get_rid(), topleft, bottomright, RS::NINE_PATCH_STRETCH, RS::NINE_PATCH_STRETCH, true, p_modulate); } void TextureProgress::_notification(int p_what) { diff --git a/scene/gui/texture_rect.cpp b/scene/gui/texture_rect.cpp index 6dafd3bf4f..92f3c5b5d9 100644 --- a/scene/gui/texture_rect.cpp +++ b/scene/gui/texture_rect.cpp @@ -30,7 +30,7 @@ #include "texture_rect.h" #include "core/core_string_names.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" void TextureRect::_notification(int p_what) { @@ -95,6 +95,15 @@ void TextureRect::_notification(int p_what) { } break; } + Ref<AtlasTexture> p_atlas = texture; + + if (p_atlas.is_valid() && region.has_no_area()) { + Size2 scale_size(size.width / texture->get_width(), size.height / texture->get_height()); + + offset.width += hflip ? p_atlas->get_margin().get_position().width * scale_size.width * 2 : 0; + offset.height += vflip ? p_atlas->get_margin().get_position().height * scale_size.height * 2 : 0; + } + size.width *= hflip ? -1.0f : 1.0f; size.height *= vflip ? -1.0f : 1.0f; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 12b3d56938..509a52d36a 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -30,13 +30,15 @@ #include "tree.h" +#include "core/input/input_filter.h" #include "core/math/math_funcs.h" -#include "core/os/input.h" #include "core/os/keyboard.h" #include "core/os/os.h" #include "core/print_string.h" #include "core/project_settings.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" + +#include "box_container.h" #ifdef TOOLS_ENABLED #include "editor/editor_scale.h" @@ -69,7 +71,7 @@ void TreeItem::move_to_bottom() { parent->children = next; } last->next = this; - next = NULL; + next = nullptr; } Size2 TreeItem::Cell::get_icon_size() const { @@ -369,7 +371,7 @@ TreeItem *TreeItem::get_next() { TreeItem *TreeItem::get_prev() { if (!parent || parent->children == this) - return NULL; + return nullptr; TreeItem *prev = parent->children; while (prev && prev->next != this) @@ -398,7 +400,7 @@ TreeItem *TreeItem::get_prev_visible(bool p_wrap) { current = current->parent; if (current == tree->root && tree->hide_root) { - return NULL; + return nullptr; } else if (!current) { if (p_wrap) { current = this; @@ -408,7 +410,7 @@ TreeItem *TreeItem::get_prev_visible(bool p_wrap) { temp = temp->get_next_visible(); } } else { - return NULL; + return nullptr; } } } else { @@ -448,7 +450,7 @@ TreeItem *TreeItem::get_next_visible(bool p_wrap) { if (p_wrap) return tree->root; else - return NULL; + return nullptr; } else { current = current->next; } @@ -470,7 +472,7 @@ void TreeItem::remove_child(TreeItem *p_item) { *c = (*c)->next; - aux->parent = NULL; + aux->parent = nullptr; return; } @@ -888,11 +890,11 @@ void TreeItem::clear_children() { TreeItem *aux = c; c = c->get_next(); - aux->parent = 0; // so it won't try to recursively autoremove from me in here + aux->parent = nullptr; // so it won't try to recursively autoremove from me in here memdelete(aux); } - children = 0; + children = nullptr; }; TreeItem::TreeItem(Tree *p_tree) { @@ -902,9 +904,9 @@ TreeItem::TreeItem(Tree *p_tree) { disable_folding = false; custom_min_height = 0; - parent = 0; // parent item - next = 0; // next in list - children = 0; //child items + parent = nullptr; // parent item + next = nullptr; // next in list + children = nullptr; //child items } TreeItem::~TreeItem() { @@ -916,29 +918,29 @@ TreeItem::~TreeItem() { if (tree && tree->root == this) { - tree->root = 0; + tree->root = nullptr; } if (tree && tree->popup_edited_item == this) { - tree->popup_edited_item = NULL; + tree->popup_edited_item = nullptr; tree->pressing_for_editor = false; } if (tree && tree->cache.hover_item == this) { - tree->cache.hover_item = NULL; + tree->cache.hover_item = nullptr; } if (tree && tree->selected_item == this) - tree->selected_item = NULL; + tree->selected_item = nullptr; if (tree && tree->drop_mode_over == this) - tree->drop_mode_over = NULL; + tree->drop_mode_over = nullptr; if (tree && tree->single_select_defer == this) - tree->single_select_defer = NULL; + tree->single_select_defer = nullptr; if (tree && tree->edited_item == this) { - tree->edited_item = NULL; + tree->edited_item = nullptr; tree->pressing_for_editor = false; } } @@ -952,45 +954,45 @@ TreeItem::~TreeItem() { void Tree::update_cache() { - cache.font = get_font("font"); - cache.tb_font = get_font("title_button_font"); - cache.bg = get_stylebox("bg"); - cache.selected = get_stylebox("selected"); - cache.selected_focus = get_stylebox("selected_focus"); - cache.cursor = get_stylebox("cursor"); - cache.cursor_unfocus = get_stylebox("cursor_unfocused"); - cache.button_pressed = get_stylebox("button_pressed"); - - cache.checked = get_icon("checked"); - cache.unchecked = get_icon("unchecked"); - cache.arrow_collapsed = get_icon("arrow_collapsed"); - cache.arrow = get_icon("arrow"); - cache.select_arrow = get_icon("select_arrow"); - cache.updown = get_icon("updown"); - - cache.custom_button = get_stylebox("custom_button"); - cache.custom_button_hover = get_stylebox("custom_button_hover"); - cache.custom_button_pressed = get_stylebox("custom_button_pressed"); - cache.custom_button_font_highlight = get_color("custom_button_font_highlight"); - - cache.font_color = get_color("font_color"); - cache.font_color_selected = get_color("font_color_selected"); - cache.guide_color = get_color("guide_color"); - cache.drop_position_color = get_color("drop_position_color"); - cache.hseparation = get_constant("hseparation"); - cache.vseparation = get_constant("vseparation"); - cache.item_margin = get_constant("item_margin"); - cache.button_margin = get_constant("button_margin"); - cache.draw_guides = get_constant("draw_guides"); - cache.draw_relationship_lines = get_constant("draw_relationship_lines"); - cache.relationship_line_color = get_color("relationship_line_color"); - cache.scroll_border = get_constant("scroll_border"); - cache.scroll_speed = get_constant("scroll_speed"); - - cache.title_button = get_stylebox("title_button_normal"); - cache.title_button_pressed = get_stylebox("title_button_pressed"); - cache.title_button_hover = get_stylebox("title_button_hover"); - cache.title_button_color = get_color("title_button_color"); + cache.font = get_theme_font("font"); + cache.tb_font = get_theme_font("title_button_font"); + cache.bg = get_theme_stylebox("bg"); + cache.selected = get_theme_stylebox("selected"); + cache.selected_focus = get_theme_stylebox("selected_focus"); + cache.cursor = get_theme_stylebox("cursor"); + cache.cursor_unfocus = get_theme_stylebox("cursor_unfocused"); + cache.button_pressed = get_theme_stylebox("button_pressed"); + + cache.checked = get_theme_icon("checked"); + cache.unchecked = get_theme_icon("unchecked"); + cache.arrow_collapsed = get_theme_icon("arrow_collapsed"); + cache.arrow = get_theme_icon("arrow"); + cache.select_arrow = get_theme_icon("select_arrow"); + cache.updown = get_theme_icon("updown"); + + cache.custom_button = get_theme_stylebox("custom_button"); + cache.custom_button_hover = get_theme_stylebox("custom_button_hover"); + cache.custom_button_pressed = get_theme_stylebox("custom_button_pressed"); + cache.custom_button_font_highlight = get_theme_color("custom_button_font_highlight"); + + cache.font_color = get_theme_color("font_color"); + cache.font_color_selected = get_theme_color("font_color_selected"); + cache.guide_color = get_theme_color("guide_color"); + cache.drop_position_color = get_theme_color("drop_position_color"); + cache.hseparation = get_theme_constant("hseparation"); + cache.vseparation = get_theme_constant("vseparation"); + cache.item_margin = get_theme_constant("item_margin"); + cache.button_margin = get_theme_constant("button_margin"); + cache.draw_guides = get_theme_constant("draw_guides"); + cache.draw_relationship_lines = get_theme_constant("draw_relationship_lines"); + cache.relationship_line_color = get_theme_color("relationship_line_color"); + cache.scroll_border = get_theme_constant("scroll_border"); + cache.scroll_speed = get_theme_constant("scroll_speed"); + + cache.title_button = get_theme_stylebox("title_button_normal"); + cache.title_button_pressed = get_theme_stylebox("title_button_pressed"); + cache.title_button_hover = get_theme_stylebox("title_button_hover"); + cache.title_button_color = get_theme_color("title_button_color"); v_scroll->set_custom_step(cache.font->get_height()); } @@ -1218,7 +1220,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } if (cache.draw_guides) { - VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(cell_rect.position.x, cell_rect.position.y + cell_rect.size.height), cell_rect.position + cell_rect.size, cache.guide_color, 1); + RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2i(cell_rect.position.x, cell_rect.position.y + cell_rect.size.height), cell_rect.position + cell_rect.size, cache.guide_color, 1); } if (i == 0) { @@ -1264,12 +1266,12 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 r.size.x += cache.hseparation; } if (p_item->cells[i].custom_bg_outline) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), p_item->cells[i].bg_color); - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y - 1, r.size.x, 1), p_item->cells[i].bg_color); - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), p_item->cells[i].bg_color); - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), p_item->cells[i].bg_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), p_item->cells[i].bg_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y - 1, r.size.x, 1), p_item->cells[i].bg_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), p_item->cells[i].bg_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), p_item->cells[i].bg_color); } else { - VisualServer::get_singleton()->canvas_item_add_rect(ci, r, p_item->cells[i].bg_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, r, p_item->cells[i].bg_color); } } @@ -1278,20 +1280,20 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 Rect2 r = cell_rect; if (drop_mode_section == -1 || drop_mode_section == 0) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), cache.drop_position_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), cache.drop_position_color); } if (drop_mode_section == 0) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), cache.drop_position_color); - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), cache.drop_position_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), cache.drop_position_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), cache.drop_position_color); } if (drop_mode_section == 1 || drop_mode_section == 0) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y, r.size.x, 1), cache.drop_position_color); + RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y, r.size.x, 1), cache.drop_position_color); } } - Color col = p_item->cells[i].custom_color ? p_item->cells[i].color : get_color(p_item->cells[i].selected ? "font_color_selected" : "font_color"); + Color col = p_item->cells[i].custom_color ? p_item->cells[i].color : get_theme_color(p_item->cells[i].selected ? "font_color_selected" : "font_color"); Color icon_col = p_item->cells[i].icon_color; Point2i text_pos = item_rect.position; @@ -1423,7 +1425,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 if (p_item->cells[i].custom_button) { if (cache.hover_item == p_item && cache.hover_cell == i) { - if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { + if (InputFilter::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { draw_style_box(cache.custom_button_pressed, ir); } else { draw_style_box(cache.custom_button_hover, ir); @@ -1496,7 +1498,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 int parent_ofs = p_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin); Point2i root_pos = Point2i(root_ofs, children_pos.y + label_h / 2) - cache.offset + p_draw_ofs; - if (c->get_children() != NULL) + if (c->get_children() != nullptr) root_pos -= Point2i(cache.arrow->get_width(), 0); float line_width = 1.0; @@ -1507,8 +1509,8 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 Point2i parent_pos = Point2i(parent_ofs - cache.arrow->get_width() / 2, p_pos.y + label_h / 2 + cache.arrow->get_height() / 2) - cache.offset + p_draw_ofs; if (root_pos.y + line_width >= 0) { - VisualServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x - Math::floor(line_width / 2), root_pos.y), cache.relationship_line_color, line_width); - VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y), Point2i(parent_pos.x, prev_ofs), cache.relationship_line_color, line_width); + RenderingServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x - Math::floor(line_width / 2), root_pos.y), cache.relationship_line_color, line_width); + RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y), Point2i(parent_pos.x, prev_ofs), cache.relationship_line_color, line_width); } if (htotal < 0) { @@ -1659,7 +1661,7 @@ Rect2 Tree::search_item_rect(TreeItem *p_from, TreeItem *p_item) { void Tree::_range_click_timeout() { - if (range_item_last && !range_drag_enabled && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { + if (range_item_last && !range_drag_enabled && InputFilter::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { Point2 pos = get_local_mouse_position() - cache.bg->get_offset(); if (show_column_titles) { @@ -2046,9 +2048,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool void Tree::_text_editor_modal_close() { - if (Input::get_singleton()->is_key_pressed(KEY_ESCAPE) || - Input::get_singleton()->is_key_pressed(KEY_KP_ENTER) || - Input::get_singleton()->is_key_pressed(KEY_ENTER)) { + if (InputFilter::get_singleton()->is_key_pressed(KEY_ESCAPE) || + InputFilter::get_singleton()->is_key_pressed(KEY_KP_ENTER) || + InputFilter::get_singleton()->is_key_pressed(KEY_ENTER)) { return; } @@ -2056,13 +2058,12 @@ void Tree::_text_editor_modal_close() { if (value_editor->has_point(value_editor->get_local_mouse_position())) return; - text_editor_enter(text_editor->get_text()); + _text_editor_enter(text_editor->get_text()); } -void Tree::text_editor_enter(String p_text) { +void Tree::_text_editor_enter(String p_text) { - text_editor->hide(); - value_editor->hide(); + popup_editor->hide(); if (!popup_edited_item) return; @@ -2130,7 +2131,7 @@ void Tree::popup_select(int p_option) { void Tree::_go_left() { if (selected_col == 0) { - if (selected_item->get_children() != NULL && !selected_item->is_collapsed()) { + if (selected_item->get_children() != nullptr && !selected_item->is_collapsed()) { selected_item->set_collapsed(true); } else { if (columns.size() == 1) { // goto parent with one column @@ -2159,7 +2160,7 @@ void Tree::_go_left() { void Tree::_go_right() { if (selected_col == (columns.size() - 1)) { - if (selected_item->get_children() != NULL && selected_item->is_collapsed()) { + if (selected_item->get_children() != nullptr && selected_item->is_collapsed()) { selected_item->set_collapsed(false); } else if (selected_item->get_next_visible()) { selected_col = 0; @@ -2180,7 +2181,7 @@ void Tree::_go_right() { } void Tree::_go_up() { - TreeItem *prev = NULL; + TreeItem *prev = nullptr; if (!selected_item) { prev = get_last_item(); selected_col = 0; @@ -2220,7 +2221,7 @@ void Tree::_go_up() { } void Tree::_go_down() { - TreeItem *next = NULL; + TreeItem *next = nullptr; if (!selected_item) { if (root) { @@ -2323,7 +2324,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (!cursor_can_exit_tree) accept_event(); - TreeItem *next = NULL; + TreeItem *next = nullptr; if (!selected_item) return; next = selected_item; @@ -2361,7 +2362,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (!cursor_can_exit_tree) accept_event(); - TreeItem *prev = NULL; + TreeItem *prev = nullptr; if (!selected_item) return; prev = selected_item; @@ -2531,7 +2532,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { range_drag_enabled = true; range_drag_capture_pos = cpos; range_drag_base = popup_edited_item->get_range(popup_edited_item_col); - Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED); + InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_CAPTURED); } } else { @@ -2583,7 +2584,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (single_select_defer) { select_single_item(single_select_defer, root, single_select_defer_column); - single_select_defer = NULL; + single_select_defer = nullptr; } range_click_timer->stop(); @@ -2593,7 +2594,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (range_drag_enabled) { range_drag_enabled = false; - Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE); warp_mouse(range_drag_capture_pos); } else { Rect2 rect = get_selected()->get_meta("__focus_rect"); @@ -2608,7 +2609,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { pressing_for_editor = false; } - if (cache.click_type == Cache::CLICK_BUTTON && cache.click_item != NULL) { + if (cache.click_type == Cache::CLICK_BUTTON && cache.click_item != nullptr) { // make sure in case of wrong reference after reconstructing whole TreeItems cache.click_item = get_item_at_position(cache.click_pos); emit_signal("button_pressed", cache.click_item, cache.click_column, cache.click_id); @@ -2616,7 +2617,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { cache.click_type = Cache::CLICK_NONE; cache.click_index = -1; cache.click_id = -1; - cache.click_item = NULL; + cache.click_item = nullptr; cache.click_column = 0; if (drag_touching) { @@ -2703,14 +2704,14 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { drag_accum = 0; //last_drag_accum=0; drag_from = v_scroll->get_value(); - drag_touching = OS::get_singleton()->has_touchscreen_ui_hint(); + drag_touching = !DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())); drag_touching_deaccel = false; if (drag_touching) { set_physics_process_internal(true); } if (b->get_button_index() == BUTTON_LEFT) { - if (get_item_at_position(b->get_position()) == NULL && !b->get_shift() && !b->get_control() && !b->get_command()) + if (get_item_at_position(b->get_position()) == nullptr && !b->get_shift() && !b->get_control() && !b->get_command()) emit_signal("nothing_selected"); } } @@ -2806,20 +2807,23 @@ bool Tree::edit_selected() { } else if (c.mode == TreeItem::CELL_MODE_STRING || c.mode == TreeItem::CELL_MODE_RANGE) { + Rect2 popup_rect; + Vector2 ofs(0, (text_editor->get_size().height - rect.size.height) / 2); - Point2i textedpos = get_global_position() + rect.position - ofs; + + Point2i textedpos = get_screen_position() + rect.position - ofs; cache.text_editor_position = textedpos; - text_editor->set_position(textedpos); - text_editor->set_size(rect.size); + popup_rect.position = textedpos; + popup_rect.size = rect.size; text_editor->clear(); text_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::range_step_decimals(c.step))); text_editor->select_all(); if (c.mode == TreeItem::CELL_MODE_RANGE) { - value_editor->set_position(textedpos + Point2i(0, text_editor->get_size().height)); - value_editor->set_size(Size2(rect.size.width, 1)); - value_editor->show_modal(); + popup_rect.size.y += value_editor->get_minimum_size().height; + + value_editor->show(); updating_value_editor = true; value_editor->set_min(c.min); value_editor->set_max(c.max); @@ -2827,10 +2831,17 @@ bool Tree::edit_selected() { value_editor->set_value(c.val); value_editor->set_exp_ratio(c.expr); updating_value_editor = false; + } else { + value_editor->hide(); } - text_editor->show_modal(); + popup_editor->set_position(popup_rect.position); + popup_editor->set_size(popup_rect.size); + popup_editor->popup(); + popup_editor->child_controls_changed(); + text_editor->grab_focus(); + return true; } @@ -2935,7 +2946,7 @@ void Tree::_notification(int p_what) { } if (p_what == NOTIFICATION_DRAG_BEGIN) { - single_select_defer = NULL; + single_select_defer = nullptr; if (cache.scroll_speed > 0) { scrolling = true; set_physics_process_internal(true); @@ -3011,7 +3022,7 @@ void Tree::_notification(int p_what) { RID ci = get_canvas_item(); Ref<StyleBox> bg = cache.bg; - Ref<StyleBox> bg_focus = get_stylebox("bg_focus"); + Ref<StyleBox> bg_focus = get_theme_stylebox("bg_focus"); Point2 draw_ofs; draw_ofs += bg->get_offset(); @@ -3019,9 +3030,9 @@ void Tree::_notification(int p_what) { bg->draw(ci, Rect2(Point2(), get_size())); if (has_focus()) { - VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci, true); + RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, true); bg_focus->draw(ci, Rect2(Point2(), get_size())); - VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci, false); + RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, false); } int tbh = _get_title_button_height(); @@ -3034,13 +3045,6 @@ void Tree::_notification(int p_what) { draw_item(Point2(), draw_ofs, draw_size, root); } - int ofs = 0; - - for (int i = 0; i < (columns.size() - 1 - 1); i++) { - - ofs += get_column_width(i); - } - if (show_column_titles) { //title buttons @@ -3065,7 +3069,7 @@ void Tree::_notification(int p_what) { if (p_what == NOTIFICATION_RESIZED || p_what == NOTIFICATION_TRANSFORM_CHANGED) { - if (popup_edited_item != NULL) { + if (popup_edited_item != nullptr) { Rect2 rect = popup_edited_item->get_meta("__focus_rect"); Vector2 ofs(0, (text_editor->get_size().height - rect.size.height) / 2); Point2i textedpos = get_global_position() + rect.position - ofs; @@ -3086,18 +3090,18 @@ Size2 Tree::get_minimum_size() const { TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) { - ERR_FAIL_COND_V(blocked > 0, NULL); + ERR_FAIL_COND_V(blocked > 0, nullptr); - TreeItem *ti = NULL; + TreeItem *ti = nullptr; if (p_parent) { // Append or insert a new item to the given parent. ti = memnew(TreeItem(this)); - ERR_FAIL_COND_V(!ti, NULL); + ERR_FAIL_COND_V(!ti, nullptr); ti->cells.resize(columns.size()); - TreeItem *prev = NULL; + TreeItem *prev = nullptr; TreeItem *c = p_parent->children; int idx = 0; @@ -3121,7 +3125,7 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) { if (!root) { // No root exists, make the given item the new root. ti = memnew(TreeItem(this)); - ERR_FAIL_COND_V(!ti, NULL); + ERR_FAIL_COND_V(!ti, nullptr); ti->cells.resize(columns.size()); root = ti; @@ -3216,7 +3220,7 @@ void Tree::deselect_all() { ERR_FAIL_COND(item == prev_item); } - selected_item = NULL; + selected_item = nullptr; selected_col = -1; update(); @@ -3224,7 +3228,7 @@ void Tree::deselect_all() { bool Tree::is_anything_selected() { - return (selected_item != NULL); + return (selected_item != nullptr); } void Tree::clear() { @@ -3234,7 +3238,7 @@ void Tree::clear() { if (pressing_for_editor) { if (range_drag_enabled) { range_drag_enabled = false; - Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE); warp_mouse(range_drag_capture_pos); } pressing_for_editor = false; @@ -3242,12 +3246,12 @@ void Tree::clear() { if (root) { memdelete(root); - root = NULL; + root = nullptr; }; - selected_item = NULL; - edited_item = NULL; - popup_edited_item = NULL; + selected_item = nullptr; + edited_item = nullptr; + popup_edited_item = nullptr; update(); }; @@ -3304,10 +3308,10 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) { /* if (!p_item) - return NULL; + return nullptr; */ if (!root) - return NULL; + return nullptr; while (true) { @@ -3327,8 +3331,8 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) { while (!p_item->next) { p_item = p_item->parent; - if (p_item == NULL) - return NULL; + if (p_item == nullptr) + return nullptr; } p_item = p_item->next; @@ -3340,7 +3344,7 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) { return p_item; } - return NULL; + return nullptr; } int Tree::get_column_width(int p_column) const { @@ -3447,7 +3451,7 @@ int Tree::get_item_offset(TreeItem *p_item) const { while (!it->next) { it = it->parent; - if (it == NULL) + if (it == nullptr) return 0; } @@ -3615,7 +3619,7 @@ TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_c break; } - return NULL; + return nullptr; } TreeItem *Tree::search_item_text(const String &p_find, int *r_col, bool p_selectable) { @@ -3625,7 +3629,7 @@ TreeItem *Tree::search_item_text(const String &p_find, int *r_col, bool p_select if (!from) from = root; if (!from) - return NULL; + return nullptr; return _search_item_text(from->get_next_visible(true), p_find, r_col, p_selectable); } @@ -3638,7 +3642,7 @@ TreeItem *Tree::get_item_with_text(const String &p_find) const { } } } - return NULL; + return nullptr; } void Tree::_do_incr_search(const String &p_add) { @@ -3692,7 +3696,7 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_ pos.x -= w; } - return NULL; + return nullptr; } else { pos.y -= h; @@ -3703,7 +3707,7 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_ } if (p_item->is_collapsed()) - return NULL; // do not try children, it's collapsed + return nullptr; // do not try children, it's collapsed TreeItem *n = p_item->get_children(); while (n) { @@ -3717,7 +3721,7 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_ n = n->get_next(); } - return NULL; + return nullptr; } int Tree::get_column_at_position(const Point2 &p_pos) const { @@ -3779,7 +3783,7 @@ TreeItem *Tree::get_item_at_position(const Point2 &p_pos) const { pos -= cache.bg->get_offset(); pos.y -= _get_title_button_height(); if (pos.y < 0) - return NULL; + return nullptr; if (h_scroll->is_visible_in_tree()) pos.x += h_scroll->get_value(); @@ -3795,7 +3799,7 @@ TreeItem *Tree::get_item_at_position(const Point2 &p_pos) const { } } - return NULL; + return nullptr; } String Tree::get_tooltip(const Point2 &p_pos) const { @@ -3872,7 +3876,7 @@ void Tree::set_drop_mode_flags(int p_flags) { return; drop_mode_flags = p_flags; if (drop_mode_flags == 0) { - drop_mode_over = NULL; + drop_mode_over = nullptr; } update(); @@ -4004,30 +4008,39 @@ Tree::Tree() { selected_col = 0; columns.resize(1); - selected_item = NULL; - edited_item = NULL; + selected_item = nullptr; + edited_item = nullptr; selected_col = -1; edited_col = -1; hide_root = false; select_mode = SELECT_SINGLE; - root = 0; - popup_menu = NULL; - popup_edited_item = NULL; - text_editor = NULL; + root = nullptr; + popup_menu = nullptr; + popup_edited_item = nullptr; + text_editor = nullptr; set_focus_mode(FOCUS_ALL); popup_menu = memnew(PopupMenu); popup_menu->hide(); add_child(popup_menu); - popup_menu->set_as_toplevel(true); + // popup_menu->set_as_toplevel(true); + + popup_editor = memnew(PopupPanel); + popup_editor->set_wrap_controls(true); + add_child(popup_editor); + popup_editor_vb = memnew(VBoxContainer); + popup_editor->add_child(popup_editor_vb); + popup_editor_vb->add_theme_constant_override("separation", 0); + popup_editor_vb->set_anchors_and_margins_preset(PRESET_WIDE); text_editor = memnew(LineEdit); - add_child(text_editor); - text_editor->set_as_toplevel(true); - text_editor->hide(); + popup_editor_vb->add_child(text_editor); + text_editor->set_v_size_flags(SIZE_EXPAND_FILL); + text_editor->set_h_size_flags(SIZE_EXPAND_FILL); value_editor = memnew(HSlider); - add_child(value_editor); - value_editor->set_as_toplevel(true); + value_editor->set_v_size_flags(SIZE_EXPAND_FILL); + value_editor->set_h_size_flags(SIZE_EXPAND_FILL); + popup_editor_vb->add_child(value_editor); value_editor->hide(); h_scroll = memnew(HScrollBar); @@ -4042,13 +4055,11 @@ Tree::Tree() { h_scroll->connect("value_changed", callable_mp(this, &Tree::_scroll_moved)); v_scroll->connect("value_changed", callable_mp(this, &Tree::_scroll_moved)); - text_editor->connect("text_entered", callable_mp(this, &Tree::text_editor_enter)); - text_editor->connect("modal_closed", callable_mp(this, &Tree::_text_editor_modal_close)); + text_editor->connect("text_entered", callable_mp(this, &Tree::_text_editor_enter)); + popup_editor->connect("popup_hide", callable_mp(this, &Tree::_text_editor_modal_close)); popup_menu->connect("id_pressed", callable_mp(this, &Tree::popup_select)); value_editor->connect("value_changed", callable_mp(this, &Tree::value_editor_changed)); - value_editor->set_as_toplevel(true); - text_editor->set_as_toplevel(true); set_notify_transform(true); updating_value_editor = false; @@ -4060,7 +4071,7 @@ Tree::Tree() { cache.hover_index = -1; cache.click_index = -1; cache.click_id = -1; - cache.click_item = NULL; + cache.click_item = nullptr; cache.click_column = 0; cache.hover_cell = -1; last_keypress = 0; @@ -4080,9 +4091,9 @@ Tree::Tree() { hide_folding = false; drop_mode_flags = 0; - drop_mode_over = NULL; + drop_mode_over = nullptr; drop_mode_section = 0; - single_select_defer = NULL; + single_select_defer = nullptr; scrolling = false; allow_rmb_select = false; @@ -4090,7 +4101,7 @@ Tree::Tree() { set_clip_contents(true); - cache.hover_item = NULL; + cache.hover_item = nullptr; cache.hover_cell = -1; allow_reselect = false; diff --git a/scene/gui/tree.h b/scene/gui/tree.h index b179c5bcba..87c2588a12 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -290,6 +290,8 @@ public: VARIANT_ENUM_CAST(TreeItem::TreeCellMode); VARIANT_ENUM_CAST(TreeItem::TextAlign); +class VBoxContainer; + class Tree : public Control { GDCLASS(Tree, Control); @@ -359,6 +361,10 @@ private: }; bool show_column_titles; + + VBoxContainer *popup_editor_vb; + + PopupPanel *popup_editor; LineEdit *text_editor; HSlider *value_editor; bool updating_value_editor; @@ -377,9 +383,9 @@ private: //void draw_item_text(String p_text,const Ref<Texture2D>& p_icon,int p_icon_max_w,bool p_tool,Rect2i p_rect,const Color& p_color); void draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, const Color &p_color, const Color &p_icon_color); int draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item); - void select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev = NULL, bool *r_in_range = NULL, bool p_force_deselect = false); + void select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev = nullptr, bool *r_in_range = nullptr, bool p_force_deselect = false); int propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool p_doubleclick, TreeItem *p_item, int p_button, const Ref<InputEventWithModifiers> &p_mod); - void text_editor_enter(String p_text); + void _text_editor_enter(String p_text); void _text_editor_modal_close(); void value_editor_changed(double p_value); @@ -578,7 +584,7 @@ public: bool edit_selected(); // First item that starts with the text, from the current focused item down and wraps around. - TreeItem *search_item_text(const String &p_find, int *r_col = NULL, bool p_selectable = false); + TreeItem *search_item_text(const String &p_find, int *r_col = nullptr, bool p_selectable = false); // First item that matches the whole text, from the first item down. TreeItem *get_item_with_text(const String &p_find) const; diff --git a/scene/main/SCsub b/scene/main/SCsub index b01e2fd54d..fc61250247 100644 --- a/scene/main/SCsub +++ b/scene/main/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/canvas_item.cpp b/scene/main/canvas_item.cpp index ef7aa9ba01..2eacad68c3 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -29,22 +29,23 @@ /*************************************************************************/ #include "canvas_item.h" + +#include "core/input/input_filter.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/main/window.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" +#include "servers/rendering_server.h" Mutex CanvasItemMaterial::material_mutex; -SelfList<CanvasItemMaterial>::List *CanvasItemMaterial::dirty_materials = NULL; +SelfList<CanvasItemMaterial>::List *CanvasItemMaterial::dirty_materials = nullptr; Map<CanvasItemMaterial::MaterialKey, CanvasItemMaterial::ShaderData> CanvasItemMaterial::shader_map; -CanvasItemMaterial::ShaderNames *CanvasItemMaterial::shader_names = NULL; +CanvasItemMaterial::ShaderNames *CanvasItemMaterial::shader_names = nullptr; void CanvasItemMaterial::init_shaders() { @@ -61,7 +62,7 @@ void CanvasItemMaterial::finish_shaders() { memdelete(dirty_materials); memdelete(shader_names); - dirty_materials = NULL; + dirty_materials = nullptr; } void CanvasItemMaterial::_update_shader() { @@ -76,7 +77,7 @@ void CanvasItemMaterial::_update_shader() { 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); + RS::get_singleton()->free(shader_map[current_key].shader); shader_map.erase(current_key); } } @@ -85,7 +86,7 @@ void CanvasItemMaterial::_update_shader() { if (shader_map.has(mk)) { - VS::get_singleton()->material_set_shader(_get_material(), shader_map[mk].shader); + RS::get_singleton()->material_set_shader(_get_material(), shader_map[mk].shader); shader_map[mk].users++; return; } @@ -136,14 +137,14 @@ void CanvasItemMaterial::_update_shader() { } ShaderData shader_data; - shader_data.shader = VS::get_singleton()->shader_create(); + shader_data.shader = RS::get_singleton()->shader_create(); shader_data.users = 1; - VS::get_singleton()->shader_set_code(shader_data.shader, code); + RS::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); + RS::get_singleton()->material_set_shader(_get_material(), shader_data.shader); } void CanvasItemMaterial::flush_changes() { @@ -205,7 +206,7 @@ bool CanvasItemMaterial::get_particles_animation() const { 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); + RS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_h_frames, p_frames); } int CanvasItemMaterial::get_particles_anim_h_frames() const { @@ -215,7 +216,7 @@ int CanvasItemMaterial::get_particles_anim_h_frames() const { 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); + RS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_v_frames, p_frames); } int CanvasItemMaterial::get_particles_anim_v_frames() const { @@ -226,7 +227,7 @@ int CanvasItemMaterial::get_particles_anim_v_frames() const { 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); + RS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_loop, particles_anim_loop); } bool CanvasItemMaterial::get_particles_anim_loop() const { @@ -314,11 +315,11 @@ CanvasItemMaterial::~CanvasItemMaterial() { 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); + RS::get_singleton()->free(shader_map[current_key].shader); shader_map.erase(current_key); } - VS::get_singleton()->material_set_shader(_get_material(), RID()); + RS::get_singleton()->material_set_shader(_get_material(), RID()); } } @@ -347,6 +348,9 @@ bool CanvasItem::is_visible_in_tree() const { while (p) { if (!p->visible) return false; + if (p->window && !p->window->is_visible()) { + return false; + } p = p->get_parent_item(); } @@ -383,7 +387,7 @@ void CanvasItem::show() { return; visible = true; - VisualServer::get_singleton()->canvas_item_set_visible(canvas_item, true); + RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, true); if (!is_inside_tree()) return; @@ -398,7 +402,7 @@ void CanvasItem::hide() { return; visible = false; - VisualServer::get_singleton()->canvas_item_set_visible(canvas_item, false); + RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, false); if (!is_inside_tree()) return; @@ -407,7 +411,7 @@ void CanvasItem::hide() { _change_notify("visible"); } -CanvasItem *CanvasItem::current_item_drawn = NULL; +CanvasItem *CanvasItem::current_item_drawn = nullptr; CanvasItem *CanvasItem::get_current_item_drawn() { return current_item_drawn; } @@ -419,7 +423,7 @@ void CanvasItem::_update_callback() { return; } - VisualServer::get_singleton()->canvas_item_clear(get_canvas_item()); + RenderingServer::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) { @@ -431,9 +435,9 @@ void CanvasItem::_update_callback() { 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); + get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_draw, nullptr, 0); } - current_item_drawn = NULL; + current_item_drawn = nullptr; drawing = false; } //todo updating = false @@ -450,6 +454,21 @@ Transform2D CanvasItem::get_global_transform_with_canvas() const { return get_global_transform(); } +Transform2D CanvasItem::get_screen_transform() const { + ERR_FAIL_COND_V(!is_inside_tree(), Transform2D()); + Transform2D xform = get_global_transform_with_canvas(); + + Window *w = Object::cast_to<Window>(get_viewport()); + if (w && !w->is_embedding_subwindows()) { + Transform2D s; + s.set_origin(w->get_position()); + + xform = s * xform; + } + + return xform; +} + Transform2D CanvasItem::get_global_transform() const { #ifdef DEBUG_ENABLED ERR_FAIL_COND_V(!is_inside_tree(), get_transform()); @@ -474,9 +493,9 @@ void CanvasItem::_toplevel_raise_self() { return; if (canvas_layer) - VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, canvas_layer->get_sort_index()); + RenderingServer::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()); + RenderingServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_viewport()->gui_get_canvas_sort_index()); } void CanvasItem::_enter_canvas() { @@ -485,7 +504,7 @@ void CanvasItem::_enter_canvas() { Node *n = this; - canvas_layer = NULL; + canvas_layer = nullptr; while (n) { @@ -505,7 +524,7 @@ void CanvasItem::_enter_canvas() { else canvas = get_viewport()->find_world_2d()->get_canvas(); - VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, canvas); + RenderingServer::get_singleton()->canvas_item_set_parent(canvas_item, canvas); group = "root_canvas" + itos(canvas.get_id()); @@ -521,8 +540,8 @@ void CanvasItem::_enter_canvas() { 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()); + RenderingServer::get_singleton()->canvas_item_set_parent(canvas_item, parent->get_canvas_item()); + RenderingServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index()); } pending_update = false; @@ -534,8 +553,8 @@ void CanvasItem::_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; + RenderingServer::get_singleton()->canvas_item_set_parent(canvas_item, RID()); + canvas_layer = nullptr; group = ""; } @@ -548,10 +567,30 @@ void CanvasItem::_notification(int p_what) { _update_texture_repeat_changed(false); first_draw = true; - if (get_parent()) { - CanvasItem *ci = Object::cast_to<CanvasItem>(get_parent()); + Node *parent = get_parent(); + if (parent) { + CanvasItem *ci = Object::cast_to<CanvasItem>(parent); if (ci) C = ci->children_items.push_back(this); + if (!ci) { + //look for a window + Viewport *viewport = nullptr; + + while (parent) { + viewport = Object::cast_to<Viewport>(parent); + if (viewport) { + break; + } + parent = parent->get_parent(); + } + + ERR_FAIL_COND(!viewport); + + window = Object::cast_to<Window>(viewport); + if (window) { + window->connect(SceneStringNames::get_singleton()->visibility_changed, callable_mp(this, &CanvasItem::_window_visibility_changed)); + } + } } _enter_canvas(); if (!block_transform_notify && !xform_change.in_list()) { @@ -568,7 +607,7 @@ void CanvasItem::_notification(int p_what) { } else { CanvasItem *p = get_parent_item(); ERR_FAIL_COND(!p); - VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index()); + RenderingServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index()); } } break; @@ -578,7 +617,10 @@ void CanvasItem::_notification(int p_what) { _exit_canvas(); if (C) { Object::cast_to<CanvasItem>(get_parent())->children_items.erase(C); - C = NULL; + C = nullptr; + } + if (window) { + window->disconnect(SceneStringNames::get_singleton()->visibility_changed, callable_mp(this, &CanvasItem::_window_visibility_changed)); } global_invalid = true; } break; @@ -600,6 +642,14 @@ void CanvasItem::set_visible(bool p_visible) { else hide(); } + +void CanvasItem::_window_visibility_changed() { + + if (visible) { + _propagate_visibility_changed(window->is_visible()); + } +} + bool CanvasItem::is_visible() const { return visible; @@ -623,7 +673,7 @@ void CanvasItem::set_modulate(const Color &p_modulate) { return; modulate = p_modulate; - VisualServer::get_singleton()->canvas_item_set_modulate(canvas_item, modulate); + RenderingServer::get_singleton()->canvas_item_set_modulate(canvas_item, modulate); } Color CanvasItem::get_modulate() const { @@ -653,7 +703,7 @@ bool CanvasItem::is_set_as_toplevel() const { CanvasItem *CanvasItem::get_parent_item() const { if (toplevel) - return NULL; + return nullptr; return Object::cast_to<CanvasItem>(get_parent()); } @@ -664,7 +714,7 @@ void CanvasItem::set_self_modulate(const Color &p_self_modulate) { return; self_modulate = p_self_modulate; - VisualServer::get_singleton()->canvas_item_set_self_modulate(canvas_item, self_modulate); + RenderingServer::get_singleton()->canvas_item_set_self_modulate(canvas_item, self_modulate); } Color CanvasItem::get_self_modulate() const { @@ -677,7 +727,7 @@ void CanvasItem::set_light_mask(int p_light_mask) { return; light_mask = p_light_mask; - VS::get_singleton()->canvas_item_set_light_mask(canvas_item, p_light_mask); + RS::get_singleton()->canvas_item_set_light_mask(canvas_item, p_light_mask); } int CanvasItem::get_light_mask() const { @@ -696,7 +746,7 @@ void CanvasItem::draw_line(const Point2 &p_from, const Point2 &p_to, const Color 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); + RenderingServer::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) { @@ -705,14 +755,14 @@ void CanvasItem::draw_polyline(const Vector<Point2> &p_points, const Color &p_co Vector<Color> colors; colors.push_back(p_color); - VisualServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, colors, p_width); + RenderingServer::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); + RenderingServer::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) { @@ -734,14 +784,14 @@ void CanvasItem::draw_multiline(const Vector<Point2> &p_points, const Color &p_c Vector<Color> colors; colors.push_back(p_color); - VisualServer::get_singleton()->canvas_item_add_multiline(canvas_item, p_points, colors, p_width); + RenderingServer::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); + RenderingServer::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) { @@ -753,7 +803,7 @@ void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_fil 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); + RenderingServer::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 @@ -764,25 +814,25 @@ void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_fil offset = 0.0; } - VisualServer::get_singleton()->canvas_item_add_line( + RenderingServer::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( + RenderingServer::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( + RenderingServer::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( + RenderingServer::get_singleton()->canvas_item_add_line( canvas_item, p_rect.position + Size2(0, p_rect.size.height - offset), p_rect.position + Size2(0, offset), @@ -795,7 +845,7 @@ void CanvasItem::draw_circle(const Point2 &p_pos, float p_radius, const Color &p 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); + RenderingServer::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) { @@ -804,7 +854,7 @@ void CanvasItem::draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_p 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)); + p_texture->draw(canvas_item, p_pos, p_modulate, false, p_normal_map, p_specular_map, p_specular_color_shininess, RS::CanvasItemTextureFilter(p_texture_filter), RS::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) { @@ -812,13 +862,13 @@ void CanvasItem::draw_texture_rect(const Ref<Texture2D> &p_texture, const Rect2 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)); + p_texture->draw_rect(canvas_item, p_rect, p_tile, p_modulate, p_transpose, p_normal_map, p_specular_map, p_specular_color_shininess, RS::CanvasItemTextureFilter(p_texture_filter), RS::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); + 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, RS::CanvasItemTextureFilter(p_texture_filter), RS::CanvasItemTextureRepeat(p_texture_repeat), p_clip_uv); } void CanvasItem::draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect) { @@ -836,7 +886,7 @@ void CanvasItem::draw_primitive(const Vector<Point2> &p_points, const Vector<Col 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)); + RenderingServer::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, RS::CanvasItemTextureFilter(p_texture_filter), RS::CanvasItemTextureRepeat(p_texture_repeat)); } void CanvasItem::draw_set_transform(const Point2 &p_offset, float p_rot, const Size2 &p_scale) { @@ -844,14 +894,14 @@ void CanvasItem::draw_set_transform(const Point2 &p_offset, float p_rot, const S Transform2D xform(p_rot, p_offset); xform.scale_basis(p_scale); - VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item, xform); + RenderingServer::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); + RenderingServer::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) { @@ -862,7 +912,7 @@ void CanvasItem::draw_polygon(const Vector<Point2> &p_points, const Vector<Color 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)); + RenderingServer::get_singleton()->canvas_item_add_polygon(canvas_item, p_points, p_colors, p_uvs, rid, rid_normal, rid_specular, p_specular_color_shininess, RS::CanvasItemTextureFilter(p_texture_filter), RS::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) { @@ -875,7 +925,7 @@ void CanvasItem::draw_colored_polygon(const Vector<Point2> &p_points, const Colo 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)); + RenderingServer::get_singleton()->canvas_item_add_polygon(canvas_item, p_points, colors, p_uvs, rid, rid_normal, rid_specular, p_specular_color_shininess, RS::CanvasItemTextureFilter(p_texture_filter), RS::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) { @@ -885,7 +935,7 @@ void CanvasItem::draw_mesh(const Ref<Mesh> &p_mesh, const Ref<Texture2D> &p_text 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)); + RenderingServer::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, RS::CanvasItemTextureFilter(p_texture_filter), RS::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) { @@ -894,7 +944,7 @@ void CanvasItem::draw_multimesh(const Ref<MultiMesh> &p_multimesh, const Ref<Tex 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)); + RenderingServer::get_singleton()->canvas_item_add_multimesh(canvas_item, p_multimesh->get_rid(), texture_rid, normal_map_rid, specular_map_rid, p_specular_color_shininess, RS::CanvasItemTextureFilter(p_texture_filter), RS::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) { @@ -1016,7 +1066,7 @@ 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); + RenderingServer::get_singleton()->canvas_item_set_draw_behind_parent(canvas_item, behind); } bool CanvasItem::is_draw_behind_parent_enabled() const { @@ -1030,14 +1080,14 @@ void CanvasItem::set_material(const Ref<Material> &p_material) { RID rid; if (material.is_valid()) rid = material->get_rid(); - VS::get_singleton()->canvas_item_set_material(canvas_item, rid); + RS::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); + RS::get_singleton()->canvas_item_set_use_parent_material(canvas_item, p_use_parent_material); } bool CanvasItem::get_use_parent_material() const { @@ -1322,18 +1372,18 @@ void CanvasItem::_update_texture_filter_changed(bool p_propagate) { } 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; + case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST: texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST; break; + case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR: texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR; break; + case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS: texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS; break; + case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS: texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS; break; default: { } } } } else { - texture_filter_cache = VS::CanvasItemTextureFilter(texture_filter); + texture_filter_cache = RS::CanvasItemTextureFilter(texture_filter); } - VS::get_singleton()->canvas_item_set_default_texture_filter(get_canvas_item(), texture_filter_cache); + RS::get_singleton()->canvas_item_set_default_texture_filter(get_canvas_item(), texture_filter_cache); update(); if (p_propagate) { @@ -1371,17 +1421,17 @@ void CanvasItem::_update_texture_repeat_changed(bool p_propagate) { } 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; + case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_DISABLED: texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED; break; + case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_ENABLED: texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED; break; + case Viewport::DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_MIRROR: texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_MIRROR; break; default: { } } } } else { - texture_repeat_cache = VS::CanvasItemTextureRepeat(texture_repeat); + texture_repeat_cache = RS::CanvasItemTextureRepeat(texture_repeat); } - VS::get_singleton()->canvas_item_set_default_texture_repeat(get_canvas_item(), texture_repeat_cache); + RS::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()) { @@ -1408,7 +1458,8 @@ CanvasItem::TextureRepeat CanvasItem::get_texture_repeat() const { CanvasItem::CanvasItem() : xform_change(this) { - canvas_item = VisualServer::get_singleton()->canvas_item_create(); + window = nullptr; + canvas_item = RenderingServer::get_singleton()->canvas_item_create(); visible = true; pending_update = false; modulate = Color(1, 1, 1, 1); @@ -1418,8 +1469,7 @@ CanvasItem::CanvasItem() : drawing = false; behind = false; block_transform_notify = false; - //viewport=NULL; - canvas_layer = NULL; + canvas_layer = nullptr; use_parent_material = false; global_invalid = true; notify_local_transform = false; @@ -1427,13 +1477,13 @@ CanvasItem::CanvasItem() : 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; + texture_filter_cache = RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR; + texture_repeat_cache = RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED; - C = NULL; + C = nullptr; } CanvasItem::~CanvasItem() { - VisualServer::get_singleton()->free(canvas_item); + RenderingServer::get_singleton()->free(canvas_item); } diff --git a/scene/2d/canvas_item.h b/scene/main/canvas_item.h index c7f9500ea1..dc17c5283b 100644 --- a/scene/2d/canvas_item.h +++ b/scene/main/canvas_item.h @@ -201,6 +201,7 @@ private: int light_mask; + Window *window; bool first_draw; bool visible; bool pending_update; @@ -212,8 +213,8 @@ private: bool notify_local_transform; bool notify_transform; - VS::CanvasItemTextureFilter texture_filter_cache; - VS::CanvasItemTextureRepeat texture_repeat_cache; + RS::CanvasItemTextureFilter texture_filter_cache; + RS::CanvasItemTextureRepeat texture_repeat_cache; TextureFilter texture_filter; TextureRepeat texture_repeat; @@ -232,6 +233,8 @@ private: void _enter_canvas(); void _exit_canvas(); + void _window_visibility_changed(); + void _notify_transform(CanvasItem *p_node); void _set_on_top(bool p_on_top) { set_draw_behind_parent(!p_on_top); } @@ -364,6 +367,7 @@ public: virtual Transform2D get_global_transform() const; virtual Transform2D get_global_transform_with_canvas() const; + virtual Transform2D get_screen_transform() const; CanvasItem *get_toplevel() const; _FORCE_INLINE_ RID get_canvas_item() const { diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp index 2085fa3a60..c1caa943e3 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -35,7 +35,7 @@ void CanvasLayer::set_layer(int p_xform) { layer = p_xform; if (viewport.is_valid()) - VisualServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); } int CanvasLayer::get_layer() const { @@ -48,7 +48,7 @@ void CanvasLayer::set_transform(const Transform2D &p_xform) { transform = p_xform; locrotscale_dirty = true; if (viewport.is_valid()) - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); + RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); } Transform2D CanvasLayer::get_transform() const { @@ -61,7 +61,7 @@ void CanvasLayer::_update_xform() { transform.set_rotation_and_scale(rot, scale); transform.set_origin(ofs); if (viewport.is_valid()) - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); + RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); } void CanvasLayer::_update_locrotscale() { @@ -150,16 +150,16 @@ void CanvasLayer::_notification(int p_what) { vp->_canvas_layer_add(this); viewport = vp->get_viewport_rid(); - VisualServer::get_singleton()->viewport_attach_canvas(viewport, canvas); - VisualServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); + RenderingServer::get_singleton()->viewport_attach_canvas(viewport, canvas); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); + RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); _update_follow_viewport(); } break; case NOTIFICATION_EXIT_TREE: { vp->_canvas_layer_remove(this); - VisualServer::get_singleton()->viewport_remove_canvas(viewport, canvas); + RenderingServer::get_singleton()->viewport_remove_canvas(viewport, canvas); viewport = RID(); _update_follow_viewport(false); @@ -167,7 +167,7 @@ void CanvasLayer::_notification(int p_what) { case NOTIFICATION_MOVED_IN_PARENT: { if (is_inside_tree()) - VisualServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); } break; } @@ -191,7 +191,7 @@ void CanvasLayer::set_custom_viewport(Node *p_viewport) { ERR_FAIL_NULL(p_viewport); if (is_inside_tree()) { vp->_canvas_layer_remove(this); - VisualServer::get_singleton()->viewport_remove_canvas(viewport, canvas); + RenderingServer::get_singleton()->viewport_remove_canvas(viewport, canvas); viewport = RID(); } @@ -213,9 +213,9 @@ void CanvasLayer::set_custom_viewport(Node *p_viewport) { vp->_canvas_layer_add(this); viewport = vp->get_viewport_rid(); - VisualServer::get_singleton()->viewport_attach_canvas(viewport, canvas); - VisualServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); + RenderingServer::get_singleton()->viewport_attach_canvas(viewport, canvas); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); + RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); } } @@ -266,9 +266,9 @@ void CanvasLayer::_update_follow_viewport(bool p_force_exit) { return; } if (p_force_exit || !follow_viewport) { - VS::get_singleton()->canvas_set_parent(canvas, RID(), 1.0); + RS::get_singleton()->canvas_set_parent(canvas, RID(), 1.0); } else { - VS::get_singleton()->canvas_set_parent(canvas, vp->get_world_2d()->get_canvas(), follow_viewport_scale); + RS::get_singleton()->canvas_set_parent(canvas, vp->get_world_2d()->get_canvas(), follow_viewport_scale); } } @@ -320,13 +320,13 @@ void CanvasLayer::_bind_methods() { CanvasLayer::CanvasLayer() { - vp = NULL; + vp = nullptr; scale = Vector2(1, 1); rot = 0; locrotscale_dirty = false; layer = 1; - canvas = VS::get_singleton()->canvas_create(); - custom_viewport = NULL; + canvas = RS::get_singleton()->canvas_create(); + custom_viewport = nullptr; sort_index = 0; follow_viewport = false; @@ -335,5 +335,5 @@ CanvasLayer::CanvasLayer() { CanvasLayer::~CanvasLayer() { - VS::get_singleton()->free(canvas); + RS::get_singleton()->free(canvas); } diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index fee2ada76d..dc0da015ac 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -162,12 +162,12 @@ void HTTPRequest::cancel_request() { thread_request_quit = true; Thread::wait_to_finish(thread); memdelete(thread); - thread = NULL; + thread = nullptr; } if (file) { memdelete(file); - file = NULL; + file = nullptr; } client->close(); body.resize(0); @@ -566,7 +566,7 @@ void HTTPRequest::_bind_methods() { HTTPRequest::HTTPRequest() { - thread = NULL; + thread = nullptr; port = 80; redirections = 0; @@ -583,7 +583,7 @@ HTTPRequest::HTTPRequest() { thread_done = false; downloaded = 0; body_size_limit = -1; - file = NULL; + file = nullptr; timer = memnew(Timer); timer->set_one_shot(true); diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp index fe238af1c4..062b221c84 100644 --- a/scene/main/instance_placeholder.cpp +++ b/scene/main/instance_placeholder.cpp @@ -77,11 +77,11 @@ String InstancePlaceholder::get_instance_path() const { Node *InstancePlaceholder::create_instance(bool p_replace, const Ref<PackedScene> &p_custom_scene) { - ERR_FAIL_COND_V(!is_inside_tree(), NULL); + ERR_FAIL_COND_V(!is_inside_tree(), nullptr); Node *base = get_parent(); if (!base) - return NULL; + return nullptr; Ref<PackedScene> ps; if (p_custom_scene.is_valid()) @@ -90,12 +90,12 @@ Node *InstancePlaceholder::create_instance(bool p_replace, const Ref<PackedScene ps = ResourceLoader::load(path, "PackedScene"); if (!ps.is_valid()) - return NULL; + return nullptr; Node *scene = ps->instance(); if (!scene) - return NULL; + return nullptr; scene->set_name(get_name()); - int pos = get_position_in_parent(); + int pos = get_index(); for (List<PropSet>::Element *E = stored_values.front(); E; E = E->next()) { scene->set(E->get().name, E->get().value); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 973dff07d2..4c02a15531 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -82,7 +82,7 @@ void Node::_notification(int p_notification) { if (data.parent) data.pause_owner = data.parent->data.pause_owner; else - data.pause_owner = NULL; + data.pause_owner = nullptr; } else { data.pause_owner = this; } @@ -112,17 +112,17 @@ void Node::_notification(int p_notification) { if (data.unhandled_key_input) remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id())); - data.pause_owner = NULL; + data.pause_owner = nullptr; if (data.path_cache) { memdelete(data.path_cache); - data.path_cache = NULL; + data.path_cache = nullptr; } } break; case NOTIFICATION_PATH_CHANGED: { if (data.path_cache) { memdelete(data.path_cache); - data.path_cache = NULL; + data.path_cache = nullptr; } } break; case NOTIFICATION_READY: { @@ -149,7 +149,7 @@ void Node::_notification(int p_notification) { set_physics_process(true); } - get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_ready, NULL, 0); + get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_ready, nullptr, 0); } } break; @@ -158,11 +158,11 @@ void Node::_notification(int p_notification) { } break; case NOTIFICATION_PREDELETE: { - set_owner(NULL); + set_owner(nullptr); while (data.owned.size()) { - data.owned.front()->get()->set_owner(NULL); + data.owned.front()->get()->set_owner(nullptr); } if (data.parent) { @@ -226,7 +226,7 @@ void Node::_propagate_enter_tree() { if (get_script_instance()) { - get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_enter_tree, NULL, 0); + get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_enter_tree, nullptr, 0); } emit_signal(SceneStringNames::get_singleton()->tree_entered); @@ -278,7 +278,7 @@ void Node::_propagate_exit_tree() { if (get_script_instance()) { - get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_tree, NULL, 0); + get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_tree, nullptr, 0); } emit_signal(SceneStringNames::get_singleton()->tree_exiting); @@ -290,17 +290,17 @@ void Node::_propagate_exit_tree() { for (Map<StringName, GroupData>::Element *E = data.grouped.front(); E; E = E->next()) { data.tree->remove_from_group(E->key(), this); - E->get().group = NULL; + E->get().group = nullptr; } - data.viewport = NULL; + data.viewport = nullptr; if (data.tree) data.tree->tree_changed(); data.inside_tree = false; data.ready_notified = false; - data.tree = NULL; + data.tree = nullptr; data.depth = -1; } @@ -423,7 +423,7 @@ void Node::set_pause_mode(PauseMode p_mode) { if ((data.pause_mode == PAUSE_MODE_INHERIT) == prev_inherits) return; ///nothing changed - Node *owner = NULL; + Node *owner = nullptr; if (data.pause_mode == PAUSE_MODE_INHERIT) { @@ -914,7 +914,7 @@ void Node::set_process_priority(int p_priority) { data.process_priority = p_priority; // Make sure we are in SceneTree. - if (data.tree == NULL) { + if (data.tree == nullptr) { return; } @@ -1268,7 +1268,7 @@ void Node::add_child_below_node(Node *p_node, Node *p_child, bool p_legible_uniq add_child(p_child, p_legible_unique_name); if (is_a_parent_of(p_node)) { - move_child(p_child, p_node->get_position_in_parent() + 1); + move_child(p_child, p_node->get_index() + 1); } else { WARN_PRINT("Cannot move under node " + p_node->get_name() + " as " + p_child->get_name() + " does not share a parent."); } @@ -1295,7 +1295,7 @@ void Node::_propagate_validate_owner() { if (!found) { data.owner->data.owned.erase(data.OW); - data.owner = NULL; + data.owner = nullptr; } } @@ -1336,7 +1336,7 @@ void Node::remove_child(Node *p_child) { //if (data.scene) { does not matter - p_child->_set_tree(NULL); + p_child->_set_tree(nullptr); //} remove_child_notify(p_child); @@ -1354,7 +1354,7 @@ void Node::remove_child(Node *p_child) { children[i]->notification(NOTIFICATION_MOVED_IN_PARENT); } - p_child->data.parent = NULL; + p_child->data.parent = nullptr; p_child->data.pos = -1; // validate owner @@ -1371,7 +1371,7 @@ int Node::get_child_count() const { } Node *Node::get_child(int p_index) const { - ERR_FAIL_INDEX_V(p_index, data.children.size(), NULL); + ERR_FAIL_INDEX_V(p_index, data.children.size(), nullptr); return data.children[p_index]; } @@ -1386,19 +1386,19 @@ Node *Node::_get_child_by_name(const StringName &p_name) const { return cd[i]; } - return NULL; + return nullptr; } Node *Node::get_node_or_null(const NodePath &p_path) const { if (p_path.is_empty()) { - return NULL; + return nullptr; } - ERR_FAIL_COND_V_MSG(!data.inside_tree && p_path.is_absolute(), NULL, "Can't use get_node() with absolute paths from outside the active scene tree."); + ERR_FAIL_COND_V_MSG(!data.inside_tree && p_path.is_absolute(), nullptr, "Can't use get_node() with absolute paths from outside the active scene tree."); - Node *current = NULL; - Node *root = NULL; + Node *current = nullptr; + Node *root = nullptr; if (!p_path.is_absolute()) { current = const_cast<Node *>(this); //start from this @@ -1412,7 +1412,7 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { for (int i = 0; i < p_path.get_name_count(); i++) { StringName name = p_path.get_name(i); - Node *next = NULL; + Node *next = nullptr; if (name == SceneStringNames::get_singleton()->dot) { // . @@ -1420,18 +1420,18 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { } else if (name == SceneStringNames::get_singleton()->doubledot) { // .. - if (current == NULL || !current->data.parent) - return NULL; + if (current == nullptr || !current->data.parent) + return nullptr; next = current->data.parent; - } else if (current == NULL) { + } else if (current == nullptr) { if (name == root->get_name()) next = root; } else { - next = NULL; + next = nullptr; for (int j = 0; j < current->data.children.size(); j++) { @@ -1443,8 +1443,8 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { break; } } - if (next == NULL) { - return NULL; + if (next == nullptr) { + return nullptr; }; } current = next; @@ -1456,13 +1456,13 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { Node *Node::get_node(const NodePath &p_path) const { Node *node = get_node_or_null(p_path); - ERR_FAIL_COND_V_MSG(!node, NULL, "Node not found: " + p_path + "."); + ERR_FAIL_COND_V_MSG(!node, nullptr, "Node not found: " + p_path + "."); return node; } bool Node::has_node(const NodePath &p_path) const { - return get_node_or_null(p_path) != NULL; + return get_node_or_null(p_path) != nullptr; } Node *Node::find_node(const String &p_mask, bool p_recursive, bool p_owned) const { @@ -1482,7 +1482,7 @@ Node *Node::find_node(const String &p_mask, bool p_recursive, bool p_owned) cons if (ret) return ret; } - return NULL; + return nullptr; } Node *Node::get_parent() const { @@ -1500,7 +1500,7 @@ Node *Node::find_parent(const String &p_mask) const { p = p->data.parent; } - return NULL; + return nullptr; } bool Node::is_a_parent_of(const Node *p_node) const { @@ -1607,8 +1607,8 @@ void Node::set_owner(Node *p_owner) { if (data.owner) { data.owner->data.owned.erase(data.OW); - data.OW = NULL; - data.owner = NULL; + data.OW = nullptr; + data.owner = nullptr; } ERR_FAIL_COND(p_owner == this); @@ -1663,7 +1663,7 @@ Node *Node::find_common_parent_with(const Node *p_node) const { } if (!common_parent) - return NULL; + return nullptr; return const_cast<Node *>(common_parent); } @@ -1762,7 +1762,7 @@ void Node::add_to_group(const StringName &p_identifier, bool p_persistent) { if (data.tree) { gd.group = data.tree->add_to_group(p_identifier, this); } else { - gd.group = NULL; + gd.group = nullptr; } gd.persistent = p_persistent; @@ -1918,6 +1918,7 @@ int Node::get_index() const { return data.pos; } + void Node::remove_and_skip() { ERR_FAIL_COND(!data.parent); @@ -1935,7 +1936,7 @@ void Node::remove_and_skip() { continue; remove_child(c_node); - c_node->_propagate_replace_owner(this, NULL); + c_node->_propagate_replace_owner(this, nullptr); children.push_back(c_node); clear = false; break; @@ -1949,7 +1950,7 @@ void Node::remove_and_skip() { Node *c_node = children.front()->get(); data.parent->add_child(c_node); - c_node->_propagate_replace_owner(NULL, new_owner); + c_node->_propagate_replace_owner(nullptr, new_owner); children.pop_front(); } @@ -2042,14 +2043,9 @@ bool Node::get_scene_instance_load_placeholder() const { return data.use_placeholder; } -int Node::get_position_in_parent() const { - - return data.pos; -} - Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const { - Node *node = NULL; + Node *node = nullptr; bool instanced = false; @@ -2063,25 +2059,25 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const } else if ((p_flags & DUPLICATE_USE_INSTANCING) && get_filename() != String()) { Ref<PackedScene> res = ResourceLoader::load(get_filename()); - ERR_FAIL_COND_V(res.is_null(), NULL); + ERR_FAIL_COND_V(res.is_null(), nullptr); PackedScene::GenEditState ges = PackedScene::GEN_EDIT_STATE_DISABLED; #ifdef TOOLS_ENABLED if (p_flags & DUPLICATE_FROM_EDITOR) ges = PackedScene::GEN_EDIT_STATE_INSTANCE; #endif node = res->instance(ges); - ERR_FAIL_COND_V(!node, NULL); + ERR_FAIL_COND_V(!node, nullptr); instanced = true; } else { Object *obj = ClassDB::instance(get_class()); - ERR_FAIL_COND_V(!obj, NULL); + ERR_FAIL_COND_V(!obj, nullptr); node = Object::cast_to<Node>(obj); if (!node) memdelete(obj); - ERR_FAIL_COND_V(!node, NULL); + ERR_FAIL_COND_V(!node, nullptr); } if (get_filename() != "") { //an instance @@ -2189,7 +2185,7 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const if (!dup) { memdelete(node); - return NULL; + return nullptr; } node->add_child(dup); @@ -2204,18 +2200,18 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const if (!parent) { memdelete(node); - return NULL; + return nullptr; } Node *dup = E->get()->_duplicate(p_flags, r_duplimap); if (!dup) { memdelete(node); - return NULL; + return nullptr; } parent->add_child(dup); - int pos = E->get()->get_position_in_parent(); + int pos = E->get()->get_index(); if (pos < parent->get_child_count() - 1) { @@ -2256,7 +2252,7 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p if (get_owner() != get_parent()->get_owner()) return; - Node *node = NULL; + Node *node = nullptr; if (get_filename() != "") { @@ -2369,15 +2365,15 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const { Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const { - ERR_FAIL_COND_V(get_filename() != "", NULL); + ERR_FAIL_COND_V(get_filename() != "", nullptr); Object *obj = ClassDB::instance(get_class()); - ERR_FAIL_COND_V_MSG(!obj, NULL, "Node: Could not duplicate: " + String(get_class()) + "."); + ERR_FAIL_COND_V_MSG(!obj, nullptr, "Node: Could not duplicate: " + String(get_class()) + "."); Node *node = Object::cast_to<Node>(obj); if (!node) { memdelete(obj); - ERR_FAIL_V_MSG(NULL, "Node: Could not duplicate: " + String(get_class()) + "."); + ERR_FAIL_V_MSG(nullptr, "Node: Could not duplicate: " + String(get_class()) + "."); } node->set_name(get_name()); @@ -2591,7 +2587,7 @@ Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<Str r_res = RES(); r_leftover_subpath = Vector<StringName>(); if (!node) - return NULL; + return nullptr; if (p_path.get_subname_count()) { @@ -2601,7 +2597,7 @@ Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<Str Variant new_res_v = j == 0 ? node->get(p_path.get_subname(j)) : r_res->get(p_path.get_subname(j)); if (new_res_v.get_type() == Variant::NIL) { // Found nothing on that path - return NULL; + return nullptr; } RES new_res = new_res_v; @@ -2623,8 +2619,8 @@ Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<Str void Node::_set_tree(SceneTree *p_tree) { - SceneTree *tree_changed_a = NULL; - SceneTree *tree_changed_b = NULL; + SceneTree *tree_changed_a = nullptr; + SceneTree *tree_changed_b = nullptr; //ERR_FAIL_COND(p_scene && data.parent && !data.parent->data.scene); //nobug if both are null @@ -2697,9 +2693,9 @@ void Node::queue_delete() { } } -Array Node::_get_children() const { +TypedArray<Node> Node::_get_children() const { - Array arr; + TypedArray<Node> arr; int cc = get_child_count(); arr.resize(cc); for (int i = 0; i < cc; i++) @@ -2860,7 +2856,6 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("get_pause_mode"), &Node::get_pause_mode); ClassDB::bind_method(D_METHOD("can_process"), &Node::can_process); ClassDB::bind_method(D_METHOD("print_stray_nodes"), &Node::_print_stray_nodes); - ClassDB::bind_method(D_METHOD("get_position_in_parent"), &Node::get_position_in_parent); ClassDB::bind_method(D_METHOD("set_display_folded", "fold"), &Node::set_display_folded); ClassDB::bind_method(D_METHOD("is_displayed_folded"), &Node::is_displayed_folded); @@ -2950,9 +2945,9 @@ void Node::_bind_methods() { BIND_CONSTANT(NOTIFICATION_WM_MOUSE_EXIT); BIND_CONSTANT(NOTIFICATION_WM_FOCUS_IN); BIND_CONSTANT(NOTIFICATION_WM_FOCUS_OUT); - BIND_CONSTANT(NOTIFICATION_WM_QUIT_REQUEST); + BIND_CONSTANT(NOTIFICATION_WM_CLOSE_REQUEST); BIND_CONSTANT(NOTIFICATION_WM_GO_BACK_REQUEST); - BIND_CONSTANT(NOTIFICATION_WM_UNFOCUS_REQUEST); + BIND_CONSTANT(NOTIFICATION_WM_SIZE_CHANGED); BIND_CONSTANT(NOTIFICATION_OS_MEMORY_WARNING); BIND_CONSTANT(NOTIFICATION_TRANSLATION_CHANGED); BIND_CONSTANT(NOTIFICATION_WM_ABOUT); @@ -3012,8 +3007,8 @@ Node::Node() { data.pos = -1; data.depth = -1; data.blocked = 0; - data.parent = NULL; - data.tree = NULL; + data.parent = nullptr; + data.tree = nullptr; data.physics_process = false; data.idle_process = false; data.process_priority = 0; @@ -3022,18 +3017,18 @@ Node::Node() { data.inside_tree = false; data.ready_notified = false; - data.owner = NULL; - data.OW = NULL; + data.owner = nullptr; + data.OW = nullptr; data.input = false; data.unhandled_input = false; data.unhandled_key_input = false; data.pause_mode = PAUSE_MODE_INHERIT; - data.pause_owner = NULL; + data.pause_owner = nullptr; data.network_master = 1; //server by default - data.path_cache = NULL; + data.path_cache = nullptr; data.parent_owned = false; data.in_constructor = true; - data.viewport = NULL; + data.viewport = nullptr; data.use_placeholder = false; data.display_folded = false; data.ready_first = true; diff --git a/scene/main/node.h b/scene/main/node.h index d1f75b71ec..1c1b7bbd7a 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -37,6 +37,7 @@ #include "core/object.h" #include "core/project_settings.h" #include "core/script_language.h" +#include "core/typed_array.h" #include "scene/main/scene_tree.h" class Viewport; @@ -180,9 +181,9 @@ private: void _duplicate_signals(const Node *p_original, Node *p_copy) const; void _duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p_reown_map) const; - Node *_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap = NULL) const; + Node *_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap = nullptr) const; - Array _get_children() const; + TypedArray<Node> _get_children() const; Array _get_groups() const; Variant _rpc_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error); @@ -244,13 +245,16 @@ public: NOTIFICATION_INTERNAL_PHYSICS_PROCESS = 26, NOTIFICATION_POST_ENTER_TREE = 27, //keep these linked to node - NOTIFICATION_WM_MOUSE_ENTER = MainLoop::NOTIFICATION_WM_MOUSE_ENTER, - NOTIFICATION_WM_MOUSE_EXIT = MainLoop::NOTIFICATION_WM_MOUSE_EXIT, - NOTIFICATION_WM_FOCUS_IN = MainLoop::NOTIFICATION_WM_FOCUS_IN, - NOTIFICATION_WM_FOCUS_OUT = MainLoop::NOTIFICATION_WM_FOCUS_OUT, - NOTIFICATION_WM_QUIT_REQUEST = MainLoop::NOTIFICATION_WM_QUIT_REQUEST, - NOTIFICATION_WM_GO_BACK_REQUEST = MainLoop::NOTIFICATION_WM_GO_BACK_REQUEST, - NOTIFICATION_WM_UNFOCUS_REQUEST = MainLoop::NOTIFICATION_WM_UNFOCUS_REQUEST, + + NOTIFICATION_WM_MOUSE_ENTER = 1002, + NOTIFICATION_WM_MOUSE_EXIT = 1003, + NOTIFICATION_WM_FOCUS_IN = 1004, + NOTIFICATION_WM_FOCUS_OUT = 1005, + NOTIFICATION_WM_CLOSE_REQUEST = 1006, + NOTIFICATION_WM_GO_BACK_REQUEST = 1007, + NOTIFICATION_WM_SIZE_CHANGED = 1008, + NOTIFICATION_WM_DPI_CHANGE = 1009, + NOTIFICATION_OS_MEMORY_WARNING = MainLoop::NOTIFICATION_OS_MEMORY_WARNING, NOTIFICATION_TRANSLATION_CHANGED = MainLoop::NOTIFICATION_TRANSLATION_CHANGED, NOTIFICATION_WM_ABOUT = MainLoop::NOTIFICATION_WM_ABOUT, @@ -283,7 +287,7 @@ public: Node *find_parent(const String &p_mask) const; _FORCE_INLINE_ SceneTree *get_tree() const { - ERR_FAIL_COND_V(!data.tree, NULL); + ERR_FAIL_COND_V(!data.tree, nullptr); return data.tree; } @@ -366,8 +370,6 @@ public: void set_process_unhandled_key_input(bool p_enable); bool is_processing_unhandled_key_input() const; - int get_position_in_parent() const; - Node *duplicate(int p_flags = DUPLICATE_GROUPS | DUPLICATE_SIGNALS | DUPLICATE_SCRIPTS) const; Node *duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const; #ifdef TOOLS_ENABLED diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index f472de220b..f30a899d69 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -31,6 +31,7 @@ #include "scene_tree.h" #include "core/debugger/engine_debugger.h" +#include "core/input/input_filter.h" #include "core/io/marshalls.h" #include "core/io/resource_loader.h" #include "core/message_queue.h" @@ -39,7 +40,6 @@ #include "core/os/os.h" #include "core/print_string.h" #include "core/project_settings.h" -#include "main/input_default.h" #include "node.h" #include "scene/debugger/scene_debugger.h" #include "scene/resources/dynamic_font.h" @@ -47,10 +47,11 @@ #include "scene/resources/mesh.h" #include "scene/resources/packed_scene.h" #include "scene/scene_string_names.h" -#include "servers/navigation_server.h" -#include "servers/physics_2d_server.h" -#include "servers/physics_server.h" -#include "viewport.h" +#include "servers/display_server.h" +#include "servers/navigation_server_3d.h" +#include "servers/physics_server_2d.h" +#include "servers/physics_server_3d.h" +#include "window.h" #include <stdio.h> @@ -111,7 +112,7 @@ void SceneTree::node_added(Node *p_node) { void SceneTree::node_removed(Node *p_node) { if (current_scene == p_node) { - current_scene = NULL; + current_scene = nullptr; } emit_signal(node_removed_name, p_node); if (call_lock > 0) @@ -397,69 +398,6 @@ void SceneTree::set_group(const StringName &p_group, const String &p_name, const set_group_flags(0, p_group, p_name, p_value); } -void SceneTree::set_input_as_handled() { - - input_handled = true; -} - -void SceneTree::input_text(const String &p_text) { - - root_lock++; - - call_group_flags(GROUP_CALL_REALTIME, "_viewports", "_vp_input_text", p_text); //special one for GUI, as controls use their own process check - - root_lock--; -} - -bool SceneTree::is_input_handled() { - return input_handled; -} - -void SceneTree::input_event(const Ref<InputEvent> &p_event) { - - if (Engine::get_singleton()->is_editor_hint() && (Object::cast_to<InputEventJoypadButton>(p_event.ptr()) || Object::cast_to<InputEventJoypadMotion>(*p_event))) - return; //avoid joy input on editor - - current_event++; - root_lock++; - - input_handled = false; - - // Don't make const ref unless you can find and fix what caused GH-34691. - Ref<InputEvent> ev = p_event; - - MainLoop::input_event(ev); - - call_group_flags(GROUP_CALL_REALTIME, "_viewports", "_vp_input", ev); //special one for GUI, as controls use their own process check - - if (EngineDebugger::is_active()) { - //quit from game window using F8 - Ref<InputEventKey> k = ev; - if (k.is_valid() && k->is_pressed() && !k->is_echo() && k->get_keycode() == KEY_F8) { - EngineDebugger::get_singleton()->send_message("request_quit", Array()); - } - } - - _flush_ugc(); - root_lock--; - //MessageQueue::get_singleton()->flush(); //flushing here causes UI and other places slowness - - root_lock++; - - if (!input_handled) { - call_group_flags(GROUP_CALL_REALTIME, "_viewports", "_vp_unhandled_input", ev); //special one for GUI, as controls use their own process check - _flush_ugc(); - // input_handled = true; - no reason to set this as handled - root_lock--; - //MessageQueue::get_singleton()->flush(); //flushing here causes UI and other places slowness - } else { - // input_handled = true; - no reason to set this as handled - root_lock--; - } - - _call_idle_callbacks(); -} - void SceneTree::init() { initialized = true; root->_set_tree(this); @@ -493,19 +431,11 @@ bool SceneTree::iteration(float p_time) { return _quit; } -void SceneTree::_update_font_oversampling(float p_ratio) { - - if (use_font_oversampling) { - DynamicFontAtSize::font_oversampling = p_ratio; - DynamicFont::update_oversampling(); - } -} - bool SceneTree::idle(float p_time) { //print_line("ram: "+itos(OS::get_singleton()->get_static_memory_usage())+" sram: "+itos(OS::get_singleton()->get_dynamic_memory_usage())); //print_line("node count: "+itos(get_node_count())); - //print_line("TEXTURE RAM: "+itos(VS::get_singleton()->get_render_info(VS::INFO_TEXTURE_MEM_USED))); + //print_line("TEXTURE RAM: "+itos(RS::get_singleton()->get_render_info(RS::INFO_TEXTURE_MEM_USED))); root_lock++; @@ -526,15 +456,6 @@ bool SceneTree::idle(float p_time) { _notify_group_pause("idle_process_internal", Node::NOTIFICATION_INTERNAL_PROCESS); _notify_group_pause("idle_process", Node::NOTIFICATION_PROCESS); - Size2 win_size = Size2(OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height); - - if (win_size != last_screen_size) { - - last_screen_size = win_size; - _update_root_rect(); - emit_signal("screen_resized"); - } - _flush_ugc(); MessageQueue::get_singleton()->flush(); //small little hack flush_transform_notifications(); //transforms after world update, to avoid unnecessary enter/exit notifications @@ -618,10 +539,10 @@ void SceneTree::finish() { MainLoop::finish(); if (root) { - root->_set_tree(NULL); + root->_set_tree(nullptr); root->_propagate_after_exit_tree(); memdelete(root); //delete root - root = NULL; + root = nullptr; } // cleanup timers @@ -642,59 +563,36 @@ void SceneTree::quit(int p_exit_code) { _quit = true; } -void SceneTree::_notification(int p_notification) { - - switch (p_notification) { - - case NOTIFICATION_WM_QUIT_REQUEST: { - - get_root()->propagate_notification(p_notification); - - if (accept_quit) { - _quit = true; - break; - } - } break; - - case NOTIFICATION_WM_GO_BACK_REQUEST: { - - get_root()->propagate_notification(p_notification); +void SceneTree::_main_window_close() { - if (quit_on_go_back) { - _quit = true; - break; - } - } break; + if (accept_quit) { + _quit = true; + } +} +void SceneTree::_main_window_go_back() { + if (quit_on_go_back) { + _quit = true; + } +} - case NOTIFICATION_WM_FOCUS_IN: { +void SceneTree::_main_window_focus_in() { + InputFilter *id = InputFilter::get_singleton(); + if (id) { + id->ensure_touch_mouse_raised(); + } +} - InputDefault *id = Object::cast_to<InputDefault>(Input::get_singleton()); - if (id) { - id->ensure_touch_mouse_raised(); - } +void SceneTree::_notification(int p_notification) { - get_root()->propagate_notification(p_notification); - } break; + switch (p_notification) { case NOTIFICATION_TRANSLATION_CHANGED: { if (!Engine::get_singleton()->is_editor_hint()) { get_root()->propagate_notification(p_notification); } } break; - - case NOTIFICATION_WM_UNFOCUS_REQUEST: { - - notify_group_flags(GROUP_CALL_REALTIME | GROUP_CALL_MULTILEVEL, "input", NOTIFICATION_WM_UNFOCUS_REQUEST); - - get_root()->propagate_notification(p_notification); - - } break; - case NOTIFICATION_OS_MEMORY_WARNING: case NOTIFICATION_OS_IME_UPDATE: - case NOTIFICATION_WM_MOUSE_ENTER: - case NOTIFICATION_WM_MOUSE_EXIT: - case NOTIFICATION_WM_FOCUS_OUT: case NOTIFICATION_WM_ABOUT: case NOTIFICATION_CRASH: case NOTIFICATION_APP_RESUMED: @@ -898,9 +796,9 @@ void SceneTree::set_pause(bool p_enabled) { if (p_enabled == pause) return; pause = p_enabled; - NavigationServer::get_singleton()->set_active(!p_enabled); - PhysicsServer::get_singleton()->set_active(!p_enabled); - Physics2DServer::get_singleton()->set_active(!p_enabled); + NavigationServer3D::get_singleton()->set_active(!p_enabled); + PhysicsServer3D::get_singleton()->set_active(!p_enabled); + PhysicsServer2D::get_singleton()->set_active(!p_enabled); if (get_root()) get_root()->propagate_notification(p_enabled ? Node::NOTIFICATION_PAUSED : Node::NOTIFICATION_UNPAUSED); } @@ -910,7 +808,7 @@ bool SceneTree::is_paused() const { return pause; } -void SceneTree::_call_input_pause(const StringName &p_group, const StringName &p_method, const Ref<InputEvent> &p_input) { +void SceneTree::_notify_group_pause(const StringName &p_group, int p_notification) { Map<StringName, Group>::Element *E = group_map.find(p_group); if (!E) @@ -919,7 +817,7 @@ void SceneTree::_call_input_pause(const StringName &p_group, const StringName &p if (g.nodes.empty()) return; - _update_group_order(g); + _update_group_order(g, p_notification == Node::NOTIFICATION_PROCESS || p_notification == Node::NOTIFICATION_INTERNAL_PROCESS || p_notification == Node::NOTIFICATION_PHYSICS_PROCESS || p_notification == Node::NOTIFICATION_INTERNAL_PHYSICS_PROCESS); //copy, so copy on write happens in case something is removed from process while being called //performance is not lost because only if something is added/removed the vector is copied. @@ -928,15 +826,9 @@ void SceneTree::_call_input_pause(const StringName &p_group, const StringName &p int node_count = nodes_copy.size(); Node **nodes = nodes_copy.ptrw(); - Variant arg = p_input; - const Variant *v[1] = { &arg }; - call_lock++; - for (int i = node_count - 1; i >= 0; i--) { - - if (input_handled) - break; + for (int i = 0; i < node_count; i++) { Node *n = nodes[i]; if (call_lock && call_skip.has(n)) @@ -944,8 +836,10 @@ void SceneTree::_call_input_pause(const StringName &p_group, const StringName &p if (!n->can_process()) continue; + if (!n->can_process_notification(p_notification)) + continue; - n->call_multilevel(p_method, (const Variant **)v, 1); + n->notification(p_notification); //ERR_FAIL_COND(node_count != g.nodes.size()); } @@ -954,7 +848,18 @@ void SceneTree::_call_input_pause(const StringName &p_group, const StringName &p call_skip.clear(); } -void SceneTree::_notify_group_pause(const StringName &p_group, int p_notification) { +/* +void SceneMainLoop::_update_listener_2d() { + + if (listener_2d.is_valid()) { + + SpatialSound2DServer::get_singleton()->listener_set_space( listener_2d, world_2d->get_sound_space() ); + } + +} +*/ + +void SceneTree::_call_input_pause(const StringName &p_group, const StringName &p_method, const Ref<InputEvent> &p_input, Viewport *p_viewport) { Map<StringName, Group>::Element *E = group_map.find(p_group); if (!E) @@ -963,7 +868,7 @@ void SceneTree::_notify_group_pause(const StringName &p_group, int p_notificatio if (g.nodes.empty()) return; - _update_group_order(g, p_notification == Node::NOTIFICATION_PROCESS || p_notification == Node::NOTIFICATION_INTERNAL_PROCESS || p_notification == Node::NOTIFICATION_PHYSICS_PROCESS || p_notification == Node::NOTIFICATION_INTERNAL_PHYSICS_PROCESS); + _update_group_order(g); //copy, so copy on write happens in case something is removed from process while being called //performance is not lost because only if something is added/removed the vector is copied. @@ -972,9 +877,15 @@ void SceneTree::_notify_group_pause(const StringName &p_group, int p_notificatio int node_count = nodes_copy.size(); Node **nodes = nodes_copy.ptrw(); + Variant arg = p_input; + const Variant *v[1] = { &arg }; + call_lock++; - for (int i = 0; i < node_count; i++) { + for (int i = node_count - 1; i >= 0; i--) { + + if (p_viewport->is_input_handled()) + break; Node *n = nodes[i]; if (call_lock && call_skip.has(n)) @@ -982,10 +893,8 @@ void SceneTree::_notify_group_pause(const StringName &p_group, int p_notificatio if (!n->can_process()) continue; - if (!n->can_process_notification(p_notification)) - continue; - n->notification(p_notification); + n->call_multilevel(p_method, (const Variant **)v, 1); //ERR_FAIL_COND(node_count != g.nodes.size()); } @@ -993,18 +902,6 @@ void SceneTree::_notify_group_pause(const StringName &p_group, int p_notificatio if (call_lock == 0) call_skip.clear(); } - -/* -void SceneMainLoop::_update_listener_2d() { - - if (listener_2d.is_valid()) { - - SpatialSound2DServer::get_singleton()->listener_set_space( listener_2d, world_2d->get_sound_space() ); - } - -} -*/ - Variant SceneTree::_call_group_flags(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { r_error.error = Callable::CallError::CALL_OK; @@ -1129,129 +1026,6 @@ int SceneTree::get_node_count() const { return node_count; } -void SceneTree::_update_root_rect() { - - if (stretch_mode == STRETCH_MODE_DISABLED) { - - _update_font_oversampling(1.0); - root->set_size((last_screen_size / stretch_shrink).floor()); - root->set_attach_to_screen_rect(Rect2(Point2(), last_screen_size)); - root->set_size_override_stretch(false); - root->set_size_override(false, Size2()); - root->update_canvas_items(); - return; //user will take care - } - - //actual screen video mode - Size2 video_mode = Size2(OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height); - Size2 desired_res = stretch_min; - - Size2 viewport_size; - Size2 screen_size; - - float viewport_aspect = desired_res.aspect(); - float video_mode_aspect = video_mode.aspect(); - - if (use_font_oversampling && stretch_aspect == STRETCH_ASPECT_IGNORE) { - WARN_PRINT("Font oversampling only works with the resize modes 'Keep Width', 'Keep Height', and 'Expand'."); - } - - if (stretch_aspect == STRETCH_ASPECT_IGNORE || Math::is_equal_approx(viewport_aspect, video_mode_aspect)) { - //same aspect or ignore aspect - viewport_size = desired_res; - screen_size = video_mode; - } else if (viewport_aspect < video_mode_aspect) { - // screen ratio is smaller vertically - - if (stretch_aspect == STRETCH_ASPECT_KEEP_HEIGHT || stretch_aspect == STRETCH_ASPECT_EXPAND) { - - //will stretch horizontally - viewport_size.x = desired_res.y * video_mode_aspect; - viewport_size.y = desired_res.y; - screen_size = video_mode; - - } else { - //will need black bars - viewport_size = desired_res; - screen_size.x = video_mode.y * viewport_aspect; - screen_size.y = video_mode.y; - } - } else { - //screen ratio is smaller horizontally - if (stretch_aspect == STRETCH_ASPECT_KEEP_WIDTH || stretch_aspect == STRETCH_ASPECT_EXPAND) { - - //will stretch horizontally - viewport_size.x = desired_res.x; - viewport_size.y = desired_res.x / video_mode_aspect; - screen_size = video_mode; - - } else { - //will need black bars - viewport_size = desired_res; - screen_size.x = video_mode.x; - screen_size.y = video_mode.x / viewport_aspect; - } - } - - screen_size = screen_size.floor(); - viewport_size = viewport_size.floor(); - - Size2 margin; - Size2 offset; - //black bars and margin - if (stretch_aspect != STRETCH_ASPECT_EXPAND && screen_size.x < video_mode.x) { - margin.x = Math::round((video_mode.x - screen_size.x) / 2.0); - VisualServer::get_singleton()->black_bars_set_margins(margin.x, 0, margin.x, 0); - offset.x = Math::round(margin.x * viewport_size.y / screen_size.y); - } else if (stretch_aspect != STRETCH_ASPECT_EXPAND && screen_size.y < video_mode.y) { - margin.y = Math::round((video_mode.y - screen_size.y) / 2.0); - VisualServer::get_singleton()->black_bars_set_margins(0, margin.y, 0, margin.y); - offset.y = Math::round(margin.y * viewport_size.x / screen_size.x); - } else { - VisualServer::get_singleton()->black_bars_set_margins(0, 0, 0, 0); - } - - switch (stretch_mode) { - case STRETCH_MODE_DISABLED: { - // Already handled above - _update_font_oversampling(1.0); - } break; - case STRETCH_MODE_2D: { - - _update_font_oversampling(screen_size.x / viewport_size.x); //screen / viewport radio drives oversampling - root->set_size((screen_size / stretch_shrink).floor()); - root->set_attach_to_screen_rect(Rect2(margin, screen_size)); - root->set_size_override_stretch(true); - root->set_size_override(true, (viewport_size / stretch_shrink).floor()); - root->update_canvas_items(); //force them to update just in case - - } break; - case STRETCH_MODE_VIEWPORT: { - - _update_font_oversampling(1.0); - root->set_size((viewport_size / stretch_shrink).floor()); - root->set_attach_to_screen_rect(Rect2(margin, screen_size)); - root->set_size_override_stretch(false); - root->set_size_override(false, Size2()); - root->update_canvas_items(); //force them to update just in case - - if (use_font_oversampling) { - WARN_PRINT("Font oversampling does not work in 'Viewport' stretch mode, only '2D'."); - } - - } break; - } -} - -void SceneTree::set_screen_stretch(StretchMode p_mode, StretchAspect p_aspect, const Size2 &p_minsize, real_t p_shrink) { - - stretch_mode = p_mode; - stretch_aspect = p_aspect; - stretch_min = p_minsize; - stretch_shrink = p_shrink; - _update_root_rect(); -} - void SceneTree::set_edited_scene_root(Node *p_node) { #ifdef TOOLS_ENABLED edited_scene_root = p_node; @@ -1263,7 +1037,7 @@ Node *SceneTree::get_edited_scene_root() const { #ifdef TOOLS_ENABLED return edited_scene_root; #else - return NULL; + return nullptr; #endif } @@ -1282,7 +1056,7 @@ void SceneTree::_change_scene(Node *p_to) { if (current_scene) { memdelete(current_scene); - current_scene = NULL; + current_scene = nullptr; } // If we're quitting, abort. @@ -1308,7 +1082,7 @@ Error SceneTree::change_scene(const String &p_path) { } Error SceneTree::change_scene_to(const Ref<PackedScene> &p_scene) { - Node *new_scene = NULL; + Node *new_scene = nullptr; if (p_scene.is_valid()) { new_scene = p_scene->instance(); ERR_FAIL_COND_V(!new_scene, ERR_CANT_CREATE); @@ -1330,18 +1104,6 @@ void SceneTree::add_current_scene(Node *p_current) { root->add_child(p_current); } -void SceneTree::drop_files(const Vector<String> &p_files, int p_from_screen) { - - emit_signal("files_dropped", p_files, p_from_screen); - MainLoop::drop_files(p_files, p_from_screen); -} - -void SceneTree::global_menu_action(const Variant &p_id, const Variant &p_meta) { - - emit_signal("global_menu_action", p_id, p_meta); - MainLoop::global_menu_action(p_id, p_meta); -} - Ref<SceneTreeTimer> SceneTree::create_timer(float p_delay_sec, bool p_process_pause) { Ref<SceneTreeTimer> stt; @@ -1469,8 +1231,6 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("set_pause", "enable"), &SceneTree::set_pause); ClassDB::bind_method(D_METHOD("is_paused"), &SceneTree::is_paused); - ClassDB::bind_method(D_METHOD("set_input_as_handled"), &SceneTree::set_input_as_handled); - ClassDB::bind_method(D_METHOD("is_input_handled"), &SceneTree::is_input_handled); ClassDB::bind_method(D_METHOD("create_timer", "time_sec", "pause_mode_process"), &SceneTree::create_timer, DEFVAL(true)); @@ -1478,8 +1238,6 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("get_frame"), &SceneTree::get_frame); ClassDB::bind_method(D_METHOD("quit", "exit_code"), &SceneTree::quit, DEFVAL(-1)); - ClassDB::bind_method(D_METHOD("set_screen_stretch", "mode", "aspect", "minsize", "shrink"), &SceneTree::set_screen_stretch, DEFVAL(1)); - ClassDB::bind_method(D_METHOD("queue_delete", "obj"), &SceneTree::queue_delete); MethodInfo mi; @@ -1529,15 +1287,11 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("set_refuse_new_network_connections", "refuse"), &SceneTree::set_refuse_new_network_connections); ClassDB::bind_method(D_METHOD("is_refusing_new_network_connections"), &SceneTree::is_refusing_new_network_connections); - ClassDB::bind_method(D_METHOD("set_use_font_oversampling", "enable"), &SceneTree::set_use_font_oversampling); - ClassDB::bind_method(D_METHOD("is_using_font_oversampling"), &SceneTree::is_using_font_oversampling); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_collisions_hint"), "set_debug_collisions_hint", "is_debugging_collisions_hint"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_navigation_hint"), "set_debug_navigation_hint", "is_debugging_navigation_hint"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "paused"), "set_pause", "is_paused"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "refuse_new_network_connections"), "set_refuse_new_network_connections", "is_refusing_new_network_connections"); ADD_PROPERTY_DEFAULT("refuse_new_network_connections", false); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_font_oversampling"), "set_use_font_oversampling", "is_using_font_oversampling"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "edited_scene_root", PROPERTY_HINT_RESOURCE_TYPE, "Node", 0), "set_edited_scene_root", "get_edited_scene_root"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "current_scene", PROPERTY_HINT_RESOURCE_TYPE, "Node", 0), "set_current_scene", "get_current_scene"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "network_peer", PROPERTY_HINT_RESOURCE_TYPE, "NetworkedMultiplayerPeer", 0), "set_network_peer", "get_network_peer"); @@ -1549,14 +1303,12 @@ void SceneTree::_bind_methods() { ADD_SIGNAL(MethodInfo("node_added", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("node_removed", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("node_renamed", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); - ADD_SIGNAL(MethodInfo("screen_resized")); ADD_SIGNAL(MethodInfo("node_configuration_warning_changed", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("idle_frame")); ADD_SIGNAL(MethodInfo("physics_frame")); ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files"), PropertyInfo(Variant::INT, "screen"))); - ADD_SIGNAL(MethodInfo("global_menu_action", PropertyInfo(Variant::NIL, "id"), PropertyInfo(Variant::NIL, "meta"))); ADD_SIGNAL(MethodInfo("network_peer_connected", PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("network_peer_disconnected", PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("connected_to_server")); @@ -1567,19 +1319,9 @@ void SceneTree::_bind_methods() { BIND_ENUM_CONSTANT(GROUP_CALL_REVERSE); BIND_ENUM_CONSTANT(GROUP_CALL_REALTIME); BIND_ENUM_CONSTANT(GROUP_CALL_UNIQUE); - - BIND_ENUM_CONSTANT(STRETCH_MODE_DISABLED); - BIND_ENUM_CONSTANT(STRETCH_MODE_2D); - BIND_ENUM_CONSTANT(STRETCH_MODE_VIEWPORT); - - BIND_ENUM_CONSTANT(STRETCH_ASPECT_IGNORE); - BIND_ENUM_CONSTANT(STRETCH_ASPECT_KEEP); - BIND_ENUM_CONSTANT(STRETCH_ASPECT_KEEP_WIDTH); - BIND_ENUM_CONSTANT(STRETCH_ASPECT_KEEP_HEIGHT); - BIND_ENUM_CONSTANT(STRETCH_ASPECT_EXPAND); } -SceneTree *SceneTree::singleton = NULL; +SceneTree *SceneTree::singleton = nullptr; SceneTree::IdleCallback SceneTree::idle_callbacks[SceneTree::MAX_IDLE_CALLBACKS]; int SceneTree::idle_callback_count = 0; @@ -1596,19 +1338,6 @@ void SceneTree::add_idle_callback(IdleCallback p_callback) { idle_callbacks[idle_callback_count++] = p_callback; } -void SceneTree::set_use_font_oversampling(bool p_oversampling) { - - if (use_font_oversampling == p_oversampling) - return; - - use_font_oversampling = p_oversampling; - _update_root_rect(); -} - -bool SceneTree::is_using_font_oversampling() const { - return use_font_oversampling; -} - void SceneTree::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const { if (p_function == "change_scene") { @@ -1643,12 +1372,11 @@ void SceneTree::get_argument_options(const StringName &p_function, int p_idx, Li SceneTree::SceneTree() { - if (singleton == NULL) singleton = this; + if (singleton == nullptr) singleton = this; _quit = false; accept_quit = true; quit_on_go_back = true; initialized = false; - use_font_oversampling = false; #ifdef DEBUG_ENABLED debug_collisions_hint = false; debug_navigation_hint = false; @@ -1664,8 +1392,7 @@ SceneTree::SceneTree() { physics_process_time = 1; idle_process_time = 1; - root = NULL; - input_handled = false; + root = nullptr; pause = false; current_frame = 0; current_event = 0; @@ -1680,11 +1407,10 @@ SceneTree::SceneTree() { //create with mainloop - root = memnew(Viewport); + root = memnew(Window); root->set_name("root"); - root->set_handle_input_locally(false); if (!root->get_world().is_valid()) - root->set_world(Ref<World>(memnew(World))); + root->set_world(Ref<World3D>(memnew(World3D))); // Initialize network state multiplayer_poll = true; @@ -1693,12 +1419,16 @@ SceneTree::SceneTree() { //root->set_world_2d( Ref<World2D>( memnew( World2D ))); root->set_as_audio_listener(true); root->set_as_audio_listener_2d(true); - current_scene = NULL; + current_scene = nullptr; - int msaa_mode = GLOBAL_DEF("rendering/quality/filters/msaa", 0); - ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/filters/msaa", PropertyInfo(Variant::INT, "rendering/quality/filters/msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x")); + int msaa_mode = GLOBAL_DEF("rendering/quality/screen_filters/msaa", 0); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/screen_filters/msaa", PropertyInfo(Variant::INT, "rendering/quality/screen_filters/msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x")); root->set_msaa(Viewport::MSAA(msaa_mode)); + int ssaa_mode = GLOBAL_DEF("rendering/quality/screen_filters/screen_space_aa", 0); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/screen_filters/screen_space_aa", PropertyInfo(Variant::INT, "rendering/quality/screen_filters/screen_space_aa", PROPERTY_HINT_ENUM, "Disabled,FXAA")); + root->set_screen_space_aa(Viewport::ScreenSpaceAA(ssaa_mode)); + { //load default fallback environment //get possible extensions List<String> exts; @@ -1730,26 +1460,23 @@ SceneTree::SceneTree() { } } - stretch_mode = STRETCH_MODE_DISABLED; - stretch_aspect = STRETCH_ASPECT_IGNORE; - stretch_shrink = 1; - - last_screen_size = Size2(OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height); - _update_root_rect(); - root->set_physics_object_picking(GLOBAL_DEF("physics/common/enable_object_picking", true)); + root->connect("close_requested", callable_mp(this, &SceneTree::_main_window_close)); + root->connect("go_back_requested", callable_mp(this, &SceneTree::_main_window_go_back)); + root->connect("focus_entered", callable_mp(this, &SceneTree::_main_window_focus_in)); + #ifdef TOOLS_ENABLED - edited_scene_root = NULL; + edited_scene_root = nullptr; #endif } SceneTree::~SceneTree() { if (root) { - root->_set_tree(NULL); + root->_set_tree(nullptr); root->_propagate_after_exit_tree(); memdelete(root); } - if (singleton == this) singleton = NULL; + if (singleton == this) singleton = nullptr; } diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index 2f805d074f..319b5a7e74 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -36,12 +36,14 @@ #include "core/os/thread_safe.h" #include "core/self_list.h" #include "scene/resources/mesh.h" -#include "scene/resources/world.h" #include "scene/resources/world_2d.h" +#include "scene/resources/world_3d.h" + +#undef Window class PackedScene; class Node; -class Viewport; +class Window; class Material; class Mesh; class SceneDebugger; @@ -76,22 +78,6 @@ class SceneTree : public MainLoop { public: typedef void (*IdleCallback)(); - enum StretchMode { - - STRETCH_MODE_DISABLED, - STRETCH_MODE_2D, - STRETCH_MODE_VIEWPORT, - }; - - enum StretchAspect { - - STRETCH_ASPECT_IGNORE, - STRETCH_ASPECT_KEEP, - STRETCH_ASPECT_KEEP_WIDTH, - STRETCH_ASPECT_KEEP_HEIGHT, - STRETCH_ASPECT_EXPAND, - }; - private: struct Group { @@ -101,7 +87,7 @@ private: Group() { changed = false; }; }; - Viewport *root; + Window *root; uint64_t tree_version; float physics_process_time; @@ -119,15 +105,12 @@ private: Map<StringName, Group> group_map; bool _quit; bool initialized; - bool input_handled; - Size2 last_screen_size; StringName tree_changed_name; StringName node_added_name; StringName node_removed_name; StringName node_renamed_name; - bool use_font_oversampling; int64_t current_frame; int64_t current_event; int node_count; @@ -147,14 +130,6 @@ private: int call_lock; Set<Node *> call_skip; //skip erased nodes - StretchMode stretch_mode; - StretchAspect stretch_aspect; - Size2i stretch_min; - real_t stretch_shrink; - - void _update_font_oversampling(float p_ratio); - void _update_root_rect(); - List<ObjectID> delete_queue; Map<UGCall, Vector<Variant>> unique_group_calls; @@ -208,14 +183,13 @@ private: void make_group_changed(const StringName &p_group); void _notify_group_pause(const StringName &p_group, int p_notification); - void _call_input_pause(const StringName &p_group, const StringName &p_method, const Ref<InputEvent> &p_input); Variant _call_group_flags(const Variant **p_args, int p_argcount, Callable::CallError &r_error); Variant _call_group(const Variant **p_args, int p_argcount, Callable::CallError &r_error); void _flush_delete_queue(); //optimization friend class CanvasItem; - friend class Spatial; + friend class Node3D; friend class Viewport; SelfList<Node>::List xform_change_list; @@ -232,6 +206,13 @@ private: static int idle_callback_count; void _call_idle_callbacks(); + void _main_window_focus_in(); + void _main_window_close(); + void _main_window_go_back(); + + //used by viewport + void _call_input_pause(const StringName &p_group, const StringName &p_method, const Ref<InputEvent> &p_input, Viewport *p_viewport); + protected: void _notification(int p_notification); static void _bind_methods(); @@ -249,7 +230,7 @@ public: GROUP_CALL_MULTILEVEL = 8, }; - _FORCE_INLINE_ Viewport *get_root() const { return root; } + _FORCE_INLINE_ Window *get_root() const { return root; } void call_group_flags(uint32_t p_call_flags, const StringName &p_group, const StringName &p_function, VARIANT_ARG_LIST); void notify_group_flags(uint32_t p_call_flags, const StringName &p_group, int p_notification); @@ -261,8 +242,6 @@ public: void flush_transform_notifications(); - virtual void input_text(const String &p_text); - virtual void input_event(const Ref<InputEvent> &p_event); virtual void init(); virtual bool iteration(float p_time); @@ -275,8 +254,6 @@ public: void quit(int p_exit_code = -1); - void set_input_as_handled(); - bool is_input_handled(); _FORCE_INLINE_ float get_physics_process_time() const { return physics_process_time; } _FORCE_INLINE_ float get_idle_process_time() const { return idle_process_time; } @@ -335,11 +312,6 @@ public: void get_nodes_in_group(const StringName &p_group, List<Node *> *p_list); bool has_group(const StringName &p_identifier) const; - void set_screen_stretch(StretchMode p_mode, StretchAspect p_aspect, const Size2 &p_minsize, real_t p_shrink = 1); - - void set_use_font_oversampling(bool p_oversampling); - bool is_using_font_oversampling() const; - //void change_scene(const String& p_path); //Node *get_loaded_scene(); @@ -359,8 +331,6 @@ public: static SceneTree *get_singleton() { return singleton; } - void drop_files(const Vector<String> &p_files, int p_from_screen = 0); - void global_menu_action(const Variant &p_id, const Variant &p_meta); void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const; //network API @@ -388,8 +358,6 @@ public: ~SceneTree(); }; -VARIANT_ENUM_CAST(SceneTree::StretchMode); -VARIANT_ENUM_CAST(SceneTree::StretchAspect); VARIANT_ENUM_CAST(SceneTree::GroupCallFlags); #endif diff --git a/scene/main/shader_globals_override.cpp b/scene/main/shader_globals_override.cpp new file mode 100644 index 0000000000..13582cf655 --- /dev/null +++ b/scene/main/shader_globals_override.cpp @@ -0,0 +1,257 @@ +#include "shader_globals_override.h" + +#include "core/core_string_names.h" +#include "scene/main/window.h" +#include "scene/scene_string_names.h" + +StringName *ShaderGlobalsOverride::_remap(const StringName &p_name) const { + + StringName *r = param_remaps.getptr(p_name); + if (!r) { + //not cached, do caching + String p = p_name; + if (p.begins_with("params/")) { + String q = p.replace_first("params/", ""); + param_remaps[p] = q; + r = param_remaps.getptr(q); + } + } + + return r; +} +bool ShaderGlobalsOverride::_set(const StringName &p_name, const Variant &p_value) { + + StringName *r = _remap(p_name); + + if (r) { + Override *o = overrides.getptr(*r); + if (!o) { + Override ov; + ov.in_use = false; + overrides[*r] = ov; + o = overrides.getptr(*r); + } + if (o) { + o->override = p_value; + if (active) { + RS::get_singleton()->global_variable_set_override(*r, p_value); + } + o->in_use = p_value.get_type() != Variant::NIL; + return true; + } + } + + return false; +} + +bool ShaderGlobalsOverride::_get(const StringName &p_name, Variant &r_ret) const { + + StringName *r = _remap(p_name); + + if (r) { + const Override *o = overrides.getptr(*r); + if (o) { + r_ret = o->override; + return true; + } + } + + return false; +} + +void ShaderGlobalsOverride::_get_property_list(List<PropertyInfo> *p_list) const { + + Vector<StringName> variables; + variables = RS::get_singleton()->global_variable_get_list(); + for (int i = 0; i < variables.size(); i++) { + PropertyInfo pinfo; + pinfo.name = "params/" + variables[i]; + pinfo.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; + + switch (RS::get_singleton()->global_variable_get_type(variables[i])) { + case RS::GLOBAL_VAR_TYPE_BOOL: { + pinfo.type = Variant::BOOL; + } break; + case RS::GLOBAL_VAR_TYPE_BVEC2: { + pinfo.type = Variant::INT; + pinfo.hint = PROPERTY_HINT_FLAGS; + pinfo.hint_string = "x,y"; + } break; + case RS::GLOBAL_VAR_TYPE_BVEC3: { + pinfo.type = Variant::INT; + pinfo.hint = PROPERTY_HINT_FLAGS; + pinfo.hint_string = "x,y,z"; + } break; + case RS::GLOBAL_VAR_TYPE_BVEC4: { + pinfo.type = Variant::INT; + pinfo.hint = PROPERTY_HINT_FLAGS; + pinfo.hint_string = "x,y,z,w"; + } break; + case RS::GLOBAL_VAR_TYPE_INT: { + pinfo.type = Variant::INT; + } break; + case RS::GLOBAL_VAR_TYPE_IVEC2: { + pinfo.type = Variant::VECTOR2I; + } break; + case RS::GLOBAL_VAR_TYPE_IVEC3: { + pinfo.type = Variant::VECTOR3I; + } break; + case RS::GLOBAL_VAR_TYPE_IVEC4: { + pinfo.type = Variant::PACKED_INT32_ARRAY; + } break; + case RS::GLOBAL_VAR_TYPE_RECT2I: { + pinfo.type = Variant::RECT2I; + } break; + case RS::GLOBAL_VAR_TYPE_UINT: { + pinfo.type = Variant::INT; + } break; + case RS::GLOBAL_VAR_TYPE_UVEC2: { + pinfo.type = Variant::VECTOR2I; + } break; + case RS::GLOBAL_VAR_TYPE_UVEC3: { + pinfo.type = Variant::VECTOR3I; + } break; + case RS::GLOBAL_VAR_TYPE_UVEC4: { + pinfo.type = Variant::PACKED_INT32_ARRAY; + } break; + case RS::GLOBAL_VAR_TYPE_FLOAT: { + pinfo.type = Variant::FLOAT; + } break; + case RS::GLOBAL_VAR_TYPE_VEC2: { + pinfo.type = Variant::VECTOR2; + } break; + case RS::GLOBAL_VAR_TYPE_VEC3: { + pinfo.type = Variant::VECTOR3; + } break; + case RS::GLOBAL_VAR_TYPE_VEC4: { + pinfo.type = Variant::PLANE; + } break; + case RS::GLOBAL_VAR_TYPE_RECT2: { + pinfo.type = Variant::RECT2; + } break; + case RS::GLOBAL_VAR_TYPE_COLOR: { + pinfo.type = Variant::COLOR; + } break; + case RS::GLOBAL_VAR_TYPE_MAT2: { + pinfo.type = Variant::PACKED_INT32_ARRAY; + } break; + case RS::GLOBAL_VAR_TYPE_MAT3: { + pinfo.type = Variant::BASIS; + } break; + case RS::GLOBAL_VAR_TYPE_TRANSFORM_2D: { + pinfo.type = Variant::TRANSFORM2D; + } break; + case RS::GLOBAL_VAR_TYPE_TRANSFORM: { + pinfo.type = Variant::TRANSFORM; + } break; + case RS::GLOBAL_VAR_TYPE_MAT4: { + pinfo.type = Variant::PACKED_INT32_ARRAY; + } break; + case RS::GLOBAL_VAR_TYPE_SAMPLER2D: { + pinfo.type = Variant::OBJECT; + pinfo.hint = PROPERTY_HINT_RESOURCE_TYPE; + pinfo.hint_string = "Texture2D"; + } break; + case RS::GLOBAL_VAR_TYPE_SAMPLER2DARRAY: { + pinfo.type = Variant::OBJECT; + pinfo.hint = PROPERTY_HINT_RESOURCE_TYPE; + pinfo.hint_string = "Texture2DArray"; + } break; + case RS::GLOBAL_VAR_TYPE_SAMPLER3D: { + pinfo.type = Variant::OBJECT; + pinfo.hint = PROPERTY_HINT_RESOURCE_TYPE; + pinfo.hint_string = "Texture3D"; + } break; + case RS::GLOBAL_VAR_TYPE_SAMPLERCUBE: { + pinfo.type = Variant::OBJECT; + pinfo.hint = PROPERTY_HINT_RESOURCE_TYPE; + pinfo.hint_string = "Cubemap"; + } break; + default: { + + } break; + } + + if (!overrides.has(variables[i])) { + Override o; + o.in_use = false; + Callable::CallError ce; + o.override = Variant::construct(pinfo.type, NULL, 0, ce); + overrides[variables[i]] = o; + } + + Override *o = overrides.getptr(variables[i]); + if (o->in_use && o->override.get_type() != Variant::NIL) { + pinfo.usage |= PROPERTY_USAGE_CHECKED; + pinfo.usage |= PROPERTY_USAGE_STORAGE; + } + + p_list->push_back(pinfo); + } +} + +void ShaderGlobalsOverride::_activate() { + + List<Node *> nodes; + get_tree()->get_nodes_in_group(SceneStringNames::get_singleton()->shader_overrides_group_active, &nodes); + if (nodes.size() == 0) { + //good we are the only override, enable all + active = true; + add_to_group(SceneStringNames::get_singleton()->shader_overrides_group_active); + + const StringName *K = nullptr; + while ((K = overrides.next(K))) { + Override *o = overrides.getptr(*K); + if (o->in_use && o->override.get_type() != Variant::NIL) { + RS::get_singleton()->global_variable_set_override(*K, o->override); + } + } + + update_configuration_warning(); //may have activated + } +} + +void ShaderGlobalsOverride::_notification(int p_what) { + + if (p_what == Node3D::NOTIFICATION_ENTER_TREE) { + + add_to_group(SceneStringNames::get_singleton()->shader_overrides_group); + _activate(); + + } else if (p_what == Node3D::NOTIFICATION_EXIT_TREE) { + + if (active) { + //remove overrides + const StringName *K = nullptr; + while ((K = overrides.next(K))) { + Override *o = overrides.getptr(*K); + if (o->in_use) { + RS::get_singleton()->global_variable_set_override(*K, Variant()); + } + } + } + + remove_from_group(SceneStringNames::get_singleton()->shader_overrides_group_active); + remove_from_group(SceneStringNames::get_singleton()->shader_overrides_group); + get_tree()->call_group(SceneStringNames::get_singleton()->shader_overrides_group, "_activate"); //another may want to activate when this is removed + active = false; + } +} + +String ShaderGlobalsOverride::get_configuration_warning() const { + + if (!active) { + return TTR("ShaderGlobalsOverride is not active because another node of the same type is in the scene."); + } + + return String(); +} + +void ShaderGlobalsOverride::_bind_methods() { + + ClassDB::bind_method(D_METHOD("_activate"), &ShaderGlobalsOverride::_activate); +} + +ShaderGlobalsOverride::ShaderGlobalsOverride() { + active = false; +} diff --git a/scene/main/shader_globals_override.h b/scene/main/shader_globals_override.h new file mode 100644 index 0000000000..33d0dc948f --- /dev/null +++ b/scene/main/shader_globals_override.h @@ -0,0 +1,37 @@ +#ifndef SHADER_GLOBALS_OVERRIDE_H +#define SHADER_GLOBALS_OVERRIDE_H + +#include "scene/3d/node_3d.h" + +class ShaderGlobalsOverride : public Node { + + GDCLASS(ShaderGlobalsOverride, Node); + + struct Override { + bool in_use = false; + Variant override; + }; + + StringName *_remap(const StringName &p_name) const; + + bool active; + mutable HashMap<StringName, Override> overrides; + mutable HashMap<StringName, StringName> param_remaps; + + void _activate(); + +protected: + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; + + void _notification(int p_what); + static void _bind_methods(); + +public: + String get_configuration_warning() const; + + ShaderGlobalsOverride(); +}; + +#endif // SHADER_GLOBALS_OVERRIDE_H diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index 7c847095e1..7c847095e1 100755..100644 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp diff --git a/scene/main/timer.h b/scene/main/timer.h index 044566738e..044566738e 100755..100644 --- a/scene/main/timer.h +++ b/scene/main/timer.h diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 8ef3bdd04e..51dd22db81 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -32,14 +32,14 @@ #include "core/core_string_names.h" #include "core/debugger/engine_debugger.h" -#include "core/os/input.h" +#include "core/input/input_filter.h" #include "core/os/os.h" #include "core/project_settings.h" #include "scene/2d/collision_object_2d.h" -#include "scene/3d/camera.h" -#include "scene/3d/collision_object.h" -#include "scene/3d/listener.h" -#include "scene/3d/spatial.h" +#include "scene/3d/camera_3d.h" +#include "scene/3d/collision_object_3d.h" +#include "scene/3d/listener_3d.h" +#include "scene/3d/node_3d.h" #include "scene/3d/world_environment.h" #include "scene/gui/control.h" #include "scene/gui/label.h" @@ -49,9 +49,11 @@ #include "scene/gui/popup_menu.h" #include "scene/main/canvas_layer.h" #include "scene/main/timer.h" +#include "scene/main/window.h" #include "scene/resources/mesh.h" #include "scene/scene_string_names.h" -#include "servers/physics_2d_server.h" +#include "servers/display_server.h" +#include "servers/physics_server_2d.h" void ViewportTexture::setup_local_to_scene() { @@ -59,7 +61,7 @@ void ViewportTexture::setup_local_to_scene() { vp->viewport_textures.erase(this); } - vp = NULL; + vp = nullptr; Node *local_scene = get_local_scene(); if (!local_scene) { @@ -76,11 +78,11 @@ void ViewportTexture::setup_local_to_scene() { vp->viewport_textures.insert(this); if (proxy_ph.is_valid()) { - VS::get_singleton()->texture_proxy_update(proxy, vp->texture_rid); - VS::get_singleton()->free(proxy_ph); + RS::get_singleton()->texture_proxy_update(proxy, vp->texture_rid); + RS::get_singleton()->free(proxy_ph); } else { ERR_FAIL_COND(proxy.is_valid()); //should be invalid - proxy = VS::get_singleton()->texture_proxy_create(vp->texture_rid); + proxy = RS::get_singleton()->texture_proxy_create(vp->texture_rid); } } @@ -120,8 +122,8 @@ RID ViewportTexture::get_rid() const { //ERR_FAIL_COND_V_MSG(!vp, RID(), "Viewport Texture must be set to use it."); if (proxy.is_null()) { - proxy_ph = VS::get_singleton()->texture_2d_placeholder_create(); - proxy = VS::get_singleton()->texture_proxy_create(proxy_ph); + proxy_ph = RS::get_singleton()->texture_2d_placeholder_create(); + proxy = RS::get_singleton()->texture_proxy_create(proxy_ph); } return proxy; } @@ -133,7 +135,7 @@ bool ViewportTexture::has_alpha() const { Ref<Image> ViewportTexture::get_data() const { ERR_FAIL_COND_V_MSG(!vp, Ref<Image>(), "Viewport Texture must be set to use it."); - return VS::get_singleton()->texture_2d_get(vp->texture_rid); + return RS::get_singleton()->texture_2d_get(vp->texture_rid); } void ViewportTexture::_bind_methods() { @@ -141,12 +143,12 @@ void ViewportTexture::_bind_methods() { ClassDB::bind_method(D_METHOD("set_viewport_path_in_scene", "path"), &ViewportTexture::set_viewport_path_in_scene); ClassDB::bind_method(D_METHOD("get_viewport_path_in_scene"), &ViewportTexture::get_viewport_path_in_scene); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "viewport_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Viewport", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT), "set_viewport_path_in_scene", "get_viewport_path_in_scene"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "viewport_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "SubViewport", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT), "set_viewport_path_in_scene", "get_viewport_path_in_scene"); } ViewportTexture::ViewportTexture() { - vp = NULL; + vp = nullptr; set_local_to_scene(true); } @@ -157,18 +159,18 @@ ViewportTexture::~ViewportTexture() { } if (proxy_ph.is_valid()) { - VS::get_singleton()->free(proxy_ph); + RS::get_singleton()->free(proxy_ph); } if (proxy.is_valid()) { - VS::get_singleton()->free(proxy); + RS::get_singleton()->free(proxy); } } ///////////////////////////////////// -class TooltipPanel : public PanelContainer { +class TooltipPanel : public PopupPanel { - GDCLASS(TooltipPanel, PanelContainer); + GDCLASS(TooltipPanel, PopupPanel); public: TooltipPanel(){}; @@ -184,39 +186,25 @@ public: Viewport::GUI::GUI() { + embed_subwindows_hint = false; + embedding_subwindows = false; + dragging = false; - mouse_focus = NULL; - mouse_click_grabber = NULL; + mouse_focus = nullptr; + forced_mouse_focus = false; + mouse_click_grabber = nullptr; mouse_focus_mask = 0; - key_focus = NULL; - mouse_over = NULL; + key_focus = nullptr; + mouse_over = nullptr; + drag_mouse_over = nullptr; - tooltip = NULL; - tooltip_popup = NULL; - tooltip_label = NULL; - subwindow_visibility_dirty = false; - subwindow_order_dirty = false; + tooltip = nullptr; + tooltip_popup = nullptr; + tooltip_label = nullptr; } ///////////////////////////////////// -void Viewport::_update_stretch_transform() { - - if (size_override_stretch && size_override) { - - stretch_transform = Transform2D(); - Size2 scale = size / (size_override_size + size_override_margin * 2); - stretch_transform.scale(scale); - stretch_transform.elements[2] = size_override_margin * scale; - - } else { - - stretch_transform = Transform2D(); - } - - _update_global_transform(); -} - void Viewport::update_worlds() { if (!is_inside_tree()) @@ -230,7 +218,7 @@ void Viewport::update_worlds() { find_world()->_update(get_tree()->get_frame()); } -void Viewport::_collision_object_input_event(CollisionObject *p_object, Camera *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) { +void Viewport::_collision_object_input_event(CollisionObject3D *p_object, Camera3D *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) { Transform object_transform = p_object->get_global_transform(); Transform camera_transform = p_camera->get_global_transform(); @@ -249,6 +237,191 @@ void Viewport::_collision_object_input_event(CollisionObject *p_object, Camera * physics_last_id = id; } +void Viewport::_sub_window_update_order() { + + for (int i = 0; i < gui.sub_windows.size(); i++) { + RS::get_singleton()->canvas_item_set_draw_index(gui.sub_windows[i].canvas_item, i); + } +} + +void Viewport::_sub_window_register(Window *p_window) { + + ERR_FAIL_COND(!is_inside_tree()); + for (int i = 0; i < gui.sub_windows.size(); i++) { + ERR_FAIL_COND(gui.sub_windows[i].window == p_window); + } + + if (gui.sub_windows.size() == 0) { + subwindow_canvas = RS::get_singleton()->canvas_create(); + RS::get_singleton()->viewport_attach_canvas(viewport, subwindow_canvas); + RS::get_singleton()->viewport_set_canvas_stacking(viewport, subwindow_canvas, SUBWINDOW_CANVAS_LAYER, 0); + } + SubWindow sw; + sw.canvas_item = RS::get_singleton()->canvas_item_create(); + RS::get_singleton()->canvas_item_set_parent(sw.canvas_item, subwindow_canvas); + sw.window = p_window; + gui.sub_windows.push_back(sw); + + _sub_window_grab_focus(p_window); + + RenderingServer::get_singleton()->viewport_set_parent_viewport(p_window->viewport, viewport); +} + +void Viewport::_sub_window_update(Window *p_window) { + + int index = -1; + for (int i = 0; i < gui.sub_windows.size(); i++) { + if (gui.sub_windows[i].window == p_window) { + index = i; + break; + } + } + + ERR_FAIL_COND(index == -1); + + const SubWindow &sw = gui.sub_windows[index]; + + Transform2D pos; + pos.set_origin(p_window->get_position()); + RS::get_singleton()->canvas_item_clear(sw.canvas_item); + Rect2i r = Rect2i(p_window->get_position(), sw.window->get_size()); + + if (!p_window->get_flag(Window::FLAG_BORDERLESS)) { + Ref<StyleBox> panel = p_window->get_theme_stylebox("panel_window"); + panel->draw(sw.canvas_item, r); + + // Draw the title bar text. + Ref<Font> title_font = p_window->get_theme_font("title_font"); + Color title_color = p_window->get_theme_color("title_color"); + int title_height = p_window->get_theme_constant("title_height"); + int font_height = title_font->get_height() - title_font->get_descent() * 2; + int x = (r.size.width - title_font->get_string_size(p_window->get_title()).x) / 2; + int y = (-title_height + font_height) / 2; + + int close_h_ofs = p_window->get_theme_constant("close_h_ofs"); + int close_v_ofs = p_window->get_theme_constant("close_v_ofs"); + + title_font->draw(sw.canvas_item, r.position + Point2(x, y), p_window->get_title(), title_color, r.size.width - panel->get_minimum_size().x - close_h_ofs); + + bool hl = gui.subwindow_focused == sw.window && gui.subwindow_drag == SUB_WINDOW_DRAG_CLOSE && gui.subwindow_drag_close_inside; + + Ref<Texture2D> close_icon = p_window->get_theme_icon(hl ? "close_highlight" : "close"); + close_icon->draw(sw.canvas_item, r.position + Vector2(r.size.width - close_h_ofs, -close_v_ofs)); + } + + RS::get_singleton()->canvas_item_add_texture_rect(sw.canvas_item, r, sw.window->get_texture()->get_rid()); +} + +void Viewport::_sub_window_grab_focus(Window *p_window) { + + if (p_window == nullptr) { + //release current focus + if (gui.subwindow_focused) { + gui.subwindow_focused->_event_callback(DisplayServer::WINDOW_EVENT_FOCUS_OUT); + gui.subwindow_focused = nullptr; + gui.subwindow_drag = SUB_WINDOW_DRAG_DISABLED; + } + + Window *this_window = Object::cast_to<Window>(this); + if (this_window) { + this_window->_event_callback(DisplayServer::WINDOW_EVENT_FOCUS_IN); + } + + return; + } + + int index = -1; + for (int i = 0; i < gui.sub_windows.size(); i++) { + if (gui.sub_windows[i].window == p_window) { + index = i; + break; + } + } + + ERR_FAIL_COND(index == -1); + + if (p_window->get_flag(Window::FLAG_NO_FOCUS)) { + //can only move to foreground, but no focus granted + SubWindow sw = gui.sub_windows[index]; + gui.sub_windows.remove(index); + gui.sub_windows.push_back(sw); + index = gui.sub_windows.size() - 1; + _sub_window_update_order(); + return; //i guess not... + } + + if (gui.subwindow_focused) { + if (gui.subwindow_focused == p_window) { + return; //nothing to do + } + gui.subwindow_focused->_event_callback(DisplayServer::WINDOW_EVENT_FOCUS_OUT); + gui.subwindow_drag = SUB_WINDOW_DRAG_DISABLED; + } else { + Window *this_window = Object::cast_to<Window>(this); + if (this_window) { + this_window->_event_callback(DisplayServer::WINDOW_EVENT_FOCUS_OUT); + } + } + + Window *old_focus = gui.subwindow_focused; + + gui.subwindow_focused = p_window; + + gui.subwindow_focused->_event_callback(DisplayServer::WINDOW_EVENT_FOCUS_IN); + + { //move to foreground + SubWindow sw = gui.sub_windows[index]; + gui.sub_windows.remove(index); + gui.sub_windows.push_back(sw); + index = gui.sub_windows.size() - 1; + _sub_window_update_order(); + } + + if (old_focus) { + _sub_window_update(old_focus); + } + + _sub_window_update(p_window); +} + +void Viewport::_sub_window_remove(Window *p_window) { + + for (int i = 0; i < gui.sub_windows.size(); i++) { + if (gui.sub_windows[i].window == p_window) { + RS::get_singleton()->free(gui.sub_windows[i].canvas_item); + gui.sub_windows.remove(i); + break; + } + } + + if (gui.sub_windows.size() == 0) { + RS::get_singleton()->free(subwindow_canvas); + subwindow_canvas = RID(); + } + + if (gui.subwindow_focused == p_window) { + Window *parent_visible = p_window->get_parent_visible_window(); + + gui.subwindow_drag = SUB_WINDOW_DRAG_DISABLED; + + gui.subwindow_focused->_event_callback(DisplayServer::WINDOW_EVENT_FOCUS_OUT); + + if (parent_visible && parent_visible != this) { + + gui.subwindow_focused = parent_visible; + gui.subwindow_focused->_event_callback(DisplayServer::WINDOW_EVENT_FOCUS_IN); + } else { + gui.subwindow_focused = nullptr; + Window *this_window = Object::cast_to<Window>(this); + if (this_window) { + this_window->_event_callback(DisplayServer::WINDOW_EVENT_FOCUS_IN); + } + } + } + + RenderingServer::get_singleton()->viewport_set_parent_viewport(p_window->viewport, p_window->parent ? p_window->parent->viewport : RID()); +} + void Viewport::_own_world_changed() { ERR_FAIL_COND(world.is_null()); ERR_FAIL_COND(own_world.is_null()); @@ -264,7 +437,7 @@ void Viewport::_own_world_changed() { } if (is_inside_tree()) { - VisualServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); + RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); } _update_listener(); @@ -276,16 +449,18 @@ void Viewport::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { + gui.embedding_subwindows = gui.embed_subwindows_hint; + if (get_parent()) { parent = get_parent()->get_viewport(); - VisualServer::get_singleton()->viewport_set_parent_viewport(viewport, parent->get_viewport_rid()); + RenderingServer::get_singleton()->viewport_set_parent_viewport(viewport, parent->get_viewport_rid()); } else { - parent = NULL; + parent = nullptr; } current_canvas = find_world_2d()->get_canvas(); - VisualServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); - VisualServer::get_singleton()->viewport_attach_canvas(viewport, current_canvas); + RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); + RenderingServer::get_singleton()->viewport_attach_canvas(viewport, current_canvas); _update_listener(); _update_listener_2d(); @@ -295,30 +470,29 @@ void Viewport::_notification(int p_what) { add_to_group("_viewports"); if (get_tree()->is_debugging_collisions_hint()) { //2D - Physics2DServer::get_singleton()->space_set_debug_contacts(find_world_2d()->get_space(), get_tree()->get_collision_debug_contact_count()); - contact_2d_debug = VisualServer::get_singleton()->canvas_item_create(); - VisualServer::get_singleton()->canvas_item_set_parent(contact_2d_debug, find_world_2d()->get_canvas()); + PhysicsServer2D::get_singleton()->space_set_debug_contacts(find_world_2d()->get_space(), get_tree()->get_collision_debug_contact_count()); + contact_2d_debug = RenderingServer::get_singleton()->canvas_item_create(); + RenderingServer::get_singleton()->canvas_item_set_parent(contact_2d_debug, find_world_2d()->get_canvas()); //3D - PhysicsServer::get_singleton()->space_set_debug_contacts(find_world()->get_space(), get_tree()->get_collision_debug_contact_count()); - contact_3d_debug_multimesh = VisualServer::get_singleton()->multimesh_create(); - VisualServer::get_singleton()->multimesh_allocate(contact_3d_debug_multimesh, get_tree()->get_collision_debug_contact_count(), VS::MULTIMESH_TRANSFORM_3D, true); - VisualServer::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh, 0); - VisualServer::get_singleton()->multimesh_set_mesh(contact_3d_debug_multimesh, get_tree()->get_debug_contact_mesh()->get_rid()); - contact_3d_debug_instance = VisualServer::get_singleton()->instance_create(); - VisualServer::get_singleton()->instance_set_base(contact_3d_debug_instance, contact_3d_debug_multimesh); - VisualServer::get_singleton()->instance_set_scenario(contact_3d_debug_instance, find_world()->get_scenario()); - //VisualServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance, VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS, true); - } - - VS::get_singleton()->viewport_set_active(viewport, true); + PhysicsServer3D::get_singleton()->space_set_debug_contacts(find_world()->get_space(), get_tree()->get_collision_debug_contact_count()); + contact_3d_debug_multimesh = RenderingServer::get_singleton()->multimesh_create(); + RenderingServer::get_singleton()->multimesh_allocate(contact_3d_debug_multimesh, get_tree()->get_collision_debug_contact_count(), RS::MULTIMESH_TRANSFORM_3D, true); + RenderingServer::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh, 0); + RenderingServer::get_singleton()->multimesh_set_mesh(contact_3d_debug_multimesh, get_tree()->get_debug_contact_mesh()->get_rid()); + contact_3d_debug_instance = RenderingServer::get_singleton()->instance_create(); + RenderingServer::get_singleton()->instance_set_base(contact_3d_debug_instance, contact_3d_debug_multimesh); + RenderingServer::get_singleton()->instance_set_scenario(contact_3d_debug_instance, find_world()->get_scenario()); + //RenderingServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance, RS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS, true); + } + } break; case NOTIFICATION_READY: { #ifndef _3D_DISABLED if (listeners.size() && !listener) { - Listener *first = NULL; - for (Set<Listener *>::Element *E = listeners.front(); E; E = E->next()) { + Listener3D *first = nullptr; + for (Set<Listener3D *>::Element *E = listeners.front(); E; E = E->next()) { - if (first == NULL || first->is_greater_than(E->get())) { + if (first == nullptr || first->is_greater_than(E->get())) { first = E->get(); } } @@ -329,10 +503,10 @@ void Viewport::_notification(int p_what) { if (cameras.size() && !camera) { //there are cameras but no current camera, pick first in tree and make it current - Camera *first = NULL; - for (Set<Camera *>::Element *E = cameras.front(); E; E = E->next()) { + Camera3D *first = nullptr; + for (Set<Camera3D *>::Element *E = cameras.front(); E; E = E->next()) { - if (first == NULL || first->is_greater_than(E->get())) { + if (first == nullptr || first->is_greater_than(E->get())) { first = E->get(); } } @@ -353,24 +527,24 @@ void Viewport::_notification(int p_what) { if (world_2d.is_valid()) world_2d->_remove_viewport(this); - VisualServer::get_singleton()->viewport_set_scenario(viewport, RID()); - // SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); - VisualServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas); + RenderingServer::get_singleton()->viewport_set_scenario(viewport, RID()); + RenderingServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas); if (contact_2d_debug.is_valid()) { - VisualServer::get_singleton()->free(contact_2d_debug); + RenderingServer::get_singleton()->free(contact_2d_debug); contact_2d_debug = RID(); } if (contact_3d_debug_multimesh.is_valid()) { - VisualServer::get_singleton()->free(contact_3d_debug_multimesh); - VisualServer::get_singleton()->free(contact_3d_debug_instance); + RenderingServer::get_singleton()->free(contact_3d_debug_multimesh); + RenderingServer::get_singleton()->free(contact_3d_debug_instance); contact_3d_debug_instance = RID(); contact_3d_debug_multimesh = RID(); } remove_from_group("_viewports"); - VS::get_singleton()->viewport_set_active(viewport, false); + RS::get_singleton()->viewport_set_active(viewport, false); + RenderingServer::get_singleton()->viewport_set_parent_viewport(viewport, RID()); } break; case NOTIFICATION_INTERNAL_PROCESS: { @@ -387,36 +561,36 @@ void Viewport::_notification(int p_what) { if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) { - VisualServer::get_singleton()->canvas_item_clear(contact_2d_debug); - VisualServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug, 0xFFFFF); //very high index + RenderingServer::get_singleton()->canvas_item_clear(contact_2d_debug); + RenderingServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug, 0xFFFFF); //very high index - Vector<Vector2> points = Physics2DServer::get_singleton()->space_get_contacts(find_world_2d()->get_space()); - int point_count = Physics2DServer::get_singleton()->space_get_contact_count(find_world_2d()->get_space()); + Vector<Vector2> points = PhysicsServer2D::get_singleton()->space_get_contacts(find_world_2d()->get_space()); + int point_count = PhysicsServer2D::get_singleton()->space_get_contact_count(find_world_2d()->get_space()); Color ccol = get_tree()->get_debug_collision_contact_color(); for (int i = 0; i < point_count; i++) { - VisualServer::get_singleton()->canvas_item_add_rect(contact_2d_debug, Rect2(points[i] - Vector2(2, 2), Vector2(5, 5)), ccol); + RenderingServer::get_singleton()->canvas_item_add_rect(contact_2d_debug, Rect2(points[i] - Vector2(2, 2), Vector2(5, 5)), ccol); } } if (get_tree()->is_debugging_collisions_hint() && contact_3d_debug_multimesh.is_valid()) { - Vector<Vector3> points = PhysicsServer::get_singleton()->space_get_contacts(find_world()->get_space()); - int point_count = PhysicsServer::get_singleton()->space_get_contact_count(find_world()->get_space()); + Vector<Vector3> points = PhysicsServer3D::get_singleton()->space_get_contacts(find_world()->get_space()); + int point_count = PhysicsServer3D::get_singleton()->space_get_contact_count(find_world()->get_space()); - VS::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh, point_count); + RS::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh, point_count); } - if (physics_object_picking && (to_screen_rect == Rect2() || Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED)) { + if (physics_object_picking && (to_screen_rect == Rect2i() || InputFilter::get_singleton()->get_mouse_mode() != InputFilter::MOUSE_MODE_CAPTURED)) { #ifndef _3D_DISABLED Vector2 last_pos(1e20, 1e20); - CollisionObject *last_object = NULL; + CollisionObject3D *last_object = nullptr; ObjectID last_id; #endif - PhysicsDirectSpaceState::RayResult result; - Physics2DDirectSpaceState *ss2d = Physics2DServer::get_singleton()->space_get_direct_state(find_world_2d()->get_space()); + PhysicsDirectSpaceState3D::RayResult result; + PhysicsDirectSpaceState2D *ss2d = PhysicsServer2D::get_singleton()->space_get_direct_state(find_world_2d()->get_space()); if (physics_has_last_mousepos) { // if no mouse event exists, create a motion one. This is necessary because objects or camera may have moved. @@ -433,6 +607,7 @@ void Viewport::_notification(int p_what) { if (!has_mouse_event) { Ref<InputEventMouseMotion> mm; mm.instance(); + mm->set_device(InputEvent::DEVICE_ID_INTERNAL); mm->set_global_position(physics_last_mousepos); mm->set_position(physics_last_mousepos); @@ -522,7 +697,7 @@ void Viewport::_notification(int p_what) { uint64_t frame = get_tree()->get_frame(); - Physics2DDirectSpaceState::ShapeResult res[64]; + PhysicsDirectSpaceState2D::ShapeResult res[64]; for (Set<CanvasLayer *>::Element *E = canvas_layers.front(); E; E = E->next()) { Transform2D canvas_transform; ObjectID canvas_layer_id; @@ -597,7 +772,7 @@ void Viewport::_notification(int p_what) { if (physics_object_capture.is_valid()) { - CollisionObject *co = Object::cast_to<CollisionObject>(ObjectDB::get_instance(physics_object_capture)); + CollisionObject3D *co = Object::cast_to<CollisionObject3D>(ObjectDB::get_instance(physics_object_capture)); if (co && camera) { _collision_object_input_event(co, camera, ev, Vector3(), Vector3(), 0); captured = true; @@ -630,14 +805,14 @@ void Viewport::_notification(int p_what) { Vector3 from = camera->project_ray_origin(pos); Vector3 dir = camera->project_ray_normal(pos); - PhysicsDirectSpaceState *space = PhysicsServer::get_singleton()->space_get_direct_state(find_world()->get_space()); + PhysicsDirectSpaceState3D *space = PhysicsServer3D::get_singleton()->space_get_direct_state(find_world()->get_space()); if (space) { bool col = space->intersect_ray(from, from + dir * 10000, result, Set<RID>(), 0xFFFFFFFF, true, true, true); ObjectID new_collider; if (col) { - CollisionObject *co = Object::cast_to<CollisionObject>(result.collider); + CollisionObject3D *co = Object::cast_to<CollisionObject3D>(result.collider); if (co) { _collision_object_input_event(co, camera, ev, result.position, result.normal, result.shape); @@ -654,7 +829,7 @@ void Viewport::_notification(int p_what) { if (physics_object_over.is_valid()) { - CollisionObject *co = Object::cast_to<CollisionObject>(ObjectDB::get_instance(physics_object_over)); + CollisionObject3D *co = Object::cast_to<CollisionObject3D>(ObjectDB::get_instance(physics_object_over)); if (co) { co->_mouse_exit(); } @@ -662,7 +837,7 @@ void Viewport::_notification(int p_what) { if (new_collider.is_valid()) { - CollisionObject *co = Object::cast_to<CollisionObject>(ObjectDB::get_instance(new_collider)); + CollisionObject3D *co = Object::cast_to<CollisionObject3D>(ObjectDB::get_instance(new_collider)); if (co) { co->_mouse_enter(); } @@ -680,13 +855,12 @@ void Viewport::_notification(int p_what) { } } break; - case SceneTree::NOTIFICATION_WM_MOUSE_EXIT: - case SceneTree::NOTIFICATION_WM_FOCUS_OUT: { + case NOTIFICATION_WM_MOUSE_EXIT: + case NOTIFICATION_WM_FOCUS_OUT: { _drop_physics_mouseover(); - if (gui.mouse_focus) { - //if mouse is being pressed, send a release event + if (gui.mouse_focus && !gui.forced_mouse_focus) { _drop_mouse_focus(); } } break; @@ -698,16 +872,6 @@ RID Viewport::get_viewport_rid() const { return viewport; } -void Viewport::set_use_arvr(bool p_use_arvr) { - arvr = p_use_arvr; - - VS::get_singleton()->viewport_set_use_arvr(viewport, arvr); -} - -bool Viewport::use_arvr() { - return arvr; -} - void Viewport::update_canvas_items() { if (!is_inside_tree()) return; @@ -715,48 +879,57 @@ void Viewport::update_canvas_items() { _update_canvas_items(this); } -void Viewport::set_size(const Size2 &p_size) { +void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, const Transform2D &p_stretch_transform, bool p_allocated) { - if (size == p_size.floor()) + if (size == p_size && size_allocated == p_allocated && stretch_transform == p_stretch_transform && p_size_2d_override == size_2d_override && to_screen_rect != p_to_screen_rect) return; - size = p_size.floor(); - VS::get_singleton()->viewport_set_size(viewport, size.width, size.height); - _update_stretch_transform(); + size = p_size; + size_allocated = p_allocated; + size_2d_override = p_size_2d_override; + stretch_transform = p_stretch_transform; + to_screen_rect = p_to_screen_rect; + + if (p_allocated) { + RS::get_singleton()->viewport_set_size(viewport, size.width, size.height); + } else { + RS::get_singleton()->viewport_set_size(viewport, 0, 0); + } + _update_global_transform(); + + update_canvas_items(); emit_signal("size_changed"); } +Size2i Viewport::_get_size() const { + return size; +} +Size2i Viewport::_get_size_2d_override() const { + return size_2d_override; +} +bool Viewport::_is_size_allocated() const { + return size_allocated; +} + Rect2 Viewport::get_visible_rect() const { Rect2 r; if (size == Size2()) { - r = Rect2(Point2(), OS::get_singleton()->get_window_size()); + r = Rect2(Point2(), DisplayServer::get_singleton()->window_get_size()); } else { r = Rect2(Point2(), size); } - if (size_override) { - r.size = size_override_size; + if (size_2d_override != Size2i()) { + r.size = size_2d_override; } return r; } -Size2 Viewport::get_size() const { - - return size; -} - void Viewport::_update_listener() { - /* - if (is_inside_tree() && audio_listener && (camera || listener) && (!get_parent() || (Object::cast_to<Control>(get_parent()) && Object::cast_to<Control>(get_parent())->is_visible_in_tree()))) { - SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, find_world()->get_sound_space()); - } else { - SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); - } -*/ } void Viewport::_update_listener_2d() { @@ -805,9 +978,9 @@ void Viewport::enable_canvas_transform_override(bool p_enable) { override_canvas_transform = p_enable; if (p_enable) { - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, find_world_2d()->get_canvas(), canvas_transform_override); + RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, find_world_2d()->get_canvas(), canvas_transform_override); } else { - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, find_world_2d()->get_canvas(), canvas_transform); + RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, find_world_2d()->get_canvas(), canvas_transform); } } @@ -822,7 +995,7 @@ void Viewport::set_canvas_transform_override(const Transform2D &p_transform) { canvas_transform_override = p_transform; if (override_canvas_transform) { - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, find_world_2d()->get_canvas(), canvas_transform_override); + RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, find_world_2d()->get_canvas(), canvas_transform_override); } } @@ -835,7 +1008,7 @@ void Viewport::set_canvas_transform(const Transform2D &p_transform) { canvas_transform = p_transform; if (!override_canvas_transform) { - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, find_world_2d()->get_canvas(), canvas_transform); + RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, find_world_2d()->get_canvas(), canvas_transform); } } @@ -848,7 +1021,7 @@ void Viewport::_update_global_transform() { Transform2D sxform = stretch_transform * global_canvas_transform; - VisualServer::get_singleton()->viewport_set_global_canvas_transform(viewport, sxform); + RenderingServer::get_singleton()->viewport_set_global_canvas_transform(viewport, sxform); } void Viewport::set_global_canvas_transform(const Transform2D &p_transform) { @@ -864,14 +1037,9 @@ Transform2D Viewport::get_global_canvas_transform() const { } void Viewport::_listener_transform_changed_notify() { - -#ifndef _3D_DISABLED -//if (listener) -// SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, listener->get_listener_transform()); -#endif } -void Viewport::_listener_set(Listener *p_listener) { +void Viewport::_listener_set(Listener3D *p_listener) { #ifndef _3D_DISABLED @@ -885,38 +1053,38 @@ void Viewport::_listener_set(Listener *p_listener) { #endif } -bool Viewport::_listener_add(Listener *p_listener) { +bool Viewport::_listener_add(Listener3D *p_listener) { listeners.insert(p_listener); return listeners.size() == 1; } -void Viewport::_listener_remove(Listener *p_listener) { +void Viewport::_listener_remove(Listener3D *p_listener) { listeners.erase(p_listener); if (listener == p_listener) { - listener = NULL; + listener = nullptr; } } #ifndef _3D_DISABLED -void Viewport::_listener_make_next_current(Listener *p_exclude) { +void Viewport::_listener_make_next_current(Listener3D *p_exclude) { if (listeners.size() > 0) { - for (Set<Listener *>::Element *E = listeners.front(); E; E = E->next()) { + for (Set<Listener3D *>::Element *E = listeners.front(); E; E = E->next()) { if (p_exclude == E->get()) continue; if (!E->get()->is_inside_tree()) continue; - if (listener != NULL) + if (listener != nullptr) return; E->get()->make_current(); } } else { // Attempt to reset listener to the camera position - if (camera != NULL) { + if (camera != nullptr) { _update_listener(); _camera_transform_changed_notify(); } @@ -927,13 +1095,10 @@ void Viewport::_listener_make_next_current(Listener *p_exclude) { void Viewport::_camera_transform_changed_notify() { #ifndef _3D_DISABLED -// If there is an active listener in the scene, it takes priority over the camera -// if (camera && !listener) -// SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, camera->get_camera_transform()); #endif } -void Viewport::_camera_set(Camera *p_camera) { +void Viewport::_camera_set(Camera3D *p_camera) { #ifndef _3D_DISABLED @@ -941,18 +1106,20 @@ void Viewport::_camera_set(Camera *p_camera) { return; if (camera) { - camera->notification(Camera::NOTIFICATION_LOST_CURRENT); + camera->notification(Camera3D::NOTIFICATION_LOST_CURRENT); } + camera = p_camera; + if (!camera_override) { if (camera) - VisualServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera()); + RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera()); else - VisualServer::get_singleton()->viewport_attach_camera(viewport, RID()); + RenderingServer::get_singleton()->viewport_attach_camera(viewport, RID()); } if (camera) { - camera->notification(Camera::NOTIFICATION_BECAME_CURRENT); + camera->notification(Camera3D::NOTIFICATION_BECAME_CURRENT); } _update_listener(); @@ -960,31 +1127,31 @@ void Viewport::_camera_set(Camera *p_camera) { #endif } -bool Viewport::_camera_add(Camera *p_camera) { +bool Viewport::_camera_add(Camera3D *p_camera) { cameras.insert(p_camera); return cameras.size() == 1; } -void Viewport::_camera_remove(Camera *p_camera) { +void Viewport::_camera_remove(Camera3D *p_camera) { cameras.erase(p_camera); if (camera == p_camera) { - camera->notification(Camera::NOTIFICATION_LOST_CURRENT); - camera = NULL; + camera->notification(Camera3D::NOTIFICATION_LOST_CURRENT); + camera = nullptr; } } #ifndef _3D_DISABLED -void Viewport::_camera_make_next_current(Camera *p_exclude) { +void Viewport::_camera_make_next_current(Camera3D *p_exclude) { - for (Set<Camera *>::Element *E = cameras.front(); E; E = E->next()) { + for (Set<Camera3D *>::Element *E = cameras.front(); E; E = E->next()) { if (p_exclude == E->get()) continue; if (!E->get()->is_inside_tree()) continue; - if (camera != NULL) + if (camera != nullptr) return; E->get()->make_current(); @@ -1005,7 +1172,7 @@ void Viewport::_canvas_layer_remove(CanvasLayer *p_canvas_layer) { void Viewport::set_transparent_background(bool p_enable) { transparent_bg = p_enable; - VS::get_singleton()->viewport_set_transparent_background(viewport, p_enable); + RS::get_singleton()->viewport_set_transparent_background(viewport, p_enable); } bool Viewport::has_transparent_background() const { @@ -1024,7 +1191,7 @@ void Viewport::set_world_2d(const Ref<World2D> &p_world_2d) { if (is_inside_tree()) { find_world_2d()->_remove_viewport(this); - VisualServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas); + RenderingServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas); } if (p_world_2d.is_valid()) @@ -1038,7 +1205,7 @@ void Viewport::set_world_2d(const Ref<World2D> &p_world_2d) { if (is_inside_tree()) { current_canvas = find_world_2d()->get_canvas(); - VisualServer::get_singleton()->viewport_attach_canvas(viewport, current_canvas); + RenderingServer::get_singleton()->viewport_attach_canvas(viewport, current_canvas); find_world_2d()->_register_viewport(this, Rect2()); } } @@ -1060,17 +1227,20 @@ void Viewport::_propagate_enter_world(Node *p_node) { if (!p_node->is_inside_tree()) //may not have entered scene yet return; - if (Object::cast_to<Spatial>(p_node) || Object::cast_to<WorldEnvironment>(p_node)) { - - p_node->notification(Spatial::NOTIFICATION_ENTER_WORLD); +#ifndef _3D_DISABLED + if (Object::cast_to<Node3D>(p_node) || Object::cast_to<WorldEnvironment>(p_node)) { + p_node->notification(Node3D::NOTIFICATION_ENTER_WORLD); } else { +#endif Viewport *v = Object::cast_to<Viewport>(p_node); if (v) { if (v->world.is_valid() || v->own_world.is_valid()) return; } +#ifndef _3D_DISABLED } +#endif } for (int i = 0; i < p_node->get_child_count(); i++) { @@ -1097,17 +1267,20 @@ void Viewport::_propagate_exit_world(Node *p_node) { if (!p_node->is_inside_tree()) //may have exited scene already return; - if (Object::cast_to<Spatial>(p_node) || Object::cast_to<WorldEnvironment>(p_node)) { - - p_node->notification(Spatial::NOTIFICATION_EXIT_WORLD); +#ifndef _3D_DISABLED + if (Object::cast_to<Node3D>(p_node) || Object::cast_to<WorldEnvironment>(p_node)) { + p_node->notification(Node3D::NOTIFICATION_EXIT_WORLD); } else { +#endif Viewport *v = Object::cast_to<Viewport>(p_node); if (v) { if (v->world.is_valid() || v->own_world.is_valid()) return; } +#ifndef _3D_DISABLED } +#endif } for (int i = 0; i < p_node->get_child_count(); i++) { @@ -1116,7 +1289,7 @@ void Viewport::_propagate_exit_world(Node *p_node) { } } -void Viewport::set_world(const Ref<World> &p_world) { +void Viewport::set_world(const Ref<World3D> &p_world) { if (world == p_world) return; @@ -1135,7 +1308,7 @@ void Viewport::set_world(const Ref<World> &p_world) { own_world = world->duplicate(); world->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_changed)); } else { - own_world = Ref<World>(memnew(World)); + own_world = Ref<World3D>(memnew(World3D)); } } @@ -1143,13 +1316,13 @@ void Viewport::set_world(const Ref<World> &p_world) { _propagate_enter_world(this); if (is_inside_tree()) { - VisualServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); + RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); } _update_listener(); } -Ref<World> Viewport::get_world() const { +Ref<World3D> Viewport::get_world() const { return world; } @@ -1159,7 +1332,7 @@ Ref<World2D> Viewport::get_world_2d() const { return world_2d; } -Ref<World> Viewport::find_world() const { +Ref<World3D> Viewport::find_world() const { if (own_world.is_valid()) return own_world; @@ -1168,15 +1341,15 @@ Ref<World> Viewport::find_world() const { else if (parent) return parent->find_world(); else - return Ref<World>(); + return Ref<World3D>(); } -Listener *Viewport::get_listener() const { +Listener3D *Viewport::get_listener() const { return listener; } -Camera *Viewport::get_camera() const { +Camera3D *Viewport::get_camera() const { return camera; } @@ -1188,18 +1361,18 @@ void Viewport::enable_camera_override(bool p_enable) { } if (p_enable) { - camera_override.rid = VisualServer::get_singleton()->camera_create(); + camera_override.rid = RenderingServer::get_singleton()->camera_create(); } else { - VisualServer::get_singleton()->free(camera_override.rid); + RenderingServer::get_singleton()->free(camera_override.rid); camera_override.rid = RID(); } if (p_enable) { - VisualServer::get_singleton()->viewport_attach_camera(viewport, camera_override.rid); + RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera_override.rid); } else if (camera) { - VisualServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera()); + RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera()); } else { - VisualServer::get_singleton()->viewport_attach_camera(viewport, RID()); + RenderingServer::get_singleton()->viewport_attach_camera(viewport, RID()); } #endif } @@ -1211,7 +1384,7 @@ bool Viewport::is_camera_override_enabled() const { void Viewport::set_camera_override_transform(const Transform &p_transform) { if (camera_override) { camera_override.transform = p_transform; - VisualServer::get_singleton()->camera_set_transform(camera_override.rid, p_transform); + RenderingServer::get_singleton()->camera_set_transform(camera_override.rid, p_transform); } } @@ -1234,7 +1407,7 @@ void Viewport::set_camera_override_perspective(float p_fovy_degrees, float p_z_n camera_override.z_far = p_z_far; camera_override.projection = CameraOverrideData::PROJECTION_PERSPECTIVE; - VisualServer::get_singleton()->camera_set_perspective(camera_override.rid, camera_override.fov, camera_override.z_near, camera_override.z_far); + RenderingServer::get_singleton()->camera_set_perspective(camera_override.rid, camera_override.fov, camera_override.z_near, camera_override.z_far); } } @@ -1249,7 +1422,7 @@ void Viewport::set_camera_override_orthogonal(float p_size, float p_z_near, floa camera_override.z_far = p_z_far; camera_override.projection = CameraOverrideData::PROJECTION_ORTHOGONAL; - VisualServer::get_singleton()->camera_set_orthogonal(camera_override.rid, camera_override.size, camera_override.z_near, camera_override.z_far); + RenderingServer::get_singleton()->camera_set_orthogonal(camera_override.rid, camera_override.size, camera_override.z_near, camera_override.z_far); } } @@ -1278,77 +1451,18 @@ void Viewport::_update_canvas_items(Node *p_node) { } } -void Viewport::set_size_override(bool p_enable, const Size2 &p_size, const Vector2 &p_margin) { - - if (size_override == p_enable && p_size == size_override_size) - return; - - size_override = p_enable; - if (p_size.x >= 0 || p_size.y >= 0) { - size_override_size = p_size; - } - size_override_margin = p_margin; - - _update_stretch_transform(); - emit_signal("size_changed"); -} - -Size2 Viewport::get_size_override() const { - - return size_override_size; -} -bool Viewport::is_size_override_enabled() const { - - return size_override; -} -void Viewport::set_size_override_stretch(bool p_enable) { - - if (p_enable == size_override_stretch) - return; - - size_override_stretch = p_enable; - - _update_stretch_transform(); -} - -bool Viewport::is_size_override_stretch_enabled() const { - - return size_override_stretch; -} - -void Viewport::set_update_mode(UpdateMode p_mode) { - - update_mode = p_mode; - VS::get_singleton()->viewport_set_update_mode(viewport, VS::ViewportUpdateMode(p_mode)); -} -Viewport::UpdateMode Viewport::get_update_mode() const { - - return update_mode; -} - Ref<ViewportTexture> Viewport::get_texture() const { return default_texture; } -void Viewport::set_clear_mode(ClearMode p_mode) { - - clear_mode = p_mode; - VS::get_singleton()->viewport_set_clear_mode(viewport, VS::ViewportClearMode(p_mode)); -} - -Viewport::ClearMode Viewport::get_clear_mode() const { - - return clear_mode; -} - void Viewport::set_shadow_atlas_size(int p_size) { if (shadow_atlas_size == p_size) return; shadow_atlas_size = p_size; - VS::get_singleton()->viewport_set_shadow_atlas_size(viewport, p_size); + RS::get_singleton()->viewport_set_shadow_atlas_size(viewport, p_size); } int Viewport::get_shadow_atlas_size() const { @@ -1367,7 +1481,7 @@ void Viewport::set_shadow_atlas_quadrant_subdiv(int p_quadrant, ShadowAtlasQuadr shadow_atlas_quadrant_subdiv[p_quadrant] = p_subdiv; static const int subdiv[SHADOW_ATLAS_QUADRANT_SUBDIV_MAX] = { 0, 1, 4, 16, 64, 256, 1024 }; - VS::get_singleton()->viewport_set_shadow_atlas_quadrant_subdivision(viewport, p_quadrant, subdiv[p_subdiv]); + RS::get_singleton()->viewport_set_shadow_atlas_quadrant_subdivision(viewport, p_quadrant, subdiv[p_subdiv]); } Viewport::ShadowAtlasQuadrantSubdiv Viewport::get_shadow_atlas_quadrant_subdiv(int p_quadrant) const { @@ -1379,7 +1493,7 @@ Transform2D Viewport::_get_input_pre_xform() const { Transform2D pre_xf; - if (to_screen_rect != Rect2()) { + if (to_screen_rect.size.x != 0 && to_screen_rect.size.y != 0) { pre_xf.elements[2] = -to_screen_rect.position; pre_xf.scale(size / to_screen_rect.size); @@ -1388,118 +1502,22 @@ Transform2D Viewport::_get_input_pre_xform() const { return pre_xf; } -Vector2 Viewport::_get_window_offset() const { - - if (get_parent() && get_parent()->has_method("get_global_position")) { - return get_parent()->call("get_global_position"); - } - return Vector2(); -} - Ref<InputEvent> Viewport::_make_input_local(const Ref<InputEvent> &ev) { - Vector2 vp_ofs = _get_window_offset(); Transform2D ai = get_final_transform().affine_inverse() * _get_input_pre_xform(); - return ev->xformed_by(ai, -vp_ofs); -} - -void Viewport::_vp_input_text(const String &p_text) { - - if (gui.key_focus) { - gui.key_focus->call("set_text", p_text); - } -} - -void Viewport::_vp_input(const Ref<InputEvent> &p_ev) { - - if (disable_input) - return; - -#ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { - return; - } -#endif - - if (to_screen_rect == Rect2()) - return; //if render target, can't get input events - - //this one handles system input, p_ev are in system coordinates - //they are converted to viewport coordinates - - Ref<InputEvent> ev = _make_input_local(p_ev); - input(ev); -} - -void Viewport::_vp_unhandled_input(const Ref<InputEvent> &p_ev) { - - if (disable_input) - return; -#ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { - return; - } -#endif - - /* - if (parent_control && !parent_control->is_visible_in_tree()) - return; - */ - - if (to_screen_rect == Rect2()) - return; //if render target, can't get input events - - //this one handles system input, p_ev are in system coordinates - //they are converted to viewport coordinates - - Ref<InputEvent> ev = _make_input_local(p_ev); - unhandled_input(ev); + return ev->xformed_by(ai); } Vector2 Viewport::get_mouse_position() const { - return (get_final_transform().affine_inverse() * _get_input_pre_xform()).xform(Input::get_singleton()->get_mouse_position() - _get_window_offset()); + return gui.last_mouse_pos; } void Viewport::warp_mouse(const Vector2 &p_pos) { Vector2 gpos = (get_final_transform().affine_inverse() * _get_input_pre_xform()).affine_inverse().xform(p_pos); - Input::get_singleton()->warp_mouse_position(gpos); -} - -void Viewport::_gui_prepare_subwindows() { - - if (gui.subwindow_visibility_dirty) { - - gui.subwindows.clear(); - for (List<Control *>::Element *E = gui.all_known_subwindows.front(); E; E = E->next()) { - if (E->get()->is_visible_in_tree()) { - gui.subwindows.push_back(E->get()); - } - } - - gui.subwindow_visibility_dirty = false; - gui.subwindow_order_dirty = true; - } - - _gui_sort_subwindows(); -} - -void Viewport::_gui_sort_subwindows() { - - if (!gui.subwindow_order_dirty) - return; - - gui.modal_stack.sort_custom<Control::CComparator>(); - gui.subwindows.sort_custom<Control::CComparator>(); - - gui.subwindow_order_dirty = false; -} - -void Viewport::_gui_sort_modal_stack() { - - gui.modal_stack.sort_custom<Control::CComparator>(); + InputFilter::get_singleton()->warp_mouse_position(gpos); } void Viewport::_gui_sort_roots() { @@ -1514,12 +1532,12 @@ void Viewport::_gui_sort_roots() { void Viewport::_gui_cancel_tooltip() { - gui.tooltip = NULL; + gui.tooltip = nullptr; gui.tooltip_timer = -1; if (gui.tooltip_popup) { gui.tooltip_popup->queue_delete(); - gui.tooltip_popup = NULL; - gui.tooltip_label = NULL; + gui.tooltip_popup = nullptr; + gui.tooltip_label = nullptr; } } @@ -1557,7 +1575,7 @@ void Viewport::_gui_show_tooltip() { return; } - Control *which = NULL; + Control *which = nullptr; String tooltip = _gui_get_tooltip(gui.tooltip, gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos), &which); tooltip = tooltip.strip_edges(); if (tooltip.length() == 0) @@ -1565,8 +1583,8 @@ void Viewport::_gui_show_tooltip() { if (gui.tooltip_popup) { memdelete(gui.tooltip_popup); - gui.tooltip_popup = NULL; - gui.tooltip_label = NULL; + gui.tooltip_popup = nullptr; + gui.tooltip_label = nullptr; } if (!which) { @@ -1575,47 +1593,49 @@ void Viewport::_gui_show_tooltip() { Control *rp = which; - gui.tooltip_popup = which->make_custom_tooltip(tooltip); - - if (!gui.tooltip_popup) { - gui.tooltip_popup = memnew(TooltipPanel); + Control *base_tooltip = which->make_custom_tooltip(tooltip); + if (!base_tooltip) { gui.tooltip_label = memnew(TooltipLabel); - gui.tooltip_popup->add_child(gui.tooltip_label); - - Ref<StyleBox> ttp = gui.tooltip_label->get_stylebox("panel", "TooltipPanel"); - - gui.tooltip_label->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_LEFT)); - gui.tooltip_label->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_TOP)); - gui.tooltip_label->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, -ttp->get_margin(MARGIN_RIGHT)); - gui.tooltip_label->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, -ttp->get_margin(MARGIN_BOTTOM)); gui.tooltip_label->set_text(tooltip); + base_tooltip = gui.tooltip_label; } + base_tooltip->set_anchors_and_margins_preset(Control::PRESET_WIDE); + + TooltipPanel *panel = memnew(TooltipPanel); + panel->set_transient(false); + panel->set_flag(Window::FLAG_NO_FOCUS, true); + panel->set_wrap_controls(true); + panel->add_child(base_tooltip); + + gui.tooltip_popup = panel; + rp->add_child(gui.tooltip_popup); - gui.tooltip_popup->force_parent_owned(); - gui.tooltip_popup->set_as_toplevel(true); - if (gui.tooltip) // Avoids crash when rapidly switching controls. - gui.tooltip_popup->set_scale(gui.tooltip->get_global_transform().get_scale()); + + //if (gui.tooltip) // Avoids crash when rapidly switching controls. + // gui.tooltip_popup->set_scale(gui.tooltip->get_global_transform().get_scale()); Point2 tooltip_offset = ProjectSettings::get_singleton()->get("display/mouse_cursor/tooltip_position_offset"); - Rect2 r(gui.tooltip_pos + tooltip_offset, gui.tooltip_popup->get_minimum_size()); - Rect2 vr = gui.tooltip_popup->get_viewport_rect(); - if (r.size.x * gui.tooltip_popup->get_scale().x + r.position.x > vr.size.x) - r.position.x = vr.size.x - r.size.x * gui.tooltip_popup->get_scale().x; - else if (r.position.x < 0) - r.position.x = 0; - - if (r.size.y * gui.tooltip_popup->get_scale().y + r.position.y > vr.size.y) - r.position.y = vr.size.y - r.size.y * gui.tooltip_popup->get_scale().y; - else if (r.position.y < 0) - r.position.y = 0; - - gui.tooltip_popup->set_global_position(r.position); + Rect2 r(gui.tooltip_pos + tooltip_offset, gui.tooltip_popup->get_contents_minimum_size()); + + Rect2i vr = gui.tooltip_popup->get_parent_visible_window()->get_usable_parent_rect(); + + if (r.size.x + r.position.x > vr.size.x + vr.position.x) + r.position.x = vr.position.x + vr.size.x - r.size.x; + else if (r.position.x < vr.position.x) + r.position.x = vr.position.x; + + if (r.size.y + r.position.y > vr.size.y + vr.position.y) + r.position.y = vr.position.y + vr.size.y - r.size.y; + else if (r.position.y < vr.position.y) + r.position.y = vr.position.y; + + gui.tooltip_popup->set_position(r.position); gui.tooltip_popup->set_size(r.size); - gui.tooltip_popup->raise(); gui.tooltip_popup->show(); + gui.tooltip_popup->child_controls_changed(); } void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_input) { @@ -1635,7 +1655,7 @@ void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu Ref<InputEventPanGesture> pn = p_input; cant_stop_me_now = pn.is_valid() || cant_stop_me_now; - bool ismouse = ev.is_valid() || Object::cast_to<InputEventMouseMotion>(*p_input) != NULL; + bool ismouse = ev.is_valid() || Object::cast_to<InputEventMouseMotion>(*p_input) != nullptr; CanvasItem *ci = p_control; while (ci) { @@ -1704,26 +1724,7 @@ void Viewport::_gui_call_notification(Control *p_control, int p_what) { } Control *Viewport::_gui_find_control(const Point2 &p_global) { - _gui_prepare_subwindows(); - - for (List<Control *>::Element *E = gui.subwindows.back(); E; E = E->prev()) { - - Control *sw = E->get(); - if (!sw->is_visible_in_tree()) - continue; - - Transform2D xform; - CanvasItem *pci = sw->get_parent_item(); - if (pci) - xform = pci->get_global_transform_with_canvas(); - else - xform = sw->get_canvas_transform(); - - Control *ret = _gui_find_control_at_pos(sw, p_global, xform, gui.focus_inv_xform); - if (ret) - return ret; - } - + //aca va subwindows _gui_sort_roots(); for (List<Control *>::Element *E = gui.roots.back(); E; E = E->prev()) { @@ -1744,25 +1745,23 @@ Control *Viewport::_gui_find_control(const Point2 &p_global) { return ret; } - return NULL; + return nullptr; } Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform) { if (Object::cast_to<Viewport>(p_node)) - return NULL; - - //subwindows first!! + return nullptr; if (!p_node->is_visible()) { //return _find_next_visible_control_at_pos(p_node,p_global,r_inv_xform); - return NULL; //canvas item hidden, discard + return nullptr; //canvas item hidden, discard } Transform2D matrix = p_xform * p_node->get_transform(); // matrix.basis_determinant() == 0.0f implies that node does not exist on scene if (matrix.basis_determinant() == 0.0f) - return NULL; + return nullptr; Control *c = Object::cast_to<Control>(p_node); @@ -1770,9 +1769,6 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_ for (int i = p_node->get_child_count() - 1; i >= 0; i--) { - if (p_node == gui.tooltip_popup) - continue; - CanvasItem *ci = Object::cast_to<CanvasItem>(p_node->get_child(i)); if (!ci || ci->is_set_as_toplevel()) continue; @@ -1784,7 +1780,7 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_ } if (!c) - return NULL; + return nullptr; matrix.affine_invert(); @@ -1793,7 +1789,7 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_ r_inv_xform = matrix; return c; } else - return NULL; + return nullptr; } bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_check) { @@ -1858,39 +1854,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { bool is_handled = false; - _gui_sort_modal_stack(); - while (!gui.modal_stack.empty()) { - - Control *top = gui.modal_stack.back()->get(); - Vector2 pos2 = top->get_global_transform_with_canvas().affine_inverse().xform(mpos); - if (!top->has_point(pos2)) { - - if (top->data.modal_exclusive || top->data.modal_frame == Engine::get_singleton()->get_frames_drawn()) { - //cancel event, sorry, modal exclusive EATS UP ALL - //alternative, you can't pop out a window the same frame it was made modal (fixes many issues) - set_input_as_handled(); - - return; // no one gets the event if exclusive NO ONE - } - - if (mb->get_button_index() == BUTTON_WHEEL_UP || mb->get_button_index() == BUTTON_WHEEL_DOWN || mb->get_button_index() == BUTTON_WHEEL_LEFT || mb->get_button_index() == BUTTON_WHEEL_RIGHT) { - //cancel scroll wheel events, only clicks should trigger focus changes. - set_input_as_handled(); - return; - } - - top->notification(Control::NOTIFICATION_MODAL_CLOSE); - top->_modal_stack_remove(); - top->hide(); - - if (!top->pass_on_modal_close_click()) { - is_handled = true; - } - } else { - break; - } - } - if (is_handled) { set_input_as_handled(); return; @@ -1979,7 +1942,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (gui.drag_preview) { memdelete(gui.drag_preview); - gui.drag_preview = NULL; + gui.drag_preview = nullptr; } _propagate_viewport_notification(this, NOTIFICATION_DRAG_END); //change mouse accordingly @@ -1992,20 +1955,18 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (gui.drag_data.get_type() != Variant::NIL && mb->get_button_index() == BUTTON_LEFT) { - if (gui.mouse_over) { - Size2 pos = mpos; - pos = gui.focus_inv_xform.xform(pos); - - _gui_drop(gui.mouse_over, pos, false); + if (gui.drag_mouse_over) { + _gui_drop(gui.drag_mouse_over, gui.drag_mouse_over_pos, false); } if (gui.drag_preview && mb->get_button_index() == BUTTON_LEFT) { memdelete(gui.drag_preview); - gui.drag_preview = NULL; + gui.drag_preview = nullptr; } gui.drag_data = Variant(); gui.dragging = false; + gui.drag_mouse_over = nullptr; _propagate_viewport_notification(this, NOTIFICATION_DRAG_END); //change mouse accordingly } @@ -2028,7 +1989,8 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { //disable mouse focus if needed before calling input, this makes popups on mouse press event work better, as the release will never be received otherwise if (gui.mouse_focus_mask == 0) { - gui.mouse_focus = NULL; + gui.mouse_focus = nullptr; + gui.forced_mouse_focus = false; } if (mouse_focus && mouse_focus->can_process()) { @@ -2053,7 +2015,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { gui.last_mouse_pos = mpos; - Control *over = NULL; + Control *over = nullptr; // D&D if (!gui.drag_attempted && gui.mouse_focus && mm->get_button_mask() & BUTTON_MASK_LEFT) { @@ -2073,14 +2035,15 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos) - gui.drag_accum); if (gui.drag_data.get_type() != Variant::NIL) { - gui.mouse_focus = NULL; + gui.mouse_focus = nullptr; + gui.forced_mouse_focus = false; gui.mouse_focus_mask = 0; break; } else { - if (gui.drag_preview != NULL) { + if (gui.drag_preview != nullptr) { ERR_PRINT("Don't set a drag preview and return null data. Preview was deleted and drag request ignored."); memdelete(gui.drag_preview); - gui.drag_preview = NULL; + gui.drag_preview = nullptr; } gui.dragging = false; } @@ -2113,45 +2076,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { over = _gui_find_control(mpos); } - if (gui.drag_data.get_type() == Variant::NIL && over && !gui.modal_stack.empty()) { - - Control *top = gui.modal_stack.back()->get(); - - if (over != top && !top->is_a_parent_of(over)) { - - PopupMenu *popup_menu = Object::cast_to<PopupMenu>(top); - MenuButton *popup_menu_parent = NULL; - MenuButton *menu_button = Object::cast_to<MenuButton>(over); - - if (popup_menu) { - popup_menu_parent = Object::cast_to<MenuButton>(popup_menu->get_parent()); - if (!popup_menu_parent) { - // Go through the parents to see if there's a MenuButton at the end. - while (Object::cast_to<PopupMenu>(popup_menu->get_parent())) { - popup_menu = Object::cast_to<PopupMenu>(popup_menu->get_parent()); - } - popup_menu_parent = Object::cast_to<MenuButton>(popup_menu->get_parent()); - } - } - - // If the mouse is over a menu button, this menu will open automatically - // if there is already a pop-up menu open at the same hierarchical level. - if (popup_menu_parent && menu_button && popup_menu_parent->is_switch_on_hover() && - !menu_button->is_disabled() && menu_button->is_switch_on_hover() && - (popup_menu_parent->get_parent()->is_a_parent_of(menu_button) || - menu_button->get_parent()->is_a_parent_of(popup_menu))) { - - popup_menu->notification(Control::NOTIFICATION_MODAL_CLOSE); - popup_menu->_modal_stack_remove(); - popup_menu->hide(); - - menu_button->pressed(); - } else { - over = NULL; //nothing can be found outside the modal stack - } - } - } - if (over != gui.mouse_over) { if (gui.mouse_over) { @@ -2167,103 +2091,195 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { gui.mouse_over = over; - if (gui.drag_preview) { - gui.drag_preview->set_position(mpos); - } + DisplayServer::CursorShape ds_cursor_shape = (DisplayServer::CursorShape)InputFilter::get_singleton()->get_default_cursor_shape(); - if (!over) { - OS::get_singleton()->set_cursor_shape((OS::CursorShape)Input::get_singleton()->get_default_cursor_shape()); - return; - } + if (over) { - Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse(); - Size2 pos = localizer.xform(mpos); - Vector2 speed = localizer.basis_xform(mm->get_speed()); - Vector2 rel = localizer.basis_xform(mm->get_relative()); + Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse(); + Size2 pos = localizer.xform(mpos); + Vector2 speed = localizer.basis_xform(mm->get_speed()); + Vector2 rel = localizer.basis_xform(mm->get_relative()); - mm = mm->xformed_by(Transform2D()); //make a copy + mm = mm->xformed_by(Transform2D()); //make a copy - mm->set_global_position(mpos); - mm->set_speed(speed); - mm->set_relative(rel); + mm->set_global_position(mpos); + mm->set_speed(speed); + mm->set_relative(rel); - if (mm->get_button_mask() == 0) { - //nothing pressed + if (mm->get_button_mask() == 0) { + //nothing pressed - bool can_tooltip = true; + bool can_tooltip = true; - if (!gui.modal_stack.empty()) { - if (gui.modal_stack.back()->get() != over && !gui.modal_stack.back()->get()->is_a_parent_of(over)) - can_tooltip = false; - } + bool is_tooltip_shown = false; - bool is_tooltip_shown = false; + if (gui.tooltip_popup) { + if (can_tooltip && gui.tooltip) { + String tooltip = _gui_get_tooltip(over, gui.tooltip->get_global_transform().xform_inv(mpos)); - if (gui.tooltip_popup) { - if (can_tooltip && gui.tooltip) { - String tooltip = _gui_get_tooltip(over, gui.tooltip->get_global_transform().xform_inv(mpos)); + if (tooltip.length() == 0) + _gui_cancel_tooltip(); + else if (gui.tooltip_label) { + if (tooltip == gui.tooltip_label->get_text()) { + is_tooltip_shown = true; + } + } else { - if (tooltip.length() == 0) - _gui_cancel_tooltip(); - else if (gui.tooltip_label) { - if (tooltip == gui.tooltip_label->get_text()) { - is_tooltip_shown = true; + Variant t = gui.tooltip_popup->call("get_tooltip_text"); + + if (t.get_type() == Variant::STRING) { + if (tooltip == String(t)) { + is_tooltip_shown = true; + } + } else { + is_tooltip_shown = true; //well, nothing to compare against, likely using custom control, so if it changes there is nothing we can do + } } - } else if (tooltip == String(gui.tooltip_popup->call("get_tooltip_text"))) { - is_tooltip_shown = true; - } - } else - _gui_cancel_tooltip(); + } else + _gui_cancel_tooltip(); + } + + if (can_tooltip && !is_tooltip_shown) { + + gui.tooltip = over; + gui.tooltip_pos = over->get_screen_transform().xform(pos); //(parent_xform * get_transform()).affine_inverse().xform(pos); + gui.tooltip_timer = gui.tooltip_delay; + } } - if (can_tooltip && !is_tooltip_shown) { + //pos = gui.focus_inv_xform.xform(pos); + + mm->set_position(pos); - gui.tooltip = over; - gui.tooltip_pos = mpos; //(parent_xform * get_transform()).affine_inverse().xform(pos); - gui.tooltip_timer = gui.tooltip_delay; + Control::CursorShape cursor_shape = Control::CURSOR_ARROW; + { + Control *c = over; + Vector2 cpos = pos; + while (c) { + cursor_shape = c->get_cursor_shape(cpos); + cpos = c->get_transform().xform(cpos); + if (cursor_shape != Control::CURSOR_ARROW) + break; + if (c->data.mouse_filter == Control::MOUSE_FILTER_STOP) + break; + if (c->is_set_as_toplevel()) + break; + c = c->get_parent_control(); + } + } + + ds_cursor_shape = (DisplayServer::CursorShape)cursor_shape; + + if (over && over->can_process()) { + _gui_call_input(over, mm); } + + set_input_as_handled(); } - //pos = gui.focus_inv_xform.xform(pos); + if (gui.drag_data.get_type() != Variant::NIL) { + //handle dragandrop - mm->set_position(pos); + if (gui.drag_preview) { + gui.drag_preview->set_position(mpos); + } - Control::CursorShape cursor_shape = Control::CURSOR_ARROW; - { - Control *c = over; - Vector2 cpos = pos; - while (c) { - cursor_shape = c->get_cursor_shape(cpos); - cpos = c->get_transform().xform(cpos); - if (cursor_shape != Control::CURSOR_ARROW) - break; - if (c->data.mouse_filter == Control::MOUSE_FILTER_STOP) - break; - if (c->is_set_as_toplevel()) - break; - c = c->get_parent_control(); + gui.drag_mouse_over = over; + gui.drag_mouse_over_pos = Vector2(); + + //find the window this is above of + + //see if there is an embedder + Viewport *embedder = nullptr; + Vector2 viewport_pos; + + if (is_embedding_subwindows()) { + embedder = this; + viewport_pos = mpos; + } else { + //not an embeder, but may be a subwindow of an embedder + Window *w = Object::cast_to<Window>(this); + if (w) { + if (w->is_embedded()) { + embedder = w->_get_embedder(); + + Transform2D ai = (get_final_transform().affine_inverse() * _get_input_pre_xform()).affine_inverse(); + + viewport_pos = ai.xform(mpos) + w->get_position(); //to parent coords + } + } } - } - OS::get_singleton()->set_cursor_shape((OS::CursorShape)cursor_shape); + Viewport *viewport_under = nullptr; - if (over && over->can_process()) { - _gui_call_input(over, mm); - } + if (embedder) { + //use embedder logic - set_input_as_handled(); + for (int i = embedder->gui.sub_windows.size() - 1; i >= 0; i--) { + Window *sw = embedder->gui.sub_windows[i].window; + Rect2 swrect = Rect2i(sw->get_position(), sw->get_size()); + if (!sw->get_flag(Window::FLAG_BORDERLESS)) { + int title_height = sw->get_theme_constant("title_height"); + swrect.position.y -= title_height; + swrect.size.y += title_height; + } - if (gui.drag_data.get_type() != Variant::NIL && mm->get_button_mask() & BUTTON_MASK_LEFT) { + if (swrect.has_point(viewport_pos)) { + viewport_under = sw; + viewport_pos -= sw->get_position(); + } + } + + if (!viewport_under) { + //not in a subwindow, likely in embedder + viewport_under = embedder; + } + } else { + //use displayserver logic + Vector2i screen_mouse_pos = DisplayServer::get_singleton()->mouse_get_position(); + + DisplayServer::WindowID window_id = DisplayServer::get_singleton()->get_window_at_screen_position(screen_mouse_pos); + + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + ObjectID object_under = DisplayServer::get_singleton()->window_get_attached_instance_id(window_id); + + if (object_under != ObjectID()) { //fetch window + Window *w = Object::cast_to<Window>(ObjectDB::get_instance(object_under)); + if (w) { + viewport_under = w; + viewport_pos = screen_mouse_pos - w->get_position(); + } + } + } + } - bool can_drop = _gui_drop(over, pos, true); + if (viewport_under) { + Transform2D ai = (viewport_under->get_final_transform().affine_inverse() * viewport_under->_get_input_pre_xform()); + viewport_pos = ai.xform(viewport_pos); + //find control under at pos + gui.drag_mouse_over = viewport_under->_gui_find_control(viewport_pos); + if (gui.drag_mouse_over) { + Transform2D localizer = gui.drag_mouse_over->get_global_transform_with_canvas().affine_inverse(); + gui.drag_mouse_over_pos = localizer.xform(viewport_pos); + + if (mm->get_button_mask() & BUTTON_MASK_LEFT) { + + bool can_drop = _gui_drop(gui.drag_mouse_over, gui.drag_mouse_over_pos, true); + + if (!can_drop) { + ds_cursor_shape = DisplayServer::CURSOR_FORBIDDEN; + } else { + ds_cursor_shape = DisplayServer::CURSOR_CAN_DROP; + } + } + } - if (!can_drop) { - OS::get_singleton()->set_cursor_shape(OS::CURSOR_FORBIDDEN); } else { - OS::get_singleton()->set_cursor_shape(OS::CURSOR_CAN_DROP); + gui.drag_mouse_over = nullptr; } - //change mouse accordingly i guess } + + DisplayServer::get_singleton()->cursor_set_shape(ds_cursor_shape); } Ref<InputEventScreenTouch> touch_event = p_event; @@ -2275,14 +2291,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { Control *over = _gui_find_control(pos); if (over) { - if (!gui.modal_stack.empty()) { - - Control *top = gui.modal_stack.back()->get(); - if (over != top && !top->is_a_parent_of(over)) { - - return; - } - } if (over->can_process()) { touch_event = touch_event->xformed_by(Transform2D()); //make a copy @@ -2348,14 +2356,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { } if (over) { - if (!gui.modal_stack.empty()) { - - Control *top = gui.modal_stack.back()->get(); - if (over != top && !top->is_a_parent_of(over)) { - - return; - } - } if (over->can_process()) { Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse(); @@ -2399,22 +2399,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { } } - if (p_event->is_pressed() && p_event->is_action("ui_cancel") && !gui.modal_stack.empty()) { - - _gui_sort_modal_stack(); - Control *top = gui.modal_stack.back()->get(); - if (!top->data.modal_exclusive) { - - top->notification(Control::NOTIFICATION_MODAL_CLOSE); - top->_modal_stack_remove(); - top->hide(); - // Close modal, set input as handled - set_input_as_handled(); - return; - } - } - - Control *from = gui.key_focus ? gui.key_focus : NULL; //hmm + Control *from = gui.key_focus ? gui.key_focus : nullptr; //hmm //keyboard focus //if (from && p_event->is_pressed() && !p_event->get_alt() && !p_event->get_metakey() && !p_event->key->get_command()) { @@ -2424,9 +2409,9 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { bool mods = k.is_valid() && (k->get_control() || k->get_alt() || k->get_shift() || k->get_metakey()); if (from && p_event->is_pressed()) { - Control *next = NULL; + Control *next = nullptr; - Input *input = Input::get_singleton(); + InputFilter *input = InputFilter::get_singleton(); if (p_event->is_action_pressed("ui_focus_next") && input->is_action_just_pressed("ui_focus_next")) { @@ -2472,68 +2457,17 @@ List<Control *>::Element *Viewport::_gui_add_root_control(Control *p_control) { return gui.roots.push_back(p_control); } -List<Control *>::Element *Viewport::_gui_add_subwindow_control(Control *p_control) { - - p_control->connect("visibility_changed", callable_mp(this, &Viewport::_subwindow_visibility_changed)); - - if (p_control->is_visible_in_tree()) { - gui.subwindow_order_dirty = true; - gui.subwindows.push_back(p_control); - } - - return gui.all_known_subwindows.push_back(p_control); -} - -void Viewport::_gui_set_subwindow_order_dirty() { - gui.subwindow_order_dirty = true; -} - void Viewport::_gui_set_root_order_dirty() { gui.roots_order_dirty = true; } -void Viewport::_gui_remove_modal_control(List<Control *>::Element *MI) { - - gui.modal_stack.erase(MI); -} - -void Viewport::_gui_remove_from_modal_stack(List<Control *>::Element *MI, ObjectID p_prev_focus_owner) { - - //transfer the focus stack to the next - - List<Control *>::Element *next = MI->next(); - - gui.modal_stack.erase(MI); - - if (p_prev_focus_owner.is_valid()) { - - // for previous window in stack, pass the focus so it feels more - // natural - - if (!next) { //top of stack - - Object *pfo = ObjectDB::get_instance(p_prev_focus_owner); - Control *pfoc = Object::cast_to<Control>(pfo); - if (!pfoc) - return; - - if (!pfoc->is_inside_tree() || !pfoc->is_visible_in_tree()) - return; - pfoc->grab_focus(); - } else { - - next->get()->_modal_set_prev_focus_owner(p_prev_focus_owner); - } - } -} - void Viewport::_gui_force_drag(Control *p_base, const Variant &p_data, Control *p_control) { ERR_FAIL_COND_MSG(p_data.get_type() == Variant::NIL, "Drag data must be a value."); gui.dragging = true; gui.drag_data = p_data; - gui.mouse_focus = NULL; + gui.mouse_focus = nullptr; if (p_control) { _gui_set_drag_preview(p_base, p_control); @@ -2545,7 +2479,7 @@ void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) { ERR_FAIL_NULL(p_control); ERR_FAIL_COND(!Object::cast_to<Control>((Object *)p_control)); ERR_FAIL_COND(p_control->is_inside_tree()); - ERR_FAIL_COND(p_control->get_parent() != NULL); + ERR_FAIL_COND(p_control->get_parent() != nullptr); if (gui.drag_preview) { memdelete(gui.drag_preview); @@ -2563,21 +2497,6 @@ void Viewport::_gui_remove_root_control(List<Control *>::Element *RI) { gui.roots.erase(RI); } -void Viewport::_gui_remove_subwindow_control(List<Control *>::Element *SI) { - - ERR_FAIL_COND(!SI); - - Control *control = SI->get(); - - control->disconnect("visibility_changed", callable_mp(this, &Viewport::_subwindow_visibility_changed)); - - List<Control *>::Element *E = gui.subwindows.find(control); - if (E) - gui.subwindows.erase(E); - - gui.all_known_subwindows.erase(SI); -} - void Viewport::_gui_unfocus_control(Control *p_control) { if (gui.key_focus == p_control) { @@ -2591,20 +2510,12 @@ void Viewport::_gui_hid_control(Control *p_control) { _drop_mouse_focus(); } - /* ??? - if (data.window==p_control) { - window->drag_data=Variant(); - if (window->drag_preview) { - memdelete( window->drag_preview); - window->drag_preview=NULL; - } - } - */ - if (gui.key_focus == p_control) _gui_remove_focus(); if (gui.mouse_over == p_control) - gui.mouse_over = NULL; + gui.mouse_over = nullptr; + if (gui.drag_mouse_over == p_control) + gui.drag_mouse_over = nullptr; if (gui.tooltip == p_control) _gui_cancel_tooltip(); } @@ -2612,37 +2523,32 @@ void Viewport::_gui_hid_control(Control *p_control) { void Viewport::_gui_remove_control(Control *p_control) { if (gui.mouse_focus == p_control) { - gui.mouse_focus = NULL; + gui.mouse_focus = nullptr; + gui.forced_mouse_focus = false; gui.mouse_focus_mask = 0; } if (gui.last_mouse_focus == p_control) { - gui.last_mouse_focus = NULL; + gui.last_mouse_focus = nullptr; } if (gui.key_focus == p_control) - gui.key_focus = NULL; + gui.key_focus = nullptr; if (gui.mouse_over == p_control) - gui.mouse_over = NULL; + gui.mouse_over = nullptr; + if (gui.drag_mouse_over == p_control) + gui.drag_mouse_over = nullptr; if (gui.tooltip == p_control) - gui.tooltip = NULL; - if (gui.tooltip_popup == p_control) { - _gui_cancel_tooltip(); - } + gui.tooltip = nullptr; } void Viewport::_gui_remove_focus() { if (gui.key_focus) { Node *f = gui.key_focus; - gui.key_focus = NULL; + gui.key_focus = nullptr; f->notification(Control::NOTIFICATION_FOCUS_EXIT, true); } } -bool Viewport::_gui_is_modal_on_top(const Control *p_control) { - - return (gui.modal_stack.size() && gui.modal_stack.back()->get() == p_control); -} - bool Viewport::_gui_control_has_focus(const Control *p_control) { return gui.key_focus == p_control; @@ -2671,7 +2577,8 @@ void Viewport::_drop_mouse_focus() { Control *c = gui.mouse_focus; int mask = gui.mouse_focus_mask; - gui.mouse_focus = NULL; + gui.mouse_focus = nullptr; + gui.forced_mouse_focus = false; gui.mouse_focus_mask = 0; for (int i = 0; i < 3; i++) { @@ -2703,7 +2610,7 @@ void Viewport::_drop_physics_mouseover() { #ifndef _3D_DISABLED if (physics_object_over.is_valid()) { - CollisionObject *co = Object::cast_to<CollisionObject>(ObjectDB::get_instance(physics_object_over)); + CollisionObject3D *co = Object::cast_to<CollisionObject3D>(ObjectDB::get_instance(physics_object_over)); if (co) { co->_mouse_exit(); } @@ -2714,22 +2621,6 @@ void Viewport::_drop_physics_mouseover() { #endif } -List<Control *>::Element *Viewport::_gui_show_modal(Control *p_control) { - - List<Control *>::Element *node = gui.modal_stack.push_back(p_control); - if (gui.key_focus) - p_control->_modal_set_prev_focus_owner(gui.key_focus->get_instance_id()); - else - p_control->_modal_set_prev_focus_owner(ObjectID()); - - if (gui.mouse_focus && !p_control->is_a_parent_of(gui.mouse_focus) && !gui.mouse_click_grabber) { - - _drop_mouse_focus(); - } - - return node; -} - Control *Viewport::_gui_get_focus_owner() { return gui.key_focus; @@ -2748,7 +2639,7 @@ void Viewport::_post_gui_grab_click_focus() { // Redundant grab requests were made return; } - gui.mouse_click_grabber = NULL; + gui.mouse_click_grabber = nullptr; if (gui.mouse_focus) { @@ -2798,44 +2689,390 @@ void Viewport::_post_gui_grab_click_focus() { /////////////////////////////// -void Viewport::input(const Ref<InputEvent> &p_event) { +void Viewport::input_text(const String &p_text) { + + if (gui.subwindow_focused) { + gui.subwindow_focused->input_text(p_text); + return; + } + + if (gui.key_focus) { + gui.key_focus->call("set_text", p_text); + } +} +Viewport::SubWindowResize Viewport::_sub_window_get_resize_margin(Window *p_subwindow, const Point2 &p_point) { + + if (p_subwindow->get_flag(Window::FLAG_BORDERLESS)) { + return SUB_WINDOW_RESIZE_DISABLED; + } + + Rect2i r = Rect2i(p_subwindow->get_position(), p_subwindow->get_size()); + + int title_height = p_subwindow->get_theme_constant("title_height"); + + r.position.y -= title_height; + r.size.y += title_height; + + if (r.has_point(p_point)) { + return SUB_WINDOW_RESIZE_DISABLED; //it's inside, so no resize + } + + int dist_x = p_point.x < r.position.x ? (p_point.x - r.position.x) : (p_point.x > (r.position.x + r.size.x) ? (p_point.x - (r.position.x + r.size.x)) : 0); + int dist_y = p_point.y < r.position.y ? (p_point.y - r.position.y) : (p_point.y > (r.position.y + r.size.y) ? (p_point.y - (r.position.y + r.size.y)) : 0); + + int limit = p_subwindow->get_theme_constant("resize_margin"); + + if (ABS(dist_x) > limit) { + return SUB_WINDOW_RESIZE_DISABLED; + } + + if (ABS(dist_y) > limit) { + return SUB_WINDOW_RESIZE_DISABLED; + } + + if (dist_x < 0 && dist_y < 0) { + return SUB_WINDOW_RESIZE_TOP_LEFT; + } + + if (dist_x == 0 && dist_y < 0) { + return SUB_WINDOW_RESIZE_TOP; + } + + if (dist_x > 0 && dist_y < 0) { + return SUB_WINDOW_RESIZE_TOP_RIGHT; + } + + if (dist_x < 0 && dist_y == 0) { + return SUB_WINDOW_RESIZE_LEFT; + } + + if (dist_x > 0 && dist_y == 0) { + return SUB_WINDOW_RESIZE_RIGHT; + } + + if (dist_x < 0 && dist_y > 0) { + return SUB_WINDOW_RESIZE_BOTTOM_LEFT; + } + + if (dist_x == 0 && dist_y > 0) { + return SUB_WINDOW_RESIZE_BOTTOM; + } + + if (dist_x > 0 && dist_y > 0) { + return SUB_WINDOW_RESIZE_BOTTOM_RIGHT; + } + + return SUB_WINDOW_RESIZE_DISABLED; +} +bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) { + + if (gui.subwindow_drag != SUB_WINDOW_DRAG_DISABLED) { + + ERR_FAIL_COND_V(gui.subwindow_focused == nullptr, false); + + Ref<InputEventMouseButton> mb = p_event; + if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { + + if (gui.subwindow_drag == SUB_WINDOW_DRAG_CLOSE) { + if (gui.subwindow_drag_close_rect.has_point(mb->get_position())) { + //close window + gui.subwindow_focused->_event_callback(DisplayServer::WINDOW_EVENT_CLOSE_REQUEST); + } + } + gui.subwindow_drag = SUB_WINDOW_DRAG_DISABLED; + if (gui.subwindow_focused != nullptr) { //may have been erased + _sub_window_update(gui.subwindow_focused); + } + } + + Ref<InputEventMouseMotion> mm = p_event; + if (mm.is_valid()) { + + if (gui.subwindow_drag == SUB_WINDOW_DRAG_MOVE) { + Vector2 diff = mm->get_position() - gui.subwindow_drag_from; + Rect2i new_rect(gui.subwindow_drag_pos + diff, gui.subwindow_focused->get_size()); + gui.subwindow_focused->_rect_changed_callback(new_rect); + } + if (gui.subwindow_drag == SUB_WINDOW_DRAG_CLOSE) { + gui.subwindow_drag_close_inside = gui.subwindow_drag_close_rect.has_point(mm->get_position()); + } + if (gui.subwindow_drag == SUB_WINDOW_DRAG_RESIZE) { + Vector2i diff = mm->get_position() - gui.subwindow_drag_from; + Size2i min_size = gui.subwindow_focused->get_min_size(); + if (gui.subwindow_focused->is_wrapping_controls()) { + Size2i cms = gui.subwindow_focused->get_contents_minimum_size(); + min_size.x = MAX(cms.x, min_size.x); + min_size.y = MAX(cms.y, min_size.y); + } + min_size.x = MAX(min_size.x, 1); + min_size.y = MAX(min_size.y, 1); + + Rect2i r = gui.subwindow_resize_from_rect; + + Size2i limit = r.size - min_size; + + switch (gui.subwindow_resize_mode) { + case SUB_WINDOW_RESIZE_TOP_LEFT: { + + diff.x = MIN(diff.x, limit.x); + diff.y = MIN(diff.y, limit.y); + r.position += diff; + r.size -= diff; + } break; + case SUB_WINDOW_RESIZE_TOP: { + diff.x = 0; + diff.y = MIN(diff.y, limit.y); + r.position += diff; + r.size -= diff; + } break; + case SUB_WINDOW_RESIZE_TOP_RIGHT: { + diff.x = MAX(diff.x, -limit.x); + diff.y = MIN(diff.y, limit.y); + r.position.y += diff.y; + r.size.y -= diff.y; + r.size.x += diff.x; + } break; + case SUB_WINDOW_RESIZE_LEFT: { + diff.x = MIN(diff.x, limit.x); + diff.y = 0; + r.position += diff; + r.size -= diff; + + } break; + case SUB_WINDOW_RESIZE_RIGHT: { + diff.x = MAX(diff.x, -limit.x); + r.size.x += diff.x; + } break; + case SUB_WINDOW_RESIZE_BOTTOM_LEFT: { + diff.x = MIN(diff.x, limit.x); + diff.y = MAX(diff.y, -limit.y); + r.position.x += diff.x; + r.size.x -= diff.x; + r.size.y += diff.y; + + } break; + case SUB_WINDOW_RESIZE_BOTTOM: { + diff.y = MAX(diff.y, -limit.y); + r.size.y += diff.y; + } break; + case SUB_WINDOW_RESIZE_BOTTOM_RIGHT: { + diff.x = MAX(diff.x, -limit.x); + diff.y = MAX(diff.y, -limit.y); + r.size += diff; + + } break; + default: { + } + } + + gui.subwindow_focused->_rect_changed_callback(r); + } + + if (gui.subwindow_focused) { //may have been erased + _sub_window_update(gui.subwindow_focused); + } + } + + return true; //handled + } + Ref<InputEventMouseButton> mb = p_event; + //if the event is a mouse button, we need to check whether another window was clicked + + if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { + + bool click_on_window = false; + for (int i = gui.sub_windows.size() - 1; i >= 0; i--) { + SubWindow &sw = gui.sub_windows.write[i]; + + //clicked inside window? + + Rect2i r = Rect2i(sw.window->get_position(), sw.window->get_size()); + + if (!sw.window->get_flag(Window::FLAG_BORDERLESS)) { + //check top bar + int title_height = sw.window->get_theme_constant("title_height"); + Rect2i title_bar = r; + title_bar.position.y -= title_height; + title_bar.size.y = title_height; + + if (title_bar.has_point(mb->get_position())) { + + click_on_window = true; + + int close_h_ofs = sw.window->get_theme_constant("close_h_ofs"); + int close_v_ofs = sw.window->get_theme_constant("close_v_ofs"); + Ref<Texture2D> close_icon = sw.window->get_theme_icon("close"); + + Rect2 close_rect; + close_rect.position = Vector2(r.position.x + r.size.x - close_v_ofs, r.position.y - close_h_ofs); + close_rect.size = close_icon->get_size(); + + if (gui.subwindow_focused != sw.window) { + //refocus + _sub_window_grab_focus(sw.window); + } + + if (close_rect.has_point(mb->get_position())) { + + gui.subwindow_drag = SUB_WINDOW_DRAG_CLOSE; + gui.subwindow_drag_close_inside = true; //starts inside + gui.subwindow_drag_close_rect = close_rect; + } else { + + gui.subwindow_drag = SUB_WINDOW_DRAG_MOVE; + } + + gui.subwindow_drag_from = mb->get_position(); + gui.subwindow_drag_pos = sw.window->get_position(); + + _sub_window_update(sw.window); + } else { + gui.subwindow_resize_mode = _sub_window_get_resize_margin(sw.window, mb->get_position()); + if (gui.subwindow_resize_mode != SUB_WINDOW_RESIZE_DISABLED) { + gui.subwindow_resize_from_rect = r; + gui.subwindow_drag_from = mb->get_position(); + gui.subwindow_drag = SUB_WINDOW_DRAG_RESIZE; + click_on_window = true; + } + } + } + if (!click_on_window && r.has_point(mb->get_position())) { + //clicked, see if it needs to fetch focus + if (gui.subwindow_focused != sw.window) { + //refocus + _sub_window_grab_focus(sw.window); + } + + click_on_window = true; + } + + if (click_on_window) { + break; + } + } + + if (!click_on_window && gui.subwindow_focused) { + //no window found and clicked, remove focus + _sub_window_grab_focus(nullptr); + } + } + + if (gui.subwindow_focused) { + + Ref<InputEventMouseMotion> mm = p_event; + if (mm.is_valid()) { + + SubWindowResize resize = _sub_window_get_resize_margin(gui.subwindow_focused, mm->get_position()); + if (resize != SUB_WINDOW_RESIZE_DISABLED) { + + DisplayServer::CursorShape shapes[SUB_WINDOW_RESIZE_MAX] = { + DisplayServer::CURSOR_ARROW, + DisplayServer::CURSOR_FDIAGSIZE, + DisplayServer::CURSOR_VSIZE, + DisplayServer::CURSOR_BDIAGSIZE, + DisplayServer::CURSOR_HSIZE, + DisplayServer::CURSOR_HSIZE, + DisplayServer::CURSOR_BDIAGSIZE, + DisplayServer::CURSOR_VSIZE, + DisplayServer::CURSOR_FDIAGSIZE + }; + + DisplayServer::get_singleton()->cursor_set_shape(shapes[resize]); + + return true; //reserved for showing the resize cursor + } + } + } + + if (gui.subwindow_drag != SUB_WINDOW_DRAG_DISABLED) { + return true; // dragging, don't pass the event + } + + if (!gui.subwindow_focused) { + return false; + } + + Transform2D window_ofs; + window_ofs.set_origin(-gui.subwindow_focused->get_position()); + + Ref<InputEvent> ev = p_event->xformed_by(window_ofs); + + gui.subwindow_focused->_window_input(ev); + + return true; +} + +void Viewport::input(const Ref<InputEvent> &p_event, bool p_local_coords) { ERR_FAIL_COND(!is_inside_tree()); + if (disable_input) + return; + + if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { + return; + } + local_input_handled = false; + Ref<InputEvent> ev; + if (!p_local_coords) { + ev = _make_input_local(p_event); + } else { + ev = p_event; + } + + if (is_embedding_subwindows() && _sub_windows_forward_input(p_event)) { + set_input_as_handled(); + return; + } + if (!is_input_handled()) { - get_tree()->_call_input_pause(input_group, "_input", p_event); //not a bug, must happen before GUI, order is _input -> gui input -> _unhandled input + get_tree()->_call_input_pause(input_group, "_input", ev, this); //not a bug, must happen before GUI, order is _input -> gui input -> _unhandled input } if (!is_input_handled()) { - _gui_input_event(p_event); + _gui_input_event(ev); } - //get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check + //get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",ev); //special one for GUI, as controls use their own process check } -void Viewport::unhandled_input(const Ref<InputEvent> &p_event) { +void Viewport::unhandled_input(const Ref<InputEvent> &p_event, bool p_local_coords) { ERR_FAIL_COND(!is_inside_tree()); - get_tree()->_call_input_pause(unhandled_input_group, "_unhandled_input", p_event); + if (disable_input) + return; + + if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { + return; + } + + Ref<InputEvent> ev; + if (!p_local_coords) { + ev = _make_input_local(p_event); + } else { + ev = p_event; + } + + get_tree()->_call_input_pause(unhandled_input_group, "_unhandled_input", ev, this); //call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_input","_unhandled_input",ev); - if (!get_tree()->input_handled && Object::cast_to<InputEventKey>(*p_event) != NULL) { - get_tree()->_call_input_pause(unhandled_key_input_group, "_unhandled_key_input", p_event); + if (!is_input_handled() && Object::cast_to<InputEventKey>(*ev) != nullptr) { + get_tree()->_call_input_pause(unhandled_key_input_group, "_unhandled_key_input", ev, this); //call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_key_input","_unhandled_key_input",ev); } - if (physics_object_picking && !get_tree()->input_handled) { + if (physics_object_picking && !is_input_handled()) { - if (Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED && - (Object::cast_to<InputEventMouseButton>(*p_event) || - Object::cast_to<InputEventMouseMotion>(*p_event) || - Object::cast_to<InputEventScreenDrag>(*p_event) || - Object::cast_to<InputEventScreenTouch>(*p_event) || - Object::cast_to<InputEventKey>(*p_event) //to remember state + if (InputFilter::get_singleton()->get_mouse_mode() != InputFilter::MOUSE_MODE_CAPTURED && + (Object::cast_to<InputEventMouseButton>(*ev) || + Object::cast_to<InputEventMouseMotion>(*ev) || + Object::cast_to<InputEventScreenDrag>(*ev) || + Object::cast_to<InputEventScreenTouch>(*ev) || + Object::cast_to<InputEventKey>(*ev) //to remember state )) { - physics_picking_events.push_back(p_event); + physics_picking_events.push_back(ev); } } } @@ -2849,7 +3086,7 @@ void Viewport::set_use_own_world(bool p_world) { _propagate_exit_world(this); if (!p_world) { - own_world = Ref<World>(); + own_world = Ref<World3D>(); if (world.is_valid()) { world->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_changed)); } @@ -2858,7 +3095,7 @@ void Viewport::set_use_own_world(bool p_world) { own_world = world->duplicate(); world->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_changed)); } else { - own_world = Ref<World>(memnew(World)); + own_world = Ref<World3D>(memnew(World3D)); } } @@ -2866,7 +3103,7 @@ void Viewport::set_use_own_world(bool p_world) { _propagate_enter_world(this); if (is_inside_tree()) { - VisualServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); + RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); } _update_listener(); @@ -2877,30 +3114,6 @@ bool Viewport::is_using_own_world() const { return own_world.is_valid(); } -void Viewport::set_attach_to_screen_rect(const Rect2 &p_rect) { - - VS::get_singleton()->viewport_attach_to_screen(viewport, p_rect); - to_screen_rect = p_rect; -} - -Rect2 Viewport::get_attach_to_screen_rect() const { - - return to_screen_rect; -} - -void Viewport::set_use_render_direct_to_screen(bool p_render_direct_to_screen) { - - if (p_render_direct_to_screen == render_direct_to_screen) - return; - - render_direct_to_screen = p_render_direct_to_screen; - VS::get_singleton()->viewport_set_render_direct_to_screen(viewport, p_render_direct_to_screen); -} - -bool Viewport::is_using_render_direct_to_screen() const { - return render_direct_to_screen; -} - void Viewport::set_physics_object_picking(bool p_enable) { physics_object_picking = p_enable; @@ -2925,11 +3138,6 @@ Vector2 Viewport::get_camera_rect_size() const { return size; } -bool Viewport::gui_has_modal_stack() const { - - return gui.modal_stack.size(); -} - void Viewport::set_disable_input(bool p_disable) { disable_input = p_disable; } @@ -2943,10 +3151,6 @@ Variant Viewport::gui_get_drag_data() const { return gui.drag_data; } -Control *Viewport::get_modal_stack_top() const { - return gui.modal_stack.size() ? gui.modal_stack.back()->get() : NULL; -} - String Viewport::get_configuration_warning() const { /*if (get_parent() && !Object::cast_to<Control>(get_parent()) && !render_target) { @@ -2969,11 +3173,11 @@ int Viewport::gui_get_canvas_sort_index() { void Viewport::set_msaa(MSAA p_msaa) { - ERR_FAIL_INDEX(p_msaa, 7); + ERR_FAIL_INDEX(p_msaa, MSAA_MAX); if (msaa == p_msaa) return; msaa = p_msaa; - VS::get_singleton()->viewport_set_msaa(viewport, VS::ViewportMSAA(p_msaa)); + RS::get_singleton()->viewport_set_msaa(viewport, RS::ViewportMSAA(p_msaa)); } Viewport::MSAA Viewport::get_msaa() const { @@ -2981,10 +3185,23 @@ Viewport::MSAA Viewport::get_msaa() const { return msaa; } +void Viewport::set_screen_space_aa(ScreenSpaceAA p_screen_space_aa) { + + ERR_FAIL_INDEX(p_screen_space_aa, SCREEN_SPACE_AA_MAX); + if (screen_space_aa == p_screen_space_aa) + return; + screen_space_aa = p_screen_space_aa; + RS::get_singleton()->viewport_set_screen_space_aa(viewport, RS::ViewportScreenSpaceAA(p_screen_space_aa)); +} + +Viewport::ScreenSpaceAA Viewport::get_screen_space_aa() const { + + return screen_space_aa; +} void Viewport::set_debug_draw(DebugDraw p_debug_draw) { debug_draw = p_debug_draw; - VS::get_singleton()->viewport_set_debug_draw(viewport, VS::ViewportDebugDraw(p_debug_draw)); + RS::get_singleton()->viewport_set_debug_draw(viewport, RS::ViewportDebugDraw(p_debug_draw)); } Viewport::DebugDraw Viewport::get_debug_draw() const { @@ -2994,7 +3211,7 @@ Viewport::DebugDraw Viewport::get_debug_draw() const { int Viewport::get_render_info(RenderInfo p_info) { - return VS::get_singleton()->viewport_get_render_info(viewport, VS::ViewportRenderInfo(p_info)); + return RS::get_singleton()->viewport_get_render_info(viewport, RS::ViewportRenderInfo(p_info)); } void Viewport::set_snap_controls_to_pixels(bool p_enable) { @@ -3017,7 +3234,17 @@ void Viewport::set_input_as_handled() { local_input_handled = true; } else { ERR_FAIL_COND(!is_inside_tree()); - get_tree()->set_input_as_handled(); + Viewport *vp = this; + while (true) { + if (Object::cast_to<Window>(vp)) { + break; + } + if (!vp->get_parent()) { + break; + } + vp = vp->get_parent()->get_viewport(); + } + vp->set_input_as_handled(); } } @@ -3025,8 +3252,17 @@ bool Viewport::is_input_handled() const { if (handle_input_locally) { return local_input_handled; } else { - ERR_FAIL_COND_V(!is_inside_tree(), false); - return get_tree()->is_input_handled(); + const Viewport *vp = this; + while (true) { + if (Object::cast_to<Window>(vp)) { + break; + } + if (!vp->get_parent()) { + break; + } + vp = vp->get_parent()->get_viewport(); + } + return vp->is_input_handled(); } } @@ -3086,13 +3322,47 @@ void Viewport::_propagate_update_default_repeat(Node *p_node) { } } -void Viewport::_bind_methods() { +DisplayServer::WindowID Viewport::get_window_id() const { + return DisplayServer::MAIN_WINDOW_ID; +} - ClassDB::bind_method(D_METHOD("set_use_arvr", "use"), &Viewport::set_use_arvr); - ClassDB::bind_method(D_METHOD("use_arvr"), &Viewport::use_arvr); +Viewport *Viewport::get_parent_viewport() const { + ERR_FAIL_COND_V(!is_inside_tree(), nullptr); + if (!get_parent()) { + return nullptr; //root viewport + } + + return get_parent()->get_viewport(); +} + +void Viewport::set_embed_subwindows_hint(bool p_embed) { + gui.embed_subwindows_hint = p_embed; +} +bool Viewport::get_embed_subwindows_hint() const { + return gui.embed_subwindows_hint; +} +bool Viewport::is_embedding_subwindows() const { + return gui.embed_subwindows_hint; +} + +void Viewport::pass_mouse_focus_to(Viewport *p_viewport, Control *p_control) { + ERR_FAIL_NULL(p_viewport); + ERR_FAIL_NULL(p_control); + + if (gui.mouse_focus) { + p_viewport->gui.mouse_focus = p_control; + p_viewport->gui.mouse_focus_mask = gui.mouse_focus_mask; + p_viewport->gui.key_focus = p_control; + p_viewport->gui.forced_mouse_focus = true; + + gui.mouse_focus = nullptr; + gui.forced_mouse_focus = false; + gui.mouse_focus_mask = 0; + } +} + +void Viewport::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_size", "size"), &Viewport::set_size); - ClassDB::bind_method(D_METHOD("get_size"), &Viewport::get_size); ClassDB::bind_method(D_METHOD("set_world_2d", "world_2d"), &Viewport::set_world_2d); ClassDB::bind_method(D_METHOD("get_world_2d"), &Viewport::get_world_2d); ClassDB::bind_method(D_METHOD("find_world_2d"), &Viewport::find_world_2d); @@ -3111,25 +3381,12 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_transparent_background", "enable"), &Viewport::set_transparent_background); ClassDB::bind_method(D_METHOD("has_transparent_background"), &Viewport::has_transparent_background); - ClassDB::bind_method(D_METHOD("_vp_input"), &Viewport::_vp_input); - ClassDB::bind_method(D_METHOD("_vp_input_text", "text"), &Viewport::_vp_input_text); - ClassDB::bind_method(D_METHOD("_vp_unhandled_input"), &Viewport::_vp_unhandled_input); - - ClassDB::bind_method(D_METHOD("set_size_override", "enable", "size", "margin"), &Viewport::set_size_override, DEFVAL(Size2(-1, -1)), DEFVAL(Size2(0, 0))); - ClassDB::bind_method(D_METHOD("get_size_override"), &Viewport::get_size_override); - ClassDB::bind_method(D_METHOD("is_size_override_enabled"), &Viewport::is_size_override_enabled); - ClassDB::bind_method(D_METHOD("set_size_override_stretch", "enabled"), &Viewport::set_size_override_stretch); - ClassDB::bind_method(D_METHOD("is_size_override_stretch_enabled"), &Viewport::is_size_override_stretch_enabled); - - ClassDB::bind_method(D_METHOD("set_clear_mode", "mode"), &Viewport::set_clear_mode); - ClassDB::bind_method(D_METHOD("get_clear_mode"), &Viewport::get_clear_mode); - - ClassDB::bind_method(D_METHOD("set_update_mode", "mode"), &Viewport::set_update_mode); - ClassDB::bind_method(D_METHOD("get_update_mode"), &Viewport::get_update_mode); - ClassDB::bind_method(D_METHOD("set_msaa", "msaa"), &Viewport::set_msaa); ClassDB::bind_method(D_METHOD("get_msaa"), &Viewport::get_msaa); + ClassDB::bind_method(D_METHOD("set_screen_space_aa", "screen_space_aa"), &Viewport::set_screen_space_aa); + ClassDB::bind_method(D_METHOD("get_screen_space_aa"), &Viewport::get_screen_space_aa); + ClassDB::bind_method(D_METHOD("set_debug_draw", "debug_draw"), &Viewport::set_debug_draw); ClassDB::bind_method(D_METHOD("get_debug_draw"), &Viewport::get_debug_draw); @@ -3141,8 +3398,9 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("get_physics_object_picking"), &Viewport::get_physics_object_picking); ClassDB::bind_method(D_METHOD("get_viewport_rid"), &Viewport::get_viewport_rid); - ClassDB::bind_method(D_METHOD("input", "local_event"), &Viewport::input); - ClassDB::bind_method(D_METHOD("unhandled_input", "local_event"), &Viewport::unhandled_input); + ClassDB::bind_method(D_METHOD("input_text", "text"), &Viewport::input_text); + ClassDB::bind_method(D_METHOD("input", "event", "in_local_coords"), &Viewport::input, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("unhandled_input", "event", "in_local_coords"), &Viewport::unhandled_input, DEFVAL(false)); ClassDB::bind_method(D_METHOD("update_worlds"), &Viewport::update_worlds); @@ -3156,19 +3414,13 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_as_audio_listener_2d", "enable"), &Viewport::set_as_audio_listener_2d); ClassDB::bind_method(D_METHOD("is_audio_listener_2d"), &Viewport::is_audio_listener_2d); - ClassDB::bind_method(D_METHOD("set_attach_to_screen_rect", "rect"), &Viewport::set_attach_to_screen_rect); - ClassDB::bind_method(D_METHOD("set_use_render_direct_to_screen", "enable"), &Viewport::set_use_render_direct_to_screen); - ClassDB::bind_method(D_METHOD("is_using_render_direct_to_screen"), &Viewport::is_using_render_direct_to_screen); ClassDB::bind_method(D_METHOD("get_mouse_position"), &Viewport::get_mouse_position); ClassDB::bind_method(D_METHOD("warp_mouse", "to_position"), &Viewport::warp_mouse); - ClassDB::bind_method(D_METHOD("gui_has_modal_stack"), &Viewport::gui_has_modal_stack); ClassDB::bind_method(D_METHOD("gui_get_drag_data"), &Viewport::gui_get_drag_data); ClassDB::bind_method(D_METHOD("gui_is_dragging"), &Viewport::gui_is_dragging); - ClassDB::bind_method(D_METHOD("get_modal_stack_top"), &Viewport::get_modal_stack_top); - ClassDB::bind_method(D_METHOD("set_disable_input", "disable"), &Viewport::set_disable_input); ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled); @@ -3194,13 +3446,13 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_default_canvas_item_texture_filter", "mode"), &Viewport::set_default_canvas_item_texture_filter); ClassDB::bind_method(D_METHOD("get_default_canvas_item_texture_filter"), &Viewport::get_default_canvas_item_texture_filter); + ClassDB::bind_method(D_METHOD("set_embed_subwindows_hint", "enable"), &Viewport::set_embed_subwindows_hint); + ClassDB::bind_method(D_METHOD("get_embed_subwindows_hint"), &Viewport::get_embed_subwindows_hint); + ClassDB::bind_method(D_METHOD("is_embedding_subwindows"), &Viewport::is_embedding_subwindows); + ClassDB::bind_method(D_METHOD("set_default_canvas_item_texture_repeat", "mode"), &Viewport::set_default_canvas_item_texture_repeat); ClassDB::bind_method(D_METHOD("get_default_canvas_item_texture_repeat"), &Viewport::get_default_canvas_item_texture_repeat); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "arvr"), "set_use_arvr", "use_arvr"); - - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "size_override_stretch"), "set_size_override_stretch", "is_size_override_stretch_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "own_world"), "set_use_own_world", "is_using_own_world"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world", PROPERTY_HINT_RESOURCE_TYPE, "World"), "set_world", "get_world"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world_2d", PROPERTY_HINT_RESOURCE_TYPE, "World2D", 0), "set_world_2d", "get_world_2d"); @@ -3208,11 +3460,8 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "handle_input_locally"), "set_handle_input_locally", "is_handling_input_locally"); ADD_GROUP("Rendering", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x"), "set_msaa", "get_msaa"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_direct_to_screen"), "set_use_render_direct_to_screen", "is_using_render_direct_to_screen"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_space_aa", PROPERTY_HINT_ENUM, "Disabled,FXAA"), "set_screen_space_aa", "get_screen_space_aa"); ADD_PROPERTY(PropertyInfo(Variant::INT, "debug_draw", PROPERTY_HINT_ENUM, "Disabled,Unshaded,Overdraw,Wireframe"), "set_debug_draw", "get_debug_draw"); - ADD_GROUP("Render Target", "render_target_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target_clear_mode", PROPERTY_HINT_ENUM, "Always,Never,Next Frame"), "set_clear_mode", "get_clear_mode"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target_update_mode", PROPERTY_HINT_ENUM, "Disabled,Once,When Visible,Always"), "set_update_mode", "get_update_mode"); ADD_GROUP("Canvas Items", "canvas_item_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "canvas_item_default_texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,MipmapLinear,MipmapNearest"), "set_default_canvas_item_texture_filter", "get_default_canvas_item_texture_filter"); ADD_PROPERTY(PropertyInfo(Variant::INT, "canvas_item_default_texture_repeat", PROPERTY_HINT_ENUM, "Disabled,Enabled,Mirror"), "set_default_canvas_item_texture_repeat", "get_default_canvas_item_texture_repeat"); @@ -3224,6 +3473,7 @@ void Viewport::_bind_methods() { ADD_GROUP("GUI", "gui_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_disable_input"), "set_disable_input", "is_input_disabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_snap_controls_to_pixels"), "set_snap_controls_to_pixels", "is_snap_controls_to_pixels_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_embed_subwindows"), "set_embed_subwindows_hint", "get_embed_subwindows_hint"); ADD_GROUP("Shadow Atlas", "shadow_atlas_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_atlas_size"), "set_shadow_atlas_size", "get_shadow_atlas_size"); ADD_PROPERTYI(PropertyInfo(Variant::INT, "shadow_atlas_quad_0", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv", 0); @@ -3236,11 +3486,6 @@ void Viewport::_bind_methods() { ADD_SIGNAL(MethodInfo("size_changed")); ADD_SIGNAL(MethodInfo("gui_focus_changed", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); - BIND_ENUM_CONSTANT(UPDATE_DISABLED); - BIND_ENUM_CONSTANT(UPDATE_ONCE); - BIND_ENUM_CONSTANT(UPDATE_WHEN_VISIBLE); - BIND_ENUM_CONSTANT(UPDATE_ALWAYS); - BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED); BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1); BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_4); @@ -3250,6 +3495,17 @@ void Viewport::_bind_methods() { BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1024); BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_MAX); + BIND_ENUM_CONSTANT(MSAA_DISABLED); + BIND_ENUM_CONSTANT(MSAA_2X); + BIND_ENUM_CONSTANT(MSAA_4X); + BIND_ENUM_CONSTANT(MSAA_8X); + BIND_ENUM_CONSTANT(MSAA_16X); + BIND_ENUM_CONSTANT(MSAA_MAX); + + BIND_ENUM_CONSTANT(SCREEN_SPACE_AA_DISABLED); + BIND_ENUM_CONSTANT(SCREEN_SPACE_AA_FXAA); + BIND_ENUM_CONSTANT(SCREEN_SPACE_AA_MAX); + BIND_ENUM_CONSTANT(RENDER_INFO_OBJECTS_IN_FRAME); BIND_ENUM_CONSTANT(RENDER_INFO_VERTICES_IN_FRAME); BIND_ENUM_CONSTANT(RENDER_INFO_MATERIAL_CHANGES_IN_FRAME); @@ -3260,9 +3516,10 @@ void Viewport::_bind_methods() { BIND_ENUM_CONSTANT(DEBUG_DRAW_DISABLED); BIND_ENUM_CONSTANT(DEBUG_DRAW_UNSHADED); + BIND_ENUM_CONSTANT(DEBUG_DRAW_LIGHTING); BIND_ENUM_CONSTANT(DEBUG_DRAW_OVERDRAW); BIND_ENUM_CONSTANT(DEBUG_DRAW_WIREFRAME); - + BIND_ENUM_CONSTANT(DEBUG_DRAW_NORMAL_BUFFER); BIND_ENUM_CONSTANT(DEBUG_DRAW_GI_PROBE_ALBEDO); BIND_ENUM_CONSTANT(DEBUG_DRAW_GI_PROBE_LIGHTING); BIND_ENUM_CONSTANT(DEBUG_DRAW_GI_PROBE_EMISSION); @@ -3270,68 +3527,47 @@ void Viewport::_bind_methods() { BIND_ENUM_CONSTANT(DEBUG_DRAW_DIRECTIONAL_SHADOW_ATLAS); BIND_ENUM_CONSTANT(DEBUG_DRAW_SCENE_LUMINANCE); BIND_ENUM_CONSTANT(DEBUG_DRAW_SSAO); - - BIND_ENUM_CONSTANT(MSAA_DISABLED); - BIND_ENUM_CONSTANT(MSAA_2X); - BIND_ENUM_CONSTANT(MSAA_4X); - BIND_ENUM_CONSTANT(MSAA_8X); - BIND_ENUM_CONSTANT(MSAA_16X); - - BIND_ENUM_CONSTANT(CLEAR_MODE_ALWAYS); - BIND_ENUM_CONSTANT(CLEAR_MODE_NEVER); - BIND_ENUM_CONSTANT(CLEAR_MODE_ONLY_NEXT_FRAME); + BIND_ENUM_CONSTANT(DEBUG_DRAW_ROUGHNESS_LIMITER); + BIND_ENUM_CONSTANT(DEBUG_DRAW_PSSM_SPLITS); + BIND_ENUM_CONSTANT(DEBUG_DRAW_DECAL_ATLAS); BIND_ENUM_CONSTANT(DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST); BIND_ENUM_CONSTANT(DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR); BIND_ENUM_CONSTANT(DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS); BIND_ENUM_CONSTANT(DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS); - BIND_ENUM_CONSTANT(DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_MAX); + BIND_ENUM_CONSTANT(DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_DISABLED); BIND_ENUM_CONSTANT(DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_ENABLED); BIND_ENUM_CONSTANT(DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_MIRROR); BIND_ENUM_CONSTANT(DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_MAX); } -void Viewport::_subwindow_visibility_changed() { - - // unfortunately, we don't know the sender, i.e. which subwindow changed; - // so we have to check them all. - gui.subwindow_visibility_dirty = true; -} - Viewport::Viewport() { world_2d = Ref<World2D>(memnew(World2D)); - viewport = VisualServer::get_singleton()->viewport_create(); - texture_rid = VisualServer::get_singleton()->viewport_get_texture(viewport); - - render_direct_to_screen = false; + viewport = RenderingServer::get_singleton()->viewport_create(); + texture_rid = RenderingServer::get_singleton()->viewport_get_texture(viewport); default_texture.instance(); default_texture->vp = const_cast<Viewport *>(this); viewport_textures.insert(default_texture.ptr()); - default_texture->proxy = VS::get_singleton()->texture_proxy_create(texture_rid); + default_texture->proxy = RS::get_singleton()->texture_proxy_create(texture_rid); - //internal_listener = SpatialSoundServer::get_singleton()->listener_create(); audio_listener = false; //internal_listener_2d = SpatialSound2DServer::get_singleton()->listener_create(); audio_listener_2d = false; transparent_bg = false; - parent = NULL; - listener = NULL; - camera = NULL; + parent = nullptr; + listener = nullptr; + camera = nullptr; override_canvas_transform = false; - canvas_layers.insert(NULL); // This eases picking code (interpreted as the canvas of the Viewport) - arvr = false; - size_override = false; - size_override_stretch = false; - size_override_size = Size2(1, 1); + canvas_layers.insert(nullptr); // This eases picking code (interpreted as the canvas of the Viewport) + gen_mipmaps = false; //clear=true; - update_mode = UPDATE_WHEN_VISIBLE; physics_object_picking = false; physics_has_last_mousepos = false; @@ -3361,19 +3597,21 @@ Viewport::Viewport() { gui.tooltip_delay = GLOBAL_DEF("gui/timers/tooltip_delay_sec", 0.5); ProjectSettings::get_singleton()->set_custom_property_info("gui/timers/tooltip_delay_sec", PropertyInfo(Variant::FLOAT, "gui/timers/tooltip_delay_sec", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater")); // No negative numbers - gui.tooltip = NULL; - gui.tooltip_label = NULL; - gui.drag_preview = NULL; + gui.tooltip = nullptr; + gui.tooltip_label = nullptr; + gui.drag_preview = nullptr; gui.drag_attempted = false; gui.canvas_sort_index = 0; gui.roots_order_dirty = false; - gui.mouse_focus = NULL; - gui.last_mouse_focus = NULL; + gui.mouse_focus = nullptr; + gui.forced_mouse_focus = false; + gui.last_mouse_focus = nullptr; + gui.subwindow_focused = nullptr; + gui.subwindow_drag = SUB_WINDOW_DRAG_DISABLED; msaa = MSAA_DISABLED; - + screen_space_aa = SCREEN_SPACE_AA_DISABLED; debug_draw = DEBUG_DRAW_DISABLED; - clear_mode = CLEAR_MODE_ALWAYS; snap_controls_to_pixels = true; physics_last_mouse_state.alt = false; @@ -3384,6 +3622,8 @@ Viewport::Viewport() { local_input_handled = false; handle_input_locally = true; + size_allocated = false; + default_canvas_item_texture_filter = DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR; default_canvas_item_texture_repeat = DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_DISABLED; } @@ -3392,9 +3632,143 @@ Viewport::~Viewport() { //erase itself from viewport textures for (Set<ViewportTexture *>::Element *E = viewport_textures.front(); E; E = E->next()) { - E->get()->vp = NULL; + E->get()->vp = nullptr; + } + RenderingServer::get_singleton()->free(viewport); +} + +///////////////////////////////// + +void SubViewport::set_use_xr(bool p_use_xr) { + xr = p_use_xr; + + RS::get_singleton()->viewport_set_use_xr(get_viewport_rid(), xr); +} + +bool SubViewport::is_using_xr() { + return xr; +} + +void SubViewport::set_size(const Size2i &p_size) { + _set_size(p_size, _get_size_2d_override(), Rect2i(), _stretch_transform(), true); +} +Size2i SubViewport::get_size() const { + return _get_size(); +} + +void SubViewport::set_size_2d_override(const Size2i &p_size) { + + _set_size(_get_size(), p_size, Rect2i(), _stretch_transform(), true); +} +Size2i SubViewport::get_size_2d_override() const { + + return _get_size_2d_override(); +} + +void SubViewport::set_size_2d_override_stretch(bool p_enable) { + + if (p_enable == size_2d_override_stretch) { + return; } - VisualServer::get_singleton()->free(viewport); - //SpatialSoundServer::get_singleton()->free(internal_listener); - //SpatialSound2DServer::get_singleton()->free(internal_listener_2d); + + size_2d_override_stretch = p_enable; + _set_size(_get_size(), _get_size_2d_override(), Rect2i(), _stretch_transform(), true); +} +bool SubViewport::is_size_2d_override_stretch_enabled() const { + + return size_2d_override_stretch; +} + +void SubViewport::set_update_mode(UpdateMode p_mode) { + + update_mode = p_mode; + RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::ViewportUpdateMode(p_mode)); +} +SubViewport::UpdateMode SubViewport::get_update_mode() const { + + return update_mode; +} + +void SubViewport::set_clear_mode(ClearMode p_mode) { + + clear_mode = p_mode; + RS::get_singleton()->viewport_set_clear_mode(get_viewport_rid(), RS::ViewportClearMode(p_mode)); +} +SubViewport::ClearMode SubViewport::get_clear_mode() const { + + return clear_mode; +} + +DisplayServer::WindowID SubViewport::get_window_id() const { + return DisplayServer::INVALID_WINDOW_ID; +} + +Transform2D SubViewport::_stretch_transform() { + + Transform2D transform = Transform2D(); + Size2i view_size_2d_override = _get_size_2d_override(); + if (size_2d_override_stretch && view_size_2d_override.width > 0 && view_size_2d_override.height > 0) { + Size2 scale = _get_size() / view_size_2d_override; + transform.scale(scale); + } + + return transform; +} + +void SubViewport::_notification(int p_what) { + + if (p_what == NOTIFICATION_ENTER_TREE) { + RS::get_singleton()->viewport_set_active(get_viewport_rid(), true); + } + if (p_what == NOTIFICATION_EXIT_TREE) { + RS::get_singleton()->viewport_set_active(get_viewport_rid(), false); + } +} + +void SubViewport::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_use_xr", "use"), &SubViewport::set_use_xr); + ClassDB::bind_method(D_METHOD("is_using_xr"), &SubViewport::is_using_xr); + + ClassDB::bind_method(D_METHOD("set_size", "size"), &SubViewport::set_size); + ClassDB::bind_method(D_METHOD("get_size"), &SubViewport::get_size); + + ClassDB::bind_method(D_METHOD("set_size_2d_override", "size"), &SubViewport::set_size_2d_override); + ClassDB::bind_method(D_METHOD("get_size_2d_override"), &SubViewport::get_size_2d_override); + + ClassDB::bind_method(D_METHOD("set_size_2d_override_stretch", "enable"), &SubViewport::set_size_2d_override_stretch); + ClassDB::bind_method(D_METHOD("is_size_2d_override_stretch_enabled"), &SubViewport::is_size_2d_override_stretch_enabled); + + ClassDB::bind_method(D_METHOD("set_update_mode", "mode"), &SubViewport::set_update_mode); + ClassDB::bind_method(D_METHOD("get_update_mode"), &SubViewport::get_update_mode); + + ClassDB::bind_method(D_METHOD("set_clear_mode", "mode"), &SubViewport::set_clear_mode); + ClassDB::bind_method(D_METHOD("get_clear_mode"), &SubViewport::get_clear_mode); + + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "xr"), "set_use_xr", "is_using_xr"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size_2d_override"), "set_size_2d_override", "get_size_2d_override"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "size_2d_override_stretch"), "set_size_2d_override_stretch", "is_size_2d_override_stretch_enabled"); + ADD_GROUP("Render Target", "render_target_"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target_clear_mode", PROPERTY_HINT_ENUM, "Always,Never,Next Frame"), "set_clear_mode", "get_clear_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target_update_mode", PROPERTY_HINT_ENUM, "Disabled,Once,When Visible,Always"), "set_update_mode", "get_update_mode"); + + BIND_ENUM_CONSTANT(CLEAR_MODE_ALWAYS); + BIND_ENUM_CONSTANT(CLEAR_MODE_NEVER); + BIND_ENUM_CONSTANT(CLEAR_MODE_ONLY_NEXT_FRAME); + + BIND_ENUM_CONSTANT(UPDATE_DISABLED); + BIND_ENUM_CONSTANT(UPDATE_ONCE); + BIND_ENUM_CONSTANT(UPDATE_WHEN_VISIBLE); + BIND_ENUM_CONSTANT(UPDATE_WHEN_PARENT_VISIBLE); + BIND_ENUM_CONSTANT(UPDATE_ALWAYS); +} + +SubViewport::SubViewport() { + xr = false; + size_2d_override_stretch = false; + update_mode = UPDATE_WHEN_VISIBLE; + clear_mode = CLEAR_MODE_ALWAYS; +} + +SubViewport::~SubViewport() { } diff --git a/scene/main/viewport.h b/scene/main/viewport.h index e511ce1b17..7e2df9fe42 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -35,11 +35,12 @@ #include "scene/main/node.h" #include "scene/resources/texture.h" #include "scene/resources/world_2d.h" -#include "servers/visual_server.h" +#include "servers/display_server.h" +#include "servers/rendering_server.h" -class Camera; +class Camera3D; class Camera2D; -class Listener; +class Listener3D; class Control; class CanvasItem; class CanvasLayer; @@ -47,7 +48,7 @@ class Panel; class Label; class Timer; class Viewport; -class CollisionObject; +class CollisionObject3D; class ViewportTexture : public Texture2D { @@ -88,13 +89,6 @@ class Viewport : public Node { GDCLASS(Viewport, Node); public: - enum UpdateMode { - UPDATE_DISABLED, - UPDATE_ONCE, //then goes to disabled - UPDATE_WHEN_VISIBLE, // default - UPDATE_ALWAYS - }; - enum ShadowAtlasQuadrantSubdiv { SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED, SHADOW_ATLAS_QUADRANT_SUBDIV_1, @@ -112,10 +106,16 @@ public: MSAA_4X, MSAA_8X, MSAA_16X, + MSAA_MAX }; - enum RenderInfo { + enum ScreenSpaceAA { + SCREEN_SPACE_AA_DISABLED, + SCREEN_SPACE_AA_FXAA, + SCREEN_SPACE_AA_MAX + }; + enum RenderInfo { RENDER_INFO_OBJECTS_IN_FRAME, RENDER_INFO_VERTICES_IN_FRAME, RENDER_INFO_MATERIAL_CHANGES_IN_FRAME, @@ -139,14 +139,9 @@ public: DEBUG_DRAW_DIRECTIONAL_SHADOW_ATLAS, DEBUG_DRAW_SCENE_LUMINANCE, DEBUG_DRAW_SSAO, - DEBUG_DRAW_ROUGHNESS_LIMITER - }; - - enum ClearMode { - - CLEAR_MODE_ALWAYS, - CLEAR_MODE_NEVER, - CLEAR_MODE_ONLY_NEXT_FRAME + DEBUG_DRAW_ROUGHNESS_LIMITER, + DEBUG_DRAW_PSSM_SPLITS, + DEBUG_DRAW_DECAL_ATLAS }; enum DefaultCanvasItemTextureFilter { @@ -164,15 +159,17 @@ public: DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_MAX, }; + enum { + SUBWINDOW_CANVAS_LAYER = 1024 + }; + private: friend class ViewportTexture; Viewport *parent; - Listener *listener; - Set<Listener *> listeners; - - bool arvr; + Listener3D *listener; + Set<Listener3D *> listeners; struct CameraOverrideData { Transform transform; @@ -192,12 +189,13 @@ private: } } camera_override; - Camera *camera; - Set<Camera *> cameras; + Camera3D *camera; + Set<Camera3D *> cameras; Set<CanvasLayer *> canvas_layers; RID viewport; RID current_canvas; + RID subwindow_canvas; bool audio_listener; RID internal_listener; @@ -212,23 +210,17 @@ private: Transform2D global_canvas_transform; Transform2D stretch_transform; - Size2 size; - Rect2 to_screen_rect; - bool render_direct_to_screen; + Size2i size; + Size2i size_2d_override; + bool size_allocated; RID contact_2d_debug; RID contact_3d_debug_multimesh; RID contact_3d_debug_instance; - bool size_override; - bool size_override_stretch; - Size2 size_override_size; - Size2 size_override_margin; - Rect2 last_vp_rect; bool transparent_bg; - ClearMode clear_mode; bool filter; bool gen_mipmaps; @@ -253,7 +245,7 @@ private: } physics_last_mouse_state; - void _collision_object_input_event(CollisionObject *p_object, Camera *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape); + void _collision_object_input_event(CollisionObject3D *p_object, Camera3D *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape); bool handle_input_locally; bool local_input_handled; @@ -261,9 +253,10 @@ private: Map<ObjectID, uint64_t> physics_2d_mouseover; Ref<World2D> world_2d; - Ref<World> world; - Ref<World> own_world; + Ref<World3D> world; + Ref<World3D> own_world; + Rect2i to_screen_rect; StringName input_group; StringName gui_input_group; StringName unhandled_input_group; @@ -276,10 +269,8 @@ private: void _propagate_exit_world(Node *p_node); void _propagate_viewport_notification(Node *p_node, int p_what); - void _update_stretch_transform(); void _update_global_transform(); - UpdateMode update_mode; RID texture_rid; DebugDraw debug_draw; @@ -288,12 +279,39 @@ private: ShadowAtlasQuadrantSubdiv shadow_atlas_quadrant_subdiv[4]; MSAA msaa; + ScreenSpaceAA screen_space_aa; Ref<ViewportTexture> default_texture; Set<ViewportTexture *> viewport_textures; + enum SubWindowDrag { + SUB_WINDOW_DRAG_DISABLED, + SUB_WINDOW_DRAG_MOVE, + SUB_WINDOW_DRAG_CLOSE, + SUB_WINDOW_DRAG_RESIZE, + }; + + enum SubWindowResize { + SUB_WINDOW_RESIZE_DISABLED, + SUB_WINDOW_RESIZE_TOP_LEFT, + SUB_WINDOW_RESIZE_TOP, + SUB_WINDOW_RESIZE_TOP_RIGHT, + SUB_WINDOW_RESIZE_LEFT, + SUB_WINDOW_RESIZE_RIGHT, + SUB_WINDOW_RESIZE_BOTTOM_LEFT, + SUB_WINDOW_RESIZE_BOTTOM, + SUB_WINDOW_RESIZE_BOTTOM_RIGHT, + SUB_WINDOW_RESIZE_MAX + }; + + struct SubWindow { + Window *window; + RID canvas_item; + }; + struct GUI { // info used when this is a window + bool forced_mouse_focus; //used for menu buttons bool key_event_accepted; Control *mouse_focus; Control *last_mouse_focus; @@ -301,8 +319,10 @@ private: int mouse_focus_mask; Control *key_focus; Control *mouse_over; + Control *drag_mouse_over; + Vector2 drag_mouse_over_pos; Control *tooltip; - Control *tooltip_popup; + Window *tooltip_popup; Label *tooltip_label; Point2 tooltip_pos; Point2 last_mouse_pos; @@ -312,16 +332,24 @@ private: Control *drag_preview; float tooltip_timer; float tooltip_delay; - List<Control *> modal_stack; Transform2D focus_inv_xform; - bool subwindow_order_dirty; - bool subwindow_visibility_dirty; - List<Control *> subwindows; // visible subwindows - List<Control *> all_known_subwindows; bool roots_order_dirty; List<Control *> roots; int canvas_sort_index; //for sorting items with canvas as root bool dragging; + bool embed_subwindows_hint; + bool embedding_subwindows; + + Window *subwindow_focused; + SubWindowDrag subwindow_drag; + Vector2 subwindow_drag_from; + Vector2 subwindow_drag_pos; + Rect2i subwindow_drag_close_rect; + bool subwindow_drag_close_inside; + SubWindowResize subwindow_resize_mode; + Rect2i subwindow_resize_from_rect; + + Vector<SubWindow> sub_windows; GUI(); } gui; @@ -337,10 +365,7 @@ private: void _gui_call_input(Control *p_control, const Ref<InputEvent> &p_input); void _gui_call_notification(Control *p_control, int p_what); - void _gui_prepare_subwindows(); - void _gui_sort_subwindows(); void _gui_sort_roots(); - void _gui_sort_modal_stack(); Control *_gui_find_control(const Point2 &p_global); Control *_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform); @@ -350,25 +375,15 @@ private: _FORCE_INLINE_ Transform2D _get_input_pre_xform() const; - void _vp_input(const Ref<InputEvent> &p_ev); - void _vp_input_text(const String &p_text); - void _vp_unhandled_input(const Ref<InputEvent> &p_ev); Ref<InputEvent> _make_input_local(const Ref<InputEvent> &ev); friend class Control; List<Control *>::Element *_gui_add_root_control(Control *p_control); - List<Control *>::Element *_gui_add_subwindow_control(Control *p_control); - - void _gui_set_subwindow_order_dirty(); - void _gui_set_root_order_dirty(); - void _gui_remove_modal_control(List<Control *>::Element *MI); - void _gui_remove_from_modal_stack(List<Control *>::Element *MI, ObjectID p_prev_focus_owner); void _gui_remove_root_control(List<Control *>::Element *RI); - void _gui_remove_subwindow_control(List<Control *>::Element *SI); - String _gui_get_tooltip(Control *p_control, const Vector2 &p_pos, Control **r_which = NULL); + String _gui_get_tooltip(Control *p_control, const Vector2 &p_pos, Control **r_which = nullptr); void _gui_cancel_tooltip(); void _gui_show_tooltip(); @@ -378,9 +393,6 @@ private: void _gui_force_drag(Control *p_base, const Variant &p_data, Control *p_control); void _gui_set_drag_preview(Control *p_base, Control *p_control); - bool _gui_is_modal_on_top(const Control *p_control); - List<Control *>::Element *_gui_show_modal(Control *p_control); - void _gui_remove_focus(); void _gui_unfocus_control(Control *p_control); bool _gui_control_has_focus(const Control *p_control); @@ -391,23 +403,21 @@ private: Control *_gui_get_focus_owner(); - Vector2 _get_window_offset() const; - bool _gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_check); - friend class Listener; + friend class Listener3D; void _listener_transform_changed_notify(); - void _listener_set(Listener *p_listener); - bool _listener_add(Listener *p_listener); //true if first - void _listener_remove(Listener *p_listener); - void _listener_make_next_current(Listener *p_exclude); + void _listener_set(Listener3D *p_listener); + bool _listener_add(Listener3D *p_listener); //true if first + void _listener_remove(Listener3D *p_listener); + void _listener_make_next_current(Listener3D *p_exclude); - friend class Camera; + friend class Camera3D; void _camera_transform_changed_notify(); - void _camera_set(Camera *p_camera); - bool _camera_add(Camera *p_camera); //true if first - void _camera_remove(Camera *p_camera); - void _camera_make_next_current(Camera *p_exclude); + void _camera_set(Camera3D *p_camera); + bool _camera_add(Camera3D *p_camera); //true if first + void _camera_remove(Camera3D *p_camera); + void _camera_make_next_current(Camera3D *p_exclude); friend class CanvasLayer; void _canvas_layer_add(CanvasLayer *p_canvas_layer); @@ -418,16 +428,34 @@ private: void _update_canvas_items(Node *p_node); + void _gui_set_root_order_dirty(); + void _own_world_changed(); + friend class Window; + + void _sub_window_update_order(); + void _sub_window_register(Window *p_window); + void _sub_window_update(Window *p_window); + void _sub_window_grab_focus(Window *p_window); + void _sub_window_remove(Window *p_window); + bool _sub_windows_forward_input(const Ref<InputEvent> &p_event); + SubWindowResize _sub_window_get_resize_margin(Window *p_subwindow, const Point2 &p_point); + protected: + void _set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, const Transform2D &p_stretch_transform, bool p_allocated); + + Size2i _get_size() const; + Size2i _get_size_2d_override() const; + bool _is_size_allocated() const; + void _notification(int p_what); static void _bind_methods(); virtual void _validate_property(PropertyInfo &property) const; public: - Listener *get_listener() const; - Camera *get_camera() const; + Listener3D *get_listener() const; + Camera3D *get_camera() const; void enable_camera_override(bool p_enable); bool is_camera_override_enabled() const; @@ -438,26 +466,21 @@ public: void set_camera_override_perspective(float p_fovy_degrees, float p_z_near, float p_z_far); void set_camera_override_orthogonal(float p_size, float p_z_near, float p_z_far); - void set_use_arvr(bool p_use_arvr); - bool use_arvr(); - void set_as_audio_listener(bool p_enable); bool is_audio_listener() const; void set_as_audio_listener_2d(bool p_enable); bool is_audio_listener_2d() const; - void set_size(const Size2 &p_size); void update_canvas_items(); - Size2 get_size() const; Rect2 get_visible_rect() const; RID get_viewport_rid() const; - void set_world(const Ref<World> &p_world); + void set_world(const Ref<World3D> &p_world); void set_world_2d(const Ref<World2D> &p_world_2d); - Ref<World> get_world() const; - Ref<World> find_world() const; + Ref<World3D> get_world() const; + Ref<World3D> find_world() const; Ref<World2D> get_world_2d() const; Ref<World2D> find_world_2d() const; @@ -479,18 +502,6 @@ public: void set_transparent_background(bool p_enable); bool has_transparent_background() const; - void set_size_override(bool p_enable, const Size2 &p_size = Size2(-1, -1), const Vector2 &p_margin = Vector2()); - Size2 get_size_override() const; - - bool is_size_override_enabled() const; - void set_size_override_stretch(bool p_enable); - bool is_size_override_stretch_enabled() const; - - void set_clear_mode(ClearMode p_mode); - ClearMode get_clear_mode() const; - - void set_update_mode(UpdateMode p_mode); - UpdateMode get_update_mode() const; Ref<ViewportTexture> get_texture() const; void set_shadow_atlas_size(int p_size); @@ -502,34 +513,29 @@ public: void set_msaa(MSAA p_msaa); MSAA get_msaa() const; + void set_screen_space_aa(ScreenSpaceAA p_screen_space_aa); + ScreenSpaceAA get_screen_space_aa() const; + Vector2 get_camera_coords(const Vector2 &p_viewport_coords) const; Vector2 get_camera_rect_size() const; void set_use_own_world(bool p_world); bool is_using_own_world() const; - void input(const Ref<InputEvent> &p_event); - void unhandled_input(const Ref<InputEvent> &p_event); + void input_text(const String &p_text); + void input(const Ref<InputEvent> &p_event, bool p_local_coords = false); + void unhandled_input(const Ref<InputEvent> &p_event, bool p_local_coords = false); void set_disable_input(bool p_disable); bool is_input_disabled() const; - void set_attach_to_screen_rect(const Rect2 &p_rect); - Rect2 get_attach_to_screen_rect() const; - - void set_use_render_direct_to_screen(bool p_render_direct_to_screen); - bool is_using_render_direct_to_screen() const; - Vector2 get_mouse_position() const; void warp_mouse(const Vector2 &p_pos); void set_physics_object_picking(bool p_enable); bool get_physics_object_picking(); - bool gui_has_modal_stack() const; - Variant gui_get_drag_data() const; - Control *get_modal_stack_top() const; void gui_reset_canvas_sort_index(); int gui_get_canvas_sort_index(); @@ -544,8 +550,6 @@ public: void set_snap_controls_to_pixels(bool p_enable); bool is_snap_controls_to_pixels_enabled() const; - void _subwindow_visibility_changed(); - void set_input_as_handled(); bool is_input_handled() const; @@ -560,15 +564,80 @@ public: void set_default_canvas_item_texture_repeat(DefaultCanvasItemTextureRepeat p_repeat); DefaultCanvasItemTextureRepeat get_default_canvas_item_texture_repeat() const; + virtual DisplayServer::WindowID get_window_id() const = 0; + + void set_embed_subwindows_hint(bool p_embed); + bool get_embed_subwindows_hint() const; + bool is_embedding_subwindows() const; + + Viewport *get_parent_viewport() const; + + void pass_mouse_focus_to(Viewport *p_viewport, Control *p_control); + Viewport(); ~Viewport(); }; -VARIANT_ENUM_CAST(Viewport::UpdateMode); +class SubViewport : public Viewport { + + GDCLASS(SubViewport, Viewport); + +public: + enum ClearMode { + + CLEAR_MODE_ALWAYS, + CLEAR_MODE_NEVER, + CLEAR_MODE_ONLY_NEXT_FRAME + }; + + enum UpdateMode { + UPDATE_DISABLED, + UPDATE_ONCE, //then goes to disabled + UPDATE_WHEN_VISIBLE, // default + UPDATE_WHEN_PARENT_VISIBLE, + UPDATE_ALWAYS + }; + +private: + UpdateMode update_mode; + ClearMode clear_mode; + bool xr; + bool size_2d_override_stretch; + +protected: + static void _bind_methods(); + virtual DisplayServer::WindowID get_window_id() const; + Transform2D _stretch_transform(); + void _notification(int p_what); + +public: + void set_size(const Size2i &p_size); + Size2i get_size() const; + + void set_size_2d_override(const Size2i &p_size); + Size2i get_size_2d_override() const; + + void set_use_xr(bool p_use_xr); + bool is_using_xr(); + + void set_size_2d_override_stretch(bool p_enable); + bool is_size_2d_override_stretch_enabled() const; + + void set_update_mode(UpdateMode p_mode); + UpdateMode get_update_mode() const; + + void set_clear_mode(ClearMode p_mode); + ClearMode get_clear_mode() const; + + SubViewport(); + ~SubViewport(); +}; +VARIANT_ENUM_CAST(SubViewport::UpdateMode); VARIANT_ENUM_CAST(Viewport::ShadowAtlasQuadrantSubdiv); VARIANT_ENUM_CAST(Viewport::MSAA); +VARIANT_ENUM_CAST(Viewport::ScreenSpaceAA); VARIANT_ENUM_CAST(Viewport::DebugDraw); -VARIANT_ENUM_CAST(Viewport::ClearMode); +VARIANT_ENUM_CAST(SubViewport::ClearMode); VARIANT_ENUM_CAST(Viewport::RenderInfo); VARIANT_ENUM_CAST(Viewport::DefaultCanvasItemTextureFilter); VARIANT_ENUM_CAST(Viewport::DefaultCanvasItemTextureRepeat); diff --git a/scene/main/window.cpp b/scene/main/window.cpp new file mode 100644 index 0000000000..19954299de --- /dev/null +++ b/scene/main/window.cpp @@ -0,0 +1,1406 @@ +/*************************************************************************/ +/* window.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 "window.h" + +#include "core/debugger/engine_debugger.h" +#include "core/os/keyboard.h" +#include "scene/gui/control.h" +#include "scene/resources/dynamic_font.h" +#include "scene/scene_string_names.h" + +void Window::set_title(const String &p_title) { + title = p_title; + + if (embedder) { + embedder->_sub_window_update(this); + + } else if (window_id != DisplayServer::INVALID_WINDOW_ID) { + + DisplayServer::get_singleton()->window_set_title(p_title, window_id); + } +} +String Window::get_title() const { + return title; +} + +void Window::set_current_screen(int p_screen) { + current_screen = p_screen; + if (window_id == DisplayServer::INVALID_WINDOW_ID) + return; + DisplayServer::get_singleton()->window_set_current_screen(p_screen, window_id); +} +int Window::get_current_screen() const { + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + current_screen = DisplayServer::get_singleton()->window_get_current_screen(window_id); + } + return current_screen; +} + +void Window::set_position(const Point2i &p_position) { + + position = p_position; + + if (embedder) { + embedder->_sub_window_update(this); + + } else if (window_id != DisplayServer::INVALID_WINDOW_ID) { + + DisplayServer::get_singleton()->window_set_position(p_position, window_id); + } +} +Point2i Window::get_position() const { + return position; +} + +void Window::set_size(const Size2i &p_size) { + size = p_size; + _update_window_size(); +} +Size2i Window::get_size() const { + + return size; +} + +Size2i Window::get_real_size() const { + + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + return DisplayServer::get_singleton()->window_get_real_size(window_id); + } + return size; +} + +void Window::set_max_size(const Size2i &p_max_size) { + max_size = p_max_size; + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_max_size(max_size, window_id); + } + _update_window_size(); +} + +Size2i Window::get_max_size() const { + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + max_size = DisplayServer::get_singleton()->window_get_max_size(window_id); + } + return max_size; +} + +void Window::set_min_size(const Size2i &p_min_size) { + min_size = p_min_size; + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_min_size(min_size, window_id); + } + _update_window_size(); +} + +Size2i Window::get_min_size() const { + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + min_size = DisplayServer::get_singleton()->window_get_min_size(window_id); + } + return min_size; +} + +void Window::set_mode(Mode p_mode) { + + mode = p_mode; + + if (embedder) { + embedder->_sub_window_update(this); + + } else if (window_id != DisplayServer::INVALID_WINDOW_ID) { + + DisplayServer::get_singleton()->window_set_mode(DisplayServer::WindowMode(p_mode), window_id); + } +} + +Window::Mode Window::get_mode() const { + + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + mode = (Mode)DisplayServer::get_singleton()->window_get_mode(window_id); + } + return mode; +} + +void Window::set_flag(Flags p_flag, bool p_enabled) { + ERR_FAIL_INDEX(p_flag, FLAG_MAX); + flags[p_flag] = p_enabled; + + if (embedder) { + embedder->_sub_window_update(this); + + } else if (window_id != DisplayServer::INVALID_WINDOW_ID) { + + DisplayServer::get_singleton()->window_set_flag(DisplayServer::WindowFlags(p_flag), p_enabled, window_id); + } +} + +bool Window::get_flag(Flags p_flag) const { + ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + flags[p_flag] = DisplayServer::get_singleton()->window_get_flag(DisplayServer::WindowFlags(p_flag), window_id); + } + return flags[p_flag]; +} + +bool Window::is_maximize_allowed() const { + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + return DisplayServer::get_singleton()->window_is_maximize_allowed(window_id); + } + return true; +} + +void Window::request_attention() { + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_request_attention(window_id); + } +} +void Window::move_to_foreground() { + + if (embedder) { + embedder->_sub_window_grab_focus(this); + + } else if (window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_move_to_foreground(window_id); + } +} + +bool Window::can_draw() const { + if (!is_inside_tree()) { + return false; + } + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + return DisplayServer::get_singleton()->window_can_draw(window_id); + } + + return visible; +} + +void Window::set_ime_active(bool p_active) { + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_ime_active(p_active, window_id); + } +} +void Window::set_ime_position(const Point2i &p_pos) { + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_ime_position(p_pos, window_id); + } +} + +bool Window::is_embedded() const { + ERR_FAIL_COND_V(!is_inside_tree(), false); + + return _get_embedder() != nullptr; +} + +void Window::_make_window() { + ERR_FAIL_COND(window_id != DisplayServer::INVALID_WINDOW_ID); + + uint32_t f = 0; + for (int i = 0; i < FLAG_MAX; i++) { + if (flags[i]) { + f |= (1 << i); + } + } + + window_id = DisplayServer::get_singleton()->create_sub_window(DisplayServer::WindowMode(mode), f, Rect2i(position, size)); + ERR_FAIL_COND(window_id == DisplayServer::INVALID_WINDOW_ID); + DisplayServer::get_singleton()->window_set_current_screen(current_screen, window_id); + DisplayServer::get_singleton()->window_set_max_size(max_size, window_id); + DisplayServer::get_singleton()->window_set_min_size(min_size, window_id); + DisplayServer::get_singleton()->window_set_title(title, window_id); + DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id); + + _update_window_size(); + + if (transient_parent && transient_parent->window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_transient(window_id, transient_parent->window_id); + } + + for (Set<Window *>::Element *E = transient_children.front(); E; E = E->next()) { + if (E->get()->window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_transient(E->get()->window_id, transient_parent->window_id); + } + } + + RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_VISIBLE); +} +void Window::_update_from_window() { + + ERR_FAIL_COND(window_id == DisplayServer::INVALID_WINDOW_ID); + mode = (Mode)DisplayServer::get_singleton()->window_get_mode(window_id); + for (int i = 0; i < FLAG_MAX; i++) { + flags[i] = DisplayServer::get_singleton()->window_get_flag(DisplayServer::WindowFlags(i), window_id); + } +} + +void Window::_clear_window() { + ERR_FAIL_COND(window_id == DisplayServer::INVALID_WINDOW_ID); + + if (transient_parent && transient_parent->window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_transient(window_id, DisplayServer::INVALID_WINDOW_ID); + } + + for (Set<Window *>::Element *E = transient_children.front(); E; E = E->next()) { + if (E->get()->window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_transient(E->get()->window_id, DisplayServer::INVALID_WINDOW_ID); + } + } + + _update_from_window(); + + DisplayServer::get_singleton()->delete_sub_window(window_id); + window_id = DisplayServer::INVALID_WINDOW_ID; + + _update_viewport_size(); + RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED); +} + +void Window::_rect_changed_callback(const Rect2i &p_callback) { + + //we must always accept this as the truth + if (size == p_callback.size && position == p_callback.position) { + return; + } + position = p_callback.position; + + if (size != p_callback.size) { + size = p_callback.size; + _update_viewport_size(); + } +} + +void Window::_propagate_window_notification(Node *p_node, int p_notification) { + p_node->notification(p_notification); + for (int i = 0; i < p_node->get_child_count(); i++) { + Node *child = p_node->get_child(i); + Window *window = Object::cast_to<Window>(child); + if (window) { + break; + } + _propagate_window_notification(child, p_notification); + } +} + +void Window::_event_callback(DisplayServer::WindowEvent p_event) { + + switch (p_event) { + case DisplayServer::WINDOW_EVENT_MOUSE_ENTER: { + _propagate_window_notification(this, NOTIFICATION_WM_MOUSE_ENTER); + emit_signal("mouse_entered"); + } break; + case DisplayServer::WINDOW_EVENT_MOUSE_EXIT: { + _propagate_window_notification(this, NOTIFICATION_WM_MOUSE_EXIT); + emit_signal("mouse_exited"); + } break; + case DisplayServer::WINDOW_EVENT_FOCUS_IN: { + focused = true; + _propagate_window_notification(this, NOTIFICATION_WM_FOCUS_IN); + emit_signal("focus_entered"); + + } break; + case DisplayServer::WINDOW_EVENT_FOCUS_OUT: { + focused = false; + _propagate_window_notification(this, NOTIFICATION_WM_FOCUS_OUT); + emit_signal("focus_exited"); + } break; + case DisplayServer::WINDOW_EVENT_CLOSE_REQUEST: { + if (exclusive_child != nullptr) { + break; //has an exclusive child, can't get events until child is closed + } + _propagate_window_notification(this, NOTIFICATION_WM_CLOSE_REQUEST); + emit_signal("close_requested"); + } break; + case DisplayServer::WINDOW_EVENT_GO_BACK_REQUEST: { + _propagate_window_notification(this, NOTIFICATION_WM_GO_BACK_REQUEST); + emit_signal("go_back_requested"); + } break; + case DisplayServer::WINDOW_EVENT_DPI_CHANGE: { + _propagate_window_notification(this, NOTIFICATION_WM_DPI_CHANGE); + emit_signal("dpi_changed"); + } break; + } +} + +void Window::show() { + set_visible(true); +} +void Window::hide() { + set_visible(false); +} + +void Window::set_visible(bool p_visible) { + + if (visible == p_visible) { + return; + } + + visible = p_visible; + + if (!is_inside_tree()) { + return; + } + + if (updating_child_controls) { + _update_child_controls(); + } + + ERR_FAIL_COND_MSG(get_parent() == nullptr, "Can't change visibility of main window."); + + Viewport *embedder_vp = _get_embedder(); + + if (!embedder_vp) { + if (!p_visible && window_id != DisplayServer::INVALID_WINDOW_ID) { + _clear_window(); + } + if (p_visible && window_id == DisplayServer::INVALID_WINDOW_ID) { + _make_window(); + _update_window_callbacks(); + } + } else { + if (visible) { + embedder = embedder_vp; + embedder->_sub_window_register(this); + RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE); + } else { + embedder->_sub_window_remove(this); + embedder = nullptr; + RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED); + } + _update_window_size(); + } + + if (!visible) { + focused = false; + } + notification(NOTIFICATION_VISIBILITY_CHANGED); + emit_signal(SceneStringNames::get_singleton()->visibility_changed); + + RS::get_singleton()->viewport_set_active(get_viewport_rid(), visible); +} + +void Window::_clear_transient() { + if (transient_parent) { + if (transient_parent->window_id != DisplayServer::INVALID_WINDOW_ID && window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_transient(window_id, DisplayServer::INVALID_WINDOW_ID); + } + transient_parent->transient_children.erase(this); + if (transient_parent->exclusive_child == this) { + transient_parent->exclusive_child = nullptr; + } + transient_parent = nullptr; + } +} + +void Window::_make_transient() { + if (!get_parent()) { + //main window, can't be transient + return; + } + //find transient parent + Viewport *vp = get_parent()->get_viewport(); + Window *window = nullptr; + while (vp) { + window = Object::cast_to<Window>(vp); + if (window) { + break; + } + if (!vp->get_parent()) { + break; + } + + vp = vp->get_parent()->get_viewport(); + } + + if (window) { + transient_parent = window; + window->transient_children.insert(this); + if (is_inside_tree() && is_visible() && exclusive) { + if (transient_parent->exclusive_child == nullptr) { + transient_parent->exclusive_child = this; + } else if (transient_parent->exclusive_child != this) { + ERR_PRINT("Making child transient exclusive, but parent has another exclusive child"); + } + } + } + + //see if we can make transient + if (transient_parent->window_id != DisplayServer::INVALID_WINDOW_ID && window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_transient(window_id, transient_parent->window_id); + } +} + +void Window::set_transient(bool p_transient) { + if (transient == p_transient) { + return; + } + + transient = p_transient; + + if (!is_inside_tree()) { + return; + } + + if (transient) { + _make_transient(); + } else { + _clear_transient(); + } +} +bool Window::is_transient() const { + return transient; +} + +void Window::set_exclusive(bool p_exclusive) { + + if (exclusive == p_exclusive) { + return; + } + + exclusive = p_exclusive; + + if (transient_parent) { + if (p_exclusive && is_inside_tree() && is_visible()) { + ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child."); + transient_parent->exclusive_child = this; + } else { + if (transient_parent->exclusive_child == this) { + transient_parent->exclusive_child = nullptr; + } + } + } +} + +bool Window::is_exclusive() const { + return exclusive; +} + +bool Window::is_visible() const { + return visible; +} + +void Window::_update_window_size() { + + Size2i size_limit; + if (wrap_controls) { + size_limit = get_contents_minimum_size(); + } + + size_limit.x = MAX(size_limit.x, min_size.x); + size_limit.y = MAX(size_limit.y, min_size.y); + + size.x = MAX(size_limit.x, size.x); + size.y = MAX(size_limit.y, size.y); + + if (max_size.x > 0 && max_size.x > min_size.x && max_size.x > size.x) { + size.x = max_size.x; + } + + if (max_size.y > 0 && max_size.y > min_size.y && max_size.y > size.y) { + size.y = max_size.y; + } + + if (embedder) { + embedder->_sub_window_update(this); + } else if (window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_set_size(size, window_id); + } + + //update the viewport + _update_viewport_size(); +} +void Window::_update_viewport_size() { + //update the viewport part + + Size2i final_size; + Size2i final_size_override; + Rect2i attach_to_screen_rect(Point2i(), size); + Transform2D stretch_transform; + float font_oversampling = 1.0; + + if (content_scale_mode == CONTENT_SCALE_MODE_DISABLED || content_scale_size.x == 0 || content_scale_size.y == 0) { + + stretch_transform = Transform2D(); + final_size = size; + + } else { + + //actual screen video mode + Size2 video_mode = size; + Size2 desired_res = content_scale_size; + + Size2 viewport_size; + Size2 screen_size; + + float viewport_aspect = desired_res.aspect(); + float video_mode_aspect = video_mode.aspect(); + + if (content_scale_aspect == CONTENT_SCALE_ASPECT_IGNORE || Math::is_equal_approx(viewport_aspect, video_mode_aspect)) { + //same aspect or ignore aspect + viewport_size = desired_res; + screen_size = video_mode; + } else if (viewport_aspect < video_mode_aspect) { + // screen ratio is smaller vertically + + if (content_scale_aspect == CONTENT_SCALE_ASPECT_KEEP_HEIGHT || content_scale_aspect == CONTENT_SCALE_ASPECT_EXPAND) { + + //will stretch horizontally + viewport_size.x = desired_res.y * video_mode_aspect; + viewport_size.y = desired_res.y; + screen_size = video_mode; + + } else { + //will need black bars + viewport_size = desired_res; + screen_size.x = video_mode.y * viewport_aspect; + screen_size.y = video_mode.y; + } + } else { + //screen ratio is smaller horizontally + if (content_scale_aspect == CONTENT_SCALE_ASPECT_KEEP_WIDTH || content_scale_aspect == CONTENT_SCALE_ASPECT_EXPAND) { + + //will stretch horizontally + viewport_size.x = desired_res.x; + viewport_size.y = desired_res.x / video_mode_aspect; + screen_size = video_mode; + + } else { + //will need black bars + viewport_size = desired_res; + screen_size.x = video_mode.x; + screen_size.y = video_mode.x / viewport_aspect; + } + } + + screen_size = screen_size.floor(); + viewport_size = viewport_size.floor(); + + Size2 margin; + Size2 offset; + //black bars and margin + if (content_scale_aspect != CONTENT_SCALE_ASPECT_EXPAND && screen_size.x < video_mode.x) { + margin.x = Math::round((video_mode.x - screen_size.x) / 2.0); + //RenderingServer::get_singleton()->black_bars_set_margins(margin.x, 0, margin.x, 0); + offset.x = Math::round(margin.x * viewport_size.y / screen_size.y); + } else if (content_scale_aspect != CONTENT_SCALE_ASPECT_EXPAND && screen_size.y < video_mode.y) { + margin.y = Math::round((video_mode.y - screen_size.y) / 2.0); + //RenderingServer::get_singleton()->black_bars_set_margins(0, margin.y, 0, margin.y); + offset.y = Math::round(margin.y * viewport_size.x / screen_size.x); + } else { + //RenderingServer::get_singleton()->black_bars_set_margins(0, 0, 0, 0); + } + + switch (content_scale_mode) { + case CONTENT_SCALE_MODE_DISABLED: { + // Already handled above + //_update_font_oversampling(1.0); + } break; + case CONTENT_SCALE_MODE_OBJECTS: { + + final_size = screen_size; + final_size_override = viewport_size; + attach_to_screen_rect = Rect2(margin, screen_size); + font_oversampling = screen_size.x / viewport_size.x; + } break; + case CONTENT_SCALE_MODE_PIXELS: { + + final_size = viewport_size; + attach_to_screen_rect = Rect2(margin, screen_size); + + } break; + } + + Size2 scale = size / (Vector2(final_size) + margin * 2); + stretch_transform.scale(scale); + stretch_transform.elements[2] = margin * scale; + } + + bool allocate = is_inside_tree() && visible && (window_id != DisplayServer::INVALID_WINDOW_ID || embedder != nullptr); + + _set_size(final_size, final_size_override, attach_to_screen_rect, stretch_transform, allocate); + + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + RenderingServer::get_singleton()->viewport_attach_to_screen(get_viewport_rid(), attach_to_screen_rect, window_id); + } else { + RenderingServer::get_singleton()->viewport_attach_to_screen(get_viewport_rid(), Rect2i(), DisplayServer::INVALID_WINDOW_ID); + } + + if (window_id == DisplayServer::MAIN_WINDOW_ID) { + + if (!use_font_oversampling) { + font_oversampling = 1.0; + } + if (DynamicFontAtSize::font_oversampling != font_oversampling) { + + DynamicFontAtSize::font_oversampling = font_oversampling; + DynamicFont::update_oversampling(); + } + } + + notification(NOTIFICATION_WM_SIZE_CHANGED); + + if (embedder) { + embedder->_sub_window_update(this); + } +} + +void Window::_update_window_callbacks() { + DisplayServer::get_singleton()->window_set_rect_changed_callback(callable_mp(this, &Window::_rect_changed_callback), window_id); + DisplayServer::get_singleton()->window_set_window_event_callback(callable_mp(this, &Window::_event_callback), window_id); + DisplayServer::get_singleton()->window_set_input_event_callback(callable_mp(this, &Window::_window_input), window_id); + DisplayServer::get_singleton()->window_set_input_text_callback(callable_mp(this, &Window::_window_input_text), window_id); + DisplayServer::get_singleton()->window_set_drop_files_callback(callable_mp(this, &Window::_window_drop_files), window_id); +} + +Viewport *Window::_get_embedder() const { + + Viewport *vp = get_parent_viewport(); + + while (vp) { + + if (vp->is_embedding_subwindows()) { + return vp; + } + + if (vp->get_parent()) { + vp = vp->get_parent()->get_viewport(); + } else { + vp = nullptr; + } + } + return nullptr; +} + +void Window::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE) { + + bool embedded = false; + { + + embedder = _get_embedder(); + + if (embedder) { + embedded = true; + + if (!visible) { + embedder = nullptr; //not yet since not visible + } + } + } + + if (embedded) { + //create as embedded + if (embedder) { + embedder->_sub_window_register(this); + RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE); + _update_window_size(); + } + + } else { + if (get_parent() == nullptr) { + //it's the root window! + visible = true; //always visible + window_id = DisplayServer::MAIN_WINDOW_ID; + DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id); + _update_from_window(); + //since this window already exists (created on start), we must update pos and size from it + { + position = DisplayServer::get_singleton()->window_get_position(window_id); + size = DisplayServer::get_singleton()->window_get_size(window_id); + } + _update_viewport_size(); //then feed back to the viewport + _update_window_callbacks(); + RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_VISIBLE); + } else { + //create + if (visible) { + _make_window(); + _update_window_callbacks(); + } + } + } + + if (transient) { + _make_transient(); + } + if (visible) { + notification(NOTIFICATION_VISIBILITY_CHANGED); + emit_signal(SceneStringNames::get_singleton()->visibility_changed); + RS::get_singleton()->viewport_set_active(get_viewport_rid(), true); + } + } + + if (p_what == NOTIFICATION_READY) { + + if (wrap_controls) { + _update_child_controls(); + } + } + + if (p_what == NOTIFICATION_EXIT_TREE) { + + if (transient) { + _clear_transient(); + } + + if (!is_embedded() && window_id != DisplayServer::INVALID_WINDOW_ID) { + + if (window_id == DisplayServer::MAIN_WINDOW_ID) { + + RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED); + _update_window_callbacks(); + } else { + _clear_window(); + } + } else { + + if (embedder) { + embedder->_sub_window_remove(this); + embedder = nullptr; + RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED); + } + _update_viewport_size(); //called by clear and make, which does not happen here + } + + RS::get_singleton()->viewport_set_active(get_viewport_rid(), false); + } +} + +void Window::set_content_scale_size(const Size2i &p_size) { + ERR_FAIL_COND(p_size.x < 0); + ERR_FAIL_COND(p_size.y < 0); + content_scale_size = p_size; + _update_viewport_size(); +} + +Size2i Window::get_content_scale_size() const { + return content_scale_size; +} + +void Window::set_content_scale_mode(ContentScaleMode p_mode) { + content_scale_mode = p_mode; + _update_viewport_size(); +} +Window::ContentScaleMode Window::get_content_scale_mode() const { + return content_scale_mode; +} + +void Window::set_content_scale_aspect(ContentScaleAspect p_aspect) { + content_scale_aspect = p_aspect; + _update_viewport_size(); +} +Window::ContentScaleAspect Window::get_content_scale_aspect() const { + return content_scale_aspect; +} + +void Window::set_use_font_oversampling(bool p_oversampling) { + if (is_inside_tree() && window_id != DisplayServer::MAIN_WINDOW_ID) { + ERR_FAIL_MSG("Only the root window can set and use font oversampling."); + } + use_font_oversampling = p_oversampling; + _update_viewport_size(); +} +bool Window::is_using_font_oversampling() const { + return use_font_oversampling; +} + +DisplayServer::WindowID Window::get_window_id() const { + return window_id; +} + +void Window::set_wrap_controls(bool p_enable) { + wrap_controls = p_enable; + if (wrap_controls) { + child_controls_changed(); + } +} + +bool Window::is_wrapping_controls() const { + return wrap_controls; +} + +Size2 Window::_get_contents_minimum_size() const { + Size2 max; + + for (int i = 0; i < get_child_count(); i++) { + Control *c = Object::cast_to<Control>(get_child(i)); + if (c) { + Point2i pos = c->get_position(); + Size2i min = c->get_combined_minimum_size(); + + max.x = MAX(pos.x + min.x, max.x); + max.y = MAX(pos.y + min.y, max.y); + } + } + + return max; +} +void Window::_update_child_controls() { + + if (!updating_child_controls) { + return; + } + + _update_window_size(); + + updating_child_controls = false; +} +void Window::child_controls_changed() { + + if (!is_inside_tree() || !visible || updating_child_controls) { + return; + } + + updating_child_controls = true; + call_deferred("_update_child_controls"); +} + +void Window::_window_input(const Ref<InputEvent> &p_ev) { + if (Engine::get_singleton()->is_editor_hint() && (Object::cast_to<InputEventJoypadButton>(p_ev.ptr()) || Object::cast_to<InputEventJoypadMotion>(*p_ev))) + return; //avoid joy input on editor + + if (EngineDebugger::is_active()) { + //quit from game window using F8 + Ref<InputEventKey> k = p_ev; + if (k.is_valid() && k->is_pressed() && !k->is_echo() && k->get_keycode() == KEY_F8) { + EngineDebugger::get_singleton()->send_message("request_quit", Array()); + } + } + + if (exclusive_child != nullptr) { + exclusive_child->grab_focus(); + + return; //has an exclusive child, can't get events until child is closed + } + + emit_signal(SceneStringNames::get_singleton()->window_input, p_ev); + input(p_ev); + if (!is_input_handled()) { + unhandled_input(p_ev); + } +} +void Window::_window_input_text(const String &p_text) { + input_text(p_text); +} +void Window::_window_drop_files(const Vector<String> &p_files) { + emit_signal("files_dropped", p_files, current_screen); +} + +Viewport *Window::get_parent_viewport() const { + + if (get_parent()) { + return get_parent()->get_viewport(); + } else { + return nullptr; + } +} + +Window *Window::get_parent_visible_window() const { + + Viewport *vp = get_parent_viewport(); + Window *window = nullptr; + while (vp) { + window = Object::cast_to<Window>(vp); + if (window && window->visible) { + break; + } + if (!vp->get_parent()) { + break; + } + + vp = vp->get_parent()->get_viewport(); + } + return window; +} + +void Window::popup_on_parent(const Rect2i &p_parent_rect) { + + ERR_FAIL_COND(!is_inside_tree()); + ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window."); + + if (!is_embedded()) { + Window *window = get_parent_visible_window(); + + if (!window) { + popup(p_parent_rect); + } else { + popup(Rect2i(window->get_position() + p_parent_rect.position, p_parent_rect.size)); + } + } else { + popup(p_parent_rect); + } +} + +void Window::popup_centered_clamped(const Size2i &p_size, float p_fallback_ratio) { + + ERR_FAIL_COND(!is_inside_tree()); + ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window."); + + Rect2 parent_rect; + + if (is_embedded()) { + parent_rect = get_parent_viewport()->get_visible_rect(); + } else { + DisplayServer::WindowID parent_id = get_parent_visible_window()->get_window_id(); + int parent_screen = DisplayServer::get_singleton()->window_get_current_screen(parent_id); + parent_rect.position = DisplayServer::get_singleton()->screen_get_position(parent_screen); + parent_rect.size = DisplayServer::get_singleton()->screen_get_size(parent_screen); + } + + Vector2i size_ratio = parent_rect.size * p_fallback_ratio; + + Rect2i popup_rect; + popup_rect.size = Vector2i(MIN(size_ratio.x, p_size.x), MIN(size_ratio.y, p_size.y)); + popup_rect.position = (parent_rect.size - popup_rect.size) / 2; + + popup(popup_rect); +} + +void Window::popup_centered(const Size2i &p_minsize) { + ERR_FAIL_COND(!is_inside_tree()); + ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window."); + + Rect2 parent_rect; + + if (is_embedded()) { + parent_rect = get_parent_viewport()->get_visible_rect(); + } else { + DisplayServer::WindowID parent_id = get_parent_visible_window()->get_window_id(); + int parent_screen = DisplayServer::get_singleton()->window_get_current_screen(parent_id); + parent_rect.position = DisplayServer::get_singleton()->screen_get_position(parent_screen); + parent_rect.size = DisplayServer::get_singleton()->screen_get_size(parent_screen); + } + + Rect2i popup_rect; + if (p_minsize == Size2i()) { + popup_rect.size = _get_contents_minimum_size(); + } else { + popup_rect.size = p_minsize; + } + popup_rect.position = (parent_rect.size - popup_rect.size) / 2; + + popup(popup_rect); +} + +void Window::popup_centered_ratio(float p_ratio) { + + ERR_FAIL_COND(!is_inside_tree()); + ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window."); + + Rect2i parent_rect; + + if (is_embedded()) { + parent_rect = get_parent_viewport()->get_visible_rect(); + } else { + DisplayServer::WindowID parent_id = get_parent_visible_window()->get_window_id(); + int parent_screen = DisplayServer::get_singleton()->window_get_current_screen(parent_id); + parent_rect.position = DisplayServer::get_singleton()->screen_get_position(parent_screen); + parent_rect.size = DisplayServer::get_singleton()->screen_get_size(parent_screen); + } + + Rect2i popup_rect; + popup_rect.size = parent_rect.size * p_ratio; + popup_rect.position = (parent_rect.size - popup_rect.size) / 2; + + popup(popup_rect); +} + +void Window::popup(const Rect2i &p_screen_rect) { + + emit_signal("about_to_popup"); + + if (p_screen_rect != Rect2i()) { + set_position(p_screen_rect.position); + set_size(p_screen_rect.size); + } + + Rect2i adjust = _popup_adjust_rect(); + if (adjust != Rect2i()) { + set_position(adjust.position); + set_size(adjust.size); + } + + set_transient(true); + set_visible(true); + _post_popup(); + notification(NOTIFICATION_POST_POPUP); +} + +Size2 Window::get_contents_minimum_size() const { + return _get_contents_minimum_size(); +} + +void Window::grab_focus() { + if (embedder) { + embedder->_sub_window_grab_focus(this); + } else if (window_id != DisplayServer::INVALID_WINDOW_ID) { + DisplayServer::get_singleton()->window_move_to_foreground(window_id); + } +} + +bool Window::has_focus() const { + return focused; +} + +Rect2i Window::get_usable_parent_rect() const { + ERR_FAIL_COND_V(!is_inside_tree(), Rect2()); + Rect2i parent; + if (is_embedded()) { + parent = _get_embedder()->get_visible_rect(); + } else { + + const Window *w = is_visible() ? this : get_parent_visible_window(); + //find a parent that can contain us + ERR_FAIL_COND_V(!w, Rect2()); + + parent = DisplayServer::get_singleton()->screen_get_usable_rect(DisplayServer::get_singleton()->window_get_current_screen(w->get_window_id())); + } + return parent; +} + +void Window::add_child_notify(Node *p_child) { + + Control *child_c = Object::cast_to<Control>(p_child); + + if (child_c && child_c->data.theme.is_null() && (theme_owner || theme_owner_window)) { + Control::_propagate_theme_changed(child_c, theme_owner, theme_owner_window); //need to propagate here, since many controls may require setting up stuff + } + + Window *child_w = Object::cast_to<Window>(p_child); + + if (child_w && child_w->theme.is_null() && (theme_owner || theme_owner_window)) { + Control::_propagate_theme_changed(child_w, theme_owner, theme_owner_window); //need to propagate here, since many controls may require setting up stuff + } + + if (is_inside_tree() && wrap_controls) { + child_controls_changed(); + } +} + +void Window::remove_child_notify(Node *p_child) { + + Control *child_c = Object::cast_to<Control>(p_child); + + if (child_c && (child_c->data.theme_owner || child_c->data.theme_owner_window) && child_c->data.theme.is_null()) { + Control::_propagate_theme_changed(child_c, nullptr, nullptr); + } + + Window *child_w = Object::cast_to<Window>(p_child); + + if (child_w && (child_w->theme_owner || child_w->theme_owner_window) && child_w->theme.is_null()) { + Control::_propagate_theme_changed(child_w, nullptr, nullptr); + } + + if (is_inside_tree() && wrap_controls) { + child_controls_changed(); + } +} + +void Window::set_theme(const Ref<Theme> &p_theme) { + + if (theme == p_theme) + return; + + theme = p_theme; + + if (!p_theme.is_null()) { + + theme_owner = nullptr; + theme_owner_window = this; + Control::_propagate_theme_changed(this, nullptr, this); + } else { + + Control *parent_c = cast_to<Control>(get_parent()); + if (parent_c && (parent_c->data.theme_owner || parent_c->data.theme_owner_window)) { + Control::_propagate_theme_changed(this, parent_c->data.theme_owner, parent_c->data.theme_owner_window); + } else { + Window *parent_w = cast_to<Window>(get_parent()); + if (parent_w && (parent_w->theme_owner || parent_w->theme_owner_window)) { + Control::_propagate_theme_changed(this, parent_w->theme_owner, parent_w->theme_owner_window); + } else { + Control::_propagate_theme_changed(this, nullptr, nullptr); + } + } + } +} +Ref<Theme> Window::get_theme() const { + return theme; +} + +Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName &p_type) const { + StringName type = p_type ? p_type : get_class_name(); + return Control::get_icons(theme_owner, theme_owner_window, p_name, type); +} +Ref<Shader> Window::get_theme_shader(const StringName &p_name, const StringName &p_type) const { + StringName type = p_type ? p_type : get_class_name(); + return Control::get_shaders(theme_owner, theme_owner_window, p_name, type); +} +Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringName &p_type) const { + StringName type = p_type ? p_type : get_class_name(); + return Control::get_styleboxs(theme_owner, theme_owner_window, p_name, type); +} +Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_type) const { + StringName type = p_type ? p_type : get_class_name(); + return Control::get_fonts(theme_owner, theme_owner_window, p_name, type); +} +Color Window::get_theme_color(const StringName &p_name, const StringName &p_type) const { + StringName type = p_type ? p_type : get_class_name(); + return Control::get_colors(theme_owner, theme_owner_window, p_name, type); +} +int Window::get_theme_constant(const StringName &p_name, const StringName &p_type) const { + StringName type = p_type ? p_type : get_class_name(); + return Control::get_constants(theme_owner, theme_owner_window, p_name, type); +} + +bool Window::has_theme_icon(const StringName &p_name, const StringName &p_type) const { + StringName type = p_type ? p_type : get_class_name(); + return Control::has_icons(theme_owner, theme_owner_window, p_name, type); +} +bool Window::has_theme_shader(const StringName &p_name, const StringName &p_type) const { + StringName type = p_type ? p_type : get_class_name(); + return Control::has_shaders(theme_owner, theme_owner_window, p_name, type); +} +bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_type) const { + StringName type = p_type ? p_type : get_class_name(); + return Control::has_styleboxs(theme_owner, theme_owner_window, p_name, type); +} +bool Window::has_theme_font(const StringName &p_name, const StringName &p_type) const { + StringName type = p_type ? p_type : get_class_name(); + return Control::has_fonts(theme_owner, theme_owner_window, p_name, type); +} +bool Window::has_theme_color(const StringName &p_name, const StringName &p_type) const { + StringName type = p_type ? p_type : get_class_name(); + return Control::has_colors(theme_owner, theme_owner_window, p_name, type); +} +bool Window::has_theme_constant(const StringName &p_name, const StringName &p_type) const { + StringName type = p_type ? p_type : get_class_name(); + return Control::has_constants(theme_owner, theme_owner_window, p_name, type); +} + +Rect2i Window::get_parent_rect() const { + ERR_FAIL_COND_V(!is_inside_tree(), Rect2i()); + if (is_embedded()) { + //viewport + Node *n = get_parent(); + ERR_FAIL_COND_V(!n, Rect2i()); + Viewport *p = n->get_viewport(); + ERR_FAIL_COND_V(!p, Rect2i()); + + return p->get_visible_rect(); + } else { + int x = get_position().x; + int closest_dist = 0x7FFFFFFF; + Rect2i closest_rect; + for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) { + Rect2i s(DisplayServer::get_singleton()->screen_get_position(i), DisplayServer::get_singleton()->screen_get_size(i)); + int d; + if (x >= s.position.x && x < s.size.x) { + //contained + closest_rect = s; + break; + } else if (x < s.position.x) { + d = s.position.x - x; + } else { + d = x - (s.position.x + s.size.x); + } + + if (d < closest_dist) { + closest_dist = d; + closest_rect = s; + } + } + return closest_rect; + } +} + +void Window::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_title", "title"), &Window::set_title); + ClassDB::bind_method(D_METHOD("get_title"), &Window::get_title); + + ClassDB::bind_method(D_METHOD("set_current_screen", "index"), &Window::set_current_screen); + ClassDB::bind_method(D_METHOD("get_current_screen"), &Window::get_current_screen); + + ClassDB::bind_method(D_METHOD("set_position", "position"), &Window::set_position); + ClassDB::bind_method(D_METHOD("get_position"), &Window::get_position); + + ClassDB::bind_method(D_METHOD("set_size", "size"), &Window::set_size); + ClassDB::bind_method(D_METHOD("get_size"), &Window::get_size); + + ClassDB::bind_method(D_METHOD("get_real_size"), &Window::get_real_size); + + ClassDB::bind_method(D_METHOD("set_max_size", "max_size"), &Window::set_max_size); + ClassDB::bind_method(D_METHOD("get_max_size"), &Window::get_max_size); + + ClassDB::bind_method(D_METHOD("set_min_size", "min_size"), &Window::set_min_size); + ClassDB::bind_method(D_METHOD("get_min_size"), &Window::get_min_size); + + ClassDB::bind_method(D_METHOD("set_mode", "mode"), &Window::set_mode); + ClassDB::bind_method(D_METHOD("get_mode"), &Window::get_mode); + + ClassDB::bind_method(D_METHOD("set_flag", "flag", "enabled"), &Window::set_flag); + ClassDB::bind_method(D_METHOD("get_flag", "flag"), &Window::get_flag); + + ClassDB::bind_method(D_METHOD("is_maximize_allowed"), &Window::is_maximize_allowed); + + ClassDB::bind_method(D_METHOD("request_attention"), &Window::request_attention); + + ClassDB::bind_method(D_METHOD("move_to_foreground"), &Window::move_to_foreground); + + ClassDB::bind_method(D_METHOD("set_visible", "visible"), &Window::set_visible); + ClassDB::bind_method(D_METHOD("is_visible"), &Window::is_visible); + + ClassDB::bind_method(D_METHOD("hide"), &Window::hide); + ClassDB::bind_method(D_METHOD("show"), &Window::show); + + ClassDB::bind_method(D_METHOD("set_transient", "transient"), &Window::set_transient); + ClassDB::bind_method(D_METHOD("is_transient"), &Window::is_transient); + + ClassDB::bind_method(D_METHOD("set_exclusive", "exclusive"), &Window::set_exclusive); + ClassDB::bind_method(D_METHOD("is_exclusive"), &Window::is_exclusive); + + ClassDB::bind_method(D_METHOD("can_draw"), &Window::can_draw); + ClassDB::bind_method(D_METHOD("has_focus"), &Window::has_focus); + ClassDB::bind_method(D_METHOD("grab_focus"), &Window::grab_focus); + + ClassDB::bind_method(D_METHOD("set_ime_active"), &Window::set_ime_active); + ClassDB::bind_method(D_METHOD("set_ime_position"), &Window::set_ime_position); + + ClassDB::bind_method(D_METHOD("is_embedded"), &Window::is_embedded); + + ClassDB::bind_method(D_METHOD("set_content_scale_size", "size"), &Window::set_content_scale_size); + ClassDB::bind_method(D_METHOD("get_content_scale_size"), &Window::get_content_scale_size); + + ClassDB::bind_method(D_METHOD("set_content_scale_mode", "mode"), &Window::set_content_scale_mode); + ClassDB::bind_method(D_METHOD("get_content_scale_mode"), &Window::get_content_scale_mode); + + ClassDB::bind_method(D_METHOD("set_content_scale_aspect", "aspect"), &Window::set_content_scale_aspect); + ClassDB::bind_method(D_METHOD("get_content_scale_aspect"), &Window::get_content_scale_aspect); + + ClassDB::bind_method(D_METHOD("set_use_font_oversampling", "enable"), &Window::set_use_font_oversampling); + ClassDB::bind_method(D_METHOD("is_using_font_oversampling"), &Window::is_using_font_oversampling); + + ClassDB::bind_method(D_METHOD("set_wrap_controls", "enable"), &Window::set_wrap_controls); + ClassDB::bind_method(D_METHOD("is_wrapping_controls"), &Window::is_wrapping_controls); + ClassDB::bind_method(D_METHOD("child_controls_changed"), &Window::child_controls_changed); + + ClassDB::bind_method(D_METHOD("_update_child_controls"), &Window::_update_child_controls); + + ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Window::set_theme); + ClassDB::bind_method(D_METHOD("get_theme"), &Window::get_theme); + + ClassDB::bind_method(D_METHOD("get_theme_icon", "name", "type"), &Window::get_theme_icon, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_stylebox", "name", "type"), &Window::get_theme_stylebox, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_font", "name", "type"), &Window::get_theme_font, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_color", "name", "type"), &Window::get_theme_color, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_constant", "name", "type"), &Window::get_theme_constant, DEFVAL("")); + + ClassDB::bind_method(D_METHOD("has_theme_icon", "name", "type"), &Window::has_theme_icon, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_stylebox", "name", "type"), &Window::has_theme_stylebox, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_font", "name", "type"), &Window::has_theme_font, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_color", "name", "type"), &Window::has_theme_color, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_constant", "name", "type"), &Window::has_theme_constant, DEFVAL("")); + + ClassDB::bind_method(D_METHOD("popup", "rect"), &Window::popup, DEFVAL(Rect2i())); + ClassDB::bind_method(D_METHOD("popup_on_parent", "parent_rect"), &Window::popup_on_parent); + ClassDB::bind_method(D_METHOD("popup_centered_ratio", "ratio"), &Window::popup_centered_ratio, DEFVAL(0.8)); + ClassDB::bind_method(D_METHOD("popup_centered", "minsize"), &Window::popup_centered, DEFVAL(Size2i())); + ClassDB::bind_method(D_METHOD("popup_centered_clamped", "minsize", "fallback_ratio"), &Window::popup_centered_clamped, DEFVAL(Size2i()), DEFVAL(0.75)); + + ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "position"), "set_position", "get_position"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "size"), "set_size", "get_size"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,FullScreen"), "set_mode", "get_mode"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_screen"), "set_current_screen", "get_current_screen"); + ADD_GROUP("Flags", ""); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "wrap_controls"), "set_wrap_controls", "is_wrapping_controls"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transient"), "set_transient", "is_transient"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclusive"), "set_exclusive", "is_exclusive"); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "unresizable"), "set_flag", "get_flag", FLAG_RESIZE_DISABLED); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "borderless"), "set_flag", "get_flag", FLAG_BORDERLESS); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "always_on_top"), "set_flag", "get_flag", FLAG_ALWAYS_ON_TOP); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "transparent"), "set_flag", "get_flag", FLAG_TRANSPARENT); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "unfocusable"), "set_flag", "get_flag", FLAG_NO_FOCUS); + ADD_GROUP("Limits", ""); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "min_size"), "set_min_size", "get_min_size"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "max_size"), "set_max_size", "get_max_size"); + ADD_GROUP("Content Scale", "content_scale_"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "content_scale_size"), "set_content_scale_size", "get_content_scale_size"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_mode", PROPERTY_HINT_ENUM, "Disabled,Object,Pixels"), "set_content_scale_mode", "get_content_scale_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_aspect", PROPERTY_HINT_ENUM, "Ignore,Keep,KeepWidth,KeepHeight,Expand"), "set_content_scale_aspect", "get_content_scale_aspect"); + ADD_GROUP("Theme", ""); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme"); + + ADD_SIGNAL(MethodInfo("window_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); + ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files"))); + ADD_SIGNAL(MethodInfo("mouse_entered")); + ADD_SIGNAL(MethodInfo("mouse_exited")); + ADD_SIGNAL(MethodInfo("focus_entered")); + ADD_SIGNAL(MethodInfo("focus_exited")); + ADD_SIGNAL(MethodInfo("close_requested")); + ADD_SIGNAL(MethodInfo("go_back_requested")); + ADD_SIGNAL(MethodInfo("visibility_changed")); + ADD_SIGNAL(MethodInfo("about_to_popup")); + + BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED); + + BIND_ENUM_CONSTANT(MODE_WINDOWED); + BIND_ENUM_CONSTANT(MODE_MINIMIZED); + BIND_ENUM_CONSTANT(MODE_MAXIMIZED); + BIND_ENUM_CONSTANT(MODE_FULLSCREEN); + + BIND_ENUM_CONSTANT(FLAG_RESIZE_DISABLED); + BIND_ENUM_CONSTANT(FLAG_BORDERLESS); + BIND_ENUM_CONSTANT(FLAG_ALWAYS_ON_TOP); + BIND_ENUM_CONSTANT(FLAG_TRANSPARENT); + BIND_ENUM_CONSTANT(FLAG_NO_FOCUS); + BIND_ENUM_CONSTANT(FLAG_MAX); + + BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_DISABLED); + BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_OBJECTS); + BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_PIXELS); + + BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_IGNORE); + BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_KEEP); + BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_KEEP_WIDTH); + BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_KEEP_HEIGHT); + BIND_ENUM_CONSTANT(CONTENT_SCALE_ASPECT_EXPAND); +} + +Window::Window() { + for (int i = 0; i < FLAG_MAX; i++) { + flags[i] = false; + } + content_scale_mode = CONTENT_SCALE_MODE_DISABLED; + content_scale_aspect = CONTENT_SCALE_ASPECT_IGNORE; + RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED); +} +Window::~Window() { +} diff --git a/scene/main/window.h b/scene/main/window.h new file mode 100644 index 0000000000..adaa5ca3be --- /dev/null +++ b/scene/main/window.h @@ -0,0 +1,265 @@ +/*************************************************************************/ +/* window.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 WINDOW_H +#define WINDOW_H + +#include "scene/main/viewport.h" +#include "scene/resources/theme.h" +#include "servers/display_server.h" + +class Control; +class Window : public Viewport { + GDCLASS(Window, Viewport) +public: + enum Mode { + MODE_WINDOWED = DisplayServer::WINDOW_MODE_WINDOWED, + MODE_MINIMIZED = DisplayServer::WINDOW_MODE_MINIMIZED, + MODE_MAXIMIZED = DisplayServer::WINDOW_MODE_MAXIMIZED, + MODE_FULLSCREEN = DisplayServer::WINDOW_MODE_FULLSCREEN, + }; + + enum Flags { + FLAG_RESIZE_DISABLED = DisplayServer::WINDOW_FLAG_RESIZE_DISABLED, + FLAG_BORDERLESS = DisplayServer::WINDOW_FLAG_BORDERLESS, + FLAG_ALWAYS_ON_TOP = DisplayServer::WINDOW_FLAG_ALWAYS_ON_TOP, + FLAG_TRANSPARENT = DisplayServer::WINDOW_FLAG_TRANSPARENT, + FLAG_NO_FOCUS = DisplayServer::WINDOW_FLAG_NO_FOCUS, + FLAG_MAX = DisplayServer::WINDOW_FLAG_MAX, + }; + + enum ContentScaleMode { + CONTENT_SCALE_MODE_DISABLED, + CONTENT_SCALE_MODE_OBJECTS, + CONTENT_SCALE_MODE_PIXELS, + }; + + enum ContentScaleAspect { + CONTENT_SCALE_ASPECT_IGNORE, + CONTENT_SCALE_ASPECT_KEEP, + CONTENT_SCALE_ASPECT_KEEP_WIDTH, + CONTENT_SCALE_ASPECT_KEEP_HEIGHT, + CONTENT_SCALE_ASPECT_EXPAND, + }; + + enum { + DEFAULT_WINDOW_SIZE = 100, + }; + +private: + DisplayServer::WindowID window_id = DisplayServer::INVALID_WINDOW_ID; + + String title; + mutable int current_screen = 0; + mutable Vector2i position; + mutable Size2i size = Size2i(DEFAULT_WINDOW_SIZE, DEFAULT_WINDOW_SIZE); + mutable Size2i min_size; + mutable Size2i max_size; + mutable Mode mode = MODE_WINDOWED; + mutable bool flags[FLAG_MAX]; + bool visible = true; + bool focused = false; + + bool use_font_oversampling = false; + bool transient = false; + bool exclusive = false; + bool wrap_controls = false; + bool updating_child_controls = false; + + void _update_child_controls(); + + Size2i content_scale_size; + ContentScaleMode content_scale_mode; + ContentScaleAspect content_scale_aspect; + + void _make_window(); + void _clear_window(); + void _update_from_window(); + + void _update_viewport_size(); + void _update_window_size(); + + void _propagate_window_notification(Node *p_node, int p_notification); + + void _update_window_callbacks(); + + void _clear_transient(); + void _make_transient(); + Window *transient_parent = nullptr; + Window *exclusive_child = nullptr; + Set<Window *> transient_children; + + friend class Control; + Ref<Theme> theme; + Control *theme_owner = nullptr; + Window *theme_owner_window = nullptr; + + Viewport *embedder = nullptr; + + friend class Viewport; //friend back, can call the methods below + + void _window_input(const Ref<InputEvent> &p_ev); + void _window_input_text(const String &p_text); + void _window_drop_files(const Vector<String> &p_files); + void _rect_changed_callback(const Rect2i &p_callback); + void _event_callback(DisplayServer::WindowEvent p_event); + +protected: + Viewport *_get_embedder() const; + + virtual Rect2i _popup_adjust_rect() const { return Rect2i(); } + + virtual void _post_popup() {} + virtual Size2 _get_contents_minimum_size() const; + static void _bind_methods(); + void _notification(int p_what); + + virtual void add_child_notify(Node *p_child); + virtual void remove_child_notify(Node *p_child); + +public: + enum { + + NOTIFICATION_VISIBILITY_CHANGED = 30, + NOTIFICATION_POST_POPUP = 31, + NOTIFICATION_THEME_CHANGED = 32, + }; + + void set_title(const String &p_title); + String get_title() const; + + void set_current_screen(int p_screen); + int get_current_screen() const; + + void set_position(const Point2i &p_position); + Point2i get_position() const; + + void set_size(const Size2i &p_size); + Size2i get_size() const; + + Size2i get_real_size() const; + + void set_max_size(const Size2i &p_max_size); + Size2i get_max_size() const; + + void set_min_size(const Size2i &p_min_size); + Size2i get_min_size() const; + + void set_mode(Mode p_mode); + Mode get_mode() const; + + void set_flag(Flags p_flag, bool p_enabled); + bool get_flag(Flags p_flag) const; + + bool is_maximize_allowed() const; + + void request_attention(); + void move_to_foreground(); + + void set_visible(bool p_visible); + bool is_visible() const; + + void show(); + void hide(); + + void set_transient(bool p_transient); + bool is_transient() const; + + void set_exclusive(bool p_exclusive); + bool is_exclusive() const; + + bool can_draw() const; + + void set_ime_active(bool p_active); + void set_ime_position(const Point2i &p_pos); + + bool is_embedded() const; + + void set_content_scale_size(const Size2i &p_size); + Size2i get_content_scale_size() const; + + void set_content_scale_mode(ContentScaleMode p_mode); + ContentScaleMode get_content_scale_mode() const; + + void set_content_scale_aspect(ContentScaleAspect p_aspect); + ContentScaleAspect get_content_scale_aspect() const; + + void set_use_font_oversampling(bool p_oversampling); + bool is_using_font_oversampling() const; + + void set_wrap_controls(bool p_enable); + bool is_wrapping_controls() const; + void child_controls_changed(); + + Window *get_parent_visible_window() const; + Viewport *get_parent_viewport() const; + void popup(const Rect2i &p_rect = Rect2i()); + void popup_on_parent(const Rect2i &p_parent_rect); + void popup_centered_ratio(float p_ratio = 0.8); + void popup_centered(const Size2i &p_minsize = Size2i()); + void popup_centered_clamped(const Size2i &p_size = Size2i(), float p_fallback_ratio = 0.75); + + void set_theme(const Ref<Theme> &p_theme); + Ref<Theme> get_theme() const; + + Size2 get_contents_minimum_size() const; + + void grab_focus(); + bool has_focus() const; + + Rect2i get_usable_parent_rect() const; + + Ref<Texture2D> get_theme_icon(const StringName &p_name, const StringName &p_type = StringName()) const; + Ref<Shader> get_theme_shader(const StringName &p_name, const StringName &p_type = StringName()) const; + Ref<StyleBox> get_theme_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const; + Ref<Font> get_theme_font(const StringName &p_name, const StringName &p_type = StringName()) const; + Color get_theme_color(const StringName &p_name, const StringName &p_type = StringName()) const; + int get_theme_constant(const StringName &p_name, const StringName &p_type = StringName()) const; + + bool has_theme_icon(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_shader(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_font(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_color(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_constant(const StringName &p_name, const StringName &p_type = StringName()) const; + + Rect2i get_parent_rect() const; + virtual DisplayServer::WindowID get_window_id() const; + + Window(); + ~Window(); +}; + +VARIANT_ENUM_CAST(Window::Mode); +VARIANT_ENUM_CAST(Window::Flags); +VARIANT_ENUM_CAST(Window::ContentScaleMode); +VARIANT_ENUM_CAST(Window::ContentScaleAspect); + +#endif // WINDOW_H diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index dd00565929..dc3ef5b508 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -33,16 +33,16 @@ #include "core/class_db.h" #include "core/os/os.h" #include "core/project_settings.h" -#include "scene/2d/animated_sprite.h" +#include "scene/2d/animated_sprite_2d.h" #include "scene/2d/area_2d.h" #include "scene/2d/audio_stream_player_2d.h" #include "scene/2d/back_buffer_copy.h" #include "scene/2d/camera_2d.h" -#include "scene/2d/canvas_item.h" #include "scene/2d/canvas_modulate.h" #include "scene/2d/collision_polygon_2d.h" #include "scene/2d/collision_shape_2d.h" #include "scene/2d/cpu_particles_2d.h" +#include "scene/2d/gpu_particles_2d.h" #include "scene/2d/joints_2d.h" #include "scene/2d/light_2d.h" #include "scene/2d/light_occluder_2d.h" @@ -54,7 +54,6 @@ #include "scene/2d/navigation_obstacle_2d.h" #include "scene/2d/parallax_background.h" #include "scene/2d/parallax_layer.h" -#include "scene/2d/particles_2d.h" #include "scene/2d/path_2d.h" #include "scene/2d/physics_body_2d.h" #include "scene/2d/polygon_2d.h" @@ -62,7 +61,7 @@ #include "scene/2d/ray_cast_2d.h" #include "scene/2d/remote_transform_2d.h" #include "scene/2d/skeleton_2d.h" -#include "scene/2d/sprite.h" +#include "scene/2d/sprite_2d.h" #include "scene/2d/tile_map.h" #include "scene/2d/touch_screen_button.h" #include "scene/2d/visibility_notifier_2d.h" @@ -111,6 +110,7 @@ #include "scene/gui/slider.h" #include "scene/gui/spin_box.h" #include "scene/gui/split_container.h" +#include "scene/gui/subviewport_container.h" #include "scene/gui/tab_container.h" #include "scene/gui/tabs.h" #include "scene/gui/text_edit.h" @@ -120,7 +120,7 @@ #include "scene/gui/tool_button.h" #include "scene/gui/tree.h" #include "scene/gui/video_player.h" -#include "scene/gui/viewport_container.h" +#include "scene/main/canvas_item.h" #include "scene/main/canvas_layer.h" #include "scene/main/http_request.h" #include "scene/main/instance_placeholder.h" @@ -128,21 +128,22 @@ #include "scene/main/scene_tree.h" #include "scene/main/timer.h" #include "scene/main/viewport.h" +#include "scene/main/window.h" #include "scene/resources/audio_stream_sample.h" #include "scene/resources/bit_map.h" -#include "scene/resources/box_shape.h" -#include "scene/resources/capsule_shape.h" +#include "scene/resources/box_shape_3d.h" #include "scene/resources/capsule_shape_2d.h" +#include "scene/resources/capsule_shape_3d.h" #include "scene/resources/circle_shape_2d.h" -#include "scene/resources/concave_polygon_shape.h" #include "scene/resources/concave_polygon_shape_2d.h" -#include "scene/resources/convex_polygon_shape.h" +#include "scene/resources/concave_polygon_shape_3d.h" #include "scene/resources/convex_polygon_shape_2d.h" -#include "scene/resources/cylinder_shape.h" +#include "scene/resources/convex_polygon_shape_3d.h" +#include "scene/resources/cylinder_shape_3d.h" #include "scene/resources/default_theme/default_theme.h" #include "scene/resources/dynamic_font.h" #include "scene/resources/gradient.h" -#include "scene/resources/height_map_shape.h" +#include "scene/resources/height_map_shape_3d.h" #include "scene/resources/line_shape_2d.h" #include "scene/resources/material.h" #include "scene/resources/mesh.h" @@ -153,12 +154,13 @@ #include "scene/resources/physics_material.h" #include "scene/resources/polygon_path_finder.h" #include "scene/resources/primitive_meshes.h" -#include "scene/resources/ray_shape.h" +#include "scene/resources/ray_shape_3d.h" #include "scene/resources/rectangle_shape_2d.h" #include "scene/resources/resource_format_text.h" #include "scene/resources/segment_shape_2d.h" #include "scene/resources/sky.h" -#include "scene/resources/sphere_shape.h" +#include "scene/resources/sky_material.h" +#include "scene/resources/sphere_shape_3d.h" #include "scene/resources/surface_tool.h" #include "scene/resources/text_file.h" #include "scene/resources/texture.h" @@ -166,50 +168,54 @@ #include "scene/resources/video_stream.h" #include "scene/resources/visual_shader.h" #include "scene/resources/visual_shader_nodes.h" -#include "scene/resources/world.h" #include "scene/resources/world_2d.h" -#include "scene/resources/world_margin_shape.h" +#include "scene/resources/world_3d.h" +#include "scene/resources/world_margin_shape_3d.h" #include "scene/scene_string_names.h" +// Needed by animation code, so keep when 3D disabled. +#include "scene/3d/node_3d.h" +#include "scene/3d/skeleton_3d.h" + +#include "scene/main/shader_globals_override.h" + #ifndef _3D_DISABLED -#include "scene/3d/area.h" -#include "scene/3d/arvr_nodes.h" +#include "scene/3d/area_3d.h" #include "scene/3d/audio_stream_player_3d.h" #include "scene/3d/baked_lightmap.h" -#include "scene/3d/bone_attachment.h" -#include "scene/3d/camera.h" -#include "scene/3d/collision_polygon.h" -#include "scene/3d/collision_shape.h" -#include "scene/3d/cpu_particles.h" +#include "scene/3d/bone_attachment_3d.h" +#include "scene/3d/camera_3d.h" +#include "scene/3d/collision_polygon_3d.h" +#include "scene/3d/collision_shape_3d.h" +#include "scene/3d/cpu_particles_3d.h" +#include "scene/3d/decal.h" #include "scene/3d/gi_probe.h" -#include "scene/3d/immediate_geometry.h" -#include "scene/3d/interpolated_camera.h" -#include "scene/3d/light.h" -#include "scene/3d/listener.h" -#include "scene/3d/mesh_instance.h" -#include "scene/3d/multimesh_instance.h" -#include "scene/3d/navigation.h" -#include "scene/3d/navigation_agent.h" -#include "scene/3d/navigation_obstacle.h" -#include "scene/3d/navigation_region.h" -#include "scene/3d/particles.h" -#include "scene/3d/path.h" -#include "scene/3d/physics_body.h" -#include "scene/3d/physics_joint.h" +#include "scene/3d/gpu_particles_3d.h" +#include "scene/3d/immediate_geometry_3d.h" +#include "scene/3d/light_3d.h" +#include "scene/3d/listener_3d.h" +#include "scene/3d/mesh_instance_3d.h" +#include "scene/3d/multimesh_instance_3d.h" +#include "scene/3d/navigation_3d.h" +#include "scene/3d/navigation_agent_3d.h" +#include "scene/3d/navigation_obstacle_3d.h" +#include "scene/3d/navigation_region_3d.h" +#include "scene/3d/path_3d.h" +#include "scene/3d/physics_body_3d.h" +#include "scene/3d/physics_joint_3d.h" #include "scene/3d/position_3d.h" -#include "scene/3d/proximity_group.h" -#include "scene/3d/ray_cast.h" +#include "scene/3d/proximity_group_3d.h" +#include "scene/3d/ray_cast_3d.h" #include "scene/3d/reflection_probe.h" -#include "scene/3d/remote_transform.h" -#include "scene/3d/skeleton.h" -#include "scene/3d/soft_body.h" -#include "scene/3d/spatial.h" -#include "scene/3d/spring_arm.h" +#include "scene/3d/remote_transform_3d.h" +#include "scene/3d/skeleton_ik_3d.h" +#include "scene/3d/soft_body_3d.h" +#include "scene/3d/spring_arm_3d.h" #include "scene/3d/sprite_3d.h" -#include "scene/3d/vehicle_body.h" -#include "scene/3d/visibility_notifier.h" +#include "scene/3d/vehicle_body_3d.h" +#include "scene/3d/visibility_notifier_3d.h" #include "scene/3d/world_environment.h" -#include "scene/animation/skeleton_ik.h" +#include "scene/3d/xr_nodes.h" #include "scene/resources/environment.h" #include "scene/resources/mesh_library.h" #endif @@ -266,15 +272,18 @@ void register_scene_types() { ClassDB::register_class<Node>(); ClassDB::register_virtual_class<InstancePlaceholder>(); - ClassDB::register_class<Viewport>(); + ClassDB::register_virtual_class<Viewport>(); + ClassDB::register_class<SubViewport>(); ClassDB::register_class<ViewportTexture>(); ClassDB::register_class<HTTPRequest>(); ClassDB::register_class<Timer>(); ClassDB::register_class<CanvasLayer>(); ClassDB::register_class<CanvasModulate>(); ClassDB::register_class<ResourcePreloader>(); + ClassDB::register_class<Window>(); /* REGISTER GUI */ + ClassDB::register_class<ButtonGroup>(); ClassDB::register_virtual_class<BaseButton>(); @@ -331,7 +340,6 @@ void register_scene_types() { ClassDB::register_class<VideoPlayer>(); #ifndef ADVANCED_GUI_DISABLED - ClassDB::register_class<FileDialog>(); ClassDB::register_class<PopupMenu>(); @@ -347,12 +355,12 @@ void register_scene_types() { ClassDB::register_class<RichTextLabel>(); ClassDB::register_class<RichTextEffect>(); ClassDB::register_class<CharFXTransform>(); - ClassDB::register_class<PopupDialog>(); - ClassDB::register_class<WindowDialog>(); + ClassDB::register_class<AcceptDialog>(); ClassDB::register_class<ConfirmationDialog>(); + ClassDB::register_class<MarginContainer>(); - ClassDB::register_class<ViewportContainer>(); + ClassDB::register_class<SubViewportContainer>(); ClassDB::register_virtual_class<SplitContainer>(); ClassDB::register_class<HSplitContainer>(); ClassDB::register_class<VSplitContainer>(); @@ -361,16 +369,18 @@ void register_scene_types() { OS::get_singleton()->yield(); //may take time to init + AcceptDialog::set_swap_ok_cancel(GLOBAL_DEF("gui/common/swap_ok_cancel", bool(DisplayServer::get_singleton()->get_swap_ok_cancel()))); #endif /* REGISTER 3D */ + // Needed even with _3D_DISABLED as used in animation code. + ClassDB::register_class<Node3D>(); + ClassDB::register_virtual_class<Node3DGizmo>(); ClassDB::register_class<Skin>(); ClassDB::register_virtual_class<SkinReference>(); + ClassDB::register_class<Skeleton3D>(); - ClassDB::register_class<Spatial>(); - ClassDB::register_virtual_class<SpatialGizmo>(); - ClassDB::register_class<Skeleton>(); ClassDB::register_class<AnimationPlayer>(); ClassDB::register_class<Tween>(); @@ -395,35 +405,37 @@ void register_scene_types() { ClassDB::register_class<AnimationNodeTimeSeek>(); ClassDB::register_class<AnimationNodeTransition>(); + ClassDB::register_class<ShaderGlobalsOverride>(); //can be used in any shader + OS::get_singleton()->yield(); //may take time to init #ifndef _3D_DISABLED - ClassDB::register_virtual_class<VisualInstance>(); - ClassDB::register_virtual_class<GeometryInstance>(); - ClassDB::register_class<Camera>(); - ClassDB::register_class<ClippedCamera>(); - ClassDB::register_class<Listener>(); - ClassDB::register_class<ARVRCamera>(); - ClassDB::register_class<ARVRController>(); - ClassDB::register_class<ARVRAnchor>(); - ClassDB::register_class<ARVROrigin>(); - ClassDB::register_class<InterpolatedCamera>(); - ClassDB::register_class<MeshInstance>(); - ClassDB::register_class<ImmediateGeometry>(); + ClassDB::register_virtual_class<VisualInstance3D>(); + ClassDB::register_virtual_class<GeometryInstance3D>(); + ClassDB::register_class<Camera3D>(); + ClassDB::register_class<ClippedCamera3D>(); + ClassDB::register_class<Listener3D>(); + ClassDB::register_class<XRCamera3D>(); + ClassDB::register_class<XRController3D>(); + ClassDB::register_class<XRAnchor3D>(); + ClassDB::register_class<XROrigin3D>(); + ClassDB::register_class<MeshInstance3D>(); + ClassDB::register_class<ImmediateGeometry3D>(); ClassDB::register_virtual_class<SpriteBase3D>(); ClassDB::register_class<Sprite3D>(); ClassDB::register_class<AnimatedSprite3D>(); - ClassDB::register_virtual_class<Light>(); - ClassDB::register_class<DirectionalLight>(); - ClassDB::register_class<OmniLight>(); - ClassDB::register_class<SpotLight>(); + ClassDB::register_virtual_class<Light3D>(); + ClassDB::register_class<DirectionalLight3D>(); + ClassDB::register_class<OmniLight3D>(); + ClassDB::register_class<SpotLight3D>(); ClassDB::register_class<ReflectionProbe>(); + ClassDB::register_class<Decal>(); ClassDB::register_class<GIProbe>(); ClassDB::register_class<GIProbeData>(); //ClassDB::register_class<BakedLightmap>(); //ClassDB::register_class<BakedLightmapData>(); - ClassDB::register_class<Particles>(); - ClassDB::register_class<CPUParticles>(); + ClassDB::register_class<GPUParticles3D>(); + ClassDB::register_class<CPUParticles3D>(); ClassDB::register_class<Position3D>(); ClassDB::register_class<RootMotionView>(); @@ -431,55 +443,53 @@ void register_scene_types() { OS::get_singleton()->yield(); //may take time to init - ClassDB::register_virtual_class<CollisionObject>(); - ClassDB::register_virtual_class<PhysicsBody>(); - ClassDB::register_class<StaticBody>(); - ClassDB::register_class<RigidBody>(); - ClassDB::register_class<KinematicCollision>(); - ClassDB::register_class<KinematicBody>(); - ClassDB::register_class<SpringArm>(); - - ClassDB::register_class<PhysicalBone>(); - ClassDB::register_class<SoftBody>(); - - ClassDB::register_class<SkeletonIK>(); - ClassDB::register_class<BoneAttachment>(); - - ClassDB::register_class<VehicleBody>(); - ClassDB::register_class<VehicleWheel>(); - ClassDB::register_class<Area>(); - ClassDB::register_class<ProximityGroup>(); - ClassDB::register_class<CollisionShape>(); - ClassDB::register_class<CollisionPolygon>(); - ClassDB::register_class<RayCast>(); - ClassDB::register_class<MultiMeshInstance>(); + ClassDB::register_virtual_class<CollisionObject3D>(); + ClassDB::register_virtual_class<PhysicsBody3D>(); + ClassDB::register_class<StaticBody3D>(); + ClassDB::register_class<RigidBody3D>(); + ClassDB::register_class<KinematicCollision3D>(); + ClassDB::register_class<KinematicBody3D>(); + ClassDB::register_class<SpringArm3D>(); + + ClassDB::register_class<PhysicalBone3D>(); + ClassDB::register_class<SoftBody3D>(); + + ClassDB::register_class<SkeletonIK3D>(); + ClassDB::register_class<BoneAttachment3D>(); + + ClassDB::register_class<VehicleBody3D>(); + ClassDB::register_class<VehicleWheel3D>(); + ClassDB::register_class<Area3D>(); + ClassDB::register_class<ProximityGroup3D>(); + ClassDB::register_class<CollisionShape3D>(); + ClassDB::register_class<CollisionPolygon3D>(); + ClassDB::register_class<RayCast3D>(); + ClassDB::register_class<MultiMeshInstance3D>(); ClassDB::register_class<Curve3D>(); - ClassDB::register_class<Path>(); - ClassDB::register_class<PathFollow>(); - ClassDB::register_class<VisibilityNotifier>(); - ClassDB::register_class<VisibilityEnabler>(); + ClassDB::register_class<Path3D>(); + ClassDB::register_class<PathFollow3D>(); + ClassDB::register_class<VisibilityNotifier3D>(); + ClassDB::register_class<VisibilityEnabler3D>(); ClassDB::register_class<WorldEnvironment>(); - ClassDB::register_class<RemoteTransform>(); + ClassDB::register_class<RemoteTransform3D>(); - ClassDB::register_virtual_class<Joint>(); - ClassDB::register_class<PinJoint>(); - ClassDB::register_class<HingeJoint>(); - ClassDB::register_class<SliderJoint>(); - ClassDB::register_class<ConeTwistJoint>(); - ClassDB::register_class<Generic6DOFJoint>(); + ClassDB::register_virtual_class<Joint3D>(); + ClassDB::register_class<PinJoint3D>(); + ClassDB::register_class<HingeJoint3D>(); + ClassDB::register_class<SliderJoint3D>(); + ClassDB::register_class<ConeTwistJoint3D>(); + ClassDB::register_class<Generic6DOFJoint3D>(); - ClassDB::register_class<Navigation>(); - ClassDB::register_class<NavigationRegion>(); - ClassDB::register_class<NavigationAgent>(); - ClassDB::register_class<NavigationObstacle>(); + ClassDB::register_class<Navigation3D>(); + ClassDB::register_class<NavigationRegion3D>(); + ClassDB::register_class<NavigationAgent3D>(); + ClassDB::register_class<NavigationObstacle3D>(); OS::get_singleton()->yield(); //may take time to init - #endif - ClassDB::register_class<NavigationMesh>(); - AcceptDialog::set_swap_ok_cancel(GLOBAL_DEF("gui/common/swap_ok_cancel", bool(OS::get_singleton()->get_swap_ok_cancel()))); + /* REGISTER SHADER */ ClassDB::register_class<Shader>(); ClassDB::register_class<VisualShader>(); @@ -553,14 +563,15 @@ void register_scene_types() { ClassDB::register_class<CanvasItemMaterial>(); SceneTree::add_idle_callback(CanvasItemMaterial::flush_changes); CanvasItemMaterial::init_shaders(); + + /* REGISTER 2D */ + ClassDB::register_class<Node2D>(); ClassDB::register_class<CPUParticles2D>(); - ClassDB::register_class<Particles2D>(); - //ClassDB::register_class<ParticleAttractor2D>(); - ClassDB::register_class<Sprite>(); - //ClassDB::register_type<ViewportSprite>(); + ClassDB::register_class<GPUParticles2D>(); + ClassDB::register_class<Sprite2D>(); ClassDB::register_class<SpriteFrames>(); - ClassDB::register_class<AnimatedSprite>(); + ClassDB::register_class<AnimatedSprite2D>(); ClassDB::register_class<Position2D>(); ClassDB::register_class<Line2D>(); ClassDB::register_class<MeshInstance2D>(); @@ -609,6 +620,10 @@ void register_scene_types() { SceneTree::add_idle_callback(ParticlesMaterial::flush_changes); ParticlesMaterial::init_shaders(); + ClassDB::register_class<ProceduralSkyMaterial>(); + ClassDB::register_class<PanoramaSkyMaterial>(); + ClassDB::register_class<PhysicalSkyMaterial>(); + ClassDB::register_virtual_class<Mesh>(); ClassDB::register_class<ArrayMesh>(); ClassDB::register_class<MultiMesh>(); @@ -636,32 +651,30 @@ void register_scene_types() { OS::get_singleton()->yield(); //may take time to init - ClassDB::register_virtual_class<Shape>(); - ClassDB::register_class<RayShape>(); - ClassDB::register_class<SphereShape>(); - ClassDB::register_class<BoxShape>(); - ClassDB::register_class<CapsuleShape>(); - ClassDB::register_class<CylinderShape>(); - ClassDB::register_class<HeightMapShape>(); - ClassDB::register_class<WorldMarginShape>(); - ClassDB::register_class<ConvexPolygonShape>(); - ClassDB::register_class<ConcavePolygonShape>(); + ClassDB::register_virtual_class<Shape3D>(); + ClassDB::register_class<RayShape3D>(); + ClassDB::register_class<SphereShape3D>(); + ClassDB::register_class<BoxShape3D>(); + ClassDB::register_class<CapsuleShape3D>(); + ClassDB::register_class<CylinderShape3D>(); + ClassDB::register_class<HeightMapShape3D>(); + ClassDB::register_class<WorldMarginShape3D>(); + ClassDB::register_class<ConvexPolygonShape3D>(); + ClassDB::register_class<ConcavePolygonShape3D>(); OS::get_singleton()->yield(); //may take time to init - ClassDB::register_class<SpatialVelocityTracker>(); - + ClassDB::register_class<VelocityTracker3D>(); #endif + ClassDB::register_class<PhysicsMaterial>(); - ClassDB::register_class<World>(); + ClassDB::register_class<World3D>(); ClassDB::register_class<Environment>(); ClassDB::register_class<CameraEffects>(); ClassDB::register_class<World2D>(); ClassDB::register_virtual_class<Texture>(); ClassDB::register_virtual_class<Texture2D>(); - ClassDB::register_virtual_class<Sky>(); - ClassDB::register_class<PanoramaSky>(); - ClassDB::register_class<ProceduralSky>(); + ClassDB::register_class<Sky>(); ClassDB::register_class<StreamTexture>(); ClassDB::register_class<ImageTexture>(); ClassDB::register_class<AtlasTexture>(); @@ -724,6 +737,7 @@ void register_scene_types() { ClassDB::register_class<Path2D>(); ClassDB::register_class<PathFollow2D>(); + ClassDB::register_class<NavigationMesh>(); ClassDB::register_class<Navigation2D>(); ClassDB::register_class<NavigationPolygon>(); ClassDB::register_class<NavigationRegion2D>(); @@ -739,16 +753,121 @@ void register_scene_types() { ClassDB::register_virtual_class<SceneTreeTimer>(); //sorry, you can't create it #ifndef DISABLE_DEPRECATED - ClassDB::add_compatibility_class("SpatialMaterial", "StandardMaterial3D"); - ClassDB::add_compatibility_class("Mesh", "ArrayMesh"); + // Dropped in 4.0, near approximation. ClassDB::add_compatibility_class("AnimationTreePlayer", "AnimationTree"); + + // Renamed in 4.0. + // Keep alphabetical ordering to easily locate classes and avoid duplicates. + ClassDB::add_compatibility_class("AnimatedSprite", "AnimatedSprite2D"); + ClassDB::add_compatibility_class("Area", "Area3D"); + ClassDB::add_compatibility_class("ARVRCamera", "XRCamera3D"); + ClassDB::add_compatibility_class("ARVRController", "XRController3D"); + ClassDB::add_compatibility_class("ARVRAnchor", "XRAnchor3D"); + ClassDB::add_compatibility_class("ARVRInterface", "XRInterface"); + ClassDB::add_compatibility_class("ARVROrigin", "XROrigin3D"); + ClassDB::add_compatibility_class("ARVRPositionalTracker", "XRPositionalTracker"); + ClassDB::add_compatibility_class("ARVRServer", "XRServer"); + ClassDB::add_compatibility_class("BoneAttachment", "BoneAttachment3D"); + ClassDB::add_compatibility_class("BoxShape", "BoxShape3D"); + ClassDB::add_compatibility_class("BulletPhysicsDirectBodyState", "BulletPhysicsDirectBodyState3D"); + ClassDB::add_compatibility_class("BulletPhysicsServer", "BulletPhysicsServer3D"); + ClassDB::add_compatibility_class("Camera", "Camera3D"); + ClassDB::add_compatibility_class("CapsuleShape", "CapsuleShape3D"); + ClassDB::add_compatibility_class("ClippedCamera", "ClippedCamera3D"); + ClassDB::add_compatibility_class("CollisionObject", "CollisionObject3D"); + ClassDB::add_compatibility_class("CollisionPolygon", "CollisionPolygon3D"); + ClassDB::add_compatibility_class("CollisionShape", "CollisionShape3D"); + ClassDB::add_compatibility_class("ConcavePolygonShape", "ConcavePolygonShape3D"); + ClassDB::add_compatibility_class("ConeTwistJoint", "ConeTwistJoint3D"); + ClassDB::add_compatibility_class("ConvexPolygonShape", "ConvexPolygonShape3D"); + ClassDB::add_compatibility_class("CPUParticles", "CPUParticles3D"); + ClassDB::add_compatibility_class("CSGBox", "CSGBox3D"); + ClassDB::add_compatibility_class("CSGCombiner", "CSGCombiner3D"); + ClassDB::add_compatibility_class("CSGCylinder", "CSGCylinder3D"); + ClassDB::add_compatibility_class("CSGMesh", "CSGMesh3D"); + ClassDB::add_compatibility_class("CSGPolygon", "CSGPolygon3D"); + ClassDB::add_compatibility_class("CSGPrimitive", "CSGPrimitive3D"); + ClassDB::add_compatibility_class("CSGShape", "CSGShape3D"); + ClassDB::add_compatibility_class("CSGSphere", "CSGSphere3D"); + ClassDB::add_compatibility_class("CSGTorus", "CSGTorus3D"); + ClassDB::add_compatibility_class("CylinderShape", "CylinderShape3D"); + ClassDB::add_compatibility_class("DirectionalLight", "DirectionalLight3D"); + ClassDB::add_compatibility_class("EditorSpatialGizmo", "EditorNode3DGizmo"); + ClassDB::add_compatibility_class("EditorSpatialGizmoPlugin", "EditorNode3DGizmoPlugin"); + ClassDB::add_compatibility_class("Generic6DOFJoint", "Generic6DOFJoint3D"); + ClassDB::add_compatibility_class("HeightMapShape", "HeightMapShape3D"); + ClassDB::add_compatibility_class("HingeJoint", "HingeJoint3D"); + ClassDB::add_compatibility_class("ImmediateGeometry", "ImmediateGeometry3D"); + ClassDB::add_compatibility_class("Joint", "Joint3D"); + ClassDB::add_compatibility_class("KinematicBody", "KinematicBody3D"); + ClassDB::add_compatibility_class("KinematicCollision", "KinematicCollision3D"); + ClassDB::add_compatibility_class("Light", "Light3D"); + ClassDB::add_compatibility_class("Listener", "Listener3D"); + ClassDB::add_compatibility_class("MeshInstance", "MeshInstance3D"); + ClassDB::add_compatibility_class("MultiMeshInstance", "MultiMeshInstance3D"); + ClassDB::add_compatibility_class("Navigation", "Navigation3D"); + ClassDB::add_compatibility_class("NavigationAgent", "NavigationAgent3D"); + ClassDB::add_compatibility_class("NavigationMeshInstance", "NavigationRegion3D"); + ClassDB::add_compatibility_class("NavigationObstacle", "NavigationObstacle3D"); + ClassDB::add_compatibility_class("NavigationPolygonInstance", "NavigationRegion2D"); + ClassDB::add_compatibility_class("NavigationRegion", "NavigationRegion3D"); + ClassDB::add_compatibility_class("Navigation2DServer", "NavigationServer2D"); + ClassDB::add_compatibility_class("NavigationServer", "NavigationServer3D"); + ClassDB::add_compatibility_class("OmniLight", "OmniLight3D"); + ClassDB::add_compatibility_class("PanoramaSky", "Sky"); + ClassDB::add_compatibility_class("Particles", "GPUParticles3D"); + ClassDB::add_compatibility_class("Particles2D", "GPUParticles2D"); + ClassDB::add_compatibility_class("Path", "Path3D"); + ClassDB::add_compatibility_class("PathFollow", "PathFollow3D"); + ClassDB::add_compatibility_class("PhysicalBone", "PhysicalBone3D"); + ClassDB::add_compatibility_class("Physics2DDirectBodyStateSW", "PhysicsDirectBodyState2DSW"); + ClassDB::add_compatibility_class("Physics2DDirectBodyState", "PhysicsDirectBodyState2D"); + ClassDB::add_compatibility_class("Physics2DDirectSpaceState", "PhysicsDirectSpaceState2D"); + ClassDB::add_compatibility_class("Physics2DServerSW", "PhysicsServer2DSW"); + ClassDB::add_compatibility_class("Physics2DServer", "PhysicsServer2D"); + ClassDB::add_compatibility_class("Physics2DShapeQueryParameters", "PhysicsShapeQueryParameters2D"); + ClassDB::add_compatibility_class("Physics2DShapeQueryResult", "PhysicsShapeQueryResult2D"); + ClassDB::add_compatibility_class("Physics2DTestMotionResult", "PhysicsTestMotionResult2D"); + ClassDB::add_compatibility_class("PhysicsBody", "PhysicsBody3D"); + ClassDB::add_compatibility_class("PhysicsDirectBodyState", "PhysicsDirectBodyState3D"); + ClassDB::add_compatibility_class("PhysicsDirectSpaceState", "PhysicsDirectSpaceState3D"); + ClassDB::add_compatibility_class("PhysicsServer", "PhysicsServer3D"); + ClassDB::add_compatibility_class("PhysicsShapeQueryParameters", "PhysicsShapeQueryParameters3D"); + ClassDB::add_compatibility_class("PhysicsShapeQueryResult", "PhysicsShapeQueryResult3D"); + ClassDB::add_compatibility_class("PinJoint", "PinJoint3D"); + ClassDB::add_compatibility_class("PlaneShape", "WorldMarginShape3D"); + ClassDB::add_compatibility_class("ProceduralSky", "Sky"); + ClassDB::add_compatibility_class("ProximityGroup", "ProximityGroup3D"); + ClassDB::add_compatibility_class("RayCast", "RayCast3D"); + ClassDB::add_compatibility_class("RayShape", "RayShape3D"); + ClassDB::add_compatibility_class("RemoteTransform", "RemoteTransform3D"); + ClassDB::add_compatibility_class("RigidBody", "RigidBody3D"); + ClassDB::add_compatibility_class("Shape", "Shape3D"); + ClassDB::add_compatibility_class("Skeleton", "Skeleton3D"); + ClassDB::add_compatibility_class("SkeletonIK", "SkeletonIK3D"); + ClassDB::add_compatibility_class("SliderJoint", "SliderJoint3D"); + ClassDB::add_compatibility_class("SoftBody", "SoftBody3D"); + ClassDB::add_compatibility_class("Spatial", "Node3D"); + ClassDB::add_compatibility_class("SpatialGizmo", "Node3DGizmo"); + ClassDB::add_compatibility_class("SpatialMaterial", "StandardMaterial3D"); + ClassDB::add_compatibility_class("SpatialVelocityTracker", "VelocityTracker3D"); + ClassDB::add_compatibility_class("SphereShape", "SphereShape3D"); + ClassDB::add_compatibility_class("SpotLight", "SpotLight3D"); + ClassDB::add_compatibility_class("SpringArm", "SpringArm3D"); + ClassDB::add_compatibility_class("Sprite", "Sprite2D"); + ClassDB::add_compatibility_class("StaticBody", "StaticBody3D"); + ClassDB::add_compatibility_class("VehicleBody", "VehicleBody3D"); + ClassDB::add_compatibility_class("VehicleWheel", "VehicleWheel3D"); + ClassDB::add_compatibility_class("ViewportContainer", "SubViewportContainer"); + ClassDB::add_compatibility_class("VisibilityEnabler", "VisibilityEnabler3D"); + ClassDB::add_compatibility_class("VisibilityNotifier", "VisibilityNotifier3D"); + ClassDB::add_compatibility_class("VisualServer", "RenderingServer"); ClassDB::add_compatibility_class("VisualShaderNodeScalarConstant", "VisualShaderNodeFloatConstant"); - ClassDB::add_compatibility_class("VisualShaderNodeScalarUniform", "VisualShaderNodeFloatUniform"); - ClassDB::add_compatibility_class("VisualShaderNodeScalarOp", "VisualShaderNodeFloatOp"); ClassDB::add_compatibility_class("VisualShaderNodeScalarFunc", "VisualShaderNodeFloatFunc"); - ClassDB::add_compatibility_class("NavigationMeshInstance", "NavigationRegion"); - ClassDB::add_compatibility_class("NavigationPolygonInstance", "NavigationRegion2D"); - ClassDB::add_compatibility_class("PlaneShape", "WorldMarginShape"); + ClassDB::add_compatibility_class("VisualShaderNodeScalarOp", "VisualShaderNodeFloatOp"); + ClassDB::add_compatibility_class("VisualShaderNodeScalarUniform", "VisualShaderNodeFloatUniform"); + ClassDB::add_compatibility_class("World", "World3D"); + #endif OS::get_singleton()->yield(); //may take time to init diff --git a/scene/resources/SCsub b/scene/resources/SCsub index 5e5b6f8fd5..3a86b22835 100644 --- a/scene/resources/SCsub +++ b/scene/resources/SCsub @@ -1,6 +1,6 @@ #!/usr/bin/env python -Import('env') +Import("env") env.add_source_files(env.scene_sources, "*.cpp") diff --git a/scene/resources/animation.h b/scene/resources/animation.h index 36d5df52df..e4e5177a8c 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -84,7 +84,10 @@ private: float transition; float time; // time in secs - Key() { transition = 1; } + Key() { + transition = 1; + time = 0; + } }; // transform key holds either Vector3 or Quaternion diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp index a68b750b31..d630a1f3ee 100644 --- a/scene/resources/audio_stream_sample.cpp +++ b/scene/resources/audio_stream_sample.cpp @@ -481,8 +481,8 @@ void AudioStreamSample::set_data(const Vector<uint8_t> &p_data) { AudioServer::get_singleton()->lock(); if (data) { - AudioServer::get_singleton()->audio_data_free(data); - data = NULL; + memfree(data); + data = nullptr; data_bytes = 0; } @@ -491,7 +491,7 @@ void AudioStreamSample::set_data(const Vector<uint8_t> &p_data) { const uint8_t *r = p_data.ptr(); int alloc_len = datalen + DATA_PAD * 2; - data = AudioServer::get_singleton()->audio_data_alloc(alloc_len); //alloc with some padding for interpolation + data = memalloc(alloc_len); //alloc with some padding for interpolation zeromem(data, alloc_len); uint8_t *dataptr = (uint8_t *)data; copymem(dataptr + DATA_PAD, r, datalen); @@ -654,14 +654,14 @@ AudioStreamSample::AudioStreamSample() { loop_begin = 0; loop_end = 0; mix_rate = 44100; - data = NULL; + data = nullptr; data_bytes = 0; } AudioStreamSample::~AudioStreamSample() { if (data) { - AudioServer::get_singleton()->audio_data_free(data); - data = NULL; + memfree(data); + data = nullptr; data_bytes = 0; } } diff --git a/scene/resources/box_shape.cpp b/scene/resources/box_shape_3d.cpp index e1f485bae6..64c821a011 100644 --- a/scene/resources/box_shape.cpp +++ b/scene/resources/box_shape_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* box_shape.cpp */ +/* box_shape_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,10 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "box_shape.h" -#include "servers/physics_server.h" +#include "box_shape_3d.h" +#include "servers/physics_server_3d.h" -Vector<Vector3> BoxShape::get_debug_mesh_lines() { +Vector<Vector3> BoxShape3D::get_debug_mesh_lines() { Vector<Vector3> lines; AABB aabb; @@ -48,17 +48,17 @@ Vector<Vector3> BoxShape::get_debug_mesh_lines() { return lines; } -real_t BoxShape::get_enclosing_radius() const { +real_t BoxShape3D::get_enclosing_radius() const { return extents.length(); } -void BoxShape::_update_shape() { +void BoxShape3D::_update_shape() { - PhysicsServer::get_singleton()->shape_set_data(get_shape(), extents); - Shape::_update_shape(); + PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), extents); + Shape3D::_update_shape(); } -void BoxShape::set_extents(const Vector3 &p_extents) { +void BoxShape3D::set_extents(const Vector3 &p_extents) { extents = p_extents; _update_shape(); @@ -66,21 +66,21 @@ void BoxShape::set_extents(const Vector3 &p_extents) { _change_notify("extents"); } -Vector3 BoxShape::get_extents() const { +Vector3 BoxShape3D::get_extents() const { return extents; } -void BoxShape::_bind_methods() { +void BoxShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_extents", "extents"), &BoxShape::set_extents); - ClassDB::bind_method(D_METHOD("get_extents"), &BoxShape::get_extents); + ClassDB::bind_method(D_METHOD("set_extents", "extents"), &BoxShape3D::set_extents); + ClassDB::bind_method(D_METHOD("get_extents"), &BoxShape3D::get_extents); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents"), "set_extents", "get_extents"); } -BoxShape::BoxShape() : - Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_BOX)) { +BoxShape3D::BoxShape3D() : + Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_BOX)) { set_extents(Vector3(1, 1, 1)); } diff --git a/scene/resources/box_shape.h b/scene/resources/box_shape_3d.h index fb164cc300..a93fd8d33a 100644 --- a/scene/resources/box_shape.h +++ b/scene/resources/box_shape_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* box_shape.h */ +/* box_shape_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,11 +31,11 @@ #ifndef BOX_SHAPE_H #define BOX_SHAPE_H -#include "scene/resources/shape.h" +#include "scene/resources/shape_3d.h" -class BoxShape : public Shape { +class BoxShape3D : public Shape3D { - GDCLASS(BoxShape, Shape); + GDCLASS(BoxShape3D, Shape3D); Vector3 extents; protected: @@ -50,7 +50,7 @@ public: virtual Vector<Vector3> get_debug_mesh_lines(); virtual real_t get_enclosing_radius() const; - BoxShape(); + BoxShape3D(); }; #endif // BOX_SHAPE_H diff --git a/scene/resources/canvas.cpp b/scene/resources/canvas.cpp deleted file mode 100644 index 1dbd02ea28..0000000000 --- a/scene/resources/canvas.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************/ -/* canvas.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.h" -#include "servers/visual_server.h" - -RID Canvas::get_rid() const { - - return canvas; -} - -Canvas::Canvas() { - - canvas = VisualServer::get_singleton()->canvas_create(); -} - -Canvas::~Canvas() { - VisualServer::get_singleton()->free(canvas); -} diff --git a/scene/resources/canvas.h b/scene/resources/canvas.h deleted file mode 100644 index 621911fe0a..0000000000 --- a/scene/resources/canvas.h +++ /dev/null @@ -1,48 +0,0 @@ -/*************************************************************************/ -/* canvas.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_H -#define CANVAS_H - -#include "core/resource.h" - -class Canvas : public Resource { - - GDCLASS(Canvas, Resource); - - RID canvas; - -public: - virtual RID get_rid() const; - Canvas(); - ~Canvas(); -}; - -#endif // CANVAS_H diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp index 9b8083de97..ab2657c892 100644 --- a/scene/resources/capsule_shape_2d.cpp +++ b/scene/resources/capsule_shape_2d.cpp @@ -30,8 +30,8 @@ #include "capsule_shape_2d.h" -#include "servers/physics_2d_server.h" -#include "servers/visual_server.h" +#include "servers/physics_server_2d.h" +#include "servers/rendering_server.h" Vector<Vector2> CapsuleShape2D::_get_points() const { @@ -54,7 +54,7 @@ bool CapsuleShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_ void CapsuleShape2D::_update_shape() { - Physics2DServer::get_singleton()->shape_set_data(get_rid(), Vector2(radius, height)); + PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), Vector2(radius, height)); emit_changed(); } @@ -85,7 +85,7 @@ void CapsuleShape2D::draw(const RID &p_to_rid, const Color &p_color) { Vector<Vector2> points = _get_points(); Vector<Color> col; col.push_back(p_color); - VisualServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col); + RenderingServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col); } Rect2 CapsuleShape2D::get_rect() const { @@ -114,7 +114,7 @@ void CapsuleShape2D::_bind_methods() { } CapsuleShape2D::CapsuleShape2D() : - Shape2D(Physics2DServer::get_singleton()->capsule_shape_create()) { + Shape2D(PhysicsServer2D::get_singleton()->capsule_shape_create()) { radius = 10; height = 20; diff --git a/scene/resources/capsule_shape.cpp b/scene/resources/capsule_shape_3d.cpp index dddbd7fef3..da3ffcb306 100644 --- a/scene/resources/capsule_shape.cpp +++ b/scene/resources/capsule_shape_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* capsule_shape.cpp */ +/* capsule_shape_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,10 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "capsule_shape.h" -#include "servers/physics_server.h" +#include "capsule_shape_3d.h" +#include "servers/physics_server_3d.h" -Vector<Vector3> CapsuleShape::get_debug_mesh_lines() { +Vector<Vector3> CapsuleShape3D::get_debug_mesh_lines() { float radius = get_radius(); float height = get_height(); @@ -69,20 +69,20 @@ Vector<Vector3> CapsuleShape::get_debug_mesh_lines() { return points; } -real_t CapsuleShape::get_enclosing_radius() const { +real_t CapsuleShape3D::get_enclosing_radius() const { return radius + height * 0.5; } -void CapsuleShape::_update_shape() { +void CapsuleShape3D::_update_shape() { Dictionary d; d["radius"] = radius; d["height"] = height; - PhysicsServer::get_singleton()->shape_set_data(get_shape(), d); - Shape::_update_shape(); + PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), d); + Shape3D::_update_shape(); } -void CapsuleShape::set_radius(float p_radius) { +void CapsuleShape3D::set_radius(float p_radius) { radius = p_radius; _update_shape(); @@ -90,12 +90,12 @@ void CapsuleShape::set_radius(float p_radius) { _change_notify("radius"); } -float CapsuleShape::get_radius() const { +float CapsuleShape3D::get_radius() const { return radius; } -void CapsuleShape::set_height(float p_height) { +void CapsuleShape3D::set_height(float p_height) { height = p_height; _update_shape(); @@ -103,24 +103,24 @@ void CapsuleShape::set_height(float p_height) { _change_notify("height"); } -float CapsuleShape::get_height() const { +float CapsuleShape3D::get_height() const { return height; } -void CapsuleShape::_bind_methods() { +void CapsuleShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_radius", "radius"), &CapsuleShape::set_radius); - ClassDB::bind_method(D_METHOD("get_radius"), &CapsuleShape::get_radius); - ClassDB::bind_method(D_METHOD("set_height", "height"), &CapsuleShape::set_height); - ClassDB::bind_method(D_METHOD("get_height"), &CapsuleShape::get_height); + ClassDB::bind_method(D_METHOD("set_radius", "radius"), &CapsuleShape3D::set_radius); + ClassDB::bind_method(D_METHOD("get_radius"), &CapsuleShape3D::get_radius); + ClassDB::bind_method(D_METHOD("set_height", "height"), &CapsuleShape3D::set_height); + ClassDB::bind_method(D_METHOD("get_height"), &CapsuleShape3D::get_height); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.01,4096,0.01"), "set_radius", "get_radius"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0.01,4096,0.01"), "set_height", "get_height"); } -CapsuleShape::CapsuleShape() : - Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_CAPSULE)) { +CapsuleShape3D::CapsuleShape3D() : + Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_CAPSULE)) { radius = 1.0; height = 1.0; diff --git a/scene/resources/capsule_shape.h b/scene/resources/capsule_shape_3d.h index f097e51175..dca7a6c983 100644 --- a/scene/resources/capsule_shape.h +++ b/scene/resources/capsule_shape_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* capsule_shape.h */ +/* capsule_shape_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,11 +31,11 @@ #ifndef CAPSULE_SHAPE_H #define CAPSULE_SHAPE_H -#include "scene/resources/shape.h" +#include "scene/resources/shape_3d.h" -class CapsuleShape : public Shape { +class CapsuleShape3D : public Shape3D { - GDCLASS(CapsuleShape, Shape); + GDCLASS(CapsuleShape3D, Shape3D); float radius; float height; @@ -53,7 +53,7 @@ public: virtual Vector<Vector3> get_debug_mesh_lines(); virtual real_t get_enclosing_radius() const; - CapsuleShape(); + CapsuleShape3D(); }; #endif // CAPSULE_SHAPE_H diff --git a/scene/resources/circle_shape_2d.cpp b/scene/resources/circle_shape_2d.cpp index 37874e17ef..afb7597280 100644 --- a/scene/resources/circle_shape_2d.cpp +++ b/scene/resources/circle_shape_2d.cpp @@ -30,8 +30,8 @@ #include "circle_shape_2d.h" -#include "servers/physics_2d_server.h" -#include "servers/visual_server.h" +#include "servers/physics_server_2d.h" +#include "servers/rendering_server.h" bool CircleShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { @@ -40,7 +40,7 @@ bool CircleShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_t void CircleShape2D::_update_shape() { - Physics2DServer::get_singleton()->shape_set_data(get_rid(), radius); + PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), radius); emit_changed(); } @@ -84,11 +84,11 @@ void CircleShape2D::draw(const RID &p_to_rid, const Color &p_color) { Vector<Color> col; col.push_back(p_color); - VisualServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col); + RenderingServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col); } CircleShape2D::CircleShape2D() : - Shape2D(Physics2DServer::get_singleton()->circle_shape_create()) { + Shape2D(PhysicsServer2D::get_singleton()->circle_shape_create()) { radius = 10; _update_shape(); diff --git a/scene/resources/concave_polygon_shape_2d.cpp b/scene/resources/concave_polygon_shape_2d.cpp index c3e9e19721..c8fec3b72d 100644 --- a/scene/resources/concave_polygon_shape_2d.cpp +++ b/scene/resources/concave_polygon_shape_2d.cpp @@ -30,8 +30,8 @@ #include "concave_polygon_shape_2d.h" -#include "servers/physics_2d_server.h" -#include "servers/visual_server.h" +#include "servers/physics_server_2d.h" +#include "servers/rendering_server.h" bool ConcavePolygonShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { @@ -52,13 +52,13 @@ bool ConcavePolygonShape2D::_edit_is_selected_on_click(const Point2 &p_point, do void ConcavePolygonShape2D::set_segments(const Vector<Vector2> &p_segments) { - Physics2DServer::get_singleton()->shape_set_data(get_rid(), p_segments); + PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), p_segments); emit_changed(); } Vector<Vector2> ConcavePolygonShape2D::get_segments() const { - return Physics2DServer::get_singleton()->shape_get_data(get_rid()); + return PhysicsServer2D::get_singleton()->shape_get_data(get_rid()); } void ConcavePolygonShape2D::draw(const RID &p_to_rid, const Color &p_color) { @@ -70,7 +70,7 @@ void ConcavePolygonShape2D::draw(const RID &p_to_rid, const Color &p_color) { const Vector2 *r = s.ptr(); for (int i = 0; i < len; i += 2) { - VisualServer::get_singleton()->canvas_item_add_line(p_to_rid, r[i], r[i + 1], p_color, 2); + RenderingServer::get_singleton()->canvas_item_add_line(p_to_rid, r[i], r[i + 1], p_color, 2); } } @@ -113,7 +113,7 @@ void ConcavePolygonShape2D::_bind_methods() { } ConcavePolygonShape2D::ConcavePolygonShape2D() : - Shape2D(Physics2DServer::get_singleton()->concave_polygon_shape_create()) { + Shape2D(PhysicsServer2D::get_singleton()->concave_polygon_shape_create()) { Vector<Vector2> empty; set_segments(empty); } diff --git a/scene/resources/concave_polygon_shape.cpp b/scene/resources/concave_polygon_shape_3d.cpp index fe123a2df7..42e06a49b6 100644 --- a/scene/resources/concave_polygon_shape.cpp +++ b/scene/resources/concave_polygon_shape_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* concave_polygon_shape.cpp */ +/* concave_polygon_shape_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,11 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "concave_polygon_shape.h" +#include "concave_polygon_shape_3d.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" -Vector<Vector3> ConcavePolygonShape::get_debug_mesh_lines() { +Vector<Vector3> ConcavePolygonShape3D::get_debug_mesh_lines() { Set<DrawEdge> edges; @@ -64,7 +64,7 @@ Vector<Vector3> ConcavePolygonShape::get_debug_mesh_lines() { return points; } -real_t ConcavePolygonShape::get_enclosing_radius() const { +real_t ConcavePolygonShape3D::get_enclosing_radius() const { Vector<Vector3> data = get_faces(); const Vector3 *read = data.ptr(); real_t r = 0; @@ -74,30 +74,30 @@ real_t ConcavePolygonShape::get_enclosing_radius() const { return Math::sqrt(r); } -void ConcavePolygonShape::_update_shape() { - Shape::_update_shape(); +void ConcavePolygonShape3D::_update_shape() { + Shape3D::_update_shape(); } -void ConcavePolygonShape::set_faces(const Vector<Vector3> &p_faces) { +void ConcavePolygonShape3D::set_faces(const Vector<Vector3> &p_faces) { - PhysicsServer::get_singleton()->shape_set_data(get_shape(), p_faces); + PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), p_faces); notify_change_to_owners(); } -Vector<Vector3> ConcavePolygonShape::get_faces() const { +Vector<Vector3> ConcavePolygonShape3D::get_faces() const { - return PhysicsServer::get_singleton()->shape_get_data(get_shape()); + return PhysicsServer3D::get_singleton()->shape_get_data(get_shape()); } -void ConcavePolygonShape::_bind_methods() { +void ConcavePolygonShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_faces", "faces"), &ConcavePolygonShape::set_faces); - ClassDB::bind_method(D_METHOD("get_faces"), &ConcavePolygonShape::get_faces); + ClassDB::bind_method(D_METHOD("set_faces", "faces"), &ConcavePolygonShape3D::set_faces); + ClassDB::bind_method(D_METHOD("get_faces"), &ConcavePolygonShape3D::get_faces); ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_faces", "get_faces"); } -ConcavePolygonShape::ConcavePolygonShape() : - Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_CONCAVE_POLYGON)) { +ConcavePolygonShape3D::ConcavePolygonShape3D() : + Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_CONCAVE_POLYGON)) { //set_planes(Vector3(1,1,1)); } diff --git a/scene/resources/concave_polygon_shape.h b/scene/resources/concave_polygon_shape_3d.h index 63aabb27d7..b4e96c662f 100644 --- a/scene/resources/concave_polygon_shape.h +++ b/scene/resources/concave_polygon_shape_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* concave_polygon_shape.h */ +/* concave_polygon_shape_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef CONCAVE_POLYGON_SHAPE_H -#define CONCAVE_POLYGON_SHAPE_H +#ifndef CONCAVE_POLYGON_SHAPE_3D_H +#define CONCAVE_POLYGON_SHAPE_3D_H -#include "scene/resources/shape.h" +#include "scene/resources/shape_3d.h" -class ConcavePolygonShape : public Shape { +class ConcavePolygonShape3D : public Shape3D { - GDCLASS(ConcavePolygonShape, Shape); + GDCLASS(ConcavePolygonShape3D, Shape3D); struct DrawEdge { @@ -69,7 +69,7 @@ public: virtual Vector<Vector3> get_debug_mesh_lines(); virtual real_t get_enclosing_radius() const; - ConcavePolygonShape(); + ConcavePolygonShape3D(); }; #endif // CONCAVE_POLYGON_SHAPE_H diff --git a/scene/resources/convex_polygon_shape_2d.cpp b/scene/resources/convex_polygon_shape_2d.cpp index 95967429c9..6b1ddec507 100644 --- a/scene/resources/convex_polygon_shape_2d.cpp +++ b/scene/resources/convex_polygon_shape_2d.cpp @@ -31,8 +31,8 @@ #include "convex_polygon_shape_2d.h" #include "core/math/geometry.h" -#include "servers/physics_2d_server.h" -#include "servers/visual_server.h" +#include "servers/physics_server_2d.h" +#include "servers/rendering_server.h" bool ConvexPolygonShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { @@ -45,7 +45,7 @@ void ConvexPolygonShape2D::_update_shape() { if (Geometry::is_polygon_clockwise(final_points)) { //needs to be counter clockwise final_points.invert(); } - Physics2DServer::get_singleton()->shape_set_data(get_rid(), final_points); + PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), final_points); emit_changed(); } @@ -81,7 +81,7 @@ void ConvexPolygonShape2D::draw(const RID &p_to_rid, const Color &p_color) { Vector<Color> col; col.push_back(p_color); - VisualServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col); + RenderingServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col); } Rect2 ConvexPolygonShape2D::get_rect() const { @@ -106,5 +106,5 @@ real_t ConvexPolygonShape2D::get_enclosing_radius() const { } ConvexPolygonShape2D::ConvexPolygonShape2D() : - Shape2D(Physics2DServer::get_singleton()->convex_polygon_shape_create()) { + Shape2D(PhysicsServer2D::get_singleton()->convex_polygon_shape_create()) { } diff --git a/scene/resources/convex_polygon_shape.cpp b/scene/resources/convex_polygon_shape_3d.cpp index b7463605b4..ec9ab68015 100644 --- a/scene/resources/convex_polygon_shape.cpp +++ b/scene/resources/convex_polygon_shape_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* convex_polygon_shape.cpp */ +/* convex_polygon_shape_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,11 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "convex_polygon_shape.h" +#include "convex_polygon_shape_3d.h" #include "core/math/quick_hull.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" -Vector<Vector3> ConvexPolygonShape::get_debug_mesh_lines() { +Vector<Vector3> ConvexPolygonShape3D::get_debug_mesh_lines() { Vector<Vector3> points = get_points(); @@ -55,7 +55,7 @@ Vector<Vector3> ConvexPolygonShape::get_debug_mesh_lines() { return Vector<Vector3>(); } -real_t ConvexPolygonShape::get_enclosing_radius() const { +real_t ConvexPolygonShape3D::get_enclosing_radius() const { Vector<Vector3> data = get_points(); const Vector3 *read = data.ptr(); real_t r = 0; @@ -65,32 +65,32 @@ real_t ConvexPolygonShape::get_enclosing_radius() const { return Math::sqrt(r); } -void ConvexPolygonShape::_update_shape() { +void ConvexPolygonShape3D::_update_shape() { - PhysicsServer::get_singleton()->shape_set_data(get_shape(), points); - Shape::_update_shape(); + PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), points); + Shape3D::_update_shape(); } -void ConvexPolygonShape::set_points(const Vector<Vector3> &p_points) { +void ConvexPolygonShape3D::set_points(const Vector<Vector3> &p_points) { points = p_points; _update_shape(); notify_change_to_owners(); } -Vector<Vector3> ConvexPolygonShape::get_points() const { +Vector<Vector3> ConvexPolygonShape3D::get_points() const { return points; } -void ConvexPolygonShape::_bind_methods() { +void ConvexPolygonShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_points", "points"), &ConvexPolygonShape::set_points); - ClassDB::bind_method(D_METHOD("get_points"), &ConvexPolygonShape::get_points); + ClassDB::bind_method(D_METHOD("set_points", "points"), &ConvexPolygonShape3D::set_points); + ClassDB::bind_method(D_METHOD("get_points"), &ConvexPolygonShape3D::get_points); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "points"), "set_points", "get_points"); } -ConvexPolygonShape::ConvexPolygonShape() : - Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_CONVEX_POLYGON)) { +ConvexPolygonShape3D::ConvexPolygonShape3D() : + Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_CONVEX_POLYGON)) { } diff --git a/scene/resources/convex_polygon_shape.h b/scene/resources/convex_polygon_shape_3d.h index fcd733887e..51e4c8eb0b 100644 --- a/scene/resources/convex_polygon_shape.h +++ b/scene/resources/convex_polygon_shape_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* convex_polygon_shape.h */ +/* convex_polygon_shape_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,11 +31,11 @@ #ifndef CONVEX_POLYGON_SHAPE_H #define CONVEX_POLYGON_SHAPE_H -#include "scene/resources/shape.h" +#include "scene/resources/shape_3d.h" -class ConvexPolygonShape : public Shape { +class ConvexPolygonShape3D : public Shape3D { - GDCLASS(ConvexPolygonShape, Shape); + GDCLASS(ConvexPolygonShape3D, Shape3D); Vector<Vector3> points; protected: @@ -50,7 +50,7 @@ public: virtual Vector<Vector3> get_debug_mesh_lines(); virtual real_t get_enclosing_radius() const; - ConvexPolygonShape(); + ConvexPolygonShape3D(); }; #endif // CONVEX_POLYGON_SHAPE_H diff --git a/scene/resources/cylinder_shape.cpp b/scene/resources/cylinder_shape_3d.cpp index 53d368d32a..19f0542818 100644 --- a/scene/resources/cylinder_shape.cpp +++ b/scene/resources/cylinder_shape_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* cylinder_shape.cpp */ +/* cylinder_shape_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,10 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "cylinder_shape.h" -#include "servers/physics_server.h" +#include "cylinder_shape_3d.h" +#include "servers/physics_server_3d.h" -Vector<Vector3> CylinderShape::get_debug_mesh_lines() { +Vector<Vector3> CylinderShape3D::get_debug_mesh_lines() { float radius = get_radius(); float height = get_height(); @@ -62,20 +62,20 @@ Vector<Vector3> CylinderShape::get_debug_mesh_lines() { return points; } -real_t CylinderShape::get_enclosing_radius() const { +real_t CylinderShape3D::get_enclosing_radius() const { return Vector2(radius, height * 0.5).length(); } -void CylinderShape::_update_shape() { +void CylinderShape3D::_update_shape() { Dictionary d; d["radius"] = radius; d["height"] = height; - PhysicsServer::get_singleton()->shape_set_data(get_shape(), d); - Shape::_update_shape(); + PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), d); + Shape3D::_update_shape(); } -void CylinderShape::set_radius(float p_radius) { +void CylinderShape3D::set_radius(float p_radius) { radius = p_radius; _update_shape(); @@ -83,12 +83,12 @@ void CylinderShape::set_radius(float p_radius) { _change_notify("radius"); } -float CylinderShape::get_radius() const { +float CylinderShape3D::get_radius() const { return radius; } -void CylinderShape::set_height(float p_height) { +void CylinderShape3D::set_height(float p_height) { height = p_height; _update_shape(); @@ -96,24 +96,24 @@ void CylinderShape::set_height(float p_height) { _change_notify("height"); } -float CylinderShape::get_height() const { +float CylinderShape3D::get_height() const { return height; } -void CylinderShape::_bind_methods() { +void CylinderShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_radius", "radius"), &CylinderShape::set_radius); - ClassDB::bind_method(D_METHOD("get_radius"), &CylinderShape::get_radius); - ClassDB::bind_method(D_METHOD("set_height", "height"), &CylinderShape::set_height); - ClassDB::bind_method(D_METHOD("get_height"), &CylinderShape::get_height); + ClassDB::bind_method(D_METHOD("set_radius", "radius"), &CylinderShape3D::set_radius); + ClassDB::bind_method(D_METHOD("get_radius"), &CylinderShape3D::get_radius); + ClassDB::bind_method(D_METHOD("set_height", "height"), &CylinderShape3D::set_height); + ClassDB::bind_method(D_METHOD("get_height"), &CylinderShape3D::get_height); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.01,4096,0.01"), "set_radius", "get_radius"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0.01,4096,0.01"), "set_height", "get_height"); } -CylinderShape::CylinderShape() : - Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_CYLINDER)) { +CylinderShape3D::CylinderShape3D() : + Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_CYLINDER)) { radius = 1.0; height = 2.0; diff --git a/scene/resources/cylinder_shape.h b/scene/resources/cylinder_shape_3d.h index a26fda10cd..7b37f733e0 100644 --- a/scene/resources/cylinder_shape.h +++ b/scene/resources/cylinder_shape_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* cylinder_shape.h */ +/* cylinder_shape_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef CYLINDER_SHAPE_H -#define CYLINDER_SHAPE_H +#ifndef CYLINDER_SHAPE_3D_H +#define CYLINDER_SHAPE_3D_H -#include "scene/resources/shape.h" +#include "scene/resources/shape_3d.h" -class CylinderShape : public Shape { +class CylinderShape3D : public Shape3D { - GDCLASS(CylinderShape, Shape); + GDCLASS(CylinderShape3D, Shape3D); float radius; float height; @@ -52,7 +52,7 @@ public: virtual Vector<Vector3> get_debug_mesh_lines(); virtual real_t get_enclosing_radius() const; - CylinderShape(); + CylinderShape3D(); }; #endif // CYLINDER_SHAPE_H diff --git a/scene/resources/default_theme/SCsub b/scene/resources/default_theme/SCsub index b01e2fd54d..fc61250247 100644 --- a/scene/resources/default_theme/SCsub +++ b/scene/resources/default_theme/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/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 9f5b49c4c3..a1e8bf51bd 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -188,6 +188,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const // Panel theme->set_stylebox("panel", "Panel", make_stylebox(panel_bg_png, 0, 0, 0, 0)); + theme->set_stylebox("panel_fg", "Panel", make_stylebox(panel_bg_png, 0, 0, 0, 0)); // Focus @@ -496,6 +497,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_stylebox("slider", "HSlider", make_stylebox(hslider_bg_png, 4, 4, 4, 4)); theme->set_stylebox("grabber_area", "HSlider", make_stylebox(hslider_bg_png, 4, 4, 4, 4)); + theme->set_stylebox("grabber_area_highlight", "HSlider", make_stylebox(hslider_bg_png, 4, 4, 4, 4)); theme->set_icon("grabber", "HSlider", make_icon(hslider_grabber_png)); theme->set_icon("grabber_highlight", "HSlider", make_icon(hslider_grabber_hl_png)); @@ -506,6 +508,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_stylebox("slider", "VSlider", make_stylebox(vslider_bg_png, 4, 4, 4, 4)); theme->set_stylebox("grabber_area", "VSlider", make_stylebox(vslider_bg_png, 4, 4, 4, 4)); + theme->set_stylebox("grabber_area_highlight", "VSlider", make_stylebox(vslider_bg_png, 4, 4, 4, 4)); theme->set_icon("grabber", "VSlider", make_icon(vslider_grabber_png)); theme->set_icon("grabber_highlight", "VSlider", make_icon(vslider_grabber_hl_png)); @@ -523,17 +526,19 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const // WindowDialog - theme->set_stylebox("panel", "WindowDialog", sb_expand(make_stylebox(popup_window_png, 10, 26, 10, 8), 8, 24, 8, 6)); - theme->set_constant("scaleborder_size", "WindowDialog", 4 * scale); + theme->set_stylebox("panel", "Window", default_style); + theme->set_stylebox("window_panel", "Window", sb_expand(make_stylebox(popup_window_png, 10, 26, 10, 8), 8, 24, 8, 6)); + theme->set_constant("scaleborder_size", "Window", 4 * scale); - theme->set_font("title_font", "WindowDialog", large_font); - theme->set_color("title_color", "WindowDialog", Color(0, 0, 0)); - theme->set_constant("title_height", "WindowDialog", 20 * scale); + theme->set_font("title_font", "Window", large_font); + theme->set_color("title_color", "Window", Color(0, 0, 0)); + theme->set_constant("title_height", "Window", 20 * scale); + theme->set_constant("resize_margin", "Window", 4 * scale); - theme->set_icon("close", "WindowDialog", make_icon(close_png)); - theme->set_icon("close_highlight", "WindowDialog", make_icon(close_hl_png)); - theme->set_constant("close_h_ofs", "WindowDialog", 18 * scale); - theme->set_constant("close_v_ofs", "WindowDialog", 18 * scale); + theme->set_icon("close", "Window", make_icon(close_png)); + theme->set_icon("close_highlight", "Window", make_icon(close_hl_png)); + theme->set_constant("close_h_ofs", "Window", 18 * scale); + theme->set_constant("close_v_ofs", "Window", 18 * scale); // File Dialog @@ -887,9 +892,9 @@ void make_default_theme(bool p_hidpi, Ref<Font> p_font) { void clear_default_theme() { - Theme::set_project_default(NULL); - Theme::set_default(NULL); - Theme::set_default_icon(NULL); - Theme::set_default_style(NULL); - Theme::set_default_font(NULL); + Theme::set_project_default(nullptr); + Theme::set_default(nullptr); + Theme::set_default_icon(nullptr); + Theme::set_default_style(nullptr); + Theme::set_default_font(nullptr); } diff --git a/scene/resources/default_theme/make_header.py b/scene/resources/default_theme/make_header.py index cf0ccf1c3a..efad3b2815 100755 --- a/scene/resources/default_theme/make_header.py +++ b/scene/resources/default_theme/make_header.py @@ -13,7 +13,7 @@ os.chdir(os.path.dirname(os.path.realpath(__file__))) f = open("theme_data.h", "wb") -f.write(b"// THIS FILE HAS BEEN AUTOGENERATED, DON\'T EDIT!!\n") +f.write(b"// THIS FILE HAS BEEN AUTOGENERATED, DON'T EDIT!!\n") # Generate png image block f.write(b"\n// png image block\n") @@ -31,17 +31,17 @@ for x in pixmaps: pngf = open(x, "rb") b = pngf.read(1) - while(len(b) == 1): + while len(b) == 1: f.write(hex(ord(b)).encode(enc)) b = pngf.read(1) - if (len(b) == 1): + if len(b) == 1: f.write(b", ") f.write(b"\n};\n") pngf.close() # Generate shaders block -f.write(b"\n// shaders block\n"); +f.write(b"\n// shaders block\n") shaders = glob.glob("*.gsl") shaders.sort() @@ -56,15 +56,15 @@ for x in shaders: sf = open(x, "rb") b = sf.readline() - while(b != ""): - if (b.endswith("\r\n")): + while b != "": + if b.endswith("\r\n"): b = b[:-2] - if (b.endswith("\n")): + if b.endswith("\n"): b = b[:-1] - s = ' \"' + b + s = ' "' + b f.write(s.encode(enc)) b = sf.readline() - if (b != ""): + if b != "": f.write(b'"\n') f.write(b'";\n') diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 410c4990a2..eea4d12d0e 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -107,7 +107,7 @@ DynamicFontData::DynamicFontData() { antialiased = true; force_autohinter = false; hinting = DynamicFontData::HINTING_NORMAL; - font_mem = NULL; + font_mem = nullptr; font_mem_size = 0; } @@ -124,7 +124,7 @@ Error DynamicFontAtSize::_load() { ERR_FAIL_COND_V_MSG(error != 0, ERR_CANT_CREATE, "Error initializing FreeType."); // FT_OPEN_STREAM is extremely slow only on Android. - if (OS::get_singleton()->get_name() == "Android" && font->font_mem == NULL && font->font_path != String()) { + if (OS::get_singleton()->get_name() == "Android" && font->font_mem == nullptr && font->font_path != String()) { // cache font only once for each font->font_path if (_fontdata.has(font->font_path)) { @@ -148,7 +148,7 @@ Error DynamicFontAtSize::_load() { } } - if (font->font_mem == NULL && font->font_path != String()) { + if (font->font_mem == nullptr && font->font_path != String()) { FileAccess *f = FileAccess::open(font->font_path, FileAccess::READ); if (!f) { @@ -157,7 +157,7 @@ Error DynamicFontAtSize::_load() { } memset(&stream, 0, sizeof(FT_StreamRec)); - stream.base = NULL; + stream.base = nullptr; stream.size = f->get_len(); stream.pos = 0; stream.descriptor.pointer = f; @@ -245,7 +245,7 @@ float DynamicFontAtSize::get_descent() const { const Pair<const DynamicFontAtSize::Character *, DynamicFontAtSize *> DynamicFontAtSize::_find_char_with_font(CharType p_char, const Vector<Ref<DynamicFontAtSize>> &p_fallbacks) const { const Character *chr = char_map.getptr(p_char); - ERR_FAIL_COND_V(!chr, (Pair<const Character *, DynamicFontAtSize *>(NULL, NULL))); + ERR_FAIL_COND_V(!chr, (Pair<const Character *, DynamicFontAtSize *>(nullptr, nullptr))); if (!chr->found) { @@ -269,7 +269,7 @@ const Pair<const DynamicFontAtSize::Character *, DynamicFontAtSize *> DynamicFon //not found, try 0xFFFD to display 'not found'. const_cast<DynamicFontAtSize *>(this)->_update_char(0xFFFD); chr = char_map.getptr(0xFFFD); - ERR_FAIL_COND_V(!chr, (Pair<const Character *, DynamicFontAtSize *>(NULL, NULL))); + ERR_FAIL_COND_V(!chr, (Pair<const Character *, DynamicFontAtSize *>(nullptr, nullptr))); } return Pair<const Character *, DynamicFontAtSize *>(chr, const_cast<DynamicFontAtSize *>(this)); @@ -336,7 +336,7 @@ float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharT modulate.r = modulate.g = modulate.b = 1.0; } RID texture = font->textures[ch->texture_idx].texture->get_rid(); - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, ch->rect.size), texture, ch->rect_uv, modulate, false, RID(), RID(), Color(1, 1, 1, 1), false); + RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, ch->rect.size), texture, ch->rect_uv, modulate, false, RID(), RID(), Color(1, 1, 1, 1), false); } advance = ch->advance; @@ -565,7 +565,7 @@ DynamicFontAtSize::Character DynamicFontAtSize::_make_outline_char(CharType p_ch goto cleanup_stroker; if (FT_Glyph_Stroke(&glyph, stroker, 1) != 0) goto cleanup_glyph; - if (FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1) != 0) + if (FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, nullptr, 1) != 0) goto cleanup_glyph; glyph_bitmap = (FT_BitmapGlyph)glyph; @@ -992,11 +992,12 @@ void DynamicFont::_bind_methods() { Mutex DynamicFont::dynamic_font_mutex; -SelfList<DynamicFont>::List *DynamicFont::dynamic_fonts = NULL; +SelfList<DynamicFont>::List *DynamicFont::dynamic_fonts = nullptr; DynamicFont::DynamicFont() : font_list(this) { + valid = false; cache_id.size = 16; outline_cache_id.size = 16; spacing_top = 0; @@ -1020,7 +1021,7 @@ void DynamicFont::initialize_dynamic_fonts() { void DynamicFont::finish_dynamic_fonts() { memdelete(dynamic_fonts); - dynamic_fonts = NULL; + dynamic_fonts = nullptr; } void DynamicFont::update_oversampling() { @@ -1063,7 +1064,7 @@ void DynamicFont::update_oversampling() { ///////////////////////// -RES ResourceFormatLoaderDynamicFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) { +RES ResourceFormatLoaderDynamicFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { if (r_error) *r_error = ERR_FILE_CANT_OPEN; diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index 88b1df039e..ef4b9dd9d0 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -302,7 +302,7 @@ VARIANT_ENUM_CAST(DynamicFont::SpacingType); class ResourceFormatLoaderDynamicFont : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index d407dd3722..835fef81e1 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -30,7 +30,7 @@ #include "environment.h" #include "core/project_settings.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" #include "texture.h" RID Environment::get_rid() const { @@ -41,7 +41,7 @@ RID Environment::get_rid() const { void Environment::set_background(BGMode p_bg) { bg_mode = p_bg; - VS::get_singleton()->environment_set_background(environment, VS::EnvironmentBG(p_bg)); + RS::get_singleton()->environment_set_background(environment, RS::EnvironmentBG(p_bg)); _change_notify(); } @@ -53,56 +53,56 @@ void Environment::set_sky(const Ref<Sky> &p_sky) { if (bg_sky.is_valid()) sb_rid = bg_sky->get_rid(); - VS::get_singleton()->environment_set_sky(environment, sb_rid); + RS::get_singleton()->environment_set_sky(environment, sb_rid); } void Environment::set_sky_custom_fov(float p_scale) { bg_sky_custom_fov = p_scale; - VS::get_singleton()->environment_set_sky_custom_fov(environment, p_scale); + RS::get_singleton()->environment_set_sky_custom_fov(environment, p_scale); } void Environment::set_bg_color(const Color &p_color) { bg_color = p_color; - VS::get_singleton()->environment_set_bg_color(environment, p_color); + RS::get_singleton()->environment_set_bg_color(environment, p_color); } void Environment::set_bg_energy(float p_energy) { bg_energy = p_energy; - VS::get_singleton()->environment_set_bg_energy(environment, p_energy); + RS::get_singleton()->environment_set_bg_energy(environment, p_energy); } void Environment::set_canvas_max_layer(int p_max_layer) { bg_canvas_max_layer = p_max_layer; - VS::get_singleton()->environment_set_canvas_max_layer(environment, p_max_layer); + RS::get_singleton()->environment_set_canvas_max_layer(environment, p_max_layer); } void Environment::set_ambient_light_color(const Color &p_color) { ambient_color = p_color; - VS::get_singleton()->environment_set_ambient_light(environment, ambient_color, VS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, VS::EnvironmentReflectionSource(reflection_source), ao_color); + RS::get_singleton()->environment_set_ambient_light(environment, ambient_color, RS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, RS::EnvironmentReflectionSource(reflection_source), ao_color); } void Environment::set_ambient_light_energy(float p_energy) { ambient_energy = p_energy; - VS::get_singleton()->environment_set_ambient_light(environment, ambient_color, VS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, VS::EnvironmentReflectionSource(reflection_source), ao_color); + RS::get_singleton()->environment_set_ambient_light(environment, ambient_color, RS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, RS::EnvironmentReflectionSource(reflection_source), ao_color); } void Environment::set_ambient_light_sky_contribution(float p_energy) { ambient_sky_contribution = p_energy; - VS::get_singleton()->environment_set_ambient_light(environment, ambient_color, VS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, VS::EnvironmentReflectionSource(reflection_source), ao_color); + RS::get_singleton()->environment_set_ambient_light(environment, ambient_color, RS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, RS::EnvironmentReflectionSource(reflection_source), ao_color); } void Environment::set_camera_feed_id(int p_camera_feed_id) { camera_feed_id = p_camera_feed_id; // FIXME: Disabled during Vulkan refactoring, should be ported. #if 0 - VS::get_singleton()->environment_set_camera_feed_id(environment, camera_feed_id); + RS::get_singleton()->environment_set_camera_feed_id(environment, camera_feed_id); #endif }; void Environment::set_ambient_source(AmbientSource p_source) { ambient_source = p_source; - VS::get_singleton()->environment_set_ambient_light(environment, ambient_color, VS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, VS::EnvironmentReflectionSource(reflection_source), ao_color); + RS::get_singleton()->environment_set_ambient_light(environment, ambient_color, RS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, RS::EnvironmentReflectionSource(reflection_source), ao_color); } Environment::AmbientSource Environment::get_ambient_source() const { @@ -110,7 +110,7 @@ Environment::AmbientSource Environment::get_ambient_source() const { } void Environment::set_reflection_source(ReflectionSource p_source) { reflection_source = p_source; - VS::get_singleton()->environment_set_ambient_light(environment, ambient_color, VS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, VS::EnvironmentReflectionSource(reflection_source), ao_color); + RS::get_singleton()->environment_set_ambient_light(environment, ambient_color, RS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, RS::EnvironmentReflectionSource(reflection_source), ao_color); } Environment::ReflectionSource Environment::get_reflection_source() const { return reflection_source; @@ -132,7 +132,7 @@ float Environment::get_sky_custom_fov() const { void Environment::set_sky_rotation(const Vector3 &p_rotation) { sky_rotation = p_rotation; - VS::get_singleton()->environment_set_sky_orientation(environment, Basis(p_rotation)); + RS::get_singleton()->environment_set_sky_orientation(environment, Basis(p_rotation)); } Vector3 Environment::get_sky_rotation() const { @@ -172,7 +172,7 @@ int Environment::get_camera_feed_id(void) const { void Environment::set_tonemapper(ToneMapper p_tone_mapper) { tone_mapper = p_tone_mapper; - VS::get_singleton()->environment_set_tonemap(environment, VS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); + RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } Environment::ToneMapper Environment::get_tonemapper() const { @@ -183,7 +183,7 @@ Environment::ToneMapper Environment::get_tonemapper() const { void Environment::set_tonemap_exposure(float p_exposure) { tonemap_exposure = p_exposure; - VS::get_singleton()->environment_set_tonemap(environment, VS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); + RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } float Environment::get_tonemap_exposure() const { @@ -194,7 +194,7 @@ float Environment::get_tonemap_exposure() const { void Environment::set_tonemap_white(float p_white) { tonemap_white = p_white; - VS::get_singleton()->environment_set_tonemap(environment, VS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); + RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } float Environment::get_tonemap_white() const { @@ -204,7 +204,7 @@ float Environment::get_tonemap_white() const { void Environment::set_tonemap_auto_exposure(bool p_enabled) { tonemap_auto_exposure = p_enabled; - VS::get_singleton()->environment_set_tonemap(environment, VS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); + RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); _change_notify(); } bool Environment::get_tonemap_auto_exposure() const { @@ -215,7 +215,7 @@ bool Environment::get_tonemap_auto_exposure() const { void Environment::set_tonemap_auto_exposure_max(float p_auto_exposure_max) { tonemap_auto_exposure_max = p_auto_exposure_max; - VS::get_singleton()->environment_set_tonemap(environment, VS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); + RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } float Environment::get_tonemap_auto_exposure_max() const { @@ -225,7 +225,7 @@ float Environment::get_tonemap_auto_exposure_max() const { void Environment::set_tonemap_auto_exposure_min(float p_auto_exposure_min) { tonemap_auto_exposure_min = p_auto_exposure_min; - VS::get_singleton()->environment_set_tonemap(environment, VS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); + RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } float Environment::get_tonemap_auto_exposure_min() const { @@ -235,7 +235,7 @@ float Environment::get_tonemap_auto_exposure_min() const { void Environment::set_tonemap_auto_exposure_speed(float p_auto_exposure_speed) { tonemap_auto_exposure_speed = p_auto_exposure_speed; - VS::get_singleton()->environment_set_tonemap(environment, VS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); + RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } float Environment::get_tonemap_auto_exposure_speed() const { @@ -245,7 +245,7 @@ float Environment::get_tonemap_auto_exposure_speed() const { void Environment::set_tonemap_auto_exposure_grey(float p_auto_exposure_grey) { tonemap_auto_exposure_grey = p_auto_exposure_grey; - VS::get_singleton()->environment_set_tonemap(environment, VS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); + RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } float Environment::get_tonemap_auto_exposure_grey() const { @@ -255,7 +255,7 @@ float Environment::get_tonemap_auto_exposure_grey() const { void Environment::set_adjustment_enable(bool p_enable) { adjustment_enabled = p_enable; - VS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); + RS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); _change_notify(); } @@ -267,7 +267,7 @@ bool Environment::is_adjustment_enabled() const { void Environment::set_adjustment_brightness(float p_brightness) { adjustment_brightness = p_brightness; - VS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); + RS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); } float Environment::get_adjustment_brightness() const { @@ -277,7 +277,7 @@ float Environment::get_adjustment_brightness() const { void Environment::set_adjustment_contrast(float p_contrast) { adjustment_contrast = p_contrast; - VS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); + RS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); } float Environment::get_adjustment_contrast() const { @@ -287,7 +287,7 @@ float Environment::get_adjustment_contrast() const { void Environment::set_adjustment_saturation(float p_saturation) { adjustment_saturation = p_saturation; - VS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); + RS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); } float Environment::get_adjustment_saturation() const { @@ -297,7 +297,7 @@ float Environment::get_adjustment_saturation() const { void Environment::set_adjustment_color_correction(const Ref<Texture2D> &p_ramp) { adjustment_color_correction = p_ramp; - VS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); + RS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); } Ref<Texture2D> Environment::get_adjustment_color_correction() const { @@ -345,7 +345,7 @@ void Environment::_validate_property(PropertyInfo &property) const { "ssao_", "glow_", "adjustment_", - NULL + nullptr }; @@ -354,7 +354,7 @@ void Environment::_validate_property(PropertyInfo &property) const { "tonemap_", "ss_reflections_", "ssao_", - NULL + nullptr }; @@ -371,7 +371,7 @@ void Environment::_validate_property(PropertyInfo &property) const { prefixes++; } - if (VisualServer::get_singleton()->is_low_end()) { + if (RenderingServer::get_singleton()->is_low_end()) { prefixes = high_end_prefixes; while (*prefixes) { String prefix = String(*prefixes); @@ -389,7 +389,7 @@ void Environment::_validate_property(PropertyInfo &property) const { void Environment::set_ssr_enabled(bool p_enable) { ssr_enabled = p_enable; - VS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance, ssr_roughness); + RS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance); _change_notify(); } @@ -401,7 +401,7 @@ bool Environment::is_ssr_enabled() const { void Environment::set_ssr_max_steps(int p_steps) { ssr_max_steps = p_steps; - VS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance, ssr_roughness); + RS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance); } int Environment::get_ssr_max_steps() const { @@ -411,7 +411,7 @@ int Environment::get_ssr_max_steps() const { void Environment::set_ssr_fade_in(float p_fade_in) { ssr_fade_in = p_fade_in; - VS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance, ssr_roughness); + RS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance); } float Environment::get_ssr_fade_in() const { @@ -421,7 +421,7 @@ float Environment::get_ssr_fade_in() const { void Environment::set_ssr_fade_out(float p_fade_out) { ssr_fade_out = p_fade_out; - VS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance, ssr_roughness); + RS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance); } float Environment::get_ssr_fade_out() const { @@ -431,27 +431,17 @@ float Environment::get_ssr_fade_out() const { void Environment::set_ssr_depth_tolerance(float p_depth_tolerance) { ssr_depth_tolerance = p_depth_tolerance; - VS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance, ssr_roughness); + RS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance); } float Environment::get_ssr_depth_tolerance() const { return ssr_depth_tolerance; } -void Environment::set_ssr_rough(bool p_enable) { - - ssr_roughness = p_enable; - VS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance, ssr_roughness); -} -bool Environment::is_ssr_rough() const { - - return ssr_roughness; -} - void Environment::set_ssao_enabled(bool p_enable) { ssao_enabled = p_enable; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); + RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); _change_notify(); } @@ -463,7 +453,7 @@ bool Environment::is_ssao_enabled() const { void Environment::set_ssao_radius(float p_radius) { ssao_radius = p_radius; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); + RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_radius() const { @@ -473,7 +463,7 @@ float Environment::get_ssao_radius() const { void Environment::set_ssao_intensity(float p_intensity) { ssao_intensity = p_intensity; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); + RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_intensity() const { @@ -484,7 +474,7 @@ float Environment::get_ssao_intensity() const { void Environment::set_ssao_bias(float p_bias) { ssao_bias = p_bias; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); + RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_bias() const { @@ -494,7 +484,7 @@ float Environment::get_ssao_bias() const { void Environment::set_ssao_direct_light_affect(float p_direct_light_affect) { ssao_direct_light_affect = p_direct_light_affect; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); + RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_direct_light_affect() const { @@ -504,7 +494,7 @@ float Environment::get_ssao_direct_light_affect() const { void Environment::set_ssao_ao_channel_affect(float p_ao_channel_affect) { ssao_ao_channel_affect = p_ao_channel_affect; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); + RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_ao_channel_affect() const { @@ -514,7 +504,7 @@ float Environment::get_ssao_ao_channel_affect() const { void Environment::set_ao_color(const Color &p_color) { ao_color = p_color; - VS::get_singleton()->environment_set_ambient_light(environment, ambient_color, VS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, VS::EnvironmentReflectionSource(reflection_source), ao_color); + RS::get_singleton()->environment_set_ambient_light(environment, ambient_color, RS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, RS::EnvironmentReflectionSource(reflection_source), ao_color); } Color Environment::get_ao_color() const { @@ -525,7 +515,7 @@ Color Environment::get_ao_color() const { void Environment::set_ssao_blur(SSAOBlur p_blur) { ssao_blur = p_blur; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); + RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } Environment::SSAOBlur Environment::get_ssao_blur() const { @@ -535,7 +525,7 @@ Environment::SSAOBlur Environment::get_ssao_blur() const { void Environment::set_ssao_edge_sharpness(float p_edge_sharpness) { ssao_edge_sharpness = p_edge_sharpness; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); + RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_edge_sharpness() const { @@ -546,7 +536,7 @@ float Environment::get_ssao_edge_sharpness() const { void Environment::set_glow_enabled(bool p_enabled) { glow_enabled = p_enabled; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); + RS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, RS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap); _change_notify(); } @@ -557,18 +547,18 @@ bool Environment::is_glow_enabled() const { void Environment::set_glow_level(int p_level, bool p_enabled) { - ERR_FAIL_INDEX(p_level, VS::MAX_GLOW_LEVELS); + ERR_FAIL_INDEX(p_level, RS::MAX_GLOW_LEVELS); if (p_enabled) glow_levels |= (1 << p_level); else glow_levels &= ~(1 << p_level); - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); + RS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, RS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap); } bool Environment::is_glow_level_enabled(int p_level) const { - ERR_FAIL_INDEX_V(p_level, VS::MAX_GLOW_LEVELS, false); + ERR_FAIL_INDEX_V(p_level, RS::MAX_GLOW_LEVELS, false); return glow_levels & (1 << p_level); } @@ -577,7 +567,7 @@ void Environment::set_glow_intensity(float p_intensity) { glow_intensity = p_intensity; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); + RS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, RS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap); } float Environment::get_glow_intensity() const { @@ -587,7 +577,7 @@ float Environment::get_glow_intensity() const { void Environment::set_glow_strength(float p_strength) { glow_strength = p_strength; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); + RS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, RS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap); } float Environment::get_glow_strength() const { @@ -597,7 +587,7 @@ float Environment::get_glow_strength() const { void Environment::set_glow_mix(float p_mix) { glow_mix = p_mix; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); + RS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, RS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap); } float Environment::get_glow_mix() const { @@ -608,7 +598,7 @@ void Environment::set_glow_bloom(float p_threshold) { glow_bloom = p_threshold; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); + RS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, RS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap); } float Environment::get_glow_bloom() const { @@ -619,7 +609,7 @@ void Environment::set_glow_blend_mode(GlowBlendMode p_mode) { glow_blend_mode = p_mode; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); + RS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, RS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap); _change_notify(); } Environment::GlowBlendMode Environment::get_glow_blend_mode() const { @@ -631,7 +621,7 @@ void Environment::set_glow_hdr_bleed_threshold(float p_threshold) { glow_hdr_bleed_threshold = p_threshold; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); + RS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, RS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap); } float Environment::get_glow_hdr_bleed_threshold() const { @@ -642,7 +632,7 @@ void Environment::set_glow_hdr_luminance_cap(float p_amount) { glow_hdr_luminance_cap = p_amount; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); + RS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, RS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap); } float Environment::get_glow_hdr_luminance_cap() const { @@ -653,28 +643,17 @@ void Environment::set_glow_hdr_bleed_scale(float p_scale) { glow_hdr_bleed_scale = p_scale; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); + RS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, RS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap); } float Environment::get_glow_hdr_bleed_scale() const { return glow_hdr_bleed_scale; } -void Environment::set_glow_bicubic_upscale(bool p_enable) { - - glow_bicubic_upscale = p_enable; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); -} - -bool Environment::is_glow_bicubic_upscale_enabled() const { - - return glow_bicubic_upscale; -} - void Environment::set_fog_enabled(bool p_enabled) { fog_enabled = p_enabled; - VS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); + RS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); _change_notify(); } @@ -686,7 +665,7 @@ bool Environment::is_fog_enabled() const { void Environment::set_fog_color(const Color &p_color) { fog_color = p_color; - VS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); + RS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); } Color Environment::get_fog_color() const { @@ -696,7 +675,7 @@ Color Environment::get_fog_color() const { void Environment::set_fog_sun_color(const Color &p_color) { fog_sun_color = p_color; - VS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); + RS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); } Color Environment::get_fog_sun_color() const { @@ -706,7 +685,7 @@ Color Environment::get_fog_sun_color() const { void Environment::set_fog_sun_amount(float p_amount) { fog_sun_amount = p_amount; - VS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); + RS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); } float Environment::get_fog_sun_amount() const { @@ -716,7 +695,7 @@ float Environment::get_fog_sun_amount() const { void Environment::set_fog_depth_enabled(bool p_enabled) { fog_depth_enabled = p_enabled; - VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); + RS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } bool Environment::is_fog_depth_enabled() const { @@ -726,7 +705,7 @@ bool Environment::is_fog_depth_enabled() const { void Environment::set_fog_depth_begin(float p_distance) { fog_depth_begin = p_distance; - VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); + RS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } float Environment::get_fog_depth_begin() const { @@ -736,7 +715,7 @@ float Environment::get_fog_depth_begin() const { void Environment::set_fog_depth_end(float p_distance) { fog_depth_end = p_distance; - VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); + RS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } float Environment::get_fog_depth_end() const { @@ -747,7 +726,7 @@ float Environment::get_fog_depth_end() const { void Environment::set_fog_depth_curve(float p_curve) { fog_depth_curve = p_curve; - VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); + RS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } float Environment::get_fog_depth_curve() const { @@ -757,7 +736,7 @@ float Environment::get_fog_depth_curve() const { void Environment::set_fog_transmit_enabled(bool p_enabled) { fog_transmit_enabled = p_enabled; - VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); + RS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } bool Environment::is_fog_transmit_enabled() const { @@ -767,7 +746,7 @@ bool Environment::is_fog_transmit_enabled() const { void Environment::set_fog_transmit_curve(float p_curve) { fog_transmit_curve = p_curve; - VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); + RS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } float Environment::get_fog_transmit_curve() const { @@ -777,7 +756,7 @@ float Environment::get_fog_transmit_curve() const { void Environment::set_fog_height_enabled(bool p_enabled) { fog_height_enabled = p_enabled; - VS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); + RS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); } bool Environment::is_fog_height_enabled() const { @@ -787,7 +766,7 @@ bool Environment::is_fog_height_enabled() const { void Environment::set_fog_height_min(float p_distance) { fog_height_min = p_distance; - VS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); + RS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); } float Environment::get_fog_height_min() const { @@ -797,7 +776,7 @@ float Environment::get_fog_height_min() const { void Environment::set_fog_height_max(float p_distance) { fog_height_max = p_distance; - VS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); + RS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); } float Environment::get_fog_height_max() const { @@ -807,7 +786,7 @@ float Environment::get_fog_height_max() const { void Environment::set_fog_height_curve(float p_distance) { fog_height_curve = p_distance; - VS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); + RS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); } float Environment::get_fog_height_curve() const { @@ -992,16 +971,12 @@ void Environment::_bind_methods() { ClassDB::bind_method(D_METHOD("set_ssr_depth_tolerance", "depth_tolerance"), &Environment::set_ssr_depth_tolerance); ClassDB::bind_method(D_METHOD("get_ssr_depth_tolerance"), &Environment::get_ssr_depth_tolerance); - ClassDB::bind_method(D_METHOD("set_ssr_rough", "rough"), &Environment::set_ssr_rough); - ClassDB::bind_method(D_METHOD("is_ssr_rough"), &Environment::is_ssr_rough); - ADD_GROUP("SS Reflections", "ss_reflections_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ss_reflections_enabled"), "set_ssr_enabled", "is_ssr_enabled"); ADD_PROPERTY(PropertyInfo(Variant::INT, "ss_reflections_max_steps", PROPERTY_HINT_RANGE, "1,512,1"), "set_ssr_max_steps", "get_ssr_max_steps"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ss_reflections_fade_in", PROPERTY_HINT_EXP_EASING), "set_ssr_fade_in", "get_ssr_fade_in"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ss_reflections_fade_out", PROPERTY_HINT_EXP_EASING), "set_ssr_fade_out", "get_ssr_fade_out"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ss_reflections_depth_tolerance", PROPERTY_HINT_RANGE, "0.1,128,0.1"), "set_ssr_depth_tolerance", "get_ssr_depth_tolerance"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ss_reflections_roughness"), "set_ssr_rough", "is_ssr_rough"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ss_reflections_depth_tolerance", PROPERTY_HINT_RANGE, "0.01,128,0.1"), "set_ssr_depth_tolerance", "get_ssr_depth_tolerance"); ClassDB::bind_method(D_METHOD("set_ssao_enabled", "enabled"), &Environment::set_ssao_enabled); ClassDB::bind_method(D_METHOD("is_ssao_enabled"), &Environment::is_ssao_enabled); @@ -1067,9 +1042,6 @@ void Environment::_bind_methods() { ClassDB::bind_method(D_METHOD("set_glow_hdr_bleed_scale", "scale"), &Environment::set_glow_hdr_bleed_scale); ClassDB::bind_method(D_METHOD("get_glow_hdr_bleed_scale"), &Environment::get_glow_hdr_bleed_scale); - ClassDB::bind_method(D_METHOD("set_glow_bicubic_upscale", "enabled"), &Environment::set_glow_bicubic_upscale); - ClassDB::bind_method(D_METHOD("is_glow_bicubic_upscale_enabled"), &Environment::is_glow_bicubic_upscale_enabled); - ADD_GROUP("Glow", "glow_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "glow_enabled"), "set_glow_enabled", "is_glow_enabled"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "glow_levels/1"), "set_glow_level", "is_glow_level_enabled", 0); @@ -1088,7 +1060,6 @@ void Environment::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_hdr_threshold", PROPERTY_HINT_RANGE, "0.0,4.0,0.01"), "set_glow_hdr_bleed_threshold", "get_glow_hdr_bleed_threshold"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_hdr_luminance_cap", PROPERTY_HINT_RANGE, "0.0,256.0,0.01"), "set_glow_hdr_luminance_cap", "get_glow_hdr_luminance_cap"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_hdr_scale", PROPERTY_HINT_RANGE, "0.0,4.0,0.01"), "set_glow_hdr_bleed_scale", "get_glow_hdr_bleed_scale"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "glow_bicubic_upscale"), "set_glow_bicubic_upscale", "is_glow_bicubic_upscale_enabled"); ClassDB::bind_method(D_METHOD("set_adjustment_enable", "enabled"), &Environment::set_adjustment_enable); ClassDB::bind_method(D_METHOD("is_adjustment_enabled"), &Environment::is_adjustment_enabled); @@ -1152,7 +1123,7 @@ Environment::Environment() : ssao_blur(SSAO_BLUR_3x3), glow_blend_mode(GLOW_BLEND_MODE_ADDITIVE) { - environment = VS::get_singleton()->environment_create(); + environment = RS::get_singleton()->environment_create(); bg_mode = BG_CLEAR_COLOR; bg_sky_custom_fov = 0; @@ -1188,7 +1159,6 @@ Environment::Environment() : ssr_fade_in = 0.15; ssr_fade_out = 2.0; ssr_depth_tolerance = 0.2; - ssr_roughness = true; ssao_enabled = false; ssao_radius = 1; @@ -1209,7 +1179,6 @@ Environment::Environment() : glow_hdr_bleed_threshold = 1.0; glow_hdr_luminance_cap = 12.0; glow_hdr_bleed_scale = 2.0; - glow_bicubic_upscale = false; fog_enabled = false; fog_color = Color(0.5, 0.5, 0.5); @@ -1236,7 +1205,7 @@ Environment::Environment() : Environment::~Environment() { - VS::get_singleton()->free(environment); + RS::get_singleton()->free(environment); } ////////////////////// @@ -1244,7 +1213,7 @@ Environment::~Environment() { void CameraEffects::set_dof_blur_far_enabled(bool p_enable) { dof_blur_far_enabled = p_enable; - VS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); + RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); } bool CameraEffects::is_dof_blur_far_enabled() const { @@ -1255,7 +1224,7 @@ bool CameraEffects::is_dof_blur_far_enabled() const { void CameraEffects::set_dof_blur_far_distance(float p_distance) { dof_blur_far_distance = p_distance; - VS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); + RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); } float CameraEffects::get_dof_blur_far_distance() const { @@ -1265,7 +1234,7 @@ float CameraEffects::get_dof_blur_far_distance() const { void CameraEffects::set_dof_blur_far_transition(float p_distance) { dof_blur_far_transition = p_distance; - VS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); + RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); } float CameraEffects::get_dof_blur_far_transition() const { @@ -1275,7 +1244,7 @@ float CameraEffects::get_dof_blur_far_transition() const { void CameraEffects::set_dof_blur_near_enabled(bool p_enable) { dof_blur_near_enabled = p_enable; - VS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); + RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); _change_notify(); } @@ -1287,7 +1256,7 @@ bool CameraEffects::is_dof_blur_near_enabled() const { void CameraEffects::set_dof_blur_near_distance(float p_distance) { dof_blur_near_distance = p_distance; - VS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); + RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); } float CameraEffects::get_dof_blur_near_distance() const { @@ -1298,7 +1267,7 @@ float CameraEffects::get_dof_blur_near_distance() const { void CameraEffects::set_dof_blur_near_transition(float p_distance) { dof_blur_near_transition = p_distance; - VS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); + RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); } float CameraEffects::get_dof_blur_near_transition() const { @@ -1309,7 +1278,7 @@ float CameraEffects::get_dof_blur_near_transition() const { void CameraEffects::set_dof_blur_amount(float p_amount) { dof_blur_amount = p_amount; - VS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); + RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); } float CameraEffects::get_dof_blur_amount() const { @@ -1318,7 +1287,7 @@ float CameraEffects::get_dof_blur_amount() const { void CameraEffects::set_override_exposure_enabled(bool p_enabled) { override_exposure_enabled = p_enabled; - VS::get_singleton()->camera_effects_set_custom_exposure(camera_effects, override_exposure_enabled, override_exposure); + RS::get_singleton()->camera_effects_set_custom_exposure(camera_effects, override_exposure_enabled, override_exposure); } bool CameraEffects::is_override_exposure_enabled() const { @@ -1327,7 +1296,7 @@ bool CameraEffects::is_override_exposure_enabled() const { void CameraEffects::set_override_exposure(float p_exposure) { override_exposure = p_exposure; - VS::get_singleton()->camera_effects_set_custom_exposure(camera_effects, override_exposure_enabled, override_exposure); + RS::get_singleton()->camera_effects_set_custom_exposure(camera_effects, override_exposure_enabled, override_exposure); } float CameraEffects::get_override_exposure() const { @@ -1382,7 +1351,7 @@ void CameraEffects::_bind_methods() { CameraEffects::CameraEffects() { - camera_effects = VS::get_singleton()->camera_effects_create(); + camera_effects = RS::get_singleton()->camera_effects_create(); dof_blur_far_enabled = false; dof_blur_far_distance = 10; @@ -1400,5 +1369,5 @@ CameraEffects::CameraEffects() { CameraEffects::~CameraEffects() { - VS::get_singleton()->free(camera_effects); + RS::get_singleton()->free(camera_effects); } diff --git a/scene/resources/environment.h b/scene/resources/environment.h index f9fe26f792..02434bc592 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -34,7 +34,7 @@ #include "core/resource.h" #include "scene/resources/sky.h" #include "scene/resources/texture.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" class Environment : public Resource { @@ -125,7 +125,6 @@ private: float ssr_fade_in; float ssr_fade_out; float ssr_depth_tolerance; - bool ssr_roughness; bool ssao_enabled; float ssao_radius; @@ -146,7 +145,6 @@ private: float glow_hdr_bleed_threshold; float glow_hdr_bleed_scale; float glow_hdr_luminance_cap; - bool glow_bicubic_upscale; bool fog_enabled; Color fog_color; @@ -258,9 +256,6 @@ public: void set_ssr_depth_tolerance(float p_depth_tolerance); float get_ssr_depth_tolerance() const; - void set_ssr_rough(bool p_enable); - bool is_ssr_rough() const; - void set_ssao_enabled(bool p_enable); bool is_ssao_enabled() const; @@ -318,9 +313,6 @@ public: void set_glow_hdr_bleed_scale(float p_scale); float get_glow_hdr_bleed_scale() const; - void set_glow_bicubic_upscale(bool p_enable); - bool is_glow_bicubic_upscale_enabled() const; - void set_fog_enabled(bool p_enabled); bool is_fog_enabled() const; diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 1f5e4b647a..267816f267 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -128,7 +128,7 @@ Vector<int> BitmapFont::_get_chars() const { Vector<int> chars; - const CharType *key = NULL; + const CharType *key = nullptr; while ((key = char_map.next(key))) { @@ -382,7 +382,7 @@ Vector<CharType> BitmapFont::get_char_keys() const { Vector<CharType> chars; chars.resize(char_map.size()); - const CharType *ct = NULL; + const CharType *ct = nullptr; int count = 0; while ((ct = char_map.next(ct))) { @@ -528,7 +528,7 @@ Size2 Font::get_wordwrap_string_size(const String &p_string, float p_width) cons void BitmapFont::set_fallback(const Ref<BitmapFont> &p_fallback) { - for (Ref<BitmapFont> fallback_child = p_fallback; fallback_child != NULL; fallback_child = fallback_child->get_fallback()) { + for (Ref<BitmapFont> fallback_child = p_fallback; fallback_child != nullptr; fallback_child = fallback_child->get_fallback()) { ERR_FAIL_COND_MSG(fallback_child == this, "Can't set as fallback one of its parents to prevent crashes due to recursive loop."); } @@ -556,7 +556,7 @@ float BitmapFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_c cpos.x += c->h_align; cpos.y -= ascent; cpos.y += c->v_align; - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size), textures[c->texture_idx]->get_rid(), c->rect, p_modulate, false, RID(), RID(), Color(1, 1, 1, 1), false); + RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size), textures[c->texture_idx]->get_rid(), c->rect, p_modulate, false, RID(), RID(), Color(1, 1, 1, 1), false); } return get_char_size(p_char, p_next).width; @@ -646,7 +646,7 @@ BitmapFont::~BitmapFont() { //////////// -RES ResourceFormatLoaderBMFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) { +RES ResourceFormatLoaderBMFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { if (r_error) *r_error = ERR_FILE_CANT_OPEN; diff --git a/scene/resources/font.h b/scene/resources/font.h index 076532f390..c233344529 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -200,7 +200,7 @@ public: class ResourceFormatLoaderBMFont : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/scene/resources/height_map_shape.cpp b/scene/resources/height_map_shape_3d.cpp index fa45ddcabb..33b6063299 100644 --- a/scene/resources/height_map_shape.cpp +++ b/scene/resources/height_map_shape_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* height_map_shape.cpp */ +/* height_map_shape_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,10 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "height_map_shape.h" -#include "servers/physics_server.h" +#include "height_map_shape_3d.h" +#include "servers/physics_server_3d.h" -Vector<Vector3> HeightMapShape::get_debug_mesh_lines() { +Vector<Vector3> HeightMapShape3D::get_debug_mesh_lines() { Vector<Vector3> points; if ((map_width != 0) && (map_depth != 0)) { @@ -76,11 +76,11 @@ Vector<Vector3> HeightMapShape::get_debug_mesh_lines() { return points; } -real_t HeightMapShape::get_enclosing_radius() const { +real_t HeightMapShape3D::get_enclosing_radius() const { return Vector3(real_t(map_width), max_height - min_height, real_t(map_depth)).length(); } -void HeightMapShape::_update_shape() { +void HeightMapShape3D::_update_shape() { Dictionary d; d["width"] = map_width; @@ -88,11 +88,11 @@ void HeightMapShape::_update_shape() { d["heights"] = map_data; d["min_height"] = min_height; d["max_height"] = max_height; - PhysicsServer::get_singleton()->shape_set_data(get_shape(), d); - Shape::_update_shape(); + PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), d); + Shape3D::_update_shape(); } -void HeightMapShape::set_map_width(int p_new) { +void HeightMapShape3D::set_map_width(int p_new) { if (p_new < 1) { // ignore } else if (map_width != p_new) { @@ -114,11 +114,11 @@ void HeightMapShape::set_map_width(int p_new) { } } -int HeightMapShape::get_map_width() const { +int HeightMapShape3D::get_map_width() const { return map_width; } -void HeightMapShape::set_map_depth(int p_new) { +void HeightMapShape3D::set_map_depth(int p_new) { if (p_new < 1) { // ignore } else if (map_depth != p_new) { @@ -140,11 +140,11 @@ void HeightMapShape::set_map_depth(int p_new) { } } -int HeightMapShape::get_map_depth() const { +int HeightMapShape3D::get_map_depth() const { return map_depth; } -void HeightMapShape::set_map_data(PackedFloat32Array p_new) { +void HeightMapShape3D::set_map_data(PackedFloat32Array p_new) { int size = (map_width * map_depth); if (p_new.size() != size) { // fail @@ -174,25 +174,25 @@ void HeightMapShape::set_map_data(PackedFloat32Array p_new) { _change_notify("map_data"); } -PackedFloat32Array HeightMapShape::get_map_data() const { +PackedFloat32Array HeightMapShape3D::get_map_data() const { return map_data; } -void HeightMapShape::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_map_width", "width"), &HeightMapShape::set_map_width); - ClassDB::bind_method(D_METHOD("get_map_width"), &HeightMapShape::get_map_width); - ClassDB::bind_method(D_METHOD("set_map_depth", "height"), &HeightMapShape::set_map_depth); - ClassDB::bind_method(D_METHOD("get_map_depth"), &HeightMapShape::get_map_depth); - ClassDB::bind_method(D_METHOD("set_map_data", "data"), &HeightMapShape::set_map_data); - ClassDB::bind_method(D_METHOD("get_map_data"), &HeightMapShape::get_map_data); +void HeightMapShape3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_map_width", "width"), &HeightMapShape3D::set_map_width); + ClassDB::bind_method(D_METHOD("get_map_width"), &HeightMapShape3D::get_map_width); + ClassDB::bind_method(D_METHOD("set_map_depth", "height"), &HeightMapShape3D::set_map_depth); + ClassDB::bind_method(D_METHOD("get_map_depth"), &HeightMapShape3D::get_map_depth); + ClassDB::bind_method(D_METHOD("set_map_data", "data"), &HeightMapShape3D::set_map_data); + ClassDB::bind_method(D_METHOD("get_map_data"), &HeightMapShape3D::get_map_data); ADD_PROPERTY(PropertyInfo(Variant::INT, "map_width", PROPERTY_HINT_RANGE, "1,4096,1"), "set_map_width", "get_map_width"); ADD_PROPERTY(PropertyInfo(Variant::INT, "map_depth", PROPERTY_HINT_RANGE, "1,4096,1"), "set_map_depth", "get_map_depth"); ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT32_ARRAY, "map_data"), "set_map_data", "get_map_data"); } -HeightMapShape::HeightMapShape() : - Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_HEIGHTMAP)) { +HeightMapShape3D::HeightMapShape3D() : + Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_HEIGHTMAP)) { map_width = 2; map_depth = 2; diff --git a/scene/resources/height_map_shape.h b/scene/resources/height_map_shape_3d.h index b8204f6c98..291d41a34e 100644 --- a/scene/resources/height_map_shape.h +++ b/scene/resources/height_map_shape_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* height_map_shape.h */ +/* height_map_shape_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,10 +31,10 @@ #ifndef HEIGHT_MAP_SHAPE_H #define HEIGHT_MAP_SHAPE_H -#include "scene/resources/shape.h" +#include "scene/resources/shape_3d.h" -class HeightMapShape : public Shape { - GDCLASS(HeightMapShape, Shape); +class HeightMapShape3D : public Shape3D { + GDCLASS(HeightMapShape3D, Shape3D); int map_width; int map_depth; @@ -57,7 +57,7 @@ public: virtual Vector<Vector3> get_debug_mesh_lines(); virtual real_t get_enclosing_radius() const; - HeightMapShape(); + HeightMapShape3D(); }; #endif /* !HEIGHT_MAP_SHAPE_H */ diff --git a/scene/resources/line_shape_2d.cpp b/scene/resources/line_shape_2d.cpp index 3b30b4528a..a1c1b2f9f4 100644 --- a/scene/resources/line_shape_2d.cpp +++ b/scene/resources/line_shape_2d.cpp @@ -30,8 +30,8 @@ #include "line_shape_2d.h" -#include "servers/physics_2d_server.h" -#include "servers/visual_server.h" +#include "servers/physics_server_2d.h" +#include "servers/rendering_server.h" bool LineShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { @@ -52,7 +52,7 @@ void LineShape2D::_update_shape() { Array arr; arr.push_back(normal); arr.push_back(d); - Physics2DServer::get_singleton()->shape_set_data(get_rid(), arr); + PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), arr); emit_changed(); } @@ -82,9 +82,9 @@ void LineShape2D::draw(const RID &p_to_rid, const Color &p_color) { Vector2 point = get_d() * get_normal(); Vector2 l1[2] = { point - get_normal().tangent() * 100, point + get_normal().tangent() * 100 }; - VS::get_singleton()->canvas_item_add_line(p_to_rid, l1[0], l1[1], p_color, 3); + RS::get_singleton()->canvas_item_add_line(p_to_rid, l1[0], l1[1], p_color, 3); Vector2 l2[2] = { point, point + get_normal() * 30 }; - VS::get_singleton()->canvas_item_add_line(p_to_rid, l2[0], l2[1], p_color, 3); + RS::get_singleton()->canvas_item_add_line(p_to_rid, l2[0], l2[1], p_color, 3); } Rect2 LineShape2D::get_rect() const { @@ -117,7 +117,7 @@ void LineShape2D::_bind_methods() { } LineShape2D::LineShape2D() : - Shape2D(Physics2DServer::get_singleton()->line_shape_create()) { + Shape2D(PhysicsServer2D::get_singleton()->line_shape_create()) { normal = Vector2(0, 1); d = 0; diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index d387a39dbe..fd8cff7cd0 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -40,7 +40,7 @@ void Material::set_next_pass(const Ref<Material> &p_pass) { - for (Ref<Material> pass_child = p_pass; pass_child != NULL; pass_child = pass_child->get_next_pass()) { + for (Ref<Material> pass_child = p_pass; pass_child != nullptr; pass_child = pass_child->get_next_pass()) { ERR_FAIL_COND_MSG(pass_child == this, "Can't set as next_pass one of its parents to prevent crashes due to recursive loop."); } @@ -51,7 +51,7 @@ void Material::set_next_pass(const Ref<Material> &p_pass) { RID next_pass_rid; if (next_pass.is_valid()) next_pass_rid = next_pass->get_rid(); - VS::get_singleton()->material_set_next_pass(material, next_pass_rid); + RS::get_singleton()->material_set_next_pass(material, next_pass_rid); } Ref<Material> Material::get_next_pass() const { @@ -64,7 +64,7 @@ void Material::set_render_priority(int p_priority) { ERR_FAIL_COND(p_priority < RENDER_PRIORITY_MIN); ERR_FAIL_COND(p_priority > RENDER_PRIORITY_MAX); render_priority = p_priority; - VS::get_singleton()->material_set_render_priority(material, p_priority); + RS::get_singleton()->material_set_render_priority(material, p_priority); } int Material::get_render_priority() const { @@ -100,13 +100,13 @@ void Material::_bind_methods() { Material::Material() { - material = VisualServer::get_singleton()->material_create(); + material = RenderingServer::get_singleton()->material_create(); render_priority = 0; } Material::~Material() { - VisualServer::get_singleton()->free(material); + RenderingServer::get_singleton()->free(material); } /////////////////////////////////// @@ -126,7 +126,7 @@ bool ShaderMaterial::_set(const StringName &p_name, const Variant &p_value) { } } if (pr) { - VisualServer::get_singleton()->material_set_param(_get_material(), pr, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), pr, p_value); return true; } } @@ -150,7 +150,7 @@ bool ShaderMaterial::_get(const StringName &p_name, Variant &r_ret) const { } if (pr) { - r_ret = VisualServer::get_singleton()->material_get_param(_get_material(), pr); + r_ret = RenderingServer::get_singleton()->material_get_param(_get_material(), pr); return true; } } @@ -171,7 +171,7 @@ bool ShaderMaterial::property_can_revert(const String &p_name) { StringName pr = shader->remap_param(p_name); if (pr) { - Variant default_value = VisualServer::get_singleton()->shader_get_param_default(shader->get_rid(), pr); + Variant default_value = RenderingServer::get_singleton()->shader_get_param_default(shader->get_rid(), pr); Variant current_value; _get(p_name, current_value); return default_value.get_type() != Variant::NIL && default_value != current_value; @@ -185,7 +185,7 @@ Variant ShaderMaterial::property_get_revert(const String &p_name) { if (shader.is_valid()) { StringName pr = shader->remap_param(p_name); if (pr) { - r_ret = VisualServer::get_singleton()->shader_get_param_default(shader->get_rid(), pr); + r_ret = RenderingServer::get_singleton()->shader_get_param_default(shader->get_rid(), pr); } } return r_ret; @@ -211,7 +211,7 @@ void ShaderMaterial::set_shader(const Ref<Shader> &p_shader) { } } - VS::get_singleton()->material_set_shader(_get_material(), rid); + RS::get_singleton()->material_set_shader(_get_material(), rid); _change_notify(); //properties for shader exposed emit_changed(); } @@ -223,12 +223,12 @@ Ref<Shader> ShaderMaterial::get_shader() const { void ShaderMaterial::set_shader_param(const StringName &p_param, const Variant &p_value) { - VS::get_singleton()->material_set_param(_get_material(), p_param, p_value); + RS::get_singleton()->material_set_param(_get_material(), p_param, p_value); } Variant ShaderMaterial::get_shader_param(const StringName &p_param) const { - return VS::get_singleton()->material_get_param(_get_material(), p_param); + return RS::get_singleton()->material_get_param(_get_material(), p_param); } void ShaderMaterial::_shader_changed() { @@ -290,9 +290,9 @@ ShaderMaterial::~ShaderMaterial() { ///////////////////////////////// Mutex BaseMaterial3D::material_mutex; -SelfList<BaseMaterial3D>::List *BaseMaterial3D::dirty_materials = NULL; +SelfList<BaseMaterial3D>::List *BaseMaterial3D::dirty_materials = nullptr; Map<BaseMaterial3D::MaterialKey, BaseMaterial3D::ShaderData> BaseMaterial3D::shader_map; -BaseMaterial3D::ShaderNames *BaseMaterial3D::shader_names = NULL; +BaseMaterial3D::ShaderNames *BaseMaterial3D::shader_names = nullptr; void BaseMaterial3D::init_shaders() { @@ -314,7 +314,7 @@ void BaseMaterial3D::init_shaders() { shader_names->anisotropy = "anisotropy_ratio"; shader_names->heightmap_scale = "heightmap_scale"; shader_names->subsurface_scattering_strength = "subsurface_scattering_strength"; - shader_names->transmission = "transmission"; + shader_names->backlight = "backlight"; shader_names->refraction = "refraction"; shader_names->point_size = "point_size"; shader_names->uv1_scale = "uv1_scale"; @@ -347,6 +347,11 @@ void BaseMaterial3D::init_shaders() { shader_names->refraction_texture_channel = "refraction_texture_channel"; shader_names->alpha_scissor_threshold = "alpha_scissor_threshold"; + shader_names->transmittance_color = "transmittance_color"; + shader_names->transmittance_curve = "transmittance_curve"; + shader_names->transmittance_depth = "transmittance_depth"; + shader_names->transmittance_boost = "transmittance_boost"; + shader_names->texture_names[TEXTURE_ALBEDO] = "texture_albedo"; shader_names->texture_names[TEXTURE_METALLIC] = "texture_metallic"; shader_names->texture_names[TEXTURE_ROUGHNESS] = "texture_roughness"; @@ -358,7 +363,8 @@ void BaseMaterial3D::init_shaders() { shader_names->texture_names[TEXTURE_AMBIENT_OCCLUSION] = "texture_ambient_occlusion"; shader_names->texture_names[TEXTURE_HEIGHTMAP] = "texture_heightmap"; shader_names->texture_names[TEXTURE_SUBSURFACE_SCATTERING] = "texture_subsurface_scattering"; - shader_names->texture_names[TEXTURE_TRANSMISSION] = "texture_transmission"; + shader_names->texture_names[TEXTURE_SUBSURFACE_TRANSMITTANCE] = "texture_subsurface_transmittance"; + shader_names->texture_names[TEXTURE_BACKLIGHT] = "texture_backlight"; shader_names->texture_names[TEXTURE_REFRACTION] = "texture_refraction"; shader_names->texture_names[TEXTURE_DETAIL_MASK] = "texture_detail_mask"; shader_names->texture_names[TEXTURE_DETAIL_ALBEDO] = "texture_detail_albedo"; @@ -375,7 +381,7 @@ void BaseMaterial3D::finish_shaders() { } memdelete(dirty_materials); - dirty_materials = NULL; + dirty_materials = nullptr; memdelete(shader_names); } @@ -385,14 +391,14 @@ void BaseMaterial3D::_update_shader() { dirty_materials->remove(&element); MaterialKey mk = _compute_key(); - if (mk.key == current_key.key) + if (mk == current_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); + RS::get_singleton()->free(shader_map[current_key].shader); shader_map.erase(current_key); } } @@ -401,7 +407,7 @@ void BaseMaterial3D::_update_shader() { if (shader_map.has(mk)) { - VS::get_singleton()->material_set_shader(_get_material(), shader_map[mk].shader); + RS::get_singleton()->material_set_shader(_get_material(), shader_map[mk].shader); shader_map[mk].users++; return; } @@ -467,6 +473,9 @@ void BaseMaterial3D::_update_shader() { case SPECULAR_TOON: code += ",specular_toon"; break; case SPECULAR_DISABLED: code += ",specular_disabled"; break; } + if (features[FEATURE_SUBSURFACE_SCATTERING] && flags[FLAG_SUBSURFACE_MODE_SKIN]) { + code += ",sss_mode_skin"; + } if (shading_mode == SHADING_MODE_UNSHADED) { code += ",unshaded"; @@ -586,16 +595,25 @@ void BaseMaterial3D::_update_shader() { code += "uniform sampler2D texture_detail_mask : hint_white," + texfilter_str + ";\n"; } - if (features[FEATURE_SUBSURACE_SCATTERING]) { + if (features[FEATURE_SUBSURFACE_SCATTERING]) { code += "uniform float subsurface_scattering_strength : hint_range(0,1);\n"; code += "uniform sampler2D texture_subsurface_scattering : hint_white," + texfilter_str + ";\n"; } - if (features[FEATURE_TRANSMISSION]) { + if (features[FEATURE_SUBSURFACE_TRANSMITTANCE]) { + + code += "uniform vec4 transmittance_color : hint_color;\n"; + code += "uniform float transmittance_depth;\n"; + code += "uniform sampler2D texture_subsurface_transmittance : hint_white," + texfilter_str + ";\n"; + code += "uniform float transmittance_curve;\n"; + code += "uniform float transmittance_boost;\n"; + } + + if (features[FEATURE_BACKLIGHT]) { - code += "uniform vec4 transmission : hint_color;\n"; - code += "uniform sampler2D texture_transmission : hint_black," + texfilter_str + ";\n"; + code += "uniform vec4 backlight : hint_color;\n"; + code += "uniform sampler2D texture_backlight : hint_black," + texfilter_str + ";\n"; } if (features[FEATURE_HEIGHT_MAPPING]) { @@ -773,7 +791,7 @@ void BaseMaterial3D::_update_shader() { code += "\tvec2 base_uv2 = UV2;\n"; } - if (!VisualServer::get_singleton()->is_low_end() && features[FEATURE_HEIGHT_MAPPING] && !flags[FLAG_UV1_USE_TRIPLANAR]) { //heightmap not supported with triplanar + if (!RenderingServer::get_singleton()->is_low_end() && features[FEATURE_HEIGHT_MAPPING] && !flags[FLAG_UV1_USE_TRIPLANAR]) { //heightmap not supported with triplanar code += "\t{\n"; code += "\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*heightmap_flip.x,-BINORMAL*heightmap_flip.y,NORMAL));\n"; // binormal is negative due to mikktspace, flip 'unflips' it ;-) @@ -953,7 +971,7 @@ void BaseMaterial3D::_update_shader() { if (distance_fade != DISTANCE_FADE_DISABLED) { if ((distance_fade == DISTANCE_FADE_OBJECT_DITHER || distance_fade == DISTANCE_FADE_PIXEL_DITHER)) { - if (!VisualServer::get_singleton()->is_low_end()) { + if (!RenderingServer::get_singleton()->is_low_end()) { code += "\t{\n"; if (distance_fade == DISTANCE_FADE_OBJECT_DITHER) { code += "\t\tfloat fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);\n"; @@ -1048,7 +1066,7 @@ void BaseMaterial3D::_update_shader() { code += "\tAO_LIGHT_AFFECT = ao_light_affect;\n"; } - if (features[FEATURE_SUBSURACE_SCATTERING]) { + if (features[FEATURE_SUBSURFACE_SCATTERING]) { if (flags[FLAG_UV1_USE_TRIPLANAR]) { code += "\tfloat sss_tex = triplanar_texture(texture_subsurface_scattering,uv1_power_normal,uv1_triplanar_pos).r;\n"; @@ -1058,13 +1076,27 @@ void BaseMaterial3D::_update_shader() { code += "\tSSS_STRENGTH=subsurface_scattering_strength*sss_tex;\n"; } - if (features[FEATURE_TRANSMISSION]) { + if (features[FEATURE_SUBSURFACE_TRANSMITTANCE]) { + + if (flags[FLAG_UV1_USE_TRIPLANAR]) { + code += "\tvec4 trans_color_tex = triplanar_texture(texture_subsurface_transmittance,uv1_power_normal,uv1_triplanar_pos);\n"; + } else { + code += "\tvec4 trans_color_tex = texture(texture_subsurface_transmittance,base_uv);\n"; + } + code += "\tSSS_TRANSMITTANCE_COLOR=transmittance_color*trans_color_tex;\n"; + + code += "\tSSS_TRANSMITTANCE_DEPTH=transmittance_depth;\n"; + code += "\tSSS_TRANSMITTANCE_CURVE=transmittance_curve;\n"; + code += "\tSSS_TRANSMITTANCE_BOOST=transmittance_boost;\n"; + } + + if (features[FEATURE_BACKLIGHT]) { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec3 transmission_tex = triplanar_texture(texture_transmission,uv1_power_normal,uv1_triplanar_pos).rgb;\n"; + code += "\tvec3 backlight_tex = triplanar_texture(texture_backlight,uv1_power_normal,uv1_triplanar_pos).rgb;\n"; } else { - code += "\tvec3 transmission_tex = texture(texture_transmission,base_uv).rgb;\n"; + code += "\tvec3 backlight_tex = texture(texture_backlight,base_uv).rgb;\n"; } - code += "\tTRANSMISSION = (transmission.rgb+transmission_tex);\n"; + code += "\tBACKLIGHT = (backlight.rgb+backlight_tex);\n"; } if (features[FEATURE_DETAIL]) { @@ -1112,14 +1144,14 @@ void BaseMaterial3D::_update_shader() { code += "}\n"; ShaderData shader_data; - shader_data.shader = VS::get_singleton()->shader_create(); + shader_data.shader = RS::get_singleton()->shader_create(); shader_data.users = 1; - VS::get_singleton()->shader_set_code(shader_data.shader, code); + RS::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); + RS::get_singleton()->material_set_shader(_get_material(), shader_data.shader); } void BaseMaterial3D::flush_changes() { @@ -1151,7 +1183,7 @@ void BaseMaterial3D::set_albedo(const Color &p_albedo) { albedo = p_albedo; - VS::get_singleton()->material_set_param(_get_material(), shader_names->albedo, p_albedo); + RS::get_singleton()->material_set_param(_get_material(), shader_names->albedo, p_albedo); } Color BaseMaterial3D::get_albedo() const { @@ -1162,7 +1194,7 @@ Color BaseMaterial3D::get_albedo() const { void BaseMaterial3D::set_specular(float p_specular) { specular = p_specular; - VS::get_singleton()->material_set_param(_get_material(), shader_names->specular, p_specular); + RS::get_singleton()->material_set_param(_get_material(), shader_names->specular, p_specular); } float BaseMaterial3D::get_specular() const { @@ -1173,7 +1205,7 @@ float BaseMaterial3D::get_specular() const { void BaseMaterial3D::set_roughness(float p_roughness) { roughness = p_roughness; - VS::get_singleton()->material_set_param(_get_material(), shader_names->roughness, p_roughness); + RS::get_singleton()->material_set_param(_get_material(), shader_names->roughness, p_roughness); } float BaseMaterial3D::get_roughness() const { @@ -1184,7 +1216,7 @@ float BaseMaterial3D::get_roughness() const { void BaseMaterial3D::set_metallic(float p_metallic) { metallic = p_metallic; - VS::get_singleton()->material_set_param(_get_material(), shader_names->metallic, p_metallic); + RS::get_singleton()->material_set_param(_get_material(), shader_names->metallic, p_metallic); } float BaseMaterial3D::get_metallic() const { @@ -1195,7 +1227,7 @@ float BaseMaterial3D::get_metallic() const { void BaseMaterial3D::set_emission(const Color &p_emission) { emission = p_emission; - VS::get_singleton()->material_set_param(_get_material(), shader_names->emission, p_emission); + RS::get_singleton()->material_set_param(_get_material(), shader_names->emission, p_emission); } Color BaseMaterial3D::get_emission() const { @@ -1205,7 +1237,7 @@ Color BaseMaterial3D::get_emission() const { void BaseMaterial3D::set_emission_energy(float p_emission_energy) { emission_energy = p_emission_energy; - VS::get_singleton()->material_set_param(_get_material(), shader_names->emission_energy, p_emission_energy); + RS::get_singleton()->material_set_param(_get_material(), shader_names->emission_energy, p_emission_energy); } float BaseMaterial3D::get_emission_energy() const { @@ -1215,7 +1247,7 @@ float BaseMaterial3D::get_emission_energy() const { void BaseMaterial3D::set_normal_scale(float p_normal_scale) { normal_scale = p_normal_scale; - VS::get_singleton()->material_set_param(_get_material(), shader_names->normal_scale, p_normal_scale); + RS::get_singleton()->material_set_param(_get_material(), shader_names->normal_scale, p_normal_scale); } float BaseMaterial3D::get_normal_scale() const { @@ -1225,7 +1257,7 @@ float BaseMaterial3D::get_normal_scale() const { void BaseMaterial3D::set_rim(float p_rim) { rim = p_rim; - VS::get_singleton()->material_set_param(_get_material(), shader_names->rim, p_rim); + RS::get_singleton()->material_set_param(_get_material(), shader_names->rim, p_rim); } float BaseMaterial3D::get_rim() const { @@ -1235,7 +1267,7 @@ float BaseMaterial3D::get_rim() const { void BaseMaterial3D::set_rim_tint(float p_rim_tint) { rim_tint = p_rim_tint; - VS::get_singleton()->material_set_param(_get_material(), shader_names->rim_tint, p_rim_tint); + RS::get_singleton()->material_set_param(_get_material(), shader_names->rim_tint, p_rim_tint); } float BaseMaterial3D::get_rim_tint() const { @@ -1245,7 +1277,7 @@ float BaseMaterial3D::get_rim_tint() const { void BaseMaterial3D::set_ao_light_affect(float p_ao_light_affect) { ao_light_affect = p_ao_light_affect; - VS::get_singleton()->material_set_param(_get_material(), shader_names->ao_light_affect, p_ao_light_affect); + RS::get_singleton()->material_set_param(_get_material(), shader_names->ao_light_affect, p_ao_light_affect); } float BaseMaterial3D::get_ao_light_affect() const { @@ -1255,7 +1287,7 @@ float BaseMaterial3D::get_ao_light_affect() const { void BaseMaterial3D::set_clearcoat(float p_clearcoat) { clearcoat = p_clearcoat; - VS::get_singleton()->material_set_param(_get_material(), shader_names->clearcoat, p_clearcoat); + RS::get_singleton()->material_set_param(_get_material(), shader_names->clearcoat, p_clearcoat); } float BaseMaterial3D::get_clearcoat() const { @@ -1266,7 +1298,7 @@ float BaseMaterial3D::get_clearcoat() const { void BaseMaterial3D::set_clearcoat_gloss(float p_clearcoat_gloss) { clearcoat_gloss = p_clearcoat_gloss; - VS::get_singleton()->material_set_param(_get_material(), shader_names->clearcoat_gloss, p_clearcoat_gloss); + RS::get_singleton()->material_set_param(_get_material(), shader_names->clearcoat_gloss, p_clearcoat_gloss); } float BaseMaterial3D::get_clearcoat_gloss() const { @@ -1277,7 +1309,7 @@ float BaseMaterial3D::get_clearcoat_gloss() const { void BaseMaterial3D::set_anisotropy(float p_anisotropy) { anisotropy = p_anisotropy; - VS::get_singleton()->material_set_param(_get_material(), shader_names->anisotropy, p_anisotropy); + RS::get_singleton()->material_set_param(_get_material(), shader_names->anisotropy, p_anisotropy); } float BaseMaterial3D::get_anisotropy() const { @@ -1287,7 +1319,7 @@ float BaseMaterial3D::get_anisotropy() const { void BaseMaterial3D::set_heightmap_scale(float p_heightmap_scale) { heightmap_scale = p_heightmap_scale; - VS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_scale, p_heightmap_scale); + RS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_scale, p_heightmap_scale); } float BaseMaterial3D::get_heightmap_scale() const { @@ -1298,7 +1330,7 @@ float BaseMaterial3D::get_heightmap_scale() const { void BaseMaterial3D::set_subsurface_scattering_strength(float p_subsurface_scattering_strength) { subsurface_scattering_strength = p_subsurface_scattering_strength; - VS::get_singleton()->material_set_param(_get_material(), shader_names->subsurface_scattering_strength, subsurface_scattering_strength); + RS::get_singleton()->material_set_param(_get_material(), shader_names->subsurface_scattering_strength, subsurface_scattering_strength); } float BaseMaterial3D::get_subsurface_scattering_strength() const { @@ -1306,21 +1338,54 @@ float BaseMaterial3D::get_subsurface_scattering_strength() const { return subsurface_scattering_strength; } -void BaseMaterial3D::set_transmission(const Color &p_transmission) { +void BaseMaterial3D::set_transmittance_color(const Color &p_color) { + transmittance_color = p_color; + RS::get_singleton()->material_set_param(_get_material(), shader_names->transmittance_color, p_color); +} + +Color BaseMaterial3D::get_transmittance_color() const { + return transmittance_color; +} + +void BaseMaterial3D::set_transmittance_depth(float p_depth) { + transmittance_depth = p_depth; + RS::get_singleton()->material_set_param(_get_material(), shader_names->transmittance_depth, p_depth); +} +float BaseMaterial3D::get_transmittance_depth() const { + return transmittance_depth; +} + +void BaseMaterial3D::set_transmittance_curve(float p_curve) { + transmittance_curve = p_curve; + RS::get_singleton()->material_set_param(_get_material(), shader_names->transmittance_curve, p_curve); +} +float BaseMaterial3D::get_transmittance_curve() const { + return transmittance_curve; +} - transmission = p_transmission; - VS::get_singleton()->material_set_param(_get_material(), shader_names->transmission, transmission); +void BaseMaterial3D::set_transmittance_boost(float p_boost) { + transmittance_boost = p_boost; + RS::get_singleton()->material_set_param(_get_material(), shader_names->transmittance_boost, p_boost); +} +float BaseMaterial3D::get_transmittance_boost() const { + return transmittance_boost; } -Color BaseMaterial3D::get_transmission() const { +void BaseMaterial3D::set_backlight(const Color &p_backlight) { - return transmission; + backlight = p_backlight; + RS::get_singleton()->material_set_param(_get_material(), shader_names->backlight, backlight); +} + +Color BaseMaterial3D::get_backlight() const { + + return backlight; } void BaseMaterial3D::set_refraction(float p_refraction) { refraction = p_refraction; - VS::get_singleton()->material_set_param(_get_material(), shader_names->refraction, refraction); + RS::get_singleton()->material_set_param(_get_material(), shader_names->refraction, refraction); } float BaseMaterial3D::get_refraction() const { @@ -1454,7 +1519,7 @@ void BaseMaterial3D::set_flag(Flags p_flag, bool p_enabled) { return; flags[p_flag] = p_enabled; - if ((p_flag == FLAG_USE_SHADOW_TO_OPACITY) || (p_flag == FLAG_USE_TEXTURE_REPEAT)) { + if (p_flag == FLAG_USE_SHADOW_TO_OPACITY || p_flag == FLAG_USE_TEXTURE_REPEAT || p_flag == FLAG_SUBSURFACE_MODE_SKIN) { _change_notify(); } _queue_shader_change(); @@ -1488,7 +1553,7 @@ void BaseMaterial3D::set_texture(TextureParam p_param, const Ref<Texture2D> &p_t ERR_FAIL_INDEX(p_param, TEXTURE_MAX); textures[p_param] = p_texture; RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); - VS::get_singleton()->material_set_param(_get_material(), shader_names->texture_names[p_param], rid); + RS::get_singleton()->material_set_param(_get_material(), shader_names->texture_names[p_param], rid); _change_notify(); _queue_shader_change(); } @@ -1537,8 +1602,8 @@ void BaseMaterial3D::_validate_property(PropertyInfo &property) const { _validate_feature("anisotropy", FEATURE_ANISOTROPY, property); _validate_feature("ao", FEATURE_AMBIENT_OCCLUSION, property); _validate_feature("heightmap", FEATURE_HEIGHT_MAPPING, property); - _validate_feature("subsurf_scatter", FEATURE_SUBSURACE_SCATTERING, property); - _validate_feature("transmission", FEATURE_TRANSMISSION, property); + _validate_feature("subsurf_scatter", FEATURE_SUBSURFACE_SCATTERING, property); + _validate_feature("backlight", FEATURE_BACKLIGHT, property); _validate_feature("refraction", FEATURE_REFRACTION, property); _validate_feature("detail", FEATURE_DETAIL, property); @@ -1572,6 +1637,10 @@ void BaseMaterial3D::_validate_property(PropertyInfo &property) const { property.usage = 0; } + if (flags[FLAG_SUBSURFACE_MODE_SKIN] && (property.name == "subsurf_scatter_transmittance_color" || property.name == "subsurf_scatter_transmittance_texture" || property.name == "subsurf_scatter_transmittance_curve")) { + property.usage = 0; + } + if (orm) { if (property.name == "shading_mode") { @@ -1628,7 +1697,11 @@ void BaseMaterial3D::_validate_property(PropertyInfo &property) const { property.usage = 0; } - if (property.name.begins_with("transmission")) { + if (property.name.begins_with("backlight")) { + property.usage = 0; + } + + if (property.name.begins_with("transmittance")) { property.usage = 0; } } @@ -1637,7 +1710,7 @@ void BaseMaterial3D::_validate_property(PropertyInfo &property) const { void BaseMaterial3D::set_point_size(float p_point_size) { point_size = p_point_size; - VS::get_singleton()->material_set_param(_get_material(), shader_names->point_size, p_point_size); + RS::get_singleton()->material_set_param(_get_material(), shader_names->point_size, p_point_size); } float BaseMaterial3D::get_point_size() const { @@ -1648,7 +1721,7 @@ float BaseMaterial3D::get_point_size() const { void BaseMaterial3D::set_uv1_scale(const Vector3 &p_scale) { uv1_scale = p_scale; - VS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_scale, p_scale); + RS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_scale, p_scale); } Vector3 BaseMaterial3D::get_uv1_scale() const { @@ -1659,7 +1732,7 @@ Vector3 BaseMaterial3D::get_uv1_scale() const { void BaseMaterial3D::set_uv1_offset(const Vector3 &p_offset) { uv1_offset = p_offset; - VS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_offset, p_offset); + RS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_offset, p_offset); } Vector3 BaseMaterial3D::get_uv1_offset() const { @@ -1669,7 +1742,7 @@ Vector3 BaseMaterial3D::get_uv1_offset() const { void BaseMaterial3D::set_uv1_triplanar_blend_sharpness(float p_sharpness) { uv1_triplanar_sharpness = p_sharpness; - VS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_blend_sharpness, p_sharpness); + RS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_blend_sharpness, p_sharpness); } float BaseMaterial3D::get_uv1_triplanar_blend_sharpness() const { @@ -1680,7 +1753,7 @@ float BaseMaterial3D::get_uv1_triplanar_blend_sharpness() const { void BaseMaterial3D::set_uv2_scale(const Vector3 &p_scale) { uv2_scale = p_scale; - VS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_scale, p_scale); + RS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_scale, p_scale); } Vector3 BaseMaterial3D::get_uv2_scale() const { @@ -1691,7 +1764,7 @@ Vector3 BaseMaterial3D::get_uv2_scale() const { void BaseMaterial3D::set_uv2_offset(const Vector3 &p_offset) { uv2_offset = p_offset; - VS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_offset, p_offset); + RS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_offset, p_offset); } Vector3 BaseMaterial3D::get_uv2_offset() const { @@ -1702,7 +1775,7 @@ Vector3 BaseMaterial3D::get_uv2_offset() const { void BaseMaterial3D::set_uv2_triplanar_blend_sharpness(float p_sharpness) { uv2_triplanar_sharpness = p_sharpness; - VS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_blend_sharpness, p_sharpness); + RS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_blend_sharpness, p_sharpness); } float BaseMaterial3D::get_uv2_triplanar_blend_sharpness() const { @@ -1725,7 +1798,7 @@ BaseMaterial3D::BillboardMode BaseMaterial3D::get_billboard_mode() const { void BaseMaterial3D::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); + RS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_h_frames, p_frames); } int BaseMaterial3D::get_particles_anim_h_frames() const { @@ -1735,7 +1808,7 @@ int BaseMaterial3D::get_particles_anim_h_frames() const { void BaseMaterial3D::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); + RS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_v_frames, p_frames); } int BaseMaterial3D::get_particles_anim_v_frames() const { @@ -1746,7 +1819,7 @@ int BaseMaterial3D::get_particles_anim_v_frames() const { void BaseMaterial3D::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); + RS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_loop, particles_anim_loop); } bool BaseMaterial3D::get_particles_anim_loop() const { @@ -1769,7 +1842,7 @@ bool BaseMaterial3D::is_heightmap_deep_parallax_enabled() const { void BaseMaterial3D::set_heightmap_deep_parallax_min_layers(int p_layer) { deep_parallax_min_layers = p_layer; - VS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_min_layers, p_layer); + RS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_min_layers, p_layer); } int BaseMaterial3D::get_heightmap_deep_parallax_min_layers() const { @@ -1779,7 +1852,7 @@ int BaseMaterial3D::get_heightmap_deep_parallax_min_layers() const { void BaseMaterial3D::set_heightmap_deep_parallax_max_layers(int p_layer) { deep_parallax_max_layers = p_layer; - VS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_max_layers, p_layer); + RS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_max_layers, p_layer); } int BaseMaterial3D::get_heightmap_deep_parallax_max_layers() const { @@ -1789,7 +1862,7 @@ int BaseMaterial3D::get_heightmap_deep_parallax_max_layers() const { void BaseMaterial3D::set_heightmap_deep_parallax_flip_tangent(bool p_flip) { heightmap_parallax_flip_tangent = p_flip; - VS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_flip, Vector2(heightmap_parallax_flip_tangent ? -1 : 1, heightmap_parallax_flip_binormal ? -1 : 1)); + RS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_flip, Vector2(heightmap_parallax_flip_tangent ? -1 : 1, heightmap_parallax_flip_binormal ? -1 : 1)); } bool BaseMaterial3D::get_heightmap_deep_parallax_flip_tangent() const { @@ -1800,7 +1873,7 @@ bool BaseMaterial3D::get_heightmap_deep_parallax_flip_tangent() const { void BaseMaterial3D::set_heightmap_deep_parallax_flip_binormal(bool p_flip) { heightmap_parallax_flip_binormal = p_flip; - VS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_flip, Vector2(heightmap_parallax_flip_tangent ? -1 : 1, heightmap_parallax_flip_binormal ? -1 : 1)); + RS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_flip, Vector2(heightmap_parallax_flip_tangent ? -1 : 1, heightmap_parallax_flip_binormal ? -1 : 1)); } bool BaseMaterial3D::get_heightmap_deep_parallax_flip_binormal() const { @@ -1820,7 +1893,7 @@ bool BaseMaterial3D::is_grow_enabled() const { void BaseMaterial3D::set_alpha_scissor_threshold(float p_threshold) { alpha_scissor_threshold = p_threshold; - VS::get_singleton()->material_set_param(_get_material(), shader_names->alpha_scissor_threshold, p_threshold); + RS::get_singleton()->material_set_param(_get_material(), shader_names->alpha_scissor_threshold, p_threshold); } float BaseMaterial3D::get_alpha_scissor_threshold() const { @@ -1830,7 +1903,7 @@ float BaseMaterial3D::get_alpha_scissor_threshold() const { void BaseMaterial3D::set_grow(float p_grow) { grow = p_grow; - VS::get_singleton()->material_set_param(_get_material(), shader_names->grow, p_grow); + RS::get_singleton()->material_set_param(_get_material(), shader_names->grow, p_grow); } float BaseMaterial3D::get_grow() const { @@ -1853,7 +1926,7 @@ static Plane _get_texture_mask(BaseMaterial3D::TextureChannel p_channel) { void BaseMaterial3D::set_metallic_texture_channel(TextureChannel p_channel) { ERR_FAIL_INDEX(p_channel, 5); metallic_texture_channel = p_channel; - VS::get_singleton()->material_set_param(_get_material(), shader_names->metallic_texture_channel, _get_texture_mask(p_channel)); + RS::get_singleton()->material_set_param(_get_material(), shader_names->metallic_texture_channel, _get_texture_mask(p_channel)); } BaseMaterial3D::TextureChannel BaseMaterial3D::get_metallic_texture_channel() const { @@ -1875,7 +1948,7 @@ void BaseMaterial3D::set_ao_texture_channel(TextureChannel p_channel) { ERR_FAIL_INDEX(p_channel, 5); ao_texture_channel = p_channel; - VS::get_singleton()->material_set_param(_get_material(), shader_names->ao_texture_channel, _get_texture_mask(p_channel)); + RS::get_singleton()->material_set_param(_get_material(), shader_names->ao_texture_channel, _get_texture_mask(p_channel)); } BaseMaterial3D::TextureChannel BaseMaterial3D::get_ao_texture_channel() const { @@ -1886,7 +1959,7 @@ void BaseMaterial3D::set_refraction_texture_channel(TextureChannel p_channel) { ERR_FAIL_INDEX(p_channel, 5); refraction_texture_channel = p_channel; - VS::get_singleton()->material_set_param(_get_material(), shader_names->refraction_texture_channel, _get_texture_mask(p_channel)); + RS::get_singleton()->material_set_param(_get_material(), shader_names->refraction_texture_channel, _get_texture_mask(p_channel)); } BaseMaterial3D::TextureChannel BaseMaterial3D::get_refraction_texture_channel() const { @@ -1954,7 +2027,7 @@ bool BaseMaterial3D::is_proximity_fade_enabled() const { void BaseMaterial3D::set_proximity_fade_distance(float p_distance) { proximity_fade_distance = p_distance; - VS::get_singleton()->material_set_param(_get_material(), shader_names->proximity_fade_distance, p_distance); + RS::get_singleton()->material_set_param(_get_material(), shader_names->proximity_fade_distance, p_distance); } float BaseMaterial3D::get_proximity_fade_distance() const { @@ -1975,7 +2048,7 @@ BaseMaterial3D::DistanceFadeMode BaseMaterial3D::get_distance_fade() const { void BaseMaterial3D::set_distance_fade_max_distance(float p_distance) { distance_fade_max_distance = p_distance; - VS::get_singleton()->material_set_param(_get_material(), shader_names->distance_fade_max, distance_fade_max_distance); + RS::get_singleton()->material_set_param(_get_material(), shader_names->distance_fade_max, distance_fade_max_distance); } float BaseMaterial3D::get_distance_fade_max_distance() const { @@ -1985,7 +2058,7 @@ float BaseMaterial3D::get_distance_fade_max_distance() const { void BaseMaterial3D::set_distance_fade_min_distance(float p_distance) { distance_fade_min_distance = p_distance; - VS::get_singleton()->material_set_param(_get_material(), shader_names->distance_fade_min, distance_fade_min_distance); + RS::get_singleton()->material_set_param(_get_material(), shader_names->distance_fade_min, distance_fade_min_distance); } float BaseMaterial3D::get_distance_fade_min_distance() const { @@ -2067,8 +2140,20 @@ void BaseMaterial3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_subsurface_scattering_strength", "strength"), &BaseMaterial3D::set_subsurface_scattering_strength); ClassDB::bind_method(D_METHOD("get_subsurface_scattering_strength"), &BaseMaterial3D::get_subsurface_scattering_strength); - ClassDB::bind_method(D_METHOD("set_transmission", "transmission"), &BaseMaterial3D::set_transmission); - ClassDB::bind_method(D_METHOD("get_transmission"), &BaseMaterial3D::get_transmission); + ClassDB::bind_method(D_METHOD("set_transmittance_color", "color"), &BaseMaterial3D::set_transmittance_color); + ClassDB::bind_method(D_METHOD("get_transmittance_color"), &BaseMaterial3D::get_transmittance_color); + + ClassDB::bind_method(D_METHOD("set_transmittance_depth", "depth"), &BaseMaterial3D::set_transmittance_depth); + ClassDB::bind_method(D_METHOD("get_transmittance_depth"), &BaseMaterial3D::get_transmittance_depth); + + ClassDB::bind_method(D_METHOD("set_transmittance_curve", "curve"), &BaseMaterial3D::set_transmittance_curve); + ClassDB::bind_method(D_METHOD("get_transmittance_curve"), &BaseMaterial3D::get_transmittance_curve); + + ClassDB::bind_method(D_METHOD("set_transmittance_boost", "boost"), &BaseMaterial3D::set_transmittance_boost); + ClassDB::bind_method(D_METHOD("get_transmittance_boost"), &BaseMaterial3D::get_transmittance_boost); + + ClassDB::bind_method(D_METHOD("set_backlight", "backlight"), &BaseMaterial3D::set_backlight); + ClassDB::bind_method(D_METHOD("get_backlight"), &BaseMaterial3D::get_backlight); ClassDB::bind_method(D_METHOD("set_refraction", "refraction"), &BaseMaterial3D::set_refraction); ClassDB::bind_method(D_METHOD("get_refraction"), &BaseMaterial3D::get_refraction); @@ -2282,14 +2367,23 @@ void BaseMaterial3D::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "heightmap_flip_texture"), "set_flag", "get_flag", FLAG_INVERT_HEIGHTMAP); ADD_GROUP("Subsurf Scatter", "subsurf_scatter_"); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "subsurf_scatter_enabled"), "set_feature", "get_feature", FEATURE_SUBSURACE_SCATTERING); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "subsurf_scatter_enabled"), "set_feature", "get_feature", FEATURE_SUBSURFACE_SCATTERING); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "subsurf_scatter_strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_subsurface_scattering_strength", "get_subsurface_scattering_strength"); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "subsurf_scatter_skin_mode"), "set_flag", "get_flag", FLAG_SUBSURFACE_MODE_SKIN); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "subsurf_scatter_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture", TEXTURE_SUBSURFACE_SCATTERING); - ADD_GROUP("Transmission", "transmission_"); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "transmission_enabled"), "set_feature", "get_feature", FEATURE_TRANSMISSION); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "transmission", PROPERTY_HINT_COLOR_NO_ALPHA), "set_transmission", "get_transmission"); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "transmission_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture", TEXTURE_TRANSMISSION); + ADD_SUBGROUP("Transmittance", "subsurf_scatter_transmittance_"); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "subsurf_scatter_transmittance_enabled"), "set_feature", "get_feature", FEATURE_SUBSURFACE_TRANSMITTANCE); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "subsurf_scatter_transmittance_color"), "set_transmittance_color", "get_transmittance_color"); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "subsurf_scatter_transmittance_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture", TEXTURE_SUBSURFACE_TRANSMITTANCE); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "subsurf_scatter_transmittance_depth", PROPERTY_HINT_RANGE, "0.001,8,0.001,or_greater"), "set_transmittance_depth", "get_transmittance_depth"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "subsurf_scatter_transmittance_curve", PROPERTY_HINT_EXP_EASING, "0.01,16,0.01"), "set_transmittance_curve", "get_transmittance_curve"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "subsurf_scatter_transmittance_boost", PROPERTY_HINT_RANGE, "0.00,1.0,0.01"), "set_transmittance_boost", "get_transmittance_boost"); + + ADD_GROUP("Back Lighting", "backlight_"); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "backlight_enabled"), "set_feature", "get_feature", FEATURE_BACKLIGHT); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "backlight", PROPERTY_HINT_COLOR_NO_ALPHA), "set_backlight", "get_backlight"); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "backlight_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture", TEXTURE_BACKLIGHT); ADD_GROUP("Refraction", "refraction_"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "refraction_enabled"), "set_feature", "get_feature", FEATURE_REFRACTION); @@ -2362,7 +2456,8 @@ void BaseMaterial3D::_bind_methods() { BIND_ENUM_CONSTANT(TEXTURE_AMBIENT_OCCLUSION); BIND_ENUM_CONSTANT(TEXTURE_HEIGHTMAP); BIND_ENUM_CONSTANT(TEXTURE_SUBSURFACE_SCATTERING); - BIND_ENUM_CONSTANT(TEXTURE_TRANSMISSION); + BIND_ENUM_CONSTANT(TEXTURE_SUBSURFACE_TRANSMITTANCE); + BIND_ENUM_CONSTANT(TEXTURE_BACKLIGHT); BIND_ENUM_CONSTANT(TEXTURE_REFRACTION); BIND_ENUM_CONSTANT(TEXTURE_DETAIL_MASK); BIND_ENUM_CONSTANT(TEXTURE_DETAIL_ALBEDO); @@ -2399,8 +2494,9 @@ void BaseMaterial3D::_bind_methods() { BIND_ENUM_CONSTANT(FEATURE_ANISOTROPY); BIND_ENUM_CONSTANT(FEATURE_AMBIENT_OCCLUSION); BIND_ENUM_CONSTANT(FEATURE_HEIGHT_MAPPING); - BIND_ENUM_CONSTANT(FEATURE_SUBSURACE_SCATTERING); - BIND_ENUM_CONSTANT(FEATURE_TRANSMISSION); + BIND_ENUM_CONSTANT(FEATURE_SUBSURFACE_SCATTERING); + BIND_ENUM_CONSTANT(FEATURE_SUBSURFACE_TRANSMITTANCE); + BIND_ENUM_CONSTANT(FEATURE_BACKLIGHT); BIND_ENUM_CONSTANT(FEATURE_REFRACTION); BIND_ENUM_CONSTANT(FEATURE_DETAIL); BIND_ENUM_CONSTANT(FEATURE_MAX); @@ -2436,6 +2532,7 @@ void BaseMaterial3D::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_USE_SHADOW_TO_OPACITY); BIND_ENUM_CONSTANT(FLAG_USE_TEXTURE_REPEAT); BIND_ENUM_CONSTANT(FLAG_INVERT_HEIGHTMAP); + BIND_ENUM_CONSTANT(FLAG_SUBSURFACE_MODE_SKIN); BIND_ENUM_CONSTANT(FLAG_MAX); BIND_ENUM_CONSTANT(DIFFUSE_BURLEY); @@ -2491,7 +2588,11 @@ BaseMaterial3D::BaseMaterial3D(bool p_orm) : set_anisotropy(0); set_heightmap_scale(0.05); set_subsurface_scattering_strength(0); - set_transmission(Color(0, 0, 0)); + set_backlight(Color(0, 0, 0)); + set_transmittance_color(Color(1, 1, 1, 1)); + set_transmittance_depth(0.1); + set_transmittance_curve(1.0); + set_transmittance_boost(0.0); set_refraction(0.05); set_point_size(1); set_uv1_offset(Vector3(0, 0, 0)); @@ -2547,7 +2648,8 @@ BaseMaterial3D::BaseMaterial3D(bool p_orm) : features[i] = false; } - current_key.key = 0; + current_key.key0 = 0; + current_key.key1 = 0; current_key.invalid_key = 1; texture_filter = TEXTURE_FILTER_LINEAR_WITH_MIPMAPS; _queue_shader_change(); @@ -2561,11 +2663,11 @@ BaseMaterial3D::~BaseMaterial3D() { 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); + RS::get_singleton()->free(shader_map[current_key].shader); shader_map.erase(current_key); } - VS::get_singleton()->material_set_shader(_get_material(), RID()); + RS::get_singleton()->material_set_shader(_get_material(), RID()); } } @@ -2641,7 +2743,7 @@ bool StandardMaterial3D::_set(const StringName &p_name, const Variant &p_value) { "depth_flip_binormal", "heightmap_flip_binormal" }, { "depth_texture", "heightmap_texture" }, - { NULL, NULL }, + { nullptr, nullptr }, }; int idx = 0; diff --git a/scene/resources/material.h b/scene/resources/material.h index fc77226fb9..241357ba9b 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -35,8 +35,8 @@ #include "core/self_list.h" #include "scene/resources/shader.h" #include "scene/resources/texture.h" -#include "servers/visual/shader_language.h" -#include "servers/visual_server.h" +#include "servers/rendering/shader_language.h" +#include "servers/rendering_server.h" class Material : public Resource { @@ -57,8 +57,8 @@ protected: public: enum { - RENDER_PRIORITY_MAX = VS::MATERIAL_RENDER_PRIORITY_MAX, - RENDER_PRIORITY_MIN = VS::MATERIAL_RENDER_PRIORITY_MIN, + RENDER_PRIORITY_MAX = RS::MATERIAL_RENDER_PRIORITY_MAX, + RENDER_PRIORITY_MIN = RS::MATERIAL_RENDER_PRIORITY_MIN, }; void set_next_pass(const Ref<Material> &p_pass); Ref<Material> get_next_pass() const; @@ -125,7 +125,8 @@ public: TEXTURE_AMBIENT_OCCLUSION, TEXTURE_HEIGHTMAP, TEXTURE_SUBSURFACE_SCATTERING, - TEXTURE_TRANSMISSION, + TEXTURE_SUBSURFACE_TRANSMITTANCE, + TEXTURE_BACKLIGHT, TEXTURE_REFRACTION, TEXTURE_DETAIL_MASK, TEXTURE_DETAIL_ALBEDO, @@ -173,8 +174,9 @@ public: FEATURE_ANISOTROPY, FEATURE_AMBIENT_OCCLUSION, FEATURE_HEIGHT_MAPPING, - FEATURE_SUBSURACE_SCATTERING, - FEATURE_TRANSMISSION, + FEATURE_SUBSURFACE_SCATTERING, + FEATURE_SUBSURFACE_TRANSMITTANCE, + FEATURE_BACKLIGHT, FEATURE_REFRACTION, FEATURE_DETAIL, FEATURE_MAX @@ -218,6 +220,7 @@ public: FLAG_USE_SHADOW_TO_OPACITY, FLAG_USE_TEXTURE_REPEAT, FLAG_INVERT_HEIGHTMAP, + FLAG_SUBSURFACE_MODE_SKIN, FLAG_MAX }; @@ -290,10 +293,16 @@ private: uint64_t roughness_channel : 3; }; - uint64_t key; + struct { + uint64_t key0; + uint64_t key1; + }; + bool operator==(const MaterialKey &p_key) const { + return (key0 == p_key.key0) && (key1 == p_key.key1); + } bool operator<(const MaterialKey &p_key) const { - return key < p_key.key; + return (key0 == p_key.key0) ? (key1 < p_key.key1) : (key0 < p_key.key0); } }; @@ -309,7 +318,8 @@ private: _FORCE_INLINE_ MaterialKey _compute_key() const { MaterialKey mk; - mk.key = 0; + mk.key0 = 0; + mk.key1 = 0; for (int i = 0; i < FEATURE_MAX; i++) { if (features[i]) { mk.feature_mask |= ((uint64_t)1 << i); @@ -356,7 +366,11 @@ private: StringName anisotropy; StringName heightmap_scale; StringName subsurface_scattering_strength; - StringName transmission; + StringName transmittance_color; + StringName transmittance_curve; + StringName transmittance_depth; + StringName transmittance_boost; + StringName backlight; StringName refraction; StringName point_size; StringName uv1_scale; @@ -414,7 +428,13 @@ private: float anisotropy; float heightmap_scale; float subsurface_scattering_strength; - Color transmission; + float transmittance_amount; + Color transmittance_color; + float transmittance_depth; + float transmittance_curve; + float transmittance_boost; + + Color backlight; float refraction; float point_size; float alpha_scissor_threshold; @@ -545,8 +565,20 @@ public: void set_subsurface_scattering_strength(float p_subsurface_scattering_strength); float get_subsurface_scattering_strength() const; - void set_transmission(const Color &p_transmission); - Color get_transmission() const; + void set_transmittance_color(const Color &p_color); + Color get_transmittance_color() const; + + void set_transmittance_depth(float p_depth); + float get_transmittance_depth() const; + + void set_transmittance_curve(float p_curve); + float get_transmittance_curve() const; + + void set_transmittance_boost(float p_boost); + float get_transmittance_boost() const; + + void set_backlight(const Color &p_backlight); + Color get_backlight() const; void set_refraction(float p_refraction); float get_refraction() const; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index f93b7ced98..6bb5be15f3 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -31,13 +31,13 @@ #include "mesh.h" #include "core/pair.h" -#include "scene/resources/concave_polygon_shape.h" -#include "scene/resources/convex_polygon_shape.h" +#include "scene/resources/concave_polygon_shape_3d.h" +#include "scene/resources/convex_polygon_shape_3d.h" #include "surface_tool.h" #include <stdlib.h> -Mesh::ConvexDecompositionFunc Mesh::convex_composition_function = NULL; +Mesh::ConvexDecompositionFunc Mesh::convex_composition_function = nullptr; Ref<TriangleMesh> Mesh::generate_triangle_mesh() const { @@ -169,20 +169,20 @@ Vector<Face3> Mesh::get_faces() const { /* for (int i=0;i<surfaces.size();i++) { - if (VisualServer::get_singleton()->mesh_surface_get_primitive_type( mesh, i ) != VisualServer::PRIMITIVE_TRIANGLES ) + if (RenderingServer::get_singleton()->mesh_surface_get_primitive_type( mesh, i ) != RenderingServer::PRIMITIVE_TRIANGLES ) continue; Vector<int> indices; Vector<Vector3> vertices; - vertices=VisualServer::get_singleton()->mesh_surface_get_array(mesh, i,VisualServer::ARRAY_VERTEX); + vertices=RenderingServer::get_singleton()->mesh_surface_get_array(mesh, i,RenderingServer::ARRAY_VERTEX); - int len=VisualServer::get_singleton()->mesh_surface_get_array_index_len(mesh, i); + int len=RenderingServer::get_singleton()->mesh_surface_get_array_index_len(mesh, i); bool has_indices; if (len>0) { - indices=VisualServer::get_singleton()->mesh_surface_get_array(mesh, i,VisualServer::ARRAY_INDEX); + indices=RenderingServer::get_singleton()->mesh_surface_get_array(mesh, i,RenderingServer::ARRAY_INDEX); has_indices=true; } else { @@ -226,28 +226,28 @@ Vector<Face3> Mesh::get_faces() const { */ } -Ref<Shape> Mesh::create_convex_shape() const { +Ref<Shape3D> Mesh::create_convex_shape() const { Vector<Vector3> vertices; for (int i = 0; i < get_surface_count(); i++) { Array a = surface_get_arrays(i); - ERR_FAIL_COND_V(a.empty(), Ref<ConvexPolygonShape>()); + ERR_FAIL_COND_V(a.empty(), Ref<ConvexPolygonShape3D>()); Vector<Vector3> v = a[ARRAY_VERTEX]; vertices.append_array(v); } - Ref<ConvexPolygonShape> shape = memnew(ConvexPolygonShape); + Ref<ConvexPolygonShape3D> shape = memnew(ConvexPolygonShape3D); shape->set_points(vertices); return shape; } -Ref<Shape> Mesh::create_trimesh_shape() const { +Ref<Shape3D> Mesh::create_trimesh_shape() const { Vector<Face3> faces = get_faces(); if (faces.size() == 0) - return Ref<Shape>(); + return Ref<Shape3D>(); Vector<Vector3> face_points; face_points.resize(faces.size() * 3); @@ -260,7 +260,7 @@ Ref<Shape> Mesh::create_trimesh_shape() const { face_points.set(i + 2, f.vertex[2]); } - Ref<ConcavePolygonShape> shape = memnew(ConcavePolygonShape); + Ref<ConcavePolygonShape3D> shape = memnew(ConcavePolygonShape3D); shape->set_faces(face_points); return shape; } @@ -372,7 +372,7 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { ERR_FAIL_COND_V(arrays.size() != ARRAY_MAX, Ref<ArrayMesh>()); { - int *ir; + int *ir = nullptr; Vector<int> indices = arrays[ARRAY_INDEX]; bool has_indices = false; Vector<Vector3> vertices = arrays[ARRAY_VERTEX]; @@ -541,15 +541,15 @@ void Mesh::clear_cache() const { debug_lines.clear(); } -Vector<Ref<Shape>> Mesh::convex_decompose() const { +Vector<Ref<Shape3D>> Mesh::convex_decompose() const { - ERR_FAIL_COND_V(!convex_composition_function, Vector<Ref<Shape>>()); + ERR_FAIL_COND_V(!convex_composition_function, Vector<Ref<Shape3D>>()); const Vector<Face3> faces = get_faces(); Vector<Vector<Face3>> decomposed = convex_composition_function(faces); - Vector<Ref<Shape>> ret; + Vector<Ref<Shape3D>> ret; for (int i = 0; i < decomposed.size(); i++) { Set<Vector3> points; @@ -569,7 +569,7 @@ Vector<Ref<Shape>> Mesh::convex_decompose() const { } } - Ref<ConvexPolygonShape> shape; + Ref<ConvexPolygonShape3D> shape; shape.instance(); shape->set_points(convex_points); ret.push_back(shape); @@ -846,7 +846,7 @@ Array ArrayMesh::_get_surfaces() const { Array ret; for (int i = 0; i < surfaces.size(); i++) { - VisualServer::SurfaceData surface = VS::get_singleton()->mesh_get_surface(mesh, i); + RenderingServer::SurfaceData surface = RS::get_singleton()->mesh_get_surface(mesh, i); Dictionary data; data["format"] = surface.format; data["primitive"] = surface.primitive; @@ -902,20 +902,20 @@ Array ArrayMesh::_get_surfaces() const { void ArrayMesh::_create_if_empty() const { if (!mesh.is_valid()) { - mesh = VS::get_singleton()->mesh_create(); - VS::get_singleton()->mesh_set_blend_shape_mode(mesh, (VS::BlendShapeMode)blend_shape_mode); + mesh = RS::get_singleton()->mesh_create(); + RS::get_singleton()->mesh_set_blend_shape_mode(mesh, (RS::BlendShapeMode)blend_shape_mode); } } void ArrayMesh::_set_surfaces(const Array &p_surfaces) { - Vector<VS::SurfaceData> surface_data; + Vector<RS::SurfaceData> surface_data; Vector<Ref<Material>> surface_materials; Vector<String> surface_names; Vector<bool> surface_2d; for (int i = 0; i < p_surfaces.size(); i++) { - VS::SurfaceData surface; + RS::SurfaceData surface; Dictionary d = p_surfaces[i]; ERR_FAIL_COND(!d.has("format")); ERR_FAIL_COND(!d.has("primitive")); @@ -923,7 +923,7 @@ void ArrayMesh::_set_surfaces(const Array &p_surfaces) { ERR_FAIL_COND(!d.has("vertex_count")); ERR_FAIL_COND(!d.has("aabb")); surface.format = d["format"]; - surface.primitive = VS::PrimitiveType(int(d["primitive"])); + surface.primitive = RS::PrimitiveType(int(d["primitive"])); surface.vertex_data = d["vertex_data"]; surface.vertex_count = d["vertex_count"]; surface.aabb = d["aabb"]; @@ -938,7 +938,7 @@ void ArrayMesh::_set_surfaces(const Array &p_surfaces) { Array lods = d["lods"]; ERR_FAIL_COND(lods.size() & 1); //must be even for (int j = 0; j < lods.size(); j += 2) { - VS::SurfaceData::LOD lod; + RS::SurfaceData::LOD lod; lod.edge_length = lods[j + 0]; lod.index_data = lods[j + 1]; surface.lods.push_back(lod); @@ -993,15 +993,15 @@ void ArrayMesh::_set_surfaces(const Array &p_surfaces) { if (mesh.is_valid()) { //if mesh exists, it needs to be updated - VS::get_singleton()->mesh_clear(mesh); + RS::get_singleton()->mesh_clear(mesh); for (int i = 0; i < surface_data.size(); i++) { - VS::get_singleton()->mesh_add_surface(mesh, surface_data[i]); + RS::get_singleton()->mesh_add_surface(mesh, surface_data[i]); } } else { // if mesh does not exist (first time this is loaded, most likely), // we can create it with a single call, which is a lot more efficient and thread friendly - mesh = VS::get_singleton()->mesh_create_from_surfaces(surface_data); - VS::get_singleton()->mesh_set_blend_shape_mode(mesh, (VS::BlendShapeMode)blend_shape_mode); + mesh = RS::get_singleton()->mesh_create_from_surfaces(surface_data); + RS::get_singleton()->mesh_set_blend_shape_mode(mesh, (RS::BlendShapeMode)blend_shape_mode); } surfaces.clear(); @@ -1102,7 +1102,7 @@ void ArrayMesh::_recompute_aabb() { #ifndef _MSC_VER #warning need to add binding to add_surface using future MeshSurfaceData object #endif -void ArrayMesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t>> &p_blend_shapes, const Vector<AABB> &p_bone_aabb, const Vector<VS::SurfaceData::LOD> &p_lods) { +void ArrayMesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t>> &p_blend_shapes, const Vector<AABB> &p_bone_aabb, const Vector<RS::SurfaceData::LOD> &p_lods) { _create_if_empty(); @@ -1117,9 +1117,9 @@ void ArrayMesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const surfaces.push_back(s); _recompute_aabb(); - VS::SurfaceData sd; + RS::SurfaceData sd; sd.format = p_format; - sd.primitive = VS::PrimitiveType(p_primitive); + sd.primitive = RS::PrimitiveType(p_primitive); sd.aabb = p_aabb; sd.vertex_count = p_vertex_count; sd.vertex_data = p_array; @@ -1129,7 +1129,7 @@ void ArrayMesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const sd.bone_aabbs = p_bone_aabb; sd.lods = p_lods; - VisualServer::get_singleton()->mesh_add_surface(mesh, sd); + RenderingServer::get_singleton()->mesh_add_surface(mesh, sd); clear_cache(); _change_notify(); @@ -1140,9 +1140,9 @@ void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array & ERR_FAIL_COND(p_arrays.size() != ARRAY_MAX); - VS::SurfaceData surface; + RS::SurfaceData surface; - Error err = VS::get_singleton()->mesh_create_surface_data_from_arrays(&surface, (VisualServer::PrimitiveType)p_primitive, p_arrays, p_blend_shapes, p_lods, p_flags); + Error err = RS::get_singleton()->mesh_create_surface_data_from_arrays(&surface, (RenderingServer::PrimitiveType)p_primitive, p_arrays, p_blend_shapes, p_lods, p_flags); ERR_FAIL_COND(err != OK); /* print_line("format: " + itos(surface.format)); @@ -1159,16 +1159,16 @@ void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array & Array ArrayMesh::surface_get_arrays(int p_surface) const { ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array()); - return VisualServer::get_singleton()->mesh_surface_get_arrays(mesh, p_surface); + return RenderingServer::get_singleton()->mesh_surface_get_arrays(mesh, p_surface); } Array ArrayMesh::surface_get_blend_shape_arrays(int p_surface) const { ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array()); - return VisualServer::get_singleton()->mesh_surface_get_blend_shape_arrays(mesh, p_surface); + return RenderingServer::get_singleton()->mesh_surface_get_blend_shape_arrays(mesh, p_surface); } Dictionary ArrayMesh::surface_get_lods(int p_surface) const { ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Dictionary()); - return VisualServer::get_singleton()->mesh_surface_get_lods(mesh, p_surface); + return RenderingServer::get_singleton()->mesh_surface_get_lods(mesh, p_surface); } int ArrayMesh::get_surface_count() const { @@ -1193,7 +1193,7 @@ void ArrayMesh::add_blend_shape(const StringName &p_name) { } blend_shapes.push_back(name); - //VS::get_singleton()->mesh_set_blend_shape_count(mesh, blend_shapes.size()); + //RS::get_singleton()->mesh_set_blend_shape_count(mesh, blend_shapes.size()); } int ArrayMesh::get_blend_shape_count() const { @@ -1215,7 +1215,7 @@ void ArrayMesh::set_blend_shape_mode(BlendShapeMode p_mode) { blend_shape_mode = p_mode; if (mesh.is_valid()) { - VS::get_singleton()->mesh_set_blend_shape_mode(mesh, (VS::BlendShapeMode)p_mode); + RS::get_singleton()->mesh_set_blend_shape_mode(mesh, (RS::BlendShapeMode)p_mode); } } @@ -1254,7 +1254,7 @@ void ArrayMesh::surface_set_material(int p_idx, const Ref<Material> &p_material) if (surfaces[p_idx].material == p_material) return; surfaces.write[p_idx].material = p_material; - VisualServer::get_singleton()->mesh_surface_set_material(mesh, p_idx, p_material.is_null() ? RID() : p_material->get_rid()); + RenderingServer::get_singleton()->mesh_surface_set_material(mesh, p_idx, p_material.is_null() ? RID() : p_material->get_rid()); _change_notify("material"); emit_changed(); @@ -1286,7 +1286,7 @@ String ArrayMesh::surface_get_name(int p_idx) const { void ArrayMesh::surface_update_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data) { ERR_FAIL_INDEX(p_surface, surfaces.size()); - VS::get_singleton()->mesh_surface_update_region(mesh, p_surface, p_offset, p_data); + RS::get_singleton()->mesh_surface_update_region(mesh, p_surface, p_offset, p_data); emit_changed(); } @@ -1318,7 +1318,7 @@ void ArrayMesh::clear_surfaces() { if (!mesh.is_valid()) { return; } - VS::get_singleton()->mesh_clear(mesh); + RS::get_singleton()->mesh_clear(mesh); surfaces.clear(); aabb = AABB(); } @@ -1327,7 +1327,7 @@ void ArrayMesh::set_custom_aabb(const AABB &p_custom) { _create_if_empty(); custom_aabb = p_custom; - VS::get_singleton()->mesh_set_custom_aabb(mesh, custom_aabb); + RS::get_singleton()->mesh_set_custom_aabb(mesh, custom_aabb); emit_changed(); } @@ -1359,7 +1359,7 @@ void ArrayMesh::regen_normalmaps() { } //dirty hack -bool (*array_mesh_lightmap_unwrap_callback)(float p_texel_size, const float *p_vertices, const float *p_normals, int p_vertex_count, const int *p_indices, const int *p_face_materials, int p_index_count, float **r_uv, int **r_vertex, int *r_vertex_count, int **r_index, int *r_index_count, int *r_size_hint_x, int *r_size_hint_y) = NULL; +bool (*array_mesh_lightmap_unwrap_callback)(float p_texel_size, const float *p_vertices, const float *p_normals, int p_vertex_count, const int *p_indices, const int *p_face_materials, int p_index_count, float **r_uv, int **r_vertex, int *r_vertex_count, int **r_index, int *r_index_count, int *r_size_hint_x, int *r_size_hint_y) = nullptr; struct ArrayMeshLightmapSurface { @@ -1609,7 +1609,7 @@ void ArrayMesh::_bind_methods() { } void ArrayMesh::reload_from_file() { - VisualServer::get_singleton()->mesh_clear(mesh); + RenderingServer::get_singleton()->mesh_clear(mesh); surfaces.clear(); clear_blend_shapes(); clear_cache(); @@ -1622,13 +1622,13 @@ void ArrayMesh::reload_from_file() { ArrayMesh::ArrayMesh() { //mesh is now created on demand - //mesh = VisualServer::get_singleton()->mesh_create(); + //mesh = RenderingServer::get_singleton()->mesh_create(); blend_shape_mode = BLEND_SHAPE_MODE_RELATIVE; } ArrayMesh::~ArrayMesh() { if (mesh.is_valid()) { - VisualServer::get_singleton()->free(mesh); + RenderingServer::get_singleton()->free(mesh); } } diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index e0cc214301..25a9722046 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -35,8 +35,8 @@ #include "core/math/triangle_mesh.h" #include "core/resource.h" #include "scene/resources/material.h" -#include "scene/resources/shape.h" -#include "servers/visual_server.h" +#include "scene/resources/shape_3d.h" +#include "servers/rendering_server.h" class Mesh : public Resource { GDCLASS(Mesh, Resource); @@ -51,22 +51,22 @@ protected: public: enum { - NO_INDEX_ARRAY = VisualServer::NO_INDEX_ARRAY, - ARRAY_WEIGHTS_SIZE = VisualServer::ARRAY_WEIGHTS_SIZE + NO_INDEX_ARRAY = RenderingServer::NO_INDEX_ARRAY, + ARRAY_WEIGHTS_SIZE = RenderingServer::ARRAY_WEIGHTS_SIZE }; enum ArrayType { - ARRAY_VERTEX = VisualServer::ARRAY_VERTEX, - ARRAY_NORMAL = VisualServer::ARRAY_NORMAL, - ARRAY_TANGENT = VisualServer::ARRAY_TANGENT, - ARRAY_COLOR = VisualServer::ARRAY_COLOR, - ARRAY_TEX_UV = VisualServer::ARRAY_TEX_UV, - ARRAY_TEX_UV2 = VisualServer::ARRAY_TEX_UV2, - ARRAY_BONES = VisualServer::ARRAY_BONES, - ARRAY_WEIGHTS = VisualServer::ARRAY_WEIGHTS, - ARRAY_INDEX = VisualServer::ARRAY_INDEX, - ARRAY_MAX = VisualServer::ARRAY_MAX + ARRAY_VERTEX = RenderingServer::ARRAY_VERTEX, + ARRAY_NORMAL = RenderingServer::ARRAY_NORMAL, + ARRAY_TANGENT = RenderingServer::ARRAY_TANGENT, + ARRAY_COLOR = RenderingServer::ARRAY_COLOR, + ARRAY_TEX_UV = RenderingServer::ARRAY_TEX_UV, + ARRAY_TEX_UV2 = RenderingServer::ARRAY_TEX_UV2, + ARRAY_BONES = RenderingServer::ARRAY_BONES, + ARRAY_WEIGHTS = RenderingServer::ARRAY_WEIGHTS, + ARRAY_INDEX = RenderingServer::ARRAY_INDEX, + ARRAY_MAX = RenderingServer::ARRAY_MAX }; @@ -98,18 +98,18 @@ public: }; enum PrimitiveType { - PRIMITIVE_POINTS = VisualServer::PRIMITIVE_POINTS, - PRIMITIVE_LINES = VisualServer::PRIMITIVE_LINES, - PRIMITIVE_LINE_STRIP = VisualServer::PRIMITIVE_LINE_STRIP, - PRIMITIVE_TRIANGLES = VisualServer::PRIMITIVE_TRIANGLES, - PRIMITIVE_TRIANGLE_STRIP = VisualServer::PRIMITIVE_TRIANGLE_STRIP, - PRIMITIVE_MAX = VisualServer::PRIMITIVE_MAX, + PRIMITIVE_POINTS = RenderingServer::PRIMITIVE_POINTS, + PRIMITIVE_LINES = RenderingServer::PRIMITIVE_LINES, + PRIMITIVE_LINE_STRIP = RenderingServer::PRIMITIVE_LINE_STRIP, + PRIMITIVE_TRIANGLES = RenderingServer::PRIMITIVE_TRIANGLES, + PRIMITIVE_TRIANGLE_STRIP = RenderingServer::PRIMITIVE_TRIANGLE_STRIP, + PRIMITIVE_MAX = RenderingServer::PRIMITIVE_MAX, }; enum BlendShapeMode { - BLEND_SHAPE_MODE_NORMALIZED = VS::BLEND_SHAPE_MODE_NORMALIZED, - BLEND_SHAPE_MODE_RELATIVE = VS::BLEND_SHAPE_MODE_RELATIVE, + BLEND_SHAPE_MODE_NORMALIZED = RS::BLEND_SHAPE_MODE_NORMALIZED, + BLEND_SHAPE_MODE_RELATIVE = RS::BLEND_SHAPE_MODE_RELATIVE, }; virtual int get_surface_count() const = 0; @@ -131,8 +131,8 @@ public: void generate_debug_mesh_lines(Vector<Vector3> &r_lines); void generate_debug_mesh_indices(Vector<Vector3> &r_points); - Ref<Shape> create_trimesh_shape() const; - Ref<Shape> create_convex_shape() const; + Ref<Shape3D> create_trimesh_shape() const; + Ref<Shape3D> create_convex_shape() const; Ref<Mesh> create_outline(float p_margin) const; @@ -146,7 +146,7 @@ public: static ConvexDecompositionFunc convex_composition_function; - Vector<Ref<Shape>> convex_decompose() const; + Vector<Ref<Shape3D>> convex_decompose() const; Mesh(); }; @@ -193,7 +193,7 @@ protected: public: void add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes = Array(), const Dictionary &p_lods = Dictionary(), uint32_t p_flags = ARRAY_COMPRESS_DEFAULT); - void add_surface(uint32_t p_format, PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t>> &p_blend_shapes = Vector<Vector<uint8_t>>(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>(), const Vector<VS::SurfaceData::LOD> &p_lods = Vector<VS::SurfaceData::LOD>()); + void add_surface(uint32_t p_format, PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t>> &p_blend_shapes = Vector<Vector<uint8_t>>(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>(), const Vector<RS::SurfaceData::LOD> &p_lods = Vector<RS::SurfaceData::LOD>()); Array surface_get_arrays(int p_surface) const; Array surface_get_blend_shape_arrays(int p_surface) const; diff --git a/scene/resources/mesh_data_tool.cpp b/scene/resources/mesh_data_tool.cpp index 675cfc6d64..76d96786bc 100644 --- a/scene/resources/mesh_data_tool.cpp +++ b/scene/resources/mesh_data_tool.cpp @@ -58,30 +58,30 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf const Vector3 *vr = varray.ptr(); - const Vector3 *nr; + const Vector3 *nr = nullptr; if (arrays[Mesh::ARRAY_NORMAL].get_type() != Variant::NIL) nr = arrays[Mesh::ARRAY_NORMAL].operator Vector<Vector3>().ptr(); - const real_t *ta; + const real_t *ta = nullptr; if (arrays[Mesh::ARRAY_TANGENT].get_type() != Variant::NIL) ta = arrays[Mesh::ARRAY_TANGENT].operator Vector<real_t>().ptr(); - const Vector2 *uv; + const Vector2 *uv = nullptr; if (arrays[Mesh::ARRAY_TEX_UV].get_type() != Variant::NIL) uv = arrays[Mesh::ARRAY_TEX_UV].operator Vector<Vector2>().ptr(); - const Vector2 *uv2; + const Vector2 *uv2 = nullptr; if (arrays[Mesh::ARRAY_TEX_UV2].get_type() != Variant::NIL) uv2 = arrays[Mesh::ARRAY_TEX_UV2].operator Vector<Vector2>().ptr(); - const Color *col; + const Color *col = nullptr; if (arrays[Mesh::ARRAY_COLOR].get_type() != Variant::NIL) col = arrays[Mesh::ARRAY_COLOR].operator Vector<Color>().ptr(); - const int *bo; + const int *bo = nullptr; if (arrays[Mesh::ARRAY_BONES].get_type() != Variant::NIL) bo = arrays[Mesh::ARRAY_BONES].operator Vector<int>().ptr(); - const real_t *we; + const real_t *we = nullptr; if (arrays[Mesh::ARRAY_WEIGHTS].get_type() != Variant::NIL) we = arrays[Mesh::ARRAY_WEIGHTS].operator Vector<real_t>().ptr(); @@ -202,43 +202,43 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { v.resize(vcount); Vector3 *vr = v.ptrw(); - Vector3 *nr; + Vector3 *nr = nullptr; if (format & Mesh::ARRAY_FORMAT_NORMAL) { n.resize(vcount); nr = n.ptrw(); } - real_t *ta; + real_t *ta = nullptr; if (format & Mesh::ARRAY_FORMAT_TANGENT) { t.resize(vcount * 4); ta = t.ptrw(); } - Vector2 *uv; + Vector2 *uv = nullptr; if (format & Mesh::ARRAY_FORMAT_TEX_UV) { u.resize(vcount); uv = u.ptrw(); } - Vector2 *uv2; + Vector2 *uv2 = nullptr; if (format & Mesh::ARRAY_FORMAT_TEX_UV2) { u2.resize(vcount); uv2 = u2.ptrw(); } - Color *col; + Color *col = nullptr; if (format & Mesh::ARRAY_FORMAT_COLOR) { c.resize(vcount); col = c.ptrw(); } - int *bo; + int *bo = nullptr; if (format & Mesh::ARRAY_FORMAT_BONES) { b.resize(vcount * 4); bo = b.ptrw(); } - real_t *we; + real_t *we = nullptr; if (format & Mesh::ARRAY_FORMAT_WEIGHTS) { w.resize(vcount * 4); we = w.ptrw(); diff --git a/scene/resources/mesh_library.h b/scene/resources/mesh_library.h index b256e86b96..55001f2545 100644 --- a/scene/resources/mesh_library.h +++ b/scene/resources/mesh_library.h @@ -34,8 +34,8 @@ #include "core/map.h" #include "core/resource.h" #include "mesh.h" -#include "scene/3d/navigation_region.h" -#include "shape.h" +#include "scene/3d/navigation_region_3d.h" +#include "shape_3d.h" class MeshLibrary : public Resource { @@ -44,7 +44,7 @@ class MeshLibrary : public Resource { public: struct ShapeData { - Ref<Shape> shape; + Ref<Shape3D> shape; Transform local_transform; }; struct Item { diff --git a/scene/resources/multimesh.cpp b/scene/resources/multimesh.cpp index aa8be326f5..ce561bfaaf 100644 --- a/scene/resources/multimesh.cpp +++ b/scene/resources/multimesh.cpp @@ -30,7 +30,7 @@ #include "multimesh.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" #ifndef DISABLE_DEPRECATED // Kept for compatibility from 3.x to 4.0. @@ -198,20 +198,20 @@ Vector<Color> MultiMesh::_get_custom_data_array() const { #endif // DISABLE_DEPRECATED void MultiMesh::set_buffer(const Vector<float> &p_buffer) { - VS::get_singleton()->multimesh_set_buffer(multimesh, p_buffer); + RS::get_singleton()->multimesh_set_buffer(multimesh, p_buffer); } Vector<float> MultiMesh::get_buffer() const { - return VS::get_singleton()->multimesh_get_buffer(multimesh); + return RS::get_singleton()->multimesh_get_buffer(multimesh); } void MultiMesh::set_mesh(const Ref<Mesh> &p_mesh) { mesh = p_mesh; if (!mesh.is_null()) - VisualServer::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid()); + RenderingServer::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid()); else - VisualServer::get_singleton()->multimesh_set_mesh(multimesh, RID()); + RenderingServer::get_singleton()->multimesh_set_mesh(multimesh, RID()); } Ref<Mesh> MultiMesh::get_mesh() const { @@ -221,7 +221,7 @@ Ref<Mesh> MultiMesh::get_mesh() const { void MultiMesh::set_instance_count(int p_count) { ERR_FAIL_COND(p_count < 0); - VisualServer::get_singleton()->multimesh_allocate(multimesh, p_count, VS::MultimeshTransformFormat(transform_format), use_colors, use_custom_data); + RenderingServer::get_singleton()->multimesh_allocate(multimesh, p_count, RS::MultimeshTransformFormat(transform_format), use_colors, use_custom_data); instance_count = p_count; } int MultiMesh::get_instance_count() const { @@ -232,7 +232,7 @@ int MultiMesh::get_instance_count() const { void MultiMesh::set_visible_instance_count(int p_count) { ERR_FAIL_COND(p_count < -1); ERR_FAIL_COND(p_count > instance_count); - VisualServer::get_singleton()->multimesh_set_visible_instances(multimesh, p_count); + RenderingServer::get_singleton()->multimesh_set_visible_instances(multimesh, p_count); visible_instance_count = p_count; } int MultiMesh::get_visible_instance_count() const { @@ -242,45 +242,45 @@ int MultiMesh::get_visible_instance_count() const { void MultiMesh::set_instance_transform(int p_instance, const Transform &p_transform) { - VisualServer::get_singleton()->multimesh_instance_set_transform(multimesh, p_instance, p_transform); + RenderingServer::get_singleton()->multimesh_instance_set_transform(multimesh, p_instance, p_transform); } void MultiMesh::set_instance_transform_2d(int p_instance, const Transform2D &p_transform) { - VisualServer::get_singleton()->multimesh_instance_set_transform_2d(multimesh, p_instance, p_transform); + RenderingServer::get_singleton()->multimesh_instance_set_transform_2d(multimesh, p_instance, p_transform); } Transform MultiMesh::get_instance_transform(int p_instance) const { - return VisualServer::get_singleton()->multimesh_instance_get_transform(multimesh, p_instance); + return RenderingServer::get_singleton()->multimesh_instance_get_transform(multimesh, p_instance); } Transform2D MultiMesh::get_instance_transform_2d(int p_instance) const { - return VisualServer::get_singleton()->multimesh_instance_get_transform_2d(multimesh, p_instance); + return RenderingServer::get_singleton()->multimesh_instance_get_transform_2d(multimesh, p_instance); } void MultiMesh::set_instance_color(int p_instance, const Color &p_color) { - VisualServer::get_singleton()->multimesh_instance_set_color(multimesh, p_instance, p_color); + RenderingServer::get_singleton()->multimesh_instance_set_color(multimesh, p_instance, p_color); } Color MultiMesh::get_instance_color(int p_instance) const { - return VisualServer::get_singleton()->multimesh_instance_get_color(multimesh, p_instance); + return RenderingServer::get_singleton()->multimesh_instance_get_color(multimesh, p_instance); } void MultiMesh::set_instance_custom_data(int p_instance, const Color &p_custom_data) { - VisualServer::get_singleton()->multimesh_instance_set_custom_data(multimesh, p_instance, p_custom_data); + RenderingServer::get_singleton()->multimesh_instance_set_custom_data(multimesh, p_instance, p_custom_data); } Color MultiMesh::get_instance_custom_data(int p_instance) const { - return VisualServer::get_singleton()->multimesh_instance_get_custom_data(multimesh, p_instance); + return RenderingServer::get_singleton()->multimesh_instance_get_custom_data(multimesh, p_instance); } AABB MultiMesh::get_aabb() const { - return VisualServer::get_singleton()->multimesh_get_aabb(multimesh); + return RenderingServer::get_singleton()->multimesh_get_aabb(multimesh); } RID MultiMesh::get_rid() const { @@ -375,7 +375,7 @@ void MultiMesh::_bind_methods() { MultiMesh::MultiMesh() { - multimesh = VisualServer::get_singleton()->multimesh_create(); + multimesh = RenderingServer::get_singleton()->multimesh_create(); use_colors = false; use_custom_data = false; transform_format = TRANSFORM_2D; @@ -385,5 +385,5 @@ MultiMesh::MultiMesh() { MultiMesh::~MultiMesh() { - VisualServer::get_singleton()->free(multimesh); + RenderingServer::get_singleton()->free(multimesh); } diff --git a/scene/resources/multimesh.h b/scene/resources/multimesh.h index 8ca30a5b88..c1e52bc981 100644 --- a/scene/resources/multimesh.h +++ b/scene/resources/multimesh.h @@ -32,7 +32,7 @@ #define MULTIMESH_H #include "scene/resources/mesh.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" class MultiMesh : public Resource { @@ -41,8 +41,8 @@ class MultiMesh : public Resource { public: enum TransformFormat { - TRANSFORM_2D = VS::MULTIMESH_TRANSFORM_2D, - TRANSFORM_3D = VS::MULTIMESH_TRANSFORM_3D + TRANSFORM_2D = RS::MULTIMESH_TRANSFORM_2D, + TRANSFORM_3D = RS::MULTIMESH_TRANSFORM_3D }; private: diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 7059682904..633771506e 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -35,7 +35,7 @@ #include "core/io/resource_loader.h" #include "core/project_settings.h" #include "scene/2d/node_2d.h" -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" #include "scene/gui/control.h" #include "scene/main/instance_placeholder.h" @@ -51,25 +51,25 @@ Node *SceneState::instance(GenEditState p_edit_state) const { // nodes where instancing failed (because something is missing) List<Node *> stray_instances; -#define NODE_FROM_ID(p_name, p_id) \ - Node *p_name; \ - if (p_id & FLAG_ID_IS_PATH) { \ - NodePath np = node_paths[p_id & FLAG_MASK]; \ - p_name = ret_nodes[0]->get_node_or_null(np); \ - } else { \ - ERR_FAIL_INDEX_V(p_id &FLAG_MASK, nc, NULL); \ - p_name = ret_nodes[p_id & FLAG_MASK]; \ +#define NODE_FROM_ID(p_name, p_id) \ + Node *p_name; \ + if (p_id & FLAG_ID_IS_PATH) { \ + NodePath np = node_paths[p_id & FLAG_MASK]; \ + p_name = ret_nodes[0]->get_node_or_null(np); \ + } else { \ + ERR_FAIL_INDEX_V(p_id &FLAG_MASK, nc, nullptr); \ + p_name = ret_nodes[p_id & FLAG_MASK]; \ } int nc = nodes.size(); - ERR_FAIL_COND_V(nc == 0, NULL); + ERR_FAIL_COND_V(nc == 0, nullptr); - const StringName *snames = NULL; + const StringName *snames = nullptr; int sname_count = names.size(); if (sname_count) snames = &names[0]; - const Variant *props = NULL; + const Variant *props = nullptr; int prop_count = variants.size(); if (prop_count) props = &variants[0]; @@ -88,11 +88,11 @@ Node *SceneState::instance(GenEditState p_edit_state) const { const NodeData &n = nd[i]; - Node *parent = NULL; + Node *parent = nullptr; if (i > 0) { - ERR_FAIL_COND_V_MSG(n.parent == -1, NULL, vformat("Invalid scene: node %s does not specify its parent node.", snames[n.name])); + ERR_FAIL_COND_V_MSG(n.parent == -1, nullptr, vformat("Invalid scene: node %s does not specify its parent node.", snames[n.name])); NODE_FROM_ID(nparent, n.parent); #ifdef DEBUG_ENABLED if (!nparent && (n.parent & FLAG_ID_IS_PATH)) { @@ -103,14 +103,14 @@ Node *SceneState::instance(GenEditState p_edit_state) const { parent = nparent; } - Node *node = NULL; + Node *node = nullptr; if (i == 0 && base_scene_idx >= 0) { //scene inheritance on root node Ref<PackedScene> sdata = props[base_scene_idx]; - ERR_FAIL_COND_V(!sdata.is_valid(), NULL); + ERR_FAIL_COND_V(!sdata.is_valid(), nullptr); node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); //only main gets main edit state - ERR_FAIL_COND_V(!node, NULL); + ERR_FAIL_COND_V(!node, nullptr); if (p_edit_state != GEN_EDIT_STATE_DISABLED) { node->set_scene_inherited_state(sdata->get_state()); } @@ -123,9 +123,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const { if (disable_placeholders) { Ref<PackedScene> sdata = ResourceLoader::load(path, "PackedScene"); - ERR_FAIL_COND_V(!sdata.is_valid(), NULL); + ERR_FAIL_COND_V(!sdata.is_valid(), nullptr); node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); - ERR_FAIL_COND_V(!node, NULL); + ERR_FAIL_COND_V(!node, nullptr); } else { InstancePlaceholder *ip = memnew(InstancePlaceholder); ip->set_instance_path(path); @@ -134,9 +134,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const { node->set_scene_instance_load_placeholder(true); } else { Ref<PackedScene> sdata = props[n.instance & FLAG_MASK]; - ERR_FAIL_COND_V(!sdata.is_valid(), NULL); + ERR_FAIL_COND_V(!sdata.is_valid(), nullptr); node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); - ERR_FAIL_COND_V(!node, NULL); + ERR_FAIL_COND_V(!node, nullptr); } } else if (n.type == TYPE_INSTANCED) { @@ -155,12 +155,12 @@ Node *SceneState::instance(GenEditState p_edit_state) const { if (!Object::cast_to<Node>(obj)) { if (obj) { memdelete(obj); - obj = NULL; + obj = nullptr; } WARN_PRINT(String("Warning node of type " + snames[n.type].operator String() + " does not exist.").ascii().get_data()); if (n.parent >= 0 && n.parent < nc && ret_nodes[n.parent]) { - if (Object::cast_to<Spatial>(ret_nodes[n.parent])) { - obj = memnew(Spatial); + if (Object::cast_to<Node3D>(ret_nodes[n.parent])) { + obj = memnew(Node3D); } else if (Object::cast_to<Control>(ret_nodes[n.parent])) { obj = memnew(Control); } else if (Object::cast_to<Node2D>(ret_nodes[n.parent])) { @@ -193,8 +193,8 @@ Node *SceneState::instance(GenEditState p_edit_state) const { for (int j = 0; j < nprop_count; j++) { bool valid; - ERR_FAIL_INDEX_V(nprops[j].name, sname_count, NULL); - ERR_FAIL_INDEX_V(nprops[j].value, prop_count, NULL); + ERR_FAIL_INDEX_V(nprops[j].name, sname_count, nullptr); + ERR_FAIL_INDEX_V(nprops[j].value, prop_count, nullptr); if (snames[nprops[j].name] == CoreStringNames::get_singleton()->_script) { //work around to avoid old script variables from disappearing, should be the proper fix to: @@ -260,7 +260,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const { //groups for (int j = 0; j < n.groups.size(); j++) { - ERR_FAIL_INDEX_V(n.groups[j], sname_count, NULL); + ERR_FAIL_INDEX_V(n.groups[j], sname_count, nullptr); node->add_to_group(snames[n.groups[j]], true); } @@ -315,8 +315,8 @@ Node *SceneState::instance(GenEditState p_edit_state) const { for (int i = 0; i < cc; i++) { const ConnectionData &c = cdata[i]; - //ERR_FAIL_INDEX_V( c.from, nc, NULL ); - //ERR_FAIL_INDEX_V( c.to, nc, NULL ); + //ERR_FAIL_INDEX_V( c.from, nc, nullptr ); + //ERR_FAIL_INDEX_V( c.to, nc, nullptr ); NODE_FROM_ID(cfrom, c.from); NODE_FROM_ID(cto, c.to); @@ -450,7 +450,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map nd.instance = _vm_get_variant(instance, variant_map); } } - n = NULL; + n = nullptr; } else { if (n->get_filename() != String()) { //is an instance @@ -773,7 +773,7 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName } } - nl = NULL; + nl = nullptr; } else { if (nl->get_filename() != String()) { //is an instance @@ -896,7 +896,7 @@ Error SceneState::pack(Node *p_scene) { } variants.resize(variant_map.size()); - const Variant *K = NULL; + const Variant *K = nullptr; while ((K = variant_map.next(K))) { int idx = variant_map[*K]; @@ -1689,12 +1689,12 @@ bool PackedScene::can_instance() const { Node *PackedScene::instance(GenEditState p_edit_state) const { #ifndef TOOLS_ENABLED - ERR_FAIL_COND_V_MSG(p_edit_state != GEN_EDIT_STATE_DISABLED, NULL, "Edit state is only for editors, does not work without tools compiled."); + ERR_FAIL_COND_V_MSG(p_edit_state != GEN_EDIT_STATE_DISABLED, nullptr, "Edit state is only for editors, does not work without tools compiled."); #endif Node *s = state->instance((SceneState::GenEditState)p_edit_state); if (!s) - return NULL; + return nullptr; if (p_edit_state != GEN_EDIT_STATE_DISABLED) { s->set_scene_instance_state(state); diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp index f18e8956f1..83430aef9e 100644 --- a/scene/resources/particles_material.cpp +++ b/scene/resources/particles_material.cpp @@ -31,9 +31,9 @@ #include "particles_material.h" Mutex ParticlesMaterial::material_mutex; -SelfList<ParticlesMaterial>::List *ParticlesMaterial::dirty_materials = NULL; +SelfList<ParticlesMaterial>::List *ParticlesMaterial::dirty_materials = nullptr; Map<ParticlesMaterial::MaterialKey, ParticlesMaterial::ShaderData> ParticlesMaterial::shader_map; -ParticlesMaterial::ShaderNames *ParticlesMaterial::shader_names = NULL; +ParticlesMaterial::ShaderNames *ParticlesMaterial::shader_names = nullptr; void ParticlesMaterial::init_shaders() { @@ -104,7 +104,7 @@ void ParticlesMaterial::init_shaders() { void ParticlesMaterial::finish_shaders() { memdelete(dirty_materials); - dirty_materials = NULL; + dirty_materials = nullptr; memdelete(shader_names); } @@ -121,7 +121,7 @@ void ParticlesMaterial::_update_shader() { 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); + RS::get_singleton()->free(shader_map[current_key].shader); shader_map.erase(current_key); } } @@ -130,7 +130,7 @@ void ParticlesMaterial::_update_shader() { if (shader_map.has(mk)) { - VS::get_singleton()->material_set_shader(_get_material(), shader_map[mk].shader); + RS::get_singleton()->material_set_shader(_get_material(), shader_map[mk].shader); shader_map[mk].users++; return; } @@ -592,14 +592,14 @@ void ParticlesMaterial::_update_shader() { code += "\n"; ShaderData shader_data; - shader_data.shader = VS::get_singleton()->shader_create(); + shader_data.shader = RS::get_singleton()->shader_create(); shader_data.users = 1; - VS::get_singleton()->shader_set_code(shader_data.shader, code); + RS::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); + RS::get_singleton()->material_set_shader(_get_material(), shader_data.shader); } void ParticlesMaterial::flush_changes() { @@ -631,7 +631,7 @@ bool ParticlesMaterial::_is_shader_dirty() const { void ParticlesMaterial::set_direction(Vector3 p_direction) { direction = p_direction; - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->direction, direction); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->direction, direction); } Vector3 ParticlesMaterial::get_direction() const { @@ -642,7 +642,7 @@ Vector3 ParticlesMaterial::get_direction() const { void ParticlesMaterial::set_spread(float p_spread) { spread = p_spread; - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->spread, p_spread); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->spread, p_spread); } float ParticlesMaterial::get_spread() const { @@ -653,7 +653,7 @@ float ParticlesMaterial::get_spread() const { void ParticlesMaterial::set_flatness(float p_flatness) { flatness = p_flatness; - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->flatness, p_flatness); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->flatness, p_flatness); } float ParticlesMaterial::get_flatness() const { @@ -668,40 +668,40 @@ void ParticlesMaterial::set_param(Parameter p_param, float p_value) { switch (p_param) { case PARAM_INITIAL_LINEAR_VELOCITY: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->initial_linear_velocity, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->initial_linear_velocity, p_value); } break; case PARAM_ANGULAR_VELOCITY: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->angular_velocity, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angular_velocity, p_value); } break; case PARAM_ORBIT_VELOCITY: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->orbit_velocity, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->orbit_velocity, p_value); } break; case PARAM_LINEAR_ACCEL: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->linear_accel, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->linear_accel, p_value); } break; case PARAM_RADIAL_ACCEL: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_accel, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_accel, p_value); } break; case PARAM_TANGENTIAL_ACCEL: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->tangent_accel, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->tangent_accel, p_value); } break; case PARAM_DAMPING: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->damping, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->damping, p_value); } break; case PARAM_ANGLE: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->initial_angle, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->initial_angle, p_value); } break; case PARAM_SCALE: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->scale, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->scale, p_value); } break; case PARAM_HUE_VARIATION: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->hue_variation, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->hue_variation, p_value); } break; case PARAM_ANIM_SPEED: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_speed, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_speed, p_value); } break; case PARAM_ANIM_OFFSET: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset, p_value); } break; case PARAM_MAX: break; // Can't happen, but silences warning } @@ -721,40 +721,40 @@ void ParticlesMaterial::set_param_randomness(Parameter p_param, float p_value) { switch (p_param) { case PARAM_INITIAL_LINEAR_VELOCITY: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->initial_linear_velocity_random, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->initial_linear_velocity_random, p_value); } break; case PARAM_ANGULAR_VELOCITY: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->angular_velocity_random, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angular_velocity_random, p_value); } break; case PARAM_ORBIT_VELOCITY: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->orbit_velocity_random, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->orbit_velocity_random, p_value); } break; case PARAM_LINEAR_ACCEL: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->linear_accel_random, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->linear_accel_random, p_value); } break; case PARAM_RADIAL_ACCEL: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_accel_random, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_accel_random, p_value); } break; case PARAM_TANGENTIAL_ACCEL: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->tangent_accel_random, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->tangent_accel_random, p_value); } break; case PARAM_DAMPING: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->damping_random, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->damping_random, p_value); } break; case PARAM_ANGLE: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->initial_angle_random, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->initial_angle_random, p_value); } break; case PARAM_SCALE: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_random, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_random, p_value); } break; case PARAM_HUE_VARIATION: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->hue_variation_random, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->hue_variation_random, p_value); } break; case PARAM_ANIM_SPEED: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_speed_random, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_speed_random, p_value); } break; case PARAM_ANIM_OFFSET: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_random, p_value); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_random, p_value); } break; case PARAM_MAX: break; // Can't happen, but silences warning } @@ -786,47 +786,47 @@ void ParticlesMaterial::set_param_texture(Parameter p_param, const Ref<Texture2D //do none for this one } break; case PARAM_ANGULAR_VELOCITY: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->angular_velocity_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angular_velocity_texture, p_texture); _adjust_curve_range(p_texture, -360, 360); } break; case PARAM_ORBIT_VELOCITY: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->orbit_velocity_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->orbit_velocity_texture, p_texture); _adjust_curve_range(p_texture, -500, 500); } break; case PARAM_LINEAR_ACCEL: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->linear_accel_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->linear_accel_texture, p_texture); _adjust_curve_range(p_texture, -200, 200); } break; case PARAM_RADIAL_ACCEL: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_accel_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_accel_texture, p_texture); _adjust_curve_range(p_texture, -200, 200); } break; case PARAM_TANGENTIAL_ACCEL: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->tangent_accel_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->tangent_accel_texture, p_texture); _adjust_curve_range(p_texture, -200, 200); } break; case PARAM_DAMPING: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->damping_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->damping_texture, p_texture); _adjust_curve_range(p_texture, 0, 100); } break; case PARAM_ANGLE: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->angle_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angle_texture, p_texture); _adjust_curve_range(p_texture, -360, 360); } break; case PARAM_SCALE: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_texture, p_texture); _adjust_curve_range(p_texture, 0, 1); } break; case PARAM_HUE_VARIATION: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->hue_variation_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->hue_variation_texture, p_texture); _adjust_curve_range(p_texture, -1, 1); } break; case PARAM_ANIM_SPEED: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_speed_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_speed_texture, p_texture); _adjust_curve_range(p_texture, 0, 200); } break; case PARAM_ANIM_OFFSET: { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_texture, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_texture, p_texture); } break; case PARAM_MAX: break; // Can't happen, but silences warning } @@ -842,7 +842,7 @@ Ref<Texture2D> ParticlesMaterial::get_param_texture(Parameter p_param) const { void ParticlesMaterial::set_color(const Color &p_color) { - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->color, p_color); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->color, p_color); color = p_color; } @@ -854,7 +854,7 @@ Color ParticlesMaterial::get_color() const { void ParticlesMaterial::set_color_ramp(const Ref<Texture2D> &p_texture) { color_ramp = p_texture; - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->color_ramp, p_texture); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->color_ramp, p_texture); _queue_shader_change(); _change_notify(); } @@ -888,38 +888,38 @@ void ParticlesMaterial::set_emission_shape(EmissionShape p_shape) { void ParticlesMaterial::set_emission_sphere_radius(float p_radius) { emission_sphere_radius = p_radius; - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_sphere_radius, p_radius); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_sphere_radius, p_radius); } void ParticlesMaterial::set_emission_box_extents(Vector3 p_extents) { emission_box_extents = p_extents; - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_box_extents, p_extents); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_box_extents, p_extents); } void ParticlesMaterial::set_emission_point_texture(const Ref<Texture2D> &p_points) { emission_point_texture = p_points; - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_points, p_points); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_points, p_points); } void ParticlesMaterial::set_emission_normal_texture(const Ref<Texture2D> &p_normals) { emission_normal_texture = p_normals; - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_normal, p_normals); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_normal, p_normals); } void ParticlesMaterial::set_emission_color_texture(const Ref<Texture2D> &p_colors) { emission_color_texture = p_colors; - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_color, p_colors); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_color, p_colors); _queue_shader_change(); } void ParticlesMaterial::set_emission_point_count(int p_count) { emission_point_count = p_count; - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_point_count, p_count); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_point_count, p_count); } ParticlesMaterial::EmissionShape ParticlesMaterial::get_emission_shape() const { @@ -957,7 +957,7 @@ int ParticlesMaterial::get_emission_point_count() const { void ParticlesMaterial::set_trail_divisor(int p_divisor) { trail_divisor = p_divisor; - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->trail_divisor, p_divisor); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->trail_divisor, p_divisor); } int ParticlesMaterial::get_trail_divisor() const { @@ -974,7 +974,7 @@ void ParticlesMaterial::set_trail_size_modifier(const Ref<CurveTexture> &p_trail curve->ensure_default_setup(); } - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->trail_size_modifier, curve); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->trail_size_modifier, curve); _queue_shader_change(); } @@ -986,7 +986,7 @@ Ref<CurveTexture> ParticlesMaterial::get_trail_size_modifier() const { void ParticlesMaterial::set_trail_color_modifier(const Ref<GradientTexture> &p_trail_color_modifier) { trail_color_modifier = p_trail_color_modifier; - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->trail_color_modifier, p_trail_color_modifier); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->trail_color_modifier, p_trail_color_modifier); _queue_shader_change(); } @@ -1002,7 +1002,7 @@ void ParticlesMaterial::set_gravity(const Vector3 &p_gravity) { if (gset == Vector3()) { gset = Vector3(0, -0.000001, 0); //as gravity is used as upvector in some calculations } - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->gravity, gset); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->gravity, gset); } Vector3 ParticlesMaterial::get_gravity() const { @@ -1013,7 +1013,7 @@ Vector3 ParticlesMaterial::get_gravity() const { void ParticlesMaterial::set_lifetime_randomness(float p_lifetime) { lifetime_randomness = p_lifetime; - VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->lifetime_randomness, lifetime_randomness); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->lifetime_randomness, lifetime_randomness); } float ParticlesMaterial::get_lifetime_randomness() const { @@ -1280,10 +1280,10 @@ ParticlesMaterial::~ParticlesMaterial() { 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); + RS::get_singleton()->free(shader_map[current_key].shader); shader_map.erase(current_key); } - VS::get_singleton()->material_set_shader(_get_material(), RID()); + RS::get_singleton()->material_set_shader(_get_material(), RID()); } } diff --git a/scene/resources/physics_material.h b/scene/resources/physics_material.h index 2f7f4424b2..f4a77d9854 100644 --- a/scene/resources/physics_material.h +++ b/scene/resources/physics_material.h @@ -32,7 +32,7 @@ #define physics_material_override_H #include "core/resource.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" class PhysicsMaterial : public Resource { diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp index eff0721cef..c3daedf918 100644 --- a/scene/resources/polygon_path_finder.cpp +++ b/scene/resources/polygon_path_finder.cpp @@ -42,7 +42,7 @@ bool PolygonPathFinder::_is_point_inside(const Vector2 &p_point) const { Vector2 a = points[e.points[0]].pos; Vector2 b = points[e.points[1]].pos; - if (Geometry::segment_intersects_segment_2d(a, b, p_point, outside_point, NULL)) { + if (Geometry::segment_intersects_segment_2d(a, b, p_point, outside_point, nullptr)) { crosses++; } } @@ -119,7 +119,7 @@ void PolygonPathFinder::setup(const Vector<Vector2> &p_points, const Vector<int> Vector2 a = points[e.points[0]].pos; Vector2 b = points[e.points[1]].pos; - if (Geometry::segment_intersects_segment_2d(a, b, from, to, NULL)) { + if (Geometry::segment_intersects_segment_2d(a, b, from, to, nullptr)) { valid = false; break; } @@ -209,7 +209,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector Vector2 a = points[e.points[0]].pos; Vector2 b = points[e.points[1]].pos; - if (Geometry::segment_intersects_segment_2d(a, b, from, to, NULL)) { + if (Geometry::segment_intersects_segment_2d(a, b, from, to, nullptr)) { can_see_eachother = false; break; } @@ -268,7 +268,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector e.points[0] != ignore_from_edge.points[0] && e.points[1] != ignore_from_edge.points[0]) { - if (Geometry::segment_intersects_segment_2d(a, b, from, points[i].pos, NULL)) { + if (Geometry::segment_intersects_segment_2d(a, b, from, points[i].pos, nullptr)) { valid_a = false; } } @@ -281,7 +281,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector e.points[0] != ignore_to_edge.points[0] && e.points[1] != ignore_to_edge.points[0]) { - if (Geometry::segment_intersects_segment_2d(a, b, to, points[i].pos, NULL)) { + if (Geometry::segment_intersects_segment_2d(a, b, to, points[i].pos, nullptr)) { valid_b = false; } } diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index 959ee214a2..46e8575018 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "primitive_meshes.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" /** PrimitiveMesh @@ -37,10 +37,10 @@ void PrimitiveMesh::_update() const { Array arr; - arr.resize(VS::ARRAY_MAX); + arr.resize(RS::ARRAY_MAX); _create_mesh_array(arr); - Vector<Vector3> points = arr[VS::ARRAY_VERTEX]; + Vector<Vector3> points = arr[RS::ARRAY_VERTEX]; aabb = AABB(); @@ -57,10 +57,10 @@ void PrimitiveMesh::_update() const { } } - Vector<int> indices = arr[VS::ARRAY_INDEX]; + Vector<int> indices = arr[RS::ARRAY_INDEX]; if (flip_faces) { - Vector<Vector3> normals = arr[VS::ARRAY_NORMAL]; + Vector<Vector3> normals = arr[RS::ARRAY_NORMAL]; if (normals.size() && indices.size()) { @@ -79,17 +79,17 @@ void PrimitiveMesh::_update() const { SWAP(w[i + 0], w[i + 1]); } } - arr[VS::ARRAY_NORMAL] = normals; - arr[VS::ARRAY_INDEX] = indices; + arr[RS::ARRAY_NORMAL] = normals; + arr[RS::ARRAY_INDEX] = indices; } } array_len = pc; index_array_len = indices.size(); // in with the new - VisualServer::get_singleton()->mesh_clear(mesh); - VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh, (VisualServer::PrimitiveType)primitive_type, arr); - VisualServer::get_singleton()->mesh_surface_set_material(mesh, 0, material.is_null() ? RID() : material->get_rid()); + RenderingServer::get_singleton()->mesh_clear(mesh); + RenderingServer::get_singleton()->mesh_add_surface_from_arrays(mesh, (RenderingServer::PrimitiveType)primitive_type, arr); + RenderingServer::get_singleton()->mesh_surface_set_material(mesh, 0, material.is_null() ? RID() : material->get_rid()); pending_request = false; @@ -136,7 +136,7 @@ Array PrimitiveMesh::surface_get_arrays(int p_surface) const { _update(); } - return VisualServer::get_singleton()->mesh_surface_get_arrays(mesh, 0); + return RenderingServer::get_singleton()->mesh_surface_get_arrays(mesh, 0); } Dictionary PrimitiveMesh::surface_get_lods(int p_surface) const { @@ -150,7 +150,7 @@ Array PrimitiveMesh::surface_get_blend_shape_arrays(int p_surface) const { uint32_t PrimitiveMesh::surface_get_format(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, 1, 0); - return VS::ARRAY_FORMAT_VERTEX | VS::ARRAY_FORMAT_NORMAL | VS::ARRAY_FORMAT_TANGENT | VS::ARRAY_FORMAT_TEX_UV | VS::ARRAY_FORMAT_INDEX | VS::ARRAY_COMPRESS_DEFAULT; + return RS::ARRAY_FORMAT_VERTEX | RS::ARRAY_FORMAT_NORMAL | RS::ARRAY_FORMAT_TANGENT | RS::ARRAY_FORMAT_TEX_UV | RS::ARRAY_FORMAT_INDEX | RS::ARRAY_COMPRESS_DEFAULT; } Mesh::PrimitiveType PrimitiveMesh::surface_get_primitive_type(int p_idx) const { @@ -164,7 +164,7 @@ void PrimitiveMesh::surface_set_material(int p_idx, const Ref<Material> &p_mater } Ref<Material> PrimitiveMesh::surface_get_material(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, 1, NULL); + ERR_FAIL_INDEX_V(p_idx, 1, nullptr); return material; } @@ -215,7 +215,7 @@ void PrimitiveMesh::set_material(const Ref<Material> &p_material) { material = p_material; if (!pending_request) { // just apply it, else it'll happen when _update is called. - VisualServer::get_singleton()->mesh_surface_set_material(mesh, 0, material.is_null() ? RID() : material->get_rid()); + RenderingServer::get_singleton()->mesh_surface_set_material(mesh, 0, material.is_null() ? RID() : material->get_rid()); _change_notify(); emit_changed(); }; @@ -232,7 +232,7 @@ Array PrimitiveMesh::get_mesh_arrays() const { void PrimitiveMesh::set_custom_aabb(const AABB &p_custom) { custom_aabb = p_custom; - VS::get_singleton()->mesh_set_custom_aabb(mesh, custom_aabb); + RS::get_singleton()->mesh_set_custom_aabb(mesh, custom_aabb); emit_changed(); } @@ -254,7 +254,7 @@ PrimitiveMesh::PrimitiveMesh() { flip_faces = false; // defaults - mesh = VisualServer::get_singleton()->mesh_create(); + mesh = RenderingServer::get_singleton()->mesh_create(); // assume primitive triangles as the type, correct for all but one and it will change this :) primitive_type = Mesh::PRIMITIVE_TRIANGLES; @@ -267,7 +267,7 @@ PrimitiveMesh::PrimitiveMesh() { } PrimitiveMesh::~PrimitiveMesh() { - VisualServer::get_singleton()->free(mesh); + RenderingServer::get_singleton()->free(mesh); } /** @@ -413,11 +413,11 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const { thisrow = point; }; - p_arr[VS::ARRAY_VERTEX] = points; - p_arr[VS::ARRAY_NORMAL] = normals; - p_arr[VS::ARRAY_TANGENT] = tangents; - p_arr[VS::ARRAY_TEX_UV] = uvs; - p_arr[VS::ARRAY_INDEX] = indices; + p_arr[RS::ARRAY_VERTEX] = points; + p_arr[RS::ARRAY_NORMAL] = normals; + p_arr[RS::ARRAY_TANGENT] = tangents; + p_arr[RS::ARRAY_TEX_UV] = uvs; + p_arr[RS::ARRAY_INDEX] = indices; } void CapsuleMesh::_bind_methods() { @@ -670,11 +670,11 @@ void CubeMesh::_create_mesh_array(Array &p_arr) const { thisrow = point; }; - p_arr[VS::ARRAY_VERTEX] = points; - p_arr[VS::ARRAY_NORMAL] = normals; - p_arr[VS::ARRAY_TANGENT] = tangents; - p_arr[VS::ARRAY_TEX_UV] = uvs; - p_arr[VS::ARRAY_INDEX] = indices; + p_arr[RS::ARRAY_VERTEX] = points; + p_arr[RS::ARRAY_NORMAL] = normals; + p_arr[RS::ARRAY_TANGENT] = tangents; + p_arr[RS::ARRAY_TEX_UV] = uvs; + p_arr[RS::ARRAY_INDEX] = indices; } void CubeMesh::_bind_methods() { @@ -871,11 +871,11 @@ void CylinderMesh::_create_mesh_array(Array &p_arr) const { }; }; - p_arr[VS::ARRAY_VERTEX] = points; - p_arr[VS::ARRAY_NORMAL] = normals; - p_arr[VS::ARRAY_TANGENT] = tangents; - p_arr[VS::ARRAY_TEX_UV] = uvs; - p_arr[VS::ARRAY_INDEX] = indices; + p_arr[RS::ARRAY_VERTEX] = points; + p_arr[RS::ARRAY_NORMAL] = normals; + p_arr[RS::ARRAY_TANGENT] = tangents; + p_arr[RS::ARRAY_TEX_UV] = uvs; + p_arr[RS::ARRAY_INDEX] = indices; } void CylinderMesh::_bind_methods() { @@ -1010,11 +1010,11 @@ void PlaneMesh::_create_mesh_array(Array &p_arr) const { thisrow = point; }; - p_arr[VS::ARRAY_VERTEX] = points; - p_arr[VS::ARRAY_NORMAL] = normals; - p_arr[VS::ARRAY_TANGENT] = tangents; - p_arr[VS::ARRAY_TEX_UV] = uvs; - p_arr[VS::ARRAY_INDEX] = indices; + p_arr[RS::ARRAY_VERTEX] = points; + p_arr[RS::ARRAY_NORMAL] = normals; + p_arr[RS::ARRAY_TANGENT] = tangents; + p_arr[RS::ARRAY_TEX_UV] = uvs; + p_arr[RS::ARRAY_INDEX] = indices; } void PlaneMesh::_bind_methods() { @@ -1270,11 +1270,11 @@ void PrismMesh::_create_mesh_array(Array &p_arr) const { thisrow = point; }; - p_arr[VS::ARRAY_VERTEX] = points; - p_arr[VS::ARRAY_NORMAL] = normals; - p_arr[VS::ARRAY_TANGENT] = tangents; - p_arr[VS::ARRAY_TEX_UV] = uvs; - p_arr[VS::ARRAY_INDEX] = indices; + p_arr[RS::ARRAY_VERTEX] = points; + p_arr[RS::ARRAY_NORMAL] = normals; + p_arr[RS::ARRAY_TANGENT] = tangents; + p_arr[RS::ARRAY_TEX_UV] = uvs; + p_arr[RS::ARRAY_INDEX] = indices; } void PrismMesh::_bind_methods() { @@ -1401,10 +1401,10 @@ void QuadMesh::_create_mesh_array(Array &p_arr) const { uvs.set(i, quad_uv[j]); } - p_arr[VS::ARRAY_VERTEX] = faces; - p_arr[VS::ARRAY_NORMAL] = normals; - p_arr[VS::ARRAY_TANGENT] = tangents; - p_arr[VS::ARRAY_TEX_UV] = uvs; + p_arr[RS::ARRAY_VERTEX] = faces; + p_arr[RS::ARRAY_NORMAL] = normals; + p_arr[RS::ARRAY_TANGENT] = tangents; + p_arr[RS::ARRAY_TEX_UV] = uvs; } void QuadMesh::_bind_methods() { @@ -1494,11 +1494,11 @@ void SphereMesh::_create_mesh_array(Array &p_arr) const { thisrow = point; }; - p_arr[VS::ARRAY_VERTEX] = points; - p_arr[VS::ARRAY_NORMAL] = normals; - p_arr[VS::ARRAY_TANGENT] = tangents; - p_arr[VS::ARRAY_TEX_UV] = uvs; - p_arr[VS::ARRAY_INDEX] = indices; + p_arr[RS::ARRAY_VERTEX] = points; + p_arr[RS::ARRAY_NORMAL] = normals; + p_arr[RS::ARRAY_TANGENT] = tangents; + p_arr[RS::ARRAY_TEX_UV] = uvs; + p_arr[RS::ARRAY_INDEX] = indices; } void SphereMesh::_bind_methods() { @@ -1585,7 +1585,7 @@ void PointMesh::_create_mesh_array(Array &p_arr) const { faces.resize(1); faces.set(0, Vector3(0.0, 0.0, 0.0)); - p_arr[VS::ARRAY_VERTEX] = faces; + p_arr[RS::ARRAY_VERTEX] = faces; } PointMesh::PointMesh() { diff --git a/scene/resources/ray_shape.cpp b/scene/resources/ray_shape_3d.cpp index 906abaf60c..0211c55f46 100644 --- a/scene/resources/ray_shape.cpp +++ b/scene/resources/ray_shape_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* ray_shape.cpp */ +/* ray_shape_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,11 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "ray_shape.h" +#include "ray_shape_3d.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" -Vector<Vector3> RayShape::get_debug_mesh_lines() { +Vector<Vector3> RayShape3D::get_debug_mesh_lines() { Vector<Vector3> points; points.push_back(Vector3()); @@ -41,20 +41,20 @@ Vector<Vector3> RayShape::get_debug_mesh_lines() { return points; } -real_t RayShape::get_enclosing_radius() const { +real_t RayShape3D::get_enclosing_radius() const { return length; } -void RayShape::_update_shape() { +void RayShape3D::_update_shape() { Dictionary d; d["length"] = length; d["slips_on_slope"] = slips_on_slope; - PhysicsServer::get_singleton()->shape_set_data(get_shape(), d); - Shape::_update_shape(); + PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), d); + Shape3D::_update_shape(); } -void RayShape::set_length(float p_length) { +void RayShape3D::set_length(float p_length) { length = p_length; _update_shape(); @@ -62,12 +62,12 @@ void RayShape::set_length(float p_length) { _change_notify("length"); } -float RayShape::get_length() const { +float RayShape3D::get_length() const { return length; } -void RayShape::set_slips_on_slope(bool p_active) { +void RayShape3D::set_slips_on_slope(bool p_active) { slips_on_slope = p_active; _update_shape(); @@ -75,24 +75,24 @@ void RayShape::set_slips_on_slope(bool p_active) { _change_notify("slips_on_slope"); } -bool RayShape::get_slips_on_slope() const { +bool RayShape3D::get_slips_on_slope() const { return slips_on_slope; } -void RayShape::_bind_methods() { +void RayShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_length", "length"), &RayShape::set_length); - ClassDB::bind_method(D_METHOD("get_length"), &RayShape::get_length); + ClassDB::bind_method(D_METHOD("set_length", "length"), &RayShape3D::set_length); + ClassDB::bind_method(D_METHOD("get_length"), &RayShape3D::get_length); - ClassDB::bind_method(D_METHOD("set_slips_on_slope", "active"), &RayShape::set_slips_on_slope); - ClassDB::bind_method(D_METHOD("get_slips_on_slope"), &RayShape::get_slips_on_slope); + ClassDB::bind_method(D_METHOD("set_slips_on_slope", "active"), &RayShape3D::set_slips_on_slope); + ClassDB::bind_method(D_METHOD("get_slips_on_slope"), &RayShape3D::get_slips_on_slope); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "length", PROPERTY_HINT_RANGE, "0,4096,0.01"), "set_length", "get_length"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "slips_on_slope"), "set_slips_on_slope", "get_slips_on_slope"); } -RayShape::RayShape() : - Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_RAY)) { +RayShape3D::RayShape3D() : + Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_RAY)) { length = 1.0; slips_on_slope = false; diff --git a/scene/resources/ray_shape.h b/scene/resources/ray_shape_3d.h index c89705ad7d..83bb71cca3 100644 --- a/scene/resources/ray_shape.h +++ b/scene/resources/ray_shape_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* ray_shape.h */ +/* ray_shape_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -30,11 +30,11 @@ #ifndef RAY_SHAPE_H #define RAY_SHAPE_H -#include "scene/resources/shape.h" +#include "scene/resources/shape_3d.h" -class RayShape : public Shape { +class RayShape3D : public Shape3D { - GDCLASS(RayShape, Shape); + GDCLASS(RayShape3D, Shape3D); float length; bool slips_on_slope; @@ -52,6 +52,6 @@ public: virtual Vector<Vector3> get_debug_mesh_lines(); virtual real_t get_enclosing_radius() const; - RayShape(); + RayShape3D(); }; #endif // RAY_SHAPE_H diff --git a/scene/resources/rectangle_shape_2d.cpp b/scene/resources/rectangle_shape_2d.cpp index f8c8ffb289..19e72a65b0 100644 --- a/scene/resources/rectangle_shape_2d.cpp +++ b/scene/resources/rectangle_shape_2d.cpp @@ -30,11 +30,11 @@ #include "rectangle_shape_2d.h" -#include "servers/physics_2d_server.h" -#include "servers/visual_server.h" +#include "servers/physics_server_2d.h" +#include "servers/rendering_server.h" void RectangleShape2D::_update_shape() { - Physics2DServer::get_singleton()->shape_set_data(get_rid(), extents); + PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), extents); emit_changed(); } @@ -51,7 +51,7 @@ Vector2 RectangleShape2D::get_extents() const { void RectangleShape2D::draw(const RID &p_to_rid, const Color &p_color) { - VisualServer::get_singleton()->canvas_item_add_rect(p_to_rid, Rect2(-extents, extents * 2.0), p_color); + RenderingServer::get_singleton()->canvas_item_add_rect(p_to_rid, Rect2(-extents, extents * 2.0), p_color); } Rect2 RectangleShape2D::get_rect() const { @@ -72,7 +72,7 @@ void RectangleShape2D::_bind_methods() { } RectangleShape2D::RectangleShape2D() : - Shape2D(Physics2DServer::get_singleton()->rectangle_shape_create()) { + Shape2D(PhysicsServer2D::get_singleton()->rectangle_shape_create()) { extents = Vector2(10, 10); _update_shape(); diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index 238bdf05ef..41146036f6 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -120,18 +120,23 @@ Error ResourceLoaderText::_parse_sub_resource(VariantParser::Stream *p_stream, R int index = token.value; - String path = local_path + "::" + itos(index); + if (use_nocache) { + r_res = int_resources[index]; + } else { - if (!ignore_resource_parsing) { + String path = local_path + "::" + itos(index); - if (!ResourceCache::has(path)) { - r_err_str = "Can't load cached sub-resource: " + path; - return ERR_PARSE_ERROR; - } + if (!ignore_resource_parsing) { - r_res = RES(ResourceCache::get(path)); - } else { - r_res = RES(); + if (!ResourceCache::has(path)) { + r_err_str = "Can't load cached sub-resource: " + path; + return ERR_PARSE_ERROR; + } + + r_res = RES(ResourceCache::get(path)); + } else { + r_res = RES(); + } } VariantParser::get_token(p_stream, token, line, r_err_str); @@ -535,7 +540,7 @@ Error ResourceLoaderText::load() { Ref<Resource> res; - if (!ResourceCache::has(path)) { //only if it doesn't exist + if (use_nocache || !ResourceCache::has(path)) { //only if it doesn't exist Object *obj = ClassDB::instance(type); if (!obj) { @@ -556,8 +561,10 @@ Error ResourceLoaderText::load() { } res = Ref<Resource>(r); - resource_cache.push_back(res); - res->set_path(path); + int_resources[id] = res; + if (!use_nocache) { + res->set_path(path); + } } resource_current++; @@ -643,10 +650,12 @@ Error ResourceLoaderText::load() { _printerr(); } else { error = OK; - if (!ResourceCache::has(res_path)) { - resource->set_path(res_path); + if (!use_nocache) { + if (!ResourceCache::has(res_path)) { + resource->set_path(res_path); + } + resource->set_as_translation_remapped(translation_remapped); } - resource->set_as_translation_remapped(translation_remapped); } return error; } @@ -691,7 +700,7 @@ Error ResourceLoaderText::load() { error = OK; //get it here resource = packed_scene; - if (!ResourceCache::has(res_path)) { + if (!use_nocache && !ResourceCache::has(res_path)) { packed_scene->set_path(res_path); } @@ -725,6 +734,9 @@ void ResourceLoaderText::set_translation_remapped(bool p_remapped) { } ResourceLoaderText::ResourceLoaderText() { + + use_nocache = false; + resources_total = 0; resource_current = 0; use_sub_threads = false; @@ -795,7 +807,7 @@ Error ResourceLoaderText::rename_dependencies(FileAccess *p_f, const String &p_p ignore_resource_parsing = true; //FileAccess - FileAccess *fw = NULL; + FileAccess *fw = nullptr; String base_path = local_path.get_base_dir(); @@ -961,7 +973,7 @@ void ResourceLoaderText::open(FileAccess *p_f, bool p_skip_first_tag) { rp.ext_func = _parse_ext_resources; rp.sub_func = _parse_sub_resources; - rp.func = NULL; + rp.func = nullptr; rp.userdata = this; } @@ -1285,7 +1297,7 @@ String ResourceLoaderText::recognize(FileAccess *p_f) { ///////////////////// -RES ResourceFormatLoaderText::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) { +RES ResourceFormatLoaderText::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { if (r_error) *r_error = ERR_CANT_OPEN; @@ -1298,6 +1310,7 @@ RES ResourceFormatLoaderText::load(const String &p_path, const String &p_origina ResourceLoaderText loader; String path = p_original_path != "" ? p_original_path : p_path; + loader.use_nocache = p_no_cache; loader.use_sub_threads = p_use_sub_threads; loader.local_path = ProjectSettings::get_singleton()->localize_path(path); loader.progress = r_progress; @@ -1392,7 +1405,7 @@ Error ResourceFormatLoaderText::rename_dependencies(const String &p_path, const return loader.rename_dependencies(f, p_path, p_map); } -ResourceFormatLoaderText *ResourceFormatLoaderText::singleton = NULL; +ResourceFormatLoaderText *ResourceFormatLoaderText::singleton = nullptr; Error ResourceFormatLoaderText::convert_file_to_binary(const String &p_src_path, const String &p_dst_path) { @@ -1674,7 +1687,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r RES res = E->get(); ERR_CONTINUE(!resource_set.has(res)); - bool main = (E->next() == NULL); + bool main = (E->next() == nullptr); if (main && packed_scene.is_valid()) break; //save as a scene @@ -1880,7 +1893,7 @@ void ResourceFormatSaverText::get_recognized_extensions(const RES &p_resource, L p_extensions->push_back("tres"); //text resource } -ResourceFormatSaverText *ResourceFormatSaverText::singleton = NULL; +ResourceFormatSaverText *ResourceFormatSaverText::singleton = nullptr; ResourceFormatSaverText::ResourceFormatSaverText() { singleton = this; } diff --git a/scene/resources/resource_format_text.h b/scene/resources/resource_format_text.h index 2425ac7f6c..b9a6db5f36 100644 --- a/scene/resources/resource_format_text.h +++ b/scene/resources/resource_format_text.h @@ -62,6 +62,7 @@ class ResourceLoaderText { //Map<String,String> remaps; Map<int, ExtResource> ext_resources; + Map<int, RES> int_resources; int resources_total; int resource_current; @@ -69,6 +70,8 @@ class ResourceLoaderText { VariantParser::Tag next_tag; + bool use_nocache; + bool use_sub_threads; float *progress; @@ -106,7 +109,6 @@ class ResourceLoaderText { friend class ResourceFormatLoaderText; - List<RES> resource_cache; Error error; RES resource; @@ -134,7 +136,7 @@ public: class ResourceFormatLoaderText : public ResourceFormatLoader { public: static ResourceFormatLoaderText *singleton; - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; diff --git a/scene/resources/segment_shape_2d.cpp b/scene/resources/segment_shape_2d.cpp index 2e78a4fccf..814c349784 100644 --- a/scene/resources/segment_shape_2d.cpp +++ b/scene/resources/segment_shape_2d.cpp @@ -30,8 +30,8 @@ #include "segment_shape_2d.h" -#include "servers/physics_2d_server.h" -#include "servers/visual_server.h" +#include "servers/physics_server_2d.h" +#include "servers/rendering_server.h" bool SegmentShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { @@ -45,7 +45,7 @@ void SegmentShape2D::_update_shape() { Rect2 r; r.position = a; r.size = b; - Physics2DServer::get_singleton()->shape_set_data(get_rid(), r); + PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), r); emit_changed(); } @@ -71,7 +71,7 @@ Vector2 SegmentShape2D::get_b() const { void SegmentShape2D::draw(const RID &p_to_rid, const Color &p_color) { - VisualServer::get_singleton()->canvas_item_add_line(p_to_rid, a, b, p_color, 3); + RenderingServer::get_singleton()->canvas_item_add_line(p_to_rid, a, b, p_color, 3); } Rect2 SegmentShape2D::get_rect() const { @@ -99,7 +99,7 @@ void SegmentShape2D::_bind_methods() { } SegmentShape2D::SegmentShape2D() : - Shape2D(Physics2DServer::get_singleton()->segment_shape_create()) { + Shape2D(PhysicsServer2D::get_singleton()->segment_shape_create()) { a = Vector2(); b = Vector2(0, 10); @@ -113,14 +113,14 @@ void RayShape2D::_update_shape() { Dictionary d; d["length"] = length; d["slips_on_slope"] = slips_on_slope; - Physics2DServer::get_singleton()->shape_set_data(get_rid(), d); + PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), d); emit_changed(); } void RayShape2D::draw(const RID &p_to_rid, const Color &p_color) { Vector2 tip = Vector2(0, get_length()); - VS::get_singleton()->canvas_item_add_line(p_to_rid, Vector2(), tip, p_color, 3); + RS::get_singleton()->canvas_item_add_line(p_to_rid, Vector2(), tip, p_color, 3); Vector<Vector2> pts; float tsize = 4; pts.push_back(tip + Vector2(0, tsize)); @@ -130,7 +130,7 @@ void RayShape2D::draw(const RID &p_to_rid, const Color &p_color) { for (int i = 0; i < 3; i++) cols.push_back(p_color); - VS::get_singleton()->canvas_item_add_primitive(p_to_rid, pts, cols, Vector<Point2>(), RID()); + RS::get_singleton()->canvas_item_add_primitive(p_to_rid, pts, cols, Vector<Point2>(), RID()); } Rect2 RayShape2D::get_rect() const { @@ -179,7 +179,7 @@ bool RayShape2D::get_slips_on_slope() const { } RayShape2D::RayShape2D() : - Shape2D(Physics2DServer::get_singleton()->ray_shape_create()) { + Shape2D(PhysicsServer2D::get_singleton()->ray_shape_create()) { length = 20; slips_on_slope = false; diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index e61a1e6880..1ac2f7c3c9 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -31,8 +31,8 @@ #include "shader.h" #include "core/os/file_access.h" #include "scene/scene_string_names.h" -#include "servers/visual/shader_language.h" -#include "servers/visual_server.h" +#include "servers/rendering/shader_language.h" +#include "servers/rendering_server.h" #include "texture.h" Shader::Mode Shader::get_mode() const { @@ -48,11 +48,13 @@ void Shader::set_code(const String &p_code) { mode = MODE_CANVAS_ITEM; } else if (type == "particles") { mode = MODE_PARTICLES; + } else if (type == "sky") { + mode = MODE_SKY; } else { mode = MODE_SPATIAL; } - VisualServer::get_singleton()->shader_set_code(shader, p_code); + RenderingServer::get_singleton()->shader_set_code(shader, p_code); params_cache_dirty = true; emit_changed(); @@ -61,7 +63,7 @@ void Shader::set_code(const String &p_code) { String Shader::get_code() const { _update_shader(); - return VisualServer::get_singleton()->shader_get_code(shader); + return RenderingServer::get_singleton()->shader_get_code(shader); } void Shader::get_param_list(List<PropertyInfo> *p_params) const { @@ -69,7 +71,7 @@ void Shader::get_param_list(List<PropertyInfo> *p_params) const { _update_shader(); List<PropertyInfo> local; - VisualServer::get_singleton()->shader_get_param_list(shader, &local); + RenderingServer::get_singleton()->shader_get_param_list(shader, &local); params_cache.clear(); params_cache_dirty = false; @@ -102,10 +104,10 @@ void Shader::set_default_texture_param(const StringName &p_param, const Ref<Text if (p_texture.is_valid()) { default_textures[p_param] = p_texture; - VS::get_singleton()->shader_set_default_texture_param(shader, p_param, p_texture->get_rid()); + RS::get_singleton()->shader_set_default_texture_param(shader, p_param, p_texture->get_rid()); } else { default_textures.erase(p_param); - VS::get_singleton()->shader_set_default_texture_param(shader, p_param, RID()); + RS::get_singleton()->shader_set_default_texture_param(shader, p_param, RID()); } emit_changed(); @@ -158,22 +160,23 @@ void Shader::_bind_methods() { BIND_ENUM_CONSTANT(MODE_SPATIAL); BIND_ENUM_CONSTANT(MODE_CANVAS_ITEM); BIND_ENUM_CONSTANT(MODE_PARTICLES); + BIND_ENUM_CONSTANT(MODE_SKY); } Shader::Shader() { mode = MODE_SPATIAL; - shader = VisualServer::get_singleton()->shader_create(); + shader = RenderingServer::get_singleton()->shader_create(); params_cache_dirty = true; } Shader::~Shader() { - VisualServer::get_singleton()->free(shader); + RenderingServer::get_singleton()->free(shader); } //////////// -RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) { +RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { if (r_error) *r_error = ERR_FILE_CANT_OPEN; diff --git a/scene/resources/shader.h b/scene/resources/shader.h index 84908852da..75c38bd561 100644 --- a/scene/resources/shader.h +++ b/scene/resources/shader.h @@ -47,6 +47,7 @@ public: MODE_SPATIAL, MODE_CANVAS_ITEM, MODE_PARTICLES, + MODE_SKY, MODE_MAX }; @@ -55,7 +56,7 @@ private: Mode mode; // hack the name of performance - // shaders keep a list of ShaderMaterial -> VisualServer name translations, to make + // shaders keep a list of ShaderMaterial -> RenderingServer name translations, to make // conversion fast and save memory. mutable bool params_cache_dirty; mutable Map<StringName, StringName> params_cache; //map a shader param to a material param.. @@ -83,7 +84,7 @@ public: _FORCE_INLINE_ StringName remap_param(const StringName &p_param) const { if (params_cache_dirty) - get_param_list(NULL); + get_param_list(nullptr); const Map<StringName, StringName>::Element *E = params_cache.find(p_param); if (E) @@ -101,7 +102,7 @@ VARIANT_ENUM_CAST(Shader::Mode); class ResourceFormatLoaderShader : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/scene/resources/shape_2d.cpp b/scene/resources/shape_2d.cpp index 64930c3117..4fe585053a 100644 --- a/scene/resources/shape_2d.cpp +++ b/scene/resources/shape_2d.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "shape_2d.h" -#include "servers/physics_2d_server.h" +#include "servers/physics_server_2d.h" RID Shape2D::get_rid() const { return shape; @@ -38,7 +38,7 @@ RID Shape2D::get_rid() const { void Shape2D::set_custom_solver_bias(real_t p_bias) { custom_bias = p_bias; - Physics2DServer::get_singleton()->shape_set_custom_solver_bias(shape, custom_bias); + PhysicsServer2D::get_singleton()->shape_set_custom_solver_bias(shape, custom_bias); } real_t Shape2D::get_custom_solver_bias() const { @@ -50,13 +50,13 @@ bool Shape2D::collide_with_motion(const Transform2D &p_local_xform, const Vector ERR_FAIL_COND_V(p_shape.is_null(), false); int r; - return Physics2DServer::get_singleton()->shape_collide(get_rid(), p_local_xform, p_local_motion, p_shape->get_rid(), p_shape_xform, p_shape_motion, NULL, 0, r); + return PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, p_local_motion, p_shape->get_rid(), p_shape_xform, p_shape_motion, nullptr, 0, r); } bool Shape2D::collide(const Transform2D &p_local_xform, const Ref<Shape2D> &p_shape, const Transform2D &p_shape_xform) { ERR_FAIL_COND_V(p_shape.is_null(), false); int r; - return Physics2DServer::get_singleton()->shape_collide(get_rid(), p_local_xform, Vector2(), p_shape->get_rid(), p_shape_xform, Vector2(), NULL, 0, r); + return PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, Vector2(), p_shape->get_rid(), p_shape_xform, Vector2(), nullptr, 0, r); } Array Shape2D::collide_with_motion_and_get_contacts(const Transform2D &p_local_xform, const Vector2 &p_local_motion, const Ref<Shape2D> &p_shape, const Transform2D &p_shape_xform, const Vector2 &p_shape_motion) { @@ -66,7 +66,7 @@ Array Shape2D::collide_with_motion_and_get_contacts(const Transform2D &p_local_x Vector2 result[max_contacts * 2]; int contacts = 0; - if (!Physics2DServer::get_singleton()->shape_collide(get_rid(), p_local_xform, p_local_motion, p_shape->get_rid(), p_shape_xform, p_shape_motion, result, max_contacts, contacts)) + if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, p_local_motion, p_shape->get_rid(), p_shape_xform, p_shape_motion, result, max_contacts, contacts)) return Array(); Array results; @@ -84,7 +84,7 @@ Array Shape2D::collide_and_get_contacts(const Transform2D &p_local_xform, const Vector2 result[max_contacts * 2]; int contacts = 0; - if (!Physics2DServer::get_singleton()->shape_collide(get_rid(), p_local_xform, Vector2(), p_shape->get_rid(), p_shape_xform, Vector2(), result, max_contacts, contacts)) + if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, Vector2(), p_shape->get_rid(), p_shape_xform, Vector2(), result, max_contacts, contacts)) return Array(); Array results; @@ -115,5 +115,5 @@ Shape2D::Shape2D(const RID &p_rid) { Shape2D::~Shape2D() { - Physics2DServer::get_singleton()->free(shape); + PhysicsServer2D::get_singleton()->free(shape); } diff --git a/scene/resources/shape.cpp b/scene/resources/shape_3d.cpp index 4a6da18f2b..f4a5d91e52 100644 --- a/scene/resources/shape.cpp +++ b/scene/resources/shape_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* shape.cpp */ +/* shape_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "shape.h" +#include "shape_3d.h" #include "core/os/os.h" #include "scene/main/scene_tree.h" #include "scene/resources/mesh.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" -void Shape::add_vertices_to_array(Vector<Vector3> &array, const Transform &p_xform) { +void Shape3D::add_vertices_to_array(Vector<Vector3> &array, const Transform &p_xform) { Vector<Vector3> toadd = get_debug_mesh_lines(); @@ -50,16 +50,16 @@ void Shape::add_vertices_to_array(Vector<Vector3> &array, const Transform &p_xfo } } -real_t Shape::get_margin() const { +real_t Shape3D::get_margin() const { return margin; } -void Shape::set_margin(real_t p_margin) { +void Shape3D::set_margin(real_t p_margin) { margin = p_margin; - PhysicsServer::get_singleton()->shape_set_margin(shape, margin); + PhysicsServer3D::get_singleton()->shape_set_margin(shape, margin); } -Ref<ArrayMesh> Shape::get_debug_mesh() { +Ref<ArrayMesh> Shape3D::get_debug_mesh() { if (debug_mesh_cache.is_valid()) return debug_mesh_cache; @@ -96,32 +96,32 @@ Ref<ArrayMesh> Shape::get_debug_mesh() { return debug_mesh_cache; } -void Shape::_update_shape() { +void Shape3D::_update_shape() { emit_changed(); debug_mesh_cache.unref(); } -void Shape::_bind_methods() { +void Shape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_margin", "margin"), &Shape::set_margin); - ClassDB::bind_method(D_METHOD("get_margin"), &Shape::get_margin); + ClassDB::bind_method(D_METHOD("set_margin", "margin"), &Shape3D::set_margin); + ClassDB::bind_method(D_METHOD("get_margin"), &Shape3D::get_margin); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin", PROPERTY_HINT_RANGE, "0.001,10,0.001"), "set_margin", "get_margin"); } -Shape::Shape() : +Shape3D::Shape3D() : margin(0.04) { ERR_PRINT("Constructor must not be called!"); } -Shape::Shape(RID p_shape) : +Shape3D::Shape3D(RID p_shape) : margin(0.04) { shape = p_shape; } -Shape::~Shape() { +Shape3D::~Shape3D() { - PhysicsServer::get_singleton()->free(shape); + PhysicsServer3D::get_singleton()->free(shape); } diff --git a/scene/resources/shape.h b/scene/resources/shape_3d.h index e5ccbf7e28..e7a516412d 100644 --- a/scene/resources/shape.h +++ b/scene/resources/shape_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* shape.h */ +/* shape_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,17 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef SHAPE_H -#define SHAPE_H +#ifndef SHAPE_3D_H +#define SHAPE_3D_H #include "core/resource.h" class ArrayMesh; -class Shape : public Resource { +class Shape3D : public Resource { - GDCLASS(Shape, Resource); - OBJ_SAVE_TYPE(Shape); + GDCLASS(Shape3D, Resource); + OBJ_SAVE_TYPE(Shape3D); RES_BASE_EXTENSION("shape"); RID shape; real_t margin; @@ -49,7 +49,7 @@ protected: static void _bind_methods(); _FORCE_INLINE_ RID get_shape() const { return shape; } - Shape(RID p_shape); + Shape3D(RID p_shape); virtual void _update_shape(); @@ -66,8 +66,8 @@ public: real_t get_margin() const; void set_margin(real_t p_margin); - Shape(); - ~Shape(); + Shape3D(); + ~Shape3D(); }; #endif // SHAPE_H diff --git a/scene/resources/sky.cpp b/scene/resources/sky.cpp index 54648e8af7..cbe86b16b2 100644 --- a/scene/resources/sky.cpp +++ b/scene/resources/sky.cpp @@ -39,7 +39,7 @@ void Sky::set_radiance_size(RadianceSize p_size) { static const int size[RADIANCE_SIZE_MAX] = { 32, 64, 128, 256, 512, 1024, 2048 }; - VS::get_singleton()->sky_set_radiance_size(sky, size[radiance_size]); + RS::get_singleton()->sky_set_radiance_size(sky, size[radiance_size]); } Sky::RadianceSize Sky::get_radiance_size() const { @@ -49,13 +49,25 @@ Sky::RadianceSize Sky::get_radiance_size() const { void Sky::set_process_mode(ProcessMode p_mode) { mode = p_mode; - VS::get_singleton()->sky_set_mode(sky, VS::SkyMode(mode)); + RS::get_singleton()->sky_set_mode(sky, RS::SkyMode(mode)); } Sky::ProcessMode Sky::get_process_mode() const { return mode; } +void Sky::set_material(const Ref<Material> &p_material) { + sky_material = p_material; + RID material_rid; + if (sky_material.is_valid()) + material_rid = sky_material->get_rid(); + RS::get_singleton()->sky_set_material(sky, material_rid); +} + +Ref<Material> Sky::get_material() const { + return sky_material; +} + RID Sky::get_rid() const { return sky; @@ -69,6 +81,10 @@ void Sky::_bind_methods() { ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Sky::set_process_mode); ClassDB::bind_method(D_METHOD("get_process_mode"), &Sky::get_process_mode); + ClassDB::bind_method(D_METHOD("set_material", "material"), &Sky::set_material); + ClassDB::bind_method(D_METHOD("get_material"), &Sky::get_material); + + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "sky_material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,PanoramaSkyMaterial,ProceduralSkyMaterial,PhysicalSkyMaterial"), "set_material", "get_material"); ADD_PROPERTY(PropertyInfo(Variant::INT, "radiance_size", PROPERTY_HINT_ENUM, "32,64,128,256,512,1024,2048"), "set_radiance_size", "get_radiance_size"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "HighQuality,RealTime"), "set_process_mode", "get_process_mode"); @@ -87,500 +103,11 @@ void Sky::_bind_methods() { Sky::Sky() { mode = PROCESS_MODE_QUALITY; - radiance_size = RADIANCE_SIZE_128; - sky = VS::get_singleton()->sky_create(); + radiance_size = RADIANCE_SIZE_256; + sky = RS::get_singleton()->sky_create(); } Sky::~Sky() { - VS::get_singleton()->free(sky); -} - -///////////////////////////////////////// - -void PanoramaSky::set_panorama(const Ref<Texture2D> &p_panorama) { - - panorama = p_panorama; - - RID rid = p_panorama.is_valid() ? p_panorama->get_rid() : RID(); - VS::get_singleton()->sky_set_texture(get_rid(), rid); -} - -Ref<Texture2D> PanoramaSky::get_panorama() const { - - return panorama; -} - -void PanoramaSky::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_panorama", "texture"), &PanoramaSky::set_panorama); - ClassDB::bind_method(D_METHOD("get_panorama"), &PanoramaSky::get_panorama); - - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "panorama", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_panorama", "get_panorama"); -} - -PanoramaSky::PanoramaSky() { -} - -PanoramaSky::~PanoramaSky() { -} -////////////////////////////////// - -Ref<Image> ProceduralSky::_generate_sky() { - - update_queued = false; - - Vector<uint8_t> imgdata; - - static const int size[TEXTURE_SIZE_MAX] = { - 256, 512, 1024, 2048, 4096 - }; - - int w = size[texture_size]; - int h = w / 2; - - imgdata.resize(w * h * 4); //RGBE - - { - uint8_t *dataw = imgdata.ptrw(); - - uint32_t *ptr = (uint32_t *)dataw; - - Color sky_top_linear = sky_top_color.to_linear(); - Color sky_horizon_linear = sky_horizon_color.to_linear(); - - Color ground_bottom_linear = ground_bottom_color.to_linear(); - Color ground_horizon_linear = ground_horizon_color.to_linear(); - - Color sun_linear; - sun_linear.r = sun_color.r * sun_energy; - sun_linear.g = sun_color.g * sun_energy; - sun_linear.b = sun_color.b * sun_energy; - - Vector3 sun(0, 0, -1); - - sun = Basis(Vector3(1, 0, 0), Math::deg2rad(sun_latitude)).xform(sun); - sun = Basis(Vector3(0, 1, 0), Math::deg2rad(sun_longitude)).xform(sun); - - sun.normalize(); - - for (int i = 0; i < w; i++) { - - float u = float(i) / (w - 1); - float phi = u * 2.0 * Math_PI; - - for (int j = 0; j < h; j++) { - - float v = float(j) / (h - 1); - float theta = v * Math_PI; - - Vector3 normal( - Math::sin(phi) * Math::sin(theta) * -1.0, - Math::cos(theta), - Math::cos(phi) * Math::sin(theta) * -1.0); - - normal.normalize(); - - float v_angle = Math::acos(CLAMP(normal.y, -1.0, 1.0)); - - Color color; - - if (normal.y < 0) { - //ground - - float c = (v_angle - (Math_PI * 0.5)) / (Math_PI * 0.5); - color = ground_horizon_linear.linear_interpolate(ground_bottom_linear, Math::ease(c, ground_curve)); - color.r *= ground_energy; - color.g *= ground_energy; - color.b *= ground_energy; - } else { - float c = v_angle / (Math_PI * 0.5); - color = sky_horizon_linear.linear_interpolate(sky_top_linear, Math::ease(1.0 - c, sky_curve)); - color.r *= sky_energy; - color.g *= sky_energy; - color.b *= sky_energy; - - float sun_angle = Math::rad2deg(Math::acos(CLAMP(sun.dot(normal), -1.0, 1.0))); - - if (sun_angle < sun_angle_min) { - color = color.blend(sun_linear); - } else if (sun_angle < sun_angle_max) { - - float c2 = (sun_angle - sun_angle_min) / (sun_angle_max - sun_angle_min); - c2 = Math::ease(c2, sun_curve); - - color = color.blend(sun_linear).linear_interpolate(color, c2); - } - } - - ptr[j * w + i] = color.to_rgbe9995(); - } - } - } - - Ref<Image> image; - image.instance(); - image->create(w, h, false, Image::FORMAT_RGBE9995, imgdata); - - return image; -} - -void ProceduralSky::set_sky_top_color(const Color &p_sky_top) { - - sky_top_color = p_sky_top; - _queue_update(); -} - -Color ProceduralSky::get_sky_top_color() const { - - return sky_top_color; -} - -void ProceduralSky::set_sky_horizon_color(const Color &p_sky_horizon) { - - sky_horizon_color = p_sky_horizon; - _queue_update(); -} -Color ProceduralSky::get_sky_horizon_color() const { - - return sky_horizon_color; -} - -void ProceduralSky::set_sky_curve(float p_curve) { - - sky_curve = p_curve; - _queue_update(); -} -float ProceduralSky::get_sky_curve() const { - - return sky_curve; -} - -void ProceduralSky::set_sky_energy(float p_energy) { - - sky_energy = p_energy; - _queue_update(); -} -float ProceduralSky::get_sky_energy() const { - - return sky_energy; -} - -void ProceduralSky::set_ground_bottom_color(const Color &p_ground_bottom) { - - ground_bottom_color = p_ground_bottom; - _queue_update(); -} -Color ProceduralSky::get_ground_bottom_color() const { - - return ground_bottom_color; -} - -void ProceduralSky::set_ground_horizon_color(const Color &p_ground_horizon) { - - ground_horizon_color = p_ground_horizon; - _queue_update(); -} -Color ProceduralSky::get_ground_horizon_color() const { - - return ground_horizon_color; -} - -void ProceduralSky::set_ground_curve(float p_curve) { - - ground_curve = p_curve; - _queue_update(); -} -float ProceduralSky::get_ground_curve() const { - - return ground_curve; -} - -void ProceduralSky::set_ground_energy(float p_energy) { - - ground_energy = p_energy; - _queue_update(); -} -float ProceduralSky::get_ground_energy() const { - - return ground_energy; -} - -void ProceduralSky::set_sun_color(const Color &p_sun) { - - sun_color = p_sun; - _queue_update(); -} -Color ProceduralSky::get_sun_color() const { - - return sun_color; -} - -void ProceduralSky::set_sun_latitude(float p_angle) { - - sun_latitude = p_angle; - _queue_update(); -} -float ProceduralSky::get_sun_latitude() const { - - return sun_latitude; -} - -void ProceduralSky::set_sun_longitude(float p_angle) { - - sun_longitude = p_angle; - _queue_update(); -} -float ProceduralSky::get_sun_longitude() const { - - return sun_longitude; -} - -void ProceduralSky::set_sun_angle_min(float p_angle) { - - sun_angle_min = p_angle; - _queue_update(); -} -float ProceduralSky::get_sun_angle_min() const { - - return sun_angle_min; -} - -void ProceduralSky::set_sun_angle_max(float p_angle) { - - sun_angle_max = p_angle; - _queue_update(); -} -float ProceduralSky::get_sun_angle_max() const { - - return sun_angle_max; -} - -void ProceduralSky::set_sun_curve(float p_curve) { - - sun_curve = p_curve; - _queue_update(); -} -float ProceduralSky::get_sun_curve() const { - - return sun_curve; -} - -void ProceduralSky::set_sun_energy(float p_energy) { - - sun_energy = p_energy; - _queue_update(); -} -float ProceduralSky::get_sun_energy() const { - - return sun_energy; -} - -void ProceduralSky::set_texture_size(TextureSize p_size) { - ERR_FAIL_INDEX(p_size, TEXTURE_SIZE_MAX); - - texture_size = p_size; - _queue_update(); -} -ProceduralSky::TextureSize ProceduralSky::get_texture_size() const { - return texture_size; -} - -void ProceduralSky::_update_sky() { - - bool use_thread = true; - if (first_time) { - use_thread = false; - first_time = false; - } -#ifdef NO_THREADS - use_thread = false; -#endif - if (use_thread) { - - if (!sky_thread) { - sky_thread = Thread::create(_thread_function, this); - regen_queued = false; - } else { - regen_queued = true; - } - - } else { - Ref<Image> image = _generate_sky(); - if (texture.is_valid()) { - RID new_texture = VS::get_singleton()->texture_2d_create(image); - VS::get_singleton()->texture_replace(texture, new_texture); - } else { - texture = VS::get_singleton()->texture_2d_create(image); - } - VS::get_singleton()->sky_set_texture(get_rid(), texture); - } -} - -void ProceduralSky::_queue_update() { - - if (update_queued) - return; - - update_queued = true; - call_deferred("_update_sky"); -} - -void ProceduralSky::_thread_done(const Ref<Image> &p_image) { - - if (texture.is_valid()) { - RID new_texture = VS::get_singleton()->texture_2d_create(p_image); - VS::get_singleton()->texture_replace(texture, new_texture); - } else { - texture = VS::get_singleton()->texture_2d_create(p_image); - } - - VS::get_singleton()->sky_set_texture(get_rid(), texture); - - Thread::wait_to_finish(sky_thread); - memdelete(sky_thread); - sky_thread = NULL; - if (regen_queued) { - sky_thread = Thread::create(_thread_function, this); - regen_queued = false; - } -} - -void ProceduralSky::_thread_function(void *p_ud) { - - ProceduralSky *psky = (ProceduralSky *)p_ud; - psky->call_deferred("_thread_done", psky->_generate_sky()); -} - -void ProceduralSky::_bind_methods() { - - ClassDB::bind_method(D_METHOD("_update_sky"), &ProceduralSky::_update_sky); - - ClassDB::bind_method(D_METHOD("set_sky_top_color", "color"), &ProceduralSky::set_sky_top_color); - ClassDB::bind_method(D_METHOD("get_sky_top_color"), &ProceduralSky::get_sky_top_color); - - ClassDB::bind_method(D_METHOD("set_sky_horizon_color", "color"), &ProceduralSky::set_sky_horizon_color); - ClassDB::bind_method(D_METHOD("get_sky_horizon_color"), &ProceduralSky::get_sky_horizon_color); - - ClassDB::bind_method(D_METHOD("set_sky_curve", "curve"), &ProceduralSky::set_sky_curve); - ClassDB::bind_method(D_METHOD("get_sky_curve"), &ProceduralSky::get_sky_curve); - - ClassDB::bind_method(D_METHOD("set_sky_energy", "energy"), &ProceduralSky::set_sky_energy); - ClassDB::bind_method(D_METHOD("get_sky_energy"), &ProceduralSky::get_sky_energy); - - ClassDB::bind_method(D_METHOD("set_ground_bottom_color", "color"), &ProceduralSky::set_ground_bottom_color); - ClassDB::bind_method(D_METHOD("get_ground_bottom_color"), &ProceduralSky::get_ground_bottom_color); - - ClassDB::bind_method(D_METHOD("set_ground_horizon_color", "color"), &ProceduralSky::set_ground_horizon_color); - ClassDB::bind_method(D_METHOD("get_ground_horizon_color"), &ProceduralSky::get_ground_horizon_color); - - ClassDB::bind_method(D_METHOD("set_ground_curve", "curve"), &ProceduralSky::set_ground_curve); - ClassDB::bind_method(D_METHOD("get_ground_curve"), &ProceduralSky::get_ground_curve); - - ClassDB::bind_method(D_METHOD("set_ground_energy", "energy"), &ProceduralSky::set_ground_energy); - ClassDB::bind_method(D_METHOD("get_ground_energy"), &ProceduralSky::get_ground_energy); - - ClassDB::bind_method(D_METHOD("set_sun_color", "color"), &ProceduralSky::set_sun_color); - ClassDB::bind_method(D_METHOD("get_sun_color"), &ProceduralSky::get_sun_color); - - ClassDB::bind_method(D_METHOD("set_sun_latitude", "degrees"), &ProceduralSky::set_sun_latitude); - ClassDB::bind_method(D_METHOD("get_sun_latitude"), &ProceduralSky::get_sun_latitude); - - ClassDB::bind_method(D_METHOD("set_sun_longitude", "degrees"), &ProceduralSky::set_sun_longitude); - ClassDB::bind_method(D_METHOD("get_sun_longitude"), &ProceduralSky::get_sun_longitude); - - ClassDB::bind_method(D_METHOD("set_sun_angle_min", "degrees"), &ProceduralSky::set_sun_angle_min); - ClassDB::bind_method(D_METHOD("get_sun_angle_min"), &ProceduralSky::get_sun_angle_min); - - ClassDB::bind_method(D_METHOD("set_sun_angle_max", "degrees"), &ProceduralSky::set_sun_angle_max); - ClassDB::bind_method(D_METHOD("get_sun_angle_max"), &ProceduralSky::get_sun_angle_max); - - ClassDB::bind_method(D_METHOD("set_sun_curve", "curve"), &ProceduralSky::set_sun_curve); - ClassDB::bind_method(D_METHOD("get_sun_curve"), &ProceduralSky::get_sun_curve); - - ClassDB::bind_method(D_METHOD("set_sun_energy", "energy"), &ProceduralSky::set_sun_energy); - ClassDB::bind_method(D_METHOD("get_sun_energy"), &ProceduralSky::get_sun_energy); - - ClassDB::bind_method(D_METHOD("set_texture_size", "size"), &ProceduralSky::set_texture_size); - ClassDB::bind_method(D_METHOD("get_texture_size"), &ProceduralSky::get_texture_size); - - ClassDB::bind_method(D_METHOD("_thread_done", "image"), &ProceduralSky::_thread_done); - - ADD_GROUP("Sky", "sky_"); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sky_top_color"), "set_sky_top_color", "get_sky_top_color"); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sky_horizon_color"), "set_sky_horizon_color", "get_sky_horizon_color"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sky_curve", PROPERTY_HINT_EXP_EASING), "set_sky_curve", "get_sky_curve"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sky_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_sky_energy", "get_sky_energy"); - - ADD_GROUP("Ground", "ground_"); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ground_bottom_color"), "set_ground_bottom_color", "get_ground_bottom_color"); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ground_horizon_color"), "set_ground_horizon_color", "get_ground_horizon_color"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ground_curve", PROPERTY_HINT_EXP_EASING), "set_ground_curve", "get_ground_curve"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ground_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_ground_energy", "get_ground_energy"); - - ADD_GROUP("Sun", "sun_"); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sun_color"), "set_sun_color", "get_sun_color"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sun_latitude", PROPERTY_HINT_RANGE, "-180,180,0.01"), "set_sun_latitude", "get_sun_latitude"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sun_longitude", PROPERTY_HINT_RANGE, "-180,180,0.01"), "set_sun_longitude", "get_sun_longitude"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sun_angle_min", PROPERTY_HINT_RANGE, "0,360,0.01"), "set_sun_angle_min", "get_sun_angle_min"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sun_angle_max", PROPERTY_HINT_RANGE, "0,360,0.01"), "set_sun_angle_max", "get_sun_angle_max"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sun_curve", PROPERTY_HINT_EXP_EASING), "set_sun_curve", "get_sun_curve"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sun_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_sun_energy", "get_sun_energy"); - - ADD_GROUP("Texture2D", "texture_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_size", PROPERTY_HINT_ENUM, "256,512,1024,2048,4096"), "set_texture_size", "get_texture_size"); - - BIND_ENUM_CONSTANT(TEXTURE_SIZE_256); - BIND_ENUM_CONSTANT(TEXTURE_SIZE_512); - BIND_ENUM_CONSTANT(TEXTURE_SIZE_1024); - BIND_ENUM_CONSTANT(TEXTURE_SIZE_2048); - BIND_ENUM_CONSTANT(TEXTURE_SIZE_4096); - BIND_ENUM_CONSTANT(TEXTURE_SIZE_MAX); -} - -ProceduralSky::ProceduralSky(bool p_desaturate) { - - update_queued = false; - sky_top_color = Color::hex(0xa5d6f1ff); - sky_horizon_color = Color::hex(0xd6eafaff); - sky_curve = 0.09; - sky_energy = 1; - - ground_bottom_color = Color::hex(0x282f36ff); - ground_horizon_color = Color::hex(0x6c655fff); - ground_curve = 0.02; - ground_energy = 1; - - if (p_desaturate) { - sky_top_color.set_hsv(sky_top_color.get_h(), 0, sky_top_color.get_v()); - sky_horizon_color.set_hsv(sky_horizon_color.get_h(), 0, sky_horizon_color.get_v()); - ground_bottom_color.set_hsv(ground_bottom_color.get_h(), 0, ground_bottom_color.get_v()); - ground_horizon_color.set_hsv(ground_horizon_color.get_h(), 0, ground_horizon_color.get_v()); - } - sun_color = Color(1, 1, 1); - sun_latitude = 35; - sun_longitude = 0; - sun_angle_min = 1; - sun_angle_max = 100; - sun_curve = 0.05; - sun_energy = 1; - - texture_size = TEXTURE_SIZE_1024; - sky_thread = NULL; - regen_queued = false; - first_time = true; - - _queue_update(); -} - -ProceduralSky::~ProceduralSky() { - - if (sky_thread) { - Thread::wait_to_finish(sky_thread); - memdelete(sky_thread); - sky_thread = NULL; - } - if (texture.is_valid()) { - VS::get_singleton()->free(texture); - } -} + RS::get_singleton()->free(sky); +}
\ No newline at end of file diff --git a/scene/resources/sky.h b/scene/resources/sky.h index 09ebbd88a0..37f0a589f9 100644 --- a/scene/resources/sky.h +++ b/scene/resources/sky.h @@ -32,6 +32,7 @@ #define SKY_H #include "core/os/thread.h" +#include "scene/resources/material.h" #include "scene/resources/texture.h" class Sky : public Resource { @@ -58,6 +59,7 @@ private: RID sky; ProcessMode mode; RadianceSize radiance_size; + Ref<Material> sky_material; protected: static void _bind_methods(); @@ -69,6 +71,9 @@ public: void set_process_mode(ProcessMode p_mode); ProcessMode get_process_mode() const; + void set_material(const Ref<Material> &p_material); + Ref<Material> get_material() const; + virtual RID get_rid() const; Sky(); @@ -78,129 +83,4 @@ public: VARIANT_ENUM_CAST(Sky::RadianceSize) VARIANT_ENUM_CAST(Sky::ProcessMode) -class PanoramaSky : public Sky { - GDCLASS(PanoramaSky, Sky); - -private: - Ref<Texture2D> panorama; - -protected: - static void _bind_methods(); - -public: - void set_panorama(const Ref<Texture2D> &p_panorama); - Ref<Texture2D> get_panorama() const; - - PanoramaSky(); - ~PanoramaSky(); -}; - -class ProceduralSky : public Sky { - GDCLASS(ProceduralSky, Sky); - -public: - enum TextureSize { - TEXTURE_SIZE_256, - TEXTURE_SIZE_512, - TEXTURE_SIZE_1024, - TEXTURE_SIZE_2048, - TEXTURE_SIZE_4096, - TEXTURE_SIZE_MAX - }; - -private: - Thread *sky_thread; - Color sky_top_color; - Color sky_horizon_color; - float sky_curve; - float sky_energy; - - Color ground_bottom_color; - Color ground_horizon_color; - float ground_curve; - float ground_energy; - - Color sun_color; - float sun_latitude; - float sun_longitude; - float sun_angle_min; - float sun_angle_max; - float sun_curve; - float sun_energy; - - TextureSize texture_size; - - RID texture; - - bool update_queued; - bool regen_queued; - - bool first_time; - - void _thread_done(const Ref<Image> &p_image); - static void _thread_function(void *p_ud); - -protected: - static void _bind_methods(); - - Ref<Image> _generate_sky(); - void _update_sky(); - - void _queue_update(); - -public: - void set_sky_top_color(const Color &p_sky_top); - Color get_sky_top_color() const; - - void set_sky_horizon_color(const Color &p_sky_horizon); - Color get_sky_horizon_color() const; - - void set_sky_curve(float p_curve); - float get_sky_curve() const; - - void set_sky_energy(float p_energy); - float get_sky_energy() const; - - void set_ground_bottom_color(const Color &p_ground_bottom); - Color get_ground_bottom_color() const; - - void set_ground_horizon_color(const Color &p_ground_horizon); - Color get_ground_horizon_color() const; - - void set_ground_curve(float p_curve); - float get_ground_curve() const; - - void set_ground_energy(float p_energy); - float get_ground_energy() const; - - void set_sun_color(const Color &p_sun); - Color get_sun_color() const; - - void set_sun_latitude(float p_angle); - float get_sun_latitude() const; - - void set_sun_longitude(float p_angle); - float get_sun_longitude() const; - - void set_sun_angle_min(float p_angle); - float get_sun_angle_min() const; - - void set_sun_angle_max(float p_angle); - float get_sun_angle_max() const; - - void set_sun_curve(float p_curve); - float get_sun_curve() const; - - void set_sun_energy(float p_energy); - float get_sun_energy() const; - - void set_texture_size(TextureSize p_size); - TextureSize get_texture_size() const; - - ProceduralSky(bool p_desaturate = false); - ~ProceduralSky(); -}; - -VARIANT_ENUM_CAST(ProceduralSky::TextureSize) - #endif // SKY_H diff --git a/scene/resources/sky_material.cpp b/scene/resources/sky_material.cpp new file mode 100644 index 0000000000..a0b6ab1e30 --- /dev/null +++ b/scene/resources/sky_material.cpp @@ -0,0 +1,611 @@ +/*************************************************************************/ +/* sky_material.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 "sky_material.h" + +void ProceduralSkyMaterial::set_sky_top_color(const Color &p_sky_top) { + + sky_top_color = p_sky_top; + RS::get_singleton()->material_set_param(_get_material(), "sky_top_color", sky_top_color.to_linear()); +} + +Color ProceduralSkyMaterial::get_sky_top_color() const { + + return sky_top_color; +} + +void ProceduralSkyMaterial::set_sky_horizon_color(const Color &p_sky_horizon) { + + sky_horizon_color = p_sky_horizon; + RS::get_singleton()->material_set_param(_get_material(), "sky_horizon_color", sky_horizon_color.to_linear()); +} +Color ProceduralSkyMaterial::get_sky_horizon_color() const { + + return sky_horizon_color; +} + +void ProceduralSkyMaterial::set_sky_curve(float p_curve) { + + sky_curve = p_curve; + RS::get_singleton()->material_set_param(_get_material(), "sky_curve", sky_curve); +} +float ProceduralSkyMaterial::get_sky_curve() const { + + return sky_curve; +} + +void ProceduralSkyMaterial::set_sky_energy(float p_energy) { + + sky_energy = p_energy; + RS::get_singleton()->material_set_param(_get_material(), "sky_energy", sky_energy); +} +float ProceduralSkyMaterial::get_sky_energy() const { + + return sky_energy; +} + +void ProceduralSkyMaterial::set_ground_bottom_color(const Color &p_ground_bottom) { + + ground_bottom_color = p_ground_bottom; + RS::get_singleton()->material_set_param(_get_material(), "ground_bottom_color", ground_bottom_color.to_linear()); +} +Color ProceduralSkyMaterial::get_ground_bottom_color() const { + + return ground_bottom_color; +} + +void ProceduralSkyMaterial::set_ground_horizon_color(const Color &p_ground_horizon) { + + ground_horizon_color = p_ground_horizon; + RS::get_singleton()->material_set_param(_get_material(), "ground_horizon_color", ground_horizon_color.to_linear()); +} +Color ProceduralSkyMaterial::get_ground_horizon_color() const { + + return ground_horizon_color; +} + +void ProceduralSkyMaterial::set_ground_curve(float p_curve) { + + ground_curve = p_curve; + RS::get_singleton()->material_set_param(_get_material(), "ground_curve", ground_curve); +} +float ProceduralSkyMaterial::get_ground_curve() const { + + return ground_curve; +} + +void ProceduralSkyMaterial::set_ground_energy(float p_energy) { + + ground_energy = p_energy; + RS::get_singleton()->material_set_param(_get_material(), "ground_energy", ground_energy); +} +float ProceduralSkyMaterial::get_ground_energy() const { + + return ground_energy; +} + +void ProceduralSkyMaterial::set_sun_angle_max(float p_angle) { + + sun_angle_max = p_angle; + RS::get_singleton()->material_set_param(_get_material(), "sun_angle_max", Math::deg2rad(sun_angle_max)); +} +float ProceduralSkyMaterial::get_sun_angle_max() const { + + return sun_angle_max; +} + +void ProceduralSkyMaterial::set_sun_curve(float p_curve) { + + sun_curve = p_curve; + RS::get_singleton()->material_set_param(_get_material(), "sun_curve", sun_curve); +} +float ProceduralSkyMaterial::get_sun_curve() const { + + return sun_curve; +} + +bool ProceduralSkyMaterial::_can_do_next_pass() const { + return false; +} + +Shader::Mode ProceduralSkyMaterial::get_shader_mode() const { + + return Shader::MODE_SKY; +} + +RID ProceduralSkyMaterial::get_shader_rid() const { + + return shader; +} + +void ProceduralSkyMaterial::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_sky_top_color", "color"), &ProceduralSkyMaterial::set_sky_top_color); + ClassDB::bind_method(D_METHOD("get_sky_top_color"), &ProceduralSkyMaterial::get_sky_top_color); + + ClassDB::bind_method(D_METHOD("set_sky_horizon_color", "color"), &ProceduralSkyMaterial::set_sky_horizon_color); + ClassDB::bind_method(D_METHOD("get_sky_horizon_color"), &ProceduralSkyMaterial::get_sky_horizon_color); + + ClassDB::bind_method(D_METHOD("set_sky_curve", "curve"), &ProceduralSkyMaterial::set_sky_curve); + ClassDB::bind_method(D_METHOD("get_sky_curve"), &ProceduralSkyMaterial::get_sky_curve); + + ClassDB::bind_method(D_METHOD("set_sky_energy", "energy"), &ProceduralSkyMaterial::set_sky_energy); + ClassDB::bind_method(D_METHOD("get_sky_energy"), &ProceduralSkyMaterial::get_sky_energy); + + ClassDB::bind_method(D_METHOD("set_ground_bottom_color", "color"), &ProceduralSkyMaterial::set_ground_bottom_color); + ClassDB::bind_method(D_METHOD("get_ground_bottom_color"), &ProceduralSkyMaterial::get_ground_bottom_color); + + ClassDB::bind_method(D_METHOD("set_ground_horizon_color", "color"), &ProceduralSkyMaterial::set_ground_horizon_color); + ClassDB::bind_method(D_METHOD("get_ground_horizon_color"), &ProceduralSkyMaterial::get_ground_horizon_color); + + ClassDB::bind_method(D_METHOD("set_ground_curve", "curve"), &ProceduralSkyMaterial::set_ground_curve); + ClassDB::bind_method(D_METHOD("get_ground_curve"), &ProceduralSkyMaterial::get_ground_curve); + + ClassDB::bind_method(D_METHOD("set_ground_energy", "energy"), &ProceduralSkyMaterial::set_ground_energy); + ClassDB::bind_method(D_METHOD("get_ground_energy"), &ProceduralSkyMaterial::get_ground_energy); + + ClassDB::bind_method(D_METHOD("set_sun_angle_max", "degrees"), &ProceduralSkyMaterial::set_sun_angle_max); + ClassDB::bind_method(D_METHOD("get_sun_angle_max"), &ProceduralSkyMaterial::get_sun_angle_max); + + ClassDB::bind_method(D_METHOD("set_sun_curve", "curve"), &ProceduralSkyMaterial::set_sun_curve); + ClassDB::bind_method(D_METHOD("get_sun_curve"), &ProceduralSkyMaterial::get_sun_curve); + + ADD_GROUP("Sky", "sky_"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sky_top_color"), "set_sky_top_color", "get_sky_top_color"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sky_horizon_color"), "set_sky_horizon_color", "get_sky_horizon_color"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sky_curve", PROPERTY_HINT_EXP_EASING), "set_sky_curve", "get_sky_curve"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sky_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_sky_energy", "get_sky_energy"); + + ADD_GROUP("Ground", "ground_"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ground_bottom_color"), "set_ground_bottom_color", "get_ground_bottom_color"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ground_horizon_color"), "set_ground_horizon_color", "get_ground_horizon_color"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ground_curve", PROPERTY_HINT_EXP_EASING), "set_ground_curve", "get_ground_curve"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ground_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_ground_energy", "get_ground_energy"); + + ADD_GROUP("Sun", "sun_"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sun_angle_max", PROPERTY_HINT_RANGE, "0,360,0.01"), "set_sun_angle_max", "get_sun_angle_max"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sun_curve", PROPERTY_HINT_EXP_EASING), "set_sun_curve", "get_sun_curve"); +} + +ProceduralSkyMaterial::ProceduralSkyMaterial() { + + String code = "shader_type sky;\n\n"; + + code += "uniform vec4 sky_top_color : hint_color = vec4(0.35, 0.46, 0.71, 1.0);\n"; + code += "uniform vec4 sky_horizon_color : hint_color = vec4(0.55, 0.69, 0.81, 1.0);\n"; + code += "uniform float sky_curve : hint_range(0, 1) = 0.09;\n"; + code += "uniform float sky_energy = 1.0;\n\n"; + code += "uniform vec4 ground_bottom_color : hint_color = vec4(0.12, 0.12, 0.13, 1.0);\n"; + code += "uniform vec4 ground_horizon_color : hint_color = vec4(0.37, 0.33, 0.31, 1.0);\n"; + code += "uniform float ground_curve : hint_range(0, 1) = 0.02;\n"; + code += "uniform float ground_energy = 1.0;\n\n"; + code += "uniform float sun_angle_max = 1.74;\n"; + code += "uniform float sun_curve : hint_range(0, 1) = 0.05;\n\n"; + code += "const float PI = 3.1415926535897932384626433833;\n\n"; + code += "void fragment() {\n"; + code += "\tfloat v_angle = acos(clamp(EYEDIR.y, -1.0, 1.0));\n"; + code += "\tfloat c = (1.0 - v_angle / (PI * 0.5));\n"; + code += "\tvec3 sky = mix(sky_horizon_color.rgb, sky_top_color.rgb, clamp(1.0 - pow(1.0 - c, 1.0 / sky_curve), 0.0, 1.0));\n"; + code += "\tsky *= sky_energy;\n"; + code += "\tif (LIGHT0_ENABLED) {\n"; + code += "\t\tfloat sun_angle = acos(dot(LIGHT0_DIRECTION, EYEDIR));\n"; + code += "\t\tif (sun_angle < LIGHT0_SIZE) {\n"; + code += "\t\t\tsky = LIGHT0_COLOR * LIGHT0_ENERGY;\n"; + code += "\t\t} else if (sun_angle < sun_angle_max) {\n"; + code += "\t\t\tfloat c2 = (sun_angle - LIGHT0_SIZE) / (sun_angle_max - LIGHT0_SIZE);\n"; + code += "\t\t\tsky = mix(LIGHT0_COLOR * LIGHT0_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n"; + code += "\t\t}\n"; + code += "\t}\n"; + code += "\tif (LIGHT1_ENABLED) {\n"; + code += "\t\tfloat sun_angle = acos(dot(LIGHT1_DIRECTION, EYEDIR));\n"; + code += "\t\tif (sun_angle < LIGHT1_SIZE) {\n"; + code += "\t\t\tsky = LIGHT1_COLOR * LIGHT1_ENERGY;\n"; + code += "\t\t} else if (sun_angle < sun_angle_max) {\n"; + code += "\t\t\tfloat c2 = (sun_angle - LIGHT1_SIZE) / (sun_angle_max - LIGHT1_SIZE);\n"; + code += "\t\t\tsky = mix(LIGHT1_COLOR * LIGHT1_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n"; + code += "\t\t}\n"; + code += "\t}\n"; + code += "\tif (LIGHT2_ENABLED) {\n"; + code += "\t\tfloat sun_angle = acos(dot(LIGHT2_DIRECTION, EYEDIR));\n"; + code += "\t\tif (sun_angle < LIGHT2_SIZE) {\n"; + code += "\t\t\tsky = LIGHT2_COLOR * LIGHT2_ENERGY;\n"; + code += "\t\t} else if (sun_angle < sun_angle_max) {\n"; + code += "\t\t\tfloat c2 = (sun_angle - LIGHT2_SIZE) / (sun_angle_max - LIGHT2_SIZE);\n"; + code += "\t\t\tsky = mix(LIGHT2_COLOR * LIGHT2_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n"; + code += "\t\t}\n"; + code += "\t}\n"; + code += "\tif (LIGHT3_ENABLED) {\n"; + code += "\t\tfloat sun_angle = acos(dot(LIGHT3_DIRECTION, EYEDIR));\n"; + code += "\t\tif (sun_angle < LIGHT3_SIZE) {\n"; + code += "\t\t\tsky = LIGHT3_COLOR * LIGHT3_ENERGY;\n"; + code += "\t\t} else if (sun_angle < sun_angle_max) {\n"; + code += "\t\t\tfloat c2 = (sun_angle - LIGHT3_SIZE) / (sun_angle_max - LIGHT3_SIZE);\n"; + code += "\t\t\tsky = mix(LIGHT3_COLOR * LIGHT3_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n"; + code += "\t\t}\n"; + code += "\t}\n"; + code += "\tc = (v_angle - (PI * 0.5)) / (PI * 0.5);\n"; + code += "\tvec3 ground = mix(ground_horizon_color.rgb, ground_bottom_color.rgb, clamp(1.0 - pow(1.0 - c, 1.0 / ground_curve), 0.0, 1.0));\n"; + code += "\tground *= ground_energy;\n"; + code += "\tCOLOR = mix(ground, sky, step(0.0, EYEDIR.y));\n"; + code += "}\n"; + + shader = RS::get_singleton()->shader_create(); + + RS::get_singleton()->shader_set_code(shader, code); + + RS::get_singleton()->material_set_shader(_get_material(), shader); + + set_sky_top_color(Color(0.35, 0.46, 0.71)); + set_sky_horizon_color(Color(0.55, 0.69, 0.81)); + set_sky_curve(0.09); + set_sky_energy(1.0); + + set_ground_bottom_color(Color(0.12, 0.12, 0.13)); + set_ground_horizon_color(Color(0.37, 0.33, 0.31)); + set_ground_curve(0.02); + set_ground_energy(1.0); + + set_sun_angle_max(100.0); + set_sun_curve(0.05); +} + +ProceduralSkyMaterial::~ProceduralSkyMaterial() { + RS::get_singleton()->free(shader); + RS::get_singleton()->material_set_shader(_get_material(), RID()); +} + +///////////////////////////////////////// +/* PanoramaSkyMaterial */ + +void PanoramaSkyMaterial::set_panorama(const Ref<Texture2D> &p_panorama) { + + panorama = p_panorama; + RS::get_singleton()->material_set_param(_get_material(), "source_panorama", panorama); +} + +Ref<Texture2D> PanoramaSkyMaterial::get_panorama() const { + + return panorama; +} + +bool PanoramaSkyMaterial::_can_do_next_pass() const { + return false; +} + +Shader::Mode PanoramaSkyMaterial::get_shader_mode() const { + + return Shader::MODE_SKY; +} + +RID PanoramaSkyMaterial::get_shader_rid() const { + + return shader; +} + +void PanoramaSkyMaterial::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_panorama", "texture"), &PanoramaSkyMaterial::set_panorama); + ClassDB::bind_method(D_METHOD("get_panorama"), &PanoramaSkyMaterial::get_panorama); + + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "panorama", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_panorama", "get_panorama"); +} + +PanoramaSkyMaterial::PanoramaSkyMaterial() { + String code = "shader_type sky;\n\n"; + + code += "uniform sampler2D source_panorama : filter_linear;\n"; + code += "void fragment() {\n"; + code += "\tCOLOR = texture(source_panorama, SKY_COORDS).rgb;\n"; + code += "}"; + + shader = RS::get_singleton()->shader_create(); + + RS::get_singleton()->shader_set_code(shader, code); + + RS::get_singleton()->material_set_shader(_get_material(), shader); +} + +PanoramaSkyMaterial::~PanoramaSkyMaterial() { + RS::get_singleton()->free(shader); + RS::get_singleton()->material_set_shader(_get_material(), RID()); +} +////////////////////////////////// +/* PhysicalSkyMaterial */ + +void PhysicalSkyMaterial::set_rayleigh_coefficient(float p_rayleigh) { + + rayleigh = p_rayleigh; + RS::get_singleton()->material_set_param(_get_material(), "rayleigh", rayleigh); +} +float PhysicalSkyMaterial::get_rayleigh_coefficient() const { + + return rayleigh; +} + +void PhysicalSkyMaterial::set_rayleigh_color(Color p_rayleigh_color) { + + rayleigh_color = p_rayleigh_color; + RS::get_singleton()->material_set_param(_get_material(), "rayleigh_color", rayleigh_color); +} +Color PhysicalSkyMaterial::get_rayleigh_color() const { + + return rayleigh_color; +} + +void PhysicalSkyMaterial::set_mie_coefficient(float p_mie) { + + mie = p_mie; + RS::get_singleton()->material_set_param(_get_material(), "mie", mie); +} +float PhysicalSkyMaterial::get_mie_coefficient() const { + + return mie; +} + +void PhysicalSkyMaterial::set_mie_eccentricity(float p_eccentricity) { + + mie_eccentricity = p_eccentricity; + RS::get_singleton()->material_set_param(_get_material(), "mie_eccentricity", mie_eccentricity); +} +float PhysicalSkyMaterial::get_mie_eccentricity() const { + + return mie_eccentricity; +} + +void PhysicalSkyMaterial::set_mie_color(Color p_mie_color) { + + mie_color = p_mie_color; + RS::get_singleton()->material_set_param(_get_material(), "mie_color", mie_color); +} +Color PhysicalSkyMaterial::get_mie_color() const { + return mie_color; +} + +void PhysicalSkyMaterial::set_turbidity(float p_turbidity) { + + turbidity = p_turbidity; + RS::get_singleton()->material_set_param(_get_material(), "turbidity", turbidity); +} +float PhysicalSkyMaterial::get_turbidity() const { + + return turbidity; +} + +void PhysicalSkyMaterial::set_sun_disk_scale(float p_sun_disk_scale) { + + sun_disk_scale = p_sun_disk_scale; + RS::get_singleton()->material_set_param(_get_material(), "sun_disk_scale", sun_disk_scale); +} +float PhysicalSkyMaterial::get_sun_disk_scale() const { + + return sun_disk_scale; +} + +void PhysicalSkyMaterial::set_ground_color(Color p_ground_color) { + + ground_color = p_ground_color; + RS::get_singleton()->material_set_param(_get_material(), "ground_color", ground_color); +} +Color PhysicalSkyMaterial::get_ground_color() const { + + return ground_color; +} + +void PhysicalSkyMaterial::set_exposure(float p_exposure) { + + exposure = p_exposure; + RS::get_singleton()->material_set_param(_get_material(), "exposure", exposure); +} +float PhysicalSkyMaterial::get_exposure() const { + + return exposure; +} + +void PhysicalSkyMaterial::set_dither_strength(float p_dither_strength) { + + dither_strength = p_dither_strength; + RS::get_singleton()->material_set_param(_get_material(), "dither_strength", dither_strength); +} +float PhysicalSkyMaterial::get_dither_strength() const { + + return dither_strength; +} + +bool PhysicalSkyMaterial::_can_do_next_pass() const { + return false; +} + +Shader::Mode PhysicalSkyMaterial::get_shader_mode() const { + + return Shader::MODE_SKY; +} + +RID PhysicalSkyMaterial::get_shader_rid() const { + + return shader; +} + +void PhysicalSkyMaterial::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_rayleigh_coefficient", "rayleigh"), &PhysicalSkyMaterial::set_rayleigh_coefficient); + ClassDB::bind_method(D_METHOD("get_rayleigh_coefficient"), &PhysicalSkyMaterial::get_rayleigh_coefficient); + + ClassDB::bind_method(D_METHOD("set_rayleigh_color", "color"), &PhysicalSkyMaterial::set_rayleigh_color); + ClassDB::bind_method(D_METHOD("get_rayleigh_color"), &PhysicalSkyMaterial::get_rayleigh_color); + + ClassDB::bind_method(D_METHOD("set_mie_coefficient", "mie"), &PhysicalSkyMaterial::set_mie_coefficient); + ClassDB::bind_method(D_METHOD("get_mie_coefficient"), &PhysicalSkyMaterial::get_mie_coefficient); + + ClassDB::bind_method(D_METHOD("set_mie_eccentricity", "eccentricity"), &PhysicalSkyMaterial::set_mie_eccentricity); + ClassDB::bind_method(D_METHOD("get_mie_eccentricity"), &PhysicalSkyMaterial::get_mie_eccentricity); + + ClassDB::bind_method(D_METHOD("set_mie_color", "color"), &PhysicalSkyMaterial::set_mie_color); + ClassDB::bind_method(D_METHOD("get_mie_color"), &PhysicalSkyMaterial::get_mie_color); + + ClassDB::bind_method(D_METHOD("set_turbidity", "turbidity"), &PhysicalSkyMaterial::set_turbidity); + ClassDB::bind_method(D_METHOD("get_turbidity"), &PhysicalSkyMaterial::get_turbidity); + + ClassDB::bind_method(D_METHOD("set_sun_disk_scale", "scale"), &PhysicalSkyMaterial::set_sun_disk_scale); + ClassDB::bind_method(D_METHOD("get_sun_disk_scale"), &PhysicalSkyMaterial::get_sun_disk_scale); + + ClassDB::bind_method(D_METHOD("set_ground_color", "color"), &PhysicalSkyMaterial::set_ground_color); + ClassDB::bind_method(D_METHOD("get_ground_color"), &PhysicalSkyMaterial::get_ground_color); + + ClassDB::bind_method(D_METHOD("set_exposure", "exposure"), &PhysicalSkyMaterial::set_exposure); + ClassDB::bind_method(D_METHOD("get_exposure"), &PhysicalSkyMaterial::get_exposure); + + ClassDB::bind_method(D_METHOD("set_dither_strength", "strength"), &PhysicalSkyMaterial::set_dither_strength); + ClassDB::bind_method(D_METHOD("get_dither_strength"), &PhysicalSkyMaterial::get_dither_strength); + + ADD_GROUP("Rayleigh", "rayleigh_"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rayleigh_coefficient", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_rayleigh_coefficient", "get_rayleigh_coefficient"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "rayleigh_color"), "set_rayleigh_color", "get_rayleigh_color"); + + ADD_GROUP("Mie", "mie_"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mie_coefficient", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_mie_coefficient", "get_mie_coefficient"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mie_eccentricity", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_mie_eccentricity", "get_mie_eccentricity"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "mie_color"), "set_mie_color", "get_mie_color"); + + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "turbidity", PROPERTY_HINT_RANGE, "0,1000,0.01"), "set_turbidity", "get_turbidity"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sun_disk_scale", PROPERTY_HINT_RANGE, "0,360,0.01"), "set_sun_disk_scale", "get_sun_disk_scale"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ground_color"), "set_ground_color", "get_ground_color"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "exposure", PROPERTY_HINT_RANGE, "0,128,0.01"), "set_exposure", "get_exposure"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dither_strength", PROPERTY_HINT_RANGE, "0,10,0.01"), "set_dither_strength", "get_dither_strength"); +} + +PhysicalSkyMaterial::PhysicalSkyMaterial() { + String code = "shader_type sky;\n\n"; + + code += "uniform float rayleigh : hint_range(0, 64) = 2.0;\n"; + code += "uniform vec4 rayleigh_color : hint_color = vec4(0.056, 0.14, 0.3, 1.0);\n"; + code += "uniform float mie : hint_range(0, 1) = 0.005;\n"; + code += "uniform float mie_eccentricity : hint_range(-1, 1) = 0.8;\n"; + code += "uniform vec4 mie_color : hint_color = vec4(0.36, 0.56, 0.82, 1.0);\n\n"; + + code += "uniform float turbidity : hint_range(0, 1000) = 10.0;\n"; + code += "uniform float sun_disk_scale : hint_range(0, 360) = 1.0;\n"; + code += "uniform vec4 ground_color : hint_color = vec4(1.0);\n"; + code += "uniform float exposure : hint_range(0, 128) = 0.1;\n"; + code += "uniform float dither_strength : hint_range(0, 10) = 1.0;\n\n"; + + code += "const float PI = 3.141592653589793238462643383279502884197169;\n"; + code += "const vec3 UP = vec3( 0.0, 1.0, 0.0 );\n\n"; + + code += "// Sun constants\n"; + code += "const float SUN_ENERGY = 1000.0;\n\n"; + + code += "// optical length at zenith for molecules\n"; + code += "const float rayleigh_zenith_size = 8.4e3;\n"; + code += "const float mie_zenith_size = 1.25e3;\n\n"; + + code += "float henyey_greenstein(float cos_theta, float g) {\n"; + code += "\tconst float k = 0.0795774715459;\n"; + code += "\treturn k * (1.0 - g * g) / (pow(1.0 + g * g - 2.0 * g * cos_theta, 1.5));\n"; + code += "}\n\n"; + + code += "// From: https://www.shadertoy.com/view/4sfGzS credit to iq\n"; + code += "float hash(vec3 p) {\n"; + code += "\tp = fract( p * 0.3183099 + 0.1 );\n"; + code += "\tp *= 17.0;\n"; + code += "\treturn fract(p.x * p.y * p.z * (p.x + p.y + p.z));\n"; + code += "}\n\n"; + + code += "void fragment() {\n"; + code += "\tfloat zenith_angle = clamp( dot(UP, normalize(LIGHT0_DIRECTION)), -1.0, 1.0 );\n"; + code += "\tfloat sun_energy = max(0.0, 1.0 - exp(-((PI * 0.5) - acos(zenith_angle)))) * SUN_ENERGY * LIGHT0_ENERGY;\n"; + code += "\tfloat sun_fade = 1.0 - clamp(1.0 - exp(LIGHT0_DIRECTION.y), 0.0, 1.0);\n\n"; + + code += "\t// rayleigh coefficients\n"; + code += "\tfloat rayleigh_coefficient = rayleigh - ( 1.0 * ( 1.0 - sun_fade ) );\n"; + code += "\tvec3 rayleigh_beta = rayleigh_coefficient * rayleigh_color.rgb * 0.0001;\n"; + code += "\t// mie coefficients from Preetham\n"; + code += "\tvec3 mie_beta = turbidity * mie * mie_color.rgb * 0.000434;\n\n"; + + code += "\t// optical length\n"; + code += "\tfloat zenith = acos(max(0.0, dot(UP, EYEDIR)));\n"; + code += "\tfloat optical_mass = 1.0 / (cos(zenith) + 0.15 * pow(93.885 - degrees(zenith), -1.253));\n"; + code += "\tfloat rayleigh_scatter = rayleigh_zenith_size * optical_mass;\n"; + code += "\tfloat mie_scatter = mie_zenith_size * optical_mass;\n\n"; + + code += "\t// light extinction based on thickness of atmosphere\n"; + code += "\tvec3 extinction = exp(-(rayleigh_beta * rayleigh_scatter + mie_beta * mie_scatter));\n\n"; + + code += "\t// in scattering\n"; + code += "\tfloat cos_theta = dot(EYEDIR, normalize(LIGHT0_DIRECTION));\n\n"; + + code += "\tfloat rayleigh_phase = (3.0 / (16.0 * PI)) * (1.0 + pow(cos_theta * 0.5 + 0.5, 2.0));\n"; + code += "\tvec3 betaRTheta = rayleigh_beta * rayleigh_phase;\n\n"; + + code += "\tfloat mie_phase = henyey_greenstein(cos_theta, mie_eccentricity);\n"; + code += "\tvec3 betaMTheta = mie_beta * mie_phase;\n\n"; + + code += "\tvec3 Lin = pow(sun_energy * ((betaRTheta + betaMTheta) / (rayleigh_beta + mie_beta)) * (1.0 - extinction), vec3(1.5));\n"; + code += "\t// Hack from https://github.com/mrdoob/three.js/blob/master/examples/jsm/objects/Sky.js\n"; + code += "\tLin *= mix(vec3(1.0), pow(sun_energy * ((betaRTheta + betaMTheta) / (rayleigh_beta + mie_beta)) * extinction, vec3(0.5)), clamp(pow(1.0 - zenith_angle, 5.0), 0.0, 1.0));\n\n"; + + code += "\t// Hack in the ground color\n"; + code += "\tLin *= mix(ground_color.rgb, vec3(1.0), smoothstep(-0.1, 0.1, dot(UP, EYEDIR)));\n\n"; + + code += "\t// Solar disk and out-scattering\n"; + code += "\tfloat sunAngularDiameterCos = cos(LIGHT0_SIZE * sun_disk_scale);\n"; + code += "\tfloat sunAngularDiameterCos2 = cos(LIGHT0_SIZE * sun_disk_scale*0.5);\n"; + code += "\tfloat sundisk = smoothstep(sunAngularDiameterCos, sunAngularDiameterCos2, cos_theta);\n"; + code += "\tvec3 L0 = (sun_energy * 1900.0 * extinction) * sundisk * LIGHT0_COLOR;\n"; + code += "\t// Note: Add nightime here: L0 += night_sky * extinction\n\n"; + + code += "\tvec3 color = (Lin + L0) * 0.04;\n"; + code += "\tCOLOR = pow(color, vec3(1.0 / (1.2 + (1.2 * sun_fade))));\n"; + code += "\tCOLOR *= exposure;\n"; + code += "\t// Make optional, eliminates banding\n"; + code += "\tCOLOR += (hash(EYEDIR * 1741.9782) * 0.08 - 0.04) * 0.008 * dither_strength;\n"; + code += "}\n"; + + shader = RS::get_singleton()->shader_create(); + + RS::get_singleton()->shader_set_code(shader, code); + + RS::get_singleton()->material_set_shader(_get_material(), shader); + + set_rayleigh_coefficient(2.0); + set_rayleigh_color(Color(0.056, 0.14, 0.3)); + set_mie_coefficient(0.005); + set_mie_eccentricity(0.8); + set_mie_color(Color(0.36, 0.56, 0.82)); + set_turbidity(10.0); + set_sun_disk_scale(1.0); + set_ground_color(Color(1.0, 1.0, 1.0)); + set_exposure(0.1); + set_dither_strength(1.0); +} + +PhysicalSkyMaterial::~PhysicalSkyMaterial() { + RS::get_singleton()->free(shader); + RS::get_singleton()->material_set_shader(_get_material(), RID()); +} diff --git a/scene/resources/sky_material.h b/scene/resources/sky_material.h new file mode 100644 index 0000000000..9bd9d7ec8b --- /dev/null +++ b/scene/resources/sky_material.h @@ -0,0 +1,186 @@ +/*************************************************************************/ +/* sky_material.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. */ +/*************************************************************************/ + +#include "core/rid.h" +#include "scene/resources/material.h" + +#ifndef SKY_MATERIAL_H +#define SKY_MATERIAL_H + +class ProceduralSkyMaterial : public Material { + + GDCLASS(ProceduralSkyMaterial, Material); + +private: + Color sky_top_color; + Color sky_horizon_color; + float sky_curve; + float sky_energy; + + Color ground_bottom_color; + Color ground_horizon_color; + float ground_curve; + float ground_energy; + + float sun_angle_max; + float sun_curve; + + RID shader; + +protected: + static void _bind_methods(); + virtual bool _can_do_next_pass() const; + +public: + void set_sky_top_color(const Color &p_sky_top); + Color get_sky_top_color() const; + + void set_sky_horizon_color(const Color &p_sky_horizon); + Color get_sky_horizon_color() const; + + void set_sky_curve(float p_curve); + float get_sky_curve() const; + + void set_sky_energy(float p_energy); + float get_sky_energy() const; + + void set_ground_bottom_color(const Color &p_ground_bottom); + Color get_ground_bottom_color() const; + + void set_ground_horizon_color(const Color &p_ground_horizon); + Color get_ground_horizon_color() const; + + void set_ground_curve(float p_curve); + float get_ground_curve() const; + + void set_ground_energy(float p_energy); + float get_ground_energy() const; + + void set_sun_angle_max(float p_angle); + float get_sun_angle_max() const; + + void set_sun_curve(float p_curve); + float get_sun_curve() const; + + virtual Shader::Mode get_shader_mode() const; + RID get_shader_rid() const; + + ProceduralSkyMaterial(); + ~ProceduralSkyMaterial(); +}; + +////////////////////////////////////////////////////// +/* PanoramaSkyMaterial */ + +class PanoramaSkyMaterial : public Material { + GDCLASS(PanoramaSkyMaterial, Material); + +private: + Ref<Texture2D> panorama; + RID shader; + +protected: + static void _bind_methods(); + virtual bool _can_do_next_pass() const; + +public: + void set_panorama(const Ref<Texture2D> &p_panorama); + Ref<Texture2D> get_panorama() const; + + virtual Shader::Mode get_shader_mode() const; + RID get_shader_rid() const; + + PanoramaSkyMaterial(); + ~PanoramaSkyMaterial(); +}; + +////////////////////////////////////////////////////// +/* PanoramaSkyMaterial */ + +class PhysicalSkyMaterial : public Material { + GDCLASS(PhysicalSkyMaterial, Material); + +private: + RID shader; + + float rayleigh; + Color rayleigh_color; + float mie; + float mie_eccentricity; + Color mie_color; + float turbidity; + float sun_disk_scale; + Color ground_color; + float exposure; + float dither_strength; + +protected: + static void _bind_methods(); + virtual bool _can_do_next_pass() const; + +public: + void set_rayleigh_coefficient(float p_rayleigh); + float get_rayleigh_coefficient() const; + + void set_rayleigh_color(Color p_rayleigh_color); + Color get_rayleigh_color() const; + + void set_turbidity(float p_turbidity); + float get_turbidity() const; + + void set_mie_coefficient(float p_mie); + float get_mie_coefficient() const; + + void set_mie_eccentricity(float p_eccentricity); + float get_mie_eccentricity() const; + + void set_mie_color(Color p_mie_color); + Color get_mie_color() const; + + void set_sun_disk_scale(float p_sun_disk_scale); + float get_sun_disk_scale() const; + + void set_ground_color(Color p_ground_color); + Color get_ground_color() const; + + void set_exposure(float p_exposure); + float get_exposure() const; + + void set_dither_strength(float p_dither_strength); + float get_dither_strength() const; + + virtual Shader::Mode get_shader_mode() const; + RID get_shader_rid() const; + + PhysicalSkyMaterial(); + ~PhysicalSkyMaterial(); +}; + +#endif /* !SKY_MATERIAL_H */ diff --git a/scene/resources/space_2d.cpp b/scene/resources/space_2d.cpp deleted file mode 100644 index 376e926548..0000000000 --- a/scene/resources/space_2d.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************/ -/* space_2d.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 "space_2d.h" - -RID Space2D::get_rid() const { - - return space; -} - -void Space2D::set_active(bool p_active) { - - active = p_active; - Physics2DServer::get_singleton()->space_set_active(space, active); -} - -bool Space2D::is_active() const { - - return active; -} - -void Space2D::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_active", "active"), &Space2D::set_active); - ClassDB::bind_method(D_METHOD("is_active"), &Space2D::is_active); - - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "is_active"); -} - -Space2D::Space2D() { - - active = false; - space = Physics2DServer::get_singleton()->space_create(); -} - -Space2D::~Space2D() { - - Physics2DServer::get_singleton()->free(space); -} diff --git a/scene/resources/space_2d.h b/scene/resources/space_2d.h deleted file mode 100644 index ff88c40348..0000000000 --- a/scene/resources/space_2d.h +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************/ -/* space_2d.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 SPACE_2D_H -#define SPACE_2D_H - -#include "core/resource.h" -#include "servers/physics_2d_server.h" - -class Space2D : public Resource { - - GDCLASS(Space2D, Resource); - bool active; - RID space; - -protected: - static void _bind_methods(); - -public: - void set_active(bool p_active); - bool is_active() const; - - virtual RID get_rid() const; - - Space2D(); - ~Space2D(); -}; - -#endif // SPACE_2D_H diff --git a/scene/resources/sphere_shape.cpp b/scene/resources/sphere_shape_3d.cpp index 825708d1e2..153db4c291 100644 --- a/scene/resources/sphere_shape.cpp +++ b/scene/resources/sphere_shape_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* sphere_shape.cpp */ +/* sphere_shape_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,10 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "sphere_shape.h" -#include "servers/physics_server.h" +#include "sphere_shape_3d.h" +#include "servers/physics_server_3d.h" -Vector<Vector3> SphereShape::get_debug_mesh_lines() { +Vector<Vector3> SphereShape3D::get_debug_mesh_lines() { float r = get_radius(); @@ -55,17 +55,17 @@ Vector<Vector3> SphereShape::get_debug_mesh_lines() { return points; } -real_t SphereShape::get_enclosing_radius() const { +real_t SphereShape3D::get_enclosing_radius() const { return radius; } -void SphereShape::_update_shape() { +void SphereShape3D::_update_shape() { - PhysicsServer::get_singleton()->shape_set_data(get_shape(), radius); - Shape::_update_shape(); + PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), radius); + Shape3D::_update_shape(); } -void SphereShape::set_radius(float p_radius) { +void SphereShape3D::set_radius(float p_radius) { radius = p_radius; _update_shape(); @@ -73,21 +73,21 @@ void SphereShape::set_radius(float p_radius) { _change_notify("radius"); } -float SphereShape::get_radius() const { +float SphereShape3D::get_radius() const { return radius; } -void SphereShape::_bind_methods() { +void SphereShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_radius", "radius"), &SphereShape::set_radius); - ClassDB::bind_method(D_METHOD("get_radius"), &SphereShape::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "radius"), &SphereShape3D::set_radius); + ClassDB::bind_method(D_METHOD("get_radius"), &SphereShape3D::get_radius); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0,4096,0.01"), "set_radius", "get_radius"); } -SphereShape::SphereShape() : - Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_SPHERE)) { +SphereShape3D::SphereShape3D() : + Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_SPHERE)) { set_radius(1.0); } diff --git a/scene/resources/sphere_shape.h b/scene/resources/sphere_shape_3d.h index 07e8f1e233..3ed50cfe83 100644 --- a/scene/resources/sphere_shape.h +++ b/scene/resources/sphere_shape_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* sphere_shape.h */ +/* sphere_shape_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef SPHERE_SHAPE_H -#define SPHERE_SHAPE_H +#ifndef SPHERE_SHAPE_3D_H +#define SPHERE_SHAPE_3D_H -#include "scene/resources/shape.h" +#include "scene/resources/shape_3d.h" -class SphereShape : public Shape { +class SphereShape3D : public Shape3D { - GDCLASS(SphereShape, Shape); + GDCLASS(SphereShape3D, Shape3D); float radius; protected: @@ -50,7 +50,7 @@ public: virtual Vector<Vector3> get_debug_mesh_lines(); virtual real_t get_enclosing_radius() const; - SphereShape(); + SphereShape3D(); }; #endif // SPHERE_SHAPE_H diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 119cbcd098..56fb5d441f 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -29,7 +29,8 @@ /*************************************************************************/ #include "style_box.h" -#include "scene/2d/canvas_item.h" + +#include "scene/main/canvas_item.h" #include <limits.h> @@ -201,7 +202,7 @@ void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const { if (normal_map.is_valid()) normal_rid = normal_map->get_rid(); - VisualServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NinePatchAxisMode(axis_h), VS::NinePatchAxisMode(axis_v), draw_center, modulate, normal_rid); + RenderingServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center, modulate, normal_rid); } void StyleBoxTexture::set_draw_center(bool p_enabled) { @@ -852,7 +853,7 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const { } //DRAWING - VisualServer *vs = VisualServer::get_singleton(); + RenderingServer *vs = RenderingServer::get_singleton(); vs->canvas_item_add_triangle_array(p_canvas_item, indices, verts, colors, uvs); } @@ -1049,7 +1050,7 @@ Size2 StyleBoxLine::get_center_size() const { } void StyleBoxLine::draw(RID p_canvas_item, const Rect2 &p_rect) const { - VisualServer *vs = VisualServer::get_singleton(); + RenderingServer *vs = RenderingServer::get_singleton(); Rect2i r = p_rect; if (vertical) { diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h index 1aa1a00c55..f19b93d00d 100644 --- a/scene/resources/style_box.h +++ b/scene/resources/style_box.h @@ -33,7 +33,7 @@ #include "core/resource.h" #include "scene/resources/texture.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" class CanvasItem; diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index fa177d03fb..4b392e23b7 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -519,7 +519,7 @@ void SurfaceTool::deindex() { void SurfaceTool::_create_list(const Ref<Mesh> &p_existing, int p_surface, List<Vertex> *r_vertex, List<int> *r_index, int &lformat) { Array arr = p_existing->surface_get_arrays(p_surface); - ERR_FAIL_COND(arr.size() != VS::ARRAY_MAX); + ERR_FAIL_COND(arr.size() != RS::ARRAY_MAX); _create_list_from_arrays(arr, r_vertex, r_index, lformat); } @@ -527,14 +527,14 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array Vector<SurfaceTool::Vertex> ret; - Vector<Vector3> varr = p_arrays[VS::ARRAY_VERTEX]; - Vector<Vector3> narr = p_arrays[VS::ARRAY_NORMAL]; - Vector<float> tarr = p_arrays[VS::ARRAY_TANGENT]; - Vector<Color> carr = p_arrays[VS::ARRAY_COLOR]; - Vector<Vector2> uvarr = p_arrays[VS::ARRAY_TEX_UV]; - Vector<Vector2> uv2arr = p_arrays[VS::ARRAY_TEX_UV2]; - Vector<int> barr = p_arrays[VS::ARRAY_BONES]; - Vector<float> warr = p_arrays[VS::ARRAY_WEIGHTS]; + Vector<Vector3> varr = p_arrays[RS::ARRAY_VERTEX]; + Vector<Vector3> narr = p_arrays[RS::ARRAY_NORMAL]; + Vector<float> tarr = p_arrays[RS::ARRAY_TANGENT]; + Vector<Color> carr = p_arrays[RS::ARRAY_COLOR]; + Vector<Vector2> uvarr = p_arrays[RS::ARRAY_TEX_UV]; + Vector<Vector2> uv2arr = p_arrays[RS::ARRAY_TEX_UV2]; + Vector<int> barr = p_arrays[RS::ARRAY_BONES]; + Vector<float> warr = p_arrays[RS::ARRAY_WEIGHTS]; int vc = varr.size(); if (vc == 0) @@ -542,48 +542,48 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array int lformat = 0; if (varr.size()) { - lformat |= VS::ARRAY_FORMAT_VERTEX; + lformat |= RS::ARRAY_FORMAT_VERTEX; } if (narr.size()) { - lformat |= VS::ARRAY_FORMAT_NORMAL; + lformat |= RS::ARRAY_FORMAT_NORMAL; } if (tarr.size()) { - lformat |= VS::ARRAY_FORMAT_TANGENT; + lformat |= RS::ARRAY_FORMAT_TANGENT; } if (carr.size()) { - lformat |= VS::ARRAY_FORMAT_COLOR; + lformat |= RS::ARRAY_FORMAT_COLOR; } if (uvarr.size()) { - lformat |= VS::ARRAY_FORMAT_TEX_UV; + lformat |= RS::ARRAY_FORMAT_TEX_UV; } if (uv2arr.size()) { - lformat |= VS::ARRAY_FORMAT_TEX_UV2; + lformat |= RS::ARRAY_FORMAT_TEX_UV2; } if (barr.size()) { - lformat |= VS::ARRAY_FORMAT_BONES; + lformat |= RS::ARRAY_FORMAT_BONES; } if (warr.size()) { - lformat |= VS::ARRAY_FORMAT_WEIGHTS; + lformat |= RS::ARRAY_FORMAT_WEIGHTS; } for (int i = 0; i < vc; i++) { Vertex v; - if (lformat & VS::ARRAY_FORMAT_VERTEX) + if (lformat & RS::ARRAY_FORMAT_VERTEX) v.vertex = varr[i]; - if (lformat & VS::ARRAY_FORMAT_NORMAL) + if (lformat & RS::ARRAY_FORMAT_NORMAL) v.normal = narr[i]; - if (lformat & VS::ARRAY_FORMAT_TANGENT) { + if (lformat & RS::ARRAY_FORMAT_TANGENT) { Plane p(tarr[i * 4 + 0], tarr[i * 4 + 1], tarr[i * 4 + 2], tarr[i * 4 + 3]); v.tangent = p.normal; v.binormal = p.normal.cross(v.tangent).normalized() * p.d; } - if (lformat & VS::ARRAY_FORMAT_COLOR) + if (lformat & RS::ARRAY_FORMAT_COLOR) v.color = carr[i]; - if (lformat & VS::ARRAY_FORMAT_TEX_UV) + if (lformat & RS::ARRAY_FORMAT_TEX_UV) v.uv = uvarr[i]; - if (lformat & VS::ARRAY_FORMAT_TEX_UV2) + if (lformat & RS::ARRAY_FORMAT_TEX_UV2) v.uv2 = uv2arr[i]; - if (lformat & VS::ARRAY_FORMAT_BONES) { + if (lformat & RS::ARRAY_FORMAT_BONES) { Vector<int> b; b.resize(4); b.write[0] = barr[i * 4 + 0]; @@ -592,7 +592,7 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array b.write[3] = barr[i * 4 + 3]; v.bones = b; } - if (lformat & VS::ARRAY_FORMAT_WEIGHTS) { + if (lformat & RS::ARRAY_FORMAT_WEIGHTS) { Vector<float> w; w.resize(4); w.write[0] = warr[i * 4 + 0]; @@ -610,14 +610,14 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, List<int> *r_index, int &lformat) { - Vector<Vector3> varr = arr[VS::ARRAY_VERTEX]; - Vector<Vector3> narr = arr[VS::ARRAY_NORMAL]; - Vector<float> tarr = arr[VS::ARRAY_TANGENT]; - Vector<Color> carr = arr[VS::ARRAY_COLOR]; - Vector<Vector2> uvarr = arr[VS::ARRAY_TEX_UV]; - Vector<Vector2> uv2arr = arr[VS::ARRAY_TEX_UV2]; - Vector<int> barr = arr[VS::ARRAY_BONES]; - Vector<float> warr = arr[VS::ARRAY_WEIGHTS]; + Vector<Vector3> varr = arr[RS::ARRAY_VERTEX]; + Vector<Vector3> narr = arr[RS::ARRAY_NORMAL]; + Vector<float> tarr = arr[RS::ARRAY_TANGENT]; + Vector<Color> carr = arr[RS::ARRAY_COLOR]; + Vector<Vector2> uvarr = arr[RS::ARRAY_TEX_UV]; + Vector<Vector2> uv2arr = arr[RS::ARRAY_TEX_UV2]; + Vector<int> barr = arr[RS::ARRAY_BONES]; + Vector<float> warr = arr[RS::ARRAY_WEIGHTS]; int vc = varr.size(); if (vc == 0) @@ -625,48 +625,48 @@ void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, Li lformat = 0; if (varr.size()) { - lformat |= VS::ARRAY_FORMAT_VERTEX; + lformat |= RS::ARRAY_FORMAT_VERTEX; } if (narr.size()) { - lformat |= VS::ARRAY_FORMAT_NORMAL; + lformat |= RS::ARRAY_FORMAT_NORMAL; } if (tarr.size()) { - lformat |= VS::ARRAY_FORMAT_TANGENT; + lformat |= RS::ARRAY_FORMAT_TANGENT; } if (carr.size()) { - lformat |= VS::ARRAY_FORMAT_COLOR; + lformat |= RS::ARRAY_FORMAT_COLOR; } if (uvarr.size()) { - lformat |= VS::ARRAY_FORMAT_TEX_UV; + lformat |= RS::ARRAY_FORMAT_TEX_UV; } if (uv2arr.size()) { - lformat |= VS::ARRAY_FORMAT_TEX_UV2; + lformat |= RS::ARRAY_FORMAT_TEX_UV2; } if (barr.size()) { - lformat |= VS::ARRAY_FORMAT_BONES; + lformat |= RS::ARRAY_FORMAT_BONES; } if (warr.size()) { - lformat |= VS::ARRAY_FORMAT_WEIGHTS; + lformat |= RS::ARRAY_FORMAT_WEIGHTS; } for (int i = 0; i < vc; i++) { Vertex v; - if (lformat & VS::ARRAY_FORMAT_VERTEX) + if (lformat & RS::ARRAY_FORMAT_VERTEX) v.vertex = varr[i]; - if (lformat & VS::ARRAY_FORMAT_NORMAL) + if (lformat & RS::ARRAY_FORMAT_NORMAL) v.normal = narr[i]; - if (lformat & VS::ARRAY_FORMAT_TANGENT) { + if (lformat & RS::ARRAY_FORMAT_TANGENT) { Plane p(tarr[i * 4 + 0], tarr[i * 4 + 1], tarr[i * 4 + 2], tarr[i * 4 + 3]); v.tangent = p.normal; v.binormal = p.normal.cross(v.tangent).normalized() * p.d; } - if (lformat & VS::ARRAY_FORMAT_COLOR) + if (lformat & RS::ARRAY_FORMAT_COLOR) v.color = carr[i]; - if (lformat & VS::ARRAY_FORMAT_TEX_UV) + if (lformat & RS::ARRAY_FORMAT_TEX_UV) v.uv = uvarr[i]; - if (lformat & VS::ARRAY_FORMAT_TEX_UV2) + if (lformat & RS::ARRAY_FORMAT_TEX_UV2) v.uv2 = uv2arr[i]; - if (lformat & VS::ARRAY_FORMAT_BONES) { + if (lformat & RS::ARRAY_FORMAT_BONES) { Vector<int> b; b.resize(4); b.write[0] = barr[i * 4 + 0]; @@ -675,7 +675,7 @@ void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, Li b.write[3] = barr[i * 4 + 3]; v.bones = b; } - if (lformat & VS::ARRAY_FORMAT_WEIGHTS) { + if (lformat & RS::ARRAY_FORMAT_WEIGHTS) { Vector<float> w; w.resize(4); w.write[0] = warr[i * 4 + 0]; @@ -690,11 +690,11 @@ void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, Li //indices - Vector<int> idx = arr[VS::ARRAY_INDEX]; + Vector<int> idx = arr[RS::ARRAY_INDEX]; int is = idx.size(); if (is) { - lformat |= VS::ARRAY_FORMAT_INDEX; + lformat |= RS::ARRAY_FORMAT_INDEX; const int *iarr = idx.ptr(); for (int i = 0; i < is; i++) { r_index->push_back(iarr[i]); @@ -733,7 +733,7 @@ void SurfaceTool::create_from_blend_shape(const Ref<Mesh> &p_existing, int p_sur ERR_FAIL_COND(shape_idx == -1); ERR_FAIL_COND(shape_idx >= arr.size()); Array mesh = arr[shape_idx]; - ERR_FAIL_COND(mesh.size() != VS::ARRAY_MAX); + ERR_FAIL_COND(mesh.size() != RS::ARRAY_MAX); _create_list_from_arrays(arr[shape_idx], &vertex_array, &index_array, format); } @@ -755,10 +755,10 @@ void SurfaceTool::append_from(const Ref<Mesh> &p_existing, int p_surface, const Vertex v = E->get(); v.vertex = p_xform.xform(v.vertex); - if (nformat & VS::ARRAY_FORMAT_NORMAL) { + if (nformat & RS::ARRAY_FORMAT_NORMAL) { v.normal = p_xform.basis.xform(v.normal); } - if (nformat & VS::ARRAY_FORMAT_TANGENT) { + if (nformat & RS::ARRAY_FORMAT_TANGENT) { v.tangent = p_xform.basis.xform(v.tangent); v.binormal = p_xform.basis.xform(v.binormal); } @@ -854,7 +854,7 @@ void SurfaceTool::mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, cons const tbool bIsOrientationPreserving, const int iFace, const int iVert) { TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData); - Vertex *vtx = NULL; + Vertex *vtx = nullptr; if (triangle_data.indices.size() > 0) { int index = triangle_data.indices[iFace * 3 + iVert]->get(); if (index < triangle_data.vertices.size()) { @@ -864,7 +864,7 @@ void SurfaceTool::mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, cons vtx = &triangle_data.vertices[iFace * 3 + iVert]->get(); } - if (vtx != NULL) { + if (vtx != nullptr) { vtx->tangent = Vector3(fvTangent[0], fvTangent[1], fvTangent[2]); vtx->binormal = Vector3(-fvBiTangent[0], -fvBiTangent[1], -fvBiTangent[2]); // for some reason these are reversed, something with the coordinate system in Godot } @@ -882,7 +882,7 @@ void SurfaceTool::generate_tangents() { mkif.m_getPosition = mikktGetPosition; mkif.m_getTexCoord = mikktGetTexCoord; mkif.m_setTSpace = mikktSetTSpaceDefault; - mkif.m_setTSpaceBasic = NULL; + mkif.m_setTSpaceBasic = nullptr; SMikkTSpaceContext msc; msc.m_pInterface = &mkif; diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 1c5b2abad2..f431a2ad48 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -47,25 +47,25 @@ bool Texture2D::is_pixel_opaque(int p_x, int p_y) const { return true; } -void Texture2D::draw(RID p_canvas_item, const Point2 &p_pos, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const { +void Texture2D::draw(RID p_canvas_item, const Point2 &p_pos, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VisualServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, get_size()), get_rid(), false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); + RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, get_size()), get_rid(), false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } -void Texture2D::draw_rect(RID p_canvas_item, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const { +void Texture2D::draw_rect(RID p_canvas_item, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VisualServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, get_rid(), p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); + RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, get_rid(), p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } -void Texture2D::draw_rect_region(RID p_canvas_item, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { +void Texture2D::draw_rect_region(RID p_canvas_item, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, get_rid(), p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat); + RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, get_rid(), p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat); } bool Texture2D::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const { @@ -82,9 +82,9 @@ void Texture2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_height"), &Texture2D::get_height); ClassDB::bind_method(D_METHOD("get_size"), &Texture2D::get_size); ClassDB::bind_method(D_METHOD("has_alpha"), &Texture2D::has_alpha); - ClassDB::bind_method(D_METHOD("draw", "canvas_item", "position", "modulate", "transpose", "normal_map", "specular_map", "specular_color_shininess", "texture_filter", "texture_repeat"), &Texture2D::draw, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT), DEFVAL(VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT)); - ClassDB::bind_method(D_METHOD("draw_rect", "canvas_item", "rect", "tile", "modulate", "transpose", "normal_map", "specular_map", "specular_color_shininess", "texture_filter", "texture_repeat"), &Texture2D::draw_rect, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT), DEFVAL(VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT)); - ClassDB::bind_method(D_METHOD("draw_rect_region", "canvas_item", "rect", "src_rect", "modulate", "transpose", "normal_map", "specular_map", "specular_color_shininess", "texture_filter", "texture_repeat", "clip_uv"), &Texture2D::draw_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT), DEFVAL(VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("draw", "canvas_item", "position", "modulate", "transpose", "normal_map", "specular_map", "specular_color_shininess", "texture_filter", "texture_repeat"), &Texture2D::draw, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT), DEFVAL(RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT)); + ClassDB::bind_method(D_METHOD("draw_rect", "canvas_item", "rect", "tile", "modulate", "transpose", "normal_map", "specular_map", "specular_color_shininess", "texture_filter", "texture_repeat"), &Texture2D::draw_rect, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT), DEFVAL(RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT)); + ClassDB::bind_method(D_METHOD("draw_rect_region", "canvas_item", "rect", "src_rect", "modulate", "transpose", "normal_map", "specular_map", "specular_color_shininess", "texture_filter", "texture_repeat", "clip_uv"), &Texture2D::draw_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(Variant()), DEFVAL(Color(1, 1, 1, 1)), DEFVAL(RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT), DEFVAL(RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT), DEFVAL(true)); ClassDB::bind_method(D_METHOD("get_data"), &Texture2D::get_data); ADD_GROUP("", ""); @@ -121,7 +121,7 @@ bool ImageTexture::_set(const StringName &p_name, const Variant &p_value) { Size2 s = p_value; w = s.width; h = s.height; - VisualServer::get_singleton()->texture_set_size_override(texture, w, h); + RenderingServer::get_singleton()->texture_set_size_override(texture, w, h); } else return false; @@ -158,8 +158,8 @@ void ImageTexture::_reload_hook(const RID &p_hook) { ERR_FAIL_COND_MSG(err != OK, "Cannot load image from path '" + path + "'."); - RID new_texture = VisualServer::get_singleton()->texture_2d_create(img); - VisualServer::get_singleton()->texture_replace(texture, new_texture); + RID new_texture = RenderingServer::get_singleton()->texture_2d_create(img); + RenderingServer::get_singleton()->texture_replace(texture, new_texture); _change_notify(); emit_changed(); @@ -174,10 +174,10 @@ void ImageTexture::create_from_image(const Ref<Image> &p_image) { mipmaps = p_image->has_mipmaps(); if (texture.is_null()) { - texture = VisualServer::get_singleton()->texture_2d_create(p_image); + texture = RenderingServer::get_singleton()->texture_2d_create(p_image); } else { - RID new_texture = VisualServer::get_singleton()->texture_2d_create(p_image); - VisualServer::get_singleton()->texture_replace(texture, new_texture); + RID new_texture = RenderingServer::get_singleton()->texture_2d_create(p_image); + RenderingServer::get_singleton()->texture_replace(texture, new_texture); } _change_notify(); emit_changed(); @@ -199,9 +199,9 @@ void ImageTexture::update(const Ref<Image> &p_image, bool p_immediate) { ERR_FAIL_COND(mipmaps != p_image->has_mipmaps()); if (p_immediate) { - VisualServer::get_singleton()->texture_2d_update_immediate(texture, p_image); + RenderingServer::get_singleton()->texture_2d_update_immediate(texture, p_image); } else { - VisualServer::get_singleton()->texture_2d_update(texture, p_image); + RenderingServer::get_singleton()->texture_2d_update(texture, p_image); } _change_notify(); @@ -219,7 +219,7 @@ void ImageTexture::_resource_path_changed() { Ref<Image> ImageTexture::get_data() const { if (image_stored) { - return VisualServer::get_singleton()->texture_2d_get(texture); + return RenderingServer::get_singleton()->texture_2d_get(texture); } else { return Ref<Image>(); } @@ -239,7 +239,7 @@ RID ImageTexture::get_rid() const { if (texture.is_null()) { //we are in trouble, create something temporary - texture = VisualServer::get_singleton()->texture_2d_placeholder_create(); + texture = RenderingServer::get_singleton()->texture_2d_placeholder_create(); } return texture; } @@ -249,29 +249,29 @@ bool ImageTexture::has_alpha() const { return (format == Image::FORMAT_LA8 || format == Image::FORMAT_RGBA8); } -void ImageTexture::draw(RID p_canvas_item, const Point2 &p_pos, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const { +void ImageTexture::draw(RID p_canvas_item, const Point2 &p_pos, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { if ((w | h) == 0) return; RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VisualServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); + RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } -void ImageTexture::draw_rect(RID p_canvas_item, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const { +void ImageTexture::draw_rect(RID p_canvas_item, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { if ((w | h) == 0) return; RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VisualServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); + RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } -void ImageTexture::draw_rect_region(RID p_canvas_item, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { +void ImageTexture::draw_rect_region(RID p_canvas_item, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { if ((w | h) == 0) return; RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, texture, p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat); + RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, texture, p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat); } bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const { @@ -316,13 +316,13 @@ void ImageTexture::set_size_override(const Size2 &p_size) { w = s.x; if (s.y != 0) h = s.y; - VisualServer::get_singleton()->texture_set_size_override(texture, w, h); + RenderingServer::get_singleton()->texture_set_size_override(texture, w, h); } void ImageTexture::set_path(const String &p_path, bool p_take_over) { if (texture.is_valid()) { - VisualServer::get_singleton()->texture_set_path(texture, p_path); + RenderingServer::get_singleton()->texture_set_path(texture, p_path); } Resource::set_path(p_path, p_take_over); @@ -349,7 +349,7 @@ ImageTexture::ImageTexture() { ImageTexture::~ImageTexture() { if (texture.is_valid()) { - VisualServer::get_singleton()->free(texture); + RenderingServer::get_singleton()->free(texture); } } @@ -495,7 +495,7 @@ Ref<Image> StreamTexture::load_image_from_file(FileAccess *f, int p_size_limit) void StreamTexture::set_path(const String &p_path, bool p_take_over) { if (texture.is_valid()) { - VisualServer::get_singleton()->texture_set_path(texture, p_path); + RenderingServer::get_singleton()->texture_set_path(texture, p_path); } Resource::set_path(p_path, p_take_over); @@ -509,7 +509,7 @@ void StreamTexture::_requested_3d(void *p_ud) { request_3d_callback(stex); } -void StreamTexture::_requested_roughness(void *p_ud, const String &p_normal_path, VS::TextureDetectRoughnessChannel p_roughness_channel) { +void StreamTexture::_requested_roughness(void *p_ud, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel) { StreamTexture *st = (StreamTexture *)p_ud; Ref<StreamTexture> stex(st); @@ -525,9 +525,9 @@ void StreamTexture::_requested_normal(void *p_ud) { request_normal_callback(stex); } -StreamTexture::TextureFormatRequestCallback StreamTexture::request_3d_callback = NULL; -StreamTexture::TextureFormatRoughnessRequestCallback StreamTexture::request_roughness_callback = NULL; -StreamTexture::TextureFormatRequestCallback StreamTexture::request_normal_callback = NULL; +StreamTexture::TextureFormatRequestCallback StreamTexture::request_3d_callback = nullptr; +StreamTexture::TextureFormatRoughnessRequestCallback StreamTexture::request_roughness_callback = nullptr; +StreamTexture::TextureFormatRequestCallback StreamTexture::request_normal_callback = nullptr; Image::Format StreamTexture::get_format() const { @@ -611,13 +611,13 @@ Error StreamTexture::load(const String &p_path) { return err; if (texture.is_valid()) { - RID new_texture = VS::get_singleton()->texture_2d_create(image); - VS::get_singleton()->texture_replace(texture, new_texture); + RID new_texture = RS::get_singleton()->texture_2d_create(image); + RS::get_singleton()->texture_replace(texture, new_texture); } else { - texture = VS::get_singleton()->texture_2d_create(image); + texture = RS::get_singleton()->texture_2d_create(image); } if (lwc || lhc) { - VS::get_singleton()->texture_set_size_override(texture, lwc, lhc); + RS::get_singleton()->texture_set_size_override(texture, lwc, lhc); } w = lwc ? lwc : lw; @@ -627,33 +627,33 @@ Error StreamTexture::load(const String &p_path) { if (get_path() == String()) { //temporarily set path if no path set for resource, helps find errors - VisualServer::get_singleton()->texture_set_path(texture, p_path); + RenderingServer::get_singleton()->texture_set_path(texture, p_path); } #ifdef TOOLS_ENABLED if (request_3d) { //print_line("request detect 3D at " + p_path); - VS::get_singleton()->texture_set_detect_3d_callback(texture, _requested_3d, this); + RS::get_singleton()->texture_set_detect_3d_callback(texture, _requested_3d, this); } else { //print_line("not requesting detect 3D at " + p_path); - VS::get_singleton()->texture_set_detect_3d_callback(texture, NULL, NULL); + RS::get_singleton()->texture_set_detect_3d_callback(texture, nullptr, nullptr); } if (request_roughness) { //print_line("request detect srgb at " + p_path); - VS::get_singleton()->texture_set_detect_roughness_callback(texture, _requested_roughness, this); + RS::get_singleton()->texture_set_detect_roughness_callback(texture, _requested_roughness, this); } else { //print_line("not requesting detect srgb at " + p_path); - VS::get_singleton()->texture_set_detect_roughness_callback(texture, NULL, NULL); + RS::get_singleton()->texture_set_detect_roughness_callback(texture, nullptr, nullptr); } if (request_normal) { //print_line("request detect srgb at " + p_path); - VS::get_singleton()->texture_set_detect_normal_callback(texture, _requested_normal, this); + RS::get_singleton()->texture_set_detect_normal_callback(texture, _requested_normal, this); } else { //print_line("not requesting detect normal at " + p_path); - VS::get_singleton()->texture_set_detect_normal_callback(texture, NULL, NULL); + RS::get_singleton()->texture_set_detect_normal_callback(texture, nullptr, nullptr); } #endif @@ -677,34 +677,34 @@ int StreamTexture::get_height() const { RID StreamTexture::get_rid() const { if (!texture.is_valid()) { - texture = VS::get_singleton()->texture_2d_placeholder_create(); + texture = RS::get_singleton()->texture_2d_placeholder_create(); } return texture; } -void StreamTexture::draw(RID p_canvas_item, const Point2 &p_pos, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const { +void StreamTexture::draw(RID p_canvas_item, const Point2 &p_pos, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { if ((w | h) == 0) return; RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VisualServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); + RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } -void StreamTexture::draw_rect(RID p_canvas_item, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const { +void StreamTexture::draw_rect(RID p_canvas_item, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { if ((w | h) == 0) return; RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VisualServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); + RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } -void StreamTexture::draw_rect_region(RID p_canvas_item, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { +void StreamTexture::draw_rect_region(RID p_canvas_item, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { if ((w | h) == 0) return; RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, texture, p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat); + RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, texture, p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat); } bool StreamTexture::has_alpha() const { @@ -715,7 +715,7 @@ bool StreamTexture::has_alpha() const { Ref<Image> StreamTexture::get_data() const { if (texture.is_valid()) { - return VS::get_singleton()->texture_2d_get(texture); + return RS::get_singleton()->texture_2d_get(texture); } else { return Ref<Image>(); } @@ -792,11 +792,11 @@ StreamTexture::StreamTexture() { StreamTexture::~StreamTexture() { if (texture.is_valid()) { - VS::get_singleton()->free(texture); + RS::get_singleton()->free(texture); } } -RES ResourceFormatLoaderStreamTexture::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) { +RES ResourceFormatLoaderStreamTexture::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { Ref<StreamTexture> st; st.instance(); @@ -935,7 +935,7 @@ void AtlasTexture::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_clip"), "set_filter_clip", "has_filter_clip"); } -void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const { +void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { if (!atlas.is_valid()) return; @@ -952,10 +952,10 @@ void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(p_pos + margin.position, rc.size), atlas->get_rid(), rc, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, filter_clip, p_texture_filter, p_texture_repeat); + RS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(p_pos + margin.position, rc.size), atlas->get_rid(), rc, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, filter_clip, p_texture_filter, p_texture_repeat); } -void AtlasTexture::draw_rect(RID p_canvas_item, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const { +void AtlasTexture::draw_rect(RID p_canvas_item, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { if (!atlas.is_valid()) return; @@ -975,9 +975,9 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, dr, atlas->get_rid(), rc, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, filter_clip, p_texture_filter, p_texture_repeat); + RS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, dr, atlas->get_rid(), rc, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, filter_clip, p_texture_filter, p_texture_repeat); } -void AtlasTexture::draw_rect_region(RID p_canvas_item, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { +void AtlasTexture::draw_rect_region(RID p_canvas_item, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { //this might not necessarily work well if using a rect, needs to be fixed properly if (!atlas.is_valid()) @@ -989,7 +989,7 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, dr, atlas->get_rid(), src_c, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, filter_clip, p_texture_filter, p_texture_repeat); + RS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, dr, atlas->get_rid(), src_c, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, filter_clip, p_texture_filter, p_texture_repeat); } bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const { @@ -1087,7 +1087,7 @@ Ref<Texture2D> MeshTexture::get_base_texture() const { return base_texture; } -void MeshTexture::draw(RID p_canvas_item, const Point2 &p_pos, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const { +void MeshTexture::draw(RID p_canvas_item, const Point2 &p_pos, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { if (mesh.is_null() || base_texture.is_null()) { return; @@ -1100,9 +1100,9 @@ void MeshTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_mo } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VisualServer::get_singleton()->canvas_item_add_mesh(p_canvas_item, mesh->get_rid(), xform, p_modulate, base_texture->get_rid(), normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); + RenderingServer::get_singleton()->canvas_item_add_mesh(p_canvas_item, mesh->get_rid(), xform, p_modulate, base_texture->get_rid(), normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } -void MeshTexture::draw_rect(RID p_canvas_item, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const { +void MeshTexture::draw_rect(RID p_canvas_item, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { if (mesh.is_null() || base_texture.is_null()) { return; } @@ -1123,9 +1123,9 @@ void MeshTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VisualServer::get_singleton()->canvas_item_add_mesh(p_canvas_item, mesh->get_rid(), xform, p_modulate, base_texture->get_rid(), normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); + RenderingServer::get_singleton()->canvas_item_add_mesh(p_canvas_item, mesh->get_rid(), xform, p_modulate, base_texture->get_rid(), normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } -void MeshTexture::draw_rect_region(RID p_canvas_item, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { +void MeshTexture::draw_rect_region(RID p_canvas_item, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { if (mesh.is_null() || base_texture.is_null()) { return; @@ -1147,7 +1147,7 @@ void MeshTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); - VisualServer::get_singleton()->canvas_item_add_mesh(p_canvas_item, mesh->get_rid(), xform, p_modulate, base_texture->get_rid(), normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); + RenderingServer::get_singleton()->canvas_item_add_mesh(p_canvas_item, mesh->get_rid(), xform, p_modulate, base_texture->get_rid(), normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } bool MeshTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const { r_rect = p_rect; @@ -1300,7 +1300,7 @@ void LargeTexture::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data"); } -void LargeTexture::draw(RID p_canvas_item, const Point2 &p_pos, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const { +void LargeTexture::draw(RID p_canvas_item, const Point2 &p_pos, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { for (int i = 0; i < pieces.size(); i++) { @@ -1309,7 +1309,7 @@ void LargeTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m } } -void LargeTexture::draw_rect(RID p_canvas_item, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat) const { +void LargeTexture::draw_rect(RID p_canvas_item, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { //tiling not supported for this if (size.x == 0 || size.y == 0) @@ -1323,7 +1323,7 @@ void LargeTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile pieces[i].texture->draw_rect(p_canvas_item, Rect2(pieces[i].offset * scale + p_rect.position, pieces[i].texture->get_size() * scale), false, p_modulate, p_transpose, p_normal_map, p_specular_map, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } } -void LargeTexture::draw_rect_region(RID p_canvas_item, 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, VS::CanvasItemTextureFilter p_texture_filter, VS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { +void LargeTexture::draw_rect_region(RID p_canvas_item, 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, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { //tiling not supported for this if (p_src_rect.size.x == 0 || p_src_rect.size.y == 0) @@ -1445,10 +1445,10 @@ void CurveTexture::_update() { Ref<Image> image = memnew(Image(_width, 1, false, Image::FORMAT_RF, data)); if (_texture.is_valid()) { - RID new_texture = VS::get_singleton()->texture_2d_create(image); - VS::get_singleton()->texture_replace(_texture, new_texture); + RID new_texture = RS::get_singleton()->texture_2d_create(image); + RS::get_singleton()->texture_replace(_texture, new_texture); } else { - _texture = VS::get_singleton()->texture_2d_create(image); + _texture = RS::get_singleton()->texture_2d_create(image); } emit_changed(); @@ -1462,7 +1462,7 @@ Ref<Curve> CurveTexture::get_curve() const { RID CurveTexture::get_rid() const { if (!_texture.is_valid()) { - _texture = VS::get_singleton()->texture_2d_placeholder_create(); + _texture = RS::get_singleton()->texture_2d_placeholder_create(); } return _texture; } @@ -1472,7 +1472,7 @@ CurveTexture::CurveTexture() { } CurveTexture::~CurveTexture() { if (_texture.is_valid()) { - VS::get_singleton()->free(_texture); + RS::get_singleton()->free(_texture); } } ////////////////// @@ -1492,7 +1492,7 @@ GradientTexture::GradientTexture() { GradientTexture::~GradientTexture() { if (texture.is_valid()) { - VS::get_singleton()->free(texture); + RS::get_singleton()->free(texture); } } @@ -1564,10 +1564,10 @@ void GradientTexture::_update() { Ref<Image> image = memnew(Image(width, 1, false, Image::FORMAT_RGBA8, data)); if (texture.is_valid()) { - RID new_texture = VS::get_singleton()->texture_2d_create(image); - VS::get_singleton()->texture_replace(texture, new_texture); + RID new_texture = RS::get_singleton()->texture_2d_create(image); + RS::get_singleton()->texture_replace(texture, new_texture); } else { - texture = VS::get_singleton()->texture_2d_create(image); + texture = RS::get_singleton()->texture_2d_create(image); } emit_changed(); @@ -1587,7 +1587,7 @@ Ref<Image> GradientTexture::get_data() const { if (!texture.is_valid()) { return Ref<Image>(); } - return VisualServer::get_singleton()->texture_2d_get(texture); + return RenderingServer::get_singleton()->texture_2d_get(texture); } ////////////////////////////////////// @@ -1607,13 +1607,13 @@ void ProxyTexture::set_base(const Ref<Texture2D> &p_texture) { base = p_texture; if (base.is_valid()) { if (proxy_ph.is_valid()) { - VS::get_singleton()->texture_proxy_update(proxy, base->get_rid()); - VS::get_singleton()->free(proxy_ph); + RS::get_singleton()->texture_proxy_update(proxy, base->get_rid()); + RS::get_singleton()->free(proxy_ph); proxy_ph = RID(); } else if (proxy.is_valid()) { - VS::get_singleton()->texture_proxy_update(proxy, base->get_rid()); + RS::get_singleton()->texture_proxy_update(proxy, base->get_rid()); } else { - proxy = VS::get_singleton()->texture_proxy_create(base->get_rid()); + proxy = RS::get_singleton()->texture_proxy_create(base->get_rid()); } } } @@ -1638,8 +1638,8 @@ int ProxyTexture::get_height() const { RID ProxyTexture::get_rid() const { if (proxy.is_null()) { - proxy_ph = VS::get_singleton()->texture_2d_placeholder_create(); - proxy = VS::get_singleton()->texture_proxy_create(proxy_ph); + proxy_ph = RS::get_singleton()->texture_2d_placeholder_create(); + proxy = RS::get_singleton()->texture_proxy_create(proxy_ph); } return proxy; } @@ -1653,16 +1653,16 @@ bool ProxyTexture::has_alpha() const { ProxyTexture::ProxyTexture() { - //proxy = VS::get_singleton()->texture_create(); + //proxy = RS::get_singleton()->texture_create(); } ProxyTexture::~ProxyTexture() { if (proxy_ph.is_valid()) { - VS::get_singleton()->free(proxy_ph); + RS::get_singleton()->free(proxy_ph); } if (proxy.is_valid()) { - VS::get_singleton()->free(proxy); + RS::get_singleton()->free(proxy); } } ////////////////////////////////////////////// @@ -1708,7 +1708,7 @@ void AnimatedTexture::_update_proxy() { } if (frames[current_frame].texture.is_valid()) { - VisualServer::get_singleton()->texture_proxy_update(proxy, frames[current_frame].texture->get_rid()); + RenderingServer::get_singleton()->texture_proxy_update(proxy, frames[current_frame].texture->get_rid()); } } @@ -1854,28 +1854,28 @@ void AnimatedTexture::_bind_methods() { } AnimatedTexture::AnimatedTexture() { - //proxy = VS::get_singleton()->texture_create(); - proxy_ph = VS::get_singleton()->texture_2d_placeholder_create(); - proxy = VS::get_singleton()->texture_proxy_create(proxy_ph); + //proxy = RS::get_singleton()->texture_create(); + proxy_ph = RS::get_singleton()->texture_2d_placeholder_create(); + proxy = RS::get_singleton()->texture_proxy_create(proxy_ph); - VisualServer::get_singleton()->texture_set_force_redraw_if_visible(proxy, true); + RenderingServer::get_singleton()->texture_set_force_redraw_if_visible(proxy, true); time = 0; frame_count = 1; fps = 4; prev_ticks = 0; current_frame = 0; - VisualServer::get_singleton()->connect("frame_pre_draw", callable_mp(this, &AnimatedTexture::_update_proxy)); + RenderingServer::get_singleton()->connect("frame_pre_draw", callable_mp(this, &AnimatedTexture::_update_proxy)); #ifndef NO_THREADS rw_lock = RWLock::create(); #else - rw_lock = NULL; + rw_lock = nullptr; #endif } AnimatedTexture::~AnimatedTexture() { - VS::get_singleton()->free(proxy); - VS::get_singleton()->free(proxy_ph); + RS::get_singleton()->free(proxy); + RS::get_singleton()->free(proxy_ph); if (rw_lock) { memdelete(rw_lock); } @@ -1921,10 +1921,10 @@ Error TextureLayered::create_from_images(Vector<Ref<Image>> p_images) { int new_layers = p_images.size(); ERR_FAIL_COND_V(new_layers == 0, ERR_INVALID_PARAMETER); - if (layered_type == VS::TEXTURE_LAYERED_CUBEMAP) { + if (layered_type == RS::TEXTURE_LAYERED_CUBEMAP) { ERR_FAIL_COND_V_MSG(new_layers != 6, ERR_INVALID_PARAMETER, "Cubemaps require exactly 6 layers"); - } else if (layered_type == VS::TEXTURE_LAYERED_CUBEMAP_ARRAY) { + } else if (layered_type == RS::TEXTURE_LAYERED_CUBEMAP_ARRAY) { ERR_FAIL_COND_V_MSG((new_layers % 6) != 0, ERR_INVALID_PARAMETER, "Cubemap array layers must be a multiple of 6"); } @@ -1946,11 +1946,11 @@ Error TextureLayered::create_from_images(Vector<Ref<Image>> p_images) { } if (texture.is_valid()) { - RID new_texture = VS::get_singleton()->texture_2d_layered_create(p_images, layered_type); + RID new_texture = RS::get_singleton()->texture_2d_layered_create(p_images, layered_type); ERR_FAIL_COND_V(!new_texture.is_valid(), ERR_CANT_CREATE); - VS::get_singleton()->texture_replace(texture, new_texture); + RS::get_singleton()->texture_replace(texture, new_texture); } else { - texture = VS::get_singleton()->texture_2d_layered_create(p_images, layered_type); + texture = RS::get_singleton()->texture_2d_layered_create(p_images, layered_type); ERR_FAIL_COND_V(!texture.is_valid(), ERR_CANT_CREATE); } @@ -1969,24 +1969,24 @@ void TextureLayered::update_layer(const Ref<Image> &p_image, int p_layer) { ERR_FAIL_COND(p_image->get_width() != width || p_image->get_height() != height); ERR_FAIL_INDEX(p_layer, layers); ERR_FAIL_COND(p_image->has_mipmaps() != mipmaps); - VS::get_singleton()->texture_2d_update(texture, p_image, p_layer); + RS::get_singleton()->texture_2d_update(texture, p_image, p_layer); } Ref<Image> TextureLayered::get_layer_data(int p_layer) const { ERR_FAIL_INDEX_V(p_layer, layers, Ref<Image>()); - return VS::get_singleton()->texture_2d_layer_get(texture, p_layer); + return RS::get_singleton()->texture_2d_layer_get(texture, p_layer); } RID TextureLayered::get_rid() const { if (texture.is_null()) { - texture = VS::get_singleton()->texture_2d_layered_placeholder_create(); + texture = RS::get_singleton()->texture_2d_layered_placeholder_create(); } return texture; } void TextureLayered::set_path(const String &p_path, bool p_take_over) { if (texture.is_valid()) { - VS::get_singleton()->texture_set_path(texture, p_path); + RS::get_singleton()->texture_set_path(texture, p_path); } Resource::set_path(p_path, p_take_over); @@ -2009,7 +2009,7 @@ void TextureLayered::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_images", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_INTERNAL), "create_from_images", "_get_images"); } -TextureLayered::TextureLayered(VisualServer::TextureLayeredType p_layered_type) { +TextureLayered::TextureLayered(RenderingServer::TextureLayeredType p_layered_type) { layered_type = p_layered_type; format = Image::FORMAT_MAX; @@ -2020,11 +2020,11 @@ TextureLayered::TextureLayered(VisualServer::TextureLayeredType p_layered_type) TextureLayered::~TextureLayered() { if (texture.is_valid()) { - VS::get_singleton()->free(texture); + RS::get_singleton()->free(texture); } } -RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) { +RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { if (r_error) { *r_error = ERR_CANT_OPEN; diff --git a/scene/resources/texture.h b/scene/resources/texture.h index 1fb8742cec..f4f00c2ca0 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -41,7 +41,7 @@ #include "scene/resources/curve.h" #include "scene/resources/gradient.h" #include "servers/camera_server.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" class Texture : public Resource { GDCLASS(Texture, Resource); @@ -68,9 +68,9 @@ public: virtual bool has_alpha() const = 0; - virtual void draw(RID p_canvas_item, const Point2 &p_pos, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; - virtual void draw_rect(RID p_canvas_item, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; - virtual void draw_rect_region(RID p_canvas_item, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, bool p_clip_uv = true) const; + virtual void draw(RID p_canvas_item, const Point2 &p_pos, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; + virtual void draw_rect(RID p_canvas_item, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; + virtual void draw_rect_region(RID p_canvas_item, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, bool p_clip_uv = true) const; virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const; virtual Ref<Image> get_data() const { return Ref<Image>(); } @@ -118,9 +118,9 @@ public: virtual RID get_rid() const; bool has_alpha() const; - virtual void draw(RID p_canvas_item, const Point2 &p_pos, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; - virtual void draw_rect(RID p_canvas_item, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; - virtual void draw_rect_region(RID p_canvas_item, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, bool p_clip_uv = true) const; + virtual void draw(RID p_canvas_item, const Point2 &p_pos, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; + virtual void draw_rect(RID p_canvas_item, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; + virtual void draw_rect_region(RID p_canvas_item, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, bool p_clip_uv = true) const; bool is_pixel_opaque(int p_x, int p_y) const; @@ -171,7 +171,7 @@ private: virtual void reload_from_file(); static void _requested_3d(void *p_ud); - static void _requested_roughness(void *p_ud, const String &p_normal_path, VS::TextureDetectRoughnessChannel p_roughness_channel); + static void _requested_roughness(void *p_ud, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel); static void _requested_normal(void *p_ud); protected: @@ -182,7 +182,7 @@ public: static Ref<Image> load_image_from_file(FileAccess *p_file, int p_size_limit); typedef void (*TextureFormatRequestCallback)(const Ref<StreamTexture> &); - typedef void (*TextureFormatRoughnessRequestCallback)(const Ref<StreamTexture> &, const String &p_normal_path, VS::TextureDetectRoughnessChannel p_roughness_channel); + typedef void (*TextureFormatRoughnessRequestCallback)(const Ref<StreamTexture> &, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel); static TextureFormatRequestCallback request_3d_callback; static TextureFormatRoughnessRequestCallback request_roughness_callback; @@ -198,9 +198,9 @@ public: virtual void set_path(const String &p_path, bool p_take_over); - virtual void draw(RID p_canvas_item, const Point2 &p_pos, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; - virtual void draw_rect(RID p_canvas_item, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; - virtual void draw_rect_region(RID p_canvas_item, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, bool p_clip_uv = true) const; + virtual void draw(RID p_canvas_item, const Point2 &p_pos, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; + virtual void draw_rect(RID p_canvas_item, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; + virtual void draw_rect_region(RID p_canvas_item, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, bool p_clip_uv = true) const; virtual bool has_alpha() const; bool is_pixel_opaque(int p_x, int p_y) const; @@ -213,7 +213,7 @@ public: class ResourceFormatLoaderStreamTexture : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; @@ -251,9 +251,9 @@ public: void set_filter_clip(const bool p_enable); bool has_filter_clip() const; - virtual void draw(RID p_canvas_item, const Point2 &p_pos, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; - virtual void draw_rect(RID p_canvas_item, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; - virtual void draw_rect_region(RID p_canvas_item, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, bool p_clip_uv = true) const; + virtual void draw(RID p_canvas_item, const Point2 &p_pos, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; + virtual void draw_rect(RID p_canvas_item, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; + virtual void draw_rect_region(RID p_canvas_item, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, bool p_clip_uv = true) const; virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const; bool is_pixel_opaque(int p_x, int p_y) const; @@ -291,9 +291,9 @@ public: void set_base_texture(const Ref<Texture2D> &p_texture); Ref<Texture2D> get_base_texture() const; - virtual void draw(RID p_canvas_item, const Point2 &p_pos, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; - virtual void draw_rect(RID p_canvas_item, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; - virtual void draw_rect_region(RID p_canvas_item, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, bool p_clip_uv = true) const; + virtual void draw(RID p_canvas_item, const Point2 &p_pos, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; + virtual void draw_rect(RID p_canvas_item, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; + virtual void draw_rect_region(RID p_canvas_item, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, bool p_clip_uv = true) const; virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const; bool is_pixel_opaque(int p_x, int p_y) const; @@ -339,9 +339,9 @@ public: Ref<Texture2D> get_piece_texture(int p_idx) const; Ref<Image> to_image() const; - virtual void draw(RID p_canvas_item, const Point2 &p_pos, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; - virtual void draw_rect(RID p_canvas_item, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; - virtual void draw_rect_region(RID p_canvas_item, 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), VS::CanvasItemTextureFilter p_texture_filter = VS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, VS::CanvasItemTextureRepeat p_texture_repeat = VS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, bool p_clip_uv = true) const; + virtual void draw(RID p_canvas_item, const Point2 &p_pos, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; + virtual void draw_rect(RID p_canvas_item, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT) const; + virtual void draw_rect_region(RID p_canvas_item, 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), RS::CanvasItemTextureFilter p_texture_filter = RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT, RS::CanvasItemTextureRepeat p_texture_repeat = RS::CANVAS_ITEM_TEXTURE_REPEAT_DEFAULT, bool p_clip_uv = true) const; bool is_pixel_opaque(int p_x, int p_y) const; @@ -352,7 +352,7 @@ class TextureLayered : public Texture { GDCLASS(TextureLayered, Texture); - VS::TextureLayeredType layered_type; + RS::TextureLayeredType layered_type; mutable RID texture; Image::Format format; @@ -383,7 +383,7 @@ public: virtual RID get_rid() const; virtual void set_path(const String &p_path, bool p_take_over = false); - TextureLayered(VS::TextureLayeredType p_layered_type); + TextureLayered(RS::TextureLayeredType p_layered_type); ~TextureLayered(); }; @@ -392,7 +392,7 @@ class Texture2DArray : public TextureLayered { GDCLASS(Texture2DArray, TextureLayered) public: Texture2DArray() : - TextureLayered(VS::TEXTURE_LAYERED_2D_ARRAY) {} + TextureLayered(RS::TEXTURE_LAYERED_2D_ARRAY) {} }; class Cubemap : public TextureLayered { @@ -401,7 +401,7 @@ class Cubemap : public TextureLayered { public: Cubemap() : - TextureLayered(VS::TEXTURE_LAYERED_CUBEMAP) {} + TextureLayered(RS::TEXTURE_LAYERED_CUBEMAP) {} }; class CubemapArray : public TextureLayered { @@ -410,7 +410,7 @@ class CubemapArray : public TextureLayered { public: CubemapArray() : - TextureLayered(VS::TEXTURE_LAYERED_CUBEMAP_ARRAY) {} + TextureLayered(RS::TEXTURE_LAYERED_CUBEMAP_ARRAY) {} }; class ResourceFormatLoaderTextureLayered : public ResourceFormatLoader { @@ -421,7 +421,7 @@ public: COMPRESSION_UNCOMPRESSED }; - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index d67f5f9ff2..98ebf048dc 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -230,11 +230,11 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const { List<PropertyInfo> list; - const StringName *key = NULL; + const StringName *key = nullptr; while ((key = icon_map.next(key))) { - const StringName *key2 = NULL; + const StringName *key2 = nullptr; while ((key2 = icon_map[*key].next(key2))) { @@ -242,11 +242,11 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const { } } - key = NULL; + key = nullptr; while ((key = style_map.next(key))) { - const StringName *key2 = NULL; + const StringName *key2 = nullptr; while ((key2 = style_map[*key].next(key2))) { @@ -254,11 +254,11 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const { } } - key = NULL; + key = nullptr; while ((key = font_map.next(key))) { - const StringName *key2 = NULL; + const StringName *key2 = nullptr; while ((key2 = font_map[*key].next(key2))) { @@ -266,11 +266,11 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const { } } - key = NULL; + key = nullptr; while ((key = color_map.next(key))) { - const StringName *key2 = NULL; + const StringName *key2 = nullptr; while ((key2 = color_map[*key].next(key2))) { @@ -278,11 +278,11 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const { } } - key = NULL; + key = nullptr; while ((key = constant_map.next(key))) { - const StringName *key2 = NULL; + const StringName *key2 = nullptr; while ((key2 = constant_map[*key].next(key2))) { @@ -417,7 +417,7 @@ void Theme::get_icon_list(StringName p_type, List<StringName> *p_list) const { if (!icon_map.has(p_type)) return; - const StringName *key = NULL; + const StringName *key = nullptr; while ((key = icon_map[p_type].next(key))) { @@ -440,7 +440,7 @@ Ref<Shader> Theme::get_shader(const StringName &p_name, const StringName &p_type if (shader_map.has(p_type) && shader_map[p_type].has(p_name) && shader_map[p_type][p_name].is_valid()) { return shader_map[p_type][p_name]; } else { - return NULL; + return nullptr; } } @@ -464,7 +464,7 @@ void Theme::get_shader_list(const StringName &p_type, List<StringName> *p_list) if (!shader_map.has(p_type)) return; - const StringName *key = NULL; + const StringName *key = nullptr; while ((key = shader_map[p_type].next(key))) { @@ -530,7 +530,7 @@ void Theme::get_stylebox_list(StringName p_type, List<StringName> *p_list) const if (!style_map.has(p_type)) return; - const StringName *key = NULL; + const StringName *key = nullptr; while ((key = style_map[p_type].next(key))) { @@ -541,7 +541,7 @@ void Theme::get_stylebox_list(StringName p_type, List<StringName> *p_list) const void Theme::get_stylebox_types(List<StringName> *p_list) const { ERR_FAIL_NULL(p_list); - const StringName *key = NULL; + const StringName *key = nullptr; while ((key = style_map.next(key))) { p_list->push_back(*key); } @@ -604,7 +604,7 @@ void Theme::get_font_list(StringName p_type, List<StringName> *p_list) const { if (!font_map.has(p_type)) return; - const StringName *key = NULL; + const StringName *key = nullptr; while ((key = font_map[p_type].next(key))) { @@ -654,7 +654,7 @@ void Theme::get_color_list(StringName p_type, List<StringName> *p_list) const { if (!color_map.has(p_type)) return; - const StringName *key = NULL; + const StringName *key = nullptr; while ((key = color_map[p_type].next(key))) { @@ -704,7 +704,7 @@ void Theme::get_constant_list(StringName p_type, List<StringName> *p_list) const if (!constant_map.has(p_type)) return; - const StringName *key = NULL; + const StringName *key = nullptr; while ((key = constant_map[p_type].next(key))) { @@ -716,9 +716,9 @@ void Theme::clear() { //these need disconnecting { - const StringName *K = NULL; + const StringName *K = nullptr; while ((K = icon_map.next(K))) { - const StringName *L = NULL; + const StringName *L = nullptr; while ((L = icon_map[*K].next(L))) { Ref<Texture2D> icon = icon_map[*K][*L]; if (icon.is_valid()) { @@ -729,9 +729,9 @@ void Theme::clear() { } { - const StringName *K = NULL; + const StringName *K = nullptr; while ((K = style_map.next(K))) { - const StringName *L = NULL; + const StringName *L = nullptr; while ((L = style_map[*K].next(L))) { Ref<StyleBox> style = style_map[*K][*L]; if (style.is_valid()) { @@ -742,9 +742,9 @@ void Theme::clear() { } { - const StringName *K = NULL; + const StringName *K = nullptr; while ((K = font_map.next(K))) { - const StringName *L = NULL; + const StringName *L = nullptr; while ((L = font_map[*K].next(L))) { Ref<Font> font = font_map[*K][*L]; if (font.is_valid()) { @@ -781,9 +781,9 @@ void Theme::copy_theme(const Ref<Theme> &p_other) { //these need reconnecting, so add normally { - const StringName *K = NULL; + const StringName *K = nullptr; while ((K = p_other->icon_map.next(K))) { - const StringName *L = NULL; + const StringName *L = nullptr; while ((L = p_other->icon_map[*K].next(L))) { set_icon(*L, *K, p_other->icon_map[*K][*L]); } @@ -791,9 +791,9 @@ void Theme::copy_theme(const Ref<Theme> &p_other) { } { - const StringName *K = NULL; + const StringName *K = nullptr; while ((K = p_other->style_map.next(K))) { - const StringName *L = NULL; + const StringName *L = nullptr; while ((L = p_other->style_map[*K].next(L))) { set_stylebox(*L, *K, p_other->style_map[*K][*L]); } @@ -801,9 +801,9 @@ void Theme::copy_theme(const Ref<Theme> &p_other) { } { - const StringName *K = NULL; + const StringName *K = nullptr; while ((K = p_other->font_map.next(K))) { - const StringName *L = NULL; + const StringName *L = nullptr; while ((L = p_other->font_map[*K].next(L))) { set_font(*L, *K, p_other->font_map[*K][*L]); } @@ -825,35 +825,35 @@ void Theme::get_type_list(List<StringName> *p_list) const { ERR_FAIL_NULL(p_list); Set<StringName> types; - const StringName *key = NULL; + const StringName *key = nullptr; while ((key = icon_map.next(key))) { types.insert(*key); } - key = NULL; + key = nullptr; while ((key = style_map.next(key))) { types.insert(*key); } - key = NULL; + key = nullptr; while ((key = font_map.next(key))) { types.insert(*key); } - key = NULL; + key = nullptr; while ((key = color_map.next(key))) { types.insert(*key); } - key = NULL; + key = nullptr; while ((key = constant_map.next(key))) { diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index b312aa054c..6f8a53be1a 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -362,7 +362,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::BOOL, pre + "shape_one_way", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); p_list->push_back(PropertyInfo(Variant::FLOAT, pre + "shape_one_way_margin", PROPERTY_HINT_RANGE, "0,128,0.01", PROPERTY_USAGE_NOEDITOR)); p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "shapes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); - p_list->push_back(PropertyInfo(Variant::INT, pre + "z_index", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1", PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::INT, pre + "z_index", PROPERTY_HINT_RANGE, itos(RS::CANVAS_ITEM_Z_MIN) + "," + itos(RS::CANVAS_ITEM_Z_MAX) + ",1", PROPERTY_USAGE_NOEDITOR)); } } @@ -620,7 +620,7 @@ Vector2 TileSet::autotile_get_subtile_for_bitmask(int p_id, uint16_t p_bitmask, ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2()); //First try to forward selection to script if (p_tilemap_node->get_class_name() == "TileMap") { - if (get_script_instance() != NULL) { + if (get_script_instance() != nullptr) { if (get_script_instance()->has_method("_forward_subtile_selection")) { Variant ret = get_script_instance()->call("_forward_subtile_selection", p_id, p_bitmask, p_tilemap_node, p_tile_location); if (ret.get_type() == Variant::VECTOR2) { @@ -681,7 +681,7 @@ Vector2 TileSet::atlastile_get_subtile_by_priority(int p_id, const Node *p_tilem ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2()); //First try to forward selection to script - if (get_script_instance() != NULL) { + if (get_script_instance() != nullptr) { if (get_script_instance()->has_method("_forward_atlas_subtile_selection")) { Variant ret = get_script_instance()->call("_forward_atlas_subtile_selection", p_id, p_tilemap_node, p_tile_location); if (ret.get_type() == Variant::VECTOR2) { @@ -1108,7 +1108,7 @@ bool TileSet::is_tile_bound(int p_drawn_id, int p_neighbor_id) { if (p_drawn_id == p_neighbor_id) { return true; - } else if (get_script_instance() != NULL) { + } else if (get_script_instance() != nullptr) { if (get_script_instance()->has_method("_is_tile_bound")) { Variant ret = get_script_instance()->call("_is_tile_bound", p_drawn_id, p_neighbor_id); if (ret.get_type() == Variant::BOOL) { diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h index 3c964ec667..05b43dfb89 100644 --- a/scene/resources/tile_set.h +++ b/scene/resources/tile_set.h @@ -34,7 +34,7 @@ #include "core/array.h" #include "core/resource.h" #include "scene/2d/light_occluder_2d.h" -#include "scene/2d/navigation_polygon.h" +#include "scene/2d/navigation_region_2d.h" #include "scene/resources/convex_polygon_shape_2d.h" #include "scene/resources/shape_2d.h" #include "scene/resources/texture.h" @@ -194,8 +194,8 @@ public: void autotile_set_bitmask(int p_id, Vector2 p_coord, uint32_t p_flag); uint32_t autotile_get_bitmask(int p_id, Vector2 p_coord); const Map<Vector2, uint32_t> &autotile_get_bitmask_map(int p_id); - Vector2 autotile_get_subtile_for_bitmask(int p_id, uint16_t p_bitmask, const Node *p_tilemap_node = NULL, const Vector2 &p_tile_location = Vector2()); - Vector2 atlastile_get_subtile_by_priority(int p_id, const Node *p_tilemap_node = NULL, const Vector2 &p_tile_location = Vector2()); + Vector2 autotile_get_subtile_for_bitmask(int p_id, uint16_t p_bitmask, const Node *p_tilemap_node = nullptr, const Vector2 &p_tile_location = Vector2()); + Vector2 atlastile_get_subtile_by_priority(int p_id, const Node *p_tilemap_node = nullptr, const Vector2 &p_tile_location = Vector2()); void tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_shape); Ref<Shape2D> tile_get_shape(int p_id, int p_shape_id) const; diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 407325c199..310a7ef4e4 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -31,7 +31,7 @@ #include "visual_shader.h" #include "core/vmap.h" -#include "servers/visual/shader_types.h" +#include "servers/rendering/shader_types.h" #include "visual_shader_nodes.h" bool VisualShaderNode::is_simple_decl() const { @@ -881,7 +881,7 @@ VisualShader::RenderModeEnums VisualShader::render_mode_enums[] = { { Shader::MODE_SPATIAL, "diffuse" }, { Shader::MODE_SPATIAL, "specular" }, { Shader::MODE_CANVAS_ITEM, "blend" }, - { Shader::MODE_CANVAS_ITEM, NULL } + { Shader::MODE_CANVAS_ITEM, nullptr } }; static const char *type_string[VisualShader::TYPE_MAX] = { @@ -1034,14 +1034,14 @@ bool VisualShader::_get(const StringName &p_name, Variant &r_ret) const { void VisualShader::_get_property_list(List<PropertyInfo> *p_list) const { //mode - p_list->push_back(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Spatial,CanvasItem,Particles")); + p_list->push_back(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Node3D,CanvasItem,Particles,Sky")); //render modes Map<String, String> blend_mode_enums; Set<String> toggles; - for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader_mode)).size(); i++) { - String mode = ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader_mode))[i]; + for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode)).size(); i++) { + String mode = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode))[i]; int idx = 0; bool in_enum = false; while (render_mode_enums[idx].string) { @@ -1085,12 +1085,12 @@ void VisualShader::_get_property_list(List<PropertyInfo> *p_list) const { } p_list->push_back(PropertyInfo(Variant::VECTOR2, prop_name + "/position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); - if (Object::cast_to<VisualShaderNodeGroupBase>(E->get().node.ptr()) != NULL) { + if (Object::cast_to<VisualShaderNodeGroupBase>(E->get().node.ptr()) != nullptr) { p_list->push_back(PropertyInfo(Variant::VECTOR2, prop_name + "/size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); p_list->push_back(PropertyInfo(Variant::STRING, prop_name + "/input_ports", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); p_list->push_back(PropertyInfo(Variant::STRING, prop_name + "/output_ports", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); } - if (Object::cast_to<VisualShaderNodeExpression>(E->get().node.ptr()) != NULL) { + if (Object::cast_to<VisualShaderNodeExpression>(E->get().node.ptr()) != nullptr) { p_list->push_back(PropertyInfo(Variant::STRING, prop_name + "/expression", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); } } @@ -1299,8 +1299,8 @@ void VisualShader::_update_shader() const { StringBuilder code; Vector<VisualShader::DefaultTextureParam> default_tex_params; Set<StringName> classes; - List<int> insertion_pos; - static const char *shader_mode_str[Shader::MODE_MAX] = { "spatial", "canvas_item", "particles" }; + Map<int, int> insertion_pos; + static const char *shader_mode_str[Shader::MODE_MAX] = { "spatial", "canvas_item", "particles", "sky" }; global_code += String() + "shader_type " + shader_mode_str[shader_mode] + ";\n"; @@ -1317,8 +1317,8 @@ void VisualShader::_update_shader() const { int which = modes[render_mode_enums[idx].string]; int count = 0; - for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader_mode)).size(); i++) { - String mode = ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader_mode))[i]; + for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode)).size(); i++) { + String mode = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode))[i]; if (mode.begins_with(render_mode_enums[idx].string)) { if (count == which) { if (render_mode != String()) { @@ -1336,9 +1336,9 @@ void VisualShader::_update_shader() const { } //fill render mode flags - for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader_mode)).size(); i++) { + for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode)).size(); i++) { - String mode = ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader_mode))[i]; + String mode = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode))[i]; if (flags.has(mode)) { if (render_mode != String()) { render_mode += ", "; @@ -1357,6 +1357,11 @@ void VisualShader::_update_shader() const { String global_expressions; for (int i = 0, index = 0; i < TYPE_MAX; i++) { + + if (!ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader_mode)).has(func_name[i])) { + continue; + } + for (Map<int, Node>::Element *E = graph[i].nodes.front(); E; E = E->next()) { Ref<VisualShaderNodeGlobalExpression> global_expression = Object::cast_to<VisualShaderNodeGlobalExpression>(E->get().node.ptr()); if (global_expression.is_valid()) { @@ -1373,6 +1378,10 @@ void VisualShader::_update_shader() const { for (int i = 0; i < TYPE_MAX; i++) { + if (!ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader_mode)).has(func_name[i])) { + continue; + } + //make it faster to go around through shader VMap<ConnectionKey, const List<Connection>::Element *> input_connections; VMap<ConnectionKey, const List<Connection>::Element *> output_connections; @@ -1396,7 +1405,7 @@ void VisualShader::_update_shader() const { Set<int> processed; Error err = _write_node(Type(i), global_code, global_code_per_node, global_code_per_func, code, default_tex_params, input_connections, output_connections, NODE_ID_OUTPUT, processed, false, classes); ERR_FAIL_COND(err != OK); - insertion_pos.push_back(code.get_string_length()); + insertion_pos.insert(i, code.get_string_length()); code += "}\n"; } @@ -1408,6 +1417,9 @@ void VisualShader::_update_shader() const { final_code += global_expressions; String tcode = code; for (int i = 0; i < TYPE_MAX; i++) { + if (!ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader_mode)).has(func_name[i])) { + continue; + } tcode = tcode.insert(insertion_pos[i], global_code_per_func[Type(i)]); } final_code += tcode; @@ -1466,7 +1478,7 @@ void VisualShader::_bind_methods() { ClassDB::bind_method(D_METHOD("remove_node", "type", "id"), &VisualShader::remove_node); ClassDB::bind_method(D_METHOD("is_node_connection", "type", "from_node", "from_port", "to_node", "to_port"), &VisualShader::is_node_connection); - ClassDB::bind_method(D_METHOD("can_connect_nodes", "type", "from_node", "from_port", "to_node", "to_port"), &VisualShader::is_node_connection); + ClassDB::bind_method(D_METHOD("can_connect_nodes", "type", "from_node", "from_port", "to_node", "to_port"), &VisualShader::can_connect_nodes); ClassDB::bind_method(D_METHOD("connect_nodes", "type", "from_node", "from_port", "to_node", "to_port"), &VisualShader::connect_nodes); ClassDB::bind_method(D_METHOD("disconnect_nodes", "type", "from_node", "from_port", "to_node", "to_port"), &VisualShader::disconnect_nodes); @@ -1643,7 +1655,39 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = { { Shader::MODE_PARTICLES, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_TRANSFORM, "emission_transform", "EMISSION_TRANSFORM" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, - { Shader::MODE_MAX, VisualShader::TYPE_MAX, VisualShaderNode::PORT_TYPE_TRANSFORM, NULL, NULL }, + + // Sky, Fragment + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_BOOLEAN, "at_cubemap_pass", "AT_CUBEMAP_PASS" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_BOOLEAN, "at_half_res_pass", "AT_HALF_RES_PASS" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_BOOLEAN, "at_quarter_res_pass", "AT_QUARTER_RES_PASS" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "eyedir", "EYEDIR" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "half_res_color", "HALF_RES_COLOR.rgb" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "half_res_alpha", "HALF_RES_COLOR.a" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "light0_color", "LIGHT0_COLOR" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "light0_direction", "LIGHT0_DIRECTION" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_BOOLEAN, "light0_enabled", "LIGHT0_ENABLED" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "light0_energy", "LIGHT0_ENERGY" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "light1_color", "LIGHT1_COLOR" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "light1_direction", "LIGHT1_DIRECTION" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_BOOLEAN, "light1_enabled", "LIGHT1_ENABLED" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "light1_energy", "LIGHT1_ENERGY" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "light2_color", "LIGHT2_COLOR" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "light2_direction", "LIGHT2_DIRECTION" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_BOOLEAN, "light2_enabled", "LIGHT2_ENABLED" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "light2_energy", "LIGHT2_ENERGY" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "light3_color", "LIGHT3_COLOR" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "light3_direction", "LIGHT3_DIRECTION" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_BOOLEAN, "light3_enabled", "LIGHT3_ENABLED" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "light3_energy", "LIGHT3_ENERGY" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "position", "POSITION" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "quarter_res_color", "QUARTER_RES_COLOR.rgb" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "quarter_res_alpha", "QUARTER_RES_COLOR.a" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SAMPLER, "radiance", "RADIANCE" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "screen_uv", "vec3(SCREEN_UV, 0.0)" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "sky_coords", "vec3(SKY_COORDS, 0.0)" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, + + { Shader::MODE_MAX, VisualShader::TYPE_MAX, VisualShaderNode::PORT_TYPE_TRANSFORM, nullptr, nullptr }, }; const VisualShaderNodeInput::Port VisualShaderNodeInput::preview_ports[] = { @@ -1692,7 +1736,7 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::preview_ports[] = { { Shader::MODE_PARTICLES, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "1.0" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "velocity", "vec3(0.0, 0.0, 1.0)" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, - { Shader::MODE_MAX, VisualShader::TYPE_MAX, VisualShaderNode::PORT_TYPE_TRANSFORM, NULL, NULL }, + { Shader::MODE_MAX, VisualShader::TYPE_MAX, VisualShaderNode::PORT_TYPE_TRANSFORM, nullptr, nullptr }, }; int VisualShaderNodeInput::get_input_port_count() const { @@ -1986,7 +2030,11 @@ const VisualShaderNodeOutput::Port VisualShaderNodeOutput::ports[] = { { Shader::MODE_PARTICLES, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "custom", "CUSTOM.rgb" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "custom_alpha", "CUSTOM.a" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_TRANSFORM, "transform", "TRANSFORM" }, - { Shader::MODE_MAX, VisualShader::TYPE_MAX, VisualShaderNode::PORT_TYPE_TRANSFORM, NULL, NULL }, + // Sky, Fragment + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR" }, + { Shader::MODE_SKY, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "ALPHA" }, + + { Shader::MODE_MAX, VisualShader::TYPE_MAX, VisualShaderNode::PORT_TYPE_TRANSFORM, nullptr, nullptr }, }; int VisualShaderNodeOutput::get_input_port_count() const { @@ -2116,6 +2164,17 @@ void VisualShaderNodeUniform::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "uniform_name"), "set_uniform_name", "get_uniform_name"); } +String VisualShaderNodeUniform::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const { + + List<String> keyword_list; + ShaderLanguage::get_keyword_list(&keyword_list); + if (keyword_list.find(uniform_name)) { + return TTR("Uniform name cannot be equal to a shader keyword. Choose another name."); + } + + return String(); +} + VisualShaderNodeUniform::VisualShaderNodeUniform() { } @@ -2517,7 +2576,7 @@ void VisualShaderNodeGroupBase::set_control(Control *p_control, int p_index) { } Control *VisualShaderNodeGroupBase::get_control(int p_index) { - ERR_FAIL_COND_V(!controls.has(p_index), NULL); + ERR_FAIL_COND_V(!controls.has(p_index), nullptr); return controls[p_index]; } diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h index 450dcfa081..ecf3f93fbb 100644 --- a/scene/resources/visual_shader.h +++ b/scene/resources/visual_shader.h @@ -379,6 +379,8 @@ public: void set_uniform_name(const String &p_name); String get_uniform_name() const; + virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const; + VisualShaderNodeUniform(); }; diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index 6bdc4cf6f0..742ef106d9 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -33,9 +33,9 @@ #include "core/project_settings.h" #include "scene/2d/camera_2d.h" #include "scene/2d/visibility_notifier_2d.h" -#include "scene/main/viewport.h" -#include "servers/physics_2d_server.h" -#include "servers/visual_server.h" +#include "scene/main/window.h" +#include "servers/physics_server_2d.h" +#include "servers/rendering_server.h" struct SpatialIndexer2D { @@ -376,33 +376,33 @@ void World2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::_RID, "canvas", PROPERTY_HINT_NONE, "", 0), "", "get_canvas"); ADD_PROPERTY(PropertyInfo(Variant::_RID, "space", PROPERTY_HINT_NONE, "", 0), "", "get_space"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "Physics2DDirectSpaceState", 0), "", "get_direct_space_state"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectSpaceState2D", 0), "", "get_direct_space_state"); } -Physics2DDirectSpaceState *World2D::get_direct_space_state() { +PhysicsDirectSpaceState2D *World2D::get_direct_space_state() { - return Physics2DServer::get_singleton()->space_get_direct_state(space); + return PhysicsServer2D::get_singleton()->space_get_direct_state(space); } World2D::World2D() { - canvas = VisualServer::get_singleton()->canvas_create(); - space = Physics2DServer::get_singleton()->space_create(); + canvas = RenderingServer::get_singleton()->canvas_create(); + space = PhysicsServer2D::get_singleton()->space_create(); //set space2D to be more friendly with pixels than meters, by adjusting some constants - Physics2DServer::get_singleton()->space_set_active(space, true); - Physics2DServer::get_singleton()->area_set_param(space, Physics2DServer::AREA_PARAM_GRAVITY, GLOBAL_DEF("physics/2d/default_gravity", 98)); - Physics2DServer::get_singleton()->area_set_param(space, Physics2DServer::AREA_PARAM_GRAVITY_VECTOR, GLOBAL_DEF("physics/2d/default_gravity_vector", Vector2(0, 1))); - Physics2DServer::get_singleton()->area_set_param(space, Physics2DServer::AREA_PARAM_LINEAR_DAMP, GLOBAL_DEF("physics/2d/default_linear_damp", 0.1)); + PhysicsServer2D::get_singleton()->space_set_active(space, true); + PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_GRAVITY, GLOBAL_DEF("physics/2d/default_gravity", 98)); + PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_GRAVITY_VECTOR, GLOBAL_DEF("physics/2d/default_gravity_vector", Vector2(0, 1))); + PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_LINEAR_DAMP, GLOBAL_DEF("physics/2d/default_linear_damp", 0.1)); ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/default_linear_damp", PropertyInfo(Variant::FLOAT, "physics/2d/default_linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater")); - Physics2DServer::get_singleton()->area_set_param(space, Physics2DServer::AREA_PARAM_ANGULAR_DAMP, GLOBAL_DEF("physics/2d/default_angular_damp", 1.0)); + PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_ANGULAR_DAMP, GLOBAL_DEF("physics/2d/default_angular_damp", 1.0)); ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/default_angular_damp", PropertyInfo(Variant::FLOAT, "physics/2d/default_angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater")); indexer = memnew(SpatialIndexer2D); } World2D::~World2D() { - VisualServer::get_singleton()->free(canvas); - Physics2DServer::get_singleton()->free(space); + RenderingServer::get_singleton()->free(canvas); + PhysicsServer2D::get_singleton()->free(space); memdelete(indexer); } diff --git a/scene/resources/world_2d.h b/scene/resources/world_2d.h index d837ef58c2..88b4c2594c 100644 --- a/scene/resources/world_2d.h +++ b/scene/resources/world_2d.h @@ -33,7 +33,7 @@ #include "core/project_settings.h" #include "core/resource.h" -#include "servers/physics_2d_server.h" +#include "servers/physics_server_2d.h" class VisibilityNotifier2D; class Viewport; @@ -67,7 +67,7 @@ public: RID get_canvas(); RID get_space(); - Physics2DDirectSpaceState *get_direct_space_state(); + PhysicsDirectSpaceState2D *get_direct_space_state(); void get_viewport_list(List<Viewport *> *r_viewports); diff --git a/scene/resources/world.cpp b/scene/resources/world_3d.cpp index a7e519479f..dee00dd82a 100644 --- a/scene/resources/world.cpp +++ b/scene/resources/world_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* world.cpp */ +/* world_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,17 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "world.h" +#include "world_3d.h" #include "core/math/camera_matrix.h" #include "core/math/octree.h" -#include "scene/3d/camera.h" -#include "scene/3d/visibility_notifier.h" +#include "scene/3d/camera_3d.h" +#include "scene/3d/visibility_notifier_3d.h" #include "scene/scene_string_names.h" struct SpatialIndexer { - Octree<VisibilityNotifier> octree; + Octree<VisibilityNotifier3D> octree; struct NotifierData { @@ -46,25 +46,25 @@ struct SpatialIndexer { OctreeElementID id; }; - Map<VisibilityNotifier *, NotifierData> notifiers; + Map<VisibilityNotifier3D *, NotifierData> notifiers; struct CameraData { - Map<VisibilityNotifier *, uint64_t> notifiers; + Map<VisibilityNotifier3D *, uint64_t> notifiers; }; - Map<Camera *, CameraData> cameras; + Map<Camera3D *, CameraData> cameras; enum { VISIBILITY_CULL_MAX = 32768 }; - Vector<VisibilityNotifier *> cull; + Vector<VisibilityNotifier3D *> cull; bool changed; uint64_t pass; uint64_t last_frame; - void _notifier_add(VisibilityNotifier *p_notifier, const AABB &p_rect) { + void _notifier_add(VisibilityNotifier3D *p_notifier, const AABB &p_rect) { ERR_FAIL_COND(notifiers.has(p_notifier)); notifiers[p_notifier].aabb = p_rect; @@ -72,9 +72,9 @@ struct SpatialIndexer { changed = true; } - void _notifier_update(VisibilityNotifier *p_notifier, const AABB &p_rect) { + void _notifier_update(VisibilityNotifier3D *p_notifier, const AABB &p_rect) { - Map<VisibilityNotifier *, NotifierData>::Element *E = notifiers.find(p_notifier); + Map<VisibilityNotifier3D *, NotifierData>::Element *E = notifiers.find(p_notifier); ERR_FAIL_COND(!E); if (E->get().aabb == p_rect) return; @@ -84,18 +84,18 @@ struct SpatialIndexer { changed = true; } - void _notifier_remove(VisibilityNotifier *p_notifier) { + void _notifier_remove(VisibilityNotifier3D *p_notifier) { - Map<VisibilityNotifier *, NotifierData>::Element *E = notifiers.find(p_notifier); + Map<VisibilityNotifier3D *, NotifierData>::Element *E = notifiers.find(p_notifier); ERR_FAIL_COND(!E); octree.erase(E->get().id); notifiers.erase(p_notifier); - List<Camera *> removed; - for (Map<Camera *, CameraData>::Element *F = cameras.front(); F; F = F->next()) { + List<Camera3D *> removed; + for (Map<Camera3D *, CameraData>::Element *F = cameras.front(); F; F = F->next()) { - Map<VisibilityNotifier *, uint64_t>::Element *G = F->get().notifiers.find(p_notifier); + Map<VisibilityNotifier3D *, uint64_t>::Element *G = F->get().notifiers.find(p_notifier); if (G) { F->get().notifiers.erase(G); @@ -112,7 +112,7 @@ struct SpatialIndexer { changed = true; } - void _add_camera(Camera *p_camera) { + void _add_camera(Camera3D *p_camera) { ERR_FAIL_COND(cameras.has(p_camera)); CameraData vd; @@ -120,17 +120,17 @@ struct SpatialIndexer { changed = true; } - void _update_camera(Camera *p_camera) { + void _update_camera(Camera3D *p_camera) { - Map<Camera *, CameraData>::Element *E = cameras.find(p_camera); + Map<Camera3D *, CameraData>::Element *E = cameras.find(p_camera); ERR_FAIL_COND(!E); changed = true; } - void _remove_camera(Camera *p_camera) { + void _remove_camera(Camera3D *p_camera) { ERR_FAIL_COND(!cameras.has(p_camera)); - List<VisibilityNotifier *> removed; - for (Map<VisibilityNotifier *, uint64_t>::Element *E = cameras[p_camera].notifiers.front(); E; E = E->next()) { + List<VisibilityNotifier3D *> removed; + for (Map<VisibilityNotifier3D *, uint64_t>::Element *E = cameras[p_camera].notifiers.front(); E; E = E->next()) { removed.push_back(E->key()); } @@ -152,26 +152,26 @@ struct SpatialIndexer { if (!changed) return; - for (Map<Camera *, CameraData>::Element *E = cameras.front(); E; E = E->next()) { + for (Map<Camera3D *, CameraData>::Element *E = cameras.front(); E; E = E->next()) { pass++; - Camera *c = E->key(); + Camera3D *c = E->key(); Vector<Plane> planes = c->get_frustum(); int culled = octree.cull_convex(planes, cull.ptrw(), cull.size()); - VisibilityNotifier **ptr = cull.ptrw(); + VisibilityNotifier3D **ptr = cull.ptrw(); - List<VisibilityNotifier *> added; - List<VisibilityNotifier *> removed; + List<VisibilityNotifier3D *> added; + List<VisibilityNotifier3D *> removed; for (int i = 0; i < culled; i++) { //notifiers in frustum - Map<VisibilityNotifier *, uint64_t>::Element *H = E->get().notifiers.find(ptr[i]); + Map<VisibilityNotifier3D *, uint64_t>::Element *H = E->get().notifiers.find(ptr[i]); if (!H) { E->get().notifiers.insert(ptr[i], pass); @@ -181,7 +181,7 @@ struct SpatialIndexer { } } - for (Map<VisibilityNotifier *, uint64_t>::Element *F = E->get().notifiers.front(); F; F = F->next()) { + for (Map<VisibilityNotifier3D *, uint64_t>::Element *F = E->get().notifiers.front(); F; F = F->next()) { if (F->get() != pass) removed.push_back(F->key()); @@ -210,171 +210,171 @@ struct SpatialIndexer { } }; -void World::_register_camera(Camera *p_camera) { +void World3D::_register_camera(Camera3D *p_camera) { #ifndef _3D_DISABLED indexer->_add_camera(p_camera); #endif } -void World::_update_camera(Camera *p_camera) { +void World3D::_update_camera(Camera3D *p_camera) { #ifndef _3D_DISABLED indexer->_update_camera(p_camera); #endif } -void World::_remove_camera(Camera *p_camera) { +void World3D::_remove_camera(Camera3D *p_camera) { #ifndef _3D_DISABLED indexer->_remove_camera(p_camera); #endif } -void World::_register_notifier(VisibilityNotifier *p_notifier, const AABB &p_rect) { +void World3D::_register_notifier(VisibilityNotifier3D *p_notifier, const AABB &p_rect) { #ifndef _3D_DISABLED indexer->_notifier_add(p_notifier, p_rect); #endif } -void World::_update_notifier(VisibilityNotifier *p_notifier, const AABB &p_rect) { +void World3D::_update_notifier(VisibilityNotifier3D *p_notifier, const AABB &p_rect) { #ifndef _3D_DISABLED indexer->_notifier_update(p_notifier, p_rect); #endif } -void World::_remove_notifier(VisibilityNotifier *p_notifier) { +void World3D::_remove_notifier(VisibilityNotifier3D *p_notifier) { #ifndef _3D_DISABLED indexer->_notifier_remove(p_notifier); #endif } -void World::_update(uint64_t p_frame) { +void World3D::_update(uint64_t p_frame) { #ifndef _3D_DISABLED indexer->_update(p_frame); #endif } -RID World::get_space() const { +RID World3D::get_space() const { return space; } -RID World::get_scenario() const { +RID World3D::get_scenario() const { return scenario; } -void World::set_environment(const Ref<Environment> &p_environment) { +void World3D::set_environment(const Ref<Environment> &p_environment) { if (environment == p_environment) { return; } environment = p_environment; if (environment.is_valid()) - VS::get_singleton()->scenario_set_environment(scenario, environment->get_rid()); + RS::get_singleton()->scenario_set_environment(scenario, environment->get_rid()); else - VS::get_singleton()->scenario_set_environment(scenario, RID()); + RS::get_singleton()->scenario_set_environment(scenario, RID()); emit_changed(); } -Ref<Environment> World::get_environment() const { +Ref<Environment> World3D::get_environment() const { return environment; } -void World::set_fallback_environment(const Ref<Environment> &p_environment) { +void World3D::set_fallback_environment(const Ref<Environment> &p_environment) { if (fallback_environment == p_environment) { return; } fallback_environment = p_environment; if (fallback_environment.is_valid()) - VS::get_singleton()->scenario_set_fallback_environment(scenario, p_environment->get_rid()); + RS::get_singleton()->scenario_set_fallback_environment(scenario, p_environment->get_rid()); else - VS::get_singleton()->scenario_set_fallback_environment(scenario, RID()); + RS::get_singleton()->scenario_set_fallback_environment(scenario, RID()); emit_changed(); } -Ref<Environment> World::get_fallback_environment() const { +Ref<Environment> World3D::get_fallback_environment() const { return fallback_environment; } -void World::set_camera_effects(const Ref<CameraEffects> &p_camera_effects) { +void World3D::set_camera_effects(const Ref<CameraEffects> &p_camera_effects) { camera_effects = p_camera_effects; if (camera_effects.is_valid()) - VS::get_singleton()->scenario_set_camera_effects(scenario, camera_effects->get_rid()); + RS::get_singleton()->scenario_set_camera_effects(scenario, camera_effects->get_rid()); else - VS::get_singleton()->scenario_set_camera_effects(scenario, RID()); + RS::get_singleton()->scenario_set_camera_effects(scenario, RID()); } -Ref<CameraEffects> World::get_camera_effects() const { +Ref<CameraEffects> World3D::get_camera_effects() const { return camera_effects; } -PhysicsDirectSpaceState *World::get_direct_space_state() { +PhysicsDirectSpaceState3D *World3D::get_direct_space_state() { - return PhysicsServer::get_singleton()->space_get_direct_state(space); + return PhysicsServer3D::get_singleton()->space_get_direct_state(space); } -void World::get_camera_list(List<Camera *> *r_cameras) { +void World3D::get_camera_list(List<Camera3D *> *r_cameras) { - for (Map<Camera *, SpatialIndexer::CameraData>::Element *E = indexer->cameras.front(); E; E = E->next()) { + for (Map<Camera3D *, SpatialIndexer::CameraData>::Element *E = indexer->cameras.front(); E; E = E->next()) { r_cameras->push_back(E->key()); } } -void World::_bind_methods() { - - ClassDB::bind_method(D_METHOD("get_space"), &World::get_space); - ClassDB::bind_method(D_METHOD("get_scenario"), &World::get_scenario); - ClassDB::bind_method(D_METHOD("set_environment", "env"), &World::set_environment); - ClassDB::bind_method(D_METHOD("get_environment"), &World::get_environment); - ClassDB::bind_method(D_METHOD("set_fallback_environment", "env"), &World::set_fallback_environment); - ClassDB::bind_method(D_METHOD("get_fallback_environment"), &World::get_fallback_environment); - ClassDB::bind_method(D_METHOD("set_camera_effects", "env"), &World::set_camera_effects); - ClassDB::bind_method(D_METHOD("get_camera_effects"), &World::get_camera_effects); - ClassDB::bind_method(D_METHOD("get_direct_space_state"), &World::get_direct_space_state); +void World3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("get_space"), &World3D::get_space); + ClassDB::bind_method(D_METHOD("get_scenario"), &World3D::get_scenario); + ClassDB::bind_method(D_METHOD("set_environment", "env"), &World3D::set_environment); + ClassDB::bind_method(D_METHOD("get_environment"), &World3D::get_environment); + ClassDB::bind_method(D_METHOD("set_fallback_environment", "env"), &World3D::set_fallback_environment); + ClassDB::bind_method(D_METHOD("get_fallback_environment"), &World3D::get_fallback_environment); + ClassDB::bind_method(D_METHOD("set_camera_effects", "env"), &World3D::set_camera_effects); + ClassDB::bind_method(D_METHOD("get_camera_effects"), &World3D::get_camera_effects); + ClassDB::bind_method(D_METHOD("get_direct_space_state"), &World3D::get_direct_space_state); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_environment", "get_environment"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "fallback_environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_fallback_environment", "get_fallback_environment"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "camera_effects", PROPERTY_HINT_RESOURCE_TYPE, "CameraEffects"), "set_camera_effects", "get_camera_effects"); ADD_PROPERTY(PropertyInfo(Variant::_RID, "space", PROPERTY_HINT_NONE, "", 0), "", "get_space"); ADD_PROPERTY(PropertyInfo(Variant::_RID, "scenario", PROPERTY_HINT_NONE, "", 0), "", "get_scenario"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectSpaceState", 0), "", "get_direct_space_state"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectSpaceState3D", 0), "", "get_direct_space_state"); } -World::World() { +World3D::World3D() { - space = PhysicsServer::get_singleton()->space_create(); - scenario = VisualServer::get_singleton()->scenario_create(); + space = PhysicsServer3D::get_singleton()->space_create(); + scenario = RenderingServer::get_singleton()->scenario_create(); - PhysicsServer::get_singleton()->space_set_active(space, true); - PhysicsServer::get_singleton()->area_set_param(space, PhysicsServer::AREA_PARAM_GRAVITY, GLOBAL_DEF("physics/3d/default_gravity", 9.8)); - PhysicsServer::get_singleton()->area_set_param(space, PhysicsServer::AREA_PARAM_GRAVITY_VECTOR, GLOBAL_DEF("physics/3d/default_gravity_vector", Vector3(0, -1, 0))); - PhysicsServer::get_singleton()->area_set_param(space, PhysicsServer::AREA_PARAM_LINEAR_DAMP, GLOBAL_DEF("physics/3d/default_linear_damp", 0.1)); + PhysicsServer3D::get_singleton()->space_set_active(space, true); + PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_GRAVITY, GLOBAL_DEF("physics/3d/default_gravity", 9.8)); + PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR, GLOBAL_DEF("physics/3d/default_gravity_vector", Vector3(0, -1, 0))); + PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_LINEAR_DAMP, GLOBAL_DEF("physics/3d/default_linear_damp", 0.1)); ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/default_linear_damp", PropertyInfo(Variant::FLOAT, "physics/3d/default_linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater")); - PhysicsServer::get_singleton()->area_set_param(space, PhysicsServer::AREA_PARAM_ANGULAR_DAMP, GLOBAL_DEF("physics/3d/default_angular_damp", 0.1)); + PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP, GLOBAL_DEF("physics/3d/default_angular_damp", 0.1)); ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/default_angular_damp", PropertyInfo(Variant::FLOAT, "physics/3d/default_angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater")); #ifdef _3D_DISABLED - indexer = NULL; + indexer = nullptr; #else indexer = memnew(SpatialIndexer); #endif } -World::~World() { +World3D::~World3D() { - PhysicsServer::get_singleton()->free(space); - VisualServer::get_singleton()->free(scenario); + PhysicsServer3D::get_singleton()->free(space); + RenderingServer::get_singleton()->free(scenario); #ifndef _3D_DISABLED memdelete(indexer); diff --git a/scene/resources/world.h b/scene/resources/world_3d.h index 6fd79abaaf..81a27a7349 100644 --- a/scene/resources/world.h +++ b/scene/resources/world_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* world.h */ +/* world_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,21 +28,20 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef WORLD_H -#define WORLD_H +#ifndef WORLD_3D_H +#define WORLD_3D_H #include "core/resource.h" #include "scene/resources/environment.h" -#include "servers/physics_server.h" -#include "servers/visual_server.h" +#include "servers/physics_server_3d.h" +#include "servers/rendering_server.h" -class Camera; -class VisibilityNotifier; +class Camera3D; +class VisibilityNotifier3D; struct SpatialIndexer; -class World : public Resource { - GDCLASS(World, Resource); - RES_BASE_EXTENSION("world"); +class World3D : public Resource { + GDCLASS(World3D, Resource); private: RID space; @@ -55,16 +54,16 @@ private: protected: static void _bind_methods(); - friend class Camera; - friend class VisibilityNotifier; + friend class Camera3D; + friend class VisibilityNotifier3D; - void _register_camera(Camera *p_camera); - void _update_camera(Camera *p_camera); - void _remove_camera(Camera *p_camera); + void _register_camera(Camera3D *p_camera); + void _update_camera(Camera3D *p_camera); + void _remove_camera(Camera3D *p_camera); - void _register_notifier(VisibilityNotifier *p_notifier, const AABB &p_rect); - void _update_notifier(VisibilityNotifier *p_notifier, const AABB &p_rect); - void _remove_notifier(VisibilityNotifier *p_notifier); + void _register_notifier(VisibilityNotifier3D *p_notifier, const AABB &p_rect); + void _update_notifier(VisibilityNotifier3D *p_notifier, const AABB &p_rect); + void _remove_notifier(VisibilityNotifier3D *p_notifier); friend class Viewport; void _update(uint64_t p_frame); @@ -81,12 +80,12 @@ public: void set_camera_effects(const Ref<CameraEffects> &p_camera_effects); Ref<CameraEffects> get_camera_effects() const; - void get_camera_list(List<Camera *> *r_cameras); + void get_camera_list(List<Camera3D *> *r_cameras); - PhysicsDirectSpaceState *get_direct_space_state(); + PhysicsDirectSpaceState3D *get_direct_space_state(); - World(); - ~World(); + World3D(); + ~World3D(); }; -#endif // WORLD_H +#endif // WORLD_3D_H diff --git a/scene/resources/world_margin_shape.cpp b/scene/resources/world_margin_shape_3d.cpp index b5b701327c..aa96f8aa68 100644 --- a/scene/resources/world_margin_shape.cpp +++ b/scene/resources/world_margin_shape_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* world_margin_shape.cpp */ +/* world_margin_shape_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,11 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "world_margin_shape.h" +#include "world_margin_shape_3d.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" -Vector<Vector3> WorldMarginShape::get_debug_mesh_lines() { +Vector<Vector3> WorldMarginShape3D::get_debug_mesh_lines() { Plane p = get_plane(); Vector<Vector3> points; @@ -61,13 +61,13 @@ Vector<Vector3> WorldMarginShape::get_debug_mesh_lines() { return points; } -void WorldMarginShape::_update_shape() { +void WorldMarginShape3D::_update_shape() { - PhysicsServer::get_singleton()->shape_set_data(get_shape(), plane); - Shape::_update_shape(); + PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), plane); + Shape3D::_update_shape(); } -void WorldMarginShape::set_plane(Plane p_plane) { +void WorldMarginShape3D::set_plane(Plane p_plane) { plane = p_plane; _update_shape(); @@ -75,21 +75,21 @@ void WorldMarginShape::set_plane(Plane p_plane) { _change_notify("plane"); } -Plane WorldMarginShape::get_plane() const { +Plane WorldMarginShape3D::get_plane() const { return plane; } -void WorldMarginShape::_bind_methods() { +void WorldMarginShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_plane", "plane"), &WorldMarginShape::set_plane); - ClassDB::bind_method(D_METHOD("get_plane"), &WorldMarginShape::get_plane); + ClassDB::bind_method(D_METHOD("set_plane", "plane"), &WorldMarginShape3D::set_plane); + ClassDB::bind_method(D_METHOD("get_plane"), &WorldMarginShape3D::get_plane); ADD_PROPERTY(PropertyInfo(Variant::PLANE, "plane"), "set_plane", "get_plane"); } -WorldMarginShape::WorldMarginShape() : - Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_PLANE)) { +WorldMarginShape3D::WorldMarginShape3D() : + Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_PLANE)) { set_plane(Plane(0, 1, 0, 0)); } diff --git a/scene/resources/world_margin_shape.h b/scene/resources/world_margin_shape_3d.h index 78ea570212..5e0f046628 100644 --- a/scene/resources/world_margin_shape.h +++ b/scene/resources/world_margin_shape_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* world_margin_shape.h */ +/* world_margin_shape_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef WORLD_MARGIN_SHAPE_H -#define WORLD_MARGIN_SHAPE_H +#ifndef WORLD_MARGIN_SHAPE_3D_H +#define WORLD_MARGIN_SHAPE_3D_H -#include "scene/resources/shape.h" +#include "scene/resources/shape_3d.h" -class WorldMarginShape : public Shape { +class WorldMarginShape3D : public Shape3D { - GDCLASS(WorldMarginShape, Shape); + GDCLASS(WorldMarginShape3D, Shape3D); Plane plane; protected: @@ -52,6 +52,6 @@ public: return 0; } - WorldMarginShape(); + WorldMarginShape3D(); }; #endif // WORLD_MARGIN_SHAPE_H diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp index d3c5a87cae..5e3f8b803b 100644 --- a/scene/scene_string_names.cpp +++ b/scene/scene_string_names.cpp @@ -30,7 +30,7 @@ #include "scene_string_names.h" -SceneStringNames *SceneStringNames::singleton = NULL; +SceneStringNames *SceneStringNames::singleton = nullptr; SceneStringNames::SceneStringNames() { @@ -193,7 +193,16 @@ SceneStringNames::SceneStringNames() { mesh_materials[i] = "material/" + itos(i); } + _window_group = StaticCString::create("_window_group"); + _window_input = StaticCString::create("_window_input"); + window_input = StaticCString::create("window_input"); + _window_unhandled_input = StaticCString::create("_window_unhandled_input"); + + theme_changed = StaticCString::create("theme_changed"); parameters_base_path = "parameters/"; tracks_changed = "tracks_changed"; + + shader_overrides_group = StaticCString::create("_shader_overrides_group_"); + shader_overrides_group_active = StaticCString::create("_shader_overrides_group_active_"); } diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h index 7976a2072c..c5de10a6f6 100644 --- a/scene/scene_string_names.h +++ b/scene/scene_string_names.h @@ -44,7 +44,7 @@ class SceneStringNames { static void create() { singleton = memnew(SceneStringNames); } static void free() { memdelete(singleton); - singleton = NULL; + singleton = nullptr; } SceneStringNames(); @@ -201,6 +201,15 @@ public: StringName tracks_changed; + StringName _window_group; + StringName _window_input; + StringName _window_unhandled_input; + StringName window_input; + + StringName theme_changed; + StringName shader_overrides_group; + StringName shader_overrides_group_active; + enum { MAX_MATERIALS = 32 }; |