diff options
Diffstat (limited to 'scene')
60 files changed, 797 insertions, 465 deletions
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index 4fcd6893b8..d65a3bfe80 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -735,8 +735,8 @@ void Camera2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_draw_limits"), "set_limit_drawing_enabled", "is_limit_drawing_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_draw_drag_margin"), "set_margin_drawing_enabled", "is_margin_drawing_enabled"); - BIND_ENUM_CONSTANT(ANCHOR_MODE_DRAG_CENTER); BIND_ENUM_CONSTANT(ANCHOR_MODE_FIXED_TOP_LEFT); + BIND_ENUM_CONSTANT(ANCHOR_MODE_DRAG_CENTER); } Camera2D::Camera2D() { diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index d9bb6576d9..b41ba7f590 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -1045,11 +1045,11 @@ void CanvasItem::_bind_methods() { BIND_ENUM_CONSTANT(BLEND_MODE_MUL); BIND_ENUM_CONSTANT(BLEND_MODE_PREMULT_ALPHA); + BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED); BIND_CONSTANT(NOTIFICATION_DRAW); BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED); BIND_CONSTANT(NOTIFICATION_ENTER_CANVAS); BIND_CONSTANT(NOTIFICATION_EXIT_CANVAS); - BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED); } Transform2D CanvasItem::get_canvas_transform() const { diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp index 69bad1623f..b98cdcc365 100644 --- a/scene/2d/joints_2d.cpp +++ b/scene/2d/joints_2d.cpp @@ -33,19 +33,49 @@ #include "physics_body_2d.h" #include "servers/physics_2d_server.h" -void Joint2D::_update_joint() { - - if (!is_inside_tree()) - return; +void Joint2D::_update_joint(bool p_only_free) { if (joint.is_valid()) { + if (ba.is_valid() && bb.is_valid()) + Physics2DServer::get_singleton()->body_remove_collision_exception(ba, bb); + Physics2DServer::get_singleton()->free(joint); + joint = RID(); + ba = RID(); + bb = RID(); } - joint = RID(); + if (p_only_free || !is_inside_tree()) + return; + + Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL; + Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL; + + if (!node_a || !node_b) + return; + + PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a); + PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b); + + if (!body_a || !body_b) + return; + + if (!body_a) { + SWAP(body_a, body_b); + } + + joint = _configure_joint(body_a, body_b); + + if (!joint.is_valid()) + return; - joint = _configure_joint(); Physics2DServer::get_singleton()->get_singleton()->joint_set_param(joint, Physics2DServer::JOINT_PARAM_BIAS, bias); + + ba = body_a->get_rid(); + bb = body_b->get_rid(); + + if (exclude_from_collision) + Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid()); } void Joint2D::set_node_a(const NodePath &p_node_a) { @@ -83,9 +113,7 @@ void Joint2D::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { if (joint.is_valid()) { - - Physics2DServer::get_singleton()->free(joint); - joint = RID(); + _update_joint(true); } } break; } @@ -164,29 +192,8 @@ void PinJoint2D::_notification(int p_what) { } } -RID PinJoint2D::_configure_joint() { - - Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL; - Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL; - - if (!node_a && !node_b) - return RID(); +RID PinJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) { - PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a); - PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b); - - if (!body_a && !body_b) - return RID(); - - if (!body_a) { - SWAP(body_a, body_b); - } else if (body_b) { - //add a collision exception between both - if (get_exclude_nodes_from_collision()) - Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid()); - else - Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(), body_b->get_rid()); - } RID pj = Physics2DServer::get_singleton()->pin_joint_create(get_global_transform().get_origin(), body_a->get_rid(), body_b ? body_b->get_rid() : RID()); Physics2DServer::get_singleton()->pin_joint_set_param(pj, Physics2DServer::PIN_JOINT_SOFTNESS, softness); return pj; @@ -241,24 +248,7 @@ void GrooveJoint2D::_notification(int p_what) { } } -RID GrooveJoint2D::_configure_joint() { - - Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL; - Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL; - - if (!node_a || !node_b) - return RID(); - - PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a); - PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b); - - if (!body_a || !body_b) - return RID(); - - if (get_exclude_nodes_from_collision()) - Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid()); - else - Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(), body_b->get_rid()); +RID GrooveJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) { Transform2D gt = get_global_transform(); Vector2 groove_A1 = gt.get_origin(); @@ -330,24 +320,7 @@ void DampedSpringJoint2D::_notification(int p_what) { } } -RID DampedSpringJoint2D::_configure_joint() { - - Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL; - Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL; - - if (!node_a || !node_b) - return RID(); - - PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a); - PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b); - - if (!body_a || !body_b) - return RID(); - - if (get_exclude_nodes_from_collision()) - Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid()); - else - Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(), body_b->get_rid()); +RID DampedSpringJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) { Transform2D gt = get_global_transform(); Vector2 anchor_A = gt.get_origin(); diff --git a/scene/2d/joints_2d.h b/scene/2d/joints_2d.h index 685299abc6..a6292be51c 100644 --- a/scene/2d/joints_2d.h +++ b/scene/2d/joints_2d.h @@ -32,11 +32,14 @@ #include "node_2d.h" +class PhysicsBody2D; + class Joint2D : public Node2D { GDCLASS(Joint2D, Node2D); RID joint; + RID ba, bb; NodePath a; NodePath b; @@ -45,10 +48,10 @@ class Joint2D : public Node2D { bool exclude_from_collision; protected: - void _update_joint(); + void _update_joint(bool p_only_free = false); void _notification(int p_what); - virtual RID _configure_joint() = 0; + virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) = 0; static void _bind_methods(); @@ -77,7 +80,7 @@ class PinJoint2D : public Joint2D { protected: void _notification(int p_what); - virtual RID _configure_joint(); + virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b); static void _bind_methods(); public: @@ -96,7 +99,7 @@ class GrooveJoint2D : public Joint2D { protected: void _notification(int p_what); - virtual RID _configure_joint(); + virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b); static void _bind_methods(); public: @@ -120,7 +123,7 @@ class DampedSpringJoint2D : public Joint2D { protected: void _notification(int p_what); - virtual RID _configure_joint(); + virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b); static void _bind_methods(); public: diff --git a/scene/2d/navigation_polygon.cpp b/scene/2d/navigation_polygon.cpp index 352ec3b300..c53241e985 100644 --- a/scene/2d/navigation_polygon.cpp +++ b/scene/2d/navigation_polygon.cpp @@ -329,7 +329,7 @@ void NavigationPolygonInstance::_notification(int p_what) { break; } - c = Object::cast_to<Node2D>(get_parent()); + c = Object::cast_to<Node2D>(c->get_parent()); } } break; @@ -452,7 +452,7 @@ String NavigationPolygonInstance::get_configuration_warning() const { return String(); } - c = Object::cast_to<Node2D>(get_parent()); + c = Object::cast_to<Node2D>(c->get_parent()); } return TTR("NavigationPolygonInstance must be a child or grandchild to a Navigation2D node. It only provides navigation data."); diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp index 0ddcb7b51b..a13ce6278e 100644 --- a/scene/2d/parallax_background.cpp +++ b/scene/2d/parallax_background.cpp @@ -49,8 +49,8 @@ void ParallaxBackground::_notification(int p_what) { void ParallaxBackground::_camera_moved(const Transform2D &p_transform) { - set_scroll_offset(p_transform.get_origin()); set_scroll_scale(p_transform.get_scale().dot(Vector2(0.5, 0.5))); + set_scroll_offset(p_transform.get_origin() / p_transform.get_scale()); } void ParallaxBackground::set_scroll_scale(float p_scale) { diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index d3b37ae903..f0ee64a53f 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -910,10 +910,10 @@ void RigidBody2D::_bind_methods() { ADD_SIGNAL(MethodInfo("body_exited", PropertyInfo(Variant::OBJECT, "body"))); ADD_SIGNAL(MethodInfo("sleeping_state_changed")); - BIND_ENUM_CONSTANT(MODE_STATIC); - BIND_ENUM_CONSTANT(MODE_KINEMATIC); BIND_ENUM_CONSTANT(MODE_RIGID); + BIND_ENUM_CONSTANT(MODE_STATIC); BIND_ENUM_CONSTANT(MODE_CHARACTER); + BIND_ENUM_CONSTANT(MODE_KINEMATIC); BIND_ENUM_CONSTANT(CCD_MODE_DISABLED); BIND_ENUM_CONSTANT(CCD_MODE_CAST_RAY); diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index b272da46f8..ff23b3183b 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -46,14 +46,14 @@ Vector2 RayCast2D::get_cast_to() const { return cast_to; } -void RayCast2D::set_collision_layer(uint32_t p_layer) { +void RayCast2D::set_collision_mask(uint32_t p_mask) { - collision_layer = p_layer; + collision_mask = p_mask; } -uint32_t RayCast2D::get_collision_layer() const { +uint32_t RayCast2D::get_collision_mask() const { - return collision_layer; + return collision_mask; } void RayCast2D::set_type_mask(uint32_t p_mask) { @@ -61,6 +61,21 @@ void RayCast2D::set_type_mask(uint32_t p_mask) { type_mask = p_mask; } +void RayCast2D::set_collision_mask_bit(int p_bit, bool p_value) { + + uint32_t mask = get_collision_mask(); + if (p_value) + mask |= 1 << p_bit; + else + mask &= ~(1 << p_bit); + set_collision_mask(mask); +} + +bool RayCast2D::get_collision_mask_bit(int p_bit) const { + + return get_collision_mask() & (1 << p_bit); +} + uint32_t RayCast2D::get_type_mask() const { return type_mask; @@ -203,7 +218,7 @@ void RayCast2D::_update_raycast_state() { Physics2DDirectSpaceState::RayResult rr; - if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_layer, type_mask)) { + if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask, type_mask)) { collided = true; against = rr.collider_id; @@ -276,8 +291,11 @@ void RayCast2D::_bind_methods() { ClassDB::bind_method(D_METHOD("clear_exceptions"), &RayCast2D::clear_exceptions); - ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &RayCast2D::set_collision_layer); - ClassDB::bind_method(D_METHOD("get_collision_layer"), &RayCast2D::get_collision_layer); + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &RayCast2D::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &RayCast2D::get_collision_mask); + + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &RayCast2D::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &RayCast2D::get_collision_mask_bit); ClassDB::bind_method(D_METHOD("set_type_mask", "mask"), &RayCast2D::set_type_mask); ClassDB::bind_method(D_METHOD("get_type_mask"), &RayCast2D::get_type_mask); @@ -288,7 +306,7 @@ void RayCast2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclude_parent"), "set_exclude_parent_body", "get_exclude_parent_body"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "cast_to"), "set_cast_to", "get_cast_to"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_layer", "get_collision_layer"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask"); ADD_PROPERTY(PropertyInfo(Variant::INT, "type_mask", PROPERTY_HINT_FLAGS, "Static,Kinematic,Rigid,Character,Area"), "set_type_mask", "get_type_mask"); } @@ -298,7 +316,7 @@ RayCast2D::RayCast2D() { against = 0; collided = false; against_shape = 0; - collision_layer = 1; + collision_mask = 1; type_mask = Physics2DDirectSpaceState::TYPE_MASK_COLLISION; cast_to = Vector2(0, 50); exclude_parent_body = true; diff --git a/scene/2d/ray_cast_2d.h b/scene/2d/ray_cast_2d.h index 338de814d2..c13ddfdc58 100644 --- a/scene/2d/ray_cast_2d.h +++ b/scene/2d/ray_cast_2d.h @@ -43,7 +43,7 @@ class RayCast2D : public Node2D { Vector2 collision_point; Vector2 collision_normal; Set<RID> exclude; - uint32_t collision_layer; + uint32_t collision_mask; uint32_t type_mask; bool exclude_parent_body; @@ -61,8 +61,11 @@ public: void set_cast_to(const Vector2 &p_point); Vector2 get_cast_to() const; - void set_collision_layer(uint32_t p_layer); - uint32_t get_collision_layer() const; + void set_collision_mask(uint32_t p_mask); + uint32_t get_collision_mask() const; + + void set_collision_mask_bit(int p_bit, bool p_value); + bool get_collision_mask_bit(int p_bit) const; void set_type_mask(uint32_t p_mask); uint32_t get_type_mask() const; diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index ca7b6aa0e4..b0fd57baf5 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -341,12 +341,12 @@ void VisibilityEnabler2D::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "process_parent"), "set_enabler", "is_enabler_enabled", ENABLER_PARENT_PROCESS); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "physics_process_parent"), "set_enabler", "is_enabler_enabled", ENABLER_PARENT_PHYSICS_PROCESS); - BIND_ENUM_CONSTANT(ENABLER_FREEZE_BODIES); BIND_ENUM_CONSTANT(ENABLER_PAUSE_ANIMATIONS); + BIND_ENUM_CONSTANT(ENABLER_FREEZE_BODIES); BIND_ENUM_CONSTANT(ENABLER_PAUSE_PARTICLES); - BIND_ENUM_CONSTANT(ENABLER_PAUSE_ANIMATED_SPRITES); BIND_ENUM_CONSTANT(ENABLER_PARENT_PROCESS); BIND_ENUM_CONSTANT(ENABLER_PARENT_PHYSICS_PROCESS); + BIND_ENUM_CONSTANT(ENABLER_PAUSE_ANIMATED_SPRITES); BIND_ENUM_CONSTANT(ENABLER_MAX); } diff --git a/scene/3d/SCsub b/scene/3d/SCsub index 72739b527e..4008f4f196 100644 --- a/scene/3d/SCsub +++ b/scene/3d/SCsub @@ -7,6 +7,9 @@ if env['disable_3d']: env.scene_sources.append("3d/spatial.cpp") env.scene_sources.append("3d/skeleton.cpp") + env.scene_sources.append("3d/particles.cpp") + env.scene_sources.append("3d/visual_instance.cpp") + env.scene_sources.append("3d/scenario_fx.cpp") else: env.add_source_files(env.scene_sources, "*.cpp") diff --git a/scene/3d/arvr_nodes.cpp b/scene/3d/arvr_nodes.cpp index c6b6c02129..e1e0b9b1ce 100644 --- a/scene/3d/arvr_nodes.cpp +++ b/scene/3d/arvr_nodes.cpp @@ -204,7 +204,7 @@ void ARVRController::_notification(int p_what) { int mask = 1; // check button states for (int i = 0; i < 16; i++) { - bool was_pressed = (button_states && mask) == mask; + bool was_pressed = (button_states & mask) == mask; bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, i); if (!was_pressed && is_pressed) { @@ -231,7 +231,7 @@ void ARVRController::_notification(int p_what) { void ARVRController::_bind_methods() { ClassDB::bind_method(D_METHOD("set_controller_id", "controller_id"), &ARVRController::set_controller_id); ClassDB::bind_method(D_METHOD("get_controller_id"), &ARVRController::get_controller_id); - ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_id"), "set_controller_id", "get_controller_id"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_id", PROPERTY_HINT_RANGE, "1,32,1"), "set_controller_id", "get_controller_id"); ClassDB::bind_method(D_METHOD("get_controller_name"), &ARVRController::get_controller_name); // passthroughs to information about our related joystick @@ -242,6 +242,10 @@ void ARVRController::_bind_methods() { ClassDB::bind_method(D_METHOD("get_is_active"), &ARVRController::get_is_active); ClassDB::bind_method(D_METHOD("get_hand"), &ARVRController::get_hand); + ClassDB::bind_method(D_METHOD("get_rumble"), &ARVRController::get_rumble); + ClassDB::bind_method(D_METHOD("set_rumble", "rumble"), &ARVRController::set_rumble); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rumble", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_rumble", "get_rumble"); + ADD_SIGNAL(MethodInfo("button_pressed", PropertyInfo(Variant::INT, "button"))); ADD_SIGNAL(MethodInfo("button_release", PropertyInfo(Variant::INT, "button"))); }; @@ -299,6 +303,30 @@ float ARVRController::get_joystick_axis(int p_axis) const { return Input::get_singleton()->get_joy_axis(joy_id, p_axis); }; +real_t ARVRController::get_rumble() const { + // get our ARVRServer + ARVRServer *arvr_server = ARVRServer::get_singleton(); + ERR_FAIL_NULL_V(arvr_server, 0.0); + + ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); + if (tracker == NULL) { + return 0.0; + }; + + return tracker->get_rumble(); +}; + +void ARVRController::set_rumble(real_t p_rumble) { + // get our ARVRServer + ARVRServer *arvr_server = ARVRServer::get_singleton(); + ERR_FAIL_NULL(arvr_server); + + ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); + if (tracker != NULL) { + tracker->set_rumble(p_rumble); + }; +}; + bool ARVRController::get_is_active() const { return is_active; }; @@ -336,6 +364,7 @@ String ARVRController::get_configuration_warning() const { ARVRController::ARVRController() { controller_id = 0; is_active = true; + button_states = 0; }; ARVRController::~ARVRController(){ diff --git a/scene/3d/arvr_nodes.h b/scene/3d/arvr_nodes.h index e0ccfab58b..6e940351f2 100644 --- a/scene/3d/arvr_nodes.h +++ b/scene/3d/arvr_nodes.h @@ -89,6 +89,9 @@ public: int is_button_pressed(int p_button) const; float get_joystick_axis(int p_axis) const; + real_t get_rumble() const; + void set_rumble(real_t p_rumble); + bool get_is_active() const; ARVRPositionalTracker::TrackerHand get_hand() const; diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 3c92814c87..ad1a15f363 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -869,7 +869,7 @@ void AudioStreamPlayer3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "attenuation_filter_cutoff_hz", PROPERTY_HINT_RANGE, "50,50000,1"), "set_attenuation_filter_cutoff_hz", "get_attenuation_filter_cutoff_hz"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "attenuation_filter_db", PROPERTY_HINT_RANGE, "-80,0,0.1"), "set_attenuation_filter_db", "get_attenuation_filter_db"); ADD_GROUP("Doppler", "doppler_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "doppler_tracking", PROPERTY_HINT_ENUM, "Disabled,Idle,Fixed"), "set_doppler_tracking", "get_doppler_tracking"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "doppler_tracking", PROPERTY_HINT_ENUM, "Disabled,Idle,Physics"), "set_doppler_tracking", "get_doppler_tracking"); BIND_ENUM_CONSTANT(ATTENUATION_INVERSE_DISTANCE); BIND_ENUM_CONSTANT(ATTENUATION_INVERSE_SQUARE_DISTANCE); diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index 7baf9a9deb..8c7d0c23c3 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -175,7 +175,7 @@ void Camera::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment")); p_list->push_back(PropertyInfo(Variant::REAL, "h_offset")); p_list->push_back(PropertyInfo(Variant::REAL, "v_offset")); - p_list->push_back(PropertyInfo(Variant::INT, "doppler/tracking", PROPERTY_HINT_ENUM, "Disabled,Idle,Fixed")); + p_list->push_back(PropertyInfo(Variant::INT, "doppler/tracking", PROPERTY_HINT_ENUM, "Disabled,Idle,Physics")); } void Camera::_update_camera() { diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp index 9d55a82824..c0ca358717 100644 --- a/scene/3d/gi_probe.cpp +++ b/scene/3d/gi_probe.cpp @@ -1134,6 +1134,10 @@ void GIProbe::_find_meshes(Node *p_at_node, Baker *p_baker) { } } +GIProbe::BakeBeginFunc GIProbe::bake_begin_function = NULL; +GIProbe::BakeStepFunc GIProbe::bake_step_function = NULL; +GIProbe::BakeEndFunc GIProbe::bake_end_function = NULL; + void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug) { Baker baker; @@ -1177,14 +1181,25 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug) { _find_meshes(p_from_node ? p_from_node : get_parent(), &baker); + if (bake_begin_function) { + bake_begin_function(baker.mesh_list.size() + 1); + } + int pmc = 0; for (List<Baker::PlotMesh>::Element *E = baker.mesh_list.front(); E; E = E->next()) { - print_line("plotting mesh " + itos(pmc++) + "/" + itos(baker.mesh_list.size())); + if (bake_step_function) { + bake_step_function(pmc, RTR("Plotting Meshes") + " " + itos(pmc) + "/" + itos(baker.mesh_list.size())); + } + + pmc++; _plot_mesh(E->get().local_xform, E->get().mesh, &baker, E->get().instance_materials, E->get().override_material); } + if (bake_step_function) { + bake_step_function(pmc++, RTR("Finishing Plot")); + } _fixup_plot(0, 0, 0, 0, 0, &baker); @@ -1282,6 +1297,10 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug) { set_probe_data(probe_data); } + + if (bake_end_function) { + bake_end_function(); + } } void GIProbe::_debug_mesh(int p_idx, int p_level, const Rect3 &p_aabb, Ref<MultiMesh> &p_multimesh, int &idx, Baker *p_baker) { @@ -1478,6 +1497,7 @@ void GIProbe::_bind_methods() { BIND_ENUM_CONSTANT(SUBDIV_64); BIND_ENUM_CONSTANT(SUBDIV_128); BIND_ENUM_CONSTANT(SUBDIV_256); + BIND_ENUM_CONSTANT(SUBDIV_512); BIND_ENUM_CONSTANT(SUBDIV_MAX); } diff --git a/scene/3d/gi_probe.h b/scene/3d/gi_probe.h index 5a06984a47..50d0c33d4f 100644 --- a/scene/3d/gi_probe.h +++ b/scene/3d/gi_probe.h @@ -95,6 +95,10 @@ public: }; + typedef void (*BakeBeginFunc)(int); + typedef void (*BakeStepFunc)(int, const String &); + typedef void (*BakeEndFunc)(); + private: //stuff used for bake struct Baker { @@ -190,6 +194,10 @@ protected: static void _bind_methods(); public: + static BakeBeginFunc bake_begin_function; + static BakeStepFunc bake_step_function; + static BakeEndFunc bake_end_function; + void set_probe_data(const Ref<GIProbeData> &p_data); Ref<GIProbeData> get_probe_data() const; diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index b7cd9bd2dc..02d10523e7 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -248,7 +248,7 @@ void Light::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_SHADOW_SPLIT_3_OFFSET); BIND_ENUM_CONSTANT(PARAM_SHADOW_NORMAL_BIAS); BIND_ENUM_CONSTANT(PARAM_SHADOW_BIAS); - + BIND_ENUM_CONSTANT(PARAM_SHADOW_BIAS_SPLIT_SCALE); BIND_ENUM_CONSTANT(PARAM_MAX); } @@ -369,12 +369,6 @@ DirectionalLight::DirectionalLight() set_shadow_depth_range(SHADOW_DEPTH_RANGE_STABLE); blend_splits = false; - -#ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint()) - // Create light with a default natural "sun" orientation in editor, instead of looking horizontally on X - set_rotation_in_degrees(Vector3(-50, 25, 30)); -#endif } void OmniLight::set_shadow_mode(ShadowMode p_mode) { diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp index 73749cacb3..4e19214c59 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/particles.cpp @@ -585,298 +585,294 @@ void ParticlesMaterial::_update_shader() { //need a random function code += "\n\n"; code += "float rand_from_seed(inout uint seed) {\n"; - code += " int k;\n"; - code += " int s = int(seed);\n"; - code += " if (s == 0)\n"; + code += " int k;\n"; + code += " int s = int(seed);\n"; + code += " if (s == 0)\n"; code += " s = 305420679;\n"; - code += " k = s / 127773;\n"; - code += " s = 16807 * (s - k * 127773) - 2836 * k;\n"; - code += " if (s < 0)\n"; - code += " s += 2147483647;\n"; - code += " seed = uint(s);\n"; - code += " return float(seed % uint(65536))/65535.0;\n"; + code += " k = s / 127773;\n"; + code += " s = 16807 * (s - k * 127773) - 2836 * k;\n"; + code += " if (s < 0)\n"; + code += " s += 2147483647;\n"; + code += " seed = uint(s);\n"; + code += " return float(seed % uint(65536))/65535.0;\n"; code += "}\n"; + code += "\n"; + //improve seed quality code += "uint hash(uint x) {\n"; - code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n"; - code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n"; - code += " x = (x >> uint(16)) ^ x;\n"; - code += " return x;\n"; + code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n"; + code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n"; + code += " x = (x >> uint(16)) ^ x;\n"; + code += " return x;\n"; code += "}\n"; - code += "void vertex() {\n\n"; code += "\n"; - code += " uint base_number=NUMBER/uint(trail_divisor);\n"; - code += " uint alt_seed=hash(base_number+uint(1)+RANDOM_SEED);\n"; - code += " float angle_rand=rand_from_seed(alt_seed);\n"; - code += " float scale_rand=rand_from_seed(alt_seed);\n"; - code += " float hue_rot_rand=rand_from_seed(alt_seed);\n"; - code += " float anim_offset_rand=rand_from_seed(alt_seed);\n"; - code += "\n"; - code += "\n"; - code += "\n"; + code += "void vertex() {\n"; + code += " uint base_number = NUMBER/uint(trail_divisor);\n"; + code += " uint alt_seed = hash(base_number+uint(1)+RANDOM_SEED);\n"; + code += " float angle_rand = rand_from_seed(alt_seed);\n"; + code += " float scale_rand = rand_from_seed(alt_seed);\n"; + code += " float hue_rot_rand = rand_from_seed(alt_seed);\n"; + code += " float anim_offset_rand = rand_from_seed(alt_seed);\n"; code += "\n"; + if (emission_shape >= EMISSION_SHAPE_POINTS) { - code += " int point = min(emission_texture_point_count-1,int(rand_from_seed(alt_seed) * float(emission_texture_point_count)));\n"; - code += " ivec2 emission_tex_size = textureSize( emission_texture_points, 0 );\n"; - code += " ivec2 emission_tex_ofs = ivec2( point % emission_tex_size.x, point / emission_tex_size.x );\n"; + code += " int point = min(emission_texture_point_count-1,int(rand_from_seed(alt_seed) * float(emission_texture_point_count)));\n"; + code += " ivec2 emission_tex_size = textureSize( emission_texture_points, 0 );\n"; + code += " ivec2 emission_tex_ofs = ivec2( point % emission_tex_size.x, point / emission_tex_size.x );\n"; } - code += " if (RESTART) {\n"; + code += " if (RESTART) {\n"; if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) - code += " float tex_linear_velocity = textureLod(linear_velocity_texture,vec2(0.0,0.0),0.0).r;\n"; + code += " float tex_linear_velocity = textureLod(linear_velocity_texture,vec2(0.0,0.0),0.0).r;\n"; else - code += " float tex_linear_velocity = 0.0;\n"; + code += " float tex_linear_velocity = 0.0;\n"; if (tex_parameters[PARAM_ANGLE].is_valid()) - code += " float tex_angle = textureLod(angle_texture,vec2(0.0,0.0),0.0).r;\n"; + code += " float tex_angle = textureLod(angle_texture,vec2(0.0,0.0),0.0).r;\n"; else - code += " float tex_angle = 0.0;\n"; + code += " float tex_angle = 0.0;\n"; if (tex_parameters[PARAM_ANIM_OFFSET].is_valid()) - code += " float tex_anim_offset = textureLod(anim_offset_texture,vec2(0.0,0.0),0.0).r;\n"; + code += " float tex_anim_offset = textureLod(anim_offset_texture,vec2(0.0,0.0),0.0).r;\n"; else - code += " float tex_anim_offset = 0.0;\n"; + code += " float tex_anim_offset = 0.0;\n"; if (flags[FLAG_DISABLE_Z]) { - code += " float angle1 = (rand_from_seed(alt_seed)*2.0-1.0)*spread/180.0*3.1416;\n"; - code += " vec3 rot=vec3( cos(angle1), sin(angle1),0.0 );\n"; - code += " VELOCITY=(rot*initial_linear_velocity+rot*initial_linear_velocity_random*rand_from_seed(alt_seed));\n"; + code += " float angle1 = (rand_from_seed(alt_seed)*2.0-1.0)*spread/180.0*3.1416;\n"; + code += " vec3 rot = vec3( cos(angle1), sin(angle1),0.0 );\n"; + code += " VELOCITY = (rot*initial_linear_velocity+rot*initial_linear_velocity_random*rand_from_seed(alt_seed));\n"; } else { //initiate velocity spread in 3D - code += " float angle1 = rand_from_seed(alt_seed)*spread*3.1416;\n"; - code += " float angle2 = rand_from_seed(alt_seed)*20.0*3.1416; // make it more random like\n"; - code += " vec3 rot_xz=vec3( sin(angle1), 0.0, cos(angle1) );\n"; - code += " vec3 rot = vec3( cos(angle2)*rot_xz.x,sin(angle2)*rot_xz.x, rot_xz.z);\n"; - code += " VELOCITY=(rot*initial_linear_velocity+rot*initial_linear_velocity_random*rand_from_seed(alt_seed));\n"; + code += " float angle1 = rand_from_seed(alt_seed)*spread*3.1416;\n"; + code += " float angle2 = rand_from_seed(alt_seed)*20.0*3.1416; // make it more random like\n"; + code += " vec3 rot_xz = vec3( sin(angle1), 0.0, cos(angle1) );\n"; + code += " vec3 rot = vec3( cos(angle2)*rot_xz.x,sin(angle2)*rot_xz.x, rot_xz.z);\n"; + code += " VELOCITY = (rot*initial_linear_velocity+rot*initial_linear_velocity_random*rand_from_seed(alt_seed));\n"; } - code += " float base_angle=(initial_angle+tex_angle)*mix(1.0,angle_rand,initial_angle_random);\n"; - code += " CUSTOM.x=base_angle*3.1416/180.0;\n"; //angle - code += " CUSTOM.y=0.0;\n"; //phase - code += " CUSTOM.z=(anim_offset+tex_anim_offset)*mix(1.0,anim_offset_rand,anim_offset_random);\n"; //animation offset (0-1) + code += " float base_angle = (initial_angle+tex_angle)*mix(1.0,angle_rand,initial_angle_random);\n"; + code += " CUSTOM.x = base_angle*3.1416/180.0;\n"; //angle + code += " CUSTOM.y = 0.0;\n"; //phase + 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) { case EMISSION_SHAPE_POINT: { //do none } break; case EMISSION_SHAPE_SPHERE: { - code += " TRANSFORM[3].xyz = normalize(vec3(rand_from_seed(alt_seed) * 2.0 - 1.0, rand_from_seed(alt_seed) * 2.0-1.0, rand_from_seed(alt_seed) * 2.0-1.0 ))*emission_sphere_radius;\n"; + code += " TRANSFORM[3].xyz = normalize(vec3(rand_from_seed(alt_seed) * 2.0 - 1.0, rand_from_seed(alt_seed) * 2.0-1.0, rand_from_seed(alt_seed) * 2.0-1.0 ))*emission_sphere_radius;\n"; } break; case EMISSION_SHAPE_BOX: { - code += " TRANSFORM[3].xyz = vec3(rand_from_seed(alt_seed) * 2.0 - 1.0, rand_from_seed(alt_seed) * 2.0-1.0, rand_from_seed(alt_seed) * 2.0-1.0)*emission_box_extents;\n"; + code += " TRANSFORM[3].xyz = vec3(rand_from_seed(alt_seed) * 2.0 - 1.0, rand_from_seed(alt_seed) * 2.0-1.0, rand_from_seed(alt_seed) * 2.0-1.0)*emission_box_extents;\n"; } break; case EMISSION_SHAPE_POINTS: case EMISSION_SHAPE_DIRECTED_POINTS: { - code += " TRANSFORM[3].xyz = texelFetch(emission_texture_points, emission_tex_ofs,0).xyz;\n"; + code += " TRANSFORM[3].xyz = texelFetch(emission_texture_points, emission_tex_ofs,0).xyz;\n"; if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) { if (flags[FLAG_DISABLE_Z]) { - code += " mat2 rotm;"; - code += " rotm[0]=texelFetch(emission_texture_normal, emission_tex_ofs,0).xy;\n"; - code += " rotm[1]=rotm[0].yx * vec2(1.0,-1.0);\n"; - code += " VELOCITY.xy = rotm * VELOCITY.xy;\n"; + code += " mat2 rotm;"; + code += " rotm[0] = texelFetch(emission_texture_normal, emission_tex_ofs,0).xy;\n"; + code += " rotm[1] = rotm[0].yx * vec2(1.0,-1.0);\n"; + code += " VELOCITY.xy = rotm * VELOCITY.xy;\n"; } else { - code += " vec3 normal = texelFetch(emission_texture_normal, emission_tex_ofs,0).xyz;\n"; - code += " vec3 v0 = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0, 1.0, 0.0);\n"; - code += " vec3 tangent = normalize(cross(v0, normal));\n"; - code += " vec3 bitangent = normalize(cross(tangent, normal));\n"; - code += " VELOCITY = mat3(tangent,bitangent,normal) * VELOCITY;\n"; + code += " vec3 normal = texelFetch(emission_texture_normal, emission_tex_ofs,0).xyz;\n"; + code += " vec3 v0 = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0, 1.0, 0.0);\n"; + code += " vec3 tangent = normalize(cross(v0, normal));\n"; + code += " vec3 bitangent = normalize(cross(tangent, normal));\n"; + code += " VELOCITY = mat3(tangent,bitangent,normal) * VELOCITY;\n"; } } } break; } - code += " VELOCITY = (EMISSION_TRANSFORM * vec4(VELOCITY,0.0)).xyz;\n"; - code += " TRANSFORM = EMISSION_TRANSFORM * TRANSFORM;\n"; + code += " VELOCITY = (EMISSION_TRANSFORM * vec4(VELOCITY,0.0)).xyz;\n"; + code += " TRANSFORM = EMISSION_TRANSFORM * TRANSFORM;\n"; if (flags[FLAG_DISABLE_Z]) { - code += " VELOCITY.z=0.0;\n"; - code += " TRANSFORM[3].z=0.0;\n"; + code += " VELOCITY.z = 0.0;\n"; + code += " TRANSFORM[3].z = 0.0;\n"; } - code += " } else {\n"; + code += " } else {\n"; - code += " CUSTOM.y+=DELTA/LIFETIME;\n"; + code += " CUSTOM.y += DELTA/LIFETIME;\n"; if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) - code += " float tex_linear_velocity = textureLod(linear_velocity_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; + code += " float tex_linear_velocity = textureLod(linear_velocity_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; else - code += " float tex_linear_velocity = 0.0;\n"; + code += " float tex_linear_velocity = 0.0;\n"; if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid()) - code += " float tex_orbit_velocity = textureLod(orbit_velocity_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; + code += " float tex_orbit_velocity = textureLod(orbit_velocity_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; else - code += " float tex_orbit_velocity = 0.0;\n"; + code += " float tex_orbit_velocity = 0.0;\n"; if (tex_parameters[PARAM_ANGULAR_VELOCITY].is_valid()) - code += " float tex_angular_velocity = textureLod(angular_velocity_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; + code += " float tex_angular_velocity = textureLod(angular_velocity_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; else - code += " float tex_angular_velocity = 0.0;\n"; + code += " float tex_angular_velocity = 0.0;\n"; if (tex_parameters[PARAM_LINEAR_ACCEL].is_valid()) - code += " float tex_linear_accel = textureLod(linear_accel_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; + code += " float tex_linear_accel = textureLod(linear_accel_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; else - code += " float tex_linear_accel = 0.0;\n"; + code += " float tex_linear_accel = 0.0;\n"; if (tex_parameters[PARAM_RADIAL_ACCEL].is_valid()) - code += " float tex_radial_accel = textureLod(radial_accel_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; + code += " float tex_radial_accel = textureLod(radial_accel_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; else - code += " float tex_radial_accel = 0.0;\n"; + code += " float tex_radial_accel = 0.0;\n"; if (tex_parameters[PARAM_TANGENTIAL_ACCEL].is_valid()) - code += " float tex_tangent_accel = textureLod(tangent_accel_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; + code += " float tex_tangent_accel = textureLod(tangent_accel_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; else - code += " float tex_tangent_accel = 0.0;\n"; + code += " float tex_tangent_accel = 0.0;\n"; if (tex_parameters[PARAM_DAMPING].is_valid()) - code += " float tex_damping = textureLod(damping_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; + code += " float tex_damping = textureLod(damping_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; else - code += " float tex_damping = 0.0;\n"; + code += " float tex_damping = 0.0;\n"; if (tex_parameters[PARAM_ANGLE].is_valid()) - code += " float tex_angle = textureLod(angle_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; + code += " float tex_angle = textureLod(angle_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; else - code += " float tex_angle = 0.0;\n"; + code += " float tex_angle = 0.0;\n"; if (tex_parameters[PARAM_ANIM_SPEED].is_valid()) - code += " float tex_anim_speed = textureLod(anim_speed_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; + code += " float tex_anim_speed = textureLod(anim_speed_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; else - code += " float tex_anim_speed = 0.0;\n"; + code += " float tex_anim_speed = 0.0;\n"; if (tex_parameters[PARAM_ANIM_OFFSET].is_valid()) - code += " float tex_anim_offset = textureLod(anim_offset_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; + code += " float tex_anim_offset = textureLod(anim_offset_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; else - code += " float tex_anim_offset = 0.0;\n"; + code += " float tex_anim_offset = 0.0;\n"; - code += " vec3 force = gravity; \n"; - code += " vec3 pos = TRANSFORM[3].xyz; \n"; + code += " vec3 force = gravity; \n"; + code += " vec3 pos = TRANSFORM[3].xyz; \n"; if (flags[FLAG_DISABLE_Z]) { - code += " pos.z=0.0; \n"; + code += " pos.z = 0.0; \n"; } - code += " //apply linear acceleration\n"; - code += " force+= length(VELOCITY) > 0.0 ? normalize(VELOCITY) * (linear_accel+tex_linear_accel)*mix(1.0,rand_from_seed(alt_seed),linear_accel_random) : vec3(0.0);\n"; - code += " //apply radial acceleration\n"; - code += " vec3 org = vec3(0.0);\n"; - code += " // if (!p_system->local_coordinates)\n"; - code += " //org=p_transform.origin;\n"; - code += " vec3 diff = pos-org;\n"; - code += " force+=length(diff) > 0.0 ? normalize(diff) * (radial_accel+tex_radial_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random) : vec3(0.0);\n"; - code += " //apply tangential acceleration;\n"; + code += " //apply linear acceleration\n"; + code += " force += length(VELOCITY) > 0.0 ? normalize(VELOCITY) * (linear_accel+tex_linear_accel)*mix(1.0,rand_from_seed(alt_seed),linear_accel_random) : vec3(0.0);\n"; + code += " //apply radial acceleration\n"; + code += " vec3 org = vec3(0.0);\n"; + code += " vec3 diff = pos-org;\n"; + code += " force += length(diff) > 0.0 ? normalize(diff) * (radial_accel+tex_radial_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random) : vec3(0.0);\n"; + code += " //apply tangential acceleration;\n"; if (flags[FLAG_DISABLE_Z]) { - code += " force+=length(diff.yx) > 0.0 ? vec3(normalize(diff.yx * vec2(-1.0,1.0)),0.0) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random)) : vec3(0.0);\n"; + code += " force += length(diff.yx) > 0.0 ? vec3(normalize(diff.yx * vec2(-1.0,1.0)),0.0) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random)) : vec3(0.0);\n"; } else { - code += " vec3 crossDiff = cross(normalize(diff),normalize(gravity));\n"; - code += " force+=length(crossDiff) > 0.0 ? normalize(crossDiff) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random)) : vec3(0.0);\n"; + code += " vec3 crossDiff = cross(normalize(diff),normalize(gravity));\n"; + code += " force += length(crossDiff) > 0.0 ? normalize(crossDiff) * ((tangent_accel+tex_tangent_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random)) : vec3(0.0);\n"; } - code += " //apply attractor forces\n"; - code += " VELOCITY+=force * DELTA;\n"; + code += " //apply attractor forces\n"; + code += " VELOCITY += force * DELTA;\n"; if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) { - code += " VELOCITY=normalize(VELOCITY)*tex_linear_velocity;\n"; + code += " VELOCITY = normalize(VELOCITY)*tex_linear_velocity;\n"; } - code += " if (damping+tex_damping>0.0) {\n"; - code += " \n"; - code += " float v = length(VELOCITY);\n"; - code += " float damp = (damping+tex_damping)*mix(1.0,rand_from_seed(alt_seed),damping_random);\n"; - code += " v -= damp * DELTA;\n"; - code += " if (v<0.0) {\n"; - code += " VELOCITY=vec3(0.0);\n"; - code += " } else {\n"; - code += " VELOCITY=normalize(VELOCITY) * v;\n"; - code += " }\n"; - code += " }\n"; - code += " float base_angle=(initial_angle+tex_angle)*mix(1.0,angle_rand,initial_angle_random);\n"; - code += " base_angle+=CUSTOM.y*LIFETIME*(angular_velocity+tex_angular_velocity)*mix(1.0,rand_from_seed(alt_seed)*2.0-1.0,angular_velocity_random);\n"; - code += " CUSTOM.x=base_angle*3.1416/180.0;\n"; //angle - code += " CUSTOM.z=(anim_offset+tex_anim_offset)*mix(1.0,anim_offset_rand,anim_offset_random)+CUSTOM.y*(anim_speed+tex_anim_speed)*mix(1.0,rand_from_seed(alt_seed),anim_speed_random);\n"; //angle + code += " if (damping + tex_damping > 0.0) {\n"; + code += " \n"; + code += " float v = length(VELOCITY);\n"; + code += " float damp = (damping+tex_damping)*mix(1.0,rand_from_seed(alt_seed),damping_random);\n"; + code += " v -= damp * DELTA;\n"; + code += " if (v < 0.0) {\n"; + code += " VELOCITY = vec3(0.0);\n"; + code += " } else {\n"; + code += " VELOCITY = normalize(VELOCITY) * v;\n"; + code += " }\n"; + code += " }\n"; + code += " float base_angle = (initial_angle+tex_angle)*mix(1.0,angle_rand,initial_angle_random);\n"; + code += " base_angle += CUSTOM.y*LIFETIME*(angular_velocity+tex_angular_velocity)*mix(1.0,rand_from_seed(alt_seed)*2.0-1.0,angular_velocity_random);\n"; + code += " CUSTOM.x = base_angle*3.1416/180.0;\n"; //angle + code += " CUSTOM.z = (anim_offset+tex_anim_offset)*mix(1.0,anim_offset_rand,anim_offset_random)+CUSTOM.y*(anim_speed+tex_anim_speed)*mix(1.0,rand_from_seed(alt_seed),anim_speed_random);\n"; //angle if (flags[FLAG_ANIM_LOOP]) { - code += " CUSTOM.z=mod(CUSTOM.z,1.0);\n"; //loop + code += " CUSTOM.z = mod(CUSTOM.z,1.0);\n"; //loop } else { - code += " CUSTOM.z=clamp(CUSTOM.z,0.0,1.0);\n"; //0 to 1 only + code += " CUSTOM.z = clamp(CUSTOM.z,0.0,1.0);\n"; //0 to 1 only } - code += " }\n"; + code += " }\n"; //apply color //apply hue rotation if (tex_parameters[PARAM_SCALE].is_valid()) - code += " float tex_scale = textureLod(scale_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; + code += " float tex_scale = textureLod(scale_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; else - code += " float tex_scale = 1.0;\n"; + code += " float tex_scale = 1.0;\n"; if (tex_parameters[PARAM_HUE_VARIATION].is_valid()) - code += " float tex_hue_variation = textureLod(hue_variation_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; + code += " float tex_hue_variation = textureLod(hue_variation_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; else - code += " float tex_hue_variation = 0.0;\n"; - - code += " float hue_rot_angle = (hue_variation+tex_hue_variation)*3.1416*2.0*mix(1.0,hue_rot_rand*2.0-1.0,hue_variation_random);\n"; - code += " float hue_rot_c = cos(hue_rot_angle);\n"; - code += " float hue_rot_s = sin(hue_rot_angle);\n"; - code += " mat4 hue_rot_mat = mat4( vec4(0.299, 0.587, 0.114, 0.0),\n"; - code += " vec4(0.299, 0.587, 0.114, 0.0),\n"; - code += " vec4(0.299, 0.587, 0.114, 0.0),\n"; - code += " vec4(0.000, 0.000, 0.000, 1.0)) +\n"; - code += " \n"; - code += " mat4( vec4(0.701, -0.587, -0.114, 0.0),\n"; - code += " vec4(-0.299, 0.413, -0.114, 0.0),\n"; - code += " vec4(-0.300, -0.588, 0.886, 0.0),\n"; - code += " vec4(0.000, 0.000, 0.000, 0.0)) * hue_rot_c +\n"; - code += "\n"; - code += " mat4( vec4(0.168, 0.330, -0.497, 0.0),\n"; - code += " vec4(-0.328, 0.035, 0.292, 0.0),\n"; - code += " vec4(1.250, -1.050, -0.203, 0.0),\n"; - code += " vec4(0.000, 0.000, 0.000, 0.0)) * hue_rot_s;\n"; + code += " float tex_hue_variation = 0.0;\n"; + + code += " float hue_rot_angle = (hue_variation+tex_hue_variation)*3.1416*2.0*mix(1.0,hue_rot_rand*2.0-1.0,hue_variation_random);\n"; + code += " float hue_rot_c = cos(hue_rot_angle);\n"; + code += " float hue_rot_s = sin(hue_rot_angle);\n"; + code += " mat4 hue_rot_mat = mat4( vec4(0.299, 0.587, 0.114, 0.0),\n"; + code += " vec4(0.299, 0.587, 0.114, 0.0),\n"; + code += " vec4(0.299, 0.587, 0.114, 0.0),\n"; + code += " vec4(0.000, 0.000, 0.000, 1.0)) +\n"; + code += " mat4( vec4(0.701, -0.587, -0.114, 0.0),\n"; + code += " vec4(-0.299, 0.413, -0.114, 0.0),\n"; + code += " vec4(-0.300, -0.588, 0.886, 0.0),\n"; + code += " vec4(0.000, 0.000, 0.000, 0.0)) * hue_rot_c +\n"; + code += " mat4( vec4(0.168, 0.330, -0.497, 0.0),\n"; + code += " vec4(-0.328, 0.035, 0.292, 0.0),\n"; + code += " vec4(1.250, -1.050, -0.203, 0.0),\n"; + code += " vec4(0.000, 0.000, 0.000, 0.0)) * hue_rot_s;\n"; if (color_ramp.is_valid()) { - code += " COLOR = textureLod(color_ramp,vec2(CUSTOM.y,0.0),0.0) * hue_rot_mat;\n"; + code += " COLOR = textureLod(color_ramp,vec2(CUSTOM.y,0.0),0.0) * hue_rot_mat;\n"; } else { - code += " COLOR = color_value * hue_rot_mat;\n"; + code += " COLOR = color_value * hue_rot_mat;\n"; } if (emission_color_texture.is_valid() && emission_shape >= EMISSION_SHAPE_POINTS) { - code += " COLOR*= texelFetch(emission_texture_color,emission_tex_ofs,0);\n"; + code += " COLOR*= texelFetch(emission_texture_color,emission_tex_ofs,0);\n"; } if (trail_color_modifier.is_valid()) { - code += "if (trail_divisor>1) { COLOR*=textureLod(trail_color_modifier,vec2(float(int(NUMBER)%trail_divisor)/float(trail_divisor-1),0.0),0.0); }\n"; + code += " if (trail_divisor > 1) { COLOR *= textureLod(trail_color_modifier,vec2(float(int(NUMBER)%trail_divisor)/float(trail_divisor-1),0.0),0.0); }\n"; } code += "\n"; if (flags[FLAG_DISABLE_Z]) { - code += " TRANSFORM[0]=vec4(cos(CUSTOM.x),-sin(CUSTOM.x),0.0,0.0);\n"; - code += " TRANSFORM[1]=vec4(sin(CUSTOM.x),cos(CUSTOM.x),0.0,0.0);\n"; - code += " TRANSFORM[2]=vec4(0.0,0.0,1.0,0.0);\n"; + code += " TRANSFORM[0] = vec4(cos(CUSTOM.x),-sin(CUSTOM.x),0.0,0.0);\n"; + code += " TRANSFORM[1] = vec4(sin(CUSTOM.x),cos(CUSTOM.x),0.0,0.0);\n"; + code += " TRANSFORM[2] = vec4(0.0,0.0,1.0,0.0);\n"; } else { //orient particle Y towards velocity if (flags[FLAG_ALIGN_Y_TO_VELOCITY]) { - code += " if (length(VELOCITY)>0.0) {TRANSFORM[1].xyz=normalize(VELOCITY);} else {TRANSFORM[1].xyz=normalize(TRANSFORM[1].xyz);}\n"; - code += " if (TRANSFORM[1].xyz==normalize(TRANSFORM[0].xyz)) {\n"; - code += "\tTRANSFORM[0].xyz=normalize(cross(normalize(TRANSFORM[1].xyz),normalize(TRANSFORM[2].xyz)));\n"; - code += "\tTRANSFORM[2].xyz=normalize(cross(normalize(TRANSFORM[0].xyz),normalize(TRANSFORM[1].xyz)));\n"; - code += " } else {\n"; - code += "\tTRANSFORM[2].xyz=normalize(cross(normalize(TRANSFORM[0].xyz),normalize(TRANSFORM[1].xyz)));\n"; - code += "\tTRANSFORM[0].xyz=normalize(cross(normalize(TRANSFORM[1].xyz),normalize(TRANSFORM[2].xyz)));\n"; - code += " }\n"; + code += " if (length(VELOCITY) > 0.0) { TRANSFORM[1].xyz = normalize(VELOCITY); } else { TRANSFORM[1].xyz = normalize(TRANSFORM[1].xyz); }\n"; + code += " if (TRANSFORM[1].xyz == normalize(TRANSFORM[0].xyz)) {\n"; + code += " TRANSFORM[0].xyz = normalize(cross(normalize(TRANSFORM[1].xyz),normalize(TRANSFORM[2].xyz)));\n"; + code += " TRANSFORM[2].xyz = normalize(cross(normalize(TRANSFORM[0].xyz),normalize(TRANSFORM[1].xyz)));\n"; + code += " } else {\n"; + code += " TRANSFORM[2].xyz = normalize(cross(normalize(TRANSFORM[0].xyz),normalize(TRANSFORM[1].xyz)));\n"; + code += " TRANSFORM[0].xyz = normalize(cross(normalize(TRANSFORM[1].xyz),normalize(TRANSFORM[2].xyz)));\n"; + code += " }\n"; } else { - code += "\tTRANSFORM[0].xyz=normalize(TRANSFORM[0].xyz);\n"; - code += "\tTRANSFORM[1].xyz=normalize(TRANSFORM[1].xyz);\n"; - code += "\tTRANSFORM[2].xyz=normalize(TRANSFORM[2].xyz);\n"; + code += " TRANSFORM[0].xyz = normalize(TRANSFORM[0].xyz);\n"; + code += " TRANSFORM[1].xyz = normalize(TRANSFORM[1].xyz);\n"; + code += " TRANSFORM[2].xyz = normalize(TRANSFORM[2].xyz);\n"; } //turn particle by rotation in Y if (flags[FLAG_ROTATE_Y]) { - code += "\tTRANSFORM = TRANSFORM * mat4( vec4(cos(CUSTOM.x),0.0,-sin(CUSTOM.x),0.0), vec4(0.0,1.0,0.0,0.0),vec4(sin(CUSTOM.x),0.0,cos(CUSTOM.x),0.0),vec4(0.0,0.0,0.0,1.0));\n"; + code += " TRANSFORM = TRANSFORM * mat4( vec4(cos(CUSTOM.x),0.0,-sin(CUSTOM.x),0.0), vec4(0.0,1.0,0.0,0.0),vec4(sin(CUSTOM.x),0.0,cos(CUSTOM.x),0.0),vec4(0.0,0.0,0.0,1.0));\n"; } } //scale by scale - code += " float base_scale=mix(scale*tex_scale,1.0,scale_random*scale_rand);\n"; + code += " float base_scale = mix(scale*tex_scale,1.0,scale_random*scale_rand);\n"; if (trail_size_modifier.is_valid()) { - code += "if (trail_divisor>1) { base_scale*=textureLod(trail_size_modifier,vec2(float(int(NUMBER)%trail_divisor)/float(trail_divisor-1),0.0),0.0).r; } \n"; + code += " if (trail_divisor > 1) { base_scale *= textureLod(trail_size_modifier,vec2(float(int(NUMBER)%trail_divisor)/float(trail_divisor-1),0.0),0.0).r; } \n"; } - code += " TRANSFORM[0].xyz*=base_scale;\n"; - code += " TRANSFORM[1].xyz*=base_scale;\n"; - code += " TRANSFORM[2].xyz*=base_scale;\n"; + code += " TRANSFORM[0].xyz *= base_scale;\n"; + code += " TRANSFORM[1].xyz *= base_scale;\n"; + code += " TRANSFORM[2].xyz *= base_scale;\n"; if (flags[FLAG_DISABLE_Z]) { - code += " VELOCITY.z=0.0;\n"; - code += " TRANSFORM[3].z=0.0;\n"; + code += " VELOCITY.z = 0.0;\n"; + code += " TRANSFORM[3].z = 0.0;\n"; } code += "}\n"; code += "\n"; @@ -1325,6 +1321,12 @@ Vector3 ParticlesMaterial::get_gravity() const { return gravity; } +RID ParticlesMaterial::get_shader_rid() const { + + ERR_FAIL_COND_V(!shader_map.has(current_key), RID()); + return shader_map[current_key].shader; +} + void ParticlesMaterial::_validate_property(PropertyInfo &property) const { if (property.name == "color" && color_ramp.is_valid()) { diff --git a/scene/3d/particles.h b/scene/3d/particles.h index 2c109d6ec8..e3109f470f 100644 --- a/scene/3d/particles.h +++ b/scene/3d/particles.h @@ -388,6 +388,8 @@ public: static void finish_shaders(); static void flush_changes(); + RID get_shader_rid() const; + ParticlesMaterial(); ~ParticlesMaterial(); }; diff --git a/scene/3d/path.cpp b/scene/3d/path.cpp index 60245fe6ce..65f20210e1 100644 --- a/scene/3d/path.cpp +++ b/scene/3d/path.cpp @@ -85,9 +85,15 @@ void PathFollow::_update_transform() { if (!c.is_valid()) return; + if (delta_offset == 0) { + return; + } + float o = offset; - if (loop) + + if (loop) { o = Math::fposmod(o, c->get_baked_length()); + } Vector3 pos = c->interpolate_baked(o, cubic); Transform t = get_transform(); @@ -101,14 +107,14 @@ void PathFollow::_update_transform() { // see C. Dougan, The Parallel Transport Frame, Game Programming Gems 2 for example // for a discussion about why not Frenet frame. - Vector3 t_prev = pos - c->interpolate_baked(o - lookahead, cubic); - Vector3 t_cur = c->interpolate_baked(o + lookahead, cubic) - 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 axis = t_prev.cross(t_cur); - float dot = t_prev.normalized().dot(t_cur.normalized()); + float dot = t_prev.dot(t_cur); float angle = Math::acos(CLAMP(dot, -1, 1)); - if (axis.length() > CMP_EPSILON && angle > CMP_EPSILON) { + if (likely(Math::abs(angle) > CMP_EPSILON)) { if (rotation_mode == ROTATION_Y) { // assuming we're referring to global Y-axis. is this correct? axis.x = 0; @@ -116,27 +122,31 @@ void PathFollow::_update_transform() { } else if (rotation_mode == ROTATION_XY) { axis.z = 0; } else if (rotation_mode == ROTATION_XYZ) { - // all components are OK + // all components are allowed } - t.rotate_basis(axis.normalized(), angle); + if (likely(axis.length() > CMP_EPSILON)) { + t.rotate_basis(axis.normalized(), angle); + } } // do the additional tilting float tilt_angle = c->interpolate_baked_tilt(o); - Vector3 tilt_axis = t_cur; // is this correct?? + Vector3 tilt_axis = t_cur; // not sure what tilt is supposed to do, is this correct?? - if (tilt_axis.length() > CMP_EPSILON && tilt_angle > CMP_EPSILON) { + if (likely(Math::abs(tilt_angle) > CMP_EPSILON)) { if (rotation_mode == ROTATION_Y) { tilt_axis.x = 0; tilt_axis.z = 0; } else if (rotation_mode == ROTATION_XY) { tilt_axis.z = 0; } else if (rotation_mode == ROTATION_XYZ) { - // all components are OK + // all components are allowed } - t.rotate_basis(tilt_axis.normalized(), tilt_angle); + if (likely(tilt_axis.length() > CMP_EPSILON)) { + t.rotate_basis(tilt_axis.normalized(), tilt_angle); + } } t.translate(pos_offset); @@ -195,8 +205,6 @@ bool PathFollow::_set(const StringName &p_name, const Variant &p_value) { set_cubic_interpolation(p_value); } else if (String(p_name) == "loop") { set_loop(p_value); - } else if (String(p_name) == "lookahead") { - set_lookahead(p_value); } else return false; @@ -219,8 +227,6 @@ bool PathFollow::_get(const StringName &p_name, Variant &r_ret) const { r_ret = cubic; } else if (String(p_name) == "loop") { r_ret = loop; - } else if (String(p_name) == "lookahead") { - r_ret = lookahead; } else return false; @@ -238,7 +244,6 @@ void PathFollow::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::INT, "rotation_mode", PROPERTY_HINT_ENUM, "None,Y,XY,XYZ")); p_list->push_back(PropertyInfo(Variant::BOOL, "cubic_interp")); p_list->push_back(PropertyInfo(Variant::BOOL, "loop")); - p_list->push_back(PropertyInfo(Variant::REAL, "lookahead", PROPERTY_HINT_RANGE, "0.001,1024.0,0.001")); } void PathFollow::_bind_methods() { @@ -271,8 +276,9 @@ void PathFollow::_bind_methods() { } void PathFollow::set_offset(float p_offset) { - + delta_offset = p_offset - offset; offset = p_offset; + if (path) _update_transform(); _change_notify("offset"); @@ -322,16 +328,6 @@ float PathFollow::get_unit_offset() const { return 0; } -void PathFollow::set_lookahead(float p_lookahead) { - - lookahead = p_lookahead; -} - -float PathFollow::get_lookahead() const { - - return lookahead; -} - void PathFollow::set_rotation_mode(RotationMode p_rotation_mode) { rotation_mode = p_rotation_mode; @@ -356,11 +352,11 @@ bool PathFollow::has_loop() const { PathFollow::PathFollow() { offset = 0; + delta_offset = 0; h_offset = 0; v_offset = 0; path = NULL; rotation_mode = ROTATION_XYZ; cubic = true; loop = true; - lookahead = 0.1; } diff --git a/scene/3d/path.h b/scene/3d/path.h index 0f9a169f72..52760e0c75 100644 --- a/scene/3d/path.h +++ b/scene/3d/path.h @@ -67,10 +67,10 @@ public: private: Path *path; + real_t delta_offset; // change in offset since last _update_transform real_t offset; real_t h_offset; real_t v_offset; - real_t lookahead; bool cubic; bool loop; RotationMode rotation_mode; @@ -98,9 +98,6 @@ public: void set_unit_offset(float p_unit_offset); float get_unit_offset() const; - void set_lookahead(float p_lookahead); - float get_lookahead() const; - void set_loop(bool p_loop); bool has_loop() const; diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index d7fdf94d40..4c661e6a88 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -870,10 +870,10 @@ void RigidBody::_bind_methods() { ADD_SIGNAL(MethodInfo("body_exited", PropertyInfo(Variant::OBJECT, "body"))); ADD_SIGNAL(MethodInfo("sleeping_state_changed")); - BIND_ENUM_CONSTANT(MODE_STATIC); - BIND_ENUM_CONSTANT(MODE_KINEMATIC); BIND_ENUM_CONSTANT(MODE_RIGID); + BIND_ENUM_CONSTANT(MODE_STATIC); BIND_ENUM_CONSTANT(MODE_CHARACTER); + BIND_ENUM_CONSTANT(MODE_KINEMATIC); BIND_ENUM_CONSTANT(AXIS_LOCK_DISABLED); BIND_ENUM_CONSTANT(AXIS_LOCK_X); diff --git a/scene/3d/physics_joint.cpp b/scene/3d/physics_joint.cpp index aa127ab79f..1d779d31fe 100644 --- a/scene/3d/physics_joint.cpp +++ b/scene/3d/physics_joint.cpp @@ -32,13 +32,8 @@ void Joint::_update_joint(bool p_only_free) { if (joint.is_valid()) { - if (ba.is_valid() && bb.is_valid()) { - - if (exclude_from_collision) - PhysicsServer::get_singleton()->body_add_collision_exception(ba, bb); - else - PhysicsServer::get_singleton()->body_remove_collision_exception(ba, bb); - } + if (ba.is_valid() && bb.is_valid()) + PhysicsServer::get_singleton()->body_remove_collision_exception(ba, bb); PhysicsServer::get_singleton()->free(joint); joint = RID(); @@ -52,33 +47,31 @@ void Joint::_update_joint(bool p_only_free) { Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL; Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL; - if (!node_a && !node_b) + if (!node_a || !node_b) return; PhysicsBody *body_a = Object::cast_to<PhysicsBody>(node_a); PhysicsBody *body_b = Object::cast_to<PhysicsBody>(node_b); - if (!body_a && !body_b) + if (!body_a || !body_b) return; if (!body_a) { SWAP(body_a, body_b); - } else if (body_b) { - //add a collision exception between both - PhysicsServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid()); } joint = _configure_joint(body_a, body_b); - if (joint.is_valid()) - PhysicsServer::get_singleton()->joint_set_solver_priority(joint, solver_priority); + if (!joint.is_valid()) + return; + + PhysicsServer::get_singleton()->joint_set_solver_priority(joint, solver_priority); - if (body_b && joint.is_valid()) { + ba = body_a->get_rid(); + bb = body_b->get_rid(); - ba = body_a->get_rid(); - bb = body_b->get_rid(); + if (exclude_from_collision) PhysicsServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid()); - } } void Joint::set_node_a(const NodePath &p_node_a) { @@ -129,8 +122,6 @@ void Joint::_notification(int p_what) { case NOTIFICATION_EXIT_TREE: { if (joint.is_valid()) { _update_joint(true); - //PhysicsServer::get_singleton()->free(joint); - joint = RID(); } } break; } diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp index df6764ee1a..9f61cc64ea 100644 --- a/scene/3d/ray_cast.cpp +++ b/scene/3d/ray_cast.cpp @@ -48,14 +48,14 @@ Vector3 RayCast::get_cast_to() const { return cast_to; } -void RayCast::set_collision_layer(uint32_t p_layer) { +void RayCast::set_collision_mask(uint32_t p_mask) { - collision_layer = p_layer; + collision_mask = p_mask; } -uint32_t RayCast::get_collision_layer() const { +uint32_t RayCast::get_collision_mask() const { - return collision_layer; + return collision_mask; } void RayCast::set_type_mask(uint32_t p_mask) { @@ -63,6 +63,21 @@ void RayCast::set_type_mask(uint32_t p_mask) { type_mask = p_mask; } +void RayCast::set_collision_mask_bit(int p_bit, bool p_value) { + + uint32_t mask = get_collision_mask(); + if (p_value) + mask |= 1 << p_bit; + else + mask &= ~(1 << p_bit); + set_collision_mask(mask); +} + +bool RayCast::get_collision_mask_bit(int p_bit) const { + + return get_collision_mask() & (1 << p_bit); +} + uint32_t RayCast::get_type_mask() const { return type_mask; @@ -172,7 +187,7 @@ void RayCast::_update_raycast_state() { PhysicsDirectSpaceState::RayResult rr; - if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_layer, type_mask)) { + if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask, type_mask)) { collided = true; against = rr.collider_id; @@ -245,15 +260,18 @@ void RayCast::_bind_methods() { ClassDB::bind_method(D_METHOD("clear_exceptions"), &RayCast::clear_exceptions); - ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &RayCast::set_collision_layer); - ClassDB::bind_method(D_METHOD("get_collision_layer"), &RayCast::get_collision_layer); + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &RayCast::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &RayCast::get_collision_mask); + + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &RayCast::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &RayCast::get_collision_mask_bit); ClassDB::bind_method(D_METHOD("set_type_mask", "mask"), &RayCast::set_type_mask); ClassDB::bind_method(D_METHOD("get_type_mask"), &RayCast::get_type_mask); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "cast_to"), "set_cast_to", "get_cast_to"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); ADD_PROPERTY(PropertyInfo(Variant::INT, "type_mask", PROPERTY_HINT_FLAGS, "Static,Kinematic,Rigid,Character,Area"), "set_type_mask", "get_type_mask"); } @@ -325,7 +343,7 @@ RayCast::RayCast() { against = 0; collided = false; against_shape = 0; - collision_layer = 1; + collision_mask = 1; type_mask = PhysicsDirectSpaceState::TYPE_MASK_COLLISION; cast_to = Vector3(0, -1, 0); debug_shape = NULL; diff --git a/scene/3d/ray_cast.h b/scene/3d/ray_cast.h index fd566cd343..cac1596264 100644 --- a/scene/3d/ray_cast.h +++ b/scene/3d/ray_cast.h @@ -47,7 +47,7 @@ class RayCast : public Spatial { Set<RID> exclude; - uint32_t collision_layer; + uint32_t collision_mask; uint32_t type_mask; Node *debug_shape; @@ -69,8 +69,11 @@ public: void set_cast_to(const Vector3 &p_point); Vector3 get_cast_to() const; - void set_collision_layer(uint32_t p_layer); - uint32_t get_collision_layer() const; + void set_collision_mask(uint32_t p_mask); + uint32_t get_collision_mask() const; + + void set_collision_mask_bit(int p_bit, bool p_value); + bool get_collision_mask_bit(int p_bit) const; void set_type_mask(uint32_t p_mask); uint32_t get_type_mask() const; diff --git a/scene/3d/visibility_notifier.cpp b/scene/3d/visibility_notifier.cpp index d3203bacec..e60b32a92a 100644 --- a/scene/3d/visibility_notifier.cpp +++ b/scene/3d/visibility_notifier.cpp @@ -252,8 +252,8 @@ void VisibilityEnabler::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "pause_animations"), "set_enabler", "is_enabler_enabled", ENABLER_PAUSE_ANIMATIONS); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "freeze_bodies"), "set_enabler", "is_enabler_enabled", ENABLER_FREEZE_BODIES); - BIND_ENUM_CONSTANT(ENABLER_FREEZE_BODIES); BIND_ENUM_CONSTANT(ENABLER_PAUSE_ANIMATIONS); + BIND_ENUM_CONSTANT(ENABLER_FREEZE_BODIES); BIND_ENUM_CONSTANT(ENABLER_MAX); } diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index c4cfce5d72..80b7748078 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -202,7 +202,6 @@ void AnimationPlayer::_notification(int p_what) { if (!Engine::get_singleton()->is_editor_hint() && animation_set.has(autoplay)) { play(autoplay); - set_autoplay(""); //this line is the fix for autoplay issues with animatio _animation_process(0); } } break; @@ -405,6 +404,10 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float if (a->value_track_get_update_mode(i) == Animation::UPDATE_CONTINUOUS || (p_delta == 0 && a->value_track_get_update_mode(i) == Animation::UPDATE_DISCRETE)) { //delta == 0 means seek Variant value = a->value_track_interpolate(i, p_time); + + if (value == Variant()) + continue; + //thanks to trigger mode, this should be solved now.. /* if (p_delta==0 && value.get_type()==Variant::STRING) @@ -1254,7 +1257,7 @@ void AnimationPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("advance", "delta"), &AnimationPlayer::advance); ADD_GROUP("Playback Options", "playback_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), "set_animation_process_mode", "get_animation_process_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_animation_process_mode", "get_animation_process_mode"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "playback_default_blend_time", PROPERTY_HINT_RANGE, "0,4096,0.01"), "set_default_blend_time", "get_default_blend_time"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_node"), "set_root", "get_root"); diff --git a/scene/animation/animation_tree_player.cpp b/scene/animation/animation_tree_player.cpp index d564671bcf..ad5329c94b 100644 --- a/scene/animation/animation_tree_player.cpp +++ b/scene/animation/animation_tree_player.cpp @@ -1796,7 +1796,7 @@ void AnimationTreePlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("recompute_caches"), &AnimationTreePlayer::recompute_caches); ADD_GROUP("Playback", "playback_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), "set_animation_process_mode", "get_animation_process_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_animation_process_mode", "get_animation_process_mode"); BIND_ENUM_CONSTANT(NODE_OUTPUT); BIND_ENUM_CONSTANT(NODE_ANIMATION); diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index fb327191b9..e0508cf147 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -222,7 +222,7 @@ void Tween::_bind_methods() { ADD_SIGNAL(MethodInfo("tween_step", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::STRING, "key"), PropertyInfo(Variant::REAL, "elapsed"), PropertyInfo(Variant::OBJECT, "value"))); ADD_SIGNAL(MethodInfo("tween_completed", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::STRING, "key"))); - ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), "set_tween_process_mode", "get_tween_process_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_tween_process_mode", "get_tween_process_mode"); BIND_ENUM_CONSTANT(TWEEN_PROCESS_PHYSICS); BIND_ENUM_CONSTANT(TWEEN_PROCESS_IDLE); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 91c5263bf5..54a58159ac 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2811,12 +2811,12 @@ void Control::_bind_methods() { BIND_ENUM_CONSTANT(PRESET_WIDE); BIND_ENUM_CONSTANT(PRESET_MODE_MINSIZE); - BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_HEIGHT); BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_WIDTH); + BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_HEIGHT); BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_SIZE); - BIND_ENUM_CONSTANT(SIZE_EXPAND); BIND_ENUM_CONSTANT(SIZE_FILL); + BIND_ENUM_CONSTANT(SIZE_EXPAND); BIND_ENUM_CONSTANT(SIZE_EXPAND_FILL); BIND_ENUM_CONSTANT(SIZE_SHRINK_CENTER); BIND_ENUM_CONSTANT(SIZE_SHRINK_END); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index d8ff048dfb..6ade4fcc38 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -759,38 +759,42 @@ FileDialog::FileDialog() { mode = MODE_SAVE_FILE; set_title(RTR("Save a File")); + HBoxContainer *hbc = memnew(HBoxContainer); + hbc->add_child(memnew(Label(RTR("Path:")))); dir = memnew(LineEdit); - HBoxContainer *pathhb = memnew(HBoxContainer); - pathhb->add_child(dir); + hbc->add_child(dir); dir->set_h_size_flags(SIZE_EXPAND_FILL); refresh = memnew(ToolButton); refresh->connect("pressed", this, "_update_file_list"); - pathhb->add_child(refresh); + hbc->add_child(refresh); drives = memnew(OptionButton); - pathhb->add_child(drives); + 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"); - pathhb->add_child(makedir); - - vbc->add_margin_child(RTR("Path:"), pathhb); + hbc->add_child(makedir); + vbc->add_child(hbc); tree = memnew(Tree); 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 = memnew(LineEdit); - //add_child(file); - vbc->add_margin_child(RTR("File:"), file); - + file->set_stretch_ratio(4); + file->set_h_size_flags(SIZE_EXPAND_FILL); + hbc->add_child(file); filter = memnew(OptionButton); - //add_child(filter); - vbc->add_margin_child(RTR("Filter:"), filter); + filter->set_stretch_ratio(3); + filter->set_h_size_flags(SIZE_EXPAND_FILL); filter->set_clip_text(true); //too many extensions overflow it + hbc->add_child(filter); + vbc->add_child(hbc); dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES); access = ACCESS_RESOURCES; diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index a034c7224f..623a110263 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -489,7 +489,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { if (mb->get_button_index() == BUTTON_RIGHT) { - emit_signal("item_rmb_selected", i, pos); + emit_signal("item_rmb_selected", i, get_local_mouse_position()); } } else { @@ -500,7 +500,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { if (items[i].selected && mb->get_button_index() == BUTTON_RIGHT) { - emit_signal("item_rmb_selected", i, pos); + emit_signal("item_rmb_selected", i, get_local_mouse_position()); } else { bool selected = !items[i].selected; @@ -515,7 +515,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { if (mb->get_button_index() == BUTTON_RIGHT) { - emit_signal("item_rmb_selected", i, pos); + emit_signal("item_rmb_selected", i, get_local_mouse_position()); } else if (/*select_mode==SELECT_SINGLE &&*/ mb->is_doubleclick()) { emit_signal("item_activated", i); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index ed8eff436c..40e2dba6c2 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -161,13 +161,14 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { } break; - case (KEY_Z): { // Simple One level undo - + case (KEY_Z): { // undo / redo if (editable) { - - undo(); + if (k->get_shift()) { + redo(); + } else { + undo(); + } } - } break; case (KEY_U): { // Delete from start to cursor @@ -175,7 +176,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { if (editable) { selection_clear(); - undo_text = text; text = text.substr(cursor_pos, text.length() - cursor_pos); Ref<Font> font = get_font("font"); @@ -205,7 +205,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { if (editable) { selection_clear(); - undo_text = text; text = text.substr(0, cursor_pos); _text_changed(); } @@ -245,7 +244,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { break; if (selection.enabled) { - undo_text = text; selection_delete(); break; } @@ -276,7 +274,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { set_cursor_position(cc); } else { - undo_text = text; delete_char(); } @@ -382,7 +379,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { } if (selection.enabled) { - undo_text = text; selection_delete(); break; } @@ -417,7 +413,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { delete_text(cursor_pos, cc); } else { - undo_text = text; set_cursor_position(cursor_pos + 1); delete_char(); } @@ -778,7 +773,6 @@ void LineEdit::copy_text() { void LineEdit::cut_text() { if (selection.enabled) { - undo_text = text; OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin)); selection_delete(); } @@ -798,23 +792,33 @@ void LineEdit::paste_text() { } void LineEdit::undo() { - - int old_cursor_pos = cursor_pos; - text = undo_text; - - Ref<Font> font = get_font("font"); - - cached_width = 0; - for (int i = 0; i < text.length(); i++) - cached_width += font->get_char_size(text[i]).width; - - if (old_cursor_pos > text.length()) { - set_cursor_position(text.length()); - } else { - set_cursor_position(old_cursor_pos); + if (undo_stack_pos == NULL) { + if (undo_stack.size() <= 1) { + return; + } + undo_stack_pos = undo_stack.back(); + } else if (undo_stack_pos == undo_stack.front()) { + return; } + undo_stack_pos = undo_stack_pos->prev(); + TextOperation op = undo_stack_pos->get(); + text = op.text; + set_cursor_position(op.cursor_pos); + _emit_text_change(); +} - _text_changed(); +void LineEdit::redo() { + if (undo_stack_pos == NULL) { + return; + } + if (undo_stack_pos == undo_stack.back()) { + return; + } + undo_stack_pos = undo_stack_pos->next(); + TextOperation op = undo_stack_pos->get(); + text = op.text; + set_cursor_position(op.cursor_pos); + _emit_text_change(); } void LineEdit::shift_selection_check_pre(bool p_shift) { @@ -947,8 +951,6 @@ void LineEdit::delete_char() { void LineEdit::delete_text(int p_from_column, int p_to_column) { - undo_text = text; - if (text.size() > 0) { Ref<Font> font = get_font("font"); if (font != NULL) { @@ -1036,9 +1038,11 @@ void LineEdit::set_cursor_position(int p_pos) { Ref<StyleBox> style = get_stylebox("normal"); Ref<Font> font = get_font("font"); - if (cursor_pos < window_pos) { + if (cursor_pos <= window_pos) { /* Adjust window if cursor goes too much to the left */ - set_window_pos(cursor_pos); + if (window_pos > 0) + set_window_pos(window_pos - 1); + } else if (cursor_pos > window_pos) { /* Adjust window if cursor goes too much to the right */ int window_width = get_size().width - style->get_minimum_size().width; @@ -1086,8 +1090,6 @@ void LineEdit::append_at_cursor(String p_text) { if ((max_length <= 0) || (text.length() + p_text.length() <= max_length)) { - undo_text = text; - Ref<Font> font = get_font("font"); if (font != NULL) { for (int i = 0; i < p_text.length(); i++) @@ -1105,6 +1107,7 @@ void LineEdit::append_at_cursor(String p_text) { void LineEdit::clear_internal() { + _clear_undo_stack(); cached_width = 0; cursor_pos = 0; window_pos = 0; @@ -1275,6 +1278,11 @@ void LineEdit::menu_option(int p_option) { undo(); } } break; + case MENU_REDO: { + if (editable) { + redo(); + } + } } } @@ -1312,10 +1320,43 @@ void LineEdit::_text_changed() { if (expand_to_text_length) minimum_size_changed(); + _emit_text_change(); + _clear_redo(); +} + +void LineEdit::_emit_text_change() { emit_signal("text_changed", text); _change_notify("text"); } +void LineEdit::_clear_redo() { + _create_undo_state(); + if (undo_stack_pos == NULL) { + return; + } + + undo_stack_pos = undo_stack_pos->next(); + while (undo_stack_pos) { + List<TextOperation>::Element *elem = undo_stack_pos; + undo_stack_pos = undo_stack_pos->next(); + undo_stack.erase(elem); + } + _create_undo_state(); +} + +void LineEdit::_clear_undo_stack() { + undo_stack.clear(); + undo_stack_pos = NULL; + _create_undo_state(); +} + +void LineEdit::_create_undo_state() { + TextOperation op; + op.text = text; + op.cursor_pos = cursor_pos; + undo_stack.push_back(op); +} + void LineEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("_toggle_draw_caret"), &LineEdit::_toggle_draw_caret); @@ -1369,6 +1410,7 @@ void LineEdit::_bind_methods() { BIND_ENUM_CONSTANT(MENU_CLEAR); BIND_ENUM_CONSTANT(MENU_SELECT_ALL); BIND_ENUM_CONSTANT(MENU_UNDO); + BIND_ENUM_CONSTANT(MENU_REDO); BIND_ENUM_CONSTANT(MENU_MAX); ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "text"), "set_text", "get_text"); @@ -1388,6 +1430,8 @@ void LineEdit::_bind_methods() { LineEdit::LineEdit() { + undo_stack_pos = NULL; + _create_undo_state(); align = ALIGN_LEFT; cached_width = 0; cursor_pos = 0; @@ -1421,6 +1465,7 @@ LineEdit::LineEdit() { menu->add_item(TTR("Clear"), MENU_CLEAR); menu->add_separator(); menu->add_item(TTR("Undo"), MENU_UNDO, KEY_MASK_CMD | KEY_Z); + menu->add_item(TTR("Redo"), MENU_REDO, KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_Z); menu->connect("id_pressed", this, "menu_option"); expand_to_text_length = false; } diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index 661f9b60b9..bece29a37d 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -56,6 +56,7 @@ public: MENU_CLEAR, MENU_SELECT_ALL, MENU_UNDO, + MENU_REDO, MENU_MAX }; @@ -92,10 +93,22 @@ private: bool drag_attempt; } selection; + struct TextOperation { + int cursor_pos; + String text; + }; + List<TextOperation> undo_stack; + List<TextOperation>::Element *undo_stack_pos; + + void _clear_undo_stack(); + void _clear_redo(); + void _create_undo_state(); + Timer *caret_blink_timer; static void _ime_text_callback(void *p_self, String p_text, Point2 p_selection); void _text_changed(); + void _emit_text_change(); bool expand_to_text_length; bool caret_blink_enabled; @@ -166,6 +179,7 @@ public: void cut_text(); void paste_text(); void undo(); + void redo(); void set_editable(bool p_editable); bool is_editable() const; diff --git a/scene/gui/patch_9_rect.cpp b/scene/gui/nine_patch_rect.cpp index 92c34dd3f9..c02d80bba8 100644 --- a/scene/gui/patch_9_rect.cpp +++ b/scene/gui/nine_patch_rect.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* patch_9_rect.cpp */ +/* nine_patch_rect.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,7 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "patch_9_rect.h" +#include "nine_patch_rect.h" #include "servers/visual_server.h" diff --git a/scene/gui/patch_9_rect.h b/scene/gui/nine_patch_rect.h index 808b7a1f5d..809daf9db3 100644 --- a/scene/gui/patch_9_rect.h +++ b/scene/gui/nine_patch_rect.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* patch_9_rect.h */ +/* nine_patch_rect.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,8 +27,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef PATCH_9_FRAME_H -#define PATCH_9_FRAME_H +#ifndef NINE_PATCH_RECT_H +#define NINE_PATCH_RECT_H #include "scene/gui/control.h" /** @@ -81,4 +81,4 @@ public: }; VARIANT_ENUM_CAST(NinePatchRect::AxisStretchMode) -#endif // PATCH_9_FRAME_H +#endif // NINE_PATCH_RECT_H diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 07b49538d9..65a8350bd3 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -1195,8 +1195,9 @@ void RichTextLabel::add_newline() { return; ItemNewline *item = memnew(ItemNewline); item->line = current_frame->lines.size(); - current_frame->lines.resize(current_frame->lines.size() + 1); _add_item(item, false); + current_frame->lines.resize(current_frame->lines.size() + 1); + _invalidate_current_line(current_frame); } bool RichTextLabel::remove_line(const int p_line) { @@ -1984,6 +1985,7 @@ void RichTextLabel::_bind_methods() { BIND_ENUM_CONSTANT(ITEM_ALIGN); BIND_ENUM_CONSTANT(ITEM_INDENT); BIND_ENUM_CONSTANT(ITEM_LIST); + BIND_ENUM_CONSTANT(ITEM_TABLE); BIND_ENUM_CONSTANT(ITEM_META); } diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 116e0ac354..e88742a3e3 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -157,6 +157,12 @@ void Slider::_notification(int p_what) { mouse_inside = false; update(); } break; + case NOTIFICATION_VISIBILITY_CHANGED: // fallthrough + case NOTIFICATION_EXIT_TREE: { + + mouse_inside = false; + grab.active = false; + } break; case NOTIFICATION_DRAW: { RID ci = get_canvas_item(); Size2i size = get_size(); diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 6e50614e8f..581034ddee 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -90,19 +90,28 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { return; } + // Do not activate tabs when tabs is empty + if (get_tab_count() == 0) + return; + Vector<Control *> tabs = _get_tabs(); // Handle navigation buttons. if (buttons_visible_cache) { + int popup_ofs = 0; + if (popup) { + popup_ofs = menu->get_width(); + } + Ref<Texture> increment = get_icon("increment"); Ref<Texture> decrement = get_icon("decrement"); - if (pos.x > size.width - increment->get_width()) { + if (pos.x > size.width - increment->get_width() - popup_ofs) { if (last_tab_cache < tabs.size() - 1) { first_tab_cache += 1; update(); } return; - } else if (pos.x > size.width - increment->get_width() - decrement->get_width()) { + } else if (pos.x > size.width - increment->get_width() - decrement->get_width() - popup_ofs) { if (first_tab_cache > 0) { first_tab_cache -= 1; update(); @@ -293,6 +302,8 @@ void TabContainer::_notification(int p_what) { } int TabContainer::_get_tab_width(int p_index) const { + + ERR_FAIL_INDEX_V(p_index, get_tab_count(), 0); Control *control = Object::cast_to<Control>(_get_tabs()[p_index]); if (!control || control->is_set_as_toplevel()) return 0; @@ -664,6 +675,7 @@ void TabContainer::_bind_methods() { TabContainer::TabContainer() { first_tab_cache = 0; + last_tab_cache = 0; buttons_visible_cache = false; tabs_ofs_cache = 0; current = 0; diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index 085f6de6b8..49823e18fc 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -820,9 +820,9 @@ void Tabs::_bind_methods() { BIND_ENUM_CONSTANT(ALIGN_RIGHT); BIND_ENUM_CONSTANT(ALIGN_MAX); + BIND_ENUM_CONSTANT(CLOSE_BUTTON_SHOW_NEVER); BIND_ENUM_CONSTANT(CLOSE_BUTTON_SHOW_ACTIVE_ONLY); BIND_ENUM_CONSTANT(CLOSE_BUTTON_SHOW_ALWAYS); - BIND_ENUM_CONSTANT(CLOSE_BUTTON_SHOW_NEVER); BIND_ENUM_CONSTANT(CLOSE_BUTTON_MAX); } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index de69406b37..ee7762b668 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -732,6 +732,19 @@ void TextEdit::_notification(int p_what) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.mark_color); } + if (str.length() == 0) { + // draw line background if empty as we won't loop at at all + if (line == cursor.line && highlight_current_line) { + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_end, get_row_height()), cache.current_line_color); + } + + // give visual indication of empty selected line + if (selection.active && line >= selection.from_line && line <= selection.to_line) { + int char_w = cache.font->get_char_size(' ').width; + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg, ofs_y, char_w, get_row_height()), cache.selection_color); + } + } + if (text.is_breakpoint(line) && !draw_breakpoint_gutter) { #ifdef TOOLS_ENABLED VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg, ofs_y + get_row_height() - EDSCALE, xmargin_end - xmargin_beg, EDSCALE), cache.breakpoint_color); @@ -952,16 +965,19 @@ void TextEdit::_notification(int p_what) { //current line highlighting bool in_selection = (selection.active && line >= selection.from_line && line <= selection.to_line && (line > selection.from_line || j >= selection.from_column) && (line < selection.to_line || j < selection.to_column)); - if (line == cursor.line) { - if (j == 0) - //first char + if (line == cursor.line && highlight_current_line) { + // if its the first char draw behind line numbers + if (j == 0) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, (char_ofs + char_margin), get_row_height()), cache.current_line_color); - else if (j == str.length() - 1) - //last char + } + // if its the last char draw to end of the line + if (j == str.length() - 1) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(char_ofs + char_margin + char_w, ofs_y, xmargin_end - (char_ofs + char_margin + char_w), get_row_height()), cache.current_line_color); - - if (!in_selection) + } + // actual text + if (!in_selection) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin, ofs_y), Size2i(char_w, get_row_height())), cache.current_line_color); + } } if (in_selection) { @@ -2172,7 +2188,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } } } - + begin_complex_operation(); bool first_line = false; if (k->get_command()) { if (k->get_shift()) { @@ -2188,8 +2204,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } } - _insert_text_at_cursor(ins); - _push_current_op(); + insert_text_at_cursor(ins); if (first_line) { cursor_set_line(0); @@ -2197,7 +2212,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { cursor_set_line(cursor.line - 1); cursor_set_column(text[cursor.line].length()); } - + end_complex_operation(); } break; case KEY_ESCAPE: { if (completion_hint != "") { @@ -4473,7 +4488,13 @@ void TextEdit::_update_completion_candidates() { completion_index = 0; completion_base = s; Vector<float> sim_cache; + bool single_quote = s.begins_with("'"); + for (int i = 0; i < completion_strings.size(); i++) { + if (single_quote && completion_strings[i].is_quoted()) { + completion_strings[i] = completion_strings[i].unquote().quote("'"); + } + if (s == completion_strings[i]) { // A perfect match, stop completion _cancel_completion(); @@ -4716,6 +4737,15 @@ int TextEdit::get_breakpoint_gutter_width() const { return cache.breakpoint_gutter_width; } +void TextEdit::set_highlight_current_line(bool p_enabled) { + highlight_current_line = p_enabled; + update(); +} + +bool TextEdit::is_highlight_current_line_enabled() const { + return highlight_current_line; +} + bool TextEdit::is_text_field() const { return true; @@ -4843,6 +4873,9 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_syntax_coloring", "enable"), &TextEdit::set_syntax_coloring); ClassDB::bind_method(D_METHOD("is_syntax_coloring_enabled"), &TextEdit::is_syntax_coloring_enabled); + ClassDB::bind_method(D_METHOD("set_highlight_current_line", "enabled"), &TextEdit::set_highlight_current_line); + ClassDB::bind_method(D_METHOD("is_highlight_current_line_enabled"), &TextEdit::is_highlight_current_line_enabled); + ClassDB::bind_method(D_METHOD("set_smooth_scroll_enable", "enable"), &TextEdit::set_smooth_scroll_enabled); ClassDB::bind_method(D_METHOD("is_smooth_scroll_enabled"), &TextEdit::is_smooth_scroll_enabled); ClassDB::bind_method(D_METHOD("set_v_scroll_speed", "speed"), &TextEdit::set_v_scroll_speed); @@ -4854,6 +4887,7 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("menu_option", "option"), &TextEdit::menu_option); ClassDB::bind_method(D_METHOD("get_menu"), &TextEdit::get_menu); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_current_line"), "set_highlight_current_line", "is_highlight_current_line_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "syntax_highlighting"), "set_syntax_coloring", "is_syntax_coloring_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_line_numbers"), "set_show_line_numbers", "is_show_line_numbers_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_all_occurrences"), "set_highlight_all_occurrences", "is_highlight_all_occurrences_enabled"); @@ -4975,6 +5009,7 @@ TextEdit::TextEdit() { auto_brace_completion_enabled = false; brace_matching_enabled = false; highlight_all_occurrences = false; + highlight_current_line = false; indent_using_spaces = false; space_indent = " "; auto_indent = false; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 03f412729d..b4b14d0139 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -253,6 +253,7 @@ class TextEdit : public Control { bool scroll_past_end_of_file_enabled; bool auto_brace_completion_enabled; bool brace_matching_enabled; + bool highlight_current_line; bool auto_indent; bool cut_copy_line; bool insert_mode; @@ -514,6 +515,9 @@ public: void set_show_line_numbers(bool p_show); bool is_show_line_numbers_enabled() const; + void set_highlight_current_line(bool p_enabled); + bool is_highlight_current_line_enabled() const; + void set_line_numbers_zero_padded(bool p_zero_padded); void set_show_line_length_guideline(bool p_show); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 178a1c272b..5c6f2b0d01 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -47,18 +47,21 @@ void TreeItem::move_to_top() { } void TreeItem::move_to_bottom() { - if (!parent || !next) return; - while (next) { + TreeItem *prev = get_prev(); + TreeItem *last = next; + while (last->next) + last = last->next; - if (parent->childs == this) - parent->childs = next; - TreeItem *n = next; - next = n->next; - n->next = this; + if (prev) { + prev->next = next; + } else { + parent->childs = next; } + last->next = this; + next = NULL; } Size2 TreeItem::Cell::get_icon_size() const { @@ -1123,7 +1126,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 if (p_item->cells[i].selected && select_mode != SELECT_ROW) { - Rect2i r(item_rect.position, item_rect.size); + Rect2i r(cell_rect.position, cell_rect.size); if (p_item->cells[i].text.size() > 0) { float icon_width = p_item->cells[i].get_icon_size().width; r.position.x += icon_width; diff --git a/scene/gui/viewport_container.cpp b/scene/gui/viewport_container.cpp index c321b873fd..9244d8de2f 100644 --- a/scene/gui/viewport_container.cpp +++ b/scene/gui/viewport_container.cpp @@ -62,6 +62,34 @@ bool ViewportContainer::is_stretch_enabled() const { return stretch; } +void ViewportContainer::set_stretch_shrink(int p_shrink) { + + ERR_FAIL_COND(p_shrink < 1); + if (shrink == p_shrink) + return; + + shrink = p_shrink; + + if (!stretch) + return; + + for (int i = 0; i < get_child_count(); i++) { + + Viewport *c = Object::cast_to<Viewport>(get_child(i)); + if (!c) + continue; + + c->set_size(get_size() / shrink); + } + + update(); +} + +int ViewportContainer::get_stretch_shrink() const { + + return shrink; +} + void ViewportContainer::_notification(int p_what) { if (p_what == NOTIFICATION_RESIZED) { @@ -75,7 +103,7 @@ void ViewportContainer::_notification(int p_what) { if (!c) continue; - c->set_size(get_size()); + c->set_size(get_size() / shrink); } } @@ -115,10 +143,15 @@ void ViewportContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &ViewportContainer::set_stretch); ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &ViewportContainer::is_stretch_enabled); + ClassDB::bind_method(D_METHOD("set_stretch_shrink", "amount"), &ViewportContainer::set_stretch_shrink); + ClassDB::bind_method(D_METHOD("get_stretch_shrink"), &ViewportContainer::get_stretch_shrink); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stretch"), "set_stretch", "is_stretch_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_shrink"), "set_stretch_shrink", "get_stretch_shrink"); } ViewportContainer::ViewportContainer() { stretch = false; + shrink = 1; } diff --git a/scene/gui/viewport_container.h b/scene/gui/viewport_container.h index 630523b5fb..ebf5869ed9 100644 --- a/scene/gui/viewport_container.h +++ b/scene/gui/viewport_container.h @@ -37,6 +37,7 @@ class ViewportContainer : public Container { GDCLASS(ViewportContainer, Container); bool stretch; + int shrink; protected: void _notification(int p_what); @@ -46,6 +47,9 @@ public: void set_stretch(bool p_enable); bool is_stretch_enabled() const; + void set_stretch_shrink(int p_shrink); + int get_stretch_shrink() const; + virtual Size2 get_minimum_size() const; ViewportContainer(); diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index 1e1e4f2d5f..672e893f1b 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -579,6 +579,7 @@ HTTPRequest::HTTPRequest() { client.instance(); use_threads = false; thread_done = false; + downloaded = 0; body_size_limit = -1; file = NULL; status = HTTPClient::STATUS_DISCONNECTED; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index c2a31b4a8b..e6e11de177 100755 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -212,6 +212,8 @@ void Node::_propagate_enter_tree() { emit_signal(SceneStringNames::get_singleton()->tree_entered); + data.tree->node_added(this); + data.blocked++; //block while adding children @@ -2801,12 +2803,12 @@ void Node::_bind_methods() { BIND_CONSTANT(NOTIFICATION_EXIT_TREE); BIND_CONSTANT(NOTIFICATION_MOVED_IN_PARENT); BIND_CONSTANT(NOTIFICATION_READY); + BIND_CONSTANT(NOTIFICATION_PAUSED); + BIND_CONSTANT(NOTIFICATION_UNPAUSED); BIND_CONSTANT(NOTIFICATION_PHYSICS_PROCESS); BIND_CONSTANT(NOTIFICATION_PROCESS); BIND_CONSTANT(NOTIFICATION_PARENTED); BIND_CONSTANT(NOTIFICATION_UNPARENTED); - BIND_CONSTANT(NOTIFICATION_PAUSED); - BIND_CONSTANT(NOTIFICATION_UNPAUSED); BIND_CONSTANT(NOTIFICATION_INSTANCED); BIND_CONSTANT(NOTIFICATION_DRAG_BEGIN); BIND_CONSTANT(NOTIFICATION_DRAG_END); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 7a28e2a6f8..d4be683a2b 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -85,6 +85,11 @@ void SceneTree::tree_changed() { emit_signal(tree_changed_name); } +void SceneTree::node_added(Node *p_node) { + + emit_signal(node_added_name, p_node); +} + void SceneTree::node_removed(Node *p_node) { if (current_scene == p_node) { @@ -1172,7 +1177,7 @@ void SceneTree::_update_root_rect() { } } -void SceneTree::set_screen_stretch(StretchMode p_mode, StretchAspect p_aspect, const Size2 p_minsize, int p_shrink) { +void SceneTree::set_screen_stretch(StretchMode p_mode, StretchAspect p_aspect, const Size2 p_minsize, real_t p_shrink) { stretch_mode = p_mode; stretch_aspect = p_aspect; @@ -2189,6 +2194,7 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("_server_disconnected"), &SceneTree::_server_disconnected); ADD_SIGNAL(MethodInfo("tree_changed")); + ADD_SIGNAL(MethodInfo("node_added", PropertyInfo(Variant::OBJECT, "node"))); ADD_SIGNAL(MethodInfo("node_removed", PropertyInfo(Variant::OBJECT, "node"))); ADD_SIGNAL(MethodInfo("screen_resized")); ADD_SIGNAL(MethodInfo("node_configuration_warning_changed", PropertyInfo(Variant::OBJECT, "node"))); @@ -2260,6 +2266,7 @@ SceneTree::SceneTree() { root = NULL; current_frame = 0; tree_changed_name = "tree_changed"; + node_added_name = "node_added"; node_removed_name = "node_removed"; ugc_locked = false; call_lock = 0; diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index f3e689adab..bc3efdc42f 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -124,6 +124,7 @@ private: bool input_handled; Size2 last_screen_size; StringName tree_changed_name; + StringName node_added_name; StringName node_removed_name; int64_t current_frame; @@ -147,7 +148,7 @@ private: StretchMode stretch_mode; StretchAspect stretch_aspect; Size2i stretch_min; - int stretch_shrink; + real_t stretch_shrink; void _update_root_rect(); @@ -233,6 +234,7 @@ private: void _rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount); void tree_changed(); + void node_added(Node *p_node); void node_removed(Node *p_node); Group *add_to_group(const StringName &p_group, Node *p_node); @@ -415,7 +417,7 @@ public: void get_nodes_in_group(const StringName &p_group, List<Node *> *p_list); bool has_group(const StringName &p_identifier) const; - void set_screen_stretch(StretchMode p_mode, StretchAspect p_aspect, const Size2 p_minsize, int p_shrink = 1); + void set_screen_stretch(StretchMode p_mode, StretchAspect p_aspect, const Size2 p_minsize, real_t p_shrink = 1); //void change_scene(const String& p_path); //Node *get_loaded_scene(); diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index 23854b5f59..e0c6f93f25 100755 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp @@ -199,7 +199,7 @@ void Timer::_bind_methods() { ADD_SIGNAL(MethodInfo("timeout")); - ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), "set_timer_process_mode", "get_timer_process_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_timer_process_mode", "get_timer_process_mode"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "wait_time", PROPERTY_HINT_EXP_RANGE, "0.01,4096,0.01"), "set_wait_time", "get_wait_time"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "is_one_shot"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autostart"), "set_autostart", "has_autostart"); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 37a393b55b..0a02f471c1 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2371,8 +2371,13 @@ void Viewport::input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(!is_inside_tree()); - get_tree()->_call_input_pause(input_group, "_input", p_event); //not a bug, must happen before GUI, order is _input -> gui input -> _unhandled input - _gui_input_event(p_event); + if (!get_tree()->is_input_handled()) { + get_tree()->_call_input_pause(input_group, "_input", p_event); //not a bug, must happen before GUI, order is _input -> gui input -> _unhandled input + } + + if (!get_tree()->is_input_handled()) { + _gui_input_event(p_event); + } //get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check } @@ -2711,7 +2716,7 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "debug_draw", PROPERTY_HINT_ENUM, "Disabled,Unshaded,Overdraw,Wireframe"), "set_debug_draw", "get_debug_draw"); ADD_GROUP("Render Target", "render_target_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target_v_flip"), "set_vflip", "get_vflip"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target_clear_mode", PROPERTY_HINT_ENUM, "Always,Never,NextFrame"), "set_clear_mode", "get_clear_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target_clear_mode", PROPERTY_HINT_ENUM, "Always,Never,Next Frame"), "set_clear_mode", "get_clear_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target_update_mode", PROPERTY_HINT_ENUM, "Disabled,Once,When Visible,Always"), "set_update_mode", "get_update_mode"); ADD_GROUP("Audio Listener", "audio_listener_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener_enable_2d"), "set_as_audio_listener_2d", "is_audio_listener_2d"); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 75268aad1f..eaa16069cf 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -86,7 +86,7 @@ #include "scene/gui/option_button.h" #include "scene/gui/panel.h" #include "scene/gui/panel_container.h" -#include "scene/gui/patch_9_rect.h" +#include "scene/gui/nine_patch_rect.h" #include "scene/gui/popup_menu.h" #include "scene/gui/progress_bar.h" #include "scene/gui/reference_rect.h" @@ -152,6 +152,10 @@ #include "scene/resources/world_2d.h" #include "scene/scene_string_names.h" +#include "scene/3d/particles.h" +#include "scene/3d/scenario_fx.h" +#include "scene/3d/spatial.h" + #ifndef _3D_DISABLED #include "scene/3d/area.h" #include "scene/3d/arvr_nodes.h" @@ -169,7 +173,6 @@ #include "scene/3d/multimesh_instance.h" #include "scene/3d/navigation.h" #include "scene/3d/navigation_mesh.h" -#include "scene/3d/particles.h" #include "scene/3d/path.h" #include "scene/3d/physics_body.h" #include "scene/3d/physics_joint.h" @@ -180,9 +183,7 @@ #include "scene/3d/reflection_probe.h" #include "scene/3d/remote_transform.h" #include "scene/3d/room_instance.h" -#include "scene/3d/scenario_fx.h" #include "scene/3d/skeleton.h" -#include "scene/3d/spatial.h" #include "scene/3d/sprite_3d.h" #include "scene/3d/vehicle_body.h" #include "scene/3d/visibility_notifier.h" @@ -541,6 +542,7 @@ void register_scene_types() { ClassDB::register_class<StyleBoxEmpty>(); ClassDB::register_class<StyleBoxTexture>(); ClassDB::register_class<StyleBoxFlat>(); + ClassDB::register_class<StyleBoxLine>(); ClassDB::register_class<Theme>(); ClassDB::register_class<PolygonPathFinder>(); @@ -551,7 +553,9 @@ void register_scene_types() { ClassDB::register_class<AudioStreamPlayer>(); ClassDB::register_class<AudioStreamPlayer2D>(); +#ifndef _3D_DISABLED ClassDB::register_class<AudioStreamPlayer3D>(); +#endif ClassDB::register_virtual_class<VideoStream>(); ClassDB::register_class<AudioStreamSample>(); diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 8dcc8d4e14..21e4a85cd1 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -1171,9 +1171,7 @@ T Animation::_interpolate(const Vector<TKey<T> > &p_keys, float p_time, Interpol ERR_FAIL_COND_V(idx == -2, T()); - if (p_ok) - *p_ok = true; - + bool result = true; int next = 0; float c = 0; // prepare for all cases of interpolation @@ -1243,10 +1241,19 @@ T Animation::_interpolate(const Vector<TKey<T> > &p_keys, float p_time, Interpol } else if (idx < 0) { - idx = next = 0; + // only allow extending first key to anim start if looping + if (loop) + idx = next = 0; + else + result = false; } } + if (p_ok) + *p_ok = result; + if (!result) + return T(); + float tr = p_keys[idx].transition; if (tr == 0 || idx == next) { @@ -1298,7 +1305,7 @@ Error Animation::transform_track_interpolate(int p_track, float p_time, Vector3 TransformKey tk = _interpolate(tt->transforms, p_time, tt->interpolation, tt->loop_wrap, &ok); - if (!ok) // ?? + if (!ok) return ERR_UNAVAILABLE; if (r_loc) diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index 4c6fa7c8a1..232f690074 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -377,7 +377,7 @@ bool Environment::is_ssr_rough() const { void Environment::set_ssao_enabled(bool p_enable) { ssao_enabled = p_enable; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, ssao_blur); + VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, VS::EnvironmentSSAOQuality(ssao_quality), VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); _change_notify(); } @@ -389,7 +389,7 @@ bool Environment::is_ssao_enabled() const { void Environment::set_ssao_radius(float p_radius) { ssao_radius = p_radius; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, ssao_blur); + VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, VS::EnvironmentSSAOQuality(ssao_quality), VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_radius() const { @@ -399,7 +399,7 @@ float Environment::get_ssao_radius() const { void Environment::set_ssao_intensity(float p_intensity) { ssao_intensity = p_intensity; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, ssao_blur); + VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, VS::EnvironmentSSAOQuality(ssao_quality), VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_intensity() const { @@ -410,7 +410,7 @@ float Environment::get_ssao_intensity() const { void Environment::set_ssao_radius2(float p_radius) { ssao_radius2 = p_radius; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, ssao_blur); + VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, VS::EnvironmentSSAOQuality(ssao_quality), VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_radius2() const { @@ -420,7 +420,7 @@ float Environment::get_ssao_radius2() const { void Environment::set_ssao_intensity2(float p_intensity) { ssao_intensity2 = p_intensity; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, ssao_blur); + VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, VS::EnvironmentSSAOQuality(ssao_quality), VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_intensity2() const { @@ -430,7 +430,7 @@ float Environment::get_ssao_intensity2() const { void Environment::set_ssao_bias(float p_bias) { ssao_bias = p_bias; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, ssao_blur); + VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, VS::EnvironmentSSAOQuality(ssao_quality), VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_bias() const { @@ -440,7 +440,7 @@ float Environment::get_ssao_bias() const { void Environment::set_ssao_direct_light_affect(float p_direct_light_affect) { ssao_direct_light_affect = p_direct_light_affect; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, ssao_blur); + VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, VS::EnvironmentSSAOQuality(ssao_quality), VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_direct_light_affect() const { @@ -450,7 +450,7 @@ float Environment::get_ssao_direct_light_affect() const { void Environment::set_ssao_color(const Color &p_color) { ssao_color = p_color; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, ssao_blur); + VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, VS::EnvironmentSSAOQuality(ssao_quality), VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } Color Environment::get_ssao_color() const { @@ -458,16 +458,38 @@ Color Environment::get_ssao_color() const { return ssao_color; } -void Environment::set_ssao_blur(bool p_enable) { +void Environment::set_ssao_blur(SSAOBlur p_blur) { - ssao_blur = p_enable; - VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, ssao_blur); + ssao_blur = p_blur; + VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, VS::EnvironmentSSAOQuality(ssao_quality), VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } -bool Environment::is_ssao_blur_enabled() const { +Environment::SSAOBlur Environment::get_ssao_blur() const { return ssao_blur; } +void Environment::set_ssao_quality(SSAOQuality p_quality) { + + ssao_quality = p_quality; + VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, VS::EnvironmentSSAOQuality(ssao_quality), VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); +} + +Environment::SSAOQuality Environment::get_ssao_quality() const { + + return ssao_quality; +} + +void Environment::set_ssao_edge_sharpness(float p_edge_sharpness) { + + ssao_edge_sharpness = p_edge_sharpness; + VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, VS::EnvironmentSSAOQuality(ssao_quality), VS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); +} + +float Environment::get_ssao_edge_sharpness() const { + + return ssao_edge_sharpness; +} + void Environment::set_glow_enabled(bool p_enabled) { glow_enabled = p_enabled; @@ -988,8 +1010,14 @@ void Environment::_bind_methods() { ClassDB::bind_method(D_METHOD("set_ssao_color", "color"), &Environment::set_ssao_color); ClassDB::bind_method(D_METHOD("get_ssao_color"), &Environment::get_ssao_color); - ClassDB::bind_method(D_METHOD("set_ssao_blur", "enabled"), &Environment::set_ssao_blur); - ClassDB::bind_method(D_METHOD("is_ssao_blur_enabled"), &Environment::is_ssao_blur_enabled); + ClassDB::bind_method(D_METHOD("set_ssao_blur", "mode"), &Environment::set_ssao_blur); + ClassDB::bind_method(D_METHOD("get_ssao_blur"), &Environment::get_ssao_blur); + + ClassDB::bind_method(D_METHOD("set_ssao_quality", "quality"), &Environment::set_ssao_quality); + ClassDB::bind_method(D_METHOD("get_ssao_quality"), &Environment::get_ssao_quality); + + ClassDB::bind_method(D_METHOD("set_ssao_edge_sharpness", "edge_sharpness"), &Environment::set_ssao_edge_sharpness); + ClassDB::bind_method(D_METHOD("get_ssao_edge_sharpness"), &Environment::get_ssao_edge_sharpness); ADD_GROUP("SSAO", "ssao_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ssao_enabled"), "set_ssao_enabled", "is_ssao_enabled"); @@ -1000,7 +1028,9 @@ void Environment::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "ssao_bias", PROPERTY_HINT_RANGE, "0.001,8,0.001"), "set_ssao_bias", "get_ssao_bias"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "ssao_light_affect", PROPERTY_HINT_RANGE, "0.00,1,0.01"), "set_ssao_direct_light_affect", "get_ssao_direct_light_affect"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ssao_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_ssao_color", "get_ssao_color"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ssao_blur"), "set_ssao_blur", "is_ssao_blur_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "ssao_quality", PROPERTY_HINT_ENUM, "Low,Medium,High"), "set_ssao_quality", "get_ssao_quality"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "ssao_blur", PROPERTY_HINT_ENUM, "Disabled,1x1,2x2,3x3"), "set_ssao_blur", "get_ssao_blur"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "ssao_edge_sharpness", PROPERTY_HINT_RANGE, "0,32,0.01"), "set_ssao_edge_sharpness", "get_ssao_edge_sharpness"); ClassDB::bind_method(D_METHOD("set_dof_blur_far_enabled", "enabled"), &Environment::set_dof_blur_far_enabled); ClassDB::bind_method(D_METHOD("is_dof_blur_far_enabled"), &Environment::is_dof_blur_far_enabled); @@ -1134,6 +1164,15 @@ void Environment::_bind_methods() { BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_LOW); BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_MEDIUM); BIND_ENUM_CONSTANT(DOF_BLUR_QUALITY_HIGH); + + BIND_ENUM_CONSTANT(SSAO_BLUR_DISABLED); + BIND_ENUM_CONSTANT(SSAO_BLUR_1x1); + BIND_ENUM_CONSTANT(SSAO_BLUR_2x2); + BIND_ENUM_CONSTANT(SSAO_BLUR_3x3); + + BIND_ENUM_CONSTANT(SSAO_QUALITY_LOW); + BIND_ENUM_CONSTANT(SSAO_QUALITY_MEDIUM); + BIND_ENUM_CONSTANT(SSAO_QUALITY_HIGH); } Environment::Environment() { @@ -1179,7 +1218,9 @@ Environment::Environment() { ssao_intensity2 = 1; ssao_bias = 0.01; ssao_direct_light_affect = false; - ssao_blur = true; + ssao_blur = SSAO_BLUR_3x3; + set_ssao_edge_sharpness(4); + set_ssao_quality(SSAO_QUALITY_LOW); glow_enabled = false; glow_levels = (1 << 2) | (1 << 4); diff --git a/scene/resources/environment.h b/scene/resources/environment.h index 5909846074..418949a6ad 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -71,6 +71,19 @@ public: DOF_BLUR_QUALITY_HIGH, }; + enum SSAOBlur { + SSAO_BLUR_DISABLED, + SSAO_BLUR_1x1, + SSAO_BLUR_2x2, + SSAO_BLUR_3x3 + }; + + enum SSAOQuality { + SSAO_QUALITY_LOW, + SSAO_QUALITY_MEDIUM, + SSAO_QUALITY_HIGH + }; + private: RID environment; @@ -114,7 +127,9 @@ private: float ssao_bias; float ssao_direct_light_affect; Color ssao_color; - bool ssao_blur; + SSAOBlur ssao_blur; + float ssao_edge_sharpness; + SSAOQuality ssao_quality; bool glow_enabled; int glow_levels; @@ -261,8 +276,14 @@ public: void set_ssao_color(const Color &p_color); Color get_ssao_color() const; - void set_ssao_blur(bool p_enable); - bool is_ssao_blur_enabled() const; + void set_ssao_blur(SSAOBlur p_blur); + SSAOBlur get_ssao_blur() const; + + void set_ssao_quality(SSAOQuality p_quality); + SSAOQuality get_ssao_quality() const; + + void set_ssao_edge_sharpness(float p_edge_sharpness); + float get_ssao_edge_sharpness() const; void set_glow_enabled(bool p_enabled); bool is_glow_enabled() const; @@ -370,5 +391,7 @@ VARIANT_ENUM_CAST(Environment::BGMode) VARIANT_ENUM_CAST(Environment::ToneMapper) VARIANT_ENUM_CAST(Environment::GlowBlendMode) VARIANT_ENUM_CAST(Environment::DOFBlurQuality) +VARIANT_ENUM_CAST(Environment::SSAOQuality) +VARIANT_ENUM_CAST(Environment::SSAOBlur) #endif // ENVIRONMENT_H diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 2936df7a51..12434b39fa 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -1242,6 +1242,15 @@ Ref<Texture> SpatialMaterial::get_texture(TextureParam p_param) const { return textures[p_param]; } +Ref<Texture> SpatialMaterial::get_texture_by_name(StringName p_name) const { + for (int i = 0; i < (int)SpatialMaterial::TEXTURE_MAX; i++) { + TextureParam param = TextureParam(i); + if (p_name == shader_names->texture_names[param]) + return textures[param]; + } + return Ref<Texture>(); +} + void SpatialMaterial::_validate_feature(const String &text, Feature feature, PropertyInfo &property) const { if (property.name.begins_with(text) && property.name != text + "_enabled" && !features[feature]) { property.usage = 0; @@ -1269,7 +1278,7 @@ void SpatialMaterial::_validate_property(PropertyInfo &property) const { property.usage = 0; } - if (property.name == "proximity_fade_distacne" && !proximity_fade_enabled) { + if (property.name == "proximity_fade_distance" && !proximity_fade_enabled) { property.usage = 0; } diff --git a/scene/resources/material.h b/scene/resources/material.h index c0e007ac5f..2425f1a174 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -510,6 +510,8 @@ public: void set_texture(TextureParam p_param, const Ref<Texture> &p_texture); Ref<Texture> get_texture(TextureParam p_param) const; + // Used only for shader material conversion + Ref<Texture> get_texture_by_name(StringName p_name) const; void set_feature(Feature p_feature, bool p_enabled); bool get_feature(Feature p_feature) const; diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index c202fad1a4..467f059fd3 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -78,11 +78,11 @@ void Texture::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_MIPMAPS); BIND_ENUM_CONSTANT(FLAG_REPEAT); BIND_ENUM_CONSTANT(FLAG_FILTER); - BIND_ENUM_CONSTANT(FLAG_VIDEO_SURFACE); BIND_ENUM_CONSTANT(FLAGS_DEFAULT); BIND_ENUM_CONSTANT(FLAG_ANISOTROPIC_FILTER); BIND_ENUM_CONSTANT(FLAG_CONVERT_TO_LINEAR); BIND_ENUM_CONSTANT(FLAG_MIRRORED_REPEAT); + BIND_ENUM_CONSTANT(FLAG_VIDEO_SURFACE); } Texture::Texture() { @@ -1324,10 +1324,8 @@ void CubeMap::_bind_methods() { ClassDB::bind_method(D_METHOD("get_width"), &CubeMap::get_width); ClassDB::bind_method(D_METHOD("get_height"), &CubeMap::get_height); - //ClassDB::bind_method(D_METHOD("get_rid"),&CubeMap::get_rid); ClassDB::bind_method(D_METHOD("set_flags", "flags"), &CubeMap::set_flags); ClassDB::bind_method(D_METHOD("get_flags"), &CubeMap::get_flags); - ClassDB::bind_method(D_METHOD("set_side", "side", "image"), &CubeMap::set_side); ClassDB::bind_method(D_METHOD("get_side", "side"), &CubeMap::get_side); ClassDB::bind_method(D_METHOD("set_storage", "mode"), &CubeMap::set_storage); @@ -1335,6 +1333,9 @@ void CubeMap::_bind_methods() { ClassDB::bind_method(D_METHOD("set_lossy_storage_quality", "quality"), &CubeMap::set_lossy_storage_quality); ClassDB::bind_method(D_METHOD("get_lossy_storage_quality"), &CubeMap::get_lossy_storage_quality); + ADD_PROPERTY(PropertyInfo(Variant::INT, "storage_mode", PROPERTY_HINT_ENUM, "Raw,Lossy Compressed,Lossless Compressed"), "set_storage", "get_storage"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "lossy_storage_quality"), "set_lossy_storage_quality", "get_lossy_storage_quality"); + BIND_ENUM_CONSTANT(STORAGE_RAW); BIND_ENUM_CONSTANT(STORAGE_COMPRESS_LOSSY); BIND_ENUM_CONSTANT(STORAGE_COMPRESS_LOSSLESS); diff --git a/scene/resources/video_stream.h b/scene/resources/video_stream.h index 0f07233185..3f79858056 100644 --- a/scene/resources/video_stream.h +++ b/scene/resources/video_stream.h @@ -60,7 +60,7 @@ public: virtual void set_audio_track(int p_idx) = 0; - //virtual int mix(int16_t* p_bufer,int p_frames)=0; + //virtual int mix(int16_t* p_buffer,int p_frames)=0; virtual Ref<Texture> get_texture() = 0; virtual void update(float p_delta) = 0; |