summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/animated_sprite.cpp8
-rw-r--r--scene/2d/canvas_item.cpp17
-rw-r--r--scene/2d/canvas_item.h2
-rw-r--r--scene/2d/collision_object_2d.cpp10
-rw-r--r--scene/2d/collision_object_2d.h1
-rw-r--r--scene/2d/collision_polygon_2d.cpp4
-rw-r--r--scene/2d/collision_shape_2d.cpp4
-rw-r--r--scene/2d/cpu_particles_2d.cpp10
-rw-r--r--scene/2d/line_2d.cpp18
-rw-r--r--scene/2d/line_2d.h4
-rw-r--r--scene/2d/navigation_2d.cpp12
-rw-r--r--scene/2d/path_2d.cpp12
-rw-r--r--scene/2d/physics_body_2d.cpp34
-rw-r--r--scene/2d/polygon_2d.cpp4
-rw-r--r--scene/2d/ray_cast_2d.cpp4
-rw-r--r--scene/2d/tile_map.cpp4
-rw-r--r--scene/2d/touch_screen_button.cpp8
-rw-r--r--scene/3d/arvr_nodes.h2
-rw-r--r--scene/3d/camera.cpp2
-rw-r--r--scene/3d/camera.h2
-rw-r--r--scene/3d/cpu_particles.cpp10
-rw-r--r--scene/3d/gi_probe.cpp4
-rw-r--r--scene/3d/navigation_mesh.h2
-rw-r--r--scene/3d/particles.cpp7
-rw-r--r--scene/3d/path.cpp39
-rw-r--r--scene/3d/physics_body.cpp51
-rw-r--r--scene/3d/soft_body.cpp11
-rw-r--r--scene/3d/spatial.cpp3
-rw-r--r--scene/3d/voxel_light_baker.cpp8
-rw-r--r--scene/SCsub1
-rw-r--r--scene/animation/animation_blend_space_1d.cpp1
-rw-r--r--scene/animation/animation_blend_space_2d.cpp1
-rw-r--r--scene/animation/animation_node_state_machine.cpp33
-rw-r--r--scene/animation/tween.cpp46
-rw-r--r--scene/animation/tween.h9
-rw-r--r--scene/debugger/SCsub5
-rw-r--r--scene/debugger/script_debugger_remote.cpp1280
-rw-r--r--scene/debugger/script_debugger_remote.h196
-rw-r--r--scene/gui/button.cpp8
-rw-r--r--scene/gui/dialogs.cpp14
-rw-r--r--scene/gui/dialogs.h5
-rw-r--r--scene/gui/file_dialog.cpp38
-rw-r--r--scene/gui/file_dialog.h3
-rw-r--r--scene/gui/gradient_edit.cpp5
-rw-r--r--scene/gui/graph_edit.cpp7
-rw-r--r--scene/gui/item_list.cpp3
-rw-r--r--scene/gui/label.cpp13
-rw-r--r--scene/gui/line_edit.cpp39
-rw-r--r--scene/gui/line_edit.h2
-rw-r--r--scene/gui/range.cpp5
-rw-r--r--scene/gui/rich_text_label.cpp40
-rw-r--r--scene/gui/rich_text_label.h5
-rw-r--r--scene/gui/scroll_container.cpp2
-rw-r--r--scene/gui/slider.cpp8
-rw-r--r--scene/gui/spin_box.cpp4
-rw-r--r--scene/gui/text_edit.cpp171
-rw-r--r--scene/gui/text_edit.h75
-rw-r--r--scene/gui/tree.cpp9
-rw-r--r--scene/gui/tree.h2
-rw-r--r--scene/gui/video_player.cpp23
-rw-r--r--scene/gui/video_player.h7
-rw-r--r--scene/main/http_request.cpp16
-rw-r--r--scene/main/http_request.h3
-rw-r--r--scene/main/node.cpp24
-rw-r--r--scene/main/node.h1
-rw-r--r--scene/main/scene_tree.cpp74
-rw-r--r--scene/main/scene_tree.h23
-rwxr-xr-xscene/main/timer.cpp2
-rw-r--r--scene/main/viewport.cpp131
-rw-r--r--scene/main/viewport.h36
-rw-r--r--scene/resources/animation.cpp12
-rw-r--r--scene/resources/audio_stream_sample.cpp5
-rw-r--r--scene/resources/default_theme/default_theme.cpp9
-rw-r--r--scene/resources/dynamic_font.cpp1
-rw-r--r--scene/resources/environment.cpp4
-rw-r--r--scene/resources/material.cpp53
-rw-r--r--scene/resources/material.h6
-rw-r--r--scene/resources/packed_scene.cpp3
-rw-r--r--scene/resources/particles_material.cpp2
-rw-r--r--scene/resources/ray_shape.cpp10
-rw-r--r--scene/resources/segment_shape_2d.cpp6
-rw-r--r--scene/resources/style_box.cpp27
-rw-r--r--scene/resources/style_box.h3
-rw-r--r--scene/resources/texture.cpp10
-rw-r--r--scene/resources/theme.cpp64
-rw-r--r--scene/resources/tile_set.cpp45
-rw-r--r--scene/resources/video_stream.h2
-rw-r--r--scene/resources/visual_shader.cpp50
-rw-r--r--scene/resources/visual_shader.h1
-rw-r--r--scene/resources/visual_shader_nodes.cpp17
90 files changed, 2564 insertions, 433 deletions
diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp
index 20ec06f033..9d02408641 100644
--- a/scene/2d/animated_sprite.cpp
+++ b/scene/2d/animated_sprite.cpp
@@ -604,10 +604,14 @@ bool AnimatedSprite::_is_playing() const {
void AnimatedSprite::play(const StringName &p_animation, const bool p_backwards) {
- if (p_animation)
+ backwards = p_backwards;
+
+ if (p_animation) {
set_animation(p_animation);
+ if (backwards && get_frame() == 0)
+ set_frame(frames->get_frame_count(p_animation) - 1);
+ }
- backwards = p_backwards;
_set_playing(true);
}
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index d584492737..fa23e3fd39 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -360,6 +360,10 @@ bool CanvasItem::_edit_is_selected_on_click(const Point2 &p_point, double p_tole
}
}
+Transform2D CanvasItem::_edit_get_transform() const {
+ return Transform2D(_edit_get_rotation(), _edit_get_position() + _edit_get_pivot());
+}
+
bool CanvasItem::is_visible_in_tree() const {
if (!is_inside_tree())
@@ -790,29 +794,29 @@ void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_fil
VisualServer::get_singleton()->canvas_item_add_line(
canvas_item,
- p_rect.position + Point2(-offset, 0),
+ p_rect.position + Size2(-offset, 0),
p_rect.position + Size2(p_rect.size.width + offset, 0),
p_color,
p_width,
p_antialiased);
VisualServer::get_singleton()->canvas_item_add_line(
canvas_item,
- p_rect.position + Point2(0, offset),
- p_rect.position + Size2(0, p_rect.size.height - offset),
+ 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,
p_antialiased);
VisualServer::get_singleton()->canvas_item_add_line(
canvas_item,
- p_rect.position + Point2(-offset, p_rect.size.height),
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,
p_antialiased);
VisualServer::get_singleton()->canvas_item_add_line(
canvas_item,
- p_rect.position + Point2(p_rect.size.width, offset),
- p_rect.position + Size2(p_rect.size.width, p_rect.size.height - offset),
+ p_rect.position + Size2(0, p_rect.size.height - offset),
+ p_rect.position + Size2(0, offset),
p_color,
p_width,
p_antialiased);
@@ -1133,6 +1137,7 @@ void CanvasItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("_edit_set_pivot", "pivot"), &CanvasItem::_edit_set_pivot);
ClassDB::bind_method(D_METHOD("_edit_get_pivot"), &CanvasItem::_edit_get_pivot);
ClassDB::bind_method(D_METHOD("_edit_use_pivot"), &CanvasItem::_edit_use_pivot);
+ ClassDB::bind_method(D_METHOD("_edit_get_transform"), &CanvasItem::_edit_get_transform);
ClassDB::bind_method(D_METHOD("get_canvas_item"), &CanvasItem::get_canvas_item);
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index 581adf1396..e51ee601e2 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -281,6 +281,8 @@ public:
virtual void _edit_set_pivot(const Point2 &p_pivot){};
virtual Point2 _edit_get_pivot() const { return Point2(); };
+ virtual Transform2D _edit_get_transform() const;
+
/* VISIBILITY */
void set_visible(bool p_visible);
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp
index 228b67990c..9f79691405 100644
--- a/scene/2d/collision_object_2d.cpp
+++ b/scene/2d/collision_object_2d.cpp
@@ -46,8 +46,6 @@ void CollisionObject2D::_notification(int p_what) {
else
Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform);
- last_transform = global_transform;
-
RID space = get_world_2d()->get_space();
if (area) {
Physics2DServer::get_singleton()->area_set_space(rid, space);
@@ -73,19 +71,17 @@ void CollisionObject2D::_notification(int p_what) {
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
- Transform2D global_transform = get_global_transform();
-
- if (only_update_transform_changes && global_transform == last_transform) {
+ if (only_update_transform_changes) {
return;
}
+ Transform2D global_transform = get_global_transform();
+
if (area)
Physics2DServer::get_singleton()->area_set_transform(rid, global_transform);
else
Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform);
- last_transform = global_transform;
-
} break;
case NOTIFICATION_EXIT_TREE: {
diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h
index 4e7d01c8e6..0a9d33b8a6 100644
--- a/scene/2d/collision_object_2d.h
+++ b/scene/2d/collision_object_2d.h
@@ -67,7 +67,6 @@ class CollisionObject2D : public Node2D {
int total_subshapes;
Map<uint32_t, ShapeData> shapes;
- Transform2D last_transform;
bool only_update_transform_changes; //this is used for sync physics in KinematicBody
protected:
diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp
index bb144dda96..766a8a6de4 100644
--- a/scene/2d/collision_polygon_2d.cpp
+++ b/scene/2d/collision_polygon_2d.cpp
@@ -169,8 +169,8 @@ void CollisionPolygon2D::_notification(int p_what) {
Vector<Vector2> pts;
float tsize = 8;
pts.push_back(line_to + (Vector2(0, tsize)));
- pts.push_back(line_to + (Vector2(0.707 * tsize, 0)));
- pts.push_back(line_to + (Vector2(-0.707 * tsize, 0)));
+ pts.push_back(line_to + (Vector2(Math_SQRT12 * tsize, 0)));
+ pts.push_back(line_to + (Vector2(-Math_SQRT12 * tsize, 0)));
Vector<Color> cols;
for (int i = 0; i < 3; i++)
cols.push_back(dcol);
diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp
index f79d79d039..d9c1d69b53 100644
--- a/scene/2d/collision_shape_2d.cpp
+++ b/scene/2d/collision_shape_2d.cpp
@@ -134,8 +134,8 @@ void CollisionShape2D::_notification(int p_what) {
Vector<Vector2> pts;
float tsize = 8;
pts.push_back(line_to + (Vector2(0, tsize)));
- pts.push_back(line_to + (Vector2(0.707 * tsize, 0)));
- pts.push_back(line_to + (Vector2(-0.707 * tsize, 0)));
+ pts.push_back(line_to + (Vector2(Math_SQRT12 * tsize, 0)));
+ pts.push_back(line_to + (Vector2(-Math_SQRT12 * tsize, 0)));
Vector<Color> cols;
for (int i = 0; i < 3; i++)
cols.push_back(draw_col);
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp
index 9da41914d7..372d8f614b 100644
--- a/scene/2d/cpu_particles_2d.cpp
+++ b/scene/2d/cpu_particles_2d.cpp
@@ -260,8 +260,7 @@ void CPUParticles2D::restart() {
inactive_time = 0;
frame_remainder = 0;
cycle = 0;
-
- set_emitting(true);
+ emitting = false;
{
int pc = particles.size();
@@ -271,6 +270,8 @@ void CPUParticles2D::restart() {
w[i].active = false;
}
}
+
+ set_emitting(true);
}
void CPUParticles2D::set_direction(Vector2 p_direction) {
@@ -1036,7 +1037,9 @@ void CPUParticles2D::_set_redraw(bool p_redraw) {
VS::get_singleton()->multimesh_set_visible_instances(multimesh, -1);
} else {
- VS::get_singleton()->disconnect("frame_pre_draw", this, "_update_render_thread");
+ if (VS::get_singleton()->is_connected("frame_pre_draw", this, "_update_render_thread")) {
+ VS::get_singleton()->disconnect("frame_pre_draw", this, "_update_render_thread");
+ }
VS::get_singleton()->canvas_item_set_update_when_visible(get_canvas_item(), false);
VS::get_singleton()->multimesh_set_visible_instances(multimesh, 0);
@@ -1422,6 +1425,7 @@ CPUParticles2D::CPUParticles2D() {
frame_remainder = 0;
cycle = 0;
redraw = false;
+ emitting = false;
mesh = VisualServer::get_singleton()->mesh_create();
multimesh = VisualServer::get_singleton()->multimesh_create();
diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp
index ad405fabbb..af3ed671aa 100644
--- a/scene/2d/line_2d.cpp
+++ b/scene/2d/line_2d.cpp
@@ -47,6 +47,7 @@ Line2D::Line2D() {
_texture_mode = LINE_TEXTURE_NONE;
_sharp_limit = 2.f;
_round_precision = 8;
+ _antialiased = false;
}
Rect2 Line2D::_edit_get_rect() const {
@@ -260,6 +261,15 @@ int Line2D::get_round_precision() const {
return _round_precision;
}
+void Line2D::set_antialiased(bool p_antialiased) {
+ _antialiased = p_antialiased;
+ update();
+}
+
+bool Line2D::get_antialiased() const {
+ return _antialiased;
+}
+
void Line2D::_draw() {
if (_points.size() <= 1 || _width == 0.f)
return;
@@ -305,8 +315,8 @@ void Line2D::_draw() {
lb.vertices,
lb.colors,
lb.uvs, Vector<int>(), Vector<float>(),
-
- texture_rid);
+ texture_rid, -1, RID(),
+ _antialiased);
// DEBUG
// Draw wireframe
@@ -386,6 +396,9 @@ void Line2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_round_precision", "precision"), &Line2D::set_round_precision);
ClassDB::bind_method(D_METHOD("get_round_precision"), &Line2D::get_round_precision);
+ ClassDB::bind_method(D_METHOD("set_antialiased", "antialiased"), &Line2D::set_antialiased);
+ ClassDB::bind_method(D_METHOD("get_antialiased"), &Line2D::get_antialiased);
+
ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "points"), "set_points", "get_points");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "width_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve", "get_curve");
@@ -401,6 +414,7 @@ void Line2D::_bind_methods() {
ADD_GROUP("Border", "");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "sharp_limit"), "set_sharp_limit", "get_sharp_limit");
ADD_PROPERTY(PropertyInfo(Variant::INT, "round_precision"), "set_round_precision", "get_round_precision");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "antialiased"), "set_antialiased", "get_antialiased");
BIND_ENUM_CONSTANT(LINE_JOINT_SHARP);
BIND_ENUM_CONSTANT(LINE_JOINT_BEVEL);
diff --git a/scene/2d/line_2d.h b/scene/2d/line_2d.h
index 14afa463ba..10b2bf16e4 100644
--- a/scene/2d/line_2d.h
+++ b/scene/2d/line_2d.h
@@ -108,6 +108,9 @@ public:
void set_round_precision(int precision);
int get_round_precision() const;
+ void set_antialiased(bool p_antialiased);
+ bool get_antialiased() const;
+
protected:
void _notification(int p_what);
void _draw();
@@ -131,6 +134,7 @@ private:
LineTextureMode _texture_mode;
float _sharp_limit;
int _round_precision;
+ bool _antialiased;
};
#endif // LINE2D_H
diff --git a/scene/2d/navigation_2d.cpp b/scene/2d/navigation_2d.cpp
index 5cf28d6c89..c7d2dabbae 100644
--- a/scene/2d/navigation_2d.cpp
+++ b/scene/2d/navigation_2d.cpp
@@ -541,7 +541,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
if (CLOCK_TANGENT(apex_point, portal_left, left) >= 0) {
//process
- if (Math::is_zero_approx(portal_left.distance_squared_to(apex_point)) || CLOCK_TANGENT(apex_point, left, portal_right) > 0) {
+ if (portal_left.is_equal_approx(apex_point) || CLOCK_TANGENT(apex_point, left, portal_right) > 0) {
left_poly = p;
portal_left = left;
} else {
@@ -551,7 +551,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
left_poly = p;
portal_left = apex_point;
portal_right = apex_point;
- if (!path.size() || path[path.size() - 1] != apex_point)
+ if (!path.size() || !path[path.size() - 1].is_equal_approx(apex_point))
path.push_back(apex_point);
skip = true;
}
@@ -559,7 +559,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
if (!skip && CLOCK_TANGENT(apex_point, portal_right, right) <= 0) {
//process
- if (Math::is_zero_approx(portal_right.distance_squared_to(apex_point)) || CLOCK_TANGENT(apex_point, right, portal_left) < 0) {
+ if (portal_right.is_equal_approx(apex_point) || CLOCK_TANGENT(apex_point, right, portal_left) < 0) {
right_poly = p;
portal_right = right;
} else {
@@ -569,7 +569,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
right_poly = p;
portal_right = apex_point;
portal_left = apex_point;
- if (!path.size() || path[path.size() - 1] != apex_point)
+ if (!path.size() || !path[path.size() - 1].is_equal_approx(apex_point))
path.push_back(apex_point);
}
}
@@ -595,7 +595,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
}
}
- if (!path.size() || !Math::is_zero_approx(path[path.size() - 1].distance_squared_to(begin_point))) {
+ if (!path.size() || !path[path.size() - 1].is_equal_approx(begin_point)) {
path.push_back(begin_point); // Add the begin point
} else {
path.write[path.size() - 1] = begin_point; // Replace first midpoint by the exact begin point
@@ -603,7 +603,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
path.invert();
- if (path.size() <= 1 || !Math::is_zero_approx(path[path.size() - 1].distance_squared_to(end_point))) {
+ if (path.size() <= 1 || !path[path.size() - 1].is_equal_approx(end_point)) {
path.push_back(end_point); // Add the end point
} else {
path.write[path.size() - 1] = end_point; // Replace last midpoint by the exact end point
diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp
index 55c8c7f229..18ace5892a 100644
--- a/scene/2d/path_2d.cpp
+++ b/scene/2d/path_2d.cpp
@@ -173,16 +173,10 @@ void PathFollow2D::_update_transform() {
if (path_length == 0) {
return;
}
- float bounded_offset = offset;
- if (loop)
- bounded_offset = Math::fposmod(bounded_offset, path_length);
- else
- bounded_offset = CLAMP(bounded_offset, 0, path_length);
-
- Vector2 pos = c->interpolate_baked(bounded_offset, cubic);
+ Vector2 pos = c->interpolate_baked(offset, cubic);
if (rotate) {
- float ahead = bounded_offset + lookahead;
+ float ahead = offset + lookahead;
if (loop && ahead >= path_length) {
// If our lookahead will loop, we need to check if the path is closed.
@@ -206,7 +200,7 @@ void PathFollow2D::_update_transform() {
// This will happen at the end of non-looping or non-closed paths.
// We'll try a look behind instead, in order to get a meaningful angle.
tangent_to_curve =
- (pos - c->interpolate_baked(bounded_offset - lookahead, cubic)).normalized();
+ (pos - c->interpolate_baked(offset - lookahead, cubic)).normalized();
} else {
tangent_to_curve = (ahead_pos - pos).normalized();
}
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index 3a4f397fe0..a57bfd4cbe 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -1214,18 +1214,20 @@ bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_
Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_floor_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) {
- Vector2 floor_motion = floor_velocity;
+ Vector2 body_velocity = p_linear_velocity;
+ Vector2 body_velocity_normal = body_velocity.normalized();
+
+ 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);
if (bs) {
- floor_motion = bs->get_linear_velocity();
+ current_floor_velocity = bs->get_linear_velocity();
}
}
// Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky
- Vector2 motion = (floor_motion + p_linear_velocity) * (Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time());
- Vector2 lv = p_linear_velocity;
+ Vector2 motion = (current_floor_velocity + body_velocity) * (Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time());
on_floor = false;
on_floor_body = RID();
@@ -1234,14 +1236,12 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const
colliders.clear();
floor_velocity = Vector2();
- Vector2 lv_n = p_linear_velocity.normalized();
-
while (p_max_slides) {
Collision collision;
bool found_collision = false;
- for (int i = 0; i < 2; i++) {
+ for (int i = 0; i < 2; ++i) {
bool collided;
if (i == 0) { //collide
collided = move_and_collide(motion, p_infinite_inertia, collision);
@@ -1273,14 +1273,13 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const
floor_velocity = collision.collider_vel;
if (p_stop_on_slope) {
- if ((lv_n + p_floor_direction).length() < 0.01 && collision.travel.length() < 1) {
+ if ((body_velocity_normal + p_floor_direction).length() < 0.01 && collision.travel.length() < 1) {
Transform2D gt = get_global_transform();
- gt.elements[2] -= collision.travel.project(p_floor_direction.tangent());
+ gt.elements[2] -= collision.travel.slide(p_floor_direction);
set_global_transform(gt);
return Vector2();
}
}
-
} else if (Math::acos(collision.normal.dot(-p_floor_direction)) <= p_floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //ceiling
on_ceiling = true;
} else {
@@ -1288,21 +1287,18 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const
}
}
- Vector2 n = collision.normal;
- motion = motion.slide(n);
- lv = lv.slide(n);
+ motion = motion.slide(collision.normal);
+ body_velocity = body_velocity.slide(collision.normal);
}
}
- if (!found_collision) {
- break;
- }
- p_max_slides--;
- if (motion == Vector2())
+ if (!found_collision || motion == Vector2())
break;
+
+ --p_max_slides;
}
- return lv;
+ return body_velocity;
}
Vector2 KinematicBody2D::move_and_slide_with_snap(const Vector2 &p_linear_velocity, const Vector2 &p_snap, const Vector2 &p_floor_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) {
diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp
index 5e14959e9d..9fe67a4d7e 100644
--- a/scene/2d/polygon_2d.cpp
+++ b/scene/2d/polygon_2d.cpp
@@ -308,7 +308,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());
+ 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, RID(), antialiased);
}
} else {
//draw individual polygons
@@ -342,7 +342,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());
+ 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(), -1, RID(), antialiased);
}
#if 0
diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp
index bf8d008bb2..4f6f410bdc 100644
--- a/scene/2d/ray_cast_2d.cpp
+++ b/scene/2d/ray_cast_2d.cpp
@@ -180,8 +180,8 @@ void RayCast2D::_notification(int p_what) {
Vector<Vector2> pts;
float tsize = 8;
pts.push_back(xf.xform(Vector2(tsize, 0)));
- pts.push_back(xf.xform(Vector2(0, 0.707 * tsize)));
- pts.push_back(xf.xform(Vector2(0, -0.707 * tsize)));
+ pts.push_back(xf.xform(Vector2(0, Math_SQRT12 * tsize)));
+ pts.push_back(xf.xform(Vector2(0, -Math_SQRT12 * tsize)));
Vector<Color> cols;
for (int i = 0; i < 3; i++)
cols.push_back(draw_col);
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 173214dfe4..d75d8cfc55 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -1233,8 +1233,8 @@ void TileMap::_set_tile_data(const PoolVector<int> &p_data) {
}
#endif
- int16_t x = decode_uint16(&local[0]);
- int16_t y = decode_uint16(&local[2]);
+ uint16_t x = decode_uint16(&local[0]);
+ uint16_t y = decode_uint16(&local[2]);
uint32_t v = decode_uint32(&local[4]);
bool flip_h = v & (1 << 29);
bool flip_v = v & (1 << 30);
diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp
index cf68528388..9a1a759e72 100644
--- a/scene/2d/touch_screen_button.cpp
+++ b/scene/2d/touch_screen_button.cpp
@@ -325,12 +325,8 @@ void TouchScreenButton::_release(bool p_exiting_tree) {
}
Rect2 TouchScreenButton::_edit_get_rect() const {
- if (texture.is_null()) {
- if (shape.is_valid())
- return shape->get_rect();
- else
- return CanvasItem::_edit_get_rect();
- }
+ if (texture.is_null())
+ return CanvasItem::_edit_get_rect();
return Rect2(Size2(), texture->get_size());
}
diff --git a/scene/3d/arvr_nodes.h b/scene/3d/arvr_nodes.h
index 8e735f7110..b647df70aa 100644
--- a/scene/3d/arvr_nodes.h
+++ b/scene/3d/arvr_nodes.h
@@ -55,7 +55,7 @@ public:
virtual Vector3 project_local_ray_normal(const Point2 &p_pos) const;
virtual Point2 unproject_position(const Vector3 &p_pos) const;
- virtual Vector3 project_position(const Point2 &p_point, float p_z_depth = 0) const;
+ virtual Vector3 project_position(const Point2 &p_point, float p_z_depth) const;
virtual Vector<Plane> get_frustum() const;
ARVRCamera();
diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp
index 9797b5f3ab..4d9bb69778 100644
--- a/scene/3d/camera.cpp
+++ b/scene/3d/camera.cpp
@@ -486,7 +486,7 @@ void Camera::_bind_methods() {
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, DEFVAL(0));
+ 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);
diff --git a/scene/3d/camera.h b/scene/3d/camera.h
index 22223880c1..d81e097fc5 100644
--- a/scene/3d/camera.h
+++ b/scene/3d/camera.h
@@ -142,7 +142,7 @@ 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 = 0) const;
+ virtual Vector3 project_position(const Point2 &p_point, float p_z_depth) const;
Vector<Vector3> get_near_plane_points() const;
diff --git a/scene/3d/cpu_particles.cpp b/scene/3d/cpu_particles.cpp
index 5c895ecf22..86daabefd2 100644
--- a/scene/3d/cpu_particles.cpp
+++ b/scene/3d/cpu_particles.cpp
@@ -240,8 +240,7 @@ void CPUParticles::restart() {
inactive_time = 0;
frame_remainder = 0;
cycle = 0;
-
- set_emitting(true);
+ emitting = false;
{
int pc = particles.size();
@@ -251,6 +250,8 @@ void CPUParticles::restart() {
w[i].active = false;
}
}
+
+ set_emitting(true);
}
void CPUParticles::set_direction(Vector3 p_direction) {
@@ -1123,7 +1124,9 @@ void CPUParticles::_set_redraw(bool p_redraw) {
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);
} else {
- VS::get_singleton()->disconnect("frame_pre_draw", this, "_update_render_thread");
+ if (VS::get_singleton()->is_connected("frame_pre_draw", this, "_update_render_thread")) {
+ VS::get_singleton()->disconnect("frame_pre_draw", this, "_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);
}
@@ -1494,6 +1497,7 @@ CPUParticles::CPUParticles() {
frame_remainder = 0;
cycle = 0;
redraw = false;
+ emitting = false;
set_notify_transform(true);
diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp
index ccc87b924c..ce7bb25665 100644
--- a/scene/3d/gi_probe.cpp
+++ b/scene/3d/gi_probe.cpp
@@ -386,11 +386,7 @@ void GIProbe::_find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes) {
}
for (int i = 0; i < p_at_node->get_child_count(); i++) {
-
Node *child = p_at_node->get_child(i);
- if (!child->get_owner())
- continue; //maybe a helper
-
_find_meshes(child, plot_meshes);
}
}
diff --git a/scene/3d/navigation_mesh.h b/scene/3d/navigation_mesh.h
index 8467f80f0e..d5de653e40 100644
--- a/scene/3d/navigation_mesh.h
+++ b/scene/3d/navigation_mesh.h
@@ -124,7 +124,7 @@ public:
void set_collision_mask_bit(int p_bit, bool p_value);
bool get_collision_mask_bit(int p_bit) const;
- void set_source_geometry_mode(int p_source_mode);
+ void set_source_geometry_mode(int p_geometry_mode);
int get_source_geometry_mode() const;
void set_source_group_name(StringName p_group_name);
diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp
index 241eb7d1ca..06b5613eb8 100644
--- a/scene/3d/particles.cpp
+++ b/scene/3d/particles.cpp
@@ -331,6 +331,13 @@ void Particles::_notification(int p_what) {
set_process_internal(false);
}
}
+
+ 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);
+ }
+ }
}
void Particles::_bind_methods() {
diff --git a/scene/3d/path.cpp b/scene/3d/path.cpp
index d55c795d38..62684bd1e1 100644
--- a/scene/3d/path.cpp
+++ b/scene/3d/path.cpp
@@ -111,18 +111,15 @@ void PathFollow::_update_transform() {
return;
}
float bi = c->get_bake_interval();
- float o = offset;
float o_next = offset + bi;
if (loop) {
- o = Math::fposmod(o, bl);
o_next = Math::fposmod(o_next, bl);
} else if (rotation_mode == ROTATION_ORIENTED && o_next >= bl) {
- o = bl - bi;
o_next = bl;
}
- Vector3 pos = c->interpolate_baked(o, cubic);
+ Vector3 pos = c->interpolate_baked(offset, cubic);
Transform t = get_transform();
// Vector3 pos_offset = Vector3(h_offset, v_offset, 0); not used in all cases
// will be replaced by "Vector3(h_offset, v_offset, 0)" where it was formerly used
@@ -136,9 +133,9 @@ void PathFollow::_update_transform() {
else
forward.normalize();
- Vector3 up = c->interpolate_baked_up_vector(o, true);
+ Vector3 up = c->interpolate_baked_up_vector(offset, true);
- if (o_next < o) {
+ if (o_next < offset) {
Vector3 up1 = c->interpolate_baked_up_vector(o_next, true);
Vector3 axis = up.cross(up1);
@@ -166,8 +163,8 @@ void PathFollow::_update_transform() {
t.origin = pos;
- Vector3 t_prev = (pos - c->interpolate_baked(o - delta_offset, cubic)).normalized();
- Vector3 t_cur = (c->interpolate_baked(o + delta_offset, cubic) - pos).normalized();
+ Vector3 t_prev = (pos - c->interpolate_baked(offset - delta_offset, cubic)).normalized();
+ Vector3 t_cur = (c->interpolate_baked(offset + delta_offset, cubic) - pos).normalized();
Vector3 axis = t_prev.cross(t_cur);
float dot = t_prev.dot(t_cur);
@@ -190,7 +187,7 @@ void PathFollow::_update_transform() {
}
// do the additional tilting
- float tilt_angle = c->interpolate_baked_tilt(o);
+ float tilt_angle = c->interpolate_baked_tilt(offset);
Vector3 tilt_axis = t_cur; // not sure what tilt is supposed to do, is this correct??
if (likely(!Math::is_zero_approx(Math::abs(tilt_angle)))) {
@@ -256,7 +253,7 @@ void PathFollow::_validate_property(PropertyInfo &property) const {
if (path && path->get_curve().is_valid())
max = path->get_curve()->get_baked_length();
- property.hint_string = "0," + rtos(max) + ",0.01,or_greater";
+ property.hint_string = "0," + rtos(max) + ",0.01,or_lesser";
}
}
@@ -300,8 +297,8 @@ void PathFollow::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_loop", "loop"), &PathFollow::set_loop);
ClassDB::bind_method(D_METHOD("has_loop"), &PathFollow::has_loop);
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "offset", PROPERTY_HINT_RANGE, "0,10000,0.01,or_greater"), "set_offset", "get_offset");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "unit_offset", PROPERTY_HINT_RANGE, "0,1,0.0001,or_greater", PROPERTY_USAGE_EDITOR), "set_unit_offset", "get_unit_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "offset", PROPERTY_HINT_RANGE, "0,10000,0.01,or_lesser"), "set_offset", "get_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "unit_offset", PROPERTY_HINT_RANGE, "0,1,0.0001,or_lesser", PROPERTY_USAGE_EDITOR), "set_unit_offset", "get_unit_offset");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "h_offset"), "set_h_offset", "get_h_offset");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "v_offset"), "set_v_offset", "get_v_offset");
ADD_PROPERTY(PropertyInfo(Variant::INT, "rotation_mode", PROPERTY_HINT_ENUM, "None,Y,XY,XYZ,Oriented"), "set_rotation_mode", "get_rotation_mode");
@@ -319,8 +316,24 @@ void PathFollow::set_offset(float p_offset) {
delta_offset = p_offset - offset;
offset = p_offset;
- if (path)
+ if (path) {
+ if (path->get_curve().is_valid() && path->get_curve()->get_baked_length()) {
+ float path_length = path->get_curve()->get_baked_length();
+
+ if (loop) {
+ while (offset > path_length)
+ offset -= path_length;
+
+ while (offset < 0)
+ offset += path_length;
+
+ } else {
+ offset = CLAMP(offset, 0, path_length);
+ }
+ }
+
_update_transform();
+ }
_change_notify("offset");
_change_notify("unit_offset");
}
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp
index a02cc4bee6..6049b6cdb4 100644
--- a/scene/3d/physics_body.cpp
+++ b/scene/3d/physics_body.cpp
@@ -1142,25 +1142,34 @@ bool KinematicBody::move_and_collide(const Vector3 &p_motion, bool p_infinite_in
Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_floor_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) {
- Vector3 lv = p_linear_velocity;
+ Vector3 body_velocity = p_linear_velocity;
+ Vector3 body_velocity_normal = body_velocity.normalized();
for (int i = 0; i < 3; i++) {
if (locked_axis & (1 << i)) {
- lv[i] = 0;
+ body_velocity[i] = 0;
+ }
+ }
+
+ Vector3 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
+ PhysicsDirectBodyState *bs = PhysicsServer::get_singleton()->body_get_direct_state(on_floor_body);
+ if (bs) {
+ current_floor_velocity = bs->get_linear_velocity();
}
}
// Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky
- Vector3 motion = (floor_velocity + lv) * (Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time());
+ Vector3 motion = (current_floor_velocity + body_velocity) * (Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time());
on_floor = false;
+ on_floor_body = RID();
on_ceiling = false;
on_wall = false;
colliders.clear();
floor_velocity = Vector3();
- Vector3 lv_n = p_linear_velocity.normalized();
-
while (p_max_slides) {
Collision collision;
@@ -1187,7 +1196,6 @@ Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Ve
colliders.push_back(collision);
motion = collision.remainder;
- bool is_on_slope = false;
if (p_floor_direction == Vector3()) {
//all is a wall
on_wall = true;
@@ -1199,16 +1207,13 @@ Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Ve
floor_velocity = collision.collider_vel;
if (p_stop_on_slope) {
- if ((lv_n + p_floor_direction).length() < 0.01 && collision.travel.length() < 1) {
+ if ((body_velocity_normal + p_floor_direction).length() < 0.01 && collision.travel.length() < 1) {
Transform gt = get_global_transform();
- gt.origin -= collision.travel;
+ gt.origin -= collision.travel.slide(p_floor_direction);
set_global_transform(gt);
return Vector3();
}
}
-
- is_on_slope = true;
-
} else if (Math::acos(collision.normal.dot(-p_floor_direction)) <= p_floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //ceiling
on_ceiling = true;
} else {
@@ -1216,18 +1221,12 @@ Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Ve
}
}
- if (p_stop_on_slope && is_on_slope) {
- motion = motion.slide(p_floor_direction);
- lv = lv.slide(p_floor_direction);
- } else {
- Vector3 n = collision.normal;
- motion = motion.slide(n);
- lv = lv.slide(n);
- }
+ motion = motion.slide(collision.normal);
+ body_velocity = body_velocity.slide(collision.normal);
for (int j = 0; j < 3; j++) {
if (locked_axis & (1 << j)) {
- lv[j] = 0;
+ body_velocity[j] = 0;
}
}
}
@@ -1239,7 +1238,7 @@ Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Ve
--p_max_slides;
}
- return lv;
+ return body_velocity;
}
Vector3 KinematicBody::move_and_slide_with_snap(const Vector3 &p_linear_velocity, const Vector3 &p_snap, const Vector3 &p_floor_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) {
@@ -1265,7 +1264,7 @@ Vector3 KinematicBody::move_and_slide_with_snap(const Vector3 &p_linear_velocity
if (p_stop_on_slope) {
// move and collide may stray the object a bit because of pre un-stucking,
// so only ensure that motion happens on floor direction in this case.
- col.travel = p_floor_direction * p_floor_direction.dot(col.travel);
+ col.travel = col.travel.project(p_floor_direction);
}
} else {
apply = false; //snapped with floor direction, but did not snap to a floor, do not snap.
@@ -2161,6 +2160,9 @@ void PhysicalBone::_notification(int p_what) {
update_bone_id();
reset_to_rest_position();
_reset_physics_simulation_state();
+ if (!joint.is_valid() && joint_data) {
+ _reload_joint();
+ }
break;
case NOTIFICATION_EXIT_TREE:
if (parent_skeleton) {
@@ -2169,7 +2171,10 @@ void PhysicalBone::_notification(int p_what) {
}
}
parent_skeleton = NULL;
- update_bone_id();
+ if (joint.is_valid()) {
+ PhysicsServer::get_singleton()->free(joint);
+ joint = RID();
+ }
break;
case NOTIFICATION_TRANSFORM_CHANGED:
if (Engine::get_singleton()->is_editor_hint()) {
diff --git a/scene/3d/soft_body.cpp b/scene/3d/soft_body.cpp
index 6c3949a0a8..6883da7f6d 100644
--- a/scene/3d/soft_body.cpp
+++ b/scene/3d/soft_body.cpp
@@ -115,7 +115,7 @@ SoftBody::PinnedPoint SoftBody::PinnedPoint::operator=(const PinnedPoint &obj) {
void SoftBody::_update_pickable() {
if (!is_inside_tree())
return;
- bool pickable = ray_pickable && is_inside_tree() && is_visible_in_tree();
+ bool pickable = ray_pickable && is_visible_in_tree();
PhysicsServer::get_singleton()->soft_body_set_ray_pickable(physics_rid, pickable);
}
@@ -395,6 +395,8 @@ void SoftBody::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "damping_coefficient", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_damping_coefficient", "get_damping_coefficient");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "drag_coefficient", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drag_coefficient", "get_drag_coefficient");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "pose_matching_coefficient", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_pose_matching_coefficient", "get_pose_matching_coefficient");
+
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ray_pickable"), "set_ray_pickable", "is_ray_pickable");
}
String SoftBody::get_configuration_warning() const {
@@ -460,7 +462,9 @@ void SoftBody::update_physics_server() {
} else {
PhysicsServer::get_singleton()->soft_body_set_mesh(physics_rid, NULL);
- VS::get_singleton()->disconnect("frame_pre_draw", this, "_draw_soft_mesh");
+ if (VS::get_singleton()->is_connected("frame_pre_draw", this, "_draw_soft_mesh")) {
+ VS::get_singleton()->disconnect("frame_pre_draw", this, "_draw_soft_mesh");
+ }
}
}
@@ -698,7 +702,8 @@ SoftBody::SoftBody() :
collision_mask(1),
collision_layer(1),
simulation_started(false),
- pinned_points_cache_dirty(true) {
+ pinned_points_cache_dirty(true),
+ ray_pickable(true) {
PhysicsServer::get_singleton()->body_attach_object_instance_id(physics_rid, get_instance_id());
//set_notify_transform(true);
diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp
index 9a659ef4af..043d5d5548 100644
--- a/scene/3d/spatial.cpp
+++ b/scene/3d/spatial.cpp
@@ -322,6 +322,7 @@ Transform Spatial::get_relative_transform(const Node *p_parent) const {
void Spatial::set_translation(const Vector3 &p_translation) {
data.local_transform.origin = p_translation;
+ _change_notify("transform");
_propagate_transform_changed(this);
if (data.notify_local_transform) {
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
@@ -337,6 +338,7 @@ void Spatial::set_rotation(const Vector3 &p_euler_rad) {
data.rotation = p_euler_rad;
data.dirty |= DIRTY_LOCAL;
+ _change_notify("transform");
_propagate_transform_changed(this);
if (data.notify_local_transform) {
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
@@ -357,6 +359,7 @@ void Spatial::set_scale(const Vector3 &p_scale) {
data.scale = p_scale;
data.dirty |= DIRTY_LOCAL;
+ _change_notify("transform");
_propagate_transform_changed(this);
if (data.notify_local_transform) {
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
diff --git a/scene/3d/voxel_light_baker.cpp b/scene/3d/voxel_light_baker.cpp
index 8e09930aed..3235953730 100644
--- a/scene/3d/voxel_light_baker.cpp
+++ b/scene/3d/voxel_light_baker.cpp
@@ -1594,10 +1594,10 @@ Vector3 VoxelLightBaker::_compute_pixel_light_at_pos(const Vector3 &p_pos, const
case BAKE_QUALITY_LOW: {
//default quality
static const Vector3 dirs[4] = {
- Vector3(0.707107, 0, 0.707107),
- Vector3(0, 0.707107, 0.707107),
- Vector3(-0.707107, 0, 0.707107),
- Vector3(0, -0.707107, 0.707107)
+ Vector3(Math_SQRT12, 0, Math_SQRT12),
+ Vector3(0, Math_SQRT12, Math_SQRT12),
+ Vector3(-Math_SQRT12, 0, Math_SQRT12),
+ Vector3(0, -Math_SQRT12, Math_SQRT12)
};
static const float weights[4] = { 0.25, 0.25, 0.25, 0.25 };
diff --git a/scene/SCsub b/scene/SCsub
index d8839ce3a8..1c5b87b87a 100644
--- a/scene/SCsub
+++ b/scene/SCsub
@@ -30,6 +30,7 @@ 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/animation_blend_space_1d.cpp b/scene/animation/animation_blend_space_1d.cpp
index 416a291da1..7fe544eaab 100644
--- a/scene/animation/animation_blend_space_1d.cpp
+++ b/scene/animation/animation_blend_space_1d.cpp
@@ -157,6 +157,7 @@ Ref<AnimationRootNode> AnimationNodeBlendSpace1D::get_blend_point_node(int p_poi
void AnimationNodeBlendSpace1D::remove_blend_point(int p_point) {
ERR_FAIL_INDEX(p_point, blend_points_used);
+ ERR_FAIL_COND(blend_points[p_point].node.is_null());
blend_points[p_point].node->disconnect("tree_changed", this, "_tree_changed");
for (int i = p_point; i < blend_points_used - 1; i++) {
diff --git a/scene/animation/animation_blend_space_2d.cpp b/scene/animation/animation_blend_space_2d.cpp
index 75031f0149..b04eefbe31 100644
--- a/scene/animation/animation_blend_space_2d.cpp
+++ b/scene/animation/animation_blend_space_2d.cpp
@@ -113,6 +113,7 @@ Ref<AnimationRootNode> AnimationNodeBlendSpace2D::get_blend_point_node(int p_poi
void AnimationNodeBlendSpace2D::remove_blend_point(int p_point) {
ERR_FAIL_INDEX(p_point, blend_points_used);
+ ERR_FAIL_COND(blend_points[p_point].node.is_null());
blend_points[p_point].node->disconnect("tree_changed", this, "_tree_changed");
for (int i = 0; i < triangles.size(); i++) {
diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp
index 65bf1e0134..a37b75d428 100644
--- a/scene/animation/animation_node_state_machine.cpp
+++ b/scene/animation/animation_node_state_machine.cpp
@@ -312,27 +312,36 @@ float AnimationNodeStateMachinePlayback::process(AnimationNodeStateMachine *p_st
bool play_start = false;
if (start_request != StringName()) {
-
if (start_request_travel) {
if (!playing) {
- String node_name = start_request;
- start_request = StringName();
- ERR_FAIL_V_MSG(0, "Can't travel to '" + node_name + "' if state machine is not playing.");
- }
-
- if (!_travel(p_state_machine, start_request)) {
- //can't travel, then teleport
- path.clear();
- current = start_request;
+ if (!stop_request && p_state_machine->start_node) {
+ // can restart, just postpone traveling
+ path.clear();
+ current = p_state_machine->start_node;
+ playing = true;
+ play_start = true;
+ } else {
+ // stopped, invalid state
+ String node_name = start_request;
+ start_request = StringName(); //clear start request
+ ERR_FAIL_V_MSG(0, "Can't travel to '" + node_name + "' if state machine is not playing.");
+ }
+ } else {
+ if (!_travel(p_state_machine, start_request)) {
+ // can't travel, then teleport
+ path.clear();
+ current = start_request;
+ }
+ start_request = StringName(); //clear start request
}
} else {
+ // teleport to start
path.clear();
current = start_request;
playing = true;
play_start = true;
+ start_request = StringName(); //clear start request
}
-
- start_request = StringName(); //clear start request
}
bool do_start = (p_seek && p_time == 0) || play_start || current == StringName();
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp
index 1f9793190d..ce3f2b3b1a 100644
--- a/scene/animation/tween.cpp
+++ b/scene/animation/tween.cpp
@@ -63,6 +63,8 @@ void Tween::_add_pending_command(StringName p_key, const Variant &p_arg1, const
count = 2;
else if (p_arg1.get_type() != Variant::NIL)
count = 1;
+ else
+ count = 0;
// Add the specified arguments to the command
// TODO: Make this a switch statement?
@@ -281,7 +283,7 @@ void Tween::_bind_methods() {
BIND_ENUM_CONSTANT(EASE_OUT_IN);
}
-Variant &Tween::_get_initial_val(InterpolateData &p_data) {
+Variant Tween::_get_initial_val(const InterpolateData &p_data) const {
// What type of data are we interpolating?
switch (p_data.type) {
@@ -299,7 +301,7 @@ Variant &Tween::_get_initial_val(InterpolateData &p_data) {
ERR_FAIL_COND_V(object == NULL, p_data.initial_val);
// Are we targeting a property or a method?
- static Variant initial_val;
+ Variant initial_val;
if (p_data.type == TARGETING_PROPERTY) {
// Get the property from the target object
bool valid = false;
@@ -322,6 +324,41 @@ Variant &Tween::_get_initial_val(InterpolateData &p_data) {
return p_data.delta_val;
}
+Variant Tween::_get_final_val(const InterpolateData &p_data) const {
+ switch (p_data.type) {
+ case FOLLOW_PROPERTY:
+ 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);
+
+ // We want to figure out the final value
+ Variant final_val;
+ if (p_data.type == FOLLOW_PROPERTY) {
+ // Read the property as-is
+ bool valid = false;
+ final_val = target->get_indexed(p_data.target_key, &valid);
+ ERR_FAIL_COND_V(!valid, p_data.initial_val);
+ } else {
+ // We're looking at a method. Call the method on the target object
+ Variant::CallError error;
+ final_val = target->call(p_data.target_key[0], NULL, 0, error);
+ ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK, p_data.initial_val);
+ }
+
+ // If we're looking at an INT value, instead convert it to a REAL
+ // This is better for interpolation
+ if (final_val.get_type() == Variant::INT) final_val = final_val.operator real_t();
+
+ return final_val;
+ }
+ default: {
+ // If we're not following a final value/method, use the final value from the data
+ return p_data.final_val;
+ }
+ }
+}
+
Variant &Tween::_get_delta_val(InterpolateData &p_data) {
// What kind of data are we interpolating?
@@ -384,7 +421,7 @@ Variant &Tween::_get_delta_val(InterpolateData &p_data) {
Variant Tween::_run_equation(InterpolateData &p_data) {
// Get the initial and delta values from the data
- Variant &initial_val = _get_initial_val(p_data);
+ Variant initial_val = _get_initial_val(p_data);
Variant &delta_val = _get_delta_val(p_data);
Variant result;
@@ -718,7 +755,8 @@ void Tween::_tween_process(float p_delta) {
// Is the tween now finished?
if (data.finish) {
// Set it to the final value directly
- _apply_tween_value(data, data.final_val);
+ Variant final_val = _get_final_val(data);
+ _apply_tween_value(data, final_val);
// Mark the tween as completed and emit the signal
data.elapsed = 0;
diff --git a/scene/animation/tween.h b/scene/animation/tween.h
index 64ce099ecd..e4c95a93d6 100644
--- a/scene/animation/tween.h
+++ b/scene/animation/tween.h
@@ -101,6 +101,12 @@ private:
int args;
Variant arg[5];
int uid;
+ InterpolateData() {
+ active = false;
+ finish = false;
+ call_deferred = false;
+ uid = 0;
+ }
};
String autoplay;
@@ -127,7 +133,8 @@ private:
real_t _run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d);
Variant &_get_delta_val(InterpolateData &p_data);
- Variant &_get_initial_val(InterpolateData &p_data);
+ Variant _get_initial_val(const InterpolateData &p_data) const;
+ Variant _get_final_val(const InterpolateData &p_data) const;
Variant _run_equation(InterpolateData &p_data);
bool _calc_delta_val(const Variant &p_initial_val, const Variant &p_final_val, Variant &p_delta_val);
bool _apply_tween_value(InterpolateData &p_data, Variant &value);
diff --git a/scene/debugger/SCsub b/scene/debugger/SCsub
new file mode 100644
index 0000000000..b01e2fd54d
--- /dev/null
+++ b/scene/debugger/SCsub
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+Import('env')
+
+env.add_source_files(env.scene_sources, "*.cpp")
diff --git a/scene/debugger/script_debugger_remote.cpp b/scene/debugger/script_debugger_remote.cpp
new file mode 100644
index 0000000000..c3c6a088cb
--- /dev/null
+++ b/scene/debugger/script_debugger_remote.cpp
@@ -0,0 +1,1280 @@
+/*************************************************************************/
+/* script_debugger_remote.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 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 "script_debugger_remote.h"
+
+#include "core/engine.h"
+#include "core/io/ip.h"
+#include "core/io/marshalls.h"
+#include "core/os/input.h"
+#include "core/os/os.h"
+#include "core/project_settings.h"
+#include "scene/main/node.h"
+#include "scene/main/scene_tree.h"
+#include "scene/main/viewport.h"
+#include "scene/resources/packed_scene.h"
+#include "servers/visual_server.h"
+
+void ScriptDebuggerRemote::_send_video_memory() {
+
+ List<ResourceUsage> usage;
+ if (resource_usage_func)
+ resource_usage_func(&usage);
+
+ usage.sort();
+
+ packet_peer_stream->put_var("message:video_mem");
+ packet_peer_stream->put_var(usage.size() * 4);
+
+ for (List<ResourceUsage>::Element *E = usage.front(); E; E = E->next()) {
+
+ packet_peer_stream->put_var(E->get().path);
+ packet_peer_stream->put_var(E->get().type);
+ packet_peer_stream->put_var(E->get().format);
+ packet_peer_stream->put_var(E->get().vram);
+ }
+}
+
+Error ScriptDebuggerRemote::connect_to_host(const String &p_host, uint16_t p_port) {
+
+ IP_Address ip;
+ if (p_host.is_valid_ip_address())
+ ip = p_host;
+ else
+ ip = IP::get_singleton()->resolve_hostname(p_host);
+
+ int port = p_port;
+
+ const int tries = 6;
+ int waits[tries] = { 1, 10, 100, 1000, 1000, 1000 };
+
+ tcp_client->connect_to_host(ip, port);
+
+ for (int i = 0; i < tries; i++) {
+
+ if (tcp_client->get_status() == StreamPeerTCP::STATUS_CONNECTED) {
+ print_verbose("Remote Debugger: Connected!");
+ break;
+ } else {
+
+ const int ms = waits[i];
+ OS::get_singleton()->delay_usec(ms * 1000);
+ print_verbose("Remote Debugger: Connection failed with status: '" + String::num(tcp_client->get_status()) + "', retrying in " + String::num(ms) + " msec.");
+ };
+ };
+
+ if (tcp_client->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
+
+ ERR_PRINTS("Remote Debugger: Unable to connect. Status: " + String::num(tcp_client->get_status()) + ".");
+ return FAILED;
+ };
+
+ packet_peer_stream->set_stream_peer(tcp_client);
+
+ return OK;
+}
+
+void ScriptDebuggerRemote::_put_variable(const String &p_name, const Variant &p_variable) {
+
+ packet_peer_stream->put_var(p_name);
+
+ Variant var = p_variable;
+ if (p_variable.get_type() == Variant::OBJECT && !ObjectDB::instance_validate(p_variable)) {
+ var = Variant();
+ }
+
+ int len = 0;
+ Error err = encode_variant(var, NULL, len, true);
+ if (err != OK)
+ ERR_PRINT("Failed to encode variant.");
+
+ if (len > packet_peer_stream->get_output_buffer_max_size()) { //limit to max size
+ packet_peer_stream->put_var(Variant());
+ } else {
+ packet_peer_stream->put_var(var);
+ }
+}
+
+void ScriptDebuggerRemote::_save_node(ObjectID id, const String &p_path) {
+
+ Node *node = Object::cast_to<Node>(ObjectDB::get_instance(id));
+ ERR_FAIL_COND(!node);
+
+ Ref<PackedScene> ps = memnew(PackedScene);
+ ps->pack(node);
+ ResourceSaver::save(p_path, ps);
+}
+
+void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue, bool p_is_error_breakpoint) {
+
+ //this function is called when there is a debugger break (bug on script)
+ //or when execution is paused from editor
+
+ if (skip_breakpoints && !p_is_error_breakpoint)
+ return;
+
+ ERR_FAIL_COND_MSG(!tcp_client->is_connected_to_host(), "Script Debugger failed to connect, but being used anyway.");
+
+ packet_peer_stream->put_var("debug_enter");
+ packet_peer_stream->put_var(2);
+ packet_peer_stream->put_var(p_can_continue);
+ packet_peer_stream->put_var(p_script->debug_get_error());
+
+ skip_profile_frame = true; // to avoid super long frame time for the frame
+
+ Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode();
+ if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
+ Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
+
+ uint64_t loop_begin_usec = 0;
+ uint64_t loop_time_sec = 0;
+ while (true) {
+ loop_begin_usec = OS::get_singleton()->get_ticks_usec();
+
+ _get_output();
+
+ if (packet_peer_stream->get_available_packet_count() > 0) {
+
+ Variant var;
+ Error err = packet_peer_stream->get_var(var);
+
+ ERR_CONTINUE(err != OK);
+ ERR_CONTINUE(var.get_type() != Variant::ARRAY);
+
+ Array cmd = var;
+
+ ERR_CONTINUE(cmd.size() == 0);
+ ERR_CONTINUE(cmd[0].get_type() != Variant::STRING);
+
+ String command = cmd[0];
+
+ if (command == "get_stack_dump") {
+
+ packet_peer_stream->put_var("stack_dump");
+ int slc = p_script->debug_get_stack_level_count();
+ packet_peer_stream->put_var(slc);
+
+ for (int i = 0; i < slc; i++) {
+
+ Dictionary d;
+ d["file"] = p_script->debug_get_stack_level_source(i);
+ d["line"] = p_script->debug_get_stack_level_line(i);
+ d["function"] = p_script->debug_get_stack_level_function(i);
+ //d["id"]=p_script->debug_get_stack_level_
+ d["id"] = 0;
+
+ packet_peer_stream->put_var(d);
+ }
+
+ } else if (command == "get_stack_frame_vars") {
+
+ cmd.remove(0);
+ ERR_CONTINUE(cmd.size() != 1);
+ int lv = cmd[0];
+
+ List<String> members;
+ List<Variant> member_vals;
+ if (ScriptInstance *inst = p_script->debug_get_stack_level_instance(lv)) {
+ members.push_back("self");
+ member_vals.push_back(inst->get_owner());
+ }
+ p_script->debug_get_stack_level_members(lv, &members, &member_vals);
+ ERR_CONTINUE(members.size() != member_vals.size());
+
+ List<String> locals;
+ List<Variant> local_vals;
+ p_script->debug_get_stack_level_locals(lv, &locals, &local_vals);
+ ERR_CONTINUE(locals.size() != local_vals.size());
+
+ List<String> globals;
+ List<Variant> globals_vals;
+ p_script->debug_get_globals(&globals, &globals_vals);
+ ERR_CONTINUE(globals.size() != globals_vals.size());
+
+ packet_peer_stream->put_var("stack_frame_vars");
+ packet_peer_stream->put_var(3 + (locals.size() + members.size() + globals.size()) * 2);
+
+ { //locals
+ packet_peer_stream->put_var(locals.size());
+
+ List<String>::Element *E = locals.front();
+ List<Variant>::Element *F = local_vals.front();
+
+ while (E) {
+ _put_variable(E->get(), F->get());
+
+ E = E->next();
+ F = F->next();
+ }
+ }
+
+ { //members
+ packet_peer_stream->put_var(members.size());
+
+ List<String>::Element *E = members.front();
+ List<Variant>::Element *F = member_vals.front();
+
+ while (E) {
+
+ _put_variable(E->get(), F->get());
+
+ E = E->next();
+ F = F->next();
+ }
+ }
+
+ { //globals
+ packet_peer_stream->put_var(globals.size());
+
+ List<String>::Element *E = globals.front();
+ List<Variant>::Element *F = globals_vals.front();
+
+ while (E) {
+ _put_variable(E->get(), F->get());
+
+ E = E->next();
+ F = F->next();
+ }
+ }
+
+ } else if (command == "step") {
+
+ set_depth(-1);
+ set_lines_left(1);
+ break;
+ } else if (command == "next") {
+
+ set_depth(0);
+ set_lines_left(1);
+ break;
+
+ } else if (command == "continue") {
+ set_depth(-1);
+ set_lines_left(-1);
+ OS::get_singleton()->move_window_to_foreground();
+ break;
+ } else if (command == "break") {
+ ERR_PRINT("Got break when already broke!");
+ break;
+ } else if (command == "request_scene_tree") {
+
+#ifdef DEBUG_ENABLED
+ if (scene_tree)
+ scene_tree->_debugger_request_tree();
+#endif
+ } else if (command == "request_video_mem") {
+
+ _send_video_memory();
+ } else if (command == "inspect_object") {
+
+ ObjectID id = cmd[1];
+ _send_object_id(id);
+ } else if (command == "set_object_property") {
+
+ _set_object_property(cmd[1], cmd[2], cmd[3]);
+
+ } else if (command == "override_camera_2D:set") {
+ bool enforce = cmd[1];
+
+ if (scene_tree) {
+ scene_tree->get_root()->enable_canvas_transform_override(enforce);
+ }
+ } else if (command == "override_camera_2D:transform") {
+ Transform2D transform = cmd[1];
+
+ if (scene_tree) {
+ scene_tree->get_root()->set_canvas_transform_override(transform);
+ }
+ } else if (command == "override_camera_3D:set") {
+ bool enable = cmd[1];
+
+ if (scene_tree) {
+ scene_tree->get_root()->enable_camera_override(enable);
+ }
+ } else if (command == "override_camera_3D:transform") {
+ Transform transform = cmd[1];
+ bool is_perspective = cmd[2];
+ float size_or_fov = cmd[3];
+ float near = cmd[4];
+ float far = cmd[5];
+
+ if (scene_tree) {
+ if (is_perspective) {
+ scene_tree->get_root()->set_camera_override_perspective(size_or_fov, near, far);
+ } else {
+ scene_tree->get_root()->set_camera_override_orthogonal(size_or_fov, near, far);
+ }
+ scene_tree->get_root()->set_camera_override_transform(transform);
+ }
+
+ } else if (command == "reload_scripts") {
+ reload_all_scripts = true;
+ } else if (command == "breakpoint") {
+
+ bool set = cmd[3];
+ if (set)
+ insert_breakpoint(cmd[2], cmd[1]);
+ else
+ remove_breakpoint(cmd[2], cmd[1]);
+
+ } else if (command == "save_node") {
+ _save_node(cmd[1], cmd[2]);
+ } else if (command == "set_skip_breakpoints") {
+ skip_breakpoints = cmd[1];
+ } else {
+ _parse_live_edit(cmd);
+ }
+
+ } else {
+ OS::get_singleton()->delay_usec(10000);
+ OS::get_singleton()->process_and_drop_events();
+ }
+
+ // This is for the camera override to stay live even when the game is paused from the editor
+ loop_time_sec = (OS::get_singleton()->get_ticks_usec() - loop_begin_usec) / 1000000.0f;
+ VisualServer::get_singleton()->sync();
+ if (VisualServer::get_singleton()->has_changed()) {
+ VisualServer::get_singleton()->draw(true, loop_time_sec * Engine::get_singleton()->get_time_scale());
+ }
+ }
+
+ packet_peer_stream->put_var("debug_exit");
+ packet_peer_stream->put_var(0);
+
+ if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
+ Input::get_singleton()->set_mouse_mode(mouse_mode);
+}
+
+void ScriptDebuggerRemote::_get_output() {
+
+ mutex->lock();
+ if (output_strings.size()) {
+
+ locking = true;
+ packet_peer_stream->put_var("output");
+ packet_peer_stream->put_var(output_strings.size());
+
+ while (output_strings.size()) {
+
+ packet_peer_stream->put_var(output_strings.front()->get());
+ output_strings.pop_front();
+ }
+ locking = false;
+ }
+
+ if (n_messages_dropped > 0) {
+ Message msg;
+ msg.message = "Too many messages! " + String::num_int64(n_messages_dropped) + " messages were dropped.";
+ messages.push_back(msg);
+ n_messages_dropped = 0;
+ }
+
+ while (messages.size()) {
+ locking = true;
+ packet_peer_stream->put_var("message:" + messages.front()->get().message);
+ packet_peer_stream->put_var(messages.front()->get().data.size());
+ for (int i = 0; i < messages.front()->get().data.size(); i++) {
+ packet_peer_stream->put_var(messages.front()->get().data[i]);
+ }
+ messages.pop_front();
+ locking = false;
+ }
+
+ if (n_errors_dropped == 1) {
+ // Only print one message about dropping per second
+ OutputError oe;
+ oe.error = "TOO_MANY_ERRORS";
+ oe.error_descr = "Too many errors! Ignoring errors for up to 1 second.";
+ oe.warning = false;
+ uint64_t time = OS::get_singleton()->get_ticks_msec();
+ oe.hr = time / 3600000;
+ oe.min = (time / 60000) % 60;
+ oe.sec = (time / 1000) % 60;
+ oe.msec = time % 1000;
+ errors.push_back(oe);
+ }
+
+ if (n_warnings_dropped == 1) {
+ // Only print one message about dropping per second
+ OutputError oe;
+ oe.error = "TOO_MANY_WARNINGS";
+ oe.error_descr = "Too many warnings! Ignoring warnings for up to 1 second.";
+ oe.warning = true;
+ uint64_t time = OS::get_singleton()->get_ticks_msec();
+ oe.hr = time / 3600000;
+ oe.min = (time / 60000) % 60;
+ oe.sec = (time / 1000) % 60;
+ oe.msec = time % 1000;
+ errors.push_back(oe);
+ }
+
+ while (errors.size()) {
+ locking = true;
+ packet_peer_stream->put_var("error");
+ OutputError oe = errors.front()->get();
+
+ packet_peer_stream->put_var(oe.callstack.size() + 2);
+
+ Array error_data;
+
+ error_data.push_back(oe.hr);
+ error_data.push_back(oe.min);
+ error_data.push_back(oe.sec);
+ error_data.push_back(oe.msec);
+ error_data.push_back(oe.source_func);
+ error_data.push_back(oe.source_file);
+ error_data.push_back(oe.source_line);
+ error_data.push_back(oe.error);
+ error_data.push_back(oe.error_descr);
+ error_data.push_back(oe.warning);
+ packet_peer_stream->put_var(error_data);
+ packet_peer_stream->put_var(oe.callstack.size());
+ for (int i = 0; i < oe.callstack.size(); i++) {
+ packet_peer_stream->put_var(oe.callstack[i]);
+ }
+
+ errors.pop_front();
+ locking = false;
+ }
+ mutex->unlock();
+}
+
+void ScriptDebuggerRemote::line_poll() {
+
+ //the purpose of this is just processing events every now and then when the script might get too busy
+ //otherwise bugs like infinite loops can't be caught
+ if (poll_every % 2048 == 0)
+ _poll_events();
+ poll_every++;
+}
+
+void ScriptDebuggerRemote::_err_handler(void *ud, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, ErrorHandlerType p_type) {
+
+ if (p_type == ERR_HANDLER_SCRIPT)
+ return; //ignore script errors, those go through debugger
+
+ Vector<ScriptLanguage::StackInfo> si;
+
+ for (int i = 0; i < ScriptServer::get_language_count(); i++) {
+ si = ScriptServer::get_language(i)->debug_get_current_stack_info();
+ if (si.size())
+ break;
+ }
+
+ ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)ud;
+ sdr->send_error(p_func, p_file, p_line, p_err, p_descr, p_type, si);
+}
+
+bool ScriptDebuggerRemote::_parse_live_edit(const Array &p_command) {
+
+#ifdef DEBUG_ENABLED
+
+ String cmdstr = p_command[0];
+ if (!scene_tree || !cmdstr.begins_with("live_"))
+ return false;
+
+ if (cmdstr == "live_set_root") {
+
+ scene_tree->_live_edit_root_func(p_command[1], p_command[2]);
+
+ } else if (cmdstr == "live_node_path") {
+
+ scene_tree->_live_edit_node_path_func(p_command[1], p_command[2]);
+
+ } else if (cmdstr == "live_res_path") {
+
+ scene_tree->_live_edit_res_path_func(p_command[1], p_command[2]);
+
+ } else if (cmdstr == "live_node_prop_res") {
+
+ scene_tree->_live_edit_node_set_res_func(p_command[1], p_command[2], p_command[3]);
+
+ } else if (cmdstr == "live_node_prop") {
+
+ scene_tree->_live_edit_node_set_func(p_command[1], p_command[2], p_command[3]);
+
+ } else if (cmdstr == "live_res_prop_res") {
+
+ scene_tree->_live_edit_res_set_res_func(p_command[1], p_command[2], p_command[3]);
+
+ } else if (cmdstr == "live_res_prop") {
+
+ scene_tree->_live_edit_res_set_func(p_command[1], p_command[2], p_command[3]);
+
+ } else if (cmdstr == "live_node_call") {
+
+ scene_tree->_live_edit_node_call_func(p_command[1], p_command[2], p_command[3], p_command[4], p_command[5], p_command[6], p_command[7]);
+
+ } else if (cmdstr == "live_res_call") {
+
+ scene_tree->_live_edit_res_call_func(p_command[1], p_command[2], p_command[3], p_command[4], p_command[5], p_command[6], p_command[7]);
+
+ } else if (cmdstr == "live_create_node") {
+
+ scene_tree->_live_edit_create_node_func(p_command[1], p_command[2], p_command[3]);
+
+ } else if (cmdstr == "live_instance_node") {
+
+ scene_tree->_live_edit_instance_node_func(p_command[1], p_command[2], p_command[3]);
+
+ } else if (cmdstr == "live_remove_node") {
+
+ scene_tree->_live_edit_remove_node_func(p_command[1]);
+
+ } else if (cmdstr == "live_remove_and_keep_node") {
+
+ scene_tree->_live_edit_remove_and_keep_node_func(p_command[1], p_command[2]);
+
+ } else if (cmdstr == "live_restore_node") {
+
+ scene_tree->_live_edit_restore_node_func(p_command[1], p_command[2], p_command[3]);
+
+ } else if (cmdstr == "live_duplicate_node") {
+
+ scene_tree->_live_edit_duplicate_node_func(p_command[1], p_command[2]);
+
+ } else if (cmdstr == "live_reparent_node") {
+
+ scene_tree->_live_edit_reparent_node_func(p_command[1], p_command[2], p_command[3], p_command[4]);
+
+ } else {
+
+ return false;
+ }
+
+ return true;
+#else
+
+ return false;
+#endif
+}
+
+void ScriptDebuggerRemote::_send_object_id(ObjectID p_id) {
+
+ Object *obj = ObjectDB::get_instance(p_id);
+ if (!obj)
+ return;
+
+ typedef Pair<PropertyInfo, Variant> PropertyDesc;
+ List<PropertyDesc> properties;
+
+ if (ScriptInstance *si = obj->get_script_instance()) {
+ if (!si->get_script().is_null()) {
+
+ typedef Map<const Script *, Set<StringName> > ScriptMemberMap;
+ typedef Map<const Script *, Map<StringName, Variant> > ScriptConstantsMap;
+
+ ScriptMemberMap members;
+ members[si->get_script().ptr()] = Set<StringName>();
+ si->get_script()->get_members(&(members[si->get_script().ptr()]));
+
+ ScriptConstantsMap constants;
+ constants[si->get_script().ptr()] = Map<StringName, Variant>();
+ si->get_script()->get_constants(&(constants[si->get_script().ptr()]));
+
+ Ref<Script> base = si->get_script()->get_base_script();
+ while (base.is_valid()) {
+
+ members[base.ptr()] = Set<StringName>();
+ base->get_members(&(members[base.ptr()]));
+
+ constants[base.ptr()] = Map<StringName, Variant>();
+ base->get_constants(&(constants[base.ptr()]));
+
+ base = base->get_base_script();
+ }
+
+ for (ScriptMemberMap::Element *sm = members.front(); sm; sm = sm->next()) {
+ for (Set<StringName>::Element *E = sm->get().front(); E; E = E->next()) {
+ Variant m;
+ if (si->get(E->get(), m)) {
+ String script_path = sm->key() == si->get_script().ptr() ? "" : sm->key()->get_path().get_file() + "/";
+ PropertyInfo pi(m.get_type(), "Members/" + script_path + E->get());
+ properties.push_back(PropertyDesc(pi, m));
+ }
+ }
+ }
+
+ for (ScriptConstantsMap::Element *sc = constants.front(); sc; sc = sc->next()) {
+ for (Map<StringName, Variant>::Element *E = sc->get().front(); E; E = E->next()) {
+ String script_path = sc->key() == si->get_script().ptr() ? "" : sc->key()->get_path().get_file() + "/";
+ if (E->value().get_type() == Variant::OBJECT) {
+ Variant id = ((Object *)E->value())->get_instance_id();
+ PropertyInfo pi(id.get_type(), "Constants/" + E->key(), PROPERTY_HINT_OBJECT_ID, "Object");
+ properties.push_back(PropertyDesc(pi, id));
+ } else {
+ PropertyInfo pi(E->value().get_type(), "Constants/" + script_path + E->key());
+ properties.push_back(PropertyDesc(pi, E->value()));
+ }
+ }
+ }
+ }
+ }
+
+ if (Node *node = Object::cast_to<Node>(obj)) {
+ // in some cases node will not be in tree here
+ // for instance where it created as variable and not yet added to tree
+ // in such cases we can't ask for it's path
+ if (node->is_inside_tree()) {
+ PropertyInfo pi(Variant::NODE_PATH, String("Node/path"));
+ properties.push_front(PropertyDesc(pi, node->get_path()));
+ } else {
+ PropertyInfo pi(Variant::STRING, String("Node/path"));
+ properties.push_front(PropertyDesc(pi, "[Orphan]"));
+ }
+
+ } else if (Resource *res = Object::cast_to<Resource>(obj)) {
+ if (Script *s = Object::cast_to<Script>(res)) {
+ Map<StringName, Variant> constants;
+ s->get_constants(&constants);
+ for (Map<StringName, Variant>::Element *E = constants.front(); E; E = E->next()) {
+ if (E->value().get_type() == Variant::OBJECT) {
+ Variant id = ((Object *)E->value())->get_instance_id();
+ PropertyInfo pi(id.get_type(), "Constants/" + E->key(), PROPERTY_HINT_OBJECT_ID, "Object");
+ properties.push_front(PropertyDesc(pi, E->value()));
+ } else {
+ PropertyInfo pi(E->value().get_type(), String("Constants/") + E->key());
+ properties.push_front(PropertyDesc(pi, E->value()));
+ }
+ }
+ }
+ }
+
+ List<PropertyInfo> pinfo;
+ obj->get_property_list(&pinfo, true);
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ if (E->get().usage & (PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CATEGORY)) {
+ properties.push_back(PropertyDesc(E->get(), obj->get(E->get().name)));
+ }
+ }
+
+ Array send_props;
+ for (int i = 0; i < properties.size(); i++) {
+ const PropertyInfo &pi = properties[i].first;
+ Variant &var = properties[i].second;
+
+ WeakRef *ref = Object::cast_to<WeakRef>(var);
+ if (ref) {
+ var = ref->get_ref();
+ }
+
+ RES res = var;
+
+ Array prop;
+ prop.push_back(pi.name);
+ prop.push_back(pi.type);
+
+ //only send information that can be sent..
+ int len = 0; //test how big is this to encode
+ encode_variant(var, NULL, len);
+ if (len > packet_peer_stream->get_output_buffer_max_size()) { //limit to max size
+ prop.push_back(PROPERTY_HINT_OBJECT_TOO_BIG);
+ prop.push_back("");
+ prop.push_back(pi.usage);
+ prop.push_back(Variant());
+ } else {
+ prop.push_back(pi.hint);
+ prop.push_back(pi.hint_string);
+ prop.push_back(pi.usage);
+
+ if (!res.is_null()) {
+ var = res->get_path();
+ }
+
+ prop.push_back(var);
+ }
+ send_props.push_back(prop);
+ }
+
+ packet_peer_stream->put_var("message:inspect_object");
+ packet_peer_stream->put_var(3);
+ packet_peer_stream->put_var(p_id);
+ packet_peer_stream->put_var(obj->get_class());
+ packet_peer_stream->put_var(send_props);
+}
+
+void ScriptDebuggerRemote::_set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value) {
+
+ Object *obj = ObjectDB::get_instance(p_id);
+ if (!obj)
+ return;
+
+ String prop_name = p_property;
+ if (p_property.begins_with("Members/")) {
+ Vector<String> ss = p_property.split("/");
+ prop_name = ss[ss.size() - 1];
+ }
+
+ obj->set(prop_name, p_value);
+}
+
+void ScriptDebuggerRemote::_poll_events() {
+
+ //this si called from ::idle_poll, happens only when running the game,
+ //does not get called while on debug break
+
+ while (packet_peer_stream->get_available_packet_count() > 0) {
+
+ _get_output();
+
+ //send over output_strings
+
+ Variant var;
+ Error err = packet_peer_stream->get_var(var);
+
+ ERR_CONTINUE(err != OK);
+ ERR_CONTINUE(var.get_type() != Variant::ARRAY);
+
+ Array cmd = var;
+
+ ERR_CONTINUE(cmd.size() == 0);
+ ERR_CONTINUE(cmd[0].get_type() != Variant::STRING);
+
+ String command = cmd[0];
+ //cmd.remove(0);
+
+ if (command == "break") {
+
+ if (get_break_language())
+ debug(get_break_language());
+ } else if (command == "request_scene_tree") {
+
+#ifdef DEBUG_ENABLED
+ if (scene_tree)
+ scene_tree->_debugger_request_tree();
+#endif
+ } else if (command == "request_video_mem") {
+
+ _send_video_memory();
+ } else if (command == "inspect_object") {
+
+ ObjectID id = cmd[1];
+ _send_object_id(id);
+ } else if (command == "set_object_property") {
+
+ _set_object_property(cmd[1], cmd[2], cmd[3]);
+
+ } else if (command == "start_profiling") {
+
+ for (int i = 0; i < ScriptServer::get_language_count(); i++) {
+ ScriptServer::get_language(i)->profiling_start();
+ }
+
+ max_frame_functions = cmd[1];
+ profiler_function_signature_map.clear();
+ profiling = true;
+ frame_time = 0;
+ idle_time = 0;
+ physics_time = 0;
+ physics_frame_time = 0;
+
+ print_line("PROFILING ALRIGHT!");
+
+ } else if (command == "stop_profiling") {
+
+ for (int i = 0; i < ScriptServer::get_language_count(); i++) {
+ ScriptServer::get_language(i)->profiling_stop();
+ }
+ profiling = false;
+ _send_profiling_data(false);
+ print_line("PROFILING END!");
+ } else if (command == "start_network_profiling") {
+
+ multiplayer->profiling_start();
+ profiling_network = true;
+ } else if (command == "stop_network_profiling") {
+
+ multiplayer->profiling_end();
+ profiling_network = false;
+ } else if (command == "override_camera_2D:set") {
+ bool enforce = cmd[1];
+
+ if (scene_tree) {
+ scene_tree->get_root()->enable_canvas_transform_override(enforce);
+ }
+ } else if (command == "override_camera_2D:transform") {
+ Transform2D transform = cmd[1];
+
+ if (scene_tree) {
+ scene_tree->get_root()->set_canvas_transform_override(transform);
+ }
+ } else if (command == "override_camera_3D:set") {
+ bool enable = cmd[1];
+
+ if (scene_tree) {
+ scene_tree->get_root()->enable_camera_override(enable);
+ }
+ } else if (command == "override_camera_3D:transform") {
+ Transform transform = cmd[1];
+ bool is_perspective = cmd[2];
+ float size_or_fov = cmd[3];
+ float near = cmd[4];
+ float far = cmd[5];
+
+ if (scene_tree) {
+ if (is_perspective) {
+ scene_tree->get_root()->set_camera_override_perspective(size_or_fov, near, far);
+ } else {
+ scene_tree->get_root()->set_camera_override_orthogonal(size_or_fov, near, far);
+ }
+ scene_tree->get_root()->set_camera_override_transform(transform);
+ }
+
+ } else if (command == "reload_scripts") {
+ reload_all_scripts = true;
+ } else if (command == "breakpoint") {
+
+ bool set = cmd[3];
+ if (set)
+ insert_breakpoint(cmd[2], cmd[1]);
+ else
+ remove_breakpoint(cmd[2], cmd[1]);
+ } else if (command == "set_skip_breakpoints") {
+ skip_breakpoints = cmd[1];
+ } else {
+ _parse_live_edit(cmd);
+ }
+ }
+}
+
+void ScriptDebuggerRemote::_send_profiling_data(bool p_for_frame) {
+
+ int ofs = 0;
+
+ for (int i = 0; i < ScriptServer::get_language_count(); i++) {
+ if (p_for_frame)
+ ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&profile_info.write[ofs], profile_info.size() - ofs);
+ else
+ ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&profile_info.write[ofs], profile_info.size() - ofs);
+ }
+
+ for (int i = 0; i < ofs; i++) {
+ profile_info_ptrs.write[i] = &profile_info.write[i];
+ }
+
+ SortArray<ScriptLanguage::ProfilingInfo *, ProfileInfoSort> sa;
+ sa.sort(profile_info_ptrs.ptrw(), ofs);
+
+ int to_send = MIN(ofs, max_frame_functions);
+
+ //check signatures first
+ uint64_t total_script_time = 0;
+
+ for (int i = 0; i < to_send; i++) {
+
+ if (!profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) {
+
+ int idx = profiler_function_signature_map.size();
+ packet_peer_stream->put_var("profile_sig");
+ packet_peer_stream->put_var(2);
+ packet_peer_stream->put_var(profile_info_ptrs[i]->signature);
+ packet_peer_stream->put_var(idx);
+
+ profiler_function_signature_map[profile_info_ptrs[i]->signature] = idx;
+ }
+
+ total_script_time += profile_info_ptrs[i]->self_time;
+ }
+
+ //send frames then
+
+ if (p_for_frame) {
+ packet_peer_stream->put_var("profile_frame");
+ packet_peer_stream->put_var(8 + profile_frame_data.size() * 2 + to_send * 4);
+ } else {
+ packet_peer_stream->put_var("profile_total");
+ packet_peer_stream->put_var(8 + to_send * 4);
+ }
+
+ packet_peer_stream->put_var(Engine::get_singleton()->get_frames_drawn()); //total frame time
+ packet_peer_stream->put_var(frame_time); //total frame time
+ packet_peer_stream->put_var(idle_time); //idle frame time
+ packet_peer_stream->put_var(physics_time); //fixed frame time
+ packet_peer_stream->put_var(physics_frame_time); //fixed frame time
+
+ packet_peer_stream->put_var(USEC_TO_SEC(total_script_time)); //total script execution time
+
+ if (p_for_frame) {
+
+ packet_peer_stream->put_var(profile_frame_data.size()); //how many profile framedatas to send
+ packet_peer_stream->put_var(to_send); //how many script functions to send
+ for (int i = 0; i < profile_frame_data.size(); i++) {
+
+ packet_peer_stream->put_var(profile_frame_data[i].name);
+ packet_peer_stream->put_var(profile_frame_data[i].data);
+ }
+ } else {
+ packet_peer_stream->put_var(0); //how many script functions to send
+ packet_peer_stream->put_var(to_send); //how many script functions to send
+ }
+
+ for (int i = 0; i < to_send; i++) {
+
+ int sig_id = -1;
+
+ if (profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) {
+ sig_id = profiler_function_signature_map[profile_info_ptrs[i]->signature];
+ }
+
+ packet_peer_stream->put_var(sig_id);
+ packet_peer_stream->put_var(profile_info_ptrs[i]->call_count);
+ packet_peer_stream->put_var(profile_info_ptrs[i]->total_time / 1000000.0);
+ packet_peer_stream->put_var(profile_info_ptrs[i]->self_time / 1000000.0);
+ }
+
+ if (p_for_frame) {
+ profile_frame_data.clear();
+ }
+}
+
+void ScriptDebuggerRemote::idle_poll() {
+
+ // this function is called every frame, except when there is a debugger break (::debug() in this class)
+ // execution stops and remains in the ::debug function
+
+ _get_output();
+
+ if (requested_quit) {
+
+ packet_peer_stream->put_var("kill_me");
+ packet_peer_stream->put_var(0);
+ requested_quit = false;
+ }
+
+ if (performance) {
+
+ uint64_t pt = OS::get_singleton()->get_ticks_msec();
+ if (pt - last_perf_time > 1000) {
+
+ last_perf_time = pt;
+ int max = performance->get("MONITOR_MAX");
+ Array arr;
+ arr.resize(max);
+ for (int i = 0; i < max; i++) {
+ arr[i] = performance->call("get_monitor", i);
+ }
+ packet_peer_stream->put_var("performance");
+ packet_peer_stream->put_var(1);
+ packet_peer_stream->put_var(arr);
+ }
+ }
+
+ if (profiling) {
+
+ if (skip_profile_frame) {
+ skip_profile_frame = false;
+ } else {
+ //send profiling info normally
+ _send_profiling_data(true);
+ }
+ }
+
+ if (profiling_network) {
+ uint64_t pt = OS::get_singleton()->get_ticks_msec();
+ if (pt - last_net_bandwidth_time > 200) {
+ last_net_bandwidth_time = pt;
+ _send_network_bandwidth_usage();
+ }
+ if (pt - last_net_prof_time > 100) {
+ last_net_prof_time = pt;
+ _send_network_profiling_data();
+ }
+ }
+
+ if (reload_all_scripts) {
+
+ for (int i = 0; i < ScriptServer::get_language_count(); i++) {
+ ScriptServer::get_language(i)->reload_all_scripts();
+ }
+ reload_all_scripts = false;
+ }
+
+ _poll_events();
+}
+
+void ScriptDebuggerRemote::_send_network_profiling_data() {
+ ERR_FAIL_COND(multiplayer.is_null());
+
+ int n_nodes = multiplayer->get_profiling_frame(&network_profile_info.write[0]);
+
+ packet_peer_stream->put_var("network_profile");
+ packet_peer_stream->put_var(n_nodes * 6);
+ for (int i = 0; i < n_nodes; ++i) {
+ packet_peer_stream->put_var(network_profile_info[i].node);
+ packet_peer_stream->put_var(network_profile_info[i].node_path);
+ packet_peer_stream->put_var(network_profile_info[i].incoming_rpc);
+ packet_peer_stream->put_var(network_profile_info[i].incoming_rset);
+ packet_peer_stream->put_var(network_profile_info[i].outgoing_rpc);
+ packet_peer_stream->put_var(network_profile_info[i].outgoing_rset);
+ }
+}
+
+void ScriptDebuggerRemote::_send_network_bandwidth_usage() {
+ ERR_FAIL_COND(multiplayer.is_null());
+
+ int incoming_bandwidth = multiplayer->get_incoming_bandwidth_usage();
+ int outgoing_bandwidth = multiplayer->get_outgoing_bandwidth_usage();
+
+ packet_peer_stream->put_var("network_bandwidth");
+ packet_peer_stream->put_var(2);
+ packet_peer_stream->put_var(incoming_bandwidth);
+ packet_peer_stream->put_var(outgoing_bandwidth);
+}
+
+void ScriptDebuggerRemote::send_message(const String &p_message, const Array &p_args) {
+
+ mutex->lock();
+ if (!locking && tcp_client->is_connected_to_host()) {
+
+ if (messages.size() >= max_messages_per_frame) {
+ n_messages_dropped++;
+ } else {
+ Message msg;
+ msg.message = p_message;
+ msg.data = p_args;
+ messages.push_back(msg);
+ }
+ }
+ mutex->unlock();
+}
+
+void ScriptDebuggerRemote::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info) {
+
+ OutputError oe;
+ oe.error = p_err;
+ oe.error_descr = p_descr;
+ oe.source_file = p_file;
+ oe.source_line = p_line;
+ oe.source_func = p_func;
+ oe.warning = p_type == ERR_HANDLER_WARNING;
+ uint64_t time = OS::get_singleton()->get_ticks_msec();
+ oe.hr = time / 3600000;
+ oe.min = (time / 60000) % 60;
+ oe.sec = (time / 1000) % 60;
+ oe.msec = time % 1000;
+ Array cstack;
+
+ uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000;
+ msec_count += ticks - last_msec;
+ last_msec = ticks;
+
+ if (msec_count > 1000) {
+ msec_count = 0;
+
+ err_count = 0;
+ n_errors_dropped = 0;
+ warn_count = 0;
+ n_warnings_dropped = 0;
+ }
+
+ cstack.resize(p_stack_info.size() * 3);
+ for (int i = 0; i < p_stack_info.size(); i++) {
+ cstack[i * 3 + 0] = p_stack_info[i].file;
+ cstack[i * 3 + 1] = p_stack_info[i].func;
+ cstack[i * 3 + 2] = p_stack_info[i].line;
+ }
+
+ oe.callstack = cstack;
+ if (oe.warning) {
+ warn_count++;
+ } else {
+ err_count++;
+ }
+
+ mutex->lock();
+
+ if (!locking && tcp_client->is_connected_to_host()) {
+
+ if (oe.warning) {
+ if (warn_count > max_warnings_per_second) {
+ n_warnings_dropped++;
+ } else {
+ errors.push_back(oe);
+ }
+ } else {
+ if (err_count > max_errors_per_second) {
+ n_errors_dropped++;
+ } else {
+ errors.push_back(oe);
+ }
+ }
+ }
+
+ mutex->unlock();
+}
+
+void ScriptDebuggerRemote::_print_handler(void *p_this, const String &p_string, bool p_error) {
+
+ ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)p_this;
+
+ uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000;
+ sdr->msec_count += ticks - sdr->last_msec;
+ sdr->last_msec = ticks;
+
+ if (sdr->msec_count > 1000) {
+ sdr->char_count = 0;
+ sdr->msec_count = 0;
+ }
+
+ String s = p_string;
+ int allowed_chars = MIN(MAX(sdr->max_cps - sdr->char_count, 0), s.length());
+
+ if (allowed_chars == 0)
+ return;
+
+ if (allowed_chars < s.length()) {
+ s = s.substr(0, allowed_chars);
+ }
+
+ sdr->char_count += allowed_chars;
+ bool overflowed = sdr->char_count >= sdr->max_cps;
+
+ sdr->mutex->lock();
+ if (!sdr->locking && sdr->tcp_client->is_connected_to_host()) {
+
+ if (overflowed)
+ s += "[...]";
+
+ sdr->output_strings.push_back(s);
+
+ if (overflowed) {
+ sdr->output_strings.push_back("[output overflow, print less text!]");
+ }
+ }
+ sdr->mutex->unlock();
+}
+
+void ScriptDebuggerRemote::request_quit() {
+
+ requested_quit = true;
+}
+
+void ScriptDebuggerRemote::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {
+ multiplayer = p_multiplayer;
+}
+
+bool ScriptDebuggerRemote::is_profiling() const {
+
+ return profiling;
+}
+void ScriptDebuggerRemote::add_profiling_frame_data(const StringName &p_name, const Array &p_data) {
+
+ int idx = -1;
+ for (int i = 0; i < profile_frame_data.size(); i++) {
+ if (profile_frame_data[i].name == p_name) {
+ idx = i;
+ break;
+ }
+ }
+
+ FrameData fd;
+ fd.name = p_name;
+ fd.data = p_data;
+
+ if (idx == -1) {
+ profile_frame_data.push_back(fd);
+ } else {
+ profile_frame_data.write[idx] = fd;
+ }
+}
+
+void ScriptDebuggerRemote::profiling_start() {
+ //ignores this, uses it via connection
+}
+
+void ScriptDebuggerRemote::profiling_end() {
+ //ignores this, uses it via connection
+}
+
+void ScriptDebuggerRemote::profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) {
+
+ frame_time = p_frame_time;
+ idle_time = p_idle_time;
+ physics_time = p_physics_time;
+ physics_frame_time = p_physics_frame_time;
+}
+
+void ScriptDebuggerRemote::set_skip_breakpoints(bool p_skip_breakpoints) {
+ skip_breakpoints = p_skip_breakpoints;
+}
+
+ScriptDebuggerRemote::ResourceUsageFunc ScriptDebuggerRemote::resource_usage_func = NULL;
+
+ScriptDebuggerRemote::ScriptDebuggerRemote() :
+ profiling(false),
+ profiling_network(false),
+ max_frame_functions(16),
+ skip_profile_frame(false),
+ reload_all_scripts(false),
+ tcp_client(Ref<StreamPeerTCP>(memnew(StreamPeerTCP))),
+ packet_peer_stream(Ref<PacketPeerStream>(memnew(PacketPeerStream))),
+ last_perf_time(0),
+ last_net_prof_time(0),
+ last_net_bandwidth_time(0),
+ performance(Engine::get_singleton()->get_singleton_object("Performance")),
+ requested_quit(false),
+ mutex(Mutex::create()),
+ max_messages_per_frame(GLOBAL_GET("network/limits/debugger_stdout/max_messages_per_frame")),
+ n_messages_dropped(0),
+ max_errors_per_second(GLOBAL_GET("network/limits/debugger_stdout/max_errors_per_second")),
+ max_warnings_per_second(GLOBAL_GET("network/limits/debugger_stdout/max_warnings_per_second")),
+ n_errors_dropped(0),
+ max_cps(GLOBAL_GET("network/limits/debugger_stdout/max_chars_per_second")),
+ char_count(0),
+ err_count(0),
+ warn_count(0),
+ last_msec(0),
+ msec_count(0),
+ locking(false),
+ poll_every(0),
+ scene_tree(NULL) {
+
+ packet_peer_stream->set_stream_peer(tcp_client);
+ packet_peer_stream->set_output_buffer_max_size(1024 * 1024 * 8); //8mb should be way more than enough
+
+ phl.printfunc = _print_handler;
+ phl.userdata = this;
+ add_print_handler(&phl);
+
+ eh.errfunc = _err_handler;
+ eh.userdata = this;
+ add_error_handler(&eh);
+
+ profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions"));
+ network_profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions"));
+ profile_info_ptrs.resize(profile_info.size());
+}
+
+ScriptDebuggerRemote::~ScriptDebuggerRemote() {
+
+ remove_print_handler(&phl);
+ remove_error_handler(&eh);
+ memdelete(mutex);
+}
diff --git a/scene/debugger/script_debugger_remote.h b/scene/debugger/script_debugger_remote.h
new file mode 100644
index 0000000000..13ad7ddbe3
--- /dev/null
+++ b/scene/debugger/script_debugger_remote.h
@@ -0,0 +1,196 @@
+/*************************************************************************/
+/* script_debugger_remote.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 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 SCRIPT_DEBUGGER_REMOTE_H
+#define SCRIPT_DEBUGGER_REMOTE_H
+
+#include "core/io/packet_peer.h"
+#include "core/io/stream_peer_tcp.h"
+#include "core/list.h"
+#include "core/os/os.h"
+#include "core/script_language.h"
+
+class SceneTree;
+
+class ScriptDebuggerRemote : public ScriptDebugger {
+
+ struct Message {
+
+ String message;
+ Array data;
+ };
+
+ struct ProfileInfoSort {
+
+ bool operator()(ScriptLanguage::ProfilingInfo *A, ScriptLanguage::ProfilingInfo *B) const {
+ return A->total_time < B->total_time;
+ }
+ };
+
+ Vector<ScriptLanguage::ProfilingInfo> profile_info;
+ Vector<ScriptLanguage::ProfilingInfo *> profile_info_ptrs;
+ Vector<MultiplayerAPI::ProfilingInfo> network_profile_info;
+
+ Map<StringName, int> profiler_function_signature_map;
+ float frame_time, idle_time, physics_time, physics_frame_time;
+
+ bool profiling;
+ bool profiling_network;
+ int max_frame_functions;
+ bool skip_profile_frame;
+ bool reload_all_scripts;
+
+ Ref<StreamPeerTCP> tcp_client;
+ Ref<PacketPeerStream> packet_peer_stream;
+
+ uint64_t last_perf_time;
+ uint64_t last_net_prof_time;
+ uint64_t last_net_bandwidth_time;
+ Object *performance;
+ bool requested_quit;
+ Mutex *mutex;
+
+ struct OutputError {
+
+ int hr;
+ int min;
+ int sec;
+ int msec;
+ String source_file;
+ String source_func;
+ int source_line;
+ String error;
+ String error_descr;
+ bool warning;
+ Array callstack;
+ };
+
+ List<String> output_strings;
+ List<Message> messages;
+ int max_messages_per_frame;
+ int n_messages_dropped;
+ List<OutputError> errors;
+ int max_errors_per_second;
+ int max_warnings_per_second;
+ int n_errors_dropped;
+ int n_warnings_dropped;
+
+ int max_cps;
+ int char_count;
+ int err_count;
+ int warn_count;
+ uint64_t last_msec;
+ uint64_t msec_count;
+
+ bool locking; //hack to avoid a deadloop
+ static void _print_handler(void *p_this, const String &p_string, bool p_error);
+
+ PrintHandlerList phl;
+
+ void _get_output();
+ void _poll_events();
+ uint32_t poll_every;
+
+ SceneTree *scene_tree;
+
+ bool _parse_live_edit(const Array &p_command);
+
+ void _set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value);
+
+ void _send_object_id(ObjectID p_id);
+ void _send_video_memory();
+
+ Ref<MultiplayerAPI> multiplayer;
+
+ ErrorHandlerList eh;
+ static void _err_handler(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type);
+
+ void _send_profiling_data(bool p_for_frame);
+ void _send_network_profiling_data();
+ void _send_network_bandwidth_usage();
+
+ struct FrameData {
+
+ StringName name;
+ Array data;
+ };
+
+ Vector<FrameData> profile_frame_data;
+
+ void _put_variable(const String &p_name, const Variant &p_variable);
+
+ void _save_node(ObjectID id, const String &p_path);
+
+ bool skip_breakpoints;
+
+public:
+ struct ResourceUsage {
+
+ String path;
+ String format;
+ String type;
+ RID id;
+ int vram;
+ bool operator<(const ResourceUsage &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; }
+ };
+
+ typedef void (*ResourceUsageFunc)(List<ResourceUsage> *);
+
+ static ResourceUsageFunc resource_usage_func;
+
+ Error connect_to_host(const String &p_host, uint16_t p_port);
+ virtual void debug(ScriptLanguage *p_script, bool p_can_continue = true, bool p_is_error_breakpoint = false);
+ virtual void idle_poll();
+ virtual void line_poll();
+
+ virtual bool is_remote() const { return true; }
+ virtual void request_quit();
+
+ virtual void send_message(const String &p_message, const Array &p_args);
+ virtual void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info);
+
+ virtual void set_multiplayer(Ref<MultiplayerAPI> p_multiplayer);
+
+ virtual bool is_profiling() const;
+ virtual void add_profiling_frame_data(const StringName &p_name, const Array &p_data);
+
+ virtual void profiling_start();
+ virtual void profiling_end();
+ virtual void profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time);
+
+ virtual void set_skip_breakpoints(bool p_skip_breakpoints);
+
+ void set_scene_tree(SceneTree *p_scene_tree) { scene_tree = p_scene_tree; };
+
+ ScriptDebuggerRemote();
+ ~ScriptDebuggerRemote();
+};
+
+#endif // SCRIPT_DEBUGGER_REMOTE_H
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index 6b3e89af6c..ca4c255855 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -174,17 +174,17 @@ void Button::_notification(int p_what) {
_size.width -= get_constant("hseparation") + icon_ofs_region;
if (!clip_text)
_size.width -= get_font("font")->get_string_size(xl_text).width;
- float icon_width = icon->get_width() * _size.height / icon->get_height();
+ float icon_width = _icon->get_width() * _size.height / _icon->get_height();
float icon_height = _size.height;
if (icon_width > _size.width) {
icon_width = _size.width;
- icon_height = icon->get_height() * icon_width / icon->get_width();
+ icon_height = _icon->get_height() * icon_width / _icon->get_width();
}
icon_region = Rect2(style->get_offset() + Point2(icon_ofs_region, (_size.height - icon_height) / 2), Size2(icon_width, icon_height));
} else {
- icon_region = Rect2(style->get_offset() + Point2(icon_ofs_region, Math::floor((valign - _icon->get_height()) / 2.0)), icon->get_size());
+ icon_region = Rect2(style->get_offset() + Point2(icon_ofs_region, Math::floor((valign - _icon->get_height()) / 2.0)), _icon->get_size());
}
}
@@ -221,7 +221,7 @@ void Button::_notification(int p_what) {
font->draw(ci, text_ofs.floor(), xl_text, color, clip_text ? text_clip : -1);
if (!_icon.is_null() && icon_region.size.width > 0) {
- draw_texture_rect_region(_icon, icon_region, Rect2(Point2(), icon->get_size()), color_icon);
+ draw_texture_rect_region(_icon, icon_region, Rect2(Point2(), _icon->get_size()), color_icon);
}
} break;
}
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index 31551d6257..b6e647d1af 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -161,7 +161,7 @@ void WindowDialog::_gui_input(const Ref<InputEvent> &p_event) {
global_pos.y = MAX(global_pos.y, 0); // Ensure title bar stays visible.
Rect2 rect = get_rect();
- Size2 min_size = get_minimum_size();
+ Size2 min_size = get_combined_minimum_size();
if (drag_type == DRAG_MOVE) {
rect.position = global_pos - drag_offset;
@@ -239,12 +239,14 @@ void WindowDialog::_notification(int p_what) {
#ifdef TOOLS_ENABLED
case NOTIFICATION_POST_POPUP: {
- if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton())
+ 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);
+ }
} break;
case NOTIFICATION_POPUP_HIDE: {
- if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton() && !get_viewport()->gui_has_modal_stack())
+ if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton() && !was_editor_dimmed)
EditorNode::get_singleton()->dim_editor(false);
} break;
#endif
@@ -345,6 +347,10 @@ WindowDialog::WindowDialog() {
close_button = memnew(TextureButton);
add_child(close_button);
close_button->connect("pressed", this, "_closed");
+
+#ifdef TOOLS_ENABLED
+ was_editor_dimmed = false;
+#endif
}
WindowDialog::~WindowDialog() {
@@ -356,7 +362,7 @@ void PopupDialog::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
RID ci = get_canvas_item();
- get_stylebox("panel", "PopupMenu")->draw(ci, Rect2(Point2(), get_size()));
+ get_stylebox("panel")->draw(ci, Rect2(Point2(), get_size()));
}
}
diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h
index afd1173f28..2eb0978e9b 100644
--- a/scene/gui/dialogs.h
+++ b/scene/gui/dialogs.h
@@ -59,6 +59,10 @@ class WindowDialog : public Popup {
Point2 drag_offset_far;
bool resizable;
+#ifdef TOOLS_ENABLED
+ bool was_editor_dimmed;
+#endif
+
void _gui_input(const Ref<InputEvent> &p_event);
void _closed();
int _drag_hit_test(const Point2 &pos) const;
@@ -106,7 +110,6 @@ class AcceptDialog : public WindowDialog {
HBoxContainer *hbc;
Label *label;
Button *ok;
- //Button *cancel; no more cancel (there is X on that titlebar)
bool hide_on_ok;
void _custom_action(const String &p_action);
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 5cb4bcc64f..dd9e11508f 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -178,8 +178,12 @@ 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 == MODE_OPEN_DIR) {
deselect_items();
+ file_box->set_visible(false);
+ } else {
+ file_box->set_visible(true);
+ }
}
void FileDialog::_action_pressed() {
@@ -413,6 +417,10 @@ void FileDialog::update_file_name() {
void FileDialog::update_file_list() {
tree->clear();
+
+ // Scroll back to the top after opening a directory
+ tree->get_vscroll_bar()->set_value(0);
+
dir_access->list_dir_begin();
TreeItem *root = tree->create_item();
@@ -550,25 +558,25 @@ void FileDialog::update_filters() {
const int max_filters = 5;
for (int i = 0; i < MIN(max_filters, filters.size()); i++) {
- String flt = filters[i].get_slice(";", 0);
+ String flt = filters[i].get_slice(";", 0).strip_edges();
if (i > 0)
- all_filters += ",";
+ all_filters += ", ";
all_filters += flt;
}
if (max_filters < filters.size())
all_filters += ", ...";
- filter->add_item(RTR("All Recognized") + " ( " + all_filters + " )");
+ filter->add_item(RTR("All Recognized") + " (" + all_filters + ")");
}
for (int i = 0; i < filters.size(); i++) {
String flt = filters[i].get_slice(";", 0).strip_edges();
String desc = filters[i].get_slice(";", 1).strip_edges();
if (desc.length())
- filter->add_item(String(tr(desc)) + " ( " + flt + " )");
+ filter->add_item(String(tr(desc)) + " (" + flt + ")");
else
- filter->add_item("( " + flt + " )");
+ filter->add_item("(" + flt + ")");
}
filter->add_item(RTR("All Files (*)"));
@@ -894,6 +902,10 @@ FileDialog::FileDialog() {
hbc->add_child(dir_up);
dir_up->connect("pressed", this, "_go_up");
+ drives = memnew(OptionButton);
+ hbc->add_child(drives);
+ drives->connect("item_selected", this, "_select_drive");
+
hbc->add_child(memnew(Label(RTR("Path:"))));
dir = memnew(LineEdit);
hbc->add_child(dir);
@@ -911,10 +923,6 @@ FileDialog::FileDialog() {
show_hidden->connect("toggled", this, "set_show_hidden_files");
hbc->add_child(show_hidden);
- drives = memnew(OptionButton);
- hbc->add_child(drives);
- drives->connect("item_selected", this, "_select_drive");
-
makedir = memnew(Button);
makedir->set_text(RTR("Create Folder"));
makedir->connect("pressed", this, "_make_dir");
@@ -925,18 +933,18 @@ FileDialog::FileDialog() {
tree->set_hide_root(true);
vbc->add_margin_child(RTR("Directories & Files:"), tree, true);
- hbc = memnew(HBoxContainer);
- hbc->add_child(memnew(Label(RTR("File:"))));
+ 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);
- hbc->add_child(file);
+ file_box->add_child(file);
filter = memnew(OptionButton);
filter->set_stretch_ratio(3);
filter->set_h_size_flags(SIZE_EXPAND_FILL);
filter->set_clip_text(true); // too many extensions overflows it
- hbc->add_child(filter);
- vbc->add_child(hbc);
+ file_box->add_child(filter);
+ vbc->add_child(file_box);
dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
access = ACCESS_RESOURCES;
diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h
index 4fd6d0d13c..687ebc8036 100644
--- a/scene/gui/file_dialog.h
+++ b/scene/gui/file_dialog.h
@@ -78,10 +78,11 @@ private:
LineEdit *dir;
OptionButton *drives;
Tree *tree;
+ HBoxContainer *file_box;
LineEdit *file;
+ OptionButton *filter;
AcceptDialog *mkdirerr;
AcceptDialog *exterr;
- OptionButton *filter;
DirAccess *dir_access;
ConfirmationDialog *confirm_save;
diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp
index 09ef6f26bf..5958106419 100644
--- a/scene/gui/gradient_edit.cpp
+++ b/scene/gui/gradient_edit.cpp
@@ -277,12 +277,13 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
if (points[i].offset == newofs && i != grabbed) {
valid = false;
+ break;
}
}
- if (!valid)
+ if (!valid || grabbed == -1) {
return;
-
+ }
points.write[grabbed].offset = newofs;
points.sort();
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 7827c66841..ed9fc0ce51 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -819,8 +819,11 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
if (gn && gn->is_selected()) {
Vector2 pos = (gn->get_drag_from() * zoom + drag_accum) / zoom;
- if (is_using_snap()) {
- int snap = get_snap();
+
+ // 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)) {
+ const int snap = get_snap();
pos = pos.snapped(Vector2(snap, snap));
}
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 1a0539effa..20bbcbde80 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -411,6 +411,7 @@ void ItemList::set_max_columns(int p_amount) {
ERR_FAIL_COND(p_amount < 0);
max_columns = p_amount;
update();
+ shape_changed = true;
}
int ItemList::get_max_columns() const {
@@ -968,7 +969,7 @@ void ItemList::_notification(int p_what) {
}
if (all_fit) {
- float page = size.height - bg->get_minimum_size().height;
+ float page = MAX(0, size.height - bg->get_minimum_size().height);
float max = MAX(page, ofs.y + max_h);
if (auto_height)
auto_height_value = ofs.y + max_h + bg->get_minimum_size().height;
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index 4edd4b8530..9e2cd9e941 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -296,8 +296,9 @@ Size2 Label::get_minimum_size() const {
Size2 min_style = get_stylebox("normal")->get_minimum_size();
// don't want to mutable everything
- if (word_cache_dirty)
+ if (word_cache_dirty) {
const_cast<Label *>(this)->regenerate_word_cache();
+ }
if (autowrap)
return Size2(1, clip ? 1 : minsize.height) + min_style;
@@ -377,8 +378,14 @@ void Label::regenerate_word_cache() {
memdelete(current);
}
- Ref<StyleBox> style = get_stylebox("normal");
- int width = autowrap ? (get_size().width - style->get_minimum_size().width) : get_longest_line_width();
+ int width;
+ if (autowrap) {
+ Ref<StyleBox> style = get_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");
int current_word_size = 0;
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index ab6f80bfa9..d96ca69c87 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -704,7 +704,7 @@ void LineEdit::_notification(int p_what) {
}
int x_ofs = 0;
- bool using_placeholder = text.empty();
+ bool using_placeholder = text.empty() && ime_text.empty();
int cached_text_width = using_placeholder ? cached_placeholder_width : cached_width;
switch (align) {
@@ -823,7 +823,7 @@ void LineEdit::_notification(int p_what) {
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);
- if (char_ofs == cursor_pos && draw_caret) {
+ 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);
@@ -866,12 +866,27 @@ void LineEdit::_notification(int p_what) {
}
}
- if (char_ofs == cursor_pos && draw_caret) { // May be at the end.
+ if ((char_ofs == cursor_pos || using_placeholder) && draw_caret) { // May be at the end, or placeholder.
if (ime_text.length() == 0) {
+ int caret_x_ofs = x_ofs;
+ if (using_placeholder) {
+ switch (align) {
+ case ALIGN_LEFT:
+ case ALIGN_FILL: {
+ caret_x_ofs = style->get_offset().x;
+ } break;
+ case ALIGN_CENTER: {
+ caret_x_ofs = ofs_max / 2;
+ } break;
+ case ALIGN_RIGHT: {
+ caret_x_ofs = ofs_max;
+ } break;
+ }
+ }
#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);
+ VisualServer::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(x_ofs, y_ofs), Size2(1, caret_height)), cursor_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(caret_x_ofs, y_ofs), Size2(1, caret_height)), cursor_color);
#endif
}
}
@@ -970,6 +985,8 @@ void LineEdit::undo() {
undo_stack_pos = undo_stack_pos->prev();
TextOperation op = undo_stack_pos->get();
text = op.text;
+ cached_width = op.cached_width;
+ window_pos = op.window_pos;
set_cursor_position(op.cursor_pos);
if (expand_to_text_length)
@@ -988,6 +1005,8 @@ void LineEdit::redo() {
undo_stack_pos = undo_stack_pos->next();
TextOperation op = undo_stack_pos->get();
text = op.text;
+ cached_width = op.cached_width;
+ window_pos = op.window_pos;
set_cursor_position(op.cursor_pos);
if (expand_to_text_length)
@@ -1169,6 +1188,10 @@ void LineEdit::delete_char() {
set_cursor_position(get_cursor_position() - 1);
+ if (align == ALIGN_CENTER || align == ALIGN_RIGHT) {
+ window_pos = CLAMP(window_pos - 1, 0, text.length() - 1);
+ }
+
_text_changed();
}
@@ -1196,6 +1219,10 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) {
window_pos = cursor_pos;
}
+ if (align == ALIGN_CENTER || align == ALIGN_RIGHT) {
+ window_pos = CLAMP(window_pos - (p_to_column - p_from_column), 0, text.length() - 1);
+ }
+
if (!text_changed_dirty) {
if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_text_changed");
@@ -1677,7 +1704,9 @@ void LineEdit::_clear_undo_stack() {
void LineEdit::_create_undo_state() {
TextOperation op;
op.text = text;
+ op.cached_width = cached_width;
op.cursor_pos = cursor_pos;
+ op.window_pos = window_pos;
undo_stack.push_back(op);
}
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index 3424131dad..ebe49091eb 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -106,6 +106,8 @@ private:
struct TextOperation {
int cursor_pos;
+ int window_pos;
+ int cached_width;
String text;
};
List<TextOperation> undo_stack;
diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp
index ed5dd77f53..5682232bc4 100644
--- a/scene/gui/range.cpp
+++ b/scene/gui/range.cpp
@@ -100,7 +100,6 @@ void Range::set_value(double p_val) {
shared->emit_value_changed();
}
void Range::set_min(double p_min) {
-
shared->min = p_min;
set_value(shared->val);
@@ -109,7 +108,6 @@ void Range::set_min(double p_min) {
update_configuration_warning();
}
void Range::set_max(double p_max) {
-
shared->max = p_max;
set_value(shared->val);
@@ -173,6 +171,8 @@ void Range::set_as_ratio(double p_value) {
}
double Range::get_as_ratio() const {
+ ERR_FAIL_COND_V_MSG(Math::is_equal_approx(get_max(), get_min()), 0.0, "Cannot get ratio when minimum and maximum value are equal.");
+
if (shared->exp_ratio && get_min() >= 0) {
double exp_min = get_min() == 0 ? 0.0 : Math::log(get_min()) / Math::log((double)2);
@@ -213,6 +213,7 @@ void Range::unshare() {
nshared->val = shared->val;
nshared->step = shared->step;
nshared->page = shared->page;
+ nshared->exp_ratio = shared->exp_ratio;
nshared->allow_greater = shared->allow_greater;
nshared->allow_lesser = shared->allow_lesser;
_unref_shared();
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 8c19255fd0..0331046492 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -1721,6 +1721,41 @@ void RichTextLabel::push_font(const Ref<Font> &p_font) {
_add_item(item, true);
}
+void RichTextLabel::push_normal() {
+ Ref<Font> normal_font = get_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");
+ 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");
+ 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");
+ ERR_FAIL_COND(italics_font.is_null());
+
+ push_font(italics_font);
+}
+
+void RichTextLabel::push_mono() {
+ Ref<Font> mono_font = get_font("mono_font");
+ ERR_FAIL_COND(mono_font.is_null());
+
+ push_font(mono_font);
+}
+
void RichTextLabel::push_color(const Color &p_color) {
ERR_FAIL_COND(current->type == ITEM_TABLE);
@@ -2636,6 +2671,11 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("newline"), &RichTextLabel::add_newline);
ClassDB::bind_method(D_METHOD("remove_line", "line"), &RichTextLabel::remove_line);
ClassDB::bind_method(D_METHOD("push_font", "font"), &RichTextLabel::push_font);
+ ClassDB::bind_method(D_METHOD("push_normal"), &RichTextLabel::push_normal);
+ ClassDB::bind_method(D_METHOD("push_bold"), &RichTextLabel::push_bold);
+ ClassDB::bind_method(D_METHOD("push_bold_italics"), &RichTextLabel::push_bold_italics);
+ ClassDB::bind_method(D_METHOD("push_italics"), &RichTextLabel::push_italics);
+ ClassDB::bind_method(D_METHOD("push_mono"), &RichTextLabel::push_mono);
ClassDB::bind_method(D_METHOD("push_color", "color"), &RichTextLabel::push_color);
ClassDB::bind_method(D_METHOD("push_align", "align"), &RichTextLabel::push_align);
ClassDB::bind_method(D_METHOD("push_indent", "level"), &RichTextLabel::push_indent);
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index 6cd69b9187..b9837fdfcc 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -411,6 +411,11 @@ public:
void add_newline();
bool remove_line(const int p_line);
void push_font(const Ref<Font> &p_font);
+ void push_normal();
+ void push_bold();
+ void push_bold_italics();
+ void push_italics();
+ void push_mono();
void push_color(const Color &p_color);
void push_underline();
void push_strikethrough();
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index a840e3fec1..fa23bf91dd 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -388,7 +388,6 @@ void ScrollContainer::update_scrollbars() {
if (hide_scroll_v) {
v_scroll->hide();
- v_scroll->set_max(0);
scroll.y = 0;
} else {
@@ -406,7 +405,6 @@ void ScrollContainer::update_scrollbars() {
if (hide_scroll_h) {
h_scroll->hide();
- h_scroll->set_max(0);
scroll.x = 0;
} else {
diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp
index 9f853cf0c8..ba57be1686 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -101,26 +101,26 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
if (!mm.is_valid() && !mb.is_valid()) {
- if (p_event->is_action("ui_left") && p_event->is_pressed()) {
+ if (p_event->is_action_pressed("ui_left", true)) {
if (orientation != HORIZONTAL)
return;
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
accept_event();
- } else if (p_event->is_action("ui_right") && p_event->is_pressed()) {
+ } else if (p_event->is_action_pressed("ui_right", true)) {
if (orientation != HORIZONTAL)
return;
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
accept_event();
- } else if (p_event->is_action("ui_up") && p_event->is_pressed()) {
+ } else if (p_event->is_action_pressed("ui_up", true)) {
if (orientation != VERTICAL)
return;
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
accept_event();
- } else if (p_event->is_action("ui_down") && p_event->is_pressed()) {
+ } else if (p_event->is_action_pressed("ui_down", true)) {
if (orientation != VERTICAL)
return;
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index bf067898e6..de25d6a63d 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -211,6 +211,10 @@ void SpinBox::_notification(int p_what) {
_adjust_width_for_icon(get_icon("updown"));
_value_changed(0);
+ } else if (p_what == NOTIFICATION_THEME_CHANGED) {
+
+ call_deferred("minimum_size_changed");
+ get_line_edit()->call_deferred("minimum_size_changed");
}
}
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 5e548b7715..bf3ec9b05b 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -161,57 +161,58 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
/* BEGIN */
int lr = cr.begin_key.length();
- if (lr == 0 || lr > left)
- continue;
+ const CharType *kc;
+ bool match;
- const CharType *kc = cr.begin_key.c_str();
+ if (lr != 0 && lr <= left) {
+ kc = cr.begin_key.c_str();
- bool match = true;
+ match = true;
- for (int k = 0; k < lr; k++) {
- if (kc[k] != str[i + k]) {
- match = false;
- break;
+ for (int k = 0; k < lr; k++) {
+ if (kc[k] != str[i + k]) {
+ match = false;
+ break;
+ }
}
- }
- if (match) {
+ if (match) {
- ColorRegionInfo cri;
- cri.end = false;
- cri.region = j;
- text.write[p_line].region_info[i] = cri;
- i += lr - 1;
+ ColorRegionInfo cri;
+ cri.end = false;
+ cri.region = j;
+ text.write[p_line].region_info[i] = cri;
+ i += lr - 1;
- break;
+ break;
+ }
}
/* END */
lr = cr.end_key.length();
- if (lr == 0 || lr > left)
- continue;
+ if (lr != 0 && lr <= left) {
+ kc = cr.end_key.c_str();
- kc = cr.end_key.c_str();
+ match = true;
- match = true;
-
- for (int k = 0; k < lr; k++) {
- if (kc[k] != str[i + k]) {
- match = false;
- break;
+ for (int k = 0; k < lr; k++) {
+ if (kc[k] != str[i + k]) {
+ match = false;
+ break;
+ }
}
- }
- if (match) {
+ if (match) {
- ColorRegionInfo cri;
- cri.end = true;
- cri.region = j;
- text.write[p_line].region_info[i] = cri;
- i += lr - 1;
+ ColorRegionInfo cri;
+ cri.end = true;
+ cri.region = j;
+ text.write[p_line].region_info[i] = cri;
+ i += lr - 1;
- break;
+ break;
+ }
}
}
}
@@ -268,6 +269,12 @@ void TextEdit::Text::clear_wrap_cache() {
}
}
+void TextEdit::Text::clear_info_icons() {
+ for (int i = 0; i < text.size(); i++) {
+ text.write[i].has_info = false;
+ }
+}
+
void TextEdit::Text::clear() {
text.clear();
@@ -302,6 +309,7 @@ void TextEdit::Text::insert(int p_at, const String &p_text) {
line.breakpoint = false;
line.bookmark = false;
line.hidden = false;
+ line.has_info = false;
line.width_cache = -1;
line.wrap_amount_cache = -1;
line.data = p_text;
@@ -409,7 +417,6 @@ void TextEdit::_update_scrollbars() {
cursor.line_ofs = 0;
cursor.wrap_ofs = 0;
v_scroll->set_value(0);
- v_scroll->set_max(0);
v_scroll->hide();
}
@@ -428,7 +435,6 @@ void TextEdit::_update_scrollbars() {
cursor.x_ofs = 0;
h_scroll->set_value(0);
- h_scroll->set_max(0);
h_scroll->hide();
}
@@ -957,6 +963,10 @@ void TextEdit::_notification(int p_what) {
}
}
+ if (minimap_line < 0 || minimap_line >= (int)text.size()) {
+ break;
+ }
+
Map<int, HighlighterInfo> color_map;
if (syntax_coloring) {
color_map = _get_line_syntax_highlighting(minimap_line);
@@ -1723,7 +1733,9 @@ void TextEdit::_notification(int p_what) {
end = font->get_string_size(l.substr(0, l.rfind(String::chr(0xFFFF)))).x;
}
- draw_string(font, hint_ofs + sb->get_offset() + Vector2(0, font->get_ascent() + font->get_height() * i + spacing), l.replace(String::chr(0xFFFF), ""), font_color);
+ Point2 round_ofs = hint_ofs + sb->get_offset() + Vector2(0, font->get_ascent() + font->get_height() * i + spacing);
+ round_ofs = round_ofs.round();
+ draw_string(font, round_ofs, l.replace(String::chr(0xFFFF), ""), font_color);
if (end > 0) {
Vector2 b = hint_ofs + sb->get_offset() + Vector2(begin, font->get_height() + font->get_height() * i + spacing - 1);
draw_line(b, b + Vector2(end - begin, 0), font_color);
@@ -2846,27 +2858,48 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
// Indent once again if previous line will end with ':','{','[','(' and the line is not a comment
// (i.e. colon/brace precedes current cursor position).
if (cursor.column > 0) {
- char prev_char = text[cursor.line][cursor.column - 1];
- switch (prev_char) {
- case ':':
- case '{':
- case '[':
- case '(': {
- if (!is_line_comment(cursor.line)) {
- if (indent_using_spaces) {
- ins += space_indent;
- } else {
- ins += "\t";
- }
+ const Map<int, Text::ColorRegionInfo> &cri_map = text.get_color_region_info(cursor.line);
+ bool indent_char_found = false;
+ bool should_indent = false;
+ char indent_char = ':';
+ char c = text[cursor.line][cursor.column];
+
+ for (int i = 0; i < cursor.column; i++) {
+ c = text[cursor.line][i];
+ switch (c) {
+ case ':':
+ case '{':
+ case '[':
+ case '(':
+ indent_char_found = true;
+ should_indent = true;
+ indent_char = c;
+ continue;
+ }
- // No need to move the brace below if we are not taking the text with us.
- char closing_char = _get_right_pair_symbol(prev_char);
- if ((closing_char != 0) && (closing_char == text[cursor.line][cursor.column]) && !k->get_command()) {
- brace_indent = true;
- ins += "\n" + ins.substr(1, ins.length() - 2);
- }
- }
- } break;
+ if (indent_char_found && cri_map.has(i) && (color_regions[cri_map[i].region].begin_key == "#" || color_regions[cri_map[i].region].begin_key == "//")) {
+
+ should_indent = true;
+ break;
+ } else if (indent_char_found && !_is_whitespace(c)) {
+ should_indent = false;
+ indent_char_found = false;
+ }
+ }
+
+ if (!is_line_comment(cursor.line) && should_indent) {
+ if (indent_using_spaces) {
+ ins += space_indent;
+ } else {
+ ins += "\t";
+ }
+
+ // No need to move the brace below if we are not taking the text with us.
+ char closing_char = _get_right_pair_symbol(indent_char);
+ if ((closing_char != 0) && (closing_char == text[cursor.line][cursor.column]) && !k->get_command()) {
+ brace_indent = true;
+ ins += "\n" + ins.substr(1, ins.length() - 2);
+ }
}
}
}
@@ -3893,7 +3926,9 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
if (shift_first_line) {
text.set_breakpoint(p_line + 1, text.is_breakpoint(p_line));
text.set_hidden(p_line + 1, text.is_hidden(p_line));
- text.set_info_icon(p_line + 1, text.get_info_icon(p_line), text.get_info(p_line));
+ if (text.has_info_icon(p_line)) {
+ text.set_info_icon(p_line + 1, text.get_info_icon(p_line), text.get_info(p_line));
+ }
text.set_breakpoint(p_line, false);
text.set_hidden(p_line, false);
@@ -4403,7 +4438,6 @@ int TextEdit::get_line_wrap_index_at_col(int p_line, int p_column) const {
}
void TextEdit::cursor_set_column(int p_col, bool p_adjust_viewport) {
-
if (p_col < 0)
p_col = 0;
@@ -4548,7 +4582,7 @@ void TextEdit::_scroll_moved(double p_to_val) {
int v_scroll_i = floor(get_v_scroll());
int sc = 0;
int n_line;
- for (n_line = 0; n_line < text.size() - 1; n_line++) {
+ for (n_line = 0; n_line < text.size(); n_line++) {
if (!is_line_hidden(n_line)) {
sc++;
sc += times_line_wraps(n_line);
@@ -4556,6 +4590,7 @@ void TextEdit::_scroll_moved(double p_to_val) {
break;
}
}
+ n_line = MIN(n_line, text.size() - 1);
int line_wrap_amount = times_line_wraps(n_line);
int wi = line_wrap_amount - (sc - v_scroll_i - 1);
wi = CLAMP(wi, 0, line_wrap_amount);
@@ -5408,11 +5443,11 @@ int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_searc
PoolVector<int> TextEdit::_search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const {
int col, line;
- if (search(p_key, p_search_flags, p_from_line, p_from_column, col, line)) {
+ if (search(p_key, p_search_flags, p_from_line, p_from_column, line, col)) {
PoolVector<int> result;
result.resize(2);
- result.set(0, line);
- result.set(1, col);
+ result.set(SEARCH_RESULT_COLUMN, col);
+ result.set(SEARCH_RESULT_LINE, line);
return result;
} else {
@@ -5656,9 +5691,7 @@ void TextEdit::set_line_info_icon(int p_line, Ref<Texture> p_icon, String p_info
}
void TextEdit::clear_info_icons() {
- for (int i = 0; i < text.size(); i++) {
- text.set_info_icon(i, NULL, "");
- }
+ text.clear_info_icons();
update();
}
@@ -6353,8 +6386,9 @@ void TextEdit::_confirm_completion() {
String line = text[cursor.line];
CharType next_char = line[cursor.column];
CharType last_completion_char = completion_current.insert_text[completion_current.insert_text.length() - 1];
+ CharType last_completion_char_display = completion_current.display[completion_current.display.length() - 1];
- if ((last_completion_char == '"' || last_completion_char == '\'') && last_completion_char == next_char) {
+ if ((last_completion_char == '"' || last_completion_char == '\'') && (last_completion_char == next_char || last_completion_char_display == next_char)) {
_remove_text(cursor.line, cursor.column, cursor.line, cursor.column + 1);
}
@@ -6501,6 +6535,7 @@ void TextEdit::_update_completion_candidates() {
if (inquote && restore_quotes == 1 && !option.display.is_quoted()) {
String quote = single_quote ? "'" : "\"";
option.display = option.display.quote(quote);
+ option.insert_text = option.insert_text.quote(quote);
}
if (option.display.begins_with(s)) {
@@ -6926,6 +6961,9 @@ void TextEdit::_bind_methods() {
BIND_ENUM_CONSTANT(SEARCH_WHOLE_WORDS);
BIND_ENUM_CONSTANT(SEARCH_BACKWARDS);
+ BIND_ENUM_CONSTANT(SEARCH_RESULT_COLUMN);
+ BIND_ENUM_CONSTANT(SEARCH_RESULT_LINE);
+
/*
ClassDB::bind_method(D_METHOD("delete_char"),&TextEdit::delete_char);
ClassDB::bind_method(D_METHOD("delete_line"),&TextEdit::delete_line);
@@ -7102,6 +7140,7 @@ TextEdit::TextEdit() {
max_chars = 0;
clear();
wrap_enabled = false;
+ wrap_at = 0;
wrap_right_offset = 10;
set_focus_mode(FOCUS_ALL);
syntax_highlighter = NULL;
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index e5d9b006fe..4f11e9bb50 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -69,6 +69,10 @@ public:
int region;
bool end;
+ ColorRegionInfo() {
+ region = 0;
+ end = false;
+ }
};
struct Line {
@@ -78,11 +82,22 @@ public:
bool bookmark : 1;
bool hidden : 1;
bool safe : 1;
+ bool has_info : 1;
int wrap_amount_cache : 24;
Map<int, ColorRegionInfo> region_info;
Ref<Texture> info_icon;
String info;
String data;
+ Line() {
+ width_cache = 0;
+ marked = false;
+ breakpoint = false;
+ bookmark = false;
+ hidden = false;
+ safe = false;
+ has_info = false;
+ wrap_amount_cache = 0;
+ }
};
private:
@@ -115,10 +130,15 @@ public:
void set_safe(int p_line, bool p_safe) { text.write[p_line].safe = p_safe; }
bool is_safe(int p_line) const { return text[p_line].safe; }
void set_info_icon(int p_line, Ref<Texture> p_icon, String p_info) {
+ if (p_icon.is_null()) {
+ text.write[p_line].has_info = false;
+ return;
+ }
text.write[p_line].info_icon = p_icon;
text.write[p_line].info = p_info;
+ text.write[p_line].has_info = true;
}
- bool has_info_icon(int p_line) const { return text[p_line].info_icon.is_valid(); }
+ bool has_info_icon(int p_line) const { return text[p_line].has_info; }
const Ref<Texture> &get_info_icon(int p_line) const { return text[p_line].info_icon; }
const String &get_info(int p_line) const { return text[p_line].info; }
void insert(int p_at, const String &p_text);
@@ -127,6 +147,7 @@ public:
void clear();
void clear_width_cache();
void clear_wrap_cache();
+ void clear_info_icons();
_FORCE_INLINE_ const String &operator[](int p_line) const { return text[p_line].data; }
Text() { indent_size = 4; }
};
@@ -136,6 +157,14 @@ private:
int last_fit_x;
int line, column; ///< cursor
int x_ofs, line_ofs, wrap_ofs;
+ Cursor() {
+ last_fit_x = 0;
+ line = 0;
+ column = 0; ///< cursor
+ x_ofs = 0;
+ line_ofs = 0;
+ wrap_ofs = 0;
+ }
} cursor;
struct Selection {
@@ -160,7 +189,21 @@ private:
int to_line, to_column;
bool shiftclick_left;
-
+ Selection() {
+ selecting_mode = MODE_NONE;
+ selecting_line = 0;
+ selecting_column = 0;
+ selected_word_beg = 0;
+ selected_word_end = 0;
+ selected_word_origin = 0;
+ selecting_text = false;
+ active = false;
+ from_line = 0;
+ from_column = 0;
+ to_line = 0;
+ to_column = 0;
+ shiftclick_left = false;
+ }
} selection;
struct Cache {
@@ -212,6 +255,16 @@ private:
int fold_gutter_width;
int info_gutter_width;
int minimap_width;
+ Cache() {
+
+ row_height = 0;
+ line_spacing = 0;
+ line_number_w = 0;
+ breakpoint_gutter_width = 0;
+ fold_gutter_width = 0;
+ info_gutter_width = 0;
+ minimap_width = 0;
+ }
} cache;
Map<int, int> color_region_cache;
@@ -233,6 +286,17 @@ private:
uint32_t version;
bool chain_forward;
bool chain_backward;
+ TextOperation() {
+ type = TYPE_NONE;
+ from_line = 0;
+ from_column = 0;
+ to_line = 0;
+ to_column = 0;
+ prev_version = 0;
+ version = 0;
+ chain_forward = false;
+ chain_backward = false;
+ }
};
String ime_text;
@@ -497,12 +561,16 @@ public:
};
enum SearchFlags {
-
SEARCH_MATCH_CASE = 1,
SEARCH_WHOLE_WORDS = 2,
SEARCH_BACKWARDS = 4
};
+ enum SearchResult {
+ SEARCH_RESULT_COLUMN,
+ SEARCH_RESULT_LINE,
+ };
+
virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const;
void _get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const;
@@ -761,6 +829,7 @@ public:
VARIANT_ENUM_CAST(TextEdit::MenuItems);
VARIANT_ENUM_CAST(TextEdit::SearchFlags);
+VARIANT_ENUM_CAST(TextEdit::SearchResult);
class SyntaxHighlighter {
protected:
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index c9d1295557..d479a1636a 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -1234,7 +1234,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
}
- if (select_mode != SELECT_ROW && (p_item->cells[i].selected || selected_item == p_item)) {
+ if ((select_mode == SELECT_ROW && selected_item == p_item) || p_item->cells[i].selected) {
Rect2i r(cell_rect.position, cell_rect.size);
if (p_item->cells[i].text.size() > 0) {
@@ -2224,8 +2224,9 @@ void Tree::_go_down() {
TreeItem *next = NULL;
if (!selected_item) {
- next = hide_root ? root->get_next_visible() : root;
- selected_item = 0;
+ if (root) {
+ next = hide_root ? root->get_next_visible() : root;
+ }
} else {
next = selected_item->get_next_visible();
@@ -2765,7 +2766,6 @@ bool Tree::edit_selected() {
return false;
Rect2 rect = s->get_meta("__focus_rect");
-
popup_edited_item = s;
popup_edited_item_col = col;
@@ -4050,6 +4050,7 @@ Tree::Tree() {
drop_mode_section = 0;
single_select_defer = NULL;
+ scrolling = false;
allow_rmb_select = false;
force_edit_checkbox_only_on_checkbox = false;
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 361830173b..d5227f6e65 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -159,7 +159,7 @@ protected:
//bind helpers
Dictionary _get_range_config(int p_column) {
Dictionary d;
- double min, max, step;
+ double min = 0.0, max = 0.0, step = 0.0;
get_range_config(p_column, min, max, step);
d["min"] = min;
d["max"] = max;
diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp
index 5768f58977..fd2d4a1a11 100644
--- a/scene/gui/video_player.cpp
+++ b/scene/gui/video_player.cpp
@@ -36,6 +36,10 @@
int VideoPlayer::sp_get_channel_count() const {
+ if (playback.is_null()) {
+ return 0;
+ }
+
return playback->get_channels();
}
@@ -56,6 +60,9 @@ bool VideoPlayer::mix(AudioFrame *p_buffer, int p_frames) {
// Called from main thread (eg VideoStreamPlaybackWebm::update)
int VideoPlayer::_audio_mix_callback(void *p_udata, const float *p_data, int p_frames) {
+ ERR_FAIL_NULL_V(p_udata, 0);
+ ERR_FAIL_NULL_V(p_data, 0);
+
VideoPlayer *vp = (VideoPlayer *)p_udata;
int todo = MIN(vp->resampler.get_writer_space(), p_frames);
@@ -71,6 +78,12 @@ int VideoPlayer::_audio_mix_callback(void *p_udata, const float *p_data, int p_f
return todo;
}
+void VideoPlayer::_mix_audios(void *p_self) {
+
+ ERR_FAIL_NULL(p_self);
+ reinterpret_cast<VideoPlayer *>(p_self)->_mix_audio();
+}
+
// Called from audio thread
void VideoPlayer::_mix_audio() {
@@ -143,7 +156,7 @@ void VideoPlayer::_notification(int p_notification) {
bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus);
- if (stream.is_null() || paused || !playback->is_playing())
+ if (stream.is_null() || paused || playback.is_null() || !playback->is_playing())
return;
double audio_time = USEC_TO_SEC(OS::get_singleton()->get_ticks_usec());
@@ -358,7 +371,7 @@ void VideoPlayer::set_stream_position(float p_position) {
playback->seek(p_position);
}
-Ref<Texture> VideoPlayer::get_video_texture() {
+Ref<Texture> VideoPlayer::get_video_texture() const {
if (playback.is_valid())
return playback->get_texture();
@@ -394,9 +407,9 @@ StringName VideoPlayer::get_bus() const {
return "Master";
}
-void VideoPlayer::_validate_property(PropertyInfo &property) const {
+void VideoPlayer::_validate_property(PropertyInfo &p_property) const {
- if (property.name == "bus") {
+ if (p_property.name == "bus") {
String options;
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
@@ -406,7 +419,7 @@ void VideoPlayer::_validate_property(PropertyInfo &property) const {
options += name;
}
- property.hint_string = options;
+ p_property.hint_string = options;
}
}
diff --git a/scene/gui/video_player.h b/scene/gui/video_player.h
index 62fb7838b6..7d2821427e 100644
--- a/scene/gui/video_player.h
+++ b/scene/gui/video_player.h
@@ -55,7 +55,6 @@ class VideoPlayer : public Control {
RID stream_rid;
Ref<ImageTexture> texture;
- Ref<Image> last_frame;
AudioRBResampler resampler;
Vector<AudioFrame> mix_buffer;
@@ -75,19 +74,19 @@ class VideoPlayer : public Control {
void _mix_audio();
static int _audio_mix_callback(void *p_udata, const float *p_data, int p_frames);
- static void _mix_audios(void *self) { reinterpret_cast<VideoPlayer *>(self)->_mix_audio(); }
+ static void _mix_audios(void *p_self);
protected:
static void _bind_methods();
void _notification(int p_notification);
- void _validate_property(PropertyInfo &property) const;
+ void _validate_property(PropertyInfo &p_property) const;
public:
Size2 get_minimum_size() const;
void set_expand(bool p_expand);
bool has_expand() const;
- Ref<Texture> get_video_texture();
+ Ref<Texture> get_video_texture() const;
void set_stream(const Ref<VideoStream> &p_stream);
Ref<VideoStream> get_stream() const;
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index 6c922adbd2..0ae330b2ed 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -457,6 +457,18 @@ String HTTPRequest::get_download_file() const {
return download_to_file;
}
+
+void HTTPRequest::set_download_chunk_size(int p_chunk_size) {
+
+ ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED);
+
+ client->set_read_chunk_size(p_chunk_size);
+}
+
+int HTTPRequest::get_download_chunk_size() const {
+ return client->get_read_chunk_size();
+}
+
HTTPClient::Status HTTPRequest::get_http_client_status() const {
return client->get_status();
}
@@ -524,9 +536,13 @@ void HTTPRequest::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_timeout", "timeout"), &HTTPRequest::set_timeout);
ClassDB::bind_method(D_METHOD("get_timeout"), &HTTPRequest::get_timeout);
+ ClassDB::bind_method(D_METHOD("set_download_chunk_size"), &HTTPRequest::set_download_chunk_size);
+ ClassDB::bind_method(D_METHOD("get_download_chunk_size"), &HTTPRequest::get_download_chunk_size);
+
ClassDB::bind_method(D_METHOD("_timeout"), &HTTPRequest::_timeout);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "download_file", PROPERTY_HINT_FILE), "set_download_file", "get_download_file");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "download_chunk_size", PROPERTY_HINT_RANGE, "256,16777216"), "set_download_chunk_size", "get_download_chunk_size");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_threads"), "set_use_threads", "is_using_threads");
ADD_PROPERTY(PropertyInfo(Variant::INT, "body_size_limit", PROPERTY_HINT_RANGE, "-1,2000000000"), "set_body_size_limit", "get_body_size_limit");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_redirects", PROPERTY_HINT_RANGE, "-1,64"), "set_max_redirects", "get_max_redirects");
diff --git a/scene/main/http_request.h b/scene/main/http_request.h
index f1f91235a6..fa01172d9f 100644
--- a/scene/main/http_request.h
+++ b/scene/main/http_request.h
@@ -126,6 +126,9 @@ public:
void set_download_file(const String &p_file);
String get_download_file() const;
+ void set_download_chunk_size(int p_chunk_size);
+ int get_download_chunk_size() const;
+
void set_body_size_limit(int p_bytes);
int get_body_size_limit() const;
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 217dacfbfe..616ccc00cb 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -835,19 +835,31 @@ bool Node::is_processing_internal() const {
void Node::set_process_priority(int p_priority) {
data.process_priority = p_priority;
- ERR_FAIL_COND(!data.tree);
+ // Make sure we are in SceneTree.
+ if (data.tree == NULL) {
+ return;
+ }
- if (is_processing())
+ if (is_processing()) {
data.tree->make_group_changed("idle_process");
+ }
- if (is_processing_internal())
+ if (is_processing_internal()) {
data.tree->make_group_changed("idle_process_internal");
+ }
- if (is_physics_processing())
+ if (is_physics_processing()) {
data.tree->make_group_changed("physics_process");
+ }
- if (is_physics_processing_internal())
+ if (is_physics_processing_internal()) {
data.tree->make_group_changed("physics_process_internal");
+ }
+}
+
+int Node::get_process_priority() const {
+
+ return data.process_priority;
}
void Node::set_process_input(bool p_enable) {
@@ -2754,6 +2766,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_process_delta_time"), &Node::get_process_delta_time);
ClassDB::bind_method(D_METHOD("set_process", "enable"), &Node::set_process);
ClassDB::bind_method(D_METHOD("set_process_priority", "priority"), &Node::set_process_priority);
+ ClassDB::bind_method(D_METHOD("get_process_priority"), &Node::get_process_priority);
ClassDB::bind_method(D_METHOD("is_processing"), &Node::is_processing);
ClassDB::bind_method(D_METHOD("set_process_input", "enable"), &Node::set_process_input);
ClassDB::bind_method(D_METHOD("is_processing_input"), &Node::is_processing_input);
@@ -2894,6 +2907,7 @@ void Node::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "owner", PROPERTY_HINT_RESOURCE_TYPE, "Node", 0), "set_owner", "get_owner");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "multiplayer", PROPERTY_HINT_RESOURCE_TYPE, "MultiplayerAPI", 0), "", "get_multiplayer");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "custom_multiplayer", PROPERTY_HINT_RESOURCE_TYPE, "MultiplayerAPI", 0), "set_custom_multiplayer", "get_custom_multiplayer");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "process_priority"), "set_process_priority", "get_process_priority");
BIND_VMETHOD(MethodInfo("_process", PropertyInfo(Variant::REAL, "delta")));
BIND_VMETHOD(MethodInfo("_physics_process", PropertyInfo(Variant::REAL, "delta")));
diff --git a/scene/main/node.h b/scene/main/node.h
index a8bcd2f273..6d0ff7e5cf 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -350,6 +350,7 @@ public:
bool is_processing_internal() const;
void set_process_priority(int p_priority);
+ int get_process_priority() const;
void set_process_input(bool p_enable);
bool is_processing_input() const;
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 38ad6886b1..48f6a0cc95 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -40,6 +40,7 @@
#include "core/project_settings.h"
#include "main/input_default.h"
#include "node.h"
+#include "scene/debugger/script_debugger_remote.h"
#include "scene/resources/dynamic_font.h"
#include "scene/resources/material.h"
#include "scene/resources/mesh.h"
@@ -422,7 +423,7 @@ void SceneTree::input_event(const Ref<InputEvent> &p_event) {
input_handled = false;
- Ref<InputEvent> ev = p_event;
+ const Ref<InputEvent> &ev = p_event;
MainLoop::input_event(ev);
@@ -1094,27 +1095,6 @@ void SceneTree::get_nodes_in_group(const StringName &p_group, List<Node *> *p_li
}
}
-static void _fill_array(Node *p_node, Array &array, int p_level) {
-
- array.push_back(p_node->get_child_count());
- array.push_back(p_node->get_name());
- array.push_back(p_node->get_class());
- array.push_back(p_node->get_instance_id());
- for (int i = 0; i < p_node->get_child_count(); i++) {
-
- _fill_array(p_node->get_child(i), array, p_level + 1);
- }
-}
-
-void SceneTree::_debugger_request_tree(void *self) {
-
- SceneTree *sml = (SceneTree *)self;
-
- Array arr;
- _fill_array(sml->root, arr, 0);
- ScriptDebugger::get_singleton()->send_message("scene_tree", arr);
-}
-
void SceneTree::_flush_delete_queue() {
_THREAD_SAFE_METHOD_
@@ -1337,6 +1317,25 @@ void SceneTree::add_current_scene(Node *p_current) {
}
#ifdef DEBUG_ENABLED
+static void _fill_array(Node *p_node, Array &array, int p_level) {
+
+ array.push_back(p_node->get_child_count());
+ array.push_back(p_node->get_name());
+ array.push_back(p_node->get_class());
+ array.push_back(p_node->get_instance_id());
+ for (int i = 0; i < p_node->get_child_count(); i++) {
+
+ _fill_array(p_node->get_child(i), array, p_level + 1);
+ }
+}
+
+void SceneTree::_debugger_request_tree() {
+
+ Array arr;
+ _fill_array(root, arr, 0);
+ ScriptDebugger::get_singleton()->send_message("scene_tree", arr);
+}
+
void SceneTree::_live_edit_node_path_func(const NodePath &p_path, int p_id) {
live_edit_node_path_cache[p_id] = p_path;
@@ -2067,7 +2066,7 @@ SceneTree::SceneTree() {
int ref_atlas_subdiv = GLOBAL_DEF("rendering/quality/reflections/atlas_subdiv", 8);
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/reflections/atlas_subdiv", PropertyInfo(Variant::INT, "rendering/quality/reflections/atlas_subdiv", PROPERTY_HINT_RANGE, "0,32,or_greater")); //next_power_of_2 will return a 0 as min value
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"));
+ 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"));
root->set_msaa(Viewport::MSAA(msaa_mode));
GLOBAL_DEF("rendering/quality/depth/hdr", true);
@@ -2117,7 +2116,11 @@ SceneTree::SceneTree() {
_update_root_rect();
if (ScriptDebugger::get_singleton()) {
- ScriptDebugger::get_singleton()->set_request_scene_tree_message_func(_debugger_request_tree, this);
+ if (ScriptDebugger::get_singleton()->is_remote()) {
+ ScriptDebuggerRemote *remote_debugger = static_cast<ScriptDebuggerRemote *>(ScriptDebugger::get_singleton());
+
+ remote_debugger->set_scene_tree(this);
+ }
ScriptDebugger::get_singleton()->set_multiplayer(multiplayer);
}
@@ -2129,29 +2132,6 @@ SceneTree::SceneTree() {
#ifdef DEBUG_ENABLED
- live_edit_funcs.udata = this;
- live_edit_funcs.node_path_func = _live_edit_node_path_funcs;
- live_edit_funcs.res_path_func = _live_edit_res_path_funcs;
- live_edit_funcs.node_set_func = _live_edit_node_set_funcs;
- live_edit_funcs.node_set_res_func = _live_edit_node_set_res_funcs;
- live_edit_funcs.node_call_func = _live_edit_node_call_funcs;
- live_edit_funcs.res_set_func = _live_edit_res_set_funcs;
- live_edit_funcs.res_set_res_func = _live_edit_res_set_res_funcs;
- live_edit_funcs.res_call_func = _live_edit_res_call_funcs;
- live_edit_funcs.root_func = _live_edit_root_funcs;
-
- live_edit_funcs.tree_create_node_func = _live_edit_create_node_funcs;
- live_edit_funcs.tree_instance_node_func = _live_edit_instance_node_funcs;
- live_edit_funcs.tree_remove_node_func = _live_edit_remove_node_funcs;
- live_edit_funcs.tree_remove_and_keep_node_func = _live_edit_remove_and_keep_node_funcs;
- live_edit_funcs.tree_restore_node_func = _live_edit_restore_node_funcs;
- live_edit_funcs.tree_duplicate_node_func = _live_edit_duplicate_node_funcs;
- live_edit_funcs.tree_reparent_node_func = _live_edit_reparent_node_funcs;
-
- if (ScriptDebugger::get_singleton()) {
- ScriptDebugger::get_singleton()->set_live_edit_funcs(&live_edit_funcs);
- }
-
live_edit_root = NodePath("/root");
#endif
diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h
index ef847ebb5b..2cf6a117e7 100644
--- a/scene/main/scene_tree.h
+++ b/scene/main/scene_tree.h
@@ -211,7 +211,6 @@ private:
Variant _call_group_flags(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
Variant _call_group(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
- static void _debugger_request_tree(void *self);
void _flush_delete_queue();
//optimization
friend class CanvasItem;
@@ -220,6 +219,7 @@ private:
SelfList<Node>::List xform_change_list;
+ friend class ScriptDebuggerRemote;
#ifdef DEBUG_ENABLED
Map<int, NodePath> live_edit_node_path_cache;
@@ -231,7 +231,7 @@ private:
Map<String, Set<Node *> > live_scene_edit_cache;
Map<Node *, Map<ObjectID, Node *> > live_edit_remove_list;
- ScriptDebugger::LiveEditFuncs live_edit_funcs;
+ void _debugger_request_tree();
void _live_edit_node_path_func(const NodePath &p_path, int p_id);
void _live_edit_res_path_func(const String &p_path, int p_id);
@@ -252,25 +252,6 @@ private:
void _live_edit_duplicate_node_func(const NodePath &p_at, const String &p_new_name);
void _live_edit_reparent_node_func(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
- static void _live_edit_node_path_funcs(void *self, const NodePath &p_path, int p_id) { reinterpret_cast<SceneTree *>(self)->_live_edit_node_path_func(p_path, p_id); }
- static void _live_edit_res_path_funcs(void *self, const String &p_path, int p_id) { reinterpret_cast<SceneTree *>(self)->_live_edit_res_path_func(p_path, p_id); }
-
- static void _live_edit_node_set_funcs(void *self, int p_id, const StringName &p_prop, const Variant &p_value) { reinterpret_cast<SceneTree *>(self)->_live_edit_node_set_func(p_id, p_prop, p_value); }
- static void _live_edit_node_set_res_funcs(void *self, int p_id, const StringName &p_prop, const String &p_value) { reinterpret_cast<SceneTree *>(self)->_live_edit_node_set_res_func(p_id, p_prop, p_value); }
- static void _live_edit_node_call_funcs(void *self, int p_id, const StringName &p_method, VARIANT_ARG_DECLARE) { reinterpret_cast<SceneTree *>(self)->_live_edit_node_call_func(p_id, p_method, VARIANT_ARG_PASS); }
- static void _live_edit_res_set_funcs(void *self, int p_id, const StringName &p_prop, const Variant &p_value) { reinterpret_cast<SceneTree *>(self)->_live_edit_res_set_func(p_id, p_prop, p_value); }
- static void _live_edit_res_set_res_funcs(void *self, int p_id, const StringName &p_prop, const String &p_value) { reinterpret_cast<SceneTree *>(self)->_live_edit_res_set_res_func(p_id, p_prop, p_value); }
- static void _live_edit_res_call_funcs(void *self, int p_id, const StringName &p_method, VARIANT_ARG_DECLARE) { reinterpret_cast<SceneTree *>(self)->_live_edit_res_call_func(p_id, p_method, VARIANT_ARG_PASS); }
- static void _live_edit_root_funcs(void *self, const NodePath &p_scene_path, const String &p_scene_from) { reinterpret_cast<SceneTree *>(self)->_live_edit_root_func(p_scene_path, p_scene_from); }
-
- static void _live_edit_create_node_funcs(void *self, const NodePath &p_parent, const String &p_type, const String &p_name) { reinterpret_cast<SceneTree *>(self)->_live_edit_create_node_func(p_parent, p_type, p_name); }
- static void _live_edit_instance_node_funcs(void *self, const NodePath &p_parent, const String &p_path, const String &p_name) { reinterpret_cast<SceneTree *>(self)->_live_edit_instance_node_func(p_parent, p_path, p_name); }
- static void _live_edit_remove_node_funcs(void *self, const NodePath &p_at) { reinterpret_cast<SceneTree *>(self)->_live_edit_remove_node_func(p_at); }
- static void _live_edit_remove_and_keep_node_funcs(void *self, const NodePath &p_at, ObjectID p_keep_id) { reinterpret_cast<SceneTree *>(self)->_live_edit_remove_and_keep_node_func(p_at, p_keep_id); }
- static void _live_edit_restore_node_funcs(void *self, ObjectID p_id, const NodePath &p_at, int p_at_pos) { reinterpret_cast<SceneTree *>(self)->_live_edit_restore_node_func(p_id, p_at, p_at_pos); }
- static void _live_edit_duplicate_node_funcs(void *self, const NodePath &p_at, const String &p_new_name) { reinterpret_cast<SceneTree *>(self)->_live_edit_duplicate_node_func(p_at, p_new_name); }
- static void _live_edit_reparent_node_funcs(void *self, const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) { reinterpret_cast<SceneTree *>(self)->_live_edit_reparent_node_func(p_at, p_new_place, p_new_name, p_at_pos); }
-
#endif
enum {
diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp
index 14cc705edb..da96c6e89c 100755
--- a/scene/main/timer.cpp
+++ b/scene/main/timer.cpp
@@ -108,7 +108,7 @@ bool Timer::has_autostart() const {
void Timer::start(float p_time) {
- ERR_FAIL_COND_MSG(!is_inside_tree(), "Timer was not added to the SceneTree!");
+ ERR_FAIL_COND_MSG(!is_inside_tree(), "Timer was not added to the SceneTree. Either add it or set autostart to true.");
if (p_time > 0) {
set_wait_time(p_time);
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 95536bbb23..3ad44a4a2e 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -779,10 +779,45 @@ bool Viewport::is_audio_listener_2d() const {
return audio_listener_2d;
}
+void Viewport::enable_canvas_transform_override(bool p_enable) {
+ if (override_canvas_transform == p_enable) {
+ return;
+ }
+
+ override_canvas_transform = p_enable;
+ if (p_enable) {
+ VisualServer::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);
+ }
+}
+
+bool Viewport::is_canvas_transform_override_enbled() const {
+ return override_canvas_transform;
+}
+
+void Viewport::set_canvas_transform_override(const Transform2D &p_transform) {
+ if (canvas_transform_override == p_transform) {
+ return;
+ }
+
+ 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);
+ }
+}
+
+Transform2D Viewport::get_canvas_transform_override() const {
+ return canvas_transform_override;
+}
+
void Viewport::set_canvas_transform(const Transform2D &p_transform) {
canvas_transform = p_transform;
- VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, find_world_2d()->get_canvas(), canvas_transform);
+
+ if (!override_canvas_transform) {
+ VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, find_world_2d()->get_canvas(), canvas_transform);
+ }
}
Transform2D Viewport::get_canvas_transform() const {
@@ -890,10 +925,12 @@ void Viewport::_camera_set(Camera *p_camera) {
camera->notification(Camera::NOTIFICATION_LOST_CURRENT);
}
camera = p_camera;
- if (camera)
- VisualServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera());
- else
- VisualServer::get_singleton()->viewport_attach_camera(viewport, RID());
+ if (!camera_override) {
+ if (camera)
+ VisualServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera());
+ else
+ VisualServer::get_singleton()->viewport_attach_camera(viewport, RID());
+ }
if (camera) {
camera->notification(Camera::NOTIFICATION_BECAME_CURRENT);
@@ -1108,10 +1145,82 @@ Listener *Viewport::get_listener() const {
}
Camera *Viewport::get_camera() const {
-
return camera;
}
+void Viewport::enable_camera_override(bool p_enable) {
+
+#ifndef _3D_DISABLED
+ if (p_enable == camera_override) {
+ return;
+ }
+
+ if (p_enable) {
+ camera_override.rid = VisualServer::get_singleton()->camera_create();
+ } else {
+ VisualServer::get_singleton()->free(camera_override.rid);
+ camera_override.rid = RID();
+ }
+
+ if (p_enable) {
+ VisualServer::get_singleton()->viewport_attach_camera(viewport, camera_override.rid);
+ } else if (camera) {
+ VisualServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera());
+ } else {
+ VisualServer::get_singleton()->viewport_attach_camera(viewport, RID());
+ }
+#endif
+}
+
+bool Viewport::is_camera_override_enabled() const {
+ return camera_override;
+}
+
+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);
+ }
+}
+
+Transform Viewport::get_camera_override_transform() const {
+ if (camera_override) {
+ return camera_override.transform;
+ }
+
+ return Transform();
+}
+
+void Viewport::set_camera_override_perspective(float p_fovy_degrees, float p_z_near, float p_z_far) {
+ if (camera_override) {
+ if (camera_override.fov == p_fovy_degrees && camera_override.z_near == p_z_near &&
+ camera_override.z_far == p_z_far && camera_override.projection == CameraOverrideData::PROJECTION_PERSPECTIVE)
+ return;
+
+ camera_override.fov = p_fovy_degrees;
+ camera_override.z_near = p_z_near;
+ 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);
+ }
+}
+
+void Viewport::set_camera_override_orthogonal(float p_size, float p_z_near, float p_z_far) {
+ if (camera_override) {
+ if (camera_override.size == p_size && camera_override.z_near == p_z_near &&
+ camera_override.z_far == p_z_far && camera_override.projection == CameraOverrideData::PROJECTION_ORTHOGONAL)
+ return;
+
+ camera_override.size = p_size;
+ camera_override.z_near = p_z_near;
+ 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);
+ }
+}
+
Transform2D Viewport::get_final_transform() const {
return stretch_transform * global_canvas_transform;
@@ -2298,12 +2407,12 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Input *input = Input::get_singleton();
- if (p_event->is_action_pressed("ui_focus_next") && input->is_action_just_pressed("ui_focus_next")) {
+ if (!mods && p_event->is_action_pressed("ui_focus_next") && input->is_action_just_pressed("ui_focus_next")) {
next = from->find_next_valid_focus();
}
- if (p_event->is_action_pressed("ui_focus_prev") && input->is_action_just_pressed("ui_focus_prev")) {
+ if (!mods && p_event->is_action_pressed("ui_focus_prev") && input->is_action_just_pressed("ui_focus_prev")) {
next = from->find_prev_valid_focus();
}
@@ -2846,7 +2955,7 @@ int Viewport::gui_get_canvas_sort_index() {
void Viewport::set_msaa(MSAA p_msaa) {
- ERR_FAIL_INDEX(p_msaa, 5);
+ ERR_FAIL_INDEX(p_msaa, 7);
if (msaa == p_msaa)
return;
msaa = p_msaa;
@@ -2913,6 +3022,7 @@ bool Viewport::gui_is_dragging() const {
}
void Viewport::set_input_as_handled() {
+ _drop_physics_mouseover();
if (handle_input_locally) {
local_input_handled = true;
} else {
@@ -3077,7 +3187,7 @@ void Viewport::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent_bg"), "set_transparent_background", "has_transparent_background");
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"), "set_msaa", "get_msaa");
+ 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, "hdr"), "set_hdr", "get_hdr");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_3d"), "set_disable_3d", "is_3d_disabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_3d_linear"), "set_keep_3d_linear", "get_keep_3d_linear");
@@ -3180,6 +3290,7 @@ Viewport::Viewport() {
parent = NULL;
listener = NULL;
camera = NULL;
+ override_canvas_transform = false;
canvas_layers.insert(NULL); // This eases picking code (interpreted as the canvas of the Viewport)
arvr = false;
size_override = false;
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 6393785b22..3c3b436ca1 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -160,6 +160,24 @@ private:
bool arvr;
+ struct CameraOverrideData {
+ Transform transform;
+ enum Projection {
+ PROJECTION_PERSPECTIVE,
+ PROJECTION_ORTHOGONAL
+ };
+ Projection projection;
+ float fov;
+ float size;
+ float z_near;
+ float z_far;
+ RID rid;
+
+ operator bool() const {
+ return rid != RID();
+ }
+ } camera_override;
+
Camera *camera;
Set<Camera *> cameras;
Set<CanvasLayer *> canvas_layers;
@@ -173,6 +191,9 @@ private:
bool audio_listener_2d;
RID internal_listener_2d;
+ bool override_canvas_transform;
+
+ Transform2D canvas_transform_override;
Transform2D canvas_transform;
Transform2D global_canvas_transform;
Transform2D stretch_transform;
@@ -394,6 +415,15 @@ public:
Listener *get_listener() const;
Camera *get_camera() const;
+ void enable_camera_override(bool p_enable);
+ bool is_camera_override_enabled() const;
+
+ void set_camera_override_transform(const Transform &p_transform);
+ Transform get_camera_override_transform() const;
+
+ 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();
@@ -418,6 +448,12 @@ public:
Ref<World2D> get_world_2d() const;
Ref<World2D> find_world_2d() const;
+ void enable_canvas_transform_override(bool p_enable);
+ bool is_canvas_transform_override_enbled() const;
+
+ void set_canvas_transform_override(const Transform2D &p_transform);
+ Transform2D get_canvas_transform_override() const;
+
void set_canvas_transform(const Transform2D &p_transform);
Transform2D get_canvas_transform() const;
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index d932545da4..f4ac277d00 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -2870,9 +2870,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
const Vector3 &v1 = t1.value.loc;
const Vector3 &v2 = t2.value.loc;
- if (v0 == v2) {
+ if (v0.is_equal_approx(v2)) {
//0 and 2 are close, let's see if 1 is close
- if (v0 != v1) {
+ if (!v0.is_equal_approx(v1)) {
//not close, not optimizable
return false;
}
@@ -2909,9 +2909,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
//localize both to rotation from q0
- if (Math::is_zero_approx((q0 - q2).length())) {
+ if (q0.is_equal_approx(q2)) {
- if (!Math::is_zero_approx((q0 - q1).length()))
+ if (!q0.is_equal_approx(q1))
return false;
} else {
@@ -2959,9 +2959,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
const Vector3 &v1 = t1.value.scale;
const Vector3 &v2 = t2.value.scale;
- if (v0 == v2) {
+ if (v0.is_equal_approx(v2)) {
//0 and 2 are close, let's see if 1 is close
- if (v0 != v1) {
+ if (!v0.is_equal_approx(v1)) {
//not close, not optimizable
return false;
}
diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp
index 5b61654c5d..286f9e37cd 100644
--- a/scene/resources/audio_stream_sample.cpp
+++ b/scene/resources/audio_stream_sample.cpp
@@ -95,8 +95,8 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds
// this function will be compiled branchless by any decent compiler
int32_t final, final_r, next, next_r;
- while (amount--) {
-
+ while (amount) {
+ amount--;
int64_t pos = offset >> MIX_FRAC_BITS;
if (is_stereo && !is_ima_adpcm)
pos <<= 1;
@@ -444,6 +444,7 @@ int AudioStreamSample::get_loop_end() const {
void AudioStreamSample::set_mix_rate(int p_hz) {
+ ERR_FAIL_COND(p_hz == 0);
mix_rate = p_hz;
}
int AudioStreamSample::get_mix_rate() const {
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 0dcc184a1d..e82819f270 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -432,7 +432,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_font("font", "TextEdit", default_font);
- theme->set_color("background_color", "TextEdit", Color(0, 0, 0));
+ theme->set_color("background_color", "TextEdit", Color(0, 0, 0, 0));
theme->set_color("completion_background_color", "TextEdit", Color(0.17, 0.16, 0.2));
theme->set_color("completion_selected_color", "TextEdit", Color(0.26, 0.26, 0.27));
theme->set_color("completion_existing_color", "TextEdit", Color(0.87, 0.87, 0.87, 0.13));
@@ -558,9 +558,14 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_stylebox("panel", "PopupPanel", style_pp);
+ // PopupDialog
+
+ Ref<StyleBoxTexture> style_pd = make_stylebox(popup_bg_png, 4, 4, 4, 4, 10, 10, 10, 10);
+ theme->set_stylebox("panel", "PopupDialog", style_pd);
+
// PopupMenu
- theme->set_stylebox("panel", "PopupMenu", make_stylebox(popup_bg_png, 4, 4, 4, 4, 10, 10, 10, 10));
+ theme->set_stylebox("panel", "PopupMenu", style_pd);
theme->set_stylebox("panel_disabled", "PopupMenu", make_stylebox(popup_bg_disabled_png, 4, 4, 4, 4));
theme->set_stylebox("hover", "PopupMenu", selected);
theme->set_stylebox("separator", "PopupMenu", make_stylebox(vseparator_png, 3, 3, 3, 3));
diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp
index 99a2881d58..7524571956 100644
--- a/scene/resources/dynamic_font.cpp
+++ b/scene/resources/dynamic_font.cpp
@@ -657,6 +657,7 @@ void DynamicFont::_reload_cache() {
if (!data.is_valid()) {
data_at_size.unref();
outline_data_at_size.unref();
+ fallbacks.resize(0);
fallback_data_at_size.resize(0);
fallback_outline_data_at_size.resize(0);
return;
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp
index bc96b5e9f3..ddf97f48d1 100644
--- a/scene/resources/environment.cpp
+++ b/scene/resources/environment.cpp
@@ -978,7 +978,9 @@ void Environment::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "background_sky", PROPERTY_HINT_RESOURCE_TYPE, "Sky"), "set_sky", "get_sky");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "background_sky_custom_fov", PROPERTY_HINT_RANGE, "0,180,0.1"), "set_sky_custom_fov", "get_sky_custom_fov");
ADD_PROPERTY(PropertyInfo(Variant::BASIS, "background_sky_orientation"), "set_sky_orientation", "get_sky_orientation");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "background_sky_rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_sky_rotation", "get_sky_rotation");
+ // Only display rotation in degrees in the inspector (like in Spatial).
+ // This avoids displaying the same information twice.
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "background_sky_rotation", PROPERTY_HINT_NONE, "", 0), "set_sky_rotation", "get_sky_rotation");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "background_sky_rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_sky_rotation_degrees", "get_sky_rotation_degrees");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "background_color"), "set_bg_color", "get_bg_color");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "background_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_bg_energy", "get_bg_energy");
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 0de462d616..41bf7f4bf0 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -496,10 +496,16 @@ void SpatialMaterial::_update_shader() {
}
code += "uniform float roughness : hint_range(0,1);\n";
code += "uniform float point_size : hint_range(0,128);\n";
- code += "uniform sampler2D texture_metallic : hint_white;\n";
- code += "uniform vec4 metallic_texture_channel;\n";
- code += "uniform sampler2D texture_roughness : hint_white;\n";
- code += "uniform vec4 roughness_texture_channel;\n";
+
+ if (textures[TEXTURE_METALLIC] != NULL) {
+ code += "uniform sampler2D texture_metallic : hint_white;\n";
+ code += "uniform vec4 metallic_texture_channel;\n";
+ }
+
+ if (textures[TEXTURE_ROUGHNESS] != NULL) {
+ code += "uniform sampler2D texture_roughness : hint_white;\n";
+ code += "uniform vec4 roughness_texture_channel;\n";
+ }
if (billboard_mode == BILLBOARD_PARTICLES) {
code += "uniform int particles_anim_h_frames;\n";
code += "uniform int particles_anim_v_frames;\n";
@@ -790,20 +796,30 @@ void SpatialMaterial::_update_shader() {
if (flags[FLAG_ALBEDO_FROM_VERTEX_COLOR]) {
code += "\talbedo_tex *= COLOR;\n";
}
-
code += "\tALBEDO = albedo.rgb * albedo_tex.rgb;\n";
- if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tfloat metallic_tex = dot(triplanar_texture(texture_metallic,uv1_power_normal,uv1_triplanar_pos),metallic_texture_channel);\n";
+
+ if (textures[TEXTURE_METALLIC] != NULL) {
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tfloat metallic_tex = dot(triplanar_texture(texture_metallic,uv1_power_normal,uv1_triplanar_pos),metallic_texture_channel);\n";
+ } else {
+ code += "\tfloat metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel);\n";
+ }
+ code += "\tMETALLIC = metallic_tex * metallic;\n";
} else {
- code += "\tfloat metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel);\n";
+ code += "\tMETALLIC = metallic;\n";
}
- code += "\tMETALLIC = metallic_tex * metallic;\n";
- if (flags[FLAG_UV1_USE_TRIPLANAR]) {
- code += "\tfloat roughness_tex = dot(triplanar_texture(texture_roughness,uv1_power_normal,uv1_triplanar_pos),roughness_texture_channel);\n";
+
+ if (textures[TEXTURE_ROUGHNESS] != NULL) {
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tfloat roughness_tex = dot(triplanar_texture(texture_roughness,uv1_power_normal,uv1_triplanar_pos),roughness_texture_channel);\n";
+ } else {
+ code += "\tfloat roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel);\n";
+ }
+ code += "\tROUGHNESS = roughness_tex * roughness;\n";
} else {
- code += "\tfloat roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel);\n";
+ code += "\tROUGHNESS = roughness;\n";
}
- code += "\tROUGHNESS = roughness_tex * roughness;\n";
+
code += "\tSPECULAR = specular;\n";
if (features[FEATURE_NORMAL_MAPPING]) {
@@ -1389,6 +1405,8 @@ void SpatialMaterial::set_texture(TextureParam p_param, const Ref<Texture> &p_te
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);
+ _change_notify();
+ _queue_shader_change();
}
Ref<Texture> SpatialMaterial::get_texture(TextureParam p_param) const {
@@ -1754,6 +1772,7 @@ SpatialMaterial::TextureChannel SpatialMaterial::get_roughness_texture_channel()
void SpatialMaterial::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));
}
@@ -1764,6 +1783,7 @@ SpatialMaterial::TextureChannel SpatialMaterial::get_ao_texture_channel() const
void SpatialMaterial::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));
}
@@ -1804,10 +1824,9 @@ RID SpatialMaterial::get_material_rid_for_2d(bool p_shaded, bool p_transparent,
material->set_flag(FLAG_SRGB_VERTEX_COLOR, true);
material->set_flag(FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
material->set_flag(FLAG_USE_ALPHA_SCISSOR, p_cut_alpha);
- if (p_billboard) {
- material->set_billboard_mode(BILLBOARD_ENABLED);
- } else if (p_billboard_y) {
- material->set_billboard_mode(BILLBOARD_FIXED_Y);
+ if (p_billboard || p_billboard_y) {
+ material->set_flag(FLAG_BILLBOARD_KEEP_SCALE, true);
+ material->set_billboard_mode(p_billboard_y ? BILLBOARD_FIXED_Y : BILLBOARD_ENABLED);
}
materials_for_2d[version] = material;
diff --git a/scene/resources/material.h b/scene/resources/material.h
index 2423d6d48b..11f8f20cf3 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -252,7 +252,7 @@ private:
uint64_t flags : 18;
uint64_t detail_blend_mode : 2;
uint64_t diffuse_mode : 3;
- uint64_t specular_mode : 2;
+ uint64_t specular_mode : 3;
uint64_t invalid_key : 1;
uint64_t deep_parallax : 1;
uint64_t billboard_mode : 2;
@@ -260,6 +260,8 @@ private:
uint64_t proximity_fade : 1;
uint64_t distance_fade : 2;
uint64_t emission_op : 1;
+ uint64_t texture_metallic : 1;
+ uint64_t texture_roughness : 1;
};
uint64_t key;
@@ -305,6 +307,8 @@ private:
mk.proximity_fade = proximity_fade_enabled;
mk.distance_fade = distance_fade;
mk.emission_op = emission_op;
+ mk.texture_metallic = textures[TEXTURE_METALLIC].is_valid() ? 1 : 0;
+ mk.texture_roughness = textures[TEXTURE_ROUGHNESS].is_valid() ? 1 : 0;
return mk;
}
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index 7d62873bbd..5ce269fff9 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -397,6 +397,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
if (p_owner->get_scene_inherited_state().is_null() && (p_node == p_owner || (p_node->get_owner() == p_owner && (p_node->get_parent() == p_owner || p_node->get_parent()->get_owner() == p_owner)))) {
//do not save index, because it belongs to saved scene and scene is not inherited
nd.index = -1;
+ } else if (p_node == p_owner) {
+ //This (hopefully) happens if the node is a scene root, so its index is irrelevant.
+ nd.index = -1;
} else {
//part of an inherited scene, or parent is from an instanced scene
nd.index = p_node->get_index();
diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp
index 969743f78c..c5956d9bc2 100644
--- a/scene/resources/particles_material.cpp
+++ b/scene/resources/particles_material.cpp
@@ -332,7 +332,7 @@ void ParticlesMaterial::_update_shader() {
code += " float base_angle = (initial_angle + tex_angle) * mix(1.0, angle_rand, initial_angle_random);\n";
code += " CUSTOM.x = base_angle * degree_to_rad;\n"; // angle
code += " CUSTOM.y = 0.0;\n"; // phase
- code += " CUSTOM.w = LIFETIME * (1.0 - lifetime_randomness * rand_from_seed(alt_seed));\n";
+ code += " CUSTOM.w = (1.0 - lifetime_randomness * rand_from_seed(alt_seed));\n";
code += " CUSTOM.z = (anim_offset + tex_anim_offset) * mix(1.0, anim_offset_rand, anim_offset_random);\n"; // animation offset (0-1)
switch (emission_shape) {
diff --git a/scene/resources/ray_shape.cpp b/scene/resources/ray_shape.cpp
index 5a696aee23..f185263a36 100644
--- a/scene/resources/ray_shape.cpp
+++ b/scene/resources/ray_shape.cpp
@@ -90,6 +90,12 @@ void RayShape::_bind_methods() {
RayShape::RayShape() :
Shape(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_RAY)) {
- set_length(1.0);
- set_slips_on_slope(false);
+ length = 1.0;
+ slips_on_slope = false;
+
+ /* Code copied from setters to prevent the use of uninitialized variables */
+ _update_shape();
+ notify_change_to_owners();
+ _change_notify("length");
+ _change_notify("slips_on_slope");
}
diff --git a/scene/resources/segment_shape_2d.cpp b/scene/resources/segment_shape_2d.cpp
index 62c5f9bab3..cc6ec93d74 100644
--- a/scene/resources/segment_shape_2d.cpp
+++ b/scene/resources/segment_shape_2d.cpp
@@ -120,8 +120,8 @@ void RayShape2D::draw(const RID &p_to_rid, const Color &p_color) {
Vector<Vector2> pts;
float tsize = 4;
pts.push_back(tip + Vector2(0, tsize));
- pts.push_back(tip + Vector2(0.707 * tsize, 0));
- pts.push_back(tip + Vector2(-0.707 * tsize, 0));
+ pts.push_back(tip + Vector2(Math_SQRT12 * tsize, 0));
+ pts.push_back(tip + Vector2(-Math_SQRT12 * tsize, 0));
Vector<Color> cols;
for (int i = 0; i < 3; i++)
cols.push_back(p_color);
@@ -134,7 +134,7 @@ Rect2 RayShape2D::get_rect() const {
Rect2 rect;
rect.position = Vector2();
rect.expand_to(Vector2(0, length));
- rect = rect.grow(0.707 * 4);
+ rect = rect.grow(Math_SQRT12 * 4);
return rect;
}
diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp
index 9ee7c2936e..f26b57b572 100644
--- a/scene/resources/style_box.cpp
+++ b/scene/resources/style_box.cpp
@@ -81,6 +81,10 @@ Size2 StyleBox::get_center_size() const {
return Size2();
}
+Rect2 StyleBox::get_draw_rect(const Rect2 &p_rect) const {
+ return p_rect;
+}
+
void StyleBox::_bind_methods() {
ClassDB::bind_method(D_METHOD("test_mask", "point", "rect"), &StyleBox::test_mask);
@@ -175,6 +179,10 @@ float StyleBoxTexture::get_style_margin(Margin p_margin) const {
return margin[p_margin];
}
+Rect2 StyleBoxTexture::get_draw_rect(const Rect2 &p_rect) const {
+ return p_rect.grow_individual(expand_margin[MARGIN_LEFT], expand_margin[MARGIN_TOP], expand_margin[MARGIN_RIGHT], expand_margin[MARGIN_BOTTOM]);
+}
+
void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const {
if (texture.is_null())
return;
@@ -685,6 +693,19 @@ inline void adapt_values(int p_index_a, int p_index_b, int *adapted_values, cons
adapted_values[p_index_a] = MIN(p_max_a, adapted_values[p_index_a]);
adapted_values[p_index_b] = MIN(p_max_b, adapted_values[p_index_b]);
}
+
+Rect2 StyleBoxFlat::get_draw_rect(const Rect2 &p_rect) const {
+ Rect2 draw_rect = p_rect.grow_individual(expand_margin[MARGIN_LEFT], expand_margin[MARGIN_TOP], expand_margin[MARGIN_RIGHT], expand_margin[MARGIN_BOTTOM]);
+
+ if (shadow_size > 0) {
+ Rect2 shadow_rect = draw_rect.grow(shadow_size);
+ shadow_rect.position += shadow_offset;
+ draw_rect = draw_rect.merge(shadow_rect);
+ }
+
+ return draw_rect;
+}
+
void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
//PREPARATIONS
@@ -694,6 +715,11 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
return;
}
+ Rect2 style_rect = p_rect.grow_individual(expand_margin[MARGIN_LEFT], expand_margin[MARGIN_TOP], expand_margin[MARGIN_RIGHT], expand_margin[MARGIN_BOTTOM]);
+ if (Math::is_zero_approx(style_rect.size.width) || Math::is_zero_approx(style_rect.size.height)) {
+ return;
+ }
+
bool rounded_corners = (corner_radius[0] > 0) || (corner_radius[1] > 0) || (corner_radius[2] > 0) || (corner_radius[3] > 0);
bool aa_on = rounded_corners && anti_aliased;
@@ -701,7 +727,6 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
bool blend_on = blend_border && draw_border;
- Rect2 style_rect = p_rect.grow_individual(expand_margin[MARGIN_LEFT], expand_margin[MARGIN_TOP], expand_margin[MARGIN_RIGHT], expand_margin[MARGIN_BOTTOM]);
Rect2 border_style_rect = style_rect;
if (aa_on && !blend_on) {
float aa_size_grow = 0.5 * ((aa_size + 1) / 2);
diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h
index d02e107480..ec07b5e885 100644
--- a/scene/resources/style_box.h
+++ b/scene/resources/style_box.h
@@ -56,6 +56,7 @@ public:
float get_margin(Margin p_margin) const;
virtual Size2 get_center_size() const;
+ virtual Rect2 get_draw_rect(const Rect2 &p_rect) const;
virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const = 0;
CanvasItem *get_current_item_drawn() const;
@@ -133,6 +134,7 @@ public:
void set_modulate(const Color &p_modulate);
Color get_modulate() const;
+ virtual Rect2 get_draw_rect(const Rect2 &p_rect) const;
virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const;
StyleBoxTexture();
@@ -227,6 +229,7 @@ public:
virtual Size2 get_center_size() const;
+ virtual Rect2 get_draw_rect(const Rect2 &p_rect) const;
virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const;
StyleBoxFlat();
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index c2e2f85723..b21546af2f 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -1333,6 +1333,7 @@ void LargeTexture::set_piece_offset(int p_idx, const Point2 &p_offset) {
void LargeTexture::set_piece_texture(int p_idx, const Ref<Texture> &p_texture) {
ERR_FAIL_COND(p_texture == this);
+ ERR_FAIL_COND(p_texture.is_null());
ERR_FAIL_INDEX(p_idx, pieces.size());
pieces.write[p_idx].texture = p_texture;
};
@@ -2369,16 +2370,20 @@ RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String
if (header[0] == 'G' && header[1] == 'D' && header[2] == '3' && header[3] == 'T') {
if (tex3d.is_null()) {
+ f->close();
memdelete(f);
ERR_FAIL_COND_V(tex3d.is_null(), RES())
}
} else if (header[0] == 'G' && header[1] == 'D' && header[2] == 'A' && header[3] == 'T') {
if (texarr.is_null()) {
+ f->close();
memdelete(f);
ERR_FAIL_COND_V(texarr.is_null(), RES())
}
} else {
+ f->close();
+ memdelete(f);
ERR_FAIL_V_MSG(RES(), "Unrecognized layered texture file format '" + String((const char *)header) + "'.");
}
@@ -2418,6 +2423,7 @@ RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String
if (r_error) {
*r_error = ERR_FILE_CORRUPT;
}
+ f->close();
memdelete(f);
ERR_FAIL_V(RES());
}
@@ -2453,6 +2459,7 @@ RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String
if (r_error) {
*r_error = ERR_FILE_CORRUPT;
}
+ f->close();
memdelete(f);
ERR_FAIL_V(RES());
}
@@ -2473,8 +2480,9 @@ RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String
if (bytes != total_size) {
if (r_error) {
*r_error = ERR_FILE_CORRUPT;
- memdelete(f);
}
+ f->close();
+ memdelete(f);
ERR_FAIL_V(RES());
}
}
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp
index f1429a7d7b..bf9079c9f4 100644
--- a/scene/resources/theme.cpp
+++ b/scene/resources/theme.cpp
@@ -44,8 +44,11 @@ PoolVector<String> Theme::_get_icon_list(const String &p_type) const {
get_icon_list(p_type, &il);
ilret.resize(il.size());
- for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
- ilret.push_back(E->get());
+
+ int i = 0;
+ PoolVector<String>::Write w = ilret.write();
+ for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
+ w[i] = E->get();
}
return ilret;
}
@@ -57,8 +60,11 @@ PoolVector<String> Theme::_get_stylebox_list(const String &p_type) const {
get_stylebox_list(p_type, &il);
ilret.resize(il.size());
- for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
- ilret.push_back(E->get());
+
+ int i = 0;
+ PoolVector<String>::Write w = ilret.write();
+ for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
+ w[i] = E->get();
}
return ilret;
}
@@ -70,8 +76,11 @@ PoolVector<String> Theme::_get_stylebox_types(void) const {
get_stylebox_types(&il);
ilret.resize(il.size());
- for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
- ilret.push_back(E->get());
+
+ int i = 0;
+ PoolVector<String>::Write w = ilret.write();
+ for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
+ w[i] = E->get();
}
return ilret;
}
@@ -83,8 +92,11 @@ PoolVector<String> Theme::_get_font_list(const String &p_type) const {
get_font_list(p_type, &il);
ilret.resize(il.size());
- for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
- ilret.push_back(E->get());
+
+ int i = 0;
+ PoolVector<String>::Write w = ilret.write();
+ for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
+ w[i] = E->get();
}
return ilret;
}
@@ -96,8 +108,11 @@ PoolVector<String> Theme::_get_color_list(const String &p_type) const {
get_color_list(p_type, &il);
ilret.resize(il.size());
- for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
- ilret.push_back(E->get());
+
+ int i = 0;
+ PoolVector<String>::Write w = ilret.write();
+ for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
+ w[i] = E->get();
}
return ilret;
}
@@ -109,8 +124,11 @@ PoolVector<String> Theme::_get_constant_list(const String &p_type) const {
get_constant_list(p_type, &il);
ilret.resize(il.size());
- for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
- ilret.push_back(E->get());
+
+ int i = 0;
+ PoolVector<String>::Write w = ilret.write();
+ for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
+ w[i] = E->get();
}
return ilret;
}
@@ -122,8 +140,11 @@ PoolVector<String> Theme::_get_type_list(const String &p_type) const {
get_type_list(&il);
ilret.resize(il.size());
- for (List<StringName>::Element *E = il.front(); E; E = E->next()) {
- ilret.push_back(E->get());
+
+ int i = 0;
+ PoolVector<String>::Write w = ilret.write();
+ for (List<StringName>::Element *E = il.front(); E; E = E->next(), i++) {
+ w[i] = E->get();
}
return ilret;
}
@@ -699,7 +720,10 @@ void Theme::clear() {
while ((K = icon_map.next(K))) {
const StringName *L = NULL;
while ((L = icon_map[*K].next(L))) {
- icon_map[*K][*L]->disconnect("changed", this, "_emit_theme_changed");
+ Ref<Texture> icon = icon_map[*K][*L];
+ if (icon.is_valid()) {
+ icon->disconnect("changed", this, "_emit_theme_changed");
+ }
}
}
}
@@ -709,7 +733,10 @@ void Theme::clear() {
while ((K = style_map.next(K))) {
const StringName *L = NULL;
while ((L = style_map[*K].next(L))) {
- style_map[*K][*L]->disconnect("changed", this, "_emit_theme_changed");
+ Ref<StyleBox> style = style_map[*K][*L];
+ if (style.is_valid()) {
+ style->disconnect("changed", this, "_emit_theme_changed");
+ }
}
}
}
@@ -719,7 +746,10 @@ void Theme::clear() {
while ((K = font_map.next(K))) {
const StringName *L = NULL;
while ((L = font_map[*K].next(L))) {
- font_map[*K][*L]->disconnect("changed", this, "_emit_theme_changed");
+ Ref<Font> font = font_map[*K][*L];
+ if (font.is_valid()) {
+ font->disconnect("changed", this, "_emit_theme_changed");
+ }
}
}
}
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index 24122a8d99..16a95e65a8 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -148,20 +148,45 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
}
}
} else if (what == "shape")
- for (int i = 0; i < tile_get_shape_count(id); i++)
- tile_set_shape(id, i, p_value);
+ if (tile_get_shape_count(id) > 0) {
+ for (int i = 0; i < tile_get_shape_count(id); i++) {
+ tile_set_shape(id, i, p_value);
+ }
+ } else {
+ tile_set_shape(id, 0, p_value);
+ }
else if (what == "shape_offset")
- for (int i = 0; i < tile_get_shape_count(id); i++)
- tile_set_shape_offset(id, i, p_value);
+ if (tile_get_shape_count(id) > 0) {
+ for (int i = 0; i < tile_get_shape_count(id); i++) {
+ tile_set_shape_offset(id, i, p_value);
+ }
+ } else {
+ tile_set_shape_offset(id, 0, p_value);
+ }
else if (what == "shape_transform")
- for (int i = 0; i < tile_get_shape_count(id); i++)
- tile_set_shape_transform(id, i, p_value);
+ if (tile_get_shape_count(id) > 0) {
+ for (int i = 0; i < tile_get_shape_count(id); i++) {
+ tile_set_shape_transform(id, i, p_value);
+ }
+ } else {
+ tile_set_shape_transform(id, 0, p_value);
+ }
else if (what == "shape_one_way")
- for (int i = 0; i < tile_get_shape_count(id); i++)
- tile_set_shape_one_way(id, i, p_value);
+ if (tile_get_shape_count(id) > 0) {
+ for (int i = 0; i < tile_get_shape_count(id); i++) {
+ tile_set_shape_one_way(id, i, p_value);
+ }
+ } else {
+ tile_set_shape_one_way(id, 0, p_value);
+ }
else if (what == "shape_one_way_margin")
- for (int i = 0; i < tile_get_shape_count(id); i++)
- tile_set_shape_one_way_margin(id, i, p_value);
+ if (tile_get_shape_count(id) > 0) {
+ for (int i = 0; i < tile_get_shape_count(id); i++) {
+ tile_set_shape_one_way_margin(id, i, p_value);
+ }
+ } else {
+ tile_set_shape_one_way_margin(id, 0, p_value);
+ }
else if (what == "shapes")
_tile_set_shapes(id, p_value);
else if (what == "occluder")
diff --git a/scene/resources/video_stream.h b/scene/resources/video_stream.h
index eb3bf6770f..81c7b062cc 100644
--- a/scene/resources/video_stream.h
+++ b/scene/resources/video_stream.h
@@ -63,7 +63,7 @@ public:
//virtual int mix(int16_t* p_buffer,int p_frames)=0;
- virtual Ref<Texture> get_texture() = 0;
+ virtual Ref<Texture> get_texture() const = 0;
virtual void update(float p_delta) = 0;
virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata) = 0;
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index bd6835f816..797de1d863 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -1064,10 +1064,11 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
String src_var = "n_out" + itos(from_node) + "p" + itos(from_port);
if (in_type == VisualShaderNode::PORT_TYPE_SAMPLER && out_type == VisualShaderNode::PORT_TYPE_SAMPLER) {
-
- VisualShaderNodeUniform *uniform = (VisualShaderNodeUniform *)graph[type].nodes[from_node].node.ptr();
- if (uniform) {
- inputs[i] = uniform->get_uniform_name();
+ VisualShaderNode *ptr = const_cast<VisualShaderNode *>(graph[type].nodes[from_node].node.ptr());
+ if (ptr->has_method("get_input_real_name")) {
+ inputs[i] = ptr->call("get_input_real_name");
+ } else if (ptr->has_method("get_uniform_name")) {
+ inputs[i] = ptr->call("get_uniform_name");
} else {
inputs[i] = "";
}
@@ -1442,6 +1443,8 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "viewport_size", "vec3(VIEWPORT_SIZE, 0.0)" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_BOOLEAN, "output_is_srgb", "OUTPUT_IS_SRGB" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_BOOLEAN, "front_facing", "FRONT_FACING" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SAMPLER, "screen_texture", "SCREEN_TEXTURE" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SAMPLER, "depth_texture", "DEPTH_TEXTURE" },
// Spatial, Light
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "fragcoord", "FRAGCOORD.xyz" },
@@ -1488,6 +1491,9 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "point_coord", "vec3(POINT_COORD,0.0)" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "light_pass", "float(AT_LIGHT_PASS ? 1.0 : 0.0)" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SAMPLER, "texture", "TEXTURE" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SAMPLER, "normal_texture", "NORMAL_TEXTURE" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SAMPLER, "screen_texture", "SCREEN_TEXTURE" },
// Canvas Item, Light
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "fragcoord", "FRAGCOORD.xyz" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "uv", "vec3(UV,0.0)" },
@@ -1504,6 +1510,7 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "texture_pixel_size", "vec3(TEXTURE_PIXEL_SIZE, 1.0)" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "point_coord", "vec3(POINT_COORD,0.0)" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SAMPLER, "texture", "TEXTURE" },
// Particles, Vertex
{ Shader::MODE_PARTICLES, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
@@ -1599,11 +1606,15 @@ String VisualShaderNodeInput::get_output_port_name(int p_port) const {
}
String VisualShaderNodeInput::get_caption() const {
- return TTR("Input");
+ return "Input";
}
String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
+ if (get_output_port_type(0) == PORT_TYPE_SAMPLER) {
+ return "";
+ }
+
if (p_for_preview) {
int idx = 0;
@@ -1672,6 +1683,20 @@ String VisualShaderNodeInput::get_input_name() const {
return input_name;
}
+String VisualShaderNodeInput::get_input_real_name() const {
+
+ int idx = 0;
+
+ while (ports[idx].mode != Shader::MODE_MAX) {
+ if (ports[idx].mode == shader_mode && ports[idx].shader_type == shader_type && ports[idx].name == input_name) {
+ return String(ports[idx].string);
+ }
+ idx++;
+ }
+
+ return "";
+}
+
VisualShaderNodeInput::PortType VisualShaderNodeInput::get_input_type_by_name(String p_name) const {
int idx = 0;
@@ -1768,6 +1793,7 @@ void VisualShaderNodeInput::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_input_name", "name"), &VisualShaderNodeInput::set_input_name);
ClassDB::bind_method(D_METHOD("get_input_name"), &VisualShaderNodeInput::get_input_name);
+ ClassDB::bind_method(D_METHOD("get_input_real_name"), &VisualShaderNodeInput::get_input_real_name);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "input_name", PROPERTY_HINT_ENUM, ""), "set_input_name", "get_input_name");
ADD_SIGNAL(MethodInfo("input_type_changed"));
@@ -1921,7 +1947,7 @@ bool VisualShaderNodeOutput::is_port_separator(int p_index) const {
}
String VisualShaderNodeOutput::get_caption() const {
- return TTR("Output");
+ return "Output";
}
String VisualShaderNodeOutput::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
@@ -2233,6 +2259,8 @@ void VisualShaderNodeGroupBase::set_input_port_type(int p_id, int p_type) {
int index = 0;
for (int i = 0; i < inputs_strings.size(); i++) {
Vector<String> arr = inputs_strings[i].split(",");
+ ERR_FAIL_COND(arr.size() != 3);
+
if (arr[0].to_int() == p_id) {
index += arr[0].size();
count = arr[1].size() - 1;
@@ -2266,6 +2294,8 @@ void VisualShaderNodeGroupBase::set_input_port_name(int p_id, const String &p_na
int index = 0;
for (int i = 0; i < inputs_strings.size(); i++) {
Vector<String> arr = inputs_strings[i].split(",");
+ ERR_FAIL_COND(arr.size() != 3);
+
if (arr[0].to_int() == p_id) {
index += arr[0].size() + arr[1].size();
count = arr[2].size() - 1;
@@ -2299,6 +2329,8 @@ void VisualShaderNodeGroupBase::set_output_port_type(int p_id, int p_type) {
int index = 0;
for (int i = 0; i < output_strings.size(); i++) {
Vector<String> arr = output_strings[i].split(",");
+ ERR_FAIL_COND(arr.size() != 3);
+
if (arr[0].to_int() == p_id) {
index += arr[0].size();
count = arr[1].size() - 1;
@@ -2332,6 +2364,8 @@ void VisualShaderNodeGroupBase::set_output_port_name(int p_id, const String &p_n
int index = 0;
for (int i = 0; i < output_strings.size(); i++) {
Vector<String> arr = output_strings[i].split(",");
+ ERR_FAIL_COND(arr.size() != 3);
+
if (arr[0].to_int() == p_id) {
index += arr[0].size() + arr[1].size();
count = arr[2].size() - 1;
@@ -2379,6 +2413,8 @@ void VisualShaderNodeGroupBase::_apply_port_changes() {
for (int i = 0; i < inputs_strings.size(); i++) {
Vector<String> arr = inputs_strings[i].split(",");
+ ERR_FAIL_COND(arr.size() != 3);
+
Port port;
port.type = (PortType)arr[1].to_int();
port.name = arr[2];
@@ -2386,6 +2422,8 @@ void VisualShaderNodeGroupBase::_apply_port_changes() {
}
for (int i = 0; i < outputs_strings.size(); i++) {
Vector<String> arr = outputs_strings[i].split(",");
+ ERR_FAIL_COND(arr.size() != 3);
+
Port port;
port.type = (PortType)arr[1].to_int();
port.name = arr[2];
diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h
index 4f73316404..09222c8d81 100644
--- a/scene/resources/visual_shader.h
+++ b/scene/resources/visual_shader.h
@@ -299,6 +299,7 @@ public:
void set_input_name(String p_name);
String get_input_name() const;
+ String get_input_real_name() const;
int get_input_index_count() const;
PortType get_input_index_type(int p_index) const;
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index a7df736c78..a94fdd9d7b 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -475,27 +475,29 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader:
String id = p_input_vars[2];
String code;
+ code += "\t{\n";
if (id == String()) {
- code += "\tvec4 " + id + "_tex_read = vec4(0.0);\n";
+ code += "\t\tvec4 " + id + "_tex_read = vec4(0.0);\n";
} else {
if (p_input_vars[0] == String()) { // Use UV by default.
if (p_input_vars[1] == String()) {
- code += "\tvec4 " + id + "_tex_read = texture( " + id + " , UV.xy );\n";
+ code += "\t\tvec4 " + id + "_tex_read = texture( " + id + " , UV.xy );\n";
} else {
- code += "\tvec4 " + id + "_tex_read = textureLod( " + id + " , UV.xy , " + p_input_vars[1] + " );\n";
+ code += "\t\tvec4 " + id + "_tex_read = textureLod( " + id + " , UV.xy , " + p_input_vars[1] + " );\n";
}
} else if (p_input_vars[1] == String()) {
//no lod
- code += "\tvec4 " + id + "_tex_read = texture( " + id + " , " + p_input_vars[0] + ".xy );\n";
+ code += "\t\tvec4 " + id + "_tex_read = texture( " + id + " , " + p_input_vars[0] + ".xy );\n";
} else {
- code += "\tvec4 " + id + "_tex_read = textureLod( " + id + " , " + p_input_vars[0] + ".xy , " + p_input_vars[1] + " );\n";
+ code += "\t\tvec4 " + id + "_tex_read = textureLod( " + id + " , " + p_input_vars[0] + ".xy , " + p_input_vars[1] + " );\n";
}
- code += "\t" + p_output_vars[0] + " = " + id + "_tex_read.rgb;\n";
- code += "\t" + p_output_vars[1] + " = " + id + "_tex_read.a;\n";
+ code += "\t\t" + p_output_vars[0] + " = " + id + "_tex_read.rgb;\n";
+ code += "\t\t" + p_output_vars[1] + " = " + id + "_tex_read.a;\n";
}
+ code += "\t}\n";
return code;
}
@@ -905,6 +907,7 @@ void VisualShaderNodeCubeMap::_bind_methods() {
VisualShaderNodeCubeMap::VisualShaderNodeCubeMap() {
texture_type = TYPE_DATA;
+ source = SOURCE_TEXTURE;
}
////////////// Scalar Op