diff options
Diffstat (limited to 'modules')
176 files changed, 1581 insertions, 1060 deletions
diff --git a/modules/basis_universal/register_types.cpp b/modules/basis_universal/register_types.cpp index 23639a4f2f..9a13406900 100644 --- a/modules/basis_universal/register_types.cpp +++ b/modules/basis_universal/register_types.cpp @@ -272,7 +272,7 @@ void register_basis_universal_types() { Image::basis_universal_packer = basis_universal_packer; #endif Image::basis_universal_unpacker = basis_universal_unpacker; - //ClassDB::register_class<TextureBasisU>(); + //GDREGISTER_CLASS(TextureBasisU); } void unregister_basis_universal_types() { diff --git a/modules/bullet/godot_result_callbacks.cpp b/modules/bullet/godot_result_callbacks.cpp index e92b6c189c..1fd656c9b4 100644 --- a/modules/bullet/godot_result_callbacks.cpp +++ b/modules/bullet/godot_result_callbacks.cpp @@ -47,17 +47,12 @@ bool godotContactAddedCallback(btManifoldPoint &cp, const btCollisionObjectWrapp return true; } -bool GodotFilterCallback::test_collision_filters(uint32_t body0_collision_layer, uint32_t body0_collision_mask, uint32_t body1_collision_layer, uint32_t body1_collision_mask) { - return body0_collision_layer & body1_collision_mask || body1_collision_layer & body0_collision_mask; -} - bool GodotFilterCallback::needBroadphaseCollision(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1) const { - return GodotFilterCallback::test_collision_filters(proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask, proxy1->m_collisionFilterGroup, proxy1->m_collisionFilterMask); + return (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) || (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask); } bool GodotClosestRayResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { - const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); - if (needs) { + if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); @@ -90,8 +85,7 @@ bool GodotAllConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) con return false; } - const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); - if (needs) { + if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); if (m_exclude->has(gObj->get_self())) { @@ -123,8 +117,7 @@ btScalar GodotAllConvexResultCallback::addSingleResult(btCollisionWorld::LocalCo } bool GodotKinClosestConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { - const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); - if (needs) { + if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); if (gObj == m_self_object) { @@ -150,8 +143,7 @@ bool GodotKinClosestConvexResultCallback::needsCollision(btBroadphaseProxy *prox } bool GodotClosestConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { - const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); - if (needs) { + if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); @@ -188,8 +180,7 @@ bool GodotAllContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) co return false; } - const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); - if (needs) { + if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); @@ -244,8 +235,7 @@ bool GodotContactPairContactResultCallback::needsCollision(btBroadphaseProxy *pr return false; } - const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); - if (needs) { + if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); @@ -287,8 +277,7 @@ btScalar GodotContactPairContactResultCallback::addSingleResult(btManifoldPoint } bool GodotRestInfoContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { - const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); - if (needs) { + if (m_collisionFilterGroup & proxy0->m_collisionFilterMask) { btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); diff --git a/modules/bullet/godot_result_callbacks.h b/modules/bullet/godot_result_callbacks.h index f92665f3e4..9216322108 100644 --- a/modules/bullet/godot_result_callbacks.h +++ b/modules/bullet/godot_result_callbacks.h @@ -47,8 +47,6 @@ bool godotContactAddedCallback(btManifoldPoint &cp, const btCollisionObjectWrapp /// This class is required to implement custom collision behaviour in the broadphase struct GodotFilterCallback : public btOverlapFilterCallback { - static bool test_collision_filters(uint32_t body0_collision_layer, uint32_t body0_collision_mask, uint32_t body1_collision_layer, uint32_t body1_collision_mask); - // return true when pairs need collision virtual bool needBroadphaseCollision(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1) const; }; diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index 33dd9ef56d..8c286a8629 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -1093,7 +1093,6 @@ private: const btCollisionObject *self_collision_object; uint32_t collision_layer = 0; - uint32_t collision_mask = 0; struct CompoundLeafCallback : btDbvt::ICollide { private: @@ -1123,10 +1122,9 @@ public: Vector<BroadphaseResult> results; public: - RecoverPenetrationBroadPhaseCallback(const btCollisionObject *p_self_collision_object, uint32_t p_collision_layer, uint32_t p_collision_mask, btVector3 p_aabb_min, btVector3 p_aabb_max) : + RecoverPenetrationBroadPhaseCallback(const btCollisionObject *p_self_collision_object, uint32_t p_collision_layer, btVector3 p_aabb_min, btVector3 p_aabb_max) : self_collision_object(p_self_collision_object), - collision_layer(p_collision_layer), - collision_mask(p_collision_mask) { + collision_layer(p_collision_layer) { bounds = btDbvtVolume::FromMM(p_aabb_min, p_aabb_max); } @@ -1135,7 +1133,7 @@ public: virtual bool process(const btBroadphaseProxy *proxy) { btCollisionObject *co = static_cast<btCollisionObject *>(proxy->m_clientObject); if (co->getInternalType() <= btCollisionObject::CO_RIGID_BODY) { - if (self_collision_object != proxy->m_clientObject && GodotFilterCallback::test_collision_filters(collision_layer, collision_mask, proxy->m_collisionFilterGroup, proxy->m_collisionFilterMask)) { + if (self_collision_object != proxy->m_clientObject && (collision_layer & proxy->m_collisionFilterMask)) { if (co->getCollisionShape()->isCompound()) { const btCompoundShape *cs = static_cast<btCompoundShape *>(co->getCollisionShape()); @@ -1218,7 +1216,7 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran } // Perform broadphase test - RecoverPenetrationBroadPhaseCallback recover_broad_result(p_body->get_bt_collision_object(), p_body->get_collision_layer(), p_body->get_collision_mask(), aabb_min, aabb_max); + RecoverPenetrationBroadPhaseCallback recover_broad_result(p_body->get_bt_collision_object(), p_body->get_collision_layer(), aabb_min, aabb_max); dynamicsWorld->getBroadphase()->aabbTest(aabb_min, aabb_max, recover_broad_result); bool penetration = false; @@ -1409,7 +1407,7 @@ int SpaceBullet::recover_from_penetration_ray(RigidBodyBullet *p_body, const btT } // Perform broadphase test - RecoverPenetrationBroadPhaseCallback recover_broad_result(p_body->get_bt_collision_object(), p_body->get_collision_layer(), p_body->get_collision_mask(), aabb_min, aabb_max); + RecoverPenetrationBroadPhaseCallback recover_broad_result(p_body->get_bt_collision_object(), p_body->get_collision_layer(), aabb_min, aabb_max); dynamicsWorld->getBroadphase()->aabbTest(aabb_min, aabb_max, recover_broad_result); int ray_count = 0; diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp index 5a37486568..57206ae18b 100644 --- a/modules/csg/csg.cpp +++ b/modules/csg/csg.cpp @@ -42,7 +42,7 @@ inline static bool is_snapable(const Vector3 &p_point1, const Vector3 &p_point2, 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 (segment_length < CMP_EPSILON) { + if (p_segement_points[0].is_equal_approx(p_segement_points[1])) { return p_uvs[0]; } @@ -53,13 +53,13 @@ inline static Vector2 interpolate_segment_uv(const Vector2 p_segement_points[2], } inline static Vector2 interpolate_triangle_uv(const Vector2 p_vertices[3], const Vector2 p_uvs[3], const Vector2 &p_interpolation_point) { - if (p_interpolation_point.distance_squared_to(p_vertices[0]) < CMP_EPSILON2) { + if (p_interpolation_point.is_equal_approx(p_vertices[0])) { return p_uvs[0]; } - if (p_interpolation_point.distance_squared_to(p_vertices[1]) < CMP_EPSILON2) { + if (p_interpolation_point.is_equal_approx(p_vertices[1])) { return p_uvs[1]; } - if (p_interpolation_point.distance_squared_to(p_vertices[2]) < CMP_EPSILON2) { + if (p_interpolation_point.is_equal_approx(p_vertices[2])) { return p_uvs[2]; } @@ -589,7 +589,7 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de Vector3 intersection_point; // Check if faces are co-planar. - if ((current_normal - face_normal).length_squared() < CMP_EPSILON2 && + if (current_normal.is_equal_approx(face_normal) && is_point_in_triangle(face_center, current_points)) { // Only add an intersection if not a B face. if (!face.from_b) { diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp index 6b0c2604e3..729dc2f8fc 100644 --- a/modules/csg/csg_shape.cpp +++ b/modules/csg/csg_shape.cpp @@ -140,7 +140,7 @@ void CSGShape3D::_make_dirty() { if (parent) { parent->_make_dirty(); } else if (!dirty) { - call_deferred("_update_shape"); + call_deferred(SNAME("_update_shape")); } dirty = true; @@ -778,7 +778,7 @@ CSGBrush *CSGMesh3D::_build_brush() { } } - bool flat = normal[0].distance_to(normal[1]) < CMP_EPSILON && normal[0].distance_to(normal[2]) < CMP_EPSILON; + bool flat = normal[0].is_equal_approx(normal[1]) && normal[0].is_equal_approx(normal[2]); vw[as + j + 0] = vertex[0]; vw[as + j + 1] = vertex[1]; @@ -820,7 +820,7 @@ CSGBrush *CSGMesh3D::_build_brush() { } } - bool flat = normal[0].distance_to(normal[1]) < CMP_EPSILON && normal[0].distance_to(normal[2]) < CMP_EPSILON; + bool flat = normal[0].is_equal_approx(normal[1]) && normal[0].is_equal_approx(normal[2]); vw[as + j + 0] = vertex[0]; vw[as + j + 1] = vertex[1]; @@ -868,7 +868,7 @@ void CSGMesh3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_material"), &CSGMesh3D::get_material); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "StandardMaterial3D,ShaderMaterial"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); } void CSGMesh3D::set_mesh(const Ref<Mesh> &p_mesh) { @@ -1027,7 +1027,7 @@ void CSGSphere3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "radial_segments", PROPERTY_HINT_RANGE, "1,100,1"), "set_radial_segments", "get_radial_segments"); ADD_PROPERTY(PropertyInfo(Variant::INT, "rings", PROPERTY_HINT_RANGE, "1,100,1"), "set_rings", "get_rings"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "StandardMaterial3D,ShaderMaterial"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); } void CSGSphere3D::set_radius(const float p_radius) { @@ -1197,7 +1197,7 @@ void CSGBox3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_material"), &CSGBox3D::get_material); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "size"), "set_size", "get_size"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "StandardMaterial3D,ShaderMaterial"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); } void CSGBox3D::set_size(const Vector3 &p_size) { @@ -1373,12 +1373,12 @@ void CSGCylinder3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_smooth_faces", "smooth_faces"), &CSGCylinder3D::set_smooth_faces); ClassDB::bind_method(D_METHOD("get_smooth_faces"), &CSGCylinder3D::get_smooth_faces); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_radius", "get_radius"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_height", "get_height"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_radius", "get_radius"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_height", "get_height"); ADD_PROPERTY(PropertyInfo(Variant::INT, "sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_sides", "get_sides"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cone"), "set_cone", "is_cone"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "StandardMaterial3D,ShaderMaterial"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); } void CSGCylinder3D::set_radius(const float p_radius) { @@ -1592,12 +1592,12 @@ void CSGTorus3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_smooth_faces", "smooth_faces"), &CSGTorus3D::set_smooth_faces); ClassDB::bind_method(D_METHOD("get_smooth_faces"), &CSGTorus3D::get_smooth_faces); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inner_radius", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_inner_radius", "get_inner_radius"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "outer_radius", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_outer_radius", "get_outer_radius"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inner_radius", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_inner_radius", "get_inner_radius"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "outer_radius", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_outer_radius", "get_outer_radius"); ADD_PROPERTY(PropertyInfo(Variant::INT, "sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_sides", "get_sides"); ADD_PROPERTY(PropertyInfo(Variant::INT, "ring_sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_ring_sides", "get_ring_sides"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "StandardMaterial3D,ShaderMaterial"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); } void CSGTorus3D::set_inner_radius(const float p_inner_radius) { @@ -2158,13 +2158,13 @@ void CSGPolygon3D::_notification(int p_what) { void CSGPolygon3D::_validate_property(PropertyInfo &property) const { if (property.name.begins_with("spin") && mode != MODE_SPIN) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name.begins_with("path") && mode != MODE_PATH) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } if (property.name == "depth" && mode != MODE_DEPTH) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } CSGShape3D::_validate_property(property); @@ -2224,17 +2224,17 @@ void CSGPolygon3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon"); ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Depth,Spin,Path"), "set_mode", "get_mode"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_depth", "get_depth"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_depth", "get_depth"); 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_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_path_interval", "get_path_interval"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_interval", PROPERTY_HINT_RANGE, "0.001,1000.0,0.001,or_greater,exp"), "set_path_interval", "get_path_interval"); 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::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, "StandardMaterial3D,ShaderMaterial"), "set_material", "get_material"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); BIND_ENUM_CONSTANT(MODE_DEPTH); BIND_ENUM_CONSTANT(MODE_SPIN); diff --git a/modules/csg/register_types.cpp b/modules/csg/register_types.cpp index e28f44d1eb..a47390c2b2 100644 --- a/modules/csg/register_types.cpp +++ b/modules/csg/register_types.cpp @@ -36,15 +36,15 @@ void register_csg_types() { #ifndef _3D_DISABLED - ClassDB::register_virtual_class<CSGShape3D>(); - ClassDB::register_virtual_class<CSGPrimitive3D>(); - ClassDB::register_class<CSGMesh3D>(); - ClassDB::register_class<CSGSphere3D>(); - ClassDB::register_class<CSGBox3D>(); - ClassDB::register_class<CSGCylinder3D>(); - ClassDB::register_class<CSGTorus3D>(); - ClassDB::register_class<CSGPolygon3D>(); - ClassDB::register_class<CSGCombiner3D>(); + GDREGISTER_VIRTUAL_CLASS(CSGShape3D); + GDREGISTER_VIRTUAL_CLASS(CSGPrimitive3D); + GDREGISTER_CLASS(CSGMesh3D); + GDREGISTER_CLASS(CSGSphere3D); + GDREGISTER_CLASS(CSGBox3D); + GDREGISTER_CLASS(CSGCylinder3D); + GDREGISTER_CLASS(CSGTorus3D); + GDREGISTER_CLASS(CSGPolygon3D); + GDREGISTER_CLASS(CSGCombiner3D); #ifdef TOOLS_ENABLED EditorPlugins::add_by_type<EditorPluginCSG>(); diff --git a/modules/enet/config.py b/modules/enet/config.py index 5fd343c75d..3662b2d94e 100644 --- a/modules/enet/config.py +++ b/modules/enet/config.py @@ -8,7 +8,7 @@ def configure(env): def get_doc_classes(): return [ - "NetworkedMultiplayerENet", + "ENetMultiplayerPeer", ] diff --git a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml b/modules/enet/doc_classes/ENetMultiplayerPeer.xml index 271cb03c9f..30dec5987b 100644 --- a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml +++ b/modules/enet/doc_classes/ENetMultiplayerPeer.xml @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="NetworkedMultiplayerENet" inherits="NetworkedMultiplayerPeer" version="4.0"> +<class name="ENetMultiplayerPeer" inherits="MultiplayerPeer" version="4.0"> <brief_description> PacketPeer implementation using the [url=http://enet.bespin.org/index.html]ENet[/url] library. </brief_description> <description> - A PacketPeer implementation that should be passed to [member SceneTree.network_peer] after being initialized as either a client or server. Events can then be handled by connecting to [SceneTree] signals. + A PacketPeer implementation that should be passed to [member MultiplayerAPI.network_peer] after being initialized as either a client or server. Events can then be handled by connecting to [SceneTree] signals. ENet's purpose is to provide a relatively thin, simple and robust network communication layer on top of UDP (User Datagram Protocol). [b]Note:[/b] ENet only uses UDP, not TCP. When forwarding the server port to make your server accessible on the public Internet, you only need to forward the server port in UDP. You can use the [UPNP] class to try to forward the server port automatically when starting the server. </description> @@ -36,7 +36,7 @@ <argument index="4" name="local_port" type="int" default="0"> </argument> <description> - Create client that connects to a server at [code]address[/code] using specified [code]port[/code]. The given address needs to be either a fully qualified domain name (e.g. [code]"www.example.com"[/code]) or an IP address in IPv4 or IPv6 format (e.g. [code]"192.168.1.1"[/code]). The [code]port[/code] is the port the server is listening on. The [code]in_bandwidth[/code] and [code]out_bandwidth[/code] parameters can be used to limit the incoming and outgoing bandwidth to the given number of bytes per second. The default of 0 means unlimited bandwidth. Note that ENet will strategically drop packets on specific sides of a connection between peers to ensure the peer's bandwidth is not overwhelmed. The bandwidth parameters also determine the window size of a connection which limits the amount of reliable packets that may be in transit at any given time. Returns [constant OK] if a client was created, [constant ERR_ALREADY_IN_USE] if this NetworkedMultiplayerENet instance already has an open connection (in which case you need to call [method close_connection] first) or [constant ERR_CANT_CREATE] if the client could not be created. If [code]local_port[/code] is specified, the client will also listen to the given port; this is useful for some NAT traversal techniques. + Create client that connects to a server at [code]address[/code] using specified [code]port[/code]. The given address needs to be either a fully qualified domain name (e.g. [code]"www.example.com"[/code]) or an IP address in IPv4 or IPv6 format (e.g. [code]"192.168.1.1"[/code]). The [code]port[/code] is the port the server is listening on. The [code]in_bandwidth[/code] and [code]out_bandwidth[/code] parameters can be used to limit the incoming and outgoing bandwidth to the given number of bytes per second. The default of 0 means unlimited bandwidth. Note that ENet will strategically drop packets on specific sides of a connection between peers to ensure the peer's bandwidth is not overwhelmed. The bandwidth parameters also determine the window size of a connection which limits the amount of reliable packets that may be in transit at any given time. Returns [constant OK] if a client was created, [constant ERR_ALREADY_IN_USE] if this ENetMultiplayerPeer instance already has an open connection (in which case you need to call [method close_connection] first) or [constant ERR_CANT_CREATE] if the client could not be created. If [code]local_port[/code] is specified, the client will also listen to the given port; this is useful for some NAT traversal techniques. </description> </method> <method name="create_server"> @@ -51,7 +51,7 @@ <argument index="3" name="out_bandwidth" type="int" default="0"> </argument> <description> - Create server that listens to connections via [code]port[/code]. The port needs to be an available, unused port between 0 and 65535. Note that ports below 1024 are privileged and may require elevated permissions depending on the platform. To change the interface the server listens on, use [method set_bind_ip]. The default IP is the wildcard [code]"*"[/code], which listens on all available interfaces. [code]max_clients[/code] is the maximum number of clients that are allowed at once, any number up to 4095 may be used, although the achievable number of simultaneous clients may be far lower and depends on the application. For additional details on the bandwidth parameters, see [method create_client]. Returns [constant OK] if a server was created, [constant ERR_ALREADY_IN_USE] if this NetworkedMultiplayerENet instance already has an open connection (in which case you need to call [method close_connection] first) or [constant ERR_CANT_CREATE] if the server could not be created. + Create server that listens to connections via [code]port[/code]. The port needs to be an available, unused port between 0 and 65535. Note that ports below 1024 are privileged and may require elevated permissions depending on the platform. To change the interface the server listens on, use [method set_bind_ip]. The default IP is the wildcard [code]"*"[/code], which listens on all available interfaces. [code]max_clients[/code] is the maximum number of clients that are allowed at once, any number up to 4095 may be used, although the achievable number of simultaneous clients may be far lower and depends on the application. For additional details on the bandwidth parameters, see [method create_client]. Returns [constant OK] if a server was created, [constant ERR_ALREADY_IN_USE] if this ENetMultiplayerPeer instance already has an open connection (in which case you need to call [method close_connection] first) or [constant ERR_CANT_CREATE] if the server could not be created. </description> </method> <method name="disconnect_peer"> @@ -150,13 +150,14 @@ </methods> <members> <member name="always_ordered" type="bool" setter="set_always_ordered" getter="is_always_ordered" default="false"> - Enforce ordered packets when using [constant NetworkedMultiplayerPeer.TRANSFER_MODE_UNRELIABLE] (thus behaving similarly to [constant NetworkedMultiplayerPeer.TRANSFER_MODE_UNRELIABLE_ORDERED]). This is the only way to use ordering with the RPC system. + Enforce ordered packets when using [constant MultiplayerPeer.TRANSFER_MODE_UNRELIABLE] (thus behaving similarly to [constant MultiplayerPeer.TRANSFER_MODE_UNRELIABLE_ORDERED]). This is the only way to use ordering with the RPC system. </member> <member name="channel_count" type="int" setter="set_channel_count" getter="get_channel_count" default="3"> The number of channels to be used by ENet. Channels are used to separate different kinds of data. In reliable or ordered mode, for example, the packet delivery order is ensured on a per-channel basis. This is done to combat latency and reduces ordering restrictions on packets. The delivery status of a packet in one channel won't stall the delivery of other packets in another channel. </member> - <member name="compression_mode" type="int" setter="set_compression_mode" getter="get_compression_mode" enum="NetworkedMultiplayerENet.CompressionMode" default="0"> + <member name="compression_mode" type="int" setter="set_compression_mode" getter="get_compression_mode" enum="ENetMultiplayerPeer.CompressionMode" default="1"> The compression method used for network packets. These have different tradeoffs of compression speed versus bandwidth, you may need to test which one works best for your use case if you use compression at all. + [b]Note:[/b] Most games' network design involve sending many small packets frequently (smaller than 4 KB each). If in doubt, it is recommended to keep the default compression algorithm as it works best on these small packets. </member> <member name="dtls_verify" type="bool" setter="set_dtls_verify_enabled" getter="is_dtls_verify_enabled" default="true"> Enable or disable certificate verification when [member use_dtls] [code]true[/code]. @@ -168,7 +169,7 @@ <member name="transfer_channel" type="int" setter="set_transfer_channel" getter="get_transfer_channel" default="-1"> Set the default channel to be used to transfer data. By default, this value is [code]-1[/code] which means that ENet will only use 2 channels: one for reliable packets, and one for unreliable packets. The channel [code]0[/code] is reserved and cannot be used. Setting this member to any value between [code]0[/code] and [member channel_count] (excluded) will force ENet to use that channel for sending data. See [member channel_count] for more information about ENet channels. </member> - <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="NetworkedMultiplayerPeer.TransferMode" default="2" /> + <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="MultiplayerPeer.TransferMode" default="2" /> <member name="use_dtls" type="bool" setter="set_dtls_enabled" getter="is_dtls_enabled" default="false"> When enabled, the client or server created by this peer, will use [PacketPeerDTLS] instead of raw UDP sockets for communicating with the remote peer. This will make the communication encrypted with DTLS at the cost of higher resource usage and potentially larger packet size. Note: When creating a DTLS server, make sure you setup the key/certificate pair via [method set_dtls_key] and [method set_dtls_certificate]. For DTLS clients, have a look at the [member dtls_verify] option, and configure the certificate accordingly via [method set_dtls_certificate]. @@ -176,10 +177,10 @@ </members> <constants> <constant name="COMPRESS_NONE" value="0" enum="CompressionMode"> - No compression. This uses the most bandwidth, but has the upside of requiring the fewest CPU resources. + No compression. This uses the most bandwidth, but has the upside of requiring the fewest CPU resources. This option may also be used to make network debugging using tools like Wireshark easier. </constant> <constant name="COMPRESS_RANGE_CODER" value="1" enum="CompressionMode"> - ENet's built-in range encoding. + ENet's built-in range encoding. Works well on small packets, but is not the most efficient algorithm on packets larger than 4 KB. </constant> <constant name="COMPRESS_FASTLZ" value="2" enum="CompressionMode"> [url=http://fastlz.org/]FastLZ[/url] compression. This option uses less CPU resources compared to [constant COMPRESS_ZLIB], at the expense of using more bandwidth. @@ -188,7 +189,7 @@ [url=https://www.zlib.net/]Zlib[/url] compression. This option uses less bandwidth compared to [constant COMPRESS_FASTLZ], at the expense of using more CPU resources. </constant> <constant name="COMPRESS_ZSTD" value="4" enum="CompressionMode"> - [url=https://facebook.github.io/zstd/]Zstandard[/url] compression. + [url=https://facebook.github.io/zstd/]Zstandard[/url] compression. Note that this algorithm is not very efficient on packets smaller than 4 KB. Therefore, it's recommended to use other compression algorithms in most cases. </constant> </constants> </class> diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/enet_multiplayer_peer.cpp index 94260e8c13..b4ca93f4d9 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/enet_multiplayer_peer.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* networked_multiplayer_enet.cpp */ +/* enet_multiplayer_peer.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,45 +28,45 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "networked_multiplayer_enet.h" +#include "enet_multiplayer_peer.h" #include "core/io/ip.h" #include "core/io/marshalls.h" #include "core/os/os.h" -void NetworkedMultiplayerENet::set_transfer_mode(TransferMode p_mode) { +void ENetMultiplayerPeer::set_transfer_mode(TransferMode p_mode) { transfer_mode = p_mode; } -NetworkedMultiplayerPeer::TransferMode NetworkedMultiplayerENet::get_transfer_mode() const { +MultiplayerPeer::TransferMode ENetMultiplayerPeer::get_transfer_mode() const { return transfer_mode; } -void NetworkedMultiplayerENet::set_target_peer(int p_peer) { +void ENetMultiplayerPeer::set_target_peer(int p_peer) { target_peer = p_peer; } -int NetworkedMultiplayerENet::get_packet_peer() const { +int ENetMultiplayerPeer::get_packet_peer() const { ERR_FAIL_COND_V_MSG(!active, 1, "The multiplayer instance isn't currently active."); ERR_FAIL_COND_V(incoming_packets.size() == 0, 1); return incoming_packets.front()->get().from; } -int NetworkedMultiplayerENet::get_packet_channel() const { +int ENetMultiplayerPeer::get_packet_channel() const { ERR_FAIL_COND_V_MSG(!active, -1, "The multiplayer instance isn't currently active."); ERR_FAIL_COND_V(incoming_packets.size() == 0, -1); return incoming_packets.front()->get().channel; } -int NetworkedMultiplayerENet::get_last_packet_channel() const { +int ENetMultiplayerPeer::get_last_packet_channel() const { ERR_FAIL_COND_V_MSG(!active, -1, "The multiplayer instance isn't currently active."); ERR_FAIL_COND_V(!current_packet.packet, -1); return current_packet.channel; } -Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int p_in_bandwidth, int p_out_bandwidth) { +Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_in_bandwidth, int p_out_bandwidth) { ERR_FAIL_COND_V_MSG(active, ERR_ALREADY_IN_USE, "The multiplayer instance is already active."); ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); ERR_FAIL_COND_V_MSG(p_max_clients < 1 || p_max_clients > 4095, ERR_INVALID_PARAMETER, "The number of clients must be set between 1 and 4095 (inclusive)."); @@ -115,7 +115,7 @@ Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int connection_status = CONNECTION_CONNECTED; return OK; } -Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_port, int p_in_bandwidth, int p_out_bandwidth, int p_local_port) { +Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, int p_in_bandwidth, int p_out_bandwidth, int p_local_port) { ERR_FAIL_COND_V_MSG(active, ERR_ALREADY_IN_USE, "The multiplayer instance is already active."); ERR_FAIL_COND_V_MSG(p_port < 1 || p_port > 65535, ERR_INVALID_PARAMETER, "The remote port number must be between 1 and 65535 (inclusive)."); ERR_FAIL_COND_V_MSG(p_local_port < 0 || p_local_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); @@ -199,7 +199,7 @@ Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_por return OK; } -void NetworkedMultiplayerENet::poll() { +void ENetMultiplayerPeer::poll() { ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active."); _pop_current_packet(); @@ -249,7 +249,7 @@ void NetworkedMultiplayerENet::poll() { connection_status = CONNECTION_CONNECTED; // If connecting, this means it connected to something! - emit_signal("peer_connected", *new_id); + emit_signal(SNAME("peer_connected"), *new_id); if (server) { // Do not notify other peers when server_relay is disabled. @@ -274,7 +274,7 @@ void NetworkedMultiplayerENet::poll() { enet_peer_send(E->get(), SYSCH_CONFIG, packet); } } else { - emit_signal("connection_succeeded"); + emit_signal(SNAME("connection_succeeded")); } } break; @@ -285,7 +285,7 @@ void NetworkedMultiplayerENet::poll() { if (!id) { if (!server) { - emit_signal("connection_failed"); + emit_signal(SNAME("connection_failed")); } // Never fully connected. break; @@ -293,7 +293,7 @@ void NetworkedMultiplayerENet::poll() { if (!server) { // Client just disconnected from server. - emit_signal("server_disconnected"); + emit_signal(SNAME("server_disconnected")); close_connection(); return; } else if (server_relay) { @@ -310,7 +310,7 @@ void NetworkedMultiplayerENet::poll() { } } - emit_signal("peer_disconnected", *id); + emit_signal(SNAME("peer_disconnected"), *id); peer_map.erase(*id); memdelete(id); } break; @@ -328,12 +328,12 @@ void NetworkedMultiplayerENet::poll() { switch (msg) { case SYSMSG_ADD_PEER: { peer_map[id] = nullptr; - emit_signal("peer_connected", id); + emit_signal(SNAME("peer_connected"), id); } break; case SYSMSG_REMOVE_PEER: { peer_map.erase(id); - emit_signal("peer_disconnected", id); + emit_signal(SNAME("peer_disconnected"), id); } break; } @@ -426,13 +426,13 @@ void NetworkedMultiplayerENet::poll() { } } -bool NetworkedMultiplayerENet::is_server() const { +bool ENetMultiplayerPeer::is_server() const { ERR_FAIL_COND_V_MSG(!active, false, "The multiplayer instance isn't currently active."); return server; } -void NetworkedMultiplayerENet::close_connection(uint32_t wait_usec) { +void ENetMultiplayerPeer::close_connection(uint32_t wait_usec) { ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active."); _pop_current_packet(); @@ -463,7 +463,7 @@ void NetworkedMultiplayerENet::close_connection(uint32_t wait_usec) { connection_status = CONNECTION_DISCONNECTED; } -void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) { +void ENetMultiplayerPeer::disconnect_peer(int p_peer, bool now) { ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active."); ERR_FAIL_COND_MSG(!is_server(), "Can't disconnect a peer when not acting as a server."); ERR_FAIL_COND_MSG(!peer_map.has(p_peer), vformat("Peer ID %d not found in the list of peers.", p_peer)); @@ -491,18 +491,18 @@ void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) { memdelete(id); } - emit_signal("peer_disconnected", p_peer); + emit_signal(SNAME("peer_disconnected"), p_peer); peer_map.erase(p_peer); } else { enet_peer_disconnect_later(peer_map[p_peer], 0); } } -int NetworkedMultiplayerENet::get_available_packet_count() const { +int ENetMultiplayerPeer::get_available_packet_count() const { return incoming_packets.size(); } -Error NetworkedMultiplayerENet::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { +Error ENetMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { ERR_FAIL_COND_V_MSG(incoming_packets.size() == 0, ERR_UNAVAILABLE, "No incoming packets available."); _pop_current_packet(); @@ -516,7 +516,7 @@ Error NetworkedMultiplayerENet::get_packet(const uint8_t **r_buffer, int &r_buff return OK; } -Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer_size) { +Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { ERR_FAIL_COND_V_MSG(!active, ERR_UNCONFIGURED, "The multiplayer instance isn't currently active."); ERR_FAIL_COND_V_MSG(connection_status != CONNECTION_CONNECTED, ERR_UNCONFIGURED, "The multiplayer instance isn't currently connected to any server or client."); @@ -591,11 +591,11 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer return OK; } -int NetworkedMultiplayerENet::get_max_packet_size() const { +int ENetMultiplayerPeer::get_max_packet_size() const { return 1 << 24; // Anything is good } -void NetworkedMultiplayerENet::_pop_current_packet() { +void ENetMultiplayerPeer::_pop_current_packet() { if (current_packet.packet) { enet_packet_destroy(current_packet.packet); current_packet.packet = nullptr; @@ -604,11 +604,11 @@ void NetworkedMultiplayerENet::_pop_current_packet() { } } -NetworkedMultiplayerPeer::ConnectionStatus NetworkedMultiplayerENet::get_connection_status() const { +MultiplayerPeer::ConnectionStatus ENetMultiplayerPeer::get_connection_status() const { return connection_status; } -uint32_t NetworkedMultiplayerENet::_gen_unique_id() const { +uint32_t ENetMultiplayerPeer::_gen_unique_id() const { uint32_t hash = 0; while (hash == 0 || hash == 1) { @@ -629,12 +629,12 @@ uint32_t NetworkedMultiplayerENet::_gen_unique_id() const { return hash; } -int NetworkedMultiplayerENet::get_unique_id() const { +int ENetMultiplayerPeer::get_unique_id() const { ERR_FAIL_COND_V_MSG(!active, 0, "The multiplayer instance isn't currently active."); return unique_id; } -void NetworkedMultiplayerENet::set_refuse_new_connections(bool p_enable) { +void ENetMultiplayerPeer::set_refuse_new_connections(bool p_enable) { refuse_connections = p_enable; #ifdef GODOT_ENET if (active) { @@ -643,20 +643,20 @@ void NetworkedMultiplayerENet::set_refuse_new_connections(bool p_enable) { #endif } -bool NetworkedMultiplayerENet::is_refusing_new_connections() const { +bool ENetMultiplayerPeer::is_refusing_new_connections() const { return refuse_connections; } -void NetworkedMultiplayerENet::set_compression_mode(CompressionMode p_mode) { +void ENetMultiplayerPeer::set_compression_mode(CompressionMode p_mode) { compression_mode = p_mode; } -NetworkedMultiplayerENet::CompressionMode NetworkedMultiplayerENet::get_compression_mode() const { +ENetMultiplayerPeer::CompressionMode ENetMultiplayerPeer::get_compression_mode() const { return compression_mode; } -size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer *inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 *outData, size_t outLimit) { - NetworkedMultiplayerENet *enet = (NetworkedMultiplayerENet *)(context); +size_t ENetMultiplayerPeer::enet_compress(void *context, const ENetBuffer *inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 *outData, size_t outLimit) { + ENetMultiplayerPeer *enet = (ENetMultiplayerPeer *)(context); if (size_t(enet->src_compressor_mem.size()) < inLimit) { enet->src_compressor_mem.resize(inLimit); @@ -709,8 +709,8 @@ size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer * return ret; } -size_t NetworkedMultiplayerENet::enet_decompress(void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit) { - NetworkedMultiplayerENet *enet = (NetworkedMultiplayerENet *)(context); +size_t ENetMultiplayerPeer::enet_decompress(void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit) { + ENetMultiplayerPeer *enet = (ENetMultiplayerPeer *)(context); int ret = -1; switch (enet->compression_mode) { case COMPRESS_FASTLZ: { @@ -732,7 +732,7 @@ size_t NetworkedMultiplayerENet::enet_decompress(void *context, const enet_uint8 } } -void NetworkedMultiplayerENet::_setup_compressor() { +void ENetMultiplayerPeer::_setup_compressor() { switch (compression_mode) { case COMPRESS_NONE: { enet_host_compress(host, nullptr); @@ -748,11 +748,11 @@ void NetworkedMultiplayerENet::_setup_compressor() { } } -void NetworkedMultiplayerENet::enet_compressor_destroy(void *context) { +void ENetMultiplayerPeer::enet_compressor_destroy(void *context) { // Nothing to do } -IPAddress NetworkedMultiplayerENet::get_peer_address(int p_peer_id) const { +IPAddress ENetMultiplayerPeer::get_peer_address(int p_peer_id) const { ERR_FAIL_COND_V_MSG(!peer_map.has(p_peer_id), IPAddress(), vformat("Peer ID %d not found in the list of peers.", p_peer_id)); ERR_FAIL_COND_V_MSG(!is_server() && p_peer_id != 1, IPAddress(), "Can't get the address of peers other than the server (ID -1) when acting as a client."); ERR_FAIL_COND_V_MSG(peer_map[p_peer_id] == nullptr, IPAddress(), vformat("Peer ID %d found in the list of peers, but is null.", p_peer_id)); @@ -767,7 +767,7 @@ IPAddress NetworkedMultiplayerENet::get_peer_address(int p_peer_id) const { return out; } -int NetworkedMultiplayerENet::get_peer_port(int p_peer_id) const { +int ENetMultiplayerPeer::get_peer_port(int p_peer_id) const { ERR_FAIL_COND_V_MSG(!peer_map.has(p_peer_id), 0, vformat("Peer ID %d not found in the list of peers.", p_peer_id)); ERR_FAIL_COND_V_MSG(!is_server() && p_peer_id != 1, 0, "Can't get the address of peers other than the server (ID -1) when acting as a client."); ERR_FAIL_COND_V_MSG(peer_map[p_peer_id] == nullptr, 0, vformat("Peer ID %d found in the list of peers, but is null.", p_peer_id)); @@ -778,12 +778,12 @@ int NetworkedMultiplayerENet::get_peer_port(int p_peer_id) const { #endif } -int NetworkedMultiplayerENet::get_local_port() const { +int ENetMultiplayerPeer::get_local_port() const { ERR_FAIL_COND_V_MSG(!active || !host, 0, "The multiplayer instance isn't currently active."); return host->address.port; } -void NetworkedMultiplayerENet::set_peer_timeout(int p_peer_id, int p_timeout_limit, int p_timeout_min, int p_timeout_max) { +void ENetMultiplayerPeer::set_peer_timeout(int p_peer_id, int p_timeout_limit, int p_timeout_min, int p_timeout_max) { ERR_FAIL_COND_MSG(!peer_map.has(p_peer_id), vformat("Peer ID %d not found in the list of peers.", p_peer_id)); ERR_FAIL_COND_MSG(!is_server() && p_peer_id != 1, "Can't change the timeout of peers other then the server when acting as a client."); ERR_FAIL_COND_MSG(peer_map[p_peer_id] == nullptr, vformat("Peer ID %d found in the list of peers, but is null.", p_peer_id)); @@ -791,73 +791,73 @@ void NetworkedMultiplayerENet::set_peer_timeout(int p_peer_id, int p_timeout_lim enet_peer_timeout(peer_map[p_peer_id], p_timeout_limit, p_timeout_min, p_timeout_max); } -void NetworkedMultiplayerENet::set_transfer_channel(int p_channel) { +void ENetMultiplayerPeer::set_transfer_channel(int p_channel) { ERR_FAIL_COND_MSG(p_channel < -1 || p_channel >= channel_count, vformat("The transfer channel must be set between 0 and %d, inclusive (got %d).", channel_count - 1, p_channel)); ERR_FAIL_COND_MSG(p_channel == SYSCH_CONFIG, vformat("The channel %d is reserved.", SYSCH_CONFIG)); transfer_channel = p_channel; } -int NetworkedMultiplayerENet::get_transfer_channel() const { +int ENetMultiplayerPeer::get_transfer_channel() const { return transfer_channel; } -void NetworkedMultiplayerENet::set_channel_count(int p_channel) { +void ENetMultiplayerPeer::set_channel_count(int p_channel) { ERR_FAIL_COND_MSG(active, "The channel count can't be set while the multiplayer instance is active."); ERR_FAIL_COND_MSG(p_channel < SYSCH_MAX, vformat("The channel count must be greater than or equal to %d to account for reserved channels (got %d).", SYSCH_MAX, p_channel)); channel_count = p_channel; } -int NetworkedMultiplayerENet::get_channel_count() const { +int ENetMultiplayerPeer::get_channel_count() const { return channel_count; } -void NetworkedMultiplayerENet::set_always_ordered(bool p_ordered) { +void ENetMultiplayerPeer::set_always_ordered(bool p_ordered) { always_ordered = p_ordered; } -bool NetworkedMultiplayerENet::is_always_ordered() const { +bool ENetMultiplayerPeer::is_always_ordered() const { return always_ordered; } -void NetworkedMultiplayerENet::set_server_relay_enabled(bool p_enabled) { +void ENetMultiplayerPeer::set_server_relay_enabled(bool p_enabled) { ERR_FAIL_COND_MSG(active, "Server relaying can't be toggled while the multiplayer instance is active."); server_relay = p_enabled; } -bool NetworkedMultiplayerENet::is_server_relay_enabled() const { +bool ENetMultiplayerPeer::is_server_relay_enabled() const { return server_relay; } -void NetworkedMultiplayerENet::_bind_methods() { - ClassDB::bind_method(D_METHOD("create_server", "port", "max_clients", "in_bandwidth", "out_bandwidth"), &NetworkedMultiplayerENet::create_server, DEFVAL(32), DEFVAL(0), DEFVAL(0)); - ClassDB::bind_method(D_METHOD("create_client", "address", "port", "in_bandwidth", "out_bandwidth", "local_port"), &NetworkedMultiplayerENet::create_client, DEFVAL(0), DEFVAL(0), DEFVAL(0)); - ClassDB::bind_method(D_METHOD("close_connection", "wait_usec"), &NetworkedMultiplayerENet::close_connection, DEFVAL(100)); - ClassDB::bind_method(D_METHOD("disconnect_peer", "id", "now"), &NetworkedMultiplayerENet::disconnect_peer, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("set_compression_mode", "mode"), &NetworkedMultiplayerENet::set_compression_mode); - ClassDB::bind_method(D_METHOD("get_compression_mode"), &NetworkedMultiplayerENet::get_compression_mode); - ClassDB::bind_method(D_METHOD("set_bind_ip", "ip"), &NetworkedMultiplayerENet::set_bind_ip); - ClassDB::bind_method(D_METHOD("set_dtls_enabled", "enabled"), &NetworkedMultiplayerENet::set_dtls_enabled); - ClassDB::bind_method(D_METHOD("is_dtls_enabled"), &NetworkedMultiplayerENet::is_dtls_enabled); - ClassDB::bind_method(D_METHOD("set_dtls_key", "key"), &NetworkedMultiplayerENet::set_dtls_key); - ClassDB::bind_method(D_METHOD("set_dtls_certificate", "certificate"), &NetworkedMultiplayerENet::set_dtls_certificate); - ClassDB::bind_method(D_METHOD("set_dtls_verify_enabled", "enabled"), &NetworkedMultiplayerENet::set_dtls_verify_enabled); - ClassDB::bind_method(D_METHOD("is_dtls_verify_enabled"), &NetworkedMultiplayerENet::is_dtls_verify_enabled); - ClassDB::bind_method(D_METHOD("get_peer_address", "id"), &NetworkedMultiplayerENet::get_peer_address); - ClassDB::bind_method(D_METHOD("get_peer_port", "id"), &NetworkedMultiplayerENet::get_peer_port); - ClassDB::bind_method(D_METHOD("get_local_port"), &NetworkedMultiplayerENet::get_local_port); - ClassDB::bind_method(D_METHOD("set_peer_timeout", "id", "timeout_limit", "timeout_min", "timeout_max"), &NetworkedMultiplayerENet::set_peer_timeout); - - ClassDB::bind_method(D_METHOD("get_packet_channel"), &NetworkedMultiplayerENet::get_packet_channel); - ClassDB::bind_method(D_METHOD("get_last_packet_channel"), &NetworkedMultiplayerENet::get_last_packet_channel); - ClassDB::bind_method(D_METHOD("set_transfer_channel", "channel"), &NetworkedMultiplayerENet::set_transfer_channel); - ClassDB::bind_method(D_METHOD("get_transfer_channel"), &NetworkedMultiplayerENet::get_transfer_channel); - ClassDB::bind_method(D_METHOD("set_channel_count", "channels"), &NetworkedMultiplayerENet::set_channel_count); - ClassDB::bind_method(D_METHOD("get_channel_count"), &NetworkedMultiplayerENet::get_channel_count); - ClassDB::bind_method(D_METHOD("set_always_ordered", "ordered"), &NetworkedMultiplayerENet::set_always_ordered); - ClassDB::bind_method(D_METHOD("is_always_ordered"), &NetworkedMultiplayerENet::is_always_ordered); - ClassDB::bind_method(D_METHOD("set_server_relay_enabled", "enabled"), &NetworkedMultiplayerENet::set_server_relay_enabled); - ClassDB::bind_method(D_METHOD("is_server_relay_enabled"), &NetworkedMultiplayerENet::is_server_relay_enabled); +void ENetMultiplayerPeer::_bind_methods() { + ClassDB::bind_method(D_METHOD("create_server", "port", "max_clients", "in_bandwidth", "out_bandwidth"), &ENetMultiplayerPeer::create_server, DEFVAL(32), DEFVAL(0), DEFVAL(0)); + ClassDB::bind_method(D_METHOD("create_client", "address", "port", "in_bandwidth", "out_bandwidth", "local_port"), &ENetMultiplayerPeer::create_client, DEFVAL(0), DEFVAL(0), DEFVAL(0)); + ClassDB::bind_method(D_METHOD("close_connection", "wait_usec"), &ENetMultiplayerPeer::close_connection, DEFVAL(100)); + ClassDB::bind_method(D_METHOD("disconnect_peer", "id", "now"), &ENetMultiplayerPeer::disconnect_peer, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("set_compression_mode", "mode"), &ENetMultiplayerPeer::set_compression_mode); + ClassDB::bind_method(D_METHOD("get_compression_mode"), &ENetMultiplayerPeer::get_compression_mode); + ClassDB::bind_method(D_METHOD("set_bind_ip", "ip"), &ENetMultiplayerPeer::set_bind_ip); + ClassDB::bind_method(D_METHOD("set_dtls_enabled", "enabled"), &ENetMultiplayerPeer::set_dtls_enabled); + ClassDB::bind_method(D_METHOD("is_dtls_enabled"), &ENetMultiplayerPeer::is_dtls_enabled); + ClassDB::bind_method(D_METHOD("set_dtls_key", "key"), &ENetMultiplayerPeer::set_dtls_key); + ClassDB::bind_method(D_METHOD("set_dtls_certificate", "certificate"), &ENetMultiplayerPeer::set_dtls_certificate); + ClassDB::bind_method(D_METHOD("set_dtls_verify_enabled", "enabled"), &ENetMultiplayerPeer::set_dtls_verify_enabled); + ClassDB::bind_method(D_METHOD("is_dtls_verify_enabled"), &ENetMultiplayerPeer::is_dtls_verify_enabled); + ClassDB::bind_method(D_METHOD("get_peer_address", "id"), &ENetMultiplayerPeer::get_peer_address); + ClassDB::bind_method(D_METHOD("get_peer_port", "id"), &ENetMultiplayerPeer::get_peer_port); + ClassDB::bind_method(D_METHOD("get_local_port"), &ENetMultiplayerPeer::get_local_port); + ClassDB::bind_method(D_METHOD("set_peer_timeout", "id", "timeout_limit", "timeout_min", "timeout_max"), &ENetMultiplayerPeer::set_peer_timeout); + + ClassDB::bind_method(D_METHOD("get_packet_channel"), &ENetMultiplayerPeer::get_packet_channel); + ClassDB::bind_method(D_METHOD("get_last_packet_channel"), &ENetMultiplayerPeer::get_last_packet_channel); + ClassDB::bind_method(D_METHOD("set_transfer_channel", "channel"), &ENetMultiplayerPeer::set_transfer_channel); + ClassDB::bind_method(D_METHOD("get_transfer_channel"), &ENetMultiplayerPeer::get_transfer_channel); + ClassDB::bind_method(D_METHOD("set_channel_count", "channels"), &ENetMultiplayerPeer::set_channel_count); + ClassDB::bind_method(D_METHOD("get_channel_count"), &ENetMultiplayerPeer::get_channel_count); + ClassDB::bind_method(D_METHOD("set_always_ordered", "ordered"), &ENetMultiplayerPeer::set_always_ordered); + ClassDB::bind_method(D_METHOD("is_always_ordered"), &ENetMultiplayerPeer::is_always_ordered); + ClassDB::bind_method(D_METHOD("set_server_relay_enabled", "enabled"), &ENetMultiplayerPeer::set_server_relay_enabled); + ClassDB::bind_method(D_METHOD("is_server_relay_enabled"), &ENetMultiplayerPeer::is_server_relay_enabled); ADD_PROPERTY(PropertyInfo(Variant::INT, "compression_mode", PROPERTY_HINT_ENUM, "None,Range Coder,FastLZ,ZLib,ZStd"), "set_compression_mode", "get_compression_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "transfer_channel"), "set_transfer_channel", "get_transfer_channel"); @@ -874,7 +874,7 @@ void NetworkedMultiplayerENet::_bind_methods() { BIND_ENUM_CONSTANT(COMPRESS_ZSTD); } -NetworkedMultiplayerENet::NetworkedMultiplayerENet() { +ENetMultiplayerPeer::ENetMultiplayerPeer() { enet_compressor.context = this; enet_compressor.compress = enet_compress; enet_compressor.decompress = enet_decompress; @@ -883,7 +883,7 @@ NetworkedMultiplayerENet::NetworkedMultiplayerENet() { bind_ip = IPAddress("*"); } -NetworkedMultiplayerENet::~NetworkedMultiplayerENet() { +ENetMultiplayerPeer::~ENetMultiplayerPeer() { if (active) { close_connection(); } @@ -891,36 +891,36 @@ NetworkedMultiplayerENet::~NetworkedMultiplayerENet() { // Sets IP for ENet to bind when using create_server or create_client // if no IP is set, then ENet bind to ENET_HOST_ANY -void NetworkedMultiplayerENet::set_bind_ip(const IPAddress &p_ip) { +void ENetMultiplayerPeer::set_bind_ip(const IPAddress &p_ip) { ERR_FAIL_COND_MSG(!p_ip.is_valid() && !p_ip.is_wildcard(), vformat("Invalid bind IP address: %s", String(p_ip))); bind_ip = p_ip; } -void NetworkedMultiplayerENet::set_dtls_enabled(bool p_enabled) { +void ENetMultiplayerPeer::set_dtls_enabled(bool p_enabled) { ERR_FAIL_COND(active); dtls_enabled = p_enabled; } -bool NetworkedMultiplayerENet::is_dtls_enabled() const { +bool ENetMultiplayerPeer::is_dtls_enabled() const { return dtls_enabled; } -void NetworkedMultiplayerENet::set_dtls_verify_enabled(bool p_enabled) { +void ENetMultiplayerPeer::set_dtls_verify_enabled(bool p_enabled) { ERR_FAIL_COND(active); dtls_verify = p_enabled; } -bool NetworkedMultiplayerENet::is_dtls_verify_enabled() const { +bool ENetMultiplayerPeer::is_dtls_verify_enabled() const { return dtls_verify; } -void NetworkedMultiplayerENet::set_dtls_key(Ref<CryptoKey> p_key) { +void ENetMultiplayerPeer::set_dtls_key(Ref<CryptoKey> p_key) { ERR_FAIL_COND(active); dtls_key = p_key; } -void NetworkedMultiplayerENet::set_dtls_certificate(Ref<X509Certificate> p_cert) { +void ENetMultiplayerPeer::set_dtls_certificate(Ref<X509Certificate> p_cert) { ERR_FAIL_COND(active); dtls_cert = p_cert; } diff --git a/modules/enet/networked_multiplayer_enet.h b/modules/enet/enet_multiplayer_peer.h index 2d928859fa..63f2ec5870 100644 --- a/modules/enet/networked_multiplayer_enet.h +++ b/modules/enet/enet_multiplayer_peer.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* networked_multiplayer_enet.h */ +/* enet_multiplayer_peer.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -33,12 +33,12 @@ #include "core/crypto/crypto.h" #include "core/io/compression.h" -#include "core/io/networked_multiplayer_peer.h" +#include "core/io/multiplayer_peer.h" #include <enet/enet.h> -class NetworkedMultiplayerENet : public NetworkedMultiplayerPeer { - GDCLASS(NetworkedMultiplayerENet, NetworkedMultiplayerPeer); +class ENetMultiplayerPeer : public MultiplayerPeer { + GDCLASS(ENetMultiplayerPeer, MultiplayerPeer); public: enum CompressionMode { @@ -90,7 +90,7 @@ private: int channel = 0; }; - CompressionMode compression_mode = COMPRESS_NONE; + CompressionMode compression_mode = COMPRESS_RANGE_CODER; List<Packet> incoming_packets; @@ -168,8 +168,8 @@ public: void set_server_relay_enabled(bool p_enabled); bool is_server_relay_enabled() const; - NetworkedMultiplayerENet(); - ~NetworkedMultiplayerENet(); + ENetMultiplayerPeer(); + ~ENetMultiplayerPeer(); void set_bind_ip(const IPAddress &p_ip); void set_dtls_enabled(bool p_enabled); @@ -180,6 +180,6 @@ public: void set_dtls_certificate(Ref<X509Certificate> p_cert); }; -VARIANT_ENUM_CAST(NetworkedMultiplayerENet::CompressionMode); +VARIANT_ENUM_CAST(ENetMultiplayerPeer::CompressionMode); #endif // NETWORKED_MULTIPLAYER_ENET_H diff --git a/modules/enet/register_types.cpp b/modules/enet/register_types.cpp index 8da2d17e13..38870316e4 100644 --- a/modules/enet/register_types.cpp +++ b/modules/enet/register_types.cpp @@ -30,7 +30,7 @@ #include "register_types.h" #include "core/error/error_macros.h" -#include "networked_multiplayer_enet.h" +#include "enet_multiplayer_peer.h" static bool enet_ok = false; @@ -41,7 +41,7 @@ void register_enet_types() { enet_ok = true; } - ClassDB::register_class<NetworkedMultiplayerENet>(); + GDREGISTER_CLASS(ENetMultiplayerPeer); } void unregister_enet_types() { diff --git a/modules/fbx/data/fbx_material.cpp b/modules/fbx/data/fbx_material.cpp index cf5d70fa5b..fb6c67f7b9 100644 --- a/modules/fbx/data/fbx_material.cpp +++ b/modules/fbx/data/fbx_material.cpp @@ -29,6 +29,10 @@ /*************************************************************************/ #include "fbx_material.h" + +// FIXME: Shouldn't depend on core_bind.h! Use DirAccessRef like the rest of +// the engine instead of _Directory. +#include "core/core_bind.h" #include "scene/resources/material.h" #include "scene/resources/texture.h" #include "tools/validation_tools.h" diff --git a/modules/fbx/data/fbx_mesh_data.cpp b/modules/fbx/data/fbx_mesh_data.cpp index 0d33b8e7c6..8b4b1e08b3 100644 --- a/modules/fbx/data/fbx_mesh_data.cpp +++ b/modules/fbx/data/fbx_mesh_data.cpp @@ -525,7 +525,7 @@ void FBXMeshData::reorganize_vertices( } const Vector3 vert_poly_normal = *nrml_arr->getptr(*pid); - if ((this_vert_poly_normal - vert_poly_normal).length_squared() > CMP_EPSILON) { + if (!vert_poly_normal.is_equal_approx(this_vert_poly_normal)) { // Yes this polygon need duplication. need_duplication = true; break; @@ -586,7 +586,7 @@ void FBXMeshData::reorganize_vertices( continue; } const Vector2 vert_poly_uv = *uvs->getptr(*pid); - if (((*this_vert_poly_uv) - vert_poly_uv).length_squared() > CMP_EPSILON) { + if (!vert_poly_uv.is_equal_approx(*this_vert_poly_uv)) { // Yes this polygon need duplication. need_duplication = true; break; diff --git a/modules/fbx/data/import_state.h b/modules/fbx/data/import_state.h index 83bc43faff..9ba60eaacf 100644 --- a/modules/fbx/data/import_state.h +++ b/modules/fbx/data/import_state.h @@ -37,7 +37,6 @@ #include "pivot_transform.h" -#include "core/core_bind.h" #include "core/io/resource_importer.h" #include "core/templates/vector.h" #include "editor/import/resource_importer_scene.h" diff --git a/modules/fbx/editor_scene_importer_fbx.h b/modules/fbx/editor_scene_importer_fbx.h index 4bb2c9d21b..4a3b78480b 100644 --- a/modules/fbx/editor_scene_importer_fbx.h +++ b/modules/fbx/editor_scene_importer_fbx.h @@ -36,7 +36,6 @@ #include "data/import_state.h" #include "tools/import_utils.h" -#include "core/core_bind.h" #include "core/io/resource_importer.h" #include "core/string/ustring.h" #include "core/templates/local_vector.h" diff --git a/modules/fbx/register_types.cpp b/modules/fbx/register_types.cpp index b615c91cd2..a75da8f3a9 100644 --- a/modules/fbx/register_types.cpp +++ b/modules/fbx/register_types.cpp @@ -46,7 +46,7 @@ void register_fbx_types() { ClassDB::APIType prev_api = ClassDB::get_current_api(); ClassDB::set_current_api(ClassDB::API_EDITOR); - ClassDB::register_class<EditorSceneImporterFBX>(); + GDREGISTER_CLASS(EditorSceneImporterFBX); ClassDB::set_current_api(prev_api); diff --git a/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml b/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml index 9f33d32e81..b88f5e7e1e 100644 --- a/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml +++ b/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="MultiplayerPeerGDNative" inherits="NetworkedMultiplayerPeer" version="4.0"> +<class name="MultiplayerPeerGDNative" inherits="MultiplayerPeer" version="4.0"> <brief_description> </brief_description> <description> diff --git a/modules/gdnative/gdnative_library_editor_plugin.cpp b/modules/gdnative/gdnative_library_editor_plugin.cpp index b4ac0d886e..f965bcd014 100644 --- a/modules/gdnative/gdnative_library_editor_plugin.cpp +++ b/modules/gdnative/gdnative_library_editor_plugin.cpp @@ -74,9 +74,9 @@ void GDNativeLibraryEditor::_update_tree() { platform->set_text(0, E->get().name); platform->set_metadata(0, E->get().library_extension); - platform->set_custom_bg_color(0, get_theme_color("prop_category", "Editor")); - platform->set_custom_bg_color(1, get_theme_color("prop_category", "Editor")); - platform->set_custom_bg_color(2, get_theme_color("prop_category", "Editor")); + platform->set_custom_bg_color(0, get_theme_color(SNAME("prop_category"), SNAME("Editor"))); + platform->set_custom_bg_color(1, get_theme_color(SNAME("prop_category"), SNAME("Editor"))); + platform->set_custom_bg_color(2, get_theme_color(SNAME("prop_category"), SNAME("Editor"))); platform->set_selectable(0, false); platform->set_expand_right(0, true); @@ -87,31 +87,31 @@ void GDNativeLibraryEditor::_update_tree() { bit->set_text(0, it->get()); bit->set_metadata(0, target); bit->set_selectable(0, false); - bit->set_custom_bg_color(0, get_theme_color("prop_subsection", "Editor")); + bit->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), SNAME("Editor"))); - bit->add_button(1, get_theme_icon("Folder", "EditorIcons"), BUTTON_SELECT_LIBRARY, false, TTR("Select the dynamic library for this entry")); + bit->add_button(1, get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")), BUTTON_SELECT_LIBRARY, false, TTR("Select the dynamic library for this entry")); String file = entry_configs[target].library; if (!file.is_empty()) { - bit->add_button(1, get_theme_icon("Clear", "EditorIcons"), BUTTON_CLEAR_LIBRARY, false, TTR("Clear")); + bit->add_button(1, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), BUTTON_CLEAR_LIBRARY, false, TTR("Clear")); } bit->set_text(1, file); - bit->add_button(2, get_theme_icon("Folder", "EditorIcons"), BUTTON_SELECT_DEPENDENCES, false, TTR("Select dependencies of the library for this entry")); + bit->add_button(2, get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")), BUTTON_SELECT_DEPENDENCES, false, TTR("Select dependencies of the library for this entry")); Array files = entry_configs[target].dependencies; if (files.size()) { - bit->add_button(2, get_theme_icon("Clear", "EditorIcons"), BUTTON_CLEAR_DEPENDENCES, false, TTR("Clear")); + bit->add_button(2, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), BUTTON_CLEAR_DEPENDENCES, false, TTR("Clear")); } bit->set_text(2, Variant(files)); - bit->add_button(3, get_theme_icon("MoveUp", "EditorIcons"), BUTTON_MOVE_UP, false, TTR("Move Up")); - bit->add_button(3, get_theme_icon("MoveDown", "EditorIcons"), BUTTON_MOVE_DOWN, false, TTR("Move Down")); - bit->add_button(3, get_theme_icon("Remove", "EditorIcons"), BUTTON_ERASE_ENTRY, false, TTR("Remove current entry")); + bit->add_button(3, get_theme_icon(SNAME("MoveUp"), SNAME("EditorIcons")), BUTTON_MOVE_UP, false, TTR("Move Up")); + bit->add_button(3, get_theme_icon(SNAME("MoveDown"), SNAME("EditorIcons")), BUTTON_MOVE_DOWN, false, TTR("Move Down")); + bit->add_button(3, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), BUTTON_ERASE_ENTRY, false, TTR("Remove current entry")); } TreeItem *new_arch = tree->create_item(platform); new_arch->set_text(0, TTR("Double click to create a new entry")); new_arch->set_text_align(0, TreeItem::ALIGN_CENTER); - new_arch->set_custom_color(0, get_theme_color("accent_color", "Editor")); + new_arch->set_custom_color(0, get_theme_color(SNAME("accent_color"), SNAME("Editor"))); new_arch->set_expand_right(0, true); new_arch->set_metadata(1, E->key()); @@ -356,12 +356,12 @@ GDNativeLibraryEditor::GDNativeLibraryEditor() { tree->set_column_titles_visible(true); tree->set_columns(4); tree->set_column_expand(0, false); - tree->set_column_min_width(0, int(200 * EDSCALE)); + tree->set_column_custom_minimum_width(0, int(200 * EDSCALE)); tree->set_column_title(0, TTR("Platform")); tree->set_column_title(1, TTR("Dynamic Library")); tree->set_column_title(2, TTR("Dependencies")); tree->set_column_expand(3, false); - tree->set_column_min_width(3, int(110 * EDSCALE)); + tree->set_column_custom_minimum_width(3, int(110 * EDSCALE)); tree->connect("button_pressed", callable_mp(this, &GDNativeLibraryEditor::_on_item_button)); tree->connect("item_collapsed", callable_mp(this, &GDNativeLibraryEditor::_on_item_collapsed)); tree->connect("item_activated", callable_mp(this, &GDNativeLibraryEditor::_on_item_activated)); diff --git a/modules/gdnative/include/gdnative/variant.h b/modules/gdnative/include/gdnative/variant.h index dd4f76cf57..a88bd2878a 100644 --- a/modules/gdnative/include/gdnative/variant.h +++ b/modules/gdnative/include/gdnative/variant.h @@ -164,7 +164,7 @@ typedef void (*godot_validated_keyed_getter)(const godot_variant *p_base, const typedef bool (*godot_validated_keyed_checker)(const godot_variant *p_base, const godot_variant *p_key, bool *r_valid); typedef void (*godot_ptr_keyed_setter)(void *p_base, const void *p_key, const void *p_value); typedef void (*godot_ptr_keyed_getter)(const void *p_base, const void *p_key, void *r_value); -typedef bool (*godot_ptr_keyed_checker)(const godot_variant *p_base, const godot_variant *p_key); +typedef uint32_t (*godot_ptr_keyed_checker)(const godot_variant *p_base, const godot_variant *p_key); typedef void (*godot_validated_utility_function)(godot_variant *r_return, const godot_variant **p_arguments, int p_argument_count); typedef void (*godot_ptr_utility_function)(void *r_return, const void **p_arguments, int p_argument_count); diff --git a/modules/gdnative/include/net/godot_net.h b/modules/gdnative/include/net/godot_net.h index 2fa576a5bf..94e7739ef9 100644 --- a/modules/gdnative/include/net/godot_net.h +++ b/modules/gdnative/include/net/godot_net.h @@ -90,7 +90,7 @@ typedef struct { godot_int (*get_available_packet_count)(const void *); godot_int (*get_max_packet_size)(const void *); - /* This is NetworkedMultiplayerPeer */ + /* This is MultiplayerPeer */ void (*set_transfer_mode)(void *, godot_int); godot_int (*get_transfer_mode)(const void *); // 0 = broadcast, 1 = server, <0 = all but abs(value) diff --git a/modules/gdnative/include/net/godot_webrtc.h b/modules/gdnative/include/net/godot_webrtc.h index 25aa72dae1..62b7e3c2c5 100644 --- a/modules/gdnative/include/net/godot_webrtc.h +++ b/modules/gdnative/include/net/godot_webrtc.h @@ -101,6 +101,7 @@ typedef struct { 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 *); diff --git a/modules/gdnative/include/text/godot_text.h b/modules/gdnative/include/text/godot_text.h index f3c50e6f87..6428f2f149 100644 --- a/modules/gdnative/include/text/godot_text.h +++ b/modules/gdnative/include/text/godot_text.h @@ -143,13 +143,14 @@ typedef struct { bool (*shaped_text_shape)(void *, godot_rid *); bool (*shaped_text_update_breaks)(void *, godot_rid *); bool (*shaped_text_update_justification_ops)(void *, godot_rid *); + void (*shaped_text_overrun_trim_to_width)(void *, godot_rid *, float, uint8_t); bool (*shaped_text_is_ready)(void *, godot_rid *); godot_packed_glyph_array (*shaped_text_get_glyphs)(void *, godot_rid *); godot_vector2i (*shaped_text_get_range)(void *, godot_rid *); godot_packed_glyph_array (*shaped_text_sort_logical)(void *, godot_rid *); godot_packed_vector2i_array (*shaped_text_get_line_breaks_adv)(void *, godot_rid *, godot_packed_float32_array *, int, bool, uint8_t); godot_packed_vector2i_array (*shaped_text_get_line_breaks)(void *, godot_rid *, float, int, uint8_t); - godot_packed_vector2i_array (*shaped_text_get_word_breaks)(void *, godot_rid *); + godot_packed_vector2i_array (*shaped_text_get_word_breaks)(void *, godot_rid *, int); godot_array (*shaped_text_get_objects)(void *, godot_rid *); godot_rect2 (*shaped_text_get_object_rect)(void *, godot_rid *, const godot_variant *); godot_vector2 (*shaped_text_get_size)(void *, godot_rid *); diff --git a/modules/gdnative/nativescript/api_generator.cpp b/modules/gdnative/nativescript/api_generator.cpp index 4f696f2a39..477bc9f74d 100644 --- a/modules/gdnative/nativescript/api_generator.cpp +++ b/modules/gdnative/nativescript/api_generator.cpp @@ -405,7 +405,7 @@ List<ClassAPI> generate_c_api_classes() { arg_type = Variant::get_type_name(arg_info.type); } } else { - arg_type = Variant::get_type_name(arg_info.type); + arg_type = get_type_name(arg_info); } method_api.argument_names.push_back(arg_name); diff --git a/modules/gdnative/nativescript/godot_nativescript.cpp b/modules/gdnative/nativescript/godot_nativescript.cpp index b10a747568..70b14836bf 100644 --- a/modules/gdnative/nativescript/godot_nativescript.cpp +++ b/modules/gdnative/nativescript/godot_nativescript.cpp @@ -332,7 +332,7 @@ void GDAPI godot_nativescript_unregister_instance_binding_data_functions(int p_i } void GDAPI *godot_nativescript_get_instance_binding_data(int p_idx, godot_object *p_object) { - return NativeScriptLanguage::get_singleton()->get_instance_binding_data(p_idx, (Object *)p_object); + return nullptr; } void GDAPI godot_nativescript_profiling_add_data(const char *p_signature, uint64_t p_time) { diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index 3695f6b9a3..d7943827c2 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -1258,6 +1258,8 @@ void NativeScriptLanguage::unregister_binding_functions(int p_idx) { } void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_object) { + return nullptr; +#if 0 ERR_FAIL_INDEX_V(p_idx, binding_functions.size(), nullptr); ERR_FAIL_COND_V_MSG(!binding_functions[p_idx].first, nullptr, "Tried to get binding data for a nativescript binding that does not exist."); @@ -1287,9 +1289,12 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec } return (*binding_data)[p_idx]; +#endif } void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) { + return nullptr; +#if 0 Vector<void *> *binding_data = new Vector<void *>; binding_data->resize(binding_functions.size()); @@ -1301,9 +1306,11 @@ void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) { binding_instances.insert(binding_data); return (void *)binding_data; +#endif } void NativeScriptLanguage::free_instance_binding_data(void *p_data) { +#if 0 if (!p_data) { return; } @@ -1323,9 +1330,11 @@ void NativeScriptLanguage::free_instance_binding_data(void *p_data) { binding_instances.erase(&binding_data); delete &binding_data; +#endif } void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_object) { +#if 0 void *data = p_object->get_script_instance_binding(lang_idx); if (!data) { @@ -1347,9 +1356,11 @@ void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_objec binding_functions[i].second.refcount_incremented_instance_binding(binding_data[i], p_object); } } +#endif } bool NativeScriptLanguage::refcount_decremented_instance_binding(Object *p_object) { +#if 0 void *data = p_object->get_script_instance_binding(lang_idx); if (!data) { @@ -1375,6 +1386,8 @@ bool NativeScriptLanguage::refcount_decremented_instance_binding(Object *p_objec } return can_die; +#endif + return false; } void NativeScriptLanguage::set_global_type_tag(int p_idx, StringName p_class_name, const void *p_type_tag) { diff --git a/modules/gdnative/nativescript/register_types.cpp b/modules/gdnative/nativescript/register_types.cpp index 0191cfd809..82a3459517 100644 --- a/modules/gdnative/nativescript/register_types.cpp +++ b/modules/gdnative/nativescript/register_types.cpp @@ -45,7 +45,7 @@ Ref<ResourceFormatSaverNativeScript> resource_saver_gdns; void register_nativescript_types() { native_script_language = memnew(NativeScriptLanguage); - ClassDB::register_class<NativeScript>(); + GDREGISTER_CLASS(NativeScript); native_script_language->set_language_index(ScriptServer::get_language_count()); ScriptServer::register_language(native_script_language); diff --git a/modules/gdnative/net/multiplayer_peer_gdnative.cpp b/modules/gdnative/net/multiplayer_peer_gdnative.cpp index 8b5fc8db5c..8ceba0f339 100644 --- a/modules/gdnative/net/multiplayer_peer_gdnative.cpp +++ b/modules/gdnative/net/multiplayer_peer_gdnative.cpp @@ -61,13 +61,13 @@ int MultiplayerPeerGDNative::get_available_packet_count() const { return interface->get_available_packet_count(interface->data); } -/* NetworkedMultiplayerPeer */ +/* MultiplayerPeer */ void MultiplayerPeerGDNative::set_transfer_mode(TransferMode p_mode) { ERR_FAIL_COND(interface == nullptr); interface->set_transfer_mode(interface->data, (godot_int)p_mode); } -NetworkedMultiplayerPeer::TransferMode MultiplayerPeerGDNative::get_transfer_mode() const { +MultiplayerPeer::TransferMode MultiplayerPeerGDNative::get_transfer_mode() const { ERR_FAIL_COND_V(interface == nullptr, TRANSFER_MODE_UNRELIABLE); return (TransferMode)interface->get_transfer_mode(interface->data); } @@ -107,7 +107,7 @@ bool MultiplayerPeerGDNative::is_refusing_new_connections() const { return interface->is_refusing_new_connections(interface->data); } -NetworkedMultiplayerPeer::ConnectionStatus MultiplayerPeerGDNative::get_connection_status() const { +MultiplayerPeer::ConnectionStatus MultiplayerPeerGDNative::get_connection_status() const { ERR_FAIL_COND_V(interface == nullptr, CONNECTION_DISCONNECTED); return (ConnectionStatus)interface->get_connection_status(interface->data); } diff --git a/modules/gdnative/net/multiplayer_peer_gdnative.h b/modules/gdnative/net/multiplayer_peer_gdnative.h index 593b2534dd..7c10ab77f7 100644 --- a/modules/gdnative/net/multiplayer_peer_gdnative.h +++ b/modules/gdnative/net/multiplayer_peer_gdnative.h @@ -31,12 +31,12 @@ #ifndef MULTIPLAYER_PEER_GDNATIVE_H #define MULTIPLAYER_PEER_GDNATIVE_H -#include "core/io/networked_multiplayer_peer.h" +#include "core/io/multiplayer_peer.h" #include "modules/gdnative/gdnative.h" #include "modules/gdnative/include/net/godot_net.h" -class MultiplayerPeerGDNative : public NetworkedMultiplayerPeer { - GDCLASS(MultiplayerPeerGDNative, NetworkedMultiplayerPeer); +class MultiplayerPeerGDNative : public MultiplayerPeer { + GDCLASS(MultiplayerPeerGDNative, MultiplayerPeer); protected: static void _bind_methods(); @@ -55,7 +55,7 @@ public: virtual int get_max_packet_size() const override; virtual int get_available_packet_count() const override; - /* Specific to NetworkedMultiplayerPeer */ + /* Specific to MultiplayerPeer */ virtual void set_transfer_mode(TransferMode p_mode) override; virtual TransferMode get_transfer_mode() const override; virtual void set_target_peer(int p_peer_id) override; diff --git a/modules/gdnative/net/register_types.cpp b/modules/gdnative/net/register_types.cpp index 645c43b7e3..46c383e5ae 100644 --- a/modules/gdnative/net/register_types.cpp +++ b/modules/gdnative/net/register_types.cpp @@ -34,9 +34,9 @@ #include "stream_peer_gdnative.h" void register_net_types() { - ClassDB::register_class<MultiplayerPeerGDNative>(); - ClassDB::register_class<PacketPeerGDNative>(); - ClassDB::register_class<StreamPeerGDNative>(); + GDREGISTER_CLASS(MultiplayerPeerGDNative); + GDREGISTER_CLASS(PacketPeerGDNative); + GDREGISTER_CLASS(StreamPeerGDNative); } void unregister_net_types() { diff --git a/modules/gdnative/pluginscript/register_types.cpp b/modules/gdnative/pluginscript/register_types.cpp index 433544178f..7faacfdcb9 100644 --- a/modules/gdnative/pluginscript/register_types.cpp +++ b/modules/gdnative/pluginscript/register_types.cpp @@ -107,7 +107,7 @@ void GDAPI godot_pluginscript_register_language(const godot_pluginscript_languag } void register_pluginscript_types() { - ClassDB::register_class<PluginScript>(); + GDREGISTER_CLASS(PluginScript); } void unregister_pluginscript_types() { diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index 8e20a2b90d..8e5ae29ed9 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -259,8 +259,8 @@ void register_gdnative_types() { EditorNode::add_init_callback(editor_init_callback); #endif - ClassDB::register_class<GDNativeLibrary>(); - ClassDB::register_class<GDNative>(); + GDREGISTER_CLASS(GDNativeLibrary); + GDREGISTER_CLASS(GDNative); resource_loader_gdnlib.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_gdnlib); diff --git a/modules/gdnative/text/text_server_gdnative.cpp b/modules/gdnative/text/text_server_gdnative.cpp index bc4b1ac134..81dd570bcb 100644 --- a/modules/gdnative/text/text_server_gdnative.cpp +++ b/modules/gdnative/text/text_server_gdnative.cpp @@ -498,6 +498,11 @@ bool TextServerGDNative::shaped_text_update_justification_ops(RID p_shaped) { return interface->shaped_text_update_justification_ops(data, (godot_rid *)&p_shaped); } +void TextServerGDNative::shaped_text_overrun_trim_to_width(RID p_shaped_line, float p_width, uint8_t p_clip_flags) { + ERR_FAIL_COND(interface == nullptr); + interface->shaped_text_overrun_trim_to_width(data, (godot_rid *)&p_shaped_line, p_width, p_clip_flags); +}; + bool TextServerGDNative::shaped_text_is_ready(RID p_shaped) const { ERR_FAIL_COND_V(interface == nullptr, false); return interface->shaped_text_is_ready(data, (godot_rid *)&p_shaped); @@ -550,15 +555,15 @@ Vector<Vector2i> TextServerGDNative::shaped_text_get_line_breaks(RID p_shaped, f } } -Vector<Vector2i> TextServerGDNative::shaped_text_get_word_breaks(RID p_shaped) const { +Vector<Vector2i> TextServerGDNative::shaped_text_get_word_breaks(RID p_shaped, int p_grapheme_flags) const { ERR_FAIL_COND_V(interface == nullptr, Vector<Vector2i>()); if (interface->shaped_text_get_word_breaks != nullptr) { - godot_packed_vector2i_array result = interface->shaped_text_get_word_breaks(data, (godot_rid *)&p_shaped); + godot_packed_vector2i_array result = interface->shaped_text_get_word_breaks(data, (godot_rid *)&p_shaped, p_grapheme_flags); Vector<Vector2i> breaks = *(Vector<Vector2i> *)&result; godot_packed_vector2i_array_destroy(&result); return breaks; } else { - return TextServer::shaped_text_get_word_breaks(p_shaped); + return TextServer::shaped_text_get_word_breaks(p_shaped, p_grapheme_flags); } } diff --git a/modules/gdnative/text/text_server_gdnative.h b/modules/gdnative/text/text_server_gdnative.h index 7e42b16fe1..7a0725f3d9 100644 --- a/modules/gdnative/text/text_server_gdnative.h +++ b/modules/gdnative/text/text_server_gdnative.h @@ -167,6 +167,8 @@ public: virtual bool shaped_text_update_breaks(RID p_shaped) override; virtual bool shaped_text_update_justification_ops(RID p_shaped) override; + virtual void shaped_text_overrun_trim_to_width(RID p_shaped, float p_width, uint8_t p_clip_flags) override; + virtual bool shaped_text_is_ready(RID p_shaped) const override; virtual Vector<Glyph> shaped_text_get_glyphs(RID p_shaped) const override; @@ -176,7 +178,7 @@ public: virtual Vector<Glyph> shaped_text_sort_logical(RID p_shaped) override; virtual Vector<Vector2i> shaped_text_get_line_breaks_adv(RID p_shaped, const Vector<float> &p_width, int p_start = 0, bool p_once = true, uint8_t /*TextBreakFlag*/ p_break_flags = BREAK_MANDATORY | BREAK_WORD_BOUND) const override; virtual Vector<Vector2i> shaped_text_get_line_breaks(RID p_shaped, float p_width, int p_start = 0, uint8_t p_break_flags = BREAK_MANDATORY | BREAK_WORD_BOUND) const override; - virtual Vector<Vector2i> shaped_text_get_word_breaks(RID p_shaped) const override; + virtual Vector<Vector2i> shaped_text_get_word_breaks(RID p_shaped, int p_grapheme_flags = GRAPHEME_IS_SPACE | GRAPHEME_IS_PUNCTUATION) const override; virtual Array shaped_text_get_objects(RID p_shaped) const override; virtual Rect2 shaped_text_get_object_rect(RID p_shaped, Variant p_key) const override; diff --git a/modules/gdnative/videodecoder/register_types.cpp b/modules/gdnative/videodecoder/register_types.cpp index e822d42312..54a577a2b6 100644 --- a/modules/gdnative/videodecoder/register_types.cpp +++ b/modules/gdnative/videodecoder/register_types.cpp @@ -39,7 +39,7 @@ void register_videodecoder_types() { resource_loader_vsgdnative.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_vsgdnative, true); - ClassDB::register_class<VideoStreamGDNative>(); + GDREGISTER_CLASS(VideoStreamGDNative); } void unregister_videodecoder_types() { diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.cpp b/modules/gdnative/videodecoder/video_stream_gdnative.cpp index 26b044c0ef..4c9bfb395d 100644 --- a/modules/gdnative/videodecoder/video_stream_gdnative.cpp +++ b/modules/gdnative/videodecoder/video_stream_gdnative.cpp @@ -185,7 +185,7 @@ void VideoStreamPlaybackGDNative::update_texture() { Ref<Image> img = memnew(Image(texture_size.width, texture_size.height, 0, Image::FORMAT_RGBA8, *pba)); - texture->update(img, true); + texture->update(img); } // ctor and dtor diff --git a/modules/gdnative/xr/register_types.cpp b/modules/gdnative/xr/register_types.cpp index b60a04f470..cb043debc5 100644 --- a/modules/gdnative/xr/register_types.cpp +++ b/modules/gdnative/xr/register_types.cpp @@ -32,7 +32,7 @@ #include "xr_interface_gdnative.h" void register_xr_types() { - ClassDB::register_class<XRInterfaceGDNative>(); + GDREGISTER_CLASS(XRInterfaceGDNative); ClassDB::add_compatibility_class("ARVRInterfaceGDNative", "XRInterfaceGDNative"); } diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index 79ec9eb65f..9a4c22f49f 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -448,7 +448,7 @@ void GDScriptSyntaxHighlighter::_update_cache() { color_regions.clear(); color_region_cache.clear(); - font_color = text_edit->get_theme_color("font_color"); + font_color = text_edit->get_theme_color(SNAME("font_color")); symbol_color = EDITOR_GET("text_editor/highlighting/symbol_color"); function_color = EDITOR_GET("text_editor/highlighting/function_color"); number_color = EDITOR_GET("text_editor/highlighting/number_color"); diff --git a/modules/gdscript/editor/gdscript_translation_parser_plugin.h b/modules/gdscript/editor/gdscript_translation_parser_plugin.h index fcf438422a..caa80fc24c 100644 --- a/modules/gdscript/editor/gdscript_translation_parser_plugin.h +++ b/modules/gdscript/editor/gdscript_translation_parser_plugin.h @@ -34,7 +34,6 @@ #include "core/templates/set.h" #include "editor/editor_translation_parser.h" #include "modules/gdscript/gdscript_parser.h" -#include "modules/regex/regex.h" class GDScriptEditorTranslationParserPlugin : public EditorTranslationParserPlugin { GDCLASS(GDScriptEditorTranslationParserPlugin, EditorTranslationParserPlugin); diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 397776ba1a..d0b7722847 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1165,15 +1165,11 @@ void GDScript::_init_rpc_methods_properties() { while (cscript) { // RPC Methods for (Map<StringName, GDScriptFunction *>::Element *E = cscript->member_functions.front(); E; E = E->next()) { - if (E->get()->get_rpc_mode() != MultiplayerAPI::RPC_MODE_DISABLED) { - MultiplayerAPI::RPCConfig nd; - nd.name = E->key(); - nd.rpc_mode = E->get()->get_rpc_mode(); - // TODO - nd.transfer_mode = NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE; - nd.channel = 0; - if (-1 == rpc_functions.find(nd)) { - rpc_functions.push_back(nd); + MultiplayerAPI::RPCConfig config = E->get()->get_rpc_config(); + if (config.rpc_mode != MultiplayerAPI::RPC_MODE_DISABLED) { + config.name = E->get()->get_name(); + if (rpc_functions.find(config) == -1) { + rpc_functions.push_back(config); } } } diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 078b7a2fd0..24809ad5fd 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -64,7 +64,6 @@ class GDScript : public Script { int index = 0; StringName setter; StringName getter; - MultiplayerAPI::RPCMode rpc_mode; GDScriptDataType data_type; }; diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp index 5a297cc50a..9ff5a342ec 100644 --- a/modules/gdscript/gdscript_byte_codegen.cpp +++ b/modules/gdscript/gdscript_byte_codegen.cpp @@ -155,7 +155,7 @@ void GDScriptByteCodeGenerator::end_parameters() { function->default_arguments.reverse(); } -void GDScriptByteCodeGenerator::write_start(GDScript *p_script, const StringName &p_function_name, bool p_static, MultiplayerAPI::RPCMode p_rpc_mode, const GDScriptDataType &p_return_type) { +void GDScriptByteCodeGenerator::write_start(GDScript *p_script, const StringName &p_function_name, bool p_static, MultiplayerAPI::RPCConfig p_rpc_config, const GDScriptDataType &p_return_type) { function = memnew(GDScriptFunction); debug_stack = EngineDebugger::is_active(); @@ -170,7 +170,7 @@ void GDScriptByteCodeGenerator::write_start(GDScript *p_script, const StringName function->_static = p_static; function->return_type = p_return_type; - function->rpc_mode = p_rpc_mode; + function->rpc_config = p_rpc_config; function->_argument_count = 0; } diff --git a/modules/gdscript/gdscript_byte_codegen.h b/modules/gdscript/gdscript_byte_codegen.h index b1f3cd5fb3..3d6fb291ad 100644 --- a/modules/gdscript/gdscript_byte_codegen.h +++ b/modules/gdscript/gdscript_byte_codegen.h @@ -419,7 +419,7 @@ public: virtual void start_block() override; virtual void end_block() override; - virtual void write_start(GDScript *p_script, const StringName &p_function_name, bool p_static, MultiplayerAPI::RPCMode p_rpc_mode, const GDScriptDataType &p_return_type) override; + virtual void write_start(GDScript *p_script, const StringName &p_function_name, bool p_static, MultiplayerAPI::RPCConfig p_rpc_config, const GDScriptDataType &p_return_type) override; virtual GDScriptFunction *write_end() override; #ifdef DEBUG_ENABLED diff --git a/modules/gdscript/gdscript_codegen.h b/modules/gdscript/gdscript_codegen.h index cac6544f03..ecc86c37f3 100644 --- a/modules/gdscript/gdscript_codegen.h +++ b/modules/gdscript/gdscript_codegen.h @@ -80,7 +80,7 @@ public: virtual void start_block() = 0; virtual void end_block() = 0; - virtual void write_start(GDScript *p_script, const StringName &p_function_name, bool p_static, MultiplayerAPI::RPCMode p_rpc_mode, const GDScriptDataType &p_return_type) = 0; + virtual void write_start(GDScript *p_script, const StringName &p_function_name, bool p_static, MultiplayerAPI::RPCConfig p_rpc_config, const GDScriptDataType &p_return_type) = 0; virtual GDScriptFunction *write_end() = 0; #ifdef DEBUG_ENABLED diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 7fa8e9c067..fbe791a109 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -1859,7 +1859,7 @@ GDScriptFunction *GDScriptCompiler::_parse_function(Error &r_error, GDScript *p_ StringName func_name; bool is_static = false; - MultiplayerAPI::RPCMode rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED; + MultiplayerAPI::RPCConfig rpc_config; GDScriptDataType return_type; return_type.has_type = true; return_type.kind = GDScriptDataType::BUILTIN; @@ -1872,7 +1872,7 @@ GDScriptFunction *GDScriptCompiler::_parse_function(Error &r_error, GDScript *p_ func_name = "<anonymous lambda>"; } is_static = p_func->is_static; - rpc_mode = p_func->rpc_mode; + rpc_config = p_func->rpc_config; return_type = _gdtype_from_datatype(p_func->get_datatype(), p_script); } else { if (p_for_ready) { @@ -1883,7 +1883,7 @@ GDScriptFunction *GDScriptCompiler::_parse_function(Error &r_error, GDScript *p_ } codegen.function_name = func_name; - codegen.generator->write_start(p_script, func_name, is_static, rpc_mode, return_type); + codegen.generator->write_start(p_script, func_name, is_static, rpc_config, return_type); int optional_parameters = 0; @@ -2088,7 +2088,7 @@ Error GDScriptCompiler::_parse_setter_getter(GDScript *p_script, const GDScriptP return_type = _gdtype_from_datatype(p_variable->get_datatype(), p_script); } - codegen.generator->write_start(p_script, func_name, false, p_variable->rpc_mode, return_type); + codegen.generator->write_start(p_script, func_name, false, MultiplayerAPI::RPCConfig(), return_type); if (p_is_setter) { uint32_t par_addr = codegen.generator->add_parameter(p_variable->setter_parameter->name, false, _gdtype_from_datatype(p_variable->get_datatype())); @@ -2268,7 +2268,6 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar } break; } - minfo.rpc_mode = variable->rpc_mode; minfo.data_type = _gdtype_from_datatype(variable->get_datatype(), p_script); PropertyInfo prop_info = minfo.data_type; diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index b149828a2f..c1a7bedbc8 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -3038,9 +3038,9 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co if (!is_function) { // Guess in autoloads as singletons. if (ProjectSettings::get_singleton()->has_autoload(p_symbol)) { - const ProjectSettings::AutoloadInfo &singleton = ProjectSettings::get_singleton()->get_autoload(p_symbol); - if (singleton.is_singleton) { - String script = singleton.path; + const ProjectSettings::AutoloadInfo &autoload = ProjectSettings::get_singleton()->get_autoload(p_symbol); + if (autoload.is_singleton) { + String script = autoload.path; if (!script.ends_with(".gd")) { // Not a script, try find the script anyway, // may have some success. diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 78399114a5..f300d5a2c9 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -262,9 +262,9 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) { if (completed) { if (first_state.is_valid()) { - first_state->emit_signal("completed", ret); + first_state->emit_signal(SNAME("completed"), ret); } else { - emit_signal("completed", ret); + emit_signal(SNAME("completed"), ret); } #ifdef DEBUG_ENABLED diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h index 553c2ecc01..9e5ef0f632 100644 --- a/modules/gdscript/gdscript_function.h +++ b/modules/gdscript/gdscript_function.h @@ -472,7 +472,7 @@ private: int _initial_line = 0; bool _static = false; - MultiplayerAPI::RPCMode rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED; + MultiplayerAPI::RPCConfig rpc_config; GDScript *_script = nullptr; @@ -592,7 +592,7 @@ public: void disassemble(const Vector<String> &p_code_lines) const; #endif - _FORCE_INLINE_ MultiplayerAPI::RPCMode get_rpc_mode() const { return rpc_mode; } + _FORCE_INLINE_ MultiplayerAPI::RPCConfig get_rpc_config() const { return rpc_config; } GDScriptFunction(); ~GDScriptFunction(); }; diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index ba208ebfe8..df36afc0f0 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -157,7 +157,6 @@ GDScriptParser::GDScriptParser() { register_annotation(MethodInfo("@export_multiline"), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_MULTILINE_TEXT, Variant::STRING>); register_annotation(MethodInfo("@export_placeholder"), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_PLACEHOLDER_TEXT, Variant::STRING>); register_annotation(MethodInfo("@export_range", { Variant::FLOAT, "min" }, { Variant::FLOAT, "max" }, { Variant::FLOAT, "step" }, { Variant::STRING, "slider1" }, { Variant::STRING, "slider2" }), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_RANGE, Variant::FLOAT>, 3); - register_annotation(MethodInfo("@export_exp_range", { Variant::FLOAT, "min" }, { Variant::FLOAT, "max" }, { Variant::FLOAT, "step" }, { Variant::STRING, "slider1" }, { Variant::STRING, "slider2" }), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_EXP_RANGE, Variant::FLOAT>, 3); register_annotation(MethodInfo("@export_exp_easing", { Variant::STRING, "hint1" }, { Variant::STRING, "hint2" }), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_EXP_EASING, Variant::FLOAT>, 2); register_annotation(MethodInfo("@export_color_no_alpha"), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_COLOR_NO_ALPHA, Variant::COLOR>); register_annotation(MethodInfo("@export_node_path", { Variant::STRING, "type" }), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_NODE_PATH_VALID_TYPES, Variant::NODE_PATH>, 1, true); @@ -169,12 +168,7 @@ GDScriptParser::GDScriptParser() { register_annotation(MethodInfo("@export_flags_3d_physics"), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_LAYERS_3D_PHYSICS, Variant::INT>); register_annotation(MethodInfo("@export_flags_3d_navigation"), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_LAYERS_3D_NAVIGATION, Variant::INT>); // Networking. - register_annotation(MethodInfo("@remote"), AnnotationInfo::VARIABLE | AnnotationInfo::FUNCTION, &GDScriptParser::network_annotations<MultiplayerAPI::RPC_MODE_REMOTE>); - register_annotation(MethodInfo("@master"), AnnotationInfo::VARIABLE | AnnotationInfo::FUNCTION, &GDScriptParser::network_annotations<MultiplayerAPI::RPC_MODE_MASTER>); - register_annotation(MethodInfo("@puppet"), AnnotationInfo::VARIABLE | AnnotationInfo::FUNCTION, &GDScriptParser::network_annotations<MultiplayerAPI::RPC_MODE_PUPPET>); - register_annotation(MethodInfo("@remotesync"), AnnotationInfo::VARIABLE | AnnotationInfo::FUNCTION, &GDScriptParser::network_annotations<MultiplayerAPI::RPC_MODE_REMOTESYNC>); - register_annotation(MethodInfo("@mastersync"), AnnotationInfo::VARIABLE | AnnotationInfo::FUNCTION, &GDScriptParser::network_annotations<MultiplayerAPI::RPC_MODE_MASTERSYNC>); - register_annotation(MethodInfo("@puppetsync"), AnnotationInfo::VARIABLE | AnnotationInfo::FUNCTION, &GDScriptParser::network_annotations<MultiplayerAPI::RPC_MODE_PUPPETSYNC>); + register_annotation(MethodInfo("@rpc", { Variant::STRING, "mode" }, { Variant::STRING, "sync" }, { Variant::STRING, "transfer_mode" }, { Variant::INT, "transfer_channel" }), AnnotationInfo::FUNCTION, &GDScriptParser::network_annotations<MultiplayerAPI::RPC_MODE_MASTER>, 4, true); // TODO: Warning annotations. } @@ -3431,27 +3425,60 @@ template <MultiplayerAPI::RPCMode t_mode> bool GDScriptParser::network_annotations(const AnnotationNode *p_annotation, Node *p_node) { ERR_FAIL_COND_V_MSG(p_node->type != Node::VARIABLE && p_node->type != Node::FUNCTION, false, vformat(R"("%s" annotation can only be applied to variables and functions.)", p_annotation->name)); - switch (p_node->type) { - case Node::VARIABLE: { - VariableNode *variable = static_cast<VariableNode *>(p_node); - if (variable->rpc_mode != MultiplayerAPI::RPC_MODE_DISABLED) { - push_error(R"(RPC annotations can only be used once per variable.)", p_annotation); + MultiplayerAPI::RPCConfig rpc_config; + rpc_config.rpc_mode = t_mode; + for (int i = 0; i < p_annotation->resolved_arguments.size(); i++) { + if (i == 0) { + String mode = p_annotation->resolved_arguments[i].operator String(); + if (mode == "any") { + rpc_config.rpc_mode = MultiplayerAPI::RPC_MODE_REMOTE; + } else if (mode == "master") { + rpc_config.rpc_mode = MultiplayerAPI::RPC_MODE_MASTER; + } else if (mode == "puppet") { + rpc_config.rpc_mode = MultiplayerAPI::RPC_MODE_PUPPET; + } else { + push_error(R"(Invalid RPC mode. Must be one of: 'any', 'master', or 'puppet')", p_annotation); + return false; } - variable->rpc_mode = t_mode; - break; + } else if (i == 1) { + String sync = p_annotation->resolved_arguments[i].operator String(); + if (sync == "sync") { + rpc_config.sync = true; + } else if (sync == "nosync") { + rpc_config.sync = false; + } else { + push_error(R"(Invalid RPC sync mode. Must be one of: 'sync' or 'nosync')", p_annotation); + return false; + } + } else if (i == 2) { + String mode = p_annotation->resolved_arguments[i].operator String(); + if (mode == "reliable") { + rpc_config.transfer_mode = MultiplayerPeer::TRANSFER_MODE_RELIABLE; + } else if (mode == "unreliable") { + rpc_config.transfer_mode = MultiplayerPeer::TRANSFER_MODE_UNRELIABLE; + } else if (mode == "ordered") { + rpc_config.transfer_mode = MultiplayerPeer::TRANSFER_MODE_UNRELIABLE_ORDERED; + } else { + push_error(R"(Invalid RPC transfer mode. Must be one of: 'reliable', 'unreliable', 'ordered')", p_annotation); + return false; + } + } else if (i == 3) { + rpc_config.channel = p_annotation->resolved_arguments[i].operator int(); } + } + switch (p_node->type) { case Node::FUNCTION: { FunctionNode *function = static_cast<FunctionNode *>(p_node); - if (function->rpc_mode != MultiplayerAPI::RPC_MODE_DISABLED) { + if (function->rpc_config.rpc_mode != MultiplayerAPI::RPC_MODE_DISABLED) { push_error(R"(RPC annotations can only be used once per function.)", p_annotation); + return false; } - function->rpc_mode = t_mode; + function->rpc_config = rpc_config; break; } default: return false; // Unreachable. } - return true; } diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 9e0b60a407..043d87c705 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -729,7 +729,7 @@ public: SuiteNode *body = nullptr; bool is_static = false; bool is_coroutine = false; - MultiplayerAPI::RPCMode rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED; + MultiplayerAPI::RPCConfig rpc_config; MethodInfo info; LambdaNode *source_lambda = nullptr; #ifdef TOOLS_ENABLED @@ -1117,7 +1117,6 @@ public: bool exported = false; bool onready = false; PropertyInfo export_info; - MultiplayerAPI::RPCMode rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED; int assignments = 0; int usages = 0; bool use_conversion_assign = false; diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp index f817964a3c..e9a7bf3830 100644 --- a/modules/gdscript/language_server/gdscript_extend_parser.cpp +++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp @@ -695,7 +695,9 @@ Dictionary ExtendGDScriptParser::dump_function_api(const GDScriptParser::Functio ERR_FAIL_NULL_V(p_func, func); func["name"] = p_func->identifier->name; func["return_type"] = p_func->get_datatype().to_string(); - func["rpc_mode"] = p_func->rpc_mode; + func["rpc_mode"] = p_func->rpc_config.rpc_mode; + func["rpc_transfer_mode"] = p_func->rpc_config.transfer_mode; + func["rpc_transfer_channel"] = p_func->rpc_config.channel; Array parameters; for (int i = 0; i < p_func->parameters.size(); i++) { Dictionary arg; diff --git a/modules/gdscript/language_server/gdscript_language_protocol.h b/modules/gdscript/language_server/gdscript_language_protocol.h index 969c38eab6..5a2dd55c46 100644 --- a/modules/gdscript/language_server/gdscript_language_protocol.h +++ b/modules/gdscript/language_server/gdscript_language_protocol.h @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef GDSCRIPT_PROTOCAL_SERVER_H -#define GDSCRIPT_PROTOCAL_SERVER_H +#ifndef GDSCRIPT_LANGUAGE_PROTOCOL_H +#define GDSCRIPT_LANGUAGE_PROTOCOL_H #include "core/io/stream_peer.h" #include "core/io/stream_peer_tcp.h" @@ -37,7 +37,13 @@ #include "gdscript_text_document.h" #include "gdscript_workspace.h" #include "lsp.hpp" + +#include "modules/modules_enabled.gen.h" +#ifdef MODULE_JSONRPC_ENABLED #include "modules/jsonrpc/jsonrpc.h" +#else +#error "Can't build GDScript LSP without JSONRPC module." +#endif #define LSP_MAX_BUFFER_SIZE 4194304 #define LSP_MAX_CLIENTS 8 @@ -108,4 +114,4 @@ public: GDScriptLanguageProtocol(); }; -#endif +#endif // GDSCRIPT_LANGUAGE_PROTOCOL_H diff --git a/modules/gdscript/language_server/gdscript_language_server.cpp b/modules/gdscript/language_server/gdscript_language_server.cpp index 33597c286f..c47164d95b 100644 --- a/modules/gdscript/language_server/gdscript_language_server.cpp +++ b/modules/gdscript/language_server/gdscript_language_server.cpp @@ -101,7 +101,7 @@ void GDScriptLanguageServer::stop() { } void register_lsp_types() { - ClassDB::register_class<GDScriptLanguageProtocol>(); - ClassDB::register_class<GDScriptTextDocument>(); - ClassDB::register_class<GDScriptWorkspace>(); + GDREGISTER_CLASS(GDScriptLanguageProtocol); + GDREGISTER_CLASS(GDScriptTextDocument); + GDREGISTER_CLASS(GDScriptWorkspace); } diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp index 030633274c..55aff618aa 100644 --- a/modules/gdscript/language_server/gdscript_text_document.cpp +++ b/modules/gdscript/language_server/gdscript_text_document.cpp @@ -40,6 +40,7 @@ void GDScriptTextDocument::_bind_methods() { ClassDB::bind_method(D_METHOD("didOpen"), &GDScriptTextDocument::didOpen); + ClassDB::bind_method(D_METHOD("didClose"), &GDScriptTextDocument::didClose); ClassDB::bind_method(D_METHOD("didChange"), &GDScriptTextDocument::didChange); ClassDB::bind_method(D_METHOD("nativeSymbol"), &GDScriptTextDocument::nativeSymbol); ClassDB::bind_method(D_METHOD("documentSymbol"), &GDScriptTextDocument::documentSymbol); @@ -61,6 +62,11 @@ void GDScriptTextDocument::didOpen(const Variant &p_param) { sync_script_content(doc.uri, doc.text); } +void GDScriptTextDocument::didClose(const Variant &p_param) { + // Left empty on purpose. Godot does nothing special on closing a document, + // but it satisfies LSP clients that require didClose be implemented. +} + void GDScriptTextDocument::didChange(const Variant &p_param) { lsp::TextDocumentItem doc = load_document_item(p_param); Dictionary dict = p_param; @@ -367,7 +373,7 @@ Variant GDScriptTextDocument::declaration(const Dictionary &p_params) { id = "class_global:" + symbol->native_class + ":" + symbol->name; break; } - call_deferred("show_native_symbol_in_editor", id); + call_deferred(SNAME("show_native_symbol_in_editor"), id); } else { notify_client_show_symbol(symbol); } @@ -404,7 +410,7 @@ void GDScriptTextDocument::sync_script_content(const String &p_path, const Strin } void GDScriptTextDocument::show_native_symbol_in_editor(const String &p_symbol_id) { - ScriptEditor::get_singleton()->call_deferred("_help_class_goto", p_symbol_id); + ScriptEditor::get_singleton()->call_deferred(SNAME("_help_class_goto"), p_symbol_id); DisplayServer::get_singleton()->window_move_to_foreground(); } diff --git a/modules/gdscript/language_server/gdscript_text_document.h b/modules/gdscript/language_server/gdscript_text_document.h index 17f1d5d5e3..e2987f779c 100644 --- a/modules/gdscript/language_server/gdscript_text_document.h +++ b/modules/gdscript/language_server/gdscript_text_document.h @@ -43,6 +43,7 @@ protected: FileAccess *file_checker; void didOpen(const Variant &p_param); + void didClose(const Variant &p_param); void didChange(const Variant &p_param); void sync_script_content(const String &p_path, const String &p_content); diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index ad4ed8bf71..c2b1981f31 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -112,7 +112,7 @@ static void _editor_init() { #endif // TOOLS_ENABLED void register_gdscript_types() { - ClassDB::register_class<GDScript>(); + GDREGISTER_CLASS(GDScript); script_language_gd = memnew(GDScriptLanguage); ScriptServer::register_language(script_language_gd); diff --git a/modules/gltf/editor_scene_importer_gltf.cpp b/modules/gltf/editor_scene_importer_gltf.cpp index cef5278f03..eca1c85bf3 100644 --- a/modules/gltf/editor_scene_importer_gltf.cpp +++ b/modules/gltf/editor_scene_importer_gltf.cpp @@ -28,22 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "core/crypto/crypto_core.h" -#include "core/io/file_access.h" -#include "core/math/disjoint_set.h" -#include "core/math/math_defs.h" -#include "core/os/os.h" -#include "editor/import/resource_importer_scene.h" -#include "modules/gltf/gltf_state.h" -#include "modules/regex/regex.h" -#include "scene/3d/bone_attachment_3d.h" -#include "scene/3d/camera_3d.h" -#include "scene/3d/mesh_instance_3d.h" -#include "scene/animation/animation_player.h" -#include "scene/resources/packed_scene.h" -#include "scene/resources/surface_tool.h" +#include "editor_scene_importer_gltf.h" + +#include "gltf_document.h" +#include "gltf_state.h" -#include "modules/gltf/editor_scene_importer_gltf.h" +#include "scene/3d/node_3d.h" +#include "scene/animation/animation_player.h" +#include "scene/resources/animation.h" uint32_t EditorSceneImporterGLTF::get_import_flags() const { return ImportFlags::IMPORT_SCENE | ImportFlags::IMPORT_ANIMATION; diff --git a/modules/gltf/editor_scene_importer_gltf.h b/modules/gltf/editor_scene_importer_gltf.h index 566d5cfd34..7bc5f594ed 100644 --- a/modules/gltf/editor_scene_importer_gltf.h +++ b/modules/gltf/editor_scene_importer_gltf.h @@ -31,28 +31,13 @@ #ifndef EDITOR_SCENE_IMPORTER_GLTF_H #define EDITOR_SCENE_IMPORTER_GLTF_H -#include "core/config/project_settings.h" -#include "core/object/object.h" -#include "core/templates/vector.h" +#include "gltf_state.h" + #include "editor/import/resource_importer_scene.h" -#include "modules/csg/csg_shape.h" -#include "modules/gridmap/grid_map.h" -#include "scene/3d/mesh_instance_3d.h" -#include "scene/3d/multimesh_instance_3d.h" -#include "scene/3d/node_3d.h" -#include "scene/3d/skeleton_3d.h" -#include "scene/animation/animation_player.h" -#include "scene/gui/check_box.h" #include "scene/main/node.h" #include "scene/resources/packed_scene.h" -#include "scene/resources/surface_tool.h" - -#include "gltf_document.h" -#include "gltf_state.h" -class AnimationPlayer; -class BoneAttachment; -class EditorSceneImporterMeshNode3D; +class Animation; #ifdef TOOLS_ENABLED class EditorSceneImporterGLTF : public EditorSceneImporter { diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 674403905a..71a9b3667f 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -29,9 +29,7 @@ /*************************************************************************/ #include "gltf_document.h" -#include "core/error/error_list.h" -#include "core/error/error_macros.h" -#include "core/variant/variant.h" + #include "gltf_accessor.h" #include "gltf_animation.h" #include "gltf_camera.h" @@ -44,35 +42,33 @@ #include "gltf_state.h" #include "gltf_texture.h" -#include <stdio.h> -#include <stdlib.h> - -#include "core/core_bind.h" #include "core/crypto/crypto_core.h" +#include "core/io/dir_access.h" #include "core/io/file_access.h" #include "core/io/json.h" #include "core/math/disjoint_set.h" #include "core/variant/typed_array.h" +#include "core/variant/variant.h" #include "core/version.h" #include "core/version_hash.gen.h" #include "drivers/png/png_driver_common.h" #include "editor/import/resource_importer_scene.h" +#include "scene/2d/node_2d.h" +#include "scene/3d/camera_3d.h" +#include "scene/3d/multimesh_instance_3d.h" +#include "scene/animation/animation_player.h" +#include "scene/resources/surface_tool.h" + +#include "modules/modules_enabled.gen.h" #ifdef MODULE_CSG_ENABLED #include "modules/csg/csg_shape.h" #endif // MODULE_CSG_ENABLED #ifdef MODULE_GRIDMAP_ENABLED #include "modules/gridmap/grid_map.h" #endif // MODULE_GRIDMAP_ENABLED -#include "scene/2d/node_2d.h" -#include "scene/3d/bone_attachment_3d.h" -#include "scene/3d/camera_3d.h" -#include "scene/3d/mesh_instance_3d.h" -#include "scene/3d/multimesh_instance_3d.h" -#include "scene/3d/node_3d.h" -#include "scene/3d/skeleton_3d.h" -#include "scene/animation/animation_player.h" -#include "scene/main/node.h" -#include "scene/resources/surface_tool.h" + +#include <stdio.h> +#include <stdlib.h> #include <limits> Error GLTFDocument::serialize(Ref<GLTFState> state, Node *p_root, const String &p_path) { @@ -2873,16 +2869,13 @@ Error GLTFDocument::_serialize_images(Ref<GLTFState> state, const String &p_path name = itos(i); } name = _gen_unique_name(state, name); - name = name.pad_zeros(3); - Ref<_Directory> dir; - dir.instantiate(); + name = name.pad_zeros(3) + ".png"; String texture_dir = "textures"; String new_texture_dir = p_path.get_base_dir() + "/" + texture_dir; - dir->open(p_path.get_base_dir()); - if (!dir->dir_exists(new_texture_dir)) { - dir->make_dir(new_texture_dir); + DirAccessRef da = DirAccess::open(p_path.get_base_dir()); + if (!da->dir_exists(new_texture_dir)) { + da->make_dir(new_texture_dir); } - name = name + ".png"; image->save_png(new_texture_dir.plus_file(name)); d["uri"] = texture_dir.plus_file(name); } @@ -5537,6 +5530,8 @@ struct EditorSceneImporterGLTFInterpolate<Quaternion> { template <class T> T GLTFDocument::_interpolate_track(const Vector<float> &p_times, const Vector<T> &p_values, const float p_time, const GLTFAnimation::Interpolation p_interp) { + ERR_FAIL_COND_V(!p_values.size(), T()); + ERR_FAIL_COND_V(p_times.size() != p_values.size(), p_values[0]); //could use binary search, worth it? int idx = -1; for (int i = 0; i < p_times.size(); i++) { @@ -6087,7 +6082,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state Vector3 translation = p_animation->track_get_key_value(p_track_i, key_i); p_track.translation_track.values.write[key_i] = translation; } - } else if (path.find(":rotation_degrees") != -1) { + } else if (path.find(":rotation") != -1) { p_track.rotation_track.times = times; p_track.rotation_track.interpolation = gltf_interpolation; @@ -6095,11 +6090,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state p_track.rotation_track.interpolation = gltf_interpolation; for (int32_t key_i = 0; key_i < key_count; key_i++) { - Vector3 rotation_degrees = p_animation->track_get_key_value(p_track_i, key_i); - Vector3 rotation_radian; - rotation_radian.x = Math::deg2rad(rotation_degrees.x); - rotation_radian.y = Math::deg2rad(rotation_degrees.y); - rotation_radian.z = Math::deg2rad(rotation_degrees.z); + Vector3 rotation_radian = p_animation->track_get_key_value(p_track_i, key_i); p_track.rotation_track.values.write[key_i] = Quaternion(rotation_radian); } } else if (path.find(":scale") != -1) { diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h index 514373c4f0..3e8ea19045 100644 --- a/modules/gltf/gltf_document.h +++ b/modules/gltf/gltf_document.h @@ -31,11 +31,9 @@ #ifndef GLTF_DOCUMENT_H #define GLTF_DOCUMENT_H -#include "editor/import/resource_importer_scene.h" -#include "editor/import/scene_importer_mesh_node_3d.h" #include "gltf_animation.h" -#include "modules/modules_enabled.gen.h" -#include "scene/2d/node_2d.h" + +#include "editor/import/scene_importer_mesh_node_3d.h" #include "scene/3d/bone_attachment_3d.h" #include "scene/3d/light_3d.h" #include "scene/3d/mesh_instance_3d.h" @@ -45,6 +43,8 @@ #include "scene/resources/material.h" #include "scene/resources/texture.h" +#include "modules/modules_enabled.gen.h" + class GLTFState; class GLTFSkin; class GLTFNode; diff --git a/modules/gltf/gltf_state.h b/modules/gltf/gltf_state.h index ba6bf8a533..d8209523c5 100644 --- a/modules/gltf/gltf_state.h +++ b/modules/gltf/gltf_state.h @@ -31,9 +31,6 @@ #ifndef GLTF_STATE_H #define GLTF_STATE_H -#include "core/io/resource.h" -#include "core/templates/vector.h" -#include "editor_scene_importer_gltf.h" #include "gltf_accessor.h" #include "gltf_animation.h" #include "gltf_buffer_view.h" @@ -45,6 +42,9 @@ #include "gltf_skeleton.h" #include "gltf_skin.h" #include "gltf_texture.h" + +#include "core/io/resource.h" +#include "core/templates/vector.h" #include "scene/animation/animation_player.h" #include "scene/resources/texture.h" diff --git a/modules/gltf/register_types.cpp b/modules/gltf/register_types.cpp index d11c7cb9cd..85921490d2 100644 --- a/modules/gltf/register_types.cpp +++ b/modules/gltf/register_types.cpp @@ -62,25 +62,25 @@ void register_gltf_types() { #ifdef TOOLS_ENABLED ClassDB::APIType prev_api = ClassDB::get_current_api(); ClassDB::set_current_api(ClassDB::API_EDITOR); - ClassDB::register_class<EditorSceneImporterGLTF>(); - ClassDB::register_class<GLTFMesh>(); + GDREGISTER_CLASS(EditorSceneImporterGLTF); + GDREGISTER_CLASS(GLTFMesh); EditorPlugins::add_by_type<SceneExporterGLTFPlugin>(); ClassDB::set_current_api(prev_api); EditorNode::add_init_callback(_editor_init); #endif - ClassDB::register_class<GLTFSpecGloss>(); - ClassDB::register_class<GLTFNode>(); - ClassDB::register_class<GLTFAnimation>(); - ClassDB::register_class<GLTFBufferView>(); - ClassDB::register_class<GLTFAccessor>(); - ClassDB::register_class<GLTFTexture>(); - ClassDB::register_class<GLTFSkeleton>(); - ClassDB::register_class<GLTFSkin>(); - ClassDB::register_class<GLTFCamera>(); - ClassDB::register_class<GLTFLight>(); - ClassDB::register_class<GLTFState>(); - ClassDB::register_class<GLTFDocument>(); - ClassDB::register_class<PackedSceneGLTF>(); + GDREGISTER_CLASS(GLTFSpecGloss); + GDREGISTER_CLASS(GLTFNode); + GDREGISTER_CLASS(GLTFAnimation); + GDREGISTER_CLASS(GLTFBufferView); + GDREGISTER_CLASS(GLTFAccessor); + GDREGISTER_CLASS(GLTFTexture); + GDREGISTER_CLASS(GLTFSkeleton); + GDREGISTER_CLASS(GLTFSkin); + GDREGISTER_CLASS(GLTFCamera); + GDREGISTER_CLASS(GLTFLight); + GDREGISTER_CLASS(GLTFState); + GDREGISTER_CLASS(GLTFDocument); + GDREGISTER_CLASS(PackedSceneGLTF); #endif } diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index c62e7acd62..0cd41133f1 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -221,7 +221,7 @@ void GridMap::set_cell_size(const Vector3 &p_size) { ERR_FAIL_COND(p_size.x < 0.001 || p_size.y < 0.001 || p_size.z < 0.001); cell_size = p_size; _recreate_octant_data(); - emit_signal("cell_size_changed", cell_size); + emit_signal(SNAME("cell_size_changed"), cell_size); } Vector3 GridMap::get_cell_size() const { @@ -780,7 +780,7 @@ void GridMap::_update_octants_callback() { while (to_delete.front()) { octant_map.erase(to_delete.front()->get()); - to_delete.pop_back(); + to_delete.pop_front(); } _update_visibility(); diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index a2f570e6a5..046f8c0adb 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -1077,8 +1077,8 @@ void GridMapEditor::_notification(int p_what) { } break; case NOTIFICATION_THEME_CHANGED: { - options->set_icon(get_theme_icon("GridMap", "EditorIcons")); - search_box->set_right_icon(get_theme_icon("Search", "EditorIcons")); + options->set_icon(get_theme_icon(SNAME("GridMap"), SNAME("EditorIcons"))); + search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); } break; case NOTIFICATION_APPLICATION_FOCUS_OUT: { @@ -1239,7 +1239,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { mode_thumbnail->set_flat(true); mode_thumbnail->set_toggle_mode(true); mode_thumbnail->set_pressed(true); - mode_thumbnail->set_icon(p_editor->get_gui_base()->get_theme_icon("FileThumbnail", "EditorIcons")); + mode_thumbnail->set_icon(p_editor->get_gui_base()->get_theme_icon(SNAME("FileThumbnail"), SNAME("EditorIcons"))); hb->add_child(mode_thumbnail); mode_thumbnail->connect("pressed", callable_mp(this, &GridMapEditor::_set_display_mode), varray(DISPLAY_THUMBNAIL)); @@ -1247,7 +1247,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { mode_list->set_flat(true); mode_list->set_toggle_mode(true); mode_list->set_pressed(false); - mode_list->set_icon(p_editor->get_gui_base()->get_theme_icon("FileList", "EditorIcons")); + mode_list->set_icon(p_editor->get_gui_base()->get_theme_icon(SNAME("FileList"), SNAME("EditorIcons"))); hb->add_child(mode_list); mode_list->connect("pressed", callable_mp(this, &GridMapEditor::_set_display_mode), varray(DISPLAY_LIST)); @@ -1271,7 +1271,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { info_message->set_text(TTR("Give a MeshLibrary resource to this GridMap to use its meshes.")); info_message->set_valign(Label::VALIGN_CENTER); info_message->set_align(Label::ALIGN_CENTER); - info_message->set_autowrap(true); + info_message->set_autowrap_mode(Label::AUTOWRAP_WORD_SMART); info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); info_message->set_anchors_and_offsets_preset(PRESET_WIDE, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE); mesh_library_palette->add_child(info_message); diff --git a/modules/gridmap/register_types.cpp b/modules/gridmap/register_types.cpp index 5680664213..85739d202e 100644 --- a/modules/gridmap/register_types.cpp +++ b/modules/gridmap/register_types.cpp @@ -37,7 +37,7 @@ void register_gridmap_types() { #ifndef _3D_DISABLED - ClassDB::register_class<GridMap>(); + GDREGISTER_CLASS(GridMap); #ifdef TOOLS_ENABLED EditorPlugins::add_by_type<GridMapEditorPlugin>(); #endif diff --git a/modules/jsonrpc/register_types.cpp b/modules/jsonrpc/register_types.cpp index d6b565ba84..8fdf6fe1aa 100644 --- a/modules/jsonrpc/register_types.cpp +++ b/modules/jsonrpc/register_types.cpp @@ -33,7 +33,7 @@ #include "jsonrpc.h" void register_jsonrpc_types() { - ClassDB::register_class<JSONRPC>(); + GDREGISTER_CLASS(JSONRPC); } void unregister_jsonrpc_types() { diff --git a/modules/lightmapper_rd/register_types.cpp b/modules/lightmapper_rd/register_types.cpp index 191bb3d765..ae9c5fc390 100644 --- a/modules/lightmapper_rd/register_types.cpp +++ b/modules/lightmapper_rd/register_types.cpp @@ -54,7 +54,7 @@ void register_lightmapper_rd_types() { GLOBAL_DEF("rendering/lightmapping/bake_quality/ultra_quality_probe_ray_count", 2048); GLOBAL_DEF("rendering/lightmapping/bake_performance/max_rays_per_probe_pass", 64); #ifndef _3D_DISABLED - ClassDB::register_class<LightmapperRD>(); + GDREGISTER_CLASS(LightmapperRD); Lightmapper::create_gpu = create_lightmapper_rd; #endif } diff --git a/modules/mbedtls/crypto_mbedtls.cpp b/modules/mbedtls/crypto_mbedtls.cpp index 774da5a324..2522f1bb11 100644 --- a/modules/mbedtls/crypto_mbedtls.cpp +++ b/modules/mbedtls/crypto_mbedtls.cpp @@ -249,6 +249,13 @@ PackedByteArray HMACContextMbedTLS::finish() { return out; } +HMACContextMbedTLS::~HMACContextMbedTLS() { + if (ctx != nullptr) { + mbedtls_md_free((mbedtls_md_context_t *)ctx); + memfree((mbedtls_md_context_t *)ctx); + } +} + Crypto *CryptoMbedTLS::create() { return memnew(CryptoMbedTLS); } diff --git a/modules/mbedtls/crypto_mbedtls.h b/modules/mbedtls/crypto_mbedtls.h index 5ced4d136c..afa1ea7a64 100644 --- a/modules/mbedtls/crypto_mbedtls.h +++ b/modules/mbedtls/crypto_mbedtls.h @@ -119,6 +119,7 @@ public: virtual PackedByteArray finish(); HMACContextMbedTLS() {} + ~HMACContextMbedTLS(); }; class CryptoMbedTLS : public Crypto { diff --git a/modules/mbedtls/tests/test_crypto_mbedtls.cpp b/modules/mbedtls/tests/test_crypto_mbedtls.cpp index 4217497082..8762838883 100644 --- a/modules/mbedtls/tests/test_crypto_mbedtls.cpp +++ b/modules/mbedtls/tests/test_crypto_mbedtls.cpp @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "modules/mbedtls/tests/test_crypto_mbedtls.h" +#include "test_crypto_mbedtls.h" #include "modules/mbedtls/crypto_mbedtls.h" #include "tests/test_macros.h" diff --git a/modules/minimp3/register_types.cpp b/modules/minimp3/register_types.cpp index 27ea512b69..63f2589f42 100644 --- a/modules/minimp3/register_types.cpp +++ b/modules/minimp3/register_types.cpp @@ -45,7 +45,7 @@ void register_minimp3_types() { ResourceFormatImporter::get_singleton()->add_importer(mp3_import); } #endif - ClassDB::register_class<AudioStreamMP3>(); + GDREGISTER_CLASS(AudioStreamMP3); } void unregister_minimp3_types() { diff --git a/modules/mobile_vr/register_types.cpp b/modules/mobile_vr/register_types.cpp index 7d138aa4c9..47d1fe482c 100644 --- a/modules/mobile_vr/register_types.cpp +++ b/modules/mobile_vr/register_types.cpp @@ -33,7 +33,7 @@ #include "mobile_vr_interface.h" void register_mobile_vr_types() { - ClassDB::register_class<MobileVRInterface>(); + GDREGISTER_CLASS(MobileVRInterface); if (XRServer::get_singleton()) { Ref<MobileVRInterface> mobile_vr; diff --git a/modules/mono/build_scripts/mono_configure.py b/modules/mono/build_scripts/mono_configure.py index 309abfbff7..8e441e7e07 100644 --- a/modules/mono/build_scripts/mono_configure.py +++ b/modules/mono/build_scripts/mono_configure.py @@ -101,12 +101,6 @@ def configure(env, env_mono): mono_lib_names = ["mono-2.0-sgen", "monosgen-2.0"] - is_travis = os.environ.get("TRAVIS") == "true" - - if is_travis: - # Travis CI may have a Mono version lower than 5.12 - env_mono.Append(CPPDEFINES=["NO_PENDING_EXCEPTIONS"]) - if is_android and not env["android_arch"] in android_arch_dirs: raise RuntimeError("This module does not support the specified 'android_arch': " + env["android_arch"]) diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index c48230f524..80675feb3b 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -1510,6 +1510,7 @@ void CSharpLanguage::free_instance_binding_data(void *p_data) { } void CSharpLanguage::refcount_incremented_instance_binding(Object *p_object) { +#if 0 RefCounted *rc_owner = Object::cast_to<RefCounted>(p_object); #ifdef DEBUG_ENABLED @@ -1544,9 +1545,11 @@ void CSharpLanguage::refcount_incremented_instance_binding(Object *p_object) { gchandle.release(); gchandle = strong_gchandle; } +#endif } bool CSharpLanguage::refcount_decremented_instance_binding(Object *p_object) { +#if 0 RefCounted *rc_owner = Object::cast_to<RefCounted>(p_object); #ifdef DEBUG_ENABLED @@ -1586,6 +1589,8 @@ bool CSharpLanguage::refcount_decremented_instance_binding(Object *p_object) { } return refcount == 0; +#endif + return false; } CSharpInstance *CSharpInstance::create_for_managed_type(Object *p_owner, CSharpScript *p_script, const MonoGCHandleData &p_gchandle) { @@ -2264,8 +2269,10 @@ CSharpInstance::~CSharpInstance() { // Otherwise, the unsafe reference debug checks will incorrectly detect a bug. bool die = _unreference_owner_unsafe(); CRASH_COND(die); // `owner_keep_alive` holds a reference, so it can't die - +#if 0 void *data = owner->get_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index()); + + CRASH_COND(data == nullptr); CSharpScriptBinding &script_binding = ((Map<Object *, CSharpScriptBinding>::Element *)data)->get(); @@ -2284,6 +2291,7 @@ CSharpInstance::~CSharpInstance() { // The "instance binding" holds a reference so the refcount should be at least 2 before `scope_keep_owner_alive` goes out of scope CRASH_COND(rc_owner->reference_get_count() <= 1); #endif +#endif } if (script.is_valid() && owner) { @@ -3030,7 +3038,7 @@ void CSharpScript::update_script_class_info(Ref<CSharpScript> p_script) { nd.name = methods[i]->get_name(); nd.rpc_mode = mode; // TODO Transfer mode, channel - nd.transfer_mode = NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE; + nd.transfer_mode = MultiplayerPeer::TRANSFER_MODE_RELIABLE; nd.channel = 0; if (-1 == p_script->rpc_functions.find(nd)) { p_script->rpc_functions.push_back(nd); @@ -3101,7 +3109,7 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg // Hold it alive. Important if we have to dispose a script instance binding before creating the CSharpInstance. ref = Ref<RefCounted>(static_cast<RefCounted *>(p_owner)); } - +#if 0 // If the object had a script instance binding, dispose it before adding the CSharpInstance if (p_owner->has_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index())) { void *data = p_owner->get_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index()); @@ -3123,7 +3131,7 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg script_binding.inited = false; } } - +#endif CSharpInstance *instance = memnew(CSharpInstance(Ref<CSharpScript>(this))); instance->base_ref_counted = p_is_ref_counted; instance->owner = p_owner; @@ -3464,15 +3472,6 @@ MultiplayerAPI::RPCMode CSharpScript::_member_get_rpc_mode(IMonoClassMember *p_m if (p_member->has_attribute(CACHED_CLASS(PuppetAttribute))) { return MultiplayerAPI::RPC_MODE_PUPPET; } - if (p_member->has_attribute(CACHED_CLASS(RemoteSyncAttribute))) { - return MultiplayerAPI::RPC_MODE_REMOTESYNC; - } - if (p_member->has_attribute(CACHED_CLASS(MasterSyncAttribute))) { - return MultiplayerAPI::RPC_MODE_MASTERSYNC; - } - if (p_member->has_attribute(CACHED_CLASS(PuppetSyncAttribute))) { - return MultiplayerAPI::RPC_MODE_PUPPETSYNC; - } return MultiplayerAPI::RPC_MODE_DISABLED; } diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs index c71c44d79d..1faa6eeac0 100644 --- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs +++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs @@ -26,8 +26,6 @@ namespace GodotTools private PopupMenu menuPopup; private AcceptDialog errorDialog; - private AcceptDialog aboutDialog; - private CheckBox aboutDialogCheckBox; private Button bottomPanelBtn; private Button toolBarBuildButton; @@ -130,13 +128,6 @@ namespace GodotTools toolBarBuildButton.Show(); } - private void _ShowAboutDialog() - { - bool showOnStart = (bool)editorSettings.GetSetting("mono/editor/show_info_on_start"); - aboutDialogCheckBox.Pressed = showOnStart; - aboutDialog.PopupCentered(); - } - private void _MenuOptionPressed(int id) { switch ((MenuOptions)id) @@ -144,9 +135,6 @@ namespace GodotTools case MenuOptions.CreateSln: CreateProjectSolution(); break; - case MenuOptions.AboutCSharp: - _ShowAboutDialog(); - break; case MenuOptions.SetupGodotNugetFallbackFolder: { try @@ -183,21 +171,11 @@ namespace GodotTools base._Ready(); MSBuildPanel.BuildOutputView.BuildStateChanged += BuildStateChanged; - - bool showInfoDialog = (bool)editorSettings.GetSetting("mono/editor/show_info_on_start"); - if (showInfoDialog) - { - aboutDialog.Exclusive = true; - _ShowAboutDialog(); - // Once shown a first time, it can be seen again via the Mono menu - it doesn't have to be exclusive from that time on. - aboutDialog.Exclusive = false; - } } private enum MenuOptions { CreateSln, - AboutCSharp, SetupGodotNugetFallbackFolder, } @@ -439,57 +417,6 @@ namespace GodotTools AddToolSubmenuItem("C#", menuPopup); - // TODO: Remove or edit this info dialog once Mono support is no longer in alpha - { - menuPopup.AddItem("About C# support".TTR(), (int)MenuOptions.AboutCSharp); - menuPopup.AddItem("Setup Godot NuGet Offline Packages".TTR(), (int)MenuOptions.SetupGodotNugetFallbackFolder); - aboutDialog = new AcceptDialog(); - editorBaseControl.AddChild(aboutDialog); - aboutDialog.Title = "Important: C# support is not feature-complete"; - - // We don't use DialogText as the default AcceptDialog Label doesn't play well with the TextureRect and CheckBox - // we'll add. Instead we add containers and a new autowrapped Label inside. - - // Main VBoxContainer (icon + label on top, checkbox at bottom) - var aboutVBox = new VBoxContainer(); - aboutDialog.AddChild(aboutVBox); - - // HBoxContainer for icon + label - var aboutHBox = new HBoxContainer(); - aboutVBox.AddChild(aboutHBox); - - var aboutIcon = new TextureRect(); - aboutIcon.Texture = aboutIcon.GetThemeIcon("NodeWarning", "EditorIcons"); - aboutHBox.AddChild(aboutIcon); - - var aboutLabel = new Label(); - aboutHBox.AddChild(aboutLabel); - aboutLabel.RectMinSize = new Vector2(600, 150) * EditorScale; - aboutLabel.SizeFlagsVertical = (int)Control.SizeFlags.ExpandFill; - aboutLabel.Autowrap = true; - aboutLabel.Text = - "C# support in Godot Engine is in late alpha stage and, while already usable, " + - "it is not meant for use in production.\n\n" + - "Projects can be exported to Linux, macOS, Windows, Android, iOS and HTML5, but not yet to UWP. " + - "Bugs and usability issues will be addressed gradually over future releases, " + - "potentially including compatibility breaking changes as new features are implemented for a better overall C# experience.\n\n" + - "If you experience issues with this Mono build, please report them on Godot's issue tracker with details about your system, MSBuild version, IDE, etc.:\n\n" + - " https://github.com/godotengine/godot/issues\n\n" + - "Your critical feedback at this stage will play a great role in shaping the C# support in future releases, so thank you!"; - - EditorDef("mono/editor/show_info_on_start", true); - - // CheckBox in main container - aboutDialogCheckBox = new CheckBox {Text = "Show this warning when starting the editor"}; - aboutDialogCheckBox.Toggled += enabled => - { - bool showOnStart = (bool)editorSettings.GetSetting("mono/editor/show_info_on_start"); - if (showOnStart != enabled) - editorSettings.SetSetting("mono/editor/show_info_on_start", enabled); - }; - aboutVBox.AddChild(aboutDialogCheckBox); - } - toolBarBuildButton = new Button { Text = "Build", diff --git a/modules/mono/editor/editor_internal_calls.cpp b/modules/mono/editor/editor_internal_calls.cpp index 21efd58938..8164f459ca 100644 --- a/modules/mono/editor/editor_internal_calls.cpp +++ b/modules/mono/editor/editor_internal_calls.cpp @@ -241,7 +241,7 @@ MonoBoolean godot_icall_Internal_IsAssembliesReloadingNeeded() { void godot_icall_Internal_ReloadAssemblies(MonoBoolean p_soft_reload) { #ifdef GD_MONO_HOT_RELOAD - _GodotSharp::get_singleton()->call_deferred("_reload_assemblies", (bool)p_soft_reload); + _GodotSharp::get_singleton()->call_deferred(SNAME("_reload_assemblies"), (bool)p_soft_reload); #endif } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs index 8fc430b6bc..6cec8773b2 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttributes.cs @@ -2,21 +2,12 @@ using System; namespace Godot { - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)] + [AttributeUsage(AttributeTargets.Method)] public class RemoteAttribute : Attribute {} - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)] + [AttributeUsage(AttributeTargets.Method)] public class MasterAttribute : Attribute {} - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)] + [AttributeUsage(AttributeTargets.Method)] public class PuppetAttribute : Attribute {} - - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)] - public class RemoteSyncAttribute : Attribute {} - - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)] - public class MasterSyncAttribute : Attribute {} - - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)] - public class PuppetSyncAttribute : Attribute {} } diff --git a/modules/mono/glue/base_object_glue.cpp b/modules/mono/glue/base_object_glue.cpp index 2b87c2d9a4..2d04cedb9b 100644 --- a/modules/mono/glue/base_object_glue.cpp +++ b/modules/mono/glue/base_object_glue.cpp @@ -64,7 +64,7 @@ void godot_icall_Object_Disposed(MonoObject *p_obj, Object *p_ptr) { return; } } - +#if 0 void *data = p_ptr->get_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index()); if (data) { @@ -76,6 +76,7 @@ void godot_icall_Object_Disposed(MonoObject *p_obj, Object *p_ptr) { } } } +#endif } void godot_icall_RefCounted_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoolean p_is_finalizer) { @@ -84,7 +85,7 @@ void godot_icall_RefCounted_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoole // This is only called with RefCounted derived classes CRASH_COND(!Object::cast_to<RefCounted>(p_ptr)); #endif - +#if 0 RefCounted *rc = static_cast<RefCounted *>(p_ptr); if (rc->get_script_instance()) { @@ -124,6 +125,7 @@ void godot_icall_RefCounted_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoole } } } +#endif } void godot_icall_Object_ConnectEventSignals(Object *p_ptr) { diff --git a/modules/mono/mono_gd/gd_mono_cache.cpp b/modules/mono/mono_gd/gd_mono_cache.cpp index 341ca88728..0b36796d98 100644 --- a/modules/mono/mono_gd/gd_mono_cache.cpp +++ b/modules/mono/mono_gd/gd_mono_cache.cpp @@ -143,9 +143,6 @@ void CachedData::clear_godot_api_cache() { class_RemoteAttribute = nullptr; class_MasterAttribute = nullptr; class_PuppetAttribute = nullptr; - class_RemoteSyncAttribute = nullptr; - class_MasterSyncAttribute = nullptr; - class_PuppetSyncAttribute = nullptr; class_GodotMethodAttribute = nullptr; field_GodotMethodAttribute_methodName = nullptr; class_ScriptPathAttribute = nullptr; @@ -272,9 +269,6 @@ void update_godot_api_cache() { CACHE_CLASS_AND_CHECK(RemoteAttribute, GODOT_API_CLASS(RemoteAttribute)); CACHE_CLASS_AND_CHECK(MasterAttribute, GODOT_API_CLASS(MasterAttribute)); CACHE_CLASS_AND_CHECK(PuppetAttribute, GODOT_API_CLASS(PuppetAttribute)); - CACHE_CLASS_AND_CHECK(RemoteSyncAttribute, GODOT_API_CLASS(RemoteSyncAttribute)); - CACHE_CLASS_AND_CHECK(MasterSyncAttribute, GODOT_API_CLASS(MasterSyncAttribute)); - CACHE_CLASS_AND_CHECK(PuppetSyncAttribute, GODOT_API_CLASS(PuppetSyncAttribute)); 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 3d867060f5..6d49da0af3 100644 --- a/modules/mono/mono_gd/gd_mono_cache.h +++ b/modules/mono/mono_gd/gd_mono_cache.h @@ -114,9 +114,6 @@ struct CachedData { GDMonoClass *class_RemoteAttribute; GDMonoClass *class_MasterAttribute; GDMonoClass *class_PuppetAttribute; - GDMonoClass *class_RemoteSyncAttribute; - GDMonoClass *class_MasterSyncAttribute; - GDMonoClass *class_PuppetSyncAttribute; GDMonoClass *class_GodotMethodAttribute; GDMonoField *field_GodotMethodAttribute_methodName; GDMonoClass *class_ScriptPathAttribute; diff --git a/modules/mono/mono_gd/gd_mono_internals.cpp b/modules/mono/mono_gd/gd_mono_internals.cpp index d7df18d5da..d6545d50ec 100644 --- a/modules/mono/mono_gd/gd_mono_internals.cpp +++ b/modules/mono/mono_gd/gd_mono_internals.cpp @@ -45,7 +45,7 @@ namespace GDMonoInternals { void tie_managed_to_unmanaged(MonoObject *managed, Object *unmanaged) { // This method should not fail - +#if 0 CRASH_COND(!unmanaged); // All mono objects created from the managed world (e.g.: 'new Player()') @@ -108,6 +108,7 @@ void tie_managed_to_unmanaged(MonoObject *managed, Object *unmanaged) { CSharpInstance *csharp_instance = CSharpInstance::create_for_managed_type(unmanaged, script.ptr(), gchandle); unmanaged->set_script_and_instance(script, csharp_instance); +#endif } void unhandled_exception(MonoException *p_exc) { diff --git a/modules/mono/mono_gd/gd_mono_utils.cpp b/modules/mono/mono_gd/gd_mono_utils.cpp index 0b9a577e01..080398c997 100644 --- a/modules/mono/mono_gd/gd_mono_utils.cpp +++ b/modules/mono/mono_gd/gd_mono_utils.cpp @@ -54,6 +54,7 @@ namespace GDMonoUtils { MonoObject *unmanaged_get_managed(Object *unmanaged) { +#if 0 if (!unmanaged) { return nullptr; } @@ -120,6 +121,8 @@ MonoObject *unmanaged_get_managed(Object *unmanaged) { } return mono_object; +#endif + return nullptr; } void set_main_thread(MonoThread *p_thread) { diff --git a/modules/mono/register_types.cpp b/modules/mono/register_types.cpp index b4a6bfdcd4..2ba89eac55 100644 --- a/modules/mono/register_types.cpp +++ b/modules/mono/register_types.cpp @@ -41,11 +41,11 @@ Ref<ResourceFormatSaverCSharpScript> resource_saver_cs; _GodotSharp *_godotsharp = nullptr; void register_mono_types() { - ClassDB::register_class<CSharpScript>(); + GDREGISTER_CLASS(CSharpScript); _godotsharp = memnew(_GodotSharp); - ClassDB::register_class<_GodotSharp>(); + GDREGISTER_CLASS(_GodotSharp); Engine::get_singleton()->add_singleton(Engine::Singleton("GodotSharp", _GodotSharp::get_singleton())); script_language_cs = memnew(CSharpLanguage); diff --git a/modules/gdnavigation/SCsub b/modules/navigation/SCsub index 22b5509b32..22b5509b32 100644 --- a/modules/gdnavigation/SCsub +++ b/modules/navigation/SCsub diff --git a/modules/gdnavigation/config.py b/modules/navigation/config.py index d22f9454ed..d22f9454ed 100644 --- a/modules/gdnavigation/config.py +++ b/modules/navigation/config.py diff --git a/modules/gdnavigation/gd_navigation_server.cpp b/modules/navigation/godot_navigation_server.cpp index d5e6e5e69f..fd965674d6 100644 --- a/modules/gdnavigation/gd_navigation_server.cpp +++ b/modules/navigation/godot_navigation_server.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_navigation_server.cpp */ +/* godot_navigation_server.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "gd_navigation_server.h" +#include "godot_navigation_server.h" #include "core/os/mutex.h" @@ -44,96 +44,96 @@ /// an instance of that struct with the submitted parameters. /// Then, that struct is stored in an array; the `sync` function consume that array. -#define COMMAND_1(F_NAME, T_0, D_0) \ - struct MERGE(F_NAME, _command) : public SetCommand { \ - T_0 d_0; \ - MERGE(F_NAME, _command) \ - (T_0 p_d_0) : \ - d_0(p_d_0) {} \ - virtual void exec(GdNavigationServer *server) { \ - server->MERGE(_cmd_, F_NAME)(d_0); \ - } \ - }; \ - void GdNavigationServer::F_NAME(T_0 D_0) const { \ - auto cmd = memnew(MERGE(F_NAME, _command)( \ - D_0)); \ - add_command(cmd); \ - } \ - void GdNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0) - -#define COMMAND_2(F_NAME, T_0, D_0, T_1, D_1) \ - struct MERGE(F_NAME, _command) : public SetCommand { \ - T_0 d_0; \ - T_1 d_1; \ - MERGE(F_NAME, _command) \ - ( \ - T_0 p_d_0, \ - T_1 p_d_1) : \ - d_0(p_d_0), \ - d_1(p_d_1) {} \ - virtual void exec(GdNavigationServer *server) { \ - server->MERGE(_cmd_, F_NAME)(d_0, d_1); \ - } \ - }; \ - void GdNavigationServer::F_NAME(T_0 D_0, T_1 D_1) const { \ - auto cmd = memnew(MERGE(F_NAME, _command)( \ - D_0, \ - D_1)); \ - add_command(cmd); \ - } \ - void GdNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1) - -#define COMMAND_4(F_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3) \ - struct MERGE(F_NAME, _command) : public SetCommand { \ - T_0 d_0; \ - T_1 d_1; \ - T_2 d_2; \ - T_3 d_3; \ - MERGE(F_NAME, _command) \ - ( \ - T_0 p_d_0, \ - T_1 p_d_1, \ - T_2 p_d_2, \ - T_3 p_d_3) : \ - d_0(p_d_0), \ - d_1(p_d_1), \ - d_2(p_d_2), \ - d_3(p_d_3) {} \ - virtual void exec(GdNavigationServer *server) { \ - server->MERGE(_cmd_, F_NAME)(d_0, d_1, d_2, d_3); \ - } \ - }; \ - void GdNavigationServer::F_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) const { \ - auto cmd = memnew(MERGE(F_NAME, _command)( \ - D_0, \ - D_1, \ - D_2, \ - D_3)); \ - add_command(cmd); \ - } \ - void GdNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) - -GdNavigationServer::GdNavigationServer() : +#define COMMAND_1(F_NAME, T_0, D_0) \ + struct MERGE(F_NAME, _command) : public SetCommand { \ + T_0 d_0; \ + MERGE(F_NAME, _command) \ + (T_0 p_d_0) : \ + d_0(p_d_0) {} \ + virtual void exec(GodotNavigationServer *server) { \ + server->MERGE(_cmd_, F_NAME)(d_0); \ + } \ + }; \ + void GodotNavigationServer::F_NAME(T_0 D_0) const { \ + auto cmd = memnew(MERGE(F_NAME, _command)( \ + D_0)); \ + add_command(cmd); \ + } \ + void GodotNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0) + +#define COMMAND_2(F_NAME, T_0, D_0, T_1, D_1) \ + struct MERGE(F_NAME, _command) : public SetCommand { \ + T_0 d_0; \ + T_1 d_1; \ + MERGE(F_NAME, _command) \ + ( \ + T_0 p_d_0, \ + T_1 p_d_1) : \ + d_0(p_d_0), \ + d_1(p_d_1) {} \ + virtual void exec(GodotNavigationServer *server) { \ + server->MERGE(_cmd_, F_NAME)(d_0, d_1); \ + } \ + }; \ + void GodotNavigationServer::F_NAME(T_0 D_0, T_1 D_1) const { \ + auto cmd = memnew(MERGE(F_NAME, _command)( \ + D_0, \ + D_1)); \ + add_command(cmd); \ + } \ + void GodotNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1) + +#define COMMAND_4(F_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3) \ + struct MERGE(F_NAME, _command) : public SetCommand { \ + T_0 d_0; \ + T_1 d_1; \ + T_2 d_2; \ + T_3 d_3; \ + MERGE(F_NAME, _command) \ + ( \ + T_0 p_d_0, \ + T_1 p_d_1, \ + T_2 p_d_2, \ + T_3 p_d_3) : \ + d_0(p_d_0), \ + d_1(p_d_1), \ + d_2(p_d_2), \ + d_3(p_d_3) {} \ + virtual void exec(GodotNavigationServer *server) { \ + server->MERGE(_cmd_, F_NAME)(d_0, d_1, d_2, d_3); \ + } \ + }; \ + void GodotNavigationServer::F_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) const { \ + auto cmd = memnew(MERGE(F_NAME, _command)( \ + D_0, \ + D_1, \ + D_2, \ + D_3)); \ + add_command(cmd); \ + } \ + void GodotNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) + +GodotNavigationServer::GodotNavigationServer() : NavigationServer3D() { } -GdNavigationServer::~GdNavigationServer() { +GodotNavigationServer::~GodotNavigationServer() { flush_queries(); } -void GdNavigationServer::add_command(SetCommand *command) const { - GdNavigationServer *mut_this = const_cast<GdNavigationServer *>(this); +void GodotNavigationServer::add_command(SetCommand *command) const { + GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); { MutexLock lock(commands_mutex); mut_this->commands.push_back(command); } } -RID GdNavigationServer::map_create() const { - GdNavigationServer *mut_this = const_cast<GdNavigationServer *>(this); +RID GodotNavigationServer::map_create() const { + GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); - NavMap *space = memnew(NavMap); - RID rid = map_owner.make_rid(space); + RID rid = map_owner.make_rid(); + NavMap *space = map_owner.getornull(rid); space->set_self(rid); return rid; } @@ -155,7 +155,7 @@ COMMAND_2(map_set_active, RID, p_map, bool, p_active) { } } -bool GdNavigationServer::map_is_active(RID p_map) const { +bool GodotNavigationServer::map_is_active(RID p_map) const { NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, false); @@ -169,7 +169,7 @@ COMMAND_2(map_set_up, RID, p_map, Vector3, p_up) { map->set_up(p_up); } -Vector3 GdNavigationServer::map_get_up(RID p_map) const { +Vector3 GodotNavigationServer::map_get_up(RID p_map) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, Vector3()); @@ -183,7 +183,7 @@ COMMAND_2(map_set_cell_size, RID, p_map, real_t, p_cell_size) { map->set_cell_size(p_cell_size); } -real_t GdNavigationServer::map_get_cell_size(RID p_map) const { +real_t GodotNavigationServer::map_get_cell_size(RID p_map) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, 0); @@ -197,53 +197,53 @@ COMMAND_2(map_set_edge_connection_margin, RID, p_map, real_t, p_connection_margi map->set_edge_connection_margin(p_connection_margin); } -real_t GdNavigationServer::map_get_edge_connection_margin(RID p_map) const { +real_t GodotNavigationServer::map_get_edge_connection_margin(RID p_map) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, 0); return map->get_edge_connection_margin(); } -Vector<Vector3> GdNavigationServer::map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize, uint32_t p_layers) const { +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); ERR_FAIL_COND_V(map == nullptr, Vector<Vector3>()); return map->get_path(p_origin, p_destination, p_optimize, p_layers); } -Vector3 GdNavigationServer::map_get_closest_point_to_segment(RID p_map, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const { +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); ERR_FAIL_COND_V(map == nullptr, Vector3()); return map->get_closest_point_to_segment(p_from, p_to, p_use_collision); } -Vector3 GdNavigationServer::map_get_closest_point(RID p_map, const Vector3 &p_point) const { +Vector3 GodotNavigationServer::map_get_closest_point(RID p_map, const Vector3 &p_point) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, Vector3()); return map->get_closest_point(p_point); } -Vector3 GdNavigationServer::map_get_closest_point_normal(RID p_map, const Vector3 &p_point) const { +Vector3 GodotNavigationServer::map_get_closest_point_normal(RID p_map, const Vector3 &p_point) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, Vector3()); return map->get_closest_point_normal(p_point); } -RID GdNavigationServer::map_get_closest_point_owner(RID p_map, const Vector3 &p_point) const { +RID GodotNavigationServer::map_get_closest_point_owner(RID p_map, const Vector3 &p_point) const { const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == nullptr, RID()); return map->get_closest_point_owner(p_point); } -RID GdNavigationServer::region_create() const { - GdNavigationServer *mut_this = const_cast<GdNavigationServer *>(this); +RID GodotNavigationServer::region_create() const { + GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); - NavRegion *reg = memnew(NavRegion); - RID rid = region_owner.make_rid(reg); + RID rid = region_owner.make_rid(); + NavRegion *reg = region_owner.getornull(rid); reg->set_self(rid); return rid; } @@ -284,7 +284,7 @@ COMMAND_2(region_set_layers, RID, p_region, uint32_t, p_layers) { region->set_layers(p_layers); } -uint32_t GdNavigationServer::region_get_layers(RID p_region) const { +uint32_t GodotNavigationServer::region_get_layers(RID p_region) const { NavRegion *region = region_owner.getornull(p_region); ERR_FAIL_COND_V(region == nullptr, 0); @@ -298,7 +298,7 @@ COMMAND_2(region_set_navmesh, RID, p_region, Ref<NavigationMesh>, p_nav_mesh) { region->set_mesh(p_nav_mesh); } -void GdNavigationServer::region_bake_navmesh(Ref<NavigationMesh> r_mesh, Node *p_node) const { +void GodotNavigationServer::region_bake_navmesh(Ref<NavigationMesh> r_mesh, Node *p_node) const { ERR_FAIL_COND(r_mesh.is_null()); ERR_FAIL_COND(p_node == nullptr); @@ -308,32 +308,32 @@ void GdNavigationServer::region_bake_navmesh(Ref<NavigationMesh> r_mesh, Node *p #endif } -int GdNavigationServer::region_get_connections_count(RID p_region) const { +int GodotNavigationServer::region_get_connections_count(RID p_region) const { NavRegion *region = region_owner.getornull(p_region); ERR_FAIL_COND_V(!region, 0); return region->get_connections_count(); } -Vector3 GdNavigationServer::region_get_connection_pathway_start(RID p_region, int p_connection_id) const { +Vector3 GodotNavigationServer::region_get_connection_pathway_start(RID p_region, int p_connection_id) const { NavRegion *region = region_owner.getornull(p_region); ERR_FAIL_COND_V(!region, Vector3()); return region->get_connection_pathway_start(p_connection_id); } -Vector3 GdNavigationServer::region_get_connection_pathway_end(RID p_region, int p_connection_id) const { +Vector3 GodotNavigationServer::region_get_connection_pathway_end(RID p_region, int p_connection_id) const { NavRegion *region = region_owner.getornull(p_region); ERR_FAIL_COND_V(!region, Vector3()); return region->get_connection_pathway_end(p_connection_id); } -RID GdNavigationServer::agent_create() const { - GdNavigationServer *mut_this = const_cast<GdNavigationServer *>(this); +RID GodotNavigationServer::agent_create() const { + GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); - RvoAgent *agent = memnew(RvoAgent()); - RID rid = agent_owner.make_rid(agent); + RID rid = agent_owner.make_rid(); + RvoAgent *agent = agent_owner.getornull(rid); agent->set_self(rid); return rid; } @@ -428,7 +428,7 @@ COMMAND_2(agent_set_ignore_y, RID, p_agent, bool, p_ignore) { agent->get_agent()->ignore_y_ = p_ignore; } -bool GdNavigationServer::agent_is_map_changed(RID p_agent) const { +bool GodotNavigationServer::agent_is_map_changed(RID p_agent) const { RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND_V(agent == nullptr, false); @@ -472,7 +472,6 @@ COMMAND_1(free, RID, p_object) { active_maps.remove(map_index); active_maps_update_id.remove(map_index); map_owner.free(p_object); - memdelete(map); } else if (region_owner.owns(p_object)) { NavRegion *region = region_owner.getornull(p_object); @@ -484,7 +483,6 @@ COMMAND_1(free, RID, p_object) { } region_owner.free(p_object); - memdelete(region); } else if (agent_owner.owns(p_object)) { RvoAgent *agent = agent_owner.getornull(p_object); @@ -496,20 +494,19 @@ COMMAND_1(free, RID, p_object) { } agent_owner.free(p_object); - memdelete(agent); } else { ERR_FAIL_COND("Invalid ID."); } } -void GdNavigationServer::set_active(bool p_active) const { - GdNavigationServer *mut_this = const_cast<GdNavigationServer *>(this); +void GodotNavigationServer::set_active(bool p_active) const { + GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); mut_this->active = p_active; } -void GdNavigationServer::flush_queries() { +void GodotNavigationServer::flush_queries() { // In c++ we can't be sure that this is performed in the main thread // even with mutable functions. MutexLock lock(commands_mutex); @@ -521,7 +518,7 @@ void GdNavigationServer::flush_queries() { commands.clear(); } -void GdNavigationServer::process(real_t p_delta_time) { +void GodotNavigationServer::process(real_t p_delta_time) { flush_queries(); if (!active) { @@ -539,7 +536,7 @@ void GdNavigationServer::process(real_t p_delta_time) { // Emit a signal if a map changed. const uint32_t new_map_update_id = active_maps[i]->get_map_update_id(); if (new_map_update_id != active_maps_update_id[i]) { - emit_signal("map_changed", active_maps[i]->get_self()); + emit_signal(SNAME("map_changed"), active_maps[i]->get_self()); active_maps_update_id[i] = new_map_update_id; } } diff --git a/modules/gdnavigation/gd_navigation_server.h b/modules/navigation/godot_navigation_server.h index 759d15e508..65224493fd 100644 --- a/modules/gdnavigation/gd_navigation_server.h +++ b/modules/navigation/godot_navigation_server.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_navigation_server.h */ +/* godot_navigation_server.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef GD_NAVIGATION_SERVER_H -#define GD_NAVIGATION_SERVER_H +#ifndef GODOT_NAVIGATION_SERVER_H +#define GODOT_NAVIGATION_SERVER_H #include "core/templates/local_vector.h" #include "core/templates/rid.h" @@ -61,31 +61,31 @@ virtual void F_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3 = D_3_DEF) const; \ void MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) -class GdNavigationServer; +class GodotNavigationServer; struct SetCommand { virtual ~SetCommand() {} - virtual void exec(GdNavigationServer *server) = 0; + virtual void exec(GodotNavigationServer *server) = 0; }; -class GdNavigationServer : public NavigationServer3D { +class GodotNavigationServer : public NavigationServer3D { Mutex commands_mutex; /// Mutex used to make any operation threadsafe. Mutex operations_mutex; std::vector<SetCommand *> commands; - mutable RID_PtrOwner<NavMap> map_owner; - mutable RID_PtrOwner<NavRegion> region_owner; - mutable RID_PtrOwner<RvoAgent> agent_owner; + mutable RID_Owner<NavMap> map_owner; + mutable RID_Owner<NavRegion> region_owner; + mutable RID_Owner<RvoAgent> agent_owner; bool active = true; LocalVector<NavMap *> active_maps; LocalVector<uint32_t> active_maps_update_id; public: - GdNavigationServer(); - virtual ~GdNavigationServer(); + GodotNavigationServer(); + virtual ~GodotNavigationServer(); void add_command(SetCommand *command) const; @@ -146,4 +146,4 @@ public: #undef COMMAND_2 #undef COMMAND_4_DEF -#endif // GD_NAVIGATION_SERVER_H +#endif // GODOT_NAVIGATION_SERVER_H diff --git a/modules/gdnavigation/nav_map.cpp b/modules/navigation/nav_map.cpp index 41306f0687..3150ca0bc8 100644 --- a/modules/gdnavigation/nav_map.cpp +++ b/modules/navigation/nav_map.cpp @@ -734,7 +734,7 @@ void NavMap::dispatch_callbacks() { void NavMap::clip_path(const std::vector<gd::NavigationPoly> &p_navigation_polys, Vector<Vector3> &path, const gd::NavigationPoly *from_poly, const Vector3 &p_to_point, const gd::NavigationPoly *p_to_poly) const { Vector3 from = path[path.size() - 1]; - if (from.distance_to(p_to_point) < CMP_EPSILON) { + if (from.is_equal_approx(p_to_point)) { return; } Plane cut_plane; @@ -752,10 +752,10 @@ void NavMap::clip_path(const std::vector<gd::NavigationPoly> &p_navigation_polys ERR_FAIL_COND(from_poly->back_navigation_poly_id == -1); from_poly = &p_navigation_polys[from_poly->back_navigation_poly_id]; - if (pathway_start.distance_to(pathway_end) > CMP_EPSILON) { + if (!pathway_start.is_equal_approx(pathway_end)) { Vector3 inters; if (cut_plane.intersects_segment(pathway_start, pathway_end, &inters)) { - if (inters.distance_to(p_to_point) > CMP_EPSILON && inters.distance_to(path[path.size() - 1]) > CMP_EPSILON) { + if (!inters.is_equal_approx(p_to_point) && !inters.is_equal_approx(path[path.size() - 1])) { path.push_back(inters); } } diff --git a/modules/gdnavigation/nav_map.h b/modules/navigation/nav_map.h index 8e013a72eb..8e013a72eb 100644 --- a/modules/gdnavigation/nav_map.h +++ b/modules/navigation/nav_map.h diff --git a/modules/gdnavigation/nav_region.cpp b/modules/navigation/nav_region.cpp index 81b15a49f5..81b15a49f5 100644 --- a/modules/gdnavigation/nav_region.cpp +++ b/modules/navigation/nav_region.cpp diff --git a/modules/gdnavigation/nav_region.h b/modules/navigation/nav_region.h index f8b067e638..f8b067e638 100644 --- a/modules/gdnavigation/nav_region.h +++ b/modules/navigation/nav_region.h diff --git a/modules/gdnavigation/nav_rid.h b/modules/navigation/nav_rid.h index a0a60a3643..a0a60a3643 100644 --- a/modules/gdnavigation/nav_rid.h +++ b/modules/navigation/nav_rid.h diff --git a/modules/gdnavigation/nav_utils.h b/modules/navigation/nav_utils.h index 35da391eea..35da391eea 100644 --- a/modules/gdnavigation/nav_utils.h +++ b/modules/navigation/nav_utils.h diff --git a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp b/modules/navigation/navigation_mesh_editor_plugin.cpp index aa9248d2a1..8f4203e260 100644 --- a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp +++ b/modules/navigation/navigation_mesh_editor_plugin.cpp @@ -47,8 +47,8 @@ void NavigationMeshEditor::_node_removed(Node *p_node) { void NavigationMeshEditor::_notification(int p_option) { if (p_option == NOTIFICATION_ENTER_TREE) { - button_bake->set_icon(get_theme_icon("Bake", "EditorIcons")); - button_reset->set_icon(get_theme_icon("Reload", "EditorIcons")); + button_bake->set_icon(get_theme_icon(SNAME("Bake"), SNAME("EditorIcons"))); + button_reset->set_icon(get_theme_icon(SNAME("Reload"), SNAME("EditorIcons"))); } } diff --git a/modules/gdnavigation/navigation_mesh_editor_plugin.h b/modules/navigation/navigation_mesh_editor_plugin.h index c39269865b..c39269865b 100644 --- a/modules/gdnavigation/navigation_mesh_editor_plugin.h +++ b/modules/navigation/navigation_mesh_editor_plugin.h diff --git a/modules/gdnavigation/navigation_mesh_generator.cpp b/modules/navigation/navigation_mesh_generator.cpp index 0d8330c1da..7aeb9e1858 100644 --- a/modules/gdnavigation/navigation_mesh_generator.cpp +++ b/modules/navigation/navigation_mesh_generator.cpp @@ -47,12 +47,12 @@ #include "scene/resources/sphere_shape_3d.h" #include "scene/resources/world_margin_shape_3d.h" -#include "modules/modules_enabled.gen.h" #ifdef TOOLS_ENABLED #include "editor/editor_node.h" #include "editor/editor_settings.h" #endif +#include "modules/modules_enabled.gen.h" #ifdef MODULE_CSG_ENABLED #include "modules/csg/csg_shape.h" #endif diff --git a/modules/gdnavigation/navigation_mesh_generator.h b/modules/navigation/navigation_mesh_generator.h index 847c7d097b..847c7d097b 100644 --- a/modules/gdnavigation/navigation_mesh_generator.h +++ b/modules/navigation/navigation_mesh_generator.h diff --git a/modules/gdnavigation/register_types.cpp b/modules/navigation/register_types.cpp index 8443d3d242..97c01d42ab 100644 --- a/modules/gdnavigation/register_types.cpp +++ b/modules/navigation/register_types.cpp @@ -31,9 +31,10 @@ #include "register_types.h" #include "core/config/engine.h" -#include "gd_navigation_server.h" #include "servers/navigation_server_3d.h" +#include "godot_navigation_server.h" + #ifndef _3D_DISABLED #include "navigation_mesh_generator.h" #endif @@ -42,38 +43,29 @@ #include "navigation_mesh_editor_plugin.h" #endif -/** - @author AndreaCatania -*/ - #ifndef _3D_DISABLED NavigationMeshGenerator *_nav_mesh_generator = nullptr; #endif NavigationServer3D *new_server() { - return memnew(GdNavigationServer); + return memnew(GodotNavigationServer); } -void register_gdnavigation_types() { +void register_navigation_types() { NavigationServer3DManager::set_default_server(new_server); #ifndef _3D_DISABLED _nav_mesh_generator = memnew(NavigationMeshGenerator); - ClassDB::register_class<NavigationMeshGenerator>(); + GDREGISTER_CLASS(NavigationMeshGenerator); Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationMeshGenerator", NavigationMeshGenerator::get_singleton())); #endif #ifdef TOOLS_ENABLED EditorPlugins::add_by_type<NavigationMeshEditorPlugin>(); - - ClassDB::APIType prev_api = ClassDB::get_current_api(); - ClassDB::set_current_api(ClassDB::API_EDITOR); - - ClassDB::set_current_api(prev_api); #endif } -void unregister_gdnavigation_types() { +void unregister_navigation_types() { #ifndef _3D_DISABLED if (_nav_mesh_generator) { memdelete(_nav_mesh_generator); diff --git a/modules/gdnavigation/register_types.h b/modules/navigation/register_types.h index c2bb08c649..4737c818eb 100644 --- a/modules/gdnavigation/register_types.h +++ b/modules/navigation/register_types.h @@ -28,14 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -/** - @author AndreaCatania -*/ +#ifndef NAVIGATION_REGISTER_TYPES_H +#define NAVIGATION_REGISTER_TYPES_H -#ifndef GDNAVIGATION_REGISTER_TYPES_H -#define GDNAVIGATION_REGISTER_TYPES_H +void register_navigation_types(); +void unregister_navigation_types(); -void register_gdnavigation_types(); -void unregister_gdnavigation_types(); - -#endif // GDNAVIGATION_REGISTER_TYPES_H +#endif // NAVIGATION_REGISTER_TYPES_H diff --git a/modules/gdnavigation/rvo_agent.cpp b/modules/navigation/rvo_agent.cpp index 21e43d08c1..21e43d08c1 100644 --- a/modules/gdnavigation/rvo_agent.cpp +++ b/modules/navigation/rvo_agent.cpp diff --git a/modules/gdnavigation/rvo_agent.h b/modules/navigation/rvo_agent.h index 369cb1f9a3..369cb1f9a3 100644 --- a/modules/gdnavigation/rvo_agent.h +++ b/modules/navigation/rvo_agent.h diff --git a/modules/opensimplex/noise_texture.cpp b/modules/opensimplex/noise_texture.cpp index 66c52ffbf9..9db3f3d5fd 100644 --- a/modules/opensimplex/noise_texture.cpp +++ b/modules/opensimplex/noise_texture.cpp @@ -109,7 +109,7 @@ void NoiseTexture::_thread_done(const Ref<Image> &p_image) { void NoiseTexture::_thread_function(void *p_ud) { NoiseTexture *tex = (NoiseTexture *)p_ud; - tex->call_deferred("_thread_done", tex->_generate_texture()); + tex->call_deferred(SNAME("_thread_done"), tex->_generate_texture()); } void NoiseTexture::_queue_update() { @@ -118,7 +118,7 @@ void NoiseTexture::_queue_update() { } update_queued = true; - call_deferred("_update_texture"); + call_deferred(SNAME("_update_texture")); } Ref<Image> NoiseTexture::_generate_texture() { diff --git a/modules/opensimplex/register_types.cpp b/modules/opensimplex/register_types.cpp index e9735a2cc8..d6f9f3436d 100644 --- a/modules/opensimplex/register_types.cpp +++ b/modules/opensimplex/register_types.cpp @@ -33,8 +33,8 @@ #include "open_simplex_noise.h" void register_opensimplex_types() { - ClassDB::register_class<OpenSimplexNoise>(); - ClassDB::register_class<NoiseTexture>(); + GDREGISTER_CLASS(OpenSimplexNoise); + GDREGISTER_CLASS(NoiseTexture); } void unregister_opensimplex_types() { diff --git a/modules/pvr/image_compress_pvrtc.cpp b/modules/pvr/image_compress_pvrtc.cpp index f33912cec0..980cac17d3 100644 --- a/modules/pvr/image_compress_pvrtc.cpp +++ b/modules/pvr/image_compress_pvrtc.cpp @@ -43,6 +43,10 @@ static void _compress_pvrtc1_4bpp(Image *p_img) { if (!img->is_size_po2() || img->get_width() != img->get_height()) { make_mipmaps = img->has_mipmaps(); img->resize_to_po2(true); + // Resizing can fail for some formats + if (!img->is_size_po2() || img->get_width() != img->get_height()) { + ERR_FAIL_MSG("Failed to resize the image for compression."); + } } img->convert(Image::FORMAT_RGBA8); if (!img->has_mipmaps() && make_mipmaps) { diff --git a/modules/regex/register_types.cpp b/modules/regex/register_types.cpp index 82f3eaf707..03957f88cf 100644 --- a/modules/regex/register_types.cpp +++ b/modules/regex/register_types.cpp @@ -33,8 +33,8 @@ #include "regex.h" void register_regex_types() { - ClassDB::register_class<RegExMatch>(); - ClassDB::register_class<RegEx>(); + GDREGISTER_CLASS(RegExMatch); + GDREGISTER_CLASS(RegEx); } void unregister_regex_types() { diff --git a/modules/stb_vorbis/register_types.cpp b/modules/stb_vorbis/register_types.cpp index d9c6c06d65..bdb1cf69cf 100644 --- a/modules/stb_vorbis/register_types.cpp +++ b/modules/stb_vorbis/register_types.cpp @@ -45,7 +45,7 @@ void register_stb_vorbis_types() { ResourceFormatImporter::get_singleton()->add_importer(ogg_import); } #endif - ClassDB::register_class<AudioStreamOGGVorbis>(); + GDREGISTER_CLASS(AudioStreamOGGVorbis); } void unregister_stb_vorbis_types() { diff --git a/modules/text_server_adv/dynamic_font_adv.h b/modules/text_server_adv/dynamic_font_adv.h index 1292966f0c..b3f97bb029 100644 --- a/modules/text_server_adv/dynamic_font_adv.h +++ b/modules/text_server_adv/dynamic_font_adv.h @@ -34,7 +34,6 @@ #include "font_adv.h" #include "modules/modules_enabled.gen.h" - #ifdef MODULE_FREETYPE_ENABLED #include <ft2build.h> diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index 906ebe4993..2513039e8e 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -129,6 +129,10 @@ _FORCE_INLINE_ bool is_linebreak(char32_t p_char) { return (p_char >= 0x000a && p_char <= 0x000d) || (p_char == 0x0085) || (p_char == 0x2028) || (p_char == 0x2029); } +_FORCE_INLINE_ bool is_underscore(char32_t p_char) { + return (p_char == 0x005F); +} + /*************************************************************************/ String TextServerAdvanced::interface_name = "ICU / HarfBuzz / Graphite"; @@ -1658,6 +1662,161 @@ float TextServerAdvanced::shaped_text_tab_align(RID p_shaped, const Vector<float return 0.f; } +void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, float p_width, uint8_t p_clip_flags) { + _THREAD_SAFE_METHOD_ + ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped_line); + ERR_FAIL_COND_MSG(!sd, "ShapedTextDataAdvanced invalid."); + if (!sd->valid) { + shaped_text_shape(p_shaped_line); + } + + bool add_ellipsis = (p_clip_flags & OVERRUN_ADD_ELLIPSIS) == OVERRUN_ADD_ELLIPSIS; + bool cut_per_word = (p_clip_flags & OVERRUN_TRIM_WORD_ONLY) == OVERRUN_TRIM_WORD_ONLY; + bool enforce_ellipsis = (p_clip_flags & OVERRUN_ENFORCE_ELLIPSIS) == OVERRUN_ENFORCE_ELLIPSIS; + + Glyph *sd_glyphs = sd->glyphs.ptrw(); + + if ((p_clip_flags & OVERRUN_TRIM) == OVERRUN_NO_TRIMMING || sd_glyphs == nullptr || p_width <= 0 || !(sd->width > p_width || enforce_ellipsis)) { + return; + } + + int sd_size = sd->glyphs.size(); + RID last_gl_font_rid = sd_glyphs[sd_size - 1].font_rid; + int last_gl_font_size = sd_glyphs[sd_size - 1].font_size; + uint32_t dot_gl_idx = font_get_glyph_index(last_gl_font_rid, '.'); + Vector2 dot_adv = font_get_glyph_advance(last_gl_font_rid, dot_gl_idx, last_gl_font_size); + uint32_t whitespace_gl_idx = font_get_glyph_index(last_gl_font_rid, ' '); + Vector2 whitespace_adv = font_get_glyph_advance(last_gl_font_rid, whitespace_gl_idx, last_gl_font_size); + + int ellipsis_advance = 0; + if (add_ellipsis) { + ellipsis_advance = 3 * dot_adv.x + font_get_spacing_glyph(last_gl_font_rid) + (cut_per_word ? whitespace_adv.x : 0); + } + + int ell_min_characters = 6; + float width = sd->width; + + bool is_rtl = sd->direction == DIRECTION_RTL || (sd->direction == DIRECTION_AUTO && sd->para_direction == DIRECTION_RTL); + + int trim_pos = (is_rtl) ? sd_size : 0; + int ellipsis_pos = (enforce_ellipsis) ? 0 : -1; + + int last_valid_cut = 0; + bool found = false; + + int glyphs_from = (is_rtl) ? 0 : sd_size - 1; + int glyphs_to = (is_rtl) ? sd_size - 1 : -1; + int glyphs_delta = (is_rtl) ? +1 : -1; + + for (int i = glyphs_from; i != glyphs_to; i += glyphs_delta) { + if (!is_rtl) { + width -= sd_glyphs[i].advance; + } + if (sd_glyphs[i].count > 0) { + bool above_min_char_treshold = ((is_rtl) ? sd_size - 1 - i : i) >= ell_min_characters; + + if (width + (((above_min_char_treshold && add_ellipsis) || enforce_ellipsis) ? ellipsis_advance : 0) <= p_width) { + if (cut_per_word && above_min_char_treshold) { + if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) { + last_valid_cut = i; + found = true; + } + } else { + last_valid_cut = i; + found = true; + } + if (found) { + trim_pos = last_valid_cut; + + if (above_min_char_treshold && width - ellipsis_advance <= p_width) { + ellipsis_pos = trim_pos; + } + break; + } + } + } + if (is_rtl) { + width -= sd_glyphs[i].advance; + } + } + + if ((trim_pos >= 0 && sd->width > p_width) || enforce_ellipsis) { + int added_glyphs = 0; + if (add_ellipsis && (ellipsis_pos > 0 || enforce_ellipsis)) { + // Insert an additional space when cutting word bound for aesthetics. + if (cut_per_word && (ellipsis_pos > 0)) { + TextServer::Glyph gl; + gl.start = sd_glyphs[ellipsis_pos].start; + gl.end = sd_glyphs[ellipsis_pos].end; + gl.count = 1; + gl.advance = whitespace_adv.x; + gl.index = whitespace_gl_idx; + gl.font_rid = last_gl_font_rid; + gl.font_size = last_gl_font_size; + gl.flags = GRAPHEME_IS_SPACE | GRAPHEME_IS_BREAK_SOFT | GRAPHEME_IS_VIRTUAL | (is_rtl ? GRAPHEME_IS_RTL : 0); + + // Optimized glyph insertion by replacing a glyph whenever possible. + int glyph_idx = trim_pos + ((is_rtl) ? (-added_glyphs - 1) : added_glyphs); + if (is_rtl) { + if (glyph_idx < 0) { + sd->glyphs.insert(0, gl); + } else { + sd->glyphs.set(glyph_idx, gl); + } + } else { + if (glyph_idx > (sd_size - 1)) { + sd->glyphs.append(gl); + } else { + sd->glyphs.set(glyph_idx, gl); + } + } + added_glyphs++; + } + // Add ellipsis dots. + for (int d = 0; d < 3; d++) { + TextServer::Glyph gl; + gl.start = sd_glyphs[ellipsis_pos].start; + gl.end = sd_glyphs[ellipsis_pos].end; + gl.count = 1; + gl.advance = dot_adv.x; + gl.index = dot_gl_idx; + gl.font_rid = last_gl_font_rid; + gl.font_size = last_gl_font_size; + gl.flags = GRAPHEME_IS_PUNCTUATION | GRAPHEME_IS_VIRTUAL | (is_rtl ? GRAPHEME_IS_RTL : 0); + + // Optimized glyph insertion by replacing a glyph whenever possible. + int glyph_idx = trim_pos + ((is_rtl) ? (-added_glyphs - 1) : added_glyphs); + if (is_rtl) { + if (glyph_idx < 0) { + sd->glyphs.insert(0, gl); + } else { + sd->glyphs.set(glyph_idx, gl); + } + } else { + if (glyph_idx > (sd_size - 1)) { + sd->glyphs.append(gl); + } else { + sd->glyphs.set(glyph_idx, gl); + } + } + added_glyphs++; + } + } + + // Cut the remaining glyphs off. + if (!is_rtl) { + sd->glyphs.resize(trim_pos + added_glyphs); + } else { + if (trim_pos - added_glyphs >= 0) { + sd->glyphs = sd->glyphs.subarray(trim_pos - added_glyphs, sd->glyphs.size() - 1); + } + } + + // Update to correct width. + sd->width = width + ((ellipsis_pos != -1) ? ellipsis_advance : 0); + } +} + bool TextServerAdvanced::shaped_text_update_breaks(RID p_shaped) { _THREAD_SAFE_METHOD_ ShapedTextDataAdvanced *sd = shaped_owner.getornull(p_shaped); @@ -1728,7 +1887,10 @@ bool TextServerAdvanced::shaped_text_update_breaks(RID p_shaped) { if (is_whitespace(c)) { sd_glyphs[i].flags |= GRAPHEME_IS_SPACE; } - if (u_ispunct(c)) { + if (is_underscore(c)) { + sd_glyphs[i].flags |= GRAPHEME_IS_UNDERSCORE; + } + if (u_ispunct(c) && c != 0x005F) { sd_glyphs[i].flags |= GRAPHEME_IS_PUNCTUATION; } if (breaks.has(sd->glyphs[i].start)) { diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h index 4ad23ca059..3c4f840bfd 100644 --- a/modules/text_server_adv/text_server_adv.h +++ b/modules/text_server_adv/text_server_adv.h @@ -229,6 +229,8 @@ public: virtual bool shaped_text_update_breaks(RID p_shaped) override; virtual bool shaped_text_update_justification_ops(RID p_shaped) override; + virtual void shaped_text_overrun_trim_to_width(RID p_shaped, float p_width, uint8_t p_clip_flags) override; + virtual bool shaped_text_is_ready(RID p_shaped) const override; virtual Vector<Glyph> shaped_text_get_glyphs(RID p_shaped) const override; diff --git a/modules/text_server_fb/dynamic_font_fb.h b/modules/text_server_fb/dynamic_font_fb.h index b34c8cbed5..82e59fa607 100644 --- a/modules/text_server_fb/dynamic_font_fb.h +++ b/modules/text_server_fb/dynamic_font_fb.h @@ -34,7 +34,6 @@ #include "font_fb.h" #include "modules/modules_enabled.gen.h" - #ifdef MODULE_FREETYPE_ENABLED #include <ft2build.h> diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index a22559efdd..9ad7dabbcc 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -46,7 +46,11 @@ _FORCE_INLINE_ bool is_linebreak(char32_t p_char) { } _FORCE_INLINE_ bool is_punct(char32_t p_char) { - return (p_char >= 0x0020 && p_char <= 0x002F) || (p_char >= 0x003A && p_char <= 0x0040) || (p_char >= 0x005B && p_char <= 0x0060) || (p_char >= 0x007B && p_char <= 0x007E) || (p_char >= 0x2000 && p_char <= 0x206F) || (p_char >= 0x3000 && p_char <= 0x303F); + return (p_char >= 0x0020 && p_char <= 0x002F) || (p_char >= 0x003A && p_char <= 0x0040) || (p_char >= 0x005B && p_char <= 0x005E) || (p_char == 0x0060) || (p_char >= 0x007B && p_char <= 0x007E) || (p_char >= 0x2000 && p_char <= 0x206F) || (p_char >= 0x3000 && p_char <= 0x303F); +} + +_FORCE_INLINE_ bool is_underscore(char32_t p_char) { + return (p_char == 0x005F); } /*************************************************************************/ @@ -1108,6 +1112,9 @@ bool TextServerFallback::shaped_text_update_breaks(RID p_shaped) { if (is_punct(c)) { sd->glyphs.write[i].flags |= GRAPHEME_IS_PUNCTUATION; } + if (is_underscore(c)) { + sd->glyphs.write[i].flags |= GRAPHEME_IS_UNDERSCORE; + } if (is_whitespace(c) && !is_linebreak(c)) { sd->glyphs.write[i].flags |= GRAPHEME_IS_SPACE; sd->glyphs.write[i].flags |= GRAPHEME_IS_BREAK_SOFT; @@ -1141,6 +1148,161 @@ bool TextServerFallback::shaped_text_update_justification_ops(RID p_shaped) { return true; } +void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, float p_width, uint8_t p_clip_flags) { + _THREAD_SAFE_METHOD_ + ShapedTextData *sd = shaped_owner.getornull(p_shaped_line); + ERR_FAIL_COND_MSG(!sd, "ShapedTextDataAdvanced invalid."); + if (!sd->valid) { + shaped_text_shape(p_shaped_line); + } + + bool add_ellipsis = (p_clip_flags & OVERRUN_ADD_ELLIPSIS) == OVERRUN_ADD_ELLIPSIS; + bool cut_per_word = (p_clip_flags & OVERRUN_TRIM_WORD_ONLY) == OVERRUN_TRIM_WORD_ONLY; + bool enforce_ellipsis = (p_clip_flags & OVERRUN_ENFORCE_ELLIPSIS) == OVERRUN_ENFORCE_ELLIPSIS; + + Glyph *sd_glyphs = sd->glyphs.ptrw(); + + if ((p_clip_flags & OVERRUN_TRIM) == OVERRUN_NO_TRIMMING || sd_glyphs == nullptr || p_width <= 0 || !(sd->width > p_width || enforce_ellipsis)) { + return; + } + + int sd_size = sd->glyphs.size(); + RID last_gl_font_rid = sd_glyphs[sd_size - 1].font_rid; + int last_gl_font_size = sd_glyphs[sd_size - 1].font_size; + uint32_t dot_gl_idx = font_get_glyph_index(last_gl_font_rid, '.'); + Vector2 dot_adv = font_get_glyph_advance(last_gl_font_rid, dot_gl_idx, last_gl_font_size); + uint32_t whitespace_gl_idx = font_get_glyph_index(last_gl_font_rid, ' '); + Vector2 whitespace_adv = font_get_glyph_advance(last_gl_font_rid, whitespace_gl_idx, last_gl_font_size); + + int ellipsis_advance = 0; + if (add_ellipsis) { + ellipsis_advance = 3 * dot_adv.x + font_get_spacing_glyph(last_gl_font_rid) + (cut_per_word ? whitespace_adv.x : 0); + } + + int ell_min_characters = 6; + float width = sd->width; + + bool is_rtl = sd->direction == DIRECTION_RTL || (sd->direction == DIRECTION_AUTO && sd->para_direction == DIRECTION_RTL); + + int trim_pos = (is_rtl) ? sd_size : 0; + int ellipsis_pos = (enforce_ellipsis) ? 0 : -1; + + int last_valid_cut = 0; + bool found = false; + + int glyphs_from = (is_rtl) ? 0 : sd_size - 1; + int glyphs_to = (is_rtl) ? sd_size - 1 : -1; + int glyphs_delta = (is_rtl) ? +1 : -1; + + for (int i = glyphs_from; i != glyphs_to; i += glyphs_delta) { + if (!is_rtl) { + width -= sd_glyphs[i].advance; + } + if (sd_glyphs[i].count > 0) { + bool above_min_char_treshold = ((is_rtl) ? sd_size - 1 - i : i) >= ell_min_characters; + + if (width + (((above_min_char_treshold && add_ellipsis) || enforce_ellipsis) ? ellipsis_advance : 0) <= p_width) { + if (cut_per_word && above_min_char_treshold) { + if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) { + last_valid_cut = i; + found = true; + } + } else { + last_valid_cut = i; + found = true; + } + if (found) { + trim_pos = last_valid_cut; + + if (above_min_char_treshold && width - ellipsis_advance <= p_width) { + ellipsis_pos = trim_pos; + } + break; + } + } + } + if (is_rtl) { + width -= sd_glyphs[i].advance; + } + } + + if ((trim_pos >= 0 && sd->width > p_width) || enforce_ellipsis) { + int added_glyphs = 0; + if (add_ellipsis && (ellipsis_pos > 0 || enforce_ellipsis)) { + // Insert an additional space when cutting word bound for aesthetics. + if (cut_per_word && (ellipsis_pos > 0)) { + TextServer::Glyph gl; + gl.start = sd_glyphs[ellipsis_pos].start; + gl.end = sd_glyphs[ellipsis_pos].end; + gl.count = 1; + gl.advance = whitespace_adv.x; + gl.index = whitespace_gl_idx; + gl.font_rid = last_gl_font_rid; + gl.font_size = last_gl_font_size; + gl.flags = GRAPHEME_IS_SPACE | GRAPHEME_IS_BREAK_SOFT | GRAPHEME_IS_VIRTUAL | (is_rtl ? GRAPHEME_IS_RTL : 0); + + // Optimized glyph insertion by replacing a glyph whenever possible. + int glyph_idx = trim_pos + ((is_rtl) ? -added_glyphs : added_glyphs); + if (is_rtl) { + if (glyph_idx < 0) { + sd->glyphs.insert(0, gl); + } else { + sd->glyphs.set(glyph_idx, gl); + } + } else { + if (glyph_idx > (sd_size - 1)) { + sd->glyphs.append(gl); + } else { + sd->glyphs.set(glyph_idx, gl); + } + } + added_glyphs++; + } + // Add ellipsis dots. + for (int d = 0; d < 3; d++) { + TextServer::Glyph gl; + gl.start = sd_glyphs[ellipsis_pos].start; + gl.end = sd_glyphs[ellipsis_pos].end; + gl.count = 1; + gl.advance = dot_adv.x; + gl.index = dot_gl_idx; + gl.font_rid = last_gl_font_rid; + gl.font_size = last_gl_font_size; + gl.flags = GRAPHEME_IS_PUNCTUATION | GRAPHEME_IS_VIRTUAL | (is_rtl ? GRAPHEME_IS_RTL : 0); + + // Optimized glyph insertion by replacing a glyph whenever possible. + int glyph_idx = trim_pos + ((is_rtl) ? -added_glyphs : added_glyphs); + if (is_rtl) { + if (glyph_idx < 0) { + sd->glyphs.insert(0, gl); + } else { + sd->glyphs.set(glyph_idx, gl); + } + } else { + if (glyph_idx > (sd_size - 1)) { + sd->glyphs.append(gl); + } else { + sd->glyphs.set(glyph_idx, gl); + } + } + added_glyphs++; + } + } + + // Cut the remaining glyphs off. + if (!is_rtl) { + sd->glyphs.resize(trim_pos + added_glyphs); + } else { + for (int ridx = 0; ridx <= trim_pos - added_glyphs; ridx++) { + sd->glyphs.remove(0); + } + } + + // Update to correct width. + sd->width = width + ((ellipsis_pos != -1) ? ellipsis_advance : 0); + } +} + bool TextServerFallback::shaped_text_shape(RID p_shaped) { _THREAD_SAFE_METHOD_ ShapedTextData *sd = shaped_owner.getornull(p_shaped); diff --git a/modules/text_server_fb/text_server_fb.h b/modules/text_server_fb/text_server_fb.h index 8f5eb1d315..b70c8f4ec0 100644 --- a/modules/text_server_fb/text_server_fb.h +++ b/modules/text_server_fb/text_server_fb.h @@ -178,6 +178,8 @@ public: virtual bool shaped_text_update_breaks(RID p_shaped) override; virtual bool shaped_text_update_justification_ops(RID p_shaped) override; + virtual void shaped_text_overrun_trim_to_width(RID p_shaped, float p_width, uint8_t p_clip_flags) override; + virtual bool shaped_text_is_ready(RID p_shaped) const override; virtual Vector<Glyph> shaped_text_get_glyphs(RID p_shaped) const override; diff --git a/modules/theora/register_types.cpp b/modules/theora/register_types.cpp index fd6c9dcd3c..55148a6b87 100644 --- a/modules/theora/register_types.cpp +++ b/modules/theora/register_types.cpp @@ -38,7 +38,7 @@ void register_theora_types() { resource_loader_theora.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_theora, true); - ClassDB::register_class<VideoStreamTheora>(); + GDREGISTER_CLASS(VideoStreamTheora); } void unregister_theora_types() { diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index 40be067a91..2f6faec8ec 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -108,7 +108,7 @@ void VideoStreamPlaybackTheora::video_write() { Ref<Image> img = memnew(Image(size.x, size.y, 0, Image::FORMAT_RGBA8, frame_data)); //zero copy image creation - texture->update(img, true); //zero copy send to visual server + texture->update(img); //zero copy send to visual server frames_pending = 1; } diff --git a/modules/upnp/register_types.cpp b/modules/upnp/register_types.cpp index a5ee39517f..1e5edd3602 100644 --- a/modules/upnp/register_types.cpp +++ b/modules/upnp/register_types.cpp @@ -36,8 +36,8 @@ #include "upnp_device.h" void register_upnp_types() { - ClassDB::register_class<UPNP>(); - ClassDB::register_class<UPNPDevice>(); + GDREGISTER_CLASS(UPNP); + GDREGISTER_CLASS(UPNPDevice); } void unregister_upnp_types() { diff --git a/modules/vhacd/register_types.cpp b/modules/vhacd/register_types.cpp index daad39bdfb..3d7aaee921 100644 --- a/modules/vhacd/register_types.cpp +++ b/modules/vhacd/register_types.cpp @@ -32,7 +32,7 @@ #include "scene/resources/mesh.h" #include "thirdparty/vhacd/public/VHACD.h" -static Vector<Vector<Face3>> convex_decompose(const Vector<Face3> &p_faces) { +static Vector<Vector<Face3>> convex_decompose(const Vector<Face3> &p_faces, int p_max_convex_hulls = -1) { Vector<float> vertices; vertices.resize(p_faces.size() * 9); Vector<uint32_t> indices; @@ -47,8 +47,12 @@ static Vector<Vector<Face3>> convex_decompose(const Vector<Face3> &p_faces) { } } - VHACD::IVHACD *decomposer = VHACD::CreateVHACD(); VHACD::IVHACD::Parameters params; + if (p_max_convex_hulls > 0) { + params.m_maxConvexHulls = p_max_convex_hulls; + } + + VHACD::IVHACD *decomposer = VHACD::CreateVHACD(); decomposer->Compute(vertices.ptr(), vertices.size() / 3, indices.ptr(), indices.size() / 3, params); int hull_count = decomposer->GetNConvexHulls(); diff --git a/modules/visual_script/doc_classes/VisualScriptExpression.xml b/modules/visual_script/doc_classes/VisualScriptExpression.xml index 5253f7bc7d..223adbbb96 100644 --- a/modules/visual_script/doc_classes/VisualScriptExpression.xml +++ b/modules/visual_script/doc_classes/VisualScriptExpression.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptExpression" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node that can execute a custom expression. </brief_description> <description> + A Visual Script node that can execute a custom expression. Values can be provided for the input and the expression result can be retrieved from the output. </description> <tutorials> </tutorials> diff --git a/modules/visual_script/doc_classes/VisualScriptFunction.xml b/modules/visual_script/doc_classes/VisualScriptFunction.xml index 873d26a5be..652418bd64 100644 --- a/modules/visual_script/doc_classes/VisualScriptFunction.xml +++ b/modules/visual_script/doc_classes/VisualScriptFunction.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptFunction" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node representing a function. </brief_description> <description> + [VisualScriptFunction] represents a function header. It is the starting point for the function body and can be used to tweak the function's properties (e.g. RPC mode). </description> <tutorials> </tutorials> diff --git a/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml b/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml index 48104afcf7..f0b666e57a 100644 --- a/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml +++ b/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptFunctionCall" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node for calling a function. </brief_description> <description> + [VisualScriptFunctionCall] is created when you add or drag and drop a function onto the Visual Script graph. It allows to tweak parameters of the call, e.g. what object the function is called on. </description> <tutorials> </tutorials> @@ -10,46 +12,66 @@ </methods> <members> <member name="base_script" type="String" setter="set_base_script" getter="get_base_script"> + The script to be used when [member call_mode] is set to [constant CALL_MODE_INSTANCE]. </member> <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="&"Object""> + The base type to be used when [member call_mode] is set to [constant CALL_MODE_INSTANCE]. </member> <member name="basic_type" type="int" setter="set_basic_type" getter="get_basic_type" enum="Variant.Type"> + The type to be used when [member call_mode] is set to [constant CALL_MODE_BASIC_TYPE]. </member> <member name="call_mode" type="int" setter="set_call_mode" getter="get_call_mode" enum="VisualScriptFunctionCall.CallMode" default="0"> + [code]call_mode[/code] determines the target object on which the method will be called. See [enum CallMode] for options. </member> <member name="function" type="StringName" setter="set_function" getter="get_function" default="&"""> + The name of the function to be called. </member> <member name="node_path" type="NodePath" setter="set_base_path" getter="get_base_path"> + The node path to use when [member call_mode] is set to [constant CALL_MODE_NODE_PATH]. </member> <member name="rpc_call_mode" type="int" setter="set_rpc_call_mode" getter="get_rpc_call_mode" enum="VisualScriptFunctionCall.RPCCallMode" default="0"> + The mode for RPC calls. See [method Node.rpc] for more details and [enum RPCCallMode] for available options. </member> <member name="singleton" type="StringName" setter="set_singleton" getter="get_singleton"> + The singleton to call the method on. Used when [member call_mode] is set to [constant CALL_MODE_SINGLETON]. </member> <member name="use_default_args" type="int" setter="set_use_default_args" getter="get_use_default_args"> + Number of default arguments that will be used when calling the function. Can't be higher than the number of available default arguments in the method's declaration. </member> <member name="validate" type="bool" setter="set_validate" getter="get_validate" default="true"> + If [code]false[/code], call errors (e.g. wrong number of arguments) will be ignored. </member> </members> <constants> <constant name="CALL_MODE_SELF" value="0" enum="CallMode"> + The method will be called on this [Object]. </constant> <constant name="CALL_MODE_NODE_PATH" value="1" enum="CallMode"> + The method will be called on the given [Node] in the scene tree. </constant> <constant name="CALL_MODE_INSTANCE" value="2" enum="CallMode"> + The method will be called on an instanced node with the given type and script. </constant> <constant name="CALL_MODE_BASIC_TYPE" value="3" enum="CallMode"> + The method will be called on a GDScript basic type (e.g. [Vector2]). </constant> <constant name="CALL_MODE_SINGLETON" value="4" enum="CallMode"> + The method will be called on a singleton. </constant> <constant name="RPC_DISABLED" value="0" enum="RPCCallMode"> + The method will be called locally. </constant> <constant name="RPC_RELIABLE" value="1" enum="RPCCallMode"> + The method will be called remotely. </constant> <constant name="RPC_UNRELIABLE" value="2" enum="RPCCallMode"> + The method will be called remotely using an unreliable protocol. </constant> <constant name="RPC_RELIABLE_TO_ID" value="3" enum="RPCCallMode"> + The method will be called remotely for the given peer. </constant> <constant name="RPC_UNRELIABLE_TO_ID" value="4" enum="RPCCallMode"> + The method will be called remotely for the given peer, using an unreliable protocol. </constant> </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptFunctionState.xml b/modules/visual_script/doc_classes/VisualScriptFunctionState.xml index 16c1629fe4..54a02bf270 100644 --- a/modules/visual_script/doc_classes/VisualScriptFunctionState.xml +++ b/modules/visual_script/doc_classes/VisualScriptFunctionState.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptFunctionState" inherits="RefCounted" version="4.0"> <brief_description> + A Visual Script node representing a function state. </brief_description> <description> + [VisualScriptFunctionState] is returned from [VisualScriptYield] and can be used to resume a paused function call. </description> <tutorials> </tutorials> @@ -17,12 +19,14 @@ <argument index="2" name="args" type="Array"> </argument> <description> + Connects this [VisualScriptFunctionState] to a signal in the given object to automatically resume when it's emitted. </description> </method> <method name="is_valid" qualifiers="const"> <return type="bool"> </return> <description> + Returns whether the function state is valid. </description> </method> <method name="resume"> @@ -31,6 +35,7 @@ <argument index="0" name="args" type="Array" default="[]"> </argument> <description> + Resumes the function to run from the point it was yielded. </description> </method> </methods> diff --git a/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml b/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml index ef17bd8a28..87fdfd4e53 100644 --- a/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml +++ b/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptGlobalConstant" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node returning a constant from [@GlobalScope]. </brief_description> <description> + A Visual Script node returning a constant from [@GlobalScope]. </description> <tutorials> </tutorials> @@ -10,6 +12,7 @@ </methods> <members> <member name="constant" type="int" setter="set_global_constant" getter="get_global_constant" default="0"> + The constant to be used. </member> </members> <constants> diff --git a/modules/visual_script/doc_classes/VisualScriptIndexGet.xml b/modules/visual_script/doc_classes/VisualScriptIndexGet.xml index bb1618a655..b348048298 100644 --- a/modules/visual_script/doc_classes/VisualScriptIndexGet.xml +++ b/modules/visual_script/doc_classes/VisualScriptIndexGet.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptIndexGet" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node for getting a value from an array or a dictionary. </brief_description> <description> + [VisualScriptIndexGet] will return the value stored in an array or a dictionary under the given index. </description> <tutorials> </tutorials> diff --git a/modules/visual_script/doc_classes/VisualScriptIndexSet.xml b/modules/visual_script/doc_classes/VisualScriptIndexSet.xml index 4ff96f7211..d7fe7340ad 100644 --- a/modules/visual_script/doc_classes/VisualScriptIndexSet.xml +++ b/modules/visual_script/doc_classes/VisualScriptIndexSet.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptIndexSet" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node for setting a value in an array or a dictionary. </brief_description> <description> + [VisualScriptIndexSet] will set the value stored in an array or a dictionary under the given index to the provided new value. </description> <tutorials> </tutorials> diff --git a/modules/visual_script/doc_classes/VisualScriptInputAction.xml b/modules/visual_script/doc_classes/VisualScriptInputAction.xml index 9ca67feacb..d6fa111500 100644 --- a/modules/visual_script/doc_classes/VisualScriptInputAction.xml +++ b/modules/visual_script/doc_classes/VisualScriptInputAction.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptInputAction" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node returning a state of an action. </brief_description> <description> + [VisualScriptInputAction] can be used to check if an action is pressed or released. </description> <tutorials> </tutorials> @@ -10,18 +12,24 @@ </methods> <members> <member name="action" type="StringName" setter="set_action_name" getter="get_action_name" default="&"""> + Name of the action. </member> <member name="mode" type="int" setter="set_action_mode" getter="get_action_mode" enum="VisualScriptInputAction.Mode" default="0"> + State of the action to check. See [enum Mode] for options. </member> </members> <constants> <constant name="MODE_PRESSED" value="0" enum="Mode"> + [code]True[/code] if action is pressed. </constant> <constant name="MODE_RELEASED" value="1" enum="Mode"> + [code]True[/code] if action is released (i.e. not pressed). </constant> <constant name="MODE_JUST_PRESSED" value="2" enum="Mode"> + [code]True[/code] on the frame the action was pressed. </constant> <constant name="MODE_JUST_RELEASED" value="3" enum="Mode"> + [code]True[/code] on the frame the action was released. </constant> </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptLists.xml b/modules/visual_script/doc_classes/VisualScriptLists.xml index 8a7254b46a..671c427228 100644 --- a/modules/visual_script/doc_classes/VisualScriptLists.xml +++ b/modules/visual_script/doc_classes/VisualScriptLists.xml @@ -19,6 +19,7 @@ <argument index="2" name="index" type="int"> </argument> <description> + Adds an input port to the Visual Script node. </description> </method> <method name="add_output_data_port"> @@ -31,6 +32,7 @@ <argument index="2" name="index" type="int"> </argument> <description> + Adds an output port to the Visual Script node. </description> </method> <method name="remove_input_data_port"> @@ -39,6 +41,7 @@ <argument index="0" name="index" type="int"> </argument> <description> + Removes an input port from the Visual Script node. </description> </method> <method name="remove_output_data_port"> @@ -47,6 +50,7 @@ <argument index="0" name="index" type="int"> </argument> <description> + Removes an output port from the Visual Script node. </description> </method> <method name="set_input_data_port_name"> @@ -57,6 +61,7 @@ <argument index="1" name="name" type="String"> </argument> <description> + Sets the name of an input port. </description> </method> <method name="set_input_data_port_type"> @@ -67,6 +72,7 @@ <argument index="1" name="type" type="int" enum="Variant.Type"> </argument> <description> + Sets the type of an input port. </description> </method> <method name="set_output_data_port_name"> @@ -77,6 +83,7 @@ <argument index="1" name="name" type="String"> </argument> <description> + Sets the name of an output port. </description> </method> <method name="set_output_data_port_type"> @@ -87,6 +94,7 @@ <argument index="1" name="type" type="int" enum="Variant.Type"> </argument> <description> + Sets the type of an output port. </description> </method> </methods> diff --git a/modules/visual_script/doc_classes/VisualScriptOperator.xml b/modules/visual_script/doc_classes/VisualScriptOperator.xml index c8ce0f2732..cbbefa7f71 100644 --- a/modules/visual_script/doc_classes/VisualScriptOperator.xml +++ b/modules/visual_script/doc_classes/VisualScriptOperator.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptOperator" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node that performs an operation on two values. </brief_description> <description> [b]Input Ports:[/b] @@ -15,8 +16,10 @@ </methods> <members> <member name="operator" type="int" setter="set_operator" getter="get_operator" enum="Variant.Operator" default="6"> + The operation to be performed. See [enum Variant.Operator] for available options. </member> <member name="type" type="int" setter="set_typed" getter="get_typed" enum="Variant.Type" default="0"> + The type of the values for this operation. See [enum Variant.Type] for available options. </member> </members> <constants> diff --git a/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml b/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml index ff6c723a3e..c1bf443ea3 100644 --- a/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml +++ b/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptPropertyGet" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node returning a value of a property from an [Object]. </brief_description> <description> + [VisualScriptPropertyGet] can return a value of any property from the current object or other objects. </description> <tutorials> </tutorials> @@ -10,28 +12,39 @@ </methods> <members> <member name="base_script" type="String" setter="set_base_script" getter="get_base_script"> + The script to be used when [member set_mode] is set to [constant CALL_MODE_INSTANCE]. </member> <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="&"Object""> + The base type to be used when [member set_mode] is set to [constant CALL_MODE_INSTANCE]. </member> <member name="basic_type" type="int" setter="set_basic_type" getter="get_basic_type" enum="Variant.Type"> + The type to be used when [member set_mode] is set to [constant CALL_MODE_BASIC_TYPE]. </member> <member name="index" type="StringName" setter="set_index" getter="get_index"> + The indexed name of the property to retrieve. See [method Object.get_indexed] for details. </member> <member name="node_path" type="NodePath" setter="set_base_path" getter="get_base_path"> + The node path to use when [member set_mode] is set to [constant CALL_MODE_NODE_PATH]. </member> <member name="property" type="StringName" setter="set_property" getter="get_property" default="&"""> + The name of the property to retrieve. Changing this will clear [member index]. </member> <member name="set_mode" type="int" setter="set_call_mode" getter="get_call_mode" enum="VisualScriptPropertyGet.CallMode" default="0"> + [code]set_mode[/code] determines the target object from which the property will be retrieved. See [enum CallMode] for options. </member> </members> <constants> <constant name="CALL_MODE_SELF" value="0" enum="CallMode"> + The property will be retrieved from this [Object]. </constant> <constant name="CALL_MODE_NODE_PATH" value="1" enum="CallMode"> + The property will be retrieved from the given [Node] in the scene tree. </constant> <constant name="CALL_MODE_INSTANCE" value="2" enum="CallMode"> + The property will be retrieved from an instanced node with the given type and script. </constant> <constant name="CALL_MODE_BASIC_TYPE" value="3" enum="CallMode"> + The property will be retrieved from a GDScript basic type (e.g. [Vector2]). </constant> </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptPropertySet.xml b/modules/visual_script/doc_classes/VisualScriptPropertySet.xml index 71bfc4c8a5..75d6a63469 100644 --- a/modules/visual_script/doc_classes/VisualScriptPropertySet.xml +++ b/modules/visual_script/doc_classes/VisualScriptPropertySet.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptPropertySet" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node that sets a property of an [Object]. </brief_description> <description> + [VisualScriptPropertySet] can set the value of any property from the current object or other objects. </description> <tutorials> </tutorials> @@ -10,52 +12,75 @@ </methods> <members> <member name="assign_op" type="int" setter="set_assign_op" getter="get_assign_op" enum="VisualScriptPropertySet.AssignOp" default="0"> + The additional operation to perform when assigning. See [enum AssignOp] for options. </member> <member name="base_script" type="String" setter="set_base_script" getter="get_base_script"> + The script to be used when [member set_mode] is set to [constant CALL_MODE_INSTANCE]. </member> <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="&"Object""> + The base type to be used when [member set_mode] is set to [constant CALL_MODE_INSTANCE]. </member> <member name="basic_type" type="int" setter="set_basic_type" getter="get_basic_type" enum="Variant.Type"> + The type to be used when [member set_mode] is set to [constant CALL_MODE_BASIC_TYPE]. </member> <member name="index" type="StringName" setter="set_index" getter="get_index"> + The indexed name of the property to set. See [method Object.set_indexed] for details. </member> <member name="node_path" type="NodePath" setter="set_base_path" getter="get_base_path"> + The node path to use when [member set_mode] is set to [constant CALL_MODE_NODE_PATH]. </member> <member name="property" type="StringName" setter="set_property" getter="get_property" default="&"""> + The name of the property to set. Changing this will clear [member index]. </member> <member name="set_mode" type="int" setter="set_call_mode" getter="get_call_mode" enum="VisualScriptPropertySet.CallMode" default="0"> + [code]set_mode[/code] determines the target object on which the property will be set. See [enum CallMode] for options. </member> </members> <constants> <constant name="CALL_MODE_SELF" value="0" enum="CallMode"> + The property will be set on this [Object]. </constant> <constant name="CALL_MODE_NODE_PATH" value="1" enum="CallMode"> + The property will be set on the given [Node] in the scene tree. </constant> <constant name="CALL_MODE_INSTANCE" value="2" enum="CallMode"> + The property will be set on an instanced node with the given type and script. </constant> <constant name="CALL_MODE_BASIC_TYPE" value="3" enum="CallMode"> + The property will be set on a GDScript basic type (e.g. [Vector2]). </constant> <constant name="ASSIGN_OP_NONE" value="0" enum="AssignOp"> + The property will be assigned regularly. </constant> <constant name="ASSIGN_OP_ADD" value="1" enum="AssignOp"> + The value will be added to the property. Equivalent of doing [code]+=[/code]. </constant> <constant name="ASSIGN_OP_SUB" value="2" enum="AssignOp"> + The value will be subtracted from the property. Equivalent of doing [code]-=[/code]. </constant> <constant name="ASSIGN_OP_MUL" value="3" enum="AssignOp"> + The property will be multiplied by the value. Equivalent of doing [code]*=[/code]. </constant> <constant name="ASSIGN_OP_DIV" value="4" enum="AssignOp"> + The property will be divided by the value. Equivalent of doing [code]/=[/code]. </constant> <constant name="ASSIGN_OP_MOD" value="5" enum="AssignOp"> + A modulo operation will be performed on the property and the value. Equivalent of doing [code]%=[/code]. </constant> <constant name="ASSIGN_OP_SHIFT_LEFT" value="6" enum="AssignOp"> + The property will be binarly shifted to the left by the given value. Equivalent of doing [code]<<[/code]. </constant> <constant name="ASSIGN_OP_SHIFT_RIGHT" value="7" enum="AssignOp"> + The property will be binarly shifted to the right by the given value. Equivalent of doing [code]>>[/code]. </constant> <constant name="ASSIGN_OP_BIT_AND" value="8" enum="AssignOp"> + A binary [code]AND[/code] operation will be performed on the property. Equivalent of doing [code]&=[/code]. </constant> <constant name="ASSIGN_OP_BIT_OR" value="9" enum="AssignOp"> + A binary [code]OR[/code] operation will be performed on the property. Equivalent of doing [code]|=[/code]. </constant> <constant name="ASSIGN_OP_BIT_XOR" value="10" enum="AssignOp"> + A binary [code]XOR[/code] operation will be performed on the property. Equivalent of doing [code]^=[/code]. </constant> </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptSceneTree.xml b/modules/visual_script/doc_classes/VisualScriptSceneTree.xml index 191d4b6977..8cddd02c77 100644 --- a/modules/visual_script/doc_classes/VisualScriptSceneTree.xml +++ b/modules/visual_script/doc_classes/VisualScriptSceneTree.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptSceneTree" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node for accessing [SceneTree] methods. </brief_description> <description> + A Visual Script node for accessing [SceneTree] methods. </description> <tutorials> </tutorials> diff --git a/modules/visual_script/doc_classes/VisualScriptSubCall.xml b/modules/visual_script/doc_classes/VisualScriptSubCall.xml index cb3b04b583..89a10edde4 100644 --- a/modules/visual_script/doc_classes/VisualScriptSubCall.xml +++ b/modules/visual_script/doc_classes/VisualScriptSubCall.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptSubCall" inherits="VisualScriptNode" version="4.0"> <brief_description> + Calls a method called [code]_subcall[/code] in this object. </brief_description> <description> + [VisualScriptSubCall] will call method named [code]_subcall[/code] in the current script. It will fail if the method doesn't exist or the provided arguments are wrong. </description> <tutorials> </tutorials> @@ -13,6 +15,7 @@ <argument index="0" name="arguments" type="Variant"> </argument> <description> + Called by this node. </description> </method> </methods> diff --git a/modules/visual_script/doc_classes/VisualScriptTypeCast.xml b/modules/visual_script/doc_classes/VisualScriptTypeCast.xml index 9e3e020f2d..5dd1ad3421 100644 --- a/modules/visual_script/doc_classes/VisualScriptTypeCast.xml +++ b/modules/visual_script/doc_classes/VisualScriptTypeCast.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptTypeCast" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node that casts the given value to another type. </brief_description> <description> + [VisualScriptTypeCast] will perform a type conversion to an [Object]-derived type. </description> <tutorials> </tutorials> @@ -10,8 +12,10 @@ </methods> <members> <member name="base_script" type="String" setter="set_base_script" getter="get_base_script" default=""""> + The target script class to be converted to. If none, only the [member base_type] will be used. </member> <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="&"Object""> + The target type to be converted to. </member> </members> <constants> diff --git a/modules/visual_script/doc_classes/VisualScriptYield.xml b/modules/visual_script/doc_classes/VisualScriptYield.xml index 0a8d529a48..b04ab7b014 100644 --- a/modules/visual_script/doc_classes/VisualScriptYield.xml +++ b/modules/visual_script/doc_classes/VisualScriptYield.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptYield" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node used to pause a function execution. </brief_description> <description> + [VisualScriptYield] will pause the function call and return [VisualScriptFunctionState], which can be used to resume the function. </description> <tutorials> </tutorials> @@ -10,16 +12,21 @@ </methods> <members> <member name="mode" type="int" setter="set_yield_mode" getter="get_yield_mode" enum="VisualScriptYield.YieldMode" default="1"> + The mode to use for yielding. See [enum YieldMode] for available options. </member> <member name="wait_time" type="float" setter="set_wait_time" getter="get_wait_time"> + The time to wait when [member mode] is set to [constant YIELD_WAIT]. </member> </members> <constants> <constant name="YIELD_FRAME" value="1" enum="YieldMode"> + Yields during an idle frame. </constant> <constant name="YIELD_PHYSICS_FRAME" value="2" enum="YieldMode"> + Yields during a physics frame. </constant> <constant name="YIELD_WAIT" value="3" enum="YieldMode"> + Yields a function and waits the given time. </constant> </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml b/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml index c59234433f..c6c3188d08 100644 --- a/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml +++ b/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualScriptYieldSignal" inherits="VisualScriptNode" version="4.0"> <brief_description> + A Visual Script node yielding for a signal. </brief_description> <description> + [VisualScriptYieldSignal] will pause the function execution until the provided signal is emitted. </description> <tutorials> </tutorials> @@ -10,20 +12,27 @@ </methods> <members> <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="&"Object""> + The base type to be used when [member call_mode] is set to [constant CALL_MODE_INSTANCE]. </member> <member name="call_mode" type="int" setter="set_call_mode" getter="get_call_mode" enum="VisualScriptYieldSignal.CallMode" default="0"> + [code]call_mode[/code] determines the target object to wait for the signal emission. See [enum CallMode] for options. </member> <member name="node_path" type="NodePath" setter="set_base_path" getter="get_base_path"> + The node path to use when [member call_mode] is set to [constant CALL_MODE_NODE_PATH]. </member> <member name="signal" type="StringName" setter="set_signal" getter="get_signal" default="&"""> + The signal name to be waited for. </member> </members> <constants> <constant name="CALL_MODE_SELF" value="0" enum="CallMode"> + A signal from this [Object] will be used. </constant> <constant name="CALL_MODE_NODE_PATH" value="1" enum="CallMode"> + A signal from the given [Node] in the scene tree will be used. </constant> <constant name="CALL_MODE_INSTANCE" value="2" enum="CallMode"> + A signal from an instanced node with the given type will be used. </constant> </constants> </class> diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index 4c7b66e368..f20ef046a3 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -51,59 +51,59 @@ void register_visual_script_types() { //script_language_gd->init(); ScriptServer::register_language(visual_script_language); - ClassDB::register_class<VisualScript>(); - ClassDB::register_virtual_class<VisualScriptNode>(); - ClassDB::register_class<VisualScriptFunctionState>(); - ClassDB::register_class<VisualScriptFunction>(); - ClassDB::register_virtual_class<VisualScriptLists>(); - ClassDB::register_class<VisualScriptComposeArray>(); - ClassDB::register_class<VisualScriptOperator>(); - ClassDB::register_class<VisualScriptVariableSet>(); - ClassDB::register_class<VisualScriptVariableGet>(); - ClassDB::register_class<VisualScriptConstant>(); - ClassDB::register_class<VisualScriptIndexGet>(); - ClassDB::register_class<VisualScriptIndexSet>(); - ClassDB::register_class<VisualScriptGlobalConstant>(); - ClassDB::register_class<VisualScriptClassConstant>(); - ClassDB::register_class<VisualScriptMathConstant>(); - ClassDB::register_class<VisualScriptBasicTypeConstant>(); - ClassDB::register_class<VisualScriptEngineSingleton>(); - ClassDB::register_class<VisualScriptSceneNode>(); - ClassDB::register_class<VisualScriptSceneTree>(); - ClassDB::register_class<VisualScriptResourcePath>(); - ClassDB::register_class<VisualScriptSelf>(); - ClassDB::register_class<VisualScriptCustomNode>(); - ClassDB::register_class<VisualScriptSubCall>(); - ClassDB::register_class<VisualScriptComment>(); - ClassDB::register_class<VisualScriptConstructor>(); - ClassDB::register_class<VisualScriptLocalVar>(); - ClassDB::register_class<VisualScriptLocalVarSet>(); - ClassDB::register_class<VisualScriptInputAction>(); - ClassDB::register_class<VisualScriptDeconstruct>(); - ClassDB::register_class<VisualScriptPreload>(); - ClassDB::register_class<VisualScriptTypeCast>(); - - ClassDB::register_class<VisualScriptFunctionCall>(); - ClassDB::register_class<VisualScriptPropertySet>(); - ClassDB::register_class<VisualScriptPropertyGet>(); + GDREGISTER_CLASS(VisualScript); + GDREGISTER_VIRTUAL_CLASS(VisualScriptNode); + GDREGISTER_CLASS(VisualScriptFunctionState); + GDREGISTER_CLASS(VisualScriptFunction); + GDREGISTER_VIRTUAL_CLASS(VisualScriptLists); + GDREGISTER_CLASS(VisualScriptComposeArray); + GDREGISTER_CLASS(VisualScriptOperator); + GDREGISTER_CLASS(VisualScriptVariableSet); + GDREGISTER_CLASS(VisualScriptVariableGet); + GDREGISTER_CLASS(VisualScriptConstant); + GDREGISTER_CLASS(VisualScriptIndexGet); + GDREGISTER_CLASS(VisualScriptIndexSet); + GDREGISTER_CLASS(VisualScriptGlobalConstant); + GDREGISTER_CLASS(VisualScriptClassConstant); + GDREGISTER_CLASS(VisualScriptMathConstant); + GDREGISTER_CLASS(VisualScriptBasicTypeConstant); + GDREGISTER_CLASS(VisualScriptEngineSingleton); + GDREGISTER_CLASS(VisualScriptSceneNode); + GDREGISTER_CLASS(VisualScriptSceneTree); + GDREGISTER_CLASS(VisualScriptResourcePath); + GDREGISTER_CLASS(VisualScriptSelf); + GDREGISTER_CLASS(VisualScriptCustomNode); + GDREGISTER_CLASS(VisualScriptSubCall); + GDREGISTER_CLASS(VisualScriptComment); + GDREGISTER_CLASS(VisualScriptConstructor); + GDREGISTER_CLASS(VisualScriptLocalVar); + GDREGISTER_CLASS(VisualScriptLocalVarSet); + GDREGISTER_CLASS(VisualScriptInputAction); + GDREGISTER_CLASS(VisualScriptDeconstruct); + GDREGISTER_CLASS(VisualScriptPreload); + GDREGISTER_CLASS(VisualScriptTypeCast); + + GDREGISTER_CLASS(VisualScriptFunctionCall); + GDREGISTER_CLASS(VisualScriptPropertySet); + GDREGISTER_CLASS(VisualScriptPropertyGet); //ClassDB::register_type<VisualScriptScriptCall>(); - ClassDB::register_class<VisualScriptEmitSignal>(); + GDREGISTER_CLASS(VisualScriptEmitSignal); - ClassDB::register_class<VisualScriptReturn>(); - ClassDB::register_class<VisualScriptCondition>(); - ClassDB::register_class<VisualScriptWhile>(); - ClassDB::register_class<VisualScriptIterator>(); - ClassDB::register_class<VisualScriptSequence>(); - //ClassDB::register_class<VisualScriptInputFilter>(); - ClassDB::register_class<VisualScriptSwitch>(); - ClassDB::register_class<VisualScriptSelect>(); + GDREGISTER_CLASS(VisualScriptReturn); + GDREGISTER_CLASS(VisualScriptCondition); + GDREGISTER_CLASS(VisualScriptWhile); + GDREGISTER_CLASS(VisualScriptIterator); + GDREGISTER_CLASS(VisualScriptSequence); + //GDREGISTER_CLASS(VisualScriptInputFilter); + GDREGISTER_CLASS(VisualScriptSwitch); + GDREGISTER_CLASS(VisualScriptSelect); - ClassDB::register_class<VisualScriptYield>(); - ClassDB::register_class<VisualScriptYieldSignal>(); + GDREGISTER_CLASS(VisualScriptYield); + GDREGISTER_CLASS(VisualScriptYieldSignal); - ClassDB::register_class<VisualScriptBuiltinFunc>(); + GDREGISTER_CLASS(VisualScriptBuiltinFunc); - ClassDB::register_class<VisualScriptExpression>(); + GDREGISTER_CLASS(VisualScriptExpression); register_visual_script_nodes(); register_visual_script_func_nodes(); @@ -114,7 +114,7 @@ void register_visual_script_types() { #ifdef TOOLS_ENABLED ClassDB::set_current_api(ClassDB::API_EDITOR); - ClassDB::register_class<_VisualScriptEditor>(); + GDREGISTER_CLASS(_VisualScriptEditor); ClassDB::set_current_api(ClassDB::API_CORE); vs_editor_singleton = memnew(_VisualScriptEditor); Engine::get_singleton()->add_singleton(Engine::Singleton("VisualScriptEditor", _VisualScriptEditor::get_singleton())); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index d49060bea8..0de39512ae 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -46,7 +46,7 @@ bool VisualScriptNode::is_breakpoint() const { } void VisualScriptNode::ports_changed_notify() { - emit_signal("ports_changed"); + emit_signal(SNAME("ports_changed")); } void VisualScriptNode::set_default_input_value(int p_port, const Variant &p_value) { @@ -264,7 +264,7 @@ void VisualScript::_node_ports_changed(int p_id) { #ifdef TOOLS_ENABLED set_edited(true); // Something changed, let's set as edited. - emit_signal("node_ports_changed", p_id); + emit_signal(SNAME("node_ports_changed"), p_id); #endif } @@ -1025,7 +1025,7 @@ void VisualScript::_set_data(const Dictionary &p_data) { MultiplayerAPI::RPCConfig nd; nd.name = E->get(); nd.rpc_mode = vsf->get_rpc_mode(); - nd.transfer_mode = NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE; // TODO + nd.transfer_mode = MultiplayerPeer::TRANSFER_MODE_RELIABLE; // TODO if (rpc_functions.find(nd) == -1) { rpc_functions.push_back(nd); } diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 8858fe9ff1..ed0583a133 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -62,7 +62,7 @@ protected: void _sig_changed() { notify_property_list_changed(); - emit_signal("changed"); + emit_signal(SNAME("changed")); } bool _set(const StringName &p_name, const Variant &p_value) { @@ -196,10 +196,10 @@ protected: void _var_changed() { notify_property_list_changed(); - emit_signal("changed"); + emit_signal(SNAME("changed")); } void _var_value_changed() { - emit_signal("changed"); + emit_signal(SNAME("changed")); } bool _set(const StringName &p_name, const Variant &p_value) { @@ -611,41 +611,44 @@ void VisualScriptEditor::_update_graph(int p_only_id) { select_func_text->hide(); Ref<Texture2D> type_icons[Variant::VARIANT_MAX] = { - Control::get_theme_icon("Variant", "EditorIcons"), - Control::get_theme_icon("bool", "EditorIcons"), - Control::get_theme_icon("int", "EditorIcons"), - Control::get_theme_icon("float", "EditorIcons"), - Control::get_theme_icon("String", "EditorIcons"), - Control::get_theme_icon("Vector2", "EditorIcons"), - Control::get_theme_icon("Vector2i", "EditorIcons"), - Control::get_theme_icon("Rect2", "EditorIcons"), - Control::get_theme_icon("Rect2i", "EditorIcons"), - Control::get_theme_icon("Vector3", "EditorIcons"), - Control::get_theme_icon("Vector3i", "EditorIcons"), - Control::get_theme_icon("Transform2D", "EditorIcons"), - Control::get_theme_icon("Plane", "EditorIcons"), - Control::get_theme_icon("Quaternion", "EditorIcons"), - Control::get_theme_icon("AABB", "EditorIcons"), - Control::get_theme_icon("Basis", "EditorIcons"), - Control::get_theme_icon("Transform3D", "EditorIcons"), - Control::get_theme_icon("Color", "EditorIcons"), - Control::get_theme_icon("NodePath", "EditorIcons"), - Control::get_theme_icon("RID", "EditorIcons"), - Control::get_theme_icon("MiniObject", "EditorIcons"), - Control::get_theme_icon("Callable", "EditorIcons"), - Control::get_theme_icon("Signal", "EditorIcons"), - Control::get_theme_icon("Dictionary", "EditorIcons"), - Control::get_theme_icon("Array", "EditorIcons"), - Control::get_theme_icon("PackedByteArray", "EditorIcons"), - Control::get_theme_icon("PackedInt32Array", "EditorIcons"), - Control::get_theme_icon("PackedFloat32Array", "EditorIcons"), - Control::get_theme_icon("PackedStringArray", "EditorIcons"), - Control::get_theme_icon("PackedVector2Array", "EditorIcons"), - Control::get_theme_icon("PackedVector3Array", "EditorIcons"), - Control::get_theme_icon("PackedColorArray", "EditorIcons") + Control::get_theme_icon(SNAME("Variant"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("bool"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("int"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("float"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("String"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Vector2i"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Rect2"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Rect2i"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Vector3i"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Transform2D"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Plane"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Quaternion"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("AABB"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Basis"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Transform3D"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Color"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("StringName"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("NodePath"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("RID"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("MiniObject"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Callable"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Signal"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Dictionary"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Array"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedByteArray"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedInt32Array"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedInt64Array"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedFloat32Array"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedFloat64Array"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedStringArray"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedVector2Array"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedVector3Array"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedColorArray"), SNAME("EditorIcons")) }; - Ref<Texture2D> seq_port = Control::get_theme_icon("VisualShaderPort", "EditorIcons"); + Ref<Texture2D> seq_port = Control::get_theme_icon(SNAME("VisualShaderPort"), SNAME("EditorIcons")); List<int> node_ids; script->get_node_list(&node_ids); @@ -711,7 +714,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { LineEdit *line_edit = memnew(LineEdit); line_edit->set_text(node->get_text()); line_edit->set_expand_to_text_length_enabled(true); - line_edit->add_theme_font_override("font", get_theme_font("source", "EditorFonts")); + line_edit->add_theme_font_override("font", get_theme_font(SNAME("source"), SNAME("EditorFonts"))); gnode->add_child(line_edit); line_edit->connect("text_changed", callable_mp(this, &VisualScriptEditor::_expression_text_changed), varray(E->get())); } else { @@ -735,7 +738,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { if (node_styles.has(node->get_category())) { Ref<StyleBoxFlat> sbf = node_styles[node->get_category()]; if (gnode->is_comment()) { - sbf = EditorNode::get_singleton()->get_theme_base()->get_theme()->get_stylebox("comment", "GraphNode"); + sbf = EditorNode::get_singleton()->get_theme_base()->get_theme()->get_stylebox(SNAME("comment"), SNAME("GraphNode")); } Color c = sbf->get_border_color(); @@ -748,7 +751,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { gnode->add_theme_style_override("frame", sbf); } - const Color mono_color = get_theme_color("mono_color", "Editor"); + const Color mono_color = get_theme_color(SNAME("mono_color"), SNAME("Editor")); int slot_idx = 0; @@ -850,7 +853,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } Button *rmbtn = memnew(Button); - rmbtn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Remove", "EditorIcons")); + rmbtn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); hbc->add_child(rmbtn); rmbtn->connect("pressed", callable_mp(this, &VisualScriptEditor::_remove_input_port), varray(E->get(), i), CONNECT_DEFERRED); } else { @@ -906,7 +909,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { if (right_ok) { if (is_vslist) { Button *rmbtn = memnew(Button); - rmbtn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Remove", "EditorIcons")); + rmbtn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); hbc->add_child(rmbtn); rmbtn->connect("pressed", callable_mp(this, &VisualScriptEditor::_remove_output_port), varray(E->get(), i), CONNECT_DEFERRED); @@ -950,7 +953,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { gnode->add_child(vbc); - bool dark_theme = get_theme_constant("dark_theme", "Editor"); + bool dark_theme = get_theme_constant(SNAME("dark_theme"), SNAME("Editor")); if (i < mixed_seq_ports) { gnode->set_slot(slot_idx, left_ok, left_type, _color_from_type(left_type, dark_theme), true, TYPE_SEQUENCE, mono_color, Ref<Texture2D>(), seq_port); } else { @@ -973,7 +976,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { graph->set_minimap_opacity(graph_minimap_opacity); // Use default_func instead of default_func for now I think that should be good stop gap solution to ensure not breaking anything. - graph->call_deferred("set_scroll_ofs", script->get_scroll() * EDSCALE); + graph->call_deferred(SNAME("set_scroll_ofs"), script->get_scroll() * EDSCALE); updating_graph = false; } @@ -1037,9 +1040,9 @@ void VisualScriptEditor::_update_members() { TreeItem *functions = members->create_item(root); functions->set_selectable(0, false); functions->set_text(0, TTR("Functions:")); - functions->add_button(0, Control::get_theme_icon("Override", "EditorIcons"), 1, false, TTR("Override an existing built-in function.")); - functions->add_button(0, Control::get_theme_icon("Add", "EditorIcons"), 0, false, TTR("Create a new function.")); - functions->set_custom_color(0, Control::get_theme_color("mono_color", "Editor")); + functions->add_button(0, Control::get_theme_icon(SNAME("Override"), SNAME("EditorIcons")), 1, false, TTR("Override an existing built-in function.")); + functions->add_button(0, Control::get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), 0, false, TTR("Create a new function.")); + functions->set_custom_color(0, Control::get_theme_color(SNAME("mono_color"), SNAME("Editor"))); List<StringName> func_names; script->get_function_list(&func_names); @@ -1049,7 +1052,7 @@ void VisualScriptEditor::_update_members() { ti->set_text(0, E->get()); ti->set_selectable(0, true); ti->set_metadata(0, E->get()); - ti->add_button(0, Control::get_theme_icon("Edit", "EditorIcons"), 0); + ti->add_button(0, Control::get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), 0); if (selected == E->get()) { ti->select(0); } @@ -1058,42 +1061,42 @@ void VisualScriptEditor::_update_members() { TreeItem *variables = members->create_item(root); variables->set_selectable(0, false); variables->set_text(0, TTR("Variables:")); - variables->add_button(0, Control::get_theme_icon("Add", "EditorIcons"), -1, false, TTR("Create a new variable.")); - variables->set_custom_color(0, Control::get_theme_color("mono_color", "Editor")); + variables->add_button(0, Control::get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), -1, false, TTR("Create a new variable.")); + variables->set_custom_color(0, Control::get_theme_color(SNAME("mono_color"), SNAME("Editor"))); Ref<Texture2D> type_icons[Variant::VARIANT_MAX] = { - Control::get_theme_icon("Variant", "EditorIcons"), - Control::get_theme_icon("bool", "EditorIcons"), - Control::get_theme_icon("int", "EditorIcons"), - Control::get_theme_icon("float", "EditorIcons"), - Control::get_theme_icon("String", "EditorIcons"), - Control::get_theme_icon("Vector2", "EditorIcons"), - Control::get_theme_icon("Vector2i", "EditorIcons"), - Control::get_theme_icon("Rect2", "EditorIcons"), - Control::get_theme_icon("Rect2i", "EditorIcons"), - Control::get_theme_icon("Vector3", "EditorIcons"), - Control::get_theme_icon("Vector3i", "EditorIcons"), - Control::get_theme_icon("Transform2D", "EditorIcons"), - Control::get_theme_icon("Plane", "EditorIcons"), - Control::get_theme_icon("Quaternion", "EditorIcons"), - Control::get_theme_icon("AABB", "EditorIcons"), - Control::get_theme_icon("Basis", "EditorIcons"), - Control::get_theme_icon("Transform3D", "EditorIcons"), - Control::get_theme_icon("Color", "EditorIcons"), - Control::get_theme_icon("NodePath", "EditorIcons"), - Control::get_theme_icon("RID", "EditorIcons"), - Control::get_theme_icon("MiniObject", "EditorIcons"), - Control::get_theme_icon("Callable", "EditorIcons"), - Control::get_theme_icon("Signal", "EditorIcons"), - Control::get_theme_icon("Dictionary", "EditorIcons"), - Control::get_theme_icon("Array", "EditorIcons"), - Control::get_theme_icon("PackedByteArray", "EditorIcons"), - Control::get_theme_icon("PackedInt32Array", "EditorIcons"), - Control::get_theme_icon("PackedFloat32Array", "EditorIcons"), - Control::get_theme_icon("PackedStringArray", "EditorIcons"), - Control::get_theme_icon("PackedVector2Array", "EditorIcons"), - Control::get_theme_icon("PackedVector3Array", "EditorIcons"), - Control::get_theme_icon("PackedColorArray", "EditorIcons") + Control::get_theme_icon(SNAME("Variant"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("bool"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("int"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("float"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("String"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Vector2i"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Rect2"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Rect2i"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Vector3i"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Transform2D"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Plane"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Quaternion"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("AABB"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Basis"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Transform3D"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Color"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("NodePath"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("RID"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("MiniObject"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Callable"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Signal"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Dictionary"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("Array"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedByteArray"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedInt32Array"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedFloat32Array"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedStringArray"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedVector2Array"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedVector3Array"), SNAME("EditorIcons")), + Control::get_theme_icon(SNAME("PackedColorArray"), SNAME("EditorIcons")) }; List<StringName> var_names; @@ -1117,8 +1120,8 @@ void VisualScriptEditor::_update_members() { TreeItem *_signals = members->create_item(root); _signals->set_selectable(0, false); _signals->set_text(0, TTR("Signals:")); - _signals->add_button(0, Control::get_theme_icon("Add", "EditorIcons"), -1, false, TTR("Create a new signal.")); - _signals->set_custom_color(0, Control::get_theme_color("mono_color", "Editor")); + _signals->add_button(0, Control::get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), -1, false, TTR("Create a new signal.")); + _signals->set_custom_color(0, Control::get_theme_color(SNAME("mono_color"), SNAME("Editor"))); List<StringName> signal_names; script->get_custom_signal_list(&signal_names); @@ -1135,12 +1138,12 @@ void VisualScriptEditor::_update_members() { String base_type = script->get_instance_base_type(); String icon_type = base_type; - if (!Control::has_theme_icon(base_type, "EditorIcons")) { + if (!Control::has_theme_icon(base_type, SNAME("EditorIcons"))) { icon_type = "Object"; } base_type_select->set_text(base_type); - base_type_select->set_icon(Control::get_theme_icon(icon_type, "EditorIcons")); + base_type_select->set_icon(Control::get_theme_icon(icon_type, SNAME("EditorIcons"))); updating_members = false; } @@ -1366,7 +1369,7 @@ void VisualScriptEditor::_add_func_input() { hbox->add_child(type_box); Button *delete_button = memnew(Button); - delete_button->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Remove", "EditorIcons")); + delete_button->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); delete_button->set_tooltip(vformat(TTR("Delete input port"))); hbox->add_child(delete_button); @@ -1428,7 +1431,7 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt undo_redo->add_do_method(script.ptr(), "add_function", name, fn_id); undo_redo->add_do_method(script.ptr(), "add_node", fn_id, func_node, pos); undo_redo->add_undo_method(script.ptr(), "remove_function", name); - undo_redo->add_do_method(script.ptr(), "remove_node", fn_id); + undo_redo->add_undo_method(script.ptr(), "remove_node", fn_id); undo_redo->add_do_method(this, "_update_members"); undo_redo->add_undo_method(this, "_update_members"); undo_redo->add_do_method(this, "_update_graph"); @@ -2172,6 +2175,11 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "files") { +#ifdef OSX_ENABLED + bool use_preload = Input::get_singleton()->is_key_pressed(KEY_META); +#else + bool use_preload = Input::get_singleton()->is_key_pressed(KEY_CTRL); +#endif Vector2 pos = _get_pos_in_graph(p_point); Array files = d["files"]; @@ -2187,13 +2195,22 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da if (!res.is_valid()) { continue; } + Ref<Script> drop_script = ResourceLoader::load(files[i]); + if (drop_script.is_valid() && drop_script->is_tool() && drop_script->get_instance_base_type() == "VisualScriptCustomNode" && !use_preload) { + Ref<VisualScriptCustomNode> vscn; + vscn.instantiate(); + vscn->set_script(drop_script); + + undo_redo->add_do_method(script.ptr(), "add_node", new_id, vscn, pos); + undo_redo->add_undo_method(script.ptr(), "remove_node", new_id); + } else { + Ref<VisualScriptPreload> prnode; + prnode.instantiate(); + prnode->set_preload(res); - Ref<VisualScriptPreload> prnode; - prnode.instantiate(); - prnode->set_preload(res); - - undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, pos); - undo_redo->add_undo_method(script.ptr(), "remove_node", new_id); + undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, pos); + undo_redo->add_undo_method(script.ptr(), "remove_node", new_id); + } new_ids.push_back(new_id); new_id++; pos += Vector2(20, 20); @@ -2387,7 +2404,7 @@ void VisualScriptEditor::_draw_color_over_button(Object *obj, Color p_color) { return; } - Ref<StyleBox> normal = get_theme_stylebox("normal", "Button"); + Ref<StyleBox> normal = get_theme_stylebox(SNAME("normal"), SNAME("Button")); button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color); } @@ -2433,7 +2450,7 @@ void VisualScriptEditor::set_edited_resource(const RES &p_res) { script->connect("node_ports_changed", callable_mp(this, &VisualScriptEditor::_node_ports_changed)); _update_graph(); - call_deferred("_update_members"); + call_deferred(SNAME("_update_members")); } void VisualScriptEditor::enable_editor() { @@ -2467,7 +2484,7 @@ String VisualScriptEditor::get_name() { } Ref<Texture2D> VisualScriptEditor::get_theme_icon() { - return Control::get_theme_icon("VisualScript", "EditorIcons"); + return Control::get_theme_icon(SNAME("VisualScript"), SNAME("EditorIcons")); } bool VisualScriptEditor::is_unsaved() { @@ -2542,7 +2559,7 @@ void VisualScriptEditor::goto_line(int p_line, bool p_with_error) { _update_graph(); _update_members(); - call_deferred("call_deferred", "_center_on_node", E->get(), p_line); //editor might be just created and size might not exist yet + call_deferred(SNAME("call_deferred"), "_center_on_node", E->get(), p_line); //editor might be just created and size might not exist yet return; } } @@ -2822,6 +2839,20 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, ERR_FAIL_COND(from_seq != to_seq); + // Checking to prevent warnings. + if (from_seq) { + if (script->has_sequence_connection(p_from.to_int(), from_port, p_to.to_int())) { + return; + } + } else if (script->has_data_connection(p_from.to_int(), from_port, p_to.to_int(), to_port)) { + return; + } + + // Preventing connection to itself. + if (p_from.to_int() == p_to.to_int()) { + return; + } + // Do all the checks here. StringName func; // This the func where we store the one the nodes at the end of the resolution on having multiple nodes. @@ -2975,7 +3006,7 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac Ref<VisualScriptNode> node = script->get_node(p_port_action_node); - if (!node.is_valid()) { + if (!node.is_valid() || node->get_output_value_port_count() <= p_port_action_output) { return tg; } @@ -3582,9 +3613,9 @@ void VisualScriptEditor::_notification(int p_what) { return; } - edit_variable_edit->add_theme_style_override("bg", get_theme_stylebox("bg", "Tree")); - edit_signal_edit->add_theme_style_override("bg", get_theme_stylebox("bg", "Tree")); - func_input_scroll->add_theme_style_override("bg", get_theme_stylebox("bg", "Tree")); + edit_variable_edit->add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); + edit_signal_edit->add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); + func_input_scroll->add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); Ref<Theme> tm = EditorNode::get_singleton()->get_theme_base()->get_theme(); @@ -3607,7 +3638,7 @@ void VisualScriptEditor::_notification(int p_what) { } for (Map<StringName, Color>::Element *E = node_colors.front(); E; E = E->next()) { - const Ref<StyleBoxFlat> sb = tm->get_stylebox("frame", "GraphNode"); + const Ref<StyleBoxFlat> sb = tm->get_stylebox(SNAME("frame"), SNAME("GraphNode")); if (!sb.is_null()) { Ref<StyleBoxFlat> frame_style = sb->duplicate(); @@ -4087,9 +4118,9 @@ void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) { TreeItem *root = members->get_root(); - Ref<Texture2D> del_icon = Control::get_theme_icon("Remove", "EditorIcons"); + Ref<Texture2D> del_icon = Control::get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")); - Ref<Texture2D> edit_icon = Control::get_theme_icon("Edit", "EditorIcons"); + Ref<Texture2D> edit_icon = Control::get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")); if (ti->get_parent() == root->get_first_child()) { member_type = MEMBER_FUNCTION; @@ -4258,7 +4289,7 @@ VisualScriptEditor::VisualScriptEditor() { members_section = memnew(VBoxContainer); // Add but wait until done setting up this. - ScriptEditor::get_singleton()->get_left_list_split()->call_deferred("add_child", members_section); + ScriptEditor::get_singleton()->get_left_list_split()->call_deferred(SNAME("add_child"), members_section); members_section->set_v_size_flags(SIZE_EXPAND_FILL); CheckButton *tool_script_check = memnew(CheckButton); @@ -4519,14 +4550,14 @@ void _VisualScriptEditor::add_custom_node(const String &p_name, const String &p_ String node_name = "custom/" + p_category + "/" + p_name; custom_nodes.insert(node_name, p_script); VisualScriptLanguage::singleton->add_register_func(node_name, &_VisualScriptEditor::create_node_custom); - emit_signal("custom_nodes_updated"); + emit_signal(SNAME("custom_nodes_updated")); } void _VisualScriptEditor::remove_custom_node(const String &p_name, const String &p_category) { String node_name = "custom/" + p_category + "/" + p_name; custom_nodes.erase(node_name); VisualScriptLanguage::singleton->remove_register_func(node_name); - emit_signal("custom_nodes_updated"); + emit_signal(SNAME("custom_nodes_updated")); } void _VisualScriptEditor::_bind_methods() { diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 98383800ba..7b5ca56dcc 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -520,19 +520,19 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (property.name == "base_script") { if (call_mode != CALL_MODE_INSTANCE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } if (property.name == "basic_type") { if (call_mode != CALL_MODE_BASIC_TYPE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } if (property.name == "singleton") { if (call_mode != CALL_MODE_SINGLETON) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } else { List<Engine::Singleton> names; Engine::get_singleton()->get_singletons(&names); @@ -550,7 +550,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (property.name == "node_path") { if (call_mode != CALL_MODE_NODE_PATH) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } else { Node *bnode = _get_base_node(); if (bnode) { @@ -621,7 +621,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } if (mc == 0) { - property.usage = 0; //do not show + property.usage = PROPERTY_USAGE_NONE; //do not show } else { property.hint_string = "0," + itos(mc) + ",1"; } @@ -629,7 +629,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (property.name == "rpc_call_mode") { if (call_mode == CALL_MODE_BASIC_TYPE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } } @@ -1288,19 +1288,19 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { if (property.name == "base_script") { if (call_mode != CALL_MODE_INSTANCE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } if (property.name == "basic_type") { if (call_mode != CALL_MODE_BASIC_TYPE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } if (property.name == "node_path") { if (call_mode != CALL_MODE_NODE_PATH) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } else { Node *bnode = _get_base_node(); if (bnode) { @@ -1362,7 +1362,7 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { property.hint_string = options; property.type = Variant::STRING; if (options == "") { - property.usage = 0; //hide if type has no usable index + property.usage = PROPERTY_USAGE_NONE; //hide if type has no usable index } } } @@ -1994,19 +1994,19 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { if (property.name == "base_script") { if (call_mode != CALL_MODE_INSTANCE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } if (property.name == "basic_type") { if (call_mode != CALL_MODE_BASIC_TYPE) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } if (property.name == "node_path") { if (call_mode != CALL_MODE_NODE_PATH) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } else { Node *bnode = _get_base_node(); if (bnode) { @@ -2067,7 +2067,7 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { property.hint_string = options; property.type = Variant::STRING; if (options == "") { - property.usage = 0; //hide if type has no usable index + property.usage = PROPERTY_USAGE_NONE; //hide if type has no usable index } } } diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 60392d8f42..2a46051ccf 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -191,7 +191,10 @@ PropertyInfo VisualScriptFunction::get_input_value_port_info(int p_idx) const { } PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, arguments.size(), PropertyInfo()); + // Need to check it without ERR_FAIL_COND, to prevent warnings from appearing on node creation via dragging. + if (p_idx < 0 || p_idx >= arguments.size()) { + return PropertyInfo(); + } PropertyInfo out; out.type = arguments[p_idx].type; out.name = arguments[p_idx].name; @@ -912,39 +915,6 @@ PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const { return pinfo; } -static const char *op_names[] = { - //comparison - "Are Equal", //OP_EQUAL, - "Are Not Equal", //OP_NOT_EQUAL, - "Less Than", //OP_LESS, - "Less Than or Equal", //OP_LESS_EQUAL, - "Greater Than", //OP_GREATER, - "Greater Than or Equal", //OP_GREATER_EQUAL, - //mathematic - "Add", //OP_ADD, - "Subtract", //OP_SUBTRACT, - "Multiply", //OP_MULTIPLY, - "Divide", //OP_DIVIDE, - "Negate", //OP_NEGATE, - "Positive", //OP_POSITIVE, - "Remainder", //OP_MODULE, - "Concatenate", //OP_STRING_CONCAT, - //bitwise - "Bit Shift Left", //OP_SHIFT_LEFT, - "Bit Shift Right", //OP_SHIFT_RIGHT, - "Bit And", //OP_BIT_AND, - "Bit Or", //OP_BIT_OR, - "Bit Xor", //OP_BIT_XOR, - "Bit Negate", //OP_BIT_NEGATE, - //logic - "And", //OP_AND, - "Or", //OP_OR, - "Xor", //OP_XOR, - "Not", //OP_NOT, - //containment - "In", //OP_IN, -}; - String VisualScriptOperator::get_caption() const { switch (op) { // comparison @@ -1011,6 +981,71 @@ String VisualScriptOperator::get_caption() const { } } +String VisualScriptOperator::get_operator_name(Variant::Operator p_op) { + switch (p_op) { + // comparison + case Variant::OP_EQUAL: + return "Are Equal"; + case Variant::OP_NOT_EQUAL: + return "Are Not Equal"; + case Variant::OP_LESS: + return "Less Than"; + case Variant::OP_LESS_EQUAL: + return "Less Than or Equal"; + case Variant::OP_GREATER: + return "Greater Than"; + case Variant::OP_GREATER_EQUAL: + return "Greater Than or Equal"; + + // mathematic + case Variant::OP_ADD: + return "Add"; + case Variant::OP_SUBTRACT: + return "Subtract"; + case Variant::OP_MULTIPLY: + return "Multiply"; + case Variant::OP_DIVIDE: + return "Divide"; + case Variant::OP_NEGATE: + return "Negate"; + case Variant::OP_POSITIVE: + return "Positive"; + case Variant::OP_MODULE: + return "Remainder"; + + // bitwise + case Variant::OP_SHIFT_LEFT: + return "Bit Shift Left"; + case Variant::OP_SHIFT_RIGHT: + return "Bit Shift Right"; + case Variant::OP_BIT_AND: + return "Bit And"; + case Variant::OP_BIT_OR: + return "Bit Or"; + case Variant::OP_BIT_XOR: + return "Bit Xor"; + case Variant::OP_BIT_NEGATE: + return "Bit Negate"; + + // logic + case Variant::OP_AND: + return "And"; + case Variant::OP_OR: + return "Or"; + case Variant::OP_XOR: + return "Xor"; + case Variant::OP_NOT: + return "Not"; + case Variant::OP_IN: + return "In"; + + default: { + ERR_FAIL_INDEX_V(p_op, Variant::OP_MAX, ""); + return "Unknown Operator"; + } + } +} + void VisualScriptOperator::set_operator(Variant::Operator p_op) { if (op == p_op) { return; @@ -1048,7 +1083,7 @@ void VisualScriptOperator::_bind_methods() { if (i > 0) { types += ","; } - types += op_names[i]; + types += get_operator_name(static_cast<Variant::Operator>(i)); } String argt = "Any"; @@ -1081,9 +1116,9 @@ public: r_error_str = *p_outputs[0]; } else { if (unary) { - r_error_str = String(op_names[op]) + RTR(": Invalid argument of type: ") + Variant::get_type_name(p_inputs[0]->get_type()); + r_error_str = String(Variant::get_operator_name(op)) + RTR(": Invalid argument of type: ") + Variant::get_type_name(p_inputs[0]->get_type()); } else { - r_error_str = String(op_names[op]) + RTR(": Invalid arguments: ") + "A: " + Variant::get_type_name(p_inputs[0]->get_type()) + " B: " + Variant::get_type_name(p_inputs[1]->get_type()); + r_error_str = String(Variant::get_operator_name(op)) + RTR(": Invalid arguments: ") + "A: " + Variant::get_type_name(p_inputs[0]->get_type()) + " B: " + Variant::get_type_name(p_inputs[1]->get_type()); } } } @@ -1502,7 +1537,7 @@ void VisualScriptConstant::_validate_property(PropertyInfo &property) const { if (property.name == "value") { property.type = type; if (type == Variant::NIL) { - property.usage = 0; //do not save if nil + property.usage = PROPERTY_USAGE_NONE; //do not save if nil } } } @@ -2092,7 +2127,7 @@ void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo &property) c Variant::get_constants_for_type(type, &constants); if (constants.size() == 0) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; return; } property.hint_string = ""; @@ -2955,7 +2990,7 @@ VisualScriptNodeInstance *VisualScriptCustomNode::instantiate(VisualScriptInstan } void VisualScriptCustomNode::_script_changed() { - call_deferred("ports_changed_notify"); + call_deferred(SNAME("ports_changed_notify")); } void VisualScriptCustomNode::_bind_methods() { diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index 551832b002..b599b92b3a 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -227,6 +227,8 @@ public: void set_typed(Variant::Type p_op); Variant::Type get_typed() const; + static String get_operator_name(Variant::Operator p_op); + virtual VisualScriptNodeInstance *instantiate(VisualScriptInstance *p_instance) override; VisualScriptOperator(); diff --git a/modules/visual_script/visual_script_property_selector.cpp b/modules/visual_script/visual_script_property_selector.cpp index 79addc5828..ccb2e2df75 100644 --- a/modules/visual_script/visual_script_property_selector.cpp +++ b/modules/visual_script/visual_script_property_selector.cpp @@ -98,35 +98,41 @@ void VisualScriptPropertySelector::_update_search() { List<PropertyInfo> props; TreeItem *category = nullptr; Ref<Texture2D> type_icons[Variant::VARIANT_MAX] = { - vbc->get_theme_icon("Variant", "EditorIcons"), - vbc->get_theme_icon("bool", "EditorIcons"), - vbc->get_theme_icon("int", "EditorIcons"), - vbc->get_theme_icon("float", "EditorIcons"), - vbc->get_theme_icon("String", "EditorIcons"), - vbc->get_theme_icon("Vector2", "EditorIcons"), - vbc->get_theme_icon("Rect2", "EditorIcons"), - vbc->get_theme_icon("Vector3", "EditorIcons"), - vbc->get_theme_icon("Transform2D", "EditorIcons"), - vbc->get_theme_icon("Plane", "EditorIcons"), - vbc->get_theme_icon("Quaternion", "EditorIcons"), - vbc->get_theme_icon("AABB", "EditorIcons"), - vbc->get_theme_icon("Basis", "EditorIcons"), - vbc->get_theme_icon("Transform3D", "EditorIcons"), - vbc->get_theme_icon("Color", "EditorIcons"), - vbc->get_theme_icon("Path", "EditorIcons"), - vbc->get_theme_icon("RID", "EditorIcons"), - vbc->get_theme_icon("Object", "EditorIcons"), - vbc->get_theme_icon("Dictionary", "EditorIcons"), - vbc->get_theme_icon("Array", "EditorIcons"), - vbc->get_theme_icon("PackedByteArray", "EditorIcons"), - vbc->get_theme_icon("PackedInt32Array", "EditorIcons"), - vbc->get_theme_icon("PackedFloat32Array", "EditorIcons"), - vbc->get_theme_icon("PackedInt64Array", "EditorIcons"), - vbc->get_theme_icon("PackedFloat64Array", "EditorIcons"), - vbc->get_theme_icon("PackedStringArray", "EditorIcons"), - vbc->get_theme_icon("PackedVector2Array", "EditorIcons"), - vbc->get_theme_icon("PackedVector3Array", "EditorIcons"), - vbc->get_theme_icon("PackedColorArray", "EditorIcons") + vbc->get_theme_icon(SNAME("Variant"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("bool"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("int"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("float"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("String"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Vector2i"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Rect2"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Rect2i"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Vector3i"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Transform2D"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Plane"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Quaternion"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("AABB"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Basis"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Transform3D"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Color"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("StringName"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("NodePath"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("RID"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("MiniObject"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Callable"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Signal"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Dictionary"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("Array"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("PackedByteArray"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("PackedInt32Array"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("PackedInt64Array"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("PackedFloat32Array"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("PackedFloat64Array"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("PackedStringArray"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("PackedVector2Array"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("PackedVector3Array"), SNAME("EditorIcons")), + vbc->get_theme_icon(SNAME("PackedColorArray"), SNAME("EditorIcons")) }; { String b = String(E->get()); @@ -253,7 +259,7 @@ void VisualScriptPropertySelector::_update_search() { TreeItem *item = search_options->create_item(category ? category : root); item->set_text(0, desc); - item->set_icon(0, vbc->get_theme_icon("MemberMethod", "EditorIcons")); + item->set_icon(0, vbc->get_theme_icon(SNAME("MemberMethod"), SNAME("EditorIcons"))); item->set_metadata(0, name); item->set_selectable(0, true); @@ -317,7 +323,7 @@ void VisualScriptPropertySelector::create_visualscript_item(const String &name, if (search_input == String() || text.findn(search_input) != -1) { TreeItem *item = search_options->create_item(root); item->set_text(0, text); - item->set_icon(0, vbc->get_theme_icon("VisualScript", "EditorIcons")); + item->set_icon(0, vbc->get_theme_icon(SNAME("VisualScript"), SNAME("EditorIcons"))); item->set_metadata(0, name); item->set_metadata(1, "action"); item->set_selectable(0, true); @@ -401,7 +407,7 @@ void VisualScriptPropertySelector::get_visual_node_names(const String &root_filt } item->set_text(0, type_name + String("").join(desc)); - item->set_icon(0, vbc->get_theme_icon("VisualScript", "EditorIcons")); + item->set_icon(0, vbc->get_theme_icon(SNAME("VisualScript"), SNAME("EditorIcons"))); item->set_selectable(0, true); item->set_metadata(0, E->get()); item->set_selectable(0, true); @@ -417,7 +423,7 @@ void VisualScriptPropertySelector::_confirmed() { if (!ti) { return; } - emit_signal("selected", ti->get_metadata(0), ti->get_metadata(1), ti->get_metadata(2)); + emit_signal(SNAME("selected"), ti->get_metadata(0), ti->get_metadata(1), ti->get_metadata(2)); set_visible(false); } diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index 2e1b0a3e99..d8bc926a1d 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -174,7 +174,7 @@ float VisualScriptYield::get_wait_time() { void VisualScriptYield::_validate_property(PropertyInfo &property) const { if (property.name == "wait_time") { if (yield_mode != YIELD_WAIT) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } } } @@ -421,7 +421,7 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { if (property.name == "node_path") { if (call_mode != CALL_MODE_NODE_PATH) { - property.usage = 0; + property.usage = PROPERTY_USAGE_NONE; } else { Node *bnode = _get_base_node(); if (bnode) { diff --git a/modules/webm/register_types.cpp b/modules/webm/register_types.cpp index 9cfaba83c1..8f690a6892 100644 --- a/modules/webm/register_types.cpp +++ b/modules/webm/register_types.cpp @@ -38,7 +38,7 @@ void register_webm_types() { resource_loader_webm.instantiate(); ResourceLoader::add_resource_format_loader(resource_loader_webm, true); - ClassDB::register_class<VideoStreamWebm>(); + GDREGISTER_CLASS(VideoStreamWebm); } void unregister_webm_types() { diff --git a/modules/webrtc/config.py b/modules/webrtc/config.py index 0a075ccef1..3281415f38 100644 --- a/modules/webrtc/config.py +++ b/modules/webrtc/config.py @@ -10,7 +10,7 @@ def get_doc_classes(): return [ "WebRTCPeerConnection", "WebRTCDataChannel", - "WebRTCMultiplayer", + "WebRTCMultiplayerPeer", ] diff --git a/modules/webrtc/doc_classes/WebRTCDataChannel.xml b/modules/webrtc/doc_classes/WebRTCDataChannel.xml index 5c90038b9a..3435dda982 100644 --- a/modules/webrtc/doc_classes/WebRTCDataChannel.xml +++ b/modules/webrtc/doc_classes/WebRTCDataChannel.xml @@ -14,6 +14,13 @@ Closes this data channel, notifying the other peer. </description> </method> + <method name="get_buffered_amount" qualifiers="const"> + <return type="int"> + </return> + <description> + Returns the number of bytes currently queued to be sent over this channel. + </description> + </method> <method name="get_id" qualifiers="const"> <return type="int"> </return> diff --git a/modules/webrtc/doc_classes/WebRTCMultiplayer.xml b/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml index 5b9459bc27..26c5bfa6ce 100644 --- a/modules/webrtc/doc_classes/WebRTCMultiplayer.xml +++ b/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml @@ -1,12 +1,12 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="WebRTCMultiplayer" inherits="NetworkedMultiplayerPeer" version="4.0"> +<class name="WebRTCMultiplayerPeer" inherits="MultiplayerPeer" version="4.0"> <brief_description> A simple interface to create a peer-to-peer mesh network composed of [WebRTCPeerConnection] that is compatible with the [MultiplayerAPI]. </brief_description> <description> This class constructs a full mesh of [WebRTCPeerConnection] (one connection for each peer) that can be used as a [member MultiplayerAPI.network_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 NetworkedMultiplayerPeer.connection_succeeded] and [signal NetworkedMultiplayerPeer.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 [NetworkedMultiplayerPeer]. + [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]. </description> <tutorials> </tutorials> @@ -66,8 +66,8 @@ </argument> <description> Initialize the multiplayer peer with the given [code]peer_id[/code] (must be between 1 and 2147483647). - If [code]server_compatibilty[/code] is [code]false[/code] (default), the multiplayer peer will be immediately in state [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTED] and [signal NetworkedMultiplayerPeer.connection_succeeded] will not be emitted. - If [code]server_compatibilty[/code] is [code]true[/code] the peer will suppress all [signal NetworkedMultiplayerPeer.peer_connected] signals until a peer with id [constant NetworkedMultiplayerPeer.TARGET_PEER_SERVER] connects and then emit [signal NetworkedMultiplayerPeer.connection_succeeded]. After that the signal [signal NetworkedMultiplayerPeer.peer_connected] will be emitted for every already connected peer, and any new peer that might connect. If the server peer disconnects after that, signal [signal NetworkedMultiplayerPeer.server_disconnected] will be emitted and state will become [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTED]. + If [code]server_compatibilty[/code] is [code]false[/code] (default), the multiplayer peer will be immediately in state [constant MultiplayerPeer.CONNECTION_CONNECTED] and [signal MultiplayerPeer.connection_succeeded] will not be emitted. + If [code]server_compatibilty[/code] is [code]true[/code] the peer will suppress all [signal MultiplayerPeer.peer_connected] signals until a peer with id [constant MultiplayerPeer.TARGET_PEER_SERVER] connects and then emit [signal MultiplayerPeer.connection_succeeded]. After that the signal [signal MultiplayerPeer.peer_connected] will be emitted for every already connected peer, and any new peer that might connect. If the server peer disconnects after that, signal [signal MultiplayerPeer.server_disconnected] will be emitted and state will become [constant MultiplayerPeer.CONNECTION_CONNECTED]. </description> </method> <method name="remove_peer"> @@ -76,13 +76,13 @@ <argument index="0" name="peer_id" type="int"> </argument> <description> - Remove the peer with given [code]peer_id[/code] from the mesh. If the peer was connected, and [signal NetworkedMultiplayerPeer.peer_connected] was emitted for it, then [signal NetworkedMultiplayerPeer.peer_disconnected] will be emitted. + Remove the peer with given [code]peer_id[/code] from the mesh. If the peer was connected, and [signal MultiplayerPeer.peer_connected] was emitted for it, then [signal MultiplayerPeer.peer_disconnected] will be emitted. </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="NetworkedMultiplayerPeer.TransferMode" default="2" /> + <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="MultiplayerPeer.TransferMode" default="2" /> </members> <constants> </constants> diff --git a/modules/webrtc/library_godot_webrtc.js b/modules/webrtc/library_godot_webrtc.js index 404a116716..a0a6c21be3 100644 --- a/modules/webrtc/library_godot_webrtc.js +++ b/modules/webrtc/library_godot_webrtc.js @@ -133,12 +133,12 @@ const GodotRTCDataChannel = { godot_js_rtc_datachannel_is_ordered__sig: 'ii', godot_js_rtc_datachannel_is_ordered: function (p_id) { - return IDHandler.get_prop(p_id, 'ordered', true); + return GodotRTCDataChannel.get_prop(p_id, 'ordered', true); }, godot_js_rtc_datachannel_id_get__sig: 'ii', godot_js_rtc_datachannel_id_get: function (p_id) { - return IDHandler.get_prop(p_id, 'id', 65535); + return GodotRTCDataChannel.get_prop(p_id, 'id', 65535); }, godot_js_rtc_datachannel_max_packet_lifetime_get__sig: 'ii', @@ -158,12 +158,17 @@ const GodotRTCDataChannel = { godot_js_rtc_datachannel_max_retransmits_get__sig: 'ii', godot_js_rtc_datachannel_max_retransmits_get: function (p_id) { - return IDHandler.get_prop(p_id, 'maxRetransmits', 65535); + return GodotRTCDataChannel.get_prop(p_id, 'maxRetransmits', 65535); }, godot_js_rtc_datachannel_is_negotiated__sig: 'ii', godot_js_rtc_datachannel_is_negotiated: function (p_id) { - return IDHandler.get_prop(p_id, 'negotiated', 65535); + return GodotRTCDataChannel.get_prop(p_id, 'negotiated', 65535); + }, + + godot_js_rtc_datachannel_get_buffered_amount__sig: 'ii', + godot_js_rtc_datachannel_get_buffered_amount: function (p_id) { + return GodotRTCDataChannel.get_prop(p_id, 'bufferedAmount', 0); }, godot_js_rtc_datachannel_label_get__sig: 'ii', diff --git a/modules/webrtc/register_types.cpp b/modules/webrtc/register_types.cpp index ecfaed9089..63ecc03a4c 100644 --- a/modules/webrtc/register_types.cpp +++ b/modules/webrtc/register_types.cpp @@ -41,7 +41,7 @@ #include "webrtc_data_channel_gdnative.h" #include "webrtc_peer_connection_gdnative.h" #endif -#include "webrtc_multiplayer.h" +#include "webrtc_multiplayer_peer.h" void register_webrtc_types() { #define _SET_HINT(NAME, _VAL_, _MAX_) \ @@ -58,11 +58,11 @@ void register_webrtc_types() { ClassDB::register_custom_instance_class<WebRTCPeerConnection>(); #ifdef WEBRTC_GDNATIVE_ENABLED - ClassDB::register_class<WebRTCPeerConnectionGDNative>(); - ClassDB::register_class<WebRTCDataChannelGDNative>(); + GDREGISTER_CLASS(WebRTCPeerConnectionGDNative); + GDREGISTER_CLASS(WebRTCDataChannelGDNative); #endif - ClassDB::register_virtual_class<WebRTCDataChannel>(); - ClassDB::register_class<WebRTCMultiplayer>(); + GDREGISTER_VIRTUAL_CLASS(WebRTCDataChannel); + GDREGISTER_CLASS(WebRTCMultiplayerPeer); } void unregister_webrtc_types() {} diff --git a/modules/webrtc/webrtc_data_channel.cpp b/modules/webrtc/webrtc_data_channel.cpp index 004112f992..ca520a733d 100644 --- a/modules/webrtc/webrtc_data_channel.cpp +++ b/modules/webrtc/webrtc_data_channel.cpp @@ -46,6 +46,7 @@ void WebRTCDataChannel::_bind_methods() { ClassDB::bind_method(D_METHOD("get_max_retransmits"), &WebRTCDataChannel::get_max_retransmits); ClassDB::bind_method(D_METHOD("get_protocol"), &WebRTCDataChannel::get_protocol); ClassDB::bind_method(D_METHOD("is_negotiated"), &WebRTCDataChannel::is_negotiated); + ClassDB::bind_method(D_METHOD("get_buffered_amount"), &WebRTCDataChannel::get_buffered_amount); ADD_PROPERTY(PropertyInfo(Variant::INT, "write_mode", PROPERTY_HINT_ENUM), "set_write_mode", "get_write_mode"); diff --git a/modules/webrtc/webrtc_data_channel.h b/modules/webrtc/webrtc_data_channel.h index 20affc513f..809d35c6e3 100644 --- a/modules/webrtc/webrtc_data_channel.h +++ b/modules/webrtc/webrtc_data_channel.h @@ -70,6 +70,8 @@ public: virtual String get_protocol() const = 0; virtual bool is_negotiated() const = 0; + virtual int get_buffered_amount() const = 0; + virtual Error poll() = 0; virtual void close() = 0; diff --git a/modules/webrtc/webrtc_data_channel_gdnative.cpp b/modules/webrtc/webrtc_data_channel_gdnative.cpp index d4cf464c7c..10a3367557 100644 --- a/modules/webrtc/webrtc_data_channel_gdnative.cpp +++ b/modules/webrtc/webrtc_data_channel_gdnative.cpp @@ -31,6 +31,7 @@ #ifdef WEBRTC_GDNATIVE_ENABLED #include "webrtc_data_channel_gdnative.h" + #include "core/io/resource_loader.h" #include "modules/gdnative/nativescript/nativescript.h" @@ -110,6 +111,11 @@ bool WebRTCDataChannelGDNative::is_negotiated() const { 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); diff --git a/modules/webrtc/webrtc_data_channel_gdnative.h b/modules/webrtc/webrtc_data_channel_gdnative.h index 7e02a32046..5c80edd48c 100644 --- a/modules/webrtc/webrtc_data_channel_gdnative.h +++ b/modules/webrtc/webrtc_data_channel_gdnative.h @@ -60,6 +60,7 @@ public: virtual int get_max_retransmits() const override; virtual String get_protocol() const override; virtual bool is_negotiated() const override; + virtual int get_buffered_amount() const override; virtual Error poll() override; virtual void close() override; diff --git a/modules/webrtc/webrtc_data_channel_js.cpp b/modules/webrtc/webrtc_data_channel_js.cpp index dfbec80c86..31d6a0568c 100644 --- a/modules/webrtc/webrtc_data_channel_js.cpp +++ b/modules/webrtc/webrtc_data_channel_js.cpp @@ -46,6 +46,7 @@ extern int godot_js_rtc_datachannel_id_get(int p_id); extern int godot_js_rtc_datachannel_max_packet_lifetime_get(int p_id); extern int godot_js_rtc_datachannel_max_retransmits_get(int p_id); extern int godot_js_rtc_datachannel_is_negotiated(int p_id); +extern int godot_js_rtc_datachannel_get_buffered_amount(int p_id); extern char *godot_js_rtc_datachannel_label_get(int p_id); // Must free the returned string. extern char *godot_js_rtc_datachannel_protocol_get(int p_id); // Must free the returned string. extern void godot_js_rtc_datachannel_destroy(int p_id); @@ -181,6 +182,10 @@ bool WebRTCDataChannelJS::is_negotiated() const { return godot_js_rtc_datachannel_is_negotiated(_js_id); } +int WebRTCDataChannelJS::get_buffered_amount() const { + return godot_js_rtc_datachannel_get_buffered_amount(_js_id); +} + WebRTCDataChannelJS::WebRTCDataChannelJS() { } diff --git a/modules/webrtc/webrtc_data_channel_js.h b/modules/webrtc/webrtc_data_channel_js.h index db58ebccff..5cd6a32ed9 100644 --- a/modules/webrtc/webrtc_data_channel_js.h +++ b/modules/webrtc/webrtc_data_channel_js.h @@ -72,6 +72,7 @@ public: virtual int get_max_retransmits() const override; virtual String get_protocol() const override; virtual bool is_negotiated() const override; + virtual int get_buffered_amount() const override; virtual Error poll() override; virtual void close() override; diff --git a/modules/webrtc/webrtc_multiplayer.cpp b/modules/webrtc/webrtc_multiplayer_peer.cpp index 741cad5640..51101e3124 100644 --- a/modules/webrtc/webrtc_multiplayer.cpp +++ b/modules/webrtc/webrtc_multiplayer_peer.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* webrtc_multiplayer.cpp */ +/* webrtc_multiplayer_peer.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,43 +28,43 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "webrtc_multiplayer.h" +#include "webrtc_multiplayer_peer.h" #include "core/io/marshalls.h" #include "core/os/os.h" -void WebRTCMultiplayer::_bind_methods() { - ClassDB::bind_method(D_METHOD("initialize", "peer_id", "server_compatibility"), &WebRTCMultiplayer::initialize, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("add_peer", "peer", "peer_id", "unreliable_lifetime"), &WebRTCMultiplayer::add_peer, DEFVAL(1)); - ClassDB::bind_method(D_METHOD("remove_peer", "peer_id"), &WebRTCMultiplayer::remove_peer); - ClassDB::bind_method(D_METHOD("has_peer", "peer_id"), &WebRTCMultiplayer::has_peer); - ClassDB::bind_method(D_METHOD("get_peer", "peer_id"), &WebRTCMultiplayer::get_peer); - ClassDB::bind_method(D_METHOD("get_peers"), &WebRTCMultiplayer::get_peers); - ClassDB::bind_method(D_METHOD("close"), &WebRTCMultiplayer::close); +void WebRTCMultiplayerPeer::_bind_methods() { + ClassDB::bind_method(D_METHOD("initialize", "peer_id", "server_compatibility"), &WebRTCMultiplayerPeer::initialize, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("add_peer", "peer", "peer_id", "unreliable_lifetime"), &WebRTCMultiplayerPeer::add_peer, DEFVAL(1)); + ClassDB::bind_method(D_METHOD("remove_peer", "peer_id"), &WebRTCMultiplayerPeer::remove_peer); + ClassDB::bind_method(D_METHOD("has_peer", "peer_id"), &WebRTCMultiplayerPeer::has_peer); + ClassDB::bind_method(D_METHOD("get_peer", "peer_id"), &WebRTCMultiplayerPeer::get_peer); + ClassDB::bind_method(D_METHOD("get_peers"), &WebRTCMultiplayerPeer::get_peers); + ClassDB::bind_method(D_METHOD("close"), &WebRTCMultiplayerPeer::close); } -void WebRTCMultiplayer::set_transfer_mode(TransferMode p_mode) { +void WebRTCMultiplayerPeer::set_transfer_mode(TransferMode p_mode) { transfer_mode = p_mode; } -NetworkedMultiplayerPeer::TransferMode WebRTCMultiplayer::get_transfer_mode() const { +MultiplayerPeer::TransferMode WebRTCMultiplayerPeer::get_transfer_mode() const { return transfer_mode; } -void WebRTCMultiplayer::set_target_peer(int p_peer_id) { +void WebRTCMultiplayerPeer::set_target_peer(int p_peer_id) { target_peer = p_peer_id; } -/* Returns the ID of the NetworkedMultiplayerPeer who sent the most recent packet: */ -int WebRTCMultiplayer::get_packet_peer() const { +/* Returns the ID of the MultiplayerPeer who sent the most recent packet: */ +int WebRTCMultiplayerPeer::get_packet_peer() const { return next_packet_peer; } -bool WebRTCMultiplayer::is_server() const { +bool WebRTCMultiplayerPeer::is_server() const { return unique_id == TARGET_PEER_SERVER; } -void WebRTCMultiplayer::poll() { +void WebRTCMultiplayerPeer::poll() { if (peer_map.size() == 0) { return; } @@ -123,19 +123,19 @@ void WebRTCMultiplayer::poll() { // Already connected to server: simply notify new peer. // NOTE: Mesh is always connected. if (connection_status == CONNECTION_CONNECTED) { - emit_signal("peer_connected", E->get()); + emit_signal(SNAME("peer_connected"), E->get()); } // Server emulation mode suppresses peer_conencted until server connects. if (server_compat && E->get() == TARGET_PEER_SERVER) { // Server connected. connection_status = CONNECTION_CONNECTED; - emit_signal("peer_connected", TARGET_PEER_SERVER); - emit_signal("connection_succeeded"); + emit_signal(SNAME("peer_connected"), TARGET_PEER_SERVER); + emit_signal(SNAME("connection_succeeded")); // Notify of all previously connected peers for (Map<int, Ref<ConnectedPeer>>::Element *F = peer_map.front(); F; F = F->next()) { if (F->key() != 1 && F->get()->connected) { - emit_signal("peer_connected", F->key()); + emit_signal(SNAME("peer_connected"), F->key()); } } break; // Because we already notified of all newly added peers. @@ -147,7 +147,7 @@ void WebRTCMultiplayer::poll() { } } -void WebRTCMultiplayer::_find_next_peer() { +void WebRTCMultiplayerPeer::_find_next_peer() { Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.find(next_packet_peer); if (E) { E = E->next(); @@ -180,19 +180,19 @@ void WebRTCMultiplayer::_find_next_peer() { next_packet_peer = 0; } -void WebRTCMultiplayer::set_refuse_new_connections(bool p_enable) { +void WebRTCMultiplayerPeer::set_refuse_new_connections(bool p_enable) { refuse_connections = p_enable; } -bool WebRTCMultiplayer::is_refusing_new_connections() const { +bool WebRTCMultiplayerPeer::is_refusing_new_connections() const { return refuse_connections; } -NetworkedMultiplayerPeer::ConnectionStatus WebRTCMultiplayer::get_connection_status() const { +MultiplayerPeer::ConnectionStatus WebRTCMultiplayerPeer::get_connection_status() const { return connection_status; } -Error WebRTCMultiplayer::initialize(int p_self_id, bool p_server_compat) { +Error WebRTCMultiplayerPeer::initialize(int p_self_id, bool p_server_compat) { ERR_FAIL_COND_V(p_self_id < 0 || p_self_id > ~(1 << 31), ERR_INVALID_PARAMETER); unique_id = p_self_id; server_compat = p_server_compat; @@ -206,12 +206,12 @@ Error WebRTCMultiplayer::initialize(int p_self_id, bool p_server_compat) { return OK; } -int WebRTCMultiplayer::get_unique_id() const { +int WebRTCMultiplayerPeer::get_unique_id() const { ERR_FAIL_COND_V(connection_status == CONNECTION_DISCONNECTED, 1); return unique_id; } -void WebRTCMultiplayer::_peer_to_dict(Ref<ConnectedPeer> p_connected_peer, Dictionary &r_dict) { +void WebRTCMultiplayerPeer::_peer_to_dict(Ref<ConnectedPeer> p_connected_peer, Dictionary &r_dict) { Array channels; for (List<Ref<WebRTCDataChannel>>::Element *F = p_connected_peer->channels.front(); F; F = F->next()) { channels.push_back(F->get()); @@ -221,18 +221,18 @@ void WebRTCMultiplayer::_peer_to_dict(Ref<ConnectedPeer> p_connected_peer, Dicti r_dict["channels"] = channels; } -bool WebRTCMultiplayer::has_peer(int p_peer_id) { +bool WebRTCMultiplayerPeer::has_peer(int p_peer_id) { return peer_map.has(p_peer_id); } -Dictionary WebRTCMultiplayer::get_peer(int p_peer_id) { +Dictionary WebRTCMultiplayerPeer::get_peer(int p_peer_id) { ERR_FAIL_COND_V(!peer_map.has(p_peer_id), Dictionary()); Dictionary out; _peer_to_dict(peer_map[p_peer_id], out); return out; } -Dictionary WebRTCMultiplayer::get_peers() { +Dictionary WebRTCMultiplayerPeer::get_peers() { Dictionary out; for (Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.front(); E; E = E->next()) { Dictionary d; @@ -242,7 +242,7 @@ Dictionary WebRTCMultiplayer::get_peers() { return out; } -Error WebRTCMultiplayer::add_peer(Ref<WebRTCPeerConnection> p_peer, int p_peer_id, int p_unreliable_lifetime) { +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); @@ -277,21 +277,21 @@ Error WebRTCMultiplayer::add_peer(Ref<WebRTCPeerConnection> p_peer, int p_peer_i return OK; } -void WebRTCMultiplayer::remove_peer(int p_peer_id) { +void WebRTCMultiplayerPeer::remove_peer(int p_peer_id) { ERR_FAIL_COND(!peer_map.has(p_peer_id)); Ref<ConnectedPeer> peer = peer_map[p_peer_id]; peer_map.erase(p_peer_id); if (peer->connected) { peer->connected = false; - emit_signal("peer_disconnected", p_peer_id); + emit_signal(SNAME("peer_disconnected"), p_peer_id); if (server_compat && p_peer_id == TARGET_PEER_SERVER) { - emit_signal("server_disconnected"); + emit_signal(SNAME("server_disconnected")); connection_status = CONNECTION_DISCONNECTED; } } } -Error WebRTCMultiplayer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { +Error WebRTCMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { // Peer not available if (next_packet_peer == 0 || !peer_map.has(next_packet_peer)) { _find_next_peer(); @@ -309,7 +309,7 @@ Error WebRTCMultiplayer::get_packet(const uint8_t **r_buffer, int &r_buffer_size ERR_FAIL_V(ERR_BUG); } -Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { +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 = CH_RELIABLE; @@ -351,7 +351,7 @@ Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size) return OK; } -int WebRTCMultiplayer::get_available_packet_count() const { +int WebRTCMultiplayerPeer::get_available_packet_count() const { if (next_packet_peer == 0) { return 0; // To be sure next call to get_packet works if size > 0 . } @@ -364,11 +364,11 @@ int WebRTCMultiplayer::get_available_packet_count() const { return size; } -int WebRTCMultiplayer::get_max_packet_size() const { +int WebRTCMultiplayerPeer::get_max_packet_size() const { return 1200; } -void WebRTCMultiplayer::close() { +void WebRTCMultiplayerPeer::close() { peer_map.clear(); unique_id = 0; next_packet_peer = 0; @@ -376,7 +376,7 @@ void WebRTCMultiplayer::close() { connection_status = CONNECTION_DISCONNECTED; } -WebRTCMultiplayer::WebRTCMultiplayer() { +WebRTCMultiplayerPeer::WebRTCMultiplayerPeer() { unique_id = 0; next_packet_peer = 0; target_peer = 0; @@ -387,6 +387,6 @@ WebRTCMultiplayer::WebRTCMultiplayer() { server_compat = false; } -WebRTCMultiplayer::~WebRTCMultiplayer() { +WebRTCMultiplayerPeer::~WebRTCMultiplayerPeer() { close(); } diff --git a/modules/webrtc/webrtc_multiplayer.h b/modules/webrtc/webrtc_multiplayer_peer.h index 2ddb98f656..1d9387b6dc 100644 --- a/modules/webrtc/webrtc_multiplayer.h +++ b/modules/webrtc/webrtc_multiplayer_peer.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* webrtc_multiplayer.h */ +/* webrtc_multiplayer_peer.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,11 +31,11 @@ #ifndef WEBRTC_MULTIPLAYER_H #define WEBRTC_MULTIPLAYER_H -#include "core/io/networked_multiplayer_peer.h" +#include "core/io/multiplayer_peer.h" #include "webrtc_peer_connection.h" -class WebRTCMultiplayer : public NetworkedMultiplayerPeer { - GDCLASS(WebRTCMultiplayer, NetworkedMultiplayerPeer); +class WebRTCMultiplayerPeer : public MultiplayerPeer { + GDCLASS(WebRTCMultiplayerPeer, MultiplayerPeer); protected: static void _bind_methods(); @@ -77,8 +77,8 @@ private: void _find_next_peer(); public: - WebRTCMultiplayer(); - ~WebRTCMultiplayer(); + WebRTCMultiplayerPeer(); + ~WebRTCMultiplayerPeer(); Error initialize(int p_self_id, bool p_server_compat = false); Error add_peer(Ref<WebRTCPeerConnection> p_peer, int p_peer_id, int p_unreliable_lifetime = 1); @@ -94,7 +94,7 @@ public: int get_available_packet_count() const override; int get_max_packet_size() const override; - // NetworkedMultiplayerPeer + // MultiplayerPeer void set_transfer_mode(TransferMode p_mode) override; TransferMode get_transfer_mode() const override; void set_target_peer(int p_peer_id) override; diff --git a/modules/webrtc/webrtc_peer_connection_js.cpp b/modules/webrtc/webrtc_peer_connection_js.cpp index 8879f7d6ec..ed3459d5f8 100644 --- a/modules/webrtc/webrtc_peer_connection_js.cpp +++ b/modules/webrtc/webrtc_peer_connection_js.cpp @@ -34,17 +34,16 @@ #include "webrtc_data_channel_js.h" -#include "core/io/json.h" #include "emscripten.h" void WebRTCPeerConnectionJS::_on_ice_candidate(void *p_obj, const char *p_mid_name, int p_mline_idx, const char *p_candidate) { WebRTCPeerConnectionJS *peer = static_cast<WebRTCPeerConnectionJS *>(p_obj); - peer->emit_signal("ice_candidate_created", String(p_mid_name), p_mline_idx, String(p_candidate)); + peer->emit_signal(SNAME("ice_candidate_created"), String(p_mid_name), p_mline_idx, String(p_candidate)); } void WebRTCPeerConnectionJS::_on_session_created(void *p_obj, const char *p_type, const char *p_session) { WebRTCPeerConnectionJS *peer = static_cast<WebRTCPeerConnectionJS *>(p_obj); - peer->emit_signal("session_description_created", String(p_type), String(p_session)); + peer->emit_signal(SNAME("session_description_created"), String(p_type), String(p_session)); } void WebRTCPeerConnectionJS::_on_connection_state_changed(void *p_obj, int p_state) { @@ -58,7 +57,7 @@ void WebRTCPeerConnectionJS::_on_error(void *p_obj) { void WebRTCPeerConnectionJS::_on_data_channel(void *p_obj, int p_id) { WebRTCPeerConnectionJS *peer = static_cast<WebRTCPeerConnectionJS *>(p_obj); - peer->emit_signal("data_channel_received", Ref<WebRTCDataChannelJS>(new WebRTCDataChannelJS(p_id))); + peer->emit_signal(SNAME("data_channel_received"), Ref<WebRTCDataChannelJS>(new WebRTCDataChannelJS(p_id))); } void WebRTCPeerConnectionJS::close() { @@ -100,7 +99,7 @@ Error WebRTCPeerConnectionJS::initialize(Dictionary p_config) { } _conn_state = STATE_NEW; - String config = JSON::print(p_config); + String config = Variant(p_config).to_json_string(); _js_id = godot_js_rtc_pc_create(config.utf8().get_data(), this, &_on_connection_state_changed, &_on_ice_candidate, &_on_data_channel); return _js_id ? OK : FAILED; } @@ -108,7 +107,7 @@ Error WebRTCPeerConnectionJS::initialize(Dictionary p_config) { Ref<WebRTCDataChannel> WebRTCPeerConnectionJS::create_data_channel(String p_channel, Dictionary p_channel_config) { ERR_FAIL_COND_V(_conn_state != STATE_NEW, nullptr); - String config = JSON::print(p_channel_config); + String config = Variant(p_channel_config).to_json_string(); int id = godot_js_rtc_pc_datachannel_create(_js_id, p_channel.utf8().get_data(), config.utf8().get_data()); ERR_FAIL_COND_V(id == 0, nullptr); return memnew(WebRTCDataChannelJS(id)); diff --git a/modules/websocket/doc_classes/WebSocketClient.xml b/modules/websocket/doc_classes/WebSocketClient.xml index 6af610c689..40c0ad17ad 100644 --- a/modules/websocket/doc_classes/WebSocketClient.xml +++ b/modules/websocket/doc_classes/WebSocketClient.xml @@ -6,7 +6,7 @@ <description> This class implements a WebSocket client compatible with any RFC 6455-compliant WebSocket server. This client can be optionally used as a network peer for the [MultiplayerAPI]. - After starting the client ([method connect_to_url]), you will need to [method NetworkedMultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). + 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. </description> <tutorials> diff --git a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml index 0679acf78a..ee1b60f739 100644 --- a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml +++ b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="WebSocketMultiplayerPeer" inherits="NetworkedMultiplayerPeer" version="4.0"> +<class name="WebSocketMultiplayerPeer" inherits="MultiplayerPeer" version="4.0"> <brief_description> Base class for WebSocket server and client. </brief_description> @@ -39,7 +39,7 @@ </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="NetworkedMultiplayerPeer.TransferMode" default="2" /> + <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="MultiplayerPeer.TransferMode" default="2" /> </members> <signals> <signal name="peer_packet"> diff --git a/modules/websocket/doc_classes/WebSocketServer.xml b/modules/websocket/doc_classes/WebSocketServer.xml index 78f2832770..5491f7de15 100644 --- a/modules/websocket/doc_classes/WebSocketServer.xml +++ b/modules/websocket/doc_classes/WebSocketServer.xml @@ -5,7 +5,7 @@ </brief_description> <description> 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 NetworkedMultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). When clients connect, disconnect, or send data, you will receive the appropriate signal. + 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. </description> <tutorials> @@ -89,6 +89,9 @@ <member name="ca_chain" type="X509Certificate" setter="set_ca_chain" getter="get_ca_chain"> When using SSL (see [member private_key] and [member ssl_certificate]), you can set this to a valid [X509Certificate] to be provided as additional CA chain information during the SSL handshake. </member> + <member name="handshake_timeout" type="float" setter="set_handshake_timeout" getter="get_handshake_timeout" default="3.0"> + The time in seconds before a pending client (i.e. a client that has not yet finished the HTTP handshake) is considered stale and forcefully disconnected. + </member> <member name="private_key" type="CryptoKey" setter="set_private_key" getter="get_private_key"> When set to a valid [CryptoKey] (along with [member ssl_certificate]) will cause the server to require SSL instead of regular TCP (i.e. the [code]wss://[/code] protocol). </member> @@ -113,8 +116,11 @@ </argument> <argument index="1" name="protocol" type="String"> </argument> + <argument index="2" name="resource_name" type="String"> + </argument> <description> - Emitted when a new client connects. "protocol" will be the sub-protocol agreed with the client. + Emitted when a new client connects. "protocol" will be the sub-protocol agreed with the client, and "resource_name" will be the resource name of the URI the peer used. + "resource_name" is a path (at the very least a single forward slash) and potentially a query string. </description> </signal> <signal name="client_disconnected"> diff --git a/modules/websocket/editor_debugger_server_websocket.cpp b/modules/websocket/editor_debugger_server_websocket.cpp index b02d212c42..2e61cbfc08 100644 --- a/modules/websocket/editor_debugger_server_websocket.cpp +++ b/modules/websocket/editor_debugger_server_websocket.cpp @@ -50,9 +50,9 @@ void EditorDebuggerServerWebSocket::poll() { Error EditorDebuggerServerWebSocket::start() { int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); - Vector<String> protocols; - protocols.push_back("binary"); // compatibility with EMSCRIPTEN TCP-to-WebSocket layer. - return server->listen(remote_port, protocols); + Vector<String> compatible_protocols; + compatible_protocols.push_back("binary"); // compatibility with EMSCRIPTEN TCP-to-WebSocket layer. + return server->listen(remote_port, compatible_protocols); } void EditorDebuggerServerWebSocket::stop() { diff --git a/modules/websocket/editor_debugger_server_websocket.h b/modules/websocket/editor_debugger_server_websocket.h index 2f73b98c3d..d9543bb647 100644 --- a/modules/websocket/editor_debugger_server_websocket.h +++ b/modules/websocket/editor_debugger_server_websocket.h @@ -28,12 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef SCRIPT_EDITOR_DEBUGGER_WEBSOCKET_H -#define SCRIPT_EDITOR_DEBUGGER_WEBSOCKET_H - -#include "modules/websocket/websocket_server.h" +#ifndef EDITOR_DEBUGGER_SERVER_WEBSOCKET_H +#define EDITOR_DEBUGGER_SERVER_WEBSOCKET_H #include "editor/debugger/editor_debugger_server.h" +#include "modules/websocket/websocket_server.h" class EditorDebuggerServerWebSocket : public EditorDebuggerServer { GDCLASS(EditorDebuggerServerWebSocket, EditorDebuggerServer); @@ -59,4 +58,4 @@ public: ~EditorDebuggerServerWebSocket(); }; -#endif // SCRIPT_EDITOR_DEBUGGER_WEBSOCKET_H +#endif // EDITOR_DEBUGGER_SERVER_WEBSOCKET_H diff --git a/modules/websocket/emws_client.cpp b/modules/websocket/emws_client.cpp index 626498e1ae..744053b6e2 100644 --- a/modules/websocket/emws_client.cpp +++ b/modules/websocket/emws_client.cpp @@ -107,7 +107,7 @@ Ref<WebSocketPeer> EMWSClient::get_peer(int p_peer_id) const { return _peer; } -NetworkedMultiplayerPeer::ConnectionStatus EMWSClient::get_connection_status() const { +MultiplayerPeer::ConnectionStatus EMWSClient::get_connection_status() const { if (_peer->is_connected_to_host()) { if (_is_connecting) return CONNECTION_CONNECTING; diff --git a/modules/websocket/emws_peer.cpp b/modules/websocket/emws_peer.cpp index 1ad3bdc825..05f9e12ae1 100644 --- a/modules/websocket/emws_peer.cpp +++ b/modules/websocket/emws_peer.cpp @@ -56,7 +56,7 @@ Error EMWSPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { int is_bin = write_mode == WebSocketPeer::WRITE_MODE_BINARY ? 1 : 0; godot_js_websocket_send(peer_sock, p_buffer, p_buffer_size, is_bin); return OK; -}; +} Error EMWSPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { if (_in_buffer.packets_left() == 0) @@ -70,19 +70,19 @@ Error EMWSPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { r_buffer_size = read; return OK; -}; +} int EMWSPeer::get_available_packet_count() const { return _in_buffer.packets_left(); -}; +} bool EMWSPeer::was_string_packet() const { return _is_string; -}; +} bool EMWSPeer::is_connected_to_host() const { return peer_sock != -1; -}; +} void EMWSPeer::close(int p_code, String p_reason) { if (peer_sock != -1) { @@ -91,7 +91,7 @@ void EMWSPeer::close(int p_code, String p_reason) { _is_string = 0; _in_buffer.clear(); peer_sock = -1; -}; +} IPAddress EMWSPeer::get_connected_host() const { ERR_FAIL_V_MSG(IPAddress(), "Not supported in HTML5 export."); @@ -99,7 +99,7 @@ IPAddress EMWSPeer::get_connected_host() const { uint16_t EMWSPeer::get_connected_port() const { ERR_FAIL_V_MSG(0, "Not supported in HTML5 export."); -}; +} void EMWSPeer::set_no_delay(bool p_enabled) { ERR_FAIL_MSG("'set_no_delay' is not supported in HTML5 export."); @@ -107,10 +107,10 @@ void EMWSPeer::set_no_delay(bool p_enabled) { EMWSPeer::EMWSPeer() { close(); -}; +} EMWSPeer::~EMWSPeer() { close(); -}; +} #endif // JAVASCRIPT_ENABLED diff --git a/modules/websocket/register_types.cpp b/modules/websocket/register_types.cpp index 5a02509c4a..7c742b1b89 100644 --- a/modules/websocket/register_types.cpp +++ b/modules/websocket/register_types.cpp @@ -63,7 +63,7 @@ void register_websocket_types() { WSLServer::make_default(); #endif - ClassDB::register_virtual_class<WebSocketMultiplayerPeer>(); + GDREGISTER_VIRTUAL_CLASS(WebSocketMultiplayerPeer); ClassDB::register_custom_instance_class<WebSocketServer>(); ClassDB::register_custom_instance_class<WebSocketClient>(); ClassDB::register_custom_instance_class<WebSocketPeer>(); diff --git a/modules/websocket/remote_debugger_peer_websocket.h b/modules/websocket/remote_debugger_peer_websocket.h index 03c60fb480..590d925dcc 100644 --- a/modules/websocket/remote_debugger_peer_websocket.h +++ b/modules/websocket/remote_debugger_peer_websocket.h @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef SCRIPT_DEBUGGER_WEBSOCKET_H -#define SCRIPT_DEBUGGER_WEBSOCKET_H +#ifndef REMOTE_DEBUGGER_PEER_WEBSOCKET_H +#define REMOTE_DEBUGGER_PEER_WEBSOCKET_H #ifdef JAVASCRIPT_ENABLED #include "modules/websocket/emws_client.h" @@ -62,4 +62,4 @@ public: RemoteDebuggerPeerWebSocket(Ref<WebSocketPeer> p_peer = Ref<WebSocketPeer>()); }; -#endif // SCRIPT_DEBUGGER_WEBSOCKET_H +#endif // REMOTE_DEBUGGER_PEER_WEBSOCKET_H diff --git a/modules/websocket/websocket_client.cpp b/modules/websocket/websocket_client.cpp index 27f0f9af6b..f7a8944745 100644 --- a/modules/websocket/websocket_client.cpp +++ b/modules/websocket/websocket_client.cpp @@ -42,9 +42,9 @@ Error WebSocketClient::connect_to_url(String p_url, const Vector<String> p_proto _is_multiplayer = gd_mp_api; String host = p_url; - String path = "/"; - String scheme = ""; - int port = 80; + String path; + String scheme; + int port = 0; Error err = p_url.parse_url(scheme, host, port, path); ERR_FAIL_COND_V_MSG(err != OK, err, "Invalid URL: " + p_url); @@ -55,6 +55,9 @@ Error WebSocketClient::connect_to_url(String p_url, const Vector<String> p_proto if (port == 0) { port = ssl ? 443 : 80; } + if (path.is_empty()) { + path = "/"; + } return connect_to_host(host, path, port, ssl, p_protocols, p_custom_headers); } @@ -83,7 +86,7 @@ void WebSocketClient::_on_peer_packet() { if (_is_multiplayer) { _process_multiplayer(get_peer(1), 1); } else { - emit_signal("data_received"); + emit_signal(SNAME("data_received")); } } @@ -91,27 +94,27 @@ void WebSocketClient::_on_connect(String p_protocol) { if (_is_multiplayer) { // need to wait for ID confirmation... } else { - emit_signal("connection_established", p_protocol); + emit_signal(SNAME("connection_established"), p_protocol); } } void WebSocketClient::_on_close_request(int p_code, String p_reason) { - emit_signal("server_close_request", p_code, p_reason); + emit_signal(SNAME("server_close_request"), p_code, p_reason); } void WebSocketClient::_on_disconnect(bool p_was_clean) { if (_is_multiplayer) { - emit_signal("connection_failed"); + emit_signal(SNAME("connection_failed")); } else { - emit_signal("connection_closed", p_was_clean); + emit_signal(SNAME("connection_closed"), p_was_clean); } } void WebSocketClient::_on_error() { if (_is_multiplayer) { - emit_signal("connection_failed"); + emit_signal(SNAME("connection_failed")); } else { - emit_signal("connection_error"); + emit_signal(SNAME("connection_error")); } } diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp index fa0ef7060f..ddd8e190df 100644 --- a/modules/websocket/websocket_multiplayer_peer.cpp +++ b/modules/websocket/websocket_multiplayer_peer.cpp @@ -123,13 +123,13 @@ Error WebSocketMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer } // -// NetworkedMultiplayerPeer +// MultiplayerPeer // void WebSocketMultiplayerPeer::set_transfer_mode(TransferMode p_mode) { // Websocket uses TCP, reliable } -NetworkedMultiplayerPeer::TransferMode WebSocketMultiplayerPeer::get_transfer_mode() const { +MultiplayerPeer::TransferMode WebSocketMultiplayerPeer::get_transfer_mode() const { // Websocket uses TCP, reliable return TRANSFER_MODE_RELIABLE; } @@ -215,7 +215,7 @@ void WebSocketMultiplayerPeer::_store_pkt(int32_t p_source, int32_t p_dest, cons packet.destination = p_dest; memcpy(packet.data, &p_data[PROTO_SIZE], p_data_size); _incoming_packets.push_back(packet); - emit_signal("peer_packet", p_source); + emit_signal(SNAME("peer_packet"), p_source); } Error WebSocketMultiplayerPeer::_server_relay(int32_t p_from, int32_t p_to, const uint8_t *p_buffer, uint32_t p_buffer_size) { @@ -306,15 +306,15 @@ void WebSocketMultiplayerPeer::_process_multiplayer(Ref<WebSocketPeer> p_peer, u switch (type) { case SYS_ADD: // Add peer _peer_map[id] = Ref<WebSocketPeer>(); - emit_signal("peer_connected", id); + emit_signal(SNAME("peer_connected"), id); if (id == 1) { // We just connected to the server - emit_signal("connection_succeeded"); + emit_signal(SNAME("connection_succeeded")); } break; case SYS_DEL: // Remove peer _peer_map.erase(id); - emit_signal("peer_disconnected", id); + emit_signal(SNAME("peer_disconnected"), id); break; case SYS_ID: // Hello, server assigned ID _peer_id = id; diff --git a/modules/websocket/websocket_multiplayer_peer.h b/modules/websocket/websocket_multiplayer_peer.h index 48a6607d89..e3ccd1a795 100644 --- a/modules/websocket/websocket_multiplayer_peer.h +++ b/modules/websocket/websocket_multiplayer_peer.h @@ -32,12 +32,12 @@ #define WEBSOCKET_MULTIPLAYER_PEER_H #include "core/error/error_list.h" -#include "core/io/networked_multiplayer_peer.h" +#include "core/io/multiplayer_peer.h" #include "core/templates/list.h" #include "websocket_peer.h" -class WebSocketMultiplayerPeer : public NetworkedMultiplayerPeer { - GDCLASS(WebSocketMultiplayerPeer, NetworkedMultiplayerPeer); +class WebSocketMultiplayerPeer : public MultiplayerPeer { + GDCLASS(WebSocketMultiplayerPeer, MultiplayerPeer); private: Vector<uint8_t> _make_pkt(uint8_t p_type, int32_t p_from, int32_t p_to, const uint8_t *p_data, uint32_t p_data_size); @@ -78,7 +78,7 @@ protected: int _gen_unique_id() const; public: - /* NetworkedMultiplayerPeer */ + /* MultiplayerPeer */ void set_transfer_mode(TransferMode p_mode) override; TransferMode get_transfer_mode() const override; void set_target_peer(int p_target_peer) override; diff --git a/modules/websocket/websocket_server.cpp b/modules/websocket/websocket_server.cpp index dfe4471659..fb838109f3 100644 --- a/modules/websocket/websocket_server.cpp +++ b/modules/websocket/websocket_server.cpp @@ -65,9 +65,13 @@ void WebSocketServer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_ca_chain"), &WebSocketServer::set_ca_chain); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "ca_chain", PROPERTY_HINT_RESOURCE_TYPE, "X509Certificate", PROPERTY_USAGE_NONE), "set_ca_chain", "get_ca_chain"); + ClassDB::bind_method(D_METHOD("get_handshake_timeout"), &WebSocketServer::get_handshake_timeout); + ClassDB::bind_method(D_METHOD("set_handshake_timeout", "timeout"), &WebSocketServer::set_handshake_timeout); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "handshake_timeout"), "set_handshake_timeout", "get_handshake_timeout"); + ADD_SIGNAL(MethodInfo("client_close_request", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::INT, "code"), PropertyInfo(Variant::STRING, "reason"))); ADD_SIGNAL(MethodInfo("client_disconnected", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::BOOL, "was_clean_close"))); - ADD_SIGNAL(MethodInfo("client_connected", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "protocol"))); + ADD_SIGNAL(MethodInfo("client_connected", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "protocol"), PropertyInfo(Variant::STRING, "resource_name"))); ADD_SIGNAL(MethodInfo("data_received", PropertyInfo(Variant::INT, "id"))); } @@ -108,7 +112,16 @@ void WebSocketServer::set_ca_chain(Ref<X509Certificate> p_ca_chain) { ca_chain = p_ca_chain; } -NetworkedMultiplayerPeer::ConnectionStatus WebSocketServer::get_connection_status() const { +float WebSocketServer::get_handshake_timeout() const { + return handshake_timeout / 1000.0; +} + +void WebSocketServer::set_handshake_timeout(float p_timeout) { + ERR_FAIL_COND(p_timeout <= 0.0); + handshake_timeout = p_timeout * 1000; +} + +MultiplayerPeer::ConnectionStatus WebSocketServer::get_connection_status() const { if (is_listening()) { return CONNECTION_CONNECTED; } @@ -124,17 +137,17 @@ void WebSocketServer::_on_peer_packet(int32_t p_peer_id) { if (_is_multiplayer) { _process_multiplayer(get_peer(p_peer_id), p_peer_id); } else { - emit_signal("data_received", p_peer_id); + emit_signal(SNAME("data_received"), p_peer_id); } } -void WebSocketServer::_on_connect(int32_t p_peer_id, String p_protocol) { +void WebSocketServer::_on_connect(int32_t p_peer_id, String p_protocol, String p_resource_name) { if (_is_multiplayer) { // Send add to clients _send_add(p_peer_id); - emit_signal("peer_connected", p_peer_id); + emit_signal(SNAME("peer_connected"), p_peer_id); } else { - emit_signal("client_connected", p_peer_id, p_protocol); + emit_signal(SNAME("client_connected"), p_peer_id, p_protocol, p_resource_name); } } @@ -142,12 +155,12 @@ void WebSocketServer::_on_disconnect(int32_t p_peer_id, bool p_was_clean) { if (_is_multiplayer) { // Send delete to clients _send_del(p_peer_id); - emit_signal("peer_disconnected", p_peer_id); + emit_signal(SNAME("peer_disconnected"), p_peer_id); } else { - emit_signal("client_disconnected", p_peer_id, p_was_clean); + emit_signal(SNAME("client_disconnected"), p_peer_id, p_was_clean); } } void WebSocketServer::_on_close_request(int32_t p_peer_id, int p_code, String p_reason) { - emit_signal("client_close_request", p_peer_id, p_code, p_reason); + emit_signal(SNAME("client_close_request"), p_peer_id, p_code, p_reason); } diff --git a/modules/websocket/websocket_server.h b/modules/websocket/websocket_server.h index bc5e591e7b..c4d651471f 100644 --- a/modules/websocket/websocket_server.h +++ b/modules/websocket/websocket_server.h @@ -48,6 +48,7 @@ protected: Ref<CryptoKey> private_key; Ref<X509Certificate> ssl_cert; Ref<X509Certificate> ca_chain; + uint32_t handshake_timeout = 3000; public: virtual Error listen(int p_port, const Vector<String> p_protocols = Vector<String>(), bool gd_mp_api = false) = 0; @@ -62,7 +63,7 @@ public: virtual void disconnect_peer(int p_peer_id, int p_code = 1000, String p_reason = "") = 0; void _on_peer_packet(int32_t p_peer_id); - void _on_connect(int32_t p_peer_id, String p_protocol); + void _on_connect(int32_t p_peer_id, String p_protocol, String p_resource_name); void _on_disconnect(int32_t p_peer_id, bool p_was_clean); void _on_close_request(int32_t p_peer_id, int p_code, String p_reason); @@ -78,6 +79,9 @@ public: Ref<X509Certificate> get_ca_chain() const; void set_ca_chain(Ref<X509Certificate> p_ca_chain); + float get_handshake_timeout() const; + void set_handshake_timeout(float p_timeout); + WebSocketServer(); ~WebSocketServer(); }; diff --git a/modules/websocket/wsl_client.cpp b/modules/websocket/wsl_client.cpp index af1bdb532c..49997b42d3 100644 --- a/modules/websocket/wsl_client.cpp +++ b/modules/websocket/wsl_client.cpp @@ -158,6 +158,7 @@ bool WSLClient::_verify_headers(String &r_protocol) { Error WSLClient::connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, const Vector<String> p_protocols, const Vector<String> p_custom_headers) { ERR_FAIL_COND_V(_connection.is_valid(), ERR_ALREADY_IN_USE); + ERR_FAIL_COND_V(p_path.is_empty(), ERR_INVALID_PARAMETER); _peer = Ref<WSLPeer>(memnew(WSLPeer)); IPAddress addr; @@ -287,7 +288,7 @@ Ref<WebSocketPeer> WSLClient::get_peer(int p_peer_id) const { return _peer; } -NetworkedMultiplayerPeer::ConnectionStatus WSLClient::get_connection_status() const { +MultiplayerPeer::ConnectionStatus WSLClient::get_connection_status() const { if (_peer->is_connected_to_host()) { return CONNECTION_CONNECTED; } diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp index 22bb1b6d1a..5f794415af 100644 --- a/modules/websocket/wsl_server.cpp +++ b/modules/websocket/wsl_server.cpp @@ -34,7 +34,7 @@ #include "core/config/project_settings.h" #include "core/os/os.h" -bool WSLServer::PendingPeer::_parse_request(const Vector<String> p_protocols) { +bool WSLServer::PendingPeer::_parse_request(const Vector<String> p_protocols, String &r_resource_name) { Vector<String> psa = String((char *)req_buf).split("\r\n"); int len = psa.size(); ERR_FAIL_COND_V_MSG(len < 4, false, "Not enough response headers, got: " + itos(len) + ", expected >= 4."); @@ -45,6 +45,7 @@ bool WSLServer::PendingPeer::_parse_request(const Vector<String> p_protocols) { // Wrong protocol ERR_FAIL_COND_V_MSG(req[0] != "GET" || req[2] != "HTTP/1.1", false, "Invalid method or HTTP version."); + r_resource_name = req[1]; Map<String, String> headers; for (int i = 1; i < len; i++) { Vector<String> header = psa[i].split(":", false, 1); @@ -95,28 +96,33 @@ bool WSLServer::PendingPeer::_parse_request(const Vector<String> p_protocols) { return true; } -Error WSLServer::PendingPeer::do_handshake(const Vector<String> p_protocols) { - if (OS::get_singleton()->get_ticks_msec() - time > WSL_SERVER_TIMEOUT) { +Error WSLServer::PendingPeer::do_handshake(const Vector<String> p_protocols, uint64_t p_timeout, String &r_resource_name) { + if (OS::get_singleton()->get_ticks_msec() - time > p_timeout) { + print_verbose(vformat("WebSocket handshake timed out after %.3f seconds.", p_timeout * 0.001)); return ERR_TIMEOUT; } + if (use_ssl) { Ref<StreamPeerSSL> ssl = static_cast<Ref<StreamPeerSSL>>(connection); if (ssl.is_null()) { - return FAILED; + ERR_FAIL_V_MSG(ERR_BUG, "Couldn't get StreamPeerSSL for WebSocket handshake."); } ssl->poll(); if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING) { return ERR_BUSY; } else if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) { + print_verbose(vformat("WebSocket SSL connection error during handshake (StreamPeerSSL status code %d).", ssl->get_status())); return FAILED; } } + if (!has_request) { int read = 0; while (true) { - ERR_FAIL_COND_V_MSG(req_pos >= WSL_MAX_HEADER_SIZE, ERR_OUT_OF_MEMORY, "Response headers too big."); + ERR_FAIL_COND_V_MSG(req_pos >= WSL_MAX_HEADER_SIZE, ERR_OUT_OF_MEMORY, "WebSocket response headers are too big."); Error err = connection->get_partial_data(&req_buf[req_pos], 1, read); if (err != OK) { // Got an error + print_verbose(vformat("WebSocket error while getting partial data (StreamPeer error code %d).", err)); return FAILED; } else if (read != 1) { // Busy, wait next poll return ERR_BUSY; @@ -125,7 +131,7 @@ Error WSLServer::PendingPeer::do_handshake(const Vector<String> p_protocols) { int l = req_pos; if (l > 3 && r[l] == '\n' && r[l - 1] == '\r' && r[l - 2] == '\n' && r[l - 3] == '\r') { r[l - 3] = '\0'; - if (!_parse_request(p_protocols)) { + if (!_parse_request(p_protocols, r_resource_name)) { return FAILED; } String s = "HTTP/1.1 101 Switching Protocols\r\n"; @@ -143,17 +149,21 @@ Error WSLServer::PendingPeer::do_handshake(const Vector<String> p_protocols) { req_pos += 1; } } + if (has_request && response_sent < response.size() - 1) { int sent = 0; Error err = connection->put_partial_data((const uint8_t *)response.get_data() + response_sent, response.size() - response_sent - 1, sent); if (err != OK) { + print_verbose(vformat("WebSocket error while putting partial data (StreamPeer error code %d).", err)); return err; } response_sent += sent; } + if (response_sent < response.size() - 1) { return ERR_BUSY; } + return OK; } @@ -187,8 +197,9 @@ void WSLServer::poll() { List<Ref<PendingPeer>> remove_peers; for (List<Ref<PendingPeer>>::Element *E = _pending.front(); E; E = E->next()) { + String resource_name; Ref<PendingPeer> ppeer = E->get(); - Error err = ppeer->do_handshake(_protocols); + Error err = ppeer->do_handshake(_protocols, handshake_timeout, resource_name); if (err == ERR_BUSY) { continue; } else if (err != OK) { @@ -211,7 +222,7 @@ void WSLServer::poll() { _peer_map[id] = ws_peer; remove_peers.push_back(ppeer); - _on_connect(id, ppeer->protocol); + _on_connect(id, ppeer->protocol, resource_name); } for (List<Ref<PendingPeer>>::Element *E = remove_peers.front(); E; E = E->next()) { _pending.erase(E->get()); diff --git a/modules/websocket/wsl_server.h b/modules/websocket/wsl_server.h index 39177a16a8..93c8bd9604 100644 --- a/modules/websocket/wsl_server.h +++ b/modules/websocket/wsl_server.h @@ -40,15 +40,13 @@ #include "core/io/stream_peer_tcp.h" #include "core/io/tcp_server.h" -#define WSL_SERVER_TIMEOUT 1000 - class WSLServer : public WebSocketServer { GDCIIMPL(WSLServer, WebSocketServer); private: class PendingPeer : public RefCounted { private: - bool _parse_request(const Vector<String> p_protocols); + bool _parse_request(const Vector<String> p_protocols, String &r_resource_name); public: Ref<StreamPeerTCP> tcp; @@ -64,7 +62,7 @@ private: CharString response; int response_sent = 0; - Error do_handshake(const Vector<String> p_protocols); + Error do_handshake(const Vector<String> p_protocols, uint64_t p_timeout, String &r_resource_name); }; int _in_buf_size = DEF_BUF_SHIFT; diff --git a/modules/webxr/register_types.cpp b/modules/webxr/register_types.cpp index 6df0234811..078a6547cf 100644 --- a/modules/webxr/register_types.cpp +++ b/modules/webxr/register_types.cpp @@ -34,7 +34,7 @@ #include "webxr_interface_js.h" void register_webxr_types() { - ClassDB::register_virtual_class<WebXRInterface>(); + GDREGISTER_VIRTUAL_CLASS(WebXRInterface); #ifdef JAVASCRIPT_ENABLED Ref<WebXRInterfaceJS> webxr; diff --git a/modules/webxr/webxr_interface_js.cpp b/modules/webxr/webxr_interface_js.cpp index 2eab0cdb07..099e769303 100644 --- a/modules/webxr/webxr_interface_js.cpp +++ b/modules/webxr/webxr_interface_js.cpp @@ -35,6 +35,7 @@ #include "core/os/os.h" #include "emscripten.h" #include "godot_webxr.h" +#include "servers/rendering/renderer_compositor.h" #include <stdlib.h> void _emwebxr_on_session_supported(char *p_session_mode, int p_supported) { @@ -45,7 +46,7 @@ void _emwebxr_on_session_supported(char *p_session_mode, int p_supported) { ERR_FAIL_COND(interface.is_null()); String session_mode = String(p_session_mode); - interface->emit_signal("session_supported", session_mode, p_supported ? true : false); + interface->emit_signal(SNAME("session_supported"), session_mode, p_supported ? true : false); } void _emwebxr_on_session_started(char *p_reference_space_type) { @@ -57,7 +58,7 @@ void _emwebxr_on_session_started(char *p_reference_space_type) { String reference_space_type = String(p_reference_space_type); ((WebXRInterfaceJS *)interface.ptr())->_set_reference_space_type(reference_space_type); - interface->emit_signal("session_started"); + interface->emit_signal(SNAME("session_started")); } void _emwebxr_on_session_ended() { @@ -68,7 +69,7 @@ void _emwebxr_on_session_ended() { ERR_FAIL_COND(interface.is_null()); interface->uninitialize(); - interface->emit_signal("session_ended"); + interface->emit_signal(SNAME("session_ended")); } void _emwebxr_on_session_failed(char *p_message) { @@ -81,7 +82,7 @@ void _emwebxr_on_session_failed(char *p_message) { interface->uninitialize(); String message = String(p_message); - interface->emit_signal("session_failed", message); + interface->emit_signal(SNAME("session_failed"), message); } void _emwebxr_on_controller_changed() { @@ -202,8 +203,8 @@ int WebXRInterfaceJS::get_capabilities() const { return XRInterface::XR_STEREO | XRInterface::XR_MONO; }; -bool WebXRInterfaceJS::is_stereo() { - return godot_webxr_get_view_count() == 2; +uint32_t WebXRInterfaceJS::get_view_count() { + return godot_webxr_get_view_count(); }; bool WebXRInterfaceJS::is_initialized() const { @@ -376,6 +377,22 @@ void WebXRInterfaceJS::commit_for_eye(XRInterface::Eyes p_eye, RID p_render_targ return; } godot_webxr_commit_for_eye(p_eye); +} + +Vector<BlitToScreen> WebXRInterfaceJS::commit_views(RID p_render_target, const Rect2 &p_screen_rect) { + Vector<BlitToScreen> blit_to_screen; + + if (!initialized) { + return blit_to_screen; + } + + // @todo Refactor this to be based on "views" rather than "eyes". + godot_webxr_commit_for_eye(XRInterface::EYE_LEFT); + if (godot_webxr_get_view_count() > 1) { + godot_webxr_commit_for_eye(XRInterface::EYE_RIGHT); + } + + return blit_to_screen; }; void WebXRInterfaceJS::process() { @@ -425,7 +442,7 @@ void WebXRInterfaceJS::_update_tracker(int p_controller_id) { int *buttons = godot_webxr_get_controller_buttons(p_controller_id); if (buttons) { for (int i = 0; i < buttons[0]; i++) { - input->joy_button(p_controller_id + 100, i, *((float *)buttons + (i + 1))); + input->joy_button(p_controller_id + 100, (JoyButton)i, *((float *)buttons + (i + 1))); } free(buttons); } @@ -436,7 +453,7 @@ void WebXRInterfaceJS::_update_tracker(int p_controller_id) { Input::JoyAxisValue joy_axis; joy_axis.min = -1; joy_axis.value = *((float *)axes + (i + 1)); - input->joy_axis(p_controller_id + 100, i, joy_axis); + input->joy_axis(p_controller_id + 100, (JoyAxis)i, joy_axis); } free(axes); } diff --git a/modules/webxr/webxr_interface_js.h b/modules/webxr/webxr_interface_js.h index 723ab952cd..f9368582b7 100644 --- a/modules/webxr/webxr_interface_js.h +++ b/modules/webxr/webxr_interface_js.h @@ -83,12 +83,13 @@ public: virtual void uninitialize() override; virtual Size2 get_render_targetsize() override; - virtual bool is_stereo() override; + virtual uint32_t get_view_count() override; virtual Transform3D get_camera_transform() override; virtual Transform3D get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) override; virtual CameraMatrix get_projection_for_view(uint32_t p_view, real_t p_aspect, real_t p_z_near, real_t p_z_far) override; virtual unsigned int get_external_texture_for_eye(XRInterface::Eyes p_eye) override; virtual void commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) override; + virtual Vector<BlitToScreen> commit_views(RID p_render_target, const Rect2 &p_screen_rect) override; virtual void process() override; virtual void notification(int p_what) override; |