diff options
Diffstat (limited to 'modules')
99 files changed, 2244 insertions, 2612 deletions
diff --git a/modules/bullet/SCsub b/modules/bullet/SCsub index ba57de303e..09509abc44 100644 --- a/modules/bullet/SCsub +++ b/modules/bullet/SCsub @@ -10,7 +10,7 @@ env_bullet = env_modules.Clone() thirdparty_obj = [] if env["builtin_bullet"]: - # Build only version 2 for now (as of 2.89) + # Build only "Bullet2" API (not "Bullet3" folders). # Sync file list with relevant upstream CMakeLists.txt for each folder. if env["float"] == "64": env.Append(CPPDEFINES=["BT_USE_DOUBLE_PRECISION=1"]) @@ -189,6 +189,7 @@ if env["builtin_bullet"]: "LinearMath/btGeometryUtil.cpp", "LinearMath/btPolarDecomposition.cpp", "LinearMath/btQuickprof.cpp", + "LinearMath/btReducedVector.cpp", "LinearMath/btSerializer.cpp", "LinearMath/btSerializer64.cpp", "LinearMath/btThreads.cpp", @@ -200,15 +201,11 @@ if env["builtin_bullet"]: thirdparty_sources = [thirdparty_dir + file for file in bullet2_src] - # Treat Bullet headers as system headers to avoid raising warnings. Not supported on MSVC. - if not env.msvc: - env_bullet.Append(CPPFLAGS=["-isystem", Dir(thirdparty_dir).path]) - else: - env_bullet.Prepend(CPPPATH=[thirdparty_dir]) + env_bullet.Prepend(CPPPATH=[thirdparty_dir]) if env["target"] == "debug" or env["target"] == "release_debug": env_bullet.Append(CPPDEFINES=["DEBUG"]) - env_bullet.Append(CPPDEFINES=["BT_USE_OLD_DAMPING_METHOD"]) + env_bullet.Append(CPPDEFINES=["BT_USE_OLD_DAMPING_METHOD", "BT_THREADSAFE"]) env_thirdparty = env_bullet.Clone() env_thirdparty.disable_warnings() diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp index ed05e51e53..3054debaec 100644 --- a/modules/bullet/bullet_physics_server.cpp +++ b/modules/bullet/bullet_physics_server.cpp @@ -124,7 +124,7 @@ RID BulletPhysicsServer3D::shape_create(ShapeType p_shape) { } void BulletPhysicsServer3D::shape_set_data(RID p_shape, const Variant &p_data) { - ShapeBullet *shape = shape_owner.getornull(p_shape); + ShapeBullet *shape = shape_owner.get_or_null(p_shape); ERR_FAIL_COND(!shape); shape->set_data(p_data); } @@ -134,25 +134,25 @@ void BulletPhysicsServer3D::shape_set_custom_solver_bias(RID p_shape, real_t p_b } PhysicsServer3D::ShapeType BulletPhysicsServer3D::shape_get_type(RID p_shape) const { - ShapeBullet *shape = shape_owner.getornull(p_shape); + ShapeBullet *shape = shape_owner.get_or_null(p_shape); ERR_FAIL_COND_V(!shape, PhysicsServer3D::SHAPE_CUSTOM); return shape->get_type(); } Variant BulletPhysicsServer3D::shape_get_data(RID p_shape) const { - ShapeBullet *shape = shape_owner.getornull(p_shape); + ShapeBullet *shape = shape_owner.get_or_null(p_shape); ERR_FAIL_COND_V(!shape, Variant()); return shape->get_data(); } void BulletPhysicsServer3D::shape_set_margin(RID p_shape, real_t p_margin) { - ShapeBullet *shape = shape_owner.getornull(p_shape); + ShapeBullet *shape = shape_owner.get_or_null(p_shape); ERR_FAIL_COND(!shape); shape->set_margin(p_margin); } real_t BulletPhysicsServer3D::shape_get_margin(RID p_shape) const { - ShapeBullet *shape = shape_owner.getornull(p_shape); + ShapeBullet *shape = shape_owner.get_or_null(p_shape); ERR_FAIL_COND_V(!shape, 0.0); return shape->get_margin(); } @@ -168,7 +168,7 @@ RID BulletPhysicsServer3D::space_create() { } void BulletPhysicsServer3D::space_set_active(RID p_space, bool p_active) { - SpaceBullet *space = space_owner.getornull(p_space); + SpaceBullet *space = space_owner.get_or_null(p_space); ERR_FAIL_COND(!space); if (space_is_active(p_space) == p_active) { @@ -185,47 +185,47 @@ void BulletPhysicsServer3D::space_set_active(RID p_space, bool p_active) { } bool BulletPhysicsServer3D::space_is_active(RID p_space) const { - SpaceBullet *space = space_owner.getornull(p_space); + SpaceBullet *space = space_owner.get_or_null(p_space); ERR_FAIL_COND_V(!space, false); return -1 != active_spaces.find(space); } void BulletPhysicsServer3D::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) { - SpaceBullet *space = space_owner.getornull(p_space); + SpaceBullet *space = space_owner.get_or_null(p_space); ERR_FAIL_COND(!space); space->set_param(p_param, p_value); } real_t BulletPhysicsServer3D::space_get_param(RID p_space, SpaceParameter p_param) const { - SpaceBullet *space = space_owner.getornull(p_space); + SpaceBullet *space = space_owner.get_or_null(p_space); ERR_FAIL_COND_V(!space, 0); return space->get_param(p_param); } PhysicsDirectSpaceState3D *BulletPhysicsServer3D::space_get_direct_state(RID p_space) { - SpaceBullet *space = space_owner.getornull(p_space); + SpaceBullet *space = space_owner.get_or_null(p_space); ERR_FAIL_COND_V(!space, nullptr); return space->get_direct_state(); } void BulletPhysicsServer3D::space_set_debug_contacts(RID p_space, int p_max_contacts) { - SpaceBullet *space = space_owner.getornull(p_space); + SpaceBullet *space = space_owner.get_or_null(p_space); ERR_FAIL_COND(!space); space->set_debug_contacts(p_max_contacts); } Vector<Vector3> BulletPhysicsServer3D::space_get_contacts(RID p_space) const { - SpaceBullet *space = space_owner.getornull(p_space); + SpaceBullet *space = space_owner.get_or_null(p_space); ERR_FAIL_COND_V(!space, Vector<Vector3>()); return space->get_debug_contacts(); } int BulletPhysicsServer3D::space_get_contact_count(RID p_space) const { - SpaceBullet *space = space_owner.getornull(p_space); + SpaceBullet *space = space_owner.get_or_null(p_space); ERR_FAIL_COND_V(!space, 0); return space->get_debug_contact_count(); @@ -239,91 +239,91 @@ RID BulletPhysicsServer3D::area_create() { } void BulletPhysicsServer3D::area_set_space(RID p_area, RID p_space) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); SpaceBullet *space = nullptr; if (p_space.is_valid()) { - space = space_owner.getornull(p_space); + space = space_owner.get_or_null(p_space); ERR_FAIL_COND(!space); } area->set_space(space); } RID BulletPhysicsServer3D::area_get_space(RID p_area) const { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); return area->get_space()->get_self(); } void BulletPhysicsServer3D::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); area->set_spOv_mode(p_mode); } PhysicsServer3D::AreaSpaceOverrideMode BulletPhysicsServer3D::area_get_space_override_mode(RID p_area) const { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND_V(!area, PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED); return area->get_spOv_mode(); } void BulletPhysicsServer3D::area_add_shape(RID p_area, RID p_shape, const Transform3D &p_transform, bool p_disabled) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); - ShapeBullet *shape = shape_owner.getornull(p_shape); + ShapeBullet *shape = shape_owner.get_or_null(p_shape); ERR_FAIL_COND(!shape); area->add_shape(shape, p_transform, p_disabled); } void BulletPhysicsServer3D::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); - ShapeBullet *shape = shape_owner.getornull(p_shape); + ShapeBullet *shape = shape_owner.get_or_null(p_shape); ERR_FAIL_COND(!shape); area->set_shape(p_shape_idx, shape); } void BulletPhysicsServer3D::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform3D &p_transform) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); area->set_shape_transform(p_shape_idx, p_transform); } int BulletPhysicsServer3D::area_get_shape_count(RID p_area) const { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND_V(!area, 0); return area->get_shape_count(); } RID BulletPhysicsServer3D::area_get_shape(RID p_area, int p_shape_idx) const { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND_V(!area, RID()); return area->get_shape(p_shape_idx)->get_self(); } Transform3D BulletPhysicsServer3D::area_get_shape_transform(RID p_area, int p_shape_idx) const { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND_V(!area, Transform3D()); return area->get_shape_transform(p_shape_idx); } void BulletPhysicsServer3D::area_remove_shape(RID p_area, int p_shape_idx) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); return area->remove_shape_full(p_shape_idx); } void BulletPhysicsServer3D::area_clear_shapes(RID p_area) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); for (int i = area->get_shape_count(); 0 < i; --i) { @@ -332,7 +332,7 @@ void BulletPhysicsServer3D::area_clear_shapes(RID p_area) { } void BulletPhysicsServer3D::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); area->set_shape_disabled(p_shape_idx, p_disabled); @@ -342,7 +342,7 @@ void BulletPhysicsServer3D::area_attach_object_instance_id(RID p_area, ObjectID if (space_owner.owns(p_area)) { return; } - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); area->set_instance_id(p_id); } @@ -351,19 +351,19 @@ ObjectID BulletPhysicsServer3D::area_get_object_instance_id(RID p_area) const { if (space_owner.owns(p_area)) { return ObjectID(); } - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND_V(!area, ObjectID()); return area->get_instance_id(); } void BulletPhysicsServer3D::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) { if (space_owner.owns(p_area)) { - SpaceBullet *space = space_owner.getornull(p_area); + SpaceBullet *space = space_owner.get_or_null(p_area); if (space) { space->set_param(p_param, p_value); } } else { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); area->set_param(p_param, p_value); @@ -372,10 +372,10 @@ void BulletPhysicsServer3D::area_set_param(RID p_area, AreaParameter p_param, co Variant BulletPhysicsServer3D::area_get_param(RID p_area, AreaParameter p_param) const { if (space_owner.owns(p_area)) { - SpaceBullet *space = space_owner.getornull(p_area); + SpaceBullet *space = space_owner.get_or_null(p_area); return space->get_param(p_param); } else { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND_V(!area, Variant()); return area->get_param(p_param); @@ -383,52 +383,52 @@ Variant BulletPhysicsServer3D::area_get_param(RID p_area, AreaParameter p_param) } void BulletPhysicsServer3D::area_set_transform(RID p_area, const Transform3D &p_transform) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); area->set_transform(p_transform); } Transform3D BulletPhysicsServer3D::area_get_transform(RID p_area) const { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND_V(!area, Transform3D()); return area->get_transform(); } void BulletPhysicsServer3D::area_set_collision_mask(RID p_area, uint32_t p_mask) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); area->set_collision_mask(p_mask); } void BulletPhysicsServer3D::area_set_collision_layer(RID p_area, uint32_t p_layer) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); area->set_collision_layer(p_layer); } void BulletPhysicsServer3D::area_set_monitorable(RID p_area, bool p_monitorable) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); area->set_monitorable(p_monitorable); } void BulletPhysicsServer3D::area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); area->set_event_callback(CollisionObjectBullet::TYPE_RIGID_BODY, p_receiver ? p_receiver->get_instance_id() : ObjectID(), p_method); } void BulletPhysicsServer3D::area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); area->set_event_callback(CollisionObjectBullet::TYPE_AREA, p_receiver ? p_receiver->get_instance_id() : ObjectID(), p_method); } void BulletPhysicsServer3D::area_set_ray_pickable(RID p_area, bool p_enable) { - AreaBullet *area = area_owner.getornull(p_area); + AreaBullet *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); area->set_ray_pickable(p_enable); } @@ -445,12 +445,12 @@ RID BulletPhysicsServer3D::body_create(BodyMode p_mode, bool p_init_sleeping) { } void BulletPhysicsServer3D::body_set_space(RID p_body, RID p_space) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); SpaceBullet *space = nullptr; if (p_space.is_valid()) { - space = space_owner.getornull(p_space); + space = space_owner.get_or_null(p_space); ERR_FAIL_COND(!space); } @@ -462,7 +462,7 @@ void BulletPhysicsServer3D::body_set_space(RID p_body, RID p_space) { } RID BulletPhysicsServer3D::body_get_space(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, RID()); SpaceBullet *space = body->get_space(); @@ -473,52 +473,52 @@ RID BulletPhysicsServer3D::body_get_space(RID p_body) const { } void BulletPhysicsServer3D::body_set_mode(RID p_body, PhysicsServer3D::BodyMode p_mode) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_mode(p_mode); } PhysicsServer3D::BodyMode BulletPhysicsServer3D::body_get_mode(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, BODY_MODE_STATIC); return body->get_mode(); } void BulletPhysicsServer3D::body_add_shape(RID p_body, RID p_shape, const Transform3D &p_transform, bool p_disabled) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); - ShapeBullet *shape = shape_owner.getornull(p_shape); + ShapeBullet *shape = shape_owner.get_or_null(p_shape); ERR_FAIL_COND(!shape); body->add_shape(shape, p_transform, p_disabled); } void BulletPhysicsServer3D::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); - ShapeBullet *shape = shape_owner.getornull(p_shape); + ShapeBullet *shape = shape_owner.get_or_null(p_shape); ERR_FAIL_COND(!shape); body->set_shape(p_shape_idx, shape); } void BulletPhysicsServer3D::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform3D &p_transform) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_shape_transform(p_shape_idx, p_transform); } int BulletPhysicsServer3D::body_get_shape_count(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_shape_count(); } RID BulletPhysicsServer3D::body_get_shape(RID p_body, int p_shape_idx) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, RID()); ShapeBullet *shape = body->get_shape(p_shape_idx); @@ -528,27 +528,27 @@ RID BulletPhysicsServer3D::body_get_shape(RID p_body, int p_shape_idx) const { } Transform3D BulletPhysicsServer3D::body_get_shape_transform(RID p_body, int p_shape_idx) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, Transform3D()); return body->get_shape_transform(p_shape_idx); } void BulletPhysicsServer3D::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_shape_disabled(p_shape_idx, p_disabled); } void BulletPhysicsServer3D::body_remove_shape(RID p_body, int p_shape_idx) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->remove_shape_full(p_shape_idx); } void BulletPhysicsServer3D::body_clear_shapes(RID p_body) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->remove_all_shapes(); @@ -569,42 +569,42 @@ ObjectID BulletPhysicsServer3D::body_get_object_instance_id(RID p_body) const { } void BulletPhysicsServer3D::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_continuous_collision_detection(p_enable); } bool BulletPhysicsServer3D::body_is_continuous_collision_detection_enabled(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, false); return body->is_continuous_collision_detection_enabled(); } void BulletPhysicsServer3D::body_set_collision_layer(RID p_body, uint32_t p_layer) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_collision_layer(p_layer); } uint32_t BulletPhysicsServer3D::body_get_collision_layer(RID p_body) const { - const RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + const RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_layer(); } void BulletPhysicsServer3D::body_set_collision_mask(RID p_body, uint32_t p_mask) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_collision_mask(p_mask); } uint32_t BulletPhysicsServer3D::body_get_collision_mask(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_mask(); @@ -620,21 +620,21 @@ uint32_t BulletPhysicsServer3D::body_get_user_flags(RID p_body) const { } void BulletPhysicsServer3D::body_set_param(RID p_body, BodyParameter p_param, real_t p_value) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_param(p_param, p_value); } real_t BulletPhysicsServer3D::body_get_param(RID p_body, BodyParameter p_param) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_param(p_param); } void BulletPhysicsServer3D::body_set_kinematic_safe_margin(RID p_body, real_t p_margin) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); if (body->get_kinematic_utilities()) { @@ -643,7 +643,7 @@ void BulletPhysicsServer3D::body_set_kinematic_safe_margin(RID p_body, real_t p_ } real_t BulletPhysicsServer3D::body_get_kinematic_safe_margin(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0); if (body->get_kinematic_utilities()) { @@ -654,90 +654,90 @@ real_t BulletPhysicsServer3D::body_get_kinematic_safe_margin(RID p_body) const { } void BulletPhysicsServer3D::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_state(p_state, p_variant); } Variant BulletPhysicsServer3D::body_get_state(RID p_body, BodyState p_state) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, Variant()); return body->get_state(p_state); } void BulletPhysicsServer3D::body_set_applied_force(RID p_body, const Vector3 &p_force) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_applied_force(p_force); } Vector3 BulletPhysicsServer3D::body_get_applied_force(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, Vector3()); return body->get_applied_force(); } void BulletPhysicsServer3D::body_set_applied_torque(RID p_body, const Vector3 &p_torque) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_applied_torque(p_torque); } Vector3 BulletPhysicsServer3D::body_get_applied_torque(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, Vector3()); return body->get_applied_torque(); } void BulletPhysicsServer3D::body_add_central_force(RID p_body, const Vector3 &p_force) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->apply_central_force(p_force); } void BulletPhysicsServer3D::body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->apply_force(p_force, p_position); } void BulletPhysicsServer3D::body_add_torque(RID p_body, const Vector3 &p_torque) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->apply_torque(p_torque); } void BulletPhysicsServer3D::body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->apply_central_impulse(p_impulse); } void BulletPhysicsServer3D::body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->apply_impulse(p_impulse, p_position); } void BulletPhysicsServer3D::body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->apply_torque_impulse(p_impulse); } void BulletPhysicsServer3D::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); Vector3 v = body->get_linear_velocity(); @@ -748,39 +748,39 @@ void BulletPhysicsServer3D::body_set_axis_velocity(RID p_body, const Vector3 &p_ } void BulletPhysicsServer3D::body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_axis_lock(p_axis, p_lock); } bool BulletPhysicsServer3D::body_is_axis_locked(RID p_body, BodyAxis p_axis) const { - const RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + const RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0); return body->is_axis_locked(p_axis); } void BulletPhysicsServer3D::body_add_collision_exception(RID p_body, RID p_body_b) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); - RigidBodyBullet *other_body = rigid_body_owner.getornull(p_body_b); + RigidBodyBullet *other_body = rigid_body_owner.get_or_null(p_body_b); ERR_FAIL_COND(!other_body); body->add_collision_exception(other_body); } void BulletPhysicsServer3D::body_remove_collision_exception(RID p_body, RID p_body_b) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); - RigidBodyBullet *other_body = rigid_body_owner.getornull(p_body_b); + RigidBodyBullet *other_body = rigid_body_owner.get_or_null(p_body_b); ERR_FAIL_COND(!other_body); body->remove_collision_exception(other_body); } void BulletPhysicsServer3D::body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); for (int i = 0; i < body->get_exceptions().size(); i++) { p_exceptions->push_back(body->get_exceptions()[i]); @@ -788,14 +788,14 @@ void BulletPhysicsServer3D::body_get_collision_exceptions(RID p_body, List<RID> } void BulletPhysicsServer3D::body_set_max_contacts_reported(RID p_body, int p_contacts) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_max_collisions_detection(p_contacts); } int BulletPhysicsServer3D::body_get_max_contacts_reported(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_max_collisions_detection(); @@ -811,39 +811,39 @@ real_t BulletPhysicsServer3D::body_get_contacts_reported_depth_threshold(RID p_b } void BulletPhysicsServer3D::body_set_omit_force_integration(RID p_body, bool p_omit) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_omit_forces_integration(p_omit); } bool BulletPhysicsServer3D::body_is_omitting_force_integration(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, false); return body->get_omit_forces_integration(); } void BulletPhysicsServer3D::body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_force_integration_callback(p_callable, p_udata); } void BulletPhysicsServer3D::body_set_ray_pickable(RID p_body, bool p_enable) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_ray_pickable(p_enable); } PhysicsDirectBodyState3D *BulletPhysicsServer3D::body_get_direct_state(RID p_body) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, nullptr); return BulletPhysicsDirectBodyState3D::get_singleton(body); } bool BulletPhysicsServer3D::body_test_motion(RID p_body, const Transform3D &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result, bool p_exclude_raycast_shapes, const Set<RID> &p_exclude) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, false); ERR_FAIL_COND_V(!body->get_space(), false); @@ -851,7 +851,7 @@ bool BulletPhysicsServer3D::body_test_motion(RID p_body, const Transform3D &p_fr } int BulletPhysicsServer3D::body_test_ray_separation(RID p_body, const Transform3D &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, real_t p_margin) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0); ERR_FAIL_COND_V(!body->get_space(), 0); @@ -869,19 +869,19 @@ RID BulletPhysicsServer3D::soft_body_create(bool p_init_sleeping) { } void BulletPhysicsServer3D::soft_body_update_rendering_server(RID p_body, RenderingServerHandler *p_rendering_server_handler) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->update_rendering_server(p_rendering_server_handler); } void BulletPhysicsServer3D::soft_body_set_space(RID p_body, RID p_space) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); SpaceBullet *space = nullptr; if (p_space.is_valid()) { - space = space_owner.getornull(p_space); + space = space_owner.get_or_null(p_space); ERR_FAIL_COND(!space); } @@ -893,7 +893,7 @@ void BulletPhysicsServer3D::soft_body_set_space(RID p_body, RID p_space) { } RID BulletPhysicsServer3D::soft_body_get_space(RID p_body) const { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, RID()); SpaceBullet *space = body->get_space(); @@ -904,7 +904,7 @@ RID BulletPhysicsServer3D::soft_body_get_space(RID p_body) const { } void BulletPhysicsServer3D::soft_body_set_mesh(RID p_body, const REF &p_mesh) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_soft_mesh(p_mesh); @@ -918,40 +918,40 @@ AABB BulletPhysicsServer::soft_body_get_bounds(RID p_body) const { } void BulletPhysicsServer3D::soft_body_set_collision_layer(RID p_body, uint32_t p_layer) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_collision_layer(p_layer); } uint32_t BulletPhysicsServer3D::soft_body_get_collision_layer(RID p_body) const { - const SoftBodyBullet *body = soft_body_owner.getornull(p_body); + const SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_layer(); } void BulletPhysicsServer3D::soft_body_set_collision_mask(RID p_body, uint32_t p_mask) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_collision_mask(p_mask); } uint32_t BulletPhysicsServer3D::soft_body_get_collision_mask(RID p_body) const { - const SoftBodyBullet *body = soft_body_owner.getornull(p_body); + const SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_mask(); } void BulletPhysicsServer3D::soft_body_add_collision_exception(RID p_body, RID p_body_b) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); - CollisionObjectBullet *other_body = rigid_body_owner.getornull(p_body_b); + CollisionObjectBullet *other_body = rigid_body_owner.get_or_null(p_body_b); if (!other_body) { - other_body = soft_body_owner.getornull(p_body_b); + other_body = soft_body_owner.get_or_null(p_body_b); } ERR_FAIL_COND(!other_body); @@ -959,12 +959,12 @@ void BulletPhysicsServer3D::soft_body_add_collision_exception(RID p_body, RID p_ } void BulletPhysicsServer3D::soft_body_remove_collision_exception(RID p_body, RID p_body_b) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); - CollisionObjectBullet *other_body = rigid_body_owner.getornull(p_body_b); + CollisionObjectBullet *other_body = rigid_body_owner.get_or_null(p_body_b); if (!other_body) { - other_body = soft_body_owner.getornull(p_body_b); + other_body = soft_body_owner.get_or_null(p_body_b); } ERR_FAIL_COND(!other_body); @@ -972,7 +972,7 @@ void BulletPhysicsServer3D::soft_body_remove_collision_exception(RID p_body, RID } void BulletPhysicsServer3D::soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); for (int i = 0; i < body->get_exceptions().size(); i++) { p_exceptions->push_back(body->get_exceptions()[i]); @@ -991,98 +991,98 @@ Variant BulletPhysicsServer3D::soft_body_get_state(RID p_body, BodyState p_state } void BulletPhysicsServer3D::soft_body_set_transform(RID p_body, const Transform3D &p_transform) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_soft_transform(p_transform); } void BulletPhysicsServer3D::soft_body_set_ray_pickable(RID p_body, bool p_enable) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_ray_pickable(p_enable); } void BulletPhysicsServer3D::soft_body_set_simulation_precision(RID p_body, int p_simulation_precision) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_simulation_precision(p_simulation_precision); } int BulletPhysicsServer3D::soft_body_get_simulation_precision(RID p_body) const { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_simulation_precision(); } void BulletPhysicsServer3D::soft_body_set_total_mass(RID p_body, real_t p_total_mass) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_total_mass(p_total_mass); } real_t BulletPhysicsServer3D::soft_body_get_total_mass(RID p_body) const { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_total_mass(); } void BulletPhysicsServer3D::soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) const { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_linear_stiffness(p_stiffness); } real_t BulletPhysicsServer3D::soft_body_get_linear_stiffness(RID p_body) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_linear_stiffness(); } void BulletPhysicsServer3D::soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_pressure_coefficient(p_pressure_coefficient); } real_t BulletPhysicsServer3D::soft_body_get_pressure_coefficient(RID p_body) const { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_pressure_coefficient(); } void BulletPhysicsServer3D::soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_damping_coefficient(p_damping_coefficient); } real_t BulletPhysicsServer3D::soft_body_get_damping_coefficient(RID p_body) const { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_damping_coefficient(); } void BulletPhysicsServer3D::soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_drag_coefficient(p_drag_coefficient); } real_t BulletPhysicsServer3D::soft_body_get_drag_coefficient(RID p_body) const { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_drag_coefficient(); } void BulletPhysicsServer3D::soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_node_position(p_point_index, p_global_position); } Vector3 BulletPhysicsServer3D::soft_body_get_point_global_position(RID p_body, int p_point_index) const { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, Vector3(0., 0., 0.)); Vector3 pos; body->get_node_position(p_point_index, pos); @@ -1090,25 +1090,25 @@ Vector3 BulletPhysicsServer3D::soft_body_get_point_global_position(RID p_body, i } void BulletPhysicsServer3D::soft_body_remove_all_pinned_points(RID p_body) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->reset_all_node_mass(); } void BulletPhysicsServer3D::soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); body->set_node_mass(p_point_index, p_pin ? 0 : 1); } bool BulletPhysicsServer3D::soft_body_is_point_pinned(RID p_body, int p_point_index) const { - SoftBodyBullet *body = soft_body_owner.getornull(p_body); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_node_mass(p_point_index); } PhysicsServer3D::JointType BulletPhysicsServer3D::joint_get_type(RID p_joint) const { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND_V(!joint, JOINT_PIN); return joint->get_type(); } @@ -1123,28 +1123,28 @@ int BulletPhysicsServer3D::joint_get_solver_priority(RID p_joint) const { } void BulletPhysicsServer3D::joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND(!joint); joint->disable_collisions_between_bodies(p_disable); } bool BulletPhysicsServer3D::joint_is_disabled_collisions_between_bodies(RID p_joint) const { - JointBullet *joint(joint_owner.getornull(p_joint)); + JointBullet *joint(joint_owner.get_or_null(p_joint)); ERR_FAIL_COND_V(!joint, false); return joint->is_disabled_collisions_between_bodies(); } RID BulletPhysicsServer3D::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) { - RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); + RigidBodyBullet *body_A = rigid_body_owner.get_or_null(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); RigidBodyBullet *body_B = nullptr; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.getornull(p_body_B); + body_B = rigid_body_owner.get_or_null(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1158,7 +1158,7 @@ RID BulletPhysicsServer3D::joint_create_pin(RID p_body_A, const Vector3 &p_local } void BulletPhysicsServer3D::pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_PIN); PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint); @@ -1166,7 +1166,7 @@ void BulletPhysicsServer3D::pin_joint_set_param(RID p_joint, PinJointParam p_par } real_t BulletPhysicsServer3D::pin_joint_get_param(RID p_joint, PinJointParam p_param) const { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, 0); PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint); @@ -1174,7 +1174,7 @@ real_t BulletPhysicsServer3D::pin_joint_get_param(RID p_joint, PinJointParam p_p } void BulletPhysicsServer3D::pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_PIN); PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint); @@ -1182,7 +1182,7 @@ void BulletPhysicsServer3D::pin_joint_set_local_a(RID p_joint, const Vector3 &p_ } Vector3 BulletPhysicsServer3D::pin_joint_get_local_a(RID p_joint) const { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND_V(!joint, Vector3()); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3()); PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint); @@ -1190,7 +1190,7 @@ Vector3 BulletPhysicsServer3D::pin_joint_get_local_a(RID p_joint) const { } void BulletPhysicsServer3D::pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_PIN); PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint); @@ -1198,7 +1198,7 @@ void BulletPhysicsServer3D::pin_joint_set_local_b(RID p_joint, const Vector3 &p_ } Vector3 BulletPhysicsServer3D::pin_joint_get_local_b(RID p_joint) const { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND_V(!joint, Vector3()); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3()); PinJointBullet *pin_joint = static_cast<PinJointBullet *>(joint); @@ -1206,13 +1206,13 @@ Vector3 BulletPhysicsServer3D::pin_joint_get_local_b(RID p_joint) const { } RID BulletPhysicsServer3D::joint_create_hinge(RID p_body_A, const Transform3D &p_hinge_A, RID p_body_B, const Transform3D &p_hinge_B) { - RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); + RigidBodyBullet *body_A = rigid_body_owner.get_or_null(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); RigidBodyBullet *body_B = nullptr; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.getornull(p_body_B); + body_B = rigid_body_owner.get_or_null(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1226,13 +1226,13 @@ RID BulletPhysicsServer3D::joint_create_hinge(RID p_body_A, const Transform3D &p } RID BulletPhysicsServer3D::joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B) { - RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); + RigidBodyBullet *body_A = rigid_body_owner.get_or_null(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); RigidBodyBullet *body_B = nullptr; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.getornull(p_body_B); + body_B = rigid_body_owner.get_or_null(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1246,7 +1246,7 @@ RID BulletPhysicsServer3D::joint_create_hinge_simple(RID p_body_A, const Vector3 } void BulletPhysicsServer3D::hinge_joint_set_param(RID p_joint, HingeJointParam p_param, real_t p_value) { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_HINGE); HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint); @@ -1254,7 +1254,7 @@ void BulletPhysicsServer3D::hinge_joint_set_param(RID p_joint, HingeJointParam p } real_t BulletPhysicsServer3D::hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, 0); HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint); @@ -1262,7 +1262,7 @@ real_t BulletPhysicsServer3D::hinge_joint_get_param(RID p_joint, HingeJointParam } void BulletPhysicsServer3D::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value) { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_HINGE); HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint); @@ -1270,7 +1270,7 @@ void BulletPhysicsServer3D::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_f } bool BulletPhysicsServer3D::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND_V(!joint, false); ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, false); HingeJointBullet *hinge_joint = static_cast<HingeJointBullet *>(joint); @@ -1278,13 +1278,13 @@ bool BulletPhysicsServer3D::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_f } RID BulletPhysicsServer3D::joint_create_slider(RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) { - RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); + RigidBodyBullet *body_A = rigid_body_owner.get_or_null(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); RigidBodyBullet *body_B = nullptr; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.getornull(p_body_B); + body_B = rigid_body_owner.get_or_null(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1298,7 +1298,7 @@ RID BulletPhysicsServer3D::joint_create_slider(RID p_body_A, const Transform3D & } void BulletPhysicsServer3D::slider_joint_set_param(RID p_joint, SliderJointParam p_param, real_t p_value) { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_SLIDER); SliderJointBullet *slider_joint = static_cast<SliderJointBullet *>(joint); @@ -1306,7 +1306,7 @@ void BulletPhysicsServer3D::slider_joint_set_param(RID p_joint, SliderJointParam } real_t BulletPhysicsServer3D::slider_joint_get_param(RID p_joint, SliderJointParam p_param) const { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_SLIDER, 0); SliderJointBullet *slider_joint = static_cast<SliderJointBullet *>(joint); @@ -1314,13 +1314,13 @@ real_t BulletPhysicsServer3D::slider_joint_get_param(RID p_joint, SliderJointPar } RID BulletPhysicsServer3D::joint_create_cone_twist(RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) { - RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); + RigidBodyBullet *body_A = rigid_body_owner.get_or_null(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); RigidBodyBullet *body_B = nullptr; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.getornull(p_body_B); + body_B = rigid_body_owner.get_or_null(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1332,7 +1332,7 @@ RID BulletPhysicsServer3D::joint_create_cone_twist(RID p_body_A, const Transform } void BulletPhysicsServer3D::cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, real_t p_value) { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_CONE_TWIST); ConeTwistJointBullet *coneTwist_joint = static_cast<ConeTwistJointBullet *>(joint); @@ -1340,7 +1340,7 @@ void BulletPhysicsServer3D::cone_twist_joint_set_param(RID p_joint, ConeTwistJoi } real_t BulletPhysicsServer3D::cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND_V(!joint, 0.); ERR_FAIL_COND_V(joint->get_type() != JOINT_CONE_TWIST, 0.); ConeTwistJointBullet *coneTwist_joint = static_cast<ConeTwistJointBullet *>(joint); @@ -1348,13 +1348,13 @@ real_t BulletPhysicsServer3D::cone_twist_joint_get_param(RID p_joint, ConeTwistJ } RID BulletPhysicsServer3D::joint_create_generic_6dof(RID p_body_A, const Transform3D &p_local_frame_A, RID p_body_B, const Transform3D &p_local_frame_B) { - RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); + RigidBodyBullet *body_A = rigid_body_owner.get_or_null(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); RigidBodyBullet *body_B = nullptr; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.getornull(p_body_B); + body_B = rigid_body_owner.get_or_null(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1368,7 +1368,7 @@ RID BulletPhysicsServer3D::joint_create_generic_6dof(RID p_body_A, const Transfo } void BulletPhysicsServer3D::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, real_t p_value) { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_6DOF); Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint); @@ -1376,7 +1376,7 @@ void BulletPhysicsServer3D::generic_6dof_joint_set_param(RID p_joint, Vector3::A } real_t BulletPhysicsServer3D::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param) { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, 0); Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint); @@ -1384,7 +1384,7 @@ real_t BulletPhysicsServer3D::generic_6dof_joint_get_param(RID p_joint, Vector3: } void BulletPhysicsServer3D::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable) { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_6DOF); Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint); @@ -1392,7 +1392,7 @@ void BulletPhysicsServer3D::generic_6dof_joint_set_flag(RID p_joint, Vector3::Ax } bool BulletPhysicsServer3D::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag) { - JointBullet *joint = joint_owner.getornull(p_joint); + JointBullet *joint = joint_owner.get_or_null(p_joint); ERR_FAIL_COND_V(!joint, false); ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, false); Generic6DOFJointBullet *generic_6dof_joint = static_cast<Generic6DOFJointBullet *>(joint); @@ -1401,7 +1401,7 @@ bool BulletPhysicsServer3D::generic_6dof_joint_get_flag(RID p_joint, Vector3::Ax void BulletPhysicsServer3D::free(RID p_rid) { if (shape_owner.owns(p_rid)) { - ShapeBullet *shape = shape_owner.getornull(p_rid); + ShapeBullet *shape = shape_owner.get_or_null(p_rid); // Notify the shape is configured for (Map<ShapeOwnerBullet *, int>::Element *element = shape->get_owners().front(); element; element = element->next()) { @@ -1411,7 +1411,7 @@ void BulletPhysicsServer3D::free(RID p_rid) { shape_owner.free(p_rid); bulletdelete(shape); } else if (rigid_body_owner.owns(p_rid)) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_rid); + RigidBodyBullet *body = rigid_body_owner.get_or_null(p_rid); body->set_space(nullptr); @@ -1421,7 +1421,7 @@ void BulletPhysicsServer3D::free(RID p_rid) { bulletdelete(body); } else if (soft_body_owner.owns(p_rid)) { - SoftBodyBullet *body = soft_body_owner.getornull(p_rid); + SoftBodyBullet *body = soft_body_owner.get_or_null(p_rid); body->set_space(nullptr); @@ -1429,7 +1429,7 @@ void BulletPhysicsServer3D::free(RID p_rid) { bulletdelete(body); } else if (area_owner.owns(p_rid)) { - AreaBullet *area = area_owner.getornull(p_rid); + AreaBullet *area = area_owner.get_or_null(p_rid); area->set_space(nullptr); @@ -1439,13 +1439,13 @@ void BulletPhysicsServer3D::free(RID p_rid) { bulletdelete(area); } else if (joint_owner.owns(p_rid)) { - JointBullet *joint = joint_owner.getornull(p_rid); + JointBullet *joint = joint_owner.get_or_null(p_rid); joint->destroy_internal_constraint(); joint_owner.free(p_rid); bulletdelete(joint); } else if (space_owner.owns(p_rid)) { - SpaceBullet *space = space_owner.getornull(p_rid); + SpaceBullet *space = space_owner.get_or_null(p_rid); space->remove_all_collision_objects(); @@ -1493,38 +1493,38 @@ int BulletPhysicsServer3D::get_process_info(ProcessInfo p_info) { SpaceBullet *BulletPhysicsServer3D::get_space(RID p_rid) const { ERR_FAIL_COND_V_MSG(space_owner.owns(p_rid) == false, nullptr, "The RID is not valid."); - return space_owner.getornull(p_rid); + return space_owner.get_or_null(p_rid); } ShapeBullet *BulletPhysicsServer3D::get_shape(RID p_rid) const { ERR_FAIL_COND_V_MSG(shape_owner.owns(p_rid) == false, nullptr, "The RID is not valid."); - return shape_owner.getornull(p_rid); + return shape_owner.get_or_null(p_rid); } CollisionObjectBullet *BulletPhysicsServer3D::get_collision_object(RID p_object) const { if (rigid_body_owner.owns(p_object)) { - return rigid_body_owner.getornull(p_object); + return rigid_body_owner.get_or_null(p_object); } if (area_owner.owns(p_object)) { - return area_owner.getornull(p_object); + return area_owner.get_or_null(p_object); } if (soft_body_owner.owns(p_object)) { - return soft_body_owner.getornull(p_object); + return soft_body_owner.get_or_null(p_object); } ERR_FAIL_V_MSG(nullptr, "The RID is no valid."); } RigidCollisionObjectBullet *BulletPhysicsServer3D::get_rigid_collision_object(RID p_object) const { if (rigid_body_owner.owns(p_object)) { - return rigid_body_owner.getornull(p_object); + return rigid_body_owner.get_or_null(p_object); } if (area_owner.owns(p_object)) { - return area_owner.getornull(p_object); + return area_owner.get_or_null(p_object); } ERR_FAIL_V_MSG(nullptr, "The RID is no valid."); } JointBullet *BulletPhysicsServer3D::get_joint(RID p_rid) const { ERR_FAIL_COND_V_MSG(joint_owner.owns(p_rid) == false, nullptr, "The RID is not valid."); - return joint_owner.getornull(p_rid); + return joint_owner.get_or_null(p_rid); } diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index 0d2cd1f5a0..7b20fad28c 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -303,6 +303,7 @@ RigidBodyBullet::~RigidBodyBullet() { void RigidBodyBullet::init_kinematic_utilities() { kinematic_utilities = memnew(KinematicUtilities(this)); + reload_kinematic_shapes(); } void RigidBodyBullet::destroy_kinematic_utilities() { @@ -529,26 +530,23 @@ void RigidBodyBullet::set_mode(PhysicsServer3D::BodyMode p_mode) { can_integrate_forces = false; destroy_kinematic_utilities(); // The mode change is relevant to its mass + mode = p_mode; switch (p_mode) { case PhysicsServer3D::BODY_MODE_KINEMATIC: - mode = PhysicsServer3D::BODY_MODE_KINEMATIC; reload_axis_lock(); _internal_set_mass(0); init_kinematic_utilities(); break; case PhysicsServer3D::BODY_MODE_STATIC: - mode = PhysicsServer3D::BODY_MODE_STATIC; reload_axis_lock(); _internal_set_mass(0); break; case PhysicsServer3D::BODY_MODE_DYNAMIC: - mode = PhysicsServer3D::BODY_MODE_DYNAMIC; reload_axis_lock(); _internal_set_mass(0 == mass ? 1 : mass); scratch_space_override_modificator(); break; - case PhysicsServer3D::MODE_DYNAMIC_LOCKED: - mode = PhysicsServer3D::MODE_DYNAMIC_LOCKED; + case PhysicsServer3D::MODE_DYNAMIC_LINEAR: reload_axis_lock(); _internal_set_mass(0 == mass ? 1 : mass); scratch_space_override_modificator(); @@ -721,7 +719,7 @@ bool RigidBodyBullet::is_axis_locked(PhysicsServer3D::BodyAxis p_axis) const { void RigidBodyBullet::reload_axis_lock() { btBody->setLinearFactor(btVector3(btScalar(!is_axis_locked(PhysicsServer3D::BODY_AXIS_LINEAR_X)), btScalar(!is_axis_locked(PhysicsServer3D::BODY_AXIS_LINEAR_Y)), btScalar(!is_axis_locked(PhysicsServer3D::BODY_AXIS_LINEAR_Z)))); - if (PhysicsServer3D::MODE_DYNAMIC_LOCKED == mode) { + if (PhysicsServer3D::MODE_DYNAMIC_LINEAR == mode) { /// When character angular is always locked btBody->setAngularFactor(btVector3(0., 0., 0.)); } else { @@ -1016,7 +1014,7 @@ void RigidBodyBullet::_internal_set_mass(real_t p_mass) { // Rigidbody is dynamic if and only if mass is non Zero, otherwise static const bool isDynamic = p_mass != 0.f; if (isDynamic) { - if (PhysicsServer3D::BODY_MODE_DYNAMIC != mode && PhysicsServer3D::MODE_DYNAMIC_LOCKED != mode) { + if (PhysicsServer3D::BODY_MODE_DYNAMIC != mode && PhysicsServer3D::MODE_DYNAMIC_LINEAR != mode) { return; } diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index a9a811c445..66d7370bd7 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -122,7 +122,7 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra return 0; } - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); + ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get_or_null(p_shape); ERR_FAIL_COND_V(!shape, 0); btCollisionShape *btShape = shape->create_bt_shape(p_xform.basis.get_scale_abs(), p_margin); @@ -158,7 +158,7 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf btVector3 bt_motion; G_TO_B(p_motion, bt_motion); - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); + ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get_or_null(p_shape); ERR_FAIL_COND_V(!shape, false); btCollisionShape *btShape = shape->create_bt_shape(p_xform.basis.get_scale(), p_margin); @@ -219,7 +219,7 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform3D return false; } - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); + ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get_or_null(p_shape); ERR_FAIL_COND_V(!shape, false); btCollisionShape *btShape = shape->create_bt_shape(p_shape_xform.basis.get_scale_abs(), p_margin); @@ -251,7 +251,7 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform3D } bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform3D &p_shape_xform, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); + ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get_or_null(p_shape); ERR_FAIL_COND_V(!shape, false); btCollisionShape *btShape = shape->create_bt_shape(p_shape_xform.basis.get_scale_abs(), p_margin); @@ -947,7 +947,6 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform3D &p if (!p_body->get_kinematic_utilities()) { p_body->init_kinematic_utilities(); - p_body->reload_kinematic_shapes(); } btVector3 initial_recover_motion(0, 0, 0); @@ -1089,7 +1088,6 @@ int SpaceBullet::test_ray_separation(RigidBodyBullet *p_body, const Transform3D if (!p_body->get_kinematic_utilities()) { p_body->init_kinematic_utilities(); - p_body->reload_kinematic_shapes(); } btVector3 recover_motion(0, 0, 0); diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp index cbe41a1310..229e1e2724 100644 --- a/modules/csg/csg.cpp +++ b/modules/csg/csg.cpp @@ -37,16 +37,16 @@ // Static helper functions. inline static bool is_snapable(const Vector3 &p_point1, const Vector3 &p_point2, real_t p_distance) { - return (p_point1 - p_point2).length_squared() < p_distance * p_distance; + return p_point2.distance_squared_to(p_point1) < p_distance * p_distance; } -inline static Vector2 interpolate_segment_uv(const Vector2 p_segement_points[2], const Vector2 p_uvs[2], const Vector2 &p_interpolation_point) { - float segment_length = (p_segement_points[1] - p_segement_points[0]).length(); - if (p_segement_points[0].is_equal_approx(p_segement_points[1])) { +inline static Vector2 interpolate_segment_uv(const Vector2 p_segment_points[2], const Vector2 p_uvs[2], const Vector2 &p_interpolation_point) { + if (p_segment_points[0].is_equal_approx(p_segment_points[1])) { return p_uvs[0]; } - float distance = (p_interpolation_point - p_segement_points[0]).length(); + float segment_length = p_segment_points[0].distance_to(p_segment_points[1]); + float distance = p_segment_points[0].distance_to(p_interpolation_point); float fraction = distance / segment_length; return p_uvs[0].lerp(p_uvs[1], fraction); @@ -162,7 +162,7 @@ inline static bool is_triangle_degenerate(const Vector2 p_vertices[3], real_t p_ return det < p_vertex_snap2; } -inline static bool are_segements_parallel(const Vector2 p_segment1_points[2], const Vector2 p_segment2_points[2], float p_vertex_snap2) { +inline static bool are_segments_parallel(const Vector2 p_segment1_points[2], const Vector2 p_segment2_points[2], float p_vertex_snap2) { Vector2 segment1 = p_segment1_points[1] - p_segment1_points[0]; Vector2 segment2 = p_segment2_points[1] - p_segment2_points[0]; real_t segment1_length2 = segment1.dot(segment1); @@ -596,7 +596,7 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de _add_distance(intersectionsA, intersectionsB, current_face.from_b, 0); } } else if (ray_intersects_triangle(face_center, face_normal, current_points, CMP_EPSILON, intersection_point)) { - real_t distance = (intersection_point - face_center).length(); + real_t distance = face_center.distance_to(intersection_point); _add_distance(intersectionsA, intersectionsB, current_face.from_b, distance); } } @@ -781,7 +781,7 @@ void CSGBrushOperation::MeshMerge::add_face(const Vector3 p_points[], const Vect int CSGBrushOperation::Build2DFaces::_get_point_idx(const Vector2 &p_point) { for (int vertex_idx = 0; vertex_idx < vertices.size(); ++vertex_idx) { - if ((p_point - vertices[vertex_idx].point).length_squared() < vertex_snap2) { + if (vertices[vertex_idx].point.distance_squared_to(p_point) < vertex_snap2) { return vertex_idx; } } @@ -911,7 +911,7 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ vertices[outer_edge_idx[1]].point, vertices[p_segment_indices[closest_idx]].point }; - if (are_segements_parallel(edge1, edge2, vertex_snap2)) { + if (are_segments_parallel(edge1, edge2, vertex_snap2)) { if (!degenerate_points.find(outer_edge_idx[0])) { degenerate_points.push_back(outer_edge_idx[0]); } @@ -961,7 +961,7 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ // Check if point is existing face vertex. bool existing = false; for (int i = 0; i < 3; ++i) { - if ((point_2D - face_vertices[i].point).length_squared() < vertex_snap2) { + if (face_vertices[i].point.distance_squared_to(point_2D) < vertex_snap2) { existing = true; break; } @@ -978,7 +978,7 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ }; Vector2 closest_point = Geometry2D::get_closest_point_to_segment(point_2D, edge_points); - if ((closest_point - point_2D).length_squared() < vertex_snap2) { + if (point_2D.distance_squared_to(closest_point) < vertex_snap2) { int opposite_vertex_idx = face.vertex_idx[(face_edge_idx + 2) % 3]; // If new vertex snaps to degenerate vertex, just delete this face. @@ -1041,7 +1041,7 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s bool on_edge = false; for (int edge_point_idx = 0; edge_point_idx < 2; ++edge_point_idx) { intersection_point = Geometry2D::get_closest_point_to_segment(p_segment_points[edge_point_idx], edge_points); - if ((intersection_point - p_segment_points[edge_point_idx]).length_squared() < vertex_snap2) { + if (p_segment_points[edge_point_idx].distance_squared_to(intersection_point) < vertex_snap2) { on_edge = true; break; } @@ -1050,13 +1050,13 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s // Else check if the segment intersects the edge. if (on_edge || Geometry2D::segment_intersects_segment(p_segment_points[0], p_segment_points[1], edge_points[0], edge_points[1], &intersection_point)) { // Check if intersection point is an edge point. - if ((intersection_point - edge_points[0]).length_squared() < vertex_snap2 || - (intersection_point - edge_points[1]).length_squared() < vertex_snap2) { + if ((edge_points[0].distance_squared_to(intersection_point) < vertex_snap2) || + (edge_points[1].distance_squared_to(intersection_point) < vertex_snap2)) { continue; } // Check if edge exists, by checking if the intersecting segment is parallel to the edge. - if (are_segements_parallel(p_segment_points, edge_points, vertex_snap2)) { + if (are_segments_parallel(p_segment_points, edge_points, vertex_snap2)) { continue; } @@ -1078,7 +1078,7 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s // If opposite point is on the segment, add its index to segment indices too. Vector2 closest_point = Geometry2D::get_closest_point_to_segment(vertices[opposite_vertex_idx].point, p_segment_points); - if ((closest_point - vertices[opposite_vertex_idx].point).length_squared() < vertex_snap2) { + if (vertices[opposite_vertex_idx].point.distance_squared_to(closest_point) < vertex_snap2) { _add_vertex_idx_sorted(r_segment_indices, opposite_vertex_idx); } @@ -1132,7 +1132,7 @@ int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) { // Check if point is existing face vertex. for (int i = 0; i < 3; ++i) { - if ((p_point - face_vertices[i].point).length_squared() < vertex_snap2) { + if (face_vertices[i].point.distance_squared_to(p_point) < vertex_snap2) { return face.vertex_idx[i]; } } @@ -1150,7 +1150,7 @@ int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) { }; Vector2 closest_point = Geometry2D::get_closest_point_to_segment(p_point, edge_points); - if ((closest_point - p_point).length_squared() < vertex_snap2) { + if (p_point.distance_squared_to(closest_point) < vertex_snap2) { on_edge = true; // Add the point as a new vertex. @@ -1172,8 +1172,8 @@ int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) { Vector2 split_edge1[2] = { vertices[new_vertex_idx].point, edge_points[0] }; Vector2 split_edge2[2] = { vertices[new_vertex_idx].point, edge_points[1] }; Vector2 new_edge[2] = { vertices[new_vertex_idx].point, vertices[opposite_vertex_idx].point }; - if (are_segements_parallel(split_edge1, new_edge, vertex_snap2) && - are_segements_parallel(split_edge2, new_edge, vertex_snap2)) { + if (are_segments_parallel(split_edge1, new_edge, vertex_snap2) && + are_segments_parallel(split_edge2, new_edge, vertex_snap2)) { break; } diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp index 452fb32d9d..e4297a593e 100644 --- a/modules/csg/csg_shape.cpp +++ b/modules/csg/csg_shape.cpp @@ -1732,6 +1732,7 @@ CSGBrush *CSGPolygon3D::_build_brush() { int extrusion_face_count = shape_sides * 2; int end_count = 0; int shape_face_count = shape_faces.size() / 3; + real_t curve_length = 1.0; switch (mode) { case MODE_DEPTH: extrusions = 1; @@ -1744,7 +1745,12 @@ CSGBrush *CSGPolygon3D::_build_brush() { } break; case MODE_PATH: { - extrusions = Math::ceil(1.0 * curve->get_point_count() / path_interval); + curve_length = curve->get_baked_length(); + if (path_interval_type == PATH_INTERVAL_DISTANCE) { + extrusions = MAX(1, Math::ceil(curve_length / path_interval)) + 1; + } else { + extrusions = Math::ceil(1.0 * curve->get_point_count() / path_interval); + } if (!path_joined) { end_count = 2; extrusions -= 1; @@ -1767,212 +1773,245 @@ CSGBrush *CSGPolygon3D::_build_brush() { smooth.resize(face_count); materials.resize(face_count); invert.resize(face_count); + int faces_removed = 0; - Vector3 *facesw = faces.ptrw(); - Vector2 *uvsw = uvs.ptrw(); - bool *smoothw = smooth.ptrw(); - Ref<Material> *materialsw = materials.ptrw(); - bool *invertw = invert.ptrw(); - - int face = 0; - Transform3D base_xform; - Transform3D current_xform; - Transform3D previous_xform; - double u_step = 1.0 / extrusions; - double v_step = 1.0 / shape_sides; - double spin_step = Math::deg2rad(spin_degrees / spin_sides); - double extrusion_step = 1.0 / extrusions; - if (mode == MODE_PATH) { - if (path_joined) { - extrusion_step = 1.0 / (extrusions - 1); - } - extrusion_step *= curve->get_baked_length(); - } + { + Vector3 *facesw = faces.ptrw(); + Vector2 *uvsw = uvs.ptrw(); + bool *smoothw = smooth.ptrw(); + Ref<Material> *materialsw = materials.ptrw(); + bool *invertw = invert.ptrw(); - if (mode == MODE_PATH) { - if (!path_local) { - base_xform = path->get_global_transform(); + int face = 0; + Transform3D base_xform; + Transform3D current_xform; + Transform3D previous_xform; + Transform3D previous_previous_xform; + double u_step = 1.0 / extrusions; + if (path_u_distance > 0.0) { + u_step *= curve_length / path_u_distance; + } + double v_step = 1.0 / shape_sides; + double spin_step = Math::deg2rad(spin_degrees / spin_sides); + double extrusion_step = 1.0 / extrusions; + if (mode == MODE_PATH) { + if (path_joined) { + extrusion_step = 1.0 / (extrusions - 1); + } + extrusion_step *= curve_length; } - Vector3 current_point = curve->interpolate_baked(0); - Vector3 next_point = curve->interpolate_baked(extrusion_step); - Vector3 current_up = Vector3(0, 1, 0); - Vector3 direction = next_point - current_point; + if (mode == MODE_PATH) { + if (!path_local) { + base_xform = path->get_global_transform(); + } - if (path_joined) { - Vector3 last_point = curve->interpolate_baked(curve->get_baked_length()); - direction = next_point - last_point; - } + Vector3 current_point = curve->interpolate_baked(0); + Vector3 next_point = curve->interpolate_baked(extrusion_step); + Vector3 current_up = Vector3(0, 1, 0); + Vector3 direction = next_point - current_point; - switch (path_rotation) { - case PATH_ROTATION_POLYGON: - direction = Vector3(0, 0, -1); - break; - case PATH_ROTATION_PATH: - break; - case PATH_ROTATION_PATH_FOLLOW: - current_up = curve->interpolate_baked_up_vector(0); - break; + if (path_joined) { + Vector3 last_point = curve->interpolate_baked(curve->get_baked_length()); + direction = next_point - last_point; + } + + switch (path_rotation) { + case PATH_ROTATION_POLYGON: + direction = Vector3(0, 0, -1); + break; + case PATH_ROTATION_PATH: + break; + case PATH_ROTATION_PATH_FOLLOW: + current_up = curve->interpolate_baked_up_vector(0); + break; + } + + Transform3D facing = Transform3D().looking_at(direction, current_up); + current_xform = base_xform.translated(current_point) * facing; } - Transform3D facing = Transform3D().looking_at(direction, current_up); - current_xform = base_xform.translated(current_point) * facing; - } + // Create the mesh. + if (end_count > 0) { + // Add front end face. + for (int face_idx = 0; face_idx < shape_face_count; face_idx++) { + for (int face_vertex_idx = 0; face_vertex_idx < 3; face_vertex_idx++) { + // We need to reverse the rotation of the shape face vertices. + int index = shape_faces[face_idx * 3 + 2 - face_vertex_idx]; + Point2 p = shape_polygon[index]; + Point2 uv = (p - shape_rect.position) / shape_rect.size; + + // Use the left side of the bottom half of the y-inverted texture. + uv.x = uv.x / 2; + uv.y = 1 - (uv.y / 2); + + facesw[face * 3 + face_vertex_idx] = current_xform.xform(Vector3(p.x, p.y, 0)); + uvsw[face * 3 + face_vertex_idx] = uv; + } - // Create the mesh. - if (end_count > 0) { - // Add front end face. - for (int face_idx = 0; face_idx < shape_face_count; face_idx++) { - for (int face_vertex_idx = 0; face_vertex_idx < 3; face_vertex_idx++) { - // We need to reverse the rotation of the shape face vertices. - int index = shape_faces[face_idx * 3 + 2 - face_vertex_idx]; - Point2 p = shape_polygon[index]; - Point2 uv = (p - shape_rect.position) / shape_rect.size; - - // Use the left side of the bottom half of the y-inverted texture. - uv.x = uv.x / 2; - uv.y = 1 - (uv.y / 2); - - facesw[face * 3 + face_vertex_idx] = current_xform.xform(Vector3(p.x, p.y, 0)); - uvsw[face * 3 + face_vertex_idx] = uv; + smoothw[face] = false; + materialsw[face] = material; + invertw[face] = invert_faces; + face++; } - - smoothw[face] = false; - materialsw[face] = material; - invertw[face] = invert_faces; - face++; } - } - // Add extrusion faces. - for (int x0 = 0; x0 < extrusions; x0++) { - previous_xform = current_xform; - - switch (mode) { - case MODE_DEPTH: { - current_xform.translate(Vector3(0, 0, -depth)); - } break; - case MODE_SPIN: { - current_xform.rotate(Vector3(0, 1, 0), spin_step); - } break; - case MODE_PATH: { - double previous_offset = x0 * extrusion_step; - double current_offset = (x0 + 1) * extrusion_step; - double next_offset = (x0 + 2) * extrusion_step; - if (x0 == extrusions - 1) { - if (path_joined) { - current_offset = 0; - next_offset = extrusion_step; + real_t angle_simplify_dot = Math::cos(Math::deg2rad(path_simplify_angle)); + Vector3 previous_simplify_dir = Vector3(0, 0, 0); + int faces_combined = 0; + + // Add extrusion faces. + for (int x0 = 0; x0 < extrusions; x0++) { + previous_previous_xform = previous_xform; + previous_xform = current_xform; + + switch (mode) { + case MODE_DEPTH: { + current_xform.translate(Vector3(0, 0, -depth)); + } break; + case MODE_SPIN: { + current_xform.rotate(Vector3(0, 1, 0), spin_step); + } break; + case MODE_PATH: { + double previous_offset = x0 * extrusion_step; + double current_offset = (x0 + 1) * extrusion_step; + double next_offset = (x0 + 2) * extrusion_step; + if (x0 == extrusions - 1) { + if (path_joined) { + current_offset = 0; + next_offset = extrusion_step; + } else { + next_offset = current_offset; + } + } + + Vector3 previous_point = curve->interpolate_baked(previous_offset); + Vector3 current_point = curve->interpolate_baked(current_offset); + Vector3 next_point = curve->interpolate_baked(next_offset); + Vector3 current_up = Vector3(0, 1, 0); + Vector3 direction = next_point - previous_point; + Vector3 current_dir = (current_point - previous_point).normalized(); + + // If the angles are similar, remove the previous face and replace it with this one. + if (path_simplify_angle > 0.0 && x0 > 0 && previous_simplify_dir.dot(current_dir) > angle_simplify_dot) { + faces_combined += 1; + previous_xform = previous_previous_xform; + face -= extrusion_face_count; + faces_removed += extrusion_face_count; } else { - next_offset = current_offset; + faces_combined = 0; + previous_simplify_dir = current_dir; } - } - Vector3 previous_point = curve->interpolate_baked(previous_offset); - Vector3 current_point = curve->interpolate_baked(current_offset); - Vector3 next_point = curve->interpolate_baked(next_offset); - Vector3 current_up = Vector3(0, 1, 0); - Vector3 direction = next_point - previous_point; + switch (path_rotation) { + case PATH_ROTATION_POLYGON: + direction = Vector3(0, 0, -1); + break; + case PATH_ROTATION_PATH: + break; + case PATH_ROTATION_PATH_FOLLOW: + current_up = curve->interpolate_baked_up_vector(current_offset); + break; + } - switch (path_rotation) { - case PATH_ROTATION_POLYGON: - direction = Vector3(0, 0, -1); - break; - case PATH_ROTATION_PATH: - break; - case PATH_ROTATION_PATH_FOLLOW: - current_up = curve->interpolate_baked_up_vector(current_offset); - break; - } + Transform3D facing = Transform3D().looking_at(direction, current_up); + current_xform = base_xform.translated(current_point) * facing; + } break; + } - Transform3D facing = Transform3D().looking_at(direction, current_up); - current_xform = base_xform.translated(current_point) * facing; - } break; - } + double u0 = (x0 - faces_combined) * u_step; + double u1 = ((x0 + 1) * u_step); + if (mode == MODE_PATH && !path_continuous_u) { + u0 = 0.0; + u1 = 1.0; + } - double u0 = x0 * u_step; - double u1 = ((x0 + 1) * u_step); - if (mode == MODE_PATH && !path_continuous_u) { - u0 = 0.0; - u1 = 1.0; - } + for (int y0 = 0; y0 < shape_sides; y0++) { + int y1 = (y0 + 1) % shape_sides; + // Use the top half of the texture. + double v0 = (y0 * v_step) / 2; + double v1 = ((y0 + 1) * v_step) / 2; - for (int y0 = 0; y0 < shape_sides; y0++) { - int y1 = (y0 + 1) % shape_sides; - // Use the top half of the texture. - double v0 = (y0 * v_step) / 2; - double v1 = ((y0 + 1) * v_step) / 2; - - Vector3 v[4] = { - previous_xform.xform(Vector3(shape_polygon[y0].x, shape_polygon[y0].y, 0)), - current_xform.xform(Vector3(shape_polygon[y0].x, shape_polygon[y0].y, 0)), - current_xform.xform(Vector3(shape_polygon[y1].x, shape_polygon[y1].y, 0)), - previous_xform.xform(Vector3(shape_polygon[y1].x, shape_polygon[y1].y, 0)), - }; - - Vector2 u[4] = { - Vector2(u0, v0), - Vector2(u1, v0), - Vector2(u1, v1), - Vector2(u0, v1), - }; - - // Face 1 - facesw[face * 3 + 0] = v[0]; - facesw[face * 3 + 1] = v[1]; - facesw[face * 3 + 2] = v[2]; - - uvsw[face * 3 + 0] = u[0]; - uvsw[face * 3 + 1] = u[1]; - uvsw[face * 3 + 2] = u[2]; - - smoothw[face] = smooth_faces; - invertw[face] = invert_faces; - materialsw[face] = material; - - face++; - - // Face 2 - facesw[face * 3 + 0] = v[2]; - facesw[face * 3 + 1] = v[3]; - facesw[face * 3 + 2] = v[0]; - - uvsw[face * 3 + 0] = u[2]; - uvsw[face * 3 + 1] = u[3]; - uvsw[face * 3 + 2] = u[0]; - - smoothw[face] = smooth_faces; - invertw[face] = invert_faces; - materialsw[face] = material; - - face++; - } - } + Vector3 v[4] = { + previous_xform.xform(Vector3(shape_polygon[y0].x, shape_polygon[y0].y, 0)), + current_xform.xform(Vector3(shape_polygon[y0].x, shape_polygon[y0].y, 0)), + current_xform.xform(Vector3(shape_polygon[y1].x, shape_polygon[y1].y, 0)), + previous_xform.xform(Vector3(shape_polygon[y1].x, shape_polygon[y1].y, 0)), + }; - if (end_count > 1) { - // Add back end face. - for (int face_idx = 0; face_idx < shape_face_count; face_idx++) { - for (int face_vertex_idx = 0; face_vertex_idx < 3; face_vertex_idx++) { - int index = shape_faces[face_idx * 3 + face_vertex_idx]; - Point2 p = shape_polygon[index]; - Point2 uv = (p - shape_rect.position) / shape_rect.size; + Vector2 u[4] = { + Vector2(u0, v0), + Vector2(u1, v0), + Vector2(u1, v1), + Vector2(u0, v1), + }; - // Use the x-inverted ride side of the bottom half of the y-inverted texture. - uv.x = 1 - uv.x / 2; - uv.y = 1 - (uv.y / 2); + // Face 1 + facesw[face * 3 + 0] = v[0]; + facesw[face * 3 + 1] = v[1]; + facesw[face * 3 + 2] = v[2]; - facesw[face * 3 + face_vertex_idx] = current_xform.xform(Vector3(p.x, p.y, 0)); - uvsw[face * 3 + face_vertex_idx] = uv; + uvsw[face * 3 + 0] = u[0]; + uvsw[face * 3 + 1] = u[1]; + uvsw[face * 3 + 2] = u[2]; + + smoothw[face] = smooth_faces; + invertw[face] = invert_faces; + materialsw[face] = material; + + face++; + + // Face 2 + facesw[face * 3 + 0] = v[2]; + facesw[face * 3 + 1] = v[3]; + facesw[face * 3 + 2] = v[0]; + + uvsw[face * 3 + 0] = u[2]; + uvsw[face * 3 + 1] = u[3]; + uvsw[face * 3 + 2] = u[0]; + + smoothw[face] = smooth_faces; + invertw[face] = invert_faces; + materialsw[face] = material; + + face++; } + } + + if (end_count > 1) { + // Add back end face. + for (int face_idx = 0; face_idx < shape_face_count; face_idx++) { + for (int face_vertex_idx = 0; face_vertex_idx < 3; face_vertex_idx++) { + int index = shape_faces[face_idx * 3 + face_vertex_idx]; + Point2 p = shape_polygon[index]; + Point2 uv = (p - shape_rect.position) / shape_rect.size; - smoothw[face] = false; - materialsw[face] = material; - invertw[face] = invert_faces; - face++; + // Use the x-inverted ride side of the bottom half of the y-inverted texture. + uv.x = 1 - uv.x / 2; + uv.y = 1 - (uv.y / 2); + + facesw[face * 3 + face_vertex_idx] = current_xform.xform(Vector3(p.x, p.y, 0)); + uvsw[face * 3 + face_vertex_idx] = uv; + } + + smoothw[face] = false; + materialsw[face] = material; + invertw[face] = invert_faces; + face++; + } } + + face_count -= faces_removed; + ERR_FAIL_COND_V_MSG(face != face_count, brush, "Bug: Failed to create the CSGPolygon mesh correctly."); } - ERR_FAIL_COND_V_MSG(face != face_count, brush, "Bug: Failed to create the CSGPolygon mesh correctly."); + if (faces_removed > 0) { + faces.resize(face_count * 3); + uvs.resize(face_count * 3); + smooth.resize(face_count); + materials.resize(face_count); + invert.resize(face_count); + } brush->build_from_faces(faces, uvs, smooth, materials, invert); @@ -2031,9 +2070,15 @@ void CSGPolygon3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_path_node", "path"), &CSGPolygon3D::set_path_node); ClassDB::bind_method(D_METHOD("get_path_node"), &CSGPolygon3D::get_path_node); + ClassDB::bind_method(D_METHOD("set_path_interval_type", "interval_type"), &CSGPolygon3D::set_path_interval_type); + ClassDB::bind_method(D_METHOD("get_path_interval_type"), &CSGPolygon3D::get_path_interval_type); + ClassDB::bind_method(D_METHOD("set_path_interval", "interval"), &CSGPolygon3D::set_path_interval); ClassDB::bind_method(D_METHOD("get_path_interval"), &CSGPolygon3D::get_path_interval); + ClassDB::bind_method(D_METHOD("set_path_simplify_angle", "degrees"), &CSGPolygon3D::set_path_simplify_angle); + ClassDB::bind_method(D_METHOD("get_path_simplify_angle"), &CSGPolygon3D::get_path_simplify_angle); + ClassDB::bind_method(D_METHOD("set_path_rotation", "path_rotation"), &CSGPolygon3D::set_path_rotation); ClassDB::bind_method(D_METHOD("get_path_rotation"), &CSGPolygon3D::get_path_rotation); @@ -2043,6 +2088,9 @@ void CSGPolygon3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_path_continuous_u", "enable"), &CSGPolygon3D::set_path_continuous_u); ClassDB::bind_method(D_METHOD("is_path_continuous_u"), &CSGPolygon3D::is_path_continuous_u); + ClassDB::bind_method(D_METHOD("set_path_u_distance", "distance"), &CSGPolygon3D::set_path_u_distance); + ClassDB::bind_method(D_METHOD("get_path_u_distance"), &CSGPolygon3D::get_path_u_distance); + ClassDB::bind_method(D_METHOD("set_path_joined", "enable"), &CSGPolygon3D::set_path_joined); ClassDB::bind_method(D_METHOD("is_path_joined"), &CSGPolygon3D::is_path_joined); @@ -2061,10 +2109,13 @@ void CSGPolygon3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "spin_degrees", PROPERTY_HINT_RANGE, "1,360,0.1"), "set_spin_degrees", "get_spin_degrees"); ADD_PROPERTY(PropertyInfo(Variant::INT, "spin_sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_spin_sides", "get_spin_sides"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "path_node", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Path3D"), "set_path_node", "get_path_node"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_interval", PROPERTY_HINT_RANGE, "0.1,1.0,0.05,exp"), "set_path_interval", "get_path_interval"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "path_interval_type", PROPERTY_HINT_ENUM, "Distance,Subdivide"), "set_path_interval_type", "get_path_interval_type"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_interval", PROPERTY_HINT_RANGE, "0.01,1.0,0.01,exp,or_greater"), "set_path_interval", "get_path_interval"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_simplify_angle", PROPERTY_HINT_RANGE, "0.0,180.0,0.1,exp"), "set_path_simplify_angle", "get_path_simplify_angle"); ADD_PROPERTY(PropertyInfo(Variant::INT, "path_rotation", PROPERTY_HINT_ENUM, "Polygon,Path,PathFollow"), "set_path_rotation", "get_path_rotation"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "path_local"), "set_path_local", "is_path_local"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "path_continuous_u"), "set_path_continuous_u", "is_path_continuous_u"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_u_distance", PROPERTY_HINT_RANGE, "0.0,10.0,0.01,or_greater"), "set_path_u_distance", "get_path_u_distance"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "path_joined"), "set_path_joined", "is_path_joined"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); @@ -2076,6 +2127,9 @@ void CSGPolygon3D::_bind_methods() { BIND_ENUM_CONSTANT(PATH_ROTATION_POLYGON); BIND_ENUM_CONSTANT(PATH_ROTATION_PATH); BIND_ENUM_CONSTANT(PATH_ROTATION_PATH_FOLLOW); + + BIND_ENUM_CONSTANT(PATH_INTERVAL_DISTANCE); + BIND_ENUM_CONSTANT(PATH_INTERVAL_SUBDIVIDE); } void CSGPolygon3D::set_polygon(const Vector<Vector2> &p_polygon) { @@ -2119,6 +2173,16 @@ bool CSGPolygon3D::is_path_continuous_u() const { return path_continuous_u; } +void CSGPolygon3D::set_path_u_distance(real_t p_path_u_distance) { + path_u_distance = p_path_u_distance; + _make_dirty(); + update_gizmos(); +} + +real_t CSGPolygon3D::get_path_u_distance() const { + return path_u_distance; +} + void CSGPolygon3D::set_spin_degrees(const float p_spin_degrees) { ERR_FAIL_COND(p_spin_degrees < 0.01 || p_spin_degrees > 360); spin_degrees = p_spin_degrees; @@ -2151,8 +2215,17 @@ NodePath CSGPolygon3D::get_path_node() const { return path_node; } +void CSGPolygon3D::set_path_interval_type(PathIntervalType p_interval_type) { + path_interval_type = p_interval_type; + _make_dirty(); + update_gizmos(); +} + +CSGPolygon3D::PathIntervalType CSGPolygon3D::get_path_interval_type() const { + return path_interval_type; +} + void CSGPolygon3D::set_path_interval(float p_interval) { - ERR_FAIL_COND_MSG(p_interval <= 0 || p_interval > 1, "Path interval must be greater than 0 and less than or equal to 1.0."); path_interval = p_interval; _make_dirty(); update_gizmos(); @@ -2162,6 +2235,16 @@ float CSGPolygon3D::get_path_interval() const { return path_interval; } +void CSGPolygon3D::set_path_simplify_angle(float p_angle) { + path_simplify_angle = p_angle; + _make_dirty(); + update_gizmos(); +} + +float CSGPolygon3D::get_path_simplify_angle() const { + return path_simplify_angle; +} + void CSGPolygon3D::set_path_rotation(PathRotation p_rotation) { path_rotation = p_rotation; _make_dirty(); @@ -2229,10 +2312,13 @@ CSGPolygon3D::CSGPolygon3D() { spin_degrees = 360; spin_sides = 8; smooth_faces = false; + path_interval_type = PATH_INTERVAL_DISTANCE; path_interval = 1.0; + path_simplify_angle = 0.0; path_rotation = PATH_ROTATION_PATH_FOLLOW; path_local = false; path_continuous_u = true; + path_u_distance = 1.0; path_joined = false; path = nullptr; } diff --git a/modules/csg/csg_shape.h b/modules/csg/csg_shape.h index 5cf371665e..c85cce776b 100644 --- a/modules/csg/csg_shape.h +++ b/modules/csg/csg_shape.h @@ -336,6 +336,11 @@ public: MODE_PATH }; + enum PathIntervalType { + PATH_INTERVAL_DISTANCE, + PATH_INTERVAL_SUBDIVIDE + }; + enum PathRotation { PATH_ROTATION_POLYGON, PATH_ROTATION_PATH, @@ -356,7 +361,9 @@ private: int spin_sides; NodePath path_node; + PathIntervalType path_interval_type; float path_interval; + float path_simplify_angle; PathRotation path_rotation; bool path_local; @@ -364,6 +371,7 @@ private: bool smooth_faces; bool path_continuous_u; + real_t path_u_distance; bool path_joined; bool _is_editable_3d_polygon() const; @@ -396,9 +404,15 @@ public: void set_path_node(const NodePath &p_path); NodePath get_path_node() const; + void set_path_interval_type(PathIntervalType p_interval_type); + PathIntervalType get_path_interval_type() const; + void set_path_interval(float p_interval); float get_path_interval() const; + void set_path_simplify_angle(float p_angle); + float get_path_simplify_angle() const; + void set_path_rotation(PathRotation p_rotation); PathRotation get_path_rotation() const; @@ -408,6 +422,9 @@ public: void set_path_continuous_u(bool p_enable); bool is_path_continuous_u() const; + void set_path_u_distance(real_t p_path_u_distance); + real_t get_path_u_distance() const; + void set_path_joined(bool p_enable); bool is_path_joined() const; @@ -422,5 +439,6 @@ public: VARIANT_ENUM_CAST(CSGPolygon3D::Mode) VARIANT_ENUM_CAST(CSGPolygon3D::PathRotation) +VARIANT_ENUM_CAST(CSGPolygon3D::PathIntervalType) #endif // CSG_SHAPE_H diff --git a/modules/csg/doc_classes/CSGPolygon3D.xml b/modules/csg/doc_classes/CSGPolygon3D.xml index 5d56e56de9..ecbb7962d1 100644 --- a/modules/csg/doc_classes/CSGPolygon3D.xml +++ b/modules/csg/doc_classes/CSGPolygon3D.xml @@ -24,6 +24,9 @@ <member name="path_interval" type="float" setter="set_path_interval" getter="get_path_interval"> When [member mode] is [constant MODE_PATH], the path interval or ratio of path points to extrusions. </member> + <member name="path_interval_type" type="int" setter="set_path_interval_type" getter="get_path_interval_type" enum="CSGPolygon3D.PathIntervalType"> + When [member mode] is [constant MODE_PATH], this will determine if the interval should be by distance ([constant PATH_INTERVAL_DISTANCE]) or subdivision fractions ([constant PATH_INTERVAL_SUBDIVIDE]). + </member> <member name="path_joined" type="bool" setter="set_path_joined" getter="is_path_joined"> When [member mode] is [constant MODE_PATH], if [code]true[/code] the ends of the path are joined, by adding an extrusion between the last and first points of the path. </member> @@ -36,6 +39,12 @@ <member name="path_rotation" type="int" setter="set_path_rotation" getter="get_path_rotation" enum="CSGPolygon3D.PathRotation"> When [member mode] is [constant MODE_PATH], the [enum PathRotation] method used to rotate the [member polygon] as it is extruded. </member> + <member name="path_simplify_angle" type="float" setter="set_path_simplify_angle" getter="get_path_simplify_angle"> + When [member mode] is [constant MODE_PATH], extrusions that are less than this angle, will be merged together to reduce polygon count. + </member> + <member name="path_u_distance" type="float" setter="set_path_u_distance" getter="get_path_u_distance"> + When [member mode] is [constant MODE_PATH], this is the distance along the path, in meters, the texture coordinates will tile. When set to 0, texture coordinates will match geometry exactly with no tiling. + </member> <member name="polygon" type="PackedVector2Array" setter="set_polygon" getter="get_polygon" default="PackedVector2Array(0, 0, 0, 1, 1, 1, 1, 0)"> The point array that defines the 2D polygon that is extruded. </member> @@ -70,5 +79,11 @@ <constant name="PATH_ROTATION_PATH_FOLLOW" value="2" enum="PathRotation"> The [member polygon] shape follows the path and its rotations around the path axis. </constant> + <constant name="PATH_INTERVAL_DISTANCE" value="0" enum="PathIntervalType"> + When [member mode] is set to [constant MODE_PATH], [member path_interval] will determine the distance, in meters, each interval of the path will extrude. + </constant> + <constant name="PATH_INTERVAL_SUBDIVIDE" value="1" enum="PathIntervalType"> + When [member mode] is set to [constant MODE_PATH], [member path_interval] will subdivide the polygons along the path. + </constant> </constants> </class> diff --git a/modules/enet/doc_classes/ENetMultiplayerPeer.xml b/modules/enet/doc_classes/ENetMultiplayerPeer.xml index 456b390dbb..f9659c092a 100644 --- a/modules/enet/doc_classes/ENetMultiplayerPeer.xml +++ b/modules/enet/doc_classes/ENetMultiplayerPeer.xml @@ -77,10 +77,8 @@ <member name="host" type="ENetConnection" setter="" getter="get_host"> The underlying [ENetConnection] created after [method create_client] and [method create_server]. </member> - <member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" /> <member name="server_relay" type="bool" setter="set_server_relay_enabled" getter="is_server_relay_enabled" default="true"> Enable or disable the server feature that notifies clients of other peers' connection/disconnection, and relays messages between them. When this option is [code]false[/code], clients won't be automatically notified of other peers and won't be able to send them packets through the server. </member> - <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="TransferMode" default="2" /> </members> </class> diff --git a/modules/enet/doc_classes/ENetPacketPeer.xml b/modules/enet/doc_classes/ENetPacketPeer.xml index 8f0693fb01..4116ba17f2 100644 --- a/modules/enet/doc_classes/ENetPacketPeer.xml +++ b/modules/enet/doc_classes/ENetPacketPeer.xml @@ -6,6 +6,7 @@ <description> A PacketPeer implementation representing a peer of an [ENetConnection]. This class cannot be instantiated directly but can be retrieved during [method ENetConnection.service] or via [method ENetConnection.get_peers]. + [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> <link title="API documentation on the ENet website">http://enet.bespin.org/usergroup0.html</link> diff --git a/modules/enet/enet_multiplayer_peer.cpp b/modules/enet/enet_multiplayer_peer.cpp index afd31207f6..52eb46f070 100644 --- a/modules/enet/enet_multiplayer_peer.cpp +++ b/modules/enet/enet_multiplayer_peer.cpp @@ -33,22 +33,6 @@ #include "core/io/marshalls.h" #include "core/os/os.h" -void ENetMultiplayerPeer::set_transfer_channel(int p_channel) { - transfer_channel = p_channel; -} - -int ENetMultiplayerPeer::get_transfer_channel() const { - return transfer_channel; -} - -void ENetMultiplayerPeer::set_transfer_mode(Multiplayer::TransferMode p_mode) { - transfer_mode = p_mode; -} - -Multiplayer::TransferMode ENetMultiplayerPeer::get_transfer_mode() const { - return transfer_mode; -} - void ENetMultiplayerPeer::set_target_peer(int p_peer) { target_peer = p_peer; } @@ -62,6 +46,7 @@ int ENetMultiplayerPeer::get_packet_peer() const { Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_max_channels, int p_in_bandwidth, int p_out_bandwidth) { ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active."); + set_refuse_new_connections(false); Ref<ENetConnection> host; host.instantiate(); Error err = host->create_host_bound(bind_ip, p_port, p_max_clients, 0, p_max_channels > 0 ? p_max_channels + SYSCH_MAX : 0, p_out_bandwidth); @@ -70,7 +55,6 @@ Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_ma } active_mode = MODE_SERVER; - refuse_connections = false; unique_id = 1; connection_status = CONNECTION_CONNECTED; hosts[0] = host; @@ -79,6 +63,7 @@ Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_ma Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, int p_channel_count, int p_in_bandwidth, int p_out_bandwidth, int p_local_port) { ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active."); + set_refuse_new_connections(false); Ref<ENetConnection> host; host.instantiate(); Error err; @@ -102,7 +87,6 @@ Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, in // Need to wait for CONNECT event. connection_status = CONNECTION_CONNECTING; active_mode = MODE_CLIENT; - refuse_connections = false; peers[1] = peer; hosts[0] = host; @@ -113,7 +97,6 @@ Error ENetMultiplayerPeer::create_mesh(int p_id) { ERR_FAIL_COND_V_MSG(p_id <= 0, ERR_INVALID_PARAMETER, "The unique ID must be greater then 0"); ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active."); active_mode = MODE_MESH; - refuse_connections = false; unique_id = p_id; connection_status = CONNECTION_CONNECTED; return OK; @@ -145,7 +128,7 @@ bool ENetMultiplayerPeer::_poll_server() { } switch (ret) { case ENetConnection::EVENT_CONNECT: { - if (refuse_connections) { + if (is_refusing_new_connections()) { event.peer->reset(); return false; } @@ -173,7 +156,7 @@ bool ENetMultiplayerPeer::_poll_server() { emit_signal(SNAME("peer_disconnected"), id); peers.erase(id); - if (!server_relay) { + if (server_relay) { _notify_peers(id, false); } return false; @@ -423,6 +406,7 @@ void ENetMultiplayerPeer::close_connection(uint32_t wait_usec) { hosts.clear(); unique_id = 0; connection_status = CONNECTION_DISCONNECTED; + set_refuse_new_connections(false); } int ENetMultiplayerPeer::get_available_packet_count() const { @@ -451,10 +435,11 @@ Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size int packet_flags = 0; int channel = SYSCH_RELIABLE; + int transfer_channel = get_transfer_channel(); if (transfer_channel > 0) { channel = SYSCH_MAX + transfer_channel - 1; } else { - switch (transfer_mode) { + switch (get_transfer_mode()) { case Multiplayer::TRANSFER_MODE_UNRELIABLE: { packet_flags = ENET_PACKET_FLAG_UNSEQUENCED; channel = SYSCH_UNRELIABLE; @@ -545,19 +530,15 @@ int ENetMultiplayerPeer::get_unique_id() const { return unique_id; } -void ENetMultiplayerPeer::set_refuse_new_connections(bool p_enable) { - refuse_connections = p_enable; +void ENetMultiplayerPeer::set_refuse_new_connections(bool p_enabled) { #ifdef GODOT_ENET if (_is_active()) { for (KeyValue<int, Ref<ENetConnection>> &E : hosts) { - E.value->refuse_new_connections(p_enable); + E.value->refuse_new_connections(p_enabled); } } #endif -} - -bool ENetMultiplayerPeer::is_refusing_new_connections() const { - return refuse_connections; + MultiplayerPeer::set_refuse_new_connections(p_enabled); } void ENetMultiplayerPeer::set_server_relay_enabled(bool p_enabled) { diff --git a/modules/enet/enet_multiplayer_peer.h b/modules/enet/enet_multiplayer_peer.h index b5316b8292..7a60e2359c 100644 --- a/modules/enet/enet_multiplayer_peer.h +++ b/modules/enet/enet_multiplayer_peer.h @@ -65,10 +65,7 @@ private: uint32_t unique_id = 0; int target_peer = 0; - int transfer_channel = 0; - Multiplayer::TransferMode transfer_mode = Multiplayer::TRANSFER_MODE_RELIABLE; - bool refuse_connections = false; bool server_relay = true; ConnectionStatus connection_status = CONNECTION_DISCONNECTED; @@ -101,40 +98,31 @@ protected: static void _bind_methods(); public: - virtual void set_transfer_channel(int p_channel) override; - virtual int get_transfer_channel() const override; - - virtual void set_transfer_mode(Multiplayer::TransferMode p_mode) override; - virtual Multiplayer::TransferMode get_transfer_mode() const override; virtual void set_target_peer(int p_peer) override; - virtual int get_packet_peer() const override; - Error create_server(int p_port, int p_max_clients = 32, int p_max_channels = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0); - Error create_client(const String &p_address, int p_port, int p_channel_count = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0, int p_local_port = 0); - Error create_mesh(int p_id); - Error add_mesh_peer(int p_id, Ref<ENetConnection> p_host); - - void close_connection(uint32_t wait_usec = 100); - - void disconnect_peer(int p_peer, bool now = false); - virtual void poll() override; - virtual bool is_server() const override; + // Overriden so we can instrument the DTLSServer when needed. + virtual void set_refuse_new_connections(bool p_enabled) override; - virtual int get_available_packet_count() const override; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; + virtual ConnectionStatus get_connection_status() const override; + + virtual int get_unique_id() const override; virtual int get_max_packet_size() const override; + virtual int get_available_packet_count() const override; + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; + virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; - virtual ConnectionStatus get_connection_status() const override; + Error create_server(int p_port, int p_max_clients = 32, int p_max_channels = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0); + Error create_client(const String &p_address, int p_port, int p_channel_count = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0, int p_local_port = 0); + Error create_mesh(int p_id); + Error add_mesh_peer(int p_id, Ref<ENetConnection> p_host); - virtual void set_refuse_new_connections(bool p_enable) override; - virtual bool is_refusing_new_connections() const override; + void close_connection(uint32_t wait_usec = 100); - virtual int get_unique_id() const override; + void disconnect_peer(int p_peer, bool now = false); void set_bind_ip(const IPAddress &p_ip); void set_server_relay_enabled(bool p_enabled); diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index 21ee39f3ed..94bda04d12 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -16,7 +16,6 @@ env_gdnative.Prepend(CPPPATH=["#modules/gdnative/include/"]) Export("env_gdnative") -SConscript("net/SCsub") SConscript("pluginscript/SCsub") SConscript("videodecoder/SCsub") SConscript("text/SCsub") diff --git a/modules/gdnative/config.py b/modules/gdnative/config.py index fa985501b5..026a84a70f 100644 --- a/modules/gdnative/config.py +++ b/modules/gdnative/config.py @@ -10,14 +10,9 @@ def get_doc_classes(): return [ "GDNative", "GDNativeLibrary", - "MultiplayerPeerGDNative", "NativeScript", - "PacketPeerGDNative", "PluginScript", - "StreamPeerGDNative", "VideoStreamGDNative", - "WebRTCPeerConnectionGDNative", - "WebRTCDataChannelGDNative", ] diff --git a/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml b/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml deleted file mode 100644 index 40f3121525..0000000000 --- a/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="MultiplayerPeerGDNative" inherits="MultiplayerPeer" version="4.0"> - <brief_description> - </brief_description> - <description> - </description> - <tutorials> - </tutorials> -</class> diff --git a/modules/gdnative/doc_classes/PacketPeerGDNative.xml b/modules/gdnative/doc_classes/PacketPeerGDNative.xml deleted file mode 100644 index 32863f8422..0000000000 --- a/modules/gdnative/doc_classes/PacketPeerGDNative.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="PacketPeerGDNative" inherits="PacketPeer" version="4.0"> - <brief_description> - </brief_description> - <description> - </description> - <tutorials> - </tutorials> -</class> diff --git a/modules/gdnative/doc_classes/StreamPeerGDNative.xml b/modules/gdnative/doc_classes/StreamPeerGDNative.xml deleted file mode 100644 index a505de2106..0000000000 --- a/modules/gdnative/doc_classes/StreamPeerGDNative.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="StreamPeerGDNative" inherits="StreamPeer" version="4.0"> - <brief_description> - </brief_description> - <description> - </description> - <tutorials> - </tutorials> -</class> diff --git a/modules/gdnative/doc_classes/WebRTCDataChannelGDNative.xml b/modules/gdnative/doc_classes/WebRTCDataChannelGDNative.xml deleted file mode 100644 index ddf354763c..0000000000 --- a/modules/gdnative/doc_classes/WebRTCDataChannelGDNative.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="WebRTCDataChannelGDNative" inherits="WebRTCDataChannel" version="4.0"> - <brief_description> - </brief_description> - <description> - </description> - <tutorials> - </tutorials> -</class> diff --git a/modules/gdnative/doc_classes/WebRTCPeerConnectionGDNative.xml b/modules/gdnative/doc_classes/WebRTCPeerConnectionGDNative.xml deleted file mode 100644 index 821779a0ff..0000000000 --- a/modules/gdnative/doc_classes/WebRTCPeerConnectionGDNative.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="WebRTCPeerConnectionGDNative" inherits="WebRTCPeerConnection" version="4.0"> - <brief_description> - </brief_description> - <description> - </description> - <tutorials> - </tutorials> -</class> diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 66d2dc267d..627883886c 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -5105,97 +5105,6 @@ ] }, { - "name": "net", - "type": "NET", - "version": { - "major": 4, - "minor": 0 - }, - "next": null, - "api": [ - { - "name": "godot_net_bind_stream_peer", - "return_type": "void", - "arguments": [ - [ - "godot_object *", - "p_obj" - ], - [ - "const godot_net_stream_peer *", - "p_interface" - ] - ] - }, - { - "name": "godot_net_bind_packet_peer", - "return_type": "void", - "arguments": [ - [ - "godot_object *", - "p_obj" - ], - [ - "const godot_net_packet_peer *", - "p_interface" - ] - ] - }, - { - "name": "godot_net_bind_multiplayer_peer", - "return_type": "void", - "arguments": [ - [ - "godot_object *", - "p_obj" - ], - [ - "const godot_net_multiplayer_peer *", - "p_interface" - ] - ] - }, - { - "name": "godot_net_set_webrtc_library", - "return_type": "godot_error", - "arguments": [ - [ - "const godot_net_webrtc_library *", - "p_library" - ] - ] - }, - { - "name": "godot_net_bind_webrtc_peer_connection", - "return_type": "void", - "arguments": [ - [ - "godot_object *", - "p_obj" - ], - [ - "const godot_net_webrtc_peer_connection *", - "p_interface" - ] - ] - }, - { - "name": "godot_net_bind_webrtc_data_channel", - "return_type": "void", - "arguments": [ - [ - "godot_object *", - "p_obj" - ], - [ - "const godot_net_webrtc_data_channel *", - "p_interface" - ] - ] - } - ] - }, - { "name": "text", "type": "TEXT", "version": { diff --git a/modules/gdnative/gdnative_builders.py b/modules/gdnative/gdnative_builders.py index 181fd71b82..4986b173cf 100644 --- a/modules/gdnative/gdnative_builders.py +++ b/modules/gdnative/gdnative_builders.py @@ -20,7 +20,6 @@ def _build_gdnative_api_struct_header(api): "#include <gdnative/gdnative.h>", "#include <android/godot_android.h>", "#include <nativescript/godot_nativescript.h>", - "#include <net/godot_net.h>", "#include <pluginscript/godot_pluginscript.h>", "#include <videodecoder/godot_videodecoder.h>", "#include <text/godot_text.h>", diff --git a/modules/gdnative/include/net/godot_net.h b/modules/gdnative/include/net/godot_net.h deleted file mode 100644 index 3fb7b9e1cc..0000000000 --- a/modules/gdnative/include/net/godot_net.h +++ /dev/null @@ -1,122 +0,0 @@ -/*************************************************************************/ -/* godot_net.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef GODOT_NATIVENET_H -#define GODOT_NATIVENET_H - -#include <gdnative/gdnative.h> - -#ifdef __cplusplus -extern "C" { -#endif - -// For future versions of the API we should only add new functions at the end of the structure and use the -// version info to detect whether a call is available - -// Use these to populate version in your plugin -#define GODOT_NET_API_MAJOR 3 -#define GODOT_NET_API_MINOR 1 - -typedef struct { - godot_gdnative_api_version version; /* version of our API */ - godot_object *data; /* User reference */ - - /* This is StreamPeer */ - godot_error (*get_data)(void *user, uint8_t *p_buffer, int p_bytes); - godot_error (*get_partial_data)(void *user, uint8_t *p_buffer, int p_bytes, int *r_received); - godot_error (*put_data)(void *user, const uint8_t *p_data, int p_bytes); - godot_error (*put_partial_data)(void *user, const uint8_t *p_data, int p_bytes, int *r_sent); - - int (*get_available_bytes)(const void *user); - - void *next; /* For extension? */ -} godot_net_stream_peer; - -/* Binds a StreamPeerGDNative to the provided interface */ -void godot_net_bind_stream_peer(godot_object *p_obj, const godot_net_stream_peer *p_interface); - -typedef struct { - godot_gdnative_api_version version; /* version of our API */ - - godot_object *data; /* User reference */ - - /* This is PacketPeer */ - godot_error (*get_packet)(void *, const uint8_t **, int *); - godot_error (*put_packet)(void *, const uint8_t *, int); - godot_int (*get_available_packet_count)(const void *); - godot_int (*get_max_packet_size)(const void *); - - void *next; /* For extension? */ -} godot_net_packet_peer; - -/* Binds a PacketPeerGDNative to the provided interface */ -void GDAPI godot_net_bind_packet_peer(godot_object *p_obj, const godot_net_packet_peer *); - -typedef struct { - godot_gdnative_api_version version; /* version of our API */ - - godot_object *data; /* User reference */ - - /* This is PacketPeer */ - godot_error (*get_packet)(void *, const uint8_t **, int *); - godot_error (*put_packet)(void *, const uint8_t *, int); - godot_int (*get_available_packet_count)(const void *); - godot_int (*get_max_packet_size)(const void *); - - /* This is MultiplayerPeer */ - void (*set_transfer_channel)(void *, godot_int); - godot_int (*get_transfer_channel)(void *); - void (*set_transfer_mode)(void *, godot_int); - godot_int (*get_transfer_mode)(const void *); - // 0 = broadcast, 1 = server, <0 = all but abs(value) - void (*set_target_peer)(void *, godot_int); - godot_int (*get_packet_peer)(const void *); - godot_bool (*is_server)(const void *); - void (*poll)(void *); - // Must be > 0, 1 is for server - int32_t (*get_unique_id)(const void *); - void (*set_refuse_new_connections)(void *, godot_bool); - godot_bool (*is_refusing_new_connections)(const void *); - godot_int (*get_connection_status)(const void *); - - void *next; /* For extension? Or maybe not... */ -} godot_net_multiplayer_peer; - -/* Binds a MultiplayerPeerGDNative to the provided interface */ -void GDAPI godot_net_bind_multiplayer_peer(godot_object *p_obj, const godot_net_multiplayer_peer *); - -#ifdef __cplusplus -} -#endif - -// WebRTC Bindings -#include "net/godot_webrtc.h" - -#endif /* GODOT_NATIVENET_H */ diff --git a/modules/gdnative/include/net/godot_webrtc.h b/modules/gdnative/include/net/godot_webrtc.h deleted file mode 100644 index 52006e56ec..0000000000 --- a/modules/gdnative/include/net/godot_webrtc.h +++ /dev/null @@ -1,123 +0,0 @@ -/*************************************************************************/ -/* godot_webrtc.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef GODOT_NATIVEWEBRTC_H -#define GODOT_NATIVEWEBRTC_H - -#include <gdnative/gdnative.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#define GODOT_NET_WEBRTC_API_MAJOR 4 -#define GODOT_NET_WEBRTC_API_MINOR 0 - -/* Library Interface (used to set default GDNative WebRTC implementation */ -typedef struct { - godot_gdnative_api_version version; /* version of our API */ - - /* Called when the library is unset as default interface via godot_net_set_webrtc_library */ - void (*unregistered)(); - - /* Used by WebRTCPeerConnection create when GDNative is the default implementation. */ - /* Takes a pointer to WebRTCPeerConnectionGDNative, should bind and return OK, failure if binding was unsuccessful. */ - godot_error (*create_peer_connection)(godot_object *); - - void *next; /* For extension */ -} godot_net_webrtc_library; - -/* WebRTCPeerConnection interface */ -typedef struct { - godot_gdnative_api_version version; /* version of our API */ - - godot_object *data; /* User reference */ - - /* This is WebRTCPeerConnection */ - godot_int (*get_connection_state)(const void *); - - godot_error (*initialize)(void *, const godot_dictionary *); - godot_object *(*create_data_channel)(void *, const char *p_channel_name, const godot_dictionary *); - godot_error (*create_offer)(void *); - godot_error (*create_answer)(void *); /* unused for now, should be done automatically on set_local_description */ - godot_error (*set_remote_description)(void *, const char *, const char *); - godot_error (*set_local_description)(void *, const char *, const char *); - godot_error (*add_ice_candidate)(void *, const char *, int, const char *); - godot_error (*poll)(void *); - void (*close)(void *); - - void *next; /* For extension? */ -} godot_net_webrtc_peer_connection; - -/* WebRTCDataChannel interface */ -typedef struct { - godot_gdnative_api_version version; /* version of our API */ - - godot_object *data; /* User reference */ - - /* This is PacketPeer */ - godot_error (*get_packet)(void *, const uint8_t **, int *); - godot_error (*put_packet)(void *, const uint8_t *, int); - godot_int (*get_available_packet_count)(const void *); - godot_int (*get_max_packet_size)(const void *); - - /* This is WebRTCDataChannel */ - void (*set_write_mode)(void *, godot_int); - godot_int (*get_write_mode)(const void *); - bool (*was_string_packet)(const void *); - - godot_int (*get_ready_state)(const void *); - const char *(*get_label)(const void *); - bool (*is_ordered)(const void *); - int (*get_id)(const void *); - int (*get_max_packet_life_time)(const void *); - int (*get_max_retransmits)(const void *); - const char *(*get_protocol)(const void *); - bool (*is_negotiated)(const void *); - int (*get_buffered_amount)(const void *); - - godot_error (*poll)(void *); - void (*close)(void *); - - void *next; /* For extension? */ -} godot_net_webrtc_data_channel; - -/* Set the default GDNative library */ -godot_error GDAPI godot_net_set_webrtc_library(const godot_net_webrtc_library *); -/* Binds a WebRTCPeerConnectionGDNative to the provided interface */ -void GDAPI godot_net_bind_webrtc_peer_connection(godot_object *p_obj, const godot_net_webrtc_peer_connection *); -/* Binds a WebRTCDataChannelGDNative to the provided interface */ -void GDAPI godot_net_bind_webrtc_data_channel(godot_object *p_obj, const godot_net_webrtc_data_channel *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/modules/gdnative/net/SCsub b/modules/gdnative/net/SCsub deleted file mode 100644 index b76500c003..0000000000 --- a/modules/gdnative/net/SCsub +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env python - -Import("env") -Import("env_gdnative") - -env_net = env_gdnative.Clone() - -has_webrtc = env_net["module_webrtc_enabled"] -if has_webrtc: - env_net.Append(CPPDEFINES=["WEBRTC_GDNATIVE_ENABLED"]) - -env_net.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/gdnative/net/multiplayer_peer_gdnative.cpp b/modules/gdnative/net/multiplayer_peer_gdnative.cpp deleted file mode 100644 index 575d5f5060..0000000000 --- a/modules/gdnative/net/multiplayer_peer_gdnative.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/*************************************************************************/ -/* multiplayer_peer_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "multiplayer_peer_gdnative.h" - -MultiplayerPeerGDNative::MultiplayerPeerGDNative() { - interface = nullptr; -} - -MultiplayerPeerGDNative::~MultiplayerPeerGDNative() { -} - -void MultiplayerPeerGDNative::set_native_multiplayer_peer(const godot_net_multiplayer_peer *p_interface) { - interface = p_interface; -} - -Error MultiplayerPeerGDNative::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->get_packet(interface->data, r_buffer, &r_buffer_size); -} - -Error MultiplayerPeerGDNative::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->put_packet(interface->data, p_buffer, p_buffer_size); -} - -int MultiplayerPeerGDNative::get_max_packet_size() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_max_packet_size(interface->data); -} - -int MultiplayerPeerGDNative::get_available_packet_count() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_available_packet_count(interface->data); -} - -/* MultiplayerPeer */ -void MultiplayerPeerGDNative::set_transfer_channel(int p_channel) { - ERR_FAIL_COND(interface == nullptr); - return interface->set_transfer_channel(interface->data, p_channel); -} - -int MultiplayerPeerGDNative::get_transfer_channel() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_transfer_channel(interface->data); -} - -void MultiplayerPeerGDNative::set_transfer_mode(Multiplayer::TransferMode p_mode) { - ERR_FAIL_COND(interface == nullptr); - interface->set_transfer_mode(interface->data, (godot_int)p_mode); -} - -Multiplayer::TransferMode MultiplayerPeerGDNative::get_transfer_mode() const { - ERR_FAIL_COND_V(interface == nullptr, Multiplayer::TRANSFER_MODE_UNRELIABLE); - return (Multiplayer::TransferMode)interface->get_transfer_mode(interface->data); -} - -void MultiplayerPeerGDNative::set_target_peer(int p_peer_id) { - ERR_FAIL_COND(interface == nullptr); - interface->set_target_peer(interface->data, p_peer_id); -} - -int MultiplayerPeerGDNative::get_packet_peer() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_packet_peer(interface->data); -} - -bool MultiplayerPeerGDNative::is_server() const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->is_server(interface->data); -} - -void MultiplayerPeerGDNative::poll() { - ERR_FAIL_COND(interface == nullptr); - interface->poll(interface->data); -} - -int MultiplayerPeerGDNative::get_unique_id() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_unique_id(interface->data); -} - -void MultiplayerPeerGDNative::set_refuse_new_connections(bool p_enable) { - ERR_FAIL_COND(interface == nullptr); - interface->set_refuse_new_connections(interface->data, p_enable); -} - -bool MultiplayerPeerGDNative::is_refusing_new_connections() const { - ERR_FAIL_COND_V(interface == nullptr, true); - return interface->is_refusing_new_connections(interface->data); -} - -MultiplayerPeer::ConnectionStatus MultiplayerPeerGDNative::get_connection_status() const { - ERR_FAIL_COND_V(interface == nullptr, CONNECTION_DISCONNECTED); - return (ConnectionStatus)interface->get_connection_status(interface->data); -} - -void MultiplayerPeerGDNative::_bind_methods() { - ADD_PROPERTY_DEFAULT("transfer_channel", 0); - ADD_PROPERTY_DEFAULT("transfer_mode", Multiplayer::TRANSFER_MODE_UNRELIABLE); - ADD_PROPERTY_DEFAULT("refuse_new_connections", true); -} - -extern "C" { - -void GDAPI godot_net_bind_multiplayer_peer(godot_object *p_obj, const godot_net_multiplayer_peer *p_impl) { - ((MultiplayerPeerGDNative *)p_obj)->set_native_multiplayer_peer(p_impl); -} -} diff --git a/modules/gdnative/net/multiplayer_peer_gdnative.h b/modules/gdnative/net/multiplayer_peer_gdnative.h deleted file mode 100644 index 33e424d284..0000000000 --- a/modules/gdnative/net/multiplayer_peer_gdnative.h +++ /dev/null @@ -1,79 +0,0 @@ -/*************************************************************************/ -/* multiplayer_peer_gdnative.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef MULTIPLAYER_PEER_GDNATIVE_H -#define MULTIPLAYER_PEER_GDNATIVE_H - -#include "core/multiplayer/multiplayer_peer.h" -#include "modules/gdnative/gdnative.h" -#include "modules/gdnative/include/net/godot_net.h" - -class MultiplayerPeerGDNative : public MultiplayerPeer { - GDCLASS(MultiplayerPeerGDNative, MultiplayerPeer); - -protected: - static void _bind_methods(); - const godot_net_multiplayer_peer *interface; - -public: - MultiplayerPeerGDNative(); - ~MultiplayerPeerGDNative(); - - /* Sets the interface implementation from GDNative */ - void set_native_multiplayer_peer(const godot_net_multiplayer_peer *p_impl); - - /* Specific to PacketPeer */ - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; - virtual int get_max_packet_size() const override; - virtual int get_available_packet_count() const override; - - /* Specific to MultiplayerPeer */ - virtual void set_transfer_channel(int p_channel) override; - virtual int get_transfer_channel() const override; - virtual void set_transfer_mode(Multiplayer::TransferMode p_mode) override; - virtual Multiplayer::TransferMode get_transfer_mode() const override; - virtual void set_target_peer(int p_peer_id) override; - - virtual int get_packet_peer() const override; - - virtual bool is_server() const override; - - virtual void poll() override; - - virtual int get_unique_id() const override; - - virtual void set_refuse_new_connections(bool p_enable) override; - virtual bool is_refusing_new_connections() const override; - - virtual ConnectionStatus get_connection_status() const override; -}; - -#endif // MULTIPLAYER_PEER_GDNATIVE_H diff --git a/modules/gdnative/net/packet_peer_gdnative.cpp b/modules/gdnative/net/packet_peer_gdnative.cpp deleted file mode 100644 index 3bcdfed8ff..0000000000 --- a/modules/gdnative/net/packet_peer_gdnative.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/*************************************************************************/ -/* packet_peer_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "packet_peer_gdnative.h" - -PacketPeerGDNative::PacketPeerGDNative() { - interface = nullptr; -} - -PacketPeerGDNative::~PacketPeerGDNative() { -} - -void PacketPeerGDNative::set_native_packet_peer(const godot_net_packet_peer *p_impl) { - interface = p_impl; -} - -void PacketPeerGDNative::_bind_methods() { -} - -Error PacketPeerGDNative::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->get_packet(interface->data, r_buffer, &r_buffer_size); -} - -Error PacketPeerGDNative::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->put_packet(interface->data, p_buffer, p_buffer_size); -} - -int PacketPeerGDNative::get_max_packet_size() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_max_packet_size(interface->data); -} - -int PacketPeerGDNative::get_available_packet_count() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_available_packet_count(interface->data); -} - -extern "C" { - -void GDAPI godot_net_bind_packet_peer(godot_object *p_obj, const godot_net_packet_peer *p_impl) { - ((PacketPeerGDNative *)p_obj)->set_native_packet_peer(p_impl); -} -} diff --git a/modules/gdnative/net/packet_peer_gdnative.h b/modules/gdnative/net/packet_peer_gdnative.h deleted file mode 100644 index 29013f9367..0000000000 --- a/modules/gdnative/net/packet_peer_gdnative.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************/ -/* packet_peer_gdnative.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef PACKET_PEER_GDNATIVE_H -#define PACKET_PEER_GDNATIVE_H - -#include "core/io/packet_peer.h" -#include "modules/gdnative/gdnative.h" -#include "modules/gdnative/include/net/godot_net.h" - -class PacketPeerGDNative : public PacketPeer { - GDCLASS(PacketPeerGDNative, PacketPeer); - -protected: - static void _bind_methods(); - const godot_net_packet_peer *interface; - -public: - PacketPeerGDNative(); - ~PacketPeerGDNative(); - - /* Sets the interface implementation from GDNative */ - void set_native_packet_peer(const godot_net_packet_peer *p_impl); - - /* Specific to PacketPeer */ - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; - virtual int get_max_packet_size() const override; - virtual int get_available_packet_count() const override; -}; - -#endif // PACKET_PEER_GDNATIVE_H diff --git a/modules/gdnative/net/register_types.h b/modules/gdnative/net/register_types.h deleted file mode 100644 index c99c6f6fbf..0000000000 --- a/modules/gdnative/net/register_types.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************/ -/* register_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef NET_REGISTER_TYPES_H -#define NET_REGISTER_TYPES_H - -void register_net_types(); -void unregister_net_types(); - -#endif // NET_REGISTER_TYPES_H diff --git a/modules/gdnative/net/stream_peer_gdnative.cpp b/modules/gdnative/net/stream_peer_gdnative.cpp deleted file mode 100644 index 72ab72323d..0000000000 --- a/modules/gdnative/net/stream_peer_gdnative.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/*************************************************************************/ -/* stream_peer_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "stream_peer_gdnative.h" - -StreamPeerGDNative::StreamPeerGDNative() { - interface = nullptr; -} - -StreamPeerGDNative::~StreamPeerGDNative() { -} - -void StreamPeerGDNative::set_native_stream_peer(const godot_net_stream_peer *p_interface) { - interface = p_interface; -} - -void StreamPeerGDNative::_bind_methods() { -} - -Error StreamPeerGDNative::put_data(const uint8_t *p_data, int p_bytes) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)(interface->put_data(interface->data, p_data, p_bytes)); -} - -Error StreamPeerGDNative::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)(interface->put_partial_data(interface->data, p_data, p_bytes, &r_sent)); -} - -Error StreamPeerGDNative::get_data(uint8_t *p_buffer, int p_bytes) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)(interface->get_data(interface->data, p_buffer, p_bytes)); -} - -Error StreamPeerGDNative::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)(interface->get_partial_data(interface->data, p_buffer, p_bytes, &r_received)); -} - -int StreamPeerGDNative::get_available_bytes() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_available_bytes(interface->data); -} - -extern "C" { - -void GDAPI godot_net_bind_stream_peer(godot_object *p_obj, const godot_net_stream_peer *p_interface) { - ((StreamPeerGDNative *)p_obj)->set_native_stream_peer(p_interface); -} -} diff --git a/modules/gdnative/net/stream_peer_gdnative.h b/modules/gdnative/net/stream_peer_gdnative.h deleted file mode 100644 index dd5abceb83..0000000000 --- a/modules/gdnative/net/stream_peer_gdnative.h +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************/ -/* stream_peer_gdnative.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef STREAM_PEER_GDNATIVE_H -#define STREAM_PEER_GDNATIVE_H - -#include "core/io/stream_peer.h" -#include "modules/gdnative/gdnative.h" -#include "modules/gdnative/include/net/godot_net.h" - -class StreamPeerGDNative : public StreamPeer { - GDCLASS(StreamPeerGDNative, StreamPeer); - -protected: - static void _bind_methods(); - const godot_net_stream_peer *interface; - -public: - StreamPeerGDNative(); - ~StreamPeerGDNative(); - - /* Sets the interface implementation from GDNative */ - void set_native_stream_peer(const godot_net_stream_peer *p_interface); - - /* Specific to StreamPeer */ - Error put_data(const uint8_t *p_data, int p_bytes) override; - Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) override; - Error get_data(uint8_t *p_buffer, int p_bytes) override; - Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) override; - int get_available_bytes() const override; -}; - -#endif // STREAM_PEER_GDNATIVE_H diff --git a/modules/gdnative/net/webrtc_gdnative.cpp b/modules/gdnative/net/webrtc_gdnative.cpp deleted file mode 100644 index 76ccbad009..0000000000 --- a/modules/gdnative/net/webrtc_gdnative.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************/ -/* webrtc_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "modules/gdnative/gdnative.h" -#include "modules/gdnative/include/net/godot_net.h" - -#ifdef WEBRTC_GDNATIVE_ENABLED -#include "modules/webrtc/webrtc_data_channel_gdnative.h" -#include "modules/webrtc/webrtc_peer_connection_gdnative.h" -#endif - -extern "C" { - -void GDAPI godot_net_bind_webrtc_peer_connection(godot_object *p_obj, const godot_net_webrtc_peer_connection *p_impl) { -#ifdef WEBRTC_GDNATIVE_ENABLED - ((WebRTCPeerConnectionGDNative *)p_obj)->set_native_webrtc_peer_connection(p_impl); -#endif -} - -void GDAPI godot_net_bind_webrtc_data_channel(godot_object *p_obj, const godot_net_webrtc_data_channel *p_impl) { -#ifdef WEBRTC_GDNATIVE_ENABLED - ((WebRTCDataChannelGDNative *)p_obj)->set_native_webrtc_data_channel(p_impl); -#endif -} - -godot_error GDAPI godot_net_set_webrtc_library(const godot_net_webrtc_library *p_lib) { -#ifdef WEBRTC_GDNATIVE_ENABLED - return (godot_error)WebRTCPeerConnectionGDNative::set_default_library(p_lib); -#else - return (godot_error)ERR_UNAVAILABLE; -#endif -} -} diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index e4c2b20224..a4ab5663ef 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -35,7 +35,6 @@ #include "gdnative.h" #include "nativescript/register_types.h" -#include "net/register_types.h" #include "pluginscript/register_types.h" #include "videodecoder/register_types.h" @@ -265,7 +264,6 @@ void register_gdnative_types() { GDNativeCallRegistry::singleton->register_native_call_type("standard_varcall", cb_standard_varcall); - register_net_types(); register_nativescript_types(); register_pluginscript_types(); register_videodecoder_types(); @@ -329,7 +327,6 @@ void unregister_gdnative_types() { unregister_videodecoder_types(); unregister_pluginscript_types(); unregister_nativescript_types(); - unregister_net_types(); memdelete(GDNativeCallRegistry::singleton); diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 23e88ae059..032e08f5a0 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -175,6 +175,11 @@ Error GDScriptAnalyzer::check_native_member_name_conflict(const StringName &p_me return ERR_PARSE_ERROR; } + if (GDScriptParser::get_builtin_type(p_member_name) != Variant::VARIANT_MAX) { + push_error(vformat(R"(The member "%s" cannot have the same name as a builtin type.)", p_member_name), p_member_node); + return ERR_PARSE_ERROR; + } + return OK; } @@ -2503,7 +2508,10 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod result.enum_type = name; p_identifier->set_datatype(result); } else { - push_error(vformat(R"(Cannot find value "%s" in "%s".)", name, base.to_string()), p_identifier); + // Consider as a Dictionary + GDScriptParser::DataType dummy; + dummy.kind = GDScriptParser::DataType::VARIANT; + p_identifier->set_datatype(dummy); } } else { push_error(R"(Cannot get property from enum value.)", p_identifier); @@ -3676,6 +3684,11 @@ bool GDScriptAnalyzer::is_type_compatible(const GDScriptParser::DataType &p_targ if (p_source.kind == GDScriptParser::DataType::BUILTIN && p_source.builtin_type == Variant::INT) { return true; } + if (p_source.kind == GDScriptParser::DataType::ENUM) { + if (p_source.native_type == p_target.native_type) { + return true; + } + } if (p_source.kind == GDScriptParser::DataType::ENUM_VALUE) { if (p_source.native_type == p_target.native_type && p_target.enum_values.has(p_source.enum_type)) { return true; diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index a8aef84db3..947224e93e 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -1071,19 +1071,25 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code } } - GDScriptCodeGenerator::Address assigned = _parse_expression(codegen, r_error, assignment->assigned_value); - GDScriptCodeGenerator::Address op_result; + GDScriptCodeGenerator::Address assigned_value = _parse_expression(codegen, r_error, assignment->assigned_value); if (r_error) { return GDScriptCodeGenerator::Address(); } - if (assignment->operation != GDScriptParser::AssignmentNode::OP_NONE) { + GDScriptCodeGenerator::Address to_assign; + bool has_operation = assignment->operation != GDScriptParser::AssignmentNode::OP_NONE; + if (has_operation) { // Perform operation. - op_result = codegen.add_temporary(); - gen->write_binary_operator(op_result, assignment->variant_op, target, assigned); + GDScriptCodeGenerator::Address op_result = codegen.add_temporary(); + GDScriptCodeGenerator::Address og_value = _parse_expression(codegen, r_error, assignment->assignee); + gen->write_binary_operator(op_result, assignment->variant_op, og_value, assigned_value); + to_assign = op_result; + + if (og_value.mode == GDScriptCodeGenerator::Address::TEMPORARY) { + gen->pop_temporary(); + } } else { - op_result = assigned; - assigned = GDScriptCodeGenerator::Address(); + to_assign = assigned_value; } GDScriptDataType assign_type = _gdtype_from_datatype(assignment->assignee->get_datatype()); @@ -1091,25 +1097,25 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code if (has_setter && !is_in_setter) { // Call setter. Vector<GDScriptCodeGenerator::Address> args; - args.push_back(op_result); + args.push_back(to_assign); gen->write_call(GDScriptCodeGenerator::Address(), GDScriptCodeGenerator::Address(GDScriptCodeGenerator::Address::SELF), setter_function, args); } else { // Just assign. if (assignment->use_conversion_assign) { - gen->write_assign_with_conversion(target, op_result); + gen->write_assign_with_conversion(target, to_assign); } else { - gen->write_assign(target, op_result); + gen->write_assign(target, to_assign); } } - if (op_result.mode == GDScriptCodeGenerator::Address::TEMPORARY) { - gen->pop_temporary(); + if (to_assign.mode == GDScriptCodeGenerator::Address::TEMPORARY) { + gen->pop_temporary(); // Pop assigned value or temp operation result. } - if (assigned.mode == GDScriptCodeGenerator::Address::TEMPORARY) { - gen->pop_temporary(); + if (has_operation && assigned_value.mode == GDScriptCodeGenerator::Address::TEMPORARY) { + gen->pop_temporary(); // Pop assigned value if not done before. } if (target.mode == GDScriptCodeGenerator::Address::TEMPORARY) { - gen->pop_temporary(); + gen->pop_temporary(); // Pop the target to assignment. } } return GDScriptCodeGenerator::Address(); // Assignment does not return a value. diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 2f8a054b2a..044ac4b661 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -637,7 +637,7 @@ static void _get_directory_contents(EditorFileSystemDirectory *p_dir, Map<String } static void _find_annotation_arguments(const GDScriptParser::AnnotationNode *p_annotation, int p_argument, const String p_quote_style, Map<String, ScriptCodeCompletionOption> &r_result) { - if (p_annotation->name == "@export_range" || p_annotation->name == "@export_exp_range") { + if (p_annotation->name == "@export_range") { if (p_argument == 3 || p_argument == 4) { // Slider hint. ScriptCodeCompletionOption slider1("or_greater", ScriptCodeCompletionOption::KIND_PLAIN_TEXT); diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index bf21c8510a..6186d0edee 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -88,9 +88,9 @@ static String _get_var_type(const Variant *p_var) { Object *bobj = p_var->get_validated_object_with_check(was_freed); if (!bobj) { if (was_freed) { - basestr = "null instance"; - } else { basestr = "previously freed"; + } else { + basestr = "null instance"; } } else { basestr = bobj->get_class(); @@ -1233,7 +1233,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a GD_ERR_BREAK(to_type < 0 || to_type >= Variant::VARIANT_MAX); #ifdef DEBUG_ENABLED - if (src->get_type() == Variant::OBJECT && !src->operator ObjectID().is_ref_counted() && ObjectDB::get_instance(src->operator ObjectID()) == nullptr) { + if (src->operator Object *() && !src->get_validated_object()) { err_text = "Trying to cast a freed object."; OPCODE_BREAK; } @@ -1263,7 +1263,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a GD_ERR_BREAK(!nc); #ifdef DEBUG_ENABLED - if (src->get_type() == Variant::OBJECT && !src->operator ObjectID().is_ref_counted() && ObjectDB::get_instance(src->operator ObjectID()) == nullptr) { + if (src->operator Object *() && !src->get_validated_object()) { err_text = "Trying to cast a freed object."; OPCODE_BREAK; } @@ -1295,7 +1295,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a GD_ERR_BREAK(!base_type); #ifdef DEBUG_ENABLED - if (src->get_type() == Variant::OBJECT && !src->operator ObjectID().is_ref_counted() && ObjectDB::get_instance(src->operator ObjectID()) == nullptr) { + if (src->operator Object *() && !src->get_validated_object()) { err_text = "Trying to cast a freed object."; OPCODE_BREAK; } @@ -2138,7 +2138,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a retvalue = gdfs; - Error err = sig.connect(Callable(gdfs.ptr(), "_signal_callback"), varray(gdfs), Object::CONNECT_ONESHOT); + Error err = sig.connect(callable_bind(Callable(gdfs.ptr(), "_signal_callback"), retvalue), Object::CONNECT_ONESHOT); if (err != OK) { err_text = "Error connecting to signal: " + sig.get_name() + " during await."; OPCODE_BREAK; diff --git a/modules/gdscript/language_server/gdscript_language_protocol.cpp b/modules/gdscript/language_server/gdscript_language_protocol.cpp index b6c48468f5..bd5a9f01b2 100644 --- a/modules/gdscript/language_server/gdscript_language_protocol.cpp +++ b/modules/gdscript/language_server/gdscript_language_protocol.cpp @@ -284,6 +284,23 @@ void GDScriptLanguageProtocol::notify_client(const String &p_method, const Varia peer->res_queue.push_back(msg.utf8()); } +void GDScriptLanguageProtocol::request_client(const String &p_method, const Variant &p_params, int p_client_id) { + if (p_client_id == -1) { + ERR_FAIL_COND_MSG(latest_client_id == -1, + "GDScript LSP: Can't notify client as none was connected."); + p_client_id = latest_client_id; + } + ERR_FAIL_COND(!clients.has(p_client_id)); + Ref<LSPeer> peer = clients.get(p_client_id); + ERR_FAIL_COND(peer == nullptr); + + Dictionary message = make_request(p_method, p_params, next_server_id); + next_server_id++; + String msg = Variant(message).to_json_string(); + msg = format_output(msg); + peer->res_queue.push_back(msg.utf8()); +} + bool GDScriptLanguageProtocol::is_smart_resolve_enabled() const { return bool(_EDITOR_GET("network/language_server/enable_smart_resolve")); } diff --git a/modules/gdscript/language_server/gdscript_language_protocol.h b/modules/gdscript/language_server/gdscript_language_protocol.h index 5a2dd55c46..899446fb42 100644 --- a/modules/gdscript/language_server/gdscript_language_protocol.h +++ b/modules/gdscript/language_server/gdscript_language_protocol.h @@ -79,6 +79,8 @@ private: int latest_client_id = 0; int next_client_id = 0; + int next_server_id = 0; + Ref<GDScriptTextDocument> text_document; Ref<GDScriptWorkspace> workspace; @@ -107,6 +109,7 @@ public: void stop(); void notify_client(const String &p_method, const Variant &p_params = Variant(), int p_client_id = -1); + void request_client(const String &p_method, const Variant &p_params = Variant(), int p_client_id = -1); bool is_smart_resolve_enabled() const; bool is_goto_native_symbols_enabled() const; diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp index 1512b4bb89..f4b55cac02 100644 --- a/modules/gdscript/language_server/gdscript_workspace.cpp +++ b/modules/gdscript/language_server/gdscript_workspace.cpp @@ -42,6 +42,7 @@ #include "scene/resources/packed_scene.h" void GDScriptWorkspace::_bind_methods() { + ClassDB::bind_method(D_METHOD("apply_new_signal"), &GDScriptWorkspace::apply_new_signal); ClassDB::bind_method(D_METHOD("didDeleteFiles"), &GDScriptWorkspace::did_delete_files); ClassDB::bind_method(D_METHOD("symbol"), &GDScriptWorkspace::symbol); ClassDB::bind_method(D_METHOD("parse_script", "path", "content"), &GDScriptWorkspace::parse_script); @@ -52,6 +53,54 @@ void GDScriptWorkspace::_bind_methods() { ClassDB::bind_method(D_METHOD("generate_script_api", "path"), &GDScriptWorkspace::generate_script_api); } +void GDScriptWorkspace::apply_new_signal(Object *obj, String function, PackedStringArray args) { + String function_signature = "func " + function; + Ref<Script> script = obj->get_script(); + + String source = script->get_source_code(); + + if (source.find(function_signature) != -1) { + return; + } + + int first_class = source.find("\nclass "); + int start_line = 0; + if (first_class != -1) { + start_line = source.substr(0, first_class).split("\n").size(); + } else { + start_line = source.split("\n").size(); + } + + String function_body = "\n\n" + function_signature + "("; + for (int i = 0; i < args.size(); ++i) { + function_body += args[i]; + if (i < args.size() - 1) { + function_body += ", "; + } + } + function_body += ")"; + if (EditorSettings::get_singleton()->get_setting("text_editor/completion/add_type_hints")) { + function_body += " -> void"; + } + function_body += ":\n\tpass # Replace with function body.\n"; + + lsp::TextEdit text_edit; + + if (first_class != -1) { + function_body += "\n\n"; + } + text_edit.range.end.line = text_edit.range.start.line = start_line; + + text_edit.newText = function_body; + + String uri = get_file_uri(script->get_path()); + + lsp::ApplyWorkspaceEditParams params; + params.edit.add_edit(uri, text_edit); + + GDScriptLanguageProtocol::get_singleton()->request_client("workspace/applyEdit", params.to_json()); +} + void GDScriptWorkspace::did_delete_files(const Dictionary &p_params) { Array files = p_params["files"]; for (int i = 0; i < files.size(); ++i) { @@ -360,6 +409,9 @@ Error GDScriptWorkspace::initialize() { } } + EditorNode *editor_node = EditorNode::get_singleton(); + editor_node->connect("script_add_function_request", callable_mp(this, &GDScriptWorkspace::apply_new_signal)); + return OK; } @@ -551,7 +603,7 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S } } -const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocumentPositionParams &p_doc_pos, const String &p_symbol_name, bool p_func_requred) { +const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocumentPositionParams &p_doc_pos, const String &p_symbol_name, bool p_func_required) { const lsp::DocumentSymbol *symbol = nullptr; String path = get_file_path(p_doc_pos.textDocument.uri); @@ -576,7 +628,10 @@ const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocu } else { ScriptLanguage::LookupResult ret; - if (OK == GDScriptLanguage::get_singleton()->lookup_code(parser->get_text_for_lookup_symbol(pos, symbol_identifier, p_func_requred), symbol_identifier, path, nullptr, ret)) { + if (symbol_identifier == "new" && parser->get_lines()[p_doc_pos.position.line].replace(" ", "").replace("\t", "").find("new(") > -1) { + symbol_identifier = "_init"; + } + if (OK == GDScriptLanguage::get_singleton()->lookup_code(parser->get_text_for_lookup_symbol(pos, symbol_identifier, p_func_required), symbol_identifier, path, nullptr, ret)) { if (ret.type == ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION) { String target_script_path = path; if (!ret.script.is_null()) { diff --git a/modules/gdscript/language_server/gdscript_workspace.h b/modules/gdscript/language_server/gdscript_workspace.h index 9496677449..6f5600b5cf 100644 --- a/modules/gdscript/language_server/gdscript_workspace.h +++ b/modules/gdscript/language_server/gdscript_workspace.h @@ -62,6 +62,8 @@ protected: void list_script_files(const String &p_root_dir, List<String> &r_files); + void apply_new_signal(Object *obj, String function, PackedStringArray args); + public: String root; String root_uri; @@ -85,7 +87,7 @@ public: void publish_diagnostics(const String &p_path); void completion(const lsp::CompletionParams &p_params, List<ScriptCodeCompletionOption> *r_options); - const lsp::DocumentSymbol *resolve_symbol(const lsp::TextDocumentPositionParams &p_doc_pos, const String &p_symbol_name = "", bool p_func_requred = false); + const lsp::DocumentSymbol *resolve_symbol(const lsp::TextDocumentPositionParams &p_doc_pos, const String &p_symbol_name = "", bool p_func_required = false); void resolve_related_symbols(const lsp::TextDocumentPositionParams &p_doc_pos, List<const lsp::DocumentSymbol *> &r_list); const lsp::DocumentSymbol *resolve_native_symbol(const lsp::NativeSymbolInspectParams &p_params); void resolve_document_links(const String &p_uri, List<lsp::DocumentLink> &r_list); diff --git a/modules/gdscript/language_server/lsp.hpp b/modules/gdscript/language_server/lsp.hpp index 9ac6c6bd4e..662382d279 100644 --- a/modules/gdscript/language_server/lsp.hpp +++ b/modules/gdscript/language_server/lsp.hpp @@ -263,6 +263,16 @@ struct WorkspaceEdit { */ Map<String, Vector<TextEdit>> changes; + _FORCE_INLINE_ void add_edit(const String &uri, const TextEdit &edit) { + if (changes.has(uri)) { + changes[uri].push_back(edit); + } else { + Vector<TextEdit> edits; + edits.push_back(edit); + changes[uri] = edits; + } + } + _FORCE_INLINE_ Dictionary to_json() const { Dictionary dict; @@ -1322,6 +1332,18 @@ struct DocumentSymbol { } }; +struct ApplyWorkspaceEditParams { + WorkspaceEdit edit; + + Dictionary to_json() { + Dictionary dict; + + dict["edit"] = edit.to_json(); + + return dict; + } +}; + struct NativeSymbolInspectParams { String native_class; String symbol_name; diff --git a/modules/gdscript/tests/scripts/analyzer/errors/class_name_shadows_builtin_type.gd b/modules/gdscript/tests/scripts/analyzer/errors/class_name_shadows_builtin_type.gd new file mode 100644 index 0000000000..b84ccdce81 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/class_name_shadows_builtin_type.gd @@ -0,0 +1,5 @@ +class Vector2: + pass + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/class_name_shadows_builtin_type.out b/modules/gdscript/tests/scripts/analyzer/errors/class_name_shadows_builtin_type.out new file mode 100644 index 0000000000..87863baf75 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/class_name_shadows_builtin_type.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +The member "Vector2" cannot have the same name as a builtin type. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/constant_name_shadows_builtin_type.gd b/modules/gdscript/tests/scripts/analyzer/errors/constant_name_shadows_builtin_type.gd new file mode 100644 index 0000000000..a7c0a29a69 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/constant_name_shadows_builtin_type.gd @@ -0,0 +1,4 @@ +const Vector2 = 0 + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/constant_name_shadows_builtin_type.out b/modules/gdscript/tests/scripts/analyzer/errors/constant_name_shadows_builtin_type.out new file mode 100644 index 0000000000..87863baf75 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/constant_name_shadows_builtin_type.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +The member "Vector2" cannot have the same name as a builtin type. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_name_shadows_builtin_type.gd b/modules/gdscript/tests/scripts/analyzer/errors/enum_name_shadows_builtin_type.gd new file mode 100644 index 0000000000..930f91b389 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_name_shadows_builtin_type.gd @@ -0,0 +1,4 @@ +enum Vector2 { A, B } + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_name_shadows_builtin_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_name_shadows_builtin_type.out new file mode 100644 index 0000000000..87863baf75 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_name_shadows_builtin_type.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +The member "Vector2" cannot have the same name as a builtin type. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/variable_name_shadows_builtin_type.gd b/modules/gdscript/tests/scripts/analyzer/errors/variable_name_shadows_builtin_type.gd new file mode 100644 index 0000000000..7cba29884c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/variable_name_shadows_builtin_type.gd @@ -0,0 +1,4 @@ +var Vector2 + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/variable_name_shadows_builtin_type.out b/modules/gdscript/tests/scripts/analyzer/errors/variable_name_shadows_builtin_type.out new file mode 100644 index 0000000000..87863baf75 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/variable_name_shadows_builtin_type.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +The member "Vector2" cannot have the same name as a builtin type. diff --git a/modules/gdscript/tests/scripts/runtime/features/property_with_operator_assignment.gd b/modules/gdscript/tests/scripts/runtime/features/property_with_operator_assignment.gd new file mode 100644 index 0000000000..3eb02816ed --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/property_with_operator_assignment.gd @@ -0,0 +1,11 @@ +#GDTEST_OK +var prop : int = 0: + get: + return prop + set(value): + prop = value % 7 + +func test(): + for i in 7: + prop += 1 + print(prop) diff --git a/modules/gdscript/tests/scripts/runtime/features/property_with_operator_assignment.out b/modules/gdscript/tests/scripts/runtime/features/property_with_operator_assignment.out new file mode 100644 index 0000000000..76157853f2 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/property_with_operator_assignment.out @@ -0,0 +1,8 @@ +GDTEST_OK +1 +2 +3 +4 +5 +6 +0 diff --git a/modules/gltf/doc_classes/GLTFLight.xml b/modules/gltf/doc_classes/GLTFLight.xml index 91df7d8014..b4f03cd1ed 100644 --- a/modules/gltf/doc_classes/GLTFLight.xml +++ b/modules/gltf/doc_classes/GLTFLight.xml @@ -7,17 +7,25 @@ <tutorials> </tutorials> <members> - <member name="color" type="Color" setter="set_color" getter="get_color" default="Color(0, 0, 0, 1)"> + <member name="color" type="Color" setter="set_color" getter="get_color" default="Color(1, 1, 1, 1)"> + The [Color] of the light. Defaults to white. A black color causes the light to have no effect. </member> <member name="inner_cone_angle" type="float" setter="set_inner_cone_angle" getter="get_inner_cone_angle" default="0.0"> + The inner angle of the cone in a spotlight. Must be less than or equal to the outer cone angle. + Within this angle, the light is at full brightness. Between the inner and outer cone angles, there is a transition from full brightness to zero brightness. When creating a Godot [SpotLight3D], the ratio between the inner and outer cone angles is used to calculate the attenuation of the light. </member> - <member name="intensity" type="float" setter="set_intensity" getter="get_intensity" default="0.0"> + <member name="intensity" type="float" setter="set_intensity" getter="get_intensity" default="1.0"> + The intensity of the light. This is expressed in candelas (lumens per steradian) for point and spot lights, and lux (lumens per m²) for directional lights. When creating a Godot light, this value is converted to a unitless multiplier. </member> <member name="light_type" type="String" setter="set_light_type" getter="get_light_type" default=""""> + The type of the light. The values accepted by Godot are "point", "spot", and "directional", which correspond to Godot's [OmniLight3D], [SpotLight3D], and [DirectionalLight3D] respectively. </member> - <member name="outer_cone_angle" type="float" setter="set_outer_cone_angle" getter="get_outer_cone_angle" default="0.0"> + <member name="outer_cone_angle" type="float" setter="set_outer_cone_angle" getter="get_outer_cone_angle" default="0.785398"> + The outer angle of the cone in a spotlight. Must be greater than or equal to the inner angle. + At this angle, the light drops off to zero brightness. Between the inner and outer cone angles, there is a transition from full brightness to zero brightness. If this angle is a half turn, then the spotlight emits in all directions. When creating a Godot [SpotLight3D], the outer cone angle is used as the angle of the spotlight. </member> - <member name="range" type="float" setter="set_range" getter="get_range" default="0.0"> + <member name="range" type="float" setter="set_range" getter="get_range" default="inf"> + The range of the light, beyond which the light has no effect. GLTF lights with no range defined behave like physical lights (which have infinite range). When creating a Godot light, the range is clamped to 4096. </member> </members> </class> diff --git a/modules/gltf/editor_scene_exporter_gltf_plugin.cpp b/modules/gltf/editor_scene_exporter_gltf_plugin.cpp index fd9f758f10..3ce5ea23dc 100644 --- a/modules/gltf/editor_scene_exporter_gltf_plugin.cpp +++ b/modules/gltf/editor_scene_exporter_gltf_plugin.cpp @@ -86,7 +86,7 @@ void SceneExporterGLTFPlugin::convert_scene_to_gltf2() { editor->show_accept(TTR("This operation can't be done without a scene."), TTR("OK")); return; } - String filename = String(root->get_filename().get_file().get_basename()); + String filename = String(root->get_scene_file_path().get_file().get_basename()); if (filename.is_empty()) { filename = root->get_name(); } diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index df2856ec7c..5f2e8d4ba6 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -78,7 +78,10 @@ Error GLTFDocument::serialize(Ref<GLTFState> state, Node *p_root, const String &p_path) { uint64_t begin_time = OS::get_singleton()->get_ticks_usec(); - _convert_scene_node(state, p_root, p_root, -1, -1); + state->skeleton3d_to_gltf_skeleton.clear(); + state->skin_and_skeleton3d_to_gltf_skin.clear(); + + _convert_scene_node(state, p_root, -1, -1); if (!state->buffers.size()) { state->buffers.push_back(Vector<uint8_t>()); } @@ -97,11 +100,7 @@ Error GLTFDocument::serialize(Ref<GLTFState> state, Node *p_root, const String & if (err != OK) { return Error::FAILED; } - /* STEP 4 CREATE BONE ATTACHMENTS */ - err = _serialize_bone_attachment(state); - if (err != OK) { - return Error::FAILED; - } + /* STEP 5 SERIALIZE MESHES (we have enough info now) */ err = _serialize_meshes(state); if (err != OK) { @@ -249,30 +248,6 @@ Error GLTFDocument::_parse_json(const String &p_path, Ref<GLTFState> state) { return OK; } -Error GLTFDocument::_serialize_bone_attachment(Ref<GLTFState> state) { - for (int skeleton_i = 0; skeleton_i < state->skeletons.size(); skeleton_i++) { - for (int attachment_i = 0; attachment_i < state->skeletons[skeleton_i]->bone_attachments.size(); attachment_i++) { - BoneAttachment3D *bone_attachment = state->skeletons[skeleton_i]->bone_attachments[attachment_i]; - String bone_name = bone_attachment->get_bone_name(); - bone_name = _sanitize_bone_name(bone_name); - int32_t bone = state->skeletons[skeleton_i]->godot_skeleton->find_bone(bone_name); - ERR_CONTINUE(bone == -1); - for (int skin_i = 0; skin_i < state->skins.size(); skin_i++) { - if (state->skins[skin_i]->skeleton != skeleton_i) { - continue; - } - - for (int node_i = 0; node_i < bone_attachment->get_child_count(); node_i++) { - ERR_CONTINUE(bone >= state->skins[skin_i]->joints.size()); - _convert_scene_node(state, bone_attachment->get_child(node_i), bone_attachment->get_owner(), state->skins[skin_i]->joints[bone], 0); - } - break; - } - } - } - return OK; -} - Error GLTFDocument::_parse_glb(const String &p_path, Ref<GLTFState> state) { Error err; FileAccessRef f = FileAccess::open(p_path, FileAccess::READ, &err); @@ -2131,11 +2106,14 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { continue; } Array primitives; - Array targets; Dictionary gltf_mesh; Array target_names; Array weights; + for (int morph_i = 0; morph_i < import_mesh->get_blend_shape_count(); morph_i++) { + target_names.push_back(import_mesh->get_blend_shape_name(morph_i)); + } for (int surface_i = 0; surface_i < import_mesh->get_surface_count(); surface_i++) { + Array targets; Dictionary primitive; Mesh::PrimitiveType primitive_type = import_mesh->get_surface_primitive_type(surface_i); switch (primitive_type) { @@ -2337,10 +2315,10 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { const Array &a = array[Mesh::ARRAY_WEIGHTS]; const Vector<Vector3> &vertex_array = array[Mesh::ARRAY_VERTEX]; if ((a.size() / JOINT_GROUP_SIZE) == vertex_array.size()) { - const int ret_size = a.size() / JOINT_GROUP_SIZE; + int32_t vertex_count = vertex_array.size(); Vector<Color> attribs; - attribs.resize(ret_size); - for (int i = 0; i < ret_size; i++) { + attribs.resize(vertex_count); + for (int i = 0; i < vertex_count; i++) { attribs.write[i] = Color(a[(i * JOINT_GROUP_SIZE) + 0], a[(i * JOINT_GROUP_SIZE) + 1], a[(i * JOINT_GROUP_SIZE) + 2], a[(i * JOINT_GROUP_SIZE) + 3]); } attributes["WEIGHTS_0"] = _encode_accessor_as_weights(state, attribs, true); @@ -2410,7 +2388,6 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { ArrayMesh::BlendShapeMode shape_mode = import_mesh->get_blend_shape_mode(); for (int morph_i = 0; morph_i < import_mesh->get_blend_shape_count(); morph_i++) { Array array_morph = import_mesh->get_surface_blend_shape_arrays(surface_i, morph_i); - target_names.push_back(import_mesh->get_blend_shape_name(morph_i)); Dictionary t; Vector<Vector3> varr = array_morph[Mesh::ARRAY_VERTEX]; Array mesh_arrays = import_mesh->get_surface_arrays(surface_i); @@ -2427,22 +2404,21 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { } Vector<Vector3> narr = array_morph[Mesh::ARRAY_NORMAL]; - if (varr.size()) { + if (narr.size()) { t["NORMAL"] = _encode_accessor_as_vec3(state, narr, true); } Vector<real_t> tarr = array_morph[Mesh::ARRAY_TANGENT]; if (tarr.size()) { const int ret_size = tarr.size() / 4; - Vector<Color> attribs; + Vector<Vector3> attribs; attribs.resize(ret_size); for (int i = 0; i < ret_size; i++) { - Color tangent; - tangent.r = tarr[(i * 4) + 0]; - tangent.g = tarr[(i * 4) + 1]; - tangent.b = tarr[(i * 4) + 2]; - tangent.a = tarr[(i * 4) + 3]; + Vector3 vec3; + vec3.x = tarr[(i * 4) + 0]; + vec3.y = tarr[(i * 4) + 1]; + vec3.z = tarr[(i * 4) + 2]; } - t["TANGENT"] = _encode_accessor_as_color(state, attribs, true); + t["TANGENT"] = _encode_accessor_as_vec3(state, attribs, true); } targets.push_back(t); } @@ -2471,12 +2447,13 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { Dictionary e; e["targetNames"] = target_names; - for (int j = 0; j < target_names.size(); j++) { + weights.resize(target_names.size()); + for (int name_i = 0; name_i < target_names.size(); name_i++) { real_t weight = 0.0; - if (j < state->meshes.write[gltf_mesh_i]->get_blend_weights().size()) { - weight = state->meshes.write[gltf_mesh_i]->get_blend_weights()[j]; + if (name_i < state->meshes.write[gltf_mesh_i]->get_blend_weights().size()) { + weight = state->meshes.write[gltf_mesh_i]->get_blend_weights()[name_i]; } - weights.push_back(weight); + weights[name_i] = weight; } if (weights.size()) { gltf_mesh["weights"] = weights; @@ -3757,10 +3734,7 @@ void GLTFDocument::spec_gloss_to_metal_base_color(const Color &p_specular_factor r_base_color.g = Math::lerp(base_color_from_diffuse.g, base_color_from_specular.g, r_metallic * r_metallic); r_base_color.b = Math::lerp(base_color_from_diffuse.b, base_color_from_specular.b, r_metallic * r_metallic); r_base_color.a = p_diffuse.a; - r_base_color.r = CLAMP(r_base_color.r, 0.0f, 1.0f); - r_base_color.g = CLAMP(r_base_color.g, 0.0f, 1.0f); - r_base_color.b = CLAMP(r_base_color.b, 0.0f, 1.0f); - r_base_color.a = CLAMP(r_base_color.a, 0.0f, 1.0f); + r_base_color = r_base_color.clamp(); } GLTFNodeIndex GLTFDocument::_find_highest_node(Ref<GLTFState> state, const Vector<GLTFNodeIndex> &subset) { @@ -4288,6 +4262,7 @@ Error GLTFDocument::_create_skeletons(Ref<GLTFState> state) { Skeleton3D *skeleton = memnew(Skeleton3D); gltf_skeleton->godot_skeleton = skeleton; + state->skeleton3d_to_gltf_skeleton[skeleton->get_instance_id()] = skel_i; // Make a unique name, no gltf node represents this skeleton skeleton->set_name(_gen_unique_name(state, "Skeleton3D")); @@ -4373,6 +4348,16 @@ Error GLTFDocument::_map_skin_joints_indices_to_skeleton_bone_indices(Ref<GLTFSt Error GLTFDocument::_serialize_skins(Ref<GLTFState> state) { _remove_duplicate_skins(state); + Array json_skins; + for (int skin_i = 0; skin_i < state->skins.size(); skin_i++) { + Ref<GLTFSkin> gltf_skin = state->skins[skin_i]; + Dictionary json_skin; + json_skin["inverseBindMatrices"] = _encode_accessor_as_xform(state, gltf_skin->inverse_binds, false); + json_skin["joints"] = gltf_skin->get_joints(); + json_skin["name"] = gltf_skin->get_name(); + json_skins.push_back(json_skin); + } + state->json["skins"] = json_skins; return OK; } @@ -4751,30 +4736,74 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> state) { channels.push_back(t); } if (track.weight_tracks.size()) { + double length = 0.0f; + + for (int32_t track_idx = 0; track_idx < track.weight_tracks.size(); track_idx++) { + int32_t last_time_index = track.weight_tracks[track_idx].times.size() - 1; + length = MAX(length, track.weight_tracks[track_idx].times[last_time_index]); + } + Dictionary t; t["sampler"] = samplers.size(); Dictionary s; - Vector<real_t> times; - Vector<real_t> values; + const double increment = 1.0 / BAKE_FPS; + { + double time = 0.0; + bool last = false; + while (true) { + times.push_back(time); + if (last) { + break; + } + time += increment; + if (time >= length) { + last = true; + time = length; + } + } + } - for (int32_t times_i = 0; times_i < track.weight_tracks[0].times.size(); times_i++) { - real_t time = track.weight_tracks[0].times[times_i]; - times.push_back(time); + for (int32_t track_idx = 0; track_idx < track.weight_tracks.size(); track_idx++) { + double time = 0.0; + bool last = false; + Vector<real_t> weight_track; + while (true) { + float weight = _interpolate_track<float>(track.weight_tracks[track_idx].times, + track.weight_tracks[track_idx].values, + time, + track.weight_tracks[track_idx].interpolation); + weight_track.push_back(weight); + if (last) { + break; + } + time += increment; + if (time >= length) { + last = true; + time = length; + } + } + track.weight_tracks.write[track_idx].times = times; + track.weight_tracks.write[track_idx].values = weight_track; } - values.resize(times.size() * track.weight_tracks.size()); - // TODO Sort by order in blend shapes + Vector<real_t> all_track_times = times; + Vector<real_t> all_track_values; + int32_t values_size = track.weight_tracks[0].values.size(); + int32_t weight_tracks_size = track.weight_tracks.size(); + all_track_values.resize(weight_tracks_size * values_size); for (int k = 0; k < track.weight_tracks.size(); k++) { Vector<float> wdata = track.weight_tracks[k].values; for (int l = 0; l < wdata.size(); l++) { - values.write[l * track.weight_tracks.size() + k] = wdata.write[l]; + int32_t index = l * weight_tracks_size + k; + ERR_BREAK(index >= all_track_values.size()); + all_track_values.write[index] = wdata.write[l]; } } s["interpolation"] = interpolation_to_string(track.weight_tracks[track.weight_tracks.size() - 1].interpolation); - s["input"] = _encode_accessor_as_floats(state, times, false); - s["output"] = _encode_accessor_as_floats(state, values, false); + s["input"] = _encode_accessor_as_floats(state, all_track_times, false); + s["output"] = _encode_accessor_as_floats(state, all_track_values, false); samplers.push_back(s); @@ -4908,7 +4937,7 @@ Error GLTFDocument::_parse_animations(Ref<GLTFState> state) { track->weight_tracks.resize(wc); const int expected_value_count = times.size() * output_count * wc; - ERR_FAIL_COND_V_MSG(weights.size() != expected_value_count, ERR_PARSE_ERROR, "Invalid weight data, expected " + itos(expected_value_count) + " weight values, got " + itos(weights.size()) + " instead."); + ERR_CONTINUE_MSG(weights.size() != expected_value_count, "Invalid weight data, expected " + itos(expected_value_count) + " weight values, got " + itos(weights.size()) + " instead."); const int wlen = weights.size() / wc; for (int k = 0; k < wc; k++) { //separate tracks, having them together is not such a good idea @@ -4973,7 +5002,7 @@ BoneAttachment3D *GLTFDocument::_generate_bone_attachment(Ref<GLTFState> state, return bone_attachment; } -GLTFMeshIndex GLTFDocument::_convert_mesh_instance(Ref<GLTFState> state, MeshInstance3D *p_mesh_instance) { +GLTFMeshIndex GLTFDocument::_convert_mesh_to_gltf(Ref<GLTFState> state, MeshInstance3D *p_mesh_instance) { ERR_FAIL_NULL_V(p_mesh_instance, -1); if (p_mesh_instance->get_mesh().is_null()) { return -1; @@ -5074,7 +5103,7 @@ Node3D *GLTFDocument::_generate_light(Ref<GLTFState> state, Node *scene_parent, const float range = CLAMP(l->range, 0, 4096); // Doubling the range will double the effective brightness, so we need double attenuation (half brightness). // We want to have double intensity give double brightness, so we need half the attenuation. - const float attenuation = range / intensity; + const float attenuation = range / (intensity * 2048); if (l->light_type == "point") { OmniLight3D *light = memnew(OmniLight3D); light->set_param(OmniLight3D::PARAM_ATTENUATION, attenuation); @@ -5150,13 +5179,13 @@ GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> state, Light3D *p_lig OmniLight3D *light = cast_to<OmniLight3D>(p_light); l->range = light->get_param(OmniLight3D::PARAM_RANGE); float attenuation = p_light->get_param(OmniLight3D::PARAM_ATTENUATION); - l->intensity = l->range / attenuation; + l->intensity = l->range / (attenuation * 2048); } else if (cast_to<SpotLight3D>(p_light)) { l->light_type = "spot"; SpotLight3D *light = cast_to<SpotLight3D>(p_light); l->range = light->get_param(SpotLight3D::PARAM_RANGE); float attenuation = light->get_param(SpotLight3D::PARAM_ATTENUATION); - l->intensity = l->range / attenuation; + l->intensity = l->range / (attenuation * 2048); l->outer_cone_angle = Math::deg2rad(light->get_param(SpotLight3D::PARAM_SPOT_ANGLE)); // This equation is the inverse of the import equation (which has a desmos link). @@ -5170,17 +5199,6 @@ GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> state, Light3D *p_lig return light_index; } -GLTFSkeletonIndex GLTFDocument::_convert_skeleton(Ref<GLTFState> state, Skeleton3D *p_skeleton) { - print_verbose("glTF: Converting skeleton: " + p_skeleton->get_name()); - Ref<GLTFSkeleton> gltf_skeleton; - gltf_skeleton.instantiate(); - gltf_skeleton->set_name(_gen_unique_name(state, p_skeleton->get_name())); - gltf_skeleton->godot_skeleton = p_skeleton; - GLTFSkeletonIndex skeleton_i = state->skeletons.size(); - state->skeletons.push_back(gltf_skeleton); - return skeleton_i; -} - void GLTFDocument::_convert_spatial(Ref<GLTFState> state, Node3D *p_spatial, Ref<GLTFNode> p_node) { Transform3D xform = p_spatial->get_transform(); p_node->scale = xform.basis.get_scale(); @@ -5196,7 +5214,7 @@ Node3D *GLTFDocument::_generate_spatial(Ref<GLTFState> state, Node *scene_parent return spatial; } -void GLTFDocument::_convert_scene_node(Ref<GLTFState> state, Node *p_current, Node *p_root, const GLTFNodeIndex p_gltf_parent, const GLTFNodeIndex p_gltf_root) { +void GLTFDocument::_convert_scene_node(Ref<GLTFState> state, Node *p_current, const GLTFNodeIndex p_gltf_parent, const GLTFNodeIndex p_gltf_root) { bool retflag = true; _check_visibility(p_current, retflag); if (retflag) { @@ -5210,37 +5228,41 @@ void GLTFDocument::_convert_scene_node(Ref<GLTFState> state, Node *p_current, No _convert_spatial(state, spatial, gltf_node); } if (cast_to<MeshInstance3D>(p_current)) { - Node3D *spatial = cast_to<Node3D>(p_current); - _convert_mesh_to_gltf(p_current, state, spatial, gltf_node); + MeshInstance3D *mi = cast_to<MeshInstance3D>(p_current); + _convert_mesh_instance_to_gltf(mi, state, gltf_node); } else if (cast_to<BoneAttachment3D>(p_current)) { - _convert_bone_attachment_to_gltf(p_current, state, gltf_node, retflag); - // TODO 2020-12-21 iFire Handle the case of objects under the bone attachment. + BoneAttachment3D *bone = cast_to<BoneAttachment3D>(p_current); + _convert_bone_attachment_to_gltf(bone, state, p_gltf_parent, p_gltf_root, gltf_node); return; } else if (cast_to<Skeleton3D>(p_current)) { - _convert_skeleton_to_gltf(p_current, state, p_gltf_parent, p_gltf_root, gltf_node, p_root); + Skeleton3D *skel = cast_to<Skeleton3D>(p_current); + _convert_skeleton_to_gltf(skel, state, p_gltf_parent, p_gltf_root, gltf_node); // We ignore the Godot Engine node that is the skeleton. return; } else if (cast_to<MultiMeshInstance3D>(p_current)) { - _convert_mult_mesh_instance_to_gltf(p_current, p_gltf_parent, p_gltf_root, gltf_node, state, p_root); + MultiMeshInstance3D *multi = cast_to<MultiMeshInstance3D>(p_current); + _convert_mult_mesh_instance_to_gltf(multi, p_gltf_parent, p_gltf_root, gltf_node, state); #ifdef MODULE_CSG_ENABLED } else if (cast_to<CSGShape3D>(p_current)) { - if (p_current->get_parent() && cast_to<CSGShape3D>(p_current)->is_root_shape()) { - _convert_csg_shape_to_gltf(p_current, p_gltf_parent, gltf_node, state); + CSGShape3D *shape = cast_to<CSGShape3D>(p_current); + if (shape->get_parent() && shape->is_root_shape()) { + _convert_csg_shape_to_gltf(shape, p_gltf_parent, gltf_node, state); } #endif // MODULE_CSG_ENABLED #ifdef MODULE_GRIDMAP_ENABLED } else if (cast_to<GridMap>(p_current)) { - _convert_grid_map_to_gltf(p_current, p_gltf_parent, p_gltf_root, gltf_node, state, p_root); + GridMap *gridmap = Object::cast_to<GridMap>(p_current); + _convert_grid_map_to_gltf(gridmap, p_gltf_parent, p_gltf_root, gltf_node, state); #endif // MODULE_GRIDMAP_ENABLED } else if (cast_to<Camera3D>(p_current)) { Camera3D *camera = Object::cast_to<Camera3D>(p_current); - _convert_camera_to_gltf(camera, state, camera, gltf_node); + _convert_camera_to_gltf(camera, state, gltf_node); } else if (cast_to<Light3D>(p_current)) { Light3D *light = Object::cast_to<Light3D>(p_current); - _convert_light_to_gltf(light, state, light, gltf_node); + _convert_light_to_gltf(light, state, gltf_node); } else if (cast_to<AnimationPlayer>(p_current)) { AnimationPlayer *animation_player = Object::cast_to<AnimationPlayer>(p_current); - _convert_animation_player_to_gltf(animation_player, state, p_gltf_parent, p_gltf_root, gltf_node, p_current, p_root); + _convert_animation_player_to_gltf(animation_player, state, p_gltf_parent, p_gltf_root, gltf_node, p_current); } GLTFNodeIndex current_node_i = state->nodes.size(); GLTFNodeIndex gltf_root = p_gltf_root; @@ -5252,13 +5274,13 @@ void GLTFDocument::_convert_scene_node(Ref<GLTFState> state, Node *p_current, No } _create_gltf_node(state, p_current, current_node_i, p_gltf_parent, gltf_root, gltf_node); for (int node_i = 0; node_i < p_current->get_child_count(); node_i++) { - _convert_scene_node(state, p_current->get_child(node_i), p_root, current_node_i, gltf_root); + _convert_scene_node(state, p_current->get_child(node_i), current_node_i, gltf_root); } } #ifdef MODULE_CSG_ENABLED -void GLTFDocument::_convert_csg_shape_to_gltf(Node *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> gltf_node, Ref<GLTFState> state) { - CSGShape3D *csg = Object::cast_to<CSGShape3D>(p_current); +void GLTFDocument::_convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> gltf_node, Ref<GLTFState> state) { + CSGShape3D *csg = p_current; csg->call("_update_shape"); Array meshes = csg->get_meshes(); if (meshes.size() != 2) { @@ -5289,16 +5311,15 @@ void GLTFDocument::_create_gltf_node(Ref<GLTFState> state, Node *p_scene_parent, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_gltf_node, Ref<GLTFNode> gltf_node) { state->scene_nodes.insert(current_node_i, p_scene_parent); state->nodes.push_back(gltf_node); - if (current_node_i == p_parent_node_index) { - return; - } + ERR_FAIL_COND(current_node_i == p_parent_node_index); + state->nodes.write[current_node_i]->parent = p_parent_node_index; if (p_parent_node_index == -1) { return; } state->nodes.write[p_parent_node_index]->children.push_back(current_node_i); } -void GLTFDocument::_convert_animation_player_to_gltf(AnimationPlayer *animation_player, Ref<GLTFState> state, const GLTFNodeIndex &p_gltf_current, const GLTFNodeIndex &p_gltf_root_index, Ref<GLTFNode> p_gltf_node, Node *p_scene_parent, Node *p_root) { +void GLTFDocument::_convert_animation_player_to_gltf(AnimationPlayer *animation_player, Ref<GLTFState> state, GLTFNodeIndex p_gltf_current, GLTFNodeIndex p_gltf_root_index, Ref<GLTFNode> p_gltf_node, Node *p_scene_parent) { ERR_FAIL_COND(!animation_player); state->animation_players.push_back(animation_player); print_verbose(String("glTF: Converting animation player: ") + animation_player->get_name()); @@ -5317,7 +5338,7 @@ void GLTFDocument::_check_visibility(Node *p_node, bool &retflag) { retflag = false; } -void GLTFDocument::_convert_camera_to_gltf(Camera3D *camera, Ref<GLTFState> state, Node3D *spatial, Ref<GLTFNode> gltf_node) { +void GLTFDocument::_convert_camera_to_gltf(Camera3D *camera, Ref<GLTFState> state, Ref<GLTFNode> gltf_node) { ERR_FAIL_COND(!camera); GLTFCameraIndex camera_index = _convert_camera(state, camera); if (camera_index != -1) { @@ -5325,7 +5346,7 @@ void GLTFDocument::_convert_camera_to_gltf(Camera3D *camera, Ref<GLTFState> stat } } -void GLTFDocument::_convert_light_to_gltf(Light3D *light, Ref<GLTFState> state, Node3D *spatial, Ref<GLTFNode> gltf_node) { +void GLTFDocument::_convert_light_to_gltf(Light3D *light, Ref<GLTFState> state, Ref<GLTFNode> gltf_node) { ERR_FAIL_COND(!light); GLTFLightIndex light_index = _convert_light(state, light); if (light_index != -1) { @@ -5334,43 +5355,39 @@ void GLTFDocument::_convert_light_to_gltf(Light3D *light, Ref<GLTFState> state, } #ifdef MODULE_GRIDMAP_ENABLED -void GLTFDocument::_convert_grid_map_to_gltf(Node *p_scene_parent, const GLTFNodeIndex &p_parent_node_index, const GLTFNodeIndex &p_root_node_index, Ref<GLTFNode> gltf_node, Ref<GLTFState> state, Node *p_root_node) { - GridMap *grid_map = Object::cast_to<GridMap>(p_scene_parent); - ERR_FAIL_COND(!grid_map); - Array cells = grid_map->get_used_cells(); +void GLTFDocument::_convert_grid_map_to_gltf(GridMap *p_grid_map, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> gltf_node, Ref<GLTFState> state) { + Array cells = p_grid_map->get_used_cells(); for (int32_t k = 0; k < cells.size(); k++) { GLTFNode *new_gltf_node = memnew(GLTFNode); gltf_node->children.push_back(state->nodes.size()); state->nodes.push_back(new_gltf_node); Vector3 cell_location = cells[k]; - int32_t cell = grid_map->get_cell_item( + int32_t cell = p_grid_map->get_cell_item( Vector3(cell_location.x, cell_location.y, cell_location.z)); EditorSceneImporterMeshNode3D *import_mesh_node = memnew(EditorSceneImporterMeshNode3D); - import_mesh_node->set_mesh(grid_map->get_mesh_library()->get_item_mesh(cell)); + import_mesh_node->set_mesh(p_grid_map->get_mesh_library()->get_item_mesh(cell)); Transform3D cell_xform; cell_xform.basis.set_orthogonal_index( - grid_map->get_cell_item_orientation( + p_grid_map->get_cell_item_orientation( Vector3(cell_location.x, cell_location.y, cell_location.z))); - cell_xform.basis.scale(Vector3(grid_map->get_cell_scale(), - grid_map->get_cell_scale(), - grid_map->get_cell_scale())); - cell_xform.set_origin(grid_map->map_to_world( + cell_xform.basis.scale(Vector3(p_grid_map->get_cell_scale(), + p_grid_map->get_cell_scale(), + p_grid_map->get_cell_scale())); + cell_xform.set_origin(p_grid_map->map_to_world( Vector3(cell_location.x, cell_location.y, cell_location.z))); Ref<GLTFMesh> gltf_mesh; gltf_mesh.instantiate(); gltf_mesh = import_mesh_node; new_gltf_node->mesh = state->meshes.size(); state->meshes.push_back(gltf_mesh); - new_gltf_node->xform = cell_xform * grid_map->get_transform(); - new_gltf_node->set_name(_gen_unique_name(state, grid_map->get_mesh_library()->get_item_name(cell))); + new_gltf_node->xform = cell_xform * p_grid_map->get_transform(); + new_gltf_node->set_name(_gen_unique_name(state, p_grid_map->get_mesh_library()->get_item_name(cell))); } } #endif // MODULE_GRIDMAP_ENABLED -void GLTFDocument::_convert_mult_mesh_instance_to_gltf(Node *p_scene_parent, const GLTFNodeIndex &p_parent_node_index, const GLTFNodeIndex &p_root_node_index, Ref<GLTFNode> gltf_node, Ref<GLTFState> state, Node *p_root_node) { - MultiMeshInstance3D *multi_mesh_instance = Object::cast_to<MultiMeshInstance3D>(p_scene_parent); - ERR_FAIL_COND(!multi_mesh_instance); - Ref<MultiMesh> multi_mesh = multi_mesh_instance->get_multimesh(); +void GLTFDocument::_convert_mult_mesh_instance_to_gltf(MultiMeshInstance3D *p_multi_mesh_instance, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> gltf_node, Ref<GLTFState> state) { + Ref<MultiMesh> multi_mesh = p_multi_mesh_instance->get_multimesh(); if (multi_mesh.is_valid()) { for (int32_t instance_i = 0; instance_i < multi_mesh->get_instance_count(); instance_i++) { @@ -5386,9 +5403,9 @@ void GLTFDocument::_convert_mult_mesh_instance_to_gltf(Node *p_scene_parent, con transform.basis.set_quaternion_scale(quaternion, Vector3(scale.x, 0, scale.y)); transform = - multi_mesh_instance->get_transform() * transform; + p_multi_mesh_instance->get_transform() * transform; } else if (multi_mesh->get_transform_format() == MultiMesh::TRANSFORM_3D) { - transform = multi_mesh_instance->get_transform() * + transform = p_multi_mesh_instance->get_transform() * multi_mesh->get_instance_transform(instance_i); } Ref<ArrayMesh> mm = multi_mesh->get_mesh(); @@ -5408,56 +5425,102 @@ void GLTFDocument::_convert_mult_mesh_instance_to_gltf(Node *p_scene_parent, con state->meshes.push_back(gltf_mesh); } new_gltf_node->xform = transform; - new_gltf_node->set_name(_gen_unique_name(state, multi_mesh_instance->get_name())); + new_gltf_node->set_name(_gen_unique_name(state, p_multi_mesh_instance->get_name())); gltf_node->children.push_back(state->nodes.size()); state->nodes.push_back(new_gltf_node); } } } -void GLTFDocument::_convert_skeleton_to_gltf(Node *p_scene_parent, Ref<GLTFState> state, const GLTFNodeIndex &p_parent_node_index, const GLTFNodeIndex &p_root_node_index, Ref<GLTFNode> gltf_node, Node *p_root_node) { - Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(p_scene_parent); - if (skeleton) { - // Remove placeholder skeleton3d node by not creating the gltf node - // Skins are per mesh - for (int node_i = 0; node_i < skeleton->get_child_count(); node_i++) { - _convert_scene_node(state, skeleton->get_child(node_i), p_root_node, p_parent_node_index, p_root_node_index); +void GLTFDocument::_convert_skeleton_to_gltf(Skeleton3D *p_skeleton3d, Ref<GLTFState> state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> gltf_node) { + Skeleton3D *skeleton = p_skeleton3d; + Ref<GLTFSkeleton> gltf_skeleton; + gltf_skeleton.instantiate(); + // GLTFSkeleton is only used to hold internal state data. It will not be written to the document. + // + gltf_skeleton->godot_skeleton = skeleton; + GLTFSkeletonIndex skeleton_i = state->skeletons.size(); + state->skeleton3d_to_gltf_skeleton[skeleton->get_instance_id()] = skeleton_i; + state->skeletons.push_back(gltf_skeleton); + + BoneId bone_count = skeleton->get_bone_count(); + for (BoneId bone_i = 0; bone_i < bone_count; bone_i++) { + Ref<GLTFNode> joint_node; + joint_node.instantiate(); + // Note that we cannot use _gen_unique_bone_name here, because glTF spec requires all node + // names to be unique regardless of whether or not they are used as joints. + joint_node->set_name(_gen_unique_name(state, skeleton->get_bone_name(bone_i))); + Transform3D xform = skeleton->get_bone_rest(bone_i) * skeleton->get_bone_pose(bone_i); + joint_node->scale = xform.basis.get_scale(); + joint_node->rotation = xform.basis.get_rotation_quaternion(); + joint_node->position = xform.origin; + joint_node->joint = true; + GLTFNodeIndex current_node_i = state->nodes.size(); + state->scene_nodes.insert(current_node_i, skeleton); + state->nodes.push_back(joint_node); + + gltf_skeleton->joints.push_back(current_node_i); + if (skeleton->get_bone_parent(bone_i) == -1) { + gltf_skeleton->roots.push_back(current_node_i); + } + gltf_skeleton->godot_bone_node.insert(bone_i, current_node_i); + } + for (BoneId bone_i = 0; bone_i < bone_count; bone_i++) { + GLTFNodeIndex current_node_i = gltf_skeleton->godot_bone_node[bone_i]; + BoneId parent_bone_id = skeleton->get_bone_parent(bone_i); + if (parent_bone_id == -1) { + if (p_parent_node_index != -1) { + state->nodes.write[current_node_i]->parent = p_parent_node_index; + state->nodes.write[p_parent_node_index]->children.push_back(current_node_i); + } + } else { + GLTFNodeIndex parent_node_i = gltf_skeleton->godot_bone_node[parent_bone_id]; + state->nodes.write[current_node_i]->parent = parent_node_i; + state->nodes.write[parent_node_i]->children.push_back(current_node_i); } } + // Remove placeholder skeleton3d node by not creating the gltf node + // Skins are per mesh + for (int node_i = 0; node_i < skeleton->get_child_count(); node_i++) { + _convert_scene_node(state, skeleton->get_child(node_i), p_parent_node_index, p_root_node_index); + } } -void GLTFDocument::_convert_bone_attachment_to_gltf(Node *p_scene_parent, Ref<GLTFState> state, Ref<GLTFNode> gltf_node, bool &retflag) { - retflag = true; - BoneAttachment3D *bone_attachment = Object::cast_to<BoneAttachment3D>(p_scene_parent); - if (bone_attachment) { - Node *node = bone_attachment->get_parent(); - while (node) { - Skeleton3D *bone_attachment_skeleton = Object::cast_to<Skeleton3D>(node); - if (bone_attachment_skeleton) { - for (GLTFSkeletonIndex skeleton_i = 0; skeleton_i < state->skeletons.size(); skeleton_i++) { - if (state->skeletons[skeleton_i]->godot_skeleton != bone_attachment_skeleton) { - continue; - } - state->skeletons.write[skeleton_i]->bone_attachments.push_back(bone_attachment); - break; - } - break; - } - node = node->get_parent(); +void GLTFDocument::_convert_bone_attachment_to_gltf(BoneAttachment3D *p_bone_attachment, Ref<GLTFState> state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> gltf_node) { + Skeleton3D *skeleton; + // Note that relative transforms to external skeletons and pose overrides are not supported. + if (p_bone_attachment->get_use_external_skeleton()) { + skeleton = cast_to<Skeleton3D>(p_bone_attachment->get_node_or_null(p_bone_attachment->get_external_skeleton())); + } else { + skeleton = cast_to<Skeleton3D>(p_bone_attachment->get_parent()); + } + GLTFSkeletonIndex skel_gltf_i = -1; + if (skeleton != nullptr && state->skeleton3d_to_gltf_skeleton.has(skeleton->get_instance_id())) { + skel_gltf_i = state->skeleton3d_to_gltf_skeleton[skeleton->get_instance_id()]; + } + int bone_idx = -1; + if (skeleton != nullptr) { + bone_idx = p_bone_attachment->get_bone_idx(); + if (bone_idx == -1) { + bone_idx = skeleton->find_bone(p_bone_attachment->get_bone_name()); } - gltf_node.unref(); - return; } - retflag = false; + GLTFNodeIndex par_node_index = p_parent_node_index; + if (skeleton != nullptr && bone_idx != -1 && skel_gltf_i != -1) { + Ref<GLTFSkeleton> gltf_skeleton = state->skeletons.write[skel_gltf_i]; + gltf_skeleton->bone_attachments.push_back(p_bone_attachment); + par_node_index = gltf_skeleton->joints[bone_idx]; + } + + for (int node_i = 0; node_i < p_bone_attachment->get_child_count(); node_i++) { + _convert_scene_node(state, p_bone_attachment->get_child(node_i), par_node_index, p_root_node_index); + } } -void GLTFDocument::_convert_mesh_to_gltf(Node *p_scene_parent, Ref<GLTFState> state, Node3D *spatial, Ref<GLTFNode> gltf_node) { - MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_scene_parent); - if (mi) { - GLTFMeshIndex gltf_mesh_index = _convert_mesh_instance(state, mi); - if (gltf_mesh_index != -1) { - gltf_node->mesh = gltf_mesh_index; - } +void GLTFDocument::_convert_mesh_instance_to_gltf(MeshInstance3D *p_scene_parent, Ref<GLTFState> state, Ref<GLTFNode> gltf_node) { + GLTFMeshIndex gltf_mesh_index = _convert_mesh_to_gltf(state, p_scene_parent); + if (gltf_mesh_index != -1) { + gltf_node->mesh = gltf_mesh_index; } } @@ -5911,10 +5974,6 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) { if (node->mesh < 0) { continue; } - Array json_skins; - if (state->json.has("skins")) { - json_skins = state->json["skins"]; - } Map<GLTFNodeIndex, Node *>::Element *mi_element = state->scene_nodes.find(mi_node_i); if (!mi_element) { continue; @@ -5926,7 +5985,6 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) { node->rotation = mi_xform.basis.get_rotation_quaternion(); node->position = mi_xform.origin; - Dictionary json_skin; Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(mi->get_node(mi->get_skeleton_path())); if (!skeleton) { continue; @@ -5935,121 +5993,75 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) { continue; } Ref<Skin> skin = mi->get_skin(); - if (skin.is_null()) { - skin = skeleton->register_skin(nullptr)->get_skin(); - } Ref<GLTFSkin> gltf_skin; gltf_skin.instantiate(); Array json_joints; - GLTFSkeletonIndex skeleton_gltf_i = -1; NodePath skeleton_path = mi->get_skeleton_path(); - bool is_unique = true; - for (int32_t skin_i = 0; skin_i < state->skins.size(); skin_i++) { - Ref<GLTFSkin> prev_gltf_skin = state->skins.write[skin_i]; - if (gltf_skin.is_null()) { - continue; - } - GLTFSkeletonIndex prev_skeleton = prev_gltf_skin->get_skeleton(); - if (prev_skeleton == -1 || prev_skeleton >= state->skeletons.size()) { - continue; - } - if (prev_gltf_skin->get_godot_skin() == skin && state->skeletons[prev_skeleton]->godot_skeleton == skeleton) { - node->skin = skin_i; - node->skeleton = prev_skeleton; - is_unique = false; - break; - } - } - if (!is_unique) { - continue; - } - GLTFSkeletonIndex skeleton_i = _convert_skeleton(state, skeleton); - skeleton_gltf_i = skeleton_i; - ERR_CONTINUE(skeleton_gltf_i == -1); - gltf_skin->skeleton = skeleton_gltf_i; - Ref<GLTFSkeleton> gltf_skeleton = state->skeletons.write[skeleton_gltf_i]; - for (int32_t bind_i = 0; bind_i < skin->get_bind_count(); bind_i++) { - String godot_bone_name = skin->get_bind_name(bind_i); - if (godot_bone_name.is_empty()) { - int32_t bone = skin->get_bind_bone(bind_i); - godot_bone_name = skeleton->get_bone_name(bone); - } - if (skeleton->find_bone(godot_bone_name) == -1) { - godot_bone_name = skeleton->get_bone_name(0); - } - BoneId bone_index = skeleton->find_bone(godot_bone_name); - ERR_CONTINUE(bone_index == -1); - Ref<GLTFNode> joint_node; - joint_node.instantiate(); - String gltf_bone_name = _gen_unique_bone_name(state, skeleton_gltf_i, godot_bone_name); - joint_node->set_name(gltf_bone_name); - - Transform3D bone_rest_xform = skeleton->get_bone_rest(bone_index); - joint_node->scale = bone_rest_xform.basis.get_scale(); - joint_node->rotation = bone_rest_xform.basis.get_rotation_quaternion(); - joint_node->position = bone_rest_xform.origin; - joint_node->joint = true; - - int32_t joint_node_i = state->nodes.size(); - state->nodes.push_back(joint_node); - gltf_skeleton->godot_bone_node.insert(bone_index, joint_node_i); - int32_t joint_index = gltf_skin->joints.size(); - gltf_skin->joint_i_to_bone_i.insert(joint_index, bone_index); - gltf_skin->joints.push_back(joint_node_i); - gltf_skin->joints_original.push_back(joint_node_i); - gltf_skin->inverse_binds.push_back(skin->get_bind_pose(bind_i)); - json_joints.push_back(joint_node_i); - for (Map<GLTFNodeIndex, Node *>::Element *skin_scene_node_i = state->scene_nodes.front(); skin_scene_node_i; skin_scene_node_i = skin_scene_node_i->next()) { - if (skin_scene_node_i->get() == skeleton) { - gltf_skin->skin_root = skin_scene_node_i->key(); - json_skin["skeleton"] = skin_scene_node_i->key(); - } - } - gltf_skin->godot_skin = skin; - gltf_skin->set_name(_gen_unique_name(state, skin->get_name())); - } - for (int32_t bind_i = 0; bind_i < skin->get_bind_count(); bind_i++) { - String bone_name = skeleton->get_bone_name(bind_i); - String godot_bone_name = skin->get_bind_name(bind_i); - int32_t bone = -1; - if (skin->get_bind_bone(bind_i) != -1) { - bone = skin->get_bind_bone(bind_i); - godot_bone_name = skeleton->get_bone_name(bone); - } - bone = skeleton->find_bone(godot_bone_name); - if (bone == -1) { - continue; - } - BoneId bone_parent = skeleton->get_bone_parent(bone); - GLTFNodeIndex joint_node_i = gltf_skeleton->godot_bone_node[bone]; - ERR_CONTINUE(joint_node_i >= state->nodes.size()); - if (bone_parent != -1) { - GLTFNodeIndex parent_joint_gltf_node = gltf_skin->joints[bone_parent]; - Ref<GLTFNode> parent_joint_node = state->nodes.write[parent_joint_gltf_node]; - parent_joint_node->children.push_back(joint_node_i); + Node *skel_node = mi->get_node_or_null(skeleton_path); + Skeleton3D *godot_skeleton = nullptr; + if (skel_node != nullptr) { + godot_skeleton = cast_to<Skeleton3D>(skel_node); + } + if (godot_skeleton != nullptr && state->skeleton3d_to_gltf_skeleton.has(godot_skeleton->get_instance_id())) { + // This is a skinned mesh. If the mesh has no ARRAY_WEIGHTS or ARRAY_BONES, it will be invisible. + const GLTFSkeletonIndex skeleton_gltf_i = state->skeleton3d_to_gltf_skeleton[godot_skeleton->get_instance_id()]; + Ref<GLTFSkeleton> gltf_skeleton = state->skeletons[skeleton_gltf_i]; + int bone_cnt = skeleton->get_bone_count(); + ERR_FAIL_COND(bone_cnt != gltf_skeleton->joints.size()); + + ObjectID gltf_skin_key = skin->get_instance_id(); + ObjectID gltf_skel_key = godot_skeleton->get_instance_id(); + GLTFSkinIndex skin_gltf_i = -1; + GLTFNodeIndex root_gltf_i = -1; + if (!gltf_skeleton->roots.is_empty()) { + root_gltf_i = gltf_skeleton->roots[0]; + } + if (state->skin_and_skeleton3d_to_gltf_skin.has(gltf_skin_key) && state->skin_and_skeleton3d_to_gltf_skin[gltf_skin_key].has(gltf_skel_key)) { + skin_gltf_i = state->skin_and_skeleton3d_to_gltf_skin[gltf_skin_key][gltf_skel_key]; } else { - Node *node_parent = skeleton->get_parent(); - ERR_CONTINUE(!node_parent); - for (Map<GLTFNodeIndex, Node *>::Element *E = state->scene_nodes.front(); E; E = E->next()) { - if (E->get() == node_parent) { - GLTFNodeIndex gltf_node_i = E->key(); - Ref<GLTFNode> gltf_node = state->nodes.write[gltf_node_i]; - gltf_node->children.push_back(joint_node_i); - break; + if (skin.is_null()) { + // Note that gltf_skin_key should remain null, so these can share a reference. + skin = skeleton->register_skin(nullptr)->get_skin(); + } + gltf_skin.instantiate(); + gltf_skin->godot_skin = skin; + gltf_skin->set_name(skin->get_name()); + gltf_skin->skeleton = skeleton_gltf_i; + gltf_skin->skin_root = root_gltf_i; + //gltf_state->godot_to_gltf_node[skel_node] + HashMap<StringName, int> bone_name_to_idx; + for (int bone_i = 0; bone_i < bone_cnt; bone_i++) { + bone_name_to_idx[skeleton->get_bone_name(bone_i)] = bone_i; + } + for (int bind_i = 0, cnt = skin->get_bind_count(); bind_i < cnt; bind_i++) { + int bone_i = skin->get_bind_bone(bind_i); + Transform3D bind_pose = skin->get_bind_pose(bind_i); + StringName bind_name = skin->get_bind_name(bind_i); + if (bind_name != StringName()) { + bone_i = bone_name_to_idx[bind_name]; } + ERR_CONTINUE(bone_i < 0 || bone_i >= bone_cnt); + if (bind_name == StringName()) { + bind_name = skeleton->get_bone_name(bone_i); + } + GLTFNodeIndex skeleton_bone_i = gltf_skeleton->joints[bone_i]; + gltf_skin->joints_original.push_back(skeleton_bone_i); + gltf_skin->joints.push_back(skeleton_bone_i); + gltf_skin->inverse_binds.push_back(bind_pose); + if (skeleton->get_bone_parent(bone_i) == -1) { + gltf_skin->roots.push_back(skeleton_bone_i); + } + gltf_skin->joint_i_to_bone_i[bind_i] = bone_i; + gltf_skin->joint_i_to_name[bind_i] = bind_name; } + skin_gltf_i = state->skins.size(); + state->skins.push_back(gltf_skin); + state->skin_and_skeleton3d_to_gltf_skin[gltf_skin_key][gltf_skel_key] = skin_gltf_i; } + node->skin = skin_gltf_i; + node->skeleton = skeleton_gltf_i; } - _expand_skin(state, gltf_skin); - node->skin = state->skins.size(); - state->skins.push_back(gltf_skin); - - json_skin["inverseBindMatrices"] = _encode_accessor_as_xform(state, gltf_skin->inverse_binds, false); - json_skin["joints"] = json_joints; - json_skin["name"] = gltf_skin->get_name(); - json_skins.push_back(json_skin); - state->json["skins"] = json_skins; } } @@ -6132,7 +6144,6 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state for (int32_t key_i = 0; key_i < key_count; key_i++) { times.write[key_i] = p_animation->track_get_key_time(p_track_i, key_i); } - const float BAKE_FPS = 30.0f; if (track_type == Animation::TYPE_TRANSFORM3D) { p_track.position_track.times = times; p_track.position_track.interpolation = gltf_interpolation; @@ -6370,69 +6381,58 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, const Vector<String> node_suffix = String(orig_track_path).split(":blend_shapes/"); const NodePath path = node_suffix[0]; const String suffix = node_suffix[1]; - const Node *node = ap->get_parent()->get_node_or_null(path); - for (Map<GLTFNodeIndex, Node *>::Element *transform_track_i = state->scene_nodes.front(); transform_track_i; transform_track_i = transform_track_i->next()) { - if (transform_track_i->get() == node) { - const MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(node); - if (!mi) { - continue; - } - Ref<ArrayMesh> array_mesh = mi->get_mesh(); - if (array_mesh.is_null()) { + Node *node = ap->get_parent()->get_node_or_null(path); + MeshInstance3D *mi = cast_to<MeshInstance3D>(node); + Ref<Mesh> mesh = mi->get_mesh(); + ERR_CONTINUE(mesh.is_null()); + int32_t mesh_index = -1; + for (Map<GLTFNodeIndex, Node *>::Element *mesh_track_i = state->scene_nodes.front(); mesh_track_i; mesh_track_i = mesh_track_i->next()) { + if (mesh_track_i->get() == node) { + mesh_index = mesh_track_i->key(); + } + } + ERR_CONTINUE(mesh_index == -1); + Map<int, GLTFAnimation::Track> &tracks = gltf_animation->get_tracks(); + GLTFAnimation::Track track = gltf_animation->get_tracks().has(mesh_index) ? gltf_animation->get_tracks()[mesh_index] : GLTFAnimation::Track(); + if (!tracks.has(mesh_index)) { + for (int32_t shape_i = 0; shape_i < mesh->get_blend_shape_count(); shape_i++) { + String shape_name = mesh->get_blend_shape_name(shape_i); + NodePath shape_path = String(path) + ":blend_shapes/" + shape_name; + int32_t shape_track_i = animation->find_track(shape_path); + if (shape_track_i == -1) { + GLTFAnimation::Channel<float> weight; + weight.interpolation = GLTFAnimation::INTERP_LINEAR; + weight.times.push_back(0.0f); + weight.times.push_back(0.0f); + weight.values.push_back(0.0f); + weight.values.push_back(0.0f); + track.weight_tracks.push_back(weight); continue; } - if (node_suffix.size() != 2) { - continue; + Animation::InterpolationType interpolation = animation->track_get_interpolation_type(track_i); + GLTFAnimation::Interpolation gltf_interpolation = GLTFAnimation::INTERP_LINEAR; + if (interpolation == Animation::InterpolationType::INTERPOLATION_LINEAR) { + gltf_interpolation = GLTFAnimation::INTERP_LINEAR; + } else if (interpolation == Animation::InterpolationType::INTERPOLATION_NEAREST) { + gltf_interpolation = GLTFAnimation::INTERP_STEP; + } else if (interpolation == Animation::InterpolationType::INTERPOLATION_CUBIC) { + gltf_interpolation = GLTFAnimation::INTERP_CUBIC_SPLINE; } - GLTFNodeIndex mesh_index = -1; - for (GLTFNodeIndex node_i = 0; node_i < state->scene_nodes.size(); node_i++) { - if (state->scene_nodes[node_i] == node) { - mesh_index = node_i; - break; - } + int32_t key_count = animation->track_get_key_count(shape_track_i); + GLTFAnimation::Channel<float> weight; + weight.interpolation = gltf_interpolation; + weight.times.resize(key_count); + for (int32_t time_i = 0; time_i < key_count; time_i++) { + weight.times.write[time_i] = animation->track_get_key_time(shape_track_i, time_i); } - ERR_CONTINUE(mesh_index == -1); - Ref<Mesh> mesh = mi->get_mesh(); - ERR_CONTINUE(mesh.is_null()); - for (int32_t shape_i = 0; shape_i < mesh->get_blend_shape_count(); shape_i++) { - if (mesh->get_blend_shape_name(shape_i) != suffix) { - continue; - } - GLTFAnimation::Track track; - Map<int, GLTFAnimation::Track>::Element *blend_shape_track_i = gltf_animation->get_tracks().find(mesh_index); - if (blend_shape_track_i) { - track = blend_shape_track_i->get(); - } - Animation::InterpolationType interpolation = animation->track_get_interpolation_type(track_i); - - GLTFAnimation::Interpolation gltf_interpolation = GLTFAnimation::INTERP_LINEAR; - if (interpolation == Animation::InterpolationType::INTERPOLATION_LINEAR) { - gltf_interpolation = GLTFAnimation::INTERP_LINEAR; - } else if (interpolation == Animation::InterpolationType::INTERPOLATION_NEAREST) { - gltf_interpolation = GLTFAnimation::INTERP_STEP; - } else if (interpolation == Animation::InterpolationType::INTERPOLATION_CUBIC) { - gltf_interpolation = GLTFAnimation::INTERP_CUBIC_SPLINE; - } - Animation::TrackType track_type = animation->track_get_type(track_i); - if (track_type == Animation::TYPE_VALUE) { - int32_t key_count = animation->track_get_key_count(track_i); - GLTFAnimation::Channel<float> weight; - weight.interpolation = gltf_interpolation; - weight.times.resize(key_count); - for (int32_t time_i = 0; time_i < key_count; time_i++) { - weight.times.write[time_i] = animation->track_get_key_time(track_i, time_i); - } - weight.values.resize(key_count); - for (int32_t value_i = 0; value_i < key_count; value_i++) { - weight.values.write[value_i] = animation->track_get_key_value(track_i, value_i); - } - track.weight_tracks.push_back(weight); - } - gltf_animation->get_tracks()[mesh_index] = track; + weight.values.resize(key_count); + for (int32_t value_i = 0; value_i < key_count; value_i++) { + weight.values.write[value_i] = animation->track_get_key_value(shape_track_i, value_i); } + track.weight_tracks.push_back(weight); } + tracks[mesh_index] = track; } - } else if (String(orig_track_path).find(":") != -1) { //Process skeleton const Vector<String> node_suffix = String(orig_track_path).split(":"); diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h index fb798a055a..18aeb81bc0 100644 --- a/modules/gltf/gltf_document.h +++ b/modules/gltf/gltf_document.h @@ -51,6 +51,9 @@ class GLTFSkin; class GLTFNode; class GLTFSpecGloss; class GLTFSkeleton; +class CSGShape3D; +class GridMap; +class MultiMeshInstance3D; using GLTFAccessorIndex = int; using GLTFAnimationIndex = int; @@ -72,6 +75,9 @@ class GLTFDocument : public Resource { friend class GLTFSkin; friend class GLTFSkeleton; +private: + const float BAKE_FPS = 30.0f; + public: const int32_t JOINT_GROUP_SIZE = 4; enum GLTFType { @@ -350,7 +356,6 @@ private: GLTFNodeIndex p_node_i); Error _encode_buffer_bins(Ref<GLTFState> state, const String &p_path); Error _encode_buffer_glb(Ref<GLTFState> state, const String &p_path); - Error _serialize_bone_attachment(Ref<GLTFState> state); Dictionary _serialize_texture_transform_uv1(Ref<BaseMaterial3D> p_material); Dictionary _serialize_texture_transform_uv2(Ref<BaseMaterial3D> p_material); Error _serialize_version(Ref<GLTFState> state); @@ -381,20 +386,17 @@ public: void _generate_skeleton_bone_node(Ref<GLTFState> state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index); void _import_animation(Ref<GLTFState> state, AnimationPlayer *ap, const GLTFAnimationIndex index, const int bake_fps); - GLTFMeshIndex _convert_mesh_instance(Ref<GLTFState> state, - MeshInstance3D *p_mesh_instance); void _convert_mesh_instances(Ref<GLTFState> state); GLTFCameraIndex _convert_camera(Ref<GLTFState> state, Camera3D *p_camera); - void _convert_light_to_gltf(Light3D *light, Ref<GLTFState> state, Node3D *spatial, Ref<GLTFNode> gltf_node); + void _convert_light_to_gltf(Light3D *light, Ref<GLTFState> state, Ref<GLTFNode> gltf_node); GLTFLightIndex _convert_light(Ref<GLTFState> state, Light3D *p_light); - GLTFSkeletonIndex _convert_skeleton(Ref<GLTFState> state, Skeleton3D *p_skeleton); void _convert_spatial(Ref<GLTFState> state, Node3D *p_spatial, Ref<GLTFNode> p_node); - void _convert_scene_node(Ref<GLTFState> state, Node *p_current, Node *p_root, + void _convert_scene_node(Ref<GLTFState> state, Node *p_current, const GLTFNodeIndex p_gltf_current, const GLTFNodeIndex p_gltf_root); #ifdef MODULE_CSG_ENABLED - void _convert_csg_shape_to_gltf(Node *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> gltf_node, Ref<GLTFState> state); + void _convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> gltf_node, Ref<GLTFState> state); #endif // MODULE_CSG_ENABLED void _create_gltf_node(Ref<GLTFState> state, @@ -405,40 +407,39 @@ public: Ref<GLTFNode> gltf_node); void _convert_animation_player_to_gltf( AnimationPlayer *animation_player, Ref<GLTFState> state, - const GLTFNodeIndex &p_gltf_current, - const GLTFNodeIndex &p_gltf_root_index, - Ref<GLTFNode> p_gltf_node, Node *p_scene_parent, - Node *p_root); + GLTFNodeIndex p_gltf_current, + GLTFNodeIndex p_gltf_root_index, + Ref<GLTFNode> p_gltf_node, Node *p_scene_parent); void _check_visibility(Node *p_node, bool &retflag); void _convert_camera_to_gltf(Camera3D *camera, Ref<GLTFState> state, - Node3D *spatial, Ref<GLTFNode> gltf_node); #ifdef MODULE_GRIDMAP_ENABLED void _convert_grid_map_to_gltf( - Node *p_scene_parent, - const GLTFNodeIndex &p_parent_node_index, - const GLTFNodeIndex &p_root_node_index, - Ref<GLTFNode> gltf_node, Ref<GLTFState> state, - Node *p_root_node); + GridMap *p_grid_map, + GLTFNodeIndex p_parent_node_index, + GLTFNodeIndex p_root_node_index, + Ref<GLTFNode> gltf_node, Ref<GLTFState> state); #endif // MODULE_GRIDMAP_ENABLED void _convert_mult_mesh_instance_to_gltf( - Node *p_scene_parent, - const GLTFNodeIndex &p_parent_node_index, - const GLTFNodeIndex &p_root_node_index, - Ref<GLTFNode> gltf_node, Ref<GLTFState> state, - Node *p_root_node); + MultiMeshInstance3D *p_scene_parent, + GLTFNodeIndex p_parent_node_index, + GLTFNodeIndex p_root_node_index, + Ref<GLTFNode> gltf_node, Ref<GLTFState> state); void _convert_skeleton_to_gltf( - Node *p_scene_parent, Ref<GLTFState> state, - const GLTFNodeIndex &p_parent_node_index, - const GLTFNodeIndex &p_root_node_index, - Ref<GLTFNode> gltf_node, Node *p_root_node); - void _convert_bone_attachment_to_gltf(Node *p_scene_parent, + Skeleton3D *p_scene_parent, Ref<GLTFState> state, + GLTFNodeIndex p_parent_node_index, + GLTFNodeIndex p_root_node_index, + Ref<GLTFNode> gltf_node); + void _convert_bone_attachment_to_gltf(BoneAttachment3D *p_bone_attachment, + Ref<GLTFState> state, + GLTFNodeIndex p_parent_node_index, + GLTFNodeIndex p_root_node_index, + Ref<GLTFNode> gltf_node); + void _convert_mesh_instance_to_gltf(MeshInstance3D *p_mesh_instance, Ref<GLTFState> state, - Ref<GLTFNode> gltf_node, - bool &retflag); - void _convert_mesh_to_gltf(Node *p_scene_parent, - Ref<GLTFState> state, Node3D *spatial, Ref<GLTFNode> gltf_node); + GLTFMeshIndex _convert_mesh_to_gltf(Ref<GLTFState> state, + MeshInstance3D *p_mesh_instance); void _convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, String p_animation_track_name); Error serialize(Ref<GLTFState> state, Node *p_root, const String &p_path); diff --git a/modules/gltf/gltf_light.h b/modules/gltf/gltf_light.h index 079fb18151..62a20d2f16 100644 --- a/modules/gltf/gltf_light.h +++ b/modules/gltf/gltf_light.h @@ -42,12 +42,12 @@ protected: static void _bind_methods(); private: - Color color; - float intensity = 0.0f; + Color color = Color(1.0f, 1.0f, 1.0f); + float intensity = 1.0f; String light_type; - float range = 0.0f; + float range = INFINITY; float inner_cone_angle = 0.0f; - float outer_cone_angle = 0.0f; + float outer_cone_angle = Math_TAU / 8.0f; public: Color get_color(); diff --git a/modules/gltf/gltf_state.h b/modules/gltf/gltf_state.h index 896ea5fc56..d6614da804 100644 --- a/modules/gltf/gltf_state.h +++ b/modules/gltf/gltf_state.h @@ -44,6 +44,8 @@ #include "gltf_texture.h" #include "core/io/resource.h" +#include "core/templates/map.h" +#include "core/templates/pair.h" #include "core/templates/vector.h" #include "scene/animation/animation_player.h" #include "scene/resources/texture.h" @@ -87,6 +89,9 @@ class GLTFState : public Resource { Vector<Ref<GLTFAnimation>> animations; Map<GLTFNodeIndex, Node *> scene_nodes; + Map<ObjectID, GLTFSkeletonIndex> skeleton3d_to_gltf_skeleton; + Map<ObjectID, Map<ObjectID, GLTFSkinIndex>> skin_and_skeleton3d_to_gltf_skin; + protected: static void _bind_methods(); diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 487e6deac0..116c0e00f9 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -377,10 +377,7 @@ int GridMap::get_cell_item_orientation(const Vector3i &p_position) const { } Vector3i GridMap::world_to_map(const Vector3 &p_world_position) const { - Vector3 map_position = p_world_position / cell_size; - map_position.x = floor(map_position.x); - map_position.y = floor(map_position.y); - map_position.z = floor(map_position.z); + Vector3 map_position = (p_world_position / cell_size).floor(); return Vector3i(map_position); } diff --git a/modules/mobile_vr/register_types.cpp b/modules/mobile_vr/register_types.cpp index 47d1fe482c..233c16531a 100644 --- a/modules/mobile_vr/register_types.cpp +++ b/modules/mobile_vr/register_types.cpp @@ -32,15 +32,30 @@ #include "mobile_vr_interface.h" +Ref<MobileVRInterface> mobile_vr; + void register_mobile_vr_types() { GDREGISTER_CLASS(MobileVRInterface); if (XRServer::get_singleton()) { - Ref<MobileVRInterface> mobile_vr; mobile_vr.instantiate(); XRServer::get_singleton()->add_interface(mobile_vr); } } void unregister_mobile_vr_types() { + if (mobile_vr.is_valid()) { + // uninitialise our interface if it is initialised + if (mobile_vr->is_initialized()) { + mobile_vr->uninitialize(); + } + + // unregister our interface from the XR server + if (XRServer::get_singleton()) { + XRServer::get_singleton()->remove_interface(mobile_vr); + } + + // and release + mobile_vr.unref(); + } } diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 6cc7ddb424..af7c54dd5b 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -3511,10 +3511,10 @@ int CSharpScript::get_member_line(const StringName &p_member) const { } Multiplayer::RPCMode CSharpScript::_member_get_rpc_mode(IMonoClassMember *p_member) const { - if (p_member->has_attribute(CACHED_CLASS(RemoteAttribute))) { + if (p_member->has_attribute(CACHED_CLASS(AnyAttribute))) { return Multiplayer::RPC_MODE_ANY; } - if (p_member->has_attribute(CACHED_CLASS(PuppetAttribute))) { + if (p_member->has_attribute(CACHED_CLASS(AuthorityAttribute))) { return Multiplayer::RPC_MODE_AUTHORITY; } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs index 2dedba2be3..1da91ea867 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs @@ -3,8 +3,8 @@ using System; namespace Godot { [AttributeUsage(AttributeTargets.Method)] - public class RemoteAttribute : Attribute { } + public class AnyAttribute : Attribute { } [AttributeUsage(AttributeTargets.Method)] - public class PuppetAttribute : Attribute { } + public class AuthorityAttribute : Attribute { } } diff --git a/modules/mono/mono_gd/gd_mono_cache.cpp b/modules/mono/mono_gd/gd_mono_cache.cpp index 8b215a66c2..34e845a589 100644 --- a/modules/mono/mono_gd/gd_mono_cache.cpp +++ b/modules/mono/mono_gd/gd_mono_cache.cpp @@ -140,8 +140,8 @@ void CachedData::clear_godot_api_cache() { field_ExportAttribute_hintString = nullptr; class_SignalAttribute = nullptr; class_ToolAttribute = nullptr; - class_RemoteAttribute = nullptr; - class_PuppetAttribute = nullptr; + class_AnyAttribute = nullptr; + class_AuthorityAttribute = nullptr; class_GodotMethodAttribute = nullptr; field_GodotMethodAttribute_methodName = nullptr; class_ScriptPathAttribute = nullptr; @@ -265,8 +265,8 @@ void update_godot_api_cache() { CACHE_FIELD_AND_CHECK(ExportAttribute, hintString, CACHED_CLASS(ExportAttribute)->get_field("hintString")); CACHE_CLASS_AND_CHECK(SignalAttribute, GODOT_API_CLASS(SignalAttribute)); CACHE_CLASS_AND_CHECK(ToolAttribute, GODOT_API_CLASS(ToolAttribute)); - CACHE_CLASS_AND_CHECK(RemoteAttribute, GODOT_API_CLASS(RemoteAttribute)); - CACHE_CLASS_AND_CHECK(PuppetAttribute, GODOT_API_CLASS(PuppetAttribute)); + CACHE_CLASS_AND_CHECK(AnyAttribute, GODOT_API_CLASS(AnyAttribute)); + CACHE_CLASS_AND_CHECK(AuthorityAttribute, GODOT_API_CLASS(AuthorityAttribute)); CACHE_CLASS_AND_CHECK(GodotMethodAttribute, GODOT_API_CLASS(GodotMethodAttribute)); CACHE_FIELD_AND_CHECK(GodotMethodAttribute, methodName, CACHED_CLASS(GodotMethodAttribute)->get_field("methodName")); CACHE_CLASS_AND_CHECK(ScriptPathAttribute, GODOT_API_CLASS(ScriptPathAttribute)); diff --git a/modules/mono/mono_gd/gd_mono_cache.h b/modules/mono/mono_gd/gd_mono_cache.h index fd28bbda14..e60a4d5279 100644 --- a/modules/mono/mono_gd/gd_mono_cache.h +++ b/modules/mono/mono_gd/gd_mono_cache.h @@ -111,8 +111,8 @@ struct CachedData { GDMonoField *field_ExportAttribute_hintString; GDMonoClass *class_SignalAttribute; GDMonoClass *class_ToolAttribute; - GDMonoClass *class_RemoteAttribute; - GDMonoClass *class_PuppetAttribute; + GDMonoClass *class_AnyAttribute; + GDMonoClass *class_AuthorityAttribute; GDMonoClass *class_GodotMethodAttribute; GDMonoField *field_GodotMethodAttribute_methodName; GDMonoClass *class_ScriptPathAttribute; diff --git a/modules/navigation/godot_navigation_server.cpp b/modules/navigation/godot_navigation_server.cpp index fd965674d6..f600f07c87 100644 --- a/modules/navigation/godot_navigation_server.cpp +++ b/modules/navigation/godot_navigation_server.cpp @@ -133,13 +133,13 @@ RID GodotNavigationServer::map_create() const { GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); RID rid = map_owner.make_rid(); - NavMap *space = map_owner.getornull(rid); + NavMap *space = map_owner.get_or_null(rid); space->set_self(rid); return rid; } COMMAND_2(map_set_active, RID, p_map, bool, p_active) { - NavMap *map = map_owner.getornull(p_map); + NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND(map == nullptr); if (p_active) { @@ -156,84 +156,84 @@ COMMAND_2(map_set_active, RID, p_map, bool, p_active) { } bool GodotNavigationServer::map_is_active(RID p_map) const { - NavMap *map = map_owner.getornull(p_map); + NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND_V(map == nullptr, false); return active_maps.find(map) >= 0; } COMMAND_2(map_set_up, RID, p_map, Vector3, p_up) { - NavMap *map = map_owner.getornull(p_map); + NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND(map == nullptr); map->set_up(p_up); } Vector3 GodotNavigationServer::map_get_up(RID p_map) const { - const NavMap *map = map_owner.getornull(p_map); + const NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND_V(map == nullptr, Vector3()); return map->get_up(); } COMMAND_2(map_set_cell_size, RID, p_map, real_t, p_cell_size) { - NavMap *map = map_owner.getornull(p_map); + NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND(map == nullptr); map->set_cell_size(p_cell_size); } real_t GodotNavigationServer::map_get_cell_size(RID p_map) const { - const NavMap *map = map_owner.getornull(p_map); + const NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND_V(map == nullptr, 0); return map->get_cell_size(); } COMMAND_2(map_set_edge_connection_margin, RID, p_map, real_t, p_connection_margin) { - NavMap *map = map_owner.getornull(p_map); + NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND(map == nullptr); map->set_edge_connection_margin(p_connection_margin); } real_t GodotNavigationServer::map_get_edge_connection_margin(RID p_map) const { - const NavMap *map = map_owner.getornull(p_map); + const NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND_V(map == nullptr, 0); return map->get_edge_connection_margin(); } Vector<Vector3> GodotNavigationServer::map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize, uint32_t p_layers) const { - const NavMap *map = map_owner.getornull(p_map); + const NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND_V(map == nullptr, Vector<Vector3>()); return map->get_path(p_origin, p_destination, p_optimize, p_layers); } Vector3 GodotNavigationServer::map_get_closest_point_to_segment(RID p_map, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const { - const NavMap *map = map_owner.getornull(p_map); + const NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND_V(map == nullptr, Vector3()); return map->get_closest_point_to_segment(p_from, p_to, p_use_collision); } Vector3 GodotNavigationServer::map_get_closest_point(RID p_map, const Vector3 &p_point) const { - const NavMap *map = map_owner.getornull(p_map); + const NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND_V(map == nullptr, Vector3()); return map->get_closest_point(p_point); } Vector3 GodotNavigationServer::map_get_closest_point_normal(RID p_map, const Vector3 &p_point) const { - const NavMap *map = map_owner.getornull(p_map); + const NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND_V(map == nullptr, Vector3()); return map->get_closest_point_normal(p_point); } RID GodotNavigationServer::map_get_closest_point_owner(RID p_map, const Vector3 &p_point) const { - const NavMap *map = map_owner.getornull(p_map); + const NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND_V(map == nullptr, RID()); return map->get_closest_point_owner(p_point); @@ -243,13 +243,13 @@ RID GodotNavigationServer::region_create() const { GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); RID rid = region_owner.make_rid(); - NavRegion *reg = region_owner.getornull(rid); + NavRegion *reg = region_owner.get_or_null(rid); reg->set_self(rid); return rid; } COMMAND_2(region_set_map, RID, p_region, RID, p_map) { - NavRegion *region = region_owner.getornull(p_region); + NavRegion *region = region_owner.get_or_null(p_region); ERR_FAIL_COND(region == nullptr); if (region->get_map() != nullptr) { @@ -262,7 +262,7 @@ COMMAND_2(region_set_map, RID, p_region, RID, p_map) { } if (p_map.is_valid()) { - NavMap *map = map_owner.getornull(p_map); + NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND(map == nullptr); map->add_region(region); @@ -271,28 +271,28 @@ COMMAND_2(region_set_map, RID, p_region, RID, p_map) { } COMMAND_2(region_set_transform, RID, p_region, Transform3D, p_transform) { - NavRegion *region = region_owner.getornull(p_region); + NavRegion *region = region_owner.get_or_null(p_region); ERR_FAIL_COND(region == nullptr); region->set_transform(p_transform); } COMMAND_2(region_set_layers, RID, p_region, uint32_t, p_layers) { - NavRegion *region = region_owner.getornull(p_region); + NavRegion *region = region_owner.get_or_null(p_region); ERR_FAIL_COND(region == nullptr); region->set_layers(p_layers); } uint32_t GodotNavigationServer::region_get_layers(RID p_region) const { - NavRegion *region = region_owner.getornull(p_region); + NavRegion *region = region_owner.get_or_null(p_region); ERR_FAIL_COND_V(region == nullptr, 0); return region->get_layers(); } COMMAND_2(region_set_navmesh, RID, p_region, Ref<NavigationMesh>, p_nav_mesh) { - NavRegion *region = region_owner.getornull(p_region); + NavRegion *region = region_owner.get_or_null(p_region); ERR_FAIL_COND(region == nullptr); region->set_mesh(p_nav_mesh); @@ -309,21 +309,21 @@ void GodotNavigationServer::region_bake_navmesh(Ref<NavigationMesh> r_mesh, Node } int GodotNavigationServer::region_get_connections_count(RID p_region) const { - NavRegion *region = region_owner.getornull(p_region); + NavRegion *region = region_owner.get_or_null(p_region); ERR_FAIL_COND_V(!region, 0); return region->get_connections_count(); } Vector3 GodotNavigationServer::region_get_connection_pathway_start(RID p_region, int p_connection_id) const { - NavRegion *region = region_owner.getornull(p_region); + NavRegion *region = region_owner.get_or_null(p_region); ERR_FAIL_COND_V(!region, Vector3()); return region->get_connection_pathway_start(p_connection_id); } Vector3 GodotNavigationServer::region_get_connection_pathway_end(RID p_region, int p_connection_id) const { - NavRegion *region = region_owner.getornull(p_region); + NavRegion *region = region_owner.get_or_null(p_region); ERR_FAIL_COND_V(!region, Vector3()); return region->get_connection_pathway_end(p_connection_id); @@ -333,13 +333,13 @@ RID GodotNavigationServer::agent_create() const { GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); RID rid = agent_owner.make_rid(); - RvoAgent *agent = agent_owner.getornull(rid); + RvoAgent *agent = agent_owner.get_or_null(rid); agent->set_self(rid); return rid; } COMMAND_2(agent_set_map, RID, p_agent, RID, p_map) { - RvoAgent *agent = agent_owner.getornull(p_agent); + RvoAgent *agent = agent_owner.get_or_null(p_agent); ERR_FAIL_COND(agent == nullptr); if (agent->get_map()) { @@ -353,7 +353,7 @@ COMMAND_2(agent_set_map, RID, p_agent, RID, p_map) { agent->set_map(nullptr); if (p_map.is_valid()) { - NavMap *map = map_owner.getornull(p_map); + NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_COND(map == nullptr); agent->set_map(map); @@ -366,77 +366,77 @@ COMMAND_2(agent_set_map, RID, p_agent, RID, p_map) { } COMMAND_2(agent_set_neighbor_dist, RID, p_agent, real_t, p_dist) { - RvoAgent *agent = agent_owner.getornull(p_agent); + RvoAgent *agent = agent_owner.get_or_null(p_agent); ERR_FAIL_COND(agent == nullptr); agent->get_agent()->neighborDist_ = p_dist; } COMMAND_2(agent_set_max_neighbors, RID, p_agent, int, p_count) { - RvoAgent *agent = agent_owner.getornull(p_agent); + RvoAgent *agent = agent_owner.get_or_null(p_agent); ERR_FAIL_COND(agent == nullptr); agent->get_agent()->maxNeighbors_ = p_count; } COMMAND_2(agent_set_time_horizon, RID, p_agent, real_t, p_time) { - RvoAgent *agent = agent_owner.getornull(p_agent); + RvoAgent *agent = agent_owner.get_or_null(p_agent); ERR_FAIL_COND(agent == nullptr); agent->get_agent()->timeHorizon_ = p_time; } COMMAND_2(agent_set_radius, RID, p_agent, real_t, p_radius) { - RvoAgent *agent = agent_owner.getornull(p_agent); + RvoAgent *agent = agent_owner.get_or_null(p_agent); ERR_FAIL_COND(agent == nullptr); agent->get_agent()->radius_ = p_radius; } COMMAND_2(agent_set_max_speed, RID, p_agent, real_t, p_max_speed) { - RvoAgent *agent = agent_owner.getornull(p_agent); + RvoAgent *agent = agent_owner.get_or_null(p_agent); ERR_FAIL_COND(agent == nullptr); agent->get_agent()->maxSpeed_ = p_max_speed; } COMMAND_2(agent_set_velocity, RID, p_agent, Vector3, p_velocity) { - RvoAgent *agent = agent_owner.getornull(p_agent); + RvoAgent *agent = agent_owner.get_or_null(p_agent); ERR_FAIL_COND(agent == nullptr); agent->get_agent()->velocity_ = RVO::Vector3(p_velocity.x, p_velocity.y, p_velocity.z); } COMMAND_2(agent_set_target_velocity, RID, p_agent, Vector3, p_velocity) { - RvoAgent *agent = agent_owner.getornull(p_agent); + RvoAgent *agent = agent_owner.get_or_null(p_agent); ERR_FAIL_COND(agent == nullptr); agent->get_agent()->prefVelocity_ = RVO::Vector3(p_velocity.x, p_velocity.y, p_velocity.z); } COMMAND_2(agent_set_position, RID, p_agent, Vector3, p_position) { - RvoAgent *agent = agent_owner.getornull(p_agent); + RvoAgent *agent = agent_owner.get_or_null(p_agent); ERR_FAIL_COND(agent == nullptr); agent->get_agent()->position_ = RVO::Vector3(p_position.x, p_position.y, p_position.z); } COMMAND_2(agent_set_ignore_y, RID, p_agent, bool, p_ignore) { - RvoAgent *agent = agent_owner.getornull(p_agent); + RvoAgent *agent = agent_owner.get_or_null(p_agent); ERR_FAIL_COND(agent == nullptr); agent->get_agent()->ignore_y_ = p_ignore; } bool GodotNavigationServer::agent_is_map_changed(RID p_agent) const { - RvoAgent *agent = agent_owner.getornull(p_agent); + RvoAgent *agent = agent_owner.get_or_null(p_agent); ERR_FAIL_COND_V(agent == nullptr, false); return agent->is_map_changed(); } COMMAND_4(agent_set_callback, RID, p_agent, Object *, p_receiver, StringName, p_method, Variant, p_udata) { - RvoAgent *agent = agent_owner.getornull(p_agent); + RvoAgent *agent = agent_owner.get_or_null(p_agent); ERR_FAIL_COND(agent == nullptr); agent->set_callback(p_receiver == nullptr ? ObjectID() : p_receiver->get_instance_id(), p_method, p_udata); @@ -452,7 +452,7 @@ COMMAND_4(agent_set_callback, RID, p_agent, Object *, p_receiver, StringName, p_ COMMAND_1(free, RID, p_object) { if (map_owner.owns(p_object)) { - NavMap *map = map_owner.getornull(p_object); + NavMap *map = map_owner.get_or_null(p_object); // Removes any assigned region std::vector<NavRegion *> regions = map->get_regions(); @@ -474,7 +474,7 @@ COMMAND_1(free, RID, p_object) { map_owner.free(p_object); } else if (region_owner.owns(p_object)) { - NavRegion *region = region_owner.getornull(p_object); + NavRegion *region = region_owner.get_or_null(p_object); // Removes this region from the map if assigned if (region->get_map() != nullptr) { @@ -485,7 +485,7 @@ COMMAND_1(free, RID, p_object) { region_owner.free(p_object); } else if (agent_owner.owns(p_object)) { - RvoAgent *agent = agent_owner.getornull(p_object); + RvoAgent *agent = agent_owner.get_or_null(p_object); // Removes this agent from the map if assigned if (agent->get_map() != nullptr) { diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp index 3150ca0bc8..962bf79150 100644 --- a/modules/navigation/nav_map.cpp +++ b/modules/navigation/nav_map.cpp @@ -664,7 +664,7 @@ void NavMap::sync() { } else { other1 = other_edge_p1.lerp(other_edge_p2, (1.0 - projected_p1_ratio) / (projected_p2_ratio - projected_p1_ratio)); } - if ((self1 - other1).length() > edge_connection_margin) { + if (other1.distance_to(self1) > edge_connection_margin) { continue; } @@ -675,7 +675,7 @@ void NavMap::sync() { } else { other2 = other_edge_p1.lerp(other_edge_p2, (0.0 - projected_p1_ratio) / (projected_p2_ratio - projected_p1_ratio)); } - if ((self2 - other2).length() > edge_connection_margin) { + if (other2.distance_to(self2) > edge_connection_margin) { continue; } diff --git a/modules/raycast/SCsub b/modules/raycast/SCsub index 2efd75b625..ef4c598194 100644 --- a/modules/raycast/SCsub +++ b/modules/raycast/SCsub @@ -79,6 +79,7 @@ if env["builtin_embree"]: env.Append(LIBS=["psapi"]) env_thirdparty = env_raycast.Clone() + env_thirdparty.force_optimization_on_debug() env_thirdparty.disable_warnings() env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources) diff --git a/modules/raycast/lightmap_raycaster.cpp b/modules/raycast/lightmap_raycaster.cpp index 0583acc119..fdcf509da8 100644 --- a/modules/raycast/lightmap_raycaster.cpp +++ b/modules/raycast/lightmap_raycaster.cpp @@ -168,7 +168,7 @@ void LightmapRaycasterEmbree::clear_mesh_filter() { filter_meshes.clear(); } -void embree_error_handler(void *p_user_data, RTCError p_code, const char *p_str) { +void embree_lm_error_handler(void *p_user_data, RTCError p_code, const char *p_str) { print_error("Embree error: " + String(p_str)); } @@ -179,16 +179,11 @@ LightmapRaycasterEmbree::LightmapRaycasterEmbree() { #endif embree_device = rtcNewDevice(nullptr); - rtcSetDeviceErrorFunction(embree_device, &embree_error_handler, nullptr); + rtcSetDeviceErrorFunction(embree_device, &embree_lm_error_handler, nullptr); embree_scene = rtcNewScene(embree_device); } LightmapRaycasterEmbree::~LightmapRaycasterEmbree() { -#ifdef __SSE2__ - _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_OFF); - _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_OFF); -#endif - if (embree_scene != nullptr) { rtcReleaseScene(embree_scene); } diff --git a/modules/raycast/lightmap_raycaster.h b/modules/raycast/lightmap_raycaster.h index 4c3de27837..290b0a1cf3 100644 --- a/modules/raycast/lightmap_raycaster.h +++ b/modules/raycast/lightmap_raycaster.h @@ -30,9 +30,9 @@ #ifdef TOOLS_ENABLED +#include "core/io/image.h" #include "core/object/object.h" #include "scene/3d/lightmapper.h" -#include "scene/resources/mesh.h" #include <embree3/rtcore.h> diff --git a/modules/raycast/raycast_occlusion_cull.cpp b/modules/raycast/raycast_occlusion_cull.cpp index 7de3318fa9..75491c98e5 100644 --- a/modules/raycast/raycast_occlusion_cull.cpp +++ b/modules/raycast/raycast_occlusion_cull.cpp @@ -217,7 +217,7 @@ void RaycastOcclusionCull::occluder_initialize(RID p_occluder) { } void RaycastOcclusionCull::occluder_set_mesh(RID p_occluder, const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices) { - Occluder *occluder = occluder_owner.getornull(p_occluder); + Occluder *occluder = occluder_owner.get_or_null(p_occluder); ERR_FAIL_COND(!occluder); occluder->vertices = p_vertices; @@ -238,7 +238,7 @@ void RaycastOcclusionCull::occluder_set_mesh(RID p_occluder, const PackedVector3 } void RaycastOcclusionCull::free_occluder(RID p_occluder) { - Occluder *occluder = occluder_owner.getornull(p_occluder); + Occluder *occluder = occluder_owner.get_or_null(p_occluder); ERR_FAIL_COND(!occluder); memdelete(occluder); occluder_owner.free(p_occluder); @@ -278,7 +278,7 @@ void RaycastOcclusionCull::scenario_set_instance(RID p_scenario, RID p_instance, bool changed = false; if (instance.occluder != p_occluder) { - Occluder *old_occluder = occluder_owner.getornull(instance.occluder); + Occluder *old_occluder = occluder_owner.get_or_null(instance.occluder); if (old_occluder) { old_occluder->users.erase(InstanceID(p_scenario, p_instance)); } @@ -286,7 +286,7 @@ void RaycastOcclusionCull::scenario_set_instance(RID p_scenario, RID p_instance, instance.occluder = p_occluder; if (p_occluder.is_valid()) { - Occluder *occluder = occluder_owner.getornull(p_occluder); + Occluder *occluder = occluder_owner.get_or_null(p_occluder); ERR_FAIL_COND(!occluder); occluder->users.insert(InstanceID(p_scenario, p_instance)); } @@ -318,7 +318,7 @@ void RaycastOcclusionCull::scenario_remove_instance(RID p_scenario, RID p_instan OccluderInstance &instance = scenario.instances[p_instance]; if (!instance.removed) { - Occluder *occluder = occluder_owner.getornull(instance.occluder); + Occluder *occluder = occluder_owner.get_or_null(instance.occluder); if (occluder) { occluder->users.erase(InstanceID(p_scenario, p_instance)); } @@ -340,7 +340,7 @@ void RaycastOcclusionCull::Scenario::_update_dirty_instance(int p_idx, RID *p_in return; } - Occluder *occ = raycast_singleton->occluder_owner.getornull(occ_inst->occluder); + Occluder *occ = raycast_singleton->occluder_owner.get_or_null(occ_inst->occluder); if (!occ) { return; @@ -456,7 +456,7 @@ bool RaycastOcclusionCull::Scenario::update(ThreadWorkPool &p_thread_pool) { const RID *inst_rid = nullptr; while ((inst_rid = instances.next(inst_rid))) { OccluderInstance *occ_inst = instances.getptr(*inst_rid); - Occluder *occ = raycast_singleton->occluder_owner.getornull(occ_inst->occluder); + Occluder *occ = raycast_singleton->occluder_owner.get_or_null(occ_inst->occluder); if (!occ || !occ_inst->enabled) { continue; diff --git a/modules/raycast/register_types.cpp b/modules/raycast/register_types.cpp index 78ca91309f..ed99e635e1 100644 --- a/modules/raycast/register_types.cpp +++ b/modules/raycast/register_types.cpp @@ -32,12 +32,14 @@ #include "lightmap_raycaster.h" #include "raycast_occlusion_cull.h" +#include "static_raycaster.h" RaycastOcclusionCull *raycast_occlusion_cull = nullptr; void register_raycast_types() { #ifdef TOOLS_ENABLED LightmapRaycasterEmbree::make_default_raycaster(); + StaticRaycasterEmbree::make_default_raycaster(); #endif raycast_occlusion_cull = memnew(RaycastOcclusionCull); } @@ -46,4 +48,7 @@ void unregister_raycast_types() { if (raycast_occlusion_cull) { memdelete(raycast_occlusion_cull); } +#ifdef TOOLS_ENABLED + StaticRaycasterEmbree::free(); +#endif } diff --git a/modules/raycast/static_raycaster.cpp b/modules/raycast/static_raycaster.cpp new file mode 100644 index 0000000000..2ba65eebf8 --- /dev/null +++ b/modules/raycast/static_raycaster.cpp @@ -0,0 +1,137 @@ +/*************************************************************************/ +/* static_raycaster.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifdef TOOLS_ENABLED + +#include "static_raycaster.h" + +#ifdef __SSE2__ +#include <pmmintrin.h> +#endif + +RTCDevice StaticRaycasterEmbree::embree_device; + +StaticRaycaster *StaticRaycasterEmbree::create_embree_raycaster() { + return memnew(StaticRaycasterEmbree); +} + +void StaticRaycasterEmbree::make_default_raycaster() { + create_function = create_embree_raycaster; +} + +void StaticRaycasterEmbree::free() { + if (embree_device) { + rtcReleaseDevice(embree_device); + } +} + +bool StaticRaycasterEmbree::intersect(Ray &r_ray) { + RTCIntersectContext context; + rtcInitIntersectContext(&context); + rtcIntersect1(embree_scene, &context, (RTCRayHit *)&r_ray); + return r_ray.geomID != RTC_INVALID_GEOMETRY_ID; +} + +void StaticRaycasterEmbree::intersect(Vector<Ray> &r_rays) { + Ray *rays = r_rays.ptrw(); + for (int i = 0; i < r_rays.size(); ++i) { + intersect(rays[i]); + } +} + +void StaticRaycasterEmbree::add_mesh(const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices, unsigned int p_id) { + RTCGeometry embree_mesh = rtcNewGeometry(embree_device, RTC_GEOMETRY_TYPE_TRIANGLE); + + int vertex_count = p_vertices.size(); + + Vector3 *embree_vertices = (Vector3 *)rtcSetNewGeometryBuffer(embree_mesh, RTC_BUFFER_TYPE_VERTEX, 0, RTC_FORMAT_FLOAT3, sizeof(Vector3), vertex_count); + memcpy(embree_vertices, p_vertices.ptr(), sizeof(Vector3) * vertex_count); + + if (p_indices.is_empty()) { + ERR_FAIL_COND(vertex_count % 3 != 0); + uint32_t *embree_triangles = (uint32_t *)rtcSetNewGeometryBuffer(embree_mesh, RTC_BUFFER_TYPE_INDEX, 0, RTC_FORMAT_UINT3, sizeof(uint32_t) * 3, vertex_count / 3); + for (int i = 0; i < vertex_count; i++) { + embree_triangles[i] = i; + } + } else { + uint32_t *embree_triangles = (uint32_t *)rtcSetNewGeometryBuffer(embree_mesh, RTC_BUFFER_TYPE_INDEX, 0, RTC_FORMAT_UINT3, sizeof(uint32_t) * 3, p_indices.size() / 3); + memcpy(embree_triangles, p_indices.ptr(), sizeof(uint32_t) * p_indices.size()); + } + + rtcCommitGeometry(embree_mesh); + rtcAttachGeometryByID(embree_scene, embree_mesh, p_id); + rtcReleaseGeometry(embree_mesh); +} + +void StaticRaycasterEmbree::commit() { + rtcCommitScene(embree_scene); +} + +void StaticRaycasterEmbree::set_mesh_filter(const Set<int> &p_mesh_ids) { + for (Set<int>::Element *E = p_mesh_ids.front(); E; E = E->next()) { + rtcDisableGeometry(rtcGetGeometry(embree_scene, E->get())); + } + rtcCommitScene(embree_scene); + filter_meshes = p_mesh_ids; +} + +void StaticRaycasterEmbree::clear_mesh_filter() { + for (Set<int>::Element *E = filter_meshes.front(); E; E = E->next()) { + rtcEnableGeometry(rtcGetGeometry(embree_scene, E->get())); + } + rtcCommitScene(embree_scene); + filter_meshes.clear(); +} + +void embree_error_handler(void *p_user_data, RTCError p_code, const char *p_str) { + print_error("Embree error: " + String(p_str)); +} + +StaticRaycasterEmbree::StaticRaycasterEmbree() { +#ifdef __SSE2__ + _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); + _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); +#endif + + if (!embree_device) { + embree_device = rtcNewDevice(nullptr); + rtcSetDeviceErrorFunction(embree_device, &embree_error_handler, nullptr); + } + + embree_scene = rtcNewScene(embree_device); +} + +StaticRaycasterEmbree::~StaticRaycasterEmbree() { + if (embree_scene != nullptr) { + rtcReleaseScene(embree_scene); + } +} + +#endif diff --git a/modules/gdnative/net/register_types.cpp b/modules/raycast/static_raycaster.h index 46c383e5ae..6b13ecf690 100644 --- a/modules/gdnative/net/register_types.cpp +++ b/modules/raycast/static_raycaster.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* register_types.cpp */ +/* static_raycaster.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,16 +28,37 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "register_types.h" -#include "multiplayer_peer_gdnative.h" -#include "packet_peer_gdnative.h" -#include "stream_peer_gdnative.h" +#ifdef TOOLS_ENABLED -void register_net_types() { - GDREGISTER_CLASS(MultiplayerPeerGDNative); - GDREGISTER_CLASS(PacketPeerGDNative); - GDREGISTER_CLASS(StreamPeerGDNative); -} +#include "core/math/static_raycaster.h" -void unregister_net_types() { -} +#include <embree3/rtcore.h> + +class StaticRaycasterEmbree : public StaticRaycaster { + GDCLASS(StaticRaycasterEmbree, StaticRaycaster); + +private: + static RTCDevice embree_device; + RTCScene embree_scene; + + Set<int> filter_meshes; + +public: + virtual bool intersect(Ray &p_ray) override; + virtual void intersect(Vector<Ray> &r_rays) override; + + virtual void add_mesh(const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices, unsigned int p_id) override; + virtual void commit() override; + + virtual void set_mesh_filter(const Set<int> &p_mesh_ids) override; + virtual void clear_mesh_filter() override; + + static StaticRaycaster *create_embree_raycaster(); + static void make_default_raycaster(); + static void free(); + + StaticRaycasterEmbree(); + ~StaticRaycasterEmbree(); +}; + +#endif diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index 2336153c0d..acc447018d 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -131,20 +131,6 @@ hb_position_t TextServerAdvanced::hb_bmp_get_glyph_h_kerning(hb_font_t *p_font, return bm_font->face->kerning_map[Vector2i(p_left_glyph, p_right_glyph)].x * 64; } -hb_position_t TextServerAdvanced::hb_bmp_get_glyph_v_kerning(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_left_glyph, hb_codepoint_t p_right_glyph, void *p_user_data) { - const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(p_font_data); - - if (!bm_font->face) { - return 0; - } - - if (!bm_font->face->kerning_map.has(Vector2i(p_left_glyph, p_right_glyph))) { - return 0; - } - - return bm_font->face->kerning_map[Vector2i(p_left_glyph, p_right_glyph)].y * 64; -} - hb_bool_t TextServerAdvanced::hb_bmp_get_glyph_v_origin(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, hb_position_t *r_x, hb_position_t *r_y, void *p_user_data) { const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(p_font_data); @@ -205,7 +191,6 @@ void TextServerAdvanced::hb_bmp_create_font_funcs() { hb_font_funcs_set_glyph_v_advance_func(funcs, hb_bmp_get_glyph_v_advance, nullptr, nullptr); hb_font_funcs_set_glyph_v_origin_func(funcs, hb_bmp_get_glyph_v_origin, nullptr, nullptr); hb_font_funcs_set_glyph_h_kerning_func(funcs, hb_bmp_get_glyph_h_kerning, nullptr, nullptr); - hb_font_funcs_set_glyph_v_kerning_func(funcs, hb_bmp_get_glyph_v_kerning, nullptr, nullptr); hb_font_funcs_set_glyph_extents_func(funcs, hb_bmp_get_glyph_extents, nullptr, nullptr); hb_font_funcs_make_immutable(funcs); @@ -348,11 +333,11 @@ String TextServerAdvanced::get_name() const { void TextServerAdvanced::free(RID p_rid) { _THREAD_SAFE_METHOD_ if (font_owner.owns(p_rid)) { - FontDataAdvanced *fd = font_owner.getornull(p_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_rid); font_owner.free(p_rid); memdelete(fd); } else if (shaped_owner.owns(p_rid)) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_rid); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_rid); shaped_owner.free(p_rid); memdelete(sd); } @@ -1611,7 +1596,7 @@ _FORCE_INLINE_ void TextServerAdvanced::_font_clear_cache(FontDataAdvanced *p_fo } hb_font_t *TextServerAdvanced::_font_get_hb_handle(RID p_font_rid, int p_size) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, nullptr); MutexLock lock(fd->mutex); @@ -1629,7 +1614,7 @@ RID TextServerAdvanced::create_font() { } void TextServerAdvanced::font_set_data(RID p_font_rid, const PackedByteArray &p_data) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1640,7 +1625,7 @@ void TextServerAdvanced::font_set_data(RID p_font_rid, const PackedByteArray &p_ } void TextServerAdvanced::font_set_data_ptr(RID p_font_rid, const uint8_t *p_data_ptr, size_t p_data_size) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1651,7 +1636,7 @@ void TextServerAdvanced::font_set_data_ptr(RID p_font_rid, const uint8_t *p_data } void TextServerAdvanced::font_set_antialiased(RID p_font_rid, bool p_antialiased) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1662,7 +1647,7 @@ void TextServerAdvanced::font_set_antialiased(RID p_font_rid, bool p_antialiased } bool TextServerAdvanced::font_is_antialiased(RID p_font_rid) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -1670,7 +1655,7 @@ bool TextServerAdvanced::font_is_antialiased(RID p_font_rid) const { } void TextServerAdvanced::font_set_multichannel_signed_distance_field(RID p_font_rid, bool p_msdf) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1681,7 +1666,7 @@ void TextServerAdvanced::font_set_multichannel_signed_distance_field(RID p_font_ } bool TextServerAdvanced::font_is_multichannel_signed_distance_field(RID p_font_rid) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -1689,7 +1674,7 @@ bool TextServerAdvanced::font_is_multichannel_signed_distance_field(RID p_font_r } void TextServerAdvanced::font_set_msdf_pixel_range(RID p_font_rid, int p_msdf_pixel_range) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1700,7 +1685,7 @@ void TextServerAdvanced::font_set_msdf_pixel_range(RID p_font_rid, int p_msdf_pi } int TextServerAdvanced::font_get_msdf_pixel_range(RID p_font_rid) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -1708,7 +1693,7 @@ int TextServerAdvanced::font_get_msdf_pixel_range(RID p_font_rid) const { } void TextServerAdvanced::font_set_msdf_size(RID p_font_rid, int p_msdf_size) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1719,7 +1704,7 @@ void TextServerAdvanced::font_set_msdf_size(RID p_font_rid, int p_msdf_size) { } int TextServerAdvanced::font_get_msdf_size(RID p_font_rid) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -1727,7 +1712,7 @@ int TextServerAdvanced::font_get_msdf_size(RID p_font_rid) const { } void TextServerAdvanced::font_set_fixed_size(RID p_font_rid, int p_fixed_size) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1737,7 +1722,7 @@ void TextServerAdvanced::font_set_fixed_size(RID p_font_rid, int p_fixed_size) { } int TextServerAdvanced::font_get_fixed_size(RID p_font_rid) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -1745,7 +1730,7 @@ int TextServerAdvanced::font_get_fixed_size(RID p_font_rid) const { } void TextServerAdvanced::font_set_force_autohinter(RID p_font_rid, bool p_force_autohinter) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1756,7 +1741,7 @@ void TextServerAdvanced::font_set_force_autohinter(RID p_font_rid, bool p_force_ } bool TextServerAdvanced::font_is_force_autohinter(RID p_font_rid) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -1764,7 +1749,7 @@ bool TextServerAdvanced::font_is_force_autohinter(RID p_font_rid) const { } void TextServerAdvanced::font_set_hinting(RID p_font_rid, TextServer::Hinting p_hinting) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1775,7 +1760,7 @@ void TextServerAdvanced::font_set_hinting(RID p_font_rid, TextServer::Hinting p_ } TextServer::Hinting TextServerAdvanced::font_get_hinting(RID p_font_rid) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, HINTING_NONE); MutexLock lock(fd->mutex); @@ -1783,7 +1768,7 @@ TextServer::Hinting TextServerAdvanced::font_get_hinting(RID p_font_rid) const { } void TextServerAdvanced::font_set_variation_coordinates(RID p_font_rid, const Dictionary &p_variation_coordinates) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1794,7 +1779,7 @@ void TextServerAdvanced::font_set_variation_coordinates(RID p_font_rid, const Di } Dictionary TextServerAdvanced::font_get_variation_coordinates(RID p_font_rid) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Dictionary()); MutexLock lock(fd->mutex); @@ -1802,7 +1787,7 @@ Dictionary TextServerAdvanced::font_get_variation_coordinates(RID p_font_rid) co } void TextServerAdvanced::font_set_oversampling(RID p_font_rid, real_t p_oversampling) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1813,7 +1798,7 @@ void TextServerAdvanced::font_set_oversampling(RID p_font_rid, real_t p_oversamp } real_t TextServerAdvanced::font_get_oversampling(RID p_font_rid) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); MutexLock lock(fd->mutex); @@ -1821,7 +1806,7 @@ real_t TextServerAdvanced::font_get_oversampling(RID p_font_rid) const { } Array TextServerAdvanced::font_get_size_cache_list(RID p_font_rid) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Array()); MutexLock lock(fd->mutex); @@ -1833,7 +1818,7 @@ Array TextServerAdvanced::font_get_size_cache_list(RID p_font_rid) const { } void TextServerAdvanced::font_clear_size_cache(RID p_font_rid) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1844,7 +1829,7 @@ void TextServerAdvanced::font_clear_size_cache(RID p_font_rid) { } void TextServerAdvanced::font_remove_size_cache(RID p_font_rid, const Vector2i &p_size) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1855,7 +1840,7 @@ void TextServerAdvanced::font_remove_size_cache(RID p_font_rid, const Vector2i & } void TextServerAdvanced::font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1866,7 +1851,7 @@ void TextServerAdvanced::font_set_ascent(RID p_font_rid, int p_size, real_t p_as } real_t TextServerAdvanced::font_get_ascent(RID p_font_rid, int p_size) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); MutexLock lock(fd->mutex); @@ -1882,7 +1867,7 @@ real_t TextServerAdvanced::font_get_ascent(RID p_font_rid, int p_size) const { } void TextServerAdvanced::font_set_descent(RID p_font_rid, int p_size, real_t p_descent) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); Vector2i size = _get_size(fd, p_size); @@ -1892,7 +1877,7 @@ void TextServerAdvanced::font_set_descent(RID p_font_rid, int p_size, real_t p_d } real_t TextServerAdvanced::font_get_descent(RID p_font_rid, int p_size) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); MutexLock lock(fd->mutex); @@ -1908,7 +1893,7 @@ real_t TextServerAdvanced::font_get_descent(RID p_font_rid, int p_size) const { } void TextServerAdvanced::font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1919,7 +1904,7 @@ void TextServerAdvanced::font_set_underline_position(RID p_font_rid, int p_size, } real_t TextServerAdvanced::font_get_underline_position(RID p_font_rid, int p_size) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); MutexLock lock(fd->mutex); @@ -1935,7 +1920,7 @@ real_t TextServerAdvanced::font_get_underline_position(RID p_font_rid, int p_siz } void TextServerAdvanced::font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1946,7 +1931,7 @@ void TextServerAdvanced::font_set_underline_thickness(RID p_font_rid, int p_size } real_t TextServerAdvanced::font_get_underline_thickness(RID p_font_rid, int p_size) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); MutexLock lock(fd->mutex); @@ -1962,7 +1947,7 @@ real_t TextServerAdvanced::font_get_underline_thickness(RID p_font_rid, int p_si } void TextServerAdvanced::font_set_scale(RID p_font_rid, int p_size, real_t p_scale) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1973,7 +1958,7 @@ void TextServerAdvanced::font_set_scale(RID p_font_rid, int p_size, real_t p_sca } real_t TextServerAdvanced::font_get_scale(RID p_font_rid, int p_size) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); MutexLock lock(fd->mutex); @@ -1989,7 +1974,7 @@ real_t TextServerAdvanced::font_get_scale(RID p_font_rid, int p_size) const { } void TextServerAdvanced::font_set_spacing(RID p_font_rid, int p_size, TextServer::SpacingType p_spacing, int p_value) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2010,7 +1995,7 @@ void TextServerAdvanced::font_set_spacing(RID p_font_rid, int p_size, TextServer } int TextServerAdvanced::font_get_spacing(RID p_font_rid, int p_size, TextServer::SpacingType p_spacing) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0); MutexLock lock(fd->mutex); @@ -2041,7 +2026,7 @@ int TextServerAdvanced::font_get_spacing(RID p_font_rid, int p_size, TextServer: } int TextServerAdvanced::font_get_texture_count(RID p_font_rid, const Vector2i &p_size) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0); MutexLock lock(fd->mutex); @@ -2053,7 +2038,7 @@ int TextServerAdvanced::font_get_texture_count(RID p_font_rid, const Vector2i &p } void TextServerAdvanced::font_clear_textures(RID p_font_rid, const Vector2i &p_size) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -2063,7 +2048,7 @@ void TextServerAdvanced::font_clear_textures(RID p_font_rid, const Vector2i &p_s } void TextServerAdvanced::font_remove_texture(RID p_font_rid, const Vector2i &p_size, int p_texture_index) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2075,7 +2060,7 @@ void TextServerAdvanced::font_remove_texture(RID p_font_rid, const Vector2i &p_s } void TextServerAdvanced::font_set_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const Ref<Image> &p_image) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); ERR_FAIL_COND(p_image.is_null()); @@ -2101,7 +2086,7 @@ void TextServerAdvanced::font_set_texture_image(RID p_font_rid, const Vector2i & } Ref<Image> TextServerAdvanced::font_get_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Ref<Image>()); MutexLock lock(fd->mutex); @@ -2116,7 +2101,7 @@ Ref<Image> TextServerAdvanced::font_get_texture_image(RID p_font_rid, const Vect } void TextServerAdvanced::font_set_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const PackedInt32Array &p_offset) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2131,7 +2116,7 @@ void TextServerAdvanced::font_set_texture_offsets(RID p_font_rid, const Vector2i } PackedInt32Array TextServerAdvanced::font_get_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, PackedInt32Array()); MutexLock lock(fd->mutex); @@ -2144,7 +2129,7 @@ PackedInt32Array TextServerAdvanced::font_get_texture_offsets(RID p_font_rid, co } Array TextServerAdvanced::font_get_glyph_list(RID p_font_rid, const Vector2i &p_size) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Array()); MutexLock lock(fd->mutex); @@ -2161,7 +2146,7 @@ Array TextServerAdvanced::font_get_glyph_list(RID p_font_rid, const Vector2i &p_ } void TextServerAdvanced::font_clear_glyphs(RID p_font_rid, const Vector2i &p_size) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2172,7 +2157,7 @@ void TextServerAdvanced::font_clear_glyphs(RID p_font_rid, const Vector2i &p_siz } void TextServerAdvanced::font_remove_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2183,7 +2168,7 @@ void TextServerAdvanced::font_remove_glyph(RID p_font_rid, const Vector2i &p_siz } Vector2 TextServerAdvanced::font_get_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Vector2()); MutexLock lock(fd->mutex); @@ -2204,7 +2189,7 @@ Vector2 TextServerAdvanced::font_get_glyph_advance(RID p_font_rid, int p_size, i } void TextServerAdvanced::font_set_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph, const Vector2 &p_advance) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2219,7 +2204,7 @@ void TextServerAdvanced::font_set_glyph_advance(RID p_font_rid, int p_size, int3 } Vector2 TextServerAdvanced::font_get_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Vector2()); MutexLock lock(fd->mutex); @@ -2240,7 +2225,7 @@ Vector2 TextServerAdvanced::font_get_glyph_offset(RID p_font_rid, const Vector2i } void TextServerAdvanced::font_set_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_offset) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2255,7 +2240,7 @@ void TextServerAdvanced::font_set_glyph_offset(RID p_font_rid, const Vector2i &p } Vector2 TextServerAdvanced::font_get_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Vector2()); MutexLock lock(fd->mutex); @@ -2276,7 +2261,7 @@ Vector2 TextServerAdvanced::font_get_glyph_size(RID p_font_rid, const Vector2i & } void TextServerAdvanced::font_set_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_gl_size) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2291,7 +2276,7 @@ void TextServerAdvanced::font_set_glyph_size(RID p_font_rid, const Vector2i &p_s } Rect2 TextServerAdvanced::font_get_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Rect2()); MutexLock lock(fd->mutex); @@ -2307,7 +2292,7 @@ Rect2 TextServerAdvanced::font_get_glyph_uv_rect(RID p_font_rid, const Vector2i } void TextServerAdvanced::font_set_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Rect2 &p_uv_rect) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2322,7 +2307,7 @@ void TextServerAdvanced::font_set_glyph_uv_rect(RID p_font_rid, const Vector2i & } int TextServerAdvanced::font_get_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, -1); MutexLock lock(fd->mutex); @@ -2338,7 +2323,7 @@ int TextServerAdvanced::font_get_glyph_texture_idx(RID p_font_rid, const Vector2 } void TextServerAdvanced::font_set_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2353,7 +2338,7 @@ void TextServerAdvanced::font_set_glyph_texture_idx(RID p_font_rid, const Vector } bool TextServerAdvanced::font_get_glyph_contours(RID p_font_rid, int p_size, int32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -2387,7 +2372,7 @@ bool TextServerAdvanced::font_get_glyph_contours(RID p_font_rid, int p_size, int } Array TextServerAdvanced::font_get_kerning_list(RID p_font_rid, int p_size) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Array()); MutexLock lock(fd->mutex); @@ -2403,7 +2388,7 @@ Array TextServerAdvanced::font_get_kerning_list(RID p_font_rid, int p_size) cons } void TextServerAdvanced::font_clear_kerning_map(RID p_font_rid, int p_size) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2414,7 +2399,7 @@ void TextServerAdvanced::font_clear_kerning_map(RID p_font_rid, int p_size) { } void TextServerAdvanced::font_remove_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2425,7 +2410,7 @@ void TextServerAdvanced::font_remove_kerning(RID p_font_rid, int p_size, const V } void TextServerAdvanced::font_set_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2436,7 +2421,7 @@ void TextServerAdvanced::font_set_kerning(RID p_font_rid, int p_size, const Vect } Vector2 TextServerAdvanced::font_get_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Vector2()); MutexLock lock(fd->mutex); @@ -2469,7 +2454,7 @@ Vector2 TextServerAdvanced::font_get_kerning(RID p_font_rid, int p_size, const V } int32_t TextServerAdvanced::font_get_glyph_index(RID p_font_rid, int p_size, char32_t p_char, char32_t p_variation_selector) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0); MutexLock lock(fd->mutex); @@ -2492,7 +2477,7 @@ int32_t TextServerAdvanced::font_get_glyph_index(RID p_font_rid, int p_size, cha } bool TextServerAdvanced::font_has_char(RID p_font_rid, char32_t p_char) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -2510,7 +2495,7 @@ bool TextServerAdvanced::font_has_char(RID p_font_rid, char32_t p_char) const { } String TextServerAdvanced::font_get_supported_chars(RID p_font_rid) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, String()); MutexLock lock(fd->mutex); @@ -2544,7 +2529,7 @@ String TextServerAdvanced::font_get_supported_chars(RID p_font_rid) const { } void TextServerAdvanced::font_render_range(RID p_font_rid, const Vector2i &p_size, char32_t p_start, char32_t p_end) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2562,7 +2547,7 @@ void TextServerAdvanced::font_render_range(RID p_font_rid, const Vector2i &p_siz } void TextServerAdvanced::font_render_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_index) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2572,7 +2557,7 @@ void TextServerAdvanced::font_render_glyph(RID p_font_rid, const Vector2i &p_siz } void TextServerAdvanced::font_draw_glyph(RID p_font_rid, RID p_canvas, int p_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2612,7 +2597,7 @@ void TextServerAdvanced::font_draw_glyph(RID p_font_rid, RID p_canvas, int p_siz } void TextServerAdvanced::font_draw_glyph_outline(RID p_font_rid, RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2652,7 +2637,7 @@ void TextServerAdvanced::font_draw_glyph_outline(RID p_font_rid, RID p_canvas, i } bool TextServerAdvanced::font_is_language_supported(RID p_font_rid, const String &p_language) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -2664,7 +2649,7 @@ bool TextServerAdvanced::font_is_language_supported(RID p_font_rid, const String } void TextServerAdvanced::font_set_language_support_override(RID p_font_rid, const String &p_language, bool p_supported) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2672,7 +2657,7 @@ void TextServerAdvanced::font_set_language_support_override(RID p_font_rid, cons } bool TextServerAdvanced::font_get_language_support_override(RID p_font_rid, const String &p_language) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -2680,7 +2665,7 @@ bool TextServerAdvanced::font_get_language_support_override(RID p_font_rid, cons } void TextServerAdvanced::font_remove_language_support_override(RID p_font_rid, const String &p_language) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2688,7 +2673,7 @@ void TextServerAdvanced::font_remove_language_support_override(RID p_font_rid, c } Vector<String> TextServerAdvanced::font_get_language_support_overrides(RID p_font_rid) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Vector<String>()); MutexLock lock(fd->mutex); @@ -2700,7 +2685,7 @@ Vector<String> TextServerAdvanced::font_get_language_support_overrides(RID p_fon } bool TextServerAdvanced::font_is_script_supported(RID p_font_rid, const String &p_script) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -2714,7 +2699,7 @@ bool TextServerAdvanced::font_is_script_supported(RID p_font_rid, const String & } void TextServerAdvanced::font_set_script_support_override(RID p_font_rid, const String &p_script, bool p_supported) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2722,7 +2707,7 @@ void TextServerAdvanced::font_set_script_support_override(RID p_font_rid, const } bool TextServerAdvanced::font_get_script_support_override(RID p_font_rid, const String &p_script) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -2730,7 +2715,7 @@ bool TextServerAdvanced::font_get_script_support_override(RID p_font_rid, const } void TextServerAdvanced::font_remove_script_support_override(RID p_font_rid, const String &p_script) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -2738,7 +2723,7 @@ void TextServerAdvanced::font_remove_script_support_override(RID p_font_rid, con } Vector<String> TextServerAdvanced::font_get_script_support_overrides(RID p_font_rid) { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Vector<String>()); MutexLock lock(fd->mutex); @@ -2750,7 +2735,7 @@ Vector<String> TextServerAdvanced::font_get_script_support_overrides(RID p_font_ } Dictionary TextServerAdvanced::font_supported_feature_list(RID p_font_rid) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Dictionary()); MutexLock lock(fd->mutex); @@ -2760,7 +2745,7 @@ Dictionary TextServerAdvanced::font_supported_feature_list(RID p_font_rid) const } Dictionary TextServerAdvanced::font_supported_variation_list(RID p_font_rid) const { - FontDataAdvanced *fd = font_owner.getornull(p_font_rid); + FontDataAdvanced *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Dictionary()); MutexLock lock(fd->mutex); @@ -2791,7 +2776,7 @@ void TextServerAdvanced::font_set_global_oversampling(real_t p_oversampling) { List<RID> text_bufs; shaped_owner.get_owned_list(&text_bufs); for (const RID &E : text_bufs) { - invalidate(shaped_owner.getornull(E)); + invalidate(shaped_owner.get_or_null(E)); } } } @@ -2852,7 +2837,7 @@ void TextServerAdvanced::invalidate(TextServerAdvanced::ShapedTextDataAdvanced * } void TextServerAdvanced::full_copy(ShapedTextDataAdvanced *p_shaped) { - ShapedTextDataAdvanced *parent = shaped_owner.getornull(p_shaped->parent); + ShapedTextDataAdvanced *parent = shaped_owner.get_or_null(p_shaped->parent); for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = parent->objects.front(); E; E = E->next()) { if (E->get().pos >= p_shaped->start && E->get().pos < p_shaped->end) { @@ -2883,7 +2868,7 @@ RID TextServerAdvanced::create_shaped_text(TextServer::Direction p_direction, Te } void TextServerAdvanced::shaped_text_clear(RID p_shaped) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND(!sd); MutexLock lock(sd->mutex); @@ -2898,7 +2883,7 @@ void TextServerAdvanced::shaped_text_clear(RID p_shaped) { } void TextServerAdvanced::shaped_text_set_direction(RID p_shaped, TextServer::Direction p_direction) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND(!sd); MutexLock lock(sd->mutex); @@ -2912,7 +2897,7 @@ void TextServerAdvanced::shaped_text_set_direction(RID p_shaped, TextServer::Dir } TextServer::Direction TextServerAdvanced::shaped_text_get_direction(RID p_shaped) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, TextServer::DIRECTION_LTR); MutexLock lock(sd->mutex); @@ -2920,7 +2905,7 @@ TextServer::Direction TextServerAdvanced::shaped_text_get_direction(RID p_shaped } void TextServerAdvanced::shaped_text_set_bidi_override(RID p_shaped, const Vector<Vector2i> &p_override) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND(!sd); MutexLock lock(sd->mutex); @@ -2932,7 +2917,7 @@ void TextServerAdvanced::shaped_text_set_bidi_override(RID p_shaped, const Vecto } void TextServerAdvanced::shaped_text_set_orientation(RID p_shaped, TextServer::Orientation p_orientation) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND(!sd); MutexLock lock(sd->mutex); @@ -2946,7 +2931,7 @@ void TextServerAdvanced::shaped_text_set_orientation(RID p_shaped, TextServer::O } void TextServerAdvanced::shaped_text_set_preserve_invalid(RID p_shaped, bool p_enabled) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND(!sd); MutexLock lock(sd->mutex); @@ -2958,7 +2943,7 @@ void TextServerAdvanced::shaped_text_set_preserve_invalid(RID p_shaped, bool p_e } bool TextServerAdvanced::shaped_text_get_preserve_invalid(RID p_shaped) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -2966,7 +2951,7 @@ bool TextServerAdvanced::shaped_text_get_preserve_invalid(RID p_shaped) const { } void TextServerAdvanced::shaped_text_set_preserve_control(RID p_shaped, bool p_enabled) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND(!sd); MutexLock lock(sd->mutex); @@ -2980,7 +2965,7 @@ void TextServerAdvanced::shaped_text_set_preserve_control(RID p_shaped, bool p_e } bool TextServerAdvanced::shaped_text_get_preserve_control(RID p_shaped) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -2988,7 +2973,7 @@ bool TextServerAdvanced::shaped_text_get_preserve_control(RID p_shaped) const { } TextServer::Orientation TextServerAdvanced::shaped_text_get_orientation(RID p_shaped) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, TextServer::ORIENTATION_HORIZONTAL); MutexLock lock(sd->mutex); @@ -2996,13 +2981,13 @@ TextServer::Orientation TextServerAdvanced::shaped_text_get_orientation(RID p_sh } bool TextServerAdvanced::shaped_text_add_string(RID p_shaped, const String &p_text, const Vector<RID> &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); ERR_FAIL_COND_V(p_size <= 0, false); MutexLock lock(sd->mutex); for (int i = 0; i < p_fonts.size(); i++) { - ERR_FAIL_COND_V(!font_owner.getornull(p_fonts[i]), false); + ERR_FAIL_COND_V(!font_owner.get_or_null(p_fonts[i]), false); } if (p_text.is_empty()) { @@ -3031,7 +3016,7 @@ bool TextServerAdvanced::shaped_text_add_string(RID p_shaped, const String &p_te bool TextServerAdvanced::shaped_text_add_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlign p_inline_align, int p_length) { _THREAD_SAFE_METHOD_ - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); ERR_FAIL_COND_V(p_key == Variant(), false); ERR_FAIL_COND_V(sd->objects.has(p_key), false); @@ -3060,7 +3045,7 @@ bool TextServerAdvanced::shaped_text_add_object(RID p_shaped, Variant p_key, con } bool TextServerAdvanced::shaped_text_resize_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlign p_inline_align) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -3193,7 +3178,7 @@ bool TextServerAdvanced::shaped_text_resize_object(RID p_shaped, Variant p_key, } RID TextServerAdvanced::shaped_text_substr(RID p_shaped, int p_start, int p_length) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, RID()); MutexLock lock(sd->mutex); @@ -3386,7 +3371,7 @@ RID TextServerAdvanced::shaped_text_substr(RID p_shaped, int p_start, int p_leng } RID TextServerAdvanced::shaped_text_get_parent(RID p_shaped) const { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, RID()); MutexLock lock(sd->mutex); @@ -3394,7 +3379,7 @@ RID TextServerAdvanced::shaped_text_get_parent(RID p_shaped) const { } real_t TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, real_t p_width, uint8_t /*JustificationFlag*/ p_jst_flags) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); @@ -3530,7 +3515,7 @@ real_t TextServerAdvanced::shaped_text_fit_to_width(RID p_shaped, real_t p_width } real_t TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); @@ -3580,7 +3565,7 @@ real_t TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const Vector<real } void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, real_t p_width, uint8_t p_trim_flags) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped_line); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped_line); ERR_FAIL_COND_MSG(!sd, "ShapedTextDataAdvanced invalid."); MutexLock lock(sd->mutex); @@ -3588,6 +3573,7 @@ void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, re shaped_text_shape(p_shaped_line); } + sd->text_trimmed = false; sd->overrun_trim_data.ellipsis_glyph_buf.clear(); bool add_ellipsis = (p_trim_flags & OVERRUN_ADD_ELLIPSIS) == OVERRUN_ADD_ELLIPSIS; @@ -3706,7 +3692,7 @@ void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, re } TextServer::TrimData TextServerAdvanced::shaped_text_get_trim_data(RID p_shaped) const { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V_MSG(!sd, TrimData(), "ShapedTextDataAdvanced invalid."); MutexLock lock(sd->mutex); @@ -3714,7 +3700,7 @@ TextServer::TrimData TextServerAdvanced::shaped_text_get_trim_data(RID p_shaped) } bool TextServerAdvanced::shaped_text_update_breaks(RID p_shaped) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -3906,7 +3892,7 @@ _FORCE_INLINE_ int _generate_kashida_justification_opportunies(const String &p_d } bool TextServerAdvanced::shaped_text_update_justification_ops(RID p_shaped) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -4263,7 +4249,7 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star } bool TextServerAdvanced::shaped_text_shape(RID p_shaped) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -4493,7 +4479,7 @@ bool TextServerAdvanced::shaped_text_shape(RID p_shaped) { } bool TextServerAdvanced::shaped_text_is_ready(RID p_shaped) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -4501,7 +4487,7 @@ bool TextServerAdvanced::shaped_text_is_ready(RID p_shaped) const { } Vector<TextServer::Glyph> TextServerAdvanced::shaped_text_get_glyphs(RID p_shaped) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, Vector<TextServer::Glyph>()); MutexLock lock(sd->mutex); @@ -4512,7 +4498,7 @@ Vector<TextServer::Glyph> TextServerAdvanced::shaped_text_get_glyphs(RID p_shape } Vector2i TextServerAdvanced::shaped_text_get_range(RID p_shaped) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, Vector2i()); MutexLock lock(sd->mutex); @@ -4520,7 +4506,7 @@ Vector2i TextServerAdvanced::shaped_text_get_range(RID p_shaped) const { } Vector<TextServer::Glyph> TextServerAdvanced::shaped_text_sort_logical(RID p_shaped) { - ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, Vector<TextServer::Glyph>()); MutexLock lock(sd->mutex); @@ -4539,7 +4525,7 @@ Vector<TextServer::Glyph> TextServerAdvanced::shaped_text_sort_logical(RID p_sha Array TextServerAdvanced::shaped_text_get_objects(RID p_shaped) const { Array ret; - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, ret); MutexLock lock(sd->mutex); @@ -4551,7 +4537,7 @@ Array TextServerAdvanced::shaped_text_get_objects(RID p_shaped) const { } Rect2 TextServerAdvanced::shaped_text_get_object_rect(RID p_shaped, Variant p_key) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, Rect2()); MutexLock lock(sd->mutex); @@ -4563,7 +4549,7 @@ Rect2 TextServerAdvanced::shaped_text_get_object_rect(RID p_shaped, Variant p_ke } Size2 TextServerAdvanced::shaped_text_get_size(RID p_shaped) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, Size2()); MutexLock lock(sd->mutex); @@ -4578,7 +4564,7 @@ Size2 TextServerAdvanced::shaped_text_get_size(RID p_shaped) const { } real_t TextServerAdvanced::shaped_text_get_ascent(RID p_shaped) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); @@ -4589,7 +4575,7 @@ real_t TextServerAdvanced::shaped_text_get_ascent(RID p_shaped) const { } real_t TextServerAdvanced::shaped_text_get_descent(RID p_shaped) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); @@ -4600,7 +4586,7 @@ real_t TextServerAdvanced::shaped_text_get_descent(RID p_shaped) const { } real_t TextServerAdvanced::shaped_text_get_width(RID p_shaped) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); @@ -4611,7 +4597,7 @@ real_t TextServerAdvanced::shaped_text_get_width(RID p_shaped) const { } real_t TextServerAdvanced::shaped_text_get_underline_position(RID p_shaped) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); @@ -4623,7 +4609,7 @@ real_t TextServerAdvanced::shaped_text_get_underline_position(RID p_shaped) cons } real_t TextServerAdvanced::shaped_text_get_underline_thickness(RID p_shaped) const { - const ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); + const ShapedTextDataAdvanced *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h index 5989035800..fc0e7a09a7 100644 --- a/modules/text_server_adv/text_server_adv.h +++ b/modules/text_server_adv/text_server_adv.h @@ -269,7 +269,6 @@ class TextServerAdvanced : public TextServer { static hb_position_t hb_bmp_get_glyph_h_advance(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, void *p_user_data); static hb_position_t hb_bmp_get_glyph_v_advance(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, void *p_user_data); static hb_position_t hb_bmp_get_glyph_h_kerning(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_left_glyph, hb_codepoint_t p_right_glyph, void *p_user_data); - static hb_position_t hb_bmp_get_glyph_v_kerning(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_left_glyph, hb_codepoint_t p_right_glyph, void *p_user_data); static hb_bool_t hb_bmp_get_glyph_v_origin(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, hb_position_t *r_x, hb_position_t *r_y, void *p_user_data); static hb_bool_t hb_bmp_get_glyph_extents(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, hb_glyph_extents_t *r_extents, void *p_user_data); static hb_bool_t hb_bmp_get_font_h_extents(hb_font_t *p_font, void *p_font_data, hb_font_extents_t *r_metrics, void *p_user_data); diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index 8a1bd93c65..b1ce85d505 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -80,11 +80,11 @@ String TextServerFallback::get_name() const { void TextServerFallback::free(RID p_rid) { _THREAD_SAFE_METHOD_ if (font_owner.owns(p_rid)) { - FontDataFallback *fd = font_owner.getornull(p_rid); + FontDataFallback *fd = font_owner.get_or_null(p_rid); font_owner.free(p_rid); memdelete(fd); } else if (shaped_owner.owns(p_rid)) { - ShapedTextData *sd = shaped_owner.getornull(p_rid); + ShapedTextData *sd = shaped_owner.get_or_null(p_rid); shaped_owner.free(p_rid); memdelete(sd); } @@ -611,11 +611,13 @@ _FORCE_INLINE_ bool TextServerFallback::_ensure_glyph(FontDataFallback *p_font_d flags |= FT_LOAD_COLOR; } + int32_t glyph_index = FT_Get_Char_Index(fd->face, p_glyph); + FT_Fixed v, h; - FT_Get_Advance(fd->face, p_glyph, flags, &h); - FT_Get_Advance(fd->face, p_glyph, flags | FT_LOAD_VERTICAL_LAYOUT, &v); + FT_Get_Advance(fd->face, glyph_index, flags, &h); + FT_Get_Advance(fd->face, glyph_index, flags | FT_LOAD_VERTICAL_LAYOUT, &v); - int error = FT_Load_Glyph(fd->face, p_glyph, flags); + int error = FT_Load_Glyph(fd->face, glyph_index, flags); if (error) { fd->glyph_map[p_glyph] = FontGlyph(); ERR_FAIL_V_MSG(false, "FreeType: Failed to load glyph."); @@ -809,7 +811,7 @@ RID TextServerFallback::create_font() { } void TextServerFallback::font_set_data(RID p_font_rid, const PackedByteArray &p_data) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -820,7 +822,7 @@ void TextServerFallback::font_set_data(RID p_font_rid, const PackedByteArray &p_ } void TextServerFallback::font_set_data_ptr(RID p_font_rid, const uint8_t *p_data_ptr, size_t p_data_size) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -831,7 +833,7 @@ void TextServerFallback::font_set_data_ptr(RID p_font_rid, const uint8_t *p_data } void TextServerFallback::font_set_antialiased(RID p_font_rid, bool p_antialiased) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -842,7 +844,7 @@ void TextServerFallback::font_set_antialiased(RID p_font_rid, bool p_antialiased } bool TextServerFallback::font_is_antialiased(RID p_font_rid) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -850,7 +852,7 @@ bool TextServerFallback::font_is_antialiased(RID p_font_rid) const { } void TextServerFallback::font_set_multichannel_signed_distance_field(RID p_font_rid, bool p_msdf) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -861,7 +863,7 @@ void TextServerFallback::font_set_multichannel_signed_distance_field(RID p_font_ } bool TextServerFallback::font_is_multichannel_signed_distance_field(RID p_font_rid) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -869,7 +871,7 @@ bool TextServerFallback::font_is_multichannel_signed_distance_field(RID p_font_r } void TextServerFallback::font_set_msdf_pixel_range(RID p_font_rid, int p_msdf_pixel_range) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -880,7 +882,7 @@ void TextServerFallback::font_set_msdf_pixel_range(RID p_font_rid, int p_msdf_pi } int TextServerFallback::font_get_msdf_pixel_range(RID p_font_rid) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -888,7 +890,7 @@ int TextServerFallback::font_get_msdf_pixel_range(RID p_font_rid) const { } void TextServerFallback::font_set_msdf_size(RID p_font_rid, int p_msdf_size) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -899,7 +901,7 @@ void TextServerFallback::font_set_msdf_size(RID p_font_rid, int p_msdf_size) { } int TextServerFallback::font_get_msdf_size(RID p_font_rid) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -907,7 +909,7 @@ int TextServerFallback::font_get_msdf_size(RID p_font_rid) const { } void TextServerFallback::font_set_fixed_size(RID p_font_rid, int p_fixed_size) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -917,7 +919,7 @@ void TextServerFallback::font_set_fixed_size(RID p_font_rid, int p_fixed_size) { } int TextServerFallback::font_get_fixed_size(RID p_font_rid) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -925,7 +927,7 @@ int TextServerFallback::font_get_fixed_size(RID p_font_rid) const { } void TextServerFallback::font_set_force_autohinter(RID p_font_rid, bool p_force_autohinter) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -936,7 +938,7 @@ void TextServerFallback::font_set_force_autohinter(RID p_font_rid, bool p_force_ } bool TextServerFallback::font_is_force_autohinter(RID p_font_rid) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -944,7 +946,7 @@ bool TextServerFallback::font_is_force_autohinter(RID p_font_rid) const { } void TextServerFallback::font_set_hinting(RID p_font_rid, TextServer::Hinting p_hinting) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -955,7 +957,7 @@ void TextServerFallback::font_set_hinting(RID p_font_rid, TextServer::Hinting p_ } TextServer::Hinting TextServerFallback::font_get_hinting(RID p_font_rid) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, HINTING_NONE); MutexLock lock(fd->mutex); @@ -963,7 +965,7 @@ TextServer::Hinting TextServerFallback::font_get_hinting(RID p_font_rid) const { } void TextServerFallback::font_set_variation_coordinates(RID p_font_rid, const Dictionary &p_variation_coordinates) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -974,7 +976,7 @@ void TextServerFallback::font_set_variation_coordinates(RID p_font_rid, const Di } Dictionary TextServerFallback::font_get_variation_coordinates(RID p_font_rid) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Dictionary()); MutexLock lock(fd->mutex); @@ -982,7 +984,7 @@ Dictionary TextServerFallback::font_get_variation_coordinates(RID p_font_rid) co } void TextServerFallback::font_set_oversampling(RID p_font_rid, real_t p_oversampling) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -993,7 +995,7 @@ void TextServerFallback::font_set_oversampling(RID p_font_rid, real_t p_oversamp } real_t TextServerFallback::font_get_oversampling(RID p_font_rid) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); MutexLock lock(fd->mutex); @@ -1001,7 +1003,7 @@ real_t TextServerFallback::font_get_oversampling(RID p_font_rid) const { } Array TextServerFallback::font_get_size_cache_list(RID p_font_rid) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Array()); MutexLock lock(fd->mutex); @@ -1013,7 +1015,7 @@ Array TextServerFallback::font_get_size_cache_list(RID p_font_rid) const { } void TextServerFallback::font_clear_size_cache(RID p_font_rid) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1024,7 +1026,7 @@ void TextServerFallback::font_clear_size_cache(RID p_font_rid) { } void TextServerFallback::font_remove_size_cache(RID p_font_rid, const Vector2i &p_size) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1035,7 +1037,7 @@ void TextServerFallback::font_remove_size_cache(RID p_font_rid, const Vector2i & } void TextServerFallback::font_set_ascent(RID p_font_rid, int p_size, real_t p_ascent) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1046,7 +1048,7 @@ void TextServerFallback::font_set_ascent(RID p_font_rid, int p_size, real_t p_as } real_t TextServerFallback::font_get_ascent(RID p_font_rid, int p_size) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); MutexLock lock(fd->mutex); @@ -1062,7 +1064,7 @@ real_t TextServerFallback::font_get_ascent(RID p_font_rid, int p_size) const { } void TextServerFallback::font_set_descent(RID p_font_rid, int p_size, real_t p_descent) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); Vector2i size = _get_size(fd, p_size); @@ -1072,7 +1074,7 @@ void TextServerFallback::font_set_descent(RID p_font_rid, int p_size, real_t p_d } real_t TextServerFallback::font_get_descent(RID p_font_rid, int p_size) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); MutexLock lock(fd->mutex); @@ -1088,7 +1090,7 @@ real_t TextServerFallback::font_get_descent(RID p_font_rid, int p_size) const { } void TextServerFallback::font_set_underline_position(RID p_font_rid, int p_size, real_t p_underline_position) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1099,7 +1101,7 @@ void TextServerFallback::font_set_underline_position(RID p_font_rid, int p_size, } real_t TextServerFallback::font_get_underline_position(RID p_font_rid, int p_size) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); MutexLock lock(fd->mutex); @@ -1115,7 +1117,7 @@ real_t TextServerFallback::font_get_underline_position(RID p_font_rid, int p_siz } void TextServerFallback::font_set_underline_thickness(RID p_font_rid, int p_size, real_t p_underline_thickness) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1126,7 +1128,7 @@ void TextServerFallback::font_set_underline_thickness(RID p_font_rid, int p_size } real_t TextServerFallback::font_get_underline_thickness(RID p_font_rid, int p_size) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); MutexLock lock(fd->mutex); @@ -1142,7 +1144,7 @@ real_t TextServerFallback::font_get_underline_thickness(RID p_font_rid, int p_si } void TextServerFallback::font_set_scale(RID p_font_rid, int p_size, real_t p_scale) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1153,7 +1155,7 @@ void TextServerFallback::font_set_scale(RID p_font_rid, int p_size, real_t p_sca } real_t TextServerFallback::font_get_scale(RID p_font_rid, int p_size) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0.f); MutexLock lock(fd->mutex); @@ -1169,7 +1171,7 @@ real_t TextServerFallback::font_get_scale(RID p_font_rid, int p_size) const { } void TextServerFallback::font_set_spacing(RID p_font_rid, int p_size, TextServer::SpacingType p_spacing, int p_value) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1190,7 +1192,7 @@ void TextServerFallback::font_set_spacing(RID p_font_rid, int p_size, TextServer } int TextServerFallback::font_get_spacing(RID p_font_rid, int p_size, TextServer::SpacingType p_spacing) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0); MutexLock lock(fd->mutex); @@ -1221,7 +1223,7 @@ int TextServerFallback::font_get_spacing(RID p_font_rid, int p_size, TextServer: } int TextServerFallback::font_get_texture_count(RID p_font_rid, const Vector2i &p_size) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, 0); MutexLock lock(fd->mutex); @@ -1233,7 +1235,7 @@ int TextServerFallback::font_get_texture_count(RID p_font_rid, const Vector2i &p } void TextServerFallback::font_clear_textures(RID p_font_rid, const Vector2i &p_size) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); @@ -1243,7 +1245,7 @@ void TextServerFallback::font_clear_textures(RID p_font_rid, const Vector2i &p_s } void TextServerFallback::font_remove_texture(RID p_font_rid, const Vector2i &p_size, int p_texture_index) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1255,7 +1257,7 @@ void TextServerFallback::font_remove_texture(RID p_font_rid, const Vector2i &p_s } void TextServerFallback::font_set_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const Ref<Image> &p_image) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); ERR_FAIL_COND(p_image.is_null()); @@ -1281,7 +1283,7 @@ void TextServerFallback::font_set_texture_image(RID p_font_rid, const Vector2i & } Ref<Image> TextServerFallback::font_get_texture_image(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Ref<Image>()); MutexLock lock(fd->mutex); @@ -1296,7 +1298,7 @@ Ref<Image> TextServerFallback::font_get_texture_image(RID p_font_rid, const Vect } void TextServerFallback::font_set_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index, const PackedInt32Array &p_offset) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1311,7 +1313,7 @@ void TextServerFallback::font_set_texture_offsets(RID p_font_rid, const Vector2i } PackedInt32Array TextServerFallback::font_get_texture_offsets(RID p_font_rid, const Vector2i &p_size, int p_texture_index) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, PackedInt32Array()); MutexLock lock(fd->mutex); @@ -1324,7 +1326,7 @@ PackedInt32Array TextServerFallback::font_get_texture_offsets(RID p_font_rid, co } Array TextServerFallback::font_get_glyph_list(RID p_font_rid, const Vector2i &p_size) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Array()); MutexLock lock(fd->mutex); @@ -1341,7 +1343,7 @@ Array TextServerFallback::font_get_glyph_list(RID p_font_rid, const Vector2i &p_ } void TextServerFallback::font_clear_glyphs(RID p_font_rid, const Vector2i &p_size) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1352,7 +1354,7 @@ void TextServerFallback::font_clear_glyphs(RID p_font_rid, const Vector2i &p_siz } void TextServerFallback::font_remove_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1363,7 +1365,7 @@ void TextServerFallback::font_remove_glyph(RID p_font_rid, const Vector2i &p_siz } Vector2 TextServerFallback::font_get_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Vector2()); MutexLock lock(fd->mutex); @@ -1384,7 +1386,7 @@ Vector2 TextServerFallback::font_get_glyph_advance(RID p_font_rid, int p_size, i } void TextServerFallback::font_set_glyph_advance(RID p_font_rid, int p_size, int32_t p_glyph, const Vector2 &p_advance) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1399,7 +1401,7 @@ void TextServerFallback::font_set_glyph_advance(RID p_font_rid, int p_size, int3 } Vector2 TextServerFallback::font_get_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Vector2()); MutexLock lock(fd->mutex); @@ -1420,7 +1422,7 @@ Vector2 TextServerFallback::font_get_glyph_offset(RID p_font_rid, const Vector2i } void TextServerFallback::font_set_glyph_offset(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_offset) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1435,7 +1437,7 @@ void TextServerFallback::font_set_glyph_offset(RID p_font_rid, const Vector2i &p } Vector2 TextServerFallback::font_get_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Vector2()); MutexLock lock(fd->mutex); @@ -1456,7 +1458,7 @@ Vector2 TextServerFallback::font_get_glyph_size(RID p_font_rid, const Vector2i & } void TextServerFallback::font_set_glyph_size(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Vector2 &p_gl_size) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1471,7 +1473,7 @@ void TextServerFallback::font_set_glyph_size(RID p_font_rid, const Vector2i &p_s } Rect2 TextServerFallback::font_get_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Rect2()); MutexLock lock(fd->mutex); @@ -1487,7 +1489,7 @@ Rect2 TextServerFallback::font_get_glyph_uv_rect(RID p_font_rid, const Vector2i } void TextServerFallback::font_set_glyph_uv_rect(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, const Rect2 &p_uv_rect) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1502,7 +1504,7 @@ void TextServerFallback::font_set_glyph_uv_rect(RID p_font_rid, const Vector2i & } int TextServerFallback::font_get_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, -1); MutexLock lock(fd->mutex); @@ -1518,7 +1520,7 @@ int TextServerFallback::font_get_glyph_texture_idx(RID p_font_rid, const Vector2 } void TextServerFallback::font_set_glyph_texture_idx(RID p_font_rid, const Vector2i &p_size, int32_t p_glyph, int p_texture_idx) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1533,7 +1535,7 @@ void TextServerFallback::font_set_glyph_texture_idx(RID p_font_rid, const Vector } bool TextServerFallback::font_get_glyph_contours(RID p_font_rid, int p_size, int32_t p_index, Vector<Vector3> &r_points, Vector<int32_t> &r_contours, bool &r_orientation) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -1542,7 +1544,7 @@ bool TextServerFallback::font_get_glyph_contours(RID p_font_rid, int p_size, int ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), false); #ifdef MODULE_FREETYPE_ENABLED - int error = FT_Load_Glyph(fd->cache[size]->face, p_index, FT_LOAD_NO_BITMAP | (fd->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)); + int error = FT_Load_Glyph(fd->cache[size]->face, FT_Get_Char_Index(fd->cache[size]->face, p_index), FT_LOAD_NO_BITMAP | (fd->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)); ERR_FAIL_COND_V(error, false); r_points.clear(); @@ -1567,7 +1569,7 @@ bool TextServerFallback::font_get_glyph_contours(RID p_font_rid, int p_size, int } Array TextServerFallback::font_get_kerning_list(RID p_font_rid, int p_size) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Array()); MutexLock lock(fd->mutex); @@ -1583,7 +1585,7 @@ Array TextServerFallback::font_get_kerning_list(RID p_font_rid, int p_size) cons } void TextServerFallback::font_clear_kerning_map(RID p_font_rid, int p_size) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1594,7 +1596,7 @@ void TextServerFallback::font_clear_kerning_map(RID p_font_rid, int p_size) { } void TextServerFallback::font_remove_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1605,7 +1607,7 @@ void TextServerFallback::font_remove_kerning(RID p_font_rid, int p_size, const V } void TextServerFallback::font_set_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair, const Vector2 &p_kerning) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1616,7 +1618,7 @@ void TextServerFallback::font_set_kerning(RID p_font_rid, int p_size, const Vect } Vector2 TextServerFallback::font_get_kerning(RID p_font_rid, int p_size, const Vector2i &p_glyph_pair) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Vector2()); MutexLock lock(fd->mutex); @@ -1636,7 +1638,9 @@ Vector2 TextServerFallback::font_get_kerning(RID p_font_rid, int p_size, const V #ifdef MODULE_FREETYPE_ENABLED if (fd->cache[size]->face) { FT_Vector delta; - FT_Get_Kerning(fd->cache[size]->face, p_glyph_pair.x, p_glyph_pair.y, FT_KERNING_DEFAULT, &delta); + int32_t glyph_a = FT_Get_Char_Index(fd->cache[size]->face, p_glyph_pair.x); + int32_t glyph_b = FT_Get_Char_Index(fd->cache[size]->face, p_glyph_pair.y); + FT_Get_Kerning(fd->cache[size]->face, glyph_a, glyph_b, FT_KERNING_DEFAULT, &delta); if (fd->msdf) { return Vector2(delta.x, delta.y) * (real_t)p_size / (real_t)fd->msdf_source_size; } else { @@ -1649,30 +1653,11 @@ Vector2 TextServerFallback::font_get_kerning(RID p_font_rid, int p_size, const V } int32_t TextServerFallback::font_get_glyph_index(RID p_font_rid, int p_size, char32_t p_char, char32_t p_variation_selector) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); - ERR_FAIL_COND_V(!fd, 0); - - MutexLock lock(fd->mutex); - Vector2i size = _get_size(fd, p_size); - ERR_FAIL_COND_V(!_ensure_cache_for_size(fd, size), 0); - -#ifdef MODULE_FREETYPE_ENABLED - if (fd->cache[size]->face) { - if (p_variation_selector) { - return FT_Face_GetCharVariantIndex(fd->cache[size]->face, p_char, p_variation_selector); - } else { - return FT_Get_Char_Index(fd->cache[size]->face, p_char); - } - } else { - return 0; - } -#else return (int32_t)p_char; -#endif } bool TextServerFallback::font_has_char(RID p_font_rid, char32_t p_char) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -1690,7 +1675,7 @@ bool TextServerFallback::font_has_char(RID p_font_rid, char32_t p_char) const { } String TextServerFallback::font_get_supported_chars(RID p_font_rid) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, String()); MutexLock lock(fd->mutex); @@ -1724,25 +1709,19 @@ String TextServerFallback::font_get_supported_chars(RID p_font_rid) const { } void TextServerFallback::font_render_range(RID p_font_rid, const Vector2i &p_size, char32_t p_start, char32_t p_end) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); Vector2i size = _get_size_outline(fd, p_size); ERR_FAIL_COND(!_ensure_cache_for_size(fd, size)); for (char32_t i = p_start; i <= p_end; i++) { -#ifdef MODULE_FREETYPE_ENABLED - if (fd->cache[size]->face) { - _ensure_glyph(fd, size, FT_Get_Char_Index(fd->cache[size]->face, i)); - continue; - } -#endif _ensure_glyph(fd, size, (int32_t)i); } } void TextServerFallback::font_render_glyph(RID p_font_rid, const Vector2i &p_size, int32_t p_index) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1752,7 +1731,7 @@ void TextServerFallback::font_render_glyph(RID p_font_rid, const Vector2i &p_siz } void TextServerFallback::font_draw_glyph(RID p_font_rid, RID p_canvas, int p_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1792,7 +1771,7 @@ void TextServerFallback::font_draw_glyph(RID p_font_rid, RID p_canvas, int p_siz } void TextServerFallback::font_draw_glyph_outline(RID p_font_rid, RID p_canvas, int p_size, int p_outline_size, const Vector2 &p_pos, int32_t p_index, const Color &p_color) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1832,7 +1811,7 @@ void TextServerFallback::font_draw_glyph_outline(RID p_font_rid, RID p_canvas, i } bool TextServerFallback::font_is_language_supported(RID p_font_rid, const String &p_language) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -1844,7 +1823,7 @@ bool TextServerFallback::font_is_language_supported(RID p_font_rid, const String } void TextServerFallback::font_set_language_support_override(RID p_font_rid, const String &p_language, bool p_supported) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1852,7 +1831,7 @@ void TextServerFallback::font_set_language_support_override(RID p_font_rid, cons } bool TextServerFallback::font_get_language_support_override(RID p_font_rid, const String &p_language) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -1860,7 +1839,7 @@ bool TextServerFallback::font_get_language_support_override(RID p_font_rid, cons } void TextServerFallback::font_remove_language_support_override(RID p_font_rid, const String &p_language) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1868,7 +1847,7 @@ void TextServerFallback::font_remove_language_support_override(RID p_font_rid, c } Vector<String> TextServerFallback::font_get_language_support_overrides(RID p_font_rid) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Vector<String>()); MutexLock lock(fd->mutex); @@ -1880,7 +1859,7 @@ Vector<String> TextServerFallback::font_get_language_support_overrides(RID p_fon } bool TextServerFallback::font_is_script_supported(RID p_font_rid, const String &p_script) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -1892,7 +1871,7 @@ bool TextServerFallback::font_is_script_supported(RID p_font_rid, const String & } void TextServerFallback::font_set_script_support_override(RID p_font_rid, const String &p_script, bool p_supported) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1900,7 +1879,7 @@ void TextServerFallback::font_set_script_support_override(RID p_font_rid, const } bool TextServerFallback::font_get_script_support_override(RID p_font_rid, const String &p_script) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, false); MutexLock lock(fd->mutex); @@ -1908,7 +1887,7 @@ bool TextServerFallback::font_get_script_support_override(RID p_font_rid, const } void TextServerFallback::font_remove_script_support_override(RID p_font_rid, const String &p_script) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); @@ -1918,7 +1897,7 @@ void TextServerFallback::font_remove_script_support_override(RID p_font_rid, con } Vector<String> TextServerFallback::font_get_script_support_overrides(RID p_font_rid) { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Vector<String>()); MutexLock lock(fd->mutex); @@ -1934,7 +1913,7 @@ Dictionary TextServerFallback::font_supported_feature_list(RID p_font_rid) const } Dictionary TextServerFallback::font_supported_variation_list(RID p_font_rid) const { - FontDataFallback *fd = font_owner.getornull(p_font_rid); + FontDataFallback *fd = font_owner.get_or_null(p_font_rid); ERR_FAIL_COND_V(!fd, Dictionary()); MutexLock lock(fd->mutex); @@ -1965,7 +1944,7 @@ void TextServerFallback::font_set_global_oversampling(real_t p_oversampling) { List<RID> text_bufs; shaped_owner.get_owned_list(&text_bufs); for (const RID &E : text_bufs) { - invalidate(shaped_owner.getornull(E)); + invalidate(shaped_owner.get_or_null(E)); } } } @@ -1990,7 +1969,7 @@ void TextServerFallback::invalidate(ShapedTextData *p_shaped) { } void TextServerFallback::full_copy(ShapedTextData *p_shaped) { - ShapedTextData *parent = shaped_owner.getornull(p_shaped->parent); + ShapedTextData *parent = shaped_owner.get_or_null(p_shaped->parent); for (Map<Variant, ShapedTextData::EmbeddedObject>::Element *E = parent->objects.front(); E; E = E->next()) { if (E->get().pos >= p_shaped->start && E->get().pos < p_shaped->end) { @@ -2021,7 +2000,7 @@ RID TextServerFallback::create_shaped_text(TextServer::Direction p_direction, Te } void TextServerFallback::shaped_text_clear(RID p_shaped) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND(!sd); MutexLock lock(sd->mutex); @@ -2045,7 +2024,7 @@ TextServer::Direction TextServerFallback::shaped_text_get_direction(RID p_shaped } void TextServerFallback::shaped_text_set_orientation(RID p_shaped, TextServer::Orientation p_orientation) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND(!sd); MutexLock lock(sd->mutex); @@ -2063,7 +2042,7 @@ void TextServerFallback::shaped_text_set_bidi_override(RID p_shaped, const Vecto } TextServer::Orientation TextServerFallback::shaped_text_get_orientation(RID p_shaped) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, TextServer::ORIENTATION_HORIZONTAL); MutexLock lock(sd->mutex); @@ -2071,7 +2050,7 @@ TextServer::Orientation TextServerFallback::shaped_text_get_orientation(RID p_sh } void TextServerFallback::shaped_text_set_preserve_invalid(RID p_shaped, bool p_enabled) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); MutexLock lock(sd->mutex); ERR_FAIL_COND(!sd); @@ -2085,7 +2064,7 @@ void TextServerFallback::shaped_text_set_preserve_invalid(RID p_shaped, bool p_e } bool TextServerFallback::shaped_text_get_preserve_invalid(RID p_shaped) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -2093,7 +2072,7 @@ bool TextServerFallback::shaped_text_get_preserve_invalid(RID p_shaped) const { } void TextServerFallback::shaped_text_set_preserve_control(RID p_shaped, bool p_enabled) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND(!sd); MutexLock lock(sd->mutex); @@ -2107,7 +2086,7 @@ void TextServerFallback::shaped_text_set_preserve_control(RID p_shaped, bool p_e } bool TextServerFallback::shaped_text_get_preserve_control(RID p_shaped) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -2115,14 +2094,14 @@ bool TextServerFallback::shaped_text_get_preserve_control(RID p_shaped) const { } bool TextServerFallback::shaped_text_add_string(RID p_shaped, const String &p_text, const Vector<RID> &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); ERR_FAIL_COND_V(p_size <= 0, false); for (int i = 0; i < p_fonts.size(); i++) { - ERR_FAIL_COND_V(!font_owner.getornull(p_fonts[i]), false); + ERR_FAIL_COND_V(!font_owner.get_or_null(p_fonts[i]), false); } if (p_text.is_empty()) { @@ -2162,7 +2141,7 @@ bool TextServerFallback::shaped_text_add_string(RID p_shaped, const String &p_te } bool TextServerFallback::shaped_text_add_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlign p_inline_align, int p_length) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -2193,7 +2172,7 @@ bool TextServerFallback::shaped_text_add_object(RID p_shaped, Variant p_key, con } bool TextServerFallback::shaped_text_resize_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlign p_inline_align) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -2326,7 +2305,7 @@ bool TextServerFallback::shaped_text_resize_object(RID p_shaped, Variant p_key, } RID TextServerFallback::shaped_text_substr(RID p_shaped, int p_start, int p_length) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, RID()); MutexLock lock(sd->mutex); @@ -2480,7 +2459,7 @@ RID TextServerFallback::shaped_text_substr(RID p_shaped, int p_start, int p_leng } RID TextServerFallback::shaped_text_get_parent(RID p_shaped) const { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, RID()); MutexLock lock(sd->mutex); @@ -2488,7 +2467,7 @@ RID TextServerFallback::shaped_text_get_parent(RID p_shaped) const { } real_t TextServerFallback::shaped_text_fit_to_width(RID p_shaped, real_t p_width, uint8_t /*JustificationFlag*/ p_jst_flags) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); @@ -2568,7 +2547,7 @@ real_t TextServerFallback::shaped_text_fit_to_width(RID p_shaped, real_t p_width } real_t TextServerFallback::shaped_text_tab_align(RID p_shaped, const Vector<real_t> &p_tab_stops) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); @@ -2618,7 +2597,7 @@ real_t TextServerFallback::shaped_text_tab_align(RID p_shaped, const Vector<real } bool TextServerFallback::shaped_text_update_breaks(RID p_shaped) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -2659,7 +2638,7 @@ bool TextServerFallback::shaped_text_update_breaks(RID p_shaped) { } bool TextServerFallback::shaped_text_update_justification_ops(RID p_shaped) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -2675,7 +2654,7 @@ bool TextServerFallback::shaped_text_update_justification_ops(RID p_shaped) { } void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, real_t p_width, uint8_t p_trim_flags) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped_line); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped_line); ERR_FAIL_COND_MSG(!sd, "ShapedTextDataFallback invalid."); MutexLock lock(sd->mutex); @@ -2683,6 +2662,7 @@ void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, re shaped_text_shape(p_shaped_line); } + sd->text_trimmed = false; sd->overrun_trim_data.ellipsis_glyph_buf.clear(); bool add_ellipsis = (p_trim_flags & OVERRUN_ADD_ELLIPSIS) == OVERRUN_ADD_ELLIPSIS; @@ -2791,7 +2771,7 @@ void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, re } TextServer::TrimData TextServerFallback::shaped_text_get_trim_data(RID p_shaped) const { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V_MSG(!sd, TrimData(), "ShapedTextDataFallback invalid."); MutexLock lock(sd->mutex); @@ -2799,7 +2779,7 @@ TextServer::TrimData TextServerFallback::shaped_text_get_trim_data(RID p_shaped) } bool TextServerFallback::shaped_text_shape(RID p_shaped) { - ShapedTextData *sd = shaped_owner.getornull(p_shaped); + ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -2993,7 +2973,7 @@ bool TextServerFallback::shaped_text_shape(RID p_shaped) { } bool TextServerFallback::shaped_text_is_ready(RID p_shaped) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, false); MutexLock lock(sd->mutex); @@ -3001,7 +2981,7 @@ bool TextServerFallback::shaped_text_is_ready(RID p_shaped) const { } Vector<TextServer::Glyph> TextServerFallback::shaped_text_get_glyphs(RID p_shaped) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, Vector<TextServer::Glyph>()); MutexLock lock(sd->mutex); @@ -3012,7 +2992,7 @@ Vector<TextServer::Glyph> TextServerFallback::shaped_text_get_glyphs(RID p_shape } Vector2i TextServerFallback::shaped_text_get_range(RID p_shaped) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, Vector2i()); MutexLock lock(sd->mutex); @@ -3020,7 +3000,7 @@ Vector2i TextServerFallback::shaped_text_get_range(RID p_shaped) const { } Vector<TextServer::Glyph> TextServerFallback::shaped_text_sort_logical(RID p_shaped) { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, Vector<TextServer::Glyph>()); MutexLock lock(sd->mutex); @@ -3033,7 +3013,7 @@ Vector<TextServer::Glyph> TextServerFallback::shaped_text_sort_logical(RID p_sha Array TextServerFallback::shaped_text_get_objects(RID p_shaped) const { Array ret; - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, ret); MutexLock lock(sd->mutex); @@ -3045,7 +3025,7 @@ Array TextServerFallback::shaped_text_get_objects(RID p_shaped) const { } Rect2 TextServerFallback::shaped_text_get_object_rect(RID p_shaped, Variant p_key) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, Rect2()); MutexLock lock(sd->mutex); @@ -3057,7 +3037,7 @@ Rect2 TextServerFallback::shaped_text_get_object_rect(RID p_shaped, Variant p_ke } Size2 TextServerFallback::shaped_text_get_size(RID p_shaped) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, Size2()); MutexLock lock(sd->mutex); @@ -3072,7 +3052,7 @@ Size2 TextServerFallback::shaped_text_get_size(RID p_shaped) const { } real_t TextServerFallback::shaped_text_get_ascent(RID p_shaped) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); @@ -3083,7 +3063,7 @@ real_t TextServerFallback::shaped_text_get_ascent(RID p_shaped) const { } real_t TextServerFallback::shaped_text_get_descent(RID p_shaped) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); @@ -3094,7 +3074,7 @@ real_t TextServerFallback::shaped_text_get_descent(RID p_shaped) const { } real_t TextServerFallback::shaped_text_get_width(RID p_shaped) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); @@ -3105,7 +3085,7 @@ real_t TextServerFallback::shaped_text_get_width(RID p_shaped) const { } real_t TextServerFallback::shaped_text_get_underline_position(RID p_shaped) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); @@ -3117,7 +3097,7 @@ real_t TextServerFallback::shaped_text_get_underline_position(RID p_shaped) cons } real_t TextServerFallback::shaped_text_get_underline_thickness(RID p_shaped) const { - const ShapedTextData *sd = shaped_owner.getornull(p_shaped); + const ShapedTextData *sd = shaped_owner.get_or_null(p_shaped); ERR_FAIL_COND_V(!sd, 0.f); MutexLock lock(sd->mutex); diff --git a/modules/webrtc/SCsub b/modules/webrtc/SCsub index 31b8a73bf2..e6b9959840 100644 --- a/modules/webrtc/SCsub +++ b/modules/webrtc/SCsub @@ -4,11 +4,6 @@ Import("env") Import("env_modules") env_webrtc = env_modules.Clone() -use_gdnative = env_webrtc["module_gdnative_enabled"] - -if use_gdnative: # GDNative is retained in Javascript for export compatibility - env_webrtc.Append(CPPDEFINES=["WEBRTC_GDNATIVE_ENABLED"]) - env_webrtc.Prepend(CPPPATH=["#modules/gdnative/include/"]) if env["platform"] == "javascript": # Our JavaScript/C++ interface. diff --git a/modules/webrtc/config.py b/modules/webrtc/config.py index 3281415f38..4ad918833a 100644 --- a/modules/webrtc/config.py +++ b/modules/webrtc/config.py @@ -11,6 +11,8 @@ def get_doc_classes(): "WebRTCPeerConnection", "WebRTCDataChannel", "WebRTCMultiplayerPeer", + "WebRTCPeerConnectionExtension", + "WebRTCDataChannelExtension", ] diff --git a/modules/webrtc/doc_classes/WebRTCDataChannelExtension.xml b/modules/webrtc/doc_classes/WebRTCDataChannelExtension.xml new file mode 100644 index 0000000000..746fabd6e5 --- /dev/null +++ b/modules/webrtc/doc_classes/WebRTCDataChannelExtension.xml @@ -0,0 +1,106 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="WebRTCDataChannelExtension" inherits="WebRTCDataChannel" version="4.0"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + <method name="_close" qualifiers="virtual"> + <return type="void" /> + <description> + </description> + </method> + <method name="_get_available_packet_count" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_buffered_amount" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_id" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_label" qualifiers="virtual const"> + <return type="String" /> + <description> + </description> + </method> + <method name="_get_max_packet_life_time" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_max_packet_size" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_max_retransmits" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_packet" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="r_buffer" type="const uint8_t **" /> + <argument index="1" name="r_buffer_size" type="int32_t*" /> + <description> + </description> + </method> + <method name="_get_protocol" qualifiers="virtual const"> + <return type="String" /> + <description> + </description> + </method> + <method name="_get_ready_state" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_write_mode" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_is_negotiated" qualifiers="virtual const"> + <return type="bool" /> + <description> + </description> + </method> + <method name="_is_ordered" qualifiers="virtual const"> + <return type="bool" /> + <description> + </description> + </method> + <method name="_poll" qualifiers="virtual"> + <return type="int" /> + <description> + </description> + </method> + <method name="_put_packet" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="p_buffer" type="const uint8_t*" /> + <argument index="1" name="p_buffer_size" type="int" /> + <description> + </description> + </method> + <method name="_set_write_mode" qualifiers="virtual"> + <return type="void" /> + <argument index="0" name="p_write_mode" type="int" /> + <description> + </description> + </method> + <method name="_was_string_packet" qualifiers="virtual const"> + <return type="bool" /> + <description> + </description> + </method> + </methods> +</class> diff --git a/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml b/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml index 9040d510c0..a8360a4d45 100644 --- a/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml +++ b/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml @@ -7,6 +7,7 @@ This class constructs a full mesh of [WebRTCPeerConnection] (one connection for each peer) that can be used as a [member MultiplayerAPI.multiplayer_peer]. You can add each [WebRTCPeerConnection] via [method add_peer] or remove them via [method remove_peer]. Peers must be added in [constant WebRTCPeerConnection.STATE_NEW] state to allow it to create the appropriate channels. This class will not create offers nor set descriptions, it will only poll them, and notify connections and disconnections. [signal MultiplayerPeer.connection_succeeded] and [signal MultiplayerPeer.server_disconnected] will not be emitted unless [code]server_compatibility[/code] is [code]true[/code] in [method initialize]. Beside that data transfer works like in a [MultiplayerPeer]. + [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> </tutorials> @@ -67,8 +68,4 @@ </description> </method> </methods> - <members> - <member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" /> - <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="TransferMode" default="2" /> - </members> </class> diff --git a/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml b/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml new file mode 100644 index 0000000000..d296fcd6e7 --- /dev/null +++ b/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="WebRTCPeerConnectionExtension" inherits="WebRTCPeerConnection" version="4.0"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + <method name="_add_ice_candidate" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="p_sdp_mid_name" type="String" /> + <argument index="1" name="p_sdp_mline_index" type="int" /> + <argument index="2" name="p_sdp_name" type="String" /> + <description> + </description> + </method> + <method name="_close" qualifiers="virtual"> + <return type="void" /> + <description> + </description> + </method> + <method name="_create_data_channel" qualifiers="virtual"> + <return type="Object" /> + <argument index="0" name="p_label" type="String" /> + <argument index="1" name="p_config" type="Dictionary" /> + <description> + </description> + </method> + <method name="_create_offer" qualifiers="virtual"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_connection_state" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_initialize" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="p_config" type="Dictionary" /> + <description> + </description> + </method> + <method name="_poll" qualifiers="virtual"> + <return type="int" /> + <description> + </description> + </method> + <method name="_set_local_description" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="p_type" type="String" /> + <argument index="1" name="p_sdp" type="String" /> + <description> + </description> + </method> + <method name="_set_remote_description" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="p_type" type="String" /> + <argument index="1" name="p_sdp" type="String" /> + <description> + </description> + </method> + <method name="make_default"> + <return type="void" /> + <description> + </description> + </method> + </methods> +</class> diff --git a/modules/webrtc/register_types.cpp b/modules/webrtc/register_types.cpp index 63ecc03a4c..8110e4a048 100644 --- a/modules/webrtc/register_types.cpp +++ b/modules/webrtc/register_types.cpp @@ -31,17 +31,11 @@ #include "register_types.h" #include "core/config/project_settings.h" #include "webrtc_data_channel.h" +#include "webrtc_multiplayer_peer.h" #include "webrtc_peer_connection.h" -#ifdef JAVASCRIPT_ENABLED -#include "emscripten.h" -#include "webrtc_peer_connection_js.h" -#endif -#ifdef WEBRTC_GDNATIVE_ENABLED -#include "webrtc_data_channel_gdnative.h" -#include "webrtc_peer_connection_gdnative.h" -#endif -#include "webrtc_multiplayer_peer.h" +#include "webrtc_data_channel_extension.h" +#include "webrtc_peer_connection_extension.h" void register_webrtc_types() { #define _SET_HINT(NAME, _VAL_, _MAX_) \ @@ -50,18 +44,12 @@ void register_webrtc_types() { _SET_HINT(WRTC_IN_BUF, 64, 4096); -#ifdef JAVASCRIPT_ENABLED - WebRTCPeerConnectionJS::make_default(); -#elif defined(WEBRTC_GDNATIVE_ENABLED) - WebRTCPeerConnectionGDNative::make_default(); -#endif - ClassDB::register_custom_instance_class<WebRTCPeerConnection>(); -#ifdef WEBRTC_GDNATIVE_ENABLED - GDREGISTER_CLASS(WebRTCPeerConnectionGDNative); - GDREGISTER_CLASS(WebRTCDataChannelGDNative); -#endif + GDREGISTER_CLASS(WebRTCPeerConnectionExtension); + GDREGISTER_VIRTUAL_CLASS(WebRTCDataChannel); + GDREGISTER_CLASS(WebRTCDataChannelExtension); + GDREGISTER_CLASS(WebRTCMultiplayerPeer); } diff --git a/modules/webrtc/webrtc_data_channel_extension.cpp b/modules/webrtc/webrtc_data_channel_extension.cpp new file mode 100644 index 0000000000..ae346f6d8e --- /dev/null +++ b/modules/webrtc/webrtc_data_channel_extension.cpp @@ -0,0 +1,215 @@ +/*************************************************************************/ +/* webrtc_data_channel_extension.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "webrtc_data_channel_extension.h" + +void WebRTCDataChannelExtension::_bind_methods() { + ADD_PROPERTY_DEFAULT("write_mode", WRITE_MODE_BINARY); + + GDVIRTUAL_BIND(_get_packet, "r_buffer", "r_buffer_size"); + GDVIRTUAL_BIND(_put_packet, "p_buffer", "p_buffer_size"); + GDVIRTUAL_BIND(_get_available_packet_count); + GDVIRTUAL_BIND(_get_max_packet_size); + + GDVIRTUAL_BIND(_poll); + GDVIRTUAL_BIND(_close); + + GDVIRTUAL_BIND(_set_write_mode, "p_write_mode"); + GDVIRTUAL_BIND(_get_write_mode); + + GDVIRTUAL_BIND(_was_string_packet); + GDVIRTUAL_BIND(_get_ready_state); + GDVIRTUAL_BIND(_get_label); + GDVIRTUAL_BIND(_is_ordered); + GDVIRTUAL_BIND(_get_id); + GDVIRTUAL_BIND(_get_max_packet_life_time); + GDVIRTUAL_BIND(_get_max_retransmits); + GDVIRTUAL_BIND(_get_protocol); + GDVIRTUAL_BIND(_is_negotiated); + GDVIRTUAL_BIND(_get_buffered_amount); +} + +int WebRTCDataChannelExtension::get_available_packet_count() const { + int count; + if (GDVIRTUAL_CALL(_get_available_packet_count, count)) { + return count; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_available_packet_count is unimplemented!"); + return -1; +} + +Error WebRTCDataChannelExtension::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { + int err; + if (GDVIRTUAL_CALL(_get_packet, r_buffer, &r_buffer_size, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_packet_native is unimplemented!"); + return FAILED; +} + +Error WebRTCDataChannelExtension::put_packet(const uint8_t *p_buffer, int p_buffer_size) { + int err; + if (GDVIRTUAL_CALL(_put_packet, p_buffer, p_buffer_size, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_put_packet_native is unimplemented!"); + return FAILED; +} + +int WebRTCDataChannelExtension::get_max_packet_size() const { + int size; + if (GDVIRTUAL_CALL(_get_max_packet_size, size)) { + return size; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_packet_size is unimplemented!"); + return 0; +} + +Error WebRTCDataChannelExtension::poll() { + int err; + if (GDVIRTUAL_CALL(_poll, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_poll is unimplemented!"); + return ERR_UNCONFIGURED; +} + +void WebRTCDataChannelExtension::close() { + if (GDVIRTUAL_CALL(_close)) { + return; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_close is unimplemented!"); +} + +void WebRTCDataChannelExtension::set_write_mode(WriteMode p_mode) { + if (GDVIRTUAL_CALL(_set_write_mode, p_mode)) { + return; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_set_write_mode is unimplemented!"); +} + +WebRTCDataChannel::WriteMode WebRTCDataChannelExtension::get_write_mode() const { + int mode; + if (GDVIRTUAL_CALL(_get_write_mode, mode)) { + return (WriteMode)mode; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_write_mode is unimplemented!"); + return WRITE_MODE_BINARY; +} + +bool WebRTCDataChannelExtension::was_string_packet() const { + bool was_string; + if (GDVIRTUAL_CALL(_was_string_packet, was_string)) { + return was_string; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_was_string_packet is unimplemented!"); + return false; +} + +WebRTCDataChannel::ChannelState WebRTCDataChannelExtension::get_ready_state() const { + int state; + if (GDVIRTUAL_CALL(_get_ready_state, state)) { + return (ChannelState)state; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_ready_state is unimplemented!"); + return STATE_CLOSED; +} + +String WebRTCDataChannelExtension::get_label() const { + String label; + if (GDVIRTUAL_CALL(_get_label, label)) { + return label; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_label is unimplemented!"); + return label; +} + +bool WebRTCDataChannelExtension::is_ordered() const { + bool ordered; + if (GDVIRTUAL_CALL(_is_ordered, ordered)) { + return ordered; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_is_ordered is unimplemented!"); + return false; +} + +int WebRTCDataChannelExtension::get_id() const { + int id; + if (GDVIRTUAL_CALL(_get_id, id)) { + return id; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_id is unimplemented!"); + return -1; +} + +int WebRTCDataChannelExtension::get_max_packet_life_time() const { + int lifetime; + if (GDVIRTUAL_CALL(_get_max_packet_life_time, lifetime)) { + return lifetime; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_packet_life_time is unimplemented!"); + return -1; +} + +int WebRTCDataChannelExtension::get_max_retransmits() const { + int retransmits; + if (GDVIRTUAL_CALL(_get_max_retransmits, retransmits)) { + return retransmits; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_retransmits is unimplemented!"); + return -1; +} + +String WebRTCDataChannelExtension::get_protocol() const { + String protocol; + if (GDVIRTUAL_CALL(_get_protocol, protocol)) { + return protocol; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_protocol is unimplemented!"); + return protocol; +} + +bool WebRTCDataChannelExtension::is_negotiated() const { + bool negotiated; + if (GDVIRTUAL_CALL(_is_negotiated, negotiated)) { + return negotiated; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_is_negotiated is unimplemented!"); + return false; +} + +int WebRTCDataChannelExtension::get_buffered_amount() const { + int amount; + if (GDVIRTUAL_CALL(_get_buffered_amount, amount)) { + return amount; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_buffered_amount is unimplemented!"); + return -1; +} diff --git a/modules/webrtc/webrtc_data_channel_gdnative.h b/modules/webrtc/webrtc_data_channel_extension.h index 5c80edd48c..eec96b4c62 100644 --- a/modules/webrtc/webrtc_data_channel_gdnative.h +++ b/modules/webrtc/webrtc_data_channel_extension.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* webrtc_data_channel_gdnative.h */ +/* webrtc_data_channel_extension.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,26 +28,22 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef WEBRTC_DATA_CHANNEL_GDNATIVE_H -#define WEBRTC_DATA_CHANNEL_GDNATIVE_H +#ifndef WEBRTC_DATA_CHANNEL_EXTENSION_H +#define WEBRTC_DATA_CHANNEL_EXTENSION_H -#ifdef WEBRTC_GDNATIVE_ENABLED - -#include "modules/gdnative/include/net/godot_net.h" #include "webrtc_data_channel.h" -class WebRTCDataChannelGDNative : public WebRTCDataChannel { - GDCLASS(WebRTCDataChannelGDNative, WebRTCDataChannel); +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language.h" +#include "core/variant/native_ptr.h" + +class WebRTCDataChannelExtension : public WebRTCDataChannel { + GDCLASS(WebRTCDataChannelExtension, WebRTCDataChannel); protected: static void _bind_methods(); -private: - const godot_net_webrtc_data_channel *interface; - public: - void set_native_webrtc_data_channel(const godot_net_webrtc_data_channel *p_impl); - virtual void set_write_mode(WriteMode mode) override; virtual WriteMode get_write_mode() const override; virtual bool was_string_packet() const override; @@ -72,10 +68,31 @@ public: virtual int get_max_packet_size() const override; - WebRTCDataChannelGDNative(); - ~WebRTCDataChannelGDNative(); -}; + /** GDExtension **/ + GDVIRTUAL0RC(int, _get_available_packet_count); + GDVIRTUAL2R(int, _get_packet, GDNativeConstPtr<const uint8_t *>, GDNativePtr<int>); + GDVIRTUAL2R(int, _put_packet, GDNativeConstPtr<const uint8_t>, int); + GDVIRTUAL0RC(int, _get_max_packet_size); -#endif // WEBRTC_GDNATIVE_ENABLED + GDVIRTUAL0R(int, _poll); + GDVIRTUAL0(_close); + + GDVIRTUAL1(_set_write_mode, int); + GDVIRTUAL0RC(int, _get_write_mode); + + GDVIRTUAL0RC(bool, _was_string_packet); + + GDVIRTUAL0RC(int, _get_ready_state); + GDVIRTUAL0RC(String, _get_label); + GDVIRTUAL0RC(bool, _is_ordered); + GDVIRTUAL0RC(int, _get_id); + GDVIRTUAL0RC(int, _get_max_packet_life_time); + GDVIRTUAL0RC(int, _get_max_retransmits); + GDVIRTUAL0RC(String, _get_protocol); + GDVIRTUAL0RC(bool, _is_negotiated); + GDVIRTUAL0RC(int, _get_buffered_amount); + + WebRTCDataChannelExtension() {} +}; -#endif // WEBRTC_DATA_CHANNEL_GDNATIVE_H +#endif // WEBRTC_DATA_CHANNEL_EXTENSION_H diff --git a/modules/webrtc/webrtc_data_channel_gdnative.cpp b/modules/webrtc/webrtc_data_channel_gdnative.cpp deleted file mode 100644 index 10a3367557..0000000000 --- a/modules/webrtc/webrtc_data_channel_gdnative.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/*************************************************************************/ -/* webrtc_data_channel_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifdef WEBRTC_GDNATIVE_ENABLED - -#include "webrtc_data_channel_gdnative.h" - -#include "core/io/resource_loader.h" -#include "modules/gdnative/nativescript/nativescript.h" - -void WebRTCDataChannelGDNative::_bind_methods() { - ADD_PROPERTY_DEFAULT("write_mode", WRITE_MODE_BINARY); -} - -WebRTCDataChannelGDNative::WebRTCDataChannelGDNative() { - interface = nullptr; -} - -WebRTCDataChannelGDNative::~WebRTCDataChannelGDNative() { -} - -Error WebRTCDataChannelGDNative::poll() { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->poll(interface->data); -} - -void WebRTCDataChannelGDNative::close() { - ERR_FAIL_COND(interface == nullptr); - interface->close(interface->data); -} - -void WebRTCDataChannelGDNative::set_write_mode(WriteMode p_mode) { - ERR_FAIL_COND(interface == nullptr); - interface->set_write_mode(interface->data, p_mode); -} - -WebRTCDataChannel::WriteMode WebRTCDataChannelGDNative::get_write_mode() const { - ERR_FAIL_COND_V(interface == nullptr, WRITE_MODE_BINARY); - return (WriteMode)interface->get_write_mode(interface->data); -} - -bool WebRTCDataChannelGDNative::was_string_packet() const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->was_string_packet(interface->data); -} - -WebRTCDataChannel::ChannelState WebRTCDataChannelGDNative::get_ready_state() const { - ERR_FAIL_COND_V(interface == nullptr, STATE_CLOSED); - return (ChannelState)interface->get_ready_state(interface->data); -} - -String WebRTCDataChannelGDNative::get_label() const { - ERR_FAIL_COND_V(interface == nullptr, ""); - return String(interface->get_label(interface->data)); -} - -bool WebRTCDataChannelGDNative::is_ordered() const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->is_ordered(interface->data); -} - -int WebRTCDataChannelGDNative::get_id() const { - ERR_FAIL_COND_V(interface == nullptr, -1); - return interface->get_id(interface->data); -} - -int WebRTCDataChannelGDNative::get_max_packet_life_time() const { - ERR_FAIL_COND_V(interface == nullptr, -1); - return interface->get_max_packet_life_time(interface->data); -} - -int WebRTCDataChannelGDNative::get_max_retransmits() const { - ERR_FAIL_COND_V(interface == nullptr, -1); - return interface->get_max_retransmits(interface->data); -} - -String WebRTCDataChannelGDNative::get_protocol() const { - ERR_FAIL_COND_V(interface == nullptr, ""); - return String(interface->get_protocol(interface->data)); -} - -bool WebRTCDataChannelGDNative::is_negotiated() const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->is_negotiated(interface->data); -} - -int WebRTCDataChannelGDNative::get_buffered_amount() const { - ERR_FAIL_COND_V(interface == NULL, 0); - return interface->get_buffered_amount(interface->data); -} - -Error WebRTCDataChannelGDNative::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->get_packet(interface->data, r_buffer, &r_buffer_size); -} - -Error WebRTCDataChannelGDNative::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->put_packet(interface->data, p_buffer, p_buffer_size); -} - -int WebRTCDataChannelGDNative::get_max_packet_size() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_max_packet_size(interface->data); -} - -int WebRTCDataChannelGDNative::get_available_packet_count() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_available_packet_count(interface->data); -} - -void WebRTCDataChannelGDNative::set_native_webrtc_data_channel(const godot_net_webrtc_data_channel *p_impl) { - interface = p_impl; -} - -#endif // WEBRTC_GDNATIVE_ENABLED diff --git a/modules/webrtc/webrtc_multiplayer_peer.cpp b/modules/webrtc/webrtc_multiplayer_peer.cpp index d60d694df1..48117f05f2 100644 --- a/modules/webrtc/webrtc_multiplayer_peer.cpp +++ b/modules/webrtc/webrtc_multiplayer_peer.cpp @@ -43,22 +43,6 @@ void WebRTCMultiplayerPeer::_bind_methods() { ClassDB::bind_method(D_METHOD("close"), &WebRTCMultiplayerPeer::close); } -void WebRTCMultiplayerPeer::set_transfer_channel(int p_channel) { - transfer_channel = p_channel; -} - -int WebRTCMultiplayerPeer::get_transfer_channel() const { - return transfer_channel; -} - -void WebRTCMultiplayerPeer::set_transfer_mode(Multiplayer::TransferMode p_mode) { - transfer_mode = p_mode; -} - -Multiplayer::TransferMode WebRTCMultiplayerPeer::get_transfer_mode() const { - return transfer_mode; -} - void WebRTCMultiplayerPeer::set_target_peer(int p_peer_id) { target_peer = p_peer_id; } @@ -188,14 +172,6 @@ void WebRTCMultiplayerPeer::_find_next_peer() { next_packet_peer = 0; } -void WebRTCMultiplayerPeer::set_refuse_new_connections(bool p_enable) { - refuse_connections = p_enable; -} - -bool WebRTCMultiplayerPeer::is_refusing_new_connections() const { - return refuse_connections; -} - MultiplayerPeer::ConnectionStatus WebRTCMultiplayerPeer::get_connection_status() const { return connection_status; } @@ -279,7 +255,7 @@ Dictionary WebRTCMultiplayerPeer::get_peers() { Error WebRTCMultiplayerPeer::add_peer(Ref<WebRTCPeerConnection> p_peer, int p_peer_id, int p_unreliable_lifetime) { ERR_FAIL_COND_V(p_peer_id < 0 || p_peer_id > ~(1 << 31), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_unreliable_lifetime < 0, ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(refuse_connections, ERR_UNAUTHORIZED); + ERR_FAIL_COND_V(is_refusing_new_connections(), ERR_UNAUTHORIZED); // Peer must be valid, and in new state (to create data channels) ERR_FAIL_COND_V(!p_peer.is_valid(), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_peer->get_connection_state() != WebRTCPeerConnection::STATE_NEW, ERR_INVALID_PARAMETER); @@ -352,9 +328,9 @@ Error WebRTCMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_ Error WebRTCMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { ERR_FAIL_COND_V(connection_status == CONNECTION_DISCONNECTED, ERR_UNCONFIGURED); - int ch = transfer_channel; + int ch = get_transfer_channel(); if (ch == 0) { - switch (transfer_mode) { + switch (get_transfer_mode()) { case Multiplayer::TRANSFER_MODE_RELIABLE: ch = CH_RELIABLE; break; diff --git a/modules/webrtc/webrtc_multiplayer_peer.h b/modules/webrtc/webrtc_multiplayer_peer.h index 80a6491492..4a7e9ad7c8 100644 --- a/modules/webrtc/webrtc_multiplayer_peer.h +++ b/modules/webrtc/webrtc_multiplayer_peer.h @@ -65,10 +65,7 @@ private: uint32_t unique_id = 0; int target_peer = 0; int client_count = 0; - bool refuse_connections = false; ConnectionStatus connection_status = CONNECTION_DISCONNECTED; - int transfer_channel = 0; - Multiplayer::TransferMode transfer_mode = Multiplayer::TRANSFER_MODE_RELIABLE; int next_packet_peer = 0; bool server_compat = false; @@ -97,10 +94,6 @@ public: int get_max_packet_size() const override; // MultiplayerPeer - void set_transfer_channel(int p_channel) override; - int get_transfer_channel() const override; - void set_transfer_mode(Multiplayer::TransferMode p_mode) override; - Multiplayer::TransferMode get_transfer_mode() const override; void set_target_peer(int p_peer_id) override; int get_unique_id() const override; @@ -110,9 +103,6 @@ public: void poll() override; - void set_refuse_new_connections(bool p_enable) override; - bool is_refusing_new_connections() const override; - ConnectionStatus get_connection_status() const override; }; diff --git a/modules/webrtc/webrtc_peer_connection.cpp b/modules/webrtc/webrtc_peer_connection.cpp index 3e2938bf7d..ad28aa76c7 100644 --- a/modules/webrtc/webrtc_peer_connection.cpp +++ b/modules/webrtc/webrtc_peer_connection.cpp @@ -30,17 +30,29 @@ #include "webrtc_peer_connection.h" -WebRTCPeerConnection *(*WebRTCPeerConnection::_create)() = nullptr; +#ifdef JAVASCRIPT_ENABLED +#include "webrtc_peer_connection_js.h" +#else +#include "webrtc_peer_connection_extension.h" +#endif -Ref<WebRTCPeerConnection> WebRTCPeerConnection::create_ref() { - return create(); +StringName WebRTCPeerConnection::default_extension; + +void WebRTCPeerConnection::set_default_extension(const StringName &p_extension) { + default_extension = p_extension; } WebRTCPeerConnection *WebRTCPeerConnection::create() { - if (!_create) { - return nullptr; +#ifdef JAVASCRIPT_ENABLED + return memnew(WebRTCPeerConnectionJS); +#else + if (default_extension == String()) { + WARN_PRINT_ONCE("No default WebRTC extension configured."); + return memnew(WebRTCPeerConnectionExtension); } - return _create(); + Object *obj = ClassDB::instantiate(default_extension); + return Object::cast_to<WebRTCPeerConnectionExtension>(obj); +#endif } void WebRTCPeerConnection::_bind_methods() { diff --git a/modules/webrtc/webrtc_peer_connection.h b/modules/webrtc/webrtc_peer_connection.h index fcfb9ae9ae..e2ef3e55ad 100644 --- a/modules/webrtc/webrtc_peer_connection.h +++ b/modules/webrtc/webrtc_peer_connection.h @@ -47,11 +47,15 @@ public: STATE_CLOSED }; +private: + static StringName default_extension; + protected: static void _bind_methods(); - static WebRTCPeerConnection *(*_create)(); public: + static void set_default_extension(const StringName &p_name); + virtual ConnectionState get_connection_state() const = 0; virtual Error initialize(Dictionary p_config = Dictionary()) = 0; @@ -63,7 +67,6 @@ public: virtual Error poll() = 0; virtual void close() = 0; - static Ref<WebRTCPeerConnection> create_ref(); static WebRTCPeerConnection *create(); WebRTCPeerConnection(); diff --git a/modules/webrtc/webrtc_peer_connection_extension.cpp b/modules/webrtc/webrtc_peer_connection_extension.cpp new file mode 100644 index 0000000000..33288e66d6 --- /dev/null +++ b/modules/webrtc/webrtc_peer_connection_extension.cpp @@ -0,0 +1,131 @@ +/*************************************************************************/ +/* webrtc_peer_connection_extension.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "webrtc_peer_connection_extension.h" + +void WebRTCPeerConnectionExtension::_bind_methods() { + ClassDB::bind_method(D_METHOD("make_default"), &WebRTCPeerConnectionExtension::make_default); + + GDVIRTUAL_BIND(_get_connection_state); + GDVIRTUAL_BIND(_initialize, "p_config"); + GDVIRTUAL_BIND(_create_data_channel, "p_label", "p_config"); + GDVIRTUAL_BIND(_create_offer); + GDVIRTUAL_BIND(_set_remote_description, "p_type", "p_sdp"); + GDVIRTUAL_BIND(_set_local_description, "p_type", "p_sdp"); + GDVIRTUAL_BIND(_add_ice_candidate, "p_sdp_mid_name", "p_sdp_mline_index", "p_sdp_name"); + GDVIRTUAL_BIND(_poll); + GDVIRTUAL_BIND(_close); +} + +void WebRTCPeerConnectionExtension::make_default() { + ERR_FAIL_COND_MSG(!_get_extension(), vformat("Can't make %s the default without extending it.", get_class())); + WebRTCPeerConnection::set_default_extension(get_class()); +} + +WebRTCPeerConnection::ConnectionState WebRTCPeerConnectionExtension::get_connection_state() const { + int state; + if (GDVIRTUAL_CALL(_get_connection_state, state)) { + return (ConnectionState)state; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_get_connection_state is unimplemented!"); + return STATE_DISCONNECTED; +} + +Error WebRTCPeerConnectionExtension::initialize(Dictionary p_config) { + int err; + if (GDVIRTUAL_CALL(_initialize, p_config, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_initialize is unimplemented!"); + return ERR_UNCONFIGURED; +} + +Ref<WebRTCDataChannel> WebRTCPeerConnectionExtension::create_data_channel(String p_label, Dictionary p_options) { + Object *ret = nullptr; + if (GDVIRTUAL_CALL(_create_data_channel, p_label, p_options, ret)) { + WebRTCDataChannel *ch = Object::cast_to<WebRTCDataChannel>(ret); + ERR_FAIL_COND_V_MSG(ret && !ch, nullptr, "Returned object must be an instance of WebRTCDataChannel."); + return ch; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_create_data_channel is unimplemented!"); + return nullptr; +} + +Error WebRTCPeerConnectionExtension::create_offer() { + int err; + if (GDVIRTUAL_CALL(_create_offer, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_create_offer is unimplemented!"); + return ERR_UNCONFIGURED; +} + +Error WebRTCPeerConnectionExtension::set_local_description(String p_type, String p_sdp) { + int err; + if (GDVIRTUAL_CALL(_set_local_description, p_type, p_sdp, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_set_local_description is unimplemented!"); + return ERR_UNCONFIGURED; +} + +Error WebRTCPeerConnectionExtension::set_remote_description(String p_type, String p_sdp) { + int err; + if (GDVIRTUAL_CALL(_set_remote_description, p_type, p_sdp, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_set_remote_description is unimplemented!"); + return ERR_UNCONFIGURED; +} + +Error WebRTCPeerConnectionExtension::add_ice_candidate(String p_sdp_mid_name, int p_sdp_mline_index, String p_sdp_name) { + int err; + if (GDVIRTUAL_CALL(_add_ice_candidate, p_sdp_mid_name, p_sdp_mline_index, p_sdp_name, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_add_ice_candidate is unimplemented!"); + return ERR_UNCONFIGURED; +} + +Error WebRTCPeerConnectionExtension::poll() { + int err; + if (GDVIRTUAL_CALL(_poll, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_poll is unimplemented!"); + return ERR_UNCONFIGURED; +} + +void WebRTCPeerConnectionExtension::close() { + if (GDVIRTUAL_CALL(_close)) { + return; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_close is unimplemented!"); +} diff --git a/modules/webrtc/webrtc_peer_connection_gdnative.h b/modules/webrtc/webrtc_peer_connection_extension.h index 578af0202f..b3c2039fc1 100644 --- a/modules/webrtc/webrtc_peer_connection_gdnative.h +++ b/modules/webrtc/webrtc_peer_connection_extension.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* webrtc_peer_connection_gdnative.h */ +/* webrtc_peer_connection_extension.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,30 +28,23 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef WEBRTC_PEER_CONNECTION_GDNATIVE_H -#define WEBRTC_PEER_CONNECTION_GDNATIVE_H +#ifndef WEBRTC_PEER_CONNECTION_EXTENSION_H +#define WEBRTC_PEER_CONNECTION_EXTENSION_H -#ifdef WEBRTC_GDNATIVE_ENABLED - -#include "modules/gdnative/include/net/godot_net.h" #include "webrtc_peer_connection.h" -class WebRTCPeerConnectionGDNative : public WebRTCPeerConnection { - GDCLASS(WebRTCPeerConnectionGDNative, WebRTCPeerConnection); +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language.h" +#include "core/variant/native_ptr.h" + +class WebRTCPeerConnectionExtension : public WebRTCPeerConnection { + GDCLASS(WebRTCPeerConnectionExtension, WebRTCPeerConnection); protected: static void _bind_methods(); - static WebRTCPeerConnection *_create(); - -private: - static const godot_net_webrtc_library *default_library; - const godot_net_webrtc_peer_connection *interface; public: - static Error set_default_library(const godot_net_webrtc_library *p_library); - static void make_default() { WebRTCPeerConnection::_create = WebRTCPeerConnectionGDNative::_create; } - - void set_native_webrtc_peer_connection(const godot_net_webrtc_peer_connection *p_impl); + void make_default(); virtual ConnectionState get_connection_state() const override; @@ -60,14 +53,22 @@ public: virtual Error create_offer() override; virtual Error set_remote_description(String type, String sdp) override; virtual Error set_local_description(String type, String sdp) override; - virtual Error add_ice_candidate(String sdpMidName, int sdpMlineIndexName, String sdpName) override; + virtual Error add_ice_candidate(String p_sdp_mid_name, int p_sdp_mline_index, String p_sdp_name) override; virtual Error poll() override; virtual void close() override; - WebRTCPeerConnectionGDNative(); - ~WebRTCPeerConnectionGDNative(); -}; + /** GDExtension **/ + GDVIRTUAL0RC(int, _get_connection_state); + GDVIRTUAL1R(int, _initialize, Dictionary); + GDVIRTUAL2R(Object *, _create_data_channel, String, Dictionary); + GDVIRTUAL0R(int, _create_offer); + GDVIRTUAL2R(int, _set_remote_description, String, String); + GDVIRTUAL2R(int, _set_local_description, String, String); + GDVIRTUAL3R(int, _add_ice_candidate, String, int, String); + GDVIRTUAL0R(int, _poll); + GDVIRTUAL0(_close); -#endif // WEBRTC_GDNATIVE_ENABLED + WebRTCPeerConnectionExtension() {} +}; -#endif // WEBRTC_PEER_CONNECTION_GDNATIVE_H +#endif // WEBRTC_PEER_CONNECTION_EXTENSION_H diff --git a/modules/webrtc/webrtc_peer_connection_gdnative.cpp b/modules/webrtc/webrtc_peer_connection_gdnative.cpp deleted file mode 100644 index dcf78dfb73..0000000000 --- a/modules/webrtc/webrtc_peer_connection_gdnative.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/*************************************************************************/ -/* webrtc_peer_connection_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifdef WEBRTC_GDNATIVE_ENABLED - -#include "webrtc_peer_connection_gdnative.h" - -#include "core/io/resource_loader.h" -#include "modules/gdnative/nativescript/nativescript.h" -#include "webrtc_data_channel_gdnative.h" - -const godot_net_webrtc_library *WebRTCPeerConnectionGDNative::default_library = nullptr; - -Error WebRTCPeerConnectionGDNative::set_default_library(const godot_net_webrtc_library *p_lib) { - if (default_library) { - const godot_net_webrtc_library *old = default_library; - default_library = nullptr; - old->unregistered(); - } - default_library = p_lib; - return OK; // Maybe add version check and fail accordingly -} - -WebRTCPeerConnection *WebRTCPeerConnectionGDNative::_create() { - WebRTCPeerConnectionGDNative *obj = memnew(WebRTCPeerConnectionGDNative); - ERR_FAIL_COND_V_MSG(!default_library, obj, "Default GDNative WebRTC implementation not defined."); - - // Call GDNative constructor - Error err = (Error)default_library->create_peer_connection(obj); - ERR_FAIL_COND_V_MSG(err != OK, obj, "GDNative default library constructor returned an error."); - - return obj; -} - -void WebRTCPeerConnectionGDNative::_bind_methods() { -} - -WebRTCPeerConnectionGDNative::WebRTCPeerConnectionGDNative() { - interface = nullptr; -} - -WebRTCPeerConnectionGDNative::~WebRTCPeerConnectionGDNative() { -} - -Error WebRTCPeerConnectionGDNative::initialize(Dictionary p_config) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->initialize(interface->data, (const godot_dictionary *)&p_config); -} - -Ref<WebRTCDataChannel> WebRTCPeerConnectionGDNative::create_data_channel(String p_label, Dictionary p_options) { - ERR_FAIL_COND_V(interface == nullptr, nullptr); - return (WebRTCDataChannel *)interface->create_data_channel(interface->data, p_label.utf8().get_data(), (const godot_dictionary *)&p_options); -} - -Error WebRTCPeerConnectionGDNative::create_offer() { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->create_offer(interface->data); -} - -Error WebRTCPeerConnectionGDNative::set_local_description(String p_type, String p_sdp) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->set_local_description(interface->data, p_type.utf8().get_data(), p_sdp.utf8().get_data()); -} - -Error WebRTCPeerConnectionGDNative::set_remote_description(String p_type, String p_sdp) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->set_remote_description(interface->data, p_type.utf8().get_data(), p_sdp.utf8().get_data()); -} - -Error WebRTCPeerConnectionGDNative::add_ice_candidate(String sdpMidName, int sdpMlineIndexName, String sdpName) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->add_ice_candidate(interface->data, sdpMidName.utf8().get_data(), sdpMlineIndexName, sdpName.utf8().get_data()); -} - -Error WebRTCPeerConnectionGDNative::poll() { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->poll(interface->data); -} - -void WebRTCPeerConnectionGDNative::close() { - ERR_FAIL_COND(interface == nullptr); - interface->close(interface->data); -} - -WebRTCPeerConnection::ConnectionState WebRTCPeerConnectionGDNative::get_connection_state() const { - ERR_FAIL_COND_V(interface == nullptr, STATE_DISCONNECTED); - return (ConnectionState)interface->get_connection_state(interface->data); -} - -void WebRTCPeerConnectionGDNative::set_native_webrtc_peer_connection(const godot_net_webrtc_peer_connection *p_impl) { - interface = p_impl; -} - -#endif // WEBRTC_GDNATIVE_ENABLED diff --git a/modules/webrtc/webrtc_peer_connection_js.h b/modules/webrtc/webrtc_peer_connection_js.h index 0272e67f6f..d2beccaf03 100644 --- a/modules/webrtc/webrtc_peer_connection_js.h +++ b/modules/webrtc/webrtc_peer_connection_js.h @@ -63,9 +63,6 @@ private: static void _on_error(void *p_obj); public: - static WebRTCPeerConnection *_create() { return memnew(WebRTCPeerConnectionJS); } - static void make_default() { WebRTCPeerConnection::_create = WebRTCPeerConnectionJS::_create; } - virtual ConnectionState get_connection_state() const; virtual Error initialize(Dictionary configuration = Dictionary()); diff --git a/modules/websocket/doc_classes/WebSocketClient.xml b/modules/websocket/doc_classes/WebSocketClient.xml index ed8f3ba867..4b515c12a1 100644 --- a/modules/websocket/doc_classes/WebSocketClient.xml +++ b/modules/websocket/doc_classes/WebSocketClient.xml @@ -8,6 +8,7 @@ This client can be optionally used as a multiplayer peer for the [MultiplayerAPI]. After starting the client ([method connect_to_url]), you will need to [method MultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). You will receive appropriate signals when connecting, disconnecting, or when new data is available. + [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> </tutorials> diff --git a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml index bf35acbd11..8d8ab220e2 100644 --- a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml +++ b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml @@ -5,6 +5,7 @@ </brief_description> <description> Base class for WebSocket server and client, allowing them to be used as multiplayer peer for the [MultiplayerAPI]. + [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> </tutorials> @@ -30,10 +31,6 @@ </description> </method> </methods> - <members> - <member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" /> - <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="TransferMode" default="2" /> - </members> <signals> <signal name="peer_packet"> <argument index="0" name="peer_source" type="int" /> diff --git a/modules/websocket/doc_classes/WebSocketServer.xml b/modules/websocket/doc_classes/WebSocketServer.xml index 2bb705b384..f901b089ea 100644 --- a/modules/websocket/doc_classes/WebSocketServer.xml +++ b/modules/websocket/doc_classes/WebSocketServer.xml @@ -7,6 +7,7 @@ This class implements a WebSocket server that can also support the high-level multiplayer API. After starting the server ([method listen]), you will need to [method MultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). When clients connect, disconnect, or send data, you will receive the appropriate signal. [b]Note:[/b] Not available in HTML5 exports. + [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> </tutorials> diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp index 7464cf2bf5..3a27855a5e 100644 --- a/modules/websocket/websocket_multiplayer_peer.cpp +++ b/modules/websocket/websocket_multiplayer_peer.cpp @@ -105,23 +105,6 @@ Error WebSocketMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer // // MultiplayerPeer // -void WebSocketMultiplayerPeer::set_transfer_channel(int p_channel) { - // Websocket does not have channels. -} - -int WebSocketMultiplayerPeer::get_transfer_channel() const { - return 0; -} - -void WebSocketMultiplayerPeer::set_transfer_mode(Multiplayer::TransferMode p_mode) { - // Websocket uses TCP, reliable -} - -Multiplayer::TransferMode WebSocketMultiplayerPeer::get_transfer_mode() const { - // Websocket uses TCP, reliable - return Multiplayer::TRANSFER_MODE_RELIABLE; -} - void WebSocketMultiplayerPeer::set_target_peer(int p_target_peer) { _target_peer = p_target_peer; } @@ -137,14 +120,6 @@ int WebSocketMultiplayerPeer::get_unique_id() const { return _peer_id; } -void WebSocketMultiplayerPeer::set_refuse_new_connections(bool p_enable) { - _refusing = p_enable; -} - -bool WebSocketMultiplayerPeer::is_refusing_new_connections() const { - return _refusing; -} - void WebSocketMultiplayerPeer::_send_sys(Ref<WebSocketPeer> p_peer, uint8_t p_type, int32_t p_peer_id) { ERR_FAIL_COND(!p_peer.is_valid()); ERR_FAIL_COND(!p_peer->is_connected_to_host()); diff --git a/modules/websocket/websocket_multiplayer_peer.h b/modules/websocket/websocket_multiplayer_peer.h index d97a599fe9..380edf67ed 100644 --- a/modules/websocket/websocket_multiplayer_peer.h +++ b/modules/websocket/websocket_multiplayer_peer.h @@ -68,7 +68,6 @@ protected: bool _is_multiplayer = false; int _target_peer = 0; int _peer_id = 0; - int _refusing = false; static void _bind_methods(); @@ -78,15 +77,9 @@ protected: public: /* MultiplayerPeer */ - void set_transfer_channel(int p_channel) override; - int get_transfer_channel() const override; - void set_transfer_mode(Multiplayer::TransferMode p_mode) override; - Multiplayer::TransferMode get_transfer_mode() const override; void set_target_peer(int p_target_peer) override; int get_packet_peer() const override; int get_unique_id() const override; - void set_refuse_new_connections(bool p_enable) override; - bool is_refusing_new_connections() const override; /* PacketPeer */ virtual int get_available_packet_count() const override; diff --git a/modules/webxr/register_types.cpp b/modules/webxr/register_types.cpp index 078a6547cf..16b483c39e 100644 --- a/modules/webxr/register_types.cpp +++ b/modules/webxr/register_types.cpp @@ -33,15 +33,34 @@ #include "webxr_interface.h" #include "webxr_interface_js.h" +#ifdef JAVASCRIPT_ENABLED +Ref<WebXRInterfaceJS> webxr; +#endif + void register_webxr_types() { GDREGISTER_VIRTUAL_CLASS(WebXRInterface); #ifdef JAVASCRIPT_ENABLED - Ref<WebXRInterfaceJS> webxr; webxr.instantiate(); XRServer::get_singleton()->add_interface(webxr); #endif } void unregister_webxr_types() { +#ifdef JAVASCRIPT_ENABLED + if (webxr.is_valid()) { + // uninitialise our interface if it is initialised + if (webxr->is_initialized()) { + webxr->uninitialize(); + } + + // unregister our interface from the XR server + if (XRServer::get_singleton()) { + XRServer::get_singleton()->remove_interface(webxr); + } + + // and release + webxr.unref(); + } +#endif } |